Thread View: linux.kernel.netdev
2 messages
2 total messages
Started by Rosen Penev
Wed, 14 Oct 2026 00:13
[PATCH net-next v3] net: ag71xx: align the IP header behind DSA tags
Author: Rosen Penev
Date: Wed, 14 Oct 2026 00:13
Date: Wed, 14 Oct 2026 00:13
92 lines
10994 bytes
10994 bytes
The receive buffer offset includes NET_IP_ALIGN to get the IP header
aligned behind a 14 byte Ethernet header. Most ag71xx devices use DSA
switches whose tag sits in front of the EtherType, which moves the IP
header by another 2 bytes. Every access to the IP and TCP headers then
traps and gets emulated by the unaligned access handler, around 6 times
per forwarded frame.
Take the headroom needed by the DSA tagger into account when choosing
the offset.
TP-Link Archer C7 v2 (qca8k), median of 3 runs, Mbit/s:
before after
routed up 743 855
routed down 660 749
local receive 554 572
The unaligned instruction counter no longer moves while forwarding.
Assisted-by: LLM
Signed-off-by: Rosen Penev <rosenp@gmail.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
---
v3: rebase and fix sashiko warnings
v2: rebase and add Reviewed-by.
drivers/net/ethernet/atheros/ag71xx.c | 28 ++++++++++++++++++++++-----
1 file changed, 23 insertions(+), 5 deletions(-)
diff --git a/drivers/net/ethernet/atheros/ag71xx.c b/drivers/net/ethernet/atheros/ag71xx.c
index 8a3c689f6825..73b5f8020ece 100644
--- a/drivers/net/ethernet/atheros/ag71xx.c
+++ b/drivers/net/ethernet/atheros/ag71xx.c
@@ -38,6 +38,7 @@
#include <linux/reset.h>
#include <linux/clk.h>
#include <linux/io.h>
+#include <net/dsa.h>
#include <net/selftests.h>
#define AG71XX_OOM_REFILL (1 + HZ / 10)
@@ -1396,6 +1397,26 @@ static void ag71xx_hw_disable(struct ag71xx *ag)
ag71xx_rings_cleanup(ag);
}
+static unsigned int ag71xx_rx_offset(struct ag71xx *ag)
+{
+ unsigned int align = NET_IP_ALIGN;
+
+ if (ag71xx_is(ag, AR7100) || ag71xx_is(ag, AR9130))
+ return NET_SKB_PAD;
+
+#if IS_ENABLED(CONFIG_NET_DSA)
+ /* A tag inserted in front of the EtherType shifts the IP header,
+ * compensate for it to avoid unaligned accesses in the stack.
+ * This is only evaluated in ndo_open, so a DSA tree that binds to
+ * or unbinds from a running conduit takes effect on the next open.
+ */
+ if (netdev_uses_dsa(ag->ndev))
+ align = (align - ag->ndev->dsa_ptr->tag_ops->needed_headroom) & 3;
+#endif
+
+ return NET_SKB_PAD + align;
+}
+
static int ag71xx_open(struct net_device *ndev)
{
struct ag71xx *ag = netdev_priv(ndev);
@@ -1410,8 +1431,9 @@ static int ag71xx_open(struct net_device *ndev)
}
max_frame_len = ag71xx_max_frame_len(ndev->mtu);
+ ag->rx_buf_offset = ag71xx_rx_offset(ag);
ag->rx_buf_size =
- SKB_DATA_ALIGN(max_frame_len + NET_SKB_PAD + NET_IP_ALIGN);
+ SKB_DATA_ALIGN(max_frame_len + ag->rx_buf_offset);
/* setup max frame length */
ag71xx_wr(ag, AG71XX_REG_MAC_MFL, max_frame_len);
@@ -1874,10 +1896,6 @@ static int ag71xx_probe(struct platform_device *pdev)
ndev->min_mtu = 68;
ndev->max_mtu = dcfg->max_frame_len - ag71xx_max_frame_len(0);
- ag->rx_buf_offset = NET_SKB_PAD;
- if (!ag71xx_is(ag, AR7100) && !ag71xx_is(ag, AR9130))
- ag->rx_buf_offset += NET_IP_ALIGN;
-
if (ag71xx_is(ag, AR7100)) {
ag->tx_ring.desc_split = AG71XX_TX_RING_SPLIT;
tx_size *= AG71XX_TX_RING_DS_PER_PKT;
--
2.56.0
Re: [PATCH net-next v3] net: ag71xx: align the IP header behind DSA tags
Author: patchwork-bot+netdevbpf
Date: Tue, 20 Oct 2026 11:20
Date: Tue, 20 Oct 2026 11:20
24 lines
8672 bytes
8672 bytes
Hello:
This patch was applied to netdev/net-next.git (main)
by Paolo Abeni <pabeni@redhat.com>:
On Tue, 13 Oct 2026 17:13:34 -0700 you wrote:
> The receive buffer offset includes NET_IP_ALIGN to get the IP header
> aligned behind a 14 byte Ethernet header. Most ag71xx devices use DSA
> switches whose tag sits in front of the EtherType, which moves the IP
> header by another 2 bytes. Every access to the IP and TCP headers then
> traps and gets emulated by the unaligned access handler, around 6 times
> per forwarded frame.
>
> [...]
Here is the summary with links:
- [net-next,v3] net: ag71xx: align the IP header behind DSA tags
https://git.kernel.org/netdev/net-next/c/f09123082704
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads