Skip to contentSkip to conversation

octeontx2-af: Install TC filter rules in hardware based on priority

PATCH Superseded Suman Ghosh 2 participants 3 messages Jul 16, 2023 – Jul 18, 2023

Subsystems (4)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 octeontx2-af: Install TC filter rules in hardware based on priority

As of today, hardware does not support installing tc filter rules based on priority. This patch fixes the issue and install the hardware rules based on priority. The final hardware rules will not be dependent on rule installation order, it will be strictly priority based, same as software.

---
Changes since v1:
- Rebased the patch on top of current 'main' branch

 .../net/ethernet/marvell/octeontx2/af/mbox.h  |   9 +-
 .../marvell/octeontx2/af/rvu_npc_fs.c         |   9 +-
 .../marvell/octeontx2/af/rvu_switch.c         |   6 +-
 .../marvell/octeontx2/nic/otx2_common.h       |  11 +-
 .../marvell/octeontx2/nic/otx2_devlink.c      |   1 -
 .../marvell/octeontx2/nic/otx2_ethtool.c      |   1 +
 .../marvell/octeontx2/nic/otx2_flows.c        |   2 +
 .../ethernet/marvell/octeontx2/nic/otx2_tc.c  | 313 +++++++++++++-----
 8 files changed, 248 insertions(+), 104 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/mbox.h +8 -1
index eba307eee2b2..ed66c5989102 100644
@@ -235,7 +235,7 @@ M(NPC_GET_KEX_CFG,	  0x600c, npc_get_kex_cfg,			\
 M(NPC_INSTALL_FLOW,	  0x600d, npc_install_flow,			       \
 				  npc_install_flow_req, npc_install_flow_rsp)  \
 M(NPC_DELETE_FLOW,	  0x600e, npc_delete_flow,			\
-				  npc_delete_flow_req, msg_rsp)		\
+				  npc_delete_flow_req, npc_delete_flow_rsp)		\
 M(NPC_MCAM_READ_ENTRY,	  0x600f, npc_mcam_read_entry,			\
 				  npc_mcam_read_entry_req,		\
 				  npc_mcam_read_entry_rsp)		\
