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

From: Joe Damato

Date: Tue Nov 10 2026 - 18:17:15 EST


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>
---
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 f6059b533eac..97f27e005810 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_tx.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
@@ -871,6 +871,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)
{
@@ -1008,16 +1025,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) {
--
2.53.0-Meta