Skip to contentSkip to conversation

net: dsa: Add Airoha AN8855 support

RFC PATCH Superseded Christian Marangi 4 participants 17 messages Oct 23, 2024 – Oct 27, 2024

Subsystems (6)

v2 of 25 Superseded Latest is v25 →

lore
Share & tools
lore
#0 lore raw

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

Some cleanup API are used and one extra patch for mdio_mutex_nested is introduced. As suggested some time ago, the use of such API is limited to scoped variants and not the guard ones.

Posting as RFC as I expect in later version to add additional feature but this is already working and upstream-ready. So this is really to have a review of the very basic features and if I missed anything in recent implementation of DSA.

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 (3):
dt-bindings: net: dsa: Add Airoha AN8855 Gigabit Switch documentation
net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver
net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY

 .../bindings/net/dsa/airoha,an8855.yaml       |  253 +++
 MAINTAINERS                                   |   11 +
 drivers/net/dsa/Kconfig                       |    9 +
 drivers/net/dsa/Makefile                      |    1 +
 drivers/net/dsa/an8855.c                      | 2012 +++++++++++++++++
 drivers/net/dsa/an8855.h                      |  498 ++++
 drivers/net/phy/Kconfig                       |    5 +
 drivers/net/phy/Makefile                      |    1 +
 drivers/net/phy/air_an8855.c                  |  265 +++
 9 files changed, 3055 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml
 create mode 100644 drivers/net/dsa/an8855.c
 create mode 100644 drivers/net/dsa/an8855.h
 create mode 100644 drivers/net/phy/air_an8855.c
Signature · 1 line
2.45.2
#1 lore raw

RFC PATCH v2 1/3 dt-bindings: net: dsa: Add Airoha AN8855 Gigabit Switch documentation

Add Airoha AN8855 5 port Gigabit Switch documentation.

The switch node requires an additional mdio node to describe each internal PHY relative offset as the PHY address for the switch match the one for the PHY ports. On top of internal PHY address, the switch base PHY address is added.

Also the switch base PHY address can be configured and changed after the first initialization. On reset, the switch PHY address is ALWAYS 1. This can be configured with the use of "airoha,base_smi_address".

Calibration values might be stored in switch EFUSE and internal PHY might need to be calibrated, in such case, airoha,ext_surge needs to be enabled and relative NVMEM cells needs to be defined in nvmem-layout node.

