Skip to contentSkip to conversation

net: dsa: Add Airoha AN8855 support

PATCH Superseded Christian Marangi 3 participants 28 messages Sep 28 – Oct 1

Subsystems (8)

v24 of 25 Superseded Latest is v25 →

lore
Share & tools
lore
#0 lore raw

v24 cover net: dsa: Add Airoha AN8855 support

This series add the initial support for the Airoha AN8855 Switch.

It's a 5 port Gigabit Switch with SGMII/HSGMII upstream port.

This is starting to get in the wild and there are already some router having this switch chip.

MT7530 is generalized with reg fields to a shared library to reduce code duplication and reuse all the logic for AN8855.

There is this special thing where PHY needs to be calibrated with values from the switch efuse. (the thing have a whole cpu timer and MCU)

Given the double usage of PHY and Switch accessor, a special handling is used with registering a mdio-regmap bus for each internal PHY.

From v8 Driver is now evaluated with Kernel selftest scripts for DSA:

Additional info about the test bridge_vlan_aware.sh.

It was discovered that the Airoha Switch (and probably the Mediatek one that produce the same test results) hardcode checking for 802.1ad when the port is configured in VLAN-Aware mode (aka Security mode).

In such mode, both 802.1q and 802.1ad TPID are checked, hence the bridge_vlan_aware.sh test fails as packets with 802.1ad TPID are rejected (in the case where a wrong VLAN ID is forwarded)

This was confirmed by Airoha and multiple try were done to try to workaround this problem. No solution were found to this as ACL mechanism can't work on receiving packets and the Switch doesn't support turning off this.

The current driver is in use from 4 month on OpenWrt with all kind of scenario confirming working in VLAN bridge. By tweaking the bridge_vlan_aware.sh test with setting the TPID to 0x9100, the test correctly pass as packets gets classified as untagged and the default PVID applied. It's also confirmed that switch correctly parse the 802.1ad tag and make the packet pass only when allowed by VLAN table rules.

Output local_termination.sh
TEST: lan2: Unicast IPv4 to primary MAC address [ OK ]
TEST: lan2: Unicast IPv4 to macvlan MAC address [ OK ]
TEST: lan2: Unicast IPv4 to unknown MAC address [ OK ]
TEST: lan2: Unicast IPv4 to unknown MAC address, promisc [ OK ]
TEST: lan2: Unicast IPv4 to unknown MAC address, allmulti [ OK ]
TEST: lan2: Multicast IPv4 to joined group [ OK ]
TEST: lan2: Multicast IPv4 to unknown group [XFAIL]
reception succeeded, but should have failed
TEST: lan2: Multicast IPv4 to unknown group, promisc [ OK ]
TEST: lan2: Multicast IPv4 to unknown group, allmulti [ OK ]
TEST: lan2: Multicast IPv6 to joined group [ OK ]
TEST: lan2: Multicast IPv6 to unknown group [XFAIL]
reception succeeded, but should have failed
TEST: lan2: Multicast IPv6 to unknown group, promisc [ OK ]
TEST: lan2: Multicast IPv6 to unknown group, allmulti [ OK ]
TEST: lan2: 1588v2 over L2 transport, Sync [ OK ]
TEST: lan2: 1588v2 over L2 transport, Follow-Up [ OK ]
TEST: lan2: 1588v2 over L2 transport, Peer Delay Request [ OK ]
TEST: lan2: 1588v2 over IPv4, Sync [FAIL]
reception failed
TEST: lan2: 1588v2 over IPv4, Follow-Up [FAIL]
reception failed
TEST: lan2: 1588v2 over IPv4, Peer Delay Request [FAIL]
reception failed
TEST: lan2: 1588v2 over IPv6, Sync [FAIL]
reception failed
TEST: lan2: 1588v2 over IPv6, Follow-Up [FAIL]
reception failed
TEST: lan2: 1588v2 over IPv6, Peer Delay Request [FAIL]
reception failed
TEST: vlan_filtering=0 bridge: Unicast IPv4 to primary MAC address [ OK ]
TEST: vlan_filtering=0 bridge: Unicast IPv4 to macvlan MAC address [ OK ]
TEST: vlan_filtering=0 bridge: Unicast IPv4 to unknown MAC address [ OK ]
TEST: vlan_filtering=0 bridge: Unicast IPv4 to unknown MAC address, promisc [ OK ]
TEST: vlan_filtering=0 bridge: Unicast IPv4 to unknown MAC address, allmulti [ OK ]
TEST: vlan_filtering=0 bridge: Multicast IPv4 to joined group [ OK ]
TEST: vlan_filtering=0 bridge: Multicast IPv4 to unknown group [XFAIL]
reception succeeded, but should have failed
TEST: vlan_filtering=0 bridge: Multicast IPv4 to unknown group, promisc [ OK ]
TEST: vlan_filtering=0 bridge: Multicast IPv4 to unknown group, allmulti [ OK ]
TEST: vlan_filtering=0 bridge: Multicast IPv6 to joined group [ OK ]
TEST: vlan_filtering=0 bridge: Multicast IPv6 to unknown group [XFAIL]
reception succeeded, but should have failed
TEST: vlan_filtering=0 bridge: Multicast IPv6 to unknown group, promisc [ OK ]
TEST: vlan_filtering=0 bridge: Multicast IPv6 to unknown group, allmulti [ OK ]
TEST: vlan_filtering=1 bridge: Unicast IPv4 to primary MAC address [ OK ]
TEST: vlan_filtering=1 bridge: Unicast IPv4 to macvlan MAC address [ OK ]
TEST: vlan_filtering=1 bridge: Unicast IPv4 to unknown MAC address [ OK ]
TEST: vlan_filtering=1 bridge: Unicast IPv4 to unknown MAC address, promisc [ OK ]
TEST: vlan_filtering=1 bridge: Unicast IPv4 to unknown MAC address, allmulti [ OK ]
TEST: vlan_filtering=1 bridge: Multicast IPv4 to joined group [ OK ]
TEST: vlan_filtering=1 bridge: Multicast IPv4 to unknown group [XFAIL]
reception succeeded, but should have failed
TEST: vlan_filtering=1 bridge: Multicast IPv4 to unknown group, promisc [ OK ]
TEST: vlan_filtering=1 bridge: Multicast IPv4 to unknown group, allmulti [ OK ]
TEST: vlan_filtering=1 bridge: Multicast IPv6 to joined group [ OK ]
TEST: vlan_filtering=1 bridge: Multicast IPv6 to unknown group [XFAIL]
reception succeeded, but should have failed
TEST: vlan_filtering=1 bridge: Multicast IPv6 to unknown group, promisc [ OK ]
TEST: vlan_filtering=1 bridge: Multicast IPv6 to unknown group, allmulti [ OK ]
TEST: VLAN upper: Unicast IPv4 to primary MAC address [ OK ]
TEST: VLAN upper: Unicast IPv4 to macvlan MAC address [ OK ]
TEST: VLAN upper: Unicast IPv4 to unknown MAC address [ OK ]
TEST: VLAN upper: Unicast IPv4 to unknown MAC address, promisc [ OK ]
TEST: VLAN upper: Unicast IPv4 to unknown MAC address, allmulti [ OK ]
TEST: VLAN upper: Multicast IPv4 to joined group [ OK ]
TEST: VLAN upper: Multicast IPv4 to unknown group [XFAIL]
reception succeeded, but should have failed
TEST: VLAN upper: Multicast IPv4 to unknown group, promisc [ OK ]
TEST: VLAN upper: Multicast IPv4 to unknown group, allmulti [ OK ]
TEST: VLAN upper: Multicast IPv6 to joined group [ OK ]
TEST: VLAN upper: Multicast IPv6 to unknown group [XFAIL]
reception succeeded, but should have failed
TEST: VLAN upper: Multicast IPv6 to unknown group, promisc [ OK ]
TEST: VLAN upper: Multicast IPv6 to unknown group, allmulti [ OK ]
TEST: VLAN upper: 1588v2 over L2 transport, Sync [ OK ]
TEST: VLAN upper: 1588v2 over L2 transport, Follow-Up [FAIL]
reception failed
TEST: VLAN upper: 1588v2 over L2 transport, Peer Delay Request [ OK ]
TEST: VLAN upper: 1588v2 over IPv4, Sync [FAIL]
reception failed
;TEST: VLAN upper: 1588v2 over IPv4, Follow-Up [FAIL]
reception failed
TEST: VLAN upper: 1588v2 over IPv4, Peer Delay Request [FAIL]
reception failed
TEST: VLAN upper: 1588v2 over IPv6, Sync [FAIL]
reception failed
TEST: VLAN upper: 1588v2 over IPv6, Follow-Up [FAIL]
reception failed
TEST: VLAN upper: 1588v2 over IPv6, Peer Delay Request [FAIL]
reception failed
TEST: VLAN over vlan_filtering=0 bridged port: Unicast IPv4 to primary MAC address [ OK ]
TEST: VLAN over vlan_filtering=0 bridged port: Unicast IPv4 to macvlan MAC address [ OK ]
TEST: VLAN over vlan_filtering=0 bridged port: Unicast IPv4 to unknown MAC address [ OK ]
TEST: VLAN over vlan_filtering=0 bridged port: Unicast IPv4 to unknown MAC address, promisc [ OK ]
TEST: VLAN over vlan_filtering=0 bridged port: Unicast IPv4 to unknown MAC address, allmulti [ OK ]
TEST: VLAN over vlan_filtering=0 bridged port: Multicast IPv4 to joined group [ OK ]
TEST: VLAN over vlan_filtering=0 bridged port: Multicast IPv4 to unknown group [XFAIL]
reception succeeded, but should have failed
TEST: VLAN over vlan_filtering=0 bridged port: Multicast IPv4 to unknown group, promisc [ OK ]
TEST: VLAN over vlan_filtering=0 bridged port: Multicast IPv4 to unknown group, allmulti [ OK ]
TEST: VLAN over vlan_filtering=0 bridged port: Multicast IPv6 to joined group [ OK ]
TEST: VLAN over vlan_filtering=0 bridged port: Multicast IPv6 to unknown group [XFAIL]
reception succeeded, but should have failed
TEST: VLAN over vlan_filtering=0 bridged port: Multicast IPv6 to unknown group, promisc [ OK ]
TEST: VLAN over vlan_filtering=0 bridged port: Multicast IPv6 to unknown group, allmulti [ OK ]
TEST: VLAN over vlan_filtering=0 bridged port: 1588v2 over L2 transport, Sync [ OK ]
TEST: VLAN over vlan_filtering=0 bridged port: 1588v2 over L2 transport, Follow-Up [ OK ]
TEST: VLAN over vlan_filtering=0 bridged port: 1588v2 over L2 transport, Peer Delay Request [ OK ]
TEST: VLAN over vlan_filtering=0 bridged port: 1588v2 over IPv4, Sync [FAIL]
reception failed
TEST: VLAN over vlan_filtering=0 bridged port: 1588v2 over IPv4, Follow-Up [FAIL]
reception failed
TEST: VLAN over vlan_filtering=0 bridged port: 1588v2 over IPv4, Peer Delay Request [FAIL]
reception failed
TEST: VLAN over vlan_filtering=0 bridged port: 1588v2 over IPv6, Sync [FAIL]
reception failed
TEST: VLAN over vlan_filtering=0 bridged port: 1588v2 over IPv6, Follow-Up [FAIL]
reception failed
TEST: VLAN over vlan_filtering=0 bridged port: 1588v2 over IPv6, Peer Delay Request [FAIL]
reception failed
TEST: VLAN over vlan_filtering=1 bridged port: Unicast IPv4 to primary MAC address [ OK ]
TEST: VLAN over vlan_filtering=1 bridged port: Unicast IPv4 to macvlan MAC address [ OK ]
TEST: VLAN over vlan_filtering=1 bridged port: Unicast IPv4 to unknown MAC address [FAIL]
reception succeeded, but should have failed
TEST: VLAN over vlan_filtering=1 bridged port: Unicast IPv4 to unknown MAC address, promisc [ OK ]
TEST: VLAN over vlan_filtering=1 bridged port: Unicast IPv4 to unknown MAC address, allmulti [FAIL]
reception succeeded, but should have failed
TEST: VLAN over vlan_filtering=1 bridged port: Multicast IPv4 to joined group [ OK ]
TEST: VLAN over vlan_filtering=1 bridged port: Multicast IPv4 to unknown group [XFAIL]
reception succeeded, but should have failed
TEST: VLAN over vlan_filtering=1 bridged port: Multicast IPv4 to unknown group, promisc [ OK ]
TEST: VLAN over vlan_filtering=1 bridged port: Multicast IPv4 to unknown group, allmulti [ OK ]
TEST: VLAN over vlan_filtering=1 bridged port: Multicast IPv6 to joined group [ OK ]
TEST: VLAN over vlan_filtering=1 bridged port: Multicast IPv6 to unknown group [XFAIL]
reception succeeded, but should have failed
TEST: VLAN over vlan_filtering=1 bridged port: Multicast IPv6 to unknown group, promisc [ OK ]
TEST: VLAN over vlan_filtering=1 bridged port: Multicast IPv6 to unknown group, allmulti [ OK ]
TEST: VLAN over vlan_filtering=1 bridged port: 1588v2 over L2 transport, Sync [ OK ]
TEST: VLAN over vlan_filtering=1 bridged port: 1588v2 over L2 transport, Follow-Up [ OK ]
TEST: VLAN over vlan_filtering=1 bridged port: 1588v2 over L2 transport, Peer Delay Request [ OK ]
TEST: VLAN over vlan_filtering=1 bridged port: 1588v2 over IPv4, Sync [FAIL]
reception failed
TEST: VLAN over vlan_filtering=1 bridged port: 1588v2 over IPv4, Follow-Up [FAIL]
reception failed
TEST: VLAN over vlan_filtering=1 bridged port: 1588v2 over IPv4, Peer Delay Request [FAIL]
reception failed
TEST: VLAN over vlan_filtering=1 bridged port: 1588v2 over IPv6, Sync [FAIL]
reception failed
TEST: VLAN over vlan_filtering=1 bridged port: 1588v2 over IPv6, Follow-Up [FAIL]
reception failed
TEST: VLAN over vlan_filtering=1 bridged port: 1588v2 over IPv6, Peer Delay Request [FAIL]
reception failed
TEST: VLAN over vlan_filtering=0 bridge: Unicast IPv4 to primary MAC address [ OK ]
TEST: VLAN over vlan_filtering=0 bridge: Unicast IPv4 to macvlan MAC address [ OK ]
TEST: VLAN over vlan_filtering=0 bridge: Unicast IPv4 to unknown MAC address [ OK ]
TEST: VLAN over vlan_filtering=0 bridge: Unicast IPv4 to unknown MAC address, promisc [ OK ]
TEST: VLAN over vlan_filtering=0 bridge: Unicast IPv4 to unknown MAC address, allmulti [ OK ]
TEST: VLAN over vlan_filtering=0 bridge: Multicast IPv4 to joined group [ OK ]
TEST: VLAN over vlan_filtering=0 bridge: Multicast IPv4 to unknown group [XFAIL]
reception succeeded, but should have failed
TEST: VLAN over vlan_filtering=0 bridge: Multicast IPv4 to unknown group, promisc [ OK ]
TEST: VLAN over vlan_filtering=0 bridge: Multicast IPv4 to unknown group, allmulti [ OK ]
TEST: VLAN over vlan_filtering=0 bridge: Multicast IPv6 to joined group [ OK ]
TEST: VLAN over vlan_filtering=0 bridge: Multicast IPv6 to unknown group [XFAIL]
reception succeeded, but should have failed
TEST: VLAN over vlan_filtering=0 bridge: Multicast IPv6 to unknown group, promisc [ OK ]
TEST: VLAN over vlan_filtering=0 bridge: Multicast IPv6 to unknown group, allmulti [ OK ]
TEST: VLAN over vlan_filtering=1 bridge: Unicast IPv4 to primary MAC address [ OK ]
TEST: VLAN over vlan_filtering=1 bridge: Unicast IPv4 to macvlan MAC address [ OK ]
TEST: VLAN over vlan_filtering=1 bridge: Unicast IPv4 to unknown MAC address [ OK ]
TEST: VLAN over vlan_filtering=1 bridge: Unicast IPv4 to unknown MAC address, promisc [ OK ]
TEST: VLAN over vlan_filtering=1 bridge: Unicast IPv4 to unknown MAC address, allmulti [ OK ]
TEST: VLAN over vlan_filtering=1 bridge: Multicast IPv4 to joined group [ OK ]
TEST: VLAN over vlan_filtering=1 bridge: Multicast IPv4 to unknown group [XFAIL]
reception succeeded, but should have failed
TEST: VLAN over vlan_filtering=1 bridge: Multicast IPv4 to unknown group, promisc [ OK ]
TEST: VLAN over vlan_filtering=1 bridge: Multicast IPv4 to unknown group, allmulti [ OK ]
TEST: VLAN over vlan_filtering=1 bridge: Multicast IPv6 to joined group [ OK ]
TEST: VLAN over vlan_filtering=1 bridge: Multicast IPv6 to unknown group [XFAIL]
reception succeeded, but should have failed
TEST: VLAN over vlan_filtering=1 bridge: Multicast IPv6 to unknown group, promisc [ OK ]
TEST: VLAN over vlan_filtering=1 bridge: Multicast IPv6 to unknown group, allmulti [ OK ]

Output bridge_vlan_unaware.sh
TEST: ping [ OK ]
TEST: ping6 [ OK ]
TEST: FDB learning [ OK ]
TEST: Unknown unicast flood [ OK ]
TEST: Unregistered multicast flood [ OK ]

Output bridge_vlan_aware.sh
TEST: ping [ OK ]
TEST: ping6 [ OK ]
TEST: FDB learning [ OK ]
TEST: Unknown unicast flood [ OK ]
TEST: Unregistered multicast flood [ OK ]
INFO: Add and delete a VLAN on bridge port lan2
TEST: ping [ OK ]
TEST: ping6 [ OK ]
TEST: Externally learned FDB entry - ageing & roaming [ OK ]
TEST: FDB entry in PVID for VLAN-tagged with other TPID [FAIL]
FDB entry was not learned when it should
TEST: Reception of VLAN with other TPID as untagged [FAIL]
Packet was not forwarded when it should
TEST: Reception of VLAN with other TPID as untagged (no PVID) [FAIL]
Packet was forwarded when should not

Changes v24:
- Add review tag by Andrew
- Fix missing multicast from generalize patch
- Add patch to move mediatek drivers to dedicated driver
- Zero out saved timer on LPI disable
- Correctl check regfiled on FDB read
- Fix MFD leaked of node

Changes v23:
- Add review by tag for DT patch
- Fix MFD fwnode handle release
- Better handle LPI handling for AN8855
- Add additional kconfig for AN8855
- Use shorter name for virtual phy bus

Changes v22:
- Improve MFD lock handling for phy bus
- Prevent devm crash on removal for MFD driver
- Address VAWD bug reported by bot
- Fix wrong msb for MIB for AN8855 driver
- Better handle kconfig dependency
- Read tx_lpi under lock

Changes v21:
- Rebase on top of net-next
- Drop megred patch from Daniel
- Address suggestion reported by bot for MFD driver
- Drop reset for MFD driver
- Reset FDB and VLAN data on writing
- Fix not correct PCR matrix in port enable
- Add ID_EN7528 fields
- Fix MAC address learning SA_DIS
- Fix MAC address FDB read swapped
- Fix mib reset logic
- Fix AN8855 missing regfiled
- Fix AN8855 ethtool stats access
- Improve tx lpi timer for AN8855
- Improve MFD Documentation patch
Changes v20:
- Address all the typo pointed out by bot
- Make documentation schema more consistent
- Address some concern for the mfd driver from bot
- Fix some conversion problem for the generalization patch
Changes v19:
- Rebase on top of net-next
- Rework with shared function from mt7530 driver
- Add dependency for mt7530 lock
- Fix some define typo for AN8855
Changes v18:
- Fix configurting typo
- Init ret in MFD driver
Changes v17:
- Drop nvmem patch (subset merged and present in linux-next)
- Fix wrong Documentation patch for MFD
- Address reviews for MFD driver
- Rework MTK tag to slipt for Airoha name
Changes v16:
- Rebase on top of net-next
- Drop PBUS implementation (Airoha said that it's not OK to use it)
- Convert to simple mdio-regmap and split regmap
- Fix typo for some define (AND8855 -> AN8855)
Changes v15:
- Rebase on top of net-next
- Drop regmap MDIO patch (in favor of PBUS)
- Implement MDIO PBUS and rework MDIO driver/MFD
- Reimplement EEE support
- Add some check for regmap from MFD
- Move to single regmap and add comments with all findings
Changes v14:
- Move MAITAINERS entry to dedicated commit (make it easier for cross subsystem merge)
- Pack variables in trap function
- Add additional patch for reported difference from MTK tag
Changes v13:
- Reimplement tx_lpi OPs
- Rework mdio-regmap to internally encode/decode address
- Fix error in Documentation
- Drop ext-surge property (assume calibration with declared nvmem cell)
- Fix comments from Lee on MFD driver
- Improve print error and drop extra space in DSA driver
Changes v12:
- Update on top of net-next
- Add additional info on conver-letter about slefttests and HW limitation
- Introduce mdio-regmap generalization for multiple address
- Drop dev flags and define PHY calibration in PHY node directly
Changes v11:
- Address reviews from Christophe (spell mistake + dev_err_probe)
- Fix kconfig dependency for MFD driver (depends on MDIO_DEVICE instead of MDIO) (indirectly fix link error for mdio APIs)
- Fix copy-paste error for MFD driver of_table
- Fix compilation error for PHY (move NVMEM to .config)
- Drop unneeded NVMEM node from MDIO example schema (from Andrew)
- Adapt MFD example schema to MDIO reg property restrictions
Changes v10:
- Entire rework to MFD + split to MDIO, EFUSE, SWITCH separate drivers
- Drop EEE OPs (while Russell finish RFC for EEE changes)
- Use new pcs_inpand OPs
- Drop AN restart function and move to pcs_config
- Enable assisted_learning and disable CPU learn (preparation for fdb_isolation)
- Move EFUSE read in Internal PHY driver to .config to handle EPROBE_DEFER (needed now that NVMEM driver is register externally instead of internally to switch node)
Changes v9:
- Error out on using 5G speed as currently not supported
- Add missing MAC_2500FD in phylink mac_capabilities
- Add comment and improve if condition for an8855_phylink_mac_config Changes v8:
- Add port Fast Age support
- Add support for Port Isolation
- Use correct register for Learning Disable
- Add support for Ageing Time OP
- Set default PVID to 0 by default
- Add mdb OPs
- Add port change MTU
- Fix support for Upper VLAN
Changes v7:
- Fix devm_dsa_register_switch wrong export symbol
Changes v6:
- Drop standard MIB and handle with ethtool OPs (as requested by Jakub)
- Cosmetic: use bool instead of 0 or 1
Changes v5:
- Add devm_dsa_register_switch() patch
- Add Reviewed-by tag for DT patch
Changes v4:
- Set regmap readable_table static (mute compilation warning)
- Add support for port_bridge flags (LEARNING, FLOOD)
- Reset fdb struct in fdb_dump
- Drop support_asym_pause in port_enable
- Add define for get_phy_flags
- Fix bug for port not inititially part of a bridge
(in an8855_setup the port matrix was always cleared but
the CPU port was never initially added)
- Disable learning and flood for user port by default
- Set CPU port to flood and learning by default
- Correctly AND force duplex and flow control in an8855_phylink_mac_link_up
- Drop RGMII from pcs_config
- Check ret in "Disable AN if not in autoneg"
- Use devm_mutex_init
- Fix typo for AN8855_PORT_CHECK_MODE
- Better define AN8855_STP_LISTENING = AN8855_STP_BLOCKING
- Fix typo in AN8855_PHY_EN_DOWN_SHIFT
- Use paged helper for PHY
- Skip calibration in config_init if priv not defined
Changes v3:
- Out of RFC
- Switch PHY code to select_page API
- Better describe masks and bits in PHY driver for ADC register
- Drop raw values and use define for mii read/write
- Switch to absolute PHY address
- Replace raw values with mask and bits for pcs_config
- Fix typo for ext-surge property name
- Drop support for relocating Switch base PHY address on the bus
Changes v2:
- Drop mutex guard patch
- Drop guard usage in DSA driver
- Use __mdiobus_write/read
- Check return condition and return errors for mii read/write
- Fix wrong logic for EEE
- Fix link_down (don't force link down with autoneg)
- Fix forcing speed on sgmii autoneg
- Better document link speed for sgmii reg
- Use standard define for sgmii reg
- Imlement nvmem support to expose switch EFUSE
- Rework PHY calibration with the use of NVMEM producer/consumer
- Update DT with new NVMEM property
- Move aneg validation for 2500-basex in pcs_config
- Move r50Ohm table and function to PHY driver

Christian Marangi (10):
dt-bindings: net: dsa: Document support for Airoha AN8855 DSA Switch
dt-bindings: net: Document support for AN8855 Switch Internal PHY
dt-bindings: mfd: Document support for Airoha AN8855 Switch SoC
mfd: an8855: Add support for Airoha AN8855 Switch
net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY
net: dsa: tag_mtk: add Airoha variant usage of this TAG
MAINTAINERS: add myself as maintainer for Airoha AN8855 Switch
net: dsa: move mediatek DSA driver in dedicated directory
net: dsa: mt7530: generalize and move common function to lib module
net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver

 .../bindings/mfd/airoha,an8855.yaml           |  176 ++
 .../bindings/net/airoha,an8855-phy.yaml       |   83 +
 .../net/dsa/airoha,an8855-switch.yaml         |   86 +
 MAINTAINERS                                   |   22 +-
 drivers/mfd/Kconfig                           |   14 +
 drivers/mfd/Makefile                          |    1 +
 drivers/mfd/airoha-an8855.c                   |  579 ++++++
 drivers/net/dsa/Kconfig                       |   45 +-
 drivers/net/dsa/Makefile                      |    5 +-
 drivers/net/dsa/mediatek/Kconfig              |   59 +
 drivers/net/dsa/mediatek/Makefile             |    7 +
 drivers/net/dsa/mediatek/an8855.c             | 1741 +++++++++++++++++
 drivers/net/dsa/mediatek/an8855.h             |  755 +++++++
 drivers/net/dsa/mediatek/mt7530-lib.c         | 1156 +++++++++++
 drivers/net/dsa/mediatek/mt7530-lib.h         |  413 ++++
 drivers/net/dsa/{ => mediatek}/mt7530-mdio.c  |    4 +
 drivers/net/dsa/{ => mediatek}/mt7530-mmio.c  |    4 +
 drivers/net/dsa/{ => mediatek}/mt7530.c       | 1366 +++----------
 drivers/net/dsa/{ => mediatek}/mt7530.h       |  256 +--
 drivers/net/dsa/{ => mediatek}/mt7628.c       |    0
 drivers/net/phy/Kconfig                       |    6 +
 drivers/net/phy/Makefile                      |    1 +
 drivers/net/phy/air_an8855.c                  |  275 +++
 include/net/dsa.h                             |    2 +
 net/dsa/Kconfig                               |   11 +
 net/dsa/Makefile                              |    2 +-
 net/dsa/tag_mtk.c                             |   36 +-
 27 files changed, 5808 insertions(+), 1297 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mfd/airoha,an8855.yaml
 create mode 100644 Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml
 create mode 100644 Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml
 create mode 100644 drivers/mfd/airoha-an8855.c
 create mode 100644 drivers/net/dsa/mediatek/Kconfig
 create mode 100644 drivers/net/dsa/mediatek/Makefile
 create mode 100644 drivers/net/dsa/mediatek/an8855.c
 create mode 100644 drivers/net/dsa/mediatek/an8855.h
 create mode 100644 drivers/net/dsa/mediatek/mt7530-lib.c
 create mode 100644 drivers/net/dsa/mediatek/mt7530-lib.h
 rename drivers/net/dsa/{ => mediatek}/mt7530-mdio.c (99%)
 rename drivers/net/dsa/{ => mediatek}/mt7530-mmio.c (97%)
 rename drivers/net/dsa/{ => mediatek}/mt7530.c (63%)
 rename drivers/net/dsa/{ => mediatek}/mt7530.h (81%)
 rename drivers/net/dsa/{ => mediatek}/mt7628.c (100%)
 create mode 100644 drivers/net/phy/air_an8855.c
Signature · 1 line
2.55.0
#1 lore raw

PATCH v24 1/10 dt-bindings: net: dsa: Document support for Airoha AN8855 DSA Switch

Document support for Airoha AN8855 5-port Gigabit Switch.

It does expose the 5 Internal PHYs on the MDIO bus and each port can access the Switch register space by configuring the PHY page.

---
 .../net/dsa/airoha,an8855-switch.yaml         | 86 +++++++++++++++++++
 1 file changed, 86 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml
Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml new file +86 -0
new file mode 100644
index 000000000000..5ad9b9e13983
@@ -0,0 +1,86 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/dsa/airoha,an8855-switch.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Airoha AN8855 Gigabit Switch
+
+maintainers:
+  - Christian Marangi <[email protected]>
+
+description: >
+  Airoha AN8855 is a 5-port Gigabit Switch.
+
+  It does expose the 5 Internal PHYs on the MDIO bus and each port
+  can access the Switch register space by configuring the PHY page.
+
+$ref: dsa.yaml#/$defs/ethernet-ports
+
+properties:
+  compatible:
+    const: airoha,an8855-switch
+
+required:
+  - compatible
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    ethernet-switch {
+        compatible = "airoha,an8855-switch";
+
+        ports {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            port@0 {
+                reg = <0>;
+                label = "lan1";
+                phy-mode = "internal";
+                phy-handle = <&internal_phy1>;
+            };
+
+            port@1 {
+                reg = <1>;
+                label = "lan2";
+                phy-mode = "internal";
+                phy-handle = <&internal_phy2>;
+            };
+
+            port@2 {
+                reg = <2>;
+                label = "lan3";
+                phy-mode = "internal";
+                phy-handle = <&internal_phy3>;
+            };
+
+            port@3 {
+                reg = <3>;
+                label = "lan4";
+                phy-mode = "internal";
+                phy-handle = <&internal_phy4>;
+            };
+
+            port@4 {
+                reg = <4>;
+                label = "wan";
+                phy-mode = "internal";
+                phy-handle = <&internal_phy5>;
+            };
+
+            port@5 {
+                reg = <5>;
+                label = "cpu";
+                ethernet = <&gmac0>;
+                phy-mode = "2500base-x";
+
+                fixed-link {
+                    speed = <2500>;
+                    full-duplex;
+                    pause;
+                };
+            };
+        };
+    };
Signature · 1 line
2.55.0
#2 lore raw

Re: [PATCH net-next v24 01/10] dt-bindings: net: dsa: Document support for Airoha AN8855 DSA Switch

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] dt-bindings: unresolved phandles in example break dt_binding_check --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] dt-bindings: unresolved phandles in example break dt_binding_check --

