+/* Function to validate the rte flow. */
+static int
+bnxt_ulp_flow_validate(struct rte_eth_dev *dev,
+ 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_parser_params params;
+ uint32_t class_id, act_tmpl;
+ int ret = BNXT_TF_RC_ERROR;
+ struct bnxt_ulp_context *ulp_ctx;
+
+ if (bnxt_ulp_flow_validate_args(attr,
+ pattern, actions,
+ error) == BNXT_TF_RC_ERROR) {
+ BNXT_TF_DBG(ERR, "Invalid arguments being passed\n");
+ goto parse_error;
+ }
+
+ ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(dev);
+ if (!ulp_ctx) {
+ BNXT_TF_DBG(ERR, "ULP context is not initialized\n");
+ goto parse_error;
+ }
+
+ /* Initialize the parser params */
+ memset(¶ms, 0, sizeof(struct ulp_rte_parser_params));
+ params.ulp_ctx = ulp_ctx;
+
+ /* Set the flow attributes */
+ bnxt_ulp_set_dir_attributes(¶ms, attr);
+
+ /* Parse the rte flow pattern */
+ ret = bnxt_ulp_rte_parser_hdr_parse(pattern, ¶ms);
+ if (ret != BNXT_TF_RC_SUCCESS)
+ goto parse_error;
+
+ /* Parse the rte flow action */
+ ret = bnxt_ulp_rte_parser_act_parse(actions, ¶ms);
+ if (ret != BNXT_TF_RC_SUCCESS)
+ goto parse_error;
+
+ /* Perform the rte flow post process */
+ ret = bnxt_ulp_rte_parser_post_process(¶ms);
+ if (ret != BNXT_TF_RC_SUCCESS)
+ goto parse_error;
+
+ ret = ulp_matcher_pattern_match(¶ms, &class_id);
+
+ if (ret != BNXT_TF_RC_SUCCESS)
+ goto parse_error;
+
+ ret = ulp_matcher_action_match(¶ms, &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;
+}
+
+/* Function to destroy the rte flow. */
+int
+bnxt_ulp_flow_destroy(struct rte_eth_dev *dev,
+ struct rte_flow *flow,
+ struct rte_flow_error *error)
+{
+ int ret = 0;
+ struct bnxt_ulp_context *ulp_ctx;
+ uint32_t flow_id;
+ uint16_t func_id;
+
+ ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(dev);
+ if (!ulp_ctx) {
+ BNXT_TF_DBG(ERR, "ULP context is not initialized\n");
+ if (error)
+ rte_flow_error_set(error, EINVAL,
+ RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
+ "Failed to destroy flow.");
+ return -EINVAL;
+ }
+
+ flow_id = (uint32_t)(uintptr_t)flow;
+
+ if (ulp_port_db_port_func_id_get(ulp_ctx,
+ dev->data->port_id,
+ &func_id)) {
+ BNXT_TF_DBG(ERR, "conversion of port to func id failed\n");
+ if (error)
+ rte_flow_error_set(error, EINVAL,
+ RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
+ "Failed to destroy flow.");
+ return -EINVAL;
+ }
+
+ if (ulp_flow_db_validate_flow_func(ulp_ctx, flow_id, func_id) ==
+ false) {
+ BNXT_TF_DBG(ERR, "Incorrect device params\n");
+ if (error)
+ rte_flow_error_set(error, EINVAL,
+ RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
+ "Failed to destroy flow.");
+ return -EINVAL;
+ }
+
+ ret = ulp_mapper_flow_destroy(ulp_ctx, BNXT_ULP_FDB_TYPE_REGULAR,
+ flow_id);
+ if (ret) {
+ BNXT_TF_DBG(ERR, "Failed to destroy flow.\n");
+ if (error)
+ rte_flow_error_set(error, -ret,
+ RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
+ "Failed to destroy flow.");
+ }
+
+ return ret;
+}
+
+/* Function to destroy the rte flows. */
+static int32_t
+bnxt_ulp_flow_flush(struct rte_eth_dev *eth_dev,
+ struct rte_flow_error *error)
+{
+ struct bnxt_ulp_context *ulp_ctx;
+ int32_t ret = 0;
+ uint16_t func_id;
+
+ ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(eth_dev);
+ if (!ulp_ctx) {
+ return ret;
+ }
+
+ /* Free the resources for the last device */
+ if (ulp_ctx_deinit_allowed(ulp_ctx)) {
+ ret = ulp_flow_db_session_flow_flush(ulp_ctx);
+ } else if (bnxt_ulp_cntxt_ptr2_flow_db_get(ulp_ctx)) {
+ ret = ulp_port_db_port_func_id_get(ulp_ctx,
+ eth_dev->data->port_id,
+ &func_id);
+ if (!ret)
+ ret = ulp_flow_db_function_flow_flush(ulp_ctx, func_id);
+ else
+ BNXT_TF_DBG(ERR, "convert port to func id failed\n");
+ }
+ if (ret)
+ rte_flow_error_set(error, ret,
+ RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
+ "Failed to flush flow.");
+ return ret;
+}
+
+/* Function to query the rte flows. */
+static int32_t
+bnxt_ulp_flow_query(struct rte_eth_dev *eth_dev,
+ struct rte_flow *flow,
+ const struct rte_flow_action *action,
+ void *data,
+ struct rte_flow_error *error)
+{
+ int rc = 0;
+ struct bnxt_ulp_context *ulp_ctx;
+ struct rte_flow_query_count *count;
+ uint32_t flow_id;
+
+ ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(eth_dev);
+ if (!ulp_ctx) {
+ BNXT_TF_DBG(ERR, "ULP context is not initialized\n");
+ rte_flow_error_set(error, EINVAL,
+ RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
+ "Failed to query flow.");
+ return -EINVAL;
+ }
+
+ flow_id = (uint32_t)(uintptr_t)flow;
+
+ switch (action->type) {
+ case RTE_FLOW_ACTION_TYPE_COUNT:
+ count = data;
+ rc = ulp_fc_mgr_query_count_get(ulp_ctx, flow_id, count);
+ if (rc) {
+ rte_flow_error_set(error, EINVAL,
+ RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
+ "Failed to query flow.");
+ }
+ break;
+ default:
+ rte_flow_error_set(error, -rc, RTE_FLOW_ERROR_TYPE_ACTION_NUM,
+ NULL, "Unsupported action item");
+ }
+
+ return rc;
+}
+