net: enable TC956x support
Subsystems (13)
cover net: enable TC956x support
This series introduces stmmac driver support for the Toshiba TC9564 (also known as Qualcomm QPS615). This is an Ethernet-AVB/TSN bridge IC that provides a high-speed connection between a host SoC and Ethernet devices on a network. It incorporates a PCIe switch, and implements two 10 Gbps capable Ethernet MACs (along with other IP blocks), and is essentially a small and highly-specialized SoC. The TC9564 is a member of a family of similar chips, and the driver code uses "tc956x" to reflect this.
TC956x chips incorporate a PCIe gen 3 switch, with one upstream and three downstream ports. Its PCIe functionality is already supported upstream, including a power control driver that performs some early configuration of the PCI ports ("pci-pwrctrl-tc9563.c").
One of the PCIe switch's downstream ports has an internal PCIe endpoint, which implements two PCIe functions, each of which has an Ethernet MAC (eMAC) subsystem. The eMAC is composed of a Synopsis Designware XGMAC combined with an XPCS and PMA. Each MAC is capable of operating at 10M/100M/1G/2.5G/5Gps and 10Gps. The initial target platform is the Qualcomm RB3gen2, which supports a 10Gbps Marvell PHY on port A, and a 2.5Gbps Qualcomm PHY on port B. (The Marvell PHY is not populated on all RB3gen2 boards, and only 2.5 Gbps support is included initially.)
TC956x chips also implement several other blocks of functionality, including a GPIO controller, interrupt controllers (MSIGEN), I2C and SPI, a UART, and an Arm Cortex M3 CPU with 128KB SRAM. The GPIO interface exposes several lines to manage external resets. The interrupt controllers are used internally by the MAC functions. The UART, SPI, microcontroller, and SRAM are currently unused.
----------------------------------
| Host |
------+...+----------+........+---
|i2c| | PCIe |
----------------+...+----------+........+------
| TC956x |I2C| |upstream| |
| ----- --+--------+--- |
| ----- ------ ------- | PCIe switch | |
| |SPI| |GPIO| |reset| | | |
| ----- ------ |clock| | DS3 DS2 DS1 | |
| ------- ---++--++--++-- |
| ----- ------ downstream// \\ \\ | downstream
| |MCU| |SRAM| /==========/ \\ \===== PCIe port 1
| ----- ------ //PCIe port 3 \\ |
| || \======= downstream
| ----+-----------++-----------+---- | PCIe port 2
| | M | internal PCIe endpoint | M | |
| | S |------------------------| S | ------ |
| | I | PCIe | | PCIe | I | |UART| |
| | G |function 0| |function 1| G | ------ |
| | E |----++----| |----++----| E | |
| | N | eMAC 0 | | eMAC 1 | N | |
--------+.......+------+.....+-----------------
|USXGMII| |SGMII|
--+.......+-- --+.....+--
| ARQ113C | | QEP8121 |
| PHY | | PHY |
------------- -----------The primary objective for this series is to support the Ethernet functionality provided by the TC956x. The code providing this support has been structured into three distinct modules.
- A driver for the GPIO controller
- Code enabling the TC956x-specific eMAC/MSIGEN hardware
- A "chip" driver, associated with the PCIe functions
The GPIO driver is implemented separately because in some hardware configurations, these GPIO lines are used to manage resets for external Ethernet PHYs. We describe these PHYs via devicetree, where the GPIO-based reset signals are defined using phandles.
The code for the eMAC/MSIGEN consists of a new source file that populates hardware-specific details about the two MACs, and integrates with the existing stmmac driver. This also required implementing some enhancements to the core stmmac driver, described further below.
To manage the common functionality (including configuring address translation and controlling internal reset and clock signals), a "chip" driver is implemented. This chip driver is associated with the PCIe function *itself*, not the eMAC associated with the function.
The driver binds to the internal PCI functions 0 and 1, and creates a shared data structure describing the common chip elements the two driver instances share. Three auxiliary bus devices are created to represent the GPIO controller and the two Synopsys MAC controllers.
The driver instance for PCIe function 0 has responsibility for controlling the common chip functionality--creating the GPIO controller auxiliary device, configuring address translation between PCIe address space and internal addresses, and controlling clocks and resets. It creates a data structure--shared via its platform data pointer with PCIe function 1--to represent shared "chip" information. In addition, PCIe function 0 creates an auxiliary device to represent its attached eMAC. It allocates IRQs and maps BAR address ranges for use by the stmmac driver, passing them in a structure via the auxiliary device's platform data.
PCIe function 1 defers probing until after PCIe function 0 has created the shared data structure. After that its only job is to set up IRQs and mapped memory and create the eMAC1 auxiliary device.
The version of the Synopsys MAC IP is 3.01, which is largely compatible with version 2.20. The core stmmac driver required several changes to enable support for the TC956x.
- A change to dwxgmac2 support changes the interrupt mode when multi_msi_en is enabled.
- While most support for version 3.01 simply uses the 2.20 code, an erratum related to the RX ring length is implemented for 3.01 DMA operations.
- Having the PCIe device be separate from an auxiliarly device implementing the eMAC required allowing a distinct DMA device to be maintained for an stmmac interface.
In addition:
- A new source file provides memory-mapped access to XPCS using regmap. The alignment of the TC956x MDIO registers aren't suitable for using simple MMIO.
- Two additional XPCS changes are implemented that provides support for the XPCS as implemented in the TC956x.
This series is available here:
https://github.com/riscstar/linux/tree/tc956x/stmmac-v1
-Alex (and Daniel)
Alex Elder (3):
net: stmmac: dma: create a separate dma_device pointer
gpio: tc956x: add TC956x/QPS615 support
misc: tc956x_pci: add TC956x/QPS615 support
Daniel Thompson (9):
net: pcs: pcs-xpcs-regmap: support XPCS memory-mapped MDIO bus via
regmap
net: pcs: pcs-xpcs: select operating mode for 10G-baseR capable PCS
net: pcs: pcs-xpcs: Preserve BMCR_ANENBLE during link up
net: stmmac: dwxgmac2: Add multi MSI interrupt mode
net: stmmac: dwxgmac2: Add XGMAC 3.01a support
net: stmmac: dwxgmac2: export symbols for XGMAC 3.01a DMA
dt-bindings: net: toshiba,tc965x-dwmac: add TC956x Ethernet bridge
net: stmmac: tc956x: add TC956x/QPS615 support
arm64: dts: qcom: qcs6490-rb3gen2: enable TC9564 with a single QCS8081
phy
.../bindings/net/toshiba,tc956x-dwmac.yaml | 111 +++ arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts | 45 +- drivers/gpio/Kconfig | 11 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-tc956x.c | 209 +++++ drivers/misc/Kconfig | 10 + drivers/misc/Makefile | 1 + drivers/misc/tc956x_pci.c | 667 +++++++++++++++ drivers/net/ethernet/stmicro/stmmac/Kconfig | 13 + drivers/net/ethernet/stmicro/stmmac/Makefile | 2 + .../net/ethernet/stmicro/stmmac/chain_mode.c | 12 +- .../ethernet/stmicro/stmmac/dwmac-tc956x.c | 791 ++++++++++++++++++ .../net/ethernet/stmicro/stmmac/dwxgmac2.h | 12 + .../ethernet/stmicro/stmmac/dwxgmac2_core.c | 1 + .../ethernet/stmicro/stmmac/dwxgmac2_descs.c | 1 + .../ethernet/stmicro/stmmac/dwxgmac2_dma.c | 78 +- .../net/ethernet/stmicro/stmmac/ring_mode.c | 12 +- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 1 + .../net/ethernet/stmicro/stmmac/stmmac_main.c | 59 +- .../net/ethernet/stmicro/stmmac/stmmac_xdp.c | 2 +- drivers/net/pcs/Makefile | 4 +- drivers/net/pcs/pcs-xpcs-regmap.c | 203 +++++ drivers/net/pcs/pcs-xpcs.c | 43 +- include/linux/pcs/pcs-xpcs-regmap.h | 20 + include/linux/stmmac.h | 1 + include/soc/toshiba/tc956x-dwmac.h | 84 ++ 26 files changed, 2341 insertions(+), 53 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml create mode 100644 drivers/gpio/gpio-tc956x.c create mode 100644 drivers/misc/tc956x_pci.c create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c create mode 100644 drivers/net/pcs/pcs-xpcs-regmap.c create mode 100644 include/linux/pcs/pcs-xpcs-regmap.h create mode 100644 include/soc/toshiba/tc956x-dwmac.h
base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731
Signature · 1 line
2.51.0
PATCH 1/12 net: pcs: pcs-xpcs-regmap: support XPCS memory-mapped MDIO bus via regmap
From: Daniel Thompson <[email protected]>
In some DesignWare XPCS implementatons 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.
--- drivers/net/pcs/Makefile | 4 +- drivers/net/pcs/pcs-xpcs-regmap.c | 203 ++++++++++++++++++++++++++++ include/linux/pcs/pcs-xpcs-regmap.h | 20 +++ 3 files changed, 225 insertions(+), 2 deletions(-) create mode 100644 drivers/net/pcs/pcs-xpcs-regmap.c create mode 100644 include/linux/pcs/pcs-xpcs-regmap.h
drivers/net/pcs/Makefile +2 -2
@@ -1,8 +1,8 @@ # SPDX-License-Identifier: GPL-2.0 # 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-$(CONFIG_PCS_XPCS) := pcs-xpcs.o pcs-xpcs-nxp.o pcs-xpcs-regmap.o \ + pcs-xpcs-plat.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 +203 -0
203 lines not on this page · raw message
include/linux/pcs/pcs-xpcs-regmap.h new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __LINUX_PCS_XPCS_REGMAP_H +#define __LINUX_PCS_XPCS_REGMAP_H + +#include <linux/types.h> + +struct device ; +struct regmap ; +struct dw_xpcs ; + +struct xpcs_regmap_config { +struct regmap *regmap; +bool reg_indir; +}; + +struct dw_xpcs *devm_xpcs_regmap_register ( +struct device *dev,const struct xpcs_regmap_config *config); + +#endif /* __LINUX_PCS_XPCS_REGMAP_H */
Signature · 1 line
2.51.0
[email protected]
AI reviewRe: [PATCH net-next 01/12] 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: - [High] devm_xpcs_regmap_register violates devm lifecycle semantics and causes a resource leak. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] devm_xpcs_regmap_register violates devm lifecycle semantics and causes a resource leak. --
commit 0a11082b5acea20f4d45fbd6df8fb9ec06db752d
Author: Daniel Thompson <[email protected]>
net: pcs: pcs-xpcs-regmap: support XPCS memory-mapped MDIO bus via regmap
This commit introduces helpers to allow a driver to register an XPCS using a regmap for the memory-mapped MDIO bus. It adds the devm_xpcs_regmap_register function to manage the bus registration and interface abstractions.
Quoted 5 lines
drivers/net/pcs/pcs-xpcs-regmap.c new file +0
-0
[ ... ]
Quoted 3 lines
drivers/net/pcs/pcs-xpcs-regmap.c new file +3
-0+struct dw_xpcs *devm_xpcs_regmap_register (struct device *dev, +const struct xpcs_regmap_config *config) +{
[ ... ]
drivers/net/pcs/pcs-xpcs-regmap.c line 201
Quoted 7 lines
drivers/net/pcs/pcs-xpcs-regmap.c new file +7
-0+ ret =devm_mdiobus_register (dev, pxpcs->bus); +if (ret) { +dev_err (dev,"Failed to create MDIO bus\n" ); +return ERR_PTR (ret); + } + +return xpcs_create_mdiodev (pxpcs->bus,0 );
Could this cause a resource leak on driver unbind?
The devm_xpcs_regmap_register() function uses the devm_ prefix, implying an API contract where the returned dw_xpcs object will be automatically managed and cleaned up.
Internally, it calls xpcs_create_mdiodev(), which allocates the dw_xpcs structure and increments the reference count of the underlying mdio_device. These resources normally must be explicitly freed via xpcs_destroy().
Should this function register a devres cleanup action (for example, using devm_add_action_or_reset()) to invoke xpcs_destroy() during unbind?
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=1
Re: [PATCH net-next 01/12] net: pcs: pcs-xpcs-regmap: support XPCS memory-mapped MDIO bus via regmap
Quoted 27 lines · On 5/2/26 10:56 AM, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High]devm_xpcs_regmap_registerviolates devm lifecycle semantics and causes a resource leak. --commit
0a11082b5acea20f4d45fbd6df8fb9ec06db752d
Author: Daniel Thompson <[email protected]>net: pcs: pcs-xpcs-regmap: support XPCS memory-mapped MDIO bus via regmap
This commit introduces helpers to allow a driver to register an XPCS using a regmap for the memory-mapped MDIO bus. It adds the
devm_xpcs_regmap_registerfunction to manage the bus registration and interface abstractions.Quoted 5 lines
drivers/net/pcs/pcs-xpcs-regmap.c new file +0
-0[ ... ]
Quoted 3 lines
drivers/net/pcs/pcs-xpcs-regmap.c new file +3
-0+struct dw_xpcs *devm_xpcs_regmap_register (struct device *dev, +const struct xpcs_regmap_config *config) +{[ ... ]
Quoted 9 lines
drivers/net/pcs/pcs-xpcs-regmap.c line 201
Quoted 7 lines
drivers/net/pcs/pcs-xpcs-regmap.c new file +7
-0+ ret =devm_mdiobus_register (dev, pxpcs->bus); +if (ret) { +dev_err (dev,"Failed to create MDIO bus\n" ); +return ERR_PTR (ret); + } + +return xpcs_create_mdiodev (pxpcs->bus,0 );Could this cause a resource leak on driver unbind?
Yes it could. This will be fixed by checking the return value here, and if it does not indicate an error, setting up a devm action to call xpcs_destroy() on the dw_xpcs structure created.
-Alex
Quoted 14 lines
The
devm_xpcs_regmap_register()function uses thedevm_prefix, implying an API contract where the returneddw_xpcsobject will be automatically managed and cleaned up.Internally, it calls
xpcs_create_mdiodev(), which allocates thedw_xpcsstructure and increments the reference count of the underlyingmdio_device. These resources normally must be explicitly freed viaxpcs_destroy().Should this function register a devres cleanup action (for example, using
devm_add_action_or_reset()) to invokexpcs_destroy()during unbind?Quoted 2 lines
drivers/net/pcs/pcs-xpcs-regmap.c new file +2
-0+} +EXPORT_SYMBOL_GPL (devm_xpcs_regmap_register);
PATCH 2/12 net: pcs: pcs-xpcs: select operating mode for 10G-baseR capable PCS
In reply to Alex ElderFrom: Daniel Thompson <[email protected]>
Currently the XPCS found on Toshiba TC9564 (a.k.a. Qualcomm QPS615) is unable to operate at 1000base-X and slower with a PHY connected using SGMII/2500base-X (in our case a Qualcomm QCA8081).
The problem arises when the XPCS supports 10Gbase-R. That means that the reset value of SR_XS_PCS_CTRL2:PCS_TYPE_SEL (0) is valid and this suppresses the modal switching based on bit 13 of SR_PMA_CTRL1 or SR_XS_PCS_CTRL1.
The reported XPCS dev ID on a TC9564 is exactly the same as every other XPCS supported by the kernel so we can't use the dev ID to automatically determine what operating mode to select. However we can use the feature bits in SR_XS_PCS_STS2 to detect 10Gbase-R support.
Rather than introduce a quirk let's attempt to solve this generically by setting SR_XS_PCS_CTRL2:PCS_TYPE_SEL to a reserved value when we detect the right we detect the right combination of phy interface and XPCS feature support.
--- drivers/net/pcs/pcs-xpcs.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
drivers/net/pcs/pcs-xpcs.c +38 -0
@@ -747,6 +747,40 @@ static void xpcs_pre_config(struct phylink_pcs *pcs, phy_interface_t interface) xpcs->need_reset = false; } +static int xpcs_config_operating_mode (struct dw_xpcs *xpcs,int an_mode) +{ +int mdio_stat2, ret; + +switch (an_mode) { +case DW_AN_C37_SGMII : +case DW_AN_C37_1000BASEX : +case DW_2500BASEX : + mdio_stat2 =xpcs_read (xpcs,MDIO_MMD_PCS ,MDIO_STAT2 ); +if (mdio_stat2 <0 ) +return mdio_stat2; + +/* +* If this XPCS supports 10Gbase-R then it will be the default +* which prevents 1000base-X and slower from working correctly. +* +* Why are we writing MDIO_PCS_CTRL2_TYPE + 1? We want the modal +* behaviour that comes when we pick a reserved value. XPCS +* allocates extra bits to this field and allocates values from +* 15 down so MDIO_PCS_CTRL2_TYPE + 1 is the value likely to +* be allocated last (and hopefully never). +*/ +if (mdio_stat2 &MDIO_PCS_STAT2_10GBR ) { + ret =xpcs_write (xpcs,MDIO_MMD_PCS ,MDIO_CTRL2 , +MDIO_PCS_CTRL2_TYPE +1 ); +if (ret <0 ) +return ret; + } +break ; + } + +return 0 ; +} +static int xpcs_config_aneg_c37_sgmii (struct dw_xpcs *xpcs,unsigned int neg_mode) {
@@ -919,6 +953,10 @@ static int xpcs_do_config(struct dw_xpcs *xpcs, phy_interface_t interface,if (!compat)return -ENODEV ; + ret =xpcs_config_operating_mode (xpcs, compat->an_mode); +if (ret <0 ) +return ret; +if (xpcs->info.pma ==WX_TXGBE_XPCS_PMA_10G_ID ) {/* Wangxun devices need backplane CL37 AN enabled for * SGMII and 1000base-X
Signature · 1 line
2.51.0
Andrew Lunn
maintainerRe: [PATCH net-next 02/12] net: pcs: pcs-xpcs: select operating mode for 10G-baseR capable PCS
Quoted 5 lines
drivers/net/pcs/pcs-xpcs.c +5
-0+static int xpcs_config_operating_mode (struct dw_xpcs *xpcs,int an_mode) +{ +int mdio_stat2, ret; + +switch (an_mode) {
drivers/net/pcs/pcs-xpcs.c static void xpcs_pre_config(struct phylink_pcs *pcs, phy_interface_t interface) · line 764
Quoted 10 lines
drivers/net/pcs/pcs-xpcs.c +10
-0+case DW_AN_C37_SGMII : +case DW_AN_C37_1000BASEX : +case DW_2500BASEX : + mdio_stat2 =xpcs_read (xpcs,MDIO_MMD_PCS ,MDIO_STAT2 ); +if (mdio_stat2 <0 ) +return mdio_stat2; + +/* +* If this XPCS supports 10Gbase-R then it will be the default +* which prevents 1000base-X and slower from working correctly.
It would be interesting to know if Toshiba messed up the integration of the PCS, or there is an errata for the licensed IP.
Anybody got access to the databook and erratas?
Andrew
Re: [PATCH net-next 02/12] net: pcs: pcs-xpcs: select operating mode for 10G-baseR capable PCS
Quoted 19 lines · Andrew Lunn
Quoted 5 lines
drivers/net/pcs/pcs-xpcs.c +5
-0+static int xpcs_config_operating_mode (struct dw_xpcs *xpcs,int an_mode) +{ +int mdio_stat2, ret; + +switch (an_mode) {drivers/net/pcs/pcs-xpcs.c static void xpcs_pre_config(struct phylink_pcs *pcs, phy_interface_t interface) · line 764
Quoted 10 lines
drivers/net/pcs/pcs-xpcs.c +10
-0+case DW_AN_C37_SGMII : +case DW_AN_C37_1000BASEX : +case DW_2500BASEX : + mdio_stat2 =xpcs_read (xpcs,MDIO_MMD_PCS ,MDIO_STAT2 ); +if (mdio_stat2 <0 ) +return mdio_stat2; + +/* +* If this XPCS supports 10Gbase-R then it will be the default +* which prevents 1000base-X and slower from working correctly. It would be interesting to know if Toshiba messed up the integration of the PCS, or there is an errata for the licensed IP.
Quoted 3 lines
Anybody got access to the databook and erratas?
Andrew
I have the same question. We do not (currently/yet?) have access to this information.
-Alex
Re: [PATCH net-next 02/12] net: pcs: pcs-xpcs: select operating mode for 10G-baseR capable PCS
In reply to Andrew LunnQuoted 10 lines · Andrew Lunn
Quoted 10 lines
drivers/net/pcs/pcs-xpcs.c +10
-0+static int xpcs_config_operating_mode (struct dw_xpcs *xpcs,int an_mode) +{ +int mdio_stat2, ret; + +switch (an_mode) { +case DW_AN_C37_SGMII : +case DW_AN_C37_1000BASEX : +case DW_2500BASEX : + mdio_stat2 =xpcs_read (xpcs,MDIO_MMD_PCS ,MDIO_STAT2 ); +if (mdio_stat2 <0 )
Quoted 8 lines
drivers/net/pcs/pcs-xpcs.c static void xpcs_pre_config(struct phylink_pcs *pcs, phy_interface_t interface) · line 764
Quoted 5 lines
drivers/net/pcs/pcs-xpcs.c +5
-0+return mdio_stat2; + +/* +* If this XPCS supports 10Gbase-R then it will be the default +* which prevents 1000base-X and slower from working correctly. It would be interesting to know if Toshiba messed up the integration of the PCS, or there is an errata for the licensed IP.
I'm afraid I don't know, but it looks like the issue is not unique to Toshiba!
This is a discovery which, rather to my chagrin, I only made after we posted the patches (thanks to a hint from Sashiko): there is similar code in txgbe_xpcs_switch_mode(). I cleary overlooked that when I originally reviewed the existing XPCS code. I suspect I stopped scanning that code path due to the PMA related conditional branch...
Regardless of how I missed it, txgbe_xpcs_switch_mode() implements similar logic to this patch. I think it is using MDIO_PCS_CTRL2_10GBX as the Reserved value but otherwise looks similar. There are comments that imply 10Gbase-X isn't implemented by their XPCS which would make MDIO_PCS_CTRL2_10GBX reserved (but are too vague to be 100% sure).
Right now it looks like xpcs_switch_interface_mode() and my xpcs_config_operating_mode() are more closely related than I realized so I plan to move my code into xpcs_switch_interface_mode().
I don't think I can unify the Wangxun and Toshiba code (the waits and resets in the Wangxun code make that too high risk) but I'm not yet ready to give up and just make the Toshiba changes into another vendor quirk!
Daniel.
[email protected]
AI reviewRe: [PATCH net-next 02/12] net: pcs: pcs-xpcs: select operating mode for 10G-baseR capable PCS
In reply to Alex ElderThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] The generic workaround unconditionally overwrites `MDIO_CTRL2`, breaking Wangxun hardware.…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] The generic workaround unconditionally overwrites MDIO_CTRL2, breaking Wangxun hardware.
- [High] Transitioning from SGMII/1000BASEX to 10GBASE-R leaves MDIO_CTRL2 in a broken state, preventing 10G modes from functioning.
- [Medium] Synthesizing a hardware value by adding 1 to a UAPI bitmask macro is brittle and semantically incorrect. --
commit 797f904fd928c0648fed4442dd4dbb70a939a7f7
Author: Daniel Thompson <[email protected]>
net: pcs: pcs-xpcs: select operating mode for 10G-baseR capable PCS
The patch attempts to solve an issue where 10Gbase-R support suppresses modal switching for 1000base-X and slower speeds on XPCS. It sets the PCS_TYPE_SEL in MDIO_CTRL2 to a reserved value when detecting the relevant PHY interface and XPCS feature support.
Quoted 23 lines
drivers/net/pcs/pcs-xpcs.c +15
-0@@ -747,6 +747,40 @@ static void xpcs_pre_config(struct phylink_pcs *pcs, phy_interface_t interface) xpcs->need_reset = false; } +static int xpcs_config_operating_mode (struct dw_xpcs *xpcs,int an_mode) +{ +int mdio_stat2, ret; + +switch (an_mode) { +case DW_AN_C37_SGMII : +case DW_AN_C37_1000BASEX : +case DW_2500BASEX : + mdio_stat2 =xpcs_read (xpcs,MDIO_MMD_PCS ,MDIO_STAT2 ); +if (mdio_stat2 <0 ) +return mdio_stat2; + +/* +* If this XPCS supports 10Gbase-R then it will be the default +* which prevents 1000base-X and slower from working correctly.
drivers/net/pcs/pcs-xpcs.c static void xpcs_pre_config(struct phylink_pcs *pcs, phy_interface_t interface) · line 774
Quoted 10 lines
drivers/net/pcs/pcs-xpcs.c +10
-0+* +* Why are we writing MDIO_PCS_CTRL2_TYPE + 1? We want the modal +* behaviour that comes when we pick a reserved value. XPCS +* allocates extra bits to this field and allocates values from +* 15 down so MDIO_PCS_CTRL2_TYPE + 1 is the value likely to +* be allocated last (and hopefully never). +*/ +if (mdio_stat2 &MDIO_PCS_STAT2_10GBR ) { + ret =xpcs_write (xpcs,MDIO_MMD_PCS ,MDIO_CTRL2 , +MDIO_PCS_CTRL2_TYPE +1 );
Is it safe to calculate the reserved value by adding 1 to the bitmask macro MDIO_PCS_CTRL2_TYPE?
MDIO_PCS_CTRL2_TYPE is defined in <uapi/linux/mdio.h> as a bitmask (0x0003), not a maximum integer value. While this evaluates to 4 today, if the IEEE standard expands the PCS type selection field (e.g. to a 4-bit mask 0x000F), this expression will evaluate to 16, overflowing the field. Could this use an explicit local constant for the targeted proprietary reserved value instead?
Also, could this cause issues if the interface is dynamically switched back to a 10G mode (e.g., DW_10GBASER)?
If the interface switches from SGMII to DW_10GBASER, xpcs_config_operating_mode() hits an empty switch case and does not update the register. Because xpcs_switch_interface_mode() only sets xpcs->need_reset = true when switching to SGMII, no soft reset is triggered, leaving MDIO_CTRL2 stuck at the reserved value 4 and breaking 10GBASE-R modal behavior.
Quoted 9 lines
drivers/net/pcs/pcs-xpcs.c +9
-0+if (ret <0 ) +return ret; + } +break ; + } + +return 0 ; +} +
[ ... ]
drivers/net/pcs/pcs-xpcs.c static int xpcs_do_config(struct dw_xpcs *xpcs, phy_interface_t interface, · line 956
Quoted 5 lines
drivers/net/pcs/pcs-xpcs.c +1
-0@@ -919,6 +953,10 @@ static int xpcs_do_config(struct dw_xpcs *xpcs, phy_interface_t interface,if (!compat)return -ENODEV ; + ret =xpcs_config_operating_mode (xpcs, compat->an_mode);
Does this unconditionally overwrite MDIO_CTRL2 and break Wangxun hardware?
For Wangxun devices, xpcs_pre_config() calls xpcs_switch_interface_mode(), which delegates to txgbe_xpcs_switch_mode(). This explicitly configures MDIO_CTRL2 to MDIO_PCS_CTRL2_10GBX (1) for SGMII and 1000BASE-X.
Later, xpcs_do_config() calls xpcs_config_operating_mode() here. Because Wangxun devices support 10GBASE-R, it writes the reserved value 4 to MDIO_CTRL2. This clobbers the required Wangxun-specific 10GBX state, forcing the hardware into a reserved state and breaking the link.
Quoted 6 lines
drivers/net/pcs/pcs-xpcs.c +3
-0+if (ret <0 ) +return ret; +if (xpcs->info.pma ==WX_TXGBE_XPCS_PMA_10G_ID ) {/* Wangxun devices need backplane CL37 AN enabled for * SGMII and 1000base-X
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH net-next 02/12] net: pcs: pcs-xpcs: select operating mode for 10G-baseR capable PCS
Quoted 44 lines · On 5/2/26 10:56 AM, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] The generic workaround unconditionally overwritesMDIO_CTRL2, breaking Wangxun hardware.
- [High] Transitioning from SGMII/1000BASEX to 10GBASE-R leavesMDIO_CTRL2in a broken state, preventing 10G modes from functioning.
- [Medium] Synthesizing a hardware value by adding 1 to a UAPI bitmask macro is brittle and semantically incorrect. --commit
797f904fd928c0648fed4442dd4dbb70a939a7f7
Author: Daniel Thompson <[email protected]>net: pcs: pcs-xpcs: select operating mode for 10G-baseR capable PCS
The patch attempts to solve an issue where 10Gbase-R support suppresses modal switching for 1000base-X and slower speeds on XPCS. It sets the
PCS_TYPE_SELinMDIO_CTRL2to a reserved value when detecting the relevant PHY interface and XPCS feature support.Quoted 28 lines
drivers/net/pcs/pcs-xpcs.c +20
-0@@ -747,6 +747,40 @@ static void xpcs_pre_config(struct phylink_pcs *pcs, phy_interface_t interface) xpcs->need_reset = false; } +static int xpcs_config_operating_mode (struct dw_xpcs *xpcs,int an_mode) +{ +int mdio_stat2, ret; + +switch (an_mode) { +case DW_AN_C37_SGMII : +case DW_AN_C37_1000BASEX : +case DW_2500BASEX : + mdio_stat2 =xpcs_read (xpcs,MDIO_MMD_PCS ,MDIO_STAT2 ); +if (mdio_stat2 <0 ) +return mdio_stat2; + +/* +* If this XPCS supports 10Gbase-R then it will be the default +* which prevents 1000base-X and slower from working correctly. +* +* Why are we writing MDIO_PCS_CTRL2_TYPE + 1? We want the modal +* behaviour that comes when we pick a reserved value. XPCS +* allocates extra bits to this field and allocates values from +* 15 down so MDIO_PCS_CTRL2_TYPE + 1 is the value likely to
Quoted 8 lines
drivers/net/pcs/pcs-xpcs.c static void xpcs_pre_config(struct phylink_pcs *pcs, phy_interface_t interface) · line 774
Quoted 5 lines
drivers/net/pcs/pcs-xpcs.c +5
-0+* be allocated last (and hopefully never). +*/ +if (mdio_stat2 &MDIO_PCS_STAT2_10GBR ) { + ret =xpcs_write (xpcs,MDIO_MMD_PCS ,MDIO_CTRL2 , +MDIO_PCS_CTRL2_TYPE +1 );Is it safe to calculate the reserved value by adding 1 to the bitmask macro
MDIO_PCS_CTRL2_TYPE?
This is a good observation, and for the reasons pointed out, it might not be "safe".
The comment above the assignment explains that what's going on is intentional (to get a behavior that comes from writing a reserved value), and was done in way that tries to avoid an eventual problem.
The next version of the code will still do this the same way, but we would welcome a suggestion for a better way to handle this.
Quoted 28 lines
MDIO_PCS_CTRL2_TYPEis defined in <uapi/linux/mdio.h> as a bitmask (0x0003), not a maximum integer value. While this evaluates to 4 today, if the IEEE standard expands the PCS type selection field (e.g. to a 4-bit mask0x000F), this expression will evaluate to 16, overflowing the field. Could this use an explicit local constant for the targeted proprietary reserved value instead?Also, could this cause issues if the interface is dynamically switched back to a 10G mode (e.g.,
DW_10GBASER)?If the interface switches from SGMII to
DW_10GBASER,xpcs_config_operating_mode()hits an empty switch case and does not update the register. Becausexpcs_switch_interface_mode()only setsxpcs->need_reset= true when switching to SGMII, no soft reset is triggered, leavingMDIO_CTRL2stuck at the reserved value 4 and breaking 10GBASE-R modal behavior.Quoted 9 lines
drivers/net/pcs/pcs-xpcs.c +9
-0+if (ret <0 ) +return ret; + } +break ; + } + +return 0 ; +} +[ ... ]
Quoted 7 lines
drivers/net/pcs/pcs-xpcs.c static int xpcs_do_config(struct dw_xpcs *xpcs, phy_interface_t interface, · line 956
Quoted 5 lines
drivers/net/pcs/pcs-xpcs.c +1
-0@@ -919,6 +953,10 @@ static int xpcs_do_config(struct dw_xpcs *xpcs, phy_interface_t interface,if (!compat)return -ENODEV ; + ret =xpcs_config_operating_mode (xpcs, compat->an_mode);Does this unconditionally overwrite
MDIO_CTRL2and break Wangxun hardware?
The next version of the code reworks how this is done. The code will preserve the special behavior used for Wanxun hardware, but will update the operating mode in a way similar to what's done in the current patch otherwise.
-Alex
Quoted 17 lines
For Wangxun devices,
xpcs_pre_config()callsxpcs_switch_interface_mode(), which delegates totxgbe_xpcs_switch_mode(). This explicitly configuresMDIO_CTRL2toMDIO_PCS_CTRL2_10GBX(1) for SGMII and 1000BASE-X.Later,
xpcs_do_config()callsxpcs_config_operating_mode()here. Because Wangxun devices support 10GBASE-R, it writes the reserved value 4 toMDIO_CTRL2. This clobbers the required Wangxun-specific 10GBX state, forcing the hardware into a reserved state and breaking the link.Quoted 6 lines
drivers/net/pcs/pcs-xpcs.c +3
-0+if (ret <0 ) +return ret; +if (xpcs->info.pma ==WX_TXGBE_XPCS_PMA_10G_ID ) {/* Wangxun devices need backplane CL37 AN enabled for * SGMII and 1000base-X
PATCH 3/12 net: pcs: pcs-xpcs: Preserve BMCR_ANENBLE during link up
In reply to Alex ElderFrom: Daniel Thompson <[email protected]>
Currently the XCPS found on Toshiba TC9564 (a.k.a. Qualcomm QPS615) is unable to operate at 1000base-X and slower with a PHY connected using SGMII/2500base-X (in our case a Qualcomm QCA8081). The link negotiates speed correctly but the MAC can't get any packets out.
This attracted attention to the ANENABLE bit and we observed that the bit is currently set during config and cleared during link up. Preserving the bit during link up allows the system to work as expected.
Perhaps I lack the imagination but I couldn't come up with any reason why keeping the ANENABLE bit set would break things for other XPCS implementations. Let's ensure link up sets the bit for SGMII interfaces.
--- drivers/net/pcs/pcs-xpcs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/pcs/pcs-xpcs.c +4 -1
@@ -1263,11 +1263,14 @@ static void xpcs_link_up_sgmii_1000basex(struct dw_xpcs *xpcs,phy_interface_t interface, int speed, int duplex) { + u16 an_enable;int ret;if (neg_mode ==PHYLINK_PCS_NEG_INBAND_ENABLED )return ; + an_enable = (interface ==PHY_INTERFACE_MODE_SGMII ?BMCR_ANENABLE :0 ); +if (interface ==PHY_INTERFACE_MODE_1000BASEX ) {if (speed !=SPEED_1000 ) { dev_err(&xpcs->mdiodev->dev,
@@ -1283,7 +1286,7 @@ static void xpcs_link_up_sgmii_1000basex(struct dw_xpcs *xpcs, } ret =xpcs_write (xpcs,MDIO_MMD_VEND2 ,MII_BMCR , -mii_bmcr_encode_fixed (speed, duplex)); +mii_bmcr_encode_fixed (speed, duplex) | an_enable);if (ret)dev_err (&xpcs->mdiodev->dev,"%s: xpcs_write returned %pe\n" , __func__,ERR_PTR (ret));
Signature · 1 line
2.51.0
Andrew Lunn
maintainerRe: [PATCH net-next 03/12] net: pcs: pcs-xpcs: Preserve BMCR_ANENBLE during link up
Quoted 6 lines · Alex Elder
From: Daniel Thompson <[email protected]>
Currently the XCPS found on Toshiba TC9564 (a.k.a. Qualcomm QPS615) is unable to operate at 1000base-X and slower with a PHY connected using SGMII/2500base-X (in our case a Qualcomm QCA8081). The link negotiates speed correctly but the MAC can't get any packets out.
We need to break this down into its components.
I assume you are saying the PHY negotiates the media speed with the link partner. That is PHY talking to PHY.
But we also have the PCS talking to the PHY. There can be inband signalling here, for SGMII and 2500BaseX. But not for over clocked SGMII, which is how some vendors implement 2500BaseX. SGMII signalling does not work when overclocked to 2.5G.
Quoted 2 lines
This attracted attention to the ANENABLE bit and we observed that the bit is currently set during config and cleared during link up.
Here we are talking about the PCS ANEBNABLE, not the PHY ANEBNABLE. So this is negotiation between the PCS and the PHY.
drivers/net/pcs/pcs-xpcs.c static void xpcs_link_up_sgmii_1000basex(struct dw_xpcs *xpcs, · line 1270
Quoted 6 lines
Preserving the bit during link up allows the system to work as expected.
drivers/net/pcs/pcs-xpcs.c +0
-0int ret;if (neg_mode ==PHYLINK_PCS_NEG_INBAND_ENABLED )return ;
Think about this.
drivers/net/pcs/pcs-xpcs.c static void xpcs_link_up_sgmii_1000basex(struct dw_xpcs *xpcs, · line 1289
Quoted 3 lines
drivers/net/pcs/pcs-xpcs.c +1
-1ret =xpcs_write (xpcs,MDIO_MMD_VEND2 ,MII_BMCR , -mii_bmcr_encode_fixed (speed, duplex)); +mii_bmcr_encode_fixed (speed, duplex) | an_enable);
And mii_bmcr_encode_fixed().
Andrew
Re: [PATCH net-next 03/12] net: pcs: pcs-xpcs: Preserve BMCR_ANENBLE during link up
Quoted 31 lines · Andrew Lunn
Quoted 6 lines · Alex Elder
From: Daniel Thompson <[email protected]>
Currently the XCPS found on Toshiba TC9564 (a.k.a. Qualcomm QPS615) is unable to operate at 1000base-X and slower with a PHY connected using SGMII/2500base-X (in our case a Qualcomm QCA8081). The link negotiates speed correctly but the MAC can't get any packets out.
We need to break this down into its components.
I assume you are saying the PHY negotiates the media speed with the link partner. That is PHY talking to PHY.
But we also have the PCS talking to the PHY. There can be inband signalling here, for SGMII and 2500BaseX. But not for over clocked SGMII, which is how some vendors implement 2500BaseX. SGMII signalling does not work when overclocked to 2.5G.
Quoted 2 lines
This attracted attention to the ANENABLE bit and we observed that the bit is currently set during config and cleared during link up.
Here we are talking about the PCS ANEBNABLE, not the PHY ANEBNABLE. So this is negotiation between the PCS and the PHY.
drivers/net/pcs/pcs-xpcs.c static void xpcs_link_up_sgmii_1000basex(struct dw_xpcs *xpcs, · line 1270
Quoted 6 lines
Preserving the bit during link up allows the system to work as expected.
drivers/net/pcs/pcs-xpcs.c +0
-0int ret;if (neg_mode ==PHYLINK_PCS_NEG_INBAND_ENABLED )return ;
Quoted 7 lines
Think about this.
drivers/net/pcs/pcs-xpcs.c static void xpcs_link_up_sgmii_1000basex(struct dw_xpcs *xpcs, · line 1289
Quoted 3 lines
drivers/net/pcs/pcs-xpcs.c +1
-1ret =xpcs_write (xpcs,MDIO_MMD_VEND2 ,MII_BMCR , -mii_bmcr_encode_fixed (speed, duplex)); +mii_bmcr_encode_fixed (speed, duplex) | an_enable);And
mii_bmcr_encode_fixed().
Thanks for highlighting that... and for being gentle with the clue stick!
This patch will be gone the next time this patchset is published and I'll get the phylink configured properly.
Daniel.
[email protected]
AI reviewRe: [PATCH net-next 03/12] net: pcs: pcs-xpcs: Preserve BMCR_ANENBLE during link up
In reply to Alex ElderThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Unconditionally forcing BMCR_ANENABLE for SGMII interfaces during out-of-band link configuration…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Unconditionally forcing BMCR_ANENABLE for SGMII interfaces during out-of-band link configuration breaks forced and fixed links. --
commit 3fde24f4d6c6c8c6b563418e32cec40953863f8a
Author: Daniel Thompson <[email protected]>
net: pcs: pcs-xpcs: Preserve BMCR_ANENBLE during link up
This commit unconditionally sets the BMCR_ANENABLE bit for SGMII interfaces during link up. This change was introduced to resolve an issue on a specific hardware platform where the MAC fails to transmit packets despite negotiating the speed correctly.
Quoted 6 lines
drivers/net/pcs/pcs-xpcs.c +0
-0@@ -1263,11 +1263,14 @@ static void xpcs_link_up_sgmii_1000basex(struct dw_xpcs *xpcs, phy_interface_t interface,
drivers/net/pcs/pcs-xpcs.c static void xpcs_link_up_sgmii_1000basex(struct dw_xpcs *xpcs, · line 1273
Quoted 10 lines
drivers/net/pcs/pcs-xpcs.c +3
-0int speed, int duplex) { +u16 an_enable;int ret;if (neg_mode ==PHYLINK_PCS_NEG_INBAND_ENABLED )return ; + an_enable = (interface ==PHY_INTERFACE_MODE_SGMII ?BMCR_ANENABLE :0 ); +
Will this break forced and fixed links by enabling auto-negotiation?
This function handles forcing the link state when in-band auto-negotiation is explicitly disabled, as indicated by the early return for PHYLINK_PCS_NEG_INBAND_ENABLED. When this function continues, phylink is requesting out-of-band negotiation or a fixed link.
By unconditionally setting BMCR_ANENABLE here, the hardware might ignore the fixed speed and duplex bits, instead waiting for auto-negotiation to complete. If the system uses a fixed link (e.g., MAC-to-MAC) or connects to a PHY with in-band signaling disabled, SGMII AN base pages will never arrive.
Could this cause the MAC PCS to wait indefinitely, failing to establish a link and dropping all traffic?
[ ... ]
Quoted 3 lines
drivers/net/pcs/pcs-xpcs.c +1
-1ret =xpcs_write (xpcs,MDIO_MMD_VEND2 ,MII_BMCR , -mii_bmcr_encode_fixed (speed, duplex)); +mii_bmcr_encode_fixed (speed, duplex) | an_enable);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [PATCH net-next 03/12] net: pcs: pcs-xpcs: Preserve BMCR_ANENBLE during link up
Quoted 25 lines · On 5/2/26 10:56 AM, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Unconditionally forcingBMCR_ANENABLEfor SGMII interfaces during out-of-band link configuration breaks forced and fixed links. --commit
3fde24f4d6c6c8c6b563418e32cec40953863f8a
Author: Daniel Thompson <[email protected]>net: pcs: pcs-xpcs: Preserve
BMCR_ANENBLEduring link upThis commit unconditionally sets the
BMCR_ANENABLEbit for SGMII interfaces during link up. This change was introduced to resolve an issue on a specific hardware platform where the MAC fails to transmit packets despite negotiating the speed correctly.Quoted 11 lines
drivers/net/pcs/pcs-xpcs.c +1
-0@@ -1263,11 +1263,14 @@ static void xpcs_link_up_sgmii_1000basex(struct dw_xpcs *xpcs,phy_interface_t interface, int speed, int duplex) { + u16 an_enable;int ret;
Quoted 7 lines
drivers/net/pcs/pcs-xpcs.c static void xpcs_link_up_sgmii_1000basex(struct dw_xpcs *xpcs, · line 1273
Quoted 5 lines
drivers/net/pcs/pcs-xpcs.c +2
-0if (neg_mode ==PHYLINK_PCS_NEG_INBAND_ENABLED )return ; + an_enable = (interface ==PHY_INTERFACE_MODE_SGMII ?BMCR_ANENABLE :0 ); +Will this break forced and fixed links by enabling auto-negotiation?
The next version of this code will handle this differently, setting the plat_stmmacenet_data->default_an_inband flag to true instead.
-Alex
Quoted 21 lines
This function handles forcing the link state when in-band auto-negotiation is explicitly disabled, as indicated by the early return for
PHYLINK_PCS_NEG_INBAND_ENABLED. When this function continues, phylink is requesting out-of-band negotiation or a fixed link.By unconditionally setting
BMCR_ANENABLEhere, the hardware might ignore the fixed speed and duplex bits, instead waiting for auto-negotiation to complete. If the system uses a fixed link (e.g., MAC-to-MAC) or connects to a PHY with in-band signaling disabled, SGMII AN base pages will never arrive.Could this cause the MAC PCS to wait indefinitely, failing to establish a link and dropping all traffic?
[ ... ]
Quoted 3 lines
drivers/net/pcs/pcs-xpcs.c +1
-1ret =xpcs_write (xpcs,MDIO_MMD_VEND2 ,MII_BMCR , -mii_bmcr_encode_fixed (speed, duplex)); +mii_bmcr_encode_fixed (speed, duplex) | an_enable);
PATCH 4/12 net: stmmac: dma: create a separate dma_device pointer
In reply to Alex ElderThe Toshiba TC956x Ethernet bridge chip is an Ethernet AVN/TSN bridge that is essentially a small but specialized SoC. It provides two XGMAC Ethernet interfaces along with a number of internal IP blocks, some of which are used by both eMACs.
The chip implements two internal PCIe functions, and one of these is used to manage the common internal IPs. Both of the PCIe functions use an auxiliary bus device to represent an XGMAC Ethernet interface. Separating the PCIe function from the XGMAC IP this way helps in managing the life cycle for various objects (common and per-MAC).
However this separation means that the MAC device is no longer the proper device to use for DMA. To address this, we add support for a second "DMA device" pointer in the stmmac_priv structure. The DMA device pointer is used for all DMA operations, while the "normal" device pointer is used for log messages, memory allocation, runtime power management, and a few other things.
To set up the DMA device pointer, we add a new device structure pointer to the plat_stmmacenet_data structure. If set, it will be assigned as the (new) dma_device pointer field in the stmmac_priv structure. If the plat_stmmacenet_data field is NULL, the "normal" device pointer is assigned as the dma_device pointer instead (preserving existing behavior).
--- .../net/ethernet/stmicro/stmmac/chain_mode.c | 12 ++-- .../net/ethernet/stmicro/stmmac/ring_mode.c | 12 ++-- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 1 + .../net/ethernet/stmicro/stmmac/stmmac_main.c | 59 ++++++++++--------- .../net/ethernet/stmicro/stmmac/stmmac_xdp.c | 2 +- include/linux/stmmac.h | 1 + 6 files changed, 46 insertions(+), 41 deletions(-)
drivers/net/ethernet/stmicro/stmmac/chain_mode.c +6 -6
@@ -34,10 +34,10 @@ static int jumbo_frm(struct stmmac_tx_queue *tx_q, struct sk_buff *skb, buf_len = min_t(unsigned int, nopaged_len, bmax); len = nopaged_len - buf_len; - des2 =dma_map_single (priv->device, skb->data, + des2 =dma_map_single (priv->dma_device, skb->data, buf_len,DMA_TO_DEVICE ); desc->des2 =cpu_to_le32 (des2); -if (dma_mapping_error (priv->device, des2)) +if (dma_mapping_error (priv->dma_device, des2))return -1 ; tx_q->tx_skbuff_dma[entry].buf = des2; tx_q->tx_skbuff_dma[entry].len = buf_len;
@@ -51,11 +51,11 @@ static int jumbo_frm(struct stmmac_tx_queue *tx_q, struct sk_buff *skb, desc = tx_q->dma_tx + entry;if (len > bmax) { - des2 =dma_map_single (priv->device, + des2 =dma_map_single (priv->dma_device, (skb->data + bmax * i), bmax,DMA_TO_DEVICE ); desc->des2 =cpu_to_le32 (des2); -if (dma_mapping_error (priv->device, des2)) +if (dma_mapping_error (priv->dma_device, des2))return -1 ; tx_q->tx_skbuff_dma[entry].buf = des2; tx_q->tx_skbuff_dma[entry].len = bmax;
@@ -64,11 +64,11 @@ static int jumbo_frm(struct stmmac_tx_queue *tx_q, struct sk_buff *skb, len -= bmax; i++; }else { - des2 =dma_map_single (priv->device, + des2 =dma_map_single (priv->dma_device, (skb->data + bmax * i), len,DMA_TO_DEVICE ); desc->des2 =cpu_to_le32 (des2); -if (dma_mapping_error (priv->device, des2)) +if (dma_mapping_error (priv->dma_device, des2))return -1 ; tx_q->tx_skbuff_dma[entry].buf = des2; tx_q->tx_skbuff_dma[entry].len = len;
drivers/net/ethernet/stmicro/stmmac/ring_mode.c +6 -6
@@ -37,10 +37,10 @@ static int jumbo_frm(struct stmmac_tx_queue *tx_q, struct sk_buff *skb,if (nopaged_len > BUF_SIZE_8KiB) { - des2 =dma_map_single (priv->device, skb->data, bmax, + des2 =dma_map_single (priv->dma_device, skb->data, bmax,DMA_TO_DEVICE ); desc->des2 =cpu_to_le32 (des2); -if (dma_mapping_error (priv->device, des2)) +if (dma_mapping_error (priv->dma_device, des2))return -1 ; tx_q->tx_skbuff_dma[entry].buf = des2;
@@ -58,10 +58,10 @@ static int jumbo_frm(struct stmmac_tx_queue *tx_q, struct sk_buff *skb,else desc = tx_q->dma_tx + entry; - des2 =dma_map_single (priv->device, skb->data + bmax, len, + des2 =dma_map_single (priv->dma_device, skb->data + bmax, len,DMA_TO_DEVICE ); desc->des2 =cpu_to_le32 (des2); -if (dma_mapping_error (priv->device, des2)) +if (dma_mapping_error (priv->dma_device, des2))return -1 ; tx_q->tx_skbuff_dma[entry].buf = des2; tx_q->tx_skbuff_dma[entry].len = len;
@@ -72,10 +72,10 @@ static int jumbo_frm(struct stmmac_tx_queue *tx_q, struct sk_buff *skb,STMMAC_RING_MODE ,1 , !skb_is_nonlinear (skb), skb->len); }else { - des2 =dma_map_single (priv->device, skb->data, + des2 =dma_map_single (priv->dma_device, skb->data, nopaged_len,DMA_TO_DEVICE ); desc->des2 =cpu_to_le32 (des2); -if (dma_mapping_error (priv->device, des2)) +if (dma_mapping_error (priv->dma_device, des2))return -1 ; tx_q->tx_skbuff_dma[entry].buf = des2; tx_q->tx_skbuff_dma[entry].len = nopaged_len;
drivers/net/ethernet/stmicro/stmmac/stmmac.h +1 -0
@@ -278,6 +278,7 @@ struct stmmac_priv {void __iomem *ioaddr;struct net_device *dev;struct device *device; +struct device *dma_device;struct mac_device_info *hw;int (*hwif_quirks)(struct stmmac_priv *priv);struct mutex lock;
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +31 -28
186 lines not on this page · raw message
drivers/net/ethernet/stmicro/stmmac/stmmac_xdp.c +1 -1
@@ -25,7 +25,7 @@ static int stmmac_xdp_enable_pool(struct stmmac_priv *priv,if (frame_size <ETH_FRAME_LEN +VLAN_HLEN *2 )return -EOPNOTSUPP ; - err =xsk_pool_dma_map (pool, priv->device,STMMAC_RX_DMA_ATTR ); + err =xsk_pool_dma_map (pool, priv->dma_device,STMMAC_RX_DMA_ATTR );if (err) {netdev_err (priv->dev,"Failed to map xsk pool\n" );return err;
include/linux/stmmac.h +1 -0
@@ -245,6 +245,7 @@ struct plat_stmmacenet_data {struct stmmac_mdio_bus_data *mdio_bus_data;struct device_node *phy_node;struct device_node *mdio_node; +struct device *dma_device;struct stmmac_dma_cfg *dma_cfg;struct stmmac_safety_feature_cfg *safety_feat_cfg;int clk_csr;
Signature · 1 line
2.51.0
Andrew Lunn
maintainerRe: [PATCH net-next 04/12] net: stmmac: dma: create a separate dma_device pointer
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static int __stmmac_dvr_probe(struct device *device, · line 7944
Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3
-2if (priv->dma_cap.host_dma_width) { - ret =dma_set_mask_and_coherent (device, -DMA_BIT_MASK (priv->dma_cap.host_dma_width)); +u64 mask =DMA_BIT_MASK (priv->dma_cap.host_dma_width); + + ret =dma_set_mask_and_coherent (priv->dma_device, mask);
I'm nitpicking, but i don't think you need to introduce mask. DMA_BIT_MASK... is already on a line of its own, and is within the 80 limit. Nothing changes here with s/device/priv->dma_device/
Andrew
Re: [PATCH net-next 04/12] net: stmmac: dma: create a separate dma_device pointer
Quoted 11 lines · Andrew Lunn
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static int __stmmac_dvr_probe(struct device *device, · line 7944
Quoted 6 lines
if (priv->dma_cap.host_dma_width) {drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3
-2- ret =dma_set_mask_and_coherent (device, -DMA_BIT_MASK (priv->dma_cap.host_dma_width)); +u64 mask =DMA_BIT_MASK (priv->dma_cap.host_dma_width); + + ret =dma_set_mask_and_coherent (priv->dma_device, mask);I'm nitpicking, but i don't think you need to introduce mask.
DMA_BIT_MASK... is already on a line of its own, and is within the 80 limit. Nothing changes here with s/device/priv->dma_device/
Quoted 1 line
Andrew
I did this. It was simply to silence a checkpatch.pl warning about a long line.
I don't care either way, I'll gladly put it back the way it was.
-Alex
Andrew Lunn
maintainerRe: [PATCH net-next 04/12] net: stmmac: dma: create a separate dma_device pointer
Quoted 12 lines · Alex Elder
Quoted 11 lines · Andrew Lunn
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static int __stmmac_dvr_probe(struct device *device, · line 7944
Quoted 6 lines
if (priv->dma_cap.host_dma_width) {drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3
-2- ret =dma_set_mask_and_coherent (device, -DMA_BIT_MASK (priv->dma_cap.host_dma_width)); +u64 mask =DMA_BIT_MASK (priv->dma_cap.host_dma_width); + + ret =dma_set_mask_and_coherent (priv->dma_device, mask);I'm nitpicking, but i don't think you need to introduce mask.
DMA_BIT_MASK... is already on a line of its own, and is within the 80 limit. Nothing changes here with s/device/priv->dma_device/
Quoted 6 lines
Quoted 1 line
Andrew
I did this. It was simply to silence a checkpatch.pl warning about a long line.
I don't care either way, I'll gladly put it back the way it was.
Please pull checkpatch fixes out into a patch of their own.
Andrew
Re: [PATCH net-next 04/12] net: stmmac: dma: create a separate dma_device pointer
Quoted 13 lines · Andrew Lunn
Quoted 12 lines · Alex Elder
Quoted 11 lines · Andrew Lunn
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static int __stmmac_dvr_probe(struct device *device, · line 7944
Quoted 6 lines
if (priv->dma_cap.host_dma_width) {drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3
-2- ret =dma_set_mask_and_coherent (device, -DMA_BIT_MASK (priv->dma_cap.host_dma_width)); +u64 mask =DMA_BIT_MASK (priv->dma_cap.host_dma_width); + + ret =dma_set_mask_and_coherent (priv->dma_device, mask);I'm nitpicking, but i don't think you need to introduce mask.
DMA_BIT_MASK... is already on a line of its own, and is within the 80 limit. Nothing changes here with s/device/priv->dma_device/
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Andrew
I did this. It was simply to silence a checkpatch.pl warning about a long line.
I don't care either way, I'll gladly put it back the way it was.
Please pull checkpatch fixes out into a patch of their own.
That's what we'll do in the next version. I'll undo this particular change, and will add it to the end of the series.
Thanks.
-Alex
Quoted 2 lines
Andrew
[email protected]
AI reviewRe: [PATCH net-next 04/12] net: stmmac: dma: create a separate dma_device pointer
In reply to Alex ElderThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] DMA mappings are permanently leaked if an error occurs mid-packet in `stmmac_xmit`…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] DMA mappings are permanently leaked if an error occurs mid-packet in stmmac_xmit, stmmac_tso_xmit, or jumbo_frm.
- [High] In jumbo_frm() (chain_mode.c and ring_mode.c), assigning a dma_addr_t to an unsigned int breaks dma_mapping_error() detection. --
commit 152df859f4e94baeb0ca419c5b87bcb9e5f13d3d
Author: Alex Elder <[email protected]>
net: stmmac: dma: create a separate dma_device pointer
This commit adds a second dma_device pointer to the stmmac_priv structure. The new pointer handles all DMA operations independently from the normal device pointer, allowing better management of common internal IPs for specialized Ethernet bridge chips.
Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/chain_mode.c +0
-0
drivers/net/ethernet/stmicro/stmmac/chain_mode.c static int jumbo_frm(struct stmmac_tx_queue *tx_q, struct sk_buff *skb, · line 40
Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/chain_mode.c +2
-2@@ -34,10 +34,10 @@ static int jumbo_frm(struct stmmac_tx_queue *tx_q, struct sk_buff *skb, buf_len = min_t(unsigned int, nopaged_len, bmax); len = nopaged_len - buf_len; - des2 =dma_map_single (priv->device, skb->data, + des2 =dma_map_single (priv->dma_device, skb->data, buf_len,DMA_TO_DEVICE ); desc->des2 =cpu_to_le32 (des2); -if (dma_mapping_error (priv->device, des2)) +if (dma_mapping_error (priv->dma_device, des2))
This isn't a bug introduced by this patch, but since the patch modifies these DMA mapping calls, it brings up a potential issue.
Does the use of an unsigned int for des2 break error detection?
On 64-bit architectures, dma_map_single() returns a 64-bit dma_addr_t. Assigning this to the unsigned int des2 truncates the upper 32 bits.
If the mapping fails, it returns an error code that becomes 0xFFFFFFFF after truncation. When this truncated value is passed to dma_mapping_error(), it is cast back to a 64-bit value, which no longer matches the expected error code representation.
Will this bypass the error check and record an invalid physical address in tx_q->tx_skbuff_dma[entry].buf? This same pattern also appears in the jumbo_frm() function in ring_mode.c.
[ ... ]
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0
-0
[ ... ]
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev) · line 4882
Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3
-3@@ -4876,9 +4876,9 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev) desc =stmmac_get_tx_desc (priv, tx_q, entry); - dma_addr =skb_frag_dma_map (priv->device, frag,0 , frag_size, -DMA_TO_DEVICE ); -if (dma_mapping_error (priv->device, dma_addr)) + dma_addr =skb_frag_dma_map (priv->dma_device, frag,0 , + frag_size,DMA_TO_DEVICE ); +if (dma_mapping_error (priv->dma_device, dma_addr)) goto dma_map_err;/* should reuse desc w/o issues */
Similarly, can this leak DMA mappings if an error occurs mid-packet?
If skb_frag_dma_map() fails for a multi-fragment packet, the code jumps to the dma_map_err label. However, tx_q->cur_tx is only updated at the very end of the function upon complete success.
Because cur_tx is not advanced on the error path, stmmac_tx_clean() won't unmap these partially filled descriptor entries. On the next transmission, the driver will start at the unmodified cur_tx index and blindly overwrite the tx_skbuff_dma entries.
Could this result in permanently leaking the previously successful DMA mappings? The same concern appears to apply to stmmac_tso_xmit() and jumbo_frm() where multiple fragments are mapped sequentially.
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [PATCH net-next 04/12] net: stmmac: dma: create a separate dma_device pointer
Quoted 33 lines · On 5/2/26 10:56 AM, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] DMA mappings are permanently leaked if an error occurs mid-packet instmmac_xmit,stmmac_tso_xmit, orjumbo_frm.
- [High] Injumbo_frm()(chain_mode.candring_mode.c), assigning adma_addr_tto anunsigned intbreaksdma_mapping_error()detection. --commit
152df859f4e94baeb0ca419c5b87bcb9e5f13d3d
Author: Alex Elder <[email protected]>net: stmmac: dma: create a separate
dma_devicepointerThis commit adds a second
dma_devicepointer to thestmmac_privstructure. The new pointer handles all DMA operations independently from the normal device pointer, allowing better management of common internal IPs for specialized Ethernet bridge chips.Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/chain_mode.c +0
-0drivers/net/ethernet/stmicro/stmmac/chain_mode.c static int jumbo_frm(struct stmmac_tx_queue *tx_q, struct sk_buff *skb, · line 40
Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/chain_mode.c +2
-2@@ -34,10 +34,10 @@ static int jumbo_frm(struct stmmac_tx_queue *tx_q, struct sk_buff *skb, buf_len = min_t(unsigned int, nopaged_len, bmax); len = nopaged_len - buf_len; - des2 =dma_map_single (priv->device, skb->data, + des2 =dma_map_single (priv->dma_device, skb->data, buf_len,DMA_TO_DEVICE ); desc->des2 =cpu_to_le32 (des2); -if (dma_mapping_error (priv->device, des2)) +if (dma_mapping_error (priv->dma_device, des2))This isn't a bug introduced by this patch, but since the patch modifies these DMA mapping calls, it brings up a potential issue.
Quoted 4 lines
Does the use of an unsigned int for des2 break error detection?
On 64-bit architectures,
dma_map_single()returns a 64-bitdma_addr_t. Assigning this to the unsigned int des2 truncates the upper 32 bits.
I think this is a legitimate report. I will follow up with a separate patch that will change the type of the variable holding the value returned by dma_map_single() to be dma_addr_t so it doesn't affect the validity of dma_mapping_error().
Quoted 19 lines
If the mapping fails, it returns an error code that becomes
0xFFFFFFFFafter truncation. When this truncated value is passed todma_mapping_error(), it is cast back to a 64-bit value, which no longer matches the expected error code representation.Will this bypass the error check and record an invalid physical address in tx_q->tx_skbuff_dma[entry].buf? This same pattern also appears in the
jumbo_frm()function inring_mode.c.[ ... ]
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0
-0[ ... ]
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0
-0@@ -4876,9 +4876,9 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev) desc =stmmac_get_tx_desc (priv, tx_q, entry);
Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev) · line 4882
Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3
-3- dma_addr =skb_frag_dma_map (priv->device, frag,0 , frag_size, -DMA_TO_DEVICE ); -if (dma_mapping_error (priv->device, dma_addr)) + dma_addr =skb_frag_dma_map (priv->dma_device, frag,0 , + frag_size,DMA_TO_DEVICE ); +if (dma_mapping_error (priv->dma_device, dma_addr)) goto dma_map_err;/* should reuse desc w/o issues */ Similarly, can this leak DMA mappings if an error occurs mid-packet?
It looks to me like it could. I don't know this code especially well, but if the loop iterates more than once, and skb_frag_dma_map() returns an error, it seems the mappings should be "unwound" at the dma_map_err label. I'll look at this as something to address in a separate patch too, but it's a little trickier than the first suggestion.
-Alex
Quoted 15 lines
If
skb_frag_dma_map()fails for a multi-fragment packet, the code jumps to thedma_map_errlabel. However,tx_q->cur_txis only updated at the very end of the function upon complete success.Because
cur_txis not advanced on the error path,stmmac_tx_clean()won't unmap these partially filled descriptor entries. On the next transmission, the driver will start at the unmodifiedcur_txindex and blindly overwrite thetx_skbuff_dmaentries.Could this result in permanently leaking the previously successful DMA mappings? The same concern appears to apply to
stmmac_tso_xmit()andjumbo_frm()where multiple fragments are mapped sequentially.[ ... ]
PATCH 5/12 net: stmmac: dwxgmac2: Add multi MSI interrupt mode
In reply to Alex ElderFrom: Daniel Thompson <[email protected]>
Currently there are no XGMAC platforms integrated using the multi MSI interrupt mode. In other words no existing driver sets both DWMAC_CORE_XGMAC and STMMAC_FLAG_MULTI_MSI_EN.
In order to support systems that do enable both options (such as the Toshiba TC9564 whose driver is currently being developed) we need to add logic to the XGMAC DMA callbacks. Happily we can simply replicate similar code from GMAC4. Let's do that!
--- drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h | 2 ++ drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c | 8 ++++++++ 2 files changed, 10 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h +2 -0
@@ -320,6 +320,8 @@/* DMA Registers */ #define XGMAC_DMA_MODE 0x00003000#define XGMAC_SWR BIT(0) +#define XGMAC_INTM_MASK GENMASK(13, 12) +#define XGMAC_INTM_MODE1 0x1#define XGMAC_DMA_SYSBUS_MODE 0x00003004#define XGMAC_WR_OSR_LMT GENMASK(29, 24)#define XGMAC_RD_OSR_LMT GENMASK(21, 16)
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c +8 -0
@@ -31,6 +31,14 @@ static void dwxgmac2_dma_init(void __iomem *ioaddr, value |=XGMAC_EAME ;writel (value, ioaddr +XGMAC_DMA_SYSBUS_MODE ); + + value =readl (ioaddr +XGMAC_DMA_MODE ); + +if (dma_cfg->multi_msi_en) + value =u32_replace_bits (value,XGMAC_INTM_MODE1 , +XGMAC_INTM_MASK ); + +writel (value, ioaddr +XGMAC_DMA_MODE ); } static void dwxgmac2_dma_init_chan(struct stmmac_priv *priv,
Signature · 1 line
2.51.0
Andrew Lunn
maintainerRe: [PATCH net-next 05/12] net: stmmac: dwxgmac2: Add multi MSI interrupt mode
Quoted 10 lines · Alex Elder
From: Daniel Thompson <[email protected]>
Currently there are no XGMAC platforms integrated using the multi MSI interrupt mode. In other words no existing driver sets both
DWMAC_CORE_XGMACandSTMMAC_FLAG_MULTI_MSI_EN.In order to support systems that do enable both options (such as the Toshiba TC9564 whose driver is currently being developed) we need to add logic to the XGMAC DMA callbacks. Happily we can simply replicate similar code from GMAC4. Let's do that!
The word replicate made me think it has been cut/paste, rather than being refactored into a helper. However,
Quoted 1 line
+#define
XGMAC_INTM_MASKGENMASK(13, 12)
#define DMA_BUS_MODE_INTM_MASK GENMASK(17, 16)
Different bits in the register, so the code structure is the same, but the code cannot be shared in a meaningful way. So this is O.K.
Andrew
PATCH 6/12 net: stmmac: dwxgmac2: Add XGMAC 3.01a support
In reply to Alex ElderFrom: 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
@@ -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)
@@ -463,6 +465,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.51.0
PATCH 7/12 net: stmmac: dwxgmac2: export symbols for XGMAC 3.01a DMA
In reply to Alex ElderFrom: Daniel Thompson <[email protected]>
Toshiba TC956x 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 TC956x 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 TC956x 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
@@ -468,4 +468,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
@@ -1556,6 +1556,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
@@ -368,3 +368,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
@@ -62,10 +62,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;
@@ -77,11 +77,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;
@@ -93,6 +93,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) {
@@ -671,3 +672,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.51.0
[email protected]
AI reviewRe: [PATCH net-next 07/12] net: stmmac: dwxgmac2: export symbols for XGMAC 3.01a DMA
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Bypassing standard DMA address translation via custom op-table overrides. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Bypassing standard DMA address translation via custom op-table overrides. --
commit 6c8a6ba67e29de7e71f5090bcca63c458ee9639d
Author: Daniel Thompson <[email protected]>
net: stmmac: dwxgmac2: export symbols for XGMAC 3.01a DMA
This patch exports several DMA operations and descriptor tables from the dwxgmac2 core to allow platform-specific code to override them. This override allows the platform code to perform manual DMA address translations required by the chip's internal AXI bus mappings.
Quoted 9 lines
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 TC956x 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.
This isn't a bug, but does this approach bypass the standard Linux DMA API?
The standard DMA API natively handles device-specific address offsets, such as through dma_range_map on the struct device.
Could this address translation be handled using the standard DMA abstractions instead of open-coding it via op-table overrides and exporting these internal symbols?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Re: [PATCH net-next 07/12] net: stmmac: dwxgmac2: export symbols for XGMAC 3.01a DMA
Quoted 24 lines · On 5/2/26 10:56 AM, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Bypassing standard DMA address translation via custom op-table overrides. --commit
6c8a6ba67e29de7e71f5090bcca63c458ee9639d
Author: Daniel Thompson <[email protected]>net: stmmac: dwxgmac2: export symbols for XGMAC 3.01a DMA
This patch exports several DMA operations and descriptor tables from the dwxgmac2 core to allow platform-specific code to override them. This override allows the platform code to perform manual DMA address translations required by the chip's internal AXI bus mappings.
Quoted 9 lines
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 TC956x 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.
Quoted 8 lines
This isn't a bug, but does this approach bypass the standard Linux DMA API?
The standard DMA API natively handles device-specific address offsets, such as through
dma_range_mapon the struct device.Could this address translation be handled using the standard DMA abstractions instead of open-coding it via op-table overrides and exporting these internal symbols?
I'm answering this on Daniel's behalf. He tried setting up the DMA range mapping but it did not have the desired effect. He suspects that the involvement of an IOMMU affects what the range map can do for peripherals.
Guidance on how to do this better is welcome.
-Alex
PATCH 8/12 dt-bindings: net: toshiba,tc965x-dwmac: add TC956x Ethernet bridge
In reply to Alex ElderFrom: Daniel Thompson <[email protected]>
Add devicetree bindings for the Toshiba TC956x family of Ethernet-AVB/TSN bridges.
--- .../bindings/net/toshiba,tc956x-dwmac.yaml | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +111 -0
@@ -0,0 +1,111 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/toshiba,tc956x-dwmac.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Toshiba TC956x Ethernet-AVB/TSN Controller + +maintainers: + - Alex Elder <[email protected]> + - Daniel Thompson <[email protected]> + +description: | + This node provides properties for configuring the Ethernet PCI functions + that are attached to the internal downstream port of the TC956x's PCIe + switch. + + TC956x are a family of Ethernet-AVB/TSN bridge chips that combine a PCIe + switch together with a number of Ethernet controllers. These bindings + cover only the Ethernet functions of these devices. + +allOf: + - $ref: /schemas/pci/pci-bus-common.yaml# + - $ref: /schemas/pci/pci-device.yaml# + +unevaluatedProperties: false + +properties: + compatible: + enum: + - pci1179,0220 # Toshiba TC9564 (a.k.a. Qualcomm QPS615) + + "#gpio-cells": + const: 2 + + gpio-controller: true + + # We can't allOf reference Ethernet-controller.yaml because we end up with + # contradictory $nodename rules (`ethernet@` versus `pci@`). Happily only a + # small number of the properties are useful on TC956x so we can just reference + # what we need. + phy-connection-type: + $ref: ethernet-controller.yaml#/properties/phy-connection-type + + phy-handle: + $ref: ethernet-controller.yaml#/properties/phy-handle + + phy-mode: + $ref: ethernet-controller.yaml#/properties/phy-mode + + mdio: + $ref: snps,dwmac.yaml#/properties/mdio + +required: + - compatible + - reg + +examples: + - | + pcie { + #address-cells = <3>; + #size-cells = <2>; + + tc956x_emac0: pci@0,0 { + compatible = "pci1179,0220"; + reg = <0x50000 0x0 0x0 0x0 0x0>; + #address-cells = <3>; + #size-cells = <2>; + device_type = "pci"; + ranges; + + gpio-controller; + #gpio-cells = <2>; + + phy-mode = "10gbase-r"; + phy-handle = <&tc956x_emac0_phy>; + + mdio { + compatible = "snps,dwmac-mdio"; + #address-cells = <1>; + #size-cells = <0>; + + tc956x_emac0_phy: ethernet-phy@1c { + compatible = "ethernet-phy-id311c.1c12"; + reg = <0x1c>; + }; + }; + }; + pci@0,1 { + compatible = "pci1179,0220"; + reg = <0x50100 0x0 0x0 0x0 0x0>; + #address-cells = <3>; + #size-cells = <2>; + device_type = "pci"; + ranges; + + phy-mode = "sgmii"; + phy-handle = <&tc956x_emac1_phy>; + + mdio { + compatible = "snps,dwmac-mdio"; + #address-cells = <1>; + #size-cells = <0>; + + tc956x_emac1_phy: ethernet-phy@1c { + compatible = "ethernet-phy-id004d.d101"; + reg = <0x1c>; + }; + }; + }; + };
Signature · 1 line
2.51.0
Andrew Lunn
maintainerRe: [PATCH net-next 08/12] dt-bindings: net: toshiba,tc965x-dwmac: add TC956x Ethernet bridge
Your ASCII art of the chip might be useful here as documentation.
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml line 41
Quoted 4 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +4
-0+ # We can't allOf reference Ethernet-controller.yaml because we end up with + # contradictory $nodename rules (`ethernet@` versus `pci@`). Happily only a + # small number of the properties are useful on TC956x so we can just reference + # what we need.
Why not add an subnodes for the ethernet interfaces?
Quoted 6 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +6
-0+examples: + - | + pcie { + #address-cells = <3>; + #size-cells = <2>; +
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml line 73
Quoted 10 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +10
-0+ tc956x_emac0: pci@0,0 { + compatible = "pci1179,0220"; + reg = <0x50000 0x0 0x0 0x0 0x0>; + #address-cells = <3>; + #size-cells = <2>; + device_type = "pci"; + ranges; + + gpio-controller; + #gpio-cells = <2>;
I've not got to the GPIO driver patch yet...
Is the GPIO part of the ethernet device, or part of the chip? The hierarchy here should match the hierarchy of the hardware.
Quoted 12 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +12
-0+ phy-mode = "10gbase-r"; + phy-handle = <&tc956x_emac0_phy>; + + mdio { + compatible = "snps,dwmac-mdio"; + #address-cells = <1>; + #size-cells = <0>; + + tc956x_emac0_phy: ethernet-phy@1c { + compatible = "ethernet-phy-id311c.1c12"; + reg = <0x1c>; + };
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml line 96
Quoted 10 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +10
-0+ }; + }; + pci@0,1 { + compatible = "pci1179,0220"; + reg = <0x50100 0x0 0x0 0x0 0x0>; + #address-cells = <3>; + #size-cells = <2>; + device_type = "pci"; + ranges; +
You second ethernet does not have a gpio controller?
Andrew
Re: [PATCH net-next 08/12] dt-bindings: net: toshiba,tc965x-dwmac: add TC956x Ethernet bridge
Quoted 8 lines · Andrew Lunn
Your ASCII art of the chip might be useful here as documentation.
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml line 41
Quoted 4 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +4
-0+ # We can't allOf reference Ethernet-controller.yaml because we end up with + # contradictory $nodename rules (`ethernet@` versus `pci@`). Happily only a + # small number of the properties are useful on TC956x so we can just reference + # what we need.Why not add an subnodes for the ethernet interfaces?
I'm going to wait to respond to this until I've had a chance to discuss it with Daniel. (It might be Tuesday.)
Quoted 20 lines
Quoted 7 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +6
-0+examples: + - | + pcie { + #address-cells = <3>; + #size-cells = <2>; +Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml line 73
Quoted 10 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +10
-0+ tc956x_emac0: pci@0,0 { + compatible = "pci1179,0220"; + reg = <0x50000 0x0 0x0 0x0 0x0>; + #address-cells = <3>; + #size-cells = <2>; + device_type = "pci"; + ranges; + + gpio-controller; + #gpio-cells = <2>;I've not got to the GPIO driver patch yet...
Quoted 2 lines
Is the GPIO part of the ethernet device, or part of the chip? The hierarchy here should match the hierarchy of the hardware.
The GPIO is part of the TC9564 chip, and is a separate IP within it. Within this chip there is one GPIO controller (as well as a UART and so on), independent of the eMACs.
Quoted 16 lines
Quoted 16 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +16
-0+ phy-mode = "10gbase-r"; + phy-handle = <&tc956x_emac0_phy>; + + mdio { + compatible = "snps,dwmac-mdio"; + #address-cells = <1>; + #size-cells = <0>; + + tc956x_emac0_phy: ethernet-phy@1c { + compatible = "ethernet-phy-id311c.1c12"; + reg = <0x1c>; + }; + }; + }; + pci@0,1 { + compatible = "pci1179,0220";
Quoted 8 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml line 96
Quoted 6 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +6
-0+ reg = <0x50100 0x0 0x0 0x0 0x0>; + #address-cells = <3>; + #size-cells = <2>; + device_type = "pci"; + ranges; +You second ethernet does not have a gpio controller?
Basically, no. We made the decision to create a "chip" abstraction that is responsible for managing these other shared IP blocks (of which only the GPIO controller has a separate driver).
Both of the PCIe endpoints are able to manipulate the registers for the GPIO, but we made it the responsibility of function 0--not function 1--to handle that.
It's possible that some platforms won't use the built-in GPIO controller to manage PHY resets. So we used this property to signal that it was required.
So *if* the gpio-controller (and #gpio-cells) property is present, then function 0 creates an auxiliary device for the GPIO controller. Otherwise something else supplies the GPIO lines managing PHY resets.
-Alex
Quoted 2 lines
Andrew
Re: [PATCH net-next 08/12] dt-bindings: net: toshiba,tc965x-dwmac: add TC956x Ethernet bridge
In reply to Andrew LunnQuoted 1 line · Andrew Lunn
Why not add an subnodes for the ethernet interfaces?
We will define "ethernet" devicetree subnodes of the PCIe functions in the next version of the series. Something like what's below.
-Alex
pci@0,1 {
compatible = "pci1179,0220";
reg = <0x50100 0x0 0x0 0x0 0x0>;
#address-cells = <3>;
#size-cells = <2>;
device_type = "pci";
ranges;
ethernet {
phy-mode = "sgmii";
phy-handle = <&tc956x_emac1_phy>;
mdio {
compatible = "snps,dwmac-mdio";
#address-cells = <1>;
#size-cells = <0>;
tc956x_emac1_phy: ethernet-phy@1c {
compatible = "ethernet-phy-id004d.d101";
...
};
};
};
};Rob Herring
maintainerRe: [PATCH net-next 08/12] dt-bindings: net: toshiba,tc965x-dwmac: add TC956x Ethernet bridge
Quoted 6 lines · Alex Elder
Quoted 1 line · Andrew Lunn
Why not add an subnodes for the ethernet interfaces?
We will define "ethernet" devicetree subnodes of the PCIe functions in the next version of the series. Something like what's below.
Are they PCIe functions? As in bus, dev, function addresses. How to do functions is already defined by the PCI binding.
Quoted 3 lines
-Alex
pci@0,1 {
The 0 here is devnum and the 1 is function.
Quoted 23 lines
compatible = "pci1179,0220";
reg = <0x50100 0x0 0x0 0x0 0x0>;
#address-cells = <3>;
#size-cells = <2>;
device_type = "pci";
ranges;
ethernet {
phy-mode = "sgmii";
phy-handle = <&tc956x_emac1_phy>;
mdio {
compatible = "snps,dwmac-mdio";
#address-cells = <1>;
#size-cells = <0>;
tc956x_emac1_phy: ethernet-phy@1c {
compatible = "ethernet-phy-id004d.d101";
...
};
};
};
};[email protected]
AI reviewRe: [PATCH net-next 08/12] dt-bindings: net: toshiba,tc965x-dwmac: add TC956x Ethernet bridge
In reply to Alex ElderThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] The binding adds GPIO provider capabilities but omits `gpio-controller` and `#gpio-cells` from…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The binding adds GPIO provider capabilities but omits gpio-controller and #gpio-cells from the required list.
- [Medium] The Ethernet endpoint is incorrectly modeled as a PCI bridge, applying bus properties to an endpoint. --
commit c5a5d0d7a89f5ad66c878c805902efc5e0bd117a
Author: Daniel Thompson <[email protected]>
dt-bindings: net: toshiba,tc965x-dwmac: add TC956x Ethernet bridge
This commit adds devicetree bindings for the Toshiba TC956x family of Ethernet-AVB/TSN bridges.
Quoted 6 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +0
-0@@ -0,0 +1,111 @@
[ ... ]
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml line 23
Quoted 2 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +2
-0+allOf: + - $ref: /schemas/pci/pci-bus-common.yaml#
Is it correct to reference pci-bus-common.yaml# here? Since the tc956x_emac0 node is a PCI endpoint (an Ethernet controller attached to an internal PCIe switch) rather than a PCI bus or bridge, applying bridge-specific properties could be semantically invalid.
Quoted 13 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +13
-0+ - $ref: /schemas/pci/pci-device.yaml# + +unevaluatedProperties: false + +properties: + compatible: + enum: + - pci1179,0220 # Toshiba TC9564 (a.k.a. Qualcomm QPS615) + + "#gpio-cells": + const: 2 + + gpio-controller: true
[ ... ]
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml line 56
Quoted 3 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +3
-0+required: + - compatible + - reg
Should gpio-controller and #gpio-cells be explicitly included in this required list?
The binding defines gpio-controller and #gpio-cells above, indicating the hardware acts as a GPIO provider. Omitting them from the required list could allow incomplete device tree nodes to silently pass schema validation.
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml line 70
Quoted 13 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +13
-0+examples: + - | + pcie { + #address-cells = <3>; + #size-cells = <2>; + + tc956x_emac0: pci@0,0 { + compatible = "pci1179,0220"; + reg = <0x50000 0x0 0x0 0x0 0x0>; + #address-cells = <3>; + #size-cells = <2>; + device_type = "pci"; + ranges;
Does this endpoint node need bridge properties like device_type = "pci", #address-cells = <3>, #size-cells = <2>, and ranges?
The child of this node is an mdio bus, which does not use PCI addresses and does not require PCI bridge translation. Using device_type = "pci" on an endpoint might confuse OS PCI enumeration logic, which expects nodes with this device_type to be actual PCI-to-PCI bridges.
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
Rob Herring
maintainerRe: [PATCH net-next 08/12] dt-bindings: net: toshiba,tc965x-dwmac: add TC956x Ethernet bridge
Quoted 4 lines · On Sat, May 02, 2026 at 03:56:15PM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The binding adds GPIO provider capabilities but omitsgpio-controllerand#gpio-cellsfrom therequiredlist.
- [Medium] The Ethernet endpoint is incorrectly modeled as a PCI bridge, applying bus properties to an endpoint. --
Please answer sashiko reports because if maintainers are, it's just more work for us. While agreeing with maintainer comments don't need a reply, I think we're still at the point any AI review does. Though sashiko is 2/2 here.
Quoted 18 lines
commit
c5a5d0d7a89f5ad66c878c805902efc5e0bd117a
Author: Daniel Thompson <[email protected]>dt-bindings: net: toshiba,tc965x-dwmac: add TC956x Ethernet bridge
This commit adds devicetree bindings for the Toshiba TC956x family of Ethernet-AVB/TSN bridges.
Quoted 6 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +0
-0@@ -0,0 +1,111 @@[ ... ]
Quoted 7 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml line 23
Quoted 2 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +2
-0+allOf: + - $ref: /schemas/pci/pci-bus-common.yaml#Is it correct to reference pci-bus-common.yaml# here? Since the
tc956x_emac0node is a PCI endpoint (an Ethernet controller attached to an internal PCIe switch) rather than a PCI bus or bridge, applying bridge-specific properties could be semantically invalid.
Correct, should be dropped.
Quoted 28 lines
Quoted 14 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +13
-0+ - $ref: /schemas/pci/pci-device.yaml# + +unevaluatedProperties: false + +properties: + compatible: + enum: + - pci1179,0220 # Toshiba TC9564 (a.k.a. Qualcomm QPS615) + + "#gpio-cells": + const: 2 + + gpio-controller: true[ ... ]
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml line 56
Quoted 3 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +3
-0+required: + - compatible + - regShould gpio-controller and #gpio-cells be explicitly included in this required list?
The binding defines gpio-controller and #gpio-cells above, indicating the hardware acts as a GPIO provider. Omitting them from the required list could allow incomplete device tree nodes to silently pass schema validation.
Quoted 16 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml line 70
Quoted 13 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +13
-0+examples: + - | + pcie { + #address-cells = <3>; + #size-cells = <2>; + + tc956x_emac0: pci@0,0 { + compatible = "pci1179,0220"; + reg = <0x50000 0x0 0x0 0x0 0x0>; + #address-cells = <3>; + #size-cells = <2>; + device_type = "pci"; + ranges;Does this endpoint node need bridge properties like
device_type= "pci", #address-cells = <3>, #size-cells = <2>, and ranges?
No, it doesn't.
Quoted 4 lines
The child of this node is an mdio bus, which does not use PCI addresses and does not require PCI bridge translation. Using
device_type= "pci" on an endpoint might confuse OS PCI enumeration logic, which expects nodes with thisdevice_typeto be actual PCI-to-PCI bridges.
Re: [PATCH net-next 08/12] dt-bindings: net: toshiba,tc965x-dwmac: add TC956x Ethernet bridge
Quoted 4 lines · Rob Herring
Please answer sashiko reports because if maintainers are, it's just more work for us. While agreeing with maintainer comments don't need a reply, I think we're still at the point any AI review does. Though sashiko is 2/2 here.
I plan to. I've been responding to maintainer/reviewer things first, but I fully intend to treat sashiko as a "proper reviewer" and will respond to those as well.
-Alex
Re: [PATCH net-next 08/12] dt-bindings: net: toshiba,tc965x-dwmac: add TC956x Ethernet bridge
In reply to [email protected]Quoted 22 lines · On 5/2/26 10:56 AM, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The binding adds GPIO provider capabilities but omitsgpio-controllerand#gpio-cellsfrom therequiredlist.
- [Medium] The Ethernet endpoint is incorrectly modeled as a PCI bridge, applying bus properties to an endpoint. --commit
c5a5d0d7a89f5ad66c878c805902efc5e0bd117a
Author: Daniel Thompson <[email protected]>dt-bindings: net: toshiba,tc965x-dwmac: add TC956x Ethernet bridge
This commit adds devicetree bindings for the Toshiba TC956x family of Ethernet-AVB/TSN bridges.
Quoted 6 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +0
-0@@ -0,0 +1,111 @@[ ... ]
Quoted 7 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml line 23
Quoted 2 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +2
-0+allOf: + - $ref: /schemas/pci/pci-bus-common.yaml#Is it correct to reference pci-bus-common.yaml# here? Since the
tc956x_emac0node is a PCI endpoint (an Ethernet controller attached to an internal PCIe switch) rather than a PCI bus or bridge, applying bridge-specific properties could be semantically invalid.
As Rob pointed reinforced, this is not correct. It will not be present in the next version of this patch.
Quoted 21 lines
Quoted 14 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +13
-0+ - $ref: /schemas/pci/pci-device.yaml# + +unevaluatedProperties: false + +properties: + compatible: + enum: + - pci1179,0220 # Toshiba TC9564 (a.k.a. Qualcomm QPS615) + + "#gpio-cells": + const: 2 + + gpio-controller: true[ ... ]
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml line 56
Quoted 3 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +3
-0+required: + - compatible + - reg
Quoted 6 lines
Should gpio-controller and #gpio-cells be explicitly included in this required list?
The binding defines gpio-controller and #gpio-cells above, indicating the hardware acts as a GPIO provider. Omitting them from the required list could allow incomplete device tree nodes to silently pass schema validation.
The GPIO controller was meant to be implemented only by PCIe function 0 (only--not function 1). It was furthermore intended to be optional (depending on whether the platform used these GPIOs for something, like reset control).
However we plan to change how the GPIO controller is modeled after version 2 of the series, and I don't want to try to explain how things will look until that work is done.
Quoted 8 lines
Quoted 8 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +8
-0+examples: + - | + pcie { + #address-cells = <3>; + #size-cells = <2>; + + tc956x_emac0: pci@0,0 { + compatible = "pci1179,0220";
Quoted 8 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml line 70
Quoted 5 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +5
-0+ reg = <0x50000 0x0 0x0 0x0 0x0>; + #address-cells = <3>; + #size-cells = <2>; + device_type = "pci"; + ranges;Does this endpoint node need bridge properties like
device_type= "pci", #address-cells = <3>, #size-cells = <2>, and ranges?
No, it doesn't. Using the PCI bridge binding definitions was a mistake. We'll try to improve this in version 2 of the series but again, revising how we model the chip will have an affect on how the binding looks.
-Alex
Quoted 7 lines
The child of this node is an mdio bus, which does not use PCI addresses and does not require PCI bridge translation. Using
device_type= "pci" on an endpoint might confuse OS PCI enumeration logic, which expects nodes with thisdevice_typeto be actual PCI-to-PCI bridges.[ ... ]
Re: [PATCH net-next 08/12] dt-bindings: net: toshiba,tc965x-dwmac: add TC956x Ethernet bridge
In reply to Alex ElderQuoted 18 lines · Alex Elder
From: Daniel Thompson <[email protected]>
Add devicetree bindings for the Toshiba TC956x family of Ethernet-AVB/TSN bridges.
Signed-off-by Daniel Thompson <[email protected]>Signed-off-by Alex Elder <[email protected]>--- .../bindings/net/toshiba,tc956x-dwmac.yaml | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yamlDocumentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +0
-0
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml line 4
Quoted 4 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +4
-0@@ -0,0 +1,111 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/toshiba,tc956x-dwmac.yaml#
Filename and here: toshiba,tc9564-dwmac
(s/x/4/)
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml line 16
Quoted 12 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +12
-0+$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Toshiba TC956x Ethernet-AVB/TSN Controller + +maintainers: + - Alex Elder <[email protected]> + - Daniel Thompson <[email protected]> + +description: | + This node provides properties for configuring the Ethernet PCI functions + that are attached to the internal downstream port of the TC956x's PCIe + switch.
Describe rather the hardware directly, not the DTS or the binding itself.
Just say what is the hardware, what is consists of, what is less obvious or usual (if there is such).
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml line 20
Quoted 4 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +4
-0+ + TC956x are a family of Ethernet-AVB/TSN bridge chips that combine a PCIe + switch together with a number of Ethernet controllers. These bindings + cover only the Ethernet functions of these devices.
What about the rest of the hardware - a PCIe switch? Shouldn't it be described?
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml line 26
Quoted 6 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +6
-0+ +allOf: + - $ref: /schemas/pci/pci-bus-common.yaml# + - $ref: /schemas/pci/pci-device.yaml# + +unevaluatedProperties: false
Place both (allOf+unevaluatedProperties) after "required:".
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml line 38
Quoted 12 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +12
-0+ +properties: + compatible: + enum: + - pci1179,0220 # Toshiba TC9564 (a.k.a. Qualcomm QPS615) + + "#gpio-cells": + const: 2 + + gpio-controller: true + + # We can't allOf reference Ethernet-controller.yaml because we end up with
s/Ethernet-controller.yaml/ethernet-controller.yaml/
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml line 39
Quoted 1 line
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +1
-0+ # contradictory $nodename rules (`ethernet@` versus `pci@`). Happily only a
But which schema requires pci@ for devices? If I am not mistaken, only dtschema/schemas/pci/pci-bus-common.yaml requires it, and it does not apply to actual PCI device.
Quoted 39 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +39
-0+ # small number of the properties are useful on TC956x so we can just reference + # what we need. + phy-connection-type: + $ref: ethernet-controller.yaml#/properties/phy-connection-type + + phy-handle: + $ref: ethernet-controller.yaml#/properties/phy-handle + + phy-mode: + $ref: ethernet-controller.yaml#/properties/phy-mode + + mdio: + $ref: snps,dwmac.yaml#/properties/mdio + +required: + - compatible + - reg + +examples: + - | + pcie { + #address-cells = <3>; + #size-cells = <2>; + + tc956x_emac0: pci@0,0 { + compatible = "pci1179,0220"; + reg = <0x50000 0x0 0x0 0x0 0x0>; + #address-cells = <3>; + #size-cells = <2>; + device_type = "pci"; + ranges; + + gpio-controller; + #gpio-cells = <2>; + + phy-mode = "10gbase-r"; + phy-handle = <&tc956x_emac0_phy>; + + mdio {
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml line 88
Quoted 10 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +10
-0+ compatible = "snps,dwmac-mdio"; + #address-cells = <1>; + #size-cells = <0>; + + tc956x_emac0_phy: ethernet-phy@1c { + compatible = "ethernet-phy-id311c.1c12"; + reg = <0x1c>; + }; + }; + };
Keep only one example, unless you have different properties (not their values, but their presence),
Best regards,
Krzysztof
Re: [PATCH net-next 08/12] dt-bindings: net: toshiba,tc965x-dwmac: add TC956x Ethernet bridge
Quoted 44 lines · Krzysztof Kozlowski
Quoted 18 lines · Alex Elder
From: Daniel Thompson <[email protected]>
Add devicetree bindings for the Toshiba TC956x family of Ethernet-AVB/TSN bridges.
Signed-off-by Daniel Thompson <[email protected]>Signed-off-by Alex Elder <[email protected]>--- .../bindings/net/toshiba,tc956x-dwmac.yaml | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+)create mode 100644
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yamlDocumentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +0
-0Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml line 4
Quoted 4 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +4
-0@@ -0,0 +1,111 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/toshiba,tc956x-dwmac.yaml#Filename and here: toshiba,tc9564-dwmac
(s/x/4/)Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml line 16
Quoted 12 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +12
-0+$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Toshiba TC956x Ethernet-AVB/TSN Controller + +maintainers: + - Alex Elder <[email protected]> + - Daniel Thompson <[email protected]> + +description: | + This node provides properties for configuring the Ethernet PCI functions + that are attached to the internal downstream port of the TC956x's PCIe + switch.Describe rather the hardware directly, not the DTS or the binding itself.
Quoted 2 lines
Just say what is the hardware, what is consists of, what is less obvious or usual (if there is such).
I understand what you're saying. We will reword this to focus on the hardware in version 2.
Quoted 8 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml line 20
Quoted 5 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +4
-0+ + TC956x are a family of Ethernet-AVB/TSN bridge chips that combine a PCIe + switch together with a number of Ethernet controllers. These bindings + cover only the Ethernet functions of these devices.What about the rest of the hardware - a PCIe switch? Shouldn't it be described?
It maybe should, just to provide a more complete picture. It's a little strange, because the PCIe switch support (or at least its power controller) was already upstreamed:
https://lore.kernel.org/all/[email protected]/
That introduced DeviceTree bindings for a PCI device, which is itself sort of spanning two worlds of discoverability.
That code focused on the *switch*. This series is focused on the *Ethernet interfaces*. But the "chip" has several other components, some of which (GPIO anyway, for now) also need to be modeled.
I want to talk more with Daniel about this but either way we will revisit this and will attempt to describe the hardware in a more complete way when we send out v2.
Quoted 8 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml line 26
Quoted 6 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +6
-0+ +allOf: + - $ref: /schemas/pci/pci-bus-common.yaml# + - $ref: /schemas/pci/pci-device.yaml# + +unevaluatedProperties: falsePlace both (allOf+unevaluatedProperties) after "required:".
OK.
Quoted 15 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml line 38
Quoted 13 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +12
-0+ +properties: + compatible: + enum: + - pci1179,0220 # Toshiba TC9564 (a.k.a. Qualcomm QPS615) + + "#gpio-cells": + const: 2 + + gpio-controller: true + + # We can't allOf reference Ethernet-controller.yaml because we end up withs/Ethernet-controller.yaml/ethernet-controller.yaml/
OK.
Quoted 6 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml line 39
Quoted 2 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +1
-0+ # contradictory $nodename rules (`ethernet@` versus `pci@`). Happily only aBut which schema requires pci@ for devices? If I am not mistaken, only
dtschema/schemas/pci/pci-bus-common.yamlrequires it, and it does not apply to actual PCI device.
We'll revisit this and will simplify/clarify if possible in v2.
Quoted 44 lines
Quoted 44 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +44
-0+ # small number of the properties are useful on TC956x so we can just reference + # what we need. + phy-connection-type: + $ref: ethernet-controller.yaml#/properties/phy-connection-type + + phy-handle: + $ref: ethernet-controller.yaml#/properties/phy-handle + + phy-mode: + $ref: ethernet-controller.yaml#/properties/phy-mode + + mdio: + $ref: snps,dwmac.yaml#/properties/mdio + +required: + - compatible + - reg + +examples: + - | + pcie { + #address-cells = <3>; + #size-cells = <2>; + + tc956x_emac0: pci@0,0 { + compatible = "pci1179,0220"; + reg = <0x50000 0x0 0x0 0x0 0x0>; + #address-cells = <3>; + #size-cells = <2>; + device_type = "pci"; + ranges; + + gpio-controller; + #gpio-cells = <2>; + + phy-mode = "10gbase-r"; + phy-handle = <&tc956x_emac0_phy>; + + mdio { + compatible = "snps,dwmac-mdio"; + #address-cells = <1>; + #size-cells = <0>; + + tc956x_emac0_phy: ethernet-phy@1c {
Quoted 8 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml line 88
Quoted 5 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +5
-0+ compatible = "ethernet-phy-id311c.1c12"; + reg = <0x1c>; + }; + }; + };Keep only one example, unless you have different properties (not their values, but their presence),
OK. Thanks a lot for your review Krzysztof.
-Alex
Quoted 5 lines
Best regards,
Krzysztof
Re: [PATCH net-next 08/12] dt-bindings: net: toshiba,tc965x-dwmac: add TC956x Ethernet bridge
In reply to Krzysztof KozlowskiQuoted 8 lines · Krzysztof Kozlowski
Quoted 7 lines · Alex Elder
From: Daniel Thompson <[email protected]>
Add devicetree bindings for the Toshiba TC956x family of Ethernet-AVB/TSN bridges.
Signed-off-by Daniel Thompson <[email protected]>Signed-off-by Alex Elder <[email protected]>
Alex already replied to most of your comments but on this one specifically...
Quoted 38 lines
Quoted 38 lines
--- .../bindings/net/toshiba,tc956x-dwmac.yaml | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yamlDocumentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +26
-0@@ -0,0 +1,111 @@ +examples: + - | + pcie { + #address-cells = <3>; + #size-cells = <2>; + + tc956x_emac0: pci@0,0 { + compatible = "pci1179,0220"; + reg = <0x50000 0x0 0x0 0x0 0x0>; + #address-cells = <3>; + #size-cells = <2>; + device_type = "pci"; + ranges; + + gpio-controller; + #gpio-cells = <2>; + + phy-mode = "10gbase-r"; + phy-handle = <&tc956x_emac0_phy>; + + mdio { + compatible = "snps,dwmac-mdio"; + #address-cells = <1>; + #size-cells = <0>; + + tc956x_emac0_phy: ethernet-phy@1c {
Quoted 8 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml line 88
Quoted 5 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +5
-0+ compatible = "ethernet-phy-id311c.1c12"; + reg = <0x1c>; + }; + }; + };Keep only one example, unless you have different properties (not their values, but their presence),
At some point I simplified the example by stripping out excess properties from each ethernet-phy. In the process it looks like I removed too much and eliminated reason I thought it important to include both PCI functions in the example!
Each ethernet-phy will typically describe a reset gpio but we expect only eMAC0 to act as a gpio-controller. For that reason I wanted to show that. You can see part of that that in the current example because tc956x_emac1 is not a gpio-controller.
In other words tc956x_emac**1**_phy will, in the real world, include a reset-gpios property that references tc956x_emac**0**. For example:
reset-gpios = <&tc956x_emac0 1 GPIO_ACTIVE_LOW>
So... is it better to strip it back the example to describe only a single PCI function or should I add back the reset-gpios that I accidentally removed?
Daniel.
Bjorn Andersson
maintainerRe: [PATCH net-next 08/12] dt-bindings: net: toshiba,tc965x-dwmac: add TC956x Ethernet bridge
In reply to Alex ElderQuoted 1 line · Alex Elder
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml +0
-0
[..]
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml
Quoted 2 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml +2
-0+ + gpio-controller: true
I don't have any concern with the use of a proper gpio driver to model the implementation, but if I understand correctly this relationship between gpio controller and gpio consumer is strictly internal to "the PCI device".
Is this connection variable or is the link merely expressed in DeviceTree to mitigate the fact that you choose to implement the responsibilities of the two parts split into two device drivers?
Are there other consumers of these TC956x gpios which would result in a board designer (and hence dts author) to ever reference this gpio-controller in a different way?
Regards,
Bjorn
Andrew Lunn
maintainerRe: [PATCH net-next 08/12] dt-bindings: net: toshiba,tc965x-dwmac: add TC956x Ethernet bridge
Quoted 3 lines
Are there other consumers of these TC956x gpios which would result in a board designer (and hence dts author) to ever reference this gpio-controller in a different way?
This Ethernet device could driver an SFP cage. Such cages typically have a number of pins connect to GPIOs, so you can tell when there is a module in the cage, enable the transmit laser, know if light is entering the module from the link peer, etc.
sfp2: sfp {
compatible = "sff,sfp";
i2c-bus = <&sfp_i2c>;
los-gpios = <&cps_gpio1 28 GPIO_ACTIVE_HIGH>;
mod-def0-gpios = <&cps_gpio1 27 GPIO_ACTIVE_LOW>;
pinctrl-names = "default";
pinctrl-0 = <&cps_sfpp0_pins>;
tx-disable-gpios = <&cps_gpio1 29 GPIO_ACTIVE_HIGH>;
tx-fault-gpios = <&cps_gpio1 26 GPIO_ACTIVE_HIGH>;
};
AndrewBjorn Andersson
maintainerRe: [PATCH net-next 08/12] dt-bindings: net: toshiba,tc965x-dwmac: add TC956x Ethernet bridge
Quoted 9 lines · Andrew Lunn
Quoted 3 lines
Are there other consumers of these TC956x gpios which would result in a board designer (and hence dts author) to ever reference this gpio-controller in a different way?
This Ethernet device could driver an SFP cage. Such cages typically have a number of pins connect to GPIOs, so you can tell when there is a module in the cage, enable the transmit laser, know if light is entering the module from the link peer, etc.
Okay, so the consumer of the gpio is actually an external component, and not just another part of the TC956x?
Then this seems reasonable.
Thank you,
Bjorn
Quoted 12 lines
sfp2: sfp {
compatible = "sff,sfp";
i2c-bus = <&sfp_i2c>;
los-gpios = <&cps_gpio1 28 GPIO_ACTIVE_HIGH>;
mod-def0-gpios = <&cps_gpio1 27 GPIO_ACTIVE_LOW>;
pinctrl-names = "default";
pinctrl-0 = <&cps_sfpp0_pins>;
tx-disable-gpios = <&cps_gpio1 29 GPIO_ACTIVE_HIGH>;
tx-fault-gpios = <&cps_gpio1 26 GPIO_ACTIVE_HIGH>;
};
AndrewRe: [PATCH net-next 08/12] dt-bindings: net: toshiba,tc965x-dwmac: add TC956x Ethernet bridge
In reply to Bjorn AnderssonQuoted 10 lines · Bjorn Andersson
Quoted 1 line · Alex Elder
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml +0
-0[..]
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml
Quoted 2 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml +2
-0+ + gpio-controller: trueI don't have any concern with the use of a proper gpio driver to model the implementation, but if I understand correctly this relationship between gpio controller and gpio consumer is strictly internal to "the PCI device".
(I think you're already cool with this but I still wanted to respond.)
That is not correct. These GPIO lines are used two ways for the RB3gen2:
- drivers/pci/pwrctrl/pci-pwrctrl-tc9563.c uses GPIOs 2 and 3 to assert/deassert the reset lines associated with the two exposed downstream PCIe ports on the PCIe switch within the TC956x.
- Each of the Ethernet PHYs has a reset GPIO. On the RB3gen2, the GPIOs used for the purpose come from the GPIO controller embedded in the TC9564 (00 and 01).
These are therefore "exposed" (they are *not* strictly internal).
Quoted 3 lines
Is this connection variable or is the link merely expressed in DeviceTree to mitigate the fact that you choose to implement the responsibilities of the two parts split into two device drivers?
It is variable. These resets might be implemented by other GPIO controllers on other platforms.
Quoted 3 lines
Are there other consumers of these TC956x gpios which would result in a board designer (and hence dts author) to ever reference this gpio-controller in a different way?
They could. Nine of these GPIOs are exposed by the TC956x pins (GPIO00-06, GPIO12, GPIO35 and GPIO36). The RB3gen2 uses 00-03 (and possibly 04 but that's for a PHY we haven't tested yet).
-Alex
Quoted 2 lines
Regards,
Bjorn
Bjorn Andersson
maintainerRe: [PATCH net-next 08/12] dt-bindings: net: toshiba,tc965x-dwmac: add TC956x Ethernet bridge
Quoted 7 lines · Alex Elder
Quoted 6 lines · Bjorn Andersson
Quoted 1 line · Alex Elder
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml +0
-0[..]
Quoted 2 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml +2
-0+ + gpio-controller: true
Quoted 7 lines
Quoted 4 lines
I don't have any concern with the use of a proper gpio driver to model the implementation, but if I understand correctly this relationship between gpio controller and gpio consumer is strictly internal to "the PCI device".
(I think you're already cool with this but I still wanted to respond.)
Thank you for the further clarifications, and added details, Alex. This does look reasonable to me.
Regards,
Bjorn
Quoted 32 lines
That is not correct. These GPIO lines are used two ways for the RB3gen2:
-drivers/pci/pwrctrl/pci-pwrctrl-tc9563.cuses GPIOs 2 and 3 to assert/deassert the reset lines associated with the two exposed downstream PCIe ports on the PCIe switch within the TC956x.- Each of the Ethernet PHYs has a reset GPIO. On the RB3gen2, the GPIOs used for the purpose come from the GPIO controller embedded in the TC9564 (00 and 01).
These are therefore "exposed" (they are *not* strictly internal).
Quoted 3 lines
Is this connection variable or is the link merely expressed in DeviceTree to mitigate the fact that you choose to implement the responsibilities of the two parts split into two device drivers?
It is variable. These resets might be implemented by other GPIO controllers on other platforms.
Quoted 3 lines
Are there other consumers of these TC956x gpios which would result in a board designer (and hence dts author) to ever reference this gpio-controller in a different way?
They could. Nine of these GPIOs are exposed by the TC956x pins (GPIO00-06, GPIO12, GPIO35 and GPIO36). The RB3gen2 uses 00-03 (and possibly 04 but that's for a PHY we haven't tested yet).
-Alex
Quoted 2 lines
Regards,
Bjorn
Rob Herring
maintainerRe: [PATCH net-next 08/12] dt-bindings: net: toshiba,tc965x-dwmac: add TC956x Ethernet bridge
In reply to Alex ElderQuoted 50 lines · Alex Elder
From: Daniel Thompson <[email protected]>
Add devicetree bindings for the Toshiba TC956x family of Ethernet-AVB/TSN bridges.
Signed-off-by Daniel Thompson <[email protected]>Signed-off-by Alex Elder <[email protected]>--- .../bindings/net/toshiba,tc956x-dwmac.yaml | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yamlDocumentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +31
-0@@ -0,0 +1,111 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/toshiba,tc956x-dwmac.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Toshiba TC956x Ethernet-AVB/TSN Controller + +maintainers: + - Alex Elder <[email protected]> + - Daniel Thompson <[email protected]> + +description: | + This node provides properties for configuring the Ethernet PCI functions + that are attached to the internal downstream port of the TC956x's PCIe + switch. + + TC956x are a family of Ethernet-AVB/TSN bridge chips that combine a PCIe + switch together with a number of Ethernet controllers. These bindings + cover only the Ethernet functions of these devices. + +allOf: + - $ref: /schemas/pci/pci-bus-common.yaml# + - $ref: /schemas/pci/pci-device.yaml# + +unevaluatedProperties: false + +properties: + compatible: + enum: + - pci1179,0220 # Toshiba TC9564 (a.k.a. Qualcomm QPS615)
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml line 41
Quoted 10 lines
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml new file +10
-0+ + "#gpio-cells": + const: 2 + + gpio-controller: true + + # We can't allOf reference Ethernet-controller.yaml because we end up with + # contradictory $nodename rules (`ethernet@` versus `pci@`). Happily only a + # small number of the properties are useful on TC956x so we can just reference + # what we need.
That would be due to the error sashiko pointed out. 'pci' is for PCI bridges (host or PCI-PCI).
Rob
PATCH 9/12 gpio: tc956x: add TC956x/QPS615 support
In reply to Alex ElderToshiba TC956x is an Ethernet-AVB/TSN bridge and is essentially a small and highly-specialized SoC. TC956x includes a GPIO block that can be accessed, alongside several other peripherals, via two PCIe endpoint functions. The PCIe function driver creates an auxiliary device for the GPIO block, and that device gets bound to this auxiliary device driver.
--- drivers/gpio/Kconfig | 11 ++ drivers/gpio/Makefile | 1 + drivers/gpio/gpio-tc956x.c | 209 +++++++++++++++++++++++++++++++++++++ 3 files changed, 221 insertions(+) create mode 100644 drivers/gpio/gpio-tc956x.c
drivers/gpio/Kconfig +11 -0
@@ -1646,6 +1646,17 @@ config GPIO_TC3589X This enables support for the GPIOs found on the TC3589X I/O Expander. +config GPIO_TC956X + tristate "Toshiba TC956X GPIO support" + depends on TOSHIBA_TC956X_PCI + default m if TOSHIBA_TC956X_PCI + help + This enables support for the GPIO controller embedded in the Toshiba + TC956X (and Qualcomm QPS615). This device connects to the host + via PCIe port, which is the upstream port on an internal PCIe + switch. On some platforms, a few of the GPIO lines are used to + manage external resets. + config GPIO_TIMBERDALE bool "Support for timberdale GPIO IP" depends on MFD_TIMBERDALE
drivers/gpio/Makefile +1 -0
@@ -178,6 +178,7 @@ obj-$(CONFIG_GPIO_SYSCON) += gpio-syscon.o obj-$(CONFIG_GPIO_TANGIER) += gpio-tangier.o obj-$(CONFIG_GPIO_TB10X) += gpio-tb10x.o obj-$(CONFIG_GPIO_TC3589X) += gpio-tc3589x.o +obj-$(CONFIG_GPIO_TC956X) += gpio-tc956x.o obj-$(CONFIG_GPIO_TEGRA186) += gpio-tegra186.o obj-$(CONFIG_GPIO_TEGRA) += gpio-tegra.o obj-$(CONFIG_GPIO_THUNDERX) += gpio-thunderx.o
drivers/gpio/gpio-tc956x.c new file +209 -0
209 lines not on this page · raw message
Signature · 1 line
2.51.0
Andrew Lunn
maintainerRe: [PATCH net-next 09/12] gpio: tc956x: add TC956x/QPS615 support
Quoted 5 lines
+ * There is a TC956X PCI power controller driver that accesses the
+ * direction and output value registers for GPIOs 2 and 3. These
+ * GPIOs control the reset signal for the two downstream PCIe ports.
+ * Their values will never change during operation of this driver, and
+ * this driver reserves these two GPIOS.
Why doesn't this power controller driver actually use this driver to control the GPIOs? Chicken/egg?
Maybe add a comment why gpio-regmap.c cannot be used. You probably need to instantiate it twice, but i still think you will end up with less code.
Andrew
Re: [PATCH net-next 09/12] gpio: tc956x: add TC956x/QPS615 support
Quoted 8 lines · Andrew Lunn
Quoted 5 lines
+ * There is a TC956X PCI power controller driver that accesses the
+ * direction and output value registers for GPIOs 2 and 3. These
+ * GPIOs control the reset signal for the two downstream PCIe ports.
+ * Their values will never change during operation of this driver, and
+ * this driver reserves these two GPIOS.Why doesn't this power controller driver actually use this driver to control the GPIOs? Chicken/egg?
I am not the one with authority on this, but yes, that's my understanding. *Something* about this chip requires that the PCIe ports need to have some configuration done on them *before* PCIe is powered up. So that driver uses the I2C interface to apply these settings. Meanwhile this driver uses the PCIe-mapped memory to manage the GPIO registers.
Quoted 3 lines
Maybe add a comment why
gpio-regmap.ccannot be used. You probably need to instantiate it twice, but i still think you will end up with less code.
It's possible gpio-regmap.c *could* be used. We started with vendor code and this code got separated at some point along the way. It was working, and I don't think I pursued other options at that point. I'll look at this possibility before we send out the next version.
What do you mean instantiate it twice?
-Alex
Quoted 2 lines
Andrew
Andrew Lunn
maintainerRe: [PATCH net-next 09/12] gpio: tc956x: add TC956x/QPS615 support
Quoted 5 lines
It's possible
gpio-regmap.c*could* be used. We started with vendor code and this code got separated at some point along the way. It was working, and I don't think I pursued other options at that point. I'll look at this possibility before we send out the next version.
The GPIO subsystem has made a big effort to provide generic code, since GPIOs are pretty simple things with a lot in common. So if the generic code works, or can be made to work with minor changes, you should use it.
Quoted 1 line
What do you mean instantiate it twice?
I _think_ you need one instance for the first 32 GPIOs, and a second one for the remaining GPIOs. But maybe config->reg_stride might allow it to work with a single instance?
Andrew
Re: [PATCH net-next 09/12] gpio: tc956x: add TC956x/QPS615 support
Quoted 10 lines · Andrew Lunn
Quoted 5 lines
It's possible
gpio-regmap.c*could* be used. We started with vendor code and this code got separated at some point along the way. It was working, and I don't think I pursued other options at that point. I'll look at this possibility before we send out the next version.The GPIO subsystem has made a big effort to provide generic code, since GPIOs are pretty simple things with a lot in common. So if the generic code works, or can be made to work with minor changes, you should use it.
Yes, I can confirm this is what I will use. As mentioned elsewhere, LinusW provided a patch that support the one unusual thing this does (input-only GPIO lines).
Quoted 5 lines
Quoted 1 line
What do you mean instantiate it twice?
I _think_ you need one instance for the first 32 GPIOs, and a second one for the remaining GPIOs. But maybe
config->reg_stridemight allow it to work with a single instance?
Oh I see. Looking at it now, I presume the reg_stride will work here.
Thanks.
-Alex
Quoted 1 line
Andrew
Andrew Lunn
maintainerRe: [PATCH net-next 09/12] gpio: tc956x: add TC956x/QPS615 support
In reply to Alex ElderQuoted 10 lines · Alex Elder
Quoted 8 lines · Andrew Lunn
Quoted 5 lines
+ * There is a TC956X PCI power controller driver that accesses the
+ * direction and output value registers for GPIOs 2 and 3. These
+ * GPIOs control the reset signal for the two downstream PCIe ports.
+ * Their values will never change during operation of this driver, and
+ * this driver reserves these two GPIOS.Why doesn't this power controller driver actually use this driver to control the GPIOs? Chicken/egg?
Quoted 6 lines
I am not the one with authority on this, but yes, that's my understanding. *Something* about this chip requires that the PCIe ports need to have some configuration done on them *before* PCIe is powered up. So that driver uses the I2C interface to apply these settings. Meanwhile this driver uses the PCIe-mapped memory to manage the GPIO registers.
The diagram you have is:
----------------------------------
| Host |
------+...+----------+........+---
|i2c| | PCIe |
----------------+...+----------+........+------
| TC956x |I2C| |upstream| |
| ----- --+--------+--- |
| ----- ------ ------- | PCIe switch | |
| |SPI| |GPIO| |reset| | | |
| ----- ------ |clock| | DS3 DS2 DS1 | |
| ------- ---++--++--++-- |
| ----- ------ downstream// \\ \\ | downstream
| |MCU| |SRAM| /==========/ \\ \===== PCIe port 1
| ----- ------ //PCIe port 3 \\ |
| || \======= downstream
| ----+-----------++-----------+---- | PCIe port 2
| | M | internal PCIe endpoint | M | |
| | S |------------------------| S | ------ |
| | I | PCIe | | PCIe | I | |UART| |
| | G |function 0| |function 1| G | ------ |
| | E |----++----| |----++----| E | |
| | N | eMAC 0 | | eMAC 1 | N | |
--------+.......+------+.....+-----------------
|USXGMII| |SGMII|
--+.......+-- --+.....+--
| ARQ113C | | QEP8121 |
| PHY | | PHY |
------------- -----------The two Ethernet controllers are hanging off port 3 of the switch. However, the GPIO block is just floating in space. What address space is it in?
I'm wondering if the GPIO controller should be a device/driver of its own? It probes first. The PCI power controller driver then probes, and has phandles to the GPIO controller so it can activate ports 1 and
2. Parallel to that the Ethernet driver(s) can probe, also using phandles to the GPIO they need.
Looking at this diagram, putting the GPIO controller within one of the port 3 functions is wrong. But maybe the diagram is not accurate.
Andrew
Re: [PATCH net-next 09/12] gpio: tc956x: add TC956x/QPS615 support
Quoted 50 lines · Andrew Lunn
Quoted 10 lines · Alex Elder
Quoted 8 lines · Andrew Lunn
Quoted 5 lines
+ * There is a TC956X PCI power controller driver that accesses the
+ * direction and output value registers for GPIOs 2 and 3. These
+ * GPIOs control the reset signal for the two downstream PCIe ports.
+ * Their values will never change during operation of this driver, and
+ * this driver reserves these two GPIOS.Why doesn't this power controller driver actually use this driver to control the GPIOs? Chicken/egg?
Quoted 6 lines
I am not the one with authority on this, but yes, that's my understanding. *Something* about this chip requires that the PCIe ports need to have some configuration done on them *before* PCIe is powered up. So that driver uses the I2C interface to apply these settings. Meanwhile this driver uses the PCIe-mapped memory to manage the GPIO registers.
The diagram you have is:
---------------------------------- | Host | ------+...+----------+........+--- |i2c| | PCIe | ----------------+...+----------+........+------ | TC956x |I2C| |upstream| | | ----- --+--------+--- | | ----- ------ ------- | PCIe switch | | | |SPI| |GPIO| |reset| | | | | ----- ------ |clock| | DS3 DS2 DS1 | | | ------- ---++--++--++-- | | ----- ------ downstream// \\ \\ | downstream | |MCU| |SRAM| /==========/ \\ \===== PCIe port 1 | ----- ------ //PCIe port 3 \\ | | || \======= downstream | ----+-----------++-----------+---- | PCIe port 2 | | M | internal PCIe endpoint | M | | | | S |------------------------| S | ------ | | | I | PCIe | | PCIe | I | |UART| | | | G |function 0| |function 1| G | ------ | | | E |----++----| |----++----| E | | | | N | eMAC 0 | | eMAC 1 | N | | --------+.......+------+.....+----------------- |USXGMII| |SGMII| --+.......+-- --+.....+-- | ARQ113C | | QEP8121 | | PHY | | PHY | ------------- -----------
Quoted 3 lines
The two Ethernet controllers are hanging off port 3 of the switch. However, the GPIO block is just floating in space. What address space is it in?
Well, that isn't easily representable.
In fact, the GPIO (and UART and eMACs, etc.) is accessible
multiple ways. They are in a single "SFR" range of memory
within the TC956x, which is partitioned into sub-ranges for the separate IP blocks.
E.g:0x40000000 Bootup config registers (size 0x1000)0x40006000 UART registers (size 0x1000)0x40020000 PCIe registerfs (size 0x00010000)0x40040000 EMAC0 (size 0x8000)
and others.
The MCU has access to this SFR space. The host CPU can access it via the I2C interface (as the PCIe power control driver does). The PCIe power control driver actually touches the GPIO registers to be able to assert reset on the two downstream PCIe ports.
In addition, BAR4 for both PCIe functions has access to the same SFR space. So in fact, both of these functions are capable of controlling GPIOs. We are having just one of them (function 0) be responsible for that.
Quoted 8 lines
I'm wondering if the GPIO controller should be a device/driver of its own? It probes first. The PCI power controller driver then probes, and has phandles to the GPIO controller so it can activate ports 1 and
2. Parallel to that the Ethernet driver(s) can probe, also using phandles to the GPIO they need.Looking at this diagram, putting the GPIO controller within one of the port 3 functions is wrong. But maybe the diagram is not accurate.
When the PCIe power controller was implemented, the GPIO functionality was not separated out. That driver simply touches two registers to manage asserting reset on the two downstream PCIe ports. (It changes these only during the appropriate times during power-up and power-down of the ports.)
It's possible *that* work could have implemented a separate GPIO driver. We did not pursue modifying the power control driver to work that way.
Instead, we modeled it starting with the STMMAC driver (which is how the Toshiba vendor driver works). But we separated the GPIO functionality into a separate (auxiliary) device, which has its own driver.
Because the internal endpoint won't operate until the PCIe power controller has enabled power, this GPIO driver and the PCIe power control driver won't interfere with each other's access to the shared registers.
In short, because this "SFR" space is available in various ways, there are several ways the GPIO (and other) IP can be managed and represented.
-Alex
Quoted 2 lines
Andrew
Andrew Lunn
maintainerRe: [PATCH net-next 09/12] gpio: tc956x: add TC956x/QPS615 support
Quoted 31 lines
Quoted 20 lines
---------------------------------- | Host | ------+...+----------+........+--- |i2c| | PCIe | ----------------+...+----------+........+------ | TC956x |I2C| |upstream| | | ----- --+--------+--- | | ----- ------ ------- | PCIe switch | | | |SPI| |GPIO| |reset| | | | | ----- ------ |clock| | DS3 DS2 DS1 | | | ------- ---++--++--++-- | | ----- ------ downstream// \\ \\ | downstream | |MCU| |SRAM| /==========/ \\ \===== PCIe port 1 | ----- ------ //PCIe port 3 \\ | | || \======= downstream | ----+-----------++-----------+---- | PCIe port 2 | | M | internal PCIe endpoint | M | | | | S |------------------------| S | ------ | | | I | PCIe | | PCIe | I | |UART| | | | G |function 0| |function 1| G | ------ |Quoted 9 lines
| | E |----++----| |----++----| E | | | | N | eMAC 0 | | eMAC 1 | N | | --------+.......+------+.....+----------------- |USXGMII| |SGMII| --+.......+-- --+.....+-- | ARQ113C | | QEP8121 | | PHY | | PHY | ------------- -----------
Quoted 4 lines
Because the internal endpoint won't operate until the PCIe power controller has enabled power, this GPIO driver and the PCIe power control driver won't interfere with each other's access to the shared registers.
What i find interesting is that there are two GPIOs, and two external downstream PCIe ports. A naive way of looking at this is that each external PCIe port has one GPIO. And the internal PCIe port does not have one. Hence the internal port might well work without any additional setup? That was my thinking.
But you are saying it is not as simple as this, and two GPIOs affect three ports? Do you have any idea what they actually do?
Andrew
Re: [PATCH net-next 09/12] gpio: tc956x: add TC956x/QPS615 support
Quoted 36 lines · Andrew Lunn
Quoted 31 lines
Quoted 20 lines
---------------------------------- | Host | ------+...+----------+........+--- |i2c| | PCIe | ----------------+...+----------+........+------ | TC956x |I2C| |upstream| | | ----- --+--------+--- | | ----- ------ ------- | PCIe switch | | | |SPI| |GPIO| |reset| | | | | ----- ------ |clock| | DS3 DS2 DS1 | | | ------- ---++--++--++-- | | ----- ------ downstream// \\ \\ | downstream | |MCU| |SRAM| /==========/ \\ \===== PCIe port 1 | ----- ------ //PCIe port 3 \\ | | || \======= downstream | ----+-----------++-----------+---- | PCIe port 2 | | M | internal PCIe endpoint | M | | | | S |------------------------| S | ------ | | | I | PCIe | | PCIe | I | |UART| | | | G |function 0| |function 1| G | ------ |Quoted 9 lines
| | E |----++----| |----++----| E | | | | N | eMAC 0 | | eMAC 1 | N | | --------+.......+------+.....+----------------- |USXGMII| |SGMII| --+.......+-- --+.....+-- | ARQ113C | | QEP8121 | | PHY | | PHY | ------------- -----------Quoted 4 lines
Because the internal endpoint won't operate until the PCIe power controller has enabled power, this GPIO driver and the PCIe power control driver won't interfere with each other's access to the shared registers.
Quoted 5 lines
What i find interesting is that there are two GPIOs, and two external downstream PCIe ports. A naive way of looking at this is that each external PCIe port has one GPIO. And the internal PCIe port does not have one. Hence the internal port might well work without any additional setup? That was my thinking.
I see what you're saying. I don't actually know what effect those two reset signals have on the internal PCIe endpoint or its port.
Here is what the power control driver does:
- asserts those two reset signals (via direct register writes)
- for every port on the switch:
- disables the port (which programs a sequence of values to specific addresses)
- sets several PCIe configuration options
- l0s_entry_delay
- l1_entry_delay
- TX amplitude
- NFTS
- disable DFE
- Finally deasserts those two reset signals again.
And "every port on the switch" is:
- USP (upstream port)
- DSP 1, 2, 3 (downstream ports, including the embedded one)
- Ethernet (which tells me maybe we need to update that driver to support two eMACs?)
The whole point of this power control driver is that it doesn't actually power up the PCIe switch at all until *after* this configuration step is complete. So I believe the internal endpoint and its two functions aren't powered until after the power control driver finishes probing.
The GPIO controller is obviously alive when the power control driver runs though.
Quoted 2 lines
But you are saying it is not as simple as this, and two GPIOs affect three ports? Do you have any idea what they actually do?
To be honest, for the most part we haven't looked closely at the PCIe power control driver--though it's relatively simple and I understand how the code works...
So I don't know the answer, but I expect with some work I might be able to find out.
To be clear, the reason you're asking is that you're suggesting we might want to model the GPIO controller differently, correct?
I.e., model it as *not* associated with the embedded PCIe functions. Then we need to think about what its parent device would be (the power control device, which I think somehow duplicates the switch device?).
-Alex
Quoted 1 line
Andrew
Andrew Lunn
maintainerRe: [PATCH net-next 09/12] gpio: tc956x: add TC956x/QPS615 support
Quoted 2 lines
To be clear, the reason you're asking is that you're suggesting we might want to model the GPIO controller differently, correct?
Correct.
Quoted 4 lines
I.e., model it as *not* associated with the embedded PCIe functions. Then we need to think about what its parent device would be (the power control device, which I think somehow duplicates the switch device?).
Logically, the GPIO controller cannot be part of a downstream function, if you need to use the GPIO controller to turn the downstream function on.
Logically, the GPIO controller needs to be above the switch downstream end points. Where above, i don't know. Which is why i was asking about where it appears in the address spaces.
But i also don't know too much about PCI, i'm used to SoCs with simple linear MMIO.
From the little i know, it is more than what address space does the GPIO appear in. Its also, what enumerable entity does it appear in within the PCI bus. Because its the enumeration which is going to trigger a driver load, which can then drive the GPIO controller.
Or, something more radical, you make the PCIe power controller an MFD, instantiating both the power controller and a GPIO controller over the I2C bus. GPIO access will not be as fast, but is there anything here which needs to be fast?
Andrew
Re: [PATCH net-next 09/12] gpio: tc956x: add TC956x/QPS615 support
Quoted 5 lines · Andrew Lunn
Quoted 2 lines
To be clear, the reason you're asking is that you're suggesting we might want to model the GPIO controller differently, correct?
Correct.
Quoted 8 lines
Quoted 4 lines
I.e., model it as *not* associated with the embedded PCIe functions. Then we need to think about what its parent device would be (the power control device, which I think somehow duplicates the switch device?).
Logically, the GPIO controller cannot be part of a downstream function, if you need to use the GPIO controller to turn the downstream function on.
Yes you're right, though the PCIe power controller functions before the PCIe switch is enabled, and uses I2C to communicate with the host.
Quoted 3 lines
Logically, the GPIO controller needs to be above the switch downstream end points. Where above, i don't know. Which is why i was asking about where it appears in the address spaces.
You are touching on an issue we have faced since we started on this earlier in the year. Our objective was to enable the eMACs, but there was no device representing the "chip" (which holds the switch and the GPIO controller, etc.). The TC956x is more than just a PCIe switch, and more than just two Ethernet MACs. The vendor code handles some of this between PCIe functions with some reference counting and perhaps other things.
Eventually we settled on the model we have presented, which creates a device for each function and lets one of them take care of common "chip" things (including creating the GPIO auxiliary device). The function device driver creates a new auxiliary device to represent the MAC for each function.
I also considered modeling the TC956x as a remoteproc, but have been reluctant to really pursue that.
Quoted 2 lines
But i also don't know too much about PCI, i'm used to SoCs with simple linear MMIO.
I'm no PCI expert either, but I'm learning.
Quoted 9 lines
From the little i know, it is more than what address space does the
GPIO appear in. Its also, what enumerable entity does it appear in within the PCI bus. Because its the enumeration which is going to trigger a driver load, which can then drive the GPIO controller.Or, something more radical, you make the PCIe power controller an MFD, instantiating both the power controller and a GPIO controller over the I2C bus. GPIO access will not be as fast, but is there anything here which needs to be fast?
I considered that, but opted not to mess with the PCIe power controller driver.
It's only asserting resets in the RB3gen2, so I don't the speed is a major factor.
-Alex
Quoted 2 lines
Andrew
[email protected]
AI reviewRe: [PATCH net-next 09/12] gpio: tc956x: add TC956x/QPS615 support
In reply to Alex ElderThank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider: - [High] Function signature mismatch for `tc956x_gpio_set` causing build failures. - [High] Sleeping in…
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] Function signature mismatch for tc956x_gpio_set causing build failures.
- [High] Sleeping in atomic context bug on PREEMPT_RT due to can_sleep = false.
- [Medium] Uninitialized stack variable used if regmap_read() fails.
- [Medium] Ignored regmap_update_bits() return value can cause incorrect hardware state.
- [Low] Kconfig depends on a non-existent symbol.
--
commit ff81a192de0fcb35d3c4b8a32cad777cd0bff29e
Author: Alex Elder <[email protected]>
gpio: tc956x: add TC956x/QPS615 support
This commit adds support for the GPIO controller embedded in the Toshiba TC956x Ethernet-AVB/TSN bridge. It implements an auxiliary device driver for the GPIO block using regmap.
Quoted 3 lines
drivers/gpio/Kconfig +0
-0
[ ... ]
drivers/gpio/Kconfig config GPIO_TC3589X · line 1651
Quoted 3 lines
drivers/gpio/Kconfig +3
-0+config GPIO_TC956X + tristate "Toshiba TC956X GPIO support" + depends on TOSHIBA_TC956X_PCI
Does TOSHIBA_TC956X_PCI exist in the tree at this point? Reference to a non-existent config symbol causes silent build failures. If it is added later in the patch series, this temporarily leaves the driver unselectable and breaks bisectability.
[ ... ]
Quoted 3 lines
drivers/gpio/gpio-tc956x.c new file +0
-0
[ ... ]
drivers/gpio/gpio-tc956x.c line 68
Quoted 12 lines
drivers/gpio/gpio-tc956x.c new file +12
-0+static int tc956x_gpio_get_direction (struct gpio_chip *gc,unsigned int offset) +{ +struct tc956x_gpio *gpio =gpiochip_get_data (gc); +u32 reg; +u32 val; + +if (test_bit (offset, gpio->input_only)) +return GPIO_LINE_DIRECTION_IN ; + + reg = offset <32 ?GPIO_EN0_OFFSET :GPIO_EN1_OFFSET ; + +regmap_read (gpio->regmap, reg, &val);
If regmap_read() fails, does it leave the stack variable val uninitialized? Should the return value be checked before evaluating val in the next line?
Quoted 5 lines
drivers/gpio/gpio-tc956x.c new file +5
-0+if (val &BIT (offset %32 )) +return GPIO_LINE_DIRECTION_IN ; + +return GPIO_LINE_DIRECTION_OUT ; +}
[ ... ]
Quoted 7 lines
drivers/gpio/gpio-tc956x.c new file +7
-0+static int tc956x_gpio_direction_output (struct gpio_chip *gc, +unsigned int offset,int value) +{ +struct tc956x_gpio *gpio =gpiochip_get_data (gc); +u32 vreg; +u32 dreg; +u32 mask;
[ ... ]
drivers/gpio/gpio-tc956x.c line 106
Quoted 2 lines
drivers/gpio/gpio-tc956x.c new file +2
-0+/* Set output value first, then direction */ +regmap_update_bits (gpio->regmap, vreg, mask, value ? mask :0 );
If this first regmap_update_bits() fails, should the function bail out early? Ignoring the error and proceeding to change the direction to output anyway could actively drive an unintended logic level onto the pin.
drivers/gpio/gpio-tc956x.c line 117
Quoted 11 lines
drivers/gpio/gpio-tc956x.c new file +11
-0+ +return regmap_update_bits (gpio->regmap, dreg, mask,0 ); +} + +static int tc956x_gpio_get (struct gpio_chip *gc,unsigned int offset) +{ +u32 reg = offset <32 ?GPIO_IN0_OFFSET :GPIO_IN1_OFFSET ; +struct tc956x_gpio *gpio =gpiochip_get_data (gc); +u32 val; + +regmap_read (gpio->regmap, reg, &val);
Similar to tc956x_gpio_get_direction(), does this leave val uninitialized and return unpredictable states if regmap_read() fails?
drivers/gpio/gpio-tc956x.c line 122
Quoted 5 lines
drivers/gpio/gpio-tc956x.c new file +5
-0+ +return val &BIT (offset %32 ) ?1 :0 ; +} + +static int tc956x_gpio_set (struct gpio_chip *gc,unsigned int offset,int value)
Does the set function pointer in struct gpio_chip expect a void return type? Assigning a function returning int could trigger an incompatible pointer type compiler error or cause Control Flow Integrity panics at runtime.
Quoted 7 lines
drivers/gpio/gpio-tc956x.c new file +7
-0+{ +u32 reg = offset <32 ?GPIO_OUT0_OFFSET :GPIO_OUT1_OFFSET ; +struct tc956x_gpio *gpio =gpiochip_get_data (gc); +u32 mask =BIT (offset %32 ); + +return regmap_update_bits (gpio->regmap, reg, mask, value ? mask :0 ); +}
[ ... ]
Quoted 3 lines
drivers/gpio/gpio-tc956x.c new file +3
-0+static int tc956x_gpio_probe (struct auxiliary_device *adev, +const struct auxiliary_device_id *id) +{
[ ... ]
drivers/gpio/gpio-tc956x.c line 182
Quoted 3 lines
drivers/gpio/gpio-tc956x.c new file +3
-0+ gc->base =-1 ; + gc->ngpio =TC956X_GPIO_COUNT ; + gc->can_sleep = false;
Is it safe to set can_sleep to false while using a regmap? By default, MMIO regmaps use spinlock_t for synchronization, which becomes a sleepable rt_mutex on PREEMPT_RT kernels. Calling these GPIO methods from an atomic context on PREEMPT_RT could cause a panic.
Quoted 5 lines
drivers/gpio/gpio-tc956x.c new file +5
-0+ +dev_set_drvdata (dev, gpio); + +return devm_gpiochip_add_data (dev, gc, gpio); +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
Re: [PATCH net-next 09/12] gpio: tc956x: add TC956x/QPS615 support
Quoted 21 lines · On 5/2/26 10:56 AM, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] Function signature mismatch fortc956x_gpio_setcausing build failures.
- [High] Sleeping in atomic context bug onPREEMPT_RTdue tocan_sleep = false.
- [Medium] Uninitialized stack variable used ifregmap_read()fails.
- [Medium] Ignoredregmap_update_bits()return value can cause incorrect hardware state.
- [Low]Kconfigdepends on a non-existent symbol.
--commit
ff81a192de0fcb35d3c4b8a32cad777cd0bff29e
Author: Alex Elder <[email protected]>gpio: tc956x: add TC956x/QPS615 support
This commit adds support for the GPIO controller embedded in the Toshiba TC956x Ethernet-AVB/TSN bridge. It implements an auxiliary device driver for the GPIO block using regmap.
Quoted 3 lines
drivers/gpio/Kconfig +0
-0[ ... ]
Quoted 8 lines
drivers/gpio/Kconfig config GPIO_TC3589X · line 1651
Quoted 3 lines
drivers/gpio/Kconfig +3
-0+config GPIO_TC956X + tristate "Toshiba TC956X GPIO support" + depends on TOSHIBA_TC956X_PCIDoes
TOSHIBA_TC956X_PCIexist in the tree at this point? Reference to a non-existent config symbol causes silent build failures. If it is added later in the patch series, this temporarily leaves the driver unselectable and breaks bisectability.
In version 2 of the series, the patch that defines TOSHIBA_TC956X_PCI will come earlier than this one in the series.
Quoted 6 lines
[ ... ]
Quoted 3 lines
drivers/gpio/gpio-tc956x.c new file +0
-0[ ... ]
Quoted 15 lines
drivers/gpio/gpio-tc956x.c line 68
Quoted 12 lines
drivers/gpio/gpio-tc956x.c new file +12
-0+static int tc956x_gpio_get_direction (struct gpio_chip *gc,unsigned int offset) +{ +struct tc956x_gpio *gpio =gpiochip_get_data (gc); +u32 reg; +u32 val; + +if (test_bit (offset, gpio->input_only)) +return GPIO_LINE_DIRECTION_IN ; + + reg = offset <32 ?GPIO_EN0_OFFSET :GPIO_EN1_OFFSET ; + +regmap_read (gpio->regmap, reg, &val);If
regmap_read()fails, does it leave the stack variable val uninitialized? Should the return value be checked before evaluating val in the next line?
In this case, we know we are using an MMIO-based regmap, and since we have no clock, regmap_mmio_read() always returns 0.
Quoted 14 lines
Quoted 5 lines
drivers/gpio/gpio-tc956x.c new file +5
-0+if (val &BIT (offset %32 )) +return GPIO_LINE_DIRECTION_IN ; + +return GPIO_LINE_DIRECTION_OUT ; +}[ ... ]
Quoted 7 lines
drivers/gpio/gpio-tc956x.c new file +7
-0+static int tc956x_gpio_direction_output (struct gpio_chip *gc, +unsigned int offset,int value) +{ +struct tc956x_gpio *gpio =gpiochip_get_data (gc); +u32 vreg; +u32 dreg; +u32 mask;[ ... ]
Quoted 6 lines
drivers/gpio/gpio-tc956x.c line 106
Quoted 2 lines
drivers/gpio/gpio-tc956x.c new file +2
-0+/* Set output value first, then direction */ +regmap_update_bits (gpio->regmap, vreg, mask, value ? mask :0 );If this first
regmap_update_bits()fails, should the function bail out early? Ignoring the error and proceeding to change the direction to output anyway could actively drive an unintended logic level onto the pin.
Again, we do not expect regmap_update_bits() to return an error for an MMIO-based regmap.
Quoted 6 lines
Quoted 6 lines
drivers/gpio/gpio-tc956x.c new file +6
-0+ +return regmap_update_bits (gpio->regmap, dreg, mask,0 ); +} + +static int tc956x_gpio_get (struct gpio_chip *gc,unsigned int offset) +{
Quoted 8 lines
drivers/gpio/gpio-tc956x.c line 117
Quoted 5 lines
drivers/gpio/gpio-tc956x.c new file +5
-0+u32 reg = offset <32 ?GPIO_IN0_OFFSET :GPIO_IN1_OFFSET ; +struct tc956x_gpio *gpio =gpiochip_get_data (gc); +u32 val; + +regmap_read (gpio->regmap, reg, &val);Similar to
tc956x_gpio_get_direction(), does this leave val uninitialized and return unpredictable states ifregmap_read()fails?
This should not fail, so we expect val will be initialized.
Quoted 11 lines
drivers/gpio/gpio-tc956x.c line 122
Quoted 6 lines
drivers/gpio/gpio-tc956x.c new file +5
-0+ +return val &BIT (offset %32 ) ?1 :0 ; +} + +static int tc956x_gpio_set (struct gpio_chip *gc,unsigned int offset,int value)Does the set function pointer in struct
gpio_chipexpect a void return type? Assigning a function returning int could trigger an incompatible pointer type compiler error or cause Control Flow Integrity panics at runtime.
I might be missing something but I don't understand this comment. In any case, the next version of the code implements the GPIO controller using the gpio-regmap framework.
Quoted 13 lines
Quoted 8 lines
drivers/gpio/gpio-tc956x.c new file +7
-0+{ +u32 reg = offset <32 ?GPIO_OUT0_OFFSET :GPIO_OUT1_OFFSET ; +struct tc956x_gpio *gpio =gpiochip_get_data (gc); +u32 mask =BIT (offset %32 ); + +return regmap_update_bits (gpio->regmap, reg, mask, value ? mask :0 ); +}[ ... ]
Quoted 3 lines
drivers/gpio/gpio-tc956x.c new file +3
-0+static int tc956x_gpio_probe (struct auxiliary_device *adev, +const struct auxiliary_device_id *id) +{[ ... ]
Quoted 8 lines
drivers/gpio/gpio-tc956x.c line 182
Quoted 3 lines
drivers/gpio/gpio-tc956x.c new file +3
-0+ gc->base =-1 ; + gc->ngpio =TC956X_GPIO_COUNT ; + gc->can_sleep = false;Is it safe to set
can_sleepto false while using a regmap? By default, MMIO regmaps usespinlock_tfor synchronization, which becomes a sleepablert_mutexonPREEMPT_RTkernels. Calling these GPIO methods from an atomic context onPREEMPT_RTcould cause a panic.
Here too, even if this were an issue, the issue will move into the gpio-regmap code with the new version of the code.
-Alex
Quoted 7 lines
Quoted 6 lines
drivers/gpio/gpio-tc956x.c new file +5
-0+ +dev_set_drvdata (dev, gpio); + +return devm_gpiochip_add_data (dev, gc, gpio); +}
Re: [PATCH net-next 09/12] gpio: tc956x: add TC956x/QPS615 support
In reply to Alex Elderdrivers/gpio/Kconfig config GPIO_TC3589X · line 1652
Quoted 4 lines · Alex Elder
drivers/gpio/Kconfig +4
-0+config GPIO_TC956X + tristate "Toshiba TC956X GPIO support" + depends on TOSHIBA_TC956X_PCI + default m if TOSHIBA_TC956X_PCI
Hi Alex,
In your Kconfig changes, this condition 'if TOSHIBA_TC956X_PCI' is dead code. Since you have the dependency on TOSHIBA_TC956X_PCI, you can just make the 'default m' unconditional - assuming this is what you intended.
Perhaps you would prefer to use 'default TOSHIBA_TC956X_PCI', which would have GPIO_TC956X default to 'm' or 'y' when TOSHIBA_TC956X_PCI is 'm' or 'y', respectively.
- Julian Braha
Re: [PATCH net-next 09/12] gpio: tc956x: add TC956x/QPS615 support
Quoted 11 lines · Julian Braha
drivers/gpio/Kconfig config GPIO_TC3589X · line 1652
Quoted 4 lines · Alex Elder
drivers/gpio/Kconfig +4
-0+config GPIO_TC956X + tristate "Toshiba TC956X GPIO support" + depends on TOSHIBA_TC956X_PCI + default m if TOSHIBA_TC956X_PCIHi Alex,
In your
Kconfigchanges, this condition 'ifTOSHIBA_TC956X_PCI' is dead code. Since you have the dependency onTOSHIBA_TC956X_PCI, you can just make the 'default m' unconditional - assuming this is what you intended.
I'm not sure I'd call it "dead" but you're right, it's not necessary because it already depends on that symbol.
Quoted 3 lines
Perhaps you would prefer to use 'default
TOSHIBA_TC956X_PCI', which would haveGPIO_TC956Xdefault to 'm' or 'y' whenTOSHIBA_TC956X_PCIis 'm' or 'y', respectively.
Yeah that might be better. I'd like to eventually include COMPILE_TEST as well, and that might need the "if" on the default. I'll find out whenever I test that.
This GPIO feature should still be a module even if TOSHIBA_TC956X_PCI is y, because it's not always necessary to enable the GPIO driver (depending on how devicetree defines the PHY resets).
So: In drivers/gpio/Kconfig it will be "default m", and for drivers/net/ethernet/stmicro/stmmac/Kconfig it will be default TOSHIBA_TC956X_PCI (at least for now).
Thanks a lot for the suggestion.
-Alex
Quoted 1 line
- Julian Braha
Bartosz Golaszewski
maintainerRe: [PATCH net-next 09/12] gpio: tc956x: add TC956x/QPS615 support
In reply to Alex ElderQuoted 73 lines · Alex Elder
Toshiba TC956x is an Ethernet-AVB/TSN bridge and is essentially a small and highly-specialized SoC. TC956x includes a GPIO block that can be accessed, alongside several other peripherals, via two PCIe endpoint functions. The PCIe function driver creates an auxiliary device for the GPIO block, and that device gets bound to this auxiliary device driver.
Co-developed-by Daniel Thompson <[email protected]>Signed-off-by Daniel Thompson <[email protected]>Signed-off-by Alex Elder <[email protected]>--- drivers/gpio/Kconfig | 11 ++ drivers/gpio/Makefile | 1 + drivers/gpio/gpio-tc956x.c | 209 +++++++++++++++++++++++++++++++++++++ 3 files changed, 221 insertions(+) create mode 100644 drivers/gpio/gpio-tc956x.cdrivers/gpio/Kconfig +11
-0@@ -1646,6 +1646,17 @@ config GPIO_TC3589X This enables support for the GPIOs found on the TC3589X I/O Expander. +config GPIO_TC956X + tristate "Toshiba TC956X GPIO support" + depends on TOSHIBA_TC956X_PCI + default m if TOSHIBA_TC956X_PCI + help + This enables support for the GPIO controller embedded in the Toshiba + TC956X (and Qualcomm QPS615). This device connects to the host + via PCIe port, which is the upstream port on an internal PCIe + switch. On some platforms, a few of the GPIO lines are used to + manage external resets. + config GPIO_TIMBERDALE bool "Support for timberdale GPIO IP" depends on MFD_TIMBERDALEdrivers/gpio/Makefile +1
-0@@ -178,6 +178,7 @@ obj-$(CONFIG_GPIO_SYSCON) += gpio-syscon.o obj-$(CONFIG_GPIO_TANGIER) += gpio-tangier.o obj-$(CONFIG_GPIO_TB10X) += gpio-tb10x.o obj-$(CONFIG_GPIO_TC3589X) += gpio-tc3589x.o +obj-$(CONFIG_GPIO_TC956X) += gpio-tc956x.o obj-$(CONFIG_GPIO_TEGRA186) += gpio-tegra186.o obj-$(CONFIG_GPIO_TEGRA) += gpio-tegra.o obj-$(CONFIG_GPIO_THUNDERX) += gpio-thunderx.odrivers/gpio/gpio-tc956x.c new file +16
-0@@ -0,0 +1,209 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* Copyright (C) 2026 by RISCstar Solutions Corporation. All rights reserved. +*/ + +/* +* The Toshiba TC956X implements a PCIe Gen 3 switch that connects an +* upstream x4 port to two downstream PCIe x2 ports. It incorporates +* an internal endpoint on a internal PCIe port that implements two +* Synopsys XGMAC Ethernet interfaces. +* +* 35 GPIOs are also implemented by an embedded GPIO controller. Three +* registers control the first 32 GPIOs (other than 20 and 21, which are +* reserved). Three other registers control GPIOs 32 through 36. GPIOs +* 22-24, 27-28, 31, and 34 are treated as "input only".
drivers/gpio/gpio-tc956x.c line 26
Quoted 10 lines
drivers/gpio/gpio-tc956x.c new file +10
-0+* +* There is a TC956X PCI power controller driver that accesses the +* direction and output value registers for GPIOs 2 and 3. These +* GPIOs control the reset signal for the two downstream PCIe ports. +* Their values will never change during operation of this driver, and +* this driver reserves these two GPIOS. +*/ + +#include <linux/auxiliary_bus.h> +#include <linux/dev_printk.h>
This is implied by device.h which is guarnteed by platform_device.h. Please drop it.
Quoted 123 lines
drivers/gpio/gpio-tc956x.c new file +123
-0+#include <linux/gpio/driver.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> + +#define DRIVER_NAME "tc956x-gpio" + +#define TC956X_GPIO_COUNT 37/* Number of GPIOs (20-21 reserved) */ + +/* The GPIO offsets are relative to 0x1200 in TC956X SFR space */ +#define GPIO_IN0_OFFSET 0x00/* Input value (0-31) */ +#define GPIO_EN0_OFFSET 0x08/* 0: out; 1: in (0-31) */ +#define GPIO_OUT0_OFFSET 0x10/* Output value (0-31) */ + +#define GPIO_IN1_OFFSET 0x04/* Input value (32-36) */ +#define GPIO_EN1_OFFSET 0x0c/* 0: out; 1: in (32-36) */ +#define GPIO_OUT1_OFFSET 0x14/* Output value (32-36) */ + +/* +* struct tc956x_gpio - Information related to the embedded GPIO controller +* @chip: GPIO chip structure +* @regmap: MMIO register map for SFR GPIO region access +* @input_only: Bitmap indicating which GPIOs are input-only +*/ +struct tc956x_gpio { +struct gpio_chip chip; +struct regmap *regmap; + DECLARE_BITMAP(input_only, TC956X_GPIO_COUNT); +}; + +static int tc956x_gpio_get_direction (struct gpio_chip *gc,unsigned int offset) +{ +struct tc956x_gpio *gpio =gpiochip_get_data (gc); +u32 reg; +u32 val; + +if (test_bit (offset, gpio->input_only)) +return GPIO_LINE_DIRECTION_IN ; + + reg = offset <32 ?GPIO_EN0_OFFSET :GPIO_EN1_OFFSET ; + +regmap_read (gpio->regmap, reg, &val); +if (val &BIT (offset %32 )) +return GPIO_LINE_DIRECTION_IN ; + +return GPIO_LINE_DIRECTION_OUT ; +} + +static int tc956x_gpio_direction_input (struct gpio_chip *gc, +unsigned int offset) +{ +u32 reg = offset <32 ?GPIO_EN0_OFFSET :GPIO_EN1_OFFSET ; +struct tc956x_gpio *gpio =gpiochip_get_data (gc); +u32 mask =BIT (offset %32 ); + +return regmap_update_bits (gpio->regmap, reg, mask, mask); +} + +static int tc956x_gpio_direction_output (struct gpio_chip *gc, +unsigned int offset,int value) +{ +struct tc956x_gpio *gpio =gpiochip_get_data (gc); +u32 vreg; +u32 dreg; +u32 mask; + +if (test_bit (offset, gpio->input_only)) +return -EINVAL ; + +if (offset <32 ) { + vreg =GPIO_OUT0_OFFSET ; + dreg =GPIO_EN0_OFFSET ; + }else { + vreg =GPIO_OUT1_OFFSET ; + dreg =GPIO_EN1_OFFSET ; + } + mask =BIT (offset %32 ); + +/* Set output value first, then direction */ +regmap_update_bits (gpio->regmap, vreg, mask, value ? mask :0 ); + +return regmap_update_bits (gpio->regmap, dreg, mask,0 ); +} + +static int tc956x_gpio_get (struct gpio_chip *gc,unsigned int offset) +{ +u32 reg = offset <32 ?GPIO_IN0_OFFSET :GPIO_IN1_OFFSET ; +struct tc956x_gpio *gpio =gpiochip_get_data (gc); +u32 val; + +regmap_read (gpio->regmap, reg, &val); + +return val &BIT (offset %32 ) ?1 :0 ; +} + +static int tc956x_gpio_set (struct gpio_chip *gc,unsigned int offset,int value) +{ +u32 reg = offset <32 ?GPIO_OUT0_OFFSET :GPIO_OUT1_OFFSET ; +struct tc956x_gpio *gpio =gpiochip_get_data (gc); +u32 mask =BIT (offset %32 ); + +return regmap_update_bits (gpio->regmap, reg, mask, value ? mask :0 ); +} + +static int tc956x_gpio_init_valid_mask (struct gpio_chip *gc, +unsigned long *valid_mask, +unsigned int ngpios) +{ +/* +* GPIOs 2 and 3 are used by the PCI power control driver, and +* we don't allow them to be used. GPIOs 20 and 21 are reserved +* (and not usable). +*/ +bitmap_fill (valid_mask, ngpios); +bitmap_clear (valid_mask,2 ,2 ); +bitmap_clear (valid_mask,20 ,2 ); + +return 0 ; +} + +static int tc956x_gpio_probe (struct auxiliary_device *adev, +const struct auxiliary_device_id *id) +{
drivers/gpio/gpio-tc956x.c line 159
Quoted 10 lines
drivers/gpio/gpio-tc956x.c new file +10
-0+struct device *dev = &adev->dev; +struct tc956x_gpio *gpio; +struct gpio_chip *gc; + +if (!dev->platform_data) +return -EINVAL ; + + gpio =devm_kzalloc (dev,sizeof (*gpio),GFP_KERNEL ); +if (!gpio) +return -ENOMEM ;
Add newline.
drivers/gpio/gpio-tc956x.c line 160
Quoted 1 line
drivers/gpio/gpio-tc956x.c new file +1
-0+ gpio->regmap = dev->platform_data;
It's not clear whether this is an mmio regmap or a slow-bus one that can fail. In the code above you're checking the return values of regmap operations quite inconsistently. Could you please verify if you need it and either always check them or not at all?
Quoted 12 lines
drivers/gpio/gpio-tc956x.c new file +12
-0+ +/* Mark GPIOs 22, 23, 24, 27, 28, 31, and 34 as input only */ +bitmap_set (gpio->input_only,22 ,3 ); +bitmap_set (gpio->input_only,27 ,2 ); +set_bit (31 , gpio->input_only); +set_bit (34 , gpio->input_only); + + gc = &gpio->chip; + + gc->label =DRIVER_NAME ; + gc->parent = dev->parent; +
drivers/gpio/gpio-tc956x.c line 182
Quoted 10 lines
drivers/gpio/gpio-tc956x.c new file +10
-0+ gc->get_direction = tc956x_gpio_get_direction; + gc->direction_input = tc956x_gpio_direction_input; + gc->direction_output = tc956x_gpio_direction_output; + gc->get = tc956x_gpio_get; + gc->set = tc956x_gpio_set; + gc->init_valid_mask = tc956x_gpio_init_valid_mask; + + gc->base =-1 ; + gc->ngpio =TC956X_GPIO_COUNT ; + gc->can_sleep = false;
This makes me think this is an MMIO regmap after all.
drivers/gpio/gpio-tc956x.c line 184
Quoted 2 lines
drivers/gpio/gpio-tc956x.c new file +2
-0+ +dev_set_drvdata (dev, gpio);
There's no corresponding dev_get_drvdata().
Quoted 26 lines
drivers/gpio/gpio-tc956x.c new file +25
-1+ +return devm_gpiochip_add_data (dev, gc, gpio); +} + +static const struct auxiliary_device_id tc956x_gpio_ids[] = { + { .name ="tc956x_pci.tc9564-gpio" , }, + { } +}; +MODULE_DEVICE_TABLE (auxiliary, tc956x_gpio_ids); + +static struct auxiliary_driver tc956x_gpio_driver = { + .name =DRIVER_NAME , + .probe = tc956x_gpio_probe, + .id_table = tc956x_gpio_ids, + .driver = { + .name =DRIVER_NAME , + .owner =THIS_MODULE , + .probe_type =PROBE_PREFER_ASYNCHRONOUS , + }, +}; +module_auxiliary_driver (tc956x_gpio_driver); + +MODULE_DESCRIPTION ("Toshiba TC956X PCIe GPIO Driver" ); +MODULE_LICENSE ("GPL" ); +MODULE_ALIAS ("auxiliary:" DRIVER_NAME ); --
Quoted 3 lines
2.51.0
There are a few minor issues but overall looks good!
Bart
Re: [PATCH net-next 09/12] gpio: tc956x: add TC956x/QPS615 support
Quoted 11 lines · Bartosz Golaszewski
Quoted 10 lines · Alex Elder
Toshiba TC956x is an Ethernet-AVB/TSN bridge and is essentially a small and highly-specialized SoC. TC956x includes a GPIO block that can be accessed, alongside several other peripherals, via two PCIe endpoint functions. The PCIe function driver creates an auxiliary device for the GPIO block, and that device gets bound to this auxiliary device driver.
Co-developed-by Daniel Thompson <[email protected]>Signed-off-by Daniel Thompson <[email protected]>Signed-off-by Alex Elder <[email protected]>
Thanks Bartosz, I've got some responses below.
Quoted 68 lines
Quoted 68 lines
--- drivers/gpio/Kconfig | 11 ++ drivers/gpio/Makefile | 1 + drivers/gpio/gpio-tc956x.c | 209 +++++++++++++++++++++++++++++++++++++ 3 files changed, 221 insertions(+)create mode 100644
drivers/gpio/gpio-tc956x.cdrivers/gpio/Kconfig +11
-0@@ -1646,6 +1646,17 @@ config GPIO_TC3589X This enables support for the GPIOs found on the TC3589X I/O Expander. +config GPIO_TC956X + tristate "Toshiba TC956X GPIO support" + depends on TOSHIBA_TC956X_PCI + default m if TOSHIBA_TC956X_PCI + help + This enables support for the GPIO controller embedded in the Toshiba + TC956X (and Qualcomm QPS615). This device connects to the host + via PCIe port, which is the upstream port on an internal PCIe + switch. On some platforms, a few of the GPIO lines are used to + manage external resets. + config GPIO_TIMBERDALE bool "Support for timberdale GPIO IP" depends on MFD_TIMBERDALEdrivers/gpio/Makefile +1
-0@@ -178,6 +178,7 @@ obj-$(CONFIG_GPIO_SYSCON) += gpio-syscon.o obj-$(CONFIG_GPIO_TANGIER) += gpio-tangier.o obj-$(CONFIG_GPIO_TB10X) += gpio-tb10x.o obj-$(CONFIG_GPIO_TC3589X) += gpio-tc3589x.o +obj-$(CONFIG_GPIO_TC956X) += gpio-tc956x.o obj-$(CONFIG_GPIO_TEGRA186) += gpio-tegra186.o obj-$(CONFIG_GPIO_TEGRA) += gpio-tegra.o obj-$(CONFIG_GPIO_THUNDERX) += gpio-thunderx.odrivers/gpio/gpio-tc956x.c new file +21
-0@@ -0,0 +1,209 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* Copyright (C) 2026 by RISCstar Solutions Corporation. All rights reserved. +*/ + +/* +* The Toshiba TC956X implements a PCIe Gen 3 switch that connects an +* upstream x4 port to two downstream PCIe x2 ports. It incorporates +* an internal endpoint on a internal PCIe port that implements two +* Synopsys XGMAC Ethernet interfaces. +* +* 35 GPIOs are also implemented by an embedded GPIO controller. Three +* registers control the first 32 GPIOs (other than 20 and 21, which are +* reserved). Three other registers control GPIOs 32 through 36. GPIOs +* 22-24, 27-28, 31, and 34 are treated as "input only". +* +* There is a TC956X PCI power controller driver that accesses the +* direction and output value registers for GPIOs 2 and 3. These +* GPIOs control the reset signal for the two downstream PCIe ports. +* Their values will never change during operation of this driver, and
Quoted 8 lines
drivers/gpio/gpio-tc956x.c line 26
Quoted 5 lines
drivers/gpio/gpio-tc956x.c new file +5
-0+* this driver reserves these two GPIOS. +*/ + +#include <linux/auxiliary_bus.h> +#include <linux/dev_printk.h> This is implied by
device.hwhich is guarnteed byplatform_device.h. Please drop it.
OK, I'll drop it.
Quoted 127 lines
Quoted 127 lines
drivers/gpio/gpio-tc956x.c new file +127
-0+#include <linux/gpio/driver.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> + +#define DRIVER_NAME "tc956x-gpio" + +#define TC956X_GPIO_COUNT 37/* Number of GPIOs (20-21 reserved) */ + +/* The GPIO offsets are relative to 0x1200 in TC956X SFR space */ +#define GPIO_IN0_OFFSET 0x00/* Input value (0-31) */ +#define GPIO_EN0_OFFSET 0x08/* 0: out; 1: in (0-31) */ +#define GPIO_OUT0_OFFSET 0x10/* Output value (0-31) */ + +#define GPIO_IN1_OFFSET 0x04/* Input value (32-36) */ +#define GPIO_EN1_OFFSET 0x0c/* 0: out; 1: in (32-36) */ +#define GPIO_OUT1_OFFSET 0x14/* Output value (32-36) */ + +/* +* struct tc956x_gpio - Information related to the embedded GPIO controller +* @chip: GPIO chip structure +* @regmap: MMIO register map for SFR GPIO region access +* @input_only: Bitmap indicating which GPIOs are input-only +*/ +struct tc956x_gpio { +struct gpio_chip chip; +struct regmap *regmap; + DECLARE_BITMAP(input_only, TC956X_GPIO_COUNT); +}; + +static int tc956x_gpio_get_direction (struct gpio_chip *gc,unsigned int offset) +{ +struct tc956x_gpio *gpio =gpiochip_get_data (gc); +u32 reg; +u32 val; + +if (test_bit (offset, gpio->input_only)) +return GPIO_LINE_DIRECTION_IN ; + + reg = offset <32 ?GPIO_EN0_OFFSET :GPIO_EN1_OFFSET ; + +regmap_read (gpio->regmap, reg, &val); +if (val &BIT (offset %32 )) +return GPIO_LINE_DIRECTION_IN ; + +return GPIO_LINE_DIRECTION_OUT ; +} + +static int tc956x_gpio_direction_input (struct gpio_chip *gc, +unsigned int offset) +{ +u32 reg = offset <32 ?GPIO_EN0_OFFSET :GPIO_EN1_OFFSET ; +struct tc956x_gpio *gpio =gpiochip_get_data (gc); +u32 mask =BIT (offset %32 ); + +return regmap_update_bits (gpio->regmap, reg, mask, mask); +} + +static int tc956x_gpio_direction_output (struct gpio_chip *gc, +unsigned int offset,int value) +{ +struct tc956x_gpio *gpio =gpiochip_get_data (gc); +u32 vreg; +u32 dreg; +u32 mask; + +if (test_bit (offset, gpio->input_only)) +return -EINVAL ; + +if (offset <32 ) { + vreg =GPIO_OUT0_OFFSET ; + dreg =GPIO_EN0_OFFSET ; + }else { + vreg =GPIO_OUT1_OFFSET ; + dreg =GPIO_EN1_OFFSET ; + } + mask =BIT (offset %32 ); + +/* Set output value first, then direction */ +regmap_update_bits (gpio->regmap, vreg, mask, value ? mask :0 ); + +return regmap_update_bits (gpio->regmap, dreg, mask,0 ); +} + +static int tc956x_gpio_get (struct gpio_chip *gc,unsigned int offset) +{ +u32 reg = offset <32 ?GPIO_IN0_OFFSET :GPIO_IN1_OFFSET ; +struct tc956x_gpio *gpio =gpiochip_get_data (gc); +u32 val; + +regmap_read (gpio->regmap, reg, &val); + +return val &BIT (offset %32 ) ?1 :0 ; +} + +static int tc956x_gpio_set (struct gpio_chip *gc,unsigned int offset,int value) +{ +u32 reg = offset <32 ?GPIO_OUT0_OFFSET :GPIO_OUT1_OFFSET ; +struct tc956x_gpio *gpio =gpiochip_get_data (gc); +u32 mask =BIT (offset %32 ); + +return regmap_update_bits (gpio->regmap, reg, mask, value ? mask :0 ); +} + +static int tc956x_gpio_init_valid_mask (struct gpio_chip *gc, +unsigned long *valid_mask, +unsigned int ngpios) +{ +/* +* GPIOs 2 and 3 are used by the PCI power control driver, and +* we don't allow them to be used. GPIOs 20 and 21 are reserved +* (and not usable). +*/ +bitmap_fill (valid_mask, ngpios); +bitmap_clear (valid_mask,2 ,2 ); +bitmap_clear (valid_mask,20 ,2 ); + +return 0 ; +} + +static int tc956x_gpio_probe (struct auxiliary_device *adev, +const struct auxiliary_device_id *id) +{ +struct device *dev = &adev->dev; +struct tc956x_gpio *gpio; +struct gpio_chip *gc; +
Quoted 8 lines
drivers/gpio/gpio-tc956x.c line 159
Quoted 6 lines
drivers/gpio/gpio-tc956x.c new file +6
-0+if (!dev->platform_data) +return -EINVAL ; + + gpio =devm_kzalloc (dev,sizeof (*gpio),GFP_KERNEL ); +if (!gpio) +return -ENOMEM ;Add newline.
I will add a newline here.
Quoted 7 lines
drivers/gpio/gpio-tc956x.c line 160
Quoted 2 lines
drivers/gpio/gpio-tc956x.c new file +1
-0+ gpio->regmap = dev->platform_data;It's not clear whether this is an mmio regmap or a slow-bus one that can fail. In the code above you're checking the return values of regmap operations quite inconsistently. Could you please verify if you need it and either always check them or not at all?
You're right. I'm returning the result of regmap_update_bits() from two callback functions. But yes, this is an MMIO regmap.
I will return 0 and ignore the return value of regmap_update_bits() in those spots, and will add some comments that make it clear that this is an MMIO regmap.
Quoted 16 lines
Quoted 16 lines
drivers/gpio/gpio-tc956x.c new file +16
-0+ +/* Mark GPIOs 22, 23, 24, 27, 28, 31, and 34 as input only */ +bitmap_set (gpio->input_only,22 ,3 ); +bitmap_set (gpio->input_only,27 ,2 ); +set_bit (31 , gpio->input_only); +set_bit (34 , gpio->input_only); + + gc = &gpio->chip; + + gc->label =DRIVER_NAME ; + gc->parent = dev->parent; + + gc->get_direction = tc956x_gpio_get_direction; + gc->direction_input = tc956x_gpio_direction_input; + gc->direction_output = tc956x_gpio_direction_output; + gc->get = tc956x_gpio_get;
Quoted 8 lines
drivers/gpio/gpio-tc956x.c line 182
Quoted 6 lines
drivers/gpio/gpio-tc956x.c new file +6
-0+ gc->set = tc956x_gpio_set; + gc->init_valid_mask = tc956x_gpio_init_valid_mask; + + gc->base =-1 ; + gc->ngpio =TC956X_GPIO_COUNT ; + gc->can_sleep = false;This makes me think this is an MMIO regmap after all.
You are correct.
Quoted 5 lines
drivers/gpio/gpio-tc956x.c line 184
Quoted 3 lines
drivers/gpio/gpio-tc956x.c new file +2
-0+ +dev_set_drvdata (dev, gpio);There's no corresponding
dev_get_drvdata().
I hadn't noticed that. We're only using the GPIO chip data field (gc->gpiodev->data) instead. I'll drop this call.
Quoted 23 lines
Quoted 23 lines
drivers/gpio/gpio-tc956x.c new file +23
-0+ +return devm_gpiochip_add_data (dev, gc, gpio); +} + +static const struct auxiliary_device_id tc956x_gpio_ids[] = { + { .name ="tc956x_pci.tc9564-gpio" , }, + { } +}; +MODULE_DEVICE_TABLE (auxiliary, tc956x_gpio_ids); + +static struct auxiliary_driver tc956x_gpio_driver = { + .name =DRIVER_NAME , + .probe = tc956x_gpio_probe, + .id_table = tc956x_gpio_ids, + .driver = { + .name =DRIVER_NAME , + .owner =THIS_MODULE , + .probe_type =PROBE_PREFER_ASYNCHRONOUS , + }, +}; +module_auxiliary_driver (tc956x_gpio_driver); + +MODULE_DESCRIPTION ("Toshiba TC956X PCIe GPIO Driver" );
Quoted 8 lines
Quoted 6 lines
drivers/gpio/gpio-tc956x.c new file +2
-1+MODULE_LICENSE ("GPL" ); +MODULE_ALIAS ("auxiliary:" DRIVER_NAME ); --2.51.0
There are a few minor issues but overall looks good!
Thank you very much for the review Bartosz. I'll implement all of your suggestions in the next version.
-Alex
Quoted 2 lines
Bart
Linus Walleij
maintainerRe: [PATCH net-next 09/12] gpio: tc956x: add TC956x/QPS615 support
In reply to Alex ElderHi Alex,
thanks for your patch!
Quoted 10 lines · Alex Elder
Toshiba TC956x is an Ethernet-AVB/TSN bridge and is essentially a small and highly-specialized SoC. TC956x includes a GPIO block that can be accessed, alongside several other peripherals, via two PCIe endpoint functions. The PCIe function driver creates an auxiliary device for the GPIO block, and that device gets bound to this auxiliary device driver.
Co-developed-by Daniel Thompson <[email protected]>Signed-off-by Daniel Thompson <[email protected]>Signed-off-by Alex Elder <[email protected]>
(...)
drivers/gpio/Kconfig config GPIO_TC3589X · line 1652
Quoted 4 lines
drivers/gpio/Kconfig +4
-0+config GPIO_TC956X + tristate "Toshiba TC956X GPIO support" + depends on TOSHIBA_TC956X_PCI + default m if TOSHIBA_TC956X_PCI
I think this driver can
select GPIO_REGMAP
drivers/gpio/gpio-tc956x.c line 30
Quoted 6 lines
drivers/gpio/gpio-tc956x.c new file +6
-0+#include <linux/auxiliary_bus.h> +#include <linux/dev_printk.h> +#include <linux/gpio/driver.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/regmap.h>
#include <linux/gpio/regmap.h>
Quoted 1 line
+#define
TC956X_GPIO_COUNT37 /* Number of GPIOs (20-21 reserved) */
I would just do 64 and flag > 37 as invalid.
Quoted 8 lines
drivers/gpio/gpio-tc956x.c new file +8
-0+/* +* struct tc956x_gpio - Information related to the embedded GPIO controller +* @chip: GPIO chip structure +* @regmap: MMIO register map for SFR GPIO region access +* @input_only: Bitmap indicating which GPIOs are input-only +*/ +struct tc956x_gpio { +struct gpio_chip chip;
drivers/gpio/gpio-tc956x.c line 122
Quoted 10 lines
drivers/gpio/gpio-tc956x.c new file +9
-0+struct regmap *regmap; +DECLARE_BITMAP (input_only,TC956X_GPIO_COUNT ); +static int tc956x_gpio_get_direction(struct gpio_chip *gc, unsigned int offset) +static int tc956x_gpio_direction_input(struct gpio_chip *gc, + unsigned int offset) +static int tc956x_gpio_direction_output(struct gpio_chip *gc, + unsigned int offset, int value) +static int tc956x_gpio_get(struct gpio_chip *gc, unsigned int offset) +static int tc956x_gpio_set(struct gpio_chip *gc, unsigned int offset, int value)
REGMAP_GPIO can handle all of this for you with the right parameterization, study the drivers using this already such as those that appear when you type
git grep 'gpio\/regmap\.h'
Quoted 5 lines
drivers/gpio/gpio-tc956x.c new file +5
-0+static int tc956x_gpio_init_valid_mask (struct gpio_chip *gc, +unsigned long *valid_mask, +unsigned int ngpios) +{ +/*
drivers/gpio/gpio-tc956x.c line 145
Quoted 10 lines
drivers/gpio/gpio-tc956x.c new file +10
-0+* GPIOs 2 and 3 are used by the PCI power control driver, and +* we don't allow them to be used. GPIOs 20 and 21 are reserved +* (and not usable). +*/ +bitmap_fill (valid_mask, ngpios); +bitmap_clear (valid_mask,2 ,2 ); +bitmap_clear (valid_mask,20 ,2 ); + +return 0 ; +}
That's good use of this facility.
I would say the chip has 64 lines and justbitmap_clear(valid_mask, 37, 64 - 37);
but that's your pick. This probably works too.
drivers/gpio/gpio-tc956x.c line 166
Quoted 5 lines
drivers/gpio/gpio-tc956x.c new file +5
-0+/* Mark GPIOs 22, 23, 24, 27, 28, 31, and 34 as input only */ +bitmap_set (gpio->input_only,22 ,3 ); +bitmap_set (gpio->input_only,27 ,2 ); +set_bit (31 , gpio->input_only); +set_bit (34 , gpio->input_only);
regmap-gpio can't currently handle selective input-only or output-only lines, but we can
very easily make it.
So I sent a patch for that (now in your inbox).
Check if this fixed_direction_sparse bitmap will do the trick for you and provide Tested-by if it does, thanks!
Yours,
Linus Walleij
Re: [PATCH net-next 09/12] gpio: tc956x: add TC956x/QPS615 support
Quoted 3 lines · Linus Walleij
Hi Alex,
thanks for your patch!
Thank you for your excellent feedback. I will plan to use regmap-gpio (already suggested strongly by Andrew Lunn) and that will be included in the next version of the series. Once I've done this and tried your other patch I'll provide a Tested-by for it.
-Alex
Quoted 101 lines · Alex Elder
Quoted 11 lines
Toshiba TC956x is an Ethernet-AVB/TSN bridge and is essentially a small and highly-specialized SoC. TC956x includes a GPIO block that can be accessed, alongside several other peripherals, via two PCIe endpoint functions. The PCIe function driver creates an auxiliary device for the GPIO block, and that device gets bound to this auxiliary device driver.
Co-developed-by Daniel Thompson <[email protected]>Signed-off-by Daniel Thompson <[email protected]>Signed-off-by Alex Elder <[email protected]>(...)
drivers/gpio/Kconfig config GPIO_TC3589X · line 1652
Quoted 4 lines
drivers/gpio/Kconfig +4
-0+config GPIO_TC956X + tristate "Toshiba TC956X GPIO support" + depends on TOSHIBA_TC956X_PCI + default m if TOSHIBA_TC956X_PCII think this driver can
select
GPIO_REGMAPdrivers/gpio/gpio-tc956x.c line 30
Quoted 6 lines
drivers/gpio/gpio-tc956x.c new file +6
-0+#include <linux/auxiliary_bus.h> +#include <linux/dev_printk.h> +#include <linux/gpio/driver.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> #include <
linux/gpio/regmap.h>Quoted 1 line
+#define
TC956X_GPIO_COUNT37 /* Number of GPIOs (20-21 reserved) */I would just do 64 and flag > 37 as invalid.
Quoted 8 lines
drivers/gpio/gpio-tc956x.c new file +8
-0+/* +* struct tc956x_gpio - Information related to the embedded GPIO controller +* @chip: GPIO chip structure +* @regmap: MMIO register map for SFR GPIO region access +* @input_only: Bitmap indicating which GPIOs are input-only +*/ +struct tc956x_gpio { +struct gpio_chip chip;drivers/gpio/gpio-tc956x.c line 122
Quoted 10 lines
drivers/gpio/gpio-tc956x.c new file +9
-0+struct regmap *regmap; +DECLARE_BITMAP (input_only,TC956X_GPIO_COUNT ); +static int tc956x_gpio_get_direction(struct gpio_chip *gc, unsigned int offset) +static int tc956x_gpio_direction_input(struct gpio_chip *gc, + unsigned int offset) +static int tc956x_gpio_direction_output(struct gpio_chip *gc, + unsigned int offset, int value) +static int tc956x_gpio_get(struct gpio_chip *gc, unsigned int offset) +static int tc956x_gpio_set(struct gpio_chip *gc, unsigned int offset, int value)
REGMAP_GPIOcan handle all of this for you with the right parameterization, study the drivers using this already such as those that appear when you type
git grep 'gpio\/regmap\.h'Quoted 5 lines
drivers/gpio/gpio-tc956x.c new file +5
-0+static int tc956x_gpio_init_valid_mask (struct gpio_chip *gc, +unsigned long *valid_mask, +unsigned int ngpios) +{ +/* drivers/gpio/gpio-tc956x.c line 145
Quoted 10 lines
drivers/gpio/gpio-tc956x.c new file +10
-0+* GPIOs 2 and 3 are used by the PCI power control driver, and +* we don't allow them to be used. GPIOs 20 and 21 are reserved +* (and not usable). +*/ +bitmap_fill (valid_mask, ngpios); +bitmap_clear (valid_mask,2 ,2 ); +bitmap_clear (valid_mask,20 ,2 ); + +return 0 ; +}That's good use of this facility.
I would say the chip has 64 lines and just
bitmap_clear(valid_mask, 37, 64 - 37);
but that's your pick. This probably works too.drivers/gpio/gpio-tc956x.c line 166
Quoted 5 lines
drivers/gpio/gpio-tc956x.c new file +5
-0+/* Mark GPIOs 22, 23, 24, 27, 28, 31, and 34 as input only */ +bitmap_set (gpio->input_only,22 ,3 ); +bitmap_set (gpio->input_only,27 ,2 ); +set_bit (31 , gpio->input_only); +set_bit (34 , gpio->input_only);regmap-gpio can't currently handle selective input-only or output-only lines, but we can
very easily make it.So I sent a patch for that (now in your inbox).
Check if this
fixed_direction_sparsebitmap will do the trick for you and provide Tested-by if it does, thanks!Yours,
Linus Walleij
PATCH 10/12 net: stmmac: tc956x: add TC956x/QPS615 support
In reply to Alex ElderFrom: Daniel Thompson <[email protected]>
Toshiba TC956x is an Ethernet AVB/TSN bridge and is essentially a small and highly-specialized SoC. TC956x includes an "eMAC" subsystem that can be accessed, along with several other peripherals, via two PCIe endpoint functions. There is a main driver for the endpoint that decomposes things and creates auxiliary bus devices to model the SoC.
The eMAC consists of a Designware XGMAC, XPCS and PMA. Each eMAC is supported by an MSIGEN that bridges TC956x level interrupts to PCIe MSIs.
Add a driver for the eMAC/MSIGEN combination.
--- drivers/net/ethernet/stmicro/stmmac/Kconfig | 13 + drivers/net/ethernet/stmicro/stmmac/Makefile | 2 + .../ethernet/stmicro/stmmac/dwmac-tc956x.c | 791 ++++++++++++++++++ include/soc/toshiba/tc956x-dwmac.h | 84 ++ 4 files changed, 890 insertions(+) create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c create mode 100644 include/soc/toshiba/tc956x-dwmac.h
drivers/net/ethernet/stmicro/stmmac/Kconfig +13 -0
@@ -404,6 +404,19 @@ config DWMAC_MOTORCOMM This enables glue driver for Motorcomm DWMAC-based PCI Ethernet controllers. Currently only YT6801 is supported. +config DWMAC_TC956X + tristate "Toshiba TC956X DWMAC support" + depends on PCI + depends on COMMON_CLK + depends on TOSHIBA_TC956X_PCI + default m if TOSHIBA_TC956X_PCI + help + This selects the Toshiba TC956X (and Qualcomm QPS615) support in the + stmmac driver. + + This provides support for the ethernet controllers found on these + devices. + config STMMAC_PCI tristate "STMMAC PCI bus support" depends on PCI
drivers/net/ethernet/stmicro/stmmac/Makefile +2 -0
@@ -51,4 +51,6 @@ 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_TC956X_PCI) += tc956x-pci.o +obj-$(CONFIG_DWMAC_TC956X) += dwmac-tc956x.o stmmac-pci-objs:= stmmac_pci.o
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +791 -0
791 lines not on this page · raw message
include/soc/toshiba/tc956x-dwmac.h new file +84 -0
84 lines not on this page · raw message
Signature · 1 line
2.51.0
Andrew Lunn
maintainerRe: [PATCH net-next 10/12] net: stmmac: tc956x: add TC956x/QPS615 support
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 135
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +4
-0+static struct tc956x_mac_speed mac_speed[] = { + {PHY_INTERFACE_MODE_2500BASEX ,SPEED_2500 ,SP_SEL_SGMII_2500M , }, + {PHY_INTERFACE_MODE_SGMII ,SPEED_2500 ,SP_SEL_SGMII_2500M , }, + {PHY_INTERFACE_MODE_SGMII ,SPEED_1000 ,SP_SEL_SGMII_1000M , },
That looks odd. Some vendors implemented 2500BaseX using SGMII overclocked. But that is not strictly 2500BaseX. Having the 2500BASEX entry suggests you have real 2500BASEX, so why have an SGMII entry with SPEED_2500?
Quoted 1 line
+/* We have one IRQ chip instance with 25 IRQs in its domain */
One per MAC, or one overall?
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 221
Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +7
-0+static struct irq_domain * +tc956x_msigen_irq_domain_instantiate (struct tc956x_data *td) +{ +struct irq_domain_chip_generic_info dgc_info; +struct irq_domain_info info; + + dgc_info.name ="tc956x-msigen" ;
If it is one per MAC, maybe this name should indicate which instance of the MAC this is.
Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +5
-0+static int tc956x_mac_setup (void *apriv,struct mac_device_info *mac) +{ +struct stmmac_priv *priv = apriv; +struct stmmac_desc_ops *desc; +struct stmmac_dma_ops *dma;
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 459
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +10
-0+struct tc956x_data *td; + + td = priv->plat->bsp_priv; + +/* dwxgmac301_dma_ops needs extending to provide DMA address translation */ + dma = &td->dma; + *dma = dwxgmac301_dma_ops; + dma->init_rx_chan = tc956x_dma_init_rx_chan; + dma->init_tx_chan = tc956x_dma_init_tx_chan; + mac->dma = dma;
I could be reading this wrong....
dma points to the global dwxgmac301_dma_ops, which you added a few patches back.
You then modify it, changing two values in it.
Doesn't that break any other dwxgmac301 in the system? Shouldn't you be making a copy of the global structure, and then making modifications to your copy? mac->dma then points to your copy?
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 466
Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +6
-0+/* dwxgmac210_desc_ops also needs extending for the same reason */ + desc = &td->desc; + *desc = dwxgmac210_desc_ops; + desc->set_addr = tc956x_desc_set_addr; + desc->set_sec_addr = tc956x_desc_set_sec_addr; + mac->desc = desc;
And the same problem here?
Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +7
-0+/* Called by tc956x_dwmac_probe(); return errors with dev_err_probe() */ +static int tc956x_dwmac_parse_dt (struct tc956x_data *td) +{ +struct device_node *mdio_node; +struct device *dev = td->dev; +struct device_node *np; +
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 547
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +10
-0+ np =dev_of_node (dev); +if (!np) +return dev_err_probe (dev, -EINVAL ,"no devicetree node\n" ); + +/* Find the MDIO bus */ +for_each_child_of_node (np, mdio_node) { +if (of_device_is_compatible (mdio_node, +"snps,dwmac-mdio" )) +break ; + }
It looks like if you put the ethernet properties into an ethernet node in DT, this might go away? Or at least allow you to use stmmac_of_get_mdio().
Andrew
Re: [PATCH net-next 10/12] net: stmmac: tc956x: add TC956x/QPS615 support
Quoted 9 lines · Andrew Lunn
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 135
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +4
-0+static struct tc956x_mac_speed mac_speed[] = { + {PHY_INTERFACE_MODE_2500BASEX ,SPEED_2500 ,SP_SEL_SGMII_2500M , }, + {PHY_INTERFACE_MODE_SGMII ,SPEED_2500 ,SP_SEL_SGMII_2500M , }, + {PHY_INTERFACE_MODE_SGMII ,SPEED_1000 ,SP_SEL_SGMII_1000M , },That looks odd. Some vendors implemented 2500BaseX using SGMII overclocked. But that is not strictly 2500BaseX. Having the 2500BASEX entry suggests you have real 2500BASEX, so why have an SGMII entry with
SPEED_2500?
This is a consequence of the code that uses this lookup table being called both during initialization and from the fix_mac_speed() callback.
During initialization we only have the value in plat->phy_interface to go on so we run the lookup table using plat->phy_interface (which is typically PHY_INTERFACE_MODE_SGMII) and with the maximum permitted speed.
I haven't got detailed enough notes to allow me to double check but I think there were problems completing the initial MAC reset if we didn't write something sensible to the hardware during initialization.
During fix_max_speed() we get told to adopt 2500base-x. Reviewing the code I can see we don't propagate that and just use plat->phy_interface for fix_mac_speed(). I will fix the code to that the requested interface propagates properly to the lookup table but I think we would still rely on the SGMII entry to get sane initial values to write to the hardware.
Quoted 3 lines
Quoted 1 line
+/* We have one IRQ chip instance with 25 IRQs in its domain */
One per MAC, or one overall?
One per MAC.
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 221
Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +7
-0+static struct irq_domain * +tc956x_msigen_irq_domain_instantiate (struct tc956x_data *td) +{ +struct irq_domain_chip_generic_info dgc_info; +struct irq_domain_info info; + + dgc_info.name ="tc956x-msigen" ;If it is one per MAC, maybe this name should indicate which instance of the MAC this is.
Will do.
Quoted 18 lines
Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +5
-0+static int tc956x_mac_setup (void *apriv,struct mac_device_info *mac) +{ +struct stmmac_priv *priv = apriv; +struct stmmac_desc_ops *desc; +struct stmmac_dma_ops *dma;drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 459
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +10
-0+struct tc956x_data *td; + + td = priv->plat->bsp_priv; + +/* dwxgmac301_dma_ops needs extending to provide DMA address translation */ + dma = &td->dma; + *dma = dwxgmac301_dma_ops; + dma->init_rx_chan = tc956x_dma_init_rx_chan; + dma->init_tx_chan = tc956x_dma_init_tx_chan; + mac->dma = dma;I could be reading this wrong....
Quoted 8 lines
dma points to the global
dwxgmac301_dma_ops, which you added a few patches back.You then modify it, changing two values in it.
Doesn't that break any other dwxgmac301 in the system? Shouldn't you be making a copy of the global structure, and then making modifications to your copy?
mac->dmathen points to your copy?
That's exactly what this code does.
*dma = dwxgmac301_dma_ops is a structure copy, we never take a pointer to dwxgmac301_dma_ops (and if we did, dwxgmac301_dma_ops is const so I think we'd get a kernel oops if we tried to write to rodata).
Would to code be easier to read if we dropped the local dma variable since that would make it clearer that td->dma is not a pointer? More like:
+ /* dwxgmac301_dma_ops needs extending to provide DMA address translation */ + td->dma = dwxgmac301_dma_ops; + td->dma.init_rx_chan = tc956x_dma_init_rx_chan; + td->dma.init_tx_chan = tc956x_dma_init_tx_chan; + mac->dma = &dma;
Quoted 23 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 466
Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +6
-0+/* dwxgmac210_desc_ops also needs extending for the same reason */ + desc = &td->desc; + *desc = dwxgmac210_desc_ops; + desc->set_addr = tc956x_desc_set_addr; + desc->set_sec_addr = tc956x_desc_set_sec_addr; + mac->desc = desc;And the same problem here?
Quoted 13 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +13
-0+/* Called by tc956x_dwmac_probe(); return errors with dev_err_probe() */ +static int tc956x_dwmac_parse_dt (struct tc956x_data *td) +{ +struct device_node *mdio_node; +struct device *dev = td->dev; +struct device_node *np; + + np =dev_of_node (dev); +if (!np) +return dev_err_probe (dev, -EINVAL ,"no devicetree node\n" ); + +/* Find the MDIO bus */ +for_each_child_of_node (np, mdio_node) {
Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 547
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +4
-0+if (of_device_is_compatible (mdio_node, +"snps,dwmac-mdio" )) +break ; + }It looks like if you put the ethernet properties into an ethernet node in DT, this might go away? Or at least allow you to use
stmmac_of_get_mdio().
Alex has started looking into adding an ethernet node.
Daniel.
Andrew Lunn
maintainerRe: [PATCH net-next 10/12] net: stmmac: tc956x: add TC956x/QPS615 support
Quoted 11 lines · Daniel Thompson
Quoted 9 lines · Andrew Lunn
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 135
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +4
-0+static struct tc956x_mac_speed mac_speed[] = { + {PHY_INTERFACE_MODE_2500BASEX ,SPEED_2500 ,SP_SEL_SGMII_2500M , }, + {PHY_INTERFACE_MODE_SGMII ,SPEED_2500 ,SP_SEL_SGMII_2500M , }, + {PHY_INTERFACE_MODE_SGMII ,SPEED_1000 ,SP_SEL_SGMII_1000M , },That looks odd. Some vendors implemented 2500BaseX using SGMII overclocked. But that is not strictly 2500BaseX. Having the 2500BASEX entry suggests you have real 2500BASEX, so why have an SGMII entry with
SPEED_2500?
Quoted 7 lines
This is a consequence of the code that uses this lookup table being called both during initialization and from the
fix_mac_speed()callback.During initialization we only have the value in
plat->phy_interfaceto go on so we run the lookup table usingplat->phy_interface(which is typicallyPHY_INTERFACE_MODE_SGMII) and with the maximum permitted speed.
Something sounds wrong here. SGMII only supports 10/100/1G. You should never be asked to do SGMII at 2500. It should ask for 2500BaseX.
Quoted 10 lines
I haven't got detailed enough notes to allow me to double check but I think there were problems completing the initial MAC reset if we didn't write something sensible to the hardware during initialization.
During
fix_max_speed()we get told to adopt 2500base-x. Reviewing the code I can see we don't propagate that and just useplat->phy_interfaceforfix_mac_speed(). I will fix the code to that the requested interface propagates properly to the lookup table but I think we would still rely on the SGMII entry to get sane initial values to write to the hardware.
Getting sane values into the hardware is good, but 2500 SGMII is not sane :-(
Quoted 14 lines
Quoted 3 lines
Doesn't that break any other dwxgmac301 in the system? Shouldn't you be making a copy of the global structure, and then making modifications to your copy?
mac->dmathen points to your copy?That's exactly what this code does.
*dma = dwxgmac301_dma_opsis a structure copy, we never take a pointer todwxgmac301_dma_ops(and if we did,dwxgmac301_dma_opsis const so I think we'd get a kernel oops if we tried to write to rodata).Would to code be easier to read if we dropped the local
dmavariable since that would make it clearer thattd->dmais not a pointer? More like:
Review
Quoted 5 lines
(quoted diff) +5
-0+ /* dwxgmac301_dma_ops needs extending to provide DMA address translation */ + td->dma = dwxgmac301_dma_ops; + td->dma.init_rx_chan = tc956x_dma_init_rx_chan; + td->dma.init_tx_chan = tc956x_dma_init_tx_chan; + mac->dma = &dma;
Yes, that is better. I also think it is partially my problem. You don't often see structure assignments, just pointer assignments. So i'm somewhat blind to them.
Andrew
Re: [PATCH net-next 10/12] net: stmmac: tc956x: add TC956x/QPS615 support
Quoted 15 lines · Andrew Lunn
Quoted 14 lines · Daniel Thompson
Quoted 9 lines · Andrew Lunn
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 135
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +4
-0+static struct tc956x_mac_speed mac_speed[] = { + {PHY_INTERFACE_MODE_2500BASEX ,SPEED_2500 ,SP_SEL_SGMII_2500M , }, + {PHY_INTERFACE_MODE_SGMII ,SPEED_2500 ,SP_SEL_SGMII_2500M , }, + {PHY_INTERFACE_MODE_SGMII ,SPEED_1000 ,SP_SEL_SGMII_1000M , },That looks odd. Some vendors implemented 2500BaseX using SGMII overclocked. But that is not strictly 2500BaseX. Having the 2500BASEX entry suggests you have real 2500BASEX, so why have an SGMII entry with
SPEED_2500?This is a consequence of the code that uses this lookup table being called both during initialization and from the
fix_mac_speed()callback.
Quoted 7 lines
Quoted 4 lines
During initialization we only have the value in
plat->phy_interfaceto go on so we run the lookup table usingplat->phy_interface(which is typicallyPHY_INTERFACE_MODE_SGMII) and with the maximum permitted speed.Something sounds wrong here. SGMII only supports 10/100/1G. You should never be asked to do SGMII at 2500. It should ask for 2500BaseX.
We weren't being asked. It was just an internal driver trick to common up some code paths.
However I did a few tests and the internal driver trick doesn't actually do much we can't achieve a different way. With that changed I can (and will) remove the PHY_INTERFACE_MODE_SGMII/SPEED_2500 entry from the table.
Quoted 11 lines
Quoted 10 lines
I haven't got detailed enough notes to allow me to double check but I think there were problems completing the initial MAC reset if we didn't write something sensible to the hardware during initialization.
During
fix_max_speed()we get told to adopt 2500base-x. Reviewing the code I can see we don't propagate that and just useplat->phy_interfaceforfix_mac_speed(). I will fix the code to that the requested interface propagates properly to the lookup table but I think we would still rely on the SGMII entry to get sane initial values to write to the hardware.
Quoted 2 lines
Getting sane values into the hardware is good, but 2500 SGMII is not sane :-(
BTW if you are bothered by SP_SEL_SGMII_2500M, that name comes directly from the TRM and I'd prefer to keep it if I can. The enumerated value we have to write into the SP_SEL for 2500base-X is "SGMII 2500M".
Daniel.
Andrew Lunn
maintainerRe: [PATCH net-next 10/12] net: stmmac: tc956x: add TC956x/QPS615 support
Quoted 3 lines
BTW if you are bothered by
SP_SEL_SGMII_2500M, that name comes directly from the TRM and I'd prefer to keep it if I can. The enumerated value we have to write into theSP_SELfor 2500base-X is "SGMII 2500M".
We try to avoid anything to do with SGMII and 2500 because it is technically wrong. Cisco never defined SGMII for 2500, it is something silicon vendors have made up, without any foundation in any standardisation. We much prefer to refer to it as 2500BaseX with broken signalling, which is a much more accurate description.
The TRM is also not a public document. If it was, i could see some value in keeping with the naming, but since ~0 developers have the document, this is less useful.
Andrew
Re: [PATCH net-next 10/12] net: stmmac: tc956x: add TC956x/QPS615 support
Quoted 10 lines · Andrew Lunn
Quoted 3 lines
BTW if you are bothered by
SP_SEL_SGMII_2500M, that name comes directly from the TRM and I'd prefer to keep it if I can. The enumerated value we have to write into theSP_SELfor 2500base-X is "SGMII 2500M".We try to avoid anything to do with SGMII and 2500 because it is technically wrong. Cisco never defined SGMII for 2500, it is something silicon vendors have made up, without any foundation in any standardisation. We much prefer to refer to it as 2500BaseX with broken signalling, which is a much more accurate description.
Quoted 3 lines
The TRM is also not a public document. If it was, i could see some value in keeping with the naming, but since ~0 developers have the document, this is less useful.
This is a pretty obscure register buried on some of the TC956x glue logic (e.g. it's not part of the DWMAC's register set). I take the view that if someone is debugging the hardware interactions deeply enough to care what this is called then the odds of them having access to the TRM are actually pretty good.
However having a different name would be only a minor irritant to the poor soul trying to debug the thing! I'll rename to SP_SEL_2500BASEX in the next rev of the patchset.
Daniel.
[email protected]
AI reviewRe: [PATCH net-next 10/12] net: stmmac: tc956x: add TC956x/QPS615 support
In reply to Alex ElderThank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider: - [High] The RX queue IRQ mapping loop incorrectly checks `res->tx_irq[i]` instead of `res->rx_irq[i]` for…
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] The RX queue IRQ mapping loop incorrectly checks res->tx_irq[i] instead of res->rx_irq[i] for failures.
- [High] DMA address truncation on 32-bit architectures leads to corrupted hardware DMA programming.
- [High] Mapped IRQs are never disposed, leaking descriptors and causing a WARN on device removal.
- [Medium] Hardware clocks and resets are leaked on probe() and mac_enable() error paths.
- [Medium] OF node reference leak for mdio_node on probe error paths and device removal.
--
commit e138cc3787ee995063c093b9ca94f6ca453bbcda
Author: Daniel Thompson <[email protected]>
Subject: net: stmmac: tc956x: add TC956x/QPS615 support
This commit adds support for the Toshiba TC956x eMAC/MSIGEN combination, implemented as a driver for an auxiliary bus device that bridges TC956x level interrupts to PCIe MSIs.
Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +0
-0
[ ... ]
Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +7
-0+static int tc956x_mac_enable (struct tc956x_data *td) +{ +const struct tc956x_chip *chip = td->auxbus_data->chip; +struct plat_stmmacenet_data *plat = td->plat; +u32 id = td->auxbus_data->mac_id; +int ret; +
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 346
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +10
-0+tc956x_clock_enable (chip, id,MAC_CLOCK_TX ); +tc956x_clock_enable (chip, id,MAC_CLOCK_RX ); +tc956x_clock_enable (chip, id,MAC_CLOCK_ALL ); +if (id) +tc956x_clock_enable (chip, id,MAC_CLOCK_RMII ); + +/* Set the speed related registers */ + ret =tc956x_mac_configure (td, plat->max_speed); +if (ret) +return ret;
If tc956x_mac_configure() fails, will this leak the clocks that were just enabled since tc956x_clock_disable() is not called?
[ ... ]
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 394
Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +6
-0+static void tc956x_dma_init_rx_chan (struct stmmac_priv *priv, +void __iomem *ioaddr, +struct stmmac_dma_cfg *dma_cfg, +dma_addr_t phy,u32 chan) +{ +dma_addr_t translated = phy +TC956X_SLV00_SRC_ADDR ;
If dma_addr_t is 32-bit on the target architecture, will adding TC956X_SLV00_SRC_ADDR (0x1000000000ULL) to phy truncate the result and cause the upper 32 bits to be 0?
Should translated be explicitly typed as u64? The same pattern appears in tc956x_dma_init_tx_chan(), tc956x_desc_set_addr(), and tc956x_desc_set_sec_addr().
[ ... ]
Quoted 15 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +15
-0+static int tc956x_dwmac_parse_dt (struct tc956x_data *td) +{ +struct device_node *mdio_node; +struct device *dev = td->dev; +struct device_node *np; + + np =dev_of_node (dev); +if (!np) +return dev_err_probe (dev, -EINVAL ,"no devicetree node\n" ); + +/* Find the MDIO bus */ +for_each_child_of_node (np, mdio_node) { +if (of_device_is_compatible (mdio_node, +"snps,dwmac-mdio" )) +break ;
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 556
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +10
-0+ } + +/* Pass the MDIO bus (if there is one) to the core driver */ +if (mdio_node) { + td->plat->mdio_node = mdio_node; + td->plat->mdio_bus_data->needs_reset = true; + } + +return 0 ; +}
Since the loop breaks early when a compatible node is found, does this leak the reference to mdio_node?
Is a call to of_node_put() needed in tc956x_dwmac_remove() and on probe error paths?
[ ... ]
Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +11
-0+static int tc956x_stmmac_resources_init (struct tc956x_data *td, +struct stmmac_resources *res) +{ +struct irq_domain *irq_domain = td->irq_domain; +u32 i; + + res->irq =irq_create_mapping (irq_domain,HWIRQ_EVENT ); +if (!res->irq) +return -EINVAL ; + +for (i =0 ; i < td->plat->tx_queues_to_use; i++) {
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 704
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +10
-0+ res->tx_irq[i] =irq_create_mapping (irq_domain,HWIRQ_TX0 + i); +if (!res->tx_irq[i]) +return -EINVAL ; + } + +for (i =0 ; i < td->plat->rx_queues_to_use; i++) { + res->rx_irq[i] =irq_create_mapping (irq_domain,HWIRQ_RX0 + i); +if (!res->tx_irq[i]) +return -EINVAL ; + }
Should this be checking res->rx_irq[i] instead of res->tx_irq[i]?
If tx_irq[i] was previously set during the TX mapping loop, this check won't catch RX mapping failures and uninitialized IRQs could be left in the resource structure.
[ ... ]
Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +3
-0+static int tc956x_dwmac_probe (struct auxiliary_device *adev, +const struct auxiliary_device_id *id) +{
[ ... ]
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 758
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +10
-0+ ret =tc956x_mac_enable (td); +if (ret) +return dev_err_probe (dev, ret,"failed to enable MAC\n" ); + + ret =stmmac_dvr_probe (dev, td->plat, &res); +if (ret) +return dev_err_probe (dev, ret,"failed stmmac probe\n" ); + +return 0 ; +}
Does this error path need to call tc956x_mac_disable(td) to unwind the hardware state if stmmac_dvr_probe() fails?
[ ... ]
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 769
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +10
-0+static void tc956x_dwmac_remove (struct auxiliary_device *adev) +{ +struct device *dev = &adev->dev; +struct net_device *ndev =dev_get_drvdata (dev); +struct stmmac_priv *priv =netdev_priv (ndev); +struct tc956x_data *td = priv->plat->bsp_priv; + +stmmac_dvr_remove (dev); +tc956x_mac_disable (td); +}
Are the IRQs created by irq_create_mapping() leaking here?
There appear to be no calls to irq_dispose_mapping() on device removal or probe error paths. While IRQ_DOMAIN_FLAG_DESTROY_GC frees the generic chip data, the descriptors might leak and trigger a warning in irq_domain_remove().
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
Re: [PATCH net-next 10/12] net: stmmac: tc956x: add TC956x/QPS615 support
Quoted 6 lines · On 5/2/26 10:56 AM, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] The RX queue IRQ mapping loop incorrectly checksres->tx_irq[i]instead ofres->rx_irq[i]for failures.
- [High] DMA address truncation on 32-bit architectures leads to corrupted hardware DMA programming.
- [High] Mapped IRQs are never disposed, leaking descriptors and causing a WARN on device removal.
- [Medium] Hardware clocks and resets are leaked onprobe()andmac_enable()error paths.
- [Medium] OF node reference leak formdio_nodeon probe error paths and device removal.
All of the reports here are valid, and all will be addressed in the next version of the patch (as described further below).
Quoted 30 lines
--
commit
e138cc3787ee995063c093b9ca94f6ca453bbcda
Author: Daniel Thompson <[email protected]>
Subject: net: stmmac: tc956x: add TC956x/QPS615 supportThis commit adds support for the Toshiba TC956x eMAC/MSIGEN combination, implemented as a driver for an auxiliary bus device that bridges TC956x level interrupts to PCIe MSIs.
Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +0
-0[ ... ]
Quoted 12 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +12
-0+static int tc956x_mac_enable (struct tc956x_data *td) +{ +const struct tc956x_chip *chip = td->auxbus_data->chip; +struct plat_stmmacenet_data *plat = td->plat; +u32 id = td->auxbus_data->mac_id; +int ret; + +tc956x_clock_enable (chip, id,MAC_CLOCK_TX ); +tc956x_clock_enable (chip, id,MAC_CLOCK_RX ); +tc956x_clock_enable (chip, id,MAC_CLOCK_ALL ); +if (id) +tc956x_clock_enable (chip, id,MAC_CLOCK_RMII );
Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 346
Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +5
-0+ +/* Set the speed related registers */ + ret =tc956x_mac_configure (td, plat->max_speed); +if (ret) +return ret;If
tc956x_mac_configure()fails, will this leak the clocks that were just enabled sincetc956x_clock_disable()is not called?
This is a legitimate issue. However in the next version of this patch, the call to tc956x_mac_configure() is no longer necessary. As as a result, the issue will no longer occur, and in fact tc956x_mac_enable() becomes a void function, simplifying callers as well.
Quoted 14 lines
[ ... ]
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 394
Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +6
-0+static void tc956x_dma_init_rx_chan (struct stmmac_priv *priv, +void __iomem *ioaddr, +struct stmmac_dma_cfg *dma_cfg, +dma_addr_t phy,u32 chan) +{ +dma_addr_t translated = phy +TC956X_SLV00_SRC_ADDR ;If
dma_addr_tis 32-bit on the target architecture, will addingTC956X_SLV00_SRC_ADDR(0x1000000000ULL) to phy truncate the result and cause the upper 32 bits to be 0?
Quoted 3 lines
Should translated be explicitly typed as u64? The same pattern appears in
tc956x_dma_init_tx_chan(),tc956x_desc_set_addr(), andtc956x_desc_set_sec_addr().
Here, the translated variable (in all four functions) will be converted to a u64, which avoids the problem even if the size of a dma_addr_t is 32 bits.
Quoted 32 lines
[ ... ]
Quoted 15 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +15
-0+static int tc956x_dwmac_parse_dt (struct tc956x_data *td) +{ +struct device_node *mdio_node; +struct device *dev = td->dev; +struct device_node *np; + + np =dev_of_node (dev); +if (!np) +return dev_err_probe (dev, -EINVAL ,"no devicetree node\n" ); + +/* Find the MDIO bus */ +for_each_child_of_node (np, mdio_node) { +if (of_device_is_compatible (mdio_node, +"snps,dwmac-mdio" )) +break ;drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 556
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +10
-0+ } + +/* Pass the MDIO bus (if there is one) to the core driver */ +if (mdio_node) { + td->plat->mdio_node = mdio_node; + td->plat->mdio_bus_data->needs_reset = true; + } + +return 0 ; +}Since the loop breaks early when a compatible node is found, does this leak the reference to
mdio_node?
Quoted 2 lines
Is a call to
of_node_put()needed intc956x_dwmac_remove()and on probe error paths?
Yes, this did leak the reference to the mdio_node. The next version of this patch addresses this in the caller, dropping the reference on any error, and dropping it also in the driver remove function.
Quoted 18 lines
[ ... ]
Quoted 15 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +15
-0+static int tc956x_stmmac_resources_init (struct tc956x_data *td, +struct stmmac_resources *res) +{ +struct irq_domain *irq_domain = td->irq_domain; +u32 i; + + res->irq =irq_create_mapping (irq_domain,HWIRQ_EVENT ); +if (!res->irq) +return -EINVAL ; + +for (i =0 ; i < td->plat->tx_queues_to_use; i++) { + res->tx_irq[i] =irq_create_mapping (irq_domain,HWIRQ_TX0 + i); +if (!res->tx_irq[i]) +return -EINVAL ; + }
Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 704
Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +6
-0+ +for (i =0 ; i < td->plat->rx_queues_to_use; i++) { + res->rx_irq[i] =irq_create_mapping (irq_domain,HWIRQ_RX0 + i); +if (!res->tx_irq[i]) +return -EINVAL ; + }Should this be checking res->rx_irq[i] instead of res->tx_irq[i]?
Yes, Ayaan mentioned this as well and it has been fixed.
Quoted 13 lines
If tx_irq[i] was previously set during the TX mapping loop, this check won't catch RX mapping failures and uninitialized IRQs could be left in the resource structure.
[ ... ]
Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +3
-0+static int tc956x_dwmac_probe (struct auxiliary_device *adev, +const struct auxiliary_device_id *id) +{[ ... ]
Quoted 13 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 758
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +10
-0+ ret =tc956x_mac_enable (td); +if (ret) +return dev_err_probe (dev, ret,"failed to enable MAC\n" ); + + ret =stmmac_dvr_probe (dev, td->plat, &res); +if (ret) +return dev_err_probe (dev, ret,"failed stmmac probe\n" ); + +return 0 ; +}Does this error path need to call
tc956x_mac_disable(td)to unwind the hardware state ifstmmac_dvr_probe()fails?
Yes, and this will be addressed in the next version of this patch.
Quoted 15 lines
[ ... ]
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 769
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +10
-0+static void tc956x_dwmac_remove (struct auxiliary_device *adev) +{ +struct device *dev = &adev->dev; +struct net_device *ndev =dev_get_drvdata (dev); +struct stmmac_priv *priv =netdev_priv (ndev); +struct tc956x_data *td = priv->plat->bsp_priv; + +stmmac_dvr_remove (dev); +tc956x_mac_disable (td); +}Are the IRQs created by
irq_create_mapping()leaking here?
A new function tc956x_stmmac_resources_exit() will be created to release the mappings created by tc956x_stmmac_resources_init().
-Alex
Quoted 6 lines
There appear to be no calls to
irq_dispose_mapping()on device removal or probe error paths. WhileIRQ_DOMAIN_FLAG_DESTROY_GCfrees the generic chip data, the descriptors might leak and trigger a warning inirq_domain_remove().
Re: [PATCH net-next 10/12] net: stmmac: tc956x: add TC956x/QPS615 support
In reply to Alex ElderHi Alex,
Review
Quoted 2 lines · Alex Elder
(quoted diff) +2
-0+ /* + * TX956x has 8 TX queues but only #0 to #3 work for general IP traffic.
Minor typo in the comment: I think you meant TC956X instead of TX956X?
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 702
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +4
-0+ +for (i =0 ; i < td->plat->rx_queues_to_use; i++) { + res->rx_irq[i] =irq_create_mapping (irq_domain,HWIRQ_RX0 + i); +if (!res->tx_irq[i])
Typo: res->rx_irq instead of res->tx_irq.
PS: I was able to successfully test this series out on a Rb3Gen2 board.
Ayaan
Re: [PATCH net-next 10/12] net: stmmac: tc956x: add TC956x/QPS615 support
Quoted 7 lines · Mohd Ayaan Anwar
Hi Alex,
Review
Quoted 2 lines · Alex Elder
(quoted diff) +2
-0+ /* + * TX956x has 8 TX queues but only #0 to #3 work for general IP traffic.Minor typo in the comment: I think you meant TC956X instead of TX956X?
Yes, I'll fix that.
Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 702
Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +3
-0+for (i =0 ; i < td->plat->rx_queues_to_use; i++) { + res->rx_irq[i] =irq_create_mapping (irq_domain,HWIRQ_RX0 + i); +if (!res->tx_irq[i])Typo:
res->rx_irqinstead ofres->tx_irq.
Wow, that's important... Fortunately we haven't been getting errors.
This will be fixed.
Quoted 1 line
PS: I was able to successfully test this series out on a Rb3Gen2 board.
Great! Thank you.
-Alex
Quoted 1 line
Ayaan
Re: [PATCH net-next 10/12] net: stmmac: tc956x: add TC956x/QPS615 support
In reply to Alex ElderQuoted 31 lines · Alex Elder
From: Daniel Thompson <[email protected]>
Toshiba TC956x is an Ethernet AVB/TSN bridge and is essentially a small and highly-specialized SoC. TC956x includes an "eMAC" subsystem that can be accessed, along with several other peripherals, via two PCIe endpoint functions. There is a main driver for the endpoint that decomposes things and creates auxiliary bus devices to model the SoC.
The eMAC consists of a Designware XGMAC, XPCS and PMA. Each eMAC is supported by an MSIGEN that bridges TC956x level interrupts to PCIe MSIs.
Add a driver for the eMAC/MSIGEN combination.
Co-developed-by Alex Elder <[email protected]>Signed-off-by Alex Elder <[email protected]>Signed-off-by Daniel Thompson <[email protected]>--- drivers/net/ethernet/stmicro/stmmac/Kconfig | 13 + drivers/net/ethernet/stmicro/stmmac/Makefile | 2 + .../ethernet/stmicro/stmmac/dwmac-tc956x.c | 791 ++++++++++++++++++ include/soc/toshiba/tc956x-dwmac.h | 84 ++ 4 files changed, 890 insertions(+)create mode 100644
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.ccreate mode 100644include/soc/toshiba/tc956x-dwmac.hdrivers/net/ethernet/stmicro/stmmac/Kconfig +0
-0
drivers/net/ethernet/stmicro/stmmac/Kconfig config DWMAC_MOTORCOMM · line 412
Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/Kconfig +6
-0@@ -404,6 +404,19 @@ config DWMAC_MOTORCOMM This enables glue driver for Motorcomm DWMAC-based PCI Ethernet controllers. Currently only YT6801 is supported. +config DWMAC_TC956X + tristate "Toshiba TC956X DWMAC support" + depends on PCI + depends on COMMON_CLK + depends on TOSHIBA_TC956X_PCI + default m if TOSHIBA_TC956X_PCI
Hi Alex,
I think GENERIC_IRQ_CHIP should be selected here.
Thank you for the driver.
Signature · 2 lines
Best regards, Xilin Wu <[email protected]>
Re: [PATCH net-next 10/12] net: stmmac: tc956x: add TC956x/QPS615 support
Quoted 43 lines · Xilin Wu
Quoted 31 lines · Alex Elder
From: Daniel Thompson <[email protected]>
Toshiba TC956x is an Ethernet AVB/TSN bridge and is essentially a small and highly-specialized SoC. TC956x includes an "eMAC" subsystem that can be accessed, along with several other peripherals, via two PCIe endpoint functions. There is a main driver for the endpoint that decomposes things and creates auxiliary bus devices to model the SoC.
The eMAC consists of a Designware XGMAC, XPCS and PMA. Each eMAC is supported by an MSIGEN that bridges TC956x level interrupts to PCIe MSIs.
Add a driver for the eMAC/MSIGEN combination.
Co-developed-by Alex Elder <[email protected]>Signed-off-by Alex Elder <[email protected]>Signed-off-by Daniel Thompson <[email protected]>---
drivers/net/ethernet/stmicro/stmmac/Kconfig | 13 + drivers/net/ethernet/stmicro/stmmac/Makefile | 2 + .../ethernet/stmicro/stmmac/dwmac-tc956x.c | 791 ++++++++++++++++++ include/soc/toshiba/tc956x-dwmac.h | 84 ++4 files changed, 890 insertions(+)create mode 100644
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.ccreate mode 100644include/soc/toshiba/tc956x-dwmac.hdrivers/net/ethernet/stmicro/stmmac/Kconfig +0
-0@@ -404,6 +404,19 @@ config DWMAC_MOTORCOMMQuoted 8 lines
This enables glue driver for Motorcomm DWMAC-based PCI Ethernet controllers. Currently only YT6801 is supported. +config
DWMAC_TC956X
+ tristate "Toshiba TC956X DWMAC support"
+ depends on PCI
+ depends onCOMMON_CLK
+ depends onTOSHIBA_TC956X_PCI
+ default m ifTOSHIBA_TC956X_PCIHi Alex,
Quoted 1 line
I think
GENERIC_IRQ_CHIPshould be selected here.
Yes there are a number of things missing in the Kconfig definitions and I'm working through them this week. And yes, since we use irq_generic_chip_ops we must ensure CONFIG_GENERIC_IRQ_CHIP is enabled here.
Quoted 1 line
Thank you for the driver.
Thank you for your feedback (this and others I see).
-Alex
Re: [PATCH net-next 10/12] net: stmmac: tc956x: add TC956x/QPS615 support
Quoted 51 lines · Alex Elder
Quoted 43 lines · Xilin Wu
Quoted 31 lines · Alex Elder
From: Daniel Thompson <[email protected]>
Toshiba TC956x is an Ethernet AVB/TSN bridge and is essentially a small and highly-specialized SoC. TC956x includes an "eMAC" subsystem that can be accessed, along with several other peripherals, via two PCIe endpoint functions. There is a main driver for the endpoint that decomposes things and creates auxiliary bus devices to model the SoC.
The eMAC consists of a Designware XGMAC, XPCS and PMA. Each eMAC is supported by an MSIGEN that bridges TC956x level interrupts to PCIe MSIs.
Add a driver for the eMAC/MSIGEN combination.
Co-developed-by Alex Elder <[email protected]>Signed-off-by Alex Elder <[email protected]>Signed-off-by Daniel Thompson <[email protected]>---
drivers/net/ethernet/stmicro/stmmac/Kconfig | 13 + drivers/net/ethernet/stmicro/stmmac/Makefile | 2 + .../ethernet/stmicro/stmmac/dwmac-tc956x.c | 791 ++++++++++++++++++ include/soc/toshiba/tc956x-dwmac.h | 84 ++4 files changed, 890 insertions(+)create mode 100644
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.ccreate mode 100644include/soc/toshiba/tc956x-dwmac.hdrivers/net/ethernet/stmicro/stmmac/Kconfig +0
-0@@ -404,6 +404,19 @@ config DWMAC_MOTORCOMMQuoted 8 lines
This enables glue driver for Motorcomm DWMAC-based PCI Ethernet controllers. Currently only YT6801 is supported. +config
DWMAC_TC956X
+ tristate "Toshiba TC956X DWMAC support"
+ depends on PCI
+ depends onCOMMON_CLK
+ depends onTOSHIBA_TC956X_PCI
+ default m ifTOSHIBA_TC956X_PCIHi Alex,
Quoted 1 line
I think
GENERIC_IRQ_CHIPshould be selected here.Yes there are a number of things missing in the
Kconfigdefinitions and I'm working through them this week. And yes, since we useirq_generic_chip_opswe must ensureCONFIG_GENERIC_IRQ_CHIPis enabled here.
Quoted 8 lines
Quoted 1 line
Thank you for the driver.
Thank you for your feedback (this and others I see).
-Alex
Hi Alex,
Do you think if a shutdown callback like this is required? It looks like the driver sometimes does a MDIO MMIO read when the PCIe link is down, causing the board to reset due to SoC side PCIe NoC timeout.
After this change, the board can always shutdown gracefully.
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c +12 -0
@@ -767,6 +767,17 @@ static void tc956x_dwmac_remove(struct auxiliary_device *adev)tc956x_mac_disable (td); } +static void tc956x_dwmac_shutdown (struct auxiliary_device *adev) +{ +struct device *dev = &adev->dev; +int ret; + + ret =stmmac_suspend (dev); +if (ret) +dev_warn (dev,"failed to suspend MAC during shutdown: %d\n" , + ret); +} +static const struct auxiliary_device_id tc956x_dwmac_ids[] = { { .name =TC956X_PCIE_DRIVER_NAME "." TC956X_XGMAC_DEV_NAME , }, { },
@@ -777,6 +788,7 @@ static struct auxiliary_driver tc956x_dwmac_driver = { .name = DRIVER_NAME, .probe = tc956x_dwmac_probe, .remove = tc956x_dwmac_remove, + .shutdown = tc956x_dwmac_shutdown, .id_table = tc956x_dwmac_ids, .driver = { .name = DRIVER_NAME,
Signature · 2 lines
Best regards, Xilin Wu <[email protected]>
Andrew Lunn
maintainerRe: [PATCH net-next 10/12] net: stmmac: tc956x: add TC956x/QPS615 support
Quoted 15 lines
Hi Alex,
Do you think if a shutdown callback like this is required? It looks like the driver sometimes does a MDIO MMIO read when the PCIe link is down, causing the board to reset due to SoC side PCIe NoC timeout.
After this change, the board can always shutdown gracefully.
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c +0
-0
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c static void tc956x_dwmac_remove(struct auxiliary_device · line 776
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c +6
-0@@ -767,6 +767,17 @@ static void tc956x_dwmac_remove(struct auxiliary_device *adev)tc956x_mac_disable (td); } +static void tc956x_dwmac_shutdown (struct auxiliary_device *adev) +{ +struct device *dev = &adev->dev; +int ret; + + ret =stmmac_suspend (dev);
It seems odd to do a suspend in shutdown.
But lets backtrack. Why is the PCIe link down?
Andrew
Re: [PATCH net-next 10/12] net: stmmac: tc956x: add TC956x/QPS615 support
In reply to Xilin WuHi Xilin
Quoted 5 lines · Xilin Wu
Do you think if a shutdown callback like this is required? It looks like the driver sometimes does a MDIO MMIO read when the PCIe link is down, causing the board to reset due to SoC side PCIe NoC timeout.
After this change, the board can always shutdown gracefully.
I've preferred controlled reboots to power cycles throughout development and I hadn't spotted any major problems with graceful shutdown (which isn't to say there have never crashes but generally I expect reboot to provoke a reboot successfully).
Just to be sure configured my board with irq=POLL (to match your setup) and still can't reproduce.
We mostly run Debian/systemd so there might be something happening in userspace to sequence things nicely. However I have ruled out NetworkManager.service and networking.service (stopped this services does *not* tear down the network link).
Can you share a bit more about how to reproduce the problem (including reliability of reproduction)?
Daniel.
Re: [PATCH net-next 10/12] net: stmmac: tc956x: add TC956x/QPS615 support
Quoted 22 lines · Daniel Thompson
Hi Xilin
Quoted 5 lines · Xilin Wu
Do you think if a shutdown callback like this is required? It looks like the driver sometimes does a MDIO MMIO read when the PCIe link is down, causing the board to reset due to SoC side PCIe NoC timeout.
After this change, the board can always shutdown gracefully.
I've preferred controlled reboots to power cycles throughout development and I hadn't spotted any major problems with graceful shutdown (which isn't to say there have never crashes but generally I expect
rebootto provoke a reboot successfully).Just to be sure configured my board with irq=POLL (to match your setup) and still can't reproduce.
We mostly run Debian/systemd so there might be something happening in userspace to sequence things nicely. However I have ruled out NetworkManager.service and networking.service (stopped this services does *not* tear down the network link).
Quoted 6 lines
Can you share a bit more about how to reproduce the problem (including reliability of reproduction)?
Daniel.
Hi Daniel,
Sorry for the late reply. After some more investigation, I think the problem is more likely related to the PCIe platform driver rather than this driver. So I agree that a shutdown callback is probably not needed here.
Signature · 2 lines
Best regards, Xilin Wu <[email protected]>
Re: [PATCH net-next 10/12] net: stmmac: tc956x: add TC956x/QPS615 support
In reply to Alex Elderdrivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 673
Quoted 11 lines · Alex Elder
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +11
-0+/* AXI Configuration */ + axi = &td->axi; + axi->axi_lpi_en =1 ; + axi->axi_wr_osr_lmt =31 ; + axi->axi_rd_osr_lmt =31 ; +/* All sizes (2^2..2^8) are supported */ + axi->axi_blen_regval =DMA_AXI_BLEN_MASK ; + plat->axi = axi; + + plat->mac_port_sel_speed = speed; + plat->flags =STMMAC_FLAG_MULTI_MSI_EN |STMMAC_FLAG_TSO_EN ;
I got WoL working only after adding STMMAC_FLAG_USE_PHY_WOL here. I guess it's required, since the driver clocks down the MAC/PMA/XPCS in its suspend hook?
Signature · 2 lines
Best regards, Xilin Wu <[email protected]>
Andrew Lunn
maintainerRe: [PATCH net-next 10/12] net: stmmac: tc956x: add TC956x/QPS615 support
Quoted 16 lines · Xilin Wu
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 673
Quoted 11 lines · Alex Elder
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +11
-0+/* AXI Configuration */ + axi = &td->axi; + axi->axi_lpi_en =1 ; + axi->axi_wr_osr_lmt =31 ; + axi->axi_rd_osr_lmt =31 ; +/* All sizes (2^2..2^8) are supported */ + axi->axi_blen_regval =DMA_AXI_BLEN_MASK ; + plat->axi = axi; + + plat->mac_port_sel_speed = speed; + plat->flags =STMMAC_FLAG_MULTI_MSI_EN |STMMAC_FLAG_TSO_EN ;I got WoL working only after adding
STMMAC_FLAG_USE_PHY_WOLhere. I guess it's required, since the driver clocks down the MAC/PMA/XPCS in its suspend hook?
Nice to see somebody testing WoL.
In your testing, is it the PHY doing the WoL, or the MAC? I assume PHY.
If i remember the DT correctly, the PHY interrupt is connected to a SoC GPIO, not a GPIO of this chip. So for your board, it is the SoCs GPIO controllers ability to perform the wake which is important. However, where the PHY interrupt is connected is a board design issue. Could the PHY interrupt be connected to the chip? Would the chip be able to wake the system? Should STMMAC_FLAG_USE_PHY_WOL be conditional?
Andrew
Re: [PATCH net-next 10/12] net: stmmac: tc956x: add TC956x/QPS615 support
Quoted 31 lines · Andrew Lunn
Quoted 16 lines · Xilin Wu
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 673
Quoted 11 lines · Alex Elder
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +11
-0+/* AXI Configuration */ + axi = &td->axi; + axi->axi_lpi_en =1 ; + axi->axi_wr_osr_lmt =31 ; + axi->axi_rd_osr_lmt =31 ; +/* All sizes (2^2..2^8) are supported */ + axi->axi_blen_regval =DMA_AXI_BLEN_MASK ; + plat->axi = axi; + + plat->mac_port_sel_speed = speed; + plat->flags =STMMAC_FLAG_MULTI_MSI_EN |STMMAC_FLAG_TSO_EN ;I got WoL working only after adding
STMMAC_FLAG_USE_PHY_WOLhere. I guess it's required, since the driver clocks down the MAC/PMA/XPCS in its suspend hook?Nice to see somebody testing WoL.
In your testing, is it the PHY doing the WoL, or the MAC? I assume PHY.
If i remember the DT correctly, the PHY interrupt is connected to a SoC GPIO, not a GPIO of this chip. So for your board, it is the SoCs GPIO controllers ability to perform the wake which is important. However, where the PHY interrupt is connected is a board design issue. Could the PHY interrupt be connected to the chip? Would the chip be able to wake the system? Should
STMMAC_FLAG_USE_PHY_WOLbe conditional?
Quoted 2 lines
Andrew
Hi Andrew,
Yes, the PHY is doing the WoL. And I guess this makes sense as it allows the MAC to power down during suspend to save power.
The INTN pin of QCA8081 is connected to the ETH_0_INT_N of QPS615. And the INTN_WOL pin is connected to a SoC GPIO.
Without this change, I can't get WoL to work. I have a working branch for our board here:
https://github.com/strongtz/linux-radxa-qcom/commits/v7.0.2-8280-wip/
Signature · 2 lines
Best regards, Xilin Wu <[email protected]>
Andrew Lunn
maintainerRe: [PATCH net-next 10/12] net: stmmac: tc956x: add TC956x/QPS615 support
Quoted 11 lines
Hi Andrew,
Yes, the PHY is doing the WoL. And I guess this makes sense as it allows the MAC to power down during suspend to save power.
The INTN pin of QCA8081 is connected to the
ETH_0_INT_Nof QPS615. And theINTN_WOLpin is connected to a SoC GPIO.Without this change, I can't get WoL to work. I have a working branch for our board here:
https://github.com/strongtz/linux-radxa-qcom/commits/v7.0.2-8280-wip/
Please take a look at commit
commit 6911308d7d111a9c367293b52f2dc265819f2b60
Author: Russell King (Oracle) <[email protected]> Date: Thu Oct 23 10:16:50 2025 +0100
net: stmmac: convert to phylink-managed Wake-on-Lan
In particular:
When STMMAC_FLAG_USE_PHY_WOL is not set, we provide the MAC's WoL capabilities to phylink, which then allows phylink to choose between the PHY and MAC for WoL depending on their individual capabilities as described in the phylink commit. This only augments the WoL functionality with PHYs that declare to the driver model that they are wake-up capable. Currently, very few PHY drivers support this.
Could you actually patch the PHY driver to make it list its capabilities. That is the direction we want to go in the long term, and not use STMMAC_FLAG_USE_PHY_WOL.
Andrew
Re: [PATCH net-next 10/12] net: stmmac: tc956x: add TC956x/QPS615 support
Quoted 29 lines · Andrew Lunn
Quoted 11 lines
Hi Andrew,
Yes, the PHY is doing the WoL. And I guess this makes sense as it allows the MAC to power down during suspend to save power.
The INTN pin of QCA8081 is connected to the
ETH_0_INT_Nof QPS615. And theINTN_WOLpin is connected to a SoC GPIO.Without this change, I can't get WoL to work. I have a working branch for our board here:
https://github.com/strongtz/linux-radxa-qcom/commits/v7.0.2-8280-wip/Please take a look at commit
commit
6911308d7d111a9c367293b52f2dc265819f2b60Author: Russell King (Oracle) <[email protected]> Date: Thu Oct 23 10:16:50 2025 +0100net: stmmac: convert to phylink-managed Wake-on-Lan
In particular:
When
STMMAC_FLAG_USE_PHY_WOLis not set, we provide the MAC's WoL capabilities to phylink, which then allows phylink to choose between the PHY and MAC for WoL depending on their individual capabilities as described in the phylink commit. This only augments the WoL functionality with PHYs that declare to the driver model that they are wake-up capable. Currently, very few PHY drivers support this.
Quoted 6 lines
Could you actually patch the PHY driver to make it list its capabilities. That is the direction we want to go in the long term, and not use
STMMAC_FLAG_USE_PHY_WOL.Andrew
Thanks for pointing this out! You are right that I should patch the PHY driver. I have made WoL work without the change in the tc956x driver.
Signature · 2 lines
Best regards, Xilin Wu <[email protected]>
Re: [PATCH net-next 10/12] net: stmmac: tc956x: add TC956x/QPS615 support
In reply to Xilin WuQuoted 32 lines · Xilin Wu
Quoted 23 lines · Andrew Lunn
Quoted 16 lines · Xilin Wu
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 673
Quoted 11 lines · Alex Elder
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +11
-0+/* AXI Configuration */ + axi = &td->axi; + axi->axi_lpi_en =1 ; + axi->axi_wr_osr_lmt =31 ; + axi->axi_rd_osr_lmt =31 ; +/* All sizes (2^2..2^8) are supported */ + axi->axi_blen_regval =DMA_AXI_BLEN_MASK ; + plat->axi = axi; + + plat->mac_port_sel_speed = speed; + plat->flags =STMMAC_FLAG_MULTI_MSI_EN |STMMAC_FLAG_TSO_EN ;I got WoL working only after adding
STMMAC_FLAG_USE_PHY_WOLhere. I guess it's required, since the driver clocks down the MAC/PMA/XPCS in its suspend hook?Nice to see somebody testing WoL.
In your testing, is it the PHY doing the WoL, or the MAC? I assume PHY.
Quoted 7 lines
If i remember the DT correctly, the PHY interrupt is connected to a SoC GPIO, not a GPIO of this chip. So for your board, it is the SoCs GPIO controllers ability to perform the wake which is important. However, where the PHY interrupt is connected is a board design issue. Could the PHY interrupt be connected to the chip? Would the chip be able to wake the system? Should
STMMAC_FLAG_USE_PHY_WOLbe conditional?
Quoted 5 lines
Yes, the PHY is doing the WoL. And I guess this makes sense as it allows the MAC to power down during suspend to save power.
The INTN pin of QCA8081 is connected to the
ETH_0_INT_Nof QPS615. And theINTN_WOLpin is connected to a SoC GPIO.
Interesting. That is different to RB3gen2 where INTN is routed to both (although there is a do-not-fit 0ohm resistor option that could change that).
Does that mean you don't get phy interrupts reported in /proc/interrupts before any suspend happens?
Quoted 3 lines
Without this change, I can't get WoL to work. I have a working branch for our board here:
https://github.com/strongtz/linux-radxa-qcom/commits/v7.0.2-8280-wip/
I took a quick look at the DT and I noticed you have an SGMII PHY attached to both eMAC0 and eMAC1 on your board. This is something we think should work but were unable to test. Are you able to use both eMACs concurrently? Would be great to see that confirmed!
Daniel.
Re: [PATCH net-next 10/12] net: stmmac: tc956x: add TC956x/QPS615 support
Quoted 39 lines · Daniel Thompson
Quoted 32 lines · Xilin Wu
Quoted 23 lines · Andrew Lunn
Quoted 16 lines · Xilin Wu
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 673
Quoted 11 lines · Alex Elder
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +11
-0+/* AXI Configuration */ + axi = &td->axi; + axi->axi_lpi_en =1 ; + axi->axi_wr_osr_lmt =31 ; + axi->axi_rd_osr_lmt =31 ; +/* All sizes (2^2..2^8) are supported */ + axi->axi_blen_regval =DMA_AXI_BLEN_MASK ; + plat->axi = axi; + + plat->mac_port_sel_speed = speed; + plat->flags =STMMAC_FLAG_MULTI_MSI_EN |STMMAC_FLAG_TSO_EN ;I got WoL working only after adding
STMMAC_FLAG_USE_PHY_WOLhere. I guess it's required, since the driver clocks down the MAC/PMA/XPCS in its suspend hook?Nice to see somebody testing WoL.
In your testing, is it the PHY doing the WoL, or the MAC? I assume PHY.
Quoted 7 lines
If i remember the DT correctly, the PHY interrupt is connected to a SoC GPIO, not a GPIO of this chip. So for your board, it is the SoCs GPIO controllers ability to perform the wake which is important. However, where the PHY interrupt is connected is a board design issue. Could the PHY interrupt be connected to the chip? Would the chip be able to wake the system? Should
STMMAC_FLAG_USE_PHY_WOLbe conditional?Quoted 5 lines
Yes, the PHY is doing the WoL. And I guess this makes sense as it allows the MAC to power down during suspend to save power.
The INTN pin of QCA8081 is connected to the
ETH_0_INT_Nof QPS615. And theINTN_WOLpin is connected to a SoC GPIO.
Quoted 7 lines
Interesting. That is different to RB3gen2 where INTN is routed to both (although there is a do-not-fit 0ohm resistor option that could change that).
Does that mean you don't get phy interrupts reported in
/proc/interruptsbefore any suspend happens?
No. The phy works in polling mode AFAIK.
Quoted 5 lines
Quoted 4 lines
Without this change, I can't get WoL to work. I have a working branch for our board here:
https://github.com/strongtz/linux-radxa-qcom/commits/v7.0.2-8280-wip/
Quoted 8 lines
I took a quick look at the DT and I noticed you have an SGMII PHY attached to both eMAC0 and eMAC1 on your board. This is something we think should work but were unable to test. Are you able to use both eMACs concurrently? Would be great to see that confirmed!
Daniel.
Yes, both eMACs can be used concurrently. And they can reach 2.5Gbps under iperf3 testing.
Signature · 2 lines
Best regards, Xilin Wu <[email protected]>
Andrew Lunn
maintainerRe: [PATCH net-next 10/12] net: stmmac: tc956x: add TC956x/QPS615 support
Quoted 5 lines
Quoted 3 lines
Does that mean you don't get phy interrupts reported in
/proc/interruptsbefore any suspend happens?No. The phy works in polling mode AFAIK.
You should be able to tell from dmesg:
Generic FE-GE Realtek PHY r8169-0-600:00: attached PHY driver (mii_bus:phy_addr=r8169-0-600:00, irq=MAC)
irq= can be MAC, POLL, or the interrupt number if interrupts are used.
If PHY WoL is used, i would expect interrupts to be used, otherwise how is the PHY waking the system?
Andrew
Re: [PATCH net-next 10/12] net: stmmac: tc956x: add TC956x/QPS615 support
Quoted 8 lines · Andrew Lunn
Quoted 5 lines
Quoted 3 lines
Does that mean you don't get phy interrupts reported in
/proc/interruptsbefore any suspend happens?No. The phy works in polling mode AFAIK.
You should be able to tell from dmesg:
Quoted 9 lines
Generic FE-GE Realtek PHY r8169-0-600:00: attached PHY driver (mii_bus:phy_addr=r8169-0-600:00, irq=MAC)
irq= can be MAC, POLL, or the interrupt number if interrupts are used.
If PHY WoL is used, i would expect interrupts to be used, otherwise how is the PHY waking the system?
Andrew
Yeah I know, it's indeed POLL. The phy is now waking the system using the INTN_WOL pin directly connected to the SoC GPIO, instead of the INTN pin connected to the QPS615.
Signature · 2 lines
Best regards, Xilin Wu <[email protected]>
Re: [PATCH net-next 10/12] net: stmmac: tc956x: add TC956x/QPS615 support
In reply to Andrew LunnQuoted 18 lines · Andrew Lunn
Quoted 16 lines · Xilin Wu
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c line 673
Quoted 11 lines · Alex Elder
drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c new file +11
-0+/* AXI Configuration */ + axi = &td->axi; + axi->axi_lpi_en =1 ; + axi->axi_wr_osr_lmt =31 ; + axi->axi_rd_osr_lmt =31 ; +/* All sizes (2^2..2^8) are supported */ + axi->axi_blen_regval =DMA_AXI_BLEN_MASK ; + plat->axi = axi; + + plat->mac_port_sel_speed = speed; + plat->flags =STMMAC_FLAG_MULTI_MSI_EN |STMMAC_FLAG_TSO_EN ;I got WoL working only after adding
STMMAC_FLAG_USE_PHY_WOLhere. I guess it's required, since the driver clocks down the MAC/PMA/XPCS in its suspend hook?
Quoted 1 line
Nice to see somebody testing WoL.
Absolutely!
We recently stripped out the (obviously broken and partially ported) WoL support we had in tc956x-pci.c. We planned to bring it back later. Hadn't realized it could be so easy.
Quoted 5 lines
In your testing, is it the PHY doing the WoL, or the MAC? I assume PHY.
If i remember the DT correctly, the PHY interrupt is connected to a SoC GPIO, not a GPIO of this chip.
On RB3Gen2 (and I think also the QPS615 reference design) the phy interrupt is routed twice. It is connected both to the TC9564 GPIO block and to the host SoC.
Quoted 6 lines
So for your board, it is the SoCs
GPIO controllers ability to perform the wake which is important. However, where the PHY interrupt is connected is a board design issue. Could the PHY interrupt be connected to the chip? Would the chip be able to wake the system? ShouldSTMMAC_FLAG_USE_PHY_WOLbe conditional?
I couldn't think of any reason to use the TC9564 GPIO block for the interrupts on RB3gen2 so I left it unused and the DT describes the SoC routing only.
However if TC9564 were to be mounted on a real PCIe card then we'd have to use the TC9564 GPIO instead and would have to leave enough of the TC9564 enabled to handle the interrupt (and also to load a firmware to catch the interrupt and drive the PCI wake up signal).
However such systems would need extensions to the current driver. We have done all we can to make it possible to add those extensions in the future but we would not be able to test them: not only do would a real PCIe card need extra driver features to play nice with ACPI but the card would also need an I2C EEPROM. We don't have that EEPROM on RB3gen2 (and again, we'd need firmware to read it).
TL;DR - there are conceivable (and sane) hardware designs where the interrupt goes only to the TC9564 GPIO, but they are too different to RB3gen2 (and related SBC designs) for them to be supported before they exist!
Daniel.
Andrew Lunn
maintainerRe: [PATCH net-next 10/12] net: stmmac: tc956x: add TC956x/QPS615 support
Quoted 4 lines
TL;DR - there are conceivable (and sane) hardware designs where the interrupt goes only to the TC9564 GPIO, but they are too different to RB3gen2 (and related SBC designs) for them to be supported before they exist!
Agreed. I'm just trying to be cautious. It would be bad to saying that WoL is supported in general, because a board might come along where it does not work because the TC9564 itself cannot wake the system. If the driver needs to say WoL is supported, it should try to validate the system is using a supported set of features.
But lets get the basic features supported first, WoL can be added later.
Andrew
Re: [PATCH net-next 10/12] net: stmmac: tc956x: add TC956x/QPS615 support
In reply to Xilin WuQuoted 13 lines · Xilin Wu
Quoted 11 lines · Alex Elder
+ /* AXI Configuration */
+ axi =&td->axi;
+axi->axi_lpi_en= 1;
+axi->axi_wr_osr_lmt= 31;
+axi->axi_rd_osr_lmt= 31;
+ /* All sizes (2^2..2^8) are supported */
+axi->axi_blen_regval=DMA_AXI_BLEN_MASK;
+plat->axi= axi;
+
+plat->mac_port_sel_speed= speed;
+plat->flags=STMMAC_FLAG_MULTI_MSI_EN|STMMAC_FLAG_TSO_EN;
Quoted 1 line
I got WoL working only after adding
STMMAC_FLAG_USE_PHY_WOLhere. I guess it's required, since the driver clocks down the MAC/PMA/XPCS in its suspend hook?
I just want to respond to this with a summary of our plans.
We will *not* be implementing wake-on-LAN (WoL) initially. We will work to get support for the eMACs upstream for TC956x, and then as a separate step, we will enable WoL.
It's great to know you have it working, and our plan is to implement it via the PHYs and not involve the MAC. It seems it will be relatively easy, but we have no plans to add it to the current series.
-Alex
Re: [PATCH net-next 10/12] net: stmmac: tc956x: add TC956x/QPS615 support
Quoted 22 lines · Alex Elder
Quoted 13 lines · Xilin Wu
Quoted 11 lines · Alex Elder
+ /* AXI Configuration */
+ axi =&td->axi;
+axi->axi_lpi_en= 1;
+axi->axi_wr_osr_lmt= 31;
+axi->axi_rd_osr_lmt= 31;
+ /* All sizes (2^2..2^8) are supported */
+axi->axi_blen_regval=DMA_AXI_BLEN_MASK;
+plat->axi= axi;
+
+plat->mac_port_sel_speed= speed;
+plat->flags=STMMAC_FLAG_MULTI_MSI_EN|STMMAC_FLAG_TSO_EN;Quoted 1 line
I got WoL working only after adding
STMMAC_FLAG_USE_PHY_WOLhere. I guess it's required, since the driver clocks down the MAC/PMA/XPCS in its suspend hook?I just want to respond to this with a summary of our plans.
We will *not* be implementing wake-on-LAN (WoL) initially. We will work to get support for the eMACs upstream for TC956x, and then as a separate step, we will enable WoL.
Quoted 7 lines
It's great to know you have it working, and our plan is to implement it via the PHYs and not involve the MAC. It seems it will be relatively easy, but we have no plans to add it to the current series.
-Alex
Hi Alex,
Maybe I missed something, but I already have WoL working *without* changes in the tc956x driver.
https://lore.kernel.org/all/[email protected]/
Signature · 2 lines
Best regards, Xilin Wu <[email protected]>
Andrew Lunn
maintainerRe: [PATCH net-next 10/12] net: stmmac: tc956x: add TC956x/QPS615 support
Quoted 6 lines
Hi Alex,
Maybe I missed something, but I already have WoL working *without* changes in the tc956x driver.
Sorry, did i miss the patches for the PHY driver? Or was the code already there?
Andrew
Re: [PATCH net-next 10/12] net: stmmac: tc956x: add TC956x/QPS615 support
Quoted 5 lines · Andrew Lunn
Quoted 5 lines
Hi Alex,
Maybe I missed something, but I already have WoL working *without* changes in the tc956x driver.
Quoted 7 lines
Quoted 1 line
Sorry, did i miss the patches for the PHY driver? Or was the code already there?
Andrew
No, I'm using an out-of-tree patch currently.
https://github.com/strongtz/linux-radxa-qcom/commit/4a085eb54115844be62bfaa9d0b3e905c22ee479
Signature · 2 lines
Best regards, Xilin Wu <[email protected]>
PATCH 11/12 misc: tc956x_pci: add TC956x/QPS615 support
In reply to Alex ElderThe Toshiba TC956x is an Ethernet AVB/TSN bridge, and is essentially a small and highly-specialized SoC. It implements a number of internal functions, including a GPIO controller, control registers managing internal reset and clock control signals, a PCIe switch and internal endpoint, and mapping hardware that translates between PCIe and internal addressing.
The internal PCIe endpoint implements two PCIe functions, each of which has an attached eMAC. Each of these eMACs is represented as two separate devices: a PCIe function; and the eMAC. The PCIe function driver serves as the primary driver, creating other associated devices using the auxiliary bus.
PCIe function 0 is responsible for managing common features on the TC956x chip. It initializes a "chip" data structure that keeps track of common information, and makes that available via its platform_data pointer to its PCIe function 1 peer. It also configures the address mapping hardware, and sets up an auxiliary device for the GPIO controller.
As probing concludes, an auxiliary device is created to represent the eMAC functionality attached to the PCIe function. A block of information is set up to be shared with the auxiliary device. It provides the IRQ to be used by the MAC device, as well as a some memory-mapped I/O pointers and a few other bits of information about the chip. This information is supplied via the auxiliary device's platform_data pointer.
--- drivers/misc/Kconfig | 10 + drivers/misc/Makefile | 1 + drivers/misc/tc956x_pci.c | 667 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 678 insertions(+) create mode 100644 drivers/misc/tc956x_pci.c
drivers/misc/Kconfig +10 -0
@@ -644,6 +644,16 @@ config MCHP_LAN966X_PCI - lan966x-miim (MDIO_MSCC_MIIM) - lan966x-switch (LAN966X_SWITCH) +config TOSHIBA_TC956X_PCI + tristate "Toshiba TC956X PCI function support" + depends on PCI + select AUXILIARY_BUS + help + This enables support for the two PCI functions implemented by + the embedded PCIe endpoint in the Toshiba TC956X. This driver + creates auxiliary devices and requires drivers for these devices + to function. + source "drivers/misc/c2port/Kconfig" source "drivers/misc/eeprom/Kconfig" source "drivers/misc/cb710/Kconfig"
drivers/misc/Makefile +1 -0
@@ -75,3 +75,4 @@ obj-$(CONFIG_MCHP_LAN966X_PCI) += lan966x-pci.o obj-y += keba/ obj-y += amd-sbi/ obj-$(CONFIG_MISC_RP1) += rp1/ +obj-$(CONFIG_TOSHIBA_TC956X_PCI) += tc956x_pci.o
drivers/misc/tc956x_pci.c new file +667 -0
667 lines not on this page · raw message
Signature · 1 line
2.51.0
Andrew Lunn
maintainerRe: [PATCH net-next 11/12] misc: tc956x_pci: add TC956x/QPS615 support
drivers/misc/tc956x_pci.c line 202
Quoted 7 lines
drivers/misc/tc956x_pci.c +5
-0+static inline void chip_reset_assert (const struct tc956x_chip *chip, +enum reset_id id) +{ +tc956x_reset_clock_set (chip, true, true, true, (u8 )id); +}
This is in drivers/misc, where the rules might be different. But in netdev, we don't like inline functions in .c files. It is better to let the compiler decide.
drivers/misc/tc956x_pci.c line 439
Quoted 11 lines
drivers/misc/tc956x_pci.c +11
-0+static void chip_init_state (struct tc956x_chip *chip) +{ +/* The only IP block we currently use is MSIGEN */ +chip_reset_assert (chip,RESET_MCU ); +chip_reset_assert (chip,RESET_MCU1 ); +chip_reset_assert (chip,RESET_INTC ); +chip_reset_assert (chip,RESET_UART0 ); +chip_clock_disable (chip,CLOCK_MCU ); +chip_clock_disable (chip,CLOCK_SRAM ); +chip_clock_disable (chip,CLOCK_PLL ); +chip_clock_disable (chip,CLOCK_SGMII );
With my networking hat on, this one standard out.
drivers/misc/tc956x_pci.c line 440
Quoted 1 line
drivers/misc/tc956x_pci.c +1
-0+chip_clock_disable (chip,CLOCK_REFCLK );
The name REFCLK is sometimes used as for the clock signals for RGMII?
drivers/misc/tc956x_pci.c line 559
Quoted 11 lines
drivers/misc/tc956x_pci.c +11
-0+static int +tc956x_function_probe (struct pci_dev *pdev,const struct pci_device_id *id) +{ +struct device *dev = &pdev->dev; +struct tc956x_chip *chip; +unsigned int msigen_irq; +int ret; + +/* Despite being a PCI device, we require devicetree */ +if (!dev->of_node) +return -EINVAL ;
Might be worth a dev_err(), since it is unusual.
Andrew
Re: [PATCH net-next 11/12] misc: tc956x_pci: add TC956x/QPS615 support
Quoted 11 lines · Andrew Lunn
drivers/misc/tc956x_pci.c line 202
Quoted 7 lines
drivers/misc/tc956x_pci.c +5
-0+static inline void chip_reset_assert (const struct tc956x_chip *chip, +enum reset_id id) +{ +tc956x_reset_clock_set (chip, true, true, true, (u8 )id); +}This is in
drivers/misc, where the rules might be different. But in netdev, we don't like inline functions in .c files. It is better to let the compiler decide.
That was a mistake. I agree with that perspective. These functions were moved out of the header file because they were only used here. And in the process, I neglected to drop the inline. Will fix.
Quoted 14 lines
drivers/misc/tc956x_pci.c line 439
Quoted 11 lines
drivers/misc/tc956x_pci.c +11
-0+static void chip_init_state (struct tc956x_chip *chip) +{ +/* The only IP block we currently use is MSIGEN */ +chip_reset_assert (chip,RESET_MCU ); +chip_reset_assert (chip,RESET_MCU1 ); +chip_reset_assert (chip,RESET_INTC ); +chip_reset_assert (chip,RESET_UART0 ); +chip_clock_disable (chip,CLOCK_MCU ); +chip_clock_disable (chip,CLOCK_SRAM ); +chip_clock_disable (chip,CLOCK_PLL ); +chip_clock_disable (chip,CLOCK_SGMII );With my networking hat on, this one standard out.
Quoted 3 lines
drivers/misc/tc956x_pci.c line 440
Quoted 1 line
drivers/misc/tc956x_pci.c +1
-0+chip_clock_disable (chip,CLOCK_REFCLK );The name REFCLK is sometimes used as for the clock signals for RGMII?
You're saying that the REFCLK disable stood out, and you want to understand what "REFCLK" actually represents?
I believe this is an *output* reference clock signal generated by the TC9564. Looking at the schematic for the RB3gen2 it leads only to a test point.
However I want to compare notes with Daniel on Monday about this.
Would it draw less attention if it were named "REFCLKO"?
In any case we can add some reassuring comments.
Quoted 14 lines
drivers/misc/tc956x_pci.c line 559
Quoted 12 lines
drivers/misc/tc956x_pci.c +11
-0+static int +tc956x_function_probe (struct pci_dev *pdev,const struct pci_device_id *id) +{ +struct device *dev = &pdev->dev; +struct tc956x_chip *chip; +unsigned int msigen_irq; +int ret; + +/* Despite being a PCI device, we require devicetree */ +if (!dev->of_node) +return -EINVAL ;Might be worth a
dev_err(), since it is unusual.
Good suggestion. I'll add that.
Thanks a lot for your review.
-Alex
Quoted 2 lines
Andrew
[email protected]
AI reviewRe: [PATCH net-next 11/12] misc: tc956x_pci: add TC956x/QPS615 support
In reply to Alex ElderThank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] Dangling `platform_data` pointer and stateless device link lead to Use-After-Free - [High] Devres…
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] Dangling platform_data pointer and stateless device link lead to Use-After-Free
- [High] Devres lifecycle violation causes memory leak of device links
- [High] Reference count leak of PCI peer device
- [High] Missing pci_free_irq_vectors() in error paths and remove function --
commit 7eab7fd4b209226034d88bc445ad71c833dda6b7
Author: Alex Elder <[email protected]>
misc: tc956x_pci: add TC956x/QPS615 support
This commit introduces support for the Toshiba TC956x Ethernet AVB/TSN bridge, configuring its PCI functions and creating auxiliary devices to support the XGMAC interfaces.
drivers/misc/tc956x_pci.c new file +0 -0
[ ... ]
Quoted 2 lines
(quoted diff) +2
-0+static struct tc956x_chip *chip_get(struct pci_dev *pdev) +{
[ ... ]
Review
Quoted 4 lines
(quoted diff) +4
-0+ /* Function 1 has to get the chip structure from function 0 */ + peer = pci_get_slot(pdev->bus, PCI_DEVFN(PCI_SLOT(devfn), 0)); + if (!peer) + return ERR_PTR(-ENXIO);
Does this leak the pci_dev reference count?
pci_get_slot() returns a device with its reference count incremented, but I do not see a matching pci_dev_put(peer) in either the success path or when returning -EPROBE_DEFER below.
Review
Quoted 8 lines
(quoted diff) +8
-0+ + /* If function 0 hasn't set up the chip yet, try again later */ + chip = dev_get_platdata(&peer->dev); + if (!chip) + return ERR_PTR(-EPROBE_DEFER); + + /* Mark function 1's device as dependent on function 0 */ + link = device_link_add(dev, &peer->dev, DL_FLAG_STATELESS);
Is DL_FLAG_STATELESS safe to use here?
Stateless links do not enforce unbind ordering. If function 0 is unbound by the user, its devres will free the chip structure and unmap the MMIO regions while function 1 remains bound. Will function 1 cause a use-after-free if it accesses the freed chip state or unmapped MMIO space?
Review
Quoted 4 lines
(quoted diff) +4
-0+ if (!link) + return ERR_PTR(-ENODEV); + + ret = devm_add_action_or_reset(&peer->dev, chip_link_del, link);
Should this cleanup action be attached to dev (function 1) instead of peer->dev (function 0)?
If function 1's probe fails downstream, its own devres list is rolled back, but this cleanup action remains attached to function 0. Will this leak the device link and accumulate duplicate devres actions on function 0 each time function 1 defers its probe?
Quoted 5 lines
(quoted diff) +5
-0+ if (ret) + return ERR_PTR(ret); + + return chip; +}
[ ... ]
Quoted 3 lines
(quoted diff) +3
-0+static int +tc956x_function_probe(struct pci_dev *pdev, const struct pci_device_id *id) +{
[ ... ]
Review
Quoted 5 lines
(quoted diff) +5
-0+ /* We called pcim_enable_device() so this will be freed automatically */ + ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_MSI); + if (ret < 1) + return dev_err_probe(dev, ret ? : -EIO, + "failed to allocate IRQ vectors\n");
Is this comment accurate?
According to PCI subsystem guidelines, pci_alloc_irq_vectors() requires explicit manual cleanup. Should the error paths below and the remove function call pci_free_irq_vectors(pdev) to prevent leaking system IRQ resources?
Quoted 6 lines
(quoted diff) +6
-0+ + ret = pci_irq_vector(pdev, 0); + if (ret < 1) + return dev_err_probe(dev, ret ? : -EIO, "failed to get IRQ\n"); + msigen_irq = ret; +
Review
Quoted 10 lines
(quoted diff) +10
-0+ ret = chip_init(chip, pdev); + if (ret) + return dev_err_probe(dev, ret, "failed to initialize chip\n"); + + /* We're ready; the other function can now probe */ + dev->platform_data = chip; + + ret = function_xgmac_adev_add(pdev, chip, msigen_irq); + if (ret) + return dev_err_probe(dev, ret, "failed to add xgmap device\n");
If function_xgmac_adev_add() fails, devm_kzalloc() will automatically free the chip structure upon exit, but dev->platform_data is not cleared.
Will function 1's chip_get() retrieve this dangling pointer via dev_get_platdata() and cause a use-after-free when it probes later?
Review
Quoted 13 lines
(quoted diff) +13
-0+ + return 0; +} + +static void tc956x_function_remove(struct pci_dev *pdev) +{ + struct tc956x_chip *chip = dev_get_platdata(&pdev->dev); + + pci_clear_master(pdev); + + if (&pdev->dev == chip->dev) + chip_msigen_disable(chip); +}
Does this function need a call to pci_free_irq_vectors(pdev) to clean up the allocated IRQ vectors before returning?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
Re: [PATCH net-next 11/12] misc: tc956x_pci: add TC956x/QPS615 support
Quoted 5 lines · On 5/2/26 10:56 AM, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] Danglingplatform_datapointer and stateless device link lead to Use-After-Free
- [High] Devres lifecycle violation causes memory leak of device links
- [High] Reference count leak of PCI peer device
- [High] Missingpci_free_irq_vectors()in error paths and remove function
All issues highlighted here are legitimate, and will be addressed in the next version of the series.
Quoted 22 lines
--
commit
7eab7fd4b209226034d88bc445ad71c833dda6b7
Author: Alex Elder <[email protected]>misc:
tc956x_pci: add TC956x/QPS615 supportThis commit introduces support for the Toshiba TC956x Ethernet AVB/TSN bridge, configuring its PCI functions and creating auxiliary devices to support the XGMAC interfaces.
drivers/misc/tc956x_pci.c new file +0
-0Quoted 3 lines
(quoted diff) +2
-0+static struct tc956x_chip *chip_get(struct pci_dev *pdev) +{[ ... ]
Quoted 6 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ /* Function 1 has to get the chip structure from function 0 */ + peer = pci_get_slot(pdev->bus, PCI_DEVFN(PCI_SLOT(devfn), 0)); + if (!peer) + return ERR_PTR(-ENXIO);Does this leak the
pci_devreference count?
Yes it does, and this will be fixed in the next version of the patch.
Quoted 5 lines
pci_get_slot()returns a device with its reference count incremented, but I do not see a matchingpci_dev_put(peer)in either the success path or when returning -EPROBE_DEFER below.
Quoted 10 lines
Review
Quoted 8 lines
(quoted diff) +8
-0+ + /* If function 0 hasn't set up the chip yet, try again later */ + chip = dev_get_platdata(&peer->dev); + if (!chip) + return ERR_PTR(-EPROBE_DEFER); + + /* Mark function 1's device as dependent on function 0 */ + link = device_link_add(dev, &peer->dev, DL_FLAG_STATELESS);Is
DL_FLAG_STATELESSsafe to use here?
We believe this is safe to use here. If it is created successfully a devm action is set up (for function 1) to remove the link.
Quoted 5 lines
Stateless links do not enforce unbind ordering. If function 0 is unbound by the user, its devres will free the chip structure and unmap the MMIO regions while function 1 remains bound. Will function 1 cause a use-after-free if it accesses the freed chip state or unmapped MMIO space?
Quoted 7 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ if (!link) + return ERR_PTR(-ENODEV); + + ret = devm_add_action_or_reset(&peer->dev, chip_link_del, link);Should this cleanup action be attached to dev (function 1) instead of
peer->dev(function 0)?
Yes, this was a very good catch. The name of the peer variable will be changed to be "slot0" to emphasize which device we're dealing with.
Quoted 20 lines
If function 1's probe fails downstream, its own devres list is rolled back, but this cleanup action remains attached to function 0. Will this leak the device link and accumulate duplicate devres actions on function 0 each time function 1 defers its probe?
Quoted 5 lines
(quoted diff) +5
-0+ if (ret) + return ERR_PTR(ret); + + return chip; +}[ ... ]
Quoted 3 lines
(quoted diff) +3
-0+static int +tc956x_function_probe(struct pci_dev *pdev, const struct pci_device_id *id) +{[ ... ]
Quoted 7 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ /* We called pcim_enable_device() so this will be freed automatically */ + ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_MSI); + if (ret < 1) + return dev_err_probe(dev, ret ? : -EIO, + "failed to allocate IRQ vectors\n");Is this comment accurate?
Looking at it now, it appears the comment is not accurate.
All error paths that follow will free this IRQ vector. And the driver remove function will do so as well.
Quoted 24 lines
According to PCI subsystem guidelines,
pci_alloc_irq_vectors()requires explicit manual cleanup. Should the error paths below and the remove function callpci_free_irq_vectors(pdev)to prevent leaking system IRQ resources?Quoted 6 lines
(quoted diff) +6
-0+ + ret = pci_irq_vector(pdev, 0); + if (ret < 1) + return dev_err_probe(dev, ret ? : -EIO, "failed to get IRQ\n"); + msigen_irq = ret; +Review
Quoted 10 lines
(quoted diff) +10
-0+ ret = chip_init(chip, pdev); + if (ret) + return dev_err_probe(dev, ret, "failed to initialize chip\n"); + + /* We're ready; the other function can now probe */ + dev->platform_data = chip; + + ret = function_xgmac_adev_add(pdev, chip, msigen_irq); + if (ret) + return dev_err_probe(dev, ret, "failed to add xgmap device\n");If
function_xgmac_adev_add()fails,devm_kzalloc()will automatically free the chip structure upon exit, butdev->platform_datais not cleared.
Quoted 2 lines
Will function 1's
chip_get()retrieve this dangling pointer viadev_get_platdata()and cause a use-after-free when it probes later?
This too was a good catch. The platform_data for function 0 will not be assigned a non-null value until it has completed its probe successfully.
Quoted 17 lines
Quoted 4 lines
(quoted diff) +3
-0+ + return 0; +}Review
Quoted 10 lines
(quoted diff) +10
-0+ +static void tc956x_function_remove(struct pci_dev *pdev) +{ + struct tc956x_chip *chip = dev_get_platdata(&pdev->dev); + + pci_clear_master(pdev); + + if (&pdev->dev == chip->dev) + chip_msigen_disable(chip); +}Does this function need a call to
pci_free_irq_vectors(pdev)to clean up the allocated IRQ vectors before returning?
This will be added, as mentioned above.
-Alex
Jakub Kicinski
maintainerRe: [PATCH net-next 11/12] misc: tc956x_pci: add TC956x/QPS615 support
In reply to Alex ElderQuoted 6 lines · On Fri, 1 May 2026 10:54:19 -0500 Alex Elder wrote:
The Toshiba TC956x is an Ethernet AVB/TSN bridge, and is essentially a small and highly-specialized SoC. It implements a number of internal functions, including a GPIO controller, control registers managing internal reset and clock control signals, a PCIe switch and internal endpoint, and mapping hardware that translates between PCIe and internal addressing.
drivers/misc/tc956x_pci.c:541:17: error: call to undeclared function 'u32_get_bits'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
541 | chip->rev_id = u32_get_bits(val, NCID_REV_ID_MASK);
| ^
Signature · 1 line
pw-bot: cr
Re: [PATCH net-next 11/12] misc: tc956x_pci: add TC956x/QPS615 support
Quoted 11 lines · Jakub Kicinski
Quoted 6 lines · On Fri, 1 May 2026 10:54:19 -0500 Alex Elder wrote:
The Toshiba TC956x is an Ethernet AVB/TSN bridge, and is essentially a small and highly-specialized SoC. It implements a number of internal functions, including a GPIO controller, control registers managing internal reset and clock control signals, a PCIe switch and internal endpoint, and mapping hardware that translates between PCIe and internal addressing.
drivers/misc/tc956x_pci.c:541:17: error: call to undeclared function 'u32_get_bits'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
541 |chip->rev_id=u32_get_bits(val, NCID_REV_ID_MASK);
| ^
Yeah I think I noticed an error like that shows up with 32-bit builds? In any case we didn't see it during development, and we'll make sure <linux/bitfield.h> gets included.
Thanks.
-Alex
Jakub Kicinski
maintainerRe: [PATCH net-next 11/12] misc: tc956x_pci: add TC956x/QPS615 support
Quoted 7 lines · On Sat, 2 May 2026 21:06:33 -0500 Alex Elder wrote:
Quoted 3 lines
drivers/misc/tc956x_pci.c:541:17: error: call to undeclared function 'u32_get_bits'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
541 |chip->rev_id=u32_get_bits(val, NCID_REV_ID_MASK);
| ^Yeah I think I noticed an error like that shows up with 32-bit builds? In any case we didn't see it during development, and we'll make sure <
linux/bitfield.h> gets included.
on x86 it hits on all configs, I suspected you're building for ARM?
Re: [PATCH net-next 11/12] misc: tc956x_pci: add TC956x/QPS615 support
Quoted 10 lines · Jakub Kicinski
Quoted 7 lines · On Sat, 2 May 2026 21:06:33 -0500 Alex Elder wrote:
Quoted 3 lines
drivers/misc/tc956x_pci.c:541:17: error: call to undeclared function 'u32_get_bits'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]541 | chip->rev_id = u32_get_bits(val, NCID_REV_ID_MASK); | ^Yeah I think I noticed an error like that shows up with 32-bit builds? In any case we didn't see it during development, and we'll make sure <
linux/bitfield.h> gets included.on x86 it hits on all configs, I suspected you're building for ARM?
Yes. I'll spend a little more time trying to build on other architectures. I normally like to add COMPILE_TEST.
-Alex
PATCH 12/12 arm64: dts: qcom: qcs6490-rb3gen2: enable TC9564 with a single QCS8081 phy
In reply to Alex ElderFrom: Daniel Thompson <[email protected]>
The QCS6490 RB3Gen2 includes a Toshiba TC9564 (a.k.a. Qualcomm QPS615). TC9564 is an twin Ethernet-AVB/TSN bridge with an integrated PCIe switch.
There are multiple builds of RB3Gen2 with components included/excluded. That means whether or not there is a phy attached to eMAC0 depends on the exact board. However all versions include a TC9564 combined with a single QCS8081 attached to eMAC1.
Add properties to the existing PCI nodes to describe how the TC9564 and QCS8081 are connected to each other (and to the host SoC).
(Note: "pci1179,0220" is documented in the "net/toshiba,tc956x-dwmac.yaml" binding, but checkpatch.pl doesn't recognize that.)
--- arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts | 45 +++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-)
arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts +44 -1
@@ -308,6 +308,16 @@ vdd_ntn_1p8: regulator-vdd-ntn-1p8 { regulator-enable-ramp-delay = <10000>; }; + qep_1p8: regulator-qep-1p8 { + compatible = "regulator-fixed"; + regulator-name = "qep_1p8"; + gpio = <&pm7325_gpios 8 GPIO_ACTIVE_HIGH>; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <1800000>; + enable-active-high; + regulator-always-on; + }; + wcn6750-pmu { compatible = "qcom,wcn6750-pmu"; pinctrl-0 = <&bt_en>;
@@ -937,20 +947,46 @@ pcie@3,0 { ranges; bus-range = <0x5 0xff>; - pci@0,0 { + tc956x_emac0: pci@0,0 { + compatible = "pci1179,0220"; reg = <0x50000 0x0 0x0 0x0 0x0>; #address-cells = <3>; #size-cells = <2>; device_type = "pci"; ranges; + + gpio-controller; + #gpio-cells = <2>; }; pci@0,1 { + compatible = "pci1179,0220"; reg = <0x50100 0x0 0x0 0x0 0x0>; #address-cells = <3>; #size-cells = <2>; device_type = "pci"; ranges; + + phy-mode = "sgmii"; + phy-handle = <&tc956x_emac1_phy>; + + mdio { + compatible = "snps,dwmac-mdio"; + #address-cells = <1>; + #size-cells = <0>; + + tc956x_emac1_phy: ethernet-phy@1c { + compatible = "ethernet-phy-id004d.d101"; + reg = <0x1c>; + reset-gpios = <&tc956x_emac0 1 GPIO_ACTIVE_LOW>; + reset-assert-us = <20>; + reset-deassert-us = <20>; + + pinctrl-names = "default"; + pinctrl-0 = <&qep_irq_pin>; + interrupts-extended = <&tlmm 101 IRQ_TYPE_EDGE_FALLING>; + }; + }; }; }; };
@@ -1524,6 +1560,13 @@ usb_hub_reset_state: usb-hub-reset-state { drive-strength = <2>; bias-disable; }; + + qep_irq_pin: qep-irq-state { + pins = "gpio101"; + function = "gpio"; + drive-strength = <2>; + bias-disable; + }; }; &lpass_audiocc {
Signature · 1 line
2.51.0
Andrew Lunn
maintainerRe: [PATCH net-next 12/12] arm64: dts: qcom: qcs6490-rb3gen2: enable TC9564 with a single QCS8081 phy
arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts pcie@3,0 { · line 987
Quoted 10 lines
arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts +10
-0+ tc956x_emac1_phy: ethernet-phy@1c { + compatible = "ethernet-phy-id004d.d101"; + reg = <0x1c>; + reset-gpios = <&tc956x_emac0 1 GPIO_ACTIVE_LOW>; + reset-assert-us = <20>; + reset-deassert-us = <20>; + + pinctrl-names = "default"; + pinctrl-0 = <&qep_irq_pin>; + interrupts-extended = <&tlmm 101 IRQ_TYPE_EDGE_FALLING>;
What is probably wrong. PHY interrupts are level, not edge.
Andrew
Re: [PATCH net-next 12/12] arm64: dts: qcom: qcs6490-rb3gen2: enable TC9564 with a single QCS8081 phy
Quoted 4 lines · Andrew Lunn
Quoted 4 lines
arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts +4
-0+ tc956x_emac1_phy: ethernet-phy@1c { + compatible = "ethernet-phy-id004d.d101"; + reg = <0x1c>; + reset-gpios = <&tc956x_emac0 1 GPIO_ACTIVE_LOW>;
Quoted 8 lines
arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts pcie@3,0 { · line 987
Quoted 6 lines
arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts +6
-0+ reset-assert-us = <20>; + reset-deassert-us = <20>; + + pinctrl-names = "default"; + pinctrl-0 = <&qep_irq_pin>; + interrupts-extended = <&tlmm 101 IRQ_TYPE_EDGE_FALLING>;What is probably wrong. PHY interrupts are level, not edge.
Thanks (and agree). Will fix.
Daniel.
Re: [PATCH net-next 12/12] arm64: dts: qcom: qcs6490-rb3gen2: enable TC9564 with a single QCS8081 phy
In reply to Alex ElderHi Alex,
Quoted 13 lines · Alex Elder
From: Daniel Thompson <[email protected]>
The QCS6490 RB3Gen2 includes a Toshiba TC9564 (a.k.a. Qualcomm QPS615). TC9564 is an twin Ethernet-AVB/TSN bridge with an integrated PCIe switch.
There are multiple builds of RB3Gen2 with components included/excluded. That means whether or not there is a phy attached to eMAC0 depends on the exact board. However all versions include a TC9564 combined with a single QCS8081 attached to eMAC1.
Add properties to the existing PCI nodes to describe how the TC9564 and QCS8081 are connected to each other (and to the host SoC).
Quoted 6 lines
(Note: "pci1179,0220" is documented in the "
net/toshiba,tc956x-dwmac.yaml" binding, but checkpatch.pl doesn't recognize that.)Co-developed-by Alex Elder <[email protected]>Signed-off-by Alex Elder <[email protected]>Signed-off-by Daniel Thompson <[email protected]>
There's a minor typo in the PHY name - QCS8081 instead of QCA8081.
Ayaan
Re: [PATCH net-next 12/12] arm64: dts: qcom: qcs6490-rb3gen2: enable TC9564 with a single QCS8081 phy
Quoted 15 lines · Mohd Ayaan Anwar
Hi Alex,
Quoted 13 lines · Alex Elder
From: Daniel Thompson <[email protected]>
The QCS6490 RB3Gen2 includes a Toshiba TC9564 (a.k.a. Qualcomm QPS615). TC9564 is an twin Ethernet-AVB/TSN bridge with an integrated PCIe switch.
There are multiple builds of RB3Gen2 with components included/excluded. That means whether or not there is a phy attached to eMAC0 depends on the exact board. However all versions include a TC9564 combined with a single QCS8081 attached to eMAC1.
Add properties to the existing PCI nodes to describe how the TC9564 and QCS8081 are connected to each other (and to the host SoC).
Quoted 8 lines
Quoted 6 lines
(Note: "pci1179,0220" is documented in the "
net/toshiba,tc956x-dwmac.yaml" binding, but checkpatch.pl doesn't recognize that.)Co-developed-by Alex Elder <[email protected]>Signed-off-by Alex Elder <[email protected]>Signed-off-by Daniel Thompson <[email protected]>There's a minor typo in the PHY name - QCS8081 instead of QCA8081.
OK, I'll fix that too. Thanks a lot Ayaan.
-Alex
Quoted 2 lines
Ayaan
Re: [PATCH net-next 12/12] arm64: dts: qcom: qcs6490-rb3gen2: enable TC9564 with a single QCS8081 phy
In reply to Alex ElderQuoted 10 lines · Alex Elder
From: Daniel Thompson <[email protected]>
The QCS6490 RB3Gen2 includes a Toshiba TC9564 (a.k.a. Qualcomm QPS615). TC9564 is an twin Ethernet-AVB/TSN bridge with an integrated PCIe switch.
There are multiple builds of RB3Gen2 with components included/excluded. That means whether or not there is a phy attached to eMAC0 depends on the exact board. However all versions include a TC9564 combined with a single QCS8081 attached to eMAC1.
Quoted 5 lines
Add properties to the existing PCI nodes to describe how the TC9564 and QCS8081 are connected to each other (and to the host SoC).
(Note: "pci1179,0220" is documented in the "
net/toshiba,tc956x-dwmac.yaml" binding, but checkpatch.pl doesn't recognize that.)
This should probably go under the --- line
[...]
arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts vdd_ntn_1p8: regulator-vdd-ntn-1p8 { · line 319
Quoted 9 lines
arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts +9
-0+ qep_1p8: regulator-qep-1p8 { + compatible = "regulator-fixed"; + regulator-name = "qep_1p8"; + gpio = <&pm7325_gpios 8 GPIO_ACTIVE_HIGH>; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <1800000>; + enable-active-high; + regulator-always-on; + };
If I'm reading the schematics right, this is only required for the PHY
- is it collapsible, or does it really need to be a-on?
[...]
arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts usb_hub_reset_state: usb-hub-reset-state { · line 1568
Quoted 5 lines
arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts +5
-0+ qep_irq_pin: qep-irq-state { + pins = "gpio101"; + function = "gpio"; + drive-strength = <2>; + bias-disable;
There's no pull-up onboard, should we use the on-chip one?
Konrad
Re: [PATCH net-next 12/12] arm64: dts: qcom: qcs6490-rb3gen2: enable TC9564 with a single QCS8081 phy
Quoted 11 lines · Konrad Dybcio
Quoted 10 lines · Alex Elder
From: Daniel Thompson <[email protected]>
The QCS6490 RB3Gen2 includes a Toshiba TC9564 (a.k.a. Qualcomm QPS615). TC9564 is an twin Ethernet-AVB/TSN bridge with an integrated PCIe switch.
There are multiple builds of RB3Gen2 with components included/excluded. That means whether or not there is a phy attached to eMAC0 depends on the exact board. However all versions include a TC9564 combined with a single QCS8081 attached to eMAC1.
Quoted 7 lines
Quoted 5 lines
Add properties to the existing PCI nodes to describe how the TC9564 and QCS8081 are connected to each other (and to the host SoC).
(Note: "pci1179,0220" is documented in the "
net/toshiba,tc956x-dwmac.yaml" binding, but checkpatch.pl doesn't recognize that.)This should probably go under the --- line
I'll leave that with Alex...
Quoted 4 lines
Quoted 4 lines
arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts +4
-0+ qep_1p8: regulator-qep-1p8 { + compatible = "regulator-fixed"; + regulator-name = "qep_1p8"; + gpio = <&pm7325_gpios 8 GPIO_ACTIVE_HIGH>;
Quoted 8 lines
arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts vdd_ntn_1p8: regulator-vdd-ntn-1p8 { · line 319
Quoted 5 lines
arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts +5
-0+ regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <1800000>; + enable-active-high; + regulator-always-on; + };If I'm reading the schematics right, this is only required for the PHY
- is it collapsible, or does it really need to be a-on?
It could be turned off if the socket isn't in use but it would prevent hotplug detection from working. In practice that means it can only collapse during suspend/resume.
However the real reason we jammed this on is because I couldn't find a way to get the phy/mdio code to turn one on. However it is possible to add regulator support to MDIO devices by extending their existing logic to manage resets so it can also manage a regulator. It comes out fairly clean so we can add that to the patch set and remove the regulator-always-on.
Quoted 7 lines
arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts usb_hub_reset_state: usb-hub-reset-state { · line 1568
Quoted 5 lines
arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts +5
-0+ qep_irq_pin: qep-irq-state { + pins = "gpio101"; + function = "gpio"; + drive-strength = <2>; + bias-disable;There's no pull-up onboard, should we use the on-chip one?
It is configured the same as lt9611_irq_pin (which I couldn't see a pull-up for).
I switched the interrupt trigger to active-low based on other feedback on the patchset and the counts in /proc/interrupts remain unchanged (with a single figure value). It certainly doesn't look like the irq line floats when the PHY interrupt is deasserted.
Daniel.
Andrew Lunn
maintainerRe: [PATCH net-next 12/12] arm64: dts: qcom: qcs6490-rb3gen2: enable TC9564 with a single QCS8081 phy
Quoted 6 lines
However the real reason we jammed this on is because I couldn't find a way to get the phy/mdio code to turn one on. However it is possible to add regulator support to MDIO devices by extending their existing logic to manage resets so it can also manage a regulator. It comes out fairly clean so we can add that to the patch set and remove the regulator-always-on.
We, I have rejected this before. It might look clean and easy, but it is not. How do you determine the order of enabling reset, regulators clocks? How do you specify the need sleeps in between these different operations?
There is nothing in particular MDIO specific here, and there is generic power sequencing code in the kernel. And a while back, somebody said they would look at what is needed to make MDIO busses and Ethernet PHYs make use of that generic power sequencing code. That is the better way to do this.
Andrew
Re: [PATCH net-next 12/12] arm64: dts: qcom: qcs6490-rb3gen2: enable TC9564 with a single QCS8081 phy
Quoted 11 lines · Andrew Lunn
Quoted 6 lines
However the real reason we jammed this on is because I couldn't find a way to get the phy/mdio code to turn one on. However it is possible to add regulator support to MDIO devices by extending their existing logic to manage resets so it can also manage a regulator. It comes out fairly clean so we can add that to the patch set and remove the regulator-always-on.
We, I have rejected this before. It might look clean and easy, but it is not. How do you determine the order of enabling reset, regulators clocks? How do you specify the need sleeps in between these different operations?
I agree it is only easy for the easy cases. I can even be specific that, for me, the easy cases mean enabling a single regulator and where power-on reset is not significantly slower than reset-pin reset meaning we don’t need to distinguish between a power-cycling reset and a reset-pin reset).
However I think that complex cases cannot be handled by generic MDIO code. I think these cases are best solved from the MDIO probe method of individual PHY drivers.
Quoted 5 lines
There is nothing in particular MDIO specific here, and there is generic power sequencing code in the kernel. And a while back, somebody said they would look at what is needed to make MDIO busses and Ethernet PHYs make use of that generic power sequencing code. That is the better way to do this.
I’d love to know if they got anywhere. I’ve reviewed the pwrseq subsystem and I don’t think it is intended to solve the problems presented by the ethernet phys on a rb3gen2. Let me try to explain my reasoning. Maybe someone will be able to point out what I have missed!
I’m afraid this must be necessarily long but to help navigate the general structure is:
1. Quick review of the pwrseq subsystem
2. Quick review of the PCI power control driver, both the concept and to note why some PCI power control drivers do not use pwrseq
3. Summarize how this works on DT
4. Introduce a description of an qca8081 in “modern devicetree”
5. Examine whether pwrseq or the power control driver concept would make writing MDIO device drivers easier than “just doing it in the probe method”
pwrseq is only generic in the sense that has a compact consumer API and that it provides reusable tools that allow *specific* power sequencing drivers to be written relatively easily. The specific drivers created with these tools typically bind to something concrete in the DT (e.g. compatible = "pcie-m2-m-connector" or "qcom,wcn6855-pmu"): things you can point to such as the M.2 slot or a special purpose power management unit in a combo chip.
The pwrseq core allows each driver to register a .match() method to allow pwrseq driver recognise that another driver has asked for its help to enable a pwrseq target. They usually match, not by compatible but by traversing the phandle relationships from the device’s DT node to verify that they link back to the pwrseq driver in the expected manner.
For ethernet phys I'm doubtful pwrseq offers any benefit because most phys are standalone and therefore just get a bunch of board level
regulators: there isn’t anything concrete in the DT for which we can instantiate a pwrseq device. Without a device it is difficult to fire up a driver that is responsible for knowing what power sequence is needed to activate the phy. It is therefore better to encode this knowledge in the phy driver instead.
Another related-but-different concept is PCI power control drivers. When pwrseq was introduced the first client was a PCI power control driver. PCI power control drivers are used to solve chicken-and-egg bus enumeration problems. They work binding a platform bus driver to any PCI device with a compatible string (e.g. compatible = "pci17cb,1103") before attempting to enumerate the real device. The platform device driver responsible for turning on the power ready for enumeration but does not drive the actual PCI device. This ensures the device can respond to enumeration requests and, eventually, probe the “real” PCI driver.
Note that the PCI power control drivers do not have to use the pwrseq framework to turn the power on. There are examples of both in the current tree:
* pci-pwrctrl-pwrseq.c uses pwrseq and is, at it's core, just table of compatible strings and pwrseq target names. This allows it recognize, from the compatible string what pwrseq target to request. For example on wcn6855 it can request that only the WLAN hardware be enabled (BT power-on is requested separately before using the HCI UART).
* pci-pwrctrl-tc9563.c is the power controller driver for the TC956x PCIe switch. This is an example of the case where there is nothing for a pwrseq driver to bind to. TC956x just gets a bunch of individual regulators and a reset line. For that reason pci-pwrctrl-tc9563 just uses the regular C code to grab everything is needs, relying on things like the bulk regulator helpers keep the code as compact as possible.
One key insight about the above is that there are three separate device drivers parsing specific properties of the node. Having all the properties related to a device in a single node was very strongly pushed for by Rob H[1] and AFAIK is a key expectation for new DT bindings. This strongly influences the scope of pwrseq and PCI power control (and power domains) and discourages giving DT a generic means to express power sequencing. That knowledge is handed to us implicitly by the compatible string!
For example, in the case of WCN6855[2] we have:
1. pci-pwrctrl-pwrseq which uses the compatible string to get itself bound and to decide what pwrseq target to enable.
2. pwrseq-qcom-wcn which reads all the *-supply properties together with a couple of clocks and enable lines. It ensures we don't enable anything until the power lines have settled.
3. ath11k[_pci] which isn’t probed until the device is “on” and then reads the remaining properties such as qcom,calibration-variant
[1]: https://lore.kernel.org/all/CAL_JsqLAnJqZ95_bf6_fFmPJFMjuy43UfP2UxzEmFMNnG_t-Ug@mail.gmail.com/
[2]: https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/sc8280xp-lenovo-thinkpad-x13s.dts#L987C1-L1004C3
In short, the pwrseq client API is beguilingly simple but that does not mean the providers are generic. In the above example there must still be something, written in C, that contains knowledge of how to turn on a wcn6855.
Let’s turn our attention to MDIO.
Following the pattern above where all the links related to power come from the main device node, then the phy node for the qca8081 in an rb3gen2 would look like something like this:
tc956x_emac1_phy: ethernet-phy@1c {
compatible = "ethernet-phy-id004d.d101";
reg = <0x1c>;
reset-gpios = <&tc956x_emac0 1 GPIO_ACTIVE_LOW>;
# On RB3gen2 all supplies are controlled by a single GPIO
# so we link all supplies to that single regulator
avdd-supply = <&qep_1p8>;
avdd18-supply = <&qep_1p8>;
vdd-supply = <&qep_1p8>;
vddldo-supply = <&qep_1p8>;
vdd18-supply = <&qep_1p8>;
vdd125-supply = <&qep_1p8>;
pinctrl-names = "default";
pinctrl-0 = <&qep_irq_pin>;
interrupts-extended = <&tlmm 101 IRQ_TYPE_LEVEL_LOW>;
};Once we have established what the DT looks like then the question becomes where to put "something, written in C [or Rust], that contains burned in knowledge of how to turn on a wcn6855^H^H^H^H^H^H^Hqca8081"?
The qca8081 on rb3gen2 just gets a bunch of individual regulators and a reset. As in the pci-pwrctrl-tc9563 example above, this means there is nothing in the DT for a pwrseq driver to bind to. Even if we could find a way to do that, it is not obviously useful to decouple how to turn on an MDIO device from how to drive it. Thus I think the right answer to that is to put the code to fire up the regulators into the qca808x.c driver and it looks to me like the existing probe/remove methods would already work perfectly well as the place to put it.
Does MDIO bus code need to know about pwrseq at all? I don't think so. Perhaps there are phys that are suitable to be managed via pwrseq because they are part of a larger ethernet chip with some kind of PMU, but that doesn’t require it to be exposed outside the driver. The drivers for such a phy can simply call the pwrseq APIs from its probe method.
Do we need something equivalent to PCI power control for the MDIO bus? I don't think the same chicken-and-egg problem actually exists for MDIO bus. If a subnode with a compatible string (and regulators) exists we don't need to scan that address because we already know enough about the bus to probe the driver and therefore can let the driver handle turning on the power (just like we do for I2C or SPI drivers).
MDIO does have bus scanning but we only need to scan for things we don’t know about and must do so on the assumption they are already powered on. That’s because when we don’t know what’s there then your earlier question ("How do you determine the order of enabling reset, regulators clocks?") is impossible to answer. There could be a generic bus-supply property to handle easy cases where a single regulator activates everything on the bus although this isn’t needed on RB3gen2 since we statically know what is on the bus.
If you've got this far and not found a fatal mistake in the reasoning then perhaps it sounds like an awful lot of churn to have to modify each PHY driver every time that PHY is used in an embedded platform with software controlled regulators!
That, in a nutshell, is why I was tempted to copy the phy-supply property to cover the "easy cases" we discussed at the outset. Doing so does nothing to impede the hard cases since the code for that would still work fine from the MDIO probe method. At worst a driver might have to register with a flag to suppress any generic power/reset logic from the core (since it's obviously wrong to wait for a reset to complete on a device that isn't powered up).
To be clear I’m very happy to back away from phy-supply. We use the same patterns we see in I2C and SPI drivers and rely purely on probe methods instead to turn on regulators. However I don’t see how to exploit power sequencing code to help describe these things generically.
Daniel.
Andrew Lunn
maintainerRe: [PATCH net-next 12/12] arm64: dts: qcom: qcs6490-rb3gen2: enable TC9564 with a single QCS8081 phy
M> I’m afraid this must be necessarily long but to help navigate the
Quoted 1 line
general structure is:
Thanks for the long email.
Quoted 25 lines
Let’s turn our attention to MDIO.
Following the pattern above where all the links related to power come from the main device node, then the phy node for the qca8081 in an rb3gen2 would look like something like this:
tc956x_emac1_phy: ethernet-phy@1c { compatible = "ethernet-phy-id004d.d101"; reg = <0x1c>; reset-gpios = <&tc956x_emac0 1 GPIO_ACTIVE_LOW>; # On RB3gen2 all supplies are controlled by a single GPIO # so we link all supplies to that single regulator avdd-supply = <&qep_1p8>; avdd18-supply = <&qep_1p8>; vdd-supply = <&qep_1p8>; vddldo-supply = <&qep_1p8>; vdd18-supply = <&qep_1p8>; vdd125-supply = <&qep_1p8>; pinctrl-names = "default"; pinctrl-0 = <&qep_irq_pin>; interrupts-extended = <&tlmm 101 IRQ_TYPE_LEVEL_LOW>; };
Quoted 7 lines
Once we have established what the DT looks like then the question becomes where to put "something, written in C [or Rust], that contains burned in knowledge of how to turn on a wcn6855^H^H^H^H^H^H^Hqca8081"?
The qca8081 on rb3gen2 just gets a bunch of individual regulators and a reset. As in the pci-pwrctrl-tc9563 example above, this means there is nothing in the DT for a pwrseq driver to bind to.
I don't understand that. We have a node in device tree for the PHY. We can put the needed properties there somehow. Maybe similar to how pinctrl works. Before probing the device, the driver core looks for the pinctrl- properties, and activates them. We could have similar properties for power sequencing, before enumerating an address, do whatever the pwrseq-names requests? It might need help for the driver actually enumerating the bus, to point to core at the node.
Quoted 6 lines
Even if we could find
a way to do that, it is not obviously useful to decouple how to turn on an MDIO device from how to drive it. Thus I think the right answer to that is to put the code to fire up the regulators into theqca808x.cdriver and it looks to me like the existing probe/remove methods would already work perfectly well as the place to put it.
But you have a chicken/egg. Same as with PCI, with Ethernet PHYs, you ask the device what it is, and then find a driver to drive it, and then call the probe function. However, if its clock is off, its GPIO reset is held in reset, its power regulators are switch off, it never answers when you ask it, what are you? If you have no idea what it is, you cannot probe it. And if you cannot probe it, the probe function cannot turn all these things on.
The standard reply we have is, ignore the fact the device can be enumerated, hard code in DT what its ID is. And that is what you have above in your DT fragment. But you also need to live with the consequences of it being wrong, since that driver is going to be loaded, no questions asked. And don't think about having a rev A board and a rev B board which have different pin compatible PHYs, and want to use the enumeration to get the correct driver loaded.
DT developers continually want to make use of the enumeration feature, since it is there, part of 802.3, it is how it was done for the first 20 years of networking, etc. And they keep trying to extend the current code to get the PHY running to allow it to be enumerated. And i keep rejecting it.
Ideally, i would like some generic core code which can be given a list of resources, probably phandles, and timing information. And it will walk the list and turn them on, inserting the requested delays. And then we can enumerate the device.
Until such code exists, i agree, forget the device is enumerable, hard code the ID, and get the probe function to enable the regulators, take the device out of reset, enable the clocks, etc. And repeat that in every PHY driver.
Andrew
Re: [PATCH net-next 12/12] arm64: dts: qcom: qcs6490-rb3gen2: enable TC9564 with a single QCS8081 phy
Quoted 29 lines · Andrew Lunn
Quoted 2 lines
I’m afraid this must be necessarily long but to help navigate the general structure is:
Thanks for the long email.
Quoted 24 lines
Let’s turn our attention to MDIO.
Following the pattern above where all the links related to power come from the main device node, then the phy node for the qca8081 in an rb3gen2 would look like something like this:
tc956x_emac1_phy: ethernet-phy@1c { compatible = "ethernet-phy-id004d.d101"; reg = <0x1c>; reset-gpios = <&tc956x_emac0 1 GPIO_ACTIVE_LOW>; # On RB3gen2 all supplies are controlled by a single GPIO # so we link all supplies to that single regulator avdd-supply = <&qep_1p8>; avdd18-supply = <&qep_1p8>; vdd-supply = <&qep_1p8>; vddldo-supply = <&qep_1p8>; vdd18-supply = <&qep_1p8>; vdd125-supply = <&qep_1p8>; pinctrl-names = "default"; pinctrl-0 = <&qep_irq_pin>; interrupts-extended = <&tlmm 101 IRQ_TYPE_LEVEL_LOW>; };
I nearly snipped this... but I referring to *-supplies so often below I decided it was useful to keep it!
Quoted 8 lines
Quoted 7 lines
Once we have established what the DT looks like then the question becomes where to put "something, written in C [or Rust], that contains burned in knowledge of how to turn on a wcn6855^H^H^H^H^H^H^Hqca8081"?
The qca8081 on rb3gen2 just gets a bunch of individual regulators and a reset. As in the pci-pwrctrl-tc9563 example above, this means there is nothing in the DT for a pwrseq driver to bind to.
Quoted 7 lines
I don't understand that. We have a node in device tree for the PHY. We can put the needed properties there somehow. Maybe similar to how pinctrl works. Before probing the device, the driver core looks for the pinctrl- properties, and activates them. We could have similar properties for power sequencing, before enumerating an address, do whatever the pwrseq-names requests? It might need help for the driver actually enumerating the bus, to point to core at the node.
pinctrl properties describe the relationship between the device and the pin controller of its host. In the case above &qep_irq_pin it leads back to something belonging to the pin controller.
Devicetree does have power domains and these are actually pretty similar to pinctrl. power-domains properties are used to essentially used to describe the relationship between the device and a power domain controller.
However in this case power domains don't really fit. There is no power domain controller to link to. Thus I'd still expect the phy power supplies to be modelled in devicetree as I showed above. pwrseq, PCI and USB all adopt this approach for modelling onboard devices in DT.
Quoted 15 lines
Quoted 6 lines
Even if we could find
a way to do that, it is not obviously useful to decouple how to turn on an MDIO device from how to drive it. Thus I think the right answer to that is to put the code to fire up the regulators into theqca808x.cdriver and it looks to me like the existing probe/remove methods would already work perfectly well as the place to put it.But you have a chicken/egg. Same as with PCI, with Ethernet PHYs, you ask the device what it is, and then find a driver to drive it, and then call the probe function. However, if its clock is off, its GPIO reset is held in reset, its power regulators are switch off, it never answers when you ask it, what are you? If you have no idea what it is, you cannot probe it. And if you cannot probe it, the probe function cannot turn all these things on.
Quoted 3 lines
The standard reply we have is, ignore the fact the device can be enumerated, hard code in DT what its ID is. And that is what you have above in your DT fragment.
My comment above about it not being useful to decouple was very much based on this "standard reply".
The *-supply properties will differ from phy to phy so we need the DT to know what device is in order to supply the right properties. In other words de-coupling the parsing of those supply properties (and anything else) does not help MDIO with the chicken/egg problem.
However perhaps I was being a little shortsighted to say there are no benefits (below).
Quoted 5 lines
But you also need to live with the
consequences of it being wrong, since that driver is going to be loaded, no questions asked. And don't think about having a rev A board and a rev B board which have different pin compatible PHYs, and want to use the enumeration to get the correct driver loaded.
Typically embedded platforms "solve" this by having a bootloader retrieve the board revision (usually from whatever non-volatile storage it keeps the mac address) and swap a status = "okay"/status = "disabled" pair in the DT.
This is not great (hence quoting "solve") but it must also be added that this approach does also work when the PHY isn't pin compatible and needs to be powered up differently.
Quoted 5 lines
DT developers continually want to make use of the enumeration feature, since it is there, part of 802.3, it is how it was done for the first 20 years of networking, etc. And they keep trying to extend the current code to get the PHY running to allow it to be enumerated. And i keep rejecting it.
Has someone already tried to "sell" you on approach somewhat similar to the onboard_usb_dev code?
onboard_usb_dev centralizes *all* knowledge of how to turn the regulators, clocks, resets for all soldered down USB devices that need help to be turned on. In the case of USB then it literally examines the list of VID/PID pairs supported by onboard_usb_dev to decide whether to create the platform device used to lubricate things.
This still relies on the "standard reply" meaning it doesn't solve the chicken/egg and it doesn't avoid there being something written in C (or Rust) that knows how to turn on devices. However it does do is move the churn associated with enabling a new USB on an embedded platform out of the USB drivers and into a single centralized place.
With the embedded churn on one place stops "embedded crap" from creeping through the all the drivers. I suspect is also much easier to divide review/maintenance responsibilities.
FWIW I think the relatively simple structure of the MDIO bus means we don't actually have to mess about with platform devices. I think one might be able to get it down to four function calls (which could easily be stubbed out on !CONFIG_OF systems).
Quoted 9 lines
Ideally, i would like some generic core code which can be given a list of resources, probably phandles, and timing information. And it will walk the list and turn them on, inserting the requested delays. And then we can enumerate the device.
Until such code exists, i agree, forget the device is enumerable, hard code the ID, and get the probe function to enable the regulators, take the device out of reset, enable the clocks, etc. And repeat that in every PHY driver.
So, having spent a bit of time thinking about it I do wonder if creating some kind of onboard_mdio.c to collect knowledge of how to turn specific mdio devices on might be better than putting the same knowledge directly into probe functions.
Should generic core code (or library functons) ever arrive then having this code centralized between phys would make adopting the generic code code easier.
I'm not overly attached to either idea but if you'd like me to sketch out a prototype then let me know!
Daniel.
Jakub Kicinski
maintainerQuoted 7 lines · On Fri, 1 May 2026 10:54:08 -0500 Alex Elder wrote:
create mode 100644 Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yaml create mode 100644 drivers/gpio/gpio-tc956x.c create mode 100644 drivers/misc/tc956x_pci.c create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.c create mode 100644 drivers/net/pcs/pcs-xpcs-regmap.c create mode 100644 include/linux/pcs/pcs-xpcs-regmap.h create mode 100644 include/soc/toshiba/tc956x-dwmac.h
Please add an entry to MAITNAINERS for tx956x stuff?
Quoted 10 lines · Jakub Kicinski
Quoted 7 lines · On Fri, 1 May 2026 10:54:08 -0500 Alex Elder wrote:
create mode 100644
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yamlcreate mode 100644drivers/gpio/gpio-tc956x.c
create mode 100644drivers/misc/tc956x_pci.c
create mode 100644drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.ccreate mode 100644drivers/net/pcs/pcs-xpcs-regmap.c
create mode 100644include/linux/pcs/pcs-xpcs-regmap.h
create mode 100644include/soc/toshiba/tc956x-dwmac.hPlease add an entry to MAITNAINERS for tx956x stuff?
OK, I'll do that for the next version of the series. Thanks.
-Alex
Quoted 8 lines · Alex Elder
This series introduces stmmac driver support for the Toshiba TC9564 (also known as Qualcomm QPS615). This is an Ethernet-AVB/TSN bridge IC that provides a high-speed connection between a host SoC and Ethernet devices on a network. It incorporates a PCIe switch, and implements two 10 Gbps capable Ethernet MACs (along with other IP blocks), and is essentially a small and highly-specialized SoC. The TC9564 is a member of a family of similar chips, and the driver code uses "tc956x" to reflect this.
I'm writing now to just state what the plan is for version 2 of this series. I had hoped to get something out this week, but it won't be available today, so I wanted to at least let people know what to expect.
First, we received a great deal of really good feedback on this series. I/we sincerely appreciate it, and have already addressed almost all of the suggestions people have made.
Andrew Lunn asked a number of questions about the way that the TC956x device is represented, and in particular questioned whether having the GPIO controller as a device subordinate to a PCIe function even made sense. This led to some additional discussion, including some offline work exploring what other options might be reasonable.
The plan for version 2 is to submit it fairly soon, to include updates that address *most* of the feedback received so far. (I have sent e-mail with clear confirmation of what we intend to do--and these changes would be incorporated in version 2).
However, because there remain other outstanding issues, including "big picture" questions about how to represent the hardware, the series will be sent as RFC.
This will allow others to see the changes we made based on feedback, but also makes it clear there is more work that needs to be done before we're confident in our final proposal.
-Alex
Quoted 173 lines
TC956x chips incorporate a PCIe gen 3 switch, with one upstream and three downstream ports. Its PCIe functionality is already supported upstream, including a power control driver that performs some early configuration of the PCI ports ("
pci-pwrctrl-tc9563.c").One of the PCIe switch's downstream ports has an internal PCIe endpoint, which implements two PCIe functions, each of which has an Ethernet MAC (eMAC) subsystem. The eMAC is composed of a Synopsis Designware XGMAC combined with an XPCS and PMA. Each MAC is capable of operating at 10M/100M/1G/2.5G/5Gps and 10Gps. The initial target platform is the Qualcomm RB3gen2, which supports a 10Gbps Marvell PHY on port A, and a 2.5Gbps Qualcomm PHY on port B. (The Marvell PHY is not populated on all RB3gen2 boards, and only 2.5 Gbps support is included initially.)
TC956x chips also implement several other blocks of functionality, including a GPIO controller, interrupt controllers (MSIGEN), I2C and SPI, a UART, and an Arm Cortex M3 CPU with 128KB SRAM. The GPIO interface exposes several lines to manage external resets. The interrupt controllers are used internally by the MAC functions. The UART, SPI, microcontroller, and SRAM are currently unused.
---------------------------------- | Host | ------+...+----------+........+--- |i2c| | PCIe | ----------------+...+----------+........+------ | TC956x |I2C| |upstream| | | ----- --+--------+--- | | ----- ------ ------- | PCIe switch | | | |SPI| |GPIO| |reset| | | | | ----- ------ |clock| | DS3 DS2 DS1 | | | ------- ---++--++--++-- | | ----- ------ downstream// \\ \\ | downstream | |MCU| |SRAM| /==========/ \\ \===== PCIe port 1 | ----- ------ //PCIe port 3 \\ | | || \======= downstream | ----+-----------++-----------+---- | PCIe port 2 | | M | internal PCIe endpoint | M | | | | S |------------------------| S | ------ | | | I | PCIe | | PCIe | I | |UART| | | | G |function 0| |function 1| G | ------ | | | E |----++----| |----++----| E | | | | N | eMAC 0 | | eMAC 1 | N | | --------+.......+------+.....+----------------- |USXGMII| |SGMII| --+.......+-- --+.....+-- | ARQ113C | | QEP8121 | | PHY | | PHY | ------------- -----------The primary objective for this series is to support the Ethernet functionality provided by the TC956x. The code providing this support has been structured into three distinct modules.
- A driver for the GPIO controller
- Code enabling the TC956x-specific eMAC/MSIGEN hardware
- A "chip" driver, associated with the PCIe functionsThe GPIO driver is implemented separately because in some hardware configurations, these GPIO lines are used to manage resets for external Ethernet PHYs. We describe these PHYs via devicetree, where the GPIO-based reset signals are defined using phandles.
The code for the eMAC/MSIGEN consists of a new source file that populates hardware-specific details about the two MACs, and integrates with the existing stmmac driver. This also required implementing some enhancements to the core stmmac driver, described further below.
To manage the common functionality (including configuring address translation and controlling internal reset and clock signals), a "chip" driver is implemented. This chip driver is associated with the PCIe function *itself*, not the eMAC associated with the function.
The driver binds to the internal PCI functions 0 and 1, and creates a shared data structure describing the common chip elements the two driver instances share. Three auxiliary bus devices are created to represent the GPIO controller and the two Synopsys MAC controllers.
The driver instance for PCIe function 0 has responsibility for controlling the common chip functionality--creating the GPIO controller auxiliary device, configuring address translation between PCIe address space and internal addresses, and controlling clocks and resets. It creates a data structure--shared via its platform data pointer with PCIe function 1--to represent shared "chip" information. In addition, PCIe function 0 creates an auxiliary device to represent its attached eMAC. It allocates IRQs and maps BAR address ranges for use by the stmmac driver, passing them in a structure via the auxiliary device's platform data.
PCIe function 1 defers probing until after PCIe function 0 has created the shared data structure. After that its only job is to set up IRQs and mapped memory and create the eMAC1 auxiliary device.
The version of the Synopsys MAC IP is 3.01, which is largely compatible with version 2.20. The core stmmac driver required several changes to enable support for the TC956x.
- A change to dwxgmac2 support changes the interrupt mode whenmulti_msi_enis enabled.
- While most support for version 3.01 simply uses the 2.20 code, an erratum related to the RX ring length is implemented for 3.01 DMA operations.
- Having the PCIe device be separate from an auxiliarly device implementing the eMAC required allowing a distinct DMA device to be maintained for an stmmac interface.In addition:
- A new source file provides memory-mapped access to XPCS using regmap. The alignment of the TC956x MDIO registers aren't suitable for using simple MMIO.
- Two additional XPCS changes are implemented that provides support for the XPCS as implemented in the TC956x.This series is available here:
https://github.com/riscstar/linux/tree/tc956x/stmmac-v1-Alex (and Daniel)
Alex Elder (3):
net: stmmac: dma: create a separate dma_device pointer gpio: tc956x: add TC956x/QPS615 support misc: tc956x_pci: add TC956x/QPS615 supportDaniel Thompson (9):
net: pcs: pcs-xpcs-regmap: support XPCS memory-mapped MDIO bus via
regmap
net: pcs: pcs-xpcs: select operating mode for 10G-baseR capable PCS
net: pcs: pcs-xpcs: PreserveBMCR_ANENBLEduring link up
net: stmmac: dwxgmac2: Add multi MSI interrupt mode
net: stmmac: dwxgmac2: Add XGMAC 3.01a support
net: stmmac: dwxgmac2: export symbols for XGMAC 3.01a DMA
dt-bindings: net: toshiba,tc965x-dwmac: add TC956x Ethernet bridge
net: stmmac: tc956x: add TC956x/QPS615 support
arm64: dts: qcom: qcs6490-rb3gen2: enable TC9564 with a single QCS8081
phy.../bindings/net/toshiba,tc956x-dwmac.yaml | 111 +++ arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts | 45 +- drivers/gpio/Kconfig | 11 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-tc956x.c | 209 +++++ drivers/misc/Kconfig | 10 + drivers/misc/Makefile | 1 + drivers/misc/tc956x_pci.c | 667 +++++++++++++++ drivers/net/ethernet/stmicro/stmmac/Kconfig | 13 + drivers/net/ethernet/stmicro/stmmac/Makefile | 2 + .../net/ethernet/stmicro/stmmac/chain_mode.c | 12 +- .../ethernet/stmicro/stmmac/dwmac-tc956x.c | 791 ++++++++++++++++++ .../net/ethernet/stmicro/stmmac/dwxgmac2.h | 12 + .../ethernet/stmicro/stmmac/dwxgmac2_core.c | 1 + .../ethernet/stmicro/stmmac/dwxgmac2_descs.c | 1 + .../ethernet/stmicro/stmmac/dwxgmac2_dma.c | 78 +- .../net/ethernet/stmicro/stmmac/ring_mode.c | 12 +- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 1 + .../net/ethernet/stmicro/stmmac/stmmac_main.c | 59 +- .../net/ethernet/stmicro/stmmac/stmmac_xdp.c | 2 +- drivers/net/pcs/Makefile | 4 +- drivers/net/pcs/pcs-xpcs-regmap.c | 203 +++++ drivers/net/pcs/pcs-xpcs.c | 43 +- include/linux/pcs/pcs-xpcs-regmap.h | 20 + include/linux/stmmac.h | 1 + include/soc/toshiba/tc956x-dwmac.h | 84 ++ 26 files changed, 2341 insertions(+), 53 deletions(-)create mode 100644
Documentation/devicetree/bindings/net/toshiba,tc956x-dwmac.yamlcreate mode 100644drivers/gpio/gpio-tc956x.c
create mode 100644drivers/misc/tc956x_pci.c
create mode 100644drivers/net/ethernet/stmicro/stmmac/dwmac-tc956x.ccreate mode 100644drivers/net/pcs/pcs-xpcs-regmap.c
create mode 100644include/linux/pcs/pcs-xpcs-regmap.h
create mode 100644include/soc/toshiba/tc956x-dwmac.hbase-commit:
254f49634ee16a731174d2ae34bc50bd5f45e731