diff mbox series

[13/20] net/bnxt: enable support for PF and VF port action items

Message ID 20200706082502.26935-14-somnath.kotur@broadcom.com (mailing list archive)
State Accepted, archived
Delegated to: Ajit Khaparde
Headers show
Series bnxt patches | expand

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/Intel-compilation fail Compilation issues
ci/checkpatch success coding style OK

Commit Message

Somnath Kotur July 6, 2020, 8:24 a.m. UTC
From: Kishore Padmanabha <kishore.padmanabha@broadcom.com>

Added support for the PF and VF port action items in the flow
create. During flow create the output port action can now be specified
as PF or VF port and those ports are parsed accordingly and converted
to vnic or vport as per the flow direction.

Signed-off-by: Kishore Padmanabha <kishore.padmanabha@broadcom.com>
Reviewed-by: Michael Baucom <michael.baucom@broadcom.com>
Signed-off-by: Somnath Kotur <somnath.kotur@broadcom.com>
Signed-off-by: Venkat Duvvuru <venkatkumar.duvvuru@broadcom.com>
---
 drivers/net/bnxt/tf_ulp/ulp_port_db.c          |  52 +++++++++
 drivers/net/bnxt/tf_ulp/ulp_port_db.h          |  26 +++++
 drivers/net/bnxt/tf_ulp/ulp_rte_parser.c       | 151 +++++++++++++++++--------
 drivers/net/bnxt/tf_ulp/ulp_rte_parser.h       |   4 +-
 drivers/net/bnxt/tf_ulp/ulp_template_db_enum.h |   4 +-
 5 files changed, 189 insertions(+), 48 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/bnxt/tf_ulp/ulp_port_db.c b/drivers/net/bnxt/tf_ulp/ulp_port_db.c
