Skip to contentSkip to conversation

nfp: flow-independent tc action hardware offload

PATCH Applied Simon Horman 2 participants 8 messages Feb 23, 2022 – Feb 25, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover nfp: flow-independent tc action hardware offload

Baowen Zheng says:

Allow nfp NIC to offload tc actions independent of flows.

The motivation for this work is to offload tc actions independent of flows for nfp NIC. We allow nfp driver to provide hardware offload of OVS metering feature - which calls for policers that may be used by multiple flows and whose lifecycle is independent of any flows that use them.

When nfp driver tries to offload a flow table using the independent action, the driver will search if the action is already offloaded to the hardware. If not, the flow table offload will fail.

When the nfp NIC successes to offload an action, the user can check in_hw_count when dumping the tc action.

Tc cli command to offload and dump an action:

 # tc actions add action police rate 100mbit burst 10000k index 200 skip_sw
 # tc -s -d actions list action police

total acts 1

action order 0: police 0xc8 rate 100Mbit burst 10000Kb mtu 2Kb action reclassify overhead 0b linklayer ethernet
ref 1 bind 0 installed 142 sec used 0 sec
Action statistics:
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0
skip_sw in_hw in_hw_count 1
used_hw_stats delayed

Changes between v1 and v2:
* Make some code-style changes based on review of v1
* Change the memory allocation way from GFP_ATOMIC to GFP_KERNEL.

Baowen Zheng (6):
nfp: refactor policer config to support ingress/egress meter
nfp: add support to offload tc action to hardware
nfp: add hash table to store meter table
nfp: add process to get action stats from hardware
nfp: add support to offload police action from flower table
nfp: add NFP_FL_FEATS_QOS_METER to host features to enable meter
offload

 .../ethernet/netronome/nfp/flower/action.c    |  58 +++
 .../net/ethernet/netronome/nfp/flower/cmsg.h  |   7 +
 .../net/ethernet/netronome/nfp/flower/main.h  |  49 +-
 .../ethernet/netronome/nfp/flower/offload.c   |  16 +-
 .../ethernet/netronome/nfp/flower/qos_conf.c  | 430 +++++++++++++++++-
 5 files changed, 534 insertions(+), 26 deletions(-)
Signature · 1 line
2.30.2
#1 lore raw

PATCH v2 1/6 nfp: refactor policer config to support ingress/egress meter

From: Baowen Zheng <[email protected]>

Add an policer API to support ingress/egress meter.

Change ingress police to compatible with the new API.

---
 .../net/ethernet/netronome/nfp/flower/main.h  |  2 +
 .../ethernet/netronome/nfp/flower/qos_conf.c  | 74 ++++++++++++++-----
 2 files changed, 56 insertions(+), 20 deletions(-)
