Skip to contentSkip to conversation

net: stmmac: enable Toshiba TC9564

PATCH In review Alex Elder 7 participants 15 messages Oct 19 – Nov 5

Subsystems (6)
lore
Share & tools
lore

Alex Elder

author
#0 lore raw

cover net: stmmac: enable Toshiba TC9564

This series enables the two XGMAC interfaces present in the Toshiba TC9564 SoC.

The TC9564 SoC connects to a host using the upstream interface of the PCIe switch it implements. The PCIe switch has three downstream ports; two are exposed externally, and one implements an embedded PCIe endpoint. That endpoint has two functions, and each of those has a 10 Gbps capable DesignWare XGMAC interface.

This support was originally submitted earlier this year using a PCI driver within the stmmac source directory. This version instead implements a platform driver, "dwmac-tc9564.c".

-Alex

Alex Elder (1):
dt-bindings: net: add support for Toshiba TC9564

Daniel Thompson (4):
net: pcs: pcs-xpcs-regmap: support XPCS memory-mapped MDIO bus via
regmap
net: stmmac: dwxgmac2: Add XGMAC 3.01a support
net: stmmac: dwxgmac2: export symbols for XGMAC 3.01a DMA
net: stmmac: support the TC9564 SoC

 .../devicetree/bindings/net/snps,dwmac.yaml   |  26 +-
 .../bindings/net/toshiba,tc9564-xgmac.yaml    | 327 ++++++++++
 MAINTAINERS                                   |  10 +
 drivers/net/ethernet/stmicro/stmmac/Kconfig   |  11 +
 drivers/net/ethernet/stmicro/stmmac/Makefile  |   1 +
 .../ethernet/stmicro/stmmac/dwmac-tc9564.c    | 590 ++++++++++++++++++
 .../net/ethernet/stmicro/stmmac/dwxgmac2.h    |  10 +
 .../ethernet/stmicro/stmmac/dwxgmac2_core.c   |   1 +
 .../ethernet/stmicro/stmmac/dwxgmac2_descs.c  |   1 +
 .../ethernet/stmicro/stmmac/dwxgmac2_dma.c    |  70 ++-
 drivers/net/pcs/Makefile                      |   3 +-
 drivers/net/pcs/pcs-xpcs-regmap.c             | 169 +++++
 include/linux/pcs/pcs-xpcs-regmap.h           |  13 +
 13 files changed, 1214 insertions(+), 18 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/toshiba,tc9564-xgmac.yaml
 create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c
 create mode 100644 drivers/net/pcs/pcs-xpcs-regmap.c
 create mode 100644 include/linux/pcs/pcs-xpcs-regmap.h

base-commit: 2efb7a11f1aa4d2dc285fe2680cca22cb9f72f64

Signature · 1 line
2.53.0
author
#1 lore raw

PATCH 1/5 dt-bindings: net: add support for Toshiba TC9564

The Toshiba TC9564 is an SoC that exposes two XGMAC 10 Gbps Ethernet interfaces, each of which is attached to an embedded PCIe function.

These XGMAC interfaces have three resets, for the MAC, PMA, and XPCS layers. These resets differ from the standard two resets defined in "snps,dwmac.yaml".

To permit these other resets to be used, modify the way resets are defined in "snps,dwmac.yaml" to be similar to the way interrupts and their names are defined earlier in the file. That is, rather than adding descriptions with the resets property values, just specify the maximum number of items. Then, in the reset-names property, provide a list of description/constant value pairs, indicating which renames may be used among the (three) reset items specified.

---
 .../devicetree/bindings/net/snps,dwmac.yaml   |  26 +-
 .../bindings/net/toshiba,tc9564-xgmac.yaml    | 327 ++++++++++++++++++
 MAINTAINERS                                   |   7 +
 3 files changed, 351 insertions(+), 9 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/toshiba,tc9564-xgmac.yaml
Documentation/devicetree/bindings/net/snps,dwmac.yaml +17 -9
index 2218a492817fd..ace827ee4eb6c 100644
@@ -120,6 +120,7 @@ properties:
         - starfive,jh7110-dwmac
         - tesla,fsd-ethqos
         - thead,th1520-gmac
+        - toshiba,tc9564-xgmac
         - ultrarisc,dp1000-gmac
 
   reg:
@@ -174,17 +175,24 @@ properties:
 
   resets:
     minItems: 1
-    items:
-      - description: GMAC stmmaceth reset
-      - description: AHB or OCP reset
+    maxItems: 3
 
   reset-names:
-    oneOf:
-      - items:
-          - enum: [stmmaceth, ahb]
-      - items:
-          - const: stmmaceth
-          - enum: [ahb, stmmaceth-ocp]
+    maxItems: 3
+    items:
+      - oneOf:
+          - description: GMAC stmmaceth reset
+            const: stmmaceth
+          - description: AHB reset
+            const: ahb
+          - description: MAC reset
+            const: mac-reset
+          - description: PMA (Physical Medium Attachment) reset
+            const: pma-reset
+          - description: XPCS reset
+            const: xpcs-reset
+          - description: OCP reset (deprecated)
+            const: stmmaceth-ocp
 
   power-domains:
     maxItems: 1
Documentation/devicetree/bindings/net/toshiba,tc9564-xgmac.yaml new file +327 -0

327 lines not on this page · raw message

MAINTAINERS +7 -0
index 149bc44003bda..55ead3d1007a8 100644
@@ -28305,6 +28305,13 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/misc/pci1179,0220.yaml
 F:	drivers/misc/tc9564-pci.c
 
+TOSHIBA TC9564 DWMAC ETHERNET DRIVER
+M:	Lorenzo Bianconi <[email protected]>
+M:	Alex Elder <[email protected]>
+M:	Daniel Thompson <[email protected]>
+S:	Maintained
+F:	Documentation/devicetree/bindings/net/toshiba,tc9564-dwmac.yaml
+
 TOSHIBA WMI HOTKEYS DRIVER
 M:	Azael Avalos <[email protected]>
 L:	[email protected]
Signature · 1 line
2.53.0
maintainer
#2 lore raw

Re: [PATCH net-next 1/5] dt-bindings: net: add support for Toshiba TC9564

Documentation/devicetree/bindings/net/toshiba,tc9564-xgmac.yaml line 95

Quoted 4 lines
Documentation/devicetree/bindings/net/toshiba,tc9564-xgmac.yaml new file +4 -0
+  snps,tso:
+    $ref: /schemas/types.yaml#/definitions/flag
+    description:
+      Enable TCP segmentation offload.

snps,dwmac.yaml

snps,tso:
$ref: /schemas/types.yaml#/definitions/flag
description:
Enables the TSO feature otherwise it will be managed by MAC HW capability register.

Documentation/devicetree/bindings/net/toshiba,tc9564-xgmac.yaml line 100

Quoted 5 lines
Documentation/devicetree/bindings/net/toshiba,tc9564-xgmac.yaml new file +5 -0
+
+  snps,pbl:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description:
+      Set the programmable burst length.

snps,pbl:
description:
Programmable Burst Length (tx and rx)
$ref: /schemas/types.yaml#/definitions/uint32
enum: [1, 2, 4, 8, 16, 32]

Documentation/devicetree/bindings/net/toshiba,tc9564-xgmac.yaml line 105

Quoted 4 lines
Documentation/devicetree/bindings/net/toshiba,tc9564-xgmac.yaml new file +4 -0
+  snps,force_sf_dma_mode:
+    $ref: /schemas/types.yaml#/definitions/flag
+    description:
+      Force store-and-forward mode for both TX and RX DMA.

snps,force_sf_dma_mode:
$ref: /schemas/types.yaml#/definitions/flag description:
Force DMA to use the Store and Forward mode for both tx and rx. This flag is ignored if force_thresh_dma_mode is set.

You should be using snps,dwmac.yaml to provide all of these.

Documentation/devicetree/bindings/net/toshiba,tc9564-xgmac.yaml line 149

Quoted 2 lines
Documentation/devicetree/bindings/net/toshiba,tc9564-xgmac.yaml new file +2 -0
+  phy-mode:
+    const: sgmii

This device support 10GBase-R? So why in the binding only allow SGMII?

Andrew

#3 lore raw

Re: [PATCH net-next 1/5] dt-bindings: net: add support for Toshiba TC9564

In reply to Alex Elder
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Medium] dt-bindings: net: snps,dwmac: invalid items list under reset-names - [Medium] dt-bindings: net…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] dt-bindings: net: snps,dwmac: invalid items list under reset-names
- [Medium] dt-bindings: net: snps,dwmac: missing toshiba,tc9564-xgmac in snps,tso rule
- [Low] MAINTAINERS: wrong filename for toshiba,tc9564-xgmac.yaml binding --

commit a79ac6443d5804b83846d7672a48631fcd49b078
Author: Alex Elder <[email protected]>