commit 940a9845cb44d5578faba1549988a5be5ce97b7a
Author: Christian Marangi <[email protected]>

dt-bindings: net: dsa: Document support for Airoha AN8855 DSA Switch

This commit documents the device tree bindings for the Airoha AN8855 5-port Gigabit Switch. It provides an example configuration demonstrating how the switch ports map to internal PHYs.

Quoted 5 lines
Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml new file +0 -0
new file mode 100644
index 0000000000000..5ad9b9e139831

[ ... ]

Quoted 4 lines
Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml new file +4 -0
+examples:
+  - |
+    ethernet-switch {
+        compatible = "airoha,an8855-switch";

Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml line 42

Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml new file +10 -0
+
+        ports {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            port@0 {
+                reg = <0>;
+                label = "lan1";
+                phy-mode = "internal";
+                phy-handle = <&internal_phy1>;

[Severity: Low]
Will this examples block fail dt_binding_check compilation?

The examples block in Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml uses node references like &internal_phy1 through &internal_phy5 for the phy-handle properties. However, these node labels are never defined anywhere within the example snippet.

When make dt_binding_check runs, dtc extracts the examples section into a standalone DTS file and compiles it. Won't these undefined references cause a fatal reference error during compilation?

Quoted 1 line

+ };

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

Re: [PATCH net-next v24 01/10] dt-bindings: net: dsa: Document support for Airoha AN8855 DSA Switch

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

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

Low priority / nit picks for your consideration:

- [Low] Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml…

--

dt-bindings: net: dsa: Document support for Airoha AN8855 DSA Switch

This commit adds a YAML binding for the Airoha AN8855 5-port Gigabit Switch. The binding references the generic DSA ethernet-ports definition and adds a single compatible string.

Quoted 5 lines
Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml new file +0 -0
new file mode 100644
index 0000000000000..5ad9b9e139831

[ ... ]

Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml line 18

Quoted 7 lines
Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml new file +7 -0
+description: >
+  Airoha AN8855 is a 5-port Gigabit Switch.
+
+  It does expose the 5 Internal PHYs on the MDIO bus and each port
+  can access the Switch register space by configuring the PHY page.
+
+$ref: dsa.yaml#/$defs/ethernet-ports

[Severity: Low]
Should the port unit addresses be limited to what the hardware has?

This binding inherits the generic port node pattern from dsa.yaml#/$defs/ethernet-ports without narrowing it:

Documentation/devicetree/bindings/net/dsa/dsa.yaml:

          "^(ethernet-)?port@[0-9a-f]+$":

The AN8855 has 6 ports. Ports 0-4 are user ports with internal PHYs and port 5 is the CPU port, and the driver later in the series sets ds->num_ports = AN8855_NUM_PORTS.

As a result, a DT with port@7 or port@1f still passes dt_binding_check and dtbs_check. It is only rejected at probe time, and then the whole switch fails to probe:

net/dsa/dsa.c:dsa_switch_parse_ports_of() {
    ...
		if (reg >= ds->num_ports) {
			dev_err(ds->dev, "port %pOF index %u exceeds num_ports (%u)\n",
    ...
}

Other DSA bindings with a fixed port count narrow the pattern under
ports: patternProperties. For example, mediatek,mt7530.yaml and qca8k.yaml use "^(ethernet-)?port@[0-6]$", and renesas,rzn1-a5psw.yaml uses "^(ethernet-)?port@[0-4]$".

Would something like "^(ethernet-)?port@[0-5]$" make sense here? This file is unchanged at the end of the series.

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928194511.41878-1-ansuelsmth%40gmail.com
#4 lore raw

PATCH v24 2/10 dt-bindings: net: Document support for AN8855 Switch Internal PHY

In reply to Christian Marangi

Document support for AN8855 Switch Internal PHY.

Airoha AN8855 is a 5-port Gigabit Switch that expose the Internal PHYs on the MDIO bus.

Each PHY might need to be calibrated to correctly work with the use of the eFUSE provided by the Switch SoC. This can be enabled by defining in the PHY node the NVMEM cell properties.

---
 .../bindings/net/airoha,an8855-phy.yaml       | 83 +++++++++++++++++++
 1 file changed, 83 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml
Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml new file +83 -0
new file mode 100644
index 000000000000..d2f86116badf
@@ -0,0 +1,83 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/airoha,an8855-phy.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Airoha AN8855 Switch Internal PHY
+
+maintainers:
+  - Christian Marangi <[email protected]>
+
+description: >
+  Airoha AN8855 is a 5-port Gigabit Switch that expose the Internal
+  PHYs on the MDIO bus.
+
+  Each PHY might need to be calibrated to correctly work with the
+  use of the eFUSE provided by the Switch SoC.
+
+allOf:
+  - $ref: ethernet-phy.yaml#
+
+select:
+  properties:
+    compatible:
+      contains:
+        enum:
+          - ethernet-phy-idc0ff.0410
+  required:
+    - compatible
+
+properties:
+  reg:
+    maxItems: 1
+
+  nvmem-cells:
+    items:
+      - description: phandle to SoC eFUSE tx_a
+      - description: phandle to SoC eFUSE tx_b
+      - description: phandle to SoC eFUSE tx_c
+      - description: phandle to SoC eFUSE tx_d
+
+  nvmem-cell-names:
+    items:
+      - const: tx_a
+      - const: tx_b
+      - const: tx_c
+      - const: tx_d
+
+required:
+  - compatible
+  - reg
+
+dependentRequired:
+  nvmem-cells: [ nvmem-cell-names ]
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    mdio {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        ethernet-phy@1 {
+            compatible = "ethernet-phy-idc0ff.0410",
+                         "ethernet-phy-ieee802.3-c45";
+
+            reg = <1>;
+        };
+
+        ethernet-phy@2 {
+            compatible = "ethernet-phy-idc0ff.0410",
+                         "ethernet-phy-ieee802.3-c45";
+
+            reg = <2>;
+
+            nvmem-cells = <&shift_sel_port0_tx_a>,
+                          <&shift_sel_port0_tx_b>,
+                          <&shift_sel_port0_tx_c>,
+                          <&shift_sel_port0_tx_d>;
+            nvmem-cell-names = "tx_a", "tx_b", "tx_c", "tx_d";
+        };
+    };
Signature · 1 line
2.55.0
#5 lore raw

Re: [PATCH net-next v24 02/10] dt-bindings: net: Document support for AN8855 Switch Internal PHY

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 10 lines

Document support for AN8855 Switch Internal PHY.

Airoha AN8855 is a 5-port Gigabit Switch that expose the Internal PHYs on the MDIO bus.

Each PHY might need to be calibrated to correctly work with the use of the eFUSE provided by the Switch SoC. This can be enabled by defining in the PHY node the NVMEM cell properties.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#6 lore raw

Re: [PATCH net-next v24 02/10] dt-bindings: net: Document support for AN8855 Switch Internal PHY

In reply to Christian Marangi
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

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

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

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

- [Medium] Both PHY nodes in the example in Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml list…
- [Low] The example in Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml gives…

--

dt-bindings: net: Document support for AN8855 Switch Internal PHY

This patch adds a DT binding for the internal PHYs of the Airoha AN8855 5-port Gigabit Switch, which are exposed on the MDIO bus. Each PHY can optionally reference four eFUSE NVMEM cells (tx_a..tx_d) that hold TX calibration data.

Quoted 5 lines
Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml new file +0 -0
new file mode 100644
index 0000000000000..d2f86116badf4

[ ... ]

Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml line 66

Quoted 9 lines
Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml new file +9 -0
+examples:
+  - |
+    mdio {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        ethernet-phy@1 {
+            compatible = "ethernet-phy-idc0ff.0410",
+                         "ethernet-phy-ieee802.3-c45";

[Severity: Medium]
Should these PHYs be described as "ethernet-phy-ieee802.3-c22" and not c45? Both example nodes use the c45 compatible.

In fwnode_mdiobus_register_phy(), the c45 compatible makes phylib ignore the explicit PHY ID and probe the device using Clause 45:

drivers/net/mdio/fwnode_mdio.c:fwnode_mdiobus_register_phy() {
    ...
    is_c45 = fwnode_device_is_compatible(child, "ethernet-phy-ieee802.3-c45");
    if (is_c45 || fwnode_get_phy_id(child, &phy_id))
        phy = get_phy_device(bus, addr, is_c45);
    ...
}

Each AN8855 PHY is on a per-PHY bus that an8855_phy_bus_register() creates via devm_mdio_regmap_register(). That bus provides only C22 accessors:

drivers/net/mdio/mdio-regmap.c:devm_mdio_regmap_register() {
    ...
    mii->read = mdio_regmap_read_c22;
    mii->write = mdio_regmap_write_c22;
    ...
}

That means get_phy_c45_ids()->get_phy_c45_devs_in_pkg() gets -EOPNOTSUPP and returns -EIO. The PHY registration then fails, and an8855_core_probe() in drivers/mfd/airoha-an8855.c goes to err_put_fwnodes. As a result, neither the PHYs nor the switch/efuse MFD cells are registered.

The PHY driver in drivers/net/phy/air_an8855.c matches the C22 ID with PHY_ID_MATCH_EXACT(0xc0ff0410) and uses C22 paged access. Also, the MFD binding example in the same series (airoha,an8855.yaml) uses "ethernet-phy-ieee802.3-c22" for these PHYs.

If a board DT follows this example, won't the whole AN8855 probe fail?

Quoted 4 lines
Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml new file +4 -0
+
+            reg = <1>;
+        };
+

Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml line 80

Quoted 10 lines
Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml new file +10 -0
+        ethernet-phy@2 {
+            compatible = "ethernet-phy-idc0ff.0410",
+                         "ethernet-phy-ieee802.3-c45";
+
+            reg = <2>;
+
+            nvmem-cells = <&shift_sel_port0_tx_a>,
+                          <&shift_sel_port0_tx_b>,
+                          <&shift_sel_port0_tx_c>,
+                          <&shift_sel_port0_tx_d>;

[Severity: Low]
Is ethernet-phy@2 meant to get port 0's calibration cells here, while ethernet-phy@1 gets none?

an8855_phy_bus_register() in drivers/mfd/airoha-an8855.c maps the MDIO address to a port relative to the switch address:

    phy_offset = addr - priv->switch_addr;
    if (phy_offset >= AN8855_MAX_PHY_PORT)
        return -EINVAL;

Because ethernet-phy@1 is present, switch_addr has to be 0 or 1. That makes address 2 port 1 or port 2, and never port 0.

The eFUSE binding (airoha,an8855-efuse.yaml) has a separate tx_a..tx_d set for each port, for example shift_sel_port0_tx_a@c and shift_sel_port1_tx_a@1c. The MFD binding example in the same series wires internal_phy1 (reg 1) to shift_sel_port0_* and internal_phy2 (reg 2) to shift_sel_port1_*, which does not match this example.

A DT copied from this example would have an8855_probe() read port 0's R50-ohm values. an8855_config_init() would then write them into the second PHY's AN8855_PHY_R50OHM_RSEL_TX_AB/CD registers, and the first PHY would stay uncalibrated. No error would be reported.

Should the cells move to ethernet-phy@1, or should ethernet-phy@2 use the shift_sel_port1_* cells?

Quoted 3 lines
Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml new file +3 -0
+            nvmem-cell-names = "tx_a", "tx_b", "tx_c", "tx_d";
+        };
+    };
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928194511.41878-1-ansuelsmth%40gmail.com
#7 lore raw

PATCH v24 3/10 dt-bindings: mfd: Document support for Airoha AN8855 Switch SoC

In reply to Christian Marangi

Document support for Airoha AN8855 Switch SoC. This SoC expose various peripherals like an Ethernet Switch, a NVMEM provider and Ethernet PHYs.

It does also support i2c and timers but those are not currently supported/used.

---
 .../bindings/mfd/airoha,an8855.yaml           | 176 ++++++++++++++++++
 1 file changed, 176 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/airoha,an8855.yaml
Documentation/devicetree/bindings/mfd/airoha,an8855.yaml new file +176 -0
new file mode 100644
index 000000000000..48127e956c96
@@ -0,0 +1,176 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/airoha,an8855.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Airoha AN8855 Switch SoC
+
+maintainers:
+  - Christian Marangi <[email protected]>
+
+description: >
+  Airoha AN8855 Switch is a SoC that expose various peripherals like an
+  Ethernet Switch, a NVMEM provider and Ethernet PHYs.
+
+  It does also support i2c and timers but those are not currently
+  supported/used.
+
+properties:
+  compatible:
+    const: airoha,an8855
+
+  reg:
+    maxItems: 1
+
+  reset-gpios:
+    maxItems: 1
+
+  efuse:
+    type: object
+    $ref: /schemas/nvmem/airoha,an8855-efuse.yaml
+    description: EFUSE exposed by the Airoha AN8855 SoC
+
+  ethernet-switch:
+    type: object
+    $ref: /schemas/net/dsa/airoha,an8855-switch.yaml
+    description: Switch exposed by the Airoha AN8855 SoC
+
+  mdio:
+    type: object
+    $ref: /schemas/net/mdio.yaml#
+    description: MDIO exposed by the Airoha AN8855 SoC
+    unevaluatedProperties: false
+
+required:
+  - compatible
+  - reg
+  - mdio
+  - ethernet-switch
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+
+    mdio {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        soc@1 {
+            compatible = "airoha,an8855";
+            reg = <1>;
+
+            reset-gpios = <&pio 39 GPIO_ACTIVE_HIGH>;
+
+            efuse {
+                compatible = "airoha,an8855-efuse";
+
+                #nvmem-cell-cells = <0>;
+
+                nvmem-layout {
+                    compatible = "fixed-layout";
+                    #address-cells = <1>;
+                    #size-cells = <1>;
+
+                    shift_sel_port0_tx_a: shift-sel-port0-tx-a@c {
+                       reg = <0xc 0x4>;
+                    };
+
+                    shift_sel_port0_tx_b: shift-sel-port0-tx-b@10 {
+                        reg = <0x10 0x4>;
+                    };
+
+                    shift_sel_port0_tx_c: shift-sel-port0-tx-c@14 {
+                        reg = <0x14 0x4>;
+                    };
+
+                    shift_sel_port0_tx_d: shift-sel-port0-tx-d@18 {
+                       reg = <0x18 0x4>;
+                    };
+
+                    shift_sel_port1_tx_a: shift-sel-port1-tx-a@1c {
+                        reg = <0x1c 0x4>;
+                    };
+
+                    shift_sel_port1_tx_b: shift-sel-port1-tx-b@20 {
+                        reg = <0x20 0x4>;
+                    };
+
+                    shift_sel_port1_tx_c: shift-sel-port1-tx-c@24 {
+                       reg = <0x24 0x4>;
+                    };
+
+                    shift_sel_port1_tx_d: shift-sel-port1-tx-d@28 {
+                        reg = <0x28 0x4>;
+                    };
+                };
+            };
+
+            ethernet-switch {
+                compatible = "airoha,an8855-switch";
+
+                ports {
+                    #address-cells = <1>;
+                    #size-cells = <0>;
+
+                    port@0 {
+                        reg = <0>;
+                        label = "lan1";
+                        phy-mode = "internal";
+                        phy-handle = <&internal_phy1>;
+                    };
+
+                    port@1 {
+                        reg = <1>;
+                        label = "lan2";
+                        phy-mode = "internal";
+                        phy-handle = <&internal_phy2>;
+                    };
+
+                    port@5 {
+                        reg = <5>;
+                        label = "cpu";
+                        ethernet = <&gmac0>;
+                        phy-mode = "2500base-x";
+
+                        fixed-link {
+                            speed = <2500>;
+                            full-duplex;
+                            pause;
+                        };
+                    };
+                };
+            };
+
+            mdio {
+                #address-cells = <1>;
+                #size-cells = <0>;
+
+                internal_phy1: ethernet-phy@1 {
+                  compatible = "ethernet-phy-idc0ff.0410",
+                               "ethernet-phy-ieee802.3-c22";
+                  reg = <1>;
+
+                  nvmem-cells = <&shift_sel_port0_tx_a>,
+                      <&shift_sel_port0_tx_b>,
+                      <&shift_sel_port0_tx_c>,
+                      <&shift_sel_port0_tx_d>;
+                  nvmem-cell-names = "tx_a", "tx_b", "tx_c", "tx_d";
+                };
+
+                internal_phy2: ethernet-phy@2 {
+                  compatible = "ethernet-phy-idc0ff.0410",
+                               "ethernet-phy-ieee802.3-c22";
+                  reg = <2>;
+
+                  nvmem-cells = <&shift_sel_port1_tx_a>,
+                      <&shift_sel_port1_tx_b>,
+                      <&shift_sel_port1_tx_c>,
+                      <&shift_sel_port1_tx_d>;
+                  nvmem-cell-names = "tx_a", "tx_b", "tx_c", "tx_d";
+                };
+            };
+        };
+    };
Signature · 1 line
2.55.0
#8 lore raw

Re: [PATCH net-next v24 03/10] dt-bindings: mfd: Document support for Airoha AN8855 Switch SoC

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines

Document support for Airoha AN8855 Switch SoC. This SoC expose various peripherals like an Ethernet Switch, a NVMEM provider and Ethernet PHYs.

It does also support i2c and timers but those are not currently supported/used.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#9 lore raw

Re: [PATCH net-next v24 03/10] dt-bindings: mfd: Document support for Airoha AN8855 Switch SoC

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

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

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

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

- [Medium] The series documents two different MDIO clauses for the same AN8855 internal PHY (ethernet-phy-idc0ff.0410).
- [Medium] The binding defines reset-gpios with only 'maxItems: 1' (airoha,an8855.yaml lines 26-27).
- [Low] The two binding examples in the series map the per-port eFUSE TX calibration cells to PHY addresses in incompatible ways.

--

dt-bindings: mfd: Document support for Airoha AN8855 Switch SoC

This adds a new YAML binding for the Airoha AN8855 Switch SoC MFD node. The node has efuse, ethernet-switch and mdio children and an optional reset-gpios property.

Quoted 6 lines
Documentation/devicetree/bindings/mfd/airoha,an8855.yaml new file +0 -0
new file mode 100644
index 0000000000000..48127e956c965
@@ -0,0 +1,176 @@

[ ... ]

Documentation/devicetree/bindings/mfd/airoha,an8855.yaml line 27

Quoted 5 lines
Documentation/devicetree/bindings/mfd/airoha,an8855.yaml new file +5 -0
+  reg:
+    maxItems: 1
+
+  reset-gpios:
+    maxItems: 1

[Severity: Medium]
The reset-gpios property doesn't describe the pin or its active level. The only example uses:

    reset-gpios = <&pio 39 GPIO_ACTIVE_HIGH>;

Does anything in the series read this property? drivers/mfd/airoha-an8855.c includes linux/gpio/consumer.h but never calls gpiod_get*(). drivers/net/dsa/mediatek/an8855.c has no reset GPIO handling either.

The MDIO core doesn't handle it for this node. The airoha,an8855 node is registered as a non-PHY mdio_device, and the reset GPIO is only requested for PHYs:

drivers/net/phy/mdio_device.c:mdiobus_register_device() {
    ...
    if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) {
        err = mdio_device_register_reset(mdiodev);
    ...
}

If the board's GPIO default holds RESET_N asserted, would the chip stay in reset and cause an8855_read_switch_id() to fail?

Could the binding also state the expected polarity? When a consumer is added, there are two options:

- It follows gpiod semantics (1 = assert). Then an ACTIVE_HIGH flag on an active-low RESET_N would hold the chip in reset.
- It follows the inverted mt7530 convention. Then the DT ABI is tied to an inverted flag.

I couldn't confirm the AN8855 pin polarity from a datasheet or from in-tree code.

[ ... ]

Documentation/devicetree/bindings/mfd/airoha,an8855.yaml line 153

Quoted 7 lines
Documentation/devicetree/bindings/mfd/airoha,an8855.yaml new file +7 -0
+            mdio {
+                #address-cells = <1>;
+                #size-cells = <0>;
+
+                internal_phy1: ethernet-phy@1 {
+                  compatible = "ethernet-phy-idc0ff.0410",
+                               "ethernet-phy-ieee802.3-c22";

[Severity: Medium]
This example declares the internal PHYs as Clause 22. The PHY binding added earlier in the series ("dt-bindings: net: Document support for AN8855 Switch Internal PHY") uses Clause 45 for the same PHY ID in Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml:

    compatible = "ethernet-phy-idc0ff.0410",
                 "ethernet-phy-ieee802.3-c45";

Which one is intended?

With the MFD driver added later in the series, only c22 seems to work. The bus comes from devm_mdio_regmap_register(), which only sets C22 accessors:

drivers/net/mdio/mdio-regmap.c:devm_mdio_regmap_register() {
    ...
    mii->read = mdio_regmap_read_c22;
    mii->write = mdio_regmap_write_c22;
    ...
}

If a board DT copies the PHY binding example, fwnode_mdiobus_register_phy() sets is_c45 and the probe goes:

an8855_core_probe()
fwnode_mdiobus_register_phy()

    get_phy_device(bus, addr, true)
      get_phy_c45_ids()
        get_phy_c45_devs_in_pkg()
          __mdiobus_c45_read()   <- -EOPNOTSUPP, no read_c45

get_phy_c45_ids() turns this into -EIO. an8855_core_probe() then takes the err_put_fwnodes path, and none of the switch, efuse or PHY functions come up.

dt_binding_check won't catch this, because ethernet-phy.yaml accepts both compatibles. Should the PHY binding example use ethernet-phy-ieee802.3-c22 to match this one?

Quoted 10 lines
Documentation/devicetree/bindings/mfd/airoha,an8855.yaml new file +10 -0
+                  reg = <1>;
+
+                  nvmem-cells = <&shift_sel_port0_tx_a>,
+                      <&shift_sel_port0_tx_b>,
+                      <&shift_sel_port0_tx_c>,
+                      <&shift_sel_port0_tx_d>;
+                  nvmem-cell-names = "tx_a", "tx_b", "tx_c", "tx_d";
+                };
+
+                internal_phy2: ethernet-phy@2 {

Documentation/devicetree/bindings/mfd/airoha,an8855.yaml line 173

Quoted 10 lines
Documentation/devicetree/bindings/mfd/airoha,an8855.yaml new file +10 -0
+                  compatible = "ethernet-phy-idc0ff.0410",
+                               "ethernet-phy-ieee802.3-c22";
+                  reg = <2>;
+
+                  nvmem-cells = <&shift_sel_port1_tx_a>,
+                      <&shift_sel_port1_tx_b>,
+                      <&shift_sel_port1_tx_c>,
+                      <&shift_sel_port1_tx_d>;
+                  nvmem-cell-names = "tx_a", "tx_b", "tx_c", "tx_d";
+                };

[Severity: Low]
Here, ethernet-phy@1 (the phy-handle of port@0) gets the shift_sel_port0_tx_* cells and ethernet-phy@2 gets shift_sel_port1_tx_*. The example in net/airoha,an8855-phy.yaml is different: ethernet-phy@2 references shift_sel_port0_tx_* and ethernet-phy@1 has no nvmem-cells.

The MFD driver treats the switch address as port 0's PHY:

drivers/mfd/airoha-an8855.c:an8855_phy_bus_register() {
    ...
    phy_offset = addr - priv->switch_addr;
    if (phy_offset >= AN8855_MAX_PHY_PORT)
        return -EINVAL;
    ...
}

So when ethernet-phy@1 exists, ethernet-phy@2 can't be port 0. The PHY driver in drivers/net/phy/air_an8855.c applies whatever tx_a..tx_d cells the node references, with no cross-check.

Would a DT that follows the PHY binding example program port 0's TX calibration into a different port? This example looks like the consistent one. Should the PHY binding example be changed to match it?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928194511.41878-1-ansuelsmth%40gmail.com
#10 lore raw

PATCH v24 4/10 mfd: an8855: Add support for Airoha AN8855 Switch

In reply to Christian Marangi

Add support for Airoha AN8855 Switch that provide support for a DSA switch and a NVMEM provider.

Also make use of the mdio-regmap driver and register a regmap for each internal PHY of the switch.
This is needed to handle the double usage of the PHYs as both PHY and Switch accessor.

---
 drivers/mfd/Kconfig         |  14 +
 drivers/mfd/Makefile        |   1 +
 drivers/mfd/airoha-an8855.c | 579 ++++++++++++++++++++++++++++++++++++
 3 files changed, 594 insertions(+)
 create mode 100644 drivers/mfd/airoha-an8855.c
drivers/mfd/Kconfig +14 -0
index e4fd4572472f..afbdcec0fce8 100644
@@ -54,6 +54,20 @@ config MFD_ALTERA_SYSMGR
 	  using regmap_mmio accesses for ARM32 parts and SMC calls to
 	  EL3 for ARM64 parts.
 
+config MFD_AIROHA_AN8855
+	tristate "Airoha AN8855 Switch Core"
+	select MFD_CORE
+	select REGMAP
+	select PHYLIB
+	select MDIO_REGMAP
+	depends on NETDEVICES && OF
+	help
+	  Support for the Airoha AN8855 Switch Core. This is an SoC
+	  that provides various peripherals, to count, i2c, an Ethrnet
+	  Switch, a CPU timer, GPIO, eFUSE.
+
+	  Currently it provides a DSA switch and a NVMEM provider.
+
 config MFD_ACT8945A
 	tristate "Active-semi ACT8945A"
 	select MFD_CORE
drivers/mfd/Makefile +1 -0
index 72d3944b0ad8..484127dba2ad 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_MFD_88PM860X)	+= 88pm860x.o
 obj-$(CONFIG_MFD_88PM800)	+= 88pm800.o 88pm80x.o
 obj-$(CONFIG_MFD_88PM805)	+= 88pm805.o 88pm80x.o
 obj-$(CONFIG_MFD_88PM886_PMIC)	+= 88pm886.o
+obj-$(CONFIG_MFD_AIROHA_AN8855)	+= airoha-an8855.o
 obj-$(CONFIG_MFD_ACT8945A)	+= act8945a.o
 obj-$(CONFIG_MFD_SM501)		+= sm501.o
 obj-$(CONFIG_ARCH_BCM2835)	+= bcm2835-pm.o
drivers/mfd/airoha-an8855.c new file +579 -0

579 lines not on this page · raw message

Signature · 1 line
2.55.0
#11 lore raw

Re: [PATCH net-next v24 04/10] mfd: an8855: Add support for Airoha AN8855 Switch

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] mfd: airoha-an8855: violates MFD naming conventions for private structures --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] mfd: airoha-an8855: violates MFD naming conventions for private structures --

commit 74bc32f30a5a15b059bad776dd3ef21cad2cb09f
Author: Christian Marangi <[email protected]>

mfd: an8855: Add support for Airoha AN8855 Switch

This commit adds support for the Airoha AN8855 Switch, which includes a DSA switch and an NVMEM provider. It also uses the mdio-regmap driver to register a regmap for each internal PHY.

Quoted 5 lines
drivers/mfd/airoha-an8855.c new file +0 -0
new file mode 100644
index 0000000000000..cd5791ef436d9

[ ... ]

drivers/mfd/airoha-an8855.c line 57

Quoted 4 lines
drivers/mfd/airoha-an8855.c new file +4 -0
+#define AN8855_MAX_PHY_PORT		5
+
+struct an8855_core_priv {
+	struct mii_bus *bus;

[Severity: Low]
Does this struct name violate the MFD subsystem naming conventions? The MFD guidelines require private data structure names to prefer using the device name directly (e.g., struct an8855) rather than using generic suffixes like priv or info.

Quoted 9 lines
drivers/mfd/airoha-an8855.c new file +9 -0
+	struct mii_bus *phy_bus;
+	unsigned int switch_addr;
+	u16 current_page;
+};
+
+struct an8855_phy_priv {
+	u8 addr;
+	struct an8855_core_priv *core;
+};

[ ... ]

drivers/mfd/airoha-an8855.c line 495

Quoted 5 lines
drivers/mfd/airoha-an8855.c new file +5 -0
+static int an8855_core_probe(struct mdio_device *mdiodev)
+{
+	struct an8855_phy_bus phy_bus_infos[AN8855_MAX_PHY_PORT] = { };
+	struct device *dev = &mdiodev->dev;
+	struct an8855_core_priv *priv;

[Severity: Low]
Does this variable name adhere to the MFD guidelines? The guidelines suggest using ddata for the variable instance instead of a generic name like priv in an8855_core_probe() and other driver functions.

Quoted 3 lines
drivers/mfd/airoha-an8855.c new file +3 -0
+	struct regmap *regmap;
+	int num_phys;
+	int i, ret;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#12 lore raw

Re: [PATCH net-next v24 04/10] mfd: an8855: Add support for Airoha AN8855 Switch

In reply to Christian Marangi
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider.

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

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

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

- [Medium] This patch adds the MFD_AIROHA_AN8855 symbol and registers an 'airoha,an8855-efuse' MFD cell.
- [Medium] The MFD binding (airoha,an8855.yaml) documents reset-gpios on the AN8855 core node, and its example uses one.
- [Medium] The PHY binding example (Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml)…
- [Medium] an8855_phy_bus_register() checks the DT PHY 'reg' only as an offset from switch_addr (phy_offset = addr - switch_addr < 5), never…
- [Low] an8855_mdio_register() uses goto-based cleanup and scope-based cleanup in the same function.
- [Low] an8855_core_probe() writes 0 to AN8855_RG_GPHY_AFE_PWD (line 534), which powers up the analog front end of all internal GPHYs.
- [Low] mfd: airoha-an8855: violates MFD naming conventions for private structures

--

mfd: an8855: Add support for Airoha AN8855 Switch

This adds an MFD core driver for the Airoha AN8855 switch. It registers efuse (NVMEM) and DSA switch child cells. It also creates an mdio-regmap bus and a regmap for each internal PHY, so those PHYs can serve both as PHYs and as the path for switch register access.

Quoted 11 lines
drivers/mfd/Kconfig +3 -0
index e4fd4572472f9..afbdcec0fce8f 100644
@@ -54,6 +54,20 @@ config MFD_ALTERA_SYSMGR
 	  using regmap_mmio accesses for ARM32 parts and SMC calls to
 	  EL3 for ARM64 parts.
 
+config MFD_AIROHA_AN8855
+	tristate "Airoha AN8855 Switch Core"
+	select MFD_CORE

drivers/mfd/Kconfig config MFD_ALTERA_SYSMGR · line 69

Quoted 10 lines
drivers/mfd/Kconfig +10 -0
+	select REGMAP
+	select PHYLIB
+	select MDIO_REGMAP
+	depends on NETDEVICES && OF
+	help
+	  Support for the Airoha AN8855 Switch Core. This is an SoC
+	  that provides various peripherals, to count, i2c, an Ethrnet
+	  Switch, a CPU timer, GPIO, eFUSE.
+
+	  Currently it provides a DSA switch and a NVMEM provider.

[Severity: Medium]
Now that this symbol exists, should NVMEM_AN8855_EFUSE in drivers/nvmem/Kconfig get its dependency back?

Commit 4796eaafd6a1 ("nvmem: an8855: drop an unused Kconfig symbol") removed "depends on MFD_AIROHA_AN8855 || COMPILE_TEST" only because this symbol did not exist yet. The nvmem entry still has just:

config NVMEM_AN8855_EFUSE

	...
	depends on COMPILE_TEST

drivers/nvmem/Kconfig is not changed anywhere else in the series.

Without COMPILE_TEST, can any driver bind to the "airoha,an8855-efuse" cell registered from an8855_cells? If not, the PHY calibration nvmem-cells in the bindings can't be resolved. nvmem_cell_read_u32() in air_an8855.c would then fail whenever a PHY node has nvmem-cells.

That seems to contradict the "NVMEM provider" described here and in the commit message.

Quoted 6 lines
drivers/mfd/airoha-an8855.c new file +0 -0
new file mode 100644
index 0000000000000..cd5791ef436d9
@@ -0,0 +1,579 @@

[ ... ]

Quoted 4 lines
drivers/mfd/airoha-an8855.c new file +4 -0
+static int an8855_phy_bus_register(struct device *dev, struct an8855_core_priv *priv,
+				   struct device_node *phy_np,
+				   struct an8855_phy_bus *phy_bus_info)
+{

[ ... ]

drivers/mfd/airoha-an8855.c line 420

Quoted 7 lines
drivers/mfd/airoha-an8855.c new file +7 -0
+	ret = of_property_read_u32(phy_np, "reg", &addr);
+	if (ret)
+		return ret;
+
+	phy_offset = addr - priv->switch_addr;
+	if (phy_offset >= AN8855_MAX_PHY_PORT)
+		return -EINVAL;

[Severity: Medium]
Is the absolute addr ever checked against PHY_MAX_ADDR?

This only checks the offset from switch_addr. With the switch at MDIO address 28-31, a DT "reg" of 32-35 gets through. an8855_core_probe() then passes it to fwnode_mdiobus_register_phy(), which skips the of_mdio_parse_addr() check that the normal OF path does.

With an explicit ethernet-phy-idXXXX.XXXX compatible, as in the binding examples, can this index past the 32-entry arrays in struct mii_bus?

fwnode_mdiobus_phy_device_register()

    mdio->irq[addr] = rc;

mdiobus_register_device()

    if (mdiodev->bus->mdio_map[mdiodev->addr])
        return -EBUSY;
    ...
    mdiodev->bus->mdio_map[mdiodev->addr] = mdiodev;

phy_device_create() also reads bus->irq[addr], and the broken-turn-around handling computes 1 << addr.

On 64-bit, irq[34] overlays the low word of bus->reset_gpiod. After an interrupt write, the mdio_map[] check returns -EBUSY. mdiobus_unregister() on the unwind path then calls gpiod_set_value_cansleep() on the corrupted pointer.

On 32-bit, mdio_map[33] overlays phy_ignore_ta_mask. The PHY ends up in a slot that mdiobus_unregister() never walks.

Such a DT would already violate mdio.yaml (reg max 31). Would an "addr >= PHY_MAX_ADDR" check here still be worth adding?

[ ... ]

Quoted 6 lines
drivers/mfd/airoha-an8855.c new file +6 -0
+	for_each_available_child_of_node_scoped(mdio_np, phy_np) {
+		if (i >= AN8855_MAX_PHY_PORT) {
+			ret = -EINVAL;
+			goto exit;
+		}
+

drivers/mfd/airoha-an8855.c line 480

Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10 -0
+		ret = an8855_phy_bus_register(dev, priv, phy_np,
+					      &phy_bus_infos[i]);
+		if (ret)
+			goto exit;
+
+		i++;
+	}
+
+exit:
+	of_node_put(mdio_np);

[Severity: Low]
This isn't a bug, but an8855_mdio_register() mixes goto-based cleanup with the scope-based __free(device_node) from for_each_available_child_of_node_scoped(). include/linux/cleanup.h asks that a routine use one style or the other, not both.

Nothing leaks today, because leaving the loop scope drops phy_np. Could mdio_np be declared with __free(device_node), and the error paths return directly after putting the fwnodes?

[ ... ]

drivers/mfd/airoha-an8855.c line 524

Quoted 4 lines
drivers/mfd/airoha-an8855.c new file +4 -0
+	/* Reset PHY page for switch address */
+	mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED);
+	ret = an8855_mii_set_page(priv, priv->switch_addr,
+				  AN8855_PHY_PAGE_STANDARD);

[Severity: Medium]
Should reset-gpios be handled before this first access?

The airoha,an8855.yaml binding documents reset-gpios on the core node, and its example uses it. <linux/gpio/consumer.h> is included and AN8855_HWTRAP is defined, but neither is used. an8855_core_probe() goes straight to MDIO accesses, with no reset pulse, settle delay or HWTRAP ready poll.

The MDIO core won't handle it either. mdiobus_register_device() only sets up the reset for PHY devices:

    if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) {
        err = mdio_device_register_reset(mdiodev);

For this plain mdio_device, reset_gpio stays NULL. The DSA driver later in the series doesn't handle reset either.

On a board that leaves the line asserted, wouldn't the AN8855_CREV read fail or return the wrong ID, so the whole device fails to probe? If the line is left deasserted, the chip keeps whatever state the bootloader left.

[ ... ]

drivers/mfd/airoha-an8855.c line 542

Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10 -0
+	/* Release global PHY power down */
+	ret = regmap_write(regmap, AN8855_RG_GPHY_AFE_PWD, 0x0);
+	if (ret)
+		goto err_put_fwnodes;
+
+	/* Register PHYs */
+	for (i = 0; i < num_phys; i++) {
+		ret = fwnode_mdiobus_register_phy(phy_bus_infos[i].bus,
+						  phy_bus_infos[i].node,
+						  phy_bus_infos[i].addr);

[Severity: Medium]
What happens here with a DT written from the PHY binding example? The example in airoha,an8855-phy.yaml uses:

    compatible = "ethernet-phy-idc0ff.0410",
                 "ethernet-phy-ieee802.3-c45";

The bus from devm_mdio_regmap_register() only has C22 accessors:

    mii->read = mdio_regmap_read_c22;
    mii->write = mdio_regmap_write_c22;

When the c45 compatible is present, fwnode_mdiobus_register_phy() probes as C45 even if an explicit PHY ID is given:

    is_c45 = fwnode_device_is_compatible(child, "ethernet-phy-ieee802.3-c45");
    if (is_c45 || fwnode_get_phy_id(child, &phy_id))
        phy = get_phy_device(bus, addr, is_c45);

get_phy_c45_ids() -> mdiobus_c45_read() then fails with -EOPNOTSUPP, and get_phy_device() returns an error. The goto err_put_fwnodes fails the whole probe, so the switch and efuse children are never created.

The MFD binding example uses "-c22", and air_an8855.c uses phy_*_mmd over C22. Should the PHY binding example be changed to match? It is still unchanged at the end of the series.

Quoted 8 lines
drivers/mfd/airoha-an8855.c new file +8 -0
+		fwnode_handle_put(phy_bus_infos[i].node);
+		phy_bus_infos[i].node = NULL;
+
+		if (ret)
+			goto err_put_fwnodes;
+	}
+
+	return devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO, an8855_cells,

drivers/mfd/airoha-an8855.c line 560

Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10 -0
+				    ARRAY_SIZE(an8855_cells), NULL, 0,
+				    NULL);
+
+err_put_fwnodes:
+	for (i = 0; i < num_phys; i++)
+		if (phy_bus_infos[i].node)
+			fwnode_handle_put(phy_bus_infos[i].node);
+
+	return ret;
+}

[Severity: Low]
Should the GPHYs be put back into power-down when probe fails?

AN8855_RG_GPHY_AFE_PWD is cleared before the PHYs are registered and before devm_mfd_add_devices() runs. If either step fails, err_put_fwnodes only drops the fwnode references. A devm_mfd_add_devices() error is returned directly.

an8855_core_driver also has no .remove. mdio_probe() does nothing on failure because reset_gpio is NULL here.

After a failed probe or an unbind, would the internal PHYs stay powered and be able to bring links up with no driver owning them?

[ ... ]

Quoted 570 lines
drivers/mfd/airoha-an8855.c new file +569 -0
@@ -0,0 +1,579 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Core driver for Airoha AN8855 Switch
+ *
+ * Copyright (C) 2024 Christian Marangi <[email protected]>
+ */
+
+#include <linux/bitfield.h>
+#include <linux/fwnode_mdio.h>
+#include <linux/gpio/consumer.h>
+#include <linux/mfd/core.h>
+#include <linux/mdio.h>
+#include <linux/mdio/mdio-regmap.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/phy.h>
+#include <linux/regmap.h>
+
+/* Register for HW trap status */
+#define AN8855_HWTRAP			0x1000009c
+
+/*
+ * Register of the Switch ID
+ * (called Project ID in Documentation)
+ */
+#define AN8855_CREV			0x10005000
+#define   AN8855_ID			0x8855 /* Switch ID */
+
+/* Register for GPHY Power Down
+ * Used to Toggle the Gigabit PHY power and enable them.
+ */
+#define AN8855_RG_GPHY_AFE_PWD		0x1028c840
+
+/* MII Registers */
+#define AN8855_PHY_SELECT_PAGE		0x1f
+#define   AN8855_PHY_PAGE		GENMASK(2, 0)
+#define   AN8855_PHY_PAGE_STANDARD	FIELD_PREP_CONST(AN8855_PHY_PAGE, 0x0)
+#define   AN8855_PHY_PAGE_EXTENDED_1	FIELD_PREP_CONST(AN8855_PHY_PAGE, 0x1)
+#define   AN8855_PHY_PAGE_EXTENDED_4	FIELD_PREP_CONST(AN8855_PHY_PAGE, 0x4)
+
+/* MII Registers Page 4 */
+#define AN8855_PBUS_MODE		0x10
+#define   AN8855_PBUS_MODE_ADDR_FIXED	0x0
+#define   AN8855_PBUS_MODE_ADDR_INCR	BIT(15)
+#define AN8855_PBUS_WR_ADDR_HIGH	0x11
+#define AN8855_PBUS_WR_ADDR_LOW		0x12
+#define AN8855_PBUS_WR_DATA_HIGH	0x13
+#define AN8855_PBUS_WR_DATA_LOW		0x14
+#define AN8855_PBUS_RD_ADDR_HIGH	0x15
+#define AN8855_PBUS_RD_ADDR_LOW		0x16
+#define AN8855_PBUS_RD_DATA_HIGH	0x17
+#define AN8855_PBUS_RD_DATA_LOW		0x18
+
+#define AN8855_MAX_PHY_PORT		5
+
+struct an8855_core_priv {
+	struct mii_bus *bus;
+	struct mii_bus *phy_bus;
+	unsigned int switch_addr;
+	u16 current_page;
+};
+
+struct an8855_phy_priv {
+	u8 addr;
+	struct an8855_core_priv *core;
+};
+
+struct an8855_phy_bus {
+	struct mii_bus *bus;
+	struct fwnode_handle *node;
+	u8 addr;
+};
+
+static const struct mfd_cell an8855_cells[] = {
+	MFD_CELL_OF("an8855-efuse", NULL, NULL, 0, 0,
+		    "airoha,an8855-efuse"),
+	MFD_CELL_OF("an8855-switch", NULL, NULL, 0, 0,
+		    "airoha,an8855-switch"),
+};
+
+static int an8855_mii_set_page(struct an8855_core_priv *priv, u8 addr,
+			       u8 page) __must_hold(&priv->bus->mdio_lock)
+{
+	struct mii_bus *bus = priv->bus;
+	int ret;
+
+	ret = __mdiobus_write(bus, addr, AN8855_PHY_SELECT_PAGE, page);
+	if (ret) {
+		dev_err_ratelimited(&bus->dev, "failed to set mii page\n");
+		return ret;
+	}
+
+	/* Cache current page if next MII read/write is for Switch page */
+	priv->current_page = page;
+	return 0;
+}
+
+static int an8855_mii_read32(struct mii_bus *bus, u8 phy_id, u32 reg,
+			     u32 *val) __must_hold(&bus->mdio_lock)
+{
+	int lo, hi, ret;
+
+	ret = __mdiobus_write(bus, phy_id, AN8855_PBUS_MODE,
+			      AN8855_PBUS_MODE_ADDR_FIXED);
+	if (ret)
+		goto err;
+
+	ret = __mdiobus_write(bus, phy_id, AN8855_PBUS_RD_ADDR_HIGH,
+			      upper_16_bits(reg));
+	if (ret)
+		goto err;
+
+	ret = __mdiobus_write(bus, phy_id, AN8855_PBUS_RD_ADDR_LOW,
+			      lower_16_bits(reg));
+	if (ret)
+		goto err;
+
+	hi = __mdiobus_read(bus, phy_id, AN8855_PBUS_RD_DATA_HIGH);
+	if (hi < 0) {
+		ret = hi;
+		goto err;
+	}
+
+	lo = __mdiobus_read(bus, phy_id, AN8855_PBUS_RD_DATA_LOW);
+	if (lo < 0) {
+		ret = lo;
+		goto err;
+	}
+
+	*val = ((u32)hi << 16) | lo;
+
+	return 0;
+err:
+	dev_err_ratelimited(&bus->dev, "failed to read register\n");
+	return ret;
+}
+
+/*
+ * Protect concurrent access to phy page if switch address also
+ * expose a PHY.
+ */
+static void an8855_regmap_lock(struct an8855_core_priv *priv)
+{
+	if (priv->phy_bus)
+		mutex_lock(&priv->phy_bus->mdio_lock);
+	mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED);
+}
+
+static void an8855_regmap_unlock(struct an8855_core_priv *priv)
+{
+	mutex_unlock(&priv->bus->mdio_lock);
+	if (priv->phy_bus)
+		mutex_unlock(&priv->phy_bus->mdio_lock);
+}
+
+static int an8855_regmap_read(void *ctx, uint32_t reg, uint32_t *val)
+{
+	struct an8855_core_priv *priv = ctx;
+	struct mii_bus *bus = priv->bus;
+	u16 addr = priv->switch_addr;
+	int ret;
+
+	an8855_regmap_lock(priv);
+	ret = an8855_mii_set_page(priv, addr, AN8855_PHY_PAGE_EXTENDED_4);
+	if (ret < 0)
+		goto exit;
+
+	ret = an8855_mii_read32(bus, addr, reg, val);
+
+exit:
+	an8855_regmap_unlock(priv);
+
+	return ret < 0 ? ret : 0;
+}
+
+static int an8855_mii_write32(struct mii_bus *bus, u8 phy_id, u32 reg,
+			      u32 val) __must_hold(&bus->mdio_lock)
+{
+	int ret;
+
+	ret = __mdiobus_write(bus, phy_id, AN8855_PBUS_MODE,
+			      AN8855_PBUS_MODE_ADDR_FIXED);
+	if (ret)
+		goto err;
+
+	ret = __mdiobus_write(bus, phy_id, AN8855_PBUS_WR_ADDR_HIGH,
+			      upper_16_bits(reg));
+	if (ret)
+		goto err;
+	ret = __mdiobus_write(bus, phy_id, AN8855_PBUS_WR_ADDR_LOW,
+			      lower_16_bits(reg));
+	if (ret)
+		goto err;
+
+	ret = __mdiobus_write(bus, phy_id, AN8855_PBUS_WR_DATA_HIGH,
+			      upper_16_bits(val));
+	if (ret)
+		goto err;
+
+	ret = __mdiobus_write(bus, phy_id, AN8855_PBUS_WR_DATA_LOW,
+			      lower_16_bits(val));
+	if (ret)
+		goto err;
+
+	return 0;
+err:
+	dev_err_ratelimited(&bus->dev,
+			    "failed to write an8855 register\n");
+	return ret;
+}
+
+static int an8855_regmap_write(void *ctx, uint32_t reg, uint32_t val)
+{
+	struct an8855_core_priv *priv = ctx;
+	struct mii_bus *bus = priv->bus;
+	u16 addr = priv->switch_addr;
+	int ret;
+
+	an8855_regmap_lock(priv);
+	ret = an8855_mii_set_page(priv, addr, AN8855_PHY_PAGE_EXTENDED_4);
+	if (ret)
+		goto exit;
+
+	ret = an8855_mii_write32(bus, addr, reg, val);
+
+exit:
+	an8855_regmap_unlock(priv);
+
+	return ret < 0 ? ret : 0;
+}
+
+static int an8855_regmap_update_bits(void *ctx, uint32_t reg, uint32_t mask,
+				     uint32_t write_val)
+{
+	struct an8855_core_priv *priv = ctx;
+	struct mii_bus *bus = priv->bus;
+	u16 addr = priv->switch_addr;
+	u32 val;
+	int ret;
+
+	an8855_regmap_lock(priv);
+	ret = an8855_mii_set_page(priv, addr, AN8855_PHY_PAGE_EXTENDED_4);
+	if (ret)
+		goto exit;
+
+	ret = an8855_mii_read32(bus, addr, reg, &val);
+	if (ret < 0)
+		goto exit;
+
+	val &= ~mask;
+	val |= write_val & mask;
+	ret = an8855_mii_write32(bus, addr, reg, val);
+
+exit:
+	an8855_regmap_unlock(priv);
+
+	return ret < 0 ? ret : 0;
+}
+
+static const struct regmap_range an8855_readable_ranges[] = {
+	regmap_reg_range(0x10000000, 0x10000fff), /* SCU */
+	regmap_reg_range(0x10001000, 0x10001fff), /* RBUS */
+	regmap_reg_range(0x10002000, 0x10002fff), /* MCU */
+	regmap_reg_range(0x10005000, 0x10005fff), /* SYS SCU */
+	regmap_reg_range(0x10007000, 0x10007fff), /* I2C Slave */
+	regmap_reg_range(0x10008000, 0x10008fff), /* I2C Master */
+	regmap_reg_range(0x10009000, 0x10009fff), /* PDMA */
+	regmap_reg_range(0x1000a100, 0x1000a2ff), /* General Purpose Timer */
+	regmap_reg_range(0x1000a200, 0x1000a2ff), /* GPU timer */
+	regmap_reg_range(0x1000a300, 0x1000a3ff), /* GPIO */
+	regmap_reg_range(0x1000a400, 0x1000a5ff), /* EFUSE */
+	regmap_reg_range(0x1000c000, 0x1000cfff), /* GDMP CSR */
+	regmap_reg_range(0x10010000, 0x1001ffff), /* GDMP SRAM */
+	regmap_reg_range(0x10200000, 0x10203fff), /* Switch - ARL Global */
+	regmap_reg_range(0x10204000, 0x10207fff), /* Switch - BMU */
+	regmap_reg_range(0x10208000, 0x1020bfff), /* Switch - ARL Port */
+	regmap_reg_range(0x1020c000, 0x1020cfff), /* Switch - SCH */
+	regmap_reg_range(0x10210000, 0x10213fff), /* Switch - MAC */
+	regmap_reg_range(0x10214000, 0x10217fff), /* Switch - MIB */
+	regmap_reg_range(0x10218000, 0x1021bfff), /* Switch - Port Control */
+	regmap_reg_range(0x1021c000, 0x1021ffff), /* Switch - TOP */
+	regmap_reg_range(0x10220000, 0x1022ffff), /* SerDes */
+	regmap_reg_range(0x10286000, 0x10286fff), /* RG Batcher */
+	regmap_reg_range(0x1028c000, 0x1028ffff), /* ETHER_SYS */
+	regmap_reg_range(0x30000000, 0x37ffffff), /* I2C EEPROM */
+	regmap_reg_range(0x38000000, 0x3fffffff), /* BOOT_ROM */
+	regmap_reg_range(0xa0000000, 0xbfffffff), /* GPHY */
+};
+
+static const struct regmap_access_table an8855_readable_table = {
+	.yes_ranges = an8855_readable_ranges,
+	.n_yes_ranges = ARRAY_SIZE(an8855_readable_ranges),
+};
+
+static const struct regmap_config an8855_regmap_config = {
+	.name = "switch",
+	.reg_bits = 32,
+	.val_bits = 32,
+	.reg_stride = 4,
+	.max_register = 0xbfffffff,
+	.reg_read = an8855_regmap_read,
+	.reg_write = an8855_regmap_write,
+	.reg_update_bits = an8855_regmap_update_bits,
+	.disable_locking = true,
+	.rd_table = &an8855_readable_table,
+};
+
+static int an8855_regmap_phy_reset_page(struct an8855_core_priv *priv,
+					int phy) __must_hold(&priv->bus->mdio_lock)
+{
+	/* Check PHY page only for addr shared with switch */
+	if (phy != priv->switch_addr)
+		return 0;
+
+	/* Don't restore page if it's not set to Switch page */
+	if (priv->current_page != AN8855_PHY_PAGE_EXTENDED_4)
+		return 0;
+
+	/*
+	 * Restore page to 0, PHY might change page right after but that
+	 * will be ignored as it won't be a switch page.
+	 */
+	return an8855_mii_set_page(priv, phy, AN8855_PHY_PAGE_STANDARD);
+}
+
+static int an8855_regmap_phy_read(void *ctx, uint32_t reg, uint32_t *val)
+{
+	struct an8855_phy_priv *priv = ctx;
+	struct an8855_core_priv *core_priv;
+	u32 addr = priv->addr;
+	struct mii_bus *bus;
+	int ret;
+
+	core_priv = priv->core;
+	bus = core_priv->bus;
+
+	mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED);
+	ret = an8855_regmap_phy_reset_page(core_priv, addr);
+	if (ret)
+		goto exit;
+
+	ret = __mdiobus_read(bus, addr, reg);
+	if (ret >= 0)
+		*val = ret;
+
+exit:
+	mutex_unlock(&bus->mdio_lock);
+
+	return ret < 0 ? ret : 0;
+}
+
+static int an8855_regmap_phy_write(void *ctx, uint32_t reg, uint32_t val)
+{
+	struct an8855_phy_priv *priv = ctx;
+	struct an8855_core_priv *core_priv;
+	u32 addr = priv->addr;
+	struct mii_bus *bus;
+	int ret;
+
+	core_priv = priv->core;
+	bus = core_priv->bus;
+
+	mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED);
+	ret = an8855_regmap_phy_reset_page(core_priv, addr);
+	if (ret)
+		goto exit;
+
+	ret = __mdiobus_write(bus, addr, reg, val);
+
+exit:
+	mutex_unlock(&bus->mdio_lock);
+
+	return ret;
+}
+
+static const struct regmap_config an8855_phy_regmap_config = {
+	.reg_bits = 16,
+	.val_bits = 16,
+	.reg_read = an8855_regmap_phy_read,
+	.reg_write = an8855_regmap_phy_write,
+	.disable_locking = true,
+	.max_register = 0x1f,
+};
+
+static int an8855_read_switch_id(struct device *dev, struct regmap *regmap)
+{
+	u32 id;
+	int ret;
+
+	ret = regmap_read(regmap, AN8855_CREV, &id);
+	if (ret)
+		return ret;
+
+	if (id != AN8855_ID) {
+		dev_err(dev, "Detected Switch ID %x but %x was expected\n",
+			id, AN8855_ID);
+		return -ENODEV;
+	}
+
+	return 0;
+}
+
+static int an8855_phy_bus_register(struct device *dev, struct an8855_core_priv *priv,
+				   struct device_node *phy_np,
+				   struct an8855_phy_bus *phy_bus_info)
+{
+	struct mdio_regmap_config mrc = { };
+	struct an8855_phy_priv *phy_priv;
+	struct regmap *regmap;
+	u32 addr, phy_offset;
+	struct mii_bus *bus;
+	int ret;
+
+	ret = of_property_read_u32(phy_np, "reg", &addr);
+	if (ret)
+		return ret;
+
+	phy_offset = addr - priv->switch_addr;
+	if (phy_offset >= AN8855_MAX_PHY_PORT)
+		return -EINVAL;
+
+	phy_priv = devm_kzalloc(dev, sizeof(*phy_priv), GFP_KERNEL);
+	if (!phy_priv)
+		return -ENOMEM;
+
+	phy_priv->addr = addr;
+	phy_priv->core = priv;
+
+	regmap = devm_regmap_init(dev, NULL, phy_priv, &an8855_phy_regmap_config);
+	if (IS_ERR(regmap))
+		return dev_err_probe(dev, PTR_ERR(regmap),
+				     "phy%d regmap initialization failed\n",
+				      addr);
+
+	mrc.regmap = regmap;
+	mrc.parent = dev;
+	mrc.valid_addr = addr;
+	snprintf(mrc.name, MII_BUS_ID_SIZE, "%s-phy%u", dev_name(dev), addr);
+
+	bus = devm_mdio_regmap_register(dev, &mrc);
+	if (IS_ERR(bus))
+		return PTR_ERR(bus);
+
+	if (addr == priv->switch_addr)
+		priv->phy_bus = bus;
+
+	phy_bus_info->bus = bus;
+	phy_bus_info->addr = addr;
+	phy_bus_info->node = fwnode_handle_get(of_fwnode_handle(phy_np));
+
+	return 0;
+}
+
+static int an8855_mdio_register(struct device *dev, struct an8855_core_priv *priv,
+				struct an8855_phy_bus *phy_bus_infos)
+{
+	struct device_node *mdio_np;
+	int ret = 0;
+	int i = 0;
+
+	mdio_np = of_get_child_by_name(dev->of_node, "mdio");
+	if (!mdio_np)
+		return -ENODEV;
+
+	for_each_available_child_of_node_scoped(mdio_np, phy_np) {
+		if (i >= AN8855_MAX_PHY_PORT) {
+			ret = -EINVAL;
+			goto exit;
+		}
+
+		ret = an8855_phy_bus_register(dev, priv, phy_np,
+					      &phy_bus_infos[i]);
+		if (ret)
+			goto exit;
+
+		i++;
+	}
+
+exit:
+	of_node_put(mdio_np);
+	if (ret) {
+		while (i--)
+			fwnode_handle_put(phy_bus_infos[i].node);
+
+		return ret;
+	}
+
+	return i;
+}
+
+static int an8855_core_probe(struct mdio_device *mdiodev)
+{
+	struct an8855_phy_bus phy_bus_infos[AN8855_MAX_PHY_PORT] = { };
+	struct device *dev = &mdiodev->dev;
+	struct an8855_core_priv *priv;
+	struct regmap *regmap;
+	int num_phys;
+	int i, ret;
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	priv->bus = mdiodev->bus;
+	priv->switch_addr = mdiodev->addr;
+	/* No DMA for mdiobus, mute warning for DMA mask not set */
+	dev->dma_mask = &dev->coherent_dma_mask;
+
+	/* Register virtual MDIO for each PHY */
+	num_phys = an8855_mdio_register(dev, priv, phy_bus_infos);
+	if (num_phys < 0)
+		return num_phys;
+
+	regmap = devm_regmap_init(dev, NULL, priv, &an8855_regmap_config);
+	if (IS_ERR(regmap)) {
+		ret = PTR_ERR(regmap);
+		dev_err_probe(dev, ret, "regmap initialization failed\n");
+		goto err_put_fwnodes;
+	}
+
+	/* Reset PHY page for switch address */
+	mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED);
+	ret = an8855_mii_set_page(priv, priv->switch_addr,
+				  AN8855_PHY_PAGE_STANDARD);
+	mutex_unlock(&priv->bus->mdio_lock);
+	if (ret)
+		goto err_put_fwnodes;
+
+	ret = an8855_read_switch_id(dev, regmap);
+	if (ret)
+		goto err_put_fwnodes;
+
+	/* Release global PHY power down */
+	ret = regmap_write(regmap, AN8855_RG_GPHY_AFE_PWD, 0x0);
+	if (ret)
+		goto err_put_fwnodes;
+
+	/* Register PHYs */
+	for (i = 0; i < num_phys; i++) {
+		ret = fwnode_mdiobus_register_phy(phy_bus_infos[i].bus,
+						  phy_bus_infos[i].node,
+						  phy_bus_infos[i].addr);
+		fwnode_handle_put(phy_bus_infos[i].node);
+		phy_bus_infos[i].node = NULL;
+
+		if (ret)
+			goto err_put_fwnodes;
+	}
+
+	return devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO, an8855_cells,
+				    ARRAY_SIZE(an8855_cells), NULL, 0,
+				    NULL);
+
+err_put_fwnodes:
+	for (i = 0; i < num_phys; i++)
+		if (phy_bus_infos[i].node)
+			fwnode_handle_put(phy_bus_infos[i].node);
+
+	return ret;
+}
+
+static const struct of_device_id an8855_core_of_match[] = {
+	{ .compatible = "airoha,an8855" },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, an8855_core_of_match);
+
+static struct mdio_driver an8855_core_driver = {
+	.probe = an8855_core_probe,

drivers/mfd/airoha-an8855.c line 579

Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10 -0
+	.mdiodrv.driver = {
+		.name = "an8855",
+		.of_match_table = an8855_core_of_match,
+	},
+};
+mdio_module_driver(an8855_core_driver);
+
+MODULE_AUTHOR("Christian Marangi <[email protected]>");
+MODULE_DESCRIPTION("Driver for Airoha AN8855");
+MODULE_LICENSE("GPL");

