Skip to contentSkip to conversation

net: dsa: realtek: rtl8365mb: add support for RTL8367S-VB

PATCH Superseded Mieczyslaw Nalewaj 4 participants 31 messages Nov 19 – Nov 24 1 message not in the archive

Subsystems (5)

v12 of 13 Superseded Latest is v13 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

v12 cover net: dsa: realtek: rtl8365mb: add support for RTL8367S-VB

This series adds support for the RTL8367S-VB (chip ID 0x6642) to the rtl8365mb driver. The chip belongs to a new "family D" that differs from the existing family C in its VLAN and L2 table layouts, speed/RGMII configuration and SerDes (SDS13) handling.

Patch 1 documents the chip in the devicetree binding.
Patch 2 adds the chip family infrastructure, with the per-family data (init jam table) in struct rtl8365mb_family_info (no functional change).
Patch 3 moves the external interface force-mode configuration behind the family info (no functional change).
Patches 4-5 add the port speed and RGMII mode configuration for family D. Patch 6 moves the VLAN 4k table accessors behind the family info (no functional change).
Patch 7 adds the VLAN 4k table access (dynamically selecting the IVL learning mode from the filtering state of the user ports for family D only).
Patch 8 refactors the PVID handling behind the family info (no functional change).
Patch 9 adds the raw-VID PVID handling for family D.
Patch 10 adds SDS13 PCS support.
Patch 11 refactors the family C L2 MAC handling by introducing shared pack/unpack helpers and reaching the family C serializers through function pointers in the family info (no functional change). Patch 12 makes the L2 (FDB/MDB) table access work on family D, which has a 5-word entry layout, narrower table access fields and no EFID, and where a VLAN-unaware bridge (VID 0) is handled with an SVL key. Patch 13 adds the RTL8367S-VB chip table entry. It comes last, so that no intermediate commit exposes a family D chip with incomplete handling and the series stays bisectable.

Family C's functional behaviour is unchanged. The L2 table access and FDB/MDB code is shared; the family D handling is selected at runtime through the family info and rtl8365mb_is_d() (patch 12). The RTL8367S-VB has 8 ports, described by port_mask in its chip info (patch 13). On family D, FDB/MDB offload is available, but there is no per-bridge FDB isolation (no EFID), so only one bridge is offloaded (max_num_bridges = 1). Further bridges are forwarded in software and isolated by the port isolation masks only (patch 12). Standalone ports, software-bridged ports and the offloaded VLAN-unaware bridge share FID 0 in the LUT.

Tested on a TP-Link Archer AX55 v1 (RTL8367S-VB, CPU port 6 over HSGMII (2500base-x) to an IPQ5018, with the UNIPHY mode sequence run at GMAC probe) with bridge VLAN filtering and per-port PVIDs, and in a reboot loop (16 boots, none broken, with traffic through the CPU port and no FCS or symbol errors), by Oleg Gavrilov.

Tested on family D by Gustavo Foletto Mora on a TP-Link EX511 v2 (RTL8367S-VB, CPU port 6 over 1G SGMII to an IPQ5018) on a live network, with a VLAN-aware bridge (tagged trunk with VIDs 10-40, access ports on VIDs 10 and 20) and a VLAN-unaware one: VLAN table and PVIDs, tagged and untagged traffic through the CPU port, VLAN isolation, FDB and MDB entries, VLAN add/delete churn, moving a port to a second bridge, traffic in the switch and through the CPU port, a conduit down/up and reboots, with no FCS, symbol, drop, fragment or jabber errors on the checked ports.

Tested on family D by tutzulyk on a TP-Link Archer AX53 v1 (RTL8367S-VB, CPU port 6 over HSGMII to an IPQ5018) with a bridge (br-lan, with a VLAN 99 interface on top) over LAN ports 1 and 4, with several gigabytes of traffic through the CPU port and no RX/TX errors on the checked ports.

Regression-tested on family C by Stanislaw Pal on a TP-Link Archer AX55 v1 (RTL8367S, CPU port 6 over a 2500base-x fixed link to an IPQ5018), on a tree that also carries an 802.1Q-based tagger for this switch:
three boots (after sysupgrade, a reboot and a cold start), a further run of 23 boots (20 reboots, 3 power cycles, none broken, with the UNIPHY mode sequence run at GMAC probe), and traffic between a LAN client and an 802.11s mesh in both directions, with no FCS errors, drops or driver warnings. Family D paths are not exercised on that chip.

Not covered: RGMII and real Wi-Fi stations.

---
v12:
- rebased on the current net-next, which describes the available ports with port_mask in struct rtl8365mb_chip_info
- 2/13, 3/13: drop num_ports from struct rtl8365mb_family_info and the num_ports use in rtl8365mb_detect(), as the ports are now described by port_mask; reword the commit message
- 7/13: track the active 4K VLAN entries in a vlan_4k_used bitmap, so rtl8365mb_d_vlan_4k_refresh_ivl() visits only the entries in use instead of all 4094 VIDs (about 5 s per vlan_filtering toggle before, 20-30 ms with the bitmap, measured by Gustavo Foletto Mora); if rewriting IVL_EN fails midway, restore the entries already rewritten (best effort); the Reviewed-by and Tested-by tags stay dropped, as the update code changed; entries that were already in the table before the driver loaded are not visited
- 8/13: reword the comment on the family C PVID reset: family C is left as it was before family D support, its PVID registers are not touched at setup
- 9/13: add the missing kernel-doc markers and parameter descriptions

    to rtl8365mb_d_vlan_port_get_pvid(), rtl8365mb_d_vlan_pvid_port_set()
    and rtl8365mb_d_vlan_pvid_port_clear(); reword the comment in
    rtl8365mb_vlan_setup(), as the PVID is only reset where the chip
    needs it

- 10/13: clarify the comment on RTL8365MB_BYPASS_LINE_RATE_REG for family D (port 5 is not an external port on the RTL8367S-VB), and state in the commit message that the register layout is the same as in the vendor RTL8367D API
- 12/13: fix the max_num_bridges comment and commit message (a bridge that already has a number from another switch can still be offloaded here), mention static multicast entries in the FID 0 paragraph, and explain why a per-bridge FID from the VLAN 4K entries does not help. Giving the offloaded bridge its own FID (FID 1) was tried and
dropped: it only works for bridges whose ports have a PVID, i.e. a VLAN 4K entry carrying the FID. A bridge without VLANs (the default br-lan) is classified into FID 0, so the static entries written with FID 1 no longer match what it learns, and with fdb_isolation the standalone ports' host entries in FID 0 shadow its traffic. FID 0 stays shared as described in the commit message, which is a known limitation of the chip without EFID
- 13/13: describe the ports of the RTL8367S-VB with .port_mask instead of a family D port count and set .num_tx_queues, as required after the rebase; reword the commit message, which now says that the init jam table is the RTL8367C one and has not been compared with the vendor RTL8367D initialization; num_tx_queues is 8 as for the other chips and has not been checked against the family D vendor code

v11: https://lore.kernel.org/netdev/[email protected]/
- 7/13: add rtl8365mb_d_vlan_4k_refresh_ivl() to update IVL_EN across active 4K VLAN entries when a vlan_filtering change flips the switch-wide filtering state; drop Reviewed-by and Tested-by tags as this adds a new scan path
- 8/13 (new): move the PVID get/reset/set/clear helpers behind struct rtl8365mb_family_info, the existing code becoming the family C implementation; no functional change (Luiz)
- 9/13: add the family D PVID get/reset/set/clear implementations and call vlan_port_reset_pvid() through struct rtl8365mb_family_info instead of using an rtl8365mb_is_d() check; drop Reviewed-by and Tested-by tags as the PVID path was reworked
- 10/13: note in a comment that the DW8051 reset/enable bits in CHIP_RESET and MISC_CFG0 are identical on family D in the vendor SDK
- 12/13: clarify in the comment on max_num_bridges = 1 that DSA allocates bridge numbers system-wide
- 13/13: wire up the family D PVID callbacks in rtl8365mb_family_d, make rtl8365mb_d_ext_config_forcemode() static and drop its declaration from rtl8365mb.h
- Added a test report from tutzulyk on family D (RTL8367S-VB); no Tested-by tag, as no real name and e-mail were provided
- Added a new family C regression run from Stanislaw Pal (Archer AX55

    v1, RTL8367S): 23 boots, none broken
  - Added Tested-by from Oleg Gavrilov on 2-4, 6 and 10-13 (family D,
    Archer AX55 v1, RTL8367S-VB, 2500base-x): 16 of 16 good boots

- Dropped Tested-by from Stanislaw Pal on 3 and 6, as these patches were added after his test

v10: https://lore.kernel.org/netdev/[email protected]/
- 8/11 of v9 (SerDes re-latch): dropped. Johan Alvarado traced the symptom to the SoC side: the bootloader hands the UNIPHY over in SGMII and the out-of-tree qca-uniphy PCS programs SGMII+ only from pcs_config() at the first open of the conduit, about two seconds after the switch brought its SerDes up in HSGMII at DSA setup, so the switch receiver trains against the wrong line rate. Running the UNIPHY mode sequence at GMAC probe, before the switch probes, fixes it with no change in rtl8365mb (0 of 32 broken boots, versus 18 of 51). As neither dwmac-ipq5018 nor pcs-qca-uniphy is in mainline, the workqueue, the extra locks and the reboot notifier are not needed in this driver (Johan, Alvin)
- 2/12: say "family-specific" in the comment on the init jam table
- 3/12 (new): move ext_config_forcemode() behind struct rtl8365mb_family_info, the existing code becoming the family C implementation; no functional change (Alvin)
- 4/12: only add the family D force-mode implementation, instead of is_d() branches in the shared code; no functional change; say in the commit message why the function is not static until the last patch
- 5/12: log an error instead of a warning when RGMII is not available on port 7, and say in the commit message that port 7 then has no supported interface
- 6/12 (new): move the VLAN 4k table accessors behind struct rtl8365mb_family_info, the existing code becoming the family C implementation; no functional change (Alvin)
- 7/12: only add the family D VLAN 4k accessors, instead of is_d() branches in the shared code; on family D enable IVL while any user port has VLAN filtering enabled, independent of the port being configured (so the CPU port cannot reset it); document that IVL_EN (bit 3, versus bit 14 on family C) is refreshed on the next port_vlan_add/del of the VID, not on a vlan_filtering change; say in the commit message why the accessors are not static until the last patch
- 9/12: do not advertise 10 and 100 Mbit/s on the family D SerDes port, as no SerDes rate is programmed for them
- 11/12: do not delete a dynamic unicast entry on family D; correct the commit message about standalone ports (DSA programs no entries for them without fdb_isolation) and describe that FID 0 is shared; name the vendor function that writes the LUT aging value (dal_rtl8367d_l2_init); say in the commit message why the family D functions are not static until the last patch
- 2/12 and 12/12: restored Reviewed-by from Linus, reconfirmed on the list after v9

v9: https://lore.kernel.org/netdev/[email protected]/
- 2/11: add struct rtl8365mb_family_info holding per-family data

    (port count, init jam table); use num_ports from it in
    rtl8365mb_detect(); rename the port count constant to
    RTL8365MB_C_MAX_NUM_PORTS (Alvin)
  - 3/11: drop the FORCE_SPEED_WIDTH macro and add a mask for the most
    significant speed bit (Alvin)
  - 5/11: restructure the family D checks when unpacking the untag
    field; no functional change
  - 7/11: update the kernel-doc of sds_supported and the commit message
    for family D always setting it; note in a comment that the register
    and field names follow the vendor API
  - 8/11:
    - use explicit mutex_lock()/mutex_unlock() instead of
      guard(mutex); no functional change
    - arm the re-latch only for 2500base-x on a CPU port, and say
      so in the commit message; ignore conduit state changes of other
      switches in the tree
  - 9/11: reach the family C L2 serialisers and entry size through
    function pointers in the family info (Alvin)
  - 10/11:
    - add the family D L2 serialisers to the family info, drop
      RTL8365MB_D_L2_MAX_PORT and the port checks, as the core never
      passes a port above num_ports - 1 (Alvin)
    - use an SVL key (IVL=0, FID=0) for VID 0, so static unicast
      and multicast entries match the learned ones in a VLAN-unaware
      bridge; they were written with IVL set and never replaced the
      learned entries (reported and tested by Gustavo Foletto Mora)
    - offload only one bridge on family D (max_num_bridges = 1),
      as the LUT cannot tell bridges apart without EFID; further bridges
      fall back to software forwarding
    - do not delete a unicast entry on family D if the entry
      found belongs to another port; update the l2_lock and EFID
      comments; note that the LUT aging value is undocumented
  - 11/11: describe the 8 ports of the RTL8367S-VB in its family info
    instead of a family check in rtl8365mb_detect(); mention the L2/LUT
    and table access differences in the family D overview comment
  - Dropped the Reviewed-by tags of Linus and Luiz from 2/11 and the
    one of Linus from 11/11, as these patches changed substantially.
    Linus, Luiz, could you please take another look? Tags on the other
    patches are unchanged.
  - Added Tested-by tags: Gustavo Foletto Mora on 2, 3, 5, 6, 7, 9, 10,
    11 and Stanislaw Pal on 2, 3, 7, 8, 9, 10

v8: https://lore.kernel.org/netdev/[email protected]/
- 2/11: declare the rtl8365mb_is_d() helper as a global inline function in the new header
- 9/10: split into two patches to improve structure and address reviewer comments:
- 9/11 (new): introduce shared MAC pack/unpack helpers and refactor family C serializers without functional changes
- 10/11: drop the confusing _any() suffixes in favor of clean symmetric dispatchers, switch to the global rtl8365mb_is_d() helper, and fix the memset size in family D serializers

v7: https://lore.kernel.org/netdev/[email protected]/
- 3/10, 6/10: note that the family D path is unreachable until the last patch
- 4/10: program EXT_TXC_DLY, the pin mux and the SerDes 1 disable before selecting RGMII; warn when RGMII is disabled because MAC4 owns EXT1
- 8/10: act only on the conduit of the CPU port that carries the SerDes; queue the work with schedule_delayed_work() and rename the devres action to rtl8365mb_sds_relatch_disable()
- 9/10: new, make L2/LUT access work on family D (5-word entries, narrower table access fields, LUT init, no FDB isolation)
- 10/10: update the NET_DSA_REALTEK_RTL8365MB help text

v6: https://lore.kernel.org/netdev/[email protected]/
- 4/9: do not advertise RGMII for port 7 when MAC4 owns EXT1, instead of returning -EBUSY from mac_config(), which phylink ignores
- 5/9: take IVL_EN from vlan4k->ivl_en and leave SVLAN_CHK_IVL_SVL at 0, as the vendor API does
- 7/9: pcs_get_state(): keep phylink's speed and duplex for SGMII and never report the link up with an unknown speed
- 8/9: start the re-latch work when the conduit comes up and stop it when it goes down (.conduit_state_change); serialize it against pcs_config() with sds_cfg_lock; disable it for good on shutdown and unbind

v5: https://lore.kernel.org/netdev/[email protected]/
- 1/9: fix the subject
- 4/9: refuse RGMII on EXT1 with -EBUSY when it is owned by MAC4, before touching any EXT1 register
- 5/9: drop the unverified rationale for forcing SVLAN_CHK_IVL_SVL, say that the vendor API leaves it at 0, and note that the family D paths are not reachable until the last patch
- 6/9: init prev_accepted_frame to avoid a maybe-uninitialized warning
- 7/9: comment the write of the whole RX disable field, as in the vendor sequence; fix two comments that still credit pcs_link_up() on family D
- 8/9: cancel the re-latch work from a reboot notifier instead of checking the driver data; fix the RESTORE_TRIES comment and do not sleep after the last failed restore attempt
- 9/9: fix the description of the external interface indices. The v4 changelog said that only HSGMII is exposed; that was wrong, SGMII is still exposed

v4: https://lore.kernel.org/netdev/[email protected]/
- 1/9: reword the commit message (support is added by the series)
- 3/9: document the per-port force enable register
- 5/9: document both forced IVL bits, update stale comments
- 6/9: clear the family D PVID registers at setup
- 7/9: do not override the forced SGMII speed in pcs_get_state(), update stale comments, note that the patch is preparatory
- 8/9: remember a failed restore and retry it first; stop the work after shutdown (driver data cleared)
- 9/9: expose HSGMII only on the SerDes port, update the SerDes interface comment

v3: https://lore.kernel.org/netdev/[email protected]/
- add a dt-bindings patch (1/9): RTL8367S-VB listed under

    realtek,rtl8365mb

