Skip to contentSkip to conversation

net: dsa: Add Airoha AN8855 support

PATCH Superseded Christian Marangi 4 participants 32 messages Sep 25 – Sep 29

Subsystems (8)

v23 of 25 Superseded Latest is v25 →

lore
Share & tools
lore
#0 lore raw

v23 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 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 (9):
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: 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                                   |   16 +
 drivers/mfd/Kconfig                           |   14 +
 drivers/mfd/Makefile                          |    1 +
 drivers/mfd/airoha-an8855.c                   |  580 ++++++
 drivers/net/dsa/Kconfig                       |   14 +
 drivers/net/dsa/Makefile                      |    2 +
 drivers/net/dsa/an8855.c                      | 1740 +++++++++++++++++
 drivers/net/dsa/an8855.h                      |  755 +++++++
 drivers/net/dsa/mt7530-lib.c                  | 1156 +++++++++++
 drivers/net/dsa/mt7530-lib.h                  |  413 ++++
 drivers/net/dsa/mt7530-mdio.c                 |    4 +
 drivers/net/dsa/mt7530-mmio.c                 |    4 +
 drivers/net/dsa/mt7530.c                      | 1368 +++----------
 drivers/net/dsa/mt7530.h                      |  256 +--
 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 +-
 24 files changed, 5754 insertions(+), 1247 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/an8855.c
 create mode 100644 drivers/net/dsa/an8855.h
 create mode 100644 drivers/net/dsa/mt7530-lib.c
 create mode 100644 drivers/net/dsa/mt7530-lib.h
 create mode 100644 drivers/net/phy/air_an8855.c
Signature · 1 line
2.55.0
#1 lore raw

PATCH v23 1/9 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 v23 1/9] 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 will cause dt_binding_check to fail --

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

commit 149759f83399f8efe1a862e7d0f5637ed4300bbc
Author: Christian Marangi <[email protected]>

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

This commit introduces a new YAML device tree binding to document support for the Airoha AN8855 5-port Gigabit Switch. It describes the exposed internal PHYs on the MDIO bus.

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 example pass make dt_binding_check? The device tree compiler strictly checks for label existence, and it looks like the internal_phy1 label (along with the other phy labels) is not defined within this example block. This might cause dtc to report a fatal "Reference to non-existent node or label" error during the validation build.

Quoted 1 line

+ };

[ ... ]

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

Quoted 11 lines
Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml new file +11 -0
+            port@4 {
+                reg = <4>;
+                label = "wan";
+                phy-mode = "internal";
+                phy-handle = <&internal_phy5>;
+            };
+
+            port@5 {
+                reg = <5>;
+                label = "cpu";
+                ethernet = <&gmac0>;

[Severity: Low]
Similar to the phy-handle references, is the gmac0 label defined in this example? Leaving this undefined could also trigger a reference compilation error when the example is extracted and built.

Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml new file +10 -0
+                phy-mode = "2500base-x";
+
+                fixed-link {
+                    speed = <2500>;
+                    full-duplex;
+                    pause;
+                };
+            };
+        };
+    };
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

PATCH v23 2/9 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
#4 lore raw

Re: [PATCH net-next v23 2/9] 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
#5 lore raw

Re: [PATCH net-next v23 2/9] 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 of the new binding Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml…
- [Low] In the example of Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml, the PHY…

--

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

This adds a binding for the internal PHYs of the Airoha AN8855 5-port Gigabit switch, which are exposed on the MDIO bus. It also documents optional nvmem-cells, which point at eFUSE cells used to calibrate each PHY.

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 this be "ethernet-phy-ieee802.3-c22"? The same pair is used for ethernet-phy@2 below.

The rest of the series treats these PHYs as Clause 22 only. The MFD binding in mfd/airoha,an8855.yaml uses "ethernet-phy-ieee802.3-c22" for the same PHYs. The PHY driver in drivers/net/phy/air_an8855.c relies on Clause 22 register 0x1f paging and has no Clause 45 callbacks.

When the c45 compatible is present, fwnode_mdiobus_register_phy() ignores the fixed PHY ID:

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);
    ...
}

The per-PHY buses that an8855_core_probe() creates come from devm_mdio_regmap_register(). That function only sets Clause 22 accessors:

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

Since read_c45 is never set, this chain fails:

get_phy_device(bus, addr, true)
get_phy_c45_ids()

    mdiobus_c45_read() -> -EOPNOTSUPP

-> -EIO

After that, fwnode_mdiobus_register_phy() fails and an8855_core_probe() jumps to err_put_fwnodes. The whole AN8855 MFD then fails to probe, including the switch and the efuse.

The schema accepts either compatible, so dt_binding_check won't catch a board DT that copies this example.

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 the port 0 calibration cells here?

Later in the series, an8855_phy_bus_register() maps a PHY to a switch port with phy_offset = addr - priv->switch_addr. This example also has a PHY at address 1, so ethernet-phy@2 can't be port 0.

The sibling bindings agree:

- dsa/airoha,an8855-switch.yaml maps port@0 to internal_phy1 and port@1 to internal_phy2.
- mfd/airoha,an8855.yaml puts the shift_sel_port0_* cells on ethernet-phy@1 and the shift_sel_port1_* cells on ethernet-phy@2.

an8855_config_init() writes whatever cells it gets into AN8855_PHY_R50OHM_RSEL_TX_AB/CD. If a board DT copies this example, the port 1 PHY would silently get the port 0 TX calibration.

Should the cells either move to ethernet-phy@1, or be renamed to shift_sel_port1_*?

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/20260925182435.21207-1-ansuelsmth%40gmail.com
#6 lore raw

PATCH v23 3/9 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
#7 lore raw

Re: [PATCH net-next v23 3/9] 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
#8 lore raw

Re: [PATCH net-next v23 3/9] dt-bindings: mfd: Document support for Airoha AN8855 Switch SoC

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

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

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

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

- [Medium] Two bindings added in this series disagree on which MDIO clause the same AN8855 internal PHY (ethernet-phy-idc0ff.0410) uses.

--

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

This commit adds a DT binding for the Airoha AN8855 Switch SoC. The SoC exposes an Ethernet switch, an efuse NVMEM provider and internal Ethernet PHYs on an mdio subnode. The example shows the full layout, including the nvmem cells the internal PHYs use.

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

[ ... ]

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 describes the internal PHY (ethernet-phy-idc0ff.0410) as ethernet-phy-ieee802.3-c22. The PHY binding added later in this series, Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml, describes the same PHY as ethernet-phy-ieee802.3-c45 in its ethernet-phy@1 and ethernet-phy@2 examples. Which one is intended?

The drivers later in the series suggest c22 is correct. The MFD core registers each PHY on an mdio-regmap bus, and devm_mdio_regmap_register() sets up only the C22 ops:

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

bus->read_c45 is never set.

Now take a board DT that copies the c45 example from the PHY binding. an8855_core_probe() would register each PHY like this:

an8855_core_probe()
fwnode_mdiobus_register_phy() /* is_c45 = true */

    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_devs_in_pkg() turns that error into -EIO. The failure then goes through err_put_fwnodes in an8855_core_probe().

Wouldn't that fail the whole AN8855 core probe, and with it the switch and efuse children? The schema can't catch this because both compatibles are valid under ethernet-phy.yaml.

This example looks correct. Should the c45 examples in airoha,an8855-phy.yaml be changed to c22 so the two bindings match?

Quoted 12 lines
Documentation/devicetree/bindings/mfd/airoha,an8855.yaml new file +12 -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 {
+                  compatible = "ethernet-phy-idc0ff.0410",
+                               "ethernet-phy-ieee802.3-c22";

[ ... ]

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

PATCH v23 4/9 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 | 580 ++++++++++++++++++++++++++++++++++++
 3 files changed, 595 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 +580 -0

580 lines not on this page · raw message

Signature · 1 line
2.55.0
#10 lore raw

Re: [PATCH net-next v23 4/9] mfd: an8855: Add support for Airoha AN8855 Switch

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] of: memory leak of mdio_np in an8855_mdio_register error path - [Medium] mfd: sysfs naming…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] of: memory leak of mdio_np in an8855_mdio_register error path
- [Medium] mfd: sysfs naming collision for virtual MDIO bus with multiple switches --

commit 802b31a10a6859408359f548c9b38d422fd3e7dc
Author: Christian Marangi <[email protected]>
Subject: mfd: an8855: Add support for Airoha AN8855 Switch

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.

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

[ ... ]

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 439

Quoted 5 lines
drivers/mfd/airoha-an8855.c new file +5 -0
+	mrc.regmap = regmap;
+	mrc.parent = dev;
+	mrc.valid_addr = addr;
+	snprintf(mrc.name, MII_BUS_ID_SIZE, "an8855:%u-phy%u", priv->switch_addr,
+		 phy_offset);

[Severity: Medium]
Will this static naming scheme fail to disambiguate virtual buses across multiple independent parent devices?

If a system contains multiple AN8855 switches on different MDIO buses but configured at the same MDIO address (e.g., address 0), priv->switch_addr will be identical for both.

Since devm_mdio_regmap_register attempts to register both virtual buses with the exact same name (e.g., an8855:0-phy0), would this lead to a sysfs naming collision and cause the second switch to fail probe? A parent device identifier like dev_name(dev) might be needed to ensure uniqueness.

Quoted 2 lines
drivers/mfd/airoha-an8855.c new file +2 -0
+
+	bus = devm_mdio_regmap_register(dev, &mrc);

[ ... ]

drivers/mfd/airoha-an8855.c line 462

Quoted 8 lines
drivers/mfd/airoha-an8855.c new file +8 -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");

[Severity: Medium]
Does this code leak the mdio_np device node on the error path?

of_get_child_by_name dynamically acquires and increments the reference count of the returned device node mdio_np.

Quoted 9 lines
drivers/mfd/airoha-an8855.c new file +9 -0
+	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;
+		}
+

drivers/mfd/airoha-an8855.c line 481

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++;
+	}
+
+	of_node_put(mdio_np);
+exit:

In the normal execution path, of_node_put(mdio_np) is correctly called. However, if an error occurs during child node iteration, the code executes goto exit, which jumps directly to the cleanup block and bypasses of_node_put(mdio_np), leaving the reference count incremented.