---
 .../bindings/net/dsa/airoha,an8855.yaml       | 253 ++++++++++++++++++
 1 file changed, 253 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml
Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml new file +253 -0
new file mode 100644
index 000000000000..5982b4c39536
@@ -0,0 +1,253 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/dsa/airoha,an8855.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.
+
+  The switch node requires an additional mdio node to describe each internal
+  PHY relative offset as the PHY address for the switch match the one for
+  the PHY ports. On top of internal PHY address, the switch base PHY address
+  is added.
+
+  Also the switch base PHY address can be configured and changed after the
+  first initialization. On reset, the switch PHY address is ALWAYS 1.
+
+properties:
+  compatible:
+    const: airoha,an8855
+
+  reg:
+    maxItems: 1
+
+  reset-gpios:
+    description:
+      GPIO to be used to reset the whole device
+    maxItems: 1
+
+  airoha,base_smi_address:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description:
+      Configure and change the base switch PHY address to a new address on
+      the bus.
+      On reset, the switch PHY address is ALWAYS 1.
+    default: 1
+    maximum: 31
+
+  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.
+
+  '#nvmem-cell-cells':
+    const: 0
+
+  nvmem-layout:
+    $ref: /schemas/nvmem/layouts/nvmem-layout.yaml
+    description:
+      NVMEM Layout for exposed EFUSE. (for example to propagate calibration
+      value for r50Ohm for internal PHYs)
+
+  mdio:
+    $ref: /schemas/net/mdio.yaml#
+    unevaluatedProperties: false
+    description:
+      Define the relative address of the internal PHY for each port.
+
+      Each reg for the PHY is relative to the switch base PHY address.
+
+$ref: dsa.yaml#
+
+required:
+  - compatible
+  - reg
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+
+    mdio {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        switch@1 {
+            compatible = "airoha,an8855";
+            reg = <1>;
+            reset-gpios = <&pio 39 0>;
+
+            airoha,ext_surge;
+
+            #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>;
+                };
+            };
+
+            ports {
+                #address-cells = <1>;
+                #size-cells = <0>;
+
+                port@0 {
+                    reg = <0>;
+                    label = "lan1";
+                    phy-mode = "internal";
+                    phy-handle = <&internal_phy0>;
+                };
+
+                port@1 {
+                    reg = <1>;
+                    label = "lan2";
+                    phy-mode = "internal";
+                    phy-handle = <&internal_phy1>;
+                };
+
+                port@2 {
+                    reg = <2>;
+                    label = "lan3";
+                    phy-mode = "internal";
+                    phy-handle = <&internal_phy2>;
+                };
+
+                port@3 {
+                    reg = <3>;
+                    label = "lan4";
+                    phy-mode = "internal";
+                    phy-handle = <&internal_phy3>;
+                };
+
+                port@5 {
+                    reg = <5>;
+                    label = "cpu";
+                    ethernet = <&gmac0>;
+                    phy-mode = "2500base-x";
+
+                    fixed-link {
+                        speed = <2500>;
+                        full-duplex;
+                        pause;
+                    };
+                };
+            };
+
+            mdio {
+                #address-cells = <1>;
+                #size-cells = <0>;
+
+                internal_phy0: phy@0 {
+                    reg = <0>;
+
+                    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_phy1: phy@1 {
+                    reg = <1>;
+
+                    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";
+                };
+
+                internal_phy2: phy@2 {
+                    reg = <2>;
+
+                    nvmem-cells = <&shift_sel_port2_tx_a>,
+                                  <&shift_sel_port2_tx_b>,
+                                  <&shift_sel_port2_tx_c>,
+                                  <&shift_sel_port2_tx_d>;
+                    nvmem-cell-names = "tx_a", "tx_b", "tx_c", "tx_d";
+                };
+
+                internal_phy3: phy@3 {
+                    reg = <3>;
+
+                    nvmem-cells = <&shift_sel_port3_tx_a>,
+                                  <&shift_sel_port3_tx_b>,
+                                  <&shift_sel_port3_tx_c>,
+                                  <&shift_sel_port3_tx_d>;
+                    nvmem-cell-names = "tx_a", "tx_b", "tx_c", "tx_d";
+                };
+            };
+        };
+    };
Signature · 1 line
2.45.2
maintainer
#2 lore raw

Re: [net-next RFC PATCH v2 1/3] dt-bindings: net: dsa: Add Airoha AN8855 Gigabit Switch documentation

Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml line 42

Quoted 8 lines
Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml new file +8 -0
+  airoha,base_smi_address:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description:
+      Configure and change the base switch PHY address to a new address on
+      the bus.
+      On reset, the switch PHY address is ALWAYS 1.
+    default: 1
+    maximum: 31

Given that this is a 5 port switch, what happens if i pick a value greater than 31 - 5 ?

Do you have a real use case for this? A board which requires the PHYs get shifted from the default of 1? Vendors have all sorts of bells and whistles which we never use. If its not needed, i would not add it, until it is actually needed, if ever.

Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml line 65

Quoted 7 lines
Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml new file +7 -0
+  mdio:
+    $ref: /schemas/net/mdio.yaml#
+    unevaluatedProperties: false
+    description:
+      Define the relative address of the internal PHY for each port.
+
+      Each reg for the PHY is relative to the switch base PHY address.

