[3/6] ethdev: add flow rule insertion by index with pattern

Message ID 20240919004813.3158356-4-akozyrev@nvidia.com (mailing list archive)
State Superseded
Delegated to: Ferruh Yigit
Headers
Series ethdev: jump to table support |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Alexander Kozyrev Sept. 19, 2024, 12:48 a.m. UTC
Add a new API to enqueue flow rule creation by index with pattern.
The new template table rules insertion type,
index-based insertion with pattern, requires a new flow rule creation
function with both rule index and pattern provided.
Packets will match on the provided pattern at the provided index.

Signed-off-by: Alexander Kozyrev <akozyrev@nvidia.com>
---
 doc/guides/prog_guide/rte_flow.rst     | 20 ++++++++++
 doc/guides/rel_notes/release_24_11.rst |  5 +++
 lib/ethdev/ethdev_trace.h              | 44 +++++++++++++++++++++
 lib/ethdev/ethdev_trace_points.c       |  6 +++
 lib/ethdev/rte_flow.c                  | 55 ++++++++++++++++++++++++++
 lib/ethdev/rte_flow.h                  | 54 +++++++++++++++++++++++++
 lib/ethdev/rte_flow_driver.h           | 14 +++++++
 lib/ethdev/version.map                 |  3 ++
 8 files changed, 201 insertions(+)
  

Comments

Dariusz Sosnowski Sept. 25, 2024, 3 p.m. UTC | #1
> -----Original Message-----
> From: Alexander Kozyrev <akozyrev@nvidia.com>
> Sent: Thursday, September 19, 2024 02:48
> To: dev@dpdk.org
> Cc: Dariusz Sosnowski <dsosnowski@nvidia.com>; Ori Kam
> <orika@nvidia.com>; NBU-Contact-Thomas Monjalon (EXTERNAL)
> <thomas@monjalon.net>; Matan Azrad <matan@nvidia.com>;
> ferruh.yigit@amd.com; stephen@networkplumber.org
> Subject: [PATCH 3/6] ethdev: add flow rule insertion by index with pattern
> 
> Add a new API to enqueue flow rule creation by index with pattern.
> The new template table rules insertion type, index-based insertion with
> pattern, requires a new flow rule creation function with both rule index and
> pattern provided.
> Packets will match on the provided pattern at the provided index.
> 
> Signed-off-by: Alexander Kozyrev <akozyrev@nvidia.com>

[snip]

> +RTE_TRACE_POINT_FP(
> +	rte_flow_trace_async_create_by_index,
> +	RTE_TRACE_POINT_ARGS(uint16_t port_id, uint32_t queue_id,
> +		const struct rte_flow_op_attr *op_attr,
> +		const struct rte_flow_template_table *template_table,
> +		uint32_t rule_index,
> +		const struct rte_flow_action *actions,
> +		uint8_t actions_template_index,
> +		const void *user_data, const struct rte_flow *flow),
> +	rte_trace_point_emit_u16(port_id);
> +	rte_trace_point_emit_u32(queue_id);
> +	rte_trace_point_emit_ptr(op_attr);
> +	rte_trace_point_emit_ptr(template_table);
> +	rte_trace_point_emit_u32(rule_index);
> +	rte_trace_point_emit_ptr(actions);
> +	rte_trace_point_emit_u8(actions_template_index);
> +	rte_trace_point_emit_ptr(user_data);
> +	rte_trace_point_emit_ptr(flow);
> +)

This tracepoint is not used anywhere and is not related to the addition of rte_flow_trace_async_create_by_index_with_pattern.
Maybe this tracepoint should be added in a separate commit?

> +RTE_TRACE_POINT_FP(
> +	rte_flow_trace_async_create_by_index_with_pattern,
> +	RTE_TRACE_POINT_ARGS(uint16_t port_id, uint32_t queue_id,
> +		const struct rte_flow_op_attr *op_attr,
> +		const struct rte_flow_template_table *template_table,
> +		uint32_t rule_index,
> +		const struct rte_flow_item *pattern,
> +		uint8_t pattern_template_index,
> +		const struct rte_flow_action *actions,
> +		uint8_t actions_template_index,
> +		const void *user_data, const struct rte_flow *flow),
> +	rte_trace_point_emit_u16(port_id);
> +	rte_trace_point_emit_u32(queue_id);
> +	rte_trace_point_emit_ptr(op_attr);
> +	rte_trace_point_emit_ptr(template_table);
> +	rte_trace_point_emit_u32(rule_index);
> +	rte_trace_point_emit_ptr(pattern);
> +	rte_trace_point_emit_u8(pattern_template_index);
> +	rte_trace_point_emit_ptr(actions);
> +	rte_trace_point_emit_u8(actions_template_index);
> +	rte_trace_point_emit_ptr(user_data);
> +	rte_trace_point_emit_ptr(flow);
> +)

