]> git.droids-corp.org - dpdk.git/commitdiff
net/mlx5: refactor getting counter action pointer
authorHaifei Luo <haifeil@nvidia.com>
Mon, 21 Feb 2022 08:27:21 +0000 (10:27 +0200)
committerRaslan Darawsheh <rasland@nvidia.com>
Wed, 23 Feb 2022 14:57:34 +0000 (15:57 +0100)
Previously API flow_dv_query_count_ptr is defined to get counter's
action pointer. This DV function is directly called and the better
way is by the callback.

Add one arg in API mlx5_counter_query and the related callback
counter_query. The added arg is for counter's action pointer.

Signed-off-by: Haifei Luo <haifeil@nvidia.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@nvidia.com>
drivers/net/mlx5/mlx5.h
drivers/net/mlx5/mlx5_flow.c
drivers/net/mlx5/mlx5_flow.h
drivers/net/mlx5/mlx5_flow_dv.c
drivers/net/mlx5/mlx5_flow_meter.c

index 35ea3fb47c207c0f867200269ce2e06d0fc8673b..e7eaacc76f6d42e5b57880d91f1fa65c5456f2b3 100644 (file)
@@ -1752,7 +1752,7 @@ void mlx5_flow_query_alarm(void *arg);
 uint32_t mlx5_counter_alloc(struct rte_eth_dev *dev);
 void mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt);
 int mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
-                      bool clear, uint64_t *pkts, uint64_t *bytes);
+                   bool clear, uint64_t *pkts, uint64_t *bytes, void **action);
 int mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow,
                        FILE *file, struct rte_flow_error *error);
 int save_dump_file(const unsigned char *data, uint32_t size,
index 1c3f64849188a991cc4d84a8f8db4e2424fc74f5..a87ac8e6d7d58114ae2e5de3bbe3ba832bf93aa7 100644 (file)
@@ -7799,14 +7799,15 @@ mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
  */
 int
 mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
-                  bool clear, uint64_t *pkts, uint64_t *bytes)
+                  bool clear, uint64_t *pkts, uint64_t *bytes, void **action)
 {
        const struct mlx5_flow_driver_ops *fops;
        struct rte_flow_attr attr = { .transfer = 0 };
 
        if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
                fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
-               return fops->counter_query(dev, cnt, clear, pkts, bytes);
+               return fops->counter_query(dev, cnt, clear, pkts,
+                                       bytes, action);
        }
        DRV_LOG(ERR,
                "port %u counter query is not supported.",
@@ -8378,6 +8379,16 @@ mlx5_flow_dev_dump_ipool(struct rte_eth_dev *dev,
                                "invalid flow handle");
        }
        handle_idx = flow->dev_handles;
