net/mlx5: improve Verbs flow priority discovery
[dpdk.git] / drivers / net / mlx5 / mlx5_flow_dv.c
index 23ee6a2..f2fde91 100644 (file)
@@ -3290,7 +3290,7 @@ flow_dv_validate_action_count(struct rte_eth_dev *dev, bool shared,
 {
        struct mlx5_priv *priv = dev->data->dev_private;
 
-       if (!priv->config.devx)
+       if (!priv->sh->devx)
                goto notsup_err;
        if (action_flags & MLX5_FLOW_ACTION_COUNT)
                return rte_flow_error_set(error, EINVAL,
@@ -3618,8 +3618,8 @@ flow_dv_encap_decap_create_cb(void *tool_ctx, void *cb_ctx)
        }
        *resource = *ctx_resource;
        resource->idx = idx;
-       ret = mlx5_flow_os_create_flow_action_packet_reformat(sh->ctx, domain,
-                                                             resource,
+       ret = mlx5_flow_os_create_flow_action_packet_reformat(sh->cdev->ctx,
+                                                             domain, resource,
                                                             &resource->action);
        if (ret) {
                mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], idx);
@@ -5252,7 +5252,7 @@ flow_dv_validate_action_age(uint64_t action_flags,
        struct mlx5_priv *priv = dev->data->dev_private;
        const struct rte_flow_action_age *age = action->conf;
 
-       if (!priv->config.devx || (priv->sh->cmng.counter_fallback &&
+       if (!priv->sh->devx || (priv->sh->cmng.counter_fallback &&
            !priv->sh->aso_age_mng))
                return rte_flow_error_set(error, ENOTSUP,
                                          RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
@@ -5434,7 +5434,7 @@ flow_dv_modify_create_cb(void *tool_ctx, void *cb_ctx)
        else
                ns = sh->rx_domain;
        ret = mlx5_flow_os_create_flow_action_modify_header
-                                       (sh->ctx, ns, entry,
+                                       (sh->cdev->ctx, ns, entry,
                                         data_len, &entry->action);
        if (ret) {
                mlx5_ipool_free(sh->mdh_ipools[ref->actions_num - 1], idx);
@@ -5537,7 +5537,7 @@ flow_dv_validate_action_sample(uint64_t *action_flags,
                return rte_flow_error_set(error, EINVAL,
                                          RTE_FLOW_ERROR_TYPE_ACTION, action,
                                          "ratio value starts from 1");
-       if (!priv->config.devx || (sample->ratio > 0 && !priv->sampler_en))
+       if (!priv->sh->devx || (sample->ratio > 0 && !priv->sampler_en))
                return rte_flow_error_set(error, ENOTSUP,
                                          RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
                                          NULL,
@@ -6056,7 +6056,7 @@ flow_dv_counter_pool_prepare(struct rte_eth_dev *dev,
 
        if (fallback) {
                /* bulk_bitmap must be 0 for single counter allocation. */
-               dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0);
+               dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0);
                if (!dcs)
                        return NULL;
                pool = flow_dv_find_pool_by_id(cmng, dcs->id);
@@ -6074,7 +6074,7 @@ flow_dv_counter_pool_prepare(struct rte_eth_dev *dev,
                *cnt_free = cnt;
                return pool;
        }
-       dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0x4);
+       dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0x4);
        if (!dcs) {
                rte_errno = ENODATA;
                return NULL;
@@ -6121,7 +6121,7 @@ flow_dv_counter_alloc(struct rte_eth_dev *dev, uint32_t age)
                        age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
        uint32_t cnt_idx;
 
-       if (!priv->config.devx) {
+       if (!priv->sh->devx) {
                rte_errno = ENOTSUP;
                return 0;
        }
@@ -6357,20 +6357,19 @@ flow_dv_mtr_container_resize(struct rte_eth_dev *dev)
  *   NULL otherwise and rte_errno is set.
  */
 static struct mlx5_aso_mtr_pool *
-flow_dv_mtr_pool_create(struct rte_eth_dev *dev,
-                            struct mlx5_aso_mtr **mtr_free)
+flow_dv_mtr_pool_create(struct rte_eth_dev *dev, struct mlx5_aso_mtr **mtr_free)
 {
        struct mlx5_priv *priv = dev->data->dev_private;
-       struct mlx5_aso_mtr_pools_mng *pools_mng =
-                               &priv->sh->mtrmng->pools_mng;
+       struct mlx5_aso_mtr_pools_mng *pools_mng = &priv->sh->mtrmng->pools_mng;
        struct mlx5_aso_mtr_pool *pool = NULL;
        struct mlx5_devx_obj *dcs = NULL;
        uint32_t i;
        uint32_t log_obj_size;
 
        log_obj_size = rte_log2_u32(MLX5_ASO_MTRS_PER_POOL >> 1);
-       dcs = mlx5_devx_cmd_create_flow_meter_aso_obj(priv->sh->ctx,
-                       priv->sh->pdn, log_obj_size);
+       dcs = mlx5_devx_cmd_create_flow_meter_aso_obj(priv->sh->cdev->ctx,
+                                                     priv->sh->cdev->pdn,
+                                                     log_obj_size);
        if (!dcs) {
                rte_errno = ENODATA;
                return NULL;
@@ -6392,8 +6391,7 @@ flow_dv_mtr_pool_create(struct rte_eth_dev *dev,
        pools_mng->n_valid++;
        for (i = 1; i < MLX5_ASO_MTRS_PER_POOL; ++i) {
                pool->mtrs[i].offset = i;
-               LIST_INSERT_HEAD(&pools_mng->meters,
-                                               &pool->mtrs[i], next);
+               LIST_INSERT_HEAD(&pools_mng->meters, &pool->mtrs[i], next);
        }
        pool->mtrs[0].offset = 0;
        *mtr_free = &pool->mtrs[0];
@@ -6443,7 +6441,7 @@ flow_dv_mtr_alloc(struct rte_eth_dev *dev)
        struct mlx5_aso_mtr_pool *pool;
        uint32_t mtr_idx = 0;
 
-       if (!priv->config.devx) {
+       if (!priv->sh->devx) {
                rte_errno = ENOTSUP;
                return 0;
        }
@@ -9067,7 +9065,7 @@ flow_dev_geneve_tlv_option_resource_register(struct rte_eth_dev *dev,
                }
        } else {
                /* Create a GENEVE TLV object and resource. */
-               obj = mlx5_devx_cmd_create_geneve_tlv_option(sh->ctx,
+               obj = mlx5_devx_cmd_create_geneve_tlv_option(sh->cdev->ctx,
                                geneve_opt_v->option_class,
                                geneve_opt_v->option_type,
                                geneve_opt_v->option_len);
@@ -10427,7 +10425,8 @@ flow_dv_matcher_create_cb(void *tool_ctx, void *cb_ctx)
        dv_attr.priority = ref->priority;
        if (tbl->is_egress)
                dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
-       ret = mlx5_flow_os_create_flow_matcher(sh->ctx, &dv_attr, tbl->tbl.obj,
+       ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
+                                              tbl->tbl.obj,
                                               &resource->matcher_object);
        if (ret) {
                mlx5_free(resource);
@@ -11864,8 +11863,8 @@ flow_dv_age_pool_create(struct rte_eth_dev *dev,
        struct mlx5_devx_obj *obj = NULL;
        uint32_t i;
 
-       obj = mlx5_devx_cmd_create_flow_hit_aso_obj(priv->sh->ctx,
-                                                   priv->sh->pdn);
+       obj = mlx5_devx_cmd_create_flow_hit_aso_obj(priv->sh->cdev->ctx,
+                                                   priv->sh->cdev->pdn);
        if (!obj) {
                rte_errno = ENODATA;
                DRV_LOG(ERR, "Failed to create flow_hit_aso_obj using DevX.");
@@ -12292,8 +12291,9 @@ flow_dv_ct_pool_create(struct rte_eth_dev *dev,
        uint32_t i;
        uint32_t log_obj_size = rte_log2_u32(MLX5_ASO_CT_ACTIONS_PER_POOL);
 
-       obj = mlx5_devx_cmd_create_conn_track_offload_obj(priv->sh->ctx,
-                                               priv->sh->pdn, log_obj_size);
+       obj = mlx5_devx_cmd_create_conn_track_offload_obj(priv->sh->cdev->ctx,
+                                                         priv->sh->cdev->pdn,
+                                                         log_obj_size);
        if (!obj) {
                rte_errno = ENODATA;
                DRV_LOG(ERR, "Failed to create conn_track_offload_obj using DevX.");
@@ -12348,7 +12348,7 @@ flow_dv_aso_ct_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
        uint32_t ct_idx;
 
        MLX5_ASSERT(mng);
-       if (!priv->config.devx) {
+       if (!priv->sh->devx) {
                rte_errno = ENOTSUP;
                return 0;
        }
@@ -12785,7 +12785,7 @@ flow_dv_translate(struct rte_eth_dev *dev,
                        }
                        break;
                case RTE_FLOW_ACTION_TYPE_COUNT:
-                       if (!dev_conf->devx) {
+                       if (!priv->sh->devx) {
                                return rte_flow_error_set
                                              (error, ENOTSUP,
                                               RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
@@ -15629,7 +15629,7 @@ flow_dv_query_count(struct rte_eth_dev *dev, uint32_t cnt_idx, void *data,
        struct mlx5_priv *priv = dev->data->dev_private;
        struct rte_flow_query_count *qc = data;
 
-       if (!priv->config.devx)
+       if (!priv->sh->devx)
                return rte_flow_error_set(error, ENOTSUP,
                                          RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
                                          NULL,
@@ -17099,8 +17099,8 @@ mlx5_flow_discover_dr_action_support(struct rte_eth_dev *dev)
                goto err;
        dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
        __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
-       ret = mlx5_flow_os_create_flow_matcher(sh->ctx, &dv_attr, tbl->obj,
-                                              &matcher);
+       ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
+                                              tbl->obj, &matcher);
        if (ret)
                goto err;
        __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
@@ -17168,7 +17168,7 @@ mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev)
                                        0, 0, 0, NULL);
        if (!tbl)
                goto err;
-       dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0x4);
+       dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0x4);
        if (!dcs)
                goto err;
        ret = mlx5_flow_os_create_flow_action_count(dcs->obj, UINT16_MAX,
@@ -17177,8 +17177,8 @@ mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev)
                goto err;
        dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
        __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
-       ret = mlx5_flow_os_create_flow_matcher(sh->ctx, &dv_attr, tbl->obj,
-                                              &matcher);
+       ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
+                                              tbl->obj, &matcher);
        if (ret)
                goto err;
        __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
@@ -17242,7 +17242,7 @@ flow_dv_counter_query(struct rte_eth_dev *dev, uint32_t counter, bool clear,
        uint64_t inn_pkts, inn_bytes;
        int ret;
 
-       if (!priv->config.devx)
+       if (!priv->sh->devx)
                return -1;
 
        ret = _flow_dv_query_count(dev, counter, &inn_pkts, &inn_bytes);
@@ -17756,18 +17756,23 @@ flow_dv_validate_mtr_policy_acts(struct rte_eth_dev *dev,
                                        "Doesn't support optional action");
                        }
                }
-               if (action_flags[i] & MLX5_FLOW_ACTION_PORT_ID)
+               if (action_flags[i] & MLX5_FLOW_ACTION_PORT_ID) {
                        domain_color[i] = MLX5_MTR_DOMAIN_TRANSFER_BIT;
-               else if ((action_flags[i] &
+               else if ((action_flags[i] &
                          (MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_QUEUE)) ||
-                        (action_flags[i] & MLX5_FLOW_ACTION_MARK))
+                         (action_flags[i] & MLX5_FLOW_ACTION_MARK)) {
                        /*
                         * Only support MLX5_XMETA_MODE_LEGACY
                         * so MARK action is only in ingress domain.
                         */
                        domain_color[i] = MLX5_MTR_DOMAIN_INGRESS_BIT;
-               else
+               } else {
                        domain_color[i] = def_domain;
+                       if (action_flags[i] &&
+                           !(action_flags[i] & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
+                               domain_color[i] &=
+                               ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
+               }
                if (action_flags[i] &
                    MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
                        domain_color[i] &= hierarchy_domain;