net: dsa: Add Airoha AN8855 support
Subsystems (8)
v22 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 v22:
- Improve MFD lock handling for phy bus
- Prevent devm crash on removal for MFD driver
- Address VAWD bug reported by bot
- Fix wrong msb for MIB for AN8855 driver
- Better handle kconfig dependency
- Read tx_lpi under lock
Changes v21:
- Rebase on top of net-next
- Drop megred patch from Daniel
- Address suggestion reported by bot for MFD driver
- Drop reset for MFD driver
- Reset FDB and VLAN data on writing
- Fix not correct PCR matrix in port enable
- Add ID_EN7528 fields
- Fix MAC address learning SA_DIS
- Fix MAC address FDB read swapped
- Fix mib reset logic
- Fix AN8855 missing regfiled
- Fix AN8855 ethtool stats access
- Improve tx lpi timer for AN8855
- Improve MFD Documentation patch
Changes v20:
- Address all the typo pointed out by bot
- Make documentation schema more consistent
- Address some concern for the mfd driver from bot
- Fix some conversion problem for the generalization patch
Changes v19:
- Rebase on top of net-next
- Rework with shared function from mt7530 driver
- Add dependency for mt7530 lock
- Fix some define typo for AN8855
Changes v18:
- Fix configurting typo
- Init ret in MFD driver
Changes v17:
- Drop nvmem patch (subset merged and present in linux-next)
- Fix wrong Documentation patch for MFD
- Address reviews for MFD driver
- Rework MTK tag to slipt for Airoha name
Changes v16:
- Rebase on top of net-next
- Drop PBUS implementation (Airoha said that it's not OK to use it)
- Convert to simple mdio-regmap and split regmap
- Fix typo for some define (AND8855 -> AN8855)
Changes v15:
- Rebase on top of net-next
- Drop regmap MDIO patch (in favor of PBUS)
- Implement MDIO PBUS and rework MDIO driver/MFD
- Reimplement EEE support
- Add some check for regmap from MFD
- Move to single regmap and add comments with all findings
Changes v14:
- Move MAITAINERS entry to dedicated commit (make it easier for cross subsystem merge)
- Pack variables in trap function
- Add additional patch for reported difference from MTK tag
Changes v13:
- Reimplement tx_lpi OPs
- Rework mdio-regmap to internally encode/decode address
- Fix error in Documentation
- Drop ext-surge property (assume calibration with declared nvmem cell)
- Fix comments from Lee on MFD driver
- Improve print error and drop extra space in DSA driver
Changes v12:
- Update on top of net-next
- Add additional info on conver-letter about slefttests and HW limitation
- Introduce mdio-regmap generalization for multiple address
- Drop dev flags and define PHY calibration in PHY node directly
Changes v11:
- Address reviews from Christophe (spell mistake + dev_err_probe)
- Fix kconfig dependency for MFD driver (depends on MDIO_DEVICE instead of MDIO) (indirectly fix link error for mdio APIs)
- Fix copy-paste error for MFD driver of_table
- Fix compilation error for PHY (move NVMEM to .config)
- Drop unneeded NVMEM node from MDIO example schema (from Andrew)
- Adapt MFD example schema to MDIO reg property restrictions
Changes v10:
- Entire rework to MFD + split to MDIO, EFUSE, SWITCH separate drivers
- Drop EEE OPs (while Russell finish RFC for EEE changes)
- Use new pcs_inpand OPs
- Drop AN restart function and move to pcs_config
- Enable assisted_learning and disable CPU learn (preparation for fdb_isolation)
- Move EFUSE read in Internal PHY driver to .config to handle EPROBE_DEFER (needed now that NVMEM driver is register externally instead of internally to switch node)
Changes v9:
- Error out on using 5G speed as currently not supported
- Add missing MAC_2500FD in phylink mac_capabilities
- Add comment and improve if condition for an8855_phylink_mac_config Changes v8:
- Add port Fast Age support
- Add support for Port Isolation
- Use correct register for Learning Disable
- Add support for Ageing Time OP
- Set default PVID to 0 by default
- Add mdb OPs
- Add port change MTU
- Fix support for Upper VLAN
Changes v7:
- Fix devm_dsa_register_switch wrong export symbol
Changes v6:
- Drop standard MIB and handle with ethtool OPs (as requested by Jakub)
- Cosmetic: use bool instead of 0 or 1
Changes v5:
- Add devm_dsa_register_switch() patch
- Add Reviewed-by tag for DT patch
Changes v4:
- Set regmap readable_table static (mute compilation warning)
- Add support for port_bridge flags (LEARNING, FLOOD)
- Reset fdb struct in fdb_dump
- Drop support_asym_pause in port_enable
- Add define for get_phy_flags
- Fix bug for port not inititially part of a bridge
(in an8855_setup the port matrix was always cleared but
the CPU port was never initially added)
- Disable learning and flood for user port by default
- Set CPU port to flood and learning by default
- Correctly AND force duplex and flow control in an8855_phylink_mac_link_up
- Drop RGMII from pcs_config
- Check ret in "Disable AN if not in autoneg"
- Use devm_mutex_init
- Fix typo for AN8855_PORT_CHECK_MODE
- Better define AN8855_STP_LISTENING = AN8855_STP_BLOCKING
- Fix typo in AN8855_PHY_EN_DOWN_SHIFT
- Use paged helper for PHY
- Skip calibration in config_init if priv not defined
Changes v3:
- Out of RFC
- Switch PHY code to select_page API
- Better describe masks and bits in PHY driver for ADC register
- Drop raw values and use define for mii read/write
- Switch to absolute PHY address
- Replace raw values with mask and bits for pcs_config
- Fix typo for ext-surge property name
- Drop support for relocating Switch base PHY address on the bus
Changes v2:
- Drop mutex guard patch
- Drop guard usage in DSA driver
- Use __mdiobus_write/read
- Check return condition and return errors for mii read/write
- Fix wrong logic for EEE
- Fix link_down (don't force link down with autoneg)
- Fix forcing speed on sgmii autoneg
- Better document link speed for sgmii reg
- Use standard define for sgmii reg
- Imlement nvmem support to expose switch EFUSE
- Rework PHY calibration with the use of NVMEM producer/consumer
- Update DT with new NVMEM property
- Move aneg validation for 2500-basex in pcs_config
- Move r50Ohm table and function to PHY driver
Christian Marangi (9):
dt-bindings: net: dsa: Document support for Airoha AN8855 DSA Switch
dt-bindings: net: Document support for AN8855 Switch Internal PHY
dt-bindings: mfd: Document support for Airoha AN8855 Switch SoC
mfd: an8855: Add support for Airoha AN8855 Switch
net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY
net: dsa: tag_mtk: add Airoha variant usage of this TAG
MAINTAINERS: add myself as maintainer for Airoha AN8855 Switch
net: dsa: mt7530: generalize and move common function to lib module
net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver
.../bindings/mfd/airoha,an8855.yaml | 176 ++ .../bindings/net/airoha,an8855-phy.yaml | 83 + .../net/dsa/airoha,an8855-switch.yaml | 86 + MAINTAINERS | 16 + drivers/mfd/Kconfig | 14 + drivers/mfd/Makefile | 1 + drivers/mfd/airoha-an8855.c | 557 ++++++ drivers/net/dsa/Kconfig | 13 + drivers/net/dsa/Makefile | 2 + drivers/net/dsa/an8855.c | 1740 +++++++++++++++++ drivers/net/dsa/an8855.h | 755 +++++++ drivers/net/dsa/mt7530-lib.c | 1156 +++++++++++ drivers/net/dsa/mt7530-lib.h | 413 ++++ drivers/net/dsa/mt7530-mdio.c | 4 + drivers/net/dsa/mt7530-mmio.c | 4 + drivers/net/dsa/mt7530.c | 1368 +++---------- drivers/net/dsa/mt7530.h | 256 +-- drivers/net/phy/Kconfig | 6 + drivers/net/phy/Makefile | 1 + drivers/net/phy/air_an8855.c | 275 +++ include/net/dsa.h | 2 + net/dsa/Kconfig | 11 + net/dsa/Makefile | 2 +- net/dsa/tag_mtk.c | 36 +- 24 files changed, 5730 insertions(+), 1247 deletions(-) create mode 100644 Documentation/devicetree/bindings/mfd/airoha,an8855.yaml create mode 100644 Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml create mode 100644 Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml create mode 100644 drivers/mfd/airoha-an8855.c create mode 100644 drivers/net/dsa/an8855.c create mode 100644 drivers/net/dsa/an8855.h create mode 100644 drivers/net/dsa/mt7530-lib.c create mode 100644 drivers/net/dsa/mt7530-lib.h create mode 100644 drivers/net/phy/air_an8855.c
Signature · 1 line
2.53.0
PATCH v22 1/9 dt-bindings: net: dsa: Document support for Airoha AN8855 DSA Switch
Document support for Airoha AN8855 5-port Gigabit Switch.
It does expose the 5 Internal PHYs on the MDIO bus and each port can access the Switch register space by configuring the PHY page.
--- .../net/dsa/airoha,an8855-switch.yaml | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml
Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml new file +86 -0
@@ -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
[email protected]
AI reviewRe: [PATCH net-next v22 1/9] dt-bindings: net: dsa: Document support for Airoha AN8855 DSA Switch
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
Document support for Airoha AN8855 5-port Gigabit Switch.
It does expose the 5 Internal PHYs on the MDIO bus and each port can access the Switch register space by configuring the PHY page.
Signed-off-by Christian Marangi <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v22 2/9 dt-bindings: net: Document support for AN8855 Switch Internal PHY
In reply to Christian MarangiDocument support for AN8855 Switch Internal PHY.
Airoha AN8855 is a 5-port Gigabit Switch that expose the Internal PHYs on the MDIO bus.
Each PHY might need to be calibrated to correctly work with the use of the eFUSE provided by the Switch SoC. This can be enabled by defining in the PHY node the NVMEM cell properties.
--- .../bindings/net/airoha,an8855-phy.yaml | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml
Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml new file +83 -0
@@ -0,0 +1,83 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/airoha,an8855-phy.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Airoha AN8855 Switch Internal PHY + +maintainers: + - Christian Marangi <[email protected]> + +description: > + Airoha AN8855 is a 5-port Gigabit Switch that expose the Internal + PHYs on the MDIO bus. + + Each PHY might need to be calibrated to correctly work with the + use of the eFUSE provided by the Switch SoC. + +allOf: + - $ref: ethernet-phy.yaml# + +select: + properties: + compatible: + contains: + enum: + - ethernet-phy-idc0ff.0410 + required: + - compatible + +properties: + reg: + maxItems: 1 + + nvmem-cells: + items: + - description: phandle to SoC eFUSE tx_a + - description: phandle to SoC eFUSE tx_b + - description: phandle to SoC eFUSE tx_c + - description: phandle to SoC eFUSE tx_d + + nvmem-cell-names: + items: + - const: tx_a + - const: tx_b + - const: tx_c + - const: tx_d + +required: + - compatible + - reg + +dependentRequired: + nvmem-cells: [ nvmem-cell-names ] + +unevaluatedProperties: false + +examples: + - | + mdio { + #address-cells = <1>; + #size-cells = <0>; + + ethernet-phy@1 { + compatible = "ethernet-phy-idc0ff.0410", + "ethernet-phy-ieee802.3-c45"; + + reg = <1>; + }; + + ethernet-phy@2 { + compatible = "ethernet-phy-idc0ff.0410", + "ethernet-phy-ieee802.3-c45"; + + reg = <2>; + + nvmem-cells = <&shift_sel_port0_tx_a>, + <&shift_sel_port0_tx_b>, + <&shift_sel_port0_tx_c>, + <&shift_sel_port0_tx_d>; + nvmem-cell-names = "tx_a", "tx_b", "tx_c", "tx_d"; + }; + };
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH net-next v22 2/9] dt-bindings: net: Document support for AN8855 Switch Internal PHY
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines
Document support for AN8855 Switch Internal PHY.
Airoha AN8855 is a 5-port Gigabit Switch that expose the Internal PHYs on the MDIO bus.
Each PHY might need to be calibrated to correctly work with the use of the eFUSE provided by the Switch SoC. This can be enabled by defining in the PHY node the NVMEM cell properties.
Signed-off-by Christian Marangi <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
PATCH v22 3/9 dt-bindings: mfd: Document support for Airoha AN8855 Switch SoC
In reply to Christian MarangiDocument support for Airoha AN8855 Switch SoC. This SoC expose various peripherals like an Ethernet Switch, a NVMEM provider and Ethernet PHYs.
It does also support i2c and timers but those are not currently supported/used.
--- .../bindings/mfd/airoha,an8855.yaml | 176 ++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/airoha,an8855.yaml
Documentation/devicetree/bindings/mfd/airoha,an8855.yaml new file +176 -0
@@ -0,0 +1,176 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mfd/airoha,an8855.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Airoha AN8855 Switch SoC + +maintainers: + - Christian Marangi <[email protected]> + +description: > + Airoha AN8855 Switch is a SoC that expose various peripherals like an + Ethernet Switch, a NVMEM provider and Ethernet PHYs. + + It does also support i2c and timers but those are not currently + supported/used. + +properties: + compatible: + const: airoha,an8855 + + reg: + maxItems: 1 + + reset-gpios: + maxItems: 1 + + efuse: + type: object + $ref: /schemas/nvmem/airoha,an8855-efuse.yaml + description: EFUSE exposed by the Airoha AN8855 SoC + + ethernet-switch: + type: object + $ref: /schemas/net/dsa/airoha,an8855-switch.yaml + description: Switch exposed by the Airoha AN8855 SoC + + mdio: + type: object + $ref: /schemas/net/mdio.yaml# + description: MDIO exposed by the Airoha AN8855 SoC + unevaluatedProperties: false + +required: + - compatible + - reg + - mdio + - ethernet-switch + +additionalProperties: false + +examples: + - | + #include <dt-bindings/gpio/gpio.h> + + mdio { + #address-cells = <1>; + #size-cells = <0>; + + soc@1 { + compatible = "airoha,an8855"; + reg = <1>; + + reset-gpios = <&pio 39 GPIO_ACTIVE_HIGH>; + + efuse { + compatible = "airoha,an8855-efuse"; + + #nvmem-cell-cells = <0>; + + nvmem-layout { + compatible = "fixed-layout"; + #address-cells = <1>; + #size-cells = <1>; + + shift_sel_port0_tx_a: shift-sel-port0-tx-a@c { + reg = <0xc 0x4>; + }; + + shift_sel_port0_tx_b: shift-sel-port0-tx-b@10 { + reg = <0x10 0x4>; + }; + + shift_sel_port0_tx_c: shift-sel-port0-tx-c@14 { + reg = <0x14 0x4>; + }; + + shift_sel_port0_tx_d: shift-sel-port0-tx-d@18 { + reg = <0x18 0x4>; + }; + + shift_sel_port1_tx_a: shift-sel-port1-tx-a@1c { + reg = <0x1c 0x4>; + }; + + shift_sel_port1_tx_b: shift-sel-port1-tx-b@20 { + reg = <0x20 0x4>; + }; + + shift_sel_port1_tx_c: shift-sel-port1-tx-c@24 { + reg = <0x24 0x4>; + }; + + shift_sel_port1_tx_d: shift-sel-port1-tx-d@28 { + reg = <0x28 0x4>; + }; + }; + }; + + ethernet-switch { + compatible = "airoha,an8855-switch"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + label = "lan1"; + phy-mode = "internal"; + phy-handle = <&internal_phy1>; + }; + + port@1 { + reg = <1>; + label = "lan2"; + phy-mode = "internal"; + phy-handle = <&internal_phy2>; + }; + + port@5 { + reg = <5>; + label = "cpu"; + ethernet = <&gmac0>; + phy-mode = "2500base-x"; + + fixed-link { + speed = <2500>; + full-duplex; + pause; + }; + }; + }; + }; + + mdio { + #address-cells = <1>; + #size-cells = <0>; + + internal_phy1: ethernet-phy@1 { + compatible = "ethernet-phy-idc0ff.0410", + "ethernet-phy-ieee802.3-c22"; + reg = <1>; + + nvmem-cells = <&shift_sel_port0_tx_a>, + <&shift_sel_port0_tx_b>, + <&shift_sel_port0_tx_c>, + <&shift_sel_port0_tx_d>; + nvmem-cell-names = "tx_a", "tx_b", "tx_c", "tx_d"; + }; + + internal_phy2: ethernet-phy@2 { + compatible = "ethernet-phy-idc0ff.0410", + "ethernet-phy-ieee802.3-c22"; + reg = <2>; + + nvmem-cells = <&shift_sel_port1_tx_a>, + <&shift_sel_port1_tx_b>, + <&shift_sel_port1_tx_c>, + <&shift_sel_port1_tx_d>; + nvmem-cell-names = "tx_a", "tx_b", "tx_c", "tx_d"; + }; + }; + }; + };
Signature · 1 line
2.53.0
Re: [PATCH net-next v22 3/9] dt-bindings: mfd: Document support for Airoha AN8855 Switch SoC
Quoted 12 lines · 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.
Signed-off-by Christian Marangi <[email protected]>--- .../bindings/mfd/airoha,an8855.yaml | 176 ++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/airoha,an8855.yaml
[email protected]
AI reviewRe: [PATCH net-next v22 3/9] dt-bindings: mfd: Document support for Airoha AN8855 Switch SoC
In reply to Christian MarangiSashiko has reviewed this patch and found no issues.
Quoted 7 lines
Document support for Airoha AN8855 Switch SoC. This SoC expose various peripherals like an Ethernet Switch, a NVMEM provider and Ethernet PHYs.
It does also support i2c and timers but those are not currently supported/used.
Signed-off-by Christian Marangi <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
PATCH v22 4/9 mfd: an8855: Add support for Airoha AN8855 Switch
In reply to Christian MarangiAdd support for Airoha AN8855 Switch that provide support for a DSA switch and a NVMEM provider.
Also make use of the mdio-regmap driver and register a regmap for each internal PHY of the switch.
This is needed to handle the double usage of the PHYs as both PHY and Switch accessor.
--- drivers/mfd/Kconfig | 14 + drivers/mfd/Makefile | 1 + drivers/mfd/airoha-an8855.c | 557 ++++++++++++++++++++++++++++++++++++ 3 files changed, 572 insertions(+) create mode 100644 drivers/mfd/airoha-an8855.c
drivers/mfd/Kconfig +14 -0
@@ -54,6 +54,20 @@ config MFD_ALTERA_SYSMGR using regmap_mmio accesses for ARM32 parts and SMC calls to EL3 for ARM64 parts. +config MFD_AIROHA_AN8855 + tristate "Airoha AN8855 Switch Core" + select MFD_CORE + select REGMAP + select PHYLIB + select MDIO_REGMAP + depends on NETDEVICES && OF + help + Support for the Airoha AN8855 Switch Core. This is an SoC + that provides various peripherals, to count, i2c, an Ethrnet + Switch, a CPU timer, GPIO, eFUSE. + + Currently it provides a DSA switch and a NVMEM provider. + config MFD_ACT8945A tristate "Active-semi ACT8945A" select MFD_CORE
drivers/mfd/Makefile +1 -0
@@ -8,6 +8,7 @@ obj-$(CONFIG_MFD_88PM860X) += 88pm860x.o obj-$(CONFIG_MFD_88PM800) += 88pm800.o 88pm80x.o obj-$(CONFIG_MFD_88PM805) += 88pm805.o 88pm80x.o obj-$(CONFIG_MFD_88PM886_PMIC) += 88pm886.o +obj-$(CONFIG_MFD_AIROHA_AN8855) += airoha-an8855.o obj-$(CONFIG_MFD_ACT8945A) += act8945a.o obj-$(CONFIG_MFD_SM501) += sm501.o obj-$(CONFIG_ARCH_BCM2835) += bcm2835-pm.o
drivers/mfd/airoha-an8855.c new file +557 -0
557 lines not on this page · raw message
Signature · 1 line
2.53.0
Jakub Kicinski
maintainerRe: [PATCH net-next v22 4/9] mfd: an8855: Add support for Airoha AN8855 Switch
Quoted 7 lines · On Tue, 15 Sep 2026 14:38:01 +0200 Christian Marangi wrote:
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.
GCC spews warnings:
drivers/mfd/airoha-an8855.c: In function ‘an8855_mdio_register’:drivers/mfd/airoha-an8855.c:438:48: warning: ‘-phy’ directive output may be truncated writing 4 bytes into a region of size between 1 and 61 [-Wformat-truncation=]
438 | snprintf(mrc.name, MII_BUS_ID_SIZE, "%s-phy%d", priv->bus->id, addr);
| ^~~~
In function ‘an8855_phy_bus_register’,
inlined from ‘an8855_mdio_register’ at ../drivers/mfd/airoha-an8855.c:469:9:
drivers/mfd/airoha-an8855.c:438:45: note: using the range [-2147483648, 2147483647] for directive argument
438 | snprintf(mrc.name, MII_BUS_ID_SIZE, "%s-phy%d", priv->bus->id, addr);
| ^~~~~~~~~~drivers/mfd/airoha-an8855.c:438:9: note: ‘snprintf’ output between 6 and 76 bytes into a destination of size 61
438 | snprintf(mrc.name, MII_BUS_ID_SIZE, "%s-phy%d", priv->bus->id, addr);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Re: [PATCH net-next v22 4/9] mfd: an8855: Add support for Airoha AN8855 Switch
Il giorno lun 21 set 2026 alle ore 22:44 Jakub Kicinski <[email protected]> ha scritto:
Quoted 17 lines · On Tue, 15 Sep 2026 14:38:01 +0200 Christian Marangi wrote:
Quoted 7 lines
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.GCC spews warnings:
drivers/mfd/airoha-an8855.c: In function ‘an8855_mdio_register’:drivers/mfd/airoha-an8855.c:438:48: warning: ‘-phy’ directive output may be truncated writing 4 bytes into a region of size between 1 and 61 [-Wformat-truncation=]
438 |snprintf(mrc.name, MII_BUS_ID_SIZE, "%s-phy%d", priv->bus->id, addr);
| ^~~~
In function ‘an8855_phy_bus_register’,
Quoted 8 lines
inlined from ‘an8855_mdio_register’ at ../drivers/mfd/airoha-an8855.c:469:9:
drivers/mfd/airoha-an8855.c:438:45: note: using the range [-2147483648, 2147483647] for directive argument
438 |snprintf(mrc.name, MII_BUS_ID_SIZE, "%s-phy%d", priv->bus->id, addr);
| ^~~~~~~~~~drivers/mfd/airoha-an8855.c:438:9: note: ‘snprintf’ output between 6 and 76 bytes into a destination of size 61438 | snprintf(mrc.name, MII_BUS_ID_SIZE, "%s-phy%d", priv->bus->id, addr); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Hi,
I also didn't receive the email for the AI review... Did it broke also here?
If everything else is ok, should I send new revision or maybe we can pick this and I can send followup for this warning?
Jakub Kicinski
maintainerRe: [PATCH net-next v22 4/9] mfd: an8855: Add support for Airoha AN8855 Switch
Quoted 3 lines · On Tue, 22 Sep 2026 12:14:22 +0200 Christian Marangi (Ansuel) wrote:
I also didn't receive the email for the AI review... Did it broke also here?
If everything else is ok, should I send new revision or maybe we can pick this and I can send followup for this warning?
Clashiko gates on build and kdoc being clean, to try to save tokens. FWIW this is also how the CI (kselftests) are gated.
[email protected]
AI reviewRe: [PATCH net-next v22 4/9] mfd: an8855: Add support for Airoha AN8855 Switch
In reply to Christian MarangiThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] mfd: airoha-an8855: use-after-free of phy_np fwnode handle - [Medium] mfd: airoha-an8855: memory…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] mfd: airoha-an8855: use-after-free of phy_np fwnode handle
- [Medium] mfd: airoha-an8855: memory leak of mdio_np on error path
--
commit 1917f4cbbcfe1c5b1f8816f88eed9bb439f23478
Author: Christian Marangi <[email protected]>
mfd: an8855: Add support for Airoha AN8855 Switch
This commit adds support for the Airoha AN8855 switch, which provides a DSA switch and an NVMEM provider. It introduces MDIO-based regmaps for each internal PHY, allowing them to act as both standard PHYs and access points for the switch fabric.
Quoted 5 lines
drivers/mfd/airoha-an8855.c new file +0
-0
[ ... ]
Quoted 4 lines
drivers/mfd/airoha-an8855.c new file +4
-0+static int an8855_phy_bus_register (struct device *dev,struct an8855_core_priv *priv, +struct device_node *phy_np, +struct an8855_phy_bus *phy_bus_info) +{
[ ... ]
drivers/mfd/airoha-an8855.c line 449
Quoted 3 lines
drivers/mfd/airoha-an8855.c new file +3
-0+ phy_bus_info->bus = bus; + phy_bus_info->addr = addr; + phy_bus_info->node =of_fwnode_handle (phy_np);
[Severity: High]
Does this leave the fwnode handle without an active reference?
The device node phy_np is supplied by a scoped iterator in an8855_mdio_register(), which automatically drops the reference on each iteration or loop exit.
Because of_node_get() is not used here to acquire an additional reference, the node is saved without incrementing the reference count. This can lead to a use-after-free later in an8855_core_probe() when the stale fwnode pointer is passed to fwnode_mdiobus_register_phy().
Quoted 8 lines
drivers/mfd/airoha-an8855.c new file +8
-0+ +return 0 ; +} + +static int an8855_mdio_register (struct device *dev,struct an8855_core_priv *priv, +struct an8855_phy_bus *phy_bus_infos) +{ +struct device_node *mdio_np;
drivers/mfd/airoha-an8855.c line 467
Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10
-0+int ret =0 ; +int i =0 ; + + mdio_np =of_get_child_by_name (dev->of_node,"mdio" ); +if (!mdio_np) +return -ENODEV ; + +for_each_available_child_of_node_scoped (mdio_np, phy_np) { +if (i >=AN8855_MAX_PHY_PORT ) +return -EINVAL ;
[Severity: Medium]
Does this early return leak the mdio_np reference?
When returning -EINVAL directly, the function bypasses the of_node_put(mdio_np) cleanup at the end of the function. This permanently leaks the device node reference that was acquired by of_get_child_by_name() before the loop.
Quoted 12 lines
drivers/mfd/airoha-an8855.c new file +12
-0+ + ret =an8855_phy_bus_register (dev, priv, phy_np, + &phy_bus_infos[i]); +if (ret) +break ; + + i++; + } + +of_node_put (mdio_np); +return ret ? ret : i; +}
[ ... ]
Quoted 2 lines
drivers/mfd/airoha-an8855.c new file +2
-0+static int an8855_core_probe (struct mdio_device *mdiodev) +{
[ ... ]
Quoted 4 lines
drivers/mfd/airoha-an8855.c new file +4
-0+/* Register virtual MDIO for each PHY */ + num_phys =an8855_mdio_register (dev, priv, phy_bus_infos); +if (num_phys <0 ) +return num_phys;
[ ... ]
Quoted 8 lines
drivers/mfd/airoha-an8855.c new file +8
-0+/* Register PHYs */ +for (i =0 ; i < num_phys; i++) { + ret =fwnode_mdiobus_register_phy (phy_bus_infos[i].bus, + phy_bus_infos[i].node, + phy_bus_infos[i].addr); +if (ret) +return ret; + }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
PATCH v22 5/9 net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY
In reply to Christian MarangiAdd support for Airoha AN8855 Internal Switch Gigabit PHY.
This is a simple PHY driver to configure and calibrate the PHY for the AN8855 Switch with the use of NVMEM cells.
--- drivers/net/phy/Kconfig | 6 + drivers/net/phy/Makefile | 1 + drivers/net/phy/air_an8855.c | 275 +++++++++++++++++++++++++++++++++++ 3 files changed, 282 insertions(+) create mode 100644 drivers/net/phy/air_an8855.c
drivers/net/phy/Kconfig +6 -0
@@ -96,6 +96,12 @@ config AIR_AN8801_PHY help Currently supports the Airoha AN8801R PHY. +config AIR_AN8855_PHY + tristate "Airoha AN8855 Internal Gigabit PHY" + depends on NVMEM || !NVMEM + help + Currently supports the internal Airoha AN8855 Switch PHY. + config AIR_EN8811H_PHY tristate "Airoha EN8811H 2.5 Gigabit PHY" select AIR_NET_PHYLIB
drivers/net/phy/Makefile +1 -0
@@ -31,6 +31,7 @@ obj-$(CONFIG_ADIN_PHY) += adin.o obj-$(CONFIG_ADIN1100_PHY) += adin1100.o obj-$(CONFIG_ADIN1140_PHY) += adin1140-phy.o obj-$(CONFIG_AIR_AN8801_PHY) += air_an8801.o +obj-$(CONFIG_AIR_AN8855_PHY) += air_an8855.o obj-$(CONFIG_AIR_EN8811H_PHY) += air_en8811h.o obj-$(CONFIG_AIR_NET_PHYLIB) += air_phy_lib.o obj-$(CONFIG_AMD_PHY) += amd.o
drivers/net/phy/air_an8855.c new file +275 -0
275 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH net-next v22 5/9] net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] net/phy: flawed calibration lookup logic corrupts valid efuse values - [Medium] net/phy…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] net/phy: flawed calibration lookup logic corrupts valid efuse values
- [Medium] net/phy: phy_write_mmd zeroing out adjacent fields in RXADC registers
- [Low] net/phy: downshift tunable ignores requested count violating ethtool API --
commit 86e9fad6319a9402e15a273e59be80e0d645c59c
Author: Christian Marangi <[email protected]>
net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY
This commit adds a simple PHY driver to support the Airoha AN8855 Internal Switch Gigabit PHY, including configuration and calibration using NVMEM cells.
Quoted 5 lines
drivers/net/phy/air_an8855.c new file +0
-0
[ ... ]
Quoted 13 lines
drivers/net/phy/air_an8855.c new file +13
-0+static int an8855_get_r50ohm_val (struct device *dev,const char *calib_name, +u8 *dest) +{ +u32 shift_sel, val; +int ret; +int i; + + ret =nvmem_cell_read_u32 (dev, calib_name, &val); +if (ret) +return ret; + + shift_sel =FIELD_GET (AN8855_SWITCH_EFUSE_R50O , val); +for (i =0 ; i <ARRAY_SIZE (dsa_r50ohm_table); i++)
drivers/net/phy/air_an8855.c line 93
Quoted 10 lines
drivers/net/phy/air_an8855.c new file +10
-0+if (dsa_r50ohm_table[i] == shift_sel) +break ; + +if (i <8 || i >=ARRAY_SIZE (dsa_r50ohm_table)) + *dest = dsa_r50ohm_table[25 ]; +else + *dest = dsa_r50ohm_table[i -8 ]; + +return 0 ; +}
[Severity: High]
Does this logic incorrectly map valid top-end EFUSE values to a fallback?
If the hardware EFUSE provides 127 (which is the first entry in dsa_r50ohm_table), the loop immediately matches at i = 0. The code then evaluates if (i < 8) as true, forcing dest to a hardcoded fallback of dsa_r50ohm_table[25] (which is 94).
However, a slightly lower value like 126 matches at i = 17, bypasses the check, and maps to dsa_r50ohm_table[9] (which correctly yields 127). Will this discontinuity erroneously penalize top-end calibration values and drop them to 94, potentially corrupting PHY TX pair calibration?
[ ... ]
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: Low]
Does this downshift tunable ignore the requested retry count?
The ethtool API for ETHTOOL_PHY_DOWNSHIFT accepts a specific retry count via the cnt parameter, but here cnt != DOWNSHIFT_DEV_DISABLE is used as a simple boolean toggle.
If userspace requests a specific unsupported downshift count, won't the driver enable the hardware default and return 0 (success) instead of rejecting the invalid count with -EOPNOTSUPP or -EINVAL?
[ ... ]
Quoted 2 lines
drivers/net/phy/air_an8855.c new file +2
-0+static int an8855_config_init (struct phy_device *phydev) +{
[ ... ]
Quoted 14 lines
drivers/net/phy/air_an8855.c new file +14
-0+/* Apply values to reduce signal noise */ + ret =phy_modify_mmd (phydev,MDIO_MMD_VEND1 ,AN8855_PHY_TX_PAIR_DLY_SEL_GBE , +AN8855_PHY_CR_DA_TX_PAIR_DELAY_SEL_A_GBE | +AN8855_PHY_CR_DA_TX_PAIR_DELAY_SEL_C_GBE , +FIELD_PREP (AN8855_PHY_CR_DA_TX_PAIR_DELAY_SEL_A_GBE ,0x4 ) | +FIELD_PREP (AN8855_PHY_CR_DA_TX_PAIR_DELAY_SEL_C_GBE ,0x4 )); +if (ret) +return ret; + ret =phy_set_bits_mmd (phydev,MDIO_MMD_VEND1 ,AN8855_PHY_RXADC_CTRL , +AN8855_PHY_RG_AD_SAMPLE_PHSEL_A | +AN8855_PHY_RG_AD_SAMPLE_PHSEL_C ); +if (ret) +return ret; + ret = phy_write_mmd(phydev, MDIO_MMD_VEND1, AN8855_PHY_RXADC_REV_0,
drivers/net/phy/air_an8855.c line 213
Quoted 10 lines
drivers/net/phy/air_an8855.c new file +10
-0+ FIELD_PREP(AN8855_PHY_RG_AD_RESERVE0_A, 0x1)); +if (ret) +return ret; + ret =phy_write_mmd (phydev,MDIO_MMD_VEND1 ,AN8855_PHY_RXADC_REV_1 , +FIELD_PREP (AN8855_PHY_RG_AD_RESERVE0_C ,0x1 )); +if (ret) +return ret; + +return 0 ; +}
[Severity: Medium]
Will phy_write_mmd() inadvertently zero out adjacent fields in these RXADC registers?
Earlier in this function, phy_modify_mmd() and phy_set_bits_mmd() are used to carefully preserve the state of pairs B and D. But for the REV_0 and REV_1 registers, phy_write_mmd() completely overwrites the 16-bit register.
By writing FIELD_PREP(AN8855_PHY_RG_AD_RESERVE0_A, 0x1) directly, won't this implicitly zero out the adjacent AN8855_PHY_RG_AD_RESERVE0_B (bits 7:0), breaking the read-modify-write pattern and wiping out hardware defaults for pairs B and D?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
PATCH v22 6/9 net: dsa: tag_mtk: add Airoha variant usage of this TAG
In reply to Christian MarangiAdd variant of the MTK TAG for Airoha Switch and comments about difference between Airoha AN8855 and Mediatek tag bitmap.
Airoha AN8855 doesn't support controlling SA learning and Leaky VLAN from tag. Although these bits are not used (and even not defined for Leaky VLAN), it's worth to add comments for these difference to prevent any kind of regression in the future if ever these bits will be used.
Rework the makefile, config and tag driver to better report to external tool (like libpcap) the usage of this variant with a dedicated "Airoha" name.
--- include/net/dsa.h | 2 ++ net/dsa/Kconfig | 11 +++++++++++ net/dsa/Makefile | 2 +- net/dsa/tag_mtk.c | 36 +++++++++++++++++++++++++++++++++--- 4 files changed, 47 insertions(+), 4 deletions(-)
include/net/dsa.h +2 -0
@@ -61,6 +61,7 @@ struct tc_action;#define DSA_TAG_PROTO_NETC_VALUE 33#define DSA_TAG_PROTO_KSZ8463_VALUE 34#define DSA_TAG_PROTO_MT7628_VALUE 35 +#define DSA_TAG_PROTO_AIROHA_VALUE 36enum dsa_tag_protocol {DSA_TAG_PROTO_NONE =DSA_TAG_PROTO_NONE_VALUE ,
@@ -75,6 +76,7 @@ enum dsa_tag_protocol {DSA_TAG_PROTO_KSZ9893 =DSA_TAG_PROTO_KSZ9893_VALUE ,DSA_TAG_PROTO_LAN9303 =DSA_TAG_PROTO_LAN9303_VALUE ,DSA_TAG_PROTO_MTK =DSA_TAG_PROTO_MTK_VALUE , +DSA_TAG_PROTO_AIROHA =DSA_TAG_PROTO_AIROHA_VALUE ,DSA_TAG_PROTO_QCA =DSA_TAG_PROTO_QCA_VALUE ,DSA_TAG_PROTO_TRAILER =DSA_TAG_PROTO_TRAILER_VALUE , DSA_TAG_PROTO_8021Q = DSA_TAG_PROTO_8021Q_VALUE,
net/dsa/Kconfig +11 -0
@@ -24,6 +24,13 @@ config NET_DSA_TAG_NONE Say Y or M if you want to enable support for switches which don't tag frames over the CPU port. +config NET_DSA_TAG_AIROHA + tristate "Tag driver for Airoha switches" + select NET_DSA_TAG_MTK_COMMON + help + Say Y or M if you want to enable support for tagging frames for + Airoha switches. + config NET_DSA_TAG_AR9331 tristate "Tag driver for Atheros AR9331 SoC with built-in switch" help
@@ -104,8 +111,12 @@ config NET_DSA_TAG_MT7628 Say Y or M if you want to enable support for tagging frames for the switch embedded in the MT7628 SoC. +config NET_DSA_TAG_MTK_COMMON + tristate + config NET_DSA_TAG_MTK tristate "Tag driver for Mediatek switches" + select NET_DSA_TAG_MTK_COMMON help Say Y or M if you want to enable support for tagging frames for Mediatek switches.
net/dsa/Makefile +1 -1
@@ -28,7 +28,7 @@ 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_MT7628) += tag_mt7628.o -obj-$(CONFIG_NET_DSA_TAG_MTK) += tag_mtk.o +obj-$(CONFIG_NET_DSA_TAG_MTK_COMMON) += tag_mtk.o obj-$(CONFIG_NET_DSA_TAG_MXL_862XX) += tag_mxl862xx.o obj-$(CONFIG_NET_DSA_TAG_MXL_GSW1XX) += tag_mxl-gsw1xx.o obj-$(CONFIG_NET_DSA_TAG_NETC) += tag_netc.o
net/dsa/tag_mtk.c +33 -3
@@ -11,6 +11,7 @@#include "tag.h" #define MTK_NAME "mtk" +#define AIROHA_NAME "airoha"#define MTK_HDR_LEN 4#define MTK_HDR_XMIT_UNTAGGED 0
@@ -18,6 +19,9 @@#define MTK_HDR_XMIT_TAGGED_TPID_88A8 2#define MTK_HDR_RECV_SOURCE_PORT_MASK GENMASK(2, 0)#define MTK_HDR_XMIT_DP_BIT_MASK GENMASK(5, 0) +/* AN8855 doesn't support SA_DIS and Leaky VLAN +* control in tag as these bits doesn't exist. +*/ #define MTK_HDR_XMIT_SA_DIS BIT(6) static struct sk_buff *mtk_tag_xmit(struct sk_buff *skb,
@@ -99,6 +103,7 @@ static struct sk_buff *mtk_tag_rcv(struct sk_buff *skb, struct net_device *dev)return skb; } +#if IS_ENABLED (CONFIG_NET_DSA_TAG_MTK )static const struct dsa_device_ops mtk_netdev_ops = { .name =MTK_NAME , .proto = DSA_TAG_PROTO_MTK,
@@ -107,8 +112,33 @@ static const struct dsa_device_ops mtk_netdev_ops = { .needed_headroom = MTK_HDR_LEN, }; -MODULE_DESCRIPTION ("DSA tag driver for Mediatek switches" ); -MODULE_LICENSE ("GPL" ); +DSA_TAG_DRIVER (mtk_netdev_ops);MODULE_ALIAS_DSA_TAG_DRIVER (DSA_TAG_PROTO_MTK ,MTK_NAME ); +#endif -module_dsa_tag_driver (mtk_netdev_ops); +#if IS_ENABLED (CONFIG_NET_DSA_TAG_AIROHA ) +static const struct dsa_device_ops airoha_netdev_ops = { + .name =AIROHA_NAME , + .proto =DSA_TAG_PROTO_AIROHA , + .xmit = mtk_tag_xmit, + .rcv = mtk_tag_rcv, + .needed_headroom =MTK_HDR_LEN , +}; + +DSA_TAG_DRIVER (airoha_netdev_ops); +MODULE_ALIAS_DSA_TAG_DRIVER (DSA_TAG_PROTO_AIROHA ,AIROHA_NAME ); +#endif + +static struct dsa_tag_driver *dsa_tag_driver_array[] = { +#if IS_ENABLED(CONFIG_NET_DSA_TAG_MTK) + &DSA_TAG_DRIVER_NAME (mtk_netdev_ops), +#endif +#if IS_ENABLED(CONFIG_NET_DSA_TAG_AIROHA) + &DSA_TAG_DRIVER_NAME (airoha_netdev_ops), +#endif +}; + +module_dsa_tag_drivers (dsa_tag_driver_array); + +MODULE_DESCRIPTION ("DSA tag driver for Mediatek switches" ); +MODULE_LICENSE ("GPL" );
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH net-next v22 6/9] net: dsa: tag_mtk: add Airoha variant usage of this TAG
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] net: dsa: missing DSA_TAG_PROTO_AIROHA in eth drivers breaks offloads --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] net: dsa: missing DSA_TAG_PROTO_AIROHA in eth drivers breaks offloads --
commit aaecc61a677f69e71544a1c2a64947df3cc03f58
Author: Christian Marangi <[email protected]>
net: dsa: tag_mtk: add Airoha variant usage of this TAG
Add variant of the MTK TAG for Airoha Switch and comments about difference between Airoha AN8855 and Mediatek tag bitmap.
include/net/dsa.h enum dsa_tag_protocol { · line 79
Quoted 9 lines
include/net/dsa.h +1
-0@@ -75,6 +76,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 break hardware offloads in the ethernet MAC drivers?
The Mediatek and Airoha ethernet drivers explicitly check for DSA_TAG_PROTO_MTK to enable hardware DSA tag extraction and PPE offloading.
For example, in airoha_get_dsa_tag() indrivers/net/ethernet/airoha/airoha_eth.c:
if (dev->dsa_ptr->tag_ops->proto != DSA_TAG_PROTO_MTK)
return 0;Because DSA_TAG_PROTO_AIROHA is not matched, the MAC drivers will skip DSA tag extraction, leaving the tag in the payload. Will this cause the hardware to miscalculate IP header offsets and break checksum offloads?
Similar checks exist in mtk_uses_dsa() indrivers/net/ethernet/mediatek/mtk_eth_soc.c:
return netdev_uses_dsa(dev) &&
dev->dsa_ptr->tag_ops->proto == DSA_TAG_PROTO_MTK;And in mtk_foe_entry_commit_subflow() indrivers/net/ethernet/mediatek/mtk_ppe.c:
if (!netdev_uses_dsa(skb->dev) ||
skb->dev->dsa_ptr->tag_ops->proto != DSA_TAG_PROTO_MTK)
goto out;This could entirely disable PPE hardware offloading for the new Airoha switch protocol. Should these drivers be updated to also match DSA_TAG_PROTO_AIROHA?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
PATCH v22 7/9 MAINTAINERS: add myself as maintainer for Airoha AN8855 Switch
In reply to Christian MarangiAdd myself as maintainer for AN8855 DSA driver and all the related subdriver (mfd, mdio, phy, nvmem)
--- MAINTAINERS | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
MAINTAINERS +16 -0
@@ -759,6 +759,22 @@ S: Maintained F: Documentation/devicetree/bindings/net/airoha,en7581-eth.yaml F: drivers/net/ethernet/airoha/ +AIROHA AN8855 DSA DRIVER +M: Christian Marangi <[email protected]> +L: [email protected] (moderated for non-subscribers) +L: [email protected] (moderated for non-subscribers) +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/mfd/airoha,an8855.yaml +F: Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml +F: Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml +F: Documentation/devicetree/bindings/nvmem/airoha,an8855-efuse.yaml +F: drivers/mfd/airoha-an8855.c +F: drivers/net/dsa/an8855.c +F: drivers/net/dsa/an8855.h +F: drivers/net/phy/air_an8855.c +F: drivers/nvmem/an8855-efuse.c + AIROHA PCIE PHY DRIVER M: Lorenzo Bianconi <[email protected]> L: [email protected] (moderated for non-subscribers)
Signature · 1 line
2.53.0
PATCH v22 8/9 net: dsa: mt7530: generalize and move common function to lib module
In reply to Christian MarangiIn preparation of support of DSA Switch from Airoha, create a mt7530 library module and move there all the common function.
Function are generalized to use the reg_field regmap API but still apply the same exact logic. Every function is renamed to mt7530_lib prefix to better identify it.
Minimum modification are needed to the register header and common enum and macro are moved to the mt7530 library header to permit reuse.
A library struct is introduced with everything required for the common functions.
The generalization and the introduction of reg_field regmap API have the side effect of permitting to clean the mirror functions that required special handling for MT7530 and MT7531 based switch that had different registers. This is done by declaring a common MT7530 reg_field and a specific one in the Switch match table.
No behaviour change is expected by this change as it's just a code move and reimplementation.
--- drivers/net/dsa/Kconfig | 4 + drivers/net/dsa/Makefile | 1 + drivers/net/dsa/mt7530-lib.c | 1128 +++++++++++++++++++++++++++ drivers/net/dsa/mt7530-lib.h | 391 ++++++++++ drivers/net/dsa/mt7530-mdio.c | 4 + drivers/net/dsa/mt7530-mmio.c | 4 + drivers/net/dsa/mt7530.c | 1368 ++++++++------------------------- drivers/net/dsa/mt7530.h | 256 ++---- 8 files changed, 1913 insertions(+), 1243 deletions(-) create mode 100644 drivers/net/dsa/mt7530-lib.c create mode 100644 drivers/net/dsa/mt7530-lib.h
drivers/net/dsa/Kconfig +4 -0
@@ -28,8 +28,12 @@ source "drivers/net/dsa/hirschmann/Kconfig" source "drivers/net/dsa/lantiq/Kconfig" +config NET_DSA_MT7530_LIB + tristate + config NET_DSA_MT7530 tristate "MediaTek MT7530 and MT7531 Ethernet switch support" + select NET_DSA_MT7530_LIB select NET_DSA_TAG_MTK select REGMAP_IRQ imply NET_DSA_MT7530_MDIO
drivers/net/dsa/Makefile +1 -0
@@ -4,6 +4,7 @@ bcm-sf2-objs := bcm_sf2.o bcm_sf2_cfp.o obj-$(CONFIG_NET_DSA_LOOP) += dsa_loop.o obj-$(CONFIG_NET_DSA_KS8995) += ks8995.o obj-$(CONFIG_NET_DSA_MT7530) += mt7530.o +obj-$(CONFIG_NET_DSA_MT7530_LIB) += mt7530-lib.o obj-$(CONFIG_NET_DSA_MT7530_MDIO) += mt7530-mdio.o obj-$(CONFIG_NET_DSA_MT7530_MMIO) += mt7530-mmio.o obj-$(CONFIG_NET_DSA_MT7628) += mt7628.o
drivers/net/dsa/mt7530-lib.c new file +1128 -0
1,128 lines not on this page · raw message
drivers/net/dsa/mt7530-lib.h new file +391 -0
391 lines not on this page · raw message
drivers/net/dsa/mt7530-mdio.c +4 -0
@@ -218,6 +218,10 @@ mt7530_probe(struct mdio_device *mdiodev)if (IS_ERR (priv->regmap))return PTR_ERR (priv->regmap); + ret =mt7530_setup_lib_priv (priv); +if (ret) +return ret; +if (priv->id ==ID_MT7531 ) priv->create_sgmii = mt7531_create_sgmii;
drivers/net/dsa/mt7530-mmio.c +4 -0
@@ -61,6 +61,10 @@ mt7988_probe(struct platform_device *pdev)if (IS_ERR (priv->regmap))return PTR_ERR (priv->regmap); + ret =mt7530_setup_lib_priv (priv); +if (ret) +return ret; +return dsa_register_switch (priv->ds); }
drivers/net/dsa/mt7530.c +321 -1047
1,442 lines not on this page · raw message
drivers/net/dsa/mt7530.h +60 -196
256 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.53.0
Part of the diff is not shown here. View the raw message.
PATCH v22 9/9 net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver
In reply to Christian MarangiAdd Airoha AN8855 5-Port Gigabit DSA switch. Switch can support 10M, 100M, 1Gb, 2.5G and 5G Ethernet Speed but 5G is currently error out as it's not currently supported as requires additional configuration for the PCS.
--- drivers/net/dsa/Kconfig | 9 + drivers/net/dsa/Makefile | 1 + drivers/net/dsa/an8855.c | 1740 ++++++++++++++++++++++++++++++++++ drivers/net/dsa/an8855.h | 755 +++++++++++++++ drivers/net/dsa/mt7530-lib.c | 68 +- drivers/net/dsa/mt7530-lib.h | 22 + 6 files changed, 2575 insertions(+), 20 deletions(-) create mode 100644 drivers/net/dsa/an8855.c create mode 100644 drivers/net/dsa/an8855.h
drivers/net/dsa/Kconfig +9 -0
@@ -24,6 +24,15 @@ config NET_DSA_LOOP This enables support for a fake mock-up switch chip which exercises the DSA APIs. +config NET_DSA_AN8855 + tristate "Airoha AN8855 Ethernet switch support" + depends on MFD_AIROHA_AN8855 || COMPILE_TEST + depends on NET_DSA + select NET_DSA_TAG_AIROHA + help + This enables support for the Ethernet switch inside the + Airoha AN8855 chip. + source "drivers/net/dsa/hirschmann/Kconfig" source "drivers/net/dsa/lantiq/Kconfig"
drivers/net/dsa/Makefile +1 -0
@@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_NET_DSA_AN8855) += an8855.o obj-$(CONFIG_NET_DSA_BCM_SF2) += bcm-sf2.o bcm-sf2-objs := bcm_sf2.o bcm_sf2_cfp.o obj-$(CONFIG_NET_DSA_LOOP) += dsa_loop.o
drivers/net/dsa/an8855.c new file +1740 -0
1,740 lines not on this page · raw message
drivers/net/dsa/an8855.h new file +755 -0
755 lines not on this page · raw message
drivers/net/dsa/mt7530-lib.c +48 -20
134 lines not on this page · raw message
drivers/net/dsa/mt7530-lib.h +22 -0
@@ -159,6 +159,8 @@ enum mt7530_regmap_field {MT7530_ATWD_AGE_TIMER ,MT7530_ATWD_PORT_MAP ,MT7530_ATWD_ENT_STATUS , +AN8855_ATWD_TYPE , +AN8855_ATWD_VLD ,MT7530_ATWD_MAC_BYTE_5 ,MT7530_ATWD_MAC_BYTE_4 , MT7530_ATWD_MAC_BYTE_3,
@@ -169,11 +171,13 @@ enum mt7530_regmap_field { __MT7530_ATWD1, __MT7530_ATWD2, __MT7530_ATWD3, + __MT7530_ATWD4,MT7530_ATRD_CVID ,MT7530_ATRD_AGE_TIMER ,MT7530_ATRD_PORT_MAP ,MT7530_ATRD_ENT_STATUS , +AN8855_ATRD_ARP ,MT7530_ATRD_MAC_BYTE_5 ,MT7530_ATRD_MAC_BYTE_4 , MT7530_ATRD_MAC_BYTE_3,
@@ -201,6 +205,7 @@ enum mt7530_regmap_field {MT7530_PVC_ACC_FRM ,MT7530_PPBV1_G0_PORT_VID , +AN8855_PVID_G0_PORT_VID ,MT7530_GMACCR_MAX_RX_JUMBO , MT7530_GMACCR_MAX_RX_PKT_LEN,
@@ -223,8 +228,13 @@ enum mt7530_regmap_field {MT7530_MIB_TX_PKT_SZ_256_TO_511 ,MT7530_MIB_TX_PKT_SZ_512_TO_1023 ,MT7530_MIB_TX_PKT_SZ_1024_TO_MAX , +AN8855_MIB_TX_PKT_SZ_1024_TO_1518 , +AN8855_MIB_TX_PKT_SZ_1519_TO_MAX ,MT7530_MIB_TX_BYTES_LOW ,MT7530_MIB_TX_BYTES_HIGH , +AN8855_MIB_TX_OVERSIZE_DROP , +AN8855_MIB_TX_BAD_PKT_BYTES_LOW , +AN8855_MIB_TX_BAD_PKT_BYTES_HIGH ,MT7530_MIB_RX_DROP ,MT7530_MIB_RX_FILTERING , MT7530_MIB_RX_UNICAST,
@@ -243,11 +253,21 @@ enum mt7530_regmap_field {MT7530_MIB_RX_PKT_SZ_256_TO_511 ,MT7530_MIB_RX_PKT_SZ_512_TO_1023 ,MT7530_MIB_RX_PKT_SZ_1024_TO_MAX , +AN8855_MIB_RX_PKT_SZ_1024_TO_1518 , +AN8855_MIB_RX_PKT_SZ_1519_TO_MAX ,MT7530_MIB_RX_BYTES_LOW ,MT7530_MIB_RX_BYTES_HIGH ,MT7530_MIB_RX_CTRL_DROP ,MT7530_MIB_RX_INGRESS_DROP ,MT7530_MIB_RX_ARL_DROP , +AN8855_MIB_FLOW_CONTROL_DROP , +AN8855_MIB_WRED_DROP , +AN8855_MIB_MIRROR_DROP , +AN8855_MIB_RX_BAD_PKT_BYTES_LOW , +AN8855_MIB_RX_BAD_PKT_BYTES_HIGH , +AN8855_MIB_RXS_FLOW_SAMPLING_PKT_DROP , +AN8855_MIB_RXS_FLOW_TOTAL_PKT_DROP , +AN8855_MIB_PORT_CONTROL_DROP , MT7530_FIELD_MAX, };
@@ -385,6 +405,8 @@ int mt7530_lib_port_vlan_add(struct mt7530_lib_priv *priv, int port,int mt7530_lib_port_vlan_del (struct mt7530_lib_priv *priv,int port,const struct switchdev_obj_port_vlan *vlan); +void mt7530_port_set_pvid (struct mt7530_lib_priv *priv,int port, +u16 pvid);int mt7530_lib_setup_vlan0 (struct mt7530_lib_priv *priv);#endif /* __MT7530_LIB_H */
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH net-next v22 9/9] net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] net: dsa: global mutex held during prolonged usleep in FDB dump - [Medium] net: dsa: duplication…
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] net: dsa: global mutex held during prolonged usleep in FDB dump
- [Medium] net: dsa: duplication of standard network stats in ethtool -S
- [Medium] net: dsa: TOCTOU race in global LPI timer update
- [Low] net: dsa: build failure due to missing NET_DSA_MT7530_LIB select
--
commit fa68dc35bd25774dad4403daf011bd3b273453f6
Author: Christian Marangi <[email protected]>
net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver
This commit adds support for the Airoha AN8855 5-Port Gigabit Ethernet switch. It implements switch setup, link configuration, FDB management, and statistics reading using functions exported by the mt7530-lib.
Quoted 4 lines
drivers/net/dsa/Kconfig +0
-0
[ ... ]
drivers/net/dsa/Kconfig config NET_DSA_LOOP · line 31
Quoted 9 lines
drivers/net/dsa/Kconfig +5
-0@@ -24,6 +24,15 @@ config NET_DSA_LOOP This enables support for a fake mock-up switch chip which exercises the DSA APIs. +config NET_DSA_AN8855 + tristate "Airoha AN8855 Ethernet switch support" + depends on MFD_AIROHA_AN8855 || COMPILE_TEST + depends on NET_DSA + select NET_DSA_TAG_AIROHA
[Severity: Low]
Will this driver fail to link if CONFIG_NET_DSA_AN8855 is enabled but CONFIG_NET_DSA_MT7530_LIB is not? The an8855 driver relies on functions exported by mt7530-lib.c, so it seems this configuration should explicitly select NET_DSA_MT7530_LIB to prevent build failures.
Quoted 11 lines
drivers/net/dsa/Kconfig +4
-0+ help + This enables support for the Ethernet switch inside the + Airoha AN8855 chip. + source "drivers/net/dsa/hirschmann/Kconfig"drivers/net/dsa/an8855.c new file +0
-0
[ ... ]
drivers/net/dsa/an8855.c line 187
Quoted 5 lines
drivers/net/dsa/an8855.c new file +5
-0+static const struct mt7530_mib_desc an8855_mib[] = { +MIB_DESC (MT7530_MIB_TX_DROP ,-1 ,"TxDrop" ), +MIB_DESC (MT7530_MIB_TX_CRC_ERR ,-1 ,"TxCrcErr" ), +MIB_DESC (MT7530_MIB_TX_COLLISION ,-1 ,"TxCollision" ), +MIB_DESC (AN8855_MIB_TX_OVERSIZE_DROP ,-1 ,"TxOversizeDrop" ),
[Severity: Medium]
Are these counters duplicating statistics that already have standard network representations? The networking subsystem guidelines prohibit exposing standard counters like TxDrop, TxCrcErr, and TxCollision through the driver-private ethtool -S interface, especially since they are already supported via standard mechanisms.
[ ... ]
Quoted 10 lines
drivers/net/dsa/an8855.c new file +10
-0+static int an8855_port_fdb_dump (struct dsa_switch *ds,int port, +dsa_fdb_dump_cb_t *cb,void *data) +{ +struct an8855_priv *priv = ds->priv; +int banks, count =0 ; +u32 rsp; +int ret; +int i; + +mutex_lock (&priv->reg_mutex);
[ ... ]
Quoted 1 line
drivers/net/dsa/an8855.c new file +1
-0+ do {
[ ... ]
Quoted 8 lines
drivers/net/dsa/an8855.c new file +8
-0+/* Each banks have 4 entry */ +for (i =0 ; i <4 ; i++) { +struct mt7530_fdb _fdb = { }; + + count++; + +/* Check if bank is present */ +if (!(banks &BIT (i)))
drivers/net/dsa/an8855.c line 387
Quoted 10 lines
drivers/net/dsa/an8855.c new file +10
-0+continue ; + +/* Select bank entry index */ + ret =regmap_write (priv->regmap,AN8855_ATRDS , +FIELD_PREP (AN8855_ATRD_SEL , i)); +if (ret) +break ; +/* wait 1ms for the bank entry to be filled */ +usleep_range (1000 ,1500 ); +mt7530_lib_fdb_read (&priv->lib_priv, &_fdb);
[Severity: High]
Does this sequence severely degrade performance by forcing an artificial sleep while holding the main driver mutex? Since the loop inside an8855_port_fdb_dump() can process up to 2048 entries, holding priv->reg_mutex while sleeping for 1-1.5ms per entry could stall all other control operations on the switch for over 2 seconds.
[ ... ]
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 16 lines
drivers/net/dsa/an8855.c new file +16
-0+if (timer) { +int i; + +/* Save requested timer and search the highest one */ +mutex_lock (&priv->reg_mutex); + priv->tx_lpi_timer_ports[dp->index] = timer; +for (i =0 ; i <AN8855_NUM_PORTS ; i++) { +if (!priv->ports[i].enable) +continue ; + +if (i == dp->index) +continue ; + +if (timer < priv->tx_lpi_timer_ports[i]) + timer = priv->tx_lpi_timer_ports[i]; + }
drivers/net/dsa/an8855.c line 1016
Quoted 10 lines
drivers/net/dsa/an8855.c new file +10
-0+mutex_unlock (&priv->reg_mutex); + + timer /=AN8855_TX_LPI_UNIT ; +if (FIELD_FIT (AN8855_LPI_TXIDLE_THD_MASK , timer)) + val =FIELD_PREP (AN8855_LPI_TXIDLE_THD_MASK , timer); +else + val =AN8855_LPI_TXIDLE_THD_MASK ; + + ret =regmap_update_bits (priv->regmap,AN8855_CKGCR , +AN8855_LPI_TXIDLE_THD_MASK , val);
[Severity: Medium]
Can this sequence lead to a race condition where the global LPI timer is updated to a stale value? By releasing priv->reg_mutex before calling regmap_update_bits() on the shared AN8855_CKGCR register, two concurrent updates from different ports might interleave and write an older timer value over a newer one.
Quoted 4 lines
drivers/net/dsa/an8855.c new file +4
-0+if (ret) { +dev_err (dp->ds->dev,"failed to set global LPI timer\n" ); +return ret; + }
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9