[v5,07/42] net/dpaa2: dpdmux: add support for CVLAN

Message ID 20241023115955.1207617-8-vanshika.shukla@nxp.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series DPAA2 specific patches |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Vanshika Shukla Oct. 23, 2024, 11:59 a.m. UTC
From: Vanshika Shukla <vanshika.shukla@nxp.com>

This patch adds the support for DPDMUX_METHOD_C_VLAN_MAC method
which implements DPDMUX based on C-VLAN and MAC address.

Signed-off-by: Vanshika Shukla <vanshika.shukla@nxp.com>
---
 drivers/net/dpaa2/dpaa2_mux.c     | 59 +++++++++++++++++++++++++------
 drivers/net/dpaa2/mc/fsl_dpdmux.h | 18 +++++++++-
 drivers/net/dpaa2/rte_pmd_dpaa2.h |  3 ++
 3 files changed, 68 insertions(+), 12 deletions(-)
  

Patch

diff --git a/drivers/net/dpaa2/dpaa2_mux.c b/drivers/net/dpaa2/dpaa2_mux.c
index 489beb6f27..3693f4b62e 100644
--- a/drivers/net/dpaa2/dpaa2_mux.c
+++ b/drivers/net/dpaa2/dpaa2_mux.c
@@ -233,6 +233,35 @@  rte_pmd_dpaa2_mux_flow_create(uint32_t dpdmux_id,
 	return NULL;
 }
 