[Severity: Low]
This isn't a functional problem, but the MFD convention is to name the private data structure after the device and to call the instance ddata, rather than using generic names like priv or info.

Here the core state is struct an8855_core_priv, the per-PHY context is struct an8855_phy_priv, and an8855_core_probe(), the switch regmap callbacks and an8855_phy_bus_register() all name the instance priv. In an8855_regmap_phy_read() and an8855_regmap_phy_write(), priv is the PHY context while core_priv is the core state, which makes it easy to mix up which structure a given priv refers to.

Could struct an8855_core_priv be renamed after the device, e.g. struct an8855 with a ddata instance, and the PHY context be given a matching device-based name?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928194511.41878-1-ansuelsmth%40gmail.com
#13 lore raw

PATCH v24 5/10 net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY

In reply to Christian Marangi

Add support for Airoha AN8855 Internal Switch Gigabit PHY.

This is a simple PHY driver to configure and calibrate the PHY for the AN8855 Switch with the use of NVMEM cells.

---
 drivers/net/phy/Kconfig      |   6 +
 drivers/net/phy/Makefile     |   1 +
 drivers/net/phy/air_an8855.c | 275 +++++++++++++++++++++++++++++++++++
 3 files changed, 282 insertions(+)
 create mode 100644 drivers/net/phy/air_an8855.c
