Skip to contentSkip to conversation

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

PATCH Superseded Mieczyslaw Nalewaj 2 participants 23 messages Nov 24 – Nov 27 1 message not in the archive

Subsystems (5)

v14 of 20 Superseded Latest is v20 →

lore
Share & tools
lore

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

#1 lore raw

v14 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, SerDes (SDS13) and untagged PCP 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, where a VLAN-unaware bridge (VID 0) is isolated in FID 1 using port-based FID, and where LUT hits outside the ingress isolation mask fall back to flooding within the isolation mask (0x0A10 bit 0) with each port included in its own mask.
Patch 13 refactors the QoS priority handling: the conversion between the traffic types of the shared QoS layer and the chip's priorities, and the programming of the PCP of untagged frames, move behind hooks in the family info (no functional change).
Patch 14 numbers the internal priorities like PCP values on family D, as the vendor API does, so that untagged frames keep PCP 0 and the PCP, DSCP and port priority tables stay consistent with the traffic type numbering of the shared QoS layer. Family D has no separate untagged-PCP register (0x0851-0x0852).
Patch 15 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), and the QoS handling through family info hooks only (patches 13 and 14). The RTL8367S-VB has 8 ports, described by port_mask in its chip info (patch 15). On family D, FDB/MDB offload is available, but there is no per-bridge EFID. Instead, port-based FID (FID 1) isolates the offloaded VLAN-unaware bridge from standalone and software-bridged ports in FID 0, 0x0A10 bit 0 (with self-bits in the port isolation masks) ensures tagged frames on standalone ports matching an IVL bridge VLAN flood to the CPU instead of dropping, and 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).

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.

Gustavo Foletto Mora tested the L2/LUT handling with port-based FID isolation (register readback across live vlan_filtering toggles and bridge leave, unicast between standalone ports through a VLAN-unaware bridge) and the lookup-hit isolation fallback (0x0A10) with self-port isolation masks.

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, real Wi-Fi stations, flow control on the family D SerDes port and DCB priority trust on family D. The QoS refactor in 13/15 changes no register values, but has not been retested on hardware yet.

---
v14:
- 4/15: drop the unused extint variable in

    rtl8365mb_d_ext_config_forcemode(); no functional change, tags kept

- 7/15: restore the entry whose write failed too when rolling back the IVL_EN rewrite in rtl8365mb_d_vlan_4k_set_ivl(), as the write may have reached the chip before the error was reported; correct the comment on vlan_4k_used (rtl8365mb family D only) (Sashiko)
- 10/15: say in the commit message that the port 6 rate limiter registers were not compared with the vendor RTL8367D API and that flow control on the family D SerDes port was not tested (Sashiko)
- 12/15: in rtl8365mb_port_vlan_filtering(), write PBFIDEN before PBFID when VLAN filtering is enabled on a bridged port (PBFID first otherwise), as rtl8365mb_port_set_efid() does, so that a port is not left learning in FID 0 with port-based FID enabled (Sashiko); note that bridges already assigned a number from another switch share FID 1; drop the else after return in rtl8365mb_port_set_efid() and note in the comments of the family D L2 serializers that an entry with IVL=0 and FID 0 is written back with FID 1 (no functional change)
- 13/15 (new): refactor the QoS priority handling behind rtl8365mb_family_info hooks (qos_iprio_to_hw, qos_hw_to_iprio, qos_set_untag_pcp) instead of rtl8365mb_is_d() checks in rtl8365mb_qos.c, like VLAN, PVID and L2; no functional change (Oleksij Rempel)
- 14/15: add the family D implementations of the QoS hooks; say in the commit message that DCB priority trust with a non-zero default priority was not tested on family D (Sashiko)
- 15/15: say in the commit message that the common init jam table is also applied to family D without comparison with the vendor RTL8367D initialization (Sashiko); wire up the family D QoS hooks in rtl8365mb_family_d

v13: https://lore.kernel.org/netdev/[email protected]/
- 7/14: write IVL_EN cleared when a 4K entry loses its last member, so that an emptied entry is not left in IVL (Sashiko); move the IVL_EN rewrite into rtl8365mb_d_vlan_4k_set_ivl(), which 12/14 also uses on its error path; Tested-by from Gustavo Foletto Mora kept after retesting the changed scan and empty-entry paths
- 12/14: comment on the shared vid/fid storage in rtl8365mb_d_l2_data_to_mc(); unlike the v12 attempt that took FID 1 from VLAN 4K entries (which failed for bridges without a PVID), isolate the offloaded VLAN-unaware bridge from standalone ports using family D's per-port PBFID registers (0x07AC / 0x07AD + port, assigning FID 1 to VLAN-unaware bridge ports and serializing VID 0 entries with FID 1), keeping standalone ports in FID 0; set 0x0A10 bit 0 and include each port in its own isolation mask on family D so tagged frames on standalone ports matching an IVL bridge VLAN reach the CPU instead of dropping; if programming the port-based FID fails in rtl8365mb_port_vlan_filtering(), restore IVL_EN through rtl8365mb_d_vlan_4k_set_ivl(); drop the Tested-by tags of Stanislaw Pal and Oleg Gavrilov on 12/14 as the L2/bridge FID path changed; Tested-by from Gustavo Foletto Mora kept after retesting
- 13/14 (new): number family D internal priorities like PCP values, as the vendor API does, converting from traffic types at the register boundary, so untagged frames keep PCP 0 (reported and tested by Gustavo Foletto Mora)
- 14/14: patch text is unchanged, but chip behavior changed through 12/14 and 13/14; Gustavo reconfirmed his tag on the full series; Linus, Oleg, please reconfirm yours

v12: https://lore.kernel.org/netdev/[email protected]/
- 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 (15):
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: refactor QoS priority handling
net: dsa: realtek: rtl8365mb: use PCP numbering 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             |  12 +-
 drivers/net/dsa/realtek/rtl8365mb.h           |  55 ++
 drivers/net/dsa/realtek/rtl8365mb_l2.c        | 269 ++++--
 drivers/net/dsa/realtek/rtl8365mb_l2.h        |  21 +
 drivers/net/dsa/realtek/rtl8365mb_main.c      | 821 +++++++++++++++---
 drivers/net/dsa/realtek/rtl8365mb_qos.c       | 134 ++-
 drivers/net/dsa/realtek/rtl8365mb_qos.h       |  10 +
 drivers/net/dsa/realtek/rtl8365mb_table.c     |  44 +-
 drivers/net/dsa/realtek/rtl8365mb_vlan.c      | 508 ++++++++++-
 drivers/net/dsa/realtek/rtl8365mb_vlan.h      |  28 +
 drivers/net/dsa/realtek/rtl83xx.c             |   5 +-
 13 files changed, 1683 insertions(+), 229 deletions(-)
 create mode 100644 drivers/net/dsa/realtek/rtl8365mb.h
Signature · 1 line
2.53.0
#2 lore raw

PATCH v14 1/15 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 v14 2/15 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

Re: [PATCH net-next v14 02/15] net: dsa: realtek: rtl8365mb: add chip family infrastructure

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] This patch removes the kernel-doc entries '@jam_table: chip- specific initialization jam table' and '@jam_size: size of the chip's…

