Skip to contentSkip to conversation

net: mtip: Add support for MTIP imx287 L2 switch driver

PATCH Superseded Lukasz Majewski 6 participants 24 messages Mar 31, 2025 – Apr 7, 2025

Subsystems (4)

v3 of 17 Superseded Latest is v17 →

lore
Share & tools
lore
#0 lore raw

v3 cover net: mtip: Add support for MTIP imx287 L2 switch driver

This patch series adds support for More Than IP's L2 switch driver embedded in some NXP's SoCs. This one has been tested on imx287, but is also available in the vf610.

In the past there has been performed some attempts to upstream this driver:
1. The 4.19-cip based one [1]
2. DSA based one for 5.12 [2] - i.e. the switch itself was treat as a DSA switch with NO tag appended.
3. The extension for FEC driver for 5.12 [3] - the trick here was to fully reuse FEC when the in-HW switching is disabled. When bridge offloading is enabled, the driver uses already configured MAC and PHY to also configure PHY.

All three approaches were not accepted as eligible for upstreaming.

The driver from this series has floowing features:

1. It is fully separated from fec_main - i.e. can be used interchangeable with it. To be more specific - one can build them as modules and if required switch between them when e.g. bridge offloading is required.

To be more specific:
- Use FEC_MAIN: When one needs support for two ETH ports with separate uDMAs used for both and bridging can be realized in SW.

- Use MTIPL2SW: When it is enough to support two ports with only uDMA0 attached to switch and bridging shall be offloaded to HW.

2. This driver uses MTIP's L2 switch internal VLAN feature to provide port separation at boot time. Port separation is disabled when bridging is required.

3. Example usage:

        Configuration:
        ip link set lan0 up; sleep 1;
        ip link set lan1 up; sleep 1;
        ip link add name br0 type bridge;
        ip link set br0 up; sleep 1;
        ip link set lan0 master br0;
        ip link set lan1 master br0;
        bridge link;
        ip addr add 192.168.2.17/24 dev br0;
        ping -c 5 192.168.2.222

        Removal:
        ip link set br0 down;
        ip link delete br0 type bridge;
        ip link set dev lan1 down
        ip link set dev lan0 down

4. Limitations:
- Driver enables and disables switch operation with learning and ageing.
- Missing is the advanced configuration (e.g. adding entries to FBD). This is on purpose, as up till now we didn't had consensus about how the driver shall be added to Linux.

Links:
[1] - https://github.com/lmajewski/linux-imx28-l2switch/commits/master
[2] - https://github.com/lmajewski/linux-imx28-l2switch/tree/imx28-v5.12-L2-upstream-RFC_v1
[3] - https://source.denx.de/linux/linux-imx28-l2switch/-/tree/imx28-v5.12-L2-upstream-switchdev-RFC_v1?ref_type=heads

Lukasz Majewski (4):
dt-bindings: net: Add MTIP L2 switch description
ARM: dts: nxp: mxs: Adjust the imx28.dtsi L2 switch description
ARM: dts: nxp: mxs: Adjust XEA board's DTS to support L2 switch
net: mtip: The L2 switch driver for imx287

 .../bindings/net/nxp,imx287-mtip-switch.yaml  |  154 ++
 MAINTAINERS                                   |    7 +
 arch/arm/boot/dts/nxp/mxs/imx28-xea.dts       |   54 +
 arch/arm/boot/dts/nxp/mxs/imx28.dtsi          |    8 +-
 drivers/net/ethernet/freescale/Kconfig        |    1 +
 drivers/net/ethernet/freescale/Makefile       |    1 +
 drivers/net/ethernet/freescale/mtipsw/Kconfig |   13 +
 .../net/ethernet/freescale/mtipsw/Makefile    |    3 +
 .../net/ethernet/freescale/mtipsw/mtipl2sw.c  | 1964 +++++++++++++++++
 .../net/ethernet/freescale/mtipsw/mtipl2sw.h  |  780 +++++++
 .../ethernet/freescale/mtipsw/mtipl2sw_br.c   |  113 +
 .../ethernet/freescale/mtipsw/mtipl2sw_mgnt.c |  449 ++++
 12 files changed, 3545 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml
 create mode 100644 drivers/net/ethernet/freescale/mtipsw/Kconfig
 create mode 100644 drivers/net/ethernet/freescale/mtipsw/Makefile
 create mode 100644 drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c
 create mode 100644 drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h
 create mode 100644 drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c
 create mode 100644 drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c
Signature · 1 line
2.39.5
#1 lore raw

PATCH v3 1/4 dt-bindings: net: Add MTIP L2 switch description

This patch provides description of the MTIP L2 switch available in some NXP's SOCs - e.g. imx287.

---
Changes for v2:
- Rename the file to match exactly the compatible
(nxp,imx287-mtip-switch)

Changes for v3:
- Remove '-' from const:'nxp,imx287-mtip-switch'
- Use '^port@[12]+$' for port patternProperties
- Drop status = "okay";
- Provide proper indentation for 'example' binding (replace 8 spaces with 4 spaces)
- Remove smsc,disable-energy-detect; property
- Remove interrupt-parent and interrupts properties as not required
- Remove #address-cells and #size-cells from required properties check
- remove description from reg:
- Add $ref: ethernet-switch.yaml#

---
 .../bindings/net/nxp,imx287-mtip-switch.yaml  | 154 ++++++++++++++++++
 1 file changed, 154 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml
Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +154 -0
new file mode 100644
index 000000000000..98eba3665f32
@@ -0,0 +1,154 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/nxp,imx287-mtip-switch.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: NXP SoC Ethernet Switch Controller (L2 MoreThanIP switch)
+
+maintainers:
+  - Lukasz Majewski <[email protected]>
+
+description:
+  The 2-port switch ethernet subsystem provides ethernet packet (L2)
+  communication and can be configured as an ethernet switch. It provides the
+  reduced media independent interface (RMII), the management data input
+  output (MDIO) for physical layer device (PHY) management.
+
+$ref: ethernet-switch.yaml#
+
+properties:
+  compatible:
+    const: nxp,imx287-mtip-switch
+
+  reg:
+    maxItems: 1
+
+  phy-supply:
+    description:
+      Regulator that powers Ethernet PHYs.
+
+  clocks:
+    items:
+      - description: Register accessing clock
+      - description: Bus access clock
+      - description: Output clock for external device - e.g. PHY source clock
+      - description: IEEE1588 timer clock
+
+  clock-names:
+    items:
+      - const: ipg
+      - const: ahb
+      - const: enet_out
+      - const: ptp
+
+  interrupts:
+    items:
+      - description: Switch interrupt
+      - description: ENET0 interrupt
+      - description: ENET1 interrupt
+
+  pinctrl-names: true
+
+  ethernet-ports:
+    type: object
+    additionalProperties: false
+
+    properties:
+      '#address-cells':
+        const: 1
+      '#size-cells':
+        const: 0
+
+    patternProperties:
+      '^port@[12]+$':
+        type: object
+        description: MTIP L2 switch external ports
+
+        $ref: ethernet-controller.yaml#
+        unevaluatedProperties: false
+
+        properties:
+          reg:
+            items:
+              - enum: [1, 2]
+            description: MTIP L2 switch port number
+
+          label:
+            description: Label associated with this port
+
+        required:
+          - reg
+          - label
+          - phy-mode
+          - phy-handle
+
+  mdio:
+    type: object
+    $ref: mdio.yaml#
+    unevaluatedProperties: false
+    description:
+      Specifies the mdio bus in the switch, used as a container for phy nodes.
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+  - interrupts
+  - mdio
+  - ethernet-ports
+
+additionalProperties: false
+
+examples:
+  - |
+    #include<dt-bindings/interrupt-controller/irq.h>
+    switch@800f0000 {
+        compatible = "nxp,imx287-mtip-switch";
+        reg = <0x800f0000 0x20000>;
+        pinctrl-names = "default";
+        pinctrl-0 = <&mac0_pins_a>, <&mac1_pins_a>;
+        phy-supply = <&reg_fec_3v3>;
+        interrupts = <100>, <101>, <102>;
+        clocks = <&clks 57>, <&clks 57>, <&clks 64>, <&clks 35>;
+        clock-names = "ipg", "ahb", "enet_out", "ptp";
+
+        ethernet-ports {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            mtip_port1: port@1 {
+                reg = <1>;
+                label = "lan0";
+                local-mac-address = [ 00 00 00 00 00 00 ];
+                phy-mode = "rmii";
+                phy-handle = <&ethphy0>;
+            };
+
+            mtip_port2: port@2 {
+                reg = <2>;
+                label = "lan1";
+                local-mac-address = [ 00 00 00 00 00 00 ];
+                phy-mode = "rmii";
+                phy-handle = <&ethphy1>;
+            };
+        };
+
+        mdio_sw: mdio {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            reset-gpios = <&gpio2 13 0>;
+            reset-delay-us = <25000>;
+            reset-post-delay-us = <10000>;
+
+            ethphy0: ethernet-phy@0 {
+                reg = <0>;
+            };
+
+            ethphy1: ethernet-phy@1 {
+                reg = <1>;
+            };
+        };
+    };
Signature · 1 line
2.39.5
reviewer
#2 lore raw

Re: [PATCH v3 1/4] dt-bindings: net: Add MTIP L2 switch description