drivers/net/phy/Kconfig +6 -0
index d3835597e379..eca2ce135c86 100644
@@ -96,6 +96,12 @@ config AIR_AN8801_PHY
 	help
 	  Currently supports the Airoha AN8801R PHY.
 
+config AIR_AN8855_PHY
+	tristate "Airoha AN8855 Internal Gigabit PHY"
+	depends on NVMEM || !NVMEM
+	help
+	  Currently supports the internal Airoha AN8855 Switch PHY.
+
 config AIR_EN8811H_PHY
 	tristate "Airoha EN8811H 2.5 Gigabit PHY"
 	select AIR_NET_PHYLIB
drivers/net/phy/Makefile +1 -0
index 579066a638f0..d5c633db0742 100644
@@ -31,6 +31,7 @@ obj-$(CONFIG_ADIN_PHY)		+= adin.o
 obj-$(CONFIG_ADIN1100_PHY)	+= adin1100.o
 obj-$(CONFIG_ADIN1140_PHY)	+= adin1140-phy.o
 obj-$(CONFIG_AIR_AN8801_PHY)	+= air_an8801.o
+obj-$(CONFIG_AIR_AN8855_PHY)	+= air_an8855.o
 obj-$(CONFIG_AIR_EN8811H_PHY)   += air_en8811h.o
 obj-$(CONFIG_AIR_NET_PHYLIB)	+= air_phy_lib.o
 obj-$(CONFIG_AMD_PHY)		+= amd.o
drivers/net/phy/air_an8855.c new file +275 -0

275 lines not on this page · raw message

Signature · 1 line
2.55.0
#14 lore raw

Re: [PATCH net-next v24 05/10] net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] net: phy: an8855_probe() fails if nvmem-cells exists for non-calibration purposes - [High] net…

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] net: phy: an8855_probe() fails if nvmem-cells exists for non-calibration purposes
- [High] net: phy: exact-match lookup in an8855_get_r50ohm_val() breaks calibration
- [Medium] net: phy: an8855_set_downshift() silently ignores unsupported counts
- [Medium] net: phy: phy_write_mmd() in an8855_config_init() clobbers adjacent RXADC_REV lanes --

commit 33dc7857103418b012780d7052f73bf932464765
Author: Christian Marangi <[email protected]>

net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY

This patch adds support for the Airoha AN8855 Internal Switch Gigabit PHY. It includes a driver to configure and calibrate the PHY using NVMEM cells.

Quoted 5 lines
drivers/net/phy/air_an8855.c new file +0 -0
new file mode 100644
index 0000000000000..bc22256fd5f95

[ ... ]

