net: mtip: Add support for MTIP imx287 L2 switch driver
Subsystems (5)
v15 cover net: mtip: Add support for MTIP imx287 L2 switch driver
From: Lukasz Majewski <[email protected]>
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.
5. Clang build:
make LLVM_SUFFIX=-19 LLVM=1 mrproper
cp ./arch/arm/configs/mxs_defconfig .config
make ARCH=arm LLVM_SUFFIX=-19 LLVM=1 W=1 menuconfig
make ARCH=arm LLVM_SUFFIX=-19 LLVM=1 W=1 -j8 LOADADDR=0x40008000 uImage dtbs
make LLVM_SUFFIX=-19 LLVM=1 mrproper
make LLVM_SUFFIX=-19 LLVM=1 allmodconfig
make LLVM_SUFFIX=-19 LLVM=1 W=1 drivers/net/ethernet/freescale/mtipsw/ | tee llvm_build.log make LLVM_SUFFIX=-19 LLVM=1 W=1 -j8 | tee llvm_build.log
6. Kernel compliance checks:
make coccicheck MODE=report J=4 M=drivers/net/ethernet/freescale/mtipsw/ ~/work/src/smatch/smatch_scripts/kchecker drivers/net/ethernet/freescale/mtipsw/
7. GCC
make mrproper
make allmodconfig
make W=1 drivers/net/ethernet/freescale/mtipsw/
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 (12):
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
net: mtip: Add buffers management functions to the L2 switch driver
net: mtip: Add net_device_ops functions to the L2 switch driver
net: mtip: Add mtip_switch_{rx|tx} functions to the L2 switch driver
net: mtip: Extend the L2 switch driver with management operations
net: mtip: Extend the L2 switch driver for imx287 with bridge
operations
ARM: mxs_defconfig: Enable CONFIG_NFS_FSCACHE
ARM: mxs_defconfig: Update mxs_defconfig to 6.16-rc5
ARM: mxs_defconfig: Enable CONFIG_FEC_MTIP_L2SW to support MTIP L2
switch
.../bindings/net/nxp,imx28-mtip-switch.yaml | 150 ++ MAINTAINERS | 7 + arch/arm/boot/dts/nxp/mxs/imx28-xea.dts | 56 + arch/arm/boot/dts/nxp/mxs/imx28.dtsi | 9 +- arch/arm/configs/mxs_defconfig | 13 +- drivers/net/ethernet/freescale/Kconfig | 1 + drivers/net/ethernet/freescale/Makefile | 1 + drivers/net/ethernet/freescale/mtipsw/Kconfig | 13 + .../net/ethernet/freescale/mtipsw/Makefile | 4 + .../net/ethernet/freescale/mtipsw/mtipl2sw.c | 1953 +++++++++++++++++ .../net/ethernet/freescale/mtipsw/mtipl2sw.h | 652 ++++++ .../ethernet/freescale/mtipsw/mtipl2sw_br.c | 120 + .../ethernet/freescale/mtipsw/mtipl2sw_mgnt.c | 443 ++++ 13 files changed, 3411 insertions(+), 11 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 v15 1/12 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
Changes for v5:
- Provide proper description for 'ethernet-port' node
Changes for v6:
- Proper usage of
$ref: ethernet-switch.yaml#/$defs/ethernet-ports/patternProperties when specifying the 'ethernet-ports' property
- Add description and check for interrupt-names property
Changes for v7:
- Change switch interrupt name from 'mtipl2sw' to 'enet_switch'
Changes for v8:
- None
Changes for v9:
- Add GPIO_ACTIVE_LOW to reset-gpios mdio phandle
Changes for v10:
- None
Changes for v11:
- None
Changes for v12:
- Remove 'label' from required properties
- Move the reference to $ref: ethernet-switch.yaml#/$defs/ethernet-ports the proper place (under 'allOf:')
Changes for v13:
- None
Changes for v14:
- None
Changes for v15:
- None
--- .../bindings/net/nxp,imx28-mtip-switch.yaml | 150 ++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml
Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml new file +150 -0
@@ -0,0 +1,150 @@ +# 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. + +allOf: + - $ref: ethernet-switch.yaml#/$defs/ethernet-ports + +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 + + interrupt-names: + items: + - const: enet_switch + - const: enet0 + - const: enet1 + + pinctrl-names: true + + ethernet-ports: + type: object + additionalProperties: true + + patternProperties: + '^ethernet-port@[12]$': + type: object + additionalProperties: true + properties: + reg: + items: + - enum: [1, 2] + description: MTIP L2 switch port number + + required: + - reg + - phy-mode + - phy-handle + + mdio: + type: object + $ref: mdio.yaml# + unevaluatedProperties: false + description: + Specifies the mdio bus in the switch, used as a container for phy nodes. + +required: + - compatible + - reg + - clocks + - clock-names + - interrupts + - interrupt-names + - mdio + - ethernet-ports + +unevaluatedProperties: false + +examples: + - | + #include<dt-bindings/interrupt-controller/irq.h> + #include<dt-bindings/gpio/gpio.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>; + interrupt-names = "enet_switch", "enet0", "enet1"; + 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 GPIO_ACTIVE_LOW>; + 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
PATCH v15 2/12 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)
Changes for v5:
- None
Changes for v6:
- Add interrupt-names property
Changes for v7:
- Change switch interrupt name from 'mtipl2sw' to 'enet_switch'
Changes for v8:
- None
Changes for v9:
- None
Changes for v10:
- None
Changes for v11:
- None
Changes for v12:
- None
Changes for v13:
- None
Changes for v14:
- None
Changes for v15:
- None
--- arch/arm/boot/dts/nxp/mxs/imx28.dtsi | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
arch/arm/boot/dts/nxp/mxs/imx28.dtsi +7 -2
@@ -1321,8 +1321,13 @@ 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>; + interrupt-names = "enet_switch", "enet0", "enet1"; + 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 v15 3/12 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]
Changes for v5:
- Add proper multiline comment for IRQs description
Changes for v6:
- None
Changes for v7:
- None
Changes for v8:
- None
Changes for v9:
- None
Changes for v10:
- None
Changes for v11:
- None
Changes for v12:
- None
Changes for v13:
- None
Changes for v14:
- None
Changes for v15:
- None
--- arch/arm/boot/dts/nxp/mxs/imx28-xea.dts | 56 +++++++++++++++++++++++++ 1 file changed, 56 insertions(+)
arch/arm/boot/dts/nxp/mxs/imx28-xea.dts +56 -0
@@ -5,6 +5,7 @@ */ /dts-v1/; +#include<dt-bindings/interrupt-controller/irq.h> #include "imx28-lwe.dtsi" / {
@@ -90,6 +91,61 @@ ®_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
PATCH v15 4/12 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()
Changes for v5:
- Fix spelling in Kconfig
- Replace tmp with reg or register name
- Replace tmpaddr with mac_addr
- Use mac address assignment (from registers) code similar to fec_main.c (as it shall handle properly generic endianess)
- Add description for fep: in the mtip_update_atable_static() kernel doc
- Replace writel(bdp, &fep->cur_rx) with fep->cur_rx = bdp;
- Fix spelling of transmit
- Remove not needed white spaces in mtipl2sw.h
- Remove '_t' from struct mtip_addr_table_t
- Provide proper alignment in the mtipl2sw.h
- Add blank line after local header in mtipl2sw_br.c
- Use %p instead of %x (and cast) for fep in debug message
- Disable L2 switch in-HW offloading when only one
of eligible ports is removed from the bridge
- Sort includes in the patch set alphabethically
- Introduce FEC_QUIRK_SWAP_FRAME to avoid #ifdef for imx28 proper operation
- Move 'mtip_port_info g_info' to struct switch_enet_private
- Replace some unsigned int with u32 (on data fields with 32 bit size)
- Remove not relevant comments from mtip_enet_init()
- Refactor functions definitions to be void when no other
value than 0 is returned.
- Use capital letters in HEX constants
- Use u32 instead of unsigned int when applicable
- Add error handling code after the dma_map_single() is called
- The MCF_FEC_MSCR register can be written unconditionally
for all supported platforms.
- Use IS_ENABLED() instead of #ifdef in mtip_timeout()
- Replace dev_info() with dev_warn_ratelimited() in mtip_switch_rx()
- Add code to handle situation when there is no memory
- Remove kfree(fep->mii_bus->irq)
- Provide more verbose output of mdio_{read|write} functions
- Handle error when clk_enable() fails in mtip_open()
- Use dev_dbg() at mtip_set_multicast_list()
- Simplify the mtip_is_switch_netdev_port() function to return condition check value
- Add dev_dbg() when of_get_mac_address() fails (as it may not be provided)
- Remove return ret; in mtip_register_notifiers()
- Replace int to bool in mtipl2sw_mgnt.c file's function definitions
- Replace unsigned int/long with u32 where applicable (where access to 32 bit registers is performed)
- Refactor code in mtip_{read|write}_atable() to be more readable
- Remove code added for not (yet) supported IMX's vf610 SoC
- Remove do { } while(); loop from mtip_interrupt() function
- Introduce MTIP_PORT_FORWARDING_INIT to indicate intial value for port forwarding
- Replace 'unsigned long' to 'u32' in mtipl2sw.h
- Replace 'unsigned short' to 'u16' in mtipl2sw.h
- use %#x in dev_dbg()
- Call SET_NETDEV_DEV() macro to set network device' parent - otherwise phy_attach_direct() will fail.
Changes for v6:
- Use dev_name(&pdev->dev) when requesting IRQ (to be in sync with other subsystems)
- Use platform_get_irq_byname() for beter readability
- Replace ARCH_MXS with SOC_IMX28
- Replace 2048 with MTIP_ATABLE_MEM_NUM_ENTRIES
- Remove check if fep == NULL in mtip_aging_timer() as timer can be setup only after the fep structure is allocated and already filled durring probe() execution
Changes for v7:
- Change switch interrupt name from 'mtipl2sw' to 'enet_switch'
Changes for v8:
- Replace struct switch_t with set of #define(s) for MTIP L2 switch IP block registers offsets. This helps to keep the '__iomem' annotation when accessing them with readl/writel() and fix warnings from sparse on GCC and CLANG. No functional changes, just registers' access coding paradigm has been updated.
- Fix warings regarding access to atable - by adding '__iomem' attribute
- Remove not used struct mtip_port_statistics_status
Changes for v9:
- Adjust Makefile to properly build mtipl2sw driver as a module (otherwise make allmodconfig build fails).
Changes for v10:
- Remove __init attribute from mtip_switch_dma_init() to avoid clang modpost Warninig
Reproduction steps:
make LLVM_SUFFIX=-19 LLVM=1 mrproper
cp ./arch/arm/configs/mxs_defconfig .config
make ARCH=arm LLVM_SUFFIX=-19 LLVM=1 W=1 menuconfig
make ARCH=arm LLVM_SUFFIX=-19 LLVM=1 W=1 -j8 LOADADDR=0x40008000 uImage dtbs
Changes for v11:
- Replace of_find_node_by_name() with of_get_child_by_name()
- Replace of_match_node() with dedicated of_device_get_match_data()
- Replace devm_err() with dev_err_probe() in the probe function
- Remove kfree(fep) from mtip_sw_remove() to fix:
./mtipl2sw.c:1953:1-6: WARNING: invalid free of devm_ allocated data
- the *bus pointer provided as an agument to mtip_mdiobus_reset() cannot be NULL itself, as then the "reset" callback couldn't be referenced. Considering the above - the "!bus" check can be removed.
It fixes the following error from coccinelle
./mtipl2sw.c:1237:16-19: ERROR: bus is NULL but dereferenced.
- Fix smatch errors:
mtip_atable_dynamicms_learn_migration() error: uninitialized symbol 'rx_mac_lo/hi'. by initializing rx_mac_lo and rx_mac_hi variables
Replace fep->irq with ret in dev_err_probe()
Changes for v12:
- Clear fep->rx_skbuff[i] when buffers are freed
Changes for v13:
- Replace spin_lock_irqsave() with spin_lock_bh() when eligible (NAPI or softirq context)
- Increment dev->stats.tx_bytes after data is really send
- Add wmb() before descriptor is used for transmission (either RX or TX)
- Add work queue to handle bottom half of network interface timeout
- Move the network statistics update (only when packet is correctly received) just before finishing processing of data.
- Remove dev_kfree_skb_any(skb); and finally rely on mtip_free_buffers()
- Use mtip_set_last_buf_to_wrap() helper function
- Cleanup defines for internal routing table entries
- Use GENMASK() when applicable
- Replace extra pair of dma_map_single()/dma_unmap_single() in RX function with dma_sync_single_for_cpu() as there is already allocated buffer (its pointer is stored in bdp->cbd_bufaddr)
- Use proper network devices when offloading is enabled
- Use FIELD_PREP() and FIELD_GET() macros
- Replace preprocessor macros with FIELD_PREP()
- Remove not used defines
- Replace AT_EXTRACT* macros with FIELD_PREP()
- Introduce mtip_timedelta() static inline function instead of macro
- Add missing error check in mtip_alloc_buffers()
- Use page pool to allocate and sync space for incoming data (instead
of using page map and unmap.
- Replace from_timer() with timer_container_of()
- Move mtipl2sw_br.c related code to a separate commit
- Move mtipl2sw_mgnt.c related code to a separate commit
- Exclude struct net_device_ops callback function to a separate commit
Changes for v14:
- Increase the maximal received frame size to 1536 (for VLAN)
- Use spin_{un}lock_irq{save|restore} when altering dynamic table of the switch and mtip_adjust_link() as both cannot be done when switch IRQ is potentially enabled (the previous one alters entries in switching table the latter one may reset the whole IP block)
- Remove separate kthread for learning
- Use jiffies to calculate time stamps for the entries in dynamic switching table
- Remove not needed mtip_mii_unregister()
- Rename timer to reflect its function
Changes for v15:
- Remove mii_lock, as it is not used in the series
- Remove extra space
- Use proper error check for devm_regulator_get_enable_optional()
- Use spin_{un}lock() instead of spin_{un}clock_irq{restore|save}() Context of altering switching table doesn't require IRQs disabled.
- Set larger number of descriptors to allow higher throughtput
--- 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 | 4 + .../net/ethernet/freescale/mtipsw/mtipl2sw.c | 1318 +++++++++++++++++ .../net/ethernet/freescale/mtipsw/mtipl2sw.h | 627 ++++++++ 7 files changed, 1971 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
MAINTAINERS +7 -0
@@ -9645,6 +9645,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 SOC_IMX28 || COMPILE_TEST + help + This enables support for the MoreThan IP L2 switch on i.MX + SoCs (e.g. iMX287). 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 requirements.
drivers/net/ethernet/freescale/mtipsw/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_FEC_MTIP_L2SW) += nxp-mtipl2sw.o +nxp-mtipl2sw-objs := mtipl2sw.o
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +1318 -0
1,318 lines not on this page · raw message
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h new file +627 -0
627 lines not on this page · raw message
Signature · 1 line
2.39.5
Jakub Kicinski
maintainerRe: [net-next v15 04/12] net: mtip: The L2 switch driver for imx287
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1064
Quoted 7 lines · On Wed, 16 Jul 2025 23:47:23 +0200 Lukasz Majewski wrote:
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +7
-0+static void mtip_ndev_cleanup (struct switch_enet_private *fep) +{ +struct mtip_ndev_priv *priv; +int i; + +for (i =0 ; i <SWITCH_EPORT_NUMBER ; i++) { +if (fep->ndev[i]) {
this just checks if netdev is NULL
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1068
Quoted 4 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +4
-0+ priv =netdev_priv (fep->ndev[i]); +cancel_work_sync (&priv->tx_timeout_work); + +unregister_netdev (fep->ndev[i]);
and if not unregisters
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1081
Quoted 13 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +13
-0+free_netdev (fep->ndev[i]); + } + } +} + +static int mtip_ndev_init (struct switch_enet_private *fep, +struct platform_device *pdev) +{ +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),
but we assign the pointer immediatelly
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+ 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; +SET_NETDEV_DEV (fep->ndev[i], &pdev->dev);
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1101
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+ + priv =netdev_priv (fep->ndev[i]); + priv->dev = fep->ndev[i]; + priv->fep = fep; + priv->portnum = i +1 ; + fep->ndev[i]->irq = fep->irq; + +mtip_setup_mac (fep->ndev[i]); + + ret =register_netdev (fep->ndev[i]);
and don't clear it when register fails
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1114
Quoted 13 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +13
-0+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);
You're probably better off handling the unwind on error separately from the full cleanup function, but I guess that's subjective.
Quoted 6 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +4
-0+return ret; +} +static int mtip_sw_probe (struct platform_device *pdev) +{
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1271
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +9
-0+ ret =mtip_ndev_init (fep, pdev); +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); + ret =mtip_mii_init (fep, pdev);
Seems like we're registering the netdevs before fully initializing the HW? Is it safe if user (or worse, some other kernel subsystem) tries to open the netdevs before the driver finished the init?
Quoted 5 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +5
-0+if (ret) { +dev_err (&pdev->dev,"%s: Cannot init phy bus (%d)!\n" , __func__, + ret); + goto mii_init_err; + }
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1286
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+/* setup timer for learning aging function */ +timer_setup (&fep->timer_mgnt, mtip_mgnt_timer,0 ); +mod_timer (&fep->timer_mgnt, + jiffies +msecs_to_jiffies (LEARNING_AGING_INTERVAL )); + +return 0 ; + + mii_init_err: + dma_init_err: +mtip_ndev_cleanup (fep);
Please name the labels after the action they jump to, not the location where they jump from.
Quoted 3 lines
+
ndev_init_err:(quoted diff) +2
-0+ + return ret;
Signature · 1 line
pw-bot: cr
Re: [net-next v15 04/12] net: mtip: The L2 switch driver for imx287
Hi Jakub,
Quoted 70 lines · On Wed, 16 Jul 2025 23:47:23 +0200 Lukasz Majewski wrote:
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1064
Quoted 7 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +7
-0+static void mtip_ndev_cleanup (struct switch_enet_private *fep) +{ +struct mtip_ndev_priv *priv; +int i; + +for (i =0 ; i <SWITCH_EPORT_NUMBER ; i++) { +if (fep->ndev[i]) {this just checks if netdev is NULL
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1068
Quoted 4 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +4
-0+ priv =netdev_priv (fep->ndev[i]); +cancel_work_sync (&priv->tx_timeout_work); + +unregister_netdev (fep->ndev[i]);and if not unregisters
Quoted 13 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +13
-0+free_netdev (fep->ndev[i]); + } + } +} + +static int mtip_ndev_init (struct switch_enet_private *fep, +struct platform_device *pdev) +{ +struct mtip_ndev_priv *priv; +int i, ret =0 ; + +for (i =0 ; i <SWITCH_EPORT_NUMBER ; i++) { + fep->ndev[i] = alloc_netdev(sizeof(structQuoted 1 line
mtip_ndev_priv),but we assign the pointer immediatelly
Quoted 11 lines
(quoted diff) +1
-0+ fep->ndev_name[i],
NET_NAME_USER,drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +9
-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; +SET_NETDEV_DEV (fep->ndev[i], &pdev->dev);drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1101
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +10
-0+ + priv =netdev_priv (fep->ndev[i]); + priv->dev = fep->ndev[i]; + priv->fep = fep; + priv->portnum = i +1 ; + fep->ndev[i]->irq = fep->irq; + +mtip_setup_mac (fep->ndev[i]); + + ret =register_netdev (fep->ndev[i]);and don't clear it when register fails
Quoted 11 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +3
-0+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 +5
-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,
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1114
Quoted 5 lines
fep->ndev[i]->dev_addr);
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +4
-0+ } + +if (ret) +mtip_ndev_cleanup (fep);You're probably better off handling the unwind on error separately from the full cleanup function, but I guess that's subjective.
Yes, you are right - I shall add:
fep->ndev[i] = NULL;
just after free_ndev(fep->ndev[i]); in themtip_ndev_cleanup() function.
Quoted 17 lines
Quoted 16 lines
(quoted diff) +7
-0+ return ret; +} +static int mtip_sw_probe(struct platform_device *pdev) +{ + ret = mtip_ndev_init(fep, pdev); + if (ret) { + dev_err(&pdev->dev, "%s: Failed to create virtualndev (%d)\n",
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +5
-0+ __func__, ret); + goto ndev_init_err; + } + + ret =mtip_switch_dma_init (fep);
Quoted 6 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1271
Quoted 1 line
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +1
-0+ ret =mtip_mii_init (fep, pdev);Seems like we're registering the netdevs before fully initializing the HW? Is it safe if user (or worse, some other kernel subsystem) tries to open the netdevs before the driver finished the init?
This needs to be reordered - the ndev registration shall be the last step.
Thanks for pointing this out.
Quoted 12 lines
Quoted 12 lines
(quoted diff) +2
-0+ 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_mgnt, mtip_mgnt_timer,0 ); + mod_timer(&fep->timer_mgnt, + jiffies +
msecs_to_jiffies(LEARNING_AGING_INTERVAL)); +
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c line 1286
Quoted 5 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c new file +5
-0+return 0 ; + + mii_init_err: + dma_init_err: +mtip_ndev_cleanup (fep);Please name the labels after the action they jump to, not the location where they jump from.
Ok.
Quoted 4 lines
Review
Quoted 4 lines
+
ndev_init_err:(quoted diff) +2
-0+ + return ret;
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Johanna Denk, Tabea Lutz HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: [email protected]
PATCH v15 5/12 net: mtip: Add buffers management functions to the L2 switch driver
In reply to Lukasz MajewskiThis patch provides buffers management funcions' content for MTIP L2 switch.
---
Changes for v14:
- New patch - created by excluding some code from large (i.e. v13 and earlier) MTIP driver
Changes for v15:
- None
--- .../net/ethernet/freescale/mtipsw/mtipl2sw.c | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+)
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +85 -0
@@ -881,11 +881,96 @@ static void mtip_get_drvinfo(struct net_device *dev,static void mtip_free_buffers (struct net_device *dev) { +struct mtip_ndev_priv *priv =netdev_priv (dev); +struct switch_enet_private *fep = priv->fep; +int i; + +for (i =0 ; i <RX_RING_SIZE ; i++) { +page_pool_put_full_page (fep->page_pool, + fep->page[i], false); + fep->page[i] =NULL ; + } + +page_pool_destroy (fep->page_pool); + fep->page_pool =NULL ; + +for (i =0 ; i <TX_RING_SIZE ; i++) +kfree (fep->tx_bounce[i]); +} + +static int mtip_create_page_pool (struct switch_enet_private *fep,int size) +{ +struct page_pool_params pp_params = { + .order =0 , + .flags =PP_FLAG_DMA_MAP |PP_FLAG_DMA_SYNC_DEV , + .pool_size = size, + .nid =dev_to_node (&fep->pdev->dev), + .dev = &fep->pdev->dev, + .dma_dir =DMA_FROM_DEVICE , + .offset =0 , + .max_len =MTIP_SWITCH_RX_FRSIZE , + }; +int ret =0 ; + + fep->page_pool =page_pool_create (&pp_params); +if (IS_ERR (fep->page_pool)) { + ret =PTR_ERR (fep->page_pool); + fep->page_pool =NULL ; + } + +return ret; }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 cbd_t *bdp; +struct page *page; +int i, ret; + + ret =mtip_create_page_pool (fep,RX_RING_SIZE ); +if (ret <0 ) { +dev_err (&fep->pdev->dev,"Failed to create page pool\n" ); +return ret; + } + + bdp = fep->rx_bd_base; +for (i =0 ; i <RX_RING_SIZE ; i++) { + page =page_pool_dev_alloc_pages (fep->page_pool); +if (!page) { +dev_err (&fep->pdev->dev, +"Failed to allocate page for rx buffer\n" ); + goto err; + } + + bdp->cbd_bufaddr =page_pool_get_dma_addr (page); + fep->page[i] = page; + + bdp->cbd_sc =BD_ENET_RX_EMPTY ; + bdp++; + } + +mtip_set_last_buf_to_wrap (bdp); + + bdp = fep->tx_bd_base; +for (i =0 ; i <TX_RING_SIZE ; i++) { + fep->tx_bounce[i] =kmalloc (MTIP_SWITCH_TX_FRSIZE ,GFP_KERNEL ); +if (!fep->tx_bounce[i]) + goto err; + + bdp->cbd_sc =0 ; + bdp->cbd_bufaddr =0 ; + bdp++; + } + +mtip_set_last_buf_to_wrap (bdp); +return 0 ; + + err: +mtip_free_buffers (dev); +return -ENOMEM ; }static int mtip_rx_napi (struct napi_struct *napi,int budget)
Signature · 1 line
2.39.5
PATCH v15 6/12 net: mtip: Add net_device_ops functions to the L2 switch driver
In reply to Lukasz MajewskiThis patch provides callbacks for struct net_device_ops for MTIP L2 switch.
---
Changes for v13:
- New patch - created by excluding some code from large (i.e. v12 and earlier) MTIP driver
Changes for v14:
- Add read memory barier (rmb) before reading current descriptor
- Use proper locking primitives
Changes for v15:
- None
--- .../net/ethernet/freescale/mtipsw/mtipl2sw.c | 277 ++++++++++++++++++ 1 file changed, 277 insertions(+)
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +277 -0
@@ -43,6 +43,15 @@#include "mtipl2sw.h" +static void swap_buffer (void *bufaddr,int len) +{ +int i; +unsigned int *buf = bufaddr; + +for (i =0 ; i < len; i +=4 , buf++) +swab32s (buf); +} +/* Set the last buffer to wrap */ static void mtip_set_last_buf_to_wrap (struct cbd_t *bdp) {
@@ -444,6 +453,130 @@ static void mtip_config_switch(struct switch_enet_private *fep) fep->hwp + ESW_IMR); } +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; +unsigned short status; +struct cbd_t *bdp; +void *bufaddr; + +spin_lock (&fep->hw_lock); + +if (!fep->link[0 ] && !fep->link[1 ]) { +/* Link is down or autonegotiation is in progress. */ +netif_stop_queue (dev); +spin_unlock (&fep->hw_lock); +return NETDEV_TX_BUSY ; + } + +/* Fill in a Tx ring entry */ + bdp = fep->cur_tx; + +/* Force read memory barier on the current transmit description */ +rmb (); + 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. +*/ +netif_stop_queue (dev); +dev_err (&fep->pdev->dev,"%s: tx queue full!.\n" , dev->name); +spin_unlock (&fep->hw_lock); +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.spin +*/ +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]; + } + +if (fep->quirks &FEC_QUIRK_SWAP_FRAME ) +swap_buffer (bufaddr, skb->len); + +/* Save skb pointer. */ + fep->tx_skbuff[fep->skb_cur] = skb; + + 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 ); +if (unlikely (dma_mapping_error (&fep->pdev->dev, bdp->cbd_bufaddr))) { +dev_err (&fep->pdev->dev, +"Failed to map descriptor tx buffer\n" ); + dev->stats.tx_errors++; + dev->stats.tx_dropped++; +dev_kfree_skb_any (skb); + goto err; + } + +/* 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 ); + +/* Synchronize all descriptor writes */ +wmb (); + bdp->cbd_sc = status; + +netif_trans_update (dev); +skb_tx_timestamp (skb); + +/* Trigger transmission start */ +writel (MCF_ESW_TDAR_X_DES_ACTIVE , fep->hwp +ESW_TDAR ); + + dev->stats.tx_bytes += skb->len; +/* 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; + err: +spin_unlock (&fep->hw_lock); + +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 ];
@@ -601,6 +734,70 @@ static void mtip_switch_restart(struct net_device *dev, int duplex0,mtip_config_switch (fep); } +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; +struct cbd_t *bdp; +int i; + + dev->stats.tx_errors++; + +if (IS_ENABLED (CONFIG_SWITCH_DEBUG )) { +spin_lock (&fep->hw_lock); +dev_info (&dev->dev,"%s: transmit timed out.\n" , dev->name); +dev_info (&dev->dev, +"Ring data: 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," %08lx: %04x %04x %08x\n" , + (kernel_ulong_t )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," %08lx: %04x %04x %08x\n" , + (kernel_ulong_t )bdp, + bdp->cbd_sc, bdp->cbd_datlen, + (int )bdp->cbd_bufaddr); + bdp++; + } +spin_unlock (&fep->hw_lock); + } + +schedule_work (&priv->tx_timeout_work); +} + +static void mtip_timeout_work (struct work_struct *work) +{ +struct mtip_ndev_priv *priv = + container_of(work, struct mtip_ndev_priv, tx_timeout_work); +struct switch_enet_private *fep = priv->fep; +struct net_device *dev = priv->dev; + +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;
@@ -1079,6 +1276,80 @@ static int mtip_close(struct net_device *dev)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 ) + enet_addr +=MCF_ESW_ENET_PORT_OFFSET ; + +if (dev->flags &IFF_PROMISC ) { +/* Promisc mode is required for switch - it is +* already enabled during driver's probe. +*/ +dev_dbg (&dev->dev,"%s: IFF_PROMISC\n" , __func__); +return ; + } + +if (dev->flags &IFF_ALLMULTI ) { +dev_dbg (&dev->dev,"%s: IFF_ALLMULTI\n" , __func__); + +/* 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,
@@ -1090,6 +1361,10 @@ static const struct ethtool_ops mtip_ethtool_ops = {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, + .ndo_tx_timeout = mtip_timeout, + .ndo_set_mac_address = mtip_set_mac_address, };bool mtip_is_switch_netdev_port (const struct net_device *ndev)
@@ -1191,6 +1466,8 @@ static int mtip_ndev_init(struct switch_enet_private *fep,break ; } +INIT_WORK (&priv->tx_timeout_work, mtip_timeout_work); +dev_dbg (&fep->ndev[i]->dev,"%s: MTIP eth L2 switch %pM\n" , fep->ndev[i]->name, fep->ndev[i]->dev_addr); }
Signature · 1 line
2.39.5
Jakub Kicinski
maintainerRe: [net-next v15 06/12] net: mtip: Add net_device_ops functions to the L2 switch driver
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c static void mtip_config_switch(struct switch_enet_private *fep) · line 465
Quoted 10 lines · On Wed, 16 Jul 2025 23:47:25 +0200 Lukasz Majewski wrote:
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +10
-0+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; +unsigned short status; +struct cbd_t *bdp; +void *bufaddr; + +spin_lock (&fep->hw_lock);
I see some inconsistencies in how you take this lock.
Bunch of bare spin_lock() calls from BH context, but there's also a _irqsave() call in mtip_adjust_link(). Please align to the strictest context (not sure if the irqsave is actually needed, at a glance, IOW whether the lock is taken from an IRQ)
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c static void mtip_config_switch(struct switch_enet_private *fep) · line 477
Quoted 11 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +11
-0+if (!fep->link[0 ] && !fep->link[1 ]) { +/* Link is down or autonegotiation is in progress. */ +netif_stop_queue (dev); +spin_unlock (&fep->hw_lock); +return NETDEV_TX_BUSY ; + } + +/* Fill in a Tx ring entry */ + bdp = fep->cur_tx; + +/* Force read memory barier on the current transmit description */
Barrier are between things. What is this barrier separating, and what write barrier does it pair with? As far as I can tell cur_tx is just a value in memory, and accesses are under ->hw_lock, so there should be no ordering concerns.
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c static void mtip_config_switch(struct switch_enet_private *fep) · line 486
Quoted 9 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +9
-0+rmb (); + 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. +*/ +netif_stop_queue (dev); +dev_err (&fep->pdev->dev,"%s: tx queue full!.\n" , dev->name);
This needs to be rate limited, we don't want to flood the logs in case there's a bug.
Also at a glance it seems like you have one fep for multiple netdevs. So stopping one netdev's Tx queue when fep fills up will not stop the other ports from pushing frames, right?
Quoted 6 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +6
-0+spin_unlock (&fep->hw_lock); +return NETDEV_TX_BUSY ; + } + +/* Clear all of the status flags */ + status &= ~BD_ENET_TX_STATS ;
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c static void mtip_config_switch(struct switch_enet_private *fep) · line 502
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +10
-0+ +/* 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.spin +*/ +if ((unsigned long )bufaddr &MTIP_ALIGNMENT ) {
I think you should add
if ... ||
fep->quirks & FEC_QUIRK_SWAP_FRAME)here. You can't modify skb->data without calling skb_cow_data() but you already have buffers allocated so can as well use them.
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c static void mtip_config_switch(struct switch_enet_private *fep) · line 507
Quoted 5 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +5
-0+unsigned int index; + + index = bdp - fep->tx_bd_base; +memcpy (fep->tx_bounce[index], + (void *)skb->data, skb->len);
this fits on one 80 char line BTW, quite easily:
memcpy(fep->tx_bounce[index], (void *)skb->data, skb->len);
Also the cast to void * is not necessary in C.
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c static void mtip_config_switch(struct switch_enet_private *fep) · line 517
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +10
-0+ bufaddr = fep->tx_bounce[index]; + } + +if (fep->quirks &FEC_QUIRK_SWAP_FRAME ) +swap_buffer (bufaddr, skb->len); + +/* Save skb pointer. */ + fep->tx_skbuff[fep->skb_cur] = skb; + + fep->skb_cur = (fep->skb_cur +1 ) &TX_RING_MOD_MASK ;
Not sure if this is buggy, but maybe delay updating things until the mapping succeeds? Fewer things to unwind.
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c static void mtip_config_switch(struct switch_enet_private *fep) · line 529
Quoted 11 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +11
-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 ); +if (unlikely (dma_mapping_error (&fep->pdev->dev, bdp->cbd_bufaddr))) { +dev_err (&fep->pdev->dev, +"Failed to map descriptor tx buffer\n" ); + dev->stats.tx_errors++; + dev->stats.tx_dropped++;
dropped and errors are two different counters
I'd stick to dropped
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c static void mtip_config_switch(struct switch_enet_private *fep) · line 539
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +10
-0+dev_kfree_skb_any (skb); + goto err; + } + +/* 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 );
The | goes at the end of the previous line, start of new line adjusts to the opening brackets..
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c static void mtip_config_switch(struct switch_enet_private *fep) · line 545
Quoted 6 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +6
-0+ +/* Synchronize all descriptor writes */ +wmb (); + bdp->cbd_sc = status; + +netif_trans_update (dev);
Is this call necessary?
Quoted 25 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +25
-0+skb_tx_timestamp (skb); + +/* Trigger transmission start */ +writel (MCF_ESW_TDAR_X_DES_ACTIVE , fep->hwp +ESW_TDAR ); + + dev->stats.tx_bytes += skb->len; +/* 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; + err: +spin_unlock (&fep->hw_lock); + +return NETDEV_TX_OK ; +}
Re: [net-next v15 06/12] net: mtip: Add net_device_ops functions to the L2 switch driver
Hi Jakub,
Quoted 7 lines · On Wed, 16 Jul 2025 23:47:25 +0200 Lukasz Majewski wrote:
Quoted 6 lines
(quoted diff) +2
-0+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 +3
-0+struct mtip_ndev_priv *priv =netdev_priv (dev); +struct switch_enet_private *fep = priv->fep; +unsigned short status;
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c static void mtip_config_switch(struct switch_enet_private *fep) · line 465
Quoted 4 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +4
-0+struct cbd_t *bdp; +void *bufaddr; + +spin_lock (&fep->hw_lock);I see some inconsistencies in how you take this lock. Bunch of bare
spin_lock()calls from BH context, but there's also a_irqsave()call inmtip_adjust_link().
In the legacy NXP (Freescale) code for this IP block (i.e. MTIP switch) the recommended way to re-setup it, when link or duplex changes, is to reset and reconfigure it.
It requires setting up interrupts as well... In that situation, IMHO disabling system interrupts is required to avoid some undefined behaviour.
Quoted 3 lines
Please align to the strictest
context (not sure if the irqsave is actually needed, at a glance, IOW whether the lock is taken from an IRQ)
The spin_lock() for xmit port is similar to what is done for fec_main.c. As this switch uses single uDMA for both ports as well as there is no support (and need) for multiple queues it can be omitted.
Quoted 11 lines
Quoted 11 lines
(quoted diff) +2
-0+ if (!fep->link[0] && !fep->link[1]) { + /* Link is down or autonegotiation is in progress.*/
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +7
-0+netif_stop_queue (dev); +spin_unlock (&fep->hw_lock); +return NETDEV_TX_BUSY ; + } + +/* Fill in a Tx ring entry */ + bdp = fep->cur_tx;
Quoted 8 lines
Quoted 3 lines
(quoted diff) +2
-0+ + /* Force read memory barier on the current transmitdescription */
Barrier are between things. What is this barrier separating, and what write barrier does it pair with? As far as I can tell
cur_txis just a value in memory, and accesses are under ->hw_lock, so there should be no ordering concerns.
The bdp is the uDMA descritptor (memory allocated in the coherent dma area). It is used by the uDMA when data is transferred to MTIP switch internal buffer.
The bdp->cbd_sc is a half word, which is modified by uDMA engine, to indicate if there are errors or transfer has ended.
The rmb() shall improve robustness - it assures that the status corresponds to what was set by uDMA. On the other hand dma coherent allocation shall do this as well.
The fec_main.c places the rmb() in similar places, so I followed their approach.
Quoted 15 lines
Quoted 11 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +6
-0+rmb (); + 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.
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +3
-0+*/ +netif_stop_queue (dev); + dev_err(&fep->pdev->dev, "%s: tx queue full!.\n",Quoted 1 line
dev->name);This needs to be rate limited, we don't want to flood the logs in case there's a bug.
+1
Quoted 2 lines
Also at a glance it seems like you have one fep for multiple netdevs.
Yes.
Quoted 2 lines
So stopping one netdev's Tx queue when fep fills up will not stop the other ports from pushing frames, right?
This is a bit more complicated...
Other solutions - like cpsw_new - are conceptually simple; there are two DMAs to two separate eth IP blocks.
During startup two separate devices are created. When one wants to enable bridge (i.e. start in-hw offloading) - just single bit is setup and ... that's it.
With vf610 / imx287 and MTIP it is a bit different (imx287 is even worse as second ETH interface has incomplete functionality by design).
When switch is not active - you have two uDMA ports to two ENET IP blocks. Full separation. That is what is done with fec_main.c driver.
When you enable MTIP switch - then you have just a single uDMA0 active for "both" ports. In fact you "bridge" two ports into a single one - that is why Freescale/NXP driver (for 2.6.y) just had eth0 to "model" bridged interfaces. That was "simpler" (PHY management was done in the driver as well).
Now, in this driver, we do have two network devices, which are "bridged" (so there is br0). And of course there must be separation between lan0/1 when this driver is used, but bridge is not (yet) created. This works :-)
So I do have - 2x netdevs (handled by single uDMA0) + 2PHYS + br0 + NAPI + switchdev (to avoid broadcast frame storms + {R}STP + FDB - WIP).
Just pure fun :-) to model it all ... and make happy all maintainers :-)
Quoted 20 lines
Quoted 7 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +6
-0+spin_unlock (&fep->hw_lock); +return NETDEV_TX_BUSY ; + } + +/* Clear all of the status flags */ + status &= ~BD_ENET_TX_STATS ;drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c static void mtip_config_switch(struct switch_enet_private *fep) · line 502
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +10
-0+ +/* 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.spin +*/ +if ((unsigned long )bufaddr &MTIP_ALIGNMENT ) {I think you should add
Quoted 5 lines
if ... || fep->quirks & FEC_QUIRK_SWAP_FRAME)here. You can't modify
skb->datawithout callingskb_cow_data()but you already have buffers allocated so can as well use them.
The vf610 doesn't need the frame to be swapped, but has requirements for alignment as well.
I would keep things as they are now - as they just improve readability.
Please keep in mind that this version only supports imx287, but the plan is to add vf610 as well (to be more specific - this driver also works on vf610, but I plan to add those patches after this one is accepted and pulled).
Quoted 9 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c static void mtip_config_switch(struct switch_enet_private *fep) · line 507
Quoted 6 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +5
-0+unsigned int index; + + index = bdp - fep->tx_bd_base; +memcpy (fep->tx_bounce[index], + (void *)skb->data, skb->len);this fits on one 80 char line BTW, quite easily:
Quoted 4 lines
memcpy(fep->tx_bounce[index], (void *)skb->data,
skb->len);Also the cast to void * is not necessary in C.
+1
Quoted 14 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c static void mtip_config_switch(struct switch_enet_private *fep) · line 517
Quoted 11 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +10
-0+ bufaddr = fep->tx_bounce[index]; + } + +if (fep->quirks &FEC_QUIRK_SWAP_FRAME ) +swap_buffer (bufaddr, skb->len); + +/* Save skb pointer. */ + fep->tx_skbuff[fep->skb_cur] = skb; + + fep->skb_cur = (fep->skb_cur +1 ) &TX_RING_MOD_MASK ;Not sure if this is buggy, but maybe delay updating things until the mapping succeeds? Fewer things to unwind.
Yes, the skb storage as well as ring buffer modification can be done after dma mapping code.
Quoted 16 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c static void mtip_config_switch(struct switch_enet_private *fep) · line 529
Quoted 13 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +7
-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 ); + if (unlikely(dma_mapping_error(&fep->pdev->dev,
bdp->cbd_bufaddr))) {drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +4
-0+dev_err (&fep->pdev->dev, +"Failed to map descriptor tx buffer\n" ); + dev->stats.tx_errors++; + dev->stats.tx_dropped++;dropped and errors are two different counters
I'd stick to dropped
Ok.
Quoted 17 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c static void mtip_config_switch(struct switch_enet_private *fep) · line 539
Quoted 13 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +5
-0+dev_kfree_skb_any (skb); + goto err; + } + +/* Send it on its way. Tell FEC it's ready, interrupt when 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 +4
-0+*/ + + status |= (BD_ENET_TX_READY |BD_ENET_TX_INTR + |BD_ENET_TX_LAST |BD_ENET_TX_TC );The | goes at the end of the previous line, start of new line adjusts to the opening brackets..
I've refactored it.
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c static void mtip_config_switch(struct switch_enet_private *fep) · line 545
Quoted 6 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +6
-0+ +/* Synchronize all descriptor writes */ +wmb (); + bdp->cbd_sc = status; + +netif_trans_update (dev);Is this call necessary?
I've added it when I was forward porting the old driver. It can be removed.
Quoted 18 lines
Quoted 18 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +17
-0+skb_tx_timestamp (skb); + +/* Trigger transmission start */ +writel (MCF_ESW_TDAR_X_DES_ACTIVE , fep->hwp +ESW_TDAR ); + + dev->stats.tx_bytes += skb->len; +/* 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);
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c static void mtip_config_switch(struct switch_enet_private *fep) · line 570
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +8
-0+ } + + fep->cur_tx = bdp; + err: +spin_unlock (&fep->hw_lock); + +return NETDEV_TX_OK ; +}
Thanks for the feedback.
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Johanna Denk, Tabea Lutz 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 v15 06/12] net: mtip: Add net_device_ops functions to the L2 switch driver
Hi Jakub, Paolo,
Do you have more comments and questions regarding this driver after my explanation?
Shall I do something more?
Thanks in advance for you feedback.
Quoted 287 lines
Hi Jakub,
Quoted 7 lines · On Wed, 16 Jul 2025 23:47:25 +0200 Lukasz Majewski wrote:
Quoted 6 lines
(quoted diff) +2
-0+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 +3
-0+struct mtip_ndev_priv *priv =netdev_priv (dev); +struct switch_enet_private *fep = priv->fep; +unsigned short status;Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c static void mtip_config_switch(struct switch_enet_private *fep) · line 465
Quoted 4 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +4
-0+struct cbd_t *bdp; +void *bufaddr; + +spin_lock (&fep->hw_lock);I see some inconsistencies in how you take this lock. Bunch of bare
spin_lock()calls from BH context, but there's also a_irqsave()call inmtip_adjust_link().In the legacy NXP (Freescale) code for this IP block (i.e. MTIP switch) the recommended way to re-setup it, when link or duplex changes, is to reset and reconfigure it.
It requires setting up interrupts as well... In that situation, IMHO disabling system interrupts is required to avoid some undefined behaviour.
Quoted 3 lines
Please align to the strictest
context (not sure if the irqsave is actually needed, at a glance, IOW whether the lock is taken from an IRQ)The
spin_lock()for xmit port is similar to what is done forfec_main.c. As this switch uses single uDMA for both ports as well as there is no support (and need) for multiple queues it can be omitted.Quoted 11 lines
Quoted 11 lines
(quoted diff) +2
-0+ if (!fep->link[0] && !fep->link[1]) { + /* Link is down or autonegotiation is inprogress. */
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +7
-0+netif_stop_queue (dev); +spin_unlock (&fep->hw_lock); +return NETDEV_TX_BUSY ; + } + +/* Fill in a Tx ring entry */ + bdp = fep->cur_tx;Quoted 8 lines
Quoted 3 lines
(quoted diff) +2
-0+ + /* Force read memory barier on the current transmitdescription */
Barrier are between things. What is this barrier separating, and what write barrier does it pair with? As far as I can tell
cur_txis just a value in memory, and accesses are under ->hw_lock, so there should be no ordering concerns.The bdp is the uDMA descritptor (memory allocated in the coherent dma area). It is used by the uDMA when data is transferred to MTIP switch internal buffer.
The
bdp->cbd_scis a half word, which is modified by uDMA engine, to indicate if there are errors or transfer has ended.The
rmb()shall improve robustness - it assures that the status corresponds to what was set by uDMA. On the other hand dma coherent allocation shall do this as well.The
fec_main.cplaces thermb()in similar places, so I followed their approach.Quoted 15 lines
Quoted 11 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +6
-0+rmb (); + 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.
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +3
-0+*/ +netif_stop_queue (dev); + dev_err(&fep->pdev->dev, "%s: tx queue full!.\n",Quoted 1 line
dev->name);This needs to be rate limited, we don't want to flood the logs in case there's a bug.
+1
Quoted 3 lines
Also at a glance it seems like you have one fep for multiple netdevs.
Yes.
Quoted 2 lines
So stopping one netdev's Tx queue when fep fills up will not stop the other ports from pushing frames, right?
This is a bit more complicated...
Other solutions - like
cpsw_new- are conceptually simple; there are two DMAs to two separate eth IP blocks.
During startup two separate devices are created. When one wants to enable bridge (i.e. start in-hw offloading) - just single bit is setup and ... that's it.With vf610 / imx287 and MTIP it is a bit different (imx287 is even worse as second ETH interface has incomplete functionality by design).
When switch is not active - you have two uDMA ports to two ENET IP blocks. Full separation. That is what is done with
fec_main.cdriver.When you enable MTIP switch - then you have just a single uDMA0 active for "both" ports. In fact you "bridge" two ports into a single one - that is why Freescale/NXP driver (for 2.6.y) just had eth0 to "model" bridged interfaces. That was "simpler" (PHY management was done in the driver as well).
Now, in this driver, we do have two network devices, which are "bridged" (so there is br0). And of course there must be separation between lan0/1 when this driver is used, but bridge is not (yet) created. This works :-)
So I do have - 2x netdevs (handled by single uDMA0) + 2PHYS + br0 + NAPI + switchdev (to avoid broadcast frame storms + {R}STP + FDB - WIP).
Just pure fun :-) to model it all ... and make happy all maintainers :-)
Quoted 20 lines
Quoted 7 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +6
-0+spin_unlock (&fep->hw_lock); +return NETDEV_TX_BUSY ; + } + +/* Clear all of the status flags */ + status &= ~BD_ENET_TX_STATS ;drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c static void mtip_config_switch(struct switch_enet_private *fep) · line 502
Quoted 10 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +10
-0+ +/* 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.spin +*/ +if ((unsigned long )bufaddr &MTIP_ALIGNMENT ) {I think you should add
Quoted 5 lines
if ... || fep->quirks & FEC_QUIRK_SWAP_FRAME)here. You can't modify
skb->datawithout callingskb_cow_data()but you already have buffers allocated so can as well use them.The vf610 doesn't need the frame to be swapped, but has requirements for alignment as well.
I would keep things as they are now - as they just improve readability.
Please keep in mind that this version only supports imx287, but the plan is to add vf610 as well (to be more specific - this driver also works on vf610, but I plan to add those patches after this one is accepted and pulled).
Quoted 9 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c static void mtip_config_switch(struct switch_enet_private *fep) · line 507
Quoted 6 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +5
-0+unsigned int index; + + index = bdp - fep->tx_bd_base; +memcpy (fep->tx_bounce[index], + (void *)skb->data, skb->len);this fits on one 80 char line BTW, quite easily:
Quoted 4 lines
memcpy(fep->tx_bounce[index], (void *)skb->data,
skb->len);Also the cast to void * is not necessary in C.
+1
Quoted 14 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c static void mtip_config_switch(struct switch_enet_private *fep) · line 517
Quoted 11 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +10
-0+ bufaddr = fep->tx_bounce[index]; + } + +if (fep->quirks &FEC_QUIRK_SWAP_FRAME ) +swap_buffer (bufaddr, skb->len); + +/* Save skb pointer. */ + fep->tx_skbuff[fep->skb_cur] = skb; + + fep->skb_cur = (fep->skb_cur +1 ) &TX_RING_MOD_MASK ;Not sure if this is buggy, but maybe delay updating things until the mapping succeeds? Fewer things to unwind.
Yes, the skb storage as well as ring buffer modification can be done after dma mapping code.
Quoted 10 lines
Quoted 10 lines
(quoted diff) +1
-0+ /* Push the data cache so the CPM does not get stalememory
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +3
-0+* data. +*/ + bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev,bufaddr,
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +3
-0+MTIP_SWITCH_TX_FRSIZE , + DMA_TO_DEVICE); + if (unlikely(dma_mapping_error(&fep->pdev->dev,Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c static void mtip_config_switch(struct switch_enet_private *fep) · line 529
Quoted 5 lines
bdp->cbd_bufaddr))) {drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +4
-0+dev_err (&fep->pdev->dev, +"Failed to map descriptor tx buffer\n" ); + dev->stats.tx_errors++; + dev->stats.tx_dropped++;dropped and errors are two different counters
I'd stick to droppedOk.
Quoted 17 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c static void mtip_config_switch(struct switch_enet_private *fep) · line 539
Quoted 13 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +5
-0+dev_kfree_skb_any (skb); + goto err; + } + +/* Send it on its way. Tell FEC it's ready, interrupt when 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 +4
-0+*/ + + status |= (BD_ENET_TX_READY |BD_ENET_TX_INTR + |BD_ENET_TX_LAST |BD_ENET_TX_TC );The | goes at the end of the previous line, start of new line adjusts to the opening brackets..
I've refactored it.
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c static void mtip_config_switch(struct switch_enet_private *fep) · line 545
Quoted 6 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +6
-0+ +/* Synchronize all descriptor writes */ +wmb (); + bdp->cbd_sc = status; + +netif_trans_update (dev);Is this call necessary?
I've added it when I was forward porting the old driver. It can be removed.
Quoted 18 lines
Quoted 18 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +17
-0+skb_tx_timestamp (skb); + +/* Trigger transmission start */ +writel (MCF_ESW_TDAR_X_DES_ACTIVE , fep->hwp +ESW_TDAR ); + + dev->stats.tx_bytes += skb->len; +/* 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);Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c static void mtip_config_switch(struct switch_enet_private *fep) · line 570
Quoted 8 lines
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +8
-0+ } + + fep->cur_tx = bdp; + err: +spin_unlock (&fep->hw_lock); + +return NETDEV_TX_OK ; +}Thanks for the feedback.
Best regards,
Lukasz Majewski
Quoted 7 lines
--
DENX Software Engineering GmbH, Managing Director: Johanna Denk, Tabea Lutz HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email:
[email protected]
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Johanna Denk, Tabea Lutz HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: [email protected]
Jakub Kicinski
maintainerRe: [net-next v15 06/12] net: mtip: Add net_device_ops functions to the L2 switch driver
Quoted 4 lines · On Wed, 23 Jul 2025 22:05:17 +0200 Lukasz Majewski wrote:
Do you have more comments and questions regarding this driver after my explanation?
Shall I do something more?
Addressing the comments may be more useful than explaining them away.
Re: [net-next v15 06/12] net: mtip: Add net_device_ops functions to the L2 switch driver
Hi Jakub,
Quoted 7 lines · On Wed, 23 Jul 2025 22:05:17 +0200 Lukasz Majewski wrote:
Quoted 4 lines
Do you have more comments and questions regarding this driver after my explanation?
Shall I do something more?
Addressing the comments may be more useful than explaining them away.
As I've already described what are the issues I try to solve (and some design decisions), I will correct them (where applicable) and prepare next code version.
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Johanna Denk, Tabea Lutz HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: [email protected]
PATCH v15 7/12 net: mtip: Add mtip_switch_{rx|tx} functions to the L2 switch driver
In reply to Lukasz MajewskiThis patch provides mtip_switch_tx and mtip_switch_rx functions code for MTIP L2 switch.
---
Changes for v13:
- New patch - created by excluding some code from large (i.e. v12 and earlier) MTIP driver
Changes for v14:
- Rewrite RX error handling code
- Remove } else { from if (unlikely(!skb)) { condition in mtip_switch_rx()
- Remove locking from RX patch (done under NAPI API and similar to fec_main.c driver)
- Use net_prefetch() instead of prefetch()
Changes for v15:
- Use page_address() instead of __va()
- Remove the check if data is NOT null, as it cannot be (those values are assured to be allocated earlier for RX path).
--- .../net/ethernet/freescale/mtipsw/mtipl2sw.c | 238 +++++++++++++++++- 1 file changed, 237 insertions(+), 1 deletion(-)
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +237 -1
@@ -228,6 +228,39 @@ struct mtip_port_info *mtip_portinfofifo_read(struct switch_enet_private *fep)return info; } +static void mtip_atable_get_entry_port_number (struct switch_enet_private *fep, +unsigned char *mac_addr,u8 *port) +{ +int block_index, block_index_end, entry; +u32 mac_addr_lo, mac_addr_hi; +u32 read_lo, read_hi; + + mac_addr_lo = (u32)((mac_addr[3 ] <<24 ) | (mac_addr[2 ] <<16 ) | + (mac_addr[1 ] <<8 ) | mac_addr[0 ]); + mac_addr_hi = (u32)((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 =MTIP_PORT_FORWARDING_INIT ; + +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 )))) + *port =FIELD_GET (AT_PORT_MASK , read_hi); +break ; + } + } + +dev_dbg (&fep->pdev->dev,"%s: MAC: %pM PORT: 0x%x\n" , __func__, + mac_addr, *port); +} +/* Clear complete MAC Look Up Table */ void mtip_clear_atable (struct switch_enet_private *fep) {
@@ -824,11 +857,214 @@ static irqreturn_t mtip_interrupt(int irq, void *ptr_fep)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; +struct cbd_t *bdp; + +spin_lock (&fep->hw_lock); + 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 (&fep->hw_lock); } +/* 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) { -return -ENOMEM ; +struct mtip_ndev_priv *priv =netdev_priv (dev); +u8 *data, rx_port =MTIP_PORT_FORWARDING_INIT ; +struct switch_enet_private *fep = priv->fep; +unsigned short status, pkt_len; +struct net_device *pndev; +struct ethhdr *eth_hdr; +int pkt_received =0 ; +struct sk_buff *skb; +struct cbd_t *bdp; +struct page *page; + +/* 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 )) { +if (pkt_received >= budget) +break ; + + pkt_received++; + +if (!fep->usage_count) + goto rx_processing_done; + + status ^=BD_ENET_RX_LAST ; +/* 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 |BD_ENET_RX_LAST | +BD_ENET_RX_CL )) { + dev->stats.rx_errors++; +if (status &BD_ENET_RX_OV ) { +/* FIFO overrun */ + dev->stats.rx_fifo_errors++; + goto rx_processing_done; + } +if (status & (BD_ENET_RX_LG |BD_ENET_RX_SH + |BD_ENET_RX_LAST )) { +/* Frame too long or too short. */ + dev->stats.rx_length_errors++; +if (status &BD_ENET_RX_LAST ) +netdev_err (dev,"rcv is not +last\n" ); + } +if (status &BD_ENET_RX_CR )/* CRC Error */ + dev->stats.rx_crc_errors++; + +/* Report late collisions as a frame error. */ +if (status & (BD_ENET_RX_NO |BD_ENET_RX_CL )) + dev->stats.rx_frame_errors++; + goto rx_processing_done; + } + +/* Get correct RX page */ + page = fep->page[bdp - fep->rx_bd_base]; +/* Process the incoming frame */ + pkt_len = bdp->cbd_datlen; + +dma_sync_single_for_cpu (&fep->pdev->dev, bdp->cbd_bufaddr, + pkt_len,DMA_FROM_DEVICE ); +net_prefetch (page_address (page)); + data =page_address (page); + +if (fep->quirks &FEC_QUIRK_SWAP_FRAME ) +swap_buffer (data, pkt_len); + + eth_hdr = (struct ethhdr *)data; +mtip_atable_get_entry_port_number (fep, eth_hdr->h_source, + &rx_port); +if (rx_port ==MTIP_PORT_FORWARDING_INIT ) +mtip_atable_dynamicms_learn_migration (fep, +mtip_get_time (), + eth_hdr->h_source, + &rx_port); + +if ((rx_port ==1 || rx_port ==2 ) && fep->ndev[rx_port -1 ]) + pndev = fep->ndev[rx_port -1 ]; +else + pndev = dev; + + *port = rx_port; + +/* This does 16 byte alignment, exactly what we need. +* 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); +page_pool_recycle_direct (fep->page_pool, page); + pndev->stats.rx_dropped++; +return -ENOMEM ; + } + +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); + + pndev->stats.rx_packets++; + pndev->stats.rx_bytes += pkt_len; + + rx_processing_done: +/* Clear the status flags for this buffer */ + status &= ~BD_ENET_RX_STATS ; + +/* Mark the buffer empty */ + status |=BD_ENET_RX_EMPTY ; +/* Make sure that updates to the descriptor are performed */ +wmb (); + 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 , fep->hwp +ESW_RDAR ); + }/* while (!((status = bdp->cbd_sc) & BD_ENET_RX_EMPTY)) */ + + fep->cur_rx = bdp; + +return pkt_received; }static void mtip_adjust_link (struct net_device *dev)
Signature · 1 line
2.39.5
PATCH v15 8/12 net: mtip: Extend the L2 switch driver with management operations
In reply to Lukasz MajewskiThis patch provides function necessary for manging the L2 switch.
---
Changes for v13:
- New patch - created by excluding some code from large (i.e. v12 and earlier) MTIP driver
Changes for v14:
- None
Changes for v15:
- None
--- .../net/ethernet/freescale/mtipsw/Makefile | 2 +- .../net/ethernet/freescale/mtipsw/mtipl2sw.c | 31 ++ .../net/ethernet/freescale/mtipsw/mtipl2sw.h | 23 + .../ethernet/freescale/mtipsw/mtipl2sw_mgnt.c | 443 ++++++++++++++++++ 4 files changed, 498 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c
drivers/net/ethernet/freescale/mtipsw/Makefile +1 -1
@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_FEC_MTIP_L2SW) += nxp-mtipl2sw.o -nxp-mtipl2sw-objs := mtipl2sw.o +nxp-mtipl2sw-objs := mtipl2sw.o mtipl2sw_mgnt.o
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +31 -0
@@ -482,8 +482,35 @@ static void mtip_config_switch(struct switch_enet_private *fep)writel (0 , fep->hwp +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 ); + +/* Disable blocking */ +mtip_port_blocking_config (fep,0 ,0 ); +mtip_port_blocking_config (fep,1 ,0 ); +mtip_port_blocking_config (fep,2 ,0 ); +writel (MCF_ESW_IMR_TXF |MCF_ESW_IMR_RXF , fep->hwp +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 ); + +mtip_port_broadcast_config (fep,0 ,1 ); +mtip_port_broadcast_config (fep,1 ,1 ); +mtip_port_broadcast_config (fep,2 ,1 ); + +/* 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,
@@ -578,6 +605,10 @@ static netdev_tx_t mtip_start_xmit_port(struct sk_buff *skb,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 , fep->hwp +ESW_TDAR );
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h +23 -0
@@ -622,6 +622,29 @@ static inline int mtip_get_time(void)#define MTIP_PORT_FORWARDING_INIT 0xFF +/* 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, +bool enable); +int mtip_vlan_output_process (struct switch_enet_private *fep,int port, +int mode); +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,bool enable); +int mtip_forced_forward (struct switch_enet_private *fep,int port,bool enable); +int mtip_port_learning_config (struct switch_enet_private *fep,int port, +bool disable,bool irq_adj); +int mtip_port_blocking_config (struct switch_enet_private *fep,int port, +bool enable);bool mtip_is_switch_netdev_port (const struct net_device *ndev); +int mtip_port_enable_config (struct switch_enet_private *fep,int port, +bool tx_en,bool rx_en);void mtip_clear_atable (struct switch_enet_private *fep);#endif /* __MTIP_L2SWITCH_H_ */
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_mgnt.c new file +443 -0
443 lines not on this page · raw message
Signature · 1 line
2.39.5
PATCH v15 9/12 net: mtip: Extend the L2 switch driver for imx287 with bridge operations
In reply to Lukasz MajewskiAfter this change the MTIP L2 switch can be configured as offloading device for packet switching when bridge on their interfaces is created.
---
Changes for v13:
- New patch - created by excluding some code from large (i.e. v12 and earlier) MTIP driver
Changes for v14:
- None
Changes for v15:
- None
--- .../net/ethernet/freescale/mtipsw/Makefile | 2 +- .../net/ethernet/freescale/mtipsw/mtipl2sw.c | 6 + .../net/ethernet/freescale/mtipsw/mtipl2sw.h | 2 + .../ethernet/freescale/mtipsw/mtipl2sw_br.c | 120 ++++++++++++++++++ 4 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c
drivers/net/ethernet/freescale/mtipsw/Makefile +1 -1
@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_FEC_MTIP_L2SW) += nxp-mtipl2sw.o -nxp-mtipl2sw-objs := mtipl2sw.o mtipl2sw_mgnt.o +nxp-mtipl2sw-objs := mtipl2sw.o mtipl2sw_mgnt.o mtipl2sw_br.o
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +6 -0
@@ -1883,6 +1883,10 @@ static int mtip_sw_probe(struct platform_device *pdev)if (ret)return dev_err_probe (&pdev->dev, ret,"Could not alloc IRQ\n" ); + ret =mtip_register_notifiers (fep); +if (ret) +return ret; + ret =mtip_ndev_init (fep, pdev);if (ret) { dev_err(&pdev->dev, "%s: Failed to create virtual ndev (%d)\n",
@@ -1914,6 +1918,7 @@ static int mtip_sw_probe(struct platform_device *pdev) dma_init_err:mtip_ndev_cleanup (fep); ndev_init_err: +mtip_unregister_notifiers (fep);return ret; }
@@ -1922,6 +1927,7 @@ 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);
drivers/net/ethernet/freescale/mtipsw/mtipl2sw.h +2 -0
@@ -644,6 +644,8 @@ int mtip_port_learning_config(struct switch_enet_private *fep, int port,int mtip_port_blocking_config (struct switch_enet_private *fep,int port,bool 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,bool tx_en,bool rx_en);void mtip_clear_atable (struct switch_enet_private *fep);
drivers/net/ethernet/freescale/mtipsw/mtipl2sw_br.c new file +120 -0
120 lines not on this page · raw message
Signature · 1 line
2.39.5
PATCH v15 10/12 ARM: mxs_defconfig: Enable CONFIG_NFS_FSCACHE
In reply to Lukasz MajewskiIt is not possible to enable by user the CONFIG_NETFS_SUPPORT anymore and hence it depends on CONFIG_NFS_FSCACHE being enabled.
This patch fixes potential performance regression for NFS on the mxs devices.
---
Changes for v6:
- New patch
Changes for v7:
- None
Changes for v8:
- None
Changes for v9:
- None
Changes for v10:
- None
Changes for v11:
- None
Changes for v12:
- None
Changes for v13:
- None
Changes for v14:
- None
Changes for v15:
- None
--- arch/arm/configs/mxs_defconfig | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/arm/configs/mxs_defconfig +1 -2
@@ -138,8 +138,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
@@ -155,6 +153,7 @@ CONFIG_NFS_FS=y CONFIG_NFS_V3_ACL=y CONFIG_NFS_V4=y CONFIG_ROOT_NFS=y +CONFIG_NFS_FSCACHE=y CONFIG_NLS_CODEPAGE_437=y CONFIG_NLS_CODEPAGE_850=y CONFIG_NLS_ISO8859_1=y
Signature · 1 line
2.39.5
PATCH v15 11/12 ARM: mxs_defconfig: Update mxs_defconfig to 6.16-rc5
In reply to Lukasz MajewskiThis file is the updated version of mxs_defconfig for the v6.16-rc5 linux-next.
Detailed description of removed configuration entries:
-CONFIG_MTD_M25P80=y -> it has been replaced MTD_SPI_NOR (which is enabled) -CONFIG_SMSC_PHY=y -> is enabled implicit by USB_NET_SMSC95XX -CONFIG_GPIO_SYSFS=y -> it has been deprecated by moving to EXPERT and
its replacement GPIO_CDEV is enabled by default
---
Changes for v5:
- New patch
Changes for v6:
- Add detailed description on the removed configuration options after update
Changes for v7:
- None
Changes for v8:
- None
Changes for v9:
- None
Changes for v10:
- None
Changes for v11:
- None
Changes for v12:
- None
Changes for v13:
- None
Changes for v14:
- None
Changes for v15:
- None
--- arch/arm/configs/mxs_defconfig | 7 ------- 1 file changed, 7 deletions(-)
arch/arm/configs/mxs_defconfig +0 -7
@@ -32,9 +32,6 @@ 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_CAN=m
@@ -45,7 +42,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
@@ -60,7 +56,6 @@ 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 +72,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
Signature · 1 line
2.39.5
PATCH v15 12/12 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 L2 switch available on some imx28[7] devices.
Moreover, it also enables CONFIG_SWITCHDEV and CONFIG_BRIDGE required by this driver for correct operation.
---
Changes for v4:
- New patch
Changes for v5:
- Apply this patch on top of patch, which updates mxs_defconfig to v6.15-rc1
- Add more verbose commit message with explanation why SWITCHDEV and BRIDGE must be enabled as well
Changes for v6:
- None
Changes for v7:
- None
Changes for v8:
- None
Changes for v9:
- None
Changes for v10:
- None
Changes for v11:
- None
Changes for v12:
- None
Changes for v13:
- None
Changes for v14:
- None
Changes for v15:
- None
--- arch/arm/configs/mxs_defconfig | 3 +++ 1 file changed, 3 insertions(+)
arch/arm/configs/mxs_defconfig +3 -0
@@ -34,6 +34,8 @@ CONFIG_IP_PNP_DHCP=y CONFIG_SYN_COOKIES=y # 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
@@ -52,6 +54,7 @@ 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
Signature · 1 line
2.39.5