From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=178.21.23.139 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796408944; b=sPH6s9soxsXPUI/EJoAXfvMXwoK6xUlEpJMVCVk0xD+r5HQfOLQ6sy4qD9jYRNJnd0kW 5JoP5YNlNS5gxiExeltn7eU4Oo44SEVVohEpO/q4EUiv3VEw0tF++qQT5tZn8S8z82b+v BGheinfGq2EYh9qLWmGGfa/3OvFnCGdne8iGAiaQRL3bxv0PV2QXQhRGvoYPRvKJL5x2S rzvOTrGE8Jy8imS//iQJY9HF+VjbduhcQT8+3rUeOetqPEBDR34TG+L9eqUYP6uf0fE3P F5VXzZcAlEI0gWfTYGw9GCKrPmu+tGZmTrGcjacvEoJ52QNM8hyaJEGG8CwC0Febjdg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796408944; h=DMARC-Filter:Received:X-Virus-Scanned:Received:DKIM-Signature:From: To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version: Content-Type:Content-Transfer-Encoding; bh=rDoI7kcRxaNEltVNJVw4wO/CaGIViADR8JC1FVs+4ho=; b=QKWYr2dTMl1MpQs7qNWeLr5d2Dqbgjtnnx7FlAh/b14d+Etbj8p6Ag0V5SGaFcOE6zY2 RfJsQ1euZ+cvY0Jghvfu9t7KPGUvaWwgkzKZun4qwugQXhUaxKaXSTzAdnKl76hLWory4 zy+QXYN0BLISVJdMA/rkYexSHYT5FEATnYpen0LpsF/oisz0IIp3aNAci5uLhr0/kHURM xlH96humB+gQAYe2Vsf9kHxfXmWZNCszQyuSfkYlr6m4eCq3QskTJ3fxgPt5fgmr3colr LwvZatF6cly9PWimrZHUFbJOclmbFfWCL4toQT72K5INkrpjIlDIGsE8k1i6iQvk9Gg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=disroot.org; spf=pass smtp.mailfrom=disroot.org; dkim=pass header.d=disroot.org header.i=@disroot.org header.a=rsa-sha256 header.s=mail header.b=fqxfWv08; arc=none smtp.remote-ip=178.21.23.139 Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A69B606A334; Fri, 4 Dec 2026 18:29:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4A69B606A334 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=disroot.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=disroot.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=disroot.org header.i=@disroot.org header.a=rsa-sha256 header.s=mail header.b=fqxfWv08 Received: from mail01.layka.lan (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id D0B3382F2B; Fri, 04 Dec 2026 19:29:01 +0100 (CET) X-Virus-Scanned: SPAM Filter at disroot.org Received: from layka.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id tKiLp_b953dY; Fri, 4 Dec 2026 19:29:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1796408940; bh=0IVbPVMyoRBdVc6jTt/agzlZ8dz60OULO2iEAmxQUBE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=fqxfWv08ri2DeJgRuXJSxd2ZiW1LzsiYYgvCmknmo291ZuFB8Wv4t4EBqRPDoXBNU e5Jmjhu/8zgfn40nlhBCnRJfwpdACM/it5acnZwKdVXSmeplRH10PhZddOmRj/oHLB ZiUAngbhUhDsWghG0OW8N8EJUMS5h/7KWT3dfAQO2zZ0ygaUj9nywRwSlmzbFKV9Ft ijdptumWBc3Yd9zR472wrLI6WEjQRTGCtY1XFFoAWdZwr2/sKUVqMWdHEeR5vjsUkQ C3QMAbUMCdtDgiRrT76JgJTWB9BR7yG83RvhBvaa73LrzzHxd3If4hmgw2U72nVc1G zVADEoBy/MxPg== From: Rustam Adilov To: Linus Walleij , Luiz Angelo Daros de Luca , =?UTF-8?q?Alvin=20=C5=A0ipraga?= , Andrew Lunn , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Heiner Kallweit , Russell King , Willem de Bruijn , Simon Horman , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Rustam Adilov , Taiga Ogawa Subject: [RFC PATCH net-next 1/6] net: dsa: tag_rtl8_4: add support for RTL9607C tag variant Date: Fri, 4 Dec 2026 23:25:15 +0500 Message-ID: <20261204182553.33952-2-adilov@disroot.org> In-Reply-To: <20261204182553.33952-1-adilov@disroot.org> References: <20261204182553.33952-1-adilov@disroot.org> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The RTL9607C family of SoCs have an embdedded switch that utilizes the same Realtek CPU Tag protocol 4 with 8 bytes in size but have a bit different of a layout. And that layout is also different for TX versus RX sides and introduces new fields not seen by RTL8_4. The fields PORT, RX_PORTMASK, PRI, PRI_EN, KEEP, LEARN_DIS, PSEL share the same semantics as in RTL8_4 tag. The REASON is the same 8 bit field at byte 3 but numbering seem to be very different. Add basic necessities for this cpu tag variant to function. Tested-by: Taiga Ogawa Signed-off-by: Rustam Adilov --- include/net/dsa.h | 2 + net/dsa/Kconfig | 3 +- net/dsa/tag_rtl8_4.c | 171 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 172 insertions(+), 4 deletions(-) diff --git a/include/net/dsa.h b/include/net/dsa.h index 09f3043d57f0..6f86c7625304 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -63,6 +63,7 @@ struct tc_action; #define DSA_TAG_PROTO_MT7628_VALUE 35 #define DSA_TAG_PROTO_KS8995_VALUE 36 #define DSA_TAG_PROTO_LAN9645X_VALUE 37 +#define DSA_TAG_PROTO_RTL8_4AP_VALUE 38 enum dsa_tag_protocol { DSA_TAG_PROTO_NONE = DSA_TAG_PROTO_NONE_VALUE, @@ -103,6 +104,7 @@ enum dsa_tag_protocol { DSA_TAG_PROTO_MT7628 = DSA_TAG_PROTO_MT7628_VALUE, DSA_TAG_PROTO_KS8995 = DSA_TAG_PROTO_KS8995_VALUE, DSA_TAG_PROTO_LAN9645X = DSA_TAG_PROTO_LAN9645X_VALUE, + DSA_TAG_PROTO_RTL8_4AP = DSA_TAG_PROTO_RTL8_4AP_VALUE, }; struct dsa_switch; diff --git a/net/dsa/Kconfig b/net/dsa/Kconfig index bdeb60af764b..efa5f1661169 100644 --- a/net/dsa/Kconfig +++ b/net/dsa/Kconfig @@ -196,7 +196,8 @@ config NET_DSA_TAG_RTL8_4 tristate "Tag driver for Realtek 8 byte protocol 4 tags" help Say Y or M if you want to enable support for tagging frames for Realtek - switches with 8 byte protocol 4 tags, such as the Realtek RTL8365MB-VC. + switches with 8 byte protocol 4 tags, such as the Realtek RTL8365MB-VC + or the Realtek RTL9607C. config NET_DSA_TAG_RZN1_A5PSW tristate "Tag driver for Renesas RZ/N1 A5PSW switch" diff --git a/net/dsa/tag_rtl8_4.c b/net/dsa/tag_rtl8_4.c index 4da3beebef75..902821524ed3 100644 --- a/net/dsa/tag_rtl8_4.c +++ b/net/dsa/tag_rtl8_4.c @@ -4,8 +4,8 @@ * * Copyright (C) 2021 Alvin Šipraga * - * NOTE: Currently only supports protocol "4" found in the RTL8365MB, hence - * named tag_rtl8_4. + * NOTE: Currently only supports protocol "4" found in the RTL8365MB and RTL9607C, + * hence named tag_rtl8_4 and tag_rtl8_4ap. * * This tag has the following format: * @@ -74,6 +74,54 @@ * software or hardware. To avoid this issue, if the checksum is still pending, * this tagger checksums the packet in software before adding the tag. * + * This 8 byte switch tag can also be found on RTL9607C family of SoCs with + * identical protocol "4", but with a slightly different insides. + * + * On switch->CPU the bytes 4-7 are different and look like: + * + * |-----------------------------------+-----------------------------------| + * | (3) | (3) / (5) | (2) | (1) | (1) | (4) | + * | PRI | EXTSPA / PON_STREAM_ID |PON_STREAM_ID|L3ROUTE| ORIG | PORT | + * |-----------------------------------+-----------------------------------| + * | (1) | (15-bit) / (7-bit) | + * | FBI | FLOW_BASED_HASH / DST_PORT_MASK | + * |-----------------------------------+-----------------------------------| + * + * On CPU->Switch the bytes 3-7 are different and look like: + * + * |-----------------------------------+-----------------------------------| + * | (8-bit) | (8-bit) | + * | Protocol [0x04] | RX_PORTMASK_LOW | + * |-----------------------------------+-----------------------------------| + * | (3-bit) |(1)| (1) | (3) |(1) |(1)| (1) |(1) |(2)| (1) |1| + * |RX_PORTMASK_HIGH| X | PRI_EN | PRI |KEEP| X |LEARN_DIS|PSEL| X |DIRTX|X| + * |-----------------------------------+-----------------------------------| + * | (3-bit)| (2-bit) | (4-bit) | (7-bit) | + * | EXTSPA | PPPOE_ACT | PPPOE_IDX | PON_STREAM_ID | + * |-----------------------------------+-----------------------------------| + * + * With the following descriptions for new fields: + * + * field | description + * -----------------+------------- + * EXTSPA | Source Extension Port. Relevant when PORT is CPU (9, 10, 7). + * PON_STREAM_ID | PON Stream ID (GPON) or LLID index (EPON). Relevant when + * | PORT is PON (5) + * L3ROUTE | "This frame is an intended routed frames" as per docs + * ORIG | The received frame by NIC is the original packet's format + * | before switch lookup and switch didn't do any modifications + * FBI | Flow Based I...? Only relevant when REASON is FB (aka < 64) + * FLOW_BASED_HASH | Flow Based Hash Index. + * DST_PORT_MASK | Switch lookup destination port mask. bit 0: CPU, bit 1-6 are + * | extension ports 0~5. + * PSEL | PON stream id (GPON) / LLID index(EPON) selection. + * DIRTX | Direct TX, whatever that means? Used to be called L34KEEP. + * PPPOE_ACT | Egress action for PPPoE header whose Ether Type = 0x8864. + * | 0: intact, 1: Add PPPoE header, 2: Remove PPPoE header, + * | 3: remarking PPPoE switch TX mac action. + * PPPOE_IDX | PPPoE index pointed to an entry of the PPPoE table in the + * | switch. Switch TX-MAC look PPPoE table up by this index to + * | get PPPoE session ID. */ #include @@ -84,11 +132,12 @@ /* Protocols supported: * - * 0x04 = RTL8365MB DSA protocol + * 0x04 = RTL8365MB / RTL9607C DSA protocol */ #define RTL8_4_NAME "rtl8_4" #define RTL8_4T_NAME "rtl8_4t" +#define RTL8_4AP_NAME "rtl8_4ap" #define RTL8_4_TAG_LEN 8 @@ -97,13 +146,23 @@ #define RTL8_4_REASON GENMASK(7, 0) #define RTL8_4_REASON_FORWARD 0 #define RTL8_4_REASON_TRAP 80 +#define RTL8_4AP_REASON_FLOOD 202 +#define RTL8_4AP_REASON_LUT 204 + +#define RTL8_4AP_RX_PORTMASK_LOW GENMASK(7, 0) +#define RTL8_4AP_RX_PORTMASK_HIGH GENMASK(15, 13) +#define RTL9607C_RX_PORTMASK_HIGH GENMASK(10, 8) +#define RTL8_4AP_DIRTX BIT(1) #define RTL8_4_LEARN_DIS BIT(5) #define RTL8_4_KEEP BIT(7) #define RTL8_4_TX GENMASK(3, 0) #define RTL8_4_RX GENMASK(10, 0) +#define RTL8_4AP_DST_PMASK GENMASK(6, 0) +#define RTL8_4AP_DST_CPU_MASK BIT(0) + static void rtl8_4_write_tag(struct sk_buff *skb, struct net_device *dev, void *tag) { @@ -153,6 +212,44 @@ static struct sk_buff *rtl8_4t_tag_xmit(struct sk_buff *skb, return skb; } +static void rtl8_4ap_write_tag(struct sk_buff *skb, struct net_device *dev, + void *tag) +{ + u16 pmask = dsa_xmit_port_mask(skb, dev); + __be16 tag16[RTL8_4_TAG_LEN / 2]; + u16 pmask_low, pmask_high; + + /* Set Realtek EtherType */ + tag16[0] = htons(ETH_P_REALTEK); + + pmask_low = FIELD_GET(RTL8_4AP_RX_PORTMASK_LOW, pmask); + /* Set Protocol; set low forwarding port mask */ + tag16[1] = htons(FIELD_PREP(RTL8_4_PROTOCOL, RTL8_4_PROTOCOL_RTL9607C) | + FIELD_PREP(RTL8_4AP_RX_PORTMASK_LOW, pmask_low)); + + pmask_high = FIELD_GET(RTL9607C_RX_PORTMASK_HIGH, pmask); + /* set high forwarding port mask, KEEP, LEARN_DIS and DIRTX */ + tag16[2] = htons(FIELD_PREP(RTL8_4AP_RX_PORTMASK_HIGH, pmask_high) | + RTL8_4_LEARN_DIS | RTL8_4_KEEP | RTL8_4AP_DIRTX); + + /* Zero EXTSPA, PPPOE_ACT/IDX and PON_STREAM_ID */ + tag16[3] = 0; + + memcpy(tag, tag16, RTL8_4_TAG_LEN); +} + +static struct sk_buff *rtl8_4ap_tag_xmit(struct sk_buff *skb, + struct net_device *dev) +{ + skb_push(skb, RTL8_4_TAG_LEN); + + dsa_alloc_etype_header(skb, RTL8_4_TAG_LEN); + + rtl8_4ap_write_tag(skb, dev, dsa_etype_header_pos_tx(skb)); + + return skb; +} + static int rtl8_4_read_tag(struct sk_buff *skb, struct net_device *dev, void *tag) { @@ -242,6 +339,60 @@ static struct sk_buff *rtl8_4t_tag_rcv(struct sk_buff *skb, return skb; } +static int rtl8_4ap_read_tag(struct sk_buff *skb, struct net_device *dev, + void *tag) +{ + __be16 tag16[RTL8_4_TAG_LEN / 2]; + u16 etype; + u8 reason; + u8 proto; + u8 port; + u8 dst_pmask; + bool is_lut; + + memcpy(tag16, tag, RTL8_4_TAG_LEN); + + /* Parse Realtek EtherType */ + etype = ntohs(tag16[0]); + if (unlikely(etype != ETH_P_REALTEK)) { + dev_warn_ratelimited(&dev->dev, + "non-realtek ethertype 0x%04x\n", etype); + return -EPROTO; + } + + /* Parse Protocol */ + proto = FIELD_GET(RTL8_4_PROTOCOL, ntohs(tag16[1])); + if (unlikely(proto != RTL8_4_PROTOCOL_RTL9607C)) { + dev_warn_ratelimited(&dev->dev, + "unknown realtek protocol 0x%02x\n", proto); + return -EPROTO; + } + + /* Parse REASON */ + reason = FIELD_GET(RTL8_4_REASON, ntohs(tag16[1])); + + /* Parse TX (switch->CPU) */ + port = FIELD_GET(RTL8_4_TX, ntohs(tag16[2])); + skb->dev = dsa_conduit_find_user(dev, 0, port); + if (!skb->dev) { + dev_warn_ratelimited(&dev->dev, + "could not find user for port %d\n", port); + return -ENOENT; + } + + /* Parse destination port mask */ + dst_pmask = FIELD_GET(RTL8_4AP_DST_PMASK, ntohs(tag16[3])); + + is_lut = reason == RTL8_4AP_REASON_LUT; + if (!is_lut && reason != RTL8_4AP_REASON_FLOOD) { + dev_warn_ratelimited(&dev->dev, "Unknown reason code: %d\n", reason); + } else if (!is_lut || (dst_pmask & RTL8_4AP_DST_CPU_MASK)) { + dsa_default_offload_fwd_mark(skb); + } + + return 0; +} + /* Ethertype version */ static const struct dsa_device_ops rtl8_4_netdev_ops = { .name = "rtl8_4", @@ -268,9 +419,23 @@ DSA_TAG_DRIVER(rtl8_4t_netdev_ops); MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_RTL8_4T, RTL8_4T_NAME); +/* Ethertype RTL9607C version */ +static const struct dsa_device_ops rtl8_4ap_netdev_ops = { + .name = RTL8_4AP_NAME, + .proto = DSA_TAG_PROTO_RTL8_4AP, + .xmit = rtl8_4ap_tag_xmit, + .rcv = rtl8_4ap_tag_rcv, + .needed_headroom = RTL8_4_TAG_LEN, +}; + +DSA_TAG_DRIVER(rtl8_4ap_netdev_ops); + +MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_RTL8_4AP, RTL8_4AP_NAME); + static struct dsa_tag_driver *dsa_tag_drivers[] = { &DSA_TAG_DRIVER_NAME(rtl8_4_netdev_ops), &DSA_TAG_DRIVER_NAME(rtl8_4t_netdev_ops), + &DSA_TAG_DRIVER_NAME(rtl8_4ap_netdev_ops), }; module_dsa_tag_drivers(dsa_tag_drivers); -- 2.56.1