--

net: dsa: realtek: rtl8365mb: add chip family infrastructure

This patch adds enum rtl8365mb_family and struct rtl8365mb_family_info, which hold the data shared by all chips of one family (the family id and the init jam table). struct rtl8365mb_chip_info now points to a family_info instance, and all existing chips use RTL8365MB_FAMILY_C. rtl8365mb_get_family_info() and rtl8365mb_is_d() are declared in a new rtl8365mb.h.

Quoted 5 lines
drivers/net/dsa/realtek/rtl8365mb.h new file +0 -0
new file mode 100644
index 0000000000000..7b0c7109378c6

[ ... ]

drivers/net/dsa/realtek/rtl8365mb.h line 18

Quoted 7 lines
drivers/net/dsa/realtek/rtl8365mb.h new file +7 -0
+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;
+};

[Severity: Low]
This isn't a bug, but should struct rtl8365mb_family_info have a kernel-doc block?

The patch removes these lines from the struct rtl8365mb_chip_info kernel-doc in rtl8365mb_main.c:

* @jam_table: chip-specific initialization jam table
* @jam_size: size of the chip's jam table

The jam_table and jam_size fields themselves move unchanged into struct rtl8365mb_family_info. That struct has no kernel-doc, and the new family member isn't documented either. struct rtl8365mb_extint and struct rtl8365mb_chip_info in the same driver still document every member.

The struct has no /** marker, so kernel-doc won't warn about it. Later patches in the series add about 18 more members to this struct (ext_config_forcemode, vlan_4k_read/write, vlan_port_get_pvid, l2_entry_size, the l2_*_to_* converters and the qos_* hooks), and none of them are documented by the end of the series.

Could a kernel-doc block be added here that keeps the removed @jam_table and @jam_size descriptions, describes @family, and covers the members added later in the series?

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/874b29a3-f47f-4bf2-a0f6-2f9fea712f4c%40yahoo.com
#5 lore raw

PATCH v14 3/15 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
#6 lore raw

PATCH v14 4/15 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 | 108 +++++++++++++++++++++++
 2 files changed, 112 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 +108 -0

126 lines not on this page · raw message

Signature · 1 line
2.53.0
#7 lore raw

PATCH v14 5/15 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 c932493..ae01cd4 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),
@@ -1848,6 +1894,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;
@@ -1877,8 +1925,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
#8 lore raw

PATCH v14 6/15 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 ae01cd4..687939d 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
#9 lore raw

PATCH v14 7/15 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. An entry that loses its last member is written back with IVL_EN cleared, as in its reset state, so that it is not left in IVL after it drops out of the bitmap. The rewrite itself is a separate function, rtl8365mb_d_vlan_4k_set_ivl(), so that an error path can restore the previous state.

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        |   8 +
 drivers/net/dsa/realtek/rtl8365mb_main.c |  13 ++
 drivers/net/dsa/realtek/rtl8365mb_vlan.c | 185 ++++++++++++++++++++++-
 drivers/net/dsa/realtek/rtl8365mb_vlan.h |   9 ++
 4 files changed, 213 insertions(+), 2 deletions(-)
drivers/net/dsa/realtek/realtek.h +8 -0
index dacb780..fda385e 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,12 @@ struct realtek_priv {
 	 * deleting port VLAN memberships and PVID configurations.
 	 */
 	struct mutex		vlan_lock;
+	/* VIDs with a non-empty 4K VLAN entry written by rtl8365mb on family
+	 * D (left empty by other chips and drivers), 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 687939d..24635fe 100644
@@ -2303,8 +2303,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 +183 -2

225 lines not on this page · raw message

drivers/net/dsa/realtek/rtl8365mb_vlan.h +9 -0
index 009b127..f6230eb 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,9 @@ 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);
+
+bool rtl8365mb_d_want_ivl(struct dsa_switch *ds, int port, bool filtering);
+int rtl8365mb_d_vlan_4k_set_ivl(struct dsa_switch *ds, bool want_ivl);
+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
#10 lore raw

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

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: 3 · Low: 1

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 decides IVL once for the whole switch, and that decision is applied to every 4K VLAN entry.
- [Medium] When a vlan_filtering change flips the switch-wide IVL state, rtl8365mb_port_vlan_filtering() -> rtl8365mb_d_vlan_4k_refresh_ivl()…
- [Medium] rtl8365mb_vlan_4k_port_set() updates the vlan_4k_used bitmap only after fi->vlan_4k_write() succeeds.
- [Low] The comment on rtl8365mb_d_want_ivl() says SVL is needed to match static FDB/MDB entries programmed with VID 0.

--

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

This adds two-word pack/unpack helpers for the family D 4K VLAN table. On family D, IVL_EN now follows whether any user port is VLAN filtering. A vlan_4k_used bitmap tracks the VIDs in use, so a vlan_filtering change that flips the switch-wide state rewrites only the active entries.

drivers/net/dsa/realtek/rtl8365mb_main.c static int rtl8365mb_port_vlan_filtering(struct dsa_switch *ds, int port, · line 2308

Quoted 11 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +3 -0
index 687939d6d9d8c..24635feafc67f 100644
@@ -2303,8 +2303,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);

[Severity: Medium]
When this call flips the switch-wide IVL state, what happens to the dynamic L2 entries the chip learned under the old mode?

rtl8365mb_port_vlan_filtering()->rtl8365mb_d_vlan_4k_refresh_ivl()-> rtl8365mb_d_vlan_4k_set_ivl() rewrites IVL_EN in the 4K entries. Nothing flushes the LUT afterwards.

A family D L2 entry stores its own IVL bit and a shared VID/FID field. You can see this in the unpacker added later in the series:

rtl8365mb_d_l2_data_to_uc() {
    ...
	uc->key.ivl = FIELD_GET(RTL8365MB_D_L2_UC_D3_IVL_MSK, data[3]);
	uc->key.vid = uc->key.ivl ? id : 0;
	uc->key.fid = uc->key.ivl ? 0 : id;
    ...
}

So IVL (VID key) lookups would never hit entries learned in SVL (FID key), and the reverse is also true. Until those entries age out after 300 s:

- they take up hash and CAM slots
- known destinations flood until they are learned again
- toggling filtering back within the ageing time could make the old entries valid again, possibly pointing at outdated ports

The DSA core calls dsa_port_fast_age() only on STP state and learning flag changes, not on vlan_filtering changes.

Should this path call the driver's existing rtl83xx_port_fast_age() or l2_flush once the IVL state flips? The final series state behaves the same way, and the PBFID toggle added later also changes the learning key.

Quoted 4 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +4 -0
+		mutex_unlock(&priv->vlan_lock);
+		if (ret)
+			goto undo_egress_mode;
+	}

[ ... ]

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

[ ... ]

Quoted 6 lines

+/* Family D has no EFID, so a VLAN-unaware bridge must learn in SVL (IVL=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.
+ */

[Severity: Low]
This isn't a bug, but at this commit the comment doesn't match the L2 code. These functions still always program key.ivl = true with the VID and use the family C L2 layout:

