From: Markus Stockhausen Date: Wed, 24 Jun 2026 09:59:29 +0000 (+0200) Subject: realtek: dsa/eth: adapt transmit path X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bc910540adbafd4cc811dcdf69e9baa562e9fffb;p=thirdparty%2Fopenwrt.git realtek: dsa/eth: adapt transmit path This is just some reordering/simplifcation of the transmit path. Relocate the port extraction into a separate helper for a smaller xmit function. While we are here add some documentation and reorder the tag and its contents. As these are only arbitrary values that help the ethernet driver to identifiy the tag this is just cosmetic. Link: https://github.com/openwrt/openwrt/pull/23948 Signed-off-by: Markus Stockhausen --- diff --git a/target/linux/realtek/files-6.18/drivers/net/ethernet/rtl838x_eth.c b/target/linux/realtek/files-6.18/drivers/net/ethernet/rtl838x_eth.c index c0f8cd86635..b9cb5724923 100644 --- a/target/linux/realtek/files-6.18/drivers/net/ethernet/rtl838x_eth.c +++ b/target/linux/realtek/files-6.18/drivers/net/ethernet/rtl838x_eth.c @@ -1001,25 +1001,32 @@ static void rteth_tx_timeout(struct net_device *dev, unsigned int txqueue) } } +static int rteth_get_dsa_port(struct sk_buff *skb, struct net_device *dev) +{ + struct rteth_ctrl *ctrl = netdev_priv(dev); + u8 *trailer = &skb->data[skb->len - 4]; + + if (netdev_uses_dsa(dev) && + dev->dsa_ptr->tag_ops->proto == DSA_TAG_PROTO_RTL_OTTO && + trailer[0] < ctrl->r->cpu_port && + trailer[1] == 0xab && + trailer[2] == 0xcd && + trailer[3] == 0xef) + return trailer[0]; + + return -1; +} + static int rteth_start_xmit(struct sk_buff *skb, struct net_device *dev) { + int port, val, slot, len = skb->len, ring = skb_get_queue_mapping(skb); struct rteth_ctrl *ctrl = netdev_priv(dev); - int val, slot, len = skb->len, port = -1; - int ring = skb_get_queue_mapping(skb); struct rteth_packet *packet; dma_addr_t packet_dma; - if (netdev_uses_dsa(dev) && - skb->data[len - 4] == 0x80 && - skb->data[len - 3] < ctrl->r->cpu_port && - skb->data[len - 2] == 0x10 && - skb->data[len - 1] == 0x00) { - port = skb->data[len - 3]; - /* space will be reused for 4 byte layer 2 FCS */ - } else { - /* No DSA tag, add space for 4 byte layer 2 FCS */ - len += ETH_FCS_LEN; - } + port = rteth_get_dsa_port(skb, dev); + if (port < 0) + len += ETH_FCS_LEN; /* No reusable 4 byte tag, add space for 4 byte layer 2 FCS */ len = max(ETH_ZLEN + ETH_FCS_LEN, len); if (unlikely(skb_put_padto(skb, len))) { diff --git a/target/linux/realtek/files-6.18/net/dsa/tag_rtl_otto.c b/target/linux/realtek/files-6.18/net/dsa/tag_rtl_otto.c index 08a99155843..2048d5addbe 100644 --- a/target/linux/realtek/files-6.18/net/dsa/tag_rtl_otto.c +++ b/target/linux/realtek/files-6.18/net/dsa/tag_rtl_otto.c @@ -1,8 +1,4 @@ // SPDX-License-Identifier: GPL-2.0+ -/* - * net/dsa/tag_trailer.c - Trailer tag format handling - * Copyright (c) 2008-2009 Marvell Semiconductor - */ #include #include @@ -10,24 +6,20 @@ #include "tag.h" -#define RTL_OTTO_NAME "rtl_otto" - -/* - * TODO: This driver was copied over from trailer tagging. It will be developed - * downstream in OpenWrt in conjunction with the Realtek Otto ethernet driver. - * For now rely on the old trailer handling and keep everything as is. - */ +#define RTL_OTTO_NAME "rtl_otto" +#define RTL_OTTO_TAILROOM 4 static struct sk_buff *rtl_otto_xmit(struct sk_buff *skb, struct net_device *dev) { struct dsa_port *dp = dsa_user_to_port(dev); u8 *trailer; - trailer = skb_put(skb, 4); - trailer[0] = 0x80; - trailer[1] = dp->index; - trailer[2] = 0x10; - trailer[3] = 0x00; + /* Hardware needs space for Layer 2 FCS. Align tag size with that. */ + trailer = skb_put(skb, RTL_OTTO_TAILROOM); + trailer[0] = dp->index; + trailer[1] = 0xab; + trailer[2] = 0xcd; + trailer[3] = 0xef; return skb; } @@ -62,11 +54,11 @@ static struct sk_buff *rtl_otto_rcv(struct sk_buff *skb, struct net_device *dev) } static const struct dsa_device_ops rtl_otto_netdev_ops = { - .name = RTL_OTTO_NAME, - .proto = DSA_TAG_PROTO_RTL_OTTO, - .xmit = rtl_otto_xmit, - .rcv = rtl_otto_rcv, - .needed_tailroom = 4, + .name = RTL_OTTO_NAME, + .proto = DSA_TAG_PROTO_RTL_OTTO, + .xmit = rtl_otto_xmit, + .rcv = rtl_otto_rcv, + .needed_tailroom = RTL_OTTO_TAILROOM, }; MODULE_DESCRIPTION("DSA tag driver for Realtek Otto switches (RTL83xx/RTL93xx)");