Skip to contentSkip to conversation

cxgb4: add mirror action support for TC-MATCHALL

PATCH Superseded Rahul Lakkireddy 2 participants 5 messages Jun 29, 2020 – Jun 30, 2020

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover cxgb4: add mirror action support for TC-MATCHALL

This series of patches add support to mirror all ingress traffic for TC-MATCHALL ingress offload.

Patch 1 adds support to dynamically create a mirror Virtual Interface (VI) that accepts all mirror ingress traffic when mirror action is set in TC-MATCHALL offload.

Patch 2 adds support to allocate mirror Rxqs and setup RSS for the mirror VI.

Patch 3 adds support to replicate all the main VI configuration to mirror VI. This includes replicating MTU, promiscuous mode, all-multicast mode, and enabled netdev Rx feature offloads.

Thanks,
Rahul

v2:
- Add mutex to protect all mirror VI data, instead of just mirror Rxqs, in patch 1 and 2.
- Remove the un-needed mirror Rxq mutex in patch 2.
- Simplify the replication code by refactoring t4_set_rxmode() to handle mirror VI, instead of duplicating the t4_set_rxmode() calls in multiple places in patch 3.

Rahul Lakkireddy (3):
cxgb4: add mirror action to TC-MATCHALL offload
cxgb4: add support for mirror Rxqs
cxgb4: add main VI to mirror VI config replication

 drivers/net/ethernet/chelsio/cxgb4/cxgb4.h    |  24 +-
 .../ethernet/chelsio/cxgb4/cxgb4_debugfs.c    |  66 ++-
 .../net/ethernet/chelsio/cxgb4/cxgb4_main.c   | 438 ++++++++++++++++--
 .../ethernet/chelsio/cxgb4/cxgb4_tc_flower.c  |  16 +-
 .../ethernet/chelsio/cxgb4/cxgb4_tc_flower.h  |   3 +-
 .../chelsio/cxgb4/cxgb4_tc_matchall.c         |  57 ++-
 .../chelsio/cxgb4/cxgb4_tc_matchall.h         |   1 +
 drivers/net/ethernet/chelsio/cxgb4/t4_hw.c    |  43 +-
 8 files changed, 599 insertions(+), 49 deletions(-)
Signature · 1 line
2.24.0
#1 lore raw

PATCH v2 1/3 cxgb4: add mirror action to TC-MATCHALL offload

Add mirror Virtual Interface (VI) support to receive all ingress mirror traffic from the underlying device. The mirror VI is created dynamically, if the TC-MATCHALL rule has a corresponding mirror action. Also request MSI-X vectors needed for the mirror VI Rxqs. If no vectors are available, then disable mirror VI support.

v2:
- Add mutex to protect all mirror VI data, instead of just mirror Rxqs.

---
 drivers/net/ethernet/chelsio/cxgb4/cxgb4.h    |  11 ++
 .../net/ethernet/chelsio/cxgb4/cxgb4_main.c   | 103 +++++++++++++++++-
 .../ethernet/chelsio/cxgb4/cxgb4_tc_flower.c  |  16 ++-
 .../ethernet/chelsio/cxgb4/cxgb4_tc_flower.h  |   3 +-
 .../chelsio/cxgb4/cxgb4_tc_matchall.c         |  57 +++++++++-
 .../chelsio/cxgb4/cxgb4_tc_matchall.h         |   1 +
 drivers/net/ethernet/chelsio/cxgb4/t4_hw.c    |  16 +++
 7 files changed, 197 insertions(+), 10 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h +11 -0
index d811df1b93d9..434cc2caaf5b 100644
@@ -679,6 +679,12 @@ struct port_info {
 	u8 rx_cchan;
 
 	bool tc_block_shared;
+
+	/* Mirror VI information */
+	u16 viid_mirror;
+	refcount_t vi_mirror_refcnt;
+	u16 nmirrorqsets;
+	struct mutex vi_mirror_mutex; /* Sync access to Mirror VI info */
 };
 
 struct dentry;