rtl8365mb_l2_add_uc()
rtl8365mb_l2_del_uc()
rtl8365mb_l2_add_mc()
rtl8365mb_l2_del_mc()

So static entries would not use the SVL key yet.

This is fixed later in the series by "net: dsa: realtek: rtl8365mb: make L2/LUT access work on family D". There, rtl8365mb_d_l2_uc_to_data() and rtl8365mb_d_l2_mc_to_data() map VID 0 to the SVL key:

	bool ivl = uc->key.ivl && uc->key.vid;
	u16 id = ivl ? uc->key.vid :
		       (uc->key.fid ? uc->key.fid :
				      RTL8365MB_D_UNAWARE_BRIDGE_FID);

Family D can't be reached until the last patch, so this has no runtime effect in between. Could the comment be reworded here, or moved to the L2 patch?

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

Quoted 12 lines
drivers/net/dsa/realtek/rtl8365mb_vlan.c +12 -0
+bool rtl8365mb_d_want_ivl(struct dsa_switch *ds, int port, bool filtering)
+{
+	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]
The comment above says a VLAN-unaware bridge must learn in SVL. This function returns true as soon as any user port is VLAN filtering, whichever bridge that port belongs to. Can a VLAN-unaware bridge end up in IVL here?

The result is applied to every entry. rtl8365mb_vlan_4k_port_set() writes:

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

and rtl8365mb_d_vlan_4k_set_ivl() rewrites every VID in vlan_4k_used to the same value.

Suppose one VLAN-aware bridge and one VLAN-unaware bridge are offloaded on the same switch. The unaware bridge's VLANs (its PVID 1, for example) would move to IVL. Its learned entries would then be keyed on {MAC, VID}, while its static and host FDB/MDB entries use the SVL/FID key. Unicast could then flood, and static MDB filtering might stop applying.

The driver does not set ds->vlan_filtering_is_global, so DSA doesn't reject mixed VLAN awareness.

Later in the series, "net: dsa: realtek: rtl8365mb: make L2/LUT access work on family D" sets ds->max_num_bridges = 1 for family D, which narrows this. That commit also notes that DSA allocates bridge numbers system-wide. A bridge that already got a number from another switch can still be offloaded here ("such bridges share FID 1, a known limitation"). In that case two bridges with different VLAN awareness can still share a family D switch.

The rollback comment in rtl8365mb_d_vlan_4k_set_ivl() also says:

	/* Best effort: restore the entries rewritten so far. IVL_EN is
	 * switch-wide, so before the scan every entry in use had the old

IVL_EN is a per-entry field (RTL8365MB_D_CVLAN_ENTRY_D1_IVL_EN_MASK). Only the driver's policy for it is switch-wide.

Should family D set ds->vlan_filtering_is_global? If not, could this limitation be documented in the commit message and in the code?

[ ... ]

Quoted 18 lines
drivers/net/dsa/realtek/rtl8365mb_vlan.c +9 -1
@@ -314,7 +480,15 @@ rtl8365mb_vlan_4k_port_set(struct dsa_switch *ds, int port,
 		vlan4k.untag |= BIT(port);
 	else
 		vlan4k.untag &= ~BIT(port);
-	vlan4k.ivl_en = true; /* always use Independent VLAN Learning */
+
+	if (!rtl8365mb_is_d(priv))
+		vlan4k.ivl_en = true;
+	else
+		/* An emptied entry goes back to its reset state, so that
+		 * it is not left in IVL after it leaves vlan_4k_used.
+		 */
+		vlan4k.ivl_en = vlan4k.member &&
+				rtl8365mb_d_want_ivl(ds, -1, false);
 
 	ret = fi->vlan_4k_write(priv, &vlan4k);
 	if (ret) {

drivers/net/dsa/realtek/rtl8365mb_vlan.c rtl8365mb_vlan_4k_port_set(struct dsa_switch *ds, int port, · line 505

Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_vlan.c +7 -0
@@ -322,6 +496,13 @@ rtl8365mb_vlan_4k_port_set(struct dsa_switch *ds, int port,
 		return ret;
 	}
 
+	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);
+	}
+

[Severity: Medium]
Can vlan_4k_used miss a live entry if fi->vlan_4k_write() returns an error after the write has actually reached the chip?

rtl8365mb_table_query() writes the data and CTRL registers, then calls rtl8365mb_table_poll_busy():

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

If that final poll times out, or a regmap error happens after the execute write, the call returns an error even though the chip may have committed the entry. For a VID getting its first member, rtl8365mb_vlan_4k_port_set() then returns early and skips set_bit(vid, vlan_4k_used).

The rollback comment in rtl8365mb_d_vlan_4k_set_ivl() already assumes this can happen ("its write may have reached the chip before the error was reported").

The bridge treats the failed port_vlan_add as not applied and never sends a matching delete, so the non-empty 4K entry stays untracked. Later IVL flips in rtl8365mb_d_vlan_4k_set_ivl() would skip it. That VLAN would stay in the old learning mode until the same VID is added again on some port.

Would it be safer to set the bit before the write for a newly populated entry? rtl8365mb_d_vlan_4k_set_ivl() already skips entries with no members.

Quoted 2 lines
drivers/net/dsa/realtek/rtl8365mb_vlan.c +0 -0
 	return 0;
 }
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/874b29a3-f47f-4bf2-a0f6-2f9fea712f4c%40yahoo.com
#11 lore raw

PATCH v14 8/15 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, and also needs its PVID registers cleared at setup.

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. Also add a vlan_port_reset_pvid hook, implemented as a no-op on family C (rtl8365mb_c_vlan_port_reset_pvid()) so existing setup behavior is preserved. 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 24635fe..1848847 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 f6230eb..b5b56ae 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
#12 lore raw

PATCH v14 9/15 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 1848847..3f45ff4 100644
@@ -2450,11 +2450,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 b5b56ae..270f88b 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
#13 lore raw

PATCH v14 10/15 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. The port 6 rate limiter registers it writes are the family C ones; they have not been compared with the vendor RTL8367D API.

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.

On family D only the MAC force register carries the pause bits; on family C the SerDes TXFC bit is what gates pause frames. Flow control on the family D SerDes port has not been tested.

---
 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 3f45ff4..cfb8d4b 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.
@@ -1953,10 +2088,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,
@@ -2035,7 +2177,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)) {
@@ -2070,9 +2212,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)) {
@@ -2085,18 +2229,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
#14 lore raw

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

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] In drivers/net/dsa/realtek/rtl8365mb_main.c, the family D early return in rtl8365mb_sds_probe_option() sets mb->sds_supported = true…

--

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

This commit extends the RTL8367S SGMII/HSGMII PCS code in rtl8365mb to family D switches. On those switches the CPU SerDes is reached through the indexed SDS13 window and the SDS_MISC fields use a different layout. Family D gets its own tuning tables and SDS_MISC programming, and it skips the family C option register probe, the SerDes pause programming and pcs_link_up().

Quoted 4 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +0 -0
index 3f45ff43cb4c8..cfb8d4bb1126c 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]
This early return comes before the "Nothing to probe if no external interface is wired to the SerDes" loop over mb->chip_info->extints. As a result, every family D chip ends up with sds_supported set, whether or not it has an SGMII/HSGMII extint.