dt-bindings: net: add support for Toshiba TC9564

This commit adds the devicetree binding for the Toshiba TC9564 XGMAC Ethernet controller and updates snps,dwmac.yaml to allow up to three resets.

Documentation/devicetree/bindings/net/snps,dwmac.yaml properties: · line 124

Quoted 10 lines
Documentation/devicetree/bindings/net/snps,dwmac.yaml +1 -0
index 2218a492817fd..ace827ee4eb6c 100644
@@ -120,6 +120,7 @@ properties:
         - starfive,jh7110-dwmac
         - tesla,fsd-ethqos
         - thead,th1520-gmac
+        - toshiba,tc9564-xgmac
         - ultrarisc,dp1000-gmac

[Severity: Medium]
Should toshiba,tc9564-xgmac also be added to the compatible list under allOf in snps,dwmac.yaml that guards snps,tso?

In Documentation/devicetree/bindings/net/snps,dwmac.yaml:

allOf:
- $ref: ethernet-controller.yaml#
- $ref: snps,dwmac-common.yaml#
- if:
properties:
compatible:
not:
contains:
enum:
...
- snps,dwxgmac
- snps,dwxgmac-2.10
- st,spear600-gmac

then:
properties:
snps,tso: false

Because toshiba,tc9564-xgmac.yaml references snps,dwmac.yaml# and defines compatible solely as const: toshiba,tc9564-xgmac, omitting toshiba,tc9564-xgmac from that list causes snps,tso: false to be applied and rejects snps,tso in the new binding and its example during dt_binding_check.

Quoted 26 lines
Documentation/devicetree/bindings/net/snps,dwmac.yaml +9 -9
   reg:
@@ -174,17 +175,24 @@ properties:
 
   resets:
     minItems: 1
-    items:
-      - description: GMAC stmmaceth reset
-      - description: AHB or OCP reset
+    maxItems: 3
 
   reset-names:
-    oneOf:
-      - items:
-          - enum: [stmmaceth, ahb]
-      - items:
-          - const: stmmaceth
-          - enum: [ahb, stmmaceth-ocp]
+    maxItems: 3
+    items:
+      - oneOf:
+          - description: GMAC stmmaceth reset
+            const: stmmaceth
+          - description: AHB reset
+            const: ahb
+          - description: MAC reset

Documentation/devicetree/bindings/net/snps,dwmac.yaml properties: · line 198

Quoted 10 lines
Documentation/devicetree/bindings/net/snps,dwmac.yaml +7 -0
+            const: mac-reset
+          - description: PMA (Physical Medium Attachment) reset
+            const: pma-reset
+          - description: XPCS reset
+            const: xpcs-reset
+          - description: OCP reset (deprecated)
+            const: stmmaceth-ocp
 
   power-domains:
     maxItems: 1

[Severity: Medium]
Does writing - oneOf: as a list item under reset-names:items cause dt_binding_check to fail?

In interrupt-names earlier in snps,dwmac.yaml, items is a mapping:

interrupt-names:

    minItems: 1
    maxItems: 19
    items:
      oneOf:
        ...

With the leading hyphen in - oneOf: and without minItems: 1, items is treated as a 1-element list rather than a schema applied to each entry up to maxItems: 3. This conflicts with maxItems: 3 in the meta-schema and rejects multi-entry reset-names such as the three resets in toshiba,tc9564-xgmac.yaml.

Quoted 8 lines
MAINTAINERS +0 -0
index 149bc44003bda..55ead3d1007a8 100644
@@ -28305,6 +28305,13 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/misc/pci1179,0220.yaml
 F:	drivers/misc/tc9564-pci.c
 

MAINTAINERS S: Maintained · line 28317

Quoted 10 lines
MAINTAINERS +7 -0
+TOSHIBA TC9564 DWMAC ETHERNET DRIVER
+M:	Lorenzo Bianconi <[email protected]>
+M:	Alex Elder <[email protected]>
+M:	Daniel Thompson <[email protected]>
+S:	Maintained
+F:	Documentation/devicetree/bindings/net/toshiba,tc9564-dwmac.yaml
+
 TOSHIBA WMI HOTKEYS DRIVER
 M:	Azael Avalos <[email protected]>
 L:	[email protected]

[Severity: Low]
Should this file entry reference toshiba,tc9564-xgmac.yaml instead of toshiba,tc9564-dwmac.yaml to match the file created by this patch?

お伝え

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#4 lore raw

Re: [PATCH net-next 1/5] dt-bindings: net: add support for Toshiba TC9564

In reply to Alex Elder
Quoted 15 lines · Alex Elder

The Toshiba TC9564 is an SoC that exposes two XGMAC 10 Gbps Ethernet interfaces, each of which is attached to an embedded PCIe function.

These XGMAC interfaces have three resets, for the MAC, PMA, and XPCS layers. These resets differ from the standard two resets defined in "snps,dwmac.yaml".

To permit these other resets to be used, modify the way resets are defined in "snps,dwmac.yaml" to be similar to the way interrupts and their names are defined earlier in the file. That is, rather than adding descriptions with the resets property values, just specify the maximum number of items. Then, in the reset-names property, provide a list of description/constant value pairs, indicating which renames may be used among the (three) reset items specified.

Quoted 8 lines
---
 .../devicetree/bindings/net/snps,dwmac.yaml   |  26 +-
 .../bindings/net/toshiba,tc9564-xgmac.yaml    | 327 ++++++++++++++++++
 MAINTAINERS                                   |   7 +
 3 files changed, 351 insertions(+), 9 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/toshiba,tc9564-xgmac.yaml

My bot found errors running 'make dt_binding_check' on your patch:

yamllint warnings/errors:

dtschema/dtc warnings/errors:
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/net/snps,dwmac.yaml: properties:reset-names: {'maxItems': 3, 'items': [{'oneOf': [{'description': 'GMAC stmmaceth reset', 'const': 'stmmaceth'}, {'description': 'AHB reset', 'const': 'ahb'}, {'description': 'MAC reset', 'const': 'mac-reset'}, {'description': 'PMA (Physical Medium Attachment) reset', 'const': 'pma-reset'}, {'description': 'XPCS reset', 'const': 'xpcs-reset'}, {'description': 'OCP reset (deprecated)', 'const': 'stmmaceth-ocp'}]}]} should not be valid under {'required': ['maxItems']}
hint: "maxItems" is not needed with an "items" list
from schema $id: http://devicetree.org/meta-schemas/items.yaml
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/net/snps,dwmac.yaml: properties:reset-names:items:0: 'oneOf' is not one of ['const', 'deprecated', 'description', 'enum', 'not', 'pattern']
from schema $id: http://devicetree.org/meta-schemas/string-array.yaml
Documentation/devicetree/bindings/net/toshiba,tc9564-xgmac.example.dtb: ethernet@48000 (toshiba,tc9564-xgmac): False schema does not allow True
from schema $id: http://devicetree.org/schemas/net/toshiba,tc9564-xgmac.yaml
Documentation/devicetree/bindings/net/toshiba,tc9564-xgmac.example.dtb: ethernet-phy@1c (ethernet-phy-id004d.d101): Unevaluated properties are not allowed ('vdd18-supply' was unexpected)
from schema $id: http://devicetree.org/schemas/net/qca,qca808x.yaml

doc reference errors (make refcheckdocs):
MAINTAINERS: Documentation/devicetree/bindings/net/toshiba,tc9564-dwmac.yaml

See https://patchwork.kernel.org/project/devicetree/patch/[email protected]

The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.

author
#5 lore raw

PATCH 2/5 net: pcs: pcs-xpcs-regmap: support XPCS memory-mapped MDIO bus via regmap

In reply to Alex Elder

From: Daniel Thompson <[email protected]>

In some DesignWare XPCS implementations the memory-mapped MDIO bus is allocated to a register window that does not align to a page boundary. This makes iomapping the registers problematic.

For example the Toshiba TC9564 (a PCIe Ethernet-AVB/TSN bridge) provides an "eMAC" subsystem with the XPCS base address cuddled up to XGMAC registers.

Let's introduce helpers to allow the driver that owns the eMAC to register an XPCS using is regmap for the memory-mapped MDIO bus.

---
 MAINTAINERS                         |   2 +
 drivers/net/pcs/Makefile            |   3 +-
 drivers/net/pcs/pcs-xpcs-regmap.c   | 169 ++++++++++++++++++++++++++++
 include/linux/pcs/pcs-xpcs-regmap.h |  13 +++
 4 files changed, 186 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/pcs/pcs-xpcs-regmap.c
 create mode 100644 include/linux/pcs/pcs-xpcs-regmap.h
MAINTAINERS +2 -0
index 55ead3d1007a8..972c9faead5b3 100644
@@ -27148,8 +27148,10 @@ F:	drivers/net/ethernet/synopsys/
 SYNOPSYS DESIGNWARE ETHERNET XPCS DRIVER
 L:	[email protected]
 S:	Orphan