Hi Lukasz,

Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml line 22

Quoted 3 lines · Lukasz Majewski
Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +3 -0
+properties:
+  compatible:
+    const: nxp,imx287-mtip-switch

For consistency, please use "nxp,imx28-mtip-switch" instead.

imx287 is not used anywhere in the kernel.

#3 lore raw

Re: [PATCH v3 1/4] dt-bindings: net: Add MTIP L2 switch description

Hi Fabio,

Quoted 11 lines

Hi Lukasz,

Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml line 22

Quoted 3 lines · Lukasz Majewski
Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +3 -0
+properties:
+  compatible:
+    const: nxp,imx287-mtip-switch  

For consistency, please use "nxp,imx28-mtip-switch" instead.

imx287 is not used anywhere in the kernel.

Ok. Thanks for the info.

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: [email protected]

maintainer
#4 lore raw

Re: [PATCH v3 1/4] dt-bindings: net: Add MTIP L2 switch description

In reply to Lukasz Majewski
Quoted 39 lines · Lukasz Majewski

This patch provides description of the MTIP L2 switch available in some NXP's SOCs - e.g. imx287.

---
Changes for v2:
- Rename the file to match exactly the compatible
(nxp,imx287-mtip-switch)

Changes for v3:
- Remove '-' from const:'nxp,imx287-mtip-switch'
- Use '^port@[12]+$' for port patternProperties
- Drop status = "okay";
- Provide proper indentation for 'example' binding (replace 8 spaces with 4 spaces)
- Remove smsc,disable-energy-detect; property
- Remove interrupt-parent and interrupts properties as not required
- Remove #address-cells and #size-cells from required properties check
- remove description from reg:
- Add $ref: ethernet-switch.yaml#

---
 .../bindings/net/nxp,imx287-mtip-switch.yaml  | 154 ++++++++++++++++++
 1 file changed, 154 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml
Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +8 -0
new file mode 100644
index 000000000000..98eba3665f32
@@ -0,0 +1,154 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/nxp,imx287-mtip-switch.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: NXP SoC Ethernet Switch Controller (L2 MoreThanIP switch)
+

Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml line 18

Quoted 10 lines
Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +10 -0
+maintainers:
+  - Lukasz Majewski <[email protected]>
+
+description:
+  The 2-port switch ethernet subsystem provides ethernet packet (L2)
+  communication and can be configured as an ethernet switch. It provides the
+  reduced media independent interface (RMII), the management data input
+  output (MDIO) for physical layer device (PHY) management.
+
+$ref: ethernet-switch.yaml#

This needs to be: ethernet-switch.yaml#/$defs/ethernet-ports

With that, you can drop much of the below part. More below...

Quoted 37 lines
Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +36 -0
+
+properties:
+  compatible:
+    const: nxp,imx287-mtip-switch
+
+  reg:
+    maxItems: 1
+
+  phy-supply:
+    description:
+      Regulator that powers Ethernet PHYs.
+
+  clocks:
+    items:
+      - description: Register accessing clock
+      - description: Bus access clock
+      - description: Output clock for external device - e.g. PHY source clock
+      - description: IEEE1588 timer clock
+
+  clock-names:
+    items:
+      - const: ipg
+      - const: ahb
+      - const: enet_out
+      - const: ptp
+
+  interrupts:
+    items:
+      - description: Switch interrupt
+      - description: ENET0 interrupt
+      - description: ENET1 interrupt
+
+  pinctrl-names: true
+
 
+  ethernet-ports:
+    type: object

Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml line 64

Quoted 10 lines
Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +10 -0
+    additionalProperties: false
+
+    properties:
+      '#address-cells':
+        const: 1
+      '#size-cells':
+        const: 0
+
+    patternProperties:
+      '^port@[12]+$':

Note that 'ethernet-port' is the preferred node name though 'port' is allowed.

Quoted 10 lines
Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +10 -0
+        type: object
+        description: MTIP L2 switch external ports
+
+        $ref: ethernet-controller.yaml#
+        unevaluatedProperties: false
+
+        properties:
+          reg:
+            items:
+              - enum: [1, 2]

Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml line 84

Quoted 10 lines
Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +10 -0
+            description: MTIP L2 switch port number
+
+          label:
+            description: Label associated with this port
+
+        required:
+          - reg
+          - label
+          - phy-mode
+          - phy-handle

All the above under 'ethernet-ports' can be dropped though you might want to keep 'required' part.

Quoted 73 lines
Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +70 -0
+
+  mdio:
+    type: object
+    $ref: mdio.yaml#
+    unevaluatedProperties: false
+    description:
+      Specifies the mdio bus in the switch, used as a container for phy nodes.
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+  - interrupts
+  - mdio
+  - ethernet-ports
+
+additionalProperties: false
+
+examples:
+  - |
+    #include<dt-bindings/interrupt-controller/irq.h>
+    switch@800f0000 {
+        compatible = "nxp,imx287-mtip-switch";
+        reg = <0x800f0000 0x20000>;
+        pinctrl-names = "default";
+        pinctrl-0 = <&mac0_pins_a>, <&mac1_pins_a>;
+        phy-supply = <&reg_fec_3v3>;
+        interrupts = <100>, <101>, <102>;
+        clocks = <&clks 57>, <&clks 57>, <&clks 64>, <&clks 35>;
+        clock-names = "ipg", "ahb", "enet_out", "ptp";
+
+        ethernet-ports {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            mtip_port1: port@1 {
+                reg = <1>;
+                label = "lan0";
+                local-mac-address = [ 00 00 00 00 00 00 ];
+                phy-mode = "rmii";
+                phy-handle = <&ethphy0>;
+            };
+
+            mtip_port2: port@2 {
+                reg = <2>;
+                label = "lan1";
+                local-mac-address = [ 00 00 00 00 00 00 ];
+                phy-mode = "rmii";
+                phy-handle = <&ethphy1>;
+            };
+        };
+
+        mdio_sw: mdio {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            reset-gpios = <&gpio2 13 0>;
+            reset-delay-us = <25000>;
+            reset-post-delay-us = <10000>;
+
+            ethphy0: ethernet-phy@0 {
+                reg = <0>;
+            };
+
+            ethphy1: ethernet-phy@1 {
+                reg = <1>;
+            };
+        };
+    };
Signature · 1 line
2.39.5
#5 lore raw

Re: [PATCH v3 1/4] dt-bindings: net: Add MTIP L2 switch description

Hi Rob,

Quoted 58 lines · Lukasz Majewski
Quoted 51 lines

This patch provides description of the MTIP L2 switch available in some NXP's SOCs - e.g. imx287.

---
Changes for v2:
- Rename the file to match exactly the compatible
(nxp,imx287-mtip-switch)

Changes for v3:
- Remove '-' from const:'nxp,imx287-mtip-switch'
- Use '^port@[12]+$' for port patternProperties
- Drop status = "okay";
- Provide proper indentation for 'example' binding (replace 8 spaces with 4 spaces)
- Remove smsc,disable-energy-detect; property
- Remove interrupt-parent and interrupts properties as not required
- Remove #address-cells and #size-cells from required properties check
- remove description from reg:
- Add $ref: ethernet-switch.yaml#

---
 .../bindings/net/nxp,imx287-mtip-switch.yaml  | 154
++++++++++++++++++ 1 file changed, 154 insertions(+)
 create mode 100644

Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml

diff --git a/Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml b/Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file mode 100644 index 000000000000..98eba3665f32 --- /dev/null
+++
b/Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml

(quoted diff) +0 -0
@@ -0,0 +1,154 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR

BSD-2-Clause) +%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/nxp,imx287-mtip-switch.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#

Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +8 -0
+
+title: NXP SoC Ethernet Switch Controller (L2 MoreThanIP switch)
+
+maintainers:
+  - Lukasz Majewski <[email protected]>
+
+description:
+  The 2-port switch ethernet subsystem provides ethernet packet

(L2)
+ communication and can be configured as an ethernet switch. It provides the
+ reduced media independent interface (RMII), the management data input

Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml line 18

Quoted 3 lines
Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +3 -0
+  output (MDIO) for physical layer device (PHY) management.
+
+$ref: ethernet-switch.yaml#  

This needs to be: ethernet-switch.yaml#/$defs/ethernet-ports

Quoted 4 lines

With that, you can drop much of the below part. More below...

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+properties:

So it shall be after the "properties:"

$ref: ethernet-switch.yaml#/$defs/ethernet-ports [*]

Quoted 34 lines
Quoted 33 lines
Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +15 -0
+  compatible:
+    const: nxp,imx287-mtip-switch
+
+  reg:
+    maxItems: 1
+
+  phy-supply:
+    description:
+      Regulator that powers Ethernet PHYs.
+
+  clocks:
+    items:
+      - description: Register accessing clock
+      - description: Bus access clock
+      - description: Output clock for external device - e.g. PHY

source clock

Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +17 -0
+      - description: IEEE1588 timer clock
+
+  clock-names:
+    items:
+      - const: ipg
+      - const: ahb
+      - const: enet_out
+      - const: ptp
+
+  interrupts:
+    items:
+      - description: Switch interrupt
+      - description: ENET0 interrupt
+      - description: ENET1 interrupt
+
+  pinctrl-names: true
+  
Quoted 1 line
Quoted 1 line

+ ethernet-ports:

And then this "node" can be removed as it has been referenced above [*]?