@@ -1491,6 +1491,8 @@ struct npc_install_flow_req {
 	u8  vtag0_op;
 	u16 vtag1_def;
 	u8  vtag1_op;
+	/* old counter value */
+	u16 cntr_val;
 };
 
 struct npc_install_flow_rsp {
@@ -1506,6 +1508,11 @@ struct npc_delete_flow_req {
 	u8 all; /* PF + VFs */
 };
 
+struct npc_delete_flow_rsp {
+	struct mbox_msghdr hdr;
+	u16 cntr_val;
+};
+
 struct npc_mcam_read_entry_req {
 	struct mbox_msghdr hdr;
 	u16 entry;	 /* MCAM entry to read */
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c +7 -2
index 952319453701..9c365cc3e736 100644
@@ -1192,7 +1192,7 @@ static int npc_install_flow(struct rvu *rvu, int blkaddr, u16 target,
 	write_req.enable_entry = (u8)enable;
 	/* if counter is available then clear and use it */
 	if (req->set_cntr && rule->has_cntr) {
-		rvu_write64(rvu, blkaddr, NPC_AF_MATCH_STATX(rule->cntr), 0x00);
+		rvu_write64(rvu, blkaddr, NPC_AF_MATCH_STATX(rule->cntr), req->cntr_val);
 		write_req.set_cntr = 1;
 		write_req.cntr = rule->cntr;
 	}
@@ -1407,12 +1407,13 @@ static int npc_delete_flow(struct rvu *rvu, struct rvu_npc_mcam_rule *rule,
 
 int rvu_mbox_handler_npc_delete_flow(struct rvu *rvu,
 				     struct npc_delete_flow_req *req,
-				     struct msg_rsp *rsp)
+				     struct npc_delete_flow_rsp *rsp)
 {
 	struct npc_mcam *mcam = &rvu->hw->mcam;
 	struct rvu_npc_mcam_rule *iter, *tmp;
 	u16 pcifunc = req->hdr.pcifunc;
 	struct list_head del_list;
+	int blkaddr;
 
 	INIT_LIST_HEAD(&del_list);
 
@@ -1428,6 +1429,10 @@ int rvu_mbox_handler_npc_delete_flow(struct rvu *rvu,
 				list_move_tail(&iter->list, &del_list);
 			/* single rule */
 			} else if (req->entry == iter->entry) {
+				blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
+				if (blkaddr)
+					rsp->cntr_val = rvu_read64(rvu, blkaddr,
+								   NPC_AF_MATCH_STATX(iter->cntr));
 				list_move_tail(&iter->list, &del_list);
 				break;
 			}
drivers/net/ethernet/marvell/octeontx2/af/rvu_switch.c +4 -2
index 592b317f4637..854045ed3b06 100644
@@ -158,6 +158,7 @@ void rvu_switch_enable(struct rvu *rvu)
 	struct npc_mcam_alloc_entry_req alloc_req = { 0 };
 	struct npc_mcam_alloc_entry_rsp alloc_rsp = { 0 };
 	struct npc_delete_flow_req uninstall_req = { 0 };
+	struct npc_delete_flow_rsp uninstall_rsp = { 0 };
 	struct npc_mcam_free_entry_req free_req = { 0 };
 	struct rvu_switch *rswitch = &rvu->rswitch;
 	struct msg_rsp rsp;
@@ -197,7 +198,7 @@ void rvu_switch_enable(struct rvu *rvu)
 uninstall_rules:
 	uninstall_req.start = rswitch->start_entry;
 	uninstall_req.end =  rswitch->start_entry + rswitch->used_entries - 1;
-	rvu_mbox_handler_npc_delete_flow(rvu, &uninstall_req, &rsp);
+	rvu_mbox_handler_npc_delete_flow(rvu, &uninstall_req, &uninstall_rsp);
 	kfree(rswitch->entry2pcifunc);
 free_entries:
 	free_req.all = 1;
@@ -209,6 +210,7 @@ void rvu_switch_enable(struct rvu *rvu)
 void rvu_switch_disable(struct rvu *rvu)
 {
 	struct npc_delete_flow_req uninstall_req = { 0 };
+	struct npc_delete_flow_rsp uninstall_rsp = { 0 };
 	struct npc_mcam_free_entry_req free_req = { 0 };
 	struct rvu_switch *rswitch = &rvu->rswitch;
 	struct rvu_hwinfo *hw = rvu->hw;
@@ -250,7 +252,7 @@ void rvu_switch_disable(struct rvu *rvu)
 	uninstall_req.start = rswitch->start_entry;
 	uninstall_req.end =  rswitch->start_entry + rswitch->used_entries - 1;
 	free_req.all = 1;
-	rvu_mbox_handler_npc_delete_flow(rvu, &uninstall_req, &rsp);
+	rvu_mbox_handler_npc_delete_flow(rvu, &uninstall_req, &uninstall_rsp);
 	rvu_mbox_handler_npc_mcam_free_entry(rvu, &free_req, &rsp);
 	rswitch->used_entries = 0;
 	kfree(rswitch->entry2pcifunc);
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +2 -9
index ba8091131ec0..67715fc906b5 100644
@@ -360,13 +360,8 @@ struct otx2_flow_config {
 	struct list_head	flow_list;
 	u32			dmacflt_max_flows;
 	u16                     max_flows;
-};
-
-struct otx2_tc_info {
-	/* hash table to store TC offloaded flows */
-	struct rhashtable		flow_table;
-	struct rhashtable_params	flow_ht_params;
-	unsigned long			*tc_entries_bitmap;
+	struct list_head	flow_list_tc;
+	bool			ntuple;
 };
 
 struct dev_hw_ops {
@@ -491,7 +486,6 @@ struct otx2_nic {
 	/* NPC MCAM */
 	struct otx2_flow_config	*flow_cfg;
 	struct otx2_mac_table	*mac_table;
-	struct otx2_tc_info	tc_info;
 
 	u64			reset_count;
 	struct work_struct	reset_task;
@@ -1063,7 +1057,6 @@ int otx2_init_tc(struct otx2_nic *nic);
 void otx2_shutdown_tc(struct otx2_nic *nic);
 int otx2_setup_tc(struct net_device *netdev, enum tc_setup_type type,
 		  void *type_data);
-int otx2_tc_alloc_ent_bitmap(struct otx2_nic *nic);
 /* CGX/RPM DMAC filters support */
 int otx2_dmacflt_get_max_cnt(struct otx2_nic *pf);
 int otx2_dmacflt_add(struct otx2_nic *pf, const u8 *mac, u32 bit_pos);
drivers/net/ethernet/marvell/octeontx2/nic/otx2_devlink.c +0 -1
index 63ef7c41d18d..4e1130496573 100644
@@ -41,7 +41,6 @@ static int otx2_dl_mcam_count_set(struct devlink *devlink, u32 id,
 		return 0;
 
 	otx2_alloc_mcam_entries(pfvf, ctx->val.vu16);
-	otx2_tc_alloc_ent_bitmap(pfvf);
 
 	return 0;
 }
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +1 -0
index c47d91da32dc..9efcec549834 100644
@@ -764,6 +764,7 @@ static int otx2_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *nfc)
 	struct otx2_nic *pfvf = netdev_priv(dev);
 	int ret = -EOPNOTSUPP;
 
+	pfvf->flow_cfg->ntuple = ntuple;
 	switch (nfc->cmd) {
 	case ETHTOOL_SRXFH:
 		ret = otx2_set_rss_hash_opts(pfvf, nfc);
drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c +2 -0
index 2d7713a1a153..4762dbea64a1 100644
@@ -276,6 +276,7 @@ int otx2vf_mcam_flow_init(struct otx2_nic *pfvf)
 
 	flow_cfg = pfvf->flow_cfg;
 	INIT_LIST_HEAD(&flow_cfg->flow_list);
+	INIT_LIST_HEAD(&flow_cfg->flow_list_tc);
 	flow_cfg->max_flows = 0;
 
 	return 0;
@@ -298,6 +299,7 @@ int otx2_mcam_flow_init(struct otx2_nic *pf)
 		return -ENOMEM;
 
 	INIT_LIST_HEAD(&pf->flow_cfg->flow_list);
+	INIT_LIST_HEAD(&pf->flow_cfg->flow_list_tc);
 
 	/* Allocate bare minimum number of MCAM entries needed for
 	 * unicast and ntuple filters.
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +224 -89

451 lines not on this page · raw message

Signature · 1 line
2.25.1
#1 lore raw
Quoted 20 lines · Suman Ghosh

As of today, hardware does not support installing tc filter rules based on priority. This patch fixes the issue and install the hardware rules based on priority. The final hardware rules will not be dependent on rule installation order, it will be strictly priority based, same as software.

---
Changes since v1:
- Rebased the patch on top of current 'main' branch

 .../net/ethernet/marvell/octeontx2/af/mbox.h  |   9 +-
 .../marvell/octeontx2/af/rvu_npc_fs.c         |   9 +-
 .../marvell/octeontx2/af/rvu_switch.c         |   6 +-
 .../marvell/octeontx2/nic/otx2_common.h       |  11 +-
 .../marvell/octeontx2/nic/otx2_devlink.c      |   1 -
 .../marvell/octeontx2/nic/otx2_ethtool.c      |   1 +
 .../marvell/octeontx2/nic/otx2_flows.c        |   2 +
 .../ethernet/marvell/octeontx2/nic/otx2_tc.c  | 313 +++++++++++++-----
 8 files changed, 248 insertions(+), 104 deletions(-)

<...>

drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c static int otx2_tc_prepare_flow(struct otx2_nic *nic, struct otx2_tc_flow *node, · line 735

Quoted 5 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +4 -0
+static void otx2_tc_del_from_flow_list(struct otx2_flow_config *flow_cfg,
+				       struct otx2_tc_flow *node)
 {
+	struct otx2_tc_flow *tmp;
+	struct list_head *pos, *n;

Please declared variables in rversed Christmas tree, in all places, thanks.

Quoted 6 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +6 -0
+
+	list_for_each_safe(pos, n, &flow_cfg->flow_list_tc) {
+		tmp = list_entry(pos, struct otx2_tc_flow, list);
+		if (node == tmp) {
+			list_del(&node->list);
+			return;

drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c static int otx2_tc_prepare_flow(struct otx2_nic *nic, struct otx2_tc_flow *node, · line 751

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +10 -0
+		}
+	}
+}
+
+static int otx2_tc_add_to_flow_list(struct otx2_flow_config *flow_cfg,
+				    struct otx2_tc_flow *node)
+{
+	struct otx2_tc_flow *tmp;
+	struct list_head *pos, *n;
+	int index = 0;

Ditto.

Quoted 1 line

+

<...>

drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c static int otx2_tc_prepare_flow(struct otx2_nic *nic, struct otx2_tc_flow *node, · line 798

Quoted 3 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +3 -0
+static int otx2_del_mcam_flow_entry(struct otx2_nic *nic, u16 entry, u16 *cntr_val)
+{
+	struct npc_delete_flow_rsp __maybe_unused *rsp;

Why __maybe_unused? This keyword is usually used when in some CONFIG_* option, it won't be used. It is not the case here.

Quoted 2 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +0 -0
 	struct npc_delete_flow_req *req;
 	int err;

<...>

drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c static int otx2_setup_tc_block_ingress_cb(enum tc_setup_type type, · line 1211

Quoted 1 line
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +1 -0
+	ntuple = !!(nic->netdev->features & NETIF_F_NTUPLE);

No need in !! for bool variables.

Thanks

#2 lore raw
Quoted 26 lines · Suman Ghosh
Quoted 21 lines

As of today, hardware does not support installing tc filter rules based on priority. This patch fixes the issue and install the hardware rules based on priority. The final hardware rules will not be dependent on rule installation order, it will be strictly priority based, same as software.

---
Changes since v1:
- Rebased the patch on top of current 'main' branch

 .../net/ethernet/marvell/octeontx2/af/mbox.h  |   9 +-
 .../marvell/octeontx2/af/rvu_npc_fs.c         |   9 +-
 .../marvell/octeontx2/af/rvu_switch.c         |   6 +-
 .../marvell/octeontx2/nic/otx2_common.h       |  11 +-
 .../marvell/octeontx2/nic/otx2_devlink.c      |   1 -
 .../marvell/octeontx2/nic/otx2_ethtool.c      |   1 +
 .../marvell/octeontx2/nic/otx2_flows.c        |   2 +
 .../ethernet/marvell/octeontx2/nic/otx2_tc.c  | 313
+++++++++++++-----
 8 files changed, 248 insertions(+), 104 deletions(-)

<...>

Quoted 1 line

+static void otx2_tc_del_from_flow_list(struct otx2_flow_config

Quoted 8 lines

*flow_cfg,

drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c static int otx2_tc_prepare_flow(struct otx2_nic *nic, struct otx2_tc_flow *node, · line 735

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +3 -0
+				       struct otx2_tc_flow *node)
 {
+	struct otx2_tc_flow *tmp;
+	struct list_head *pos, *n;

Please declared variables in rversed Christmas tree, in all places, thanks.

[Suman] Ack, will update in v3 patch.

Quoted 13 lines

drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c static int otx2_tc_prepare_flow(struct otx2_nic *nic, struct otx2_tc_flow *node,

Quoted 12 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +11 -0
+
+	list_for_each_safe(pos, n, &flow_cfg->flow_list_tc) {
+		tmp = list_entry(pos, struct otx2_tc_flow, list);
+		if (node == tmp) {
+			list_del(&node->list);
+			return;
+		}
+	}
+}
+
+static int otx2_tc_add_to_flow_list(struct otx2_flow_config

*flow_cfg,

Quoted 7 lines

drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c static int otx2_tc_prepare_flow(struct otx2_nic *nic, struct otx2_tc_flow *node, · line 751

Quoted 5 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +5 -0
+				    struct otx2_tc_flow *node)
+{
+	struct otx2_tc_flow *tmp;
+	struct list_head *pos, *n;
+	int index = 0;

Ditto.

[Suman] Ack, will update in v3 patch.

Quoted 11 lines
Quoted 2 lines

+

<...>

Review

Quoted 3 lines
(quoted diff) +3 -0
+static int otx2_del_mcam_flow_entry(struct otx2_nic *nic, u16 entry,
+u16 *cntr_val) {
+	struct npc_delete_flow_rsp __maybe_unused *rsp;

Why __maybe_unused? This keyword is usually used when in some CONFIG_* option, it won't be used. It is not the case here.

[Suman] Ack, not needed her. Will update in v3 patch

Quoted 9 lines
Quoted 3 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +0 -0
 	struct npc_delete_flow_req *req;
 	int err;

<...>

drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c static int otx2_setup_tc_block_ingress_cb(enum tc_setup_type type, · line 1211

Quoted 1 line
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +1 -0
+	ntuple = !!(nic->netdev->features & NETIF_F_NTUPLE);

No need in !! for bool variables.

[Suman] Ack, will update in v3 patch.

Quoted 2 lines

Thanks