diff mbox series

[net-next] mlxsw: Enable Tx checksum offload

Message ID 8dc86c95474ce10572a0fa83b8adb0259558e982.1738950446.git.petrm@nvidia.com (mailing list archive)
State Accepted
Commit 907dd32b4a8aa7fedc2ef1867a6c3a1033738bcb
Delegated to: Netdev Maintainers
Headers show
Series [net-next] mlxsw: Enable Tx checksum offload | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
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 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 4 this patch: 4
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, 31 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-08--03-00 (tests: 889)

Commit Message

Petr Machata Feb. 7, 2025, 6 p.m. UTC
From: Ido Schimmel <idosch@nvidia.com>

The device is able to checksum plain TCP / UDP packets over IPv4 / IPv6
when the 'ipcs' bit in the send descriptor is set. Advertise support for
the 'NETIF_F_IP{,6}_CSUM' features in net devices registered by the
driver and VLAN uppers and set the 'ipcs' bit when the stack requests Tx
checksum offload.

Note that the device also calculates the IPv4 checksum, but it first
zeroes the current checksum so there should not be any difference
compared to the checksum calculated by the kernel.

On SN5600 (Spectrum-4) there is about 10% improvement in Tx packet rate
with 1400 byte packets when using pktgen.

Tested on Spectrum-{1,2,3,4} with all the combinations of IPv4 / IPv6,
TCP / UDP, with and without VLAN.

Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: Petr Machata <petrm@nvidia.com>
---
 drivers/net/ethernet/mellanox/mlxsw/pci.c      | 2 ++
 drivers/net/ethernet/mellanox/mlxsw/pci_hw.h   | 5 +++++
 drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 6 ++++--
 3 files changed, 11 insertions(+), 2 deletions(-)

Comments

Simon Horman Feb. 10, 2025, 8:59 p.m. UTC | #1
On Fri, Feb 07, 2025 at 07:00:44PM +0100, Petr Machata wrote:
> From: Ido Schimmel <idosch@nvidia.com>
> 
> The device is able to checksum plain TCP / UDP packets over IPv4 / IPv6
> when the 'ipcs' bit in the send descriptor is set. Advertise support for
> the 'NETIF_F_IP{,6}_CSUM' features in net devices registered by the
> driver and VLAN uppers and set the 'ipcs' bit when the stack requests Tx
> checksum offload.
> 
> Note that the device also calculates the IPv4 checksum, but it first
> zeroes the current checksum so there should not be any difference
> compared to the checksum calculated by the kernel.
> 
> On SN5600 (Spectrum-4) there is about 10% improvement in Tx packet rate
> with 1400 byte packets when using pktgen.
> 
> Tested on Spectrum-{1,2,3,4} with all the combinations of IPv4 / IPv6,
> TCP / UDP, with and without VLAN.
> 
> Signed-off-by: Ido Schimmel <idosch@nvidia.com>
> Reviewed-by: Petr Machata <petrm@nvidia.com>
> Signed-off-by: Petr Machata <petrm@nvidia.com>

Reviewed-by: Simon Horman <horms@kernel.org>
patchwork-bot+netdevbpf@kernel.org Feb. 11, 2025, 3:30 a.m. UTC | #2
Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Fri, 7 Feb 2025 19:00:44 +0100 you wrote:
> From: Ido Schimmel <idosch@nvidia.com>
> 
> The device is able to checksum plain TCP / UDP packets over IPv4 / IPv6
> when the 'ipcs' bit in the send descriptor is set. Advertise support for
> the 'NETIF_F_IP{,6}_CSUM' features in net devices registered by the
> driver and VLAN uppers and set the 'ipcs' bit when the stack requests Tx
> checksum offload.
> 
> [...]

Here is the summary with links:
  - [net-next] mlxsw: Enable Tx checksum offload
    https://git.kernel.org/netdev/net-next/c/907dd32b4a8a

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mellanox/mlxsw/pci.c b/drivers/net/ethernet/mellanox/mlxsw/pci.c
index 2c34c420af56..3488d6e4fbf1 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/pci.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/pci.c
@@ -2595,6 +2595,8 @@  static int mlxsw_pci_skb_transmit(void *bus_priv, struct sk_buff *skb,
 	for (i++; i < MLXSW_PCI_WQE_SG_ENTRIES; i++)
 		mlxsw_pci_wqe_byte_count_set(wqe, i, 0);
 
+	mlxsw_pci_wqe_ipcs_set(wqe, skb->ip_summed == CHECKSUM_PARTIAL);
+
 	/* Everything is set up, ring producer doorbell to get HW going */
 	q->producer_counter++;
 	mlxsw_pci_queue_doorbell_producer_ring(mlxsw_pci, q);
diff --git a/drivers/net/ethernet/mellanox/mlxsw/pci_hw.h b/drivers/net/ethernet/mellanox/mlxsw/pci_hw.h
index e56da24e9e9e..882e01abd9c4 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/pci_hw.h
+++ b/drivers/net/ethernet/mellanox/mlxsw/pci_hw.h
@@ -96,6 +96,11 @@  MLXSW_ITEM32(pci, wqe, lp, 0x00, 30, 1);
  */
 MLXSW_ITEM32(pci, wqe, type, 0x00, 23, 4);
 
+/* pci_wqe_ipcs
+ * Calculate IPv4 and TCP / UDP checksums.
+ */
+MLXSW_ITEM32(pci, wqe, ipcs, 0x00, 14, 1);
+
 /* pci_wqe_byte_count
  * Size of i-th scatter/gather entry, 0 if entry is unused.
  */
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
index 98632c046170..2f4e14d2f2e2 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
@@ -1630,8 +1630,10 @@  static int mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u16 local_port,
 	netif_carrier_off(dev);
 
 	dev->features |= NETIF_F_SG | NETIF_F_HW_VLAN_CTAG_FILTER |
-			 NETIF_F_HW_TC;
-	dev->hw_features |= NETIF_F_HW_TC | NETIF_F_LOOPBACK;
+			 NETIF_F_HW_TC | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
+	dev->hw_features |= NETIF_F_HW_TC | NETIF_F_LOOPBACK |
+			    NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
+	dev->vlan_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
 	dev->lltx = true;
 	dev->netns_local = true;