- add chip family infrastructure as its own patch (2/9), no functional change
- squash the family D PVID getter and the PVID set/clear patches into one (6/9), so the read and write paths use the same register layout at every point of the series
- add the RTL8367S-VB chip table entry last (9/9), after the family D speed, RGMII, VLAN and PCS support, so no intermediate commit can reach the chip with incomplete handling (reported by the automated review)
- 6/9: fix the commit message (port p's write lands in port p >> 1) and update the stale kernel-doc and file comments
- 8/9: start the re-latch work only for 2500base-x, cancel it from .pcs_disable, from pcs_config() and via a devres action; retry the SDS_MISC restore and come back soon if it fails; rewrite the commit message to match the code (reported by the automated review)
- 9/9: document family D in the file header comment and in the learn limit comment (limit confirmed against the Realtek vendor API)

v2: https://lore.kernel.org/netdev/[email protected]/
- 2/8: mask r_speed to the width of the FORCE_SPEED field before passing it to FIELD_PREP(), so that the family D 2500M value (5) cannot trip the compile-time range check; bit 2 still goes to FORCE_SPEED2 (reported by the automated review).
- 4/8: the commit message now explains why EXT_TXC_DLY[5:3] is cleared for RGMII on EXT1: the vendor RGMII setup does it, and the init jam table leaves the field at 2, which would add an extra TX delay on top of tx-internal-delay-ps. Add a comment describing the EXT_TXC_DLY layout (Andrew Lunn's review).
- 8/8: document the new struct rtl8365mb members in the kernel-doc comment (sds_lock, sds_relatch, sds_relatch_count, sds_misc_target_val), which fixes the kernel-doc warnings.
- 1/8, 3/8, 5/8, 6/8, 7/8: no changes.

v1: https://lore.kernel.org/netdev/[email protected]/

Mieczyslaw Nalewaj (13):
dt-bindings: net: dsa: realtek: add RTL8367S-VB
net: dsa: realtek: rtl8365mb: add chip family infrastructure
net: dsa: realtek: rtl8365mb: refactor forcemode handling
net: dsa: realtek: rtl8365mb: set speed for family D
net: dsa: realtek: rtl8365mb: set RGMII mode for family D
net: dsa: realtek: rtl8365mb: refactor VLAN 4k handling
net: dsa: realtek: rtl8365mb: set and get vlan 4k for family D
net: dsa: realtek: rtl8365mb: refactor PVID handling
net: dsa: realtek: rtl8365mb: use raw VID for PVID on family D
net: dsa: realtek: rtl8365mb: add family D SDS13 PCS support
net: dsa: realtek: rtl8365mb: refactor L2 MAC handling
net: dsa: realtek: rtl8365mb: make L2/LUT access work on family D
net: dsa: realtek: rtl8365mb: add support for RTL8367S-VB

 .../devicetree/bindings/net/dsa/realtek.yaml  |   2 +-
 drivers/net/dsa/realtek/Kconfig               |   3 +-
 drivers/net/dsa/realtek/realtek.h             |  11 +-
 drivers/net/dsa/realtek/rtl8365mb.h           |  51 ++
 drivers/net/dsa/realtek/rtl8365mb_l2.c        | 251 +++++--
 drivers/net/dsa/realtek/rtl8365mb_l2.h        |  18 +
 drivers/net/dsa/realtek/rtl8365mb_main.c      | 676 +++++++++++++++---
 drivers/net/dsa/realtek/rtl8365mb_table.c     |  44 +-
 drivers/net/dsa/realtek/rtl8365mb_vlan.c      | 488 ++++++++++++-
 drivers/net/dsa/realtek/rtl8365mb_vlan.h      |  26 +
 drivers/net/dsa/realtek/rtl83xx.c             |   5 +-
 11 files changed, 1370 insertions(+), 205 deletions(-)
 create mode 100644 drivers/net/dsa/realtek/rtl8365mb.h
Signature · 1 line
2.53.0
#2 lore raw

PATCH v12 1/13 dt-bindings: net: dsa: realtek: add RTL8367S-VB

The RTL8367S-VB (chip ID 0x6642) is supported by the rtl8365mb driver with the changes that follow in this series. It is identified by its chip ID register, so it does not need a compatible string of its own. List it under realtek,rtl8365mb.

---
 Documentation/devicetree/bindings/net/dsa/realtek.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/devicetree/bindings/net/dsa/realtek.yaml +1 -1
index 473facd..ca775f6 100644
@@ -43,7 +43,7 @@ properties:
       realtek,rtl8365mb:
         Use with models RTL8363NB, RTL8363NB-VB, RTL8363SC, RTL8363SC-VB,
         RTL8364NB, RTL8364NB-VB, RTL8365MB, RTL8366SC, RTL8367RB-VB, RTL8367S,
-        RTL8367SB, RTL8370MB, RTL8310SR
+        RTL8367S-VB, RTL8367SB, RTL8370MB, RTL8310SR
       realtek,rtl8366rb:
         Use with models RTL8366RB, RTL8366S
 
Signature · 1 line
2.53.0
#3 lore raw

PATCH v12 2/13 net: dsa: realtek: rtl8365mb: add chip family infrastructure

In reply to Mieczyslaw Nalewaj

Add enum rtl8365mb_family and struct rtl8365mb_family_info, which holds the data shared by all chips of one family: the family id and the init jam table. struct rtl8365mb_chip_info now points to it through a family_info member, and all existing chips use the RTL8365MB_FAMILY_C instance. rtl8365mb_get_family_info() and rtl8365mb_is_d() are declared in a new rtl8365mb.h so that the VLAN code can use them too.

The available ports of a chip are already described by port_mask in struct rtl8365mb_chip_info, so the family info does not carry a port count.

RTL8365MB_FAMILY_D is defined here but no chip uses it yet; it is needed by the following patches, which add family D handling for chips whose register layout differs from the existing ones.

No functional change.

---
 drivers/net/dsa/realtek/rtl8365mb.h      | 28 ++++++++++++++
 drivers/net/dsa/realtek/rtl8365mb_main.c | 47 ++++++++++++++----------
 2 files changed, 56 insertions(+), 19 deletions(-)
 create mode 100644 drivers/net/dsa/realtek/rtl8365mb.h
drivers/net/dsa/realtek/rtl8365mb.h new file +28 -0
new file mode 100644
index 0000000..7b0c710
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _RTL8365MB_H
+#define _RTL8365MB_H
+
+#include "realtek.h"
+
+enum rtl8365mb_family {
+	RTL8365MB_FAMILY_C,
+	RTL8365MB_FAMILY_D,
+};
+
+struct rtl8365mb_jam_tbl_entry;
+
+struct rtl8365mb_family_info {
+	enum rtl8365mb_family family;
+	const struct rtl8365mb_jam_tbl_entry *jam_table;
+	size_t jam_size;
+};
+
+const struct rtl8365mb_family_info *
+rtl8365mb_get_family_info(struct realtek_priv *priv);
+
+static inline bool rtl8365mb_is_d(struct realtek_priv *priv)
+{
+	return rtl8365mb_get_family_info(priv)->family == RTL8365MB_FAMILY_D;
+}
+
+#endif /* _RTL8365MB_H */
drivers/net/dsa/realtek/rtl8365mb_main.c +28 -19

136 lines not on this page · raw message

Signature · 1 line
2.53.0
#4 lore raw

PATCH v12 3/13 net: dsa: realtek: rtl8365mb: refactor forcemode handling

In reply to Mieczyslaw Nalewaj

Move the external interface force-mode configuration behind struct rtl8365mb_family_info, so that family D can provide its own versions without is_d() checks in the shared code. The existing code becomes the family C implementation and is otherwise unchanged. The mac_link_up() and mac_link_down() callbacks call it through the family info.

No functional change.

---
 drivers/net/dsa/realtek/rtl8365mb.h      |  3 ++
 drivers/net/dsa/realtek/rtl8365mb_main.c | 44 ++++++++++++++----------
 2 files changed, 29 insertions(+), 18 deletions(-)
drivers/net/dsa/realtek/rtl8365mb.h +3 -0
index 7b0c710..390ff0a 100644
@@ -15,6 +15,9 @@ struct rtl8365mb_family_info {
 	enum rtl8365mb_family family;
 	const struct rtl8365mb_jam_tbl_entry *jam_table;
 	size_t jam_size;
+	int (*ext_config_forcemode)(struct realtek_priv *priv, int port,
+				    bool link, int speed, int duplex,
+				    bool tx_pause, bool rx_pause);
 };
 
 const struct rtl8365mb_family_info *
drivers/net/dsa/realtek/rtl8365mb_main.c +26 -18

115 lines not on this page · raw message

Signature · 1 line
2.53.0
#5 lore raw

PATCH v12 4/13 net: dsa: realtek: rtl8365mb: set speed for family D

In reply to Mieczyslaw Nalewaj

On family C hardware, forcing a 2.5 Gbps link speed requires relying strictly on the HSGMII SerDes configuration block, while forcing a dummy 1 Gbps value inside the standard digital interface register. Family D introduces a dedicated hardware link speed value (5) for 2500M. The speed bitfield width has been expanded to 3 bits, splitting the most significant bit into a new separate register field (FORCE_SPEED2), which maps directly to a distinct per-port digital interface force layout.

On family D the forced-mode configuration (link, duplex, pause, speed) is written to a per-port register at 0x12c0 + port instead of the per-extint register. The bit positions of TXPAUSE, RXPAUSE, LINK, DUPLEX and the low two speed bits are the same as on family C; the upper speed bits go to bits 13:12 (FORCE_SPEED2), so FORCE_EN (bit 12 on family C) is not set. A second per-port register at 0x12c8 + port enables the forced mode: the vendor RTL8367D API writes 0xFFFF there when the MAC is forced and 0 otherwise. This driver always forces the MAC, as on family C, so it writes 0xFFFF on every call, including link down.

Add the family D implementation as rtl8365mb_d_ext_config_forcemode(). The shared code reaches it through the ext_config_forcemode pointer in struct rtl8365mb_family_info, so it needs no is_d() check.

Nothing points to it until the family D info is added together with the chip table entry in the last patch. Until then it is not static and is declared in rtl8365mb.h, so that the build does not warn about an unused function.

---
 drivers/net/dsa/realtek/rtl8365mb.h      |   4 +
 drivers/net/dsa/realtek/rtl8365mb_main.c | 110 +++++++++++++++++++++++
 2 files changed, 114 insertions(+)
drivers/net/dsa/realtek/rtl8365mb.h +4 -0
index 390ff0a..a9bf4f2 100644
@@ -23,6 +23,10 @@ struct rtl8365mb_family_info {
 const struct rtl8365mb_family_info *
 rtl8365mb_get_family_info(struct realtek_priv *priv);
 
+int rtl8365mb_d_ext_config_forcemode(struct realtek_priv *priv, int port,
+				     bool link, int speed, int duplex,
+				     bool tx_pause, bool rx_pause);
+
 static inline bool rtl8365mb_is_d(struct realtek_priv *priv)
 {
 	return rtl8365mb_get_family_info(priv)->family == RTL8365MB_FAMILY_D;
drivers/net/dsa/realtek/rtl8365mb_main.c +110 -0

128 lines not on this page · raw message

Signature · 1 line
2.53.0
#6 lore raw

PATCH v12 5/13 net: dsa: realtek: rtl8365mb: set RGMII mode for family D

In reply to Mieczyslaw Nalewaj

On family D, RGMII on extension interface 1 needs three things that the other families do not: the EXT1 RGMII TX clock delay field in EXT_TXC_DLY (0x13f9, bits [5:3]) must be cleared, the pin mux in the top-level configuration register must be set up, and SerDes 1, which shares the pins, must be disabled.

The vendor RGMII setup for EXT1 clears the RGMII field of EXT_TXC_DLY (0x13f9, bits [5:3]) in addition to programming TXDELAY in RGMXF. Do the same. The init jam table writes 0x0090 to this register, which leaves the field at 2, so without the clear an extra TX delay would be applied on top of tx-internal-delay-ps. Clearing it makes tx-internal-delay-ps the only source of TX delay.

If the internal MAC4 block occupies extension 1, do not advertise RGMII for port 7 in phylink_get_caps(), so the configuration is refused before any EXT1 register is touched. This mirrors the vendor RTL8367D API, which returns an error for RGMII on port 7 when UTP port 4 uses the RGMII interface. The driver logs an error naming the conflict. RGMII is the only interface of port 7 this driver implements, so port 7 then has no supported interface: phylink_create() fails for it, and if it is a CPU port the switch does not probe.

When MAC4 does not own the pins, bind the RGMII/MII pins to MAC7 and disable SerDes 1, which shares them. The TX delay field, the pin mux and the SerDes 1 disable are all programmed before RGMII is selected, so the shared pins are never driven by RGMII and SerDes 1 at the same time.

The family D branch is not reachable until the chip table entry is added in the last patch.

---
 drivers/net/dsa/realtek/rtl8365mb_main.c | 70 +++++++++++++++++++++++-
 1 file changed, 68 insertions(+), 2 deletions(-)
drivers/net/dsa/realtek/rtl8365mb_main.c +68 -2
index 05db3dd..d59f15c 100644
@@ -334,6 +334,12 @@
 #define   RTL8365MB_SDS_OPTION_ARM_KEY		0x0249
 #define RTL8365MB_SDS_OPTION_REG		0x13C1
 
+#define RTL8365MB_D_SDS_MISC_MODE_FIELD_MASK		GENMASK(4, 0)
+/* Shared "disable" encoding for both SDS_MISC's and SDS1_MISC0's
+ * 5-bit mode fields.
+ */
+#define RTL8365MB_D_PORT_SDS_MODE_DISABLE		0x1f
+
 /* Embedded DW8051 microcontroller control registers. The microcontroller
  * can run firmware to manage the SerDes link, but this driver keeps it in
  * reset and disabled: phylink already performs the link management that
@@ -466,6 +472,20 @@
 #define   RTL8365MB_PORT_MISC_CFG_VLAN_EGRESS_MODE_MASK		GENMASK(5, 4)
 #define   RTL8365MB_PORT_MISC_CFG_CONGESTION_SUSTAIN_TIME_MASK	GENMASK(3, 0)
 
+/* EXT_TXC_DLY holds a 3-bit TX clock delay per external interface, for
+ * RGMII ([2:0] EXT0, [5:3] EXT1, [8:6] EXT2) and separately for GMII.
+ * Only the EXT1 RGMII field is used here, and it is cleared in RGMII
+ * mode so that tx-internal-delay-ps is the only TX delay applied.
+ */
+#define RTL8365MB_D_REG_EXT_TXC_DLY				0x13f9
+#define   RTL8365MB_D_EXT1_RGMII_TX_DLY_MASK			GENMASK(5, 3)
+
+#define RTL8365MB_D_REG_TOP_CON0				0x1d70
+#define   RTL8365MB_D_MAC7_SEL_EXT1_MASK			BIT(13)
+#define   RTL8365MB_D_MAC4_SEL_EXT1_MASK			BIT(12)
+
+#define RTL8365MB_D_REG_SDS1_MISC0				0x1d78
+
 /**
  * enum rtl8365mb_vlan_egress_mode - port VLAN egress mode
  * @RTL8365MB_VLAN_EGRESS_MODE_ORIGINAL: follow untag mask in VLAN4k table entry
@@ -1283,6 +1303,32 @@ static int rtl8365mb_ext_config_rgmii(struct realtek_priv *priv, int port,
 	if (ret)
 		return ret;
 
+	if (rtl8365mb_is_d(priv) && extint->id == 1) {
+		ret = regmap_update_bits(priv->map,
+					 RTL8365MB_D_REG_EXT_TXC_DLY,
+					 RTL8365MB_D_EXT1_RGMII_TX_DLY_MASK, 0);
+		if (ret)
+			return ret;
+
+		/* Bind the RGMII/MII pins to MAC7. MAC4 does not own them:
+		 * RGMII is not advertised otherwise, see
+		 * rtl8365mb_phylink_get_caps().
+		 */
+		ret = regmap_update_bits(priv->map,
+					 RTL8365MB_D_REG_TOP_CON0,
+					 RTL8365MB_D_MAC7_SEL_EXT1_MASK,
+					 RTL8365MB_D_MAC7_SEL_EXT1_MASK);
+		if (ret)
+			return ret;
+
+		ret = regmap_update_bits(priv->map,
+					 RTL8365MB_D_REG_SDS1_MISC0,
+					 RTL8365MB_D_SDS_MISC_MODE_FIELD_MASK,
+					 RTL8365MB_D_PORT_SDS_MODE_DISABLE);
+		if (ret)
+			return ret;
+	}
+
 	ret = regmap_update_bits(
 		priv->map, RTL8365MB_DIGITAL_INTERFACE_SELECT_REG(extint->id),
 		RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_MASK(extint->id),
@@ -1850,6 +1896,8 @@ static void rtl8365mb_phylink_get_caps(struct dsa_switch *ds, int port,
 		rtl8365mb_get_port_extint(ds->priv, port);
 	struct realtek_priv *priv = ds->priv;
 	struct rtl8365mb *mb = priv->chip_data;
+	u32 data;
+	int ret;
 
 	config->mac_capabilities = MAC_SYM_PAUSE | MAC_ASYM_PAUSE |
 				   MAC_10 | MAC_100 | MAC_1000FD;
@@ -1879,8 +1927,26 @@ static void rtl8365mb_phylink_get_caps(struct dsa_switch *ds, int port,
 	 * which remain unimplemented.
 	 */
 
-	if (extint->supported_interfaces & RTL8365MB_PHY_INTERFACE_MODE_RGMII)
-		phy_interface_set_rgmii(config->supported_interfaces);
+	if (extint->supported_interfaces & RTL8365MB_PHY_INTERFACE_MODE_RGMII) {
+		/* On family D the EXT1 pins are shared with MAC4 (UTP port 4).
+		 * If MAC4 owns them, RGMII on this port cannot work.
+		 */
+		if (rtl8365mb_is_d(priv) && extint->id == 1) {
+			ret = regmap_read(priv->map, RTL8365MB_D_REG_TOP_CON0, &data);
+			if (ret)
+				dev_err(priv->dev,
+					"failed to read TOP_CON0, RGMII on port %d disabled: %pe\n",
+					port, ERR_PTR(ret));
+			else if (data & RTL8365MB_D_MAC4_SEL_EXT1_MASK)
+				dev_err(priv->dev,
+					"port %d: EXT1 is owned by MAC4, RGMII cannot be used\n",
+					port);
+			else
+				phy_interface_set_rgmii(config->supported_interfaces);
+		} else {
+			phy_interface_set_rgmii(config->supported_interfaces);
+		}
+	}
 
 	if (extint->supported_interfaces & RTL8365MB_PHY_INTERFACE_MODE_SGMII &&
 	    mb->sds_supported)
Signature · 1 line
2.53.0
#7 lore raw

PATCH v12 6/13 net: dsa: realtek: rtl8365mb: refactor VLAN 4k handling

In reply to Mieczyslaw Nalewaj

Move the family-specific VLAN 4k table accessors behind struct rtl8365mb_family_info, so that family D can provide its own versions without is_d() checks in the shared code. The existing code becomes the family C implementation and is otherwise unchanged: rename the functions to rtl8365mb_c_vlan_4k_read() and rtl8365mb_c_vlan_4k_write(), export them and call them through the family info.

No functional change.

---
 drivers/net/dsa/realtek/rtl8365mb.h      |  5 +++++
 drivers/net/dsa/realtek/rtl8365mb_main.c |  2 ++
 drivers/net/dsa/realtek/rtl8365mb_vlan.c | 21 ++++++++++++---------
 drivers/net/dsa/realtek/rtl8365mb_vlan.h |  7 +++++++
 4 files changed, 26 insertions(+), 9 deletions(-)
drivers/net/dsa/realtek/rtl8365mb.h +5 -0
index a9bf4f2..be0f49e 100644
@@ -10,6 +10,7 @@ enum rtl8365mb_family {
 };
 
 struct rtl8365mb_jam_tbl_entry;
+struct rtl8365mb_vlan4k;
 
 struct rtl8365mb_family_info {
 	enum rtl8365mb_family family;
@@ -18,6 +19,10 @@ struct rtl8365mb_family_info {
 	int (*ext_config_forcemode)(struct realtek_priv *priv, int port,
 				    bool link, int speed, int duplex,
 				    bool tx_pause, bool rx_pause);
+	int (*vlan_4k_read)(struct realtek_priv *priv, u16 vid,
+			    struct rtl8365mb_vlan4k *vlan4k);
+	int (*vlan_4k_write)(struct realtek_priv *priv,
+			     const struct rtl8365mb_vlan4k *vlan4k);
 };
 
 const struct rtl8365mb_family_info *
drivers/net/dsa/realtek/rtl8365mb_main.c +2 -0
index d59f15c..ed7078e 100644
@@ -756,6 +756,8 @@ static const struct rtl8365mb_family_info rtl8365mb_family_c = {
 	.jam_table = rtl8365mb_init_jam_8365mb_vc,
 	.jam_size = ARRAY_SIZE(rtl8365mb_init_jam_8365mb_vc),
 	.ext_config_forcemode = rtl8365mb_c_ext_config_forcemode,
+	.vlan_4k_read = rtl8365mb_c_vlan_4k_read,
+	.vlan_4k_write = rtl8365mb_c_vlan_4k_write,
 };
 
 /**
drivers/net/dsa/realtek/rtl8365mb_vlan.c +12 -9
index 8d49ffa..566c6bc 100644
@@ -48,12 +48,13 @@
 
 #include "rtl8365mb_vlan.h"
 #include "rtl8365mb_table.h"
+#include "rtl8365mb.h"
 #include <linux/if_bridge.h>
 #include <linux/lockdep.h>
 #include <linux/regmap.h>
 
 /* CVLAN (i.e. VLAN4k) table entry layout, u16[3] */
-#define RTL8365MB_CVLAN_ENTRY_SIZE			3 /* 48-bits */
+#define RTL8365MB_C_CVLAN_ENTRY_SIZE			3 /* 48-bits */
 #define RTL8365MB_CVLAN_ENTRY_D0_MBR_MASK		GENMASK(7, 0)
 #define   RTL8365MB_CVLAN_MBR_LO_MASK			GENMASK(7, 0)
 #define RTL8365MB_CVLAN_ENTRY_D0_UNTAG_MASK		GENMASK(15, 8)
@@ -182,10 +183,10 @@ struct rtl8365mb_vlanmc {
 	u8 meteridx : 6;
 };
 
-static int rtl8365mb_vlan_4k_read(struct realtek_priv *priv, u16 vid,
-				  struct rtl8365mb_vlan4k *vlan4k)
+int rtl8365mb_c_vlan_4k_read(struct realtek_priv *priv, u16 vid,
+			     struct rtl8365mb_vlan4k *vlan4k)
 {
-	u16 data[RTL8365MB_CVLAN_ENTRY_SIZE];
+	u16 data[RTL8365MB_C_CVLAN_ENTRY_SIZE];
 	int val;
 	int ret;
 
@@ -230,10 +231,10 @@ static int rtl8365mb_vlan_4k_read(struct realtek_priv *priv, u16 vid,
 	return 0;
 }
 
-static int rtl8365mb_vlan_4k_write(struct realtek_priv *priv,
-				   const struct rtl8365mb_vlan4k *vlan4k)
+int rtl8365mb_c_vlan_4k_write(struct realtek_priv *priv,
+			      const struct rtl8365mb_vlan4k *vlan4k)
 {
-	u16 data[RTL8365MB_CVLAN_ENTRY_SIZE] = { 0 };
+	u16 data[RTL8365MB_C_CVLAN_ENTRY_SIZE] = { 0 };
 	u16 vid;
 	int val;
 
@@ -282,6 +283,7 @@ rtl8365mb_vlan_4k_port_set(struct dsa_switch *ds, int port,
 			   struct netlink_ext_ack *extack,
 			   bool include)
 {
+	const struct rtl8365mb_family_info *fi;
 	struct realtek_priv *priv = ds->priv;
 	struct rtl8365mb_vlan4k vlan4k = {0};
 	int ret;
@@ -296,7 +298,8 @@ rtl8365mb_vlan_4k_port_set(struct dsa_switch *ds, int port,
 		return -EINVAL;
 	}
 
-	ret = rtl8365mb_vlan_4k_read(priv, vlan->vid, &vlan4k);
+	fi = rtl8365mb_get_family_info(priv);
+	ret = fi->vlan_4k_read(priv, vlan->vid, &vlan4k);
 	if (ret) {
 		dev_err(priv->dev, "Failed to read VLAN 4k table\n");
 		return ret;
@@ -313,7 +316,7 @@ rtl8365mb_vlan_4k_port_set(struct dsa_switch *ds, int port,
 		vlan4k.untag &= ~BIT(port);
 	vlan4k.ivl_en = true; /* always use Independent VLAN Learning */
 
-	ret = rtl8365mb_vlan_4k_write(priv, &vlan4k);
+	ret = fi->vlan_4k_write(priv, &vlan4k);
 	if (ret) {
 		dev_err(priv->dev, "Failed to write VLAN 4k table\n");
 		return ret;
drivers/net/dsa/realtek/rtl8365mb_vlan.h +7 -0
index 27a526b..009b127 100644
@@ -18,6 +18,13 @@ enum rtl8365mb_frame_ingress {
 	RTL8365MB_FRAME_TYPE_UNTAGGED_ONLY,
 };
 
+struct rtl8365mb_vlan4k;
+
+int rtl8365mb_c_vlan_4k_read(struct realtek_priv *priv, u16 vid,
+			     struct rtl8365mb_vlan4k *vlan4k);
+int rtl8365mb_c_vlan_4k_write(struct realtek_priv *priv,
+			      const struct rtl8365mb_vlan4k *vlan4k);
+
 int rtl8365mb_vlan_port_get_pvid(struct realtek_priv *priv, int port,
 				 u16 *pvid);
 int
Signature · 1 line
2.53.0
#8 lore raw

PATCH v12 7/13 net: dsa: realtek: rtl8365mb: set and get vlan 4k for family D

In reply to Mieczyslaw Nalewaj

The hardware structure of 4K VLAN table entries has changed between silicon families. Family D's CVLAN entry is two 16-bit words rather than three: there is no third word extending member/untag past bit 7, and no priority/meter fields at all. The FID field is restricted to a narrower 2-bit width. The chip itself supports both IVL and SVL.

IVL_EN (bit 3, versus bit 14 on family C) follows vlan4k->ivl_en. On family D, rtl8365mb_vlan_4k_port_set() enables it while any user port has VLAN filtering enabled (dsa_port_is_vlan_filtering()), so that static and learned FDB/MDB entries use the same key. Family C keeps IVL always enabled, as before.

When a vlan_filtering change flips this switch-wide state, rtl8365mb_d_vlan_4k_refresh_ivl() updates IVL_EN across the active 4K entries, so existing VLANs, including those programmed before filtering was enabled, switch between SVL and IVL immediately. Changes that leave the state as it is do not touch the table.

The update visits only the VIDs in use, tracked in the vlan_4k_used bitmap in struct realtek_priv. rtl8365mb_vlan_4k_port_set() keeps it up to date under vlan_lock, so a toggle does not read all 4094 entries over the slow management bus (about 5 s per toggle on an RTL8367S-VB; 20-30 ms with the bitmap). The bitmap covers the entries written by this driver:
an entry that was already in the table before the driver loaded is not visited.

Reusing the three-word family C layout on family D would read a third word that does not exist as a distinct table word on family D's die. Whatever data happens to be in that register would be folded into member/untag bits [10:8] on read, and written back on every read-modify-write cycle in rtl8365mb_vlan_4k_port_set(). Give family D its own two-word pack/unpack instead: add rtl8365mb_d_vlan_4k_read() and rtl8365mb_d_vlan_4k_write(). The shared code reaches them through the vlan_4k_read and vlan_4k_write pointers in struct rtl8365mb_family_info, so the pack/unpack code needs no is_d() check.

The two-word layout matches the vendor switch API for this chip family, which writes only 0x0510/0x0511 for a CVLAN entry.

Nothing points to them until the family D info is added together with the chip table entry in the last patch. Until then they are not static and are declared in rtl8365mb_vlan.h, so that the build does not warn about unused functions.

---
 drivers/net/dsa/realtek/realtek.h        |   7 +
 drivers/net/dsa/realtek/rtl8365mb_main.c |  13 ++
 drivers/net/dsa/realtek/rtl8365mb_vlan.c | 165 ++++++++++++++++++++++-
 drivers/net/dsa/realtek/rtl8365mb_vlan.h |   7 +
 4 files changed, 190 insertions(+), 2 deletions(-)
drivers/net/dsa/realtek/realtek.h +7 -0
index dacb780..c166719 100644
@@ -8,6 +8,8 @@
 #ifndef _REALTEK_H
 #define _REALTEK_H
 
+#include <linux/bitmap.h>
+#include <linux/if_vlan.h>
 #include <linux/phy.h>
 #include <linux/platform_device.h>
 #include <linux/gpio/consumer.h>
@@ -65,6 +67,11 @@ struct realtek_priv {
 	 * deleting port VLAN memberships and PVID configurations.
 	 */
 	struct mutex		vlan_lock;
+	/* VIDs with a non-empty 4K VLAN entry, protected by vlan_lock. Lets
+	 * a switch-wide update visit only the entries in use instead of
+	 * reading all 4094 over the slow management bus.
+	 */
+	DECLARE_BITMAP(vlan_4k_used, VLAN_N_VID);
 	/* l2_lock is used to prevent concurrent modifications of L2 table
 	 * entries while another function is reading it. l2_(add,del)_mc
 	 * is an example that first read current table entry and then
drivers/net/dsa/realtek/rtl8365mb_main.c +13 -0
index ed7078e..2269ac9 100644
@@ -2305,8 +2305,21 @@ static int rtl8365mb_port_vlan_filtering(struct dsa_switch *ds, int port,
 	if (ret)
 		goto undo_set_framefilter;
 
+	if (rtl8365mb_is_d(priv)) {
+		mutex_lock(&priv->vlan_lock);
+		ret = rtl8365mb_d_vlan_4k_refresh_ivl(ds, port, vlan_filtering);
+		mutex_unlock(&priv->vlan_lock);
+		if (ret)
+			goto undo_egress_mode;
+	}
+
 	return ret;
 
+undo_egress_mode:
+	/* The previous state was the opposite of the new one, see below */
+	(void)rtl8365mb_port_set_vlan_egress_mode(priv, port,
+		vlan_filtering ? RTL8365MB_VLAN_EGRESS_MODE_REAL_KEEP :
+				 RTL8365MB_VLAN_EGRESS_MODE_ORIGINAL);
 undo_set_framefilter:
 	if (prev_accepted_frame != accepted_frame)
 		rtl8365mb_vlan_port_set_framefilter(priv, port,
drivers/net/dsa/realtek/rtl8365mb_vlan.c +163 -2

205 lines not on this page · raw message

drivers/net/dsa/realtek/rtl8365mb_vlan.h +7 -0
index 009b127..625d4c1 100644
@@ -24,6 +24,10 @@ int rtl8365mb_c_vlan_4k_read(struct realtek_priv *priv, u16 vid,
 			     struct rtl8365mb_vlan4k *vlan4k);
 int rtl8365mb_c_vlan_4k_write(struct realtek_priv *priv,
 			      const struct rtl8365mb_vlan4k *vlan4k);
+int rtl8365mb_d_vlan_4k_read(struct realtek_priv *priv, u16 vid,
+			     struct rtl8365mb_vlan4k *vlan4k);
+int rtl8365mb_d_vlan_4k_write(struct realtek_priv *priv,
+			      const struct rtl8365mb_vlan4k *vlan4k);
 
 int rtl8365mb_vlan_port_get_pvid(struct realtek_priv *priv, int port,
 				 u16 *pvid);
@@ -43,4 +47,7 @@ int rtl8365mb_vlan_4k_port_del(struct dsa_switch *ds, int port,
 int rtl8365mb_vlan_pvid_port_set(struct dsa_switch *ds, int port, u16 vid,
 				 struct netlink_ext_ack *extack);
 int rtl8365mb_vlan_pvid_port_clear(struct dsa_switch *ds, int port, u16 vid);
+
+int rtl8365mb_d_vlan_4k_refresh_ivl(struct dsa_switch *ds, int port,
+				    bool filtering);
 #endif /* _REALTEK_RTL8365MB_VLAN_H */
Signature · 1 line
2.53.0
Tested-by on v12 7/13
#9 lore raw

Re: [PATCH net-next v12 07/13] net: dsa: realtek: rtl8365mb: set and get vlan 4k for family D

On a TP-Link EX511 v2 (RTL8367S-VB, CPU port 6 over 1G SGMII to an IPQ5018), on 6.18.44 with the rtl8365mb DCB QoS series from net-next and v12 applied as is (the same code as v12-pre5 in OpenWrt PR #19644):

- Live vlan_filtering toggle on a bridge with a VLAN in use: IVL/SVL changes at once in both directions. After 1 -> 0 the hosts are learned without a VID, and static and group entries with VID 0 steer, drop and restrict as expected; after 0 -> 1 they are learned with the VID again, and entries with the VID behave as expected. Each toggle that flips the switch-wide state took 20 to 30 ms.
- The rollback added in v12 is an error path I could not provoke here.

The rest of the series passes my regression test on this board as with
v11: VLAN-aware and VLAN-unaware bridges, PVIDs, isolation, FDB and MDB entries, flooding flags, load, no driver warnings and no port errors. The QoS baseline programmed at setup did not change any of it; QoS itself was not tested (CONFIG_DCB is not set in this build).

Thanks,
Gustavo

#10 lore raw

Re: [PATCH net-next v12 07/13] net: dsa: realtek: rtl8365mb: set and get vlan 4k for family D

Quoted 9 lines · On 20/11/2026 Gustavo Foletto Mora wrote:

- Live vlan_filtering toggle on a bridge with a VLAN in use: IVL/SVL changes at once in both directions. [...] Each toggle that flips the switch-wide state took 20 to 30 ms.
- The rollback added in v12 is an error path I could not provoke here.

The rest of the series passes my regression test on this board as with
v11: [...]

Hi Gustavo,

Thank you for testing again, and for the timings.

In v13 I changed one thing in this patch after the automated review (Sashiko) of v12: an entry that loses its last member could stay in hardware with IVL_EN=1. rtl8365mb_vlan_4k_port_set() cleared its bit in vlan_4k_used, so rtl8365mb_d_vlan_4k_refresh_ivl() never visited it again, and after filtering was switched off, frames with that VID would still have been looked up with IVL instead of SVL (FID 0).

On family D the emptied entry is now written back with IVL_EN cleared, as in its reset state:

	vlan4k.ivl_en = vlan4k.member &&
			rtl8365mb_d_want_ivl(ds, -1, false);

The commit message and the comment in the code say so. Family C is unchanged.

This path is only reached when the last port leaves a VLAN while filtering is on (e.g. a port leaving a VLAN-aware bridge), which the toggle test does not exercise, so I kept your Tested-by but would be glad if you could re-run that case.

Best regards,
Mieczyslaw

#11 lore raw

Re: [PATCH net-next v12 07/13] net: dsa: realtek: rtl8365mb: set and get vlan 4k for family D

Hi Mieczyslaw,

Quoted 4 lines · On 21/11/2026 Mieczyslaw Nalewaj wrote:

This path is only reached when the last port leaves a VLAN while filtering is on (e.g. a port leaving a VLAN-aware bridge), which the toggle test does not exercise, so I kept your Tested-by but would be glad if you could re-run that case.

Done with v13-pre2 from the OpenWrt PR. In a VLAN-aware bridge, VLAN 50 added tagged to lan2 and lan3 and used (the hosts are learned with VID 50), then deleted from both ports while filtering is on, then vlan_filtering 0: frames tagged with VID 50 are learned without a VID (SVL), and h1 -> h2 on VID 50 gets 20 of 20 replies. The toggles took 30 ms. The rest of the toggle tests give the same results as on v12.

#12 lore raw

Re: [PATCH net-next v12 07/13] net: dsa: realtek: rtl8365mb: set and get vlan 4k for family D

In reply to Mieczyslaw Nalewaj
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 2 · Low: 2

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] rtl8365mb_d_want_ivl() (drivers/net/dsa/realtek/rtl8365mb_vlan.c:364-376) makes one switch-…
- [Medium] net: dsa: realtek: stale ivl_en in rtl8365mb_vlan_4k_port_set() on family D
- [Low] The comment on the new realtek_priv::vlan_4k_used field in drivers/net/dsa/realtek/realtek.h (lines 70-74) says it holds "VIDs…
- [Low] The rollback in rtl8365mb_d_vlan_4k_refresh_ivl() (drivers/net/dsa/realtek/rtl8365mb_vlan.c:416-427) sets failed = vid…

--

net: dsa: realtek: rtl8365mb: set and get vlan 4k for family D

This adds read and write helpers for the two-word CVLAN (4K VLAN) table entry used by family D. On family D, IVL_EN now follows one switch-wide
setting: it is on while any user port is VLAN-filtering. When that setting flips, rtl8365mb_d_vlan_4k_refresh_ivl() rewrites the in-use entries, which are tracked in a new vlan_4k_used bitmap.

Quoted 4 lines
drivers/net/dsa/realtek/realtek.h +0 -0
index cfe56d30f5cb1..a3ecc13ec561e 100644

[ ... ]

drivers/net/dsa/realtek/realtek.h struct realtek_priv { · line 74

Quoted 9 lines
drivers/net/dsa/realtek/realtek.h +5 -0
@@ -65,6 +67,11 @@ struct realtek_priv {
 	 * deleting port VLAN memberships and PVID configurations.
 	 */
 	struct mutex		vlan_lock;
+	/* VIDs with a non-empty 4K VLAN entry, protected by vlan_lock. Lets
+	 * a switch-wide update visit only the entries in use instead of
+	 * reading all 4094 over the slow management bus.
+	 */
+	DECLARE_BITMAP(vlan_4k_used, VLAN_N_VID);

[Severity: Low]
This isn't a bug, but is this comment accurate for every user of struct realtek_priv?

The only writer is rtl8365mb_vlan_4k_port_set(), and it only updates the bitmap on family D:

	if (rtl8365mb_is_d(priv)) {
		if (vlan4k.member)
			set_bit(vlan->vid, priv->vlan_4k_used);
		else
			clear_bit(vlan->vid, priv->vlan_4k_used);
	}

On family C, and in rtl8366rb, which also uses struct realtek_priv, the bitmap stays empty even when 4K entries exist. If later code relies on this comment and does a switch-wide update on family C, it would visit no entries.

Could the comment say that the bitmap is only maintained on family D? Alternatively, the bitmap could be maintained for all families.

Quoted 4 lines
drivers/net/dsa/realtek/rtl8365mb_vlan.c +0 -0
index 566c6bc1449af..6317ea8fb6cde 100644

[ ... ]

Quoted 4 lines
drivers/net/dsa/realtek/rtl8365mb_vlan.c +0 -0
@@ -277,6 +323,110 @@ int rtl8365mb_c_vlan_4k_write(struct realtek_priv *priv,
 				     data, ARRAY_SIZE(data));
 }
 

[ ... ]

Quoted 9 lines
drivers/net/dsa/realtek/rtl8365mb_vlan.c +9 -0
+/* Family D has no EFID, so a VLAN-unaware bridge must learn in SVL (IVL=0,
+ * FID=0) to match static FDB/MDB entries programmed with VID 0. Use IVL only
+ * while at least one user port is VLAN-filtering. @port/@filtering override
+ * the state of the port currently being changed, as DSA updates
+ * dp->vlan_filtering only after the driver callback returns.
+ */
+static bool rtl8365mb_d_want_ivl(struct dsa_switch *ds, int port,
+				 bool filtering)
+{

drivers/net/dsa/realtek/rtl8365mb_vlan.c int rtl8365mb_c_vlan_4k_write(struct realtek_priv *priv, · line 376

Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_vlan.c +10 -0
+	struct dsa_port *dp;
+
+	dsa_switch_for_each_user_port(dp, ds) {
+		if (dp->index == port ? filtering :
+					dsa_port_is_vlan_filtering(dp))
+			return true;
+	}
+
+	return false;
+}

[Severity: Medium]
What happens when a VLAN-aware bridge and a VLAN-unaware bridge are both offloaded on the same family D switch?

VLAN awareness is set per bridge, but this function makes one choice for the whole switch. Both rtl8365mb_d_vlan_4k_refresh_ivl() and rtl8365mb_vlan_4k_port_set() write that value into IVL_EN of every 4K entry.

The driver sets ds->configure_vlan_while_not_filtering, so the VLAN-unaware bridge also has 4K entries, for example its default_pvid VLAN. Those entries get IVL=1 as well, so lookups and learning on that bridge use the key {IVL=1, VID=PVID}.

Its static FDB/MDB entries come from DSA with vid 0. The family D L2 packer added later in the series programs them with the SVL key {IVL=0, FID=0}:

rtl8365mb_d_l2_uc_to_data()

	bool ivl = uc->key.ivl && uc->key.vid;

Would those static entries ever be hit? If not, unicast to host or static addresses is flooded. Static multicast is either flooded or dropped, depending on mcast_flood.

That is the mismatch the commit message says this change avoids ("so that static and learned FDB/MDB entries use the same key"). The commit message does not mention this limitation.

The last patch in the series, "net: dsa: realtek: rtl8365mb: add support for RTL8367S-VB", sets ds->max_num_bridges = 1 for family D. That narrows the problem but does not close it.

dsa_bridge_num_get() returns a bridge number that is already allocated without checking max. The comment added in that patch also says that a bridge that already has a number from another switch can still be offloaded. In multi-switch setups, it still seems possible to have two bridges with different VLAN awareness on one family D switch.

Nothing sets ds->vlan_filtering_is_global, and rtl8365mb_port_vlan_filtering() does not reject this case through extack. Should one of these be done? If not, should the commit message document the restriction?

Quoted 5 lines
drivers/net/dsa/realtek/rtl8365mb_vlan.c +5 -0
+
+/* Must be called with &priv->vlan_lock held. */
+int rtl8365mb_d_vlan_4k_refresh_ivl(struct dsa_switch *ds, int port,
+				    bool filtering)
+{

[ ... ]

Quoted 18 lines
drivers/net/dsa/realtek/rtl8365mb_vlan.c +18 -0
+	for_each_set_bit(vid, priv->vlan_4k_used, VLAN_N_VID) {
+		ret = fi->vlan_4k_read(priv, vid, &vlan4k);
+		if (ret)
+			goto rollback;
+		if (!vlan4k.member || vlan4k.ivl_en == want_ivl)
+			continue;
+
+		vlan4k.ivl_en = want_ivl;
+		ret = fi->vlan_4k_write(priv, &vlan4k);
+		if (ret)
+			goto rollback;
+	}
+
+	return 0;
+
+rollback:
+	/* Best effort: restore the entries rewritten so far */
+	failed = vid;

drivers/net/dsa/realtek/rtl8365mb_vlan.c int rtl8365mb_c_vlan_4k_write(struct realtek_priv *priv, · line 428

Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_vlan.c +10 -0
+	for_each_set_bit(vid, priv->vlan_4k_used, failed) {
+		if (fi->vlan_4k_read(priv, vid, &vlan4k))
+			continue;
+		if (!vlan4k.member || vlan4k.ivl_en != want_ivl)
+			continue;
+		vlan4k.ivl_en = !want_ivl;
+		fi->vlan_4k_write(priv, &vlan4k);
+	}
+	return ret;
+}

[Severity: Medium]
When the last port leaves a VLAN on family D while some user port is still VLAN-filtering, does this leave IVL_EN set in a hardware entry that the refresh can no longer reach?

In that case rtl8365mb_vlan_4k_port_set() computes vlan4k.member == 0. It still sets vlan4k.ivl_en from rtl8365mb_d_want_ivl(ds, -1, false), which returns true, and writes the entry with IVL_EN=1. It then clears the VID from priv->vlan_4k_used.

When VLAN filtering is later turned off, rtl8365mb_d_vlan_4k_refresh_ivl() only walks the bits set in vlan_4k_used, and it also skips entries with no members. So that entry keeps IVL_EN=1.

This is not limited to an explicit bridge vlan del. When the ports of a VLAN-aware bridge leave it, dsa_port_pre_bridge_leave() unoffloads all of the bridge VLANs while dp->vlan_filtering is still true. Only after that does dsa_port_bridge_leave() call dsa_port_reset_vlan_filtering(). So every VLAN of that bridge is emptied with IVL_EN=1 and dropped from the bitmap before the refresh runs.

Suppose the ports then join a VLAN-unaware bridge. Ingress membership filtering is off and egress is transparent, so frames tagged with one of those old VIDs are still looked up in the 4K table. If the chip honours IVL_EN of an entry with no members, those frames would be learned and looked up under {IVL=1, VID}. The static FDB/MDB entries that DSA programs with vid 0 use the SVL key {IVL=0, FID=0}, so they would not match.

Would it be enough to write ivl_en = 0, or an all-zero entry, when vlan4k.member becomes empty? Or does the hardware ignore IVL_EN for an entry with no members?

[Severity: Low]
The size bound passed to for_each_set_bit() is exclusive, so the rollback never revisits the VID whose vlan_4k_write() failed. Could that entry still end up written in hardware?

rtl8365mb_table_query() writes the data, address and command registers. It then waits in rtl8365mb_table_poll_busy(), which has a 10 ms timeout:

	return regmap_read_poll_timeout(priv->map_nolock,
			RTL8365MB_TABLE_STATUS_REG, val,
			!FIELD_GET(RTL8365MB_TABLE_STATUS_BUSY_FLAG_MASK, val),
			10, 10000);

Suppose the poll times out after the command was issued, and the hardware still commits the write. That VID keeps ivl_en == want_ivl while the other entries are restored, and DSA keeps the old dp->vlan_filtering. That one VLAN would then stay in the opposite learning mode until something rewrites it.

The rollback loop already re-reads each entry and skips it when ivl_en != want_ivl. Would it be safe to use failed + 1 as the bound here?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/bc42ae96-dc7e-4b6e-b9cc-64cde5dc51ce%40yahoo.com
#13 lore raw

PATCH v12 8/13 net: dsa: realtek: rtl8365mb: refactor PVID handling

In reply to Mieczyslaw Nalewaj

The PVID helpers (rtl8365mb_vlan_port_get_pvid(), rtl8365mb_vlan_pvid_port_set() and rtl8365mb_vlan_pvid_port_clear()) work on a VLAN MC table index, which only family C has. Family D stores a raw VID in a per-port register, so it needs its own implementation.

Move the helpers behind struct rtl8365mb_family_info, as already done for the VLAN 4k accessors: the existing code becomes the family C implementation (rtl8365mb_c_vlan_port_get_pvid() and the like), and the three functions above only call it through the vlan_port_get_pvid, vlan_pvid_port_set and vlan_pvid_port_clear pointers in the family info. The callers are not changed. The following patch adds the family D implementation without any is_d() check in the shared code.

No functional change.

The family C functions are not static because they are referenced from the family C info in rtl8365mb_main.c.

---
 drivers/net/dsa/realtek/rtl8365mb.h      |   8 ++
 drivers/net/dsa/realtek/rtl8365mb_main.c |   4 +
 drivers/net/dsa/realtek/rtl8365mb_vlan.c | 101 +++++++++++++++++++++--
 drivers/net/dsa/realtek/rtl8365mb_vlan.h |   6 ++
 4 files changed, 111 insertions(+), 8 deletions(-)
drivers/net/dsa/realtek/rtl8365mb.h +8 -0
index be0f49e..c59e657 100644
@@ -9,6 +9,8 @@ enum rtl8365mb_family {
 	RTL8365MB_FAMILY_D,
 };
 
+struct dsa_switch;
+struct netlink_ext_ack;
 struct rtl8365mb_jam_tbl_entry;
 struct rtl8365mb_vlan4k;
 
@@ -23,6 +25,12 @@ struct rtl8365mb_family_info {
 			    struct rtl8365mb_vlan4k *vlan4k);
 	int (*vlan_4k_write)(struct realtek_priv *priv,
 			     const struct rtl8365mb_vlan4k *vlan4k);
+	int (*vlan_port_get_pvid)(struct realtek_priv *priv, int port,
+				  u16 *pvid);
+	int (*vlan_port_reset_pvid)(struct realtek_priv *priv, int port);
+	int (*vlan_pvid_port_set)(struct dsa_switch *ds, int port, u16 vid,
+				  struct netlink_ext_ack *extack);
+	int (*vlan_pvid_port_clear)(struct dsa_switch *ds, int port, u16 vid);
 };
 
 const struct rtl8365mb_family_info *
drivers/net/dsa/realtek/rtl8365mb_main.c +4 -0
index 2269ac9..bb3d7cd 100644
@@ -758,6 +758,10 @@ static const struct rtl8365mb_family_info rtl8365mb_family_c = {
 	.ext_config_forcemode = rtl8365mb_c_ext_config_forcemode,
 	.vlan_4k_read = rtl8365mb_c_vlan_4k_read,
 	.vlan_4k_write = rtl8365mb_c_vlan_4k_write,
+	.vlan_port_get_pvid = rtl8365mb_c_vlan_port_get_pvid,
+	.vlan_port_reset_pvid = rtl8365mb_c_vlan_port_reset_pvid,
+	.vlan_pvid_port_set = rtl8365mb_c_vlan_pvid_port_set,
+	.vlan_pvid_port_clear = rtl8365mb_c_vlan_pvid_port_clear,
 };
 
 /**
drivers/net/dsa/realtek/rtl8365mb_vlan.c +93 -8

146 lines not on this page · raw message

drivers/net/dsa/realtek/rtl8365mb_vlan.h +6 -0
index 625d4c1..62ee59c 100644
@@ -28,6 +28,12 @@ int rtl8365mb_d_vlan_4k_read(struct realtek_priv *priv, u16 vid,
 			     struct rtl8365mb_vlan4k *vlan4k);
 int rtl8365mb_d_vlan_4k_write(struct realtek_priv *priv,
 			      const struct rtl8365mb_vlan4k *vlan4k);
+int rtl8365mb_c_vlan_port_get_pvid(struct realtek_priv *priv, int port,
+				   u16 *pvid);
+int rtl8365mb_c_vlan_port_reset_pvid(struct realtek_priv *priv, int port);
+int rtl8365mb_c_vlan_pvid_port_set(struct dsa_switch *ds, int port, u16 vid,
+				   struct netlink_ext_ack *extack);
+int rtl8365mb_c_vlan_pvid_port_clear(struct dsa_switch *ds, int port, u16 vid);
 
 int rtl8365mb_vlan_port_get_pvid(struct realtek_priv *priv, int port,
 				 u16 *pvid);
Signature · 1 line
2.53.0
Tested-by on v12 8/13
#14 lore raw

Re: [PATCH net-next v12 08/13] net: dsa: realtek: rtl8365mb: refactor PVID handling

Tested on family D only (RTL8367S-VB, TP-Link EX511 v2), v12 as is: the PVID paths reached through the family info behave as with v11, PVIDs set and cleared on access ports, untagged and priority-tagged frames handled per PVID, deleting another VLAN keeps the PVID. The family C implementation is not exercised here.

Thanks,
Gustavo

#15 lore raw

PATCH v12 9/13 net: dsa: realtek: rtl8365mb: use raw VID for PVID on family D

In reply to Mieczyslaw Nalewaj

Family D has no working VLAN member config (MC) table. Its PVID is a raw 12-bit VID in a per-port register at 0x0700 + port, whereas family C stores a 5-bit MC table index, two ports per register, at 0x0700 + (port >> 1).

Running the family C code on family D therefore reads an MC table that does not exist, and writes an MC index into the VID register of port (port >> 1) instead of the one of the port being configured.

Add the family D implementations of the PVID helpers, rtl8365mb_d_vlan_port_get_pvid(), rtl8365mb_d_vlan_pvid_port_set() and rtl8365mb_d_vlan_pvid_port_clear(), which skip the MC table. They keep the family C frame filter handling and rollback on error. The shared code reaches them through the vlan_port_get_pvid, vlan_pvid_port_set and vlan_pvid_port_clear pointers in struct rtl8365mb_family_info, so it needs no is_d() check.

Also clear the family D PVID registers when the VLAN support is set up. Unlike on family C, where VLANMC index 0 is the neutral PVID, the register holds a raw VID, and after a reset it keeps its hardware (or EEPROM) default. Without clearing it an unconfigured port could report a stale PVID from rtl8365mb_vlan_port_get_pvid(), and rtl8365mb_port_vlan_filtering() would accept untagged frames into it. rtl8365mb_c_vlan_port_reset_pvid() does nothing on family C.

No functional change for family C.

Nothing points to the new functions until the family D info is added together with the chip table entry in the last patch. Until then they are not static and are declared in rtl8365mb_vlan.h, so that the build does not warn about unused functions.

---
 drivers/net/dsa/realtek/rtl8365mb_main.c |  11 ++
 drivers/net/dsa/realtek/rtl8365mb_vlan.c | 201 ++++++++++++++++++++++-
 drivers/net/dsa/realtek/rtl8365mb_vlan.h |   6 +
 3 files changed, 217 insertions(+), 1 deletion(-)
drivers/net/dsa/realtek/rtl8365mb_main.c +11 -0
index bb3d7cd..7ad9ef1 100644
@@ -2452,11 +2452,22 @@ out_unlock:
  */
 static int rtl8365mb_vlan_setup(struct dsa_switch *ds)
 {
+	const struct rtl8365mb_family_info *fi;
 	struct realtek_priv *priv = ds->priv;
 	struct dsa_port *dp;
 	int ret;
 
+	fi = rtl8365mb_get_family_info(priv);
 	dsa_switch_for_each_available_port(dp, ds) {
+		/* Put the PVID in its neutral state, if the chip needs it */
+		ret = fi->vlan_port_reset_pvid(priv, dp->index);
+		if (ret) {
+			dev_err(priv->dev,
+				"Failed to reset PVID on port %d\n",
+				dp->index);
+			return ret;
+		}
+
 		/* Disable vlan-filtering for all ports */
 		ret = rtl8365mb_port_vlan_filtering(ds, dp->index, false, NULL);
 		if (ret) {
drivers/net/dsa/realtek/rtl8365mb_vlan.c +200 -1

222 lines not on this page · raw message

drivers/net/dsa/realtek/rtl8365mb_vlan.h +6 -0
index 62ee59c..d8187bc 100644
@@ -34,6 +34,12 @@ int rtl8365mb_c_vlan_port_reset_pvid(struct realtek_priv *priv, int port);
 int rtl8365mb_c_vlan_pvid_port_set(struct dsa_switch *ds, int port, u16 vid,
 				   struct netlink_ext_ack *extack);
 int rtl8365mb_c_vlan_pvid_port_clear(struct dsa_switch *ds, int port, u16 vid);
+int rtl8365mb_d_vlan_port_get_pvid(struct realtek_priv *priv, int port,
+				   u16 *pvid);
+int rtl8365mb_d_vlan_port_reset_pvid(struct realtek_priv *priv, int port);
+int rtl8365mb_d_vlan_pvid_port_set(struct dsa_switch *ds, int port, u16 vid,
+				   struct netlink_ext_ack *extack);
+int rtl8365mb_d_vlan_pvid_port_clear(struct dsa_switch *ds, int port, u16 vid);
 
 int rtl8365mb_vlan_port_get_pvid(struct realtek_priv *priv, int port,
 				 u16 *pvid);
Signature · 1 line
2.53.0
Tested-by on v12 9/13
#16 lore raw

Re: [PATCH net-next v12 09/13] net: dsa: realtek: rtl8365mb: use raw VID for PVID on family D

Tested on a TP-Link EX511 v2 (RTL8367S-VB), v12 as is: PVID registers at setup, PVID set and clear on access ports, untagged frames dropped without a PVID and taken in with one, priority-tagged frames taken into the PVID, and a PVID change in a VLAN-unaware bridge with no effect on traffic.

Thanks,
Gustavo

#17 lore raw

Re: [PATCH net-next v12 09/13] net: dsa: realtek: rtl8365mb: use raw VID for PVID on family D

In reply to Mieczyslaw Nalewaj
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The PVID reset hook is split across two patches, and neither commit message fully describes its own part of it.

--

net: dsa: realtek: rtl8365mb: use raw VID for PVID on family D

This adds family D versions of the PVID helpers. On family D the PVID is a raw 12-bit VID in a per-port register, and there is no VLAN MC table. It also clears the family D PVID registers from rtl8365mb_vlan_setup() through a new vlan_port_reset_pvid hook in struct rtl8365mb_family_info.

Quoted 7 lines

Add the family D implementations of the PVID helpers, rtl8365mb_d_vlan_port_get_pvid(), rtl8365mb_d_vlan_pvid_port_set() and rtl8365mb_d_vlan_pvid_port_clear(), which skip the MC table. They keep the family C frame filter handling and rollback on error. The shared code reaches them through the vlan_port_get_pvid, vlan_pvid_port_set and vlan_pvid_port_clear pointers in struct rtl8365mb_family_info, so it needs no is_d() check.

[Severity: Low]
This isn't a bug, but the list of new family D helpers leaves out rtl8365mb_d_vlan_port_reset_pvid(). This patch also adds it to rtl8365mb_vlan.c and exports it through rtl8365mb_vlan.h:

  int rtl8365mb_d_vlan_port_reset_pvid(struct realtek_priv *priv, int port);

A later paragraph does describe clearing the PVID at setup. Could the function and the vlan_port_reset_pvid pointer be added to this list as well?

The hook is also split across two patches. The earlier patch "net: dsa:
realtek: rtl8365mb: refactor PVID handling" adds these pieces:

- the vlan_port_reset_pvid member of struct rtl8365mb_family_info
- the no-op rtl8365mb_c_vlan_port_reset_pvid()
- its prototype in rtl8365mb_vlan.h
- .vlan_port_reset_pvid = rtl8365mb_c_vlan_port_reset_pvid in the family C info

The message of that patch lists only three pointers and says "No functional change". Nothing calls the hook there. Its only caller arrives in this patch, in rtl8365mb_vlan_setup():

drivers/net/dsa/realtek/rtl8365mb_main.c out_unlock: · line 2463

Quoted 1 line
drivers/net/dsa/realtek/rtl8365mb_main.c +1 -0
+		ret = fi->vlan_port_reset_pvid(priv, dp->index);

Would it make sense to either move the hook and the family C stub into this patch, or mention them in the refactor patch's commit message?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/bc42ae96-dc7e-4b6e-b9cc-64cde5dc51ce%40yahoo.com
#18 lore raw

PATCH v12 10/13 net: dsa: realtek: rtl8365mb: add family D SDS13 PCS support

In reply to Mieczyslaw Nalewaj

Extend the existing RTL8367S SGMII/HSGMII PCS implementation in this driver for family D switches, whose CPU SerDes is reached through the indexed SDS13 window and whose SDS_MISC fields differ from family C.

The register sequence and tuning tables are derived from the GPL-licensed Realtek RTL8367D port API distributed in the Mercusys MR80X GPL release. Keep the existing family C path unchanged and select the new behavior from the driver's chip-family metadata, making the implementation reusable by other family D boards.

The SerDes line rate bypass register (RTL8365MB_BYPASS_LINE_RATE_REG, 0x03f7) is laid out the same way in the RTL8367D port API as for family C: one bit per port, with bit 0 being port 5 (the RTL8367D_BYPASS_PORTn_CONSTRAINT_* definitions cover ports 5 to 7). The existing mask for port 6 therefore applies to family D as well.

This patch only prepares the family D paths; they become reachable when the RTL8367S-VB chip entry is added in the last patch.

On family D rtl8365mb_sds_probe_option() does not read the family C option register and always sets sds_supported, so the port 6 rate limits are raised for every family D chip. The only family D chip in this series, the RTL8367S-VB, has a SerDes interface on port 6.

Nothing on family D programs a SerDes rate for 10 and 100 Mbit/s:
pcs_link_up() does nothing and the MAC force register only sets the MAC side. It is not known whether the SerDes follows that register, and only 1G SGMII and 2500base-x were tested, so do not advertise 10 and 100 Mbit/s on the SerDes port of family D.

---
 drivers/net/dsa/realtek/rtl8365mb_main.c | 263 ++++++++++++++++++-----
 1 file changed, 205 insertions(+), 58 deletions(-)
drivers/net/dsa/realtek/rtl8365mb_main.c +205 -58
index 7ad9ef1..50ba2fa 100644
@@ -264,7 +264,10 @@
  * interface, indexed by the external port number with port 5 (the first
  * external port) as the base. Other RTL8367 families index this register
  * differently (e.g. the RTL8367R uses (id + 1) % 2), so this mapping only
- * holds for the RTL8367C-style parts this driver supports.
+ * holds for the RTL8367C-style parts and for family D, where it is the same
+ * (one bit per port, bit 0 being port 5), as in the vendor RTL8367D API.
+ * Port 5 is not an external port on the RTL8367S-VB, whose external ports
+ * are 6 and 7.
  */
 #define RTL8365MB_BYPASS_LINE_RATE_REG		0x03F7
 #define RTL8365MB_BYPASS_LINE_RATE_MASK(_port)	BIT((_port) - 5)
@@ -286,6 +289,7 @@
 #define   RTL8365MB_SDS_INDACS_CMD_BUSY_MASK	BIT(8)
 #define   RTL8365MB_SDS_INDACS_CMD_RUN_MASK	BIT(7)
 #define   RTL8365MB_SDS_INDACS_CMD_WR_MASK	BIT(6)
+#define   RTL8365MB_SDS_INDACS_CMD_INDEX_MASK	GENMASK(5, 0)
 #define RTL8365MB_SDS_INDACS_ADR_REG		0x6601
 #define RTL8365MB_SDS_INDACS_DATA_REG		0x6602
 
@@ -315,8 +319,10 @@
 #define RTL8365MB_SDS_REG_LINK_STATUS		0x003d
 #define   RTL8365MB_SDS_LINK_STATUS_LINK_MASK	BIT(4)
 
-/* The embedded SerDes can only be muxed to external interface 1 (MAC8),
- * which is port 6.
+/* On family C the embedded SerDes can only be muxed to external interface
+ * 1 (MAC8), which is port 6. Family D has it on external interface 0
+ * (MAC6), see RTL8365MB_D_SDS_EXT0_INDEX. RTL8365MB_SDS_EXT_INTERFACE_ID
+ * below is the family C id; the SerDes port is 6 on both families.
  */
 #define RTL8365MB_SDS_EXT_INTERFACE_ID		1
 #define RTL8365MB_SDS_EXT_INTERFACE_PORT	6
@@ -334,7 +340,22 @@
 #define   RTL8365MB_SDS_OPTION_ARM_KEY		0x0249
 #define RTL8365MB_SDS_OPTION_REG		0x13C1
 
+/* Family D uses the SDS13 indirect window for its MAC6 SerDes. */
+#define RTL8365MB_D_SDS_EXT0_INDEX			13
+#define RTL8365MB_D_FIBER_CFG2_REG			0x13E8
+#define   RTL8365MB_D_FIBER_CFG2_RX_DISABLE_MASK	GENMASK(7, 6)
+#define   RTL8365MB_D_FIBER_CFG2_RX_DISABLE_SDS0	BIT(6)
+#define RTL8365MB_D_SDS_MISC_PA33PC_EN			BIT(11)
+#define RTL8365MB_D_SDS_MISC_PA12PC_EN			BIT(10)
+#define RTL8365MB_D_SDS_MISC_MAC6_SEL_SDS0		BIT(9)
 #define RTL8365MB_D_SDS_MISC_MODE_FIELD_MASK		GENMASK(4, 0)
+#define RTL8365MB_D_SDS_MISC_MODE_SGMII			0x02
+#define RTL8365MB_D_SDS_MISC_MODE_HSGMII		0x12
+#define RTL8365MB_D_SDS_MISC_CFG_MASK			\
+	(RTL8365MB_D_SDS_MISC_PA33PC_EN |		\
+	 RTL8365MB_D_SDS_MISC_PA12PC_EN |		\
+	 RTL8365MB_D_SDS_MISC_MAC6_SEL_SDS0 |		\
+	 RTL8365MB_D_SDS_MISC_MODE_FIELD_MASK)
 /* Shared "disable" encoding for both SDS_MISC's and SDS1_MISC0's
  * 5-bit mode fields.
  */
@@ -721,6 +742,21 @@ static const struct rtl8365mb_jam_tbl_entry rtl8365mb_sds_jam_hsgmii[] = {
 	{ 0x0424, 0xD810 }, { 0x0001, 0x0F80 }, { 0x002E, 0x83F2 },
 };
 
+/* Family D tuning tables from the Realtek vendor port API. */
+static const struct rtl8365mb_jam_tbl_entry rtl8365mb_d_sds_jam_sgmii[] = {
+	{ 0x0427, 0x4E0C }, { 0x0428, 0xAA00 }, { 0x0425, 0x5189 },
+	{ 0x0424, 0x8414 }, { 0x0423, 0x1020 }, { 0x0410, 0x0002 },
+	{ 0x0484, 0x011B }, { 0x0421, 0x8E13 }, { 0x0422, 0x1140 },
+	{ 0x0004, 0x074F },
+};
+
+static const struct rtl8365mb_jam_tbl_entry rtl8365mb_d_sds_jam_hsgmii[] = {
+	{ 0x0427, 0x4E0C }, { 0x0428, 0xAA00 }, { 0x0425, 0x5189 },
+	{ 0x0424, 0x8414 }, { 0x0423, 0x1020 }, { 0x0410, 0x0002 },
+	{ 0x0504, 0x051B }, { 0x0421, 0x8E13 }, { 0x0422, 0x1140 },
+	{ 0x0004, 0x074F },
+};
+
 enum rtl8365mb_phy_interface_mode {
 	RTL8365MB_PHY_INTERFACE_MODE_INVAL = 0,
 	RTL8365MB_PHY_INTERFACE_MODE_INTERNAL = BIT(0),
@@ -933,8 +969,9 @@ struct rtl8365mb_port {
  * @mib_lock: prevent concurrent reads of MIB counters
  * @ports: per-port data
  * @pcs: PCS for the SerDes external interface
- * @sds_supported: SerDes tuning parameters match the chip option, so the
- *                 SerDes interface modes can be advertised
+ * @sds_supported: SerDes interface modes can be advertised: the tuning
+ *                 parameters match the chip option (family C), or the chip
+ *                 is family D, which does not use the option
  *
  * Private data for this driver.
  */
@@ -1347,7 +1384,8 @@ static int rtl8365mb_ext_config_rgmii(struct realtek_priv *priv, int port,
 	return 0;
 }
 
-static int rtl8365mb_sds_write(struct realtek_priv *priv, u16 addr, u16 data)
+static int rtl8365mb_sds_write(struct realtek_priv *priv, u8 index,
+			       u16 addr, u16 data)
 {
 	int ret;
 
@@ -1365,10 +1403,13 @@ static int rtl8365mb_sds_write(struct realtek_priv *priv, u16 addr, u16 data)
 	 */
 	return regmap_write(priv->map, RTL8365MB_SDS_INDACS_CMD_REG,
 			    RTL8365MB_SDS_INDACS_CMD_RUN_MASK |
-			    RTL8365MB_SDS_INDACS_CMD_WR_MASK);
+			    RTL8365MB_SDS_INDACS_CMD_WR_MASK |
+			    FIELD_PREP(RTL8365MB_SDS_INDACS_CMD_INDEX_MASK,
+				       index));
 }
 
-static int rtl8365mb_sds_read(struct realtek_priv *priv, u16 addr, u16 *data)
+static int rtl8365mb_sds_read(struct realtek_priv *priv, u8 index,
+			      u16 addr, u16 *data)
 {
 	u32 val;
 	int ret;
@@ -1378,7 +1419,9 @@ static int rtl8365mb_sds_read(struct realtek_priv *priv, u16 addr, u16 *data)
 		return ret;
 
 	ret = regmap_write(priv->map, RTL8365MB_SDS_INDACS_CMD_REG,
-			   RTL8365MB_SDS_INDACS_CMD_RUN_MASK);
+			   RTL8365MB_SDS_INDACS_CMD_RUN_MASK |
+			   FIELD_PREP(RTL8365MB_SDS_INDACS_CMD_INDEX_MASK,
+				      index));
 	if (ret)
 		return ret;
 
@@ -1418,6 +1461,14 @@ static int rtl8365mb_sds_probe_option(struct realtek_priv *priv)
 	int ret;
 	int i;
 
+	/* Family D has a fixed SDS13 programming model and does not use the
+	 * family C option register to select its tuning table.
+	 */
+	if (rtl8365mb_is_d(priv)) {
+		mb->sds_supported = true;
+		return 0;
+	}
+
 	/* Nothing to probe if no external interface is wired to the SerDes */
 	for (i = 0; i < RTL8365MB_MAX_NUM_EXTINTS; i++) {
 		extint = &mb->chip_info->extints[i];
@@ -1499,31 +1550,54 @@ static int rtl8365mb_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode,
 	const struct rtl8365mb_jam_tbl_entry *sds_jam;
 	const int id = RTL8365MB_SDS_EXT_INTERFACE_ID;
 	struct rtl8365mb *mb = pcs_to_rtl8365mb(pcs);
-	struct realtek_priv *priv;
+	struct realtek_priv *priv = mb->priv;
 	size_t sds_jam_size;
-	u32 mode;
+	u32 misc_mask;
+	u32 misc_val;
+	u32 sds_mode;
+	u8 sds_index;
+	bool is_d;
 	u16 val;
 	int ret;
 	int i;
 
-	priv = mb->priv;
+	is_d = rtl8365mb_is_d(priv);
 
+	/* Select the appropriate tuning table and SDS mode */
 	if (interface == PHY_INTERFACE_MODE_2500BASEX) {
-		sds_jam = rtl8365mb_sds_jam_hsgmii;
-		sds_jam_size = ARRAY_SIZE(rtl8365mb_sds_jam_hsgmii);
-		mode = RTL8365MB_EXT_PORT_MODE_HSGMII;
+		if (is_d) {
+			sds_jam = rtl8365mb_d_sds_jam_hsgmii;
+			sds_jam_size = ARRAY_SIZE(rtl8365mb_d_sds_jam_hsgmii);
+			sds_mode = RTL8365MB_D_SDS_MISC_MODE_HSGMII;
+		} else {
+			sds_jam = rtl8365mb_sds_jam_hsgmii;
+			sds_jam_size = ARRAY_SIZE(rtl8365mb_sds_jam_hsgmii);
+			sds_mode = RTL8365MB_EXT_PORT_MODE_HSGMII;
+		}
 	} else {
-		sds_jam = rtl8365mb_sds_jam_sgmii;
-		sds_jam_size = ARRAY_SIZE(rtl8365mb_sds_jam_sgmii);
-		mode = RTL8365MB_EXT_PORT_MODE_SGMII;
+		if (is_d) {
+			sds_jam = rtl8365mb_d_sds_jam_sgmii;
+			sds_jam_size = ARRAY_SIZE(rtl8365mb_d_sds_jam_sgmii);
+			sds_mode = RTL8365MB_D_SDS_MISC_MODE_SGMII;
+		} else {
+			sds_jam = rtl8365mb_sds_jam_sgmii;
+			sds_jam_size = ARRAY_SIZE(rtl8365mb_sds_jam_sgmii);
+			sds_mode = RTL8365MB_EXT_PORT_MODE_SGMII;
+		}
 	}
 
+	sds_index = is_d ? RTL8365MB_D_SDS_EXT0_INDEX : 0;
+
 	/* Hold the embedded DW8051 microcontroller in reset and keep it
 	 * disabled. The vendor driver loads firmware into it to manage the
 	 * SerDes link, but the firmware only duplicates work that phylink
 	 * already does: it polls the port status and forces the external
 	 * interface configuration in the very registers this driver manages.
 	 * Letting it run would race with phylink.
+	 *
+	 * The CHIP_RESET (bit 4) and MISC_CFG0 (bit 5) bit definitions
+	 * for the DW8051 reset and enable controls are identical on both
+	 * family C and family D switches in the vendor SDK.
 	 */
 	ret = regmap_update_bits(priv->map, RTL8365MB_CHIP_RESET_REG,
 				 RTL8365MB_CHIP_RESET_DW8051_MASK,
@@ -1546,34 +1620,58 @@ static int rtl8365mb_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode,
 
 	/* Tune the SerDes with vendor-prescribed parameters */
 	for (i = 0; i < sds_jam_size; i++) {
-		ret = rtl8365mb_sds_write(priv, sds_jam[i].reg,
-					  sds_jam[i].val);
+		ret = rtl8365mb_sds_write(priv, sds_index,
+					  sds_jam[i].reg, sds_jam[i].val);
 		if (ret)
 			return ret;
 	}
 
-	/* Mux the SerDes to MAC8 in the requested mode */
+	/* Family-specific post-tuning configuration */
+	if (is_d) {
+		/* The register and field names follow the vendor RTL8367D API,
+		 * whose SDS numbering differs from the SDS13 window used
+		 * here. As in the vendor sequence the whole 2-bit field
+		 * (bits 7:6) is written, so bit 7 is cleared as well.
+		 */
+		ret = regmap_update_bits(priv->map, RTL8365MB_D_FIBER_CFG2_REG,
+					 RTL8365MB_D_FIBER_CFG2_RX_DISABLE_MASK,
+					 RTL8365MB_D_FIBER_CFG2_RX_DISABLE_SDS0);
+		if (ret)
+			return ret;
+
+		misc_mask = RTL8365MB_D_SDS_MISC_CFG_MASK;
+		misc_val  = RTL8365MB_D_SDS_MISC_PA33PC_EN |
+			    RTL8365MB_D_SDS_MISC_PA12PC_EN |
+			    RTL8365MB_D_SDS_MISC_MAC6_SEL_SDS0 | sds_mode;
+	} else {
+		/* Mux the SerDes to MAC8 in the requested mode */
+		misc_mask = RTL8365MB_SDS_MISC_MAC8_SEL_SGMII_MASK |
+			    RTL8365MB_SDS_MISC_MAC8_SEL_HSGMII_MASK;
+		misc_val  = (sds_mode == RTL8365MB_EXT_PORT_MODE_SGMII) ?
+			    RTL8365MB_SDS_MISC_MAC8_SEL_SGMII_MASK :
+			    RTL8365MB_SDS_MISC_MAC8_SEL_HSGMII_MASK;
+	}
+
 	ret = regmap_update_bits(priv->map, RTL8365MB_SDS_MISC_REG,
-				 RTL8365MB_SDS_MISC_MAC8_SEL_SGMII_MASK |
-					 RTL8365MB_SDS_MISC_MAC8_SEL_HSGMII_MASK,
-				 mode == RTL8365MB_EXT_PORT_MODE_SGMII ?
-					 RTL8365MB_SDS_MISC_MAC8_SEL_SGMII_MASK :
-					 RTL8365MB_SDS_MISC_MAC8_SEL_HSGMII_MASK);
+				 misc_mask, misc_val);
 	if (ret)
 		return ret;
 
-	val = mode << RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_OFFSET(id);
-	ret = regmap_update_bits(priv->map,
-				 RTL8365MB_DIGITAL_INTERFACE_SELECT_REG(id),
-				 RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_MASK(id),
-				 val);
-	if (ret)
-		return ret;
+	if (!is_d) {
+		val = sds_mode << RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_OFFSET(id);
+		ret = regmap_update_bits(priv->map,
+					 RTL8365MB_DIGITAL_INTERFACE_SELECT_REG(id),
+					 RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_MASK(id),
+					 val);
+		if (ret)
+			return ret;
+	}
 
 	/* Take the SerDes out of reset. The vendor driver does this only
 	 * after the SerDes mux and the interface mode are configured.
 	 */
-	ret = rtl8365mb_sds_write(priv, RTL8365MB_SDS_REG_RESET,
+	ret = rtl8365mb_sds_write(priv, sds_index,
+				  RTL8365MB_SDS_REG_RESET,
 				  RTL8365MB_SDS_RESET_DEASSERT);
 	if (ret)
 		return ret;
@@ -1583,27 +1681,32 @@ static int rtl8365mb_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode,
 	 * This flushes the FIFOs and ensures a clean state for the link,
 	 * preventing silent drops and CRC errors.
 	 */
-	ret = rtl8365mb_sds_write(priv, RTL8365MB_SDS_REG_BMCR,
+	ret = rtl8365mb_sds_write(priv, sds_index,
+				  RTL8365MB_SDS_REG_BMCR,
 				  RTL8365MB_SDS_BMCR_DPRST_PHASE1);
 	if (ret)
 		return ret;
 
-	ret = rtl8365mb_sds_write(priv, RTL8365MB_SDS_REG_BMCR,
+	ret = rtl8365mb_sds_write(priv, sds_index,
+				  RTL8365MB_SDS_REG_BMCR,
 				  RTL8365MB_SDS_BMCR_DPRST_PHASE2);
 	if (ret)
 		return ret;
 
 	/* Keep SGMII in-band autonegotiation disabled: the link parameters are
-	 * forced from rtl8365mb_pcs_link_up() instead.
+	 * forced from rtl8365mb_pcs_link_up() instead (family C), or from
+	 * mac_link_up() (family D).
 	 */
-	ret = rtl8365mb_sds_read(priv, RTL8365MB_SDS_REG_NWAY, &val);
+	ret = rtl8365mb_sds_read(priv, sds_index,
+				 RTL8365MB_SDS_REG_NWAY, &val);
 	if (ret)
 		return ret;
 
 	val &= ~RTL8365MB_SDS_NWAY_EN_MASK;
 	val |= RTL8365MB_SDS_NWAY_RESTART_MASK;
 
-	return rtl8365mb_sds_write(priv, RTL8365MB_SDS_REG_NWAY, val);
+	return rtl8365mb_sds_write(priv, sds_index,
+				   RTL8365MB_SDS_REG_NWAY, val);
 }
 
 static bool rtl8365mb_interface_is_serdes(phy_interface_t interface)
@@ -1628,18 +1731,27 @@ static void rtl8365mb_pcs_get_state(struct phylink_pcs *pcs,
 {
 	struct rtl8365mb *mb = pcs_to_rtl8365mb(pcs);
 	struct realtek_priv *priv = mb->priv;
+	u8 sds_index = 0;
 	u16 status;
+	bool is_d;
 	u32 val;
 	int ret;
 
-	/* In-band autonegotiation is not implemented, so the link parameters are
-	 * forced from rtl8365mb_pcs_link_up(). The real link state must still be
-	 * read from the SerDes itself: the embedded DW8051 microcontroller that
+	is_d = rtl8365mb_is_d(priv);
+
+	/* In-band autonegotiation is not implemented, so the link parameters
+	 * are forced from rtl8365mb_pcs_link_up() on family C, and from
+	 * mac_link_up() on family D. The real link state must still be read
+	 * from the SerDes itself: the embedded DW8051 microcontroller that
 	 * the vendor firmware uses to poll the SerDes is kept disabled (see
 	 * rtl8365mb_pcs_config()), so the link status register can be read
 	 * directly through the SDS_INDACS window without racing the auto-poll.
 	 */
-	ret = rtl8365mb_sds_read(priv, RTL8365MB_SDS_REG_LINK_STATUS, &status);
+	if (is_d)
+		sds_index = RTL8365MB_D_SDS_EXT0_INDEX;
+
+	ret = rtl8365mb_sds_read(priv, sds_index,
+				 RTL8365MB_SDS_REG_LINK_STATUS, &status);
 	if (ret) {
 		state->link = false;
 		return;
@@ -1650,6 +1762,23 @@ static void rtl8365mb_pcs_get_state(struct phylink_pcs *pcs,
 	if (!state->link)
 		return;
 
+	if (is_d) {
+		if (state->interface == PHY_INTERFACE_MODE_2500BASEX) {
+			state->duplex = DUPLEX_FULL;
+			state->speed = SPEED_2500;
+		} else {
+			/* Keep what phylink passed in, but never report the
+			 * link up with an unknown speed: mac_link_up() cannot
+			 * force the port with it.
+			 */
+			if (state->speed == SPEED_UNKNOWN)
+				state->speed = SPEED_1000;
+			if (state->duplex == DUPLEX_UNKNOWN)
+				state->duplex = DUPLEX_FULL;
+		}
+		return;
+	}
+
 	/* The speed and duplex are forced; read them back from the values
 	 * programmed into the SerDes MISC register.
 	 */
@@ -1691,6 +1820,12 @@ static void rtl8365mb_pcs_link_up(struct phylink_pcs *pcs,
 	u32 r_speed;
 	int ret;
 
+	/* Family D forces the external MAC ability from mac_link_up(); its
+	 * SDS_MISC fields do not share the family C link-force layout.
+	 */
+	if (rtl8365mb_is_d(priv))
+		return;
+
 	/* The speed field has no value for 2.5 Gbps: the rate is determined by
 	 * the HSGMII SerDes configuration, and the vendor driver programs the
 	 * 1 Gbps value here.
@@ -1955,10 +2090,17 @@ static void rtl8365mb_phylink_get_caps(struct dsa_switch *ds, int port,
 	}
 
 	if (extint->supported_interfaces & RTL8365MB_PHY_INTERFACE_MODE_SGMII &&
-	    mb->sds_supported)
+	    mb->sds_supported) {
 		__set_bit(PHY_INTERFACE_MODE_SGMII,
 			  config->supported_interfaces);
 
+		/* The SerDes rate is not programmed for 10 and 100 Mbit/s on
+		 * family D, see rtl8365mb_pcs_link_up().
+		 */
+		if (rtl8365mb_is_d(priv))
+			config->mac_capabilities &= ~(MAC_10 | MAC_100);
+	}
+
 	if (extint->supported_interfaces & RTL8365MB_PHY_INTERFACE_MODE_HSGMII &&
 	    mb->sds_supported) {
 		__set_bit(PHY_INTERFACE_MODE_2500BASEX,
@@ -2037,7 +2179,7 @@ static void rtl8365mb_phylink_mac_link_down(struct phylink_config *config,
 	/* phylink has no pcs_link_down callback, so on the SerDes path only the
 	 * MAC external interface force is reset here. Clearing the MAC force is
 	 * enough to bring the link down; the SerDes keeps presenting its last
-	 * forced state until the next pcs_link_up() reprograms it.
+	 * forced state (family C) until the next pcs_link_up() reprograms it.
 	 */
 	if (phy_interface_mode_is_rgmii(interface) ||
 	    rtl8365mb_interface_is_serdes(interface)) {
@@ -2072,9 +2214,11 @@ static void rtl8365mb_phylink_mac_link_up(struct phylink_config *config,
 	p = &mb->ports[port];
 	schedule_delayed_work(&p->mib_work, 0);
 
-	/* The SerDes forced link state is programmed by the PCS in
+	/* On family C the SerDes forced link state is programmed by the PCS in
 	 * rtl8365mb_pcs_link_up(); here only the MAC external interface force
-	 * is configured, for both RGMII and SerDes.
+	 * is configured. On family D pcs_link_up() does nothing, and the MAC
+	 * external interface force is the only forced link state, for both
+	 * RGMII and SerDes.
 	 */
 	if (phy_interface_mode_is_rgmii(interface) ||
 	    rtl8365mb_interface_is_serdes(interface)) {
@@ -2087,18 +2231,21 @@ static void rtl8365mb_phylink_mac_link_up(struct phylink_config *config,
 			return;
 		}
 
-		/* The SerDes has its own pause enables; program them from
-		 * the resolved pause modes, as the vendor driver does when
-		 * forcing the link on a SerDes external interface. These
-		 * bits, not the MAC force pause bits, gate pause on the
-		 * SerDes external interface: flow control testing shows
-		 * that pause frames are only emitted with the SerDes TXFC
-		 * bit set, while the MAC force pause bits alone have no
-		 * effect on this port. This is done here rather than in
-		 * rtl8365mb_pcs_link_up() because pcs_link_up() carries no
-		 * pause information.
+		/* Family C: the SerDes has its own pause enables; program
+		 * them from the resolved pause modes, as the vendor driver
+		 * does when forcing the link on a SerDes external
+		 * interface. These bits, not the MAC force pause bits, gate
+		 * pause on the SerDes external interface: flow control
+		 * testing shows that pause frames are only emitted with the
+		 * SerDes TXFC bit set, while the MAC force pause bits alone
+		 * have no effect on this port. This is done here rather
+		 * than in rtl8365mb_pcs_link_up() because pcs_link_up()
+		 * carries no pause information. Family D does not use this
+		 * path: its pause bits are set in the forced-mode register
+		 * by rtl8365mb_d_ext_config_forcemode().
 		 */
-		if (rtl8365mb_interface_is_serdes(interface)) {
+		if (rtl8365mb_interface_is_serdes(interface) &&
+		    !rtl8365mb_is_d(priv)) {
 			u32 val = 0;
 
 			if (tx_pause)
Signature · 1 line
2.53.0
#19 lore raw

Re: [PATCH net-next v12 10/13] net: dsa: realtek: rtl8365mb: add family D SDS13 PCS support

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 2

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] rtl8365mb_phylink_mac_link_up() now skips the SerDes-side pause programming (RTL8365MB_SDS_MISC_REG 0x1D11, SGMII_TXFC BIT(13) /…
- [Low] On family D, rtl8365mb_pcs_config() in drivers/net/dsa/realtek/rtl8365mb_main.c now wraps the external…
- [Low] On family D, rtl8365mb_sds_probe_option() returns early with mb->sds_supported = true (line 1468).

--

net: dsa: realtek: rtl8365mb: add family D SDS13 PCS support

This extends the existing RTL8367S SGMII/HSGMII PCS code to family D switches. On family D the CPU SerDes is reached through the indexed SDS13 window, and the family D SDS_MISC layout and tuning tables come from the vendor RTL8367D API. On family D the patch also skips the pcs_link_up() forcing and the SerDes pause programming, and stops advertising 10/100 on the SerDes port.

Quoted 4 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +0 -0
index 7ad9ef1cbab7d..50ba2fa465808 100644

[ ... ]

drivers/net/dsa/realtek/rtl8365mb_main.c static int rtl8365mb_sds_probe_option(struct realtek_priv *priv) · line 1471

Quoted 12 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +8 -0
@@ -1418,6 +1461,14 @@ static int rtl8365mb_sds_probe_option(struct realtek_priv *priv)
 	int ret;
 	int i;
 
+	/* Family D has a fixed SDS13 programming model and does not use the
+	 * family C option register to select its tuning table.
+	 */
+	if (rtl8365mb_is_d(priv)) {
+		mb->sds_supported = true;
+		return 0;
+	}
+

[Severity: Low]
Since sds_supported is now always true on family D, rtl8365mb_setup() will always call rtl8365mb_sds_raise_rate_limits() on these chips:

drivers/net/dsa/realtek/rtl8365mb_main.c:rtl8365mb_setup() {
    ...
	if (mb->sds_supported) {
		ret = rtl8365mb_sds_raise_rate_limits(priv);
    ...
}

That function writes 0xFFFF to 0x00CF and 0x0398, and sets GENMASK(2, 0) in 0x00D0 and 0x0399. These are the family C port 6 ingress/egress limiter addresses, with the family C 3-bit MSB field layout.

The commit message checks the BYPASS_LINE_RATE (0x03f7) layout against the RTL8367D vendor definitions. It doesn't do the same for these four registers. The comment above rtl8365mb_sds_raise_rate_limits() says the vendor driver raises them "for the whole chip family", and that appears to mean family C.

In this series family D already differs from family C in several other register blocks: the per-port force registers, the 3-bit speed field, the VLAN 4k format, PVID and the LUT.

Do the port 6 rate limiter registers have the same addresses and field widths on the RTL8367D? If they don't, could these writes set bits in registers the driver doesn't mean to touch?

Quoted 3 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +0 -0
 	/* Nothing to probe if no external interface is wired to the SerDes */
 	for (i = 0; i < RTL8365MB_MAX_NUM_EXTINTS; i++) {
 		extint = &mb->chip_info->extints[i];

[ ... ]

Quoted 1 line
drivers/net/dsa/realtek/rtl8365mb_main.c +0 -0
@@ -1546,34 +1620,58 @@ static int rtl8365mb_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode,

[ ... ]

Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +3 -7
-	val = mode << RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_OFFSET(id);
-	ret = regmap_update_bits(priv->map,
-				 RTL8365MB_DIGITAL_INTERFACE_SELECT_REG(id),
-				 RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_MASK(id),
-				 val);
-	if (ret)
-		return ret;
+	if (!is_d) {
+		val = sds_mode << RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_OFFSET(id);
+		ret = regmap_update_bits(priv->map,

drivers/net/dsa/realtek/rtl8365mb_main.c static int rtl8365mb_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode, · line 1672

Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +6 -0
+					 RTL8365MB_DIGITAL_INTERFACE_SELECT_REG(id),
+					 RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_MASK(id),
+					 val);
+		if (ret)
+			return ret;
+	}
 
 	/* Take the SerDes out of reset. The vendor driver does this only
 	 * after the SerDes mux and the interface mode are configured.
 	 */

[Severity: Low]
This isn't a functional bug as far as the testing shows. On family D the DIGITAL_INTERFACE_SELECT mode write in rtl8365mb_pcs_config() is now skipped, and nothing equivalent is written for ext0 (MAC6). Does the RTL8367D vendor sequence leave out this step on purpose? For example, does SDS_MISC[4:0] (0x02/0x12) alone select SGMII/HSGMII?

The commit message only says that the SDS13 window and the SDS_MISC fields differ. The comment just below still says the interface mode is configured before the reset is deasserted.

Could a short comment or a sentence in the commit message explain why family D doesn't need an interface mode select write here?

[ ... ]

Quoted 20 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +6 -10
@@ -2087,18 +2231,21 @@ static void rtl8365mb_phylink_mac_link_up(struct phylink_config *config,
 			return;
 		}
 
-		/* The SerDes has its own pause enables; program them from
-		 * the resolved pause modes, as the vendor driver does when
-		 * forcing the link on a SerDes external interface. These
-		 * bits, not the MAC force pause bits, gate pause on the
-		 * SerDes external interface: flow control testing shows
-		 * that pause frames are only emitted with the SerDes TXFC
-		 * bit set, while the MAC force pause bits alone have no
-		 * effect on this port. This is done here rather than in
-		 * rtl8365mb_pcs_link_up() because pcs_link_up() carries no
-		 * pause information.
+		/* Family C: the SerDes has its own pause enables; program
+		 * them from the resolved pause modes, as the vendor driver
+		 * does when forcing the link on a SerDes external
+		 * interface. These bits, not the MAC force pause bits, gate
+		 * pause on the SerDes external interface: flow control
+		 * testing shows that pause frames are only emitted with the

drivers/net/dsa/realtek/rtl8365mb_main.c static void rtl8365mb_phylink_mac_link_up(struct phylink_config *config, · line 2248

Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +8 -1
+		 * SerDes TXFC bit set, while the MAC force pause bits alone
+		 * have no effect on this port. This is done here rather
+		 * than in rtl8365mb_pcs_link_up() because pcs_link_up()
+		 * carries no pause information. Family D does not use this
+		 * path: its pause bits are set in the forced-mode register
+		 * by rtl8365mb_d_ext_config_forcemode().
 		 */
-		if (rtl8365mb_interface_is_serdes(interface)) {
+		if (rtl8365mb_interface_is_serdes(interface) &&
+		    !rtl8365mb_is_d(priv)) {

[Severity: Medium]
Does flow control still work on the family D SerDes port after this change?

The comment records a measured family C result. On the SerDes external interface, the MAC force pause bits alone have no effect, and pause frames are only sent when the SerDes TXFC bit is set.

On family D, mac_link_up() now skips the SDS_MISC TXFC/RXFC programming. It relies only on the TXPAUSE/RXPAUSE bits that rtl8365mb_d_ext_config_forcemode() writes to the MAC force register.

The family D SDS_MISC update in rtl8365mb_pcs_config() only touches RTL8365MB_D_SDS_MISC_CFG_MASK (bits 11, 10, 9 and 4:0). Any SerDes-side flow control gate on family D would therefore keep its reset value.

Is there an RTL8367D vendor API reference, or a flow control test, showing that family D has no similar SerDes pause gate? The commit message only mentions link testing at 1G SGMII and 2500base-x.

If such a gate does exist, phylink and ethtool would report tx/rx pause as active on port 6 while the hardware never sends or honours pause frames.

Quoted 3 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +0 -0
 			u32 val = 0;
 
 			if (tx_pause)
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/bc42ae96-dc7e-4b6e-b9cc-64cde5dc51ce%40yahoo.com
#20 lore raw

PATCH v12 11/13 net: dsa: realtek: rtl8365mb: refactor L2 MAC handling

In reply to Mieczyslaw Nalewaj

Add L2 MAC pack/unpack helpers and use them in the family C serializers instead of open-coding the byte packing, since the layout of the MAC address words is the same for both families. The now unused per-field MAC masks are dropped.

Rename the family C serializers to rtl8365mb_c_l2_*(), export them and reach them through function pointers in struct rtl8365mb_family_info, so that a following patch can add the family D layout without touching the family C code again.

No functional change.

---
 drivers/net/dsa/realtek/rtl8365mb.h      |   7 ++
 drivers/net/dsa/realtek/rtl8365mb_l2.c   | 125 +++++++++++------------
 drivers/net/dsa/realtek/rtl8365mb_l2.h   |  12 +++
 drivers/net/dsa/realtek/rtl8365mb_main.c |   5 +
 4 files changed, 83 insertions(+), 66 deletions(-)
drivers/net/dsa/realtek/rtl8365mb.h +7 -0
index c59e657..9a69e85 100644
@@ -13,6 +13,8 @@ struct dsa_switch;
 struct netlink_ext_ack;
 struct rtl8365mb_jam_tbl_entry;
 struct rtl8365mb_vlan4k;
+struct rtl8365mb_l2_uc;
+struct rtl8365mb_l2_mc;
 
 struct rtl8365mb_family_info {
 	enum rtl8365mb_family family;
@@ -31,6 +33,11 @@ struct rtl8365mb_family_info {
 	int (*vlan_pvid_port_set)(struct dsa_switch *ds, int port, u16 vid,
 				  struct netlink_ext_ack *extack);
 	int (*vlan_pvid_port_clear)(struct dsa_switch *ds, int port, u16 vid);
+	size_t l2_entry_size;
+	void (*l2_data_to_uc)(const u16 *data, struct rtl8365mb_l2_uc *uc);
+	void (*l2_uc_to_data)(const struct rtl8365mb_l2_uc *uc, u16 *data);
+	void (*l2_data_to_mc)(const u16 *data, struct rtl8365mb_l2_mc *mc);
+	void (*l2_mc_to_data)(const struct rtl8365mb_l2_mc *mc, u16 *data);
 };
 
 const struct rtl8365mb_family_info *
drivers/net/dsa/realtek/rtl8365mb_l2.c +59 -66

291 lines not on this page · raw message

drivers/net/dsa/realtek/rtl8365mb_l2.h +12 -0
index 9470cf0..a9f9ae4 100644
@@ -12,6 +12,18 @@
 
 #include "realtek.h"
 
+#define RTL8365MB_C_L2_ENTRY_SIZE		6
+/* Highest L2 entry size of any supported chip, used for sizing */
+#define RTL8365MB_L2_ENTRY_SIZE			RTL8365MB_C_L2_ENTRY_SIZE
+
+struct rtl8365mb_l2_uc;
+struct rtl8365mb_l2_mc;
+
+void rtl8365mb_c_l2_data_to_uc(const u16 *data, struct rtl8365mb_l2_uc *uc);
+void rtl8365mb_c_l2_uc_to_data(const struct rtl8365mb_l2_uc *uc, u16 *data);
+void rtl8365mb_c_l2_data_to_mc(const u16 *data, struct rtl8365mb_l2_mc *mc);
+void rtl8365mb_c_l2_mc_to_data(const struct rtl8365mb_l2_mc *mc, u16 *data);
+
 int rtl8365mb_l2_get_next_uc(struct realtek_priv *priv, u16 *addr, int port,
 			     struct realtek_fdb_entry *entry);
 int rtl8365mb_l2_add_uc(struct realtek_priv *priv, int port,
drivers/net/dsa/realtek/rtl8365mb_main.c +5 -0
index 50ba2fa..b83e393 100644
@@ -798,6 +798,11 @@ static const struct rtl8365mb_family_info rtl8365mb_family_c = {
 	.vlan_port_reset_pvid = rtl8365mb_c_vlan_port_reset_pvid,
 	.vlan_pvid_port_set = rtl8365mb_c_vlan_pvid_port_set,
 	.vlan_pvid_port_clear = rtl8365mb_c_vlan_pvid_port_clear,
+	.l2_entry_size = RTL8365MB_C_L2_ENTRY_SIZE,
+	.l2_data_to_uc = rtl8365mb_c_l2_data_to_uc,
+	.l2_uc_to_data = rtl8365mb_c_l2_uc_to_data,
+	.l2_data_to_mc = rtl8365mb_c_l2_data_to_mc,
+	.l2_mc_to_data = rtl8365mb_c_l2_mc_to_data,
 };
 
 /**
Signature · 1 line
2.53.0
#21 lore raw

PATCH v12 12/13 net: dsa: realtek: rtl8365mb: make L2/LUT access work on family D

In reply to Mieczyslaw Nalewaj

The L2 lookup table on family D switches (e.g. RTL8367S-VB) differs from family C in ways that make the current FDB/MDB code misbehave:

- An L2 entry is 5 words instead of 6, with a different field layout in words 3 and 4 (port, age, static and multicast member bits).
- There is no EFID and no per-bridge FDB isolation. The register at 0x0A32, used as the per-port EFID register on family C, is the LUT aging timer on family D, so writing an EFID there corrupts it.
- In the table access interface, the SPA field is 3 bits wide and the address register is 12 bits wide, with no address extension bit.
- Only ports 0..7 are present in the LUT and there is no FLUSH_PORT_EXT register.
- A VLAN-unaware bridge reaches the driver with VID 0, where the chip learns in SVL (IVL=0, FID=0). An entry programmed by DSA with IVL set gets a different key than the learned one for the same MAC, so both coexist and the learned one keeps winning.

Teach the table and L2 code about these differences. The L2 entry layout is selected through struct rtl8365mb_family_info, the other differences with rtl8365mb_is_d(). Family C behavior is unchanged.

Specifically:

- rtl8365mb_table: use the family D port mask and address width, and read the hit address from status bits [11:0].
- rtl8365mb_l2: add family D unicast/multicast entry (de)serializers. The IVL bit is set only for a non-zero VID, so VID 0 produces the SVL key (IVL=0, FID=0) and static unicast and multicast entries match the learned ones in a VLAN-unaware bridge. IVL_EN of the VLANs follows the VLAN filtering state (see the VLAN 4k patch), so the key matches the one the chip learns with in VLAN-unaware and VLAN-aware bridges. Entries read back with IVL=0 are reported with VID 0. Use age 6 for static unicast entries as the vendor code does.
Look an entry up before deleting it, so that a missing entry is not allocated by the delete; as the key has no EFID, an entry found on another port or one that is not static is left alone.
- rtl8365mb_main: make port_set_efid() a no-op on family D, add a LUT init step that clears IPMC_HASH and BCAM_DISABLE and writes 3000 to the aging timer register, as dal_rtl8367d_l2_init() does in the vendor RTL8367D API (the unit is not documented), and do not advertise fdb_isolation. Without EFID the bridges cannot be told apart in the LUT, so set max_num_bridges to 1. DSA allocates bridge numbers system-wide, so this does not stop a bridge that already has a number from another switch from being offloaded here as well. Bridges that are offloaded together share the LUT and are separated by the port isolation masks only.

Without EFID, FID 0 is shared by every port that is not in a VLAN-aware
bridge: standalone ports, ports of bridges left to software and the offloaded VLAN-unaware bridge. There is no isolation between them in the LUT, only the port isolation masks. DSA does not program FDB/MDB entries of standalone ports here, as fdb_isolation is not set, so those ports get no host address filtering and their traffic goes to the CPU. A MAC learned in FID 0 on a bridge port may therefore also be hit by traffic from a standalone port, or from a software-bridged one, until the entry ages out or is replaced. Static multicast entries written for a VLAN-unaware bridge use the same key and do not age, so the same may apply to them. This was observed by Gustavo Foletto Mora: with the hosts on standalone ports of the same switch, unicast to a host was dropped once its MAC had been learned on the VLAN-unaware bridge side. With learning off on the bridge ports it was forwarded, and with a VLAN-aware bridge it did not happen.

A host on an offloaded port can use this to keep the MAC of a standalone port in FID 0 on its own port, so that traffic arriving on the standalone port for that MAC is dropped until the entry ages out. This needs a host on the local L2 segment and is bounded by the aging time. Avoiding it needs a per-bridge FID. VLAN 4K entries carry a FID, but they only classify bridges whose ports have a PVID; a bridge without VLANs is classified into FID 0, so that does not help the VLAN-unaware case. It is a known limitation of the chip without EFID.

Register layouts follow the vendor RTL8367D API; the code itself is an independent implementation.

Tested by Gustavo Foletto Mora on a TP-Link EX511 v2 (RTL8367S-VB, CPU port 6 over 1G SGMII to an IPQ5018). With a VLAN-aware bridge: per-VID FDB readback, static entries replacing learned ones and being deleted again on every port and VID, the same MAC as a static entry on two VIDs, MDB entries, VLAN add/delete churn, and moving a port to a second bridge (handled in software). With a VLAN-unaware bridge: a static entry with VID 0 replaces the learned one and traffic follows it, a static entry pointing at the ingress port drops the frames, the MAC relearns on the original port after the delete; traffic to the bridge MAC no longer floods to the WAN port; MDB entries limit the flood to the group members and the flood returns after the delete. Unicast and multicast forwarding were also checked with loopback cables between user ports (known and unknown unicast, static entries on the wrong port, MDB, 20k full-size pings without loss or port errors). MACs of foreign ports (a veth standing in for a Wi-Fi station) become entries on the CPU port through assisted learning. Real Wi-Fi stations, RGMII and 2500base-x were not covered by this test. Leaving a dynamic or foreign-port entry alone in l2_del_uc() was not exercised.

Nothing points to them until the family D info is added together with the chip table entry in the last patch. Until then they are not static and are declared in rtl8365mb_l2.h, so that the build does not warn about unused functions.

---
 drivers/net/dsa/realtek/realtek.h         |   4 +-
 drivers/net/dsa/realtek/rtl8365mb_l2.c    | 126 +++++++++++++++++++++-
 drivers/net/dsa/realtek/rtl8365mb_l2.h    |   6 ++
 drivers/net/dsa/realtek/rtl8365mb_main.c  |  58 +++++++++-
 drivers/net/dsa/realtek/rtl8365mb_table.c |  44 ++++++--
 drivers/net/dsa/realtek/rtl83xx.c         |   5 +-
 6 files changed, 226 insertions(+), 17 deletions(-)
drivers/net/dsa/realtek/realtek.h +3 -1
index c166719..920db50 100644
@@ -78,7 +78,9 @@ struct realtek_priv {
 	 * create/update it. l2_(add|del)_uc uses a single table op and,
 	 * internally, it might not need this lock. However, altering FDB
 	 * may still collide, as well as l2_flush, with fdb_dump iterating
-	 * over FDB.
+	 * over FDB. On the RTL8367S-VB (family D), l2_del_uc also looks the
+	 * entry up before writing it, as two separate table queries, so it
+	 * does depend on this lock.
 	 */
 	struct mutex		l2_lock;
 	struct mii_bus		*user_mii_bus;
drivers/net/dsa/realtek/rtl8365mb_l2.c +124 -2

150 lines not on this page · raw message

drivers/net/dsa/realtek/rtl8365mb_l2.h +6 -0
index a9f9ae4..5bb4e32 100644
@@ -13,6 +13,7 @@
 #include "realtek.h"
 
 #define RTL8365MB_C_L2_ENTRY_SIZE		6
+#define RTL8365MB_D_L2_ENTRY_SIZE		5
 /* Highest L2 entry size of any supported chip, used for sizing */
 #define RTL8365MB_L2_ENTRY_SIZE			RTL8365MB_C_L2_ENTRY_SIZE
 
@@ -24,6 +25,11 @@ void rtl8365mb_c_l2_uc_to_data(const struct rtl8365mb_l2_uc *uc, u16 *data);
 void rtl8365mb_c_l2_data_to_mc(const u16 *data, struct rtl8365mb_l2_mc *mc);
 void rtl8365mb_c_l2_mc_to_data(const struct rtl8365mb_l2_mc *mc, u16 *data);
 
+void rtl8365mb_d_l2_data_to_uc(const u16 *data, struct rtl8365mb_l2_uc *uc);
+void rtl8365mb_d_l2_uc_to_data(const struct rtl8365mb_l2_uc *uc, u16 *data);
+void rtl8365mb_d_l2_data_to_mc(const u16 *data, struct rtl8365mb_l2_mc *mc);
+void rtl8365mb_d_l2_mc_to_data(const struct rtl8365mb_l2_mc *mc, u16 *data);
+
 int rtl8365mb_l2_get_next_uc(struct realtek_priv *priv, u16 *addr, int port,
 			     struct realtek_fdb_entry *entry);
 int rtl8365mb_l2_add_uc(struct realtek_priv *priv, int port,
drivers/net/dsa/realtek/rtl8365mb_main.c +55 -3

88 lines not on this page · raw message

drivers/net/dsa/realtek/rtl8365mb_table.c +34 -10

90 lines not on this page · raw message

drivers/net/dsa/realtek/rtl83xx.c +4 -1
index ad42c05..cfe7d42 100644
@@ -602,7 +602,8 @@ int rtl83xx_port_fdb_add(struct dsa_switch *ds, int port,
 
 	/* Bridge ports use bridge.num as EFID, while standalone ports use
 	 * EFID 0. FDB entries for the CPU port follow the bridge EFID due
-	 * to assisted learning.
+	 * to assisted learning. Chips without an EFID in their L2 table
+	 * (RTL8367S-VB) ignore it in l2_add_uc().
 	 */
 	efid = db.type == DSA_DB_BRIDGE ? db.bridge.num : 0;
 
@@ -654,6 +655,8 @@ int rtl83xx_port_fdb_del(struct dsa_switch *ds, int port,
 	/*
 	 * DSA_DB_BRIDGE ports use bridge number [1..N] as EFID, while
 	 * DSA_DB_PORT use the default EFID (0), not used by any bridge.
+	 * Chips without an EFID in their L2 table (RTL8367S-VB) ignore it in
+	 * l2_del_uc().
 	 */
 	efid = db.type == DSA_DB_BRIDGE ? db.bridge.num : 0;
 
Signature · 1 line
2.53.0
#22 lore raw

Re: [PATCH net-next v12 12/13] net: dsa: realtek: rtl8365mb: make L2/LUT access work on family D

Subject: Re: [PATCH net-next v12 12/13] net: dsa: realtek: rtl8365mb: make L2/LUT access work on family D

drivers/net/dsa/realtek/rtl8365mb_l2.c void rtl8365mb_c_l2_mc_to_data(const struct rtl8365mb_l2_mc *mc, · line 304

Quoted 6 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c +6 -0
+void rtl8365mb_d_l2_data_to_mc(const u16 *data,
+			       struct rtl8365mb_l2_mc *mc)
+{
+	rtl8365mb_l2_data_to_mac(data, mc->key.mac_addr);
+	mc->key.vid = FIELD_GET(RTL8365MB_D_L2_MC_D3_VID_MSK, data[3]);
+	mc->key.ivl = FIELD_GET(RTL8365MB_D_L2_MC_D3_IVL_MSK, data[3]);

I noticed that, unlike rtl8365mb_d_l2_data_to_uc(), this does not clear key.vid when IVL is 0, so the FID could be taken for a VID.

I do not think this is a bug, so I am not changing the logic. I will add a comment here in the next revision, so that it is not mistaken for an omission.

In struct rtl8365mb_l2_mc_key, vid and fid share storage. Reading the field into key.vid therefore also sets key.fid, and with IVL=0 the field holds the FID. Nothing is reinterpreted: it is the same value.

For unicast, vid and fid are separate members, which is why rtl8365mb_d_l2_data_to_uc() has to split the shared hardware field by IVL. For multicast there is nothing to split.

Keeping the field as read also makes a read-modify-write go back to the same key through rtl8365mb_d_l2_mc_to_data(), which uses
ivl = key.ivl && key.vid and writes key.vid as the id. Clearing it for IVL=0, as for unicast, would write a different key for an entry that has a non-zero FID.

The driver only writes FID 0 (VID 0 gives IVL=0, FID=0), so there is no functional difference today. The comment will say that vid and fid share storage and why the value is kept as read.

Best regards,
Mieczyslaw Nalewaj

#23 lore raw

Re: [PATCH net-next v12 12/13] net: dsa: realtek: rtl8365mb: make L2/LUT access work on family D

Hi Mieczyslaw,

Tested v13-pre2's port-based FID on a TP-Link EX511 v2 (RTL8367S-VB), over loopback cables between bridge ports and standalone ports of the same switch:

- 0x07AC/0x07AD read back as intended: FID 1 on the ports of the VLAN-unaware bridge (the uplink included), nothing on the standalone ports or the CPU port, nothing in a VLAN-aware bridge, set and cleared again by live vlan_filtering toggles, and cleared once the ports leave the bridge.
- What failed on v12 with the shared FID 0 now works: unicast between two hosts on standalone ports through the VLAN-unaware bridge with learning on (also when the bridge ports have a PVID, and with frames tagged with a VID the bridge does not have), and static and group entries without a VID no longer catch frames arriving on standalone ports.
- Everything else gives the same results as on v12.

One limitation remains in VLAN-aware bridges, unchanged from v12 as far as I can see: a frame tagged with one of the bridge's VIDs that enters a standalone port is looked up in that VLAN. With VLAN 50 tagged on two bridge ports and the hosts learned there, the frames that come back in through the hosts' own standalone ports are sent towards the bridge ports and dropped by the isolation; with learning off they reach the CPU. Untagged access VLANs are not affected. This needs the same MAC on a standalone port and in the bridge, so I think it is only a corner case.

Family D seems to have a setting for it. The Realtek API in the stock firmware has dal_rtl8367d_l2_lookupHitIsolationAction_set(), with no family C counterpart, which writes bit 0 of 0x0A10. The reset value 0 drops a frame whose lookup hits a port outside the ingress port's isolation mask. I tried two test-only changes on top of v13-pre2:

- 0x0A10 bit 0 set to 1: the case above works (20 of 20 replies), but a frame for a host behind the port it came in on is flooded instead of dropped, since the ingress port is not in its own mask. A static entry or an MDB entry on the ingress port no longer cuts the traffic.
- the same, plus each port in its own isolation mask: the switch still never sends a frame back out of its ingress port (I checked that with a single loop cable first), the case above works, and the static entry and MDB tests pass again.

That was a focused run only: the cabling check, isolation between standalone ports, the VLAN-aware bridge tests (load included) and unicast with learning in the VLAN-unaware bridge. If you want to make this change, I will run the full set of tests on it.

Thanks,
Gustavo

#24 lore raw

Re: [PATCH net-next v12 12/13] net: dsa: realtek: rtl8365mb: make L2/LUT access work on family D

In reply to Mieczyslaw Nalewaj
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 4 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] Family D sets ds->max_num_bridges = 1 in rtl8365mb_setup() (drivers/net/dsa/realtek/rtl8365mb_main.c:3728), but DSA hands out…
- [Medium] The comment in rtl8365mb_d_l2_uc_to_data() (drivers/net/dsa/realtek/rtl8365mb_l2.c:278-284) says that IVL_EN…
- [Medium] rtl8365mb_d_l2_mc_to_data() (rtl8365mb_l2.c:318) writes VID-0 MDB entries of a VLAN-unaware bridge with IVL=0, FID 0.
- [Medium] The family D serializers pick IVL from the VID alone (ivl = key.ivl && key.vid, rtl8365mb_d_l2_uc_to_data() at…

--

net: dsa: realtek: rtl8365mb: make L2/LUT access work on family D

This patch adds L2 entry (de)serializers for family D (RTL8367S-VB). It also adjusts table access for the narrower SPA and address fields, and adds a LUT init step. EFID handling becomes a no-op on family D, fdb_isolation is not advertised, and max_num_bridges is set to 1.

Quoted 4 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c +0 -0
index cd5b333932bee..e98ba5c5f9193 100644

[ ... ]

Quoted 4 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c +0 -0
@@ -240,6 +255,78 @@ void rtl8365mb_c_l2_mc_to_data(const struct rtl8365mb_l2_mc *mc,
 	data[5] |= FIELD_PREP(RTL8365MB_L2_MC_D5_MBR_HI2_MSK, val);
 }
 

[ ... ]

drivers/net/dsa/realtek/rtl8365mb_l2.c void rtl8365mb_c_l2_mc_to_data(const struct rtl8365mb_l2_mc *mc, · line 285

Quoted 11 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c +11 -0
+void rtl8365mb_d_l2_uc_to_data(const struct rtl8365mb_l2_uc *uc,
+			       u16 *data)
+{
+	/* A VLAN-unaware bridge reaches us with VID 0. The chip learns such
+	 * traffic in SVL (IVL=0, FID=0), so use the same key here, otherwise
+	 * the static entry never matches the learned one. Only a real VID
+	 * selects IVL. IVL_EN of the VLANs follows the VLAN filtering state
+	 * (see rtl8365mb_d_vlan_4k_refresh_ivl()), so this matches the key
+	 * the chip learns with.
+	 */
+	bool ivl = uc->key.ivl && uc->key.vid;

[Severity: Medium]
Does this comment still hold when one family D switch offloads two bridges with different vlan_filtering settings?

IVL_EN is decided once for the whole switch, not per bridge. In rtl8365mb_d_want_ivl(), a single filtering user port is enough:

    dsa_switch_for_each_user_port(dp, ds) {
        if (dp->index == port ? filtering :
                    dsa_port_is_vlan_filtering(dp))
            return true;
    }

rtl8365mb_d_vlan_4k_refresh_ivl() then writes that value to every used VID, including the default PVID VLAN:

    vlan4k.ivl_en = want_ivl;

The comment in rtl8365mb_setup() says a bridge that already has a number from another switch can still be offloaded here. So a VLAN-aware bridge and a VLAN-unaware bridge can both be offloaded on this switch.

With configure_vlan_while_not_filtering set, the VLAN-unaware bridge's ports keep PVID 1. Would the chip then learn them in IVL with VID 1, while DSA still passes their FDB/MDB entries with VID 0 and this code writes IVL=0/FID=0?

If so, it looks like the duplicate key problem from the commit message comes back for static FDB entries, and MDB entries would stop limiting the flood. How the chip learns on non-filtering ports is a hardware assumption here.

drivers/net/dsa/realtek/rtl8365mb_l2.c void rtl8365mb_c_l2_mc_to_data(const struct rtl8365mb_l2_mc *mc, · line 286

Quoted 1 line
drivers/net/dsa/realtek/rtl8365mb_l2.c +1 -0
+	u16 id = ivl ? uc->key.vid : uc->key.fid;

[Severity: Medium]
IVL is chosen here from the VID alone, not from whether the bridge is VLAN-aware. Can a VLAN-aware bridge put a static entry into the shared FID 0 domain this way?

A VLAN-aware bridge still produces VID-0 FDB entries. For example, "bridge fdb add MAC dev swpX master static" without a vlan argument makes br_fdb_add() add a VID-0 entry next to the per-VLAN ones. DSA passes the VID through unchanged, so the path is:

    rtl83xx_port_fdb_add(vid 0)
      -> rtl8365mb_l2_add_uc()
        -> rtl8365mb_d_l2_uc_to_data()

and it writes a static (age 6) entry with IVL=0/FID 0.

The commit message says standalone and software-bridged ports look up in that same FID 0. Would unicast to MAC arriving on a standalone port then hit the swpX entry and be dropped by the isolation mask? The entry is static, so it would never age out.

In VLAN-aware mode the bridge treats VID-0 entries as matching nothing, so the software FDB and the hardware LUT would disagree. On family C the same entry was written with IVL=1, VID 0 and EFID separation, so it did not affect other ports.

The commit message notes that with a VLAN-aware bridge the drop "did not happen". Does that observation cover only learned entries, not static VID-0 ones like this?

Quoted 6 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c +6 -0
+
+	memset(data, 0, RTL8365MB_D_L2_ENTRY_SIZE * 2);
+	rtl8365mb_l2_mac_to_data(uc->key.mac_addr, data);
+	data[3] = FIELD_PREP(RTL8365MB_D_L2_UC_D3_VID_MSK, id) |
+		  FIELD_PREP(RTL8365MB_D_L2_UC_D3_IVL_MSK, ivl) |
+		  FIELD_PREP(RTL8365MB_D_L2_UC_D3_PORT_LO_MSK, uc->port & 0x3);

[ ... ]

drivers/net/dsa/realtek/rtl8365mb_l2.c void rtl8365mb_c_l2_mc_to_data(const struct rtl8365mb_l2_mc *mc, · line 318

Quoted 5 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c +5 -0
+void rtl8365mb_d_l2_mc_to_data(const struct rtl8365mb_l2_mc *mc,
+			       u16 *data)
+{
+	/* Same as for unicast: VID 0 means a VLAN-unaware bridge, use SVL. */
+	bool ivl = mc->key.ivl && mc->key.vid;

[Severity: Medium]
VID-0 MDB entries end up in the shared FID 0 SVL key, and rtl8365mb_l2_add_mc() makes them static:

    mc.member |= BIT(port);
    mc.is_static = 1;

Family D has no EFID, since rtl8365mb_port_set_efid() returns 0. It also does not set fdb_isolation, so standalone ports get no host MDB entries and share FID 0 with the VLAN-unaware bridge. Normal IGMP/MLD snooping on the bridge would then install non-aging entries {G -> bridge ports}.

Would multicast for G arriving on a standalone port (for example a WAN stream used by igmpproxy) hit that entry and go to the bridge ports? The standalone port's CPU-only isolation mask would then drop it instead of delivering it to the CPU.

Any LAN host could trigger this just by sending membership reports, and it would last as long as the membership is refreshed.

The commit message calls the unicast case "bounded by the aging time" and "a known limitation of the chip", and only says the same "may apply" to static multicast entries. These entries do not age, and they come from the choice to offload VID-0 MDB entries into the shared key.

Could family D avoid offloading VID-0 MDB entries instead, for example by returning -EOPNOTSUPP for them?

Quoted 2 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c +2 -0
+
+	memset(data, 0, RTL8365MB_D_L2_ENTRY_SIZE * 2);

[ ... ]

Quoted 4 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +0 -0
index b83e39314708f..bfd7e303ca254 100644

[ ... ]

Quoted 9 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +2 -3
@@ -3672,9 +3714,19 @@ static int rtl8365mb_setup(struct dsa_switch *ds)
 		goto out_teardown_irq;
 
 	ds->assisted_learning_on_cpu_port = true;
-	ds->fdb_isolation = true;
-	/* The EFID is 3 bits, but EFID 0 is reserved for standalone ports */
-	ds->max_num_bridges = FIELD_MAX(RTL8365MB_EFID_MASK);
+	if (!rtl8365mb_is_d(priv)) {
+		ds->fdb_isolation = true;

drivers/net/dsa/realtek/rtl8365mb_main.c static int rtl8365mb_setup(struct dsa_switch *ds) · line 3728

Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +10 -0
+		/* The EFID is 3 bits, but EFID 0 is reserved for standalone */
+		ds->max_num_bridges = FIELD_MAX(RTL8365MB_EFID_MASK);
+	} else {
+		/* No EFID, so bridges cannot be told apart in the LUT: allow
+		 * at most one offloaded bridge. Bridge numbers are allocated
+		 * system-wide by DSA, so this does not stop a bridge that
+		 * already has a number from another switch from being
+		 * offloaded here as well.
+		 */
+		ds->max_num_bridges = 1;

[Severity: Medium]
Can this block bridge offload on this switch completely if another DSA switch in the system already holds bridge number 1?

For a new bridge, dsa_bridge_num_get() in net/dsa/dsa.c picks the next free number from one global bitmap:

bridge_num = find_next_zero_bit(&dsa_fwd_offloading_bridges,
DSA_MAX_NUM_OFFLOADING_BRIDGES, 1);
if (bridge_num > max)
return 0;

If bit 1 is taken, for example by a family C rtl8365mb, mv88e6xxx, felix, sja1105 or a second RTL8367S-VB, this returns 2 or more and is rejected with max = 1. dsa_port_bridge_create() then fails:

    bridge->num = dsa_bridge_num_get(br, ds->max_num_bridges);
    if (ds->max_num_bridges && !bridge->num) {
        NL_SET_ERR_MSG_MOD(extack,
                           "Range of offloadable bridges exceeded");
        kfree(bridge);
        return -EOPNOTSUPP;
    }

The bridge then falls back to software, even if it would be the only bridge on this switch.

The comment and commit message cover only the other direction, where this limit is not an upper bound. Whether offload works here then depends on the order in which bridges were created on other switches.

Would a driver-side check in port_bridge_join that tracks the single bridge offloaded on this switch be a better fit? Family D ignores the EFID, so max_num_bridges could then stay 0.

Quoted 4 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +1 -0
+	}
 
 	ds->configure_vlan_while_not_filtering = true;
 
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/bc42ae96-dc7e-4b6e-b9cc-64cde5dc51ce%40yahoo.com
#25 lore raw

PATCH v12 13/13 net: dsa: realtek: rtl8365mb: add support for RTL8367S-VB

In reply to Mieczyslaw Nalewaj

Add the RTL8367S-VB (chip ID 0x6642, version 0x0010) to the chip table. It is the first chip of family D, whose handling was added in the preceding patches, so this is the patch that makes it reachable.

The SGMII/HSGMII SerDes of this chip sits on port 6 and the MII/TMII/RMII/RGMII interface on port 7, as on family C, but the external interface indices are one lower (EXT0 and EXT1 instead of EXT1 and EXT2). The chip reuses the existing initialization jam table, taken as is from the RTL8367C code; it has not been compared with the vendor RTL8367D initialization. It was used on the tested hardware (see below).

The chip has 8 ports (0-4, 6 and 7), which is described by port_mask in its chip info, as for the other chips. rtl8365mb_family_d selects the family D implementations added in the preceding patches: the force-mode configuration, the VLAN 4k accessors, the PVID handling and the L2 entry (de)serializers.

The L2 learning limit is the same as on family C (2112 entries), as given by the Realtek rtl8367 common API (rtl8367_common V1.4.2), so RTL8365MB_LEARN_LIMIT_MAX needs no per-family handling; only its comment is updated.

Tested on a TP-Link Archer AX55 v1 (RTL8367S-VB, CPU port over HSGMII (2500base-x) to an IPQ5018) with bridge VLAN filtering and per-port PVIDs, and on a TP-Link EX511 v2 (RTL8367S-VB, CPU port over 1G SGMII to an IPQ5018). RGMII mode has not been tested. See the cover letter for details.

---
 drivers/net/dsa/realtek/Kconfig          |  3 +-
 drivers/net/dsa/realtek/rtl8365mb.h      |  4 --
 drivers/net/dsa/realtek/rtl8365mb_main.c | 55 +++++++++++++++++++++---
 3 files changed, 51 insertions(+), 11 deletions(-)
drivers/net/dsa/realtek/Kconfig +2 -1
index f1530ba..e366632 100644
@@ -35,7 +35,8 @@ config NET_DSA_REALTEK_RTL8365MB
 	depends on NET_DSA_REALTEK_SMI || NET_DSA_REALTEK_MDIO
 	select NET_DSA_TAG_RTL8_4
 	help
-	  Select to enable support for Realtek RTL8365MB-VC and RTL8367S.
+	  Select to enable support for Realtek RTL8365MB-VC, RTL8367S and
+	  RTL8367S-VB.
 
 config NET_DSA_REALTEK_RTL8366RB
 	tristate "Realtek RTL8366RB switch driver"
drivers/net/dsa/realtek/rtl8365mb.h +0 -4
index 9a69e85..c280e62 100644
@@ -43,10 +43,6 @@ struct rtl8365mb_family_info {
 const struct rtl8365mb_family_info *
 rtl8365mb_get_family_info(struct realtek_priv *priv);
 
-int rtl8365mb_d_ext_config_forcemode(struct realtek_priv *priv, int port,
-				     bool link, int speed, int duplex,
-				     bool tx_pause, bool rx_pause);
-
 static inline bool rtl8365mb_is_d(struct realtek_priv *priv)
 {
 	return rtl8365mb_get_family_info(priv)->family == RTL8365MB_FAMILY_D;
drivers/net/dsa/realtek/rtl8365mb_main.c +49 -6

91 lines not on this page · raw message

Signature · 1 line
2.53.0
#26 lore raw

Hi Mieczyslaw, Oleksij,

On a TP-Link EX511 v2 (RTL8367S-VB, family D), with v12 on top of the rtl8365mb DCB series, an untagged frame that the switch forwards to a port where its VLAN is egress-tagged leaves with PCP 1. With v12's family D code before the rebase (v12-pre3 in OpenWrt PR #19644), without the DCB series, it leaves with PCP 0.

Test: a VLAN-aware bridge with lan2 and lan3 as untagged members of VLAN 100 (PVID 100), then lan3 made a tagged member ("bridge vlan add dev lan3 vid 100 pvid"). 100 frames per case sent into lan2 and counted by PCP behind lan3, over loopback cables:

- untagged: all leave tagged with PCP 1 (without the DCB series: PCP 0)
- tagged with PCP 1 or 5: the PCP is kept
- lan3 untagged again: all leave untagged

CONFIG_DCB is not set, so only the baseline from rtl8365mb_setup() runs. The untagged PCP register (0x0851-0x0852) reads 0 in both cases, while the port priority (0x0877-0x0878) goes from 0 to 1 with the series (IEEE8021Q_TT_BE, set by rtl83xx_qos_init_port()). So on this chip the PCP added to an untagged frame seems to follow the frame's internal priority (here the port priority), not 0x0851, and untagged traffic leaves a trunk as Background (PCP 1) instead of Best Effort. I could not change the port priority to confirm it (no CONFIG_DCB).

The Realtek API in the board's stock firmware points the same way: for family C the PVID is set together with a priority, written at 0x0851; for family D, dal_rtl8367d_vlan_portPvid_set() writes only the VID and rejects any priority other than 0, and dal_rtl8367d_qos_init() sets the port priority to 0.

The rest of our tests give the same results on v12 as on v12-pre3. Tested on OpenWrt's 6.18.44 with both series backported (PR #19644).

Thanks,
Gustavo

#27 lore raw
Quoted 6 lines · On 21/11/2026 Gustavo Foletto Mora wrote:

an untagged frame that the switch forwards to a port where its VLAN is egress-tagged leaves with PCP 1. [...] without the DCB series, it leaves with PCP 0.
[...]
So on this chip the PCP added to an untagged frame seems to follow the frame's internal priority (here the port priority), not 0x0851 [...]

Hi Gustavo,

Thank you for the detailed test and for narrowing it down to the register values.

This series does not touch QoS, so I think the difference comes from the DCB series. Reading rtl8365mb_qos_set_port_prio(), it does this on every port, with no family check:

- writes iprio (IEEE8021Q_TT_BE, which is 1; Background is 0) to the

    port priority register (0x0877..0x0878),

- writes untag_pcp (0 for Best Effort) to 0x0851..0x0852.

On family C both registers work, so an untagged frame gets PCP 0 and internal priority 1. On family D, as you measured, 0x0851 has no visible effect, and nothing in the backend programs an internal priority -> PCP mapping. So the frame leaves with the PCP that matches its internal priority, i.e. 1. That is what I expect from your data, but I have not confirmed it on hardware.

Note that setting the port priority to 0 on family D would not be a fix:
that is Background internally, below what ingress PCP 0 gets, so untagged traffic would be treated worse than tagged Best Effort.

Two questions, if you have time:

1. Does a non-zero value written to 0x0851 on your board change anything (PCP of untagged frames, or the register reading back)? The backend writes it unconditionally today.
2. Does the Realtek API in your stock firmware have an 802.1p remarking table (internal priority -> PCP, with a per-port enable) for this chip, and at which registers? If so, the family D fix would be to program the inverse of the ingress mapping, so that internal priority 1 leaves as PCP 0.

I do not plan to change anything in this series for this. I think it should be raised against the DCB series (Oleksij Cc'd), unless you see something in v13 that I missed.

Best regards,
Mieczyslaw

#28 lore raw

Hi Mieczyslaw,

Quoted 2 lines · On 21/11/2026 Mieczyslaw Nalewaj wrote:

1. Does a non-zero value written to 0x0851 on your board change anything (PCP of untagged frames, or the register reading back)?

Not yet answered: on my test image the switch registers are read-only from userspace (regmap debugfs) and CONFIG_DCB is not set, so nothing writes 0x0851 other than the baseline's 0. It needs a test kernel that allows debugfs writes; I will report back if I do that.

Quoted 3 lines

2. Does the Realtek API in your stock firmware have an 802.1p remarking table (internal priority -> PCP, with a per-port enable) for this chip, and at which registers?

Yes. The family D functions write the same registers as family C's rtl8367c_setAsicRemarkingDot1p*():

- dal_rtl8367d_qos_1pRemarkEnable_set(): per-port enable, bit 12 of 0x000E + 0x20 * port
- dal_rtl8367d_qos_1pRemark_set(): internal priority -> PCP, 0x1211 for priorities 0-3 and 0x1212 for 4-7, 3 bits per priority at a 4-bit stride
- dal_rtl8367d_qos_1pRemarkSrcSel_set(): the remark source, 0x09DF bit 2

dal_rtl8367d_qos_init() clears the per-port enable on every port.

One thing to keep in mind: the remark applies to every frame that leaves the port tagged, not only to the untagged ones. If I read the baseline's priority decision right (port priority only, weights 0001 0000 0000 0000 at 0x087b), every frame gets internal priority 1, so an inverse table would also turn tagged PCP 5 into PCP 0, while today tagged frames keep their PCP (1 and 5 measured). With an apptrust that includes PCP, the inverse table would keep the tagged PCPs and give untagged frames PCP 0. I have not tried any of this on hardware.

Thanks,
Gustavo

#29 lore raw

Hi Gustavo, Mieczyslaw,

thank you. I have no family D hardware, so only some pointers from family C.

Quoted 5 lines · On 21/11/2026 Gustavo Foletto Mora wrote:
Quoted 2 lines · On 21/11/2026 Mieczyslaw Nalewaj wrote:

1. Does a non-zero value written to 0x0851 on your board change anything (PCP of untagged frames, or the register reading back)?

Not yet answered: on my test image the switch registers are read-only

On family C the added tag takes its PCP from 0x0851/0x0852. If family D ignores that field, the tag probably carries the internal priority unconverted.

Other places that can set this PCP on family C, in case they matter on family D:

- remarking, bit 12 of 0x000e + 0x20 * port (off after reset)
- 0x093a bit 0: when set, an untagged IPv4 frame takes its PCP from the DSCP table

Quoted 1 line

[...] so an inverse table would also turn tagged PCP 5 into PCP 0

Agreed, without PCP trust that table would change tagged frames too.

Family D is not merged, so the DCB code has no bug in net-next and needs no Fixes: tag. I think the family D part belongs behind a hook in rtl8365mb_family_info, like VLAN, PVID and L2 in v12.

Regards,
Oleksij

#30 lore raw

Hi Oleksij,

Quoted 7 lines · Oleksij Rempel

Hi Gustavo, Mieczyslaw,

thank you. I have no family D hardware, so only some pointers from family C.

Quoted 1 line · On 21/11/2026 Gustavo Foletto Mora wrote:

On 21/11/2026 Mieczyslaw Nalewaj wrote:

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

1. Does a non-zero value written to 0x0851 on your board change anything (PCP of untagged frames, or the register reading back)?

Not yet answered: on my test image the switch registers are read-only

On family C the added tag takes its PCP from 0x0851/0x0852. If family D ignores that field, the tag probably carries the internal priority unconverted.

That matches what Gustavo observed on the RTL8367S-VB: without 0x0851/0x0852, newly inserted 802.1Q tags take their PCP directly from the frame's internal priority.

Quoted 6 lines

Other places that can set this PCP on family C, in case they matter on family D:

- remarking, bit 12 of 0x000e + 0x20 * port (off after reset)
- 0x093a bit 0: when set, an untagged IPv4 frame takes its PCP from the DSCP table

Good to know, thanks. Numbering the internal priorities like PCP values on family D (matching the vendor RTL8367D API) makes the newly inserted tag match the traffic type without needing remarking.

Quoted 7 lines
Quoted 1 line

[...] so an inverse table would also turn tagged PCP 5 into PCP 0

Agreed, without PCP trust that table would change tagged frames too.

Family D is not merged, so the DCB code has no bug in net-next and needs no Fixes: tag. I think the family D part belongs behind a hook in rtl8365mb_family_info, like VLAN, PVID and L2 in v12.

Agreed. I have refactored the QoS priority handling behind rtl8365mb_family_info hooks (qos_iprio_to_hw, qos_hw_to_iprio and qos_set_untag_pcp) and implemented the PCP-numbered family D hooks on top of that in v14, which I will send shortly.

Regards,
Mieczyslaw

#31 lore raw
In reply to Mieczyslaw Nalewaj
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit message says "The chip has 8 ports (0-4, 6 and 7)", but that list names 7 ports: five UTP ports (0-4) and the two…
- [Low] The new rtl8365mb_family_d descriptor sets .jam_table = rtl8365mb_init_jam_8365mb_vc.

--

net: dsa: realtek: rtl8365mb: add support for RTL8367S-VB

This patch adds the RTL8367S-VB (chip ID 0x6642, version 0x0010) to the rtl8365mb chip table. It also adds a new rtl8365mb_family_d descriptor that selects the family D implementations added earlier in the series. It also makes rtl8365mb_d_ext_config_forcemode() static and updates the Kconfig help text and the RTL8365MB_LEARN_LIMIT_MAX comment.

Quoted 2 lines

The chip has 8 ports (0-4, 6 and 7), which is described by port_mask in its chip info, as for the other chips.

[Severity: Low]
Is the count here correct? The list (0-4, 6 and 7) names 7 ports. The new entry in rtl8365mb_chip_infos[] matches the list, not the count:

    .port_mask = PORT_MASK(GENMASK(4, 0) | BIT(6) | BIT(7)),

The 8 seems to come from rtl8365mb_detect(), where priv->num_ports = fls(mb->chip_info->port_mask). That counts up to the highest port index, not the number of ports present.

Could this say 7 ports, or say that the port indices run 0-7 with port 5 absent?

Quoted 4 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +0 -0
index bfd7e303ca254..d4a886435876b 100644

[ ... ]

drivers/net/dsa/realtek/rtl8365mb_main.c static const struct rtl8365mb_family_info rtl8365mb_family_c = { · line 835

Quoted 8 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +4 -0
@@ -817,6 +829,24 @@ static const struct rtl8365mb_family_info rtl8365mb_family_c = {
 	.l2_mc_to_data = rtl8365mb_c_l2_mc_to_data,
 };
 
+static const struct rtl8365mb_family_info rtl8365mb_family_d = {
+	.family = RTL8365MB_FAMILY_D,
+	.jam_table = rtl8365mb_init_jam_8365mb_vc,
+	.jam_size = ARRAY_SIZE(rtl8365mb_init_jam_8365mb_vc),

[Severity: Low]
Can the RTL8367C jam table be written to family D silicon without first checking it against the vendor RTL8367D init?

On every RTL8367S-VB probe, rtl8365mb_switch_init() writes all of these register/value pairs right after reset. It then writes rtl8365mb_init_jam_common. Neither table is filtered for family D:

rtl8365mb_switch_init() {
    ...
	if (fi->jam_table) {
		for (i = 0; i < fi->jam_size; i++) {
			ret = regmap_write(priv->map, fi->jam_table[i].reg,
					   fi->jam_table[i].val);
    ...
}

The series already shows that register meanings change between families in this address space. For example, 0x0A32 is the per-port EFID register on family C but the LUT aging timer on family D.

rtl8365mb_init_jam_common also writes 0x020E to 0x0A30:

    { 0x03Fa, 0x0007 }, { 0x08C8, 0x00C0 }, { 0x0A30, 0x020E },

The driver defines 0x0A30 as the family D LUT_CFG register, with only BIT(4) and BIT(6) documented. This value sets bits 1, 2, 3 and 9, which have no documented meaning on family D. rtl8365mb_d_lut_init() only clears bits 4 and 6.

0x13F9 (EXT_TXC_DLY) does look handled: rtl8365mb_ext_config_rgmii() clears the EXT1 RGMII TX delay field when port 7 is set up for RGMII.

None of the other family-specific entries is corrected that way:

the 0x13EB and 0x1303/0x1304 pad controls
0x13E2
the 0x121E/0x1233/0x1237/0x1239/0x123A flow-control thresholds 0x0301, 0x1349, 0x18E0, 0x122B, 0x1305 and 0x13F0

Testing covered only the SGMII/HSGMII CPU port, and RGMII was not tested.

Would it be better to take the init sequence from the vendor RTL8367D sources, or to leave .jam_table NULL for family D? rtl8365mb_switch_init() already handles a NULL table.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/bc42ae96-dc7e-4b6e-b9cc-64cde5dc51ce%40yahoo.com