Subject: Re: [PATCH net-next 05/10] net/mlx5e: Support IPsec RX packet offload in tunnel mode

From: Leon Romanovsky <[email-masked]>
Date: Thu, 13 Apr 2023 14:46:36 +0300

On Tue, Apr 11, 2023 at 06:37:03PM +0200, Simon Horman wrote:
> On Mon, Apr 10, 2023 at 09:19:07AM +0300, Leon Romanovsky wrote:
> > From: Leon Romanovsky <[email-masked]>
> > 
> > Extend mlx5 driver with logic to support IPsec RX packet offload
> > in tunnel mode.
> > 
> > Signed-off-by: Leon Romanovsky <[email-masked]>
> 
> ...
> 
> > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c
> > index 980583fb1e52..8ecaf4100b9c 100644
> > --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c
> > +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c
> > @@ -836,6 +836,60 @@ static int setup_modify_header(struct mlx5_core_dev *mdev, u32 val, u8 dir,
> >  	return 0;
> >  }
> >  
> > +static int
> > +setup_pkt_tunnel_reformat(struct mlx5_core_dev *mdev,
> > +			  struct mlx5_accel_esp_xfrm_attrs *attrs,
> > +			  struct mlx5_pkt_reformat_params *reformat_params)
> > +{
> > +	union {
> > +		struct {
> > +			u8 dmac[6];
> > +			u8 smac[6];
> > +			__be16 ethertype;
> > +		} __packed;
> > +		u8 raw[ETH_HLEN];
> > +	} __packed *mac_hdr;
> 
> Can struct ethhrd be used here?
> I think it has the same layout as the fields of the inner structure above.

Yes, it can, will change.

> And I don't think the union is giving us much: the raw field seems unused.

Thanks, it isn't needed here.

> 
> > +	char *reformatbf;
> > +	size_t bfflen;
> > +
> > +	bfflen = sizeof(*mac_hdr);
> > +
> > +	reformatbf = kzalloc(bfflen, GFP_KERNEL);
> 
> I'm not sure that reformatbf is providing much value.

It is more useful in next patch, where reformatbf will hold ESP, ipv4/6 and ETH
headers.

> Perhaps:
> 
> 	mac_hdr = kzalloc(bfflen, GFP_KERNEL);
> 
> > +	if (!reformatbf)
> > +		return -ENOMEM;
> > +
> > +	mac_hdr = (void *)reformatbf;
> 
> If you must cast, perhaps to the type of mac_hdr, which is not void *.

I'll change.

> 
> > +	switch (attrs->family) {
> > +	case AF_INET:
> > +		mac_hdr->ethertype = htons(ETH_P_IP);
> > +		break;
> > +	case AF_INET6:
> > +		mac_hdr->ethertype = htons(ETH_P_IPV6);
> > +		break;
> > +	default:
> > +		goto free_reformatbf;
> > +	}
> > +
> > +	ether_addr_copy(mac_hdr->dmac, attrs->dmac);
> > +	ether_addr_copy(mac_hdr->smac, attrs->smac);
> > +
> > +	switch (attrs->dir) {
> > +	case XFRM_DEV_OFFLOAD_IN:
> > +		reformat_params->type = MLX5_REFORMAT_TYPE_L3_ESP_TUNNEL_TO_L2;
> > +		break;
> > +	default:
> > +		goto free_reformatbf;
> > +	}
> > +
> > +	reformat_params->size = bfflen;
> > +	reformat_params->data = reformatbf;
> > +	return 0;
> > +
> > +free_reformatbf:
> > +	kfree(reformatbf);
> > +	return -EINVAL;
> > +}
> 
> ...