In rtl8365mb_setup(), sds_supported is the only check before the rate limiters are raised:

	if (mb->sds_supported) {
		ret = rtl8365mb_sds_raise_rate_limits(priv);

So every family D chip now gets 0xFFFF written to 0x00CF and 0x0398, and GENMASK(2, 0) written to 0x00D0 and 0x0399. Before this patch, family D never wrote those registers.

The 19-bit LSB/MSB layout and the reason for raising these registers (the 0x1FFFF reset default) are documented only for family C. The commit message also says:

"The port 6 rate limiter registers it writes are the family C ones;
they have not been compared with the vendor RTL8367D API."

If these addresses mean something else on the RTL8367D, the regmap writes would still succeed. The switch would be misconfigured and no error would be reported.

For the RTL8367S-VB this probably makes no difference, since it does have a SerDes on port 6. The commit message does say the code is meant to be reused by other family D boards, though. A later family D chip without a port 6 SerDes would still get these writes.

Could the family D branch skip only the option register read and keep the extint check? And could the limiter addresses be checked against the RTL8367D API, or the writes skipped on family D until they have been?

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];

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/874b29a3-f47f-4bf2-a0f6-2f9fea712f4c%40yahoo.com
#15 lore raw

PATCH v14 11/15 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 cfb8d4b..cf06bc9 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
#16 lore raw

PATCH v14 12/15 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, so the extended port flush register, which the L2 code only writes for ports above 7, is never reached.
- A VLAN-unaware bridge reaches the driver with VID 0, where the chip learns in SVL. If both standalone ports and an offloaded VLAN-unaware bridge share SVL FID 0, a MAC learned or programmed on a bridge port is hit by traffic arriving on a standalone port and dropped by the ingress port isolation mask instead of flooding to the CPU.
- Even with IVL enabled in a VLAN-aware bridge, an 802.1Q-tagged frame entering a standalone port with a VID used by the bridge performs an IVL lookup in that VLAN. Without EFID, hitting a bridge entry drops the frame instead of flooding it to the CPU, unless the lookup-hit isolation fallback is enabled.

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=1) and static unicast and multicast entries match the ones learned 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. Nothing points to the family D helpers 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.
- rtl8365mb_main: use family D's port-based FID registers (0x07AC / 0x07AD + port) in port_set_efid() and port_vlan_filtering() to assign FID 1 to the ports of an offloaded VLAN-unaware bridge, while standalone ports stay in FID 0. Port-based FID applies regardless of the VLAN tag, so it isolates the bridge's LUT entries from standalone ports and keeps 802.1Q tagged frames transparent on a VLAN-unaware bridge. It is not enabled on the shared CPU port, whose TX frames carry an explicit port mask in the CPU tag; assisted learning entries added on the CPU port with VID 0 use FID 1 so that bridge traffic hits them. It is disabled when a port leaves the bridge or when VLAN filtering is enabled on it.
Enable the lookup-hit isolation fallback (bit 0 of 0x0A10, dal_rtl8367d_l2_lookupHitIsolationAction_set() in the vendor API) and include each port's own bit in its port isolation mask on family D. A LUT hit on a port outside the ingress port's isolation mask then floods according to the ingress isolation mask, reaching the CPU on standalone ports, including for tagged frames in IVL VLANs, while same-port hits are still dropped.
Add a LUT init step that clears PBFIDEN, sets LOOKUP_HIT_ISO_ACT, clears IPMC_HASH and BCAM_DISABLE, and writes 3000 to the aging timer register, as dal_rtl8367d_l2_init() does (units of 0.1 s, i.e. 300 s).
Do not advertise fdb_isolation and set max_num_bridges to 1: the driver reserves FID 0 for standalone ports and assigns the single fixed FID 1 to the offloaded VLAN-unaware bridge, instead of allocating FIDs 1..3 across several bridges. 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; such bridges share FID 1, a known limitation. The bridge number is also what port_set_efid() uses to tell that a port is in an offloaded bridge, so max_num_bridges must stay non-zero.

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

Base L2/LUT handling and port-based FID isolation in FID 1 were tested by Gustavo Foletto Mora on a TP-Link EX511 v2 (RTL8367S-VB, CPU port 6 over 1G SGMII to an IPQ5018), including register readback across live vlan_filtering toggles and bridge leave, and unicast between standalone ports through a VLAN-unaware bridge. The lookup-hit isolation fallback (0x0A10) with self-port isolation masks was tested as well (no frame is sent back out of its ingress port), including a VLAN tagged on two bridge ports with the hosts on standalone ports of the same switch.

---
 drivers/net/dsa/realtek/realtek.h         |   4 +-
 drivers/net/dsa/realtek/rtl8365mb_l2.c    | 144 +++++++++++++++-
 drivers/net/dsa/realtek/rtl8365mb_l2.h    |   9 +
 drivers/net/dsa/realtek/rtl8365mb_main.c  | 199 +++++++++++++++++++++-
 drivers/net/dsa/realtek/rtl8365mb_table.c |  44 +++--
 drivers/net/dsa/realtek/rtl83xx.c         |   5 +-
 6 files changed, 384 insertions(+), 21 deletions(-)
drivers/net/dsa/realtek/realtek.h +3 -1
index fda385e..cee8e65 100644
@@ -79,7 +79,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 +142 -2

168 lines not on this page · raw message

drivers/net/dsa/realtek/rtl8365mb_l2.h +9 -0
index a9f9ae4..449ecca 100644
@@ -13,9 +13,13 @@
 #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
 
+/* SVL FID used for an offloaded VLAN-unaware bridge on family D */
+#define RTL8365MB_D_UNAWARE_BRIDGE_FID		1
+
 struct rtl8365mb_l2_uc;
 struct rtl8365mb_l2_mc;
 
@@ -24,6 +28,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 +192 -7

258 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
#17 lore raw

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

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

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

Critical: 0 · High: 0 · Medium: 1 · 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] On family D, rtl8365mb_setup() sets ds->max_num_bridges = 1 (drivers/net/dsa/realtek/rtl8365mb_main.c:3859) and treats it as a…

--

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

This patch teaches the rtl8365mb table and L2 code about the family D (RTL8367S-VB) LUT layout. It also uses port-based FID to isolate an offloaded VLAN-unaware bridge in FID 1 from standalone ports in FID 0. On family D, fdb_isolation is no longer advertised and max_num_bridges is set to 1.

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

[ ... ]