+int
+rte_pmd_dpaa2_mux_flow_l2(uint32_t dpdmux_id,
+	uint8_t mac_addr[6], uint16_t vlan_id, int dest_if)
+{
+	struct dpaa2_dpdmux_dev *dpdmux_dev;
+	struct dpdmux_l2_rule rule;
+	int ret, i;
+
+	/* Find the DPDMUX from dpdmux_id in our list */
+	dpdmux_dev = get_dpdmux_from_id(dpdmux_id);
+	if (!dpdmux_dev) {
+		DPAA2_PMD_ERR("Invalid dpdmux_id: %d", dpdmux_id);
+		return -ENODEV;
+	}
+
+	for (i = 0; i < 6; i++)
+		rule.mac_addr[i] = mac_addr[i];
+	rule.vlan_id = vlan_id;
+
+	ret = dpdmux_if_add_l2_rule(&dpdmux_dev->dpdmux, CMD_PRI_LOW,
+			dpdmux_dev->token, dest_if, &rule);
+	if (ret) {
+		DPAA2_PMD_ERR("dpdmux_if_add_l2_rule failed:err(%d)", ret);
+		return ret;
+	}
+
+	return 0;
+}
+
 int
 rte_pmd_dpaa2_mux_rx_frame_len(uint32_t dpdmux_id, uint16_t max_rx_frame_len)
 {
@@ -353,6 +382,7 @@  dpaa2_create_dpdmux_device(int vdev_fd __rte_unused,
 	int ret;
 	uint16_t maj_ver;
 	uint16_t min_ver;
+	uint8_t skip_reset_flags;
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -379,12 +409,18 @@  dpaa2_create_dpdmux_device(int vdev_fd __rte_unused,
 		goto init_err;
 	}
 
-	ret = dpdmux_if_set_default(&dpdmux_dev->dpdmux, CMD_PRI_LOW,
-				    dpdmux_dev->token, attr.default_if);
-	if (ret) {
-		DPAA2_PMD_ERR("setting default interface failed in %s",
-			      __func__);
-		goto init_err;
+	if (attr.method != DPDMUX_METHOD_C_VLAN_MAC) {
+		ret = dpdmux_if_set_default(&dpdmux_dev->dpdmux, CMD_PRI_LOW,
+				dpdmux_dev->token, attr.default_if);
+		if (ret) {
+			DPAA2_PMD_ERR("setting default interface failed in %s",
+				      __func__);
+			goto init_err;
+		}
+		skip_reset_flags = DPDMUX_SKIP_DEFAULT_INTERFACE
+			| DPDMUX_SKIP_UNICAST_RULES | DPDMUX_SKIP_MULTICAST_RULES;
+	} else {
+		skip_reset_flags = DPDMUX_SKIP_DEFAULT_INTERFACE;
 	}
 
 	ret = dpdmux_get_api_version(&dpdmux_dev->dpdmux, CMD_PRI_LOW,
@@ -400,10 +436,7 @@  dpaa2_create_dpdmux_device(int vdev_fd __rte_unused,
 	 */
 	if (maj_ver >= 6 && min_ver >= 6) {
 		ret = dpdmux_set_resetable(&dpdmux_dev->dpdmux, CMD_PRI_LOW,
-				dpdmux_dev->token,
-				DPDMUX_SKIP_DEFAULT_INTERFACE |
-				DPDMUX_SKIP_UNICAST_RULES |
-				DPDMUX_SKIP_MULTICAST_RULES);
+				dpdmux_dev->token, skip_reset_flags);
 		if (ret) {
 			DPAA2_PMD_ERR("setting default interface failed in %s",
 				      __func__);
@@ -416,7 +449,11 @@  dpaa2_create_dpdmux_device(int vdev_fd __rte_unused,
 
 		memset(&mux_err_cfg, 0, sizeof(mux_err_cfg));
 		mux_err_cfg.error_action = DPDMUX_ERROR_ACTION_CONTINUE;
-		mux_err_cfg.errors = DPDMUX_ERROR_DISC;
+
+		if (attr.method != DPDMUX_METHOD_C_VLAN_MAC)
+			mux_err_cfg.errors = DPDMUX_ERROR_DISC;
+		else
+			mux_err_cfg.errors = DPDMUX_ALL_ERRORS;
 
 		ret = dpdmux_if_set_errors_behavior(&dpdmux_dev->dpdmux,
 				CMD_PRI_LOW,
diff --git a/drivers/net/dpaa2/mc/fsl_dpdmux.h b/drivers/net/dpaa2/mc/fsl_dpdmux.h
index 4600ea94d4..9bbac44219 100644
--- a/drivers/net/dpaa2/mc/fsl_dpdmux.h
+++ b/drivers/net/dpaa2/mc/fsl_dpdmux.h
@@ -1,7 +1,7 @@ 
 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
  *
  * Copyright 2013-2016 Freescale Semiconductor Inc.
- * Copyright 2018-2021 NXP
+ * Copyright 2018-2022 NXP
  *
  */
 #ifndef __FSL_DPDMUX_H
@@ -549,6 +549,22 @@  int dpdmux_get_api_version(struct fsl_mc_io *mc_io,
  */
 #define DPDMUX__ERROR_L4CE			0x00000001
 
+#define DPDMUX_ALL_ERRORS	(DPDMUX__ERROR_L4CE | \
+				 DPDMUX__ERROR_L4CV | \
+				 DPDMUX__ERROR_L3CE | \
+				 DPDMUX__ERROR_L3CV | \
+				 DPDMUX_ERROR_BLE | \
+				 DPDMUX_ERROR_PHE | \
+				 DPDMUX_ERROR_ISP | \
+				 DPDMUX_ERROR_PTE | \
+				 DPDMUX_ERROR_FPE | \
+				 DPDMUX_ERROR_FLE | \
+				 DPDMUX_ERROR_PIEE | \
+				 DPDMUX_ERROR_TIDE | \
+				 DPDMUX_ERROR_MNLE | \
+				 DPDMUX_ERROR_EOFHE | \
+				 DPDMUX_ERROR_KSE)
+
 enum dpdmux_error_action {
 	DPDMUX_ERROR_ACTION_DISCARD = 0,
 	DPDMUX_ERROR_ACTION_CONTINUE = 1
diff --git a/drivers/net/dpaa2/rte_pmd_dpaa2.h b/drivers/net/dpaa2/rte_pmd_dpaa2.h
index 80e5e3298b..bebebcacdc 100644
--- a/drivers/net/dpaa2/rte_pmd_dpaa2.h
+++ b/drivers/net/dpaa2/rte_pmd_dpaa2.h
@@ -35,6 +35,9 @@  rte_pmd_dpaa2_mux_flow_create(uint32_t dpdmux_id,
 int
 rte_pmd_dpaa2_mux_flow_destroy(uint32_t dpdmux_id,
 	uint16_t entry_index);
+int
+rte_pmd_dpaa2_mux_flow_l2(uint32_t dpdmux_id,
+	uint8_t mac_addr[6], uint16_t vlan_id, int dest_if);
 
 /**
  * @warning