This tracepoint is not used in this commit.
Could you please add the usage?

Best regards,
Dariusz Sosnowski
  

Patch

diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst
index dad588763f..adbd9b1c20 100644
--- a/doc/guides/prog_guide/rte_flow.rst
+++ b/doc/guides/prog_guide/rte_flow.rst
@@ -4156,6 +4156,26 @@  Enqueueing a flow rule creation operation to insert a rule at a table index.
 A valid handle in case of success is returned. It must be destroyed later
 by calling ``rte_flow_async_destroy()`` even if the rule is rejected by HW.
 
+Enqueue creation by index with pattern
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Enqueueing a flow rule creation operation to insert a rule at a table index with pattern.
+
+.. code-block:: c
+
+   struct rte_flow *
+   rte_flow_async_create_by_index_with_pattern(uint16_t port_id,
+                                               uint32_t queue_id,
+                                               const struct rte_flow_op_attr *op_attr,
+                                               struct rte_flow_template_table *template_table,
+                                               uint32_t rule_index,
+                                               const struct rte_flow_item pattern[],
+                                               uint8_t pattern_template_index,
+                                               const struct rte_flow_action actions[],
+                                               uint8_t actions_template_index,
+                                               void *user_data,
+                                               struct rte_flow_error *error);
+
 Enqueue destruction operation
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
diff --git a/doc/guides/rel_notes/release_24_11.rst b/doc/guides/rel_notes/release_24_11.rst
index 7056f17f3c..f71a9ab562 100644
--- a/doc/guides/rel_notes/release_24_11.rst
+++ b/doc/guides/rel_notes/release_24_11.rst
@@ -60,6 +60,11 @@  New Features
   Extended rte_flow_table_insertion_type enum with new
   RTE_FLOW_TABLE_INSERTION_TYPE_INDEX_WITH_PATTERN type.
 
+* **Added flow rule insertion by index with pattern to the Flow API.**
+
+  Added API for inserting the rule by index with pattern.
+  Introduced rte_flow_async_create_by_index_with_pattern() function.
+
 Removed Items
 -------------
 
diff --git a/lib/ethdev/ethdev_trace.h b/lib/ethdev/ethdev_trace.h
index 3bec87bfdb..910bedbebd 100644
--- a/lib/ethdev/ethdev_trace.h
+++ b/lib/ethdev/ethdev_trace.h
@@ -2343,6 +2343,50 @@  RTE_TRACE_POINT_FP(
 	rte_trace_point_emit_ptr(flow);
 )
 