+F:	drivers/net/pcs/pcs-xpcs-regmap.c
 F:	drivers/net/pcs/pcs-xpcs.c
 F:	drivers/net/pcs/pcs-xpcs.h
+F:	include/linux/pcs/pcs-xpcs-regmap.h
 F:	include/linux/pcs/pcs-xpcs.h
 
 SYNOPSYS DESIGNWARE HDMI RX CONTROLLER DRIVER
drivers/net/pcs/Makefile +2 -1
index 4f7920618b900..088d35f21a4c3 100644
@@ -2,7 +2,8 @@
 # Makefile for Linux PCS drivers
 
 pcs_xpcs-$(CONFIG_PCS_XPCS)	:= pcs-xpcs.o pcs-xpcs-plat.o \
-				   pcs-xpcs-nxp.o pcs-xpcs-wx.o
+				   pcs-xpcs-nxp.o pcs-xpcs-regmap.o \
+				   pcs-xpcs-wx.o
 
 obj-$(CONFIG_PCS_XPCS)		+= pcs_xpcs.o
 obj-$(CONFIG_PCS_LYNX)		+= pcs-lynx.o
drivers/net/pcs/pcs-xpcs-regmap.c new file +169 -0

169 lines not on this page · raw message

include/linux/pcs/pcs-xpcs-regmap.h new file +13 -0
new file mode 100644
index 0000000000000..c6d934b1054ed
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __LINUX_PCS_XPCS_REGMAP_H
+#define __LINUX_PCS_XPCS_REGMAP_H
+
+struct device;
+struct regmap;
+struct dw_xpcs;
+
+struct dw_xpcs *devm_xpcs_regmap_register(struct device *dev,
+					  struct regmap *regmap);
+
+#endif /* __LINUX_PCS_XPCS_REGMAP_H */
Signature · 1 line
2.53.0
#6 lore raw

Re: [PATCH net-next 2/5] net: pcs: pcs-xpcs-regmap: support XPCS memory-mapped MDIO bus via regmap

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] net: pcs: MDIO bus ID collision in devm_xpcs_regmap_register() --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] net: pcs: MDIO bus ID collision in devm_xpcs_regmap_register() --

commit f4103deca1c1d0d48e4d0e095369247a1ba3779b
Author: Daniel Thompson <[email protected]>

net: pcs: pcs-xpcs-regmap: support XPCS memory-mapped MDIO bus via regmap

This commit introduces devm_xpcs_regmap_register() and indirect MDIO CSR access helpers so drivers can register a DesignWare XPCS instance backed by a regmap.

Quoted 6 lines
drivers/net/pcs/pcs-xpcs-regmap.c new file +0 -0
new file mode 100644
index 0000000000000..f3f3aaaf0b75a
@@ -0,0 +1,169 @@

[ ... ]

Quoted 12 lines
drivers/net/pcs/pcs-xpcs-regmap.c new file +12 -0
+struct dw_xpcs *devm_xpcs_regmap_register(struct device *dev,
+					  struct regmap *regmap)
+{
+	static atomic_t id = ATOMIC_INIT(-1);
+	struct dw_xpcs *xpcs;
+	struct mii_bus *bus;
+	int ret;
+
+	bus = devm_mdiobus_alloc_size(dev, 0);
+	if (!bus)
+		return ERR_PTR(-ENOMEM);
+

drivers/net/pcs/pcs-xpcs-regmap.c line 147

Quoted 10 lines
drivers/net/pcs/pcs-xpcs-regmap.c new file +10 -0
+	bus->name = "DW XPCS MCI/APB3";
+	bus->read = xpcs_regmap_read_c22;
+	bus->write = xpcs_regmap_write_c22;
+	bus->read_c45 = xpcs_regmap_read_c45;
+	bus->write_c45 = xpcs_regmap_write_c45;
+	bus->phy_mask = ~0;
+	bus->parent = dev;
+	bus->priv = regmap;
+
+	snprintf(bus->id, sizeof(bus->id), "dwxpcs-%x", atomic_inc_return(&id));

[Severity: Medium]
Can bus->id collide with an existing platform DW XPCS bus here?

In drivers/net/pcs/pcs-xpcs-plat.c, xpcs_plat_init_bus() defines its own separate static atomic counter and uses the identical "dwxpcs-%x" format string:

drivers/net/pcs/pcs-xpcs-plat.c:xpcs_plat_init_bus() {
	static atomic_t id = ATOMIC_INIT(-1);
	...
	snprintf(pxpcs->bus->id, MII_BUS_ID_SIZE,
		 "dwxpcs-%x", atomic_inc_return(&id));
}

If a system probes both a platform DW XPCS via xpcs_plat_probe() -> xpcs_plat_init_bus() and a regmap DW XPCS via devm_xpcs_regmap_register() (for example, an SoC with a platform XPCS and a PCIe Toshiba TC9564 card), both counters start at -1 and format their first bus->id as "dwxpcs-0".

When devm_mdiobus_register() calls __mdiobus_register() -> device_register(), device_add_class_symlinks() tries to create the class symlink under /sys/class/mdio_bus/dwxpcs-0, which fails with -EEXIST and causes __mdiobus_register() to fail with -EINVAL.

Should devm_xpcs_regmap_register() use a distinct prefix (such as "dwxpcs-regmap-%x") or share a common counter or IDA with xpcs_plat_init_bus()?

Quoted 6 lines
drivers/net/pcs/pcs-xpcs-regmap.c new file +6 -0
+
+	/* MDIO-bus here serves as just a back-end engine abstracting out
+	 * the MDIO and MCI/APB3 IO interfaces utilized for the DW XPCS CSRs
+	 * access.
+	 */
+	ret = devm_mdiobus_register(dev, bus);

[ ... ]

Quoted 2 lines
drivers/net/pcs/pcs-xpcs-regmap.c new file +2 -0
+}
+EXPORT_SYMBOL_GPL(devm_xpcs_regmap_register);

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
author
#7 lore raw

PATCH 3/5 net: stmmac: dwxgmac2: Add XGMAC 3.01a support

In reply to Alex Elder

From: Daniel Thompson <[email protected]>

XGMAC 2.x and 3.x are architecturally very similar. That means that for everything except one erratum we can simply use the XGMAC 2.x callback functions in the stmmac_dma_ops structure.

Only the set_rx_ring_len callback is specific to XGMAC 3.01. It limits the number of outstanding write requests that can be serviced per DMA.

The other erratum addressed in this patch is simply a comment to ensure that a feature that stmmac doesn't currently use is not enabled without contemplating the errata.

---
 .../net/ethernet/stmicro/stmmac/dwxgmac2.h    |  3 ++
 .../ethernet/stmicro/stmmac/dwxgmac2_dma.c    | 52 +++++++++++++++++++
 2 files changed, 55 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h +3 -0
index f8ab347f7b5b9..0fe86e9942334 100644
@@ -374,6 +374,8 @@
 #define XGMAC_DMA_CH_RxDESC_TAIL_LPTR(x)	(0x0000312c + (0x80 * (x)))
 #define XGMAC_DMA_CH_TxDESC_RING_LEN(x)		(0x00003130 + (0x80 * (x)))
 #define XGMAC_DMA_CH_RxDESC_RING_LEN(x)		(0x00003134 + (0x80 * (x)))
+#define XGMAC_OWRQ			GENMASK(25, 24)
+#define XGMAC_RDRL			GENMASK(15, 0)
 #define XGMAC_DMA_CH_INT_EN(x)		(0x00003138 + (0x80 * (x)))
 #define XGMAC_NIE			BIT(15)
 #define XGMAC_AIE			BIT(14)
@@ -465,6 +467,7 @@
 extern const struct stmmac_ops dwxgmac210_ops;
 extern const struct stmmac_ops dwxlgmac2_ops;
 extern const struct stmmac_dma_ops dwxgmac210_dma_ops;
+extern const struct stmmac_dma_ops dwxgmac301_dma_ops;
 extern const struct stmmac_desc_ops dwxgmac210_desc_ops;
 
 #endif /* __STMMAC_DWXGMAC2_H__ */
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c +52 -0

67 lines not on this page · raw message

Signature · 1 line
2.53.0
maintainer Reviewed-by on v1 3/5
#8 lore raw

Re: [PATCH net-next 3/5] net: stmmac: dwxgmac2: Add XGMAC 3.01a support

Hi,

Quoted 10 lines · Alex Elder

From: Daniel Thompson <[email protected]>

XGMAC 2.x and 3.x are architecturally very similar. That means that for everything except one erratum we can simply use the XGMAC 2.x callback functions in the stmmac_dma_ops structure.

Only the set_rx_ring_len callback is specific to XGMAC 3.01. It limits the number of outstanding write requests that can be serviced per DMA.