Quoted 9 lines
drivers/mfd/airoha-an8855.c new file +9 -0
+	if (ret) {
+		while (i--)
+			fwnode_handle_put(phy_bus_infos[i].node);
+
+		return ret;
+	}
+
+	return i;
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#11 lore raw

Re: [PATCH net-next v23 4/9] mfd: an8855: Add support for Airoha AN8855 Switch

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: 0 · Medium: 5 · 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] The patch adds MFD_AIROHA_AN8855, and both the commit message and the Kconfig help say this MFD provides an NVMEM provider.
- [Medium] an8855_phy_bus_register() names each virtual MDIO bus with snprintf(mrc.name, MII_BUS_ID_SIZE, "an8855:%u-phy%u",…
- [Medium] an8855_phy_bus_register() reads the PHY address from DT "reg" and only checks `phy_offset = addr - priv->switch_addr; if (phy_offset…
- [Medium] In an8855_mdio_register(), of_node_put(mdio_np) comes before the 'exit:' label.
- [Medium] The MFD binding puts reset-gpios on the core airoha,an8855 node, and its example wires reset-gpios = <&pio 39 GPIO_ACTIVE_HIGH>.
- [Low] The MFD binding (airoha,an8855.yaml) leaves the 'efuse' child
optional: required is compatible, reg, mdio, ethernet-switch.
- [Low] Both examples in the AN8855 PHY binding (airoha,an8855-phy.yaml) use "ethernet-phy-idc0ff.0410", "ethernet-phy-ieee802.3-c45".
- [Low] an8855_core_probe() clears AN8855_RG_GPHY_AFE_PWD ("Release global PHY power down") before registering the PHYs and the MFD…

--

mfd: an8855: Add support for Airoha AN8855 Switch

This adds an MFD core driver for the Airoha AN8855 switch, which is accessed over MDIO. It adds a paged regmap for the switch registers and one mdio-regmap bus for each internal PHY. It also registers eFuse and DSA switch child cells.

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]
The help text and the commit message both say this provides an NVMEM provider. However, NVMEM_AN8855_EFUSE in drivers/nvmem/Kconfig still only has:

depends on COMPILE_TEST

It was reduced to that by commit 4796eaafd6a1 ("nvmem: an8855: drop an unused Kconfig symbol"), because MFD_AIROHA_AN8855 was referenced but never defined.

Now that this patch defines the symbol, should the nvmem entry go back to "depends on MFD_AIROHA_AN8855 || COMPILE_TEST"? NET_DSA_AN8855, added later in the series, already uses that form.

As it stands, the eFuse driver can't be enabled when COMPILE_TEST is not set. That leaves the an8855-efuse cell with no driver to bind. The PHY nodes' nvmem-cells (tx_a..tx_d) then point at a provider that never registers, so an8855_probe()->an8855_get_r50ohm_val() in the AN8855 PHY driver can't get its calibration cells.

[ ... ]

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

[ ... ]

drivers/mfd/airoha-an8855.c line 76

Quoted 3 lines
drivers/mfd/airoha-an8855.c new file +3 -0
+static const struct mfd_cell an8855_cells[] = {
+	MFD_CELL_OF("an8855-efuse", NULL, NULL, 0, 0,
+		    "airoha,an8855-efuse"),

[Severity: Low]
The MFD binding (airoha,an8855.yaml) makes the efuse child optional. Its required list is compatible, reg, mdio and ethernet-switch. This cell is still registered every time.

When the DT has no efuse node, won't mfd_add_device() print a "Failed to locate of_node" warning and register the platform device anyway? The efuse driver would then bind by platform name and register an NVMEM device that the DT never described.

Quoted 3 lines
drivers/mfd/airoha-an8855.c new file +3 -0
+	MFD_CELL_OF("an8855-switch", NULL, NULL, 0, 0,
+		    "airoha,an8855-switch"),
+};

[ ... ]

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 addr ever checked against PHY_MAX_ADDR? The only check here is relative to switch_addr. If the switch sits at MDIO address 28..31, a child reg of 32..35 passes.

That addr goes straight to fwnode_mdiobus_register_phy() in an8855_core_probe(), which skips the of_mdio_parse_addr() check done on the normal OF MDIO path. For a C22 compatible such as ethernet-phy-idc0ff.0410, the call chain is:

an8855_core_probe()
fwnode_mdiobus_register_phy(bus, node, addr)

    phy_device_create(bus, addr, ...)
      dev->irq = bus->irq[addr];
    fwnode_mdiobus_phy_device_register()
      mdio->irq[addr] = rc;
      mdio->phy_ignore_ta_mask |= 1 << addr;
      phy_device_register()
        mdiobus_register_device()
          mdiodev->bus->mdio_map[mdiodev->addr] = mdiodev;

Could this read and write past the end of bus->irq[] and bus->mdio_map[]? Those writes could overwrite later fields of struct mii_bus, such as reset_delay_us, reset_post_delay_us or reset_gpiod.

Such a DT would violate mdio.yaml (reg maximum 31), but nothing enforces that at runtime.

[ ... ]

drivers/mfd/airoha-an8855.c line 443

Quoted 9 lines
drivers/mfd/airoha-an8855.c new file +9 -0
+	mrc.regmap = regmap;
+	mrc.parent = dev;
+	mrc.valid_addr = addr;
+	snprintf(mrc.name, MII_BUS_ID_SIZE, "an8855:%u-phy%u", priv->switch_addr,
+		 phy_offset);
+
+	bus = devm_mdio_regmap_register(dev, &mrc);
+	if (IS_ERR(bus))
+		return PTR_ERR(bus);

[Severity: Medium]
Can two AN8855 chips on different host MDIO buses end up with the same mii_bus name? The name is built only from switch_addr and phy_offset. Two switches at the same address on two MACs would therefore both produce the same "an8855:<addr>-phy<n>" names.

devm_mdio_regmap_register() copies this into mii->id, and __mdiobus_register() then does:

	dev_set_name(&bus->dev, "%s", bus->id);

The bus is in mdio_bus_class, so the second device_add() looks like it would fail with -EEXIST. The whole second an8855_core_probe() would fail with it. PHY device names built with PHY_ID_FMT would collide in the same way.

Could the name include something unique to the parent, such as dev_name(dev)?

[ ... ]

Quoted 17 lines
drivers/mfd/airoha-an8855.c new file +17 -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;
+		}
+

drivers/mfd/airoha-an8855.c line 481

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++;
+	}
+
+	of_node_put(mdio_np);
+exit:

[Severity: Medium]
Does this leak the reference on mdio_np taken by of_get_child_by_name()? of_node_put(mdio_np) sits above the exit label. Both gotos inside the loop skip it: the one for too many children and the one for an8855_phy_bus_register() failing.

This function also mixes goto-based cleanup with the __free(device_node) scoped iterator from for_each_available_child_of_node_scoped(). include/linux/cleanup.h asks that goto and cleanup helpers not be mixed in the same function.

Would declaring mdio_np with __free(device_node) and dropping the gotos fix both?

[ ... ]

Quoted 2 lines
drivers/mfd/airoha-an8855.c new file +2 -0
+static int an8855_core_probe(struct mdio_device *mdiodev)
+{

[ ... ]

drivers/mfd/airoha-an8855.c line 525

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]
The MFD binding documents reset-gpios on the airoha,an8855 node, and its example uses reset-gpios = <&pio 39 GPIO_ACTIVE_HIGH>. Does anything request or deassert that GPIO before this first MDIO access?

an8855_core_probe() doesn't touch it. mdiobus_register_device() only sets up reset for MDIO_DEVICE_FLAG_PHY devices, so mdio_device_reset() in mdio_probe() does nothing for this mdio_device. The DSA driver at the end of the series doesn't handle the reset line either.

There is also no wait for the chip to finish its internal init before the page select, the CREV read and the AFE_PWD write. linux/gpio/consumer.h is included but unused, and so is this define:

#define AN8855_HWTRAP 0x1000009c

Was a reset and HWTRAP poll sequence lost when this code moved into the MFD? On boards where reset is still asserted at boot, it looks like an8855_read_switch_id() would fail and the switch would be unusable.

drivers/mfd/airoha-an8855.c line 537

Quoted 12 lines
drivers/mfd/airoha-an8855.c new file +12 -0
+	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;

[Severity: Low]
Nothing appears to set the AN8855_RG_GPHY_AFE_PWD bits again later. fwnode_mdiobus_register_phy() or devm_mfd_add_devices() can still fail after this write. The err_put_fwnodes path only drops fwnode references, and there is no .remove callback or devm action for unbind.

Should power down be restored on those paths, so the PHY analog front ends aren't left powered with no driver managing the ports?

drivers/mfd/airoha-an8855.c line 543

Quoted 6 lines
drivers/mfd/airoha-an8855.c new file +6 -0
+
+	/* 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: Low]
Both examples in Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml use:

compatible = "ethernet-phy-idc0ff.0410",

             "ethernet-phy-ieee802.3-c45";

The buses created by devm_mdio_regmap_register() only provide C22 read/write callbacks. With that compatible, fwnode_mdiobus_register_phy() does:

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

The explicit PHY ID is then ignored. get_phy_c45_ids() fails because __mdiobus_c45_read() returns -EOPNOTSUPP when bus->read_c45 is not set.

Would a DT copied from that example make the whole an8855_core_probe() fail? The MFD binding example uses the c22 compatible, so the two bindings seem to disagree.

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

PATCH v23 5/9 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
#13 lore raw

Re: [PATCH net-next v23 5/9] net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Medium] net: phy: air_an8855: incorrect r50ohm calibration for 127 due to forward search - [Medium] net…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] net: phy: air_an8855: incorrect r50ohm calibration for 127 due to forward search
- [Medium] net: phy: air_an8855: register clobbering in AN8855_PHY_RXADC_REV registers
- [Low] net: phy: air_an8855: an8855_set_downshift ignores specific count values --

commit c9b4d007095aa6a972d5abbc505cecf057eb353e
Author: Christian Marangi <[email protected]>

net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY

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.

Quoted 6 lines
drivers/net/phy/air_an8855.c new file +0 -0
new file mode 100644
index 0000000000000..bc22256fd5f95
@@ -0,0 +1,275 @@

[ ... ]

Quoted 8 lines
drivers/net/phy/air_an8855.c new file +8 -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);

drivers/net/phy/air_an8855.c line 88

Quoted 10 lines
drivers/net/phy/air_an8855.c new file +10 -0
+	if (ret)
+		return ret;
+
+	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];

[Severity: Medium]
Will this mapping produce the wrong value for 127?

Since dsa_r50ohm_table starts with multiple 127s, the forward loop finds the first match at index 0. Then the subsequent check sees i < 8 and assigns 94 (table index 25) instead of 127.

Should this use a reverse search (or find the last match) to map 127 to 127 at index 16 (where 16 - 8 = 8)?

Quoted 5 lines
drivers/net/phy/air_an8855.c new file +5 -0
+	else
+		*dest = dsa_r50ohm_table[i - 8];
+
+	return 0;
+}

[ ... ]

drivers/net/phy/air_an8855.c line 148

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

[Severity: Low]
Does this code incorrectly ignore unsupported downshift counts?

If a user sets an unsupported downshift retry count via ethtool that isn't DOWNSHIFT_DEV_DISABLE or DOWNSHIFT_DEV_DEFAULT_COUNT, this simply applies AN8855_PHY_EN_DOWN_SHIFT and returns 0 (success).

Should it return -EOPNOTSUPP for unknown values to maintain consistency between requested and actual hardware state?

Quoted 5 lines
drivers/net/phy/air_an8855.c new file +5 -0
+
+	return phy_modify_paged(phydev, AN8855_PHY_PAGE_EXTENDED_1,
+				AN8855_PHY_EXT_REG_14, AN8855_PHY_EN_DOWN_SHIFT,
+				ds);
+}

[ ... ]

Quoted 2 lines
drivers/net/phy/air_an8855.c new file +2 -0
+static int an8855_config_init(struct phy_device *phydev)
+{

[ ... ]

drivers/net/phy/air_an8855.c line 208

Quoted 11 lines
drivers/net/phy/air_an8855.c new file +11 -0
+	ret = phy_set_bits_mmd(phydev, MDIO_MMD_VEND1, AN8855_PHY_RXADC_CTRL,
+			       AN8855_PHY_RG_AD_SAMPLE_PHSEL_A |
+			       AN8855_PHY_RG_AD_SAMPLE_PHSEL_C);
+	if (ret)
+		return ret;
+	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]
Can this clobber the adjacent fields in the RXADC_REV registers?

phy_write_mmd() overwrites the entire 16-bit register. By preparing only AN8855_PHY_RG_AD_RESERVE0_A and AN8855_PHY_RG_AD_RESERVE0_C, the lower 8 bits (RESERVE0_B and RESERVE0_D) will be unintentionally zeroed out.

Should phy_modify_mmd() be used here instead to preserve undocumented hardware defaults?

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
maintainer Reviewed-by on v23 5/9
#14 lore raw

Re: [PATCH net-next v23 5/9] net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY

In reply to Christian Marangi
Quoted 6 lines · 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.

Andrew

#15 lore raw

Re: [PATCH net-next v23 5/9] 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: 4 · Low: 0

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

- [Medium] The downshift tunable accepts retry counts the hardware cannot program and reports a sentinel as the count.
- [Medium] Probe fails, and the driver never binds, when the DT has "nvmem-cells" but NVMEM support or the AN8855 efuse provider is…
- [Medium] The PHY binding example contradicts the driver and bus.
- [Medium] net: phy: air_an8855: register clobbering in AN8855_PHY_RXADC_REV registers

--

net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY

This commit adds a PHY driver for the internal gigabit PHYs of the Airoha AN8855 switch. At probe time it reads R50 ohm calibration values from NVMEM cells. In config_init it applies them together with downshift and noise-reduction settings.

Quoted 6 lines
drivers/net/phy/air_an8855.c new file +0 -0
new file mode 100644
index 0000000000000..bc22256fd5f95
@@ -0,0 +1,275 @@

[ ... ]

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]
Do these two writes also clear the B and D reserve fields?

phy_write_mmd() writes the whole 16-bit register. The value written to AN8855_PHY_RXADC_REV_0 is 0x0100. That sets AN8855_PHY_RG_AD_RESERVE0_A to 0x1, but it also forces AN8855_PHY_RG_AD_RESERVE0_B (bits 7:0) to zero. AN8855_PHY_RXADC_REV_1 has the same problem: only AN8855_PHY_RG_AD_RESERVE0_C is meant to be set, but AN8855_PHY_RG_AD_RESERVE0_D ends up zeroed as well.

The rest of the noise-reduction sequence in an8855_config_init() only touches pairs A and C:

- AN8855_PHY_TX_PAIR_DLY_SEL_GBE is updated with phy_modify_mmd(), masking only the A and C delay fields.
- AN8855_PHY_RXADC_CTRL uses phy_set_bits_mmd() for the A and C phase select bits.

The B and D masks are defined but never used.

Writing the REV registers wholesale breaks that pattern. It overwrites the hardware reset defaults in the B and D reserve fields, which could change RX ADC behaviour on those pairs. This happens every time phy_init_hw() runs config_init, not just once at first attach.

If B and D should keep their defaults, could these be phy_modify_mmd() calls with AN8855_PHY_RG_AD_RESERVE0_A and AN8855_PHY_RG_AD_RESERVE0_C as the masks? If the vendor sequence really writes the full register, could a comment say so?

[Severity: Medium]
Can this probe fail on configurations where the NVMEM cells cannot be read?

needs_calibration depends only on whether "nvmem-cells" is present in the DT. an8855_probe() returns any error from an8855_get_r50ohm_val().

NVMEM is a bool symbol, so the Kconfig line added in this patch is always true and has no effect:

    depends on NVMEM || !NVMEM

With CONFIG_NVMEM=n, the stub in include/linux/nvmem-consumer.h is used, so probe fails with -EOPNOTSUPP:

static inline int nvmem_cell_read_u32(struct device *dev,
const char *cell_id, u32 *val)

{
	return -EOPNOTSUPP;
}

With CONFIG_NVMEM=y, the only provider for these cells is NVMEM_AN8855_EFUSE in drivers/nvmem/Kconfig. It currently has only "depends on COMPILE_TEST", and nothing in this series changes that. On a non-COMPILE_TEST config the provider can't be built. nvmem_cell_read_u32() then keeps returning -EPROBE_DEFER, and this driver never probes.

In both cases, a DT that follows the MFD binding example leaves this driver unbound, because that example puts nvmem-cells on every PHY. phy_attach_direct() then falls back to genphy. The downshift and noise-reduction settings in an8855_config_init() are lost as well, even though they don't need NVMEM.

Could the calibration be skipped, perhaps with a warning, when the cells are unavailable? And could the Kconfig dependency reflect what is actually required?

Quoted 4 lines
drivers/net/phy/air_an8855.c new file +4 -0
+
+		ret = an8855_get_r50ohm_val(dev, "tx_b", &priv->calibration_data[1]);
+		if (ret)
+			return ret;

[ ... ]

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]
Are retry counts other than enable/disable silently accepted here?

an8855_set_downshift() maps every non-zero cnt to the same enable bit and returns success. For ETHTOOL_PHY_DOWNSHIFT, ethtool_phy_tunable_valid() in net/ethtool/ioctl.c only checks len and type_id, so any u8 value reaches this function. For example, this succeeds without applying a count of 3:

ethtool --set-phy-tunable ethX downshift on count 3

On the read side, an8855_get_downshift() reports DOWNSHIFT_DEV_DEFAULT_COUNT (0xff) whenever the bit is set. DOWNSHIFT_DEV_DEFAULT_COUNT is an input sentinel that means "use the default count", so a later get shows userspace a count of 255.

Other phylib drivers reject counts they can't program. For example, bcm54140_set_downshift() does:

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

Could this driver return -EINVAL for counts it can't program, and report the count the hardware actually uses on get?

[ ... ]

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 10 lines
drivers/net/phy/air_an8855.c new file +10 -0
+	.probe			= an8855_probe,
+	.config_init		= an8855_config_init,
+	.soft_reset		= genphy_soft_reset,
+	.get_tunable		= an8855_get_tunable,
+	.set_tunable		= an8855_set_tunable,
+	.suspend		= genphy_suspend,
+	.resume			= genphy_resume,
+	.read_page		= an8855_read_page,
+	.write_page		= an8855_write_page,
+}, };

[Severity: Medium]
This one is in another patch of the series, "dt-bindings: net: Document support for AN8855 Switch Internal PHY". Both PHY nodes in that binding example use:

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

Would a DT written from that example make the whole switch fail to probe?

fwnode_mdiobus_register_phy() sets is_c45 from that compatible. When is_c45 is set, it ignores the explicit PHY ID:

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

The per-PHY bus comes from devm_mdio_regmap_register(), which only installs C22 ops:

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

So get_phy_c45_ids()->get_phy_c45_devs_in_pkg()->mdiobus_c45_read() gets -EOPNOTSUPP. That becomes -EIO, and an8855_core_probe() aborts.

This driver is Clause 22 only: paged access through register 0x1f, genphy_soft_reset(), and PHY_ID_MATCH_EXACT() on the C22 ID. The MFD binding example already uses "ethernet-phy-ieee802.3-c22".

Should the PHY binding example use "ethernet-phy-ieee802.3-c22" as well?

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

PATCH v23 6/9 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 v23 6/9] 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: missing DSA_TAG_PROTO_AIROHA support in Mediatek/Airoha ethernet drivers --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] net: dsa: missing DSA_TAG_PROTO_AIROHA support in Mediatek/Airoha ethernet drivers --

commit 3da7d110875eb668c591fb8186046c81cef009ee
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 adding this new protocol variant break Ethernet drivers that explicitly check for DSA_TAG_PROTO_MTK?

For example, in drivers/net/ethernet/airoha/airoha_eth.c:airoha_get_dsa_tag(), failing to recognize the Airoha DSA protocol prevents extracting the tag for hardware DMA descriptors, breaking transmission:

	if (dev->dsa_ptr->tag_ops->proto != DSA_TAG_PROTO_MTK)
		return 0;

Similarly, does this break PPE L2 flow offload in drivers/net/ethernet/mediatek/mtk_ppe.c:mtk_ppe_check_skb() because it rejects the Airoha protocol variant?

	if (!netdev_uses_dsa(skb->dev) ||
		    skb->dev->dsa_ptr->tag_ops->proto != DSA_TAG_PROTO_MTK)

And in drivers/net/ethernet/mediatek/mtk_ppe_offload.c:mtk_flow_get_dsa_port(), will flow offloads targeting Airoha DSA ports fail or misroute?

	if (dp->cpu_dp->tag_ops->proto != DSA_TAG_PROTO_MTK)
		return -ENODEV;

Finally, in drivers/net/ethernet/mediatek/mtk_eth_soc.c:mtk_uses_dsa(), does it disable GDMA hardware special tag parsing when an Airoha switch is connected?

	return netdev_uses_dsa(dev) &&
	       dev->dsa_ptr->tag_ops->proto == DSA_TAG_PROTO_MTK;
Quoted 3 lines
include/net/dsa.h +0 -0
 	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,
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
maintainer Reviewed-by on v23 6/9
#18 lore raw

Re: [PATCH net-next v23 6/9] net: dsa: tag_mtk: add Airoha variant usage of this TAG

In reply to Christian Marangi
Quoted 8 lines · 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.

Quoted 5 lines

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.

Andrew

#19 lore raw

Re: [PATCH net-next v23 6/9] 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 1 potential issue(s) to consider.

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

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

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

- [Medium] The patch adds DSA_TAG_PROTO_AIROHA (37) and gives it the same handlers as DSA_TAG_PROTO_MTK (mtk_tag_xmit/mtk_tag_rcv, MTK_HDR_LEN…

--

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

This adds a DSA_TAG_PROTO_AIROHA protocol ID and an "airoha" tag driver that reuses the MTK xmit/rcv handlers. It also adds comments on how the AN8855 tag bitmap differs from the Mediatek one. Kconfig and the Makefile now build tag_mtk.o through a shared NET_DSA_TAG_MTK_COMMON symbol.

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]
Frames on the wire are identical for DSA_TAG_PROTO_AIROHA and DSA_TAG_PROTO_MTK. What about the conduit Ethernet drivers that check for the MTK tag format by comparing against DSA_TAG_PROTO_MTK? None of them are updated here.

Later in this series, an8855_get_tag_protocol() returns DSA_TAG_PROTO_AIROHA. For an AN8855 behind a MediaTek or Airoha SoC conduit, dsa_ptr->tag_ops->proto would then be 37, and these checks would stop matching.

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

On NETSYS v1, mtk_open() would then take the else branch. It clears MTK_CDMP_STAG_EN and skips the dsa_meta allocation, so hardware special tag untagging is turned off.

drivers/net/ethernet/mediatek/mtk_ppe.c:__mtk_ppe_check_skb() {
	case htons(ETH_P_XDSA):
		if (!netdev_uses_dsa(skb->dev) ||
		    skb->dev->dsa_ptr->tag_ops->proto != DSA_TAG_PROTO_MTK)
			goto out;
}
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;
}

These two checks mean PPE entries are never bound for DSA frames, and flowtable hardware offload through the switch ports would be refused.

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

On the Airoha conduit, this returns before the VLAN TPID is restored and before the special tag is moved into the QDMA descriptor. The comment in that function says the PPE needs that move. airoha_dev_xmit() would then send the frame with the inline tag and SP_TAG=0.

airoha_get_dsa_port() in airoha_ppe.c has no proto check, though, so the Airoha PPE would still accept flow offload for these ports. Can the TX path and the PPE path then disagree about how the tag is handled?

The commit message describes this as giving external tools like libpcap a dedicated "Airoha" name. It doesn't mention these behaviour changes on the conduit side.

Should these call sites accept both protocols in this series, for example through a helper that checks for an MTK-format tag?

Quoted 4 lines
net/dsa/tag_mtk.c +4 -0
+
+DSA_TAG_DRIVER(airoha_netdev_ops);
+MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_AIROHA, AIROHA_NAME);
+#endif

[ ... ]

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

PATCH v23 7/9 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..f6749933aa0b 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/an8855.c
+F:	drivers/net/dsa/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
#22 lore raw

PATCH v23 8/9 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/Kconfig       |    4 +
 drivers/net/dsa/Makefile      |    1 +
 drivers/net/dsa/mt7530-lib.c  | 1128 +++++++++++++++++++++++++++
 drivers/net/dsa/mt7530-lib.h  |  391 ++++++++++
 drivers/net/dsa/mt7530-mdio.c |    4 +
 drivers/net/dsa/mt7530-mmio.c |    4 +
 drivers/net/dsa/mt7530.c      | 1368 ++++++++-------------------------
 drivers/net/dsa/mt7530.h      |  256 ++----
 8 files changed, 1913 insertions(+), 1243 deletions(-)
 create mode 100644 drivers/net/dsa/mt7530-lib.c
 create mode 100644 drivers/net/dsa/mt7530-lib.h
drivers/net/dsa/Kconfig +4 -0
index fe8cd5338fda..f13ac7e77200 100644
@@ -28,8 +28,12 @@ source "drivers/net/dsa/hirschmann/Kconfig"
 
 source "drivers/net/dsa/lantiq/Kconfig"
 
+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/Makefile +1 -0
index 7e637d56b35c..447e849a78e5 100644
@@ -3,6 +3,7 @@ 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_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/mt7530-lib.c new file +1128 -0

1,128 lines not on this page · raw message

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

391 lines not on this page · raw message

drivers/net/dsa/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/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/mt7530.c +321 -1047

1,442 lines not on this page · raw message

drivers/net/dsa/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 v23 8/9] net: dsa: mt7530: generalize and move common function to lib module

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] net/dsa: mt7530: lost multicast counter in rtnl_link_stats64 --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] net/dsa: mt7530: lost multicast counter in rtnl_link_stats64
--

commit 7c73e5182e23c339dc9a92fe7e7c4d4b45721dd7
Author: Christian Marangi <[email protected]>

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

This commit introduces a library module for MT7530 switches, moving common functions there to prepare for Airoha switch support. The migrated functions are generalized using the reg_field regmap API.

Quoted 3 lines
drivers/net/dsa/mt7530.c +0 -0

[ ... ]

Quoted 6 lines
drivers/net/dsa/mt7530.c +0 -2
@@ -861,38 +833,40 @@ static void mt7530_read_port_stats64(struct mt7530_priv *priv, int port,
 	 * To simulate a global frame counter, read Unicast and addition Multicast
 	 * and Broadcast later
 	 */
-	mt7530_read_port_stats(priv, port, MT7530_PORT_MIB_RX_UNICAST, 1,
-			       &storage->rx_packets);

drivers/net/dsa/mt7530.c static void mt7530_read_port_stats64(struct mt7530_priv *priv, int port, · line 840

Quoted 10 lines
drivers/net/dsa/mt7530.c +5 -5
-	mt7530_read_port_stats(priv, port, MT7530_PORT_MIB_RX_MULTICAST, 1,
-			       &storage->multicast);
-	storage->rx_packets += storage->multicast;
-	mt7530_read_port_stats(priv, port, MT7530_PORT_MIB_RX_BROADCAST, 1,
-			       &data);
+	mt7530_lib_read_port_stats(lib_priv->fields[MT7530_MIB_RX_UNICAST],
+				   NULL, port, &storage->rx_packets);
+	mt7530_lib_read_port_stats(lib_priv->fields[MT7530_MIB_RX_MULTICAST],
+				   NULL, port, &data);
+	storage->rx_packets += data;

[Severity: Medium]
Does this refactoring inadvertently drop the assignment to storage->multicast?

The hardware multicast counter is correctly read into the local data variable and added to rx_packets, but it is no longer being assigned to storage->multicast as it was in the original code. This will cause the multicast statistics metric (exported via rtnl_link_stats64) to permanently report 0.

Quoted 3 lines
drivers/net/dsa/mt7530.c +2 -0
+	mt7530_lib_read_port_stats(lib_priv->fields[MT7530_MIB_RX_BROADCAST],
+				   NULL, port, &data);
 	storage->rx_packets += data;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
maintainer Reviewed-by on v23 8/9
#24 lore raw

Re: [PATCH net-next v23 8/9] net: dsa: mt7530: generalize and move common function to lib module

In reply to Christian Marangi
Quoted 23 lines · 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.

Quoted 9 lines
---
 drivers/net/dsa/Kconfig       |    4 +
 drivers/net/dsa/Makefile      |    1 +
 drivers/net/dsa/mt7530-lib.c  | 1128 +++++++++++++++++++++++++++
 drivers/net/dsa/mt7530-lib.h  |  391 ++++++++++
 drivers/net/dsa/mt7530-mdio.c |    4 +
 drivers/net/dsa/mt7530-mmio.c |    4 +
 drivers/net/dsa/mt7530.c      | 1368 ++++++++-------------------------
 drivers/net/dsa/mt7530.h      |  256 ++----

The number of mt* file keep going up. Is it time to move it into a subdirectory?

Andrew

#25 lore raw

Re: [PATCH net-next v23 8/9] net: dsa: mt7530: generalize and move common function to lib module

Quoted 34 lines · Andrew Lunn
Quoted 23 lines · 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.

Quoted 9 lines
---
 drivers/net/dsa/Kconfig       |    4 +
 drivers/net/dsa/Makefile      |    1 +
 drivers/net/dsa/mt7530-lib.c  | 1128 +++++++++++++++++++++++++++
 drivers/net/dsa/mt7530-lib.h  |  391 ++++++++++
 drivers/net/dsa/mt7530-mdio.c |    4 +
 drivers/net/dsa/mt7530-mmio.c |    4 +
 drivers/net/dsa/mt7530.c      | 1368 ++++++++-------------------------
 drivers/net/dsa/mt7530.h      |  256 ++----
Quoted 2 lines

The number of mt* file keep going up. Is it time to move it into a subdirectory?

The problem as always is that mediatek directory will also contain airoha stuff...

Quoted 3 lines

I would like to fix some trivial things pointed out by sashiko. Can I apply those and keep the review tag? For this patch for example it's just the typo for the multicast MIB.

For the other patch is also very trivial stuff.

Signature · 1 line
	Ansuel
maintainer
#26 lore raw

Re: [PATCH net-next v23 8/9] net: dsa: mt7530: generalize and move common function to lib module

Quoted 35 lines · Christian Marangi
Quoted 34 lines · Andrew Lunn
Quoted 32 lines · 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/Kconfig       |    4 +
 drivers/net/dsa/Makefile      |    1 +
 drivers/net/dsa/mt7530-lib.c  | 1128 +++++++++++++++++++++++++++
 drivers/net/dsa/mt7530-lib.h  |  391 ++++++++++
 drivers/net/dsa/mt7530-mdio.c |    4 +
 drivers/net/dsa/mt7530-mmio.c |    4 +
 drivers/net/dsa/mt7530.c      | 1368 ++++++++-------------------------
 drivers/net/dsa/mt7530.h      |  256 ++----
Quoted 5 lines
Quoted 2 lines

The number of mt* file keep going up. Is it time to move it into a subdirectory?

The problem as always is that mediatek directory will also contain airoha stuff...

That is only a Marketing problem, and Mainline generally ignores marketing. Companies get bought and sold all the time. We don't rename anything because of that.

Quoted 5 lines

I would like to fix some trivial things pointed out by sashiko. Can I apply those and keep the review tag? For this patch for example it's just the typo for the multicast MIB.

For the other patch is also very trivial stuff.

Yes, not a problem. If you make major changes then drop it, but trivial stuff is fine.

Andrew

#27 lore raw

Re: [PATCH net-next v23 8/9] 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 7 potential issue(s) to consider.

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

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

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] A name collision between a macro and an enum constant puts the mirror-enable regmap field at the wrong index.
- [Medium] mt7530_read_port_stats64() no longer fills rtnl_link_stats64.multicast.
- [Medium] mt753x_table[ID_EN7528] now uses .reg_fields = mt7531_fields, so on EN7528 mirroring goes to MT7531_CFC (MIRROR_EN…
- [Medium] mt7530_lib_port_mdb_add(), mt7530_lib_port_mdb_del() and mt7530_hw_vlan_del() declare u32 val; without initializing it.
- [Low] mt7530_lib_fdb_cmd() and mt7530_vlan_cmd() ignore failures of their final status reads.
- [Low] Two comments were not updated to match the new code.
- [Low] Splitting whole-register accesses into regmap_field accesses multiplies register traffic for FDB and VLAN operations.

Pre-existing issues:
- [Low] This problem wasn't introduced by this patch, but mt7530_hw_vlan_update() ignores the results of the RD_VID command, the…
- [Low] This problem wasn't introduced by this patch, but mt7530_lib_port_mdb_add()/mt7530_lib_port_mdb_del() handle any failure…
- [Low] This problem wasn't introduced by this patch, but mt7530_lib_fdb_write() returns void and ignores every register write.
- [Low] This problem wasn't introduced by this patch, but mt7530_port_fdb_dump() returns 0 unconditionally.

--

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

This commit adds a mt7530 library module to prepare for Airoha DSA switch support, and moves the common MT7530 functions into it under a mt7530_lib prefix. The functions now use the regmap reg_field API. There is one common field table, plus per-chip mirror fields taken from the match table. The commit message says no behaviour change is expected.

Quoted 5 lines
drivers/net/dsa/mt7530-lib.c new file +0 -0
new file mode 100644
index 0000000000000..098dd45d3ee9f

[ ... ]

Quoted 3 lines
drivers/net/dsa/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)
+{

[ ... ]

Quoted 6 lines
drivers/net/dsa/mt7530-lib.c new file +6 -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;
+	}

drivers/net/dsa/mt7530-lib.c line 434

Quoted 10 lines
drivers/net/dsa/mt7530-lib.c new file +10 -0
+
+	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);
+
+	return 0;
+}

[Severity: Low]
The old mt7530_fdb_cmd() returned an error if the final regmap_read() of MT7530_ATC failed. Both regmap_field_read() calls here ignore the return value.

After a successful busy poll val is 0, and a failed read leaves it at 0. That means an invalid entry would be reported as success.

A failed read of rsp leaves the previous command's ATC_SRCH_HIT and ATC_SRCH_END bits in place. Could mt7530_port_fdb_dump() then process stale search state and report duplicate entries (bounded by cnt)?

mt7530_vlan_cmd() does the same thing with MT7530_VTCR_INVALID. The last patch in the series wraps these reads in NULL checks, but it still doesn't check their return values.

Should these reads check their return values as the old code did?

Quoted 11 lines
drivers/net/dsa/mt7530-lib.c new file +11 -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);

[ ... ]

drivers/net/dsa/mt7530-lib.c

Quoted 2 lines
drivers/net/dsa/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 introduced by this patch, but mt7530_lib_fdb_write() returns void and ignores every register write, just like the old mt7530_fdb_write().

mt7530_lib_port_fdb_add() and mt7530_lib_port_fdb_del() then issue MT7530_FDB_WRITE even if writing the ATA/ATWD staging registers failed.

Could that write or delete an entry keyed on a partly programmed MAC/VID?

Quoted 7 lines
drivers/net/dsa/mt7530-lib.c new file +7 -0
+
+void mt7530_lib_fdb_read(struct mt7530_lib_priv *priv, struct mt7530_fdb *fdb)
+{
+	u32 val = 0;
+
+	regmap_field_read(priv->fields[MT7530_ATRD_CVID], &val);
+	fdb->vid = val;

[ ... ]

drivers/net/dsa/mt7530-lib.c line 488

Quoted 3 lines
drivers/net/dsa/mt7530-lib.c new file +3 -0
+	regmap_field_read(priv->fields[MT7530_ATRD_ENT_STATUS], &val);
+	fdb->noarp = val == STATIC_ENT;
+}

[Severity: Low]
This isn't a bug, but splitting whole-register accesses into regmap fields adds a lot of register traffic on the MDIO path, where the regmap has no cache. Each field write is a read plus a write. Each 32-bit access over MDIO is a page-select write plus two 16-bit transfers.

The register access counts before and after this patch:

- mt7530_lib_fdb_read(): 10 register reads instead of 3.
- mt7530_lib_fdb_write(): 3 clears plus 12 field read-modify-writes, instead of 3 writes.
- mt7530_lib_fdb_cmd(): 3 read-modify-writes, the poll and 2 more reads, instead of 1 write, the poll and 1 read.

mt7530_port_fdb_dump() repeats FDB_NEXT plus mt7530_lib_fdb_read() for up to MT7530_NUM_FDB_RECORDS entries. It does this while holding reg_mutex and the MDIO bus lock, with about 3x the old bus traffic.

Would it make sense to keep whole-register accesses for the ATA, ATWD, ATRD and ATC registers?

[ ... ]

Quoted 9 lines
drivers/net/dsa/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/mt7530-lib.c line 555

Quoted 10 lines
drivers/net/dsa/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 val be used uninitialized here? When regmap_read() fails, regmap_field_read() returns early without writing *val.

The old code called regmap_read() directly on the caller's variable. mt7530_regmap_read() in mt7530-mdio.c sets *val = 0 first, with the comment "Callers do not check for errors, keep the value deterministic". regmap_field_read() reads into its own local reg_val, so that zero no longer reaches this caller.

On an MDIO read failure, stack garbage would become port_mask and be written as a STATIC_ENT multicast port map.

mt7530_lib_port_mdb_del() has the same pattern. mt7530_hw_vlan_del() tests an uninitialized val:

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

Should these val variables start at 0, or should the return values be checked?

drivers/net/dsa/mt7530-lib.c line 560

Quoted 5 lines
drivers/net/dsa/mt7530-lib.c new file +5 -0
+
+	port_mask |= BIT(port);
+	mt7530_lib_fdb_write(priv, vid, port_mask, addr, -1, STATIC_ENT);
+	ret = mt7530_lib_fdb_cmd(priv, MT7530_FDB_WRITE,
+				 ATC_MAT_MACTAB, NULL);

[Severity: Low]
This is a pre-existing issue, but any failure of MT7530_FDB_READ (I/O error or timeout) is handled the same way as a missing entry. In that case mt7530_lib_port_mdb_add() writes a mask containing only BIT(port), and mt7530_lib_port_mdb_del() writes STATIC_EMP with a zero mask.

After a failed lookup, can this drop the multicast membership of the other ports?

[ ... ]

Quoted 8 lines
drivers/net/dsa/mt7530-lib.c new file +8 -0
+static void mt7530_hw_vlan_update(struct mt7530_lib_priv *priv, u16 vid,
+				  struct mt7530_hw_vlan_entry *entry,
+				  mt7530_vlan_op vlan_op)
+{
+	u32 val = 0;
+
+	/* Fetch entry */
+	mt7530_vlan_cmd(priv, MT7530_VTCR_RD_VID, vid);

drivers/net/dsa/mt7530-lib.c line 1013

Quoted 10 lines
drivers/net/dsa/mt7530-lib.c new file +10 -0
+
+	regmap_field_read(priv->fields[MT7530_VAWD_PORT_MEM], &val);
+	entry->old_members = val;
+
+	/* Manipulate entry */
+	vlan_op(priv, entry);
+
+	/* Flush result to hardware */
+	mt7530_vlan_cmd(priv, MT7530_VTCR_WR_VID, vid);
+}

[Severity: Low]
This isn't a bug introduced by this patch, but mt7530_hw_vlan_update() ignores the results of the RD_VID command, the PORT_MEM read and the final WR_VID command. The old code did the same.

vlan_op() can run on stale VAWD data. mt7530_lib_port_vlan_add() and mt7530_lib_port_vlan_del() then update the PVID state and return 0, even if the VLAN table write failed.

Should the errors be passed back to the callers?

[ ... ]

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

[ ... ]

drivers/net/dsa/mt7530.c line 182

Quoted 9 lines
drivers/net/dsa/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, which declares:

    enum mt7530_regmap_field {
    	MT7530_MIRROR_EN,
    	...

After that include, mt7530.h still keeps the old register bit define:

    #define  MT7530_MIRROR_EN		BIT(3)

So in mt7530.c both tables get id = BIT(3) = 8, which is MT7530_CCR_TX_OCT_CNT_GOOD in the enum. mt7530-lib.c only includes mt7530-lib.h, so in the library MT7530_MIRROR_EN is 0.

mt7530_setup_lib_priv() fills in mt753x_fields first and the per-chip table second. That overwrites fields[8] with the mirror enable field and leaves fields[0] NULL, since priv comes from devm_kzalloc().

A tc matchall mirred rule then reaches:

mt753x_port_mirror_add()
mt7530_lib_port_mirror_add()

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

with a NULL field, and regmap_field_read() dereferences field->regmap. mt7530_lib_port_mirror_del() also writes through the same NULL field.

mt7530_lib_mib_reset() is called from mt7530_setup() and mt7531_setup_common(), and does:

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

This would now set the global mirror enable bit (MFC bit 3 or CFC bit 19) on every setup, and MIB CCR bit 5 would never be set. The old code wrote CCR_MIB_ACTIVATE, which included TX_OCT_CNT_GOOD.

mt7530.h and mt7530.c aren't changed later in the series, so this seems to still be present at the end of it. Should the old MT7530_MIRROR_EN define be removed or renamed?

[ ... ]

Quoted 4 lines
drivers/net/dsa/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[] = {

[ ... ]

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

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

[Severity: Low]
This isn't a bug, but this comment no longer matches the descriptor. The descriptor now holds regmap field IDs (field_low, field_high, with -1 meaning no high word), not an offset and a size.

The same goes for this comment in mt7530.h:

    /* Each define is an offset of MT7530_PORT_MIB_COUNTER */

Each MT7530_PORT_MIB_* define now includes the MT7530_MIB_COUNTER base and is used as an absolute port 0 address.

[ ... ]

Quoted 6 lines
drivers/net/dsa/mt7530.c +0 -2
@@ -861,38 +833,40 @@ static void mt7530_read_port_stats64(struct mt7530_priv *priv, int port,
 	 * To simulate a global frame counter, read Unicast and addition Multicast
 	 * and Broadcast later
 	 */
-	mt7530_read_port_stats(priv, port, MT7530_PORT_MIB_RX_UNICAST, 1,
-			       &storage->rx_packets);

drivers/net/dsa/mt7530.c static void mt7530_read_port_stats64(struct mt7530_priv *priv, int port, · line 840

Quoted 10 lines
drivers/net/dsa/mt7530.c +5 -5
-	mt7530_read_port_stats(priv, port, MT7530_PORT_MIB_RX_MULTICAST, 1,
-			       &storage->multicast);
-	storage->rx_packets += storage->multicast;
-	mt7530_read_port_stats(priv, port, MT7530_PORT_MIB_RX_BROADCAST, 1,
-			       &data);
+	mt7530_lib_read_port_stats(lib_priv->fields[MT7530_MIB_RX_UNICAST],
+				   NULL, port, &storage->rx_packets);
+	mt7530_lib_read_port_stats(lib_priv->fields[MT7530_MIB_RX_MULTICAST],
+				   NULL, port, &data);
+	storage->rx_packets += data;

[Severity: Medium]
The old code read the RX multicast counter into storage->multicast. The new code reads it into the scratch variable data and only adds it to rx_packets. Nothing else in mt7530*.c writes the multicast field now.

mt7530_stats_refresh() starts from a zeroed struct rtnl_link_stats64. Won't ndo_get_stats64 then always report multicast as 0 on every user port? The commit message says no behaviour change is expected.

[ ... ]

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

Quoted 10 lines
drivers/net/dsa/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: Low]
This is a pre-existing issue, but mt7530_port_fdb_dump() still returns 0 unconditionally after this label. A failed FDB_START jumps to err, and a failed FDB_NEXT ends the loop without keeping its error.

Should the error be returned to dsa_port_fdb_dump(), so an incomplete dump isn't reported as success?

[ ... ]

Quoted 7 lines
drivers/net/dsa/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,

[ ... ]

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

Quoted 7 lines
drivers/net/dsa/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),
 		.pcs_ops = &mt7530_pcs_ops,

[Severity: Medium]
Is it intended that EN7528 uses mt7531_fields? The MT753X_MIRROR_REG() macro still in mt7530.h maps only MT7531, MT7988, EN7581 and AN7583 to MT7531_CFC. Before this patch, EN7528 mirroring used MT753X_MFC with enable BIT(3) and port GENMASK(2, 0).

Other code that this patch doesn't touch also treats EN7528 as MFC-based. mt753x_conduit_state_change() groups it with MT7530 and MT7621, and mt753x_cpu_port_enable() leaves it out of the MT7531_CFC CPU_PMAP chips.

On EN7528, mt7530_lib_port_mirror_add() would now do a read-modify-write on bits 16..19 of register 0x4 instead of bits 0..3 of MFC. It would still return success.

AN7583 changes as well. MT753X_MIRROR_EN() did not list ID_AN7583, so its enable bit was BIT(3) in CFC, which overlaps CPU_PMAP. It is now BIT(19). If that was an old bug being fixed, could the commit message say so?

The MT753X_MIRROR_* macros are now unused, and they contradict the new tables for both chips.

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

PATCH v23 9/9 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/Kconfig      |   10 +
 drivers/net/dsa/Makefile     |    1 +
 drivers/net/dsa/an8855.c     | 1740 ++++++++++++++++++++++++++++++++++
 drivers/net/dsa/an8855.h     |  755 +++++++++++++++
 drivers/net/dsa/mt7530-lib.c |   68 +-
 drivers/net/dsa/mt7530-lib.h |   22 +
 6 files changed, 2576 insertions(+), 20 deletions(-)
 create mode 100644 drivers/net/dsa/an8855.c
 create mode 100644 drivers/net/dsa/an8855.h
drivers/net/dsa/Kconfig +10 -0
index f13ac7e77200..1753578c8e03 100644
@@ -24,6 +24,16 @@ config NET_DSA_LOOP
 	  This enables support for a fake mock-up switch chip which
 	  exercises the DSA APIs.
 
+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.
+
 source "drivers/net/dsa/hirschmann/Kconfig"
 
 source "drivers/net/dsa/lantiq/Kconfig"
drivers/net/dsa/Makefile +1 -0
index 447e849a78e5..76888495c5b3 100644
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_NET_DSA_AN8855)	+= an8855.o
 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
drivers/net/dsa/an8855.c new file +1740 -0

1,740 lines not on this page · raw message

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

755 lines not on this page · raw message

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

134 lines not on this page · raw message

drivers/net/dsa/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
#29 lore raw

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

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] net: dsa: NULL deref in mt7530_lib_fdb_read() due to mismatched field check - [Medium] net: dsa…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] net: dsa: NULL deref in mt7530_lib_fdb_read() due to mismatched field check
- [Medium] net: dsa: ethtool -S stat duplication for standard uAPI counters
- [Medium] net: dsa: stale tx_lpi_timer_ports values corrupt global LPI timer calculation --

commit 6c2fcaf5228ec0a75518542784a8b035277e4900
Author: Christian Marangi <[email protected]>
Subject: net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver

This introduces the driver for the Airoha AN8855 5-Port Gigabit DSA switch. It supports multiple Ethernet speeds up to 2.5G and includes necessary adjustments to the mt7530-lib to support Airoha structures.

Quoted 4 lines
drivers/net/dsa/an8855.c new file +0 -0
index 0000000000000..428d7dd85dd80

[ ... ]

drivers/net/dsa/an8855.c line 185

Quoted 3 lines
drivers/net/dsa/an8855.c new file +3 -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"),

[Severity: Medium]
Are these standard networking statistics meant to be duplicated as driver-private ethtool -S strings here? Standard counters already have a defined uAPI, and duplicating them in private strings exposes redundant data to userspace tools.

[ ... ]

drivers/net/dsa/an8855.c line 479

Quoted 11 lines
drivers/net/dsa/an8855.c new file +11 -0
+static void an8855_get_strings(struct dsa_switch *ds, int port,
+			       u32 stringset, uint8_t *data)
+{
+	int i;
+
+	if (stringset != ETH_SS_STATS)
+		return;
+
+	for (i = 0; i < ARRAY_SIZE(an8855_mib); i++)
+		ethtool_puts(&data, an8855_mib[i].name);
+}

[Severity: Medium]
Since the statistics mapped in an8855_mib[] overlap with standard uAPI counters, doesn't exposing them here violate kernel networking guidelines for ethtool -S statistics?

[ ... ]

drivers/net/dsa/an8855.c line 959

Quoted 12 lines
drivers/net/dsa/an8855.c new file +12 -0
+static void an8855_phylink_mac_disable_tx_lpi(struct phylink_config *config)
+{
+	struct dsa_port *dp = dsa_phylink_to_port(config);
+	struct an8855_priv *priv = dp->ds->priv;
+	int port = dp->index;
+	int ret;
+
+	mutex_lock(&priv->reg_mutex);
+	ret = regmap_clear_bits(priv->regmap, AN8855_PMCR_P(port),
+				AN8855_PMCR_FORCE_EEE1G |
+				AN8855_PMCR_FORCE_EEE100);
+	mutex_unlock(&priv->reg_mutex);

[Severity: Medium]
When EEE is disabled on a port here, shouldn't we also clear the software state for the timer (priv->tx_lpi_timer_ports[port] = 0)?

[ ... ]

Quoted 3 lines
drivers/net/dsa/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 6 lines
drivers/net/dsa/an8855.c new file +6 -0
+	if (timer) {
+		int i;
+
+		/* Save requested timer and search the highest one */
+		mutex_lock(&priv->reg_mutex);
+		priv->tx_lpi_timer_ports[dp->index] = timer;

drivers/net/dsa/an8855.c line 1006

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+		for (i = 0; i < AN8855_NUM_PORTS; i++) {
+			if (!priv->ports[i].enable)
+				continue;
+
+			if (i == dp->index)
+				continue;
+
+			if (timer < priv->tx_lpi_timer_ports[i])
+				timer = priv->tx_lpi_timer_ports[i];
+		}

[Severity: Medium]
Because an8855_phylink_mac_disable_tx_lpi() doesn't clear the port's software timer state, couldn't this loop evaluate stale timer values from ports where EEE was previously disabled? Could this corrupt the global LPI timer calculation?

Quoted 4 lines
drivers/net/dsa/mt7530-lib.c +0 -0
index 098dd45d3ee9f..cf474faf8ed6a 100644

[ ... ]

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

Quoted 8 lines
drivers/net/dsa/mt7530-lib.c +2 -2
@@ -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);
-	fdb->noarp = val == STATIC_ENT;
+	if (priv->fields[MT7530_ATWD_ENT_STATUS]) {
+		regmap_field_read(priv->fields[MT7530_ATRD_ENT_STATUS], &val);

[Severity: High]
Can this cause a NULL pointer dereference? The condition checks if the ATWD (write) field exists, but then unconditionally dereferences the ATRD (read) field. If a driver populates the ATWD field but omits the ATRD field, wouldn't regmap_field_read() crash?

Quoted 8 lines
drivers/net/dsa/mt7530-lib.c +6 -0
+		fdb->noarp = val == STATIC_ENT;
+	}
+	if (priv->fields[AN8855_ATRD_ARP]) {
+		regmap_field_read(priv->fields[AN8855_ATRD_ARP], &val);
+		fdb->noarp = !!val;
+	}
 }
 EXPORT_SYMBOL_GPL(mt7530_lib_fdb_read);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
maintainer Reviewed-by on v23 9/9
#30 lore raw

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

In reply to Christian Marangi
Quoted 6 lines · 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.

Andrew

#31 lore raw

Re: [PATCH net-next v23 9/9] 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 15 potential issue(s) to consider.

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

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

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 AN8855 port_enable/port_disable callbacks never write the hardware port matrix.
- [High] On AN8855, the shared VLAN read-modify-write path reads back from the write-data register instead of the read register.
- [High] net: dsa: NULL deref in mt7530_lib_fdb_read() due to mismatched field check
- [Medium] The jumbo frame length encoding is wrong for AN8855.
- [Medium] an8855_set_mac_eee() rejects any tx_lpi_timer > 0xFFF (4095 us).
- [Medium] The link-local trap fields for AN8855 point at the wrong bits.
- [Medium] an8855_pcs_config() updates AN8855_RG_DA_QP_PLL_SDM_HREN_INTF, which the header defines as a PLL_CTRL_4 field (GENMASK(4,3)), but…
- [Medium] SGMII without in-band negotiation always forces the PCS to 1000 Mb/s.
- [Medium] The new AN8855 driver adds private ethtool -S strings for counters that already have standard uAPIs.
- [Low] The COMPILE_TEST dependency lets NET_DSA_AN8855 be built with MFD_AIROHA_AN8855=n, but neither NET_DSA_AN8855 nor NET_DSA_MT7530_LIB…
- [Low] an8855_phylink_mac_link_up() ignores the return value of regmap_read(AN8855_PMCR_P(port), &reg).
- [Low] In an8855_phylink_mac_enable_tx_lpi(), priv->tx_lpi_timer_ports[port] is written only when a non-zero timer…
- [Low] an8855_port_fdb_dump() declares u32 rsp without initialising it and uses FIELD_GET(AN8855_ATC_HIT, rsp) after mt7530_lib_fdb_cmd()…
- [Low] an8855_pcs_config() does not restore the bits that belong to other modes, so the programmed PCS state depends on earlier…
- [Low] The last RMON histogram bucket is {1519, AN8855_MAX_MTU}, and AN8855_MAX_MTU is an L3 MTU (15360 - ETH_HLEN - ETH_FCS_LEN -…

--

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

This adds a DSA driver for the switch inside the Airoha AN8855 chip. It is built on the shared mt7530-lib helpers and has an in-driver PCS for SGMII and 2500BASE-X on port 5. mt7530-lib gains optional AN8855 regmap fields (ATWD type/valid, ATRD ARP, PVID, extra MIB counters) and a new mt7530_port_set_pvid() helper.

Quoted 5 lines
drivers/net/dsa/Kconfig +0 -0
index f13ac7e772002..1753578c8e037 100644

drivers/net/dsa/Kconfig config NET_DSA_LOOP · line 32

Quoted 9 lines
drivers/net/dsa/Kconfig +6 -0
@@ -24,6 +24,16 @@ config NET_DSA_LOOP
 	  This enables support for a fake mock-up switch chip which
 	  exercises the DSA APIs.
 
+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]
With COMPILE_TEST this symbol can be enabled while MFD_AIROHA_AN8855=n. Neither NET_DSA_AN8855 nor NET_DSA_MT7530_LIB selects REGMAP, which is a hidden symbol.

In include/linux/regmap.h, struct reg_field, REG_FIELD(), REG_FIELD_ID() and devm_regmap_field_alloc() are only declared under #ifdef CONFIG_REGMAP. mt7530-lib.h embeds the struct by value:

struct mt7530_reg_field {
	unsigned int id;
	const struct reg_field field;
};

Would a COMPILE_TEST randconfig with no other REGMAP selector fail to build here? Should this select REGMAP?

Quoted 6 lines
drivers/net/dsa/an8855.c new file +0 -0
new file mode 100644
index 0000000000000..428d7dd85dd80
@@ -0,0 +1,1740 @@

[ ... ]

Quoted 1 line

+static const struct mt7530_reg_field an8855_fields[] = {

[ ... ]

drivers/net/dsa/an8855.c line 38

Quoted 5 lines
drivers/net/dsa/an8855.c new file +5 -0
+	{ MT7530_BPDU_EG_TAG, REG_FIELD(AN8855_BPC, 9, 11) },
+	{ MT7530_BPDU_PORT_FW, REG_FIELD(AN8855_BPC, 0, 2) },
+	{ MT7530_PAE_BPDU_FR, REG_FIELD(AN8855_PAC, 28, 28) },
+	{ MT7530_PAE_EG_TAG, REG_FIELD(AN8855_PAC, 25, 27) },
+	{ MT7530_PAE_PORT_FW, REG_FIELD(AN8855_PAC, 16, 18) },

[Severity: Medium]
Are these the intended PAC bits? an8855.h names bit 28, bits 27:25 and bits 18:16 of AN8855_PAC as AN8855_TAG_PAE_BPDU_FR, AN8855_TAG_PAE_EG_TAG and AN8855_TAG_PAE_PORT_FW. The plain PAE fields are defined elsewhere:

#define AN8855_PAE_BPDU_FR BIT(12)
#define AN8855_PAE_EG_TAG GENMASK(11, 9)
...
#define AN8855_PAE_PORT_FW GENMASK(2, 0)

mt7530_lib_trap_frames() never programs those fields. This looks like the MT7530 layout carried over, since on MT7530 the PAE fields sit in the upper half of BPC.

AN8855_BPC also has an AN8855_BPDU_BPDU_FR bit (BIT(12)), but no lib field maps to it. So real BPDUs (01:80:C2:00:00:00) are never marked as "regarded as BPDU", and the lib comment says only such frames bypass the spanning-tree port state.

Depending on the AN8855 reset defaults, could EAPOL frames fail to reach the CPU? Could BPDUs received on blocking or listening ports be dropped?

drivers/net/dsa/an8855.c line 61

Quoted 10 lines
drivers/net/dsa/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]
mt7530_hw_vlan_update() fetches an entry with RD_VID, then reads the result through MT7530_VAWD_PORT_MEM:

	/* Fetch entry */
	mt7530_vlan_cmd(priv, MT7530_VTCR_RD_VID, vid);

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

Here every VAWD_* field points at AN8855_VAWD0, which is the write-data register. an8855.h defines a separate read register, and no field maps to it:

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

If RD_VID results land in VARD0, the same way the ATU uses separate ATWD/ATRD registers, several values would come from whatever was last written to VAWD0:

- old_members
- the VLAN_VALID check in mt7530_hw_vlan_del()
- the ETAG bits kept by regmap_field_update_bits()

mt7530_lib_setup_vlan0() leaves VAWD0 with all ports in PORT_MEM and EG_CON set. Would every VLAN added through an8855_port_vlan_add() then get all ports as members and inherit EG_CON? Would an8855_port_vlan_del() ever actually remove a port?

Should the fetched entry be read from AN8855_VARD0 instead?

[ ... ]

drivers/net/dsa/an8855.c line 192

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -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"),
+	MIB_DESC(AN8855_MIB_TX_BAD_PKT_BYTES_LOW,
+		 AN8855_MIB_TX_BAD_PKT_BYTES_HIGH, "TxBadPktBytes"),
+	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]
Some of these private ethtool -S strings already have standard uAPIs:

- "RxCrcErr" matches ethtool_eth_mac_stats FrameCheckSequenceErrors and rtnl_link_stats64 rx_crc_errors.
- "TxCollision" matches rtnl_link_stats64 collisions.

The driver implements get_eth_mac_stats through mt7530_lib_get_eth_mac_stats(), but that helper never fills FrameCheckSequenceErrors. The standard counter reads 0, and the value only shows up in the private list.

Could these be reported through the standard interfaces instead?

[ ... ]

Quoted 14 lines
drivers/net/dsa/an8855.c new file +14 -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;
+
+	mutex_lock(&priv->reg_mutex);
+
+	/* Load search port */
+	ret = regmap_write(priv->regmap, AN8855_ATWD2,
+			   FIELD_PREP(AN8855_ATWD2_PORT, BIT(port)));

drivers/net/dsa/an8855.c line 366

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+	if (ret)
+		goto exit;
+	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: Low]
rsp is not initialised. mt7530_lib_fdb_cmd() ignores the result of its final read and returns success:

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

	return 0;

regmap_field_read() does not write *val on error. If that MDIO read fails after a successful busy poll, is uninitialised stack data used as the bank bitmap here? That could produce bogus dump entries or end the dump early.

[ ... ]

drivers/net/dsa/an8855.c line 467

Quoted 12 lines
drivers/net/dsa/an8855.c new file +12 -0
+static int an8855_port_change_mtu(struct dsa_switch *ds, int port,
+				  int new_mtu)
+{
+	struct an8855_priv *priv = ds->priv;
+
+	return mt7530_lib_port_change_mtu(&priv->lib_priv, port, new_mtu);
+}
+
+static int an8855_port_max_mtu(struct dsa_switch *ds, int port)
+{
+	return AN8855_MAX_MTU;
+}

[Severity: Medium]
Does the jumbo size encoding match AN8855? For lengths above 1552, mt7530_lib_port_change_mtu() uses a linear 1 KiB encoding:

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

an8855.h documents a non-linear encoding:

#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)

This gives three problems:

- With AN8855_MAX_MTU = 15338, the length is 15338 + 14 + 4 + 4 =

    15360, which programs 0xf. That value is not defined.
  - Lengths from 9217 to 12288 program 0xa..0xc. The hardware reads
    those as 12K/15K/16K, not 10K/11K/12K.
  - Anything above 12288 programs one of the undefined values
    0xd..0xf.

Does AN8855 need its own translation here?

[ ... ]

drivers/net/dsa/an8855.c line 528

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+static const struct ethtool_rmon_hist_range an8855_rmon_ranges[] = {
+	{ 0, 64 },
+	{ 65, 127 },
+	{ 128, 255 },
+	{ 256, 511 },
+	{ 512, 1023 },
+	{ 1024, 1518 },
+	{ 1519, AN8855_MAX_MTU },
+	{}
+};

[Severity: Low]
This isn't a bug, but AN8855_MAX_MTU is an L3 MTU while the other bounds are frame lengths. The last bucket's reported upper bound ends up about 22 bytes below the largest frame the counter can count. mt7530.c and rzn1_a5psw.c use the same convention.

[ ... ]

Quoted 18 lines
drivers/net/dsa/an8855.c new file +18 -0
+static int an8855_port_enable(struct dsa_switch *ds, int port,
+			      struct phy_device *phy)
+{
+	struct an8855_priv *priv = ds->priv;
+	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;
+}
+
+static void an8855_port_disable(struct dsa_switch *ds, int port)
+{
+	struct an8855_priv *priv = ds->priv;

drivers/net/dsa/an8855.c line 616

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+	int ret;
+
+	mutex_lock(&priv->reg_mutex);
+	priv->ports[port].enable = false;
+	ret = regmap_clear_bits(priv->regmap, AN8855_PMCR_P(port),
+				AN8855_PMCR_TX_EN | AN8855_PMCR_RX_EN);
+	mutex_unlock(&priv->reg_mutex);
+	if (ret)
+		dev_err(priv->ds->dev, "failed to disable port: %d\n", ret);
+}

[Severity: High]
mt7530_update_port_member() only writes the port matrix to hardware for ports that are currently enabled:

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

The same check applies to other_p->enable. The helper relies on port_enable to write ports[port].pm and on port_disable to clear the matrix, which is what mt7530_port_enable() and mt7530_port_disable() do. an8855_port_enable() and an8855_port_disable() only toggle the enable flag and PMCR TX/RX_EN.

Take this sequence:

ip link set lan1 master br0 (lan1 still down)
ip link set lan1 up

Doesn't AN8855_PORTMATRIX_P(port) keep the BIT(AN8855_CPU_PORT) value from an8855_setup()? Then the hardware never forwards lan1 frames to its bridge siblings, and the software bridge won't either because offload_fwd_mark is set.

The reverse case is a bridged port that goes down, leaves the bridge, and comes back up standalone. Does its matrix still list the old bridge members, so traffic leaks between the standalone port and the bridge?

Should these callbacks write priv->ports[port].pm to AN8855_PORTMATRIX_P(port) on enable and clear it on disable, as mt7530 does?

drivers/net/dsa/an8855.c line 625

Quoted 8 lines
drivers/net/dsa/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]
This limit matches mt753x_set_mac_eee(), but it rejects this driver's own default. an8855_phylink_get_caps() sets:

	/* Global LPI TXIDLE Threshold, default 60ms (unit 2us) */
	config->lpi_timer_default = FIELD_GET(AN8855_LPI_TXIDLE_THD_MASK, reg) *
				    AN8855_TX_LPI_UNIT;

That is roughly 60000us, and phylink reports it through get_eee. ethnl_set_eee() starts from the get_eee values and only changes the attributes the user passes. dsa_user_set_eee() returns the set_mac_eee() error before it calls phylink_ethtool_set_eee().

So will something like "ethtool --set-eee lan1 eee off" fail with -EINVAL unless a small tx-timer is also given?

an8855_phylink_mac_enable_tx_lpi() already clamps to the 18-bit AN8855_LPI_TXIDLE_THD_MASK field. Is the 0xFFF check needed at all?

[ ... ]

drivers/net/dsa/an8855.c line 902

Quoted 13 lines
drivers/net/dsa/an8855.c new file +13 -0
+static void an8855_phylink_mac_link_up(struct phylink_config *config,
+				       struct phy_device *phydev, unsigned int mode,
+				       phy_interface_t interface, int speed,
+				       int duplex, bool tx_pause, bool rx_pause)
+{
+	struct dsa_port *dp = dsa_phylink_to_port(config);
+	struct an8855_priv *priv = dp->ds->priv;
+	int port = dp->index;
+	u32 reg = 0;
+
+	mutex_lock(&priv->reg_mutex);
+
+	regmap_read(priv->regmap, AN8855_PMCR_P(port), &reg);

[Severity: Low]
The regmap_read() return value is ignored here. If the read fails, reg stays 0, and the later regmap_write(priv->regmap, AN8855_PMCR_P(port), reg) overwrites the whole register. That write would clear:

- MAC_MODE, IFG_XMIT, BACKOFF_EN and BACKPR_EN, set in

    an8855_phylink_mac_config()

- the FORCE_EEE bits, set in an8855_phylink_mac_enable_tx_lpi()

Should the read error be checked, or regmap_update_bits() used instead?

[ ... ]

Quoted 6 lines
drivers/net/dsa/an8855.c new file +6 -0
+	if (timer) {
+		int i;
+
+		/* Save requested timer and search the highest one */
+		mutex_lock(&priv->reg_mutex);
+		priv->tx_lpi_timer_ports[dp->index] = timer;

drivers/net/dsa/an8855.c line 1006

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+		for (i = 0; i < AN8855_NUM_PORTS; i++) {
+			if (!priv->ports[i].enable)
+				continue;
+
+			if (i == dp->index)
+				continue;
+
+			if (timer < priv->tx_lpi_timer_ports[i])
+				timer = priv->tx_lpi_timer_ports[i];
+		}

[Severity: Low]
tx_lpi_timer_ports[] is only written when a non-zero timer is requested. It is not reset in the timer == 0 branch or in an8855_phylink_mac_disable_tx_lpi().

A port that has since disabled LPI, or switched to immediate LPI, still counts in this maximum. Can the shared AN8855_CKGCR threshold therefore stay higher than any active port asked for?

[ ... ]

drivers/net/dsa/an8855.c line 1219

Quoted 6 lines
drivers/net/dsa/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 write go to AN8855_PLL_CTRL_4? The header defines this 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:3 belong to AN8855_RG_DA_QP_PLL_BPA_INTF (GENMASK(4, 2)). The "PLL - LPF" step just above sets that field to 0x5, and this update turns it into 0x1. The PLL_CTRL_4 SDM_HREN bits are never written.

The other PLL_CTRL_4 fields in an8855_pcs_config() (ICOLP_EN and SSC_DIR_DLY) are written to PLL_CTRL_4.

[ ... ]

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+	/* PCS Init */
+	if (interface == PHY_INTERFACE_MODE_SGMII &&
+	    neg_mode == PHYLINK_PCS_NEG_INBAND_DISABLED) {
+		ret = regmap_clear_bits(priv->regmap, AN8855_QP_DIG_MODE_CTRL_0,
+					AN8855_RG_SGMII_MODE | AN8855_RG_SGMII_AN_EN);
+		if (ret)
+			return ret;
+	}
+
+	ret = regmap_clear_bits(priv->regmap, AN8855_RG_HSGMII_PCS_CTROL_1,

drivers/net/dsa/an8855.c line 1460

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+				AN8855_RG_TBI_10B_MODE);
+	if (ret)
+		return ret;
+
+	if (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED) {
+		/* Set AN Ability - Interrupt */
+		ret = regmap_set_bits(priv->regmap, AN8855_SGMII_REG_AN_FORCE_CL37,
+				      AN8855_RG_FORCE_AN_DONE);
+		if (ret)
+			return ret;

[Severity: Low]
Several bits in an8855_pcs_config() are set or cleared in only one branch, and nothing restores them when the mode changes:

- The SGMII in-band path sets RG_FORCE_AN_DONE and RG_P0_RA_AN_EN. It never clears FORCE_TXC_SEL or FORCE_SPD_MODE_P0.
- The in-band path never sets RG_SGMII_MODE or RG_SGMII_AN_EN again after the block above has cleared them.
- RG_P0_MII_MODE is set on the SGMII path and is not cleared on the

    2500BASE-X path.

If phylink reconfigures port 5 to another mode, or the bootloader left a different setup, could these stale bits keep the link from coming up or select the wrong rate adaptation?

[ ... ]

drivers/net/dsa/an8855.c line 1542

Quoted 7 lines
drivers/net/dsa/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]
SGMII without in-band negotiation is always forced to 1000 here, and an8855_pcs_ops has no .pcs_link_up to program the resolved speed.

an8855_phylink_get_caps() still advertises MAC_10 | MAC_100, and an8855_phylink_mac_link_up() forces the MAC to 10 or 100. Take port 5 with phy-mode sgmii and a fixed-link of speed = <100>. Would the PCS stay at 1000 while the MAC runs at 100?

The header defines AN8855_RG_LINK_MODE_P0_SPEED_100 and _10, but they are never used.

Should there be a pcs_link_up callback that programs the speed?

[ ... ]

Quoted 10 lines
drivers/net/dsa/mt7530-lib.c +1 -2
@@ -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);
-	fdb->noarp = val == STATIC_ENT;
+	if (priv->fields[MT7530_ATWD_ENT_STATUS]) {

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

Quoted 10 lines
drivers/net/dsa/mt7530-lib.c +7 -0
+		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;
+	}
 }
 EXPORT_SYMBOL_GPL(mt7530_lib_fdb_read);
 

[Severity: High]
The guard here tests the write-data field MT7530_ATWD_ENT_STATUS, but the read goes through MT7530_ATRD_ENT_STATUS. regmap_field_read() dereferences field->regmap without checking the field pointer. A mt7530-lib user that fills in the ATWD entry but leaves out the ATRD one would oops here on every FDB dump that reaches mt7530_lib_fdb_read().

With the users in this series, both fields appear to be populated together for mt7530 and both are absent for an8855, so nothing crashes today. The check is still protecting the wrong pointer.

The reverse case also goes wrong. A switch that provides only the ATRD status field would silently skip it and never report noarp from it.

Should this test priv->fields[MT7530_ATRD_ENT_STATUS] instead, so the check matches the field that is actually read?

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