Skip to contentSkip to conversation

net/mlx5: improve MAC address and VLAN add latency

PATCH Superseded Dariusz Sosnowski 6 participants 29 messages Oct 17, 2024 – Nov 8, 2024

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

cover net/mlx5: improve MAC address and VLAN add latency

Whenever a new MAC address is added to the port, mlx5 PMD will:

- Add this address to dev->data->mac_addrs[].
- Destroy all control flow rules.
- Recreate all control flow rules.

Similar logic is also implemented for VLAN filters.

Because of such logic, the latency of adding the new MAC address
(i.e., latency of rte_eth_dev_mac_addr_add() function call)
is actually linear to number of MAC addresses already configured.
Since each operation of creating/destroying a control flow rule,
involves an ioctl() syscall, on some setups the latency of adding
a single MAC address can reach ~100ms, when port is operating with >= 100 MAC addresses. The same problem exists for VLAN filters (and even compounded by it).

This patchset aims to resolve these issues,
by reworking how mlx5 PMD handles adding/removing MAC addresses and VLAN filters. Instead of recreating all control flow rules,
only necessary flow rules will be created/removed on each operation, thus minimizing number of syscalls triggered.

Summary of patches:

- Patch 1-2 - Extends existing mlx5_hw_ctrl_flow_type enum with special variants, which will be used for tracking MAC and VLAN control flow rules.
- Patch 3-4 - Refactors HWS code for control flow rule creation to allow
creation of specific control flow rules with unicast MAC/VLAN match.
Also functions are added for deletion of specific rules.
- Patch 5-6 - Prepares the control flow rules list, used by HWS flow engine,
to be used by other flow engine.
Goal is to reuse the similar logic in Verbs and DV flow engines.
- Patch 7-8 - Adjusts legacy flow engines, so that unicast DMAC/VLAN control flow rules are added to the control flow rules list.
Also exposes functions for creating/destroying specific ones.
- Patch 9-10 - Extends mlx5_traffic_* interface with mlx5_traffic_mac_add/remove and mlx5_traffic_vlan_add/remove functions.
They are used in implementations of DPDK APIs for adding/removing MAC addresses/VLAN filters and their goal is to update the set of control flow rules in a minimal number of steps possible, without recreating the rules.

As a result of these patches the time to add 128th MAC address, after 127th was added drops **from ~72 ms to ~197 us** (at least on my setup).

Dariusz Sosnowski (10):
net/mlx5: track unicast DMAC control flow rules net/mlx5: add checking if unicast flow rule exists net/mlx5: rework creation of unicast flow rules net/mlx5: support destroying unicast flow rules net/mlx5: rename control flow rules types net/mlx5: shared init of control flow rules net/mlx5: add legacy unicast flow rules management net/mlx5: add legacy unicast flow rule registration net/mlx5: add dynamic unicast flow rule management net/mlx5: optimize MAC address and VLAN filter handling

 drivers/net/mlx5/linux/mlx5_os.c      |   3 +
 drivers/net/mlx5/meson.build          |   1 +
 drivers/net/mlx5/mlx5.h               |  62 +++--
 drivers/net/mlx5/mlx5_flow.c          | 149 ++++++++++-
 drivers/net/mlx5/mlx5_flow.h          |  36 +++
 drivers/net/mlx5/mlx5_flow_hw.c       | 349 ++++++++++++++++++++------
 drivers/net/mlx5/mlx5_flow_hw_stubs.c |  68 +++++
 drivers/net/mlx5/mlx5_mac.c           |  41 ++-
 drivers/net/mlx5/mlx5_trigger.c       | 262 ++++++++++++++++++-
 drivers/net/mlx5/mlx5_vlan.c          |   9 +-
 drivers/net/mlx5/windows/mlx5_os.c    |   3 +
 11 files changed, 867 insertions(+), 116 deletions(-)
 create mode 100644 drivers/net/mlx5/mlx5_flow_hw_stubs.c

--
2.39.5

#1 lore raw

PATCH 1/10 net/mlx5: track unicast DMAC control flow rules

All control flow rules in NIC Rx domain, created by HWS flow engine, were assigned MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS type. To allow checking if a flow rule with given DMAC or VLAN were created, the list of associated types is extended with:

- type for unicast DMAC flow rules,
- type for unicast DMAC with VLAN flow rules.

These will be used in the follow up commit,
which adds functions for checking if a given control flow rule exists.

---
 drivers/net/mlx5/mlx5.h         | 15 +++++++++++++++
 drivers/net/mlx5/mlx5_flow_hw.c | 11 +++++++----
 2 files changed, 22 insertions(+), 4 deletions(-)
drivers/net/mlx5/mlx5.h +15 -0
index 18b4c15a26..80829be5b4 100644
@@ -1796,6 +1796,8 @@ enum mlx5_hw_ctrl_flow_type {
 	MLX5_HW_CTRL_FLOW_TYPE_TX_REPR_MATCH,
 	MLX5_HW_CTRL_FLOW_TYPE_LACP_RX,
 	MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS,
+	MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC,
+	MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN,
 };
 
 /** Additional info about control flow rule. */
@@ -1813,6 +1815,19 @@ struct mlx5_hw_ctrl_flow_info {
 		 * then fields contains matching SQ number.
 		 */
 		uint32_t tx_repr_sq;
+		/** Contains data relevant for unicast control flow rules. */
+		struct {
+			/**
+			 * If control flow is a unicast DMAC (or with VLAN) flow rule,
+			 * then this field contains DMAC.
+			 */
+			struct rte_ether_addr dmac;
+			/**
+			 * If control flow is a unicast DMAC with VLAN flow rule,
+			 * then this field contains VLAN ID.
+			 */
+			uint16_t vlan;
+		} uc;
 	};
 };
 