Quoted 13 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +6 -3
@@ -3670,9 +3841,23 @@ 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;
+		/* The EFID is 3 bits, but EFID 0 is reserved for standalone */
+		ds->max_num_bridges = FIELD_MAX(RTL8365MB_EFID_MASK);
+	} else {
+		/* No EFID; FID 0 is used by standalone ports and FID 1 by the

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

Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +10 -0
+		 * offloaded VLAN-unaware bridge via port-based FID, so allow
+		 * at most one offloaded bridge. The bridge number it gets is
+		 * what rtl8365mb_port_set_efid() takes as "offloaded" to
+		 * enable port-based FID, so max_num_bridges must not be 0.
+		 * 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; such
+		 * bridges share FID 1 (known limitation).
+		 */
+		ds->max_num_bridges = 1;

[Severity: Medium]
Does max_num_bridges = 1 actually mean "at most one offloaded bridge" on this switch?

DSA treats max_num_bridges as an upper bound on bridge numbers, and those numbers come from a single system-wide bitmap:

net/dsa/dsa.c:dsa_bridge_num_get() {
    ...
	if (!bridge_num) {
		bridge_num = find_next_zero_bit(&dsa_fwd_offloading_bridges,
						DSA_MAX_NUM_OFFLOADING_BRIDGES,
						1);
		if (bridge_num > max)
			return 0;
    ...
}

If it returns 0, dsa_port_bridge_create() fails with "Range of offloadable bridges exceeded" and -EOPNOTSUPP, and dsa_user_changeupper() falls back to software bridging.

Here is one case. Another DSA switch in a different tree already offloads a bridge holding bridge number 1. A new bridge built only from RTL8367S-VB ports then gets number 2. Since 2 > 1, it is refused, and this switch cannot offload any bridge at all, so all bridged traffic goes through the CPU.

Whether offload works then depends on the order in which unrelated switches allocated numbers. It can also change as bridges are deleted and their numbers freed.

The comment above, and this part of the commit message, describe only the opposite outcome of the same mismatch:

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; such bridges share FID 1, a known limitation.

rtl83xx_port_bridge_join() passes any non-zero bridge.num to port_set_efid(), which maps it to FID 1 on family D. It does not enforce the one-bridge-per-switch limit itself.

Would it work better to keep max_num_bridges at a larger value? On family D, port_bridge_join could then return -EOPNOTSUPP when another port of this switch already offloads a different bridge, which would avoid both outcomes.

At minimum, could the comment and the commit message say that on multi-switch systems this switch may be unable to offload any bridge?

This code is unchanged at the end of the series, in "net: dsa: realtek:
rtl8365mb: add support for RTL8367S-VB".

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/874b29a3-f47f-4bf2-a0f6-2f9fea712f4c%40yahoo.com
#18 lore raw

PATCH v14 13/15 net: dsa: realtek: rtl8365mb: refactor QoS priority handling

In reply to Mieczyslaw Nalewaj

The shared QoS layer hands the backend internal priorities that are 802.1Q traffic types, and the backend stores them in the chip as they are, together with a separate per-port PCP for untagged frames. Family D numbers its internal priorities differently and has no separate untagged-PCP register, which the next patch adds.

Move the conversion between a traffic type and the chip's priority, and the programming of the PCP of untagged frames, behind three new hooks in struct rtl8365mb_family_info, as for the VLAN, PVID and L2 helpers:
qos_iprio_to_hw, qos_hw_to_iprio and qos_set_untag_pcp. The existing behaviour becomes the family C implementation: the traffic type is stored as it is and the untagged PCP register is written as before. rtl8365mb_qos_qmap_init() now iterates over the chip's priorities and converts each one back to its traffic type.

No functional change.

---
 drivers/net/dsa/realtek/rtl8365mb.h      |   4 +
 drivers/net/dsa/realtek/rtl8365mb_main.c |   3 +
 drivers/net/dsa/realtek/rtl8365mb_qos.c  | 102 +++++++++++++++++++----
 drivers/net/dsa/realtek/rtl8365mb_qos.h  |   6 ++
 4 files changed, 98 insertions(+), 17 deletions(-)
drivers/net/dsa/realtek/rtl8365mb.h +4 -0
index 9a69e85..d34c9b6 100644
@@ -38,6 +38,10 @@ struct rtl8365mb_family_info {
 	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);
+	int (*qos_iprio_to_hw)(u8 iprio);
+	int (*qos_hw_to_iprio)(u8 hw);
+	int (*qos_set_untag_pcp)(struct realtek_priv *priv, int port,
+				 u8 hw_prio, u8 untag_pcp);
 };
 
 const struct rtl8365mb_family_info *
drivers/net/dsa/realtek/rtl8365mb_main.c +3 -0
index bf508ed..639e6b6 100644
@@ -830,6 +830,9 @@ static const struct rtl8365mb_family_info rtl8365mb_family_c = {
 	.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,
+	.qos_iprio_to_hw = rtl8365mb_c_qos_iprio_to_hw,
+	.qos_hw_to_iprio = rtl8365mb_c_qos_hw_to_iprio,
+	.qos_set_untag_pcp = rtl8365mb_c_qos_set_untag_pcp,
 };
 
 /**
drivers/net/dsa/realtek/rtl8365mb_qos.c +85 -17

164 lines not on this page · raw message

drivers/net/dsa/realtek/rtl8365mb_qos.h +6 -0
index 9602807..d68b2bd 100644
@@ -30,4 +30,10 @@ int rtl8365mb_qos_set_apptrust(struct realtek_priv *priv, int port,
 int rtl8365mb_qos_get_apptrust(struct realtek_priv *priv, int port, bool *trust,
 			       unsigned int n);
 
+/* Hooks of struct rtl8365mb_family_info, one set per chip family */
+int rtl8365mb_c_qos_iprio_to_hw(u8 iprio);
+int rtl8365mb_c_qos_hw_to_iprio(u8 hw);
+int rtl8365mb_c_qos_set_untag_pcp(struct realtek_priv *priv, int port,
+				  u8 hw_prio, u8 untag_pcp);
+
 #endif /* _REALTEK_RTL8365MB_QOS_H */
Signature · 1 line
2.53.0
#19 lore raw

Re: [PATCH net-next v14 13/15] net: dsa: realtek: rtl8365mb: refactor QoS priority handling

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] This patch splits the QoS code into two value spaces.

--

net: dsa: realtek: rtl8365mb: refactor QoS priority handling

This patch moves two pieces of QoS handling behind three new rtl8365mb_family_info hooks: the conversion between an 802.1Q traffic type and the chip's priority, and the programming of the untagged-frame PCP. The hooks are qos_iprio_to_hw, qos_hw_to_iprio and qos_set_untag_pcp. Family C keeps its existing behaviour through an identity mapping, and rtl8365mb_qos_qmap_init() now iterates over chip priorities and converts each one back to a traffic type.

Quoted 4 lines
drivers/net/dsa/realtek/rtl8365mb_qos.c +0 -0
index 5b9e1abe75c8b..b61ffdb4073ac 100644

[ ... ]

Quoted 7 lines
drivers/net/dsa/realtek/rtl8365mb_qos.c +7 -0
+/* Convert an internal priority (an 802.1Q traffic type) to the value the
+ * chip uses. Return the value or a negative errno.
+ */
+static int rtl8365mb_qos_iprio_to_hw(struct realtek_priv *priv, u8 iprio)
+{
+	return rtl8365mb_get_family_info(priv)->qos_iprio_to_hw(iprio);
+}

[ ... ]

