diff mbox series

[net-next,11/12] mlxsw: Set some SKB fields in bus driver

Message ID cf7b6b6a689446db4fc9777679f98c738c3b9b79.1738665783.git.petrm@nvidia.com (mailing list archive)
State New
Delegated to: Netdev Maintainers
Headers show
Series mlxsw: Preparations for XDP support | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 12 of 12 maintainers
netdev/build_clang success Errors and warnings before: 5 this patch: 5
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 76 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2025-02-04--15-00 (tests: 886)

Commit Message

Petr Machata Feb. 4, 2025, 11:05 a.m. UTC
From: Amit Cohen <amcohen@nvidia.com>

Currently, skb->dev and skb->protocol are set in the switch driver
(i.e., 'mlxsw_spectrum'). Previous patches add ports array to bus driver,
so we can get netdevice given local port. There is no real reason to not
set skb->dev and skb->protocol when SKB is created. Move the relevant code
to bus driver. This is needed as a preparation for using
xdp_build_skb_from_buff() which takes care of calling eth_type_trans().

eth_type_trans() moves skb->data to point after Ethernet header, so
skb->len is decreased accordingly. Add ETH_HLEN when per CPU stats are
updated, to save the current behavior which counts also Ethernet header
length.

eth_type_trans() sets skb->dev, so do not handle this in the driver.

Note that for EMADs, local port in CQE is zero, and there is no relevant
netdevice, for such packets, do not set skb->dev and skb->protocol.

Signed-off-by: Amit Cohen <amcohen@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: Petr Machata <petrm@nvidia.com>
---
 drivers/net/ethernet/mellanox/mlxsw/pci.c           | 13 ++++++++++---
 drivers/net/ethernet/mellanox/mlxsw/spectrum.c      |  5 +----
 drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c |  6 +-----
 3 files changed, 12 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mellanox/mlxsw/pci.c b/drivers/net/ethernet/mellanox/mlxsw/pci.c
index b102be38d29d..b560c21fd3ef 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/pci.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/pci.c
@@ -494,7 +494,8 @@  mlxsw_pci_sync_for_cpu(const struct mlxsw_pci_queue *q,
 
 static struct sk_buff *
 mlxsw_pci_rdq_build_skb(struct mlxsw_pci_queue *q,
-			const struct mlxsw_pci_rx_pkt_info *rx_pkt_info)
+			const struct mlxsw_pci_rx_pkt_info *rx_pkt_info,
+			struct net_device *netdev)
 {
 	unsigned int linear_data_size;
 	struct sk_buff *skb;
@@ -513,7 +514,7 @@  mlxsw_pci_rdq_build_skb(struct mlxsw_pci_queue *q,
 	skb_put(skb, linear_data_size);
 
 	if (rx_pkt_info->num_sg_entries == 1)
-		return skb;
+		goto out;
 
 	for (i = 1; i < rx_pkt_info->num_sg_entries; i++) {
 		unsigned int frag_size;
@@ -525,6 +526,10 @@  mlxsw_pci_rdq_build_skb(struct mlxsw_pci_queue *q,
 				page, 0, frag_size, PAGE_SIZE);
 	}
 
+out:
+	if (netdev)
+		skb->protocol = eth_type_trans(skb, netdev);
+
 	return skb;
 }
 
@@ -814,6 +819,7 @@  static void mlxsw_pci_cqe_rdq_handle(struct mlxsw_pci *mlxsw_pci,
 	struct pci_dev *pdev = mlxsw_pci->pdev;
 	struct mlxsw_pci_queue_elem_info *elem_info;
 	struct mlxsw_rx_info rx_info = {};
+	struct mlxsw_pci_port *pci_port;
 	struct sk_buff *skb;
 	u16 byte_count;
 	int err;
@@ -851,7 +857,8 @@  static void mlxsw_pci_cqe_rdq_handle(struct mlxsw_pci *mlxsw_pci,
 	if (err)
 		goto out;
 
-	skb = mlxsw_pci_rdq_build_skb(q, &rx_pkt_info);
+	pci_port = &mlxsw_pci->pci_ports[rx_info.local_port];
+	skb = mlxsw_pci_rdq_build_skb(q, &rx_pkt_info, pci_port->netdev);
 	if (IS_ERR(skb)) {
 		dev_err_ratelimited(&pdev->dev, "Failed to build skb for RDQ\n");
 		mlxsw_pci_rdq_pages_recycle(q, rx_pkt_info.pages,
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
index 6b77e087fe47..a7d2e3716283 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
@@ -2340,15 +2340,12 @@  void mlxsw_sp_rx_listener_no_mark_func(struct sk_buff *skb,
 		return;
 	}
 
-	skb->dev = mlxsw_sp_port->dev;
-
 	pcpu_stats = this_cpu_ptr(mlxsw_sp_port->pcpu_stats);
 	u64_stats_update_begin(&pcpu_stats->syncp);
 	pcpu_stats->rx_packets++;
-	pcpu_stats->rx_bytes += skb->len;
+	pcpu_stats->rx_bytes += skb->len + ETH_HLEN;
 	u64_stats_update_end(&pcpu_stats->syncp);
 
-	skb->protocol = eth_type_trans(skb, skb->dev);
 	napi_gro_receive(mlxsw_skb_cb(skb)->rx_md_info.napi, skb);
 }
 
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c
index 1f9c1c86839f..2a69f1815e5a 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c
@@ -72,16 +72,12 @@  static int mlxsw_sp_rx_listener(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
 		return -EINVAL;
 	}
 
-	skb->dev = mlxsw_sp_port->dev;
-
 	pcpu_stats = this_cpu_ptr(mlxsw_sp_port->pcpu_stats);
 	u64_stats_update_begin(&pcpu_stats->syncp);
 	pcpu_stats->rx_packets++;
-	pcpu_stats->rx_bytes += skb->len;
+	pcpu_stats->rx_bytes += skb->len + ETH_HLEN;
 	u64_stats_update_end(&pcpu_stats->syncp);
 
-	skb->protocol = eth_type_trans(skb, skb->dev);
-
 	return 0;
 }