index 3c5a218..122b5f4 100644
--- a/drivers/net/bnxt/tf_ulp/ulp_port_db.c
+++ b/drivers/net/bnxt/tf_ulp/ulp_port_db.c
@@ -162,6 +162,7 @@  int32_t	ulp_port_db_dev_port_intf_update(struct bnxt_ulp_context *ulp_ctxt,
 			bnxt_get_vnic_id(port_id, BNXT_ULP_INTF_TYPE_INVALID);
 		func->phy_port_id = bnxt_get_phy_port_id(port_id);
 		func->func_valid = true;
+		func->ifindex = ifindex;
 	}
 
 	if (intf->type == BNXT_ULP_INTF_TYPE_VF_REP) {
@@ -178,6 +179,7 @@  int32_t	ulp_port_db_dev_port_intf_update(struct bnxt_ulp_context *ulp_ctxt,
 		func->func_vnic =
 			bnxt_get_vnic_id(port_id, BNXT_ULP_INTF_TYPE_VF_REP);
 		func->phy_port_id = bnxt_get_phy_port_id(port_id);
+		func->ifindex = ifindex;
 	}
 
 	port_data = &port_db->phy_port_list[func->phy_port_id];
@@ -461,3 +463,53 @@  ulp_port_db_phy_port_vport_get(struct bnxt_ulp_context *ulp_ctxt,
 	*out_port = port_db->phy_port_list[phy_port].port_vport;
 	return 0;
 }
+
+/*
+ * Api to get the port type for a given ulp ifindex.
+ *
+ * ulp_ctxt [in] Ptr to ulp context
+ * ifindex [in] ulp ifindex
+ *
+ * Returns port type.
+ */
+enum bnxt_ulp_intf_type
+ulp_port_db_port_type_get(struct bnxt_ulp_context *ulp_ctxt,
+			  uint32_t ifindex)
+{
+	struct bnxt_ulp_port_db *port_db;
+
+	port_db = bnxt_ulp_cntxt_ptr2_port_db_get(ulp_ctxt);
+	if (!port_db || ifindex >= port_db->ulp_intf_list_size || !ifindex) {
+		BNXT_TF_DBG(ERR, "Invalid Arguments\n");
+		return BNXT_ULP_INTF_TYPE_INVALID;
+	}
+	return port_db->ulp_intf_list[ifindex].type;
+}
+
+/*
+ * Api to get the ulp ifindex for a given function id.
+ *
+ * ulp_ctxt [in] Ptr to ulp context
+ * func_id [in].device func id
+ * ifindex [out] ulp ifindex
+ *
+ * Returns 0 on success or negative number on failure.
+ */
+int32_t
+ulp_port_db_dev_func_id_to_ulp_index(struct bnxt_ulp_context *ulp_ctxt,
+				     uint32_t func_id, uint32_t *ifindex)
+{
+	struct bnxt_ulp_port_db *port_db;
+
+	*ifindex = 0;
+	port_db = bnxt_ulp_cntxt_ptr2_port_db_get(ulp_ctxt);
+	if (!port_db || func_id >= BNXT_PORT_DB_MAX_FUNC) {
+		BNXT_TF_DBG(ERR, "Invalid Arguments\n");
+		return -EINVAL;
+	}
+	if (!port_db->ulp_func_id_tbl[func_id].func_valid)
+		return -ENOENT;
+
+	*ifindex = port_db->ulp_func_id_tbl[func_id].ifindex;
+	return 0;
+}
diff --git a/drivers/net/bnxt/tf_ulp/ulp_port_db.h b/drivers/net/bnxt/tf_ulp/ulp_port_db.h
index e3870f9..4afbb84 100644
--- a/drivers/net/bnxt/tf_ulp/ulp_port_db.h
+++ b/drivers/net/bnxt/tf_ulp/ulp_port_db.h
@@ -46,6 +46,7 @@  struct ulp_func_if_info {
 	uint16_t		func_parif;
 	uint16_t		func_vnic;
 	uint16_t		phy_port_id;
+	uint16_t		ifindex;
 };
 
 /* Structure for the Port database resource information. */
@@ -218,4 +219,29 @@  ulp_port_db_phy_port_vport_get(struct bnxt_ulp_context *ulp_ctxt,
 			       uint32_t phy_port,
 			       uint16_t *out_port);
 
+/*
+ * Api to get the port type for a given ulp ifindex.
+ *
+ * ulp_ctxt [in] Ptr to ulp context
+ * ifindex [in] ulp ifindex
+ *
+ * Returns port type.
+ */
+enum bnxt_ulp_intf_type
+ulp_port_db_port_type_get(struct bnxt_ulp_context *ulp_ctxt,
+			  uint32_t ifindex);
+
+/*
+ * Api to get the ulp ifindex for a given function id.
+ *
+ * ulp_ctxt [in] Ptr to ulp context
+ * func_id [in].device func id
+ * ifindex [out] ulp ifindex
+ *
+ * Returns 0 on success or negative number on failure.
+ */
+int32_t
+ulp_port_db_dev_func_id_to_ulp_index(struct bnxt_ulp_context *ulp_ctxt,
+				     uint32_t func_id, uint32_t *ifindex);
+
 #endif /* _ULP_PORT_DB_H_ */
diff --git a/drivers/net/bnxt/tf_ulp/ulp_rte_parser.c b/drivers/net/bnxt/tf_ulp/ulp_rte_parser.c
index 58090bf..3c65442 100644
--- a/drivers/net/bnxt/tf_ulp/ulp_rte_parser.c
+++ b/drivers/net/bnxt/tf_ulp/ulp_rte_parser.c
@@ -155,8 +155,8 @@  bnxt_ulp_rte_parser_act_parse(const struct rte_flow_action actions[],
 		}
 		action_item++;
 	}
-	/* update the implied VNIC */
-	ulp_rte_parser_vnic_process(params);
+	/* update the implied port details */
+	ulp_rte_parser_implied_act_port_process(params);
 	return BNXT_TF_RC_SUCCESS;
 }
 
@@ -235,30 +235,26 @@  ulp_rte_parser_svif_process(struct ulp_rte_parser_params *params)
 				       port_id, svif_mask);
 }
 
-/* Function to handle the implicit VNIC RTE port id */
+/* Function to handle the implicit action port id */
 int32_t