Quoted 19 lines
drivers/net/dsa/realtek/rtl8365mb_qos.c +9 -3
@@ -306,19 +366,27 @@ int rtl8365mb_qos_qmap_init(struct realtek_priv *priv)
 {
 	unsigned int nq = priv->ds.num_tx_queues;
 	struct dsa_port *dp;
-	int iprio, ret;
+	int prio, ret;
 
-	for (iprio = 0; iprio < RTL8365MB_NUM_INTERNAL_PRIOS; iprio++) {
-		int tc = ieee8021q_tt_to_tc(iprio, nq);
+	/* The table is indexed by the chip's priority, not by the traffic
+	 * type.
+	 */
+	for (prio = 0; prio < RTL8365MB_NUM_INTERNAL_PRIOS; prio++) {
+		int tt = rtl8365mb_qos_hw_to_iprio(priv, prio);
+		int tc;
 		u8 qid;
 
+		if (tt < 0)
+			return tt;

drivers/net/dsa/realtek/rtl8365mb_qos.c int rtl8365mb_qos_qmap_init(struct realtek_priv *priv) · line 389

Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_qos.c +3 -1
+
+		tc = ieee8021q_tt_to_tc(tt, nq);
 		if (tc < 0)
 			return tc;
 
 		qid = rtl8365mb_qos_tc_to_qid(nq, tc);
 		ret = rtl8365mb_qos_set_qmap_qid(priv,
 						 RTL8365MB_QOS_QMAP_DEFAULT,
-						 iprio, qid);
+						 prio, qid);

[Severity: Low]
This isn't a bug, but should the remaining names and comments be updated to match the new split between iprio (traffic type) and hw (chip priority)?

The loop now passes the chip priority to rtl8365mb_qos_set_qmap_qid(). The callee still calls that argument iprio, and so does the register macro it uses:

static int rtl8365mb_qos_set_qmap_qid(struct realtek_priv *priv, int qmap,
u8 iprio, u8 qid)

{
	u32 reg = RTL8365MB_QOS_QMAP_TBL_REG(qmap, iprio);

#define RTL8365MB_QOS_QMAP_TBL_REG(_m, _iprio) \

In the same file, rtl8365mb_qos_set_pcp_prio() and rtl8365mb_qos_set_dscp_prio() use iprio for the traffic type before converting it, so the same parameter name now means two different things.

A few register comments also still describe their contents as an internal priority, although after this patch they hold the converted hw value:

/* qmaps: the queue id of each internal priority, one table per qmap */ /* 802.1p (PCP) -> internal priority remap */
/* DSCP -> internal priority, one table for the whole chip */

rtl8365mb_qos.h has the same wording:

/* Internal priority -> queue id tables (qmaps) */

At this commit, the comment at the top of rtl8365mb_qos.c ("The chip's eight internal priorities carry 802.1Q traffic types") also conflicts with the new "not by the traffic type" comment above.

The later patch "net: dsa: realtek: rtl8365mb: use PCP numbering on family D" rewrites the top-of-file comment. It leaves the rtl8365mb_qos_set_qmap_qid() parameter, the RTL8365MB_QOS_QMAP_TBL_REG() argument and the register and header comments unchanged.

On family D the two value spaces really are different, so would renaming these (for example to hw_prio, matching qos_set_untag_pcp) make it harder to pass the wrong one later?

Quoted 3 lines
drivers/net/dsa/realtek/rtl8365mb_qos.c +0 -0
 		if (ret)
 			return ret;
 	}
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/874b29a3-f47f-4bf2-a0f6-2f9fea712f4c%40yahoo.com
#20 lore raw

PATCH v14 14/15 net: dsa: realtek: rtl8365mb: use PCP numbering on family D

In reply to Mieczyslaw Nalewaj

Family C has separate per-port registers for the 802.1p PCP given to untagged frames (0x0851-0x0852) and for the port's default internal priority (0x0877-0x0878). The shared QoS layer hands the backend internal priorities that are 802.1Q traffic types (Best Effort is 1, Background is
0) and writes the untagged PCP separately.

Family D has no 0x0851-0x0852 registers: its per-port PVID register at 0x0700 + port holds only the 12-bit VID, and dal_rtl8367d_vlan_portPvid_set() rejects any priority != 0. On an RTL8367S-VB the PCP of a newly inserted 802.1Q tag follows the frame's internal priority, so writing the traffic type as is made untagged frames leave an egress-tagged port with PCP 1 (Background) instead of PCP 0 (Best Effort).

The vendor API numbers family D internal priorities like PCP values:
dal_rtl8367d_qos_init() maps each PCP to the same internal priority, sets the port priority to 0 and keeps 1p remarking disabled. Do the same. On family D, convert between traffic types and the chip's numbering at the register boundary: for the port priority, the PCP-to-priority and DSCP-to-priority tables, and the priority-to-queue table. The PCP of a newly inserted tag then matches the traffic type whichever source classified the frame, and each traffic type still lands in the same queue as before.

Add the family D implementations of the qos_iprio_to_hw, qos_hw_to_iprio and qos_set_untag_pcp hooks introduced by the previous patch. The PCP of untagged frames cannot differ from the one the port priority implies, so the family D qos_set_untag_pcp hook returns -EOPNOTSUPP for a mismatching @untag_pcp. The shared layer never asks for one. As for the other family D functions, the hooks are wired up by the patch that adds the first family D chip, so this patch changes no behaviour yet.

Tested by Gustavo Foletto Mora on a TP-Link EX511 v2 with the baseline QoS configuration (no CONFIG_DCB): untagged frames leave tagged with PCP 0, tagged frames keep their PCP, and the QoS registers read back in PCP numbering. Trusting PCP (dcb apptrust) together with a non-zero default priority was not tested on family D, so it is not known whether the chip then classifies untagged frames by that priority or by PCP 0.

---
 drivers/net/dsa/realtek/rtl8365mb_qos.c | 36 +++++++++++++++++++++----
 drivers/net/dsa/realtek/rtl8365mb_qos.h |  4 +++
 2 files changed, 35 insertions(+), 5 deletions(-)
drivers/net/dsa/realtek/rtl8365mb_qos.c +31 -5
index b61ffdb..23e1ebb 100644
@@ -21,8 +21,12 @@
 #include "rtl8365mb.h"
 #include "rtl8365mb_qos.h"
 
-/* The chip's eight internal priorities carry 802.1Q traffic types, one
- * internal priority per traffic type.
+/* The shared rtl83xx-qos.c layer hands this backend internal priorities
+ * that are 802.1Q traffic types, one per traffic type. Family C stores them
+ * as they are. Family D numbers its internal priorities like PCP values, as
+ * its vendor API does, and takes the PCP of a newly inserted 802.1Q tag from
+ * the internal priority, so it converts them at the register boundary
+ * through the qos_* hooks of struct rtl8365mb_family_info.
  */
 static_assert(RTL8365MB_NUM_INTERNAL_PRIOS == IEEE8021Q_TT_MAX);
 
@@ -66,7 +70,9 @@ static_assert(RTL8365MB_QOS_QMAP_DEFAULT < RTL8365MB_QOS_NUM_QMAPS);
 #define RTL8365MB_QOS_1Q_REMAP_REG(_pcp) \
 	(0x0865 + (_pcp) / RTL8365MB_QOS_SELS_PER_REG)
 
-/* PCP given to untagged frames, one 3-bit field per port */
+/* PCP given to untagged frames, one 3-bit field per port (family C only;
+ * family D has no such register, see rtl8365mb_d_qos_set_untag_pcp())
+ */
 #define RTL8365MB_QOS_PORT_UNTAG_PCP_REG(_p) \
 	(0x0851 + (_p) / RTL8365MB_QOS_SELS_PER_REG)
 
@@ -239,6 +245,26 @@ int rtl8365mb_c_qos_set_untag_pcp(struct realtek_priv *priv, int port,
 						 untag_pcp);
 }
 