Quoted 10 lines
drivers/net/phy/air_an8855.c new file +10 -0
+static int an8855_get_r50ohm_val(struct device *dev, const char *calib_name,
+				 u8 *dest)
+{
+	u32 shift_sel, val;
+	int ret;
+	int i;
+
+	ret = nvmem_cell_read_u32(dev, calib_name, &val);
+	if (ret)
+		return ret;

drivers/net/phy/air_an8855.c line 90

Quoted 10 lines
drivers/net/phy/air_an8855.c new file +10 -0
+
+	shift_sel = FIELD_GET(AN8855_SWITCH_EFUSE_R50O, val);
+	for (i = 0; i < ARRAY_SIZE(dsa_r50ohm_table); i++)
+		if (dsa_r50ohm_table[i] == shift_sel)
+			break;
+
+	if (i < 8 || i >= ARRAY_SIZE(dsa_r50ohm_table))
+		*dest = dsa_r50ohm_table[25];
+	else
+		*dest = dsa_r50ohm_table[i - 8];

[Severity: High]
Does this exact-match loop lookup load incorrect calibration values?

Since 127 occurs 17 times at the start of dsa_r50ohm_table, searching for 127 will always break at i = 0. This triggers the i < 8 fallback, applying a value of 94 instead of the intended 127.

Also, any intermediate EFUSE values missing from the sparse table (e.g., 125,
124) will fail the exact match loop entirely (i = 64) and also fall back to 94, which could cause massive discontinuities.

Quoted 12 lines
drivers/net/phy/air_an8855.c new file +12 -0
+
+	return 0;
+}
+
+static int an8855_probe(struct phy_device *phydev)
+{
+	struct device *dev = &phydev->mdio.dev;
+	struct air_an8855_priv *priv;
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;

drivers/net/phy/air_an8855.c line 112

Quoted 10 lines
drivers/net/phy/air_an8855.c new file +10 -0
+
+	priv->needs_calibration = of_property_present(dev->of_node,
+						      "nvmem-cells");
+
+	if (priv->needs_calibration) {
+		int ret;
+
+		ret = an8855_get_r50ohm_val(dev, "tx_a", &priv->calibration_data[0]);
+		if (ret)
+			return ret;

[Severity: High]
Does this broad property presence check break probing on valid device trees?

If the nvmem-cells property is present for another standard purpose (like providing a MAC address) but the calibration cell (tx_a) is missing, nvmem_cell_read_u32() in an8855_get_r50ohm_val() will return -ENOENT.

Because this error is returned directly, the PHY driver completely fails to probe on devices that legally use nvmem-cells for non-calibration data.

[ ... ]

drivers/net/phy/air_an8855.c line 153

Quoted 8 lines
drivers/net/phy/air_an8855.c new file +8 -0
+static int an8855_set_downshift(struct phy_device *phydev, u8 cnt)
+{
+	u16 ds = cnt != DOWNSHIFT_DEV_DISABLE ? AN8855_PHY_EN_DOWN_SHIFT : 0;
+
+	return phy_modify_paged(phydev, AN8855_PHY_PAGE_EXTENDED_1,
+				AN8855_PHY_EXT_REG_14, AN8855_PHY_EN_DOWN_SHIFT,
+				ds);
+}

[Severity: Medium]
Should this function return an error such as -EOPNOTSUPP or -EINVAL for unsupported downshift counts?

The requested cnt is completely ignored unless it is DOWNSHIFT_DEV_DISABLE, always enabling the default downshift behavior. Userspace configuration will desynchronize from the actual hardware state, as ethtool will report success for counts the PHY did not actually apply.

[ ... ]

drivers/net/phy/air_an8855.c line 208

Quoted 6 lines
drivers/net/phy/air_an8855.c new file +6 -0
+	ret = phy_write_mmd(phydev, MDIO_MMD_VEND1, AN8855_PHY_RXADC_REV_0,
+			    FIELD_PREP(AN8855_PHY_RG_AD_RESERVE0_A, 0x1));
+	if (ret)
+		return ret;
+	ret = phy_write_mmd(phydev, MDIO_MMD_VEND1, AN8855_PHY_RXADC_REV_1,
+			    FIELD_PREP(AN8855_PHY_RG_AD_RESERVE0_C, 0x1));

[Severity: Medium]
Will these raw writes clobber the adjacent RXADC_REV lanes?

Using phy_write_mmd() rather than a modify wipes out the RESERVE0_B and RESERVE0_D fields located in the lower byte of these registers, destroying any hardware defaults or prior configurations for lanes B and D.

Quoted 5 lines
drivers/net/phy/air_an8855.c new file +5 -0
+	if (ret)
+		return ret;
+
+	return 0;
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
#15 lore raw

Re: [PATCH net-next v24 05/10] net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY

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

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

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

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

- [Medium] an8855_probe() (drivers/net/phy/air_an8855.c) reads the four eFUSE NVMEM cells in .probe and returns any error as a probe failure.
- [Medium] AIR_AN8855_PHY has 'depends on NVMEM || !NVMEM' (drivers/net/phy/Kconfig:101), so CONFIG_NVMEM=n is an explicitly…
- [Medium] The ETHTOOL_PHY_DOWNSHIFT tunable does not follow the retry- count ABI.
- [Low] The PHY binding added in the series (commit "dt-bindings: net:
Document support for AN8855 Switch Internal PHY",…

--

net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY

This adds a phylib driver for the internal gigabit PHYs of the Airoha AN8855 switch. At probe time it reads per-pair R50 calibration values from eFUSE NVMEM cells. config_init then applies them, along with noise-reduction tuning and HW downshift enable, and the downshift tunable is exposed through ethtool.

drivers/net/phy/Kconfig config AIR_AN8801_PHY · line 101

Quoted 11 lines
drivers/net/phy/Kconfig +3 -0
index d3835597e3795..eca2ce135c86b 100644
@@ -96,6 +96,12 @@ config AIR_AN8801_PHY
 	help
 	  Currently supports the Airoha AN8801R PHY.
 
+config AIR_AN8855_PHY
+	tristate "Airoha AN8855 Internal Gigabit PHY"
+	depends on NVMEM || !NVMEM

[Severity: Medium]
This dependency allows a CONFIG_NVMEM=n build. In that build nvmem_cell_read_u32() is the inline stub:

include/linux/nvmem-consumer.h:
static inline int nvmem_cell_read_u32(struct device *dev,
const char *cell_id, u32 *val)

{
	return -EOPNOTSUPP;
}

an8855_probe() still sets needs_calibration from of_property_present(dev->of_node, "nvmem-cells"). It then returns the -EOPNOTSUPP from an8855_get_r50ohm_val() as a probe failure.

nvmem-cells is optional in airoha,an8855-phy.yaml, and the MFD binding example puts nvmem-cells on every PHY. On an NVMEM=n kernel, would a DT that follows the binding leave every port bound to genphy instead of this driver?

That would also drop the noise-reduction writes and the downshift setup in an8855_config_init(), and neither of those depends on NVMEM.

Could probe treat -EOPNOTSUPP and -ENOENT as "no calibration" and continue? dp83867_of_init_io_impedance() does this:

	if (ret != -ENOENT && ret != -EOPNOTSUPP)
		return phydev_err_probe(phydev, ret, ...);
Quoted 2 lines
drivers/net/phy/Kconfig +2 -0
+	help
+	  Currently supports the internal Airoha AN8855 Switch PHY.

[ ... ]

Quoted 5 lines
drivers/net/phy/air_an8855.c new file +0 -0
new file mode 100644
index 0000000000000..bc22256fd5f95

[ ... ]

Quoted 8 lines
drivers/net/phy/air_an8855.c new file +8 -0
+static int an8855_probe(struct phy_device *phydev)
+{
+	struct device *dev = &phydev->mdio.dev;
+	struct air_an8855_priv *priv;
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;

drivers/net/phy/air_an8855.c line 112

Quoted 10 lines
drivers/net/phy/air_an8855.c new file +10 -0
+
+	priv->needs_calibration = of_property_present(dev->of_node,
+						      "nvmem-cells");
+
+	if (priv->needs_calibration) {
+		int ret;
+
+		ret = an8855_get_r50ohm_val(dev, "tx_a", &priv->calibration_data[0]);
+		if (ret)
+			return ret;

[Severity: Medium]
Can this succeed on the first probe? an8855_core_probe() in drivers/mfd/airoha-an8855.c registers the PHYs before it creates the eFUSE provider cell:

drivers/mfd/airoha-an8855.c:an8855_core_probe() {
    ...
	/* Register PHYs */
	for (i = 0; i < num_phys; i++) {
		ret = fwnode_mdiobus_register_phy(phy_bus_infos[i].bus,
						  phy_bus_infos[i].node,
						  phy_bus_infos[i].addr);
    ...
	return devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO, an8855_cells,
				    ARRAY_SIZE(an8855_cells), NULL, 0,
				    NULL);
}

So nvmem_cell_read_u32() here would return -EPROBE_DEFER on the first probe of every PHY node that has nvmem-cells.

The DSA switch cell is added in the same devm_mfd_add_devices() call, and fw_devlink does not follow phy-handle. If the switch attaches the PHY while this driver is still deferred, phy_attach_direct() takes its fallback:

	if (!d->driver) {
		if (phydev->is_c45)
			d->driver = &genphy_c45_driver.mdiodrv.driver;
		else
			d->driver = &genphy_driver.mdiodrv.driver;

Would genphy then stay bound? If so, the R50 calibration, the noise-reduction writes and the downshift setup would all be skipped with no error.

There is also a Kconfig problem. NVMEM_AN8855_EFUSE in drivers/nvmem/Kconfig currently has:

config NVMEM_AN8855_EFUSE
tristate "Airoha AN8855 eFuse support"
depends on COMPILE_TEST

On a non-COMPILE_TEST kernel with CONFIG_NVMEM=y the provider can never exist. Would a DT that follows the MFD binding example then defer here forever and always end up on genphy?

Should a missing provider fall back to running uncalibrated? Or should AIR_AN8855_PHY be tied to the eFUSE provider in Kconfig?

[ ... ]

Quoted 12 lines
drivers/net/phy/air_an8855.c new file +12 -0
+static int an8855_get_downshift(struct phy_device *phydev, u8 *data)
+{
+	int val;
+
+	val = phy_read_paged(phydev, AN8855_PHY_PAGE_EXTENDED_1, AN8855_PHY_EXT_REG_14);
+	if (val < 0)
+		return val;
+
+	*data = val & AN8855_PHY_EN_DOWN_SHIFT ? DOWNSHIFT_DEV_DEFAULT_COUNT :
+						 DOWNSHIFT_DEV_DISABLE;
+
+	return 0;

drivers/net/phy/air_an8855.c line 153

Quoted 10 lines
drivers/net/phy/air_an8855.c new file +10 -0
+}
+
+static int an8855_set_downshift(struct phy_device *phydev, u8 cnt)
+{
+	u16 ds = cnt != DOWNSHIFT_DEV_DISABLE ? AN8855_PHY_EN_DOWN_SHIFT : 0;
+
+	return phy_modify_paged(phydev, AN8855_PHY_PAGE_EXTENDED_1,
+				AN8855_PHY_EXT_REG_14, AN8855_PHY_EN_DOWN_SHIFT,
+				ds);
+}

[Severity: Medium]
Do these follow the downshift retry-count ABI?

an8855_set_downshift() accepts any count from 1 to 254 and reduces it to the single AN8855_PHY_EN_DOWN_SHIFT bit. It returns success even though the hardware keeps its own fixed retry threshold. ethtool_phy_tunable_valid() only checks length and type, so nothing else rejects the value.

On the get side, an8855_get_downshift() reports DOWNSHIFT_DEV_DEFAULT_COUNT (0xff) whenever the bit is set. That value is a set-side sentinel, so ethtool would show "Downshift count: 255". A set of 3 followed by a get would not read back 3.

Other drivers map the sentinel to a concrete count and reject counts they cannot program. For example, bcm54140_set_downshift() does:

	if (cnt > BCM54140_MAX_DOWNSHIFT && cnt != DOWNSHIFT_DEV_DEFAULT_COUNT)
		return -EINVAL;
	...
	if (cnt == DOWNSHIFT_DEV_DEFAULT_COUNT)
		cnt = BCM54140_DEFAULT_DOWNSHIFT;

microchip.c, mscc_main.c, qcom-phy-lib.c and marvell10g.c work the same way.

Could this driver report the count the hardware actually uses, and return -EINVAL for counts it cannot honor?

A smaller point: an8855_config_init() runs on every phy_init_hw() call (attach and resume) and does:

	/* Enable HW auto downshift */
	ret = an8855_set_downshift(phydev, DOWNSHIFT_DEV_DEFAULT_COUNT);

So a user's "downshift off" setting is re-enabled after resume. mtk-ge.c and marvell10g.c do the same, so this part may be acceptable.

[ ... ]

Quoted 6 lines
drivers/net/phy/air_an8855.c new file +6 -0
+static struct phy_driver an8855_driver[] = {
+{
+	PHY_ID_MATCH_EXACT(AN8855_PHY_ID),
+	.name			= "Airoha AN8855 internal PHY",
+	/* PHY_GBIT_FEATURES */
+	.flags			= PHY_IS_INTERNAL,

[ ... ]

drivers/net/phy/air_an8855.c line 262

Quoted 3 lines
drivers/net/phy/air_an8855.c new file +3 -0
+	.read_page		= an8855_read_page,
+	.write_page		= an8855_write_page,
+}, };

[Severity: Low]
This one is in another patch in the series, but it affects how this driver gets probed. The examples in the PHY binding (Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml) use:

    compatible = "ethernet-phy-idc0ff.0410",
                 "ethernet-phy-ieee802.3-c45";

mfd/airoha,an8855.yaml uses "ethernet-phy-ieee802.3-c22" for the same PHYs. The driver and the bus are both Clause 22 only, since devm_mdio_regmap_register() sets only mii->read and mii->write.

If a DT copies the PHY binding example, fwnode_mdiobus_register_phy() sees the c45 compatible:

	is_c45 = fwnode_device_is_compatible(child, "ethernet-phy-ieee802.3-c45");
	if (is_c45 || fwnode_get_phy_id(child, &phy_id))
		phy = get_phy_device(bus, addr, is_c45);

Wouldn't get_phy_c45_ids() then fail with -EIO on this C22-only bus? That would make an8855_core_probe() fail for the whole MFD (switch, PHYs and eFUSE).

Should the example use "ethernet-phy-ieee802.3-c22" instead?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928194511.41878-1-ansuelsmth%40gmail.com
#16 lore raw

PATCH v24 6/10 net: dsa: tag_mtk: add Airoha variant usage of this TAG

In reply to Christian Marangi

Add variant of the MTK TAG for Airoha Switch and comments about difference between Airoha AN8855 and Mediatek tag bitmap.

Airoha AN8855 doesn't support controlling SA learning and Leaky VLAN from tag. Although these bits are not used (and even not defined for Leaky VLAN), it's worth to add comments for these difference to prevent any kind of regression in the future if ever these bits will be used.

Rework the makefile, config and tag driver to better report to external tool (like libpcap) the usage of this variant with a dedicated "Airoha" name.

---
 include/net/dsa.h |  2 ++
 net/dsa/Kconfig   | 11 +++++++++++
 net/dsa/Makefile  |  2 +-
 net/dsa/tag_mtk.c | 36 +++++++++++++++++++++++++++++++++---
 4 files changed, 47 insertions(+), 4 deletions(-)
include/net/dsa.h +2 -0
index 5d12191b6f6f..9824c63ad50b 100644
@@ -62,6 +62,7 @@ struct tc_action;
 #define DSA_TAG_PROTO_KSZ8463_VALUE		34
 #define DSA_TAG_PROTO_MT7628_VALUE		35
 #define DSA_TAG_PROTO_KS8995_VALUE		36
+#define DSA_TAG_PROTO_AIROHA_VALUE		37
 
 enum dsa_tag_protocol {
 	DSA_TAG_PROTO_NONE		= DSA_TAG_PROTO_NONE_VALUE,
@@ -76,6 +77,7 @@ enum dsa_tag_protocol {
 	DSA_TAG_PROTO_KSZ9893		= DSA_TAG_PROTO_KSZ9893_VALUE,
 	DSA_TAG_PROTO_LAN9303		= DSA_TAG_PROTO_LAN9303_VALUE,
 	DSA_TAG_PROTO_MTK		= DSA_TAG_PROTO_MTK_VALUE,
+	DSA_TAG_PROTO_AIROHA		= DSA_TAG_PROTO_AIROHA_VALUE,
 	DSA_TAG_PROTO_QCA		= DSA_TAG_PROTO_QCA_VALUE,
 	DSA_TAG_PROTO_TRAILER		= DSA_TAG_PROTO_TRAILER_VALUE,
 	DSA_TAG_PROTO_8021Q		= DSA_TAG_PROTO_8021Q_VALUE,
net/dsa/Kconfig +11 -0
index 4f44bf3ede23..28a249f04a43 100644
@@ -24,6 +24,13 @@ config NET_DSA_TAG_NONE
 	  Say Y or M if you want to enable support for switches which don't tag
 	  frames over the CPU port.
 
+config NET_DSA_TAG_AIROHA
+	tristate "Tag driver for Airoha switches"
+	select NET_DSA_TAG_MTK_COMMON
+	help
+	  Say Y or M if you want to enable support for tagging frames for
+	  Airoha switches.
+
 config NET_DSA_TAG_AR9331
 	tristate "Tag driver for Atheros AR9331 SoC with built-in switch"
 	help
@@ -104,8 +111,12 @@ config NET_DSA_TAG_MT7628
 	  Say Y or M if you want to enable support for tagging frames for the
 	  switch embedded in the MT7628 SoC.
 
+config NET_DSA_TAG_MTK_COMMON
+	tristate
+
 config NET_DSA_TAG_MTK
 	tristate "Tag driver for Mediatek switches"
+	select NET_DSA_TAG_MTK_COMMON
 	help
 	  Say Y or M if you want to enable support for tagging frames for
 	  Mediatek switches.
net/dsa/Makefile +1 -1
index 1f9cc30e9988..7ccaa528a989 100644
@@ -29,7 +29,7 @@ obj-$(CONFIG_NET_DSA_TAG_KS8995) += tag_ks8995.o
 obj-$(CONFIG_NET_DSA_TAG_KSZ) += tag_ksz.o
 obj-$(CONFIG_NET_DSA_TAG_LAN9303) += tag_lan9303.o
 obj-$(CONFIG_NET_DSA_TAG_MT7628) += tag_mt7628.o
-obj-$(CONFIG_NET_DSA_TAG_MTK) += tag_mtk.o
+obj-$(CONFIG_NET_DSA_TAG_MTK_COMMON) += tag_mtk.o
 obj-$(CONFIG_NET_DSA_TAG_MXL_862XX) += tag_mxl862xx.o
 obj-$(CONFIG_NET_DSA_TAG_MXL_GSW1XX) += tag_mxl-gsw1xx.o
 obj-$(CONFIG_NET_DSA_TAG_NETC) += tag_netc.o
net/dsa/tag_mtk.c +33 -3
index c7dc7731675e..f8087d768da6 100644
@@ -11,6 +11,7 @@
 #include "tag.h"
 
 #define MTK_NAME		"mtk"
+#define AIROHA_NAME		"airoha"
 
 #define MTK_HDR_LEN		4
 #define MTK_HDR_XMIT_UNTAGGED		0
@@ -18,6 +19,9 @@
 #define MTK_HDR_XMIT_TAGGED_TPID_88A8	2
 #define MTK_HDR_RECV_SOURCE_PORT_MASK	GENMASK(2, 0)
 #define MTK_HDR_XMIT_DP_BIT_MASK	GENMASK(5, 0)
+/* AN8855 doesn't support SA_DIS and Leaky VLAN
+ * control in tag as these bits doesn't exist.
+ */
 #define MTK_HDR_XMIT_SA_DIS		BIT(6)
 
 static struct sk_buff *mtk_tag_xmit(struct sk_buff *skb,
@@ -99,6 +103,7 @@ static struct sk_buff *mtk_tag_rcv(struct sk_buff *skb, struct net_device *dev)
 	return skb;
 }
 
+#if IS_ENABLED(CONFIG_NET_DSA_TAG_MTK)
 static const struct dsa_device_ops mtk_netdev_ops = {
 	.name		= MTK_NAME,
 	.proto		= DSA_TAG_PROTO_MTK,
@@ -107,8 +112,33 @@ static const struct dsa_device_ops mtk_netdev_ops = {
 	.needed_headroom = MTK_HDR_LEN,
 };
 
-MODULE_DESCRIPTION("DSA tag driver for Mediatek switches");
-MODULE_LICENSE("GPL");
+DSA_TAG_DRIVER(mtk_netdev_ops);
 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_MTK, MTK_NAME);
+#endif
 
-module_dsa_tag_driver(mtk_netdev_ops);
+#if IS_ENABLED(CONFIG_NET_DSA_TAG_AIROHA)
+static const struct dsa_device_ops airoha_netdev_ops = {
+	.name		= AIROHA_NAME,
+	.proto		= DSA_TAG_PROTO_AIROHA,
+	.xmit		= mtk_tag_xmit,
+	.rcv		= mtk_tag_rcv,
+	.needed_headroom = MTK_HDR_LEN,
+};
+
+DSA_TAG_DRIVER(airoha_netdev_ops);
+MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_AIROHA, AIROHA_NAME);
+#endif
+
+static struct dsa_tag_driver *dsa_tag_driver_array[] =	{
+#if IS_ENABLED(CONFIG_NET_DSA_TAG_MTK)
+	&DSA_TAG_DRIVER_NAME(mtk_netdev_ops),
+#endif
+#if IS_ENABLED(CONFIG_NET_DSA_TAG_AIROHA)
+	&DSA_TAG_DRIVER_NAME(airoha_netdev_ops),
+#endif
+};
+
+module_dsa_tag_drivers(dsa_tag_driver_array);
+
+MODULE_DESCRIPTION("DSA tag driver for Mediatek switches");
+MODULE_LICENSE("GPL");
Signature · 1 line
2.55.0
#17 lore raw

Re: [PATCH net-next v24 06/10] net: dsa: tag_mtk: add Airoha variant usage of this TAG

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] net: dsa: MAC driver offloads fail for new Airoha tag protocol --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] net: dsa: MAC driver offloads fail for new Airoha tag protocol
--

commit 8cdc1e6c2d15d8ca09e78024f7070167218dff24
Author: Christian Marangi <[email protected]>

net: dsa: tag_mtk: add Airoha variant usage of this TAG

Add variant of the MTK TAG for Airoha Switch and comments about difference between Airoha AN8855 and Mediatek tag bitmap.

include/net/dsa.h enum dsa_tag_protocol { · line 80

Quoted 9 lines
include/net/dsa.h +1 -0
index 5d12191b6f6f5..9824c63ad50b3 100644
@@ -76,6 +77,7 @@ enum dsa_tag_protocol {
 	DSA_TAG_PROTO_KSZ9893		= DSA_TAG_PROTO_KSZ9893_VALUE,
 	DSA_TAG_PROTO_LAN9303		= DSA_TAG_PROTO_LAN9303_VALUE,
 	DSA_TAG_PROTO_MTK		= DSA_TAG_PROTO_MTK_VALUE,
+	DSA_TAG_PROTO_AIROHA		= DSA_TAG_PROTO_AIROHA_VALUE,

[Severity: High]
Does this new protocol ID break hardware offloading and DMA descriptor construction in existing drivers?

Several MAC drivers currently hardcode checks for DSA_TAG_PROTO_MTK and will silently fail or reject this new protocol.

In the Airoha Ethernet driver, returning 0 breaks DMA descriptor construction:

drivers/net/ethernet/airoha/airoha_eth.c:airoha_get_dsa_tag() {
	if (dev->dsa_ptr->tag_ops->proto != DSA_TAG_PROTO_MTK)
		return 0;
}

In the Mediatek Ethernet driver, metadata allocation for hardware forwarding fails because mtk_uses_dsa() returns false:

drivers/net/ethernet/mediatek/mtk_eth_soc.c:mtk_uses_dsa() {
	return netdev_uses_dsa(dev) &&
	       dev->dsa_ptr->tag_ops->proto == DSA_TAG_PROTO_MTK;
}

PPE hardware offloading silently aborts instead of forwarding:

drivers/net/ethernet/mediatek/mtk_ppe.c:mtk_foe_entry_prepare() {
	if (!netdev_uses_dsa(skb->dev) ||
	    skb->dev->dsa_ptr->tag_ops->proto != DSA_TAG_PROTO_MTK)
		goto out;
}

And flow offloading completely fails:

drivers/net/ethernet/mediatek/mtk_ppe_offload.c:mtk_flow_get_dsa_port() {
	if (dp->cpu_dp->tag_ops->proto != DSA_TAG_PROTO_MTK)
		return -ENODEV;
}

Do these drivers need to be updated to also accept DSA_TAG_PROTO_AIROHA?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
#18 lore raw

Re: [PATCH net-next v24 06/10] net: dsa: tag_mtk: add Airoha variant usage of this TAG

In reply to Christian Marangi
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

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

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

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

- [Medium] This patch adds a new tag protocol, DSA_TAG_PROTO_AIROHA ("airoha").
- [Low] After this patch, tag_mtk.ko can register both the "mtk" and "airoha" tag drivers through…

--

net: dsa: tag_mtk: add Airoha variant usage of this TAG

This commit adds a new DSA_TAG_PROTO_AIROHA tag protocol ("airoha") that reuses the existing MTK tag xmit/rcv handlers. It adds a comment noting that AN8855 lacks the SA_DIS and Leaky VLAN tag bits. It also reworks Kconfig and the Makefile so tag_mtk.o is built through a common NET_DSA_TAG_MTK_COMMON symbol and registers either or both taggers.

Quoted 4 lines
net/dsa/tag_mtk.c +0 -0
index c7dc7731675ec..f8087d768da6d 100644

[ ... ]

Quoted 9 lines
net/dsa/tag_mtk.c +2 -2
@@ -107,8 +112,33 @@ static const struct dsa_device_ops mtk_netdev_ops = {
 	.needed_headroom = MTK_HDR_LEN,
 };
 
-MODULE_DESCRIPTION("DSA tag driver for Mediatek switches");
-MODULE_LICENSE("GPL");
+DSA_TAG_DRIVER(mtk_netdev_ops);
 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_MTK, MTK_NAME);
+#endif

net/dsa/tag_mtk.c static const struct dsa_device_ops mtk_netdev_ops = { · line 126

Quoted 10 lines
net/dsa/tag_mtk.c +8 -1
 
-module_dsa_tag_driver(mtk_netdev_ops);
+#if IS_ENABLED(CONFIG_NET_DSA_TAG_AIROHA)
+static const struct dsa_device_ops airoha_netdev_ops = {
+	.name		= AIROHA_NAME,
+	.proto		= DSA_TAG_PROTO_AIROHA,
+	.xmit		= mtk_tag_xmit,
+	.rcv		= mtk_tag_rcv,
+	.needed_headroom = MTK_HDR_LEN,
+};

[Severity: Medium]
The wire format here is the same as DSA_TAG_PROTO_MTK. However, the conduit drivers that handle the MTK special tag in hardware check the protocol ID, not the format. Will they still handle a conduit that uses the "airoha" tagger correctly?

Later in the series, an8855_get_tag_protocol() returns DSA_TAG_PROTO_AIROHA. No later patch updates these checks, which still only match DSA_TAG_PROTO_MTK:

drivers/net/ethernet/mediatek/mtk_ppe_offload.c:mtk_flow_get_dsa_port() {
	...
	if (dp->cpu_dp->tag_ops->proto != DSA_TAG_PROTO_MTK)
		return -ENODEV;
	...
}
drivers/net/ethernet/mediatek/mtk_ppe.c:__mtk_ppe_check_skb() {
	...
		if (!netdev_uses_dsa(skb->dev) ||
		    skb->dev->dsa_ptr->tag_ops->proto != DSA_TAG_PROTO_MTK)
			goto out;
	...
}

With an AN8855 behind a mtk_eth_soc conduit, it looks like PPE/flowtable offload to the switch user ports would be silently unavailable.

On netsys v1, mtk_uses_dsa() also compares only against DSA_TAG_PROTO_MTK:

drivers/net/ethernet/mediatek/mtk_eth_soc.c:mtk_uses_dsa() {
	return netdev_uses_dsa(dev) &&
	       dev->dsa_ptr->tag_ops->proto == DSA_TAG_PROTO_MTK;
}

So mtk_open() skips the dsa_meta allocation and takes the else branch:

	} else {
		...
		val &= ~MTK_CDMP_STAG_EN;
		mtk_w32(eth, val, MTK_CDMP_IG_CTRL);

		mtk_w32(eth, 0, MTK_CDMP_EG_CTRL);
	}

Meanwhile, mtk_gdm_config() still sets MTK_GDMA_SPECIAL_TAG and mtk_tx_set_dma_desc_v2() still sets TX_DMA_SPTAG_V3 for any DSA conduit. Does this leave the MAC only partly configured for the special tag?

On Airoha SoCs, airoha_get_dsa_tag() has the same kind of check:

drivers/net/ethernet/airoha/airoha_eth.c:airoha_get_dsa_tag() {
	...
	if (dev->dsa_ptr->tag_ops->proto != DSA_TAG_PROTO_MTK)
		return 0;
	...
	default:
		/* PPE module requires untagged DSA packets to work properly,
		 * so move DSA tag to DMA descriptor.
		 */
		memmove(skb->data + MTK_HDR_LEN, skb->data, 2 * ETH_ALEN);
		__skb_pull(skb, MTK_HDR_LEN);
		break;
	...
}

With the new protocol, the in-band tag stays in the frame and 0 is written to QDMA_ETH_TXMSG_SP_TAG_MASK. airoha_dev_xmit() still requests TCO/UCO/ICO checksum offload and TSO for that frame.

On RX, airoha_dev_open() sets GDM_STAG_EN_MASK for any DSA conduit, so RX and TX handling of the tag would not match. Whether this corrupts checksums or makes the hardware insert a second tag depends on hardware behaviour, and the code alone can't show which.

The commit message says the change is about giving external tools like libpcap a dedicated name. Should these conduit checks also accept DSA_TAG_PROTO_AIROHA? One option is a helper that means "uses the MTK special tag format".

Quoted 7 lines
net/dsa/tag_mtk.c +7 -0
+
+DSA_TAG_DRIVER(airoha_netdev_ops);
+MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_AIROHA, AIROHA_NAME);
+#endif
+
+static struct dsa_tag_driver *dsa_tag_driver_array[] =	{
+#if IS_ENABLED(CONFIG_NET_DSA_TAG_MTK)

net/dsa/tag_mtk.c static const struct dsa_device_ops mtk_netdev_ops = { · line 143

Quoted 10 lines
net/dsa/tag_mtk.c +10 -0
+	&DSA_TAG_DRIVER_NAME(mtk_netdev_ops),
+#endif
+#if IS_ENABLED(CONFIG_NET_DSA_TAG_AIROHA)
+	&DSA_TAG_DRIVER_NAME(airoha_netdev_ops),
+#endif
+};
+
+module_dsa_tag_drivers(dsa_tag_driver_array);
+
+MODULE_DESCRIPTION("DSA tag driver for Mediatek switches");

[Severity: Low]
This isn't a bug, but should the module description be updated here? The module can now register the "airoha" tagger too. With only CONFIG_NET_DSA_TAG_AIROHA enabled, it registers only the Airoha tagger, but modinfo still reports "DSA tag driver for Mediatek switches".

Quoted 1 line
net/dsa/tag_mtk.c +1 -0
+MODULE_LICENSE("GPL");
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928194511.41878-1-ansuelsmth%40gmail.com
#19 lore raw

PATCH v24 7/10 MAINTAINERS: add myself as maintainer for Airoha AN8855 Switch

In reply to Christian Marangi

Add myself as maintainer for AN8855 DSA driver and all the related subdriver (mfd, mdio, phy, nvmem)

---
 MAINTAINERS | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
MAINTAINERS +16 -0
index 6de1ff058db6..59e6385b2c50 100644
@@ -759,6 +759,22 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/net/airoha,en7581-eth.yaml
 F:	drivers/net/ethernet/airoha/
 
+AIROHA AN8855 DSA DRIVER
+M:	Christian Marangi <[email protected]>
+L:	[email protected] (moderated for non-subscribers)
+L:	[email protected] (moderated for non-subscribers)
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/mfd/airoha,an8855.yaml
+F:	Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml
+F:	Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml
+F:	Documentation/devicetree/bindings/nvmem/airoha,an8855-efuse.yaml
+F:	drivers/mfd/airoha-an8855.c
+F:	drivers/net/dsa/mediatek/an8855.c
+F:	drivers/net/dsa/mediatek/an8855.h
+F:	drivers/net/phy/air_an8855.c
+F:	drivers/nvmem/an8855-efuse.c
+
 AIROHA PCIE PHY DRIVER
 M:	Lorenzo Bianconi <[email protected]>
 L:	[email protected] (moderated for non-subscribers)
Signature · 1 line
2.55.0
#20 lore raw

PATCH v24 8/10 net: dsa: move mediatek DSA driver in dedicated directory

In reply to Christian Marangi

To tidy things up and better organize DSA drivers, move the Mediatek related driver to the dedicated Vendor directory.

MAINTAINERS file is updated accordingly to reference the new location.

---
 MAINTAINERS                                  |  6 +--
 drivers/net/dsa/Kconfig                      | 45 +-------------------
 drivers/net/dsa/Makefile                     |  5 +--
 drivers/net/dsa/mediatek/Kconfig             | 45 ++++++++++++++++++++
 drivers/net/dsa/mediatek/Makefile            |  5 +++
 drivers/net/dsa/{ => mediatek}/mt7530-mdio.c |  0
 drivers/net/dsa/{ => mediatek}/mt7530-mmio.c |  0
 drivers/net/dsa/{ => mediatek}/mt7530.c      |  0
 drivers/net/dsa/{ => mediatek}/mt7530.h      |  0
 drivers/net/dsa/{ => mediatek}/mt7628.c      |  0
 10 files changed, 55 insertions(+), 51 deletions(-)
 create mode 100644 drivers/net/dsa/mediatek/Kconfig
 create mode 100644 drivers/net/dsa/mediatek/Makefile
 rename drivers/net/dsa/{ => mediatek}/mt7530-mdio.c (100%)
 rename drivers/net/dsa/{ => mediatek}/mt7530-mmio.c (100%)
 rename drivers/net/dsa/{ => mediatek}/mt7530.c (100%)
 rename drivers/net/dsa/{ => mediatek}/mt7530.h (100%)
 rename drivers/net/dsa/{ => mediatek}/mt7628.c (100%)
MAINTAINERS +3 -3
index 59e6385b2c50..ff8c5dda07b5 100644
@@ -16839,9 +16839,9 @@ M:	Chester A. Unal <[email protected]>
 M:	Daniel Golle <[email protected]>
 L:	[email protected]
 S:	Maintained
-F:	drivers/net/dsa/mt7530-mdio.c
-F:	drivers/net/dsa/mt7530-mmio.c
-F:	drivers/net/dsa/mt7530.*
+F:	drivers/net/dsa/mediatek/mt7530-mdio.c
+F:	drivers/net/dsa/mediatek/mt7530-mmio.c
+F:	drivers/net/dsa/mediatek/mt7530.*
 F:	net/dsa/tag_mtk.c
 
 MEDIATEK T7XX 5G WWAN MODEM DRIVER
drivers/net/dsa/Kconfig +1 -44

51 lines not on this page · raw message

drivers/net/dsa/Makefile +1 -4
index 7e637d56b35c..ee4784a9839b 100644
@@ -2,10 +2,6 @@
 obj-$(CONFIG_NET_DSA_BCM_SF2)	+= bcm-sf2.o
 bcm-sf2-objs			:= bcm_sf2.o bcm_sf2_cfp.o
 obj-$(CONFIG_NET_DSA_LOOP)	+= dsa_loop.o
-obj-$(CONFIG_NET_DSA_MT7530)	+= mt7530.o
-obj-$(CONFIG_NET_DSA_MT7530_MDIO) += mt7530-mdio.o
-obj-$(CONFIG_NET_DSA_MT7530_MMIO) += mt7530-mmio.o
-obj-$(CONFIG_NET_DSA_MT7628) += mt7628.o
 obj-$(CONFIG_NET_DSA_MV88E6060) += mv88e6060.o
 obj-$(CONFIG_NET_DSA_RZN1_A5PSW) += rzn1_a5psw.o
 obj-$(CONFIG_NET_DSA_SMSC_LAN9303) += lan9303-core.o
@@ -17,6 +13,7 @@ obj-$(CONFIG_NET_DSA_VITESSE_VSC73XX_SPI) += vitesse-vsc73xx-spi.o
 obj-y				+= b53/
 obj-y				+= hirschmann/
 obj-y				+= lantiq/
+obj-y				+= mediatek/
 obj-y				+= microchip/
 obj-y				+= motorcomm/
 obj-y				+= mv88e6xxx/
drivers/net/dsa/mediatek/Kconfig new file +45 -0

45 lines not on this page · raw message

drivers/net/dsa/mediatek/Makefile new file +5 -0
new file mode 100644
index 000000000000..0ed6e11f292e
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_NET_DSA_MT7530)	+= mt7530.o
+obj-$(CONFIG_NET_DSA_MT7530_MDIO) += mt7530-mdio.o
+obj-$(CONFIG_NET_DSA_MT7530_MMIO) += mt7530-mmio.o
+obj-$(CONFIG_NET_DSA_MT7628) += mt7628.o
drivers/net/dsa/mediatek/mt7530-mdio.c renamed from drivers/net/dsa/mt7530-mdio.c +0 -0
similarity index 100%
rename from drivers/net/dsa/mt7530-mdio.c
rename to drivers/net/dsa/mediatek/mt7530-mdio.c
drivers/net/dsa/mediatek/mt7530-mmio.c renamed from drivers/net/dsa/mt7530-mmio.c +0 -0
similarity index 100%
rename from drivers/net/dsa/mt7530-mmio.c
rename to drivers/net/dsa/mediatek/mt7530-mmio.c
drivers/net/dsa/mediatek/mt7530.c renamed from drivers/net/dsa/mt7530.c +0 -0
similarity index 100%
rename from drivers/net/dsa/mt7530.c
rename to drivers/net/dsa/mediatek/mt7530.c
drivers/net/dsa/mediatek/mt7530.h renamed from drivers/net/dsa/mt7530.h +0 -0
similarity index 100%
rename from drivers/net/dsa/mt7530.h
rename to drivers/net/dsa/mediatek/mt7530.h
drivers/net/dsa/mediatek/mt7628.c renamed from drivers/net/dsa/mt7628.c +0 -0
similarity index 100%
rename from drivers/net/dsa/mt7628.c
rename to drivers/net/dsa/mediatek/mt7628.c
Signature · 1 line
2.55.0
#21 lore raw

Re: [PATCH net-next v24 08/10] net: dsa: move mediatek DSA driver in dedicated directory

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines

To tidy things up and better organize DSA drivers, move the Mediatek related driver to the dedicated Vendor directory.

MAINTAINERS file is updated accordingly to reference the new location.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
#22 lore raw

PATCH v24 9/10 net: dsa: mt7530: generalize and move common function to lib module

In reply to Christian Marangi

In preparation of support of DSA Switch from Airoha, create a mt7530 library module and move there all the common function.

Function are generalized to use the reg_field regmap API but still apply the same exact logic. Every function is renamed to mt7530_lib prefix to better identify it.

Minimum modification are needed to the register header and common enum and macro are moved to the mt7530 library header to permit reuse.

A library struct is introduced with everything required for the common functions.

The generalization and the introduction of reg_field regmap API have the side effect of permitting to clean the mirror functions that required special handling for MT7530 and MT7531 based switch that had different registers. This is done by declaring a common MT7530 reg_field and a specific one in the Switch match table.

No behaviour change is expected by this change as it's just a code move and reimplementation.

---
 drivers/net/dsa/mediatek/Kconfig       |    4 +
 drivers/net/dsa/mediatek/Makefile      |    1 +
 drivers/net/dsa/mediatek/mt7530-lib.c  | 1128 +++++++++++++++++++
 drivers/net/dsa/mediatek/mt7530-lib.h  |  391 +++++++
 drivers/net/dsa/mediatek/mt7530-mdio.c |    4 +
 drivers/net/dsa/mediatek/mt7530-mmio.c |    4 +
 drivers/net/dsa/mediatek/mt7530.c      | 1366 ++++++------------------
 drivers/net/dsa/mediatek/mt7530.h      |  256 ++---
 8 files changed, 1912 insertions(+), 1242 deletions(-)
 create mode 100644 drivers/net/dsa/mediatek/mt7530-lib.c
 create mode 100644 drivers/net/dsa/mediatek/mt7530-lib.h
drivers/net/dsa/mediatek/Kconfig +4 -0
index ef62481662fd..7b48300dca0c 100644
@@ -1,6 +1,10 @@
 # SPDX-License-Identifier: GPL-2.0-only
+config NET_DSA_MT7530_LIB
+	tristate
+
 config NET_DSA_MT7530
 	tristate "MediaTek MT7530 and MT7531 Ethernet switch support"
+	select NET_DSA_MT7530_LIB
 	select NET_DSA_TAG_MTK
 	select REGMAP_IRQ
 	imply NET_DSA_MT7530_MDIO
drivers/net/dsa/mediatek/Makefile +1 -0
index 0ed6e11f292e..b2c0693dbb58 100644
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_NET_DSA_MT7530)	+= mt7530.o
+obj-$(CONFIG_NET_DSA_MT7530_LIB) += mt7530-lib.o
 obj-$(CONFIG_NET_DSA_MT7530_MDIO) += mt7530-mdio.o
 obj-$(CONFIG_NET_DSA_MT7530_MMIO) += mt7530-mmio.o
 obj-$(CONFIG_NET_DSA_MT7628) += mt7628.o
drivers/net/dsa/mediatek/mt7530-lib.c new file +1128 -0

1,128 lines not on this page · raw message

drivers/net/dsa/mediatek/mt7530-lib.h new file +391 -0

391 lines not on this page · raw message

drivers/net/dsa/mediatek/mt7530-mdio.c +4 -0
index 0be107dc6759..e823a9b1422f 100644
@@ -218,6 +218,10 @@ mt7530_probe(struct mdio_device *mdiodev)
 	if (IS_ERR(priv->regmap))
 		return PTR_ERR(priv->regmap);
 
+	ret = mt7530_setup_lib_priv(priv);
+	if (ret)
+		return ret;
+
 	if (priv->id == ID_MT7531)
 		priv->create_sgmii = mt7531_create_sgmii;
 
drivers/net/dsa/mediatek/mt7530-mmio.c +4 -0
index cf3bdb23a2d5..2dcb2bb545b9 100644
@@ -61,6 +61,10 @@ mt7988_probe(struct platform_device *pdev)
 	if (IS_ERR(priv->regmap))
 		return PTR_ERR(priv->regmap);
 
+	ret = mt7530_setup_lib_priv(priv);
+	if (ret)
+		return ret;
+
 	return dsa_register_switch(priv->ds);
 }
 
drivers/net/dsa/mediatek/mt7530.c +320 -1046

1,445 lines not on this page · raw message

drivers/net/dsa/mediatek/mt7530.h +60 -196

256 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.55.0

Part of the diff is not shown here. View the raw message.

#23 lore raw

Re: [PATCH net-next v24 09/10] net: dsa: mt7530: generalize and move common function to lib module

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] net: dsa: mt7530: spurious command/trigger execution via sequential RMW on command registers…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] net: dsa: mt7530: spurious command/trigger execution via sequential RMW on command registers
- [High] net: dsa: mt7530: stale hardware state leaks into VLAN table entries
- [High] net: dsa: mt7530: potential data loss and severe MDIO overhead in FDB writes --

commit 01f4c0abd9feaaa7a4bc2c096b85e94c4360593d
Author: Christian Marangi <[email protected]>
net: dsa: mt7530: generalize and move common function to lib module

This commit moves common MT7530 switch functions into a new library module and converts them to use the regmap field API. The refactoring aims to prepare for Airoha switch support while maintaining existing logic.

Quoted 15 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +9 -0
new file mode 100644
index 0000000000000..098dd45d3ee9f
@@ -0,0 +1,1128 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/device.h>
+#include <linux/if_bridge.h>
+#include <linux/module.h>
+#include <linux/regmap.h>
+#include <net/dsa.h>
+
+#include "mt7530-lib.h"

drivers/net/dsa/mediatek/mt7530-lib.c line 19

Quoted 10 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +10 -0
+
+void mt7530_lib_mib_reset(struct mt7530_lib_priv *priv)
+{
+	regmap_field_write(priv->fields[MT7530_CCR_MIB_ENABLE], 0);
+	regmap_field_write(priv->fields[MT7530_CCR_RX_OCT_CNT_GOOD], 1);
+	regmap_field_write(priv->fields[MT7530_CCR_RX_OCT_CNT_BAD], 1);
+	regmap_field_write(priv->fields[MT7530_CCR_TX_OCT_CNT_GOOD], 1);
+	regmap_field_write(priv->fields[MT7530_CCR_TX_OCT_CNT_BAD], 1);
+	regmap_field_write(priv->fields[MT7530_CCR_MIB_ENABLE], 1);
+}

[Severity: High]
Could this sequence trigger multiple spurious flushes? Since regmap_field_write() performs a read-modify-write (RMW), each sequential write to this register might repeatedly write back flush trigger bits before the operation completes. The original implementation avoided this by writing the entire register atomically with a single regmap_write().

[ ... ]

Quoted 5 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +5 -0
+int mt7530_lib_fdb_cmd(struct mt7530_lib_priv *priv, enum mt7530_fdb_cmd cmd,
+		       u32 mat, u32 *rsp)
+{
+	u32 val;
+	int ret;

drivers/net/dsa/mediatek/mt7530-lib.c line 415

Quoted 10 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +10 -0
+
+	ret = regmap_field_write(priv->fields[MT7530_ATC_MAT], mat);
+	if (ret)
+		return ret;
+
+	ret = regmap_field_write(priv->fields[MT7530_ATC_CMD], cmd);
+	if (ret)
+		return ret;
+
+	ret = regmap_field_write(priv->fields[MT7530_ATC_BUSY], 1);

[Severity: High]
Can these sequential RMW operations on the Address Table Command register lead to premature or spurious FDB command executions?

If the BUSY bit happens to be already set (e.g., from a previous command timeout, which the code polls for and can occur), the very first regmap_field_write() might read BUSY=1, modify the MAT field, and write it back with BUSY=1 still set. This would trigger the hardware immediately with incomplete command fields. Previously, this was handled safely by constructing the payload and BUSY bit in a local variable and issuing a single atomic regmap_write().

[ ... ]

Quoted 16 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +16 -0
+static void mt7530_lib_fdb_write(struct mt7530_lib_priv *priv, u16 vid,
+				 u8 port_mask, const u8 *mac,
+				 u8 aging, u8 type)
+{
+	/* Clear ATWD registers from previous access */
+	regmap_field_write(priv->fields[__MT7530_ATWD1], 0);
+	regmap_field_write(priv->fields[__MT7530_ATWD2], 0);
+	regmap_field_write(priv->fields[__MT7530_ATWD3], 0);
+
+	regmap_field_write(priv->fields[MT7530_ATWD_CVID], vid);
+	regmap_field_write(priv->fields[MT7530_ATWD_IVL], 1);
+	regmap_field_write(priv->fields[MT7530_ATWD_FID], FID_BRIDGED);
+	regmap_field_write(priv->fields[MT7530_ATWD_AGE_TIMER], aging);
+	regmap_field_write(priv->fields[MT7530_ATWD_PORT_MAP], port_mask);
+	/* STATIC_ENT indicate that entry is static wouldn't
+	 * be aged out and STATIC_EMP specified as erasing an

drivers/net/dsa/mediatek/mt7530-lib.c line 462

Quoted 10 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +10 -0
+	 * entry
+	 */
+	regmap_field_write(priv->fields[MT7530_ATWD_ENT_STATUS], type);
+	regmap_field_write(priv->fields[MT7530_ATWD_MAC_BYTE_5], mac[5]);
+	regmap_field_write(priv->fields[MT7530_ATWD_MAC_BYTE_4], mac[4]);
+	regmap_field_write(priv->fields[MT7530_ATWD_MAC_BYTE_3], mac[3]);
+	regmap_field_write(priv->fields[MT7530_ATWD_MAC_BYTE_2], mac[2]);
+	regmap_field_write(priv->fields[MT7530_ATWD_MAC_BYTE_1], mac[1]);
+	regmap_field_write(priv->fields[MT7530_ATWD_MAC_BYTE_0], mac[0]);
+}

[Severity: High]
Will these sequential updates to the FDB payload registers cause data loss?

These are write-only command payload buffers. Reading them (which regmap_field_write() does internally during the read-modify-write cycle) typically returns 0. If it returns 0, the RMW operation would overwrite and destroy the fields set by the preceding calls within the same register.

Additionally, since caching is disabled in the regmap configuration, this sequence generates 24 individual MDIO transactions per FDB update. Could this create severe performance overhead in the FDB hot path compared to the original bulk regmap_write()?

[ ... ]

Quoted 5 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +5 -0
+static int mt7530_vlan_cmd(struct mt7530_lib_priv *priv, enum mt7530_vlan_cmd cmd,
+			   u16 vid)
+{
+	u32 val;
+	int ret;

drivers/net/dsa/mediatek/mt7530-lib.c line 911

Quoted 10 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +10 -0
+
+	ret = regmap_field_write(priv->fields[MT7530_VTCR_FUNC], cmd);
+	if (ret)
+		return ret;
+
+	ret = regmap_field_write(priv->fields[MT7530_VTCR_VID], vid);
+	if (ret)
+		return ret;
+
+	ret = regmap_field_write(priv->fields[MT7530_VTCR_BUSY], 1);

[Severity: High]
Similar to mt7530_lib_fdb_cmd(), could these sequential RMWs on the VLAN Table Command register risk spurious VLAN command executions if the BUSY bit is already 1 when the first field is updated?

[ ... ]

Quoted 9 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +9 -0
+static void mt7530_hw_vlan_add(struct mt7530_lib_priv *priv,
+			       struct mt7530_hw_vlan_entry *entry)
+{
+	struct dsa_port *dp = dsa_to_port(priv->ds, entry->port);
+	u8 new_members;
+	u32 val;
+
+	new_members = entry->old_members | BIT(entry->port);
+

drivers/net/dsa/mediatek/mt7530-lib.c line 949

Quoted 10 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +10 -0
+	/* Validate the entry with independent learning, create egress tag per
+	 * VLAN and joining the port as one of the port members.
+	 */
+	regmap_field_write(priv->fields[MT7530_VAWD_IVL_MAC], 1);
+	regmap_field_write(priv->fields[MT7530_VAWD_VTAG_EN], 1);
+	regmap_field_write(priv->fields[MT7530_VAWD_PORT_MEM],
+			   new_members);
+	regmap_field_write(priv->fields[MT7530_VAWD_FID],
+			   FID_BRIDGED);
+	regmap_field_write(priv->fields[MT7530_VAWD_VLAN_VALID], 1);

[Severity: High]
Does this sequence leak uninitialized or stale bits into the VLAN table entry?

This register (MT7530_VAWD1) is populated by the hardware after executing a read command (MT7530_VTCR_RD_VID). For newly initialized VLANs, the hardware might return garbage or leftover state.

Because the regmap_field_write() RMW sequence modifies only specific bits without clearing the entire register first, these unspecified bits are preserved and written back. The original code used a bulk regmap_write() to deterministically zero out unspecified fields.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
#24 lore raw

Re: [PATCH net-next v24 09/10] net: dsa: mt7530: generalize and move common function to lib module

In reply to Christian Marangi
Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider.

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

Critical: 0 · High: 2 · Medium: 3 (1) · Low: 3

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

- [High] The name MT7530_MIRROR_EN is defined twice: once as a macro in mt7530.h and once as an enum constant in mt7530-lib.h.
- [High] net: dsa: mt7530: spurious command/trigger execution via sequential RMW on command registers
- [Medium] The patch changes the mirror register layout used for ID_EN7528 and ID_AN7583.
- [Medium] The VLAN table entries written to hardware are different after the patch.
- [Medium] Three functions declare u32 val; without a starting value, pass it to regmap_field_read(), ignore the return value, and then…
- [Low] Moving to one regmap_field access per register field sharply increases register traffic on MDIO-attached MT7530/MT7531.
- [Low] Two comments were not updated and now contradict the code.
- [Low] After a successful BUSY poll (val==0), the new FDB and VLAN command helpers ignore errors from the status reads that follow.

Pre-existing issues:
- [Medium] mt7530_port_fdb_dump() stores the callback's -EMSGSIZE from dsa_user_port_fdb_do_dump() and breaks out of the loop, but always…

--

net: dsa: mt7530: generalize and move common function to lib module

This commit creates an mt7530 library module and moves the common DSA switch operations there, to prepare for supporting Airoha switches. The moved functions are rewritten on top of the regmap reg_field API. There is a common field table, plus per-chip mirror field tables selected through mt753x_table.

Quoted 6 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +0 -0
new file mode 100644
index 0000000000000..098dd45d3ee9f
@@ -0,0 +1,1128 @@

[ ... ]

Quoted 3 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +3 -0
+int mt7530_lib_fdb_cmd(struct mt7530_lib_priv *priv, enum mt7530_fdb_cmd cmd,
+		       u32 mat, u32 *rsp)
+{

[ ... ]

drivers/net/dsa/mediatek/mt7530-lib.c line 431

Quoted 13 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +13 -0
+	ret = regmap_field_read_poll_timeout(priv->fields[MT7530_ATC_BUSY],
+					     val, !val, 20, 20000);
+	if (ret < 0) {
+		dev_err(priv->dev, "reset timeout\n");
+		return ret;
+	}
+
+	regmap_field_read(priv->fields[MT7530_ATC_INVALID], &val);
+	if (cmd == MT7530_FDB_READ && val)
+		return -EINVAL;
+
+	if (rsp)
+		regmap_field_read(priv->fields[__MT7530_ATC], rsp);

[Severity: High]
Can splitting the command register updates into separate read-modify-write field updates start a command with half-written parameters?

The old mt7530_fdb_cmd() and mt7530_vlan_cmd() put BUSY, the command and its arguments into one value and issued it with a single regmap_write(). Those values were ATC_BUSY | ATC_MAT(0) | cmd, and VTCR_BUSY | VTCR_FUNC(cmd) | VTCR_VID(vid).

mt7530_lib_fdb_cmd() now does three regmap_field_write() calls on
MT7530_ATC: MAT, then CMD, then BUSY. mt7530_vlan_cmd() does the same on MT7530_VTCR with FUNC, VID and BUSY. Each of these reads the register back and rewrites all the other bits unchanged.

That is only safe while BUSY reads back as 0. Both helpers return early on a poll timeout and leave BUSY set in hardware, and no caller clears it.

On the next call, the first field write puts BUSY=1 back into the register, together with the new MAT (or FUNC) and the previous CMD (or VID). If the switch treats any write with BUSY set as a new command, it runs the old command with mixed arguments. The CMD and BUSY writes that follow can then issue it again.

Here is a concrete case. mt7530_lib_port_fast_age() issues MT7530_FDB_FLUSH with ATC_MAT_NON_STATIC_MAC. Suppose that times out. The next mt7530_lib_port_fdb_add() first writes ATC_MAT_MACTAB while CMD is still FLUSH and BUSY is still set. mt7530_setup() uses that same combination to flush the whole table, so the static FDB and MDB entries would be lost.

The VLAN path has the same risk. mt7530_hw_vlan_update() ignores the result of the RD_VID fetch. After a timeout, the FUNC write could program whatever is in VAWD1/VAWD2 into the previous VID.

mt7530_lib_mib_reset() has a similar issue. The old code did two whole-register writes, CCR_MIB_FLUSH and then CCR_MIB_ACTIVATE. The new code does six read-modify-write updates, so the switch sees four intermediate MIB_CCR values between disable and enable. If those bits act as triggers, each write can cause its own flush.

Could each of these registers still be written in one go? For example, the value could be built from the field definitions and written through the whole-register __MT7530_ATC field. VTCR and MIB_CCR would need matching whole-register fields. Or do you have another way in mind to keep this generic?

[Severity: Low]
Should these two regmap_field_read() calls have their return values checked?

regmap_field_read() does not write *val when it fails. val then keeps the 0 left by the poll, so a failed read after FDB_READ looks like a successful lookup.

If the rsp read fails, rsp keeps its previous value, and mt7530_port_fdb_dump() could repeat or skip entries.

The old helper returned the error:

	if (!ret)
		ret = regmap_read(priv->regmap, MT7530_ATC, &val);

	if (ret < 0) {
		dev_err(priv->dev, "reset timeout\n");
		return ret;
	}

mt7530_vlan_cmd() has the same pattern with MT7530_VTCR_INVALID, so a failed read there is reported as success.

Quoted 15 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +15 -0
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(mt7530_lib_fdb_cmd);
+
+static void mt7530_lib_fdb_write(struct mt7530_lib_priv *priv, u16 vid,
+				 u8 port_mask, const u8 *mac,
+				 u8 aging, u8 type)
+{
+	/* Clear ATWD registers from previous access */
+	regmap_field_write(priv->fields[__MT7530_ATWD1], 0);
+	regmap_field_write(priv->fields[__MT7530_ATWD2], 0);
+	regmap_field_write(priv->fields[__MT7530_ATWD3], 0);
+
+	regmap_field_write(priv->fields[MT7530_ATWD_CVID], vid);

[ ... ]

drivers/net/dsa/mediatek/mt7530-lib.c

Quoted 2 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +2 -0
+	regmap_field_write(priv->fields[MT7530_ATWD_MAC_BYTE_0], mac[0]);
+}

[Severity: Low]
This isn't a bug, but it adds a lot of register traffic on MDIO-attached MT7530/MT7531. There the regmap has no cache, and each access takes several MDIO frames:

- mt7530_lib_fdb_write() goes from 3 register writes to 15 read-modify-write field updates.
- mt7530_lib_fdb_read() goes from 3 reads to 10.
- mt7530_lib_fdb_cmd() and mt7530_vlan_cmd() go from one write to 3 read-modify-writes plus 2 extra reads.

All of this runs under reg_mutex, including the up to 2048 iterations in mt7530_port_fdb_dump().

Some updates that used to be a single write are now split. For example, mt7530_port_set_vlan_unaware() writes VLAN_ATTR, EG_TAG and ACC_FRM of PVC separately. mt7530_lib_port_change_mtu() writes MAX_RX_JUMBO and MAX_RX_PKT_LEN separately. A port that is passing traffic briefly runs with a mix of old and new settings.

Would whole-register writes be better for these multi-field updates?

[ ... ]

Quoted 9 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +9 -0
+int mt7530_lib_port_mdb_add(struct mt7530_lib_priv *priv, int port,
+			    const struct switchdev_obj_port_mdb *mdb,
+			    struct dsa_db db)
+{
+	const u8 *addr = mdb->addr;
+	u16 vid = mdb->vid;
+	u8 port_mask = 0;
+	u32 val;
+	int ret;

drivers/net/dsa/mediatek/mt7530-lib.c line 555

Quoted 10 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +10 -0
+
+	mutex_lock(priv->reg_mutex);
+
+	mt7530_lib_fdb_write(priv, vid, 0, addr, 0, STATIC_EMP);
+	if (!mt7530_lib_fdb_cmd(priv, MT7530_FDB_READ,
+				ATC_MAT_MACTAB, NULL)) {
+		regmap_field_read(priv->fields[MT7530_ATRD_PORT_MAP],
+				  &val);
+		port_mask = val;
+	}

[Severity: Medium]
Can port_mask end up holding uninitialized stack data here? val is not initialized, and regmap_field_read() returns early on a regmap_read() error without writing *val.

Before this patch these paths called regmap_read() directly, and the MDIO backend zeroes the output first:

drivers/net/dsa/mediatek/mt7530-mdio.c:mt7530_regmap_read() {
	/* Callers do not check for errors, keep the value deterministic */
	*val = 0;
	...
}

regmap_field_read() reads into its own local variable, so that guarantee does not reach the caller. If the MDIO read fails, a garbage port map is ORed with BIT(port) and written into the static multicast entry.

mt7530_lib_port_mdb_del() has the same problem. So does the VLAN_VALID check in mt7530_hw_vlan_del(), which also uses an uninitialized u32 val.

Would initializing val to 0 be enough here? mt7530_lib_fdb_read() and mt7530_hw_vlan_update() already do that.

[ ... ]

Quoted 11 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +11 -0
+static void mt7530_hw_vlan_del(struct mt7530_lib_priv *priv,
+			       struct mt7530_hw_vlan_entry *entry)
+{
+	u8 new_members;
+	u32 val;
+
+	new_members = entry->old_members & ~BIT(entry->port);
+
+	regmap_field_read(priv->fields[MT7530_VAWD_VLAN_VALID], &val);
+	if (!val) {
+		dev_err(priv->dev,

drivers/net/dsa/mediatek/mt7530-lib.c line 989

Quoted 10 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +10 -0
+			"Cannot be deleted due to invalid entry\n");
+		return;
+	}
+
+	if (new_members) {
+		regmap_field_write(priv->fields[MT7530_VAWD_IVL_MAC], 1);
+		regmap_field_write(priv->fields[MT7530_VAWD_VTAG_EN], 1);
+		regmap_field_write(priv->fields[MT7530_VAWD_PORT_MEM],
+				   new_members);
+		regmap_field_write(priv->fields[MT7530_VAWD_VLAN_VALID], 1);

[Severity: Medium]
Is this change to the programmed VLAN entry intended? The old code wrote all of VAWD1 here:

	val = IVL_MAC | VTAG_EN | PORT_MEM(new_members) |
	      VLAN_VALID;
	regmap_write(priv->regmap, MT7530_VAWD1, val);

That forced FID to 0 and cleared EG_CON and PORT_STAG.

The field writes now keep whatever the VTCR_RD_VID fetch loaded, so the entry stays on FID_BRIDGED. The VLAN FID selects which FID_PST STP state in SSP applies. Removing one member from a VLAN therefore now gives different forwarding and STP behaviour than before.

There are two related changes:

- mt7530_hw_vlan_add() no longer clears EG_CON, PORT_STAG or the other VAWD1 bits.
- mt7530_lib_mib_reset() now does read-modify-write on single MIB_CCR bits, instead of the two full CCR_MIB_FLUSH and CCR_MIB_ACTIVATE writes.

The new FID behaviour may well be more correct, but the commit message says:

No behaviour change is expected by this change as it's just a code move and reimplementation.

Could these changes be split out, or at least described in the commit message?

[ ... ]

Quoted 9 lines
drivers/net/dsa/mediatek/mt7530.c +1 -0
index 50e80585d5585..d0f2691a44a0a 100644
@@ -24,10 +24,163 @@
 #include <net/pkt_cls.h>
 
 #include "mt7530.h"
+#include "mt7530-lib.h"

[ ... ]

drivers/net/dsa/mediatek/mt7530.c line 182

Quoted 9 lines
drivers/net/dsa/mediatek/mt7530.c +9 -0
+static const struct mt7530_reg_field mt7530_fields[] = {
+	{ MT7530_MIRROR_EN, REG_FIELD(MT753X_MFC, 3, 3) },
+	{ MT7530_MIRROR_PORT, REG_FIELD(MT753X_MFC, 0, 2) },
+};
+
+static const struct mt7530_reg_field mt7531_fields[] = {
+	{ MT7530_MIRROR_EN, REG_FIELD(MT7531_CFC, 19, 19) },
+	{ MT7530_MIRROR_PORT, REG_FIELD(MT7531_CFC, 16, 18) },
+};

[Severity: High]
Does MT7530_MIRROR_EN expand to the enum index here?

mt7530.h includes mt7530-lib.h, where MT7530_MIRROR_EN is the first member of enum mt7530_regmap_field (value 0). mt7530.h still keeps the old register bit macro with the same name:

drivers/net/dsa/mediatek/mt7530.h:

	#include "mt7530-lib.h"
	...
	#define  MT7530_MIRROR_EN		BIT(3)

mt7530.c includes mt7530.h, so both initializers above become { 8, REG_FIELD(...) }.

mt7530_setup_lib_priv() handles the per-chip table after the common one:

	lib_priv->fields[reg_field->id] = field;

The mirror enable field therefore ends up in fields[8], which is MT7530_CCR_TX_OCT_CNT_GOOD. fields[0] stays NULL. mt7530-lib.c only sees the enum, so it uses index 0.

Wouldn't the first tc matchall mirred rule then oops on a NULL regmap_field?

mt753x_port_mirror_add()
mt7530_lib_port_mirror_add()

    regmap_field_read(priv->fields[MT7530_MIRROR_EN], &val);

mt7530_lib_port_mirror_del() does the same with regmap_field_write().

mt7530_lib_mib_reset(), called from mt7530_setup() and mt7531_setup_common(), would also set the global mirror enable bit (MFC bit 3 or CFC bit 19) instead of MIB_CCR bit 5:

	regmap_field_write(priv->fields[MT7530_CCR_TX_OCT_CNT_GOOD], 1);

The macro and the enum constant both still seem to be there at the end of the series (the AN8855 driver patch), so a later patch does not fix this.

[ ... ]

drivers/net/dsa/mediatek/mt7530.c static struct mt753x_pcs *pcs_to_mt753x_pcs(struct phylink_pcs *pcs) · line 190

Quoted 4 lines
drivers/net/dsa/mediatek/mt7530.c +0 -0
@@ -35,15 +188,15 @@ static struct mt753x_pcs *pcs_to_mt753x_pcs(struct phylink_pcs *pcs)
 
 /* String, offset, and register size in bytes if different from 4 bytes */
 static const struct mt7530_mib_desc mt7530_mib[] = {

[Severity: Low]
This isn't a bug, but this comment is now out of date. MIB_DESC() takes (field_low, field_high, name) regmap field indices, not an offset and a size.

The "Each define is an offset of MT7530_PORT_MIB_COUNTER" comment in mt7530.h is also wrong now, because the MT7530_PORT_MIB_* defines include MT7530_MIB_COUNTER.

Quoted 1 line
drivers/net/dsa/mediatek/mt7530.c +0 -1
-	MIB_DESC(1, MT7530_PORT_MIB_TX_DROP, "TxDrop"),

[ ... ]

Quoted 1 line
drivers/net/dsa/mediatek/mt7530.c +1 -0
+	MIB_DESC(MT7530_MIB_TX_DROP, -1, "TxDrop"),

[ ... ]

drivers/net/dsa/mediatek/mt7530.c mt7530_port_fdb_dump(struct dsa_switch *ds, int port, · line 1257

Quoted 10 lines
drivers/net/dsa/mediatek/mt7530.c +2 -1
@@ -1785,7 +1250,8 @@ mt7530_port_fdb_dump(struct dsa_switch *ds, int port,
 		}
 	} while (--cnt &&
 		 !(rsp & ATC_SRCH_END) &&
-		 !mt7530_fdb_cmd(priv, MT7530_FDB_NEXT, &rsp));
+		 !mt7530_lib_fdb_cmd(&priv->lib_priv, MT7530_FDB_NEXT,
+				     ATC_MAT_MACTAB, &rsp));
 err:
 	mutex_unlock(&priv->reg_mutex);
 

[Severity: Medium]
This patch did not introduce this, but mt7530_port_fdb_dump() drops the callback's error:

	ret = cb(_fdb.mac, _fdb.vid, _fdb.noarp, data);
	if (ret < 0)
		break;
	...
err:
	mutex_unlock(&priv->reg_mutex);

	return 0;

When dsa_user_port_fdb_do_dump() returns -EMSGSIZE because the skb is full, rtnl_fdb_dump() gets 0. It then moves on to the next device and resets fdb_idx.

Wouldn't that leave the rest of a large FDB out of "bridge fdb show"?

[ ... ]

Quoted 10 lines
drivers/net/dsa/mediatek/mt7530.c +2 -0
@@ -3509,6 +2738,8 @@ const struct mt753x_info mt753x_table[] = {
 	},
 	[ID_AN7583] = {
 		.id = ID_AN7583,
+		.reg_fields = mt7531_fields,
+		.num_reg_fields = ARRAY_SIZE(mt7531_fields),
 		.pcs_ops = &mt7530_pcs_ops,
 		.sw_setup = mt7988_setup,
 		.phy_read_c22 = mt7531_ind_c22_phy_read,

drivers/net/dsa/mediatek/mt7530.c const struct mt753x_info mt753x_table[] = { · line 2754

Quoted 5 lines
drivers/net/dsa/mediatek/mt7530.c +2 -0
@@ -3519,6 +2750,8 @@ const struct mt753x_info mt753x_table[] = {
 	},
 	[ID_EN7528] = {
 		.id = ID_EN7528,
+		.reg_fields = mt7531_fields,
+		.num_reg_fields = ARRAY_SIZE(mt7531_fields),

[Severity: Medium]
Is it intended that EN7528 and AN7583 now use mt7531_fields?

The old MT753X_MIRROR_REG() and MT753X_MIRROR_PORT_*() macros chose MT7531_CFC only for MT7531, MT7988, EN7581 and AN7583. EN7528 therefore used MT753X_MFC: bit 3 for enable and bits 2:0 for the monitor port. It now programs MT7531_CFC bits 19 and 18:16 instead.

Other parts of the driver still treat EN7528 like MT7530. For example, mt753x_conduit_state_change() has:

	if (priv->id != ID_MT7530 && priv->id != ID_MT7621 &&
	    priv->id != ID_EN7528)
		return;

Also, mt753x_cpu_port_enable() does not program the CFC CPU_PMAP for EN7528.

Could this be a regression that breaks port mirroring on EN7528?

For AN7583, MT753X_MIRROR_EN() left it out, so it used to set CFC bit 3, which is inside CPU_PMAP. It now uses CFC bit 19. That looks like a real fix, but the commit message says "No behaviour change is expected".

Should the AN7583 change be a separate patch with its own description?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928194511.41878-1-ansuelsmth%40gmail.com
#25 lore raw

PATCH v24 10/10 net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver

In reply to Christian Marangi

Add Airoha AN8855 5-Port Gigabit DSA switch. Switch can support 10M, 100M, 1Gb, 2.5G and 5G Ethernet Speed but 5G is currently error out as it's not currently supported as requires additional configuration for the PCS.

---
 drivers/net/dsa/mediatek/Kconfig      |   10 +
 drivers/net/dsa/mediatek/Makefile     |    1 +
 drivers/net/dsa/mediatek/an8855.c     | 1741 +++++++++++++++++++++++++
 drivers/net/dsa/mediatek/an8855.h     |  755 +++++++++++
 drivers/net/dsa/mediatek/mt7530-lib.c |   68 +-
 drivers/net/dsa/mediatek/mt7530-lib.h |   22 +
 6 files changed, 2577 insertions(+), 20 deletions(-)
 create mode 100644 drivers/net/dsa/mediatek/an8855.c
 create mode 100644 drivers/net/dsa/mediatek/an8855.h
drivers/net/dsa/mediatek/Kconfig +10 -0
index 7b48300dca0c..2799e78a8651 100644
@@ -1,4 +1,14 @@
 # SPDX-License-Identifier: GPL-2.0-only
+config NET_DSA_AN8855
+	tristate "Airoha AN8855 Ethernet switch support"
+	depends on MFD_AIROHA_AN8855 || COMPILE_TEST
+	depends on NET_DSA
+	select NET_DSA_MT7530_LIB
+	select NET_DSA_TAG_AIROHA
+	help
+	  This enables support for the Ethernet switch inside the
+	  Airoha AN8855 chip.
+
 config NET_DSA_MT7530_LIB
 	tristate
 
drivers/net/dsa/mediatek/Makefile +1 -0
index b2c0693dbb58..60e5f5cd0901 100644
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_NET_DSA_AN8855)	+= an8855.o
 obj-$(CONFIG_NET_DSA_MT7530)	+= mt7530.o
 obj-$(CONFIG_NET_DSA_MT7530_LIB) += mt7530-lib.o
 obj-$(CONFIG_NET_DSA_MT7530_MDIO) += mt7530-mdio.o
drivers/net/dsa/mediatek/an8855.c new file +1741 -0

1,741 lines not on this page · raw message

drivers/net/dsa/mediatek/an8855.h new file +755 -0

755 lines not on this page · raw message

drivers/net/dsa/mediatek/mt7530-lib.c +48 -20

134 lines not on this page · raw message

drivers/net/dsa/mediatek/mt7530-lib.h +22 -0
index da2ee781f7e6..1465eb49f4cb 100644
@@ -159,6 +159,8 @@ enum mt7530_regmap_field {
 	MT7530_ATWD_AGE_TIMER,
 	MT7530_ATWD_PORT_MAP,
 	MT7530_ATWD_ENT_STATUS,
+	AN8855_ATWD_TYPE,
+	AN8855_ATWD_VLD,
 	MT7530_ATWD_MAC_BYTE_5,
 	MT7530_ATWD_MAC_BYTE_4,
 	MT7530_ATWD_MAC_BYTE_3,
@@ -169,11 +171,13 @@ enum mt7530_regmap_field {
 	__MT7530_ATWD1,
 	__MT7530_ATWD2,
 	__MT7530_ATWD3,
+	__MT7530_ATWD4,
 
 	MT7530_ATRD_CVID,
 	MT7530_ATRD_AGE_TIMER,
 	MT7530_ATRD_PORT_MAP,
 	MT7530_ATRD_ENT_STATUS,
+	AN8855_ATRD_ARP,
 	MT7530_ATRD_MAC_BYTE_5,
 	MT7530_ATRD_MAC_BYTE_4,
 	MT7530_ATRD_MAC_BYTE_3,
@@ -201,6 +205,7 @@ enum mt7530_regmap_field {
 	MT7530_PVC_ACC_FRM,
 
 	MT7530_PPBV1_G0_PORT_VID,
+	AN8855_PVID_G0_PORT_VID,
 
 	MT7530_GMACCR_MAX_RX_JUMBO,
 	MT7530_GMACCR_MAX_RX_PKT_LEN,
@@ -223,8 +228,13 @@ enum mt7530_regmap_field {
 	MT7530_MIB_TX_PKT_SZ_256_TO_511,
 	MT7530_MIB_TX_PKT_SZ_512_TO_1023,
 	MT7530_MIB_TX_PKT_SZ_1024_TO_MAX,
+	AN8855_MIB_TX_PKT_SZ_1024_TO_1518,
+	AN8855_MIB_TX_PKT_SZ_1519_TO_MAX,
 	MT7530_MIB_TX_BYTES_LOW,
 	MT7530_MIB_TX_BYTES_HIGH,
+	AN8855_MIB_TX_OVERSIZE_DROP,
+	AN8855_MIB_TX_BAD_PKT_BYTES_LOW,
+	AN8855_MIB_TX_BAD_PKT_BYTES_HIGH,
 	MT7530_MIB_RX_DROP,
 	MT7530_MIB_RX_FILTERING,
 	MT7530_MIB_RX_UNICAST,
@@ -243,11 +253,21 @@ enum mt7530_regmap_field {
 	MT7530_MIB_RX_PKT_SZ_256_TO_511,
 	MT7530_MIB_RX_PKT_SZ_512_TO_1023,
 	MT7530_MIB_RX_PKT_SZ_1024_TO_MAX,
+	AN8855_MIB_RX_PKT_SZ_1024_TO_1518,
+	AN8855_MIB_RX_PKT_SZ_1519_TO_MAX,
 	MT7530_MIB_RX_BYTES_LOW,
 	MT7530_MIB_RX_BYTES_HIGH,
 	MT7530_MIB_RX_CTRL_DROP,
 	MT7530_MIB_RX_INGRESS_DROP,
 	MT7530_MIB_RX_ARL_DROP,
+	AN8855_MIB_FLOW_CONTROL_DROP,
+	AN8855_MIB_WRED_DROP,
+	AN8855_MIB_MIRROR_DROP,
+	AN8855_MIB_RX_BAD_PKT_BYTES_LOW,
+	AN8855_MIB_RX_BAD_PKT_BYTES_HIGH,
+	AN8855_MIB_RXS_FLOW_SAMPLING_PKT_DROP,
+	AN8855_MIB_RXS_FLOW_TOTAL_PKT_DROP,
+	AN8855_MIB_PORT_CONTROL_DROP,
 
 	MT7530_FIELD_MAX,
 };
@@ -385,6 +405,8 @@ int mt7530_lib_port_vlan_add(struct mt7530_lib_priv *priv, int port,
 int mt7530_lib_port_vlan_del(struct mt7530_lib_priv *priv, int port,
 			     const struct switchdev_obj_port_vlan *vlan);
 
+void mt7530_port_set_pvid(struct mt7530_lib_priv *priv, int port,
+			  u16 pvid);
 int mt7530_lib_setup_vlan0(struct mt7530_lib_priv *priv);
 
 #endif /* __MT7530_LIB_H */
Signature · 1 line
2.55.0
#26 lore raw

Re: [PATCH net-next v24 10/10] net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider: - [High] net: dsa: an8855: Unconditional sleep in FDB dump loop causes severe latency - [High] net: dsa…

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
- [High] net: dsa: an8855: Unconditional sleep in FDB dump loop causes severe latency
- [High] net: dsa: an8855: Missing port matrix hardware synchronization in port_enable
- [Medium] net: dsa: an8855: Failure to enable TX LPI mode when timer is non-zero
- [Medium] net: dsa: an8855: FDB dump incorrectly reports static entries as dynamic
- [Medium] net: dsa: an8855: Incorrect jumbo frame size encoding breaks MTU configuration
- [Low] net: dsa: an8855: Duplication of standard MAC statistics in ethtool -S --

commit 162cbb2c5557815ac251de80602fb068741ed063
Author: Christian Marangi <[email protected]>

net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver

Add Airoha AN8855 5-Port Gigabit DSA switch. Switch can support 10M, 100M, 1Gb, 2.5G and 5G Ethernet Speed but 5G is currently error out as it's not currently supported as requires additional configuration for the PCS.

Quoted 5 lines
drivers/net/dsa/mediatek/an8855.c new file +0 -0
index 0000000000000..b4b02b7cb6eb8 100644
@@ -0,0 +1,1741 @@

[ ... ]

drivers/net/dsa/mediatek/an8855.c line 187

Quoted 5 lines
drivers/net/dsa/mediatek/an8855.c new file +5 -0
+static const struct mt7530_mib_desc an8855_mib[] = {
+	MIB_DESC(MT7530_MIB_TX_DROP, -1, "TxDrop"),
+	MIB_DESC(MT7530_MIB_TX_CRC_ERR, -1, "TxCrcErr"),
+	MIB_DESC(MT7530_MIB_TX_COLLISION, -1, "TxCollision"),
+	MIB_DESC(AN8855_MIB_TX_OVERSIZE_DROP, -1, "TxOversizeDrop"),

[Severity: Low]
Is it necessary to include these standard statistics in the private ethtool strings?

The networking core guidelines recommend avoiding duplication in ethtool -S for counters that already have a standard uAPI (e.g., exposed via rtnl_link_stats64 or get_eth_mac_stats).

[ ... ]

Quoted 8 lines
drivers/net/dsa/mediatek/an8855.c new file +8 -0
+		/* Each banks have 4 entry */
+		for (i = 0; i < 4; i++) {
+			struct mt7530_fdb _fdb = {  };
+
+			count++;
+
+			/* Check if bank is present */
+			if (!(banks & BIT(i)))

drivers/net/dsa/mediatek/an8855.c line 387

Quoted 10 lines
drivers/net/dsa/mediatek/an8855.c new file +10 -0
+				continue;
+
+			/* Select bank entry index */
+			ret = regmap_write(priv->regmap, AN8855_ATRDS,
+					   FIELD_PREP(AN8855_ATRD_SEL, i));
+			if (ret)
+				break;
+			/* wait 1ms for the bank entry to be filled */
+			usleep_range(1000, 1500);
+			mt7530_lib_fdb_read(&priv->lib_priv, &_fdb);

[Severity: High]
Does this loop introduce too much latency?

Since the loop processes up to 2048 records and sleeps unconditionally for 1000-1500us on every valid bank entry while holding priv->reg_mutex, a full FDB dump could block all ATU/VLAN and port configurations for more than 2 seconds.

Can this be refactored to poll hardware readiness instead of relying on a hardcoded sleep?

[ ... ]

Quoted 4 lines
drivers/net/dsa/mediatek/an8855.c new file +4 -0
+static int an8855_port_enable(struct dsa_switch *ds, int port,
+			      struct phy_device *phy)
+{
+	struct an8855_priv *priv = ds->priv;

drivers/net/dsa/mediatek/an8855.c line 602

Quoted 10 lines
drivers/net/dsa/mediatek/an8855.c new file +10 -0
+	int ret;
+
+	mutex_lock(&priv->reg_mutex);
+	priv->ports[port].enable = true;
+	ret = regmap_set_bits(priv->regmap, AN8855_PMCR_P(port),
+			      AN8855_PMCR_TX_EN | AN8855_PMCR_RX_EN);
+	mutex_unlock(&priv->reg_mutex);
+
+	return ret;
+}

[Severity: High]
Can a port added to a bridge while administratively down become permanently isolated when brought up?

When a port is disabled, mt7530_update_port_member() defers writing the updated pm matrix to the hardware. Here in an8855_port_enable(), the port is enabled but the synchronized priv->ports[port].pm matrix is not written to AN8855_PORTMATRIX, which leaves the port disconnected.

[ ... ]

Quoted 3 lines
drivers/net/dsa/mediatek/an8855.c new file +3 -0
+static int an8855_phylink_mac_enable_tx_lpi(struct phylink_config *config,
+					    u32 timer, bool tx_clock_stop)
+{

[ ... ]

Quoted 1 line
drivers/net/dsa/mediatek/an8855.c new file +1 -0
+	if (timer) {

[ ... ]

Quoted 12 lines
drivers/net/dsa/mediatek/an8855.c new file +12 -0
+		ret = regmap_update_bits(priv->regmap, AN8855_CKGCR,
+					 AN8855_LPI_TXIDLE_THD_MASK, val);
+		mutex_unlock(&priv->reg_mutex);
+		if (ret) {
+			dev_err(dp->ds->dev, "failed to set global LPI timer\n");
+			return ret;
+		}
+	} else {
+		ret = regmap_set_bits(priv->regmap, AN8855_PMEEECR_P(port),
+				      AN8855_LPI_MODE_EN);
+		if (ret) {
+			dev_err(dp->ds->dev, "failed to enable LPI for port %d\n",

drivers/net/dsa/mediatek/an8855.c line 1036

Quoted 10 lines
drivers/net/dsa/mediatek/an8855.c new file +10 -0
+				port);
+			return ret;
+		}
+	}
+
+	mutex_lock(&priv->reg_mutex);
+	ret = regmap_set_bits(priv->regmap, AN8855_PMCR_P(port),
+			      AN8855_PMCR_FORCE_EEE1G |
+			      AN8855_PMCR_FORCE_EEE100);
+	mutex_unlock(&priv->reg_mutex);

[Severity: Medium]
Will TX LPI mode fail to enable if a custom idle timer is passed?

When timer != 0, the branch updates the global threshold in AN8855_CKGCR but completely skips setting the AN8855_LPI_MODE_EN bit for the port via AN8855_PMEEECR_P.

Since the disable path clears this bit, failing to set it here means the power-saving mode won't actually be enabled.

Quoted 5 lines
drivers/net/dsa/mediatek/an8855.h new file +0 -0
index 0000000000000..85003e5684509 100644
@@ -0,0 +1,755 @@

[ ... ]

drivers/net/dsa/mediatek/an8855.h line 455

Quoted 3 lines
drivers/net/dsa/mediatek/an8855.h new file +3 -0
+#define   AN8855_MAX_RX_JUMBO_12K	FIELD_PREP_CONST(AN8855_MAX_RX_JUMBO, 0xa)
+#define   AN8855_MAX_RX_JUMBO_15K	FIELD_PREP_CONST(AN8855_MAX_RX_JUMBO, 0xb)
+#define   AN8855_MAX_RX_JUMBO_16K	FIELD_PREP_CONST(AN8855_MAX_RX_JUMBO, 0xc)

[Severity: Medium]
Is it possible that jumbo frame MTU configuration will break for frames

Quoted 1 line

= 12K?

The shared MT7530 library computes the jumbo size encoding using a linear
division: DIV_ROUND_UP(length, 1024). For a 15K frame, this produces 0xF.

However, the AN8855 hardware uses a custom non-linear encoding where 15K is 0xB. Passing 0xF will program an invalid or undefined value to the hardware, causing reception of jumbo frames to fail.

Quoted 9 lines
drivers/net/dsa/mediatek/mt7530-lib.c +0 -1
index 098dd45d3ee9f..4325768033325 100644
@@ -483,8 +497,14 @@ void mt7530_lib_fdb_read(struct mt7530_lib_priv *priv, struct mt7530_fdb *fdb)
 	fdb->mac[1] = val;
 	regmap_field_read(priv->fields[MT7530_ATRD_MAC_BYTE_0], &val);
 	fdb->mac[0] = val;
-	regmap_field_read(priv->fields[MT7530_ATRD_ENT_STATUS], &val);

drivers/net/dsa/mediatek/mt7530-lib.c void mt7530_lib_fdb_read(struct mt7530_lib_priv *priv, struct mt7530_fdb *fdb) · line 508

Quoted 10 lines
drivers/net/dsa/mediatek/mt7530-lib.c +8 -1
-	fdb->noarp = val == STATIC_ENT;
+	if (priv->fields[MT7530_ATRD_ENT_STATUS]) {
+		regmap_field_read(priv->fields[MT7530_ATRD_ENT_STATUS], &val);
+		fdb->noarp = val == STATIC_ENT;
+	}
+	if (priv->fields[AN8855_ATRD_ARP]) {
+		regmap_field_read(priv->fields[AN8855_ATRD_ARP], &val);
+		fdb->noarp = !!val;
+	}
 }

[Severity: Medium]
Will this incorrectly report static entries as dynamic during an FDB dump?

The read path evaluates fdb->noarp from the AN8855_ATRD_ARP field. However, when writing a static entry, the type is set via AN8855_ATWD_TYPE (0 for static) and no ARP field is manipulated.

Because this reads an unrelated ARP field instead of the TYPE field, an8855_port_fdb_dump() will falsely compute and report the static flag to the bridge.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
#27 lore raw

Re: [PATCH net-next v24 10/10] net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver

In reply to Christian Marangi
Thank you for your contribution! Sashiko AI review found 12 potential issue(s) to consider.

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

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

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

- [High] In the AN8855 driver, the shared VLAN read-modify-write path reads the VLAN write-data register (AN8855_VAWD0) back, not the read-…
- [High] an8855_port_enable() sets ports[port].enable and turns on PMCR TX/RX, but it never writes the cached forwarding matrix…
- [Medium] mt7530_lib_port_change_mtu() writes DIV_ROUND_UP(length, 1024) into MT7530_GMACCR_MAX_RX_JUMBO.
- [Medium] an8855_set_mac_eee() rejects any tx_lpi_timer > 0xFFF (4095 us).
- [Medium] The new an8855_mib table exposes, as private ethtool -S strings, counters that already have standard uAPI homes, and the…
- [Medium] an8855_setup() clears the AN8855_UNIPMF (IP unknown-multicast flood) bit for every user port, and nothing sets it again.
- [Medium] an8855_pcs_config() updates AN8855_PLL_CTRL_2 with AN8855_RG_DA_QP_PLL_SDM_HREN_INTF, a field an8855.h defines in…
- [Medium] SGMII without in-band negotiation is always forced to 1000 Mb/s in the PCS.
- [Medium] an8855_port_fdb_dump() declares 'u32 rsp;' without initialising it and passes it to mt7530_lib_fdb_cmd().
- [Low] NET_DSA_AN8855 can be enabled with COMPILE_TEST and CONFIG_REGMAP=n.
- [Low] an8855_pcs_config() changes several mode-specific SerDes/PCS bits in one direction only.
- [Low] an8855_rmon_ranges gives the top RMON histogram bucket as { 1519, AN8855_MAX_MTU }.

--

net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver

This patch adds a DSA driver for the switch inside the Airoha AN8855. It reuses the shared mt7530-lib helpers through a per-chip regmap_field table, and it extends the lib with several AN8855-specific fields. It also adds a PCS for the SGMII/2500base-X CPU port and EEE support.

drivers/net/dsa/mediatek/Kconfig line 7

Quoted 12 lines
drivers/net/dsa/mediatek/Kconfig +6 -0
index 7b48300dca0c5..2799e78a86517 100644
@@ -1,4 +1,14 @@
 # SPDX-License-Identifier: GPL-2.0-only
+config NET_DSA_AN8855
+	tristate "Airoha AN8855 Ethernet switch support"
+	depends on MFD_AIROHA_AN8855 || COMPILE_TEST
+	depends on NET_DSA
+	select NET_DSA_MT7530_LIB
+	select NET_DSA_TAG_AIROHA

[Severity: Low]
Can this fail to build with COMPILE_TEST=y, MFD_AIROHA_AN8855=n and CONFIG_REGMAP=n?

REGMAP is only guaranteed through the select REGMAP in MFD_AIROHA_AN8855. Neither NET_DSA_MT7530_LIB nor NET_DSA selects it.

In include/linux/regmap.h, struct reg_field and devm_regmap_field_alloc() only exist under CONFIG_REGMAP, and there are no stubs for them. struct mt7530_reg_field and an8855_setup_lib_priv() use both.

Is a select REGMAP needed on NET_DSA_AN8855 or NET_DSA_MT7530_LIB?

Quoted 6 lines
drivers/net/dsa/mediatek/an8855.c new file +0 -0
new file mode 100644
index 0000000000000..b4b02b7cb6eb8
@@ -0,0 +1,1741 @@

[ ... ]

drivers/net/dsa/mediatek/an8855.c line 61

Quoted 10 lines
drivers/net/dsa/mediatek/an8855.c new file +10 -0
+	{ MT7530_VAWD_IVL_MAC, REG_FIELD(AN8855_VAWD0, 5, 5) },
+	{ MT7530_VAWD_EG_CON, REG_FIELD(AN8855_VAWD0, 11, 11) },
+	{ MT7530_VAWD_VTAG_EN, REG_FIELD(AN8855_VAWD0, 10, 10) },
+	{ MT7530_VAWD_PORT_MEM, REG_FIELD(AN8855_VAWD0, 26, 31) },
+	{ MT7530_VAWD_FID, REG_FIELD(AN8855_VAWD0, 1, 4) },
+	{ MT7530_VAWD_VLAN_VALID, REG_FIELD(AN8855_VAWD0, 0, 0) },
+	{ __MT7530_VAWD1, REG_FIELD(AN8855_VAWD0, 0, 31) },
+
+	{ MT7530_VAWD_ETAG, REG_FIELD(AN8855_VAWD0, 12, 23) },
+	{ __MT7530_VAWD2, REG_FIELD(AN8855_VAWD1, 0, 31) },

[Severity: High]
On AN8855, do the VLAN read-modify-write paths in mt7530-lib.c read back the correct register?

After the VTCR read command, mt7530_hw_vlan_update() reads the entry through the VAWD fields:

mt7530_hw_vlan_update() {
    ...
    mt7530_vlan_cmd(priv, MT7530_VTCR_RD_VID, vid);

    regmap_field_read(priv->fields[MT7530_VAWD_PORT_MEM], &val);
    entry->old_members = val;
    ...
}

mt7530_hw_vlan_del() also checks:

    regmap_field_read(priv->fields[MT7530_VAWD_VLAN_VALID], &val);
    if (!val) {

In this table all of those fields map to AN8855_VAWD0, which is the write-data register. an8855.h defines a read-data register, but nothing uses it:

/* Same register field of VAWD0 */
#define AN8855_VARD0 0x10200618

If the hardware puts the read result in VARD0, the fetched entry is whatever was last written to VAWD0. For example, an8855_setup() ends with mt7530_lib_setup_vlan0(), which leaves PORT_MEM set to all members and VALID=1. The first bridge VLAN add would then read old_members as all ports.

Could this make ports members of VIDs they were never added to, or carry ETAG bits from one VID to another?

Could it also let mt7530_hw_vlan_del() see a stale VALID=0, after which WR_VID writes stale data over a live VLAN?

Quoted 4 lines
drivers/net/dsa/mediatek/an8855.c new file +4 -0
+static const struct mt7530_mib_desc an8855_mib[] = {
+	MIB_DESC(MT7530_MIB_TX_DROP, -1, "TxDrop"),
+	MIB_DESC(MT7530_MIB_TX_CRC_ERR, -1, "TxCrcErr"),
+	MIB_DESC(MT7530_MIB_TX_COLLISION, -1, "TxCollision"),

[ ... ]

drivers/net/dsa/mediatek/an8855.c line 192

Quoted 3 lines
drivers/net/dsa/mediatek/an8855.c new file +3 -0
+	MIB_DESC(MT7530_MIB_RX_DROP, -1, "RxDrop"),
+	MIB_DESC(MT7530_MIB_RX_FILTERING, -1, "RxFiltering"),
+	MIB_DESC(MT7530_MIB_RX_CRC_ERR, -1, "RxCrcErr"),

[Severity: Medium]
Should some of these counters go through the standard interfaces rather than ethtool -S?

RxCrcErr matches the eth-mac FrameCheckSequenceErrors counter and rtnl_link_stats64.rx_crc_errors. TxCollision matches collisions, and RxDrop/TxDrop match rx_dropped/tx_dropped.

mt7530_lib_get_eth_mac_stats() never fills FrameCheckSequenceErrors. an8855_switch_ops also has no .get_stats64, while mt7530.c implements mt7530_get_stats64() from the same MIB.

[ ... ]

Quoted 8 lines
drivers/net/dsa/mediatek/an8855.c new file +8 -0
+static int an8855_port_fdb_dump(struct dsa_switch *ds, int port,
+				dsa_fdb_dump_cb_t *cb, void *data)
+{
+	struct an8855_priv *priv = ds->priv;
+	int banks, count = 0;
+	u32 rsp;
+	int ret;
+	int i;

[ ... ]

drivers/net/dsa/mediatek/an8855.c line 366

Quoted 8 lines
drivers/net/dsa/mediatek/an8855.c new file +8 -0
+	ret = mt7530_lib_fdb_cmd(&priv->lib_priv, MT7530_FDB_START,
+				 AN8855_FDB_MAT_MAC_PORT, &rsp);
+	if (ret < 0)
+		goto exit;
+
+	do {
+		/* From response get the number of banks to read, exit if 0 */
+		banks = FIELD_GET(AN8855_ATC_HIT, rsp);

[Severity: Medium]
Can rsp be used uninitialized here?

mt7530_lib_fdb_cmd() ignores the result of its final read and returns 0 anyway:

    if (rsp)
        regmap_field_read(priv->fields[__MT7530_ATC], rsp);

    return 0;

regmap_field_read() leaves *val untouched when it fails. If that read fails after FDB_START, FIELD_GET() runs on an uninitialized stack value. After FDB_NEXT it would run on a stale value.

Should rsp be initialized, or should mt7530_lib_fdb_cmd() return the read error?

[ ... ]

drivers/net/dsa/mediatek/an8855.c line 467

Quoted 4 lines
drivers/net/dsa/mediatek/an8855.c new file +4 -0
+static int an8855_port_max_mtu(struct dsa_switch *ds, int port)
+{
+	return AN8855_MAX_MTU;
+}

[Severity: Medium]
Does mt7530_lib_port_change_mtu() program a valid jumbo value on AN8855?

It writes the MT7530 linear encoding:

    regmap_field_write(priv->fields[MT7530_GMACCR_MAX_RX_JUMBO],
                       DIV_ROUND_UP(length, 1024));

an8855.h documents a non-linear encoding for this field:

#define   AN8855_MAX_RX_JUMBO_9K	FIELD_PREP_CONST(AN8855_MAX_RX_JUMBO, 0x9)
#define   AN8855_MAX_RX_JUMBO_12K	FIELD_PREP_CONST(AN8855_MAX_RX_JUMBO, 0xa)
#define   AN8855_MAX_RX_JUMBO_15K	FIELD_PREP_CONST(AN8855_MAX_RX_JUMBO, 0xb)
#define   AN8855_MAX_RX_JUMBO_16K	FIELD_PREP_CONST(AN8855_MAX_RX_JUMBO, 0xc)

At AN8855_MAX_MTU, length is 15338 + 14 + 4 + 4 = 15360, so 0xf gets written, and that value is not defined.

More generally, frame lengths from 12289 to 15360 give 0xd-0xf. Lengths from 9217 to 12288 give 0xa-0xc, which the hardware would read as 12K/15K/16K.

[ ... ]

Quoted 1 line

+static const struct ethtool_rmon_hist_range an8855_rmon_ranges[] = {

[ ... ]

drivers/net/dsa/mediatek/an8855.c line 528

Quoted 4 lines
drivers/net/dsa/mediatek/an8855.c new file +4 -0
+	{ 1024, 1518 },
+	{ 1519, AN8855_MAX_MTU },
+	{}
+};

[Severity: Low]
Should the top bucket's upper bound be a frame length?

The other buckets are frame lengths in octets. AN8855_MAX_MTU (15338) is an L3 MTU, while the PKT_SZ_1519_TO_MAX counter counts frames up to 15360 bytes.

[ ... ]

Quoted 4 lines
drivers/net/dsa/mediatek/an8855.c new file +4 -0
+static int an8855_port_enable(struct dsa_switch *ds, int port,
+			      struct phy_device *phy)
+{
+	struct an8855_priv *priv = ds->priv;

drivers/net/dsa/mediatek/an8855.c line 602

Quoted 10 lines
drivers/net/dsa/mediatek/an8855.c new file +10 -0
+	int ret;
+
+	mutex_lock(&priv->reg_mutex);
+	priv->ports[port].enable = true;
+	ret = regmap_set_bits(priv->regmap, AN8855_PMCR_P(port),
+			      AN8855_PMCR_TX_EN | AN8855_PMCR_RX_EN);
+	mutex_unlock(&priv->reg_mutex);
+
+	return ret;
+}

[Severity: High]
Should this also write the cached port matrix to hardware?

mt7530_update_port_member() skips the hardware write for disabled ports:

    if (priv->ports[port].enable)
        regmap_fields_write(priv->fields[MT7530_PCR_MATRIX],
                            port, port_bitmap);

mt7530_port_enable() in mt7530.c then applies it when the port comes up:

    regmap_update_bits(priv->regmap, MT7530_PCR_P(port), PCR_MATRIX_MASK,
                       PCR_MATRIX(priv->ports[port].pm));

an8855_setup() calls an8855_port_disable() for every user port, so every port starts with enable=false.

If a port joins a bridge, or is marked isolated, while it is down, does that matrix ever reach AN8855_PORTMATRIX_P(port)?

If not, bridged ports would not forward to each other in hardware, and an isolated port would still reach its peers.

[ ... ]

drivers/net/dsa/mediatek/an8855.c line 625

Quoted 8 lines
drivers/net/dsa/mediatek/an8855.c new file +8 -0
+static int an8855_set_mac_eee(struct dsa_switch *ds, int port,
+			      struct ethtool_keee *e)
+{
+	if (e->tx_lpi_timer > 0xFFF)
+		return -EINVAL;
+
+	return 0;
+}

[Severity: Medium]
Is the 0xFFF limit from MT7530 right for AN8855?

an8855_phylink_get_caps() reports the default timer from the 18-bit AN8855_LPI_TXIDLE_THD_MASK field, in 2us units:

    config->lpi_timer_default = FIELD_GET(AN8855_LPI_TXIDLE_THD_MASK, reg) *
                                AN8855_TX_LPI_UNIT;

That comes to about 60000us, and phylink reports it via get_eee.

ethtool set-eee does a get-modify-set. dsa_user_set_eee() therefore passes the unchanged 60000us timer to set_mac_eee(), and the request is aborted with -EINVAL.

Wouldn't that make "ethtool --set-eee lanX eee off" fail unless tx-timer is also lowered to 4095 or less?

an8855_phylink_mac_enable_tx_lpi() accepts timers up to the full 18-bit field and clamps them.

[ ... ]

drivers/net/dsa/mediatek/an8855.c line 670

Quoted 8 lines
drivers/net/dsa/mediatek/an8855.c new file +8 -0
+		/* Disable Unknown Multicast Forward on user ports */
+		ret = regmap_clear_bits(priv->regmap, AN8855_UNMF, BIT(dp->index));
+		if (ret)
+			return ret;
+
+		ret = regmap_clear_bits(priv->regmap, AN8855_UNIPMF, BIT(dp->index));
+		if (ret)
+			return ret;

[Severity: Medium]
What sets a user port's AN8855_UNIPMF bit again after this?

an8855_port_pre_bridge_flags() accepts BR_MCAST_FLOOD, but mt7530_lib_port_bridge_flags() only updates the UNMF mask:

if (flags.mask & BR_MCAST_FLOOD)
regmap_field_update_bits(priv->fields[MT7530_UNM_FFP],

With this, is unknown IP multicast still not flooded between bridged user ports when mcast_flood is on, which is the bridge default?

[ ... ]

drivers/net/dsa/mediatek/an8855.c line 1220

Quoted 6 lines
drivers/net/dsa/mediatek/an8855.c new file +6 -0
+	/* PLL - SDM */
+	ret = regmap_update_bits(priv->regmap, AN8855_PLL_CTRL_2,
+				 AN8855_RG_DA_QP_PLL_SDM_HREN_INTF,
+				 FIELD_PREP(AN8855_RG_DA_QP_PLL_SDM_HREN_INTF, 0x0));
+	if (ret)
+		return ret;

[Severity: Medium]
Should this register be AN8855_PLL_CTRL_4?

an8855.h defines the field under PLL_CTRL_4:

#define AN8855_PLL_CTRL_4 0x1022e410
#define AN8855_RG_DA_QP_PLL_SDM_HREN_INTF GENMASK(4, 3)

In PLL_CTRL_2, bits 4:2 hold AN8855_RG_DA_QP_PLL_BPA_INTF, which the "PLL - LPF" step just set to 0x5.

Clearing bits 4:3 here changes BPA to 0x1, and SDM_HREN in PLL_CTRL_4 is never written.

[ ... ]

drivers/net/dsa/mediatek/an8855.c line 1490

Quoted 7 lines
drivers/net/dsa/mediatek/an8855.c new file +7 -0
+		} else {
+			ret = regmap_update_bits(priv->regmap, AN8855_RG_AN_SGMII_MODE_FORCE,
+						 AN8855_RG_FORCE_CUR_SGMII_MODE |
+						 AN8855_RG_FORCE_CUR_SGMII_SEL,
+						 AN8855_RG_FORCE_CUR_SGMII_SEL);
+			if (ret)
+				return ret;

[Severity: Low]
Several mode-specific bits in an8855_pcs_config() only ever change in one direction.

These are only set: FORCE_TXC_SEL, FORCE_SPD_MODE_P0, FORCE_CUR_SGMII_SEL, P0_MII_MODE, P0_RA_AN_EN and FORCE_AN_DONE.

These are only cleared: SGMII_MODE/SGMII_AN_EN, P0_DIS_MII_MODE and P0_MII_RA_*.

For example, FORCE_SPD_MODE_P0 is set for forced SGMII but never cleared for in-band SGMII.

Could moving between in-band SGMII, forced SGMII and 2500base-X, or starting from a PCS the bootloader configured, leave a mix of register state from two modes?

[ ... ]

drivers/net/dsa/mediatek/an8855.c line 1543

Quoted 7 lines
drivers/net/dsa/mediatek/an8855.c new file +7 -0
+	/* Force Speed with fixed-link or 2500base-x as doesn't support aneg */
+	if (interface == PHY_INTERFACE_MODE_2500BASEX ||
+	    neg_mode != PHYLINK_PCS_NEG_INBAND_ENABLED) {
+		if (interface == PHY_INTERFACE_MODE_2500BASEX)
+			val = AN8855_RG_LINK_MODE_P0_SPEED_2500;
+		else
+			val = AN8855_RG_LINK_MODE_P0_SPEED_1000;

[Severity: Medium]
Does SGMII without in-band negotiation work at 10/100?

an8855_phylink_get_caps() advertises MAC_10 | MAC_100 along with SGMII on port 5, but this code always forces the PCS to 1000.

an8855_phylink_mac_link_up() only updates PMCR, and an8855_pcs_ops has no .pcs_link_up to program the resolved speed into the PCS.

With a 10/100 fixed-link, or an out-of-band PHY that resolves to 10/100, would the PCS stay at 1000 while the MAC runs at the lower speed?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928194511.41878-1-ansuelsmth%40gmail.com