-ulp_rte_parser_vnic_process(struct ulp_rte_parser_params *params)
+ulp_rte_parser_implied_act_port_process(struct ulp_rte_parser_params *params)
 {
-	struct ulp_rte_act_bitmap *act = &params->act_bitmap;
+	struct rte_flow_action action_item = {0};
+	struct rte_flow_action_port_id port_id = {0};
 
-	if (ULP_BITMAP_ISSET(act->bits, BNXT_ULP_ACTION_BIT_VNIC) ||
-	    ULP_BITMAP_ISSET(act->bits, BNXT_ULP_ACTION_BIT_VPORT)) {
-		/*
-		 * Reset the vnic/vport action bitmaps
-		 * it is not required for match
-		 */
-		ULP_BITMAP_RESET(params->act_bitmap.bits,
-				 BNXT_ULP_ACTION_BIT_VNIC);
-		ULP_BITMAP_RESET(params->act_bitmap.bits,
-				 BNXT_ULP_ACTION_BIT_VPORT);
+	/* Read the action port set bit */
+	if (ULP_COMP_FLD_IDX_RD(params, BNXT_ULP_CF_IDX_ACT_PORT_IS_SET)) {
+		/* Already set, so just exit */
 		return BNXT_TF_RC_SUCCESS;
 	}
+	port_id.id = ULP_COMP_FLD_IDX_RD(params, BNXT_ULP_CF_IDX_INCOMING_IF);
+	action_item.conf = &port_id;
 
-	/* Update the vnic details */
-	ulp_rte_pf_act_handler(NULL, params);
-	/* Reset the hdr_bitmap with vnic bit */
-	ULP_BITMAP_RESET(params->act_bitmap.bits, BNXT_ULP_ACTION_BIT_VNIC);
+	/* Update the action port based on incoming port */
+	ulp_rte_port_id_act_handler(&action_item, params);
 
+	/* Reset the action port set bit */
+	ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_ACT_PORT_IS_SET, 0);
 	return BNXT_TF_RC_SUCCESS;
 }
 
