net/bnxt: support count action in flow query
[dpdk.git] / drivers / net / bnxt / tf_ulp / bnxt_ulp_flow.c
index 6eb2d61..36a0141 100644 (file)
@@ -9,6 +9,7 @@
 #include "ulp_matcher.h"
 #include "ulp_flow_db.h"
 #include "ulp_mapper.h"
+#include "ulp_fc_mgr.h"
 #include <rte_malloc.h>
 
 static int32_t
@@ -128,7 +129,8 @@ bnxt_ulp_flow_create(struct rte_eth_dev *dev,
        mapper_cparms.act_prop = &params.act_prop;
        mapper_cparms.class_tid = class_id;
        mapper_cparms.act_tid = act_tmpl;
-       mapper_cparms.func_id = bnxt_get_fw_func_id(dev->data->port_id);
+       mapper_cparms.func_id = bnxt_get_fw_func_id(dev->data->port_id,
+                                                   BNXT_ULP_INTF_TYPE_INVALID);
        mapper_cparms.dir = params.dir;
 
        /* Call the ulp mapper to create the flow in the hardware. */
@@ -206,7 +208,7 @@ parse_error:
 }
 
 /* Function to destroy the rte flow. */
-static int
+int
 bnxt_ulp_flow_destroy(struct rte_eth_dev *dev,
                      struct rte_flow *flow,
                      struct rte_flow_error *error)
@@ -219,29 +221,36 @@ bnxt_ulp_flow_destroy(struct rte_eth_dev *dev,
        ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(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 destroy flow.");
+               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;
-       func_id = bnxt_get_fw_func_id(dev->data->port_id);
+       func_id = bnxt_get_fw_func_id(dev->data->port_id,
+                                     BNXT_ULP_INTF_TYPE_INVALID);
 
        if (ulp_flow_db_validate_flow_func(ulp_ctx, flow_id, func_id) ==
            false) {
                BNXT_TF_DBG(ERR, "Incorrect device params\n");
-               rte_flow_error_set(error, EINVAL,
-                                  RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
-                                  "Failed to destroy flow.");
+               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, flow_id);
-       if (ret)
-               rte_flow_error_set(error, -ret,
-                                  RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
-                                  "Failed to destroy flow.");
+       ret = ulp_mapper_flow_destroy(ulp_ctx, flow_id,
+                                     BNXT_ULP_REGULAR_FLOW_TABLE);
+       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;
 }
@@ -270,7 +279,8 @@ bnxt_ulp_flow_flush(struct rte_eth_dev *eth_dev,
        if (ulp_ctx_deinit_allowed(bp)) {
                ret = ulp_flow_db_session_flow_flush(ulp_ctx);
        } else if (bnxt_ulp_cntxt_ptr2_flow_db_get(ulp_ctx)) {
-               func_id = bnxt_get_fw_func_id(eth_dev->data->port_id);
+               func_id = bnxt_get_fw_func_id(eth_dev->data->port_id,
+                                             BNXT_ULP_INTF_TYPE_INVALID);
                ret = ulp_flow_db_function_flow_flush(ulp_ctx, func_id);
        }
        if (ret)
@@ -280,11 +290,53 @@ bnxt_ulp_flow_flush(struct rte_eth_dev *eth_dev,
        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;
+}
+
 const struct rte_flow_ops bnxt_ulp_rte_flow_ops = {
        .validate = bnxt_ulp_flow_validate,
        .create = bnxt_ulp_flow_create,
        .destroy = bnxt_ulp_flow_destroy,
        .flush = bnxt_ulp_flow_flush,
-       .query = NULL,
+       .query = bnxt_ulp_flow_query,
        .isolate = NULL
 };