net: mtip: Add support for MTIP imx287 L2 switch driver
Subsystems (5)
v4 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 down4. 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 (5):
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
ARM: mxs_defconfig: Enable CONFIG_FEC_MTIP_L2SW to support MTIP L2
switch
.../bindings/net/nxp,imx28-mtip-switch.yaml | 126 ++ MAINTAINERS | 7 + arch/arm/boot/dts/nxp/mxs/imx28-xea.dts | 54 + arch/arm/boot/dts/nxp/mxs/imx28.dtsi | 8 +- arch/arm/configs/mxs_defconfig | 14 +- 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 | 1970 +++++++++++++++++ .../net/ethernet/freescale/mtipsw/mtipl2sw.h | 782 +++++++ .../ethernet/freescale/mtipsw/mtipl2sw_br.c | 122 + .../ethernet/freescale/mtipsw/mtipl2sw_mgnt.c | 449 ++++ 13 files changed, 3537 insertions(+), 13 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/nxp,imx28-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
PATCH v4 1/5 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#
Changes for v4:
- Use $ref: ethernet-switch.yaml#/$defs/ethernet-ports and remove already referenced properties
- Rename file to nxp,imx28-mtip-switch.yaml
--- .../bindings/net/nxp,imx28-mtip-switch.yaml | 126 ++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml
Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml new file +126 -0
@@ -0,0 +1,126 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/nxp,imx28-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#/$defs/ethernet-ports + +patternProperties: + "^(ethernet-)?ports$": + type: object + additionalProperties: true + +properties: + compatible: + const: nxp,imx28-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 + + 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,imx28-mtip-switch"; + reg = <0x800f0000 0x20000>; + pinctrl-names = "default"; + pinctrl-0 = <&mac0_pins_a>, <&mac1_pins_a>; + phy-supply = <®_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: ethernet-port@1 { + reg = <1>; + label = "lan0"; + local-mac-address = [ 00 00 00 00 00 00 ]; + phy-mode = "rmii"; + phy-handle = <ðphy0>; + }; + + mtip_port2: ethernet-port@2 { + reg = <2>; + label = "lan1"; + local-mac-address = [ 00 00 00 00 00 00 ]; + phy-mode = "rmii"; + phy-handle = <ðphy1>; + }; + }; + + 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
Rob Herring
maintainerRe: [net-next v4 1/5] dt-bindings: net: Add MTIP L2 switch description
Quoted 48 lines · Lukasz Majewski
This patch provides description of the MTIP L2 switch available in some NXP's SOCs - e.g. imx287.
Signed-off-by Lukasz Majewski <[email protected]>---
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#Changes for v4:
- Use $ref: ethernet-switch.yaml#/$defs/ethernet-ports and remove already referenced properties
- Rename file to nxp,imx28-mtip-switch.yaml--- .../bindings/net/nxp,imx28-mtip-switch.yaml | 126 ++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yamlDocumentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml new file +12
-0@@ -0,0 +1,126 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/nxp,imx28-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:
Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml line 21
Quoted 10 lines
Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml new file +9
-0+ 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#/$defs/ethernet-ports + +patternProperties: + "^(ethernet-)?ports$":
New bindings should only use 'ethernet-ports'.
Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml line 23
Quoted 2 lines
Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml new file +2
-0+ type: object + additionalProperties: true
But what's this for? I thought you had some constrants for phy-mode and phy-handle?
Quoted 41 lines
Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml new file +41
-0+ +properties: + compatible: + const: nxp,imx28-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 + + 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,imx28-mtip-switch.yaml line 74
Quoted 10 lines
Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml new file +10
-0+required: + - compatible + - reg + - clocks + - clock-names + - interrupts + - mdio + - ethernet-ports + +additionalProperties: false
unevaluatedProperties: false
Quoted 55 lines
Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml new file +52
-0+ +examples: + - | + #include<dt-bindings/interrupt-controller/irq.h> + switch@800f0000 { + compatible = "nxp,imx28-mtip-switch"; + reg = <0x800f0000 0x20000>; + pinctrl-names = "default"; + pinctrl-0 = <&mac0_pins_a>, <&mac1_pins_a>; + phy-supply = <®_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: ethernet-port@1 { + reg = <1>; + label = "lan0"; + local-mac-address = [ 00 00 00 00 00 00 ]; + phy-mode = "rmii"; + phy-handle = <ðphy0>; + }; + + mtip_port2: ethernet-port@2 { + reg = <2>; + label = "lan1"; + local-mac-address = [ 00 00 00 00 00 00 ]; + phy-mode = "rmii"; + phy-handle = <ðphy1>; + }; + }; + + 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
Re: [net-next v4 1/5] dt-bindings: net: Add MTIP L2 switch description
Hi Rob,
Quoted 62 lines · Lukasz Majewski
Quoted 60 lines
This patch provides description of the MTIP L2 switch available in some NXP's SOCs - e.g. imx287.
Signed-off-by Lukasz Majewski <[email protected]>---
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#Changes for v4:
- Use $ref: ethernet-switch.yaml#/$defs/ethernet-ports and remove already referenced properties
- Rename file to nxp,imx28-mtip-switch.yaml--- .../bindings/net/nxp,imx28-mtip-switch.yaml | 126 ++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644
Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yamldiff --git
a/Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yamlb/Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yamlnew file mode 100644 index 000000000000..1afaf8029725 ---/dev/null
+++b/Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml(quoted diff) +0
-0@@ -0,0 +1,126 @@ +# SPDX-License-Identifier: (GPL-2.0-only ORBSD-2-Clause) +%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/nxp,imx28-mtip-switch.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#(quoted diff) +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(quoted diff) +4
-0+ output (MDIO) for physical layer device (PHY) management. + +$ref: ethernet-switch.yaml#/$defs/ethernet-ports +
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+patternProperties: + "^(ethernet-)?ports$":New bindings should only use 'ethernet-ports'.
Ok.
Quoted 7 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ type: object + additionalProperties: trueBut what's this for? I thought you had some constrants for phy-mode and phy-handle?
I've prepared following changes:
Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml +21 -6
@@ -17,11 +17,6 @@ description: $ref: ethernet-switch.yaml#/$defs/ethernet-ports -patternProperties: - "^(ethernet-)?ports$": - type: object - additionalProperties: true - properties: compatible: const: nxp,imx28-mtip-switch
@@ -55,6 +50,26 @@ properties: pinctrl-names: true + ethernet-ports: + type: object + additionalProperties: true + properties: + ethernet-port: + type: object + unevaluatedProperties: false + + properties: + reg: + items: + - enum: [1, 2] + description: MTIP L2 switch port number + + required: + - reg + - label + - phy-mode + - phy-handle + mdio: type: object $ref: mdio.yaml#
@@ -71,7 +86,7 @@ required: - mdio - ethernet-ports -additionalProperties: false +unevaluatedProperties: false examples:
To be applied on top of this patch. It takes into account the "required:" for 'ethernet-port' and also reuses the $ref: ethernet-switch.yaml#/$defs/ethernet-ports
Last, but not least:
make dt_binding_check DT_SCHEMA_FILES=nxp,imx28-mtip-switch.yaml make CHECK_DTBS=y DT_SCHEMA_FILES=nxp,imx28-mtip-switch.yaml nxp/mxs/imx28-xea.dtb
show no errors.
Quoted 46 lines
Quoted 46 lines
(quoted diff) +17
-0+ +properties: + compatible: + const: nxp,imx28-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. PHYsource clock
(quoted diff) +23
-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 + + mdio: + type: object + $ref: mdio.yaml# + unevaluatedProperties: false + description: + Specifies the mdio bus in the switch, used as a containerfor phy nodes. +
(quoted diff) +4
-0+required: + - compatible + - reg + - clocks
Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ - clock-names + - interrupts + - mdio + - ethernet-ports + +additionalProperties: falseunevaluatedProperties: false
Ok.
Quoted 48 lines
Quoted 48 lines
(quoted diff) +47
-0+ +examples: + - | + #include<dt-bindings/interrupt-controller/irq.h> + switch@800f0000 { + compatible = "nxp,imx28-mtip-switch"; + reg = <0x800f0000 0x20000>; + pinctrl-names = "default"; + pinctrl-0 = <&mac0_pins_a>, <&mac1_pins_a>; + phy-supply = <®_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: ethernet-port@1 { + reg = <1>; + label = "lan0"; + local-mac-address = [ 00 00 00 00 00 00 ]; + phy-mode = "rmii"; + phy-handle = <ðphy0>; + }; + + mtip_port2: ethernet-port@2 { + reg = <2>; + label = "lan1"; + local-mac-address = [ 00 00 00 00 00 00 ]; + phy-mode = "rmii"; + phy-handle = <ðphy1>; + }; + }; + + 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
(quoted diff) +5
-0+ ethphy1: ethernet-phy@1 { + reg = <1>; + }; + }; + };Signature · 1 line
2.39.5
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]
PATCH v4 2/5 ARM: dts: nxp: mxs: Adjust the imx28.dtsi L2 switch description
In reply to Lukasz MajewskiThe 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
Changes for v4:
- Rename imx287 with imx28 (as the former is not used in kernel anymore)
--- 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
@@ -1321,8 +1321,12 @@ mac1: ethernet@800f4000 { status = "disabled"; }; - eth_switch: switch@800f8000 { - reg = <0x800f8000 0x8000>; + eth_switch: switch@800f0000 { + compatible = "nxp,imx28-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
PATCH v4 3/5 ARM: dts: nxp: mxs: Adjust XEA board's DTS to support L2 switch
In reply to Lukasz MajewskiThe 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
Changes for v4:
- Use GPIO_ACTIVE_LOW instead of 0 in 'reset-gpios'
- Replace port@[12] with ethernet-port@[12]
--- 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
@@ -5,6 +5,7 @@ */ /dts-v1/; +#include<dt-bindings/interrupt-controller/irq.h> #include "imx28-lwe.dtsi" / {
@@ -90,6 +91,59 @@ ®_usb_5v { gpio = <&gpio0 2 0>; }; +ð_switch { + pinctrl-names = "default"; + pinctrl-0 = <&mac0_pins_a>, <&mac1_pins_a>; + phy-supply = <®_fec_3v3>; + status = "okay"; + + ethernet-ports { + #address-cells = <1>; + #size-cells = <0>; + + mtip_port1: ethernet-port@1 { + reg = <1>; + label = "lan0"; + local-mac-address = [ 00 00 00 00 00 00 ]; + phy-mode = "rmii"; + phy-handle = <ðphy0>; + }; + + mtip_port2: ethernet-port@2 { + reg = <2>; + label = "lan1"; + local-mac-address = [ 00 00 00 00 00 00 ]; + phy-mode = "rmii"; + phy-handle = <ðphy1>; + }; + }; + + mdio_sw: mdio { + #address-cells = <1>; + #size-cells = <0>; + + reset-gpios = <&gpio3 21 GPIO_ACTIVE_LOW>; + 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
Re: [net-next v4 3/5] ARM: dts: nxp: mxs: Adjust XEA board's DTS to support L2 switch
Quoted 3 lines · Lukasz Majewski
The description is similar to the one used with the new CPSW driver.
Signed-off-by Lukasz Majewski <[email protected]>
Andrew
Fabio Estevam
reviewerRe: [net-next v4 3/5] ARM: dts: nxp: mxs: Adjust XEA board's DTS to support L2 switch
In reply to Lukasz MajewskiHi Lukasz,
arch/arm/boot/dts/nxp/mxs/imx28-xea.dts ®_usb_5v { · line 133
Quoted 5 lines · Lukasz Majewski
arch/arm/boot/dts/nxp/mxs/imx28-xea.dts +5
-0+ 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) */
Please fix the multi-line comment style.
Re: [net-next v4 3/5] ARM: dts: nxp: mxs: Adjust XEA board's DTS to support L2 switch
Hi Fabio,
Quoted 12 lines
Hi Lukasz,
Quoted 7 lines · Lukasz Majewski
arch/arm/boot/dts/nxp/mxs/imx28-xea.dts +4
-0+ 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) */
Quoted 1 line
Please fix the multi-line comment style.
Ok, I will fix it.
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]
PATCH v4 4/5 net: mtip: The L2 switch driver for imx287
In reply to Lukasz MajewskiThis 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()
Changes for v4:
- Rename imx287 with imx28 (as the former is not used in kernel anymore)
- Reorder the place where ENET interface is initialized - without this change the enet_out clock has default (25 MHz) value, which causes issues during reset (RMII's 50 MHz is required for proper PHY reset).
- Use PAUR instead of PAUR register to program MAC address
- Replace eth_mac_addr() with eth_hw_addr_set()
- Write to HW the randomly generated MAC address (if required)
- Adjust the reset code
- s/read_atable/mtip_read_atable/g and s/write_atable/mtip_write_atable/g
- Add clk_disable() and netif_napi_del() when errors occur during mtip_open() - refactor the error handling path.
- Refactor the mtip_set_multicast_list() to write (now) correct values to ENET-FEC registers.
- Replace dev_warn() with dev_err()
- Use GPIO_ACTIVE_LOW to indicate polarity in DTS
- Refactor code to check if network device is the switch device
- Remove mtip_port_dev_check()
- Refactor mtip_ndev_port_link() avoid starting HW offloading for bridge when MTIP ports are parts of two distinct bridges
- Replace del_timer() with timer_delete_sync()
--- 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 | 1970 +++++++++++++++++ .../net/ethernet/freescale/mtipsw/mtipl2sw.h | 782 +++++++ .../ethernet/freescale/mtipsw/mtipl2sw_br.c | 122 + .../ethernet/freescale/mtipsw/mtipl2sw_mgnt.c | 449 ++++ 9 files changed, 3348 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
@@ -9455,6 +9455,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,imx28-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
@@ -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
@@ -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
@@ -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
@@ -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 +1970 -0
1,970 lines not on this page · raw message
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +782 -0
782 lines not on this page · raw message
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +122 -0
122 lines not on this page · raw message
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +449 -0
86 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.
Simon Horman
reviewerRe: [net-next v4 4/5] net: mtip: The L2 switch driver for imx287
Quoted 9 lines · 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.
Quoted 6 lines
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).Signed-off-by Lukasz Majewski <[email protected]>
Hi Lukasz,
This is not a complete review, but I did spend a bit of time looking over this and have provided some feedback on things I noticed below.
...
Quoted 9 lines
drivers/net/ethernet/freescale/mtipsw/Kconfig new file +3
-0@@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0-only +config FEC_MTIP_L2SW + tristate "MoreThanIP L2 switch support to FEC driver"
drivers/net/ethernet/freescale/mtipsw/Kconfig line 13
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/Kconfig new file +10
-0+ 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.
nit: requirements
Flagged by checkpatch.pl --codespell
...
Quoted 1 line
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +0
-0
...
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 70
Quoted 4 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +4
-0+static void mtip_enet_init (struct switch_enet_private *fep,int port) +{ +void __iomem *enet_addr = fep->enet_addr; +u32 mii_speed, holdtime, tmp;
I think it would be best to avoid variable names like tmp which have little meaning. Although still rather generic, perhaps reg would be more appropriate. Or better still something relating to the name the register, say rcr.
Quoted 36 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +36
-0+ +if (port ==2 ) + enet_addr +=MCF_ESW_ENET_PORT_OFFSET ; + + tmp =MCF_FEC_RCR_PROM |MCF_FEC_RCR_MII_MODE | +MCF_FEC_RCR_MAX_FL (1522 ); + +if (fep->phy_interface[port -1 ] ==PHY_INTERFACE_MODE_RMII ) + tmp |=MCF_FEC_RCR_RMII_MODE ; + +writel (tmp, enet_addr +MCF_FEC_RCR ); + +/* TCR */ +writel (MCF_FEC_TCR_FDEN , enet_addr +MCF_FEC_TCR ); + +/* ECR */ +writel (MCF_FEC_ECR_ETHER_EN , enet_addr +MCF_FEC_ECR ); + +/* Set MII speed to 2.5 MHz +*/ + mii_speed =DIV_ROUND_UP (clk_get_rate (fep->clk_ipg),5000000 ); + mii_speed--; + +/* The i.MX28 and i.MX6 types have another filed in the MSCR (aka +* MII_SPEED) register that defines the MDIO output hold time. Earlier +* versions are RAZ there, so just ignore the difference and write the +* register always. +* The minimal hold time according to IEE802.3 (clause 22) is 10 ns. +* HOLDTIME + 1 is the number of clk cycles the fec is holding the +* output. +* The HOLDTIME bitfield takes values between 0 and 7 (inclusive). +* Given that ceil(clkrate / 5000000) <= 64, the calculation for +* holdtime cannot result in a value greater than 3. +*/ + holdtime =DIV_ROUND_UP (clk_get_rate (fep->clk_ipg),100000000 ) -1 ; +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 116
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +10
-0+ fep->phy_speed = mii_speed <<1 | holdtime <<8 ; + +writel (fep->phy_speed, enet_addr +MCF_FEC_MSCR ); +} + +static int mtip_setup_mac (struct net_device *dev) +{ +struct mtip_ndev_priv *priv =netdev_priv (dev); +struct switch_enet_private *fep = priv->fep; +unsigned char *iap, tmpaddr[ETH_ALEN ];
Maybe mac_addr instead of tmpaddr.
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 127
Quoted 11 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +11
-0+ +/* Use MAC address from DTS */ + iap = &fep->mac[priv->portnum -1 ][0 ]; + +/* Use MAC address set by bootloader */ +if (!is_valid_ether_addr (iap)) { + *((unsigned long *)&tmpaddr[0 ]) = +be32_to_cpu (readl (fep->enet_addr +MCF_FEC_PALR )); + *((unsigned short *)&tmpaddr[4 ]) = +be16_to_cpu (readl (fep->enet_addr + +MCF_FEC_PAUR ) >>16 );
* Above, and elsewhere in this patch unsigned long seems to be used for 32 bit values. But unsigned long can be 64 bits wide.
I would suggest using u32, u16, and friends throughout this patch where an integer has a specific number of bits.
* readl returns a 32-bit value in host byte order. But the above assumes it returns a big endian value.
This does not seem correct.
* The point immediately above aside, the assignment of host byte order values to the byte-array tmpaddr seems to assume an endianness (little endian?).
It should work on either endian.
Quoted 24 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +24
-0+ iap = &tmpaddr[0 ]; + } + +/* Use random MAC address */ +if (!is_valid_ether_addr (iap)) { +eth_hw_addr_random (dev); +dev_info (&fep->pdev->dev,"Using random MAC address: %pM\n" , + dev->dev_addr); + iap = (unsigned char *)dev->dev_addr; + } + +/* Adjust MAC if using macaddr (and increment if needed) */ +eth_hw_addr_gen (dev, iap, priv->portnum -1 ); + +return 0 ; +} + +/** +* crc8_calc - calculate CRC for MAC storage +* +* @pmacaddress: A 6-byte array with the MAC address. The first byte is +* the first byte transmitted. +* +* Calculate Galois Field Arithmetic CRC for Polynom x^8+x^2+x+1.
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 161
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +10
-0+* It omits the final shift in of 8 zeroes a "normal" CRC would do +* (getting the remainder). +* +* Examples (hexadecimal values):<br> +* 10-11-12-13-14-15 => CRC=0xc2 +* 10-11-cc-dd-ee-00 => CRC=0xe6 +* +* Return: The 8-bit CRC in bits 7:0 +*/ +static int crc8_calc (unsigned char *pmacaddress)
Can lib/crc8.c:crc8() be used here?
Quoted 27 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +27
-0+{ +int byt;/* byte index */ +int bit;/* bit index */ +int crc =0x12 ; +int inval; + +for (byt =0 ; byt <6 ; byt++) { + inval = (((int )pmacaddress[byt]) &0xff ); +/* shift bit 0 to bit 8 so all our bits +* travel through bit 8 +* (simplifies below calc) +*/ + inval <<=8 ; + +for (bit =0 ; bit <8 ; bit++) { +/* next input bit comes into d7 after shift */ + crc |= inval &0x100 ; +if (crc &0x01 ) +/* before shift */ + crc ^=0x1c0 ; + + crc >>=1 ; + inval >>=1 ; + } + } +/* upper bits are clean as we shifted in zeroes! */ +return crc;
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 198
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +10
-0+} + +static void mtip_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 ); +}
It is unclear why hwentry, which is a pointer, is being cast to an integer and then back to a pointer. I see pointer arithmetic, but that can operate on pointers just as well as integers, without making assumptions about how wide pointers are with respect to longs.
And in any case, can't the types be used to directly access the offsets needed like this?
atable = fep->hwentry.mtip_table64b_entry; *read_lo = readl(&atable[index].lo); *read_hi = readl(&atable[index].hi);
Also, and perhaps more importantly, readl expects to be passed a pointer to __iomem. But the appropriate annotations seem to be missing (forcing them with a cast is not advisable here IMHO).
Please do run sparse over your patches to iron out __iomem (and endian) issues.
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 206
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +8
-0+ +static void mtip_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 );
Likewise here.
Quoted 1 line
+}
...
Quoted 7 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +7
-0+/* Clear complete MAC Look Up Table */ +void mtip_clear_atable (struct switch_enet_private *fep) +{ +int index; + +for (index =0 ; index <2048 ; index++) +mtip_write_atable (fep, index,0 ,0 );
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 300
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +10
-0+} + +/** +* mtip_update_atable_static - Update switch static address table +* +* @mac_addr: Pointer to the array containing MAC address to +* be put as static entry +* @port: Port bitmask numbers to be added in static entry, +* valid values are 1-7 +* @priority: The priority for the static entry in table
@fep should also be documented here.
Flagged by ./scripts/kernel-doc -none
and W=1 builds.
Quoted 12 lines
+ *
+ * Updates MAC address lookup table with a static entry.
+ *
+ * Searches if the MAC address is already there in the block and replaces
+ * the older entry with the new one. If MAC address is not there then puts
+ * a new entry in the first empty slot available in the block.
+ *
+ * Return: 0 for a successful update else-ENOSPCwhen no slot available
+ */drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +3
-0+static int mtip_update_atable_static (unsigned char *mac_addr,unsigned int port, +unsigned int priority, +struct switch_enet_private *fep)
...
Quoted 27 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +27
-0+/* During a receive, the cur_rx points to the current incoming buffer. +* When we update through the ring, if the next incoming buffer has +* not been given to the system, we just set the empty indicator, +* effectively tossing the packet. +*/ +static int mtip_switch_rx (struct net_device *dev,int budget,int *port) +{ +struct mtip_ndev_priv *priv =netdev_priv (dev); +struct switch_enet_private *fep = priv->fep; +struct switch_t *fecp = fep->hwp; +unsigned short status, pkt_len; +struct net_device *pndev; +u8 *data, rx_port =0xFF ; +struct ethhdr *eth_hdr; +int pkt_received =0 ; +struct sk_buff *skb; +unsigned long flags; +struct cbd_t *bdp; + +spin_lock_irqsave (&fep->hw_lock, flags); + +/* First, grab all of the stats for the incoming packet. +* These get messed up if we get called due to a busy condition. +*/ + bdp = fep->cur_rx; + +while (!((status = bdp->cbd_sc) &BD_ENET_RX_EMPTY )) {
...
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1108
Quoted 3 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +3
-0+ }/* while (!((status = bdp->cbd_sc) & BD_ENET_RX_EMPTY)) */ + +writel (bdp, &fep->cur_rx);
I'm confused buy this.
At the top of this function, bdp is assigned using:
bdp = fep->cur_rx;
But here writel() is used to assign bdp to &fep->cur_rx. Which assumes that bdp is a 32-bit little endian value.
But it is a pointer in host byte order which may be wide than 32-bits.
On x86_64 int is 32-bits while pointers are 64 bits. W=1 builds with gcc 14.2.0 flag this problem like this:
.../mtipl2sw.c:1108:9: error: incompatible pointer to integer conversion passing 'struct cbd_t *' to parameter of type 'unsigned int' [-Wint-conversion]
1108 | writel(bdp, &fep->cur_rx);
| ^~~
This also assumes that &fep->cur_rx is a pointer to __iomem, but that does not seem to be the case.
Quoted 4 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +4
-0+spin_unlock_irqrestore (&fep->hw_lock, flags); + +return pkt_received; +}
...
Quoted 24 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +24
-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_err (&fep->pdev->dev,"No suitable DMA available\n" ); +return ret; + } + +/* Allocate memory for buffer descriptors */ + cbd_base =dma_alloc_coherent (&fep->pdev->dev,PAGE_SIZE , &fep->bd_dma, +GFP_KERNEL ); +if (!cbd_base) +return -ENOMEM ; + +/* Set receive and transmit descriptor base */ + fep->rx_bd_base = cbd_base; + fep->tx_bd_base = cbd_base +RX_RING_SIZE ; + +/* Initialize the receive buffer descriptors */ + bdp = fep->rx_bd_base;
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1655
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +10
-0+for (i =0 ; i <RX_RING_SIZE ; i++) { + bdp->cbd_sc =0 ; + bdp++; + } + +/* Set the last buffer to wrap */ + bdp--; + bdp->cbd_sc |=BD_SC_WRAP ; + +/* ...and the same for transmmit */
nit: transmit
Quoted 26 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +26
-0+ bdp = fep->tx_bd_base; +for (i =0 ; i <TX_RING_SIZE ; i++) { +/* Initialize the BD for every fragment in the page */ + bdp->cbd_sc =0 ; + bdp->cbd_bufaddr =0 ; + bdp++; + } + +/* Set the last buffer to wrap */ + bdp--; + bdp->cbd_sc |=BD_SC_WRAP ; + +return 0 ; +} + +static void mtip_ndev_cleanup (struct switch_enet_private *fep) +{ +int i; + +for (i =0 ; i <SWITCH_EPORT_NUMBER ; i++) { +if (fep->ndev[i]) { +unregister_netdev (fep->ndev[i]); +free_netdev (fep->ndev[i]); + } + } +}
...
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1803
Quoted 5 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +5
-0+static const struct of_device_id mtipl2_of_match[] = { + { .compatible ="nxp,imx28-mtip-switch" , + .data = &mtip_imx28_l2switch_info}, + {/* sentinel */ } +}
There should be a trailing ';' on the line above.
...
Quoted 1 line
+struct
addr_table64b_entry{
One space after struct is enough.
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c
Quoted 5 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +5
-0+unsigned int lo;/* lower 32 bits */ +unsigned int hi;/* upper 32 bits */ +}; + +struct mtip_addr_table_t {
I think you can drop the '_t' from the name of this struct. We know it is a type :)
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c
Quoted 1 line
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +1
-0+struct addr_table64b_entry mtip_table64b_entry[2048 ];
One space is enough after addr_table64b_entry. And in general, unless the aim is to align field names (not here because there is only one field :)
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c
Quoted 5 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +5
-0+}; + +#define MCF_ESW_LOOKUP_MEM_OFFSET 0x4000 +#define MCF_ESW_ENET_PORT_OFFSET 0x4000 +#define ENET_SWI_PHYS_ADDR_OFFSET 0x8000
Ditto.
...
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c +0
-0new file mode 100644
index 000000000000..0b76a60858a5drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +3
-0@@ -0,0 +1,122 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* L2 switch Controller driver for MTIP block - bridge network interface
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c line 13
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +10
-0+* +* Copyright (C) 2025 DENX Software Engineering GmbH +* Lukasz Majewski <[email protected]> +*/ + +#include <linux/netdevice.h> +#include <linux/etherdevice.h> +#include <linux/platform_device.h> + +#include "mtipl2sw.h"
Blank line here please.
Quoted 22 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +22
-0+static int mtip_ndev_port_link (struct net_device *ndev, +struct net_device *br_ndev, +struct netlink_ext_ack *extack) +{ +struct mtip_ndev_priv *priv =netdev_priv (ndev), *other_priv; +struct switch_enet_private *fep = priv->fep; +struct net_device *other_ndev; + +/* Check if one port of MTIP switch is already bridged */ +if (fep->br_members && !fep->br_offload) { +/* Get the second bridge ndev */ + other_ndev = fep->ndev[fep->br_members -1 ]; + other_priv =netdev_priv (other_ndev); +if (other_priv->master_dev != br_ndev) { +NL_SET_ERR_MSG_MOD (extack, +"L2 offloading only possible for the same bridge!" ); +return notifier_from_errno (-EOPNOTSUPP ); + } + + fep->br_offload =1 ; +mtip_switch_dis_port_separation (fep); +mtip_clear_atable (fep);
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c line 45
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +10
-0+ } + +if (!priv->master_dev) + priv->master_dev = br_ndev; + + fep->br_members |=BIT (priv->portnum -1 ); + + dev_dbg(&ndev->dev, + "%s: ndev: %s br: %s fep: 0x%x members: 0x%x offload: %d\n", + __func__, ndev->name, br_ndev->name, (unsigned int)fep,
Perhaps it would be best to use %p as the format specifier for fep and not cast it.
On x86_64 int is 32-bits while pointers are 64 bits. W=1 builds with gcc 14.2.0 flag this problem like this:
.../mtipl2sw_br.c:45:55: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
45 | __func__, ndev->name, br_ndev->name, (unsigned int)fep,
| ^
Quoted 22 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +22
-0+ fep->br_members, fep->br_offload); + +return NOTIFY_DONE ; +} + +static void mtip_netdevice_port_unlink (struct net_device *ndev) +{ +struct mtip_ndev_priv *priv =netdev_priv (ndev); +struct switch_enet_private *fep = priv->fep; + +dev_dbg (&ndev->dev,"%s: ndev: %s members: 0x%x\n" , __func__, + ndev->name, fep->br_members); + + fep->br_members &= ~BIT (priv->portnum -1 ); + priv->master_dev =NULL ; + +if (!fep->br_members) { + fep->br_offload =0 ; +mtip_switch_en_port_separation (fep); +mtip_clear_atable (fep); + } +}
...
Signature · 1 line
pw-bot: changes-requested
Re: [net-next v4 4/5] net: mtip: The L2 switch driver for imx287
Hi Simon,
Quoted 16 lines · Lukasz Majewski
Quoted 15 lines
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).
Quoted 8 lines
Quoted 1 line
Signed-off-by Lukasz Majewski <[email protected]>Hi Lukasz,
This is not a complete review, but I did spend a bit of time looking over this and have provided some feedback on things I noticed below.
Thanks for your feedback.
Quoted 29 lines
...
Quoted 23 lines
(quoted diff) +0
-0b/drivers/net/ethernet/freescale/mtipsw/Kconfig new file mode 100644 index 000000000000..450ff734a321
drivers/net/ethernet/freescale/mtipsw/Kconfig new file +9
-0@@ -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 oni.MX
drivers/net/ethernet/freescale/mtipsw/Kconfig new file +1
-0+ SoCs (e.g. iMX28, vf610). It offloads bridging to thisIP block's
drivers/net/ethernet/freescale/mtipsw/Kconfig new file +1
-0+ hardware and allows switch management with standardLinux tools.
drivers/net/ethernet/freescale/mtipsw/Kconfig new file +1
-0+ This switch driver can be used interchangeable with thealready
drivers/net/ethernet/freescale/mtipsw/Kconfig new file +1
-0+ available FEC driver, depending on the use case'sQuoted 1 line
requirments.
nit: requirements
Quoted 2 lines
Flagged by checkpatch.pl --codespell
Ok.
Quoted 7 lines
...
Quoted 2 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +0
-0...
Quoted 9 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 70
Quoted 4 lines
+static void
mtip_enet_init(struct switch_enet_private *fep, int port)+{drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +2
-0+void __iomem *enet_addr = fep->enet_addr; +u32 mii_speed, holdtime, tmp;I think it would be best to avoid variable names like tmp which have little meaning. Although still rather generic, perhaps reg would be more appropriate. Or better still something relating to the name the register, say rcr.
Ok, I will use reg/rcr instead of tmp.
Quoted 50 lines
Quoted 50 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +8
-0+ +if (port ==2 ) + enet_addr +=MCF_ESW_ENET_PORT_OFFSET ; + + tmp =MCF_FEC_RCR_PROM |MCF_FEC_RCR_MII_MODE | +MCF_FEC_RCR_MAX_FL (1522 ); + + if (fep->phy_interface[port - 1] ==
PHY_INTERFACE_MODE_RMII)drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +13
-0+ tmp |=MCF_FEC_RCR_RMII_MODE ; + +writel (tmp, enet_addr +MCF_FEC_RCR ); + +/* TCR */ +writel (MCF_FEC_TCR_FDEN , enet_addr +MCF_FEC_TCR ); + +/* ECR */ +writel (MCF_FEC_ECR_ETHER_EN , enet_addr +MCF_FEC_ECR ); + +/* Set MII speed to 2.5 MHz +*/ + mii_speed = DIV_ROUND_UP(clk_get_rate(fep->clk_ipg),5000000);
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +3
-0+ mii_speed--; + +/* The i.MX28 and i.MX6 types have another filed in the MSCR (aka
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +1
-0+* MII_SPEED) register that defines the MDIO output hold time. Earlier
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +1
-0+* versions are RAZ there, so just ignore the difference and write the
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +2
-0+* register always. +* The minimal hold time according to IEE802.3 (clause 22) is 10 ns.
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +1
-0+* HOLDTIME + 1 is the number of clk cycles the fec is holding the
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +2
-0+* output. +* The HOLDTIME bitfield takes values between 0 and 7 (inclusive).
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +1
-0+* Given that ceil(clkrate / 5000000) <= 64, the calculation for
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +3
-0+* holdtime cannot result in a value greater than 3. +*/ + holdtime = DIV_ROUND_UP(clk_get_rate(fep->clk_ipg),100000000) - 1; +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +4
-0+ fep->phy_speed = mii_speed <<1 | holdtime <<8 ; + +writel (fep->phy_speed, enet_addr +MCF_FEC_MSCR ); +}
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 116
Quoted 6 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +6
-0+ +static int mtip_setup_mac (struct net_device *dev) +{ +struct mtip_ndev_priv *priv =netdev_priv (dev); +struct switch_enet_private *fep = priv->fep; +unsigned char *iap, tmpaddr[ETH_ALEN ];Maybe
mac_addrinstead of tmpaddr.
Ok.
Quoted 17 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 127
Quoted 13 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +8
-0+ +/* Use MAC address from DTS */ + iap = &fep->mac[priv->portnum -1 ][0 ]; + +/* Use MAC address set by bootloader */ +if (!is_valid_ether_addr (iap)) { + *((unsigned long *)&tmpaddr[0 ]) = + be32_to_cpu(readl(fep->enet_addr +
MCF_FEC_PALR));drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +3
-0+ *((unsigned short *)&tmpaddr[4 ]) = +be16_to_cpu (readl (fep->enet_addr + +MCF_FEC_PAUR ) >>16 );* Above, and elsewhere in this patch unsigned long seems to be used for 32 bit values. But unsigned long can be 64 bits wide.
As fair as I know - from the outset - this driver had some implicit assumption to be used on 32 bit SoCs (imx28, vf610).
As a result the unsigned long would be 32 bits.
On the other hand - the documentation clearly says that registers in this IP block implementation are 32 bit wide.
Quoted 3 lines
I would suggest using u32, u16, and friends throughout this patch where an integer has a specific number of bits.
I think that values, which directly readl()/writel() values from the registers shall be u32. However, more generic code could use int/ unsigned int though.
Quoted 5 lines
* readl returns a 32-bit value in host byte order. But the above assumes it returns a big endian value.
This does not seem correct.
Please consult similar implementation from fec_main.c:
https://elixir.bootlin.com/linux/v6.14-rc6/source/drivers/net/ethernet/freescale/fec_main.c#L2044
I would use the same approach as in the above link.
Quoted 6 lines
* The point immediately above aside, the assignment of host byte order values to the byte-array tmpaddr seems to assume an endianness (little endian?).
It should work on either endian.
I guess that implementation from above link is the correct one.
Quoted 30 lines
Quoted 30 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +7
-0+ iap = &tmpaddr[0 ]; + } + +/* Use random MAC address */ +if (!is_valid_ether_addr (iap)) { +eth_hw_addr_random (dev); + dev_info(&fep->pdev->dev, "Using random MACaddress: %pM\n",
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +14
-0+ dev->dev_addr); + iap = (unsigned char *)dev->dev_addr; + } + +/* Adjust MAC if using macaddr (and increment if needed) */ +eth_hw_addr_gen (dev, iap, priv->portnum -1 ); + +return 0 ; +} + +/** +* crc8_calc - calculate CRC for MAC storage +* +* @pmacaddress: A 6-byte array with the MAC address. The first byte is
+ * the first byte transmitted.
+ *
+ * Calculate Galois Field Arithmetic CRC for Polynom x^8+x^2+x+1.
+ * It omits the final shift in of 8 zeroes a "normal" CRC would do
+ * (getting the remainder).
+ *
+ * Examples (hexadecimal values):<br>
Quoted 8 lines
Quoted 6 lines
+ * 10-11-12-13-14-15 => CRC=0xc2 + * 10-11-cc-dd-ee-00 => CRC=0xe6+ *
+ * Return: The 8-bit CRC in bits 7:0
+ */
+static intcrc8_calc(unsigned char *pmacaddress)Can lib/crc8.c:crc8() be used here?
This seems a bit problematic, as the above code is taken from the vendor driver.
The documentation states - that the hash uses CRC-8 with following polynomial:
x^8 + x^2 + x + 1 (0x07), which shall correspond to available in Linux:
static unsigned char mac1[] = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15}; crc8_populate_msb(mtipl2sw_crc8_table, 0x07); crc8(mtipl2sw_crc8_table, mac1, sizeof(mac1), CRC8_INIT_VALUE);
However, those results don't match (either with 0xFF and 0x00 as the initial value).
I've also searched the Internet to compare different CRC implementations used in field:
https://crccalc.com/?crc=0x10 0x11 0x12 0x13 0x14 0x15&method=CRC-8&datatype=hex&outtype=hex
they also doesn't match results from this code.
Hence, the question - which implementation is right?
Vendor developer could have known a bit more than we do, so I would prefer to keep this code as is - especially that switch internally may use this crc8 calculation to find proper "slot/index" in the atable.
Quoted 46 lines
Quoted 35 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +16
-0+{ +int byt;/* byte index */ +int bit;/* bit index */ +int crc =0x12 ; +int inval; + +for (byt =0 ; byt <6 ; byt++) { + inval = (((int )pmacaddress[byt]) &0xff ); +/* shift bit 0 to bit 8 so all our bits +* travel through bit 8 +* (simplifies below calc) +*/ + inval <<=8 ; + +for (bit =0 ; bit <8 ; bit++) { +/* next input bit comes into d7 after shift */
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +14
-0+ crc |= inval &0x100 ; +if (crc &0x01 ) +/* before shift */ + crc ^=0x1c0 ; + + crc >>=1 ; + inval >>=1 ; + } + } +/* upper bits are clean as we shifted in zeroes! */ +return crc; +} + +static void mtip_read_atable(struct switch_enet_private *fep, intindex,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +1
-0+ unsigned long *read_lo, unsigned long
*read_hi) +{drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c
Quoted 5 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +5
-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); +}It is unclear why hwentry, which is a pointer, is being cast to an integer and then back to a pointer. I see pointer arithmetic, but that can operate on pointers just as well as integers, without making assumptions about how wide pointers are with respect to longs.
Quoted 8 lines
And in any case, can't the types be used to directly access the offsets needed like this?
atable = fep->hwentry.mtip_table64b_entry; *read_lo = readl(&atable[index].lo); *read_hi = readl(&atable[index].hi);
The code as is seems to be OK.
The (atable) memory structure is as follows:
1. You can store 2048 MAC addresses (2x32 bit each).
2. Memory from point 1 is addressed as follows:
2.1 -> from MAC address the CRC8 is calculated (0x00 - 0xFF). This is the 'index' in the original code.
2.2 -> as it may happen that for two different MAC address the same CRC8 is calculated (i.e. 'index' is the same), each 'index' can store 8 entries for MAC addresses (and it is searched in a linear way if needed).
IMHO, the index above shall be multiplied by 8.
Quoted 4 lines
Also, and perhaps more importantly, readl expects to be passed a pointer to
__iomem. But the appropriate annotations seem to be missing (forcing them with a cast is not advisable here IMHO).
I think that the code below:
unsigned long atable_base = (unsigned long)fep->hwentry;
could be replaced with
void __iomem *atable_base = fep->hwentry;
and the (index << 3) with (index * ATABLE_ENTRY_PER_SLOT)
Quoted 3 lines
Please do run sparse over your patches to iron out
__iomem(and endian) issues.
Ok, I will run the make C=1 when compiling.
Quoted 11 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 206
Quoted 9 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +2
-0+ +static void mtip_write_atable(struct switch_enet_private *fep, intindex,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +1
-0+unsigned long write_lo, unsignedlong
write_hi) +{drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +4
-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 );Likewise here.
Please see the above comment.
Quoted 16 lines
Quoted 2 lines
+}
...
Quoted 11 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +11
-0+/* Clear complete MAC Look Up Table */ +void mtip_clear_atable (struct switch_enet_private *fep) +{ +int index; + +for (index =0 ; index <2048 ; index++) +mtip_write_atable (fep, index,0 ,0 ); +} + +/** +* mtip_update_atable_static - Update switch static address table
Quoted 9 lines
Quoted 6 lines
+ *
+ * @mac_addr: Pointer to the array containing MAC address to+ * be put as static entry + * @port: Port bitmask numbers to be added in static entry, + * valid values are 1-7+ * @priority: The priority for the static entry in table
@fep should also be documented here.
OK.
Quoted 63 lines
Flagged by
./scripts/kernel-doc-none
and W=1 builds.Quoted 17 lines
+ *
+ * Updates MAC address lookup table with a static entry.
+ *
+ * Searches if the MAC address is already there in the block and replaces
+ * the older entry with the new one. If MAC address is not there then puts
+ * a new entry in the first empty slot available in the block.
+ *
+ * Return: 0 for a successful update else-ENOSPCwhen no slot available
+ */
+static int mtip_update_atable_static(unsigned char*mac_addr, unsigned int port,drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +2
-0+unsigned int priority, + struct switch_enet_private*fep)
...
Quoted 29 lines
+/* During a receive, the
cur_rxpoints to the current incoming buffer.
+ * When we update through the ring, if the next incoming buffer has
+ * not been given to the system, we just set the empty indicator,
+ * effectively tossing the packet.
+ */
+static intmtip_switch_rx(struct net_device *dev, int budget, int *port)+{drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +16
-0+struct mtip_ndev_priv *priv =netdev_priv (dev); +struct switch_enet_private *fep = priv->fep; +struct switch_t *fecp = fep->hwp; +unsigned short status, pkt_len; +struct net_device *pndev; +u8 *data, rx_port =0xFF ; +struct ethhdr *eth_hdr; +int pkt_received =0 ; +struct sk_buff *skb; +unsigned long flags; +struct cbd_t *bdp; + +spin_lock_irqsave (&fep->hw_lock, flags); + +/* First, grab all of the stats for the incoming packet. +* These get messed up if we get called due to a busy condition.
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +4
-0+*/ + bdp = fep->cur_rx; + +while (!((status = bdp->cbd_sc) &BD_ENET_RX_EMPTY )) {...
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1108
Quoted 3 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +1
-0+ }/* while (!((status = bdp->cbd_sc) & BD_ENET_RX_EMPTY)) */ +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +1
-0+writel (bdp, &fep->cur_rx);I'm confused buy this.
At the top of this function, bdp is assigned using:
Quoted 7 lines
bdp = fep->cur_rx;But here
writel()is used to assign bdp to&fep->cur_rx. Which assumes that bdp is a 32-bit little endian value.
But it is a pointer in host byte order which may be wide than 32-bits.On
x86_64int is 32-bits while pointers are 64 bits.
I will cross compile with make W=1 and C=1 to find all problematic places.
Quoted 11 lines
W=1 builds with gcc 14.2.0 flag this problem like this:
.../mtipl2sw.c:1108:9: error: incompatible pointer to integer conversion passing 'structcbd_t*' to parameter of type 'unsigned
int' [-Wint-conversion] 1108 |writel(bdp, &fep->cur_rx); |^~~This also assumes that
&fep->cur_rxis a pointer to__iomem, but that does not seem to be the case.
The writel(bdp, &fep->cur_rx); shall be just replaced with fep->cur_rx = bdp.
Thanks for spotting.
Quoted 39 lines
Quoted 5 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +4
-0+spin_unlock_irqrestore (&fep->hw_lock, flags); + +return pkt_received; +}...
Quoted 31 lines
+static int
__initmtip_switch_dma_init(struct switch_enet_private *fep)+{drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +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));drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +2
-0+if (ret <0 ) { + dev_err(&fep->pdev->dev, "No suitable DMAavailable\n");
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +5
-0+return ret; + } + +/* Allocate memory for buffer descriptors */ + cbd_base = dma_alloc_coherent(&fep->pdev->dev, PAGE_SIZE,
&fep->bd_dma,drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +14
-0+ GFP_KERNEL); +if (!cbd_base) +return -ENOMEM ; + +/* Set receive and transmit descriptor base */ + fep->rx_bd_base = cbd_base; + fep->tx_bd_base = cbd_base +RX_RING_SIZE ; + +/* Initialize the receive buffer descriptors */ + bdp = fep->rx_bd_base; +for (i =0 ; i <RX_RING_SIZE ; i++) { + bdp->cbd_sc =0 ; + bdp++; + }
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1655
Quoted 6 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +6
-0+ +/* Set the last buffer to wrap */ + bdp--; + bdp->cbd_sc |=BD_SC_WRAP ; + +/* ...and the same for transmmit */ nit: transmit
Ok.
Quoted 31 lines
Quoted 28 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +3
-0+ bdp = fep->tx_bd_base; +for (i =0 ; i <TX_RING_SIZE ; i++) { +/* Initialize the BD for every fragment in the page */
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +23
-0+ bdp->cbd_sc =0 ; + bdp->cbd_bufaddr =0 ; + bdp++; + } + +/* Set the last buffer to wrap */ + bdp--; + bdp->cbd_sc |=BD_SC_WRAP ; + +return 0 ; +} + +static void mtip_ndev_cleanup (struct switch_enet_private *fep) +{ +int i; + +for (i =0 ; i <SWITCH_EPORT_NUMBER ; i++) { +if (fep->ndev[i]) { +unregister_netdev (fep->ndev[i]); +free_netdev (fep->ndev[i]); + } + } +}...
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1803
Quoted 5 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +5
-0+static const struct of_device_id mtipl2_of_match[] = { + { .compatible ="nxp,imx28-mtip-switch" , + .data = &mtip_imx28_l2switch_info}, + {/* sentinel */ } +}There should be a trailing ';' on the line above.
+1
Quoted 6 lines
...
Quoted 1 line
+struct
addr_table64b_entry{One space after struct is enough.
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c
Quoted 5 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +5
-0+unsigned int lo;/* lower 32 bits */ +unsigned int hi;/* upper 32 bits */ +}; + +struct mtip_addr_table_t {I think you can drop the '_t' from the name of this struct. We know it is a type :)
Ok.
Quoted 7 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c
Quoted 2 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +1
-0+struct addr_table64b_entry mtip_table64b_entry[2048 ];One space is enough after
addr_table64b_entry. And in general, unless the aim is to align field names (not here because there is only one field :)
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c
Quoted 5 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +5
-0+}; + +#define MCF_ESW_LOOKUP_MEM_OFFSET 0x4000 +#define MCF_ESW_ENET_PORT_OFFSET 0x4000 +#define ENET_SWI_PHYS_ADDR_OFFSET 0x8000Ditto.
+1
Quoted 18 lines
...
Quoted 16 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c +0
-0new file mode 100644
index 000000000000..0b76a60858a5drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +3
-0@@ -0,0 +1,122 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* L2 switch Controller driver for MTIP block - bridge network interface
+ *
+ * Copyright (C) 2025 DENX Software Engineering GmbH
+ * Lukasz Majewski <[email protected]>
+ */
Quoted 9 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c
Quoted 6 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +6
-0+ +#include <linux/netdevice.h> +#include <linux/etherdevice.h> +#include <linux/platform_device.h> + +#include "mtipl2sw.h" Blank line here please.
Ok.
Quoted 40 lines
Quoted 35 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +5
-0+static int mtip_ndev_port_link (struct net_device *ndev, +struct net_device *br_ndev, +struct netlink_ext_ack *extack) +{ + struct mtip_ndev_priv *priv = netdev_priv(ndev),
*other_priv;drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +11
-0+struct switch_enet_private *fep = priv->fep; +struct net_device *other_ndev; + +/* Check if one port of MTIP switch is already bridged */ +if (fep->br_members && !fep->br_offload) { +/* Get the second bridge ndev */ + other_ndev = fep->ndev[fep->br_members -1 ]; + other_priv =netdev_priv (other_ndev); +if (other_priv->master_dev != br_ndev) { + NL_SET_ERR_MSG_MOD(extack, + "L2 offloading onlypossible for the same bridge!");
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +15
-0+return notifier_from_errno (-EOPNOTSUPP ); + } + + fep->br_offload =1 ; +mtip_switch_dis_port_separation (fep); +mtip_clear_atable (fep); + } + +if (!priv->master_dev) + priv->master_dev = br_ndev; + + fep->br_members |=BIT (priv->portnum -1 ); + + dev_dbg(&ndev->dev, + "%s: ndev: %s br: %s fep: 0x%x members: 0x%xoffload: %d\n",
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +1
-0+ __func__, ndev->name, br_ndev->name, (unsignedQuoted 1 line
int)fep,
Perhaps it would be best to use %p as the format specifier for fep and not cast it.
Quoted 7 lines
On
x86_64int is 32-bits while pointers are 64 bits. W=1 builds with gcc 14.2.0 flag this problem like this:
.../mtipl2sw_br.c:45:55: warning: cast from pointer to integer of
different size [-Wpointer-to-int-cast] 45 |__func__,ndev->name,br_ndev->name, (unsigned int)fep, |^
Ok.
Quoted 18 lines
Quoted 18 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +11
-0+ fep->br_members, fep->br_offload); + +return NOTIFY_DONE ; +} + +static void mtip_netdevice_port_unlink (struct net_device *ndev) +{ +struct mtip_ndev_priv *priv =netdev_priv (ndev); +struct switch_enet_private *fep = priv->fep; + + dev_dbg(&ndev->dev, "%s: ndev: %s members: 0x%x\n",
__func__,drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +5
-0+ ndev->name, fep->br_members); + + fep->br_members &= ~BIT (priv->portnum -1 ); + priv->master_dev =NULL ; +
Quoted 9 lines
Quoted 6 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +6
-0+if (!fep->br_members) { + fep->br_offload =0 ; +mtip_switch_en_port_separation (fep); +mtip_clear_atable (fep); + } +}...
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]
Re: [net-next v4 4/5] net: mtip: The L2 switch driver for imx287
Hi Simon,
Quoted 29 lines
Quoted 6 lines
It is unclear why hwentry, which is a pointer, is being cast to an integer and then back to a pointer. I see pointer arithmetic, but that can operate on pointers just as well as integers, without making assumptions about how wide pointers are with respect to longs.
Quoted 8 lines
And in any case, can't the types be used to directly access the offsets needed like this?
atable = fep->hwentry.mtip_table64b_entry; *read_lo = readl(&atable[index].lo); *read_hi = readl(&atable[index].hi);The code as is seems to be OK.
The (atable) memory structure is as follows:
1. You can store 2048 MAC addresses (2x32 bit each).
2. Memory from point 1 is addressed as follows:
2.1 -> from MAC address the CRC8 is calculated (0x00-0xFF). This is the 'index' in the original code.
2.2 -> as it may happen that for two different MAC address the same CRC8 is calculated (i.e. 'index' is the same), each 'index' can store 8 entries for MAC addresses (and it is searched in a linear way if needed).
Quoted 1 line
IMHO, the index above shall be multiplied by 8.
I've double check it and it turned out that you were right :-)
The following code:
struct addr_table64b_entry *atable_base =fep->hwentry->mtip_table64b_entry;
*read_lo = readl(&atable_base[index].lo);*read_hi = readl(&atable_base[index].hi);
Is more readable than the current code.
The same would be used for atable_write()
I will change it for v5.
Quoted 6 lines
Quoted 5 lines
Also, and perhaps more importantly, readl expects to be passed a pointer to
__iomem. But the appropriate annotations seem to be missing (forcing them with a cast is not advisable here IMHO).
Quoted 7 lines
I think that the code below:
unsigned longatable_base= (unsigned long)fep->hwentry;could be replaced with
void__iomem*atable_base=fep->hwentry;and the (index << 3) with (index *
ATABLE_ENTRY_PER_SLOT)
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]
Re: [net-next v4 4/5] net: mtip: The L2 switch driver for imx287
In reply to Lukasz MajewskiHi Lukasz,
thanks for sending this to linux-arm-kernel
Am 07.04.25 um 16:51 schrieb Lukasz Majewski:
Quoted 146 lines
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).Signed-off-by Lukasz Majewski<[email protected]>---
Changes for v2:- Remove not needed comments
- Restore udelay(10) for switch reset (such delay is explicitly specifed in the documentation
- AddCOMPILE_TEST
- replace pr_* with dev_*
- Usefor_each_available_child_of_node_scoped()
- Use devm_* function for memory allocation
- Remove printing information about the HW and SW revision of the driver
- Usedevm_regulator_get_optional()
- Change compatible prefix from 'fsl' to more up to date 'nxp'
- Remove .owner =THIS_MODULE
- Usedevm_platform_ioremap_resource(pdev, 0);
- Usedevm_request_irq()
- Usedevm_regulator_get_enable_optional()
- Replaceclk_prepare_enable()anddevm_clk_get()with single call todevm_clk_get_optional_enabled()
- Cleanup error patch when function calls in probe fail
- Refactor themtip_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 atesw_mac_addr_static()
- Removemtip_print_link_status()and replace it withphy_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 removemtip_ndev_setup()
- Use-ENOMEMinstead of -1 return code when allocation fails
- Replacedev_info()withdev_dbg()to reduce number of information print on normal operation
- Return ret instead of 0 frommtip_ndev_init()
- Removefep->mii_timeoutflag from the driver
- Remove not used stop_gpr_* fields inmtip_devinfostruct
- Removeplatform_device_iddescription for mtipl2sw driver
- AddMODULE_DEVICE_TABLE()formtip_of_match
- RemoveMODULE_ALIAS()Changes for v4:
- Rename imx287 with imx28 (as the former is not used in kernel anymore)
- Reorder the place where ENET interface is initialized - without this change theenet_outclock has default (25 MHz) value, which causes issues during reset (RMII's 50 MHz is required for proper PHY reset).
- Use PAUR instead of PAUR register to program MAC address
- Replaceeth_mac_addr()witheth_hw_addr_set()
- Write to HW the randomly generated MAC address (if required)
- Adjust the reset code
- s/read_atable/mtip_read_atable/g and s/write_atable/mtip_write_atable/g
- Addclk_disable()andnetif_napi_del()when errors occur duringmtip_open()- refactor the error handling path.
- Refactor themtip_set_multicast_list()to write (now) correct values to ENET-FEC registers.
- Replacedev_warn()withdev_err()
- UseGPIO_ACTIVE_LOWto indicate polarity in DTS
- Refactor code to check if network device is the switch device
- Removemtip_port_dev_check()
- Refactormtip_ndev_port_link()avoid starting HW offloading for bridge when MTIP ports are parts of two distinct bridges
- Replacedel_timer()withtimer_delete_sync()--- 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 | 1970 +++++++++++++++++ .../net/ethernet/freescale/mtipsw/mtipl2sw.h | 782 +++++++ .../ethernet/freescale/mtipsw/mtipl2sw_br.c | 122 + .../ethernet/freescale/mtipsw/mtipl2sw_mgnt.c | 449 ++++ 9 files changed, 3348 insertions(+)create mode 100644
drivers/net/ethernet/freescale/mtipsw/Kconfigcreate mode 100644drivers/net/ethernet/freescale/mtipsw/Makefilecreate mode 100644drivers/net/ethernet/freescale/mtipsw/mtipl2sw.ccreate mode 100644drivers/net/ethernet/freescale/mtipsw/mtipl2sw.hcreate mode 100644drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.ccreate mode 100644drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.cMAINTAINERS +7
-0@@ -9455,6 +9455,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,imx28-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@@ -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" diff --git a/drivers/net/ethernet/freescale/Makefileb/drivers/net/ethernet/freescale/Makefile index
de7b31842233..0e6cacb0948a100644 ---
a/drivers/net/ethernet/freescale/Makefile +++
b/drivers/net/ethernet/freescale/Makefile @@ -25,3 +25,4 @@
obj-$(CONFIG_FSL_DPAA_ETH) += dpaa/ obj-$(CONFIG_FSL_DPAA2_ETH) +=
dpaa2/ obj-y += enetc/ +obj-y += mtipsw/ diff --git a/drivers/net/ethernet/freescale/mtipsw/Kconfig
b/drivers/net/ethernet/freescale/mtipsw/Kconfig new file mode 100644
index 000000000000..450ff734a321 ---/dev/null+++ b/drivers/net/ethernet/freescale/mtipsw/Kconfig @@ -0,0 +1,13 @@ +#
SPDX-License-Identifier: GPL-2.0-only +configFEC_MTIP_L2SW+ tristate "MoreThanIP L2 switch support to FEC driver"
drivers/net/ethernet/freescale/Kconfig
Quoted 7 lines
drivers/net/ethernet/freescale/Kconfig +7
-0+ 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
This is confusing. The Kconfig and most of the code looks prepared for other platforms than i.MX28, but there is only a i.MX28 OF compatible. I don't like that Kconfig pretent something, which is not true.
Quoted 23 lines
drivers/net/ethernet/freescale/Kconfig +3
-0+ 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@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_FEC_MTIP_L2SW) += mtipl2sw.o mtipl2sw_mgnt.o mtipl2sw_br.odrivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +5
-0@@ -0,0 +1,1970 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* L2 switch Controller (Ethernet L2 switch) driver for MTIP block. +* +* Copyright (C) 2025 DENX Software Engineering GmbH
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 15
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+* Lukasz Majewski<[email protected]> +* +* Based on a previous work by: +* +* Copyright 2010-2012 Freescale Semiconductor, Inc. +* Alison Wang ([email protected]) +* Jason Jin ([email protected]) +* +* Copyright (C) 2010-2013 Freescale Semiconductor, Inc. All Rights Reserved. +* Shrek Wu ([email protected])
I'm not sure how to properly handle these old Freescale addresses, which are unlikely to work. A quick search suggests that some of these people may still working for NXP.
Quoted 16 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +16
-0+*/ + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/string.h> +#include <linux/errno.h> +#include <linux/iopoll.h> +#include <linux/slab.h> +#include <linux/interrupt.h> +#include <linux/init.h> +#include <linux/delay.h> +#include <linux/netdevice.h> +#include <linux/etherdevice.h> +#include <linux/skbuff.h> +#include <linux/spinlock.h> +#include <linux/bitops.h>
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 41
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+#include <linux/clk.h> +#include <linux/platform_device.h> +#include <linux/phy.h> +#include <linux/of_mdio.h> +#include <linux/gpio/consumer.h> +#include <linux/of_net.h> +#include <linux/of_platform.h> +#include <linux/rtnetlink.h> +#include <linux/regulator/consumer.h> +#include <linux/io.h>
Please order alphabetically
Quoted 7 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +7
-0+ +#include "mtipl2sw.h" + +#ifdef CONFIG_ARCH_MXS +static void *swap_buffer (void *bufaddr,int len) +{ +unsigned int *buf = bufaddr;
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 58
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+int i; + +for (i =0 ; i < (len +3 ) /4 ; i++, buf++) + *buf =__swab32 (*buf); + + return bufaddr; +} +#else +static void *swap_buffer (void *bufaddr,int len) {return NULL ; } +#endif
The fec driver also needs to handle this i.MX28 errata, but #ifdef isn't a proper solution. Please handle it as a quirk like in fec driver.
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 65
Quoted 7 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +7
-0+ +struct mtip_devinfo { +u32 quirks; +}; + +/* Last read entry from learning interface */ +struct mtip_port_info g_info;
Please avoid global variables. I don't see why this is necessary.
Quoted 19 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +19
-0+ +static void mtip_enet_init (struct switch_enet_private *fep,int port) +{ +void __iomem *enet_addr = fep->enet_addr; +u32 mii_speed, holdtime, tmp; + +if (port ==2 ) + enet_addr +=MCF_ESW_ENET_PORT_OFFSET ; + + tmp =MCF_FEC_RCR_PROM |MCF_FEC_RCR_MII_MODE | +MCF_FEC_RCR_MAX_FL (1522 ); + +if (fep->phy_interface[port -1 ] ==PHY_INTERFACE_MODE_RMII ) + tmp |=MCF_FEC_RCR_RMII_MODE ; + +writel (tmp, enet_addr +MCF_FEC_RCR ); + +/* TCR */ +writel (MCF_FEC_TCR_FDEN , enet_addr +MCF_FEC_TCR );
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 94
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+ +/* ECR */ +writel (MCF_FEC_ECR_ETHER_EN , enet_addr +MCF_FEC_ECR ); + +/* Set MII speed to 2.5 MHz +*/ + mii_speed =DIV_ROUND_UP (clk_get_rate (fep->clk_ipg),5000000 ); + mii_speed--; + +/* The i.MX28 and i.MX6 types have another filed in the MSCR (aka
field ?
Quoted 39 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +39
-0+* MII_SPEED) register that defines the MDIO output hold time. Earlier +* versions are RAZ there, so just ignore the difference and write the +* register always. +* The minimal hold time according to IEE802.3 (clause 22) is 10 ns. +* HOLDTIME + 1 is the number of clk cycles the fec is holding the +* output. +* The HOLDTIME bitfield takes values between 0 and 7 (inclusive). +* Given that ceil(clkrate / 5000000) <= 64, the calculation for +* holdtime cannot result in a value greater than 3. +*/ + holdtime =DIV_ROUND_UP (clk_get_rate (fep->clk_ipg),100000000 ) -1 ; + + fep->phy_speed = mii_speed <<1 | holdtime <<8 ; + +writel (fep->phy_speed, enet_addr +MCF_FEC_MSCR ); +} + +static int mtip_setup_mac (struct net_device *dev) +{ +struct mtip_ndev_priv *priv =netdev_priv (dev); +struct switch_enet_private *fep = priv->fep; +unsigned char *iap, tmpaddr[ETH_ALEN ]; + +/* Use MAC address from DTS */ + iap = &fep->mac[priv->portnum -1 ][0 ]; + +/* Use MAC address set by bootloader */ +if (!is_valid_ether_addr (iap)) { + *((unsigned long *)&tmpaddr[0 ]) = +be32_to_cpu (readl (fep->enet_addr +MCF_FEC_PALR )); + *((unsigned short *)&tmpaddr[4 ]) = +be16_to_cpu (readl (fep->enet_addr + +MCF_FEC_PAUR ) >>16 ); + iap = &tmpaddr[0 ]; + } + +/* Use random MAC address */ +if (!is_valid_ether_addr (iap)) { +eth_hw_addr_random (dev);
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 143
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+dev_info (&fep->pdev->dev,"Using random MAC address: %pM\n" , + dev->dev_addr); + iap = (unsigned char *)dev->dev_addr; + } + +/* Adjust MAC if using macaddr (and increment if needed) */ +eth_hw_addr_gen (dev, iap, priv->portnum -1 ); + +return 0 ; +}
Why does this function has a return value, but it always returns 0 ?
Quoted 129 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +129
-0+ +/** +* crc8_calc - calculate CRC for MAC storage +* +* @pmacaddress: A 6-byte array with the MAC address. The first byte is +* the first byte transmitted. +* +* Calculate Galois Field Arithmetic CRC for Polynom x^8+x^2+x+1. +* It omits the final shift in of 8 zeroes a "normal" CRC would do +* (getting the remainder). +* +* Examples (hexadecimal values):<br> +* 10-11-12-13-14-15 => CRC=0xc2 +* 10-11-cc-dd-ee-00 => CRC=0xe6 +* +* Return: The 8-bit CRC in bits 7:0 +*/ +static int crc8_calc (unsigned char *pmacaddress) +{ +int byt;/* byte index */ +int bit;/* bit index */ +int crc =0x12 ; +int inval; + +for (byt =0 ; byt <6 ; byt++) { + inval = (((int )pmacaddress[byt]) &0xff ); +/* shift bit 0 to bit 8 so all our bits +* travel through bit 8 +* (simplifies below calc) +*/ + inval <<=8 ; + +for (bit =0 ; bit <8 ; bit++) { +/* next input bit comes into d7 after shift */ + crc |= inval &0x100 ; +if (crc &0x01 ) +/* before shift */ + crc ^=0x1c0 ; + + crc >>=1 ; + inval >>=1 ; + } + } +/* upper bits are clean as we shifted in zeroes! */ +return crc; +} + +static void mtip_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 ); +} + +static void mtip_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 ); +} + +/** +* mtip_portinfofifo_read - Read element from receive FIFO +* +* @fep: Structure describing switch +* +* Read one element from the HW receive FIFO (Queue) +* if available and return it. +* +* Return: mtip_port_info or NULL if no data is available. +*/ +static +struct mtip_port_info *mtip_portinfofifo_read (struct switch_enet_private *fep) +{ +struct switch_t *fecp = fep->hwp; +u32 tmp; + + tmp =readl (&fecp->ESW_LSR); +if (tmp ==0 ) { +dev_dbg (&fep->pdev->dev,"%s: ESW_LSR = 0x%x\n" , __func__, tmp); +return NULL ; + } + +/* read word from FIFO */ + g_info.maclo =readl (&fecp->ESW_LREC0); +if (g_info.maclo ==0 ) { +dev_dbg (&fep->pdev->dev,"%s: mac lo 0x%x\n" , __func__, + g_info.maclo); +return NULL ; + } + +/* read 2nd word from FIFO */ + tmp =readl (&fecp->ESW_LREC1); + g_info.machi = tmp &0xffff ; + g_info.hash = (tmp >>16 ) &0xff ; + g_info.port = (tmp >>24 ) &0xf ; + +return &g_info; +} + +static int mtip_atable_get_entry_port_number (struct switch_enet_private *fep, +unsigned char *mac_addr,u8 *port) +{ +int block_index, block_index_end, entry; +unsigned long mac_addr_lo, mac_addr_hi; +unsigned long read_lo, read_hi; + + mac_addr_lo = (unsigned long )((mac_addr[3 ] <<24 ) | + (mac_addr[2 ] <<16 ) | + (mac_addr[1 ] <<8 ) | mac_addr[0 ]); + mac_addr_hi = (unsigned long )((mac_addr[5 ] <<8 ) | (mac_addr[4 ])); + + block_index =GET_BLOCK_PTR (crc8_calc (mac_addr)); + block_index_end = block_index +ATABLE_ENTRY_PER_SLOT ; + +/* now search all the entries in the selected block */ +for (entry = block_index; entry < block_index_end; entry++) { +mtip_read_atable (fep, entry, &read_lo, &read_hi); + *port =0xff ; + +if (read_lo == mac_addr_lo && + ((read_hi &0x0000ffff ) == + (mac_addr_hi &0x0000ffff ))) { +/* found the correct address */ +if ((read_hi & (1 <<16 )) && (!(read_hi & (1 <<17 ))))
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 282
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+ *port =AT_EXTRACT_PORT (read_hi); +break ; + } + } + +dev_dbg (&fep->pdev->dev,"%s: MAC: %pM PORT: 0x%x\n" , __func__, + mac_addr, *port); + +return 0 ; +}
ditto
Quoted 70 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +70
-0+ +/* Clear complete MAC Look Up Table */ +void mtip_clear_atable (struct switch_enet_private *fep) +{ +int index; + +for (index =0 ; index <2048 ; index++) +mtip_write_atable (fep, index,0 ,0 ); +} + +/** +* mtip_update_atable_static - Update switch static address table +* +* @mac_addr: Pointer to the array containing MAC address to +* be put as static entry +* @port: Port bitmask numbers to be added in static entry, +* valid values are 1-7 +* @priority: The priority for the static entry in table +* +* Updates MAC address lookup table with a static entry. +* +* Searches if the MAC address is already there in the block and replaces +* the older entry with the new one. If MAC address is not there then puts +* a new entry in the first empty slot available in the block. +* +* Return: 0 for a successful update else -ENOSPC when no slot available +*/ +static int mtip_update_atable_static (unsigned char *mac_addr,unsigned int port, +unsigned int priority, +struct switch_enet_private *fep) +{ +unsigned long block_index, entry, index_end; +unsigned long write_lo, write_hi; +unsigned long read_lo, read_hi; + + write_lo = (unsigned long )((mac_addr[3 ] <<24 ) | + (mac_addr[2 ] <<16 ) | + (mac_addr[1 ] <<8 ) | + mac_addr[0 ]); + write_hi = (unsigned long )(0 | (port << AT_SENTRY_PORTMASK_shift) | + (priority << AT_SENTRY_PRIO_shift) | + (AT_ENTRY_TYPE_STATIC << + AT_ENTRY_TYPE_shift) | + (AT_ENTRY_RECORD_VALID << + AT_ENTRY_VALID_shift) | + (mac_addr[5 ] <<8 ) | (mac_addr[4 ])); + + block_index =GET_BLOCK_PTR (crc8_calc (mac_addr)); + index_end = block_index +ATABLE_ENTRY_PER_SLOT ; +/* Now search all the entries in the selected block */ +for (entry = block_index; entry < index_end; entry++) { +mtip_read_atable (fep, entry, &read_lo, &read_hi); +/* MAC address matched, so update the +* existing entry +* even if its a dynamic one +*/ +if (read_lo == write_lo && + ((read_hi &0x0000ffff ) == + (write_hi &0x0000ffff ))) { +mtip_write_atable (fep, entry, write_lo, write_hi); +return 0 ; + }else if (!(read_hi & (1 <<16 ))) { +/* Fill this empty slot (valid bit zero), +* assuming no holes in the block +*/ +mtip_write_atable (fep, entry, write_lo, write_hi); + fep->at_curr_entries++; +return 0 ; + } + }
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 362
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+ +/* No space available for this static entry */ +return -ENOSPC ; +} + +static int mtip_update_atable_dynamic1 (unsigned long write_lo, +unsigned long write_hi,int block_index, +unsigned int port, +unsigned int curr_time, +struct switch_enet_private *fep)
Looks like the return type should be bool ?
Quoted 46 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +46
-0+{ +unsigned long entry, index_end; +unsigned long read_lo, read_hi; +int time, timeold, indexold; +unsigned long tmp; + +/* prepare update port and timestamp */ + tmp =AT_ENTRY_RECORD_VALID << AT_ENTRY_VALID_shift; + tmp |=AT_ENTRY_TYPE_DYNAMIC << AT_ENTRY_TYPE_shift; + tmp |= curr_time << AT_DENTRY_TIME_shift; + tmp |= port << AT_DENTRY_PORT_shift; + tmp |= write_hi; + +/* linear search through all slot +* entries and update if found +*/ + index_end = block_index +ATABLE_ENTRY_PER_SLOT ; +/* Now search all the entries in the selected block */ +for (entry = block_index; entry < index_end; entry++) { +mtip_read_atable (fep, entry, &read_lo, &read_hi); +if (read_lo == write_lo && + ((read_hi &0x0000ffff ) == + (write_hi &0x0000ffff ))) { +/* found correct address, +* update timestamp. +*/ +mtip_write_atable (fep, entry, write_lo, tmp); + +return 0 ; + }else if (!(read_hi & (1 <<16 ))) { +/* slot is empty, then use it +* for new entry +* Note: There are no holes, +* therefore cannot be any +* more that need to be compared. +*/ +mtip_write_atable (fep, entry, write_lo, tmp); +/* statistics (we do it between writing +* .hi an .lo due to +* hardware limitation... +*/ + fep->at_curr_entries++; +/* newly inserted */ + +return 1 ; + }
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 418
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+ } + +/* No more entry available in block overwrite oldest */ + timeold =0 ; + indexold =0 ; +for (entry = block_index; entry < index_end; entry++) { +mtip_read_atable (fep, entry, &read_lo, &read_hi); + time =AT_EXTRACT_TIMESTAMP (read_hi); +dev_err (&fep->pdev->dev,"%s : time %x currtime %x\n" , + __func__, time, curr_time);
This doesn't look a like a helpful error message. The fact it's within a for loop, makes it even worse.
Quoted 19 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +19
-0+ time =TIMEDELTA (curr_time, time); +if (time > timeold) { +/* is it older ? */ + timeold = time; + indexold = entry; + } + } + +mtip_write_atable (fep, indexold, write_lo, tmp); + +/* Statistics (do it inbetween writing to .lo and .hi */ + fep->at_block_overflows++; +dev_err (&fep->pdev->dev,"%s update time, at_block_overflows %x\n" , + __func__, fep->at_block_overflows); +/* newly inserted */ +return 1 ; +} + +/* dynamicms MAC address table learn and migration */
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 447
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+static int +mtip_atable_dynamicms_learn_migration (struct switch_enet_private *fep, +int curr_time,unsigned char *mac, +u8 *rx_port) +{ +unsigned long rx_mac_lo, rx_mac_hi; +struct mtip_port_info *port_info; +int index, inserted =0 ; +unsigned long flags; +u8 port =0xFF ;
Sometimes the code uses capital letter and sometimes small letter for hex, please keep it consistent.
Quoted 26 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +26
-0+ +spin_lock_irqsave (&fep->learn_lock, flags); + +if (mac &&is_valid_ether_addr (mac)) { + rx_mac_lo = (unsigned long )((mac[3 ] <<24 ) | (mac[2 ] <<16 ) | + (mac[1 ] <<8 ) | mac[0 ]); + rx_mac_hi = (unsigned long )((mac[5 ] <<8 ) | (mac[4 ])); + } + + port_info =mtip_portinfofifo_read (fep); +while (port_info) { +/* get block index from lookup table */ + index =GET_BLOCK_PTR (port_info->hash); + inserted =mtip_update_atable_dynamic1 (port_info->maclo, + port_info->machi, + index, + port_info->port, + curr_time, fep); + +if (mac &&is_valid_ether_addr (mac) && port ==0xFF ) { +if (rx_mac_lo == port_info->maclo && + rx_mac_hi == port_info->machi) { +/* The newly learned MAC is the source of +* our filtered frame. +*/ + port = (u8 )port_info->port;
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 483
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+ } + } + port_info =mtip_portinfofifo_read (fep); + } + +if (rx_port) + *rx_port = port; + +spin_unlock_irqrestore (&fep->learn_lock, flags); +return 0 ;
Either there should be some kind of error handling within this function or the return code should be dropped.
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 486
Quoted 3 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +3
-0+} + +/* The timer should create an interrupt every 4 seconds*/
Does this comment still apply? I suggest to drop it.
Quoted 22 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +22
-0+static void mtip_aging_timer (struct timer_list *t) +{ +struct switch_enet_private *fep =from_timer (fep, t, timer_aging); + +if (fep) + fep->curr_time =mtip_timeincrement (fep->curr_time); + +mod_timer (&fep->timer_aging, + jiffies +msecs_to_jiffies (LEARNING_AGING_INTERVAL )); +} + +static void esw_mac_addr_static (struct switch_enet_private *fep) +{ +int i; + +for (i =0 ; i <SWITCH_EPORT_NUMBER ; i++) +mtip_update_atable_static ((unsigned char *) + fep->ndev[i]->dev_addr,7 ,7 , fep); +} + +static void mtip_config_switch (struct switch_enet_private *fep) +{
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 518
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+struct switch_t *fecp = fep->hwp; + +esw_mac_addr_static (fep); + +writel (0 , &fecp->ESW_BKLR); + +/* Do NOT disable learning */ +mtip_port_learning_config (fep,0 ,0 ,0 ); +mtip_port_learning_config (fep,1 ,0 ,0 ); +mtip_port_learning_config (fep,2 ,0 ,0 );
Looks like the last 2 parameter are always 0?
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 523
Quoted 5 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +5
-0+ +/* Disable blocking */ +mtip_port_blocking_config (fep,0 ,0 ); +mtip_port_blocking_config (fep,1 ,0 ); +mtip_port_blocking_config (fep,2 ,0 );
Looks like the last parameter is always 0?
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 530
Quoted 7 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +7
-0+ +writel (MCF_ESW_IMR_TXF |MCF_ESW_IMR_RXF , + &fecp->ESW_IMR); + +mtip_port_enable_config (fep,0 ,1 ,1 ); +mtip_port_enable_config (fep,1 ,1 ,1 ); +mtip_port_enable_config (fep,2 ,1 ,1 );
Looks like the last 2 parameter are always 1?
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 534
Quoted 4 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +4
-0+ +mtip_port_broadcast_config (fep,0 ,1 ); +mtip_port_broadcast_config (fep,1 ,1 ); +mtip_port_broadcast_config (fep,2 ,1 );
Looks like the last parameter is always 1?
Quoted 69 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +69
-0+ +/* Disable multicast receive on port 0 (MGNT) */ +mtip_port_multicast_config (fep,0 ,0 ); +mtip_port_multicast_config (fep,1 ,1 ); +mtip_port_multicast_config (fep,2 ,1 ); + +/* Setup VLANs to provide port separation */ +if (!fep->br_offload) +mtip_switch_en_port_separation (fep); +} + +static netdev_tx_t mtip_start_xmit_port (struct sk_buff *skb, +struct net_device *dev,int port) +{ +struct mtip_ndev_priv *priv =netdev_priv (dev); +struct switch_enet_private *fep = priv->fep; +struct switch_t *fecp = fep->hwp; +unsigned short status; +unsigned long flags; +struct cbd_t *bdp; +void *bufaddr; + +spin_lock_irqsave (&fep->hw_lock, flags); + +if (!fep->link[0 ] && !fep->link[1 ]) { +/* Link is down or autonegotiation is in progress. */ +netif_stop_queue (dev); +spin_unlock_irqrestore (&fep->hw_lock, flags); +return NETDEV_TX_BUSY ; + } + +/* Fill in a Tx ring entry */ + bdp = fep->cur_tx; + + status = bdp->cbd_sc; + +if (status &BD_ENET_TX_READY ) { +/* All transmit buffers are full. Bail out. +* This should not happen, since dev->tbusy should be set. +*/ +dev_err (&fep->pdev->dev,"%s: tx queue full!.\n" , dev->name); +spin_unlock_irqrestore (&fep->hw_lock, flags); +return NETDEV_TX_BUSY ; + } + +/* Clear all of the status flags */ + status &= ~BD_ENET_TX_STATS ; + +/* Set buffer length and buffer pointer */ + bufaddr = skb->data; + bdp->cbd_datlen = skb->len; + +/* On some FEC implementations data must be aligned on +* 4-byte boundaries. Use bounce buffers to copy data +* and get it aligned. +*/ +if ((unsigned long )bufaddr &MTIP_ALIGNMENT ) { +unsigned int index; + + index = bdp - fep->tx_bd_base; +memcpy (fep->tx_bounce[index], + (void *)skb->data, skb->len); + bufaddr = fep->tx_bounce[index]; + } + +swap_buffer (bufaddr, skb->len); + +/* Save skb pointer. */ + fep->tx_skbuff[fep->skb_cur] = skb;
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 613
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+ + dev->stats.tx_bytes += skb->len; + fep->skb_cur = (fep->skb_cur +1 ) &TX_RING_MOD_MASK ; + +/* Push the data cache so the CPM does not get stale memory +* data. +*/ + bdp->cbd_bufaddr =dma_map_single (&fep->pdev->dev, bufaddr, +MTIP_SWITCH_TX_FRSIZE , +DMA_TO_DEVICE );
I would expect some kind of error handling here (e.g. dma_mapping_error ).
Quoted 63 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +63
-0+ +/* Send it on its way. Tell FEC it's ready, interrupt when done, +* it's the last BD of the frame, and to put the CRC on the end. +*/ + + status |= (BD_ENET_TX_READY |BD_ENET_TX_INTR + |BD_ENET_TX_LAST |BD_ENET_TX_TC ); + bdp->cbd_sc = status; + +netif_trans_update (dev); +skb_tx_timestamp (skb); + +/* For port separation - force sending via specified port */ +if (!fep->br_offload && port !=0 ) +mtip_forced_forward (fep, port,1 ); + +/* Trigger transmission start */ +writel (MCF_ESW_TDAR_X_DES_ACTIVE , &fecp->ESW_TDAR); + +/* If this was the last BD in the ring, +* start at the beginning again. +*/ +if (status &BD_ENET_TX_WRAP ) + bdp = fep->tx_bd_base; +else + bdp++; + +if (bdp == fep->dirty_tx) { + fep->tx_full =1 ; +netif_stop_queue (dev); + } + + fep->cur_tx = bdp; +spin_unlock_irqrestore (&fep->hw_lock, flags); + +return NETDEV_TX_OK ; +} + +static netdev_tx_t mtip_start_xmit (struct sk_buff *skb, +struct net_device *dev) +{ +struct mtip_ndev_priv *priv =netdev_priv (dev); + +return mtip_start_xmit_port (skb, dev, priv->portnum); +} + +static void mtip_configure_enet_mii (struct switch_enet_private *fep,int port) +{ +struct phy_device *phydev = fep->phy_dev[port -1 ]; +struct net_device *dev = fep->ndev[port -1 ]; +void __iomem *enet_addr = fep->enet_addr; +int duplex = fep->full_duplex[port -1 ]; +u32 tmp; + +if (port ==2 ) + enet_addr +=MCF_ESW_ENET_PORT_OFFSET ; + +/* ECR */ +writel (MCF_FEC_ECR_MAGIC_ENA , enet_addr +MCF_FEC_ECR ); + +/* EMRBR */ +writel (PKT_MAXBLR_SIZE , enet_addr +MCF_FEC_EMRBR ); +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 686
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+/* set the receive and transmit BDs ring base to +* hardware registers(ERDSR & ETDSR) +*/ +writel (fep->bd_dma, enet_addr +MCF_FEC_ERDSR ); +writel ((unsigned long )fep->bd_dma +sizeof (struct cbd_t ) *RX_RING_SIZE , + enet_addr +MCF_FEC_ETDSR ); + +#ifdef CONFIG_ARCH_MXS +writel (fep->phy_speed, enet_addr +MCF_FEC_MSCR ); +#endif
Please handle it via quirk / platform data, not #ifdef
Quoted 132 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +132
-0+/* EIR */ +writel (0 , enet_addr +MCF_FEC_EIR ); + +/* IAUR */ +writel (0 , enet_addr +MCF_FEC_IAUR ); + +/* IALR */ +writel (0 , enet_addr +MCF_FEC_IALR ); + +/* GAUR */ +writel (0 , enet_addr +MCF_FEC_GAUR ); + +/* GALR */ +writel (0 , enet_addr +MCF_FEC_GALR ); + +/* EMRBR */ +writel (PKT_MAXBLR_SIZE , enet_addr +MCF_FEC_EMRBR ); + +/* EIMR */ +writel (0 , enet_addr +MCF_FEC_EIMR ); + +/* PALR PAUR */ +/* Set the station address for the ENET Adapter */ +writel (dev->dev_addr[3 ] | + dev->dev_addr[2 ] <<8 | + dev->dev_addr[1 ] <<16 | + dev->dev_addr[0 ] <<24 , enet_addr +MCF_FEC_PALR ); +writel (dev->dev_addr[5 ] <<16 | + (dev->dev_addr[4 ] + (unsigned char )(0 )) <<24 , + enet_addr +MCF_FEC_PAUR ); + +/* RCR */ + tmp =readl (enet_addr +MCF_FEC_RCR ); +if (phydev && phydev->speed ==SPEED_100 ) + tmp &= ~MCF_FEC_RCR_RMII_10BASET ; +else + tmp |=MCF_FEC_RCR_RMII_10BASET ; + +if (duplex ==DUPLEX_FULL ) + tmp &= ~MCF_FEC_RCR_DRT ; +else + tmp |=MCF_FEC_RCR_DRT ; + +writel (tmp, enet_addr +MCF_FEC_RCR ); + +/* TCR */ +if (duplex ==DUPLEX_FULL ) +writel (0x1c , enet_addr +MCF_FEC_TCR ); +else +writel (0x18 , enet_addr +MCF_FEC_TCR ); + +/* ECR */ +writel (readl (enet_addr +MCF_FEC_ECR ) |MCF_FEC_ECR_ETHER_EN , + enet_addr +MCF_FEC_ECR ); +} + +/* This function is called to start or restart the FEC during a link +* change. This only happens when switching between half and full +* duplex. +*/ +static void mtip_switch_restart (struct net_device *dev,int duplex0, +int duplex1) +{ +struct mtip_ndev_priv *priv =netdev_priv (dev); +struct switch_enet_private *fep = priv->fep; +struct switch_t *fecp = fep->hwp; +int i; + +/* Perform a reset. We should wait for this. */ +writel (MCF_ESW_MODE_SW_RST , &fecp->ESW_MODE); + +/* Delay of 10us specified in the documentation to perform +* SW reset by the switch internally. +*/ +udelay (10 ); +writel (MCF_ESW_MODE_STATRST , &fecp->ESW_MODE); +writel (MCF_ESW_MODE_SW_EN , &fecp->ESW_MODE); + +/* Management port configuration, +* make port 0 as management port +*/ +writel (0 , &fecp->ESW_BMPC); + +/* Clear any outstanding interrupt */ +writel (0xffffffff , &fecp->ESW_ISR); + +/* Set backpressure threshold to minimize discarded frames +* during due to congestion. +*/ +writel (P0BC_THRESHOLD , &fecp->ESW_P0BCT); + +/* Set maximum receive buffer size */ +writel (PKT_MAXBLR_SIZE , &fecp->ESW_MRBR); + +/* Set receive and transmit descriptor base */ +writel (fep->bd_dma, &fecp->ESW_RDSR); +writel ((unsigned long )fep->bd_dma + +sizeof (struct cbd_t ) *RX_RING_SIZE , + &fecp->ESW_TDSR); + + fep->cur_tx = fep->tx_bd_base; + fep->cur_rx = fep->rx_bd_base; + fep->dirty_tx = fep->cur_tx; + +/* Reset SKB transmit buffers */ + fep->skb_cur =0 ; + fep->skb_dirty =0 ; +for (i =0 ; i <=TX_RING_MOD_MASK ; i++) { +if (fep->tx_skbuff[i]) { +dev_kfree_skb_any (fep->tx_skbuff[i]); + fep->tx_skbuff[i] =NULL ; + } + } + + fep->full_duplex[0 ] = duplex0; + fep->full_duplex[1 ] = duplex1; + +mtip_configure_enet_mii (fep,1 ); +mtip_configure_enet_mii (fep,2 ); +mtip_clear_atable (fep); + +/* And last, enable the transmit and receive processing */ +writel (MCF_ESW_RDAR_R_DES_ACTIVE , &fecp->ESW_RDAR); + +/* Enable interrupts we wish to service */ +writel (0xffffffff , &fecp->ESW_ISR); +writel (MCF_ESW_IMR_TXF |MCF_ESW_IMR_RXF , + &fecp->ESW_IMR); + +mtip_config_switch (fep); +} +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 828
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+static void mtip_timeout (struct net_device *dev,unsigned int txqueue) +{ +struct mtip_ndev_priv *priv =netdev_priv (dev); +struct switch_enet_private *fep = priv->fep; +#ifdef SWITCH_DEBUG +struct cbd_t *bdp; +int i; +#endif + dev->stats.tx_errors++; +#ifdef SWITCH_DEBUG
Please try to get the rid of these #ifdef. IS_ENABLED() ?
Quoted 53 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +53
-0+dev_info (&dev->dev,"%s: transmit timed out.\n" , dev->name); +dev_info (&dev->dev, +"Ring data dump: cur_tx %lx%s, dirty_tx %lx cur_rx: %lx\n" , + (unsigned long )fep->cur_tx, fep->tx_full ?" (full)" :"" , + (unsigned long )fep->dirty_tx, + (unsigned long )fep->cur_rx); + + bdp = fep->tx_bd_base; +dev_info (&dev->dev," tx: %u buffers\n" ,TX_RING_SIZE ); +for (i =0 ; i <TX_RING_SIZE ; i++) { +dev_info (&dev->dev," %08x: %04x %04x %08x\n" , + (uint )bdp, bdp->cbd_sc, bdp->cbd_datlen, + (int )bdp->cbd_bufaddr); + bdp++; + } + + bdp = fep->rx_bd_base; +dev_info (&dev->dev," rx: %lu buffers\n" , + (unsigned long )RX_RING_SIZE ); +for (i =0 ; i <RX_RING_SIZE ; i++) { +dev_info (&dev->dev," %08x: %04x %04x %08x\n" , (uint )bdp, + bdp->cbd_sc, bdp->cbd_datlen, + (int )bdp->cbd_bufaddr); + bdp++; + } +#endif + +rtnl_lock (); +if (netif_device_present (dev) ||netif_running (dev)) { +napi_disable (&fep->napi); +netif_tx_lock_bh (dev); +mtip_switch_restart (dev, fep->full_duplex[0 ], + fep->full_duplex[1 ]); +netif_tx_wake_all_queues (dev); +netif_tx_unlock_bh (dev); +napi_enable (&fep->napi); + } +rtnl_unlock (); +} + +static irqreturn_t mtip_interrupt (int irq,void *ptr_fep) +{ +struct switch_enet_private *fep = ptr_fep; +struct switch_t *fecp = fep->hwp; +irqreturn_t ret =IRQ_NONE ; +u32 int_events, int_imask; + +/* Get the interrupt events that caused us to be here */ + do { + int_events = readl(&fecp->ESW_ISR); + writel(int_events, &fecp->ESW_ISR); + + if (int_events & (MCF_ESW_ISR_RXF | MCF_ESW_ISR_TXF)) {
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 891
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+ ret =IRQ_HANDLED ; +/* Disable the RX interrupt */ +if (napi_schedule_prep (&fep->napi)) { + int_imask =readl (&fecp->ESW_IMR); + int_imask &= ~MCF_ESW_IMR_RXF ; +writel (int_imask, &fecp->ESW_IMR); +__napi_schedule (&fep->napi); + } + } + }while (int_events);
This looks bad, in case of bad hardware / timing behavior this interrupt handler will loop forever.
Quoted 103 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +103
-0+ +return ret; +} + +static void mtip_switch_tx (struct net_device *dev) +{ +struct mtip_ndev_priv *priv =netdev_priv (dev); +struct switch_enet_private *fep = priv->fep; +unsigned short status; +struct sk_buff *skb; +unsigned long flags; +struct cbd_t *bdp; + +spin_lock_irqsave (&fep->hw_lock, flags); + bdp = fep->dirty_tx; + +while (((status = bdp->cbd_sc) &BD_ENET_TX_READY ) ==0 ) { +if (bdp == fep->cur_tx && fep->tx_full ==0 ) +break ; + +dma_unmap_single (&fep->pdev->dev, bdp->cbd_bufaddr, +MTIP_SWITCH_TX_FRSIZE ,DMA_TO_DEVICE ); + bdp->cbd_bufaddr =0 ; + skb = fep->tx_skbuff[fep->skb_dirty]; +/* Check for errors */ +if (status & (BD_ENET_TX_HB |BD_ENET_TX_LC | +BD_ENET_TX_RL |BD_ENET_TX_UN | +BD_ENET_TX_CSL )) { + dev->stats.tx_errors++; +if (status &BD_ENET_TX_HB )/* No heartbeat */ + dev->stats.tx_heartbeat_errors++; +if (status &BD_ENET_TX_LC )/* Late collision */ + dev->stats.tx_window_errors++; +if (status &BD_ENET_TX_RL )/* Retrans limit */ + dev->stats.tx_aborted_errors++; +if (status &BD_ENET_TX_UN )/* Underrun */ + dev->stats.tx_fifo_errors++; +if (status &BD_ENET_TX_CSL )/* Carrier lost */ + dev->stats.tx_carrier_errors++; + }else { + dev->stats.tx_packets++; + } + +if (status &BD_ENET_TX_READY ) +dev_err (&fep->pdev->dev, +"Enet xmit interrupt and TX_READY.\n" ); + +/* Deferred means some collisions occurred during transmit, +* but we eventually sent the packet OK. +*/ +if (status &BD_ENET_TX_DEF ) + dev->stats.collisions++; + +/* Free the sk buffer associated with this last transmit */ +dev_consume_skb_irq (skb); + fep->tx_skbuff[fep->skb_dirty] =NULL ; + fep->skb_dirty = (fep->skb_dirty +1 ) &TX_RING_MOD_MASK ; + +/* Update pointer to next buffer descriptor to be transmitted */ +if (status &BD_ENET_TX_WRAP ) + bdp = fep->tx_bd_base; +else + bdp++; + +/* Since we have freed up a buffer, the ring is no longer +* full. +*/ +if (fep->tx_full) { + fep->tx_full =0 ; +if (netif_queue_stopped (dev)) +netif_wake_queue (dev); + } + } + fep->dirty_tx = bdp; +spin_unlock_irqrestore (&fep->hw_lock, flags); +} + +/* During a receive, the cur_rx points to the current incoming buffer. +* When we update through the ring, if the next incoming buffer has +* not been given to the system, we just set the empty indicator, +* effectively tossing the packet. +*/ +static int mtip_switch_rx (struct net_device *dev,int budget,int *port) +{ +struct mtip_ndev_priv *priv =netdev_priv (dev); +struct switch_enet_private *fep = priv->fep; +struct switch_t *fecp = fep->hwp; +unsigned short status, pkt_len; +struct net_device *pndev; +u8 *data, rx_port =0xFF ; +struct ethhdr *eth_hdr; +int pkt_received =0 ; +struct sk_buff *skb; +unsigned long flags; +struct cbd_t *bdp; + +spin_lock_irqsave (&fep->hw_lock, flags); + +/* First, grab all of the stats for the incoming packet. +* These get messed up if we get called due to a busy condition. +*/ + bdp = fep->cur_rx; +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1004
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+while (!((status = bdp->cbd_sc) &BD_ENET_RX_EMPTY )) { +if (pkt_received >= budget) +break ; + + pkt_received++; +/* Since we have allocated space to hold a complete frame, +* the last indicator should be set. +*/ +if ((status &BD_ENET_RX_LAST ) ==0 ) +dev_info (&dev->dev,"SWITCH ENET: rcv is not +last\n" );
This looks more like a warning than an info message. Btw this is within a loop, it should be limited via _once or _ratelimited .
Quoted 60 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +60
-0+ +if (!fep->usage_count) + goto rx_processing_done; + +/* Check for errors. */ +if (status & (BD_ENET_RX_LG |BD_ENET_RX_SH |BD_ENET_RX_NO | +BD_ENET_RX_CR |BD_ENET_RX_OV )) { + dev->stats.rx_errors++; +if (status & (BD_ENET_RX_LG |BD_ENET_RX_SH )) { +/* Frame too long or too short. */ + dev->stats.rx_length_errors++; + } +if (status &BD_ENET_RX_NO )/* Frame alignment */ + dev->stats.rx_frame_errors++; +if (status &BD_ENET_RX_CR )/* CRC Error */ + dev->stats.rx_crc_errors++; +if (status &BD_ENET_RX_OV )/* FIFO overrun */ + dev->stats.rx_fifo_errors++; + } + +/* Report late collisions as a frame error. +* On this error, the BD is closed, but we don't know what we +* have in the buffer. So, just drop this frame on the floor. +*/ +if (status &BD_ENET_RX_CL ) { + dev->stats.rx_errors++; + dev->stats.rx_frame_errors++; + goto rx_processing_done; + } + +/* Process the incoming frame */ + pkt_len = bdp->cbd_datlen; + data = (__u8 *)__va (bdp->cbd_bufaddr); + +dma_unmap_single (&fep->pdev->dev, bdp->cbd_bufaddr, + bdp->cbd_datlen,DMA_FROM_DEVICE ); + +swap_buffer (data, pkt_len); +if (data) { + eth_hdr = (struct ethhdr *)data; +mtip_atable_get_entry_port_number (fep, + eth_hdr->h_source, + &rx_port); +if (rx_port ==0xFF ) +mtip_atable_dynamicms_learn_migration (fep, + fep->curr_time, + eth_hdr->h_source, + &rx_port); + } + +if (!fep->br_offload && (rx_port ==1 || rx_port ==2 )) + pndev = fep->ndev[rx_port -1 ]; +else + pndev = dev; + + *port = rx_port; + pndev->stats.rx_packets++; + pndev->stats.rx_bytes += pkt_len; + +/* This does 16 byte alignment, exactly what we need.
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1074
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+* The packet length includes FCS, but we don't want to +* include that when passing upstream as it messes up +* bridging applications. +*/ + skb =netdev_alloc_skb (pndev, pkt_len +NET_IP_ALIGN ); +if (unlikely (!skb)) { +dev_dbg (&fep->pdev->dev, +"%s: Memory squeeze, dropping packet.\n" , + pndev->name); + pndev->stats.rx_dropped++;
Shouldn't we make sure that the loop is left under this circumstances?
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1085
Quoted 11 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +11
-0+ }else { +skb_reserve (skb,NET_IP_ALIGN ); +skb_put (skb, pkt_len);/* Make room */ +skb_copy_to_linear_data (skb, data, pkt_len); + skb->protocol =eth_type_trans (skb, pndev); +napi_gro_receive (&fep->napi, skb); + } + + bdp->cbd_bufaddr =dma_map_single (&fep->pdev->dev, data, + bdp->cbd_datlen, +DMA_FROM_DEVICE );
I would expect some kind of error handling here (e.g. dma_mapping_error ).
Quoted 94 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +94
-0+ + rx_processing_done: +/* Clear the status flags for this buffer */ + status &= ~BD_ENET_RX_STATS ; + +/* Mark the buffer empty */ + status |=BD_ENET_RX_EMPTY ; + bdp->cbd_sc = status; + +/* Update BD pointer to next entry */ +if (status &BD_ENET_RX_WRAP ) + bdp = fep->rx_bd_base; +else + bdp++; + +/* Doing this here will keep the FEC running while we process +* incoming frames. On a heavily loaded network, we should be +* able to keep up at the expense of system resources. +*/ +writel (MCF_ESW_RDAR_R_DES_ACTIVE , &fecp->ESW_RDAR); + }/* while (!((status = bdp->cbd_sc) & BD_ENET_RX_EMPTY)) */ + +writel (bdp, &fep->cur_rx); +spin_unlock_irqrestore (&fep->hw_lock, flags); + +return pkt_received; +} + +static void mtip_adjust_link (struct net_device *dev) +{ +struct mtip_ndev_priv *priv =netdev_priv (dev); +struct switch_enet_private *fep = priv->fep; +struct phy_device *phy_dev; +int status_change =0 , idx; +unsigned long flags; + +spin_lock_irqsave (&fep->hw_lock, flags); + + idx = priv->portnum -1 ; + phy_dev = fep->phy_dev[idx]; + +/* Duplex link change */ +if (phy_dev->link && fep->full_duplex[idx] != phy_dev->duplex) { +if (idx ==0 ) +mtip_switch_restart (dev, phy_dev->duplex, + fep->full_duplex[!idx]); +else +mtip_switch_restart (dev, fep->full_duplex[!idx], + phy_dev->duplex); + status_change =1 ; + } + +/* Link on or off change */ +if (phy_dev->link != fep->link[idx]) { + fep->link[idx] = phy_dev->link; +if (phy_dev->link) { +if (idx ==0 ) +mtip_switch_restart (dev, phy_dev->duplex, + fep->full_duplex[!idx]); +else +mtip_switch_restart (dev, fep->full_duplex[!idx], + phy_dev->duplex); +/* if link becomes up and tx be stopped, start it */ +if (netif_queue_stopped (dev)) { +netif_start_queue (dev); +netif_wake_queue (dev); + } + } + status_change =1 ; + } + +spin_unlock_irqrestore (&fep->hw_lock, flags); + +if (status_change) +phy_print_status (phy_dev); +} + +static int mtip_mdio_wait (struct switch_enet_private *fep) +{ +uint ievent =0 ; +int ret; + + ret =readl_poll_timeout_atomic (fep->enet_addr +MCF_FEC_EIR , ievent, + ievent &MCF_ENET_MII ,2 ,30000 ); +if (!ret) +writel (MCF_ENET_MII , fep->enet_addr +MCF_FEC_EIR ); + +return ret; +} + +static int mtip_mdio_read (struct mii_bus *bus,int mii_id,int regnum) +{ +struct switch_enet_private *fep = bus->priv; +int ret;
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1189
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+ +/* start a read op */ +writel (FEC_MMFR_ST |FEC_MMFR_OP_READ | +FEC_MMFR_PA (mii_id) |FEC_MMFR_RA (regnum) | +FEC_MMFR_TA , fep->enet_addr +MCF_FEC_MII_DATA ); + +/* wait for end of transfer */ + ret =mtip_mdio_wait (fep); +if (ret) { +dev_err (&fep->pdev->dev,"MTIP: MDIO read timeout\n" );
Not an expert, but does it make sense to provide more context here (e.g. mii_id, ...)?
Quoted 13 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +13
-0+return ret; + } + +/* return value */ +return FEC_MMFR_DATA (readl (fep->enet_addr +MCF_FEC_MII_DATA )); +} + +static int mtip_mdio_write (struct mii_bus *bus,int mii_id,int regnum, +u16 value) +{ +struct switch_enet_private *fep = bus->priv; +int ret; +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1212
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+/* start a write op */ +writel (FEC_MMFR_ST |FEC_MMFR_OP_WRITE | +FEC_MMFR_PA (mii_id) |FEC_MMFR_RA (regnum) | +FEC_MMFR_TA |FEC_MMFR_DATA (value), + fep->enet_addr +MCF_FEC_MII_DATA ); + +/* wait for end of transfer */ + ret =mtip_mdio_wait (fep); +if (ret) { +dev_err (&fep->pdev->dev,"MTIP: MDIO write timeout\n" );
dito
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1216
Quoted 4 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +4
-0+return ret; + } + +return 0 ;
I think we can make return ret here and drop the one before.
Quoted 115 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +115
-0+} + +static int mtip_mii_probe (struct net_device *dev) +{ +struct mtip_ndev_priv *priv =netdev_priv (dev); +struct switch_enet_private *fep = priv->fep; +struct phy_device *phy_dev =NULL ; +int port_idx = priv->portnum -1 ; + +if (fep->phy_np[port_idx]) { + phy_dev =of_phy_connect (dev, fep->phy_np[port_idx], + &mtip_adjust_link,0 , + fep->phy_interface[port_idx]); +if (!phy_dev) { +netdev_err (dev,"Unable to connect to phy\n" ); +return -ENODEV ; + } + } + +phy_set_max_speed (phy_dev,100 ); + fep->phy_dev[port_idx] = phy_dev; + fep->link[port_idx] =0 ; + fep->full_duplex[port_idx] =0 ; + +dev_dbg (&dev->dev, +"MTIP PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n" , + fep->phy_dev[port_idx]->drv->name, +phydev_name (fep->phy_dev[port_idx]), + fep->phy_dev[port_idx]->irq); + +return 0 ; +} + +static int mtip_mdiobus_reset (struct mii_bus *bus) +{ +if (!bus || !bus->reset_gpiod) { +dev_err (&bus->dev,"Reset GPIO pin not provided!\n" ); +return -EINVAL ; + } + +gpiod_set_value_cansleep (bus->reset_gpiod,0 ); + +/* Extra time to allow: +* 1. GPIO RESET pin go high to prevent situation where its value is +* "LOW" as it is NOT configured. +* 2. The ENET CLK to stabilize before GPIO RESET is asserted +*/ +usleep_range (200 ,300 ); + +gpiod_set_value_cansleep (bus->reset_gpiod,1 ); +usleep_range (bus->reset_delay_us, bus->reset_delay_us +1000 ); +gpiod_set_value_cansleep (bus->reset_gpiod,0 ); + +if (bus->reset_post_delay_us >0 ) +usleep_range (bus->reset_post_delay_us, + bus->reset_post_delay_us +1000 ); + +return 0 ; +} + +static int mtip_mii_init (struct switch_enet_private *fep, +struct platform_device *pdev) +{ +struct device_node *node; +int err = -ENXIO ; + +/* Clear MMFR to avoid to generate MII event by writing MSCR. +* MII event generation condition: +* - writing MSCR: +* - mmfr[31:0]_not_zero & mscr[7:0]_is_zero & +* mscr_reg_data_in[7:0] != 0 +* - writing MMFR: +* - mscr[7:0]_not_zero +*/ +writel (0 , fep->hwp +MCF_FEC_MII_DATA ); +/* Clear any pending transaction complete indication */ +writel (MCF_ENET_MII , fep->enet_addr +MCF_FEC_EIR ); + + fep->mii_bus =mdiobus_alloc (); +if (!fep->mii_bus) { + err = -ENOMEM ; + goto err_out; + } + + fep->mii_bus->name ="mtip_mii_bus" ; + fep->mii_bus->read = mtip_mdio_read; + fep->mii_bus->write = mtip_mdio_write; + fep->mii_bus->reset = mtip_mdiobus_reset; +snprintf (fep->mii_bus->id,MII_BUS_ID_SIZE ,"%x" ,0 ); + fep->mii_bus->priv = fep; + fep->mii_bus->parent = &pdev->dev; + + node =of_get_child_by_name (pdev->dev.of_node,"mdio" ); +if (node) +dev_err (&fep->pdev->dev,"%s: PHY name: %s\n" , + __func__, node->name); + + err =of_mdiobus_register (fep->mii_bus, node); +if (node) +of_node_put (node); +if (err) + goto err_out_free_mdiobus; + +return 0 ; + +err_out_free_mdiobus: +mdiobus_free (fep->mii_bus); +err_out: +return err; +} + +static void mtip_mii_remove (struct switch_enet_private *fep) +{ +int i; +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1341
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+for (i =0 ; i <SWITCH_EPORT_NUMBER ; i++) { +if (fep->phy_np[i]) +of_node_put (fep->phy_np[i]); + +if (fep->phy_dev[i]) +phy_disconnect (fep->phy_dev[i]); + } + +mdiobus_unregister (fep->mii_bus); +kfree (fep->mii_bus->irq);
This looks fishy. AFAIK this is a fixed array. Are you sure?
Quoted 51 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +51
-0+mdiobus_free (fep->mii_bus); +} + +static void mtip_get_drvinfo (struct net_device *dev, +struct ethtool_drvinfo *info) +{ +struct mtip_ndev_priv *priv =netdev_priv (dev); +struct switch_enet_private *fep = priv->fep; + +strscpy (info->driver, fep->pdev->dev.driver->name, +sizeof (info->driver)); +strscpy (info->bus_info,dev_name (&dev->dev), +sizeof (info->bus_info)); +} + +static void mtip_free_buffers (struct net_device *dev) +{ +struct mtip_ndev_priv *priv =netdev_priv (dev); +struct switch_enet_private *fep = priv->fep; +struct sk_buff *skb; +struct cbd_t *bdp; +int i; + + bdp = fep->rx_bd_base; +for (i =0 ; i <RX_RING_SIZE ; i++) { + skb = fep->rx_skbuff[i]; + +if (bdp->cbd_bufaddr) +dma_unmap_single (&fep->pdev->dev, bdp->cbd_bufaddr, +MTIP_SWITCH_RX_FRSIZE , +DMA_FROM_DEVICE ); +if (skb) +dev_kfree_skb (skb); + bdp++; + } + + bdp = fep->tx_bd_base; +for (i =0 ; i <TX_RING_SIZE ; i++) +kfree (fep->tx_bounce[i]); +} + +static int mtip_alloc_buffers (struct net_device *dev) +{ +struct mtip_ndev_priv *priv =netdev_priv (dev); +struct switch_enet_private *fep = priv->fep; +struct sk_buff *skb; +struct cbd_t *bdp; +int i; + + bdp = fep->rx_bd_base; +for (i =0 ; i <RX_RING_SIZE ; i++) {
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1402
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+ skb =netdev_alloc_skb (dev,MTIP_SWITCH_RX_FRSIZE ); +if (!skb) { +mtip_free_buffers (dev); +return -ENOMEM ; + } + fep->rx_skbuff[i] = skb; + + bdp->cbd_bufaddr =dma_map_single (&fep->pdev->dev, skb->data, +MTIP_SWITCH_RX_FRSIZE , +DMA_FROM_DEVICE );
I would expect some kind of error handling here (e.g. dma_mapping_error ).
Quoted 24 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +24
-0+ bdp->cbd_sc =BD_ENET_RX_EMPTY ; + bdp++; + } + +/* Set the last buffer to wrap. */ + bdp--; + bdp->cbd_sc |=BD_SC_WRAP ; + + bdp = fep->tx_bd_base; +for (i =0 ; i <TX_RING_SIZE ; i++) { + fep->tx_bounce[i] =kmalloc (MTIP_SWITCH_TX_FRSIZE ,GFP_KERNEL ); + + bdp->cbd_sc =0 ; + bdp->cbd_bufaddr =0 ; + bdp++; + } + +/* Set the last buffer to wrap. */ + bdp--; + bdp->cbd_sc |=BD_SC_WRAP ; + +return 0 ; +} +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1436
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+static int mtip_rx_napi (struct napi_struct *napi,int budget) +{ +struct mtip_ndev_priv *priv =netdev_priv (napi->dev); +struct switch_enet_private *fep = priv->fep; +struct switch_t *fecp = fep->hwp; +int pkts, port; + + pkts =mtip_switch_rx (napi->dev, budget, &port); +if (!fep->br_offload && + (port ==1 || port ==2 ) && fep->ndev[port -1 ])
(port > 0) && fep->ndev[port - 1])
Quoted 11 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +11
-0+mtip_switch_tx (fep->ndev[port -1 ]); + else + mtip_switch_tx(napi->dev); + +if (pkts < budget) { +napi_complete_done (napi, pkts); +/* Set default interrupt mask for L2 switch */ +writel (MCF_ESW_IMR_RXF |MCF_ESW_IMR_TXF , + &fecp->ESW_IMR); + } +return pkts;
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1457
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-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);
Yes, it's unlikely but this could fail
Quoted 73 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +73
-0+netif_napi_add (dev, &fep->napi, mtip_rx_napi); + + ret =mtip_alloc_buffers (dev); +if (ret) + goto mtip_alloc_buffers_err; + } + + 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) + goto mtip_mii_probe_err; + +phy_start (fep->phy_dev[port_idx]); + +if (fep->usage_count ==0 ) { +napi_enable (&fep->napi); +mtip_switch_restart (dev,1 ,1 ); + + fep->curr_time =0 ; +netif_start_queue (dev); + } + + fep->usage_count++; +return 0 ; + + mtip_mii_probe_err: +mtip_free_buffers (dev); + mtip_alloc_buffers_err: +if (fep->usage_count ==0 ) { +netif_napi_del (&fep->napi); +clk_disable (fep->clk_ipg); + } +return ret; +}; + +static int mtip_close (struct net_device *dev) +{ +struct mtip_ndev_priv *priv =netdev_priv (dev); +struct switch_enet_private *fep = priv->fep; +int idx = priv->portnum -1 ; + + fep->link[idx] =0 ; + +if (fep->phy_dev[idx]) { +phy_stop (fep->phy_dev[idx]); +netif_stop_queue (dev); +phy_disconnect (fep->phy_dev[idx]); + fep->phy_dev[idx] =NULL ; + } + +if (fep->usage_count ==1 ) { +napi_disable (&fep->napi); +netif_napi_del (&fep->napi); +mtip_free_buffers (dev); +clk_disable (fep->clk_ipg); + } + + fep->usage_count--; + +return 0 ; +} + +#define FEC_HASH_BITS 6/* #bits in hash */ +static void mtip_set_multicast_list (struct net_device *dev) +{ +struct mtip_ndev_priv *priv =netdev_priv (dev); +unsigned int hash_high =0 , hash_low =0 , crc; +struct switch_enet_private *fep = priv->fep;
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1540
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+void __iomem *enet_addr = fep->enet_addr; +struct netdev_hw_addr *ha; +unsigned char hash; + +if (priv->portnum ==2 ) + enet_addr +=MCF_ESW_ENET_PORT_OFFSET ; + +if (dev->flags &IFF_PROMISC ) { +/* Promisc mode is required for switch */ +dev_info (&dev->dev,"%s: IFF_PROMISC\n" , __func__);
I don't think we should do log on info level, which can be triggered via userspace.
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1545
Quoted 5 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +5
-0+return ; + } + +if (dev->flags &IFF_ALLMULTI ) { +dev_info (&dev->dev,"%s: IFF_ALLMULTI\n" , __func__);
ditto
Quoted 61 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +61
-0+ +/* Allow all multicast addresses */ +writel (0xffffffff , enet_addr +MCF_FEC_GRP_HASH_TABLE_HIGH ); +writel (0xffffffff , enet_addr +MCF_FEC_GRP_HASH_TABLE_LOW ); + +return ; + } + +netdev_for_each_mc_addr (ha, dev) { +/* calculate crc32 value of mac address */ + crc =ether_crc_le (dev->addr_len, ha->addr); + +/* only upper 6 bits (FEC_HASH_BITS) are used +* which point to specific bit in the hash registers +*/ + hash = (crc >> (32 -FEC_HASH_BITS )) &0x3f ; + +if (hash >31 ) + hash_high |=1 << (hash -32 ); +else + hash_low |=1 << hash; + } + +writel (hash_high, enet_addr +MCF_FEC_GRP_HASH_TABLE_HIGH ); +writel (hash_low, enet_addr +MCF_FEC_GRP_HASH_TABLE_LOW ); +} + +static int mtip_set_mac_address (struct net_device *dev,void *p) +{ +struct mtip_ndev_priv *priv =netdev_priv (dev); +struct switch_enet_private *fep = priv->fep; +void __iomem *enet_addr = fep->enet_addr; +struct sockaddr *addr = p; + +if (!is_valid_ether_addr (addr->sa_data)) +return -EADDRNOTAVAIL ; +eth_hw_addr_set (dev, addr->sa_data); + +if (priv->portnum ==2 ) + enet_addr +=MCF_ESW_ENET_PORT_OFFSET ; + +writel (dev->dev_addr[3 ] | (dev->dev_addr[2 ] <<8 ) | + (dev->dev_addr[1 ] <<16 ) | (dev->dev_addr[0 ] <<24 ), + enet_addr +MCF_FEC_PALR ); +writel ((dev->dev_addr[5 ] <<16 ) | (dev->dev_addr[4 ] <<24 ), + enet_addr +MCF_FEC_PAUR ); + +return mtip_update_atable_static ((unsigned char *)dev->dev_addr, +7 ,7 , fep); +} + +static const struct ethtool_ops mtip_ethtool_ops = { + .get_link_ksettings = phy_ethtool_get_link_ksettings, + .set_link_ksettings = phy_ethtool_set_link_ksettings, + .get_drvinfo = mtip_get_drvinfo, + .get_link = ethtool_op_get_link, + .get_ts_info = ethtool_op_get_ts_info, +}; + +static const struct net_device_ops mtip_netdev_ops = { + .ndo_open = mtip_open,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1616
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+ .ndo_stop = mtip_close, + .ndo_start_xmit = mtip_start_xmit, + .ndo_set_rx_mode = mtip_set_multicast_list, + .ndo_tx_timeout = mtip_timeout, + .ndo_set_mac_address = mtip_set_mac_address, +}; + +bool mtip_is_switch_netdev_port (const struct net_device *ndev) +{ +if (ndev->netdev_ops == &mtip_netdev_ops)
I think we can directly return the result of the expression
Quoted 118 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +118
-0+return true; + +return false; +} + +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_err (&fep->pdev->dev,"No suitable DMA available\n" ); +return ret; + } + +/* Allocate memory for buffer descriptors */ + cbd_base =dma_alloc_coherent (&fep->pdev->dev,PAGE_SIZE , &fep->bd_dma, +GFP_KERNEL ); +if (!cbd_base) +return -ENOMEM ; + +/* Set receive and transmit descriptor base */ + fep->rx_bd_base = cbd_base; + fep->tx_bd_base = cbd_base +RX_RING_SIZE ; + +/* Initialize the receive buffer descriptors */ + bdp = fep->rx_bd_base; +for (i =0 ; i <RX_RING_SIZE ; i++) { + bdp->cbd_sc =0 ; + bdp++; + } + +/* Set the last buffer to wrap */ + bdp--; + bdp->cbd_sc |=BD_SC_WRAP ; + +/* ...and the same for transmmit */ + bdp = fep->tx_bd_base; +for (i =0 ; i <TX_RING_SIZE ; i++) { +/* Initialize the BD for every fragment in the page */ + bdp->cbd_sc =0 ; + bdp->cbd_bufaddr =0 ; + bdp++; + } + +/* Set the last buffer to wrap */ + bdp--; + bdp->cbd_sc |=BD_SC_WRAP ; + +return 0 ; +} + +static void mtip_ndev_cleanup (struct switch_enet_private *fep) +{ +int i; + +for (i =0 ; i <SWITCH_EPORT_NUMBER ; i++) { +if (fep->ndev[i]) { +unregister_netdev (fep->ndev[i]); +free_netdev (fep->ndev[i]); + } + } +} + +static int mtip_ndev_init (struct switch_enet_private *fep) +{ +struct mtip_ndev_priv *priv; +int i, ret =0 ; + +for (i =0 ; i <SWITCH_EPORT_NUMBER ; i++) { + fep->ndev[i] =alloc_netdev (sizeof (struct mtip_ndev_priv ), + fep->ndev_name[i],NET_NAME_USER , + ether_setup); +if (!fep->ndev[i]) { + ret = -ENOMEM ; +break ; + } + + fep->ndev[i]->ethtool_ops = &mtip_ethtool_ops; + fep->ndev[i]->netdev_ops = &mtip_netdev_ops; + + priv =netdev_priv (fep->ndev[i]); + priv->dev = fep->ndev[i]; + priv->fep = fep; + priv->portnum = i +1 ; + fep->ndev[i]->irq = fep->irq; + + ret =mtip_setup_mac (fep->ndev[i]); +if (ret) { +dev_err (&fep->ndev[i]->dev, +"%s: ndev %s MAC setup err: %d\n" , + __func__, fep->ndev[i]->name, ret); +break ; + } + + ret =register_netdev (fep->ndev[i]); +if (ret) { +dev_err (&fep->ndev[i]->dev, +"%s: ndev %s register err: %d\n" , __func__, + fep->ndev[i]->name, ret); +break ; + } +dev_dbg (&fep->ndev[i]->dev,"%s: MTIP eth L2 switch %pM\n" , + fep->ndev[i]->name, fep->ndev[i]->dev_addr); + } + +if (ret) +mtip_ndev_cleanup (fep); + +return ret; +} + +static int mtip_parse_of (struct switch_enet_private *fep, +struct device_node *np) +{ +struct device_node *p;
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1744
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+unsigned int port_num; +int ret; + + p =of_find_node_by_name (np,"ethernet-ports" ); + +for_each_available_child_of_node_scoped (p, port) { +if (of_property_read_u32 (port,"reg" , &port_num)) +continue ; + + fep->n_ports = port_num;
Don't we need a check against SWITCH_EPORT_NUMBER here?
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1745
Quoted 1 line
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +1
-0+of_get_mac_address (port, &fep->mac[port_num -1 ][0 ]);
This can fail
Quoted 1,122 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +225
-0+ + ret =of_property_read_string (port,"label" , + &fep->ndev_name[port_num -1 ]); +if (ret <0 ) { +dev_err (&fep->pdev->dev, +"%s: Cannot get ethernet port name (%d)!\n" , + __func__, ret); + goto of_get_err; + } + + ret =of_get_phy_mode (port, &fep->phy_interface[port_num -1 ]); +if (ret <0 ) { +dev_err (&fep->pdev->dev, +"%s: Cannot get PHY mode (%d)!\n" , __func__, + ret); + goto of_get_err; + } + + fep->phy_np[port_num -1 ] =of_parse_phandle (port, +"phy-handle" ,0 ); + } + + of_get_err: +of_node_put (p); + +return 0 ; +} + +static int mtip_sw_learning (void *arg) +{ +struct switch_enet_private *fep = arg; + +while (!kthread_should_stop ()) { +set_current_state (TASK_INTERRUPTIBLE ); +/* check learning record valid */ +mtip_atable_dynamicms_learn_migration (fep, fep->curr_time, +NULL ,NULL ); +schedule_timeout (HZ /100 ); + } + +return 0 ; +} + +static void mtip_mii_unregister (struct switch_enet_private *fep) +{ +mdiobus_unregister (fep->mii_bus); +mdiobus_free (fep->mii_bus); +} + +static const struct mtip_devinfo mtip_imx28_l2switch_info = { + .quirks =FEC_QUIRK_BUG_CAPTURE |FEC_QUIRK_SINGLE_MDIO , +}; + +static const struct of_device_id mtipl2_of_match[] = { + { .compatible ="nxp,imx28-mtip-switch" , + .data = &mtip_imx28_l2switch_info}, + {/* sentinel */ } +} +MODULE_DEVICE_TABLE (of, mtipl2_of_match); + +static int mtip_sw_probe (struct platform_device *pdev) +{ +struct device_node *np = pdev->dev.of_node; +const struct of_device_id *of_id; +struct switch_enet_private *fep; +struct mtip_devinfo *dev_info; +struct switch_t *fecp; +int ret; + + fep =devm_kzalloc (&pdev->dev,sizeof (*fep),GFP_KERNEL ); +if (!fep) +return -ENOMEM ; + + of_id =of_match_node (mtipl2_of_match, pdev->dev.of_node); +if (of_id) { + dev_info = (struct mtip_devinfo *)of_id->data; +if (dev_info) + fep->quirks = dev_info->quirks; + } + + fep->pdev = pdev; +platform_set_drvdata (pdev, fep); + + fep->enet_addr =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (fep->enet_addr)) +return PTR_ERR (fep->enet_addr); + + fep->irq =platform_get_irq (pdev,0 ); +if (fep->irq <0 ) +return fep->irq; + + ret =mtip_parse_of (fep, np); +if (ret <0 ) { +dev_err (&pdev->dev,"%s: OF parse error (%d)!\n" , __func__, + ret); +return ret; + } + +/* Create an Ethernet device instance. +* The switch lookup address memory starts at 0x800FC000 +*/ + fep->hwp_enet = fep->enet_addr; + fecp = (struct switch_t *)(fep->enet_addr +ENET_SWI_PHYS_ADDR_OFFSET ); + + fep->hwp = fecp; + fep->hwentry = (struct mtip_addr_table_t *) + ((unsigned long )fecp +MCF_ESW_LOOKUP_MEM_OFFSET ); + + ret =devm_regulator_get_enable_optional (&pdev->dev,"phy" ); +if (ret) +return dev_err_probe (&pdev->dev, ret, +"Unable to get and enable 'phy'\n" ); + + fep->clk_ipg =devm_clk_get_enabled (&pdev->dev,"ipg" ); +if (IS_ERR (fep->clk_ipg)) +return dev_err_probe (&pdev->dev,PTR_ERR (fep->clk_ipg), +"Unable to acquire 'ipg' clock\n" ); + + fep->clk_ahb =devm_clk_get_enabled (&pdev->dev,"ahb" ); +if (IS_ERR (fep->clk_ahb)) +return dev_err_probe (&pdev->dev,PTR_ERR (fep->clk_ahb), +"Unable to acquire 'ahb' clock\n" ); + + fep->clk_enet_out =devm_clk_get_optional_enabled (&pdev->dev, +"enet_out" ); +if (IS_ERR (fep->clk_enet_out)) +return dev_err_probe (&pdev->dev,PTR_ERR (fep->clk_enet_out), +"Unable to acquire 'enet_out' clock\n" ); + +/* setup MII interface for external switch ports */ +mtip_enet_init (fep,1 ); +mtip_enet_init (fep,2 ); + +spin_lock_init (&fep->learn_lock); +spin_lock_init (&fep->hw_lock); +spin_lock_init (&fep->mii_lock); + + ret =devm_request_irq (&pdev->dev, fep->irq, mtip_interrupt,0 , +"mtip_l2sw" , fep); +if (ret) +return dev_err_probe (&pdev->dev, fep->irq, +"Could not alloc IRQ\n" ); + + ret =mtip_register_notifiers (fep); +if (ret) +return ret; + + ret =mtip_ndev_init (fep); +if (ret) { +dev_err (&pdev->dev,"%s: Failed to create virtual ndev (%d)\n" , + __func__, ret); + goto ndev_init_err; + } + + ret =mtip_switch_dma_init (fep); +if (ret) { +dev_err (&pdev->dev,"%s: ethernet switch init fail (%d)!\n" , + __func__, ret); + goto dma_init_err; + } + + ret =mtip_mii_init (fep, pdev); +if (ret) { +dev_err (&pdev->dev,"%s: Cannot init phy bus (%d)!\n" , __func__, + ret); + goto mii_init_err; + } +/* setup timer for learning aging function */ +timer_setup (&fep->timer_aging, mtip_aging_timer,0 ); +mod_timer (&fep->timer_aging, + jiffies +msecs_to_jiffies (LEARNING_AGING_INTERVAL )); + + fep->task =kthread_run (mtip_sw_learning, fep,"mtip_l2sw_learning" ); +if (IS_ERR (fep->task)) { + ret =PTR_ERR (fep->task); +dev_err (&pdev->dev,"%s: learning kthread_run error (%d)!\n" , + __func__, ret); + goto task_learning_err; + } + +return 0 ; + + task_learning_err: +timer_delete_sync (&fep->timer_aging); +mtip_mii_unregister (fep); + mii_init_err: + dma_init_err: +mtip_ndev_cleanup (fep); + ndev_init_err: +mtip_unregister_notifiers (fep); + +return ret; +} + +static void mtip_sw_remove (struct platform_device *pdev) +{ +struct switch_enet_private *fep =platform_get_drvdata (pdev); + +mtip_unregister_notifiers (fep); +mtip_ndev_cleanup (fep); + +mtip_mii_remove (fep); + +kthread_stop (fep->task); +timer_delete_sync (&fep->timer_aging); +platform_set_drvdata (pdev,NULL ); + +kfree (fep); +} + +static struct platform_driver mtipl2plat_driver = { + .driver = { + .name ="mtipl2sw" , + .of_match_table = mtipl2_of_match, + .suppress_bind_attrs = true, + }, + .probe = mtip_sw_probe, + .remove = mtip_sw_remove, +}; + +module_platform_driver (mtipl2plat_driver); + +MODULE_AUTHOR ("Lukasz Majewski<[email protected]>" ); +MODULE_DESCRIPTION ("Driver for MTIP L2 on SOC switch" ); +MODULE_LICENSE ("GPL" );drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +782
-0@@ -0,0 +1,782 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (C) 2025 DENX Software Engineering GmbH +* Lukasz Majewski<[email protected]> +*/ + +#ifndef __MTIP_L2SWITCH_H_ +#define __MTIP_L2SWITCH_H_ + +#include <linux/clocksource.h> +#include <linux/net_tstamp.h> +#include <linux/ptp_clock_kernel.h> +#include <linux/timecounter.h> +#include <linux/netdevice.h> +#include <linux/phy.h> + +#define PKT_MAXBUF_SIZE 1518 +#define PKT_MINBUF_SIZE 64 +#define PKT_MAXBLR_SIZE 1520 + +/* The number of Tx and Rx buffers. These are allocated from the page +* pool. The code may assume these are power of two, so it is best +* to keep them that size. +* We don't need to allocate pages for the transmitter. We just use +* the skbuffer directly. +*/ +#define MTIP_SWITCH_RX_PAGES 8 +#define MTIP_SWITCH_RX_FRSIZE 2048 +#define MTIP_SWITCH_RX_FRPPG (PAGE_SIZE / MTIP_SWITCH_RX_FRSIZE) +#define RX_RING_SIZE (MTIP_SWITCH_RX_FRPPG * MTIP_SWITCH_RX_PAGES) +#define MTIP_SWITCH_TX_FRSIZE 2048 +#define MTIP_SWITCH_TX_FRPPG (PAGE_SIZE / MTIP_SWITCH_TX_FRSIZE) + +#define TX_RING_SIZE 16/* Must be power of two */ +#define TX_RING_MOD_MASK 15/* for this to work */ + +#define SWITCH_EPORT_NUMBER 2 + +#if (((RX_RING_SIZE +TX_RING_SIZE ) *8 ) >PAGE_SIZE ) +#error "L2SWITCH: descriptor ring size constants too large" +#endif +struct mtip_port_statistics_status { +/*outgoing frames discarded due to transmit queue congestion*/ +unsigned long MCF_ESW_POQC; +/*incoming frames discarded due to VLAN domain mismatch*/ +unsigned long MCF_ESW_PMVID; +/*incoming frames discarded due to untagged discard*/ +unsigned long MCF_ESW_PMVTAG; +/*incoming frames discarded due port is in blocking state*/ +unsigned long MCF_ESW_PBL; +}; + +struct switch_t { +unsigned long ESW_REVISION; +unsigned long ESW_SCRATCH; +unsigned long ESW_PER; +unsigned long reserved0[1 ]; +unsigned long ESW_VLANV; +unsigned long ESW_DBCR; +unsigned long ESW_DMCR; +unsigned long ESW_BKLR; +unsigned long ESW_BMPC; +unsigned long ESW_MODE; +unsigned long ESW_VIMSEL; +unsigned long ESW_VOMSEL; +unsigned long ESW_VIMEN; +unsigned long ESW_VID;/*0x34*/ +/*from 0x38 0x3C*/ +unsigned long esw_reserved0[2 ]; +unsigned long ESW_MCR;/*0x40*/ +unsigned long ESW_EGMAP; +unsigned long ESW_INGMAP; +unsigned long ESW_INGSAL; +unsigned long ESW_INGSAH; +unsigned long ESW_INGDAL; +unsigned long ESW_INGDAH; +unsigned long ESW_ENGSAL; +unsigned long ESW_ENGSAH; +unsigned long ESW_ENGDAL; +unsigned long ESW_ENGDAH; +unsigned long ESW_MCVAL;/*0x6C*/ +/*from 0x70--0x7C*/ +unsigned long esw_reserved1[4 ]; +unsigned long ESW_MMSR;/*0x80*/ +unsigned long ESW_LMT; +unsigned long ESW_LFC; +unsigned long ESW_PCSR; +unsigned long ESW_IOSR; +unsigned long ESW_QWT;/*0x94*/ +unsigned long esw_reserved2[1 ];/*0x98*/ +unsigned long ESW_P0BCT;/*0x9C*/ +/*from 0xA0-0xB8*/ +unsigned long esw_reserved3[7 ]; +unsigned long ESW_P0FFEN;/*0xBC*/ +unsigned long ESW_PSNP[8 ]; +unsigned long ESW_IPSNP[8 ]; +unsigned long ESW_PVRES[3 ]; +/*from 0x10C-0x13C*/ +unsigned long esw_reserved4[13 ]; +unsigned long ESW_IPRES;/*0x140*/ +/*from 0x144-0x17C*/ +unsigned long esw_reserved5[15 ]; +unsigned long ESW_PRES[3 ]; +/*from 0x18C-0x1FC*/ +unsigned long esw_reserved6[29 ]; +unsigned long ESW_PID[3 ]; +/*from 0x20C-0x27C*/ +unsigned long esw_reserved7[29 ]; +unsigned long ESW_VRES[32 ]; +unsigned long ESW_DISCN;/*0x300*/ +unsigned long ESW_DISCB; +unsigned long ESW_NDISCN; +unsigned long ESW_NDISCB;/*0xFC0DC30C*/ +struct mtip_port_statistics_status port_statistics_status[3 ]; +/*from 0x340-0x400*/ +unsigned long esw_reserved8[48 ]; +/*0xFC0DC400---0xFC0DC418*/ +unsigned long ESW_ISR; +unsigned long ESW_IMR; +unsigned long ESW_RDSR; +unsigned long ESW_TDSR; +unsigned long ESW_MRBR; +unsigned long ESW_RDAR; +unsigned long ESW_TDAR; +/*from 0x420-0x4FC*/ +unsigned long esw_reserved9[57 ]; +/*0xFC0DC500---0xFC0DC508*/ +unsigned long ESW_LREC0; +unsigned long ESW_LREC1; +unsigned long ESW_LSR; +}; + +struct addr_table64b_entry { +unsigned int lo;/* lower 32 bits */ +unsigned int hi;/* upper 32 bits */ +}; + +struct mtip_addr_table_t { +struct addr_table64b_entry mtip_table64b_entry[2048 ]; +}; + +#define MCF_ESW_LOOKUP_MEM_OFFSET 0x4000 +#define MCF_ESW_ENET_PORT_OFFSET 0x4000 +#define ENET_SWI_PHYS_ADDR_OFFSET 0x8000 +#define MCF_ESW_PER (0x08) +#define MCF_ESW_DBCR (0x14) +#define MCF_ESW_IMR (0x404) + +#define MCF_FEC_BASE_ADDR (fep->enet_addr) +#define MCF_FEC_EIR (0x04) +#define MCF_FEC_EIMR (0x08) +#define MCF_FEC_MMFR (0x40) +#define MCF_FEC_MSCR (0x44) + +#define MCF_FEC_RCR (0x84) +#define MCF_FEC_TCR (0xC4) +#define MCF_FEC_ECR (0x24) + +#define MCF_FEC_PALR (0xE4) +#define MCF_FEC_PAUR (0xE8) + +#define MCF_FEC_ERDSR (0x180) +#define MCF_FEC_ETDSR (0x184) + +#define MCF_FEC_IAUR (0x118) +#define MCF_FEC_IALR (0x11C) + +#define MCF_FEC_GAUR (0x120) +#define MCF_FEC_GALR (0x124) + +#define MCF_FEC_EMRBR (0x188) + +#define MCF_FEC_RCR_DRT BIT(1) +#define MCF_FEC_RCR_MII_MODE BIT(2) +#define MCF_FEC_RCR_PROM BIT(3) +#define MCF_FEC_RCR_FCE BIT(5) +#define MCF_FEC_RCR_RMII_MODE BIT(8) +#define MCF_FEC_RCR_RMII_10BASET BIT(9) +#define MCF_FEC_RCR_MAX_FL (x) (((x) & 0x00003FFF) << 16) +#define MCF_FEC_RCR_CRC_FWD BIT(14) +#define MCF_FEC_RCR_NO_LGTH_CHECK BIT(30) +#define MCF_FEC_TCR_FDEN BIT(2) + +#define MCF_FEC_ECR_RESET BIT(0) +#define MCF_FEC_ECR_ETHER_EN BIT(1) +#define MCF_FEC_ECR_MAGIC_ENA BIT(2) +#define MCF_FEC_ECR_ENA_1588 BIT(4) + +#define MTIP_ALIGNMENT 0xf +#define MCF_ENET_MII BIT(23) + +/* FEC MII MMFR bits definition */ +#define FEC_MMFR_ST BIT(30) +#define FEC_MMFR_OP_READ BIT(29) +#define FEC_MMFR_OP_WRITE BIT(28) +#define FEC_MMFR_PA (v) (((v) & 0x1F) << 23) +#define FEC_MMFR_RA (v) (((v) & 0x1F) << 18) +#define FEC_MMFR_TA (2 << 16) +#define FEC_MMFR_DATA (v) ((v) & 0xffff) + +/* Port 0 backpressure congestion threshold */ +#define P0BC_THRESHOLD 0x40 +#define LEARNING_AGING_INTERVAL 100 +/* Info received from Hardware Learning FIFO, +* holding MAC address and corresponding Hash Value and +* port number where the frame was received (disassembled). +*/ +struct mtip_port_info { +/* MAC lower 32 bits (first byte is 7:0). */ +unsigned int maclo; +/* MAC upper 16 bits (47:32). */ +unsigned int machi; +/* the hash value for this MAC address. */ +unsigned int hash; +/* the port number this MAC address is associated with. */ +unsigned int port; +}; + +/* Define the buffer descriptor structure. */ +struct cbd_t { +unsigned short cbd_datlen;/* Data length */ +unsigned short cbd_sc;/* Control and status info */ +unsigned long cbd_bufaddr;/* Buffer address */ +}; + +/* The switch buffer descriptors track the ring buffers. The rx_bd_base and +* tx_bd_base always point to the base of the buffer descriptors. The +* cur_rx and cur_tx point to the currently available buffer. +* The dirty_tx tracks the current buffer that is being sent by the +* controller. The cur_tx and dirty_tx are equal under both completely +* empty and completely full conditions. The empty/ready indicator in +* the buffer descriptor determines the actual condition. +*/ +struct switch_enet_private { +/* Base addresses for HW registers of the switch device */ +void __iomem *hwp_enet; +struct switch_t *hwp; +struct mtip_addr_table_t *hwentry; +void __iomem *enet_addr; + +struct platform_device *pdev; + +/* Clocks */ +struct clk *clk_ipg; +struct clk *clk_ahb; +struct clk *clk_enet_out; + +/* skbuff */ +unsigned char *tx_bounce[TX_RING_SIZE ]; +struct sk_buff *tx_skbuff[TX_RING_SIZE ]; +struct sk_buff *rx_skbuff[RX_RING_SIZE ]; +ushort skb_cur; +ushort skb_dirty; + +/* DMA */ +dma_addr_t bd_dma; +struct cbd_t *rx_bd_base;/* Address of Rx and Tx buffers. */ +struct cbd_t *tx_bd_base; +struct cbd_t *cur_rx, *cur_tx;/* The next free ring entry */ +struct cbd_t *dirty_tx;/* The ring entries to be free()ed. */ +uint tx_full; + +/* Locking */ +spinlock_t hw_lock;/* Lock for HW configuration */ +spinlock_t mii_lock;/* Lock for MII operation */ +spinlock_t learn_lock;/* Lock for learning DB adjustments */ + +/* NAPI support */ +struct napi_struct napi; + +/* Timer for Aging */ +struct timer_list timer_aging; +struct task_struct *task; +int at_block_overflows; +int at_curr_entries; +int curr_time; + +/* PHY and MDIO */ +struct mii_bus *mii_bus; +struct phy_device *phy_dev[SWITCH_EPORT_NUMBER ]; +uint phy_speed; +int link[SWITCH_EPORT_NUMBER ]; +int full_duplex[SWITCH_EPORT_NUMBER ]; +phy_interface_t phy_interface[SWITCH_EPORT_NUMBER ]; +struct device_node *phy_np[SWITCH_EPORT_NUMBER ]; + +/* IRQ number */ +int irq; + +/* lan[01] ports */ +int n_ports; +const char *ndev_name[SWITCH_EPORT_NUMBER ]; +struct net_device *ndev[SWITCH_EPORT_NUMBER ]; +unsigned char mac[SWITCH_EPORT_NUMBER ][ETH_ALEN ]; + +/* Switch state */ +u8 br_members;/* Bit field with active members */ +u8 br_offload;/* Bridge in-HW offloading flag */ +int usage_count;/* Number of configured ports */ + +/* Driver related */ +u32 quirks; +}; + +struct mtip_ndev_priv { +int portnum; +struct net_device *dev; +struct net_device_stats stats; +struct net_device *master_dev; +struct switch_enet_private *fep; +}; + +#define MCF_FEC_MII_DATA 0x040/* MII manage frame reg */ +#define MCF_FEC_GRP_HASH_TABLE_HIGH 0x120/* High 32bits hash table */ +#define MCF_FEC_GRP_HASH_TABLE_LOW 0x124/* Low 32bits hash table */ + +#define BD_SC_EMPTY ((ushort)0x8000)/* Receive is empty */ +#define BD_SC_READY ((ushort)0x8000)/* Transmit is ready */ +#define BD_SC_WRAP ((ushort)0x2000)/* Last buffer descriptor */ +#define BD_SC_INTRPT ((ushort)0x1000)/* Interrupt on change */ +#define BD_SC_CM ((ushort)0x0200)/* Continuous mode */ +#define BD_SC_ID ((ushort)0x0100)/* Rec'd too many idles */ +#define BD_SC_P ((ushort)0x0100)/* xmt preamble */ +#define BD_SC_BR ((ushort)0x0020)/* Break received */ +#define BD_SC_FR ((ushort)0x0010)/* Framing error */ +#define BD_SC_PR ((ushort)0x0008)/* Parity error */ +#define BD_SC_OV ((ushort)0x0002)/* Overrun */ +#define BD_SC_CD ((ushort)0x0001) + +/* Buffer descriptor control/status used by Ethernet receive. */ +#define BD_ENET_RX_EMPTY ((ushort)0x8000) +#define BD_ENET_RX_WRAP ((ushort)0x2000) +#define BD_ENET_RX_INTR ((ushort)0x1000) +#define BD_ENET_RX_LAST ((ushort)0x0800) +#define BD_ENET_RX_FIRST ((ushort)0x0400) +#define BD_ENET_RX_MISS ((ushort)0x0100) +#define BD_ENET_RX_LG ((ushort)0x0020) +#define BD_ENET_RX_NO ((ushort)0x0010) +#define BD_ENET_RX_SH ((ushort)0x0008) +#define BD_ENET_RX_CR ((ushort)0x0004) +#define BD_ENET_RX_OV ((ushort)0x0002) +#define BD_ENET_RX_CL ((ushort)0x0001) +/* All status bits */ +#define BD_ENET_RX_STATS ((ushort)0x013f) + +/* Buffer descriptor control/status used by Ethernet transmit.*/ +#define BD_ENET_TX_READY ((ushort)0x8000) +#define BD_ENET_TX_PAD ((ushort)0x4000) +#define BD_ENET_TX_WRAP ((ushort)0x2000) +#define BD_ENET_TX_INTR ((ushort)0x1000) +#define BD_ENET_TX_LAST ((ushort)0x0800) +#define BD_ENET_TX_TC ((ushort)0x0400) +#define BD_ENET_TX_DEF ((ushort)0x0200) +#define BD_ENET_TX_HB ((ushort)0x0100) +#define BD_ENET_TX_LC ((ushort)0x0080) +#define BD_ENET_TX_RL ((ushort)0x0040) +#define BD_ENET_TX_RCMASK ((ushort)0x003c) +#define BD_ENET_TX_UN ((ushort)0x0002) +#define BD_ENET_TX_CSL ((ushort)0x0001) +/* All status bits */ +#define BD_ENET_TX_STATS ((ushort)0x03ff) + +/* Copy from validation code */ +#define RX_BUFFER_SIZE 256 +#define TX_BUFFER_SIZE 256 + +#define TX_BD_R BIT(15) +#define TX_BD_TO1 BIT(14) +#define TX_BD_W BIT(13) +#define TX_BD_TO2 BIT(12) +#define TX_BD_L BIT(11) +#define TX_BD_TC BIT(10) + +#define TX_BD_INT BIT(30) +#define TX_BD_TS BIT(29) +#define TX_BD_PINS BIT(28) +#define TX_BD_IINS BIT(27) +#define TX_BD_TXE BIT(15) +#define TX_BD_UE BIT(13) +#define TX_BD_EE BIT(12) +#define TX_BD_FE BIT(11) +#define TX_BD_LCE BIT(10) +#define TX_BD_OE BIT(9) +#define TX_BD_TSE BIT(8) +#define TX_BD_BDU BIT(31) + +#define RX_BD_E BIT(15) +#define RX_BD_R01 BIT(14) +#define RX_BD_W BIT(13) +#define RX_BD_R02 BIT(12) +#define RX_BD_L BIT(11) +#define RX_BD_M BIT(8) +#define RX_BD_BC BIT(7) +#define RX_BD_MC BIT(6) +#define RX_BD_LG BIT(5) +#define RX_BD_NO BIT(4) +#define RX_BD_CR BIT(2) +#define RX_BD_OV BIT(1) +#define RX_BD_TR BIT(0) + +#define RX_BD_ME BIT(31) +#define RX_BD_PE 0x04000000 +#define RX_BD_CE 0x02000000 +#define RX_BD_UC 0x01000000 +#define RX_BD_INT 0x00800000 +#define RX_BD_ICE BIT(5) +#define RX_BD_PCR BIT(4) +#define RX_BD_VLAN BIT(2) +#define RX_BD_IPV6 BIT(1) +#define RX_BD_FRAG BIT(0) +#define RX_BD_BDU BIT(31) +/****************************************************************************/ + +/* Address Table size in bytes(2048 64bit entry ) */ +#define MTIP_ATABLE_MEM_SIZE (2048 * 8) +/* How many 64-bit elements fit in the address table */ +#define MTIP_ATABLE_MEM_NUM_ENTRIES (2048) +/* Address Table Maximum number of entries in each Slot */ +#define ATABLE_ENTRY_PER_SLOT 8 +/* log2(ATABLE_ENTRY_PER_SLOT)*/ +#define ATABLE_ENTRY_PER_SLOT_bits 3 +/* entry size in byte */ +#define ATABLE_ENTRY_SIZE 8 +/* slot size in byte */ +#define ATABLE_SLOT_SIZE (ATABLE_ENTRY_PER_SLOT * ATABLE_ENTRY_SIZE) +/* width of timestamp variable (bits) within address table entry */ +#define AT_DENTRY_TIMESTAMP_WIDTH 10 +/* number of bits for port number storage */ +#define AT_DENTRY_PORT_WIDTH 4 +/* number of bits for port bitmask number storage */ +#define AT_SENTRY_PORT_WIDTH 11 +/* address table static entry port bitmask start address bit */ +#define AT_SENTRY_PORTMASK_shift 21 +/* address table static entry priority start address bit */ +#define AT_SENTRY_PRIO_shift 18 +/* address table dynamic entry port start address bit */ +#define AT_DENTRY_PORT_shift 28 +/* address table dynamic entry timestamp start address bit */ +#define AT_DENTRY_TIME_shift 18 +/* address table entry record type start address bit */ +#define AT_ENTRY_TYPE_shift 17 +/* address table entry record type bit: 1 static, 0 dynamic */ +#define AT_ENTRY_TYPE_STATIC 1 +#define AT_ENTRY_TYPE_DYNAMIC 0 +/* address table entry record valid start address bit */ +#define AT_ENTRY_VALID_shift 16 +#define AT_ENTRY_RECORD_VALID 1 + +/* return block corresponding to the 8 bit hash value calculated */ +#define GET_BLOCK_PTR (hash) ((hash) << 3) +#define AT_EXTRACT_TIMESTAMP (x) \ + (((x) >> AT_DENTRY_TIME_shift) & ((1 << AT_DENTRY_TIMESTAMP_WIDTH) - 1)) +#define AT_EXTRACT_PORT (x) \ + (((x) >> AT_DENTRY_PORT_shift) & ((1 << AT_DENTRY_PORT_WIDTH) - 1)) +#define TIMEDELTA (newtime, oldtime) \ + (((newtime) - (oldtime)) & \ + ((1 << AT_DENTRY_TIMESTAMP_WIDTH) - 1)) + +/* increment time value respecting modulo. */ +static inline int mtip_timeincrement (int time) +{ +return (time +1 ) & ((1 <<AT_DENTRY_TIMESTAMP_WIDTH ) -1 ); +} + +/* ------------------------------------------------------------------------- */ +/* Bit definitions and macros for MCF_ESW_REVISION */ +#define MCF_MTIP_REVISION_CORE_REVISION (x) ((x) & 0x0000FFFF) +#define MCF_MTIP_REVISION_CUSTOMER_REVISION (x) (((x) & 0xFFFF0000) >> 16) + +/* Bit definitions and macros for MCF_ESW_PER */ +#define MCF_ESW_PER_TE0 BIT(0) +#define MCF_ESW_PER_TE1 BIT(1) +#define MCF_ESW_PER_TE2 BIT(2) +#define MCF_ESW_PER_RE0 BIT(16) +#define MCF_ESW_PER_RE1 BIT(17) +#define MCF_ESW_PER_RE2 BIT(18) + +/* Bit definitions and macros for MCF_ESW_VLANV */ +#define MCF_ESW_VLANV_VV0 BIT(0) +#define MCF_ESW_VLANV_VV1 BIT(1) +#define MCF_ESW_VLANV_VV2 BIT(2) +#define MCF_ESW_VLANV_DU0 BIT(16) +#define MCF_ESW_VLANV_DU1 BIT(17) +#define MCF_ESW_VLANV_DU2 BIT(18) + +/* Bit definitions and macros for MCF_ESW_DBCR */ +#define MCF_ESW_DBCR_P0 BIT(0) +#define MCF_ESW_DBCR_P1 BIT(1) +#define MCF_ESW_DBCR_P2 BIT(2) + +/* Bit definitions and macros for MCF_ESW_DMCR */ +#define MCF_ESW_DMCR_P0 BIT(0) +#define MCF_ESW_DMCR_P1 BIT(1) +#define MCF_ESW_DMCR_P2 BIT(2) + +/* Bit definitions and macros for MCF_ESW_BKLR */ +#define MCF_ESW_BKLR_BE0 BIT(0) +#define MCF_ESW_BKLR_BE1 BIT(1) +#define MCF_ESW_BKLR_BE2 BIT(2) +#define MCF_ESW_BKLR_LD0 BIT(16) +#define MCF_ESW_BKLR_LD1 BIT(17) +#define MCF_ESW_BKLR_LD2 BIT(18) + +/* Bit definitions and macros for MCF_ESW_BMPC */ +#define MCF_ESW_BMPC_PORT (x) (((x) & 0x0000000F) << 0) +#define MCF_ESW_BMPC_MSG_TX BIT(5) +#define MCF_ESW_BMPC_EN BIT(6) +#define MCF_ESW_BMPC_DIS BIT(7) +#define MCF_ESW_BMPC_PRIORITY (x) (((x) & 0x00000007) << 13) +#define MCF_ESW_BMPC_PORTMASK (x) (((x) & 0x00000007) << 16) + +/* Bit definitions and macros for MCF_ESW_MODE */ +#define MCF_ESW_MODE_SW_RST BIT(0) +#define MCF_ESW_MODE_SW_EN BIT(1) +#define MCF_ESW_MODE_STOP BIT(7) +#define MCF_ESW_MODE_CRC_TRAN BIT(8) +#define MCF_ESW_MODE_P0CT BIT(9) +#define MCF_ESW_MODE_STATRST BIT(31) + +/* Bit definitions and macros for MCF_ESW_VIMSEL */ +#define MCF_ESW_VIMSEL_IM0 (x) (((x) & 0x00000003) << 0) +#define MCF_ESW_VIMSEL_IM1 (x) (((x) & 0x00000003) << 2) +#define MCF_ESW_VIMSEL_IM2 (x) (((x) & 0x00000003) << 4) + +/* Bit definitions and macros for MCF_ESW_VOMSEL */ +#define MCF_ESW_VOMSEL_OM0 (x) (((x) & 0x00000003) << 0) +#define MCF_ESW_VOMSEL_OM1 (x) (((x) & 0x00000003) << 2) +#define MCF_ESW_VOMSEL_OM2 (x) (((x) & 0x00000003) << 4) + +/* Bit definitions and macros for MCF_ESW_VIMEN */ +#define MCF_ESW_VIMEN_EN0 BIT(0) +#define MCF_ESW_VIMEN_EN1 BIT(1) +#define MCF_ESW_VIMEN_EN2 BIT(2) + +/* Bit definitions and macros for MCF_ESW_VID */ +#define MCF_ESW_VID_TAG (x) (((x) & 0xFFFFFFFF) << 0) + +/* Bit definitions and macros for MCF_ESW_MCR */ +#define MCF_ESW_MCR_PORT (x) (((x) & 0x0000000F) << 0) +#define MCF_ESW_MCR_MEN BIT(4) +#define MCF_ESW_MCR_INGMAP BIT(5) +#define MCF_ESW_MCR_EGMAP BIT(6) +#define MCF_ESW_MCR_INGSA BIT(7) +#define MCF_ESW_MCR_INGDA BIT(8) +#define MCF_ESW_MCR_EGSA BIT(9) +#define MCF_ESW_MCR_EGDA BIT(10) + +/* Bit definitions and macros for MCF_ESW_EGMAP */ +#define MCF_ESW_EGMAP_EG0 BIT(0) +#define MCF_ESW_EGMAP_EG1 BIT(1) +#define MCF_ESW_EGMAP_EG2 BIT(2) + +/* Bit definitions and macros for MCF_ESW_INGMAP */ +#define MCF_ESW_INGMAP_ING0 BIT(0) +#define MCF_ESW_INGMAP_ING1 BIT(1) +#define MCF_ESW_INGMAP_ING2 BIT(2) + +/* Bit definitions and macros for MCF_ESW_INGSAL */ +#define MCF_ESW_INGSAL_ADDLOW (x) (((x) & 0xFFFFFFFF) << 0) + +/* Bit definitions and macros for MCF_ESW_INGSAH */ +#define MCF_ESW_INGSAH_ADDHIGH (x) (((x) & 0x0000FFFF) << 0) + +/* Bit definitions and macros for MCF_ESW_INGDAL */ +#define MCF_ESW_INGDAL_ADDLOW (x) (((x) & 0xFFFFFFFF) << 0) + +/* Bit definitions and macros for MCF_ESW_INGDAH */ +#define MCF_ESW_INGDAH_ADDHIGH (x) (((x) & 0x0000FFFF) << 0) + +/* Bit definitions and macros for MCF_ESW_ENGSAL */ +#define MCF_ESW_ENGSAL_ADDLOW (x) (((x) & 0xFFFFFFFF) << 0) + +/* Bit definitions and macros for MCF_ESW_ENGSAH */ +#define MCF_ESW_ENGSAH_ADDHIGH (x) (((x) & 0x0000FFFF) << 0) + +/* Bit definitions and macros for MCF_ESW_ENGDAL */ +#define MCF_ESW_ENGDAL_ADDLOW (x) (((x) & 0xFFFFFFFF) << 0) + +/* Bit definitions and macros for MCF_ESW_ENGDAH */ +#define MCF_ESW_ENGDAH_ADDHIGH (x) (((x) & 0x0000FFFF) << 0) + +/* Bit definitions and macros for MCF_ESW_MCVAL */ +#define MCF_ESW_MCVAL_COUNT (x) (((x) & 0x000000FF) << 0) + +/* Bit definitions and macros for MCF_ESW_MMSR */ +#define MCF_ESW_MMSR_BUSY BIT(0) +#define MCF_ESW_MMSR_NOCELL BIT(1) +#define MCF_ESW_MMSR_MEMFULL BIT(2) +#define MCF_ESW_MMSR_MFLATCH BIT(3) +#define MCF_ESW_MMSR_DQ_GRNT BIT(6) +#define MCF_ESW_MMSR_CELLS_AVAIL (x) (((x) & 0x000000FF) << 16) + +/* Bit definitions and macros for MCF_ESW_LMT */ +#define MCF_ESW_LMT_THRESH (x) (((x) & 0x000000FF) << 0) + +/* Bit definitions and macros for MCF_ESW_LFC */ +#define MCF_ESW_LFC_COUNT (x) (((x) & 0xFFFFFFFF) << 0) + +/* Bit definitions and macros for MCF_ESW_PCSR */ +#define MCF_ESW_PCSR_PC0 BIT(0) +#define MCF_ESW_PCSR_PC1 BIT(1) +#define MCF_ESW_PCSR_PC2 BIT(2) + +/* Bit definitions and macros for MCF_ESW_IOSR */ +#define MCF_ESW_IOSR_OR0 BIT(0) +#define MCF_ESW_IOSR_OR1 BIT(1) +#define MCF_ESW_IOSR_OR2 BIT(2) + +/* Bit definitions and macros for MCF_ESW_QWT */ +#define MCF_ESW_QWT_Q0WT (x) (((x) & 0x0000001F) << 0) +#define MCF_ESW_QWT_Q1WT (x) (((x) & 0x0000001F) << 8) +#define MCF_ESW_QWT_Q2WT (x) (((x) & 0x0000001F) << 16) +#define MCF_ESW_QWT_Q3WT (x) (((x) & 0x0000001F) << 24) + +/* Bit definitions and macros for MCF_ESW_P0BCT */ +#define MCF_ESW_P0BCT_THRESH (x) (((x) & 0x000000FF) << 0) + +/* Bit definitions and macros for MCF_ESW_P0FFEN */ +#define MCF_ESW_P0FFEN_FEN BIT(0) +#define MCF_ESW_P0FFEN_FD (x) (((x) & 0x00000003) << 2) + +/* Bit definitions and macros for MCF_ESW_PSNP */ +#define MCF_ESW_PSNP_EN BIT(0) +#define MCF_ESW_PSNP_MODE (x) (((x) & 0x00000003) << 1) +#define MCF_ESW_PSNP_CD BIT(3) +#define MCF_ESW_PSNP_CS BIT(4) +#define MCF_ESW_PSNP_PORT_COMPARE (x) (((x) & 0x0000FFFF) << 16) + +/* Bit definitions and macros for MCF_ESW_IPSNP */ +#define MCF_ESW_IPSNP_EN BIT(0) +#define MCF_ESW_IPSNP_MODE (x) (((x) & 0x00000003) << 1) +#define MCF_ESW_IPSNP_PROTOCOL (x) (((x) & 0x000000FF) << 8) + +/* Bit definitions and macros for MCF_ESW_PVRES */ +#define MCF_ESW_PVRES_PRI0 (x) (((x) & 0x00000007) << 0) +#define MCF_ESW_PVRES_PRI1 (x) (((x) & 0x00000007) << 3) +#define MCF_ESW_PVRES_PRI2 (x) (((x) & 0x00000007) << 6) +#define MCF_ESW_PVRES_PRI3 (x) (((x) & 0x00000007) << 9) +#define MCF_ESW_PVRES_PRI4 (x) (((x) & 0x00000007) << 12) +#define MCF_ESW_PVRES_PRI5 (x) (((x) & 0x00000007) << 15) +#define MCF_ESW_PVRES_PRI6 (x) (((x) & 0x00000007) << 18) +#define MCF_ESW_PVRES_PRI7 (x) (((x) & 0x00000007) << 21) + +/* Bit definitions and macros for MCF_ESW_IPRES */ +#define MCF_ESW_IPRES_ADDRESS (x) (((x) & 0x000000FF) << 0) +#define MCF_ESW_IPRES_IPV4SEL BIT(8) +#define MCF_ESW_IPRES_PRI0 (x) (((x) & 0x00000003) << 9) +#define MCF_ESW_IPRES_PRI1 (x) (((x) & 0x00000003) << 11) +#define MCF_ESW_IPRES_PRI2 (x) (((x) & 0x00000003) << 13) +#define MCF_ESW_IPRES_READ BIT(31) + +/* Bit definitions and macros for MCF_ESW_PRES */ +#define MCF_ESW_PRES_VLAN BIT(0) +#define MCF_ESW_PRES_IP BIT(1) +#define MCF_ESW_PRES_MAC BIT(2) +#define MCF_ESW_PRES_DFLT_PRI (x) (((x) & 0x00000007) << 4) + +/* Bit definitions and macros for MCF_ESW_PID */ +#define MCF_ESW_PID_VLANID (x) (((x) & 0x0000FFFF) << 0) + +/* Bit definitions and macros for MCF_ESW_VRES */ +#define MCF_ESW_VRES_P0 BIT(0) +#define MCF_ESW_VRES_P1 BIT(1) +#define MCF_ESW_VRES_P2 BIT(2) +#define MCF_ESW_VRES_VLANID (x) (((x) & 0x00000FFF) << 3) + +/* Bit definitions and macros for MCF_ESW_DISCN */ +#define MCF_ESW_DISCN_COUNT (x) (((x) & 0xFFFFFFFF) << 0) + +/* Bit definitions and macros for MCF_ESW_DISCB */ +#define MCF_ESW_DISCB_COUNT (x) (((x) & 0xFFFFFFFF) << 0) + +/* Bit definitions and macros for MCF_ESW_NDISCN */ +#define MCF_ESW_NDISCN_COUNT (x) (((x) & 0xFFFFFFFF) << 0) + +/* Bit definitions and macros for MCF_ESW_NDISCB */ +#define MCF_ESW_NDISCB_COUNT (x) (((x) & 0xFFFFFFFF) << 0) + +/* Bit definitions and macros for MCF_ESW_POQC */ +#define MCF_ESW_POQC_COUNT (x) (((x) & 0xFFFFFFFF) << 0) + +/* Bit definitions and macros for MCF_ESW_PMVID */ +#define MCF_ESW_PMVID_COUNT (x) (((x) & 0xFFFFFFFF) << 0) + +/* Bit definitions and macros for MCF_ESW_PMVTAG */ +#define MCF_ESW_PMVTAG_COUNT (x) (((x) & 0xFFFFFFFF) << 0) + +/* Bit definitions and macros for MCF_ESW_PBL */ +#define MCF_ESW_PBL_COUNT (x) (((x) & 0xFFFFFFFF) << 0) + +/* Bit definitions and macros for MCF_ESW_ISR */ +#define MCF_ESW_ISR_EBERR BIT(0) +#define MCF_ESW_ISR_RXB BIT(1) +#define MCF_ESW_ISR_RXF BIT(2) +#define MCF_ESW_ISR_TXB BIT(3) +#define MCF_ESW_ISR_TXF BIT(4) +#define MCF_ESW_ISR_QM BIT(5) +#define MCF_ESW_ISR_OD0 BIT(6) +#define MCF_ESW_ISR_OD1 BIT(7) +#define MCF_ESW_ISR_OD2 BIT(8) +#define MCF_ESW_ISR_LRN BIT(9) + +/* Bit definitions and macros for MCF_ESW_IMR */ +#define MCF_ESW_IMR_EBERR BIT(0) +#define MCF_ESW_IMR_RXB BIT(1) +#define MCF_ESW_IMR_RXF BIT(2) +#define MCF_ESW_IMR_TXB BIT(3) +#define MCF_ESW_IMR_TXF BIT(4) +#define MCF_ESW_IMR_QM BIT(5) +#define MCF_ESW_IMR_OD0 BIT(6) +#define MCF_ESW_IMR_OD1 BIT(7) +#define MCF_ESW_IMR_OD2 BIT(8) +#define MCF_ESW_IMR_LRN BIT(9) + +/* Bit definitions and macros for MCF_ESW_RDSR */ +#define MCF_ESW_RDSR_ADDRESS (x) (((x) & 0x3FFFFFFF) << 2) + +/* Bit definitions and macros for MCF_ESW_TDSR */ +#define MCF_ESW_TDSR_ADDRESS (x) (((x) & 0x3FFFFFFF) << 2) + +/* Bit definitions and macros for MCF_ESW_MRBR */ +#define MCF_ESW_MRBR_SIZE (x) (((x) & 0x000003FF) << 4) + +/* Bit definitions and macros for MCF_ESW_RDAR */ +#define MCF_ESW_RDAR_R_DES_ACTIVE BIT(24) + +/* Bit definitions and macros for MCF_ESW_TDAR */ +#define MCF_ESW_TDAR_X_DES_ACTIVE BIT(24) + +/* Bit definitions and macros for MCF_ESW_LREC0 */ +#define MCF_ESW_LREC0_MACADDR0 (x) (((x) & 0xFFFFFFFF) << 0) + +/* Bit definitions and macros for MCF_ESW_LREC1 */ +#define MCF_ESW_LREC1_MACADDR1 (x) (((x) & 0x0000FFFF) << 0) +#define MCF_ESW_LREC1_HASH (x) (((x) & 0x000000FF) << 16) +#define MCF_ESW_LREC1_SWPORT (x) (((x) & 0x00000003) << 24) + +/* Bit definitions and macros for MCF_ESW_LSR */ +#define MCF_ESW_LSR_DA BIT(0) + +/* ENET Block Guide/ Chapter for the iMX6SX (PELE) address one issue: +* After set ENET_ATCR[Capture], there need some time cycles before the counter +* value is capture in the register clock domain. +* The wait-time-cycles is at least 6 clock cycles of the slower clock between +* the register clock and the 1588 clock. The 1588 ts_clk is fixed to 25Mhz, +* register clock is 66Mhz, so the wait-time-cycles must be greater than 240ns +* (40ns * 6). +*/ +#define FEC_QUIRK_BUG_CAPTURE BIT(10) +/* Controller has only one MDIO bus */ +#define FEC_QUIRK_SINGLE_MDIO BIT(11) + +/* Switch Management functions */ +int mtip_vlan_input_process (struct switch_enet_private *fep, +int port,int mode,unsigned short port_vlanid, +int vlan_verify_en,int vlan_domain_num, +int vlan_domain_port); +int mtip_set_vlan_verification (struct switch_enet_private *fep,int port, +int vlan_domain_verify_en, +int vlan_discard_unknown_en); +int mtip_port_multicast_config (struct switch_enet_private *fep,int port, +int enable); +int mtip_vlan_output_process (struct switch_enet_private *fep,int port, +int mode); +int mtip_port_multicast_config (struct switch_enet_private *fep, +int port,int enable); +void mtip_switch_en_port_separation (struct switch_enet_private *fep); +void mtip_switch_dis_port_separation (struct switch_enet_private *fep); +int mtip_port_broadcast_config (struct switch_enet_private *fep, +int port,int enable); +int mtip_forced_forward (struct switch_enet_private *fep,int port,int enable); +int mtip_port_learning_config (struct switch_enet_private *fep,int port, +int disable,int irq_adj); +int mtip_port_blocking_config (struct switch_enet_private *fep,int port, +int enable); +bool mtip_is_switch_netdev_port (const struct net_device *ndev); +int mtip_register_notifiers (struct switch_enet_private *fep); +void mtip_unregister_notifiers (struct switch_enet_private *fep); +int mtip_port_enable_config (struct switch_enet_private *fep,int port, +int tx_en,int rx_en); +void mtip_clear_atable (struct switch_enet_private *fep); +#endif /* __MTIP_L2SWITCH_H_ */ drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +103
-0@@ -0,0 +1,122 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* L2 switch Controller driver for MTIP block - bridge network interface +* +* Copyright (C) 2025 DENX Software Engineering GmbH +* Lukasz Majewski<[email protected]> +*/ + +#include <linux/netdevice.h> +#include <linux/etherdevice.h> +#include <linux/platform_device.h> + +#include "mtipl2sw.h" +static int mtip_ndev_port_link (struct net_device *ndev, +struct net_device *br_ndev, +struct netlink_ext_ack *extack) +{ +struct mtip_ndev_priv *priv =netdev_priv (ndev), *other_priv; +struct switch_enet_private *fep = priv->fep; +struct net_device *other_ndev; + +/* Check if one port of MTIP switch is already bridged */ +if (fep->br_members && !fep->br_offload) { +/* Get the second bridge ndev */ + other_ndev = fep->ndev[fep->br_members -1 ]; + other_priv =netdev_priv (other_ndev); +if (other_priv->master_dev != br_ndev) { +NL_SET_ERR_MSG_MOD (extack, +"L2 offloading only possible for the same bridge!" ); +return notifier_from_errno (-EOPNOTSUPP ); + } + + fep->br_offload =1 ; +mtip_switch_dis_port_separation (fep); +mtip_clear_atable (fep); + } + +if (!priv->master_dev) + priv->master_dev = br_ndev; + + fep->br_members |=BIT (priv->portnum -1 ); + +dev_dbg (&ndev->dev, +"%s: ndev: %s br: %s fep: 0x%x members: 0x%x offload: %d\n" , + __func__, ndev->name, br_ndev->name, (unsigned int )fep, + fep->br_members, fep->br_offload); + +return NOTIFY_DONE ; +} + +static void mtip_netdevice_port_unlink (struct net_device *ndev) +{ +struct mtip_ndev_priv *priv =netdev_priv (ndev); +struct switch_enet_private *fep = priv->fep; + +dev_dbg (&ndev->dev,"%s: ndev: %s members: 0x%x\n" , __func__, + ndev->name, fep->br_members); + + fep->br_members &= ~BIT (priv->portnum -1 ); + priv->master_dev =NULL ; + +if (!fep->br_members) { + fep->br_offload =0 ; +mtip_switch_en_port_separation (fep); +mtip_clear_atable (fep); + } +} + +/* 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 = ptr; +struct netlink_ext_ack *extack; +int ret =NOTIFY_DONE ; + +if (!mtip_is_switch_netdev_port (ndev)) +return NOTIFY_DONE ; + + extack =netdev_notifier_info_to_extack (&info->info); + +switch (event) { +case NETDEV_CHANGEUPPER : +if (!netif_is_bridge_master (info->upper_dev)) +break ; + +if (info->linking) + ret =mtip_ndev_port_link (ndev, info->upper_dev, + extack); +else +mtip_netdevice_port_unlink (ndev); + +break ; +default : +return NOTIFY_DONE ; + } + +return notifier_from_errno (ret); +} + +static struct notifier_block mtip_netdevice_nb__read_mostly = { + .notifier_call = mtip_netdevice_event,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c line 113
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +10
-0+}; + +int mtip_register_notifiers (struct switch_enet_private *fep) +{ +int ret =0 ; + + ret =register_netdevice_notifier (&mtip_netdevice_nb); +if (ret) { +dev_err (&fep->pdev->dev,"can't register netdevice notifier\n" ); +return ret;
I think this could be dropped
Quoted 171 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +9
-0+ } + +return ret; +} + +void mtip_unregister_notifiers (struct switch_enet_private *fep) +{ +unregister_netdevice_notifier (&mtip_netdevice_nb); +}drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +156
-0@@ -0,0 +1,449 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* L2 switch Controller driver for MTIP block - switch MGNT +* +* Copyright (C) 2025 DENX Software Engineering GmbH +* Lukasz Majewski<[email protected]> +* +* Based on a previous work by: +* +* Copyright 2010-2012 Freescale Semiconductor, Inc. +* Alison Wang ([email protected]) +* Jason Jin ([email protected]) +* +* Copyright (C) 2010-2013 Freescale Semiconductor, Inc. All Rights Reserved. +* Shrek Wu ([email protected]) +*/ + +#include <linux/netdevice.h> +#include <linux/etherdevice.h> +#include <linux/platform_device.h> + +#include "mtipl2sw.h" + +int mtip_vlan_input_process (struct switch_enet_private *fep, +int port,int mode,unsigned short port_vlanid, +int vlan_verify_en,int vlan_domain_num, +int vlan_domain_port) +{ +struct switch_t *fecp = fep->hwp; + +/* Only modes from 1 to 4 are valid*/ +if (mode <0 || mode >4 ) { +dev_err (&fep->pdev->dev, +"%s: VLAN input processing mode (%d) not supported\n" , + __func__, mode); +return -EINVAL ; + } + +if (port <0 || port >2 ) { +dev_err (&fep->pdev->dev,"%s: Port (%d) not supported!\n" , + __func__, port); +return -EINVAL ; + } + +if (vlan_verify_en ==1 && + (vlan_domain_num <0 || vlan_domain_num >32 )) { +dev_err (&fep->pdev->dev,"%s: Domain out of range\n" , __func__); +return -EINVAL ; + } + + fecp->ESW_PID[port] =MCF_ESW_PID_VLANID (port_vlanid); +if (port ==0 ) { +if (vlan_verify_en ==1 ) +writel (MCF_ESW_VRES_VLANID (port_vlanid) | +MCF_ESW_VRES_P0 , + &fecp->ESW_VRES[vlan_domain_num]); + +writel (readl (&fecp->ESW_VIMEN) |MCF_ESW_VIMEN_EN0 , + &fecp->ESW_VIMEN); +writel (readl (&fecp->ESW_VIMSEL) |MCF_ESW_VIMSEL_IM0 (mode), + &fecp->ESW_VIMSEL); + }else if (port ==1 ) { +if (vlan_verify_en ==1 ) +writel (MCF_ESW_VRES_VLANID (port_vlanid) | +MCF_ESW_VRES_P1 , + &fecp->ESW_VRES[vlan_domain_num]); + +writel (readl (&fecp->ESW_VIMEN) |MCF_ESW_VIMEN_EN1 , + &fecp->ESW_VIMEN); +writel (readl (&fecp->ESW_VIMSEL) |MCF_ESW_VIMSEL_IM1 (mode), + &fecp->ESW_VIMSEL); + }else if (port ==2 ) { +if (vlan_verify_en ==1 ) +writel (MCF_ESW_VRES_VLANID (port_vlanid) | +MCF_ESW_VRES_P2 , + &fecp->ESW_VRES[vlan_domain_num]); + +writel (readl (&fecp->ESW_VIMEN) |MCF_ESW_VIMEN_EN2 , + &fecp->ESW_VIMEN); +writel (readl (&fecp->ESW_VIMSEL) |MCF_ESW_VIMSEL_IM2 (mode), + &fecp->ESW_VIMSEL); + } +Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c line 93
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +10
-0+return 0 ; +} + +int mtip_vlan_output_process (struct switch_enet_private *fep,int port, +int mode) +{ +struct switch_t *fecp = fep->hwp; + +if (port <0 || port >2 ) { + dev_err(&fep->pdev->dev, "%s: Port (%d) not supported!\n",
This looks like a lot of copy & paste
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c
Quoted 9 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +9
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
bool enable
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c
Quoted 94 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +94
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Looks like the last parameter is always 0?
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c
Quoted 21 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +21
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
dito
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c
Quoted 4 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +4
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Looks like the last parameter is always 2?
Part of the diff is not shown here. View the raw message.
Re: [net-next v4 4/5] net: mtip: The L2 switch driver for imx287
Hi Stefan,
Quoted 166 lines
Hi Lukasz,
thanks for sending this to linux-arm-kernel
Am 07.04.25 um 16:51 schrieb Lukasz Majewski:
Quoted 161 lines
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).
Signed-off-by Lukasz Majewski<[email protected]>---
Changes for v2:- Remove not needed comments
- Restore udelay(10) for switch reset (such delay is explicitly specifed in the documentation
- AddCOMPILE_TEST
- replace pr_* with dev_*
- Usefor_each_available_child_of_node_scoped()
- Use devm_* function for memory allocation
- Remove printing information about the HW and SW revision of the driver
- Usedevm_regulator_get_optional()
- Change compatible prefix from 'fsl' to more up to date 'nxp'
- Remove .owner =THIS_MODULE
- Usedevm_platform_ioremap_resource(pdev, 0);
- Usedevm_request_irq()
- Usedevm_regulator_get_enable_optional()
- Replaceclk_prepare_enable()anddevm_clk_get()with single call todevm_clk_get_optional_enabled()
- Cleanup error patch when function calls in probe fail
- Refactor themtip_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 atesw_mac_addr_static()
- Removemtip_print_link_status()and replace it withphy_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 removemtip_ndev_setup()
- Use-ENOMEMinstead of -1 return code when allocation fails
- Replacedev_info()withdev_dbg()to reduce number of information print on normal operation
- Return ret instead of 0 frommtip_ndev_init()
- Removefep->mii_timeoutflag from the driver
- Remove not used stop_gpr_* fields inmtip_devinfostruct
- Removeplatform_device_iddescription for mtipl2sw driver
- AddMODULE_DEVICE_TABLE()formtip_of_match
- RemoveMODULE_ALIAS()Changes for v4:
- Rename imx287 with imx28 (as the former is not used in kernel anymore)
- Reorder the place where ENET interface is initialized - without this change theenet_outclock has default (25 MHz) value, which causes issues during reset (RMII's 50 MHz is required for proper PHY reset).
- Use PAUR instead of PAUR register to program MAC address
- Replaceeth_mac_addr()witheth_hw_addr_set()
- Write to HW the randomly generated MAC address (if required)
- Adjust the reset code
- s/read_atable/mtip_read_atable/g and s/write_atable/mtip_write_atable/g
- Addclk_disable()andnetif_napi_del()when errors occur duringmtip_open()- refactor the error handling path.
- Refactor themtip_set_multicast_list()to write (now) correct values to ENET-FEC registers.
- Replacedev_warn()withdev_err()
- UseGPIO_ACTIVE_LOWto indicate polarity in DTS
- Refactor code to check if network device is the switch device
- Removemtip_port_dev_check()
- Refactormtip_ndev_port_link()avoid starting HW offloading for bridge when MTIP ports are parts of two distinct bridges
- Replacedel_timer()withtimer_delete_sync()--- 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 | 1970 +++++++++++++++++ .../net/ethernet/freescale/mtipsw/mtipl2sw.h | 782 +++++++ .../ethernet/freescale/mtipsw/mtipl2sw_br.c | 122 + .../ethernet/freescale/mtipsw/mtipl2sw_mgnt.c | 449 ++++ 9 files changed, 3348 insertions(+)create mode 100644
drivers/net/ethernet/freescale/mtipsw/Kconfigcreate mode 100644drivers/net/ethernet/freescale/mtipsw/Makefilecreate mode 100644drivers/net/ethernet/freescale/mtipsw/mtipl2sw.ccreate mode 100644drivers/net/ethernet/freescale/mtipsw/mtipl2sw.hcreate mode 100644drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.ccreate mode 100644drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.cMAINTAINERS +5
-0@@ -9455,6 +9455,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,imx28-mtip-switch.yamlMAINTAINERS +1
-0+F: drivers/net/ethernet/freescale/mtipsw/* + FREESCALE QORIQ DPAA ETHERNET DRIVER M: Madalin Bucur<[email protected]> L: [email protected](quoted diff) +0
-0b/drivers/net/ethernet/freescale/Kconfig index
a2d7300925a8..056a11c3a74e100644 --- a/drivers/net/ethernet/freescale/Kconfig +++ b/drivers/net/ethernet/freescale/Kconfig @@ -60,6 +60,7 @@ configFEC_MPC52xx_MDIOsource "
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" diff --git
a/drivers/net/ethernet/freescale/Makefile b/drivers/net/ethernet/freescale/Makefile indexde7b31842233..0e6cacb0948a100644 --- a/drivers/net/ethernet/freescale/Makefile +++ b/drivers/net/ethernet/freescale/Makefile @@ -25,3 +25,4 @@ obj-$(CONFIG_FSL_DPAA_ETH) += dpaa/ obj-$(CONFIG_FSL_DPAA2_ETH) += dpaa2/ obj-y += enetc/ +obj-y += mtipsw/ diff --git a/drivers/net/ethernet/freescale/mtipsw/Kconfig b/drivers/net/ethernet/freescale/mtipsw/Kconfig new file mode 100644 index 000000000000..450ff734a321 ---/dev/null+++ b/drivers/net/ethernet/freescale/mtipsw/Kconfig @@ -0,0 +1,13 @@ +#
SPDX-License-Identifier: GPL-2.0-only +configFEC_MTIP_L2SW+ tristate "MoreThanIP L2 switch support to FEC driver"drivers/net/ethernet/freescale/mtipsw/Kconfig new file +4
-0+ depends on OF + depends on NET_SWITCHDEV + depends on BRIDGE + depends on ARCH_MXS || ARCH_MXC || COMPILE_TEST
Quoted 8 lines
Quoted 5 lines
(quoted diff) +2
-0+ help + This enables support for the MoreThan IP L2 switch oni.MX
(quoted diff) +1
-0+ SoCs (e.g. iMX28, vf610). It offloads bridging to thisIP block's
This is confusing. The
Kconfigand most of the code looks prepared for other platforms than i.MX28, but there is only a i.MX28 OF compatible.
I've took the approach to upstream the driver in several steps. The first step is this patch set - add the code for a single platform (imx28).
And Yes, I also have on my desk another board with soc having this IP block (vf610).
However, I will not start any other upstream work until patches from this "step" are not pulled.
(To follow "one things at a time" principle)
Quoted 2 lines
I don't like that
Kconfigpretent something, which is not true.
If you prefer I can remove 'depends on ARCH_MXC' and the vf610 SoC... (only to add it afterwards).
Quoted 32 lines
Quoted 32 lines
(quoted diff) +1
-0+ hardware and allows switch management with standardLinux tools.
(quoted diff) +1
-0+ This switch driver can be used interchangeable with thealready
(quoted diff) +1
-0+ available FEC driver, depending on the use case'srequirments. diff --git a/drivers/net/ethernet/freescale/mtipsw/Makefile b/drivers/net/ethernet/freescale/mtipsw/Makefile new file mode 100644 index 000000000000..4d69db2226a6 ---
/dev/null+++ b/drivers/net/ethernet/freescale/mtipsw/Makefiledrivers/net/ethernet/freescale/mtipsw/Makefile new file +3
-0@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_FEC_MTIP_L2SW) += mtipl2sw.o mtipl2sw_mgnt.omtipl2sw_br.o diff --git
a/drivers/net/ethernet/freescale/mtipsw/mtipl2sw.cb/drivers/net/ethernet/freescale/mtipsw/mtipl2sw.cnew file mode 100644 index 000000000000..08681ecff97a ---/dev/null+++b/drivers/net/ethernet/freescale/mtipsw/mtipl2sw.cdrivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +3
-0@@ -0,0 +1,1970 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* L2 switch Controller (Ethernet L2 switch) driver for MTIP block.
+ *
+ * Copyright (C) 2025 DENX Software Engineering GmbH
+ * Lukasz Majewski<[email protected]>
+ *
+ * Based on a previous work by:
+ *
+ * Copyright 2010-2012 Freescale Semiconductor, Inc.
+ * Alison Wang ([email protected])
Quoted 8 lines
Quoted 5 lines
+ * Jason Jin ([email protected])
+ *
+ * Copyright (C) 2010-2013 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Shrek Wu ([email protected])I'm not sure how to properly handle these old Freescale addresses, which are unlikely to work. A quick search suggests that some of these people may still working for NXP.
I took the credentials from the other drivers which I've used in the past. Those had the Copyright notice as above.
I don't know if I shall change/adjust them.... (and what is the kernel policy).
Quoted 19 lines
Quoted 19 lines
+ */
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +18
-0+ +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/string.h> +#include <linux/errno.h> +#include <linux/iopoll.h> +#include <linux/slab.h> +#include <linux/interrupt.h> +#include <linux/init.h> +#include <linux/delay.h> +#include <linux/netdevice.h> +#include <linux/etherdevice.h> +#include <linux/skbuff.h> +#include <linux/spinlock.h> +#include <linux/bitops.h> +#include <linux/clk.h> +#include <linux/platform_device.h> +#include <linux/phy.h>
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 41
Quoted 7 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +7
-0+#include <linux/of_mdio.h> +#include <linux/gpio/consumer.h> +#include <linux/of_net.h> +#include <linux/of_platform.h> +#include <linux/rtnetlink.h> +#include <linux/regulator/consumer.h> +#include <linux/io.h> Please order alphabetically
Ok.
Quoted 12 lines
Quoted 12 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +12
-0+ +#include "mtipl2sw.h" + +#ifdef CONFIG_ARCH_MXS +static void *swap_buffer (void *bufaddr,int len) +{ +unsigned int *buf = bufaddr; +int i; + +for (i =0 ; i < (len +3 ) /4 ; i++, buf++) + *buf =__swab32 (*buf); +
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 58
Quoted 5 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +5
-0+ return bufaddr; +} +#else +static void *swap_buffer (void *bufaddr,int len) {return NULL ; } +#endif The fec driver also needs to handle this i.MX28 errata, but #ifdef isn't a proper solution. Please handle it as a quirk like in fec driver.
Ok.
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 65
Quoted 7 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +7
-0+ +struct mtip_devinfo { +u32 quirks; +}; + +/* Last read entry from learning interface */ +struct mtip_port_info g_info;Please avoid global variables. I don't see why this is necessary.
I will move its definition to common switch structure.
Quoted 25 lines
Quoted 25 lines
(quoted diff) +2
-0+ +static void mtip_enet_init(struct switch_enet_private *fep, intport) +{
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+void __iomem *enet_addr = fep->enet_addr; +u32 mii_speed, holdtime, tmp; + +if (port ==2 ) + enet_addr +=MCF_ESW_ENET_PORT_OFFSET ; + + tmp =MCF_FEC_RCR_PROM |MCF_FEC_RCR_MII_MODE | +MCF_FEC_RCR_MAX_FL (1522 ); + + if (fep->phy_interface[port - 1] ==
PHY_INTERFACE_MODE_RMII)drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +11
-0+ tmp |=MCF_FEC_RCR_RMII_MODE ; + +writel (tmp, enet_addr +MCF_FEC_RCR ); + +/* TCR */ +writel (MCF_FEC_TCR_FDEN , enet_addr +MCF_FEC_TCR ); + +/* ECR */ +writel (MCF_FEC_ECR_ETHER_EN , enet_addr +MCF_FEC_ECR ); + +/* Set MII speed to 2.5 MHz
Quoted 8 lines
Quoted 7 lines
(quoted diff) +2
-0+ */ + mii_speed = DIV_ROUND_UP(clk_get_rate(fep->clk_ipg),5000000);
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +3
-0+ mii_speed--; + +/* The i.MX28 and i.MX6 types have another filed in the MSCR (aka
field ?
I will remove this comment altogether.
Quoted 50 lines
Quoted 50 lines
(quoted diff) +1
-0+ * MII_SPEED) register that defines the MDIO output holdtime. Earlier
(quoted diff) +1
-0+ * versions are RAZ there, so just ignore the differenceand write the
(quoted diff) +2
-0+ * register always. + * The minimal hold time according to IEE802.3 (clause 22)is 10 ns.
(quoted diff) +1
-0+ * HOLDTIME + 1 is the number of clk cycles the fec isholding the
(quoted diff) +2
-0+ * output. + * The HOLDTIME bitfield takes values between 0 and 7(inclusive).
(quoted diff) +1
-0+ * Given that ceil(clkrate / 5000000) <= 64, thecalculation for
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +3
-0+* holdtime cannot result in a value greater than 3. +*/ + holdtime = DIV_ROUND_UP(clk_get_rate(fep->clk_ipg),100000000) - 1; +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +18
-0+ fep->phy_speed = mii_speed <<1 | holdtime <<8 ; + +writel (fep->phy_speed, enet_addr +MCF_FEC_MSCR ); +} + +static int mtip_setup_mac (struct net_device *dev) +{ +struct mtip_ndev_priv *priv =netdev_priv (dev); +struct switch_enet_private *fep = priv->fep; +unsigned char *iap, tmpaddr[ETH_ALEN ]; + +/* Use MAC address from DTS */ + iap = &fep->mac[priv->portnum -1 ][0 ]; + +/* Use MAC address set by bootloader */ +if (!is_valid_ether_addr (iap)) { + *((unsigned long *)&tmpaddr[0 ]) = + be32_to_cpu(readl(fep->enet_addr +
MCF_FEC_PALR));drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+ *((unsigned short *)&tmpaddr[4 ]) = +be16_to_cpu (readl (fep->enet_addr + +MCF_FEC_PAUR ) >>16 ); + iap = &tmpaddr[0 ]; + } + +/* Use random MAC address */ +if (!is_valid_ether_addr (iap)) { +eth_hw_addr_random (dev); + dev_info(&fep->pdev->dev, "Using random MACaddress: %pM\n",
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +2
-0+ dev->dev_addr); + iap = (unsigned char *)dev->dev_addr;
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 143
Quoted 7 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +7
-0+ } + +/* Adjust MAC if using macaddr (and increment if needed) */ +eth_hw_addr_gen (dev, iap, priv->portnum -1 ); + +return 0 ; +}Why does this function has a return value, but it always returns 0 ?
This may be for some historical reasons. I will change it to void.
Quoted 143 lines
Quoted 143 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +5
-0+ +/** +* crc8_calc - calculate CRC for MAC storage +* +* @pmacaddress: A 6-byte array with the MAC address. The first byte is
+ * the first byte transmitted.
+ *
+ * Calculate Galois Field Arithmetic CRC for Polynom x^8+x^2+x+1.
+ * It omits the final shift in of 8 zeroes a "normal" CRC would do
+ * (getting the remainder).
+ *
+ * Examples (hexadecimal values):<br>+ * 10-11-12-13-14-15 => CRC=0xc2 + * 10-11-cc-dd-ee-00 => CRC=0xe6+ *
+ * Return: The 8-bit CRC in bits 7:0
+ */drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +17
-0+static int crc8_calc (unsigned char *pmacaddress) +{ +int byt;/* byte index */ +int bit;/* bit index */ +int crc =0x12 ; +int inval; + +for (byt =0 ; byt <6 ; byt++) { + inval = (((int )pmacaddress[byt]) &0xff ); +/* shift bit 0 to bit 8 so all our bits +* travel through bit 8 +* (simplifies below calc) +*/ + inval <<=8 ; + +for (bit =0 ; bit <8 ; bit++) { +/* next input bit comes into d7 after shift */
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +14
-0+ crc |= inval &0x100 ; +if (crc &0x01 ) +/* before shift */ + crc ^=0x1c0 ; + + crc >>=1 ; + inval >>=1 ; + } + } +/* upper bits are clean as we shifted in zeroes! */ +return crc; +} + +static void mtip_read_atable(struct switch_enet_private *fep, intindex,
(quoted diff) +1
-0+ 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 mtip_write_atable(struct switch_enet_private *fep, intindex,
(quoted diff) +1
-0+ unsigned long write_lo, unsignedlong
write_hi) +{drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +18
-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 ); +} + +/** +* mtip_portinfofifo_read - Read element from receive FIFO +* +* @fep: Structure describing switch +* +* Read one element from the HW receive FIFO (Queue) +* if available and return it. +* +* Return: mtip_port_info or NULL if no data is available. +*/ +static +struct mtip_port_info *mtip_portinfofifo_read(struct
switch_enet_private*fep) +{drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +6
-0+struct switch_t *fecp = fep->hwp; +u32 tmp; + + tmp =readl (&fecp->ESW_LSR); +if (tmp ==0 ) { + dev_dbg(&fep->pdev->dev, "%s: ESW_LSR = 0x%x\n",
__func__, tmp);drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +7
-0+return NULL ; + } + +/* read word from FIFO */ + g_info.maclo =readl (&fecp->ESW_LREC0); +if (g_info.maclo ==0 ) { + dev_dbg(&fep->pdev->dev, "%s: mac lo 0x%x\n",
__func__,drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +14
-0+ g_info.maclo); +return NULL ; + } + +/* read 2nd word from FIFO */ + tmp =readl (&fecp->ESW_LREC1); + g_info.machi = tmp &0xffff ; + g_info.hash = (tmp >>16 ) &0xff ; + g_info.port = (tmp >>24 ) &0xf ; + +return &g_info; +} + +static int mtip_atable_get_entry_port_number(struct
switch_enet_private*fep,(quoted diff) +1
-0+ unsigned char
*mac_addr, u8 *port) +{drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +7
-0+int block_index, block_index_end, entry; +unsigned long mac_addr_lo, mac_addr_hi; +unsigned long read_lo, read_hi; + + mac_addr_lo = (unsigned long)((mac_addr[3] << 24) | + (mac_addr[2] << 16) | + (mac_addr[1] << 8) |mac_addr[0]);
(quoted diff) +1
-0+ mac_addr_hi = (unsigned long)((mac_addr[5] << 8) |(mac_addr[4])); +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +5
-0+ block_index =GET_BLOCK_PTR (crc8_calc (mac_addr)); + block_index_end = block_index +ATABLE_ENTRY_PER_SLOT ; + +/* now search all the entries in the selected block */ + for (entry = block_index; entry < block_index_end;entry++) {
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +8
-0+mtip_read_atable (fep, entry, &read_lo, &read_hi); + *port =0xff ; + +if (read_lo == mac_addr_lo && + ((read_hi &0x0000ffff ) == + (mac_addr_hi &0x0000ffff ))) { +/* found the correct address */ + if ((read_hi & (1 << 16)) && (!(read_hi &(1 << 17))))
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +4
-0+ *port =AT_EXTRACT_PORT (read_hi); +break ; + } + }
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 282
Quoted 7 lines
(quoted diff) +2
-0+ + dev_dbg(&fep->pdev->dev, "%s: MAC: %pM PORT: 0x%x\n",
__func__,drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +4
-0+ mac_addr, *port); + +return 0 ; +}ditto
Ok.
Quoted 83 lines
Quoted 83 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +22
-0+ +/* Clear complete MAC Look Up Table */ +void mtip_clear_atable (struct switch_enet_private *fep) +{ +int index; + +for (index =0 ; index <2048 ; index++) +mtip_write_atable (fep, index,0 ,0 ); +} + +/** +* mtip_update_atable_static - Update switch static address table +* +* @mac_addr: Pointer to the array containing MAC address to +* be put as static entry +* @port: Port bitmask numbers to be added in static entry, +* valid values are 1-7 +* @priority: The priority for the static entry in table +* +* Updates MAC address lookup table with a static entry. +* +* Searches if the MAC address is already there in the block and replaces
+ * the older entry with the new one. If MAC address is not there then puts
+ * a new entry in the first empty slot available in the block.
+ *
+ * Return: 0 for a successful update else-ENOSPCwhen no slot available
+ */
+static int mtip_update_atable_static(unsigned char*mac_addr, unsigned int port,(quoted diff) +2
-0+ unsigned int priority, + struct switch_enet_private*fep) +{
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +9
-0+unsigned long block_index, entry, index_end; +unsigned long write_lo, write_hi; +unsigned long read_lo, read_hi; + + write_lo = (unsigned long )((mac_addr[3 ] <<24 ) | + (mac_addr[2 ] <<16 ) | + (mac_addr[1 ] <<8 ) | + mac_addr[0 ]); + write_hi = (unsigned long)(0 | (port <<
AT_SENTRY_PORTMASK_shift) |(quoted diff) +1
-0+ (priority <<
AT_SENTRY_PRIO_shift) |drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +5
-0+ (AT_ENTRY_TYPE_STATIC << + AT_ENTRY_TYPE_shift) | + (AT_ENTRY_RECORD_VALID << + AT_ENTRY_VALID_shift) | + (mac_addr[5] << 8) |(mac_addr[4])); +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +13
-0+ block_index =GET_BLOCK_PTR (crc8_calc (mac_addr)); + index_end = block_index +ATABLE_ENTRY_PER_SLOT ; +/* Now search all the entries in the selected block */ +for (entry = block_index; entry < index_end; entry++) { +mtip_read_atable (fep, entry, &read_lo, &read_hi); +/* MAC address matched, so update the +* existing entry +* even if its a dynamic one +*/ +if (read_lo == write_lo && + ((read_hi &0x0000ffff ) == + (write_hi &0x0000ffff ))) { + mtip_write_atable(fep, entry, write_lo,
write_hi);drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +6
-0+return 0 ; + }else if (!(read_hi & (1 <<16 ))) { +/* Fill this empty slot (valid bit zero), +* assuming no holes in the block +*/ + mtip_write_atable(fep, entry, write_lo,
write_hi);drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +9
-0+ fep->at_curr_entries++; +return 0 ; + } + } + +/* No space available for this static entry */ +return -ENOSPC ; +} +
Quoted 8 lines
Quoted 7 lines
(quoted diff) +2
-0+static int mtip_update_atable_dynamic1(unsigned long write_lo, + unsigned long write_hi, int
block_index,drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +3
-0+unsigned int port, + unsigned int curr_time, + struct switch_enet_private*fep)
Looks like the return type should be bool ?
+1
Quoted 52 lines
Quoted 52 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +27
-0+{ +unsigned long entry, index_end; +unsigned long read_lo, read_hi; +int time, timeold, indexold; +unsigned long tmp; + +/* prepare update port and timestamp */ + tmp =AT_ENTRY_RECORD_VALID << AT_ENTRY_VALID_shift; + tmp |=AT_ENTRY_TYPE_DYNAMIC << AT_ENTRY_TYPE_shift; + tmp |= curr_time << AT_DENTRY_TIME_shift; + tmp |= port << AT_DENTRY_PORT_shift; + tmp |= write_hi; + +/* linear search through all slot +* entries and update if found +*/ + index_end = block_index +ATABLE_ENTRY_PER_SLOT ; +/* Now search all the entries in the selected block */ +for (entry = block_index; entry < index_end; entry++) { +mtip_read_atable (fep, entry, &read_lo, &read_hi); +if (read_lo == write_lo && + ((read_hi &0x0000ffff ) == + (write_hi &0x0000ffff ))) { +/* found correct address, +* update timestamp. +*/ + mtip_write_atable(fep, entry, write_lo,tmp); +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +9
-0+return 0 ; + }else if (!(read_hi & (1 <<16 ))) { +/* slot is empty, then use it +* for new entry +* Note: There are no holes, +* therefore cannot be any +* more that need to be compared. +*/ + mtip_write_atable(fep, entry, write_lo,tmp);
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +14
-0+/* statistics (we do it between writing +* .hi an .lo due to +* hardware limitation... +*/ + fep->at_curr_entries++; +/* newly inserted */ + +return 1 ; + } + } + +/* No more entry available in block overwrite oldest */ + timeold =0 ; + indexold =0 ;
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 418
Quoted 6 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +4
-0+for (entry = block_index; entry < index_end; entry++) { +mtip_read_atable (fep, entry, &read_lo, &read_hi); + time =AT_EXTRACT_TIMESTAMP (read_hi); + dev_err(&fep->pdev->dev, "%s : time %x currtime%x\n",
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +1
-0+ __func__, time, curr_time);This doesn't look a like a helpful error message. The fact it's within a for loop, makes it even worse.
This shall be dev_dbg();
Quoted 26 lines
Quoted 26 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +13
-0+ time =TIMEDELTA (curr_time, time); +if (time > timeold) { +/* is it older ? */ + timeold = time; + indexold = entry; + } + } + +mtip_write_atable (fep, indexold, write_lo, tmp); + +/* Statistics (do it inbetween writing to .lo and .hi */ + fep->at_block_overflows++; + dev_err(&fep->pdev->dev, "%s update time,
at_block_overflows%x\n",drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +8
-0+ __func__, fep->at_block_overflows); +/* newly inserted */ +return 1 ; +} + +/* dynamicms MAC address table learn and migration */ +static int +mtip_atable_dynamicms_learn_migration(struct switch_enet_private*fep,
(quoted diff) +1
-0+ int curr_time, unsigned char*mac,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +1
-0+ u8 *rx_port)
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 447
Quoted 6 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +6
-0+{ +unsigned long rx_mac_lo, rx_mac_hi; +struct mtip_port_info *port_info; +int index, inserted =0 ; +unsigned long flags; +u8 port =0xFF ;Sometimes the code uses capital letter and sometimes small letter for hex, please keep it consistent.
I've replaced all the hex constants to capital letters.
Quoted 38 lines
Quoted 38 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +5
-0+ +spin_lock_irqsave (&fep->learn_lock, flags); + +if (mac &&is_valid_ether_addr (mac)) { + rx_mac_lo = (unsigned long)((mac[3] << 24) |(mac[2] << 16) |
(quoted diff) +1
-0+ (mac[1] << 8) |mac[0]);
(quoted diff) +1
-0+ rx_mac_hi = (unsigned long)((mac[5] << 8) |(mac[4]));
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +7
-0+ } + + port_info =mtip_portinfofifo_read (fep); +while (port_info) { +/* get block index from lookup table */ + index =GET_BLOCK_PTR (port_info->hash); + inserted =mtip_update_atable_dynamic1(port_info->maclo,
+port_info->machi,drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +2
-0+ index, +
port_info->port,(quoted diff) +1
-0+ curr_time,fep); +
(quoted diff) +1
-0+ if (mac && is_valid_ether_addr(mac) && port ==
0xFF) {drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +3
-0+if (rx_mac_lo == port_info->maclo && + rx_mac_hi == port_info->machi) { +/* The newly learned MAC is the source of
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +7
-0+* our filtered frame. +*/ + port = (u8 )port_info->port; + } + } + port_info =mtip_portinfofifo_read (fep); + }
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 483
Quoted 6 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +6
-0+ +if (rx_port) + *rx_port = port; + +spin_unlock_irqrestore (&fep->learn_lock, flags); +return 0 ;Either there should be some kind of error handling within this function or the return code should be dropped.
It can be void.
Quoted 4 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 486
Quoted 3 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +3
-0+} + +/* The timer should create an interrupt every 4 seconds*/ Does this comment still apply? I suggest to drop it.
+1
Quoted 25 lines
Quoted 25 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +3
-0+static void mtip_aging_timer (struct timer_list *t) +{ + struct switch_enet_private *fep = from_timer(fep, t,
timer_aging); +(quoted diff) +2
-0+ if (fep) + fep->curr_time =
mtip_timeincrement(fep->curr_time); +(quoted diff) +2
-0+ mod_timer(&fep->timer_aging, + jiffies +
msecs_to_jiffies(LEARNING_AGING_INTERVAL)); +}drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +8
-0+ +static void esw_mac_addr_static (struct switch_enet_private *fep) +{ +int i; + +for (i =0 ; i <SWITCH_EPORT_NUMBER ; i++) + mtip_update_atable_static((unsigned char *) + fep->ndev[i]->dev_addr,7, 7, fep); +}
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +6
-0+ +static void mtip_config_switch (struct switch_enet_private *fep) +{ +struct switch_t *fecp = fep->hwp; + +esw_mac_addr_static (fep);
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 518
Quoted 7 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +7
-0+ +writel (0 , &fecp->ESW_BKLR); + +/* Do NOT disable learning */ +mtip_port_learning_config (fep,0 ,0 ,0 ); +mtip_port_learning_config (fep,1 ,0 ,0 ); +mtip_port_learning_config (fep,2 ,0 ,0 );Looks like the last 2 parameter are always 0?
Those functions are defined in mtipl2sw_mgnt.c file.
I've followed the way legacy (i.e. vendor) driver has defined them. In this particular case the last '0' is to not enable interrupt for learning.
Quoted 6 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 523
Quoted 5 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +5
-0+ +/* Disable blocking */ +mtip_port_blocking_config (fep,0 ,0 ); +mtip_port_blocking_config (fep,1 ,0 ); +mtip_port_blocking_config (fep,2 ,0 );Looks like the last parameter is always 0?
It is to disable blocking.
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 530
Quoted 7 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +7
-0+ +writel (MCF_ESW_IMR_TXF |MCF_ESW_IMR_RXF , + &fecp->ESW_IMR); + +mtip_port_enable_config (fep,0 ,1 ,1 ); +mtip_port_enable_config (fep,1 ,1 ,1 ); +mtip_port_enable_config (fep,2 ,1 ,1 );Looks like the last 2 parameter are always 1?
Quoted 5 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 534
Quoted 4 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +4
-0+ +mtip_port_broadcast_config (fep,0 ,1 ); +mtip_port_broadcast_config (fep,1 ,1 ); +mtip_port_broadcast_config (fep,2 ,1 );Looks like the last parameter is always 1?
For the above - please look into the mtipl2sw_mgnt.c file.
Quoted 76 lines
Quoted 76 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +13
-0+ +/* Disable multicast receive on port 0 (MGNT) */ +mtip_port_multicast_config (fep,0 ,0 ); +mtip_port_multicast_config (fep,1 ,1 ); +mtip_port_multicast_config (fep,2 ,1 ); + +/* Setup VLANs to provide port separation */ +if (!fep->br_offload) +mtip_switch_en_port_separation (fep); +} + +static netdev_tx_t mtip_start_xmit_port(struct sk_buff *skb, + struct net_device *dev,int port) +{
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +12
-0+struct mtip_ndev_priv *priv =netdev_priv (dev); +struct switch_enet_private *fep = priv->fep; +struct switch_t *fecp = fep->hwp; +unsigned short status; +unsigned long flags; +struct cbd_t *bdp; +void *bufaddr; + +spin_lock_irqsave (&fep->hw_lock, flags); + +if (!fep->link[0 ] && !fep->link[1 ]) { +/* Link is down or autonegotiation is in progress. */
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +13
-0+netif_stop_queue (dev); +spin_unlock_irqrestore (&fep->hw_lock, flags); +return NETDEV_TX_BUSY ; + } + +/* Fill in a Tx ring entry */ + bdp = fep->cur_tx; + + status = bdp->cbd_sc; + +if (status &BD_ENET_TX_READY ) { +/* All transmit buffers are full. Bail out. +* This should not happen, since dev->tbusy should be set.
(quoted diff) +2
-0+ */ + dev_err(&fep->pdev->dev, "%s: tx queue full!.\n",
dev->name);drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +32
-0+spin_unlock_irqrestore (&fep->hw_lock, flags); +return NETDEV_TX_BUSY ; + } + +/* Clear all of the status flags */ + status &= ~BD_ENET_TX_STATS ; + +/* Set buffer length and buffer pointer */ + bufaddr = skb->data; + bdp->cbd_datlen = skb->len; + +/* On some FEC implementations data must be aligned on +* 4-byte boundaries. Use bounce buffers to copy data +* and get it aligned. +*/ +if ((unsigned long )bufaddr &MTIP_ALIGNMENT ) { +unsigned int index; + + index = bdp - fep->tx_bd_base; +memcpy (fep->tx_bounce[index], + (void *)skb->data, skb->len); + bufaddr = fep->tx_bounce[index]; + } + +swap_buffer (bufaddr, skb->len); + +/* Save skb pointer. */ + fep->tx_skbuff[fep->skb_cur] = skb; + + dev->stats.tx_bytes += skb->len; + fep->skb_cur = (fep->skb_cur +1 ) &TX_RING_MOD_MASK ; +
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 613
Quoted 6 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +6
-0+/* Push the data cache so the CPM does not get stale memory +* data. +*/ + bdp->cbd_bufaddr =dma_map_single (&fep->pdev->dev, bufaddr, +MTIP_SWITCH_TX_FRSIZE , +DMA_TO_DEVICE );I would expect some kind of error handling here (e.g.
dma_mapping_error).
I've added it to v5.
Quoted 70 lines
Quoted 70 lines
(quoted diff) +2
-0+ + /* Send it on its way. Tell FEC it's ready, interruptwhen done,
(quoted diff) +1
-0+ * it's the last BD of the frame, and to put the CRC onthe end.
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+*/ + + status |= (BD_ENET_TX_READY |BD_ENET_TX_INTR + |BD_ENET_TX_LAST |BD_ENET_TX_TC ); + bdp->cbd_sc = status; + +netif_trans_update (dev); +skb_tx_timestamp (skb); + +/* For port separation - force sending via specified port */
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +34
-0+if (!fep->br_offload && port !=0 ) +mtip_forced_forward (fep, port,1 ); + +/* Trigger transmission start */ +writel (MCF_ESW_TDAR_X_DES_ACTIVE , &fecp->ESW_TDAR); + +/* If this was the last BD in the ring, +* start at the beginning again. +*/ +if (status &BD_ENET_TX_WRAP ) + bdp = fep->tx_bd_base; +else + bdp++; + +if (bdp == fep->dirty_tx) { + fep->tx_full =1 ; +netif_stop_queue (dev); + } + + fep->cur_tx = bdp; +spin_unlock_irqrestore (&fep->hw_lock, flags); + +return NETDEV_TX_OK ; +} + +static netdev_tx_t mtip_start_xmit (struct sk_buff *skb, +struct net_device *dev) +{ +struct mtip_ndev_priv *priv =netdev_priv (dev); + +return mtip_start_xmit_port (skb, dev, priv->portnum); +} + +static void mtip_configure_enet_mii(struct switch_enet_private*fep, int port) +{
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +19
-0+struct phy_device *phydev = fep->phy_dev[port -1 ]; +struct net_device *dev = fep->ndev[port -1 ]; +void __iomem *enet_addr = fep->enet_addr; +int duplex = fep->full_duplex[port -1 ]; +u32 tmp; + +if (port ==2 ) + enet_addr +=MCF_ESW_ENET_PORT_OFFSET ; + +/* ECR */ +writel (MCF_FEC_ECR_MAGIC_ENA , enet_addr +MCF_FEC_ECR ); + +/* EMRBR */ +writel (PKT_MAXBLR_SIZE , enet_addr +MCF_FEC_EMRBR ); + +/* set the receive and transmit BDs ring base to +* hardware registers(ERDSR & ETDSR) +*/ +writel (fep->bd_dma, enet_addr +MCF_FEC_ERDSR );
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 686
Quoted 7 lines
(quoted diff) +1
-0+ writel((unsigned long)fep->bd_dma + sizeof(struct cbd_t) *
RX_RING_SIZE,drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +5
-0+ enet_addr + MCF_FEC_ETDSR); + +#ifdef CONFIG_ARCH_MXS +writel (fep->phy_speed, enet_addr +MCF_FEC_MSCR ); +#endif Please handle it via quirk / platform data, not #ifdef
This register can be written always for all supported platforms.
Quoted 138 lines
Quoted 138 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +53
-0+/* EIR */ +writel (0 , enet_addr +MCF_FEC_EIR ); + +/* IAUR */ +writel (0 , enet_addr +MCF_FEC_IAUR ); + +/* IALR */ +writel (0 , enet_addr +MCF_FEC_IALR ); + +/* GAUR */ +writel (0 , enet_addr +MCF_FEC_GAUR ); + +/* GALR */ +writel (0 , enet_addr +MCF_FEC_GALR ); + +/* EMRBR */ +writel (PKT_MAXBLR_SIZE , enet_addr +MCF_FEC_EMRBR ); + +/* EIMR */ +writel (0 , enet_addr +MCF_FEC_EIMR ); + +/* PALR PAUR */ +/* Set the station address for the ENET Adapter */ +writel (dev->dev_addr[3 ] | + dev->dev_addr[2 ] <<8 | + dev->dev_addr[1 ] <<16 | + dev->dev_addr[0 ] <<24 , enet_addr +MCF_FEC_PALR ); +writel (dev->dev_addr[5 ] <<16 | + (dev->dev_addr[4 ] + (unsigned char )(0 )) <<24 , + enet_addr +MCF_FEC_PAUR ); + +/* RCR */ + tmp =readl (enet_addr +MCF_FEC_RCR ); +if (phydev && phydev->speed ==SPEED_100 ) + tmp &= ~MCF_FEC_RCR_RMII_10BASET ; +else + tmp |=MCF_FEC_RCR_RMII_10BASET ; + +if (duplex ==DUPLEX_FULL ) + tmp &= ~MCF_FEC_RCR_DRT ; +else + tmp |=MCF_FEC_RCR_DRT ; + +writel (tmp, enet_addr +MCF_FEC_RCR ); + +/* TCR */ +if (duplex ==DUPLEX_FULL ) +writel (0x1c , enet_addr +MCF_FEC_TCR ); +else +writel (0x18 , enet_addr +MCF_FEC_TCR ); + +/* ECR */ + writel(readl(enet_addr + MCF_FEC_ECR) |
MCF_FEC_ECR_ETHER_EN,drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +4
-0+ enet_addr + MCF_FEC_ECR); +} + +/* This function is called to start or restart the FEC during a link
+ * change. This only happens when switching between half and full
+ * duplex.
+ */
+static void mtip_switch_restart(structnet_device*dev, int duplex0,drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +72
-0+ int duplex1) +{ +struct mtip_ndev_priv *priv =netdev_priv (dev); +struct switch_enet_private *fep = priv->fep; +struct switch_t *fecp = fep->hwp; +int i; + +/* Perform a reset. We should wait for this. */ +writel (MCF_ESW_MODE_SW_RST , &fecp->ESW_MODE); + +/* Delay of 10us specified in the documentation to perform +* SW reset by the switch internally. +*/ +udelay (10 ); +writel (MCF_ESW_MODE_STATRST , &fecp->ESW_MODE); +writel (MCF_ESW_MODE_SW_EN , &fecp->ESW_MODE); + +/* Management port configuration, +* make port 0 as management port +*/ +writel (0 , &fecp->ESW_BMPC); + +/* Clear any outstanding interrupt */ +writel (0xffffffff , &fecp->ESW_ISR); + +/* Set backpressure threshold to minimize discarded frames +* during due to congestion. +*/ +writel (P0BC_THRESHOLD , &fecp->ESW_P0BCT); + +/* Set maximum receive buffer size */ +writel (PKT_MAXBLR_SIZE , &fecp->ESW_MRBR); + +/* Set receive and transmit descriptor base */ +writel (fep->bd_dma, &fecp->ESW_RDSR); +writel ((unsigned long )fep->bd_dma + +sizeof (struct cbd_t ) *RX_RING_SIZE , + &fecp->ESW_TDSR); + + fep->cur_tx = fep->tx_bd_base; + fep->cur_rx = fep->rx_bd_base; + fep->dirty_tx = fep->cur_tx; + +/* Reset SKB transmit buffers */ + fep->skb_cur =0 ; + fep->skb_dirty =0 ; +for (i =0 ; i <=TX_RING_MOD_MASK ; i++) { +if (fep->tx_skbuff[i]) { +dev_kfree_skb_any (fep->tx_skbuff[i]); + fep->tx_skbuff[i] =NULL ; + } + } + + fep->full_duplex[0 ] = duplex0; + fep->full_duplex[1 ] = duplex1; + +mtip_configure_enet_mii (fep,1 ); +mtip_configure_enet_mii (fep,2 ); +mtip_clear_atable (fep); + +/* And last, enable the transmit and receive processing */ +writel (MCF_ESW_RDAR_R_DES_ACTIVE , &fecp->ESW_RDAR); + +/* Enable interrupts we wish to service */ +writel (0xffffffff , &fecp->ESW_ISR); +writel (MCF_ESW_IMR_TXF |MCF_ESW_IMR_RXF , + &fecp->ESW_IMR); + +mtip_config_switch (fep); +} + +static void mtip_timeout(struct net_device *dev, unsigned inttxqueue) +{
(quoted diff) +1
-0+ struct mtip_ndev_priv *priv = netdev_priv(dev);
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 828
Quoted 7 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +7
-0+struct switch_enet_private *fep = priv->fep; +#ifdef SWITCH_DEBUG +struct cbd_t *bdp; +int i; +#endif + dev->stats.tx_errors++; +#ifdef SWITCH_DEBUG Please try to get the rid of these #ifdef.
IS_ENABLED()?
Ok.
Quoted 62 lines
Quoted 62 lines
(quoted diff) +1
-0+ dev_info(&dev->dev, "%s: transmit timed out.\n",
dev->name);(quoted diff) +2
-0+ dev_info(&dev->dev, + "Ring data dump: cur_tx %lx%s, dirty_tx %lx
cur_rx: %lx\n",(quoted diff) +1
-0+ (unsigned long)fep->cur_tx, fep->tx_full ? "(full)" : "",
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +17
-0+ (unsigned long )fep->dirty_tx, + (unsigned long)fep->cur_rx); + + bdp = fep->tx_bd_base; +dev_info (&dev->dev," tx: %u buffers\n" ,TX_RING_SIZE ); +for (i =0 ; i <TX_RING_SIZE ; i++) { +dev_info (&dev->dev," %08x: %04x %04x %08x\n" , + (uint )bdp, bdp->cbd_sc, bdp->cbd_datlen, + (int )bdp->cbd_bufaddr); + bdp++; + } + + bdp = fep->rx_bd_base; +dev_info (&dev->dev," rx: %lu buffers\n" , + (unsigned long )RX_RING_SIZE ); +for (i =0 ; i <RX_RING_SIZE ; i++) { + dev_info(&dev->dev, " %08x: %04x %04x %08x\n",(uint)bdp,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +32
-0+ bdp->cbd_sc, bdp->cbd_datlen, + (int)bdp->cbd_bufaddr); + bdp++; + } +#endif + +rtnl_lock (); +if (netif_device_present (dev) ||netif_running (dev)) { +napi_disable (&fep->napi); +netif_tx_lock_bh (dev); +mtip_switch_restart (dev, fep->full_duplex[0 ], + fep->full_duplex[1 ]); +netif_tx_wake_all_queues (dev); +netif_tx_unlock_bh (dev); +napi_enable (&fep->napi); + } +rtnl_unlock (); +} + +static irqreturn_t mtip_interrupt(int irq, void *ptr_fep) +{ + struct switch_enet_private *fep = ptr_fep; + struct switch_t *fecp = fep->hwp; + irqreturn_t ret = IRQ_NONE; + u32 int_events, int_imask; + + /* Get the interrupt events that caused us to be here */ + do { + int_events = readl(&fecp->ESW_ISR); + writel(int_events, &fecp->ESW_ISR); + + if (int_events & (MCF_ESW_ISR_RXF |
MCF_ESW_ISR_TXF)) {drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +4
-0+ ret =IRQ_HANDLED ; +/* Disable the RX interrupt */ +if (napi_schedule_prep (&fep->napi)) { + int_imask =readl (&fecp->ESW_IMR);
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 891
Quoted 6 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +6
-0+ int_imask &= ~MCF_ESW_IMR_RXF ; +writel (int_imask, &fecp->ESW_IMR); +__napi_schedule (&fep->napi); + } + } + }while (int_events);This looks bad, in case of bad hardware / timing behavior this interrupt handler will loop forever.
The 'writel(int_events, &fecp->ESW_ISR);'
clears the interrupts, so after reading them and clearing (by writing the same value), the int_events shall be 0.
Also, during probe the IRQ mask for switch IRQ is written, so only expected (and served) interrupts are delivered.
Quoted 120 lines
Quoted 120 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +22
-0+ +return ret; +} + +static void mtip_switch_tx (struct net_device *dev) +{ +struct mtip_ndev_priv *priv =netdev_priv (dev); +struct switch_enet_private *fep = priv->fep; +unsigned short status; +struct sk_buff *skb; +unsigned long flags; +struct cbd_t *bdp; + +spin_lock_irqsave (&fep->hw_lock, flags); + bdp = fep->dirty_tx; + +while (((status = bdp->cbd_sc) &BD_ENET_TX_READY ) ==0 ) { +if (bdp == fep->cur_tx && fep->tx_full ==0 ) +break ; + + dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr, + MTIP_SWITCH_TX_FRSIZE,
DMA_TO_DEVICE);drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +8
-0+ bdp->cbd_bufaddr =0 ; + skb = fep->tx_skbuff[fep->skb_dirty]; +/* Check for errors */ +if (status & (BD_ENET_TX_HB |BD_ENET_TX_LC | +BD_ENET_TX_RL |BD_ENET_TX_UN | +BD_ENET_TX_CSL )) { + dev->stats.tx_errors++; +if (status &BD_ENET_TX_HB )/* No heartbeat */
(quoted diff) +2
-0+ dev->stats.tx_heartbeat_errors++; + if (status & BD_ENET_TX_LC) /* Latecollision */
(quoted diff) +2
-0+ dev->stats.tx_window_errors++; + if (status & BD_ENET_TX_RL) /* Retranslimit */
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +4
-0+ dev->stats.tx_aborted_errors++; +if (status &BD_ENET_TX_UN )/* Underrun */ + dev->stats.tx_fifo_errors++; +if (status &BD_ENET_TX_CSL )/* Carrier lost */
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +8
-0+ dev->stats.tx_carrier_errors++; + }else { + dev->stats.tx_packets++; + } + +if (status &BD_ENET_TX_READY ) + dev_err(&fep->pdev->dev, + "Enet xmit interrupt andTX_READY.\n"); +
(quoted diff) +1
-0+ /* Deferred means some collisions occurred duringtransmit,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +6
-0+* but we eventually sent the packet OK. +*/ +if (status &BD_ENET_TX_DEF ) + dev->stats.collisions++; + +/* Free the sk buffer associated with this last transmit */
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +3
-0+dev_consume_skb_irq (skb); + fep->tx_skbuff[fep->skb_dirty] =NULL ; + fep->skb_dirty = (fep->skb_dirty + 1) &
TX_RING_MOD_MASK; +(quoted diff) +1
-0+ /* Update pointer to next buffer descriptor to betransmitted */
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +6
-0+if (status &BD_ENET_TX_WRAP ) + bdp = fep->tx_bd_base; +else + bdp++; + +/* Since we have freed up a buffer, the ring is no longer
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +13
-0+* full. +*/ +if (fep->tx_full) { + fep->tx_full =0 ; +if (netif_queue_stopped (dev)) +netif_wake_queue (dev); + } + } + fep->dirty_tx = bdp; +spin_unlock_irqrestore (&fep->hw_lock, flags); +} + +/* During a receive, the cur_rx points to the current incoming buffer.
+ * When we update through the ring, if the next incoming buffer has
+ * not been given to the system, we just set the empty indicator,
+ * effectively tossing the packet.
+ */
+static intmtip_switch_rx(struct net_device *dev, int budget, int *port)+{drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +16
-0+struct mtip_ndev_priv *priv =netdev_priv (dev); +struct switch_enet_private *fep = priv->fep; +struct switch_t *fecp = fep->hwp; +unsigned short status, pkt_len; +struct net_device *pndev; +u8 *data, rx_port =0xFF ; +struct ethhdr *eth_hdr; +int pkt_received =0 ; +struct sk_buff *skb; +unsigned long flags; +struct cbd_t *bdp; + +spin_lock_irqsave (&fep->hw_lock, flags); + +/* First, grab all of the stats for the incoming packet. +* These get messed up if we get called due to a busy condition.
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +9
-0+*/ + bdp = fep->cur_rx; + +while (!((status = bdp->cbd_sc) &BD_ENET_RX_EMPTY )) { +if (pkt_received >= budget) +break ; + + pkt_received++; +/* Since we have allocated space to hold a
Quoted 8 lines
Quoted 6 lines
complete frame,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +4
-0+* the last indicator should be set. +*/ +if ((status &BD_ENET_RX_LAST ) ==0 ) + dev_info(&dev->dev, "SWITCH ENET: rcv isnot +last\n");
This looks more like a warning than an info message. Btw this is within a loop, it should be limited via
_onceor_ratelimited.
Yes. I will use dev_warn_ratelimited();
Quoted 82 lines
Quoted 82 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +6
-0+ +if (!fep->usage_count) + goto rx_processing_done; + +/* Check for errors. */ + if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH |
BD_ENET_RX_NO|drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +3
-0+ BD_ENET_RX_CR | BD_ENET_RX_OV)) { + dev->stats.rx_errors++; + if (status & (BD_ENET_RX_LG |
BD_ENET_RX_SH)) {drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +4
-0+/* Frame too long or too short. */ + dev->stats.rx_length_errors++; + } +if (status &BD_ENET_RX_NO )/* Frame alignment */
(quoted diff) +2
-0+ dev->stats.rx_frame_errors++; + if (status & BD_ENET_RX_CR) /* CRCError */
(quoted diff) +2
-0+ dev->stats.rx_crc_errors++; + if (status & BD_ENET_RX_OV) /* FIFOoverrun */
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +5
-0+ dev->stats.rx_fifo_errors++; + } + +/* Report late collisions as a frame error. +* On this error, the BD is closed, but we don't know what we
(quoted diff) +1
-0+ * have in the buffer. So, just drop this frameon the floor.
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +19
-0+*/ +if (status &BD_ENET_RX_CL ) { + dev->stats.rx_errors++; + dev->stats.rx_frame_errors++; + goto rx_processing_done; + } + +/* Process the incoming frame */ + pkt_len = bdp->cbd_datlen; + data = (__u8 *)__va (bdp->cbd_bufaddr); + +dma_unmap_single (&fep->pdev->dev, bdp->cbd_bufaddr, + bdp->cbd_datlen,DMA_FROM_DEVICE ); + +swap_buffer (data, pkt_len); +if (data) { + eth_hdr = (struct ethhdr *)data; + mtip_atable_get_entry_port_number(fep, +
eth_hdr->h_source,
+&rx_port);drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +2
-0+if (rx_port ==0xFF ) +mtip_atable_dynamicms_learn_migration(fep,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +6
-0+ fep->curr_time, + eth_hdr->h_source, + &rx_port); + } + + if (!fep->br_offload && (rx_port == 1 || rx_port== 2))
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +9
-0+ pndev = fep->ndev[rx_port -1 ]; + else + pndev = dev; + + *port = rx_port; + pndev->stats.rx_packets++; + pndev->stats.rx_bytes += pkt_len; + +/* This does 16 byte alignment, exactly what we need.
(quoted diff) +1
-0+ * The packet length includes FCS, but we don'twant to
(quoted diff) +1
-0+ * include that when passing upstream as it messesup
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +3
-0+* bridging applications. +*/ + skb = netdev_alloc_skb(pndev, pkt_len +
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1074
Quoted 7 lines
NET_IP_ALIGN);drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +3
-0+if (unlikely (!skb)) { + dev_dbg(&fep->pdev->dev, + "%s: Memory squeeze, droppingpacket.\n",
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +2
-0+ pndev->name); + pndev->stats.rx_dropped++;Shouldn't we make sure that the loop is left under this circumstances?
Yes, we shall exit the loop with proper error.
Quoted 8 lines
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +4
-0+ }else { +skb_reserve (skb,NET_IP_ALIGN ); +skb_put (skb, pkt_len);/* Make room */ + skb_copy_to_linear_data(skb, data,
pkt_len);drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +3
-0+ skb->protocol =eth_type_trans (skb, pndev); +napi_gro_receive (&fep->napi, skb); + }
Quoted 8 lines
Quoted 6 lines
(quoted diff) +2
-0+ + bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev,data,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +2
-0+ bdp->cbd_datlen, +
DMA_FROM_DEVICE);I would expect some kind of error handling here (e.g.
dma_mapping_error).
Yes, correct this error shall be checked.
Quoted 112 lines
Quoted 112 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +16
-0+ + rx_processing_done: +/* Clear the status flags for this buffer */ + status &= ~BD_ENET_RX_STATS ; + +/* Mark the buffer empty */ + status |=BD_ENET_RX_EMPTY ; + bdp->cbd_sc = status; + +/* Update BD pointer to next entry */ +if (status &BD_ENET_RX_WRAP ) + bdp = fep->rx_bd_base; +else + bdp++; + +/* Doing this here will keep the FEC running while we process
(quoted diff) +1
-0+ * incoming frames. On a heavily loaded network,we should be
(quoted diff) +1
-0+ * able to keep up at the expense of systemresources.
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +3
-0+*/ +writel (MCF_ESW_RDAR_R_DES_ACTIVE , &fecp->ESW_RDAR); + }/* while (!((status = bdp->cbd_sc) & BD_ENET_RX_EMPTY)) */ +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +21
-0+writel (bdp, &fep->cur_rx); +spin_unlock_irqrestore (&fep->hw_lock, flags); + +return pkt_received; +} + +static void mtip_adjust_link(struct net_device *dev) +{ + struct mtip_ndev_priv *priv = netdev_priv(dev); + struct switch_enet_private *fep = priv->fep; + struct phy_device *phy_dev; + int status_change = 0, idx; + unsigned long flags; + + spin_lock_irqsave(&fep->hw_lock, flags); + + idx = priv->portnum - 1; + phy_dev = fep->phy_dev[idx]; + + /* Duplex link change */ + if (phy_dev->link && fep->full_duplex[idx] !=
phy_dev->duplex) {drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +3
-0+if (idx ==0 ) + mtip_switch_restart(dev, phy_dev->duplex, +fep->full_duplex[!idx]);
(quoted diff) +2
-0+ else + mtip_switch_restart(dev,fep->full_duplex[!idx],
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+ phy_dev->duplex); + status_change =1 ; + } + +/* Link on or off change */ +if (phy_dev->link != fep->link[idx]) { + fep->link[idx] = phy_dev->link; +if (phy_dev->link) { +if (idx ==0 ) + mtip_switch_restart(dev,
phy_dev->duplex,
+
fep->full_duplex[!idx]);(quoted diff) +2
-0+ else + mtip_switch_restart(dev,fep->full_duplex[!idx],
+phy_dev->duplex);(quoted diff) +1
-0+ /* if link becomes up and tx be stopped,start it */
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +20
-0+if (netif_queue_stopped (dev)) { +netif_start_queue (dev); +netif_wake_queue (dev); + } + } + status_change =1 ; + } + +spin_unlock_irqrestore (&fep->hw_lock, flags); + +if (status_change) +phy_print_status (phy_dev); +} + +static int mtip_mdio_wait (struct switch_enet_private *fep) +{ +uint ievent =0 ; +int ret; + + ret = readl_poll_timeout_atomic(fep->enet_addr +
MCF_FEC_EIR, ievent,(quoted diff) +1
-0+ ievent & MCF_ENET_MII, 2,30000);
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +7
-0+if (!ret) +writel (MCF_ENET_MII , fep->enet_addr +MCF_FEC_EIR ); + +return ret; +} + +static int mtip_mdio_read(struct mii_bus *bus, int mii_id, intregnum) +{
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +7
-0+struct switch_enet_private *fep = bus->priv; +int ret; + +/* start a read op */ +writel (FEC_MMFR_ST |FEC_MMFR_OP_READ | +FEC_MMFR_PA (mii_id) |FEC_MMFR_RA (regnum) | +FEC_MMFR_TA , fep->enet_addr +MCF_FEC_MII_DATA );
Quoted 8 lines
Quoted 6 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +5
-0+ +/* wait for end of transfer */ + ret =mtip_mdio_wait (fep); +if (ret) { + dev_err(&fep->pdev->dev, "MTIP: MDIO readtimeout\n");
Not an expert, but does it make sense to provide more context here (e.g.
mii_id, ...)?
Ok, I will add more verbose output.
Quoted 26 lines
Quoted 24 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +5
-0+return ret; + } + +/* return value */ + return FEC_MMFR_DATA(readl(fep->enet_addr +
MCF_FEC_MII_DATA)); +}(quoted diff) +2
-0+ +static int mtip_mdio_write(struct mii_bus *bus, int mii_id, intregnum,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +15
-0+ u16 value) +{ +struct switch_enet_private *fep = bus->priv; +int ret; + +/* start a write op */ +writel (FEC_MMFR_ST |FEC_MMFR_OP_WRITE | +FEC_MMFR_PA (mii_id) |FEC_MMFR_RA (regnum) | +FEC_MMFR_TA |FEC_MMFR_DATA (value), + fep->enet_addr +MCF_FEC_MII_DATA ); + +/* wait for end of transfer */ + ret =mtip_mdio_wait (fep); +if (ret) { + dev_err(&fep->pdev->dev, "MTIP: MDIO writeQuoted 1 line
timeout\n");
dito
Quoted 5 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1216
Quoted 4 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +4
-0+return ret; + } + +return 0 ;I think we can make return ret here and drop the one before.
+1
Quoted 127 lines
Quoted 127 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +11
-0+} + +static int mtip_mii_probe (struct net_device *dev) +{ +struct mtip_ndev_priv *priv =netdev_priv (dev); +struct switch_enet_private *fep = priv->fep; +struct phy_device *phy_dev =NULL ; +int port_idx = priv->portnum -1 ; + +if (fep->phy_np[port_idx]) { + phy_dev = of_phy_connect(dev,fep->phy_np[port_idx],
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +2
-0+ &mtip_adjust_link, 0, +fep->phy_interface[port_idx]);
(quoted diff) +2
-0+ if (!phy_dev) { + netdev_err(dev, "Unable to connect tophy\n");
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +11
-0+return -ENODEV ; + } + } + +phy_set_max_speed (phy_dev,100 ); + fep->phy_dev[port_idx] = phy_dev; + fep->link[port_idx] =0 ; + fep->full_duplex[port_idx] =0 ; + + dev_dbg(&dev->dev, + "MTIP PHY driver [%s] (mii_bus:phy_addr=%s,irq=%d)\n",
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +11
-0+ fep->phy_dev[port_idx]->drv->name, +phydev_name (fep->phy_dev[port_idx]), + fep->phy_dev[port_idx]->irq); + +return 0 ; +} + +static int mtip_mdiobus_reset (struct mii_bus *bus) +{ +if (!bus || !bus->reset_gpiod) { + dev_err(&bus->dev, "Reset GPIO pin notprovided!\n");
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +7
-0+return -EINVAL ; + } + +gpiod_set_value_cansleep (bus->reset_gpiod,0 ); + +/* Extra time to allow: +* 1. GPIO RESET pin go high to prevent situation where its value is
(quoted diff) +2
-0+ * "LOW" as it is NOT configured. + * 2. The ENET CLK to stabilize before GPIO RESET isasserted
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +5
-0+*/ +usleep_range (200 ,300 ); + +gpiod_set_value_cansleep (bus->reset_gpiod,1 ); + usleep_range(bus->reset_delay_us, bus->reset_delay_us +1000);
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +16
-0+gpiod_set_value_cansleep (bus->reset_gpiod,0 ); + +if (bus->reset_post_delay_us >0 ) +usleep_range (bus->reset_post_delay_us, + bus->reset_post_delay_us +1000 ); + +return 0 ; +} + +static int mtip_mii_init (struct switch_enet_private *fep, +struct platform_device *pdev) +{ +struct device_node *node; +int err = -ENXIO ; + +/* Clear MMFR to avoid to generate MII event by writing MSCR.
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +51
-0+* MII event generation condition: +* - writing MSCR: +* - mmfr[31:0]_not_zero & mscr[7:0]_is_zero & +* mscr_reg_data_in[7:0] != 0 +* - writing MMFR: +* - mscr[7:0]_not_zero +*/ +writel (0 , fep->hwp +MCF_FEC_MII_DATA ); +/* Clear any pending transaction complete indication */ +writel (MCF_ENET_MII , fep->enet_addr +MCF_FEC_EIR ); + + fep->mii_bus =mdiobus_alloc (); +if (!fep->mii_bus) { + err = -ENOMEM ; + goto err_out; + } + + fep->mii_bus->name ="mtip_mii_bus" ; + fep->mii_bus->read = mtip_mdio_read; + fep->mii_bus->write = mtip_mdio_write; + fep->mii_bus->reset = mtip_mdiobus_reset; +snprintf (fep->mii_bus->id,MII_BUS_ID_SIZE ,"%x" ,0 ); + fep->mii_bus->priv = fep; + fep->mii_bus->parent = &pdev->dev; + + node =of_get_child_by_name (pdev->dev.of_node,"mdio" ); +if (node) +dev_err (&fep->pdev->dev,"%s: PHY name: %s\n" , + __func__, node->name); + + err =of_mdiobus_register (fep->mii_bus, node); +if (node) +of_node_put (node); +if (err) + goto err_out_free_mdiobus; + +return 0 ; + +err_out_free_mdiobus: +mdiobus_free (fep->mii_bus); +err_out: +return err; +} + +static void mtip_mii_remove (struct switch_enet_private *fep) +{ +int i; + +for (i =0 ; i <SWITCH_EPORT_NUMBER ; i++) { +if (fep->phy_np[i]) +of_node_put (fep->phy_np[i]);
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1341
Quoted 7 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +7
-0+ +if (fep->phy_dev[i]) +phy_disconnect (fep->phy_dev[i]); + } + +mdiobus_unregister (fep->mii_bus); +kfree (fep->mii_bus->irq);This looks fishy. AFAIK this is a fixed array. Are you sure?
As I've moved to "poll" based MDIO this can be safely removed.
Quoted 59 lines
Quoted 59 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +29
-0+mdiobus_free (fep->mii_bus); +} + +static void mtip_get_drvinfo (struct net_device *dev, +struct ethtool_drvinfo *info) +{ +struct mtip_ndev_priv *priv =netdev_priv (dev); +struct switch_enet_private *fep = priv->fep; + +strscpy (info->driver, fep->pdev->dev.driver->name, +sizeof (info->driver)); +strscpy (info->bus_info,dev_name (&dev->dev), +sizeof (info->bus_info)); +} + +static void mtip_free_buffers (struct net_device *dev) +{ +struct mtip_ndev_priv *priv =netdev_priv (dev); +struct switch_enet_private *fep = priv->fep; +struct sk_buff *skb; +struct cbd_t *bdp; +int i; + + bdp = fep->rx_bd_base; +for (i =0 ; i <RX_RING_SIZE ; i++) { + skb = fep->rx_skbuff[i]; + +if (bdp->cbd_bufaddr) + dma_unmap_single(&fep->pdev->dev,
bdp->cbd_bufaddr,drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +29
-0+MTIP_SWITCH_RX_FRSIZE , + DMA_FROM_DEVICE); +if (skb) +dev_kfree_skb (skb); + bdp++; + } + + bdp = fep->tx_bd_base; +for (i =0 ; i <TX_RING_SIZE ; i++) +kfree (fep->tx_bounce[i]); +} + +static int mtip_alloc_buffers (struct net_device *dev) +{ +struct mtip_ndev_priv *priv =netdev_priv (dev); +struct switch_enet_private *fep = priv->fep; +struct sk_buff *skb; +struct cbd_t *bdp; +int i; + + bdp = fep->rx_bd_base; +for (i =0 ; i <RX_RING_SIZE ; i++) { + skb =netdev_alloc_skb (dev,MTIP_SWITCH_RX_FRSIZE ); +if (!skb) { +mtip_free_buffers (dev); +return -ENOMEM ; + } + fep->rx_skbuff[i] = skb; +
Quoted 8 lines
Quoted 6 lines
(quoted diff) +1
-0+ bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev,
skb->data,
+MTIP_SWITCH_RX_FRSIZE,
+DMA_FROM_DEVICE);I would expect some kind of error handling here (e.g.
dma_mapping_error).
+1
Quoted 27 lines
Quoted 27 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +11
-0+ bdp->cbd_sc =BD_ENET_RX_EMPTY ; + bdp++; + } + +/* Set the last buffer to wrap. */ + bdp--; + bdp->cbd_sc |=BD_SC_WRAP ; + + bdp = fep->tx_bd_base; +for (i =0 ; i <TX_RING_SIZE ; i++) { + fep->tx_bounce[i] = kmalloc(MTIP_SWITCH_TX_FRSIZE,
GFP_KERNEL); +drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +15
-0+ bdp->cbd_sc =0 ; + bdp->cbd_bufaddr =0 ; + bdp++; + } + +/* Set the last buffer to wrap. */ + bdp--; + bdp->cbd_sc |=BD_SC_WRAP ; + +return 0 ; +} + +static int mtip_rx_napi (struct napi_struct *napi,int budget) +{ +struct mtip_ndev_priv *priv =netdev_priv (napi->dev);
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1436
Quoted 7 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +7
-0+struct switch_enet_private *fep = priv->fep; +struct switch_t *fecp = fep->hwp; +int pkts, port; + + pkts =mtip_switch_rx (napi->dev, budget, &port); +if (!fep->br_offload && + (port ==1 || port ==2 ) && fep->ndev[port -1 ])(port > 0) && fep->ndev[port - 1])
This needs to be kept as is - only when port is set to 1 or 2 (after reading the switch internal register) this shall be executed.
(port also can be 0xFF or 0x3 -> then we shall send frame to both egress ports).
This code is responsible for port separation when bridge HW offloading is disabled.
Quoted 14 lines
Quoted 14 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +14
-0+mtip_switch_tx (fep->ndev[port -1 ]); + else + mtip_switch_tx(napi->dev); + +if (pkts < budget) { +napi_complete_done (napi, pkts); +/* Set default interrupt mask for L2 switch */ +writel (MCF_ESW_IMR_RXF |MCF_ESW_IMR_TXF , + &fecp->ESW_IMR); + } +return pkts; +} + +static int mtip_open (struct net_device *dev)
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1457
Quoted 7 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +7
-0+{ +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);Yes, it's unlikely but this could fail
Yes, I've added proper code to handle it.
Quoted 80 lines
Quoted 80 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+netif_napi_add (dev, &fep->napi, mtip_rx_napi); + + ret =mtip_alloc_buffers (dev); +if (ret) + goto mtip_alloc_buffers_err; + } + + 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 deviceis
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +67
-0+* re-opened). +*/ + ret =mtip_mii_probe (dev); +if (ret) + goto mtip_mii_probe_err; + +phy_start (fep->phy_dev[port_idx]); + +if (fep->usage_count ==0 ) { +napi_enable (&fep->napi); +mtip_switch_restart (dev,1 ,1 ); + + fep->curr_time =0 ; +netif_start_queue (dev); + } + + fep->usage_count++; +return 0 ; + + mtip_mii_probe_err: +mtip_free_buffers (dev); + mtip_alloc_buffers_err: +if (fep->usage_count ==0 ) { +netif_napi_del (&fep->napi); +clk_disable (fep->clk_ipg); + } +return ret; +}; + +static int mtip_close (struct net_device *dev) +{ +struct mtip_ndev_priv *priv =netdev_priv (dev); +struct switch_enet_private *fep = priv->fep; +int idx = priv->portnum -1 ; + + fep->link[idx] =0 ; + +if (fep->phy_dev[idx]) { +phy_stop (fep->phy_dev[idx]); +netif_stop_queue (dev); +phy_disconnect (fep->phy_dev[idx]); + fep->phy_dev[idx] =NULL ; + } + +if (fep->usage_count ==1 ) { +napi_disable (&fep->napi); +netif_napi_del (&fep->napi); +mtip_free_buffers (dev); +clk_disable (fep->clk_ipg); + } + + fep->usage_count--; + +return 0 ; +} + +#define FEC_HASH_BITS 6/* #bits in hash */ +static void mtip_set_multicast_list (struct net_device *dev) +{ +struct mtip_ndev_priv *priv =netdev_priv (dev); +unsigned int hash_high =0 , hash_low =0 , crc; +struct switch_enet_private *fep = priv->fep; +void __iomem *enet_addr = fep->enet_addr; +struct netdev_hw_addr *ha; +unsigned char hash; + +if (priv->portnum ==2 )
Quoted 8 lines
Quoted 6 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +5
-0+ enet_addr +=MCF_ESW_ENET_PORT_OFFSET ; + +if (dev->flags &IFF_PROMISC ) { +/* Promisc mode is required for switch */ + dev_info(&dev->dev, "%s: IFF_PROMISC\n",
__func__);I don't think we should do log on info level, which can be triggered via userspace.
Ok.
Quoted 7 lines
Quoted 6 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +5
-0+return ; + } + +if (dev->flags &IFF_ALLMULTI ) { + dev_info(&dev->dev, "%s: IFF_ALLMULTI\n",
__func__);ditto
Ok.
Quoted 67 lines
Quoted 67 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +3
-0+ +/* Allow all multicast addresses */ + writel(0xffffffff, enet_addr +
MCF_FEC_GRP_HASH_TABLE_HIGH);(quoted diff) +1
-0+ writel(0xffffffff, enet_addr +
MCF_FEC_GRP_HASH_TABLE_LOW); +drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +9
-0+return ; + } + +netdev_for_each_mc_addr (ha, dev) { +/* calculate crc32 value of mac address */ + crc =ether_crc_le (dev->addr_len, ha->addr); + +/* only upper 6 bits (FEC_HASH_BITS) are used +* which point to specific bit in the hash registers
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +34
-0+*/ + hash = (crc >> (32 -FEC_HASH_BITS )) &0x3f ; + +if (hash >31 ) + hash_high |=1 << (hash -32 ); +else + hash_low |=1 << hash; + } + +writel (hash_high, enet_addr +MCF_FEC_GRP_HASH_TABLE_HIGH ); +writel (hash_low, enet_addr +MCF_FEC_GRP_HASH_TABLE_LOW ); +} + +static int mtip_set_mac_address (struct net_device *dev,void *p) +{ +struct mtip_ndev_priv *priv =netdev_priv (dev); +struct switch_enet_private *fep = priv->fep; +void __iomem *enet_addr = fep->enet_addr; +struct sockaddr *addr = p; + +if (!is_valid_ether_addr (addr->sa_data)) +return -EADDRNOTAVAIL ; +eth_hw_addr_set (dev, addr->sa_data); + +if (priv->portnum ==2 ) + enet_addr +=MCF_ESW_ENET_PORT_OFFSET ; + +writel (dev->dev_addr[3 ] | (dev->dev_addr[2 ] <<8 ) | + (dev->dev_addr[1 ] <<16 ) | (dev->dev_addr[0 ] <<24 ), + enet_addr +MCF_FEC_PALR ); +writel ((dev->dev_addr[5 ] <<16 ) | (dev->dev_addr[4 ] <<24 ), + enet_addr +MCF_FEC_PAUR ); + + return mtip_update_atable_static((unsigned char*)dev->dev_addr,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +16
-0+ 7, 7, fep); +} + +static const struct ethtool_ops mtip_ethtool_ops = { + .get_link_ksettings = phy_ethtool_get_link_ksettings, + .set_link_ksettings = phy_ethtool_set_link_ksettings, + .get_drvinfo = mtip_get_drvinfo, + .get_link = ethtool_op_get_link, + .get_ts_info = ethtool_op_get_ts_info, +}; + +static const struct net_device_ops mtip_netdev_ops = { + .ndo_open = mtip_open, + .ndo_stop = mtip_close, + .ndo_start_xmit = mtip_start_xmit, + .ndo_set_rx_mode = mtip_set_multicast_list,
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1616
Quoted 7 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +7
-0+ .ndo_tx_timeout = mtip_timeout, + .ndo_set_mac_address = mtip_set_mac_address, +}; + +bool mtip_is_switch_netdev_port (const struct net_device *ndev) +{ +if (ndev->netdev_ops == &mtip_netdev_ops)I think we can directly return the result of the expression
+1
Quoted 130 lines
Quoted 130 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +6
-0+return true; + +return false; +} + +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_err(&fep->pdev->dev, "No suitable DMAavailable\n");
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +5
-0+return ret; + } + +/* Allocate memory for buffer descriptors */ + cbd_base = dma_alloc_coherent(&fep->pdev->dev, PAGE_SIZE,
&fep->bd_dma,drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +23
-0+ GFP_KERNEL); +if (!cbd_base) +return -ENOMEM ; + +/* Set receive and transmit descriptor base */ + fep->rx_bd_base = cbd_base; + fep->tx_bd_base = cbd_base +RX_RING_SIZE ; + +/* Initialize the receive buffer descriptors */ + bdp = fep->rx_bd_base; +for (i =0 ; i <RX_RING_SIZE ; i++) { + bdp->cbd_sc =0 ; + bdp++; + } + +/* Set the last buffer to wrap */ + bdp--; + bdp->cbd_sc |=BD_SC_WRAP ; + +/* ...and the same for transmmit */ + bdp = fep->tx_bd_base; +for (i =0 ; i <TX_RING_SIZE ; i++) { +/* Initialize the BD for every fragment in the page */
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +31
-0+ bdp->cbd_sc =0 ; + bdp->cbd_bufaddr =0 ; + bdp++; + } + +/* Set the last buffer to wrap */ + bdp--; + bdp->cbd_sc |=BD_SC_WRAP ; + +return 0 ; +} + +static void mtip_ndev_cleanup (struct switch_enet_private *fep) +{ +int i; + +for (i =0 ; i <SWITCH_EPORT_NUMBER ; i++) { +if (fep->ndev[i]) { +unregister_netdev (fep->ndev[i]); +free_netdev (fep->ndev[i]); + } + } +} + +static int mtip_ndev_init (struct switch_enet_private *fep) +{ +struct mtip_ndev_priv *priv; +int i, ret =0 ; + +for (i =0 ; i <SWITCH_EPORT_NUMBER ; i++) { + fep->ndev[i] = alloc_netdev(sizeof(struct
mtip_ndev_priv),(quoted diff) +1
-0+ fep->ndev_name[i],
NET_NAME_USER,drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +27
-0+ ether_setup); +if (!fep->ndev[i]) { + ret = -ENOMEM ; +break ; + } + + fep->ndev[i]->ethtool_ops = &mtip_ethtool_ops; + fep->ndev[i]->netdev_ops = &mtip_netdev_ops; + + priv =netdev_priv (fep->ndev[i]); + priv->dev = fep->ndev[i]; + priv->fep = fep; + priv->portnum = i +1 ; + fep->ndev[i]->irq = fep->irq; + + ret =mtip_setup_mac (fep->ndev[i]); +if (ret) { +dev_err (&fep->ndev[i]->dev, +"%s: ndev %s MAC setup err: %d\n" , + __func__, fep->ndev[i]->name, ret); +break ; + } + + ret =register_netdev (fep->ndev[i]); +if (ret) { + dev_err(&fep->ndev[i]->dev, + "%s: ndev %s register err: %d\n",
__func__,drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +4
-0+ fep->ndev[i]->name, ret); +break ; + } + dev_dbg(&fep->ndev[i]->dev, "%s: MTIP eth L2switch %pM\n",
(quoted diff) +1
-0+ fep->ndev[i]->name,fep->ndev[i]->dev_addr);
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +15
-0+ } + +if (ret) +mtip_ndev_cleanup (fep); + +return ret; +} + +static int mtip_parse_of (struct switch_enet_private *fep, +struct device_node *np) +{ +struct device_node *p; +unsigned int port_num; +int ret; +
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1744
Quoted 7 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +7
-0+ p =of_find_node_by_name (np,"ethernet-ports" ); + +for_each_available_child_of_node_scoped (p, port) { +if (of_property_read_u32 (port,"reg" , &port_num)) +continue ; + + fep->n_ports = port_num;Don't we need a check against
SWITCH_EPORT_NUMBERhere?
+1
Quoted 3 lines
Quoted 2 lines
(quoted diff) +1
-0+ of_get_mac_address(port, &fep->mac[port_num -1][0]);
This can fail
I will add:
ret = of_get_mac_address(port, &fep->mac[port_num - 1][0]); if (ret)
dev_warn(dev, "of_get_mac_address(%pOF) failed\n", port);
as it is also valid to not have the mac address defined in DTS (then some random based value is generated).
Quoted 1,179 lines
Quoted 1,179 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +3
-0+ + ret = of_property_read_string(port, "label", +&fep->ndev_name[port_num - 1]);
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +3
-0+if (ret <0 ) { + dev_err(&fep->pdev->dev, + "%s: Cannot get ethernet port name(%d)!\n",
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +5
-0+ __func__, ret); + goto of_get_err; + } + + ret = of_get_phy_mode(port,&fep->phy_interface[port_num - 1]);
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +3
-0+if (ret <0 ) { + dev_err(&fep->pdev->dev, + "%s: Cannot get PHY mode (%d)!\n",
__func__,drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +6
-0+ ret); + goto of_get_err; + } + + fep->phy_np[port_num - 1] = of_parse_phandle(port, +"phy-handle", 0);
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +16
-0+ } + + of_get_err: +of_node_put (p); + +return 0 ; +} + +static int mtip_sw_learning (void *arg) +{ +struct switch_enet_private *fep = arg; + +while (!kthread_should_stop ()) { +set_current_state (TASK_INTERRUPTIBLE ); +/* check learning record valid */ + mtip_atable_dynamicms_learn_migration(fep,
fep->curr_time,drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +58
-0+ NULL, NULL); +schedule_timeout (HZ /100 ); + } + +return 0 ; +} + +static void mtip_mii_unregister (struct switch_enet_private *fep) +{ +mdiobus_unregister (fep->mii_bus); +mdiobus_free (fep->mii_bus); +} + +static const struct mtip_devinfo mtip_imx28_l2switch_info = { + .quirks =FEC_QUIRK_BUG_CAPTURE |FEC_QUIRK_SINGLE_MDIO , +}; + +static const struct of_device_id mtipl2_of_match[] = { + { .compatible ="nxp,imx28-mtip-switch" , + .data = &mtip_imx28_l2switch_info}, + {/* sentinel */ } +} +MODULE_DEVICE_TABLE (of, mtipl2_of_match); + +static int mtip_sw_probe (struct platform_device *pdev) +{ +struct device_node *np = pdev->dev.of_node; +const struct of_device_id *of_id; +struct switch_enet_private *fep; +struct mtip_devinfo *dev_info; +struct switch_t *fecp; +int ret; + + fep =devm_kzalloc (&pdev->dev,sizeof (*fep),GFP_KERNEL ); +if (!fep) +return -ENOMEM ; + + of_id =of_match_node (mtipl2_of_match, pdev->dev.of_node); +if (of_id) { + dev_info = (struct mtip_devinfo *)of_id->data; +if (dev_info) + fep->quirks = dev_info->quirks; + } + + fep->pdev = pdev; +platform_set_drvdata (pdev, fep); + + fep->enet_addr =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (fep->enet_addr)) +return PTR_ERR (fep->enet_addr); + + fep->irq =platform_get_irq (pdev,0 ); +if (fep->irq <0 ) +return fep->irq; + + ret =mtip_parse_of (fep, np); +if (ret <0 ) { + dev_err(&pdev->dev, "%s: OF parse error (%d)!\n",
__func__,drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +9
-0+ ret); +return ret; + } + +/* Create an Ethernet device instance. +* The switch lookup address memory starts at 0x800FC000 +*/ + fep->hwp_enet = fep->enet_addr; + fecp = (struct switch_t *)(fep->enet_addr +
ENET_SWI_PHYS_ADDR_OFFSET); +drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +5
-0+ fep->hwp = fecp; + fep->hwentry = (struct mtip_addr_table_t *) + ((unsigned long )fecp +MCF_ESW_LOOKUP_MEM_OFFSET ); + + ret = devm_regulator_get_enable_optional(&pdev->dev,"phy");
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +3
-0+if (ret) + return dev_err_probe(&pdev->dev, ret, + "Unable to get and enable'phy'\n"); +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +3
-0+ fep->clk_ipg =devm_clk_get_enabled (&pdev->dev,"ipg" ); +if (IS_ERR (fep->clk_ipg)) + return dev_err_probe(&pdev->dev,
PTR_ERR(fep->clk_ipg),(quoted diff) +1
-0+ "Unable to acquire 'ipg'clock\n"); +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +3
-0+ fep->clk_ahb =devm_clk_get_enabled (&pdev->dev,"ahb" ); +if (IS_ERR (fep->clk_ahb)) + return dev_err_probe(&pdev->dev,
PTR_ERR(fep->clk_ahb),(quoted diff) +1
-0+ "Unable to acquire 'ahb'clock\n"); +
(quoted diff) +1
-0+ fep->clk_enet_out =devm_clk_get_optional_enabled(&pdev->dev,
+
"enet_out");(quoted diff) +2
-0+ if (IS_ERR(fep->clk_enet_out)) + return dev_err_probe(&pdev->dev,
PTR_ERR(fep->clk_enet_out),(quoted diff) +1
-0+ "Unable to acquire 'enet_out'clock\n"); +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +9
-0+/* setup MII interface for external switch ports */ +mtip_enet_init (fep,1 ); +mtip_enet_init (fep,2 ); + +spin_lock_init (&fep->learn_lock); +spin_lock_init (&fep->hw_lock); +spin_lock_init (&fep->mii_lock); + + ret = devm_request_irq(&pdev->dev, fep->irq,
mtip_interrupt, 0,drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +12
-0+ "mtip_l2sw", fep); +if (ret) +return dev_err_probe (&pdev->dev, fep->irq, +"Could not alloc IRQ\n" ); + + ret =mtip_register_notifiers (fep); +if (ret) +return ret; + + ret =mtip_ndev_init (fep); +if (ret) { + dev_err(&pdev->dev, "%s: Failed to create virtualndev (%d)\n",
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +7
-0+ __func__, ret); + goto ndev_init_err; + } + + ret =mtip_switch_dma_init (fep); +if (ret) { + dev_err(&pdev->dev, "%s: ethernet switch init fail(%d)!\n",
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +7
-0+ __func__, ret); + goto dma_init_err; + } + + ret =mtip_mii_init (fep, pdev); +if (ret) { + dev_err(&pdev->dev, "%s: Cannot init phy bus(%d)!\n",
__func__,drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +7
-0+ ret); + goto mii_init_err; + } +/* setup timer for learning aging function */ +timer_setup (&fep->timer_aging, mtip_aging_timer,0 ); + mod_timer(&fep->timer_aging, + jiffies +
msecs_to_jiffies(LEARNING_AGING_INTERVAL)); +(quoted diff) +1
-0+ fep->task = kthread_run(mtip_sw_learning, fep,"
mtip_l2sw_learning");drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +3
-0+if (IS_ERR (fep->task)) { + ret =PTR_ERR (fep->task); + dev_err(&pdev->dev, "%s: learning kthread_runerror (%d)!\n",
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +21
-0+ __func__, ret); + goto task_learning_err; + } + +return 0 ; + + task_learning_err: +timer_delete_sync (&fep->timer_aging); +mtip_mii_unregister (fep); + mii_init_err: + dma_init_err: +mtip_ndev_cleanup (fep); + ndev_init_err: +mtip_unregister_notifiers (fep); + +return ret; +} + +static void mtip_sw_remove (struct platform_device *pdev) +{ + struct switch_enet_private *fep =
platform_get_drvdata(pdev); +drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +27
-0+mtip_unregister_notifiers (fep); +mtip_ndev_cleanup (fep); + +mtip_mii_remove (fep); + +kthread_stop (fep->task); +timer_delete_sync (&fep->timer_aging); +platform_set_drvdata (pdev,NULL ); + +kfree (fep); +} + +static struct platform_driver mtipl2plat_driver = { + .driver = { + .name ="mtipl2sw" , + .of_match_table = mtipl2_of_match, + .suppress_bind_attrs = true, + }, + .probe = mtip_sw_probe, + .remove = mtip_sw_remove, +}; + +module_platform_driver (mtipl2plat_driver); + +MODULE_AUTHOR ("Lukasz Majewski<[email protected]>" ); +MODULE_DESCRIPTION ("Driver for MTIP L2 on SOC switch" ); +MODULE_LICENSE ("GPL" );(quoted diff) +0
-0
b/drivers/net/ethernet/freescale/mtipsw/mtipl2sw.hnew file mode 100644 index 000000000000..e9c8655676fddrivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +21
-0@@ -0,0 +1,782 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (C) 2025 DENX Software Engineering GmbH +* Lukasz Majewski<[email protected]> +*/ + +#ifndef __MTIP_L2SWITCH_H_ +#define __MTIP_L2SWITCH_H_ + +#include <linux/clocksource.h> +#include <linux/net_tstamp.h> +#include <linux/ptp_clock_kernel.h> +#include <linux/timecounter.h> +#include <linux/netdevice.h> +#include <linux/phy.h> + +#define PKT_MAXBUF_SIZE 1518 +#define PKT_MINBUF_SIZE 64 +#define PKT_MAXBLR_SIZE 1520 + +/* The number of Tx and Rx buffers. These are allocated from the page
+ * pool. The code may assume these are power of two, so it is best
+ * to keep them that size.
+ * We don't need to allocate pages for the transmitter. We just use
+ * the skbuffer directly.
+ */drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +3
-0+#define MTIP_SWITCH_RX_PAGES 8 +#define MTIP_SWITCH_RX_FRSIZE 2048 +#define MTIP_SWITCH_RX_FRPPG (PAGE_SIZE /
MTIP_SWITCH_RX_FRSIZE) +#defineRX_RING_SIZE(MTIP_SWITCH_RX_FRPPG*MTIP_SWITCH_RX_PAGES) +#defineMTIP_SWITCH_TX_FRSIZE2048 +#defineMTIP_SWITCH_TX_FRPPG
(PAGE_SIZE/MTIP_SWITCH_TX_FRSIZE) +drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +10
-0+#define TX_RING_SIZE 16/* Must be power of two */ +#define TX_RING_MOD_MASK 15/* for this to work */ + +#define SWITCH_EPORT_NUMBER 2 + +#if (((RX_RING_SIZE +TX_RING_SIZE ) *8 ) >PAGE_SIZE ) +#error "L2SWITCH: descriptor ring size constants too large" +#endif +struct mtip_port_statistics_status { +/*outgoing frames discarded due to transmit queue congestion*/
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +71
-0+unsigned long MCF_ESW_POQC ; +/*incoming frames discarded due to VLAN domain mismatch*/ +unsigned long MCF_ESW_PMVID ; +/*incoming frames discarded due to untagged discard*/ +unsigned long MCF_ESW_PMVTAG ; +/*incoming frames discarded due port is in blocking state*/ +unsigned long MCF_ESW_PBL ; +}; + +struct switch_t { +unsigned long ESW_REVISION; +unsigned long ESW_SCRATCH; +unsigned long ESW_PER; +unsigned long reserved0[1 ]; +unsigned long ESW_VLANV; +unsigned long ESW_DBCR; +unsigned long ESW_DMCR; +unsigned long ESW_BKLR; +unsigned long ESW_BMPC; +unsigned long ESW_MODE; +unsigned long ESW_VIMSEL; +unsigned long ESW_VOMSEL; +unsigned long ESW_VIMEN; +unsigned long ESW_VID;/*0x34*/ +/*from 0x38 0x3C*/ +unsigned long esw_reserved0[2 ]; +unsigned long ESW_MCR;/*0x40*/ +unsigned long ESW_EGMAP; +unsigned long ESW_INGMAP; +unsigned long ESW_INGSAL; +unsigned long ESW_INGSAH; +unsigned long ESW_INGDAL; +unsigned long ESW_INGDAH; +unsigned long ESW_ENGSAL; +unsigned long ESW_ENGSAH; +unsigned long ESW_ENGDAL; +unsigned long ESW_ENGDAH; +unsigned long ESW_MCVAL;/*0x6C*/ +/*from 0x70--0x7C*/ +unsigned long esw_reserved1[4 ]; +unsigned long ESW_MMSR;/*0x80*/ +unsigned long ESW_LMT; +unsigned long ESW_LFC; +unsigned long ESW_PCSR; +unsigned long ESW_IOSR; +unsigned long ESW_QWT;/*0x94*/ +unsigned long esw_reserved2[1 ];/*0x98*/ +unsigned long ESW_P0BCT;/*0x9C*/ +/*from 0xA0-0xB8*/ +unsigned long esw_reserved3[7 ]; +unsigned long ESW_P0FFEN;/*0xBC*/ +unsigned long ESW_PSNP[8 ]; +unsigned long ESW_IPSNP[8 ]; +unsigned long ESW_PVRES[3 ]; +/*from 0x10C-0x13C*/ +unsigned long esw_reserved4[13 ]; +unsigned long ESW_IPRES;/*0x140*/ +/*from 0x144-0x17C*/ +unsigned long esw_reserved5[15 ]; +unsigned long ESW_PRES[3 ]; +/*from 0x18C-0x1FC*/ +unsigned long esw_reserved6[29 ]; +unsigned long ESW_PID[3 ]; +/*from 0x20C-0x27C*/ +unsigned long esw_reserved7[29 ]; +unsigned long ESW_VRES[32 ]; +unsigned long ESW_DISCN;/*0x300*/ +unsigned long ESW_DISCB; +unsigned long ESW_NDISCN; +unsigned long ESW_NDISCB;/*0xFC0DC30C*/ +struct mtip_port_statistics_status port_statistics_status[3];
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +107
-0+/*from 0x340-0x400*/ +unsigned long esw_reserved8[48 ]; +/*0xFC0DC400---0xFC0DC418*/ +unsigned long ESW_ISR ; +unsigned long ESW_IMR ; +unsigned long ESW_RDSR ; +unsigned long ESW_TDSR ; +unsigned long ESW_MRBR ; +unsigned long ESW_RDAR ; +unsigned long ESW_TDAR ; +/*from 0x420-0x4FC*/ +unsigned long esw_reserved9[57 ]; +/*0xFC0DC500---0xFC0DC508*/ +unsigned long ESW_LREC0 ; +unsigned long ESW_LREC1 ; +unsigned long ESW_LSR ; +}; + +struct addr_table64b_entry { +unsigned int lo;/* lower 32 bits */ +unsigned int hi;/* upper 32 bits */ +}; + +struct mtip_addr_table_t { +struct addr_table64b_entry mtip_table64b_entry[2048 ]; +}; + +#define MCF_ESW_LOOKUP_MEM_OFFSET 0x4000 +#define MCF_ESW_ENET_PORT_OFFSET 0x4000 +#define ENET_SWI_PHYS_ADDR_OFFSET 0x8000 +#define MCF_ESW_PER (0x08) +#define MCF_ESW_DBCR (0x14) +#define MCF_ESW_IMR (0x404) + +#define MCF_FEC_BASE_ADDR (fep->enet_addr) +#define MCF_FEC_EIR (0x04) +#define MCF_FEC_EIMR (0x08) +#define MCF_FEC_MMFR (0x40) +#define MCF_FEC_MSCR (0x44) + +#define MCF_FEC_RCR (0x84) +#define MCF_FEC_TCR (0xC4) +#define MCF_FEC_ECR (0x24) + +#define MCF_FEC_PALR (0xE4) +#define MCF_FEC_PAUR (0xE8) + +#define MCF_FEC_ERDSR (0x180) +#define MCF_FEC_ETDSR (0x184) + +#define MCF_FEC_IAUR (0x118) +#define MCF_FEC_IALR (0x11C) + +#define MCF_FEC_GAUR (0x120) +#define MCF_FEC_GALR (0x124) + +#define MCF_FEC_EMRBR (0x188) + +#define MCF_FEC_RCR_DRT BIT(1) +#define MCF_FEC_RCR_MII_MODE BIT(2) +#define MCF_FEC_RCR_PROM BIT(3) +#define MCF_FEC_RCR_FCE BIT(5) +#define MCF_FEC_RCR_RMII_MODE BIT(8) +#define MCF_FEC_RCR_RMII_10BASET BIT(9) +#define MCF_FEC_RCR_MAX_FL (x) (((x) & 0x00003FFF) << 16) +#define MCF_FEC_RCR_CRC_FWD BIT(14) +#define MCF_FEC_RCR_NO_LGTH_CHECK BIT(30) +#define MCF_FEC_TCR_FDEN BIT(2) + +#define MCF_FEC_ECR_RESET BIT(0) +#define MCF_FEC_ECR_ETHER_EN BIT(1) +#define MCF_FEC_ECR_MAGIC_ENA BIT(2) +#define MCF_FEC_ECR_ENA_1588 BIT(4) + +#define MTIP_ALIGNMENT 0xf +#define MCF_ENET_MII BIT(23) + +/* FEC MII MMFR bits definition */ +#define FEC_MMFR_ST BIT(30) +#define FEC_MMFR_OP_READ BIT(29) +#define FEC_MMFR_OP_WRITE BIT(28) +#define FEC_MMFR_PA (v) (((v) & 0x1F) << 23) +#define FEC_MMFR_RA (v) (((v) & 0x1F) << 18) +#define FEC_MMFR_TA (2 << 16) +#define FEC_MMFR_DATA (v) ((v) & 0xffff) + +/* Port 0 backpressure congestion threshold */ +#define P0BC_THRESHOLD 0x40 +#define LEARNING_AGING_INTERVAL 100 +/* Info received from Hardware Learning FIFO, +* holding MAC address and corresponding Hash Value and +* port number where the frame was received (disassembled). +*/ +struct mtip_port_info { +/* MAC lower 32 bits (first byte is 7:0). */ +unsigned int maclo; +/* MAC upper 16 bits (47:32). */ +unsigned int machi; +/* the hash value for this MAC address. */ +unsigned int hash; +/* the port number this MAC address is associated with. */ +unsigned int port; +}; + +/* Define the buffer descriptor structure. */ +struct cbd_t { +unsigned short cbd_datlen;/* Data length */
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +1
-0+unsigned short cbd_sc;/* Control and status info */
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +1
-0+unsigned long cbd_bufaddr;/* Buffer address */ +};
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+ +/* The switch buffer descriptors track the ring buffers. The
rx_bd_baseand
+ *tx_bd_basealways point to the base of the buffer descriptors. The
+ *cur_rxandcur_txpoint to the currently available buffer.
+ * Thedirty_txtracks the current buffer that is being sent by the
+ * controller. Thecur_txanddirty_txare equal under both completely
+ * empty and completely full conditions. The empty/ready indicator in
+ * the buffer descriptor determines the actual condition.
+ */drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +24
-0+struct switch_enet_private { +/* Base addresses for HW registers of the switch device */ +void __iomem *hwp_enet; +struct switch_t *hwp; +struct mtip_addr_table_t *hwentry; +void __iomem *enet_addr; + +struct platform_device *pdev; + +/* Clocks */ +struct clk *clk_ipg; +struct clk *clk_ahb; +struct clk *clk_enet_out; + +/* skbuff */ +unsigned char *tx_bounce[TX_RING_SIZE ]; +struct sk_buff *tx_skbuff[TX_RING_SIZE ]; +struct sk_buff *rx_skbuff[RX_RING_SIZE ]; +ushort skb_cur; +ushort skb_dirty; + +/* DMA */ +dma_addr_t bd_dma; +struct cbd_t *rx_bd_base;/* Address of Rx and Tx buffers. */
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+struct cbd_t *tx_bd_base; +struct cbd_t *cur_rx, *cur_tx;/* The next free ring entry */
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +1
-0+struct cbd_t *dirty_tx;/* The ring entries to be free()ed. */
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +6
-0+uint tx_full; + +/* Locking */ +spinlock_t hw_lock;/* Lock for HW configuration */ +spinlock_t mii_lock;/* Lock for MII operation */ +spinlock_t learn_lock;/* Lock for learning DB adjustments */ +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +47
-0+/* NAPI support */ +struct napi_struct napi; + +/* Timer for Aging */ +struct timer_list timer_aging; +struct task_struct *task; +int at_block_overflows; +int at_curr_entries; +int curr_time; + +/* PHY and MDIO */ +struct mii_bus *mii_bus; +struct phy_device *phy_dev[SWITCH_EPORT_NUMBER ]; +uint phy_speed; +int link[SWITCH_EPORT_NUMBER ]; +int full_duplex[SWITCH_EPORT_NUMBER ]; +phy_interface_t phy_interface[SWITCH_EPORT_NUMBER ]; +struct device_node *phy_np[SWITCH_EPORT_NUMBER ]; + +/* IRQ number */ +int irq; + +/* lan[01] ports */ +int n_ports; +const char *ndev_name[SWITCH_EPORT_NUMBER ]; +struct net_device *ndev[SWITCH_EPORT_NUMBER ]; +unsigned char mac[SWITCH_EPORT_NUMBER ][ETH_ALEN ]; + +/* Switch state */ +u8 br_members;/* Bit field with active members */ +u8 br_offload;/* Bridge in-HW offloading flag */ +int usage_count;/* Number of configured ports */ + +/* Driver related */ +u32 quirks; +}; + +struct mtip_ndev_priv { +int portnum; +struct net_device *dev; +struct net_device_stats stats; +struct net_device *master_dev; +struct switch_enet_private *fep; +}; + +#define MCF_FEC_MII_DATA 0x040/* MII manage frame reg */ +#define MCF_FEC_GRP_HASH_TABLE_HIGH 0x120/* High 32bits hash table */ +#define
MCF_FEC_GRP_HASH_TABLE_LOW0x124/*
Low 32bits hash table */ +drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +3
-0+#define BD_SC_EMPTY ((ushort)0x8000)/* Receive is empty */ +#define BD_SC_READY ((ushort)0x8000)/* Transmit is ready */ +#define BD_SC_WRAP ((ushort)0x2000)/* Last buffer descriptor */ +#define
BD_SC_INTRPT((ushort)0x1000) /* Interrupt on change
*/ +#defineBD_SC_CM((ushort)0x0200) /* Continuous mode */drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +104
-0+#define BD_SC_ID ((ushort)0x0100)/* Rec'd too many idles */ +#define BD_SC_P ((ushort)0x0100)/* xmt preamble */ +#define BD_SC_BR ((ushort)0x0020)/* Break received */ +#define BD_SC_FR ((ushort)0x0010)/* Framing error */ +#define BD_SC_PR ((ushort)0x0008)/* Parity error */ +#define BD_SC_OV ((ushort)0x0002)/* Overrun */ +#define BD_SC_CD ((ushort)0x0001) + +/* Buffer descriptor control/status used by Ethernet receive. */ +#define BD_ENET_RX_EMPTY ((ushort)0x8000) +#define BD_ENET_RX_WRAP ((ushort)0x2000) +#define BD_ENET_RX_INTR ((ushort)0x1000) +#define BD_ENET_RX_LAST ((ushort)0x0800) +#define BD_ENET_RX_FIRST ((ushort)0x0400) +#define BD_ENET_RX_MISS ((ushort)0x0100) +#define BD_ENET_RX_LG ((ushort)0x0020) +#define BD_ENET_RX_NO ((ushort)0x0010) +#define BD_ENET_RX_SH ((ushort)0x0008) +#define BD_ENET_RX_CR ((ushort)0x0004) +#define BD_ENET_RX_OV ((ushort)0x0002) +#define BD_ENET_RX_CL ((ushort)0x0001) +/* All status bits */ +#define BD_ENET_RX_STATS ((ushort)0x013f) + +/* Buffer descriptor control/status used by Ethernet transmit.*/ +#define BD_ENET_TX_READY ((ushort)0x8000) +#define BD_ENET_TX_PAD ((ushort)0x4000) +#define BD_ENET_TX_WRAP ((ushort)0x2000) +#define BD_ENET_TX_INTR ((ushort)0x1000) +#define BD_ENET_TX_LAST ((ushort)0x0800) +#define BD_ENET_TX_TC ((ushort)0x0400) +#define BD_ENET_TX_DEF ((ushort)0x0200) +#define BD_ENET_TX_HB ((ushort)0x0100) +#define BD_ENET_TX_LC ((ushort)0x0080) +#define BD_ENET_TX_RL ((ushort)0x0040) +#define BD_ENET_TX_RCMASK ((ushort)0x003c) +#define BD_ENET_TX_UN ((ushort)0x0002) +#define BD_ENET_TX_CSL ((ushort)0x0001) +/* All status bits */ +#define BD_ENET_TX_STATS ((ushort)0x03ff) + +/* Copy from validation code */ +#define RX_BUFFER_SIZE 256 +#define TX_BUFFER_SIZE 256 + +#define TX_BD_R BIT(15) +#define TX_BD_TO1 BIT(14) +#define TX_BD_W BIT(13) +#define TX_BD_TO2 BIT(12) +#define TX_BD_L BIT(11) +#define TX_BD_TC BIT(10) + +#define TX_BD_INT BIT(30) +#define TX_BD_TS BIT(29) +#define TX_BD_PINS BIT(28) +#define TX_BD_IINS BIT(27) +#define TX_BD_TXE BIT(15) +#define TX_BD_UE BIT(13) +#define TX_BD_EE BIT(12) +#define TX_BD_FE BIT(11) +#define TX_BD_LCE BIT(10) +#define TX_BD_OE BIT(9) +#define TX_BD_TSE BIT(8) +#define TX_BD_BDU BIT(31) + +#define RX_BD_E BIT(15) +#define RX_BD_R01 BIT(14) +#define RX_BD_W BIT(13) +#define RX_BD_R02 BIT(12) +#define RX_BD_L BIT(11) +#define RX_BD_M BIT(8) +#define RX_BD_BC BIT(7) +#define RX_BD_MC BIT(6) +#define RX_BD_LG BIT(5) +#define RX_BD_NO BIT(4) +#define RX_BD_CR BIT(2) +#define RX_BD_OV BIT(1) +#define RX_BD_TR BIT(0) + +#define RX_BD_ME BIT(31) +#define RX_BD_PE 0x04000000 +#define RX_BD_CE 0x02000000 +#define RX_BD_UC 0x01000000 +#define RX_BD_INT 0x00800000 +#define RX_BD_ICE BIT(5) +#define RX_BD_PCR BIT(4) +#define RX_BD_VLAN BIT(2) +#define RX_BD_IPV6 BIT(1) +#define RX_BD_FRAG BIT(0) +#define RX_BD_BDU BIT(31) +/****************************************************************************/ + +/* Address Table size in bytes(2048 64bit entry ) */ +#define MTIP_ATABLE_MEM_SIZE (2048 * 8) +/* How many 64-bit elements fit in the address table */ +#define MTIP_ATABLE_MEM_NUM_ENTRIES (2048) +/* Address Table Maximum number of entries in each Slot */ +#define ATABLE_ENTRY_PER_SLOT 8 +/* log2(ATABLE_ENTRY_PER_SLOT)*/ +#define ATABLE_ENTRY_PER_SLOT_bits 3 +/* entry size in byte */ +#define ATABLE_ENTRY_SIZE 8 +/* slot size in byte */ +#define ATABLE_SLOT_SIZE (ATABLE_ENTRY_PER_SLOT *
ATABLE_ENTRY_SIZE) +/* width of timestamp variable (bits) within
address table entry */ +#defineAT_DENTRY_TIMESTAMP_WIDTH10drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +25
-0+/* number of bits for port number storage */ +#define AT_DENTRY_PORT_WIDTH 4 +/* number of bits for port bitmask number storage */ +#define AT_SENTRY_PORT_WIDTH 11 +/* address table static entry port bitmask start address bit */ +#define AT_SENTRY_PORTMASK_shift 21 +/* address table static entry priority start address bit */ +#define AT_SENTRY_PRIO_shift 18 +/* address table dynamic entry port start address bit */ +#define AT_DENTRY_PORT_shift 28 +/* address table dynamic entry timestamp start address bit */ +#define AT_DENTRY_TIME_shift 18 +/* address table entry record type start address bit */ +#define AT_ENTRY_TYPE_shift 17 +/* address table entry record type bit: 1 static, 0 dynamic */ +#define AT_ENTRY_TYPE_STATIC 1 +#define AT_ENTRY_TYPE_DYNAMIC 0 +/* address table entry record valid start address bit */ +#define AT_ENTRY_VALID_shift 16 +#define AT_ENTRY_RECORD_VALID 1 + +/* return block corresponding to the 8 bit hash value calculated */ +#define GET_BLOCK_PTR (hash) ((hash) << 3) +#define AT_EXTRACT_TIMESTAMP (x) \ + (((x) >> AT_DENTRY_TIME_shift) & ((1 <<
AT_DENTRY_TIMESTAMP_WIDTH) - 1)) +#defineAT_EXTRACT_PORT(x)\drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +1
-0+ (((x) >> AT_DENTRY_PORT_shift) & ((1 <<
AT_DENTRY_PORT_WIDTH) - 1)) +#defineTIMEDELTA(newtime, oldtime)\drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +10
-1+ (((newtime) - (oldtime)) & \ + ((1 <<AT_DENTRY_TIMESTAMP_WIDTH ) -1 )) + +/* increment time value respecting modulo. */ +static inline int mtip_timeincrement (int time) +{ +return (time +1 ) & ((1 <<AT_DENTRY_TIMESTAMP_WIDTH ) -1 ); +} + +/* -------------------------------------------------------------------------*/ +/* Bit definitions and macros for
MCF_ESW_REVISION*/ +#defineMCF_MTIP_REVISION_CORE_REVISION(x)((x) &0x0000FFFF) +#defineMCF_MTIP_REVISION_CUSTOMER_REVISION(x)(((x) &0xFFFF0000) >> 16) +drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +36
-0+/* Bit definitions and macros for MCF_ESW_PER */ +#define MCF_ESW_PER_TE0 BIT(0) +#define MCF_ESW_PER_TE1 BIT(1) +#define MCF_ESW_PER_TE2 BIT(2) +#define MCF_ESW_PER_RE0 BIT(16) +#define MCF_ESW_PER_RE1 BIT(17) +#define MCF_ESW_PER_RE2 BIT(18) + +/* Bit definitions and macros for MCF_ESW_VLANV */ +#define MCF_ESW_VLANV_VV0 BIT(0) +#define MCF_ESW_VLANV_VV1 BIT(1) +#define MCF_ESW_VLANV_VV2 BIT(2) +#define MCF_ESW_VLANV_DU0 BIT(16) +#define MCF_ESW_VLANV_DU1 BIT(17) +#define MCF_ESW_VLANV_DU2 BIT(18) + +/* Bit definitions and macros for MCF_ESW_DBCR */ +#define MCF_ESW_DBCR_P0 BIT(0) +#define MCF_ESW_DBCR_P1 BIT(1) +#define MCF_ESW_DBCR_P2 BIT(2) + +/* Bit definitions and macros for MCF_ESW_DMCR */ +#define MCF_ESW_DMCR_P0 BIT(0) +#define MCF_ESW_DMCR_P1 BIT(1) +#define MCF_ESW_DMCR_P2 BIT(2) + +/* Bit definitions and macros for MCF_ESW_BKLR */ +#define MCF_ESW_BKLR_BE0 BIT(0) +#define MCF_ESW_BKLR_BE1 BIT(1) +#define MCF_ESW_BKLR_BE2 BIT(2) +#define MCF_ESW_BKLR_LD0 BIT(16) +#define MCF_ESW_BKLR_LD1 BIT(17) +#define MCF_ESW_BKLR_LD2 BIT(18) + +/* Bit definitions and macros for MCF_ESW_BMPC */ +#define MCF_ESW_BMPC_PORT (x) (((x) & 0x0000000F)<< 0) +#define
MCF_ESW_BMPC_MSG_TXBIT(5)drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +3
-0+#define MCF_ESW_BMPC_EN BIT(6) +#define MCF_ESW_BMPC_DIS BIT(7) +#define MCF_ESW_BMPC_PRIORITY (x) (((x) & 0x00000007)<< 13) +#define
MCF_ESW_BMPC_PORTMASK(x)(((x) &0x00000007) << 16) +drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +10
-0+/* Bit definitions and macros for MCF_ESW_MODE */ +#define MCF_ESW_MODE_SW_RST BIT(0) +#define MCF_ESW_MODE_SW_EN BIT(1) +#define MCF_ESW_MODE_STOP BIT(7) +#define MCF_ESW_MODE_CRC_TRAN BIT(8) +#define MCF_ESW_MODE_P0CT BIT(9) +#define MCF_ESW_MODE_STATRST BIT(31) + +/* Bit definitions and macros for MCF_ESW_VIMSEL */ +#define MCF_ESW_VIMSEL_IM0 (x) (((x) & 0x00000003)<< 0) +#define
MCF_ESW_VIMSEL_IM1(x)(((x) &0x00000003) << 2) +#defineMCF_ESW_VIMSEL_IM2(x)
(((x) &0x00000003) << 4) +drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+/* Bit definitions and macros for MCF_ESW_VOMSEL */ +#define MCF_ESW_VOMSEL_OM0 (x) (((x) & 0x00000003)<< 0) +#define
MCF_ESW_VOMSEL_OM1(x)(((x) &0x00000003) << 2) +#defineMCF_ESW_VOMSEL_OM2(x)
(((x) &0x00000003) << 4) +drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +7
-0+/* Bit definitions and macros for MCF_ESW_VIMEN */ +#define MCF_ESW_VIMEN_EN0 BIT(0) +#define MCF_ESW_VIMEN_EN1 BIT(1) +#define MCF_ESW_VIMEN_EN2 BIT(2) + +/* Bit definitions and macros for MCF_ESW_VID */ +#define MCF_ESW_VID_TAG (x) (((x) & 0xFFFFFFFF)<< 0) +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+/* Bit definitions and macros for MCF_ESW_MCR */ +#define MCF_ESW_MCR_PORT (x) (((x) & 0x0000000F)<< 0) +#define
MCF_ESW_MCR_MENBIT(4)drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +19
-0+#define MCF_ESW_MCR_INGMAP BIT(5) +#define MCF_ESW_MCR_EGMAP BIT(6) +#define MCF_ESW_MCR_INGSA BIT(7) +#define MCF_ESW_MCR_INGDA BIT(8) +#define MCF_ESW_MCR_EGSA BIT(9) +#define MCF_ESW_MCR_EGDA BIT(10) + +/* Bit definitions and macros for MCF_ESW_EGMAP */ +#define MCF_ESW_EGMAP_EG0 BIT(0) +#define MCF_ESW_EGMAP_EG1 BIT(1) +#define MCF_ESW_EGMAP_EG2 BIT(2) + +/* Bit definitions and macros for MCF_ESW_INGMAP */ +#define MCF_ESW_INGMAP_ING0 BIT(0) +#define MCF_ESW_INGMAP_ING1 BIT(1) +#define MCF_ESW_INGMAP_ING2 BIT(2) + +/* Bit definitions and macros for MCF_ESW_INGSAL */ +#define MCF_ESW_INGSAL_ADDLOW (x) (((x) & 0xFFFFFFFF)<< 0) +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+/* Bit definitions and macros for MCF_ESW_INGSAH */ +#define MCF_ESW_INGSAH_ADDHIGH (x) (((x) & 0x0000FFFF)<< 0) +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+/* Bit definitions and macros for MCF_ESW_INGDAL */ +#define MCF_ESW_INGDAL_ADDLOW (x) (((x) & 0xFFFFFFFF)<< 0) +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+/* Bit definitions and macros for MCF_ESW_INGDAH */ +#define MCF_ESW_INGDAH_ADDHIGH (x) (((x) & 0x0000FFFF)<< 0) +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+/* Bit definitions and macros for MCF_ESW_ENGSAL */ +#define MCF_ESW_ENGSAL_ADDLOW (x) (((x) & 0xFFFFFFFF)<< 0) +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+/* Bit definitions and macros for MCF_ESW_ENGSAH */ +#define MCF_ESW_ENGSAH_ADDHIGH (x) (((x) & 0x0000FFFF)<< 0) +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+/* Bit definitions and macros for MCF_ESW_ENGDAL */ +#define MCF_ESW_ENGDAL_ADDLOW (x) (((x) & 0xFFFFFFFF)<< 0) +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+/* Bit definitions and macros for MCF_ESW_ENGDAH */ +#define MCF_ESW_ENGDAH_ADDHIGH (x) (((x) & 0x0000FFFF)<< 0) +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+/* Bit definitions and macros for MCF_ESW_MCVAL */ +#define MCF_ESW_MCVAL_COUNT (x) (((x) & 0x000000FF)<< 0) +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +7
-0+/* Bit definitions and macros for MCF_ESW_MMSR */ +#define MCF_ESW_MMSR_BUSY BIT(0) +#define MCF_ESW_MMSR_NOCELL BIT(1) +#define MCF_ESW_MMSR_MEMFULL BIT(2) +#define MCF_ESW_MMSR_MFLATCH BIT(3) +#define MCF_ESW_MMSR_DQ_GRNT BIT(6) +#define MCF_ESW_MMSR_CELLS_AVAIL (x) (((x) & 0x000000FF)<< 16) +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+/* Bit definitions and macros for MCF_ESW_LMT */ +#define MCF_ESW_LMT_THRESH (x) (((x) & 0x000000FF)<< 0) +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+/* Bit definitions and macros for MCF_ESW_LFC */ +#define MCF_ESW_LFC_COUNT (x) (((x) & 0xFFFFFFFF)<< 0) +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +12
-0+/* Bit definitions and macros for MCF_ESW_PCSR */ +#define MCF_ESW_PCSR_PC0 BIT(0) +#define MCF_ESW_PCSR_PC1 BIT(1) +#define MCF_ESW_PCSR_PC2 BIT(2) + +/* Bit definitions and macros for MCF_ESW_IOSR */ +#define MCF_ESW_IOSR_OR0 BIT(0) +#define MCF_ESW_IOSR_OR1 BIT(1) +#define MCF_ESW_IOSR_OR2 BIT(2) + +/* Bit definitions and macros for MCF_ESW_QWT */ +#define MCF_ESW_QWT_Q0WT (x) (((x) & 0x0000001F)<< 0) +#define
MCF_ESW_QWT_Q1WT(x)(((x) &0x0000001F) << 8) +#defineMCF_ESW_QWT_Q2WT(x)(((x) &0x0000001F) << 16) +#defineMCF_ESW_QWT_Q3WT(x)(((x) & 0x0000001F) << 24) +drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+/* Bit definitions and macros for MCF_ESW_P0BCT */ +#define MCF_ESW_P0BCT_THRESH (x) (((x) & 0x000000FF)<< 0) +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +3
-0+/* Bit definitions and macros for MCF_ESW_P0FFEN */ +#define MCF_ESW_P0FFEN_FEN BIT(0) +#define MCF_ESW_P0FFEN_FD (x) (((x) & 0x00000003)<< 2) +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +3
-0+/* Bit definitions and macros for MCF_ESW_PSNP */ +#define MCF_ESW_PSNP_EN BIT(0) +#define MCF_ESW_PSNP_MODE (x) (((x) & 0x00000003)<< 1) +#define
MCF_ESW_PSNP_CDBIT(3)drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+#define MCF_ESW_PSNP_CS BIT(4) +#define MCF_ESW_PSNP_PORT_COMPARE (x) (((x) & 0x0000FFFF)<< 16) +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +3
-0+/* Bit definitions and macros for MCF_ESW_IPSNP */ +#define MCF_ESW_IPSNP_EN BIT(0) +#define MCF_ESW_IPSNP_MODE (x) (((x) & 0x00000003)<< 1) +#define
MCF_ESW_IPSNP_PROTOCOL(x)(((x) &0x000000FF) << 8) +drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+/* Bit definitions and macros for MCF_ESW_PVRES */ +#define MCF_ESW_PVRES_PRI0 (x) (((x) & 0x00000007)<< 0) +#define
MCF_ESW_PVRES_PRI1(x)(((x) &0x00000007) << 3) +#defineMCF_ESW_PVRES_PRI2(x)(((x) &0x00000007) << 6) +#defineMCF_ESW_PVRES_PRI3(x)(((x) & 0x00000007) << 9) +#define MCF_ESW_PVRES_PRI4(x) (((x) & 0x00000007) << 12) +#define
MCF_ESW_PVRES_PRI5(x)(((x) &0x00000007) << 15)
+#defineMCF_ESW_PVRES_PRI6(x)(((x) &0x00000007)
<< 18) +#defineMCF_ESW_PVRES_PRI7(x)(((x) &0x00000007) << 21) + +/* Bit definitions and macros forMCF_ESW_IPRES*/ +#defineMCF_ESW_IPRES_ADDRESS(x)(((x) &0x000000FF) << 0) +#defineMCF_ESW_IPRES_IPV4SEL
BIT(8) +#defineMCF_ESW_IPRES_PRI0(x)(((x)
&0x00000003) << 9) +#defineMCF_ESW_IPRES_PRI1(x)(((x) &0x00000003) << 11) +#defineMCF_ESW_IPRES_PRI2(x)(((x) & 0x00000003) << 13) +#define MCF_ESW_IPRES_READ BIT(31) +drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +5
-0+/* Bit definitions and macros for MCF_ESW_PRES */ +#define MCF_ESW_PRES_VLAN BIT(0) +#define MCF_ESW_PRES_IP BIT(1) +#define MCF_ESW_PRES_MAC BIT(2) +#define MCF_ESW_PRES_DFLT_PRI (x) (((x) & 0x00000007)<< 4) +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+/* Bit definitions and macros for MCF_ESW_PID */ +#define MCF_ESW_PID_VLANID (x) (((x) & 0x0000FFFF)<< 0) +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +5
-0+/* Bit definitions and macros for MCF_ESW_VRES */ +#define MCF_ESW_VRES_P0 BIT(0) +#define MCF_ESW_VRES_P1 BIT(1) +#define MCF_ESW_VRES_P2 BIT(2) +#define MCF_ESW_VRES_VLANID (x) (((x) & 0x00000FFF)<< 3) +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+/* Bit definitions and macros for MCF_ESW_DISCN */ +#define MCF_ESW_DISCN_COUNT (x) (((x) & 0xFFFFFFFF)<< 0) +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+/* Bit definitions and macros for MCF_ESW_DISCB */ +#define MCF_ESW_DISCB_COUNT (x) (((x) & 0xFFFFFFFF)<< 0) +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+/* Bit definitions and macros for MCF_ESW_NDISCN */ +#define MCF_ESW_NDISCN_COUNT (x) (((x) & 0xFFFFFFFF)<< 0) +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+/* Bit definitions and macros for MCF_ESW_NDISCB */ +#define MCF_ESW_NDISCB_COUNT (x) (((x) & 0xFFFFFFFF)<< 0) +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+/* Bit definitions and macros for MCF_ESW_POQC */ +#define MCF_ESW_POQC_COUNT (x) (((x) & 0xFFFFFFFF)<< 0) +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+/* Bit definitions and macros for MCF_ESW_PMVID */ +#define MCF_ESW_PMVID_COUNT (x) (((x) & 0xFFFFFFFF)<< 0) +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+/* Bit definitions and macros for MCF_ESW_PMVTAG */ +#define MCF_ESW_PMVTAG_COUNT (x) (((x) & 0xFFFFFFFF)<< 0) +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+/* Bit definitions and macros for MCF_ESW_PBL */ +#define MCF_ESW_PBL_COUNT (x) (((x) & 0xFFFFFFFF)<< 0) +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +26
-0+/* Bit definitions and macros for MCF_ESW_ISR */ +#define MCF_ESW_ISR_EBERR BIT(0) +#define MCF_ESW_ISR_RXB BIT(1) +#define MCF_ESW_ISR_RXF BIT(2) +#define MCF_ESW_ISR_TXB BIT(3) +#define MCF_ESW_ISR_TXF BIT(4) +#define MCF_ESW_ISR_QM BIT(5) +#define MCF_ESW_ISR_OD0 BIT(6) +#define MCF_ESW_ISR_OD1 BIT(7) +#define MCF_ESW_ISR_OD2 BIT(8) +#define MCF_ESW_ISR_LRN BIT(9) + +/* Bit definitions and macros for MCF_ESW_IMR */ +#define MCF_ESW_IMR_EBERR BIT(0) +#define MCF_ESW_IMR_RXB BIT(1) +#define MCF_ESW_IMR_RXF BIT(2) +#define MCF_ESW_IMR_TXB BIT(3) +#define MCF_ESW_IMR_TXF BIT(4) +#define MCF_ESW_IMR_QM BIT(5) +#define MCF_ESW_IMR_OD0 BIT(6) +#define MCF_ESW_IMR_OD1 BIT(7) +#define MCF_ESW_IMR_OD2 BIT(8) +#define MCF_ESW_IMR_LRN BIT(9) + +/* Bit definitions and macros for MCF_ESW_RDSR */ +#define MCF_ESW_RDSR_ADDRESS (x) (((x) & 0x3FFFFFFF)<< 2) +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+/* Bit definitions and macros for MCF_ESW_TDSR */ +#define MCF_ESW_TDSR_ADDRESS (x) (((x) & 0x3FFFFFFF)<< 2) +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+/* Bit definitions and macros for MCF_ESW_MRBR */ +#define MCF_ESW_MRBR_SIZE (x) (((x) & 0x000003FF)<< 4) +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +8
-0+/* Bit definitions and macros for MCF_ESW_RDAR */ +#define MCF_ESW_RDAR_R_DES_ACTIVE BIT(24) + +/* Bit definitions and macros for MCF_ESW_TDAR */ +#define MCF_ESW_TDAR_X_DES_ACTIVE BIT(24) + +/* Bit definitions and macros for MCF_ESW_LREC0 */ +#define MCF_ESW_LREC0_MACADDR0 (x) (((x) & 0xFFFFFFFF)<< 0) +
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+/* Bit definitions and macros for MCF_ESW_LREC1 */ +#define MCF_ESW_LREC1_MACADDR1 (x) (((x) & 0x0000FFFF)<< 0) +#define
MCF_ESW_LREC1_HASH(x)(((x) &0x000000FF) << 16) +#defineMCF_ESW_LREC1_SWPORT(x)(((x) &0x00000003) << 24) +drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +4
-0+/* Bit definitions and macros for MCF_ESW_LSR */ +#define MCF_ESW_LSR_DA BIT(0) + +/* ENET Block Guide/ Chapter for the iMX6SX (PELE) address one issue:
+ * After set ENET_ATCR[Capture], there need some time cycles before the counter
+ * value is capture in the register clock domain.
+ * The wait-time-cycles is at least 6 clock cycles of the slower clock between
+ * the register clock and the 1588 clock. The 1588ts_clkis fixed to 25Mhz,
+ * register clock is 66Mhz, so the wait-time-cycles must be greater than 240ns
+ * (40ns * 6).
+ */drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +7
-0+#define FEC_QUIRK_BUG_CAPTURE BIT(10) +/* Controller has only one MDIO bus */ +#define FEC_QUIRK_SINGLE_MDIO BIT(11) + +/* Switch Management functions */ +int mtip_vlan_input_process (struct switch_enet_private *fep, + int port, int mode, unsigned short
port_vlanid,drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +1
-0+int vlan_verify_en, int
vlan_domain_num,drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+ int vlan_domain_port); +int mtip_set_vlan_verification(struct switch_enet_private *fep,int port,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +3
-0+int vlan_domain_verify_en, + int vlan_discard_unknown_en); +int mtip_port_multicast_config(struct switch_enet_private *fep,int port,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+ int enable); +int mtip_vlan_output_process(struct switch_enet_private *fep, intport,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +4
-0+ int mode); +int mtip_port_multicast_config (struct switch_enet_private *fep, +int port,int enable); +void mtip_switch_en_port_separation(struct switch_enet_private*fep); +void
mtip_switch_dis_port_separation(struct switch_enet_private *fep); +int mtip_port_broadcast_config(structswitch_enet_private*fep,drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+ int port, int enable); +int mtip_forced_forward(struct switch_enet_private *fep, int port,int enable); +int mtip_port_learning_config(struct
switch_enet_private*fep, int port,drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +2
-0+ int disable, int irq_adj); +int mtip_port_blocking_config(struct switch_enet_private *fep, intport,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +5
-0+ int enable); +bool mtip_is_switch_netdev_port (const struct net_device *ndev); +int mtip_register_notifiers (struct switch_enet_private *fep); +void mtip_unregister_notifiers (struct switch_enet_private *fep); +int mtip_port_enable_config(struct switch_enet_private *fep, intport,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +3
-0+ int tx_en, int rx_en); +void mtip_clear_atable (struct switch_enet_private *fep); +#endif /* __MTIP_L2SWITCH_H_ */ (quoted diff) +0
-0
b/drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.cnew file mode 100644 index 000000000000..0b76a60858a5drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +3
-0@@ -0,0 +1,122 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* L2 switch Controller driver for MTIP block - bridge network interface
+ *
+ * Copyright (C) 2025 DENX Software Engineering GmbH
+ * Lukasz Majewski<[email protected]>
+ */drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +11
-0+ +#include <linux/netdevice.h> +#include <linux/etherdevice.h> +#include <linux/platform_device.h> + +#include "mtipl2sw.h" +static int mtip_ndev_port_link (struct net_device *ndev, +struct net_device *br_ndev, +struct netlink_ext_ack *extack) +{ + struct mtip_ndev_priv *priv = netdev_priv(ndev),
*other_priv;drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +11
-0+struct switch_enet_private *fep = priv->fep; +struct net_device *other_ndev; + +/* Check if one port of MTIP switch is already bridged */ +if (fep->br_members && !fep->br_offload) { +/* Get the second bridge ndev */ + other_ndev = fep->ndev[fep->br_members -1 ]; + other_priv =netdev_priv (other_ndev); +if (other_priv->master_dev != br_ndev) { + NL_SET_ERR_MSG_MOD(extack, + "L2 offloading onlypossible for the same bridge!");
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +15
-0+return notifier_from_errno (-EOPNOTSUPP ); + } + + fep->br_offload =1 ; +mtip_switch_dis_port_separation (fep); +mtip_clear_atable (fep); + } + +if (!priv->master_dev) + priv->master_dev = br_ndev; + + fep->br_members |=BIT (priv->portnum -1 ); + + dev_dbg(&ndev->dev, + "%s: ndev: %s br: %s fep: 0x%x members: 0x%xoffload: %d\n",
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +1
-0+ __func__, ndev->name, br_ndev->name, (unsignedint)fep,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +11
-0+ fep->br_members, fep->br_offload); + +return NOTIFY_DONE ; +} + +static void mtip_netdevice_port_unlink (struct net_device *ndev) +{ +struct mtip_ndev_priv *priv =netdev_priv (ndev); +struct switch_enet_private *fep = priv->fep; + + dev_dbg(&ndev->dev, "%s: ndev: %s members: 0x%x\n",
__func__,drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +33
-0+ ndev->name, fep->br_members); + + fep->br_members &= ~BIT (priv->portnum -1 ); + priv->master_dev =NULL ; + +if (!fep->br_members) { + fep->br_offload =0 ; +mtip_switch_en_port_separation (fep); +mtip_clear_atable (fep); + } +} + +/* 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 = ptr; +struct netlink_ext_ack *extack; +int ret =NOTIFY_DONE ; + +if (!mtip_is_switch_netdev_port (ndev)) +return NOTIFY_DONE ; + + extack =netdev_notifier_info_to_extack (&info->info); + +switch (event) { +case NETDEV_CHANGEUPPER : +if (!netif_is_bridge_master (info->upper_dev)) +break ; + +if (info->linking) + ret = mtip_ndev_port_link(ndev,
info->upper_dev,drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +18
-0+ extack); + else +mtip_netdevice_port_unlink (ndev ); + +break ; +default : +return NOTIFY_DONE ; + } + +return notifier_from_errno (ret); +} + +static struct notifier_block mtip_netdevice_nb__read_mostly = { + .notifier_call = mtip_netdevice_event, +}; + +int mtip_register_notifiers (struct switch_enet_private *fep) +{
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c
Quoted 7 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +5
-0+int ret =0 ; + + ret =register_netdevice_notifier (&mtip_netdevice_nb); +if (ret) { + dev_err(&fep->pdev->dev, "can't register netdevicenotifier\n");
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +1
-0+return ret;I think this could be dropped
+1
Quoted 202 lines
Quoted 202 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +9
-0+ } + +return ret; +} + +void mtip_unregister_notifiers (struct switch_enet_private *fep) +{ +unregister_netdevice_notifier (&mtip_netdevice_nb); +}(quoted diff) +0
-0
b/drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.cnew file mode 100644 index 000000000000..bd40522a9b53drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +14
-0@@ -0,0 +1,449 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* L2 switch Controller driver for MTIP block - switch MGNT +* +* Copyright (C) 2025 DENX Software Engineering GmbH +* Lukasz Majewski<[email protected]> +* +* Based on a previous work by: +* +* Copyright 2010-2012 Freescale Semiconductor, Inc. +* Alison Wang ([email protected]) +* Jason Jin ([email protected]) +* +* Copyright (C) 2010-2013 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Shrek Wu ([email protected])
+ */drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +9
-0+ +#include <linux/netdevice.h> +#include <linux/etherdevice.h> +#include <linux/platform_device.h> + +#include "mtipl2sw.h" + +int mtip_vlan_input_process (struct switch_enet_private *fep, + int port, int mode, unsigned short
port_vlanid,drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +1
-0+int vlan_verify_en, int
vlan_domain_num,drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +8
-0+ int vlan_domain_port) +{ +struct switch_t *fecp = fep->hwp; + +/* Only modes from 1 to 4 are valid*/ +if (mode <0 || mode >4 ) { + dev_err(&fep->pdev->dev, + "%s: VLAN input processing mode (%d) notsupported\n",
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +6
-0+ __func__, mode); +return -EINVAL ; + } + +if (port <0 || port >2 ) { + dev_err(&fep->pdev->dev, "%s: Port (%d) notsupported!\n",
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +7
-0+ __func__, port); +return -EINVAL ; + } + +if (vlan_verify_en ==1 && + (vlan_domain_num <0 || vlan_domain_num >32 )) { + dev_err(&fep->pdev->dev, "%s: Domain out ofrange\n",
__func__);drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +13
-0+return -EINVAL ; + } + + fecp->ESW_PID[port] =MCF_ESW_PID_VLANID (port_vlanid); +if (port ==0 ) { +if (vlan_verify_en ==1 ) +writel (MCF_ESW_VRES_VLANID (port_vlanid) | +MCF_ESW_VRES_P0 , + &fecp->ESW_VRES[vlan_domain_num]); + +writel (readl (&fecp->ESW_VIMEN) |MCF_ESW_VIMEN_EN0 , + &fecp->ESW_VIMEN); + writel(readl(&fecp->ESW_VIMSEL) |
MCF_ESW_VIMSEL_IM0(mode),drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +10
-0+ &fecp->ESW_VIMSEL); + }else if (port ==1 ) { +if (vlan_verify_en ==1 ) +writel (MCF_ESW_VRES_VLANID (port_vlanid) | +MCF_ESW_VRES_P1 , + &fecp->ESW_VRES[vlan_domain_num]); + +writel (readl (&fecp->ESW_VIMEN) |MCF_ESW_VIMEN_EN1 , + &fecp->ESW_VIMEN); + writel(readl(&fecp->ESW_VIMSEL) |
MCF_ESW_VIMSEL_IM1(mode),drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +10
-0+ &fecp->ESW_VIMSEL); + }else if (port ==2 ) { +if (vlan_verify_en ==1 ) +writel (MCF_ESW_VRES_VLANID (port_vlanid) | +MCF_ESW_VRES_P2 , + &fecp->ESW_VRES[vlan_domain_num]); + +writel (readl (&fecp->ESW_VIMEN) |MCF_ESW_VIMEN_EN2 , + &fecp->ESW_VIMEN); + writel(readl(&fecp->ESW_VIMSEL) |
MCF_ESW_VIMSEL_IM2(mode),drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +7
-0+ &fecp->ESW_VIMSEL); + } + +return 0 ; +} + +int mtip_vlan_output_process(struct switch_enet_private *fep, intport,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +6
-0+ int mode) +{ +struct switch_t *fecp = fep->hwp; + +if (port <0 || port >2 ) { + dev_err(&fep->pdev->dev, "%s: Port (%d) notsupported!\n",
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +6
-0+ __func__, port); +return -EINVAL ; + } + +if (port ==0 ) { + writel(readl(&fecp->ESW_VOMSEL) |
MCF_ESW_VOMSEL_OM0(mode),drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +3
-0+ &fecp->ESW_VOMSEL); + }else if (port ==1 ) { + writel(readl(&fecp->ESW_VOMSEL) |
MCF_ESW_VOMSEL_OM1(mode),drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +3
-0+ &fecp->ESW_VOMSEL); + }else if (port ==2 ) { + writel(readl(&fecp->ESW_VOMSEL) |
MCF_ESW_VOMSEL_OM2(mode),drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +7
-0+ &fecp->ESW_VOMSEL); + } + +return 0 ; +} + +int mtip_set_vlan_verification(struct switch_enet_private *fep,int port,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +7
-0+ int vlan_domain_verify_en, + int vlan_discard_unknown_en) +{ +struct switch_t *fecp = fep->hwp; + +if (port <0 || port >2 ) { + dev_err(&fep->pdev->dev, "%s: Port (%d) notsupported!\n",
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +7
-0+ __func__, port); +return -EINVAL ; + } + +if (vlan_domain_verify_en ==1 ) { +if (port ==0 ) + writel(readl(&fecp->ESW_VLANV) |
MCF_ESW_VLANV_VV0,drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +3
-0+ &fecp->ESW_VLANV); + else if (port == 1) + writel(readl(&fecp->ESW_VLANV) |
MCF_ESW_VLANV_VV1,drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +3
-0+ &fecp->ESW_VLANV); + else if (port == 2) + writel(readl(&fecp->ESW_VLANV) |
MCF_ESW_VLANV_VV2,drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +4
-0+ &fecp->ESW_VLANV); + }else if (vlan_domain_verify_en ==0 ) { +if (port ==0 ) + writel(readl(&fecp->ESW_VLANV) &~MCF_ESW_VLANV_VV0,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +3
-0+ &fecp->ESW_VLANV); + else if (port == 1) + writel(readl(&fecp->ESW_VLANV) &~MCF_ESW_VLANV_VV1,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +3
-0+ &fecp->ESW_VLANV); + else if (port == 2) + writel(readl(&fecp->ESW_VLANV) &~MCF_ESW_VLANV_VV2,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +6
-0+ &fecp->ESW_VLANV); + } + +if (vlan_discard_unknown_en ==1 ) { +if (port ==0 ) + writel(readl(&fecp->ESW_VLANV) |
MCF_ESW_VLANV_DU0,drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +3
-0+ &fecp->ESW_VLANV); + else if (port == 1) + writel(readl(&fecp->ESW_VLANV) |
MCF_ESW_VLANV_DU1,drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +3
-0+ &fecp->ESW_VLANV); + else if (port == 2) + writel(readl(&fecp->ESW_VLANV) |
MCF_ESW_VLANV_DU2,drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +4
-0+ &fecp->ESW_VLANV); + }else if (vlan_discard_unknown_en ==0 ) { +if (port ==0 ) + writel(readl(&fecp->ESW_VLANV) &~MCF_ESW_VLANV_DU0,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +3
-0+ &fecp->ESW_VLANV); + else if (port == 1) + writel(readl(&fecp->ESW_VLANV) &
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c
Quoted 7 lines
~MCF_ESW_VLANV_DU1,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +3
-0+ &fecp->ESW_VLANV); + else if (port == 2) + writel(readl(&fecp->ESW_VLANV) &~MCF_ESW_VLANV_DU2,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +2
-0+ &fecp->ESW_VLANV); + }This looks like a lot of copy & paste
IMHO, the readability of the code is OK.
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c line 175
Quoted 9 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +9
-0+ +dev_dbg (&fep->pdev->dev,"%s: ESW_VLANV %#lx\n" , __func__, + fecp->ESW_VLANV); + +return 0 ; +} + +int mtip_port_multicast_config (struct switch_enet_private *fep, +int port,int enable)bool enable
I've adjusted it globally in the mtipl2sw_mgnt.c file.
Quoted 90 lines
Quoted 90 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +6
-0+{ +struct switch_t *fecp = fep->hwp; +u32 tmp =0 ; + +if (port <0 || port >2 ) { + dev_err(&fep->pdev->dev, "%s: Port (%d) notsupported\n",
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +32
-0+ __func__, port); +return -EINVAL ; + } + + tmp =readl (&fecp->ESW_DMCR); +if (enable ==1 ) { +if (port ==0 ) + tmp |=MCF_ESW_DMCR_P0 ; +else if (port ==1 ) + tmp |=MCF_ESW_DMCR_P1 ; +else if (port ==2 ) + tmp |=MCF_ESW_DMCR_P2 ; + }else if (enable ==0 ) { +if (port ==0 ) + tmp &= ~MCF_ESW_DMCR_P0 ; +else if (port ==1 ) + tmp &= ~MCF_ESW_DMCR_P1 ; +else if (port ==2 ) + tmp &= ~MCF_ESW_DMCR_P2 ; + } + +writel (tmp, &fecp->ESW_DMCR); +return 0 ; +} + +/* enable or disable port n tx or rx +* tx_en 0 disable port n tx +* tx_en 1 enable port n tx +* rx_en 0 disable port n rx +* rx_en 1 enable port n rx +*/ +int mtip_port_enable_config(struct switch_enet_private *fep, intport,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +7
-0+ int tx_en, int rx_en) +{ +struct switch_t *fecp = fep->hwp; +u32 tmp =0 ; + +if (port <0 || port >2 ) { + dev_err(&fep->pdev->dev, "%s: Port (%d) notsupported\n",
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +42
-0+ __func__, port); +return -EINVAL ; + } + + tmp =readl (&fecp->ESW_PER); +if (tx_en ==1 ) { +if (port ==0 ) + tmp |=MCF_ESW_PER_TE0 ; +else if (port ==1 ) + tmp |=MCF_ESW_PER_TE1 ; +else if (port ==2 ) + tmp |=MCF_ESW_PER_TE2 ; + }else if (tx_en ==0 ) { +if (port ==0 ) + tmp &= (~MCF_ESW_PER_TE0 ); +else if (port ==1 ) + tmp &= (~MCF_ESW_PER_TE1 ); +else if (port ==2 ) + tmp &= (~MCF_ESW_PER_TE2 ); + } + +if (rx_en ==1 ) { +if (port ==0 ) + tmp |=MCF_ESW_PER_RE0 ; +else if (port ==1 ) + tmp |=MCF_ESW_PER_RE1 ; +else if (port ==2 ) + tmp |=MCF_ESW_PER_RE2 ; + }else if (rx_en ==0 ) { +if (port ==0 ) + tmp &= (~MCF_ESW_PER_RE0 ); +else if (port ==1 ) + tmp &= (~MCF_ESW_PER_RE1 ); +else if (port ==2 ) + tmp &= (~MCF_ESW_PER_RE2 ); + } + +writel (tmp, &fecp->ESW_PER); +return 0 ; +} + +void mtip_switch_en_port_separation(struct switch_enet_private
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c line 269
Quoted 7 lines
*fep) +{
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +6
-0+struct switch_t *fecp = fep->hwp; +u32 tmp; + +mtip_vlan_input_process (fep,0 ,3 ,0x10 ,1 ,0 ,0 ); +mtip_vlan_input_process (fep,1 ,3 ,0x11 ,1 ,1 ,0 ); +mtip_vlan_input_process (fep,2 ,3 ,0x12 ,1 ,2 ,0 );Looks like the last parameter is always 0?
Yes, I've explained it earlier in this reply.
Such function parameters would be helpful when adding for example fdb callback(s) in the future (next step).
Quoted 14 lines
Quoted 14 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +14
-0+ + tmp =readl (&fecp->ESW_VRES[0 ]); +writel (tmp |MCF_ESW_VRES_P1 |MCF_ESW_VRES_P2 , + &fecp->ESW_VRES[0 ]); + + tmp =readl (&fecp->ESW_VRES[1 ]); +writel (tmp |MCF_ESW_VRES_P0 , &fecp->ESW_VRES[1 ]); + + tmp =readl (&fecp->ESW_VRES[2 ]); +writel (tmp |MCF_ESW_VRES_P0 , &fecp->ESW_VRES[2 ]); + +dev_dbg (&fep->pdev->dev,"%s: VRES0: 0x%x\n" , + __func__,readl (&fecp->ESW_VRES[0 ])); + dev_dbg(&fep->pdev->dev, "%s: VRES1: 0x%x\n", __func__,
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c line 290
Quoted 7 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +7
-0+ readl(&fecp->ESW_VRES[1])); +dev_dbg (&fep->pdev->dev,"%s: VRES2: 0x%x\n" , __func__, +readl (&fecp->ESW_VRES[2 ])); + +mtip_set_vlan_verification (fep,0 ,1 ,0 ); +mtip_set_vlan_verification (fep,1 ,1 ,0 ); +mtip_set_vlan_verification (fep,2 ,1 ,0 );dito
Please look at the above comment.
Quoted 5 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c line 292
Quoted 4 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +4
-0+ +mtip_vlan_output_process (fep,0 ,2 );Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Looks like the last parameter is always 2?
Yes, correct. This is the "magic" behind port separation.
The in-chip "vlan" (name is confusing, thought) - mode 2 - provides separation of the egress ports.
Thanks for so thorough review. I do appreciate it.
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]
Part of the diff is not shown here. View the raw message.
Re: [net-next v4 4/5] net: mtip: The L2 switch driver for imx287
Am 10.04.25 um 15:37 schrieb Lukasz Majewski:
Quoted 186 lines
Hi Stefan,
Quoted 166 lines
Hi Lukasz,
thanks for sending this to linux-arm-kernel
Am 07.04.25 um 16:51 schrieb Lukasz Majewski:
Quoted 161 lines
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).
Signed-off-by Lukasz Majewski<[email protected]>---
Changes for v2:- Remove not needed comments
- Restore udelay(10) for switch reset (such delay is explicitly specifed in the documentation
- AddCOMPILE_TEST
- replace pr_* with dev_*
- Usefor_each_available_child_of_node_scoped()
- Use devm_* function for memory allocation
- Remove printing information about the HW and SW revision of the driver
- Usedevm_regulator_get_optional()
- Change compatible prefix from 'fsl' to more up to date 'nxp'
- Remove .owner =THIS_MODULE
- Usedevm_platform_ioremap_resource(pdev, 0);
- Usedevm_request_irq()
- Usedevm_regulator_get_enable_optional()
- Replaceclk_prepare_enable()anddevm_clk_get()with single call todevm_clk_get_optional_enabled()
- Cleanup error patch when function calls in probe fail
- Refactor themtip_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 atesw_mac_addr_static()
- Removemtip_print_link_status()and replace it withphy_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 removemtip_ndev_setup()
- Use-ENOMEMinstead of -1 return code when allocation fails
- Replacedev_info()withdev_dbg()to reduce number of information print on normal operation
- Return ret instead of 0 frommtip_ndev_init()
- Removefep->mii_timeoutflag from the driver
- Remove not used stop_gpr_* fields inmtip_devinfostruct
- Removeplatform_device_iddescription for mtipl2sw driver
- AddMODULE_DEVICE_TABLE()formtip_of_match
- RemoveMODULE_ALIAS()Changes for v4:
- Rename imx287 with imx28 (as the former is not used in kernel anymore)
- Reorder the place where ENET interface is initialized - without this change theenet_outclock has default (25 MHz) value, which causes issues during reset (RMII's 50 MHz is required for proper PHY reset).
- Use PAUR instead of PAUR register to program MAC address
- Replaceeth_mac_addr()witheth_hw_addr_set()
- Write to HW the randomly generated MAC address (if required)
- Adjust the reset code
- s/read_atable/mtip_read_atable/g and s/write_atable/mtip_write_atable/g
- Addclk_disable()andnetif_napi_del()when errors occur duringmtip_open()- refactor the error handling path.
- Refactor themtip_set_multicast_list()to write (now) correct values to ENET-FEC registers.
- Replacedev_warn()withdev_err()
- UseGPIO_ACTIVE_LOWto indicate polarity in DTS
- Refactor code to check if network device is the switch device
- Removemtip_port_dev_check()
- Refactormtip_ndev_port_link()avoid starting HW offloading for bridge when MTIP ports are parts of two distinct bridges
- Replacedel_timer()withtimer_delete_sync()--- 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 | 1970 +++++++++++++++++ .../net/ethernet/freescale/mtipsw/mtipl2sw.h | 782 +++++++ .../ethernet/freescale/mtipsw/mtipl2sw_br.c | 122 + .../ethernet/freescale/mtipsw/mtipl2sw_mgnt.c | 449 ++++ 9 files changed, 3348 insertions(+)create mode 100644
drivers/net/ethernet/freescale/mtipsw/Kconfigcreate mode 100644drivers/net/ethernet/freescale/mtipsw/Makefilecreate mode 100644drivers/net/ethernet/freescale/mtipsw/mtipl2sw.ccreate mode 100644drivers/net/ethernet/freescale/mtipsw/mtipl2sw.hcreate mode 100644drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.ccreate mode 100644drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.cMAINTAINERS +5
-0@@ -9455,6 +9455,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,imx28-mtip-switch.yamlMAINTAINERS +1
-0+F: drivers/net/ethernet/freescale/mtipsw/* + FREESCALE QORIQ DPAA ETHERNET DRIVER M: Madalin Bucur<[email protected]> L: [email protected](quoted diff) +0
-0b/drivers/net/ethernet/freescale/Kconfig index
a2d7300925a8..056a11c3a74e100644 --- a/drivers/net/ethernet/freescale/Kconfig +++ b/drivers/net/ethernet/freescale/Kconfig @@ -60,6 +60,7 @@ configFEC_MPC52xx_MDIOsource "
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" diff --git
a/drivers/net/ethernet/freescale/Makefile b/drivers/net/ethernet/freescale/Makefile indexde7b31842233..0e6cacb0948a100644 --- a/drivers/net/ethernet/freescale/Makefile +++ b/drivers/net/ethernet/freescale/Makefile @@ -25,3 +25,4 @@ obj-$(CONFIG_FSL_DPAA_ETH) += dpaa/ obj-$(CONFIG_FSL_DPAA2_ETH) += dpaa2/ obj-y += enetc/ +obj-y += mtipsw/ diff --git a/drivers/net/ethernet/freescale/mtipsw/Kconfig b/drivers/net/ethernet/freescale/mtipsw/Kconfig new file mode 100644 index 000000000000..450ff734a321 ---/dev/null+++ b/drivers/net/ethernet/freescale/mtipsw/Kconfig @@ -0,0 +1,13 @@ +#
SPDX-License-Identifier: GPL-2.0-only +configFEC_MTIP_L2SW+ tristate "MoreThanIP L2 switch support to FEC driver"drivers/net/ethernet/freescale/mtipsw/Kconfig new file +4
-0+ depends on OF + depends on NET_SWITCHDEV + depends on BRIDGE + depends on ARCH_MXS || ARCH_MXC || COMPILE_TESTQuoted 8 lines
Quoted 5 lines
(quoted diff) +2
-0+ help + This enables support for the MoreThan IP L2 switch oni.MX
(quoted diff) +1
-0+ SoCs (e.g. iMX28, vf610). It offloads bridging to thisIP block's
This is confusing. The
Kconfigand most of the code looks prepared for other platforms than i.MX28, but there is only a i.MX28 OF compatible.I've took the approach to upstream the driver in several steps. The first step is this patch set - add the code for a single platform (imx28).
And Yes, I also have on my desk another board with soc having this IP block (vf610).
However, I will not start any other upstream work until patches from this "step" are not pulled.
Quoted 6 lines
(To follow "one things at a time" principle)
Quoted 2 lines
I don't like that
Kconfigpretent something, which is not true.If you prefer I can remove 'depends on
ARCH_MXC' and the vf610 SoC... (only to add it afterwards).
In case you want to do "one thing at a time", please remove this.
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +6
-0+ +static void mtip_config_switch (struct switch_enet_private *fep) +{ +struct switch_t *fecp = fep->hwp; + +esw_mac_addr_static (fep);Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 518
Quoted 7 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +7
-0+ +writel (0 , &fecp->ESW_BKLR); + +/* Do NOT disable learning */ +mtip_port_learning_config (fep,0 ,0 ,0 ); +mtip_port_learning_config (fep,1 ,0 ,0 ); +mtip_port_learning_config (fep,2 ,0 ,0 );Looks like the last 2 parameter are always 0?
Quoted 5 lines
Those functions are defined in
mtipl2sw_mgnt.cfile.I've followed the way legacy (i.e. vendor) driver has defined them. In this particular case the last '0' is to not enable interrupt for learning.
This wasn't my concern. The question was "why do we need a parameter if it's always the same?". But you answered this further below, so i'm fine.
Quoted 27 lines
Quoted 19 lines
Quoted 19 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +14
-0+ +static irqreturn_t mtip_interrupt(int irq, void *ptr_fep) +{ + struct switch_enet_private *fep = ptr_fep; + struct switch_t *fecp = fep->hwp; + irqreturn_t ret = IRQ_NONE; + u32 int_events, int_imask; + + /* Get the interrupt events that caused us to be here */ + do { + int_events = readl(&fecp->ESW_ISR); + writel(int_events, &fecp->ESW_ISR); + + if (int_events & (MCF_ESW_ISR_RXF |
MCF_ESW_ISR_TXF)) {drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +4
-0+ ret =IRQ_HANDLED ; +/* Disable the RX interrupt */ +if (napi_schedule_prep (&fep->napi)) { + int_imask =readl (&fecp->ESW_IMR);Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 891
Quoted 6 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +6
-0+ int_imask &= ~MCF_ESW_IMR_RXF ; +writel (int_imask, &fecp->ESW_IMR); +__napi_schedule (&fep->napi); + } + } + }while (int_events);This looks bad, in case of bad hardware / timing behavior this interrupt handler will loop forever.
Quoted 7 lines
The '
writel(int_events, &fecp->ESW_ISR);'clears the interrupts, so after reading them and clearing (by writing the same value), the
int_eventsshall be 0.Also, during probe the IRQ mask for switch IRQ is written, so only expected (and served) interrupts are delivered.
This was not my point. A possible endless loop especially in a interrupt handler should be avoided. The kernel shouldn't trust the hardware and the driver should be fair to all the other interrupts which might have occurred.
Quoted 12 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +11
-0+ +static int mtip_rx_napi (struct napi_struct *napi,int budget) +{ +struct mtip_ndev_priv *priv =netdev_priv (napi->dev); +struct switch_enet_private *fep = priv->fep; +struct switch_t *fecp = fep->hwp; +int pkts, port; + + pkts =mtip_switch_rx (napi->dev, budget, &port); +if (!fep->br_offload && + (port ==1 || port ==2 ) && fep->ndev[port -1 ])Quoted 1 line
(port > 0) && fep->ndev[port - 1])
Quoted 2 lines
This needs to be kept as is - only when port is set to 1 or 2 (after reading the switch internal register) this shall be executed.
Oops, missed that
Quoted 2 lines
(port also can be
0xFFor0x3-> then we shall send frame to both egress ports).
Maybe we should use defines for such special values
Quoted 7 lines
This code is responsible for port separation when bridge HW offloading is disabled.
Quoted 3 lines
Quoted 2 lines
(quoted diff) +1
-0+ of_get_mac_address(port, &fep->mac[port_num -1][0]);
This can fail
Quoted 8 lines
I will add:
ret =
of_get_mac_address(port, &fep->mac[port_num - 1][0]); if (ret)dev_warn(dev, "of_get_mac_address(%pOF) failed\n", port);as it is also valid to not have the mac address defined in DTS (then some random based value is generated).
AFAIK this is a little bit more complex. It's possible that the MAC is stored within a NVMEM and the driver isn't ready (EPROBE_DEFER).
Are you sure about the randomize fallback behavior of of_get_mac_address() ?
I tought you still need to call eth_random_addr().
Quoted 71 lines
Quoted 63 lines
Quoted 63 lines
(quoted diff) +2
-0+ +int mtip_set_vlan_verification(struct switch_enet_private *fep,int port,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +7
-0+ int vlan_domain_verify_en, + int vlan_discard_unknown_en) +{ +struct switch_t *fecp = fep->hwp; + +if (port <0 || port >2 ) { + dev_err(&fep->pdev->dev, "%s: Port (%d) notsupported!\n",
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +7
-0+ __func__, port); +return -EINVAL ; + } + +if (vlan_domain_verify_en ==1 ) { +if (port ==0 ) + writel(readl(&fecp->ESW_VLANV) |
MCF_ESW_VLANV_VV0,drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +3
-0+ &fecp->ESW_VLANV); + else if (port == 1) + writel(readl(&fecp->ESW_VLANV) |
MCF_ESW_VLANV_VV1,drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +3
-0+ &fecp->ESW_VLANV); + else if (port == 2) + writel(readl(&fecp->ESW_VLANV) |
MCF_ESW_VLANV_VV2,drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +4
-0+ &fecp->ESW_VLANV); + }else if (vlan_domain_verify_en ==0 ) { +if (port ==0 ) + writel(readl(&fecp->ESW_VLANV) &~MCF_ESW_VLANV_VV0,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +3
-0+ &fecp->ESW_VLANV); + else if (port == 1) + writel(readl(&fecp->ESW_VLANV) &~MCF_ESW_VLANV_VV1,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +3
-0+ &fecp->ESW_VLANV); + else if (port == 2) + writel(readl(&fecp->ESW_VLANV) &~MCF_ESW_VLANV_VV2,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +6
-0+ &fecp->ESW_VLANV); + } + +if (vlan_discard_unknown_en ==1 ) { +if (port ==0 ) + writel(readl(&fecp->ESW_VLANV) |
MCF_ESW_VLANV_DU0,drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +3
-0+ &fecp->ESW_VLANV); + else if (port == 1) + writel(readl(&fecp->ESW_VLANV) |
MCF_ESW_VLANV_DU1,drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +3
-0+ &fecp->ESW_VLANV); + else if (port == 2) + writel(readl(&fecp->ESW_VLANV) |
MCF_ESW_VLANV_DU2,drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +4
-0+ &fecp->ESW_VLANV); + }else if (vlan_discard_unknown_en ==0 ) { +if (port ==0 ) + writel(readl(&fecp->ESW_VLANV) &~MCF_ESW_VLANV_DU0,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +3
-0+ &fecp->ESW_VLANV); + else if (port == 1) + writel(readl(&fecp->ESW_VLANV) &Quoted 8 lines
Review
Quoted 7 lines
~MCF_ESW_VLANV_DU1,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +3
-0+ &fecp->ESW_VLANV); + else if (port == 2) + writel(readl(&fecp->ESW_VLANV) &~MCF_ESW_VLANV_DU2,
(quoted diff) +2
-0+ &fecp->ESW_VLANV); + }This looks like a lot of copy & paste
Quoted 1 line
IMHO, the readability of the code is OK.
Actually the concern was about maintenance.
Re: [net-next v4 4/5] net: mtip: The L2 switch driver for imx287
Hi Stefan,
Quoted 193 lines
Am 10.04.25 um 15:37 schrieb Lukasz Majewski:
Quoted 192 lines
Hi Stefan,
Quoted 172 lines
Hi Lukasz,
thanks for sending this to linux-arm-kernel
Am 07.04.25 um 16:51 schrieb Lukasz Majewski:
Quoted 167 lines
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).
Signed-off-by Lukasz Majewski<[email protected]>---
Changes for v2:- Remove not needed comments
- Restore udelay(10) for switch reset (such delay is explicitly specifed in the documentation
- AddCOMPILE_TEST
- replace pr_* with dev_*
- Usefor_each_available_child_of_node_scoped()
- Use devm_* function for memory allocation
- Remove printing information about the HW and SW revision of the driver
- Usedevm_regulator_get_optional()
- Change compatible prefix from 'fsl' to more up to date 'nxp'
- Remove .owner =THIS_MODULE
- Usedevm_platform_ioremap_resource(pdev, 0);
- Usedevm_request_irq()
- Usedevm_regulator_get_enable_optional()
- Replaceclk_prepare_enable()anddevm_clk_get()with single call todevm_clk_get_optional_enabled()
- Cleanup error patch when function calls in probe fail
- Refactor themtip_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 atesw_mac_addr_static()
- Removemtip_print_link_status()and replace it withphy_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 removemtip_ndev_setup()
- Use-ENOMEMinstead of -1 return code when allocation fails
- Replacedev_info()withdev_dbg()to reduce number of information print on normal operation
- Return ret instead of 0 frommtip_ndev_init()
- Removefep->mii_timeoutflag from the driver
- Remove not used stop_gpr_* fields inmtip_devinfostruct
- Removeplatform_device_iddescription for mtipl2sw driver
- AddMODULE_DEVICE_TABLE()formtip_of_match
- RemoveMODULE_ALIAS()Changes for v4:
- Rename imx287 with imx28 (as the former is not used in kernel anymore)
- Reorder the place where ENET interface is initialized - without this change theenet_outclock has default (25 MHz) value, which causes issues during reset (RMII's 50 MHz is required for proper PHY reset).
- Use PAUR instead of PAUR register to program MAC address
- Replaceeth_mac_addr()witheth_hw_addr_set()
- Write to HW the randomly generated MAC address (if required)
- Adjust the reset code
- s/read_atable/mtip_read_atable/g and s/write_atable/mtip_write_atable/g
- Addclk_disable()andnetif_napi_del()when errors occur duringmtip_open()- refactor the error handling path.
- Refactor themtip_set_multicast_list()to write (now) correct values to ENET-FEC registers.
- Replacedev_warn()withdev_err()
- UseGPIO_ACTIVE_LOWto indicate polarity in DTS
- Refactor code to check if network device is the switch device
- Removemtip_port_dev_check()
- Refactormtip_ndev_port_link()avoid starting HW offloading for bridge when MTIP ports are parts of two distinct bridges
- Replacedel_timer()withtimer_delete_sync()--- 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 | 1970 +++++++++++++++++ .../net/ethernet/freescale/mtipsw/mtipl2sw.h | 782 +++++++ .../ethernet/freescale/mtipsw/mtipl2sw_br.c | 122 + .../ethernet/freescale/mtipsw/mtipl2sw_mgnt.c | 449 ++++ 9 files changed, 3348 insertions(+)create mode 100644
drivers/net/ethernet/freescale/mtipsw/Kconfigcreate mode 100644drivers/net/ethernet/freescale/mtipsw/Makefilecreate mode 100644drivers/net/ethernet/freescale/mtipsw/mtipl2sw.ccreate mode 100644drivers/net/ethernet/freescale/mtipsw/mtipl2sw.hcreate mode 100644drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.ccreate mode 100644drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.cMAINTAINERS +5
-0@@ -9455,6 +9455,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,imx28-mtip-switch.yamlMAINTAINERS +1
-0+F: drivers/net/ethernet/freescale/mtipsw/* + FREESCALE QORIQ DPAA ETHERNET DRIVER M: Madalin Bucur<[email protected]> L: [email protected](quoted diff) +0
-0b/drivers/net/ethernet/freescale/Kconfig index
a2d7300925a8..056a11c3a74e100644 --- a/drivers/net/ethernet/freescale/Kconfig +++ b/drivers/net/ethernet/freescale/Kconfig @@ -60,6 +60,7 @@ configFEC_MPC52xx_MDIOsource "
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" diff --git
a/drivers/net/ethernet/freescale/Makefile b/drivers/net/ethernet/freescale/Makefile indexde7b31842233..0e6cacb0948a100644 --- a/drivers/net/ethernet/freescale/Makefile +++ b/drivers/net/ethernet/freescale/Makefile @@ -25,3 +25,4 @@ obj-$(CONFIG_FSL_DPAA_ETH) += dpaa/ obj-$(CONFIG_FSL_DPAA2_ETH) += dpaa2/ obj-y += enetc/ +obj-y += mtipsw/ diff --git a/drivers/net/ethernet/freescale/mtipsw/Kconfig b/drivers/net/ethernet/freescale/mtipsw/Kconfig new file mode 100644 index 000000000000..450ff734a321 ---/dev/null+++ b/drivers/net/ethernet/freescale/mtipsw/Kconfig @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0-only +configFEC_MTIP_L2SW+ tristate "MoreThanIP L2 switch support to FEC driver"drivers/net/ethernet/freescale/mtipsw/Kconfig new file +4
-0+ depends on OF + depends on NET_SWITCHDEV + depends on BRIDGE + depends on ARCH_MXS || ARCH_MXC || COMPILE_TESTQuoted 8 lines
Quoted 5 lines
(quoted diff) +2
-0+ help + This enables support for the MoreThan IP L2 switch oni.MX
(quoted diff) +1
-0+ SoCs (e.g. iMX28, vf610). It offloads bridging to thisIP block's
This is confusing. The
Kconfigand most of the code looks prepared for other platforms than i.MX28, but there is only a i.MX28 OF compatible.I've took the approach to upstream the driver in several steps. The first step is this patch set - add the code for a single platform (imx28).
And Yes, I also have on my desk another board with soc having this IP block (vf610).
However, I will not start any other upstream work until patches from this "step" are not pulled.
Quoted 7 lines
Quoted 6 lines
(To follow "one things at a time" principle)
Quoted 2 lines
I don't like that
Kconfigpretent something, which is not true.If you prefer I can remove 'depends on
ARCH_MXC' and the vf610 SoC... (only to add it afterwards).In case you want to do "one thing at a time", please remove this.
+1
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 518
Quoted 13 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +13
-0+ +static void mtip_config_switch (struct switch_enet_private *fep) +{ +struct switch_t *fecp = fep->hwp; + +esw_mac_addr_static (fep); + +writel (0 , &fecp->ESW_BKLR); + +/* Do NOT disable learning */ +mtip_port_learning_config (fep,0 ,0 ,0 ); +mtip_port_learning_config (fep,1 ,0 ,0 ); +mtip_port_learning_config (fep,2 ,0 ,0 );Looks like the last 2 parameter are always 0?
Quoted 8 lines
Quoted 5 lines
Those functions are defined in
mtipl2sw_mgnt.cfile.I've followed the way legacy (i.e. vendor) driver has defined them. In this particular case the last '0' is to not enable interrupt for learning.
This wasn't my concern. The question was "why do we need a parameter if it's always the same?". But you answered this further below, so i'm fine.
Ok.
Quoted 34 lines
Quoted 34 lines
Quoted 21 lines
Quoted 21 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +14
-0+ +static irqreturn_t mtip_interrupt(int irq, void *ptr_fep) +{ + struct switch_enet_private *fep = ptr_fep; + struct switch_t *fecp = fep->hwp; + irqreturn_t ret = IRQ_NONE; + u32 int_events, int_imask; + + /* Get the interrupt events that caused us to be here */ + do { + int_events = readl(&fecp->ESW_ISR); + writel(int_events, &fecp->ESW_ISR); + + if (int_events & (MCF_ESW_ISR_RXF |
MCF_ESW_ISR_TXF)) {drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +4
-0+ ret =IRQ_HANDLED ; +/* Disable the RX interrupt */ +if (napi_schedule_prep (&fep->napi)) { + int_imask =
readl(&fecp->ESW_IMR);drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +1
-0+ int_imask &= ~MCF_ESW_IMR_RXF ;Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 891
Quoted 6 lines
(quoted diff) +1
-0+ writel(int_imask,
&fecp->ESW_IMR);drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +4
-0+__napi_schedule (&fep->napi); + } + } + }while (int_events);This looks bad, in case of bad hardware / timing behavior this interrupt handler will loop forever.
The '
writel(int_events, &fecp->ESW_ISR);'clears the interrupts, so after reading them and clearing (by writing the same value), the
int_eventsshall be 0.
Quoted 6 lines
Quoted 2 lines
Also, during probe the IRQ mask for switch IRQ is written, so only expected (and served) interrupts are delivered.
This was not my point. A possible endless loop especially in a interrupt handler should be avoided. The kernel shouldn't trust the hardware and the driver should be fair to all the other interrupts which might have occurred.
Ok.
Quoted 11 lines
Quoted 11 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +11
-0+ +static int mtip_rx_napi (struct napi_struct *napi,int budget) +{ +struct mtip_ndev_priv *priv =netdev_priv (napi->dev); +struct switch_enet_private *fep = priv->fep; +struct switch_t *fecp = fep->hwp; +int pkts, port; + + pkts =mtip_switch_rx (napi->dev, budget, &port); +if (!fep->br_offload && + (port ==1 || port ==2 ) && fep->ndev[port -1 ])
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
(port > 0) && fep->ndev[port - 1])
This needs to be kept as is - only when port is set to 1 or 2 (after reading the switch internal register) this shall be executed.
Oops, missed that
Quoted 2 lines
(port also can be
0xFFor0x3-> then we shall send frame to both egress ports).Maybe we should use defines for such special values
Port = 1 or port = 2 seems to be self explanatory.
Nonetheless, I've added MTIP_PORT_FORWARDING_INIT for 0xFF initial forwarding value.
Quoted 9 lines
Quoted 9 lines
This code is responsible for port separation when bridge HW offloading is disabled.
Quoted 3 lines
Quoted 2 lines
(quoted diff) +1
-0+ of_get_mac_address(port, &fep->mac[port_num -1][0]);
This can fail
I will add:
Quoted 9 lines
Quoted 6 lines
ret =
of_get_mac_address(port, &fep->mac[port_num - 1][0]); if (ret)dev_warn(dev, "of_get_mac_address(%pOF) failed\n", port);as it is also valid to not have the mac address defined in DTS (then some random based value is generated).
AFAIK this is a little bit more complex. It's possible that the MAC is stored within a NVMEM and the driver isn't ready (
EPROBE_DEFER).
In my use case - always the local mac address is provided during production (to ethernet-port nodes).
The other possibility is no MAC address provided, that is why there is dev_warn().
Quoted 5 lines
Are you sure about the randomize fallback behavior of
of_get_mac_address()?I tought you still need to call
eth_random_addr().
The "random" MAC address is generated in another place - namely mtip_setup_mac();
Quoted 72 lines
Quoted 72 lines
Quoted 72 lines
Quoted 69 lines
(quoted diff) +2
-0+ +int mtip_set_vlan_verification(struct switch_enet_private *fep,int port,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +7
-0+ int vlan_domain_verify_en, + int vlan_discard_unknown_en) +{ +struct switch_t *fecp = fep->hwp; + +if (port <0 || port >2 ) { + dev_err(&fep->pdev->dev, "%s: Port (%d) notsupported!\n",
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +7
-0+ __func__, port); +return -EINVAL ; + } + +if (vlan_domain_verify_en ==1 ) { +if (port ==0 ) + writel(readl(&fecp->ESW_VLANV) |
MCF_ESW_VLANV_VV0,drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +3
-0+ &fecp->ESW_VLANV); + else if (port == 1) + writel(readl(&fecp->ESW_VLANV) |
MCF_ESW_VLANV_VV1,drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +3
-0+ &fecp->ESW_VLANV); + else if (port == 2) + writel(readl(&fecp->ESW_VLANV) |
MCF_ESW_VLANV_VV2,drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +4
-0+ &fecp->ESW_VLANV); + }else if (vlan_domain_verify_en ==0 ) { +if (port ==0 ) + writel(readl(&fecp->ESW_VLANV) &~MCF_ESW_VLANV_VV0,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +3
-0+ &fecp->ESW_VLANV); + else if (port == 1) + writel(readl(&fecp->ESW_VLANV) &~MCF_ESW_VLANV_VV1,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +3
-0+ &fecp->ESW_VLANV); + else if (port == 2) + writel(readl(&fecp->ESW_VLANV) &~MCF_ESW_VLANV_VV2,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +6
-0+ &fecp->ESW_VLANV); + } + +if (vlan_discard_unknown_en ==1 ) { +if (port ==0 ) + writel(readl(&fecp->ESW_VLANV) |
MCF_ESW_VLANV_DU0,drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +3
-0+ &fecp->ESW_VLANV); + else if (port == 1) + writel(readl(&fecp->ESW_VLANV) |
MCF_ESW_VLANV_DU1,drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +3
-0+ &fecp->ESW_VLANV); + else if (port == 2) + writel(readl(&fecp->ESW_VLANV) |
MCF_ESW_VLANV_DU2,drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +4
-0+ &fecp->ESW_VLANV); + }else if (vlan_discard_unknown_en ==0 ) { +if (port ==0 ) + writel(readl(&fecp->ESW_VLANV) &~MCF_ESW_VLANV_DU0,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +3
-0+ &fecp->ESW_VLANV); + else if (port == 1) + writel(readl(&fecp->ESW_VLANV) &~MCF_ESW_VLANV_DU1,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +3
-0+ &fecp->ESW_VLANV); + else if (port == 2) + writel(readl(&fecp->ESW_VLANV) &~MCF_ESW_VLANV_DU2,
Review
Quoted 2 lines
(quoted diff) +2
-0+ &fecp->ESW_VLANV); + }This looks like a lot of copy & paste
Quoted 2 lines
Quoted 1 line
IMHO, the readability of the code is OK.
Actually the concern was about maintenance.
IMHO, (for me) the maintenance cost of this code is acceptable.
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]
Re: [net-next v4 4/5] net: mtip: The L2 switch driver for imx287
In reply to Lukasz MajewskiQuoted 7 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +7
-0+static int mtip_ndev_port_link (struct net_device *ndev, +struct net_device *br_ndev, +struct netlink_ext_ack *extack) +{ +struct mtip_ndev_priv *priv =netdev_priv (ndev), *other_priv; +struct switch_enet_private *fep = priv->fep; +struct net_device *other_ndev;
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c line 30
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +10
-0+ +/* Check if one port of MTIP switch is already bridged */ +if (fep->br_members && !fep->br_offload) { +/* Get the second bridge ndev */ + other_ndev = fep->ndev[fep->br_members -1 ]; + other_priv =netdev_priv (other_ndev); +if (other_priv->master_dev != br_ndev) { +NL_SET_ERR_MSG_MOD (extack, +"L2 offloading only possible for the same bridge!" ); +return notifier_from_errno (-EOPNOTSUPP );
This is not an error condition as such. The switch cannot do it, so -EOPNOTSUPP is correct, but the Linux software bridge can, and it will. So there is no need to use NL_SET_ERR_MSG_MOD().
Quoted 26 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +26
-0+ } + + fep->br_offload =1 ; +mtip_switch_dis_port_separation (fep); +mtip_clear_atable (fep); + } + +if (!priv->master_dev) + priv->master_dev = br_ndev; + + fep->br_members |=BIT (priv->portnum -1 ); + +dev_dbg (&ndev->dev, +"%s: ndev: %s br: %s fep: 0x%x members: 0x%x offload: %d\n" , + __func__, ndev->name, br_ndev->name, (unsigned int )fep, + fep->br_members, fep->br_offload); + +return NOTIFY_DONE ; +} + +static void mtip_netdevice_port_unlink (struct net_device *ndev) +{ +struct mtip_ndev_priv *priv =netdev_priv (ndev); +struct switch_enet_private *fep = priv->fep; + + dev_dbg(&ndev->dev, "%s: ndev: %s members: 0x%x\n", __func__,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c line 66
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +10
-0+ ndev->name, fep->br_members); + + fep->br_members &= ~BIT (priv->portnum -1 ); + priv->master_dev =NULL ; + +if (!fep->br_members) { + fep->br_offload =0 ; +mtip_switch_en_port_separation (fep); +mtip_clear_atable (fep); + }
This does not look quite correct. So you disable port separation once both ports are a member of the same bridge. So you should enable port separation as soon as one leaves. So if fep->br_members has 0 or 1 bits set, you need to enable port separation.
Andrew
Re: [net-next v4 4/5] net: mtip: The L2 switch driver for imx287
Hi Andrew,
Quoted 14 lines
Quoted 14 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +5
-0+static int mtip_ndev_port_link (struct net_device *ndev, +struct net_device *br_ndev, +struct netlink_ext_ack *extack) +{ + struct mtip_ndev_priv *priv = netdev_priv(ndev),
*other_priv;drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +8
-0+struct switch_enet_private *fep = priv->fep; +struct net_device *other_ndev; + +/* Check if one port of MTIP switch is already bridged */ +if (fep->br_members && !fep->br_offload) { +/* Get the second bridge ndev */ + other_ndev = fep->ndev[fep->br_members -1 ]; + other_priv =netdev_priv (other_ndev);
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c line 30
Quoted 5 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +3
-0+if (other_priv->master_dev != br_ndev) { + NL_SET_ERR_MSG_MOD(extack, + "L2 offloading onlypossible for the same bridge!");
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +1
-0+return notifier_from_errno (-EOPNOTSUPP );This is not an error condition as such. The switch cannot do it, so
-EOPNOTSUPPis correct,
Ok, so the:
return notifier_from_errno(-EOPNOTSUPP);
is correct.
Quoted 3 lines
but the Linux software bridge can, and it will. So there is no need to use
NL_SET_ERR_MSG_MOD().
This NL_SET_ERR_MSG_MOD() only is relevant for two ports managed by MTIP L2 switch driver.
As a result - other bridges created by other drivers will not follow this execution path.
Considering the above - I would keep this message - it is informative for the potential user (similar approach has been taken when HSR driver was added for KSZ9477 switch).
Quoted 37 lines
Quoted 37 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +14
-0+ } + + fep->br_offload =1 ; +mtip_switch_dis_port_separation (fep); +mtip_clear_atable (fep); + } + +if (!priv->master_dev) + priv->master_dev = br_ndev; + + fep->br_members |=BIT (priv->portnum -1 ); + + dev_dbg(&ndev->dev, + "%s: ndev: %s br: %s fep: 0x%x members: 0x%xoffload: %d\n",
(quoted diff) +1
-0+ __func__, ndev->name, br_ndev->name, (unsignedint)fep,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +11
-0+ fep->br_members, fep->br_offload); + +return NOTIFY_DONE ; +} + +static void mtip_netdevice_port_unlink (struct net_device *ndev) +{ +struct mtip_ndev_priv *priv =netdev_priv (ndev); +struct switch_enet_private *fep = priv->fep; + + dev_dbg(&ndev->dev, "%s: ndev: %s members: 0x%x\n",
__func__,drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +7
-0+ ndev->name, fep->br_members); + + fep->br_members &= ~BIT (priv->portnum -1 ); + priv->master_dev =NULL ; + +if (!fep->br_members) { + fep->br_offload =0 ;
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c line 66
Quoted 3 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +3
-0+mtip_switch_en_port_separation (fep); +mtip_clear_atable (fep); + }This does not look quite correct. So you disable port separation once both ports are a member of the same bridge. So you should enable port separation as soon as one leaves. So if
fep->br_membershas 0 or 1 bits set, you need to enable port separation.
Yes, the if (!fep->br_members)
shall be replaced with:
if (fep->br_members && fep->br_offload)
to avoid situation when disabling second port would re-enable separation and clear atable.
Quoted 2 lines
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]
PATCH v4 5/5 ARM: mxs_defconfig: Enable CONFIG_FEC_MTIP_L2SW to support MTIP L2 switch
In reply to Lukasz MajewskiThis patch enables support for More Than IP switch available on some imx28[7] devices.
---
Changes for v4:
- New patch
--- arch/arm/configs/mxs_defconfig | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)
arch/arm/configs/mxs_defconfig +3 -11
@@ -32,11 +32,10 @@ CONFIG_INET=y CONFIG_IP_PNP=y CONFIG_IP_PNP_DHCP=y CONFIG_SYN_COOKIES=y -# CONFIG_INET_XFRM_MODE_TRANSPORT is not set -# CONFIG_INET_XFRM_MODE_TUNNEL is not set -# CONFIG_INET_XFRM_MODE_BEET is not set # CONFIG_INET_DIAG is not set # CONFIG_IPV6 is not set +CONFIG_BRIDGE=y +CONFIG_NET_SWITCHDEV=y CONFIG_CAN=m # CONFIG_WIRELESS is not set CONFIG_DEVTMPFS=y
@@ -45,7 +44,6 @@ CONFIG_MTD=y CONFIG_MTD_CMDLINE_PARTS=y CONFIG_MTD_BLOCK=y CONFIG_MTD_DATAFLASH=y -CONFIG_MTD_M25P80=y CONFIG_MTD_SST25L=y CONFIG_MTD_RAW_NAND=y CONFIG_MTD_NAND_GPMI_NAND=y
@@ -56,11 +54,11 @@ CONFIG_EEPROM_AT24=y CONFIG_SCSI=y CONFIG_BLK_DEV_SD=y CONFIG_NETDEVICES=y +CONFIG_FEC_MTIP_L2SW=y CONFIG_ENC28J60=y CONFIG_ICPLUS_PHY=y CONFIG_MICREL_PHY=y CONFIG_REALTEK_PHY=y -CONFIG_SMSC_PHY=y CONFIG_CAN_FLEXCAN=m CONFIG_USB_USBNET=y CONFIG_USB_NET_SMSC95XX=y
@@ -77,13 +75,11 @@ CONFIG_SERIAL_AMBA_PL011=y CONFIG_SERIAL_AMBA_PL011_CONSOLE=y CONFIG_SERIAL_MXS_AUART=y # CONFIG_HW_RANDOM is not set -# CONFIG_I2C_COMPAT is not set CONFIG_I2C_CHARDEV=y CONFIG_I2C_MXS=y CONFIG_SPI=y CONFIG_SPI_GPIO=m CONFIG_SPI_MXS=y -CONFIG_GPIO_SYSFS=y # CONFIG_HWMON is not set CONFIG_WATCHDOG=y CONFIG_STMP3XXX_RTC_WATCHDOG=y
@@ -138,10 +134,6 @@ CONFIG_PWM_MXS=y CONFIG_NVMEM_MXS_OCOTP=y CONFIG_EXT4_FS=y # CONFIG_DNOTIFY is not set -CONFIG_NETFS_SUPPORT=m -CONFIG_FSCACHE=y -CONFIG_FSCACHE_STATS=y -CONFIG_CACHEFILES=m CONFIG_VFAT_FS=y CONFIG_TMPFS=y CONFIG_TMPFS_POSIX_ACL=y
Signature · 1 line
2.39.5
Re: [net-next v4 5/5] ARM: mxs_defconfig: Enable CONFIG_FEC_MTIP_L2SW to support MTIP L2 switch
Hi Lukasz,
Am 07.04.25 um 16:51 schrieb Lukasz Majewski:
Quoted 4 lines
This patch enables support for More Than IP switch available on some imx28[7] devices.
Signed-off-by Lukasz Majewski <[email protected]>
thanks adding the driver to mxs_defconfig. Unfortunately it's not possible for reviewers to identify the relevant changes, also the commit messages doesn't provide further information.
In general there are two approaches to solves this:
1) prepend an additional patch which synchronizes mxs_defconfig with current mainline
2) manually create the relevant changes against mxs_defconfig
The decision about the approaches is up to the maintainer.
Btw driver review will follow ...
Regards
Quoted 71 lines
---
Changes for v4:
- New patch--- arch/arm/configs/mxs_defconfig | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)arch/arm/configs/mxs_defconfig +3
-11@@ -32,11 +32,10 @@ CONFIG_INET=y CONFIG_IP_PNP=y CONFIG_IP_PNP_DHCP=y CONFIG_SYN_COOKIES=y -# CONFIG_INET_XFRM_MODE_TRANSPORT is not set -# CONFIG_INET_XFRM_MODE_TUNNEL is not set -# CONFIG_INET_XFRM_MODE_BEET is not set # CONFIG_INET_DIAG is not set # CONFIG_IPV6 is not set +CONFIG_BRIDGE=y +CONFIG_NET_SWITCHDEV=y CONFIG_CAN=m # CONFIG_WIRELESS is not set CONFIG_DEVTMPFS=y@@ -45,7 +44,6 @@ CONFIG_MTD=y CONFIG_MTD_CMDLINE_PARTS=y CONFIG_MTD_BLOCK=y CONFIG_MTD_DATAFLASH=y -CONFIG_MTD_M25P80=y CONFIG_MTD_SST25L=y CONFIG_MTD_RAW_NAND=y CONFIG_MTD_NAND_GPMI_NAND=y@@ -56,11 +54,11 @@ CONFIG_EEPROM_AT24=y CONFIG_SCSI=y CONFIG_BLK_DEV_SD=y CONFIG_NETDEVICES=y +CONFIG_FEC_MTIP_L2SW=y CONFIG_ENC28J60=y CONFIG_ICPLUS_PHY=y CONFIG_MICREL_PHY=y CONFIG_REALTEK_PHY=y -CONFIG_SMSC_PHY=y CONFIG_CAN_FLEXCAN=m CONFIG_USB_USBNET=y CONFIG_USB_NET_SMSC95XX=y@@ -77,13 +75,11 @@ CONFIG_SERIAL_AMBA_PL011=y CONFIG_SERIAL_AMBA_PL011_CONSOLE=y CONFIG_SERIAL_MXS_AUART=y # CONFIG_HW_RANDOM is not set -# CONFIG_I2C_COMPAT is not set CONFIG_I2C_CHARDEV=y CONFIG_I2C_MXS=y CONFIG_SPI=y CONFIG_SPI_GPIO=m CONFIG_SPI_MXS=y -CONFIG_GPIO_SYSFS=y # CONFIG_HWMON is not set CONFIG_WATCHDOG=y CONFIG_STMP3XXX_RTC_WATCHDOG=y@@ -138,10 +134,6 @@ CONFIG_PWM_MXS=y CONFIG_NVMEM_MXS_OCOTP=y CONFIG_EXT4_FS=y # CONFIG_DNOTIFY is not set -CONFIG_NETFS_SUPPORT=m -CONFIG_FSCACHE=y -CONFIG_FSCACHE_STATS=y -CONFIG_CACHEFILES=m CONFIG_VFAT_FS=y CONFIG_TMPFS=y CONFIG_TMPFS_POSIX_ACL=y
Re: [net-next v4 5/5] ARM: mxs_defconfig: Enable CONFIG_FEC_MTIP_L2SW to support MTIP L2 switch
Hi Stefan,
Quoted 9 lines
Hi Lukasz,
Am 07.04.25 um 16:51 schrieb Lukasz Majewski:
Quoted 4 lines
This patch enables support for More Than IP switch available on some imx28[7] devices.
Signed-off-by Lukasz Majewski <[email protected]>thanks adding the driver to
mxs_defconfig. Unfortunately it's not possible for reviewers to identify the relevant changes,
Could you be more specific here?
As fair as I see - there is only 14 LOCs changed for review.
Please also be aware that MTIP L2 switch driver has some dependencies - on e.g. SWITCHDEV and BRIDGE, which had to be enabled to allow the former one to be active.
Quoted 3 lines
also the
commit messages doesn't provide further information.
What kind of extra information shall I provide? IMHO the patch is self-explaining.
Quoted 6 lines
In general there are two approaches to solves this:
1) prepend an additional patch which synchronizesmxs_defconfigwith current mainline
2) manually create the relevant changes againstmxs_defconfigThe decision about the approaches is up to the maintainer.
I took the linux-next's (or net-next) mxs defconfig (cp it to be .config)
Then run CROSS_COMPILE= ... make ARCH=arm menuconfig Enabled all the relevant Kconfig options and run
CROSS_COMPILE= ... make ARCH=arm savedefconfig
and copy defconfig to mxs_defconfig.
Then I used git to prepare the patch.
Isn't the above procedure correct?
Quoted 67 lines
Btw driver review will follow ...
Regards
Quoted 63 lines
---
Changes for v4:
- New patch--- arch/arm/configs/mxs_defconfig | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)(quoted diff) +0
-0b/arch/arm/configs/mxs_defconfig index
d8a6e43c401e..4dc4306c035f100644 --- a/arch/arm/configs/mxs_defconfig
+++ b/arch/arm/configs/mxs_defconfigarch/arm/configs/mxs_defconfig +3
-7@@ -32,11 +32,10 @@ CONFIG_INET=y CONFIG_IP_PNP=y CONFIG_IP_PNP_DHCP=y CONFIG_SYN_COOKIES=y -# CONFIG_INET_XFRM_MODE_TRANSPORT is not set -# CONFIG_INET_XFRM_MODE_TUNNEL is not set -# CONFIG_INET_XFRM_MODE_BEET is not set # CONFIG_INET_DIAG is not set # CONFIG_IPV6 is not set +CONFIG_BRIDGE=y +CONFIG_NET_SWITCHDEV=y CONFIG_CAN=m # CONFIG_WIRELESS is not set CONFIG_DEVTMPFS=y@@ -45,7 +44,6 @@ CONFIG_MTD=y CONFIG_MTD_CMDLINE_PARTS=y CONFIG_MTD_BLOCK=y CONFIG_MTD_DATAFLASH=y -CONFIG_MTD_M25P80=y CONFIG_MTD_SST25L=y CONFIG_MTD_RAW_NAND=y CONFIG_MTD_NAND_GPMI_NAND=y@@ -56,11 +54,11 @@ CONFIG_EEPROM_AT24=y CONFIG_SCSI=y CONFIG_BLK_DEV_SD=y CONFIG_NETDEVICES=y +CONFIG_FEC_MTIP_L2SW=y CONFIG_ENC28J60=y CONFIG_ICPLUS_PHY=y CONFIG_MICREL_PHY=y CONFIG_REALTEK_PHY=y -CONFIG_SMSC_PHY=y CONFIG_CAN_FLEXCAN=m CONFIG_USB_USBNET=y CONFIG_USB_NET_SMSC95XX=y@@ -77,13 +75,11 @@ CONFIG_SERIAL_AMBA_PL011=y CONFIG_SERIAL_AMBA_PL011_CONSOLE=y CONFIG_SERIAL_MXS_AUART=y # CONFIG_HW_RANDOM is not set -# CONFIG_I2C_COMPAT is not set CONFIG_I2C_CHARDEV=y CONFIG_I2C_MXS=y CONFIG_SPI=y CONFIG_SPI_GPIO=m CONFIG_SPI_MXS=y -CONFIG_GPIO_SYSFS=y # CONFIG_HWMON is not set CONFIG_WATCHDOG=y CONFIG_STMP3XXX_RTC_WATCHDOG=y@@ -138,10 +134,6 @@ CONFIG_PWM_MXS=y CONFIG_NVMEM_MXS_OCOTP=y CONFIG_EXT4_FS=y
Quoted 9 lines
arch/arm/configs/mxs_defconfig CONFIG_PWM_MXS=y · line 139
Quoted 8 lines
arch/arm/configs/mxs_defconfig +0
-4# CONFIG_DNOTIFY is not set -CONFIG_NETFS_SUPPORT=m -CONFIG_FSCACHE=y -CONFIG_FSCACHE_STATS=y -CONFIG_CACHEFILES=m CONFIG_VFAT_FS=y CONFIG_TMPFS=y CONFIG_TMPFS_POSIX_ACL=y
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]
Re: [net-next v4 5/5] ARM: mxs_defconfig: Enable CONFIG_FEC_MTIP_L2SW to support MTIP L2 switch
Quoted 8 lines · Lukasz Majewski
Hi Stefan,
Quoted 6 lines
Hi Lukasz,
Am 07.04.25 um 16:51 schrieb Lukasz Majewski:
Quoted 3 lines
This patch enables support for More Than IP switch available on some imx28[7] devices.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Lukasz Majewski <[email protected]>thanks adding the driver to
mxs_defconfig. Unfortunately it's not possible for reviewers to identify the relevant changes,Could you be more specific here?
As fair as I see - there is only 14 LOCs changed for review.
Really, the comment was very specific. You make multiple independent, looking irrelevant changes to the file.
Quoted 11 lines
Please also be aware that MTIP L2 switch driver has some dependencies - on e.g. SWITCHDEV and BRIDGE, which had to be enabled to allow the former one to be active.
Quoted 3 lines
also the
commit messages doesn't provide further information.What kind of extra information shall I provide? IMHO the patch is self-explaining.
For example explain why do you think GPIO_SYSFS should be dropped.
Quoted 11 lines
Quoted 7 lines
In general there are two approaches to solves this:
1) prepend an additional patch which synchronizesmxs_defconfigwith current mainline
2) manually create the relevant changes againstmxs_defconfigThe decision about the approaches is up to the maintainer.
I took the linux-next's (or net-next) mxs defconfig (cp it to be .config)
Quoted 8 lines
Then run CROSS_COMPILE= ... make ARCH=arm menuconfig Enabled all the relevant
Kconfigoptions and runCROSS_COMPILE= ... make ARCH=arm savedefconfig
and copy defconfig tomxs_defconfig.
Then I used git to prepare the patch.Isn't the above procedure correct?
No, it is not correct. Do not make any changes in the "Enabled all the relevant Kconfig options and run" step and check the result. Do you see difference in result file? If yes, then why such difference should be part of this commit?
Best regards,
Krzysztof
Re: [net-next v4 5/5] ARM: mxs_defconfig: Enable CONFIG_FEC_MTIP_L2SW to support MTIP L2 switch
Hi Krzysztof,
Quoted 51 lines · Lukasz Majewski
Quoted 8 lines
Hi Stefan,
Quoted 6 lines
Hi Lukasz,
Am 07.04.25 um 16:51 schrieb Lukasz Majewski:
Quoted 3 lines
This patch enables support for More Than IP switch available on some imx28[7] devices.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Lukasz Majewski <[email protected]>thanks adding the driver to
mxs_defconfig. Unfortunately it's not possible for reviewers to identify the relevant changes,Could you be more specific here?
As fair as I see - there is only 14 LOCs changed for review.Really, the comment was very specific. You make multiple independent, looking irrelevant changes to the file.
Quoted 11 lines
Please also be aware that MTIP L2 switch driver has some dependencies - on e.g. SWITCHDEV and BRIDGE, which had to be enabled to allow the former one to be active.
Quoted 3 lines
also the
commit messages doesn't provide further information.What kind of extra information shall I provide? IMHO the patch is self-explaining.
For example explain why do you think
GPIO_SYSFSshould be dropped.Quoted 18 lines
Quoted 7 lines
In general there are two approaches to solves this:
1) prepend an additional patch which synchronizesmxs_defconfigwith current mainline
2) manually create the relevant changes againstmxs_defconfigThe decision about the approaches is up to the maintainer.
I took the linux-next's (or net-next) mxs defconfig (cp it to be .config)
Then run CROSS_COMPILE= ... make ARCH=arm menuconfig Enabled all the relevant
Kconfigoptions and runCROSS_COMPILE= ... make ARCH=arm savedefconfig
and copy defconfig tomxs_defconfig.
Then I used git to prepare the patch.
Quoted 6 lines
Quoted 1 line
Isn't the above procedure correct?
No, it is not correct. Do not make any changes in the "Enabled all the relevant
Kconfigoptions and run" step and check the result. Do you see difference in result file? If yes, then why such difference should be part of this commit?
Ok, I get your point. Then I shall prepare a separate, pre-patch. Thanks for info.
Quoted 3 lines
Best regards,
Krzysztof
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]
Re: [net-next v4 5/5] ARM: mxs_defconfig: Enable CONFIG_FEC_MTIP_L2SW to support MTIP L2 switch
In reply to Lukasz MajewskiAm 10.04.25 um 09:01 schrieb Lukasz Majewski:
Quoted 5 lines
Hi Stefan,
Quoted 3 lines
Hi Lukasz,
Am 07.04.25 um 16:51 schrieb Lukasz Majewski:
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
This patch enables support for More Than IP switch available on some imx28[7] devices.
Signed-off-by Lukasz Majewski <[email protected]>thanks adding the driver to
mxs_defconfig. Unfortunately it's not possible for reviewers to identify the relevant changes,Could you be more specific here?
As fair as I see - there is only 14 LOCs changed for review.
Yes, this is exactly the problem. The subject suggests enable one driver, but the changes are not self-explaining.
Quoted 3 lines
Please also be aware that MTIP L2 switch driver has some dependencies - on e.g. SWITCHDEV and BRIDGE, which had to be enabled to allow the former one to be active.
This should be part of the commit message.
Quoted 6 lines
Quoted 4 lines
also the
commit messages doesn't provide further information.What kind of extra information shall I provide? IMHO the patch is self-explaining.
No, it is not. How should a reviewer know that
CONFIG_MTD_M25P80=y
should be dropped? This is completely unrelated to the change.
Quoted 10 lines
Quoted 7 lines
In general there are two approaches to solves this:
1) prepend an additional patch which synchronizesmxs_defconfigwith current mainline
2) manually create the relevant changes againstmxs_defconfigThe decision about the approaches is up to the maintainer.
I took the linux-next's (or net-next) mxs defconfig (cp it to be .config)
Quoted 8 lines
Then run CROSS_COMPILE= ... make ARCH=arm menuconfig Enabled all the relevant
Kconfigoptions and runCROSS_COMPILE= ... make ARCH=arm savedefconfig
and copy defconfig tomxs_defconfig.
Then I used git to prepare the patch.Isn't the above procedure correct?
The problem here is that you send a patch for two steps. First is to synchronize mxs_defconfig against current tree and the second is to enable the driver.
Regards
Quoted 88 lines
Quoted 68 lines
Btw driver review will follow ...
Regards
Quoted 63 lines
---
Changes for v4:
- New patch--- arch/arm/configs/mxs_defconfig | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)(quoted diff) +0
-0b/arch/arm/configs/mxs_defconfig index
d8a6e43c401e..4dc4306c035f100644 --- a/arch/arm/configs/mxs_defconfig
+++ b/arch/arm/configs/mxs_defconfigarch/arm/configs/mxs_defconfig +3
-7@@ -32,11 +32,10 @@ CONFIG_INET=y CONFIG_IP_PNP=y CONFIG_IP_PNP_DHCP=y CONFIG_SYN_COOKIES=y -# CONFIG_INET_XFRM_MODE_TRANSPORT is not set -# CONFIG_INET_XFRM_MODE_TUNNEL is not set -# CONFIG_INET_XFRM_MODE_BEET is not set # CONFIG_INET_DIAG is not set # CONFIG_IPV6 is not set +CONFIG_BRIDGE=y +CONFIG_NET_SWITCHDEV=y CONFIG_CAN=m # CONFIG_WIRELESS is not set CONFIG_DEVTMPFS=y@@ -45,7 +44,6 @@ CONFIG_MTD=y CONFIG_MTD_CMDLINE_PARTS=y CONFIG_MTD_BLOCK=y CONFIG_MTD_DATAFLASH=y -CONFIG_MTD_M25P80=y CONFIG_MTD_SST25L=y CONFIG_MTD_RAW_NAND=y CONFIG_MTD_NAND_GPMI_NAND=y@@ -56,11 +54,11 @@ CONFIG_EEPROM_AT24=y CONFIG_SCSI=y CONFIG_BLK_DEV_SD=y CONFIG_NETDEVICES=y +CONFIG_FEC_MTIP_L2SW=y CONFIG_ENC28J60=y CONFIG_ICPLUS_PHY=y CONFIG_MICREL_PHY=y CONFIG_REALTEK_PHY=y -CONFIG_SMSC_PHY=y CONFIG_CAN_FLEXCAN=m CONFIG_USB_USBNET=y CONFIG_USB_NET_SMSC95XX=y@@ -77,13 +75,11 @@ CONFIG_SERIAL_AMBA_PL011=y CONFIG_SERIAL_AMBA_PL011_CONSOLE=y CONFIG_SERIAL_MXS_AUART=y # CONFIG_HW_RANDOM is not set -# CONFIG_I2C_COMPAT is not set CONFIG_I2C_CHARDEV=y CONFIG_I2C_MXS=y CONFIG_SPI=y CONFIG_SPI_GPIO=m CONFIG_SPI_MXS=y -CONFIG_GPIO_SYSFS=y # CONFIG_HWMON is not set CONFIG_WATCHDOG=y CONFIG_STMP3XXX_RTC_WATCHDOG=y@@ -138,10 +134,6 @@ CONFIG_PWM_MXS=y CONFIG_NVMEM_MXS_OCOTP=y CONFIG_EXT4_FS=yQuoted 8 lines
arch/arm/configs/mxs_defconfig CONFIG_PWM_MXS=y · line 139
Quoted 8 lines
arch/arm/configs/mxs_defconfig +0
-4# CONFIG_DNOTIFY is not set -CONFIG_NETFS_SUPPORT=m -CONFIG_FSCACHE=y -CONFIG_FSCACHE_STATS=y -CONFIG_CACHEFILES=m CONFIG_VFAT_FS=y CONFIG_TMPFS=y CONFIG_TMPFS_POSIX_ACL=yBest 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]