(I shall only keep the properties, which are not standard to [*] if any).

Quoted 6 lines
Quoted 6 lines
Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +6 -0
+    type: object
+    additionalProperties: false
+
+    properties:
+      '#address-cells':
+        const: 1
Quoted 8 lines

Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml line 64

Quoted 5 lines
Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +5 -0
+      '#size-cells':
+        const: 0
+
+    patternProperties:
+      '^port@[12]+$':  

Note that 'ethernet-port' is the preferred node name though 'port' is allowed.

Ok. That would be the correct define:

ethernet-ports {
     mtip_port1: ethernet-port@1 {
               reg = <1>;
               label = "lan0";
               local-mac-address = [ 00 00 00 00 00 00 ];
               phy-mode = "rmii";
               phy-handle = <&ethphy0>;
	       };

               mtip_port2: port@2 {
		....
	       };
Quoted 16 lines
Quoted 16 lines
Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +15 -0
+        type: object
+        description: MTIP L2 switch external ports
+
+        $ref: ethernet-controller.yaml#
+        unevaluatedProperties: false
+
+        properties:
+          reg:
+            items:
+              - enum: [1, 2]
+            description: MTIP L2 switch port number
+
+          label:
+            description: Label associated with this port
+
Quoted 8 lines

Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml line 84

Quoted 5 lines
Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +5 -0
+        required:
+          - reg
+          - label
+          - phy-mode
+          - phy-handle  

All the above under 'ethernet-ports' can be dropped though you might want to keep 'required' part.

Ok, I will keep it.

Quoted 66 lines
Quoted 66 lines
Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +7 -0
+
+  mdio:
+    type: object
+    $ref: mdio.yaml#
+    unevaluatedProperties: false
+    description:
+      Specifies the mdio bus in the switch, used as a container

for phy nodes. +

Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +57 -0
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+  - interrupts
+  - mdio
+  - ethernet-ports
+
+additionalProperties: false
+
+examples:
+  - |
+    #include<dt-bindings/interrupt-controller/irq.h>
+    switch@800f0000 {
+        compatible = "nxp,imx287-mtip-switch";
+        reg = <0x800f0000 0x20000>;
+        pinctrl-names = "default";
+        pinctrl-0 = <&mac0_pins_a>, <&mac1_pins_a>;
+        phy-supply = <&reg_fec_3v3>;
+        interrupts = <100>, <101>, <102>;
+        clocks = <&clks 57>, <&clks 57>, <&clks 64>, <&clks 35>;
+        clock-names = "ipg", "ahb", "enet_out", "ptp";
+
+        ethernet-ports {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            mtip_port1: port@1 {
+                reg = <1>;
+                label = "lan0";
+                local-mac-address = [ 00 00 00 00 00 00 ];
+                phy-mode = "rmii";
+                phy-handle = <&ethphy0>;
+            };
+
+            mtip_port2: port@2 {
+                reg = <2>;
+                label = "lan1";
+                local-mac-address = [ 00 00 00 00 00 00 ];
+                phy-mode = "rmii";
+                phy-handle = <&ethphy1>;
+            };
+        };
+
+        mdio_sw: mdio {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            reset-gpios = <&gpio2 13 0>;
+            reset-delay-us = <25000>;
+            reset-post-delay-us = <10000>;
+
+            ethphy0: ethernet-phy@0 {
+                reg = <0>;
+            };
+
Quoted 8 lines
Quoted 8 lines
Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +5 -0
+            ethphy1: ethernet-phy@1 {
+                reg = <1>;
+            };
+        };
+    };
Signature · 1 line
2.39.5

Thanks for the hint.

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: [email protected]

maintainer
#6 lore raw

Re: [PATCH v3 1/4] dt-bindings: net: Add MTIP L2 switch description

Quoted 60 lines · Lukasz Majewski

Hi Rob,

Quoted 58 lines · Lukasz Majewski
Quoted 51 lines

This patch provides description of the MTIP L2 switch available in some NXP's SOCs - e.g. imx287.

---
Changes for v2:
- Rename the file to match exactly the compatible
(nxp,imx287-mtip-switch)

Changes for v3:
- Remove '-' from const:'nxp,imx287-mtip-switch'
- Use '^port@[12]+$' for port patternProperties
- Drop status = "okay";
- Provide proper indentation for 'example' binding (replace 8 spaces with 4 spaces)
- Remove smsc,disable-energy-detect; property
- Remove interrupt-parent and interrupts properties as not required
- Remove #address-cells and #size-cells from required properties check
- remove description from reg:
- Add $ref: ethernet-switch.yaml#

---
 .../bindings/net/nxp,imx287-mtip-switch.yaml  | 154
++++++++++++++++++ 1 file changed, 154 insertions(+)
 create mode 100644

Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml

diff --git a/Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml b/Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file mode 100644 index 000000000000..98eba3665f32 --- /dev/null
+++
b/Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml

(quoted diff) +0 -0
@@ -0,0 +1,154 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR

BSD-2-Clause) +%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/nxp,imx287-mtip-switch.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#

Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +8 -0
+
+title: NXP SoC Ethernet Switch Controller (L2 MoreThanIP switch)
+
+maintainers:
+  - Lukasz Majewski <[email protected]>
+
+description:
+  The 2-port switch ethernet subsystem provides ethernet packet

(L2)
+ communication and can be configured as an ethernet switch. It provides the
+ reduced media independent interface (RMII), the management data input

Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml line 18

Quoted 3 lines
Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +3 -0
+  output (MDIO) for physical layer device (PHY) management.
+
+$ref: ethernet-switch.yaml#  

This needs to be: ethernet-switch.yaml#/$defs/ethernet-ports

Quoted 8 lines
Quoted 4 lines

With that, you can drop much of the below part. More below...

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+properties:

So it shall be after the "properties:"

$ref: ethernet-switch.yaml#/$defs/ethernet-ports [*]

It can stay where it is, just add "/$defs/ethernet-ports"

Quoted 34 lines
Quoted 34 lines
Quoted 33 lines
Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +15 -0
+  compatible:
+    const: nxp,imx287-mtip-switch
+
+  reg:
+    maxItems: 1
+
+  phy-supply:
+    description:
+      Regulator that powers Ethernet PHYs.
+
+  clocks:
+    items:
+      - description: Register accessing clock
+      - description: Bus access clock
+      - description: Output clock for external device - e.g. PHY

source clock

Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +17 -0
+      - description: IEEE1588 timer clock
+
+  clock-names:
+    items:
+      - const: ipg
+      - const: ahb
+      - const: enet_out
+      - const: ptp
+
+  interrupts:
+    items:
+      - description: Switch interrupt
+      - description: ENET0 interrupt
+      - description: ENET1 interrupt
+
+  pinctrl-names: true
+  
Quoted 3 lines
Quoted 1 line
Quoted 1 line

+ ethernet-ports:

And then this "node" can be removed as it has been referenced above [*]?

Well, you have to keep it to have 'required' in the child nodes.

Quoted 21 lines

(I shall only keep the properties, which are not standard to [*] if any).

Quoted 6 lines
Quoted 6 lines
Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +6 -0
+    type: object
+    additionalProperties: false
+
+    properties:
+      '#address-cells':
+        const: 1
Quoted 8 lines

Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml line 64

Quoted 5 lines
Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +5 -0
+      '#size-cells':
+        const: 0
+
+    patternProperties:
+      '^port@[12]+$':  

Note that 'ethernet-port' is the preferred node name though 'port' is allowed.

Ok. That would be the correct define:

Quoted 10 lines
ethernet-ports {
     mtip_port1: ethernet-port@1 {
               reg = <1>;
               label = "lan0";
               local-mac-address = [ 00 00 00 00 00 00 ];
               phy-mode = "rmii";
               phy-handle = <&ethphy0>;
	       };

               mtip_port2: port@2 {

And here...

Quoted 28 lines
		....
	       };
Quoted 16 lines
Quoted 16 lines
Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +15 -0
+        type: object
+        description: MTIP L2 switch external ports
+
+        $ref: ethernet-controller.yaml#
+        unevaluatedProperties: false
+
+        properties:
+          reg:
+            items:
+              - enum: [1, 2]
+            description: MTIP L2 switch port number
+
+          label:
+            description: Label associated with this port
+
Quoted 8 lines

Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml line 84

Quoted 5 lines
Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +5 -0
+        required:
+          - reg
+          - label
+          - phy-mode
+          - phy-handle  

All the above under 'ethernet-ports' can be dropped though you might want to keep 'required' part.

Quoted 1 line

Ok, I will keep it.

So I think you just want this:

ethernet-ports:
type: object
additionalProperties: true # Check if you need this

patternProperties:
'^ethernet-port@[12]$':
required:
- label
- phy-mode
- phy-handle

Rob

#7 lore raw

Re: [PATCH v3 1/4] dt-bindings: net: Add MTIP L2 switch description

Quoted 185 lines · On Tue, 1 Apr 2025 18:03:46 -0500 Rob Herring <[email protected]> wrote:
Quoted 61 lines · Lukasz Majewski

Hi Rob,

Quoted 59 lines · Lukasz Majewski
Quoted 52 lines

This patch provides description of the MTIP L2 switch available in some NXP's SOCs - e.g. imx287.

---
Changes for v2:
- Rename the file to match exactly the compatible
(nxp,imx287-mtip-switch)

Changes for v3:
- Remove '-' from const:'nxp,imx287-mtip-switch'
- Use '^port@[12]+$' for port patternProperties
- Drop status = "okay";
- Provide proper indentation for 'example' binding (replace 8 spaces with 4 spaces)
- Remove smsc,disable-energy-detect; property
- Remove interrupt-parent and interrupts properties as not required
- Remove #address-cells and #size-cells from required properties check
- remove description from reg:
- Add $ref: ethernet-switch.yaml#

---
 .../bindings/net/nxp,imx287-mtip-switch.yaml  | 154
++++++++++++++++++ 1 file changed, 154 insertions(+)
 create mode 100644

Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml

diff --git a/Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml b/Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file mode 100644 index 000000000000..98eba3665f32 --- /dev/null +++ b/Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml

(quoted diff) +0 -0
@@ -0,0 +1,154 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR

BSD-2-Clause) +%YAML 1.2
+---
+$id:
http://devicetree.org/schemas/net/nxp,imx287-mtip-switch.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: NXP SoC Ethernet Switch Controller (L2 MoreThanIP switch) +

Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +5 -0
+maintainers:
+  - Lukasz Majewski <[email protected]>
+
+description:
+  The 2-port switch ethernet subsystem provides ethernet packet

(L2)
+ communication and can be configured as an ethernet switch. It provides the
+ reduced media independent interface (RMII), the management data input

Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml line 18

Quoted 3 lines
Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +3 -0
+  output (MDIO) for physical layer device (PHY) management.
+
+$ref: ethernet-switch.yaml#    

This needs to be: ethernet-switch.yaml#/$defs/ethernet-ports

Quoted 8 lines
Quoted 4 lines

With that, you can drop much of the below part. More below...

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+properties:  

So it shall be after the "properties:"

$ref: ethernet-switch.yaml#/$defs/ethernet-ports [*]

It can stay where it is, just add "/$defs/ethernet-ports"

Quoted 34 lines
Quoted 34 lines
Quoted 33 lines
Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +15 -0
+  compatible:
+    const: nxp,imx287-mtip-switch
+
+  reg:
+    maxItems: 1
+
+  phy-supply:
+    description:
+      Regulator that powers Ethernet PHYs.
+
+  clocks:
+    items:
+      - description: Register accessing clock
+      - description: Bus access clock
+      - description: Output clock for external device - e.g.

PHY source clock

Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +17 -0
+      - description: IEEE1588 timer clock
+
+  clock-names:
+    items:
+      - const: ipg
+      - const: ahb
+      - const: enet_out
+      - const: ptp
+
+  interrupts:
+    items:
+      - description: Switch interrupt
+      - description: ENET0 interrupt
+      - description: ENET1 interrupt
+
+  pinctrl-names: true
+    
Quoted 4 lines
Quoted 1 line
Quoted 1 line

+ ethernet-ports:

And then this "node" can be removed as it has been referenced above [*]?

Well, you have to keep it to have 'required' in the child nodes.

Quoted 21 lines

(I shall only keep the properties, which are not standard to [*] if any).

Quoted 6 lines
Quoted 6 lines
Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +6 -0
+    type: object
+    additionalProperties: false
+
+    properties:
+      '#address-cells':
+        const: 1
Quoted 8 lines

Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml line 64

Quoted 5 lines
Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +5 -0
+      '#size-cells':
+        const: 0
+
+    patternProperties:
+      '^port@[12]+$':    

Note that 'ethernet-port' is the preferred node name though 'port' is allowed.

Ok. That would be the correct define:

