net/mlx5e: Support offloading tc priorities and chains for eswitch flows
authorPaul Blakey <paulb@mellanox.com>
Sun, 2 Sep 2018 07:19:14 +0000 (10:19 +0300)
committerSaeed Mahameed <saeedm@mellanox.com>
Wed, 17 Oct 2018 21:20:49 +0000 (14:20 -0700)
Currently we fail when user specify a non-zero chain, this patch adds the
support for it and tc priorities. To get to a new chain, use the tc
goto action.

Currently we support a fixed prio range 1-16, and chain range 0-3.

Signed-off-by: Paul Blakey <paulb@mellanox.com>
Reviewed-by: Or Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
drivers/net/ethernet/mellanox/mlx5/core/en_main.c
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c

index c9848e333450cb24411326da9db5707e11be1c52..1243edbedc9e96c90196f7b7f311129f2eb0cb04 100644 (file)
@@ -3392,9 +3392,6 @@ static int mlx5e_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
 {
        struct mlx5e_priv *priv = cb_priv;
 
-       if (!tc_cls_can_offload_and_chain0(priv->netdev, type_data))
-               return -EOPNOTSUPP;
-
        switch (type) {
        case TC_SETUP_CLSFLOWER:
                return mlx5e_setup_tc_cls_flower(priv, type_data, MLX5E_TC_INGRESS);
index 64c2b9ea8b1ed931fa017bdc896e8a5037873301..c3c657548824117f1732f3c7d14158c9a2a8e2a0 100644 (file)
@@ -853,9 +853,6 @@ static int mlx5e_rep_setup_tc_cb_egdev(enum tc_setup_type type, void *type_data,
 {
        struct mlx5e_priv *priv = cb_priv;
 
-       if (!tc_cls_can_offload_and_chain0(priv->netdev, type_data))
-               return -EOPNOTSUPP;
-
        switch (type) {
        case TC_SETUP_CLSFLOWER:
                return mlx5e_rep_setup_tc_cls_flower(priv, type_data, MLX5E_TC_EGRESS);
@@ -869,9 +866,6 @@ static int mlx5e_rep_setup_tc_cb(enum tc_setup_type type, void *type_data,
 {
        struct mlx5e_priv *priv = cb_priv;
 
-       if (!tc_cls_can_offload_and_chain0(priv->netdev, type_data))
-               return -EOPNOTSUPP;
-
        switch (type) {
        case TC_SETUP_CLSFLOWER:
                return mlx5e_rep_setup_tc_cls_flower(priv, type_data, MLX5E_TC_INGRESS);
index cb66964aa1ffcedd786c45784719e7c1e6cde2a3..608025ca5c04d3d5249595db31edf802bb47615f 100644 (file)
@@ -898,15 +898,32 @@ mlx5e_tc_add_fdb_flow(struct mlx5e_priv *priv,
                      struct netlink_ext_ack *extack)
 {
        struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
+       u32 max_chain = mlx5_eswitch_get_chain_range(esw);
        struct mlx5_esw_flow_attr *attr = flow->esw_attr;
+       u16 max_prio = mlx5_eswitch_get_prio_range(esw);
        struct net_device *out_dev, *encap_dev = NULL;
        struct mlx5_fc *counter = NULL;
        struct mlx5e_rep_priv *rpriv;
        struct mlx5e_priv *out_priv;
        int err = 0, encap_err = 0;
 
-       /* keep the old behaviour, use same prio for all offloaded rules */
-       attr->prio = 1;
+       /* if prios are not supported, keep the old behaviour of using same prio
+        * for all offloaded rules.
+        */
+       if (!mlx5_eswitch_prios_supported(esw))
+               attr->prio = 1;
+
+       if (attr->chain > max_chain) {
+               NL_SET_ERR_MSG(extack, "Requested chain is out of supported range");
+               err = -EOPNOTSUPP;
+               goto err_max_prio_chain;
+       }
+
+       if (attr->prio > max_prio) {
+               NL_SET_ERR_MSG(extack, "Requested priority is out of supported range");
+               err = -EOPNOTSUPP;
+               goto err_max_prio_chain;
+       }
 
        if (attr->action & MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT) {
                out_dev = __dev_get_by_index(dev_net(priv->netdev),
@@ -975,6 +992,7 @@ err_add_vlan:
        if (attr->action & MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT)
                mlx5e_detach_encap(priv, flow);
 err_attach_encap:
+err_max_prio_chain:
        return err;
 }
 
@@ -2826,6 +2844,7 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
                                struct mlx5e_tc_flow *flow,
                                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 *rpriv = priv->ppriv;
        struct ip_tunnel_info *info = NULL;
@@ -2934,6 +2953,25 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
                        continue;
                }
 
+               if (is_tcf_gact_goto_chain(a)) {
+                       u32 dest_chain = tcf_gact_goto_chain_index(a);
+                       u32 max_chain = mlx5_eswitch_get_chain_range(esw);
+
+                       if (dest_chain <= attr->chain) {
+                               NL_SET_ERR_MSG(extack, "Goto earlier chain isn't supported");
+                               return -EOPNOTSUPP;
+                       }
+                       if (dest_chain > max_chain) {
+                               NL_SET_ERR_MSG(extack, "Requested destination chain is out of supported range");
+                               return -EOPNOTSUPP;
+                       }
+                       action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST |
+                                 MLX5_FLOW_CONTEXT_ACTION_COUNT;
+                       attr->dest_chain = dest_chain;
+
+                       continue;
+               }
+
                return -EINVAL;
        }
 
@@ -3036,6 +3074,8 @@ mlx5e_add_fdb_flow(struct mlx5e_priv *priv,
        if (err)
                goto out;
 
+       flow->esw_attr->chain = f->common.chain_index;
+       flow->esw_attr->prio = TC_H_MAJ(f->common.prio) >> 16;
        err = parse_tc_fdb_actions(priv, f->exts, parse_attr, flow, extack);
        if (err)
                goto err_free;
@@ -3070,6 +3110,10 @@ mlx5e_add_nic_flow(struct mlx5e_priv *priv,
        struct mlx5e_tc_flow *flow;
        int attr_size, err;
 
+       /* multi-chain not supported for NIC rules */
+       if (!tc_cls_can_offload_and_chain0(priv->netdev, &f->common))
+               return -EOPNOTSUPP;
+
        flow_flags |= MLX5E_TC_FLOW_NIC;
        attr_size  = sizeof(struct mlx5_nic_flow_attr);
        err = mlx5e_alloc_flow(priv, attr_size, f, flow_flags,
@@ -3110,6 +3154,9 @@ mlx5e_tc_add_flow(struct mlx5e_priv *priv,
 
        get_flags(flags, &flow_flags);
 
+       if (!tc_can_offload_extack(priv->netdev, f->common.extack))
+               return -EOPNOTSUPP;
+
        if (esw && esw->mode == SRIOV_OFFLOADS)
                err = mlx5e_add_fdb_flow(priv, f, flow_flags, flow);
        else
index 42a130455ef8630a7903010d06ea1f37bbf74cbe..9eac137790f5aa2222522344139395c5bc5aed11 100644 (file)
@@ -71,7 +71,7 @@ u16 mlx5_eswitch_get_prio_range(struct mlx5_eswitch *esw)
        if (esw->fdb_table.flags & ESW_FDB_CHAINS_AND_PRIOS_SUPPORTED)
                return FDB_MAX_PRIO;
 
-       return U16_MAX;
+       return 1;
 }
 
 struct mlx5_flow_handle *