[v2,10/11] net/nfp: support MARK flow action

Message ID 20231205025457.1067372-11-chaoyong.he@corigine.com (mailing list archive)
State Accepted
Delegated to: Ferruh Yigit
Headers
Series Add basic flow support for corenic firmware |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Chaoyong He Dec. 5, 2023, 2:54 a.m. UTC
  Add the corresponding logics to support the offload of MARK action.
Also add the related logics to parse the mark id and put into the mbuf
structure, and assigned the offload flags.

Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
Reviewed-by: Long Wu <long.wu@corigine.com>
Reviewed-by: Peng Zhang <peng.zhang@corigine.com>
---
 doc/guides/nics/features/nfp.ini     |  1 +
 drivers/common/nfp/nfp_common_ctrl.h |  1 +
 drivers/net/nfp/nfp_net_flow.c       | 18 ++++++++++++++++++
 drivers/net/nfp/nfp_rxtx.c           | 18 ++++++++++++++++++
 4 files changed, 38 insertions(+)
  

Patch

diff --git a/doc/guides/nics/features/nfp.ini b/doc/guides/nics/features/nfp.ini
index 1a09c4cbaf..248fd34a39 100644
--- a/doc/guides/nics/features/nfp.ini
+++ b/doc/guides/nics/features/nfp.ini
@@ -48,6 +48,7 @@  conntrack            = Y
 count                = Y
 drop                 = Y
 jump                 = Y
+mark                 = Y
 meter                = Y
 of_pop_vlan          = Y
 of_push_vlan         = Y
diff --git a/drivers/common/nfp/nfp_common_ctrl.h b/drivers/common/nfp/nfp_common_ctrl.h
index cbde987736..d65fcd17cb 100644
--- a/drivers/common/nfp/nfp_common_ctrl.h
+++ b/drivers/common/nfp/nfp_common_ctrl.h
@@ -33,6 +33,7 @@ 
 
 /* Prepend field types */
 #define NFP_NET_META_HASH               1 /* Next field carries hash type */
+#define NFP_NET_META_MARK               2
 #define NFP_NET_META_VLAN               4
 #define NFP_NET_META_PORTID             5
 #define NFP_NET_META_IPSEC              9
diff --git a/drivers/net/nfp/nfp_net_flow.c b/drivers/net/nfp/nfp_net_flow.c
index f561e9ecbe..71f126156e 100644
--- a/drivers/net/nfp/nfp_net_flow.c
+++ b/drivers/net/nfp/nfp_net_flow.c
@@ -548,6 +548,20 @@  nfp_net_flow_action_drop(struct rte_flow *nfp_flow)
 	action_data->action = NFP_NET_CMSG_ACTION_DROP;
 }
 
+static void
+nfp_net_flow_action_mark(struct rte_flow *nfp_flow,
+		const struct rte_flow_action *action)
+{
+	struct nfp_net_cmsg_action *action_data;
+	const struct rte_flow_action_mark *mark;
+
+	action_data = (struct nfp_net_cmsg_action *)nfp_flow->payload.action_data;
+	mark = action->conf;
+
+	action_data->action |= NFP_NET_CMSG_ACTION_MARK;
+	action_data->mark_id = mark->id;
+}
+
 static int
 nfp_net_flow_compile_actions(const struct rte_flow_action actions[],
 		struct rte_flow *nfp_flow)
@@ -560,6 +574,10 @@  nfp_net_flow_compile_actions(const struct rte_flow_action actions[],
 			PMD_DRV_LOG(DEBUG, "Process RTE_FLOW_ACTION_TYPE_DROP");
 			nfp_net_flow_action_drop(nfp_flow);
 			return 0;
+		case RTE_FLOW_ACTION_TYPE_MARK:
+			PMD_DRV_LOG(DEBUG, "Process RTE_FLOW_ACTION_TYPE_MARK");
+			nfp_net_flow_action_mark(nfp_flow, action);
+			break;
 		default:
 			PMD_DRV_LOG(ERR, "Unsupported action type: %d", action->type);
 			return -ENOTSUP;
diff --git a/drivers/net/nfp/nfp_rxtx.c b/drivers/net/nfp/nfp_rxtx.c
index f21e120a43..5094bbf145 100644
--- a/drivers/net/nfp/nfp_rxtx.c
+++ b/drivers/net/nfp/nfp_rxtx.c
@@ -25,6 +25,8 @@  struct nfp_meta_parsed {
 	uint32_t port_id;         /**< Port id value */
 	uint32_t sa_idx;          /**< IPsec SA index */
 	uint32_t hash;            /**< RSS hash value */
+	uint32_t mark_id;         /**< Mark id value */
+	uint16_t flags;           /**< Bitmap to indicate if meta exist */
 	uint8_t hash_type;        /**< RSS hash type */
 	uint8_t ipsec_type;       /**< IPsec type */
 	uint8_t vlan_layer;       /**< The valid number of value in @vlan[] */
@@ -290,6 +292,10 @@  nfp_net_parse_chained_meta(uint8_t *meta_base,
 			meta->sa_idx = rte_be_to_cpu_32(*(rte_be32_t *)meta_offset);
 			meta->ipsec_type = meta_info & NFP_NET_META_FIELD_MASK;
 			break;
+		case NFP_NET_META_MARK:
+			meta->flags |= (1 << NFP_NET_META_MARK);
+			meta->mark_id = rte_be_to_cpu_32(*(rte_be32_t *)meta_offset);
+			break;
 		default:
 			/* Unsupported metadata can be a performance issue */
 			return false;
@@ -434,6 +440,17 @@  nfp_net_parse_meta_ipsec(struct nfp_meta_parsed *meta,
 	}
 }
 
+static void
+nfp_net_parse_meta_mark(const struct nfp_meta_parsed *meta,
+		struct rte_mbuf *mbuf)
+{
+	if (((meta->flags >> NFP_NET_META_MARK) & 0x1) == 0)
+		return;
+
+	mbuf->hash.fdir.hi = meta->mark_id;
+	mbuf->ol_flags |= RTE_MBUF_F_RX_FDIR | RTE_MBUF_F_RX_FDIR_ID;
+}
+
 /* Parse the metadata from packet */
 static void
 nfp_net_parse_meta(struct nfp_net_rx_desc *rxds,
@@ -458,6 +475,7 @@  nfp_net_parse_meta(struct nfp_net_rx_desc *rxds,
 			nfp_net_parse_meta_vlan(meta, rxds, rxq, mb);
 			nfp_net_parse_meta_qinq(meta, rxq, mb);
 			nfp_net_parse_meta_ipsec(meta, rxq, mb);
+			nfp_net_parse_meta_mark(meta, mb);
 		} else {
 			PMD_RX_LOG(DEBUG, "RX chained metadata format is wrong!");
 		}