net: dsa: Add Airoha AN8855 support
Subsystems (8)
v19 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 v19:
- Rebase on top of net-next
- Rework with shared function from mt7530 driver
- Add dependency for mt7530 lock
- Fix some define typo for AN8855
Changes v18:
- Fix configurting typo
- Init ret in MFD driver
Changes v17:
- Drop nvmem patch (subset merged and present in linux-next)
- Fix wrong Documentation patch for MFD
- Address reviews for MFD driver
- Rework MTK tag to slipt for Airoha name
Changes v16:
- Rebase on top of net-next
- Drop PBUS implementation (Airoha said that it's not OK to use it)
- Convert to simple mdio-regmap and split regmap
- Fix typo for some define (AND8855 -> AN8855)
Changes v15:
- Rebase on top of net-next
- Drop regmap MDIO patch (in favor of PBUS)
- Implement MDIO PBUS and rework MDIO driver/MFD
- Reimplement EEE support
- Add some check for regmap from MFD
- Move to single regmap and add comments with all findings
Changes v14:
- Move MAITAINERS entry to dedicated commit (make it easier for cross subsystem merge)
- Pack variables in trap function
- Add additional patch for reported difference from MTK tag
Changes v13:
- Reimplement tx_lpi OPs
- Rework mdio-regmap to internally encode/decode address
- Fix error in Documentation
- Drop ext-surge property (assume calibration with declared nvmem cell)
- Fix comments from Lee on MFD driver
- Improve print error and drop extra space in DSA driver
Changes v12:
- Update on top of net-next
- Add additional info on conver-letter about slefttests and HW limitation
- Introduce mdio-regmap generalization for multiple address
- Drop dev flags and define PHY calibration in PHY node directly
Changes v11:
- Address reviews from Christophe (spell mistake + dev_err_probe)
- Fix kconfig dependency for MFD driver (depends on MDIO_DEVICE instead of MDIO) (indirectly fix link error for mdio APIs)
- Fix copy-paste error for MFD driver of_table
- Fix compilation error for PHY (move NVMEM to .config)
- Drop unneeded NVMEM node from MDIO example schema (from Andrew)
- Adapt MFD example schema to MDIO reg property restrictions
Changes v10:
- Entire rework to MFD + split to MDIO, EFUSE, SWITCH separate drivers
- Drop EEE OPs (while Russell finish RFC for EEE changes)
- Use new pcs_inpand OPs
- Drop AN restart function and move to pcs_config
- Enable assisted_learning and disable CPU learn (preparation for fdb_isolation)
- Move EFUSE read in Internal PHY driver to .config to handle EPROBE_DEFER (needed now that NVMEM driver is register externally instead of internally to switch node)
Changes v9:
- Error out on using 5G speed as currently not supported
- Add missing MAC_2500FD in phylink mac_capabilities
- Add comment and improve if condition for an8855_phylink_mac_config Changes v8:
- Add port Fast Age support
- Add support for Port Isolation
- Use correct register for Learning Disable
- Add support for Ageing Time OP
- Set default PVID to 0 by default
- Add mdb OPs
- Add port change MTU
- Fix support for Upper VLAN
Changes v7:
- Fix devm_dsa_register_switch wrong export symbol
Changes v6:
- Drop standard MIB and handle with ethtool OPs (as requested by Jakub)
- Cosmetic: use bool instead of 0 or 1
Changes v5:
- Add devm_dsa_register_switch() patch
- Add Reviewed-by tag for DT patch
Changes v4:
- Set regmap readable_table static (mute compilation warning)
- Add support for port_bridge flags (LEARNING, FLOOD)
- Reset fdb struct in fdb_dump
- Drop support_asym_pause in port_enable
- Add define for get_phy_flags
- Fix bug for port not inititially part of a bridge
(in an8855_setup the port matrix was always cleared but
the CPU port was never initially added)
- Disable learning and flood for user port by default
- Set CPU port to flood and learning by default
- Correctly AND force duplex and flow control in an8855_phylink_mac_link_up
- Drop RGMII from pcs_config
- Check ret in "Disable AN if not in autoneg"
- Use devm_mutex_init
- Fix typo for AN8855_PORT_CHECK_MODE
- Better define AN8855_STP_LISTENING = AN8855_STP_BLOCKING
- Fix typo in AN8855_PHY_EN_DOWN_SHIFT
- Use paged helper for PHY
- Skip calibration in config_init if priv not defined
Changes v3:
- Out of RFC
- Switch PHY code to select_page API
- Better describe masks and bits in PHY driver for ADC register
- Drop raw values and use define for mii read/write
- Switch to absolute PHY address
- Replace raw values with mask and bits for pcs_config
- Fix typo for ext-surge property name
- Drop support for relocating Switch base PHY address on the bus
Changes v2:
- Drop mutex guard patch
- Drop guard usage in DSA driver
- Use __mdiobus_write/read
- Check return condition and return errors for mii read/write
- Fix wrong logic for EEE
- Fix link_down (don't force link down with autoneg)
- Fix forcing speed on sgmii autoneg
- Better document link speed for sgmii reg
- Use standard define for sgmii reg
- Imlement nvmem support to expose switch EFUSE
- Rework PHY calibration with the use of NVMEM producer/consumer
- Update DT with new NVMEM property
- Move aneg validation for 2500-basex in pcs_config
- Move r50Ohm table and function to PHY driver
Christian Marangi (9):
dt-bindings: net: dsa: Document support for Airoha AN8855 DSA Switch
dt-bindings: net: Document support for AN8855 Switch Internal PHY
dt-bindings: mfd: Document support for Airoha AN8855 Switch SoC
mfd: an8855: Add support for Airoha AN8855 Switch MFD
net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY
net: dsa: tag_mtk: add Airoha variant usage of this TAG
MAINTAINERS: add myself as maintainer for Airoha AN8855 Switch
net: dsa: mt7530: generalize and move common function to lib module
net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver
Daniel Golle (1):
net: dsa: mt7530: move MDIO bus locking into regmap
.../bindings/mfd/airoha,an8855.yaml | 173 ++ .../bindings/net/airoha,an8855-phy.yaml | 83 + .../net/dsa/airoha,an8855-switch.yaml | 86 + MAINTAINERS | 16 + drivers/mfd/Kconfig | 13 + drivers/mfd/Makefile | 1 + drivers/mfd/airoha-an8855.c | 517 +++++ drivers/net/dsa/Kconfig | 13 + drivers/net/dsa/Makefile | 2 + drivers/net/dsa/an8855.c | 1682 +++++++++++++++++ drivers/net/dsa/an8855.h | 753 ++++++++ drivers/net/dsa/mt7530-lib.c | 1120 +++++++++++ drivers/net/dsa/mt7530-lib.h | 416 ++++ drivers/net/dsa/mt7530-mdio.c | 13 +- drivers/net/dsa/mt7530-mmio.c | 4 + drivers/net/dsa/mt7530.c | 1341 +++---------- drivers/net/dsa/mt7530.h | 264 +-- drivers/net/phy/Kconfig | 5 + drivers/net/phy/Makefile | 1 + drivers/net/phy/air_an8855.c | 261 +++ include/net/dsa.h | 2 + net/dsa/Kconfig | 11 + net/dsa/Makefile | 2 +- net/dsa/tag_mtk.c | 36 +- 24 files changed, 5574 insertions(+), 1241 deletions(-) create mode 100644 Documentation/devicetree/bindings/mfd/airoha,an8855.yaml create mode 100644 Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml create mode 100644 Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml create mode 100644 drivers/mfd/airoha-an8855.c create mode 100644 drivers/net/dsa/an8855.c create mode 100644 drivers/net/dsa/an8855.h create mode 100644 drivers/net/dsa/mt7530-lib.c create mode 100644 drivers/net/dsa/mt7530-lib.h create mode 100644 drivers/net/phy/air_an8855.c
Signature · 1 line
2.53.0
PATCH v19 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.53.0
Re: [PATCH net-next v19 01/10] dt-bindings: net: dsa: Document support for Airoha AN8855 DSA Switch
Quoted 8 lines · Christian Marangi
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]>Reviewed-by Rob Herring (Arm) <[email protected]>Signed-off-by Christian Marangi <[email protected]>
Just one SoB.
Best regards,
Krzysztof
[email protected]
AI reviewRe: [PATCH net-next v19 01/10] dt-bindings: net: dsa: Document support for Airoha AN8855 DSA Switch
In reply to Christian MarangiSashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 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]>Reviewed-by Rob Herring (Arm) <[email protected]>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 v19 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.53.0
[email protected]
AI reviewRe: [PATCH net-next v19 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
PATCH v19 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 | 173 ++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/airoha,an8855.yaml
Documentation/devicetree/bindings/mfd/airoha,an8855.yaml new file +173 -0
@@ -0,0 +1,173 @@ +# 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: true + + 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: + $ref: /schemas/net/mdio.yaml# + description: MDIO exposed by the Airoha AN8855 SoC + +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 0>; + + 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.53.0
[email protected]
AI reviewRe: [PATCH net-next v19 03/10] dt-bindings: mfd: Document support for Airoha AN8855 Switch SoC
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Low] The `reset-gpios` property is defined as `true` without a `maxItems` constraint. - [Low] The `mdio`…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Low] The reset-gpios property is defined as true without a maxItems constraint.
- [Low] The mdio child node property is missing the type: object declaration.
- [Low] The example includes a DT binding header for GPIO flags but uses a magic number instead of the appropriate macro. --
--- Patch [3]: [PATCH net-next v19 03/10] dt-bindings: mfd: Document support for Airoha AN8855 Switch SoC --- commit bdb9e8bcc1f2530430cfc54469b92361f09d65cd
Author: Christian Marangi <[email protected]>
dt-bindings: mfd: Document support for Airoha AN8855 Switch SoC
This commit adds device tree bindings documentation for the Airoha AN8855 Switch SoC. It defines the constraints for peripherals including an Ethernet switch, NVMEM provider, and Ethernet PHYs.
Quoted 5 lines
Documentation/devicetree/bindings/mfd/airoha,an8855.yaml new file +0
-0@@ -0,0 +1,173 @@
[ ... ]
Documentation/devicetree/bindings/mfd/airoha,an8855.yaml line 26
Quoted 8 lines
Documentation/devicetree/bindings/mfd/airoha,an8855.yaml new file +8
-0+properties: + compatible: + const: airoha,an8855 + + reg: + maxItems: 1 + + reset-gpios: true
[Severity: Low]
Should this define a maxItems constraint?
Since it doesn't reference a common schema that enforces a limit (like panel-common.yaml), device trees defining multiple GPIOs might silently pass validation, even if the hardware only supports a single reset line.
Quoted 4 lines
Documentation/devicetree/bindings/mfd/airoha,an8855.yaml new file +4
-0+ + efuse: + type: object + $ref: /schemas/nvmem/airoha,an8855-efuse.yaml
Documentation/devicetree/bindings/mfd/airoha,an8855.yaml line 40
Quoted 10 lines
Documentation/devicetree/bindings/mfd/airoha,an8855.yaml new file +10
-0+ 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: + $ref: /schemas/net/mdio.yaml# + description: MDIO exposed by the Airoha AN8855 SoC
[Severity: Low]
Is type: object missing here?
The standard mdio.yaml does not enforce type: object at its root. If a malformed device tree defines mdio as a scalar value, object-related validation rules might be bypassed. The sibling efuse and ethernet-switch declarations correctly specify it for their respective nodes.
Quoted 12 lines
Documentation/devicetree/bindings/mfd/airoha,an8855.yaml new file +12
-0+ +required: + - compatible + - reg + - mdio + - ethernet-switch + +additionalProperties: false + +examples: + - | + #include <dt-bindings/gpio/gpio.h>
Documentation/devicetree/bindings/mfd/airoha,an8855.yaml line 62
Quoted 10 lines
Documentation/devicetree/bindings/mfd/airoha,an8855.yaml new file +10
-0+ + mdio { + #address-cells = <1>; + #size-cells = <0>; + + soc@1 { + compatible = "airoha,an8855"; + reg = <1>; + + reset-gpios = <&pio 39 0>;
[Severity: Low]
Since the dt-bindings/gpio/gpio.h header is included at the top of the example, would it be better to use GPIO_ACTIVE_HIGH instead of the raw integer 0 for the flags parameter?
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Rob Herring
maintainerRe: [PATCH net-next v19 03/10] dt-bindings: mfd: Document support for Airoha AN8855 Switch SoC
Quoted 1 line · On Wed, Jul 29, 2026 at 05:16:35PM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
If you want to make maintainers happy, reply to sashiko reports on with what you think are valid or not valid issues.
Quoted 1 line
- [Low] The
reset-gpiosproperty is defined astruewithout amaxItemsconstraint.
Not an issue.
Quoted 1 line
- [Low] The
mdiochild node property is missing thetype: objectdeclaration.
Not an issue because we implicitly add one IIRC, but you are inconsistent with using 'type: object' on child nodes.
Quoted 1 line
- [Low] The example includes a DT binding header for GPIO flags but uses a magic number instead of the appropriate macro.
Fix this.
Rob
PATCH v19 4/10 mfd: an8855: Add support for Airoha AN8855 Switch MFD
In reply to Christian MarangiAdd support for Airoha AN8855 Switch MFD 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 | 13 + drivers/mfd/Makefile | 1 + drivers/mfd/airoha-an8855.c | 517 ++++++++++++++++++++++++++++++++++++ 3 files changed, 531 insertions(+) create mode 100644 drivers/mfd/airoha-an8855.c
drivers/mfd/Kconfig +13 -0
@@ -54,6 +54,19 @@ 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 MDIO_DEVICE + 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 +517 -0
517 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH net-next v19 04/10] mfd: an8855: Add support for Airoha AN8855 Switch MFD
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider: - [High] Concurrent accesses by the switch regmap and the PHY driver on the shared MDIO address corrupt the…
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
- [High] Concurrent accesses by the switch regmap and the PHY driver on the shared MDIO address corrupt the PHY's hardware page state, causing arbitrary out-of-bounds PHY register reads/writes.
- [High] MDIO child buses and PHYs are registered before the switch is taken out of reset and initialized, causing PHY probe failures.
- [High] The reset GPIO sequence incorrectly leaves the switch held in reset, and the subsequent poll loop is vulnerable to false successes.
- [High] an8855_regmap_update_bits fails to mask write_val, risking modification of adjacent bits.
- [Medium] The driver assumes the hardware page register is 0 at boot without synchronizing this assumption, potentially causing MDIO reads from the wrong page.
- [Low] The patch violates multiple MFD subsystem guidelines regarding naming conventions and commit message formatting.
--
--- Patch [4]: [PATCH net-next v19 04/10] mfd: an8855: Add support for Airoha AN8855 Switch MFD --- Please note that due to mailing list constraints on quoting large blocks of
code, this review is provided as a free-form summary without direct patch
quotes.
commit 9fc0a25ce584ed2b0b637f4a623a857dd535edcc
Author: Christian Marangi <[email protected]>
mfd: an8855: Add support for Airoha AN8855 Switch MFD
This patch adds support for the Airoha AN8855 Switch MFD, providing a DSA switch and an NVMEM provider. It introduces a regmap over MDIO for switch and PHY accesses.
[Severity: High]
In an8855_regmap_read(), the switch regmap acquires the parent lock and sets the hardware page to EXTENDED_4. Does this interleave dangerously with the PHY driver's paged operations?
Since the PHY driver paged operations hold the child MDIO bus lock, the parent lock is acquired and released for each transaction (page write, data read, restore). Can a switch regmap operation interleave between the PHY's page write and data read, changing the hardware page?
Furthermore, when the PHY driver resumes, an855_regmap_phy_reset_page() resets the page to STANDARD (0), ignoring the PHY driver's intended page. Also, an8855_regmap_phy_write() writes the page without updating the cached priv->current_page state. Will this lead to arbitrary out-of-bounds PHY register reads and writes?
[Severity: High]
In an8855_core_probe(), the driver calls an855_mdio_register() before toggling the reset GPIO and clearing the global PHY power-down.
Since fwnode_mdiobus_register_phy() triggers the MDIO subsystem to read the PHY ID registers to detect devices, won't these accesses fail or time out if the switch is still in reset and powered down? Should the MDIO and PHY registration be moved after the hardware initialization sequence is complete?
[Severity: High]
Looking at the reset sequence in an8855_core_probe(), the code calls gpiod_set_value_cansleep(reset_gpio, 1) at the end. Since the gpiod API treats a logical 1 as asserted regardless of polarity, does this permanently hold the switch in reset?
Immediately after this, regmap_read_poll_timeout() waits for the HWTRAP register to be non-zero. Since the device is in reset, won't the 32-bit MDIO read reconstruct 0xffffffff (as __mdiobus_read returns 0xffff on error), causing the poll loop to instantly and falsely succeed?
[Severity: High]
In an8855_regmap_update_bits(), the implementation performs val &= ~mask followed by val |= write_val.
Since the regmap core does not guarantee that write_val is already pre-masked by the caller, could this unintentionally corrupt adjacent bits in the switch registers if write_val contains bits outside the mask? Would it be safer to explicitly mask it using val |= (write_val & mask)?
[Severity: Medium]
In an855_regmap_phy_reset_page(), the function skips restoring the page if priv->current_page is 0. Since priv is allocated with kzalloc(), this assumes the hardware page is also 0 at boot.
If the bootloader or a previous kernel execution left the hardware in a different page, such as EXTENDED_4, will subsequent PHY reads access the wrong hardware page because the software state does not match? Should the page register be explicitly initialized during probe?
[Severity: Low]
This isn't a bug, but there are a few MFD subsystem style and naming guideline violations.
Does the commit message description unnecessarily include the string "MFD"? Also, the private structure is named struct an8855_core_priv with an instance variable named priv. The MFD guidelines prefer using the device name for the structure, such as struct an8855, and ddata for the instance.
Finally, are there typos in the function names an855_mdio_register and an855_regmap_phy_reset_page, missing the second 8 in AN8855?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Lee Jones
maintainerRe: [PATCH net-next v19 04/10] mfd: an8855: Add support for Airoha AN8855 Switch MFD
Quoted 7 lines · On Wed, 29 Jul 2026, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
- [High] Concurrent accesses by the switch regmap and the PHY driver on the shared MDIO address corrupt the PHY's hardware page state, causing arbitrary out-of-bounds PHY register reads/writes.
- [High] MDIO child buses and PHYs are registered before the switch is taken out of reset and initialized, causing PHY probe failures.
- [High] The reset GPIO sequence incorrectly leaves the switch held in reset, and the subsequent poll loop is vulnerable to false successes.
- [High]an8855_regmap_update_bitsfails to maskwrite_val, risking modification of adjacent bits.
- [Medium] The driver assumes the hardware page register is 0 at boot without synchronizing this assumption, potentially causing MDIO reads from the wrong page.
- [Low] The patch violates multiple MFD subsystem guidelines regarding naming conventions and commit message formatting.
I'll leave these with you! :)
Quoted 85 lines
--
--- Patch [4]: [PATCH net-next v19 04/10] mfd: an8855: Add support for Airoha AN8855 Switch MFD --- Please note that due to mailing list constraints on quoting large blocks of
code, this review is provided as a free-form summary without direct patch
quotes.commit
9fc0a25ce584ed2b0b637f4a623a857dd535edcc
Author: Christian Marangi <[email protected]>
mfd: an8855: Add support for Airoha AN8855 Switch MFDThis patch adds support for the Airoha AN8855 Switch MFD, providing a DSA switch and an NVMEM provider. It introduces a regmap over MDIO for switch and PHY accesses.
[Severity: High]
Inan8855_regmap_read(), the switch regmap acquires the parent lock and sets the hardware page toEXTENDED_4. Does this interleave dangerously with the PHY driver's paged operations?Since the PHY driver paged operations hold the child MDIO bus lock, the parent lock is acquired and released for each transaction (page write, data read, restore). Can a switch regmap operation interleave between the PHY's page write and data read, changing the hardware page?
Furthermore, when the PHY driver resumes,
an855_regmap_phy_reset_page()resets the page to STANDARD (0), ignoring the PHY driver's intended page. Also,an8855_regmap_phy_write()writes the page without updating the cachedpriv->current_pagestate. Will this lead to arbitrary out-of-bounds PHY register reads and writes?[Severity: High]
Inan8855_core_probe(), the driver callsan855_mdio_register()before toggling the reset GPIO and clearing the global PHY power-down.Since
fwnode_mdiobus_register_phy()triggers the MDIO subsystem to read the PHY ID registers to detect devices, won't these accesses fail or time out if the switch is still in reset and powered down? Should the MDIO and PHY registration be moved after the hardware initialization sequence is complete?[Severity: High]
Looking at the reset sequence inan8855_core_probe(), the code callsgpiod_set_value_cansleep(reset_gpio, 1)at the end. Since the gpiod API treats a logical 1 as asserted regardless of polarity, does this permanently hold the switch in reset?Immediately after this,
regmap_read_poll_timeout()waits for the HWTRAP register to be non-zero. Since the device is in reset, won't the 32-bit MDIO read reconstruct0xffffffff(as__mdiobus_readreturns0xffffon error), causing the poll loop to instantly and falsely succeed?[Severity: High]
Inan8855_regmap_update_bits(), the implementation performs val &= ~mask followed by val |=write_val.Since the regmap core does not guarantee that
write_valis already pre-masked by the caller, could this unintentionally corrupt adjacent bits in the switch registers ifwrite_valcontains bits outside the mask? Would it be safer to explicitly mask it using val |= (write_val& mask)?[Severity: Medium]
Inan855_regmap_phy_reset_page(), the function skips restoring the page ifpriv->current_pageis 0. Since priv is allocated withkzalloc(), this assumes the hardware page is also 0 at boot.If the bootloader or a previous kernel execution left the hardware in a different page, such as
EXTENDED_4, will subsequent PHY reads access the wrong hardware page because the software state does not match? Should the page register be explicitly initialized during probe?[Severity: Low]
This isn't a bug, but there are a few MFD subsystem style and naming guideline violations.Does the commit message description unnecessarily include the string "MFD"? Also, the private structure is named struct
an8855_core_privwith an instance variable named priv. The MFD guidelines prefer using the device name for the structure, such as struct an8855, and ddata for the instance.Finally, are there typos in the function names
an855_mdio_registerandan855_regmap_phy_reset_page, missing the second 8 in AN8855?Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Signature · 1 line
Lee Jones
PATCH v19 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 | 5 + drivers/net/phy/Makefile | 1 + drivers/net/phy/air_an8855.c | 261 +++++++++++++++++++++++++++++++++++ 3 files changed, 267 insertions(+) create mode 100644 drivers/net/phy/air_an8855.c
drivers/net/phy/Kconfig +5 -0
@@ -96,6 +96,11 @@ config AIR_AN8801_PHY help Currently supports the Airoha AN8801R PHY. +config AIR_AN8855_PHY + tristate "Airoha AN8855 Internal Gigabit PHY" + 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
@@ -30,6 +30,7 @@ obj-y += $(sfp-obj-y) $(sfp-obj-m) obj-$(CONFIG_ADIN_PHY) += adin.o obj-$(CONFIG_ADIN1100_PHY) += adin1100.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 +261 -0
261 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH net-next v19 05/10] net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider: - [High] Unintended register overwrites using `phy_write_mmd` clobbers configurations for Gigabit pairs B…
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
- [High] Unintended register overwrites using phy_write_mmd clobbers configurations for Gigabit pairs B and D.
- [High] Premature exposure of the network device to userspace and broken probe deferral due to requesting NVMEM cells in config_init instead of probe.
- [Medium] TX resistance calibration enable bits are defined but not set during calibration, likely causing the hardware to ignore the calibration values.
- [Medium] The downshift tunable silently ignores the requested count, breaking the Ethtool expectation that requested tunable values are enforced.
- [Low] Missing Kconfig dependency on NVMEM causes link errors when the PHY driver is built-in and NVMEM is a module.
- [Low] Multiple register macros contain typos (R500HM instead of R50OHM, DELKAY instead of DELAY, SAMNPLE instead of SAMPLE). --
--- Patch [5]: [PATCH net-next v19 05/10] net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY ---
Note: Due to system recitation restrictions, I am providing a free-form summary of the review findings instead of the standard inline-quoted diff format.
Commit: 838a0b60afc5cdb8527d6d477a38318567cda39e
Author: Christian Marangi <[email protected]>
Subject: net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY
Summary: 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.
[Severity: Low]
In drivers/net/phy/Kconfig, AIR_AN8855_PHY is added without a dependency on NVMEM.
Will this cause a linker error if the PHY driver is built-in (CONFIG_AIR_AN8855_PHY=y) and NVMEM is built as a module (CONFIG_NVMEM=m)?
It might be safer to add depends on NVMEM || !NVMEM to prevent this linkage mismatch.
[Severity: High]
In drivers/net/phy/air_an8855.c, inside an8855_config_init(), nvmem_cell_read_u32() is called via an8855_get_r50ohm_val() to fetch calibration data.
Since config_init executes during phy_init_hw(), which typically happens when the interface is brought up (ndo_open), will this break probe deferral?
If the NVMEM provider is not yet ready, nvmem_cell_read_u32() will return -EPROBE_DEFER. Returning this from an open() syscall prevents the kernel from properly rescheduling the probe.
Should these NVMEM cells be requested and cached earlier during an8855_probe()?
[Severity: Medium]
Also in an8855_config_init(), when applying the calibration data for TX pairs A, B, C, and D using phy_modify_mmd(), the enable bits (such as AN8855_PHY_R50OHM_RSEL_TX_A_EN) are not included in the mask or set arguments.
Are these enable bits required by the hardware to apply the calibration?
If so, will the hardware ignore the new calibration values because the enable bits are not being asserted?
[Severity: High]
Further down in an8855_config_init(), phy_write_mmd() is used to configure AN8855_PHY_TX_PAIR_DLY_SEL_GBE and AN8855_PHY_RXADC_CTRL for pairs A and C.
Because phy_write_mmd() overwrites the entire 16-bit register, does this unintentionally zero out the configurations for Gigabit pairs B and D?
Since Gigabit Ethernet requires all four pairs, clearing the delay and phase selection for pairs B and D might break link establishment or degrade the signal.
Should this use phy_modify_mmd() instead?
[Severity: Medium]
In an8855_set_downshift(), the function accepts a downshift count, but it entirely ignores the numeric value unless it equals DOWNSHIFT_DEV_DISABLE.
Does this break the ethtool expectation that requested tunable values are strictly enforced?
Since an8855_get_downshift() unconditionally returns DOWNSHIFT_DEV_DEFAULT_COUNT, subsequent reads won't match the user's setting.
Should the driver return -EOPNOTSUPP for unsupported numeric values rather than silently ignoring the requested count and returning success?
[Severity: Low]
This isn't a bug, but there are a few typos in the register macro definitions at the top of drivers/net/phy/air_an8855.c.
AN8855_PHY_R500HM_RSEL_TX_AB uses zeroes instead of the letter O. AN8855_PHY_CR_DA_TX_PAIR_DELKAY_SEL_A_GBE spells DELAY as DELKAY, and AN8855_PHY_RG_AD_SAMNPLE_PHSEL_A spells SAMPLE as SAMNPLE.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
PATCH v19 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
@@ -59,6 +59,7 @@ struct tc_action;#define DSA_TAG_PROTO_MXL_GSW1XX_VALUE 31#define DSA_TAG_PROTO_MXL862_VALUE 32#define DSA_TAG_PROTO_NETC_VALUE 33 +#define DSA_TAG_PROTO_AIROHA_VALUE 34enum dsa_tag_protocol {DSA_TAG_PROTO_NONE =DSA_TAG_PROTO_NONE_VALUE ,
@@ -73,6 +74,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
@@ -98,8 +105,12 @@ config NET_DSA_TAG_EDSA Say Y or M if you want to enable support for tagging frames for the Marvell switches which use EtherType DSA headers. +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
@@ -27,7 +27,7 @@ obj-$(CONFIG_NET_DSA_TAG_GSWIP) += tag_gswip.o obj-$(CONFIG_NET_DSA_TAG_HELLCREEK) += tag_hellcreek.o obj-$(CONFIG_NET_DSA_TAG_KSZ) += tag_ksz.o obj-$(CONFIG_NET_DSA_TAG_LAN9303) += tag_lan9303.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.53.0
[email protected]
AI reviewRe: [PATCH net-next v19 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] Introducing DSA_TAG_PROTO_AIROHA breaks DSA hardware offloading and tag processing in compatible…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Introducing DSA_TAG_PROTO_AIROHA breaks DSA hardware offloading and tag processing in compatible Ethernet MAC drivers (Airoha and Mediatek). --
--- Patch [6]: [PATCH net-next v19 06/10] net: dsa: tag_mtk: add Airoha variant usage of this TAG --- commit 2b8fd23ca8ea6ac3597ff1360a2ad1a9a14fa563
Author: Christian Marangi <[email protected]>
net: dsa: tag_mtk: add Airoha variant usage of this TAG
This commit introduces a new DSA tag protocol variant for Airoha switches, documenting differences from the Mediatek tag bitmap. It also adds a dedicated config, makefile entry, and "airoha" name for external tools like libpcap.
include/net/dsa.h enum dsa_tag_protocol { · line 77
Quoted 9 lines
include/net/dsa.h +1
-0@@ -73,6 +74,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]
Will this new tag protocol break hardware offloading and tag processing in the Ethernet MAC drivers?
Looking at airoha_get_dsa_tag() in drivers/net/ethernet/airoha/airoha_eth.c, the driver requires DSA_TAG_PROTO_MTK to extract the tag into the DMA descriptor:
if (dev->dsa_ptr->tag_ops->proto != DSA_TAG_PROTO_MTK) return 0;
For DSA_TAG_PROTO_AIROHA, this fails and leaves the tag in the packet payload, which can break the PPE module that expects untagged packets.
Similarly, the Mediatek Ethernet driver checks strictly for DSA_TAG_PROTO_MTK in mtk_uses_dsa() (mtk_eth_soc.c), __mtk_ppe_check_skb() (mtk_ppe.c), and mtk_flow_get_dsa_port() (mtk_ppe_offload.c). Without DSA_TAG_PROTO_MTK, hardware DSA untagging and PPE offloading will silently fail.
Do these host Ethernet drivers need to be updated to accept DSA_TAG_PROTO_AIROHA alongside DSA_TAG_PROTO_MTK?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
PATCH v19 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
@@ -760,6 +760,22 @@ S: Maintained F: Documentation/devicetree/bindings/net/airoha,en7581-eth.yaml F: drivers/net/ethernet/airoha/ +AIROHA AN8855 DSA DRIVER +M: Christian Marangi <[email protected]> +L: [email protected] (moderated for non-subscribers) +L: [email protected] (moderated for non-subscribers) +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/mfd/airoha,an8855.yaml +F: Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml +F: Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml +F: Documentation/devicetree/bindings/nvmem/airoha,an8855-efuse.yaml +F: drivers/mfd/airoha-an8855.c +F: drivers/net/dsa/an8855.c +F: drivers/net/dsa/an8855.h +F: drivers/net/phy/air_an8855.c +F: drivers/nvmem/an8855-efuse.c + AIROHA PCIE PHY DRIVER M: Lorenzo Bianconi <[email protected]> L: [email protected] (moderated for non-subscribers)
Signature · 1 line
2.53.0
PATCH v19 8/10 net: dsa: mt7530: move MDIO bus locking into regmap
In reply to Christian MarangiFrom: Daniel Golle <[email protected]>
The switch register regmap was created with .disable_locking = true, relying on callers to manually lock the MDIO bus. Move the locking into the regmap using .lock/.unlock callbacks, matching the PCS regmaps that already do this. This allows any code path reaching the regmap to be automatically protected.
With regmap handling bus locking, the manual mt7530_mutex_lock/unlock wrappers in mt7530_write(), _mt7530_read(), mt7530_rmw() and mt7530_port_change_mtu() become redundant and are removed.
The MT7531 indirect PHY access functions need serialization of their multi-step register sequences, but no longer need to hold bus->mdio_lock across the whole operation. Switch them to reg_mutex.
core_write()/core_rmw() are the only remaining callers of mt7530_mutex_lock(). They access TRGMII core PHY registers via the clause 22 MMD indirect protocol -- a separate register space that bypasses regmap and needs manual bus->mdio_lock protection.
Generated using the following semantic patch:
// Remove mt7530_mutex_lock/unlock around single regmap-based calls. @@
expression priv, reg, val;
@@
{
- mt7530_mutex_lock(priv);
-
mt7530_mii_write(priv, reg, val);
-
- mt7530_mutex_unlock(priv);
}
@@
expression priv, reg, mask, set;
@@
{
- mt7530_mutex_lock(priv);
-
regmap_update_bits(priv->regmap, reg, mask, set);
-
- mt7530_mutex_unlock(priv);
}
@@
expression p;
identifier val;
@@
{
- u32 val;
- mt7530_mutex_lock(p->priv);
- val = mt7530_mii_read(p->priv, p->reg);
- mt7530_mutex_unlock(p->priv);
- return val;
+ return mt7530_mii_read(p->priv, p->reg);
}
@@
expression priv;
@@
- mt7530_mutex_lock(priv);
val = mt7530_mii_read(priv, MT7530_GMACCR);
...
mt7530_mii_write(priv, MT7530_GMACCR, val);
- mt7530_mutex_unlock(priv);
@@
expression priv, port;
@@
INIT_MT7530_DUMMY_POLL(&p, priv, MT7531_PHY_IAC);
- mt7530_mutex_lock(priv);
+ mutex_lock(&priv->reg_mutex);
@@
expression priv;
@@
out:
- mt7530_mutex_unlock(priv);
+ mutex_unlock(&priv->reg_mutex);
--- drivers/net/dsa/mt7530-mdio.c | 9 ++++++--- drivers/net/dsa/mt7530.c | 38 +++++++++-------------------------- 2 files changed, 15 insertions(+), 32 deletions(-)
drivers/net/dsa/mt7530-mdio.c +6 -3
@@ -141,12 +141,14 @@ static const struct regmap_config regmap_config = { .val_bits = 32, .reg_stride = 4, .max_register = MT7530_CREV, - .disable_locking = true, + .lock = mt7530_mdio_regmap_lock, + .unlock = mt7530_mdio_regmap_unlock, };static int mt7530_probe (struct mdio_device *mdiodev) { +struct regmap_config rc = regmap_config;struct mt7530_priv *priv;struct device_node *dn;int ret;
@@ -200,8 +202,9 @@ mt7530_probe(struct mdio_device *mdiodev)return PTR_ERR (priv->io_pwr); } - priv->regmap =devm_regmap_init (priv->dev, &mt7530_regmap_bus, priv, - ®map_config); + rc.lock_arg = &priv->bus->mdio_lock; + priv->regmap =devm_regmap_init (priv->dev, &mt7530_regmap_bus, + priv, &rc);if (IS_ERR (priv->regmap))return PTR_ERR (priv->regmap);
drivers/net/dsa/mt7530.c +9 -29
@@ -184,11 +184,7 @@ mt7530_mii_read(struct mt7530_priv *priv, u32 reg)static void mt7530_write (struct mt7530_priv *priv,u32 reg,u32 val) { -mt7530_mutex_lock (priv); -mt7530_mii_write (priv, reg, val); - -mt7530_mutex_unlock (priv); } static u32
@@ -200,15 +196,7 @@ _mt7530_unlocked_read(struct mt7530_dummy_poll *p)static u32 _mt7530_read (struct mt7530_dummy_poll *p) { -u32 val; - -mt7530_mutex_lock (p->priv); - - val =mt7530_mii_read (p->priv, p->reg); - -mt7530_mutex_unlock (p->priv); - -return val; +return mt7530_mii_read (p->priv, p->reg); } static u32
@@ -224,11 +212,7 @@ static void mt7530_rmw(struct mt7530_priv *priv, u32 reg, u32 mask, u32 set) { -mt7530_mutex_lock (priv); - regmap_update_bits(priv->regmap, reg, mask, set); - -mt7530_mutex_unlock (priv); } static void
@@ -555,7 +539,7 @@ mt7531_ind_c45_phy_read(struct mt7530_priv *priv, int port, int devad,INIT_MT7530_DUMMY_POLL (&p, priv,MT7531_PHY_IAC ); -mt7530_mutex_lock (priv); +mutex_lock (&priv->reg_mutex); ret =readx_poll_timeout (_mt7530_unlocked_read, &p, val, !(val &MT7531_PHY_ACS_ST ),20 ,100000 );
@@ -588,7 +572,7 @@ mt7531_ind_c45_phy_read(struct mt7530_priv *priv, int port, int devad, ret = val &MT7531_MDIO_RW_DATA_MASK ; out: -mt7530_mutex_unlock (priv); +mutex_unlock (&priv->reg_mutex);return ret; }
@@ -603,7 +587,7 @@ mt7531_ind_c45_phy_write(struct mt7530_priv *priv, int port, int devad,INIT_MT7530_DUMMY_POLL (&p, priv,MT7531_PHY_IAC ); -mt7530_mutex_lock (priv); +mutex_lock (&priv->reg_mutex); ret =readx_poll_timeout (_mt7530_unlocked_read, &p, val, !(val &MT7531_PHY_ACS_ST ),20 ,100000 );
@@ -635,7 +619,7 @@ mt7531_ind_c45_phy_write(struct mt7530_priv *priv, int port, int devad, } out: -mt7530_mutex_unlock (priv); +mutex_unlock (&priv->reg_mutex);return ret; }
@@ -649,7 +633,7 @@ mt7531_ind_c22_phy_read(struct mt7530_priv *priv, int port, int regnum)INIT_MT7530_DUMMY_POLL (&p, priv,MT7531_PHY_IAC ); -mt7530_mutex_lock (priv); +mutex_lock (&priv->reg_mutex); ret =readx_poll_timeout (_mt7530_unlocked_read, &p, val, !(val &MT7531_PHY_ACS_ST ),20 ,100000 );
@@ -672,7 +656,7 @@ mt7531_ind_c22_phy_read(struct mt7530_priv *priv, int port, int regnum) ret = val &MT7531_MDIO_RW_DATA_MASK ; out: -mt7530_mutex_unlock (priv); +mutex_unlock (&priv->reg_mutex);return ret; }
@@ -687,7 +671,7 @@ mt7531_ind_c22_phy_write(struct mt7530_priv *priv, int port, int regnum,INIT_MT7530_DUMMY_POLL (&p, priv,MT7531_PHY_IAC ); -mt7530_mutex_lock (priv); +mutex_lock (&priv->reg_mutex); ret =readx_poll_timeout (_mt7530_unlocked_read, &p, reg, !(reg &MT7531_PHY_ACS_ST ),20 ,100000 );
@@ -709,7 +693,7 @@ mt7531_ind_c22_phy_write(struct mt7530_priv *priv, int port, int regnum, } out: -mt7530_mutex_unlock (priv); +mutex_unlock (&priv->reg_mutex);return ret; }
@@ -1444,8 +1428,6 @@ mt7530_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu)if (!dsa_is_cpu_port (ds, port))return 0 ; -mt7530_mutex_lock (priv); - val =mt7530_mii_read (priv,MT7530_GMACCR ); val &= ~MAX_RX_PKT_LEN_MASK ;
@@ -1465,8 +1447,6 @@ mt7530_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu)mt7530_mii_write (priv,MT7530_GMACCR , val); -mt7530_mutex_unlock (priv); -return 0 ; }
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH net-next v19 08/10] net: dsa: mt7530: move MDIO bus locking into regmap
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 19 lines
From: Daniel Golle <[email protected]>
The switch register regmap was created with .disable_locking = true, relying on callers to manually lock the MDIO bus. Move the locking into the regmap using .lock/.unlock callbacks, matching the PCS regmaps that already do this. This allows any code path reaching the regmap to be automatically protected.
With regmap handling bus locking, the manual mt7530_mutex_lock/unlock wrappers in
mt7530_write(),_mt7530_read(),mt7530_rmw()andmt7530_port_change_mtu()become redundant and are removed.The MT7531 indirect PHY access functions need serialization of their multi-step register sequences, but no longer need to hold
bus->mdio_lockacross the whole operation. Switch them toreg_mutex.
[ ... ](quoted diff) +1
-1- mt7530_mutex_unlock(priv); + mutex_unlock(&priv->reg_mutex);
Quoted 2 lines
Signed-off-by Daniel Golle <[email protected]>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 v19 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/Kconfig | 4 + drivers/net/dsa/Makefile | 1 + drivers/net/dsa/mt7530-lib.c | 1094 +++++++++++++++++++++++++++ drivers/net/dsa/mt7530-lib.h | 395 ++++++++++ drivers/net/dsa/mt7530-mdio.c | 4 + drivers/net/dsa/mt7530-mmio.c | 4 + drivers/net/dsa/mt7530.c | 1303 ++++++++------------------------- drivers/net/dsa/mt7530.h | 264 ++----- 8 files changed, 1864 insertions(+), 1205 deletions(-) create mode 100644 drivers/net/dsa/mt7530-lib.c create mode 100644 drivers/net/dsa/mt7530-lib.h
drivers/net/dsa/Kconfig +4 -0
@@ -28,8 +28,12 @@ source "drivers/net/dsa/hirschmann/Kconfig" source "drivers/net/dsa/lantiq/Kconfig" +config NET_DSA_MT7530_LIB + tristate + config NET_DSA_MT7530 tristate "MediaTek MT7530 and MT7531 Ethernet switch support" + select NET_DSA_MT7530_LIB select NET_DSA_TAG_MTK select REGMAP_IRQ imply NET_DSA_MT7530_MDIO
drivers/net/dsa/Makefile +1 -0
@@ -4,6 +4,7 @@ bcm-sf2-objs := bcm_sf2.o bcm_sf2_cfp.o obj-$(CONFIG_NET_DSA_LOOP) += dsa_loop.o obj-$(CONFIG_NET_DSA_KS8995) += ks8995.o obj-$(CONFIG_NET_DSA_MT7530) += mt7530.o +obj-$(CONFIG_NET_DSA_MT7530_LIB) += mt7530-lib.o obj-$(CONFIG_NET_DSA_MT7530_MDIO) += mt7530-mdio.o obj-$(CONFIG_NET_DSA_MT7530_MMIO) += mt7530-mmio.o obj-$(CONFIG_NET_DSA_MV88E6060) += mv88e6060.o
drivers/net/dsa/mt7530-lib.c new file +1094 -0
1,094 lines not on this page · raw message
drivers/net/dsa/mt7530-lib.h new file +395 -0
395 lines not on this page · raw message
drivers/net/dsa/mt7530-mdio.c +4 -0
@@ -208,6 +208,10 @@ mt7530_probe(struct mdio_device *mdiodev)if (IS_ERR (priv->regmap))return PTR_ERR (priv->regmap); + ret =mt7530_setup_lib_priv (priv); +if (ret) +return ret; +if (priv->id ==ID_MT7531 ) priv->create_sgmii = mt7531_create_sgmii;
drivers/net/dsa/mt7530-mmio.c +4 -0
@@ -60,6 +60,10 @@ mt7988_probe(struct platform_device *pdev)if (IS_ERR (priv->regmap))return PTR_ERR (priv->regmap); + ret =mt7530_setup_lib_priv (priv); +if (ret) +return ret; +return dsa_register_switch (priv->ds); }
drivers/net/dsa/mt7530.c +300 -1003
1,472 lines not on this page · raw message
drivers/net/dsa/mt7530.h +62 -202
264 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.53.0
Part of the diff is not shown here. View the raw message.
[email protected]
AI reviewRe: [PATCH net-next v19 09/10] net: dsa: mt7530: generalize and move common function to lib module
Thank you for your contribution! Sashiko AI review found 11 potential issue(s) to consider: - [Critical] Negative array indexing (`fields[-1]`) in `mt7530_get_ethtool_stats` causes an out-of-bounds…
Thank you for your contribution! Sashiko AI review found 11 potential issue(s) to consider:
- [Critical] Negative array indexing (fields[-1]) in mt7530_get_ethtool_stats causes an out-of-bounds read and kernel panic.
- [High] Bridge port MAC learning logic evaluates to zero, permanently enabling learning.
- [High] FDB write operations store corrupted all-zero MAC addresses due to incorrect right-shifting and swapped bit ranges.
- [High] Semantic mismatch in the port matrix (pm) cache breaks port enablement and corrupts port control registers.
- [High] MIB counter REG_FIELD_ID definitions specify an invalid MSB of 32, triggering undefined behavior in GENMASK on 32-bit platforms.
- [High] A copy-paste error omits the hardware trap configuration for the :03 MAC DA, bypassing IEEE 802.1Q filtering rules.
- [High] Replacing atomic register writes with field-specific RMWs preserves dirty hardware register states during VLAN 0 setup.
- [High] Unchecked regmap field reads leak uninitialized kernel stack memory to userspace and break hardware isolation policies.
- [Medium] TX and RX RMON packet size histograms are incorrectly swapped, reporting TX stats as RX and vice versa.
- [Medium] Multicast packet statistics are incorrectly discarded and never reported in mt7530_read_port_stats64.
- [Medium] MIB counters are not flushed during initialization because the driver writes 0 instead of 1 to the respective flush bits. --
--- Patch [9]: [PATCH net-next v19 09/10] net: dsa: mt7530: generalize and move common function to lib module --- commit 0ff2707d21a36354cbb42ab9fd85231c636ec13a
Author: Christian Marangi <[email protected]>
net: dsa: mt7530: generalize and move common function to lib module
In preparation of support of DSA Switch from Airoha, create a mt7530 library module and move there all the common function.
Quoted 13 lines
drivers/net/dsa/mt7530-lib.c new file +7
-0@@ -0,0 +1,1094 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include <linux/device.h> +#include <linux/if_bridge.h> +#include <linux/module.h> +#include <linux/regmap.h> +#include <net/dsa.h>
drivers/net/dsa/mt7530-lib.c line 17
Quoted 10 lines
drivers/net/dsa/mt7530-lib.c new file +10
-0+ +#include "mt7530-lib.h" + +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 ],0 ); +regmap_field_write (priv->fields[MT7530_CCR_RX_OCT_CNT_BAD ],0 ); +regmap_field_write (priv->fields[MT7530_CCR_TX_OCT_CNT_GOOD ],0 ); +regmap_field_write (priv->fields[MT7530_CCR_TX_OCT_CNT_BAD ],0 );
[Severity: Medium]
Does writing 0 here correctly trigger the flush?
The hardware typically requires these specific bits to be asserted (1) to clear the counters, similar to the original CCR_MIB_FLUSH bitmask.
Writing 0 might leave the flush operation disabled, causing the hardware to report leftover garbage across reboots.
[ ... ]
Quoted 10 lines
drivers/net/dsa/mt7530-lib.c new file +10
-0+void mt7530_lib_trap_frames (struct mt7530_lib_priv *priv) +{ +/* Trap 802.1X PAE frames and BPDUs to the CPU port(s) and egress +* them with the EG_TAG attribute set to disabled (system default) +* so that any VLAN tags in the frame are not modified by the +* switch egress VLAN tag processing. This preserves VLAN tags +* for reception on VLAN sub-interfaces. +*/ +regmap_field_write (priv->fields[MT7530_BPDU_EG_TAG ], +MT7530_VLAN_EG_DISABLED );
[ ... ]
drivers/net/dsa/mt7530-lib.c line 229
Quoted 8 lines
drivers/net/dsa/mt7530-lib.c new file +8
-0+/* Trap frames with :03 and :0E MAC DAs to the CPU port(s) and +* egress them with EG_TAG disabled. +*/ +regmap_field_write (priv->fields[MT7530_R02_BPDU_FR ],1 ); +regmap_field_write (priv->fields[MT7530_R02_EG_TAG ], +MT7530_VLAN_EG_DISABLED ); +regmap_field_write (priv->fields[MT7530_R02_PORT_FW ], +TO_CPU_FW_CPU_ONLY );
[Severity: High]
Is there a copy-paste error here?
The comment mentions trapping :03 and :0E MAC DAs, but the code modifies MT7530_R02 instead of MT7530_R03.
This leaves the :03 frame trap unconfigured, potentially bypassing IEEE 802.1Q filtering rules.
Quoted 36 lines
drivers/net/dsa/mt7530-lib.c new file +36
-0+regmap_field_write (priv->fields[MT7530_R0E_BPDU_FR ],1 ); +regmap_field_write (priv->fields[MT7530_R0E_EG_TAG ], +MT7530_VLAN_EG_DISABLED ); +regmap_field_write (priv->fields[MT7530_R0E_PORT_FW ], +TO_CPU_FW_CPU_ONLY ); +} +EXPORT_SYMBOL_GPL (mt7530_lib_trap_frames); + +static void mt7530_update_port_member (struct mt7530_lib_priv *priv,int port, +const struct net_device *bridge_dev, + bool join) __must_hold(priv->reg_mutex) +{ +struct dsa_port *dp =dsa_to_port (priv->ds, port), *other_dp; +struct mt7530_port *p = &priv->ports[port], *other_p; +struct dsa_port *cpu_dp = dp->cpu_dp; +u32 port_bitmap =BIT (cpu_dp->index); +int other_port; +bool isolated; + +dsa_switch_for_each_user_port (other_dp, priv->ds) { + other_port = other_dp->index; + other_p = &priv->ports[other_port]; + +if (dp == other_dp) +continue ; + +/* Add/remove this port to/from the port matrix of the other +* ports in the same bridge. If the port is disabled, port +* matrix is kept and not being setup until the port becomes +* enabled. +*/ +if (!dsa_port_offloads_bridge_dev (other_dp, bridge_dev)) +continue ; + + isolated = p->isolated && other_p->isolated; +
drivers/net/dsa/mt7530-lib.c line 275
Quoted 10 lines
drivers/net/dsa/mt7530-lib.c new file +10
-0+if (join && !isolated) { + other_p->pm |=BIT (port); + port_bitmap |=BIT (other_port); + }else { + other_p->pm &= ~BIT (port); + } + +if (other_p->enable) +regmap_fields_write (priv->fields[MT7530_PCR_MATRIX ], + other_port, other_p->pm);
[Severity: High]
Could this corrupt the port control registers?
The legacy mt7530_port_enable() function (which is still present) stores pre-shifted values in pm (e.g., PCR_MATRIX(BIT(cpu_dp->index))).
Here, pm is treated as an unshifted bitmask and passed to regmap_fields_write(), which shifts the entire value left by 16 bits.
This will shift the pre-shifted CPU port bit completely out of bounds (overflowing to 0) and isolate the port from the CPU.
Quoted 10 lines
drivers/net/dsa/mt7530-lib.c new file +10
-0+ } + +/* Add/remove the all other ports to this port matrix. For !join +* (leaving the bridge), only the CPU port will remain in the port matrix +* of this port. +*/ + p->pm = port_bitmap; +if (priv->ports[port].enable) +regmap_fields_write (priv->fields[MT7530_PCR_MATRIX ], + port, port_bitmap);
drivers/net/dsa/mt7530-lib.c line 295
Quoted 10 lines
drivers/net/dsa/mt7530-lib.c new file +10
-0+} + +void mt7530_lib_read_port_stats (struct regmap_field *low, +struct regmap_field *high, +int port,uint64_t *data) +{ +u32 val; + +regmap_fields_read (low, port, &val); + *data = val;
[Severity: High]
What happens if the underlying MDIO bus read fails here?
The return value of regmap_fields_read() is not checked, meaning val could remain uninitialized.
This would leak kernel stack memory to userspace via ethtool. Similarly, in mt7530_hw_vlan_update() below, it uses uninitialized stack data to build port masks, randomly altering VLAN memberships.
Quoted 7 lines
drivers/net/dsa/mt7530-lib.c new file +7
-0+ +if (high) { +regmap_fields_read (high, port, &val); + *data |= (u64 )val <<32 ; + } +} +EXPORT_SYMBOL_GPL (mt7530_lib_read_port_stats);
[ ... ]
Quoted 6 lines
drivers/net/dsa/mt7530-lib.c new file +6
-0+static void mt7530_lib_fdb_write (struct mt7530_lib_priv *priv,u16 vid, +u8 port_mask,const u8 *mac, +u8 aging,u8 type) +{ +regmap_field_write (priv->fields[MT7530_ATWD_CVID ], vid); +regmap_field_write (priv->fields[MT7530_ATWD_IVL ],1 );
drivers/net/dsa/mt7530-lib.c line 443
Quoted 10 lines
drivers/net/dsa/mt7530-lib.c new file +10
-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); +/* STATIC_ENT indicate that entry is static wouldn't +* be aged out and STATIC_EMP specified as erasing an +* entry +*/ +regmap_field_write (priv->fields[MT7530_ATWD_ENT_STATUS ], type); +regmap_field_write (priv->fields[MT7530_ATWD_MAC_BYTE_5 ], + mac[5 ] >>MAC_BYTE_5 );
[Severity: High]
Will this result in all-zero MAC addresses being written to the FDB?
The mac array contains 8-bit u8 values. Right-shifting a u8 by MAC_BYTE_5 (which is 16) or MAC_BYTE_4 (which is 24) will always evaluate to 0.
Since regmap_field_write() automatically handles shifting values into their proper field positions, it seems we should pass the raw mac[x] bytes without shifting.
Quoted 4 lines
drivers/net/dsa/mt7530-lib.c new file +4
-0+regmap_field_write (priv->fields[MT7530_ATWD_MAC_BYTE_4 ], + mac[4 ] >>MAC_BYTE_4 ); +regmap_field_write (priv->fields[MT7530_ATWD_MAC_BYTE_3 ], + mac[3 ] >>MAC_BYTE_3 );
[ ... ]
drivers/net/dsa/mt7530-lib.c line 700
Quoted 9 lines
drivers/net/dsa/mt7530-lib.c new file +9
-0+int mt7530_lib_port_bridge_flags (struct mt7530_lib_priv *priv,int port, +struct switchdev_brport_flags flags, +struct netlink_ext_ack *extack) +{ +struct dsa_switch *ds = priv->ds; + +if (flags.mask &BR_LEARNING ) +regmap_fields_write (priv->fields[MT7530_PSC_SA_DIR ], + port, flags.val &BR_LEARNING );
[Severity: High]
Does this write permanently enable MAC learning?
BR_LEARNING is BIT(5) (32). The MT7530_PSC_SA_DIR field is a 1-bit field at bit 4.
When regmap_fields_write() shifts the value by 4 and masks it with 0x10, (32 << 4) & 0x10 evaluates to 0.
Additionally, the SA_DIR bit disables learning when set to 1, so writing 0 ensures learning can never be disabled.
Quoted 5 lines
drivers/net/dsa/mt7530-lib.c new file +5
-0+ +if (flags.mask &BR_FLOOD ) +regmap_field_update_bits (priv->fields[MT7530_UNU_FFP ], +BIT (port), + flags.val &BR_FLOOD ?BIT (port) :0 );
[ ... ]
Quoted 19 lines
drivers/net/dsa/mt7530-lib.c new file +19
-0+static void mt7530_hw_vlan_update (struct mt7530_lib_priv *priv,u16 vid, +struct mt7530_hw_vlan_entry *entry, +mt7530_vlan_op vlan_op) +{ +u32 val; + +/* Fetch entry */ +mt7530_vlan_cmd (priv,MT7530_VTCR_RD_VID , vid); + +regmap_field_read (priv->fields[MT7530_VAWD_PORT_MEM ], &val); + + entry->old_members = val; + +/* Manipulate entry */ +vlan_op (priv, entry); + +/* Flush result to hardware */ +mt7530_vlan_cmd (priv,MT7530_VTCR_WR_VID , vid); +}
[ ... ]
drivers/net/dsa/mt7530-lib.c line 1080
Quoted 4 lines
drivers/net/dsa/mt7530-lib.c new file +4
-0+int mt7530_lib_setup_vlan0 (struct mt7530_lib_priv *priv) +{ +regmap_field_write (priv->fields[MT7530_VAWD_IVL_MAC ],1 ); +regmap_field_write (priv->fields[MT7530_VAWD_EG_CON ],1 );
[Severity: High]
Could this leave MT7530_VAWD1 in an inconsistent state?
The original code wrote directly to the MT7530_VAWD1 register, effectively clearing unspecified bits like VTAG_EN.
Because VAWD1 is a data window that retains the state of the last accessed VLAN entry, selectively modifying individual fields with read-modify-write might leave VTAG_EN in an undefined state from a previous operation, randomly tagging VLAN 0 frames.
Quoted 4 lines
drivers/net/dsa/mt7530-lib.c new file +4
-0+regmap_field_write (priv->fields[MT7530_VAWD_PORT_MEM ], +MT7530_ALL_MEMBERS ); +regmap_field_write (priv->fields[MT7530_VAWD_FID ], +FID_BRIDGED );
[ ... ]
Quoted 16 lines
drivers/net/dsa/mt7530.c +4
-0@@ -24,10 +24,159 @@#include <net/pkt_cls.h> #include "mt7530.h" +#include "mt7530-lib.h" #define MT7530_STATS_POLL_INTERVAL (1 * HZ)#define MT7530_STATS_RATE_LIMIT (HZ / 10) +static const struct mt7530_reg_field mt753x_fields[] = { + {MT7530_BC_FFP ,REG_FIELD (MT753X_MFC ,24 ,31 ) }, + {MT7530_UNM_FFP ,REG_FIELD (MT753X_MFC ,16 ,23 ) },
[ ... ]
drivers/net/dsa/mt7530.c line 84
Quoted 3 lines
drivers/net/dsa/mt7530.c +3
-0+ { MT7530_ATWD_ENT_STATUS, REG_FIELD(MT7530_ATWD, 2, 3), }, + { MT7530_ATWD_MAC_BYTE_5, REG_FIELD(MT7530_ATA2, 24, 31), }, + { MT7530_ATWD_MAC_BYTE_4, REG_FIELD(MT7530_ATA2, 16, 23), },
[Severity: High]
Are the bit ranges for MAC_BYTE_4 and MAC_BYTE_5 swapped here?
The original definitions and typical byte ordering suggest MAC_BYTE_5 should be bits 16-23 and MAC_BYTE_4 should be bits 24-31.
Quoted 3 lines
drivers/net/dsa/mt7530.c +3
-0+ { MT7530_ATWD_MAC_BYTE_3, REG_FIELD(MT7530_ATA1, 0, 7), }, + { MT7530_ATWD_MAC_BYTE_2, REG_FIELD(MT7530_ATA1, 8, 15), }, + { MT7530_ATWD_MAC_BYTE_1, REG_FIELD(MT7530_ATA1, 16, 23), },
[ ... ]
drivers/net/dsa/mt7530.c line 126
Quoted 5 lines
drivers/net/dsa/mt7530.c +5
-0+ { MT7530_GMACCR_MAX_RX_JUMBO, REG_FIELD(MT7530_GMACCR, 2, 5) }, + { MT7530_GMACCR_MAX_RX_PKT_LEN, REG_FIELD(MT7530_GMACCR, 0, 1) }, + + { MT7530_MIB_TX_DROP, REG_FIELD_ID(MT7530_PORT_MIB_TX_DROP, 0, 32, MT7530_NUM_PORTS, 0x100) }, + { MT7530_MIB_TX_CRC_ERR, REG_FIELD_ID(MT7530_PORT_MIB_TX_CRC_ERR, 0, 32, MT7530_NUM_PORTS, 0x100) },
[Severity: High]
Does specifying 32 as the MSB here cause undefined behavior on 32-bit platforms?
The REG_FIELD_ID macro takes inclusive bounds, so an MSB of 32 results in GENMASK(32, 0).
On 32-bit architectures, this evaluates to a negative shift count (~0UL << -1). Should the bound be 0, 31 instead?
Quoted 3 lines
drivers/net/dsa/mt7530.c +3
-0+ { MT7530_MIB_TX_UNICAST, REG_FIELD_ID(MT7530_PORT_MIB_TX_UNICAST, 0, 32, MT7530_NUM_PORTS, 0x100) }, + { MT7530_MIB_TX_MULTICAST, REG_FIELD_ID(MT7530_PORT_MIB_TX_MULTICAST, 0, 32, MT7530_NUM_PORTS, 0x100) }, + { MT7530_MIB_TX_BROADCAST, REG_FIELD_ID(MT7530_PORT_MIB_TX_BROADCAST, 0, 32, MT7530_NUM_PORTS, 0x100) },
[ ... ]
Quoted 18 lines
static struct
mt753x_pcs*pcs_to_mt753x_pcs(structphylink_pcs*pcs) {drivers/net/dsa/mt7530.c +2
-9return container_of(pcs, struct mt753x_pcs, pcs);@@ -35,15 +184,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[] = { -MIB_DESC (1 ,MT7530_PORT_MIB_TX_DROP ,"TxDrop" ), -MIB_DESC (1 ,MT7530_PORT_MIB_TX_CRC_ERR ,"TxCrcErr" ), -MIB_DESC (1 ,MT7530_PORT_MIB_TX_COLLISION ,"TxCollision" ), -MIB_DESC (1 ,MT7530_PORT_MIB_RX_DROP ,"RxDrop" ), -MIB_DESC (1 ,MT7530_PORT_MIB_RX_FILTERING ,"RxFiltering" ), -MIB_DESC (1 ,MT7530_PORT_MIB_RX_CRC_ERR ,"RxCrcErr" ), -MIB_DESC (1 ,MT7530_PORT_MIB_RX_CTRL_DROP ,"RxCtrlDrop" ), -MIB_DESC (1 ,MT7530_PORT_MIB_RX_INGRESS_DROP ,"RxIngressDrop" ), -MIB_DESC (1 ,MT7530_PORT_MIB_RX_ARL_DROP ,"RxArlDrop" ), +MIB_DESC (MT7530_MIB_TX_DROP ,-1 ,"TxDrop" ), +MIB_DESC (MT7530_MIB_TX_CRC_ERR ,-1 ,"TxCrcErr" ),
[ ... ]
Quoted 27 lines
drivers/net/dsa/mt7530.c +1
-15@@ -744,34 +796,22 @@ mt7530_get_strings(struct dsa_switch *ds, int port, u32 stringset,ethtool_puts (&data, mt7530_mib[i].name); } -static void -mt7530_read_port_stats (struct mt7530_priv *priv,int port, -u32 offset,u8 size,uint64_t *data) -{ -u32 val, reg =MT7530_PORT_MIB_COUNTER (port) + offset; - - val =mt7530_read (priv, reg); - *data = val; - -if (size ==2 ) { - val =mt7530_read (priv, reg +4 ); - *data |= (u64 )val <<32 ; - } -} -static void mt7530_get_ethtool_stats (struct dsa_switch *ds,int port,uint64_t *data) {struct mt7530_priv *priv = ds->priv;const struct mt7530_mib_desc *mib; +struct mt7530_lib_priv *lib_priv;int i;
drivers/net/dsa/mt7530.c mt7530_get_strings(struct dsa_switch *ds, int port, u32 stringset, · line 814
Quoted 10 lines
drivers/net/dsa/mt7530.c +4
-2+ lib_priv = &priv->lib_priv;for (i =0 ; i <ARRAY_SIZE (mt7530_mib); i++) { mib = &mt7530_mib[i]; -mt7530_read_port_stats (priv, port, mib->offset, mib->size, - data + i); +mt7530_lib_read_port_stats (lib_priv->fields[mib->field_low], + lib_priv->fields[mib->field_high], + port, data + i);
[Severity: Critical]
Will this cause an out-of-bounds read and kernel panic?
The MIB_DESC macro initializes field_high to -1 for 32-bit single-register counters.
In mt7530_get_ethtool_stats(), this unconditionally accesses lib_priv->fields[-1], which evaluates to the non-NULL struct regmap pointer.
Passing this invalid regmap_field pointer to mt7530_lib_read_port_stats() will crash when regmap_fields_read() attempts to dereference it.
Quoted 3 lines
drivers/net/dsa/mt7530.c +0
-0} }
[ ... ]
Quoted 7 lines
drivers/net/dsa/mt7530.c +7
-0+static const struct mt7530_rmon_hist mt7530_rmon_hist_info = { + .ranges_fields = (unsigned int []){ +MT7530_MIB_TX_PKT_SZ_64 , +MT7530_MIB_TX_PKT_SZ_65_TO_127 , +MT7530_MIB_TX_PKT_SZ_128_TO_255 , +MT7530_MIB_TX_PKT_SZ_256_TO_511 , +MT7530_MIB_TX_PKT_SZ_512_TO_1023 ,
drivers/net/dsa/mt7530.c static const struct ethtool_rmon_hist_range mt7530_rmon_ranges[] = { · line 861
Quoted 10 lines
drivers/net/dsa/mt7530.c +10
-0+ MT7530_MIB_TX_PKT_SZ_1024_TO_MAX, + }, + .ranges_tx_fields = (unsigned int []){ +MT7530_MIB_RX_PKT_SZ_64 , +MT7530_MIB_RX_PKT_SZ_65_TO_127 , +MT7530_MIB_RX_PKT_SZ_128_TO_255 , +MT7530_MIB_RX_PKT_SZ_256_TO_511 , +MT7530_MIB_RX_PKT_SZ_512_TO_1023 , +MT7530_MIB_RX_PKT_SZ_1024_TO_MAX , + },
[Severity: Medium]
Could these arrays be swapped?
The ranges_fields array is populated with TX macros, while ranges_tx_fields uses RX macros.
When these are mapped later in mt7530_lib_get_rmon_stats(), it appears to report TX stats as RX and vice versa.
Quoted 7 lines
drivers/net/dsa/mt7530.c +4
-0+ .ranges = mt7530_rmon_ranges, + .num_ranges = ARRAY_SIZE(mt7530_rmon_ranges) - 1, +}; +static void mt7530_get_rmon_stats (struct dsa_switch *ds,int port,struct ethtool_rmon_stats *rmon_stats,const struct ethtool_rmon_hist_range **ranges)
[ ... ]
Quoted 10 lines
static void mt7530_read_port_stats64(struct
mt7530_priv*priv, int port,drivers/net/dsa/mt7530.c +1
-0struct rtnl_link_stats64 *storage) { +struct mt7530_lib_priv *lib_priv = &priv->lib_priv;uint64_t data;/* MIB counter doesn't provide a FramesTransmittedOK but instead @@ -903,38 +884,40 @@ static void mt7530_read_port_stats64(struct mt7530_priv *priv, int port,* To simulate a global frame counter, read Unicast and addition Multicast * and Broadcast later
drivers/net/dsa/mt7530.c static void mt7530_read_port_stats64(struct mt7530_priv *priv, int port, · line 891
Quoted 10 lines
drivers/net/dsa/mt7530.c +4
-4*/ -mt7530_read_port_stats (priv, port,MT7530_PORT_MIB_RX_UNICAST ,1 , - &storage->rx_packets); -mt7530_read_port_stats (priv, port,MT7530_PORT_MIB_RX_MULTICAST ,1 , - &storage->multicast); +mt7530_lib_read_port_stats (lib_priv->fields[MT7530_MIB_RX_UNICAST ], +NULL , port, &storage->rx_packets); +mt7530_lib_read_port_stats (lib_priv->fields[MT7530_MIB_RX_MULTICAST ], +NULL , port, &data); storage->rx_packets += storage->multicast;
[Severity: Medium]
Does this correctly track multicast packets?
The counter is read into the local variable data, but then the code adds storage->multicast to rx_packets.
Since storage->multicast is never assigned the read value, it seems the multicast packet count is lost.
Quoted 5 lines
drivers/net/dsa/mt7530.c +2
-2-mt7530_read_port_stats (priv, port,MT7530_PORT_MIB_RX_BROADCAST ,1 , - &data); +mt7530_lib_read_port_stats (lib_priv->fields[MT7530_MIB_RX_BROADCAST ], +NULL , port, &data); storage->rx_packets += data;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
PATCH v19 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/Kconfig | 9 + drivers/net/dsa/Makefile | 1 + drivers/net/dsa/an8855.c | 1682 ++++++++++++++++++++++++++++++++++ drivers/net/dsa/an8855.h | 753 +++++++++++++++ drivers/net/dsa/mt7530-lib.c | 66 +- drivers/net/dsa/mt7530-lib.h | 21 + 6 files changed, 2512 insertions(+), 20 deletions(-) create mode 100644 drivers/net/dsa/an8855.c create mode 100644 drivers/net/dsa/an8855.h
drivers/net/dsa/Kconfig +9 -0
@@ -24,6 +24,15 @@ config NET_DSA_LOOP This enables support for a fake mock-up switch chip which exercises the DSA APIs. +config NET_DSA_AN8855 + tristate "Airoha AN8855 Ethernet switch support" + depends on MFD_AIROHA_AN8855 || COMPILE_TEST + depends on NET_DSA + select NET_DSA_TAG_MTK + help + This enables support for the Ethernet switch inside the + Airoha AN8855 chip. + source "drivers/net/dsa/hirschmann/Kconfig" source "drivers/net/dsa/lantiq/Kconfig"
drivers/net/dsa/Makefile +1 -0
@@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_NET_DSA_AN8855) += an8855.o obj-$(CONFIG_NET_DSA_BCM_SF2) += bcm-sf2.o bcm-sf2-objs := bcm_sf2.o bcm_sf2_cfp.o obj-$(CONFIG_NET_DSA_LOOP) += dsa_loop.o
drivers/net/dsa/an8855.c new file +1682 -0
1,682 lines not on this page · raw message
drivers/net/dsa/an8855.h new file +753 -0
753 lines not on this page · raw message
drivers/net/dsa/mt7530-lib.c +46 -20
126 lines not on this page · raw message
drivers/net/dsa/mt7530-lib.h +21 -0
@@ -168,6 +168,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,
@@ -179,6 +181,7 @@ enum mt7530_regmap_field {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,
@@ -206,6 +209,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,
@@ -228,8 +232,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,
@@ -248,11 +257,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, };
@@ -389,6 +408,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.53.0
[email protected]
AI reviewRe: [PATCH net-next v19 10/10] net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver
Thank you for your contribution! Sashiko AI review found 10 potential issue(s) to consider: - [High] Unprotected access to `dev->phydev` and inverted logic in `an8855_phylink_mac_enable_tx_lpi`.…
Thank you for your contribution! Sashiko AI review found 10 potential issue(s) to consider:
- [High] Unprotected access to dev->phydev and inverted logic in an8855_phylink_mac_enable_tx_lpi.
- [High] FDB flush operations run without the required register mutex, racing with concurrent FDB interactions.
- [High] Incorrect maths logic in an8855_set_ageing_time leads to register field overflow and heavily misconfigured switch aging time.
- [High] Failure to propagate the error code in an8855_port_fdb_dump() leads to silent dump truncations and spurious infinite looping.
- [High] Missing and incorrectly mapped regmap_field entries lead to uninitialized pointers, causing a kernel crash when configuring port mirroring or reading statistics.
- [High] Ignoring the return value of regmap_read() leads to using uninitialized stack variables.
- [High] Torn updates on the PMCR register due to bypassed regmap locking.
- [Medium] TX flow control enablement incorrectly checks rx_pause instead of tx_pause.
- [Medium] The driver duplicates standard UAPI networking statistics into driver-private ethtool -S strings.
- [Medium] Writing an undocumented, invalid Jumbo Frame register value for MTUs larger than 12K.
--
--- Patch [10]: [PATCH net-next v19 10/10] net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver --- commit 95a1bba0a8e59d58da6f98ffbe49372121797adc
Author: Christian Marangi <[email protected]>
net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver
Add Airoha AN8855 5-Port Gigabit DSA switch. Switch can support 10M, 100M, 1Gb, 2.5G and 5G Ethernet Speed but 5G is currently error out as it's not currently supported as requires additional configuration for the PCS.
Quoted 6 lines
drivers/net/dsa/an8855.c new file +0
-0@@ -0,0 +1,1682 @@
[ ... ]
Quoted 1 line
+static const struct
mt7530_reg_fieldan8855_fields[] = {
[ ... ]
Quoted 5 lines
drivers/net/dsa/an8855.c new file +5
-0+ { MT7530_MIB_TX_PKT_SZ_512_TO_1023, REG_FIELD_ID(AN8855_PORT_MIB_TX_PKT_SZ_512_TO_1023, 0, 32, AN8855_NUM_PORTS, 0x200) }, + { AN8855_MIB_TX_PKT_SZ_1024_TO_1518, REG_FIELD_ID(AN8855_PORT_MIB_TX_PKT_SZ_1024_TO_1518, 0, 32, AN8855_NUM_PORTS, 0x200) }, + { AN8855_MIB_TX_PKT_SZ_1519_TO_MAX, REG_FIELD_ID(AN8855_PORT_MIB_TX_PKT_SZ_1519_TO_MAX, 0, 32, AN8855_NUM_PORTS, 0x200) }, + { MT7530_MIB_TX_BYTES_LOW, REG_FIELD_ID(AN8855_PORT_MIB_TX_BYTES_LOW, 0, 32, AN8855_NUM_PORTS, 0x200) }, + { MT7530_MIB_TX_BYTES_HIGH, REG_FIELD_ID(AN8855_PORT_MIB_TX_BYTES_HIGH, 0, 32, AN8855_NUM_PORTS, 0x200) },
[ ... ]
drivers/net/dsa/an8855.c line 157
Quoted 5 lines
drivers/net/dsa/an8855.c new file +5
-0+ { MT7530_MIB_RX_PKT_SZ_256_TO_511, REG_FIELD_ID(AN8855_PORT_MIB_RX_PKT_SZ_256_TO_511, 0, 32, AN8855_NUM_PORTS, 0x200) }, + { MT7530_MIB_RX_PKT_SZ_512_TO_1023, REG_FIELD_ID(AN8855_PORT_MIB_RX_PKT_SZ_512_TO_1023, 0, 32, AN8855_NUM_PORTS, 0x200) }, + { AN8855_MIB_TX_PKT_SZ_1024_TO_1518, REG_FIELD_ID(AN8855_PORT_MIB_RX_PKT_SZ_1024_TO_1518, 0, 32, AN8855_NUM_PORTS, 0x200) }, + { AN8855_MIB_TX_PKT_SZ_1519_TO_MAX, REG_FIELD_ID(AN8855_PORT_MIB_RX_PKT_SZ_1519_TO_MAX, 0, 32, AN8855_NUM_PORTS, 0x200) }, + { MT7530_MIB_RX_BYTES_LOW, REG_FIELD_ID(AN8855_PORT_MIB_RX_BYTES_LOW, 0, 32, AN8855_NUM_PORTS, 0x200) },
[Severity: High]
Are there missing or incorrectly mapped regmap_field entries here?
The array omits required mappings for MT7530_MIRROR_EN and MT7530_MIRROR_PORT. Also, it looks like AN8855_MIB_TX_PKT_SZ_1024_TO_1518 is mapped twice, once here to an RX register, leaving the corresponding RX slot uninitialized.
Could this result in a NULL pointer dereference when userspace queries ethtool/RMON statistics or configures mirroring?
drivers/net/dsa/an8855.c line 168
Quoted 11 lines
drivers/net/dsa/an8855.c new file +11
-0+ { MT7530_MIB_RX_BYTES_HIGH, REG_FIELD_ID(AN8855_PORT_MIB_RX_BYTES_HIGH, 0, 32, AN8855_NUM_PORTS, 0x200) }, + { MT7530_MIB_RX_CTRL_DROP, REG_FIELD_ID(AN8855_PORT_MIB_RX_CTRL_DROP, 0, 32, AN8855_NUM_PORTS, 0x200) }, + { MT7530_MIB_RX_INGRESS_DROP, REG_FIELD_ID(AN8855_PORT_MIB_RX_INGRESS_DROP, 0, 32, AN8855_NUM_PORTS, 0x200) }, + { MT7530_MIB_RX_ARL_DROP, REG_FIELD_ID(AN8855_PORT_MIB_RX_ARL_DROP, 0, 32, AN8855_NUM_PORTS, 0x200) }, +}; + +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: Medium]
Does this array duplicate standard UAPI networking statistics into driver private ethtool strings?
Standard practice suggests that statistics with existing standard UAPIs (like TxDrop, TxCrcErr, etc.) should use standard interfaces instead of being manually exposed via ethtool -S.
Could these standard counters be removed to prevent bloating the ethtool interface?
[ ... ]
Quoted 13 lines
drivers/net/dsa/an8855.c new file +13
-0+static void an8855_port_fast_age (struct dsa_switch *ds,int port) +{ +struct an8855_priv *priv = ds->priv; +int ret; + +/* Set to clean Dynamic entry */ + ret =regmap_write (priv->regmap,AN8855_ATA2 ,AN8855_ATA2_TYPE ); +if (ret) { +dev_err (priv->ds->dev,"failed to update ATA2 reg: %d\n" , ret); +return ; + } + +/* Set Port */
drivers/net/dsa/an8855.c line 234
Quoted 10 lines
drivers/net/dsa/an8855.c new file +10
-0+ ret =regmap_write (priv->regmap,AN8855_ATWD2 , +FIELD_PREP (AN8855_ATWD2_PORT ,BIT (port))); +if (ret) { +dev_err (priv->ds->dev,"failed to update ATWD2 reg: %d\n" , ret); +return ; + } + +/* Flush Dynamic entry at port */ + ret =mt7530_lib_fdb_cmd (&priv->lib_priv,MT7530_FDB_FLUSH , +AN8855_FDB_MAT_MAC_TYPE_PORT ,NULL );
[Severity: High]
Are these indirect FDB register writes vulnerable to concurrent access?
We modify shared indirect FDB registers (AN8855_ATA2 and AN8855_ATWD2) and then trigger mt7530_lib_fdb_cmd without holding the priv->reg_mutex synchronization lock here.
Could concurrent FDB reads or writes from other CPU threads overwrite these indirect registers mid-flight?
Quoted 4 lines
drivers/net/dsa/an8855.c new file +4
-0+if (ret) +dev_err (priv->ds->dev,"failed to send FDB cmd: %d\n" , ret); +} +
[ ... ]
Quoted 5 lines
drivers/net/dsa/an8855.c new file +5
-0+static int an8855_set_ageing_time (struct dsa_switch *ds,unsigned int msecs) +{ +struct an8855_priv *priv = ds->priv; +u32 age_count, age_unit, val; +
drivers/net/dsa/an8855.c line 274
Quoted 10 lines
drivers/net/dsa/an8855.c new file +10
-0+/* Convert msec in AN8855_L2_AGING_MS_CONSTANT counter */ + val = msecs /AN8855_L2_AGING_MS_CONSTANT ; +/* Derive the count unit */ + age_unit = val /FIELD_MAX (AN8855_AGE_UNIT ); +/* Get the count in unit, age_unit is always incremented by 1 internally */ + age_count = val / (age_unit +1 ); + + return regmap_update_bits(priv->regmap, AN8855_AAC, + AN8855_AGE_CNT | AN8855_AGE_UNIT, + FIELD_PREP(AN8855_AGE_CNT, age_count) |
[Severity: High]
Is the mathematical logic deriving age_unit and age_count correct?
By dividing val by FIELD_MAX(AN8855_AGE_UNIT), age_count can reach around 2042. However, AN8855_AGE_CNT is a 9-bit field with a maximum of 511.
Did you intend to swap the target division boundaries, dividing by FIELD_MAX(AN8855_AGE_CNT) instead, to prevent register field overflow during FIELD_PREP?
Quoted 3 lines
drivers/net/dsa/an8855.c new file +3
-0+ FIELD_PREP(AN8855_AGE_UNIT, age_unit)); +} +
[ ... ]
Quoted 3 lines
drivers/net/dsa/an8855.c new file +3
-0+static int an8855_port_fdb_dump (struct dsa_switch *ds,int port, +dsa_fdb_dump_cb_t *cb,void *data) +{
[ ... ]
Quoted 18 lines
drivers/net/dsa/an8855.c new file +18
-0+ do { + /* From response get the number of banks to read, exit if 0 */ + banks = FIELD_GET(AN8855_ATC_HIT, rsp); + 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))) + continue; + + /* Select bank entry index */ + ret = regmap_write(priv->regmap, AN8855_ATRDS,
drivers/net/dsa/an8855.c line 363
Quoted 10 lines
drivers/net/dsa/an8855.c new file +10
-0+ 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); + + ret =cb (_fdb.mac, _fdb.vid, _fdb.noarp, data); +if (ret <0 ) +break ;
[Severity: High]
Does this inner loop break correctly handle error propagation?
If the userspace netlink buffer fills, cb() returns a negative error code and breaks the inner loop.
However, the outer loop fails to check this error, and calls mt7530_lib_fdb_cmd() which overwrites ret with 0. Will this cause the driver to spin endlessly until AN8855_NUM_FDB_RECORDS is reached and silently return 0, truncating the FDB dump?
Quoted 12 lines
drivers/net/dsa/an8855.c new file +12
-0+ } + +/* Stop if reached max FDB number */ +if (count >=AN8855_NUM_FDB_RECORDS ) +break ; + +/* Read next bank */ + ret =mt7530_lib_fdb_cmd (&priv->lib_priv,MT7530_FDB_NEXT , +AN8855_FDB_MAT_MAC_PORT , &rsp); +if (ret <0 ) +break ; + }while (true);
[ ... ]
drivers/net/dsa/an8855.c line 433
Quoted 6 lines
drivers/net/dsa/an8855.c new file +6
-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]
Can this MT7530 library function safely handle AN8855 jumbo frame configuration?
The mt7530_lib_port_change_mtu function calculates Jumbo codes using a linear formula. However, for the AN8855, the jumbo mapping is non-linear past 9K according to the header definitions (e.g., 12K is 0xa, 15K is 0xb).
If a user configures an MTU larger than 12K, could this write an undocumented, invalid Jumbo Frame register value?
Quoted 2 lines
drivers/net/dsa/an8855.c new file +2
-0+} +
[ ... ]
Quoted 8 lines
drivers/net/dsa/an8855.c new file +8
-0+static void an8855_phylink_get_caps (struct dsa_switch *ds,int port, +struct phylink_config *config) +{ +struct an8855_priv *priv = ds->priv; +u32 reg; +int ret; + +switch (port) {
[ ... ]
drivers/net/dsa/an8855.c line 819
Quoted 12 lines
drivers/net/dsa/an8855.c new file +12
-0+ config->mac_capabilities =MAC_ASYM_PAUSE |MAC_SYM_PAUSE | +MAC_10 |MAC_100 |MAC_1000FD |MAC_2500FD ; + + ret =regmap_read (priv->regmap,AN8855_CKGCR , ®); +if (ret) +dev_err (ds->dev,"failed to read EEE LPI timer\n" ); + +memcpy (config->lpi_interfaces, config->supported_interfaces, +sizeof (config->lpi_interfaces)); + config->lpi_capabilities =MAC_100FD |MAC_1000FD ; +/* Global LPI TXIDLE Threshold, default 60ms (unit 2us) */ + config->lpi_timer_default = FIELD_GET(AN8855_LPI_TXIDLE_THD_MASK, reg) *
[Severity: High]
Is the uninitialized stack variable reg used if the regmap_read above fails?
The code logs an error but does not return early. Could this result in configuring the LPI timers with uninitialized stack garbage?
Quoted 5 lines
drivers/net/dsa/an8855.c new file +5
-0+AN8855_TX_LPI_UNIT ; + + config->eee_enabled_default = true; +} +
[ ... ]
drivers/net/dsa/an8855.c line 854
Quoted 11 lines
drivers/net/dsa/an8855.c new file +11
-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; + +regmap_read (priv->regmap,AN8855_PMCR_P (port), ®);
[Severity: High]
What happens if this regmap_read fails?
The return value is completely ignored. If it fails, the uninitialized reg variable will be bitwise-modified and written directly back into the MAC control register.
Quoted 7 lines
drivers/net/dsa/an8855.c new file +7
-0+if (phylink_autoneg_inband (mode)) { + reg &= ~AN8855_PMCR_FORCE_MODE ; + }else { + reg |=AN8855_PMCR_FORCE_MODE |AN8855_PMCR_FORCE_LNK ; + + reg &= ~AN8855_PMCR_FORCE_SPEED ; +switch (speed) {
[ ... ]
drivers/net/dsa/an8855.c line 888
Quoted 10 lines
drivers/net/dsa/an8855.c new file +10
-0+ reg &= ~AN8855_PMCR_FORCE_FDX ; +if (duplex ==DUPLEX_FULL ) + reg |=AN8855_PMCR_FORCE_FDX ; + + reg &= ~AN8855_PMCR_RX_FC_EN ; +if (rx_pause ||dsa_port_is_cpu (dp)) + reg |=AN8855_PMCR_RX_FC_EN ; + + reg &= ~AN8855_PMCR_TX_FC_EN ; +if (rx_pause ||dsa_port_is_cpu (dp))
[Severity: Medium]
Should this condition check tx_pause instead of rx_pause?
When enabling AN8855_PMCR_TX_FC_EN, the code ignores the tx_pause argument provided by phylink, which might break TX flow control in asymmetric pause setups.
drivers/net/dsa/an8855.c line 894
Quoted 6 lines
drivers/net/dsa/an8855.c new file +6
-0+ reg |=AN8855_PMCR_TX_FC_EN ; + } + + reg |=AN8855_PMCR_TX_EN |AN8855_PMCR_RX_EN ; + +regmap_write (priv->regmap,AN8855_PMCR_P (port), reg);
[Severity: High]
Does this read-modify-write sequence bypass regmap locking?
Because the atomic regmap lock is dropped between the regmap_read at the start of the function and this regmap_write, could concurrent modifications (like an8855_phylink_mac_enable_tx_lpi using regmap_set_bits) be irreversibly overwritten?
Quoted 2 lines
drivers/net/dsa/an8855.c new file +2
-0+} +
[ ... ]
Quoted 22 lines
drivers/net/dsa/an8855.c new file +22
-0+static int an8855_phylink_mac_enable_tx_lpi (struct phylink_config *config, +u32 timer,bool tx_clock_stop) +{ +struct dsa_port *dp, *other_dp; +struct an8855_priv *priv; +struct dsa_switch *ds; +int port; +u32 val; +int ret; + + dp =dsa_phylink_to_port (config); + port = dp->index; + ds = dp->ds; + priv = ds->priv; + +/* TX LPI timer is global, find the highest timer +* across all port. +* If requested timer is 0, set to enter LPI immediately +* for the single port. +*/ +if (timer) { +dsa_switch_for_each_user_port (other_dp, ds) {
drivers/net/dsa/an8855.c line 949
Quoted 10 lines
drivers/net/dsa/an8855.c new file +10
-0+struct phy_device *phydev; +struct net_device *dev; + +if (other_dp == dp) +continue ; + + dev = other_dp->user; + phydev = dev->phydev; + +if (timer > phydev->eee_cfg.tx_lpi_timer)
[Severity: High]
Can this lead to a NULL pointer dereference?
The code unconditionally dereferences dev and phydev without checking if the port is bound to a network device or if a PHY is attached (e.g., fixed-link or disabled ports).
Additionally, does the condition timer > phydev->eee_cfg.tx_lpi_timer use inverted logic? It replaces timer when it is strictly greater, finding the lowest timer across ports instead of the highest as documented.
Quoted 5 lines
drivers/net/dsa/an8855.c new file +5
-0+ timer = phydev->eee_cfg.tx_lpi_timer; + } + + timer /=AN8855_TX_LPI_UNIT ; +if (FIELD_FIT (AN8855_LPI_TXIDLE_THD_MASK , timer))
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
Jakub Kicinski
maintainerQuoted 1 line · On Tue, 28 Jul 2026 17:48:27 +0200 Christian Marangi wrote:
This series add the initial support for the Airoha AN8855 Switch.
This series did not apply at the time of posting.
Looks like Sashiko/Gemini applied and reviewed it against net/main so you should check if it has anything worth addressing to say: