[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250422123902.2019685-5-o.rempel@pengutronix.de>
Date: Tue, 22 Apr 2025 14:39:02 +0200
From: Oleksij Rempel <o.rempel@...gutronix.de>
To: "David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>,
Simon Horman <horms@...nel.org>
Cc: Oleksij Rempel <o.rempel@...gutronix.de>,
kernel@...gutronix.de,
linux-kernel@...r.kernel.org,
netdev@...r.kernel.org,
Maxime Chevallier <maxime.chevallier@...tlin.com>
Subject: [PATCH net-next v2 4/4] net: selftests: add PHY loopback tests with HW checksum offload
Introduce two new PHY loopback tests that validate hardware checksum
offload functionality using UDP and TCP packets. These tests set
csum_mode = CHECKSUM_PARTIAL, allowing the NIC to compute transport
checksums.
Tests are only executed if the device advertises NETIF_F_HW_CSUM
support. If not, they are skipped with -EOPNOTSUPP.
Also register the tests under descriptive names in the test list.
Signed-off-by: Oleksij Rempel <o.rempel@...gutronix.de>
Reviewed-by: Simon Horman <horms@...nel.org>
---
net/core/selftests.c | 80 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 80 insertions(+)
diff --git a/net/core/selftests.c b/net/core/selftests.c
index 591686978dd7..e751dc677858 100644
--- a/net/core/selftests.c
+++ b/net/core/selftests.c
@@ -539,6 +539,79 @@ static int net_test_phy_loopback_tcp(struct net_device *ndev)
return __net_test_loopback(ndev, &attr);
}
+/**
+ * net_test_phy_loopback_udp_hwcsum - PHY loopback test using UDP with HW
+ * checksum
+ * @ndev: The network device to test
+ *
+ * Sends and receives a UDP packet through the device's internal PHY loopback
+ * path. The packet is configured for hardware checksum offload
+ * (CHECKSUM_PARTIAL), allowing the NIC to compute the transport checksum.
+ *
+ * Expected packet path:
+ * Test code → MAC driver → MAC HW → xMII → PHY →
+ * internal PHY loopback → xMII → MAC HW → MAC driver → test code
+ *
+ * The test frame includes Ethernet (14B), IPv4 (20B), UDP (8B), and a
+ * small payload (13B), totaling 55 bytes before MAC padding/FCS. Most
+ * MACs pad this to the minimum Ethernet payload (60 bytes before FCS).
+ *
+ * If the device does not support NETIF_F_HW_CSUM, the test is skipped
+ * and -EOPNOTSUPP is returned.
+ *
+ * Returns 0 on success, or negative error code on failure.
+ */
+static int net_test_phy_loopback_udp_hwcsum(struct net_device *ndev)
+{
+ struct net_packet_attrs attr = { };
+
+ if (!(ndev->features & NETIF_F_HW_CSUM))
+ return -EOPNOTSUPP;
+
+ attr.dst = ndev->dev_addr;
+ attr.tcp = false;
+ attr.csum_mode = NET_TEST_CHECKSUM_PARTIAL;
+
+ return __net_test_loopback(ndev, &attr);
+}
+
+/**
+ * net_test_phy_loopback_tcp_hwcsum - PHY loopback test using TCP with HW
+ * checksum
+ * @ndev: The network device to test
+ *
+ * Sends and receives a TCP packet through the device's internal PHY loopback
+ * path. The packet is configured for hardware checksum offload
+ * (CHECKSUM_PARTIAL), allowing the NIC to compute the transport checksum.
+ *
+ * Expected packet path:
+ * Test code → MAC driver → MAC HW → xMII → PHY →
+ * internal PHY loopback → xMII → MAC HW → MAC driver → test code
+ * (via packet_type handler)
+ *
+ * The test frame includes Ethernet (14B), IPv4 (20B), TCP (20B),
+ * and a small payload (13B), totaling 67 bytes before FCS.
+ * No additional padding is required.
+ *
+ * If the device does not support NETIF_F_HW_CSUM, the test is skipped
+ * and -EOPNOTSUPP is returned.
+ *
+ * Returns 0 on success, or negative error code on failure.
+ */
+static int net_test_phy_loopback_tcp_hwcsum(struct net_device *ndev)
+{
+ struct net_packet_attrs attr = { };
+
+ if (!(ndev->features & NETIF_F_HW_CSUM))
+ return -EOPNOTSUPP;
+
+ attr.dst = ndev->dev_addr;
+ attr.tcp = true;
+ attr.csum_mode = NET_TEST_CHECKSUM_PARTIAL;
+
+ return __net_test_loopback(ndev, &attr);
+}
+
static const struct net_test {
char name[ETH_GSTRING_LEN];
int (*fn)(struct net_device *ndev);
@@ -562,6 +635,13 @@ static const struct net_test {
}, {
.name = "PHY loopback TCP (SW csum) ",
.fn = net_test_phy_loopback_tcp,
+ }, {
+ /* Conditional HW checksum tests */
+ .name = "PHY loopback UDP (HW csum) ",
+ .fn = net_test_phy_loopback_udp_hwcsum,
+ }, {
+ .name = "PHY loopback TCP (HW csum) ",
+ .fn = net_test_phy_loopback_tcp_hwcsum,
}, {
/* This test should be done after all PHY loopback test */
.name = "PHY internal loopback, disable",
--
2.39.5
Powered by blists - more mailing lists