add basic support for i.MX95 NETC
Subsystems (7)
Wei Fang
maintainerv5 cover add basic support for i.MX95 NETC
This is first time that the NETC IP is applied on i.MX MPU platform. Its revision has been upgraded to 4.1, which is very different from the NETC of LS1028A (its revision is 1.0). Therefore, some existing drivers of NETC devices in the Linux kernel are not compatible with the current hardware. For example, the fsl-enetc driver is used to drive the ENETC PF of LS1028A, but for i.MX95 ENETC PF, its registers and tables configuration are very different from those of LS1028A, and only the station interface (SI) part remains basically the same. For the SI part, Vladimir has separated the fsl-enetc-core driver, so we can reuse this driver on i.MX95. However, for other parts of PF, the fsl-enetc driver cannot be reused, so the nxp-enetc4 driver is added to support revision 4.1 and later.
During the development process, we found that the two PF drivers have some interfaces with basically the same logic, and the only difference is the hardware configuration. So in order to reuse these interfaces and reduce code redundancy, we extracted these interfaces and compiled them into a separate nxp-enetc-pf-common driver for use by the two PF drivers.
In addition, we have developed the nxp-netc-blk-ctrl driver, which is used to control three blocks, namely Integrated Endpoint Register Block (IERB), Privileged Register Block (PRB) and NETCMIX block. The IERB contains registers that are used for pre-boot initialization, debug, and non-customer configuration. The PRB controls global reset and global error handling for NETC. The NETCMIX block is mainly used to set MII protocol and PCS protocol of the links, it also contains settings for some other functions.
---
v1 Link: https://lore.kernel.org/imx/[email protected]/
v2 Link: https://lore.kernel.org/imx/[email protected]/
v3 Link: https://lore.kernel.org/imx/[email protected]/
v4 Link: https://lore.kernel.org/imx/[email protected]/
---
Clark Wang (2):
net: enetc: extract enetc_int_vector_init/destroy() from
enetc_alloc_msix()
net: enetc: optimize the allocation of tx_bdr
Vladimir Oltean (1):
net: enetc: remove ERR050089 workaround for i.MX95
Wei Fang (10):
dt-bindings: net: add compatible string for i.MX95 EMDIO
dt-bindings: net: add i.MX95 ENETC support
dt-bindings: net: add bindings for NETC blocks control
net: enetc: add initial netc-blk-ctrl driver support
net: enetc: extract common ENETC PF parts for LS1028A and i.MX95
platforms
net: enetc: build enetc_pf_common.c as a separate module
PCI: Add NXP NETC vendor ID and device IDs
net: enetc: add i.MX95 EMDIO support
net: enetc: add preliminary support for i.MX95 ENETC PF
MAINTAINERS: update ENETC driver files and maintainers
.../bindings/net/fsl,enetc-mdio.yaml | 11 +- .../devicetree/bindings/net/fsl,enetc.yaml | 34 +- .../bindings/net/nxp,netc-blk-ctrl.yaml | 104 +++ MAINTAINERS | 7 + drivers/net/ethernet/freescale/enetc/Kconfig | 40 + drivers/net/ethernet/freescale/enetc/Makefile | 9 + drivers/net/ethernet/freescale/enetc/enetc.c | 261 +++--- drivers/net/ethernet/freescale/enetc/enetc.h | 30 +- .../net/ethernet/freescale/enetc/enetc4_hw.h | 152 ++++ .../net/ethernet/freescale/enetc/enetc4_pf.c | 759 ++++++++++++++++++ .../ethernet/freescale/enetc/enetc_ethtool.c | 35 +- .../net/ethernet/freescale/enetc/enetc_hw.h | 53 +- .../ethernet/freescale/enetc/enetc_pci_mdio.c | 21 + .../net/ethernet/freescale/enetc/enetc_pf.c | 310 +------ .../net/ethernet/freescale/enetc/enetc_pf.h | 42 + .../freescale/enetc/enetc_pf_common.c | 338 ++++++++ .../net/ethernet/freescale/enetc/enetc_qos.c | 2 +- .../net/ethernet/freescale/enetc/enetc_vf.c | 6 + .../ethernet/freescale/enetc/netc_blk_ctrl.c | 438 ++++++++++ include/linux/fsl/netc_global.h | 19 + include/linux/pci_ids.h | 7 + 21 files changed, 2263 insertions(+), 415 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/nxp,netc-blk-ctrl.yaml create mode 100644 drivers/net/ethernet/freescale/enetc/enetc4_hw.h create mode 100644 drivers/net/ethernet/freescale/enetc/enetc4_pf.c create mode 100644 drivers/net/ethernet/freescale/enetc/enetc_pf_common.c create mode 100644 drivers/net/ethernet/freescale/enetc/netc_blk_ctrl.c create mode 100644 include/linux/fsl/netc_global.h
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH v5 1/13 dt-bindings: net: add compatible string for i.MX95 EMDIO
The EMDIO of i.MX95 has been upgraded to revision 4.1, and the vendor ID and device ID have also changed, so add the new compatible strings for i.MX95 EMDIO.
---
v5: no changes
--- .../devicetree/bindings/net/fsl,enetc-mdio.yaml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
Documentation/devicetree/bindings/net/fsl,enetc-mdio.yaml +7 -4
@@ -20,10 +20,13 @@ maintainers: properties: compatible: - items: - - enum: - - pci1957,ee01 - - const: fsl,enetc-mdio + oneOf: + - items: + - enum: + - pci1957,ee01 + - const: fsl,enetc-mdio + - items: + - const: pci1131,ee00 reg: maxItems: 1
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH v5 2/13 dt-bindings: net: add i.MX95 ENETC support
In reply to Wei FangThe ENETC of i.MX95 has been upgraded to revision 4.1, and the vendor ID and device ID have also changed, so add the new compatible strings for i.MX95 ENETC. In addition, i.MX95 supports configuration of RGMII or RMII reference clock.
---
v2: Remove "nxp,imx95-enetc" compatible string.
v3:
1. Add restriction to "clcoks" and "clock-names" properties and rename the clock, also remove the items from these two properties.
2. Remove unnecessary items for "pci1131,e101" compatible string.
v4: Move clocks and clock-names to top level.
v5: Add items to clocks and clock-names
--- .../devicetree/bindings/net/fsl,enetc.yaml | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/net/fsl,enetc.yaml +31 -3
@@ -20,14 +20,23 @@ maintainers: properties: compatible: - items: + oneOf: + - items: + - enum: + - pci1957,e100 + - const: fsl,enetc - enum: - - pci1957,e100 - - const: fsl,enetc + - pci1131,e101 reg: maxItems: 1 + clocks: + maxItems: 1 + + clock-names: + maxItems: 1 + mdio: $ref: mdio.yaml unevaluatedProperties: false
@@ -40,6 +49,25 @@ required: allOf: - $ref: /schemas/pci/pci-device.yaml - $ref: ethernet-controller.yaml + - if: + properties: + compatible: + contains: + enum: + - pci1131,e101 + then: + properties: + clocks: + items: + - description: MAC transmit/receiver reference clock + + clock-names: + items: + - const: ref + else: + properties: + clocks: false + clock-names: false unevaluatedProperties: false
Signature · 1 line
2.34.1
Rob Herring
maintainerRe: [PATCH v5 net-next 02/13] dt-bindings: net: add i.MX95 ENETC support
Quoted 54 lines · Wei Fang
The ENETC of i.MX95 has been upgraded to revision 4.1, and the vendor ID and device ID have also changed, so add the new compatible strings for i.MX95 ENETC. In addition, i.MX95 supports configuration of RGMII or RMII reference clock.
Signed-off-by Wei Fang <[email protected]>---
v2: Remove "nxp,imx95-enetc" compatible string.
v3:
1. Add restriction to "clcoks" and "clock-names" properties and rename the clock, also remove the items from these two properties.
2. Remove unnecessary items for "pci1131,e101" compatible string.
v4: Move clocks and clock-names to top level.
v5: Add items to clocks and clock-names--- .../devicetree/bindings/net/fsl,enetc.yaml | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-)Documentation/devicetree/bindings/net/fsl,enetc.yaml +13
-3@@ -20,14 +20,23 @@ maintainers: properties: compatible: - items: + oneOf: + - items: + - enum: + - pci1957,e100 + - const: fsl,enetc - enum: - - pci1957,e100 - - const: fsl,enetc + - pci1131,e101 reg: maxItems: 1 + clocks: + maxItems: 1 + + clock-names: + maxItems: 1 + mdio: $ref: mdio.yaml unevaluatedProperties: false@@ -40,6 +49,25 @@ required: allOf: - $ref: /schemas/pci/pci-device.yaml - $ref: ethernet-controller.yaml + - if:
Documentation/devicetree/bindings/net/fsl,enetc.yaml required: · line 62
Quoted 10 lines
Documentation/devicetree/bindings/net/fsl,enetc.yaml +10
-0+ properties: + compatible: + contains: + enum: + - pci1131,e101 + then: + properties: + clocks: + items: + - description: MAC transmit/receiver reference clock
This goes in the top-level or can just be dropped.
Documentation/devicetree/bindings/net/fsl,enetc.yaml required: · line 66
Quoted 4 lines
Documentation/devicetree/bindings/net/fsl,enetc.yaml +4
-0+ + clock-names: + items: + - const: ref
This goes in the top-level.
Documentation/devicetree/bindings/net/fsl,enetc.yaml required: · line 67
Quoted 1 line
Documentation/devicetree/bindings/net/fsl,enetc.yaml +1
-0+ else:
Then negate the 'if' schema (not: contains: ...) and you just need the part below:
Quoted 9 lines
Documentation/devicetree/bindings/net/fsl,enetc.yaml +3
-0+ properties: + clocks: false + clock-names: false unevaluatedProperties: falseSignature · 1 line
2.34.1
Wei Fang
maintainerRE: [PATCH v5 net-next 02/13] dt-bindings: net: add i.MX95 ENETC support
Quoted 75 lines · Wei Fang
Quoted 55 lines
The ENETC of i.MX95 has been upgraded to revision 4.1, and the vendor ID and device ID have also changed, so add the new compatible strings for i.MX95 ENETC. In addition, i.MX95 supports configuration of RGMII or RMII reference clock.
Signed-off-by Wei Fang <[email protected]>---
v2: Remove "nxp,imx95-enetc" compatible string.
v3:
1. Add restriction to "clcoks" and "clock-names" properties and rename the clock, also remove the items from these two properties.
2. Remove unnecessary items for "pci1131,e101" compatible string.
v4: Move clocks and clock-names to top level.
v5: Add items to clocks and clock-names--- .../devicetree/bindings/net/fsl,enetc.yaml | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-)Documentation/devicetree/bindings/net/fsl,enetc.yaml +13
-3@@ -20,14 +20,23 @@ maintainers: properties: compatible: - items: + oneOf: + - items: + - enum: + - pci1957,e100 + - const: fsl,enetc - enum: - - pci1957,e100 - - const: fsl,enetc + - pci1131,e101 reg: maxItems: 1 + clocks: + maxItems: 1 + + clock-names: + maxItems: 1 + mdio: $ref: mdio.yaml unevaluatedProperties: false@@ -40,6 +49,25 @@ required: allOf: - $ref: /schemas/pci/pci-device.yaml - $ref: ethernet-controller.yaml + - if:Documentation/devicetree/bindings/net/fsl,enetc.yaml required: · line 62
Quoted 10 lines
Documentation/devicetree/bindings/net/fsl,enetc.yaml +10
-0+ properties: + compatible: + contains: + enum: + - pci1131,e101 + then: + properties: + clocks: + items: + - description: MAC transmit/receiver reference clockThis goes in the top-level or can just be dropped.
Documentation/devicetree/bindings/net/fsl,enetc.yaml required: · line 66
Quoted 4 lines
Documentation/devicetree/bindings/net/fsl,enetc.yaml +4
-0+ + clock-names: + items: + - const: ref
Quoted 7 lines
This goes in the top-level.
Documentation/devicetree/bindings/net/fsl,enetc.yaml required: · line 67
Quoted 1 line
Documentation/devicetree/bindings/net/fsl,enetc.yaml +1
-0+ else:Then negate the 'if' schema (not: contains: ...) and you just need the part below:
Okay, I'll improve it, many thanks.
Quoted 10 lines
Quoted 10 lines
Documentation/devicetree/bindings/net/fsl,enetc.yaml +3
-1+ properties: + clocks: false + clock-names: false unevaluatedProperties: false --2.34.1
Wei Fang
maintainerPATCH v5 3/13 dt-bindings: net: add bindings for NETC blocks control
In reply to Wei FangAdd bindings for NXP NETC blocks control. Usually, NETC has 2 blocks of 64KB registers, integrated endpoint register block (IERB) and privileged register block (PRB). IERB is used for pre-boot initialization for all NETC devices, such as ENETC, Timer, EMDIO and so on. And PRB controls global reset and global error handling for NETC. Moreover, for the i.MX platform, there is also a NETCMIX block for link configuration, such as MII protocol, PCS protocol, etc.
---
v2 changes:
1. Rephrase the commit message.
2. Change unevaluatedProperties to additionalProperties.
3. Remove the useless lables from examples.
v3 changes:
1. Remove the items from clocks and clock-names, add maxItems to clocks and rename the clock.
v4 changes:
1. Reorder the required properties.
2. Add assigned-clocks, assigned-clock-parents and assigned-clock-rates. v5 changes:
1. Remove assigned-clocks, assigned-clock-parents and assigned-clock-rates
2. Remove minItems from reg and reg-names
3. Rename the node in the examples to be more general
--- .../bindings/net/nxp,netc-blk-ctrl.yaml | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/nxp,netc-blk-ctrl.yaml
Documentation/devicetree/bindings/net/nxp,netc-blk-ctrl.yaml new file +104 -0
@@ -0,0 +1,104 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/nxp,netc-blk-ctrl.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: NETC Blocks Control + +description: + Usually, NETC has 2 blocks of 64KB registers, integrated endpoint register + block (IERB) and privileged register block (PRB). IERB is used for pre-boot + initialization for all NETC devices, such as ENETC, Timer, EMIDO and so on. + And PRB controls global reset and global error handling for NETC. Moreover, + for the i.MX platform, there is also a NETCMIX block for link configuration, + such as MII protocol, PCS protocol, etc. + +maintainers: + - Wei Fang <[email protected]> + - Clark Wang <[email protected]> + +properties: + compatible: + enum: + - nxp,imx95-netc-blk-ctrl + + reg: + maxItems: 3 + + reg-names: + items: + - const: ierb + - const: prb + - const: netcmix + + "#address-cells": + const: 2 + + "#size-cells": + const: 2 + + ranges: true + + clocks: + maxItems: 1 + + clock-names: + items: + - const: ipg + + power-domains: + maxItems: 1 + +patternProperties: + "^pcie@[0-9a-f]+$": + $ref: /schemas/pci/host-generic-pci.yaml# + +required: + - compatible + - reg + - reg-names + - "#address-cells" + - "#size-cells" + - ranges + +additionalProperties: false + +examples: + - | + bus { + #address-cells = <2>; + #size-cells = <2>; + + system-controller@4cde0000 { + compatible = "nxp,imx95-netc-blk-ctrl"; + reg = <0x0 0x4cde0000 0x0 0x10000>, + <0x0 0x4cdf0000 0x0 0x10000>, + <0x0 0x4c81000c 0x0 0x18>; + reg-names = "ierb", "prb", "netcmix"; + #address-cells = <2>; + #size-cells = <2>; + ranges; + clocks = <&scmi_clk 98>; + clock-names = "ipg"; + power-domains = <&scmi_devpd 18>; + + pcie@4cb00000 { + compatible = "pci-host-ecam-generic"; + reg = <0x0 0x4cb00000 0x0 0x100000>; + #address-cells = <3>; + #size-cells = <2>; + device_type = "pci"; + bus-range = <0x1 0x1>; + ranges = <0x82000000 0x0 0x4cce0000 0x0 0x4cce0000 0x0 0x20000 + 0xc2000000 0x0 0x4cd10000 0x0 0x4cd10000 0x0 0x10000>; + + mdio@0,0 { + compatible = "pci1131,ee00"; + reg = <0x010000 0 0 0 0>; + #address-cells = <1>; + #size-cells = <0>; + }; + }; + }; + };
Signature · 1 line
2.34.1
Re: [PATCH v5 net-next 03/13] dt-bindings: net: add bindings for NETC blocks control
Quoted 24 lines · Wei Fang
Add bindings for NXP NETC blocks control. Usually, NETC has 2 blocks of 64KB registers, integrated endpoint register block (IERB) and privileged register block (PRB). IERB is used for pre-boot initialization for all NETC devices, such as ENETC, Timer, EMDIO and so on. And PRB controls global reset and global error handling for NETC. Moreover, for the i.MX platform, there is also a NETCMIX block for link configuration, such as MII protocol, PCS protocol, etc.
Signed-off-by Wei Fang <[email protected]>---
v2 changes:
1. Rephrase the commit message.
2. Change unevaluatedProperties to additionalProperties.
3. Remove the useless lables from examples.
v3 changes:
1. Remove the items from clocks and clock-names, add maxItems to clocks and rename the clock.
v4 changes:
1. Reorder the required properties.
2. Add assigned-clocks, assigned-clock-parents and assigned-clock-rates. v5 changes:
1. Remove assigned-clocks, assigned-clock-parents and assigned-clock-rates
2. Remove minItems from reg and reg-names
3. Rename the node in the examples to be more general
Quoted 5 lines
--- .../bindings/net/nxp,netc-blk-ctrl.yaml | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/nxp,netc-blk-ctrl.yaml
Wei Fang
maintainerPATCH v5 4/13 net: enetc: add initial netc-blk-ctrl driver support
In reply to Wei FangThe netc-blk-ctrl driver is used to configure Integrated Endpoint Register Block (IERB) and Privileged Register Block (PRB) of NETC. For i.MX platforms, it is also used to configure the NETCMIX block.
The IERB contains registers that are used for pre-boot initialization, debug, and non-customer configuration. The PRB controls global reset and global error handling for NETC. The NETCMIX block is mainly used to set MII protocol and PCS protocol of the links, it also contains settings for some other functions.
Note the IERB configuration registers can only be written after being unlocked by PRB, otherwise, all write operations are inhibited. A warm reset is performed when the IERB is unlocked, and it results in an FLR to all NETC devices. Therefore, all NETC device drivers must be probed or initialized after the warm reset is finished.
---
v5: no changes
--- drivers/net/ethernet/freescale/enetc/Kconfig | 14 + drivers/net/ethernet/freescale/enetc/Makefile | 3 + .../ethernet/freescale/enetc/netc_blk_ctrl.c | 438 ++++++++++++++++++ include/linux/fsl/netc_global.h | 19 + 4 files changed, 474 insertions(+) create mode 100644 drivers/net/ethernet/freescale/enetc/netc_blk_ctrl.c create mode 100644 include/linux/fsl/netc_global.h
drivers/net/ethernet/freescale/enetc/Kconfig +14 -0
@@ -75,3 +75,17 @@ config FSL_ENETC_QOS enable/disable from user space via Qos commands(tc). In the kernel side, it can be loaded by Qos driver. Currently, it is only support taprio(802.1Qbv) and Credit Based Shaper(802.1Qbu). + +config NXP_NETC_BLK_CTRL + tristate "NETC blocks control driver" + help + This driver configures Integrated Endpoint Register Block (IERB) and + Privileged Register Block (PRB) of NETC. For i.MX platforms, it also + includes the configuration of NETCMIX block. + The IERB contains registers that are used for pre-boot initialization, + debug, and non-customer configuration. The PRB controls global reset + and global error handling for NETC. The NETCMIX block is mainly used + to set MII protocol and PCS protocol of the links, it also contains + settings for some other functions. + + If compiled as module (M), the module name is nxp-netc-blk-ctrl.
drivers/net/ethernet/freescale/enetc/Makefile +3 -0
@@ -19,3 +19,6 @@ fsl-enetc-mdio-y := enetc_pci_mdio.o enetc_mdio.o obj-$(CONFIG_FSL_ENETC_PTP_CLOCK) += fsl-enetc-ptp.o fsl-enetc-ptp-y := enetc_ptp.o + +obj-$(CONFIG_NXP_NETC_BLK_CTRL) += nxp-netc-blk-ctrl.o +nxp-netc-blk-ctrl-y := netc_blk_ctrl.o
drivers/net/ethernet/freescale/enetc/netc_blk_ctrl.c new file +438 -0
438 lines not on this page · raw message
include/linux/fsl/netc_global.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */ +/* Copyright 2024 NXP +*/ +#ifndef __NETC_GLOBAL_H +#define __NETC_GLOBAL_H + +#include <linux/io.h> + +static inline u32 netc_read (void __iomem *reg) +{ +return ioread32 (reg); +} + +static inline void netc_write (void __iomem *reg,u32 val) +{ +iowrite32 (val, reg); +} + +#endif
Signature · 1 line
2.34.1
Vladimir Oltean
maintainerRe: [PATCH v5 net-next 04/13] net: enetc: add initial netc-blk-ctrl driver support
Quoted 16 lines · Wei Fang
The netc-blk-ctrl driver is used to configure Integrated Endpoint Register Block (IERB) and Privileged Register Block (PRB) of NETC. For i.MX platforms, it is also used to configure the NETCMIX block.
The IERB contains registers that are used for pre-boot initialization, debug, and non-customer configuration. The PRB controls global reset and global error handling for NETC. The NETCMIX block is mainly used to set MII protocol and PCS protocol of the links, it also contains settings for some other functions.
Note the IERB configuration registers can only be written after being unlocked by PRB, otherwise, all write operations are inhibited. A warm reset is performed when the IERB is unlocked, and it results in an FLR to all NETC devices. Therefore, all NETC device drivers must be probed or initialized after the warm reset is finished.
Quoted 3 lines
Signed-off-by Wei Fang <[email protected]>Reviewed-by Frank Li <[email protected]>---
Can U-Boot deal with the IERB/PRB configuration?
For LS1028A, the platform which initiated the IERB driver "trend", the situation was a bit more complicated, as we realized the reset-time defaults aren't what we need very late in the product life cycle, when customer boards already had bootloaders and we didn't want to complicate their process to have to redeploy in order to get access to such a basic feature as flow control. Though if we knew it from day one, we would have put the IERB fixups in U-Boot.
What is written in the IERB for MII/PCS protocols by default? I suppose there's some other mechanism to preinitialize it with good values?
Wei Fang
maintainerRE: [PATCH v5 net-next 04/13] net: enetc: add initial netc-blk-ctrl driver support
Quoted 21 lines · Wei Fang
Quoted 16 lines
The netc-blk-ctrl driver is used to configure Integrated Endpoint Register Block (IERB) and Privileged Register Block (PRB) of NETC. For i.MX platforms, it is also used to configure the NETCMIX block.
The IERB contains registers that are used for pre-boot initialization, debug, and non-customer configuration. The PRB controls global reset and global error handling for NETC. The NETCMIX block is mainly used to set MII protocol and PCS protocol of the links, it also contains settings for some other functions.
Note the IERB configuration registers can only be written after being unlocked by PRB, otherwise, all write operations are inhibited. A warm reset is performed when the IERB is unlocked, and it results in an FLR to all NETC devices. Therefore, all NETC device drivers must be probed or initialized after the warm reset is finished.
Quoted 3 lines
Signed-off-by Wei Fang <[email protected]>Reviewed-by Frank Li <[email protected]>---
Quoted 8 lines
Can U-Boot deal with the IERB/PRB configuration?
For LS1028A, the platform which initiated the IERB driver "trend", the situation was a bit more complicated, as we realized the reset-time defaults aren't what we need very late in the product life cycle, when customer boards already had bootloaders and we didn't want to complicate their process to have to redeploy in order to get access to such a basic feature as flow control. Though if we knew it from day one, we would have put the IERB fixups in U-Boot.
The situation of i.MX95 is different from LS1028A, i.MX95 needs to support system suspend/resume feature. If the i.MX95 enters suspend mode, the NETC may power off (depends on user case), so IERB and PRB will be reset, in this case, we need to reconfigure the IERB & PRB, including NETCMIX.
Quoted 3 lines
What is written in the IERB for MII/PCS protocols by default? I suppose there's some other mechanism to preinitialize it with good values?
The MII/PCS protocols are set in NETCMIX not IERB, but the IERB will get these info from NETCMIX, I mean the hardware, not the software. The default values are all 0.
Vladimir Oltean
maintainerRe: [PATCH v5 net-next 04/13] net: enetc: add initial netc-blk-ctrl driver support
Quoted 15 lines · Wei Fang
Quoted 9 lines · Wei Fang
Can U-Boot deal with the IERB/PRB configuration?
For LS1028A, the platform which initiated the IERB driver "trend", the situation was a bit more complicated, as we realized the reset-time defaults aren't what we need very late in the product life cycle, when customer boards already had bootloaders and we didn't want to complicate their process to have to redeploy in order to get access to such a basic feature as flow control. Though if we knew it from day one, we would have put the IERB fixups in U-Boot.
The situation of i.MX95 is different from LS1028A, i.MX95 needs to support system suspend/resume feature. If the i.MX95 enters suspend mode, the NETC may power off (depends on user case), so IERB and PRB will be reset, in this case, we need to reconfigure the IERB & PRB, including NETCMIX.
Quoted 6 lines
Quoted 2 lines
What is written in the IERB for MII/PCS protocols by default? I suppose there's some other mechanism to preinitialize it with good values?
The MII/PCS protocols are set in NETCMIX not IERB, but the IERB will get these info from NETCMIX, I mean the hardware, not the software. The default values are all 0.
I am shocked that the NETCMIX/IERB blocks does not have a separate power domain from the ENETC, to avoid powering them off, which loses the settings. Please provide this explanation in the opening comments of this driver, it is its entire "raison d'être".
Wei Fang
maintainerRE: [PATCH v5 net-next 04/13] net: enetc: add initial netc-blk-ctrl driver support
Quoted 44 lines
-----Original Message-----
From: Vladimir Oltean <[email protected]>
Sent: 2024年10月25日 20:43
To: Wei Fang <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Claudiu Manoil <[email protected]>; Clark Wang <[email protected]>; Frank Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v5 net-next 04/13] net: enetc: add initial netc-blk-ctrl driver supportQuoted 4 lines · Wei Fang
Quoted 4 lines · Wei Fang
Can U-Boot deal with the IERB/PRB configuration?
For LS1028A, the platform which initiated the IERB driver "trend", the
situation
Quoted 1 line
Quoted 1 line
was a bit more complicated, as we realized the reset-time defaults aren't
what
Quoted 1 line
Quoted 1 line
we need very late in the product life cycle, when customer boards already
had
Quoted 1 line
Quoted 1 line
bootloaders and we didn't want to complicate their process to have to
redeploy
Quoted 1 line
Quoted 1 line
in order to get access to such a basic feature as flow control. Though if we
knew
Quoted 3 lines
Quoted 1 line
it from day one, we would have put the IERB fixups in U-Boot.
The situation of i.MX95 is different from LS1028A, i.MX95 needs to support
system
Quoted 2 lines
suspend/resume feature. If the i.MX95 enters suspend mode, the NETC may power off (depends on user case), so IERB and PRB will be reset, in this case,
we need
Quoted 3 lines
to reconfigure the IERB & PRB, including NETCMIX.
Quoted 1 line
What is written in the IERB for MII/PCS protocols by default? I suppose
there's
Quoted 3 lines
Quoted 1 line
some other mechanism to preinitialize it with good values?
The MII/PCS protocols are set in NETCMIX not IERB, but the IERB will get
these
Quoted 8 lines
Quoted 1 line
info from NETCMIX, I mean the hardware, not the software. The default
values
Quoted 1 line
are all 0.
I am shocked that the NETCMIX/IERB blocks does not have a separate power domain from the ENETC, to avoid powering them off, which loses the settings. Please provide this explanation in the opening comments of this driver, it is its entire "raison d'être".
Hmm, it's a good idea, I can add this annotation at the beginning of the driver. But this in not the entire "raison d'être", because we also hope to be able to dynamically configure based on DTS, which is more flexible than under uboot. For example, Timer binding for ENETC and switch if there are multiple Timer instances, port selection if two ENETCs or one ENETC and one switch port share the same physical port.
Wei Fang
maintainerPATCH v5 5/13 net: enetc: extract common ENETC PF parts for LS1028A and i.MX95 platforms
In reply to Wei FangThe ENETC PF driver of LS1028A (rev 1.0) is incompatible with the version used on the i.MX95 platform (rev 4.1), except for the station interface (SI) part. To reduce code redundancy and prepare for a new driver for rev 4.1 and later, extract shared interfaces from enetc_pf.c and move them to enetc_pf_common.c. This refactoring lays the groundwork for compiling enetc_pf_common.c into a shared driver for both platforms' PF drivers.
---
v5: no changes
--- drivers/net/ethernet/freescale/enetc/Makefile | 2 +- .../net/ethernet/freescale/enetc/enetc_pf.c | 297 +----------------- .../net/ethernet/freescale/enetc/enetc_pf.h | 13 + .../freescale/enetc/enetc_pf_common.c | 295 +++++++++++++++++ 4 files changed, 313 insertions(+), 294 deletions(-) create mode 100644 drivers/net/ethernet/freescale/enetc/enetc_pf_common.c
drivers/net/ethernet/freescale/enetc/Makefile +1 -1
@@ -4,7 +4,7 @@ obj-$(CONFIG_FSL_ENETC_CORE) += fsl-enetc-core.o fsl-enetc-core-y := enetc.o enetc_cbdr.o enetc_ethtool.o obj-$(CONFIG_FSL_ENETC) += fsl-enetc.o -fsl-enetc-y := enetc_pf.o +fsl-enetc-y := enetc_pf.o enetc_pf_common.o fsl-enetc-$(CONFIG_PCI_IOV) += enetc_msg.o fsl-enetc-$(CONFIG_FSL_ENETC_QOS) += enetc_qos.o
drivers/net/ethernet/freescale/enetc/enetc_pf.c +4 -293
347 lines not on this page · raw message
drivers/net/ethernet/freescale/enetc/enetc_pf.h +13 -0
@@ -58,3 +58,16 @@ struct enetc_pf {int enetc_msg_psi_init (struct enetc_pf *pf);void enetc_msg_psi_free (struct enetc_pf *pf);void enetc_msg_handle_rxmsg (struct enetc_pf *pf,int mbox_id,u16 *status); + +void enetc_pf_get_primary_mac_addr (struct enetc_hw *hw,int si,u8 *addr); +void enetc_pf_set_primary_mac_addr (struct enetc_hw *hw,int si, +const u8 *addr); +int enetc_pf_set_mac_addr (struct net_device *ndev,void *addr); +int enetc_setup_mac_addresses (struct device_node *np,struct enetc_pf *pf); +void enetc_pf_netdev_setup (struct enetc_si *si,struct net_device *ndev, +const struct net_device_ops *ndev_ops); +int enetc_mdiobus_create (struct enetc_pf *pf,struct device_node *node); +void enetc_mdiobus_destroy (struct enetc_pf *pf); +int enetc_phylink_create (struct enetc_ndev_priv *priv,struct device_node *node, +const struct phylink_mac_ops *ops); +void enetc_phylink_destroy (struct enetc_ndev_priv *priv);
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c new file +295 -0
295 lines not on this page · raw message
Signature · 1 line
2.34.1
Vladimir Oltean
maintainerRe: [PATCH v5 net-next 05/13] net: enetc: extract common ENETC PF parts for LS1028A and i.MX95 platforms
Quoted 11 lines · Wei Fang
drivers/net/ethernet/freescale/enetc/enetc_pf.h +3
-0@@ -58,3 +58,16 @@ struct enetc_pf {int enetc_msg_psi_init (struct enetc_pf *pf);void enetc_msg_psi_free (struct enetc_pf *pf);void enetc_msg_handle_rxmsg (struct enetc_pf *pf,int mbox_id,u16 *status); + +void enetc_pf_get_primary_mac_addr (struct enetc_hw *hw,int si,u8 *addr); +void enetc_pf_set_primary_mac_addr(struct enetc_hw *hw, int si,
drivers/net/ethernet/freescale/enetc/enetc_pf.h struct enetc_pf { · line 73
Quoted 10 lines
drivers/net/ethernet/freescale/enetc/enetc_pf.h +10
-0+ const u8 *addr); +int enetc_pf_set_mac_addr (struct net_device *ndev,void *addr); +int enetc_setup_mac_addresses (struct device_node *np,struct enetc_pf *pf); +void enetc_pf_netdev_setup (struct enetc_si *si,struct net_device *ndev, +const struct net_device_ops *ndev_ops); +int enetc_mdiobus_create (struct enetc_pf *pf,struct device_node *node); +void enetc_mdiobus_destroy (struct enetc_pf *pf); +int enetc_phylink_create (struct enetc_ndev_priv *priv,struct device_node *node, +const struct phylink_mac_ops *ops); +void enetc_phylink_destroy (struct enetc_ndev_priv *priv);
Could you put the prototypes of functions exported by enetc_pf_common.c into a header named enetc_pf_common.h? It should be self-contained, i.e. a dummy C file with just #include "enetc_pf_common.h" in it should compile fine.
I know the enetc driver isn't there yet when it comes to thoroughly respecting that, but for code we touch now, we should try to follow it.
Wei Fang
maintainerRE: [PATCH v5 net-next 05/13] net: enetc: extract common ENETC PF parts for LS1028A and i.MX95 platforms
Quoted 25 lines · Wei Fang
Review
Quoted 1 line
(quoted diff) +0
-0
b/drivers/net/ethernet/freescale/enetc/enetc_pf.hdrivers/net/ethernet/freescale/enetc/enetc_pf.h struct enetc_pf { · line 60
Quoted 7 lines
index
c26bd66e4597..92a26b09cf57100644drivers/net/ethernet/freescale/enetc/enetc_pf.h +0
-0@@ -58,3 +58,16 @@ struct enetc_pf {int enetc_msg_psi_init (struct enetc_pf *pf);void enetc_msg_psi_free (struct enetc_pf *pf); void enetc_msg_handle_rxmsg(struct enetc_pf *pf, int mbox_id, u16*status);
drivers/net/ethernet/freescale/enetc/enetc_pf.h struct enetc_pf { · line 62
Quoted 2 lines
drivers/net/ethernet/freescale/enetc/enetc_pf.h +2
-0+ +void enetc_pf_get_primary_mac_addr(struct enetc_hw *hw, int si, u8*addr);
drivers/net/ethernet/freescale/enetc/enetc_pf.h struct enetc_pf {
Quoted 4 lines
drivers/net/ethernet/freescale/enetc/enetc_pf.h +4
-0+void enetc_pf_set_primary_mac_addr (struct enetc_hw *hw,int si, +const u8 *addr); +int enetc_pf_set_mac_addr (struct net_device *ndev,void *addr); +int enetc_setup_mac_addresses(struct device_node *np, struct enetc_pf*pf);
drivers/net/ethernet/freescale/enetc/enetc_pf.h struct enetc_pf {
Quoted 5 lines
drivers/net/ethernet/freescale/enetc/enetc_pf.h +5
-0+void enetc_pf_netdev_setup (struct enetc_si *si,struct net_device *ndev, +const struct net_device_ops *ndev_ops); +int enetc_mdiobus_create (struct enetc_pf *pf,struct device_node *node); +void enetc_mdiobus_destroy (struct enetc_pf *pf); +int enetc_phylink_create(struct enetc_ndev_priv *priv, struct device_node*node,
Quoted 8 lines
drivers/net/ethernet/freescale/enetc/enetc_pf.h struct enetc_pf { · line 73
Quoted 2 lines
drivers/net/ethernet/freescale/enetc/enetc_pf.h +2
-0+ const struct phylink_mac_ops *ops); +void enetc_phylink_destroy (struct enetc_ndev_priv *priv);Could you put the prototypes of functions exported by
enetc_pf_common.cinto a header namedenetc_pf_common.h? It should be self-contained, i.e. a dummy C file with just #include "enetc_pf_common.h" in it should compile fine.
Sure, I'll add a new header file.
Quoted 2 lines
I know the enetc driver isn't there yet when it comes to thoroughly respecting that, but for code we touch now, we should try to follow it.
kernel test robot
build botRe: [PATCH v5 net-next 05/13] net: enetc: extract common ENETC PF parts for LS1028A and i.MX95 platforms
In reply to Wei Fangkernel test robot noticed the following build errors:
Hi Wei,
kernel test robot noticed the following build errors:
[auto build test ERROR on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Wei-Fang/dt-bindings-net-add-compatible-string-for-i-MX95-EMDIO/20241024-151502 base: net-next/main patch link: https://lore.kernel.org/r/20241024065328.521518-6-wei.fang%40nxp.com patch subject: [PATCH v5 net-next 05/13] net: enetc: extract common ENETC PF parts for LS1028A and i.MX95 platforms config: x86_64-buildonly-randconfig-001-20241026 (https://download.01.org/0day-ci/archive/20241026/[email protected]/config) compiler: clang version 19.1.2 (https://github.com/llvm/llvm-project 7ba7d8e2f7b6445b60679da826210cdde29eaf8b) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241026/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from drivers/net/ethernet/freescale/enetc/enetc_pf.c:7:
In file included from include/linux/of_net.h:9:
In file included from include/linux/phy.h:16:
In file included from include/linux/ethtool.h:18:
In file included from include/linux/if_ether.h:19:
In file included from include/linux/skbuff.h:17:
In file included from include/linux/bvec.h:10:
In file included from include/linux/highmem.h:8:
In file included from include/linux/cacheflush.h:5:
In file included from arch/x86/include/asm/cacheflush.h:5:
In file included from include/linux/mm.h:2213:
include/linux/vmstat.h:518:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
518 | return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
| ~~~~~~~~~~~ ^ ~~~
>> drivers/net/ethernet/freescale/enetc/enetc_pf.c:906:14: error: call to undeclared function 'of_find_compatible_node'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
906 | ierb_node = of_find_compatible_node(NULL, NULL,
| ^
>> drivers/net/ethernet/freescale/enetc/enetc_pf.c:906:12: error: incompatible integer to pointer conversion assigning to 'struct device_node *' from 'int' [-Wint-conversion]
906 | ierb_node = of_find_compatible_node(NULL, NULL,
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
907 | "fsl,ls1028a-enetc-ierb");
| ~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/net/ethernet/freescale/enetc/enetc_pf.c:908:21: error: call to undeclared function 'of_device_is_available'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
908 | if (!ierb_node || !of_device_is_available(ierb_node))
| ^
>> drivers/net/ethernet/freescale/enetc/enetc_pf.c:912:2: error: call to undeclared function 'of_node_put'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
912 | of_node_put(ierb_node);
| ^
drivers/net/ethernet/freescale/enetc/enetc_pf.c:1115:14: error: call to undeclared function 'of_device_is_available'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
1115 | if (node && of_device_is_available(node))
| ^1 warning and 5 errors generated.
vim +/of_find_compatible_node +906 drivers/net/ethernet/freescale/enetc/enetc_pf.c
07bf34a50e3279 Vladimir Oltean 2021-02-04 900
e7d48e5fbf30f8 Vladimir Oltean 2021-04-17 901 static int enetc_pf_register_with_ierb(struct pci_dev *pdev)
e7d48e5fbf30f8 Vladimir Oltean 2021-04-17 902 {
e7d48e5fbf30f8 Vladimir Oltean 2021-04-17 903 struct platform_device *ierb_pdev;
e7d48e5fbf30f8 Vladimir Oltean 2021-04-17 904 struct device_node *ierb_node;
e7d48e5fbf30f8 Vladimir Oltean 2021-04-17 905
e7d48e5fbf30f8 Vladimir Oltean 2021-04-17 @906 ierb_node = of_find_compatible_node(NULL, NULL,
e7d48e5fbf30f8 Vladimir Oltean 2021-04-17 907 "fsl,ls1028a-enetc-ierb");
e7d48e5fbf30f8 Vladimir Oltean 2021-04-17 @908 if (!ierb_node || !of_device_is_available(ierb_node))
e7d48e5fbf30f8 Vladimir Oltean 2021-04-17 909 return -ENODEV;
e7d48e5fbf30f8 Vladimir Oltean 2021-04-17 910
e7d48e5fbf30f8 Vladimir Oltean 2021-04-17 911 ierb_pdev = of_find_device_by_node(ierb_node);
e7d48e5fbf30f8 Vladimir Oltean 2021-04-17 @912 of_node_put(ierb_node);
e7d48e5fbf30f8 Vladimir Oltean 2021-04-17 913
e7d48e5fbf30f8 Vladimir Oltean 2021-04-17 914 if (!ierb_pdev)
e7d48e5fbf30f8 Vladimir Oltean 2021-04-17 915 return -EPROBE_DEFER;
e7d48e5fbf30f8 Vladimir Oltean 2021-04-17 916
e7d48e5fbf30f8 Vladimir Oltean 2021-04-17 917 return enetc_ierb_register_pf(ierb_pdev, pdev);
e7d48e5fbf30f8 Vladimir Oltean 2021-04-17 918 }
e7d48e5fbf30f8 Vladimir Oltean 2021-04-17 919 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Wei Fang
maintainerPATCH v5 6/13 net: enetc: build enetc_pf_common.c as a separate module
In reply to Wei FangCompile enetc_pf_common.c as a standalone module to allow shared usage between ENETC v1 and v4 PF drivers. Add struct enetc_pf_ops to register different hardware operation interfaces for both ENETC v1 and v4 PF drivers.
---
v5: no changes
--- drivers/net/ethernet/freescale/enetc/Kconfig | 9 ++++ drivers/net/ethernet/freescale/enetc/Makefile | 5 +- .../net/ethernet/freescale/enetc/enetc_pf.c | 26 ++++++++-- .../net/ethernet/freescale/enetc/enetc_pf.h | 21 ++++++-- .../freescale/enetc/enetc_pf_common.c | 50 ++++++++++++++++--- 5 files changed, 96 insertions(+), 15 deletions(-)
drivers/net/ethernet/freescale/enetc/Kconfig +9 -0
@@ -7,6 +7,14 @@ config FSL_ENETC_CORE If compiled as module (M), the module name is fsl-enetc-core. +config NXP_ENETC_PF_COMMON + tristate + help + This module supports common functionality between drivers of + different versions of NXP ENETC PF controllers. + + If compiled as module (M), the module name is nxp-enetc-pf-common. + config FSL_ENETC tristate "ENETC PF driver" depends on PCI_MSI
@@ -14,6 +22,7 @@ config FSL_ENETC select FSL_ENETC_CORE select FSL_ENETC_IERB select FSL_ENETC_MDIO + select NXP_ENETC_PF_COMMON select PHYLINK select PCS_LYNX select DIMLIB
drivers/net/ethernet/freescale/enetc/Makefile +4 -1
@@ -3,8 +3,11 @@ obj-$(CONFIG_FSL_ENETC_CORE) += fsl-enetc-core.o fsl-enetc-core-y := enetc.o enetc_cbdr.o enetc_ethtool.o +obj-$(CONFIG_NXP_ENETC_PF_COMMON) += nxp-enetc-pf-common.o +nxp-enetc-pf-common-y := enetc_pf_common.o + obj-$(CONFIG_FSL_ENETC) += fsl-enetc.o -fsl-enetc-y := enetc_pf.o enetc_pf_common.o +fsl-enetc-y := enetc_pf.o fsl-enetc-$(CONFIG_PCI_IOV) += enetc_msg.o fsl-enetc-$(CONFIG_FSL_ENETC_QOS) += enetc_qos.o
drivers/net/ethernet/freescale/enetc/enetc_pf.c +23 -3
@@ -11,7 +11,7 @@#define ENETC_DRV_NAME_STR "ENETC PF driver" -void enetc_pf_get_primary_mac_addr (struct enetc_hw *hw,int si,u8 *addr) +static void enetc_pf_get_primary_mac_addr (struct enetc_hw *hw,int si,u8 *addr) {u32 upper =__raw_readl (hw->port +ENETC_PSIPMAR0 (si));u16 lower =__raw_readw (hw->port +ENETC_PSIPMAR1 (si));
@@ -20,8 +20,8 @@ void enetc_pf_get_primary_mac_addr(struct enetc_hw *hw, int si, u8 *addr)put_unaligned_le16 (lower, addr +4 ); } -void enetc_pf_set_primary_mac_addr (struct enetc_hw *hw,int si, -const u8 *addr) +static void enetc_pf_set_primary_mac_addr (struct enetc_hw *hw,int si, +const u8 *addr) {u32 upper =get_unaligned_le32 (addr);u16 lower =get_unaligned_le16 (addr +4 );
@@ -30,6 +30,17 @@ void enetc_pf_set_primary_mac_addr(struct enetc_hw *hw, int si,__raw_writew (lower, hw->port +ENETC_PSIPMAR1 (si)); } +static struct phylink_pcs *enetc_pf_create_pcs (struct enetc_pf *pf, +struct mii_bus *bus) +{ +return lynx_pcs_create_mdiodev (bus,0 ); +} + +static void enetc_pf_destroy_pcs (struct phylink_pcs *pcs) +{ +lynx_pcs_destroy (pcs); +} +static void enetc_set_vlan_promisc (struct enetc_hw *hw,char si_map) {u32 val =enetc_port_rd (hw,ENETC_PSIPVMR );
@@ -970,6 +981,14 @@ static void enetc_psi_destroy(struct pci_dev *pdev)enetc_pci_remove (pdev); } +static const struct enetc_pf_ops enetc_pf_ops = { + .set_si_primary_mac = enetc_pf_set_primary_mac_addr, + .get_si_primary_mac = enetc_pf_get_primary_mac_addr, + .create_pcs = enetc_pf_create_pcs, + .destroy_pcs = enetc_pf_destroy_pcs, + .enable_psfp = enetc_psfp_enable, +}; +static int enetc_pf_probe (struct pci_dev *pdev,const struct pci_device_id *ent) {
@@ -997,6 +1016,7 @@ static int enetc_pf_probe(struct pci_dev *pdev, pf =enetc_si_priv (si); pf->si = si; pf->total_vfs =pci_sriov_get_totalvfs (pdev); +enetc_pf_ops_register (pf, &enetc_pf_ops); err =enetc_setup_mac_addresses (node, pf);if (err)
drivers/net/ethernet/freescale/enetc/enetc_pf.h +18 -3
@@ -28,6 +28,16 @@ struct enetc_vf_state {enum enetc_vf_flags flags; }; +struct enetc_pf ; + +struct enetc_pf_ops { +void (*set_si_primary_mac)(struct enetc_hw *hw,int si,const u8 *addr); +void (*get_si_primary_mac)(struct enetc_hw *hw,int si,u8 *addr); +struct phylink_pcs *(*create_pcs)(struct enetc_pf *pf,struct mii_bus *bus); +void (*destroy_pcs)(struct phylink_pcs *pcs); +int (*enable_psfp)(struct enetc_ndev_priv *priv); +}; +struct enetc_pf {struct enetc_si *si;int num_vfs;/* number of active VFs, after sriov_init */
@@ -50,6 +60,8 @@ struct enetc_pf {phy_interface_t if_mode;struct phylink_config phylink_config; + +const struct enetc_pf_ops *ops; };#define phylink_to_enetc_pf (config) \
@@ -59,9 +71,6 @@ int enetc_msg_psi_init(struct enetc_pf *pf);void enetc_msg_psi_free (struct enetc_pf *pf);void enetc_msg_handle_rxmsg (struct enetc_pf *pf,int mbox_id,u16 *status); -void enetc_pf_get_primary_mac_addr (struct enetc_hw *hw,int si,u8 *addr); -void enetc_pf_set_primary_mac_addr (struct enetc_hw *hw,int si, -const u8 *addr);int enetc_pf_set_mac_addr (struct net_device *ndev,void *addr);int enetc_setup_mac_addresses (struct device_node *np,struct enetc_pf *pf); void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
@@ -71,3 +80,9 @@ void enetc_mdiobus_destroy(struct enetc_pf *pf);int enetc_phylink_create (struct enetc_ndev_priv *priv,struct device_node *node,const struct phylink_mac_ops *ops);void enetc_phylink_destroy (struct enetc_ndev_priv *priv); + +static inline void enetc_pf_ops_register (struct enetc_pf *pf, +const struct enetc_pf_ops *ops) +{ + pf->ops = ops; +}
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +42 -8
141 lines not on this page · raw message
Signature · 1 line
2.34.1
Vladimir Oltean
maintainerRe: [PATCH v5 net-next 06/13] net: enetc: build enetc_pf_common.c as a separate module
Quoted 41 lines · Wei Fang
drivers/net/ethernet/freescale/enetc/enetc_pf.h +12
-3@@ -28,6 +28,16 @@ struct enetc_vf_state {enum enetc_vf_flags flags; }; +struct enetc_pf ; + +struct enetc_pf_ops { +void (*set_si_primary_mac)(struct enetc_hw *hw,int si,const u8 *addr); +void (*get_si_primary_mac)(struct enetc_hw *hw,int si,u8 *addr); +struct phylink_pcs *(*create_pcs)(struct enetc_pf *pf,struct mii_bus *bus); +void (*destroy_pcs)(struct phylink_pcs *pcs); +int (*enable_psfp)(struct enetc_ndev_priv *priv); +}; +struct enetc_pf {struct enetc_si *si;int num_vfs;/* number of active VFs, after sriov_init */ @@ -50,6 +60,8 @@ struct enetc_pf {phy_interface_t if_mode;struct phylink_config phylink_config; + +const struct enetc_pf_ops *ops; };#define phylink_to_enetc_pf (config) \@@ -59,9 +71,6 @@ int enetc_msg_psi_init(struct enetc_pf *pf);void enetc_msg_psi_free (struct enetc_pf *pf);void enetc_msg_handle_rxmsg (struct enetc_pf *pf,int mbox_id,u16 *status); -void enetc_pf_get_primary_mac_addr (struct enetc_hw *hw,int si,u8 *addr); -void enetc_pf_set_primary_mac_addr (struct enetc_hw *hw,int si, -const u8 *addr);int enetc_pf_set_mac_addr (struct net_device *ndev,void *addr);int enetc_setup_mac_addresses (struct device_node *np,struct enetc_pf *pf); void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
drivers/net/ethernet/freescale/enetc/enetc_pf.h void enetc_mdiobus_destroy(struct enetc_pf *pf); · line 88
Quoted 9 lines
drivers/net/ethernet/freescale/enetc/enetc_pf.h +6
-0@@ -71,3 +80,9 @@ void enetc_mdiobus_destroy(struct enetc_pf *pf);int enetc_phylink_create (struct enetc_ndev_priv *priv,struct device_node *node,const struct phylink_mac_ops *ops);void enetc_phylink_destroy (struct enetc_ndev_priv *priv); + +static inline void enetc_pf_ops_register (struct enetc_pf *pf, +const struct enetc_pf_ops *ops) +{ + pf->ops = ops; +}
I think this is more confusing than helpful? "register" suggests there should also be an "unregister" coming. Either "set" or just open-code the assignment?
Quoted 8 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +0
-0@@ -8,19 +8,37 @@#include "enetc_pf.h"
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c line 20
Quoted 10 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +10
-0+static int enetc_set_si_hw_addr (struct enetc_pf *pf,int si,u8 *mac_addr) +{ +struct enetc_hw *hw = &pf->si->hw; + +if (pf->ops->set_si_primary_mac) + pf->ops->set_si_primary_mac (hw, si, mac_addr); +else +return -EOPNOTSUPP ; + +return 0 ;
Don't artificially create errors when there are really no errors to handle. Both enetc_pf_ops and enetc4_pf_ops provide .set_si_primary_mac(), so it is unnecessary to handle the case where it isn't present. Those functions return void, and void can be propagated to enetc_set_si_hw_addr() as well.
Quoted 8 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +4
-0+} +int enetc_pf_set_mac_addr (struct net_device *ndev,void *addr) {struct enetc_ndev_priv *priv =netdev_priv (ndev); +struct enetc_pf *pf =enetc_si_priv (priv->si);struct sockaddr *saddr = addr; +int err;
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c line 20
Quoted 10 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +4
-1if (!is_valid_ether_addr (saddr->sa_data))return -EADDRNOTAVAIL ; + err =enetc_set_si_hw_addr (pf,0 , saddr->sa_data); +if (err) +return err; +eth_hw_addr_set (ndev, saddr->sa_data); -enetc_pf_set_primary_mac_addr (&priv->si->hw,0 , saddr->sa_data);
This isn't one for one replacement, it also moves the function call relative to eth_hw_addr_set() without making any mention about that movement being safe. And even if safe, it is logically a separate change which deserves its own merit analysis in another patch (if there's no merit, leave it where it is).
I believe the merit was: enetc_set_si_hw_addr() can return error, thus we simplify the control flow if we call it prior to eth_hw_addr_set() - nothing to unroll. But as explained above, enetc_set_si_hw_addr() cannot actually fail, so there is no real merit.
Quoted 8 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +1
-0return 0 ; } +EXPORT_SYMBOL_GPL (enetc_pf_set_mac_addr);static int enetc_setup_mac_address (struct device_node *np,struct enetc_pf *pf,int si)
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c static int enetc_setup_mac_address(struct device_node *np, struct enetc_pf *pf, · line 60
Quoted 7 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +2
-2@@ -38,8 +56,8 @@ static int enetc_setup_mac_address(struct device_node *np, struct enetc_pf *pf, }/* (2) bootloader supplied MAC address */ -if (is_zero_ether_addr (mac_addr)) -enetc_pf_get_primary_mac_addr (hw, si, mac_addr); +if (is_zero_ether_addr (mac_addr) && pf->ops->get_si_primary_mac) + pf->ops->get_si_primary_mac (hw, si, mac_addr);
Again, if there's no reason for the method to be optional (both PF drivers support it), don't make it optional.
A bit inconsistent that pf->ops->set_si_primary_mac() goes through a wrapper function but this doesn't.
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c static int enetc_setup_mac_address(struct device_node *np, struct enetc_pf *pf, · line 71
Quoted 11 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +3
-1/* (3) choose a random one */ if (is_zero_ether_addr (mac_addr)) {@@ -48,7 +66,9 @@ static int enetc_setup_mac_address(struct device_node *np, struct enetc_pf *pf, si, mac_addr); } -enetc_pf_set_primary_mac_addr (hw, si, mac_addr); + err =enetc_set_si_hw_addr (pf, si, mac_addr); +if (err) +return err;
This should go back to normal (no "err = ...; if (err) return err") once the function is made void.
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev, · line 133
Quoted 10 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +2
-1return 0 ; }@@ -107,7 +129,8 @@ void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,NETDEV_XDP_ACT_NDO_XMIT |NETDEV_XDP_ACT_RX_SG |NETDEV_XDP_ACT_NDO_XMIT_SG ; -if (si->hw_features &ENETC_SI_F_PSFP && !enetc_psfp_enable (priv)) { +if (si->hw_features &ENETC_SI_F_PSFP && pf->ops->enable_psfp && + !pf->ops->enable_psfp (priv)) {
This one looks extremely weird in the existing code, but I suppose I'm too late to the party to request you to clean up any of the PSFP code, so I'll make a note to do it myself after your work. I haven't spotted any actual bug, just weird coding patterns.
No change request here. I see the netc4_pf doesn't implement enable_psfp(), so making it optional here is fine.
Quoted 12 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +1
-0priv->active_offloads |=ENETC_F_QCI ; ndev->features |=NETIF_F_HW_TC ; ndev->hw_features |=NETIF_F_HW_TC ;@@ -116,6 +139,7 @@ void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,/* pick up primary MAC address from SI */ enetc_load_primary_mac_addr (&si->hw, ndev); } +EXPORT_SYMBOL_GPL (enetc_pf_netdev_setup);static int enetc_mdio_probe (struct enetc_pf *pf,struct device_node *np) {
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c static int enetc_imdio_create(struct enetc_pf *pf) · line 191
Quoted 6 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +3
-0@@ -162,6 +186,9 @@ static int enetc_imdio_create(struct enetc_pf *pf)struct mii_bus *bus;int err; +if (!pf->ops->create_pcs) +return -EOPNOTSUPP ; +
I don't understand how this works. You don't implement create_pcs() for netc4_pf until the very end of the series. Probing will fail for SerDes interfaces (enetc_port_has_pcs() returns true) and that's fine?
A message maybe, stating what's the deal? Just that users figure out quickly that it's an expected behavior, and not spend hours debugging until they find out it's not their fault?
Quoted 3 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +0
-0bus =mdiobus_alloc_size (sizeof (*mdio_priv));if (!bus)return -ENOMEM ;
Wei Fang
maintainerRE: [PATCH v5 net-next 06/13] net: enetc: build enetc_pf_common.c as a separate module
Quoted 37 lines
Quoted 23 lines
drivers/net/ethernet/freescale/enetc/enetc_pf.h +12
-0+struct enetc_pf ; + +struct enetc_pf_ops { +void (*set_si_primary_mac)(struct enetc_hw *hw,int si,const u8 *addr); +void (*get_si_primary_mac)(struct enetc_hw *hw,int si,u8 *addr); +struct phylink_pcs *(*create_pcs)(struct enetc_pf *pf,struct mii_bus *bus); +void (*destroy_pcs)(struct phylink_pcs *pcs); +int (*enable_psfp)(struct enetc_ndev_priv *priv); +}; +struct enetc_pf {struct enetc_si *si;int num_vfs;/* number of active VFs, after sriov_init */ @@ -50,6 +60,8 @@ struct enetc_pf {phy_interface_t if_mode;struct phylink_config phylink_config; + +const struct enetc_pf_ops *ops; };#define phylink_to_enetc_pf (config) \drivers/net/ethernet/freescale/enetc/enetc_pf.h int enetc_msg_psi_init(struct enetc_pf *pf); · line 72
Quoted 2 lines
drivers/net/ethernet/freescale/enetc/enetc_pf.h +0
-0@@ -59,9 +71,6 @@ int enetc_msg_psi_init(struct enetc_pf *pf);void enetc_msg_psi_free (struct enetc_pf *pf); void enetc_msg_handle_rxmsg(struct enetc_pf *pf, int mbox_id, u16*status);
drivers/net/ethernet/freescale/enetc/enetc_pf.h int enetc_msg_psi_init(struct enetc_pf *pf);
Quoted 6 lines
drivers/net/ethernet/freescale/enetc/enetc_pf.h +0
-3-void enetc_pf_get_primary_mac_addr (struct enetc_hw *hw,int si,u8 *addr); -void enetc_pf_set_primary_mac_addr (struct enetc_hw *hw,int si, -const u8 *addr);int enetc_pf_set_mac_addr (struct net_device *ndev,void *addr); int enetc_setup_mac_addresses(struct device_node *np, struct enetc_pf*pf);
Review void enetc_mdiobus_destroy(struct enetc_pf *pf); · line 80
Quoted 3 lines
(quoted diff) +0
-0void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,@@ -71,3 +80,9 @@ void enetc_mdiobus_destroy(struct enetc_pf *pf); int enetc_phylink_create(struct enetc_ndev_priv *priv, struct device_node*node,
Quoted 12 lines
drivers/net/ethernet/freescale/enetc/enetc_pf.h void enetc_mdiobus_destroy(struct enetc_pf *pf); · line 88
Quoted 8 lines
drivers/net/ethernet/freescale/enetc/enetc_pf.h +6
-0const struct phylink_mac_ops *ops);void enetc_phylink_destroy (struct enetc_ndev_priv *priv); + +static inline void enetc_pf_ops_register (struct enetc_pf *pf, +const struct enetc_pf_ops *ops) +{ + pf->ops = ops; +}I think this is more confusing than helpful? "register" suggests there should also be an "unregister" coming. Either "set" or just open-code the assignment?
Okay, I can remove this helper function, just use open-code.
Quoted 10 lines
Review
Quoted 2 lines
(quoted diff) +0
-0
b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.cQuoted 7 lines
index
bce81a4f6f88..94690ed92e3f100644drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +0
-0@@ -8,19 +8,37 @@#include "enetc_pf.h"
Quoted 16 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c line 20
Quoted 10 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +10
-0+static int enetc_set_si_hw_addr (struct enetc_pf *pf,int si,u8 *mac_addr) +{ +struct enetc_hw *hw = &pf->si->hw; + +if (pf->ops->set_si_primary_mac) + pf->ops->set_si_primary_mac (hw, si, mac_addr); +else +return -EOPNOTSUPP ; + +return 0 ;Don't artificially create errors when there are really no errors to handle. Both
enetc_pf_opsandenetc4_pf_opsprovide .set_si_primary_mac(), so it is unnecessary to handle the case where it isn't present. Those functions return void, and void can be propagated toenetc_set_si_hw_addr()as well.
I thought checking the pointer is safer, so you mean that pointers that are definitely present in the current driver do not need to be checked?
Quoted 51 lines
Quoted 8 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +4
-0+} +int enetc_pf_set_mac_addr (struct net_device *ndev,void *addr) {struct enetc_ndev_priv *priv =netdev_priv (ndev); +struct enetc_pf *pf =enetc_si_priv (priv->si);struct sockaddr *saddr = addr; +int err;drivers/net/ethernet/freescale/enetc/enetc_pf_common.c line 20
Quoted 10 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +4
-1if (!is_valid_ether_addr (saddr->sa_data))return -EADDRNOTAVAIL ; + err =enetc_set_si_hw_addr (pf,0 , saddr->sa_data); +if (err) +return err; +eth_hw_addr_set (ndev, saddr->sa_data); -enetc_pf_set_primary_mac_addr (&priv->si->hw,0 , saddr->sa_data);This isn't one for one replacement, it also moves the function call relative to
eth_hw_addr_set()without making any mention about that movement being safe. And even if safe, it is logically a separate change which deserves its own merit analysis in another patch (if there's no merit, leave it where it is).I believe the merit was:
enetc_set_si_hw_addr()can return error, thus we simplify the control flow if we call it prior toeth_hw_addr_set()- nothing to unroll. But as explained above,enetc_set_si_hw_addr()cannot actually fail, so there is no real merit.drivers/net/ethernet/freescale/enetc/enetc_pf_common.c
Quoted 6 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +1
-0return 0 ; } +EXPORT_SYMBOL_GPL (enetc_pf_set_mac_addr); static int enetc_setup_mac_address(struct device_node *np, struct
enetc_pf*pf,drivers/net/ethernet/freescale/enetc/enetc_pf_common.c static int enetc_setup_mac_address(struct device_node
Quoted 2 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +0
-0int si)@@ -38,8 +56,8 @@ static int enetc_setup_mac_address(struct device_node*np, struct
enetc_pf*pf,drivers/net/ethernet/freescale/enetc/enetc_pf_common.c static int enetc_setup_mac_address(struct device_node *np, struct enetc_pf *pf, · line 60
Quoted 7 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +2
-2}/* (2) bootloader supplied MAC address */ -if (is_zero_ether_addr (mac_addr)) -enetc_pf_get_primary_mac_addr (hw, si, mac_addr); +if (is_zero_ether_addr (mac_addr) && pf->ops->get_si_primary_mac) + pf->ops->get_si_primary_mac (hw, si, mac_addr);Again, if there's no reason for the method to be optional (both PF drivers support it), don't make it optional.
Quoted 3 lines
A bit inconsistent that
pf->ops->set_si_primary_mac()goes through a wrapper function but this doesn't.
If we really do not need to check these callback pointers, then I think I can remove the wrapper.
Quoted 34 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c static int enetc_setup_mac_address(struct device_node
Quoted 4 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +0
-0/* (3) choose a random one */ if (is_zero_ether_addr (mac_addr)) {@@ -48,7 +66,9 @@ static int enetc_setup_mac_address(struct device_node*np, struct
enetc_pf*pf,drivers/net/ethernet/freescale/enetc/enetc_pf_common.c static int enetc_setup_mac_address(struct device_node *np, struct enetc_pf *pf, · line 71
Quoted 7 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +3
-1si, mac_addr); } -enetc_pf_set_primary_mac_addr (hw, si, mac_addr); + err =enetc_set_si_hw_addr (pf, si, mac_addr); +if (err) +return err;This should go back to normal (no "err = ...; if (err) return err") once the function is made void.
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c void enetc_pf_netdev_setup(struct enetc_si *si,
Quoted 4 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +0
-0return 0 ; }@@ -107,7 +129,8 @@ void enetc_pf_netdev_setup(struct enetc_si *si,struct
net_device*ndev,drivers/net/ethernet/freescale/enetc/enetc_pf_common.c void enetc_pf_netdev_setup(struct enetc_si *si, · line 129
Quoted 1 line
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +0
-0NETDEV_XDP_ACT_NDO_XMIT |
NETDEV_XDP_ACT_RX_SG|drivers/net/ethernet/freescale/enetc/enetc_pf_common.c void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev, · line 133
Quoted 5 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +2
-1NETDEV_XDP_ACT_NDO_XMIT_SG ; -if (si->hw_features &ENETC_SI_F_PSFP && !enetc_psfp_enable (priv)) { +if (si->hw_features &ENETC_SI_F_PSFP && pf->ops->enable_psfp && + !pf->ops->enable_psfp (priv)) {This one looks extremely weird in the existing code, but I suppose I'm too late to the party to request you to clean up any of the PSFP code, so I'll make a note to do it myself after your work. I haven't spotted any actual bug, just weird coding patterns.
Quoted 2 lines
No change request here. I see the
netc4_pfdoesn't implementenable_psfp(), so making it optional here is fine.
Yes, PSFP is not supported in this patch set, I will remove it in future.
Quoted 17 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c void enetc_pf_netdev_setup(struct enetc_si *si,
Quoted 5 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +0
-0priv->active_offloads |=ENETC_F_QCI ; ndev->features |=NETIF_F_HW_TC ; ndev->hw_features |=NETIF_F_HW_TC ;@@ -116,6 +139,7 @@ void enetc_pf_netdev_setup(struct enetc_si *si,struct
net_device*ndev,Quoted 11 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +1
-0/* pick up primary MAC address from SI */ enetc_load_primary_mac_addr (&si->hw, ndev); } +EXPORT_SYMBOL_GPL (enetc_pf_netdev_setup);static int enetc_mdio_probe (struct enetc_pf *pf,struct device_node *np) {@@ -162,6 +186,9 @@ static int enetc_imdio_create(struct enetc_pf *pf)struct mii_bus *bus;int err;
Quoted 8 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c static int enetc_imdio_create(struct enetc_pf *pf) · line 191
Quoted 3 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +3
-0+if (!pf->ops->create_pcs) +return -EOPNOTSUPP ; +I don't understand how this works. You don't implement
create_pcs()fornetc4_pfuntil the very end of the series. Probing will fail for SerDes interfaces (enetc_port_has_pcs()returns true) and that's fine?
Currently, we have not add the PCS support, so the 10G ENETC is not supported yet. And we also disable the 10G ENETC in DTS. Only the 1G ENETCs (without PCS) are supported for i.MX95.
Quoted 3 lines
A message maybe, stating what's the deal? Just that users figure out quickly that it's an expected behavior, and not spend hours debugging until they find out it's not their fault?
I will explain in the commit message that i.MX95 10G ENETC is not currently supported.
Quoted 4 lines
Quoted 4 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +0
-0bus =mdiobus_alloc_size (sizeof (*mdio_priv));if (!bus)return -ENOMEM ;
Vladimir Oltean
maintainerRe: [PATCH v5 net-next 06/13] net: enetc: build enetc_pf_common.c as a separate module
Quoted 7 lines · Wei Fang
Quoted 4 lines
Don't artificially create errors when there are really no errors to handle. Both
enetc_pf_opsandenetc4_pf_opsprovide .set_si_primary_mac(), so it is unnecessary to handle the case where it isn't present. Those functions return void, and void can be propagated toenetc_set_si_hw_addr()as well.I thought checking the pointer is safer, so you mean that pointers that are definitely present in the current driver do not need to be checked?
Yes, there is no point to check for a condition which is impossible to trigger in the current code. The callee and the caller are tightly coupled (in the same driver), it's not a rigid API, so if the function pointers should be made optional for some future hardware IP, the error handling will be added when necessary. Ideally any change passes through review, and any inconsistency should be spotted when added.
Quoted 6 lines
Quoted 3 lines
A bit inconsistent that
pf->ops->set_si_primary_mac()goes through a wrapper function but this doesn't.If we really do not need to check these callback pointers, then I think I can remove the wrapper.
Fine without wrapping throughout, my comment was first and foremost about consistency.
Quoted 9 lines
Quoted 7 lines
This one looks extremely weird in the existing code, but I suppose I'm too late to the party to request you to clean up any of the PSFP code, so I'll make a note to do it myself after your work. I haven't spotted any actual bug, just weird coding patterns.
No change request here. I see the
netc4_pfdoesn't implementenable_psfp(), so making it optional here is fine.Yes, PSFP is not supported in this patch set, I will remove it in future.
If by "I will remove it in future" you mean "once NETC4 gains PSFP support, I will make enable_psfp() non-optional", then ok, great.
Quoted 3 lines
Currently, we have not add the PCS support, so the 10G ENETC is not supported yet. And we also disable the 10G ENETC in DTS. Only the 1G ENETCs (without PCS) are supported for i.MX95.
Also think about the case where the current version of the kernel will boot on a newer version of the device tree, which does not have 'status = "disabled";' for those ports. It should do something reasonable. In any case, "they're now disabled in the device tree" is not an argument.
My anecdotal and vague understanding of the Arm SystemReady (IR I think) requirements is that the device tree is provided by the platform, separately from the kernel/rootfs. It relies on the device tree ABI being stable, backwards-compatible and forwards-compatible.
Quoted 6 lines
Quoted 3 lines
A message maybe, stating what's the deal? Just that users figure out quickly that it's an expected behavior, and not spend hours debugging until they find out it's not their fault?
I will explain in the commit message that i.MX95 10G ENETC is not currently supported.
By "a message, maybe" I actually meant dev_err("Message here\n"); rather than silent/imprecise failure.
Wei Fang
maintainerRE: [PATCH v5 net-next 06/13] net: enetc: build enetc_pf_common.c as a separate module
Quoted 42 lines · Wei Fang
Quoted 7 lines
Quoted 4 lines
Don't artificially create errors when there are really no errors to handle. Both
enetc_pf_opsandenetc4_pf_opsprovide .set_si_primary_mac(), so it is unnecessary to handle the case where it isn't present. Those functions return void, and void can be propagated toenetc_set_si_hw_addr()as well.I thought checking the pointer is safer, so you mean that pointers that are definitely present in the current driver do not need to be checked?
Yes, there is no point to check for a condition which is impossible to trigger in the current code. The callee and the caller are tightly coupled (in the same driver), it's not a rigid API, so if the function pointers should be made optional for some future hardware IP, the error handling will be added when necessary. Ideally any change passes through review, and any inconsistency should be spotted when added.
Quoted 6 lines
Quoted 3 lines
A bit inconsistent that
pf->ops->set_si_primary_mac()goes through a wrapper function but this doesn't.If we really do not need to check these callback pointers, then I think I can remove the wrapper.
Fine without wrapping throughout, my comment was first and foremost about consistency.
Quoted 6 lines
Quoted 6 lines
This one looks extremely weird in the existing code, but I suppose I'm too late to the party to request you to clean up any of the PSFP code, so I'll make a note to do it myself after your work. I haven't spotted any actual bug, just weird coding patterns.
No change request here. I see the
netc4_pfdoesn't implement
enable_psfp(),Quoted 3 lines
Quoted 1 line
so making it optional here is fine.
Yes, PSFP is not supported in this patch set, I will remove it in future.
If by "I will remove it in future" you mean "once NETC4 gains PSFP support, I will make
enable_psfp()non-optional", then ok, great.Quoted 1 line
Currently, we have not add the PCS support, so the 10G ENETC is not
supported
Quoted 9 lines
Quoted 1 line
yet. And we also disable the 10G ENETC in DTS. Only the 1G ENETCs (without
PCS)
Quoted 1 line
are supported for i.MX95.
Also think about the case where the current version of the kernel will boot on a newer version of the device tree, which does not have 'status = "disabled";' for those ports. It should do something reasonable. In any case, "they're now disabled in the device tree" is not an argument.
For this case where the kernel is lower but the device tree is newer, I think there is no problem. It just fails in probe() and does not affect other functions. The old kernel does not support PCS, it is reasonable to return a '- EOPNOTSUPP' error.
Quoted 9 lines
My anecdotal and vague understanding of the Arm SystemReady (IR I think) requirements is that the device tree is provided by the platform, separately from the kernel/rootfs. It relies on the device tree ABI being stable, backwards-compatible and forwards-compatible.
Quoted 4 lines
Quoted 3 lines
A message maybe, stating what's the deal? Just that users figure out quickly that it's an expected behavior, and not spend hours debugging until they find out it's not their fault?
Quoted 5 lines
Quoted 2 lines
I will explain in the commit message that i.MX95 10G ENETC is not currently supported.
By "a message, maybe" I actually meant
dev_err("Message here\n"); rather than silent/imprecise failure.
Okay, I'll add an explicit error message.
Wei Fang
maintainerPATCH v5 7/13 net: enetc: remove ERR050089 workaround for i.MX95
In reply to Wei FangFrom: Vladimir Oltean <[email protected]>
The ERR050089 workaround causes performance degradation and potential functional issues (e.g., RCU stalls) under certain workloads. Since new SoCs like i.MX95 do not require this workaround, use a static key to compile out enetc_lock_mdio() and enetc_unlock_mdio() at runtime, improving performance and avoiding unnecessary logic.
---
v5: no changes
--- .../net/ethernet/freescale/enetc/enetc_hw.h | 34 +++++++++++++------ .../ethernet/freescale/enetc/enetc_pci_mdio.c | 17 ++++++++++ 2 files changed, 41 insertions(+), 10 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc_hw.h +24 -10
@@ -396,18 +396,22 @@ struct enetc_hw {*/ extern rwlock_t enetc_mdio_lock; +DECLARE_STATIC_KEY_FALSE (enetc_has_err050089); +/* use this locking primitive only on the fast datapath to * group together multiple non-MDIO register accesses to * minimize the overhead of the lock */ static inline void enetc_lock_mdio (void ) { -read_lock (&enetc_mdio_lock); +if (static_branch_unlikely (&enetc_has_err050089)) +read_lock (&enetc_mdio_lock); }static inline void enetc_unlock_mdio (void ) { -read_unlock (&enetc_mdio_lock); +if (static_branch_unlikely (&enetc_has_err050089)) +read_unlock (&enetc_mdio_lock); }/* use these accessors only on the fast datapath under
@@ -416,14 +420,16 @@ static inline void enetc_unlock_mdio(void)*/ static inline u32 enetc_rd_reg_hot (void __iomem *reg) { -lockdep_assert_held (&enetc_mdio_lock); +if (static_branch_unlikely (&enetc_has_err050089)) +lockdep_assert_held (&enetc_mdio_lock);return ioread32 (reg); }static inline void enetc_wr_reg_hot (void __iomem *reg,u32 val) { -lockdep_assert_held (&enetc_mdio_lock); +if (static_branch_unlikely (&enetc_has_err050089)) +lockdep_assert_held (&enetc_mdio_lock);iowrite32 (val, reg); }
@@ -452,9 +458,13 @@ static inline u32 _enetc_rd_mdio_reg_wa(void __iomem *reg)unsigned long flags;u32 val; -write_lock_irqsave (&enetc_mdio_lock, flags); - val =ioread32 (reg); -write_unlock_irqrestore (&enetc_mdio_lock, flags); +if (static_branch_unlikely (&enetc_has_err050089)) { +write_lock_irqsave (&enetc_mdio_lock, flags); + val =ioread32 (reg); +write_unlock_irqrestore (&enetc_mdio_lock, flags); + }else { + val =ioread32 (reg); + }return val; }
@@ -463,9 +473,13 @@ static inline void _enetc_wr_mdio_reg_wa(void __iomem *reg, u32 val) {unsigned long flags; -write_lock_irqsave (&enetc_mdio_lock, flags); -iowrite32 (val, reg); -write_unlock_irqrestore (&enetc_mdio_lock, flags); +if (static_branch_unlikely (&enetc_has_err050089)) { +write_lock_irqsave (&enetc_mdio_lock, flags); +iowrite32 (val, reg); +write_unlock_irqrestore (&enetc_mdio_lock, flags); + }else { +iowrite32 (val, reg); + } }#ifdef ioread64
drivers/net/ethernet/freescale/enetc/enetc_pci_mdio.c +17 -0
@@ -9,6 +9,9 @@#define ENETC_MDIO_BUS_NAME ENETC_MDIO_DEV_NAME " Bus"#define ENETC_MDIO_DRV_NAME ENETC_MDIO_DEV_NAME " driver" +DEFINE_STATIC_KEY_FALSE (enetc_has_err050089); +EXPORT_SYMBOL_GPL (enetc_has_err050089); +static int enetc_pci_mdio_probe (struct pci_dev *pdev,const struct pci_device_id *ent) {
@@ -62,6 +65,12 @@ static int enetc_pci_mdio_probe(struct pci_dev *pdev, goto err_pci_mem_reg; } +if (pdev->vendor ==PCI_VENDOR_ID_FREESCALE && + pdev->device ==ENETC_MDIO_DEV_ID ) { +static_branch_inc (&enetc_has_err050089); +dev_info (&pdev->dev,"Enabled ERR050089 workaround\n" ); + } + err =of_mdiobus_register (bus, dev->of_node);if (err) goto err_mdiobus_reg;
@@ -88,6 +97,14 @@ static void enetc_pci_mdio_remove(struct pci_dev *pdev)struct enetc_mdio_priv *mdio_priv;mdiobus_unregister (bus); + +if (pdev->vendor ==PCI_VENDOR_ID_FREESCALE && + pdev->device ==ENETC_MDIO_DEV_ID ) { +static_branch_dec (&enetc_has_err050089); +if (!static_key_enabled (&enetc_has_err050089.key)) +dev_info (&pdev->dev,"Disabled ERR050089 workaround\n" ); + } + mdio_priv = bus->priv;iounmap (mdio_priv->hw->port);pci_release_region (pdev,0 );
Signature · 1 line
2.34.1
Vladimir Oltean
maintainerRe: [PATCH v5 net-next 07/13] net: enetc: remove ERR050089 workaround for i.MX95
drivers/net/ethernet/freescale/enetc/enetc_pci_mdio.c static int enetc_pci_mdio_probe(struct pci_dev *pdev, · line 76
Quoted 13 lines · Wei Fang
drivers/net/ethernet/freescale/enetc/enetc_pci_mdio.c +6
-0@@ -62,6 +65,12 @@ static int enetc_pci_mdio_probe(struct pci_dev *pdev, goto err_pci_mem_reg; } +if (pdev->vendor ==PCI_VENDOR_ID_FREESCALE && + pdev->device ==ENETC_MDIO_DEV_ID ) { +static_branch_inc (&enetc_has_err050089); +dev_info (&pdev->dev,"Enabled ERR050089 workaround\n" ); + } + err =of_mdiobus_register (bus, dev->of_node);if (err) goto err_mdiobus_reg;
If of_mdiobus_register() fails, we should disable the static key.
Perhaps the snippets to enable and disable the static key should be in helper functions to more easily insert the error teardown logic.
Wei Fang
maintainerRE: [PATCH v5 net-next 07/13] net: enetc: remove ERR050089 workaround for i.MX95
Quoted 18 lines · Wei Fang
drivers/net/ethernet/freescale/enetc/enetc_pci_mdio.c static int enetc_pci_mdio_probe(struct pci_dev *pdev, · line 76
Quoted 13 lines
drivers/net/ethernet/freescale/enetc/enetc_pci_mdio.c +6
-0@@ -62,6 +65,12 @@ static int enetc_pci_mdio_probe(struct pci_dev *pdev, goto err_pci_mem_reg; } +if (pdev->vendor ==PCI_VENDOR_ID_FREESCALE && + pdev->device ==ENETC_MDIO_DEV_ID ) { +static_branch_inc (&enetc_has_err050089); +dev_info (&pdev->dev,"Enabled ERR050089 workaround\n" ); + } + err =of_mdiobus_register (bus, dev->of_node);if (err) goto err_mdiobus_reg;If
of_mdiobus_register()fails, we should disable the static key.
Quoted 2 lines
Perhaps the snippets to enable and disable the static key should be in helper functions to more easily insert the error teardown logic.
Okay, I will refine it
Wei Fang
maintainerPATCH v5 8/13 PCI: Add NXP NETC vendor ID and device IDs
In reply to Wei FangNXP NETC is a multi-function RCiEP and it contains multiple functions, such as EMDIO, PTP Timer, ENETC PF and VF. Therefore, add these device IDs to pci_ids.h.
Below are the device IDs and corresponding drivers. PCI_DEVICE_ID_NXP2_ENETC_PF: nxp-enetc4 PCI_DEVICE_ID_NXP2_NETC_EMDIO: fsl-enetc-mdio PCI_DEVICE_ID_NXP2_NETC_TIMER: ptp_netc PCI_DEVICE_ID_NXP2_ENETC_VF: fsl-enetc-vf
---
v5: no changes
--- include/linux/pci_ids.h | 7 +++++++ 1 file changed, 7 insertions(+)
include/linux/pci_ids.h +7 -0
@@ -1556,6 +1556,13 @@#define PCI_DEVICE_ID_PHILIPS_SAA7146 0x7146#define PCI_DEVICE_ID_PHILIPS_SAA9730 0x9730 +/* NXP has two vendor IDs, the other one is 0x1957 */ +#define PCI_VENDOR_ID_NXP2 PCI_VENDOR_ID_PHILIPS +#define PCI_DEVICE_ID_NXP2_ENETC_PF 0xe101 +#define PCI_DEVICE_ID_NXP2_NETC_EMDIO 0xee00 +#define PCI_DEVICE_ID_NXP2_NETC_TIMER 0xee02 +#define PCI_DEVICE_ID_NXP2_ENETC_VF 0xef00 +#define PCI_VENDOR_ID_EICON 0x1133#define PCI_DEVICE_ID_EICON_DIVA20 0xe002#define PCI_DEVICE_ID_EICON_DIVA20_U 0xe004
Signature · 1 line
2.34.1
Re: [PATCH v5 net-next 08/13] PCI: Add NXP NETC vendor ID and device IDs
Quoted 4 lines · Wei Fang
NXP NETC is a multi-function RCiEP and it contains multiple functions, such as EMDIO, PTP Timer, ENETC PF and VF. Therefore, add these device IDs to
pci_ids.h.
Quoted 8 lines
Below are the device IDs and corresponding drivers.
PCI_DEVICE_ID_NXP2_ENETC_PF: nxp-enetc4PCI_DEVICE_ID_NXP2_NETC_EMDIO: fsl-enetc-mdioPCI_DEVICE_ID_NXP2_NETC_TIMER:ptp_netcPCI_DEVICE_ID_NXP2_ENETC_VF: fsl-enetc-vfSigned-off-by Wei Fang <[email protected]>Acked-by Bjorn Helgaas <[email protected]>
Please drop my ack. I don't think these meet the spirit of the guidance in pci_ids.h, which is there to minimize churn in that file and make backports easier:
* Do not add new entries to this file unless the definitions
* are shared between multiple drivers.
PCI_DEVICE_ID_NXP2_NETC_TIMER and PCI_DEVICE_ID_NXP2_ENETC_VF aren't used at all by this series, so they shouldn't be added to pci_ids.h.
PCI_DEVICE_ID_NXP2_NETC_EMDIO is used only by drivers/net/ethernet/freescale/enetc/enetc_pci_mdio.c, so it should be defined there, not in pci_ids.h.
PCI_DEVICE_ID_NXP2_ENETC_PF is used by enetc.c and enetc4_pf.c, but it looks like those are basically part of the same driver, and it could be defined in enetc4_hw.h or similar.
Quoted 27 lines
---
v5: no changes--- include/linux/pci_ids.h | 7 +++++++ 1 file changed, 7 insertions(+)include/linux/pci_ids.h +7
-0@@ -1556,6 +1556,13 @@#define PCI_DEVICE_ID_PHILIPS_SAA7146 0x7146#define PCI_DEVICE_ID_PHILIPS_SAA9730 0x9730 +/* NXP has two vendor IDs, the other one is 0x1957 */ +#define PCI_VENDOR_ID_NXP2 PCI_VENDOR_ID_PHILIPS +#define PCI_DEVICE_ID_NXP2_ENETC_PF 0xe101 +#define PCI_DEVICE_ID_NXP2_NETC_EMDIO 0xee00 +#define PCI_DEVICE_ID_NXP2_NETC_TIMER 0xee02 +#define PCI_DEVICE_ID_NXP2_ENETC_VF 0xef00 +#define PCI_VENDOR_ID_EICON 0x1133#define PCI_DEVICE_ID_EICON_DIVA20 0xe002#define PCI_DEVICE_ID_EICON_DIVA20_U 0xe004Signature · 1 line
2.34.1
Wei Fang
maintainerRE: [PATCH v5 net-next 08/13] PCI: Add NXP NETC vendor ID and device IDs
Quoted 24 lines · Wei Fang
Quoted 4 lines
NXP NETC is a multi-function RCiEP and it contains multiple functions, such as EMDIO, PTP Timer, ENETC PF and VF. Therefore, add these device IDs to
pci_ids.h.Quoted 8 lines
Below are the device IDs and corresponding drivers.
PCI_DEVICE_ID_NXP2_ENETC_PF: nxp-enetc4PCI_DEVICE_ID_NXP2_NETC_EMDIO: fsl-enetc-mdioPCI_DEVICE_ID_NXP2_NETC_TIMER:ptp_netcPCI_DEVICE_ID_NXP2_ENETC_VF: fsl-enetc-vfSigned-off-by Wei Fang <[email protected]>Acked-by Bjorn Helgaas <[email protected]>Please drop my ack. I don't think these meet the spirit of the guidance in
pci_ids.h, which is there to minimize churn in that file and make backports easier:* Do not add new entries to this file unless the definitions
* are shared between multiple drivers.
PCI_DEVICE_ID_NXP2_NETC_TIMERandPCI_DEVICE_ID_NXP2_ENETC_VFaren't used at all by this series, so they shouldn't be added topci_ids.h.
Quoted 8 lines
PCI_DEVICE_ID_NXP2_NETC_EMDIOis used only bydrivers/net/ethernet/freescale/enetc/enetc_pci_mdio.c, so it should be defined there, not inpci_ids.h.
PCI_DEVICE_ID_NXP2_ENETC_PFis used byenetc.candenetc4_pf.c, but it looks like those are basically part of the same driver, and it could be defined inenetc4_hw.hor similar.
I was not aware of this, I will remove this patch, thanks.
Wei Fang
maintainerPATCH v5 9/13 net: enetc: add i.MX95 EMDIO support
In reply to Wei FangThe verdor ID and device ID of i.MX95 EMDIO are different from LS1028A EMDIO, so add new vendor ID and device ID to pci_device_id table to support i.MX95 EMDIO. And the i.MX95 EMDIO has two pins that need to be controlled, namely MDC and MDIO.
---
v5: no changes
--- drivers/net/ethernet/freescale/enetc/enetc_pci_mdio.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/ethernet/freescale/enetc/enetc_pci_mdio.c +4 -0
@@ -2,6 +2,7 @@/* Copyright 2019 NXP */ #include <linux/fsl/enetc_mdio.h> #include <linux/of_mdio.h> +#include <linux/pinctrl/consumer.h> #include "enetc_pf.h" #define ENETC_MDIO_DEV_ID 0xee01
@@ -71,6 +72,8 @@ static int enetc_pci_mdio_probe(struct pci_dev *pdev,dev_info (&pdev->dev,"Enabled ERR050089 workaround\n" ); } +pinctrl_pm_select_default_state (dev); + err =of_mdiobus_register (bus, dev->of_node);if (err) goto err_mdiobus_reg;
@@ -113,6 +116,7 @@ static void enetc_pci_mdio_remove(struct pci_dev *pdev)static const struct pci_device_id enetc_pci_mdio_id_table[] = { {PCI_DEVICE (PCI_VENDOR_ID_FREESCALE ,ENETC_MDIO_DEV_ID ) }, + {PCI_DEVICE (PCI_VENDOR_ID_NXP2 ,PCI_DEVICE_ID_NXP2_NETC_EMDIO ) }, {0 , }/* End of table. */ };MODULE_DEVICE_TABLE (pci, enetc_pci_mdio_id_table);
Signature · 1 line
2.34.1
Vladimir Oltean
maintainerRe: [PATCH v5 net-next 09/13] net: enetc: add i.MX95 EMDIO support
Quoted 26 lines · Wei Fang
The verdor ID and device ID of i.MX95 EMDIO are different from LS1028A EMDIO, so add new vendor ID and device ID to
pci_device_idtable to support i.MX95 EMDIO. And the i.MX95 EMDIO has two pins that need to be controlled, namely MDC and MDIO.Signed-off-by Wei Fang <[email protected]>Reviewed-by Frank Li <[email protected]>---
v5: no changes--- drivers/net/ethernet/freescale/enetc/enetc_pci_mdio.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/net/ethernet/freescale/enetc/enetc_pci_mdio.c +1
-0@@ -2,6 +2,7 @@/* Copyright 2019 NXP */ #include <linux/fsl/enetc_mdio.h> #include <linux/of_mdio.h> +#include <linux/pinctrl/consumer.h> #include "enetc_pf.h" #define ENETC_MDIO_DEV_ID 0xee01
drivers/net/ethernet/freescale/enetc/enetc_pci_mdio.c static int enetc_pci_mdio_probe(struct pci_dev *pdev, · line 76
Quoted 5 lines
drivers/net/ethernet/freescale/enetc/enetc_pci_mdio.c +2
-0@@ -71,6 +72,8 @@ static int enetc_pci_mdio_probe(struct pci_dev *pdev,dev_info (&pdev->dev,"Enabled ERR050089 workaround\n" ); } +pinctrl_pm_select_default_state (dev); +
Not an expert on pinctrl by any means.. but is this needed? Documentation/driver-api/pin-control.rst says:
| When a device driver is about to probe the device core will automatically | attempt to issue ``pinctrl_get_select_default()`` on these devices. | This way driver writers do not need to add any of the boilerplate code | of the type found below.
The documentation is obsolete, because pinctrl_get_select_default() doesn't seem to be the current mechanism through which that happens. But there is a pinctrl_bind_pins() function in really_probe() which looks like it does that job. So.. is this needed?
Also, pinctrl_pm_select_default_state() seems to be the suspend/resume (hence _pm_ name) variant of pinctrl_select_default_state(), but this is called from probe().
Quoted 14 lines
drivers/net/ethernet/freescale/enetc/enetc_pci_mdio.c +1
-0err =of_mdiobus_register (bus, dev->of_node);if (err) goto err_mdiobus_reg;@@ -113,6 +116,7 @@ static void enetc_pci_mdio_remove(struct pci_dev *pdev)static const struct pci_device_id enetc_pci_mdio_id_table[] = { {PCI_DEVICE (PCI_VENDOR_ID_FREESCALE ,ENETC_MDIO_DEV_ID ) }, + {PCI_DEVICE (PCI_VENDOR_ID_NXP2 ,PCI_DEVICE_ID_NXP2_NETC_EMDIO ) }, {0 , }/* End of table. */ };MODULE_DEVICE_TABLE (pci, enetc_pci_mdio_id_table);Signature · 1 line
2.34.1
Wei Fang
maintainerRE: [PATCH v5 net-next 09/13] net: enetc: add i.MX95 EMDIO support
Quoted 37 lines
Review
Quoted 10 lines
Signed-off-by Wei Fang <[email protected]>Reviewed-by Frank Li <[email protected]>---
v5: no changes--- drivers/net/ethernet/freescale/enetc/enetc_pci_mdio.c | 4 ++++ 1 file changed, 4 insertions(+)(quoted diff) +0
-0
b/drivers/net/ethernet/freescale/enetc/enetc_pci_mdio.cQuoted 12 lines
index
2445e35a764a..9968a1e9b5ef100644drivers/net/ethernet/freescale/enetc/enetc_pci_mdio.c +1
-0@@ -2,6 +2,7 @@/* Copyright 2019 NXP */ #include <linux/fsl/enetc_mdio.h> #include <linux/of_mdio.h> +#include <linux/pinctrl/consumer.h> #include "enetc_pf.h" #define ENETC_MDIO_DEV_ID 0xee01drivers/net/ethernet/freescale/enetc/enetc_pci_mdio.c static int enetc_pci_mdio_probe(struct pci_dev *pdev, · line 76
Quoted 5 lines
drivers/net/ethernet/freescale/enetc/enetc_pci_mdio.c +2
-0@@ -71,6 +72,8 @@ static int enetc_pci_mdio_probe(struct pci_dev *pdev,dev_info (&pdev->dev,"Enabled ERR050089 workaround\n" ); } +pinctrl_pm_select_default_state (dev); +Not an expert on pinctrl by any means.. but is this needed?
Documentation/driver-api/pin-control.rstsays:| When a device driver is about to probe the device core will automatically | attempt to issue ``pinctrl_get_select_default()`` on these devices. | This way driver writers do not need to add any of the boilerplate code | of the type found below.
Quoted 4 lines
The documentation is obsolete, because
pinctrl_get_select_default()doesn't seem to be the current mechanism through which that happens. But there is apinctrl_bind_pins()function inreally_probe()which looks like it does that job. So.. is this needed?
I think it is no need, I will remove it, thanks.
Vladimir Oltean
maintainerRe: [PATCH v5 net-next 09/13] net: enetc: add i.MX95 EMDIO support
In reply to Wei FangQuoted 1 line · Wei Fang
The verdor ID and device ID of i.MX95 EMDIO are different from LS1028A
Also: s/verdor/vendor/
Wei Fang
maintainerPATCH v5 10/13 net: enetc: extract enetc_int_vector_init/destroy() from enetc_alloc_msix()
In reply to Wei FangFrom: Clark Wang <[email protected]>
Extract enetc_int_vector_init() and enetc_int_vector_destroy() from enetc_alloc_msix() so that the code is more concise and readable. In addition, slightly different from before, the cleanup helper function is used to manage dynamically allocated memory resources.
---
v5: no changes
--- drivers/net/ethernet/freescale/enetc/enetc.c | 172 ++++++++++--------- 1 file changed, 87 insertions(+), 85 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc.c +87 -85
@@ -2965,6 +2965,87 @@ int enetc_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd) }EXPORT_SYMBOL_GPL (enetc_ioctl); +static int enetc_int_vector_init (struct enetc_ndev_priv *priv,int i, +int v_tx_rings) +{ + struct enetc_int_vector *v __free(kfree); +struct enetc_bdr *bdr; +int j, err; + + v =kzalloc (struct_size (v, tx_ring, v_tx_rings),GFP_KERNEL ); +if (!v) +return -ENOMEM ; + + bdr = &v->rx_ring; + bdr->index = i; + bdr->ndev = priv->ndev; + bdr->dev = priv->dev; + bdr->bd_count = priv->rx_bd_count; + bdr->buffer_offset =ENETC_RXB_PAD ; + priv->rx_ring[i] = bdr; + + err =xdp_rxq_info_reg (&bdr->xdp.rxq, priv->ndev, i,0 ); +if (err) +return err; + + err =xdp_rxq_info_reg_mem_model (&bdr->xdp.rxq, +MEM_TYPE_PAGE_SHARED ,NULL ); +if (err) { +xdp_rxq_info_unreg (&bdr->xdp.rxq); +return err; + } + +/* init defaults for adaptive IC */ +if (priv->ic_mode &ENETC_IC_RX_ADAPTIVE ) { + v->rx_ictt =0x1 ; + v->rx_dim_en = true; + } + +INIT_WORK (&v->rx_dim.work, enetc_rx_dim_work); +netif_napi_add (priv->ndev, &v->napi, enetc_poll); + v->count_tx_rings = v_tx_rings; + +for (j =0 ; j < v_tx_rings; j++) { +int idx; + +/* default tx ring mapping policy */ + idx = priv->bdr_int_num * j + i; +__set_bit (idx, &v->tx_rings_map); + bdr = &v->tx_ring[j]; + bdr->index = idx; + bdr->ndev = priv->ndev; + bdr->dev = priv->dev; + bdr->bd_count = priv->tx_bd_count; + priv->tx_ring[idx] = bdr; + } + + priv->int_vector[i] =no_free_ptr (v); + +return 0 ; +} + +static void enetc_int_vector_destroy (struct enetc_ndev_priv *priv,int i) +{ +struct enetc_int_vector *v = priv->int_vector[i]; +struct enetc_bdr *rx_ring = &v->rx_ring; +int j, tx_ring_index; + +xdp_rxq_info_unreg_mem_model (&rx_ring->xdp.rxq); +xdp_rxq_info_unreg (&rx_ring->xdp.rxq); +netif_napi_del (&v->napi); +cancel_work_sync (&v->rx_dim.work); + + priv->rx_ring[i] =NULL ; + +for (j =0 ; j < v->count_tx_rings; j++) { + tx_ring_index = priv->bdr_int_num * j + i; + priv->tx_ring[tx_ring_index] =NULL ; + } + +kfree (v); + priv->int_vector[i] =NULL ; +} +int enetc_alloc_msix (struct enetc_ndev_priv *priv) {struct pci_dev *pdev = priv->si->pdev;
@@ -2987,62 +3068,9 @@ int enetc_alloc_msix(struct enetc_ndev_priv *priv) v_tx_rings = priv->num_tx_rings / priv->bdr_int_num;for (i =0 ; i < priv->bdr_int_num; i++) { -struct enetc_int_vector *v; -struct enetc_bdr *bdr; -int j; - - v =kzalloc (struct_size (v, tx_ring, v_tx_rings),GFP_KERNEL ); -if (!v) { - err = -ENOMEM ; - goto fail; - } - - priv->int_vector[i] = v; - - bdr = &v->rx_ring; - bdr->index = i; - bdr->ndev = priv->ndev; - bdr->dev = priv->dev; - bdr->bd_count = priv->rx_bd_count; - bdr->buffer_offset =ENETC_RXB_PAD ; - priv->rx_ring[i] = bdr; - - err =xdp_rxq_info_reg (&bdr->xdp.rxq, priv->ndev, i,0 ); -if (err) { -kfree (v); - goto fail; - } - - err =xdp_rxq_info_reg_mem_model (&bdr->xdp.rxq, -MEM_TYPE_PAGE_SHARED ,NULL ); -if (err) { -xdp_rxq_info_unreg (&bdr->xdp.rxq); -kfree (v); + err =enetc_int_vector_init (priv, i, v_tx_rings); +if (err) goto fail; - } - -/* init defaults for adaptive IC */ -if (priv->ic_mode &ENETC_IC_RX_ADAPTIVE ) { - v->rx_ictt =0x1 ; - v->rx_dim_en = true; - } -INIT_WORK (&v->rx_dim.work, enetc_rx_dim_work); -netif_napi_add (priv->ndev, &v->napi, enetc_poll); - v->count_tx_rings = v_tx_rings; - -for (j =0 ; j < v_tx_rings; j++) { -int idx; - -/* default tx ring mapping policy */ - idx = priv->bdr_int_num * j + i; -__set_bit (idx, &v->tx_rings_map); - bdr = &v->tx_ring[j]; - bdr->index = idx; - bdr->ndev = priv->ndev; - bdr->dev = priv->dev; - bdr->bd_count = priv->tx_bd_count; - priv->tx_ring[idx] = bdr; - } } num_stack_tx_queues =enetc_num_stack_tx_queues (priv);
@@ -3062,16 +3090,8 @@ int enetc_alloc_msix(struct enetc_ndev_priv *priv)return 0 ; fail: -while (i--) { -struct enetc_int_vector *v = priv->int_vector[i]; -struct enetc_bdr *rx_ring = &v->rx_ring; - -xdp_rxq_info_unreg_mem_model (&rx_ring->xdp.rxq); -xdp_rxq_info_unreg (&rx_ring->xdp.rxq); -netif_napi_del (&v->napi); -cancel_work_sync (&v->rx_dim.work); -kfree (v); - } +while (i--) +enetc_int_vector_destroy (priv, i);pci_free_irq_vectors (pdev);
@@ -3083,26 +3103,8 @@ void enetc_free_msix(struct enetc_ndev_priv *priv) {int i; -for (i =0 ; i < priv->bdr_int_num; i++) { -struct enetc_int_vector *v = priv->int_vector[i]; -struct enetc_bdr *rx_ring = &v->rx_ring; - -xdp_rxq_info_unreg_mem_model (&rx_ring->xdp.rxq); -xdp_rxq_info_unreg (&rx_ring->xdp.rxq); -netif_napi_del (&v->napi); -cancel_work_sync (&v->rx_dim.work); - } - -for (i =0 ; i < priv->num_rx_rings; i++) - priv->rx_ring[i] =NULL ; - -for (i =0 ; i < priv->num_tx_rings; i++) - priv->tx_ring[i] =NULL ; - -for (i =0 ; i < priv->bdr_int_num; i++) { -kfree (priv->int_vector[i]); - priv->int_vector[i] =NULL ; - } +for (i =0 ; i < priv->bdr_int_num; i++) +enetc_int_vector_destroy (priv, i);/* disable all MSIX for this device */ pci_free_irq_vectors (priv->si->pdev);
Signature · 1 line
2.34.1
Vladimir Oltean
maintainerRe: [PATCH v5 net-next 10/13] net: enetc: extract enetc_int_vector_init/destroy() from enetc_alloc_msix()
Quoted 22 lines · Wei Fang
From: Clark Wang <[email protected]>
Extract
enetc_int_vector_init()andenetc_int_vector_destroy()fromenetc_alloc_msix()so that the code is more concise and readable. In addition, slightly different from before, the cleanup helper function is used to manage dynamically allocated memory resources.Signed-off-by Clark Wang <[email protected]>Signed-off-by Wei Fang <[email protected]>Reviewed-by Frank Li <[email protected]>Reviewed-by Claudiu Manoil <[email protected]>---
v5: no changes--- drivers/net/ethernet/freescale/enetc/enetc.c | 172 ++++++++++--------- 1 file changed, 87 insertions(+), 85 deletions(-)drivers/net/ethernet/freescale/enetc/enetc.c +0
-0
drivers/net/ethernet/freescale/enetc/enetc.c int enetc_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd) · line 2971
Quoted 7 lines
drivers/net/ethernet/freescale/enetc/enetc.c +4
-0@@ -2965,6 +2965,87 @@ int enetc_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd) }EXPORT_SYMBOL_GPL (enetc_ioctl); +static int enetc_int_vector_init (struct enetc_ndev_priv *priv,int i, +int v_tx_rings) +{ + struct enetc_int_vector *v __free(kfree);
Please limit yourself to refactoring the code as-is into a separate function. This function does not benefit in any way from the use of __free() and no_free_ptr(). The established norm is that the normal teardown path should be identical to the error unwind path, minus the last step. Combining normal function calls with devres/scope-based cleanup/whatever other "look, you don't get to care about error handling!!!" APIs there may be makes that much more difficult to reason about. If the function is really simple and you really don't get to care about error handling by using __free(), then maybe its usage is tolerable, but that is hardly the general case. The more intricate the error handling becomes, the less useful __free() is, and the more it starts getting in the way of a human correctness reviewer.
FWIW, Documentation/process/maintainer-netdev.rst, section "Using device-managed and cleanup.h constructs", appears to mostly state the same position as me here.
Obviously, here, the established cleanup norm isn't followed anyway, but a patch which brings it in line would be appreciated. I think that a multi-patch approach, where the code is first moved and just moved, and then successively transformed in obviously correct and easy to review steps, would be best.
Since you're quite close currently to the 15-patch limit, I would try to create a patch set just for preparing the enetc drivers, and introduce the i.mx95 support in a separate set which has mostly "+" lines in its diff. That way, there is also some time to not rush the ongoing IERB/PRB dt-binding discussion, while you can progress on pure driver refactoring.
Quoted 11 lines
drivers/net/ethernet/freescale/enetc/enetc.c +11
-0+struct enetc_bdr *bdr; +int j, err; + + v =kzalloc (struct_size (v, tx_ring, v_tx_rings),GFP_KERNEL ); +if (!v) +return -ENOMEM ; + + bdr = &v->rx_ring; + bdr->index = i; + bdr->ndev = priv->ndev; + bdr->dev = priv->dev;
drivers/net/ethernet/freescale/enetc/enetc.c int enetc_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd) · line 2992
Quoted 10 lines
drivers/net/ethernet/freescale/enetc/enetc.c +10
-0+ bdr->bd_count = priv->rx_bd_count; + bdr->buffer_offset =ENETC_RXB_PAD ; + priv->rx_ring[i] = bdr; + + err =xdp_rxq_info_reg (&bdr->xdp.rxq, priv->ndev, i,0 ); +if (err) +return err; + + err =xdp_rxq_info_reg_mem_model (&bdr->xdp.rxq, +MEM_TYPE_PAGE_SHARED ,NULL );
MEM_TYPE_PAGE_SHARED fits on the previous line.
Quoted 33 lines
drivers/net/ethernet/freescale/enetc/enetc.c +33
-0+if (err) { +xdp_rxq_info_unreg (&bdr->xdp.rxq); +return err; + } + +/* init defaults for adaptive IC */ +if (priv->ic_mode &ENETC_IC_RX_ADAPTIVE ) { + v->rx_ictt =0x1 ; + v->rx_dim_en = true; + } + +INIT_WORK (&v->rx_dim.work, enetc_rx_dim_work); +netif_napi_add (priv->ndev, &v->napi, enetc_poll); + v->count_tx_rings = v_tx_rings; + +for (j =0 ; j < v_tx_rings; j++) { +int idx; + +/* default tx ring mapping policy */ + idx = priv->bdr_int_num * j + i; +__set_bit (idx, &v->tx_rings_map); + bdr = &v->tx_ring[j]; + bdr->index = idx; + bdr->ndev = priv->ndev; + bdr->dev = priv->dev; + bdr->bd_count = priv->tx_bd_count; + priv->tx_ring[idx] = bdr; + } + + priv->int_vector[i] =no_free_ptr (v); + +return 0 ; +}
Wei Fang
maintainerRE: [PATCH v5 net-next 10/13] net: enetc: extract enetc_int_vector_init/destroy() from enetc_alloc_msix()
Quoted 28 lines · Wei Fang
Quoted 11 lines
From: Clark Wang <[email protected]>
Extract
enetc_int_vector_init()andenetc_int_vector_destroy()fromenetc_alloc_msix()so that the code is more concise and readable. In addition, slightly different from before, the cleanup helper function is used to manage dynamically allocated memory resources.Signed-off-by Clark Wang <[email protected]>Signed-off-by Wei Fang <[email protected]>Reviewed-by Frank Li <[email protected]>Reviewed-by Claudiu Manoil <[email protected]>Review
Quoted 7 lines
---
v5: no changes--- drivers/net/ethernet/freescale/enetc/enetc.c | 172 ++++++++++--------- 1 file changed, 87 insertions(+), 85 deletions(-)(quoted diff) +0
-0
b/drivers/net/ethernet/freescale/enetc/enetc.cdrivers/net/ethernet/freescale/enetc/enetc.c int enetc_ioctl(struct net_device *ndev, struct
Quoted 4 lines
index
032d8eadd003..bd725561b8a2100644drivers/net/ethernet/freescale/enetc/enetc.c +0
-0@@ -2965,6 +2965,87 @@ int enetc_ioctl(struct net_device *ndev, structifreq *rq, int cmd)
Quoted 3 lines
drivers/net/ethernet/freescale/enetc/enetc.c +0
-0}EXPORT_SYMBOL_GPL (enetc_ioctl);
Quoted 6 lines
drivers/net/ethernet/freescale/enetc/enetc.c int enetc_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd) · line 2971
Quoted 4 lines
drivers/net/ethernet/freescale/enetc/enetc.c +4
-0+static int enetc_int_vector_init (struct enetc_ndev_priv *priv,int i, +int v_tx_rings) +{ + struct enetc_int_vector *v __free(kfree);Please limit yourself to refactoring the code as-is into a separate function.
Okay
Quoted 21 lines
This function does not benefit in any way from the use of
__free()andno_free_ptr(). The established norm is that the normal teardown path should be identical to the error unwind path, minus the last step. Combining normal function calls with devres/scope-based cleanup/whatever other "look, you don't get to care about error handling!!!" APIs there may be makes that much more difficult to reason about. If the function is really simple and you really don't get to care about error handling by using__free(), then maybe its usage is tolerable, but that is hardly the general case. The more intricate the error handling becomes, the less useful__free()is, and the more it starts getting in the way of a human correctness reviewer.FWIW,
Documentation/process/maintainer-netdev.rst, section "Using device-managed andcleanup.hconstructs", appears to mostly state the same position as me here.Obviously, here, the established cleanup norm isn't followed anyway, but a patch which brings it in line would be appreciated. I think that a multi-patch approach, where the code is first moved and just moved, and then successively transformed in obviously correct and easy to review steps, would be best.
Quoted 6 lines
Since you're quite close currently to the 15-patch limit, I would try to create a patch set just for preparing the enetc drivers, and introduce the i.mx95 support in a separate set which has mostly "+" lines in its diff. That way, there is also some time to not rush the ongoing IERB/PRB dt-binding discussion, while you can progress on pure driver refactoring.
Thanks for your suggestion.
Wei Fang
maintainerPATCH v5 11/13 net: enetc: optimize the allocation of tx_bdr
In reply to Wei FangFrom: Clark Wang <[email protected]>
There is a situation where num_tx_rings cannot be divided by bdr_int_num. For example, num_tx_rings is 8 and bdr_int_num is 3. According to the previous logic, this results in two tx_bdr corresponding memories not being allocated, so when sending packets to tx ring 6 or 7, wild pointers will be accessed. Of course, this issue doesn't exist on LS1028A, because its num_tx_rings is 8, and bdr_int_num is either 1 or 2. However, there is a risk for the upcoming i.MX95. Therefore, it is necessary to ensure that each tx_bdr can be allocated to the corresponding memory.
---
v5: no changes
--- drivers/net/ethernet/freescale/enetc/enetc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc.c +5 -2
@@ -3049,10 +3049,10 @@ static void enetc_int_vector_destroy(struct enetc_ndev_priv *priv, int i)int enetc_alloc_msix (struct enetc_ndev_priv *priv) {struct pci_dev *pdev = priv->si->pdev; +int v_tx_rings, v_remainder;int num_stack_tx_queues;int first_xdp_tx_ring;int i, n, err, nvec; -int v_tx_rings; nvec =ENETC_BDR_INT_BASE_IDX + priv->bdr_int_num;/* allocate MSIX for both messaging and Rx/Tx interrupts */
@@ -3066,9 +3066,12 @@ int enetc_alloc_msix(struct enetc_ndev_priv *priv)/* # of tx rings per int vector */ v_tx_rings = priv->num_tx_rings / priv->bdr_int_num; + v_remainder = priv->num_tx_rings % priv->bdr_int_num;for (i =0 ; i < priv->bdr_int_num; i++) { - err =enetc_int_vector_init (priv, i, v_tx_rings); +int num_tx_rings = i < v_remainder ? v_tx_rings +1 : v_tx_rings; + + err =enetc_int_vector_init (priv, i, num_tx_rings);if (err) goto fail; }
Signature · 1 line
2.34.1
Vladimir Oltean
maintainerRe: [PATCH v5 net-next 11/13] net: enetc: optimize the allocation of tx_bdr
Quoted 38 lines · Wei Fang
From: Clark Wang <[email protected]>
There is a situation where
num_tx_ringscannot be divided bybdr_int_num. For example,num_tx_ringsis 8 andbdr_int_numis 3. According to the previous logic, this results in twotx_bdrcorresponding memories not being allocated, so when sending packets to tx ring 6 or 7, wild pointers will be accessed. Of course, this issue doesn't exist on LS1028A, because itsnum_tx_ringsis 8, andbdr_int_numis either 1 or 2. However, there is a risk for the upcoming i.MX95. Therefore, it is necessary to ensure that eachtx_bdrcan be allocated to the corresponding memory.Signed-off-by Clark Wang <[email protected]>Signed-off-by Wei Fang <[email protected]>Reviewed-by Claudiu Manoil <[email protected]>Reviewed-by Frank Li <[email protected]>---
v5: no changes--- drivers/net/ethernet/freescale/enetc/enetc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/net/ethernet/freescale/enetc/enetc.c +1
-1@@ -3049,10 +3049,10 @@ static void enetc_int_vector_destroy(struct enetc_ndev_priv *priv, int i)int enetc_alloc_msix (struct enetc_ndev_priv *priv) {struct pci_dev *pdev = priv->si->pdev; +int v_tx_rings, v_remainder;int num_stack_tx_queues;int first_xdp_tx_ring;int i, n, err, nvec; -int v_tx_rings; nvec =ENETC_BDR_INT_BASE_IDX + priv->bdr_int_num;/* allocate MSIX for both messaging and Rx/Tx interrupts */
drivers/net/ethernet/freescale/enetc/enetc.c int enetc_alloc_msix(struct enetc_ndev_priv *priv) · line 3072
Quoted 8 lines
drivers/net/ethernet/freescale/enetc/enetc.c +2
-1@@ -3066,9 +3066,12 @@ int enetc_alloc_msix(struct enetc_ndev_priv *priv)/* # of tx rings per int vector */ v_tx_rings = priv->num_tx_rings / priv->bdr_int_num; + v_remainder = priv->num_tx_rings % priv->bdr_int_num;for (i =0 ; i < priv->bdr_int_num; i++) { - err =enetc_int_vector_init (priv, i, v_tx_rings); +int num_tx_rings = i < v_remainder ? v_tx_rings +1 : v_tx_rings;
It took me a moment to understand the mechanism through which this works, even though I read the intention in the commit message.
Do you think this additional comment would help?
/* Distribute the remaining TX rings to the first * v_tx_rings interrupt vectors */
Quoted 8 lines
drivers/net/ethernet/freescale/enetc/enetc.c +2
-0+ + err =enetc_int_vector_init (priv, i, num_tx_rings);if (err) goto fail; }Signature · 1 line
2.34.1
Wei Fang
maintainerRE: [PATCH v5 net-next 11/13] net: enetc: optimize the allocation of tx_bdr
Quoted 47 lines · Wei Fang
Quoted 15 lines
From: Clark Wang <[email protected]>
There is a situation where
num_tx_ringscannot be divided bybdr_int_num. For example,num_tx_ringsis 8 andbdr_int_numis 3. According to the previous logic, this results in twotx_bdrcorresponding memories not being allocated, so when sending packets to tx ring 6 or 7, wild pointers will be accessed. Of course, this issue doesn't exist on LS1028A, because itsnum_tx_ringsis 8, andbdr_int_numis either 1 or 2. However, there is a risk for the upcoming i.MX95. Therefore, it is necessary to ensure that eachtx_bdrcan be allocated to the corresponding memory.Signed-off-by Clark Wang <[email protected]>Signed-off-by Wei Fang <[email protected]>Reviewed-by Claudiu Manoil <[email protected]>Reviewed-by Frank Li <[email protected]>Review
Quoted 7 lines
---
v5: no changes--- drivers/net/ethernet/freescale/enetc/enetc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)(quoted diff) +0
-0
b/drivers/net/ethernet/freescale/enetc/enetc.cdrivers/net/ethernet/freescale/enetc/enetc.c static void enetc_int_vector_destroy(struct
Quoted 4 lines
index
bd725561b8a2..bccbeb1f355c100644drivers/net/ethernet/freescale/enetc/enetc.c +0
-0@@ -3049,10 +3049,10 @@ static void enetc_int_vector_destroy(struct
enetc_ndev_priv*priv, int i)drivers/net/ethernet/freescale/enetc/enetc.c int enetc_alloc_msix(struct enetc_ndev_priv
Quoted 12 lines
drivers/net/ethernet/freescale/enetc/enetc.c +1
-1int enetc_alloc_msix (struct enetc_ndev_priv *priv) {struct pci_dev *pdev = priv->si->pdev; +int v_tx_rings, v_remainder;int num_stack_tx_queues;int first_xdp_tx_ring;int i, n, err, nvec; -int v_tx_rings; nvec =ENETC_BDR_INT_BASE_IDX + priv->bdr_int_num;/* allocate MSIX for both messaging and Rx/Tx interrupts */ @@ -3066,9 +3066,12 @@ int enetc_alloc_msix(struct enetc_ndev_priv*priv)
Quoted 5 lines
drivers/net/ethernet/freescale/enetc/enetc.c +1
-0/* # of tx rings per int vector */ v_tx_rings = priv->num_tx_rings / priv->bdr_int_num; + v_remainder = priv->num_tx_rings % priv->bdr_int_num;
Quoted 8 lines
drivers/net/ethernet/freescale/enetc/enetc.c int enetc_alloc_msix(struct enetc_ndev_priv *priv) · line 3072
Quoted 3 lines
drivers/net/ethernet/freescale/enetc/enetc.c +1
-1for (i =0 ; i < priv->bdr_int_num; i++) { - err =enetc_int_vector_init (priv, i, v_tx_rings); +int num_tx_rings = i < v_remainder ? v_tx_rings +1 : v_tx_rings;It took me a moment to understand the mechanism through which this works, even though I read the intention in the commit message.
Do you think this additional comment would help?
Yeah, it does help users understand quickly. I will add this comment.
Quoted 13 lines
/* Distribute the remaining TX rings to the first * v_tx_rings interrupt vectors */Quoted 8 lines
drivers/net/ethernet/freescale/enetc/enetc.c +2
-1+ + err =enetc_int_vector_init (priv, i, num_tx_rings);if (err) goto fail; } --2.34.1
Wei Fang
maintainerPATCH v5 12/13 net: enetc: add preliminary support for i.MX95 ENETC PF
In reply to Wei FangThe i.MX95 ENETC has been upgraded to revision 4.1, which is different from the LS1028A ENETC (revision 1.0) except for the SI part. Therefore, the fsl-enetc driver is incompatible with i.MX95 ENETC PF. So add new nxp-enetc4 driver to support i.MX95 ENETC PF, and this driver will be used to support the ENETC PF with major revision 4 for other SoCs in the future.
Currently, the nxp-enetc4 driver only supports basic transmission feature for i.MX95 ENETC PF, the more basic and advanced features will be added in the subsequent patches.
---
v2 changes:
1. Refine the commit message.
2. Sort the header files.
3. Use dev_err_probe() in enetc4_pf_probe().
4. Remove unused variable 'pf' from enetc4_pf_remove(). v3 changes:
1. Remove is_enetc_rev1() from enetc_init_si_rings_params().
2. Use devm_add_action_or_reset() in enetc4_pf_probe().
3. Directly return dev_err_probe() in enetc4_pf_probe(). v4 changes:
1. Move clk_freq from enect_si to enetc_ndev_priv.
2. Remove is_enetc_rev4().
3. Add enetc4_pf_ethtool_ops for i.MX95 ENETC PF.
v5 changes:
1. Add driver data support, some information such as system clock frequency, pMAC offset and so on are defined in driver data.
2. Add some macros to replace numbers in the driver
--- drivers/net/ethernet/freescale/enetc/Kconfig | 17 + drivers/net/ethernet/freescale/enetc/Makefile | 3 + drivers/net/ethernet/freescale/enetc/enetc.c | 86 +- drivers/net/ethernet/freescale/enetc/enetc.h | 30 +- .../net/ethernet/freescale/enetc/enetc4_hw.h | 152 ++++ .../net/ethernet/freescale/enetc/enetc4_pf.c | 759 ++++++++++++++++++ .../ethernet/freescale/enetc/enetc_ethtool.c | 35 +- .../net/ethernet/freescale/enetc/enetc_hw.h | 19 +- .../net/ethernet/freescale/enetc/enetc_pf.c | 7 + .../net/ethernet/freescale/enetc/enetc_pf.h | 14 + .../freescale/enetc/enetc_pf_common.c | 11 +- .../net/ethernet/freescale/enetc/enetc_qos.c | 2 +- .../net/ethernet/freescale/enetc/enetc_vf.c | 6 + 13 files changed, 1113 insertions(+), 28 deletions(-) create mode 100644 drivers/net/ethernet/freescale/enetc/enetc4_hw.h create mode 100644 drivers/net/ethernet/freescale/enetc/enetc4_pf.c
drivers/net/ethernet/freescale/enetc/Kconfig +17 -0
@@ -33,6 +33,23 @@ config FSL_ENETC If compiled as module (M), the module name is fsl-enetc. +config NXP_ENETC4 + tristate "ENETC4 PF driver" + depends on PCI_MSI + select MDIO_DEVRES + select FSL_ENETC_CORE + select FSL_ENETC_MDIO + select NXP_ENETC_PF_COMMON + select PHYLINK + select DIMLIB + help + This driver supports NXP ENETC devices with major revision 4. ENETC is + as the NIC functionality in NETC, it supports virtualization/isolation + based on PCIe Single Root IO Virtualization (SR-IOV) and a full range + of TSN standards and NIC offload capabilities. + + If compiled as module (M), the module name is nxp-enetc4. + config FSL_ENETC_VF tristate "ENETC VF driver" depends on PCI_MSI
drivers/net/ethernet/freescale/enetc/Makefile +3 -0
@@ -11,6 +11,9 @@ fsl-enetc-y := enetc_pf.o fsl-enetc-$(CONFIG_PCI_IOV) += enetc_msg.o fsl-enetc-$(CONFIG_FSL_ENETC_QOS) += enetc_qos.o +obj-$(CONFIG_NXP_ENETC4) += nxp-enetc4.o +nxp-enetc4-y := enetc4_pf.o + obj-$(CONFIG_FSL_ENETC_VF) += fsl-enetc-vf.o fsl-enetc-vf-y := enetc_vf.o
drivers/net/ethernet/freescale/enetc/enetc.c +77 -9
150 lines not on this page · raw message
drivers/net/ethernet/freescale/enetc/enetc.h +28 -2
@@ -14,6 +14,7 @@#include <net/xdp.h> #include "enetc_hw.h" +#include "enetc4_hw.h" #define ENETC_MAC_MAXFRM_SIZE 9600#define ENETC_MAX_MTU (ENETC_MAC_MAXFRM_SIZE - \
@@ -231,6 +232,18 @@ enum enetc_errata {#define ENETC_SI_F_QBV BIT(1)#define ENETC_SI_F_QBU BIT(2) +struct enetc_drvdata { +u32 pmac_offset;/* Only valid for PSI which supports 802.1Qbu */ +u64 sysclk_freq; +const struct ethtool_ops *eth_ops; +}; + +struct enetc_platform_info { +u16 revision; +u16 dev_id; +const struct enetc_drvdata *data; +}; +/* PCI IEP device data */ struct enetc_si {struct pci_dev *pdev;
@@ -246,11 +259,18 @@ struct enetc_si {int num_fs_entries;int num_rss;/* number of RSS buckets */ unsigned short pad; +u16 revision;int hw_features; +const struct enetc_drvdata *drvdata; };#define ENETC_SI_ALIGN 32 +static inline bool is_enetc_rev1 (struct enetc_si *si) +{ +return si->pdev->revision ==ENETC_REV1 ; +} +static inline void *enetc_si_priv (const struct enetc_si *si) {return (char *)si +ALIGN (sizeof (struct enetc_si ),ENETC_SI_ALIGN );
@@ -302,7 +322,7 @@ struct enetc_cls_rule {int used; }; -#define ENETC_MAX_BDR_INT 2/* fixed to max # of available cpus */ +#define ENETC_MAX_BDR_INT 6/* fixed to max # of available cpus */ struct psfp_cap {u32 max_streamid;u32 max_psfp_filter;
@@ -340,7 +360,6 @@ enum enetc_ic_mode {#define ENETC_RXIC_PKTTHR min_t(u32, 256, ENETC_RX_RING_DEFAULT_SIZE / 2)#define ENETC_TXIC_PKTTHR min_t(u32, 128, ENETC_TX_RING_DEFAULT_SIZE / 2) -#define ENETC_TXIC_TIMETHR enetc_usecs_to_cycles(600)struct enetc_ndev_priv {struct net_device *ndev;
@@ -388,6 +407,9 @@ struct enetc_ndev_priv {* and link state updates */ struct mutex mm_lock; + +struct clk *ref_clk;/* RGMII/RMII reference clock */ +u64 sysclk_freq;/* NETC system clock frequency */ };/* Messaging */
@@ -417,6 +439,7 @@ void enetc_init_si_rings_params(struct enetc_ndev_priv *priv);int enetc_alloc_si_resources (struct enetc_ndev_priv *priv);void enetc_free_si_resources (struct enetc_ndev_priv *priv);int enetc_configure_si (struct enetc_ndev_priv *priv); +int enetc_get_driver_data (struct enetc_si *si);int enetc_open (struct net_device *ndev);int enetc_close (struct net_device *ndev);
@@ -433,6 +456,9 @@ int enetc_xdp_xmit(struct net_device *ndev, int num_frames, struct xdp_frame **frames, u32 flags);/* ethtool */ +extern const struct ethtool_ops enetc_pf_ethtool_ops; +extern const struct ethtool_ops enetc4_pf_ethtool_ops; +extern const struct ethtool_ops enetc_vf_ethtool_ops;void enetc_set_ethtool_ops (struct net_device *ndev);void enetc_mm_link_state_update (struct enetc_ndev_priv *priv,bool link);void enetc_mm_commit_preemptible_tcs (struct enetc_ndev_priv *priv);
drivers/net/ethernet/freescale/enetc/enetc4_hw.h new file +152 -0
152 lines not on this page · raw message
drivers/net/ethernet/freescale/enetc/enetc4_pf.c new file +759 -0
759 lines not on this page · raw message
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +25 -10
@@ -775,9 +775,10 @@ static int enetc_get_coalesce(struct net_device *ndev, {struct enetc_ndev_priv *priv =netdev_priv (ndev);struct enetc_int_vector *v = priv->int_vector[0 ]; +u64 clk_freq = priv->sysclk_freq; - ic->tx_coalesce_usecs =enetc_cycles_to_usecs (priv->tx_ictt); - ic->rx_coalesce_usecs =enetc_cycles_to_usecs (v->rx_ictt); + ic->tx_coalesce_usecs =enetc_cycles_to_usecs (priv->tx_ictt, clk_freq); + ic->rx_coalesce_usecs =enetc_cycles_to_usecs (v->rx_ictt, clk_freq); ic->tx_max_coalesced_frames =ENETC_TXIC_PKTTHR ; ic->rx_max_coalesced_frames =ENETC_RXIC_PKTTHR ;
@@ -793,12 +794,13 @@ static int enetc_set_coalesce(struct net_device *ndev, struct netlink_ext_ack *extack) {struct enetc_ndev_priv *priv =netdev_priv (ndev); +u64 clk_freq = priv->sysclk_freq;u32 rx_ictt, tx_ictt;int i, ic_mode;bool changed; - tx_ictt =enetc_usecs_to_cycles (ic->tx_coalesce_usecs); - rx_ictt =enetc_usecs_to_cycles (ic->rx_coalesce_usecs); + tx_ictt =enetc_usecs_to_cycles (ic->tx_coalesce_usecs, clk_freq); + rx_ictt =enetc_usecs_to_cycles (ic->rx_coalesce_usecs, clk_freq);if (ic->rx_max_coalesced_frames !=ENETC_RXIC_PKTTHR )return -EOPNOTSUPP ;
@@ -1178,7 +1180,7 @@ void enetc_mm_link_state_update(struct enetc_ndev_priv *priv, bool link) }EXPORT_SYMBOL_GPL (enetc_mm_link_state_update); -static const struct ethtool_ops enetc_pf_ethtool_ops = { +const struct ethtool_ops enetc_pf_ethtool_ops = { .supported_coalesce_params =ETHTOOL_COALESCE_USECS |ETHTOOL_COALESCE_MAX_FRAMES |ETHTOOL_COALESCE_USE_ADAPTIVE_RX ,
@@ -1213,7 +1215,7 @@ static const struct ethtool_ops enetc_pf_ethtool_ops = { .get_mm_stats = enetc_get_mm_stats, }; -static const struct ethtool_ops enetc_vf_ethtool_ops = { +const struct ethtool_ops enetc_vf_ethtool_ops = { .supported_coalesce_params =ETHTOOL_COALESCE_USECS |ETHTOOL_COALESCE_MAX_FRAMES |ETHTOOL_COALESCE_USE_ADAPTIVE_RX ,
@@ -1234,13 +1236,26 @@ static const struct ethtool_ops enetc_vf_ethtool_ops = { .get_ts_info = enetc_get_ts_info, }; +const struct ethtool_ops enetc4_pf_ethtool_ops = { + .supported_coalesce_params =ETHTOOL_COALESCE_USECS | +ETHTOOL_COALESCE_MAX_FRAMES | +ETHTOOL_COALESCE_USE_ADAPTIVE_RX , + .get_ringparam = enetc_get_ringparam, + .get_coalesce = enetc_get_coalesce, + .set_coalesce = enetc_set_coalesce, + .get_link_ksettings = enetc_get_link_ksettings, + .set_link_ksettings = enetc_set_link_ksettings, + .get_link = ethtool_op_get_link, + .get_wol = enetc_get_wol, + .set_wol = enetc_set_wol, + .get_pauseparam = enetc_get_pauseparam, + .set_pauseparam = enetc_set_pauseparam, +}; +void enetc_set_ethtool_ops (struct net_device *ndev) {struct enetc_ndev_priv *priv =netdev_priv (ndev); -if (enetc_si_is_pf (priv->si)) - ndev->ethtool_ops = &enetc_pf_ethtool_ops; -else - ndev->ethtool_ops = &enetc_vf_ethtool_ops; + ndev->ethtool_ops = priv->si->drvdata->eth_ops; }EXPORT_SYMBOL_GPL (enetc_set_ethtool_ops);
drivers/net/ethernet/freescale/enetc/enetc_hw.h +14 -5
@@ -6,6 +6,8 @@#define ENETC_MM_VERIFY_SLEEP_US USEC_PER_MSEC#define ENETC_MM_VERIFY_RETRIES 3 +#define ENETC_NUM_TC 8 +/* ENETC device IDs */ #define ENETC_DEV_ID_PF 0xe100#define ENETC_DEV_ID_VF 0xef00
@@ -25,6 +27,7 @@#define ENETC_SIPCAPR0_RSS BIT(8)#define ENETC_SIPCAPR0_QBV BIT(4)#define ENETC_SIPCAPR0_QBU BIT(3) +#define ENETC_SIPCAPR0_RFS BIT(2)#define ENETC_SIPCAPR1 0x24#define ENETC_SITGTGR 0x30#define ENETC_SIRBGCR 0x38
@@ -368,6 +371,10 @@ enum enetc_bdr_type {TX, RX};/** Global regs, offset: 2_0000h */ #define ENETC_GLOBAL_BASE 0x20000#define ENETC_G_EIPBRR0 0x0bf8 +#define EIPBRR0_REVISION GENMASK(15, 0) +#define ENETC_REV_1_0 0x0100 +#define ENETC_REV_4_1 0X0401 +#define ENETC_G_EIPBRR1 0x0bfc#define ENETC_G_EPFBLPR (n) (0xd00 + 4 * (n))#define ENETC_G_EPFBLPR1_XGMII 0x80000000
@@ -971,15 +978,17 @@ struct enetc_cbd {u8 status_flags; }; -#define ENETC_CLK 400000000ULL -static inline u32 enetc_cycles_to_usecs (u32 cycles) +#define ENETC_CLK_400M 400000000ULL +#define ENETC_CLK_333M 333000000ULL + +static inline u32 enetc_cycles_to_usecs (u32 cycles,u64 clk_freq) { -return (u32 )div_u64 (cycles *1000000ULL ,ENETC_CLK ); +return (u32 )div_u64 (cycles *1000000ULL , clk_freq); } -static inline u32 enetc_usecs_to_cycles (u32 usecs) +static inline u32 enetc_usecs_to_cycles (u32 usecs,u64 clk_freq) { -return (u32 )div_u64 (usecs *ENETC_CLK ,1000000ULL ); +return (u32 )div_u64 (usecs * clk_freq,1000000ULL ); }/* Port traffic class frame preemption register */
drivers/net/ethernet/freescale/enetc/enetc_pf.c +7 -0
@@ -946,6 +946,13 @@ static struct enetc_si *enetc_psi_create(struct pci_dev *pdev) goto out_pci_remove; } + si->revision =enetc_get_ip_revision (&si->hw); + err =enetc_get_driver_data (si); +if (err) { +dev_err (&pdev->dev,"Could not get PF driver data\n" ); + goto out_pci_remove; + } + err =enetc_setup_cbdr (&pdev->dev, &si->hw,ENETC_CBDR_DEFAULT_SIZE , &si->cbd_ring);if (err)
drivers/net/ethernet/freescale/enetc/enetc_pf.h +14 -0
@@ -28,6 +28,14 @@ struct enetc_vf_state {enum enetc_vf_flags flags; }; +struct enetc_port_caps { +u32 half_duplex:1 ; +int num_vsi; +int num_msix; +int num_rx_bdr; +int num_tx_bdr; +}; +struct enetc_pf ;struct enetc_pf_ops {
@@ -61,6 +69,7 @@ struct enetc_pf {phy_interface_t if_mode;struct phylink_config phylink_config; +struct enetc_port_caps caps;const struct enetc_pf_ops *ops; };
@@ -81,6 +90,11 @@ int enetc_phylink_create(struct enetc_ndev_priv *priv, struct device_node *node, const struct phylink_mac_ops *ops);void enetc_phylink_destroy (struct enetc_ndev_priv *priv); +static inline u16 enetc_get_ip_revision (struct enetc_hw *hw) +{ +return enetc_global_rd (hw,ENETC_G_EIPBRR0 ) &EIPBRR0_REVISION ; +} +static inline void enetc_pf_ops_register (struct enetc_pf *pf,const struct enetc_pf_ops *ops) {
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +10 -1
@@ -105,6 +105,7 @@ void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev, si->ndev = ndev; priv->msg_enable = (NETIF_MSG_WOL <<1 ) -1 ; + priv->sysclk_freq = si->drvdata->sysclk_freq; ndev->netdev_ops = ndev_ops;enetc_set_ethtool_ops (ndev); ndev->watchdog_timeo =5 *HZ ;
@@ -121,10 +122,17 @@ void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev, ndev->vlan_features =NETIF_F_SG |NETIF_F_HW_CSUM |NETIF_F_TSO |NETIF_F_TSO6 ; + ndev->priv_flags |=IFF_UNICAST_FLT ; + +/* TODO: currently, i.MX95 ENETC driver does not support advanced features */ +if (!is_enetc_rev1 (si)) { + ndev->hw_features &= ~(NETIF_F_HW_VLAN_CTAG_FILTER |NETIF_F_LOOPBACK ); + goto end; + } +if (si->num_rss) ndev->hw_features |=NETIF_F_RXHASH ; - ndev->priv_flags |=IFF_UNICAST_FLT ; ndev->xdp_features =NETDEV_XDP_ACT_BASIC |NETDEV_XDP_ACT_REDIRECT |NETDEV_XDP_ACT_NDO_XMIT |NETDEV_XDP_ACT_RX_SG |NETDEV_XDP_ACT_NDO_XMIT_SG ;
@@ -136,6 +144,7 @@ void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev, ndev->hw_features |=NETIF_F_HW_TC ; } +end:/* pick up primary MAC address from SI */ enetc_load_primary_mac_addr (&si->hw, ndev); }
drivers/net/ethernet/freescale/enetc/enetc_qos.c +1 -1
@@ -336,7 +336,7 @@ int enetc_setup_tc_cbs(struct net_device *ndev, void *type_data)* * (enetClockFrequency / portTransmitRate) * 100 */ - hi_credit_reg = (u32 )div_u64 ((ENETC_CLK *100ULL ) * hi_credit_bit, + hi_credit_reg = (u32 )div_u64 ((priv->sysclk_freq *100ULL ) * hi_credit_bit, port_transmit_rate *1000000ULL );enetc_port_wr (hw,ENETC_PTCCBSR1 (tc), hi_credit_reg);
drivers/net/ethernet/freescale/enetc/enetc_vf.c +6 -0
@@ -128,6 +128,7 @@ static void enetc_vf_netdev_setup(struct enetc_si *si, struct net_device *ndev, si->ndev = ndev; priv->msg_enable = (NETIF_MSG_IFUP <<1 ) -1 ; + priv->sysclk_freq = si->drvdata->sysclk_freq; ndev->netdev_ops = ndev_ops;enetc_set_ethtool_ops (ndev); ndev->watchdog_timeo =5 *HZ ;
@@ -164,6 +165,11 @@ static int enetc_vf_probe(struct pci_dev *pdev,return dev_err_probe (&pdev->dev, err,"PCI probing failed\n" ); si =pci_get_drvdata (pdev); + si->revision =ENETC_REV_1_0 ; + err =enetc_get_driver_data (si); +if (err) +return dev_err_probe (&pdev->dev, err, +"Could not get VF driver data\n" );enetc_get_si_caps (si);
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH v5 13/13 MAINTAINERS: update ENETC driver files and maintainers
In reply to Wei FangAdd related YAML documentation and header files. Also, add maintainers from the i.MX side as ENETC starts to be used on i.MX platforms.
---
v5: no changes
--- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
@@ -9018,9 +9018,16 @@ F: drivers/dma/fsl-edma*.* FREESCALE ENETC ETHERNET DRIVERS M: Claudiu Manoil <[email protected]> M: Vladimir Oltean <[email protected]> +M: Wei Fang <[email protected]> +M: Clark Wang <[email protected]> +L: [email protected] L: [email protected] S: Maintained +F: Documentation/devicetree/bindings/net/fsl,enetc*.yaml +F: Documentation/devicetree/bindings/net/nxp,netc-blk-ctrl.yaml F: drivers/net/ethernet/freescale/enetc/ +F: include/linux/fsl/enetc_mdio.h +F: include/linux/fsl/netc_global.h FREESCALE eTSEC ETHERNET DRIVER (GIANFAR) M: Claudiu Manoil <[email protected]>
Signature · 1 line
2.34.1