net/mlx5: check register available for metadata action
[dpdk.git] / drivers / net / mlx5 / mlx5_flow_dv.c
index ee3a172..f546b89 100644 (file)
@@ -1217,6 +1217,7 @@ flow_dv_convert_action_set_meta
 
        if (reg < 0)
                return reg;
+       MLX5_ASSERT(reg != REG_NON);
        /*
         * In datapath code there is no endianness
         * coversions for perfromance reasons, all
@@ -1438,6 +1439,10 @@ flow_dv_validate_item_meta(struct rte_eth_dev *dev __rte_unused,
                reg = flow_dv_get_metadata_reg(dev, attr, error);
                if (reg < 0)
                        return reg;
+               if (reg == REG_NON)
+                       return rte_flow_error_set(error, ENOTSUP,
+                                       RTE_FLOW_ERROR_TYPE_ITEM, item,
+                                       "unavalable extended metadata register");
                if (reg == REG_B)
                        return rte_flow_error_set(error, ENOTSUP,
                                          RTE_FLOW_ERROR_TYPE_ITEM, item,
@@ -2446,6 +2451,10 @@ flow_dv_validate_action_set_meta(struct rte_eth_dev *dev,
        reg = flow_dv_get_metadata_reg(dev, attr, error);
        if (reg < 0)
                return reg;
+       if (reg == REG_NON)
+               return rte_flow_error_set(error, ENOTSUP,
+                                         RTE_FLOW_ERROR_TYPE_ACTION, action,
+                                         "unavalable extended metadata register");
        if (reg != REG_A && reg != REG_B) {
                struct mlx5_priv *priv = dev->data->dev_private;
 
@@ -7471,6 +7480,7 @@ flow_dv_translate_item_meta(struct rte_eth_dev *dev,
                reg = flow_dv_get_metadata_reg(dev, attr, NULL);
                if (reg < 0)
                        return;
+               MLX5_ASSERT(reg != REG_NON);
                /*
                 * In datapath code there is no endianness
                 * coversions for perfromance reasons, all
@@ -7875,7 +7885,7 @@ flow_dv_translate_item_ecpri(struct rte_eth_dev *dev, void *matcher,
                            prog_sample_field_value_0);
        /* Already big endian (network order) in the header. */
        *(uint32_t *)dw_m = ecpri_m->hdr.common.u32;
-       *(uint32_t *)dw_v = ecpri_v->hdr.common.u32;
+       *(uint32_t *)dw_v = ecpri_v->hdr.common.u32 & ecpri_m->hdr.common.u32;
        /* Sample#0, used for matching type, offset 0. */
        MLX5_SET(fte_match_set_misc4, misc4_m,
                 prog_sample_field_id_0, samples[0]);
@@ -7897,7 +7907,8 @@ flow_dv_translate_item_ecpri(struct rte_eth_dev *dev, void *matcher,
                        dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
                                            prog_sample_field_value_1);
                        *(uint32_t *)dw_m = ecpri_m->hdr.dummy[0];
-                       *(uint32_t *)dw_v = ecpri_v->hdr.dummy[0];
+                       *(uint32_t *)dw_v = ecpri_v->hdr.dummy[0] &
+                                           ecpri_m->hdr.dummy[0];
                        /* Sample#1, to match message body, offset 4. */
                        MLX5_SET(fte_match_set_misc4, misc4_m,
                                 prog_sample_field_id_1, samples[1]);
@@ -9468,12 +9479,14 @@ flow_dv_age_pool_create(struct rte_eth_dev *dev,
  *
  * @param[in] dev
  *   Pointer to the Ethernet device structure.
+ * @param[out] error
+ *   Pointer to the error structure.
  *
  * @return
  *   Index to ASO age action on success, 0 otherwise and rte_errno is set.
  */
 static uint32_t
-flow_dv_aso_age_alloc(struct rte_eth_dev *dev)
+flow_dv_aso_age_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
 {
        struct mlx5_priv *priv = dev->data->dev_private;
        const struct mlx5_aso_age_pool *pool;
@@ -9488,7 +9501,9 @@ flow_dv_aso_age_alloc(struct rte_eth_dev *dev)
                LIST_REMOVE(age_free, next);
        } else if (!flow_dv_age_pool_create(dev, &age_free)) {
                rte_spinlock_unlock(&mng->free_sl);
-               return 0; /* 0 is an error.*/
+               rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
+                                  NULL, "failed to create ASO age pool");
+               return 0; /* 0 is an error. */
        }
        rte_spinlock_unlock(&mng->free_sl);
        pool = container_of
