[RFC,v2,4/6] net/ixgbe: add mirror rule config and add/del rule APIs
diff mbox series

Message ID 20201103082809.41149-5-stevex.yang@intel.com
State RFC
Delegated to: Ferruh Yigit
Headers show
Series
  • [RFC,v2,1/6] net/i40e: add mirror rule config and add/del rule APIs
Related show

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Steve Yang Nov. 3, 2020, 8:28 a.m. UTC
Define ixgbe_flow_mirror_conf structure that is used for set mirror flow
rule to ixgbe register, and relocate the mirror related MACORs to header
file.

Signed-off-by: Steve Yang <stevex.yang@intel.com>
---
 drivers/net/ixgbe/ixgbe_ethdev.c |  8 -----
 drivers/net/ixgbe/ixgbe_ethdev.h | 54 ++++++++++++++++++++++++++++++--
 2 files changed, 52 insertions(+), 10 deletions(-)

Patch
diff mbox series

diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index 9a47a8b26..cc07b0e31 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -5724,14 +5724,6 @@  ixgbe_convert_vm_rx_mask_to_val(uint16_t rx_mask, uint32_t orig_val)
 	return new_val;
 }
 
-#define IXGBE_MRCTL_VPME  0x01 /* Virtual Pool Mirroring. */
-#define IXGBE_MRCTL_UPME  0x02 /* Uplink Port Mirroring. */
-#define IXGBE_MRCTL_DPME  0x04 /* Downlink Port Mirroring. */
-#define IXGBE_MRCTL_VLME  0x08 /* VLAN Mirroring. */
-#define IXGBE_INVALID_MIRROR_TYPE(mirror_type) \
-	((mirror_type) & ~(uint8_t)(ETH_MIRROR_VIRTUAL_POOL_UP | \
-	ETH_MIRROR_UPLINK_PORT | ETH_MIRROR_DOWNLINK_PORT | ETH_MIRROR_VLAN))
-
 static int
 ixgbe_mirror_rule_set(struct rte_eth_dev *dev,
 		      struct rte_eth_mirror_conf *mirror_conf,
diff --git a/drivers/net/ixgbe/ixgbe_ethdev.h b/drivers/net/ixgbe/ixgbe_ethdev.h
index 3d35ea791..db95a53f1 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.h
+++ b/drivers/net/ixgbe/ixgbe_ethdev.h
@@ -216,6 +216,27 @@  struct ixgbe_rte_flow_rss_conf {
 	uint16_t queue[IXGBE_MAX_RX_QUEUE_NUM]; /**< Queues indices to use. */
 };
 
+#define IXGBE_MAX_MIRROR_RULES 4  /* Maximum nb. of mirror rules. */
+#define IXGBE_MRCTL_VPME  0x01 /* Virtual Pool Mirroring. */
+#define IXGBE_MRCTL_UPME  0x02 /* Uplink Port Mirroring. */
+#define IXGBE_MRCTL_DPME  0x04 /* Downlink Port Mirroring. */
+#define IXGBE_MRCTL_VLME  0x08 /* VLAN Mirroring. */
+#define IXGBE_INVALID_MIRROR_TYPE(mirror_type)			\
+	((mirror_type) & ~(uint8_t)(ETH_MIRROR_VIRTUAL_POOL_UP |\
+				    ETH_MIRROR_UPLINK_PORT |	\
+				    ETH_MIRROR_DOWNLINK_PORT |	\
+				    ETH_MIRROR_VLAN))
+
+struct ixgbe_flow_mirror_conf {
+	uint8_t  rule_type;
+	uint16_t rule_id;
+	uint8_t  dst_pool;  /* Destination pool for this mirror rule. */
+	uint64_t pool_mask; /* Bitmap of pool for virtual pool mirroring */
+	uint64_t vlan_mask; /* mask for valid VLAN ID. */
+	/* VLAN ID list for vlan mirroring. */
+	uint16_t vlan_id[ETH_MIRROR_MAX_VLANS];
+};
+
 /* structure for interrupt relative data */
 struct ixgbe_interrupt {
 	uint32_t flags;
@@ -250,8 +271,6 @@  struct ixgbe_uta_info {
 	uint32_t uta_shadow[IXGBE_MAX_UTA];
 };
 
-#define IXGBE_MAX_MIRROR_RULES 4  /* Maximum nb. of mirror rules. */
-
 struct ixgbe_mirror_info {
 	struct rte_eth_mirror_conf mr_conf[IXGBE_MAX_MIRROR_RULES];
 	/**< store PF mirror rules configuration*/
@@ -337,6 +356,8 @@  struct ixgbe_filter_info {
 	uint32_t syn_info;
 	/* store the rss filter info */
 	struct ixgbe_rte_flow_rss_conf rss_info;
+	uint8_t mirror_mask;  /* Bit mask for every used mirror filter */
+	struct ixgbe_flow_mirror_conf mirror_filters[IXGBE_MAX_MIRROR_RULES];
 };
 
 struct ixgbe_l2_tn_key {
@@ -830,4 +851,33 @@  ixgbe_ethertype_filter_remove(struct ixgbe_filter_info *filter_info,
 	return idx;
 }
 
+static inline int8_t
+ixgbe_mirror_filter_insert(struct ixgbe_filter_info *filter_info,
+			   struct ixgbe_flow_mirror_conf *mirror_conf)
+{
+	int i;
+
+	for (i = 0; i < IXGBE_MAX_MIRROR_RULES; i++) {
+		if (!(filter_info->mirror_mask & (1 << i))) {
+			filter_info->mirror_mask |= 1 << i;
+			mirror_conf->rule_id = i;
+			filter_info->mirror_filters[i] = *mirror_conf;
+			return i;
+		}
+	}
+	return -1;
+}
+
+static inline int
+ixgbe_mirror_filter_remove(struct ixgbe_filter_info *filter_info,
+			      uint8_t idx)
+{
+	if (idx >= IXGBE_MAX_MIRROR_RULES)
+		return -1;
+	filter_info->mirror_mask &= ~(1 << idx);
+	memset(&filter_info->mirror_filters[idx], 0,
+	       sizeof(filter_info->mirror_filters[0]));
+	return idx;
+}
+
 #endif /* _IXGBE_ETHDEV_H_ */