From: Amit Cohen <amcohen@xxxxxxxxxx> 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@xxxxxxxxxx> Reviewed-by: Ido Schimmel <idosch@xxxxxxxxxx> Signed-off-by: Petr Machata <petrm@xxxxxxxxxx> --- 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 --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; } -- 2.47.0