diff mbox series

[net-next,v2,2/2] net/mlx5e: add mlx5e_rep_indr_setup_ft_cb support

Message ID 1584523959-6587-3-git-send-email-wenxu@ucloud.cn
State Awaiting Upstream
Delegated to: David Miller
Headers show
Series net/mlx5e: add indr block support in the FT mode | expand

Commit Message

wenxu March 18, 2020, 9:32 a.m. UTC
From: wenxu <wenxu@ucloud.cn>

Add mlx5e_rep_indr_setup_ft_cb to support indr block setup
in FT mode.

Signed-off-by: wenxu <wenxu@ucloud.cn>
---
v2: rebase to master

 drivers/net/ethernet/mellanox/mlx5/core/en_rep.c | 49 ++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

Comments

Saeed Mahameed March 21, 2020, 2:45 a.m. UTC | #1
On Wed, 2020-03-18 at 17:32 +0800, wenxu@ucloud.cn wrote:
> From: wenxu <wenxu@ucloud.cn>
> 
> Add mlx5e_rep_indr_setup_ft_cb to support indr block setup
> in FT mode.
> 
> Signed-off-by: wenxu <wenxu@ucloud.cn>
> ---
> v2: rebase to master
> 
>  drivers/net/ethernet/mellanox/mlx5/core/en_rep.c | 49
> ++++++++++++++++++++++++
>  1 file changed, 49 insertions(+)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
> b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
> index 057f5f9..a88c70b 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
> @@ -732,6 +732,52 @@ static int mlx5e_rep_indr_setup_tc_cb(enum
> tc_setup_type type,
>  	}
>  }
>  
> +static int mlx5e_rep_indr_setup_ft_cb(enum tc_setup_type type,
> +				      void *type_data, void *indr_priv)
> +{
> +	struct mlx5e_rep_indr_block_priv *priv = indr_priv;
> +	struct mlx5e_priv *mpriv = netdev_priv(priv->rpriv->netdev);

Hi Wenxu,

let's fix reverse xmas tree style here, while vlad is looking at this.

> +	struct mlx5_eswitch *esw = mpriv->mdev->priv.eswitch;
> +	struct flow_cls_offload *f = type_data;
> +	struct flow_cls_offload tmp;
> +	unsigned long flags;
> +	int err;
> +
> +	flags = MLX5_TC_FLAG(EGRESS) |
> +		MLX5_TC_FLAG(ESW_OFFLOAD) |
> +		MLX5_TC_FLAG(FT_OFFLOAD);
> +
> +	switch (type) {
> +	case TC_SETUP_CLSFLOWER:
> +		memcpy(&tmp, f, sizeof(*f));
> +
> +		if (!mlx5_esw_chains_prios_supported(esw))
> +			return -EOPNOTSUPP;
> +
> +		/* Re-use tc offload path by moving the ft flow to the
> +		 * reserved ft chain.
> +		 *
> +		 * FT offload can use prio range [0, INT_MAX], so we
> normalize
> +		 * it to range [1, mlx5_esw_chains_get_prio_range(esw)]
> +		 * as with tc, where prio 0 isn't supported.
> +		 *
> +		 * We only support chain 0 of FT offload.
> +		 */
> +		if (tmp.common.prio >=
> mlx5_esw_chains_get_prio_range(esw))
> +			return -EOPNOTSUPP;
> +		if (tmp.common.chain_index != 0)
> +			return -EOPNOTSUPP;
> +
> +		tmp.common.chain_index =
> mlx5_esw_chains_get_ft_chain(esw);
> +		tmp.common.prio++;
> +		err = mlx5e_rep_indr_offload(priv->netdev, &tmp, priv,
> flags);
> +		memcpy(&f->stats, &tmp.stats, sizeof(f->stats));
> +		return err;
> +	default:
> +		return -EOPNOTSUPP;
> +	}
> +}
> +
>  static void mlx5e_rep_indr_block_unbind(void *cb_priv)
>  {
>  	struct mlx5e_rep_indr_block_priv *indr_priv = cb_priv;
> @@ -809,6 +855,9 @@ int mlx5e_rep_indr_setup_cb(struct net_device
> *netdev, void *cb_priv,
>  	case TC_SETUP_BLOCK:
>  		return mlx5e_rep_indr_setup_block(netdev, cb_priv,
> type_data,
>  						  mlx5e_rep_indr_setup_
> tc_cb);
> +	case TC_SETUP_FT:
> +		return mlx5e_rep_indr_setup_block(netdev, cb_priv,
> type_data,
> +						  mlx5e_rep_indr_setup_
> ft_cb);
>  	default:
>  		return -EOPNOTSUPP;
>  	}
wenxu March 21, 2020, 3:57 a.m. UTC | #2
在 2020/3/21 10:45, Saeed Mahameed 写道:
> On Wed, 2020-03-18 at 17:32 +0800, wenxu@ucloud.cn wrote:
>> From: wenxu <wenxu@ucloud.cn>
>>
>> Add mlx5e_rep_indr_setup_ft_cb to support indr block setup
>> in FT mode.
>>
>> Signed-off-by: wenxu <wenxu@ucloud.cn>
>> ---
>> v2: rebase to master
>>
>>   drivers/net/ethernet/mellanox/mlx5/core/en_rep.c | 49
>> ++++++++++++++++++++++++
>>   1 file changed, 49 insertions(+)
>>
>> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
>> b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
>> index 057f5f9..a88c70b 100644
>> --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
>> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
>> @@ -732,6 +732,52 @@ static int mlx5e_rep_indr_setup_tc_cb(enum
>> tc_setup_type type,
>>   	}
>>   }
>>   
>> +static int mlx5e_rep_indr_setup_ft_cb(enum tc_setup_type type,
>> +				      void *type_data, void *indr_priv)
>> +{
>> +	struct mlx5e_rep_indr_block_priv *priv = indr_priv;
>> +	struct mlx5e_priv *mpriv = netdev_priv(priv->rpriv->netdev);
> Hi Wenxu,
>
> let's fix reverse xmas tree style here, while vlad is looking at this.

But the second line depends on the first line.  the mpriv ptr get from 
the priv ptr.


>
>> +	struct mlx5_eswitch *esw = mpriv->mdev->priv.eswitch;
>> +	struct flow_cls_offload *f = type_data;
>> +	struct flow_cls_offload tmp;
>> +	unsigned long flags;
>> +	int err;
>> +
>> +	flags = MLX5_TC_FLAG(EGRESS) |
>> +		MLX5_TC_FLAG(ESW_OFFLOAD) |
>> +		MLX5_TC_FLAG(FT_OFFLOAD);
>> +
>> +	switch (type) {
>> +	case TC_SETUP_CLSFLOWER:
>> +		memcpy(&tmp, f, sizeof(*f));
>> +
>> +		if (!mlx5_esw_chains_prios_supported(esw))
>> +			return -EOPNOTSUPP;
>> +
>> +		/* Re-use tc offload path by moving the ft flow to the
>> +		 * reserved ft chain.
>> +		 *
>> +		 * FT offload can use prio range [0, INT_MAX], so we
>> normalize
>> +		 * it to range [1, mlx5_esw_chains_get_prio_range(esw)]
>> +		 * as with tc, where prio 0 isn't supported.
>> +		 *
>> +		 * We only support chain 0 of FT offload.
>> +		 */
>> +		if (tmp.common.prio >=
>> mlx5_esw_chains_get_prio_range(esw))
>> +			return -EOPNOTSUPP;
>> +		if (tmp.common.chain_index != 0)
>> +			return -EOPNOTSUPP;
>> +
>> +		tmp.common.chain_index =
>> mlx5_esw_chains_get_ft_chain(esw);
>> +		tmp.common.prio++;
>> +		err = mlx5e_rep_indr_offload(priv->netdev, &tmp, priv,
>> flags);
>> +		memcpy(&f->stats, &tmp.stats, sizeof(f->stats));
>> +		return err;
>> +	default:
>> +		return -EOPNOTSUPP;
>> +	}
>> +}
>> +
>>   static void mlx5e_rep_indr_block_unbind(void *cb_priv)
>>   {
>>   	struct mlx5e_rep_indr_block_priv *indr_priv = cb_priv;
>> @@ -809,6 +855,9 @@ int mlx5e_rep_indr_setup_cb(struct net_device
>> *netdev, void *cb_priv,
>>   	case TC_SETUP_BLOCK:
>>   		return mlx5e_rep_indr_setup_block(netdev, cb_priv,
>> type_data,
>>   						  mlx5e_rep_indr_setup_
>> tc_cb);
>> +	case TC_SETUP_FT:
>> +		return mlx5e_rep_indr_setup_block(netdev, cb_priv,
>> type_data,
>> +						  mlx5e_rep_indr_setup_
>> ft_cb);
>>   	default:
>>   		return -EOPNOTSUPP;
>>   	}
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
index 057f5f9..a88c70b 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
@@ -732,6 +732,52 @@  static int mlx5e_rep_indr_setup_tc_cb(enum tc_setup_type type,
 	}
 }
 
