net/mlx5: Eswitch, enable forwarding back to uplink port
authorEli Cohen <eli@mellanox.com>
Mon, 24 Feb 2020 14:59:54 +0000 (16:59 +0200)
committerSaeed Mahameed <saeedm@mellanox.com>
Wed, 18 Mar 2020 02:41:39 +0000 (19:41 -0700)
Add dependencny on cap termination_table_raw_traffic to allow non
encapsulated packets received from uplink to be forwarded back to the
received uplink port.

Refactor the conditions into a separate function.

Signed-off-by: Eli Cohen <eli@mellanox.com>
Reviewed-by: Oz Shlomo <ozsh@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
include/linux/mlx5/mlx5_ifc.h

index ddb933a..ebf60ff 100644 (file)
@@ -3641,6 +3641,46 @@ static int mlx5_validate_goto_chain(struct mlx5_eswitch *esw,
        return 0;
 }
 
+static int verify_uplink_forwarding(struct mlx5e_priv *priv,
+                                   struct mlx5e_tc_flow *flow,
+                                   struct net_device *out_dev,
+                                   struct netlink_ext_ack *extack)
+{
+       struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
+       struct mlx5_esw_flow_attr *attr = flow->esw_attr;
+       struct mlx5e_rep_priv *rep_priv;
+
+       /* Forwarding non encapsulated traffic between
+        * uplink ports is allowed only if
+        * termination_table_raw_traffic cap is set.
+        *
+        * Input vport was stored esw_attr->in_rep.
+        * In LAG case, *priv* is the private data of
+        * uplink which may be not the input vport.
+        */
+       rep_priv = mlx5e_rep_to_rep_priv(attr->in_rep);
+
+       if (!(mlx5e_eswitch_uplink_rep(rep_priv->netdev) &&
+             mlx5e_eswitch_uplink_rep(out_dev)))
+               return 0;
+
+       if (!MLX5_CAP_ESW_FLOWTABLE_FDB(esw->dev,
+                                       termination_table_raw_traffic)) {
+               NL_SET_ERR_MSG_MOD(extack,
+                                  "devices are both uplink, can't offload forwarding");
+                       pr_err("devices %s %s are both uplink, can't offload forwarding\n",
+                              priv->netdev->name, out_dev->name);
+                       return -EOPNOTSUPP;
+       } else if (out_dev != rep_priv->netdev) {
+               NL_SET_ERR_MSG_MOD(extack,
+                                  "devices are not the same uplink, can't offload forwarding");
+               pr_err("devices %s %s are both uplink but not the same, can't offload forwarding\n",
+                      priv->netdev->name, out_dev->name);
+               return -EOPNOTSUPP;
+       }
+       return 0;
+}
+
 static int parse_tc_fdb_actions(struct mlx5e_priv *priv,
                                struct flow_action *flow_action,
                                struct mlx5e_tc_flow *flow,
@@ -3738,7 +3778,6 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv,
                                struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
                                struct net_device *uplink_dev = mlx5_eswitch_uplink_get_proto_dev(esw, REP_ETH);
                                struct net_device *uplink_upper;
-                               struct mlx5e_rep_priv *rep_priv;
 
                                if (is_duplicated_output_device(priv->netdev,
                                                                out_dev,
@@ -3774,21 +3813,9 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv,
                                                return err;
                                }
 
-                               /* Don't allow forwarding between uplink.
-                                *
-                                * Input vport was stored esw_attr->in_rep.
-                                * In LAG case, *priv* is the private data of
-                                * uplink which may be not the input vport.
-                                */
-                               rep_priv = mlx5e_rep_to_rep_priv(attr->in_rep);
-                               if (mlx5e_eswitch_uplink_rep(rep_priv->netdev) &&
-                                   mlx5e_eswitch_uplink_rep(out_dev)) {
-                                       NL_SET_ERR_MSG_MOD(extack,
-                                                          "devices are both uplink, can't offload forwarding");
-                                       pr_err("devices %s %s are both uplink, can't offload forwarding\n",
-                                              priv->netdev->name, out_dev->name);
-                                       return -EOPNOTSUPP;
-                               }
+                               err = verify_uplink_forwarding(priv, flow, out_dev, extack);
+                               if (err)
+                                       return err;
 
                                if (!mlx5e_is_valid_eswitch_fwd_dev(priv, out_dev)) {
                                        NL_SET_ERR_MSG_MOD(extack,
index 2bd9209..cc55cee 100644 (file)
@@ -416,7 +416,8 @@ struct mlx5_ifc_flow_table_prop_layout_bits {
        u8         termination_table[0x1];
        u8         reformat_and_fwd_to_table[0x1];
        u8         reserved_at_1a[0x6];
-       u8         reserved_at_20[0x2];
+       u8         termination_table_raw_traffic[0x1];
+       u8         reserved_at_21[0x1];
        u8         log_max_ft_size[0x6];
        u8         log_max_modify_header_context[0x8];
        u8         max_modify_header_actions[0x8];