+/* Family D numbers its internal priorities like PCP values */
+int rtl8365mb_d_qos_iprio_to_hw(u8 iprio)
+{
+	return ieee8021q_tt_to_pcp(iprio);
+}
+
+int rtl8365mb_d_qos_hw_to_iprio(u8 hw)
+{
+	return ieee8021q_pcp_to_tt(hw);
+}
+
+/* There is no separate PCP for untagged frames: it is the one the port
+ * priority implies, so a different one cannot be set.
+ */
+int rtl8365mb_d_qos_set_untag_pcp(struct realtek_priv *priv, int port,
+				  u8 hw_prio, u8 untag_pcp)
+{
+	return untag_pcp == hw_prio ? 0 : -EOPNOTSUPP;
+}
+
 /* Convert an internal priority (an 802.1Q traffic type) to the value the
  * chip uses. Return the value or a negative errno.
  */
@@ -368,8 +394,8 @@ int rtl8365mb_qos_qmap_init(struct realtek_priv *priv)
 	struct dsa_port *dp;
 	int prio, ret;
 
-	/* The table is indexed by the chip's priority, not by the traffic
-	 * type.
+	/* The table is indexed by the chip's priority, which is the traffic
+	 * type on family C and the PCP on family D.
 	 */
 	for (prio = 0; prio < RTL8365MB_NUM_INTERNAL_PRIOS; prio++) {
 		int tt = rtl8365mb_qos_hw_to_iprio(priv, prio);
drivers/net/dsa/realtek/rtl8365mb_qos.h +4 -0
index d68b2bd..ec88eb2 100644
@@ -35,5 +35,9 @@ int rtl8365mb_c_qos_iprio_to_hw(u8 iprio);
 int rtl8365mb_c_qos_hw_to_iprio(u8 hw);
 int rtl8365mb_c_qos_set_untag_pcp(struct realtek_priv *priv, int port,
 				  u8 hw_prio, u8 untag_pcp);
+int rtl8365mb_d_qos_iprio_to_hw(u8 iprio);
+int rtl8365mb_d_qos_hw_to_iprio(u8 hw);
+int rtl8365mb_d_qos_set_untag_pcp(struct realtek_priv *priv, int port,
+				  u8 hw_prio, u8 untag_pcp);
 
 #endif /* _REALTEK_RTL8365MB_QOS_H */
Signature · 1 line
2.53.0
#21 lore raw

Re: [PATCH net-next v14 14/15] net: dsa: realtek: rtl8365mb: use PCP numbering on family D

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_d_qos_set_untag_pcp() returns success and programs nothing whenever untag_pcp == hw_prio.
- [Low] The qmap helpers still call their index an iprio, but after this patch the index is the chip's priority, and on family D that is…
- [Low] The kernel-doc for realtek_ops.qos_set_port_prio in realtek.h says the backend will "Set the priority of @port to @iprio, and make…

--

net: dsa: realtek: rtl8365mb: use PCP numbering on family D

This patch adds family D implementations of the qos_iprio_to_hw, qos_hw_to_iprio and qos_set_untag_pcp hooks. With them, family D numbers its internal priorities like PCP values and converts traffic types at the register boundary. Family D has no untagged PCP register, so its qos_set_untag_pcp hook returns -EOPNOTSUPP when the untagged PCP differs from the one the port priority implies.

Quoted 4 lines
drivers/net/dsa/realtek/rtl8365mb_qos.c +0 -0
index b61ffdb4073ac..23e1ebbe0a591 100644

[ ... ]

Quoted 13 lines
drivers/net/dsa/realtek/rtl8365mb_qos.c +9 -0
@@ -239,6 +245,26 @@ int rtl8365mb_c_qos_set_untag_pcp(struct realtek_priv *priv, int port,
 						 untag_pcp);
 }
 
