net: dsa: Add Airoha AN8855 support
Subsystems (8)
v25 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 v25:
- Address suggestion for MFD for sashiko
- Better handle port enable/disable
Changes v24:
- Add review tag by Andrew
- Fix missing multicast from generalize patch
- Add patch to move mediatek drivers to dedicated driver
- Zero out saved timer on LPI disable
- Correctl check regfiled on FDB read
- Fix MFD leaked of node
- Better handle MFD virtual mdio name
Changes v23:
- Add review by tag for DT patch
- Fix MFD fwnode handle release
- Better handle LPI handling for AN8855
- Add additional kconfig for AN8855
- Use shorter name for virtual phy bus
Changes v22:
- Improve MFD lock handling for phy bus
- Prevent devm crash on removal for MFD driver
- Address VAWD bug reported by bot
- Fix wrong msb for MIB for AN8855 driver
- Better handle kconfig dependency
- Read tx_lpi under lock
Changes v21:
- Rebase on top of net-next
- Drop megred patch from Daniel
- Address suggestion reported by bot for MFD driver
- Drop reset for MFD driver
- Reset FDB and VLAN data on writing
- Fix not correct PCR matrix in port enable
- Add ID_EN7528 fields
- Fix MAC address learning SA_DIS
- Fix MAC address FDB read swapped
- Fix mib reset logic
- Fix AN8855 missing regfiled
- Fix AN8855 ethtool stats access
- Improve tx lpi timer for AN8855
- Improve MFD Documentation patch
Changes v20:
- Address all the typo pointed out by bot
- Make documentation schema more consistent
- Address some concern for the mfd driver from bot
- Fix some conversion problem for the generalization patch
Changes v19:
- Rebase on top of net-next
- Rework with shared function from mt7530 driver
- Add dependency for mt7530 lock
- Fix some define typo for AN8855
Changes v18:
- Fix configurting typo
- Init ret in MFD driver
Changes v17:
- Drop nvmem patch (subset merged and present in linux-next)
- Fix wrong Documentation patch for MFD
- Address reviews for MFD driver
- Rework MTK tag to slipt for Airoha name
Changes v16:
- Rebase on top of net-next
- Drop PBUS implementation (Airoha said that it's not OK to use it)
- Convert to simple mdio-regmap and split regmap
- Fix typo for some define (AND8855 -> AN8855)
Changes v15:
- Rebase on top of net-next
- Drop regmap MDIO patch (in favor of PBUS)
- Implement MDIO PBUS and rework MDIO driver/MFD
- Reimplement EEE support
- Add some check for regmap from MFD
- Move to single regmap and add comments with all findings
Changes v14:
- Move MAITAINERS entry to dedicated commit (make it easier for cross subsystem merge)
- Pack variables in trap function
- Add additional patch for reported difference from MTK tag
Changes v13:
- Reimplement tx_lpi OPs
- Rework mdio-regmap to internally encode/decode address
- Fix error in Documentation
- Drop ext-surge property (assume calibration with declared nvmem cell)
- Fix comments from Lee on MFD driver
- Improve print error and drop extra space in DSA driver
Changes v12:
- Update on top of net-next
- Add additional info on conver-letter about slefttests and HW limitation
- Introduce mdio-regmap generalization for multiple address
- Drop dev flags and define PHY calibration in PHY node directly
Changes v11:
- Address reviews from Christophe (spell mistake + dev_err_probe)
- Fix kconfig dependency for MFD driver (depends on MDIO_DEVICE instead of MDIO) (indirectly fix link error for mdio APIs)
- Fix copy-paste error for MFD driver of_table
- Fix compilation error for PHY (move NVMEM to .config)
- Drop unneeded NVMEM node from MDIO example schema (from Andrew)
- Adapt MFD example schema to MDIO reg property restrictions
Changes v10:
- Entire rework to MFD + split to MDIO, EFUSE, SWITCH separate drivers
- Drop EEE OPs (while Russell finish RFC for EEE changes)
- Use new pcs_inpand OPs
- Drop AN restart function and move to pcs_config
- Enable assisted_learning and disable CPU learn (preparation for fdb_isolation)
- Move EFUSE read in Internal PHY driver to .config to handle EPROBE_DEFER (needed now that NVMEM driver is register externally instead of internally to switch node)
Changes v9:
- Error out on using 5G speed as currently not supported
- Add missing MAC_2500FD in phylink mac_capabilities
- Add comment and improve if condition for an8855_phylink_mac_config Changes v8:
- Add port Fast Age support
- Add support for Port Isolation
- Use correct register for Learning Disable
- Add support for Ageing Time OP
- Set default PVID to 0 by default
- Add mdb OPs
- Add port change MTU
- Fix support for Upper VLAN
Changes v7:
- Fix devm_dsa_register_switch wrong export symbol
Changes v6:
- Drop standard MIB and handle with ethtool OPs (as requested by Jakub)
- Cosmetic: use bool instead of 0 or 1
Changes v5:
- Add devm_dsa_register_switch() patch
- Add Reviewed-by tag for DT patch
Changes v4:
- Set regmap readable_table static (mute compilation warning)
- Add support for port_bridge flags (LEARNING, FLOOD)
- Reset fdb struct in fdb_dump
- Drop support_asym_pause in port_enable
- Add define for get_phy_flags
- Fix bug for port not inititially part of a bridge
(in an8855_setup the port matrix was always cleared but
the CPU port was never initially added)
- Disable learning and flood for user port by default
- Set CPU port to flood and learning by default
- Correctly AND force duplex and flow control in an8855_phylink_mac_link_up
- Drop RGMII from pcs_config
- Check ret in "Disable AN if not in autoneg"
- Use devm_mutex_init
- Fix typo for AN8855_PORT_CHECK_MODE
- Better define AN8855_STP_LISTENING = AN8855_STP_BLOCKING
- Fix typo in AN8855_PHY_EN_DOWN_SHIFT
- Use paged helper for PHY
- Skip calibration in config_init if priv not defined
Changes v3:
- Out of RFC
- Switch PHY code to select_page API
- Better describe masks and bits in PHY driver for ADC register
- Drop raw values and use define for mii read/write
- Switch to absolute PHY address
- Replace raw values with mask and bits for pcs_config
- Fix typo for ext-surge property name
- Drop support for relocating Switch base PHY address on the bus
Changes v2:
- Drop mutex guard patch
- Drop guard usage in DSA driver
- Use __mdiobus_write/read
- Check return condition and return errors for mii read/write
- Fix wrong logic for EEE
- Fix link_down (don't force link down with autoneg)
- Fix forcing speed on sgmii autoneg
- Better document link speed for sgmii reg
- Use standard define for sgmii reg
- Imlement nvmem support to expose switch EFUSE
- Rework PHY calibration with the use of NVMEM producer/consumer
- Update DT with new NVMEM property
- Move aneg validation for 2500-basex in pcs_config
- Move r50Ohm table and function to PHY driver
Christian Marangi (10):
dt-bindings: net: dsa: Document support for Airoha AN8855 DSA Switch
dt-bindings: net: Document support for AN8855 Switch Internal PHY
dt-bindings: mfd: Document support for Airoha AN8855 Switch SoC
mfd: an8855: Add support for Airoha AN8855 Switch
net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY
net: dsa: tag_mtk: add Airoha variant usage of this TAG
MAINTAINERS: add myself as maintainer for Airoha AN8855 Switch
net: dsa: move mediatek DSA driver in dedicated directory
net: dsa: mt7530: generalize and move common function to lib module
net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver
.../bindings/mfd/airoha,an8855.yaml | 176 ++
.../bindings/net/airoha,an8855-phy.yaml | 83 +
.../net/dsa/airoha,an8855-switch.yaml | 86 +
MAINTAINERS | 22 +-
drivers/mfd/Kconfig | 14 +
drivers/mfd/Makefile | 1 +
drivers/mfd/airoha-an8855.c | 579 ++++++
drivers/net/dsa/Kconfig | 45 +-
drivers/net/dsa/Makefile | 5 +-
drivers/net/dsa/mediatek/Kconfig | 59 +
drivers/net/dsa/mediatek/Makefile | 7 +
drivers/net/dsa/mediatek/an8855.c | 1765 +++++++++++++++++
drivers/net/dsa/mediatek/an8855.h | 755 +++++++
drivers/net/dsa/mediatek/mt7530-lib.c | 1156 +++++++++++
drivers/net/dsa/mediatek/mt7530-lib.h | 413 ++++
drivers/net/dsa/{ => mediatek}/mt7530-mdio.c | 4 +
drivers/net/dsa/{ => mediatek}/mt7530-mmio.c | 4 +
drivers/net/dsa/{ => mediatek}/mt7530.c | 1366 +++----------
drivers/net/dsa/{ => mediatek}/mt7530.h | 256 +--
drivers/net/dsa/{ => mediatek}/mt7628.c | 0
drivers/net/phy/Kconfig | 6 +
drivers/net/phy/Makefile | 1 +
drivers/net/phy/air_an8855.c | 275 +++
include/net/dsa.h | 2 +
net/dsa/Kconfig | 11 +
net/dsa/Makefile | 2 +-
net/dsa/tag_mtk.c | 36 +-
27 files changed, 5832 insertions(+), 1297 deletions(-)
create mode 100644 Documentation/devicetree/bindings/mfd/airoha,an8855.yaml
create mode 100644 Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml
create mode 100644 Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml
create mode 100644 drivers/mfd/airoha-an8855.c
create mode 100644 drivers/net/dsa/mediatek/Kconfig
create mode 100644 drivers/net/dsa/mediatek/Makefile
create mode 100644 drivers/net/dsa/mediatek/an8855.c
create mode 100644 drivers/net/dsa/mediatek/an8855.h
create mode 100644 drivers/net/dsa/mediatek/mt7530-lib.c
create mode 100644 drivers/net/dsa/mediatek/mt7530-lib.h
rename drivers/net/dsa/{ => mediatek}/mt7530-mdio.c (99%)
rename drivers/net/dsa/{ => mediatek}/mt7530-mmio.c (97%)
rename drivers/net/dsa/{ => mediatek}/mt7530.c (63%)
rename drivers/net/dsa/{ => mediatek}/mt7530.h (81%)
rename drivers/net/dsa/{ => mediatek}/mt7628.c (100%)
create mode 100644 drivers/net/phy/air_an8855.cSignature · 1 line
2.55.0
PATCH v25 1/10 dt-bindings: net: dsa: Document support for Airoha AN8855 DSA Switch
Document support for Airoha AN8855 5-port Gigabit Switch.
It does expose the 5 Internal PHYs on the MDIO bus and each port can access the Switch register space by configuring the PHY page.
--- .../net/dsa/airoha,an8855-switch.yaml | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml
Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml new file +86 -0
@@ -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
[email protected]
AI reviewRe: [PATCH net-next v25 01/10] dt-bindings: net: dsa: Document support for Airoha AN8855 DSA Switch
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines
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.
Signed-off-by Christian Marangi <[email protected]>
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=1
PATCH v25 2/10 dt-bindings: net: Document support for AN8855 Switch Internal PHY
In reply to Christian MarangiDocument 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
@@ -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
[email protected]
AI reviewRe: [PATCH net-next v25 02/10] dt-bindings: net: Document support for AN8855 Switch Internal PHY
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 10 lines
Document support for AN8855 Switch Internal PHY.
Airoha AN8855 is a 5-port Gigabit Switch that expose the Internal PHYs on the MDIO bus.
Each PHY might need to be calibrated to correctly work with the use of the eFUSE provided by the Switch SoC. This can be enabled by defining in the PHY node the NVMEM cell properties.
Signed-off-by Christian Marangi <[email protected]>
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
[email protected]
AI reviewRe: [PATCH net-next v25 02/10] dt-bindings: net: Document support for AN8855 Switch Internal PHY
In reply to Christian MarangiThank 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] In the example of Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml, both PHY…
- [Low] In the example of Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml,…
--
dt-bindings: net: Document support for AN8855 Switch Internal PHY
This adds a YAML binding for the internal PHYs of the Airoha AN8855 5-port Gigabit Switch. These PHYs are exposed on the MDIO bus. The binding also lets each PHY node reference the SoC eFUSE NVMEM cells (tx_a..tx_d) used for calibration.
Quoted 6 lines
Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml new file +0
-0@@ -0,0 +1,83 @@
[ ... ]
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" (or just the ID compatible)? The same applies to ethernet-phy@2 below.
Later in the series, an8855_core_probe() in drivers/mfd/airoha-an8855.c registers each internal PHY on a bus created by devm_mdio_regmap_register(). That bus only provides C22 accessors:
drivers/net/mdio/mdio-regmap.c:devm_mdio_regmap_register() {
...
mii->read = mdio_regmap_read_c22;
mii->write = mdio_regmap_write_c22;
...
}When the c45 compatible is present, fwnode_mdiobus_register_phy() ignores the explicit c0ff.0410 ID and forces Clause 45 probing:
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);bus->read_c45 is NULL, so __mdiobus_c45_read() returns -EOPNOTSUPP. The call chain is:
get_phy_device()->get_phy_c45_ids()->get_phy_c45_devs_in_pkg()
and get_phy_c45_ids() turns that error into -EIO. an8855_core_probe() treats a fwnode_mdiobus_register_phy() failure as fatal (goto err_put_fwnodes). So a DT copied from this example would make the whole AN8855 MFD fail to probe, and neither the switch nor the eFUSE device would be created.
The PHY driver later in the series (drivers/net/phy/air_an8855.c) also uses C22 paged access, and the MFD binding in the same series ("dt-bindings: mfd: Document support for Airoha AN8855 Switch SoC") uses "ethernet-phy-ieee802.3-c22" for these same PHYs. ethernet-phy.yaml accepts both strings, so dt_binding_check won't flag the mismatch.
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 the PHY at reg 2 meant to use port 0's calibration cells here? In this example ethernet-phy@1 has no cells and ethernet-phy@2 uses shift_sel_port0_tx_*.
The MFD binding later in the series maps them differently:
ethernet-phy@1 (internal_phy1) uses shift_sel_port0_tx_*, ethernet-phy@2 (internal_phy2) uses shift_sel_port1_tx_*, port@0 is internal_phy1 and port@1 is internal_phy2.
an8855_phy_bus_register() computes the port from the address:
phy_offset = addr - priv->switch_addr;
if (phy_offset >= AN8855_MAX_PHY_PORT)
return -EINVAL;So when both reg 1 and reg 2 are present, the PHY at reg 2 can't be port 0.
air_an8855.c reads tx_a..tx_d in an8855_probe() and writes them into the VEND1 R50OHM_RSEL registers in an8855_config_init(). A DTS copied from this example would put port 0's trim on a different PHY and leave the port 0 PHY uncalibrated.
Would it make sense to match the MFD example, with port0 cells on ethernet-phy@1 and port1 cells on ethernet-phy@2?
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/20261009161102.38961-1-ansuelsmth%40gmail.com
PATCH v25 3/10 dt-bindings: mfd: Document support for Airoha AN8855 Switch SoC
In reply to Christian MarangiDocument 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
@@ -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
[email protected]
AI reviewRe: [PATCH net-next v25 03/10] dt-bindings: mfd: Document support for Airoha AN8855 Switch SoC
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines
Document support for Airoha AN8855 Switch SoC. This SoC expose various peripherals like an Ethernet Switch, a NVMEM provider and Ethernet PHYs.
It does also support i2c and timers but those are not currently supported/used.
Signed-off-by Christian Marangi <[email protected]>
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
[email protected]
AI reviewRe: [PATCH net-next v25 03/10] dt-bindings: mfd: Document support for Airoha AN8855 Switch SoC
In reply to Christian MarangiThank 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 two AN8855 binding examples disagree on how the internal PHYs are accessed.
--
dt-bindings: mfd: Document support for Airoha AN8855 Switch SoC
This commit adds a YAML binding for the Airoha AN8855 Switch SoC. The SoC exposes an Ethernet switch, an eFUSE NVMEM provider and internal Ethernet PHYs. The example puts the internal PHYs on a nested mdio node.
Quoted 6 lines
Documentation/devicetree/bindings/mfd/airoha,an8855.yaml new file +0
-0@@ -0,0 +1,176 @@
[ ... ]
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 gives the internal PHYs the ethernet-phy-ieee802.3-c22 compatible. The PHY binding added earlier in this series uses the C45 compatible for the same PHY ID:
Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml:
ethernet-phy@1 {
compatible = "ethernet-phy-idc0ff.0410",
"ethernet-phy-ieee802.3-c45";Which of the two is correct?
The PHY binding selects on ethernet-phy-idc0ff.0410, so it also applies to the PHY nodes nested here. Its $ref to ethernet-phy.yaml accepts both c22 and c45, which means dt_binding_check won't catch the mismatch.
Later in the series, the MFD driver puts each PHY on a bus created with devm_mdio_regmap_register(). That bus only provides C22 accessors:
drivers/net/mdio/mdio-regmap.c:devm_mdio_regmap_register()
mii->read = mdio_regmap_read_c22;
mii->write = mdio_regmap_write_c22;Would a board DT that copies the PHY binding example end up on this path?
an8855_core_probe()
fwnode_mdiobus_register_phy() /* is_c45 is true */
get_phy_device(bus, addr, true)
get_phy_c45_ids()
get_phy_c45_devs_in_pkg()
mdiobus_c45_read()
__mdiobus_c45_read() /* -EOPNOTSUPP, no read_c45 */That error turns into -EIO. an8855_core_probe() then jumps to err_put_fwnodes, so the switch, eFUSE and PHYs never get registered.
The switch binding says its registers are reached by configuring the PHY page. That also points to C22 access.
Should the PHY binding example use ethernet-phy-ieee802.3-c22, or drop the C45 compatible, so the two bindings agree?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261009161102.38961-1-ansuelsmth%40gmail.com
PATCH v25 4/10 mfd: an8855: Add support for Airoha AN8855 Switch
In reply to Christian MarangiAdd support for Airoha AN8855 Switch that provide support for a DSA switch and a NVMEM provider.
Also make use of the mdio-regmap driver and register a regmap for each internal PHY of the switch.
This is needed to handle the double usage of the PHYs as both PHY and Switch accessor.
--- drivers/mfd/Kconfig | 14 + drivers/mfd/Makefile | 1 + drivers/mfd/airoha-an8855.c | 579 ++++++++++++++++++++++++++++++++++++ 3 files changed, 594 insertions(+) create mode 100644 drivers/mfd/airoha-an8855.c
drivers/mfd/Kconfig +14 -0
@@ -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
@@ -8,6 +8,7 @@ obj-$(CONFIG_MFD_88PM860X) += 88pm860x.o obj-$(CONFIG_MFD_88PM800) += 88pm800.o 88pm80x.o obj-$(CONFIG_MFD_88PM805) += 88pm805.o 88pm80x.o obj-$(CONFIG_MFD_88PM886_PMIC) += 88pm886.o +obj-$(CONFIG_MFD_AIROHA_AN8855) += airoha-an8855.o obj-$(CONFIG_MFD_ACT8945A) += act8945a.o obj-$(CONFIG_MFD_SM501) += sm501.o obj-$(CONFIG_ARCH_BCM2835) += bcm2835-pm.o
drivers/mfd/airoha-an8855.c new file +579 -0
579 lines not on this page · raw message
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH net-next v25 04/10] mfd: an8855: Add support for Airoha AN8855 Switch
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] mfd: overlapping regmap readable ranges for General Purpose and GPU timers - [Low] mfd…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] mfd: overlapping regmap readable ranges for General Purpose and GPU timers
- [Low] mfd: structure and variable naming violates MFD API guidelines
--
commit 05d4dc95b969f0fcf66d11398aafad3e7eb7c7f1
Author: Christian Marangi <[email protected]>
mfd: an8855: Add support for Airoha AN8855 Switch
This commit adds support for the Airoha AN8855 Switch which provides a DSA switch and a NVMEM provider. It utilizes the mdio-regmap driver and registers a regmap for each internal PHY.
Quoted 5 lines
drivers/mfd/airoha-an8855.c new file +0
-0
[ ... ]
Quoted 1 line
+static const struct
regmap_rangean8855_readable_ranges[] = {
[ ... ]
drivers/mfd/airoha-an8855.c line 269
Quoted 3 lines
drivers/mfd/airoha-an8855.c new file +3
-0+regmap_reg_range (0x10009000 ,0x10009fff ),/* PDMA */ +regmap_reg_range (0x1000a100 ,0x1000a2ff ),/* General Purpose Timer */ + regmap_reg_range(0x1000a200, 0x1000a2ff), /* GPU timer */
[Severity: Medium]
Is this range definition correct? The General Purpose Timer range (0x1000a100 to 0x1000a2ff) fully overlaps with the GPU timer range (0x1000a200 to 0x1000a2ff).
Could this be a typo in the hardware memory map definition? It seems like the General Purpose Timer range might have been intended to end at 0x1000a1ff to avoid overlapping and potential register access boundary issues.
[ ... ]
drivers/mfd/airoha-an8855.c line 500
Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10
-0+static int an8855_core_probe (struct mdio_device *mdiodev) +{ +struct an8855_phy_bus phy_bus_infos[AN8855_MAX_PHY_PORT ] = { }; +struct device *dev = &mdiodev->dev; +struct an8855_core *priv; +struct regmap *regmap; +int num_phys; +int i, ret; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL );
[Severity: Low]
This isn't a bug, but does this variable and structure naming align with MFD subsystem conventions?
The MFD guidelines suggest avoiding generic variable names like priv, and instead recommend using ddata for the instance variable. Also, should the struct name itself avoid hardcoding implementation details like core? Naming it something closer to struct an8855 might better adhere to the subsystem guidelines.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [PATCH net-next v25 04/10] mfd: an8855: Add support for Airoha AN8855 Switch
Quoted 31 lines · On Sat, Oct 10, 2026 at 04:11:40PM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] mfd: overlapping regmap readable ranges for General Purpose and GPU timers
- [Low] mfd: structure and variable naming violates MFD API guidelines
--commit
05d4dc95b969f0fcf66d11398aafad3e7eb7c7f1
Author: Christian Marangi <[email protected]>mfd: an8855: Add support for Airoha AN8855 Switch
This commit adds support for the Airoha AN8855 Switch which provides a DSA switch and a NVMEM provider. It utilizes the mdio-regmap driver and registers a regmap for each internal PHY.
Quoted 5 lines
drivers/mfd/airoha-an8855.c new file +0
-0[ ... ]
Quoted 1 line
+static const struct
regmap_rangean8855_readable_ranges[] = {[ ... ]
drivers/mfd/airoha-an8855.c line 269
Quoted 3 lines
drivers/mfd/airoha-an8855.c new file +3
-0+regmap_reg_range (0x10009000 ,0x10009fff ),/* PDMA */ +regmap_reg_range (0x1000a100 ,0x1000a2ff ),/* General Purpose Timer */ + regmap_reg_range(0x1000a200, 0x1000a2ff), /* GPU timer */[Severity: Medium]
Is this range definition correct? The General Purpose Timer range (0x1000a100to0x1000a2ff) fully overlaps with the GPU timer range (0x1000a200to0x1000a2ff).
Quoted 5 lines
Could this be a typo in the hardware memory map definition? It seems like the General Purpose Timer range might have been intended to end at
0x1000a1ffto avoid overlapping and potential register access boundary issues.
I have to double check this from documentation, but if possible I would like to fix this with a followup patch.
Quoted 16 lines
[ ... ]
drivers/mfd/airoha-an8855.c line 500
Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10
-0+static int an8855_core_probe (struct mdio_device *mdiodev) +{ +struct an8855_phy_bus phy_bus_infos[AN8855_MAX_PHY_PORT ] = { }; +struct device *dev = &mdiodev->dev; +struct an8855_core *priv; +struct regmap *regmap; +int num_phys; +int i, ret; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL );[Severity: Low]
This isn't a bug, but does this variable and structure naming align with MFD subsystem conventions?
Quoted 6 lines
The MFD guidelines suggest avoiding generic variable names like priv, and instead recommend using ddata for the instance variable. Also, should the struct name itself avoid hardcoding implementation details like core? Naming it something closer to struct an8855 might better adhere to the subsystem guidelines.
I already updated the struct, is it needed to also update the local variables?
Quoted 2 lines
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Signature · 1 line
Ansuel
Lee Jones
maintainerRe: [PATCH net-next v25 04/10] mfd: an8855: Add support for Airoha AN8855 Switch
Quoted 63 lines · Christian Marangi
Quoted 31 lines · On Sat, Oct 10, 2026 at 04:11:40PM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] mfd: overlapping regmap readable ranges for General Purpose and GPU timers
- [Low] mfd: structure and variable naming violates MFD API guidelines
--commit
05d4dc95b969f0fcf66d11398aafad3e7eb7c7f1
Author: Christian Marangi <[email protected]>mfd: an8855: Add support for Airoha AN8855 Switch
This commit adds support for the Airoha AN8855 Switch which provides a DSA switch and a NVMEM provider. It utilizes the mdio-regmap driver and registers a regmap for each internal PHY.
Quoted 5 lines
drivers/mfd/airoha-an8855.c new file +0
-0[ ... ]
Quoted 1 line
+static const struct
regmap_rangean8855_readable_ranges[] = {[ ... ]
drivers/mfd/airoha-an8855.c line 269
Quoted 3 lines
drivers/mfd/airoha-an8855.c new file +3
-0+regmap_reg_range (0x10009000 ,0x10009fff ),/* PDMA */ +regmap_reg_range (0x1000a100 ,0x1000a2ff ),/* General Purpose Timer */ + regmap_reg_range(0x1000a200, 0x1000a2ff), /* GPU timer */[Severity: Medium]
Is this range definition correct? The General Purpose Timer range (0x1000a100to0x1000a2ff) fully overlaps with the GPU timer range (0x1000a200to0x1000a2ff).Quoted 4 lines
Could this be a typo in the hardware memory map definition? It seems like the General Purpose Timer range might have been intended to end at
0x1000a1ffto avoid overlapping and potential register access boundary issues.I have to double check this from documentation, but if possible I would like to fix this with a followup patch.
Quoted 16 lines
[ ... ]
drivers/mfd/airoha-an8855.c line 500
Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10
-0+static int an8855_core_probe (struct mdio_device *mdiodev) +{ +struct an8855_phy_bus phy_bus_infos[AN8855_MAX_PHY_PORT ] = { }; +struct device *dev = &mdiodev->dev; +struct an8855_core *priv; +struct regmap *regmap; +int num_phys; +int i, ret; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL );[Severity: Low]
This isn't a bug, but does this variable and structure naming align with MFD subsystem conventions?Quoted 6 lines
The MFD guidelines suggest avoiding generic variable names like priv, and instead recommend using ddata for the instance variable. Also, should the struct name itself avoid hardcoding implementation details like core? Naming it something closer to struct an8855 might better adhere to the subsystem guidelines.
Quoted 2 lines
I already updated the struct, is it needed to also update the local variables?
Ah, I was just about to apply this!
This would be preferred:
struct an8855 *ddata;
Signature · 1 line
Lee Jones
Re: [PATCH net-next v25 04/10] mfd: an8855: Add support for Airoha AN8855 Switch
Quoted 65 lines · Lee Jones
Quoted 63 lines · Christian Marangi
Quoted 31 lines · On Sat, Oct 10, 2026 at 04:11:40PM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] mfd: overlapping regmap readable ranges for General Purpose and GPU timers
- [Low] mfd: structure and variable naming violates MFD API guidelines
--commit
05d4dc95b969f0fcf66d11398aafad3e7eb7c7f1
Author: Christian Marangi <[email protected]>mfd: an8855: Add support for Airoha AN8855 Switch
This commit adds support for the Airoha AN8855 Switch which provides a DSA switch and a NVMEM provider. It utilizes the mdio-regmap driver and registers a regmap for each internal PHY.
Quoted 5 lines
drivers/mfd/airoha-an8855.c new file +0
-0[ ... ]
Quoted 1 line
+static const struct
regmap_rangean8855_readable_ranges[] = {[ ... ]
drivers/mfd/airoha-an8855.c line 269
Quoted 3 lines
drivers/mfd/airoha-an8855.c new file +3
-0+regmap_reg_range (0x10009000 ,0x10009fff ),/* PDMA */ +regmap_reg_range (0x1000a100 ,0x1000a2ff ),/* General Purpose Timer */ + regmap_reg_range(0x1000a200, 0x1000a2ff), /* GPU timer */[Severity: Medium]
Is this range definition correct? The General Purpose Timer range (0x1000a100to0x1000a2ff) fully overlaps with the GPU timer range (0x1000a200to0x1000a2ff).Quoted 4 lines
Could this be a typo in the hardware memory map definition? It seems like the General Purpose Timer range might have been intended to end at
0x1000a1ffto avoid overlapping and potential register access boundary issues.I have to double check this from documentation, but if possible I would like to fix this with a followup patch.
Quoted 22 lines
[ ... ]
drivers/mfd/airoha-an8855.c line 500
Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10
-0+static int an8855_core_probe (struct mdio_device *mdiodev) +{ +struct an8855_phy_bus phy_bus_infos[AN8855_MAX_PHY_PORT ] = { }; +struct device *dev = &mdiodev->dev; +struct an8855_core *priv; +struct regmap *regmap; +int num_phys; +int i, ret; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL );[Severity: Low]
This isn't a bug, but does this variable and structure naming align with MFD subsystem conventions?The MFD guidelines suggest avoiding generic variable names like priv, and instead recommend using ddata for the instance variable. Also, should the struct name itself avoid hardcoding implementation details like core? Naming it something closer to struct an8855 might better adhere to the subsystem guidelines.
Quoted 9 lines
Quoted 2 lines
I already updated the struct, is it needed to also update the local variables?
Ah, I was just about to apply this!
This would be preferred:
struct an8855 *ddata;
Ahhhhhh! You got me!
Do you think there might be a faster method to submit this so I can quickly rename the variable and you can pick it?
Signature · 1 line
Ansuel
Lee Jones
maintainerRe: [PATCH net-next v25 04/10] mfd: an8855: Add support for Airoha AN8855 Switch
Quoted 73 lines · Christian Marangi
Quoted 72 lines · Lee Jones
Quoted 63 lines · Christian Marangi
Quoted 31 lines · On Sat, Oct 10, 2026 at 04:11:40PM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] mfd: overlapping regmap readable ranges for General Purpose and GPU timers
- [Low] mfd: structure and variable naming violates MFD API guidelines
--commit
05d4dc95b969f0fcf66d11398aafad3e7eb7c7f1
Author: Christian Marangi <[email protected]>mfd: an8855: Add support for Airoha AN8855 Switch
This commit adds support for the Airoha AN8855 Switch which provides a DSA switch and a NVMEM provider. It utilizes the mdio-regmap driver and registers a regmap for each internal PHY.
Quoted 5 lines
drivers/mfd/airoha-an8855.c new file +0
-0[ ... ]
Quoted 1 line
+static const struct
regmap_rangean8855_readable_ranges[] = {[ ... ]
drivers/mfd/airoha-an8855.c line 269
Quoted 3 lines
drivers/mfd/airoha-an8855.c new file +3
-0+regmap_reg_range (0x10009000 ,0x10009fff ),/* PDMA */ +regmap_reg_range (0x1000a100 ,0x1000a2ff ),/* General Purpose Timer */ + regmap_reg_range(0x1000a200, 0x1000a2ff), /* GPU timer */[Severity: Medium]
Is this range definition correct? The General Purpose Timer range (0x1000a100to0x1000a2ff) fully overlaps with the GPU timer range (0x1000a200to0x1000a2ff).Quoted 4 lines
Could this be a typo in the hardware memory map definition? It seems like the General Purpose Timer range might have been intended to end at
0x1000a1ffto avoid overlapping and potential register access boundary issues.I have to double check this from documentation, but if possible I would like to fix this with a followup patch.
Quoted 16 lines
[ ... ]
drivers/mfd/airoha-an8855.c line 500
Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10
-0+static int an8855_core_probe (struct mdio_device *mdiodev) +{ +struct an8855_phy_bus phy_bus_infos[AN8855_MAX_PHY_PORT ] = { }; +struct device *dev = &mdiodev->dev; +struct an8855_core *priv; +struct regmap *regmap; +int num_phys; +int i, ret; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL );[Severity: Low]
This isn't a bug, but does this variable and structure naming align with MFD subsystem conventions?Quoted 6 lines
The MFD guidelines suggest avoiding generic variable names like priv, and instead recommend using ddata for the instance variable. Also, should the struct name itself avoid hardcoding implementation details like core? Naming it something closer to struct an8855 might better adhere to the subsystem guidelines.
Quoted 2 lines
I already updated the struct, is it needed to also update the local variables?
Ah, I was just about to apply this!
This would be preferred:
Quoted 7 lines
Quoted 2 lines
struct an8855 *ddata;
Ahhhhhh! You got me!
Do you think there might be a faster method to submit this so I can quickly rename the variable and you can pick it?
Is everything else ready to go?
BTW, there is no rush on this - I'm done for v7.4-rc1.
Signature · 1 line
Lee Jones
Re: [PATCH net-next v25 04/10] mfd: an8855: Add support for Airoha AN8855 Switch
Quoted 78 lines · Lee Jones
Quoted 76 lines · Christian Marangi
Quoted 74 lines · Lee Jones
Quoted 63 lines · Christian Marangi
Quoted 31 lines · On Sat, Oct 10, 2026 at 04:11:40PM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] mfd: overlapping regmap readable ranges for General Purpose and GPU timers
- [Low] mfd: structure and variable naming violates MFD API guidelines
--commit
05d4dc95b969f0fcf66d11398aafad3e7eb7c7f1
Author: Christian Marangi <[email protected]>mfd: an8855: Add support for Airoha AN8855 Switch
This commit adds support for the Airoha AN8855 Switch which provides a DSA switch and a NVMEM provider. It utilizes the mdio-regmap driver and registers a regmap for each internal PHY.
Quoted 5 lines
drivers/mfd/airoha-an8855.c new file +0
-0[ ... ]
Quoted 1 line
+static const struct
regmap_rangean8855_readable_ranges[] = {[ ... ]
drivers/mfd/airoha-an8855.c line 269
Quoted 3 lines
drivers/mfd/airoha-an8855.c new file +3
-0+regmap_reg_range (0x10009000 ,0x10009fff ),/* PDMA */ +regmap_reg_range (0x1000a100 ,0x1000a2ff ),/* General Purpose Timer */ + regmap_reg_range(0x1000a200, 0x1000a2ff), /* GPU timer */[Severity: Medium]
Is this range definition correct? The General Purpose Timer range (0x1000a100to0x1000a2ff) fully overlaps with the GPU timer range (0x1000a200to0x1000a2ff).Quoted 4 lines
Could this be a typo in the hardware memory map definition? It seems like the General Purpose Timer range might have been intended to end at
0x1000a1ffto avoid overlapping and potential register access boundary issues.I have to double check this from documentation, but if possible I would like to fix this with a followup patch.
Quoted 16 lines
[ ... ]
drivers/mfd/airoha-an8855.c line 500
Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10
-0+static int an8855_core_probe (struct mdio_device *mdiodev) +{ +struct an8855_phy_bus phy_bus_infos[AN8855_MAX_PHY_PORT ] = { }; +struct device *dev = &mdiodev->dev; +struct an8855_core *priv; +struct regmap *regmap; +int num_phys; +int i, ret; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL );[Severity: Low]
This isn't a bug, but does this variable and structure naming align with MFD subsystem conventions?Quoted 6 lines
The MFD guidelines suggest avoiding generic variable names like priv, and instead recommend using ddata for the instance variable. Also, should the struct name itself avoid hardcoding implementation details like core? Naming it something closer to struct an8855 might better adhere to the subsystem guidelines.
Quoted 2 lines
I already updated the struct, is it needed to also update the local variables?
Ah, I was just about to apply this!
This would be preferred:
struct an8855 *ddata;
Quoted 9 lines
Quoted 4 lines
Ahhhhhh! You got me!
Do you think there might be a faster method to submit this so I can quickly rename the variable and you can pick it?
Is everything else ready to go?
BTW, there is no rush on this - I'm done for v7.4-rc1.
Honestly it's really to slim down this series and the fact that it's multi-subystem related.
The net part is done, I also asnwered the comments from sashiko but still waiting a slot for maintainers to check.
I understand there is no rush but it's also true that it's getting problematic to carry this part in this series (at least for me)
So if we can already include the mfd driver and related DT it might be ideal.
Signature · 1 line
Ansuel
Lee Jones
maintainerRe: [PATCH net-next v25 04/10] mfd: an8855: Add support for Airoha AN8855 Switch
Quoted 92 lines · Christian Marangi
Quoted 78 lines · Lee Jones
Quoted 76 lines · Christian Marangi
Quoted 74 lines · Lee Jones
Quoted 63 lines · Christian Marangi
Quoted 31 lines · On Sat, Oct 10, 2026 at 04:11:40PM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] mfd: overlapping regmap readable ranges for General Purpose and GPU timers
- [Low] mfd: structure and variable naming violates MFD API guidelines
--commit
05d4dc95b969f0fcf66d11398aafad3e7eb7c7f1
Author: Christian Marangi <[email protected]>mfd: an8855: Add support for Airoha AN8855 Switch
This commit adds support for the Airoha AN8855 Switch which provides a DSA switch and a NVMEM provider. It utilizes the mdio-regmap driver and registers a regmap for each internal PHY.
Quoted 5 lines
drivers/mfd/airoha-an8855.c new file +0
-0[ ... ]
Quoted 1 line
+static const struct
regmap_rangean8855_readable_ranges[] = {[ ... ]
drivers/mfd/airoha-an8855.c
Quoted 3 lines
drivers/mfd/airoha-an8855.c new file +3
-0+regmap_reg_range (0x10009000 ,0x10009fff ),/* PDMA */ +regmap_reg_range (0x1000a100 ,0x1000a2ff ),/* General Purpose Timer */ + regmap_reg_range(0x1000a200, 0x1000a2ff), /* GPU timer */[Severity: Medium]
Is this range definition correct? The General Purpose Timer range (0x1000a100to0x1000a2ff) fully overlaps with the GPU timer range (0x1000a200to0x1000a2ff).Quoted 4 lines
Could this be a typo in the hardware memory map definition? It seems like the General Purpose Timer range might have been intended to end at
0x1000a1ffto avoid overlapping and potential register access boundary issues.I have to double check this from documentation, but if possible I would like to fix this with a followup patch.
Quoted 16 lines
[ ... ]
drivers/mfd/airoha-an8855.c
Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10
-0+static int an8855_core_probe (struct mdio_device *mdiodev) +{ +struct an8855_phy_bus phy_bus_infos[AN8855_MAX_PHY_PORT ] = { }; +struct device *dev = &mdiodev->dev; +struct an8855_core *priv; +struct regmap *regmap; +int num_phys; +int i, ret; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL );[Severity: Low]
This isn't a bug, but does this variable and structure naming align with MFD subsystem conventions?Quoted 6 lines
The MFD guidelines suggest avoiding generic variable names like priv, and instead recommend using ddata for the instance variable. Also, should the struct name itself avoid hardcoding implementation details like core? Naming it something closer to struct an8855 might better adhere to the subsystem guidelines.
Quoted 2 lines
I already updated the struct, is it needed to also update the local variables?
Ah, I was just about to apply this!
This would be preferred:
struct an8855 *ddata;
Quoted 9 lines
Quoted 4 lines
Ahhhhhh! You got me!
Do you think there might be a faster method to submit this so I can quickly rename the variable and you can pick it?
Is everything else ready to go?
BTW, there is no rush on this - I'm done for v7.4-rc1.
Honestly it's really to slim down this series and the fact that it's multi-subystem related.
Quoted 8 lines
The net part is done, I also asnwered the comments from sashiko but still waiting a slot for maintainers to check.
I understand there is no rush but it's also true that it's getting problematic to carry this part in this series (at least for me)
So if we can already include the mfd driver and related DT it might be ideal.
See my most recent reply to Jakub.
Fix this small thing, then send it as a RESEND and I'll queue it for v7.5.
Signature · 1 line
Lee Jones
[email protected]
AI reviewRe: [PATCH net-next v25 04/10] mfd: an8855: Add support for Airoha AN8855 Switch
In reply to Christian MarangiThank you for your contribution! Sashiko AI review found 13 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 13 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 3 · Low: 9
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 MFD binding (Documentation/devicetree/bindings/mfd/airoha,an8855.yaml) defines…
- [Medium] The commit message says the driver provides "a DSA switch and a NVMEM provider", and so does the MFD_AIROHA_AN8855 help text.
- [Medium] The PHY binding added in this series (Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml) shows…
- [Medium] an8855_phy_bus_register() checks the DT PHY reg only as an offset from the switch address (`phy_offset = addr -…
- [Low] The patch leaves several loose ends: - AN8855_HWTRAP, AN8855_PHY_PAGE_EXTENDED_1 and AN8855_PBUS_MODE_ADDR_INCR are defined…
- [Low] an8855_phy_bus_register() registers one unnamed 16-bit regmap per internal PHY on the MFD parent device.
- [Low] In an8855_readable_ranges, the "General Purpose Timer" entry covers 0x1000a100-0x1000a2ff.
- [Low] The MFD binding leaves efuse out of required, but an8855_cells always adds the "an8855-efuse" cell with of_compatible…
- [Low] In an8855_phy_bus_register(), the u32 addr is printed with %d in dev_err_probe(dev, ..., "phy%d regmap initialization failed\n",…
- [Low] an8855_phy_bus_register() builds each virtual MDIO bus id with snprintf(mrc.name, MII_BUS_ID_SIZE, "%s-phy%u", dev_name(dev), addr)…
- [Low] an8855_regmap_phy_reset_page() always restores page 0 (AN8855_PHY_PAGE_STANDARD) after a switch access.
- [Low] an8855_mdio_register() mixes scope-based and goto-based cleanup.
- [Low] an8855_core_probe() writes 0 to AN8855_RG_GPHY_AFE_PWD, releasing the analog front-end power-down for every internal GPHY at once,…
--
mfd: an8855: Add support for Airoha AN8855 Switch
This adds an MFD core driver for the Airoha AN8855 switch, which sits on an MDIO bus. It exposes a 32-bit switch regmap and registers efuse and DSA switch child cells. It also creates a virtual mdio-regmap bus, with its own regmap, for each internal PHY, so that PHY and switch accesses sharing the same MDIO address are serialized.
Quoted 5 lines
drivers/mfd/Kconfig +0
-0@@ -54,6 +54,20 @@ config MFD_ALTERA_SYSMGR
[ ... ]
drivers/mfd/Kconfig config MFD_ALTERA_SYSMGR · line 69
Quoted 13 lines
drivers/mfd/Kconfig +13
-0+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.
[Severity: Medium]
The commit message and this help text both say the driver provides "a DSA switch and a NVMEM provider". The DSA and PHY parts arrive later in the series, in "net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver" and "net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY".
Can the NVMEM provider be enabled on real hardware, though? The driver for the an8855-efuse cell can still only be built with COMPILE_TEST:
drivers/nvmem/Kconfig:
config NVMEM_AN8855_EFUSE
tristate "Airoha AN8855 eFuse support"
depends on COMPILE_TEST
No patch in the series relaxes this to something like "depends on MFD_AIROHA_AN8855 || COMPILE_TEST", which is what NET_DSA_AN8855 uses.
Once the series is applied, an8855_probe() in drivers/net/phy/air_an8855.c calls nvmem_cell_read_u32() whenever the PHY node has nvmem-cells, as both binding examples do. With no provider registered, that returns -EPROBE_DEFER, or an error if NVMEM is disabled. The PHY driver then never binds, and phy_attach_direct() falls back to genphy.
Wouldn't the R50 calibration and the vendor config_init (downshift and noise-reduction settings) then never be applied?
Quoted 6 lines
drivers/mfd/airoha-an8855.c new file +0
-0@@ -0,0 +1,579 @@
[ ... ]
Quoted 1 line
+#include <
linux/gpio/consumer.h>
[ ... ]
Quoted 2 lines
drivers/mfd/airoha-an8855.c new file +2
-0+/* Register for HW trap status */ +#define AN8855_HWTRAP 0x1000009c
[ ... ]
Quoted 7 lines
drivers/mfd/airoha-an8855.c new file +7
-0+#define AN8855_PHY_PAGE_EXTENDED_1 FIELD_PREP_CONST(AN8855_PHY_PAGE, 0x1) +#define AN8855_PHY_PAGE_EXTENDED_4 FIELD_PREP_CONST(AN8855_PHY_PAGE, 0x4) + +/* MII Registers Page 4 */ +#define AN8855_PBUS_MODE 0x10 +#define AN8855_PBUS_MODE_ADDR_FIXED 0x0 +#define AN8855_PBUS_MODE_ADDR_INCR BIT(15)
[ ... ]
drivers/mfd/airoha-an8855.c line 61
Quoted 6 lines
drivers/mfd/airoha-an8855.c new file +6
-0+struct an8855_core { +struct mii_bus *bus; +struct mii_bus *phy_bus; +unsigned int switch_addr; +u16 current_page; +};
[Severity: Low]
This isn't a bug, but there are a few leftovers here.
AN8855_HWTRAP, AN8855_PHY_PAGE_EXTENDED_1 and AN8855_PBUS_MODE_ADDR_INCR are defined but never used. linux/gpio/consumer.h is included, but no GPIO API is used.
The MFD_AIROHA_AN8855 help text has typos: "to count" and "Ethrnet".
The MFD guidelines also prefer naming the private data struct after the device and calling the instance ddata, rather than using struct an8855_core *priv.
[ ... ]
drivers/mfd/airoha-an8855.c line 79
Quoted 6 lines
drivers/mfd/airoha-an8855.c new file +6
-0+static const struct mfd_cell an8855_cells[] = { +MFD_CELL_OF ("an8855-efuse" ,NULL ,NULL ,0 ,0 , +"airoha,an8855-efuse" ), +MFD_CELL_OF ("an8855-switch" ,NULL ,NULL ,0 ,0 , +"airoha,an8855-switch" ), +};
[Severity: Low]
The airoha,an8855.yaml binding does not list efuse under required, but the an8855-efuse cell is always added.
Take a DT that is valid under the binding but has no efuse node. In that case mfd_add_device() prints "Failed to locate of_node" and registers the platform device anyway. The efuse driver then binds by name and registers an NVMEM device with no OF node, which no PHY can reference.
Should the efuse cell only be added when the node exists, or should efuse be required in the binding?
[ ... ]
Quoted 1 line
+static const struct
regmap_rangean8855_readable_ranges[] = {
[ ... ]
drivers/mfd/airoha-an8855.c line 269
Quoted 3 lines
drivers/mfd/airoha-an8855.c new file +3
-0+regmap_reg_range (0x10009000 ,0x10009fff ),/* PDMA */ +regmap_reg_range (0x1000a100 ,0x1000a2ff ),/* General Purpose Timer */ + regmap_reg_range(0x1000a200, 0x1000a2ff), /* GPU timer */
[Severity: Low]
Should the General Purpose Timer range end at 0x1000a1ff? As written, it fully contains the GPU timer range that follows.
Also, should "GPU timer" be "CPU timer"? That is what the Kconfig help text calls it.
[ ... ]
Quoted 7 lines
drivers/mfd/airoha-an8855.c new file +7
-0+static int an8855_regmap_phy_reset_page (struct an8855_core *priv, + int phy) __must_hold(&priv->bus->mdio_lock) +{ +/* Check PHY page only for addr shared with switch */ +if (phy != priv->switch_addr) +return 0 ; +
drivers/mfd/airoha-an8855.c line 324
Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10
-0+/* Don't restore page if it's not set to Switch page */ +if (priv->current_page !=AN8855_PHY_PAGE_EXTENDED_4 ) +return 0 ; + +/* +* Restore page to 0, PHY might change page right after but that +* will be ignored as it won't be a switch page. +*/ +return an8855_mii_set_page (priv, phy,AN8855_PHY_PAGE_STANDARD ); +}
[Severity: Low]
This isn't a bug for in-kernel users, but this always restores page 0 after a switch access. PHY writes to register 0x1f that go through an8855_regmap_phy_write() don't update priv->current_page. So if a switch regmap access runs between two PHY accesses, the page the PHY selected is lost.
In-kernel, phy_read_paged() and phy_modify_paged() in air_an8855.c hold the virtual bus mdio_lock across the page select, the access and the restore. an8855_regmap_lock() takes the same phy_bus->mdio_lock, so those paths are serialized.
The remaining case is privileged userspace that selects a page with one SIOCSMIIREG call and then accesses a register with a separate call. Is that an acceptable limitation, and should the existing comment mention it?
[ ... ]
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, +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]
Should this also check that addr is below PHY_MAX_ADDR?
With the switch at MDIO address 28-31, a PHY child with reg 32-35 passes this check. of_mdio_parse_addr() would normally reject that address. This driver calls fwnode_mdiobus_register_phy() directly, so the address reaches code that indexes PHY_MAX_ADDR-sized arrays in struct mii_bus:
an8855_core_probe()
fwnode_mdiobus_register_phy()
phy_device_create()
dev->irq = bus->irq[addr];
fwnode_mdiobus_phy_device_register()
mdio->irq[addr] = rc;
mdio->phy_ignore_ta_mask |= 1 << addr;irq[32..35] overlaps reset_delay_us, reset_post_delay_us and reset_gpiod. Also, "1 << addr" is undefined when addr is 32 or more.
Next, phy_device_register() fails with -EBUSY, because mdio_map[addr] overlaps fields that are non-zero. The devres unwind then runs mdiobus_unregister(), which passes bus->reset_gpiod to gpiod_set_value_cansleep().
Could that dereference a corrupted reset_gpiod? Triggering this needs a DT that breaks the reg maximum in mdio.yaml, but the core enforces this bound at runtime on its own paths.
drivers/mfd/airoha-an8855.c line 429
Quoted 9 lines
drivers/mfd/airoha-an8855.c new file +9
-0+ + phy_priv =devm_kzalloc (dev,sizeof (*phy_priv),GFP_KERNEL ); +if (!phy_priv) +return -ENOMEM ; + + phy_priv->addr = addr; + phy_priv->core = priv; + + regmap =devm_regmap_init (dev,NULL , phy_priv, &an8855_phy_regmap_config);
[Severity: Low]
This isn't a bug with the current probe order, but these unnamed PHY regmaps are attached to the same device as the "switch" regmap.
an8855_efuse_probe(), and the DSA driver later in the series, both call dev_get_regmap(dev->parent, NULL). That matches any regmap on the parent and returns the most recently added one. The children get the switch regmap only because an8855_core_probe() creates it after all the PHY regmaps.
Would it be more robust for the children to look up "switch" by name, or to give the PHY regmaps names?
drivers/mfd/airoha-an8855.c line 433
Quoted 4 lines
drivers/mfd/airoha-an8855.c new file +4
-0+if (IS_ERR (regmap)) +return dev_err_probe (dev,PTR_ERR (regmap), +"phy%d regmap initialization failed\n" , + addr);
[Severity: Low]
This isn't a bug, but addr is a u32 printed with %d here, while the snprintf() below prints it with %u.
drivers/mfd/airoha-an8855.c line 438
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 ,"%s-phy%u" ,dev_name (dev), addr);
[Severity: Low]
Can this truncation drop the per-PHY suffix?
dev_name(dev) for this mdio_device is PHY_ID_FMT ("%s:%02x") applied to the parent bus id, which can be up to 60 characters long. If the parent bus id is 53 characters or longer, "-phyN", or at least its digit, gets cut off.
devm_mdio_regmap_register() copies this name into mii->id, so every virtual bus would get the same id and the second bus registration would fail. Should the snprintf() return value be checked, or a shorter naming scheme be used?
drivers/mfd/airoha-an8855.c line 442
Quoted 4 lines
drivers/mfd/airoha-an8855.c new file +4
-0+ + bus =devm_mdio_regmap_register (dev, &mrc); +if (IS_ERR (bus)) +return PTR_ERR (bus);
[Severity: Medium]
The PHY binding added in this series (airoha,an8855-phy.yaml) shows the internal PHYs as:
compatible = "ethernet-phy-idc0ff.0410", "ethernet-phy-ieee802.3-c45";
The MFD binding example uses "ethernet-phy-ieee802.3-c22" for the same PHYs. The bus created here only sets mdio_regmap_read_c22() and mdio_regmap_write_c22(), with no read_c45 or write_c45.
If a DT follows the PHY binding, wouldn't probe fail?
an8855_core_probe()
fwnode_mdiobus_register_phy() /* is_c45 set, PHY ID shortcut skipped */
get_phy_device(bus, addr, true)
get_phy_c45_ids()
mdiobus_c45_read() /* -EOPNOTSUPP without read_c45 */
get_phy_c45_ids() turns that into -EIO, and an8855_core_probe() jumps to err_put_fwnodes. The switch, the efuse and all the PHYs then fail to register.
Should the PHY binding example use c22, or should the driver handle the c45 compatible?
[ ... ]
Quoted 17 lines
drivers/mfd/airoha-an8855.c new file +17
-0+static int an8855_mdio_register (struct device *dev,struct an8855_core *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 480
Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10
-0+ ret =an8855_phy_bus_register (dev, priv, phy_np, + &phy_bus_infos[i]); +if (ret) + goto exit; + + i++; + } + +exit: +of_node_put (mdio_np);
[Severity: Low]
This isn't a bug as written, but this function mixes the scoped iterator (phy_np is declared __free(device_node)) with goto-based cleanup. include/linux/cleanup.h asks that the two not be mixed in one function.
Could mdio_np use __free(device_node), with the error paths returning directly? Alternatively, the non-scoped iterator could be used with an explicit of_node_put() on early exit.
[ ... ]
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 531
Quoted 11 lines
drivers/mfd/airoha-an8855.c new file +11
-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 ); +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;
[Severity: High]
Is the reset-gpios property from the airoha,an8855.yaml binding handled anywhere? The binding example uses reset-gpios = <&pio 39 GPIO_ACTIVE_HIGH>. an8855_core_probe() never requests or toggles that GPIO, and starts MDIO traffic right here.
The MDIO core doesn't handle it either. mdiobus_register_device() only calls mdio_device_register_reset() when MDIO_DEVICE_FLAG_PHY is set, and the AN8855 core is a plain mdio_device.
If the bootloader leaves the switch in reset, wouldn't an8855_read_switch_id() fail and leave the whole switch unusable? If reset was released only just before probe, nothing waits for init to finish. In both cases the chip never gets a clean hardware reset, so switch and PHY state configured by the bootloader carries over.
The unused linux/gpio/consumer.h include and the unused AN8855_HWTRAP ("Register for HW trap status") define suggest a reset-and-wait sequence was removed. Was that intended?
drivers/mfd/airoha-an8855.c line 536
Quoted 5 lines
drivers/mfd/airoha-an8855.c new file +5
-0+ +/* Release global PHY power down */ + ret =regmap_write (regmap,AN8855_RG_GPHY_AFE_PWD ,0x0 ); +if (ret) + goto err_put_fwnodes;
[Severity: Low]
This powers up the analog front end of every internal GPHY, including PHYs that are not described in DT. Is anything expected to put them back into power down?
If a later step fails, the err_put_fwnodes path only drops fwnode references. There is no remove callback or devm action, and the DSA driver later in the series never touches AN8855_RG_GPHY_AFE_PWD.
So after a failed probe or an unbind, the PHYs stay powered with no driver managing them.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261009161102.38961-1-ansuelsmth%40gmail.com
Jakub Kicinski
maintainerRe: [PATCH net-next v25 04/10] mfd: an8855: Add support for Airoha AN8855 Switch
In reply to Christian MarangiQuoted 3 lines · On Fri, 9 Oct 2026 18:10:49 +0200 Christian Marangi wrote:
drivers/mfd/Kconfig | 14 + drivers/mfd/Makefile | 1 + drivers/mfd/airoha-an8855.c | 579 ++++++++++++++++++++++++++++++++++++
You didn't explain why the MFD is needed and more importantly what merging path you expect. We need an ack from Lee, at the very least. Given the merge window has already started I don't think we can do the necessary dance in time.
Signature · 1 line
pw-bot: defer
Lee Jones
maintainerRe: [PATCH net-next v25 04/10] mfd: an8855: Add support for Airoha AN8855 Switch
Quoted 9 lines · Jakub Kicinski
Quoted 3 lines · On Fri, 9 Oct 2026 18:10:49 +0200 Christian Marangi wrote:
drivers/mfd/Kconfig | 14 + drivers/mfd/Makefile | 1 + drivers/mfd/airoha-an8855.c | 579 ++++++++++++++++++++++++++++++++++++You didn't explain why the MFD is needed and more importantly what merging path you expect. We need an ack from Lee, at the very least. Given the merge window has already started I don't think we can do the necessary dance in time.
This patch is orthogonal. No need for a mass-merge.
I plan to queue this for v7.5.
Signature · 1 line
Lee Jones
PATCH v25 5/10 net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY
In reply to Christian MarangiAdd 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
@@ -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
@@ -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
[email protected]
AI reviewRe: [PATCH net-next v25 05/10] net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] net: phy: air_an8855: phy_write_mmd clobbers adjacent reserved fields - [Medium] net: phy…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] net: phy: air_an8855: phy_write_mmd clobbers adjacent reserved fields
- [Medium] net: phy: air_an8855: Array linear search underflow causes valid high efuse values to fall back to default --
commit e8cc9bb475e2accd40605a3774a8e659a3156338
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@@ -0,0 +1,275 @@
[ ... ]
Quoted 20 lines
drivers/net/phy/air_an8855.c new file +20
-0+static const u8 dsa_r50ohm_table[] = { +127 ,127 ,127 ,127 ,127 ,127 ,127 ,127 ,127 ,127 , +127 ,127 ,127 ,127 ,127 ,127 ,127 ,126 ,122 ,117 , +112 ,109 ,104 ,101 ,97 ,94 ,90 ,88 ,84 ,80 , +78 ,74 ,72 ,68 ,66 ,64 ,61 ,58 ,56 ,53 , +51 ,48 ,47 ,44 ,42 ,40 ,38 ,36 ,34 ,32 , +31 ,28 ,27 ,24 ,24 ,22 ,20 ,18 ,16 ,16 , +14 ,12 ,11 ,9 +}; + +static int an8855_get_r50ohm_val (struct device *dev,const char *calib_name, +u8 *dest) +{ +u32 shift_sel, val; +int ret; +int i; + + ret =nvmem_cell_read_u32 (dev, calib_name, &val); +if (ret) +return ret;
drivers/net/phy/air_an8855.c line 90
Quoted 10 lines
drivers/net/phy/air_an8855.c new file +10
-0+ + shift_sel =FIELD_GET (AN8855_SWITCH_EFUSE_R50O , val); +for (i =0 ; i <ARRAY_SIZE (dsa_r50ohm_table); i++) +if (dsa_r50ohm_table[i] == shift_sel) +break ; + +if (i <8 || i >=ARRAY_SIZE (dsa_r50ohm_table)) + *dest = dsa_r50ohm_table[25 ]; +else + *dest = dsa_r50ohm_table[i -8 ];
[Severity: Medium]
Can a valid high efuse value cause an array search underflow here?
Since dsa_r50ohm_table contains 17 occurrences of 127 at the beginning of the array, a forward linear search for 127 breaks at i = 0.
The subsequent logic if (i < 8) intercepts i = 0 as an error. Consequently, an input of 127 falls back to index 25 (94), whereas an input of 126 correctly matches at index 17 and maps to table[17-8] (127). The forward search breaks the - 8 shift algorithm for saturated values.
Quoted 3 lines
drivers/net/phy/air_an8855.c new file +3
-0+ +return 0 ; +}
[ ... ]
Quoted 2 lines
drivers/net/phy/air_an8855.c new file +2
-0+static int an8855_config_init (struct phy_device *phydev) +{
[ ... ]
Quoted 5 lines
drivers/net/phy/air_an8855.c new file +5
-0+/* Apply values to reduce signal noise */ + ret = phy_modify_mmd(phydev, MDIO_MMD_VEND1, AN8855_PHY_TX_PAIR_DLY_SEL_GBE, + AN8855_PHY_CR_DA_TX_PAIR_DELAY_SEL_A_GBE | + AN8855_PHY_CR_DA_TX_PAIR_DELAY_SEL_C_GBE, + FIELD_PREP(AN8855_PHY_CR_DA_TX_PAIR_DELAY_SEL_A_GBE, 0x4) |
drivers/net/phy/air_an8855.c line 204
Quoted 10 lines
drivers/net/phy/air_an8855.c new file +10
-0+ FIELD_PREP(AN8855_PHY_CR_DA_TX_PAIR_DELAY_SEL_C_GBE, 0x4)); +if (ret) +return ret; + 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 ));
[Severity: Medium]
Does this inadvertently clear the adjacent reserved fields for pair B?
phy_write_mmd() unconditionally overwrites the entire 16-bit register. By writing FIELD_PREP(AN8855_PHY_RG_AD_RESERVE0_A, 0x1), this inadvertently zeroes out the adjacent 8-bit field AN8855_PHY_RG_AD_RESERVE0_B (bits 7:0). Should phy_modify_mmd() be used here instead?
drivers/net/phy/air_an8855.c line 208
Quoted 4 lines
drivers/net/phy/air_an8855.c new file +4
-0+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]
Similarly, does this inadvertently clear the adjacent reserved fields for pair D (AN8855_PHY_RG_AD_RESERVE0_D)?
Quoted 5 lines
drivers/net/phy/air_an8855.c new file +5
-0+if (ret) +return ret; + +return 0 ; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Re: [PATCH net-next v25 05/10] net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY
Quoted 57 lines · On Sat, Oct 10, 2026 at 04:11:39PM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] net: phy:air_an8855:phy_write_mmdclobbers adjacent reserved fields
- [Medium] net: phy:air_an8855: Array linear search underflow causes valid high efuse values to fall back to default --commit
e8cc9bb475e2accd40605a3774a8e659a3156338
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@@ -0,0 +1,275 @@[ ... ]
Quoted 20 lines
drivers/net/phy/air_an8855.c new file +20
-0+static const u8 dsa_r50ohm_table[] = { +127 ,127 ,127 ,127 ,127 ,127 ,127 ,127 ,127 ,127 , +127 ,127 ,127 ,127 ,127 ,127 ,127 ,126 ,122 ,117 , +112 ,109 ,104 ,101 ,97 ,94 ,90 ,88 ,84 ,80 , +78 ,74 ,72 ,68 ,66 ,64 ,61 ,58 ,56 ,53 , +51 ,48 ,47 ,44 ,42 ,40 ,38 ,36 ,34 ,32 , +31 ,28 ,27 ,24 ,24 ,22 ,20 ,18 ,16 ,16 , +14 ,12 ,11 ,9 +}; + +static int an8855_get_r50ohm_val (struct device *dev,const char *calib_name, +u8 *dest) +{ +u32 shift_sel, val; +int ret; +int i; + + ret =nvmem_cell_read_u32 (dev, calib_name, &val); +if (ret) +return ret;drivers/net/phy/air_an8855.c line 90
Quoted 10 lines
drivers/net/phy/air_an8855.c new file +10
-0+ + shift_sel =FIELD_GET (AN8855_SWITCH_EFUSE_R50O , val); +for (i =0 ; i <ARRAY_SIZE (dsa_r50ohm_table); i++) +if (dsa_r50ohm_table[i] == shift_sel) +break ; + +if (i <8 || i >=ARRAY_SIZE (dsa_r50ohm_table)) + *dest = dsa_r50ohm_table[25 ]; +else + *dest = dsa_r50ohm_table[i -8 ];[Severity: Medium]
Can a valid high efuse value cause an array search underflow here?
Quoted 8 lines
Since
dsa_r50ohm_tablecontains 17 occurrences of 127 at the beginning of the array, a forward linear search for 127 breaks at i = 0.The subsequent logic if (i < 8) intercepts i = 0 as an error. Consequently, an input of 127 falls back to index 25 (94), whereas an input of 126 correctly matches at index 17 and maps to table[17-8] (127). The forward search breaks the - 8 shift algorithm for saturated values.
This is exaclty the logic used by the original driver and how EFUSE are fused on the PHY.
Quoted 30 lines
Quoted 3 lines
drivers/net/phy/air_an8855.c new file +3
-0+ +return 0 ; +}[ ... ]
Quoted 2 lines
drivers/net/phy/air_an8855.c new file +2
-0+static int an8855_config_init (struct phy_device *phydev) +{[ ... ]
Quoted 5 lines
drivers/net/phy/air_an8855.c new file +5
-0+/* Apply values to reduce signal noise */ + ret = phy_modify_mmd(phydev, MDIO_MMD_VEND1, AN8855_PHY_TX_PAIR_DLY_SEL_GBE, + AN8855_PHY_CR_DA_TX_PAIR_DELAY_SEL_A_GBE | + AN8855_PHY_CR_DA_TX_PAIR_DELAY_SEL_C_GBE, + FIELD_PREP(AN8855_PHY_CR_DA_TX_PAIR_DELAY_SEL_A_GBE, 0x4) |drivers/net/phy/air_an8855.c line 204
Quoted 10 lines
drivers/net/phy/air_an8855.c new file +10
-0+ FIELD_PREP(AN8855_PHY_CR_DA_TX_PAIR_DELAY_SEL_C_GBE, 0x4)); +if (ret) +return ret; + 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 ));[Severity: Medium]
Does this inadvertently clear the adjacent reserved fields for pair B?
Quoted 5 lines
phy_write_mmd()unconditionally overwrites the entire 16-bit register. By writingFIELD_PREP(AN8855_PHY_RG_AD_RESERVE0_A, 0x1), this inadvertently zeroes out the adjacent 8-bit fieldAN8855_PHY_RG_AD_RESERVE0_B(bits 7:0). Shouldphy_modify_mmd()be used here instead?
No this is intended.
Quoted 9 lines
drivers/net/phy/air_an8855.c line 208
Quoted 4 lines
drivers/net/phy/air_an8855.c new file +4
-0+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]
Similarly, does this inadvertently clear the adjacent reserved fields for pair D (AN8855_PHY_RG_AD_RESERVE0_D)?
Intended.
Quoted 8 lines
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
Signature · 1 line
Ansuel
[email protected]
AI reviewRe: [PATCH net-next v25 05/10] net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY
In reply to Christian MarangiThank 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 commit says the driver calibrates the AN8855 PHY from NVMEM cells, but the only provider of those cells cannot be enabled in…
- [Medium] The ETHTOOL_PHY_DOWNSHIFT tunable does not round-trip.
- [Medium] The PHY binding added in this series and the rest of the stack disagree on Clause 22 vs Clause 45.
- [Medium] net: phy: air_an8855: phy_write_mmd clobbers adjacent reserved fields
--
net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY
This adds a PHY driver for the internal Gigabit PHYs in the Airoha AN8855 switch. At probe time it reads R50 calibration values from NVMEM cells. In config_init it applies them together with some noise reduction settings, and it also exposes the downshift tunable.
Quoted 6 lines
drivers/net/phy/air_an8855.c new file +0
-0@@ -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]
Can this probe succeed on a kernel built without COMPILE_TEST when the DT has nvmem-cells? The MFD binding example has them on every PHY.
The only provider of these cells is NVMEM_AN8855_EFUSE. In drivers/nvmem/Kconfig it currently has:
config NVMEM_AN8855_EFUSE
... depends on COMPILE_TEST
Commit 4796eaafd6a1 ("nvmem: an8855: drop an unused Kconfig symbol") removed the MFD_AIROHA_AN8855 alternative because that symbol did not exist yet.
This series adds MFD_AIROHA_AN8855 in "mfd: an8855: Add support for Airoha AN8855 Switch". The "MFD_AIROHA_AN8855 ||" part of that dependency doesn't seem to be added back anywhere in the series.
With NVMEM=y, an8855_get_r50ohm_val()->nvmem_cell_read_u32() ends up in nvmem_device_match(). That never finds a provider and returns -EPROBE_DEFER, so the probe defers forever.
With NVMEM=n, which the new "depends on NVMEM || !NVMEM" in drivers/net/phy/Kconfig allows, the inline nvmem_cell_read_u32() stub returns -EOPNOTSUPP and the probe fails.
Either way this driver never binds, and phy_attach_direct() falls back to genphy when DSA attaches the port. Wouldn't that silently skip the R50 calibration, the noise reduction writes and the downshift enable in an8855_config_init()?
Could the NVMEM_AN8855_EFUSE dependency on MFD_AIROHA_AN8855 be added back? Separately, could the -EOPNOTSUPP case let the PHY run uncalibrated instead of failing the probe?
[ ... ]
Quoted 7 lines
drivers/net/phy/air_an8855.c new file +7
-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;
drivers/net/phy/air_an8855.c line 148
Quoted 10 lines
drivers/net/phy/air_an8855.c new file +10
-0+ + *data = val &AN8855_PHY_EN_DOWN_SHIFT ?DOWNSHIFT_DEV_DEFAULT_COUNT : +DOWNSHIFT_DEV_DISABLE ; + +return 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: Medium]
Does the ETHTOOL_PHY_DOWNSHIFT tunable round-trip correctly?
In an8855_set_downshift(), any count from 1 to 255 returns success. The requested count is dropped and only the enable bit is set. Counts the hardware can't honour are never rejected. ethtool_phy_tunable_valid() in net/ethtool/ioctl.c only checks len and type_id, so range checking is left to the driver.
In an8855_get_downshift(), DOWNSHIFT_DEV_DEFAULT_COUNT (0xff) is reported to userspace whenever the enable bit is set. That value is a request sentinel, not a real retry count.
As a result, "ethtool --set-phy-tunable ethX downshift count 3" succeeds, and a later get shows "Downshift count: 255".
Other drivers that use DOWNSHIFT_DEV_DEFAULT_COUNT (bcm-phy-lib.c, bcm54140.c, marvell10g.c, microchip.c, mscc_main.c, qcom-phy-lib.c) map it to a real count on set and reject counts they can't support. For example, mv3310_set_downshift() does:
if (ds == DOWNSHIFT_DEV_DEFAULT_COUNT) ds = 2;
None of them return 0xff from get.
[ ... ]
Quoted 4 lines
drivers/net/phy/air_an8855.c new file +4
-0+static int an8855_config_init (struct phy_device *phydev) +{ +struct air_an8855_priv *priv = phydev->priv; +int ret;
[ ... ]
drivers/net/phy/air_an8855.c line 195
Quoted 6 lines
drivers/net/phy/air_an8855.c new file +6
-0+/* Apply values to reduce signal noise */ + ret =phy_modify_mmd (phydev,MDIO_MMD_VEND1 ,AN8855_PHY_TX_PAIR_DLY_SEL_GBE , +AN8855_PHY_CR_DA_TX_PAIR_DELAY_SEL_A_GBE | +AN8855_PHY_CR_DA_TX_PAIR_DELAY_SEL_C_GBE , +FIELD_PREP (AN8855_PHY_CR_DA_TX_PAIR_DELAY_SEL_A_GBE ,0x4 ) | +FIELD_PREP (AN8855_PHY_CR_DA_TX_PAIR_DELAY_SEL_C_GBE ,0x4 ));
[Severity: Medium]
Do these two writes clear the pair B and D fields?
The other noise reduction settings in an8855_config_init() only touch pairs A and C. The TX pair delay uses phy_modify_mmd() and the RXADC sample phase uses phy_set_bits_mmd(), so the B and D fields keep their reset values.
The two RXADC reserve registers are handled differently. phy_write_mmd() replaces the whole 16-bit register.
Writing FIELD_PREP(AN8855_PHY_RG_AD_RESERVE0_A, 0x1) to AN8855_PHY_RXADC_REV_0 therefore also sets AN8855_PHY_RG_AD_RESERVE0_B (bits 7:0) to 0. The write to AN8855_PHY_RXADC_REV_1 does the same to AN8855_PHY_RG_AD_RESERVE0_D.
config_init runs from phy_init_hw() on every attach and resume, so this is applied unconditionally. If the reset values of the B and D fields are not zero, this would change the ADC tuning of pairs B and D. That doesn't match how the other A/C-only writes in this block are done.
Is clearing the B and D fields intended, for example because the vendor code writes these registers as whole values? If so, could the code say that? If not, should these be phy_modify_mmd() calls that mask only AN8855_PHY_RG_AD_RESERVE0_A and AN8855_PHY_RG_AD_RESERVE0_C, like the TX pair delay write above?
[Severity: Medium]
Several parts of this driver assume Clause 22 access:
- these MMD accesses, which go through C22-indirect access
- the register 0x1f paging in an8855_read_page() and an8855_write_page()
- genphy_soft_reset(), genphy_suspend() and genphy_resume()
Is the PHY binding added in this series consistent with that?
Both example nodes in Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml use:
compatible = "ethernet-phy-idc0ff.0410",
"ethernet-phy-ieee802.3-c45";The MFD binding example in Documentation/devicetree/bindings/mfd/airoha,an8855.yaml declares the same PHY as "ethernet-phy-ieee802.3-c22".
The MDIO bus registered by an8855_core_probe() comes from devm_mdio_regmap_register(), which only provides C22 accessors:
drivers/net/mdio/mdio-regmap.c:devm_mdio_regmap_register() {
...
mii->read = mdio_regmap_read_c22;
mii->write = mdio_regmap_write_c22;
...
}If a DT follows the PHY binding example, the path would be:
an8855_core_probe()
fwnode_mdiobus_register_phy()
get_phy_device(bus, addr, true)
get_phy_c45_ids()
__mdiobus_c45_read() <- -EOPNOTSUPP, no read_c45get_phy_c45_ids() turns this into -EIO, and the whole MFD probe fails.
Even if a phydev were created with is_c45 set, wouldn't every phy_modify_mmd() and phy_write_mmd() in an8855_config_init() take the unsupported C45 direct access path?
Should the PHY binding examples use "ethernet-phy-ieee802.3-c22" instead?
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261009161102.38961-1-ansuelsmth%40gmail.com
PATCH v25 6/10 net: dsa: tag_mtk: add Airoha variant usage of this TAG
In reply to Christian MarangiAdd 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
@@ -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 37enum 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
@@ -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
@@ -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
@@ -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
[email protected]
AI reviewRe: [PATCH net-next v25 06/10] net: dsa: tag_mtk: add Airoha variant usage of this TAG
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] net: dsa: airoha/mtk eth: hardware offload broken for AIROHA tag protocol --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] net: dsa: airoha/mtk eth: hardware offload broken for AIROHA tag protocol --
commit feed6f0245d293aabba2178225f4097258a1d66c
Author: Christian Marangi <[email protected]>
net: dsa: tag_mtk: add Airoha variant usage of this TAG
This commit adds a new DSA tag protocol variant for Airoha switches, updating the Mediatek tag driver, Kconfig, and Makefile. It also adds comments explaining the differences between Airoha AN8855 and the Mediatek tag bitmap.
Quoted 4 lines
include/net/dsa.h +0
-0
[ ... ]
include/net/dsa.h enum dsa_tag_protocol { · line 80
Quoted 5 lines
include/net/dsa.h +1
-0@@ -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 ID require updating the ethernet MAC and PPE drivers to recognize it as well?
For example, looking at airoha_get_dsa_tag() indrivers/net/ethernet/airoha/airoha_eth.c:
if (dev->dsa_ptr->tag_ops->proto != DSA_TAG_PROTO_MTK) return 0;
And mtk_uses_dsa() in drivers/net/ethernet/mediatek/mtk_eth_soc.c:
return netdev_uses_dsa(dev) && dev->dsa_ptr->tag_ops->proto == DSA_TAG_PROTO_MTK;
If these are not updated to also accept DSA_TAG_PROTO_AIROHA, will hardware tag extraction and PPE hardware flow offloading (like in __mtk_ppe_check_skb() and mtk_flow_get_dsa_port()) fail because the strict protocol checks against DSA_TAG_PROTO_MTK no longer match?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Re: [PATCH net-next v25 06/10] net: dsa: tag_mtk: add Airoha variant usage of this TAG
Quoted 37 lines · On Sat, Oct 10, 2026 at 04:11:37PM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] net: dsa: airoha/mtk eth: hardware offload broken for AIROHA tag protocol --commit
feed6f0245d293aabba2178225f4097258a1d66c
Author: Christian Marangi <[email protected]>net: dsa:
tag_mtk: add Airoha variant usage of this TAGThis commit adds a new DSA tag protocol variant for Airoha switches, updating the Mediatek tag driver,
Kconfig, andMakefile. It also adds comments explaining the differences between Airoha AN8855 and the Mediatek tag bitmap.Quoted 4 lines
include/net/dsa.h +0
-0[ ... ]
include/net/dsa.h enum dsa_tag_protocol { · line 80
Quoted 5 lines
include/net/dsa.h +1
-0@@ -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 ID require updating the ethernet MAC and PPE drivers to recognize it as well?For example, looking at
airoha_get_dsa_tag()indrivers/net/ethernet/airoha/airoha_eth.c:if (dev->dsa_ptr->tag_ops->proto != DSA_TAG_PROTO_MTK) return 0;And
mtk_uses_dsa()indrivers/net/ethernet/mediatek/mtk_eth_soc.c:
Quoted 8 lines
return netdev_uses_dsa(dev) && dev->dsa_ptr->tag_ops->proto == DSA_TAG_PROTO_MTK;If these are not updated to also accept
DSA_TAG_PROTO_AIROHA, will hardware tag extraction and PPE hardware flow offloading (like in__mtk_ppe_check_skb()andmtk_flow_get_dsa_port()) fail because the strict protocol checks againstDSA_TAG_PROTO_MTKno longer match?
This is irrelevant for this series and can be handled later. I'm not sure offload can work with the AN8855 external switch.
Quoted 2 lines
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Signature · 1 line
Ansuel
[email protected]
AI reviewRe: [PATCH net-next v25 06/10] net: dsa: tag_mtk: add Airoha variant usage of this TAG
In reply to Christian MarangiThank 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 as a second proto ID for exactly the same wire format as DSA_TAG_PROTO_MTK.
--
net: dsa: tag_mtk: add Airoha variant usage of this TAG
This commit adds a DSA_TAG_PROTO_AIROHA tag protocol. It reuses the MTK tag xmit/rcv handlers under a separate "airoha" name. The Kconfig is split into NET_DSA_TAG_MTK and NET_DSA_TAG_AIROHA, and both select a common NET_DSA_TAG_MTK_COMMON symbol that builds tag_mtk.o.
Quoted 4 lines
net/dsa/tag_mtk.c +0
-0
[ ... ]
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]
This adds a second proto ID for the same wire format as DSA_TAG_PROTO_MTK. Several conduit drivers handle this tag format in hardware, but they only check for DSA_TAG_PROTO_MTK. None of them are updated here or later in the series.
Once an8855_get_tag_protocol() returns DSA_TAG_PROTO_AIROHA, will AN8855 switches behind these conduits lose that handling?
In 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;
...
}After the -ENODEV, *dev is still the DSA user netdev. That means mtk_flow_set_output_device() fails every eth->netdev[] comparison and returns -EOPNOTSUPP.
Would this reject nft flowtable hardware offload through AN8855 user ports, even though mtk_foe_entry_set_dsa() would build the same tag?
In drivers/net/ethernet/mediatek/mtk_ppe.c, mtk_ppe_check_skb() skips PPE binding for ETH_P_XDSA frames:
case htons(ETH_P_XDSA): if (!netdev_uses_dsa(skb->dev) || skb->dev->dsa_ptr->tag_ops->proto != DSA_TAG_PROTO_MTK) goto out;
In drivers/net/ethernet/mediatek/mtk_eth_soc.c, mtk_uses_dsa() would return false:
return netdev_uses_dsa(dev) && dev->dsa_ptr->tag_ops->proto == DSA_TAG_PROTO_MTK;
On NETSYS v1, mtk_open() then takes the branch that clears MTK_CDMP_STAG_EN. That turns off hardware special tag untagging and RX VLAN offload.
In drivers/net/ethernet/airoha/airoha_eth.c, airoha_get_dsa_tag() returns early:
if (dev->dsa_ptr->tag_ops->proto != DSA_TAG_PROTO_MTK) return 0;
So the 4-byte special tag stays in the frame and is not moved into the QDMA descriptor. That goes against the driver's own comment:
/* PPE module requires untagged DSA packets to work properly, * so move DSA tag to DMA descriptor.
The RX side of that driver still turns on hardware special tag stripping (GDM_STAG_EN_MASK in REG_GDM_INGRESS_CFG), based only on netdev_uses_dsa(). TX and RX handling would then no longer match.
The DSA user netdev also inherits the conduit vlan_features (AIROHA_HW_FEATURES). If the QDMA/FE cannot parse L3/L4 headers behind an in-frame MTK tag, could CHECKSUM_PARTIAL or TSO frames end up with bad checksums? I couldn't confirm that hardware behaviour from the code.
Should these conduit checks accept both DSA_TAG_PROTO_MTK and DSA_TAG_PROTO_AIROHA, maybe through a shared helper? If not, is a separate proto ID needed for an identical tag format?
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/20261009161102.38961-1-ansuelsmth%40gmail.com
PATCH v25 7/10 MAINTAINERS: add myself as maintainer for Airoha AN8855 Switch
In reply to Christian MarangiAdd 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
@@ -759,6 +759,22 @@ S: Maintained F: Documentation/devicetree/bindings/net/airoha,en7581-eth.yaml F: drivers/net/ethernet/airoha/ +AIROHA AN8855 DSA DRIVER +M: Christian Marangi <[email protected]> +L: [email protected] (moderated for non-subscribers) +L: [email protected] (moderated for non-subscribers) +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/mfd/airoha,an8855.yaml +F: Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml +F: Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml +F: Documentation/devicetree/bindings/nvmem/airoha,an8855-efuse.yaml +F: drivers/mfd/airoha-an8855.c +F: drivers/net/dsa/mediatek/an8855.c +F: drivers/net/dsa/mediatek/an8855.h +F: drivers/net/phy/air_an8855.c +F: drivers/nvmem/an8855-efuse.c + AIROHA PCIE PHY DRIVER M: Lorenzo Bianconi <[email protected]> L: [email protected] (moderated for non-subscribers)
Signature · 1 line
2.55.0
PATCH v25 8/10 net: dsa: move mediatek DSA driver in dedicated directory
In reply to Christian MarangiTo tidy things up and better organize DSA drivers, move the Mediatek related driver to the dedicated Vendor directory.
MAINTAINERS file is updated accordingly to reference the new location.
---
MAINTAINERS | 6 +--
drivers/net/dsa/Kconfig | 45 +-------------------
drivers/net/dsa/Makefile | 5 +--
drivers/net/dsa/mediatek/Kconfig | 45 ++++++++++++++++++++
drivers/net/dsa/mediatek/Makefile | 5 +++
drivers/net/dsa/{ => mediatek}/mt7530-mdio.c | 0
drivers/net/dsa/{ => mediatek}/mt7530-mmio.c | 0
drivers/net/dsa/{ => mediatek}/mt7530.c | 0
drivers/net/dsa/{ => mediatek}/mt7530.h | 0
drivers/net/dsa/{ => mediatek}/mt7628.c | 0
10 files changed, 55 insertions(+), 51 deletions(-)
create mode 100644 drivers/net/dsa/mediatek/Kconfig
create mode 100644 drivers/net/dsa/mediatek/Makefile
rename drivers/net/dsa/{ => mediatek}/mt7530-mdio.c (100%)
rename drivers/net/dsa/{ => mediatek}/mt7530-mmio.c (100%)
rename drivers/net/dsa/{ => mediatek}/mt7530.c (100%)
rename drivers/net/dsa/{ => mediatek}/mt7530.h (100%)
rename drivers/net/dsa/{ => mediatek}/mt7628.c (100%)MAINTAINERS +3 -3
@@ -16841,9 +16841,9 @@ M: Chester A. Unal <[email protected]> M: Daniel Golle <[email protected]> L: [email protected] S: Maintained -F: drivers/net/dsa/mt7530-mdio.c -F: drivers/net/dsa/mt7530-mmio.c -F: drivers/net/dsa/mt7530.* +F: drivers/net/dsa/mediatek/mt7530-mdio.c +F: drivers/net/dsa/mediatek/mt7530-mmio.c +F: drivers/net/dsa/mediatek/mt7530.* F: net/dsa/tag_mtk.c MEDIATEK T7XX 5G WWAN MODEM DRIVER
drivers/net/dsa/Kconfig +1 -44
51 lines not on this page · raw message
drivers/net/dsa/Makefile +1 -4
@@ -2,10 +2,6 @@ obj-$(CONFIG_NET_DSA_BCM_SF2) += bcm-sf2.o bcm-sf2-objs := bcm_sf2.o bcm_sf2_cfp.o obj-$(CONFIG_NET_DSA_LOOP) += dsa_loop.o -obj-$(CONFIG_NET_DSA_MT7530) += mt7530.o -obj-$(CONFIG_NET_DSA_MT7530_MDIO) += mt7530-mdio.o -obj-$(CONFIG_NET_DSA_MT7530_MMIO) += mt7530-mmio.o -obj-$(CONFIG_NET_DSA_MT7628) += mt7628.o obj-$(CONFIG_NET_DSA_MV88E6060) += mv88e6060.o obj-$(CONFIG_NET_DSA_RZN1_A5PSW) += rzn1_a5psw.o obj-$(CONFIG_NET_DSA_SMSC_LAN9303) += lan9303-core.o
@@ -17,6 +13,7 @@ obj-$(CONFIG_NET_DSA_VITESSE_VSC73XX_SPI) += vitesse-vsc73xx-spi.o obj-y += b53/ obj-y += hirschmann/ obj-y += lantiq/ +obj-y += mediatek/ obj-y += microchip/ obj-y += motorcomm/ obj-y += mv88e6xxx/
drivers/net/dsa/mediatek/Kconfig new file +45 -0
45 lines not on this page · raw message
drivers/net/dsa/mediatek/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_NET_DSA_MT7530) += mt7530.o +obj-$(CONFIG_NET_DSA_MT7530_MDIO) += mt7530-mdio.o +obj-$(CONFIG_NET_DSA_MT7530_MMIO) += mt7530-mmio.o +obj-$(CONFIG_NET_DSA_MT7628) += mt7628.o
drivers/net/dsa/mediatek/mt7530-mdio.c renamed from drivers/net/dsa/mt7530-mdio.c +0 -0
drivers/net/dsa/mediatek/mt7530-mmio.c renamed from drivers/net/dsa/mt7530-mmio.c +0 -0
drivers/net/dsa/mediatek/mt7530.c renamed from drivers/net/dsa/mt7530.c +0 -0
drivers/net/dsa/mediatek/mt7530.h renamed from drivers/net/dsa/mt7530.h +0 -0
drivers/net/dsa/mediatek/mt7628.c renamed from drivers/net/dsa/mt7628.c +0 -0
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH net-next v25 08/10] net: dsa: move mediatek DSA driver in dedicated directory
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines
To tidy things up and better organize DSA drivers, move the Mediatek related driver to the dedicated Vendor directory.
MAINTAINERSfile is updated accordingly to reference the new location.Signed-off-by Christian Marangi <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
PATCH v25 9/10 net: dsa: mt7530: generalize and move common function to lib module
In reply to Christian MarangiIn preparation of support of DSA Switch from Airoha, create a mt7530 library module and move there all the common function.
Function are generalized to use the reg_field regmap API but still apply the same exact logic. Every function is renamed to mt7530_lib prefix to better identify it.
Minimum modification are needed to the register header and common enum and macro are moved to the mt7530 library header to permit reuse.
A library struct is introduced with everything required for the common functions.
The generalization and the introduction of reg_field regmap API have the side effect of permitting to clean the mirror functions that required special handling for MT7530 and MT7531 based switch that had different registers. This is done by declaring a common MT7530 reg_field and a specific one in the Switch match table.
No behaviour change is expected by this change as it's just a code move and reimplementation.
--- drivers/net/dsa/mediatek/Kconfig | 4 + drivers/net/dsa/mediatek/Makefile | 1 + drivers/net/dsa/mediatek/mt7530-lib.c | 1128 +++++++++++++++++++ drivers/net/dsa/mediatek/mt7530-lib.h | 391 +++++++ drivers/net/dsa/mediatek/mt7530-mdio.c | 4 + drivers/net/dsa/mediatek/mt7530-mmio.c | 4 + drivers/net/dsa/mediatek/mt7530.c | 1366 ++++++------------------ drivers/net/dsa/mediatek/mt7530.h | 256 ++--- 8 files changed, 1912 insertions(+), 1242 deletions(-) create mode 100644 drivers/net/dsa/mediatek/mt7530-lib.c create mode 100644 drivers/net/dsa/mediatek/mt7530-lib.h
drivers/net/dsa/mediatek/Kconfig +4 -0
@@ -1,6 +1,10 @@ # SPDX-License-Identifier: GPL-2.0-only +config NET_DSA_MT7530_LIB + tristate + config NET_DSA_MT7530 tristate "MediaTek MT7530 and MT7531 Ethernet switch support" + select NET_DSA_MT7530_LIB select NET_DSA_TAG_MTK select REGMAP_IRQ imply NET_DSA_MT7530_MDIO
drivers/net/dsa/mediatek/Makefile +1 -0
@@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_NET_DSA_MT7530) += mt7530.o +obj-$(CONFIG_NET_DSA_MT7530_LIB) += mt7530-lib.o obj-$(CONFIG_NET_DSA_MT7530_MDIO) += mt7530-mdio.o obj-$(CONFIG_NET_DSA_MT7530_MMIO) += mt7530-mmio.o obj-$(CONFIG_NET_DSA_MT7628) += mt7628.o
drivers/net/dsa/mediatek/mt7530-lib.c new file +1128 -0
1,128 lines not on this page · raw message
drivers/net/dsa/mediatek/mt7530-lib.h new file +391 -0
391 lines not on this page · raw message
drivers/net/dsa/mediatek/mt7530-mdio.c +4 -0
@@ -218,6 +218,10 @@ mt7530_probe(struct mdio_device *mdiodev)if (IS_ERR (priv->regmap))return PTR_ERR (priv->regmap); + ret =mt7530_setup_lib_priv (priv); +if (ret) +return ret; +if (priv->id ==ID_MT7531 ) priv->create_sgmii = mt7531_create_sgmii;
drivers/net/dsa/mediatek/mt7530-mmio.c +4 -0
@@ -61,6 +61,10 @@ mt7988_probe(struct platform_device *pdev)if (IS_ERR (priv->regmap))return PTR_ERR (priv->regmap); + ret =mt7530_setup_lib_priv (priv); +if (ret) +return ret; +return dsa_register_switch (priv->ds); }
drivers/net/dsa/mediatek/mt7530.c +320 -1046
1,445 lines not on this page · raw message
drivers/net/dsa/mediatek/mt7530.h +60 -196
256 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.55.0
Part of the diff is not shown here. View the raw message.
[email protected]
AI reviewRe: [PATCH net-next v25 09/10] net: dsa: mt7530: generalize and move common function to lib module
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] net: severe MDIO bus performance regression via sequential regmap_field accesses - [Medium] net…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] net: severe MDIO bus performance regression via sequential regmap_field accesses
- [Medium] net: dsa: mt7530: stale hardware bits preserved during VLAN setup due to RMW --
commit 9f9905cb3bdc569b54ef5ded23eb827e6ba6ffc2
Author: Christian Marangi <[email protected]>
net: dsa: mt7530: generalize and move common function to lib module
This commit creates a mt7530 library module to share common functions in preparation for Airoha switch support. The functions are refactored to use the reg_field regmap API for register access while aiming to preserve the same logic. Minimum modifications are made to header files to permit reuse of common macros and enums.
Quoted 5 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +0
-0
[ ... ]
drivers/net/dsa/mediatek/mt7530-lib.c line 447
Quoted 11 lines
drivers/net/dsa/mediatek/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); +regmap_field_write (priv->fields[MT7530_ATWD_IVL ],1 );
[Severity: High]
Does this sequence of regmap_field_write() calls cause a severe performance regression on the MDIO bus?
Since the MDIO bus is inherently slow, taking around 20 to 30 microseconds per transaction, replacing a bulk 32-bit regmap_write() with individual regmap_field_write() operations expands a single register update into multiple Read-Modify-Write cycles.
It looks like this single FDB entry write will now execute up to 15 RMW operations instead of a single bulk update.
Quoted 3 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +3
-0+regmap_field_write (priv->fields[MT7530_ATWD_FID ],FID_BRIDGED ); +regmap_field_write (priv->fields[MT7530_ATWD_AGE_TIMER ], aging); +regmap_field_write (priv->fields[MT7530_ATWD_PORT_MAP ], port_mask);
[ ... ]
drivers/net/dsa/mediatek/mt7530-lib.c line 471
Quoted 8 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +8
-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; +regmap_field_read (priv->fields[MT7530_ATRD_AGE_TIMER ], &val); + fdb->aging = val;
[Severity: High]
Similarly, does this sequence expand a single 3-register access into 10 separate MDIO read transactions?
If a full FDB dump of 2048 entries is requested, or continuous stat polling occurs, this could multiply the bus traffic and cause severe latency and MDIO bus congestion.
Quoted 4 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +4
-0+regmap_field_read (priv->fields[MT7530_ATRD_PORT_MAP ], &val); + fdb->port_mask = val; +regmap_field_read (priv->fields[MT7530_ATRD_MAC_BYTE_5 ], &val); + fdb->mac[5 ] = val;
[ ... ]
Quoted 9 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +9
-0+static void mt7530_hw_vlan_add (struct mt7530_lib_priv *priv, +struct mt7530_hw_vlan_entry *entry) +{ +struct dsa_port *dp =dsa_to_port (priv->ds, entry->port); +u8 new_members; +u32 val; + + new_members = entry->old_members |BIT (entry->port); +
drivers/net/dsa/mediatek/mt7530-lib.c line 949
Quoted 10 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +10
-0+/* Validate the entry with independent learning, create egress tag per +* VLAN and joining the port as one of the port members. +*/ +regmap_field_write (priv->fields[MT7530_VAWD_IVL_MAC ],1 ); +regmap_field_write (priv->fields[MT7530_VAWD_VTAG_EN ],1 ); +regmap_field_write (priv->fields[MT7530_VAWD_PORT_MEM ], + new_members); +regmap_field_write (priv->fields[MT7530_VAWD_FID ], +FID_BRIDGED ); +regmap_field_write (priv->fields[MT7530_VAWD_VLAN_VALID ],1 );
[Severity: Medium]
Can this sequence of regmap_field_write() calls preserve stale hardware bits and leak them into new VLAN entries?
By using individual regmap_field_write() operations, this performs Read-Modify-Write cycles on the previously populated hardware register via RD_VID. The old implementation used a full 32-bit regmap_write() which safely cleared unspecified bits.
It appears that any leftover hardware bits in MT7530_VAWD1, such as EG_CON or PORT_STAG from prior usages or bootloader states, will be preserved.
Could this lead to corrupted egress tagging behaviors or STAG attributes on standard VLANs?
Quoted 4 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +4
-0+ +/* Decide whether adding tag or not for those outgoing packets from the +* port inside the VLAN. +* CPU port is always taken as a tagged port for serving more than one
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
Re: [PATCH net-next v25 09/10] net: dsa: mt7530: generalize and move common function to lib module
Quoted 40 lines · On Sat, Oct 10, 2026 at 04:11:43PM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] net: severe MDIO bus performance regression via sequentialregmap_fieldaccesses
- [Medium] net: dsa: mt7530: stale hardware bits preserved during VLAN setup due to RMW --commit
9f9905cb3bdc569b54ef5ded23eb827e6ba6ffc2
Author: Christian Marangi <[email protected]>net: dsa: mt7530: generalize and move common function to lib module
This commit creates a mt7530 library module to share common functions in preparation for Airoha switch support. The functions are refactored to use the
reg_fieldregmap API for register access while aiming to preserve the same logic. Minimum modifications are made to header files to permit reuse of common macros and enums.Quoted 5 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +0
-0[ ... ]
drivers/net/dsa/mediatek/mt7530-lib.c line 447
Quoted 11 lines
drivers/net/dsa/mediatek/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); +regmap_field_write (priv->fields[MT7530_ATWD_IVL ],1 );[Severity: High]
Does this sequence ofregmap_field_write()calls cause a severe performance regression on the MDIO bus?
Quoted 8 lines
Since the MDIO bus is inherently slow, taking around 20 to 30 microseconds per transaction, replacing a bulk 32-bit
regmap_write()with individualregmap_field_write()operations expands a single register update into multiple Read-Modify-Write cycles.It looks like this single FDB entry write will now execute up to 15 RMW operations instead of a single bulk update.
I think it's acceptable for the good generalization done here and also it's not exactly an hot path updating the FDB entry.
Quoted 23 lines
Quoted 3 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +3
-0+regmap_field_write (priv->fields[MT7530_ATWD_FID ],FID_BRIDGED ); +regmap_field_write (priv->fields[MT7530_ATWD_AGE_TIMER ], aging); +regmap_field_write (priv->fields[MT7530_ATWD_PORT_MAP ], port_mask);[ ... ]
drivers/net/dsa/mediatek/mt7530-lib.c line 471
Quoted 8 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +8
-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; +regmap_field_read (priv->fields[MT7530_ATRD_AGE_TIMER ], &val); + fdb->aging = val;[Severity: High]
Similarly, does this sequence expand a single 3-register access into 10 separate MDIO read transactions?If a full FDB dump of 2048 entries is requested, or continuous stat polling occurs, this could multiply the bus traffic and cause severe latency and MDIO bus congestion.
Quoted 7 lines
Quoted 4 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +4
-0+regmap_field_read (priv->fields[MT7530_ATRD_PORT_MAP ], &val); + fdb->port_mask = val; +regmap_field_read (priv->fields[MT7530_ATRD_MAC_BYTE_5 ], &val); + fdb->mac[5 ] = val;[ ... ]
Same reason, it's acceptable.
Quoted 29 lines
Quoted 9 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +9
-0+static void mt7530_hw_vlan_add (struct mt7530_lib_priv *priv, +struct mt7530_hw_vlan_entry *entry) +{ +struct dsa_port *dp =dsa_to_port (priv->ds, entry->port); +u8 new_members; +u32 val; + + new_members = entry->old_members |BIT (entry->port); +drivers/net/dsa/mediatek/mt7530-lib.c line 949
Quoted 10 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +10
-0+/* Validate the entry with independent learning, create egress tag per +* VLAN and joining the port as one of the port members. +*/ +regmap_field_write (priv->fields[MT7530_VAWD_IVL_MAC ],1 ); +regmap_field_write (priv->fields[MT7530_VAWD_VTAG_EN ],1 ); +regmap_field_write (priv->fields[MT7530_VAWD_PORT_MEM ], + new_members); +regmap_field_write (priv->fields[MT7530_VAWD_FID ], +FID_BRIDGED ); +regmap_field_write (priv->fields[MT7530_VAWD_VLAN_VALID ],1 );[Severity: Medium]
Can this sequence ofregmap_field_write()calls preserve stale hardware bits and leak them into new VLAN entries?By using individual
regmap_field_write()operations, this performs Read-Modify-Write cycles on the previously populated hardware register viaRD_VID. The old implementation used a full 32-bitregmap_write()which safely cleared unspecified bits.
Quoted 6 lines
It appears that any leftover hardware bits in
MT7530_VAWD1, such asEG_CONorPORT_STAGfrom prior usages or bootloader states, will be preserved.Could this lead to corrupted egress tagging behaviors or STAG attributes on standard VLANs?
From what I can see the vlan entry gets read first for existance. This zero all these values addressing this concern.
Quoted 9 lines
Quoted 4 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +4
-0+ +/* Decide whether adding tag or not for those outgoing packets from the +* port inside the VLAN. +* CPU port is always taken as a tagged port for serving more than one [ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
Signature · 1 line
Ansuel
[email protected]
AI reviewRe: [PATCH net-next v25 09/10] net: dsa: mt7530: generalize and move common function to lib module
In reply to Christian MarangiThank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider.
Critical: 0 · High: 2 · Medium: 4 (1) · Low: 2
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [High] Name collision between the new enum constant and an old register macro in drivers/net/dsa/mediatek/mt7530.c.
- [High] net: severe MDIO bus performance regression via sequential regmap_field accesses
- [Medium] EN7528 port mirroring now programs the wrong register.
- [Medium] VLAN table entries written by mt7530_hw_vlan_add()/mt7530_hw_vlan_del()…
- [Medium] Failed final status reads are treated as success.
- [Medium] The switch to regmap_field_read() introduces uninitialized stack reads.
- [Low] mt7530_lib_mib_reset() replaces the two full writes to MT7530_MIB_CCR (CCR_MIB_FLUSH = 0xF0, then CCR_MIB_ACTIVATE =…
- [Low] Two comments no longer match the definitions they describe.
Pre-existing issues:
- [Medium] This problem wasn't introduced by this patch, but mt7530_port_fdb_dump() saves the callback's return value (for example…
--
net: dsa: mt7530: generalize and move common function to lib module
This moves the common MT7530 FDB, VLAN, bridge, mirror, MTU and MIB helpers into a new mt7530-lib module. They are reimplemented on top of the regmap_field API, and the per-chip mirror register layout is now described by a reg_field table in mt753x_info. The commit message states that no behaviour change is expected.
Quoted 6 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +0
-0@@ -0,0 +1,1128 @@
[ ... ]
drivers/net/dsa/mediatek/mt7530-lib.c line 19
Quoted 9 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +9
-0+void mt7530_lib_mib_reset (struct mt7530_lib_priv *priv) +{ +regmap_field_write (priv->fields[MT7530_CCR_MIB_ENABLE ],0 ); +regmap_field_write (priv->fields[MT7530_CCR_RX_OCT_CNT_GOOD ],1 ); +regmap_field_write (priv->fields[MT7530_CCR_RX_OCT_CNT_BAD ],1 ); +regmap_field_write (priv->fields[MT7530_CCR_TX_OCT_CNT_GOOD ],1 ); +regmap_field_write (priv->fields[MT7530_CCR_TX_OCT_CNT_BAD ],1 ); +regmap_field_write (priv->fields[MT7530_CCR_MIB_ENABLE ],1 ); +}
[Severity: Low]
Is this sequence equivalent to the old one? The removed mt7530_mib_reset() wrote the whole register twice:
regmap_write(priv->regmap, MT7530_MIB_CCR, CCR_MIB_FLUSH);
regmap_write(priv->regmap, MT7530_MIB_CCR, CCR_MIB_ACTIVATE);regmap_field_write() is a read-modify-write that skips the bus write when the value is unchanged. If MIB_ENABLE already reads as 0, the flush write is never sent.
Bits 30:8 and 3:0 of MT7530_MIB_CCR are also no longer forced to 0, so reset or bootloader values in those bits survive.
Could this change how the MIB counters get cleared and activated compared with the old code? Separately, the MT7530_CCR_TX_OCT_CNT_GOOD write is misrouted by the MT7530_MIRROR_EN collision described further down.
[ ... ]
drivers/net/dsa/mediatek/mt7530-lib.c line 403
Quoted 3 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +3
-0+int mt7530_lib_fdb_cmd (struct mt7530_lib_priv *priv,enum mt7530_fdb_cmd cmd, +u32 mat,u32 *rsp) +{
[Severity: High]
How much extra MDIO traffic does this add on MDIO-connected switches? On MT7530 and MT7531, each 32-bit register access already costs several MDIO frames. mt7530_regmap_read() and mt7530_regmap_write() each issue a page select plus two 16-bit transfers.
The old mt7530_fdb_read() did three regmap_read() calls, on TSRA1, TSRA2 and ATRD. This version does ten regmap_field_read() calls, and each one is a separate bus read of one of those same three registers. That is more than three times the bus traffic for every entry.
The write side is worse. regmap_field_write() goes through regmap_update_bits_base(). These regmaps don't appear to have a register cache, and the ARL registers are volatile anyway. So each call is a bus read, followed by a write when the value differs.
mt7530_lib_fdb_write() does three clearing writes and then twelve field writes. That is up to 15 reads and 15 writes, where mt7530_fdb_write() did three plain regmap_write() calls. mt7530_lib_fdb_cmd() likewise turns the single ATC write into three read-modify-write cycles before the BUSY poll.
mt7530_port_fdb_dump() goes through this path once per entry, up to MT7530_NUM_FDB_RECORDS times, while holding reg_mutex. Every port_fdb_add/del and port_mdb_add/del also pays the expanded cost. The VLAN paths do too: mt7530_hw_vlan_add(), mt7530_hw_vlan_del() and mt7530_lib_setup_vlan0() now do one read-modify-write per field. The old code built VAWD1 in software and wrote it once.
The result is a large increase in FDB dump and update latency. It also adds a lot of MDIO bus load that the PHYs on the same bus have to compete with. That doesn't seem to fit "No behaviour change is expected".
Could the library build the full ATA1/ATA2/ATWD and VAWD1 values in software and write each register once? On the read side, it could read TSRA1/TSRA2/ATRD once and extract the fields from those values. The per-chip layout could then be described with masks rather than separate regmap_field accesses. Alternatively, were FDB dump times measured on an MDIO-attached MT7531 before and after this change?
[ ... ]
Quoted 6 lines
drivers/net/dsa/mediatek/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/mediatek/mt7530-lib.c line 434
Quoted 10 lines
drivers/net/dsa/mediatek/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: Medium]
What happens here if one of these final reads fails? After a successful BUSY poll, val is 0. regmap_field_read() returns early on error without touching its output:
ret = regmap_read(field->regmap, field->reg, ®_val);
if (ret != 0)
return ret;A failed ATC_INVALID read therefore makes a failed FDB_READ look like a valid hit. The unchecked rsp read leaves the caller's previous rsp in place, so mt7530_port_fdb_dump() could act on stale ATC_SRCH_HIT or ATC_SRCH_END bits.
mt7530_vlan_cmd() does the same with the MT7530_VTCR_INVALID read and returns 0.
The removed helpers propagated these errors:
if (!ret)
ret = regmap_read(priv->regmap, MT7530_ATC, &val);
if (ret < 0) {
...
return ret;
}Should the return values of these reads be checked?
[ ... ]
Quoted 9 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +9
-0+int mt7530_lib_port_mdb_add (struct mt7530_lib_priv *priv,int port, +const struct switchdev_obj_port_mdb *mdb, +struct dsa_db db) +{ +const u8 *addr = mdb->addr; +u16 vid = mdb->vid; +u8 port_mask =0 ; +u32 val; +int ret;
drivers/net/dsa/mediatek/mt7530-lib.c line 555
Quoted 10 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +10
-0+ +mutex_lock (priv->reg_mutex); + +mt7530_lib_fdb_write (priv, vid,0 , addr,0 ,STATIC_EMP ); +if (!mt7530_lib_fdb_cmd (priv,MT7530_FDB_READ , +ATC_MAT_MACTAB ,NULL )) { +regmap_field_read (priv->fields[MT7530_ATRD_PORT_MAP ], + &val); + port_mask = val; + }
[Severity: Medium]
Can val be used uninitialized here? regmap_field_read() reads into its own temporary and does not assign *val when regmap_read() fails.
Before this patch, regmap_read() passed the caller's pointer straight down to mt7530_regmap_read() in mt7530-mdio.c, which does:
/* Callers do not check for errors, keep the value deterministic */
*val = 0;With the field API that zeroing only reaches the temporary inside regmap_field_read(). On an MDIO read failure, an indeterminate port_mask would then be written back into the ARL entry.
The same pattern appears in mt7530_lib_port_mdb_del() with MT7530_ATRD_PORT_MAP. It also appears in mt7530_hw_vlan_del(), which branches on an uninitialized val after reading MT7530_VAWD_VLAN_VALID.
[ ... ]
Quoted 3 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +3
-0+static void mt7530_hw_vlan_add (struct mt7530_lib_priv *priv, +struct mt7530_hw_vlan_entry *entry) +{
[ ... ]
Quoted 7 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +7
-0+regmap_field_write (priv->fields[MT7530_VAWD_IVL_MAC ],1 ); +regmap_field_write (priv->fields[MT7530_VAWD_VTAG_EN ],1 ); +regmap_field_write (priv->fields[MT7530_VAWD_PORT_MEM ], + new_members); +regmap_field_write (priv->fields[MT7530_VAWD_FID ], +FID_BRIDGED ); +regmap_field_write (priv->fields[MT7530_VAWD_VLAN_VALID ],1 );
[ ... ]
drivers/net/dsa/mediatek/mt7530-lib.c line 990
Quoted 7 lines
drivers/net/dsa/mediatek/mt7530-lib.c new file +7
-0+if (new_members) { +regmap_field_write (priv->fields[MT7530_VAWD_IVL_MAC ],1 ); +regmap_field_write (priv->fields[MT7530_VAWD_VTAG_EN ],1 ); +regmap_field_write (priv->fields[MT7530_VAWD_PORT_MEM ], + new_members); +regmap_field_write (priv->fields[MT7530_VAWD_VLAN_VALID ],1 ); + }else {
[Severity: Medium]
Are these VLAN entries still fully defined? The old mt7530_hw_vlan_add() wrote the whole register:
val = IVL_MAC | VTAG_EN | PORT_MEM(new_members) | FID(FID_BRIDGED) |
VLAN_VALID;
regmap_write(priv->regmap, MT7530_VAWD1, val);That cleared EG_CON (bit 29) and PORT_STAG (bit 31). The field read-modify-writes here keep whatever RD_VID or an earlier access left in VAWD1.
mt7530_hw_vlan_update() ignores the result of:
mt7530_vlan_cmd(priv, MT7530_VTCR_RD_VID, vid);
If that command fails, VAWD1 can still hold the VID 0 entry staged by mt7530_lib_setup_vlan0() with EG_CON set. Could the new VLAN then be written with EG_CON=1, overriding the per-VLAN ETAG?
In mt7530_hw_vlan_del() with members remaining, the old code wrote VAWD1 without FID, which reset it to 0 (FID_STANDALONE). The new code keeps FID_BRIDGED. Does that change which FID_PST STP state applies to the VLAN after a member is removed?
Even if the new behaviour is preferable, it seems to differ from "No behaviour change is expected".
[ ... ]
Quoted 9 lines
drivers/net/dsa/mediatek/mt7530.c +1
-0@@ -24,10 +24,163 @@#include <net/pkt_cls.h> #include "mt7530.h" +#include "mt7530-lib.h"
[ ... ]
drivers/net/dsa/mediatek/mt7530.c line 182
Quoted 9 lines
drivers/net/dsa/mediatek/mt7530.c +9
-0+static const struct mt7530_reg_field mt7530_fields[] = { + {MT7530_MIRROR_EN ,REG_FIELD (MT753X_MFC ,3 ,3 ) }, + {MT7530_MIRROR_PORT ,REG_FIELD (MT753X_MFC ,0 ,2 ) }, +}; + +static const struct mt7530_reg_field mt7531_fields[] = { + {MT7530_MIRROR_EN ,REG_FIELD (MT7531_CFC ,19 ,19 ) }, + {MT7530_MIRROR_PORT ,REG_FIELD (MT7531_CFC ,16 ,18 ) }, +};
[Severity: High]
Does MT7530_MIRROR_EN expand to the new enum value in these tables? mt7530.h includes mt7530-lib.h but still keeps the old register macro:
#define MT7530_MIRROR_EN BIT(3)
In enum mt7530_regmap_field, MT7530_MIRROR_EN is 0 and MT7530_CCR_TX_OCT_CNT_GOOD is 8. By the time these tables are compiled in mt7530.c the macro is defined, so their id becomes BIT(3), which is 8.
mt7530_setup_lib_priv() then does:
lib_priv->fields[reg_field->id] = field;
That overwrites fields[MT7530_CCR_TX_OCT_CNT_GOOD] with the mirror enable field and leaves fields[0] NULL. mt7530-lib.c does not include mt7530.h, so MT7530_MIRROR_EN is 0 there.
Wouldn't this oops when a matchall mirror is offloaded?
mt753x_port_mirror_add()
mt7530_lib_port_mirror_add()
regmap_field_read(priv->fields[MT7530_MIRROR_EN], &val)
field->regmap on a NULL fieldmt7530_lib_port_mirror_del() would hit the same NULL in regmap_field_write().
Also, on every setup:
mt7530_setup() / mt7531_setup_common()
mt7530_lib_mib_reset()
regmap_field_write(priv->fields[MT7530_CCR_TX_OCT_CNT_GOOD], 1)This now sets MFC bit 3 (or CFC bit 19), enabling the mirror engine at boot, and MIB_CCR bit 5 is never set.
Would dropping or renaming the old MT7530_MIRROR_EN macro in mt7530.h avoid this? The collision appears to still be present at the end of the series.
[ ... ]
Quoted 4 lines
drivers/net/dsa/mediatek/mt7530.c +0
-0@@ -35,15 +188,15 @@ static struct mt753x_pcs *pcs_to_mt753x_pcs(struct phylink_pcs *pcs)/* String, offset, and register size in bytes if different from 4 bytes */ static const struct mt7530_mib_desc mt7530_mib[] = {
[ ... ]
drivers/net/dsa/mediatek/mt7530.c static struct mt753x_pcs *pcs_to_mt753x_pcs(struct phylink_pcs *pcs) · line 191
Quoted 1 line
drivers/net/dsa/mediatek/mt7530.c +1
-0+ MIB_DESC(MT7530_MIB_TX_DROP, -1, "TxDrop"),
[Severity: Low]
This isn't a bug, but the comment above mt7530_mib[] still describes offset and size. struct mt7530_mib_desc now holds field_low and field_high regmap field indices.
In mt7530.h, "Each define is an offset of MT7530_PORT_MIB_COUNTER" no longer holds either. The MT7530_PORT_MIB_* macros are now absolute port 0 addresses (MT7530_MIB_COUNTER + off), and the "64 bytes" notes now sit on the *_BYTES_LOW halves.
Both comments are still present at the end of the series.
[ ... ]
Quoted 18 lines
drivers/net/dsa/mediatek/mt7530.c +3
-2@@ -1769,13 +1233,14 @@ mt7530_port_fdb_dump(struct dsa_switch *ds, int port,mutex_lock (&priv->reg_mutex); - ret =mt7530_fdb_cmd (priv,MT7530_FDB_START , &rsp); + ret =mt7530_lib_fdb_cmd (&priv->lib_priv,MT7530_FDB_START , +ATC_MAT_MACTAB , &rsp);if (ret <0 ) goto err; do { if (rsp & ATC_SRCH_HIT) { - mt7530_fdb_read(priv, &_fdb); + mt7530_lib_fdb_read(&priv->lib_priv, &_fdb); if (_fdb.port_mask & BIT(port)) { ret = cb(_fdb.mac, _fdb.vid, _fdb.noarp, data);
drivers/net/dsa/mediatek/mt7530.c mt7530_port_fdb_dump(struct dsa_switch *ds, int port, · line 1257
Quoted 9 lines
drivers/net/dsa/mediatek/mt7530.c +2
-1@@ -1785,7 +1250,8 @@ mt7530_port_fdb_dump(struct dsa_switch *ds, int port, } }while (--cnt && !(rsp &ATC_SRCH_END ) && - !mt7530_fdb_cmd (priv,MT7530_FDB_NEXT , &rsp)); + !mt7530_lib_fdb_cmd (&priv->lib_priv,MT7530_FDB_NEXT , +ATC_MAT_MACTAB , &rsp)); err:mutex_unlock (&priv->reg_mutex);
[Severity: Medium]
This is a pre-existing issue and was not introduced by this patch. The function saves ret from cb() and breaks out of the loop, but always ends with:
err:
mutex_unlock(&priv->reg_mutex); return 0;
dsa_user_port_fdb_do_dump() returns -EMSGSIZE once the netlink skb is full, and rtnl_fdb_dump() only keeps its continuation position for -EMSGSIZE. Could the remaining FDB entries be silently dropped from a multi-part bridge fdb show?
[ ... ]
drivers/net/dsa/mediatek/mt7530.c const struct mt753x_info mt753x_table[] = { · line 2751
Quoted 9 lines
drivers/net/dsa/mediatek/mt7530.c +2
-0@@ -3513,6 +2744,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, .sw_setup = mt7988_setup, .phy_read_c22 = mt7531_ind_c22_phy_read,
[Severity: Medium]
Should EN7528 use mt7530_fields here? The old MT753X_MIRROR_REG(), MT753X_MIRROR_EN() and related macros in mt7530.h only selected MT7531_CFC for ID_MT7531, ID_MT7988, ID_EN7581 and ID_AN7583. EN7528 therefore used MT753X_MFC, with enable at bit 3 and the monitor port in bits 2:0.
With mt7531_fields, mt7530_lib_port_mirror_add() and mt7530_lib_port_mirror_del() on EN7528 now read-modify-write MT7531_CFC bit 19 and bits 18:16 instead.
The rest of the driver treats EN7528 as having the MT7530-style MFC layout:
if (priv->id != ID_MT7530 && priv->id != ID_MT7621 &&
priv->id != ID_EN7528)
return;That is from mt753x_conduit_state_change(). mt753x_cpu_port_enable() also skips the MT7531_CFC CPU_PMAP setup for EN7528.
Does mirroring then silently stop working on EN7528, while bits get written in a register this chip otherwise doesn't program? The MT7530_MIRROR_EN collision above currently crashes earlier in this path, but this mapping would remain once that is fixed. It is unchanged at the end of the series.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261009161102.38961-1-ansuelsmth%40gmail.com
PATCH v25 10/10 net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver
In reply to Christian MarangiAdd Airoha AN8855 5-Port Gigabit DSA switch. Switch can support 10M, 100M, 1Gb, 2.5G and 5G Ethernet Speed but 5G is currently error out as it's not currently supported as requires additional configuration for the PCS.
--- drivers/net/dsa/mediatek/Kconfig | 10 + drivers/net/dsa/mediatek/Makefile | 1 + drivers/net/dsa/mediatek/an8855.c | 1765 +++++++++++++++++++++++++ drivers/net/dsa/mediatek/an8855.h | 755 +++++++++++ drivers/net/dsa/mediatek/mt7530-lib.c | 68 +- drivers/net/dsa/mediatek/mt7530-lib.h | 22 + 6 files changed, 2601 insertions(+), 20 deletions(-) create mode 100644 drivers/net/dsa/mediatek/an8855.c create mode 100644 drivers/net/dsa/mediatek/an8855.h
drivers/net/dsa/mediatek/Kconfig +10 -0
@@ -1,4 +1,14 @@ # SPDX-License-Identifier: GPL-2.0-only +config NET_DSA_AN8855 + tristate "Airoha AN8855 Ethernet switch support" + depends on MFD_AIROHA_AN8855 || COMPILE_TEST + depends on NET_DSA + select NET_DSA_MT7530_LIB + select NET_DSA_TAG_AIROHA + help + This enables support for the Ethernet switch inside the + Airoha AN8855 chip. + config NET_DSA_MT7530_LIB tristate
drivers/net/dsa/mediatek/Makefile +1 -0
@@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_NET_DSA_AN8855) += an8855.o obj-$(CONFIG_NET_DSA_MT7530) += mt7530.o obj-$(CONFIG_NET_DSA_MT7530_LIB) += mt7530-lib.o obj-$(CONFIG_NET_DSA_MT7530_MDIO) += mt7530-mdio.o
drivers/net/dsa/mediatek/an8855.c new file +1765 -0
1,765 lines not on this page · raw message
drivers/net/dsa/mediatek/an8855.h new file +755 -0
755 lines not on this page · raw message
drivers/net/dsa/mediatek/mt7530-lib.c +48 -20
134 lines not on this page · raw message
drivers/net/dsa/mediatek/mt7530-lib.h +22 -0
@@ -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
[email protected]
AI reviewRe: [PATCH net-next v25 10/10] net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider: - [High] net: dsa: an8855: Port matrix is unconditionally zeroed out during port_enable - [Medium] net…
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:
- [High] net: dsa: an8855: Port matrix is unconditionally zeroed out during port_enable
- [Medium] net: dsa: an8855: Unchecked regmap_read in an8855_phylink_mac_link_up causes silent register corruption
- [Medium] net: dsa: an8855: Uninitialized stack variable read in an8855_port_fdb_dump()
- [Medium] net: dsa: an8855: an8855_phylink_mac_enable_tx_lpi() leaves stale timer values on immediate LPI
- [Medium] net: dsa: an8855: missing mtu_enforcement_ingress flag allows MTU violation
- [Low] net: dsa: an8855: Driver duplicates standard UAPI statistics as private ethtool strings
- [Low] net: dsa: an8855: an8855_port_enable() leaves priv->ports[port].enable true on error
--
commit d3cae945049e5b42ed716ab1ac6797e64ffa036c
Author: Christian Marangi <[email protected]>
net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver
This patch adds support for the Airoha AN8855 5-Port Gigabit DSA switch, including phylink MAC operations and standard switch functions. It supports multiple port speeds, though 5G speed is currently disabled pending PCS configuration support.
Quoted 4 lines
drivers/net/dsa/mediatek/an8855.c new file +0
-0@@ -0,0 +1,1765 @@
[ ... ]
drivers/net/dsa/mediatek/an8855.c line 187
Quoted 5 lines
drivers/net/dsa/mediatek/an8855.c new file +5
-0+static const struct mt7530_mib_desc an8855_mib[] = { +MIB_DESC (MT7530_MIB_TX_DROP ,-1 ,"TxDrop" ), +MIB_DESC (MT7530_MIB_TX_CRC_ERR ,-1 ,"TxCrcErr" ), +MIB_DESC (MT7530_MIB_TX_COLLISION ,-1 ,"TxCollision" ), +MIB_DESC (AN8855_MIB_TX_OVERSIZE_DROP ,-1 ,"TxOversizeDrop" ),
[Severity: Low]
Is it necessary to expose these standard hardware counters through driver-private ethtool strings? The driver already implements the standard .get_eth_mac_stats interface. Exposing values like TxDrop and TxCrcErr via ethtool -S duplicates standard UAPI statistics, which goes against the Networking Drivers guidelines for standard statistics.
[ ... ]
Quoted 14 lines
drivers/net/dsa/mediatek/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/mediatek/an8855.c line 366
Quoted 10 lines
drivers/net/dsa/mediatek/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: Medium]
Could this read an uninitialized stack value? If mt7530_lib_fdb_cmd() succeeds but the final regmap_field_read(..., rsp) inside it fails, the function returns 0 without populating rsp. This would leave rsp uninitialized here, leading to unpredictable loop behavior when parsing FDB entries.
[ ... ]
drivers/net/dsa/mediatek/an8855.c line 926
Quoted 13 lines
drivers/net/dsa/mediatek/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), ®);
[Severity: Medium]
What happens if this regmap_read() fails? The return value is not checked, so reg would remain 0. The function then sets specific bits (speed, duplex, TX_EN, RX_EN) and writes it back, which could silently overwrite and corrupt other configuration bits (like MAC mode or backoff settings) that were configured in an8855_phylink_mac_config().
[ ... ]
Quoted 11 lines
drivers/net/dsa/mediatek/an8855.c new file +11
-0+static int an8855_port_enable (struct dsa_switch *ds,int port, +struct phy_device *phy) +{ +struct dsa_port *dp =dsa_to_port (ds, port); +struct an8855_priv *priv = ds->priv; +int ret; + +mutex_lock (&priv->reg_mutex); + +/* Allow the user port gets connected to the cpu port and also +* restore the port matrix if the port is the member of a certain
drivers/net/dsa/mediatek/an8855.c line 609
Quoted 10 lines
drivers/net/dsa/mediatek/an8855.c new file +10
-0+* bridge. +*/ +if (dsa_port_is_user (dp)) { +struct dsa_port *cpu_dp = dp->cpu_dp; + + priv->ports[port].pm |=BIT (cpu_dp->index); + } + priv->ports[port].enable = true; + ret =regmap_fields_write (priv->lib_priv.fields[MT7530_PCR_MATRIX ], + port,0 );
[Severity: High]
Should this be passing priv->ports[port].pm instead of 0? Writing the literal 0 disables the port's forwarding matrix in hardware, effectively isolating the port and dropping all forwarded traffic, rather than applying the port matrix computed just above.
[Severity: Low]
Also, if this regmap_fields_write() fails, the function jumps to the exit label and returns an error without reverting priv->ports[port].enable back to false. Can this desynchronize the software state from the hardware state and cause issues in loops that check priv->ports[i].enable (such as the LPI timer calculation)?
Quoted 11 lines
drivers/net/dsa/mediatek/an8855.c new file +11
-0+if (ret) + goto exit; + + ret =regmap_set_bits (priv->regmap,AN8855_PMCR_P (port), +AN8855_PMCR_TX_EN |AN8855_PMCR_RX_EN ); + +exit: +mutex_unlock (&priv->reg_mutex); + +return ret; +}
[ ... ]
Quoted 2 lines
drivers/net/dsa/mediatek/an8855.c new file +2
-0+static int an8855_setup (struct dsa_switch *ds) +{
[ ... ]
Quoted 4 lines
drivers/net/dsa/mediatek/an8855.c new file +4
-0+/* Set min a max ageing value supported */ + ds->ageing_time_min =AN8855_L2_AGING_MS_CONSTANT ; + ds->ageing_time_max =FIELD_MAX (AN8855_AGE_CNT ) * + FIELD_MAX(AN8855_AGE_UNIT) *
drivers/net/dsa/mediatek/an8855.c line 805
Quoted 10 lines
drivers/net/dsa/mediatek/an8855.c new file +10
-0+AN8855_L2_AGING_MS_CONSTANT ; + +/* User reported problem with WiFi roaming and +* ethernet port. Enabling assisted learning fix +* the issue. +*/ + ds->assisted_learning_on_cpu_port = true; + +return 0 ; +}
[Severity: Medium]
Does this switch require the mtu_enforcement_ingress flag to be set here? Because mt7530_lib_port_change_mtu() configures the MTU limit globally based on the CPU port's requested MTU, user ports configured with smaller MTUs might accept oversized frames. Setting ds->mtu_enforcement_ingress = true would let the DSA core normalize bridged port MTUs.
[ ... ]
Quoted 3 lines
drivers/net/dsa/mediatek/an8855.c new file +3
-0+static int an8855_phylink_mac_enable_tx_lpi (struct phylink_config *config, +u32 timer,bool tx_clock_stop) +{
[ ... ]
drivers/net/dsa/mediatek/an8855.c line 1048
Quoted 10 lines
drivers/net/dsa/mediatek/an8855.c new file +10
-0+ ret =regmap_update_bits (priv->regmap,AN8855_CKGCR , +AN8855_LPI_TXIDLE_THD_MASK , val); +mutex_unlock (&priv->reg_mutex); +if (ret) { +dev_err (dp->ds->dev,"failed to set global LPI timer\n" ); +return ret; + } + }else { + ret =regmap_set_bits (priv->regmap,AN8855_PMEEECR_P (port), +AN8855_LPI_MODE_EN );
[Severity: Medium]
If timer == 0 is requested to enter LPI immediately, the software array priv->tx_lpi_timer_ports[port] is not updated to 0. If the port previously had a non-zero timer, won't this leave a stale value in the array? Because the global LPI timer is derived from the maximum of all enabled ports, a stale non-zero value here could artificially inflate the global threshold.
Quoted 6 lines
drivers/net/dsa/mediatek/an8855.c new file +6
-0+if (ret) { +dev_err (dp->ds->dev,"failed to enable LPI for port %d\n" , + port); +return ret; + } + }
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
Re: [PATCH net-next v25 10/10] net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver
Quoted 25 lines · On Sat, Oct 10, 2026 at 04:11:42PM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:
- [High] net: dsa: an8855: Port matrix is unconditionally zeroed out duringport_enable
- [Medium] net: dsa: an8855: Uncheckedregmap_readinan8855_phylink_mac_link_upcauses silent register corruption
- [Medium] net: dsa: an8855: Uninitialized stack variable read inan8855_port_fdb_dump()
- [Medium] net: dsa: an8855:an8855_phylink_mac_enable_tx_lpi()leaves stale timer values on immediate LPI
- [Medium] net: dsa: an8855: missingmtu_enforcement_ingressflag allows MTU violation
- [Low] net: dsa: an8855: Driver duplicates standard UAPI statistics as private ethtool strings
- [Low] net: dsa: an8855:an8855_port_enable()leaves priv->ports[port].enable true on error
--commit
d3cae945049e5b42ed716ab1ac6797e64ffa036c
Author: Christian Marangi <[email protected]>net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver
This patch adds support for the Airoha AN8855 5-Port Gigabit DSA switch, including phylink MAC operations and standard switch functions. It supports multiple port speeds, though 5G speed is currently disabled pending PCS configuration support.
Quoted 4 lines
drivers/net/dsa/mediatek/an8855.c new file +0
-0@@ -0,0 +1,1765 @@[ ... ]
Quoted 13 lines
drivers/net/dsa/mediatek/an8855.c line 187
Quoted 5 lines
drivers/net/dsa/mediatek/an8855.c new file +5
-0+static const struct mt7530_mib_desc an8855_mib[] = { +MIB_DESC (MT7530_MIB_TX_DROP ,-1 ,"TxDrop" ), +MIB_DESC (MT7530_MIB_TX_CRC_ERR ,-1 ,"TxCrcErr" ), +MIB_DESC (MT7530_MIB_TX_COLLISION ,-1 ,"TxCollision" ), +MIB_DESC (AN8855_MIB_TX_OVERSIZE_DROP ,-1 ,"TxOversizeDrop" ),[Severity: Low]
Is it necessary to expose these standard hardware counters through driver-private ethtool strings? The driver already implements the standard .get_eth_mac_stats interface. Exposing values like TxDrop and TxCrcErr via ethtool -S duplicates standard UAPI statistics, which goes against the Networking Drivers guidelines for standard statistics.
Same tretement of MT7530, these MIB doesn't reflect the standard linux values.
Quoted 24 lines
[ ... ]
Quoted 23 lines
drivers/net/dsa/mediatek/an8855.c new file +23
-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))); +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 */
Quoted 9 lines
drivers/net/dsa/mediatek/an8855.c line 366
Quoted 1 line
drivers/net/dsa/mediatek/an8855.c new file +1
-0+ banks =FIELD_GET (AN8855_ATC_HIT , rsp);[Severity: Medium]
Could this read an uninitialized stack value? Ifmt7530_lib_fdb_cmd()succeeds but the finalregmap_field_read(..., rsp)inside it fails, the function returns 0 without populating rsp. This would leave rsp uninitialized here, leading to unpredictable loop behavior when parsing FDB entries.
This is an almost impossible scenario. If ok I can address this with a followup.
Quoted 13 lines
[ ... ]
Quoted 12 lines
drivers/net/dsa/mediatek/an8855.c new file +12
-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); +
Quoted 9 lines
drivers/net/dsa/mediatek/an8855.c line 926
Quoted 1 line
drivers/net/dsa/mediatek/an8855.c new file +1
-0+regmap_read (priv->regmap,AN8855_PMCR_P (port), ®);[Severity: Medium]
What happens if thisregmap_read()fails? The return value is not checked, so reg would remain 0. The function then sets specific bits (speed, duplex,TX_EN,RX_EN) and writes it back, which could silently overwrite and corrupt other configuration bits (like MAC mode or backoff settings) that were configured inan8855_phylink_mac_config().
Similar to above, very unlikely scenario.
Quoted 20 lines
[ ... ]
Quoted 19 lines
drivers/net/dsa/mediatek/an8855.c new file +19
-0+static int an8855_port_enable (struct dsa_switch *ds,int port, +struct phy_device *phy) +{ +struct dsa_port *dp =dsa_to_port (ds, port); +struct an8855_priv *priv = ds->priv; +int ret; + +mutex_lock (&priv->reg_mutex); + +/* Allow the user port gets connected to the cpu port and also +* restore the port matrix if the port is the member of a certain +* bridge. +*/ +if (dsa_port_is_user (dp)) { +struct dsa_port *cpu_dp = dp->cpu_dp; + + priv->ports[port].pm |=BIT (cpu_dp->index); + } + priv->ports[port].enable = true;
Quoted 9 lines
drivers/net/dsa/mediatek/an8855.c
Quoted 2 lines
drivers/net/dsa/mediatek/an8855.c new file +2
-0+ ret =regmap_fields_write (priv->lib_priv.fields[MT7530_PCR_MATRIX ], + port,0 );[Severity: High]
Should this be passing priv->ports[port].pm instead of 0? Writing the literal 0 disables the port's forwarding matrix in hardware, effectively isolating the port and dropping all forwarded traffic, rather than applying the port matrix computed just above.
I can address this in follow-up patch if possible.
Quoted 38 lines
[Severity: Low]
Also, if thisregmap_fields_write()fails, the function jumps to the exit label and returns an error without reverting priv->ports[port].enable back to false. Can this desynchronize the software state from the hardware state and cause issues in loops that check priv->ports[i].enable (such as the LPI timer calculation)?Quoted 11 lines
drivers/net/dsa/mediatek/an8855.c new file +11
-0+if (ret) + goto exit; + + ret =regmap_set_bits (priv->regmap,AN8855_PMCR_P (port), +AN8855_PMCR_TX_EN |AN8855_PMCR_RX_EN ); + +exit: +mutex_unlock (&priv->reg_mutex); + +return ret; +}[ ... ]
Quoted 2 lines
drivers/net/dsa/mediatek/an8855.c new file +2
-0+static int an8855_setup (struct dsa_switch *ds) +{[ ... ]
Quoted 13 lines
drivers/net/dsa/mediatek/an8855.c new file +13
-0+/* Set min a max ageing value supported */ + ds->ageing_time_min =AN8855_L2_AGING_MS_CONSTANT ; + ds->ageing_time_max =FIELD_MAX (AN8855_AGE_CNT ) * +FIELD_MAX (AN8855_AGE_UNIT ) * +AN8855_L2_AGING_MS_CONSTANT ; + +/* User reported problem with WiFi roaming and +* ethernet port. Enabling assisted learning fix +* the issue. +*/ + ds->assisted_learning_on_cpu_port = true; + +return 0 ;
Quoted 9 lines
Quoted 1 line
+}
[Severity: Medium]
Does this switch require themtu_enforcement_ingressflag to be set here? Becausemt7530_lib_port_change_mtu()configures the MTU limit globally based on the CPU port's requested MTU, user ports configured with smaller MTUs might accept oversized frames. Settingds->mtu_enforcement_ingress= true would let the DSA core normalize bridged port MTUs.
I will double check this.
Quoted 14 lines
[ ... ]
Quoted 3 lines
drivers/net/dsa/mediatek/an8855.c new file +3
-0+static int an8855_phylink_mac_enable_tx_lpi (struct phylink_config *config, +u32 timer,bool tx_clock_stop) +{[ ... ]
Quoted 9 lines
drivers/net/dsa/mediatek/an8855.c new file +9
-0+ ret =regmap_update_bits (priv->regmap,AN8855_CKGCR , +AN8855_LPI_TXIDLE_THD_MASK , val); +mutex_unlock (&priv->reg_mutex); +if (ret) { +dev_err (dp->ds->dev,"failed to set global LPI timer\n" ); +return ret; + } + }else { + ret = regmap_set_bits(priv->regmap, AN8855_PMEEECR_P(port),
Quoted 9 lines
drivers/net/dsa/mediatek/an8855.c
Quoted 1 line
drivers/net/dsa/mediatek/an8855.c new file +1
-0+ AN8855_LPI_MODE_EN);[Severity: Medium]
If timer == 0 is requested to enter LPI immediately, the software array priv->tx_lpi_timer_ports[port] is not updated to 0. If the port previously had a non-zero timer, won't this leave a stale value in the array? Because the global LPI timer is derived from the maximum of all enabled ports, a stale non-zero value here could artificially inflate the global threshold.
I can address in follow-up patch.
Quoted 10 lines
Quoted 6 lines
drivers/net/dsa/mediatek/an8855.c new file +6
-0+if (ret) { +dev_err (dp->ds->dev,"failed to enable LPI for port %d\n" , + port); +return ret; + } + }[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
Signature · 1 line
Ansuel
[email protected]
AI reviewRe: [PATCH net-next v25 10/10] net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver
In reply to Christian MarangiThank 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: 2 · Medium: 9 · Low: 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] an8855_port_enable() writes 0 to the port matrix instead of the value it just computed.
- [High] On AN8855 the shared VLAN code reads table entries back from the write-data register.
- [Medium] The patch makes the MT7530_ATC_INVALID check in mt7530_lib_fdb_cmd() optional and gives AN8855 no replacement.
- [Medium] an8855_port_change_mtu() calls mt7530_lib_port_change_mtu() directly.
- [Medium] an8855_set_mac_eee() rejects tx_lpi_timer > 0xFFF, a limit copied from MT7530's 12-bit LPI_THRESH field.
- [Medium] The SGMII 'PCS Init' block in an8855_pcs_config() is dead code.
- [Medium] an8855_port_fdb_dump() calls usleep_range(1000, 1500) for every valid bank entry while it walks up to AN8855_NUM_FDB_RECORDS…
- [Medium] In an8855_pcs_config(), the 'PLL - SDM' step applies AN8855_RG_DA_QP_PLL_SDM_HREN_INTF to AN8855_PLL_CTRL_2, but the header…
- [Medium] For SGMII without in-band negotiation, an8855_pcs_config() always forces the PCS to 1000 Mb/s (AN8855_RG_LINK_MODE_P0_SPEED_1000…
- [Medium] The new driver adds ethtool -S strings for counters that already have standard uAPIs.
- [Medium] net: dsa: an8855: missing mtu_enforcement_ingress flag allows MTU violation
- [Low] NET_DSA_AN8855 is declared with depends on MFD_AIROHA_AN8855 || COMPILE_TEST and does not select REGMAP.
- [Low] The last RMON histogram bucket in an8855_rmon_ranges is { 1519, AN8855_MAX_MTU }.
- [Low] an8855_phylink_mac_link_up() initialises u32 reg = 0, ignores the return value of `regmap_read(priv->regmap, AN8855_PMCR_P(port),…
- [Low] an8855_port_fdb_dump() declares u32 rsp; without initialising it and passes &rsp to mt7530_lib_fdb_cmd().
--
net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver
This adds a DSA driver for the Airoha AN8855 5-port gigabit switch. It is built on the shared mt7530-lib helpers and has an SGMII/2500BASE-X PCS for the CPU port. mt7530-lib gains optional AN8855-specific regmap fields, and its ATC/VTCR invalid checks become optional.
drivers/net/dsa/mediatek/Kconfig line 7
Quoted 12 lines
drivers/net/dsa/mediatek/Kconfig +6
-0@@ -1,4 +1,14 @@ # SPDX-License-Identifier: GPL-2.0-only +config NET_DSA_AN8855 + tristate "Airoha AN8855 Ethernet switch support" + depends on MFD_AIROHA_AN8855 || COMPILE_TEST + depends on NET_DSA + select NET_DSA_MT7530_LIB + select NET_DSA_TAG_AIROHA
[Severity: Low]
Can REGMAP end up disabled with COMPILE_TEST=y and MFD_AIROHA_AN8855=n? NET_DSA_MT7530_LIB is a bare tristate, and REGMAP normally comes in because MFD_AIROHA_AN8855 selects it.
struct reg_field, REG_FIELD() and devm_regmap_field_alloc() are declared only under CONFIG_REGMAP in include/linux/regmap.h, with no stubs. In that configuration an8855.c and mt7530-lib.c would fail to build.
Should this also select REGMAP?
Quoted 6 lines
drivers/net/dsa/mediatek/an8855.c new file +0
-0@@ -0,0 +1,1765 @@
[ ... ]
drivers/net/dsa/mediatek/an8855.c line 60
Quoted 9 lines
drivers/net/dsa/mediatek/an8855.c new file +9
-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) },
[Severity: High]
After a VTCR read command, the shared VLAN code reads the entry back through these fields:
- mt7530_hw_vlan_update() reads MT7530_VAWD_PORT_MEM for old_members.
- mt7530_hw_vlan_del() checks MT7530_VAWD_VLAN_VALID.
- mt7530_hw_vlan_add() does a read-modify-write of MT7530_VAWD_ETAG.
All of these map to AN8855_VAWD0, which is the write-data register. an8855.h also defines a read-data register that nothing maps:
/* Same register field of VAWD0 */
#define AN8855_VARD0 0x10200618
If MT7530_VTCR_RD_VID returns its result in VARD0, does the VLAN code read back whatever was last written to VAWD0 instead?
For example, mt7530_lib_setup_vlan0() leaves PORT_MEM = MT7530_ALL_MEMBERS in VAWD0. A following bridge vlan add for another VID could then start from all members. Could deletes also take the invalid-entry path, or clear the wrong members?
drivers/net/dsa/mediatek/an8855.c line 192
Quoted 10 lines
drivers/net/dsa/mediatek/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]
Several of these ethtool -S strings duplicate counters that already have standard interfaces:
- "RxCrcErr" is FrameCheckSequenceErrors in ethtool_eth_mac_stats and rx_crc_errors in rtnl_link_stats64.
- "TxCollision" is collisions.
- "RxDrop" and "TxDrop" are rx_dropped and tx_dropped.
an8855_switch_ops also has no .get_stats64. mt7530.c fills rtnl_link_stats64 from the same field IDs in mt7530_get_stats64(). In addition, mt7530_lib_get_eth_mac_stats() does not fill FrameCheckSequenceErrors.
Could these be reported through the standard interfaces rather than as driver-private strings?
[ ... ]
Quoted 14 lines
drivers/net/dsa/mediatek/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/mediatek/an8855.c line 366
Quoted 10 lines
drivers/net/dsa/mediatek/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, and mt7530_lib_fdb_cmd() ignores the return value of the response read:
if (rsp) regmap_field_read(priv->fields[__MT7530_ATC], rsp); return 0;
On a read error regmap_field_read() returns without writing *val. If that read fails after a successful BUSY poll, does this FIELD_GET() work on an indeterminate value?
Quoted 11 lines
drivers/net/dsa/mediatek/an8855.c new file +11
-0+if (!banks) +break ; + +/* Each banks have 4 entry */ +for (i =0 ; i <4 ; i++) { +struct mt7530_fdb _fdb = { }; + + count++; + +/* Check if bank is present */ +if (!(banks &BIT (i)))
drivers/net/dsa/mediatek/an8855.c line 387
Quoted 10 lines
drivers/net/dsa/mediatek/an8855.c new file +10
-0+continue ; + +/* Select bank entry index */ + ret =regmap_write (priv->regmap,AN8855_ATRDS , +FIELD_PREP (AN8855_ATRD_SEL , i)); +if (ret) +break ; +/* wait 1ms for the bank entry to be filled */ +usleep_range (1000 ,1500 ); +mt7530_lib_fdb_read (&priv->lib_priv, &_fdb);
[Severity: Medium]
This sleeps once per valid entry while walking up to AN8855_NUM_FDB_RECORDS (2048) slots. Each MT7530_FDB_NEXT can also poll ATC_BUSY for up to 20ms.
All of this runs under priv->reg_mutex and rtnl_lock, because the PF_BRIDGE RTM_GETNEIGH dumpit (rtnl_fdb_dump) is not registered as unlocked.
The dump needs no CAP_NET_ADMIN, and learning on bridged ports can fill the table. Could one unprivileged bridge fdb show hold rtnl for seconds? The walk also restarts from the beginning on every netlink continuation, so the delay would repeat each time.
Is the per-entry 1ms sleep needed? The MT7530 dump does not have one.
[ ... ]
drivers/net/dsa/mediatek/an8855.c line 462
Quoted 7 lines
drivers/net/dsa/mediatek/an8855.c new file +7
-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); +}
[Severity: Medium]
For jumbo frames, mt7530_lib_port_change_mtu() writes a linear KiB count:
regmap_field_write(priv->fields[MT7530_GMACCR_MAX_RX_JUMBO], DIV_ROUND_UP(length, 1024));
The AN8855_MAX_RX_JUMBO_* defines in an8855.h describe a non-linear
encoding: 0x0-0x2 = 2K, 0x3-0x9 = 3K-9K, 0xa = 12K, 0xb = 15K, 0xc = 16K. AN8855_MAX_MTU allows frame lengths up to 15360.
With that encoding, frame lengths of 9217-12288 bytes would be written as 0xa-0xc (12K/15K/16K). Lengths of 12289-15360 bytes would be written as 0xd-0xf, which are not defined. Is that intended? None of the AN8855_MAX_RX_JUMBO_* macros seem to be used.
[ ... ]
drivers/net/dsa/mediatek/an8855.c line 528
Quoted 10 lines
drivers/net/dsa/mediatek/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]AN8855_MAX_MTU is an L3 MTU: 15360 - ETH_HLEN - ETH_FCS_LEN - MTK_TAG_LEN = 15338. ethtool_rmon_hist_range bounds are frame lengths. Should the upper bound be the maximum frame length (15360) instead?
[ ... ]
Quoted 11 lines
drivers/net/dsa/mediatek/an8855.c new file +11
-0+static int an8855_port_enable (struct dsa_switch *ds,int port, +struct phy_device *phy) +{ +struct dsa_port *dp =dsa_to_port (ds, port); +struct an8855_priv *priv = ds->priv; +int ret; + +mutex_lock (&priv->reg_mutex); + +/* Allow the user port gets connected to the cpu port and also +* restore the port matrix if the port is the member of a certain
drivers/net/dsa/mediatek/an8855.c line 609
Quoted 10 lines
drivers/net/dsa/mediatek/an8855.c new file +10
-0+* bridge. +*/ +if (dsa_port_is_user (dp)) { +struct dsa_port *cpu_dp = dp->cpu_dp; + + priv->ports[port].pm |=BIT (cpu_dp->index); + } + priv->ports[port].enable = true; + ret =regmap_fields_write (priv->lib_priv.fields[MT7530_PCR_MATRIX ], + port,0 );
[Severity: High]
Should this write priv->ports[port].pm instead of 0? The pm value computed just above is never used, so the port matrix is empty once the port is enabled.
an8855_setup() sets AN8855_PORTMATRIX_P(user) to BIT(AN8855_CPU_PORT). dsa_user_open()->dsa_port_enable_rt()->an8855_port_enable() then overwrites it with 0.
Would a standalone user port then be unable to forward to the CPU port until a bridge join or leave calls mt7530_update_port_member()?
The same would happen in two other cases:
- The CPU port's dsa_user_ports() matrix would be cleared when DSA enables the CPU port.
- A port that was bridged before it came up would lose its membership, because mt7530_update_port_member() skips the write for disabled ports.
For comparison, mt7530_port_enable() writesPCR_MATRIX(priv->ports[port].pm) at this point.
[ ... ]
drivers/net/dsa/mediatek/an8855.c line 649
Quoted 8 lines
drivers/net/dsa/mediatek/an8855.c new file +8
-0+static int an8855_set_mac_eee (struct dsa_switch *ds,int port, +struct ethtool_keee *e) +{ +if (e->tx_lpi_timer >0xFFF ) +return -EINVAL ; + +return 0 ; +}
[Severity: Medium]
Should an8855_setup() also set ds->mtu_enforcement_ingress?
mt7530_lib_port_change_mtu() returns early for every port except the CPU port, because GMACCR is a single global RX length limit. It relies on DSA setting the CPU port MTU to the largest user port MTU, and programs that value into the switch.
The per-port MTUs are therefore never enforced in hardware. Take two user ports in the same bridge with different MTUs. The port with the smaller MTU still accepts frames up to the largest configured MTU, so its own setting is silently ignored on ingress.
ds->mtu_enforcement_ingress exists for switches that only have a global MRU. With it set, DSA normalizes the MTU of all bridged ports when one of them changes, so the global limit matches what every bridged port is configured for. The MT7530 setup path sets it for this reason.
This could be set next to assisted_learning_on_cpu_port. Or is there something on AN8855 that enforces the per-port MTU that I am missing?
[Severity: Medium]
The 0xFFF limit matches MT7530's 12-bit LPI threshold. On AN8855 the timer field is AN8855_LPI_TXIDLE_THD_MASK, GENMASK(31, 14), in 2us units, and an8855_phylink_mac_enable_tx_lpi() already clamps the value to it.
an8855_phylink_get_caps() takes lpi_timer_default from CKGCR. Its comment gives the default as 60ms, which is about 60000us.
The resulting call sequence is:
- phylink reports that default through get_eee.
- ethnl_set_eee() keeps it unless the user passes tx-timer.
- dsa_user_set_eee() then calls set_mac_eee() with it.
Would any ethtool --set-eee on a user port, including eee off, fail with -EINVAL unless it also passes tx-timer <= 4095?
[ ... ]
drivers/net/dsa/mediatek/an8855.c line 926
Quoted 13 lines
drivers/net/dsa/mediatek/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), ®);
[Severity: Low]
If this read fails, reg stays 0 and the later regmap_write() rebuilds PMCR from zero. Would that clear MAC_MODE, IFG_XMIT, BACKOFF/BACKPR and the EEE force bits set by mac_config and mac_enable_tx_lpi?
Should the read error be checked before the register is written back?
[ ... ]
Quoted 5 lines
drivers/net/dsa/mediatek/an8855.c new file +5
-0+static int an8855_pcs_config (struct phylink_pcs *pcs,unsigned int neg_mode, +phy_interface_t interface, +const unsigned long *advertising, +bool permit_pause_to_mac) +{
[ ... ]
drivers/net/dsa/mediatek/an8855.c line 1242
Quoted 4 lines
drivers/net/dsa/mediatek/an8855.c new file +4
-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 ));
[Severity: Medium]
Is AN8855_PLL_CTRL_2 the right register here? an8855.h defines this field in AN8855_PLL_CTRL_4:
#define AN8855_PLL_CTRL_4 0x1022e410
#define AN8855_RG_DA_QP_PLL_SDM_HREN_INTF GENMASK(4, 3)
In AN8855_PLL_CTRL_2, bits 4:2 are AN8855_RG_DA_QP_PLL_BPA_INTF, and the earlier "PLL - LPF" step set that field to 0x5. Clearing bits 4:3 here would change BPA to 0x1 and leave the real SDM_HREN field untouched.
[ ... ]
drivers/net/dsa/mediatek/an8855.c line 1470
Quoted 5 lines
drivers/net/dsa/mediatek/an8855.c new file +5
-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 );
[Severity: Medium]
Can this branch ever run? For SGMII, phylink_pcs_neg_mode() returns either PHYLINK_PCS_NEG_INBAND_ENABLED or PHYLINK_PCS_NEG_OUTBAND. INBAND_DISABLED only comes from the Base-X without a PHY case.
For SGMII fixed-link or PHY-managed links, SGMII_MODE and SGMII_AN_EN would then stay at their reset or previous value. The other branches in this function test neg_mode != PHYLINK_PCS_NEG_INBAND_ENABLED and set up forced mode, so the PCS would end up configured inconsistently.
Should this condition also test neg_mode != PHYLINK_PCS_NEG_INBAND_ENABLED?
[ ... ]
drivers/net/dsa/mediatek/an8855.c line 1567
Quoted 7 lines
drivers/net/dsa/mediatek/an8855.c new file +7
-0+/* Force Speed with fixed-link or 2500base-x as doesn't support aneg */ +if (interface ==PHY_INTERFACE_MODE_2500BASEX || + neg_mode !=PHYLINK_PCS_NEG_INBAND_ENABLED ) { +if (interface ==PHY_INTERFACE_MODE_2500BASEX ) + val =AN8855_RG_LINK_MODE_P0_SPEED_2500 ; +else + val =AN8855_RG_LINK_MODE_P0_SPEED_1000 ;
[Severity: Medium]
For SGMII without in-band negotiation, this always forces the PCS to 1000.
an8855_phylink_get_caps() advertises MAC_10 | MAC_100 for port 5, and an8855_phylink_mac_link_up() programs PMCR for 10 or 100. an8855_pcs_ops has no .pcs_link_up to update the forced rate afterwards.
Would a 10/100 out-of-band SGMII link on port 5 run with the MAC and the PCS at different rates?
[ ... ]
Quoted 6 lines
drivers/net/dsa/mediatek/mt7530-lib.c +0
-0@@ -423,9 +423,11 @@ int mt7530_lib_fdb_cmd(struct mt7530_lib_priv *priv, enum mt7530_fdb_cmd cmd,return ret;
drivers/net/dsa/mediatek/mt7530-lib.c int mt7530_lib_fdb_cmd(struct mt7530_lib_priv *priv, enum mt7530_fdb_cmd cmd, · line 430
Quoted 10 lines
drivers/net/dsa/mediatek/mt7530-lib.c +5
-3} -regmap_field_read (priv->fields[MT7530_ATC_INVALID ], &val); -if (cmd ==MT7530_FDB_READ && val) -return -EINVAL ; +if (priv->fields[MT7530_ATC_INVALID ]) { +regmap_field_read (priv->fields[MT7530_ATC_INVALID ], &val); +if (cmd ==MT7530_FDB_READ && val) +return -EINVAL ; + }
[Severity: Medium]
an8855_fields[] has no MT7530_ATC_INVALID entry. On AN8855 an MT7530_FDB_READ therefore returns 0 even when the lookup misses.
mt7530_lib_port_mdb_add() and mt7530_lib_port_mdb_del() treat 0 as "entry exists":
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;
}On a miss, could they merge whatever AN8855_ATRD3 still holds, for example data left by the last an8855_port_fdb_dump()? That could program a new group with ports that never joined it, or make mdb_del write a STATIC_ENT for a group that does not exist.
The READ path also does not select the hit bank through AN8855_ATRDS, as the fdb dump does.
AN8855 reports hits through AN8855_ATC_HIT. Should this check use that on AN8855 instead?
The MT7530_VTCR_INVALID check in mt7530_vlan_cmd() was made optional in the same way.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261009161102.38961-1-ansuelsmth%40gmail.com