nfp: add support to offload police action from flower table
authorBaowen Zheng <baowen.zheng@corigine.com>
Wed, 23 Feb 2022 16:23:01 +0000 (17:23 +0100)
committerJakub Kicinski <kuba@kernel.org>
Fri, 25 Feb 2022 05:51:08 +0000 (21:51 -0800)
Offload flow table if the action is already offloaded to hardware when
flow table uses this action.

Change meter id to type of u32 to support all the action index.

Signed-off-by: Baowen Zheng <baowen.zheng@corigine.com>
Signed-off-by: Louis Peens <louis.peens@corigine.com>
Signed-off-by: Simon Horman <simon.horman@corigine.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/netronome/nfp/flower/action.c
drivers/net/ethernet/netronome/nfp/flower/cmsg.h
drivers/net/ethernet/netronome/nfp/flower/main.h
drivers/net/ethernet/netronome/nfp/flower/qos_conf.c

index a3242b36e216ecc81e7173970fa564e9652e7c22..2c40a3959f94da31e4f5a1d54a48c889e8893661 100644 (file)
@@ -922,6 +922,51 @@ nfp_fl_pedit(const struct flow_action_entry *act,
        }
 }
 
+static struct nfp_fl_meter *nfp_fl_meter(char *act_data)
+{
+       size_t act_size = sizeof(struct nfp_fl_meter);
+       struct nfp_fl_meter *meter_act;
+
+       meter_act = (struct nfp_fl_meter *)act_data;
+
+       memset(meter_act, 0, act_size);
+
+       meter_act->head.jump_id = NFP_FL_ACTION_OPCODE_METER;
+       meter_act->head.len_lw = act_size >> NFP_FL_LW_SIZ;
+
+       return meter_act;
+}
+
+static int
+nfp_flower_meter_action(struct nfp_app *app,
+                       const struct flow_action_entry *action,
+                       struct nfp_fl_payload *nfp_fl, int *a_len,
+                       struct net_device *netdev,
+                       struct netlink_ext_ack *extack)
+{
+       struct nfp_fl_meter *fl_meter;
+       u32 meter_id;
+
+       if (*a_len + sizeof(struct nfp_fl_meter) > NFP_FL_MAX_A_SIZ) {
+               NL_SET_ERR_MSG_MOD(extack,
+                                  "unsupported offload:meter action size beyond the allowed maximum");
+               return -EOPNOTSUPP;
+       }
+
+       meter_id = action->hw_index;
+       if (!nfp_flower_search_meter_entry(app, meter_id)) {
+               NL_SET_ERR_MSG_MOD(extack,
+                                  "can not offload flow table with unsupported police action.\n");
+               return -EOPNOTSUPP;
+       }
+
+       fl_meter = nfp_fl_meter(&nfp_fl->action_data[*a_len]);
+       *a_len += sizeof(struct nfp_fl_meter);
+       fl_meter->meter_id = cpu_to_be32(meter_id);
+
+       return 0;
+}
+
 static int
 nfp_flower_output_action(struct nfp_app *app,
                         const struct flow_action_entry *act,
@@ -985,6 +1030,7 @@ nfp_flower_loop_action(struct nfp_app *app, const struct flow_action_entry *act,
                       struct nfp_flower_pedit_acts *set_act, bool *pkt_host,
                       struct netlink_ext_ack *extack, int act_idx)
 {
+       struct nfp_flower_priv *fl_priv = app->priv;
        struct nfp_fl_pre_tunnel *pre_tun;
        struct nfp_fl_set_tun *set_tun;
        struct nfp_fl_push_vlan *psh_v;
@@ -1149,6 +1195,18 @@ nfp_flower_loop_action(struct nfp_app *app, const struct flow_action_entry *act,
 
                *pkt_host = true;
                break;
+       case FLOW_ACTION_POLICE:
+               if (!(fl_priv->flower_ext_feats & NFP_FL_FEATS_QOS_METER)) {
+                       NL_SET_ERR_MSG_MOD(extack,
+                                          "unsupported offload: unsupported police action in action list");
+                       return -EOPNOTSUPP;
+               }
+
+               err = nfp_flower_meter_action(app, act, nfp_fl, a_len, netdev,
+                                             extack);
+               if (err)
+                       return err;
+               break;
        default:
                /* Currently we do not handle any other actions. */
                NL_SET_ERR_MSG_MOD(extack, "unsupported offload: unsupported action in action list");
index 1543e47456d57ec28837b7b1ba3331a5df57590c..68e8a2fb1a2979511e8c193a6e3d66a9dd37a988 100644 (file)
@@ -85,6 +85,7 @@
 #define NFP_FL_ACTION_OPCODE_SET_TCP           15
 #define NFP_FL_ACTION_OPCODE_PRE_LAG           16
 #define NFP_FL_ACTION_OPCODE_PRE_TUNNEL                17
+#define NFP_FL_ACTION_OPCODE_METER             24
 #define NFP_FL_ACTION_OPCODE_PUSH_GENEVE       26
 #define NFP_FL_ACTION_OPCODE_NUM               32
 
@@ -260,6 +261,12 @@ struct nfp_fl_set_mpls {
        __be32 lse;
 };
 
+struct nfp_fl_meter {
+       struct nfp_fl_act_head head;
+       __be16 reserved;
+       __be32 meter_id;
+};
+
 /* Metadata with L2 (1W/4B)
  * ----------------------------------------------------------------
  *    3                   2                   1
index c2888a3bac9a8986db29682ab2ad076d971236a7..729f3244be04da48826f026016c9c4e14a6487ae 100644 (file)
@@ -613,4 +613,6 @@ int nfp_flower_setup_meter_entry(struct nfp_app *app,
                                 const struct flow_action_entry *action,
                                 enum nfp_meter_op op,
                                 u32 meter_id);
+struct nfp_meter_entry *
+nfp_flower_search_meter_entry(struct nfp_app *app, u32 meter_id);
 #endif
index 286743de8ea44e04f19c1b9e822be3f8937acc4a..6f2f3c797f1ae36ca1f9ff57358ef8c7df0d6420 100644 (file)
@@ -502,7 +502,7 @@ static const struct rhashtable_params stats_meter_table_params = {
        .key_len        = sizeof(u32),
 };
 
-static struct nfp_meter_entry *
+struct nfp_meter_entry *
 nfp_flower_search_meter_entry(struct nfp_app *app, u32 meter_id)
 {
        struct nfp_flower_priv *priv = app->priv;