Subject: Re: [PATCH RFC,net-next 10/10] dsa: bcm_sf2: use flow_rule infrastructure

From: Florian Fainelli <[email-masked]>
Date: Wed, 26 Sep 2018 11:41:30 -0700

Hi Pablo,

On 09/25/2018 12:20 PM, Pablo Neira Ayuso wrote:
> Update this driver to use the flow_rule infrastructure, hence the same
> code to populate hardware IR can be used from ethtool_rx_flow and the
> cls_flower interfaces.

Thanks for doing the conversion, I believe we could change things a
little bit such that there are fewer things to audit for correctness,
see below:

> 
> Signed-off-by: Pablo Neira Ayuso <[email-masked]>
> ---
>  drivers/net/dsa/bcm_sf2_cfp.c | 311 ++++++++++++++++++++++--------------------
>  1 file changed, 166 insertions(+), 145 deletions(-)
> 
> diff --git a/drivers/net/dsa/bcm_sf2_cfp.c b/drivers/net/dsa/bcm_sf2_cfp.c
> index 47c5f272a084..9dace0e25a3a 100644
> --- a/drivers/net/dsa/bcm_sf2_cfp.c
> +++ b/drivers/net/dsa/bcm_sf2_cfp.c
> @@ -251,10 +251,12 @@ static int bcm_sf2_cfp_act_pol_set(struct bcm_sf2_priv *priv,
>  }
>  
>  static void bcm_sf2_cfp_slice_ipv4(struct bcm_sf2_priv *priv,
> -				   struct ethtool_tcpip4_spec *v4_spec,
> +				   struct flow_rule *flow_rule,
>  				   unsigned int slice_num,
>  				   bool mask)
>  {
> +	struct flow_match_ipv4_addrs ipv4;
> +	struct flow_match_ports ports;
>  	u32 reg, offset;
>  
>  	/* C-Tag		[31:24]
> @@ -268,41 +270,54 @@ static void bcm_sf2_cfp_slice_ipv4(struct bcm_sf2_priv *priv,
>  		offset = CORE_CFP_DATA_PORT(4);
>  	core_writel(priv, reg, offset);
>  
> +	flow_rule_match_ipv4_addrs(flow_rule, &ipv4);
> +	flow_rule_match_ports(flow_rule, &ports);
> +
>  	/* UDF_n_A7		[31:24]
>  	 * UDF_n_A6		[23:8]
>  	 * UDF_n_A5		[7:0]
>  	 */
> -	reg = be16_to_cpu(v4_spec->pdst) >> 8;
> -	if (mask)
> +	if (mask) {
> +		reg = be16_to_cpu(ports.mask->dst) >> 8;
>  		offset = CORE_CFP_MASK_PORT(3);
> -	else
> +	} else {
> +		reg = be16_to_cpu(ports.key->dst) >> 8;
>  		offset = CORE_CFP_DATA_PORT(3);
> +	}

For instance here, instead of having to assign "reg" differently, just
have an intermediate struct flow_match_ports variable that either points
to &ports.mask or &ports.key.

I quickly glanced through the changes, and I suspect that they are
correct, but there is unfortunately way too much code movement within
the functions which greatly hinders the ability to have complete
confidence in the changes :)

Can you find a way to only perform the ethtool_rx_flow_spec to flow_rule
conversion as close as possible from the point of use within the callee?

Thanks!
-- 
Florian