drivers/net/mlx5/mlx5_flow_hw.c +7 -4
index c5ddd1d404..f6918825eb 100644
@@ -15908,7 +15908,7 @@ __flow_hw_ctrl_flows_unicast(struct rte_eth_dev *dev,
 		{ .type = RTE_FLOW_ACTION_TYPE_END },
 	};
 	struct mlx5_hw_ctrl_flow_info flow_info = {
-		.type = MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS,
+		.type = MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC,
 	};
 	const struct rte_ether_addr cmp = {
 		.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
@@ -15932,7 +15932,8 @@ __flow_hw_ctrl_flows_unicast(struct rte_eth_dev *dev,
 
 		if (!memcmp(mac, &cmp, sizeof(*mac)))
 			continue;
-		memcpy(&eth_spec.hdr.dst_addr.addr_bytes, mac->addr_bytes, RTE_ETHER_ADDR_LEN);
+		eth_spec.hdr.dst_addr = *mac;
+		flow_info.uc.dmac = *mac;
 		if (flow_hw_create_ctrl_flow(dev, dev,
 					     tbl, items, 0, actions, 0, &flow_info, false))
 			return -rte_errno;
@@ -15954,7 +15955,7 @@ __flow_hw_ctrl_flows_unicast_vlan(struct rte_eth_dev *dev,
 		{ .type = RTE_FLOW_ACTION_TYPE_END },
 	};
 	struct mlx5_hw_ctrl_flow_info flow_info = {
-		.type = MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS,
+		.type = MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN,
 	};
 	const struct rte_ether_addr cmp = {
 		.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
@@ -15979,13 +15980,15 @@ __flow_hw_ctrl_flows_unicast_vlan(struct rte_eth_dev *dev,
 
 		if (!memcmp(mac, &cmp, sizeof(*mac)))
 			continue;
-		memcpy(&eth_spec.hdr.dst_addr.addr_bytes, mac->addr_bytes, RTE_ETHER_ADDR_LEN);
+		eth_spec.hdr.dst_addr = *mac;
+		flow_info.uc.dmac = *mac;
 		for (j = 0; j < priv->vlan_filter_n; ++j) {
 			uint16_t vlan = priv->vlan_filter[j];
 			struct rte_flow_item_vlan vlan_spec = {
 				.hdr.vlan_tci = rte_cpu_to_be_16(vlan),
 			};
 
+			flow_info.uc.vlan = vlan;
 			items[1].spec = &vlan_spec;
 			if (flow_hw_create_ctrl_flow(dev, dev, tbl, items, 0, actions, 0,
 						     &flow_info, false))
Signature · 1 line
2.39.5
#2 lore raw

PATCH 2/10 net/mlx5: add checking if unicast flow rule exists

In reply to Dariusz Sosnowski

Add 2 internal functions for checking if:

- unicast DMAC control flow rule or
- unicast DMAC with VLAN control flow rule,

was created.

---
 drivers/net/mlx5/mlx5.h      | 11 +++++++++++
 drivers/net/mlx5/mlx5_flow.c | 37 ++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)
drivers/net/mlx5/mlx5.h +11 -0
index 80829be5b4..3551b793d6 100644
@@ -1831,6 +1831,17 @@ struct mlx5_hw_ctrl_flow_info {
 	};
 };
 
+/** Returns true if a control flow rule with unicast DMAC match on given address was created. */
+bool mlx5_ctrl_flow_uc_dmac_exists(struct rte_eth_dev *dev, const struct rte_ether_addr *addr);
+
+/**
+ * Returns true if a control flow rule with unicast DMAC and VLAN match
+ * on given values was created.
+ */
+bool mlx5_ctrl_flow_uc_dmac_vlan_exists(struct rte_eth_dev *dev,
+					const struct rte_ether_addr *addr,
+					const uint16_t vid);
+
 /** Entry for tracking control flow rules in HWS. */
 struct mlx5_hw_ctrl_flow {
 	LIST_ENTRY(mlx5_hw_ctrl_flow) next;
drivers/net/mlx5/mlx5_flow.c +37 -0
index effc61cdc9..69f8bd8d97 100644
@@ -12180,3 +12180,40 @@ rte_pmd_mlx5_destroy_geneve_tlv_parser(void *handle)
 	return -rte_errno;
 #endif
 }
+
+bool
+mlx5_ctrl_flow_uc_dmac_exists(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
+{
+	struct mlx5_priv *priv = dev->data->dev_private;
+	struct mlx5_hw_ctrl_flow *entry;
+	bool exists = false;
+
+	LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
+		if (entry->info.type == MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC &&
+		    rte_is_same_ether_addr(addr, &entry->info.uc.dmac)) {
+			exists = true;
+			break;
+		}
+	}
+	return exists;
+}
+
+bool
+mlx5_ctrl_flow_uc_dmac_vlan_exists(struct rte_eth_dev *dev,
+				   const struct rte_ether_addr *addr,
+				   const uint16_t vid)
+{
+	struct mlx5_priv *priv = dev->data->dev_private;
+	struct mlx5_hw_ctrl_flow *entry;
+	bool exists = false;
+
+	LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
+		if (entry->info.type == MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN &&
+		    rte_is_same_ether_addr(addr, &entry->info.uc.dmac) &&
+		    vid == entry->info.uc.vlan) {
+			exists = true;
+			break;
+		}
+	}
+	return exists;
+}
Signature · 1 line
2.39.5
#3 lore raw

PATCH 3/10 net/mlx5: rework creation of unicast flow rules

In reply to Dariusz Sosnowski

Rework the code responsible for creation of unicast control flow rules, to allow creation of:

- unicast DMAC flow rules and
- unicast DMAC with VMAN flow rules,

outside of mlx5_traffic_enable() called when port is started.

---
 drivers/net/mlx5/meson.build          |   1 +
 drivers/net/mlx5/mlx5_flow.h          |   9 ++
 drivers/net/mlx5/mlx5_flow_hw.c       | 215 ++++++++++++++++++++------
 drivers/net/mlx5/mlx5_flow_hw_stubs.c |  41 +++++
 4 files changed, 219 insertions(+), 47 deletions(-)
 create mode 100644 drivers/net/mlx5/mlx5_flow_hw_stubs.c
drivers/net/mlx5/meson.build +1 -0
index eb5eb2cce7..0114673491 100644
@@ -23,6 +23,7 @@ sources = files(
         'mlx5_flow_dv.c',
         'mlx5_flow_aso.c',
         'mlx5_flow_flex.c',
+        'mlx5_flow_hw_stubs.c',
         'mlx5_mac.c',
         'mlx5_rss.c',
         'mlx5_rx.c',
drivers/net/mlx5/mlx5_flow.h +9 -0
index 86a1476879..2ff0b25d4d 100644
@@ -2990,6 +2990,15 @@ struct mlx5_flow_hw_ctrl_fdb {
 #define MLX5_CTRL_VLAN_FILTER    (RTE_BIT32(6))
 
 int mlx5_flow_hw_ctrl_flows(struct rte_eth_dev *dev, uint32_t flags);
+
+/** Create a control flow rule for matching unicast DMAC (HWS). */
+int mlx5_flow_hw_ctrl_flow_dmac(struct rte_eth_dev *dev, const struct rte_ether_addr *addr);
+
+/** Create a control flow rule for matching unicast DMAC with VLAN (HWS). */
+int mlx5_flow_hw_ctrl_flow_dmac_vlan(struct rte_eth_dev *dev,
+				     const struct rte_ether_addr *addr,
+				     const uint16_t vlan);
+
 void mlx5_flow_hw_cleanup_ctrl_rx_templates(struct rte_eth_dev *dev);
 
 int mlx5_flow_group_to_table(struct rte_eth_dev *dev,
drivers/net/mlx5/mlx5_flow_hw.c +168 -47

281 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_hw_stubs.c new file +41 -0

41 lines not on this page · raw message

Signature · 1 line
2.39.5
#4 lore raw

PATCH 4/10 net/mlx5: support destroying unicast flow rules

In reply to Dariusz Sosnowski

This patch adds support for destroying:

- unicast DMAC control flow rules and
- unicast DMAC with VLAN control flow rules,

without affecting any other control flow rules,
when HWS flow engine is used.

---
 drivers/net/mlx5/mlx5_flow.h          |  8 +++
 drivers/net/mlx5/mlx5_flow_hw.c       | 72 +++++++++++++++++++++++++++
 drivers/net/mlx5/mlx5_flow_hw_stubs.c | 27 ++++++++++
 3 files changed, 107 insertions(+)
drivers/net/mlx5/mlx5_flow.h +8 -0
index 2ff0b25d4d..165d17e40a 100644
@@ -2994,11 +2994,19 @@ int mlx5_flow_hw_ctrl_flows(struct rte_eth_dev *dev, uint32_t flags);
 /** Create a control flow rule for matching unicast DMAC (HWS). */
 int mlx5_flow_hw_ctrl_flow_dmac(struct rte_eth_dev *dev, const struct rte_ether_addr *addr);
 
+/** Destroy a control flow rule for matching unicast DMAC (HWS). */
+int mlx5_flow_hw_ctrl_flow_dmac_destroy(struct rte_eth_dev *dev, const struct rte_ether_addr *addr);
+
 /** Create a control flow rule for matching unicast DMAC with VLAN (HWS). */
 int mlx5_flow_hw_ctrl_flow_dmac_vlan(struct rte_eth_dev *dev,
 				     const struct rte_ether_addr *addr,
 				     const uint16_t vlan);
 
+/** Destroy a control flow rule for matching unicast DMAC with VLAN (HWS). */
+int mlx5_flow_hw_ctrl_flow_dmac_vlan_destroy(struct rte_eth_dev *dev,
+					     const struct rte_ether_addr *addr,
+					     const uint16_t vlan);
+
 void mlx5_flow_hw_cleanup_ctrl_rx_templates(struct rte_eth_dev *dev);
 
 int mlx5_flow_group_to_table(struct rte_eth_dev *dev,
drivers/net/mlx5/mlx5_flow_hw.c +72 -0

84 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_hw_stubs.c +27 -0
index 985c046056..0e79e6c1f2 100644
@@ -26,6 +26,19 @@ mlx5_flow_hw_ctrl_flow_dmac(struct rte_eth_dev *dev __rte_unused,
 	return -rte_errno;
 }
 
+/*
+ * This is a stub for the real implementation of this function in mlx5_flow_hw.c in case:
+ * - PMD is compiled on Windows or
+ * - available rdma-core does not support HWS.
+ */
+__rte_weak int
+mlx5_flow_hw_ctrl_flow_dmac_destroy(struct rte_eth_dev *dev __rte_unused,
+				    const struct rte_ether_addr *addr __rte_unused)
+{
+	rte_errno = ENOTSUP;
+	return -rte_errno;
+}
+
 /*
  * This is a stub for the real implementation of this function in mlx5_flow_hw.c in case:
  * - PMD is compiled on Windows or
@@ -39,3 +52,17 @@ mlx5_flow_hw_ctrl_flow_dmac_vlan(struct rte_eth_dev *dev __rte_unused,
 	rte_errno = ENOTSUP;
 	return -rte_errno;
 }
+
+/*
+ * This is a stub for the real implementation of this function in mlx5_flow_hw.c in case:
+ * - PMD is compiled on Windows or
+ * - available rdma-core does not support HWS.
+ */
+__rte_weak int
+mlx5_flow_hw_ctrl_flow_dmac_vlan_destroy(struct rte_eth_dev *dev __rte_unused,
+					 const struct rte_ether_addr *addr __rte_unused,
+					 const uint16_t vlan __rte_unused)
+{
+	rte_errno = ENOTSUP;
+	return -rte_errno;
+}
Signature · 1 line
2.39.5
#5 lore raw

PATCH 5/10 net/mlx5: rename control flow rules types

In reply to Dariusz Sosnowski

All structs and enumerations used for managenement of HWS control flow rules do not really depend on HWS itself. In order to allow their reuse with Verbs and DV flow engines and allow fine-grained creation/destruction of unicast DMAC (with VLAN) flow rules with these flow engines, this patch renames all related structs and enumerations.
All are renamed as follows:

- Enum mlx5_hw_ctrl_flow_type renamed to mlx5_ctrl_flow_type.
- Enum prefix MLX5_HW_CTRL_FLOW_TYPE_ changes to MLX5_CTRL_FLOW_TYPE_
- Struct mlx5_hw_ctrl_flow_info renamed to mlx5_ctrl_flow_info.
- Struct mlx5_hw_ctrl_flow renamed to mlx5_ctrl_flow_entry.

---
 drivers/net/mlx5/mlx5.h         | 36 ++++++++--------
 drivers/net/mlx5/mlx5_flow.c    |  8 ++--
 drivers/net/mlx5/mlx5_flow_hw.c | 74 ++++++++++++++++-----------------
 3 files changed, 59 insertions(+), 59 deletions(-)
drivers/net/mlx5/mlx5.h +18 -18
index 3551b793d6..a51727526f 100644
@@ -1787,23 +1787,23 @@ struct mlx5_obj_ops {
 
 #define MLX5_RSS_HASH_FIELDS_LEN RTE_DIM(mlx5_rss_hash_fields)
 
-enum mlx5_hw_ctrl_flow_type {
-	MLX5_HW_CTRL_FLOW_TYPE_GENERAL,
-	MLX5_HW_CTRL_FLOW_TYPE_SQ_MISS_ROOT,
-	MLX5_HW_CTRL_FLOW_TYPE_SQ_MISS,
-	MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_JUMP,
-	MLX5_HW_CTRL_FLOW_TYPE_TX_META_COPY,
-	MLX5_HW_CTRL_FLOW_TYPE_TX_REPR_MATCH,
-	MLX5_HW_CTRL_FLOW_TYPE_LACP_RX,
-	MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS,
-	MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC,
-	MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN,
+enum mlx5_ctrl_flow_type {
+	MLX5_CTRL_FLOW_TYPE_GENERAL,
+	MLX5_CTRL_FLOW_TYPE_SQ_MISS_ROOT,
+	MLX5_CTRL_FLOW_TYPE_SQ_MISS,
+	MLX5_CTRL_FLOW_TYPE_DEFAULT_JUMP,
+	MLX5_CTRL_FLOW_TYPE_TX_META_COPY,
+	MLX5_CTRL_FLOW_TYPE_TX_REPR_MATCH,
+	MLX5_CTRL_FLOW_TYPE_LACP_RX,
+	MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS,
+	MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC,
+	MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN,
 };
 
 /** Additional info about control flow rule. */
-struct mlx5_hw_ctrl_flow_info {
+struct mlx5_ctrl_flow_info {
 	/** Determines the kind of control flow rule. */
-	enum mlx5_hw_ctrl_flow_type type;
+	enum mlx5_ctrl_flow_type type;
 	union {
 		/**
 		 * If control flow is a SQ miss flow (root or not),
@@ -1843,8 +1843,8 @@ bool mlx5_ctrl_flow_uc_dmac_vlan_exists(struct rte_eth_dev *dev,
 					const uint16_t vid);
 
 /** Entry for tracking control flow rules in HWS. */
-struct mlx5_hw_ctrl_flow {
-	LIST_ENTRY(mlx5_hw_ctrl_flow) next;
+struct mlx5_ctrl_flow_entry {
+	LIST_ENTRY(mlx5_ctrl_flow_entry) next;
 	/**
 	 * Owner device is a port on behalf of which flow rule was created.
 	 *
@@ -1856,7 +1856,7 @@ struct mlx5_hw_ctrl_flow {
 	/** Pointer to flow rule handle. */
 	struct rte_flow *flow;
 	/** Additional information about the control flow rule. */
-	struct mlx5_hw_ctrl_flow_info info;
+	struct mlx5_ctrl_flow_info info;
 };
 
 /* HW Steering port configuration passed to rte_flow_configure(). */
@@ -1965,8 +1965,8 @@ struct mlx5_priv {
 	struct mlx5_drop drop_queue; /* Flow drop queues. */
 	void *root_drop_action; /* Pointer to root drop action. */
 	rte_spinlock_t hw_ctrl_lock;
-	LIST_HEAD(hw_ctrl_flow, mlx5_hw_ctrl_flow) hw_ctrl_flows;
-	LIST_HEAD(hw_ext_ctrl_flow, mlx5_hw_ctrl_flow) hw_ext_ctrl_flows;
+	LIST_HEAD(hw_ctrl_flow, mlx5_ctrl_flow_entry) hw_ctrl_flows;
+	LIST_HEAD(hw_ext_ctrl_flow, mlx5_ctrl_flow_entry) hw_ext_ctrl_flows;
 	struct mlx5_flow_hw_ctrl_fdb *hw_ctrl_fdb;
 	struct rte_flow_pattern_template *hw_tx_repr_tagging_pt;
 	struct rte_flow_actions_template *hw_tx_repr_tagging_at;
drivers/net/mlx5/mlx5_flow.c +4 -4
index 69f8bd8d97..af79956eaa 100644
@@ -12185,11 +12185,11 @@ bool
 mlx5_ctrl_flow_uc_dmac_exists(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
 {
 	struct mlx5_priv *priv = dev->data->dev_private;
-	struct mlx5_hw_ctrl_flow *entry;
+	struct mlx5_ctrl_flow_entry *entry;
 	bool exists = false;
 
 	LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
-		if (entry->info.type == MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC &&
+		if (entry->info.type == MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC &&
 		    rte_is_same_ether_addr(addr, &entry->info.uc.dmac)) {
 			exists = true;
 			break;
@@ -12204,11 +12204,11 @@ mlx5_ctrl_flow_uc_dmac_vlan_exists(struct rte_eth_dev *dev,
 				   const uint16_t vid)
 {
 	struct mlx5_priv *priv = dev->data->dev_private;
-	struct mlx5_hw_ctrl_flow *entry;
+	struct mlx5_ctrl_flow_entry *entry;
 	bool exists = false;
 
 	LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
-		if (entry->info.type == MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN &&
+		if (entry->info.type == MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN &&
 		    rte_is_same_ether_addr(addr, &entry->info.uc.dmac) &&
 		    vid == entry->info.uc.vlan) {
 			exists = true;
drivers/net/mlx5/mlx5_flow_hw.c +37 -37

206 lines not on this page · raw message

Signature · 1 line
2.39.5
#6 lore raw

PATCH 6/10 net/mlx5: shared init of control flow rules

In reply to Dariusz Sosnowski

Control flow rules lists and control flow rule lock can be reused between all flow engines, but their initialization was done in flow_hw_configure() implementation.
This patch moves it to mlx5_dev_spawn(),
which is called for Verbs, DV and HWS flow engines.

---
 drivers/net/mlx5/linux/mlx5_os.c   | 3 +++
 drivers/net/mlx5/mlx5_flow_hw.c    | 3 ---
 drivers/net/mlx5/windows/mlx5_os.c | 3 +++
 3 files changed, 6 insertions(+), 3 deletions(-)
drivers/net/mlx5/linux/mlx5_os.c +3 -0
index 0a8de88759..c8d7fdb8dd 100644
@@ -1701,6 +1701,9 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 		    (sh->config.dv_flow_en == 1 && mlx5_flow_discover_ipv6_tc_support(eth_dev)))
 			sh->phdev->config.ipv6_tc_fallback = MLX5_IPV6_TC_FALLBACK;
 	}
+	rte_spinlock_init(&priv->hw_ctrl_lock);
+	LIST_INIT(&priv->hw_ctrl_flows);
+	LIST_INIT(&priv->hw_ext_ctrl_flows);
 	if (priv->sh->config.dv_flow_en == 2) {
 #ifdef HAVE_MLX5_HWS_SUPPORT
 		if (priv->sh->config.dv_esw_en) {
drivers/net/mlx5/mlx5_flow_hw.c +0 -3
index 0d8224b8de..9ab66f5929 100644
@@ -11832,9 +11832,6 @@ __flow_hw_configure(struct rte_eth_dev *dev,
 	if (!priv->dr_ctx)
 		goto err;
 	priv->nb_queue = nb_q_updated;
-	rte_spinlock_init(&priv->hw_ctrl_lock);
-	LIST_INIT(&priv->hw_ctrl_flows);
-	LIST_INIT(&priv->hw_ext_ctrl_flows);
 	ret = flow_hw_action_template_drop_init(dev, error);
 	if (ret)
 		goto err;
drivers/net/mlx5/windows/mlx5_os.c +3 -0
index 0ebd233595..80f1679388 100644
@@ -600,6 +600,9 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 	}
 	mlx5_flow_counter_mode_config(eth_dev);
 	mlx5_queue_counter_id_prepare(eth_dev);
+	rte_spinlock_init(&priv->hw_ctrl_lock);
+	LIST_INIT(&priv->hw_ctrl_flows);
+	LIST_INIT(&priv->hw_ext_ctrl_flows);
 	return eth_dev;
 error:
 	if (priv) {
Signature · 1 line
2.39.5
#7 lore raw

PATCH 7/10 net/mlx5: add legacy unicast flow rules management

In reply to Dariusz Sosnowski

This patch adds the following internal functions for creation of unicast DMAC flow rules:

- mlx5_legacy_dmac_flow_create() - simple wrapper over mlx5_ctrl_flow().
- mlx5_legacy_dmac_vlan_flow_create() - simple wrapper over mlx5_ctrl_flow_vlan().

These will be used as a basis for implementing dynamic additions of unicast DMAC or unicast DMAC with VLAN control flow rules when new addresses/VLANs are added.

Also, this path adds the following internal functions for destructions of unicast DMAC flow rules:

- mlx5_legacy_ctrl_flow_destroy() - assuming a flow rule is on the control flow rule list, destroy it.
- mlx5_legacy_dmac_flow_destroy() - find and destroy a flow rule with given unicast DMAC.
- mlx5_legacy_dmac_flow_destroy() - find and destroy a flow rule with given unicast DMAC and VLAN ID.

These will be used as a basis for implementing dynamic removals of unicast DMAC or unicast DMAC with VLAN control flow rules when addresses/VLANs are removed.

At the moment, no relevant flow rules are registered on the list when working with Verbs or DV flow engine.
This will be added in the follow up commit.

---
 drivers/net/mlx5/mlx5_flow.c | 80 ++++++++++++++++++++++++++++++++++++
 drivers/net/mlx5/mlx5_flow.h | 19 +++++++++
 2 files changed, 99 insertions(+)
drivers/net/mlx5/mlx5_flow.c +80 -0
index af79956eaa..463edae70e 100644
@@ -8534,6 +8534,86 @@ mlx5_ctrl_flow(struct rte_eth_dev *dev,
 	return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
 }
 
+int
+mlx5_legacy_dmac_flow_create(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
+{
+	struct rte_flow_item_eth unicast = {
+		.hdr.dst_addr = *addr,
+	};
+	struct rte_flow_item_eth unicast_mask = {
+		.hdr.dst_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff",
+	};
+
+	return mlx5_ctrl_flow(dev, &unicast, &unicast_mask);
+}
+
+int
+mlx5_legacy_dmac_vlan_flow_create(struct rte_eth_dev *dev,
+				  const struct rte_ether_addr *addr,
+				  const uint16_t vid)
+{
+	struct rte_flow_item_eth unicast_spec = {
+		.hdr.dst_addr = *addr,
+	};
+	struct rte_flow_item_eth unicast_mask = {
+		.hdr.dst_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff",
+	};
+	struct rte_flow_item_vlan vlan_spec = {
+		.hdr.vlan_tci = rte_cpu_to_be_16(vid),
+	};
+	struct rte_flow_item_vlan vlan_mask = rte_flow_item_vlan_mask;
+
+	return mlx5_ctrl_flow_vlan(dev, &unicast_spec, &unicast_mask, &vlan_spec, &vlan_mask);
+}
+
+void
+mlx5_legacy_ctrl_flow_destroy(struct rte_eth_dev *dev, struct mlx5_ctrl_flow_entry *entry)
+{
+	uintptr_t flow_idx;
+
+	flow_idx = (uintptr_t)entry->flow;
+	mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_CTL, flow_idx);
+	LIST_REMOVE(entry, next);
+	mlx5_free(entry);
+}
+
+int
+mlx5_legacy_dmac_flow_destroy(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
+{
+	struct mlx5_priv *priv = dev->data->dev_private;
+	struct mlx5_ctrl_flow_entry *entry;
+
+	LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
+		if (entry->info.type != MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC ||
+		    !rte_is_same_ether_addr(addr, &entry->info.uc.dmac))
+			continue;
+
+		mlx5_legacy_ctrl_flow_destroy(dev, entry);
+		return 0;
+	}
+	return 0;
+}
+
+int
+mlx5_legacy_dmac_vlan_flow_destroy(struct rte_eth_dev *dev,
+				   const struct rte_ether_addr *addr,
+				   const uint16_t vid)
+{
+	struct mlx5_priv *priv = dev->data->dev_private;
+	struct mlx5_ctrl_flow_entry *entry;
+
+	LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
+		if (entry->info.type != MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN ||
+		    !rte_is_same_ether_addr(addr, &entry->info.uc.dmac) ||
+		    vid != entry->info.uc.vlan)
+			continue;
+
+		mlx5_legacy_ctrl_flow_destroy(dev, entry);
+		return 0;
+	}
+	return 0;
+}
+
 /**
  * Create default miss flow rule matching lacp traffic
  *
drivers/net/mlx5/mlx5_flow.h +19 -0
index 165d17e40a..db56ae051d 100644
@@ -2991,6 +2991,25 @@ struct mlx5_flow_hw_ctrl_fdb {
 
 int mlx5_flow_hw_ctrl_flows(struct rte_eth_dev *dev, uint32_t flags);
 
+/** Create a control flow rule for matching unicast DMAC with VLAN (Verbs and DV). */
+int mlx5_legacy_dmac_flow_create(struct rte_eth_dev *dev, const struct rte_ether_addr *addr);
+
+/** Destroy a control flow rule for matching unicast DMAC with VLAN (Verbs and DV). */
+int mlx5_legacy_dmac_flow_destroy(struct rte_eth_dev *dev, const struct rte_ether_addr *addr);
+
+/** Create a control flow rule for matching unicast DMAC with VLAN (Verbs and DV). */
+int mlx5_legacy_dmac_vlan_flow_create(struct rte_eth_dev *dev,
+				      const struct rte_ether_addr *addr,
+				      const uint16_t vid);
+
+/** Destroy a control flow rule for matching unicast DMAC with VLAN (Verbs and DV). */
+int mlx5_legacy_dmac_vlan_flow_destroy(struct rte_eth_dev *dev,
+				      const struct rte_ether_addr *addr,
+				      const uint16_t vid);
+
+/** Destroy a control flow rule registered on port level control flow rule type. */
+void mlx5_legacy_ctrl_flow_destroy(struct rte_eth_dev *dev, struct mlx5_ctrl_flow_entry *entry);
+
 /** Create a control flow rule for matching unicast DMAC (HWS). */
 int mlx5_flow_hw_ctrl_flow_dmac(struct rte_eth_dev *dev, const struct rte_ether_addr *addr);
 
Signature · 1 line
2.39.5
#8 lore raw

PATCH 8/10 net/mlx5: add legacy unicast flow rule registration

In reply to Dariusz Sosnowski

Whenever a unicast DMAC or unicast DMAC with VLAN ID control flow rule is created when working with Verbs or DV flow engine,
add this flow rule to the control flow rule list,
with information required for recognizing it.

---
 drivers/net/mlx5/mlx5_flow.c    | 32 +++++++++++++++++++++++++++++---
 drivers/net/mlx5/mlx5_trigger.c | 26 ++++++++++++++++++++++++--
 2 files changed, 53 insertions(+), 5 deletions(-)
drivers/net/mlx5/mlx5_flow.c +29 -3
index 463edae70e..2038f78481 100644
@@ -8495,8 +8495,9 @@ mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
 			.type = RTE_FLOW_ACTION_TYPE_END,
 		},
 	};
-	uint32_t flow_idx;
+	uintptr_t flow_idx;
 	struct rte_flow_error error;
+	struct mlx5_ctrl_flow_entry *entry;
 	unsigned int i;
 
 	if (!priv->reta_idx_n || !priv->rxqs_n) {
@@ -8506,11 +8507,36 @@ mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
 		action_rss.types = 0;
 	for (i = 0; i != priv->reta_idx_n; ++i)
 		queue[i] = (*priv->reta_idx)[i];
+
+	entry = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*entry), alignof(typeof(*entry)), SOCKET_ID_ANY);
+	if (entry == NULL) {
+		rte_errno = ENOMEM;
+		goto err;
+	}
+
+	entry->owner_dev = dev;
+	if (vlan_spec == NULL) {
+		entry->info.type = MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC;
+	} else {
+		entry->info.type = MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN;
+		entry->info.uc.vlan = rte_be_to_cpu_16(vlan_spec->hdr.vlan_tci);
+	}
+	entry->info.uc.dmac = eth_spec->hdr.dst_addr;
+
 	flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
 				    &attr, items, actions, false, &error);
-	if (!flow_idx)
-		return -rte_errno;
+	if (!flow_idx) {
+		mlx5_free(entry);
+		goto err;
+	}
+
+	entry->flow = (struct rte_flow *)flow_idx;
+	LIST_INSERT_HEAD(&priv->hw_ctrl_flows, entry, next);
+
 	return 0;
+
+err:
+	return -rte_errno;
 }
 
 /**
drivers/net/mlx5/mlx5_trigger.c +24 -2
index bf836c92fc..4fa9319c4d 100644
@@ -20,6 +20,8 @@
 #include "mlx5_utils.h"
 #include "rte_pmd_mlx5.h"
 
+static void mlx5_traffic_disable_legacy(struct rte_eth_dev *dev);
+
 /**
  * Stop traffic on Tx queues.
  *
@@ -1736,11 +1738,31 @@ mlx5_traffic_enable(struct rte_eth_dev *dev)
 	return 0;
 error:
 	ret = rte_errno; /* Save rte_errno before cleanup. */
-	mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_CTL, false);
+	mlx5_traffic_disable_legacy(dev);
 	rte_errno = ret; /* Restore rte_errno. */
 	return -rte_errno;
 }
 
+static void
+mlx5_traffic_disable_legacy(struct rte_eth_dev *dev)
+{
+	struct mlx5_priv *priv = dev->data->dev_private;
+	struct mlx5_ctrl_flow_entry *entry;
+	struct mlx5_ctrl_flow_entry *tmp;
+
+	/*
+	 * Free registered control flow rules first,
+	 * to free the memory allocated for list entries
+	 */
+	entry = LIST_FIRST(&priv->hw_ctrl_flows);
+	while (entry != NULL) {
+		tmp = LIST_NEXT(entry, next);
+		mlx5_legacy_ctrl_flow_destroy(dev, entry);
+		entry = tmp;
+	}
+
+	mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_CTL, false);
+}
 
 /**
  * Disable traffic flows configured by control plane
@@ -1758,7 +1780,7 @@ mlx5_traffic_disable(struct rte_eth_dev *dev)
 		mlx5_flow_hw_flush_ctrl_flows(dev);
 	else
 #endif
-		mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_CTL, false);
+		mlx5_traffic_disable_legacy(dev);
 }
 
 /**
Signature · 1 line
2.39.5
#9 lore raw

PATCH 9/10 net/mlx5: add dynamic unicast flow rule management

In reply to Dariusz Sosnowski

This patch extens the mlx5_traffic interface with a couple of functions:

- mlx5_traffic_mac_add() - Create an unicast DMAC flow rule, without recreating all control flow rules.
- mlx5_traffic_mac_remove() - Remove an unicast DMAC flow rule, without recreating all control flow rules.
- mlx5_traffic_mac_vlan_add() - Create an unicast DMAC with VLAN flow rule, without recreating all control flow rules.
- mlx5_traffic_mac_vlan_remove() - Remove an unicast DMAC with VLAN flow rule, without recreating all control flow rules.

These functions will be used in the follow up commit, which will modify the behavior of adding/removing MAC address and enabling/disabling VLAN filter in mlx5 PMD.

---
 drivers/net/mlx5/mlx5.h         |   4 +
 drivers/net/mlx5/mlx5_trigger.c | 236 ++++++++++++++++++++++++++++++++
 2 files changed, 240 insertions(+)
drivers/net/mlx5/mlx5.h +4 -0
index a51727526f..0e026f7bbb 100644
@@ -2372,6 +2372,10 @@ int mlx5_hairpin_bind(struct rte_eth_dev *dev, uint16_t rx_port);
 int mlx5_hairpin_unbind(struct rte_eth_dev *dev, uint16_t rx_port);
 int mlx5_hairpin_get_peer_ports(struct rte_eth_dev *dev, uint16_t *peer_ports,
 				size_t len, uint32_t direction);
+int mlx5_traffic_mac_add(struct rte_eth_dev *dev, const struct rte_ether_addr *addr);
+int mlx5_traffic_mac_remove(struct rte_eth_dev *dev, const struct rte_ether_addr *addr);
+int mlx5_traffic_vlan_add(struct rte_eth_dev *dev, const uint16_t vid);
+int mlx5_traffic_vlan_remove(struct rte_eth_dev *dev, const uint16_t vid);
 
 /* mlx5_flow.c */
 
drivers/net/mlx5/mlx5_trigger.c +236 -0

239 lines not on this page · raw message

Signature · 1 line
2.39.5
#10 lore raw

PATCH 10/10 net/mlx5: optimize MAC address and VLAN filter handling

In reply to Dariusz Sosnowski

This patch:

- Changes MAC address adding/removing handling, so that only required control rules are added/removed.
As a result, rte_eth_dev_mac_addr_add() or rte_eth_dev_mac_addr_remove() calls are faster for mlx5 PMD.
- Changes VLAN filtering handling, so that
only required control flow rules are added/removed.
As a result, rte_eth_dev_vlan_filter() call is faster for mlx5 PMD.

---
 drivers/net/mlx5/mlx5_mac.c  | 41 +++++++++++++++++++++++++-----------
 drivers/net/mlx5/mlx5_vlan.c |  9 ++++----
 2 files changed, 33 insertions(+), 17 deletions(-)
drivers/net/mlx5/mlx5_mac.c +29 -12
index 22a756a52b..0e5d2be530 100644
@@ -25,15 +25,25 @@
  *   Pointer to Ethernet device structure.
  * @param index
  *   MAC address index.
+ * @param addr
+ *   If MAC address is actually removed, it will be stored here if pointer is not a NULL.
+ *
+ * @return
+ *   True if there was a MAC address under given index.
  */
-static void
-mlx5_internal_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
+static bool
+mlx5_internal_mac_addr_remove(struct rte_eth_dev *dev,
+			      uint32_t index,
+			      struct rte_ether_addr *addr)
 {
 	MLX5_ASSERT(index < MLX5_MAX_MAC_ADDRESSES);
 	if (rte_is_zero_ether_addr(&dev->data->mac_addrs[index]))
-		return;
+		return false;
 	mlx5_os_mac_addr_remove(dev, index);
+	if (addr != NULL)
+		*addr = dev->data->mac_addrs[index];
 	memset(&dev->data->mac_addrs[index], 0, sizeof(struct rte_ether_addr));
+	return true;
 }
 
 /**
@@ -91,15 +101,15 @@ mlx5_internal_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac,
 void
 mlx5_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
 {
+	struct rte_ether_addr addr = { 0 };
 	int ret;
 
 	if (index >= MLX5_MAX_UC_MAC_ADDRESSES)
 		return;
-	mlx5_internal_mac_addr_remove(dev, index);
-	if (!dev->data->promiscuous) {
-		ret = mlx5_traffic_restart(dev);
+	if (mlx5_internal_mac_addr_remove(dev, index, &addr)) {
+		ret = mlx5_traffic_mac_remove(dev, &addr);
 		if (ret)
-			DRV_LOG(ERR, "port %u cannot restart traffic: %s",
+			DRV_LOG(ERR, "port %u cannot update control flow rules: %s",
 				dev->data->port_id, strerror(rte_errno));
 	}
 }
@@ -132,9 +142,7 @@ mlx5_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac,
 	ret = mlx5_internal_mac_addr_add(dev, mac, index);
 	if (ret < 0)
 		return ret;
-	if (!dev->data->promiscuous)
-		return mlx5_traffic_restart(dev);
-	return 0;
+	return mlx5_traffic_mac_add(dev, mac);
 }
 
 /**
@@ -154,6 +162,12 @@ mlx5_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
 	uint16_t port_id;
 	struct mlx5_priv *priv = dev->data->dev_private;
 	struct mlx5_priv *pf_priv;
+	struct rte_ether_addr old_mac_addr = dev->data->mac_addrs[0];
+	int ret;
+
+	/* ethdev does not check if new default address is the same as the old one. */
+	if (rte_is_same_ether_addr(mac_addr, &old_mac_addr))
+		return 0;
 
 	/*
 	 * Configuring the VF instead of its representor,
@@ -188,7 +202,10 @@ mlx5_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
 
 	DRV_LOG(DEBUG, "port %u setting primary MAC address",
 		dev->data->port_id);
-	return mlx5_mac_addr_add(dev, mac_addr, 0, 0);
+	ret = mlx5_mac_addr_add(dev, mac_addr, 0, 0);
+	if (ret)
+		return ret;
+	return mlx5_traffic_mac_remove(dev, &old_mac_addr);
 }
 
 /**
@@ -208,7 +225,7 @@ mlx5_set_mc_addr_list(struct rte_eth_dev *dev,
 		return -rte_errno;
 	}
 	for (i = MLX5_MAX_UC_MAC_ADDRESSES; i != MLX5_MAX_MAC_ADDRESSES; ++i)
-		mlx5_internal_mac_addr_remove(dev, i);
+		mlx5_internal_mac_addr_remove(dev, i, NULL);
 	i = MLX5_MAX_UC_MAC_ADDRESSES;
 	while (nb_mc_addr--) {
 		ret = mlx5_internal_mac_addr_add(dev, mc_addr_set++, i++);
drivers/net/mlx5/mlx5_vlan.c +4 -5
index e7161b66fe..43a314a679 100644
@@ -54,7 +54,7 @@ mlx5_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
 		MLX5_ASSERT(priv->vlan_filter_n != 0);
 		/* Enabling an existing VLAN filter has no effect. */
 		if (on)
-			goto out;
+			goto no_effect;
 		/* Remove VLAN filter from list. */
 		--priv->vlan_filter_n;
 		memmove(&priv->vlan_filter[i],
@@ -66,14 +66,13 @@ mlx5_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
 		MLX5_ASSERT(i == priv->vlan_filter_n);
 		/* Disabling an unknown VLAN filter has no effect. */
 		if (!on)
-			goto out;
+			goto no_effect;
 		/* Add new VLAN filter. */
 		priv->vlan_filter[priv->vlan_filter_n] = vlan_id;
 		++priv->vlan_filter_n;
 	}
-out:
-	if (dev->data->dev_started)
-		return mlx5_traffic_restart(dev);
+	return on ? mlx5_traffic_vlan_add(dev, vlan_id) : mlx5_traffic_vlan_remove(dev, vlan_id);
+no_effect:
 	return 0;
 }
 
Signature · 1 line
2.39.5
Acked-by on the v1 series
#11 lore raw
In reply to Dariusz Sosnowski

For the entire series:

Quoted 87 lines

-----Original Message-----
From: Dariusz Sosnowski <[email protected]>
Sent: Thursday, October 17, 2024 10:57 AM
To: Slava Ovsiienko <[email protected]>; Bing Zhao <[email protected]>; Ori Kam <[email protected]>; Suanming Mou <[email protected]>; Matan Azrad <[email protected]>
Cc: [email protected]
Subject: [PATCH 00/10] net/mlx5: improve MAC address and VLAN add latency

Whenever a new MAC address is added to the port, mlx5 PMD will:

- Add this address to dev->data->mac_addrs[].
- Destroy all control flow rules.
- Recreate all control flow rules.

Similar logic is also implemented for VLAN filters.

Because of such logic, the latency of adding the new MAC address (i.e., latency of rte_eth_dev_mac_addr_add() function call) is actually linear to number of MAC addresses already configured.
Since each operation of creating/destroying a control flow rule, involves an ioctl() syscall, on some setups the latency of adding a single MAC address can reach ~100ms, when port is operating with >= 100 MAC addresses. The same problem exists for VLAN filters (and even compounded by it).

This patchset aims to resolve these issues, by reworking how mlx5 PMD handles adding/removing MAC addresses and VLAN filters.
Instead of recreating all control flow rules, only necessary flow rules will be created/removed on each operation, thus minimizing number of syscalls triggered.

Summary of patches:

- Patch 1-2 - Extends existing mlx5_hw_ctrl_flow_type enum with special variants,
which will be used for tracking MAC and VLAN control flow rules.
- Patch 3-4 - Refactors HWS code for control flow rule creation to allow creation of specific control flow rules with unicast MAC/VLAN match. Also functions are added for deletion of specific rules.
- Patch 5-6 - Prepares the control flow rules list, used by HWS flow engine, to be used by other flow engine.
Goal is to reuse the similar logic in Verbs and DV flow engines.
- Patch 7-8 - Adjusts legacy flow engines, so that unicast DMAC/VLAN control flow rules
are added to the control flow rules list.
Also exposes functions for creating/destroying specific ones.
- Patch 9-10 - Extends mlx5_traffic_* interface with mlx5_traffic_mac_add/remove and
mlx5_traffic_vlan_add/remove functions.
They are used in implementations of DPDK APIs for adding/removing MAC
addresses/VLAN filters
and their goal is to update the set of control flow rules in a minimal number
of steps possible,
without recreating the rules.

As a result of these patches the time to add 128th MAC address, after 127th was added drops **from ~72 ms to ~197 us** (at least on my setup).

Dariusz Sosnowski (10):
net/mlx5: track unicast DMAC control flow rules net/mlx5: add checking if unicast flow rule exists net/mlx5: rework creation of unicast flow rules net/mlx5: support destroying unicast flow rules net/mlx5: rename control flow rules types net/mlx5: shared init of control flow rules net/mlx5: add legacy unicast flow rules management net/mlx5: add legacy unicast flow rule registration net/mlx5: add dynamic unicast flow rule management net/mlx5: optimize MAC address and VLAN filter handling

 drivers/net/mlx5/linux/mlx5_os.c      |   3 +
 drivers/net/mlx5/meson.build          |   1 +
 drivers/net/mlx5/mlx5.h               |  62 +++--
 drivers/net/mlx5/mlx5_flow.c          | 149 ++++++++++-
 drivers/net/mlx5/mlx5_flow.h          |  36 +++
 drivers/net/mlx5/mlx5_flow_hw.c       | 349 ++++++++++++++++++++------
 drivers/net/mlx5/mlx5_flow_hw_stubs.c |  68 +++++
 drivers/net/mlx5/mlx5_mac.c           |  41 ++-
 drivers/net/mlx5/mlx5_trigger.c       | 262 ++++++++++++++++++-
 drivers/net/mlx5/mlx5_vlan.c          |   9 +-
 drivers/net/mlx5/windows/mlx5_os.c    |   3 +
 11 files changed, 867 insertions(+), 116 deletions(-)  create mode 100644

drivers/net/mlx5/mlx5_flow_hw_stubs.c

--
2.39.5

#12 lore raw

v2 cover net/mlx5: improve MAC address and VLAN add latency

In reply to Dariusz Sosnowski

Whenever a new MAC address is added to the port, mlx5 PMD will:

- Add this address to dev->data->mac_addrs[].
- Destroy all control flow rules.
- Recreate all control flow rules.

Similar logic is also implemented for VLAN filters.

Because of such logic, the latency of adding the new MAC address
(i.e., latency of rte_eth_dev_mac_addr_add() function call)
is actually linear to number of MAC addresses already configured.
Since each operation of creating/destroying a control flow rule,
involves an ioctl() syscall, on some setups the latency of adding
a single MAC address can reach ~100ms, when port is operating with >= 100 MAC addresses. The same problem exists for VLAN filters (and even compounded by it).

This patchset aims to resolve these issues,
by reworking how mlx5 PMD handles adding/removing MAC addresses and VLAN filters. Instead of recreating all control flow rules,
only necessary flow rules will be created/removed on each operation, thus minimizing number of syscalls triggered.

Summary of patches:

- Patch 1-2 - Extends existing mlx5_hw_ctrl_flow_type enum with special variants, which will be used for tracking MAC and VLAN control flow rules.
- Patch 3-4 - Refactors HWS code for control flow rule creation to allow
creation of specific control flow rules with unicast MAC/VLAN match.
Also functions are added for deletion of specific rules.
- Patch 5-6 - Prepares the control flow rules list, used by HWS flow engine,
to be used by other flow engine.
Goal is to reuse the similar logic in Verbs and DV flow engines.
- Patch 7-8 - Adjusts legacy flow engines, so that unicast DMAC/VLAN control flow rules are added to the control flow rules list.
Also exposes functions for creating/destroying specific ones.
- Patch 9-10 - Extends mlx5_traffic_* interface with mlx5_traffic_mac_add/remove and mlx5_traffic_vlan_add/remove functions.
They are used in implementations of DPDK APIs for adding/removing MAC addresses/VLAN filters and their goal is to update the set of control flow rules in a minimal number of steps possible, without recreating the rules.

As a result of these patches the time to add 128th MAC address, after 127th was added drops **from ~72 ms to ~197 us** (at least on my setup).

v2:
- Rebase on top of 24.11-rc1.
- Added Acked-by tags from v1.

Dariusz Sosnowski (10):
net/mlx5: track unicast DMAC control flow rules net/mlx5: add checking if unicast flow rule exists net/mlx5: rework creation of unicast flow rules net/mlx5: support destroying unicast flow rules net/mlx5: rename control flow rules types net/mlx5: shared init of control flow rules net/mlx5: add legacy unicast flow rules management net/mlx5: add legacy unicast flow rule registration net/mlx5: add dynamic unicast flow rule management net/mlx5: optimize MAC address and VLAN filter handling

 drivers/net/mlx5/linux/mlx5_os.c      |   3 +
 drivers/net/mlx5/meson.build          |   1 +
 drivers/net/mlx5/mlx5.h               |  62 +++--
 drivers/net/mlx5/mlx5_flow.c          | 149 ++++++++++-
 drivers/net/mlx5/mlx5_flow.h          |  36 +++
 drivers/net/mlx5/mlx5_flow_hw.c       | 349 ++++++++++++++++++++------
 drivers/net/mlx5/mlx5_flow_hw_stubs.c |  68 +++++
 drivers/net/mlx5/mlx5_mac.c           |  41 ++-
 drivers/net/mlx5/mlx5_trigger.c       | 262 ++++++++++++++++++-
 drivers/net/mlx5/mlx5_vlan.c          |   9 +-
 drivers/net/mlx5/windows/mlx5_os.c    |   3 +
 11 files changed, 867 insertions(+), 116 deletions(-)
 create mode 100644 drivers/net/mlx5/mlx5_flow_hw_stubs.c

--
2.39.5

#13 lore raw

PATCH v2 1/10 net/mlx5: track unicast DMAC control flow rules

All control flow rules in NIC Rx domain, created by HWS flow engine, were assigned MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS type. To allow checking if a flow rule with given DMAC or VLAN were created, the list of associated types is extended with:

- type for unicast DMAC flow rules,
- type for unicast DMAC with VLAN flow rules.

These will be used in the follow up commit,
which adds functions for checking if a given control flow rule exists.

---
 drivers/net/mlx5/mlx5.h         | 15 +++++++++++++++
 drivers/net/mlx5/mlx5_flow_hw.c | 11 +++++++----
 2 files changed, 22 insertions(+), 4 deletions(-)
drivers/net/mlx5/mlx5.h +15 -0
index 18b4c15a26..80829be5b4 100644
@@ -1796,6 +1796,8 @@ enum mlx5_hw_ctrl_flow_type {
 	MLX5_HW_CTRL_FLOW_TYPE_TX_REPR_MATCH,
 	MLX5_HW_CTRL_FLOW_TYPE_LACP_RX,
 	MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS,
+	MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC,
+	MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN,
 };
 
 /** Additional info about control flow rule. */
@@ -1813,6 +1815,19 @@ struct mlx5_hw_ctrl_flow_info {
 		 * then fields contains matching SQ number.
 		 */
 		uint32_t tx_repr_sq;
+		/** Contains data relevant for unicast control flow rules. */
+		struct {
+			/**
+			 * If control flow is a unicast DMAC (or with VLAN) flow rule,
+			 * then this field contains DMAC.
+			 */
+			struct rte_ether_addr dmac;
+			/**
+			 * If control flow is a unicast DMAC with VLAN flow rule,
+			 * then this field contains VLAN ID.
+			 */
+			uint16_t vlan;
+		} uc;
 	};
 };
 
drivers/net/mlx5/mlx5_flow_hw.c +7 -4
index 0084f81980..fbc56497ae 100644
@@ -15906,7 +15906,7 @@ __flow_hw_ctrl_flows_unicast(struct rte_eth_dev *dev,
 		{ .type = RTE_FLOW_ACTION_TYPE_END },
 	};
 	struct mlx5_hw_ctrl_flow_info flow_info = {
-		.type = MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS,
+		.type = MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC,
 	};
 	const struct rte_ether_addr cmp = {
 		.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
@@ -15930,7 +15930,8 @@ __flow_hw_ctrl_flows_unicast(struct rte_eth_dev *dev,
 
 		if (!memcmp(mac, &cmp, sizeof(*mac)))
 			continue;
-		memcpy(&eth_spec.hdr.dst_addr.addr_bytes, mac->addr_bytes, RTE_ETHER_ADDR_LEN);
+		eth_spec.hdr.dst_addr = *mac;
+		flow_info.uc.dmac = *mac;
 		if (flow_hw_create_ctrl_flow(dev, dev,
 					     tbl, items, 0, actions, 0, &flow_info, false))
 			return -rte_errno;
@@ -15952,7 +15953,7 @@ __flow_hw_ctrl_flows_unicast_vlan(struct rte_eth_dev *dev,
 		{ .type = RTE_FLOW_ACTION_TYPE_END },
 	};
 	struct mlx5_hw_ctrl_flow_info flow_info = {
-		.type = MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS,
+		.type = MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN,
 	};
 	const struct rte_ether_addr cmp = {
 		.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
@@ -15977,13 +15978,15 @@ __flow_hw_ctrl_flows_unicast_vlan(struct rte_eth_dev *dev,
 
 		if (!memcmp(mac, &cmp, sizeof(*mac)))
 			continue;
-		memcpy(&eth_spec.hdr.dst_addr.addr_bytes, mac->addr_bytes, RTE_ETHER_ADDR_LEN);
+		eth_spec.hdr.dst_addr = *mac;
+		flow_info.uc.dmac = *mac;
 		for (j = 0; j < priv->vlan_filter_n; ++j) {
 			uint16_t vlan = priv->vlan_filter[j];
 			struct rte_flow_item_vlan vlan_spec = {
 				.hdr.vlan_tci = rte_cpu_to_be_16(vlan),
 			};
 
+			flow_info.uc.vlan = vlan;
 			items[1].spec = &vlan_spec;
 			if (flow_hw_create_ctrl_flow(dev, dev, tbl, items, 0, actions, 0,
 						     &flow_info, false))
Signature · 1 line
2.39.5
#14 lore raw

PATCH v2 2/10 net/mlx5: add checking if unicast flow rule exists

In reply to Dariusz Sosnowski

Add 2 internal functions for checking if:

- unicast DMAC control flow rule or
- unicast DMAC with VLAN control flow rule,

was created.

---
 drivers/net/mlx5/mlx5.h      | 11 +++++++++++
 drivers/net/mlx5/mlx5_flow.c | 37 ++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)
drivers/net/mlx5/mlx5.h +11 -0
index 80829be5b4..3551b793d6 100644
@@ -1831,6 +1831,17 @@ struct mlx5_hw_ctrl_flow_info {
 	};
 };
 
+/** Returns true if a control flow rule with unicast DMAC match on given address was created. */
+bool mlx5_ctrl_flow_uc_dmac_exists(struct rte_eth_dev *dev, const struct rte_ether_addr *addr);
+
+/**
+ * Returns true if a control flow rule with unicast DMAC and VLAN match
+ * on given values was created.
+ */
+bool mlx5_ctrl_flow_uc_dmac_vlan_exists(struct rte_eth_dev *dev,
+					const struct rte_ether_addr *addr,
+					const uint16_t vid);
+
 /** Entry for tracking control flow rules in HWS. */
 struct mlx5_hw_ctrl_flow {
 	LIST_ENTRY(mlx5_hw_ctrl_flow) next;
drivers/net/mlx5/mlx5_flow.c +37 -0
index 7f8640b488..19c9668bb6 100644
@@ -12178,3 +12178,40 @@ rte_pmd_mlx5_destroy_geneve_tlv_parser(void *handle)
 	return -rte_errno;
 #endif
 }
+
+bool
+mlx5_ctrl_flow_uc_dmac_exists(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
+{
+	struct mlx5_priv *priv = dev->data->dev_private;
+	struct mlx5_hw_ctrl_flow *entry;
+	bool exists = false;
+
+	LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
+		if (entry->info.type == MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC &&
+		    rte_is_same_ether_addr(addr, &entry->info.uc.dmac)) {
+			exists = true;
+			break;
+		}
+	}
+	return exists;
+}
+
+bool
+mlx5_ctrl_flow_uc_dmac_vlan_exists(struct rte_eth_dev *dev,
+				   const struct rte_ether_addr *addr,
+				   const uint16_t vid)
+{
+	struct mlx5_priv *priv = dev->data->dev_private;
+	struct mlx5_hw_ctrl_flow *entry;
+	bool exists = false;
+
+	LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
+		if (entry->info.type == MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN &&
+		    rte_is_same_ether_addr(addr, &entry->info.uc.dmac) &&
+		    vid == entry->info.uc.vlan) {
+			exists = true;
+			break;
+		}
+	}
+	return exists;
+}
Signature · 1 line
2.39.5
#15 lore raw

PATCH v2 3/10 net/mlx5: rework creation of unicast flow rules

In reply to Dariusz Sosnowski

Rework the code responsible for creation of unicast control flow rules, to allow creation of:

- unicast DMAC flow rules and
- unicast DMAC with VMAN flow rules,

outside of mlx5_traffic_enable() called when port is started.

---
 drivers/net/mlx5/meson.build          |   1 +
 drivers/net/mlx5/mlx5_flow.h          |   9 ++
 drivers/net/mlx5/mlx5_flow_hw.c       | 215 ++++++++++++++++++++------
 drivers/net/mlx5/mlx5_flow_hw_stubs.c |  41 +++++
 4 files changed, 219 insertions(+), 47 deletions(-)
 create mode 100644 drivers/net/mlx5/mlx5_flow_hw_stubs.c
drivers/net/mlx5/meson.build +1 -0
index eb5eb2cce7..0114673491 100644
@@ -23,6 +23,7 @@ sources = files(
         'mlx5_flow_dv.c',
         'mlx5_flow_aso.c',
         'mlx5_flow_flex.c',
+        'mlx5_flow_hw_stubs.c',
         'mlx5_mac.c',
         'mlx5_rss.c',
         'mlx5_rx.c',
drivers/net/mlx5/mlx5_flow.h +9 -0
index 86a1476879..2ff0b25d4d 100644
@@ -2990,6 +2990,15 @@ struct mlx5_flow_hw_ctrl_fdb {
 #define MLX5_CTRL_VLAN_FILTER    (RTE_BIT32(6))
 
 int mlx5_flow_hw_ctrl_flows(struct rte_eth_dev *dev, uint32_t flags);
+
+/** Create a control flow rule for matching unicast DMAC (HWS). */
+int mlx5_flow_hw_ctrl_flow_dmac(struct rte_eth_dev *dev, const struct rte_ether_addr *addr);
+
+/** Create a control flow rule for matching unicast DMAC with VLAN (HWS). */
+int mlx5_flow_hw_ctrl_flow_dmac_vlan(struct rte_eth_dev *dev,
+				     const struct rte_ether_addr *addr,
+				     const uint16_t vlan);
+
 void mlx5_flow_hw_cleanup_ctrl_rx_templates(struct rte_eth_dev *dev);
 
 int mlx5_flow_group_to_table(struct rte_eth_dev *dev,
drivers/net/mlx5/mlx5_flow_hw.c +168 -47

281 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_hw_stubs.c new file +41 -0

41 lines not on this page · raw message

Signature · 1 line
2.39.5
#16 lore raw

PATCH v2 4/10 net/mlx5: support destroying unicast flow rules

In reply to Dariusz Sosnowski

This patch adds support for destroying:

- unicast DMAC control flow rules and
- unicast DMAC with VLAN control flow rules,

without affecting any other control flow rules,
when HWS flow engine is used.

---
 drivers/net/mlx5/mlx5_flow.h          |  8 +++
 drivers/net/mlx5/mlx5_flow_hw.c       | 72 +++++++++++++++++++++++++++
 drivers/net/mlx5/mlx5_flow_hw_stubs.c | 27 ++++++++++
 3 files changed, 107 insertions(+)
drivers/net/mlx5/mlx5_flow.h +8 -0
index 2ff0b25d4d..165d17e40a 100644
@@ -2994,11 +2994,19 @@ int mlx5_flow_hw_ctrl_flows(struct rte_eth_dev *dev, uint32_t flags);
 /** Create a control flow rule for matching unicast DMAC (HWS). */
 int mlx5_flow_hw_ctrl_flow_dmac(struct rte_eth_dev *dev, const struct rte_ether_addr *addr);
 
+/** Destroy a control flow rule for matching unicast DMAC (HWS). */
+int mlx5_flow_hw_ctrl_flow_dmac_destroy(struct rte_eth_dev *dev, const struct rte_ether_addr *addr);
+
 /** Create a control flow rule for matching unicast DMAC with VLAN (HWS). */
 int mlx5_flow_hw_ctrl_flow_dmac_vlan(struct rte_eth_dev *dev,
 				     const struct rte_ether_addr *addr,
 				     const uint16_t vlan);
 
+/** Destroy a control flow rule for matching unicast DMAC with VLAN (HWS). */
+int mlx5_flow_hw_ctrl_flow_dmac_vlan_destroy(struct rte_eth_dev *dev,
+					     const struct rte_ether_addr *addr,
+					     const uint16_t vlan);
+
 void mlx5_flow_hw_cleanup_ctrl_rx_templates(struct rte_eth_dev *dev);
 
 int mlx5_flow_group_to_table(struct rte_eth_dev *dev,
drivers/net/mlx5/mlx5_flow_hw.c +72 -0

84 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_hw_stubs.c +27 -0
index 985c046056..0e79e6c1f2 100644
@@ -26,6 +26,19 @@ mlx5_flow_hw_ctrl_flow_dmac(struct rte_eth_dev *dev __rte_unused,
 	return -rte_errno;
 }
 
+/*
+ * This is a stub for the real implementation of this function in mlx5_flow_hw.c in case:
+ * - PMD is compiled on Windows or
+ * - available rdma-core does not support HWS.
+ */
+__rte_weak int
+mlx5_flow_hw_ctrl_flow_dmac_destroy(struct rte_eth_dev *dev __rte_unused,
+				    const struct rte_ether_addr *addr __rte_unused)
+{
+	rte_errno = ENOTSUP;
+	return -rte_errno;
+}
+
 /*
  * This is a stub for the real implementation of this function in mlx5_flow_hw.c in case:
  * - PMD is compiled on Windows or
@@ -39,3 +52,17 @@ mlx5_flow_hw_ctrl_flow_dmac_vlan(struct rte_eth_dev *dev __rte_unused,
 	rte_errno = ENOTSUP;
 	return -rte_errno;
 }
+
+/*
+ * This is a stub for the real implementation of this function in mlx5_flow_hw.c in case:
+ * - PMD is compiled on Windows or
+ * - available rdma-core does not support HWS.
+ */
+__rte_weak int
+mlx5_flow_hw_ctrl_flow_dmac_vlan_destroy(struct rte_eth_dev *dev __rte_unused,
+					 const struct rte_ether_addr *addr __rte_unused,
+					 const uint16_t vlan __rte_unused)
+{
+	rte_errno = ENOTSUP;
+	return -rte_errno;
+}
Signature · 1 line
2.39.5
#17 lore raw

PATCH v2 5/10 net/mlx5: rename control flow rules types

In reply to Dariusz Sosnowski

All structs and enumerations used for managenement of HWS control flow rules do not really depend on HWS itself. In order to allow their reuse with Verbs and DV flow engines and allow fine-grained creation/destruction of unicast DMAC (with VLAN) flow rules with these flow engines, this patch renames all related structs and enumerations.
All are renamed as follows:

- Enum mlx5_hw_ctrl_flow_type renamed to mlx5_ctrl_flow_type.
- Enum prefix MLX5_HW_CTRL_FLOW_TYPE_ changes to MLX5_CTRL_FLOW_TYPE_
- Struct mlx5_hw_ctrl_flow_info renamed to mlx5_ctrl_flow_info.
- Struct mlx5_hw_ctrl_flow renamed to mlx5_ctrl_flow_entry.

---
 drivers/net/mlx5/mlx5.h         | 36 ++++++++--------
 drivers/net/mlx5/mlx5_flow.c    |  8 ++--
 drivers/net/mlx5/mlx5_flow_hw.c | 74 ++++++++++++++++-----------------
 3 files changed, 59 insertions(+), 59 deletions(-)
drivers/net/mlx5/mlx5.h +18 -18
index 3551b793d6..a51727526f 100644
@@ -1787,23 +1787,23 @@ struct mlx5_obj_ops {
 
 #define MLX5_RSS_HASH_FIELDS_LEN RTE_DIM(mlx5_rss_hash_fields)
 
-enum mlx5_hw_ctrl_flow_type {
-	MLX5_HW_CTRL_FLOW_TYPE_GENERAL,
-	MLX5_HW_CTRL_FLOW_TYPE_SQ_MISS_ROOT,
-	MLX5_HW_CTRL_FLOW_TYPE_SQ_MISS,
-	MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_JUMP,
-	MLX5_HW_CTRL_FLOW_TYPE_TX_META_COPY,
-	MLX5_HW_CTRL_FLOW_TYPE_TX_REPR_MATCH,
-	MLX5_HW_CTRL_FLOW_TYPE_LACP_RX,
-	MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS,
-	MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC,
-	MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN,
+enum mlx5_ctrl_flow_type {
+	MLX5_CTRL_FLOW_TYPE_GENERAL,
+	MLX5_CTRL_FLOW_TYPE_SQ_MISS_ROOT,
+	MLX5_CTRL_FLOW_TYPE_SQ_MISS,
+	MLX5_CTRL_FLOW_TYPE_DEFAULT_JUMP,
+	MLX5_CTRL_FLOW_TYPE_TX_META_COPY,
+	MLX5_CTRL_FLOW_TYPE_TX_REPR_MATCH,
+	MLX5_CTRL_FLOW_TYPE_LACP_RX,
+	MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS,
+	MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC,
+	MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN,
 };
 
 /** Additional info about control flow rule. */
-struct mlx5_hw_ctrl_flow_info {
+struct mlx5_ctrl_flow_info {
 	/** Determines the kind of control flow rule. */
-	enum mlx5_hw_ctrl_flow_type type;
+	enum mlx5_ctrl_flow_type type;
 	union {
 		/**
 		 * If control flow is a SQ miss flow (root or not),
@@ -1843,8 +1843,8 @@ bool mlx5_ctrl_flow_uc_dmac_vlan_exists(struct rte_eth_dev *dev,
 					const uint16_t vid);
 
 /** Entry for tracking control flow rules in HWS. */
-struct mlx5_hw_ctrl_flow {
-	LIST_ENTRY(mlx5_hw_ctrl_flow) next;
+struct mlx5_ctrl_flow_entry {
+	LIST_ENTRY(mlx5_ctrl_flow_entry) next;
 	/**
 	 * Owner device is a port on behalf of which flow rule was created.
 	 *
@@ -1856,7 +1856,7 @@ struct mlx5_hw_ctrl_flow {
 	/** Pointer to flow rule handle. */
 	struct rte_flow *flow;
 	/** Additional information about the control flow rule. */
-	struct mlx5_hw_ctrl_flow_info info;
+	struct mlx5_ctrl_flow_info info;
 };
 
 /* HW Steering port configuration passed to rte_flow_configure(). */
@@ -1965,8 +1965,8 @@ struct mlx5_priv {
 	struct mlx5_drop drop_queue; /* Flow drop queues. */
 	void *root_drop_action; /* Pointer to root drop action. */
 	rte_spinlock_t hw_ctrl_lock;
-	LIST_HEAD(hw_ctrl_flow, mlx5_hw_ctrl_flow) hw_ctrl_flows;
-	LIST_HEAD(hw_ext_ctrl_flow, mlx5_hw_ctrl_flow) hw_ext_ctrl_flows;
+	LIST_HEAD(hw_ctrl_flow, mlx5_ctrl_flow_entry) hw_ctrl_flows;
+	LIST_HEAD(hw_ext_ctrl_flow, mlx5_ctrl_flow_entry) hw_ext_ctrl_flows;
 	struct mlx5_flow_hw_ctrl_fdb *hw_ctrl_fdb;
 	struct rte_flow_pattern_template *hw_tx_repr_tagging_pt;
 	struct rte_flow_actions_template *hw_tx_repr_tagging_at;
drivers/net/mlx5/mlx5_flow.c +4 -4
index 19c9668bb6..62e3bca2f0 100644
@@ -12183,11 +12183,11 @@ bool
 mlx5_ctrl_flow_uc_dmac_exists(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
 {
 	struct mlx5_priv *priv = dev->data->dev_private;
-	struct mlx5_hw_ctrl_flow *entry;
+	struct mlx5_ctrl_flow_entry *entry;
 	bool exists = false;
 
 	LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
-		if (entry->info.type == MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC &&
+		if (entry->info.type == MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC &&
 		    rte_is_same_ether_addr(addr, &entry->info.uc.dmac)) {
 			exists = true;
 			break;
@@ -12202,11 +12202,11 @@ mlx5_ctrl_flow_uc_dmac_vlan_exists(struct rte_eth_dev *dev,
 				   const uint16_t vid)
 {
 	struct mlx5_priv *priv = dev->data->dev_private;
-	struct mlx5_hw_ctrl_flow *entry;
+	struct mlx5_ctrl_flow_entry *entry;
 	bool exists = false;
 
 	LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
-		if (entry->info.type == MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN &&
+		if (entry->info.type == MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN &&
 		    rte_is_same_ether_addr(addr, &entry->info.uc.dmac) &&
 		    vid == entry->info.uc.vlan) {
 			exists = true;
drivers/net/mlx5/mlx5_flow_hw.c +37 -37

206 lines not on this page · raw message

Signature · 1 line
2.39.5
#18 lore raw

PATCH v2 6/10 net/mlx5: shared init of control flow rules

In reply to Dariusz Sosnowski

Control flow rules lists and control flow rule lock can be reused between all flow engines, but their initialization was done in flow_hw_configure() implementation.
This patch moves it to mlx5_dev_spawn(),
which is called for Verbs, DV and HWS flow engines.

---
 drivers/net/mlx5/linux/mlx5_os.c   | 3 +++
 drivers/net/mlx5/mlx5_flow_hw.c    | 3 ---
 drivers/net/mlx5/windows/mlx5_os.c | 3 +++
 3 files changed, 6 insertions(+), 3 deletions(-)
drivers/net/mlx5/linux/mlx5_os.c +3 -0
index 0a8de88759..c8d7fdb8dd 100644
@@ -1701,6 +1701,9 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 		    (sh->config.dv_flow_en == 1 && mlx5_flow_discover_ipv6_tc_support(eth_dev)))
 			sh->phdev->config.ipv6_tc_fallback = MLX5_IPV6_TC_FALLBACK;
 	}
+	rte_spinlock_init(&priv->hw_ctrl_lock);
+	LIST_INIT(&priv->hw_ctrl_flows);
+	LIST_INIT(&priv->hw_ext_ctrl_flows);
 	if (priv->sh->config.dv_flow_en == 2) {
 #ifdef HAVE_MLX5_HWS_SUPPORT
 		if (priv->sh->config.dv_esw_en) {
drivers/net/mlx5/mlx5_flow_hw.c +0 -3
index 228dc677c0..5b34154bf1 100644
@@ -11830,9 +11830,6 @@ __flow_hw_configure(struct rte_eth_dev *dev,
 	if (!priv->dr_ctx)
 		goto err;
 	priv->nb_queue = nb_q_updated;
-	rte_spinlock_init(&priv->hw_ctrl_lock);
-	LIST_INIT(&priv->hw_ctrl_flows);
-	LIST_INIT(&priv->hw_ext_ctrl_flows);
 	ret = flow_hw_action_template_drop_init(dev, error);
 	if (ret)
 		goto err;
drivers/net/mlx5/windows/mlx5_os.c +3 -0
index 0ebd233595..80f1679388 100644
@@ -600,6 +600,9 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 	}
 	mlx5_flow_counter_mode_config(eth_dev);
 	mlx5_queue_counter_id_prepare(eth_dev);
+	rte_spinlock_init(&priv->hw_ctrl_lock);
+	LIST_INIT(&priv->hw_ctrl_flows);
+	LIST_INIT(&priv->hw_ext_ctrl_flows);
 	return eth_dev;
 error:
 	if (priv) {
Signature · 1 line
2.39.5
#19 lore raw

PATCH v2 7/10 net/mlx5: add legacy unicast flow rules management

In reply to Dariusz Sosnowski

This patch adds the following internal functions for creation of unicast DMAC flow rules:

- mlx5_legacy_dmac_flow_create() - simple wrapper over mlx5_ctrl_flow().
- mlx5_legacy_dmac_vlan_flow_create() - simple wrapper over mlx5_ctrl_flow_vlan().

These will be used as a basis for implementing dynamic additions of unicast DMAC or unicast DMAC with VLAN control flow rules when new addresses/VLANs are added.

Also, this path adds the following internal functions for destructions of unicast DMAC flow rules:

- mlx5_legacy_ctrl_flow_destroy() - assuming a flow rule is on the control flow rule list, destroy it.
- mlx5_legacy_dmac_flow_destroy() - find and destroy a flow rule with given unicast DMAC.
- mlx5_legacy_dmac_flow_destroy() - find and destroy a flow rule with given unicast DMAC and VLAN ID.

These will be used as a basis for implementing dynamic removals of unicast DMAC or unicast DMAC with VLAN control flow rules when addresses/VLANs are removed.

At the moment, no relevant flow rules are registered on the list when working with Verbs or DV flow engine.
This will be added in the follow up commit.

---
 drivers/net/mlx5/mlx5_flow.c | 80 ++++++++++++++++++++++++++++++++++++
 drivers/net/mlx5/mlx5_flow.h | 19 +++++++++
 2 files changed, 99 insertions(+)
drivers/net/mlx5/mlx5_flow.c +80 -0
index 62e3bca2f0..0d83357eb0 100644
@@ -8532,6 +8532,86 @@ mlx5_ctrl_flow(struct rte_eth_dev *dev,
 	return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
 }
 
+int
+mlx5_legacy_dmac_flow_create(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
+{
+	struct rte_flow_item_eth unicast = {
+		.hdr.dst_addr = *addr,
+	};
+	struct rte_flow_item_eth unicast_mask = {
+		.hdr.dst_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff",
+	};
+
+	return mlx5_ctrl_flow(dev, &unicast, &unicast_mask);
+}
+
+int
+mlx5_legacy_dmac_vlan_flow_create(struct rte_eth_dev *dev,
+				  const struct rte_ether_addr *addr,
+				  const uint16_t vid)
+{
+	struct rte_flow_item_eth unicast_spec = {
+		.hdr.dst_addr = *addr,
+	};
+	struct rte_flow_item_eth unicast_mask = {
+		.hdr.dst_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff",
+	};
+	struct rte_flow_item_vlan vlan_spec = {
+		.hdr.vlan_tci = rte_cpu_to_be_16(vid),
+	};
+	struct rte_flow_item_vlan vlan_mask = rte_flow_item_vlan_mask;
+
+	return mlx5_ctrl_flow_vlan(dev, &unicast_spec, &unicast_mask, &vlan_spec, &vlan_mask);
+}
+
+void
+mlx5_legacy_ctrl_flow_destroy(struct rte_eth_dev *dev, struct mlx5_ctrl_flow_entry *entry)
+{
+	uintptr_t flow_idx;
+
+	flow_idx = (uintptr_t)entry->flow;
+	mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_CTL, flow_idx);
+	LIST_REMOVE(entry, next);
+	mlx5_free(entry);
+}
+
+int
+mlx5_legacy_dmac_flow_destroy(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
+{
+	struct mlx5_priv *priv = dev->data->dev_private;
+	struct mlx5_ctrl_flow_entry *entry;
+
+	LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
+		if (entry->info.type != MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC ||
+		    !rte_is_same_ether_addr(addr, &entry->info.uc.dmac))
+			continue;
+
+		mlx5_legacy_ctrl_flow_destroy(dev, entry);
+		return 0;
+	}
+	return 0;
+}
+
+int
+mlx5_legacy_dmac_vlan_flow_destroy(struct rte_eth_dev *dev,
+				   const struct rte_ether_addr *addr,
+				   const uint16_t vid)
+{
+	struct mlx5_priv *priv = dev->data->dev_private;
+	struct mlx5_ctrl_flow_entry *entry;
+
+	LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
+		if (entry->info.type != MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN ||
+		    !rte_is_same_ether_addr(addr, &entry->info.uc.dmac) ||
+		    vid != entry->info.uc.vlan)
+			continue;
+
+		mlx5_legacy_ctrl_flow_destroy(dev, entry);
+		return 0;
+	}
+	return 0;
+}
+
 /**
  * Create default miss flow rule matching lacp traffic
  *
drivers/net/mlx5/mlx5_flow.h +19 -0
index 165d17e40a..db56ae051d 100644
@@ -2991,6 +2991,25 @@ struct mlx5_flow_hw_ctrl_fdb {
 
 int mlx5_flow_hw_ctrl_flows(struct rte_eth_dev *dev, uint32_t flags);
 
+/** Create a control flow rule for matching unicast DMAC with VLAN (Verbs and DV). */
+int mlx5_legacy_dmac_flow_create(struct rte_eth_dev *dev, const struct rte_ether_addr *addr);
+
+/** Destroy a control flow rule for matching unicast DMAC with VLAN (Verbs and DV). */
+int mlx5_legacy_dmac_flow_destroy(struct rte_eth_dev *dev, const struct rte_ether_addr *addr);
+
+/** Create a control flow rule for matching unicast DMAC with VLAN (Verbs and DV). */
+int mlx5_legacy_dmac_vlan_flow_create(struct rte_eth_dev *dev,
+				      const struct rte_ether_addr *addr,
+				      const uint16_t vid);
+
+/** Destroy a control flow rule for matching unicast DMAC with VLAN (Verbs and DV). */
+int mlx5_legacy_dmac_vlan_flow_destroy(struct rte_eth_dev *dev,
+				      const struct rte_ether_addr *addr,
+				      const uint16_t vid);
+
+/** Destroy a control flow rule registered on port level control flow rule type. */
+void mlx5_legacy_ctrl_flow_destroy(struct rte_eth_dev *dev, struct mlx5_ctrl_flow_entry *entry);
+
 /** Create a control flow rule for matching unicast DMAC (HWS). */
 int mlx5_flow_hw_ctrl_flow_dmac(struct rte_eth_dev *dev, const struct rte_ether_addr *addr);
 
Signature · 1 line
2.39.5
#20 lore raw

Re: [PATCH v2 07/10] net/mlx5: add legacy unicast flow rules management

Quoted 45 lines · Dariusz Sosnowski

This patch adds the following internal functions for creation of unicast DMAC flow rules:

- mlx5_legacy_dmac_flow_create() - simple wrapper over mlx5_ctrl_flow().
- mlx5_legacy_dmac_vlan_flow_create() - simple wrapper over mlx5_ctrl_flow_vlan().

These will be used as a basis for implementing dynamic additions of unicast DMAC or unicast DMAC with VLAN control flow rules when new addresses/VLANs are added.

Also, this path adds the following internal functions for destructions of unicast DMAC flow rules:

- mlx5_legacy_ctrl_flow_destroy() - assuming a flow rule is on the control flow rule list, destroy it.
- mlx5_legacy_dmac_flow_destroy() - find and destroy a flow rule with given unicast DMAC.
- mlx5_legacy_dmac_flow_destroy() - find and destroy a flow rule with given unicast DMAC and VLAN ID.

These will be used as a basis for implementing dynamic removals of unicast DMAC or unicast DMAC with VLAN control flow rules when addresses/VLANs are removed.

At the moment, no relevant flow rules are registered on the list when working with Verbs or DV flow engine.
This will be added in the follow up commit.

---
 drivers/net/mlx5/mlx5_flow.c | 80 ++++++++++++++++++++++++++++++++++++
 drivers/net/mlx5/mlx5_flow.h | 19 +++++++++
 2 files changed, 99 insertions(+)
drivers/net/mlx5/mlx5_flow.c +0 -0
index 62e3bca2f0..0d83357eb0 100644
@@ -8532,6 +8532,86 @@ mlx5_ctrl_flow(struct rte_eth_dev *dev,
 	return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
 }
 

drivers/net/mlx5/mlx5_flow.c mlx5_ctrl_flow(struct rte_eth_dev *dev, · line 8544

Quoted 10 lines
drivers/net/mlx5/mlx5_flow.c +9 -0
+int
+mlx5_legacy_dmac_flow_create(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
+{
+	struct rte_flow_item_eth unicast = {
+		.hdr.dst_addr = *addr,
+	};
+	struct rte_flow_item_eth unicast_mask = {
+		.hdr.dst_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff",
+	};
 

Initialization as string breaks build [3] with experimental gcc-15 [1], please see [2].

[1]
gcc 15.0.0 "gcc (GCC) 15.0.0 20241107 (experimental)"

[2]
https://git.dpdk.org/dpdk/commit/?id=e0d947a1e6c2

[3]
../drivers/net/mlx5/mlx5_flow.c: In function ‘mlx5_legacy_dmac_flow_create’:
../drivers/net/mlx5/mlx5_flow.c:8568:44: error: initializer-string for array of ‘unsigned char’ is too long [-Werror=unterminated-string-initialization]
8568 | .hdr.dst_addr.addr_bytes =
"\xff\xff\xff\xff\xff\xff",

      |

^~~~~~~~~~~~~~~~~~~~~~~~~~
../drivers/net/mlx5/mlx5_flow.c: In function ‘mlx5_legacy_dmac_vlan_flow_create’:
../drivers/net/mlx5/mlx5_flow.c:8583:44: error: initializer-string for array of ‘unsigned char’ is too long [-Werror=unterminated-string-initialization]
8583 | .hdr.dst_addr.addr_bytes =
"\xff\xff\xff\xff\xff\xff",

      |

^~~~~~~~~~~~~~~~~~~~~~~~~~

#21 lore raw

RE: [PATCH v2 07/10] net/mlx5: add legacy unicast flow rules management

Quoted 98 lines

-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Friday, November 8, 2024 15:48
To: Dariusz Sosnowski <[email protected]>; Slava Ovsiienko <[email protected]>; Bing Zhao <[email protected]>; Ori Kam <[email protected]>; Suanming Mou <[email protected]>; Matan Azrad <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v2 07/10] net/mlx5: add legacy unicast flow rules management

External email: Use caution opening links or attachments

Quoted 46 lines · Dariusz Sosnowski

This patch adds the following internal functions for creation of unicast DMAC flow rules:

- mlx5_legacy_dmac_flow_create() - simple wrapper over mlx5_ctrl_flow().
- mlx5_legacy_dmac_vlan_flow_create() - simple wrapper over mlx5_ctrl_flow_vlan().

These will be used as a basis for implementing dynamic additions of unicast DMAC or unicast DMAC with VLAN control flow rules when new addresses/VLANs are added.

Also, this path adds the following internal functions for destructions of unicast DMAC flow rules:

- mlx5_legacy_ctrl_flow_destroy() - assuming a flow rule is on the control flow rule list, destroy it.
- mlx5_legacy_dmac_flow_destroy() - find and destroy a flow rule with given unicast DMAC.
- mlx5_legacy_dmac_flow_destroy() - find and destroy a flow rule with given unicast DMAC and VLAN ID.

These will be used as a basis for implementing dynamic removals of unicast DMAC or unicast DMAC with VLAN control flow rules when addresses/VLANs are removed.

At the moment, no relevant flow rules are registered on the list when working with Verbs or DV flow engine.
This will be added in the follow up commit.

---
 drivers/net/mlx5/mlx5_flow.c | 80
++++++++++++++++++++++++++++++++++++
 drivers/net/mlx5/mlx5_flow.h | 19 +++++++++
 2 files changed, 99 insertions(+)
(quoted diff) +0 -0

b/drivers/net/mlx5/mlx5_flow.c index 62e3bca2f0..0d83357eb0 100644

drivers/net/mlx5/mlx5_flow.c +0 -0
@@ -8532,6 +8532,86 @@ mlx5_ctrl_flow(struct rte_eth_dev *dev,
      return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
 }
 

drivers/net/mlx5/mlx5_flow.c mlx5_ctrl_flow(struct rte_eth_dev *dev, · line 8544

Quoted 10 lines
drivers/net/mlx5/mlx5_flow.c +9 -0
+int
+mlx5_legacy_dmac_flow_create(struct rte_eth_dev *dev, const struct
+rte_ether_addr *addr) {
+     struct rte_flow_item_eth unicast = {
+             .hdr.dst_addr = *addr,
+     };
+     struct rte_flow_item_eth unicast_mask = {
+             .hdr.dst_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff",
+     };
 

Initialization as string breaks build [3] with experimental gcc-15 [1], please see [2].

[1]
gcc 15.0.0 "gcc (GCC) 15.0.0 20241107 (experimental)"

[2]
https://git.dpdk.org/dpdk/commit/?id=e0d947a1e6c2

[3]
../drivers/net/mlx5/mlx5_flow.c: In function ‘mlx5_legacy_dmac_flow_create’:
../drivers/net/mlx5/mlx5_flow.c:8568:44: error: initializer-string for array of ‘unsigned char’ is too long [-Werror=unterminated-string-initialization]
8568 | .hdr.dst_addr.addr_bytes =
"\xff\xff\xff\xff\xff\xff",

      |

^~~~~~~~~~~~~~~~~~~~~~~~~~
../drivers/net/mlx5/mlx5_flow.c: In function ‘mlx5_legacy_dmac_vlan_flow_create’:
../drivers/net/mlx5/mlx5_flow.c:8583:44: error: initializer-string for array of ‘unsigned char’ is too long [-Werror=unterminated-string-initialization]
8583 | .hdr.dst_addr.addr_bytes =
"\xff\xff\xff\xff\xff\xff",

Quoted 2 lines
      |

^~~~~~~~~~~~~~~~~~~~~~~~~~

Thanks for notifying. I already sent a fix: https://patches.dpdk.org/project/dpdk/patch/[email protected]/

Best regards,
Dariusz Sosnowski

#22 lore raw

PATCH v2 8/10 net/mlx5: add legacy unicast flow rule registration

In reply to Dariusz Sosnowski

Whenever a unicast DMAC or unicast DMAC with VLAN ID control flow rule is created when working with Verbs or DV flow engine,
add this flow rule to the control flow rule list,
with information required for recognizing it.

---
 drivers/net/mlx5/mlx5_flow.c    | 32 +++++++++++++++++++++++++++++---
 drivers/net/mlx5/mlx5_trigger.c | 26 ++++++++++++++++++++++++--
 2 files changed, 53 insertions(+), 5 deletions(-)
drivers/net/mlx5/mlx5_flow.c +29 -3
index 0d83357eb0..9c43201e05 100644
@@ -8493,8 +8493,9 @@ mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
 			.type = RTE_FLOW_ACTION_TYPE_END,
 		},
 	};
-	uint32_t flow_idx;
+	uintptr_t flow_idx;
 	struct rte_flow_error error;
+	struct mlx5_ctrl_flow_entry *entry;
 	unsigned int i;
 
 	if (!priv->reta_idx_n || !priv->rxqs_n) {
@@ -8504,11 +8505,36 @@ mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
 		action_rss.types = 0;
 	for (i = 0; i != priv->reta_idx_n; ++i)
 		queue[i] = (*priv->reta_idx)[i];
+
+	entry = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*entry), alignof(typeof(*entry)), SOCKET_ID_ANY);
+	if (entry == NULL) {
+		rte_errno = ENOMEM;
+		goto err;
+	}
+
+	entry->owner_dev = dev;
+	if (vlan_spec == NULL) {
+		entry->info.type = MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC;
+	} else {
+		entry->info.type = MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN;
+		entry->info.uc.vlan = rte_be_to_cpu_16(vlan_spec->hdr.vlan_tci);
+	}
+	entry->info.uc.dmac = eth_spec->hdr.dst_addr;
+
 	flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
 				    &attr, items, actions, false, &error);
-	if (!flow_idx)
-		return -rte_errno;
+	if (!flow_idx) {
+		mlx5_free(entry);
+		goto err;
+	}
+
+	entry->flow = (struct rte_flow *)flow_idx;
+	LIST_INSERT_HEAD(&priv->hw_ctrl_flows, entry, next);
+
 	return 0;
+
+err:
+	return -rte_errno;
 }
 
 /**
drivers/net/mlx5/mlx5_trigger.c +24 -2
index bf836c92fc..4fa9319c4d 100644
@@ -20,6 +20,8 @@
 #include "mlx5_utils.h"
 #include "rte_pmd_mlx5.h"
 
+static void mlx5_traffic_disable_legacy(struct rte_eth_dev *dev);
+
 /**
  * Stop traffic on Tx queues.
  *
@@ -1736,11 +1738,31 @@ mlx5_traffic_enable(struct rte_eth_dev *dev)
 	return 0;
 error:
 	ret = rte_errno; /* Save rte_errno before cleanup. */
-	mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_CTL, false);
+	mlx5_traffic_disable_legacy(dev);
 	rte_errno = ret; /* Restore rte_errno. */
 	return -rte_errno;
 }
 
+static void
+mlx5_traffic_disable_legacy(struct rte_eth_dev *dev)
+{
+	struct mlx5_priv *priv = dev->data->dev_private;
+	struct mlx5_ctrl_flow_entry *entry;
+	struct mlx5_ctrl_flow_entry *tmp;
+
+	/*
+	 * Free registered control flow rules first,
+	 * to free the memory allocated for list entries
+	 */
+	entry = LIST_FIRST(&priv->hw_ctrl_flows);
+	while (entry != NULL) {
+		tmp = LIST_NEXT(entry, next);
+		mlx5_legacy_ctrl_flow_destroy(dev, entry);
+		entry = tmp;
+	}
+
+	mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_CTL, false);
+}
 
 /**
  * Disable traffic flows configured by control plane
@@ -1758,7 +1780,7 @@ mlx5_traffic_disable(struct rte_eth_dev *dev)
 		mlx5_flow_hw_flush_ctrl_flows(dev);
 	else
 #endif
-		mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_CTL, false);
+		mlx5_traffic_disable_legacy(dev);
 }
 
 /**
Signature · 1 line
2.39.5
#23 lore raw

PATCH v2 9/10 net/mlx5: add dynamic unicast flow rule management

In reply to Dariusz Sosnowski

This patch extens the mlx5_traffic interface with a couple of functions:

- mlx5_traffic_mac_add() - Create an unicast DMAC flow rule, without recreating all control flow rules.
- mlx5_traffic_mac_remove() - Remove an unicast DMAC flow rule, without recreating all control flow rules.
- mlx5_traffic_mac_vlan_add() - Create an unicast DMAC with VLAN flow rule, without recreating all control flow rules.
- mlx5_traffic_mac_vlan_remove() - Remove an unicast DMAC with VLAN flow rule, without recreating all control flow rules.

These functions will be used in the follow up commit, which will modify the behavior of adding/removing MAC address and enabling/disabling VLAN filter in mlx5 PMD.

---
 drivers/net/mlx5/mlx5.h         |   4 +
 drivers/net/mlx5/mlx5_trigger.c | 236 ++++++++++++++++++++++++++++++++
 2 files changed, 240 insertions(+)
drivers/net/mlx5/mlx5.h +4 -0
index a51727526f..0e026f7bbb 100644
@@ -2372,6 +2372,10 @@ int mlx5_hairpin_bind(struct rte_eth_dev *dev, uint16_t rx_port);
 int mlx5_hairpin_unbind(struct rte_eth_dev *dev, uint16_t rx_port);
 int mlx5_hairpin_get_peer_ports(struct rte_eth_dev *dev, uint16_t *peer_ports,
 				size_t len, uint32_t direction);
+int mlx5_traffic_mac_add(struct rte_eth_dev *dev, const struct rte_ether_addr *addr);
+int mlx5_traffic_mac_remove(struct rte_eth_dev *dev, const struct rte_ether_addr *addr);
+int mlx5_traffic_vlan_add(struct rte_eth_dev *dev, const uint16_t vid);
+int mlx5_traffic_vlan_remove(struct rte_eth_dev *dev, const uint16_t vid);
 
 /* mlx5_flow.c */
 
drivers/net/mlx5/mlx5_trigger.c +236 -0

239 lines not on this page · raw message

Signature · 1 line
2.39.5
#24 lore raw

PATCH v2 10/10 net/mlx5: optimize MAC address and VLAN filter handling

In reply to Dariusz Sosnowski

This patch:

- Changes MAC address adding/removing handling, so that only required control rules are added/removed.
As a result, rte_eth_dev_mac_addr_add() or rte_eth_dev_mac_addr_remove() calls are faster for mlx5 PMD.
- Changes VLAN filtering handling, so that
only required control flow rules are added/removed.
As a result, rte_eth_dev_vlan_filter() call is faster for mlx5 PMD.

---
 drivers/net/mlx5/mlx5_mac.c  | 41 +++++++++++++++++++++++++-----------
 drivers/net/mlx5/mlx5_vlan.c |  9 ++++----
 2 files changed, 33 insertions(+), 17 deletions(-)
drivers/net/mlx5/mlx5_mac.c +29 -12
index 22a756a52b..0e5d2be530 100644
@@ -25,15 +25,25 @@
  *   Pointer to Ethernet device structure.
  * @param index
  *   MAC address index.
+ * @param addr
+ *   If MAC address is actually removed, it will be stored here if pointer is not a NULL.
+ *
+ * @return
+ *   True if there was a MAC address under given index.
  */
-static void
-mlx5_internal_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
+static bool
+mlx5_internal_mac_addr_remove(struct rte_eth_dev *dev,
+			      uint32_t index,
+			      struct rte_ether_addr *addr)
 {
 	MLX5_ASSERT(index < MLX5_MAX_MAC_ADDRESSES);
 	if (rte_is_zero_ether_addr(&dev->data->mac_addrs[index]))
-		return;
+		return false;
 	mlx5_os_mac_addr_remove(dev, index);
+	if (addr != NULL)
+		*addr = dev->data->mac_addrs[index];
 	memset(&dev->data->mac_addrs[index], 0, sizeof(struct rte_ether_addr));
+	return true;
 }
 
 /**
@@ -91,15 +101,15 @@ mlx5_internal_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac,
 void
 mlx5_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
 {
+	struct rte_ether_addr addr = { 0 };
 	int ret;
 
 	if (index >= MLX5_MAX_UC_MAC_ADDRESSES)
 		return;
-	mlx5_internal_mac_addr_remove(dev, index);
-	if (!dev->data->promiscuous) {
-		ret = mlx5_traffic_restart(dev);
+	if (mlx5_internal_mac_addr_remove(dev, index, &addr)) {
+		ret = mlx5_traffic_mac_remove(dev, &addr);
 		if (ret)
-			DRV_LOG(ERR, "port %u cannot restart traffic: %s",
+			DRV_LOG(ERR, "port %u cannot update control flow rules: %s",
 				dev->data->port_id, strerror(rte_errno));
 	}
 }
@@ -132,9 +142,7 @@ mlx5_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac,
 	ret = mlx5_internal_mac_addr_add(dev, mac, index);
 	if (ret < 0)
 		return ret;
-	if (!dev->data->promiscuous)
-		return mlx5_traffic_restart(dev);
-	return 0;
+	return mlx5_traffic_mac_add(dev, mac);
 }
 
 /**
@@ -154,6 +162,12 @@ mlx5_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
 	uint16_t port_id;
 	struct mlx5_priv *priv = dev->data->dev_private;
 	struct mlx5_priv *pf_priv;
+	struct rte_ether_addr old_mac_addr = dev->data->mac_addrs[0];
+	int ret;
+
+	/* ethdev does not check if new default address is the same as the old one. */
+	if (rte_is_same_ether_addr(mac_addr, &old_mac_addr))
+		return 0;
 
 	/*
 	 * Configuring the VF instead of its representor,
@@ -188,7 +202,10 @@ mlx5_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
 
 	DRV_LOG(DEBUG, "port %u setting primary MAC address",
 		dev->data->port_id);
-	return mlx5_mac_addr_add(dev, mac_addr, 0, 0);
+	ret = mlx5_mac_addr_add(dev, mac_addr, 0, 0);
+	if (ret)
+		return ret;
+	return mlx5_traffic_mac_remove(dev, &old_mac_addr);
 }
 
 /**
@@ -208,7 +225,7 @@ mlx5_set_mc_addr_list(struct rte_eth_dev *dev,
 		return -rte_errno;
 	}
 	for (i = MLX5_MAX_UC_MAC_ADDRESSES; i != MLX5_MAX_MAC_ADDRESSES; ++i)
-		mlx5_internal_mac_addr_remove(dev, i);
+		mlx5_internal_mac_addr_remove(dev, i, NULL);
 	i = MLX5_MAX_UC_MAC_ADDRESSES;
 	while (nb_mc_addr--) {
 		ret = mlx5_internal_mac_addr_add(dev, mc_addr_set++, i++);
drivers/net/mlx5/mlx5_vlan.c +4 -5
index e7161b66fe..43a314a679 100644
@@ -54,7 +54,7 @@ mlx5_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
 		MLX5_ASSERT(priv->vlan_filter_n != 0);
 		/* Enabling an existing VLAN filter has no effect. */
 		if (on)
-			goto out;
+			goto no_effect;
 		/* Remove VLAN filter from list. */
 		--priv->vlan_filter_n;
 		memmove(&priv->vlan_filter[i],
@@ -66,14 +66,13 @@ mlx5_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
 		MLX5_ASSERT(i == priv->vlan_filter_n);
 		/* Disabling an unknown VLAN filter has no effect. */
 		if (!on)
-			goto out;
+			goto no_effect;
 		/* Add new VLAN filter. */
 		priv->vlan_filter[priv->vlan_filter_n] = vlan_id;
 		++priv->vlan_filter_n;
 	}
-out:
-	if (dev->data->dev_started)
-		return mlx5_traffic_restart(dev);
+	return on ? mlx5_traffic_vlan_add(dev, vlan_id) : mlx5_traffic_vlan_remove(dev, vlan_id);
+no_effect:
 	return 0;
 }
 
Signature · 1 line
2.39.5
#25 lore raw
In reply to Dariusz Sosnowski
Quoted 16 lines · On Tue, 22 Oct 2024 14:06:08 +0200 Dariusz Sosnowski <[email protected]>…

Whenever a new MAC address is added to the port, mlx5 PMD will:

- Add this address to dev->data->mac_addrs[].
- Destroy all control flow rules.
- Recreate all control flow rules.

Similar logic is also implemented for VLAN filters.

Because of such logic, the latency of adding the new MAC address
(i.e., latency of rte_eth_dev_mac_addr_add() function call)
is actually linear to number of MAC addresses already configured.
Since each operation of creating/destroying a control flow rule,
involves an ioctl() syscall, on some setups the latency of adding
a single MAC address can reach ~100ms, when port is operating with >= 100 MAC addresses. The same problem exists for VLAN filters (and even compounded by it).

Quoted 5 lines

This patchset aims to resolve these issues,
by reworking how mlx5 PMD handles adding/removing MAC addresses and VLAN filters. Instead of recreating all control flow rules,
only necessary flow rules will be created/removed on each operation, thus minimizing number of syscalls triggered.

Looks good.
Is there already functional test which does this? Mlx5 may not be alone in having this problem.

#26 lore raw
Quoted 36 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Tuesday, October 22, 2024 17:41
To: Dariusz Sosnowski <[email protected]>
Cc: Slava Ovsiienko <[email protected]>; Bing Zhao <[email protected]>; Ori Kam <[email protected]>; Suanming Mou <[email protected]>; Matan Azrad <[email protected]>; [email protected]
Subject: Re: [PATCH v2 00/10] net/mlx5: improve MAC address and VLAN add latency

Quoted 6 lines · On Tue, 22 Oct 2024 14:06:08 +0200 Dariusz Sosnowski <[email protected]>…

Whenever a new MAC address is added to the port, mlx5 PMD will:

- Add this address to dev->data->mac_addrs[].
- Destroy all control flow rules.
- Recreate all control flow rules.

Quoted 8 lines

Similar logic is also implemented for VLAN filters.

Because of such logic, the latency of adding the new MAC address (i.e., latency of rte_eth_dev_mac_addr_add() function call) is actually linear to number of MAC addresses already configured. Since each operation of creating/destroying a control flow rule, involves an ioctl() syscall, on some setups the latency of adding a single MAC address can reach ~100ms, when port is operating with >= 100 MAC

addresses.

Quoted 7 lines

The same problem exists for VLAN filters (and even compounded by it).

This patchset aims to resolve these issues, by reworking how mlx5 PMD handles adding/removing MAC addresses and VLAN filters. Instead of recreating all control flow rules, only necessary flow rules will be created/removed on each operation, thus minimizing number of syscalls triggered.

Quoted 3 lines

Looks good.
Is there already functional test which does this? Mlx5 may not be alone in having this problem.

I could not find any existing functional test in DPDK or DTS for such a scenario.

#27 lore raw
In reply to Dariusz Sosnowski

Hi,

From: Dariusz Sosnowski <[email protected]>
Sent: Tuesday, October 22, 2024 3:06 PM
To: Slava Ovsiienko; Bing Zhao; Ori Kam; Suanming Mou; Matan Azrad
Cc: [email protected]
Subject: [PATCH v2 00/10] net/mlx5: improve MAC address and VLAN add latency

Whenever a new MAC address is added to the port, mlx5 PMD will:

- Add this address to dev->data->mac_addrs[].
- Destroy all control flow rules.
- Recreate all control flow rules.

Similar logic is also implemented for VLAN filters.

Because of such logic, the latency of adding the new MAC address
(i.e., latency of rte_eth_dev_mac_addr_add() function call)
is actually linear to number of MAC addresses already configured.
Since each operation of creating/destroying a control flow rule,
involves an ioctl() syscall, on some setups the latency of adding
a single MAC address can reach ~100ms, when port is operating with >= 100 MAC addresses. The same problem exists for VLAN filters (and even compounded by it).

This patchset aims to resolve these issues,
by reworking how mlx5 PMD handles adding/removing MAC addresses and VLAN filters. Instead of recreating all control flow rules,
only necessary flow rules will be created/removed on each operation, thus minimizing number of syscalls triggered.

Summary of patches:

- Patch 1-2 - Extends existing mlx5_hw_ctrl_flow_type enum with special variants, which will be used for tracking MAC and VLAN control flow rules.
- Patch 3-4 - Refactors HWS code for control flow rule creation to allow
creation of specific control flow rules with unicast MAC/VLAN match.
Also functions are added for deletion of specific rules.
- Patch 5-6 - Prepares the control flow rules list, used by HWS flow engine,
to be used by other flow engine.
Goal is to reuse the similar logic in Verbs and DV flow engines.
- Patch 7-8 - Adjusts legacy flow engines, so that unicast DMAC/VLAN control flow rules are added to the control flow rules list.
Also exposes functions for creating/destroying specific ones.
- Patch 9-10 - Extends mlx5_traffic_* interface with mlx5_traffic_mac_add/remove and mlx5_traffic_vlan_add/remove functions.
They are used in implementations of DPDK APIs for adding/removing MAC addresses/VLAN filters and their goal is to update the set of control flow rules in a minimal number of steps possible, without recreating the rules.

As a result of these patches the time to add 128th MAC address, after 127th was added drops **from ~72 ms to ~197 us** (at least on my setup).

v2:
- Rebase on top of 24.11-rc1.
- Added Acked-by tags from v1.

Dariusz Sosnowski (10):
net/mlx5: track unicast DMAC control flow rules net/mlx5: add checking if unicast flow rule exists net/mlx5: rework creation of unicast flow rules net/mlx5: support destroying unicast flow rules net/mlx5: rename control flow rules types net/mlx5: shared init of control flow rules net/mlx5: add legacy unicast flow rules management net/mlx5: add legacy unicast flow rule registration net/mlx5: add dynamic unicast flow rule management net/mlx5: optimize MAC address and VLAN filter handling

 drivers/net/mlx5/linux/mlx5_os.c      |   3 +
 drivers/net/mlx5/meson.build          |   1 +
 drivers/net/mlx5/mlx5.h               |  62 +++--
 drivers/net/mlx5/mlx5_flow.c          | 149 ++++++++++-
 drivers/net/mlx5/mlx5_flow.h          |  36 +++
 drivers/net/mlx5/mlx5_flow_hw.c       | 349 ++++++++++++++++++++------
 drivers/net/mlx5/mlx5_flow_hw_stubs.c |  68 +++++
 drivers/net/mlx5/mlx5_mac.c           |  41 ++-
 drivers/net/mlx5/mlx5_trigger.c       | 262 ++++++++++++++++++-
 drivers/net/mlx5/mlx5_vlan.c          |   9 +-
 drivers/net/mlx5/windows/mlx5_os.c    |   3 +
 11 files changed, 867 insertions(+), 116 deletions(-)
 create mode 100644 drivers/net/mlx5/mlx5_flow_hw_stubs.c

--
2.39.5

Series applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh

#28 lore raw

24/10/2024 16:11, Raslan Darawsheh:

Quoted 1 line

Series applied to next-net-mlx,

This series fails to build on MinGW because of the weak stubs. Please check why.
Note: I'm off for a week.