[v7,03/12] ethdev: add port representor action to flow API

Message ID 20211013173448.28621-4-ivan.malov@oktetlabs.ru (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series ethdev: rework transfer flow API |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Ivan Malov Oct. 13, 2021, 5:34 p.m. UTC
  For use in "transfer" flows. Supposed to send matching traffic to
the given ethdev (to the application), at embedded switch level.

Signed-off-by: Ivan Malov <ivan.malov@oktetlabs.ru>
Acked-by: Ori Kam <orika@nvidia.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 app/test-pmd/cmdline_flow.c                 | 26 ++++++++++
 doc/guides/nics/features/default.ini        |  1 +
 doc/guides/prog_guide/rte_flow.rst          | 56 +++++++++++++++++++++
 doc/guides/rel_notes/release_21_11.rst      |  2 +-
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  5 ++
 lib/ethdev/rte_flow.c                       |  1 +
 lib/ethdev/rte_flow.h                       | 18 +++++++
 7 files changed, 108 insertions(+), 1 deletion(-)
  

Patch

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 354f0fb2d7..1496d7a067 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -459,6 +459,8 @@  enum index {
 	ACTION_POL_G,
 	ACTION_POL_Y,
 	ACTION_POL_R,
+	ACTION_PORT_REPRESENTOR,
+	ACTION_PORT_REPRESENTOR_PORT_ID,
 };
 
 /** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -1451,6 +1453,7 @@  static const enum index next_action[] = {
 	ACTION_MODIFY_FIELD,
 	ACTION_CONNTRACK,
 	ACTION_CONNTRACK_UPDATE,
+	ACTION_PORT_REPRESENTOR,
 	ZERO,
 };
 
@@ -1731,6 +1734,12 @@  static const enum index action_update_conntrack[] = {
 	ZERO,
 };
 
+static const enum index action_port_representor[] = {
+	ACTION_PORT_REPRESENTOR_PORT_ID,
+	ACTION_NEXT,
+	ZERO,
+};
+
 static int parse_set_raw_encap_decap(struct context *, const struct token *,
 				     const char *, unsigned int,
 				     void *, unsigned int);
@@ -4810,6 +4819,23 @@  static const struct token token_list[] = {
 		.next = NEXT(action_update_conntrack),
 		.call = parse_vc_action_conntrack_update,
 	},
+	[ACTION_PORT_REPRESENTOR] = {
+		.name = "port_representor",
+		.help = "at embedded switch level, send matching traffic to the given ethdev",
+		.priv = PRIV_ACTION(PORT_REPRESENTOR,
+				    sizeof(struct rte_flow_action_ethdev)),
+		.next = NEXT(action_port_representor),
+		.call = parse_vc,
+	},
+	[ACTION_PORT_REPRESENTOR_PORT_ID] = {
+		.name = "port_id",
+		.help = "ethdev port ID",
+		.next = NEXT(action_port_representor,
+			     NEXT_ENTRY(COMMON_UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct rte_flow_action_ethdev,
+					port_id)),
+		.call = parse_vc_conf,
+	},
 	/* Indirect action destroy arguments. */
 	[INDIRECT_ACTION_DESTROY_ID] = {
 		.name = "action_id",
diff --git a/doc/guides/nics/features/default.ini b/doc/guides/nics/features/default.ini
index 419bffc66e..f7f937ca0a 100644
--- a/doc/guides/nics/features/default.ini
+++ b/doc/guides/nics/features/default.ini
@@ -169,6 +169,7 @@  passthru             =
 pf                   =
 phy_port             =
 port_id              =
+port_representor     =
 queue                =
 raw_decap            =
 raw_encap            =
diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst
index 2da286dce8..587ed37c2c 100644
--- a/doc/guides/prog_guide/rte_flow.rst
+++ b/doc/guides/prog_guide/rte_flow.rst
@@ -1484,6 +1484,8 @@  at the opposite end of the "wire" leading to the ethdev.
 
 - Default ``mask`` provides exact match behaviour.
 
+See also `Action: PORT_REPRESENTOR`_.
+
 Item: ``REPRESENTED_PORT``
 ^^^^^^^^^^^^^^^^^^^^^^^^^^
 
@@ -3089,6 +3091,60 @@  which is set in the packet meta-data (i.e. struct ``rte_mbuf::sched::color``)
    | ``meter_color`` | Packet color |
    +-----------------+--------------+
 
+Action: ``PORT_REPRESENTOR``
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+At embedded switch level, send matching traffic to the given ethdev.
+
+Term **ethdev** and the concept of **port representor** are synonymous.
+The **represented port** is an *entity* plugged to the embedded switch
+at the opposite end of the "wire" leading to the ethdev.
+
+::
+
+    .--------------------.
+    |  PORT_REPRESENTOR  |  Ethdev (Application Port Referred to by its ID)
+    '--------------------'
+              /\
+              ||
+      .----------------.
+      |  Logical Port  |
+      '----------------'
+              /\
+              ||
+              ||
+              ||
+         .----------.       .--------------------.
+         |  Switch  |  <==  |  Matching Traffic  |
+         '----------'       '--------------------'
+              :
+               :
+              :
+               :
+      .----------------.
+      |  Logical Port  |
+      '----------------'
+              :
+               :
+    .--------------------.
+    |  REPRESENTED_PORT  |  Net / Guest / Another Ethdev (Same Application)
+    '--------------------'
+
+
+- Requires `Attribute: Transfer`_.
+
+.. _table_rte_flow_action_ethdev:
+
+.. table:: ``struct rte_flow_action_ethdev``
+
+   +-------------+----------------+
+   | Field       | Value          |
+   +=============+================+
+   | ``port_id`` | ethdev port ID |
+   +-------------+----------------+
+
+See also `Item: PORT_REPRESENTOR`_.
+
 Negative types
 ~~~~~~~~~~~~~~
 
diff --git a/doc/guides/rel_notes/release_21_11.rst b/doc/guides/rel_notes/release_21_11.rst
index b9f918cab8..9a0ab97914 100644
--- a/doc/guides/rel_notes/release_21_11.rst
+++ b/doc/guides/rel_notes/release_21_11.rst
@@ -252,7 +252,7 @@  API Changes
   the crypto/security operation. This field will be used to communicate
   events such as soft expiry with IPsec in lookaside mode.
 
-* ethdev: Added items ``PORT_REPRESENTOR``, ``REPRESENTED_PORT`` to flow API.
+* ethdev: Added items ``PORT_REPRESENTOR``, ``REPRESENTED_PORT`` and action ``PORT_REPRESENTOR`` to flow API.
 
 
 ABI Changes
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index 61669d1d5a..46b7f07cbc 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -4085,6 +4085,11 @@  This section lists supported actions and their attributes, if any.
 
   - ``type {value}``: Set color type with specified value(green/yellow/red)
 
+- ``port_representor``: at embedded switch level, send matching traffic to
+  the given ethdev
+
+  - ``port_id {unsigned}``: ethdev port ID
+
 Destroying flow rules
 ~~~~~~~~~~~~~~~~~~~~~
 
diff --git a/lib/ethdev/rte_flow.c b/lib/ethdev/rte_flow.c
index d4b654a2c6..b074b1c77d 100644
--- a/lib/ethdev/rte_flow.c
+++ b/lib/ethdev/rte_flow.c
@@ -191,6 +191,7 @@  static const struct rte_flow_desc_data rte_flow_desc_action[] = {
 	 */
 	MK_FLOW_ACTION(INDIRECT, 0),
 	MK_FLOW_ACTION(CONNTRACK, sizeof(struct rte_flow_action_conntrack)),
+	MK_FLOW_ACTION(PORT_REPRESENTOR, sizeof(struct rte_flow_action_ethdev)),
 };
 
 int
diff --git a/lib/ethdev/rte_flow.h b/lib/ethdev/rte_flow.h
index b50c3d38b5..56fd4393e5 100644
--- a/lib/ethdev/rte_flow.h
+++ b/lib/ethdev/rte_flow.h
@@ -2455,6 +2455,13 @@  enum rte_flow_action_type {
 	 * See struct rte_flow_action_meter_color.
 	 */
 	RTE_FLOW_ACTION_TYPE_METER_COLOR,
+
+	/**
+	 * At embedded switch level, sends matching traffic to the given ethdev.
+	 *
+	 * @see struct rte_flow_action_ethdev
+	 */
+	RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR,
 };
 
 /**
@@ -3200,6 +3207,17 @@  struct rte_flow_action_meter_color {
 	enum rte_color color; /**< Packet color. */
 };
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * Provides an ethdev port ID for use with the following actions:
+ * RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR.
+ */
+struct rte_flow_action_ethdev {
+	uint16_t port_id; /**< ethdev port ID */
+};
+
 /**
  * Field IDs for MODIFY_FIELD action.
  */