+RTE_TRACE_POINT_FP(
+	rte_flow_trace_async_create_by_index,
+	RTE_TRACE_POINT_ARGS(uint16_t port_id, uint32_t queue_id,
+		const struct rte_flow_op_attr *op_attr,
+		const struct rte_flow_template_table *template_table,
+		uint32_t rule_index,
+		const struct rte_flow_action *actions,
+		uint8_t actions_template_index,
+		const void *user_data, const struct rte_flow *flow),
+	rte_trace_point_emit_u16(port_id);
+	rte_trace_point_emit_u32(queue_id);
+	rte_trace_point_emit_ptr(op_attr);
+	rte_trace_point_emit_ptr(template_table);
+	rte_trace_point_emit_u32(rule_index);
+	rte_trace_point_emit_ptr(actions);
+	rte_trace_point_emit_u8(actions_template_index);
+	rte_trace_point_emit_ptr(user_data);
+	rte_trace_point_emit_ptr(flow);
+)
+
+RTE_TRACE_POINT_FP(
+	rte_flow_trace_async_create_by_index_with_pattern,
+	RTE_TRACE_POINT_ARGS(uint16_t port_id, uint32_t queue_id,
+		const struct rte_flow_op_attr *op_attr,
+		const struct rte_flow_template_table *template_table,
+		uint32_t rule_index,
+		const struct rte_flow_item *pattern,
+		uint8_t pattern_template_index,
+		const struct rte_flow_action *actions,
+		uint8_t actions_template_index,
+		const void *user_data, const struct rte_flow *flow),
+	rte_trace_point_emit_u16(port_id);
+	rte_trace_point_emit_u32(queue_id);
+	rte_trace_point_emit_ptr(op_attr);
+	rte_trace_point_emit_ptr(template_table);
+	rte_trace_point_emit_u32(rule_index);
+	rte_trace_point_emit_ptr(pattern);
+	rte_trace_point_emit_u8(pattern_template_index);
+	rte_trace_point_emit_ptr(actions);
+	rte_trace_point_emit_u8(actions_template_index);
+	rte_trace_point_emit_ptr(user_data);
+	rte_trace_point_emit_ptr(flow);
+)
+
 RTE_TRACE_POINT_FP(
 	rte_flow_trace_async_destroy,
 	RTE_TRACE_POINT_ARGS(uint16_t port_id, uint32_t queue_id,
diff --git a/lib/ethdev/ethdev_trace_points.c b/lib/ethdev/ethdev_trace_points.c
index 99e04f5893..0563fb1451 100644
--- a/lib/ethdev/ethdev_trace_points.c
+++ b/lib/ethdev/ethdev_trace_points.c
@@ -583,6 +583,12 @@  RTE_TRACE_POINT_REGISTER(rte_flow_trace_template_table_destroy,
 RTE_TRACE_POINT_REGISTER(rte_flow_trace_async_create,
 	lib.ethdev.flow.async_create)
 
+RTE_TRACE_POINT_REGISTER(rte_flow_trace_async_create_by_index,
+	lib.ethdev.flow.async_create_by_index)
+
+RTE_TRACE_POINT_REGISTER(rte_flow_trace_async_create_by_index_with_pattern,
+	lib.ethdev.flow.async_create_by_index_with_pattern)
+
 RTE_TRACE_POINT_REGISTER(rte_flow_trace_async_destroy,
 	lib.ethdev.flow.async_destroy)
 
diff --git a/lib/ethdev/rte_flow.c b/lib/ethdev/rte_flow.c
index 4076ae4ee1..f6259343e8 100644
--- a/lib/ethdev/rte_flow.c
+++ b/lib/ethdev/rte_flow.c
@@ -2109,6 +2109,42 @@  rte_flow_async_create_by_index(uint16_t port_id,
 						       user_data, error);
 }
 
+struct rte_flow *
+rte_flow_async_create_by_index_with_pattern(uint16_t port_id,
+					    uint32_t queue_id,
+					    const struct rte_flow_op_attr *op_attr,
+					    struct rte_flow_template_table *template_table,
+					    uint32_t rule_index,
+					    const struct rte_flow_item pattern[],
+					    uint8_t pattern_template_index,
+					    const struct rte_flow_action actions[],
+					    uint8_t actions_template_index,
+					    void *user_data,
+					    struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+
+#ifdef RTE_FLOW_DEBUG
+	if (!rte_eth_dev_is_valid_port(port_id)) {
+		rte_flow_error_set(error, ENODEV, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+				   rte_strerror(ENODEV));
+		return NULL;
+	}
+	if (dev->flow_fp_ops == NULL ||
+	    dev->flow_fp_ops->async_create_by_index_with_pattern == NULL) {
+		rte_flow_error_set(error, ENOSYS, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+				   rte_strerror(ENOSYS));
+		return NULL;
+	}
+#endif
+
+	return dev->flow_fp_ops->async_create_by_index_with_pattern(dev, queue_id, op_attr,
+								    template_table, rule_index,
+								    pattern, pattern_template_index,
+								    actions, actions_template_index,
+								    user_data, error);
+}
+
 int
 rte_flow_async_destroy(uint16_t port_id,
 		       uint32_t queue_id,
@@ -2733,6 +2769,24 @@  rte_flow_dummy_async_create_by_index(struct rte_eth_dev *dev __rte_unused,
 	return NULL;
 }
 
+static struct rte_flow *
+rte_flow_dummy_async_create_by_index_with_pattern(struct rte_eth_dev *dev __rte_unused,
+						uint32_t queue __rte_unused,
+						const struct rte_flow_op_attr *attr __rte_unused,
+						struct rte_flow_template_table *table __rte_unused,
+						uint32_t rule_index __rte_unused,
+						const struct rte_flow_item items[] __rte_unused,
+						uint8_t pattern_template_index __rte_unused,
+						const struct rte_flow_action actions[] __rte_unused,
+						uint8_t action_template_index __rte_unused,
+						void *user_data __rte_unused,
+						struct rte_flow_error *error)
+{
+	rte_flow_error_set(error, ENOSYS, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+			   rte_strerror(ENOSYS));
+	return NULL;
+}
+
 static int
 rte_flow_dummy_async_actions_update(struct rte_eth_dev *dev __rte_unused,
 				    uint32_t queue_id __rte_unused,
@@ -2899,6 +2953,7 @@  struct rte_flow_fp_ops rte_flow_fp_default_ops = {
 	.async_create = rte_flow_dummy_async_create,
 	.async_create_by_index = rte_flow_dummy_async_create_by_index,
 	.async_actions_update = rte_flow_dummy_async_actions_update,
+	.async_create_by_index_with_pattern = rte_flow_dummy_async_create_by_index_with_pattern,
 	.async_destroy = rte_flow_dummy_async_destroy,
 	.push = rte_flow_dummy_push,
 	.pull = rte_flow_dummy_pull,
diff --git a/lib/ethdev/rte_flow.h b/lib/ethdev/rte_flow.h
index 6f30dd7ae9..84473241fb 100644
--- a/lib/ethdev/rte_flow.h
+++ b/lib/ethdev/rte_flow.h
@@ -6187,6 +6187,60 @@  rte_flow_async_create_by_index(uint16_t port_id,
 			       void *user_data,
 			       struct rte_flow_error *error);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Enqueue rule creation by index with pattern operation.
+ * Packets are only matched if there is a rule inserted at the index.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param queue_id
+ *   Flow queue used to insert the rule.
+ * @param[in] op_attr
+ *   Rule creation operation attributes.
+ * @param[in] template_table
+ *   Template table to select templates from.
+ * @param[in] rule_index
+ *   Rule index in the table.
+ *   Inserting a rule to already occupied index results in undefined behavior.
+ * @param[in] pattern
+ *   List of pattern items to be used.
+ *   The list order should match the order in the pattern template.
+ *   The spec is the only relevant member of the item that is being used.
+ * @param[in] pattern_template_index
+ *   Pattern template index in the table.
+ * @param[in] actions
+ *   List of actions to be used.
+ *   The list order should match the order in the actions template.
+ * @param[in] actions_template_index
+ *   Actions template index in the table.
+ * @param[in] user_data
+ *   The user data that will be returned on the completion events.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   Handle on success, NULL otherwise and rte_errno is set.
+ *   The rule handle doesn't mean that the rule has been populated.
+ *   Only completion result indicates that if there was success or failure.
+ */
+__rte_experimental
+struct rte_flow *
+rte_flow_async_create_by_index_with_pattern(uint16_t port_id,
+					    uint32_t queue_id,
+					    const struct rte_flow_op_attr *op_attr,
+					    struct rte_flow_template_table *template_table,
+					    uint32_t rule_index,
+					    const struct rte_flow_item pattern[],
+					    uint8_t pattern_template_index,
+					    const struct rte_flow_action actions[],
+					    uint8_t actions_template_index,
+					    void *user_data,
+					    struct rte_flow_error *error);
+
 /**
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
diff --git a/lib/ethdev/rte_flow_driver.h b/lib/ethdev/rte_flow_driver.h
index 506d1262ab..e00a5d7f7e 100644
--- a/lib/ethdev/rte_flow_driver.h
+++ b/lib/ethdev/rte_flow_driver.h
@@ -319,6 +319,19 @@  typedef struct rte_flow *(*rte_flow_async_create_by_index_t)(struct rte_eth_dev
 							     void *user_data,
 							     struct rte_flow_error *error);
 
+/** @internal Enqueue rule creation by index with pattern operation. */
+typedef struct rte_flow *(*rte_flow_async_create_by_index_with_pattern_t)(struct rte_eth_dev *dev,
+							uint32_t queue,
+							const struct rte_flow_op_attr *attr,
+							struct rte_flow_template_table *table,
+							uint32_t rule_index,
+							const struct rte_flow_item *items,
+							uint8_t pattern_template_index,
+							const struct rte_flow_action *actions,
+							uint8_t action_template_index,
+							void *user_data,
+							struct rte_flow_error *error);
+
 /** @internal Enqueue rule update operation. */
 typedef int (*rte_flow_async_actions_update_t)(struct rte_eth_dev *dev,
 					       uint32_t queue_id,
@@ -436,6 +449,7 @@  struct __rte_cache_aligned rte_flow_fp_ops {
 	rte_flow_async_create_t async_create;
 	rte_flow_async_create_by_index_t async_create_by_index;
 	rte_flow_async_actions_update_t async_actions_update;
+	rte_flow_async_create_by_index_with_pattern_t async_create_by_index_with_pattern;
 	rte_flow_async_destroy_t async_destroy;
 	rte_flow_push_t push;
 	rte_flow_pull_t pull;
diff --git a/lib/ethdev/version.map b/lib/ethdev/version.map
index 1669055ca5..8e02e1de8f 100644
--- a/lib/ethdev/version.map
+++ b/lib/ethdev/version.map
@@ -325,6 +325,9 @@  EXPERIMENTAL {
 	rte_flow_template_table_resizable;
 	rte_flow_template_table_resize;
 	rte_flow_template_table_resize_complete;
+
+	# added in 24.11
+	rte_flow_async_create_by_index_with_pattern;
 };
 
 INTERNAL {