add basic support for i.MX95 NETC
Subsystems (7)
Wei Fang
maintainerv6 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]/
v5 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 (9):
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
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 | 28 +- .../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 | 269 ++++--- drivers/net/ethernet/freescale/enetc/enetc.h | 30 +- .../net/ethernet/freescale/enetc/enetc4_hw.h | 155 ++++ .../net/ethernet/freescale/enetc/enetc4_pf.c | 756 ++++++++++++++++++ .../ethernet/freescale/enetc/enetc_ethtool.c | 35 +- .../net/ethernet/freescale/enetc/enetc_hw.h | 53 +- .../ethernet/freescale/enetc/enetc_pci_mdio.c | 31 + .../net/ethernet/freescale/enetc/enetc_pf.c | 313 +------- .../net/ethernet/freescale/enetc/enetc_pf.h | 21 + .../freescale/enetc/enetc_pf_common.c | 336 ++++++++ .../freescale/enetc/enetc_pf_common.h | 19 + .../net/ethernet/freescale/enetc/enetc_qos.c | 2 +- .../net/ethernet/freescale/enetc/enetc_vf.c | 6 + .../ethernet/freescale/enetc/netc_blk_ctrl.c | 445 +++++++++++ include/linux/fsl/netc_global.h | 19 + 21 files changed, 2273 insertions(+), 416 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/enetc_pf_common.h 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 v6 1/12 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.
---
v6: 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 v6 2/12 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
v6:
1. use negate the 'if' schema (not: contains: ...)
--- .../devicetree/bindings/net/fsl,enetc.yaml | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/net/fsl,enetc.yaml +25 -3
@@ -20,14 +20,25 @@ maintainers: properties: compatible: - items: + oneOf: + - items: + - enum: + - pci1957,e100 + - const: fsl,enetc - enum: - - pci1957,e100 - - const: fsl,enetc + - pci1131,e101 reg: maxItems: 1 + clocks: + items: + - description: MAC transmit/receive reference clock + + clock-names: + items: + - const: ref + mdio: $ref: mdio.yaml unevaluatedProperties: false
@@ -40,6 +51,17 @@ required: allOf: - $ref: /schemas/pci/pci-device.yaml - $ref: ethernet-controller.yaml + - if: + not: + properties: + compatible: + contains: + enum: + - pci1131,e101 + then: + properties: + clocks: false + clock-names: false unevaluatedProperties: false
Signature · 1 line
2.34.1
Re: [PATCH v6 net-next 02/12] dt-bindings: net: add i.MX95 ENETC support
Quoted 6 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]>
Quoted 68 lines
---
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
v6:
1. use negate the 'if' schema (not: contains: ...)--- .../devicetree/bindings/net/fsl,enetc.yaml | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-)Documentation/devicetree/bindings/net/fsl,enetc.yaml +25
-4@@ -20,14 +20,25 @@ maintainers: properties: compatible: - items: + oneOf: + - items: + - enum: + - pci1957,e100 + - const: fsl,enetc - enum: - - pci1957,e100 - - const: fsl,enetc + - pci1131,e101 reg: maxItems: 1 + clocks: + items: + - description: MAC transmit/receive reference clock + + clock-names: + items: + - const: ref + mdio: $ref: mdio.yaml unevaluatedProperties: false@@ -40,6 +51,17 @@ required: allOf: - $ref: /schemas/pci/pci-device.yaml - $ref: ethernet-controller.yaml + - if: + not: + properties: + compatible: + contains: + enum: + - pci1131,e101 + then: + properties: + clocks: false + clock-names: false unevaluatedProperties: false --2.34.1
Re: [PATCH v6 net-next 02/12] dt-bindings: net: add i.MX95 ENETC support
In reply to Wei FangQuoted 16 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
v6:
1. use negate the 'if' schema (not: contains: ...)
Quoted 4 lines
--- .../devicetree/bindings/net/fsl,enetc.yaml | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-)
Wei Fang
maintainerPATCH v6 3/12 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.
---
v6: no changes
--- .../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
Wei Fang
maintainerPATCH v6 4/12 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.
---
v6: only add some opening comments at the beginning of netc_blk_ctrl.c
--- drivers/net/ethernet/freescale/enetc/Kconfig | 14 + drivers/net/ethernet/freescale/enetc/Makefile | 3 + .../ethernet/freescale/enetc/netc_blk_ctrl.c | 445 ++++++++++++++++++ include/linux/fsl/netc_global.h | 19 + 4 files changed, 481 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 +445 -0
445 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
Wei Fang
maintainerPATCH v6 5/12 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.
---
v6:
1. add enetc_pf_common.h and put the prototypes of functions exported by enetc_pf_common.c into enetc_pf_common.h
2. add linux/of.h to enetc_pf.c due to undeclared function 'of_device_is_available'
--- drivers/net/ethernet/freescale/enetc/Makefile | 2 +- .../net/ethernet/freescale/enetc/enetc_pf.c | 300 +----------------- .../freescale/enetc/enetc_pf_common.c | 295 +++++++++++++++++ .../freescale/enetc/enetc_pf_common.h | 17 + 4 files changed, 319 insertions(+), 295 deletions(-) create mode 100644 drivers/net/ethernet/freescale/enetc/enetc_pf_common.c create mode 100644 drivers/net/ethernet/freescale/enetc/enetc_pf_common.h
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 +6 -294
350 lines not on this page · raw message
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c new file +295 -0
295 lines not on this page · raw message
drivers/net/ethernet/freescale/enetc/enetc_pf_common.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */ +/* Copyright 2024 NXP */ + +#include "enetc_pf.h" + +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);
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH v6 6/12 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.
---
v6:
1. remove enetc_pf_ops_register()
2. do not check enetc_pf_ops::set_si_primary_mac() and enetc_pf_ops::get_si_primary_mac(), because both enetc v1 and v4 drivers supports them
3. add enetc_get_si_hw_addr()
4. add dev_err() message if pf->ops->create_pcs() is NULL
--- 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 | 12 +++++ .../freescale/enetc/enetc_pf_common.c | 50 +++++++++++++++---- .../freescale/enetc/enetc_pf_common.h | 3 -- 6 files changed, 89 insertions(+), 16 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
@@ -12,7 +12,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));
@@ -21,8 +21,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 );
@@ -31,6 +31,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 );
@@ -971,6 +982,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) {
@@ -998,6 +1017,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); + pf->ops = &enetc_pf_ops; err =enetc_setup_mac_addresses (node, pf);if (err)
drivers/net/ethernet/freescale/enetc/enetc_pf.h +12 -0
@@ -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) \
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +41 -9
149 lines not on this page · raw message
drivers/net/ethernet/freescale/enetc/enetc_pf_common.h +0 -3
@@ -3,9 +3,6 @@#include "enetc_pf.h" -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,
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH v6 7/12 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.
---
v6:
1. add helper functions to enable/disable the static key
2. disable the static key if of_mdiobus_register() returns error
--- .../net/ethernet/freescale/enetc/enetc_hw.h | 34 +++++++++++++------ .../ethernet/freescale/enetc/enetc_pci_mdio.c | 28 +++++++++++++++ 2 files changed, 52 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 +28 -0
@@ -9,6 +9,28 @@#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 void enetc_emdio_enable_err050089 (struct pci_dev *pdev) +{ +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" ); + } +} + +static void enetc_emdio_disable_err050089 (struct pci_dev *pdev) +{ +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" ); + } +} +static int enetc_pci_mdio_probe (struct pci_dev *pdev,const struct pci_device_id *ent) {
@@ -62,6 +84,8 @@ static int enetc_pci_mdio_probe(struct pci_dev *pdev, goto err_pci_mem_reg; } +enetc_emdio_enable_err050089 (pdev); + err =of_mdiobus_register (bus, dev->of_node);if (err) goto err_mdiobus_reg;
@@ -71,6 +95,7 @@ static int enetc_pci_mdio_probe(struct pci_dev *pdev,return 0 ; err_mdiobus_reg: +enetc_emdio_disable_err050089 (pdev);pci_release_region (pdev,0 ); err_pci_mem_reg:pci_disable_device (pdev);
@@ -88,6 +113,9 @@ static void enetc_pci_mdio_remove(struct pci_dev *pdev)struct enetc_mdio_priv *mdio_priv;mdiobus_unregister (bus); + +enetc_emdio_disable_err050089 (pdev); + mdio_priv = bus->priv;iounmap (mdio_priv->hw->port);pci_release_region (pdev,0 );
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH v6 8/12 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.
---
v6:
1. remove pinctrl_pm_select_default_state()
2. Add macros to define the vendor ID and device ID of EMDIO.
--- drivers/net/ethernet/freescale/enetc/enetc_pci_mdio.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/ethernet/freescale/enetc/enetc_pci_mdio.c +3 -0
@@ -4,6 +4,8 @@#include <linux/of_mdio.h> #include "enetc_pf.h" +#define NETC_EMDIO_VEN_ID 0x1131 +#define NETC_EMDIO_DEV_ID 0xee00#define ENETC_MDIO_DEV_ID 0xee01#define ENETC_MDIO_DEV_NAME "FSL PCIe IE Central MDIO"#define ENETC_MDIO_BUS_NAME ENETC_MDIO_DEV_NAME " Bus"
@@ -124,6 +126,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 (NETC_EMDIO_VEN_ID ,NETC_EMDIO_DEV_ID ) }, {0 , }/* End of table. */ };MODULE_DEVICE_TABLE (pci, enetc_pci_mdio_id_table);
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH v6 9/12 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.
---
v6:
1. remove the cleanup helper functions
--- drivers/net/ethernet/freescale/enetc/enetc.c | 177 ++++++++++--------- 1 file changed, 92 insertions(+), 85 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc.c +92 -85
@@ -2995,6 +2995,92 @@ 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; +struct enetc_bdr *bdr; +int j, err; + + v =kzalloc (struct_size (v, tx_ring, v_tx_rings),GFP_KERNEL ); +if (!v) +return -ENOMEM ; + + 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) + goto free_vector; + + err =xdp_rxq_info_reg_mem_model (&bdr->xdp.rxq,MEM_TYPE_PAGE_SHARED , +NULL ); +if (err) { +xdp_rxq_info_unreg (&bdr->xdp.rxq); + goto free_vector; + } + +/* 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; + } + +return 0 ; + +free_vector: + priv->rx_ring[i] =NULL ; + priv->int_vector[i] =NULL ; +kfree (v); + +return err; +} + +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); + +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 ; + } + + priv->rx_ring[i] =NULL ; + priv->int_vector[i] =NULL ; +kfree (v); +} +int enetc_alloc_msix (struct enetc_ndev_priv *priv) {struct pci_dev *pdev = priv->si->pdev;
@@ -3017,62 +3103,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);
@@ -3092,16 +3125,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);
@@ -3113,26 +3138,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
Wei Fang
maintainerPATCH v6 10/12 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.
---
v6: only add a opening comment in the code
--- drivers/net/ethernet/freescale/enetc/enetc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc.c +8 -2
@@ -3084,10 +3084,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 */
@@ -3101,9 +3101,15 @@ 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); +/* Distribute the remaining TX rings to the first v_remainder +* interrupt vectors +*/ +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
Wei Fang
maintainerPATCH v6 11/12 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. In addition, PCS support has not been added yet, so 10G ENETC (ENETC instance 2) is not supported now.
---
v6:
1. remove pinctrl_pm_select_default_state()
2. add macros to define the vendor ID and device ID of ENETC PF
--- 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 | 155 ++++ .../net/ethernet/freescale/enetc/enetc4_pf.c | 756 ++++++++++++++++++ .../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 | 9 + .../freescale/enetc/enetc_pf_common.c | 11 +- .../freescale/enetc/enetc_pf_common.h | 5 + .../net/ethernet/freescale/enetc/enetc_qos.c | 2 +- .../net/ethernet/freescale/enetc/enetc_vf.c | 6 + 14 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;
@@ -341,7 +361,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;
@@ -389,6 +408,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 */
@@ -418,6 +440,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);
@@ -434,6 +457,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 +155 -0
155 lines not on this page · raw message
drivers/net/ethernet/freescale/enetc/enetc4_pf.c new file +756 -0
756 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
@@ -947,6 +947,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 +9 -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; };
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +10 -1
@@ -100,6 +100,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 ;
@@ -116,10 +117,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 ;
@@ -131,6 +139,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_pf_common.h +5 -0
@@ -12,3 +12,8 @@ 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 u16 enetc_get_ip_revision (struct enetc_hw *hw) +{ +return enetc_global_rd (hw,ENETC_G_EIPBRR0 ) &EIPBRR0_REVISION ; +}
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
Re: [PATCH v6 net-next 11/12] net: enetc: add preliminary support for i.MX95 ENETC PF
Quoted 83 lines · Wei Fang
The 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. In addition, PCS support has not been added yet, so 10G ENETC (ENETC instance 2) is not supported now.
Signed-off-by Wei Fang <[email protected]>---
v6:
1. removepinctrl_pm_select_default_state()
2. add macros to define the vendor ID and device ID of ENETC PF--- 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 | 155 ++++ .../net/ethernet/freescale/enetc/enetc4_pf.c | 756 ++++++++++++++++++ .../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 | 9 + .../freescale/enetc/enetc_pf_common.c | 11 +- .../freescale/enetc/enetc_pf_common.h | 5 + .../net/ethernet/freescale/enetc/enetc_qos.c | 2 +- .../net/ethernet/freescale/enetc/enetc_vf.c | 6 + 14 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.cdrivers/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_MSIdrivers/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.odrivers/net/ethernet/freescale/enetc/enetc.c +0
-0
drivers/net/ethernet/freescale/enetc/enetc.c line 4
Quoted 2 lines
drivers/net/ethernet/freescale/enetc/enetc.c +0
-0@@ -3,6 +3,7 @@#include "enetc.h"
nit: generally private header file should be after common header file. #include "..." should after #include <...>
Quoted 1,449 lines
drivers/net/ethernet/freescale/enetc/enetc.c +77
-9#include <linux/bpf_trace.h> +#include <linux/clk.h> #include <linux/tcp.h> #include <linux/udp.h> #include <linux/vmalloc.h> @@ -21,7 +22,7 @@ void enetc_port_mac_wr(struct enetc_si *si, u32 reg, u32 val) {enetc_port_wr (&si->hw, reg, val);if (si->hw_features &ENETC_SI_F_QBU ) -enetc_port_wr (&si->hw, reg +ENETC_PMAC_OFFSET , val); +enetc_port_wr (&si->hw, reg + si->drvdata->pmac_offset, val); }EXPORT_SYMBOL_GPL (enetc_port_mac_wr);@@ -700,8 +701,9 @@ static void enetc_rx_dim_work(struct work_struct *w)net_dim_get_rx_moderation (dim->mode, dim->profile_ix);struct enetc_int_vector *v = container_of(dim, struct enetc_int_vector, rx_dim); +struct enetc_ndev_priv *priv =netdev_priv (v->rx_ring.ndev); - v->rx_ictt =enetc_usecs_to_cycles (moder.usec); + v->rx_ictt =enetc_usecs_to_cycles (moder.usec, priv->sysclk_freq); dim->state =DIM_START_MEASURE ; }@@ -1736,9 +1738,15 @@ void enetc_get_si_caps(struct enetc_si *si) si->num_rx_rings = (val >>16 ) &0xff ; si->num_tx_rings = val &0xff ; - val =enetc_rd (hw,ENETC_SIRFSCAPR ); - si->num_fs_entries =ENETC_SIRFSCAPR_GET_NUM_RFS (val); - si->num_fs_entries =min (si->num_fs_entries,ENETC_MAX_RFS_SIZE ); + val =enetc_rd (hw,ENETC_SIPCAPR0 ); +if (val &ENETC_SIPCAPR0_RFS ) { + val =enetc_rd (hw,ENETC_SIRFSCAPR ); + si->num_fs_entries =ENETC_SIRFSCAPR_GET_NUM_RFS (val); + si->num_fs_entries =min (si->num_fs_entries,ENETC_MAX_RFS_SIZE ); + }else { +/* ENETC which not supports RFS */ + si->num_fs_entries =0 ; + } si->num_rss =0 ; val =enetc_rd (hw,ENETC_SIPCAPR0 );@@ -2066,7 +2074,10 @@ int enetc_configure_si(struct enetc_ndev_priv *priv)/* enable SI */ enetc_wr (hw,ENETC_SIMR ,ENETC_SIMR_EN ); -if (si->num_rss) { +/* TODO: RSS support for i.MX95 will be supported later, and the +* is_enetc_rev1() condition will be removed +*/ +if (si->num_rss &&is_enetc_rev1 (si)) { err =enetc_setup_default_rss_table (si, priv->num_rx_rings);if (err)return err;@@ -2090,9 +2101,9 @@ void enetc_init_si_rings_params(struct enetc_ndev_priv *priv)*/ priv->num_rx_rings =min_t (int, cpus, si->num_rx_rings); priv->num_tx_rings = si->num_tx_rings; - priv->bdr_int_num = cpus; + priv->bdr_int_num = priv->num_rx_rings; priv->ic_mode =ENETC_IC_RX_ADAPTIVE |ENETC_IC_TX_MANUAL ; - priv->tx_ictt =ENETC_TXIC_TIMETHR ; + priv->tx_ictt =enetc_usecs_to_cycles (600 , priv->sysclk_freq); }EXPORT_SYMBOL_GPL (enetc_init_si_rings_params);@@ -2501,10 +2512,14 @@ int enetc_open(struct net_device *ndev) extended = !!(priv->active_offloads &ENETC_F_RX_TSTAMP ); - err =enetc_setup_irqs (priv); + err =clk_prepare_enable (priv->ref_clk);if (err)return err; + err =enetc_setup_irqs (priv); +if (err) + goto err_setup_irqs; + err =enetc_phylink_connect (ndev);if (err) goto err_phy_connect;@@ -2536,6 +2551,8 @@ int enetc_open(struct net_device *ndev)phylink_disconnect_phy (priv->phylink); err_phy_connect:enetc_free_irqs (priv); +err_setup_irqs: +clk_disable_unprepare (priv->ref_clk);return err; }@@ -2589,6 +2606,7 @@ int enetc_close(struct net_device *ndev)enetc_assign_tx_resources (priv,NULL );enetc_free_irqs (priv); +clk_disable_unprepare (priv->ref_clk);return 0 ; }@@ -3254,5 +3272,55 @@ void enetc_pci_remove(struct pci_dev *pdev) }EXPORT_SYMBOL_GPL (enetc_pci_remove); +static const struct enetc_drvdata enetc_pf_data = { + .sysclk_freq =ENETC_CLK_400M , + .pmac_offset =ENETC_PMAC_OFFSET , + .eth_ops = &enetc_pf_ethtool_ops, +}; + +static const struct enetc_drvdata enetc4_pf_data = { + .sysclk_freq =ENETC_CLK_333M , + .pmac_offset =ENETC4_PMAC_OFFSET , + .eth_ops = &enetc4_pf_ethtool_ops, +}; + +static const struct enetc_drvdata enetc_vf_data = { + .sysclk_freq =ENETC_CLK_400M , + .eth_ops = &enetc_vf_ethtool_ops, +}; + +static const struct enetc_platform_info enetc_info[] = { + { .revision =ENETC_REV_1_0 , + .dev_id =ENETC_DEV_ID_PF , + .data = &enetc_pf_data, + }, + { .revision =ENETC_REV_4_1 , + .dev_id =NXP_ENETC_PF_DEV_ID , + .data = &enetc4_pf_data, + }, + { .revision =ENETC_REV_1_0 , + .dev_id =ENETC_DEV_ID_VF , + .data = &enetc_vf_data, + }, +}; + +int enetc_get_driver_data (struct enetc_si *si) +{ +u16 dev_id = si->pdev->device; +int i; + +for (i =0 ; i <ARRAY_SIZE (enetc_info); i++) { +if (si->revision == enetc_info[i].revision && + dev_id == enetc_info[i].dev_id) { + si->drvdata = enetc_info[i].data; + +return 0 ; + } + } + +return -ERANGE ; +} +EXPORT_SYMBOL_GPL (enetc_get_driver_data); +MODULE_DESCRIPTION ("NXP ENETC Ethernet driver" );MODULE_LICENSE ("Dual BSD/GPL" );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;@@ -341,7 +361,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;@@ -389,6 +408,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 */ @@ -418,6 +440,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);@@ -434,6 +457,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 +155
-0@@ -0,0 +1,155 @@ +/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */ +/* +* This header file defines the register offsets and bit fields +* of ENETC4 PF and VFs. Note that the same registers as ENETC +* version 1.0 are defined in the enetc_hw.h file. +* +* Copyright 2024 NXP +*/ +#ifndef __ENETC4_HW_H_ +#define __ENETC4_HW_H_ + +#define NXP_ENETC_VENDOR_ID 0x1131 +#define NXP_ENETC_PF_DEV_ID 0xe101 + +/***************************ENETC port registers**************************/ +#define ENETC4_ECAPR0 0x0 +#define ECAPR0_RFS BIT(2) +#define ECAPR0_TSD BIT(5) +#define ECAPR0_RSS BIT(8) +#define ECAPR0_RSC BIT(9) +#define ECAPR0_LSO BIT(10) +#define ECAPR0_WO BIT(13) + +#define ENETC4_ECAPR1 0x4 +#define ECAPR1_NUM_TCS GENMASK(6, 4) +#define ECAPR1_NUM_MCH GENMASK(9, 8) +#define ECAPR1_NUM_UCH GENMASK(11, 10) +#define ECAPR1_NUM_MSIX GENMASK(22, 12) +#define ECAPR1_NUM_VSI GENMASK(27, 24) +#define ECAPR1_NUM_IPV BIT(31) + +#define ENETC4_ECAPR2 0x8 +#define ECAPR2_NUM_TX_BDR GENMASK(9, 0) +#define ECAPR2_NUM_RX_BDR GENMASK(25, 16) + +#define ENETC4_PMR 0x10 +#define PMR_SI_EN (a) BIT((16 + (a))) + +/* Port Pause ON/OFF threshold register */ +#define ENETC4_PPAUONTR 0x108 +#define ENETC4_PPAUOFFTR 0x10c + +/* Port Station interface promiscuous MAC mode register */ +#define ENETC4_PSIPMMR 0x200 +#define PSIPMMR_SI_MAC_UP (a) BIT(a)/* a = SI index */ +#define PSIPMMR_SI_MAC_MP (a) BIT((a) + 16) + +/* Port Station interface promiscuous VLAN mode register */ +#define ENETC4_PSIPVMR 0x204 + +/* Port RSS key register n. n = 0,1,2,...,9 */ +#define ENETC4_PRSSKR (n) ((n) * 0x4 + 0x250) + +/* Port station interface MAC address filtering capability register */ +#define ENETC4_PSIMAFCAPR 0x280 +#define PSIMAFCAPR_NUM_MAC_AFTE GENMASK(11, 0) + +/* Port station interface VLAN filtering capability register */ +#define ENETC4_PSIVLANFCAPR 0x2c0 +#define PSIVLANFCAPR_NUM_VLAN_FTE GENMASK(11, 0) + +/* Port station interface VLAN filtering mode register */ +#define ENETC4_PSIVLANFMR 0x2c4 +#define PSIVLANFMR_VS BIT(0) + +/* Port Station interface a primary MAC address registers */ +#define ENETC4_PSIPMAR0 (a) ((a) * 0x80 + 0x2000) +#define ENETC4_PSIPMAR1 (a) ((a) * 0x80 + 0x2004) + +/* Port station interface a configuration register 0/2 */ +#define ENETC4_PSICFGR0 (a) ((a) * 0x80 + 0x2010) +#define PSICFGR0_VASE BIT(13) +#define PSICFGR0_ASE BIT(15) +#define PSICFGR0_ANTI_SPOOFING (PSICFGR0_VASE | PSICFGR0_ASE) + +#define ENETC4_PSICFGR2 (a) ((a) * 0x80 + 0x2018) +#define PSICFGR2_NUM_MSIX GENMASK(5, 0) + +#define ENETC4_PMCAPR 0x4004 +#define PMCAPR_HD BIT(8) +#define PMCAPR_FP GENMASK(10, 9) + +/* Port configuration register */ +#define ENETC4_PCR 0x4010 +#define PCR_HDR_FMT BIT(0) +#define PCR_L2DOSE BIT(4) +#define PCR_TIMER_CS BIT(8) +#define PCR_PSPEED GENMASK(29, 16) +#define PCR_PSPEED_VAL (speed) (((speed) / 10 - 1) << 16) + +/* Port MAC address register 0/1 */ +#define ENETC4_PMAR0 0x4020 +#define ENETC4_PMAR1 0x4024 + +/* Port operational register */ +#define ENETC4_POR 0x4100 + +/* Port traffic class a transmit maximum SDU register */ +#define ENETC4_PTCTMSDUR (a) ((a) * 0x20 + 0x4208) +#define PTCTMSDUR_MAXSDU GENMASK(15, 0) +#define PTCTMSDUR_SDU_TYPE GENMASK(17, 16) +#define SDU_TYPE_PPDU 0 +#define SDU_TYPE_MPDU 1 +#define SDU_TYPE_MSDU 2 + +#define ENETC4_PMAC_OFFSET 0x400 +#define ENETC4_PM_CMD_CFG (mac) (0x5008 + (mac) * 0x400) +#define PM_CMD_CFG_TX_EN BIT(0) +#define PM_CMD_CFG_RX_EN BIT(1) +#define PM_CMD_CFG_PAUSE_FWD BIT(7) +#define PM_CMD_CFG_PAUSE_IGN BIT(8) +#define PM_CMD_CFG_TX_ADDR_INS BIT(9) +#define PM_CMD_CFG_LOOP_EN BIT(10) +#define PM_CMD_CFG_LPBK_MODE GENMASK(12, 11) +#define LPBCK_MODE_EXT_TX_CLK 0 +#define LPBCK_MODE_MAC_LEVEL 1 +#define LPBCK_MODE_INT_TX_CLK 2 +#define PM_CMD_CFG_CNT_FRM_EN BIT(13) +#define PM_CMD_CFG_TXP BIT(15) +#define PM_CMD_CFG_SEND_IDLE BIT(16) +#define PM_CMD_CFG_HD_FCEN BIT(18) +#define PM_CMD_CFG_SFD BIT(21) +#define PM_CMD_CFG_TX_FLUSH BIT(22) +#define PM_CMD_CFG_TX_LOWP_EN BIT(23) +#define PM_CMD_CFG_RX_LOWP_EMPTY BIT(24) +#define PM_CMD_CFG_SWR BIT(26) +#define PM_CMD_CFG_TS_MODE BIT(30) +#define PM_CMD_CFG_MG BIT(31) + +/* Port MAC 0/1 Maximum Frame Length Register */ +#define ENETC4_PM_MAXFRM (mac) (0x5014 + (mac) * 0x400) + +/* Port MAC 0/1 Pause Quanta Register */ +#define ENETC4_PM_PAUSE_QUANTA (mac) (0x5054 + (mac) * 0x400) + +/* Port MAC 0/1 Pause Quanta Threshold Register */ +#define ENETC4_PM_PAUSE_THRESH (mac) (0x5064 + (mac) * 0x400) + +/* Port MAC 0 Interface Mode Control Register */ +#define ENETC4_PM_IF_MODE (mac) (0x5300 + (mac) * 0x400) +#define PM_IF_MODE_IFMODE GENMASK(2, 0) +#define IFMODE_XGMII 0 +#define IFMODE_RMII 3 +#define IFMODE_RGMII 4 +#define IFMODE_SGMII 5 +#define PM_IF_MODE_REVMII BIT(3) +#define PM_IF_MODE_M10 BIT(4) +#define PM_IF_MODE_HD BIT(6) +#define PM_IF_MODE_SSP GENMASK(14, 13) +#define SSP_100M 0 +#define SSP_10M 1 +#define SSP_1G 2 +#define PM_IF_MODE_ENA BIT(15) + +#endif drivers/net/ethernet/freescale/enetc/enetc4_pf.c new file +756
-0@@ -0,0 +1,756 @@ +// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) +/* Copyright 2024 NXP */ + +#include <linux/clk.h> +#include <linux/module.h> +#include <linux/of_net.h> +#include <linux/of_platform.h> +#include <linux/unaligned.h> + +#include "enetc_pf_common.h" + +#define ENETC_SI_MAX_RING_NUM 8 + +static void enetc4_get_port_caps (struct enetc_pf *pf) +{ +struct enetc_hw *hw = &pf->si->hw; +u32 val; + + val =enetc_port_rd (hw,ENETC4_ECAPR1 ); + pf->caps.num_vsi = (val &ECAPR1_NUM_VSI ) >>24 ; + pf->caps.num_msix = ((val &ECAPR1_NUM_MSIX ) >>12 ) +1 ; + + val =enetc_port_rd (hw,ENETC4_ECAPR2 ); + pf->caps.num_rx_bdr = (val &ECAPR2_NUM_RX_BDR ) >>16 ; + pf->caps.num_tx_bdr = val &ECAPR2_NUM_TX_BDR ; + + val =enetc_port_rd (hw,ENETC4_PMCAPR ); + pf->caps.half_duplex = (val &PMCAPR_HD ) ?1 :0 ; +} + +static void enetc4_pf_set_si_primary_mac (struct enetc_hw *hw,int si, +const u8 *addr) +{ +u16 lower =get_unaligned_le16 (addr +4 ); +u32 upper =get_unaligned_le32 (addr); + +if (si !=0 ) { +__raw_writel (upper, hw->port +ENETC4_PSIPMAR0 (si)); +__raw_writew (lower, hw->port +ENETC4_PSIPMAR1 (si)); + }else { +__raw_writel (upper, hw->port +ENETC4_PMAR0 ); +__raw_writew (lower, hw->port +ENETC4_PMAR1 ); + } +} + +static void enetc4_pf_get_si_primary_mac (struct enetc_hw *hw,int si, +u8 *addr) +{ +u32 upper; +u16 lower; + + upper =__raw_readl (hw->port +ENETC4_PSIPMAR0 (si)); + lower =__raw_readw (hw->port +ENETC4_PSIPMAR1 (si)); + +put_unaligned_le32 (upper, addr); +put_unaligned_le16 (lower, addr +4 ); +} + +static const struct enetc_pf_ops enetc4_pf_ops = { + .set_si_primary_mac = enetc4_pf_set_si_primary_mac, + .get_si_primary_mac = enetc4_pf_get_si_primary_mac, +}; + +static int enetc4_pf_struct_init (struct enetc_si *si) +{ +struct enetc_pf *pf =enetc_si_priv (si); + + pf->si = si; + pf->total_vfs =pci_sriov_get_totalvfs (si->pdev); + pf->ops = &enetc4_pf_ops; + +enetc4_get_port_caps (pf); + +return 0 ; +} + +static u32 enetc4_psicfgr0_val_construct (bool is_vf,u32 num_tx_bdr,u32 num_rx_bdr) +{ +u32 val; + + val =ENETC_PSICFGR0_SET_TXBDR (num_tx_bdr); + val |=ENETC_PSICFGR0_SET_RXBDR (num_rx_bdr); + val |=ENETC_PSICFGR0_SIVC (ENETC_VLAN_TYPE_C |ENETC_VLAN_TYPE_S ); + +if (is_vf) + val |=ENETC_PSICFGR0_VTE |ENETC_PSICFGR0_SIVIE ; + +return val; +} + +static void enetc4_default_rings_allocation (struct enetc_pf *pf) +{ +struct enetc_hw *hw = &pf->si->hw; +u32 num_rx_bdr, num_tx_bdr, val; +u32 vf_tx_bdr, vf_rx_bdr; +int i, rx_rem, tx_rem; + +if (pf->caps.num_rx_bdr <ENETC_SI_MAX_RING_NUM + pf->caps.num_vsi) + num_rx_bdr = pf->caps.num_rx_bdr - pf->caps.num_vsi; +else + num_rx_bdr =ENETC_SI_MAX_RING_NUM ; + +if (pf->caps.num_tx_bdr <ENETC_SI_MAX_RING_NUM + pf->caps.num_vsi) + num_tx_bdr = pf->caps.num_tx_bdr - pf->caps.num_vsi; +else + num_tx_bdr =ENETC_SI_MAX_RING_NUM ; + + val =enetc4_psicfgr0_val_construct (false, num_tx_bdr, num_rx_bdr); +enetc_port_wr (hw,ENETC4_PSICFGR0 (0 ), val); + + num_rx_bdr = pf->caps.num_rx_bdr - num_rx_bdr; + rx_rem = num_rx_bdr % pf->caps.num_vsi; + num_rx_bdr = num_rx_bdr / pf->caps.num_vsi; + + num_tx_bdr = pf->caps.num_tx_bdr - num_tx_bdr; + tx_rem = num_tx_bdr % pf->caps.num_vsi; + num_tx_bdr = num_tx_bdr / pf->caps.num_vsi; + +for (i =0 ; i < pf->caps.num_vsi; i++) { + vf_tx_bdr = (i < tx_rem) ? num_tx_bdr +1 : num_tx_bdr; + vf_rx_bdr = (i < rx_rem) ? num_rx_bdr +1 : num_rx_bdr; + val =enetc4_psicfgr0_val_construct (true, vf_tx_bdr, vf_rx_bdr); +enetc_port_wr (hw,ENETC4_PSICFGR0 (i +1 ), val); + } +} + +static void enetc4_allocate_si_rings (struct enetc_pf *pf) +{ +enetc4_default_rings_allocation (pf); +} + +static void enetc4_pf_set_si_vlan_promisc (struct enetc_hw *hw,int si,bool en) +{ +u32 val =enetc_port_rd (hw,ENETC4_PSIPVMR ); + +if (en) + val |=BIT (si); +else + val &= ~BIT (si); + +enetc_port_wr (hw,ENETC4_PSIPVMR , val); +} + +static void enetc4_set_default_si_vlan_promisc (struct enetc_pf *pf) +{ +struct enetc_hw *hw = &pf->si->hw; +int num_si = pf->caps.num_vsi +1 ; +int i; + +/* enforce VLAN promiscuous mode for all SIs */ +for (i =0 ; i < num_si; i++) +enetc4_pf_set_si_vlan_promisc (hw, i, true); +} + +/* Allocate the number of MSI-X vectors for per SI. */ +static void enetc4_set_si_msix_num (struct enetc_pf *pf) +{ +struct enetc_hw *hw = &pf->si->hw; +int i, num_msix, total_si; +u32 val; + + total_si = pf->caps.num_vsi +1 ; + + num_msix = pf->caps.num_msix / total_si + + pf->caps.num_msix % total_si -1 ; + val = num_msix &PSICFGR2_NUM_MSIX ; +enetc_port_wr (hw,ENETC4_PSICFGR2 (0 ), val); + + num_msix = pf->caps.num_msix / total_si -1 ; + val = num_msix &PSICFGR2_NUM_MSIX ; +for (i =0 ; i < pf->caps.num_vsi; i++) +enetc_port_wr (hw,ENETC4_PSICFGR2 (i +1 ), val); +} + +static void enetc4_enable_all_si (struct enetc_pf *pf) +{ +struct enetc_hw *hw = &pf->si->hw; +int num_si = pf->caps.num_vsi +1 ; +u32 si_bitmap =0 ; +int i; + +/* Master enable for all SIs */ +for (i =0 ; i < num_si; i++) + si_bitmap |=PMR_SI_EN (i); + +enetc_port_wr (hw,ENETC4_PMR , si_bitmap); +} + +static void enetc4_configure_port_si (struct enetc_pf *pf) +{ +struct enetc_hw *hw = &pf->si->hw; + +enetc4_allocate_si_rings (pf); + +/* Outer VLAN tag will be used for VLAN filtering */ +enetc_port_wr (hw,ENETC4_PSIVLANFMR ,PSIVLANFMR_VS ); + +enetc4_set_default_si_vlan_promisc (pf); + +/* Disable SI MAC multicast & unicast promiscuous */ +enetc_port_wr (hw,ENETC4_PSIPMMR ,0 ); + +enetc4_set_si_msix_num (pf); + +enetc4_enable_all_si (pf); +} + +static void enetc4_pf_reset_tc_msdu (struct enetc_hw *hw) +{ +u32 val =ENETC_MAC_MAXFRM_SIZE ; +int tc; + + val =u32_replace_bits (val,SDU_TYPE_MPDU ,PTCTMSDUR_SDU_TYPE ); + +for (tc =0 ; tc <ENETC_NUM_TC ; tc++) +enetc_port_wr (hw,ENETC4_PTCTMSDUR (tc), val); +} + +static void enetc4_set_trx_frame_size (struct enetc_pf *pf) +{ +struct enetc_si *si = pf->si; + +enetc_port_mac_wr (si,ENETC4_PM_MAXFRM (0 ), +ENETC_SET_MAXFRM (ENETC_MAC_MAXFRM_SIZE )); + +enetc4_pf_reset_tc_msdu (&si->hw); +} + +static void enetc4_set_rss_key (struct enetc_hw *hw,const u8 *bytes) +{ +int i; + +for (i =0 ; i <ENETC_RSSHASH_KEY_SIZE /4 ; i++) +enetc_port_wr (hw,ENETC4_PRSSKR (i), ((u32 *)bytes)[i]); +} + +static void enetc4_set_default_rss_key (struct enetc_pf *pf) +{ +u8 hash_key[ENETC_RSSHASH_KEY_SIZE ] = {0 }; +struct enetc_hw *hw = &pf->si->hw; + +/* set up hash key */ +get_random_bytes (hash_key,ENETC_RSSHASH_KEY_SIZE ); +enetc4_set_rss_key (hw, hash_key); +} + +static void enetc4_enable_trx (struct enetc_pf *pf) +{ +struct enetc_hw *hw = &pf->si->hw; + +/* Enable port transmit/receive */ +enetc_port_wr (hw,ENETC4_POR ,0 ); +} + +static void enetc4_configure_port (struct enetc_pf *pf) +{ +enetc4_configure_port_si (pf); +enetc4_set_trx_frame_size (pf); +enetc4_set_default_rss_key (pf); +enetc4_enable_trx (pf); +} + +static int enetc4_pf_init (struct enetc_pf *pf) +{ +struct device *dev = &pf->si->pdev->dev; +int err; + +/* Initialize the MAC address for PF and VFs */ + err =enetc_setup_mac_addresses (dev->of_node, pf); +if (err) { +dev_err (dev,"Failed to set MAC addresses\n" ); +return err; + } + +enetc4_configure_port (pf); + +return 0 ; +} + +static const struct net_device_ops enetc4_ndev_ops = { + .ndo_open = enetc_open, + .ndo_stop = enetc_close, + .ndo_start_xmit = enetc_xmit, + .ndo_get_stats = enetc_get_stats, + .ndo_set_mac_address = enetc_pf_set_mac_addr, +}; + +static struct phylink_pcs * +enetc4_pl_mac_select_pcs (struct phylink_config *config,phy_interface_t iface) +{ +struct enetc_pf *pf =phylink_to_enetc_pf (config); + +return pf->pcs; +} + +static void enetc4_mac_config (struct enetc_pf *pf,unsigned int mode, +phy_interface_t phy_mode) +{ +struct enetc_ndev_priv *priv =netdev_priv (pf->si->ndev); +struct enetc_si *si = pf->si; +u32 val; + + val =enetc_port_mac_rd (si,ENETC4_PM_IF_MODE (0 )); + val &= ~(PM_IF_MODE_IFMODE |PM_IF_MODE_ENA ); + +switch (phy_mode) { +case PHY_INTERFACE_MODE_RGMII : +case PHY_INTERFACE_MODE_RGMII_ID : +case PHY_INTERFACE_MODE_RGMII_RXID : +case PHY_INTERFACE_MODE_RGMII_TXID : + val |=IFMODE_RGMII ; +/* We need to enable auto-negotiation for the MAC +* if its RGMII interface support In-Band status. +*/ +if (phylink_autoneg_inband (mode)) + val |=PM_IF_MODE_ENA ; +break ; +case PHY_INTERFACE_MODE_RMII : + val |=IFMODE_RMII ; +break ; +case PHY_INTERFACE_MODE_SGMII : +case PHY_INTERFACE_MODE_2500BASEX : + val |=IFMODE_SGMII ; +break ; +case PHY_INTERFACE_MODE_10GBASER : +case PHY_INTERFACE_MODE_XGMII : +case PHY_INTERFACE_MODE_USXGMII : + val |=IFMODE_XGMII ; +break ; +default : +dev_err (priv->dev, +"Unsupported PHY mode:%d\n" , phy_mode); +return ; + } + +enetc_port_mac_wr (si,ENETC4_PM_IF_MODE (0 ), val); +} + +static void enetc4_pl_mac_config (struct phylink_config *config,unsigned int mode, +const struct phylink_link_state *state) +{ +struct enetc_pf *pf =phylink_to_enetc_pf (config); + +enetc4_mac_config (pf, mode, state->interface); +} + +static void enetc4_set_port_speed (struct enetc_ndev_priv *priv,int speed) +{ +u32 old_speed = priv->speed; +u32 val; + +if (speed == old_speed) +return ; + + val =enetc_port_rd (&priv->si->hw,ENETC4_PCR ); + val &= ~PCR_PSPEED ; + +switch (speed) { +case SPEED_100 : +case SPEED_1000 : +case SPEED_2500 : +case SPEED_10000 : + val |= (PCR_PSPEED &PCR_PSPEED_VAL (speed)); +break ; +case SPEED_10 : +default : + val |= (PCR_PSPEED &PCR_PSPEED_VAL (SPEED_10 )); + } + + priv->speed = speed; +enetc_port_wr (&priv->si->hw,ENETC4_PCR , val); +} + +static void enetc4_set_rgmii_mac (struct enetc_pf *pf,int speed,int duplex) +{ +struct enetc_si *si = pf->si; +u32 old_val, val; + + old_val =enetc_port_mac_rd (si,ENETC4_PM_IF_MODE (0 )); + val = old_val & ~(PM_IF_MODE_ENA |PM_IF_MODE_M10 |PM_IF_MODE_REVMII ); + +switch (speed) { +case SPEED_1000 : + val =u32_replace_bits (val,SSP_1G ,PM_IF_MODE_SSP ); +break ; +case SPEED_100 : + val =u32_replace_bits (val,SSP_100M ,PM_IF_MODE_SSP ); +break ; +case SPEED_10 : + val =u32_replace_bits (val,SSP_10M ,PM_IF_MODE_SSP ); + } + + val =u32_replace_bits (val, duplex ==DUPLEX_FULL ?0 :1 , +PM_IF_MODE_HD ); + +if (val == old_val) +return ; + +enetc_port_mac_wr (si,ENETC4_PM_IF_MODE (0 ), val); +} + +static void enetc4_set_rmii_mac (struct enetc_pf *pf,int speed,int duplex) +{ +struct enetc_si *si = pf->si; +u32 old_val, val; + + old_val =enetc_port_mac_rd (si,ENETC4_PM_IF_MODE (0 )); + val = old_val & ~(PM_IF_MODE_ENA |PM_IF_MODE_SSP ); + +switch (speed) { +case SPEED_100 : + val &= ~PM_IF_MODE_M10 ; +break ; +case SPEED_10 : + val |=PM_IF_MODE_M10 ; + } + + val =u32_replace_bits (val, duplex ==DUPLEX_FULL ?0 :1 , +PM_IF_MODE_HD ); + +if (val == old_val) +return ; + +enetc_port_mac_wr (si,ENETC4_PM_IF_MODE (0 ), val); +} + +static void enetc4_set_hd_flow_control (struct enetc_pf *pf,bool enable) +{ +struct enetc_si *si = pf->si; +u32 old_val, val; + +if (!pf->caps.half_duplex) +return ; + + old_val =enetc_port_mac_rd (si,ENETC4_PM_CMD_CFG (0 )); + val =u32_replace_bits (old_val, enable ?1 :0 ,PM_CMD_CFG_HD_FCEN ); +if (val == old_val) +return ; + +enetc_port_mac_wr (si,ENETC4_PM_CMD_CFG (0 ), val); +} + +static void enetc4_set_rx_pause (struct enetc_pf *pf,bool rx_pause) +{ +struct enetc_si *si = pf->si; +u32 old_val, val; + + old_val =enetc_port_mac_rd (si,ENETC4_PM_CMD_CFG (0 )); + val =u32_replace_bits (old_val, rx_pause ?0 :1 ,PM_CMD_CFG_PAUSE_IGN ); +if (val == old_val) +return ; + +enetc_port_mac_wr (si,ENETC4_PM_CMD_CFG (0 ), val); +} + +static void enetc4_set_tx_pause (struct enetc_pf *pf,int num_rxbdr,bool tx_pause) +{ +u32 pause_off_thresh =0 , pause_on_thresh =0 ; +u32 init_quanta =0 , refresh_quanta =0 ; +struct enetc_hw *hw = &pf->si->hw; +u32 rbmr, old_rbmr; +int i; + +for (i =0 ; i < num_rxbdr; i++) { + old_rbmr =enetc_rxbdr_rd (hw, i,ENETC_RBMR ); + rbmr =u32_replace_bits (old_rbmr, tx_pause ?1 :0 ,ENETC_RBMR_CM ); +if (rbmr == old_rbmr) +continue ; + +enetc_rxbdr_wr (hw, i,ENETC_RBMR , rbmr); + } + +if (tx_pause) { +/* When the port first enters congestion, send a PAUSE request +* with the maximum number of quanta. When the port exits +* congestion, it will automatically send a PAUSE frame with +* zero quanta. +*/ + init_quanta =0xffff ; + +/* Also, set up the refresh timer to send follow-up PAUSE +* frames at half the quanta value, in case the congestion +* condition persists. +*/ + refresh_quanta =0xffff /2 ; + +/* Start emitting PAUSE frames when 3 large frames (or more +* smaller frames) have accumulated in the FIFO waiting to be +* DMAed to the RX ring. +*/ + pause_on_thresh =3 *ENETC_MAC_MAXFRM_SIZE ; + pause_off_thresh =1 *ENETC_MAC_MAXFRM_SIZE ; + } + +enetc_port_mac_wr (pf->si,ENETC4_PM_PAUSE_QUANTA (0 ), init_quanta); +enetc_port_mac_wr (pf->si,ENETC4_PM_PAUSE_THRESH (0 ), refresh_quanta); +enetc_port_wr (hw,ENETC4_PPAUONTR , pause_on_thresh); +enetc_port_wr (hw,ENETC4_PPAUOFFTR , pause_off_thresh); +} + +static void enetc4_enable_mac (struct enetc_pf *pf,bool en) +{ +struct enetc_si *si = pf->si; +u32 val; + + val =enetc_port_mac_rd (si,ENETC4_PM_CMD_CFG (0 )); + val &= ~(PM_CMD_CFG_TX_EN |PM_CMD_CFG_RX_EN ); + val |= en ? (PM_CMD_CFG_TX_EN |PM_CMD_CFG_RX_EN ) :0 ; + +enetc_port_mac_wr (si,ENETC4_PM_CMD_CFG (0 ), val); +} + +static void enetc4_pl_mac_link_up (struct phylink_config *config, +struct phy_device *phy,unsigned int mode, +phy_interface_t interface,int speed, +int duplex,bool tx_pause,bool rx_pause) +{ +struct enetc_pf *pf =phylink_to_enetc_pf (config); +struct enetc_si *si = pf->si; +struct enetc_ndev_priv *priv; +bool hd_fc = false; + + priv =netdev_priv (si->ndev); +enetc4_set_port_speed (priv, speed); + +if (!phylink_autoneg_inband (mode) && +phy_interface_mode_is_rgmii (interface)) +enetc4_set_rgmii_mac (pf, speed, duplex); + +if (interface ==PHY_INTERFACE_MODE_RMII ) +enetc4_set_rmii_mac (pf, speed, duplex); + +if (duplex ==DUPLEX_FULL ) { +/* When preemption is enabled, generation of PAUSE frames +* must be disabled, as stated in the IEEE 802.3 standard. +*/ +if (priv->active_offloads &ENETC_F_QBU ) + tx_pause = false; + }else {/* DUPLEX_HALF */ +if (tx_pause || rx_pause) + hd_fc = true; + +/* As per 802.3 annex 31B, PAUSE frames are only supported +* when the link is configured for full duplex operation. +*/ + tx_pause = false; + rx_pause = false; + } + +enetc4_set_hd_flow_control (pf, hd_fc); +enetc4_set_tx_pause (pf, priv->num_rx_rings, tx_pause); +enetc4_set_rx_pause (pf, rx_pause); +enetc4_enable_mac (pf, true); +} + +static void enetc4_pl_mac_link_down (struct phylink_config *config, +unsigned int mode, +phy_interface_t interface) +{ +struct enetc_pf *pf =phylink_to_enetc_pf (config); + +enetc4_enable_mac (pf, false); +} + +static const struct phylink_mac_ops enetc_pl_mac_ops = { + .mac_select_pcs = enetc4_pl_mac_select_pcs, + .mac_config = enetc4_pl_mac_config, + .mac_link_up = enetc4_pl_mac_link_up, + .mac_link_down = enetc4_pl_mac_link_down, +}; + +static void enetc4_pci_remove (void *data) +{ +struct pci_dev *pdev = data; + +enetc_pci_remove (pdev); +} + +static int enetc4_link_init (struct enetc_ndev_priv *priv, +struct device_node *node) +{ +struct enetc_pf *pf =enetc_si_priv (priv->si); +struct device *dev = priv->dev; +int err; + + err =of_get_phy_mode (node, &pf->if_mode); +if (err) { +dev_err (dev,"Failed to get PHY mode\n" ); +return err; + } + + err =enetc_mdiobus_create (pf, node); +if (err) { +dev_err (dev,"Failed to create MDIO bus\n" ); +return err; + } + + err =enetc_phylink_create (priv, node, &enetc_pl_mac_ops); +if (err) { +dev_err (dev,"Failed to create phylink\n" ); + goto err_phylink_create; + } + +return 0 ; + +err_phylink_create: +enetc_mdiobus_destroy (pf); + +return err; +} + +static void enetc4_link_deinit (struct enetc_ndev_priv *priv) +{ +struct enetc_pf *pf =enetc_si_priv (priv->si); + +enetc_phylink_destroy (priv); +enetc_mdiobus_destroy (pf); +} + +static int enetc4_pf_netdev_create (struct enetc_si *si) +{ +struct device *dev = &si->pdev->dev; +struct enetc_ndev_priv *priv; +struct net_device *ndev; +int err; + + ndev =alloc_etherdev_mqs (sizeof (struct enetc_ndev_priv ), + si->num_tx_rings, si->num_rx_rings); +if (!ndev) +return -ENOMEM ; + + priv =netdev_priv (ndev); + priv->ref_clk =devm_clk_get_optional (dev,"ref" ); +if (IS_ERR (priv->ref_clk)) { +dev_err (dev,"Get referencce clock failed\n" ); + err =PTR_ERR (priv->ref_clk); + goto err_clk_get; + } + +enetc_pf_netdev_setup (si, ndev, &enetc4_ndev_ops); + +enetc_init_si_rings_params (priv); + + err =enetc_configure_si (priv); +if (err) { +dev_err (dev,"Failed to configure SI\n" ); + goto err_config_si; + } + + err =enetc_alloc_msix (priv); +if (err) { +dev_err (dev,"Failed to alloc MSI-X\n" ); + goto err_alloc_msix; + } + + err =enetc4_link_init (priv, dev->of_node); +if (err) + goto err_link_init; + + err =register_netdev (ndev); +if (err) { +dev_err (dev,"Failed to register netdev\n" ); + goto err_reg_netdev; + } + +return 0 ; + +err_reg_netdev: +enetc4_link_deinit (priv); +err_link_init: +enetc_free_msix (priv); +err_alloc_msix: +err_config_si: +err_clk_get: +mutex_destroy (&priv->mm_lock); +free_netdev (ndev); + +return err; +} + +static void enetc4_pf_netdev_destroy (struct enetc_si *si) +{ +struct enetc_ndev_priv *priv =netdev_priv (si->ndev); +struct net_device *ndev = si->ndev; + +unregister_netdev (ndev); +enetc_free_msix (priv); +free_netdev (ndev); +} + +static int enetc4_pf_probe (struct pci_dev *pdev, +const struct pci_device_id *ent) +{ +struct device *dev = &pdev->dev; +struct enetc_si *si; +struct enetc_pf *pf; +int err; + + err =enetc_pci_probe (pdev,KBUILD_MODNAME ,sizeof (*pf)); +if (err) +return dev_err_probe (dev, err,"PCIe probing failed\n" ); + + err =devm_add_action_or_reset (dev, enetc4_pci_remove, pdev); +if (err) +return dev_err_probe (dev, err, +"Add enetc4_pci_remove() action failed\n" ); + +/* si is the private data. */ + si =pci_get_drvdata (pdev); +if (!si->hw.port || !si->hw.global) +return dev_err_probe (dev, -ENODEV , +"Couldn't map PF only space\n" ); + + si->revision =enetc_get_ip_revision (&si->hw); + err =enetc_get_driver_data (si); +if (err) +return dev_err_probe (dev, err, +"Could not get VF driver data\n" ); + + err =enetc4_pf_struct_init (si); +if (err) +return err; + + pf =enetc_si_priv (si); + err =enetc4_pf_init (pf); +if (err) +return err; + +enetc_get_si_caps (si); + +return enetc4_pf_netdev_create (si); +} + +static void enetc4_pf_remove (struct pci_dev *pdev) +{ +struct enetc_si *si =pci_get_drvdata (pdev); + +enetc4_pf_netdev_destroy (si); +} + +static const struct pci_device_id enetc4_pf_id_table[] = { + {PCI_DEVICE (NXP_ENETC_VENDOR_ID ,NXP_ENETC_PF_DEV_ID ) }, + {0 , }/* End of table. */ +}; +MODULE_DEVICE_TABLE (pci, enetc4_pf_id_table); + +static struct pci_driver enetc4_pf_driver = { + .name =KBUILD_MODNAME , + .id_table = enetc4_pf_id_table, + .probe = enetc4_pf_probe, + .remove = enetc4_pf_remove, +}; +module_pci_driver (enetc4_pf_driver); + +MODULE_DESCRIPTION ("ENETC4 PF Driver" ); +MODULE_LICENSE ("Dual BSD/GPL" );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@@ -947,6 +947,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 +9
-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; };drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +10
-1@@ -100,6 +100,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 ;@@ -116,10 +117,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 ;@@ -131,6 +139,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_pf_common.h +5
-0@@ -12,3 +12,8 @@ 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 u16 enetc_get_ip_revision (struct enetc_hw *hw) +{ +return enetc_global_rd (hw,ENETC_G_EIPBRR0 ) &EIPBRR0_REVISION ; +}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
-1@@ -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); --2.34.1
Wei Fang
maintainerRE: [PATCH v6 net-next 11/12] net: enetc: add preliminary support for i.MX95 ENETC PF
Quoted 88 lines · Wei Fang
Quoted 87 lines
The 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. In addition, PCS support has not been added yet, so 10G ENETC (ENETC instance 2) is not supported now.
Signed-off-by Wei Fang <[email protected]>---
v6:
1. removepinctrl_pm_select_default_state()2. add macros to define the vendor ID and device ID of ENETC PF--- 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 | 155 ++++ .../net/ethernet/freescale/enetc/enetc4_pf.c | 756 ++++++++++++++++++ .../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 | 9 + .../freescale/enetc/enetc_pf_common.c | 11 +- .../freescale/enetc/enetc_pf_common.h | 5 + .../net/ethernet/freescale/enetc/enetc_qos.c | 2 +- .../net/ethernet/freescale/enetc/enetc_vf.c | 6 + 14 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.cdrivers/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_MSIdrivers/net/ethernet/freescale/enetc/Makefile +2
-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 +0
-0@@ -3,6 +3,7 @@
Quoted 5 lines
drivers/net/ethernet/freescale/enetc/enetc.c line 4
Quoted 1 line
drivers/net/ethernet/freescale/enetc/enetc.c +0
-0#include "enetc.h" nit: generally private header file should be after common header file. #include "..." should after #include <...>
Yeah, but this is not the change of this patch. We can fix this nit in the future.
Quoted 1 line
Reviewed-by Frank Li <[email protected]>
Wei Fang
maintainerPATCH v6 12/12 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.
---
v6: no changes
--- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
@@ -8996,9 +8996,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
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Quoted 13 lines · On Wed, 30 Oct 2024 17:39:11 +0800 you wrote:
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.
Quoted 1 line
[...]
Here is the summary with links:
- [v6,net-next,01/12] dt-bindings: net: add compatible string for i.MX95 EMDIO
https://git.kernel.org/netdev/net-next/c/da98dbbc2c74 - [v6,net-next,02/12] dt-bindings: net: add i.MX95 ENETC support https://git.kernel.org/netdev/net-next/c/db2fb74c8560 - [v6,net-next,03/12] dt-bindings: net: add bindings for NETC blocks control https://git.kernel.org/netdev/net-next/c/f70384e53b09 - [v6,net-next,04/12] net: enetc: add initial netc-blk-ctrl driver support https://git.kernel.org/netdev/net-next/c/fe5ba6bf91b3 - [v6,net-next,05/12] net: enetc: extract common ENETC PF parts for LS1028A and i.MX95 platforms https://git.kernel.org/netdev/net-next/c/80c8c852615e - [v6,net-next,06/12] net: enetc: build enetc_pf_common.c as a separate module https://git.kernel.org/netdev/net-next/c/3774409fd4c6 - [v6,net-next,07/12] net: enetc: remove ERR050089 workaround for i.MX95 https://git.kernel.org/netdev/net-next/c/86831a3f4cd4 - [v6,net-next,08/12] net: enetc: add i.MX95 EMDIO support https://git.kernel.org/netdev/net-next/c/a52201fb9caa - [v6,net-next,09/12] net: enetc: extract enetc_int_vector_init/destroy() from enetc_alloc_msix() https://git.kernel.org/netdev/net-next/c/b4bfd0a904e9 - [v6,net-next,10/12] net: enetc: optimize the allocation of tx_bdr https://git.kernel.org/netdev/net-next/c/9e7f2116199d - [v6,net-next,11/12] net: enetc: add preliminary support for i.MX95 ENETC PF https://git.kernel.org/netdev/net-next/c/99100d0d9922 - [v6,net-next,12/12] MAINTAINERS: update ENETC driver files and maintainers https://git.kernel.org/netdev/net-next/c/f488649e40f8
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html