+/* Family D numbers its internal priorities like PCP values */
+int rtl8365mb_d_qos_iprio_to_hw(u8 iprio)
+{
+	return ieee8021q_tt_to_pcp(iprio);
+}
+
+int rtl8365mb_d_qos_hw_to_iprio(u8 hw)
+{
+	return ieee8021q_pcp_to_tt(hw);

drivers/net/dsa/realtek/rtl8365mb_qos.c int rtl8365mb_c_qos_set_untag_pcp(struct realtek_priv *priv, int port, · line 266

Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_qos.c +10 -0
+}
+
+/* There is no separate PCP for untagged frames: it is the one the port
+ * priority implies, so a different one cannot be set.
+ */
+int rtl8365mb_d_qos_set_untag_pcp(struct realtek_priv *priv, int port,
+				  u8 hw_prio, u8 untag_pcp)
+{
+	return untag_pcp == hw_prio ? 0 : -EOPNOTSUPP;
+}

[Severity: Medium]

This comment says the untagged-frame PCP "is the one the port priority implies". The commit message only shows that for the PCP of a newly inserted egress tag. It also says:

"it is not known whether the chip then classifies untagged frames by that priority or by PCP 0."

On family C, the 1Q priority source classifies untagged frames using RTL8365MB_QOS_PORT_UNTAG_PCP_REG. rtl8365mb_c_qos_set_untag_pcp() sets that register to the dcb default prio.

Family D has no such register. The vendor dal_rtl8367d_vlan_portPvid_set() also rejects any priority != 0. That suggests the port-based VLAN priority that feeds the 1Q classifier is fixed at 0.

The last patch of the series wires up the family D hooks. After that, could this sequence leave untagged frames with the wrong priority?

dcb app add dev swpN default-prio X (X != 0)

    rtl83xx_port_set_default_prio()
      qos_set_port_prio(priv, port, pcp_to_tt(X), X)
        rtl8365mb_qos_set_port_prio()
          rtl8365mb_d_qos_set_untag_pcp()   /* hw == X, returns 0 */

dcb apptrust set dev swpN order pcp

    rtl83xx_port_set_apptrust()->rtl8365mb_qos_set_apptrust()
      /* RTL8365MB_QOS_PRIDEC_1Q weighted above the port source */

Suppose the 1Q classifier then uses PCP 0 for untagged frames. They would map through remap[0] to hw 0 (Best Effort) and leave with PCP 0 instead of X. Meanwhile rtl83xx_port_get_default_prio() would still read X back from the port priority register, so dcbnl reports a default priority that is not in effect.

Could the hook refuse this case instead? For example, it could reject a non-zero untag_pcp on family D, or PCP trust could be rejected while a non-zero default prio is set. Or could the comment describe this as an unverified limitation rather than state it as fact?

[Severity: Low]

The qos_set_port_prio documentation in realtek.h still reads:

	/* Set the priority of @port to @iprio, and make @untag_pcp the PCP
	 * given to untagged frames on @port. @untag_pcp is an 802.1p
	 * priority, not an iprio.
	 */

That wording treats untag_pcp as independent of iprio. This hook returns -EOPNOTSUPP whenever untag_pcp differs from ieee8021q_tt_to_pcp(iprio).

Both current callers in rtl83xx-qos.c, rtl83xx_qos_init_port() and rtl83xx_port_set_default_prio(), pass matching values. So the error path cannot be reached today. However, the restriction is only described in the commit message.

Should the ops documentation say that a backend may reject an untag_pcp that does not match iprio? Otherwise a future shared-layer caller that sets the untagged PCP separately would work on family C and fail only on family D.

Similarly, the comment above the apptrust table in rtl8365mb_qos.c still describes the family C register model:

/* The 1Q source also classifies untagged frames, by the PCP given to untagged
* frames. Ranked above DSCP, it would hide DSCP from untagged IP frames. */

drivers/net/dsa/realtek/rtl8365mb_qos.c int rtl8365mb_qos_qmap_init(struct realtek_priv *priv) · line 401

Quoted 11 lines
drivers/net/dsa/realtek/rtl8365mb_qos.c +2 -2
@@ -368,8 +394,8 @@ int rtl8365mb_qos_qmap_init(struct realtek_priv *priv)
 	struct dsa_port *dp;
 	int prio, ret;
 
-	/* The table is indexed by the chip's priority, not by the traffic
-	 * type.
+	/* The table is indexed by the chip's priority, which is the traffic
+	 * type on family C and the PCP on family D.
 	 */
 	for (prio = 0; prio < RTL8365MB_NUM_INTERNAL_PRIOS; prio++) {
 		int tt = rtl8365mb_qos_hw_to_iprio(priv, prio);

[Severity: Low]

This isn't a bug, but the qmap helpers still call this index an iprio:

/* qmaps: the queue id of each internal priority, one table per qmap */
...
#define RTL8365MB_QOS_QMAP_TBL_REG(_m, _iprio) \

static int rtl8365mb_qos_set_qmap_qid(struct realtek_priv *priv, int qmap,
u8 iprio, u8 qid)

realtek.h defines an iprio as an internal priority that holds an enum ieee8021q_traffic_type value. rtl8365mb_qos_set_port_prio(), rtl8365mb_qos_set_pcp_prio() and rtl8365mb_qos_set_dscp_prio() all use iprio in that sense and convert it through qos_iprio_to_hw().

rtl8365mb_qos_qmap_init() passes the hardware prio as that iprio argument, not tt. That did no harm on family C, where the two are equal. With the family D hooks they differ: Best Effort is tt 1 / hw 0, and Background is tt 0 / hw 1.

Could the parameter, the macro argument and the qmaps comment be renamed to say they take the chip's priority? Otherwise a later caller that passes a traffic type would swap the BE and BK queue slots on family D.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/874b29a3-f47f-4bf2-a0f6-2f9fea712f4c%40yahoo.com
#22 lore raw

PATCH v14 15/15 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, followed by the common jam table. Neither has been compared with the vendor RTL8367D initialization. Some common entries write registers that family D programs later (EXT_TXC_DLY at 0x13F9, the LUT configuration at 0x0A30, the interface select register at 0x1305); the bits that the jam leaves set there are not documented for family D. They were used on the tested hardware (see below), which uses SGMII and HSGMII on port 6 and not RGMII or MII on port 7.

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, the L2 entry (de)serializers and the QoS priority numbering.

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 | 58 +++++++++++++++++++++---
 3 files changed, 54 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 d34c9b6..282a225 100644
@@ -47,10 +47,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 +52 -6

94 lines not on this page · raw message

Signature · 1 line
2.53.0
#23 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

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

Critical: 0 · High: 0 · Medium: 1 · 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] In drivers/net/dsa/realtek/rtl8365mb_main.c, the new rtl8365mb_family_d sets .jam_table = rtl8365mb_init_jam_8365mb_vc.

--

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

This adds the RTL8367S-VB (chip ID 0x6642, version 0x0010) to the chip table as the first family D chip. It also adds a rtl8365mb_family_d family_info that selects the family D code added earlier in the series. The chip reuses the RTL8365MB-VC init jam table, followed by the common jam table.

Quoted 4 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +0 -0
index 639e6b62a2fc3..eef591eed0c91 100644

[ ... ]

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

Quoted 8 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +4 -0
@@ -835,6 +847,27 @@ static const struct rtl8365mb_family_info rtl8365mb_family_c = {
 	.qos_set_untag_pcp = rtl8365mb_c_qos_set_untag_pcp,
 };
 
+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: Medium]
Is it safe to write the RTL8365MB-VC jam table to family D silicon?

With this change, rtl8365mb_setup()->rtl8365mb_switch_init() writes rtl8365mb_init_jam_8365mb_vc and then rtl8365mb_init_jam_common to the RTL8367S-VB. It does this with plain regmap_write() right after the reset, and nothing filters the writes for family D.

The new header comment says family D registers differ in the VLAN table, the ext interface and RGMII setup, the SerDes and the LUT. The RTL8365MB_D_LUT_CFG2_REG comment also says 0x0A32 is the EFID register on family C but the aging timer on family D.

Some jam writes hit registers that family D only partly reprograms later. The common table writes the LUT config:

rtl8365mb_init_jam_common[] = {
    ...
	{ 0x03Fa, 0x0007 }, { 0x08C8, 0x00C0 }, { 0x0A30, 0x020E },
    ...
	{ 0x1D32, 0x0002 },
};

rtl8365mb_d_lut_init() then clears only two bits of it:

	ret = regmap_update_bits(priv->map, RTL8365MB_D_LUT_CFG_REG,
				 RTL8365MB_D_LUT_CFG_IPMC_HASH_MASK |
				 RTL8365MB_D_LUT_CFG_BCAM_DISABLE_MASK, 0);

That means bits 1, 2, 3 and 9 of 0x0A30 keep their family C values on a family D LUT.

The VC table also writes the interface select register:

	{ 0x18E0, 0x4004 }, { 0x122B, 0x241C }, { 0x1305, 0xC000 },

On family D, rtl8365mb_pcs_config() skips that register:

	if (!is_d) {
		val = sds_mode << RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_OFFSET(id);
		...

So the EXT0 mode field and bits 15:14 stay as the jam left them.

Other entries, such as 0x1303, 0x1304, 0x13EB, 0x121E..0x123A, 0x18E0, 0x1349, 0x0301 and 0x1D32, have no family D definition in the driver.

The commit message says neither table was compared with the vendor RTL8367D init, and testing covered only SGMII/HSGMII on port 6.

Could a wrong pad, MAC or LUT control value here break untested setups such as RGMII/MII on port 7? Could it leave the LUT configured differently from what the driver assumes?

The 0x13F9 entry mentioned in the commit message looks less worrying. The family D RGMII path clears the EXT1 RGMII TX delay field (bits 5:3), and the other value lands in the EXT2 field (bits 8:6), which family D does not have.

Would it make sense to give family D its own jam table, or none, until it can be checked against the vendor RTL8367D init sequence?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/874b29a3-f47f-4bf2-a0f6-2f9fea712f4c%40yahoo.com