net: dsa: realtek: rtl8365mb: add support for RTL8367S-VB
Subsystems (5)
v7 cover net: dsa: realtek: rtl8365mb: add support for RTL8367S-VB
In reply to a message not in the archiveThis series adds support for the RTL8367S-VB (chip ID 0x6642) to the rtl8365mb driver. The chip belongs to a new "family D" that differs from the existing family C in its VLAN and L2 table layouts, speed/RGMII configuration and SerDes (SDS13) handling.
Patch 1 documents the chip in the devicetree binding.
Patch 2 adds the chip family infrastructure (no functional change). Patches 3-4 add port speed and RGMII mode configuration for family D. Patches 5-6 add VLAN 4k table access and raw-VID PVID handling. Patches 7-8 add SDS13 PCS support and re-latching of the SerDes. Patch 9 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. Patch 10 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. Changes in a shared path include a mutex serializing SerDes register access, as well as .pcs_disable in pcs_ops and .conduit_state_change in dsa_switch_ops (both bail out immediately on family C). The L2 table access and FDB/MDB code is shared too; the family D handling is selected at runtime with rtl8365mb_get_family() (patch 9). The port count is capped at 8 for family D only (patch 10). On family D, FDB/MDB offload is available, but per-bridge FDB isolation is not (no EFID); bridges are isolated by the port isolation masks only (patch 9).
Tested on a TP-Link Archer AX55 v1 (RTL8367S-VB, CPU port over HSGMII to an IPQ5018) with bridge VLAN filtering and per-port PVIDs. SGMII has also been seen working, but I no longer have the exact link partner and speed it was tested with, so treat it as lightly tested. RGMII mode has not yet been tested. FDB/MDB offload on family D has not been tested on hardware yet.
---
v7:
- 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 (10):
dt-bindings: net: dsa: realtek: add RTL8367S-VB
net: dsa: realtek: rtl8365mb: add chip family infrastructure
net: dsa: realtek: rtl8365mb: set speed for family D
net: dsa: realtek: rtl8365mb: set RGMII mode for family D
net: dsa: realtek: rtl8365mb: set and get vlan 4k for family D
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: re-latch the family D SerDes
net: dsa: realtek: rtl8365mb: make L2/LUT access work on family D
net: dsa: realtek: rtl8365mb: add support for RTL8367S-VB
.../devicetree/bindings/net/dsa/realtek.yaml | 2 +- drivers/net/dsa/realtek/Kconfig | 3 +- drivers/net/dsa/realtek/rtl8365mb.h | 14 + drivers/net/dsa/realtek/rtl8365mb_l2.c | 216 ++++- drivers/net/dsa/realtek/rtl8365mb_main.c | 872 ++++++++++++++++-- drivers/net/dsa/realtek/rtl8365mb_table.c | 46 +- drivers/net/dsa/realtek/rtl8365mb_vlan.c | 366 ++++++-- drivers/net/dsa/realtek/rtl8365mb_vlan.h | 1 + 8 files changed, 1348 insertions(+), 172 deletions(-) create mode 100644 drivers/net/dsa/realtek/rtl8365mb.h
Signature · 1 line
2.53.0
PATCH v7 1/10 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
@@ -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
PATCH v7 2/10 net: dsa: realtek: rtl8365mb: add chip family infrastructure
In reply to Mieczyslaw NalewajAdd enum rtl8365mb_family and a family member to struct rtl8365mb_chip_info, together with rtl8365mb_get_family() declared in a new rtl8365mb.h so that the VLAN code can use it too. Tag all existing chips as RTL8365MB_FAMILY_C.
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 | 14 ++++++++++++++ drivers/net/dsa/realtek/rtl8365mb_main.c | 14 ++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 drivers/net/dsa/realtek/rtl8365mb.h
drivers/net/dsa/realtek/rtl8365mb.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _RTL8365MB_H +#define _RTL8365MB_H + +#include "realtek.h" + +enum rtl8365mb_family { +RTL8365MB_FAMILY_C , +RTL8365MB_FAMILY_D , +}; + +enum rtl8365mb_family rtl8365mb_get_family (struct realtek_priv *priv); + +#endif /* _RTL8365MB_H */
drivers/net/dsa/realtek/rtl8365mb_main.c +14 -0
@@ -110,6 +110,7 @@#include "rtl83xx.h" #include "rtl8365mb_l2.h" #include "rtl8365mb_vlan.h" +#include "rtl8365mb.h" /* Family-specific data and limits */ #define RTL8365MB_PHYADDRMAX 7
@@ -707,6 +708,7 @@ struct rtl8365mb_extint {* @name: human-readable chip name * @chip_id: chip identifier * @chip_ver: chip silicon revision +* @family: chip family * @extints: available external interfaces * @jam_table: chip-specific initialization jam table * @jam_size: size of the chip's jam table
@@ -719,6 +721,7 @@ struct rtl8365mb_chip_info {const char *name;u32 chip_id;u32 chip_ver; +enum rtl8365mb_family family;const struct rtl8365mb_extint extints[RTL8365MB_MAX_NUM_EXTINTS ];const struct rtl8365mb_jam_tbl_entry *jam_table;size_t jam_size;
@@ -731,6 +734,7 @@ static const struct rtl8365mb_chip_info rtl8365mb_chip_infos[] = { .name = "RTL8365MB-VC", .chip_id = 0x6367, .chip_ver = 0x0040, + .family = RTL8365MB_FAMILY_C, .extints = { {6 ,1 ,PHY_INTF (MII ) |PHY_INTF (TMII ) | PHY_INTF(RMII) | PHY_INTF(RGMII) },
@@ -742,6 +746,7 @@ static const struct rtl8365mb_chip_info rtl8365mb_chip_infos[] = { .name = "RTL8367S", .chip_id = 0x6367, .chip_ver = 0x00A0, + .family = RTL8365MB_FAMILY_C, .extints = { { 6, 1, PHY_INTF(SGMII) | PHY_INTF(HSGMII) }, { 7, 2, PHY_INTF(MII) | PHY_INTF(TMII) |
@@ -754,6 +759,7 @@ static const struct rtl8365mb_chip_info rtl8365mb_chip_infos[] = { .name = "RTL8367SB", .chip_id = 0x6367, .chip_ver = 0x0010, + .family = RTL8365MB_FAMILY_C, .extints = { {6 ,1 ,PHY_INTF (MII ) |PHY_INTF (TMII ) | PHY_INTF(RMII) | PHY_INTF(RGMII) |
@@ -768,6 +774,7 @@ static const struct rtl8365mb_chip_info rtl8365mb_chip_infos[] = { .name = "RTL8367RB-VB", .chip_id = 0x6367, .chip_ver = 0x0020, + .family = RTL8365MB_FAMILY_C, .extints = { {6 ,1 ,PHY_INTF (MII ) |PHY_INTF (TMII ) | PHY_INTF(RMII) | PHY_INTF(RGMII) },
@@ -874,6 +881,13 @@ struct rtl8365mb {#define pcs_to_rtl8365mb (_pcs) container_of((_pcs), struct rtl8365mb, pcs) +enum rtl8365mb_family rtl8365mb_get_family (struct realtek_priv *priv) +{ +struct rtl8365mb *mb = priv->chip_data; + +return mb->chip_info->family; +} +static int rtl8365mb_phy_poll_busy (struct realtek_priv *priv) {u32 val;
Signature · 1 line
2.53.0
PATCH v7 3/10 net: dsa: realtek: rtl8365mb: set speed for family D
In reply to Mieczyslaw NalewajOn 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.
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 | 82 ++++++++++++++++++++---- 1 file changed, 69 insertions(+), 13 deletions(-)
drivers/net/dsa/realtek/rtl8365mb_main.c +69 -13
@@ -344,6 +344,7 @@#define RTL8365MB_PORT_SPEED_10M 0#define RTL8365MB_PORT_SPEED_100M 1#define RTL8365MB_PORT_SPEED_1000M 2 +#define RTL8365MB_D_PORT_SPEED_2500M 5/* External interface force configuration registers 0~2 */ #define RTL8365MB_DIGITAL_INTERFACE_FORCE_REG0 0x1310/* EXT0 */
@@ -361,6 +362,28 @@#define RTL8365MB_DIGITAL_INTERFACE_FORCE_LINK_MASK BIT(4)#define RTL8365MB_DIGITAL_INTERFACE_FORCE_DUPLEX_MASK BIT(2)#define RTL8365MB_DIGITAL_INTERFACE_FORCE_SPEED_MASK GENMASK(1, 0) +/* Width of the FORCE_SPEED field, bits[1:0] */ +#define RTL8365MB_DIGITAL_INTERFACE_FORCE_SPEED_WIDTH 2 + +/* bits[13:12]; bit 13 reserved, no defined speed value uses it yet */ +#define RTL8365MB_D_DIGITAL_INTERFACE_FORCE_SPEED2_MASK GENMASK(13, 12) + +#define RTL8365MB_D_DIGITAL_INTERFACE_FORCE_REG_BASE 0x12c0 +#define RTL8365MB_D_DIGITAL_INTERFACE_FORCE_REG (_port) \ + (RTL8365MB_D_DIGITAL_INTERFACE_FORCE_REG_BASE + (_port)) + +#define RTL8365MB_D_DIGITAL_INTERFACE_FORCE_EN_BASE 0x12c8 +#define RTL8365MB_D_DIGITAL_INTERFACE_FORCE_REG_EN (_port) \ + (RTL8365MB_D_DIGITAL_INTERFACE_FORCE_EN_BASE + (_port)) + +/* Per-port force-mode enable. The vendor RTL8367D API +* (dal_rtl8367d_port_macForceLink_set()) treats it as an on/off switch for +* the whole forced configuration: all bits set when the MAC is forced, zero +* when it is not. The meaning of the individual bits is not documented. +* This driver always forces the MAC, as on family C, so all bits are set +* on every call, including link down. +*/ +#define RTL8365MB_D_DIGITAL_INTERFACE_FORCE_EN_ALL_MASK GENMASK(15, 0)/* CPU port mask register - controls which ports are treated as CPU ports */ #define RTL8365MB_CPU_PORT_MASK_REG 0x1219
@@ -1646,23 +1669,32 @@ static int rtl8365mb_ext_config_forcemode(struct realtek_priv *priv, int port,u32 r_duplex;u32 r_speed;u32 r_link; +bool is_d;int val;int ret;if (!extint)return -ENODEV ; + is_d =rtl8365mb_get_family (priv) ==RTL8365MB_FAMILY_D ;if (link) {/* Force the link up with the desired configuration */ r_link =1 ; r_rx_pause = rx_pause ?1 :0 ; r_tx_pause = tx_pause ?1 :0 ; -/* 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. -*/ -if (speed ==SPEED_2500 || speed ==SPEED_1000 ) { +if (speed ==SPEED_2500 ) { +if (is_d) { + r_speed =RTL8365MB_D_PORT_SPEED_2500M ; + }else { +/* 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. +*/ + r_speed =RTL8365MB_PORT_SPEED_1000M ; + } + }else if (speed ==SPEED_1000 ) { r_speed =RTL8365MB_PORT_SPEED_1000M ; }else if (speed ==SPEED_100 ) { r_speed =RTL8365MB_PORT_SPEED_100M ;
@@ -1692,20 +1724,44 @@ static int rtl8365mb_ext_config_forcemode(struct realtek_priv *priv, int port, r_duplex =0 ; } - val =FIELD_PREP (RTL8365MB_DIGITAL_INTERFACE_FORCE_EN_MASK ,1 ) | -FIELD_PREP (RTL8365MB_DIGITAL_INTERFACE_FORCE_TXPAUSE_MASK , + val =FIELD_PREP (RTL8365MB_DIGITAL_INTERFACE_FORCE_TXPAUSE_MASK , r_tx_pause) |FIELD_PREP (RTL8365MB_DIGITAL_INTERFACE_FORCE_RXPAUSE_MASK , r_rx_pause) |FIELD_PREP (RTL8365MB_DIGITAL_INTERFACE_FORCE_LINK_MASK , r_link) |FIELD_PREP (RTL8365MB_DIGITAL_INTERFACE_FORCE_DUPLEX_MASK , r_duplex) | -FIELD_PREP (RTL8365MB_DIGITAL_INTERFACE_FORCE_SPEED_MASK , r_speed); - ret =regmap_write (priv->map, -RTL8365MB_DIGITAL_INTERFACE_FORCE_REG (extint->id), - val); -if (ret) -return ret; +FIELD_PREP (RTL8365MB_DIGITAL_INTERFACE_FORCE_SPEED_MASK , + r_speed & +RTL8365MB_DIGITAL_INTERFACE_FORCE_SPEED_MASK ); + +if (is_d) { +/* Speed is 3 bits on family D: bits[1:0] go into FORCE_SPEED, +* bit[2] goes into FORCE_SPEED2 (bit 12); only 2500M sets it, +* bit 13 of the field is unused. +*/ + val |=FIELD_PREP (RTL8365MB_D_DIGITAL_INTERFACE_FORCE_SPEED2_MASK , + r_speed >> +RTL8365MB_DIGITAL_INTERFACE_FORCE_SPEED_WIDTH ); + ret =regmap_write (priv->map, +RTL8365MB_D_DIGITAL_INTERFACE_FORCE_REG (port), + val); +if (ret) +return ret; + + ret =regmap_write (priv->map, +RTL8365MB_D_DIGITAL_INTERFACE_FORCE_REG_EN (port), +RTL8365MB_D_DIGITAL_INTERFACE_FORCE_EN_ALL_MASK ); +if (ret) +return ret; + }else { + val |=FIELD_PREP (RTL8365MB_DIGITAL_INTERFACE_FORCE_EN_MASK ,1 ); + ret =regmap_write (priv->map, +RTL8365MB_DIGITAL_INTERFACE_FORCE_REG (extint->id), + val); +if (ret) +return ret; + }return 0 ; }
Signature · 1 line
2.53.0
PATCH v7 4/10 net: dsa: realtek: rtl8365mb: set RGMII mode for family D
In reply to Mieczyslaw NalewajOn family D, RGMII on extension interface 1 needs two 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, and the pin mux in the top-level configuration register must be set up.
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 a warning naming the conflict. When MAC4 does not own the pins, bind the RGMII/MII pins to MAC7. SerDes 1, which shares the pins, is always disabled. 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 | 72 +++++++++++++++++++++++- 1 file changed, 70 insertions(+), 2 deletions(-)
drivers/net/dsa/realtek/rtl8365mb_main.c +70 -2
@@ -332,6 +332,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
@@ -465,6 +471,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
@@ -1261,6 +1281,33 @@ static int rtl8365mb_ext_config_rgmii(struct realtek_priv *priv, int port,if (ret)return ret; +if (rtl8365mb_get_family (priv) ==RTL8365MB_FAMILY_D && + 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),
@@ -1773,6 +1820,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 ;
@@ -1802,8 +1851,27 @@ 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_get_family (priv) ==RTL8365MB_FAMILY_D && + extint->id ==1 ) { + ret =regmap_read (priv->map,RTL8365MB_D_REG_TOP_CON0 , &data); +if (ret) +dev_warn (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_warn (priv->dev, +"port %d: EXT1 is owned by MAC4, RGMII disabled\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
PATCH v7 5/10 net: dsa: realtek: rtl8365mb: set and get vlan 4k for family D
In reply to Mieczyslaw NalewajThe 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) follows vlan4k->ivl_en, as on family C; the only caller, rtl8365mb_vlan_4k_port_set(), always requests IVL. SVLAN_CHK_IVL_SVL (bit 2) is left at 0, as in the vendor RTL8367D CVLAN API, which sets it only from the SVLAN member API; this driver has no SVLAN support. vlan4k->ivl_en is read back from IVL_EN.
Reusing the three-word family C layout unconditionally means the third word is read from and written back to the register that holds it on family C, but does not exist as a distinct table word on family D's die; whatever data happens to be there gets folded into member/untag bits [10:8] on read, and re-written on every read-modify-write cycle in rtl8365mb_vlan_4k_port_set(). Give family D its own two-word pack/unpack instead.
The two-word layout matches the vendor switch API for this chip family, which writes only 0x0510/0x0511 for a CVLAN entry.
The family D paths are not reachable until the RTL8367S-VB chip table entry is added in the last patch of the series.
--- drivers/net/dsa/realtek/rtl8365mb_vlan.c | 161 ++++++++++++++++------- 1 file changed, 111 insertions(+), 50 deletions(-)
drivers/net/dsa/realtek/rtl8365mb_vlan.c +111 -50
@@ -48,12 +48,16 @@#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] */ +/* CVLAN (i.e. VLAN4k) table entry layout: u16[3] on family C, u16[2] on +* family D +*/ #define RTL8365MB_CVLAN_ENTRY_SIZE 3/* 48-bits */ +#define RTL8365MB_D_CVLAN_ENTRY_SIZE 2/* 32-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)
@@ -65,6 +69,9 @@#define RTL8365MB_CVLAN_ENTRY_D1_METERIDX_MASK GENMASK(13, 9)#define RTL8365MB_CVLAN_METERIDX_LO_MASK GENMASK(4, 0)#define RTL8365MB_CVLAN_ENTRY_D1_IVL_SVL_MASK GENMASK(14, 14) +/* Family D CVLAN entry, word 1 (family D has no word 2) */ +#define RTL8365MB_D_CVLAN_ENTRY_D1_IVL_EN_MASK GENMASK(3, 3) +#define RTL8365MB_D_CVLAN_ENTRY_D1_FID_MASK GENMASK(1, 0)/* extends RTL8365MB_CVLAN_ENTRY_D0_MBR_MASK */ #define RTL8365MB_CVLAN_ENTRY_D2_MBR_EXT_MASK GENMASK(2, 0)#define RTL8365MB_CVLAN_MBR_HI_MASK GENMASK(10, 8)
@@ -185,13 +192,16 @@ struct rtl8365mb_vlanmc {static int rtl8365mb_vlan_4k_read (struct realtek_priv *priv,u16 vid,struct rtl8365mb_vlan4k *vlan4k) { +bool is_d =rtl8365mb_get_family (priv) ==RTL8365MB_FAMILY_D ; +size_t entry_size = is_d ?RTL8365MB_D_CVLAN_ENTRY_SIZE : +RTL8365MB_CVLAN_ENTRY_SIZE ;u16 data[RTL8365MB_CVLAN_ENTRY_SIZE ];int val;int ret; ret =rtl8365mb_table_query (priv,RTL8365MB_TABLE_CVLAN ,RTL8365MB_TABLE_OP_READ , &vid,0 ,0 , - data,ARRAY_SIZE (data)); + data, entry_size);if (ret)return ret;
@@ -199,33 +209,61 @@ static int rtl8365mb_vlan_4k_read(struct realtek_priv *priv, u16 vid,memset (vlan4k,0 ,sizeof (*vlan4k)); vlan4k->vid = vid; +/* member/untag: d0[7:0]/d0[15:8] on both families. Family C +* extends these into data[2] bits [2:0]/[5:3] for its 9th-11th +* ports; family D's die has only 8 ports and no third table +* word, so data[2] does not exist there and must not be read. +*/ val =FIELD_GET (RTL8365MB_CVLAN_ENTRY_D0_MBR_MASK , data[0 ]); vlan4k->member =FIELD_PREP (RTL8365MB_CVLAN_MBR_LO_MASK , val); - val =FIELD_GET (RTL8365MB_CVLAN_ENTRY_D2_MBR_EXT_MASK , data[2 ]); - vlan4k->member |=FIELD_PREP (RTL8365MB_CVLAN_MBR_HI_MASK , val); +if (!is_d) { + val =FIELD_GET (RTL8365MB_CVLAN_ENTRY_D2_MBR_EXT_MASK , data[2 ]); + vlan4k->member |=FIELD_PREP (RTL8365MB_CVLAN_MBR_HI_MASK , val); + } val =FIELD_GET (RTL8365MB_CVLAN_ENTRY_D0_UNTAG_MASK , data[0 ]); vlan4k->untag =FIELD_PREP (RTL8365MB_CVLAN_UNTAG_LO_MASK , val); - val =FIELD_GET (RTL8365MB_CVLAN_ENTRY_D2_UNTAG_EXT_MASK , data[2 ]); - vlan4k->untag |=FIELD_PREP (RTL8365MB_CVLAN_UNTAG_HI_MASK , val); - - vlan4k->fid =FIELD_GET (RTL8365MB_CVLAN_ENTRY_D1_FID_MASK , data[1 ]); - vlan4k->priority_en = -FIELD_GET (RTL8365MB_CVLAN_ENTRY_D1_VBPEN_MASK , data[1 ]); - vlan4k->priority = -FIELD_GET (RTL8365MB_CVLAN_ENTRY_D1_VBPRI_MASK , data[1 ]); - vlan4k->policing_en = -FIELD_GET (RTL8365MB_CVLAN_ENTRY_D1_ENVLANPOL_MASK , data[1 ]); - - val =FIELD_GET (RTL8365MB_CVLAN_ENTRY_D1_METERIDX_MASK , data[1 ]); - val =FIELD_PREP (RTL8365MB_CVLAN_METERIDX_LO_MASK , val); - vlan4k->meteridx = val; - val =FIELD_GET (RTL8365MB_CVLAN_ENTRY_D2_METERIDX_EXT_MASK , data[2 ]); - val =FIELD_PREP (RTL8365MB_CVLAN_METERIDX_HI_MASK , val); - vlan4k->meteridx |= val; - - vlan4k->ivl_en = -FIELD_GET (RTL8365MB_CVLAN_ENTRY_D1_IVL_SVL_MASK , data[1 ]); +if (!is_d) { + val =FIELD_GET (RTL8365MB_CVLAN_ENTRY_D2_UNTAG_EXT_MASK , + data[2 ]); + vlan4k->untag |=FIELD_PREP (RTL8365MB_CVLAN_UNTAG_HI_MASK , val); + } + +if (is_d) { + vlan4k->fid =FIELD_GET (RTL8365MB_D_CVLAN_ENTRY_D1_FID_MASK , + data[1 ]); +/* Family D has no priority/meter fields in this entry - +* left zeroed by the memset() above. +*/ + vlan4k->ivl_en = +FIELD_GET (RTL8365MB_D_CVLAN_ENTRY_D1_IVL_EN_MASK , + data[1 ]); + }else { + vlan4k->fid =FIELD_GET (RTL8365MB_CVLAN_ENTRY_D1_FID_MASK , + data[1 ]); + vlan4k->priority_en = +FIELD_GET (RTL8365MB_CVLAN_ENTRY_D1_VBPEN_MASK , + data[1 ]); + vlan4k->priority = +FIELD_GET (RTL8365MB_CVLAN_ENTRY_D1_VBPRI_MASK , + data[1 ]); + vlan4k->policing_en = +FIELD_GET (RTL8365MB_CVLAN_ENTRY_D1_ENVLANPOL_MASK , + data[1 ]); + + val =FIELD_GET (RTL8365MB_CVLAN_ENTRY_D1_METERIDX_MASK , + data[1 ]); + val =FIELD_PREP (RTL8365MB_CVLAN_METERIDX_LO_MASK , val); + vlan4k->meteridx = val; + val =FIELD_GET (RTL8365MB_CVLAN_ENTRY_D2_METERIDX_EXT_MASK , + data[2 ]); + val =FIELD_PREP (RTL8365MB_CVLAN_METERIDX_HI_MASK , val); + vlan4k->meteridx |= val; + + vlan4k->ivl_en = +FIELD_GET (RTL8365MB_CVLAN_ENTRY_D1_IVL_SVL_MASK , + data[1 ]); + }return 0 ; }
@@ -233,6 +271,9 @@ static int rtl8365mb_vlan_4k_read(struct realtek_priv *priv, u16 vid,static int rtl8365mb_vlan_4k_write (struct realtek_priv *priv,const struct rtl8365mb_vlan4k *vlan4k) { +bool is_d =rtl8365mb_get_family (priv) ==RTL8365MB_FAMILY_D ; +size_t entry_size = is_d ?RTL8365MB_D_CVLAN_ENTRY_SIZE : +RTL8365MB_CVLAN_ENTRY_SIZE ;u16 data[RTL8365MB_CVLAN_ENTRY_SIZE ] = {0 };u16 vid;int val;
@@ -244,36 +285,56 @@ static int rtl8365mb_vlan_4k_write(struct realtek_priv *priv, val =FIELD_GET (RTL8365MB_CVLAN_UNTAG_LO_MASK , vlan4k->untag); data[0 ] |=FIELD_PREP (RTL8365MB_CVLAN_ENTRY_D0_UNTAG_MASK , val); - data[1 ] |=FIELD_PREP (RTL8365MB_CVLAN_ENTRY_D1_FID_MASK , vlan4k->fid); - data[1 ] |=FIELD_PREP (RTL8365MB_CVLAN_ENTRY_D1_VBPEN_MASK , - vlan4k->priority_en); - data[1 ] |=FIELD_PREP (RTL8365MB_CVLAN_ENTRY_D1_VBPRI_MASK , - vlan4k->priority); - data[1 ] |=FIELD_PREP (RTL8365MB_CVLAN_ENTRY_D1_ENVLANPOL_MASK , - vlan4k->policing_en); - -/* FIELD_* does not play nice with struct bitfield. */ - val = vlan4k->meteridx; - val =FIELD_GET (RTL8365MB_CVLAN_METERIDX_LO_MASK , val); - data[1 ] |=FIELD_PREP (RTL8365MB_CVLAN_ENTRY_D1_METERIDX_MASK , val); - - data[1 ] |=FIELD_PREP (RTL8365MB_CVLAN_ENTRY_D1_IVL_SVL_MASK , - vlan4k->ivl_en); - - val =FIELD_GET (RTL8365MB_CVLAN_MBR_HI_MASK , vlan4k->member); - data[2 ] |=FIELD_PREP (RTL8365MB_CVLAN_ENTRY_D2_MBR_EXT_MASK , val); - - val =FIELD_GET (RTL8365MB_CVLAN_UNTAG_HI_MASK , vlan4k->untag); - data[2 ] |=FIELD_PREP (RTL8365MB_CVLAN_ENTRY_D2_UNTAG_EXT_MASK , val); - - val = vlan4k->meteridx; - val =FIELD_GET (RTL8365MB_CVLAN_METERIDX_HI_MASK , val); - data[2 ] |=FIELD_PREP (RTL8365MB_CVLAN_ENTRY_D2_METERIDX_EXT_MASK , val); +if (is_d) { +/* IVL_EN follows the caller, as on family C. The vendor CVLAN +* API leaves SVLAN_CHK_IVL_SVL at 0, and this driver has no +* SVLAN support. +*/ + data[1 ] |=FIELD_PREP (RTL8365MB_D_CVLAN_ENTRY_D1_IVL_EN_MASK , + vlan4k->ivl_en); + data[1 ] |=FIELD_PREP (RTL8365MB_D_CVLAN_ENTRY_D1_FID_MASK , + vlan4k->fid); +/* No priority/meter/member-untag-extension fields exist in +* family D's 2-word entry - data[1] and data[0] above are +* the whole entry, and data[2] is not part of it at all. +*/ + }else { + val = vlan4k->fid; + data[1 ] |=FIELD_PREP (RTL8365MB_CVLAN_ENTRY_D1_FID_MASK , val); + data[1 ] |=FIELD_PREP (RTL8365MB_CVLAN_ENTRY_D1_VBPEN_MASK , + vlan4k->priority_en); + data[1 ] |=FIELD_PREP (RTL8365MB_CVLAN_ENTRY_D1_VBPRI_MASK , + vlan4k->priority); + data[1 ] |=FIELD_PREP (RTL8365MB_CVLAN_ENTRY_D1_ENVLANPOL_MASK , + vlan4k->policing_en); + +/* FIELD_* does not play nice with struct bitfield. */ + val = vlan4k->meteridx; + val =FIELD_GET (RTL8365MB_CVLAN_METERIDX_LO_MASK , val); + data[1 ] |=FIELD_PREP (RTL8365MB_CVLAN_ENTRY_D1_METERIDX_MASK , + val); + + data[1 ] |=FIELD_PREP (RTL8365MB_CVLAN_ENTRY_D1_IVL_SVL_MASK , + vlan4k->ivl_en); + + val =FIELD_GET (RTL8365MB_CVLAN_MBR_HI_MASK , vlan4k->member); + data[2 ] |=FIELD_PREP (RTL8365MB_CVLAN_ENTRY_D2_MBR_EXT_MASK , + val); + + val =FIELD_GET (RTL8365MB_CVLAN_UNTAG_HI_MASK , vlan4k->untag); + data[2 ] |=FIELD_PREP (RTL8365MB_CVLAN_ENTRY_D2_UNTAG_EXT_MASK , + val); + + val = vlan4k->meteridx; + val =FIELD_GET (RTL8365MB_CVLAN_METERIDX_HI_MASK , val); + data[2 ] |=FIELD_PREP (RTL8365MB_CVLAN_ENTRY_D2_METERIDX_EXT_MASK , + val); + } vid = vlan4k->vid;return rtl8365mb_table_query (priv,RTL8365MB_TABLE_CVLAN ,RTL8365MB_TABLE_OP_WRITE , &vid,0 ,0 , - data,ARRAY_SIZE (data)); + data, entry_size); } static int
Signature · 1 line
2.53.0
PATCH v7 6/10 net: dsa: realtek: rtl8365mb: use raw VID for PVID on family D
In reply to Mieczyslaw NalewajFamily 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.
Read the PVID straight from its register in rtl8365mb_vlan_port_get_pvid(), and make rtl8365mb_vlan_pvid_port_set() and rtl8365mb_vlan_pvid_port_clear() use direct-VID variants on family D that skip the MC table. They keep the family C frame filter handling and rollback on error.
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.
No functional change for family C.
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 | 9 + drivers/net/dsa/realtek/rtl8365mb_vlan.c | 205 ++++++++++++++++++++++- drivers/net/dsa/realtek/rtl8365mb_vlan.h | 1 + 3 files changed, 210 insertions(+), 5 deletions(-)
drivers/net/dsa/realtek/rtl8365mb_main.c +9 -0
@@ -2360,6 +2360,15 @@ static int rtl8365mb_vlan_setup(struct dsa_switch *ds)int ret;dsa_switch_for_each_available_port (dp, ds) { +/* Start every port with the neutral PVID */ + ret =rtl8365mb_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 -5
269 lines not on this page · raw message
drivers/net/dsa/realtek/rtl8365mb_vlan.h +1 -0
@@ -20,6 +20,7 @@ enum rtl8365mb_frame_ingress {int rtl8365mb_vlan_port_get_pvid (struct realtek_priv *priv,int port,u16 *pvid); +int rtl8365mb_vlan_port_reset_pvid (struct realtek_priv *priv,int port); int rtl8365mb_vlan_port_get_framefilter(struct realtek_priv *priv, int port,
Signature · 1 line
2.53.0
PATCH v7 7/10 net: dsa: realtek: rtl8365mb: add family D SDS13 PCS support
In reply to Mieczyslaw NalewajExtend 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.
This patch only prepares the family D paths; they become reachable when the RTL8367S-VB chip entry is added in the last patch.
--- drivers/net/dsa/realtek/rtl8365mb_main.c | 242 +++++++++++++++++------ 1 file changed, 187 insertions(+), 55 deletions(-)
drivers/net/dsa/realtek/rtl8365mb_main.c +187 -55
@@ -262,7 +262,8 @@* 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 external port, base port 5), as in the vendor RTL8367D API. */ #define RTL8365MB_BYPASS_LINE_RATE_REG 0x03F7#define RTL8365MB_BYPASS_LINE_RATE_MASK (_port) BIT((_port) - 5)
@@ -284,6 +285,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
@@ -313,8 +315,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
@@ -332,7 +336,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. */
@@ -720,6 +739,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),
@@ -1320,7 +1354,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;
@@ -1338,10 +1373,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;
@@ -1351,7 +1389,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;
@@ -1391,6 +1431,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_get_family (priv) ==RTL8365MB_FAMILY_D ) { + 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];
@@ -1472,25 +1520,44 @@ 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_get_family (priv) ==RTL8365MB_FAMILY_D ; +/* 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
@@ -1519,34 +1586,57 @@ 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) { +/* Bit 6 disables the RX of SDS0. As in the vendor RTL8367D +* 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;
@@ -1556,27 +1646,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)
@@ -1601,18 +1696,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_get_family (priv) ==RTL8365MB_FAMILY_D ; + +/* 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 ;
@@ -1623,6 +1727,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. */
@@ -1664,6 +1785,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_get_family (priv) ==RTL8365MB_FAMILY_D ) +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.
@@ -1954,7 +2081,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)) {
@@ -1987,9 +2114,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)) {
@@ -2003,18 +2132,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_ext_config_forcemode(). */ -if (rtl8365mb_interface_is_serdes (interface)) { +if (rtl8365mb_interface_is_serdes (interface) && +rtl8365mb_get_family (priv) !=RTL8365MB_FAMILY_D ) {u32 val =0 ;if (tx_pause)
Signature · 1 line
2.53.0
PATCH v7 8/10 net: dsa: realtek: rtl8365mb: re-latch the family D SerDes
In reply to Mieczyslaw NalewajThe family D receiver latches on the DISABLE -> HSGMII edge in SDS_MISC rather than on the value, and it will not latch until the MAC at the other end of the trunk has brought its own half of the link up. If it does not latch, the trunk reports 2.5Gbps/Full on both sides but moves no frames: the CPU MAC transmits, the switch CPU port counts no octets, and there are no CRC, alignment or FIFO errors.
The two ends can be seconds apart, e.g. on an IPQ5018 board:
5.27 rtl8365mb: configuring for fixed/2500base-x <- pcs_config() 7.72 ipq5018-gmac-dwmac eth0: configuring for fixed/2500base-x 8.02 ipq5018-gmac-dwmac eth0: Link is Up - 2.5Gbps/Full 8.56 SerDes latches
pcs_config() runs seconds before the far-end MAC even starts configuring, so a single edge driven from there is not enough: the receiver has nothing to latch onto yet. Neither is pcs_link_up(), which is seconds early for the same reason. phylink does not help either - it never calls rtl8365mb_pcs_get_state() for this port in the first place, since mb->pcs.poll only arms phylink's own poll for in-band links, and this CPU port is a fixed link.
There is no local signal that predicts when the far-end MAC will bring up its half of the link (bit 8 of the SDS link-status word does not change ahead of it), so the work cannot wait for it; it can only tell afterwards, from the link-status bit, whether an edge took.
The far-end MAC starts when its conduit is brought up, which DSA reports through ->conduit_state_change(), so an episode of re-latch attempts starts there. Only the conduit of the CPU port that carries the SerDes (port 6) is considered: the chip can have a second CPU port on RGMII, and its conduit says nothing about the SerDes link. pcs_config() only arms the work, and starts an episode itself if that conduit is already up. The work re-arms itself after each edge; the next run checks whether the edge took, rather than waiting on a poll that will not come. When the conduit goes down the work is stopped, so a link without a far end is not reported as lost and not parked every 10 s.
Each attempt (park for 20 ms, then restore the target mode) is performed by a work item rather than from the callbacks, because the attempts have to continue for seconds after they have returned. pcs_config(), pcs_disable(), teardown() and conduit_state_change() are serialized by a new sds_cfg_lock and cancel the work before touching SDS_MISC or restarting it, so an attempt never interleaves with a reconfiguration. Before parking, the work reads the link status itself and does not park if the receiver has already latched, since the condition that queued it may be stale by the time it runs; it then ends the episode instead.
Attempts are spaced about 1 s apart and capped at RTL8365MB_D_SDS_RELATCH_MAX_TRIES (15) per fast episode. After the last attempt one more run checks whether it took and only then warns that the SerDes did not latch. The work then keeps driving one edge per RTL8365MB_D_SDS_HEALTHCHECK_INTERVAL, so a far end that comes up late or a link that drops again is recovered without a reconfiguration, at a bounded cost of one 20 ms park per interval.
Once the receiver has latched, the work keeps checking the link every 10 s (RTL8365MB_D_SDS_HEALTHCHECK_INTERVAL). If it finds the link down outside a reconfiguration, e.g. after the far end reset its PLL, it logs that and starts a new episode.
For family D, pcs_config() keeps the masked update of SDS_MISC and saves the value it wrote as the target the work restores. The work parks and restores with masked updates over the same fields, so other bits are never touched.
The work reads the SerDes link status through the SDS_INDACS indirect access window, a multi-register ADR/CMD/DATA sequence that the PCS callbacks also use, so those sequences are serialized by a new sds_lock. The SDS_MISC updates need no extra locking: each one is a single regmap read-modify-write.
The work is only armed for 2500base-x, the mode the re-latch edge was observed with. It is cancelled from pcs_disable(), from pcs_config() before SDS_MISC is touched, from conduit_state_change() and from teardown(), and disabled by a reboot notifier and by a devres action. disable_delayed_work_sync() is used in the latter two so that a late pcs_config() cannot queue the work again, and so that it never outlives the PCS or the driver data and does not touch the bus while it is shut down. dsa_switch_shutdown() does not stop the PCS, which is why the reboot notifier is needed.
If restoring the target mode fails, the lane stays parked. The mode field in SDS_MISC tells so, and the next run of the work puts it back before doing anything else. If the work is stopped before that run, the lane stays parked until the next pcs_config().
No chip uses family D before the last patch of the series, so this code is unreachable until then.
--- drivers/net/dsa/realtek/rtl8365mb_main.c | 387 ++++++++++++++++++++++- 1 file changed, 372 insertions(+), 15 deletions(-)
drivers/net/dsa/realtek/rtl8365mb_main.c +372 -15
@@ -97,6 +97,9 @@#include <linux/irqdomain.h> #include <linux/mii.h> #include <linux/mutex.h> +#include <linux/workqueue.h> +#include <linux/reboot.h> +#include <linux/cleanup.h> #include <linux/of_irq.h> #include <linux/regmap.h> #include <linux/if_bridge.h>
@@ -299,6 +302,29 @@#define RTL8365MB_SDS_MISC_SGMII_SPD_MASK GENMASK(8, 7)#define RTL8365MB_SDS_MISC_MAC8_SEL_SGMII_MASK BIT(6) +/* Re-latch retry interval and attempt budget. Each attempt parks the +* SerDes for 20 ms, so a far end that never comes up must not be retried +* at this rate forever, and the interval must not be so tight that +* back-to-back parks starve a link that is about to latch. The count is +* reset to 1 whenever an episode starts and to 0 whenever the receiver +* latches. Episodes start when the conduit comes up, so with the +* interval below the budget is roughly RELATCH_MAX_TRIES seconds, which +* is generous for a far end that needs a moment to bring up its half of +* the link. +*/ +#define RTL8365MB_D_SDS_RELATCH_INTERVAL (HZ) +#define RTL8365MB_D_SDS_RELATCH_MAX_TRIES 15 + +/* The SerDes stays parked until the restore write succeeds, so the write is +* attempted up to this many times before giving up until the next run. +*/ +#define RTL8365MB_D_SDS_RESTORE_TRIES 3 + +/* How often a latched (or out-of-budget) SerDes is checked, and re-latched +* if still down. Much slower than the re-latch interval. +*/ +#define RTL8365MB_D_SDS_HEALTHCHECK_INTERVAL (10 * HZ) +/* SerDes internal registers, accessed via the SDS_INDACS registers. The BMCR * data path reset holds BMCR_ANENABLE | BMCR_ISOLATE while toggling the * vendor-specific low bits from phase 1 to phase 2, which triggers a data path
@@ -938,10 +964,23 @@ struct rtl8365mb_port {* @chip_info: chip-specific info about the attached switch * @cpu: CPU tagging and CPU port configuration for this chip * @mib_lock: prevent concurrent reads of MIB counters +* @sds_cfg_lock: serializes pcs_config(), pcs_disable(), teardown() and +* conduit_state_change(), which arm, start and stop the +* re-latch work +* @sds_lock: serializes access to the shared SDS_INDACS ADR/CMD/DATA window, +* reachable both from phylink's PCS callbacks and from the +* family D SerDes re-latch work * @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_reboot_nb: disables @sds_relatch before the devices are shut down +* @sds_relatch: re-latch edges and link health check (family D) +* @sds_relatch_count: next attempt of the re-latch episode, 0 once latched +* @sds_misc_target_val: SDS_MISC_CFG_MASK fields the re-latch work restores +* @sds_relatch_armed: pcs_config() set up 2500base-x; the re-latch work may run +* @sds_conduit_up: the conduit of the CPU port that carries the SerDes (port 6) +* is admin and oper up * * Private data for this driver. */
@@ -951,9 +990,17 @@ struct rtl8365mb {const struct rtl8365mb_chip_info *chip_info;struct rtl8365mb_cpu cpu;struct mutex mib_lock; +struct mutex sds_cfg_lock; +struct mutex sds_lock;struct rtl8365mb_port ports[RTL8365MB_MAX_NUM_PORTS ];struct phylink_pcs pcs;bool sds_supported; +struct notifier_block sds_reboot_nb; +struct delayed_work sds_relatch; +unsigned int sds_relatch_count; +u32 sds_misc_target_val; +bool sds_relatch_armed; +bool sds_conduit_up; };#define pcs_to_rtl8365mb (_pcs) container_of((_pcs), struct rtl8365mb, pcs)
@@ -1357,43 +1404,53 @@ static int rtl8365mb_ext_config_rgmii(struct realtek_priv *priv, int port,static int rtl8365mb_sds_write (struct realtek_priv *priv,u8 index,u16 addr,u16 data) { +struct rtl8365mb *mb = priv->chip_data;int ret; +mutex_lock (&mb->sds_lock); + ret =regmap_write (priv->map,RTL8365MB_SDS_INDACS_DATA_REG , data);if (ret) -return ret; + goto out_unlock; ret =regmap_write (priv->map,RTL8365MB_SDS_INDACS_ADR_REG , addr);if (ret) -return ret; + goto out_unlock;/* The SerDes indirect access engine completes the command within the * register write transaction, so there is no need to wait or poll for * completion before the next access, matching the vendor driver. */ -return regmap_write (priv->map,RTL8365MB_SDS_INDACS_CMD_REG , -RTL8365MB_SDS_INDACS_CMD_RUN_MASK | -RTL8365MB_SDS_INDACS_CMD_WR_MASK | -FIELD_PREP (RTL8365MB_SDS_INDACS_CMD_INDEX_MASK , - index)); + ret =regmap_write (priv->map,RTL8365MB_SDS_INDACS_CMD_REG , +RTL8365MB_SDS_INDACS_CMD_RUN_MASK | +RTL8365MB_SDS_INDACS_CMD_WR_MASK | +FIELD_PREP (RTL8365MB_SDS_INDACS_CMD_INDEX_MASK , + index)); + +out_unlock: +mutex_unlock (&mb->sds_lock); +return ret; }static int rtl8365mb_sds_read (struct realtek_priv *priv,u8 index,u16 addr,u16 *data) { +struct rtl8365mb *mb = priv->chip_data;u32 val;int ret; +mutex_lock (&mb->sds_lock); + ret =regmap_write (priv->map,RTL8365MB_SDS_INDACS_ADR_REG , addr);if (ret) -return ret; + goto out_unlock; ret =regmap_write (priv->map,RTL8365MB_SDS_INDACS_CMD_REG ,RTL8365MB_SDS_INDACS_CMD_RUN_MASK |FIELD_PREP (RTL8365MB_SDS_INDACS_CMD_INDEX_MASK , index));if (ret) -return ret; + goto out_unlock;/* Wait for the indirect read to complete: the engine clears the BUSY * bit once the data register holds the result.
@@ -1403,15 +1460,19 @@ static int rtl8365mb_sds_read(struct realtek_priv *priv, u8 index, !(val &RTL8365MB_SDS_INDACS_CMD_BUSY_MASK ), 10, 1000);if (ret) -return ret; + goto out_unlock; ret =regmap_read (priv->map,RTL8365MB_SDS_INDACS_DATA_REG , &val);if (ret) -return ret; + goto out_unlock; *data = val; -return 0 ; + ret =0 ; + +out_unlock: +mutex_unlock (&mb->sds_lock); +return ret; }/* The vendor driver selects between two sets of SerDes tuning parameters based
@@ -1512,6 +1573,37 @@ static int rtl8365mb_sds_raise_rate_limits(struct realtek_priv *priv) RTL8365MB_PORT6_EGRESSBW_CTRL1_MASK); } +static void rtl8365mb_sds_relatch_start (struct rtl8365mb *mb) +{ +WRITE_ONCE (mb->sds_relatch_count,1 ); +schedule_delayed_work (&mb->sds_relatch,0 ); +} + +/* Put SDS_MISC back to the target mode. The lane stays parked (mode field +* DISABLE) until this succeeds, so retry a few times before giving up until +* the next run. +*/ +static int rtl8365mb_sds_relatch_restore (struct rtl8365mb *mb) +{ +struct realtek_priv *priv = mb->priv; +int ret =0 ; +int i; + +for (i =0 ; i <RTL8365MB_D_SDS_RESTORE_TRIES ; i++) { + ret =regmap_update_bits (priv->map,RTL8365MB_SDS_MISC_REG , +RTL8365MB_D_SDS_MISC_CFG_MASK , +READ_ONCE (mb->sds_misc_target_val)); +if (!ret) +return 0 ; +if (i <RTL8365MB_D_SDS_RESTORE_TRIES -1 ) +usleep_range (1000 ,2000 ); + } + +dev_err_ratelimited (priv->dev,"failed to restore SDS_MISC: %pe\n" , +ERR_PTR (ret)); +return ret; +} + static int rtl8365mb_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode, phy_interface_t interface, const unsigned long *advertising,
@@ -1533,6 +1625,17 @@ static int rtl8365mb_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode, is_d =rtl8365mb_get_family (priv) ==RTL8365MB_FAMILY_D ; +guard (mutex)(&mb->sds_cfg_lock); + +/* Cancel any in-flight re-latch edge before touching SDS_MISC: the +* work parks SDS_MISC and restores the target value after a sleep, so +* it could otherwise write a stale target over the new configuration. +*/ +if (is_d) { +WRITE_ONCE (mb->sds_relatch_armed, false); +cancel_delayed_work_sync (&mb->sds_relatch); + } +/* Select the appropriate tuning table and SDS mode */ if (interface ==PHY_INTERFACE_MODE_2500BASEX ) {if (is_d) {
@@ -1622,7 +1725,9 @@ static int rtl8365mb_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode,if (ret)return ret; -if (!is_d) { +if (is_d) { +WRITE_ONCE (mb->sds_misc_target_val, misc_val); + }else { val = sds_mode <<RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_OFFSET (id); ret = regmap_update_bits(priv->map, RTL8365MB_DIGITAL_INTERFACE_SELECT_REG(id),
@@ -1670,8 +1775,192 @@ static int rtl8365mb_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode, val &= ~RTL8365MB_SDS_NWAY_EN_MASK ; val |=RTL8365MB_SDS_NWAY_RESTART_MASK ; -return rtl8365mb_sds_write (priv, sds_index, -RTL8365MB_SDS_REG_NWAY , val); + ret =rtl8365mb_sds_write (priv, sds_index, +RTL8365MB_SDS_REG_NWAY , val); +if (ret) +return ret; + +/* The re-latch edge has only been observed with HSGMII, so the work is +* only armed for 2500base-x. It starts once the conduit is up. +*/ +if (is_d) { +WRITE_ONCE (mb->sds_relatch_armed, + interface ==PHY_INTERFACE_MODE_2500BASEX ); +/* With the conduit already up no conduit_state_change() will +* follow, so start the episode here. +*/ +if (READ_ONCE (mb->sds_relatch_armed) && +READ_ONCE (mb->sds_conduit_up)) +rtl8365mb_sds_relatch_start (mb); + } + +return 0 ; +} + +static void rtl8365mb_conduit_state_change (struct dsa_switch *ds, +const struct net_device *conduit, +bool operational) +{ +struct dsa_port *cpu_dp = conduit->dsa_ptr; +struct realtek_priv *priv = ds->priv; +struct rtl8365mb *mb = priv->chip_data; + +if (rtl8365mb_get_family (priv) !=RTL8365MB_FAMILY_D ) +return ; + +/* The chip can have two CPU ports (SerDes on port 6, RGMII on +* port 7) and DSA reports every conduit. Only the one behind the +* SerDes matters here. +*/ +if (cpu_dp->index !=RTL8365MB_SDS_EXT_INTERFACE_PORT ) +return ; + +guard (mutex)(&mb->sds_cfg_lock); + +WRITE_ONCE (mb->sds_conduit_up, operational); +cancel_delayed_work_sync (&mb->sds_relatch); +if (operational &&READ_ONCE (mb->sds_relatch_armed)) +rtl8365mb_sds_relatch_start (mb); +} + +/* The family D receiver latches on a DISABLE -> mode edge in SDS_MISC +* rather than on the value, and only once the far-end MAC has brought up +* its half of the link. No local signal predicts that (bit 8 of the SDS +* link-status word does not change ahead of it), so the work cannot wait +* for it, only check afterwards whether an edge took. Nor does phylink +* call rtl8365mb_pcs_get_state() for a link without in-band signalling +* such as the fixed-link CPU trunk (mb->pcs.poll only arms phylink's own +* poll for in-band links), so this cannot rely on being polled at all. +* Instead, an episode starts when the conduit comes up (see +* rtl8365mb_conduit_state_change(), or pcs_config() if it is already up) +* and this work re-arms itself. +* +* An episode is capped at RTL8365MB_D_SDS_RELATCH_MAX_TRIES edges, spaced +* RTL8365MB_D_SDS_RELATCH_INTERVAL apart, so that a far end which never +* comes up costs a bounded burst of 20 ms parks. The run after the last +* edge only checks whether it took and reports failure; from then on one +* edge is driven per RTL8365MB_D_SDS_HEALTHCHECK_INTERVAL, so a far end +* that comes up late is recovered without a reconfiguration. Once the +* receiver has latched the work just polls the link at the same slow +* interval; finding it down then starts a new episode, e.g. after the far +* end reset its PLL without a reconfiguration. +* +* sds_relatch_count is the number of the next attempt of the episode: 0 +* while latched, 1..MAX_TRIES in budget, MAX_TRIES + 1 for the run that +* only reports, and above that once out of budget. +*/ +static void rtl8365mb_sds_relatch_work (struct work_struct *work) +{ +struct rtl8365mb *mb =container_of (to_delayed_work (work), + struct rtl8365mb, sds_relatch); +struct realtek_priv *priv = mb->priv; +u32 park = (READ_ONCE (mb->sds_misc_target_val) & + ~RTL8365MB_D_SDS_MISC_MODE_FIELD_MASK ) | +RTL8365MB_D_PORT_SDS_MODE_DISABLE ; +unsigned long delay =RTL8365MB_D_SDS_RELATCH_INTERVAL ; +unsigned int attempts; +u16 status; +u32 misc; +int ret; + +/* An earlier run may have failed to restore the target mode, which +* leaves the lane parked. The mode field in SDS_MISC says so: put it +* back before anything else. +*/ + ret =regmap_read (priv->map,RTL8365MB_SDS_MISC_REG , &misc); +if (ret) { +dev_err_ratelimited (priv->dev, +"failed to read SDS_MISC: %pe\n" , +ERR_PTR (ret)); + goto rearm; + } +if ((misc &RTL8365MB_D_SDS_MISC_MODE_FIELD_MASK ) == +RTL8365MB_D_PORT_SDS_MODE_DISABLE ) { +rtl8365mb_sds_relatch_restore (mb); + goto rearm; + } + +/* The condition that queued this work may already be stale by the +* time it runs (e.g. an earlier edge from a prior attempt just +* latched). Parking an already-live link would drop it for no +* reason. +*/ + ret =rtl8365mb_sds_read (priv,RTL8365MB_D_SDS_EXT0_INDEX , +RTL8365MB_SDS_REG_LINK_STATUS , &status); +if (ret) { +dev_err_ratelimited (priv->dev, +"failed to read SerDes link status: %pe\n" , +ERR_PTR (ret)); + goto rearm; + } +if (status &RTL8365MB_SDS_LINK_STATUS_LINK_MASK ) { +/* Latched: end the episode, keep watching for a later loss. */ +WRITE_ONCE (mb->sds_relatch_count,0 ); + delay =RTL8365MB_D_SDS_HEALTHCHECK_INTERVAL ; + goto rearm; + } + + attempts =READ_ONCE (mb->sds_relatch_count); +if (!attempts) { +dev_warn (priv->dev, +"SerDes link lost outside a reconfiguration; re-latching\n" ); + attempts =1 ; + }else if (attempts ==RTL8365MB_D_SDS_RELATCH_MAX_TRIES +1 ) { +/* This run only checked whether the last in-budget edge +* took. The first out-of-budget edge comes one healthcheck +* interval from now, not on this pass. +*/ +WRITE_ONCE (mb->sds_relatch_count, attempts +1 ); +dev_warn (priv->dev, +"SerDes did not latch after %u re-latch attempts; still retrying every %d s\n" , +RTL8365MB_D_SDS_RELATCH_MAX_TRIES , +RTL8365MB_D_SDS_HEALTHCHECK_INTERVAL /HZ ); + delay =RTL8365MB_D_SDS_HEALTHCHECK_INTERVAL ; + goto rearm; + } + +if (attempts <=RTL8365MB_D_SDS_RELATCH_MAX_TRIES ) +WRITE_ONCE (mb->sds_relatch_count, attempts +1 ); +else +/* Past the fast-retry budget. The receiver latches only on a +* DISABLE -> mode edge and nothing re-runs pcs_config() for a +* link without in-band signalling, so keep driving one edge +* per interval. +*/ + delay =RTL8365MB_D_SDS_HEALTHCHECK_INTERVAL ; + + ret =regmap_update_bits (priv->map,RTL8365MB_SDS_MISC_REG , +RTL8365MB_D_SDS_MISC_CFG_MASK , park); +if (ret) { +dev_err_ratelimited (priv->dev, +"failed to park SDS_MISC: %pe\n" , +ERR_PTR (ret)); + goto rearm; + } + +usleep_range (20000 ,21000 ); + +if (rtl8365mb_sds_relatch_restore (mb)) { +/* The SerDes is left parked: come back soon rather than +* at the (possibly 10 s) pace chosen above. +*/ + delay =RTL8365MB_D_SDS_RELATCH_INTERVAL ; + goto rearm; + } + +dev_dbg (priv->dev,"SerDes re-latch edge driven (attempt %u)\n" , + attempts); + +/* This edge may not have taken either; the next run checks. */ +rearm: +schedule_delayed_work (&mb->sds_relatch, delay); +} + +static void rtl8365mb_sds_relatch_disable (void *data) +{ +struct rtl8365mb *mb = data; + +disable_delayed_work_sync (&mb->sds_relatch); }static bool rtl8365mb_interface_is_serdes (phy_interface_t interface)
@@ -1825,11 +2114,25 @@ static void rtl8365mb_pcs_link_up(struct phylink_pcs *pcs, } } +static void rtl8365mb_pcs_disable (struct phylink_pcs *pcs) +{ +struct rtl8365mb *mb =pcs_to_rtl8365mb (pcs); + +if (rtl8365mb_get_family (mb->priv) !=RTL8365MB_FAMILY_D ) +return ; + +guard (mutex)(&mb->sds_cfg_lock); + +WRITE_ONCE (mb->sds_relatch_armed, false); +cancel_delayed_work_sync (&mb->sds_relatch); +} +static const struct phylink_pcs_ops rtl8365mb_pcs_ops = { .pcs_inband_caps = rtl8365mb_pcs_inband_caps, .pcs_config = rtl8365mb_pcs_config, .pcs_get_state = rtl8365mb_pcs_get_state, .pcs_link_up = rtl8365mb_pcs_link_up, + .pcs_disable = rtl8365mb_pcs_disable, }; static int rtl8365mb_ext_config_forcemode(struct realtek_priv *priv, int port,
@@ -3563,6 +3866,14 @@ out_error:static void rtl8365mb_teardown (struct dsa_switch *ds) {struct realtek_priv *priv = ds->priv; +struct rtl8365mb *mb = priv->chip_data; + +if (rtl8365mb_get_family (priv) ==RTL8365MB_FAMILY_D ) { +guard (mutex)(&mb->sds_cfg_lock); + +WRITE_ONCE (mb->sds_relatch_armed, false); +cancel_delayed_work_sync (&mb->sds_relatch); + }rtl8365mb_stats_teardown (priv);rtl8365mb_irq_teardown (priv);
@@ -3595,6 +3906,23 @@ static int rtl8365mb_get_chip_id_and_ver(struct regmap *map, u32 *id, u32 *ver)return 0 ; } +static int rtl8365mb_sds_reboot_notify (struct notifier_block *nb, +unsigned long action,void *data) +{ + struct rtl8365mb *mb = container_of(nb, struct rtl8365mb, + sds_reboot_nb); + +/* Runs before device_shutdown() on reboot, halt, power off and kexec. +* disable_delayed_work_sync() waits for a running pass and keeps +* pcs_config() from queueing the work again, so the bus is not +* touched once it is being shut down. If the last restore failed the +* lane stays parked until the next pcs_config(). +*/ +disable_delayed_work_sync (&mb->sds_relatch); + +return NOTIFY_DONE ; +} +static int rtl8365mb_detect (struct realtek_priv *priv) {struct rtl8365mb *mb = priv->chip_data;
@@ -3630,6 +3958,34 @@ static int rtl8365mb_detect(struct realtek_priv *priv) priv->num_ports =RTL8365MB_MAX_NUM_PORTS ; mb->priv = priv; + + ret =devm_mutex_init (priv->dev, &mb->sds_lock); +if (ret) +return ret; + + ret =devm_mutex_init (priv->dev, &mb->sds_cfg_lock); +if (ret) +return ret; + +if (rtl8365mb_get_family (priv) ==RTL8365MB_FAMILY_D ) { +/* Registered after sds_lock, so on release the work is +* disabled before the mutex is destroyed. +*/ +INIT_DELAYED_WORK (&mb->sds_relatch, + rtl8365mb_sds_relatch_work); + ret =devm_add_action_or_reset (priv->dev, + rtl8365mb_sds_relatch_disable, + mb); +if (ret) +return ret; + + mb->sds_reboot_nb.notifier_call = rtl8365mb_sds_reboot_notify; + ret =devm_register_reboot_notifier (priv->dev, + &mb->sds_reboot_nb); +if (ret) +return ret; + } + mb->cpu.trap_port =RTL8365MB_MAX_NUM_PORTS ; mb->cpu.insert =RTL8365MB_CPU_INSERT_TO_ALL ; mb->cpu.position =RTL8365MB_CPU_POS_AFTER_SA ;
@@ -3714,6 +4070,7 @@ static const struct dsa_switch_ops rtl8365mb_switch_ops = { .port_vlan_add = rtl8365mb_port_vlan_add, .port_vlan_del = rtl8365mb_port_vlan_del, .port_vlan_filtering = rtl8365mb_port_vlan_filtering, + .conduit_state_change = rtl8365mb_conduit_state_change, .get_strings = rtl8365mb_get_strings, .get_ethtool_stats = rtl8365mb_get_ethtool_stats, .get_sset_count = rtl8365mb_get_sset_count,
Signature · 1 line
2.53.0
PATCH v7 9/10 net: dsa: realtek: rtl8365mb: make L2/LUT access work on family D
In reply to Mieczyslaw NalewajThe L2 lookup table on family D switches (e.g. RTL8367S-VB) differs from family C in ways that make the current FDB/MDB code misbehave:
- An L2 entry is 5 words instead of 6, with a different field layout in words 3 and 4 (port, age, static and multicast member bits).
- There is no EFID and no per-bridge FDB isolation. The register at 0x0A32, used as the per-port EFID register on family C, is the LUT aging timer on family D, so writing an EFID there corrupts it.
- In the table access interface, the SPA field is 3 bits wide and the address register is 12 bits wide, with no address extension bit.
- Only ports 0..7 are present in the LUT and there is no FLUSH_PORT_EXT register.
Teach the table and L2 code about these differences, selecting the layout at runtime with rtl8365mb_get_family(). Family C behaviour 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)serialisers behind *_any() wrappers, pass the proper entry size to the table layer, reject ports above 7, report SVL (FID) entries with VID 0. Use age 6 for static unicast entries as the vendor code does, and look an entry up before deleting it so that a missing entry is not allocated by the delete.
- rtl8365mb_main: make port_set_efid() a no-op on family D, add a LUT init step that clears IPMC_HASH and BCAM_DISABLE and programs the aging timer, and do not advertise fdb_isolation or max_num_bridges. Traffic between bridges is then isolated by the port isolation masks only.
Register layouts were taken from the family D register description; the code itself is an independent implementation.
No chip uses family D before the last patch of the series, so this code is unreachable until then.
--- drivers/net/dsa/realtek/rtl8365mb_l2.c | 216 ++++++++++++++++++++-- drivers/net/dsa/realtek/rtl8365mb_main.c | 46 ++++- drivers/net/dsa/realtek/rtl8365mb_table.c | 46 ++++- 3 files changed, 276 insertions(+), 32 deletions(-)
drivers/net/dsa/realtek/rtl8365mb_l2.c +197 -19
@@ -8,9 +8,12 @@#include "rtl8365mb_l2.h" #include "rtl8365mb_table.h" +#include "rtl8365mb.h" #include <linux/regmap.h> #define RTL8365MB_L2_ENTRY_SIZE 6 +#define RTL8365MB_D_L2_ENTRY_SIZE 5 +#define RTL8365MB_D_L2_MAX_PORT 7#define RTL8365MB_L2_UC_D0_MAC5_MSK GENMASK(7, 0)#define RTL8365MB_L2_UC_D0_MAC4_MSK GENMASK(15, 8)
@@ -58,6 +61,21 @@#define RTL8365MB_L2_MC_D5_MBR_HI2_MSK GENMASK(7, 7)#define RTL8365MB_L2_MC_MBR_HI2_MSK GENMASK(10, 10) +/* Family D unicast (auto-learn / static) entry */ +#define RTL8365MB_D_L2_UC_D3_VID_MSK GENMASK(11, 0) +#define RTL8365MB_D_L2_UC_D3_IVL_MSK BIT(13) +#define RTL8365MB_D_L2_UC_D3_PORT_LO_MSK GENMASK(15, 14) +#define RTL8365MB_D_L2_UC_D4_PORT_HI_MSK BIT(0) +#define RTL8365MB_D_L2_UC_D4_AGE_MSK GENMASK(3, 1) +#define RTL8365MB_D_L2_UC_D4_STATIC_MSK BIT(6) + +/* Family D multicast entry */ +#define RTL8365MB_D_L2_MC_D3_VID_MSK GENMASK(11, 0) +#define RTL8365MB_D_L2_MC_D3_IVL_MSK BIT(13) +#define RTL8365MB_D_L2_MC_D3_MBR_LO_MSK GENMASK(15, 14) +#define RTL8365MB_D_L2_MC_D4_MBR_HI_MSK GENMASK(5, 0) +#define RTL8365MB_D_L2_MC_D4_STATIC_MSK BIT(6) +/* Port flush command registers - writing a 1 to the port's MASK bit will * initiate the flush procedure. Completion is signalled when the corresponding * BUSY bit is 0.
@@ -258,6 +276,130 @@ static void rtl8365mb_l2_mc_to_data(const struct rtl8365mb_l2_mc *mc, u16 *data) data[5 ] |=FIELD_PREP (RTL8365MB_L2_MC_D5_MBR_HI2_MSK , val); } +static bool rtl8365mb_l2_is_d (struct realtek_priv *priv) +{ +return rtl8365mb_get_family (priv) ==RTL8365MB_FAMILY_D ; +} + +static size_t rtl8365mb_l2_entry_size (struct realtek_priv *priv) +{ +return rtl8365mb_l2_is_d (priv) ?RTL8365MB_D_L2_ENTRY_SIZE : +RTL8365MB_L2_ENTRY_SIZE ; +} + +static void rtl8365mb_l2_mac_to_data (const u8 *m,u16 *data) +{ + data[0 ] = (m[4 ] <<8 ) | m[5 ]; + data[1 ] = (m[2 ] <<8 ) | m[3 ]; + data[2 ] = (m[0 ] <<8 ) | m[1 ]; +} + +static void rtl8365mb_l2_data_to_mac (const u16 *data,u8 *m) +{ + m[5 ] = data[0 ] &0xff ; + m[4 ] = data[0 ] >>8 ; + m[3 ] = data[1 ] &0xff ; + m[2 ] = data[1 ] >>8 ; + m[1 ] = data[2 ] &0xff ; + m[0 ] = data[2 ] >>8 ; +} + +static void rtl8365mb_d_l2_data_to_uc (const u16 *data, +struct rtl8365mb_l2_uc *uc) +{ +rtl8365mb_l2_data_to_mac (data, uc->key.mac_addr); + uc->key.vid =FIELD_GET (RTL8365MB_D_L2_UC_D3_VID_MSK , data[3 ]); + uc->key.ivl =FIELD_GET (RTL8365MB_D_L2_UC_D3_IVL_MSK , data[3 ]); + uc->key.fid =0 ; + uc->key.efid =0 ; + uc->port =FIELD_GET (RTL8365MB_D_L2_UC_D3_PORT_LO_MSK , data[3 ]) | + (FIELD_GET (RTL8365MB_D_L2_UC_D4_PORT_HI_MSK , data[4 ]) <<2 ); + uc->age =FIELD_GET (RTL8365MB_D_L2_UC_D4_AGE_MSK , data[4 ]); + uc->is_static =FIELD_GET (RTL8365MB_D_L2_UC_D4_STATIC_MSK , data[4 ]); +} + +static void rtl8365mb_d_l2_uc_to_data (const struct rtl8365mb_l2_uc *uc, +u16 *data) +{ +memset (data,0 ,RTL8365MB_L2_ENTRY_SIZE *2 ); +rtl8365mb_l2_mac_to_data (uc->key.mac_addr, data); + data[3 ] =FIELD_PREP (RTL8365MB_D_L2_UC_D3_VID_MSK , uc->key.vid) | +FIELD_PREP (RTL8365MB_D_L2_UC_D3_IVL_MSK , uc->key.ivl) | +FIELD_PREP (RTL8365MB_D_L2_UC_D3_PORT_LO_MSK , uc->port &0x3 ); + data[4 ] =FIELD_PREP (RTL8365MB_D_L2_UC_D4_PORT_HI_MSK , + (uc->port >>2 ) &0x1 ) | +FIELD_PREP (RTL8365MB_D_L2_UC_D4_AGE_MSK , uc->age) | +FIELD_PREP (RTL8365MB_D_L2_UC_D4_STATIC_MSK , uc->is_static); +} + +static void rtl8365mb_d_l2_data_to_mc (const u16 *data, +struct rtl8365mb_l2_mc *mc) +{ +rtl8365mb_l2_data_to_mac (data, mc->key.mac_addr); + mc->key.vid =FIELD_GET (RTL8365MB_D_L2_MC_D3_VID_MSK , data[3 ]); + mc->key.ivl =FIELD_GET (RTL8365MB_D_L2_MC_D3_IVL_MSK , data[3 ]); + mc->member =FIELD_GET (RTL8365MB_D_L2_MC_D3_MBR_LO_MSK , data[3 ]) | + (FIELD_GET (RTL8365MB_D_L2_MC_D4_MBR_HI_MSK , data[4 ]) <<2 ); + mc->is_static =FIELD_GET (RTL8365MB_D_L2_MC_D4_STATIC_MSK , data[4 ]); + mc->igmpidx =0 ; + mc->priority =0 ; + mc->fwd_pri =0 ; + mc->igmp_asic =0 ; +} + +static void rtl8365mb_d_l2_mc_to_data (const struct rtl8365mb_l2_mc *mc, +u16 *data) +{ +memset (data,0 ,RTL8365MB_L2_ENTRY_SIZE *2 ); +rtl8365mb_l2_mac_to_data (mc->key.mac_addr, data); + data[3 ] =FIELD_PREP (RTL8365MB_D_L2_MC_D3_VID_MSK , mc->key.vid) | +FIELD_PREP (RTL8365MB_D_L2_MC_D3_IVL_MSK , mc->key.ivl) | +FIELD_PREP (RTL8365MB_D_L2_MC_D3_MBR_LO_MSK , mc->member &0x3 ); + data[4 ] =FIELD_PREP (RTL8365MB_D_L2_MC_D4_MBR_HI_MSK , + (mc->member >>2 ) &0x3f ) | +FIELD_PREP (RTL8365MB_D_L2_MC_D4_STATIC_MSK , mc->is_static); +} + +static void rtl8365mb_l2_data_to_uc_any (struct realtek_priv *priv, +const u16 *data, +struct rtl8365mb_l2_uc *uc) +{ +if (rtl8365mb_l2_is_d (priv)) +rtl8365mb_d_l2_data_to_uc (data, uc); +else +rtl8365mb_l2_data_to_uc (data, uc); +} + +static void rtl8365mb_l2_uc_to_data_any (struct realtek_priv *priv, +const struct rtl8365mb_l2_uc *uc, +u16 *data) +{ +if (rtl8365mb_l2_is_d (priv)) +rtl8365mb_d_l2_uc_to_data (uc, data); +else +rtl8365mb_l2_uc_to_data (uc, data); +} + +static void rtl8365mb_l2_data_to_mc_any (struct realtek_priv *priv, +const u16 *data, +struct rtl8365mb_l2_mc *mc) +{ +if (rtl8365mb_l2_is_d (priv)) +rtl8365mb_d_l2_data_to_mc (data, mc); +else +rtl8365mb_l2_data_to_mc (data, mc); +} + +static void rtl8365mb_l2_mc_to_data_any (struct realtek_priv *priv, +const struct rtl8365mb_l2_mc *mc, +u16 *data) +{ +if (rtl8365mb_l2_is_d (priv)) +rtl8365mb_d_l2_mc_to_data (mc, data); +else +rtl8365mb_l2_mc_to_data (mc, data); +} +/* * rtl8365mb_l2_get_next_uc() - get the next Unicast L2 entry * @priv: realtek_priv pointer
@@ -286,17 +428,23 @@ int rtl8365mb_l2_get_next_uc(struct realtek_priv *priv, u16 *addr, int port,struct rtl8365mb_l2_uc uc;int ret; +if (rtl8365mb_l2_is_d (priv) && port >RTL8365MB_D_L2_MAX_PORT ) +return -EINVAL ; + ret =rtl8365mb_table_query (priv,RTL8365MB_TABLE_L2 ,RTL8365MB_TABLE_OP_READ , addr,RTL8365MB_TABLE_L2_METHOD_ADDR_NEXT_UC_PORT , - port, data,RTL8365MB_L2_ENTRY_SIZE ); + port, data,rtl8365mb_l2_entry_size (priv));if (ret)return ret; -rtl8365mb_l2_data_to_uc (data, &uc); +rtl8365mb_l2_data_to_uc_any (priv, data, &uc);ether_addr_copy (entry->mac_addr, uc.key.mac_addr); - entry->vid = uc.key.vid; +/* D has one shared VID/FID field; report SVL (FID) entries with +* vid 0 as they have no VLAN to be shown under +*/ + entry->vid = (rtl8365mb_l2_is_d (priv) && !uc.key.ivl) ?0 : uc.key.vid; entry->is_static = uc.is_static;return 0 ;
@@ -311,6 +459,9 @@ int rtl8365mb_l2_add_uc(struct realtek_priv *priv, int port,u16 addr;int ret; +if (rtl8365mb_l2_is_d (priv) && port >RTL8365MB_D_L2_MAX_PORT ) +return -EINVAL ; +memcpy (uc.key.mac_addr, mac_addr,ETH_ALEN ); uc.key.efid = efid; uc.key.fid =0 ;
@@ -324,15 +475,18 @@ int rtl8365mb_l2_add_uc(struct realtek_priv *priv, int port,* OS's back. As a trade-off, these will show up as permanent to users. */ uc.is_static = true; -/* age greater than 0 adds/updates entries */ - uc.age =1 ; -rtl8365mb_l2_uc_to_data (&uc, data); +/* age greater than 0 adds/updates entries. D has no EFID, so efid is +* not serialised (bridges are isolated by the port isolation masks only). +* Vendor code writes age 6 for D. +*/ + uc.age =rtl8365mb_l2_is_d (priv) ?6 :1 ; +rtl8365mb_l2_uc_to_data_any (priv, &uc, data);/* add the new entry or update an existing one */ ret =rtl8365mb_table_query (priv,RTL8365MB_TABLE_L2 ,RTL8365MB_TABLE_OP_WRITE , &addr,0 ,0 , - data,RTL8365MB_L2_ENTRY_SIZE ); + data,rtl8365mb_l2_entry_size (priv));/* Assume the missing new entry as the table is full */ if (ret == -ENOENT )
@@ -358,7 +512,25 @@ int rtl8365mb_l2_del_uc(struct realtek_priv *priv, int port, uc.key.vid = vid;/* age 0 deletes the entry */ uc.age =0 ; -rtl8365mb_l2_uc_to_data (&uc, data); +rtl8365mb_l2_uc_to_data_any (priv, &uc, data); + +if (rtl8365mb_l2_is_d (priv)) { +/* Do not blind-write: look the entry up first (as the vendor +* code does) so a missing entry is not (re)allocated. +*/ + ret =rtl8365mb_table_query (priv,RTL8365MB_TABLE_L2 , +RTL8365MB_TABLE_OP_READ , &addr, +RTL8365MB_TABLE_L2_METHOD_MAC ,0 , + data, +rtl8365mb_l2_entry_size (priv)); +if (ret == -ENOENT ) +return 0 ; +if (ret) +return ret; + +/* rebuild the write payload: the read overwrote data[] */ +rtl8365mb_l2_uc_to_data_any (priv, &uc, data); + }/* it looks like the switch will always add/update the entry, * even when age is 0 or uc.key did not match an existing entry,
@@ -368,7 +540,7 @@ int rtl8365mb_l2_del_uc(struct realtek_priv *priv, int port, ret =rtl8365mb_table_query (priv,RTL8365MB_TABLE_L2 ,RTL8365MB_TABLE_OP_WRITE , &addr,0 ,0 , - data,RTL8365MB_L2_ENTRY_SIZE ); + data,rtl8365mb_l2_entry_size (priv));if (ret == -ENOENT ) { dev_dbg(priv->dev, "%s: %pM vid=%d efid=%d missing\n",
@@ -388,6 +560,9 @@ int rtl8365mb_l2_flush(struct realtek_priv *priv, int port, u16 vid)u32 val, mask;int ret; +if (rtl8365mb_l2_is_d (priv) && port >RTL8365MB_D_L2_MAX_PORT ) +return -EINVAL ; +mutex_lock (&priv->map_lock);/* Configure flushing mode; only flush dynamic entries */
@@ -455,6 +630,9 @@ int rtl8365mb_l2_add_mc(struct realtek_priv *priv, int port,u16 addr;int ret; +if (rtl8365mb_l2_is_d (priv) && port >RTL8365MB_D_L2_MAX_PORT ) +return -EINVAL ; +memcpy (mc.key.mac_addr, mac_addr,ETH_ALEN ); mc.key.vid = vid; mc.key.ivl = true;
@@ -463,16 +641,16 @@ int rtl8365mb_l2_add_mc(struct realtek_priv *priv, int port,*/ mc.member |=BIT (port); mc.is_static =1 ; -rtl8365mb_l2_mc_to_data (&mc, data); +rtl8365mb_l2_mc_to_data_any (priv, &mc, data);/* First look for an existing entry (to get existing port members) */ ret =rtl8365mb_table_query (priv,RTL8365MB_TABLE_L2 ,RTL8365MB_TABLE_OP_READ , &addr,RTL8365MB_TABLE_L2_METHOD_MAC ,0 , - data,RTL8365MB_L2_ENTRY_SIZE ); + data,rtl8365mb_l2_entry_size (priv));if (!ret) {/* There is already an entry... */ -rtl8365mb_l2_data_to_mc (data, &mc); +rtl8365mb_l2_data_to_mc_any (priv, data, &mc); dev_dbg(priv->dev, "%s: found %pM addr=%d member=0x%x igmpidx=0x%x %s\n", __func__, mac_addr, addr, mc.member, mc.igmpidx,
@@ -487,7 +665,7 @@ int rtl8365mb_l2_add_mc(struct realtek_priv *priv, int port, mc.is_static =1 ; } -rtl8365mb_l2_mc_to_data (&mc, data); +rtl8365mb_l2_mc_to_data_any (priv, &mc, data); }else if (ret == -ENOENT ) {/* New entry, no need to update data again as it already * includes the member.
@@ -508,7 +686,7 @@ int rtl8365mb_l2_add_mc(struct realtek_priv *priv, int port, ret =rtl8365mb_table_query (priv,RTL8365MB_TABLE_L2 ,RTL8365MB_TABLE_OP_WRITE , &addr,0 ,0 , - data,RTL8365MB_L2_ENTRY_SIZE ); + data,rtl8365mb_l2_entry_size (priv));/* Assume the missing new entry as the table is full */ if (ret == -ENOENT )
@@ -529,13 +707,13 @@ int rtl8365mb_l2_del_mc(struct realtek_priv *priv, int port,memcpy (mc.key.mac_addr, mac_addr,ETH_ALEN ); mc.key.vid = vid; mc.key.ivl = true; -rtl8365mb_l2_mc_to_data (&mc, data); +rtl8365mb_l2_mc_to_data_any (priv, &mc, data);/* First look for an existing entry (to get existing port members) */ ret =rtl8365mb_table_query (priv,RTL8365MB_TABLE_L2 ,RTL8365MB_TABLE_OP_READ , &addr,RTL8365MB_TABLE_L2_METHOD_MAC ,0 , - data,RTL8365MB_L2_ENTRY_SIZE ); + data,rtl8365mb_l2_entry_size (priv));if (ret == -ENOENT ) {dev_dbg (priv->dev,"%s: %pM vid=%d missing\n" , __func__, mac_addr, vid);
@@ -547,7 +725,7 @@ int rtl8365mb_l2_del_mc(struct realtek_priv *priv, int port,/* Return on any other error */ return ret; -rtl8365mb_l2_data_to_mc (data, &mc); +rtl8365mb_l2_data_to_mc_any (priv, data, &mc); dev_dbg(priv->dev, "%s: found %pM addr=%d member=0x%x igmpidx=0x%x %s\n", __func__, mac_addr, addr, mc.member, mc.igmpidx,
@@ -565,12 +743,12 @@ int rtl8365mb_l2_del_mc(struct realtek_priv *priv, int port, mc.fwd_pri =0 ; mc.igmp_asic =0 ; } -rtl8365mb_l2_mc_to_data (&mc, data); +rtl8365mb_l2_mc_to_data_any (priv, &mc, data);/* update the existing entry. */ ret =rtl8365mb_table_query (priv,RTL8365MB_TABLE_L2 ,RTL8365MB_TABLE_OP_WRITE , &addr,0 ,0 , - data,RTL8365MB_L2_ENTRY_SIZE ); + data,rtl8365mb_l2_entry_size (priv));return ret; }
drivers/net/dsa/realtek/rtl8365mb_main.c +43 -3
76 lines not on this page · raw message
drivers/net/dsa/realtek/rtl8365mb_table.c +36 -10
92 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v7 10/10 net: dsa: realtek: rtl8365mb: add support for RTL8367S-VB
In reply to Mieczyslaw NalewajAdd 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.
The chip has 8 ports, not 11. Cap priv->num_ports at RTL8365MB_D_MAX_NUM_PORTS for family D. This is a functional change: it sets ds->num_ports, the IRQ domain size and the bound of every loop over priv->num_ports.
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 to an IPQ5018) with bridge VLAN filtering and per-port PVIDs. SGMII has also been seen working, but I no longer have the exact link partner and speed it was tested with, so treat it as lightly tested. RGMII mode has not yet been tested.
--- drivers/net/dsa/realtek/Kconfig | 3 ++- drivers/net/dsa/realtek/rtl8365mb_main.c | 32 +++++++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-)
drivers/net/dsa/realtek/Kconfig +2 -1
@@ -34,7 +34,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_main.c +28 -4
@@ -89,6 +89,12 @@* things will work out-of-the-box for other chips, and a careful review of the * vendor driver may be needed to expand support. The RTL8365MB-VC seems to be * one of the simpler chips. +* +* The RTL8367S-VB (chip ID 0x6642) is not part of the family listed above. It +* belongs to a newer generation, which this driver calls family D. Its +* registers differ in the VLAN table, the external interface speed and RGMII +* configuration and the SerDes, so the code paths specific to it are selected +* with rtl8365mb_get_family(). */ #include <linux/bitfield.h>
@@ -120,9 +126,10 @@#define RTL8365MB_NUM_PHYREGS 32#define RTL8365MB_PHYREGMAX (RTL8365MB_NUM_PHYREGS - 1)#define RTL8365MB_MAX_NUM_PORTS 11 -/* Valid for the whole family except RTL8370B, which has 4160 entries. -* RTL8370B is mentioned in vendor code but it might not even belong -* to the same RTL8367C family. +#define RTL8365MB_D_MAX_NUM_PORTS 8 +/* Valid for the whole RTL8367C family (and for family D, RTL8367S-VB) +* except RTL8370B, which has 4160 entries. RTL8370B is mentioned in +* vendor code but it might not even belong to the same RTL8367C family. */ #define RTL8365MB_LEARN_LIMIT_MAX 2112#define RTL8365MB_MAX_NUM_EXTINTS 3
@@ -895,6 +902,19 @@ static const struct rtl8365mb_chip_info rtl8365mb_chip_infos[] = { .jam_table = rtl8365mb_init_jam_8365mb_vc, .jam_size = ARRAY_SIZE(rtl8365mb_init_jam_8365mb_vc), }, + { + .name = "RTL8367S-VB", + .chip_id = 0x6642, + .chip_ver = 0x0010, + .family = RTL8365MB_FAMILY_D, + .extints = { + { 6, 0, PHY_INTF(SGMII) | PHY_INTF(HSGMII) }, + { 7, 1, PHY_INTF(MII) | PHY_INTF(TMII) | + PHY_INTF(RMII) | PHY_INTF(RGMII) }, + }, + .jam_table = rtl8365mb_init_jam_8365mb_vc, + .jam_size = ARRAY_SIZE(rtl8365mb_init_jam_8365mb_vc), + }, }; enum rtl8365mb_stp_state {
@@ -3996,7 +4016,11 @@ static int rtl8365mb_detect(struct realtek_priv *priv)dev_info (priv->dev,"found an %s switch\n" , mb->chip_info->name); - priv->num_ports =RTL8365MB_MAX_NUM_PORTS ; +if (rtl8365mb_get_family (priv) ==RTL8365MB_FAMILY_D ) + priv->num_ports =RTL8365MB_D_MAX_NUM_PORTS ; +else + priv->num_ports =RTL8365MB_MAX_NUM_PORTS ; + mb->priv = priv; ret =devm_mutex_init (priv->dev, &mb->sds_lock);
Signature · 1 line
2.53.0
Alvin Šipraga
reviewerRe: [PATCH net-next v7 09/10] net: dsa: realtek: rtl8365mb: make L2/LUT access work on family D
In reply to Mieczyslaw NalewajQuoted 86 lines · 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 at0x0A32, used as the per-port EFID register on family C, is the LUT aging timer on family D, so writing an EFID there corrupts it.
- In the table access interface, the SPA field is 3 bits wide and the address register is 12 bits wide, with no address extension bit.
- Only ports 0..7 are present in the LUT and there is noFLUSH_PORT_EXTregister.Teach the table and L2 code about these differences, selecting the layout at runtime with
rtl8365mb_get_family(). Family C behaviour 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)serialisers behind*_any()wrappers, pass the proper entry size to the table layer, reject ports above 7, report SVL (FID) entries with VID 0. Use age 6 for static unicast entries as the vendor code does, and look an entry up before deleting it so that a missing entry is not allocated by the delete.
-rtl8365mb_main: makeport_set_efid()a no-op on family D, add a LUT init step that clearsIPMC_HASHandBCAM_DISABLEand programs the aging timer, and do not advertisefdb_isolationormax_num_bridges. Traffic between bridges is then isolated by the port isolation masks only.Register layouts were taken from the family D register description; the code itself is an independent implementation.
No chip uses family D before the last patch of the series, so this code is unreachable until then.
Signed-off-by Mieczyslaw Nalewaj <[email protected]>--- drivers/net/dsa/realtek/rtl8365mb_l2.c | 216 ++++++++++++++++++++-- drivers/net/dsa/realtek/rtl8365mb_main.c | 46 ++++- drivers/net/dsa/realtek/rtl8365mb_table.c | 46 ++++- 3 files changed, 276 insertions(+), 32 deletions(-)drivers/net/dsa/realtek/rtl8365mb_l2.c +18
-0@@ -8,9 +8,12 @@#include "rtl8365mb_l2.h" #include "rtl8365mb_table.h" +#include "rtl8365mb.h" #include <linux/regmap.h> #define RTL8365MB_L2_ENTRY_SIZE 6 +#define RTL8365MB_D_L2_ENTRY_SIZE 5 +#define RTL8365MB_D_L2_MAX_PORT 7#define RTL8365MB_L2_UC_D0_MAC5_MSK GENMASK(7, 0)#define RTL8365MB_L2_UC_D0_MAC4_MSK GENMASK(15, 8)@@ -58,6 +61,21 @@#define RTL8365MB_L2_MC_D5_MBR_HI2_MSK GENMASK(7, 7)#define RTL8365MB_L2_MC_MBR_HI2_MSK GENMASK(10, 10) +/* Family D unicast (auto-learn / static) entry */ +#define RTL8365MB_D_L2_UC_D3_VID_MSK GENMASK(11, 0) +#define RTL8365MB_D_L2_UC_D3_IVL_MSK BIT(13) +#define RTL8365MB_D_L2_UC_D3_PORT_LO_MSK GENMASK(15, 14) +#define RTL8365MB_D_L2_UC_D4_PORT_HI_MSK BIT(0) +#define RTL8365MB_D_L2_UC_D4_AGE_MSK GENMASK(3, 1) +#define RTL8365MB_D_L2_UC_D4_STATIC_MSK BIT(6) + +/* Family D multicast entry */ +#define RTL8365MB_D_L2_MC_D3_VID_MSK GENMASK(11, 0) +#define RTL8365MB_D_L2_MC_D3_IVL_MSK BIT(13) +#define RTL8365MB_D_L2_MC_D3_MBR_LO_MSK GENMASK(15, 14) +#define RTL8365MB_D_L2_MC_D4_MBR_HI_MSK GENMASK(5, 0) +#define RTL8365MB_D_L2_MC_D4_STATIC_MSK BIT(6) +/* Port flush command registers - writing a 1 to the port's MASK bit will * initiate the flush procedure. Completion is signalled when the corresponding * BUSY bit is 0.
drivers/net/dsa/realtek/rtl8365mb_l2.c static void rtl8365mb_l2_mc_to_data(const struct rtl8365mb_l2_mc *mc, u16 *data) · line 282
Quoted 7 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c +4
-0@@ -258,6 +276,130 @@ static void rtl8365mb_l2_mc_to_data(const struct rtl8365mb_l2_mc *mc, u16 *data) data[5 ] |=FIELD_PREP (RTL8365MB_L2_MC_D5_MBR_HI2_MSK , val); } +static bool rtl8365mb_l2_is_d (struct realtek_priv *priv) +{ +return rtl8365mb_get_family (priv) ==RTL8365MB_FAMILY_D ; +}
Shouldn't this be a top-level function, like rtl8365mb_is_d()?
Quoted 13 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c +13
-0+ +static size_t rtl8365mb_l2_entry_size (struct realtek_priv *priv) +{ +return rtl8365mb_l2_is_d (priv) ?RTL8365MB_D_L2_ENTRY_SIZE : +RTL8365MB_L2_ENTRY_SIZE ; +} + +static void rtl8365mb_l2_mac_to_data (const u8 *m,u16 *data) +{ + data[0 ] = (m[4 ] <<8 ) | m[5 ]; + data[1 ] = (m[2 ] <<8 ) | m[3 ]; + data[2 ] = (m[0 ] <<8 ) | m[1 ]; +}
drivers/net/dsa/realtek/rtl8365mb_l2.c static void rtl8365mb_l2_mc_to_data(const struct rtl8365mb_l2_mc *mc, u16 *data) · line 305
Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c +10
-0+ +static void rtl8365mb_l2_data_to_mac (const u16 *data,u8 *m) +{ + m[5 ] = data[0 ] &0xff ; + m[4 ] = data[0 ] >>8 ; + m[3 ] = data[1 ] &0xff ; + m[2 ] = data[1 ] >>8 ; + m[1 ] = data[2 ] &0xff ; + m[0 ] = data[2 ] >>8 ; +}
From the diff it would seem that this is specific to the D family, since you only use it in those functions. But looking over my crappy original code for the C family, it's quite the same is it not? Can't you update the C family functions to use these helpers too?
Quoted 56 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c +56
-0+ +static void rtl8365mb_d_l2_data_to_uc (const u16 *data, +struct rtl8365mb_l2_uc *uc) +{ +rtl8365mb_l2_data_to_mac (data, uc->key.mac_addr); + uc->key.vid =FIELD_GET (RTL8365MB_D_L2_UC_D3_VID_MSK , data[3 ]); + uc->key.ivl =FIELD_GET (RTL8365MB_D_L2_UC_D3_IVL_MSK , data[3 ]); + uc->key.fid =0 ; + uc->key.efid =0 ; + uc->port =FIELD_GET (RTL8365MB_D_L2_UC_D3_PORT_LO_MSK , data[3 ]) | + (FIELD_GET (RTL8365MB_D_L2_UC_D4_PORT_HI_MSK , data[4 ]) <<2 ); + uc->age =FIELD_GET (RTL8365MB_D_L2_UC_D4_AGE_MSK , data[4 ]); + uc->is_static =FIELD_GET (RTL8365MB_D_L2_UC_D4_STATIC_MSK , data[4 ]); +} + +static void rtl8365mb_d_l2_uc_to_data (const struct rtl8365mb_l2_uc *uc, +u16 *data) +{ +memset (data,0 ,RTL8365MB_L2_ENTRY_SIZE *2 ); +rtl8365mb_l2_mac_to_data (uc->key.mac_addr, data); + data[3 ] =FIELD_PREP (RTL8365MB_D_L2_UC_D3_VID_MSK , uc->key.vid) | +FIELD_PREP (RTL8365MB_D_L2_UC_D3_IVL_MSK , uc->key.ivl) | +FIELD_PREP (RTL8365MB_D_L2_UC_D3_PORT_LO_MSK , uc->port &0x3 ); + data[4 ] =FIELD_PREP (RTL8365MB_D_L2_UC_D4_PORT_HI_MSK , + (uc->port >>2 ) &0x1 ) | +FIELD_PREP (RTL8365MB_D_L2_UC_D4_AGE_MSK , uc->age) | +FIELD_PREP (RTL8365MB_D_L2_UC_D4_STATIC_MSK , uc->is_static); +} + +static void rtl8365mb_d_l2_data_to_mc (const u16 *data, +struct rtl8365mb_l2_mc *mc) +{ +rtl8365mb_l2_data_to_mac (data, mc->key.mac_addr); + mc->key.vid =FIELD_GET (RTL8365MB_D_L2_MC_D3_VID_MSK , data[3 ]); + mc->key.ivl =FIELD_GET (RTL8365MB_D_L2_MC_D3_IVL_MSK , data[3 ]); + mc->member =FIELD_GET (RTL8365MB_D_L2_MC_D3_MBR_LO_MSK , data[3 ]) | + (FIELD_GET (RTL8365MB_D_L2_MC_D4_MBR_HI_MSK , data[4 ]) <<2 ); + mc->is_static =FIELD_GET (RTL8365MB_D_L2_MC_D4_STATIC_MSK , data[4 ]); + mc->igmpidx =0 ; + mc->priority =0 ; + mc->fwd_pri =0 ; + mc->igmp_asic =0 ; +} + +static void rtl8365mb_d_l2_mc_to_data (const struct rtl8365mb_l2_mc *mc, +u16 *data) +{ +memset (data,0 ,RTL8365MB_L2_ENTRY_SIZE *2 ); +rtl8365mb_l2_mac_to_data (mc->key.mac_addr, data); + data[3 ] =FIELD_PREP (RTL8365MB_D_L2_MC_D3_VID_MSK , mc->key.vid) | +FIELD_PREP (RTL8365MB_D_L2_MC_D3_IVL_MSK , mc->key.ivl) | +FIELD_PREP (RTL8365MB_D_L2_MC_D3_MBR_LO_MSK , mc->member &0x3 ); + data[4 ] =FIELD_PREP (RTL8365MB_D_L2_MC_D4_MBR_HI_MSK , + (mc->member >>2 ) &0x3f ) | +FIELD_PREP (RTL8365MB_D_L2_MC_D4_STATIC_MSK , mc->is_static); +}
drivers/net/dsa/realtek/rtl8365mb_l2.c static void rtl8365mb_l2_mc_to_data(const struct rtl8365mb_l2_mc *mc, u16 *data) · line 371
Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c +10
-0+ +static void rtl8365mb_l2_data_to_uc_any (struct realtek_priv *priv, +const u16 *data, +struct rtl8365mb_l2_uc *uc) +{ +if (rtl8365mb_l2_is_d (priv)) +rtl8365mb_d_l2_data_to_uc (data, uc); +else +rtl8365mb_l2_data_to_uc (data, uc); +}
Can't we have:
rtl8365mb_l2_data_to_uc() # same as before at all callsites
call into either:
rtl8365mb_c_l2_data_to_uc()rtl8365mb_d_l2_data_to_uc()
instead?
Right now it looks quite asymmetric. And the _any() is confusing when reading the code downstairs. (One wonders, what does "any" mean? Of course, it's obvious when you read this function.)
Even though family C is the originally supported family, I guess D is an equal citizen, so it's good to keep things in this driver symmetric.
Quoted 21 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c +21
-0+ +static void rtl8365mb_l2_uc_to_data_any (struct realtek_priv *priv, +const struct rtl8365mb_l2_uc *uc, +u16 *data) +{ +if (rtl8365mb_l2_is_d (priv)) +rtl8365mb_d_l2_uc_to_data (uc, data); +else +rtl8365mb_l2_uc_to_data (uc, data); +} + +static void rtl8365mb_l2_data_to_mc_any (struct realtek_priv *priv, +const u16 *data, +struct rtl8365mb_l2_mc *mc) +{ +if (rtl8365mb_l2_is_d (priv)) +rtl8365mb_d_l2_data_to_mc (data, mc); +else +rtl8365mb_l2_data_to_mc (data, mc); +} +
drivers/net/dsa/realtek/rtl8365mb_l2.c static void rtl8365mb_l2_mc_to_data(const struct rtl8365mb_l2_mc *mc, u16 *data) · line 402
Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c +10
-0+static void rtl8365mb_l2_mc_to_data_any (struct realtek_priv *priv, +const struct rtl8365mb_l2_mc *mc, +u16 *data) +{ +if (rtl8365mb_l2_is_d (priv)) +rtl8365mb_d_l2_mc_to_data (mc, data); +else +rtl8365mb_l2_mc_to_data (mc, data); +} +
The above comment applies to all these _any() functions.
Kind regards,
Alvin
Re: [PATCH net-next v7 09/10] net: dsa: realtek: rtl8365mb: make L2/LUT access work on family D
Quoted 4 lines · Mieczyslaw Nalewaj
drivers/net/dsa/realtek/rtl8365mb_l2.c +4
-0+static bool rtl8365mb_l2_is_d (struct realtek_priv *priv) +{ +return rtl8365mb_get_family (priv) ==RTL8365MB_FAMILY_D ; +}
Quoted 1 line · Alvin
Shouldn't this be a top-level function, like
rtl8365mb_is_d()?
Yes. For v8 I'll add a single rtl8365mb_is_d() static inline to rtl8365mb.h (in the patch that introduces the family infrastructure) and the L2, table and main code now use it. The l2-local helper will gone.
Quoted 2 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c +2
-0+static void rtl8365mb_l2_mac_to_data(const u8 *m, u16 *data) +static void rtl8365mb_l2_data_to_mac(const u16 *data, u8 *m)
[...]
Quoted 4 lines
From the diff it would seem that this is specific to the D family, since you only use it in those functions. But looking over my crappy original code for the C family, it's quite the same is it not? Can't you update the C family functions to use these helpers too?
Good catch, the packing is identical. For v8 I'll add a preparatory patch before this one that moves the two MAC helpers above the C serialisers and converts the C functions to use them. It is meant to be a no-op refactor, so it can be reviewed on its own.
Quoted 14 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c +9
-0+static void rtl8365mb_l2_data_to_uc_any (struct realtek_priv *priv, +const u16 *data, +struct rtl8365mb_l2_uc *uc) +{ +if (rtl8365mb_l2_is_d (priv)) +rtl8365mb_d_l2_data_to_uc (data, uc); +else +rtl8365mb_l2_data_to_uc (data, uc); +}Can't we have:
rtl8365mb_l2_data_to_uc()# same as before at all callsites
Quoted 8 lines
call into either:
rtl8365mb_c_l2_data_to_uc()rtl8365mb_d_l2_data_to_uc()instead?
[...]
The above comment applies to all these_any()functions.
Agreed. In v8 the existing C serialisers are renamed to rtl8365mb_c_l2_*() (in the same preparatory patch, so this patch stays purely additive), and rtl8365mb_l2_{data_to_uc,uc_to_data, data_to_mc,mc_to_data}() become the per-family dispatchers calling the c_ or d_ variant. The _any() wrappers are dropped. The dispatchers need to know the family, so the callsites only gain the priv argument.
Quoted 2 lines
Even though family C is the originally supported family, I guess D is an equal citizen, so it's good to keep things in this driver symmetric.
Agreed, D should be a peer of C rather than a special case bolted on.
Thanks for the review,
Mieczyslaw
Alvin Šipraga
reviewerHi Mieczyslaw,
First of all, apologies for such a late review! I hope you appreciate the feedback anyways.
Quoted 9 lines · Mieczyslaw Nalewaj
Add the RTL8367S-VB (chip ID
0x6642, version0x0010) 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.
Quoted 4 lines
The chip has 8 ports, not 11. Cap
priv->num_portsatRTL8365MB_D_MAX_NUM_PORTSfor family D. This is a functional change: it setsds->num_ports, the IRQ domain size and the bound of every loop overpriv->num_ports.
Something about this below...
Quoted 38 lines
The L2 learning limit is the same as on family C (2112 entries), as given by the Realtek rtl8367 common API (
rtl8367_commonV1.4.2), soRTL8365MB_LEARN_LIMIT_MAXneeds no per-family handling; only its comment is updated.Tested on a TP-Link Archer AX55 v1 (RTL8367S-VB, CPU port over HSGMII to an IPQ5018) with bridge VLAN filtering and per-port PVIDs. SGMII has also been seen working, but I no longer have the exact link partner and speed it was tested with, so treat it as lightly tested. RGMII mode has not yet been tested.
Signed-off-by Mieczyslaw Nalewaj <[email protected]>Reviewed-by Linus Walleij <[email protected]>--- drivers/net/dsa/realtek/Kconfig | 3 ++- drivers/net/dsa/realtek/rtl8365mb_main.c | 32 +++++++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-)drivers/net/dsa/realtek/Kconfig +2
-1@@ -34,7 +34,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_main.c +0
-0
drivers/net/dsa/realtek/rtl8365mb_main.c line 97
Quoted 9 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +6
-0@@ -89,6 +89,12 @@* things will work out-of-the-box for other chips, and a careful review of the * vendor driver may be needed to expand support. The RTL8365MB-VC seems to be * one of the simpler chips. +* +* The RTL8367S-VB (chip ID 0x6642) is not part of the family listed above. It +* belongs to a newer generation, which this driver calls family D. Its +* registers differ in the VLAN table, the external interface speed and RGMII +* configuration and the SerDes, so the code paths specific to it are selected +* with rtl8365mb_get_family().
More below, but I hope we can sort of avoid too much branching of this kind.
drivers/net/dsa/realtek/rtl8365mb_main.c line 129
Quoted 11 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +1
-3*/ #include <linux/bitfield.h> @@ -120,9 +126,10 @@#define RTL8365MB_NUM_PHYREGS 32#define RTL8365MB_PHYREGMAX (RTL8365MB_NUM_PHYREGS - 1)#define RTL8365MB_MAX_NUM_PORTS 11 -/* Valid for the whole family except RTL8370B, which has 4160 entries. -* RTL8370B is mentioned in vendor code but it might not even belong -* to the same RTL8367C family. +#define RTL8365MB_D_MAX_NUM_PORTS 8
This is OK, but in the same spirit as my comment to your other patch, I think we want to make the C and D families equal. So why not:
-#define RTL8365MB_MAX_NUM_PORTS 11
+#define RTL8365MB_C_MAX_NUM_PORTS 11
+#define RTL8365MB_D_MAX_NUM_PORTS 8
and add a num_ports member to struct rtl8365mb_chip_info. Then below:
[...]
drivers/net/dsa/realtek/rtl8365mb_main.c static int rtl8365mb_detect(struct realtek_priv *priv) · line 4023
Quoted 11 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +5
-1enum rtl8365mb_stp_state {@@ -3996,7 +4016,11 @@ static int rtl8365mb_detect(struct realtek_priv *priv)dev_info (priv->dev,"found an %s switch\n" , mb->chip_info->name); - priv->num_ports =RTL8365MB_MAX_NUM_PORTS ; +if (rtl8365mb_get_family (priv) ==RTL8365MB_FAMILY_D ) + priv->num_ports =RTL8365MB_D_MAX_NUM_PORTS ; +else + priv->num_ports =RTL8365MB_MAX_NUM_PORTS ; +
The above becomes something like
priv->num_ports = mb->chip_info->num_ports;
The reason I'm saying this is that I saw quite a few places where you have a construct of the form:
if (family is d)
// use family d constant
else
// use family c constant
Which can become a bit hard to follow/maintain.
I haven't yet had the time to look closely at all the patches (I picked the other one first because it was missing a Reviewed-by). But I'll try and take a closer look tomorrow and point out where else we could improve in this direction. I hope it's possible to remove most of the if (family is x) { do something } constructs and keep things flat.
Another thing I noticed in the L2 patch was that you added a macro:
#define RTL8365MB_D_L2_MAX_PORT 7
followed by:
@@ -286,17 +428,23 @@ int rtl8365mb_l2_get_next_uc(struct realtek_priv *priv, u16 *addr, int port,
struct rtl8365mb_l2_uc uc;
int ret;+ if (rtl8365mb_l2_is_d(priv) && port > RTL8365MB_D_L2_MAX_PORT)
+ return -EINVAL;
+
Which I wonder, can you even get there if the num_ports is 8? We didn't need that protection for family C. I think you can drop the macro and this check.
Kind regards,
Alvin
Quoted 4 lines · Alvin Šipraga
Hi Mieczyslaw,
First of all, apologies for such a late review! I hope you appreciate the feedback anyways.
Hi Alvin,
Thanks for the review, no need to apologise. Your comments crossed with the v8 I had just sent, so they are not included there. I will address them in v9.
Quoted 8 lines
This is OK, but in the same spirit as my comment to your other patch, I think we want to make the C and D families equal. So why not:
(quoted diff) +2
-1-#define RTL8365MB_MAX_NUM_PORTS 11 +#define RTL8365MB_C_MAX_NUM_PORTS 11 +#define RTL8365MB_D_MAX_NUM_PORTS 8and add a
num_portsmember to structrtl8365mb_chip_info. Then below:
[...]
Quoted 3 lines
The above becomes something like
priv->num_ports=mb->chip_info->num_ports;
Agreed. In v9 I'll rename the constants as you suggest, add num_ports to struct rtl8365mb_chip_info and use it in rtl8365mb_detect().
Quoted 3 lines
Another thing I noticed in the L2 patch was that you added a macro:
#define
RTL8365MB_D_L2_MAX_PORT7
[...]
Quoted 3 lines
Which I wonder, can you even get there if the
num_portsis 8? We didn't need that protection for family C. I think you can drop the macro and this check.
Right, with num_ports capped at 8 the core never passes a port above 7, same as on family C. I'll drop the macro and the related checks in v9.
Quoted 9 lines
The reason I'm saying this is that I saw quite a few places where you have a construct of the form:
if (family is d)
// use family d constant
else
// use family c constantWhich can become a bit hard to follow/maintain.
[...]
Quoted 2 lines
I hope it's possible to remove most of the if (family is x) { do something } constructs and keep things flat.
Understood. I'll wait for the rest of your comments on v8 and then move per-family constants into chip_info where it makes sense, rather than branching in the code.
Thanks,
Mieczyslaw
Quoted 5 lines · Alvin Šipraga
I haven't yet had the time to look closely at all the patches [...]. But I'll try and take a closer look tomorrow and point out where else we could improve in this direction. I hope it's possible to remove most of the if (family is x) { do something } constructs and keep things flat.
Hi Alvin,
While waiting for your comments I went through the series myself with that goal. Per-family constants and the L2 serializers are the cleanest case, so I'm taking them one step further than a num_ports member. Instead of adding more members to struct rtl8365mb_chip_info one by one, I'm grouping everything that depends only on the family into a single struct that chip_info points to:
struct rtl8365mb_family_info {
enum rtl8365mb_family family;
unsigned int num_ports;
const struct rtl8365mb_jam_tbl_entry *jam_table;
size_t jam_size;
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); };
There is one instance for family C and one for family D, and the chip table entries only say:
.family_info = &rtl8365mb_family_d,
Quoted 7 lines
The reason I'm saying this is that I saw quite a few places where you have a construct of the form:
if (family is d)
// use family d constant
else
// use family c constant
For the L2 code this removes the construct entirely: the four rtl8365mb_l2_*() dispatchers and rtl8365mb_l2_entry_size() are gone, and the callers use fi->l2_uc_to_data(), fi->l2_entry_size and so on. The same goes for num_ports in detect() and the jam table in switch_init().
Some places differ in sequence and not only in constants, e.g. the SerDes configuration, the CVLAN entry packing and the PVID handling. I'd rather not hide those behind callbacks without a clear gain, but I'll go through them again and convert what reads better as per-family data or ops. If you see specific spots when you review the rest of the series, please point them out and I'll look at those first.
Thanks,
Mieczyslaw
Alvin Šipraga
reviewerRe: [PATCH net-next v7 03/10] net: dsa: realtek: rtl8365mb: set speed for family D
In reply to Mieczyslaw NalewajQuoted 32 lines · 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), soFORCE_EN(bit 12 on family C) is not set. A second per-port register at0x12c8+ port enables the forced mode: the vendor RTL8367D API writes0xFFFFthere when the MAC is forced and 0 otherwise. This driver always forces the MAC, as on family C, so it writes0xFFFFon every call, including link down.The family D branch is not reachable until the chip table entry is added in the last patch.
Signed-off-by Mieczyslaw Nalewaj <[email protected]>Reviewed-by Linus Walleij <[email protected]>--- drivers/net/dsa/realtek/rtl8365mb_main.c | 82 ++++++++++++++++++++---- 1 file changed, 69 insertions(+), 13 deletions(-)drivers/net/dsa/realtek/rtl8365mb_main.c +0
-0
drivers/net/dsa/realtek/rtl8365mb_main.c line 347
Quoted 4 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +1
-0@@ -344,6 +344,7 @@#define RTL8365MB_PORT_SPEED_10M 0#define RTL8365MB_PORT_SPEED_100M 1#define RTL8365MB_PORT_SPEED_1000M 2 +#define RTL8365MB_D_PORT_SPEED_2500M 5
I'm starting to doubt the value of these macros now that I see this _D exception too. Maybe it's more straightforward to inline the values in the function.
drivers/net/dsa/realtek/rtl8365mb_main.c line 366
Quoted 9 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +2
-0/* External interface force configuration registers 0~2 */ #define RTL8365MB_DIGITAL_INTERFACE_FORCE_REG0 0x1310/* EXT0 */ @@ -361,6 +362,28 @@#define RTL8365MB_DIGITAL_INTERFACE_FORCE_LINK_MASK BIT(4)#define RTL8365MB_DIGITAL_INTERFACE_FORCE_DUPLEX_MASK BIT(2)#define RTL8365MB_DIGITAL_INTERFACE_FORCE_SPEED_MASK GENMASK(1, 0) +/* Width of the FORCE_SPEED field, bits[1:0] */ +#define RTL8365MB_DIGITAL_INTERFACE_FORCE_SPEED_WIDTH 2
We don't have any other _WIDTH macros so my instinct is that you can dispose of this...
Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +10
-0+ +/* bits[13:12]; bit 13 reserved, no defined speed value uses it yet */ +#define RTL8365MB_D_DIGITAL_INTERFACE_FORCE_SPEED2_MASK GENMASK(13, 12) + +#define RTL8365MB_D_DIGITAL_INTERFACE_FORCE_REG_BASE 0x12c0 +#define RTL8365MB_D_DIGITAL_INTERFACE_FORCE_REG (_port) \ + (RTL8365MB_D_DIGITAL_INTERFACE_FORCE_REG_BASE + (_port)) + +#define RTL8365MB_D_DIGITAL_INTERFACE_FORCE_EN_BASE 0x12c8 +#define RTL8365MB_D_DIGITAL_INTERFACE_FORCE_REG_EN (_port) \
drivers/net/dsa/realtek/rtl8365mb_main.c line 386
Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +10
-0+ (RTL8365MB_D_DIGITAL_INTERFACE_FORCE_EN_BASE + (_port)) + +/* Per-port force-mode enable. The vendor RTL8367D API +* (dal_rtl8367d_port_macForceLink_set()) treats it as an on/off switch for +* the whole forced configuration: all bits set when the MAC is forced, zero +* when it is not. The meaning of the individual bits is not documented. +* This driver always forces the MAC, as on family C, so all bits are set +* on every call, including link down. + */ +#define RTL8365MB_D_DIGITAL_INTERFACE_FORCE_EN_ALL_MASK GENMASK(15, 0)
Ahh, at this rate, maybe the ext_config_forcemode() should just be split into two functions per family. Since you're now writing to completely different registers depending on the family, which are only somewhat similar. Can you try it and see how it looks?
I'd then also update the "old" C register macros to have the RTL8365MB_C_ prefix. That way we have an approach in the driver where non-common registers are labelled by their family.
And as above, you can then just inline the values for r_speed and r_speed2. It's not pretty but the global macros do not really help IMO.
Again, try it out, if you don't like it, then I guess this is still OK.
Kind regards,
Alvin
Alvin Šipraga
reviewerRe: [PATCH net-next v7 04/10] net: dsa: realtek: rtl8365mb: set RGMII mode for family D
In reply to Mieczyslaw NalewajQuoted 11 lines · Mieczyslaw Nalewaj
On family D, RGMII on extension interface 1 needs two 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, and the pin mux in the top-level configuration register must be set up.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 writes0x0090to 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.
Should we not just clear it with the jam table then? It would save some code here, which is just undoing what the jam table did anyway. Or am I missing something? If you deviate from the vendor driver's jam table then a comment inline or in its own commit could be appropriate. But either way it seems it would save some code here?
Quoted 112 lines
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 a warning naming the conflict. When MAC4 does not own the pins, bind the RGMII/MII pins to MAC7. SerDes 1, which shares the pins, is always disabled. 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.
Signed-off-by Mieczyslaw Nalewaj <[email protected]>Reviewed-by Linus Walleij <[email protected]>--- drivers/net/dsa/realtek/rtl8365mb_main.c | 72 +++++++++++++++++++++++- 1 file changed, 70 insertions(+), 2 deletions(-)drivers/net/dsa/realtek/rtl8365mb_main.c +54
-2@@ -332,6 +332,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 @@ -465,6 +471,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 @@ -1261,6 +1281,33 @@ static int rtl8365mb_ext_config_rgmii(struct realtek_priv *priv, int port,if (ret)return ret; +if (rtl8365mb_get_family (priv) ==RTL8365MB_FAMILY_D && + 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),@@ -1773,6 +1820,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 ;@@ -1802,8 +1851,27 @@ 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_get_family(priv) == RTL8365MB_FAMILY_D &&
drivers/net/dsa/realtek/rtl8365mb_main.c static void rtl8365mb_phylink_get_caps(struct dsa_switch *ds, int port, · line 1868
Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +10
-0+ extint->id == 1) { + ret =regmap_read (priv->map,RTL8365MB_D_REG_TOP_CON0 , &data); +if (ret) +dev_warn (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_warn (priv->dev, +"port %d: EXT1 is owned by MAC4, RGMII disabled\n" , + port);
I am a little confused about everything that's going on here, but it's probably just me. Could you perhaps explain the two scenarios and the order in which you expect things to happen? I'm sort of wondering when this warning might be emitted. Part of me also wonders if you can't avoid doing a regmap_read() here in phylink_get_caps.
Quoted 12 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +6
-0+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
Alvin Šipraga
reviewerRe: [PATCH net-next v7 05/10] net: dsa: realtek: rtl8365mb: set and get vlan 4k for family D
In reply to Mieczyslaw NalewajQuoted 152 lines · 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) followsvlan4k->ivl_en, as on family C; the only caller,rtl8365mb_vlan_4k_port_set(), always requests IVL.SVLAN_CHK_IVL_SVL(bit 2) is left at 0, as in the vendor RTL8367D CVLAN API, which sets it only from the SVLAN member API; this driver has no SVLAN support.vlan4k->ivl_enis read back fromIVL_EN.Reusing the three-word family C layout unconditionally means the third word is read from and written back to the register that holds it on family C, but does not exist as a distinct table word on family D's die; whatever data happens to be there gets folded into member/untag bits [10:8] on read, and re-written on every read-modify-write cycle in
rtl8365mb_vlan_4k_port_set(). Give family D its own two-word pack/unpack instead.The two-word layout matches the vendor switch API for this chip family, which writes only 0x0510/0x0511 for a CVLAN entry.
The family D paths are not reachable until the RTL8367S-VB chip table entry is added in the last patch of the series.
Signed-off-by Mieczyslaw Nalewaj <[email protected]>Reviewed-by Linus Walleij <[email protected]>--- drivers/net/dsa/realtek/rtl8365mb_vlan.c | 161 ++++++++++++++++------- 1 file changed, 111 insertions(+), 50 deletions(-)drivers/net/dsa/realtek/rtl8365mb_vlan.c +52
-24@@ -48,12 +48,16 @@#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] */ +/* CVLAN (i.e. VLAN4k) table entry layout: u16[3] on family C, u16[2] on +* family D +*/ #define RTL8365MB_CVLAN_ENTRY_SIZE 3/* 48-bits */ +#define RTL8365MB_D_CVLAN_ENTRY_SIZE 2/* 32-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)@@ -65,6 +69,9 @@#define RTL8365MB_CVLAN_ENTRY_D1_METERIDX_MASK GENMASK(13, 9)#define RTL8365MB_CVLAN_METERIDX_LO_MASK GENMASK(4, 0)#define RTL8365MB_CVLAN_ENTRY_D1_IVL_SVL_MASK GENMASK(14, 14) +/* Family D CVLAN entry, word 1 (family D has no word 2) */ +#define RTL8365MB_D_CVLAN_ENTRY_D1_IVL_EN_MASK GENMASK(3, 3) +#define RTL8365MB_D_CVLAN_ENTRY_D1_FID_MASK GENMASK(1, 0)/* extends RTL8365MB_CVLAN_ENTRY_D0_MBR_MASK */ #define RTL8365MB_CVLAN_ENTRY_D2_MBR_EXT_MASK GENMASK(2, 0)#define RTL8365MB_CVLAN_MBR_HI_MASK GENMASK(10, 8)@@ -185,13 +192,16 @@ struct rtl8365mb_vlanmc {static int rtl8365mb_vlan_4k_read (struct realtek_priv *priv,u16 vid,struct rtl8365mb_vlan4k *vlan4k) { +bool is_d =rtl8365mb_get_family (priv) ==RTL8365MB_FAMILY_D ; +size_t entry_size = is_d ?RTL8365MB_D_CVLAN_ENTRY_SIZE : +RTL8365MB_CVLAN_ENTRY_SIZE ;u16 data[RTL8365MB_CVLAN_ENTRY_SIZE ];int val;int ret; ret =rtl8365mb_table_query (priv,RTL8365MB_TABLE_CVLAN ,RTL8365MB_TABLE_OP_READ , &vid,0 ,0 , - data,ARRAY_SIZE (data)); + data, entry_size);if (ret)return ret;@@ -199,33 +209,61 @@ static int rtl8365mb_vlan_4k_read(struct realtek_priv *priv, u16 vid,memset (vlan4k,0 ,sizeof (*vlan4k)); vlan4k->vid = vid; +/* member/untag: d0[7:0]/d0[15:8] on both families. Family C +* extends these into data[2] bits [2:0]/[5:3] for its 9th-11th +* ports; family D's die has only 8 ports and no third table +* word, so data[2] does not exist there and must not be read. +*/ val =FIELD_GET (RTL8365MB_CVLAN_ENTRY_D0_MBR_MASK , data[0 ]); vlan4k->member =FIELD_PREP (RTL8365MB_CVLAN_MBR_LO_MASK , val); - val =FIELD_GET (RTL8365MB_CVLAN_ENTRY_D2_MBR_EXT_MASK , data[2 ]); - vlan4k->member |=FIELD_PREP (RTL8365MB_CVLAN_MBR_HI_MASK , val); +if (!is_d) { + val =FIELD_GET (RTL8365MB_CVLAN_ENTRY_D2_MBR_EXT_MASK , data[2 ]); + vlan4k->member |=FIELD_PREP (RTL8365MB_CVLAN_MBR_HI_MASK , val); + } val =FIELD_GET (RTL8365MB_CVLAN_ENTRY_D0_UNTAG_MASK , data[0 ]); vlan4k->untag =FIELD_PREP (RTL8365MB_CVLAN_UNTAG_LO_MASK , val); - val =FIELD_GET (RTL8365MB_CVLAN_ENTRY_D2_UNTAG_EXT_MASK , data[2 ]); - vlan4k->untag |=FIELD_PREP (RTL8365MB_CVLAN_UNTAG_HI_MASK , val); - - vlan4k->fid =FIELD_GET (RTL8365MB_CVLAN_ENTRY_D1_FID_MASK , data[1 ]); - vlan4k->priority_en = -FIELD_GET (RTL8365MB_CVLAN_ENTRY_D1_VBPEN_MASK , data[1 ]); - vlan4k->priority = -FIELD_GET (RTL8365MB_CVLAN_ENTRY_D1_VBPRI_MASK , data[1 ]); - vlan4k->policing_en = -FIELD_GET (RTL8365MB_CVLAN_ENTRY_D1_ENVLANPOL_MASK , data[1 ]); - - val =FIELD_GET (RTL8365MB_CVLAN_ENTRY_D1_METERIDX_MASK , data[1 ]); - val =FIELD_PREP (RTL8365MB_CVLAN_METERIDX_LO_MASK , val); - vlan4k->meteridx = val; - val =FIELD_GET (RTL8365MB_CVLAN_ENTRY_D2_METERIDX_EXT_MASK , data[2 ]); - val =FIELD_PREP (RTL8365MB_CVLAN_METERIDX_HI_MASK , val); - vlan4k->meteridx |= val; - - vlan4k->ivl_en = -FIELD_GET (RTL8365MB_CVLAN_ENTRY_D1_IVL_SVL_MASK , data[1 ]); +if (!is_d) { + val =FIELD_GET (RTL8365MB_CVLAN_ENTRY_D2_UNTAG_EXT_MASK , + data[2 ]); + vlan4k->untag |=FIELD_PREP (RTL8365MB_CVLAN_UNTAG_HI_MASK , val); + } + +if (is_d) { + vlan4k->fid =FIELD_GET (RTL8365MB_D_CVLAN_ENTRY_D1_FID_MASK , + data[1 ]); +/* Family D has no priority/meter fields in this entry - +* left zeroed by the memset() above. +*/ + vlan4k->ivl_en = +FIELD_GET (RTL8365MB_D_CVLAN_ENTRY_D1_IVL_EN_MASK , + data[1 ]); + }else { + vlan4k->fid =FIELD_GET (RTL8365MB_CVLAN_ENTRY_D1_FID_MASK , + data[1 ]); + vlan4k->priority_en = +FIELD_GET (RTL8365MB_CVLAN_ENTRY_D1_VBPEN_MASK , + data[1 ]); + vlan4k->priority = +FIELD_GET (RTL8365MB_CVLAN_ENTRY_D1_VBPRI_MASK , + data[1 ]); + vlan4k->policing_en = +FIELD_GET (RTL8365MB_CVLAN_ENTRY_D1_ENVLANPOL_MASK , + data[1 ]); + + val =FIELD_GET (RTL8365MB_CVLAN_ENTRY_D1_METERIDX_MASK , + data[1 ]); + val =FIELD_PREP (RTL8365MB_CVLAN_METERIDX_LO_MASK , val);
drivers/net/dsa/realtek/rtl8365mb_vlan.c static int rtl8365mb_vlan_4k_read(struct realtek_priv *priv, u16 vid, · line 266
Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_vlan.c +10
-0+ vlan4k->meteridx = val; + val =FIELD_GET (RTL8365MB_CVLAN_ENTRY_D2_METERIDX_EXT_MASK , + data[2 ]); + val =FIELD_PREP (RTL8365MB_CVLAN_METERIDX_HI_MASK , val); + vlan4k->meteridx |= val; + + vlan4k->ivl_en = +FIELD_GET (RTL8365MB_CVLAN_ENTRY_D1_IVL_SVL_MASK , + data[1 ]); + }
Don't you think it's better to just split out into family C/D variants for these ops? If you do so, then I think relabelling the old macros for the C family with RTL8365MB_C_ prefixes will also be appropriate.
[...]
Kind regards,
Alvin
Alvin Šipraga
reviewerRe: [PATCH net-next v7 08/10] net: dsa: realtek: rtl8365mb: re-latch the family D SerDes
In reply to Mieczyslaw NalewajQuoted 6 lines · Mieczyslaw Nalewaj
The family D receiver latches on the DISABLE -> HSGMII edge in
SDS_MISCrather than on the value, and it will not latch until the MAC at the other end of the trunk has brought its own half of the link up. If it does not latch, the trunk reports 2.5Gbps/Full on both sides but moves no frames: the CPU MAC transmits, the switch CPU port counts no octets, and there are no CRC, alignment or FIFO errors.
[...]
drivers/net/dsa/realtek/rtl8365mb_main.c static int rtl8365mb_ext_config_rgmii(struct realtek_priv *priv, int port, · line 1410
Quoted 10 lines
#define
pcs_to_rtl8365mb(_pcs)container_of((_pcs), struct rtl8365mb, pcs)drivers/net/dsa/realtek/rtl8365mb_main.c +2
-0@@ -1357,43 +1404,53 @@ static int rtl8365mb_ext_config_rgmii(struct realtek_priv *priv, int port,static int rtl8365mb_sds_write (struct realtek_priv *priv,u8 index,u16 addr,u16 data) { +struct rtl8365mb *mb = priv->chip_data;int ret; +mutex_lock (&mb->sds_lock);
OK, I don't think I can give a particularly good review of this patch since I didn't follow the previous work for SerDes support... But at least, can you use guard(mutex)() here? ;-) And elsewhere it might apply.
Quoted 29 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +12
-7+ ret =regmap_write (priv->map,RTL8365MB_SDS_INDACS_DATA_REG , data);if (ret) -return ret; + goto out_unlock; ret =regmap_write (priv->map,RTL8365MB_SDS_INDACS_ADR_REG , addr);if (ret) -return ret; + goto out_unlock;/* The SerDes indirect access engine completes the command within the * register write transaction, so there is no need to wait or poll for * completion before the next access, matching the vendor driver. */ -return regmap_write (priv->map,RTL8365MB_SDS_INDACS_CMD_REG , -RTL8365MB_SDS_INDACS_CMD_RUN_MASK | -RTL8365MB_SDS_INDACS_CMD_WR_MASK | -FIELD_PREP (RTL8365MB_SDS_INDACS_CMD_INDEX_MASK , - index)); + ret =regmap_write (priv->map,RTL8365MB_SDS_INDACS_CMD_REG , +RTL8365MB_SDS_INDACS_CMD_RUN_MASK | +RTL8365MB_SDS_INDACS_CMD_WR_MASK | +FIELD_PREP (RTL8365MB_SDS_INDACS_CMD_INDEX_MASK , + index)); + +out_unlock: +mutex_unlock (&mb->sds_lock); +return ret;
drivers/net/dsa/realtek/rtl8365mb_main.c static int rtl8365mb_ext_config_rgmii(struct realtek_priv *priv, int port, · line 1442
Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +2
-0}static int rtl8365mb_sds_read (struct realtek_priv *priv,u8 index,u16 addr,u16 *data) { +struct rtl8365mb *mb = priv->chip_data;u32 val;int ret; +mutex_lock (&mb->sds_lock);
Like here, etc.
Kind regards,
Alvin
Alvin Šipraga
reviewerQuoted 28 lines · Mieczyslaw Nalewaj
Quoted 5 lines · Alvin Šipraga
I haven't yet had the time to look closely at all the patches [...]. But I'll try and take a closer look tomorrow and point out where else we could improve in this direction. I hope it's possible to remove most of the if (family is x) { do something } constructs and keep things flat.
Hi Alvin,
While waiting for your comments I went through the series myself with that goal. Per-family constants and the L2 serializers are the cleanest case, so I'm taking them one step further than a
num_portsmember. Instead of adding more members to structrtl8365mb_chip_infoone by one, I'm grouping everything that depends only on the family into a single struct thatchip_infopoints to:struct
rtl8365mb_family_info{
enumrtl8365mb_familyfamily;
unsigned intnum_ports;
const structrtl8365mb_jam_tbl_entry*jam_table;
size_tjam_size;
size_tl2_entry_size;
void (*l2_data_to_uc)(const u16 *data, structrtl8365mb_l2_uc*uc); void (*l2_uc_to_data)(const structrtl8365mb_l2_uc*uc, u16 *data); void (*l2_data_to_mc)(const u16 *data, structrtl8365mb_l2_mc*mc); void (*l2_mc_to_data)(const structrtl8365mb_l2_mc*mc, u16 *data); };
Quoted 4 lines
There is one instance for family C and one for family D, and the chip table entries only say:
.family_info =
&rtl8365mb_family_d,
Yes, sounds reasonable. Starts to resemble how mv88e6xxx does it.
Quoted 15 lines
Quoted 8 lines
The reason I'm saying this is that I saw quite a few places where you have a construct of the form:
if (family is d)
// use family d constant
else
// use family c constantFor the L2 code this removes the construct entirely: the four rtl8365mb_l2_*() dispatchers and
rtl8365mb_l2_entry_size()are gone, and the callers usefi->l2_uc_to_data(),fi->l2_entry_sizeand so on. The same goes fornum_portsindetect()and the jam table inswitch_init().
Quoted 7 lines
Some places differ in sequence and not only in constants, e.g. the SerDes configuration, the CVLAN entry packing and the PVID handling. I'd rather not hide those behind callbacks without a clear gain, but I'll go through them again and convert what reads better as per-family data or ops. If you see specific spots when you review the rest of the series, please point them out and I'll look at those first.
It seemed to me that VLAN would also benefit from being split out somehow. I already tried to structure the VLAN/L2 APIs into somewhat high- and low-level implementations, the former being accessed by _main.c and the latter implemented in _{vlan,l2}.c. In the cases where the binary format/address the chip expects is different, it seems logical to then have different low-level implementations depending on family. There might be some code duplication, but to the extent that it's just incidental (e.g. 50% of the stuff is the same), it can still improve the maintainability of the code IMO.
But if there's also extra steps in the sequence, then perhaps it's better to avoid an if (family D) { do this extra thing }, and instead implement a whole different operation with a little code duplication. It's a matter of taste though.
I would encourage you not to send a v9 straight away but to discuss some things on the list first. Otherwise it's easy to lose track of the conversation.
Kind regards,
Alvin
Quoted 6 lines · Alvin Šipraga
Quoted 4 lines · Mieczyslaw Nalewaj
There is one instance for family C and one for family D, and the chip table entries only say:
.family_info =
&rtl8365mb_family_d,Yes, sounds reasonable. Starts to resemble how mv88e6xxx does it.
Thanks. I'm glad we are aligned on the family_info approach. Since I already
have a working draft of this refactoring, I’ve pushed the current pre-v9 code
to GitHub for early visibility. If you'd like to see how the family_info
looks in practice while reviewing, you can check it out here: https://github.com/namiltd/rtl8367d/pull/11/commits
Quoted 5 lines
It seemed to me that VLAN would also benefit from being split out somehow. I already tried to structure the VLAN/L2 APIs into somewhat high- and low-level implementations, the former being accessed by
_main.cand the latter implemented in _{vlan,l2}.c. In the cases where the binary format/address the chip expects is different, it seems
Quoted 8 lines
logical to then have different low-level implementations depending on family. There might be some code duplication, but to the extent that it's just incidental (e.g. 50% of the stuff is the same), it can still improve the maintainability of the code IMO.
But if there's also extra steps in the sequence, then perhaps it's better to avoid an if (family D) { do this extra thing }, and instead implement a whole different operation with a little code duplication. It's a matter of taste though.
Agreed. I will look into splitting the low-level VLAN operations into distinct family C and D functions inside rtl8365mb_vlan.c to avoid internal if/else checks. A bit of duplication is definitely worth it for better maintainability.
Quoted 3 lines
I would encourage you not to send a v9 straight away but to discuss some things on the list first. Otherwise it's easy to lose track of the conversation.
Understood. I will hold off on sending the official v9 patchset until we finish discussing the remaining parts here on the list.
Kind regards,
Mieczyslaw
Re: [PATCH net-next v7 08/10] net: dsa: realtek: rtl8365mb: re-latch the family D SerDes
In reply to Alvin ŠipragaSubject: Re: [PATCH net-next v7 08/10] net: dsa: realtek: rtl8365mb: re-latch the family D SerDes
Quoted 10 lines · Alvin Šipraga
Quoted 4 lines · Mieczyslaw Nalewaj
+ struct rtl8365mb *mb =
priv->chip_data;
int ret;+
mutex_lock(&mb->sds_lock);OK, I don't think I can give a particularly good review of this patch since I didn't follow the previous work for SerDes support... But at least, can you use guard(mutex)() here? ;-) And elsewhere it might apply.
Sure, done. rtl8365mb_sds_write() and rtl8365mb_sds_read() now take sds_lock with guard(mutex)(&mb->sds_lock), so the goto out_unlock paths and the explicit mutex_unlock() are gone and every error path is a plain return.
Quoted 3 lines
Quoted 1 line
+
mutex_lock(&mb->sds_lock);Like here, etc.
These two are the only users of sds_lock. The other locking in the patch (sds_cfg_lock in pcs_config(), pcs_disable(), conduit_state_change() and teardown()) already uses guard(mutex)().
As you suggested, I will not post v9 yet and will wait until we have settled the remaining points in this thread.
Best regards,
Mieczyslaw
Re: [PATCH net-next v7 04/10] net: dsa: realtek: rtl8365mb: set RGMII mode for family D
In reply to Alvin ŠipragaQuoted 13 lines · Alvin Šipraga
Quoted 11 lines · Mieczyslaw Nalewaj
On family D, RGMII on extension interface 1 needs two 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, and the pin mux in the top-level configuration register must be set up.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 writes0x0090to 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.
Quoted 5 lines
Should we not just clear it with the jam table then? It would save some code here, which is just undoing what the jam table did anyway. Or am I missing something? If you deviate from the vendor driver's jam table then a comment inline or in its own commit could be appropriate. But either way it seems it would save some code here?
The jam table rtl8365mb_init_jam_8365mb_vc is shared between family C and D. Changing the 0x13f9 entry from 0x0090 to 0x0080 would also change family C behaviour, which I cannot test. Duplicating the whole table for a single word seemed worse than two lines of code. Also, the vendor code clears this field only when configuring RGMII on EXT1, not on every init, so doing it in ext_config_rgmii() matches that.
If you would still prefer a separate table for D, family_info->jam_table already allows it and I can do that in v10.
Quoted 14 lines
Quoted 4 lines
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. [...]Quoted 9 lines
[...]
+ 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_get_family(priv)==RTL8365MB_FAMILY_D&& +extint->id== 1) {
+ ret =regmap_read(priv->map, RTL8365MB_D_REG_TOP_CON0, &data); [...]
Quoted 5 lines
I am a little confused about everything that's going on here, but it's probably just me. Could you perhaps explain the two scenarios and the order in which you expect things to happen? I'm sort of wondering when this warning might be emitted. Part of me also wonders if you can't avoid doing a
regmap_read()here inphylink_get_caps.
On family D the EXT1 pins are shared between MAC7 (the port described in the DT) and the internal MAC4 (UTP port 4). TOP_CON0 bit 12 tells which of them owns the pins. This comes from the vendor RTL8367D API, which refuses RGMII on port 7 when UTP port 4 uses the RGMII interface. The driver never writes bit 12 and I do not know what sets its value at reset (strap, EEPROM or bootloader); I do not have a board where it is set, so I could not test that case. That is why get_caps() reads the bit instead of assuming a value.
1) Bit 12 set (MAC4 owns EXT1):
- get_caps() does not advertise RGMII for port 7,
- phylink refuses an RGMII phy-mode for that port,
- ext_config_rgmii() is never reached, so no EXT1 register is touched,
- the warning is printed from get_caps() when phylink is created for the port.
2) Bit 12 clear (MAC4 does not own EXT1):
- get_caps() advertises RGMII,
- ext_config_rgmii() clears the EXT1 TX delay field, binds the pins to MAC7 (MAC7_SEL_EXT1 in TOP_CON0) and disables SerDes 1, all before RGMII is selected, so the shared pins are never driven by RGMII and SerDes 1 at the same time.
You are right that the regmap_read() in get_caps() is not nice. It also means the warning is printed whenever get_caps() runs for that port, even if the DT does not use RGMII there.
Since the driver never modifies the bit, reading it once in rtl8365mb_setup() should be sufficient. I could store it in struct rtl8365mb (e.g. bool ext1_owned_by_mac4) and have get_caps() only test that flag, so it no longer touches the regmap. The warning could then be moved to setup and printed only when the DT actually requests RGMII on port 7. Would you like me to do that in v10?
Kind regards,
Mieczyslaw
Alvin Šipraga
reviewerRe: [PATCH net-next v7 08/10] net: dsa: realtek: rtl8365mb: re-latch the family D SerDes
In reply to Mieczyslaw NalewajQuoted 15 lines · Mieczyslaw Nalewaj
Subject: Re: [PATCH net-next v7 08/10] net: dsa: realtek: rtl8365mb:
re-latch the family D SerDesQuoted 10 lines · Alvin Šipraga
Quoted 4 lines · Mieczyslaw Nalewaj
+ struct rtl8365mb *mb =
priv->chip_data;
int ret;+
mutex_lock(&mb->sds_lock);OK, I don't think I can give a particularly good review of this patch since I didn't follow the previous work for SerDes support... But at least, can you use guard(mutex)() here? ;-) And elsewhere it might apply.
Quoted 4 lines
Sure, done.
rtl8365mb_sds_write()andrtl8365mb_sds_read()now takesds_lockwith guard(mutex)(&mb->sds_lock), so the gotoout_unlockpaths and the explicitmutex_unlock()are gone and every error path is a plain return.
I've spent too much time out of netdev recently:
https://lore.kernel.org/all/[email protected]/
Andrew here gives some input on netdev maintainters' view of guard().
So perhaps you can ignore my comment to this patch after all.
Quoted 14 lines
Quoted 4 lines
Quoted 2 lines
+
mutex_lock(&mb->sds_lock);Like here, etc.
These two are the only users of
sds_lock. The other locking in the patch (sds_cfg_lockinpcs_config(),pcs_disable(),conduit_state_change()andteardown()) already uses guard(mutex)().As you suggested, I will not post v9 yet and will wait until we have settled the remaining points in this thread.
Best regards,
Mieczyslaw
Re: [PATCH net-next v7 08/10] net: dsa: realtek: rtl8365mb: re-latch the family D SerDes
Quoted 6 lines · Alvin Šipraga
Quoted 4 lines · Mieczyslaw Nalewaj
rtl8365mb_sds_write()andrtl8365mb_sds_read()now takesds_lockwith guard(mutex)(&mb->sds_lock), so the gotoout_unlockpaths and the explicitmutex_unlock()are gone and every error path is a plain return.
Quoted 7 lines
I've spent too much time out of netdev recently:
Andrew here gives some input on netdev maintainters' view of
guard().So perhaps you can ignore my comment to this patch after all.
Thanks for the heads-up and for sharing Andrew's input.
However, please note that guard(mutex) is already used for sds_cfg_lock in several other functions within this patch, namely pcs_config(), pcs_disable(), conduit_state_change(), and teardown().
To maintain a consistent coding style across the whole patch, should I keep guard(mutex) as it is, or would you prefer that I convert all of them back to the classic mutex_lock()/mutex_unlock() pattern for v9?
Both rtl8365mb_sds_write() and rtl8365mb_sds_read() are very short and the lock always spans until the final return, so they shouldn't suffer from the over-protection issues Andrew mentioned, but I am happy to change the whole file back to explicit locking if that is preferred for netdev.
Best regards,
Mieczyslaw
Alvin Šipraga
reviewerRe: [PATCH net-next v7 08/10] net: dsa: realtek: rtl8365mb: re-latch the family D SerDes
Quoted 21 lines · Mieczyslaw Nalewaj
Quoted 6 lines · Alvin Šipraga
Quoted 4 lines · Mieczyslaw Nalewaj
rtl8365mb_sds_write()andrtl8365mb_sds_read()now takesds_lockwith guard(mutex)(&mb->sds_lock), so the gotoout_unlockpaths and the explicitmutex_unlock()are gone and every error path is a plain return.Quoted 7 lines
I've spent too much time out of netdev recently:
Andrew here gives some input on netdev maintainters' view of
guard().So perhaps you can ignore my comment to this patch after all.
Thanks for the heads-up and for sharing Andrew's input.
However, please note that guard(mutex) is already used for
sds_cfg_lockin several other functions within this patch, namelypcs_config(),pcs_disable(),conduit_state_change(), andteardown().
Quoted 8 lines
To maintain a consistent coding style across the whole patch, should I keep guard(mutex) as it is, or would you prefer that I convert all of them back to the classic mutex_lock()/mutex_unlock() pattern for v9?
Both
rtl8365mb_sds_write()andrtl8365mb_sds_read()are very short and the lock always spans until the final return, so they shouldn't suffer from the over-protection issues Andrew mentioned, but I am happy to change the whole file back to explicit locking if that is preferred for netdev.
After considering what Andrew said, and the fact that none of the current driver code uses guard()s, I would suggest being consistent and not using them at all.
Kind regards,
Alvin
Alvin Šipraga
reviewerRe: [PATCH net-next v7 04/10] net: dsa: realtek: rtl8365mb: set RGMII mode for family D
In reply to Mieczyslaw NalewajQuoted 27 lines · Mieczyslaw Nalewaj
Quoted 13 lines · Alvin Šipraga
Quoted 11 lines · Mieczyslaw Nalewaj
On family D, RGMII on extension interface 1 needs two 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, and the pin mux in the top-level configuration register must be set up.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 writes0x0090to 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.Quoted 5 lines
Should we not just clear it with the jam table then? It would save some code here, which is just undoing what the jam table did anyway. Or am I missing something? If you deviate from the vendor driver's jam table then a comment inline or in its own commit could be appropriate. But either way it seems it would save some code here?
The jam table
rtl8365mb_init_jam_8365mb_vcis shared between family C and D. Changing the0x13f9entry from0x0090to0x0080would also change family C behaviour, which I cannot test. Duplicating the whole table for a single word seemed worse than two lines of code. Also, the vendor code clears this field only when configuring RGMII on EXT1, not on every init, so doing it inext_config_rgmii()matches that.
Quoted 2 lines
If you would still prefer a separate table for D,
family_info->jam_tablealready allows it and I can do that in v10.
I lifted the jam tables from the vendor driver mostly verbatim, and without spending much time deciphering them. During your work on the D family, did you find that the vendor driver is programming the same values?
One thing I'm wondering is: for the other C family chips, is some extra RGMII TX delay being silently added by the jam table we already have? Or does it have some other meaning on the C family? I never got any complaints from the hardware engineers about the RGMII timing so I am kind of inclined to say that it might do something else. That was with RTL8365MB-VC which uses EXT1.
Anyway, if the jam table the vendor driver uses is indeed the same for both families, maybe it's best to keep it explicit like you have done.
Quoted 40 lines
Quoted 7 lines
Quoted 7 lines
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. [...][...]
+ if (extint->supported_interfaces&
RTL8365MB_PHY_INTERFACE_MODE_RGMII) {Quoted 6 lines
Quoted 6 lines
+ /* 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_get_family(priv)==RTL8365MB_FAMILY_D&& +extint->id== 1) {
+ ret = regmap_read(priv->map,RTL8365MB_D_REG_TOP_CON0,&data);
Quoted 7 lines
Quoted 1 line
[...]
I am a little confused about everything that's going on here, but it's probably just me. Could you perhaps explain the two scenarios and the order in which you expect things to happen? I'm sort of wondering when this warning might be emitted. Part of me also wonders if you can't avoid doing a
regmap_read()here inphylink_get_caps.On family D the EXT1 pins are shared between MAC7 (the port described in the DT) and the internal MAC4 (UTP port 4).
TOP_CON0bit 12 tells which of them owns the pins. This comes from the vendor RTL8367D API, which refuses RGMII on port 7 when UTP port 4 uses the RGMII interface. The driver never writes bit 12 and I do not know what sets its value at reset (strap, EEPROM or bootloader); I do not have a board where it is set, so I could not test that case. That is whyget_caps()reads the bit instead of assuming a value.1) Bit 12 set (MAC4 owns EXT1):
-get_caps()does not advertise RGMII for port 7,
- phylink refuses an RGMII phy-mode for that port,
-ext_config_rgmii()is never reached, so no EXT1 register is touched,
- the warning is printed fromget_caps()when phylink is created for the port.
Quoted 6 lines
2) Bit 12 clear (MAC4 does not own EXT1):
-get_caps()advertises RGMII,
-ext_config_rgmii()clears the EXT1 TX delay field, binds the pins to MAC7 (MAC7_SEL_EXT1inTOP_CON0) and disables SerDes 1, all before RGMII is selected, so the shared pins are never driven by RGMII and SerDes 1 at the same time.
Do you have a datasheet I can look at? I couldn't find one.
I'm also a bit confused by what it means for MAC4 to "own" EXT1. Are we talking about physical pin muxing (i.e. pins on the package can have different function), or is this internal muxing? And since you say MAC4 is a UTP port, I don't understand how it can also be associated with EXT1 (an MII/RGMII interface).
Quoted 11 lines
You are right that the
regmap_read()inget_caps()is not nice. It also means the warning is printed wheneverget_caps()runs for that port, even if the DT does not use RGMII there.Since the driver never modifies the bit, reading it once in
rtl8365mb_setup()should be sufficient. I could store it in struct rtl8365mb (e.g. boolext1_owned_by_mac4) and haveget_caps()only test that flag, so it no longer touches the regmap. The warning could then be moved to setup and printed only when the DT actually requests RGMII on port 7. Would you like me to do that in v10?
Since MAC7_SEL_EXT1 is writable, I would guess that so is MAC4_SEL_EXT1. Could we not instead keep it configurable, and do some bookkeeping in the driver to see who has requested these pins? Then, whenever either is configured, you first check if it's already in use, warn if so, or otherwise set it up and mark it as in-use.
Hope that makes sense.
Kind regards,
Alvin
Re: [PATCH net-next v7 04/10] net: dsa: realtek: rtl8365mb: set RGMII mode for family D
Quoted 6 lines · Alvin Šipraga
During your work on the D family, did you find that the vendor driver is programming the same values?
One thing I'm wondering is: for the other C family chips, is some extra RGMII TX delay being silently added by the jam table we already have? [...]
I did not diff the vendor family D init table against the family C one, so I cannot say they are identical. I only know this register: our table writes 0x0090 to 0x13f9, which leaves the EXT1 RGMII TX delay field at 2, and the vendor RGMII setup for EXT1 on family D clears that field. I do not know what the field does on family C.
Quoted 3 lines
Anyway, if the jam table the vendor driver uses is indeed the same for both families, maybe it's best to keep it explicit like you have done.
OK, I will keep it as it is.
Quoted 1 line
Do you have a datasheet I can look at? I couldn't find one.
No, I do not have one either. Everything about family D comes from the vendor RTL8367D API.
Quoted 4 lines
I'm also a bit confused by what it means for MAC4 to "own" EXT1. Are we talking about physical pin muxing [...] or is this internal muxing? And since you say MAC4 is a UTP port, I don't understand how it can also be associated with EXT1 [...].
I cannot answer that. "Owns" was my shorthand for the bit. All I have is this check in the vendor RGMII setup for port 7:
/* Configure RGMII/MII mux to port 7 if UTP_PORT4 is not RGMII mode */
if ((retVal = rtl8367d_getAsicRegBit(RTL8367D_REG_TOP_CON0,
RTL8367D_MAC4_SEL_EXT1_OFFSET, &mux)) != RT_ERR_OK)
return retVal;I did not verify anything beyond it, so I do not know whether this is a physical or an internal mux.
Quoted 3 lines
Since
MAC7_SEL_EXT1is writable, I would guess that so isMAC4_SEL_EXT1. Could we not instead keep it configurable, and do some bookkeeping in the driver to see who has requested these pins? [...]
The vendor code only reads MAC4_SEL_EXT1 in this path, and I have not verified that writing it is safe or what it does to UTP port 4. The driver has no code path that selects MAC4 for EXT1, so port 7 would be the only requester.
I can implement the bookkeeping in v9, but I would need to know how you want the MAC4 side handled. Alternatively, I can read the bit once in rtl8365mb_setup() and refuse RGMII on port 7 when it is set.
Kind regards,
Mieczyslaw
Alvin Šipraga
reviewerRe: [PATCH net-next v7 04/10] net: dsa: realtek: rtl8365mb: set RGMII mode for family D
Quoted 33 lines · Mieczyslaw Nalewaj
Quoted 6 lines · Alvin Šipraga
During your work on the D family, did you find that the vendor driver is programming the same values?
One thing I'm wondering is: for the other C family chips, is some extra RGMII TX delay being silently added by the jam table we already have? [...]
I did not diff the vendor family D init table against the family C one, so I cannot say they are identical. I only know this register: our table writes
0x0090to0x13f9, which leaves the EXT1 RGMII TX delay field at 2, and the vendor RGMII setup for EXT1 on family D clears that field. I do not know what the field does on family C.Quoted 3 lines
Anyway, if the jam table the vendor driver uses is indeed the same for both families, maybe it's best to keep it explicit like you have done.
OK, I will keep it as it is.
Quoted 1 line
Do you have a datasheet I can look at? I couldn't find one.
No, I do not have one either. Everything about family D comes from the vendor RTL8367D API.
Quoted 4 lines
I'm also a bit confused by what it means for MAC4 to "own" EXT1. Are we talking about physical pin muxing [...] or is this internal muxing? And since you say MAC4 is a UTP port, I don't understand how it can also be associated with EXT1 [...].
I cannot answer that. "Owns" was my shorthand for the bit. All I have is this check in the vendor RGMII setup for port 7:
Quoted 7 lines
/* Configure RGMII/MII mux to port 7 if UTP_PORT4 is not RGMII mode */ if ((retVal = rtl8367d_getAsicRegBit(RTL8367D_REG_TOP_CON0, RTL8367D_MAC4_SEL_EXT1_OFFSET, &mux)) != RT_ERR_OK) return retVal;I did not verify anything beyond it, so I do not know whether this is a physical or an internal mux.
Looking at the vendor driver, it seems you can mux what they call MAC4, to either a copper PHY, a SerDes, or an RGMII interface (EXT1). They call port it a "combo port" (see RTK_CHK_PORT_IS_COMBO()). The other port, MAC7, can also use EXT1. Or it can use a SerDes. But not copper.
The vendor driver is predictably quite confusing in its terminology, calling port 4 a UTP port while also allowing RGMII etc. But whatever.
So if I understood correctly it looks something like this:
UTP EXT1 (RMII/RGMII) SerDes(1?)
| ___|___ ___|___
| / \ / \
| |_______| |_______|
| | | | |
| .-----------' | | |
| | .------------------------' |
___|__|__|___ | .---------'
| | ___|_____|___
\_____________/ | |
| \_____________/
MAC4 |
MAC7Quoted 9 lines
Quoted 4 lines
Since
MAC7_SEL_EXT1is writable, I would guess that so isMAC4_SEL_EXT1. Could we not instead keep it configurable, and do some bookkeeping in the driver to see who has requested these pins? [...]The vendor code only reads
MAC4_SEL_EXT1in this path, and I have not verified that writing it is safe or what it does to UTP port 4. The driver has no code path that selects MAC4 for EXT1, so port 7 would be the only requester.
If you look at dal_rtl8367d_port_phyComboPortMedia_set(), it actually writes MAC4_SEL_EXT1 = 1. So this is configurable.
But for the sake of the Linux driver, we don't care about MAC4 being anything other than connected to the UTP (internal PHY), right?
So maybe just check in the switch registers, when it comes out of reset, whether the default state of MAC4_SEL_EXT1 is 0. If yes then I think we can just ignore this problem altogether, advertise RGMII capability on port 7 (i.e. use EXT1), and be done with it. Maybe add a comment where you write 1 to MAC7_SEL_EXT1 that a mux is being configured which is also shared with MAC4 somehow, but that this feature is unsupported.
Does that make sense?
Quoted 4 lines
I can implement the bookkeeping in v9, but I would need to know how you want the MAC4 side handled. Alternatively, I can read the bit once in
rtl8365mb_setup()and refuse RGMII on port 7 when it is set.
Bookkeeping is overkill. Let's just not support MAC4 as anything other than UTP. If someone wants to add that support later, then it would make sense to add bookkeeping.
Kind regards,
Alvin
Alvin Šipraga
reviewerRe: [PATCH net-next v7 08/10] net: dsa: realtek: rtl8365mb: re-latch the family D SerDes
In reply to Mieczyslaw NalewajQuoted 2 lines · Mieczyslaw Nalewaj
The family D receiver latches on the DISABLE -> HSGMII edge in
SDS_MISCrather than on the value, and it will not latch until the MAC at the
I don't understand this at all, should it be obvious what you mean by "edge" and "latch" here? I would assume you are talking about interrupts but it's not clear.
Quoted 12 lines
other end of the trunk has brought its own half of the link up. If it does not latch, the trunk reports 2.5Gbps/Full on both sides but moves no frames: the CPU MAC transmits, the switch CPU port counts no octets, and there are no CRC, alignment or FIFO errors.
The two ends can be seconds apart, e.g. on an IPQ5018 board:
5.27 rtl8365mb: configuring for fixed/2500base-x <- pcs_config() 7.72 ipq5018-gmac-dwmac eth0: configuring for fixed/2500base-x 8.02 ipq5018-gmac-dwmac eth0: Link is Up - 2.5Gbps/Full 8.56 SerDes latches
Quoted 7 lines
pcs_config()runs seconds before the far-end MAC even starts configuring, so a single edge driven from there is not enough: the receiver has nothing to latch onto yet. Neither ispcs_link_up(), which is seconds early for the same reason. phylink does not help either - it never callsrtl8365mb_pcs_get_state()for this port in the first place, sincemb->pcs.pollonly arms phylink's own poll for in-band links, and this CPU port is a fixed link.
OK, I'm out of the loop regarding the SerDes stuff. But I find this patch quite baroque and the reasoning hard to follow, with a lot of strange terminology (episode, latch, "value"?). Maybe it's just me.
Is the shortcoming/issue you are addressing one of DSA when a SerDes is used in the CPU link? Or is it rather some hardware oddity?
Can we use interrupts instead of polling?
The notifier block, extra locking, etc. gives me the creeps and seems like a lot of infrastructure to solve something I don't understand. Sorry if my questions are dumb, but I need a better explanation of the whole problem to review this properly.
Quoted 5 lines
There is no local signal that predicts when the far-end MAC will bring up its half of the link (bit 8 of the SDS link-status word does not change ahead of it), so the work cannot wait for it; it can only tell afterwards, from the link-status bit, whether an edge took.
You talk about "it" and "work" but it is unclear what you mean. You've added some scheduled work in this patch but you do not make that apparent in the commit message here.
Quoted 12 lines
The far-end MAC starts when its conduit is brought up, which DSA reports through ->conduit_state_change(), so an episode of re-latch attempts starts there. Only the conduit of the CPU port that carries the SerDes (port 6) is considered: the chip can have a second CPU port on RGMII, and its conduit says nothing about the SerDes link.
pcs_config()only arms the work, and starts an episode itself if that conduit is already up. The work re-arms itself after each edge; the next run checks whether the edge took, rather than waiting on a poll that will not come. When the conduit goes down the work is stopped, so a link without a far end is not reported as lost and not parked every 10 s.
I'm basically wondering here if this is not something that DSA or phylink could help with?
[...]
Cutting the rest for now!
Kind regards,
Alvin
Re: [PATCH net-next v7 08/10] net: dsa: realtek: rtl8365mb: re-latch the family D SerDes
Subject: Re: [PATCH net-next v7 08/10] net: dsa: realtek: rtl8365mb: re-latch the family D SerDes
Quoted 3 lines · Alvin Šipraga
I don't understand this at all, should it be obvious what you mean by "edge" and "latch" here? I would assume you are talking about interrupts but it's not clear.
Sorry, the wording was unclear, and no interrupts are involved. "Edge" is the SDS_MISC mode field changing from DISABLE to HSGMII, and "latch" is the SerDes receiver locking onto the incoming signal. It locks on that change, not on the value, and only if the far end is already sending.
Quoted 2 lines
Is the shortcoming/issue you are addressing one of DSA when a SerDes is used in the CPU link? Or is it rather some hardware oddity?
As far as I can tell, a hardware oddity. If the change happens before the far-end MAC is up, the receiver does not lock and nothing retries. Both ends then report 2.5Gbps/Full while no frames pass.
Quoted 1 line
Can we use interrupts instead of polling?
I do not know. I have no datasheet, and the vendor API I have does not expose an interrupt for the SerDes state.
Quoted 2 lines
I'm basically wondering here if this is not something that DSA or phylink could help with?
pcs_config() and pcs_link_up() run seconds before the far-end MAC starts, and phylink never calls rtl8365mb_pcs_get_state() for this
port: mb->pcs.poll only arms polling for in-band links, and the CPU port is a fixed link. The only event I found that tells the driver the far end is starting is the CPU conduit coming up, reported through ->conduit_state_change().
Quoted 2 lines
You've added some scheduled work in this patch but you do not make that apparent in the commit message here.
Right, the commit message does not say it. The work repeats the DISABLE -> HSGMII change every 10 s until the link-status bit shows that the receiver locked.
Kind regards,
Mieczyslaw
Re: [PATCH net-next v7 04/10] net: dsa: realtek: rtl8365mb: set RGMII mode for family D
In reply to Alvin ŠipragaSubject: Re: [PATCH net-next v7 04/10] net: dsa: realtek: rtl8365mb: set RGMII mode for family D
Quoted 2 lines · Alvin Šipraga
If you look at
dal_rtl8367d_port_phyComboPortMedia_set(), it actually writesMAC4_SEL_EXT1= 1. So this is configurable.
Thanks for the pointer and for the diagram, that makes the mux clear.
Quoted 2 lines
But for the sake of the Linux driver, we don't care about MAC4 being anything other than connected to the UTP (internal PHY), right?
Right, nothing in the driver selects MAC4 for EXT1.
Quoted 4 lines
So maybe just check in the switch registers, when it comes out of reset, whether the default state of
MAC4_SEL_EXT1is 0. If yes then I think we can just ignore this problem altogether, advertise RGMII capability on port 7 (i.e. use EXT1), and be done with it.
I do not have the hardware, so I cannot read the reset default of MAC4_SEL_EXT1 myself. Could someone with a board read bit 12 of TOP_CON0 (0x1d70) right after reset and confirm it is 0? If it is, the check is unnecessary and I will drop it.
Until that is confirmed I kept a single read of that bit, and RGMII is not advertised on port 7 if MAC4 owns the pins. It costs one register read, does not touch MAC4, and avoids driving the shared pins from two blocks if the default turns out to be different. It is not bookkeeping:
nothing tracks who requested EXT1, and MAC4 on EXT1 stays unsupported.
Quoted 2 lines
Bookkeeping is overkill. Let's just not support MAC4 as anything other than UTP.
Agreed.
Kind regards,
Mieczyslaw
Re: [PATCH net-next v7 04/10] net: dsa: realtek: rtl8365mb: set RGMII mode for family D
In reply to Alvin ŠipragaSubject: Re: [PATCH net-next v7 04/10] net: dsa: realtek: rtl8365mb: set RGMII mode for family D
Quoted 3 lines · Alvin Šipraga
Bookkeeping is overkill. Let's just not support MAC4 as anything other than UTP. If someone wants to add that support later, then it would make sense to add bookkeeping.
One more thing, since it affects how much I can verify. I do not have RTL8367S-VB hardware or a test setup of my own, as I wrote to Luiz earlier:
https://lore.kernel.org/netdev/[email protected]/
Quoted 3 lines
I cannot exercise FDB, VLAN filtering, STP or flooding controls myself. All testing so far was done by other users who run this code on their devices, and I depend on their reports.
This is why I could not read the reset default of MAC4_SEL_EXT1. For v9 I intend to make only the changes needed to address the open review comments, and I will not extend the series beyond that. Further verification of the shared code paths against the family D layout needs someone with the hardware and a proper test setup.
Kind regards,
Mieczyslaw
Alvin Šipraga
reviewerRe: [PATCH net-next v7 04/10] net: dsa: realtek: rtl8365mb: set RGMII mode for family D
In reply to Mieczyslaw NalewajQuoted 9 lines · Mieczyslaw Nalewaj
Quoted 4 lines
So maybe just check in the switch registers, when it comes out of reset, whether the default state of
MAC4_SEL_EXT1is 0. If yes then I think we can just ignore this problem altogether, advertise RGMII capability on port 7 (i.e. use EXT1), and be done with it.I do not have the hardware, so I cannot read the reset default of
MAC4_SEL_EXT1myself. Could someone with a board read bit 12 ofTOP_CON0(0x1d70) right after reset and confirm it is 0? If it is, the check is unnecessary and I will drop it.
If you don't have the HW, how are you testing these patches...?
I think we will need a Tested-by: tag from someone(s) with both a family C and D to get this series in, if you are unable to test things yourself.
Please also do not submit anything if it has not been tested. Maybe it was, but then please get that person's Tested-by and put them on CC. Otherwise maintainers might merge this assuming it was tested, if you got the reviews... It is a basic assumption that non-RFC stuff has been tested when posted to the list.
Kind regards,
Alvin
Alvin Šipraga
reviewerRe: [PATCH net-next v7 08/10] net: dsa: realtek: rtl8365mb: re-latch the family D SerDes
In reply to Mieczyslaw NalewajQuoted 28 lines · Mieczyslaw Nalewaj
Subject: Re: [PATCH net-next v7 08/10] net: dsa: realtek: rtl8365mb: re-latch the family D SerDes
Quoted 3 lines · Alvin Šipraga
I don't understand this at all, should it be obvious what you mean by "edge" and "latch" here? I would assume you are talking about interrupts but it's not clear.
Sorry, the wording was unclear, and no interrupts are involved. "Edge" is the
SDS_MISCmode field changing from DISABLE to HSGMII, and "latch" is the SerDes receiver locking onto the incoming signal. It locks on that change, not on the value, and only if the far end is already sending.Quoted 2 lines
Is the shortcoming/issue you are addressing one of DSA when a SerDes is used in the CPU link? Or is it rather some hardware oddity?
As far as I can tell, a hardware oddity. If the change happens before the far-end MAC is up, the receiver does not lock and nothing retries. Both ends then report 2.5Gbps/Full while no frames pass.
Quoted 1 line
Can we use interrupts instead of polling?
I do not know. I have no datasheet, and the vendor API I have does not expose an interrupt for the SerDes state.
Quoted 2 lines
I'm basically wondering here if this is not something that DSA or phylink could help with?
Quoted 6 lines
pcs_config()andpcs_link_up()run seconds before the far-end MAC starts, and phylink never callsrtl8365mb_pcs_get_state()for this
port:mb->pcs.pollonly arms polling for in-band links, and the CPU port is a fixed link. The only event I found that tells the driver the far end is starting is the CPU conduit coming up, reported through ->conduit_state_change().
OK. Unfortunately I'm a bit out of my depth here, not having worked with SerDes links before. My gut tells me this patch is overkill. I hope somebody else with more experience can chip in. Adding Johan to the mail, as he added SGMII support and might have some opinters.
Kind regards,
Alvin
Andrew Lunn
maintainerRe: [PATCH net-next v7 08/10] net: dsa: realtek: rtl8365mb: re-latch the family D SerDes
In reply to Alvin ŠipragaQuoted 7 lines
Quoted 7 lines
pcs_config()runs seconds before the far-end MAC even starts configuring, so a single edge driven from there is not enough: the receiver has nothing to latch onto yet. Neither ispcs_link_up(), which is seconds early for the same reason. phylink does not help either - it never callsrtl8365mb_pcs_get_state()for this port in the first place, sincemb->pcs.pollonly arms phylink's own poll for in-band links, and this CPU port is a fixed link.
Sorry, not been following this patch series.
One thing which might help here. Russell once said it should be possible to use phylink with pcs to pcs links, rather than use fixed-link. You then get all the phylink machinery, which might trigger the pcs negotiation and get your link up?
I don't know of any board which actually does this, so i've no idea if it really does work.
Andrew
Re: [PATCH net-next v7 04/10] net: dsa: realtek: rtl8365mb: set RGMII mode for family D
In reply to Alvin ŠipragaQuoted 5 lines · Alvin Šipraga
Quoted 2 lines · Mieczyslaw Nalewaj
I do not have the hardware, so I cannot read the reset default of
MAC4_SEL_EXT1myself. [...]If you don't have the HW, how are you testing these patches...?
The code was tested by users of RTL8367S-VB devices from the OpenWrt GitHub and the OpenWrt forum, who built it and reported back to me. These were basic functionality tests only. I do not test it myself, and I should have said so in the cover letter.
Quoted 3 lines
I think we will need a Tested-by: tag from someone(s) with both a family C and D to get this series in, if you are unable to test things yourself.
Understood. I have already asked those users to respond on this mailing list and give their Tested-by tags,
Quoted 5 lines
Please also do not submit anything if it has not been tested. Maybe it was, but then please get that person's Tested-by and put them on CC. Otherwise maintainers might merge this assuming it was tested, if you got the reviews... It is a basic assumption that non-RFC stuff has been tested when posted to the list.
Noted, and sorry for the confusion.
Kind regards,
Mieczyslaw
Luiz Angelo Daros de Luca
maintainerRe: [PATCH net-next v7 05/10] net: dsa: realtek: rtl8365mb: set and get vlan 4k for family D
In reply to Alvin ŠipragaQuoted 3 lines
Don't you think it's better to just split out into family C/D variants for these ops? If you do so, then I think relabelling the old macros for the C family with
RTL8365MB_C_prefixes will also be appropriate.
Adding a C prefix is a clean way to organize the code, and it avoids scaling issues with is_d checks as more families are added.
Splitting the logic into subfunctions handled via a family enum switch (or eventually function pointers) is much more maintainable. Using a switch statement also has the advantage of compiler warnings if a new family is added and forgotten.
Here is a revised version of your response, keeping it professional, concise, and clear:
---
Quoted 3 lines
Don't you think it's better to just split out into family C/D variants for these ops? If you do so, then I think relabelling the old macros for the C family with
RTL8365MB_C_prefixes will also be appropriate.
Adding a *_C_ prefix is a good way to organize it. It will get a bit messier when I submit the RTL8367R support, which I arbitrarily named Family A, but extra macros won't increase the final binary size. We might need to duplicate some macros once we have a register used by more than one but not all families.
As Alvin mentioned, splitting into subfunctions when each family has a distinct implementation is much cleaner. In my WIP tree
(https://github.com/torvalds/linux/compare/master...luizluca:linux:realtek_families_wip),
I handle it like this:
static void rtl8365mb_l2_data_to_uc(struct realtek_priv *priv, const u16 *data,
struct rtl8365mb_l2_uc *uc)
{
switch (rtl8365mb_get_family(priv)) {
case RTL8365MB_FAMILY_A:
rtl8365mb_a_l2_data_to_uc(data, uc);
break;
case RTL8365MB_FAMILY_C:
rtl8365mb_c_l2_data_to_uc(data, uc);
break;
}
}This is how I'm structuring it now, though it might migrate to function pointers later. A family check inside a shared function only makes sense for very localized differences. Since family A is shaping up well and family B sits conceptually between A and C, is_d doesn't scale well for future variants. Using an enum with a switch statement also ensures the compiler warns you if a new family case is missed.
Best regards,
Luiz
Luiz Angelo Daros de Luca
maintainerRe: [PATCH net-next v7 06/10] net: dsa: realtek: rtl8365mb: use raw VID for PVID on family D
In reply to Mieczyslaw NalewajQuoted 40 lines
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, at0x0700+ (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.
Read the PVID straight from its register in
rtl8365mb_vlan_port_get_pvid(), and makertl8365mb_vlan_pvid_port_set()andrtl8365mb_vlan_pvid_port_clear()use direct-VID variants on family D that skip the MC table. They keep the family C frame filter handling and rollback on error.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(), andrtl8365mb_port_vlan_filtering()would accept untagged frames into it.No functional change for family C.
The family D branch is not reachable until the chip table entry is added in the last patch.
Signed-off-by Mieczyslaw Nalewaj <[email protected]>Reviewed-by Linus Walleij <[email protected]>--- drivers/net/dsa/realtek/rtl8365mb_main.c | 9 + drivers/net/dsa/realtek/rtl8365mb_vlan.c | 205 ++++++++++++++++++++++- drivers/net/dsa/realtek/rtl8365mb_vlan.h | 1 + 3 files changed, 210 insertions(+), 5 deletions(-)drivers/net/dsa/realtek/rtl8365mb_main.c +0
-0
drivers/net/dsa/realtek/rtl8365mb_main.c static int rtl8365mb_vlan_setup(struct dsa_switch *ds) · line 2364
Quoted 5 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +2
-0@@ -2360,6 +2360,15 @@ static int rtl8365mb_vlan_setup(struct dsa_switch *ds)int ret;dsa_switch_for_each_available_port (dp, ds) { +/* Start every port with the neutral PVID */ + ret =rtl8365mb_vlan_port_reset_pvid (priv, dp->index);
We already have a clear and a set operation. Why do we need a separate reset? [...]
Quoted 53 lines
drivers/net/dsa/realtek/rtl8365mb_vlan.c +22
-4@@ -44,6 +44,10 @@* * VLANMC index 0 is reserved as a neutral PVID, used for standalone ports. * +* Everything above describes chips that have a VLAN membership configuration +* table. RTL8365MB_FAMILY_D chips do not have one: their PVID is a raw 12-bit +* VID in a per-port register, and no VLANMC entries are allocated. +* */ #include "rtl8365mb_vlan.h" @@ -120,6 +124,11 @@#define RTL8365MB_VLAN_PVID_CTRL_PORT_MCIDX_MASK (_p) \ (0x1F << RTL8365MB_VLAN_PVID_CTRL_PORT_MCIDX_OFFSET(_p)) +#define RTL8365MB_D_VLAN_PVID_CTRL_BASE 0x0700 +#define RTL8365MB_D_VLAN_PVID_CTRL_REG (port) \ + (RTL8365MB_D_VLAN_PVID_CTRL_BASE + (port)) +#define RTL8365MB_D_VLAN_PVID_CTRL_MASK GENMASK(11, 0) +/* Frame type filtering registers */ #define RTL8365MB_VLAN_ACCEPT_FRAME_TYPE_BASE 0x07aa#define RTL8365MB_VLAN_ACCEPT_FRAME_TYPE_REG (port) \@@ -171,7 +180,7 @@ struct rtl8365mb_vlan4k {* This structure is used to get/set entries in the VLAN membership * configuration database. This feature is largely vestigial, but * still needed for at least the following features: -* - PVID configuration +* - PVID configuration (family C only, family D has no VLAN MC table) * - ACL configuration * - selection of VLAN by the CPU tag when VSEL=1, although the switch * can also select VLAN based on the VLAN tag if VSEL=0 @@ -740,14 +749,51 @@ int rtl8365mb_vlan_port_get_pvid(struct realtek_priv *priv, int port, u16 *pvid)u8 vlanmc_idx;int ret; - ret =rtl8365mb_vlan_get_pvid_mc (priv, port, &vlanmc_idx, &vlanmc); -if (ret) -return ret; +if (rtl8365mb_get_family (priv) ==RTL8365MB_FAMILY_D ) { +u32 data; + + ret =regmap_read (priv->map, +RTL8365MB_D_VLAN_PVID_CTRL_REG (port), + &data); +if (ret) +return ret; + + *pvid = data &RTL8365MB_D_VLAN_PVID_CTRL_MASK ; + }else { + ret = rtl8365mb_vlan_get_pvid_mc(priv, port, &vlanmc_idx,
drivers/net/dsa/realtek/rtl8365mb_vlan.c int rtl8365mb_vlan_port_get_pvid(struct realtek_priv *priv, int port, u16 *pvid) · line 772
Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_vlan.c +6
-1+ &vlanmc); +if (ret) +return ret; + + *pvid = vlanmc.evid; + } - *pvid = vlanmc.evid;return 0 ; }
If the functions don't share most of their code, they shouldn't be lumped together inside a shared function with an if/else.
drivers/net/dsa/realtek/rtl8365mb_vlan.c int rtl8365mb_vlan_port_get_pvid(struct realtek_priv *priv, int port, u16 *pvid) · line 782
Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_vlan.c +9
-0+/** +* rtl8365mb_vlan_port_reset_pvid() - Put a port's PVID in its neutral state +* @priv: realtek_priv pointer +* @port: the port number +* +* On family C the neutral PVID is VLANMC index 0, which is the reset value, so +* there is nothing to do. On family D the PVID is a raw VID in a per-port +* register whose value after reset is not defined by the driver (it may come +* from the hardware default or from an EEPROM), so clear it to 0.
I'm not entirely convinced by this. VLANMC index 0 isn't a hardware-defined neutral index; it's just a convention we use where VID == 0. The driver treats VID 0 as "unset" alongside the ingress filter. Furthermore, checking rtl8365mb_get_family(priv) != RTL8365MB_FAMILY_D doesn't scale well if we eventually introduce a family E.
Quoted 18 lines
drivers/net/dsa/realtek/rtl8365mb_vlan.c +14
-0+* +* Context: Can sleep. +* Return: 0 on success, or a negative error code on failure. +*/ +int rtl8365mb_vlan_port_reset_pvid (struct realtek_priv *priv,int port) +{ +if (rtl8365mb_get_family (priv) !=RTL8365MB_FAMILY_D ) +return 0 ; + +return regmap_update_bits (priv->map, +RTL8365MB_D_VLAN_PVID_CTRL_REG (port), +RTL8365MB_D_VLAN_PVID_CTRL_MASK ,0 ); +} +/* * rtl8365mb_vlan_port_get_framefilter() - Get the ingress frame filtering mode * for a port
drivers/net/dsa/realtek/rtl8365mb_vlan.c rtl8365mb_vlan_port_set_framefilter(struct realtek_priv *priv, · line 859
Quoted 5 lines
drivers/net/dsa/realtek/rtl8365mb_vlan.c +2
-0@@ -809,6 +855,68 @@ rtl8365mb_vlan_port_set_framefilter(struct realtek_priv *priv, val); } +/* +* rtl8365mb_vlan_pvid_port_set_direct() - Configure a port's PVID as a raw
The term "direct" doesn't give me much meaning. Since it has essentially the same signature, it should simply be a clean, family-specific implementation (same goes for the other functions).
Best regards,
Luiz
Luiz Angelo Daros de Luca
maintainerRe: [PATCH net-next v7 09/10] net: dsa: realtek: rtl8365mb: make L2/LUT access work on family D
In reply to Mieczyslaw NalewajQuoted 19 lines
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 at0x0A32, used as the per-port EFID register on family C, is the LUT aging timer on family D, so writing an EFID there corrupts it.
- In the table access interface, the SPA field is 3 bits wide and the address register is 12 bits wide, with no address extension bit.
- Only ports 0..7 are present in the LUT and there is noFLUSH_PORT_EXTregister.Teach the table and L2 code about these differences, selecting the layout at runtime with
rtl8365mb_get_family(). Family C behaviour is unchanged.Specifically:
Quoted 13 lines
-
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)serialisers behind*_any()wrappers, pass the proper entry size to the table layer, reject ports above 7, report SVL (FID) entries with VID 0. Use age 6 for static unicast entries as the vendor code does, and look an entry up before deleting it so that a missing entry is not allocated by the delete.
-rtl8365mb_main: makeport_set_efid()a no-op on family D, add a LUT init step that clearsIPMC_HASHandBCAM_DISABLEand programs the aging timer, and do not advertisefdb_isolationormax_num_bridges. Traffic between bridges is then isolated by the port isolation masks only.
So, family D does not have EFID support? I'm curious how this will work in the FDB table when you have two bridges using the same VLAN and receiving traffic from the same MAC address. On family C and earlier, the L2 table uses both EFID and FID/VID as lookup keys. Without EFID on family D, what are the implications?
The number of EFIDs defines the number of supported bridges. Without EFID, should we limit the number of bridges to 1 (or prevent creating multiple bridges with conflicting VLANs)? Turning a used field or function into a no-op without handling its architectural consequences can lead to subtle bugs.
This highlights why a simple end-user test isn't enough when adding support for a new family. Every feature needs to be tested individually and aligned with the driver changes. I've had the RTL8367R up and running for months, but I'm still testing features and finding bugs (and the support is still incomplete). That's also why the VLAN/FDB offloading patches took so long to get merged. Alvin's original implementation worked well for standard use cases, but covering edge cases and verifying all features required a significant amount of rigorous testing and bug fixing.
Best regards,
Luiz
Re: [PATCH net-next v7 05/10] net: dsa: realtek: rtl8365mb: set and get vlan 4k for family D
In reply to Luiz Angelo Daros de LucaQuoted 5 lines · Luiz Angelo Daros de Luca
This is how I'm structuring it now, though it might migrate to function pointers later. A family check inside a shared function only makes sense for very localized differences. Since family A is shaping up well and family B sits conceptually between A and C,
is_ddoesn't scale well for future variants.
We are completely on the same page here. In the upcoming v10 patchset, I have already migrated to function pointers to handle these family-specific differences cleanly.
I introduced a dedicated struct rtl8365mb_family_info which has made it possible to reduce the use of switch statements:
struct rtl8365mb_family_info {
enum rtl8365mb_family family;
unsigned int num_ports;
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);
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);
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);
};static const struct rtl8365mb_family_info rtl8365mb_family_c = {
.family = RTL8365MB_FAMILY_C,
.num_ports = RTL8365MB_C_MAX_NUM_PORTS,
.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,
.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,
};static const struct rtl8365mb_family_info rtl8365mb_family_d = {
.family = RTL8365MB_FAMILY_D,
.num_ports = RTL8365MB_D_MAX_NUM_PORTS,
.jam_table = rtl8365mb_init_jam_8365mb_vc,
.jam_size = ARRAY_SIZE(rtl8365mb_init_jam_8365mb_vc),
.ext_config_forcemode = rtl8365mb_d_ext_config_forcemode,
.vlan_4k_read = rtl8365mb_d_vlan_4k_read,
.vlan_4k_write = rtl8365mb_d_vlan_4k_write,
.l2_entry_size = RTL8365MB_D_L2_ENTRY_SIZE,
.l2_data_to_uc = rtl8365mb_d_l2_data_to_uc,
.l2_uc_to_data = rtl8365mb_d_l2_uc_to_data,
.l2_data_to_mc = rtl8365mb_d_l2_data_to_mc,
.l2_mc_to_data = rtl8365mb_d_l2_mc_to_data,
};This infrastructure should make it very straightforward to hook up your upcoming Family A support without duplicating logic or bloating the shared functions.
Best regards,
Mieczyslaw