From: Haifei Luo Date: Mon, 21 Feb 2022 08:27:21 +0000 (+0200) Subject: net/mlx5: refactor getting counter action pointer X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=9b57df5575de8f8e3615f6e5efce4ef664f288d2;p=dpdk.git net/mlx5: refactor getting counter action pointer 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 Acked-by: Viacheslav Ovsiienko --- diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index 35ea3fb47c..e7eaacc76f 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -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, diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index 1c3f648491..a87ac8e6d7 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -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; diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h index 583e8b7321..a20773eeb2 100644 --- a/drivers/net/mlx5/mlx5_flow.h +++ b/drivers/net/mlx5/mlx5_flow.h @@ -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); diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c index ce69b6ff3a..689b191748 100644 --- a/drivers/net/mlx5/mlx5_flow_dv.c +++ b/drivers/net/mlx5/mlx5_flow_dv.c @@ -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) { diff --git a/drivers/net/mlx5/mlx5_flow_meter.c b/drivers/net/mlx5/mlx5_flow_meter.c index 3b3f3cb7fd..06ab7c4a88 100644 --- a/drivers/net/mlx5/mlx5_flow_meter.c +++ b/drivers/net/mlx5/mlx5_flow_meter.c @@ -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. */