@@ -1314,46 +1310,111 @@  int32_t
 ulp_rte_pf_act_handler(const struct rte_flow_action *action_item __rte_unused,
 		       struct ulp_rte_parser_params *params)
 {
-	uint32_t svif;
+	uint32_t port_id, pid;
+	uint32_t ifindex;
+	uint16_t pid_s;
+	struct ulp_rte_act_prop *act = &params->act_prop;
 
-	/* Update the hdr_bitmap with vnic bit */
-	ULP_BITMAP_SET(params->act_bitmap.bits, BNXT_ULP_ACTION_BIT_VNIC);
+	/* Get the port id of the current device */
+	port_id = ULP_COMP_FLD_IDX_RD(params, BNXT_ULP_CF_IDX_INCOMING_IF);
+
+	/* Get the port db ifindex */
+	if (ulp_port_db_dev_port_to_ulp_index(params->ulp_ctx, port_id,
+					      &ifindex)) {
+		BNXT_TF_DBG(ERR, "Invalid port id\n");
+		return BNXT_TF_RC_ERROR;
+	}
 
-	/* copy the PF of the current device into VNIC Property */
-	svif = ULP_COMP_FLD_IDX_RD(params, BNXT_ULP_CF_IDX_INCOMING_IF);
-	svif = bnxt_get_vnic_id(svif, BNXT_ULP_INTF_TYPE_INVALID);
-	svif = rte_cpu_to_be_32(svif);
-	memcpy(&params->act_prop.act_details[BNXT_ULP_ACT_PROP_IDX_VNIC],
-	       &svif, BNXT_ULP_ACT_PROP_SZ_VNIC);
+	/* Check the port is PF port */
+	if (ulp_port_db_port_type_get(params->ulp_ctx,
+				      ifindex) != BNXT_ULP_INTF_TYPE_PF) {
+		BNXT_TF_DBG(ERR, "Port is not a PF port\n");
+		return BNXT_TF_RC_ERROR;
+	}
 
+	if (params->dir == ULP_DIR_EGRESS) {
+		/* For egress direction, fill vport */
+		if (ulp_port_db_vport_get(params->ulp_ctx, ifindex, &pid_s))
+			return BNXT_TF_RC_ERROR;
+		pid = pid_s;
+		pid = rte_cpu_to_be_32(pid);
+		memcpy(&act->act_details[BNXT_ULP_ACT_PROP_IDX_VPORT],
+		       &pid, BNXT_ULP_ACT_PROP_SZ_VPORT);
+	} else {
+		/* For ingress direction, fill vnic */
+		if (ulp_port_db_default_vnic_get(params->ulp_ctx, ifindex,
+						 BNXT_ULP_DRV_FUNC_VNIC,
+						 &pid_s))
+			return BNXT_TF_RC_ERROR;
+		pid = pid_s;
+		pid = rte_cpu_to_be_32(pid);
+		memcpy(&act->act_details[BNXT_ULP_ACT_PROP_IDX_VNIC],
+		       &pid, BNXT_ULP_ACT_PROP_SZ_VNIC);
+	}
+
+	/*Update the action port set bit */
+	ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_ACT_PORT_IS_SET, 1);
 	return BNXT_TF_RC_SUCCESS;
 }
 
 /* Function to handle the parsing of RTE Flow action VF. */
 int32_t
 ulp_rte_vf_act_handler(const struct rte_flow_action *action_item,
-		       struct ulp_rte_parser_params *param)
+		       struct ulp_rte_parser_params *params)
 {
 	const struct rte_flow_action_vf *vf_action;
 	uint32_t pid;
+	uint32_t ifindex;
+	uint16_t pid_s;
+	struct ulp_rte_act_prop *act = &params->act_prop;
+	enum bnxt_ulp_intf_type intf_type;
 
 	vf_action = action_item->conf;
-	if (vf_action) {
-		if (vf_action->original) {
-			BNXT_TF_DBG(ERR,
-				    "Parse Error:VF Original not supported\n");
-			return BNXT_TF_RC_PARSE_ERR;
-		}
-		/* TBD: Update the computed VNIC using VF conversion */
-		pid = bnxt_get_vnic_id(vf_action->id,
-				       BNXT_ULP_INTF_TYPE_INVALID);
+	if (!vf_action) {
+		BNXT_TF_DBG(ERR, "ParseErr: Invalid Argument\n");
+		return BNXT_TF_RC_PARSE_ERR;
+	}
+
+	if (vf_action->original) {
+		BNXT_TF_DBG(ERR, "ParseErr:VF Original not supported\n");
+		return BNXT_TF_RC_PARSE_ERR;
+	}
+
+	/* Check the port is VF port */
+	if (ulp_port_db_dev_func_id_to_ulp_index(params->ulp_ctx, vf_action->id,
+						 &ifindex)) {
+		BNXT_TF_DBG(ERR, "VF is not valid interface\n");
+		return BNXT_TF_RC_ERROR;
+	}
+	intf_type = ulp_port_db_port_type_get(params->ulp_ctx, ifindex);
+	if (intf_type != BNXT_ULP_INTF_TYPE_VF &&
+	    intf_type != BNXT_ULP_INTF_TYPE_TRUSTED_VF) {
+		BNXT_TF_DBG(ERR, "Port is not a VF port\n");
+		return BNXT_TF_RC_ERROR;
+	}
+
+	if (params->dir == ULP_DIR_EGRESS) {
+		/* For egress direction, fill vport */
+		if (ulp_port_db_vport_get(params->ulp_ctx, ifindex, &pid_s))
+			return BNXT_TF_RC_ERROR;
+		pid = pid_s;
 		pid = rte_cpu_to_be_32(pid);
-		memcpy(&param->act_prop.act_details[BNXT_ULP_ACT_PROP_IDX_VNIC],
+		memcpy(&act->act_details[BNXT_ULP_ACT_PROP_IDX_VPORT],
+		       &pid, BNXT_ULP_ACT_PROP_SZ_VPORT);
+	} else {
+		/* For ingress direction, fill vnic */
+		if (ulp_port_db_default_vnic_get(params->ulp_ctx, ifindex,
+						 BNXT_ULP_DRV_FUNC_VNIC,
+						 &pid_s))
+			return BNXT_TF_RC_ERROR;
+		pid = pid_s;
+		pid = rte_cpu_to_be_32(pid);
+		memcpy(&act->act_details[BNXT_ULP_ACT_PROP_IDX_VNIC],
 		       &pid, BNXT_ULP_ACT_PROP_SZ_VNIC);
 	}
 
-	/* Update the hdr_bitmap with count */
-	ULP_BITMAP_SET(param->act_bitmap.bits, BNXT_ULP_ACTION_BIT_VNIC);
+	/*Update the action port set bit */
+	ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_ACT_PORT_IS_SET, 1);
 	return BNXT_TF_RC_SUCCESS;
 }
 
@@ -1415,8 +1476,8 @@  ulp_rte_port_id_act_handler(const struct rte_flow_action *act_item,
 		       &pid, BNXT_ULP_ACT_PROP_SZ_VNIC);
 	}
 