+static int mlx5e_rep_indr_setup_ft_cb(enum tc_setup_type type,
+				      void *type_data, void *indr_priv)
+{
+	struct mlx5e_rep_indr_block_priv *priv = indr_priv;
+	struct mlx5e_priv *mpriv = netdev_priv(priv->rpriv->netdev);
+	struct mlx5_eswitch *esw = mpriv->mdev->priv.eswitch;
+	struct flow_cls_offload *f = type_data;
+	struct flow_cls_offload tmp;
+	unsigned long flags;
+	int err;
+
+	flags = MLX5_TC_FLAG(EGRESS) |
+		MLX5_TC_FLAG(ESW_OFFLOAD) |
+		MLX5_TC_FLAG(FT_OFFLOAD);
+
+	switch (type) {
+	case TC_SETUP_CLSFLOWER:
+		memcpy(&tmp, f, sizeof(*f));
+
+		if (!mlx5_esw_chains_prios_supported(esw))
+			return -EOPNOTSUPP;
+
+		/* Re-use tc offload path by moving the ft flow to the
+		 * reserved ft chain.
+		 *
+		 * FT offload can use prio range [0, INT_MAX], so we normalize
+		 * it to range [1, mlx5_esw_chains_get_prio_range(esw)]
+		 * as with tc, where prio 0 isn't supported.
+		 *
+		 * We only support chain 0 of FT offload.
+		 */
+		if (tmp.common.prio >= mlx5_esw_chains_get_prio_range(esw))
+			return -EOPNOTSUPP;
+		if (tmp.common.chain_index != 0)
+			return -EOPNOTSUPP;
+
+		tmp.common.chain_index = mlx5_esw_chains_get_ft_chain(esw);
+		tmp.common.prio++;
+		err = mlx5e_rep_indr_offload(priv->netdev, &tmp, priv, flags);
+		memcpy(&f->stats, &tmp.stats, sizeof(f->stats));
+		return err;
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
 static void mlx5e_rep_indr_block_unbind(void *cb_priv)
 {
 	struct mlx5e_rep_indr_block_priv *indr_priv = cb_priv;
@@ -809,6 +855,9 @@  int mlx5e_rep_indr_setup_cb(struct net_device *netdev, void *cb_priv,
 	case TC_SETUP_BLOCK:
 		return mlx5e_rep_indr_setup_block(netdev, cb_priv, type_data,
 						  mlx5e_rep_indr_setup_tc_cb);
+	case TC_SETUP_FT:
+		return mlx5e_rep_indr_setup_block(netdev, cb_priv, type_data,
+						  mlx5e_rep_indr_setup_ft_cb);
 	default:
 		return -EOPNOTSUPP;
 	}