Quoted 7 lines

The other erratum addressed in this patch is simply a comment to ensure that a feature that stmmac doesn't currently use is not enabled without contemplating the errata.

Maxime

Quoted 100 lines
---
 .../net/ethernet/stmicro/stmmac/dwxgmac2.h    |  3 ++
 .../ethernet/stmicro/stmmac/dwxgmac2_dma.c    | 52 +++++++++++++++++++
 2 files changed, 55 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h +3 -0
index f8ab347f7b5b9..0fe86e9942334 100644
@@ -374,6 +374,8 @@
 #define XGMAC_DMA_CH_RxDESC_TAIL_LPTR(x)	(0x0000312c + (0x80 * (x)))
 #define XGMAC_DMA_CH_TxDESC_RING_LEN(x)		(0x00003130 + (0x80 * (x)))
 #define XGMAC_DMA_CH_RxDESC_RING_LEN(x)		(0x00003134 + (0x80 * (x)))
+#define XGMAC_OWRQ			GENMASK(25, 24)
+#define XGMAC_RDRL			GENMASK(15, 0)
 #define XGMAC_DMA_CH_INT_EN(x)		(0x00003138 + (0x80 * (x)))
 #define XGMAC_NIE			BIT(15)
 #define XGMAC_AIE			BIT(14)
@@ -465,6 +467,7 @@
 extern const struct stmmac_ops dwxgmac210_ops;
 extern const struct stmmac_ops dwxlgmac2_ops;
 extern const struct stmmac_dma_ops dwxgmac210_dma_ops;