Which is not the usual meaning of reg.

Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml line 213

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml new file +6 -0
+            mdio {
+                #address-cells = <1>;
+                #size-cells = <0>;
+
+                internal_phy0: phy@0 {
+                    reg = <0>;

So given that airoha,base_smi_address defaults to 1, this is actually address 1 on the MDIO bus?

Andrew

#3 lore raw

Re: [net-next RFC PATCH v2 1/3] dt-bindings: net: dsa: Add Airoha AN8855 Gigabit Switch documentation

Quoted 11 lines · Andrew Lunn

Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml line 42

Quoted 8 lines
Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml new file +8 -0
+  airoha,base_smi_address:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description:
+      Configure and change the base switch PHY address to a new address on
+      the bus.
+      On reset, the switch PHY address is ALWAYS 1.
+    default: 1
+    maximum: 31

Given that this is a 5 port switch, what happens if i pick a value greater than 31 - 5 ?

The PHY at those address won't be reachable, I didn't think of this, you are right.

Quoted 5 lines

Do you have a real use case for this? A board which requires the PHYs get shifted from the default of 1? Vendors have all sorts of bells and whistles which we never use. If its not needed, i would not add it, until it is actually needed, if ever.

Well the first case that comes to mind is multiple switch and conflict. I have no idea if there are hw strap to configure this so I assume if a SoC have 2 switch (maybe of the same type), this permits to configure them (with reset pin and deasserting them once the base address is correctly configured)

But yes totally ok to drop this if too strange... I assume it's problematic that PHY change at runtime.

Quoted 18 lines

Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml line 65

Quoted 8 lines
Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml new file +7 -0
+  mdio:
+    $ref: /schemas/net/mdio.yaml#
+    unevaluatedProperties: false
+    description:
+      Define the relative address of the internal PHY for each port.
+
+      Each reg for the PHY is relative to the switch base PHY address.

Which is not the usual meaning of reg.

Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml line 213

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml new file +6 -0
+            mdio {
+                #address-cells = <1>;
+                #size-cells = <0>;
+
+                internal_phy0: phy@0 {
+                    reg = <0>;
Quoted 3 lines

So given that airoha,base_smi_address defaults to 1, this is actually address 1 on the MDIO bus?

Yes correct. One problem I had was that moving this outside the swich cause panic as it does conflict with the switch PHY address...

Signature · 1 line
	Ansuel
maintainer
#4 lore raw

Re: [net-next RFC PATCH v2 1/3] dt-bindings: net: dsa: Add Airoha AN8855 Gigabit Switch documentation

Quoted 5 lines

Well the first case that comes to mind is multiple switch and conflict. I have no idea if there are hw strap to configure this so I assume if a SoC have 2 switch (maybe of the same type), this permits to configure them (with reset pin and deasserting them once the base address is correctly configured)

Is this switch internal on an internal MDIO bus, or external?

Most PHYs and switches i've seen have strapping pins to set the base address. It would be unusual if there was not strapping.

For the Marvell switches, the strapping moves all the MDIO registers. This is why we have a reg at the top level in mv88e6xxx:

        ethernet-switch@0 {
            compatible = "marvell,mv88e6085";
            reg = <0>;

There is one family which use the values of 0 or 16, and each switch uses 16 addresses. So you can put two on the bus.

Quoted 17 lines
Quoted 17 lines

Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml line 65

Quoted 7 lines
Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml new file +7 -0
+  mdio:
+    $ref: /schemas/net/mdio.yaml#
+    unevaluatedProperties: false
+    description:
+      Define the relative address of the internal PHY for each port.
+
+      Each reg for the PHY is relative to the switch base PHY address.

Which is not the usual meaning of reg.

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml new file +6 -0
+            mdio {
+                #address-cells = <1>;
+                #size-cells = <0>;
+
+                internal_phy0: phy@0 {
+                    reg = <0>;
Quoted 6 lines
Quoted 3 lines

So given that airoha,base_smi_address defaults to 1, this is actually address 1 on the MDIO bus?

Yes correct. One problem I had was that moving this outside the swich cause panic as it does conflict with the switch PHY address...

I would make these addresses absolute, not relative. The example above from the marvell switch, the device using addresses 16-31 has its PHYs within that range, and we uses the absolute reg values.

Andrew

#5 lore raw

Re: [net-next RFC PATCH v2 1/3] dt-bindings: net: dsa: Add Airoha AN8855 Gigabit Switch documentation

Quoted 7 lines · Andrew Lunn
Quoted 5 lines

Well the first case that comes to mind is multiple switch and conflict. I have no idea if there are hw strap to configure this so I assume if a SoC have 2 switch (maybe of the same type), this permits to configure them (with reset pin and deasserting them once the base address is correctly configured)

Is this switch internal on an internal MDIO bus, or external?

External so it can be mounted on any SoC given correct mdio/mdc.

Quoted 3 lines

Most PHYs and switches i've seen have strapping pins to set the base address. It would be unusual if there was not strapping.

Same feeling, but I didn't found anything in the documentation. (actually no mention of hw strap or pin)

Quoted 11 lines

For the Marvell switches, the strapping moves all the MDIO registers. This is why we have a reg at the top level in mv88e6xxx:

        ethernet-switch@0 {
            compatible = "marvell,mv88e6085";
            reg = <0>;

There is one family which use the values of 0 or 16, and each switch uses 16 addresses. So you can put two on the bus.

Yes this is what that property does. Everything is shifted.

Quoted 21 lines
Quoted 21 lines
Quoted 20 lines

Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml line 65

Quoted 7 lines
Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml new file +7 -0
+  mdio:
+    $ref: /schemas/net/mdio.yaml#
+    unevaluatedProperties: false
+    description:
+      Define the relative address of the internal PHY for each port.
+
+      Each reg for the PHY is relative to the switch base PHY address.

Which is not the usual meaning of reg.

Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml line 213

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml new file +6 -0
+            mdio {
+                #address-cells = <1>;
+                #size-cells = <0>;
+
+                internal_phy0: phy@0 {
+                    reg = <0>;

So given that airoha,base_smi_address defaults to 1, this is actually address 1 on the MDIO bus?

Quoted 7 lines
Quoted 2 lines

Yes correct. One problem I had was that moving this outside the swich cause panic as it does conflict with the switch PHY address...

I would make these addresses absolute, not relative. The example above from the marvell switch, the device using addresses 16-31 has its PHYs within that range, and we uses the absolute reg values.

They were relative with the base SMI implementation in mind (as we would then offset) If the path is to drop that option then yes, these address should be absolute.

Or do you think even with that option, these address should be absolute?

Signature · 1 line
	Ansuel
maintainer
#6 lore raw

Re: [net-next RFC PATCH v2 1/3] dt-bindings: net: dsa: Add Airoha AN8855 Gigabit Switch documentation

In reply to Christian Marangi
Quoted 30 lines · Christian Marangi

Add Airoha AN8855 5 port Gigabit Switch documentation.

The switch node requires an additional mdio node to describe each internal PHY relative offset as the PHY address for the switch match the one for the PHY ports. On top of internal PHY address, the switch base PHY address is added.

Also the switch base PHY address can be configured and changed after the first initialization. On reset, the switch PHY address is ALWAYS 1. This can be configured with the use of "airoha,base_smi_address".

Calibration values might be stored in switch EFUSE and internal PHY might need to be calibrated, in such case, airoha,ext_surge needs to be enabled and relative NVMEM cells needs to be defined in nvmem-layout node.

---
 .../bindings/net/dsa/airoha,an8855.yaml       | 253 ++++++++++++++++++
 1 file changed, 253 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml
Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml new file +2 -0
new file mode 100644
index 000000000000..5982b4c39536
@@ -0,0 +1,253 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2

Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml line 12

Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml new file +10 -0
+---
+$id: http://devicetree.org/schemas/net/dsa/airoha,an8855.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Airoha AN8855 Gigabit switch
+
+maintainers:
+  - Christian Marangi <[email protected]>
+
+description:

You need '>' to preserve paragraphs.

Quoted 13 lines
Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml new file +13 -0
+  Airoha AN8855 is a 5-port Gigabit Switch.
+
+  The switch node requires an additional mdio node to describe each internal
+  PHY relative offset as the PHY address for the switch match the one for
+  the PHY ports. On top of internal PHY address, the switch base PHY address
+  is added.
+
+  Also the switch base PHY address can be configured and changed after the
+  first initialization. On reset, the switch PHY address is ALWAYS 1.
+
+properties:
+  compatible:
+    const: airoha,an8855

Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml line 35

Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml new file +10 -0
+
+  reg:
+    maxItems: 1
+
+  reset-gpios:
+    description:
+      GPIO to be used to reset the whole device
+    maxItems: 1
+
+  airoha,base_smi_address:

s/_/-/

Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml line 40

Quoted 5 lines
Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml new file +5 -0
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description:
+      Configure and change the base switch PHY address to a new address on
+      the bus.
+      On reset, the switch PHY address is ALWAYS 1.

The paragraphs here won't be maintained without '>' and a blank line in between.

Or just move the 2nd sentence up to follow the first one.

Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml line 44

Quoted 4 lines
Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml new file +4 -0
+    default: 1
+    maximum: 31
+
+  airoha,ext_surge:

ditto.

Quoted 212 lines
Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml new file +209 -0
+    $ref: /schemas/types.yaml#/definitions/flag
+    description:
+      Calibrate the internal PHY with the calibration values stored in EFUSE
+      for the r50Ohm values.
+
+  '#nvmem-cell-cells':
+    const: 0
+
+  nvmem-layout:
+    $ref: /schemas/nvmem/layouts/nvmem-layout.yaml
+    description:
+      NVMEM Layout for exposed EFUSE. (for example to propagate calibration
+      value for r50Ohm for internal PHYs)
+
+  mdio:
+    $ref: /schemas/net/mdio.yaml#
+    unevaluatedProperties: false
+    description:
+      Define the relative address of the internal PHY for each port.
+
+      Each reg for the PHY is relative to the switch base PHY address.
+
+$ref: dsa.yaml#
+
+required:
+  - compatible
+  - reg
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+
+    mdio {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        switch@1 {
+            compatible = "airoha,an8855";
+            reg = <1>;
+            reset-gpios = <&pio 39 0>;
+
+            airoha,ext_surge;
+
+            #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>;
+                };
+            };
+
+            ports {
+                #address-cells = <1>;
+                #size-cells = <0>;
+
+                port@0 {
+                    reg = <0>;
+                    label = "lan1";
+                    phy-mode = "internal";
+                    phy-handle = <&internal_phy0>;
+                };
+
+                port@1 {
+                    reg = <1>;
+                    label = "lan2";
+                    phy-mode = "internal";
+                    phy-handle = <&internal_phy1>;
+                };
+
+                port@2 {
+                    reg = <2>;
+                    label = "lan3";
+                    phy-mode = "internal";
+                    phy-handle = <&internal_phy2>;
+                };
+
+                port@3 {
+                    reg = <3>;
+                    label = "lan4";
+                    phy-mode = "internal";
+                    phy-handle = <&internal_phy3>;
+                };
+
+                port@5 {
+                    reg = <5>;
+                    label = "cpu";
+                    ethernet = <&gmac0>;
+                    phy-mode = "2500base-x";
+
+                    fixed-link {
+                        speed = <2500>;
+                        full-duplex;
+                        pause;
+                    };
+                };
+            };
+
+            mdio {
+                #address-cells = <1>;
+                #size-cells = <0>;
+
+                internal_phy0: phy@0 {
+                    reg = <0>;
+
+                    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_phy1: phy@1 {
+                    reg = <1>;
+
+                    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";
+                };
+
+                internal_phy2: phy@2 {
+                    reg = <2>;
+
+                    nvmem-cells = <&shift_sel_port2_tx_a>,
+                                  <&shift_sel_port2_tx_b>,
+                                  <&shift_sel_port2_tx_c>,
+                                  <&shift_sel_port2_tx_d>;
+                    nvmem-cell-names = "tx_a", "tx_b", "tx_c", "tx_d";
+                };
+
+                internal_phy3: phy@3 {
+                    reg = <3>;
+
+                    nvmem-cells = <&shift_sel_port3_tx_a>,
+                                  <&shift_sel_port3_tx_b>,
+                                  <&shift_sel_port3_tx_c>,
+                                  <&shift_sel_port3_tx_d>;
+                    nvmem-cell-names = "tx_a", "tx_b", "tx_c", "tx_d";
+                };
+            };
+        };
+    };
Signature · 1 line
2.45.2
#7 lore raw

RFC PATCH v2 2/3 net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver

In reply to Christian Marangi

Add Airoha AN8855 5-Port Gigabit DSA switch.

---
 MAINTAINERS              |   10 +
 drivers/net/dsa/Kconfig  |    9 +
 drivers/net/dsa/Makefile |    1 +
 drivers/net/dsa/an8855.c | 2012 ++++++++++++++++++++++++++++++++++++++
 drivers/net/dsa/an8855.h |  498 ++++++++++
 5 files changed, 2530 insertions(+)
 create mode 100644 drivers/net/dsa/an8855.c
 create mode 100644 drivers/net/dsa/an8855.h
MAINTAINERS +10 -0
index 16933f9faa0f..e3077d9feee2 100644
@@ -717,6 +717,16 @@ 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/net/dsa/airoha,an8855.yaml
+F:	drivers/net/dsa/an8855.c
+F:	drivers/net/dsa/an8855.h
+
 AIROHA ETHERNET DRIVER
 M:	Lorenzo Bianconi <[email protected]>
 L:	[email protected] (moderated for non-subscribers)
drivers/net/dsa/Kconfig +9 -0
index 2d10b4d6cfbb..6b6d0b7bae72 100644
@@ -24,6 +24,15 @@ config NET_DSA_LOOP
 	  This enables support for a fake mock-up switch chip which
 	  exercises the DSA APIs.
 
+
+config NET_DSA_AN8855
+	tristate "Airoha AN8855 Ethernet switch support"
+	depends on NET_DSA
+	select NET_DSA_TAG_MTK
+	help
+	  This enables support for the Airoha AN8855 Ethernet switch
+	  chip.
+
 source "drivers/net/dsa/hirschmann/Kconfig"
 
 config NET_DSA_LANTIQ_GSWIP
drivers/net/dsa/Makefile +1 -0
index cb9a97340e58..a74afb41a491 100644
@@ -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 +2012 -0

2,012 lines not on this page · raw message

drivers/net/dsa/an8855.h new file +498 -0

498 lines not on this page · raw message

Signature · 1 line
2.45.2
#8 lore raw

Re: [net-next RFC PATCH v2 2/3] net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver

kernel test robot noticed the following build errors:

Hi Christian,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:

[auto build test ERROR on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Christian-Marangi/dt-bindings-net-dsa-Add-Airoha-AN8855-Gigabit-Switch-documentation/20241024-002325
base:   net-next/main
patch link:    https://lore.kernel.org/r/20241023161958.12056-3-ansuelsmth%40gmail.com
patch subject: [net-next RFC PATCH v2 2/3] net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver
config: alpha-allyesconfig (https://download.01.org/0day-ci/archive/20241027/[email protected]/config)
compiler: alpha-linux-gcc (GCC) 13.3.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241027/[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 errors (new ones prefixed by >>):

alpha-linux-ld: drivers/net/dsa/an8855.o: in function `an8855_port_vlan_add':

>> (.text+0x1d5c): undefined reference to `__ffsdi2'
>> alpha-linux-ld: (.text+0x1d8c): undefined reference to `__ffsdi2'
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#9 lore raw

Re: [net-next RFC PATCH v2 2/3] net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver

In reply to Christian Marangi
kernel test robot noticed the following build errors:

Hi Christian,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:

[auto build test ERROR on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Christian-Marangi/dt-bindings-net-dsa-Add-Airoha-AN8855-Gigabit-Switch-documentation/20241024-002325
base:   net-next/main
patch link:    https://lore.kernel.org/r/20241023161958.12056-3-ansuelsmth%40gmail.com
patch subject: [net-next RFC PATCH v2 2/3] net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver
config: arm-allyesconfig (https://download.01.org/0day-ci/archive/20241027/[email protected]/config)
compiler: arm-linux-gnueabi-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241027/[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 errors (new ones prefixed by >>):

arm-linux-gnueabi-ld: drivers/net/dsa/an8855.o: in function `an8855_vlan_add':

>> an8855.c:(.text.an8855_vlan_add+0x1a4): undefined reference to `__ffsdi2'

Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for GET_FREE_REGION Depends on [n]: SPARSEMEM [=n]
Selected by [y]:
- RESOURCE_KUNIT_TEST [=y] && RUNTIME_TESTING_MENU [=y] && KUNIT [=y]

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#10 lore raw

RFC PATCH v2 3/3 net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY

In reply to Christian Marangi

Add support for Airoha AN8855 Internal Switch Gigabit PHY.

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

---
 MAINTAINERS                  |   1 +
 drivers/net/phy/Kconfig      |   5 +
 drivers/net/phy/Makefile     |   1 +
 drivers/net/phy/air_an8855.c | 265 +++++++++++++++++++++++++++++++++++
 4 files changed, 272 insertions(+)
 create mode 100644 drivers/net/phy/air_an8855.c
MAINTAINERS +1 -0
index e3077d9feee2..cf34add2a0bb 100644
@@ -726,6 +726,7 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml
 F:	drivers/net/dsa/an8855.c
 F:	drivers/net/dsa/an8855.h
+F:	drivers/net/phy/air_an8855.c
 
 AIROHA ETHERNET DRIVER
 M:	Lorenzo Bianconi <[email protected]>
drivers/net/phy/Kconfig +5 -0
index ee3ea0b56d48..1d474038ea7f 100644
@@ -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
index 90f886844381..baba7894785b 100644
@@ -35,6 +35,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 +265 -0

265 lines not on this page · raw message

Signature · 1 line
2.45.2
maintainer
#11 lore raw

Re: [net-next RFC PATCH v2 3/3] net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY

drivers/net/phy/air_an8855.c line 132

Quoted 4 lines
drivers/net/phy/air_an8855.c new file +4 -0
+	/* Enable Asymmetric Pause Capability */
+	ret = phy_set_bits(phydev, MII_ADVERTISE, ADVERTISE_PAUSE_ASYM);
+	if (ret)
+		return ret;

The PHY driver alone does not decide this. The MAC driver needs to indicate it supports asym pause by calling phy_supports_asym_pause().

drivers/net/phy/air_an8855.c line 137

Quoted 5 lines
drivers/net/phy/air_an8855.c new file +5 -0
+
+	/* Disable EEE */
+	ret = phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, 0);
+	if (ret)
+		return ret;

Again, the core code should handle this, unless EEE is broken and you need to force it off.

Andrew

#12 lore raw

Re: [net-next RFC PATCH v2 3/3] net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY

Quoted 8 lines · Andrew Lunn

drivers/net/phy/air_an8855.c line 132

Quoted 4 lines
drivers/net/phy/air_an8855.c new file +4 -0
+	/* Enable Asymmetric Pause Capability */
+	ret = phy_set_bits(phydev, MII_ADVERTISE, ADVERTISE_PAUSE_ASYM);
+	if (ret)
+		return ret;

The PHY driver alone does not decide this. The MAC driver needs to indicate it supports asym pause by calling phy_supports_asym_pause().

Sorry for the stupid question, I couldn't find this OPs. Any hit how to handle this?

Quoted 9 lines

drivers/net/phy/air_an8855.c line 137

Quoted 5 lines
drivers/net/phy/air_an8855.c new file +5 -0
+
+	/* Disable EEE */
+	ret = phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, 0);
+	if (ret)
+		return ret;

Again, the core code should handle this, unless EEE is broken and you need to force it off.

They confirmed this was done just to handle kernel init condition... Will drop.

Signature · 1 line
	Ansuel
maintainer
#13 lore raw

Re: [net-next RFC PATCH v2 3/3] net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY

Quoted 10 lines · Christian Marangi
Quoted 8 lines · Andrew Lunn

drivers/net/phy/air_an8855.c line 132

Quoted 4 lines
drivers/net/phy/air_an8855.c new file +4 -0
+	/* Enable Asymmetric Pause Capability */
+	ret = phy_set_bits(phydev, MII_ADVERTISE, ADVERTISE_PAUSE_ASYM);
+	if (ret)
+		return ret;

The PHY driver alone does not decide this. The MAC driver needs to indicate it supports asym pause by calling phy_supports_asym_pause().

Quoted 2 lines

Sorry for the stupid question, I couldn't find this OPs. Any hit how to handle this?

For phylink, set MAC_ASYM_PAUSE | MAC_SYM_PAUSE in the capabilities in phylink_config.

For phylib, call phy_support_asym_pause(phydev) after connecting to the PHY.

Andrew

maintainer
#14 lore raw

Re: [net-next RFC PATCH v2 3/3] net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY

In reply to Christian Marangi
Quoted 6 lines
drivers/net/phy/air_an8855.c new file +6 -0
+static int an8855_config_init(struct phy_device *phydev)
+{
+	struct air_an8855_priv *priv = phydev->priv;
+	int ret;
+
+	/* Enable HW auto downshift */

drivers/net/phy/air_an8855.c line 127

Quoted 10 lines
drivers/net/phy/air_an8855.c new file +10 -0
+	ret = phy_write(phydev, AN8855_PHY_PAGE_CTRL, AN8855_PHY_EXT_PAGE);
+	if (ret)
+		return ret;
+	ret = phy_set_bits(phydev, AN8855_PHY_EXT_REG_14,
+			   AN8855_PHY_EN_DOWN_SHFIT);
+	if (ret)
+		return ret;
+	ret = phy_write(phydev, AN8855_PHY_PAGE_CTRL, AN8855_PHY_NORMAL_PAGE);
+	if (ret)
+		return ret;

There are locking issues here, which is why we have the helpers phy_select_page() and phy_restore_page(). The air_en8811h.c gets this right.

Is there anything in common with the en8811h? Does it also support downshift? Can its LED code be used here?

Andrew

#15 lore raw

Re: [net-next RFC PATCH v2 3/3] net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY

Quoted 12 lines · Andrew Lunn
Quoted 12 lines
drivers/net/phy/air_an8855.c new file +12 -0
+static int an8855_config_init(struct phy_device *phydev)
+{
+	struct air_an8855_priv *priv = phydev->priv;
+	int ret;
+
+	/* Enable HW auto downshift */
+	ret = phy_write(phydev, AN8855_PHY_PAGE_CTRL, AN8855_PHY_EXT_PAGE);
+	if (ret)
+		return ret;
+	ret = phy_set_bits(phydev, AN8855_PHY_EXT_REG_14,
+			   AN8855_PHY_EN_DOWN_SHFIT);
+	if (ret)
Quoted 8 lines

drivers/net/phy/air_an8855.c line 127

Quoted 4 lines
drivers/net/phy/air_an8855.c new file +4 -0
+		return ret;
+	ret = phy_write(phydev, AN8855_PHY_PAGE_CTRL, AN8855_PHY_NORMAL_PAGE);
+	if (ret)
+		return ret;

There are locking issues here, which is why we have the helpers phy_select_page() and phy_restore_page(). The air_en8811h.c gets this right.

Ugh didn't think about it... The switch address is shared with the PHY so yes this is a problem.

Consider that this page thing comes from my speculation... Not really use if 1f select page...
From what I observed
0x0 PHY page
0x1 this strange EXT
0x4 acess switch register (every PHY can access the switch)

Quoted 4 lines

Is there anything in common with the en8811h? Does it also support downshift? Can its LED code be used here?

For some reason part of the LED are controlled by the switch and some are by the PHY. I still have to investigate that (not giving priority to it... just on my todo)

For downshift as you notice it's a single bit with no count... From their comments in the original driver it's said "Enable HW autodownshift"

Trying to reach them but currently it's all very obscure.

Signature · 1 line
	Ansuel
#16 lore raw

Re: [net-next RFC PATCH v2 3/3] net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY

Quoted 25 lines · Christian Marangi
Quoted 12 lines · Andrew Lunn
Quoted 12 lines
drivers/net/phy/air_an8855.c new file +12 -0
+static int an8855_config_init(struct phy_device *phydev)
+{
+	struct air_an8855_priv *priv = phydev->priv;
+	int ret;
+
+	/* Enable HW auto downshift */
+	ret = phy_write(phydev, AN8855_PHY_PAGE_CTRL, AN8855_PHY_EXT_PAGE);
+	if (ret)
+		return ret;
+	ret = phy_set_bits(phydev, AN8855_PHY_EXT_REG_14,
+			   AN8855_PHY_EN_DOWN_SHFIT);
+	if (ret)
Quoted 8 lines

drivers/net/phy/air_an8855.c line 127

Quoted 4 lines
drivers/net/phy/air_an8855.c new file +4 -0
+		return ret;
+	ret = phy_write(phydev, AN8855_PHY_PAGE_CTRL, AN8855_PHY_NORMAL_PAGE);
+	if (ret)
+		return ret;

There are locking issues here, which is why we have the helpers phy_select_page() and phy_restore_page(). The air_en8811h.c gets this right.

Ugh didn't think about it... The switch address is shared with the PHY so yes this is a problem.

Quoted 7 lines

Consider that this page thing comes from my speculation... Not really use if 1f select page...
From what I observed
0x0 PHY page
0x1 this strange EXT
0x4 acess switch register (every PHY can access the switch)

Just to followup on this... I checked air_en8811h registers again and they match MII access to the switch so yes my speculation is correct.

Also extra happy since I now know what those magic values means at least for MII.

Quoted 17 lines
Quoted 4 lines

Is there anything in common with the en8811h? Does it also support downshift? Can its LED code be used here?

For some reason part of the LED are controlled by the switch and some are by the PHY. I still have to investigate that (not giving priority to it... just on my todo)

For downshift as you notice it's a single bit with no count... From their comments in the original driver it's said "Enable HW autodownshift"

Trying to reach them but currently it's all very obscure.

Signature · 1 line
	Ansuel
Signature · 1 line
	Ansuel