Skip to contentSkip to conversation

net: dsa: Add Airoha AN8855 support

PATCH Superseded Christian Marangi 5 participants 24 messages Aug 17 – Aug 27

Subsystems (8)

v20 of 25 Superseded Latest is v25 →

lore
Share & tools
lore
#0 lore raw

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

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

Daniel Golle (1):
net: dsa: mt7530: move MDIO bus locking into regmap

 .../bindings/mfd/airoha,an8855.yaml           |  175 ++
 .../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                   |  523 +++++
 drivers/net/dsa/Kconfig                       |   13 +
 drivers/net/dsa/Makefile                      |    2 +
 drivers/net/dsa/an8855.c                      | 1716 +++++++++++++++++
 drivers/net/dsa/an8855.h                      |  753 ++++++++
 drivers/net/dsa/mt7530-lib.c                  | 1132 +++++++++++
 drivers/net/dsa/mt7530-lib.h                  |  406 ++++
 drivers/net/dsa/mt7530-mdio.c                 |   13 +-
 drivers/net/dsa/mt7530-mmio.c                 |    4 +
 drivers/net/dsa/mt7530.c                      | 1358 +++----------
 drivers/net/dsa/mt7530.h                      |  258 +--
 drivers/net/phy/Kconfig                       |    6 +
 drivers/net/phy/Makefile                      |    1 +
 drivers/net/phy/air_an8855.c                  |  275 +++
 include/net/dsa.h                             |    2 +
 net/dsa/Kconfig                               |   11 +
 net/dsa/Makefile                              |    2 +-
 net/dsa/tag_mtk.c                             |   36 +-
 24 files changed, 5635 insertions(+), 1250 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
#1 lore raw

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

Document support for Airoha AN8855 5-port Gigabit Switch.

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

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

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

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

Document support for Airoha AN8855 5-port Gigabit Switch.

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

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
#3 lore raw

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

In reply to Christian Marangi

Document support for AN8855 Switch Internal PHY.

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

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

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

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

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

Document support for AN8855 Switch Internal PHY.

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

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

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

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

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

In reply to Christian Marangi

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

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

---
 .../bindings/mfd/airoha,an8855.yaml           | 175 ++++++++++++++++++
 1 file changed, 175 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/airoha,an8855.yaml
Documentation/devicetree/bindings/mfd/airoha,an8855.yaml new file +175 -0
new file mode 100644
index 000000000000..472da8384a30
@@ -0,0 +1,175 @@
+# 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:
+    type: object
+    $ref: /schemas/net/mdio.yaml#
+    description: MDIO exposed by the Airoha AN8855 SoC
+    unevaluatedProperties: true
+
+required:
+  - compatible
+  - reg
+  - mdio
+  - ethernet-switch
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+
+    mdio {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        soc@1 {
+            compatible = "airoha,an8855";
+            reg = <1>;
+
+            reset-gpios = <&pio 39 GPIO_ACTIVE_HIGH>;
+
+            efuse {
+                compatible = "airoha,an8855-efuse";
+
+                #nvmem-cell-cells = <0>;
+
+                nvmem-layout {
+                    compatible = "fixed-layout";
+                    #address-cells = <1>;
+                    #size-cells = <1>;
+
+                    shift_sel_port0_tx_a: shift-sel-port0-tx-a@c {
+                       reg = <0xc 0x4>;
+                    };
+
+                    shift_sel_port0_tx_b: shift-sel-port0-tx-b@10 {
+                        reg = <0x10 0x4>;
+                    };
+
+                    shift_sel_port0_tx_c: shift-sel-port0-tx-c@14 {
+                        reg = <0x14 0x4>;
+                    };
+
+                    shift_sel_port0_tx_d: shift-sel-port0-tx-d@18 {
+                       reg = <0x18 0x4>;
+                    };
+
+                    shift_sel_port1_tx_a: shift-sel-port1-tx-a@1c {
+                        reg = <0x1c 0x4>;
+                    };
+
+                    shift_sel_port1_tx_b: shift-sel-port1-tx-b@20 {
+                        reg = <0x20 0x4>;
+                    };
+
+                    shift_sel_port1_tx_c: shift-sel-port1-tx-c@24 {
+                       reg = <0x24 0x4>;
+                    };
+
+                    shift_sel_port1_tx_d: shift-sel-port1-tx-d@28 {
+                        reg = <0x28 0x4>;
+                    };
+                };
+            };
+
+            ethernet-switch {
+                compatible = "airoha,an8855-switch";
+
+                ports {
+                    #address-cells = <1>;
+                    #size-cells = <0>;
+
+                    port@0 {
+                        reg = <0>;
+                        label = "lan1";
+                        phy-mode = "internal";
+                        phy-handle = <&internal_phy1>;
+                    };
+
+                    port@1 {
+                        reg = <1>;
+                        label = "lan2";
+                        phy-mode = "internal";
+                        phy-handle = <&internal_phy2>;
+                    };
+
+                    port@5 {
+                        reg = <5>;
+                        label = "cpu";
+                        ethernet = <&gmac0>;
+                        phy-mode = "2500base-x";
+
+                        fixed-link {
+                            speed = <2500>;
+                            full-duplex;
+                            pause;
+                        };
+                    };
+                };
+            };
+
+            mdio {
+                #address-cells = <1>;
+                #size-cells = <0>;
+
+                internal_phy1: ethernet-phy@1 {
+                  compatible = "ethernet-phy-idc0ff.0410",
+                               "ethernet-phy-ieee802.3-c22";
+                  reg = <1>;
+
+                  nvmem-cells = <&shift_sel_port0_tx_a>,
+                      <&shift_sel_port0_tx_b>,
+                      <&shift_sel_port0_tx_c>,
+                      <&shift_sel_port0_tx_d>;
+                  nvmem-cell-names = "tx_a", "tx_b", "tx_c", "tx_d";
+                };
+
+                internal_phy2: ethernet-phy@2 {
+                  compatible = "ethernet-phy-idc0ff.0410",
+                               "ethernet-phy-ieee802.3-c22";
+                  reg = <2>;
+
+                  nvmem-cells = <&shift_sel_port1_tx_a>,
+                      <&shift_sel_port1_tx_b>,
+                      <&shift_sel_port1_tx_c>,
+                      <&shift_sel_port1_tx_d>;
+                  nvmem-cell-names = "tx_a", "tx_b", "tx_c", "tx_d";
+                };
+            };
+        };
+    };
Signature · 1 line
2.53.0
#6 lore raw

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

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Low] The `mdio` node explicitly sets `unevaluatedProperties: true`, disabling strict schema validation…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Low] The mdio node explicitly sets unevaluatedProperties: true, disabling strict schema validation for its contents.
- [Low] The reset-gpios property lacks an item count constraint.
--

--- Patch [3]: [PATCH net-next v20 03/10] dt-bindings: mfd: Document support for Airoha AN8855 Switch SoC --- commit becec7ba9d50daec0a4bb4e2976f7f7fc33b268e
Author: Christian Marangi <[email protected]>

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

This commit documents support for the Airoha AN8855 Switch SoC. The SoC exposes various peripherals including an Ethernet Switch, an NVMEM provider, and Ethernet PHYs.

Quoted 11 lines
Documentation/devicetree/bindings/mfd/airoha,an8855.yaml new file +5 -0
new file mode 100644
index 0000000000000..472da8384a30e
@@ -0,0 +1,175 @@
+# 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#

[ ... ]

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 property have a maxItems constraint? The core gpios.yaml schema doesn't restrict the number of array elements.

Without maxItems: 1, could a device tree incorrectly specify multiple reset lines and silently pass validation?

Quoted 6 lines
Documentation/devicetree/bindings/mfd/airoha,an8855.yaml new file +6 -0
+
+  efuse:
+    type: object
+    $ref: /schemas/nvmem/airoha,an8855-efuse.yaml
+    description: EFUSE exposed by the Airoha AN8855 SoC
+

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

Quoted 10 lines
Documentation/devicetree/bindings/mfd/airoha,an8855.yaml new file +10 -0
+  ethernet-switch:
+    type: object
+    $ref: /schemas/net/dsa/airoha,an8855-switch.yaml
+    description: Switch exposed by the Airoha AN8855 SoC
+
+  mdio:
+    type: object
+    $ref: /schemas/net/mdio.yaml#
+    description: MDIO exposed by the Airoha AN8855 SoC
+    unevaluatedProperties: true

[Severity: Low]
Should this be unevaluatedProperties: false?