Quoted 10 lines
ethernet-ports {
     mtip_port1: ethernet-port@1 {
               reg = <1>;
               label = "lan0";
               local-mac-address = [ 00 00 00 00 00 00 ];
               phy-mode = "rmii";
               phy-handle = <&ethphy0>;
	       };

               mtip_port2: port@2 {  

And here...

Quoted 28 lines
		....
	       };
Quoted 16 lines
Quoted 16 lines
Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +15 -0
+        type: object
+        description: MTIP L2 switch external ports
+
+        $ref: ethernet-controller.yaml#
+        unevaluatedProperties: false
+
+        properties:
+          reg:
+            items:
+              - enum: [1, 2]
+            description: MTIP L2 switch port number
+
+          label:
+            description: Label associated with this port
+
Quoted 8 lines

Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml line 84

Quoted 5 lines
Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml new file +5 -0
+        required:
+          - reg
+          - label
+          - phy-mode
+          - phy-handle    

All the above under 'ethernet-ports' can be dropped though you might want to keep 'required' part.

Quoted 1 line

Ok, I will keep it.

So I think you just want this:

ethernet-ports:
type: object
additionalProperties: true # Check if you need this

Quoted 7 lines

patternProperties:
'^ethernet-port@[12]$':
required:
- label
- phy-mode
- phy-handle

I had to add:

$ref: ethernet-switch.yaml#/$defs/ethernet-ports
patternProperties:
"^(ethernet-)?ports$":
type: object
additionalProperties: true

after the
description:

to avoid issues when checking DT schema.

Simple adding

patternProperties:
'^ethernet-port@[12]$':
required:
- label
- phy-mode
- phy-handle

Causes more errors.

Quoted 1 line

Rob

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: [email protected]

#8 lore raw

PATCH v3 2/4 ARM: dts: nxp: mxs: Adjust the imx28.dtsi L2 switch description

In reply to Lukasz Majewski

The current range of 'reg' property is too small to allow full control of the L2 switch on imx287.

As this IP block also uses ENET-MAC blocks for its operation, the address range for it must be included as well.

Moreover, some SoC common properties (like compatible, clocks, interrupts numbers) have been moved to this node.

---
Changes for v2:
- adding extra properties (like compatible, clocks, interupts)

Changes for v3:
- None

---
 arch/arm/boot/dts/nxp/mxs/imx28.dtsi | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
arch/arm/boot/dts/nxp/mxs/imx28.dtsi +6 -2
index bbea8b77386f..4117a5003b36 100644
@@ -1321,8 +1321,12 @@ mac1: ethernet@800f4000 {
 			status = "disabled";
 		};
 
-		eth_switch: switch@800f8000 {
-			reg = <0x800f8000 0x8000>;
+		eth_switch: switch@800f0000 {
+			compatible = "nxp,imx287-mtip-switch";
+			reg = <0x800f0000 0x20000>;
+			interrupts = <100>, <101>, <102>;
+			clocks = <&clks 57>, <&clks 57>, <&clks 64>, <&clks 35>;
+			clock-names = "ipg", "ahb", "enet_out", "ptp";
 			status = "disabled";
 		};
 	};
Signature · 1 line
2.39.5
Reviewed-by on v3 2/4
#9 lore raw

Re: [PATCH v3 2/4] ARM: dts: nxp: mxs: Adjust the imx28.dtsi L2 switch description

Quoted 10 lines · Lukasz Majewski

The current range of 'reg' property is too small to allow full control of the L2 switch on imx287.

As this IP block also uses ENET-MAC blocks for its operation, the address range for it must be included as well.

Moreover, some SoC common properties (like compatible, clocks, interrupts numbers) have been moved to this node.

Assuming it passed the DT checking:

Andrew

#10 lore raw

PATCH v3 3/4 ARM: dts: nxp: mxs: Adjust XEA board's DTS to support L2 switch

In reply to Lukasz Majewski

The description is similar to the one used with the new CPSW driver.

---
Changes for v2:
- Remove properties which are common for the imx28(7) SoC
- Use mdio properties to perform L2 switch reset (avoid using deprecated properties)

Changes for v3:
- Replace IRQ_TYPE_EDGE_FALLING with IRQ_TYPE_LEVEL_LOW
- Update comment regarding PHY interrupts s/AND/OR/g

---
 arch/arm/boot/dts/nxp/mxs/imx28-xea.dts | 54 +++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
arch/arm/boot/dts/nxp/mxs/imx28-xea.dts +54 -0
index 6c5e6856648a..8642578fddf3 100644
@@ -5,6 +5,7 @@
  */
 
 /dts-v1/;
+#include<dt-bindings/interrupt-controller/irq.h>
 #include "imx28-lwe.dtsi"
 
 / {
@@ -90,6 +91,59 @@ &reg_usb_5v {
 	gpio = <&gpio0 2 0>;
 };
 
+&eth_switch {
+	pinctrl-names = "default";
+	pinctrl-0 = <&mac0_pins_a>, <&mac1_pins_a>;
+	phy-supply = <&reg_fec_3v3>;
+	status = "okay";
+
+	ethernet-ports {
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		mtip_port1: port@1 {
+			reg = <1>;
+			label = "lan0";
+			local-mac-address = [ 00 00 00 00 00 00 ];
+			phy-mode = "rmii";
+			phy-handle = <&ethphy0>;
+		};
+
+		mtip_port2: port@2 {
+			reg = <2>;
+			label = "lan1";
+			local-mac-address = [ 00 00 00 00 00 00 ];
+			phy-mode = "rmii";
+			phy-handle = <&ethphy1>;
+		};
+	};
+
+	mdio_sw: mdio {
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		reset-gpios = <&gpio3 21 0>;
+		reset-delay-us = <25000>;
+		reset-post-delay-us = <10000>;
+
+		ethphy0: ethernet-phy@0 {
+			reg = <0>;
+			smsc,disable-energy-detect;
+			/* Both PHYs (i.e. 0,1) have the same, single GPIO, */
+			/* line to handle both, their interrupts (OR'ed) */
+			interrupt-parent = <&gpio4>;
+			interrupts = <13 IRQ_TYPE_LEVEL_LOW>;
+		};
+
+		ethphy1: ethernet-phy@1 {
+			reg = <1>;
+			smsc,disable-energy-detect;
+			interrupt-parent = <&gpio4>;
+			interrupts = <13 IRQ_TYPE_LEVEL_LOW>;
+		};
+	};
+};
+
 &spi2_pins_a {
 	fsl,pinmux-ids = <
 		MX28_PAD_SSP2_SCK__SSP2_SCK
Signature · 1 line
2.39.5
#11 lore raw

Re: [PATCH v3 3/4] ARM: dts: nxp: mxs: Adjust XEA board's DTS to support L2 switch

Hi,

Am 31.03.25 um 12:31 schrieb Lukasz Majewski:

Quoted 54 lines

The description is similar to the one used with the new CPSW driver.

---
Changes for v2:
- Remove properties which are common for the imx28(7) SoC
- Use mdio properties to perform L2 switch reset (avoid using deprecated properties)

Changes for v3:
- Replace IRQ_TYPE_EDGE_FALLING with IRQ_TYPE_LEVEL_LOW
- Update comment regarding PHY interrupts s/AND/OR/g

---
  arch/arm/boot/dts/nxp/mxs/imx28-xea.dts | 54 +++++++++++++++++++++++++
  1 file changed, 54 insertions(+)
arch/arm/boot/dts/nxp/mxs/imx28-xea.dts +23 -0
index 6c5e6856648a..8642578fddf3 100644
@@ -5,6 +5,7 @@
   */
 
  /dts-v1/;
+#include<dt-bindings/interrupt-controller/irq.h>
  #include "imx28-lwe.dtsi"
 
  / {
@@ -90,6 +91,59 @@ &reg_usb_5v {
  	gpio = <&gpio0 2 0>;
  };
 
+&eth_switch {
+	pinctrl-names = "default";
+	pinctrl-0 = <&mac0_pins_a>, <&mac1_pins_a>;
+	phy-supply = <&reg_fec_3v3>;
+	status = "okay";
+
+	ethernet-ports {
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		mtip_port1: port@1 {
+			reg = <1>;
+			label = "lan0";
+			local-mac-address = [ 00 00 00 00 00 00 ];
+			phy-mode = "rmii";
+			phy-handle = <&ethphy0>;
+		};
+
+		mtip_port2: port@2 {
+			reg = <2>;
+			label = "lan1";
+			local-mac-address = [ 00 00 00 00 00 00 ];

arch/arm/boot/dts/nxp/mxs/imx28-xea.dts &reg_usb_5v { · line 125

Quoted 10 lines
arch/arm/boot/dts/nxp/mxs/imx28-xea.dts +10 -0
+			phy-mode = "rmii";
+			phy-handle = <&ethphy1>;
+		};
+	};
+
+	mdio_sw: mdio {
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		reset-gpios = <&gpio3 21 0>;

i'm a huge fan of the polarity defines, which makes it easier to understand.

Btw since you introduced the compatible in the DTS of a i.MX28 board, it would be nice to also enable the driver in mxs_defconfig.

Regards

Quoted 24 lines
arch/arm/boot/dts/nxp/mxs/imx28-xea.dts +21 -0
+		reset-delay-us = <25000>;
+		reset-post-delay-us = <10000>;
+
+		ethphy0: ethernet-phy@0 {
+			reg = <0>;
+			smsc,disable-energy-detect;
+			/* Both PHYs (i.e. 0,1) have the same, single GPIO, */
+			/* line to handle both, their interrupts (OR'ed) */
+			interrupt-parent = <&gpio4>;
+			interrupts = <13 IRQ_TYPE_LEVEL_LOW>;
+		};
+
+		ethphy1: ethernet-phy@1 {
+			reg = <1>;
+			smsc,disable-energy-detect;
+			interrupt-parent = <&gpio4>;
+			interrupts = <13 IRQ_TYPE_LEVEL_LOW>;
+		};
+	};
+};
+
  &spi2_pins_a {
  	fsl,pinmux-ids = <
  		MX28_PAD_SSP2_SCK__SSP2_SCK
#12 lore raw

Re: [PATCH v3 3/4] ARM: dts: nxp: mxs: Adjust XEA board's DTS to support L2 switch

Hi Stefan,

Quoted 61 lines

Hi,

Am 31.03.25 um 12:31 schrieb Lukasz Majewski:

Quoted 58 lines

The description is similar to the one used with the new CPSW driver.

---
Changes for v2:
- Remove properties which are common for the imx28(7) SoC
- Use mdio properties to perform L2 switch reset (avoid using deprecated properties)

Changes for v3:
- Replace IRQ_TYPE_EDGE_FALLING with IRQ_TYPE_LEVEL_LOW
- Update comment regarding PHY interrupts s/AND/OR/g

---
  arch/arm/boot/dts/nxp/mxs/imx28-xea.dts | 54

+++++++++++++++++++++++++ 1 file changed, 54 insertions(+)

(quoted diff) +0 -0

b/arch/arm/boot/dts/nxp/mxs/imx28-xea.dts index 6c5e6856648a..8642578fddf3 100644 --- a/arch/arm/boot/dts/nxp/mxs/imx28-xea.dts +++ b/arch/arm/boot/dts/nxp/mxs/imx28-xea.dts @@ -5,6 +5,7 @@
*/

/dts-v1/;

arch/arm/boot/dts/nxp/mxs/imx28-xea.dts +27 -0
+#include<dt-bindings/interrupt-controller/irq.h>
  #include "imx28-lwe.dtsi"
 
  / {
@@ -90,6 +91,59 @@ &reg_usb_5v {
  	gpio = <&gpio0 2 0>;
  };
 
+&eth_switch {
+	pinctrl-names = "default";
+	pinctrl-0 = <&mac0_pins_a>, <&mac1_pins_a>;
+	phy-supply = <&reg_fec_3v3>;
+	status = "okay";
+
+	ethernet-ports {
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		mtip_port1: port@1 {
+			reg = <1>;
+			label = "lan0";
+			local-mac-address = [ 00 00 00 00 00 00 ];
+			phy-mode = "rmii";
+			phy-handle = <&ethphy0>;
+		};
+
+		mtip_port2: port@2 {
+			reg = <2>;
+			label = "lan1";
+			local-mac-address = [ 00 00 00 00 00 00 ];
+			phy-mode = "rmii";
+			phy-handle = <&ethphy1>;
+		};
+	};
Quoted 9 lines

arch/arm/boot/dts/nxp/mxs/imx28-xea.dts &reg_usb_5v { · line 125

Quoted 6 lines
arch/arm/boot/dts/nxp/mxs/imx28-xea.dts +6 -0
+
+	mdio_sw: mdio {
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		reset-gpios = <&gpio3 21 0>;  

i'm a huge fan of the polarity defines, which makes it easier to understand.

Ok.

Quoted 2 lines

Btw since you introduced the compatible in the DTS of a i.MX28 board, it would be nice to also enable the driver in mxs_defconfig.

Yes, thanks for the tip.

Quoted 20 lines

Regards

Quoted 18 lines
arch/arm/boot/dts/nxp/mxs/imx28-xea.dts +7 -0
+		reset-delay-us = <25000>;
+		reset-post-delay-us = <10000>;
+
+		ethphy0: ethernet-phy@0 {
+			reg = <0>;
+			smsc,disable-energy-detect;
+			/* Both PHYs (i.e. 0,1) have the same,

single GPIO, */

(quoted diff) +1 -0
+			/* line to handle both, their interrupts

(OR'ed) */

arch/arm/boot/dts/nxp/mxs/imx28-xea.dts +8 -0
+			interrupt-parent = <&gpio4>;
+			interrupts = <13 IRQ_TYPE_LEVEL_LOW>;
+		};
+
+		ethphy1: ethernet-phy@1 {
+			reg = <1>;
+			smsc,disable-energy-detect;
+			interrupt-parent = <&gpio4>;
Quoted 9 lines

arch/arm/boot/dts/nxp/mxs/imx28-xea.dts &reg_usb_5v { · line 149

Quoted 8 lines
arch/arm/boot/dts/nxp/mxs/imx28-xea.dts +5 -0
+			interrupts = <13 IRQ_TYPE_LEVEL_LOW>;
+		};
+	};
+};
+
  &spi2_pins_a {
  	fsl,pinmux-ids = <
  		MX28_PAD_SSP2_SCK__SSP2_SCK  

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: [email protected]

#13 lore raw

PATCH v3 4/4 net: mtip: The L2 switch driver for imx287

In reply to Lukasz Majewski

This patch series provides support for More Than IP L2 switch embedded in the imx287 SoC.

This is a two port switch (placed between uDMA[01] and MAC-NET[01]), which can be used for offloading the network traffic.

It can be used interchangeably with current FEC driver - to be more
specific: one can use either of it, depending on the requirements.

The biggest difference is the usage of DMA - when FEC is used, separate DMAs are available for each ENET-MAC block.
However, with switch enabled - only the DMA0 is used to send/receive data to/form switch (and then switch sends them to respecitive ports).

---

Changes for v2:

- Remove not needed comments
- Restore udelay(10) for switch reset (such delay is explicitly specifed in the documentation
- Add COMPILE_TEST
- replace pr_* with dev_*
- Use for_each_available_child_of_node_scoped()
- Use devm_* function for memory allocation
- Remove printing information about the HW and SW revision of the driver
- Use devm_regulator_get_optional()
- Change compatible prefix from 'fsl' to more up to date 'nxp'
- Remove .owner = THIS_MODULE
- Use devm_platform_ioremap_resource(pdev, 0);
- Use devm_request_irq()
- Use devm_regulator_get_enable_optional()
- Replace clk_prepare_enable() and devm_clk_get() with single call to devm_clk_get_optional_enabled()
- Cleanup error patch when function calls in probe fail
- Refactor the mtip_reset_phy() to serve as mdio bus reset callback
- Add myself as the MTIP L2 switch maintainer (squashed the separated commit)
- More descriptive help paragraphs (> 4 lines)

Changes for v3:
- Remove 'bridge_offloading' module parameter (to bridge ports just after probe)
- Remove forward references
- Fix reverse christmas tree formatting in functions
- Convert eligible comments to kernel doc format
- Remove extra MAC address validation check at esw_mac_addr_static()
- Remove mtip_print_link_status() and replace it with phy_print_status()
- Avoid changing phy device state in the driver (instead use functions exported by the phy API)
- Do not print extra information regarding PHY (which is printed by phylib) - e.g. net lan0: lan0: MTIP eth L2 switch 1e:ce:a5:0b:4c:12
- Remove VERSION from the driver - now we rely on the SHA1 in Linux mainline tree
- Remove zeroing of the net device private area (shall be already done during allocation)
- Refactor the code to remove mtip_ndev_setup()
- Use -ENOMEM instead of -1 return code when allocation fails
- Replace dev_info() with dev_dbg() to reduce number of information print on normal operation
- Return ret instead of 0 from mtip_ndev_init()
- Remove fep->mii_timeout flag from the driver
- Remove not used stop_gpr_* fields in mtip_devinfo struct
- Remove platform_device_id description for mtipl2sw driver
- Add MODULE_DEVICE_TABLE() for mtip_of_match
- Remove MODULE_ALIAS()

---
 MAINTAINERS                                   |    7 +
 drivers/net/ethernet/freescale/Kconfig        |    1 +
 drivers/net/ethernet/freescale/Makefile       |    1 +
 drivers/net/ethernet/freescale/mtipsw/Kconfig |   13 +
 .../net/ethernet/freescale/mtipsw/Makefile    |    3 +
 .../net/ethernet/freescale/mtipsw/mtipl2sw.c  | 1964 +++++++++++++++++
 .../net/ethernet/freescale/mtipsw/mtipl2sw.h  |  780 +++++++
 .../ethernet/freescale/mtipsw/mtipl2sw_br.c   |  113 +
 .../ethernet/freescale/mtipsw/mtipl2sw_mgnt.c |  449 ++++
 9 files changed, 3331 insertions(+)
 create mode 100644 drivers/net/ethernet/freescale/mtipsw/Kconfig
 create mode 100644 drivers/net/ethernet/freescale/mtipsw/Makefile
 create mode 100644 drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c
 create mode 100644 drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h
 create mode 100644 drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c
 create mode 100644 drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c
MAINTAINERS +7 -0
index 1cd25139cc58..d135076bde68 100644
@@ -9305,6 +9305,13 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/i2c/i2c-mpc.yaml
 F:	drivers/i2c/busses/i2c-mpc.c
 
+FREESCALE MTIP ETHERNET SWITCH DRIVER
+M:	Lukasz Majewski <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/net/nxp,imx287-mtip-switch.yaml
+F:	drivers/net/ethernet/freescale/mtipsw/*
+
 FREESCALE QORIQ DPAA ETHERNET DRIVER
 M:	Madalin Bucur <[email protected]>
 L:	[email protected]
drivers/net/ethernet/freescale/Kconfig +1 -0
index a2d7300925a8..056a11c3a74e 100644
@@ -60,6 +60,7 @@ config FEC_MPC52xx_MDIO
 
 source "drivers/net/ethernet/freescale/fs_enet/Kconfig"
 source "drivers/net/ethernet/freescale/fman/Kconfig"
+source "drivers/net/ethernet/freescale/mtipsw/Kconfig"
 
 config FSL_PQ_MDIO
 	tristate "Freescale PQ MDIO"
drivers/net/ethernet/freescale/Makefile +1 -0
index de7b31842233..0e6cacb0948a 100644
@@ -25,3 +25,4 @@ obj-$(CONFIG_FSL_DPAA_ETH) += dpaa/
 obj-$(CONFIG_FSL_DPAA2_ETH) += dpaa2/
 
 obj-y += enetc/
+obj-y += mtipsw/
drivers/net/ethernet/freescale/mtipsw/Kconfig new file +13 -0
new file mode 100644
index 000000000000..450ff734a321
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0-only
+config FEC_MTIP_L2SW
+	tristate "MoreThanIP L2 switch support to FEC driver"
+	depends on OF
+	depends on NET_SWITCHDEV
+	depends on BRIDGE
+	depends on ARCH_MXS || ARCH_MXC || COMPILE_TEST
+	help
+	  This enables support for the MoreThan IP L2 switch on i.MX
+	  SoCs (e.g. iMX28, vf610). It offloads bridging to this IP block's
+	  hardware and allows switch management with standard Linux tools.
+	  This switch driver can be used interchangeable with the already
+	  available FEC driver, depending on the use case's requirments.
drivers/net/ethernet/freescale/mtipsw/Makefile new file +3 -0
new file mode 100644
index 000000000000..4d69db2226a6
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-$(CONFIG_FEC_MTIP_L2SW) += mtipl2sw.o mtipl2sw_mgnt.o mtipl2sw_br.o
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +1964 -0

1,964 lines not on this page · raw message

drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +780 -0

780 lines not on this page · raw message

drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +113 -0

113 lines not on this page · raw message

drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +449 -0

103 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.39.5

Part of the diff is not shown here. View the raw message.

#14 lore raw

Re: [PATCH v3 4/4] net: mtip: The L2 switch driver for imx287

Quoted 7 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +7 -0
+static void read_atable(struct switch_enet_private *fep, int index,
+			unsigned long *read_lo, unsigned long *read_hi)
+{
+	unsigned long atable_base = (unsigned long)fep->hwentry;
+
+	*read_lo = readl((const void *)atable_base + (index << 3));
+	*read_hi = readl((const void *)atable_base + (index << 3) + 4);

drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 206

Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10 -0
+}
+
+static void write_atable(struct switch_enet_private *fep, int index,
+			 unsigned long write_lo, unsigned long write_hi)
+{
+	unsigned long atable_base = (unsigned long)fep->hwentry;
+
+	writel(write_lo, (void *)atable_base + (index << 3));
+	writel(write_hi, (void *)atable_base + (index << 3) + 4);
+}

It would be nice to have the mtip_ prefix on all functions.

drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1461

Quoted 13 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +13 -0
+static int mtip_open(struct net_device *dev)
+{
+	struct mtip_ndev_priv *priv = netdev_priv(dev);
+	struct switch_enet_private *fep = priv->fep;
+	int ret, port_idx = priv->portnum - 1;
+
+	if (fep->usage_count == 0) {
+		clk_enable(fep->clk_ipg);
+		netif_napi_add(dev, &fep->napi, mtip_rx_napi);
+
+		ret = mtip_alloc_buffers(dev);
+		if (ret)
+			return ret;

nitpick: You might want to turn the clock off before returning the error.

drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1472

Quoted 11 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +11 -0
+	}
+
+	fep->link[port_idx] = 0;
+
+	/* Probe and connect to PHY when open the interface, if already
+	 * NOT done in the switch driver probe (or when the device is
+	 * re-opened).
+	 */
+	ret = mtip_mii_probe(dev);
+	if (ret) {
+		mtip_free_buffers(dev);

I've not checked. Does this do the opposite of netif_napi_add()?

drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1534

Quoted 6 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +6 -0
+static void mtip_set_multicast_list(struct net_device *dev)
+{
+	unsigned int i, bit, data, crc;
+
+	if (dev->flags & IFF_PROMISC) {
+		dev_info(&dev->dev, "%s: IFF_PROMISC\n", __func__);

You can save one level of indentation with a return here.

drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1537

Quoted 3 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +3 -0
+	} else {
+		if (dev->flags & IFF_ALLMULTI) {
+			dev_info(&dev->dev, "%s: IFF_ALLMULTI\n", __func__);

and other level here.

drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1546

Quoted 9 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +9 -0
+		} else {
+			struct netdev_hw_addr *ha;
+			u_char *addrs;
+
+			netdev_for_each_mc_addr(ha, dev) {
+				addrs = ha->addr;
+				/* Only support group multicast for now */
+				if (!(*addrs & 1))
+					continue;

You could pull there CRC caluclation out into a helper. You might also want to search the tree and see if it exists somewhere else.

drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1551

Quoted 5 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +5 -0
+
+				/* calculate crc32 value of mac address */
+				crc = 0xffffffff;
+
+				for (i = 0; i < 6; i++) {

Is 6 the lengh of a MAC address? There is a #define for that.

Quoted 22 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +21 -0
+					data = addrs[i];
+					for (bit = 0; bit < 8;
+					     bit++, data >>= 1) {
+						crc = (crc >> 1) ^
+						(((crc ^ data) & 1) ?
+						CRC32_POLY : 0);
+					}
+				}
+			}
+		}
+	}
+}
+
 
+struct switch_enet_private *mtip_netdev_get_priv(const struct net_device *ndev)
+{
+	if (ndev->netdev_ops == &mtip_netdev_ops)
+		return netdev_priv(ndev);
+
+	return NULL;
+}
+

drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1624

Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +9 -0
 
+static int __init mtip_switch_dma_init(struct switch_enet_private *fep)
+{
+	struct cbd_t *bdp, *cbd_base;
+	int ret, i;
+
+	/* Check mask of the streaming and coherent API */
+	ret = dma_set_mask_and_coherent(&fep->pdev->dev, DMA_BIT_MASK(32));
+	if (ret < 0) {
+		dev_warn(&fep->pdev->dev, "No suitable DMA available\n");

Can you recover from this? Or should it be dev_err()?

More later...

Andrew

#15 lore raw

Re: [PATCH v3 4/4] net: mtip: The L2 switch driver for imx287

Hi Andrew,

Quoted 12 lines
Quoted 12 lines
(quoted diff) +2 -0
+static void read_atable(struct switch_enet_private *fep, int index,
+			unsigned long *read_lo, unsigned long

*read_hi) +{

drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +7 -0
+	unsigned long atable_base = (unsigned long)fep->hwentry;
+
+	*read_lo = readl((const void *)atable_base + (index << 3));
+	*read_hi = readl((const void *)atable_base + (index << 3)
+ 4); +}
+
+static void write_atable(struct switch_enet_private *fep, int

index,

(quoted diff) +1 -0
+			 unsigned long write_lo, unsigned long
Quoted 8 lines

drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 206

Quoted 6 lines

write_hi) +{

drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +5 -0
+	unsigned long atable_base = (unsigned long)fep->hwentry;
+
+	writel(write_lo, (void *)atable_base + (index << 3));
+	writel(write_hi, (void *)atable_base + (index << 3) + 4);
+}  

It would be nice to have the mtip_ prefix on all functions.

Ok.

Quoted 17 lines
Quoted 4 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +3 -0
+static int mtip_open(struct net_device *dev)
+{
+	struct mtip_ndev_priv *priv = netdev_priv(dev);

drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1461

Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10 -0
+	struct switch_enet_private *fep = priv->fep;
+	int ret, port_idx = priv->portnum - 1;
+
+	if (fep->usage_count == 0) {
+		clk_enable(fep->clk_ipg);
+		netif_napi_add(dev, &fep->napi, mtip_rx_napi);
+
+		ret = mtip_alloc_buffers(dev);
+		if (ret)
+			return ret;  

nitpick: You might want to turn the clock off before returning the error.

Ok.

Quoted 16 lines
Quoted 9 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +5 -0
+	}
+
+	fep->link[port_idx] = 0;
+
+	/* Probe and connect to PHY when open the interface, if

already

(quoted diff) +1 -0
+	 * NOT done in the switch driver probe (or when the device

is

drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1472

Quoted 5 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +5 -0
+	 * re-opened).
+	 */
+	ret = mtip_mii_probe(dev);
+	if (ret) {
+		mtip_free_buffers(dev);  

I've not checked. Does this do the opposite of netif_napi_add()?

No, the netif_napi_add() is required here as well.

Quoted 10 lines
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +6 -0
+static void mtip_set_multicast_list(struct net_device *dev)
+{
+	unsigned int i, bit, data, crc;
+
+	if (dev->flags & IFF_PROMISC) {
+		dev_info(&dev->dev, "%s: IFF_PROMISC\n",

__func__);

You can save one level of indentation with a return here.

Ok.

Quoted 7 lines
Quoted 5 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +3 -0
+	} else {
+		if (dev->flags & IFF_ALLMULTI) {
+			dev_info(&dev->dev, "%s: IFF_ALLMULTI\n",

__func__);

and other level here.

Ok.

Quoted 15 lines

drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1546

Quoted 11 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +7 -0
+		} else {
+			struct netdev_hw_addr *ha;
+			u_char *addrs;
+
+			netdev_for_each_mc_addr(ha, dev) {
+				addrs = ha->addr;
+				/* Only support group multicast

for now */

drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +2 -0
+				if (!(*addrs & 1))
+					continue;  

You could pull there CRC caluclation out into a helper. You might also want to search the tree and see if it exists somewhere else.

The ether_crc_le(ndev->addr_len,·ha->addr); could be the replacement.

However, when I look on the code and compare it with fec_main.c's set_multicast_list() - it looks like a dead code.

The calculated hash is not used at all (in fec_main.c it is written to some registers).

I've refactored the code to do similar things, but taking into account already set switch setup (promisc must be enabled from the outset).

Quoted 8 lines

drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1551

Quoted 6 lines
(quoted diff) +2 -0
+
+				/* calculate crc32 value of mac

address */

drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +3 -0
+				crc = 0xffffffff;
+
+				for (i = 0; i < 6; i++) {  

Is 6 the lengh of a MAC address? There is a #define for that.

This is not needed and can be replaced with already present function.

Quoted 25 lines
Quoted 24 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +5 -0
+					data = addrs[i];
+					for (bit = 0; bit < 8;
+					     bit++, data >>= 1) {
+						crc = (crc >> 1) ^
+						(((crc ^ data) &

1) ?

drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +9 -0
+						CRC32_POLY : 0);
+					}
+				}
+			}
+		}
+	}
+}
+  
 
+struct switch_enet_private *mtip_netdev_get_priv(const struct

net_device *ndev) +{

drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +6 -0
+	if (ndev->netdev_ops == &mtip_netdev_ops)
+		return netdev_priv(ndev);
+
+	return NULL;
+}
+  
Quoted 14 lines
Quoted 11 lines

+static int __init mtip_switch_dma_init(struct switch_enet_private *fep) +{

drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +5 -0
+	struct cbd_t *bdp, *cbd_base;
+	int ret, i;
+
+	/* Check mask of the streaming and coherent API */
+	ret = dma_set_mask_and_coherent(&fep->pdev->dev,

DMA_BIT_MASK(32));

(quoted diff) +2 -0
+	if (ret < 0) {
+		dev_warn(&fep->pdev->dev, "No suitable DMA

available\n");

Can you recover from this? Or should it be dev_err()?

It was my mistake - of course there shall be dev_err().

Quoted 3 lines

More later...

Andrew

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: [email protected]

#16 lore raw

Re: [PATCH v3 4/4] net: mtip: The L2 switch driver for imx287

In reply to Lukasz Majewski
Quoted 5 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +5 -0
+struct switch_enet_private *mtip_netdev_get_priv(const struct net_device *ndev)
+{
+	if (ndev->netdev_ops == &mtip_netdev_ops)
+		return netdev_priv(ndev);
+

drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1626

Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +9 -0
+	return NULL;
+}
 
+static bool mtip_port_dev_check(const struct net_device *ndev)
+{
+	if (!mtip_netdev_get_priv(ndev))
+		return false;
+
+	return true;
+}

This appears to be the only use of mtip_netdev_get_priv(). It does not care what priv actually is. In my previous review i said i think you can simply this. I still think that is true.

Andrew

#17 lore raw

Re: [PATCH v3 4/4] net: mtip: The L2 switch driver for imx287

In reply to Lukasz Majewski
Quoted 6 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +6 -0
+struct switch_enet_private *mtip_netdev_get_priv(const struct net_device *ndev)
+{
+	if (ndev->netdev_ops == &mtip_netdev_ops)
+		return netdev_priv(ndev);
+
+	return NULL;

drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1627

Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +9 -0
+}
 
+static bool mtip_port_dev_check(const struct net_device *ndev)
+{
+	if (!mtip_netdev_get_priv(ndev))
+		return false;
+
+	return true;
+}
+

Rearranging the code a bit to make my point....

mtip_port_dev_check() tells us if this ndev is one of the ports of this switch.

drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c line 72

Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +10 -0
+/* netdev notifier */
+static int mtip_netdevice_event(struct notifier_block *unused,
+				unsigned long event, void *ptr)
+{
+	struct net_device *ndev = netdev_notifier_info_to_dev(ptr);
+	struct netdev_notifier_changeupper_info *info;
+	int ret = NOTIFY_DONE;
+
+	if (!mtip_port_dev_check(ndev))
+		return NOTIFY_DONE;

We have received a notification about some interface. This filters out all but the switches interfaces.

drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c line 76

Quoted 4 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +4 -0
+
+	switch (event) {
+	case NETDEV_CHANGEUPPER:
+		info = ptr;

CHANGERUPPER is that a netdev has been added or removed from a bridge, or some other sort of master device, e.g. a bond.

drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c line 81

Quoted 5 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +5 -0
+
+		if (netif_is_bridge_master(info->upper_dev)) {
+			if (info->linking)
+				ret = mtip_ndev_port_link(ndev,
+							  info->upper_dev);

Call mtip_ndev_port_link() has been added to some bridge.

Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +8 -0
+static int mtip_ndev_port_link(struct net_device *ndev,
+			       struct net_device *br_ndev)
+{
+	struct mtip_ndev_priv *priv = netdev_priv(ndev);
+	struct switch_enet_private *fep = priv->fep;
+
+	dev_dbg(&ndev->dev, "%s: ndev: %s br: %s fep: 0x%x\n",
+		__func__, ndev->name,  br_ndev->name, (unsigned int)fep);

drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c line 31

Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +10 -0
+
+	/* Check if MTIP switch is already enabled */
+	if (!fep->br_offload) {
+		if (!priv->master_dev)
+			priv->master_dev = br_ndev;
+
+		fep->br_offload = 1;
+		mtip_switch_dis_port_separation(fep);
+		mtip_clear_atable(fep);
+	}

So lets consider

ip link add br0 type bridge
ip link add br1 type bridge
ip link set dev lan1 master br0

We create two bridges, and add the first port to one of the bridges.

fep->br_offload should be False
priv->master_dev should be NULL.

So fep->br_offload is set to 1, priv->master_dev is set to br0 and the separation between the ports is removed.

It seems like the hardware will now be bridging packets between the two interfaces, despite lan2 not being a member of any bridge....

Now

ip link set dev lan2 master br1

I make the second port a member of some other bridge. fep->br_offload is True, so nothing happens.

This is why i said this code needs expanding.

If you look at other switch drivers, you will see each port keeps track of what bridge it has been joined to. There is then logic which iterates over the ports, finds which ports are members of the same bridge, and enables packets to flow between those ports.

With only two ports, you can make some simplifications, but you should only disable the separation once both ports are the member of the same bridge.

Andrew

#18 lore raw

Re: [PATCH v3 4/4] net: mtip: The L2 switch driver for imx287

Hi Andrew,

Quoted 98 lines
Quoted 6 lines

+struct switch_enet_private *mtip_netdev_get_priv(const struct net_device *ndev) +{

drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +4 -0
+	if (ndev->netdev_ops == &mtip_netdev_ops)
+		return netdev_priv(ndev);
+
+	return NULL;

drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c line 62

Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +9 -0
+}  
 
+static bool mtip_port_dev_check(const struct net_device *ndev)
+{
+	if (!mtip_netdev_get_priv(ndev))
+		return false;
+
+	return true;
+}
+  

Rearranging the code a bit to make my point....

mtip_port_dev_check() tells us if this ndev is one of the ports of this switch.

drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c line 72

Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +10 -0
+/* netdev notifier */
+static int mtip_netdevice_event(struct notifier_block *unused,
+				unsigned long event, void *ptr)
+{
+	struct net_device *ndev = netdev_notifier_info_to_dev(ptr);
+	struct netdev_notifier_changeupper_info *info;
+	int ret = NOTIFY_DONE;
+
+	if (!mtip_port_dev_check(ndev))
+		return NOTIFY_DONE;  

We have received a notification about some interface. This filters out all but the switches interfaces.

drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c line 76

Quoted 4 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +4 -0
+
+	switch (event) {
+	case NETDEV_CHANGEUPPER:
+		info = ptr;  

CHANGERUPPER is that a netdev has been added or removed from a bridge, or some other sort of master device, e.g. a bond.

Quoted 6 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +5 -0
+
+		if (netif_is_bridge_master(info->upper_dev)) {
+			if (info->linking)
+				ret = mtip_ndev_port_link(ndev,
+

info->upper_dev);

Call mtip_ndev_port_link() has been added to some bridge.

Quoted 9 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +8 -0
+static int mtip_ndev_port_link(struct net_device *ndev,
+			       struct net_device *br_ndev)
+{
+	struct mtip_ndev_priv *priv = netdev_priv(ndev);
+	struct switch_enet_private *fep = priv->fep;
+
+	dev_dbg(&ndev->dev, "%s: ndev: %s br: %s fep: 0x%x\n",
+		__func__, ndev->name,  br_ndev->name, (unsigned

int)fep); +

drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c line 31

Quoted 9 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +9 -0
+	/* Check if MTIP switch is already enabled */
+	if (!fep->br_offload) {
+		if (!priv->master_dev)
+			priv->master_dev = br_ndev;
+
+		fep->br_offload = 1;
+		mtip_switch_dis_port_separation(fep);
+		mtip_clear_atable(fep);
+	}  

So lets consider

ip link add br0 type bridge
ip link add br1 type bridge
ip link set dev lan1 master br0

We create two bridges, and add the first port to one of the bridges.

fep->br_offload should be False
priv->master_dev should be NULL.

So fep->br_offload is set to 1, priv->master_dev is set to br0 and the separation between the ports is removed.

It seems like the hardware will now be bridging packets between the two interfaces, despite lan2 not being a member of any bridge....

Now

ip link set dev lan2 master br1

I make the second port a member of some other bridge. fep->br_offload is True, so nothing happens.

This is why i said this code needs expanding.

Quoted 9 lines

If you look at other switch drivers, you will see each port keeps track of what bridge it has been joined to. There is then logic which iterates over the ports, finds which ports are members of the same bridge, and enables packets to flow between those ports.

With only two ports, you can make some simplifications, but you should only disable the separation once both ports are the member of the same bridge.

I think that I do have your point. Thanks for the info.

Quoted 1 line

Andrew

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: [email protected]

maintainer
#19 lore raw
In reply to Lukasz Majewski
Quoted 3 lines · On Mon, 31 Mar 2025 12:31:12 +0200 Lukasz Majewski wrote:

This patch series adds support for More Than IP's L2 switch driver embedded in some NXP's SoCs. This one has been tested on imx287, but is also available in the vf610.

Lukasz, please post with RFC in the subject tags during the merge window. As I already said net-next is closed.

#20 lore raw

Hi Jakub,

Quoted 7 lines · On Mon, 31 Mar 2025 12:31:12 +0200 Lukasz Majewski wrote:
Quoted 3 lines

This patch series adds support for More Than IP's L2 switch driver embedded in some NXP's SoCs. This one has been tested on imx287, but is also available in the vf610.

Lukasz, please post with RFC in the subject tags during the merge window. As I already said net-next is closed.

Ach, Ok.

I hope, that we will finish all reviews till 07.04, so v4 would be the final version.

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: [email protected]

#21 lore raw

Hi Lukasz,

Am 31.03.25 um 21:11 schrieb Lukasz Majewski:

Quoted 6 lines

Hi Jakub,

Quoted 4 lines · On Mon, 31 Mar 2025 12:31:12 +0200 Lukasz Majewski wrote:
Quoted 3 lines

This patch series adds support for More Than IP's L2 switch driver embedded in some NXP's SoCs. This one has been tested on imx287, but is also available in the vf610.

Quoted 6 lines
Quoted 2 lines

Lukasz, please post with RFC in the subject tags during the merge window. As I already said net-next is closed.

Ach, Ok.

I hope, that we will finish all reviews till 07.04, so v4 would be the final version.

well i appreciate your work on this driver, but this is not how it's going to work. No version of this patch series had a review time of a week. It's about quality not about deadlines.

Regards

#22 lore raw

Hi Stefan,

Quoted 9 lines

Hi Lukasz,

Am 31.03.25 um 21:11 schrieb Lukasz Majewski:

Quoted 6 lines

Hi Jakub,

Quoted 4 lines · On Mon, 31 Mar 2025 12:31:12 +0200 Lukasz Majewski wrote:
Quoted 3 lines

This patch series adds support for More Than IP's L2 switch driver embedded in some NXP's SoCs. This one has been tested on imx287, but is also available in the vf610.

Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

Lukasz, please post with RFC in the subject tags during the merge window. As I already said net-next is closed.

Ach, Ok.

I hope, that we will finish all reviews till 07.04, so v4 would be the final version.

well i appreciate your work on this driver,

Do you maintain some vf610 or imx28 devices, which would like to use L2 switch?

Quoted 3 lines

but this is not how it's
going to work. No version of this patch series had a review time of a week.

I just pointed out that patches would not be pulled (or anything else would be done with them) until the merge window is re-opened.

Quoted 2 lines

It's about quality not about deadlines.

:-D

Quoted 1 line

Regards

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: [email protected]

#23 lore raw

Am 31.03.25 um 23:42 schrieb Lukasz Majewski:

Quoted 13 lines

Hi Stefan,

Quoted 11 lines

Hi Lukasz,

Am 31.03.25 um 21:11 schrieb Lukasz Majewski:

Quoted 8 lines

Hi Jakub,

Quoted 6 lines · On Mon, 31 Mar 2025 12:31:12 +0200 Lukasz Majewski wrote:
Quoted 3 lines

This patch series adds support for More Than IP's L2 switch driver embedded in some NXP's SoCs. This one has been tested on imx287, but is also available in the vf610.

Lukasz, please post with RFC in the subject tags during the merge window. As I already said net-next is closed.

Quoted 7 lines
Quoted 5 lines
Quoted 4 lines

Ach, Ok.

I hope, that we will finish all reviews till 07.04, so v4 would be the final version.

well i appreciate your work on this driver,

Do you maintain some vf610 or imx28 devices, which would like to use L2 switch?

I've have been working with some i.MX28 devices and still "maintain" one i.MX28 platform of my employer. But it doesn't have a L2 switch.

Many years again, I tried to mainline a driver for the on-chip regulator of i.MX28 SoC with cpufreq support at the end.

https://github.com/lategoodbye/linux-mxs-power

Regards