[27/33] net/bnxt: add support for rte flow validate driver hook
diff mbox series

Message ID 1584459511-5353-28-git-send-email-venkatkumar.duvvuru@broadcom.com
State Superseded, archived
Delegated to: Ajit Khaparde
Headers show
Series
  • add support for host based flow table management
Related show

Checks

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

Commit Message

Venkat Duvvuru March 17, 2020, 3:38 p.m. UTC
From: Kishore Padmanabha <kishore.padmanabha@broadcom.com>

This patch does the following
1. Validates rte_flow_create arguments
2. Parses rte_flow_item types
3. Parses rte_flow_action types
4. Calls ulp_matcher_pattern_match to see if the flow is supported
5. If there is a match, returns success otherwise failure

Signed-off-by: Kishore Padmanabha <kishore.padmanabha@broadcom.com>
Signed-off-by: Venkat Duvvuru <venkatkumar.duvvuru@broadcom.com>
Reviewed-by: Lance Richardson <lance.richardson@broadcom.com>
Reviewed-by: Ajit Kumar Khaparde <ajit.khaparde@broadcom.com>
Reviewed-by: Somnath Kotur <somnath.kotur@broadcom.com>
---
 drivers/net/bnxt/tf_ulp/bnxt_ulp_flow.c | 67 ++++++++++++++++++++++++++++++++-
 1 file changed, 66 insertions(+), 1 deletion(-)

Patch
diff mbox series

diff --git a/drivers/net/bnxt/tf_ulp/bnxt_ulp_flow.c b/drivers/net/bnxt/tf_ulp/bnxt_ulp_flow.c
index 6402dd3..490b2ba 100644
--- a/drivers/net/bnxt/tf_ulp/bnxt_ulp_flow.c
+++ b/drivers/net/bnxt/tf_ulp/bnxt_ulp_flow.c
@@ -167,8 +167,73 @@  bnxt_ulp_flow_create(struct rte_eth_dev			*dev,
 	return NULL;
 }
 
+/* Function to validate the rte flow. */
+static int
+bnxt_ulp_flow_validate(struct rte_eth_dev *dev __rte_unused,
+		       const struct rte_flow_attr *attr,
+		       const struct rte_flow_item pattern[],
+		       const struct rte_flow_action actions[],
+		       struct rte_flow_error *error)
+{
+	struct ulp_rte_hdr_bitmap hdr_bitmap;
+	struct ulp_rte_hdr_field hdr_field[BNXT_ULP_PROTO_HDR_MAX];
+	struct ulp_rte_act_bitmap act_bitmap;
+	struct ulp_rte_act_prop act_prop;
+	enum ulp_direction_type dir = ULP_DIR_INGRESS;
+	uint32_t class_id, act_tmpl;
+	int ret;
+
+	if (bnxt_ulp_flow_validate_args(attr,
+					pattern, actions,
+					error) == BNXT_TF_RC_ERROR) {
+		BNXT_TF_DBG(ERR, "Invalid arguments being passed\n");
+		return -EINVAL;
+	}
+
+	/* clear the header bitmap and field structure */
+	memset(&hdr_bitmap, 0, sizeof(struct ulp_rte_hdr_bitmap));
+	memset(hdr_field, 0, sizeof(hdr_field));
+	memset(&act_bitmap, 0, sizeof(act_bitmap));
+	memset(&act_prop, 0, sizeof(act_prop));
+
+	/* Parse the rte flow pattern */
+	ret = bnxt_ulp_rte_parser_hdr_parse(pattern,
+					    &hdr_bitmap,
+					    hdr_field);
+	if (ret != BNXT_TF_RC_SUCCESS)
+		goto parse_error;
+
+	/* Parse the rte flow action */
+	ret = bnxt_ulp_rte_parser_act_parse(actions,
+					    &act_bitmap,
+					    &act_prop);
+	if (ret != BNXT_TF_RC_SUCCESS)
+		goto parse_error;
+
+	if (attr->egress)
+		dir = ULP_DIR_EGRESS;
+
+	ret = ulp_matcher_pattern_match(dir, &hdr_bitmap, hdr_field,
+					&act_bitmap, &class_id);
+
+	if (ret != BNXT_TF_RC_SUCCESS)
+		goto parse_error;
+
+	ret = ulp_matcher_action_match(dir, &act_bitmap, &act_tmpl);
+	if (ret != BNXT_TF_RC_SUCCESS)
+		goto parse_error;
+
+	/* all good return success */
+	return ret;
+
+parse_error:
+	rte_flow_error_set(error, ret, RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
+			   "Failed to validate flow.");
+	return -EINVAL;
+}
+
 const struct rte_flow_ops bnxt_ulp_rte_flow_ops = {
-	.validate = NULL,
+	.validate = bnxt_ulp_flow_validate,
 	.create = bnxt_ulp_flow_create,
 	.destroy = NULL,
 	.flush = NULL,