-	/*Update the hdr_bitmap with vnic */
-	ULP_BITMAP_SET(param->act_bitmap.bits, BNXT_ULP_ACTION_BIT_VNIC);
+	/*Update the action port set bit */
+	ULP_COMP_FLD_IDX_WR(param, BNXT_ULP_CF_IDX_ACT_PORT_IS_SET, 1);
 	return BNXT_TF_RC_SUCCESS;
 }
 
@@ -1460,8 +1521,8 @@  ulp_rte_phy_port_act_handler(const struct rte_flow_action *action_item,
 	memcpy(&prm->act_prop.act_details[BNXT_ULP_ACT_PROP_IDX_VPORT],
 	       &pid, BNXT_ULP_ACT_PROP_SZ_VPORT);
 
-	/* update the hdr_bitmap with vport */
-	ULP_BITMAP_SET(prm->act_bitmap.bits, BNXT_ULP_ACTION_BIT_VPORT);
+	/*Update the action port set bit */
+	ULP_COMP_FLD_IDX_WR(prm, BNXT_ULP_CF_IDX_ACT_PORT_IS_SET, 1);
 	return BNXT_TF_RC_SUCCESS;
 }
 
diff --git a/drivers/net/bnxt/tf_ulp/ulp_rte_parser.h b/drivers/net/bnxt/tf_ulp/ulp_rte_parser.h
index 1bb4721..49e9cbb 100644
--- a/drivers/net/bnxt/tf_ulp/ulp_rte_parser.h
+++ b/drivers/net/bnxt/tf_ulp/ulp_rte_parser.h
@@ -35,9 +35,9 @@ 
 int32_t
 ulp_rte_parser_svif_process(struct ulp_rte_parser_params *params);
 
-/* Function to handle the implicit VNIC RTE port id */
+/* Function to handle the implicit action port id */
 int32_t
-ulp_rte_parser_vnic_process(struct ulp_rte_parser_params *params);
+ulp_rte_parser_implied_act_port_process(struct ulp_rte_parser_params *params);
 
 /*
  * Function to handle the parsing of RTE Flows and placing
diff --git a/drivers/net/bnxt/tf_ulp/ulp_template_db_enum.h b/drivers/net/bnxt/tf_ulp/ulp_template_db_enum.h
index 13d1782..ada3a5e 100644
--- a/drivers/net/bnxt/tf_ulp/ulp_template_db_enum.h
+++ b/drivers/net/bnxt/tf_ulp/ulp_template_db_enum.h
@@ -128,7 +128,9 @@  enum bnxt_ulp_cf_idx {
 	BNXT_ULP_CF_IDX_ACT_ENCAP_IPV6_FLAG = 32,
 	BNXT_ULP_CF_IDX_ACT_DEC_TTL = 33,
 	BNXT_ULP_CF_IDX_ACT_T_DEC_TTL = 34,
-	BNXT_ULP_CF_IDX_LAST = 35
+	BNXT_ULP_CF_IDX_ACT_PORT_IS_SET = 35,
+	BNXT_ULP_CF_IDX_MATCH_PORT_TYPE = 36,
+	BNXT_ULP_CF_IDX_LAST = 37
 };
 
 enum bnxt_ulp_cond_opcode {