@@ -9496,15 +9511,33 @@ flow_dv_aso_age_alloc(struct rte_eth_dev *dev)
                  (age_free - age_free->offset), const struct mlx5_aso_age_pool,
                                                                       actions);
        if (!age_free->dr_action) {
-               age_free->dr_action = mlx5_glue->dr_action_create_flow_hit
-                                               (pool->flow_hit_aso_obj->obj,
-                                                age_free->offset, REG_C_5);
+               int reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_FLOW_HIT, 0,
+                                                error);
+
+               if (reg_c < 0) {
+                       rte_flow_error_set(error, rte_errno,
+                                          RTE_FLOW_ERROR_TYPE_ACTION,
+                                          NULL, "failed to get reg_c "
+                                          "for ASO flow hit");
+                       return 0; /* 0 is an error. */
+               }
+#ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
+               age_free->dr_action = mlx5_glue->dv_create_flow_action_aso
+                               (priv->sh->rx_domain,
+                                pool->flow_hit_aso_obj->obj, age_free->offset,
+                                MLX5DV_DR_ACTION_FLAGS_ASO_FIRST_HIT_SET,
+                                (reg_c - REG_C_0));
+#endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
                if (!age_free->dr_action) {
                        rte_errno = errno;
                        rte_spinlock_lock(&mng->free_sl);
                        LIST_INSERT_HEAD(&mng->free, age_free, next);
                        rte_spinlock_unlock(&mng->free_sl);
-                       return 0; /* 0 is an error.*/
+                       rte_flow_error_set(error, rte_errno,
+                                          RTE_FLOW_ERROR_TYPE_ACTION,
+                                          NULL, "failed to create ASO "
+                                          "flow hit action");
+                       return 0; /* 0 is an error. */
                }
        }
        __atomic_store_n(&age_free->refcnt, 1, __ATOMIC_RELAXED);
@@ -9518,18 +9551,21 @@ flow_dv_aso_age_alloc(struct rte_eth_dev *dev)
  *   Pointer to rte_eth_dev structure.
  * @param[in] age
  *   Pointer to the aging action configuration.
+ * @param[out] error
+ *   Pointer to the error structure.
  *
  * @return
  *   Index to flow counter on success, 0 otherwise.
  */
 static uint32_t
 flow_dv_translate_create_aso_age(struct rte_eth_dev *dev,
-                                const struct rte_flow_action_age *age)
+                                const struct rte_flow_action_age *age,
+                                struct rte_flow_error *error)
 {
        uint32_t age_idx = 0;
        struct mlx5_aso_age_action *aso_age;
 
-       age_idx = flow_dv_aso_age_alloc(dev);
+       age_idx = flow_dv_aso_age_alloc(dev, error);
        if (!age_idx)
                return 0;
        aso_age = flow_aso_age_get_by_idx(dev, age_idx);
@@ -9841,7 +9877,7 @@ flow_dv_translate(struct rte_eth_dev *dev,
                case RTE_FLOW_ACTION_TYPE_AGE:
                        if (priv->sh->flow_hit_aso_en && attr->group) {
                                flow->age = flow_dv_translate_create_aso_age
-                                               (dev, action->conf);
+                                               (dev, action->conf, error);
                                if (!flow->age)
                                        return rte_flow_error_set
                                                (error, rte_errno,
@@ -11475,14 +11511,14 @@ __flow_dv_action_rss_release(struct rte_eth_dev *dev, uint32_t idx,
                                          "invalid shared action");
        remaining = __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
        if (remaining)
-               return rte_flow_error_set(error, ETOOMANYREFS,
+               return rte_flow_error_set(error, EBUSY,
                                          RTE_FLOW_ERROR_TYPE_ACTION,
                                          NULL,
                                          "shared rss hrxq has references");
        if (!__atomic_compare_exchange_n(&shared_rss->refcnt, &old_refcnt,
                                         0, 0, __ATOMIC_ACQUIRE,
                                         __ATOMIC_RELAXED))
-               return rte_flow_error_set(error, ETOOMANYREFS,
+               return rte_flow_error_set(error, EBUSY,
                                          RTE_FLOW_ERROR_TYPE_ACTION,
                                          NULL,
                                          "shared rss has references");
@@ -11531,7 +11567,7 @@ flow_dv_action_create(struct rte_eth_dev *dev,
                       MLX5_SHARED_ACTION_TYPE_OFFSET) | ret;
                break;
        case RTE_FLOW_ACTION_TYPE_AGE:
-               ret = flow_dv_translate_create_aso_age(dev, action->conf);
+               ret = flow_dv_translate_create_aso_age(dev, action->conf, err);
                idx = (MLX5_SHARED_ACTION_TYPE_AGE <<
                       MLX5_SHARED_ACTION_TYPE_OFFSET) | ret;
                if (ret) {