The core mdio.yaml schema sets additionalProperties: true, so by setting
unevaluatedProperties: true locally, does this schema actively permit undocumented or misspelled properties in the mdio node to silently pass validation?

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

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

In reply to Christian Marangi

Add 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 | 523 ++++++++++++++++++++++++++++++++++++
 3 files changed, 537 insertions(+)
 create mode 100644 drivers/mfd/airoha-an8855.c
drivers/mfd/Kconfig +13 -0
index 763ce6a34782..4d763ed6e53d 100644
@@ -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
index dd4bb7e77c33..00eab2c9f55f 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_MFD_88PM860X)	+= 88pm860x.o
 obj-$(CONFIG_MFD_88PM800)	+= 88pm800.o 88pm80x.o
 obj-$(CONFIG_MFD_88PM805)	+= 88pm805.o 88pm80x.o
 obj-$(CONFIG_MFD_88PM886_PMIC)	+= 88pm886.o
+obj-$(CONFIG_MFD_AIROHA_AN8855)	+= airoha-an8855.o
 obj-$(CONFIG_MFD_ACT8945A)	+= act8945a.o
 obj-$(CONFIG_MFD_SM501)		+= sm501.o
 obj-$(CONFIG_ARCH_BCM2835)	+= bcm2835-pm.o
drivers/mfd/airoha-an8855.c new file +523 -0

523 lines not on this page · raw message

Signature · 1 line
2.53.0
#8 lore raw

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

Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider: - [High] Missing 'select REGMAP' dependency for MDIO_REGMAP and devm_regmap_init(). - [High] Incorrect…

Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:
- [High] Missing 'select REGMAP' dependency for MDIO_REGMAP and devm_regmap_init().
- [High] Incorrect reset GPIO polarity logic actively leaves the switch in a reset state.
- [High] PHY page state is corrupted when switch regmap accesses interleave with PHY paged accesses.
- [High] Unprotected call to 'an8855_mii_set_page' in probe triggers a lockdep splat and data race.
- [Medium] Signed integer overflow when bit-shifting a 16-bit variable.
- [Medium] Duplicate virtual MII bus IDs if multiple switches exist.
- [Low] Selection of non-existent Kconfig symbol 'MDIO_DEVICE'.
--

--- Patch [4]: [PATCH net-next v20 04/10] mfd: an8855: Add support for Airoha AN8855 Switch MFD --- commit 302d7f55459ecc6ab21029f136b77629fdc1e7cb
Author: Christian Marangi <[email protected]>
Subject: mfd: an8855: Add support for Airoha AN8855 Switch MFD

This commit adds core MFD support for the Airoha AN8855 switch, registering a DSA switch and an NVMEM provider. It implements an MDIO regmap driver for the internal PHYs to handle the dual usage of PHYs as both PHY and switch accessors.

drivers/mfd/Kconfig config MFD_ALTERA_SYSMGR · line 60

Quoted 12 lines
drivers/mfd/Kconfig +4 -0
index 763ce6a34782b..4d763ed6e53d5 100644
@@ -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

[Severity: Low]
Is MDIO_DEVICE a valid Kconfig symbol in the tree, or was it intended to be used as a C macro? Selecting a non-existent symbol has no effect and is silently ignored by Kconfig.

[Severity: High]
Does this driver also need to select REGMAP?

Since the driver relies heavily on the regmap subsystem and explicitly calls devm_regmap_init(), failing to select it will cause the regmap APIs to fallback to -EINVAL stubs if CONFIG_REGMAP isn't enabled by another subsystem.

Quoted 2 lines
drivers/mfd/Kconfig +2 -0
+	select MDIO_REGMAP
+	depends on NETDEVICES && OF

[ ... ]

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

[ ... ]