drivers/net/ethernet/netronome/nfp/flower/main.h +2 -0
index 917c450a7aad..7720403e79fb 100644
@@ -569,4 +569,6 @@ nfp_flower_xmit_flow(struct nfp_app *app, struct nfp_fl_payload *nfp_flow,
 void
 nfp_flower_update_merge_stats(struct nfp_app *app,
 			      struct nfp_fl_payload *sub_flow);
+int nfp_flower_offload_one_police(struct nfp_app *app, bool ingress,
+				  bool pps, u32 id, u32 rate, u32 burst);
 #endif
drivers/net/ethernet/netronome/nfp/flower/qos_conf.c +54 -20

114 lines not on this page · raw message

Signature · 1 line
2.30.2
#2 lore raw

PATCH v2 2/6 nfp: add support to offload tc action to hardware

In reply to Simon Horman

From: Baowen Zheng <[email protected]>

Add process to offload tc action to hardware.

Currently we only support to offload police action.

Add meter capability to check if firmware supports meter offload.

---
 .../net/ethernet/netronome/nfp/flower/main.h  |   6 ++
 .../ethernet/netronome/nfp/flower/offload.c   |  16 ++-
 .../ethernet/netronome/nfp/flower/qos_conf.c  | 100 ++++++++++++++++++
 3 files changed, 121 insertions(+), 1 deletion(-)
drivers/net/ethernet/netronome/nfp/flower/main.h +6 -0
index 7720403e79fb..a880f7684600 100644
@@ -12,7 +12,9 @@
 #include <linux/rhashtable.h>
 #include <linux/time64.h>
 #include <linux/types.h>
+#include <net/flow_offload.h>
 #include <net/pkt_cls.h>
+#include <net/pkt_sched.h>
 #include <net/tcp.h>
 #include <linux/workqueue.h>
 #include <linux/idr.h>
@@ -48,6 +50,7 @@ struct nfp_app;
 #define NFP_FL_FEATS_IPV6_TUN		BIT(7)
 #define NFP_FL_FEATS_VLAN_QINQ		BIT(8)
 #define NFP_FL_FEATS_QOS_PPS		BIT(9)
+#define NFP_FL_FEATS_QOS_METER		BIT(10)
 #define NFP_FL_FEATS_HOST_ACK		BIT(31)
 
 #define NFP_FL_ENABLE_FLOW_MERGE	BIT(0)
@@ -569,6 +572,9 @@ nfp_flower_xmit_flow(struct nfp_app *app, struct nfp_fl_payload *nfp_flow,
 void
 nfp_flower_update_merge_stats(struct nfp_app *app,
 			      struct nfp_fl_payload *sub_flow);
+
+int nfp_setup_tc_act_offload(struct nfp_app *app,
+			     struct flow_offload_action *fl_act);
 int nfp_flower_offload_one_police(struct nfp_app *app, bool ingress,
 				  bool pps, u32 id, u32 rate, u32 burst);
 #endif
drivers/net/ethernet/netronome/nfp/flower/offload.c +15 -1
index f97eff5afd12..92e8ade4854e 100644
@@ -1861,6 +1861,20 @@ nfp_flower_setup_indr_tc_block(struct net_device *netdev, struct Qdisc *sch, str
 	return 0;
 }
 
+static int
+nfp_setup_tc_no_dev(struct nfp_app *app, enum tc_setup_type type, void *data)
+{
+	if (!data)
+		return -EOPNOTSUPP;
+
+	switch (type) {
+	case TC_SETUP_ACT:
+		return nfp_setup_tc_act_offload(app, data);
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
 int
 nfp_flower_indr_setup_tc_cb(struct net_device *netdev, struct Qdisc *sch, void *cb_priv,
 			    enum tc_setup_type type, void *type_data,
@@ -1868,7 +1882,7 @@ nfp_flower_indr_setup_tc_cb(struct net_device *netdev, struct Qdisc *sch, void *
 			    void (*cleanup)(struct flow_block_cb *block_cb))
 {
 	if (!netdev)
-		return -EOPNOTSUPP;
+		return nfp_setup_tc_no_dev(cb_priv, type, data);
 
 	if (!nfp_fl_is_netdev_to_offload(netdev))
 		return -EOPNOTSUPP;
drivers/net/ethernet/netronome/nfp/flower/qos_conf.c +100 -0

103 lines not on this page · raw message

Signature · 1 line
2.30.2
#3 lore raw

PATCH v2 3/6 nfp: add hash table to store meter table

In reply to Simon Horman

From: Baowen Zheng <[email protected]>

Add a hash table to store meter table.

This meter table will also be used by flower action.

---
 .../net/ethernet/netronome/nfp/flower/main.h  |  35 +++++
 .../ethernet/netronome/nfp/flower/qos_conf.c  | 142 +++++++++++++++++-
 2 files changed, 176 insertions(+), 1 deletion(-)
drivers/net/ethernet/netronome/nfp/flower/main.h +35 -0
index a880f7684600..7ecba013d2ab 100644
@@ -194,6 +194,8 @@ struct nfp_fl_internal_ports {
  * @qos_stats_work:	Workqueue for qos stats processing
  * @qos_rate_limiters:	Current active qos rate limiters
  * @qos_stats_lock:	Lock on qos stats updates
+ * @meter_stats_lock:   Lock on meter stats updates
+ * @meter_table:	Hash table used to store the meter table
  * @pre_tun_rule_cnt:	Number of pre-tunnel rules offloaded
  * @merge_table:	Hash table to store merged flows
  * @ct_zone_table:	Hash table used to store the different zones
@@ -231,6 +233,8 @@ struct nfp_flower_priv {
 	struct delayed_work qos_stats_work;
 	unsigned int qos_rate_limiters;
 	spinlock_t qos_stats_lock; /* Protect the qos stats */
+	struct mutex meter_stats_lock; /* Protect the meter stats */
+	struct rhashtable meter_table;
 	int pre_tun_rule_cnt;
 	struct rhashtable merge_table;
 	struct rhashtable ct_zone_table;
@@ -377,6 +381,31 @@ struct nfp_fl_stats_frame {
 	__be64 stats_cookie;
 };
 
+struct nfp_meter_stats_entry {
+	u64 pkts;
+	u64 bytes;
+	u64 drops;
+};
+
+struct nfp_meter_entry {
+	struct rhash_head ht_node;
+	u32 meter_id;
+	bool bps;
+	u32 rate;
+	u32 burst;
+	u64 used;
+	struct nfp_meter_stats {
+		u64 update;
+		struct nfp_meter_stats_entry curr;
+		struct nfp_meter_stats_entry prev;
+	} stats;
+};
+
+enum nfp_meter_op {
+	NFP_METER_ADD,
+	NFP_METER_DEL,
+};
+
 static inline bool
 nfp_flower_internal_port_can_offload(struct nfp_app *app,
 				     struct net_device *netdev)
@@ -575,6 +604,12 @@ nfp_flower_update_merge_stats(struct nfp_app *app,
 
 int nfp_setup_tc_act_offload(struct nfp_app *app,
 			     struct flow_offload_action *fl_act);
+int nfp_init_meter_table(struct nfp_app *app);
+
 int nfp_flower_offload_one_police(struct nfp_app *app, bool ingress,
 				  bool pps, u32 id, u32 rate, u32 burst);
+int nfp_flower_setup_meter_entry(struct nfp_app *app,
+				 const struct flow_action_entry *action,
+				 enum nfp_meter_op op,
+				 u32 meter_id);
 #endif
drivers/net/ethernet/netronome/nfp/flower/qos_conf.c +141 -1

192 lines not on this page · raw message

Signature · 1 line
2.30.2
#4 lore raw

PATCH v2 4/6 nfp: add process to get action stats from hardware

In reply to Simon Horman

From: Baowen Zheng <[email protected]>

Add a process to update action stats from hardware.

This stats data will be updated to tc action when dumping actions or filters.

---
 .../net/ethernet/netronome/nfp/flower/main.h  |   3 +-
 .../ethernet/netronome/nfp/flower/qos_conf.c  | 116 +++++++++++++++++-
 2 files changed, 114 insertions(+), 5 deletions(-)
drivers/net/ethernet/netronome/nfp/flower/main.h +2 -1
index 7ecba013d2ab..c2888a3bac9a 100644
@@ -605,7 +605,8 @@ nfp_flower_update_merge_stats(struct nfp_app *app,
 int nfp_setup_tc_act_offload(struct nfp_app *app,
 			     struct flow_offload_action *fl_act);
 int nfp_init_meter_table(struct nfp_app *app);
-
+void nfp_flower_stats_meter_request_all(struct nfp_flower_priv *fl_priv);
+void nfp_act_stats_reply(struct nfp_app *app, void *pmsg);
 int nfp_flower_offload_one_police(struct nfp_app *app, bool ingress,
 				  bool pps, u32 id, u32 rate, u32 burst);
 int nfp_flower_setup_meter_entry(struct nfp_app *app,
drivers/net/ethernet/netronome/nfp/flower/qos_conf.c +112 -4

166 lines not on this page · raw message

Signature · 1 line
2.30.2
#5 lore raw

PATCH v2 5/6 nfp: add support to offload police action from flower table

In reply to Simon Horman

From: Baowen Zheng <[email protected]>

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.

---
 .../ethernet/netronome/nfp/flower/action.c    | 58 +++++++++++++++++++
 .../net/ethernet/netronome/nfp/flower/cmsg.h  |  7 +++
 .../net/ethernet/netronome/nfp/flower/main.h  |  2 +
 .../ethernet/netronome/nfp/flower/qos_conf.c  |  2 +-
 4 files changed, 68 insertions(+), 1 deletion(-)
drivers/net/ethernet/netronome/nfp/flower/action.c +58 -0
index a3242b36e216..2c40a3959f94 100644
@@ -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");
drivers/net/ethernet/netronome/nfp/flower/cmsg.h +7 -0
index 1543e47456d5..68e8a2fb1a29 100644
@@ -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
drivers/net/ethernet/netronome/nfp/flower/main.h +2 -0
index c2888a3bac9a..729f3244be04 100644
@@ -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
drivers/net/ethernet/netronome/nfp/flower/qos_conf.c +1 -1
index 286743de8ea4..6f2f3c797f1a 100644
@@ -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;
Signature · 1 line
2.30.2
#6 lore raw

PATCH v2 6/6 nfp: add NFP_FL_FEATS_QOS_METER to host features to enable meter offload

In reply to Simon Horman

From: Baowen Zheng <[email protected]>

Add NFP_FL_FEATS_QOS_METER to host features to enable meter offload in driver.

Before adding this feature, we will not offload any police action since we will check the host features before offloading any police action.

---
 drivers/net/ethernet/netronome/nfp/flower/main.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/netronome/nfp/flower/main.h +2 -1
index 729f3244be04..fa902ce2dd82 100644
@@ -66,7 +66,8 @@ struct nfp_app;
 	NFP_FL_FEATS_PRE_TUN_RULES | \
 	NFP_FL_FEATS_IPV6_TUN | \
 	NFP_FL_FEATS_VLAN_QINQ | \
-	NFP_FL_FEATS_QOS_PPS)
+	NFP_FL_FEATS_QOS_PPS | \
+	NFP_FL_FEATS_QOS_METER)
 
 struct nfp_fl_mask_id {
 	struct circ_buf mask_id_free_list;
Signature · 1 line
2.30.2
#7 lore raw
In reply to Simon Horman
This series was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Wed, 23 Feb 2022 17:22:56 +0100 you wrote:

Baowen Zheng says:

Allow nfp NIC to offload tc actions independent of flows.

The motivation for this work is to offload tc actions independent of flows for nfp NIC. We allow nfp driver to provide hardware offload of OVS metering feature - which calls for policers that may be used by multiple flows and whose lifecycle is independent of any flows that use them.

[...]

Here is the summary with links:
- [net-next,v2,1/6] nfp: refactor policer config to support ingress/egress meter

    https://git.kernel.org/netdev/net-next/c/bbab5f9332ee
  - [net-next,v2,2/6] nfp: add support to offload tc action to hardware
    https://git.kernel.org/netdev/net-next/c/59080da09038
  - [net-next,v2,3/6] nfp: add hash table to store meter table
    https://git.kernel.org/netdev/net-next/c/26ff98d7dd20
  - [net-next,v2,4/6] nfp: add process to get action stats from hardware
    https://git.kernel.org/netdev/net-next/c/776178a5cc67
  - [net-next,v2,5/6] nfp: add support to offload police action from flower table
    https://git.kernel.org/netdev/net-next/c/147747ec664e
  - [net-next,v2,6/6] nfp: add NFP_FL_FEATS_QOS_METER to host features to enable meter offload
    https://git.kernel.org/netdev/net-next/c/5e98743cfad0

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html