@@ -960,6 +966,7 @@ struct sge {
 	u16 ofldqsets;              /* # of active ofld queue sets */
 	u16 nqs_per_uld;	    /* # of Rx queues per ULD */
 	u16 eoqsets;                /* # of ETHOFLD queues */
+	u16 mirrorqsets;            /* # of Mirror queues */
 
 	u16 timer_val[SGE_NTIMERS];
 	u8 counter_val[SGE_NCOUNTERS];
@@ -1857,6 +1864,8 @@ int t4_init_rss_mode(struct adapter *adap, int mbox);
 int t4_init_portinfo(struct port_info *pi, int mbox,
 		     int port, int pf, int vf, u8 mac[]);
 int t4_port_init(struct adapter *adap, int mbox, int pf, int vf);
+int t4_init_port_mirror(struct port_info *pi, u8 mbox, u8 port, u8 pf, u8 vf,
+			u16 *mirror_viid);
 void t4_fatal_err(struct adapter *adapter);
 unsigned int t4_chip_rss_size(struct adapter *adapter);
 int t4_config_rss_range(struct adapter *adapter, int mbox, unsigned int viid,
@@ -2141,6 +2150,8 @@ int cxgb_open(struct net_device *dev);
 int cxgb_close(struct net_device *dev);
 void cxgb4_enable_rx(struct adapter *adap, struct sge_rspq *q);
 void cxgb4_quiesce_rx(struct sge_rspq *q);
+int cxgb4_port_mirror_alloc(struct net_device *dev);
+void cxgb4_port_mirror_free(struct net_device *dev);
 #ifdef CONFIG_CHELSIO_TLS_DEVICE
 int cxgb4_set_ktls_feature(struct adapter *adap, bool enable);
 #endif
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +99 -4

165 lines not on this page · raw message

drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c +13 -3
index ae0e998d9338..6251444ffa58 100644
@@ -372,6 +372,7 @@ void cxgb4_process_flow_actions(struct net_device *in,
 		case FLOW_ACTION_DROP:
 			fs->action = FILTER_DROP;
 			break;
+		case FLOW_ACTION_MIRRED:
 		case FLOW_ACTION_REDIRECT: {
 			struct net_device *out = act->dev;
 			struct port_info *pi = netdev_priv(out);
@@ -529,7 +530,8 @@ static bool valid_pedit_action(struct net_device *dev,
 
 int cxgb4_validate_flow_actions(struct net_device *dev,
 				struct flow_action *actions,
-				struct netlink_ext_ack *extack)
+				struct netlink_ext_ack *extack,
+				u8 matchall_filter)
 {
 	struct flow_action_entry *act;
 	bool act_redir = false;
@@ -546,11 +548,19 @@ int cxgb4_validate_flow_actions(struct net_device *dev,
 		case FLOW_ACTION_DROP:
 			/* Do nothing */
 			break;
+		case FLOW_ACTION_MIRRED:
 		case FLOW_ACTION_REDIRECT: {
 			struct adapter *adap = netdev2adap(dev);
 			struct net_device *n_dev, *target_dev;
-			unsigned int i;
 			bool found = false;
+			unsigned int i;
+
+			if (act->id == FLOW_ACTION_MIRRED &&
+			    !matchall_filter) {
+				NL_SET_ERR_MSG_MOD(extack,
+						   "Egress mirror action is only supported for tc-matchall");
+				return -EOPNOTSUPP;
+			}
 
 			target_dev = act->dev;
 			for_each_port(adap, i) {
@@ -689,7 +699,7 @@ int cxgb4_flow_rule_replace(struct net_device *dev, struct flow_rule *rule,
 	u8 inet_family;
 	int fidx, ret;
 
-	if (cxgb4_validate_flow_actions(dev, &rule->action, extack))
+	if (cxgb4_validate_flow_actions(dev, &rule->action, extack, 0))
 		return -EOPNOTSUPP;
 
 	if (cxgb4_validate_flow_match(dev, rule))
drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.h +2 -1
index befa459324fb..6296e1d5a12b 100644
@@ -113,7 +113,8 @@ void cxgb4_process_flow_actions(struct net_device *in,
 				struct ch_filter_specification *fs);
 int cxgb4_validate_flow_actions(struct net_device *dev,
 				struct flow_action *actions,
-				struct netlink_ext_ack *extack);
+				struct netlink_ext_ack *extack,
+				u8 matchall_filter);
 
 int cxgb4_tc_flower_replace(struct net_device *dev,
 			    struct flow_cls_offload *cls);
drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_matchall.c +55 -2

91 lines not on this page · raw message

drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_matchall.h +1 -0
index ab6b5683dfd3..e264b6e606c4 100644
@@ -21,6 +21,7 @@ struct cxgb4_matchall_ingress_entry {
 	enum cxgb4_matchall_state state; /* Current MATCHALL offload state */
 	u32 tid; /* Index to hardware filter entry */
 	struct ch_filter_specification fs; /* Filter entry */
+	u16 viid_mirror; /* Identifier for allocated Mirror VI */
 	u64 bytes; /* # of bytes hitting the filter */
 	u64 packets; /* # of packets hitting the filter */
 	u64 last_used; /* Last updated jiffies time */
drivers/net/ethernet/chelsio/cxgb4/t4_hw.c +16 -0
index 70fe189202be..7876aa392aae 100644
@@ -9711,6 +9711,22 @@ int t4_port_init(struct adapter *adap, int mbox, int pf, int vf)
 	return 0;
 }
 
+int t4_init_port_mirror(struct port_info *pi, u8 mbox, u8 port, u8 pf, u8 vf,
+			u16 *mirror_viid)
+{
+	int ret;
+
+	ret = t4_alloc_vi(pi->adapter, mbox, port, pf, vf, 1, NULL, NULL,
+			  NULL, NULL);
+	if (ret < 0)
+		return ret;
+
+	if (mirror_viid)
+		*mirror_viid = ret;
+
+	return 0;
+}
+
 /**
  *	t4_read_cimq_cfg - read CIM queue configuration
  *	@adap: the adapter
Signature · 1 line
2.24.0
maintainer
#2 lore raw

Re: [PATCH net-next v2 1/3] cxgb4: add mirror action to TC-MATCHALL offload

drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c static int setup_debugfs(struct adapter *adap) · line 1327

Quoted 4 lines · On Tue, 30 Jun 2020 04:19:51 +0530 Rahul Lakkireddy wrote:
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +4 -0
+	if (refcount_read(&pi->vi_mirror_refcnt) > 1) {
+		refcount_dec(&pi->vi_mirror_refcnt);
+		goto out_unlock;
+	}

Please remove the use of refcount_t if you're doing this, otherwise a person looking at this code will waste time trying to validate if this clearly bogus use of refcount_t is harmless or not.

#3 lore raw

PATCH v2 2/3 cxgb4: add support for mirror Rxqs

In reply to Rahul Lakkireddy

When mirror VI is enabled, allocate the mirror Rxqs and setup the mirror VI RSS table. The mirror Rxqs are allocated/freed when the mirror VI is created/destroyed or when underlying port is brought up/down, respectively.

v2:
- Use mutex to protect all mirror VI data, instead of just mirror Rxqs.
- Remove the un-needed mirror Rxq mutex.

---
 drivers/net/ethernet/chelsio/cxgb4/cxgb4.h    |   9 +
 .../ethernet/chelsio/cxgb4/cxgb4_debugfs.c    |  66 ++++-
 .../net/ethernet/chelsio/cxgb4/cxgb4_main.c   | 235 ++++++++++++++++--
 3 files changed, 288 insertions(+), 22 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h +9 -0
index 434cc2caaf5b..8985d85a1530 100644
@@ -711,6 +711,13 @@ enum {
 	ULP_CRYPTO_KTLS_INLINE  = 1 << 3,
 };
 
+#define CXGB4_MIRROR_RXQ_DEFAULT_DESC_NUM 1024
+#define CXGB4_MIRROR_RXQ_DEFAULT_DESC_SIZE 64
+#define CXGB4_MIRROR_RXQ_DEFAULT_INTR_USEC 5
+#define CXGB4_MIRROR_RXQ_DEFAULT_PKT_CNT 8
+
+#define CXGB4_MIRROR_FLQ_DEFAULT_DESC_NUM 72
+
 struct rx_sw_desc;
 
 struct sge_fl {                     /* SGE free-buffer queue state */
@@ -960,6 +967,8 @@ struct sge {
 	struct sge_eohw_txq *eohw_txq;
 	struct sge_ofld_rxq *eohw_rxq;
 
+	struct sge_eth_rxq *mirror_rxq[NCHAN];
+
 	u16 max_ethqsets;           /* # of available Ethernet queue sets */
 	u16 ethqsets;               /* # of active Ethernet queue sets */
 	u16 ethtxq_rover;           /* Tx queue to clean up next */
drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c +64 -2

92 lines not on this page · raw message

drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +215 -20

285 lines not on this page · raw message

Signature · 1 line
2.24.0
#4 lore raw

PATCH v2 3/3 cxgb4: add main VI to mirror VI config replication

In reply to Rahul Lakkireddy

When mirror VI is enabled, replicate various VI config params enabled on main VI to mirror VI. These include replicating MTU, promiscuous mode, all-multicast mode, and enabled netdev Rx feature offloads.

v2:
- Simplify the replication code by refactoring t4_set_rxmode() to handle mirror VI, instead of duplicating the t4_set_rxmode() calls in multiple places.

---
 drivers/net/ethernet/chelsio/cxgb4/cxgb4.h    |   4 +-
 .../net/ethernet/chelsio/cxgb4/cxgb4_main.c   | 100 ++++++++++++++++--
 drivers/net/ethernet/chelsio/cxgb4/t4_hw.c    |  27 ++++-
 3 files changed, 114 insertions(+), 17 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h +2 -2
index 8985d85a1530..cc009f7fa530 100644
@@ -1984,8 +1984,8 @@ int t4_free_vi(struct adapter *adap, unsigned int mbox,
 	       unsigned int pf, unsigned int vf,
 	       unsigned int viid);
 int t4_set_rxmode(struct adapter *adap, unsigned int mbox, unsigned int viid,
-		int mtu, int promisc, int all_multi, int bcast, int vlanex,
-		bool sleep_ok);
+		  unsigned int viid_mirror, int mtu, int promisc, int all_multi,
+		  int bcast, int vlanex, bool sleep_ok);
 int t4_free_raw_mac_filt(struct adapter *adap, unsigned int viid,
 			 const u8 *addr, const u8 *mask, unsigned int idx,
 			 u8 lookup_type, u8 port_id, bool sleep_ok);
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +89 -11

167 lines not on this page · raw message

drivers/net/ethernet/chelsio/cxgb4/t4_hw.c +23 -4
index 7876aa392aae..0af5ee9975df 100644
@@ -7711,6 +7711,7 @@ int t4_free_vi(struct adapter *adap, unsigned int mbox, unsigned int pf,
  *	@adap: the adapter
  *	@mbox: mailbox to use for the FW command
  *	@viid: the VI id
+ *	@viid_mirror: the mirror VI id
  *	@mtu: the new MTU or -1
  *	@promisc: 1 to enable promiscuous mode, 0 to disable it, -1 no change
  *	@all_multi: 1 to enable all-multi mode, 0 to disable it, -1 no change
@@ -7721,10 +7722,11 @@ int t4_free_vi(struct adapter *adap, unsigned int mbox, unsigned int pf,
  *	Sets Rx properties of a virtual interface.
  */
 int t4_set_rxmode(struct adapter *adap, unsigned int mbox, unsigned int viid,
-		  int mtu, int promisc, int all_multi, int bcast, int vlanex,
-		  bool sleep_ok)
+		  unsigned int viid_mirror, int mtu, int promisc, int all_multi,
+		  int bcast, int vlanex, bool sleep_ok)
 {
-	struct fw_vi_rxmode_cmd c;
+	struct fw_vi_rxmode_cmd c, c_mirror;
+	int ret;
 
 	/* convert to FW values */
 	if (mtu < 0)
@@ -7749,7 +7751,24 @@ int t4_set_rxmode(struct adapter *adap, unsigned int mbox, unsigned int viid,
 			    FW_VI_RXMODE_CMD_ALLMULTIEN_V(all_multi) |
 			    FW_VI_RXMODE_CMD_BROADCASTEN_V(bcast) |
 			    FW_VI_RXMODE_CMD_VLANEXEN_V(vlanex));
-	return t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), NULL, sleep_ok);
+
+	if (viid_mirror) {
+		memcpy(&c_mirror, &c, sizeof(c_mirror));
+		c_mirror.op_to_viid =
+			cpu_to_be32(FW_CMD_OP_V(FW_VI_RXMODE_CMD) |
+				    FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
+				    FW_VI_RXMODE_CMD_VIID_V(viid_mirror));
+	}
+
+	ret = t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), NULL, sleep_ok);
+	if (ret)
+		return ret;
+
+	if (viid_mirror)
+		ret = t4_wr_mbox_meat(adap, mbox, &c_mirror, sizeof(c_mirror),
+				      NULL, sleep_ok);
+
+	return ret;
 }
 
 /**
Signature · 1 line
2.24.0