Quoted 7 lines
drivers/mfd/airoha-an8855.c new file +7 -0
+static int an8855_mii_set_page(struct an8855_core_priv *priv, u8 addr,
+			       u8 page) __must_hold(&priv->bus->mdio_lock)
+{
+	struct mii_bus *bus = priv->bus;
+	int ret;
+
+	ret = __mdiobus_write(bus, addr, AN8855_PHY_SELECT_PAGE, page);

[ ... ]

Quoted 3 lines
drivers/mfd/airoha-an8855.c new file +3 -0
+static int an8855_mii_read32(struct mii_bus *bus, u8 phy_id, u32 reg,
+			     u32 *val) __must_hold(&bus->mdio_lock)
+{

[ ... ]

drivers/mfd/airoha-an8855.c line 123

Quoted 7 lines
drivers/mfd/airoha-an8855.c new file +7 -0
+	lo = __mdiobus_read(bus, phy_id, AN8855_PBUS_RD_DATA_LOW);
+	if (lo < 0) {
+		ret = lo;
+		goto err;
+	}
+
+	*val = ((u16)hi << 16) | ((u16)lo & 0xffff);

[Severity: Medium]
Could this bit-shift cause a signed integer overflow? The cast to (u16) causes integer promotion to a signed int. If the highest bit of 'hi' is set, shifting it by 16 bits overflows. Casting to u32 before the shift would avoid this.

Quoted 3 lines
drivers/mfd/airoha-an8855.c new file +3 -0
+
+	return 0;
+err:

[ ... ]

Quoted 7 lines
drivers/mfd/airoha-an8855.c new file +7 -0
+static int an8855_regmap_phy_reset_page(struct an8855_core_priv *priv,
+					int phy) __must_hold(&priv->bus->mdio_lock)
+{
+	/* Check PHY page only for addr shared with switch */
+	if (phy != priv->switch_addr)
+		return 0;
+

drivers/mfd/airoha-an8855.c line 299

Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10 -0
+	/* Don't restore page if it's not set to Switch page */
+	if (priv->current_page != FIELD_GET(AN8855_PHY_PAGE,
+					    AN8855_PHY_PAGE_EXTENDED_4))
+		return 0;
+
+	/*
+	 * Restore page to 0, PHY might change page right after but that
+	 * will be ignored as it won't be a switch page.
+	 */
+	return an8855_mii_set_page(priv, phy, AN8855_PHY_PAGE_STANDARD);

[Severity: High]
Could unconditionally restoring the page to STANDARD corrupt the PHY page state if a switch regmap access interleaves with a PHY paged access?

If the PHY framework locks its virtual MDIO bus to perform a paged access sequence, a concurrent switch access can interleave since it locks the parent MDIO bus independently. When the PHY access resumes, forcing the page to STANDARD here would overwrite the PHY's requested page, leading to data corruption.

Quoted 1 line

+}

[ ... ]

Quoted 4 lines
drivers/mfd/airoha-an8855.c new file +4 -0
+static int an8855_phy_register(struct device *dev, struct an8855_core_priv *priv,
+			       struct device_node *phy_np)
+{
+	struct mdio_regmap_config mrc = { };

[ ... ]

drivers/mfd/airoha-an8855.c line 414

Quoted 4 lines
drivers/mfd/airoha-an8855.c new file +4 -0
+	mrc.regmap = regmap;
+	mrc.parent = dev;
+	mrc.valid_addr = addr;
+	snprintf(mrc.name, MII_BUS_ID_SIZE, "an8855-phy%d-mii", addr);

[Severity: Medium]
Will this naming scheme cause duplicate sysfs MII bus IDs if multiple switches exist on the system?

Generating the ID using only the local MDIO address might lead to collisions if there is another switch on a different parent MDIO bus sharing the same local address. Incorporating the parent device name would ensure it is globally unique.

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

[ ... ]

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

[ ... ]

drivers/mfd/airoha-an8855.c line 473

Quoted 9 lines
drivers/mfd/airoha-an8855.c new file +9 -0
+	reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
+	if (IS_ERR(reset_gpio))
+		return PTR_ERR(reset_gpio);
+
+	if (reset_gpio) {
+		usleep_range(100000, 150000);
+		gpiod_set_value_cansleep(reset_gpio, 0);
+		usleep_range(100000, 150000);
+		gpiod_set_value_cansleep(reset_gpio, 1);

[Severity: High]
Does this sequence actively leave the switch hardware in a reset state?

Since gpiod_set_value_cansleep abstracts polarity (where 1 means asserted and 0 means deasserted), calling it with 1 right before attempting to poll the HWTRAP register will likely cause the initialization and subsequent MDIO poll to fail.

drivers/mfd/airoha-an8855.c line 484

Quoted 11 lines
drivers/mfd/airoha-an8855.c new file +11 -0
+
+		/* Poll HWTRAP reg to wait for Switch to fully Init */
+		ret = regmap_read_poll_timeout(regmap, AN8855_HWTRAP, val,
+					       val, 20, 200000);
+		if (ret)
+			return ret;
+	}
+
+	/* Reset PHY page for switch address */
+	ret = an8855_mii_set_page(priv, priv->switch_addr,
+				  AN8855_PHY_PAGE_STANDARD);

[Severity: High]
Should we hold the mdio_lock before calling an8855_mii_set_page() here?

an8855_mii_set_page() expects the lock to be held and uses the lockless __mdiobus_write() internal helper. Calling it unprotected in the probe sequence will trigger a lockdep splat and can race with concurrent accesses on the same parent MDIO bus.

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

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

Quoted 8 lines · On Tue, 18 Aug 2026, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:
- [High] Missing 'select REGMAP' dependency for MDIO_REGMAP and devm_regmap_init().
- [High] Incorrect reset GPIO polarity logic actively leaves the switch in a reset state.
- [High] PHY page state is corrupted when switch regmap accesses interleave with PHY paged accesses.
- [High] Unprotected call to 'an8855_mii_set_page' in probe triggers a lockdep splat and data race.
- [Medium] Signed integer overflow when bit-shifting a 16-bit variable.
- [Medium] Duplicate virtual MII bus IDs if multiple switches exist.
- [Low] Selection of non-existent Kconfig symbol 'MDIO_DEVICE'.

Please review, explain or fix the Sashiko review(s).

If this is a set, this request includes the other patches too.

Quoted 193 lines

--

--- Patch [4]: [PATCH net-next v20 04/10] mfd: an8855: Add support for Airoha AN8855 Switch MFD --- commit 302d7f55459ecc6ab21029f136b77629fdc1e7cb
Author: Christian Marangi <[email protected]>
Subject: mfd: an8855: Add support for Airoha AN8855 Switch MFD

This commit adds core MFD support for the Airoha AN8855 switch, registering a DSA switch and an NVMEM provider. It implements an MDIO regmap driver for the internal PHYs to handle the dual usage of PHYs as both PHY and switch accessors.

drivers/mfd/Kconfig config MFD_ALTERA_SYSMGR · line 60

Quoted 12 lines
drivers/mfd/Kconfig +4 -0
index 763ce6a34782b..4d763ed6e53d5 100644
@@ -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

[Severity: Low]
Is MDIO_DEVICE a valid Kconfig symbol in the tree, or was it intended to be used as a C macro? Selecting a non-existent symbol has no effect and is silently ignored by Kconfig.

[Severity: High]
Does this driver also need to select REGMAP?

Since the driver relies heavily on the regmap subsystem and explicitly calls devm_regmap_init(), failing to select it will cause the regmap APIs to fallback to -EINVAL stubs if CONFIG_REGMAP isn't enabled by another subsystem.

Quoted 2 lines
drivers/mfd/Kconfig +2 -0
+	select MDIO_REGMAP
+	depends on NETDEVICES && OF

[ ... ]

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

[ ... ]

Quoted 7 lines
drivers/mfd/airoha-an8855.c new file +7 -0
+static int an8855_mii_set_page(struct an8855_core_priv *priv, u8 addr,
+			       u8 page) __must_hold(&priv->bus->mdio_lock)
+{
+	struct mii_bus *bus = priv->bus;
+	int ret;
+
+	ret = __mdiobus_write(bus, addr, AN8855_PHY_SELECT_PAGE, page);

[ ... ]

Quoted 3 lines
drivers/mfd/airoha-an8855.c new file +3 -0
+static int an8855_mii_read32(struct mii_bus *bus, u8 phy_id, u32 reg,
+			     u32 *val) __must_hold(&bus->mdio_lock)
+{

[ ... ]

drivers/mfd/airoha-an8855.c line 123

Quoted 7 lines
drivers/mfd/airoha-an8855.c new file +7 -0
+	lo = __mdiobus_read(bus, phy_id, AN8855_PBUS_RD_DATA_LOW);
+	if (lo < 0) {
+		ret = lo;
+		goto err;
+	}
+
+	*val = ((u16)hi << 16) | ((u16)lo & 0xffff);

[Severity: Medium]
Could this bit-shift cause a signed integer overflow? The cast to (u16) causes integer promotion to a signed int. If the highest bit of 'hi' is set, shifting it by 16 bits overflows. Casting to u32 before the shift would avoid this.

Quoted 3 lines
drivers/mfd/airoha-an8855.c new file +3 -0
+
+	return 0;
+err:

[ ... ]

Quoted 7 lines
drivers/mfd/airoha-an8855.c new file +7 -0
+static int an8855_regmap_phy_reset_page(struct an8855_core_priv *priv,
+					int phy) __must_hold(&priv->bus->mdio_lock)
+{
+	/* Check PHY page only for addr shared with switch */
+	if (phy != priv->switch_addr)
+		return 0;
+

drivers/mfd/airoha-an8855.c line 299

Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10 -0
+	/* Don't restore page if it's not set to Switch page */
+	if (priv->current_page != FIELD_GET(AN8855_PHY_PAGE,
+					    AN8855_PHY_PAGE_EXTENDED_4))
+		return 0;
+
+	/*
+	 * Restore page to 0, PHY might change page right after but that
+	 * will be ignored as it won't be a switch page.
+	 */
+	return an8855_mii_set_page(priv, phy, AN8855_PHY_PAGE_STANDARD);

[Severity: High]
Could unconditionally restoring the page to STANDARD corrupt the PHY page state if a switch regmap access interleaves with a PHY paged access?

If the PHY framework locks its virtual MDIO bus to perform a paged access sequence, a concurrent switch access can interleave since it locks the parent MDIO bus independently. When the PHY access resumes, forcing the page to STANDARD here would overwrite the PHY's requested page, leading to data corruption.

Quoted 1 line

+}

[ ... ]

Quoted 4 lines
drivers/mfd/airoha-an8855.c new file +4 -0
+static int an8855_phy_register(struct device *dev, struct an8855_core_priv *priv,
+			       struct device_node *phy_np)
+{
+	struct mdio_regmap_config mrc = { };

[ ... ]

drivers/mfd/airoha-an8855.c line 414

Quoted 4 lines
drivers/mfd/airoha-an8855.c new file +4 -0
+	mrc.regmap = regmap;
+	mrc.parent = dev;
+	mrc.valid_addr = addr;
+	snprintf(mrc.name, MII_BUS_ID_SIZE, "an8855-phy%d-mii", addr);

[Severity: Medium]
Will this naming scheme cause duplicate sysfs MII bus IDs if multiple switches exist on the system?

Generating the ID using only the local MDIO address might lead to collisions if there is another switch on a different parent MDIO bus sharing the same local address. Incorporating the parent device name would ensure it is globally unique.

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

[ ... ]

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

[ ... ]

drivers/mfd/airoha-an8855.c line 473

Quoted 9 lines
drivers/mfd/airoha-an8855.c new file +9 -0
+	reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
+	if (IS_ERR(reset_gpio))
+		return PTR_ERR(reset_gpio);
+
+	if (reset_gpio) {
+		usleep_range(100000, 150000);
+		gpiod_set_value_cansleep(reset_gpio, 0);
+		usleep_range(100000, 150000);
+		gpiod_set_value_cansleep(reset_gpio, 1);

[Severity: High]
Does this sequence actively leave the switch hardware in a reset state?

Since gpiod_set_value_cansleep abstracts polarity (where 1 means asserted and 0 means deasserted), calling it with 1 right before attempting to poll the HWTRAP register will likely cause the initialization and subsequent MDIO poll to fail.

drivers/mfd/airoha-an8855.c line 484

Quoted 11 lines
drivers/mfd/airoha-an8855.c new file +11 -0
+
+		/* Poll HWTRAP reg to wait for Switch to fully Init */
+		ret = regmap_read_poll_timeout(regmap, AN8855_HWTRAP, val,
+					       val, 20, 200000);
+		if (ret)
+			return ret;
+	}
+
+	/* Reset PHY page for switch address */
+	ret = an8855_mii_set_page(priv, priv->switch_addr,
+				  AN8855_PHY_PAGE_STANDARD);

[Severity: High]
Should we hold the mdio_lock before calling an8855_mii_set_page() here?

an8855_mii_set_page() expects the lock to be held and uses the lockless __mdiobus_write() internal helper. Calling it unprotected in the probe sequence will trigger a lockdep splat and can race with concurrent accesses on the same parent MDIO bus.

Quoted 2 lines
drivers/mfd/airoha-an8855.c new file +2 -0
+	if (ret)
+		return ret;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Signature · 1 line
Lee Jones
#10 lore raw

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

In reply to Christian Marangi

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

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

---
 drivers/mfd/Kconfig         |  13 +
 drivers/mfd/Makefile        |   1 +
 drivers/mfd/airoha-an8855.c | 523 ++++++++++++++++++++++++++++++++++++
 3 files changed, 537 insertions(+)
 create mode 100644 drivers/mfd/airoha-an8855.c
drivers/mfd/Kconfig +13 -0
index 763ce6a34782..4d763ed6e53d 100644
@@ -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
index dd4bb7e77c33..00eab2c9f55f 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_MFD_88PM860X)	+= 88pm860x.o
 obj-$(CONFIG_MFD_88PM800)	+= 88pm800.o 88pm80x.o
 obj-$(CONFIG_MFD_88PM805)	+= 88pm805.o 88pm80x.o
 obj-$(CONFIG_MFD_88PM886_PMIC)	+= 88pm886.o
+obj-$(CONFIG_MFD_AIROHA_AN8855)	+= airoha-an8855.o
 obj-$(CONFIG_MFD_ACT8945A)	+= act8945a.o
 obj-$(CONFIG_MFD_SM501)		+= sm501.o
 obj-$(CONFIG_ARCH_BCM2835)	+= bcm2835-pm.o
drivers/mfd/airoha-an8855.c new file +523 -0

523 lines not on this page · raw message

Signature · 1 line
2.53.0
#11 lore raw

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

Hi Christian,

I noticed a possible MDIO bus locking issue in
an8855_core_probe().

The helper an8855_mii_set_page() is declared as:

static int an8855_mii_set_page(struct an8855_core_priv *priv,
u8 addr, u8 page)
__must_hold(&priv->bus->mdio_lock)

and uses __mdiobus_write(). The latter requires the caller to hold bus->mdio_lock and checks this with lockdep_assert_held_once().

The other callers of an8855_mii_set_page() correctly hold the MDIO bus lock, for example:

        mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED);
        ret = an8855_mii_set_page(priv, addr, page);
        ...
        mutex_unlock(&bus->mdio_lock);

However, an8855_core_probe() calls the same helper directly:

        ret = an8855_mii_set_page(priv, priv->switch_addr,
                                  AN8855_PHY_PAGE_STANDARD);

The MDIO device probe path does not hold bus->mdio_lock around the driver's probe callback. Therefore this call can trigger the lockdep assertion, and the MDIO page-select write is not protected by the MDIO bus lock against concurrent accesses to the same bus.

Could this be changed to take the bus lock around the call, for example:

        mutex_lock(&priv->bus->mdio_lock);
        ret = an8855_mii_set_page(priv, priv->switch_addr,
                                  AN8855_PHY_PAGE_STANDARD);
        mutex_unlock(&priv->bus->mdio_lock);
        if (ret)
                return ret;

Alternatively, if there is a reason why the probe path is serialized by another mechanism, it would be useful to document that assumption and annotate the call accordingly.

I don't think changing an8855_mii_set_page() to use mdiobus_write() would be appropriate, since the helper is also called by paths that already hold mdio_lock; that could result in recursive locking. Keeping the helper as an unlocked MDIO primitive with an explicit locking contract seems reasonable, but the probe caller appears to need the missing lock.

This is a discussion and fix suggestion rather than a request to redesign the series. Please let me know if I am missing an existing serialization guarantee in the MDIO device probe path.

Thanks,
Wayen

#12 lore raw

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

In reply to Christian Marangi

Add support for Airoha AN8855 Internal Switch Gigabit PHY.

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

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

275 lines not on this page · raw message

Signature · 1 line
2.53.0
#13 lore raw

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

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Broken exact-match search causes silent calibration fallback for intermediate eFuse values…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Broken exact-match search causes silent calibration fallback for intermediate eFuse values
- [Medium] API contract violation: an8855_set_downshift silently ignores unsupported requested retry counts --

--- Patch [5]: [PATCH net-next v20 05/10] net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY --- commit e5962bf38329639f7d4d409e75314ddeedd25edf
Author: Christian Marangi <[email protected]>

net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY

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

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

[ ... ]

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

drivers/net/phy/air_an8855.c line 85

Quoted 10 lines
drivers/net/phy/air_an8855.c new file +10 -0
+	int i;
+
+	ret = nvmem_cell_read_u32(dev, calib_name, &val);
+	if (ret)
+		return ret;
+
+	shift_sel = FIELD_GET(AN8855_SWITCH_EFUSE_R50O, val);
+	for (i = 0; i < ARRAY_SIZE(dsa_r50ohm_table); i++)
+		if (dsa_r50ohm_table[i] == shift_sel)
+			break;

[Severity: High]
Will this exact match condition fail for intermediate physical calibration values from the eFuse?

If the hardware reads a valid intermediate value like 100 or 102 that isn't explicitly present in the dsa_r50ohm_table, the loop will exhaust the array without matching. This would cause the search to silently discard the calibration data and fall back to the default uncalibrated value.

Should this use a closest-match or bound search to safely handle intermediate ADC/calibration values without dropping them?

Quoted 8 lines
drivers/net/phy/air_an8855.c new file +8 -0
+
+	if (i < 8 || i >= ARRAY_SIZE(dsa_r50ohm_table))
+		*dest = dsa_r50ohm_table[25];
+	else
+		*dest = dsa_r50ohm_table[i - 8];
+
+	return 0;
+}

[ ... ]

drivers/net/phy/air_an8855.c line 153

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

[Severity: Medium]
Does this silently ignore unsupported downshift retry counts?

The function treats the user-provided count only as a boolean toggle. If userspace configures ETHTOOL_PHY_DOWNSHIFT with a specific retry count (e.g. via ethtool), the driver unconditionally enables downshift but ignores the requested count.

If the driver only supports a fixed internal count, should it validate the user's input and return -EOPNOTSUPP or -EINVAL when the requested count doesn't match DOWNSHIFT_DEV_DISABLE or DOWNSHIFT_DEV_DEFAULT_COUNT?

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

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

In reply to Christian Marangi

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

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

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

---
 include/net/dsa.h |  2 ++
 net/dsa/Kconfig   | 11 +++++++++++
 net/dsa/Makefile  |  2 +-
 net/dsa/tag_mtk.c | 36 +++++++++++++++++++++++++++++++++---
 4 files changed, 47 insertions(+), 4 deletions(-)
include/net/dsa.h +2 -0
index 6f7f5c17b532..396c1e520852 100644
@@ -60,6 +60,7 @@ struct tc_action;
 #define DSA_TAG_PROTO_MXL862_VALUE		32
 #define DSA_TAG_PROTO_NETC_VALUE		33
 #define DSA_TAG_PROTO_KSZ8463_VALUE		34
+#define DSA_TAG_PROTO_AIROHA_VALUE		35
 
 enum dsa_tag_protocol {
 	DSA_TAG_PROTO_NONE		= DSA_TAG_PROTO_NONE_VALUE,
@@ -74,6 +75,7 @@ enum dsa_tag_protocol {
 	DSA_TAG_PROTO_KSZ9893		= DSA_TAG_PROTO_KSZ9893_VALUE,
 	DSA_TAG_PROTO_LAN9303		= DSA_TAG_PROTO_LAN9303_VALUE,
 	DSA_TAG_PROTO_MTK		= DSA_TAG_PROTO_MTK_VALUE,
+	DSA_TAG_PROTO_AIROHA		= DSA_TAG_PROTO_AIROHA_VALUE,
 	DSA_TAG_PROTO_QCA		= DSA_TAG_PROTO_QCA_VALUE,
 	DSA_TAG_PROTO_TRAILER		= DSA_TAG_PROTO_TRAILER_VALUE,
 	DSA_TAG_PROTO_8021Q		= DSA_TAG_PROTO_8021Q_VALUE,
net/dsa/Kconfig +11 -0
index d5e725b90d78..510055d7b1f3 100644
@@ -24,6 +24,13 @@ config NET_DSA_TAG_NONE
 	  Say Y or M if you want to enable support for switches which don't tag
 	  frames over the CPU port.
 
+config NET_DSA_TAG_AIROHA
+	tristate "Tag driver for Airoha switches"
+	select NET_DSA_TAG_MTK_COMMON
+	help
+	  Say Y or M if you want to enable support for tagging frames for
+	  Airoha switches.
+
 config NET_DSA_TAG_AR9331
 	tristate "Tag driver for Atheros AR9331 SoC with built-in switch"
 	help
@@ -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
index b8c2667cd14a..fb8c359d6ef9 100644
@@ -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
index c7dc7731675e..f8087d768da6 100644
@@ -11,6 +11,7 @@
 #include "tag.h"
 
 #define MTK_NAME		"mtk"
+#define AIROHA_NAME		"airoha"
 
 #define MTK_HDR_LEN		4
 #define MTK_HDR_XMIT_UNTAGGED		0
@@ -18,6 +19,9 @@
 #define MTK_HDR_XMIT_TAGGED_TPID_88A8	2
 #define MTK_HDR_RECV_SOURCE_PORT_MASK	GENMASK(2, 0)
 #define MTK_HDR_XMIT_DP_BIT_MASK	GENMASK(5, 0)
+/* AN8855 doesn't support SA_DIS and Leaky VLAN
+ * control in tag as these bits doesn't exist.
+ */
 #define MTK_HDR_XMIT_SA_DIS		BIT(6)
 
 static struct sk_buff *mtk_tag_xmit(struct sk_buff *skb,
@@ -99,6 +103,7 @@ static struct sk_buff *mtk_tag_rcv(struct sk_buff *skb, struct net_device *dev)
 	return skb;
 }
 
+#if IS_ENABLED(CONFIG_NET_DSA_TAG_MTK)
 static const struct dsa_device_ops mtk_netdev_ops = {
 	.name		= MTK_NAME,
 	.proto		= DSA_TAG_PROTO_MTK,
@@ -107,8 +112,33 @@ static const struct dsa_device_ops mtk_netdev_ops = {
 	.needed_headroom = MTK_HDR_LEN,
 };
 
-MODULE_DESCRIPTION("DSA tag driver for Mediatek switches");
-MODULE_LICENSE("GPL");
+DSA_TAG_DRIVER(mtk_netdev_ops);
 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_MTK, MTK_NAME);
+#endif
 
-module_dsa_tag_driver(mtk_netdev_ops);
+#if IS_ENABLED(CONFIG_NET_DSA_TAG_AIROHA)
+static const struct dsa_device_ops airoha_netdev_ops = {
+	.name		= AIROHA_NAME,
+	.proto		= DSA_TAG_PROTO_AIROHA,
+	.xmit		= mtk_tag_xmit,
+	.rcv		= mtk_tag_rcv,
+	.needed_headroom = MTK_HDR_LEN,
+};
+
+DSA_TAG_DRIVER(airoha_netdev_ops);
+MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_AIROHA, AIROHA_NAME);
+#endif
+
+static struct dsa_tag_driver *dsa_tag_driver_array[] =	{
+#if IS_ENABLED(CONFIG_NET_DSA_TAG_MTK)
+	&DSA_TAG_DRIVER_NAME(mtk_netdev_ops),
+#endif
+#if IS_ENABLED(CONFIG_NET_DSA_TAG_AIROHA)
+	&DSA_TAG_DRIVER_NAME(airoha_netdev_ops),
+#endif
+};
+
+module_dsa_tag_drivers(dsa_tag_driver_array);
+
+MODULE_DESCRIPTION("DSA tag driver for Mediatek switches");
+MODULE_LICENSE("GPL");
Signature · 1 line
2.53.0
#15 lore raw

Re: [PATCH net-next v20 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] Adding a new tag protocol enum for Airoha without updating the strict protocol checks in…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Adding a new tag protocol enum for Airoha without updating the strict protocol checks in MediaTek/Airoha ethernet master drivers silently breaks hardware offloads and special tag functionality. --

--- Patch [6]: [PATCH net-next v20 06/10] net: dsa: tag_mtk: add Airoha variant usage of this TAG --- commit 9a6d2b41d720a4ec342b1d91531294b7baced74f
Author: Christian Marangi <[email protected]>

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

This commit adds a variant of the MTK DSA tag for Airoha switches, documenting differences and introducing the new DSA_TAG_PROTO_AIROHA enum to report the Airoha name to external tools.

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

Quoted 9 lines
include/net/dsa.h +1 -0
index 6f7f5c17b5320..396c1e5208523 100644
@@ -74,6 +75,7 @@ enum dsa_tag_protocol {
 	DSA_TAG_PROTO_KSZ9893		= DSA_TAG_PROTO_KSZ9893_VALUE,
 	DSA_TAG_PROTO_LAN9303		= DSA_TAG_PROTO_LAN9303_VALUE,
 	DSA_TAG_PROTO_MTK		= DSA_TAG_PROTO_MTK_VALUE,
+	DSA_TAG_PROTO_AIROHA		= DSA_TAG_PROTO_AIROHA_VALUE,

[Severity: High]
Does adding this new protocol enum break hardware offloads and tag processing in the ethernet master drivers?

Looking at the Mediatek and Airoha ethernet drivers, they appear to use strict protocol checks for DSA_TAG_PROTO_MTK. For example, in drivers/net/ethernet/airoha/airoha_eth.c:airoha_get_dsa_tag():

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

This check would fail to extract the DSA tag for the new Airoha protocol, causing untagged packets to retain the tag in the payload which breaks the hardware PPE module.

Similar strict checks exist in other master drivers that might bypass PPE hardware routing logic and L2/L3 flow offloading:

drivers/net/ethernet/mediatek/mtk_eth_soc.c:mtk_uses_dsa()

    dev->dsa_ptr->tag_ops->proto == DSA_TAG_PROTO_MTK;

drivers/net/ethernet/mediatek/mtk_ppe.c:__mtk_ppe_check_skb()

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

drivers/net/ethernet/mediatek/mtk_ppe_offload.c:mtk_flow_get_dsa_port()

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

Should these master drivers be updated to also accept DSA_TAG_PROTO_AIROHA so that hardware capabilities are not disabled?

[ ... ]

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

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

In reply to Christian Marangi

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

---
 MAINTAINERS | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
MAINTAINERS +16 -0
index e0e7fae5b92f..d9338fd2f19c 100644
@@ -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
#17 lore raw

PATCH v20 8/10 net: dsa: mt7530: move MDIO bus locking into regmap

In reply to Christian Marangi

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() 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      | 36 ++++++-----------------------------
 2 files changed, 12 insertions(+), 33 deletions(-)
drivers/net/dsa/mt7530-mdio.c +6 -3
index 784dd58a7158..422f785d2143 100644
@@ -148,12 +148,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;
@@ -207,8 +209,9 @@ mt7530_probe(struct mdio_device *mdiodev)
 			return PTR_ERR(priv->io_pwr);
 	}
 
-	priv->regmap = devm_regmap_init(priv->dev, &mt7530_regmap_bus, priv,
-					&regmap_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 +6 -30
index 2b7be091c056..d01772cfe3a2 100644
@@ -188,29 +188,13 @@ mt7530_mii_read(struct mt7530_priv *priv, u32 reg)
 static int
 mt7530_write(struct mt7530_priv *priv, u32 reg, u32 val)
 {
-	int ret;
-
-	mt7530_mutex_lock(priv);
-
-	ret = mt7530_mii_write(priv, reg, val);
-
-	mt7530_mutex_unlock(priv);
-
-	return ret;
+	return mt7530_mii_write(priv, reg, val);
 }
 
 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
@@ -226,11 +210,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
@@ -597,7 +577,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;
 }
@@ -645,7 +625,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;
 }
@@ -681,7 +661,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;
 }
@@ -717,7 +697,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;
 }
@@ -1452,8 +1432,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;
 
@@ -1473,8 +1451,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
#18 lore raw

Re: [PATCH net-next v20 08/10] net: dsa: mt7530: move MDIO bus locking into regmap

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Recursive mutex deadlock in `mt7530_fdb_cmd`, `mt7530_vlan_cmd`, and `mt7530_irq_mask_sync` due to…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Recursive mutex deadlock in mt7530_fdb_cmd, mt7530_vlan_cmd, and mt7530_irq_mask_sync due to unremoved manual locks.
- [High] Mismatched lock acquisition and release, plus recursive self-deadlock, in MT7531 indirect PHY access functions. --

--- Patch [8]: [PATCH net-next v20 08/10] net: dsa: mt7530: move MDIO bus locking into regmap --- commit 93dc44aef1eb650f9b327c234ee71f5777a75b62
Author: Daniel Golle <[email protected]>

net: dsa: mt7530: move MDIO bus locking into regmap

This patch moves MDIO bus locking into the switch register regmap by configuring the .lock and .unlock callbacks. It removes several manual locking wrappers, relying on the regmap to protect register accesses automatically. It also attempts to switch MT7531 indirect PHY accesses to use reg_mutex.

drivers/net/dsa/mt7530-mdio.c static const struct regmap_config regmap_config = { · line 153

Quoted 10 lines
drivers/net/dsa/mt7530-mdio.c +2 -1
@@ -148,12 +148,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,
 };

[Severity: High]
Will adding the lock to the regmap configuration cause a recursive deadlock in other functions that still hold the manual lock?

For example, in mt7530_fdb_cmd(), the manual lock is still held across a regmap_read_poll_timeout() call:

mt7530_fdb_cmd() {
	mt7530_mutex_lock(priv);

	ret = regmap_read_poll_timeout(priv->regmap, MT7530_ATC, val,
				       !(val & ATC_BUSY), 20, 20000);
	...
}

Since mt7530_mutex_lock() takes the non-recursive mdio_lock, and the regmap now automatically attempts to take the same lock, does this code self-deadlock?

It looks like mt7530_vlan_cmd() and mt7530_irq_mask_sync() also still hold mt7530_mutex_lock() while calling regmap operations.

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

[ ... ]

drivers/net/dsa/mt7530.c mt7531_ind_c45_phy_read(struct mt7530_priv *priv, int port, int devad, · line 583

Quoted 9 lines
drivers/net/dsa/mt7530.c +1 -1
@@ -597,7 +577,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;
 }

[Severity: High]
Does this leave the locks in an unbalanced state?

The entry path of mt7531_ind_c45_phy_read() still calls mt7530_mutex_lock(priv), which takes the mdio_lock:

mt7531_ind_c45_phy_read() {
	mt7530_mutex_lock(priv);
	...
	ret = regmap_read_poll_timeout(...)
	...
}

But the exit path now releases a completely different lock (reg_mutex), which wasn't previously held.

This pattern also seems to be present in mt7531_ind_c45_phy_write(), mt7531_ind_c22_phy_read(), and mt7531_ind_c22_phy_write(), where the semantic patch updated the unlock label but missed replacing the entry lock.

Additionally, since the entry path still takes the manual mdio_lock, do the subsequent regmap calls inside these functions also trigger the same recursive deadlock mentioned earlier?

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

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

In reply to Christian Marangi

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

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

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

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

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

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

---
 drivers/net/dsa/Kconfig       |    4 +
 drivers/net/dsa/Makefile      |    1 +
 drivers/net/dsa/mt7530-lib.c  | 1106 +++++++++++++++++++++++++++
 drivers/net/dsa/mt7530-lib.h  |  385 ++++++++++
 drivers/net/dsa/mt7530-mdio.c |    4 +
 drivers/net/dsa/mt7530-mmio.c |    4 +
 drivers/net/dsa/mt7530.c      | 1322 ++++++++-------------------------
 drivers/net/dsa/mt7530.h      |  258 ++-----
 8 files changed, 1871 insertions(+), 1213 deletions(-)
 create mode 100644 drivers/net/dsa/mt7530-lib.c
 create mode 100644 drivers/net/dsa/mt7530-lib.h
drivers/net/dsa/Kconfig +4 -0
index 4ab567c5bbaf..7e0952dfc9ac 100644
@@ -28,8 +28,12 @@ source "drivers/net/dsa/hirschmann/Kconfig"
 
 source "drivers/net/dsa/lantiq/Kconfig"
 
+config NET_DSA_MT7530_LIB
+	tristate
+
 config NET_DSA_MT7530
 	tristate "MediaTek MT7530 and MT7531 Ethernet switch support"
+	select NET_DSA_MT7530_LIB
 	select NET_DSA_TAG_MTK
 	select REGMAP_IRQ
 	imply NET_DSA_MT7530_MDIO
drivers/net/dsa/Makefile +1 -0
index d2975badffc0..77e4ab5b3944 100644
@@ -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 +1106 -0

1,106 lines not on this page · raw message

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

385 lines not on this page · raw message

drivers/net/dsa/mt7530-mdio.c +4 -0
index 422f785d2143..b94de106ff54 100644
@@ -215,6 +215,10 @@ mt7530_probe(struct mdio_device *mdiodev)
 	if (IS_ERR(priv->regmap))
 		return PTR_ERR(priv->regmap);
 
+	ret = mt7530_setup_lib_priv(priv);
+	if (ret)
+		return ret;
+
 	if (priv->id == ID_MT7531)
 		priv->create_sgmii = mt7531_create_sgmii;
 
drivers/net/dsa/mt7530-mmio.c +4 -0
index fd68b1cd0630..3304d1b1a06d 100644
@@ -61,6 +61,10 @@ mt7988_probe(struct platform_device *pdev)
 	if (IS_ERR(priv->regmap))
 		return PTR_ERR(priv->regmap);
 
+	ret = mt7530_setup_lib_priv(priv);
+	if (ret)
+		return ret;
+
 	return dsa_register_switch(priv->ds);
 }
 