+extern const struct stmmac_dma_ops dwxgmac301_dma_ops;
 extern const struct stmmac_desc_ops dwxgmac210_desc_ops;
 
 #endif /* __STMMAC_DWXGMAC2_H__ */
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c +52 -0
index ff83858ebc1f3..f9a77d641eb65 100644
@@ -36,6 +36,13 @@ static void dwxgmac2_dma_init(void __iomem *ioaddr,
 	 * Route DMA interrupts to per-channel lines when multi-MSI enabled.
 	 */
 	if (dma_cfg->multi_msi_en) {
+		/*
+		 * A friendly warning to future adventurers. If Descriptor Posted
+		 * Write support, which is off by default, is ever enabled then be sure
+		 * to make it optional. This is required by errata for at least XGMAC
+		 * 3.01A... and the XGMAC 2.x and 3.x are architecturally similar so we
+		 * use dwxgmac2 support for the 3.x family as well.
+		 */
 		value = readl(ioaddr + XGMAC_DMA_MODE);
 		value = u32_replace_bits(value, XGMAC_INTM_MODE1,
 					 XGMAC_INTM_MASK);
@@ -492,6 +499,20 @@ static void dwxgmac2_set_rx_ring_len(struct stmmac_priv *priv,
 	writel(len, ioaddr + XGMAC_DMA_CH_RxDESC_RING_LEN(chan));
 }
 
+static void dwxgmac301_set_rx_ring_len(struct stmmac_priv *priv,
+				       void __iomem *ioaddr, u32 len, u32 chan)
+{
+	u32 val = FIELD_PREP(XGMAC_RDRL, len);
+
+	/*
+	 * Reduce the number of outstanding write requests to 3 (from default
+	 * of 4). This is an errata workaround for XGMAC 3.01a.
+	 */
+	val |= FIELD_PREP(XGMAC_OWRQ, 3);
+
+	writel(val, ioaddr + XGMAC_DMA_CH_RxDESC_RING_LEN(chan));
+}
+
 static void dwxgmac2_set_tx_ring_len(struct stmmac_priv *priv,
 				     void __iomem *ioaddr, u32 len, u32 chan)
 {
@@ -621,3 +642,34 @@ const struct stmmac_dma_ops dwxgmac210_dma_ops = {
 	.enable_sph = dwxgmac2_enable_sph,
 	.enable_tbs = dwxgmac2_enable_tbs,
 };
+
+/* All but one field are the same as dwxgmac210_dma_ops */
+const struct stmmac_dma_ops dwxgmac301_dma_ops = {
+	.reset = dwxgmac2_dma_reset,
+	.init = dwxgmac2_dma_init,
+	.init_chan = dwxgmac2_dma_init_chan,
+	.init_rx_chan = dwxgmac2_dma_init_rx_chan,
+	.init_tx_chan = dwxgmac2_dma_init_tx_chan,
+	.axi = dwxgmac2_dma_axi,
+	.dump_regs = dwxgmac2_dma_dump_regs,
+	.dma_rx_mode = dwxgmac2_dma_rx_mode,
+	.dma_tx_mode = dwxgmac2_dma_tx_mode,
+	.enable_dma_irq = dwxgmac2_enable_dma_irq,
+	.disable_dma_irq = dwxgmac2_disable_dma_irq,
+	.start_tx = dwxgmac2_dma_start_tx,
+	.stop_tx = dwxgmac2_dma_stop_tx,
+	.start_rx = dwxgmac2_dma_start_rx,
+	.stop_rx = dwxgmac2_dma_stop_rx,
+	.dma_interrupt = dwxgmac2_dma_interrupt,
+	.get_hw_feature = dwxgmac2_get_hw_feature,
+	.rx_watchdog = dwxgmac2_rx_watchdog,
+	.set_rx_ring_len = dwxgmac301_set_rx_ring_len,	/* Only 3.01 */
+	.set_tx_ring_len = dwxgmac2_set_tx_ring_len,
+	.set_rx_tail_ptr = dwxgmac2_set_rx_tail_ptr,
+	.set_tx_tail_ptr = dwxgmac2_set_tx_tail_ptr,
+	.enable_tso = dwxgmac2_enable_tso,
+	.qmode = dwxgmac2_qmode,
+	.set_bfsize = dwxgmac2_set_bfsize,
+	.enable_sph = dwxgmac2_enable_sph,
+	.enable_tbs = dwxgmac2_enable_tbs,
+};
author
#9 lore raw

PATCH 4/5 net: stmmac: dwxgmac2: export symbols for XGMAC 3.01a DMA

In reply to Alex Elder

From: Daniel Thompson <[email protected]>

Toshiba TC9564 is an Ethernet-AVB/TSN bridge and is essentially a small and highly-specialised SoC. Ethernet on this chip is provided by a DesignWare XGMAC.

One consequence of the SoC-like design is that the internal AXI bus (used by the XGMAC for DMA) maps the PCI DMA space with a non-zero base address. This requires a translation step (happily just simple addition) to convert the PCI DMA address to the hardware DMA address.

This is pretty funky so rather than push that translation logic into the core driver we intend to keep that logic inside the TC9564 platform code. In order to do that we need to export a few symbols to allow us to override some of the DMA and descriptor op tables.

FWIW this approach to overriding the ops tables is similar to the mechanism currently found in dwmac-loongson.c (with the exception that we have also exported a couple of functions so we don't have to replicate their content in the TC9564 platform code).

---
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h |  7 +++++++
 .../ethernet/stmicro/stmmac/dwxgmac2_core.c    |  1 +
 .../ethernet/stmicro/stmmac/dwxgmac2_descs.c   |  1 +
 .../net/ethernet/stmicro/stmmac/dwxgmac2_dma.c | 18 ++++++++++--------
 4 files changed, 19 insertions(+), 8 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h +7 -0
index 0fe86e9942334..1b32d14c37440 100644
@@ -470,4 +470,11 @@ extern const struct stmmac_dma_ops dwxgmac210_dma_ops;
 extern const struct stmmac_dma_ops dwxgmac301_dma_ops;
 extern const struct stmmac_desc_ops dwxgmac210_desc_ops;
 
+void dwxgmac2_dma_init_rx_chan(struct stmmac_priv *priv, void __iomem *ioaddr,
+			       struct stmmac_dma_cfg *dma_cfg, dma_addr_t phy,
+			       u32 chan);
+void dwxgmac2_dma_init_tx_chan(struct stmmac_priv *priv, void __iomem *ioaddr,
+			       struct stmmac_dma_cfg *dma_cfg, dma_addr_t phy,
+			       u32 chan);
+
 #endif /* __STMMAC_DWXGMAC2_H__ */
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c +1 -0
index 1a88cbaed70ca..0effdd6969d65 100644
@@ -1542,6 +1542,7 @@ int dwxgmac2_setup(struct stmmac_priv *priv)
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(dwxgmac2_setup);
 
 int dwxlgmac2_setup(struct stmmac_priv *priv)
 {
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c +1 -0
index 6719ac6e395bc..f0e7b8ee48ac7 100644
@@ -374,3 +374,4 @@ const struct stmmac_desc_ops dwxgmac210_desc_ops = {
 	.set_vlan = dwxgmac2_set_vlan,
 	.set_tbs = dwxgmac2_set_tbs,
 };
+EXPORT_SYMBOL_GPL(dwxgmac210_desc_ops);
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c +10 -8
index f9a77d641eb65..2f9334d7cb922 100644
@@ -63,10 +63,10 @@ static void dwxgmac2_dma_init_chan(struct stmmac_priv *priv,
 	writel(XGMAC_DMA_INT_DEFAULT_EN, ioaddr + XGMAC_DMA_CH_INT_EN(chan));
 }
 
-static void dwxgmac2_dma_init_rx_chan(struct stmmac_priv *priv,
-				      void __iomem *ioaddr,
-				      struct stmmac_dma_cfg *dma_cfg,
-				      dma_addr_t phy, u32 chan)
+void dwxgmac2_dma_init_rx_chan(struct stmmac_priv *priv,
+			       void __iomem *ioaddr,
+			       struct stmmac_dma_cfg *dma_cfg,
+			       dma_addr_t phy, u32 chan)
 {
 	u32 rxpbl = dma_cfg->rxpbl ?: dma_cfg->pbl;
 	u32 value;
@@ -78,11 +78,11 @@ static void dwxgmac2_dma_init_rx_chan(struct stmmac_priv *priv,
 	writel(upper_32_bits(phy), ioaddr + XGMAC_DMA_CH_RxDESC_HADDR(chan));
 	writel(lower_32_bits(phy), ioaddr + XGMAC_DMA_CH_RxDESC_LADDR(chan));
 }
+EXPORT_SYMBOL_GPL(dwxgmac2_dma_init_rx_chan);
 
-static void dwxgmac2_dma_init_tx_chan(struct stmmac_priv *priv,
-				      void __iomem *ioaddr,
-				      struct stmmac_dma_cfg *dma_cfg,
-				      dma_addr_t phy, u32 chan)
+void dwxgmac2_dma_init_tx_chan(struct stmmac_priv *priv, void __iomem *ioaddr,
+			       struct stmmac_dma_cfg *dma_cfg, dma_addr_t phy,
+			       u32 chan)
 {
 	u32 txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;
 	u32 value;
@@ -94,6 +94,7 @@ static void dwxgmac2_dma_init_tx_chan(struct stmmac_priv *priv,
 	writel(upper_32_bits(phy), ioaddr + XGMAC_DMA_CH_TxDESC_HADDR(chan));
 	writel(lower_32_bits(phy), ioaddr + XGMAC_DMA_CH_TxDESC_LADDR(chan));
 }
+EXPORT_SYMBOL_GPL(dwxgmac2_dma_init_tx_chan);
 
 static void dwxgmac2_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi)
 {
@@ -673,3 +674,4 @@ const struct stmmac_dma_ops dwxgmac301_dma_ops = {
 	.enable_sph = dwxgmac2_enable_sph,
 	.enable_tbs = dwxgmac2_enable_tbs,
 };
+EXPORT_SYMBOL_GPL(dwxgmac301_dma_ops);
Signature · 1 line
2.53.0
author
#10 lore raw

PATCH 5/5 net: stmmac: support the TC9564 SoC

In reply to Alex Elder

From: Daniel Thompson <[email protected]>

Add support for the Ethernet XGMAC functionality present in the Toshiba TC9564 SoC.

The TC9564 is a fairly complex chip that attaches to a host via the upstream port of a PCIe switch it implements. That switch has three downstream ports, and one of those has an embedded PCI endpoint. The PCI endpoint implements two PCI functions, and a 10 Gbps-capable XGMAC interface is attached to each.

The TC9564 implements additional peripherals, and access to them is provided by a PCI endpoint bus associated with BAR 4 of the first PCI function. A PCI driver sets up the PCI function for use, and peripherals using the bus use platform drivers, matched by compatible string.

We use the pci-ep-bus approach for the stmmac driver as well, with each PCI function exposing access to its BAR 4 via an endpoint bus. The XGMAC device is defined within a pci-ep-bus node, and is bound to the platform driver based on its compatible string.

---
 MAINTAINERS                                   |   1 +
 drivers/net/ethernet/stmicro/stmmac/Kconfig   |  11 +
 drivers/net/ethernet/stmicro/stmmac/Makefile  |   1 +
 .../ethernet/stmicro/stmmac/dwmac-tc9564.c    | 590 ++++++++++++++++++
 4 files changed, 603 insertions(+)
 create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c
MAINTAINERS +1 -0
index 972c9faead5b3..69f301aa26eb9 100644
@@ -28313,6 +28313,7 @@ M:	Alex Elder <[email protected]>
 M:	Daniel Thompson <[email protected]>
 S:	Maintained
 F:	Documentation/devicetree/bindings/net/toshiba,tc9564-dwmac.yaml
+F:	drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c
 
 TOSHIBA WMI HOTKEYS DRIVER
 M:	Azael Avalos <[email protected]>
drivers/net/ethernet/stmicro/stmmac/Kconfig +11 -0
index ab3c4cf964239..5613921188df4 100644
@@ -363,6 +363,17 @@ config DWMAC_LOONGSON1
 	  device driver. This driver is used for Loongson1-based boards
 	  like Loongson LS1B/LS1C.
 
+config DWMAC_TC9564
+	tristate "Toshiba TC9564 DWMAC support"
+	depends on OF && COMMON_CLK && TC9564_PCI
+	default TC9564_PCI
+	help
+	  Support for the Ethernet controllers on the Toshiba TC9564.
+
+	  This enables glue layer support in the stmmac driver support
+	  for the Toshiba TC9564.  This chip implements two embedded
+	  PCIe functions, each of which has an XGMAC interface.
+
 config DWMAC_TEGRA
 	tristate "NVIDIA Tegra MGBE support"
 	depends on ARCH_TEGRA || COMPILE_TEST
drivers/net/ethernet/stmicro/stmmac/Makefile +1 -0
index b16a456b730ec..c4de25db93715 100644
@@ -52,4 +52,5 @@ obj-$(CONFIG_STMMAC_PCI)	+= stmmac-pci.o
 obj-$(CONFIG_DWMAC_INTEL)	+= dwmac-intel.o
 obj-$(CONFIG_DWMAC_LOONGSON)	+= dwmac-loongson.o
 obj-$(CONFIG_DWMAC_MOTORCOMM)	+= dwmac-motorcomm.o
+obj-$(CONFIG_DWMAC_TC9564)	+= dwmac-tc9564.o
 stmmac-pci-objs:= stmmac_pci.o
drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c new file +590 -0

590 lines not on this page · raw message

Signature · 1 line
2.53.0
#11 lore raw

Re: [PATCH net-next 5/5] net: stmmac: support the TC9564 SoC

Hi Alex,

Quoted 269 lines · Alex Elder

From: Daniel Thompson <[email protected]>

Add support for the Ethernet XGMAC functionality present in the Toshiba TC9564 SoC.

The TC9564 is a fairly complex chip that attaches to a host via the upstream port of a PCIe switch it implements. That switch has three downstream ports, and one of those has an embedded PCI endpoint. The PCI endpoint implements two PCI functions, and a 10 Gbps-capable XGMAC interface is attached to each.

The TC9564 implements additional peripherals, and access to them is provided by a PCI endpoint bus associated with BAR 4 of the first PCI function. A PCI driver sets up the PCI function for use, and peripherals using the bus use platform drivers, matched by compatible string.

We use the pci-ep-bus approach for the stmmac driver as well, with each PCI function exposing access to its BAR 4 via an endpoint bus. The XGMAC device is defined within a pci-ep-bus node, and is bound to the platform driver based on its compatible string.

---
 MAINTAINERS                                   |   1 +
 drivers/net/ethernet/stmicro/stmmac/Kconfig   |  11 +
 drivers/net/ethernet/stmicro/stmmac/Makefile  |   1 +
 .../ethernet/stmicro/stmmac/dwmac-tc9564.c    | 590 ++++++++++++++++++
 4 files changed, 603 insertions(+)
 create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c
MAINTAINERS +1 -0
index 972c9faead5b3..69f301aa26eb9 100644
@@ -28313,6 +28313,7 @@ M:	Alex Elder <[email protected]>
 M:	Daniel Thompson <[email protected]>
 S:	Maintained
 F:	Documentation/devicetree/bindings/net/toshiba,tc9564-dwmac.yaml
+F:	drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c
 
 TOSHIBA WMI HOTKEYS DRIVER
 M:	Azael Avalos <[email protected]>
drivers/net/ethernet/stmicro/stmmac/Kconfig +11 -0
index ab3c4cf964239..5613921188df4 100644
@@ -363,6 +363,17 @@ config DWMAC_LOONGSON1
 	  device driver. This driver is used for Loongson1-based boards
 	  like Loongson LS1B/LS1C.
 
+config DWMAC_TC9564
+	tristate "Toshiba TC9564 DWMAC support"
+	depends on OF && COMMON_CLK && TC9564_PCI
+	default TC9564_PCI
+	help
+	  Support for the Ethernet controllers on the Toshiba TC9564.
+
+	  This enables glue layer support in the stmmac driver support
+	  for the Toshiba TC9564.  This chip implements two embedded
+	  PCIe functions, each of which has an XGMAC interface.
+
 config DWMAC_TEGRA
 	tristate "NVIDIA Tegra MGBE support"
 	depends on ARCH_TEGRA || COMPILE_TEST
drivers/net/ethernet/stmicro/stmmac/Makefile +1 -0
index b16a456b730ec..c4de25db93715 100644
@@ -52,4 +52,5 @@ obj-$(CONFIG_STMMAC_PCI)	+= stmmac-pci.o
 obj-$(CONFIG_DWMAC_INTEL)	+= dwmac-intel.o
 obj-$(CONFIG_DWMAC_LOONGSON)	+= dwmac-loongson.o
 obj-$(CONFIG_DWMAC_MOTORCOMM)	+= dwmac-motorcomm.o
+obj-$(CONFIG_DWMAC_TC9564)	+= dwmac-tc9564.o
 stmmac-pci-objs:= stmmac_pci.o
drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c new file +186 -0
new file mode 100644
index 0000000000000..21098f91e3bbf
@@ -0,0 +1,590 @@
+// SPDX-License-Identifier: GPL-2.0
+
+/*
+ * Copyright (C) 2026 by RISCstar Solutions Corporation.  All rights reserved.
+ *
+ * Derived from code having the following copyrights:
+ * Copyright (C) 2011-2012  Vayavya Labs Pvt Ltd
+ * Copyright (C) 2025 Toshiba Electronic Devices & Storage Corporation
+ */
+
+#include <linux/bitops.h>
+#include <linux/iopoll.h>
+#include <linux/irqdomain.h>
+#include <linux/irqchip/chained_irq.h>
+#include <linux/mfd/syscon.h>
+#include <linux/pcs/pcs-xpcs-regmap.h>
+#include <linux/pcs/pcs-xpcs.h>
+#include <linux/phy.h>
+#include <linux/regmap.h>
+#include <linux/stmmac.h>
+#include <linux/types.h>
+#include <linux/units.h>
+
+#include "common.h"
+#include "dwxgmac2.h"
+#include "stmmac.h"
+#include "stmmac_platform.h"
+
+#define DRIVER_NAME			"dwmac-tc9564"
+
+/* Start of range representing PCI space on the TC9564 internal bus */
+#define TC9564_SLV00_SRC_ADDR		0x0000001000000000ULL
+
+#define TC9564_PTP_CLOCK_RATE		(250 * HZ_PER_MHZ)
+
+#define TC9564_RX_FIFO_SIZE		(46 * SZ_1K)
+#define TC9564_TX_FIFO_SIZE		(46 * SZ_1K)
+
+/* Fields and values for the EMACTL registers */
+#define EMAC_SP_SEL_MASK		GENMASK(3, 0)
+#define SP_SEL_2500BASEX		4
+#define SP_SEL_SGMII_1000M		5
+#define SP_SEL_SGMII_100M		6
+#define SP_SEL_SGMII_10M		7
+#define EMAC_PHY_INF_SEL_MASK		GENMASK(5, 4)
+#define PCS_CLK_PHY			1	/* Clock from PHY */
+#define EMAC_INV_SGM_SIG_DET		BIT(6)	/* 1 = polarity inverted */
+#define EMAC_LPIHWCLKEN			BIT(8)	/* 1 = low power mode */
+#define EMAC_INIT_DONE			BIT(21)
+
+/* Offset to the XPCS memory block, relative to the EMAC address range */
+#define DWMAC_XPCS_OFFSET		0x3a00
+
+/* Offset to the PMATOP memory block, relative to the EMAC address range */
+#define DWMAC_PMATOP_OFFSET			0x4000
+
+#define PMA_CML_GL_PM_CFG0			0x01b8
+
+/*
+ * Five sets three registers must be configured for PMA.  The HWT_REFCLK
+ * registers are each separated by 0x14 bytes.  The Common0 configuration
+ * registers are separated by 0x8 bytes.
+ */
+#define PMA_REG_COUNT				5
+
+#define PMA_HWT_REFCK_R_EN			0x1080
+#define PMA_HWT_REFCK_TERM_EN			0x1090
+#define PMA_HWT_REFCK_STRIDE			0x0014
+
+#define PMA_COMM_CFG_0_1			0x1888
+#define PMA_COMM_CFG_0_1_STRIDE			0x0008
+
+/* PMA_COMM_CFG_0_1 fields (WRITE_MASK is a field name) */
+#define COMM_CFG_WRITE_MASK_MASK		GENMASK(16, 9)
+#define WRITE_MASK_VALUE			0xf7	/* Power-on value */
+#define COMM_CFG_ENABLE				BIT(8)
+#define COMM_CFG_WRITE_DATA_MASK		GENMASK(7, 0)
+#define WRITE_DATA_VALUE			0x04	/* Power-on value */
+
+enum {
+	RESET_ID_MAC,
+	RESET_ID_XPCS,
+	RESET_ID_PMA,
+};
+
+static const char * const tc9564_reset_names[] = {
+	[RESET_ID_MAC] = "mac",
+	[RESET_ID_XPCS] = "xpcs",
+	[RESET_ID_PMA] = "pma",
+};
+
+/**
+ * struct tc9564_data - Toshiba-specific platform data
+ * @dev:		Device pointer
+ * @ioaddr:		Pointer to mapped eMAC memory
+ * @plat:		Pointer to our stmmac platform data
+ * @resets:		Reset controller bulk array
+ * @clocks:		Clock controller bulk array
+ * @clock_count:	Number of valid elements in the clock array
+ * @config_regmap:	Regmap used to access eMAC configuration registers
+ * @emac_ctl_offset:	Offset of the eMAC control register within the regmap
+ * @res:		Structure passed to stmmac_dvr_probe()
+ * @desc:		DMA descriptor data used by mac_device_info
+ * @dma:		DMA operations data used by mac_device_info
+ */
+struct tc9564_data {
+	struct device *dev;
+	void __iomem *ioaddr;
+	struct plat_stmmacenet_data *plat;
+	struct reset_control_bulk_data resets[ARRAY_SIZE(tc9564_reset_names)];
+	struct clk_bulk_data *clocks;
+	u32 clock_count;
+
+	struct regmap *config_regmap;
+	u32 emac_ctl_offset;
+
+	/* This field is data passed to stmmac_dvr_probe() */
+	struct stmmac_resources res;
+
+	/* These two fields are used by the mac_device_info structure */
+	struct stmmac_desc_ops desc;
+	struct stmmac_dma_ops dma;
+};
+
+struct tc9564_mac_speed {
+	phy_interface_t phy_interface;
+	int speed;
+	u32 sp_sel;
+};
+
+static struct tc9564_mac_speed mac_speed[] = {
+	{ PHY_INTERFACE_MODE_2500BASEX,	SPEED_2500,  SP_SEL_2500BASEX },
+	{ PHY_INTERFACE_MODE_SGMII,	SPEED_1000,  SP_SEL_SGMII_1000M },
+	{ PHY_INTERFACE_MODE_SGMII,	SPEED_100,   SP_SEL_SGMII_100M },
+	{ PHY_INTERFACE_MODE_SGMII,	SPEED_10,    SP_SEL_SGMII_10M },
+};
+
+/* TC9564 uses indirect addressing so this need only describe a 1KiB range */
+static const struct regmap_config xpcs_regmap_config = {
+	.reg_bits	= 32,
+	.val_bits	= 32,
+	.reg_base	= 0x00,		/* Minimum XPCS reg offset */
+	.max_register	= 0xff,		/* Register DW_VR_CSR_VIEWPORT */
+	.reg_shift	= REGMAP_UPSHIFT(2),
+};
+
+/**
+ * tc9564_pma_init() - Initialize PMA
+ * @td:	bsp_priv pointer
+ *
+ * Initialize (or re-initialize) the PMA, configure the clocks and wait for the
+ * eMAC to be ready.
+ */
+static void tc9564_pma_init(struct tc9564_data *td)
+{
+	struct reset_control *rstc = td->resets[RESET_ID_PMA].rstc;
+	struct regmap *regmap = td->config_regmap;
+	void __iomem *pmatop;
+	u32 val;
+	int ret;
+	u32 i;
+
+	/*
+	 * When we re-initialize the PMA then the reset will already have
+	 * been deasserted. We must make sure the PMA reset is asserted
+	 * before we change the clock settings.
+	 */
+	WARN_ON(reset_control_assert(rstc));
+
+	pmatop = td->res.addr + DWMAC_PMATOP_OFFSET;
+
+	/* Power on CML buffer (0 = normal mode, 1 = power down) */
+	writel(0, pmatop + PMA_CML_GL_PM_CFG0);
+
+	/* This value switches clock from C0_REFCK to CLK_REF_I */
+	val = u32_encode_bits(WRITE_MASK_VALUE, COMM_CFG_WRITE_MASK_MASK);
+	val |= COMM_CFG_ENABLE;
+	val |= u32_encode_bits(WRITE_DATA_VALUE, COMM_CFG_WRITE_DATA_MASK);
+
+	for (i = 0; i < PMA_REG_COUNT; i++) {
+		u32 offset =  i * PMA_HWT_REFCK_STRIDE;
+
+		/* Disable C0_REFCK and 100 ohm termination */
+		writel(0, pmatop + PMA_HWT_REFCK_R_EN + offset);
+		writel(0, pmatop + PMA_HWT_REFCK_TERM_EN + offset);
+

drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c line 196

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c new file +10 -0
+		/* Switch clock from C0_REFCK to CLK_REF_I */
+		offset =  i * PMA_COMM_CFG_0_1_STRIDE;
+		writel(val, pmatop + PMA_COMM_CFG_0_1 + offset);
+	}
+
+	WARN_ON(reset_control_deassert(rstc));
+
+	ret = regmap_read_poll_timeout(regmap, td->emac_ctl_offset,
+				       val, val & EMAC_INIT_DONE, 50, 1000000);
+	WARN(ret, "timeout waiting for MAC init done\n");

This is too many WARN_ON / WARN, there's 3 just in this function. At least use
WARN_ON_ONCE, or maybe better print a log with pr_warn / dev_warn ?

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c new file +5 -0
+}
+
+static int tc9564_mac_speed_select(struct tc9564_data *td,
+				   phy_interface_t interface, int speed)
+{

drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c line 211

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c new file +10 -0
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(mac_speed); i++) {
+		if (mac_speed[i].phy_interface != interface)
+			continue;
+
+		if (speed == mac_speed[i].speed || speed == SPEED_UNKNOWN)
+			return mac_speed[i].sp_sel;
+	}
+	dev_err(td->dev, "%s/%d unsupported\n", phy_modes(interface), speed);

Is that "mac_speed" lookup table actually needed ? maybe a simpler switch/case based on the speed alone would be enough, or do we really need to validate the phy_interface_t each time ?

Quoted 25 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c new file +25 -0
+
+	return -EOPNOTSUPP;
+}
+
+static void tc9564_mac_configure(struct tc9564_data *td,
+				 phy_interface_t interface, int speed)
+{
+	struct regmap *regmap = td->config_regmap;
+	u32 offset = td->emac_ctl_offset;
+	int sp_sel;
+	u32 val;
+
+	sp_sel = tc9564_mac_speed_select(td, interface, speed);
+	if (sp_sel < 0)
+		return;
+
+	/* No error checking needed for MMIO regmap */
+	regmap_read(regmap, offset, &val);
+	val |= EMAC_LPIHWCLKEN;
+	val &= ~EMAC_INV_SGM_SIG_DET;
+	val = u32_replace_bits(val, PCS_CLK_PHY, EMAC_PHY_INF_SEL_MASK);
+	val = u32_replace_bits(val, sp_sel, EMAC_SP_SEL_MASK);
+	regmap_write(regmap, offset, val);
+}
+

drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c line 246

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c new file +10 -0
+static void tc9564_mac_enable(struct tc9564_data *td)
+{
+	WARN_ON(clk_bulk_prepare_enable(td->clock_count, td->clocks));
+
+	WARN_ON(reset_control_deassert(td->resets[RESET_ID_MAC].rstc));
+
+	tc9564_mac_configure(td, td->plat->phy_interface, SPEED_UNKNOWN);
+	tc9564_pma_init(td);
+
+	WARN_ON(reset_control_deassert(td->resets[RESET_ID_XPCS].rstc));

Too many warns :)

drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c line 251

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c new file +5 -0
+}
+
+static void tc9564_mac_disable(struct tc9564_data *td)
+{
+	WARN_ON(reset_control_bulk_assert(ARRAY_SIZE(td->resets), td->resets));

same

Maxime

#12 lore raw

Re: [PATCH net-next 5/5] net: stmmac: support the TC9564 SoC

Hi Maxime

Actually, this might be more for Alex to find when he works through the review feedback but...

Quoted 16 lines · Maxime Chevallier
Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c new file +6 -0
+static struct tc9564_mac_speed mac_speed[] = {
+	{ PHY_INTERFACE_MODE_2500BASEX,	SPEED_2500,  SP_SEL_2500BASEX },
+	{ PHY_INTERFACE_MODE_SGMII,	SPEED_1000,  SP_SEL_SGMII_1000M },
+	{ PHY_INTERFACE_MODE_SGMII,	SPEED_100,   SP_SEL_SGMII_100M },
+	{ PHY_INTERFACE_MODE_SGMII,	SPEED_10,    SP_SEL_SGMII_10M },
+};

<snip>

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c new file +9 -0
+static int tc9564_mac_speed_select(struct tc9564_data *td,
+				   phy_interface_t interface, int speed)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(mac_speed); i++) {
+		if (mac_speed[i].phy_interface != interface)
+			continue;
+
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c line 211

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c new file +4 -0
+		if (speed == mac_speed[i].speed || speed == SPEED_UNKNOWN)
+			return mac_speed[i].sp_sel;
+	}
+	dev_err(td->dev, "%s/%d unsupported\n", phy_modes(interface), speed);

Is that "mac_speed" lookup table actually needed ? maybe a simpler switch/case based on the speed alone would be enough, or do we really need to validate the phy_interface_t each time ?

Once we add 10G PHY support I don't think it can be based on link speed alone (for 10G PHY we have to write the same value to SP_SEL regardless of link speed).

However even when that happens we could still code it up using switch/case and ifs.

Daniel.

#13 lore raw

Re: [PATCH net-next 5/5] net: stmmac: support the TC9564 SoC

In reply to Alex Elder

Hi Alex,

Quoted 29 lines · Alex Elder

From: Daniel Thompson <[email protected]>

Add support for the Ethernet XGMAC functionality present in the Toshiba TC9564 SoC.

The TC9564 is a fairly complex chip that attaches to a host via the upstream port of a PCIe switch it implements. That switch has three downstream ports, and one of those has an embedded PCI endpoint. The PCI endpoint implements two PCI functions, and a 10 Gbps-capable XGMAC interface is attached to each.

The TC9564 implements additional peripherals, and access to them is provided by a PCI endpoint bus associated with BAR 4 of the first PCI function. A PCI driver sets up the PCI function for use, and peripherals using the bus use platform drivers, matched by compatible string.

We use the pci-ep-bus approach for the stmmac driver as well, with each PCI function exposing access to its BAR 4 via an endpoint bus. The XGMAC device is defined within a pci-ep-bus node, and is bound to the platform driver based on its compatible string.

---
...

drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c new file +2 -0
+/* Fields and values for the EMACTL registers */
+#define EMAC_SP_SEL_MASK		GENMASK(3, 0)

drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c line 50

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c new file +10 -0
+#define SP_SEL_2500BASEX		4
+#define SP_SEL_SGMII_1000M		5
+#define SP_SEL_SGMII_100M		6
+#define SP_SEL_SGMII_10M		7
+#define EMAC_PHY_INF_SEL_MASK		GENMASK(5, 4)
+#define PCS_CLK_PHY			1	/* Clock from PHY */
+#define EMAC_INV_SGM_SIG_DET		BIT(6)	/* 1 = polarity inverted */
+#define EMAC_LPIHWCLKEN			BIT(8)	/* 1 = low power mode */
+#define EMAC_INIT_DONE			BIT(21)
+

Nit: extra tab before BIT(8) and BIT(21).

drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c line 71

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c new file +7 -0
+
+#define PMA_HWT_REFCK_R_EN			0x1080
+#define PMA_HWT_REFCK_TERM_EN			0x1090
+#define PMA_HWT_REFCK_STRIDE			0x0014
+
+#define PMA_COMM_CFG_0_1			0x1888
+#define PMA_COMM_CFG_0_1_STRIDE			0x0008

Nit: extra tab before 0x1090 and 0x0008.

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c new file +5 -0
+
+static int tc9564_probe_config_dt(struct tc9564_data *td)
+{
+	struct platform_device *pdev = to_platform_device(td->dev);
+	struct device_node *np = td->dev->of_node;

drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c line 412

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c new file +10 -0
+	struct plat_stmmacenet_data *plat;
+	phy_interface_t phy_interface;
+	struct device *dev = td->dev;
+	int ret;
+
+	ret = device_get_phy_mode(dev);
+	if (ret < 0)
+		return -ENODEV;
+	phy_interface = ret;
+

Nit: I think the call to devm_stmmac_probe_config_dt() will get the PHY mode from firmware and store it in plat_dat->phy_interface so this is probably redundant.

Quoted 44 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c new file +42 -0
+	/* The platform structure is allocated with devm_kzalloc() */
+	plat = devm_stmmac_probe_config_dt(pdev, td->res.mac);
+	if (IS_ERR(plat))
+		return PTR_ERR(plat);
+
 
 
+static int tc9564_dwmac_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct tc9564_data *td;
+	struct device_node *np;
+	struct regmap *regmap;
+	int ret;
+
+	td = devm_kzalloc(dev, sizeof(*td), GFP_KERNEL);
+	if (!td)
+		return -ENOMEM;
+
+	td->dev = dev;
+
+	np = dev_of_node(dev);
+	regmap = syscon_regmap_lookup_by_phandle_args(np,
+						      "toshiba,config-syscon",
+						      1, &td->emac_ctl_offset);
+	if (IS_ERR(regmap))
+		return dev_err_probe(dev, PTR_ERR(regmap),
+				     "failed to get config regmap\n");
+	td->config_regmap = regmap;
+
+	ret = tc9564_reset_init(td);
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to initialize resets\n");
+
+	ret = tc9564_clock_init(td);
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to initialize clocks\n");
+
+	ret = tc9564_probe_config_dt(td);
+	if (ret)
+		return ret;
+
+	ret = stmmac_get_platform_resources(pdev, &td->res);
+	if (ret)

drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c line 550

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c new file +10 -0
+		return dev_err_probe(dev, ret,
+				     "failed to initialize stmmac resources\n");
+
+	tc9564_mac_enable(td);
+
+	ret = stmmac_dvr_probe(dev, td->plat, &td->res);
+	if (ret) {
+		ret = dev_err_probe(dev, ret, "failed stmmac probe\n");
+		goto err_disable_mac;
+	}

Nit: Could this use devm_stmmac_pltfr_probe() and drop tc9564_dwmac_remove()?
tc9564_mac_disable() could be registered as the priv->plat->exit callback.

drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c line 559

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c new file +9 -0
+
+	return 0;
+
+err_disable_mac:
+	tc9564_mac_disable(td);
+
+	return ret;
+}
+

Ayaan

#14 lore raw

Re: [PATCH net-next 5/5] net: stmmac: support the TC9564 SoC

In reply to Alex Elder
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] net: stmmac: tc9564_reset_names mismatch with DT binding reset-names - [High] net: stmmac…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] net: stmmac: tc9564_reset_names mismatch with DT binding reset-names
- [High] net: stmmac: stmmac_get_platform_resources() zeroes DT MAC address
- [Medium] net: stmmac: tc9564: unconditional reset and clock disable in suspend breaks WoL --

commit d94523eb7296bd3578512ea2f1d63c42d3751631
Author: Daniel Thompson <[email protected]>

net: stmmac: support the TC9564 SoC

This commit adds stmmac glue layer support for the Ethernet XGMAC functionality on the Toshiba TC9564 SoC via a platform driver bound to a PCI endpoint bus node.

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c new file +0 -0
new file mode 100644
index 0000000000000..21098f91e3bbf
@@ -0,0 +1,590 @@

[ ... ]

drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c line 90

Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c new file +11 -0
+enum {
+	RESET_ID_MAC,
+	RESET_ID_XPCS,
+	RESET_ID_PMA,
+};
+
+static const char * const tc9564_reset_names[] = {
+	[RESET_ID_MAC] = "mac",
+	[RESET_ID_XPCS] = "xpcs",
+	[RESET_ID_PMA] = "pma",
+};

[Severity: High]
Should the entries in tc9564_reset_names include the "-reset" suffix?

In Documentation/devicetree/bindings/net/toshiba,tc9564-xgmac.yaml, the required reset-names property items are defined as:

reset-names:
items:
- const: mac-reset
- const: pma-reset
- const: xpcs-reset

When tc9564_dwmac_probe() calls tc9564_reset_init() -> devm_reset_control_bulk_get_exclusive(), the reset lookup matches each td->resets[i].id against the device tree node's reset-names property. With "mac", "xpcs", and "pma", won't reset lookup fail during probe on a binding-compliant device tree?

[ ... ]

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c new file +6 -0
+static void tc9564_mac_disable(struct tc9564_data *td)
+{
+	WARN_ON(reset_control_bulk_assert(ARRAY_SIZE(td->resets), td->resets));
+
+	clk_bulk_disable_unprepare(td->clock_count, td->clocks);
+}

[ ... ]

Quoted 47 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c new file +47 -0
+static int tc9564_dwmac_suspend(struct device *dev, void *bsp_priv)
+{
+	struct tc9564_data *td = bsp_priv;
+
+	tc9564_mac_disable(td);
+
+	return 0;
+}
+
+static int tc9564_dwmac_resume(struct device *dev, void *bsp_priv)
+{
+	struct tc9564_data *td = bsp_priv;
+
+	tc9564_mac_enable(td);
+
+	return 0;
+}
+
+static int tc9564_probe_config_dt(struct tc9564_data *td)
+{
+	struct platform_device *pdev = to_platform_device(td->dev);
+	struct device_node *np = td->dev->of_node;
+	struct plat_stmmacenet_data *plat;
+	phy_interface_t phy_interface;
+	struct device *dev = td->dev;
+	int ret;
+
+	ret = device_get_phy_mode(dev);
+	if (ret < 0)
+		return -ENODEV;
+	phy_interface = ret;
+
+	/* The platform structure is allocated with devm_kzalloc() */
+	plat = devm_stmmac_probe_config_dt(pdev, td->res.mac);
+	if (IS_ERR(plat))
+		return PTR_ERR(plat);
+
+	/*
+	 * Core driver cannot deduce or validate fifo size because the bits
+	 * that provide FIFO size only worth in powers of two.
+	 */
+	if (plat->rx_fifo_size == 0 || plat->tx_fifo_size == 0)
+		return dev_err_probe(dev, -EINVAL, "fifo size is not set\n");
+	if (plat->rx_fifo_size > TC9564_RX_FIFO_SIZE ||
+	    plat->tx_fifo_size > TC9564_TX_FIFO_SIZE)
+		return dev_err_probe(dev, -EINVAL, "fifo size too big (%u/%u)\n",
+				     plat->rx_fifo_size, plat->tx_fifo_size);

drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c line 437

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c new file +10 -0
+
+	/*
+	 * toshiba,tc9564-xgmac is *not* compatible with snps,dwxgmac because
+	 * generic drivers cannot possibly work on TC9564 (without clocks
+	 * reading registers wedges the bus). However, without snps,dwxgmac,
+	 * devm_stmmac_probe_config_dt(), can't figure of the core type and
+	 * won't parse a couple of extra properties. Let's handle that here!
+	 */
+	plat->core_type = DWMAC_CORE_XGMAC;
+	plat->pmt = true;

[Severity: Medium]
Does calling tc9564_mac_disable() unconditionally in tc9564_dwmac_suspend() break Wake-on-LAN?

In tc9564_probe_config_dt(), plat->pmt is set to true. When Wake-on-LAN is enabled via ethtool and the system suspends, stmmac_suspend() programs the XGMAC receiver and PMT wakeup registers via stmmac_pmt() and keeps the link active via phylink_suspend(priv->phylink, true), before calling priv->plat->suspend().

Because tc9564_dwmac_suspend() unconditionally calls tc9564_mac_disable(), all three resets (RESET_ID_MAC, RESET_ID_XPCS, RESET_ID_PMA) are asserted and all clocks are disabled without checking device_may_wakeup(dev), which clears the programmed PMT state and shuts down the receive path.

[ ... ]

Quoted 2 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c new file +2 -0
+static int tc9564_dwmac_probe(struct platform_device *pdev)
+{

[ ... ]

drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c line 542

Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc9564.c new file +8 -0
+	ret = tc9564_probe_config_dt(td);
+	if (ret)
+		return ret;
+
+	ret = stmmac_get_platform_resources(pdev, &td->res);
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "failed to initialize stmmac resources\n");

[Severity: High]
Does calling stmmac_get_platform_resources() after tc9564_probe_config_dt() wipe out the MAC address read from the device tree?

In tc9564_probe_config_dt(), devm_stmmac_probe_config_dt(pdev, td->res.mac) populates td->res.mac from the device tree. However, stmmac_get_platform_resources(pdev, &td->res) is called immediately afterward, and it begins with:

drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c:stmmac_get_platform_resources() {
	int ret;

	memset(stmmac_res, 0, sizeof(*stmmac_res));

This zeroes the entire td->res structure, including td->res.mac, before it is passed to stmmac_dvr_probe(). Should stmmac_get_platform_resources() be called before tc9564_probe_config_dt()?

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5