[v8,13/47] net/bnxt: tf_ulp: add custom l2 etype tunnel support

Message ID 20241107135254.1611676-14-sriharsha.basavapatna@broadcom.com (mailing list archive)
State Accepted, archived
Delegated to: Ajit Khaparde
Headers
Series TruFlow update for Thor2 |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Sriharsha Basavapatna Nov. 7, 2024, 1:52 p.m. UTC
From: Shahaji Bhosle <sbhosle@broadcom.com>

Add hooks in the hwrm and ulp layer to enable,
custom tunnel header support on wh+ generic app(ovs).

Signed-off-by: Shahaji Bhosle <sbhosle@broadcom.com>
Signed-off-by: Sriharsha Basavapatna <sriharsha.basavapatna@broadcom.com>
Reviewed-by: Kishore Padmanabha <kishore.padmanabha@broadcom.com>
Reviewed-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
---
 drivers/net/bnxt/bnxt.h            |  4 +++
 drivers/net/bnxt/bnxt_hwrm.c       | 18 ++++++++++
 drivers/net/bnxt/tf_ulp/bnxt_ulp.c | 54 ++++++++++++++++++++++++++++++
 drivers/net/bnxt/tf_ulp/bnxt_ulp.h |  3 ++
 4 files changed, 79 insertions(+)
  

Patch

diff --git a/drivers/net/bnxt/bnxt.h b/drivers/net/bnxt/bnxt.h
index ce10167e1f..b50ae71c1f 100644
--- a/drivers/net/bnxt/bnxt.h
+++ b/drivers/net/bnxt/bnxt.h
@@ -989,13 +989,17 @@  struct bnxt {
 	uint8_t			vxlan_port_cnt;
 	uint8_t			geneve_port_cnt;
 	uint8_t			ecpri_port_cnt;
+	uint8_t			l2_etype_tunnel_cnt;
 	uint16_t		vxlan_port;
 	uint16_t		geneve_port;
 	uint16_t		ecpri_port;
 	uint16_t		vxlan_fw_dst_port_id;
 	uint16_t		geneve_fw_dst_port_id;
 	uint16_t		ecpri_fw_dst_port_id;
+#define BNXT_L2_ETYPE_TUNNEL_ID 0xFFFF /* CUSTOM L2 ENCAP - VF representors */
+	uint16_t		l2_etype_tunnel_id;
 	uint16_t		ecpri_upar_in_use;
+	uint8_t			l2_etype_upar_in_use;
 	uint32_t		fw_ver;
 	uint32_t		hwrm_spec_code;
 
diff --git a/drivers/net/bnxt/bnxt_hwrm.c b/drivers/net/bnxt/bnxt_hwrm.c
index 97ea32b286..c102e2cdb3 100644
--- a/drivers/net/bnxt/bnxt_hwrm.c
+++ b/drivers/net/bnxt/bnxt_hwrm.c
@@ -3542,6 +3542,10 @@  bnxt_free_tunnel_ports(struct bnxt *bp)
 	if (bp->ecpri_port_cnt)
 		bnxt_hwrm_tunnel_dst_port_free(bp, bp->ecpri_fw_dst_port_id,
 			HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_ECPRI);
+
+	if (bp->l2_etype_tunnel_cnt)
+		bnxt_hwrm_tunnel_dst_port_free(bp, bp->l2_etype_tunnel_id,
+			HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_L2_ETYPE);
 }
 
 void bnxt_free_all_hwrm_resources(struct bnxt *bp)
@@ -4839,6 +4843,10 @@  int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt *bp, uint16_t port,
 		bp->ecpri_port = port;
 		bp->ecpri_upar_in_use = resp->upar_in_use;
 		break;
+	case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_L2_ETYPE:
+		bp->l2_etype_tunnel_id = port;
+		bp->l2_etype_upar_in_use = resp->upar_in_use;
+		break;
 	default:
 		break;
 	}
@@ -4869,6 +4877,9 @@  int bnxt_hwrm_tunnel_upar_id_get(struct bnxt *bp, uint8_t *upar_id,
 	case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_SRV6:
 		*upar_id = resp->upar_in_use;
 		break;
+	case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_L2_ETYPE:
+		*upar_id = resp->upar_in_use;
+		break;
 	default:
 		/* INVALID UPAR Id if another tunnel type tries to retrieve */
 		*upar_id = 0xff;
@@ -4915,6 +4926,13 @@  int bnxt_hwrm_tunnel_dst_port_free(struct bnxt *bp, uint16_t port,
 		bp->ecpri_port_cnt = 0;
 	}
 
+	if (tunnel_type ==
+	    HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_L2_ETYPE) {
+		bp->l2_etype_tunnel_cnt = 0;
+		bp->l2_etype_tunnel_id = 0;
+		bp->l2_etype_upar_in_use = 0;
+	}
+
 	bnxt_hwrm_set_tpa(bp);
 	return rc;
 }
diff --git a/drivers/net/bnxt/tf_ulp/bnxt_ulp.c b/drivers/net/bnxt/tf_ulp/bnxt_ulp.c
index 5afb4d4e3d..a0b252c6e4 100644
--- a/drivers/net/bnxt/tf_ulp/bnxt_ulp.c
+++ b/drivers/net/bnxt/tf_ulp/bnxt_ulp.c
@@ -454,6 +454,10 @@  bnxt_ulp_cntxt_app_caps_init(struct bnxt *bp,
 			}
 		}
 
