Hi Jiawei,

PSB.

Best,
Ori

> -----Original Message-----
> From: Jiawei Wang <jiaw...@mellanox.com>
> Sent: Thursday, June 25, 2020 7:26 PM
> Subject: [PATCH 4/8] net/mlx5: add the validate sample action
> 
> Add sample action validate function.
> 
> For Sample flow support NIC-RX and FDB domain, must include an
> action of a dest TIR in NIC_RX or DEFAULT_MISS in FDB.

What is the DEFAULT_MISS action?
I think from reading the code that you mean that no action is allowed and it is 
always goes to e-switch manager / go to PF, am I correct?

> 
> Only NIC_RX support with addition optinal actions.
> 
> Signed-off-by: Jiawei Wang <jiaw...@mellanox.com>
> ---
>  drivers/net/mlx5/linux/mlx5_os.c |  14 +++++
>  drivers/net/mlx5/mlx5.h          |   1 +
>  drivers/net/mlx5/mlx5_flow.h     |   1 +
>  drivers/net/mlx5/mlx5_flow_dv.c  | 130
> +++++++++++++++++++++++++++++++++++++++
>  4 files changed, 146 insertions(+)
> 
> diff --git a/drivers/net/mlx5/linux/mlx5_os.c
> b/drivers/net/mlx5/linux/mlx5_os.c
> index f0147e6..5c057d3 100644
> --- a/drivers/net/mlx5/linux/mlx5_os.c
> +++ b/drivers/net/mlx5/linux/mlx5_os.c
> @@ -878,6 +878,20 @@
>                       }
>               }
>  #endif
> +#if defined(HAVE_MLX5DV_DR) &&
> defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE)
> +             if (config.hca_attr.log_max_ft_sampler_num > 0  &&
> +                 config.dv_flow_en) {
> +                     priv->sampler_en = 1;
> +                     DRV_LOG(DEBUG, "The Sampler enabled!\n");
> +             } else {
> +                     priv->sampler_en = 0;
> +                     if (!config.hca_attr.log_max_ft_sampler_num)
> +                             DRV_LOG(WARNING, "No available register
> for"
> +                                             " Sampler.");
> +                     else
> +                             DRV_LOG(DEBUG, "DV flow is not
> supported!\n");
> +             }
> +#endif
>       }
>       if (config.mprq.enabled && mprq) {
>               if (config.mprq.stride_num_n &&
> diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
> index 8a09ebc..c2a875c 100644
> --- a/drivers/net/mlx5/mlx5.h
> +++ b/drivers/net/mlx5/mlx5.h
> @@ -607,6 +607,7 @@ struct mlx5_priv {
>       unsigned int counter_fallback:1; /* Use counter fallback management.
> */
>       unsigned int mtr_en:1; /* Whether support meter. */
>       unsigned int mtr_reg_share:1; /* Whether support meter REG_C share.
> */
> +     unsigned int sampler_en:1; /* Whether support sampler. */
>       uint16_t domain_id; /* Switch domain identifier. */
>       uint16_t vport_id; /* Associated VF vport index (if any). */
>       uint32_t vport_meta_tag; /* Used for vport index match ove VF LAG. */
> diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
> index 2c96677..902380b 100644
> --- a/drivers/net/mlx5/mlx5_flow.h
> +++ b/drivers/net/mlx5/mlx5_flow.h
> @@ -200,6 +200,7 @@ enum mlx5_feature_name {
>  #define MLX5_FLOW_ACTION_SET_IPV4_DSCP (1ull << 32)
>  #define MLX5_FLOW_ACTION_SET_IPV6_DSCP (1ull << 33)
>  #define MLX5_FLOW_ACTION_AGE (1ull << 34)
> +#define MLX5_FLOW_ACTION_SAMPLE (1ull << 35)
> 
>  #define MLX5_FLOW_FATE_ACTIONS \
>       (MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
> diff --git a/drivers/net/mlx5/mlx5_flow_dv.c
> b/drivers/net/mlx5/mlx5_flow_dv.c
> index f174009..710c0f3 100644
> --- a/drivers/net/mlx5/mlx5_flow_dv.c
> +++ b/drivers/net/mlx5/mlx5_flow_dv.c
> @@ -3925,6 +3925,127 @@ struct field_modify_info modify_tcp[] = {
>  }
> 
>  /**
> + * Validate the sample action.
> + *
> + * @param[in] action_flags
> + *   Holds the actions detected until now.
> + * @param[in] action
> + *   Pointer to the sample action.
> + * @param[in] dev
> + *   Pointer to the Ethernet device structure.
> + * @param[in] attr
> + *   Attributes of flow that includes this action.
> + * @param[out] error
> + *   Pointer to error structure.
> + *
> + * @return
> + *   0 on success, a negative errno value otherwise and rte_errno is set.
> + */
> +static int
> +flow_dv_validate_action_sample(uint64_t action_flags,
> +                           const struct rte_flow_action *action,
> +                           struct rte_eth_dev *dev,
> +                           const struct rte_flow_attr *attr,
> +                           struct rte_flow_error *error)
> +{
> +     struct mlx5_priv *priv = dev->data->dev_private;
> +     struct mlx5_dev_config *dev_conf = &priv->config;
> +     const struct rte_flow_action_sample *sample = action->conf;
> +     const struct rte_flow_action *act = sample->actions;
> +     uint64_t sub_action_flags = 0;
> +     int actions_n = 0;
> +     int ret;
> +
> +     if (!attr->group)
> +             return rte_flow_error_set(error, ENOTSUP,
> +
> RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
> +                                       NULL, "root table is not supported");
> +     if (!priv->config.devx || !priv->sampler_en)
> +             return rte_flow_error_set(error, ENOTSUP,
> +
> RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
> +                                       NULL,
> +                                       "sample action not supported");
> +     if (!(action->conf))
> +             return rte_flow_error_set(error, EINVAL,
> +                                       RTE_FLOW_ERROR_TYPE_ACTION,
> action,
> +                                       "configuration cannot be null");
> +     if (sample->ratio == 0)
> +             return rte_flow_error_set(error, EINVAL,
> +                                       RTE_FLOW_ERROR_TYPE_ACTION,
> action,
> +                                       "ratio value start from 1");
> +     if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
> +             return rte_flow_error_set(error, EINVAL,
> +                                       RTE_FLOW_ERROR_TYPE_ACTION,
> NULL,
> +                                       "Duplicate sample actions set");
> +     if (action_flags & MLX5_FLOW_ACTION_METER)
> +             return rte_flow_error_set(error, EINVAL,
> +                                       RTE_FLOW_ERROR_TYPE_ACTION,
> action,
> +                                       "wrong action order, meter should "
> +                                       "be after sample action");
> +     for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
> +             if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
> +                     return rte_flow_error_set(error, ENOTSUP,
> +
> RTE_FLOW_ERROR_TYPE_ACTION,
> +                                               act, "too many actions");
> +             switch (act->type) {
> +             case RTE_FLOW_ACTION_TYPE_QUEUE:
> +                     ret = mlx5_flow_validate_action_queue(act,
> +                                                           sub_action_flags,
> +                                                           dev,
> +                                                           attr, error);
> +                     if (ret < 0)
> +                             return ret;
> +                     sub_action_flags |= MLX5_FLOW_ACTION_QUEUE;
> +                     break;
> +             case RTE_FLOW_ACTION_TYPE_MARK:
> +                     ret = flow_dv_validate_action_mark(dev, act,
> +                                                        sub_action_flags,
> +                                                        attr, error);
> +                     if (ret < 0)
> +                             return ret;
> +                     if (dev_conf->dv_xmeta_en !=
> MLX5_XMETA_MODE_LEGACY)
> +                             sub_action_flags |=
> MLX5_FLOW_ACTION_MARK |
> +
>       MLX5_FLOW_ACTION_MARK_EXT;
> +                     else
> +                             sub_action_flags |=
> MLX5_FLOW_ACTION_MARK;
> +                     break;
> +             case RTE_FLOW_ACTION_TYPE_COUNT:
> +                     ret = flow_dv_validate_action_count(dev, error);
> +                     if (ret < 0)
> +                             return ret;
> +                     sub_action_flags |= MLX5_FLOW_ACTION_COUNT;
> +                     break;
> +             default:
> +                     return rte_flow_error_set(error, ENOTSUP,
> +
> RTE_FLOW_ERROR_TYPE_ACTION,
> +                                               NULL,
> +                                               "Doesn't support optional "
> +                                               "action");
> +             }
> +     }
> +     if (attr->ingress && !attr->transfer) {
> +             if (!(sub_action_flags & MLX5_FLOW_ACTION_QUEUE))
> +                     return rte_flow_error_set(error, EINVAL,
> +
> RTE_FLOW_ERROR_TYPE_ACTION,
> +                                               NULL,
> +                                               "Ingress must has a dest "
> +                                               "QUEUE for Sample");
> +     } else if (attr->egress && !attr->transfer) {
> +             return rte_flow_error_set(error, ENOTSUP,
> +                                       RTE_FLOW_ERROR_TYPE_ACTION,
> +                                       NULL,
> +                                       "Sample Only support Ingress "
> +                                       "or E-Switch");
> +     } else if (sample->actions->type != RTE_FLOW_ACTION_TYPE_END) {
> +             return rte_flow_error_set(error, ENOTSUP,
> +                                       RTE_FLOW_ERROR_TYPE_ACTION,
> NULL,
> +                                       "E-Switch doesn't support any "
> +                                       "optinal action for sampling");
> +     }
> +     return 0;
> +}
> +
> +/**
>   * Find existing modify-header resource or create and register a new one.
>   *
>   * @param dev[in, out]
> @@ -5539,6 +5660,15 @@ struct field_modify_info modify_tcp[] = {
>                       action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
>                       rw_act_num += MLX5_ACT_NUM_SET_DSCP;
>                       break;
> +             case RTE_FLOW_ACTION_TYPE_SAMPLE:
> +                     ret = flow_dv_validate_action_sample(action_flags,
> +                                                          actions, dev,
> +                                                          attr, error);
> +                     if (ret < 0)
> +                             return ret;
> +                     action_flags |= MLX5_FLOW_ACTION_SAMPLE;
> +                     ++actions_n;
> +                     break;
>               default:
>                       return rte_flow_error_set(error, ENOTSUP,
> 
> RTE_FLOW_ERROR_TYPE_ACTION,
> --
> 1.8.3.1

Reply via email to