net: dsa: Add Airoha AN8855 support
Subsystems (9)
v12 cover net: dsa: Add Airoha AN8855 support
This small 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.
It's conceptually similar to mediatek switch but register and bits are different. And there is that massive Hell that is the PCS configuration.
Saddly for that part we have absolutely NO documentation currently.
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)
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 2 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
[ For Vladimir, I still have to implement fdb_isolation but posting to start the ball rolling for the multiple subsystem this patch affect and for the dubious DT schema ]
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 (13):
dt-bindings: nvmem: Document support for Airoha AN8855 Switch EFUSE
dt-bindings: net: Document support for Airoha AN8855 Switch Virtual
MDIO
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
net: mdio: regmap: prepare support for multiple valid addr
net: mdio: regmap: add support for multiple valid addr
net: mdio: regmap: add OF support
mfd: an8855: Add support for Airoha AN8855 Switch MFD
net: mdio: Add Airoha AN8855 Switch MDIO Passtrough
nvmem: an8855: Add support for Airoha AN8855 Switch EFUSE
net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver
net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY
.../bindings/mfd/airoha,an8855.yaml | 186 ++ .../bindings/net/airoha,an8855-mdio.yaml | 56 + .../bindings/net/airoha,an8855-phy.yaml | 93 + .../net/dsa/airoha,an8855-switch.yaml | 105 + .../bindings/nvmem/airoha,an8855-efuse.yaml | 123 + MAINTAINERS | 18 + drivers/mfd/Kconfig | 10 + drivers/mfd/Makefile | 1 + drivers/mfd/airoha-an8855.c | 445 ++++ drivers/net/dsa/Kconfig | 9 + drivers/net/dsa/Makefile | 1 + drivers/net/dsa/an8855.c | 2296 +++++++++++++++++ drivers/net/dsa/an8855.h | 771 ++++++ drivers/net/mdio/Kconfig | 10 + drivers/net/mdio/Makefile | 1 + drivers/net/mdio/mdio-an8855.c | 48 + drivers/net/mdio/mdio-regmap.c | 24 +- drivers/net/phy/Kconfig | 5 + drivers/net/phy/Makefile | 1 + drivers/net/phy/air_an8855.c | 261 ++ drivers/nvmem/Kconfig | 11 + drivers/nvmem/Makefile | 2 + drivers/nvmem/an8855-efuse.c | 63 + include/linux/mdio/mdio-regmap.h | 10 + 24 files changed, 4544 insertions(+), 6 deletions(-) create mode 100644 Documentation/devicetree/bindings/mfd/airoha,an8855.yaml create mode 100644 Documentation/devicetree/bindings/net/airoha,an8855-mdio.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 Documentation/devicetree/bindings/nvmem/airoha,an8855-efuse.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/mdio/mdio-an8855.c create mode 100644 drivers/net/phy/air_an8855.c create mode 100644 drivers/nvmem/an8855-efuse.c
Signature · 1 line
2.48.1
PATCH v12 1/13 dt-bindings: nvmem: Document support for Airoha AN8855 Switch EFUSE
Document support for Airoha AN8855 Switch EFUSE used to calibrate internal PHYs and store additional configuration info.
--- .../bindings/nvmem/airoha,an8855-efuse.yaml | 123 ++++++++++++++++++ MAINTAINERS | 8 ++ 2 files changed, 131 insertions(+) create mode 100644 Documentation/devicetree/bindings/nvmem/airoha,an8855-efuse.yaml
Documentation/devicetree/bindings/nvmem/airoha,an8855-efuse.yaml new file +123 -0
@@ -0,0 +1,123 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/nvmem/airoha,an8855-efuse.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Airoha AN8855 Switch EFUSE + +maintainers: + - Christian Marangi <[email protected]> + +description: + Airoha AN8855 EFUSE used to calibrate internal PHYs and store additional + configuration info. + +$ref: nvmem.yaml# + +properties: + compatible: + const: airoha,an8855-efuse + + '#nvmem-cell-cells': + const: 0 + +required: + - compatible + - '#nvmem-cell-cells' + +unevaluatedProperties: false + +examples: + - | + 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>; + }; + + shift_sel_port2_tx_a: shift-sel-port2-tx-a@2c { + reg = <0x2c 0x4>; + }; + + shift_sel_port2_tx_b: shift-sel-port2-tx-b@30 { + reg = <0x30 0x4>; + }; + + shift_sel_port2_tx_c: shift-sel-port2-tx-c@34 { + reg = <0x34 0x4>; + }; + + shift_sel_port2_tx_d: shift-sel-port2-tx-d@38 { + reg = <0x38 0x4>; + }; + + shift_sel_port3_tx_a: shift-sel-port3-tx-a@4c { + reg = <0x4c 0x4>; + }; + + shift_sel_port3_tx_b: shift-sel-port3-tx-b@50 { + reg = <0x50 0x4>; + }; + + shift_sel_port3_tx_c: shift-sel-port3-tx-c@54 { + reg = <0x54 0x4>; + }; + + shift_sel_port3_tx_d: shift-sel-port3-tx-d@58 { + reg = <0x58 0x4>; + }; + + shift_sel_port4_tx_a: shift-sel-port4-tx-a@5c { + reg = <0x5c 0x4>; + }; + + shift_sel_port4_tx_b: shift-sel-port4-tx-b@60 { + reg = <0x60 0x4>; + }; + + shift_sel_port4_tx_c: shift-sel-port4-tx-c@64 { + reg = <0x64 0x4>; + }; + + shift_sel_port4_tx_d: shift-sel-port4-tx-d@68 { + reg = <0x68 0x4>; + }; + }; + };
MAINTAINERS +8 -0
@@ -719,6 +719,14 @@ S: Supported F: fs/aio.c F: include/linux/*aio*.h +AIROHA 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/nvmem/airoha,an8855-efuse.yaml + AIROHA ETHERNET DRIVER M: Lorenzo Bianconi <[email protected]> L: [email protected] (moderated for non-subscribers)
Signature · 1 line
2.48.1
PATCH v12 2/13 dt-bindings: net: Document support for Airoha AN8855 Switch Virtual MDIO
In reply to Christian MarangiDocument support for Airoha AN8855 Virtual MDIO Passtrough. This is needed as AN8855 require special handling as the same address on the MDIO bus is shared for both Switch and PHY and special handling for the page configuration is needed to switch accessing to Switch address space or PHY.
--- .../bindings/net/airoha,an8855-mdio.yaml | 56 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 57 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/airoha,an8855-mdio.yaml
Documentation/devicetree/bindings/net/airoha,an8855-mdio.yaml new file +56 -0
@@ -0,0 +1,56 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/airoha,an8855-mdio.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Airoha AN8855 MDIO Passtrough + +maintainers: + - Christian Marangi <[email protected]> + +description: + Airoha AN8855 Virtual MDIO Passtrough. This is needed as AN8855 + require special handling as the same address on the MDIO bus is + shared for both Switch and PHY and special handling for the page + configuration is needed to switch accessing to Switch address space + or PHY. + +$ref: /schemas/net/mdio.yaml# + +properties: + compatible: + const: airoha,an8855-mdio + +required: + - compatible + +unevaluatedProperties: false + +examples: + - | + mdio { + compatible = "airoha,an8855-mdio"; + #address-cells = <1>; + #size-cells = <0>; + + internal_phy1: phy@1 { + reg = <1>; + }; + + internal_phy2: phy@2 { + reg = <2>; + }; + + internal_phy3: phy@3 { + reg = <3>; + }; + + internal_phy4: phy@4 { + reg = <4>; + }; + + internal_phy5: phy@5 { + reg = <5>; + }; + };
MAINTAINERS +1 -0
@@ -725,6 +725,7 @@ L: [email protected] (moderated for non-subscribers) L: [email protected] (moderated for non-subscribers) L: [email protected] S: Maintained +F: Documentation/devicetree/bindings/net/airoha,an8855-mdio.yaml F: Documentation/devicetree/bindings/nvmem/airoha,an8855-efuse.yaml AIROHA ETHERNET DRIVER
Signature · 1 line
2.48.1
Simon Horman
reviewerRe: [net-next PATCH v12 02/13] dt-bindings: net: Document support for Airoha AN8855 Switch Virtual MDIO
Quoted 1 line · Christian Marangi
Document support for Airoha AN8855 Virtual MDIO Passtrough. This is needed
nit: passthrough
Quoted 19 lines
as AN8855 require special handling as the same address on the MDIO bus is shared for both Switch and PHY and special handling for the page configuration is needed to switch accessing to Switch address space or PHY.
Signed-off-by Christian Marangi <[email protected]>Reviewed-by Rob Herring (Arm) <[email protected]>--- .../bindings/net/airoha,an8855-mdio.yaml | 56 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 57 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/airoha,an8855-mdio.yamlDocumentation/devicetree/bindings/net/airoha,an8855-mdio.yaml new file +0
-0
Documentation/devicetree/bindings/net/airoha,an8855-mdio.yaml line 7
Quoted 7 lines
Documentation/devicetree/bindings/net/airoha,an8855-mdio.yaml new file +7
-0@@ -0,0 +1,56 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/airoha,an8855-mdio.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Airoha AN8855 MDIO Passtrough
Ditto.
Documentation/devicetree/bindings/net/airoha,an8855-mdio.yaml line 13
Quoted 6 lines
Documentation/devicetree/bindings/net/airoha,an8855-mdio.yaml new file +6
-0+ +maintainers: + - Christian Marangi <[email protected]> + +description: + Airoha AN8855 Virtual MDIO Passtrough. This is needed as AN8855
Ditto.
Quoted 4 lines
Documentation/devicetree/bindings/net/airoha,an8855-mdio.yaml new file +4
-0+ require special handling as the same address on the MDIO bus is + shared for both Switch and PHY and special handling for the page + configuration is needed to switch accessing to Switch address space + or PHY.
...
PATCH v12 3/13 dt-bindings: net: dsa: Document support for Airoha AN8855 DSA Switch
In reply to Christian MarangiDocument 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 configurting the PHY page.
Each internal PHY might require calibration with the fused EFUSE on the switch exposed by the Airoha AN8855 SoC NVMEM.
--- .../net/dsa/airoha,an8855-switch.yaml | 105 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 106 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml
Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml new file +105 -0
@@ -0,0 +1,105 @@ +# 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 configurting the PHY page. + + Each internal PHY might require calibration with the fused EFUSE on + the switch exposed by the Airoha AN8855 SoC NVMEM. + +$ref: dsa.yaml# + +properties: + compatible: + const: airoha,an8855-switch + + reset-gpios: + description: + GPIO to be used to reset the whole device + maxItems: 1 + + airoha,ext-surge: + $ref: /schemas/types.yaml#/definitions/flag + description: + Calibrate the internal PHY with the calibration values stored in EFUSE + for the r50Ohm values. + +required: + - compatible + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/gpio/gpio.h> + + ethernet-switch { + compatible = "airoha,an8855-switch"; + reset-gpios = <&pio 39 0>; + + airoha,ext-surge; + + 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; + }; + }; + }; + };
MAINTAINERS +1 -0
@@ -726,6 +726,7 @@ L: [email protected] (moderated for non-subscribers) L: [email protected] S: Maintained F: Documentation/devicetree/bindings/net/airoha,an8855-mdio.yaml +F: Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml F: Documentation/devicetree/bindings/nvmem/airoha,an8855-efuse.yaml AIROHA ETHERNET DRIVER
Signature · 1 line
2.48.1
Rob Herring
maintainerRe: [net-next PATCH v12 03/13] dt-bindings: net: dsa: Document support for Airoha AN8855 DSA Switch
Quoted 32 lines · Christian Marangi
Document support for Airoha AN8855 5-port Gigabit Switch.
It does expose the 5 Internal PHYs on the MDIO bus and each port can access the Switch register space by configurting the PHY page.
Each internal PHY might require calibration with the fused EFUSE on the switch exposed by the Airoha AN8855 SoC NVMEM.
Signed-off-by Christian Marangi <[email protected]>--- .../net/dsa/airoha,an8855-switch.yaml | 105 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 106 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yamlDocumentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml new file +11
-0@@ -0,0 +1,105 @@ +# 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]> +
Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml line 21
Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml new file +10
-0+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 configurting the PHY page. + + Each internal PHY might require calibration with the fused EFUSE on + the switch exposed by the Airoha AN8855 SoC NVMEM. + +$ref: dsa.yaml#
This needs to be:
dsa.yaml#/$defs/ethernet-ports
As that restricts custom properties.
Quoted 5 lines
Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml new file +5
-0+ +properties: + compatible: + const: airoha,an8855-switch +
Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml line 36
Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml new file +10
-0+ reset-gpios: + description: + GPIO to be used to reset the whole device + maxItems: 1 + + airoha,ext-surge: + $ref: /schemas/types.yaml#/definitions/flag + description: + Calibrate the internal PHY with the calibration values stored in EFUSE + for the r50Ohm values.
Should you be using nvmem binding to the efuse block? Or the efuses are within this block?
Quoted 5 lines
Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml new file +5
-0+ +required: + - compatible + +unevaluatedProperties: false
Simon Horman
reviewerRe: [net-next PATCH v12 03/13] dt-bindings: net: dsa: Document support for Airoha AN8855 DSA Switch
In reply to Christian MarangiQuoted 4 lines · Christian Marangi
Document support for Airoha AN8855 5-port Gigabit Switch.
It does expose the 5 Internal PHYs on the MDIO bus and each port can access the Switch register space by configurting the PHY page.
nit: configuring
Quoted 23 lines
Each internal PHY might require calibration with the fused EFUSE on the switch exposed by the Airoha AN8855 SoC NVMEM.
Signed-off-by Christian Marangi <[email protected]>--- .../net/dsa/airoha,an8855-switch.yaml | 105 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 106 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yamlDocumentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml new file +6
-0@@ -0,0 +1,105 @@ +# 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# +
Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml line 16
Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml new file +10
-0+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 configurting the PHY page.
Ditto.
Quoted 3 lines
Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml new file +3
-0+ + Each internal PHY might require calibration with the fused EFUSE on + the switch exposed by the Airoha AN8855 SoC NVMEM.
...
PATCH v12 4/13 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 "airoha,ext-surge" property.
--- .../bindings/net/airoha,an8855-phy.yaml | 93 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 94 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml
Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml new file +93 -0
@@ -0,0 +1,93 @@ +# 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 + + airoha,ext-surge: + description: enable PHY calibration with the use of SoC eFUSE. + + 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 + +if: + required: + - airoha,ext-surge +then: + required: + - 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>; + + airoha,ext-surge; + + 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"; + }; + };
MAINTAINERS +1 -0
@@ -726,6 +726,7 @@ L: [email protected] (moderated for non-subscribers) L: [email protected] S: Maintained F: Documentation/devicetree/bindings/net/airoha,an8855-mdio.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
Signature · 1 line
2.48.1
Rob Herring
maintainerRe: [net-next PATCH v12 04/13] dt-bindings: net: Document support for AN8855 Switch Internal PHY
Quoted 48 lines · 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 "airoha,ext-surge" property.
Signed-off-by Christian Marangi <[email protected]>--- .../bindings/net/airoha,an8855-phy.yaml | 93 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 94 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/airoha,an8855-phy.yamlDocumentation/devicetree/bindings/net/airoha,an8855-phy.yaml new file +26
-0@@ -0,0 +1,93 @@ +# 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:
Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml line 36
Quoted 10 lines
Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml new file +10
-0+ - ethernet-phy-idc0ff.0410 + required: + - compatible + +properties: + reg: + maxItems: 1 + + airoha,ext-surge: + description: enable PHY calibration with the use of SoC eFUSE.
Wouldn't nvmem-cells presence enable this?
Quoted 16 lines
Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml new file +16
-0+ + 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:
Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml line 62
Quoted 10 lines
Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml new file +10
-0+ - compatible + - reg + +if: + required: + - airoha,ext-surge +then: + required: + - nvmem-cells + - nvmem-cell-names
dependentRequired:
airoha,ext-surge: [ nvmem-cells, nvmem-cell-names ]
Quoted 46 lines
Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml new file +31
-0+ +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>; + + airoha,ext-surge; + + 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"; + }; + };MAINTAINERS +1
-0@@ -726,6 +726,7 @@ L: [email protected] (moderated for non-subscribers) L: [email protected] S: Maintained F: Documentation/devicetree/bindings/net/airoha,an8855-mdio.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.yamlSignature · 1 line
2.48.1
PATCH v12 5/13 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 | 186 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 187 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/airoha,an8855.yaml
Documentation/devicetree/bindings/mfd/airoha,an8855.yaml new file +186 -0
@@ -0,0 +1,186 @@ +# 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 + + efuse: + type: object + $ref: /schemas/nvmem/airoha,an8855-efuse.yaml + description: + EFUSE exposed by the Airoha AN8855 Switch. This child node definition + should follow the bindings specified in + Documentation/devicetree/bindings/nvmem/airoha,an8855-efuse.yaml + + ethernet-switch: + type: object + $ref: /schemas/net/dsa/airoha,an8855-switch.yaml + description: + Switch exposed by the Airoha AN8855 Switch. This child node definition + should follow the bindings specified in + Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml + + mdio: + type: object + $ref: /schemas/net/airoha,an8855-mdio.yaml + description: + MDIO exposed by the Airoha AN8855 Switch. This child node definition + should follow the bindings specified in + Documentation/devicetree/bindings/net/airoha,an8855-mdio.yaml + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + #include <dt-bindings/gpio/gpio.h> + + mdio { + #address-cells = <1>; + #size-cells = <0>; + + soc@1 { + compatible = "airoha,an8855"; + reg = <1>; + + 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"; + + reset-gpios = <&pio 39 0>; + + airoha,ext-surge; + + 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 { + compatible = "airoha,an8855-mdio"; + #address-cells = <1>; + #size-cells = <0>; + + internal_phy1: phy@1 { + compatible = "ethernet-phy-idc0ff.0410", + "ethernet-phy-ieee802.3-c45"; + reg = <1>; + + airoha,ext-surge; + + 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: phy@2 { + compatible = "ethernet-phy-idc0ff.0410", + "ethernet-phy-ieee802.3-c45"; + reg = <2>; + + airoha,ext-surge; + + 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"; + }; + }; + }; + };
MAINTAINERS +1 -0
@@ -725,6 +725,7 @@ 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-mfd.yaml F: Documentation/devicetree/bindings/net/airoha,an8855-mdio.yaml F: Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml F: Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml
Signature · 1 line
2.48.1
Rob Herring (Arm)
maintainerRe: [net-next PATCH v12 05/13] dt-bindings: mfd: Document support for Airoha AN8855 Switch SoC
Quoted 6 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.
Quoted 7 lines
Signed-off-by Christian Marangi <[email protected]>--- .../bindings/mfd/airoha,an8855.yaml | 186 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 187 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/airoha,an8855.yaml
My bot found errors running 'make dt_binding_check' on your patch:
yamllint warnings/errors:
dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/mfd/airoha,an8855.example.dtb: phy@1: $nodename:0: 'phy@1' does not match '^ethernet-phy(@[a-f0-9]+)?$'
from schema $id: http://devicetree.org/schemas/net/airoha,an8855-phy.yaml#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/mfd/airoha,an8855.example.dtb: phy@1: Unevaluated properties are not allowed ('compatible' was unexpected)
from schema $id: http://devicetree.org/schemas/net/airoha,an8855-phy.yaml#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/mfd/airoha,an8855.example.dtb: phy@2: $nodename:0: 'phy@2' does not match '^ethernet-phy(@[a-f0-9]+)?$'
from schema $id: http://devicetree.org/schemas/net/airoha,an8855-phy.yaml#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/mfd/airoha,an8855.example.dtb: phy@2: Unevaluated properties are not allowed ('compatible' was unexpected)
from schema $id: http://devicetree.org/schemas/net/airoha,an8855-phy.yaml#
doc reference errors (make refcheckdocs):
Warning: MAINTAINERS references a file that doesn't exist: Documentation/devicetree/bindings/mfd/airoha,an8855-mfd.yamlMAINTAINERS: Documentation/devicetree/bindings/mfd/airoha,an8855-mfd.yaml
See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/[email protected]
The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.
If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:
pip3 install dtschema --upgrade
Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.
kernel test robot
build botRe: [net-next PATCH v12 05/13] dt-bindings: mfd: Document support for Airoha AN8855 Switch SoC
In reply to Christian Marangikernel test robot noticed the following build warnings:
Hi Christian,
kernel test robot noticed the following build warnings:
[auto build test WARNING on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Christian-Marangi/dt-bindings-nvmem-Document-support-for-Airoha-AN8855-Switch-EFUSE/20250310-013306 base: net-next/main patch link: https://lore.kernel.org/r/20250309172717.9067-6-ansuelsmth%40gmail.com patch subject: [net-next PATCH v12 05/13] dt-bindings: mfd: Document support for Airoha AN8855 Switch SoC reproduce: (https://download.01.org/0day-ci/archive/20250310/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
Warning: Documentation/translations/ja_JP/SubmittingPatches references a file that doesn't exist: linux-2.6.12-vanilla/Documentation/dontdiff
Warning: Documentation/translations/zh_CN/admin-guide/README.rst references a file that doesn't exist: Documentation/dev-tools/kgdb.rst
Warning: Documentation/translations/zh_CN/dev-tools/gdb-kernel-debugging.rst references a file that doesn't exist: Documentation/dev-tools/gdb-kernel-debugging.rst
Warning: Documentation/translations/zh_TW/admin-guide/README.rst references a file that doesn't exist: Documentation/dev-tools/kgdb.rst
Warning: Documentation/translations/zh_TW/dev-tools/gdb-kernel-debugging.rst references a file that doesn't exist: Documentation/dev-tools/gdb-kernel-debugging.rst
>> Warning: MAINTAINERS references a file that doesn't exist: Documentation/devicetree/bindings/mfd/airoha,an8855-mfd.yaml
Warning: MAINTAINERS references a file that doesn't exist: Documentation/devicetree/bindings/misc/fsl,qoriq-mc.txt
Warning: MAINTAINERS references a file that doesn't exist: Documentation/devicetree/bindings/leds/backlight/ti,lp8864.yaml
Warning: lib/Kconfig.debug references a file that doesn't exist: Documentation/dev-tools/fault-injection/fault-injection.rst Using alabaster theme
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH v12 6/13 net: mdio: regmap: prepare support for multiple valid addr
In reply to Christian MarangiRework the valid_addr and convert it to a mask in preparation for mdio regmap to support multiple valid addr in the case the regmap can support it.
--- drivers/net/mdio/mdio-regmap.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/net/mdio/mdio-regmap.c +5 -5
@@ -19,7 +19,7 @@struct mdio_regmap_priv {struct regmap *regmap; -u8 valid_addr; +u32 valid_addr_mask; };static int mdio_regmap_read_c22 (struct mii_bus *bus,int addr,int regnum)
@@ -28,7 +28,7 @@ static int mdio_regmap_read_c22(struct mii_bus *bus, int addr, int regnum)unsigned int val;int ret; -if (ctx->valid_addr != addr) +if (!(ctx->valid_addr_mask &BIT (addr)))return -ENODEV ; ret =regmap_read (ctx->regmap, regnum, &val);
@@ -43,7 +43,7 @@ static int mdio_regmap_write_c22(struct mii_bus *bus, int addr, int regnum, {struct mdio_regmap_priv *ctx = bus->priv; -if (ctx->valid_addr != addr) +if (!(ctx->valid_addr_mask &BIT (addr)))return -ENODEV ;return regmap_write (ctx->regmap, regnum, val);
@@ -65,7 +65,7 @@ struct mii_bus *devm_mdio_regmap_register(struct device *dev, mr = mii->priv; mr->regmap = config->regmap; - mr->valid_addr = config->valid_addr; + mr->valid_addr_mask =BIT (config->valid_addr); mii->name =DRV_NAME ;strscpy (mii->id, config->name,MII_BUS_ID_SIZE );
@@ -74,7 +74,7 @@ struct mii_bus *devm_mdio_regmap_register(struct device *dev, mii->write = mdio_regmap_write_c22;if (config->autoscan) - mii->phy_mask = ~BIT (config->valid_addr); + mii->phy_mask = ~mr->valid_addr_mask;else mii->phy_mask = ~0 ;
Signature · 1 line
2.48.1
PATCH v12 7/13 net: mdio: regmap: add support for multiple valid addr
In reply to Christian MarangiAdd support for multiple valid addr for mdio regmap. This can be done by defining the new valid_addr_mask value in the mdio regmap config.
In such case, the PHY address is appended to the regmap regnum right after the first 16 bit of the PHY register used for the read/write operation.
The passed regmap will then extract the address from the passed regnum and execute the needed operations accordingly.
Notice that if valid_addr_mask, the unique valid_addr in config is ignored.
--- drivers/net/mdio/mdio-regmap.c | 14 +++++++++++++- include/linux/mdio/mdio-regmap.h | 9 +++++++++ 2 files changed, 22 insertions(+), 1 deletion(-)
drivers/net/mdio/mdio-regmap.c +13 -1
@@ -20,6 +20,7 @@struct mdio_regmap_priv {struct regmap *regmap;u32 valid_addr_mask; +bool append_addr; };static int mdio_regmap_read_c22 (struct mii_bus *bus,int addr,int regnum)
@@ -31,6 +32,9 @@ static int mdio_regmap_read_c22(struct mii_bus *bus, int addr, int regnum)if (!(ctx->valid_addr_mask &BIT (addr)))return -ENODEV ; +if (ctx->append_addr) + regnum |=FIELD_PREP (MDIO_REGMAP_PHY_ADDR , addr); + ret =regmap_read (ctx->regmap, regnum, &val);if (ret <0 )return ret;
@@ -46,6 +50,9 @@ static int mdio_regmap_write_c22(struct mii_bus *bus, int addr, int regnum,if (!(ctx->valid_addr_mask &BIT (addr)))return -ENODEV ; +if (ctx->append_addr) + regnum |=FIELD_PREP (MDIO_REGMAP_PHY_ADDR , addr); +return regmap_write (ctx->regmap, regnum, val); }
@@ -65,7 +72,12 @@ struct mii_bus *devm_mdio_regmap_register(struct device *dev, mr = mii->priv; mr->regmap = config->regmap; - mr->valid_addr_mask =BIT (config->valid_addr); +if (config->valid_addr_mask) { + mr->valid_addr_mask = config->valid_addr_mask; + mr->append_addr = true; + }else { + mr->valid_addr_mask =BIT (config->valid_addr); + } mii->name =DRV_NAME ;strscpy (mii->id, config->name,MII_BUS_ID_SIZE );
include/linux/mdio/mdio-regmap.h +9 -0
@@ -12,11 +12,20 @@struct device ;struct regmap ; +/* If a non empty valid_addr_mask is passed, PHY address and +* read/write register are encoded in the regmap register +* by placing the register in the first 16 bits and the PHY address +* right after. +*/ +#define MDIO_REGMAP_PHY_ADDR GENMASK(20, 16) +#define MDIO_REGMAP_PHY_REG GENMASK(15, 0) +struct mdio_regmap_config {struct device *parent;struct regmap *regmap;char name[MII_BUS_ID_SIZE ];u8 valid_addr; +u32 valid_addr_mask;bool autoscan; };
Signature · 1 line
2.48.1
Russell King (Oracle)
reviewerRe: [net-next PATCH v12 07/13] net: mdio: regmap: add support for multiple valid addr
include/linux/mdio/mdio-regmap.h line 21
Quoted 7 lines · Christian Marangi
include/linux/mdio/mdio-regmap.h +7
-0+/* If a non empty valid_addr_mask is passed, PHY address and +* read/write register are encoded in the regmap register +* by placing the register in the first 16 bits and the PHY address +* right after. +*/ +#define MDIO_REGMAP_PHY_ADDR GENMASK(20, 16) +#define MDIO_REGMAP_PHY_REG GENMASK(15, 0)
Clause 45 PHYs have 5 bits of PHY address, then 5 bits of mmd address, and then 16 bits of register address - significant in that order. Can we adjust the mask for the PHY address later to add the MMD between the PHY address and register number?
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Re: [net-next PATCH v12 07/13] net: mdio: regmap: add support for multiple valid addr
Quoted 14 lines · Russell King (Oracle)
include/linux/mdio/mdio-regmap.h line 21
Quoted 7 lines · Christian Marangi
include/linux/mdio/mdio-regmap.h +7
-0+/* If a non empty valid_addr_mask is passed, PHY address and +* read/write register are encoded in the regmap register +* by placing the register in the first 16 bits and the PHY address +* right after. +*/ +#define MDIO_REGMAP_PHY_ADDR GENMASK(20, 16) +#define MDIO_REGMAP_PHY_REG GENMASK(15, 0)Clause 45 PHYs have 5 bits of PHY address, then 5 bits of mmd address, and then 16 bits of register address - significant in that order. Can we adjust the mask for the PHY address later to add the MMD between the PHY address and register number?
Honestly to future proof this, I think a good idea might be to add helper to encode these info and use Clause 45 format even for C22. Maybe we can use an extra bit to signal if the format is C22 or C45.
BIT(26) 0: C22 1:C45GENMASK(25, 21) PHY ADDRGENMASK(20, 16) MMD ADDRGENMASK(15, 0) REG
What do you think?
Signature · 1 line
Ansuel
Andrew Lunn
maintainerRe: [net-next PATCH v12 07/13] net: mdio: regmap: add support for multiple valid addr
Quoted 16 lines · Christian Marangi
Quoted 14 lines · Russell King (Oracle)
include/linux/mdio/mdio-regmap.h line 21
Quoted 7 lines · Christian Marangi
include/linux/mdio/mdio-regmap.h +7
-0+/* If a non empty valid_addr_mask is passed, PHY address and +* read/write register are encoded in the regmap register +* by placing the register in the first 16 bits and the PHY address +* right after. +*/ +#define MDIO_REGMAP_PHY_ADDR GENMASK(20, 16) +#define MDIO_REGMAP_PHY_REG GENMASK(15, 0)Clause 45 PHYs have 5 bits of PHY address, then 5 bits of mmd address, and then 16 bits of register address - significant in that order. Can we adjust the mask for the PHY address later to add the MMD between the PHY address and register number?
Quoted 8 lines
Honestly to future proof this, I think a good idea might be to add helper to encode these info and use Clause 45 format even for C22. Maybe we can use an extra bit to signal if the format is C22 or C45.
BIT(26) 0: C22 1:C45
GENMASK(25, 21)PHY ADDRGENMASK(20, 16)MMD ADDRGENMASK(15, 0)REG
If you look back at older kernels, there was some helpers to do something like this, but the C22/C45 was in bit 31. When i cleaned up MDIO drivers to have separate C22 and C45 read/write functions, they become redundant and they were removed. You might want to bring them back again.
Andrew
Russell King (Oracle)
reviewerRe: [net-next PATCH v12 07/13] net: mdio: regmap: add support for multiple valid addr
Quoted 26 lines · Andrew Lunn
Quoted 16 lines · Christian Marangi
Quoted 14 lines · Russell King (Oracle)
include/linux/mdio/mdio-regmap.h line 21
Quoted 7 lines · Christian Marangi
include/linux/mdio/mdio-regmap.h +7
-0+/* If a non empty valid_addr_mask is passed, PHY address and +* read/write register are encoded in the regmap register +* by placing the register in the first 16 bits and the PHY address +* right after. +*/ +#define MDIO_REGMAP_PHY_ADDR GENMASK(20, 16) +#define MDIO_REGMAP_PHY_REG GENMASK(15, 0)Clause 45 PHYs have 5 bits of PHY address, then 5 bits of mmd address, and then 16 bits of register address - significant in that order. Can we adjust the mask for the PHY address later to add the MMD between the PHY address and register number?
Quoted 8 lines
Honestly to future proof this, I think a good idea might be to add helper to encode these info and use Clause 45 format even for C22. Maybe we can use an extra bit to signal if the format is C22 or C45.
BIT(26) 0: C22 1:C45
GENMASK(25, 21)PHY ADDRGENMASK(20, 16)MMD ADDRGENMASK(15, 0)REG
Quoted 5 lines
If you look back at older kernels, there was some helpers to do something like this, but the C22/C45 was in bit 31. When i cleaned up MDIO drivers to have separate C22 and C45 read/write functions, they become redundant and they were removed. You might want to bring them back again.
I'd prefer we didn't bring that abomination back. The detail about how things are stored in regmap should be internal within regmap, and I think it would be better to have an API presented that takes sensible parameters, rather than something that's been encoded.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Re: [net-next PATCH v12 07/13] net: mdio: regmap: add support for multiple valid addr
Quoted 33 lines · Russell King (Oracle)
Quoted 26 lines · Andrew Lunn
Quoted 16 lines · Christian Marangi
Quoted 14 lines · Russell King (Oracle)
include/linux/mdio/mdio-regmap.h line 21
Quoted 7 lines · Christian Marangi
include/linux/mdio/mdio-regmap.h +7
-0+/* If a non empty valid_addr_mask is passed, PHY address and +* read/write register are encoded in the regmap register +* by placing the register in the first 16 bits and the PHY address +* right after. +*/ +#define MDIO_REGMAP_PHY_ADDR GENMASK(20, 16) +#define MDIO_REGMAP_PHY_REG GENMASK(15, 0)Clause 45 PHYs have 5 bits of PHY address, then 5 bits of mmd address, and then 16 bits of register address - significant in that order. Can we adjust the mask for the PHY address later to add the MMD between the PHY address and register number?
Quoted 8 lines
Honestly to future proof this, I think a good idea might be to add helper to encode these info and use Clause 45 format even for C22. Maybe we can use an extra bit to signal if the format is C22 or C45.
BIT(26) 0: C22 1:C45
GENMASK(25, 21)PHY ADDRGENMASK(20, 16)MMD ADDRGENMASK(15, 0)REGQuoted 5 lines
If you look back at older kernels, there was some helpers to do something like this, but the C22/C45 was in bit 31. When i cleaned up MDIO drivers to have separate C22 and C45 read/write functions, they become redundant and they were removed. You might want to bring them back again.
Quoted 5 lines
I'd prefer we didn't bring that abomination back. The detail about how things are stored in regmap should be internal within regmap, and I think it would be better to have an API presented that takes sensible parameters, rather than something that's been encoded.
Well problem is that regmap_write and regmap_read will take max 2 value at the very end (reg and value) so it's really a matter of making the encoding part internal but encoding it can't be skipped.
You are suggesting to introduce additional API like
mdio_regmap_write(regmap, phy, addr, val); mdio_mmd_regmap_write(regmap, phy, mmd, addr, val);
And the encoding is done internally?
My concern is the decoding part from the .write/read_bits regmap OPs. I guess for that also some helper should be exposed (to keep the decoding/encoding internal to the driver and not expose the _abomination_)
What do you think?
Signature · 1 line
Ansuel
Russell King (Oracle)
reviewerRe: [net-next PATCH v12 07/13] net: mdio: regmap: add support for multiple valid addr
Quoted 10 lines · Christian Marangi
Quoted 4 lines · Russell King (Oracle)
I'd prefer we didn't bring that abomination back. The detail about how things are stored in regmap should be internal within regmap, and I think it would be better to have an API presented that takes sensible parameters, rather than something that's been encoded.
Well problem is that
regmap_writeandregmap_readwill take max 2 value at the very end (reg and value) so it's really a matter of making the encoding part internal but encoding it can't be skipped.
Quoted 6 lines
You are suggesting to introduce additional API like
mdio_regmap_write(regmap, phy, addr, val);mdio_mmd_regmap_write(regmap, phy, mmd, addr, val);And the encoding is done internally?
Yes, because littering drivers with the details of the conversion is unreasonable.
Quoted 4 lines
My concern is the decoding part from the .write/read_bits regmap OPs. I guess for that also some helper should be exposed (to keep the decoding/encoding internal to the driver and not expose the _abomination_)
Sadly, I don't think that's something we can get away from, but we should make it _easy_ for people to get it right.
From what I remember from the days of shoe-horning C45 into the C22 MDIO API, encoding and/or decoding addresses was buggy because people would use the wrong encoders and decoders.
For example, we had MDIO drivers using mdio_phy_id_is_c45() to test whether the access being requested was C45 - mdio_phy_id_is_c45() is for the _userspace_ MII API encoding (struct mii_ioctl_data), not the kernel space. Kernel space used:
-#define MII_ADDR_C45 (1<<30)
-#define MII_DEVADDR_C45_SHIFT 16
-#define MII_REGADDR_C45_MASK GENMASK(15, 0)
to encode into the register number argument vs the userspace encoding into the phy_id member of struct mii_ioctl_data:
#define MDIO_PHY_ID_C45 0x8000 #define MDIO_PHY_ID_PRTAD 0x03e0 #define MDIO_PHY_ID_DEVAD 0x001f
which is what the mdio_phy_id_*() accessors are using. The two approaches are incompatible, and using the userspace one in a MDIO driver wasn't going to work correctly - but people did it.
This is one of the reasons I hated the old MDIO API, and why we now have separate C22 and C45 interfaces in the driver code.
This is exactly why I don't like reintroducing a new set of "massage the package, mmd and address into some single integer representation" and "decode a single integer into their respective parts" - we've been here before, it's lead to problems because driver authors can't grasp what the right approach is, and it results in bugs.
Given the history here, my personal opinion would be... if regmap can't cope with MDIO devices having a three-part address without requiring callers to flatten it first, and then have various regmap drivers unflatten it, then regmap is unsuitable to be used with MDIO and ought not be used.
So, this encoding/decoding is a problem that should be solved entirely within regmap, and not spread out into users of regmap and drivers behind regmap. Anything else is, IMHO, insane.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
PATCH v12 8/13 net: mdio: regmap: add OF support
In reply to Christian MarangiPermit to pass the device node pointer to mdio regmap config and permit mdio registration with an OF node to support DT PHY probe.
With the device node pointer NULL, the normal mdio registration is used.
--- drivers/net/mdio/mdio-regmap.c | 2 +- include/linux/mdio/mdio-regmap.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/net/mdio/mdio-regmap.c +1 -1
@@ -90,7 +90,7 @@ struct mii_bus *devm_mdio_regmap_register(struct device *dev,else mii->phy_mask = ~0 ; - rc =devm_mdiobus_register (dev, mii); + rc =devm_of_mdiobus_register (dev, mii, config->np);if (rc) {dev_err (config->parent,"Cannot register MDIO bus![%s] (%d)\n" , mii->id, rc);return ERR_PTR (rc);
include/linux/mdio/mdio-regmap.h +1 -0
@@ -22,6 +22,7 @@ struct regmap;struct mdio_regmap_config {struct device *parent; +struct device_node *np;struct regmap *regmap;char name[MII_BUS_ID_SIZE ];u8 valid_addr;
Signature · 1 line
2.48.1
Russell King (Oracle)
reviewerRe: [net-next PATCH v12 08/13] net: mdio: regmap: add OF support
Quoted 4 lines · Christian Marangi
Permit to pass the device node pointer to mdio regmap config and permit mdio registration with an OF node to support DT PHY probe.
With the device node pointer NULL, the normal mdio registration is used.
Should this be using a device node, or a fwnode?
It depends _why_ you're adding this, and you omit to state that in the commit description (hint - it should say why!)
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Re: [net-next PATCH v12 08/13] net: mdio: regmap: add OF support
Quoted 11 lines · Russell King (Oracle)
Quoted 4 lines · Christian Marangi
Permit to pass the device node pointer to mdio regmap config and permit mdio registration with an OF node to support DT PHY probe.
With the device node pointer NULL, the normal mdio registration is used.
Should this be using a device node, or a fwnode?
It depends _why_ you're adding this, and you omit to state that in the commit description (hint - it should say why!)
Ugh totally forgot... It should be a device node. The use of the of_ variant of mdiobus register permits to autoprobe PHY defined in device tree.
The current regmap driver only permit manual probe using the mask value so it's problematic for MFD usage with an abstract regmap and PHY autoprobe.
Will add additional info in the commit.
Signature · 1 line
Ansuel
PATCH v12 9/13 mfd: an8855: Add support for Airoha AN8855 Switch MFD
In reply to Christian MarangiAdd support for Airoha AN8855 Switch MFD that provide support for a DSA switch and a NVMEM provider. Also provide support for a virtual MDIO passthrough as the PHYs address for the switch are shared with the switch address.
--- MAINTAINERS | 1 + drivers/mfd/Kconfig | 10 + drivers/mfd/Makefile | 1 + drivers/mfd/airoha-an8855.c | 445 ++++++++++++++++++++++++++++++++++++ 4 files changed, 457 insertions(+) create mode 100644 drivers/mfd/airoha-an8855.c
MAINTAINERS +1 -0
@@ -730,6 +730,7 @@ F: Documentation/devicetree/bindings/net/airoha,an8855-mdio.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 AIROHA ETHERNET DRIVER M: Lorenzo Bianconi <[email protected]>
drivers/mfd/Kconfig +10 -0
@@ -53,6 +53,16 @@ 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 MFD" + select MFD_CORE + select MDIO_DEVICE + depends on NETDEVICES && OF + help + Support for the Airoha AN8855 Switch MFD. This is a SoC Switch + that provides various peripherals. 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 +445 -0
445 lines not on this page · raw message
Signature · 1 line
2.48.1
Lee Jones
maintainerRe: [net-next PATCH v12 09/13] mfd: an8855: Add support for Airoha AN8855 Switch MFD
Quoted 1 line · Christian Marangi
Add support for Airoha AN8855 Switch MFD that provide support for a DSA
Drop all references to MFD.
It doesn't exist. It is a figment of your (and my) imagination.
Quoted 30 lines
switch and a NVMEM provider. Also provide support for a virtual MDIO passthrough as the PHYs address for the switch are shared with the switch address.
Signed-off-by Christian Marangi <[email protected]>--- MAINTAINERS | 1 + drivers/mfd/Kconfig | 10 + drivers/mfd/Makefile | 1 + drivers/mfd/airoha-an8855.c | 445 ++++++++++++++++++++++++++++++++++++ 4 files changed, 457 insertions(+) create mode 100644 drivers/mfd/airoha-an8855.cMAINTAINERS +1
-0@@ -730,6 +730,7 @@ F: Documentation/devicetree/bindings/net/airoha,an8855-mdio.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 AIROHA ETHERNET DRIVER M: Lorenzo Bianconi <[email protected]>drivers/mfd/Kconfig +0
-0
drivers/mfd/Kconfig config MFD_ALTERA_SYSMGR · line 56
Quoted 4 lines
drivers/mfd/Kconfig +1
-0@@ -53,6 +53,16 @@ config MFD_ALTERA_SYSMGR using regmap_mmio accesses for ARM32 parts and SMC calls to EL3 for ARM64 parts. +config MFD_AIROHA_AN8855
Should this be EN?
drivers/mfd/Kconfig config MFD_ALTERA_SYSMGR · line 62
Quoted 6 lines
drivers/mfd/Kconfig +6
-0+ tristate "Airoha AN8855 Switch MFD" + select MFD_CORE + select MDIO_DEVICE + depends on NETDEVICES && OF + help + Support for the Airoha AN8855 Switch MFD. This is a SoC Switch
Nit: "an SoC".
What kind of switch?
drivers/mfd/Kconfig config MFD_ALTERA_SYSMGR · line 63
Quoted 1 line
drivers/mfd/Kconfig +1
-0+ that provides various peripherals. Currently it provides a
Which other peripherals?
Quoted 23 lines
drivers/mfd/Kconfig +2
-0+ DSA switch and a NVMEM provider. + config MFD_ACT8945A tristate "Active-semi ACT8945A" select MFD_COREdrivers/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.odrivers/mfd/airoha-an8855.c new file +0
-0
drivers/mfd/airoha-an8855.c line 3
Quoted 3 lines
drivers/mfd/airoha-an8855.c new file +3
-0@@ -0,0 +1,445 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* MFD driver for Airoha AN8855 Switch
No such thing as an MFD driver.
Core is sometimes used in place of a better name.
drivers/mfd/airoha-an8855.c line 15
Quoted 12 lines
drivers/mfd/airoha-an8855.c new file +12
-0+*/ + +#include <linux/bitfield.h> +#include <linux/gpio/consumer.h> +#include <linux/mfd/core.h> +#include <linux/mdio.h> +#include <linux/mdio/mdio-regmap.h> +#include <linux/module.h> +#include <linux/phy.h> +#include <linux/regmap.h> + +/* Register for hw trap status */
Ironically, this is probably the most readable name, yet it is the only one graced with a comment. Also 'hw' is an abbreviation, so it should be HW or H/W or better yet hardware.
drivers/mfd/airoha-an8855.c line 18
Quoted 3 lines
drivers/mfd/airoha-an8855.c new file +3
-0+#define AN8855_HWTRAP 0x1000009c + +#define AN8855_CREV 0x10005000
Chip?
drivers/mfd/airoha-an8855.c line 19
Quoted 1 line
drivers/mfd/airoha-an8855.c new file +1
-0+#define AN8855_ID 0x8855
What kid of ID? Chip, revision, model, serial?
drivers/mfd/airoha-an8855.c line 21
Quoted 1 line
drivers/mfd/airoha-an8855.c new file +1
-0+#define AN8855_RG_GPHY_AFE_PWD 0x1028c840
No idea!
Quoted 11 lines
drivers/mfd/airoha-an8855.c new file +11
-0+/* MII Registers */ +#define AN8855_PHY_SELECT_PAGE 0x1f +#define AN8855_PHY_PAGE GENMASK(2, 0) +#define AN8855_PHY_PAGE_STANDARD FIELD_PREP_CONST(AN8855_PHY_PAGE, 0x0) +#define AN8855_PHY_PAGE_EXTENDED_1 FIELD_PREP_CONST(AN8855_PHY_PAGE, 0x1) +#define AN8855_PHY_PAGE_EXTENDED_4 FIELD_PREP_CONST(AN8855_PHY_PAGE, 0x4) + +/* MII Registers Page 4 */ +#define AN8855_PBUS_MODE 0x10 +#define AN8855_PBUS_MODE_ADDR_FIXED 0x0 +#define AN8855_PBUS_MODE_ADDR_INCR BIT(15)
drivers/mfd/airoha-an8855.c line 43
Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10
-0+#define AN8855_PBUS_WR_ADDR_HIGH 0x11 +#define AN8855_PBUS_WR_ADDR_LOW 0x12 +#define AN8855_PBUS_WR_DATA_HIGH 0x13 +#define AN8855_PBUS_WR_DATA_LOW 0x14 +#define AN8855_PBUS_RD_ADDR_HIGH 0x15 +#define AN8855_PBUS_RD_ADDR_LOW 0x16 +#define AN8855_PBUS_RD_DATA_HIGH 0x17 +#define AN8855_PBUS_RD_DATA_LOW 0x18 + +struct an8855_mfd_priv {
It's not an "mfd".
drivers/mfd/airoha-an8855.c line 50
Quoted 7 lines
drivers/mfd/airoha-an8855.c new file +7
-0+struct mii_bus *bus; + +unsigned int switch_addr; +u16 current_page; +}; + +static const struct mfd_cell an8855_mfd_devs[] = {
"_child_" or "_sub_" or drop it entirely.
Quoted 9 lines
drivers/mfd/airoha-an8855.c new file +9
-0+ { + .name = "an8855-efuse", + .of_compatible = "airoha,an8855-efuse", + }, { + .name = "an8855-switch", + .of_compatible = "airoha,an8855-switch", + }, { + .name = "an8855-mdio", + .of_compatible = "airoha,an8855-mdio",
drivers/mfd/airoha-an8855.c line 69
Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10
-0+ } +}; + +static int an8855_mii_set_page (struct an8855_mfd_priv *priv,u8 phy_id, + u8 page) __must_hold(&priv->bus->mdio_lock) +{ +struct mii_bus *bus = priv->bus; +int ret; + + ret =__mdiobus_write (bus, phy_id,AN8855_PHY_SELECT_PAGE , page);
Calling functions with '__' is a red flag.
drivers/mfd/airoha-an8855.c line 72
Quoted 3 lines
drivers/mfd/airoha-an8855.c new file +3
-0+if (ret <0 ) +dev_err_ratelimited (&bus->dev, +"failed to set an8855 mii page\n" );
Use 100-chars if it avoids these kind of line breaks.
drivers/mfd/airoha-an8855.c line 74
Quoted 1 line
drivers/mfd/airoha-an8855.c new file +1
-0+/* Cache current page if next mii read/write is for switch */
MII here?
"this switch"?
I don't see any checks here - how do we know if it is for switch or not?
drivers/mfd/airoha-an8855.c line 73
Quoted 2 lines
drivers/mfd/airoha-an8855.c new file +2
-0+ priv->current_page = page; +return ret <0 ? ret :0 ;
You already check for 'ret < 0' at the call sites, so this little dance is superfluous.
drivers/mfd/airoha-an8855.c line 85
Quoted 9 lines
drivers/mfd/airoha-an8855.c new file +9
-0+} + +static int an8855_mii_read32 (struct mii_bus *bus,u8 phy_id,u32 reg, + u32 *val) __must_hold(&bus->mdio_lock) +{ +int lo, hi, ret; + + ret =__mdiobus_write (bus, phy_id,AN8855_PBUS_MODE , +AN8855_PBUS_MODE_ADDR_FIXED );
100-chars.
drivers/mfd/airoha-an8855.c line 92
Quoted 7 lines
drivers/mfd/airoha-an8855.c new file +7
-0+if (ret <0 ) + goto err; + + ret =__mdiobus_write (bus, phy_id,AN8855_PBUS_RD_ADDR_HIGH , +upper_16_bits (reg)); +if (ret <0 ) + goto err;
'\n'
drivers/mfd/airoha-an8855.c line 102
Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10
-0+ ret =__mdiobus_write (bus, phy_id,AN8855_PBUS_RD_ADDR_LOW , +lower_16_bits (reg)); +if (ret <0 ) + goto err; + + hi =__mdiobus_read (bus, phy_id,AN8855_PBUS_RD_DATA_HIGH ); +if (hi <0 ) { + ret = hi; + goto err; + }
'\n'
drivers/mfd/airoha-an8855.c line 114
Quoted 12 lines
drivers/mfd/airoha-an8855.c new file +12
-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 ); + +return 0 ; +err: +dev_err_ratelimited (&bus->dev, +"failed to read an8855 register\n" );
dev_err() will already print out the an8855 part.
drivers/mfd/airoha-an8855.c line 125
Quoted 11 lines
drivers/mfd/airoha-an8855.c new file +11
-0+return ret; +} + +static int an8855_regmap_read (void *ctx,uint32_t reg,uint32_t *val) +{ +struct an8855_mfd_priv *priv = ctx; +struct mii_bus *bus = priv->bus; +u16 addr = priv->switch_addr; +int ret; + +mutex_lock_nested (&bus->mdio_lock,MDIO_MUTEX_NESTED );
guard()?
Quoted 55 lines
drivers/mfd/airoha-an8855.c new file +55
-0+ ret =an8855_mii_set_page (priv, addr,AN8855_PHY_PAGE_EXTENDED_4 ); +if (ret <0 ) + goto exit; + + ret =an8855_mii_read32 (bus, addr, reg, val); + +exit: +mutex_unlock (&bus->mdio_lock); + +return ret <0 ? ret :0 ; +} + +static int an8855_mii_write32 (struct mii_bus *bus,u8 phy_id,u32 reg, + u32 val) __must_hold(&bus->mdio_lock) +{ +int ret; + + ret =__mdiobus_write (bus, phy_id,AN8855_PBUS_MODE , +AN8855_PBUS_MODE_ADDR_FIXED ); +if (ret <0 ) + goto err; + + ret =__mdiobus_write (bus, phy_id,AN8855_PBUS_WR_ADDR_HIGH , +upper_16_bits (reg)); +if (ret <0 ) + goto err; + ret =__mdiobus_write (bus, phy_id,AN8855_PBUS_WR_ADDR_LOW , +lower_16_bits (reg)); +if (ret <0 ) + goto err; + + ret =__mdiobus_write (bus, phy_id,AN8855_PBUS_WR_DATA_HIGH , +upper_16_bits (val)); +if (ret <0 ) + goto err; + ret =__mdiobus_write (bus, phy_id,AN8855_PBUS_WR_DATA_LOW , +lower_16_bits (val)); +if (ret <0 ) + goto err; + +return 0 ; +err: +dev_err_ratelimited (&bus->dev, +"failed to write an8855 register\n" ); +return ret; +} + +static int an8855_regmap_write (void *ctx,uint32_t reg,uint32_t val) +{ +struct an8855_mfd_priv *priv = ctx; +struct mii_bus *bus = priv->bus; +u16 addr = priv->switch_addr; +int ret; + +mutex_lock_nested (&bus->mdio_lock,MDIO_MUTEX_NESTED );
drivers/mfd/airoha-an8855.c line 190
Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10
-0+ ret =an8855_mii_set_page (priv, addr,AN8855_PHY_PAGE_EXTENDED_4 ); +if (ret <0 ) + goto exit; + + ret =an8855_mii_write32 (bus, addr, reg, val); + +exit: +mutex_unlock (&bus->mdio_lock); + +return ret <0 ? ret :0 ;
Doesn't the caller already expect possible >0 results?
Quoted 83 lines
drivers/mfd/airoha-an8855.c new file +83
-0+} + +static int an8855_regmap_update_bits (void *ctx,uint32_t reg,uint32_t mask, +uint32_t write_val) +{ +struct an8855_mfd_priv *priv = ctx; +struct mii_bus *bus = priv->bus; +u16 addr = priv->switch_addr; +u32 val; +int ret; + +mutex_lock_nested (&bus->mdio_lock,MDIO_MUTEX_NESTED ); + ret =an8855_mii_set_page (priv, addr,AN8855_PHY_PAGE_EXTENDED_4 ); +if (ret <0 ) + goto exit; + + ret =an8855_mii_read32 (bus, addr, reg, &val); +if (ret <0 ) + goto exit; + + val &= ~mask; + val |= write_val; + ret =an8855_mii_write32 (bus, addr, reg, val); + +exit: +mutex_unlock (&bus->mdio_lock); + +return ret <0 ? ret :0 ; +} + +static const struct regmap_range an8855_readable_ranges[] = { +regmap_reg_range (0x10000000 ,0x10000fff ),/* SCU */ +regmap_reg_range (0x10001000 ,0x10001fff ),/* RBUS */ +regmap_reg_range (0x10002000 ,0x10002fff ),/* MCU */ +regmap_reg_range (0x10005000 ,0x10005fff ),/* SYS SCU */ +regmap_reg_range (0x10007000 ,0x10007fff ),/* I2C Slave */ +regmap_reg_range (0x10008000 ,0x10008fff ),/* I2C Master */ +regmap_reg_range (0x10009000 ,0x10009fff ),/* PDMA */ +regmap_reg_range (0x1000a100 ,0x1000a2ff ),/* General Purpose Timer */ +regmap_reg_range (0x1000a200 ,0x1000a2ff ),/* GPU timer */ +regmap_reg_range (0x1000a300 ,0x1000a3ff ),/* GPIO */ +regmap_reg_range (0x1000a400 ,0x1000a5ff ),/* EFUSE */ +regmap_reg_range (0x1000c000 ,0x1000cfff ),/* GDMP CSR */ +regmap_reg_range (0x10010000 ,0x1001ffff ),/* GDMP SRAM */ +regmap_reg_range (0x10200000 ,0x10203fff ),/* Switch - ARL Global */ +regmap_reg_range (0x10204000 ,0x10207fff ),/* Switch - BMU */ +regmap_reg_range (0x10208000 ,0x1020bfff ),/* Switch - ARL Port */ +regmap_reg_range (0x1020c000 ,0x1020cfff ),/* Switch - SCH */ +regmap_reg_range (0x10210000 ,0x10213fff ),/* Switch - MAC */ +regmap_reg_range (0x10214000 ,0x10217fff ),/* Switch - MIB */ +regmap_reg_range (0x10218000 ,0x1021bfff ),/* Switch - Port Control */ +regmap_reg_range (0x1021c000 ,0x1021ffff ),/* Switch - TOP */ +regmap_reg_range (0x10220000 ,0x1022ffff ),/* SerDes */ +regmap_reg_range (0x10286000 ,0x10286fff ),/* RG Batcher */ +regmap_reg_range (0x1028c000 ,0x1028ffff ),/* ETHER_SYS */ +regmap_reg_range (0x30000000 ,0x37ffffff ),/* I2C EEPROM */ +regmap_reg_range (0x38000000 ,0x3fffffff ),/* BOOT_ROM */ +regmap_reg_range (0xa0000000 ,0xbfffffff ),/* GPHY */ +}; + +static const struct regmap_access_table an8855_readable_table = { + .yes_ranges = an8855_readable_ranges, + .n_yes_ranges =ARRAY_SIZE (an8855_readable_ranges), +}; + +static const struct regmap_config an8855_regmap_config = { + .name ="switch" , + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , + .max_register =0xbfffffff , + .reg_read = an8855_regmap_read, + .reg_write = an8855_regmap_write, + .reg_update_bits = an8855_regmap_update_bits, + .disable_locking = true, + .rd_table = &an8855_readable_table, +}; + +static int an855_regmap_phy_reset_page (struct an8855_mfd_priv *priv, + int phy) __must_hold(&priv->bus->mdio_lock) +{ +/* Check PHY page only for addr shared with switch */ +if (phy != priv->switch_addr)
drivers/mfd/airoha-an8855.c line 283
Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10
-0+return 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. +*/
Use proper multi-line comments please.
Quoted 68 lines
drivers/mfd/airoha-an8855.c new file +68
-0+return an8855_mii_set_page (priv, phy,AN8855_PHY_PAGE_STANDARD ); +} + +static int an8855_regmap_phy_read (void *ctx,uint32_t reg,uint32_t *val) +{ +struct an8855_mfd_priv *priv = ctx; +struct mii_bus *bus = priv->bus; +u16 phy_id, addr; +int ret; + + phy_id =FIELD_GET (MDIO_REGMAP_PHY_ADDR , reg); + addr =FIELD_GET (MDIO_REGMAP_PHY_REG , reg); + +mutex_lock_nested (&bus->mdio_lock,MDIO_MUTEX_NESTED ); + ret =an855_regmap_phy_reset_page (priv, phy_id); +if (ret) + goto exit; + + ret =__mdiobus_read (priv->bus, phy_id, addr); + +exit: +mutex_unlock (&bus->mdio_lock); + +if (ret <0 ) +return ret; + + *val = ret; +return 0 ; +} + +static int an8855_regmap_phy_write (void *ctx,uint32_t reg,uint32_t val) +{ +struct an8855_mfd_priv *priv = ctx; +struct mii_bus *bus = priv->bus; +u16 phy_id, addr; +int ret; + + phy_id =FIELD_GET (MDIO_REGMAP_PHY_ADDR , reg); + addr =FIELD_GET (MDIO_REGMAP_PHY_REG , reg); + +mutex_lock_nested (&bus->mdio_lock,MDIO_MUTEX_NESTED ); + ret =an855_regmap_phy_reset_page (priv, phy_id); +if (ret) + goto exit; + + ret =__mdiobus_write (priv->bus, phy_id, addr, val); + +exit: +mutex_unlock (&bus->mdio_lock); + +return ret; +} + +/* Regmap for MDIO Passtrough +* PHY Addr and PHY Reg are encoded in the regmap register. +*/ +static const struct regmap_config an8855_regmap_phy_config = { + .name ="phy" , + .reg_bits =20 , + .val_bits =16 , + .reg_stride =1 , + .max_register =MDIO_REGMAP_PHY_ADDR |MDIO_REGMAP_PHY_REG , + .reg_read = an8855_regmap_phy_read, + .reg_write = an8855_regmap_phy_write, + .disable_locking = true, +}; + +static int an8855_read_switch_id (struct device *dev,struct regmap *regmap)
drivers/mfd/airoha-an8855.c line 361
Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10
-0+{ +u32 id; +int ret; + + ret =regmap_read (regmap,AN8855_CREV , &id); +if (ret) +return ret; + +if (id !=AN8855_ID ) { + dev_err(dev, "Switch ID detected %x but expected %x\n",
"Detected Switch ID %x but %x was expected"
Or
"Expected Switch ID %x but %x was detected"
Quoted 13 lines
drivers/mfd/airoha-an8855.c new file +13
-0+ id, AN8855_ID); +return -ENODEV ; + } + +return 0 ; +} + +static int an8855_mfd_probe (struct mdio_device *mdiodev) +{ +struct regmap *regmap, *regmap_phy; +struct device *dev = &mdiodev->dev; +struct an8855_mfd_priv *priv; +struct gpio_desc *reset_gpio;
drivers/mfd/airoha-an8855.c line 384
Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10
-0+u32 val; +int ret; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + + priv->bus = mdiodev->bus; + priv->switch_addr = mdiodev->addr; +/* no DMA for mdiobus, mute warning for DMA mask not set */
Nit: Please start sentences with uppercase chars.
Quoted 64 lines
drivers/mfd/airoha-an8855.c new file +61
-0+ dev->dma_mask = &dev->coherent_dma_mask; + + regmap =devm_regmap_init (dev,NULL , priv, &an8855_regmap_config); +if (IS_ERR (regmap)) +return dev_err_probe (dev,PTR_ERR (regmap), +"regmap initialization failed\n" ); + + regmap_phy =devm_regmap_init (dev,NULL , priv, &an8855_regmap_phy_config); +if (IS_ERR (regmap_phy)) +return dev_err_probe (dev,PTR_ERR (regmap_phy), +"regmap phy initialization failed\n" ); + + 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 ); + +/* 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; + } + + ret =an8855_read_switch_id (dev, regmap); +if (ret) +return ret; + +/* Release global PHY power down */ + ret =regmap_write (regmap,AN8855_RG_GPHY_AFE_PWD ,0x0 ); +if (ret) +return ret; + +return devm_mfd_add_devices (dev,PLATFORM_DEVID_AUTO , an8855_mfd_devs, +ARRAY_SIZE (an8855_mfd_devs),NULL ,0 , +NULL ); +} + +static const struct of_device_id an8855_mfd_of_match[] = { + { .compatible ="airoha,an8855" }, + {/* sentinel */ } +}; +MODULE_DEVICE_TABLE (of, an8855_mfd_of_match); + +static struct mdio_driver an8855_mfd_driver = { + .probe = an8855_mfd_probe, + .mdiodrv.driver = { + .name ="an8855" , + .of_match_table = an8855_mfd_of_match, + }, +}; +mdio_module_driver (an8855_mfd_driver); + +MODULE_AUTHOR ("Christian Marangi <[email protected]>" ); +MODULE_DESCRIPTION ("Driver for Airoha AN8855 MFD" ); +MODULE_LICENSE ("GPL" );Signature · 1 line
2.48.1
Signature · 1 line
Lee Jones [李琼斯]
Andrew Lunn
maintainerRe: [net-next PATCH v12 09/13] mfd: an8855: Add support for Airoha AN8855 Switch MFD
Quoted 9 lines
drivers/mfd/airoha-an8855.c line 69
Quoted 7 lines
drivers/mfd/airoha-an8855.c new file +7
-0+static int an8855_mii_set_page (struct an8855_mfd_priv *priv,u8 phy_id, + u8 page) __must_hold(&priv->bus->mdio_lock) +{ +struct mii_bus *bus = priv->bus; +int ret; + + ret =__mdiobus_write (bus, phy_id,AN8855_PHY_SELECT_PAGE , page);Calling functions with '__' is a red flag.
In this case, it is correct. It was probably a bad decision to call this __mdiobus_write() in the first place, but we were not expecting it to be used in real driver code, just in core code, where calls to it are wrapped with a mutex lock/unlock.
But drivers started to need to perform multiple read/write operations in an atomic sequence, so they started doing there own taking of the lock, and using these unlocked low level helpers.
We should probably rename __mdiobus_write() to _mdiobus_write() to avoid compiler namespace issues.
Quoted 5 lines
drivers/mfd/airoha-an8855.c line 72
Quoted 3 lines
drivers/mfd/airoha-an8855.c new file +3
-0+if (ret <0 ) +dev_err_ratelimited (&bus->dev, +"failed to set an8855 mii page\n" );Use 100-chars if it avoids these kind of line breaks.
I _guess_ the code is following networking coding style, even though it is outside of normal networking directories. netdev keeps with the old 80 limit.
Quoted 10 lines
drivers/mfd/airoha-an8855.c line 125
Quoted 8 lines
drivers/mfd/airoha-an8855.c new file +8
-0+static int an8855_regmap_read (void *ctx,uint32_t reg,uint32_t *val) +{ +struct an8855_mfd_priv *priv = ctx; +struct mii_bus *bus = priv->bus; +u16 addr = priv->switch_addr; +int ret; + +mutex_lock_nested (&bus->mdio_lock,MDIO_MUTEX_NESTED );
guard()?
netdev people consider guard() too magical. scoped_guard() is however O.K.
Quoted 3 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ return ret < 0 ? ret : 0;Doesn't the caller already expect possible >0 results?
It should not happen. Networking has a very small number of functions which do return 1 on a different sort of success. Such functions are generally called foo_changed(), e.g. mdiobus_modify_changed(). This will do a read/modify/write. If it did not need to modify anything, because of the current value, it will return 0. If something did actually change, it returns 1. If something did actually change, you sometimes need to take further actions. But many callers don't care, so we have wrappers e.g. mdiobus_modify() calls mdiobus_modify_changed() and then converts 0 or 1 to just 0. I'm guessing this code copied such a helper when it should not of done.
Andrew
Re: [net-next PATCH v12 09/13] mfd: an8855: Add support for Airoha AN8855 Switch MFD
In reply to Lee JonesQuoted 41 lines · Lee Jones
Quoted 1 line · Christian Marangi
Add support for Airoha AN8855 Switch MFD that provide support for a DSA
Drop all references to MFD.
It doesn't exist. It is a figment of your (and my) imagination.
Quoted 33 lines
switch and a NVMEM provider. Also provide support for a virtual MDIO passthrough as the PHYs address for the switch are shared with the switch address.
Signed-off-by Christian Marangi <[email protected]>--- MAINTAINERS | 1 + drivers/mfd/Kconfig | 10 + drivers/mfd/Makefile | 1 + drivers/mfd/airoha-an8855.c | 445 ++++++++++++++++++++++++++++++++++++ 4 files changed, 457 insertions(+) create mode 100644 drivers/mfd/airoha-an8855.cMAINTAINERS +1
-0@@ -730,6 +730,7 @@ F: Documentation/devicetree/bindings/net/airoha,an8855-mdio.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 AIROHA ETHERNET DRIVER M: Lorenzo Bianconi <[email protected]>drivers/mfd/Kconfig +0
-0@@ -53,6 +53,16 @@ config MFD_ALTERA_SYSMGR using regmap_mmio accesses for ARM32 parts and SMC calls to EL3 for ARM64 parts.
Quoted 4 lines
drivers/mfd/Kconfig config MFD_ALTERA_SYSMGR · line 56
Quoted 1 line
drivers/mfd/Kconfig +1
-0+config MFD_AIROHA_AN8855Should this be EN?
In official internal documentation this is referenced with AN8855...
EN stands for EcoNet, Airoha then brought it so there currently a mix of name with old driver using EN and new one AN. This switch is new enough to use AN.
Quoted 70 lines
drivers/mfd/Kconfig config MFD_ALTERA_SYSMGR · line 62
Quoted 7 lines
drivers/mfd/Kconfig +6
-0+ tristate "Airoha AN8855 Switch MFD" + select MFD_CORE + select MDIO_DEVICE + depends on NETDEVICES && OF + help + Support for the Airoha AN8855 Switch MFD. This is a SoC SwitchNit: "an SoC".
What kind of switch?
drivers/mfd/Kconfig config MFD_ALTERA_SYSMGR · line 63
Quoted 1 line
drivers/mfd/Kconfig +1
-0+ that provides various peripherals. Currently it provides aWhich other peripherals?
Quoted 23 lines
drivers/mfd/Kconfig +2
-0+ DSA switch and a NVMEM provider. + config MFD_ACT8945A tristate "Active-semi ACT8945A" select MFD_COREdrivers/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.odrivers/mfd/airoha-an8855.c new file +0
-0drivers/mfd/airoha-an8855.c line 3
Quoted 3 lines
drivers/mfd/airoha-an8855.c new file +3
-0@@ -0,0 +1,445 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* MFD driver for Airoha AN8855 Switch No such thing as an MFD driver.
Core is sometimes used in place of a better name.
drivers/mfd/airoha-an8855.c line 15
Quoted 12 lines
drivers/mfd/airoha-an8855.c new file +12
-0+*/ + +#include <linux/bitfield.h> +#include <linux/gpio/consumer.h> +#include <linux/mfd/core.h> +#include <linux/mdio.h> +#include <linux/mdio/mdio-regmap.h> +#include <linux/module.h> +#include <linux/phy.h> +#include <linux/regmap.h> + +/* Register for hw trap status */ Ironically, this is probably the most readable name, yet it is the only one graced with a comment. Also 'hw' is an abbreviation, so it should be HW or H/W or better yet hardware.
drivers/mfd/airoha-an8855.c line 18
Quoted 3 lines
drivers/mfd/airoha-an8855.c new file +3
-0+#define AN8855_HWTRAP 0x1000009c + +#define AN8855_CREV 0x10005000Chip?
Quoted 8 lines
drivers/mfd/airoha-an8855.c line 19
Quoted 1 line
drivers/mfd/airoha-an8855.c new file +1
-0+#define AN8855_ID 0x8855What kid of ID? Chip, revision, model, serial?
drivers/mfd/airoha-an8855.c line 21
Quoted 1 line
drivers/mfd/airoha-an8855.c new file +1
-0+#define AN8855_RG_GPHY_AFE_PWD 0x1028c840No idea!
There magic name are the 1:1 map of the register on the internal documentation. Honestly it would put more harm than good to rename these register to a more symbolic name since it would make it even harder to find them.
Quoted 47 lines
Quoted 11 lines
drivers/mfd/airoha-an8855.c new file +11
-0+/* MII Registers */ +#define AN8855_PHY_SELECT_PAGE 0x1f +#define AN8855_PHY_PAGE GENMASK(2, 0) +#define AN8855_PHY_PAGE_STANDARD FIELD_PREP_CONST(AN8855_PHY_PAGE, 0x0) +#define AN8855_PHY_PAGE_EXTENDED_1 FIELD_PREP_CONST(AN8855_PHY_PAGE, 0x1) +#define AN8855_PHY_PAGE_EXTENDED_4 FIELD_PREP_CONST(AN8855_PHY_PAGE, 0x4) + +/* MII Registers Page 4 */ +#define AN8855_PBUS_MODE 0x10 +#define AN8855_PBUS_MODE_ADDR_FIXED 0x0 +#define AN8855_PBUS_MODE_ADDR_INCR BIT(15)drivers/mfd/airoha-an8855.c line 43
Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10
-0+#define AN8855_PBUS_WR_ADDR_HIGH 0x11 +#define AN8855_PBUS_WR_ADDR_LOW 0x12 +#define AN8855_PBUS_WR_DATA_HIGH 0x13 +#define AN8855_PBUS_WR_DATA_LOW 0x14 +#define AN8855_PBUS_RD_ADDR_HIGH 0x15 +#define AN8855_PBUS_RD_ADDR_LOW 0x16 +#define AN8855_PBUS_RD_DATA_HIGH 0x17 +#define AN8855_PBUS_RD_DATA_LOW 0x18 + +struct an8855_mfd_priv {It's not an "mfd".
drivers/mfd/airoha-an8855.c line 50
Quoted 7 lines
drivers/mfd/airoha-an8855.c new file +7
-0+struct mii_bus *bus; + +unsigned int switch_addr; +u16 current_page; +}; + +static const struct mfd_cell an8855_mfd_devs[] = {"_child_" or "_sub_" or drop it entirely.
Quoted 13 lines
drivers/mfd/airoha-an8855.c new file +13
-0+ { + .name = "an8855-efuse", + .of_compatible = "airoha,an8855-efuse", + }, { + .name = "an8855-switch", + .of_compatible = "airoha,an8855-switch", + }, { + .name = "an8855-mdio", + .of_compatible = "airoha,an8855-mdio", + } +}; + +static int an8855_mii_set_page(struct an8855_mfd_priv *priv, u8 phy_id,
Quoted 9 lines
drivers/mfd/airoha-an8855.c line 69
Quoted 6 lines
drivers/mfd/airoha-an8855.c new file +6
-0+ u8 page) __must_hold(&priv->bus->mdio_lock) +{ +struct mii_bus *bus = priv->bus; +int ret; + + ret =__mdiobus_write (bus, phy_id,AN8855_PHY_SELECT_PAGE , page);Calling functions with '__' is a red flag.
As already explained it's an unlucky name, __ was used at times probably to stress that this is an internal variant with no lock and should be used ONLY when actually intended (this is the case as the function enforce locking with the __must_hold)
Quoted 6 lines
drivers/mfd/airoha-an8855.c line 72
Quoted 3 lines
drivers/mfd/airoha-an8855.c new file +3
-0+if (ret <0 ) +dev_err_ratelimited (&bus->dev, +"failed to set an8855 mii page\n" );Use 100-chars if it avoids these kind of line breaks.
Quoted 8 lines
drivers/mfd/airoha-an8855.c line 74
Quoted 1 line
drivers/mfd/airoha-an8855.c new file +1
-0+/* Cache current page if next mii read/write is for switch */ MII here?
"this switch"?
I don't see any checks here - how do we know if it is for switch or not?
Check is done in an855_regmap_phy_reset_page.
Quoted 18 lines
drivers/mfd/airoha-an8855.c line 73
Quoted 2 lines
drivers/mfd/airoha-an8855.c new file +2
-0+ priv->current_page = page; +return ret <0 ? ret :0 ;You already check for 'ret < 0' at the call sites, so this little dance is superfluous.
drivers/mfd/airoha-an8855.c line 85
Quoted 9 lines
drivers/mfd/airoha-an8855.c new file +9
-0+} + +static int an8855_mii_read32 (struct mii_bus *bus,u8 phy_id,u32 reg, + u32 *val) __must_hold(&bus->mdio_lock) +{ +int lo, hi, ret; + + ret =__mdiobus_write (bus, phy_id,AN8855_PBUS_MODE , +AN8855_PBUS_MODE_ADDR_FIXED );100-chars.
Quoted 10 lines
drivers/mfd/airoha-an8855.c line 92
Quoted 7 lines
drivers/mfd/airoha-an8855.c new file +7
-0+if (ret <0 ) + goto err; + + ret =__mdiobus_write (bus, phy_id,AN8855_PBUS_RD_ADDR_HIGH , +upper_16_bits (reg)); +if (ret <0 ) + goto err;'\n'
The idea for these operation without extra line were to pack the upper and lower part to form the full 32bit value. But ok will split.
Quoted 28 lines
drivers/mfd/airoha-an8855.c line 102
Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10
-0+ ret =__mdiobus_write (bus, phy_id,AN8855_PBUS_RD_ADDR_LOW , +lower_16_bits (reg)); +if (ret <0 ) + goto err; + + hi =__mdiobus_read (bus, phy_id,AN8855_PBUS_RD_DATA_HIGH ); +if (hi <0 ) { + ret = hi; + goto err; + }'\n'
drivers/mfd/airoha-an8855.c line 114
Quoted 12 lines
drivers/mfd/airoha-an8855.c new file +12
-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 ); + +return 0 ; +err: +dev_err_ratelimited (&bus->dev, +"failed to read an8855 register\n" );
dev_err()will already print out the an8855 part.
Quoted 14 lines
drivers/mfd/airoha-an8855.c line 125
Quoted 11 lines
drivers/mfd/airoha-an8855.c new file +11
-0+return ret; +} + +static int an8855_regmap_read (void *ctx,uint32_t reg,uint32_t *val) +{ +struct an8855_mfd_priv *priv = ctx; +struct mii_bus *bus = priv->bus; +u16 addr = priv->switch_addr; +int ret; + +mutex_lock_nested (&bus->mdio_lock,MDIO_MUTEX_NESTED );
guard()?
Problem is that we can't even use scoped_guard as there isn't a variant with MUTEX_NESTED. This patch is already bit enough that I didn't want to pollute it more for it. If it's not a problem I will send a followup later.
Quoted 342 lines
Quoted 55 lines
drivers/mfd/airoha-an8855.c new file +55
-0+ ret =an8855_mii_set_page (priv, addr,AN8855_PHY_PAGE_EXTENDED_4 ); +if (ret <0 ) + goto exit; + + ret =an8855_mii_read32 (bus, addr, reg, val); + +exit: +mutex_unlock (&bus->mdio_lock); + +return ret <0 ? ret :0 ; +} + +static int an8855_mii_write32 (struct mii_bus *bus,u8 phy_id,u32 reg, + u32 val) __must_hold(&bus->mdio_lock) +{ +int ret; + + ret =__mdiobus_write (bus, phy_id,AN8855_PBUS_MODE , +AN8855_PBUS_MODE_ADDR_FIXED ); +if (ret <0 ) + goto err; + + ret =__mdiobus_write (bus, phy_id,AN8855_PBUS_WR_ADDR_HIGH , +upper_16_bits (reg)); +if (ret <0 ) + goto err; + ret =__mdiobus_write (bus, phy_id,AN8855_PBUS_WR_ADDR_LOW , +lower_16_bits (reg)); +if (ret <0 ) + goto err; + + ret =__mdiobus_write (bus, phy_id,AN8855_PBUS_WR_DATA_HIGH , +upper_16_bits (val)); +if (ret <0 ) + goto err; + ret =__mdiobus_write (bus, phy_id,AN8855_PBUS_WR_DATA_LOW , +lower_16_bits (val)); +if (ret <0 ) + goto err; + +return 0 ; +err: +dev_err_ratelimited (&bus->dev, +"failed to write an8855 register\n" ); +return ret; +} + +static int an8855_regmap_write (void *ctx,uint32_t reg,uint32_t val) +{ +struct an8855_mfd_priv *priv = ctx; +struct mii_bus *bus = priv->bus; +u16 addr = priv->switch_addr; +int ret; + +mutex_lock_nested (&bus->mdio_lock,MDIO_MUTEX_NESTED );drivers/mfd/airoha-an8855.c line 190
Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10
-0+ ret =an8855_mii_set_page (priv, addr,AN8855_PHY_PAGE_EXTENDED_4 ); +if (ret <0 ) + goto exit; + + ret =an8855_mii_write32 (bus, addr, reg, val); + +exit: +mutex_unlock (&bus->mdio_lock); + +return ret <0 ? ret :0 ;Doesn't the caller already expect possible >0 results?
Quoted 83 lines
drivers/mfd/airoha-an8855.c new file +83
-0+} + +static int an8855_regmap_update_bits (void *ctx,uint32_t reg,uint32_t mask, +uint32_t write_val) +{ +struct an8855_mfd_priv *priv = ctx; +struct mii_bus *bus = priv->bus; +u16 addr = priv->switch_addr; +u32 val; +int ret; + +mutex_lock_nested (&bus->mdio_lock,MDIO_MUTEX_NESTED ); + ret =an8855_mii_set_page (priv, addr,AN8855_PHY_PAGE_EXTENDED_4 ); +if (ret <0 ) + goto exit; + + ret =an8855_mii_read32 (bus, addr, reg, &val); +if (ret <0 ) + goto exit; + + val &= ~mask; + val |= write_val; + ret =an8855_mii_write32 (bus, addr, reg, val); + +exit: +mutex_unlock (&bus->mdio_lock); + +return ret <0 ? ret :0 ; +} + +static const struct regmap_range an8855_readable_ranges[] = { +regmap_reg_range (0x10000000 ,0x10000fff ),/* SCU */ +regmap_reg_range (0x10001000 ,0x10001fff ),/* RBUS */ +regmap_reg_range (0x10002000 ,0x10002fff ),/* MCU */ +regmap_reg_range (0x10005000 ,0x10005fff ),/* SYS SCU */ +regmap_reg_range (0x10007000 ,0x10007fff ),/* I2C Slave */ +regmap_reg_range (0x10008000 ,0x10008fff ),/* I2C Master */ +regmap_reg_range (0x10009000 ,0x10009fff ),/* PDMA */ +regmap_reg_range (0x1000a100 ,0x1000a2ff ),/* General Purpose Timer */ +regmap_reg_range (0x1000a200 ,0x1000a2ff ),/* GPU timer */ +regmap_reg_range (0x1000a300 ,0x1000a3ff ),/* GPIO */ +regmap_reg_range (0x1000a400 ,0x1000a5ff ),/* EFUSE */ +regmap_reg_range (0x1000c000 ,0x1000cfff ),/* GDMP CSR */ +regmap_reg_range (0x10010000 ,0x1001ffff ),/* GDMP SRAM */ +regmap_reg_range (0x10200000 ,0x10203fff ),/* Switch - ARL Global */ +regmap_reg_range (0x10204000 ,0x10207fff ),/* Switch - BMU */ +regmap_reg_range (0x10208000 ,0x1020bfff ),/* Switch - ARL Port */ +regmap_reg_range (0x1020c000 ,0x1020cfff ),/* Switch - SCH */ +regmap_reg_range (0x10210000 ,0x10213fff ),/* Switch - MAC */ +regmap_reg_range (0x10214000 ,0x10217fff ),/* Switch - MIB */ +regmap_reg_range (0x10218000 ,0x1021bfff ),/* Switch - Port Control */ +regmap_reg_range (0x1021c000 ,0x1021ffff ),/* Switch - TOP */ +regmap_reg_range (0x10220000 ,0x1022ffff ),/* SerDes */ +regmap_reg_range (0x10286000 ,0x10286fff ),/* RG Batcher */ +regmap_reg_range (0x1028c000 ,0x1028ffff ),/* ETHER_SYS */ +regmap_reg_range (0x30000000 ,0x37ffffff ),/* I2C EEPROM */ +regmap_reg_range (0x38000000 ,0x3fffffff ),/* BOOT_ROM */ +regmap_reg_range (0xa0000000 ,0xbfffffff ),/* GPHY */ +}; + +static const struct regmap_access_table an8855_readable_table = { + .yes_ranges = an8855_readable_ranges, + .n_yes_ranges =ARRAY_SIZE (an8855_readable_ranges), +}; + +static const struct regmap_config an8855_regmap_config = { + .name ="switch" , + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , + .max_register =0xbfffffff , + .reg_read = an8855_regmap_read, + .reg_write = an8855_regmap_write, + .reg_update_bits = an8855_regmap_update_bits, + .disable_locking = true, + .rd_table = &an8855_readable_table, +}; + +static int an855_regmap_phy_reset_page (struct an8855_mfd_priv *priv, + int phy) __must_hold(&priv->bus->mdio_lock) +{ +/* Check PHY page only for addr shared with switch */ +if (phy != priv->switch_addr)drivers/mfd/airoha-an8855.c line 283
Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10
-0+return 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. +*/ Use proper multi-line comments please.
Quoted 68 lines
drivers/mfd/airoha-an8855.c new file +68
-0+return an8855_mii_set_page (priv, phy,AN8855_PHY_PAGE_STANDARD ); +} + +static int an8855_regmap_phy_read (void *ctx,uint32_t reg,uint32_t *val) +{ +struct an8855_mfd_priv *priv = ctx; +struct mii_bus *bus = priv->bus; +u16 phy_id, addr; +int ret; + + phy_id =FIELD_GET (MDIO_REGMAP_PHY_ADDR , reg); + addr =FIELD_GET (MDIO_REGMAP_PHY_REG , reg); + +mutex_lock_nested (&bus->mdio_lock,MDIO_MUTEX_NESTED ); + ret =an855_regmap_phy_reset_page (priv, phy_id); +if (ret) + goto exit; + + ret =__mdiobus_read (priv->bus, phy_id, addr); + +exit: +mutex_unlock (&bus->mdio_lock); + +if (ret <0 ) +return ret; + + *val = ret; +return 0 ; +} + +static int an8855_regmap_phy_write (void *ctx,uint32_t reg,uint32_t val) +{ +struct an8855_mfd_priv *priv = ctx; +struct mii_bus *bus = priv->bus; +u16 phy_id, addr; +int ret; + + phy_id =FIELD_GET (MDIO_REGMAP_PHY_ADDR , reg); + addr =FIELD_GET (MDIO_REGMAP_PHY_REG , reg); + +mutex_lock_nested (&bus->mdio_lock,MDIO_MUTEX_NESTED ); + ret =an855_regmap_phy_reset_page (priv, phy_id); +if (ret) + goto exit; + + ret =__mdiobus_write (priv->bus, phy_id, addr, val); + +exit: +mutex_unlock (&bus->mdio_lock); + +return ret; +} + +/* Regmap for MDIO Passtrough +* PHY Addr and PHY Reg are encoded in the regmap register. +*/ +static const struct regmap_config an8855_regmap_phy_config = { + .name ="phy" , + .reg_bits =20 , + .val_bits =16 , + .reg_stride =1 , + .max_register =MDIO_REGMAP_PHY_ADDR |MDIO_REGMAP_PHY_REG , + .reg_read = an8855_regmap_phy_read, + .reg_write = an8855_regmap_phy_write, + .disable_locking = true, +}; + +static int an8855_read_switch_id (struct device *dev,struct regmap *regmap)drivers/mfd/airoha-an8855.c line 361
Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10
-0+{ +u32 id; +int ret; + + ret =regmap_read (regmap,AN8855_CREV , &id); +if (ret) +return ret; + +if (id !=AN8855_ID ) { + dev_err(dev, "Switch ID detected %x but expected %x\n","Detected Switch ID %x but %x was expected"
Or
"Expected Switch ID %x but %x was detected"
Quoted 13 lines
drivers/mfd/airoha-an8855.c new file +13
-0+ id, AN8855_ID); +return -ENODEV ; + } + +return 0 ; +} + +static int an8855_mfd_probe (struct mdio_device *mdiodev) +{ +struct regmap *regmap, *regmap_phy; +struct device *dev = &mdiodev->dev; +struct an8855_mfd_priv *priv; +struct gpio_desc *reset_gpio;drivers/mfd/airoha-an8855.c line 384
Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10
-0+u32 val; +int ret; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + + priv->bus = mdiodev->bus; + priv->switch_addr = mdiodev->addr; +/* no DMA for mdiobus, mute warning for DMA mask not set */ Nit: Please start sentences with uppercase chars.
Quoted 64 lines
drivers/mfd/airoha-an8855.c new file +61
-0+ dev->dma_mask = &dev->coherent_dma_mask; + + regmap =devm_regmap_init (dev,NULL , priv, &an8855_regmap_config); +if (IS_ERR (regmap)) +return dev_err_probe (dev,PTR_ERR (regmap), +"regmap initialization failed\n" ); + + regmap_phy =devm_regmap_init (dev,NULL , priv, &an8855_regmap_phy_config); +if (IS_ERR (regmap_phy)) +return dev_err_probe (dev,PTR_ERR (regmap_phy), +"regmap phy initialization failed\n" ); + + 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 ); + +/* 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; + } + + ret =an8855_read_switch_id (dev, regmap); +if (ret) +return ret; + +/* Release global PHY power down */ + ret =regmap_write (regmap,AN8855_RG_GPHY_AFE_PWD ,0x0 ); +if (ret) +return ret; + +return devm_mfd_add_devices (dev,PLATFORM_DEVID_AUTO , an8855_mfd_devs, +ARRAY_SIZE (an8855_mfd_devs),NULL ,0 , +NULL ); +} + +static const struct of_device_id an8855_mfd_of_match[] = { + { .compatible ="airoha,an8855" }, + {/* sentinel */ } +}; +MODULE_DEVICE_TABLE (of, an8855_mfd_of_match); + +static struct mdio_driver an8855_mfd_driver = { + .probe = an8855_mfd_probe, + .mdiodrv.driver = { + .name ="an8855" , + .of_match_table = an8855_mfd_of_match, + }, +}; +mdio_module_driver (an8855_mfd_driver); + +MODULE_AUTHOR ("Christian Marangi <[email protected]>" ); +MODULE_DESCRIPTION ("Driver for Airoha AN8855 MFD" ); +MODULE_LICENSE ("GPL" );Signature · 1 line
2.48.1Signature · 1 line
Lee Jones [李琼斯]
Signature · 1 line
Ansuel
Andrew Lunn
maintainerRe: [net-next PATCH v12 09/13] mfd: an8855: Add support for Airoha AN8855 Switch MFD
In reply to Christian MarangiQuoted 1 line
+static int an8855_mii_set_page(struct
an8855_mfd_priv*priv, u8phy_id,
phy_id is a bit of an odd name. __mdiobus_write() expects addr, since at this level, it is just a device on a bus. We have no idea if it is a PHY, or an Ethernet switch, or anything else.
drivers/mfd/airoha-an8855.c line 76
Quoted 13 lines
drivers/mfd/airoha-an8855.c new file +13
-0+ u8 page) __must_hold(&priv->bus->mdio_lock) +{ +struct mii_bus *bus = priv->bus; +int ret; + + ret =__mdiobus_write (bus, phy_id,AN8855_PHY_SELECT_PAGE , page); +if (ret <0 ) +dev_err_ratelimited (&bus->dev, +"failed to set an8855 mii page\n" ); + +/* Cache current page if next mii read/write is for switch */ + priv->current_page = page; +return ret <0 ? ret :0 ;
__mdiobus_write() should only return -ve error code, or 0. So you don't need this.
Andrew
PATCH v12 10/13 net: mdio: Add Airoha AN8855 Switch MDIO Passtrough
In reply to Christian MarangiAdd Airoha AN8855 Switch driver to register a MDIO passtrough as switch address is shared with the internal PHYs and require additional page handling.
This requires the upper Switch MFD to be probed and init to actually work.
--- MAINTAINERS | 1 + drivers/net/mdio/Kconfig | 10 +++++++ drivers/net/mdio/Makefile | 1 + drivers/net/mdio/mdio-an8855.c | 48 ++++++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 drivers/net/mdio/mdio-an8855.c
MAINTAINERS +1 -0
@@ -731,6 +731,7 @@ 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/mdio/mdio-an8855.c AIROHA ETHERNET DRIVER M: Lorenzo Bianconi <[email protected]>
drivers/net/mdio/Kconfig +10 -0
@@ -61,6 +61,16 @@ config MDIO_XGENE This module provides a driver for the MDIO busses found in the APM X-Gene SoC's. +config MDIO_AN8855 + tristate "Airoha AN8855 Switch MDIO bus controller" + depends on MFD_AIROHA_AN8855 + depends on OF_MDIO + select MDIO_REGMAP + help + This module provides a driver for the Airoha AN8855 Switch + that requires a MDIO passtrough as switch address is shared + with the internal PHYs and requires additional page handling. + config MDIO_ASPEED tristate "ASPEED MDIO bus controller" depends on ARCH_ASPEED || COMPILE_TEST
drivers/net/mdio/Makefile +1 -0
@@ -5,6 +5,7 @@ obj-$(CONFIG_ACPI_MDIO) += acpi_mdio.o obj-$(CONFIG_FWNODE_MDIO) += fwnode_mdio.o obj-$(CONFIG_OF_MDIO) += of_mdio.o +obj-$(CONFIG_MDIO_AN8855) += mdio-an8855.o obj-$(CONFIG_MDIO_ASPEED) += mdio-aspeed.o obj-$(CONFIG_MDIO_BCM_IPROC) += mdio-bcm-iproc.o obj-$(CONFIG_MDIO_BCM_UNIMAC) += mdio-bcm-unimac.o
drivers/net/mdio/mdio-an8855.c new file +48 -0
48 lines not on this page · raw message
Signature · 1 line
2.48.1
PATCH v12 11/13 nvmem: an8855: Add support for Airoha AN8855 Switch EFUSE
In reply to Christian MarangiAdd support for Airoha AN8855 Switch EFUSE. These EFUSE might be used for calibration data for the internal switch PHYs.
--- MAINTAINERS | 1 + drivers/nvmem/Kconfig | 11 +++++++ drivers/nvmem/Makefile | 2 ++ drivers/nvmem/an8855-efuse.c | 63 ++++++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 drivers/nvmem/an8855-efuse.c
MAINTAINERS +1 -0
@@ -732,6 +732,7 @@ 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/mdio/mdio-an8855.c +F: drivers/nvmem/an8855-efuse.c AIROHA ETHERNET DRIVER M: Lorenzo Bianconi <[email protected]>
drivers/nvmem/Kconfig +11 -0
@@ -28,6 +28,17 @@ source "drivers/nvmem/layouts/Kconfig" # Devices +config NVMEM_AN8855_EFUSE + tristate "Airoha AN8855 eFuse support" + depends on MFD_AIROHA_AN8855 || COMPILE_TEST + help + Say y here to enable support for reading eFuses on Airoha AN8855 + Switch. These are e.g. used to store factory programmed + calibration data required for the PHY. + + This driver can also be built as a module. If so, the module will + be called nvmem-an8855-efuse. + config NVMEM_APPLE_EFUSES tristate "Apple eFuse support" depends on ARCH_APPLE || COMPILE_TEST
drivers/nvmem/Makefile +2 -0
@@ -10,6 +10,8 @@ nvmem_layouts-y := layouts.o obj-y += layouts/ # Devices +obj-$(CONFIG_NVMEM_AN8855_EFUSE) += nvmem-an8855-efuse.o +nvmem-an8855-efuse-y := an8855-efuse.o obj-$(CONFIG_NVMEM_APPLE_EFUSES) += nvmem-apple-efuses.o nvmem-apple-efuses-y := apple-efuses.o obj-$(CONFIG_NVMEM_BCM_OCOTP) += nvmem-bcm-ocotp.o
drivers/nvmem/an8855-efuse.c new file +63 -0
63 lines not on this page · raw message
Signature · 1 line
2.48.1
PATCH v12 12/13 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.
--- MAINTAINERS | 2 + drivers/net/dsa/Kconfig | 9 + drivers/net/dsa/Makefile | 1 + drivers/net/dsa/an8855.c | 2296 ++++++++++++++++++++++++++++++++++++++ drivers/net/dsa/an8855.h | 771 +++++++++++++ 5 files changed, 3079 insertions(+) create mode 100644 drivers/net/dsa/an8855.c create mode 100644 drivers/net/dsa/an8855.h
MAINTAINERS +2 -0
@@ -731,6 +731,8 @@ 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/mdio/mdio-an8855.c F: drivers/nvmem/an8855-efuse.c
drivers/net/dsa/Kconfig +9 -0
@@ -24,6 +24,15 @@ config NET_DSA_LOOP This enables support for a fake mock-up switch chip which exercises the DSA APIs. +config NET_DSA_AN8855 + tristate "Airoha AN8855 Ethernet switch support" + depends on MFD_AIROHA_AN8855 || COMPILE_TEST + depends on NET_DSA + select NET_DSA_TAG_MTK + help + This enables support for the Ethernet switch inside the + Airoha AN8855 chip. + source "drivers/net/dsa/hirschmann/Kconfig" config NET_DSA_LANTIQ_GSWIP
drivers/net/dsa/Makefile +1 -0
@@ -5,6 +5,7 @@ obj-$(CONFIG_NET_DSA_LOOP) += dsa_loop.o ifdef CONFIG_NET_DSA_LOOP obj-$(CONFIG_FIXED_PHY) += dsa_loop_bdinfo.o endif +obj-$(CONFIG_NET_DSA_AN8855) += an8855.o obj-$(CONFIG_NET_DSA_LANTIQ_GSWIP) += lantiq_gswip.o obj-$(CONFIG_NET_DSA_MT7530) += mt7530.o obj-$(CONFIG_NET_DSA_MT7530_MDIO) += mt7530-mdio.o
drivers/net/dsa/an8855.c new file +2296 -0
2,296 lines not on this page · raw message
drivers/net/dsa/an8855.h new file +771 -0
674 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.48.1
Part of the diff is not shown here. View the raw message.
Russell King (Oracle)
reviewerRe: [net-next PATCH v12 12/13] net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver
drivers/net/dsa/an8855.c line 1225
Quoted 7 lines · Christian Marangi
drivers/net/dsa/an8855.c new file +7
-0+static int an8855_port_enable (struct dsa_switch *ds,int port, +struct phy_device *phy) +{ +struct an8855_priv *priv = ds->priv; + +return regmap_set_bits (priv->regmap,AN8855_PMCR_P (port), +AN8855_PMCR_TX_EN |AN8855_PMCR_RX_EN );
Shouldn't you wait for phylink to call your mac_link_up() method?
drivers/net/dsa/an8855.c line 1236
Quoted 11 lines
drivers/net/dsa/an8855.c new file +11
-0+} + +static void an8855_port_disable (struct dsa_switch *ds,int port) +{ +struct an8855_priv *priv = ds->priv; +int ret; + + ret =regmap_clear_bits (priv->regmap,AN8855_PMCR_P (port), +AN8855_PMCR_TX_EN |AN8855_PMCR_RX_EN ); +if (ret) +dev_err (priv->ds->dev,"failed to disable port: %d\n" , ret);
Doesn't the link get set down before this is called? IOW, doesn't phylink call your mac_link_down() method first?
...
Quoted 40 lines
drivers/net/dsa/an8855.c new file +40
-0+static void an8855_phylink_mac_link_up (struct phylink_config *config, +struct phy_device *phydev,unsigned int mode, +phy_interface_t interface,int speed, +int duplex,bool tx_pause,bool rx_pause) +{ +struct dsa_port *dp =dsa_phylink_to_port (config); +struct an8855_priv *priv = dp->ds->priv; +int port = dp->index; +u32 reg; + + reg =regmap_read (priv->regmap,AN8855_PMCR_P (port), ®); +if (phylink_autoneg_inband (mode)) { + reg &= ~AN8855_PMCR_FORCE_MODE ; + }else { + reg |=AN8855_PMCR_FORCE_MODE |AN8855_PMCR_FORCE_LNK ; + + reg &= ~AN8855_PMCR_FORCE_SPEED ; +switch (speed) { +case SPEED_10 : + reg |=AN8855_PMCR_FORCE_SPEED_10 ; +break ; +case SPEED_100 : + reg |=AN8855_PMCR_FORCE_SPEED_100 ; +break ; +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 ; + } + + reg &= ~AN8855_PMCR_FORCE_FDX ; +if (duplex ==DUPLEX_FULL ) + reg |=AN8855_PMCR_FORCE_FDX ; + + reg &= ~AN8855_PMCR_RX_FC_EN ;
drivers/net/dsa/an8855.c line 1628
Quoted 10 lines
drivers/net/dsa/an8855.c new file +10
-0+if (rx_pause ||dsa_port_is_cpu (dp)) + reg |=AN8855_PMCR_RX_FC_EN ; + + reg &= ~AN8855_PMCR_TX_FC_EN ; +if (rx_pause ||dsa_port_is_cpu (dp)) + reg |=AN8855_PMCR_TX_FC_EN ; + +/* Disable any EEE options */ + reg &= ~(AN8855_PMCR_FORCE_EEE5G |AN8855_PMCR_FORCE_EEE2P5G | +AN8855_PMCR_FORCE_EEE1G |AN8855_PMCR_FORCE_EEE100 );
Why? Maybe consider implementing the phylink tx_lpi functions for EEE support.
Quoted 6 lines
drivers/net/dsa/an8855.c new file +6
-0+ } + + reg |=AN8855_PMCR_TX_EN |AN8855_PMCR_RX_EN ; + +regmap_write (priv->regmap,AN8855_PMCR_P (port), reg); +}
drivers/net/dsa/an8855.c line 1644
Quoted 10 lines
drivers/net/dsa/an8855.c new file +10
-0+ +static unsigned int an8855_pcs_inband_caps (struct phylink_pcs *pcs, +phy_interface_t interface) +{ +/* SGMII can be configured to use inband with AN result */ +if (interface ==PHY_INTERFACE_MODE_SGMII ) +return LINK_INBAND_DISABLE |LINK_INBAND_ENABLE ; + +/* inband is not supported in 2500-baseX and must be disabled */ +return LINK_INBAND_DISABLE ;
Spurious double space.
Quoted 26 lines
drivers/net/dsa/an8855.c new file +26
-0+} + +static void an8855_pcs_get_state (struct phylink_pcs *pcs,unsigned int neg_mode, +struct phylink_link_state *state) +{ + struct an8855_priv *priv = container_of(pcs, struct an8855_priv, pcs); +u32 val; +int ret; + + ret =regmap_read (priv->regmap,AN8855_PMSR_P (AN8855_CPU_PORT ), &val); +if (ret <0 ) { + state->link = false; +return ; + } + + state->link = !!(val &AN8855_PMSR_LNK ); + state->an_complete = state->link; + state->duplex = (val &AN8855_PMSR_DPX ) ?DUPLEX_FULL : +DUPLEX_HALF ; + +switch (val &AN8855_PMSR_SPEED ) { +case AN8855_PMSR_SPEED_10 : + state->speed =SPEED_10 ; +break ; +case AN8855_PMSR_SPEED_100 : + state->speed =SPEED_100 ;
drivers/net/dsa/an8855.c line 1680
Quoted 10 lines
drivers/net/dsa/an8855.c new file +10
-0+break ; +case AN8855_PMSR_SPEED_1000 : + state->speed =SPEED_1000 ; +break ; +case AN8855_PMSR_SPEED_2500 : + state->speed =SPEED_2500 ; +break ; +case AN8855_PMSR_SPEED_5000 : +dev_err (priv->ds->dev,"Missing support for 5G speed. Setting Unknown.\n" ); + fallthrough;
Which is wrong now, we have SPEED_5000.
Quoted 12 lines
drivers/net/dsa/an8855.c new file +12
-0+default : + state->speed =SPEED_UNKNOWN ; +break ; + } + +if (val &AN8855_PMSR_RX_FC ) + state->pause |=MLO_PAUSE_RX ; +if (val &AN8855_PMSR_TX_FC ) + state->pause |=MLO_PAUSE_TX ; +} + +static int an8855_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode,
drivers/net/dsa/an8855.c line 1702
Quoted 10 lines
drivers/net/dsa/an8855.c new file +10
-0+phy_interface_t interface, + const unsigned long *advertising, + bool permit_pause_to_mac) +{ + struct an8855_priv *priv = container_of(pcs, struct an8855_priv, pcs); +u32 val; +int ret; + +/* !!! WELCOME TO HELL !!! */ +
[... hell ...]
Quoted 5 lines
drivers/net/dsa/an8855.c new file +5
-0+ ret = regmap_write(priv->regmap, AN8855_MSG_RX_LIK_STS_2, + AN8855_RG_RXFC_AN_BYPASS_P3 | + AN8855_RG_RXFC_AN_BYPASS_P2 | + AN8855_RG_RXFC_AN_BYPASS_P1 | + AN8855_RG_TXFC_AN_BYPASS_P3 |
drivers/net/dsa/an8855.c line 2167
Quoted 10 lines
drivers/net/dsa/an8855.c new file +10
-0+AN8855_RG_TXFC_AN_BYPASS_P2 | +AN8855_RG_TXFC_AN_BYPASS_P1 | +AN8855_RG_DPX_AN_BYPASS_P3 | +AN8855_RG_DPX_AN_BYPASS_P2 | +AN8855_RG_DPX_AN_BYPASS_P1 | + AN8855_RG_DPX_AN_BYPASS_P0); +if (ret) +return ret; + +return 0 ;
Is this disruptive to the link if the link is up, and this is called (e.g. to change the advertisement rather than switch interface mode). If so, please do something about that - e.g. only doing the bulk of the configuration if the interface mode has changed.
I guess, however, that as you're only using SGMII with in-band, it probably doesn't make much difference, but having similar behaviour in the various drivers helps with ongoing maintenance.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Re: [net-next PATCH v12 12/13] net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver
Quoted 11 lines · Russell King (Oracle)
drivers/net/dsa/an8855.c line 1225
Quoted 7 lines · Christian Marangi
drivers/net/dsa/an8855.c new file +7
-0+static int an8855_port_enable (struct dsa_switch *ds,int port, +struct phy_device *phy) +{ +struct an8855_priv *priv = ds->priv; + +return regmap_set_bits (priv->regmap,AN8855_PMCR_P (port), +AN8855_PMCR_TX_EN |AN8855_PMCR_RX_EN );Shouldn't you wait for phylink to call your
mac_link_up()method?
Did something change recently for this? I checked the pattern for other driver and port enable normally just enable TX/RX traffic for the port.
Any hint for this?
Quoted 62 lines
drivers/net/dsa/an8855.c line 1236
Quoted 11 lines
drivers/net/dsa/an8855.c new file +11
-0+} + +static void an8855_port_disable (struct dsa_switch *ds,int port) +{ +struct an8855_priv *priv = ds->priv; +int ret; + + ret =regmap_clear_bits (priv->regmap,AN8855_PMCR_P (port), +AN8855_PMCR_TX_EN |AN8855_PMCR_RX_EN ); +if (ret) +dev_err (priv->ds->dev,"failed to disable port: %d\n" , ret);Doesn't the link get set down before this is called? IOW, doesn't phylink call your
mac_link_down()method first?...
Quoted 45 lines
drivers/net/dsa/an8855.c new file +45
-0+static void an8855_phylink_mac_link_up (struct phylink_config *config, +struct phy_device *phydev,unsigned int mode, +phy_interface_t interface,int speed, +int duplex,bool tx_pause,bool rx_pause) +{ +struct dsa_port *dp =dsa_phylink_to_port (config); +struct an8855_priv *priv = dp->ds->priv; +int port = dp->index; +u32 reg; + + reg =regmap_read (priv->regmap,AN8855_PMCR_P (port), ®); +if (phylink_autoneg_inband (mode)) { + reg &= ~AN8855_PMCR_FORCE_MODE ; + }else { + reg |=AN8855_PMCR_FORCE_MODE |AN8855_PMCR_FORCE_LNK ; + + reg &= ~AN8855_PMCR_FORCE_SPEED ; +switch (speed) { +case SPEED_10 : + reg |=AN8855_PMCR_FORCE_SPEED_10 ; +break ; +case SPEED_100 : + reg |=AN8855_PMCR_FORCE_SPEED_100 ; +break ; +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 ; + } + + reg &= ~AN8855_PMCR_FORCE_FDX ; +if (duplex ==DUPLEX_FULL ) + reg |=AN8855_PMCR_FORCE_FDX ; + + reg &= ~AN8855_PMCR_RX_FC_EN ; +if (rx_pause ||dsa_port_is_cpu (dp)) + reg |=AN8855_PMCR_RX_FC_EN ; + + reg &= ~AN8855_PMCR_TX_FC_EN ; +if (rx_pause ||dsa_port_is_cpu (dp))
Quoted 9 lines
drivers/net/dsa/an8855.c line 1628
Quoted 5 lines
drivers/net/dsa/an8855.c new file +5
-0+ reg |=AN8855_PMCR_TX_FC_EN ; + +/* Disable any EEE options */ + reg &= ~(AN8855_PMCR_FORCE_EEE5G |AN8855_PMCR_FORCE_EEE2P5G | +AN8855_PMCR_FORCE_EEE1G |AN8855_PMCR_FORCE_EEE100 );Why? Maybe consider implementing the phylink
tx_lpifunctions for EEE support.
Will do, I disabled this as the EEE rework was being approved.
Quoted 10 lines
Quoted 10 lines
drivers/net/dsa/an8855.c new file +10
-0+ } + + reg |=AN8855_PMCR_TX_EN |AN8855_PMCR_RX_EN ; + +regmap_write (priv->regmap,AN8855_PMCR_P (port), reg); +} + +static unsigned int an8855_pcs_inband_caps (struct phylink_pcs *pcs, +phy_interface_t interface) +{
Quoted 9 lines
drivers/net/dsa/an8855.c line 1644
Quoted 6 lines
drivers/net/dsa/an8855.c new file +6
-0+/* SGMII can be configured to use inband with AN result */ +if (interface ==PHY_INTERFACE_MODE_SGMII ) +return LINK_INBAND_DISABLE |LINK_INBAND_ENABLE ; + +/* inband is not supported in 2500-baseX and must be disabled */ +return LINK_INBAND_DISABLE ;Spurious double space.
Will drop.
Quoted 30 lines
Quoted 30 lines
drivers/net/dsa/an8855.c new file +30
-0+} + +static void an8855_pcs_get_state (struct phylink_pcs *pcs,unsigned int neg_mode, +struct phylink_link_state *state) +{ + struct an8855_priv *priv = container_of(pcs, struct an8855_priv, pcs); +u32 val; +int ret; + + ret =regmap_read (priv->regmap,AN8855_PMSR_P (AN8855_CPU_PORT ), &val); +if (ret <0 ) { + state->link = false; +return ; + } + + state->link = !!(val &AN8855_PMSR_LNK ); + state->an_complete = state->link; + state->duplex = (val &AN8855_PMSR_DPX ) ?DUPLEX_FULL : +DUPLEX_HALF ; + +switch (val &AN8855_PMSR_SPEED ) { +case AN8855_PMSR_SPEED_10 : + state->speed =SPEED_10 ; +break ; +case AN8855_PMSR_SPEED_100 : + state->speed =SPEED_100 ; +break ; +case AN8855_PMSR_SPEED_1000 : + state->speed =SPEED_1000 ; +break ;
Quoted 9 lines
drivers/net/dsa/an8855.c line 1680
Quoted 6 lines
drivers/net/dsa/an8855.c new file +6
-0+case AN8855_PMSR_SPEED_2500 : + state->speed =SPEED_2500 ; +break ; +case AN8855_PMSR_SPEED_5000 : +dev_err (priv->ds->dev,"Missing support for 5G speed. Setting Unknown.\n" ); + fallthrough;Which is wrong now, we have
SPEED_5000.
Maybe the comments weren't so clear. The Switch doesn't support the speed... Even if it does have bits, the switch doesn't support it. And the 2500 speed is really only for the CPU port. The user port are only gigabit.
Quoted 15 lines
Quoted 15 lines
drivers/net/dsa/an8855.c new file +15
-0+default : + state->speed =SPEED_UNKNOWN ; +break ; + } + +if (val &AN8855_PMSR_RX_FC ) + state->pause |=MLO_PAUSE_RX ; +if (val &AN8855_PMSR_TX_FC ) + state->pause |=MLO_PAUSE_TX ; +} + +static int an8855_pcs_config (struct phylink_pcs *pcs,unsigned int neg_mode, +phy_interface_t interface, +const unsigned long *advertising, +bool permit_pause_to_mac)
Quoted 8 lines
drivers/net/dsa/an8855.c line 1702
Quoted 7 lines
drivers/net/dsa/an8855.c new file +7
-0+{ + struct an8855_priv *priv = container_of(pcs, struct an8855_priv, pcs); +u32 val; +int ret; + +/* !!! WELCOME TO HELL !!! */ +[... hell ...]
Will drop :( It was an easter egg for the 300 lines to configure PCS.
Quoted 12 lines
Quoted 12 lines
drivers/net/dsa/an8855.c new file +12
-0+ ret =regmap_write (priv->regmap,AN8855_MSG_RX_LIK_STS_2 , +AN8855_RG_RXFC_AN_BYPASS_P3 | +AN8855_RG_RXFC_AN_BYPASS_P2 | +AN8855_RG_RXFC_AN_BYPASS_P1 | +AN8855_RG_TXFC_AN_BYPASS_P3 | +AN8855_RG_TXFC_AN_BYPASS_P2 | +AN8855_RG_TXFC_AN_BYPASS_P1 | +AN8855_RG_DPX_AN_BYPASS_P3 | +AN8855_RG_DPX_AN_BYPASS_P2 | +AN8855_RG_DPX_AN_BYPASS_P1 | +AN8855_RG_DPX_AN_BYPASS_P0 ); +if (ret)
Quoted 8 lines
drivers/net/dsa/an8855.c line 143
Quoted 3 lines
drivers/net/dsa/an8855.c new file +3
-0+return ret; + +return 0 ;Is this disruptive to the link if the link is up, and this is called (e.g. to change the advertisement rather than switch interface mode). If so, please do something about that - e.g. only doing the bulk of the configuration if the interface mode has changed.
Airoha confirmed this is not disruptive, applying these config doesn't terminate or disrupt the link.
Quoted 4 lines
I guess, however, that as you're only using SGMII with in-band, it probably doesn't make much difference, but having similar behaviour in the various drivers helps with ongoing maintenance.
Do we have some driver that implement the logic of skipping the bulk of configuration if the mode doesn't change?
Maybe we can introduce some kind of additional OP like .init to apply the very initial configuration that are not related to the mode. Or something like .setup?
Signature · 1 line
Ansuel
Russell King (Oracle)
reviewerRe: [net-next PATCH v12 12/13] net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver
Quoted 13 lines · Christian Marangi
Quoted 4 lines
Quoted 4 lines
drivers/net/dsa/an8855.c new file +4
-0+static int an8855_pcs_config (struct phylink_pcs *pcs,unsigned int neg_mode, +phy_interface_t interface, +const unsigned long *advertising, +bool permit_pause_to_mac)Quoted 8 lines
drivers/net/dsa/an8855.c line 1702
Quoted 7 lines
drivers/net/dsa/an8855.c new file +7
-0+{ + struct an8855_priv *priv = container_of(pcs, struct an8855_priv, pcs); +u32 val; +int ret; + +/* !!! WELCOME TO HELL !!! */ +[... hell ...]
Quoted 1 line
Will drop :( It was an easter egg for the 300 lines to configure PCS.
That wasn't a request to drop the comment, just that I didn't want to include all that in my reply.
Quoted 6 lines
Quoted 3 lines
I guess, however, that as you're only using SGMII with in-band, it probably doesn't make much difference, but having similar behaviour in the various drivers helps with ongoing maintenance.
Do we have some driver that implement the logic of skipping the bulk of configuration if the mode doesn't change?
For many, it doesn't matter, but for e.g. xpcs, there may be a reset of the XPCS when the mode changes, and there's workarounds for the TXGBE - both of those only happen when the interface mode actually changes.
Re-reading my .pcs_config() documentation, I really ought to mention that .pcs_config() will be called for both interface mode changes and for advertisement changes, and should not disrupt the link when nothing has changed.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
PATCH v12 13/13 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.
--- MAINTAINERS | 1 + drivers/net/phy/Kconfig | 5 + drivers/net/phy/Makefile | 1 + drivers/net/phy/air_an8855.c | 261 +++++++++++++++++++++++++++++++++++ 4 files changed, 268 insertions(+) create mode 100644 drivers/net/phy/air_an8855.c
MAINTAINERS +1 -0
@@ -734,6 +734,7 @@ F: drivers/mfd/airoha-an8855.c F: drivers/net/dsa/an8855.c F: drivers/net/dsa/an8855.h F: drivers/net/mdio/mdio-an8855.c +F: drivers/net/phy/air_an8855.c F: drivers/nvmem/an8855-efuse.c AIROHA ETHERNET DRIVER
drivers/net/phy/Kconfig +5 -0
@@ -79,6 +79,11 @@ config SFP comment "MII PHY device drivers" +config AIR_AN8855_PHY + tristate "Airoha AN8855 Internal Gigabit PHY" + help + Currently supports the internal Airoha AN8855 Switch PHY. + config AIR_EN8811H_PHY tristate "Airoha EN8811H 2.5 Gigabit PHY" help
drivers/net/phy/Makefile +1 -0
@@ -36,6 +36,7 @@ obj-y += $(sfp-obj-y) $(sfp-obj-m) obj-$(CONFIG_ADIN_PHY) += adin.o obj-$(CONFIG_ADIN1100_PHY) += adin1100.o +obj-$(CONFIG_AIR_AN8855_PHY) += air_an8855.o obj-$(CONFIG_AIR_EN8811H_PHY) += air_en8811h.o obj-$(CONFIG_AMD_PHY) += amd.o obj-$(CONFIG_AMCC_QT2025_PHY) += qt2025.o
drivers/net/phy/air_an8855.c new file +261 -0
261 lines not on this page · raw message
Signature · 1 line
2.48.1