Re: [PATCH net-next v3 3/5] net/mlx4: factor HW loopback DMAC into mlx4_en_set_loopback_dmac()

From: Mark Bloch

Date: Wed Nov 25 2026 - 22:40:41 EST




On 25/11/2026 20:00, Joe Damato wrote:
> Extract the code which copies the destination MAC into the WQE for
> eSwitch loopback into a helper. This helper will be used by a follow-up
> series implementing software USO, so USO packets between functions on
> the same port are looped back too.
>
> Signed-off-by: Joe Damato <joe@xxxxxxx>
> Reviewed-by: Daniel Machon <daniel.machon@xxxxxxxxxxxxx>

Thanks for the patch,

Reviewed-by: Mark Bloch <mbloch@xxxxxxxxxx>

> ---
> drivers/net/ethernet/mellanox/mlx4/en_tx.c | 28 ++++++++++++++--------
> 1 file changed, 18 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/net/ethernet/mellanox/mlx4/en_tx.c b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
> index 1fb265a30a30..40dc4f6a7329 100644
> --- a/drivers/net/ethernet/mellanox/mlx4/en_tx.c
> +++ b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
> @@ -870,6 +870,23 @@ static __be32 mlx4_en_csum_flags(const struct sk_buff *skb)
> return cpu_to_be32(MLX4_WQE_CTRL_IP_CSUM | MLX4_WQE_CTRL_TCP_UDP_CSUM);
> }
>
> +static void mlx4_en_set_loopback_dmac(const struct mlx4_en_priv *priv,
> + struct mlx4_en_tx_desc *tx_desc,
> + const struct sk_buff *skb)
> +{
> + struct ethhdr *ethh;
> +
> + if (!(priv->flags & MLX4_EN_FLAG_ENABLE_HW_LOOPBACK))
> + return;
> +
> + /* Copy dst mac address to wqe. This allows loopback in eSwitch,
> + * so that VFs and PF can communicate with each other
> + */
> + ethh = (struct ethhdr *)skb->data;
> + tx_desc->ctrl.srcrb_flags16[0] = get_unaligned((__be16 *)ethh->h_dest);
> + tx_desc->ctrl.imm = get_unaligned((__be32 *)(ethh->h_dest + 2));
> +}
> +
> static bool mlx4_en_prep_vlan(const struct sk_buff *skb,
> union mlx4_wqe_qpn_vlan *qpn_vlan)
> {
> @@ -1007,16 +1024,7 @@ netdev_tx_t mlx4_en_xmit(struct sk_buff *skb, struct net_device *dev)
> ring->tx_csum++;
> }
>
> - if (priv->flags & MLX4_EN_FLAG_ENABLE_HW_LOOPBACK) {
> - struct ethhdr *ethh;
> -
> - /* Copy dst mac address to wqe. This allows loopback in eSwitch,
> - * so that VFs and PF can communicate with each other
> - */
> - ethh = (struct ethhdr *)skb->data;
> - tx_desc->ctrl.srcrb_flags16[0] = get_unaligned((__be16 *)ethh->h_dest);
> - tx_desc->ctrl.imm = get_unaligned((__be32 *)(ethh->h_dest + 2));
> - }
> + mlx4_en_set_loopback_dmac(priv, tx_desc, skb);
>
> /* Handle LSO (TSO) packets */
> if (lso_header_size) {