drivers/net/dsa/mt7530.c +305 -1017

1,470 lines not on this page · raw message

drivers/net/dsa/mt7530.h +62 -196

258 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.

#20 lore raw

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

Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider: - [High] Unsafe conversion of atomic command register triggers into multiple sequential Read-Modify-Write…

Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider:
- [High] Unsafe conversion of atomic command register triggers into multiple sequential Read-Modify-Write (RMW) operations.
- [High] Hardware staging registers for FDB and VLAN data will retain stale or garbage bits due to the switch from full-register overwrites to field-based RMWs.
- [High] mt7530_port_enable() incorrectly applies PCR_MATRIX_MASK to an unshifted port matrix value, isolating the port and dropping all traffic.
- [High] Missing reg_fields initialization for ID_EN7528 leads to a NULL pointer dereference during port mirroring.
- [High] mt7530_lib_port_bridge_flags() disables MAC address learning when it is supposed to be enabled, and vice versa.
- [High] mt7530_lib_fdb_read() swaps the last two bytes of the MAC address when reading FDB entries.
- [High] Unchecked regmap_field_read() failures lead to the use of uninitialized stack variables, potentially leaking stack memory to userspace or corrupting hardware state.
- [Medium] mt7530_lib_mib_reset() inadvertently disables the hardware MIB counters for octets and breaks the flush sequence by writing 0 instead of 1. --