+		if (info[i].flags & BNXT_ULP_APP_CAP_L2_ETYPE)
+			ulp_ctx->cfg_data->ulp_flags |=
+				BNXT_ULP_APP_L2_ETYPE;
+
 		bnxt_ulp_vxlan_ip_port_set(ulp_ctx, info[i].vxlan_ip_port);
 		bnxt_ulp_vxlan_port_set(ulp_ctx, info[i].vxlan_port);
 		bnxt_ulp_ecpri_udp_port_set(ulp_ctx, info[i].ecpri_udp_port);
@@ -1795,6 +1799,29 @@  bnxt_ulp_init(struct bnxt *bp,
 	return rc;
 }
 
+static int
+ulp_l2_etype_tunnel_alloc(struct bnxt *bp)
+{
+	int rc = 0;
+
+	if (!ULP_APP_L2_ETYPE_SUPPORT(bp->ulp_ctx))
+		return rc;
+
+	if (bp->l2_etype_tunnel_cnt) {
+		BNXT_TF_DBG(DEBUG, "L2 ETYPE Custom Tunnel already allocated\n");
+		return rc;
+	}
+	rc = bnxt_tunnel_dst_port_alloc(bp,
+					BNXT_L2_ETYPE_TUNNEL_ID,
+					HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_L2_ETYPE);
+	if (rc)
+		BNXT_TF_DBG(ERR, "Failed to set global L2 ETYPE Custom Tunnel\n");
+	else
+		bp->l2_etype_tunnel_cnt++;
+
+	return rc;
+}
+
 static int
 ulp_cust_vxlan_alloc(struct bnxt *bp)
 {
@@ -1943,6 +1970,10 @@  bnxt_ulp_port_init(struct bnxt *bp)
 	if (rc)
 		goto jump_to_error;
 
+	rc = ulp_l2_etype_tunnel_alloc(bp);
+	if (rc)
+		goto jump_to_error;
+
 	return rc;
 
 jump_to_error:
@@ -1950,6 +1981,28 @@  bnxt_ulp_port_init(struct bnxt *bp)
 	return rc;
 }
 
+static void
+ulp_l2_etype_tunnel_free(struct bnxt *bp)
+{
+	int rc;
+
+	if (!ULP_APP_L2_ETYPE_SUPPORT(bp->ulp_ctx))
+		return;
+
+	if (bp->l2_etype_tunnel_cnt == 0) {
+		BNXT_TF_DBG(DEBUG, "L2 ETYPE Custom Tunnel already freed\n");
+		return;
+	}
+
+	rc = bnxt_tunnel_dst_port_free(bp,
+				       BNXT_L2_ETYPE_TUNNEL_ID,
+				       HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_L2_ETYPE);
+	if (rc)
+		BNXT_TF_DBG(ERR, "Failed to clear L2 ETYPE Custom Tunnel\n");
+
+	bp->l2_etype_tunnel_cnt--;
+}
+
 static void
 ulp_cust_vxlan_free(struct bnxt *bp)
 {
@@ -2026,6 +2079,7 @@  bnxt_ulp_port_deinit(struct bnxt *bp)
 		if (bp->ulp_ctx->cfg_data->ref_cnt) {
 			/* Free tunnel configurations */
 			ulp_cust_vxlan_free(bp);
+			ulp_l2_etype_tunnel_free(bp);
 
 			/* free the port details */
 			/* Free the default flow rule associated to this port */
diff --git a/drivers/net/bnxt/tf_ulp/bnxt_ulp.h b/drivers/net/bnxt/tf_ulp/bnxt_ulp.h
index d42382d947..8b75120926 100644
--- a/drivers/net/bnxt/tf_ulp/bnxt_ulp.h
+++ b/drivers/net/bnxt/tf_ulp/bnxt_ulp.h
@@ -40,6 +40,7 @@ 
 #define BNXT_ULP_CUST_VXLAN_SUPPORT	0x100
 #define BNXT_ULP_MULTI_SHARED_SUPPORT	0x200
 #define BNXT_ULP_APP_HA_DYNAMIC		0x400
+#define BNXT_ULP_APP_L2_ETYPE		0x800
 
 #define ULP_VF_REP_IS_ENABLED(flag)	((flag) & BNXT_ULP_VF_REP_ENABLED)
 #define ULP_SHARED_SESSION_IS_ENABLED(flag) ((flag) &\
@@ -60,6 +61,8 @@ 
 #define ULP_APP_CUST_VXLAN_SUPPORT(ctx)	   ((ctx)->cfg_data->vxlan_port != 0)
 #define ULP_APP_VXLAN_GPE_SUPPORT(ctx)     ((ctx)->cfg_data->vxlan_gpe_port != 0)
 #define ULP_APP_CUST_VXLAN_IP_SUPPORT(ctx) ((ctx)->cfg_data->vxlan_ip_port != 0)
+#define ULP_APP_L2_ETYPE_SUPPORT(ctx)	((ctx)->cfg_data->ulp_flags &\
+					BNXT_ULP_APP_L2_ETYPE)
 
 enum bnxt_ulp_flow_mem_type {
 	BNXT_ULP_FLOW_MEM_TYPE_INT = 0,