+       /* query counter */
+       if (flow->counter &&
+       (!mlx5_counter_query(dev, flow->counter, false,
+       &count.hits, &count.bytes, &action)) && action) {
+               id = (uint64_t)(uintptr_t)action;
+               type = DR_DUMP_REC_TYPE_PMD_COUNTER;
+               save_dump_file(NULL, 0, type,
+                       id, (void *)&count, file);
+       }
+
        while (handle_idx) {
                dh = mlx5_ipool_get(priv->sh->ipool
                                [MLX5_IPOOL_MLX5_FLOW], handle_idx);
@@ -8385,16 +8396,6 @@ mlx5_flow_dev_dump_ipool(struct rte_eth_dev *dev,
                        continue;
                handle_idx = dh->next.next;
 
-               /* query counter */
-               type = DR_DUMP_REC_TYPE_PMD_COUNTER;
-               flow_dv_query_count_ptr(dev, flow->counter,
-                                               &action, error);
-               if (action) {
-                       id = (uint64_t)(uintptr_t)action;
-                       if (!mlx5_flow_query_counter(dev, flow, &count, error))
-                               save_dump_file(NULL, 0, type,
-                                               id, (void *)&count, file);
-               }
                /* Get modify_hdr and encap_decap buf from ipools. */
                encap_decap = NULL;
                modify_hdr = dh->dvh.modify_hdr;
@@ -8440,7 +8441,7 @@ mlx5_flow_dev_dump_ipool(struct rte_eth_dev *dev,
  */
 static int
 mlx5_flow_dev_dump_sh_all(struct rte_eth_dev *dev,
-       FILE *file, struct rte_flow_error *error)
+       FILE *file, struct rte_flow_error *error __rte_unused)
 {
        struct mlx5_priv *priv = dev->data->dev_private;
        struct mlx5_dev_ctx_shared *sh = priv->sh;
@@ -8525,14 +8526,12 @@ mlx5_flow_dev_dump_sh_all(struct rte_eth_dev *dev,
        max = MLX5_COUNTERS_PER_POOL * cmng->n_valid;
        for (j = 1; j <= max; j++) {
                action = NULL;
-               flow_dv_query_count_ptr(dev, j, &action, error);
-               if (action) {
-                       if (!flow_dv_query_count(dev, j, &count, error)) {
-                               type = DR_DUMP_REC_TYPE_PMD_COUNTER;
-                               id = (uint64_t)(uintptr_t)action;
-                               save_dump_file(NULL, 0, type,
-                                               id, (void *)&count, file);
-                       }
+               if ((!mlx5_counter_query(dev, j, false, &count.hits,
+               &count.bytes, &action)) && action) {
+                       id = (uint64_t)(uintptr_t)action;
+                       type = DR_DUMP_REC_TYPE_PMD_COUNTER;
+                       save_dump_file(NULL, 0, type,
+                                       id, (void *)&count, file);
                }
        }
        return 0;
index 583e8b73214095b3a5593041db250bdb521b8ee6..a20773eeb2553954b134bd7e2c836201a1e4129a 100644 (file)
@@ -1180,7 +1180,7 @@ typedef void (*mlx5_flow_counter_free_t)(struct rte_eth_dev *dev,
 typedef int (*mlx5_flow_counter_query_t)(struct rte_eth_dev *dev,
                                         uint32_t cnt,
                                         bool clear, uint64_t *pkts,
-                                        uint64_t *bytes);
+                                        uint64_t *bytes, void **action);
 typedef int (*mlx5_flow_get_aged_flows_t)
                                        (struct rte_eth_dev *dev,
                                         void **context,
@@ -1723,11 +1723,6 @@ struct mlx5_list_entry *flow_dv_dest_array_clone_cb(void *tool_ctx,
                                   struct mlx5_list_entry *entry, void *cb_ctx);
 void flow_dv_dest_array_clone_free_cb(void *tool_ctx,
                                      struct mlx5_list_entry *entry);
-int flow_dv_query_count_ptr(struct rte_eth_dev *dev, uint32_t cnt_idx,
-                               void **action, struct rte_flow_error *error);
-int
-flow_dv_query_count(struct rte_eth_dev *dev, uint32_t cnt_idx, void *data,
-                   struct rte_flow_error *error);
 
 struct mlx5_aso_age_action *flow_aso_age_get_by_idx(struct rte_eth_dev *dev,
                                                    uint32_t age_idx);
index ce69b6ff3a48395c428241f82d0dcdeb8041072a..689b1917481696e27ed7d0ef4fe0f3de0bd458ca 100644 (file)
@@ -15830,7 +15830,7 @@ flow_dv_create_mtr_policy_acts(struct rte_eth_dev *dev,
  * @return
  *   0 on success, a negative errno value otherwise and rte_errno is set.
  */
-int
+static int
 flow_dv_query_count(struct rte_eth_dev *dev, uint32_t cnt_idx, void *data,
                    struct rte_flow_error *error)
 {
@@ -15868,48 +15868,6 @@ flow_dv_query_count(struct rte_eth_dev *dev, uint32_t cnt_idx, void *data,
                                  "counters are not available");
 }
 
-
-/**
- * Query counter's action pointer for a DV flow rule via DevX.
- *
- * @param[in] dev
- *   Pointer to Ethernet device.
- * @param[in] cnt_idx
- *   Index to the flow counter.
- * @param[out] action_ptr
- *   Action pointer for counter.
- * @param[out] error
- *   Perform verbose error reporting if not NULL.
- *
- * @return
- *   0 on success, a negative errno value otherwise and rte_errno is set.
- */
-int
-flow_dv_query_count_ptr(struct rte_eth_dev *dev, uint32_t cnt_idx,
-       void **action_ptr, struct rte_flow_error *error)
-{
-       struct mlx5_priv *priv = dev->data->dev_private;
-
-       if (!priv->sh->cdev->config.devx || !action_ptr)
-               return rte_flow_error_set(error, ENOTSUP,
-                                         RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
-                                         NULL,
-                                         "counters are not supported");
-
-       if (cnt_idx) {
-               struct mlx5_flow_counter *cnt = NULL;
-               cnt = flow_dv_counter_get_by_idx(dev, cnt_idx, NULL);
-               if (cnt) {
-                       *action_ptr = cnt->action;
-                       return 0;
-               }
-       }
-       return rte_flow_error_set(error, EINVAL,
-                                 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
-                                 NULL,
-                                 "counters are not available");
-}
-
 static int
 flow_dv_action_query(struct rte_eth_dev *dev,
                     const struct rte_flow_action_handle *handle, void *data,
@@ -17488,7 +17446,7 @@ err:
  */
 static int
 flow_dv_counter_query(struct rte_eth_dev *dev, uint32_t counter, bool clear,
-                     uint64_t *pkts, uint64_t *bytes)
+                     uint64_t *pkts, uint64_t *bytes, void **action)
 {
        struct mlx5_priv *priv = dev->data->dev_private;
        struct mlx5_flow_counter *cnt;
@@ -17502,6 +17460,9 @@ flow_dv_counter_query(struct rte_eth_dev *dev, uint32_t counter, bool clear,
        if (ret)
                return -1;
        cnt = flow_dv_counter_get_by_idx(dev, counter, NULL);
+       if (cnt && action)
+               *action = cnt->action;
+
        *pkts = inn_pkts - cnt->hits;
        *bytes = inn_bytes - cnt->bytes;
        if (clear) {
index 3b3f3cb7fd0931cf756eb6bdbcde56317e0c118f..06ab7c4a882bfcac7aca9b50921014ef4bbc452e 100644 (file)
@@ -1726,7 +1726,7 @@ mlx5_flow_meter_stats_read(struct rte_eth_dev *dev,
        memset(stats, 0, sizeof(*stats));
        if (fm->drop_cnt) {
                ret = mlx5_counter_query(dev, fm->drop_cnt, clear, &pkts,
-                                                &bytes);
+                                                &bytes, NULL);
                if (ret)
                        goto error;
                /* If need to read the packets, set it. */