--- Patch [9]: [PATCH net-next v20 09/10] net: dsa: mt7530: generalize and move common function to lib module --- commit 302309065c4dc5c4e0f17f164c9e39732602b582
Author: Christian Marangi <[email protected]>

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

This commit moves common functions for the MT7530 switch into a separate library module to prepare for Airoha support. It refactors register accesses to use the regmap reg_field API instead of raw read/writes. A new library struct is introduced to house the shared dependencies and register fields.

Quoted 6 lines
drivers/net/dsa/mt7530-lib.c new file +0 -0
new file mode 100644
index 0000000000000..01ed941efc892
@@ -0,0 +1,1106 @@

[ ... ]

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

Quoted 7 lines
drivers/net/dsa/mt7530-lib.c new file +7 -0
+void mt7530_lib_mib_reset(struct mt7530_lib_priv *priv)
+{
+	regmap_field_write(priv->fields[MT7530_CCR_MIB_ENABLE], 0);
+	regmap_field_write(priv->fields[MT7530_CCR_RX_OCT_CNT_GOOD], 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 this correctly clear the counters? The original code wrote a 1 to flush and clear the counters. Writing 0 to a write-1-to-clear field might fail to reset them.

[ ... ]

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

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

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

[Severity: High]
Can splitting the FDB command execution into multiple read-modify-writes corrupt the MAC table operations? The previous implementation constructed the 32-bit value and wrote it atomically, preventing intermediate hardware states.

[ ... ]

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

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

[Severity: High]
Could this approach leak uninitialized or stale data into the FDB table? Writing fields individually performs a read-modify-write, preserving undefined bits from prior operations, whereas the old code explicitly cleared unspecified bits by writing fully initialized arrays directly.

[ ... ]

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

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

[Severity: High]
If regmap_field_read fails, could we end up assigning uninitialized stack memory from val to the fdb fields? This might leak kernel stack data to userspace during an FDB dump.

[ ... ]

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

Quoted 12 lines
drivers/net/dsa/mt7530-lib.c new file +12 -0
+int mt7530_lib_port_mirror_add(struct mt7530_lib_priv *priv, int port,
+			       struct dsa_mall_mirror_tc_entry *mirror,
+			       bool ingress, struct netlink_ext_ack *extack)
+{
+	int monitor_port;
+	u32 val;
+
+	/* Check for existent entry */
+	if ((ingress ? priv->mirror_rx : priv->mirror_tx) & BIT(port))
+		return -EEXIST;
+
+	regmap_field_read(priv->fields[MT7530_MIRROR_EN], &val);

[Severity: High]
Is it possible for priv->fields to lack an initialization here? The ID_EN7528 entry in mt753x_table appears to be missing its reg_fields setup, which could lead to a NULL pointer dereference.

[Severity: High]
Could a failure in regmap_field_read leave val and monitor_port uninitialized? Using these uninitialized values in the subsequent condition might cause unpredictable branch behavior.

[ ... ]

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

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 invert the learning logic? The hardware bit SA_DIS disables learning, so passing the boolean value of BR_LEARNING directly might disable learning when it is supposed to be enabled, and vice versa.

[ ... ]

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

Quoted 11 lines
drivers/net/dsa/mt7530-lib.c new file +11 -0
+static int mt7530_vlan_cmd(struct mt7530_lib_priv *priv, enum mt7530_vlan_cmd cmd,
+			   u16 vid)
+{
+	u32 val;
+	int ret;
+
+	ret = regmap_field_write(priv->fields[MT7530_VTCR_FUNC], cmd);
+	if (ret)
+		return ret;
+
+	ret = regmap_field_write(priv->fields[MT7530_VTCR_VID], vid);

[Severity: High]
Will breaking this command register access into multiple read-modify-write operations cause issues with the hardware state machine? The original code wrote the entire VTCR register in a single atomic operation.

[ ... ]

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

Quoted 13 lines
drivers/net/dsa/mt7530-lib.c new file +13 -0
+static void mt7530_hw_vlan_add(struct mt7530_lib_priv *priv,
+			       struct mt7530_hw_vlan_entry *entry)
+{
+	struct dsa_port *dp = dsa_to_port(priv->ds, entry->port);
+	u8 new_members;
+	u32 val;
+
+	new_members = entry->old_members | BIT(entry->port);
+
+	/* Validate the entry with independent learning, create egress tag per
+	 * VLAN and joining the port as one of the port members.
+	 */
+	regmap_field_write(priv->fields[MT7530_VAWD_IVL_MAC], 1);

[Severity: High]
Might this leave stale or garbage bits in the VAWD1 register? The original logic performed a full 32-bit register overwrite, explicitly clearing unspecified bits like EG_CON. Using sequential regmap_field_write operations performs read-modify-writes, which retains any previous unmapped bits.

Quoted 4 lines
drivers/net/dsa/mt7530.c +0 -0
index d01772cfe3a2d..f313a7a7bfef1 100644

[ ... ]

Quoted 10 lines
drivers/net/dsa/mt7530.c +2 -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[] = {

[ ... ]

drivers/net/dsa/mt7530.c line 95

Quoted 3 lines
drivers/net/dsa/mt7530.c +3 -0
+	{ MT7530_ATRD_ENT_STATUS, REG_FIELD(MT7530_ATRD, 2, 3), },
+	{ MT7530_ATRD_MAC_BYTE_5, REG_FIELD(MT7530_TSRA2, 24, 31), },
+	{ MT7530_ATRD_MAC_BYTE_4, REG_FIELD(MT7530_TSRA2, 16, 23), },

[Severity: High]
Are the bit ranges for MAC_BYTE_4 and MAC_BYTE_5 swapped here? The original logic mapped MAC_BYTE_4 to bits 24-31 and MAC_BYTE_5 to bits 16-23 in the TSRA2 register, causing corrupted MAC addresses on FDB read.

[ ... ]

Quoted 10 lines
drivers/net/dsa/mt7530.c +1 -1
@@ -1373,7 +1141,7 @@ mt7530_port_enable(struct dsa_switch *ds, int port,
 	if (dsa_port_is_user(dp)) {
 		struct dsa_port *cpu_dp = dp->cpu_dp;
 
-		priv->ports[port].pm |= PCR_MATRIX(BIT(cpu_dp->index));
+		priv->ports[port].pm |= BIT(cpu_dp->index);
 	}
 	priv->ports[port].enable = true;
 	mt7530_rmw(priv, MT7530_PCR_P(port), PCR_MATRIX_MASK,

priv->ports[port].pm);

[Severity: High]
Does this effectively isolate the port by dropping all traffic? The bitmask in pm is now constructed without the PCR_MATRIX() shift, but it is passed directly into mt7530_rmw() where PCR_MATRIX_MASK is applied. Since the unshifted bits fall outside the mask, this will write zero to the matrix field.

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

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

In reply to Christian Marangi

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

---
 drivers/net/dsa/Kconfig      |    9 +
 drivers/net/dsa/Makefile     |    1 +
 drivers/net/dsa/an8855.c     | 1716 ++++++++++++++++++++++++++++++++++
 drivers/net/dsa/an8855.h     |  753 +++++++++++++++
 drivers/net/dsa/mt7530-lib.c |   66 +-
 drivers/net/dsa/mt7530-lib.h |   21 +
 6 files changed, 2546 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
index 7e0952dfc9ac..6076bdef5460 100644
@@ -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
index 77e4ab5b3944..d5f5cbadbe59 100644
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_NET_DSA_AN8855)	+= an8855.o
 obj-$(CONFIG_NET_DSA_BCM_SF2)	+= bcm-sf2.o
 bcm-sf2-objs			:= bcm_sf2.o bcm_sf2_cfp.o
 obj-$(CONFIG_NET_DSA_LOOP)	+= dsa_loop.o
drivers/net/dsa/an8855.c new file +1716 -0

1,716 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
index bab68ff745fb..1ff458c5c3ce 100644
@@ -158,6 +158,8 @@ enum mt7530_regmap_field {
 	MT7530_ATWD_AGE_TIMER,
 	MT7530_ATWD_PORT_MAP,
 	MT7530_ATWD_ENT_STATUS,
+	AN8855_ATWD_TYPE,
+	AN8855_ATWD_VLD,
 	MT7530_ATWD_MAC_BYTE_5,
 	MT7530_ATWD_MAC_BYTE_4,
 	MT7530_ATWD_MAC_BYTE_3,
@@ -169,6 +171,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,
@@ -196,6 +199,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,
@@ -218,8 +222,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,
@@ -238,11 +247,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,
 };
@@ -379,6 +398,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
#22 lore raw

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

Thank you for your contribution! Sashiko AI review found 9 potential issue(s) to consider: - [High] Missing mutex unlock on error paths permanently deadlocks `priv->reg_mutex`. - [High] Kconfig…

Thank you for your contribution! Sashiko AI review found 9 potential issue(s) to consider:
- [High] Missing mutex unlock on error paths permanently deadlocks priv->reg_mutex.
- [High] Kconfig dependency mismatch selects the wrong DSA tag driver, breaking switch probe.
- [High] Inverted logic for BR_LEARNING disables hardware MAC address learning when requested to be enabled.
- [High] Array index of -1 for mib->field_high accesses the regmap pointer, causing a type confusion kernel panic.
- [High] Kernel panics due to NULL pointer dereferences from missing/uninitialized regmap fields.
- [High] Unprotected lockless access to dev->phydev of other ports causes Use-After-Free.
- [Medium] Duplication of standard kernel statistics in private ethtool -S counters.
- [Medium] Swapped TX and RX histograms in RMON stats mappings.
- [Low] an8855_get_sset_count incorrectly returns 0 instead of -EOPNOTSUPP for unsupported string sets. --

--- Patch [10]: [PATCH net-next v20 10/10] net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver --- commit 2771206895bf8d2182821a844b4664df5776fc10
Author: Christian Marangi <[email protected]>

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

This commit introduces the driver for the Airoha AN8855 5-Port Gigabit DSA switch. It adds configuration for MAC and PHY settings, ethtool statistics, bridging, and VLAN capabilities.

Quoted 4 lines
drivers/net/dsa/Kconfig +0 -0
@@ -24,6 +24,15 @@ config NET_DSA_LOOP

[ ... ]

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

Quoted 5 lines
drivers/net/dsa/Kconfig +5 -0
+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

[Severity: High]
Does this config mistakenly select the MTK tagger instead of the AIROHA tagger?

In an8855_get_tag_protocol(), the driver returns DSA_TAG_PROTO_AIROHA. If NET_DSA_TAG_AIROHA is not independently selected, the required Airoha tagger won't be compiled, which will cause the switch initialization to abort.

Quoted 4 lines
drivers/net/dsa/an8855.c new file +0 -0
@@ -0,0 +1,1716 @@

[ ... ]

Quoted 2 lines
drivers/net/dsa/an8855.c new file +2 -0
+static const struct mt7530_reg_field an8855_fields[] = {
+	{ MT7530_BC_FFP, REG_FIELD(AN8855_BCF, 0, 7) },

[ ... ]

drivers/net/dsa/an8855.c line 105

Quoted 1 line
drivers/net/dsa/an8855.c new file +1 -0
+	{ MT7530_PSC_SA_DIR, REG_FIELD_ID(AN8855_PSC, 4, 4, AN8855_NUM_PORTS, 0x200) },

[Severity: High]
Does this inverted logic disable hardware MAC address learning when it should be enabled?

The MT7530_PSC_SA_DIR field is mapped to AN8855_SA_DIS (Source Address Disable, bit 4). When mt7530_lib_port_bridge_flags() processes the BR_LEARNING flag, it writes a 1 to this field to enable learning, which instead sets the disable bit and turns the feature off.

[ ... ]

drivers/net/dsa/an8855.c line 156

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

[Severity: High]
Could the omission of several expected mapping IDs in this array lead to kernel panics?

The array appears to omit MT7530_MIRROR_EN, MT7530_MIRROR_PORT, and AN8855_MIB_TX_OVERSIZE_DROP. When mt7530_lib_port_mirror_add() or an8855_get_ethtool_stats() execute, they will unconditionally read from these uninitialized pointers, resulting in a NULL pointer dereference.

[ ... ]

drivers/net/dsa/an8855.c line 167

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

[Severity: Medium]
Does this array add standardized UAPI counters to the private ethtool statistics?

Standard kernel subsystem rules mandate using the standard UAPI (such as rtnl_link_stats64 or ethtool_eth_mac_stats) rather than ethtool -S for widely standardized counters like TxDrop and TxCollision.

[ ... ]

Quoted 11 lines
drivers/net/dsa/an8855.c new file +11 -0
+static void an8855_port_fast_age(struct dsa_switch *ds, int port)
+{
+	struct an8855_priv *priv = ds->priv;
+	int ret;
+
+	mutex_lock(&priv->reg_mutex);
+
+	/* 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);

drivers/net/dsa/an8855.c line 232

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+		return;
+	}
+
+	/* Set Port */
+	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;
+	}

[Severity: High]
Can these error paths cause a permanent deadlock on priv->reg_mutex?

If regmap_write() fails, the function returns directly without executing mutex_unlock(&priv->reg_mutex), deadlocking future driver operations.

[ ... ]

drivers/net/dsa/an8855.c line 486

Quoted 8 lines
drivers/net/dsa/an8855.c new file +8 -0
+static int an8855_get_sset_count(struct dsa_switch *ds, int port,
+				 int sset)
+{
+	if (sset != ETH_SS_STATS)
+		return 0;
+
+	return ARRAY_SIZE(an8855_mib);
+}

[Severity: Low]
Should this return -EOPNOTSUPP instead of 0 for unsupported string sets?

Standard kernel API rules require returning -EOPNOTSUPP for unsupported ethtool sets to prevent userspace tools from misinterpreting the capability as existing but having 0 elements.

[ ... ]

Quoted 7 lines
drivers/net/dsa/an8855.c new file +7 -0
+static void an8855_get_ethtool_stats(struct dsa_switch *ds, int port,
+				     uint64_t *data)
+{
+	struct an8855_priv *priv = ds->priv;
+	const struct mt7530_mib_desc *mib;
+	struct mt7530_lib_priv *lib_priv;
+	int i;

drivers/net/dsa/an8855.c line 477

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+
+	lib_priv = &priv->lib_priv;
+	for (i = 0; i < ARRAY_SIZE(an8855_mib); i++) {
+		mib = &an8855_mib[i];
+
+		mt7530_lib_read_port_stats(lib_priv->fields[mib->field_low],
+					   lib_priv->fields[mib->field_high],
+					   port, data + i);
+	}
+}

[Severity: High]
Will passing an array index of -1 for mib->field_high cause a type confusion kernel panic?

Several MIB definitions pass -1 for field_high. Since the fields array follows the regmap pointer in struct mt7530_lib_priv, an index of -1 evaluates to the address of the regmap pointer. This disguised pointer will then be passed to regmap_fields_read(), causing a crash.

[ ... ]

Quoted 9 lines
drivers/net/dsa/an8855.c new file +9 -0
+static const struct mt7530_rmon_hist an8855_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,
+		AN8855_MIB_RX_PKT_SZ_1024_TO_1518,
+		AN8855_MIB_RX_PKT_SZ_1519_TO_MAX,

drivers/net/dsa/an8855.c line 525

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+	},
+	.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,
+		AN8855_MIB_RX_PKT_SZ_1024_TO_1518,
+		AN8855_MIB_RX_PKT_SZ_1519_TO_MAX,
+	},

[Severity: Medium]
Are the TX and RX histograms swapped in these RMON stats mappings?

The ranges_fields array (intended for RX histograms) is populated with TX_PKT_SZ register references, while ranges_tx_fields (intended for TX histograms) is populated with RX_PKT_SZ references.

[ ... ]

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

[ ... ]

Quoted 11 lines
drivers/net/dsa/an8855.c new file +11 -0
+	} else {
+		reg |= AN8855_PMCR_FORCE_MODE | AN8855_PMCR_FORCE_LNK;
+
+		reg &= ~AN8855_PMCR_FORCE_SPEED;
+		switch (speed) {
+		case SPEED_10:
+			reg |= AN8855_PMCR_FORCE_SPEED_10;
+			break;
+		case SPEED_100:
+			reg |= AN8855_PMCR_FORCE_SPEED_100;
+			break;

drivers/net/dsa/an8855.c line 900

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+		case SPEED_1000:
+			reg |= AN8855_PMCR_FORCE_SPEED_1000;
+			break;
+		case SPEED_2500:
+			reg |= AN8855_PMCR_FORCE_SPEED_2500;
+			break;
+		case SPEED_5000:
+			dev_err(priv->ds->dev, "Missing support for 5G speed. Aborting...\n");
+			return;
+		}

[Severity: High]
Does this error path leave priv->reg_mutex permanently locked?

Returning directly in the SPEED_5000 case skips the mutex_unlock() call, which will deadlock any future driver operations requiring this mutex.

[ ... ]

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

[ ... ]

Quoted 9 lines
drivers/net/dsa/an8855.c new file +9 -0
+	if (timer) {
+		dsa_switch_for_each_user_port(other_dp, ds) {
+			struct phy_device *phydev;
+			struct net_device *dev;
+
+			if (other_dp == dp)
+				continue;
+
+			dev = other_dp->user;

drivers/net/dsa/an8855.c line 983

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+			if (!dev)
+				continue;
+
+			phydev = dev->phydev;
+			if (!phydev)
+				continue;
+
+			if (timer < phydev->eee_cfg.tx_lpi_timer)
+				timer = phydev->eee_cfg.tx_lpi_timer;
+		}

[Severity: High]
Can this lockless access to another port's dev->phydev cause a use-after-free?

Because this function runs without holding the rtnl_lock or any lock protecting other ports, it is possible for another interface to concurrently be brought down. If that happens, phy_disconnect() could clear and free that phydev under rtnl_lock, resulting in this loop accessing freed memory.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
maintainer
#23 lore raw
In reply to Christian Marangi
Quoted 1 line · On Mon, 17 Aug 2026 10:20:21 +0200 Christian Marangi wrote:

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

## Form letter - net-next-closed

The merge window for v7.3 has started, and therefore net-next is closed for new drivers, features, code refactoring and optimizations. We will only consider applying net-next patches which were posted before the announcement:

https://lore.kernel.org/[email protected]

Fixes are obviously welcome at any time. net-next patches may be sent for review and discussion only with an RFC tag.

Please repost when net-next reopens.

See: https://www.kernel.org/doc/html/next/process/maintainer-netdev.html#development-cycle

Signature · 2 lines
pw-bot: defer
pv-bot: closed