* [PATCH net-next 0/3] Add Cortina Systems CS7542 MDIO controller support
@ 2026-11-23 18:41 Fil Dunsky via B4 Relay
2026-11-23 18:41 ` [PATCH net-next 1/3] dt-bindings: net: Add Cortina CS7542 MDIO controller Fil Dunsky via B4 Relay
` (2 more replies)
0 siblings, 3 replies; 12+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-11-23 18:41 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Andrew Lunn,
Heiner Kallweit, Russell King, Andrew Lunn
Cc: netdev, devicetree, linux-kernel
Add an independent Clause 22 MDIO driver for the CS7542 controller used by
Securifi Almond+. The series is based on Linux v7.4-rc4 and has no platform
or ARCH_CORTINA_ACCESS dependency. It is intended for net-next.
Enable manual operation while retaining the prescaler initialized by
firmware and all unrelated configuration bits. The factory bootloader and
vendor driver set the prescaler to 0x20 on this board; the source clock and
exact divisor formula are not documented by the material available here.
Accordingly, this version does not advertise programmable clock-frequency
or preamble suppression. It does not claim Clause 45 support.
Poll short transfers with bounded microsecond waits. A timed-out transfer
remains pending until completion; a later operation cannot replace its
address and consume a stale completion. Device-managed bus allocation and
registration handle probe cleanup and removal.
Validation:
- Full independent ARM vmlinux and modules builds, driver both =y and =m,
COMPILE_TEST=n, without the platform series.
- Binding schema/example and strict source checkpatch pass.
- Actual read/write/wait functions: 5125 address, data, timeout and recovery
cases with mocked MMIO under UBSAN.
- Linux 7.4-rc4 booted in RAM on Almond+. Read PHY ID 004d:d036, performed
an unchanged-value advertisement write/readback and preserved CFG=00200001.
- A RAM-only test slowed the prescaler to induce a real -ETIMEDOUT, restored
the original setting and verified both PHY ID registers again. All hardware
checks passed and the board returned to installed OpenWrt 6.18.64.
No kernel image was installed by these tests. The hardware-test helper and
board integration are not part of the series.
---
Fil Dunsky (3):
dt-bindings: net: Add Cortina CS7542 MDIO controller
net: mdio: Add Cortina CS7542 bus controller
MAINTAINERS: Add Cortina CS7542 MDIO controller entry
.../bindings/net/cortina,cs7542-mdio.yaml | 48 ++++++++
MAINTAINERS | 7 ++
drivers/net/mdio/Kconfig | 13 ++
drivers/net/mdio/Makefile | 1 +
drivers/net/mdio/mdio-cs75xx.c | 136 +++++++++++++++++++++
5 files changed, 205 insertions(+)
---
base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
change-id: 20261123-b4-cs7542-mdio-ec44e757e824
Best regards,
--
Fil Dunsky <filipp.dunsky@gmail.com>
^ permalink raw reply [flat|nested] 12+ messages in thread* [PATCH net-next 1/3] dt-bindings: net: Add Cortina CS7542 MDIO controller 2026-11-23 18:41 [PATCH net-next 0/3] Add Cortina Systems CS7542 MDIO controller support Fil Dunsky via B4 Relay @ 2026-11-23 18:41 ` Fil Dunsky via B4 Relay 2026-11-24 19:07 ` netdev-bot+sashiko 2026-11-23 18:41 ` [PATCH net-next 2/3] net: mdio: Add Cortina CS7542 bus controller Fil Dunsky via B4 Relay 2026-11-23 18:41 ` [PATCH net-next 3/3] MAINTAINERS: Add Cortina CS7542 MDIO controller entry Fil Dunsky via B4 Relay 2 siblings, 1 reply; 12+ messages in thread From: Fil Dunsky via B4 Relay @ 2026-11-23 18:41 UTC (permalink / raw) To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Andrew Lunn, Heiner Kallweit, Russell King, Andrew Lunn Cc: netdev, devicetree, linux-kernel From: Fil Dunsky <filipp.dunsky@gmail.com> Describe the CS7542 Clause 22 MDIO register bank and devices on its bus. The firmware initializes the MDC prescaler, which this interface preserves; clock-frequency and preamble suppression are not supported. Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com> --- .../bindings/net/cortina,cs7542-mdio.yaml | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/Documentation/devicetree/bindings/net/cortina,cs7542-mdio.yaml b/Documentation/devicetree/bindings/net/cortina,cs7542-mdio.yaml new file mode 100644 index 000000000..77b5e2f09 --- /dev/null +++ b/Documentation/devicetree/bindings/net/cortina,cs7542-mdio.yaml @@ -0,0 +1,48 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/cortina,cs7542-mdio.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Cortina Systems CS7542 MDIO controller + +maintainers: + - Fil Dunsky <filipp.dunsky@gmail.com> + +description: + Clause 22 MDIO controller. Firmware configures the MDC prescaler before + the operating system starts; the driver retains this setting. + +allOf: + - $ref: mdio.yaml# + +properties: + compatible: + const: cortina,cs7542-mdio + + reg: + maxItems: 1 + + clock-frequency: false + suppress-preamble: false + +required: + - compatible + - reg + - "#address-cells" + - "#size-cells" + +unevaluatedProperties: false + +examples: + - | + mdio@f00700a0 { + compatible = "cortina,cs7542-mdio"; + reg = <0xf00700a0 0x14>; + #address-cells = <1>; + #size-cells = <0>; + + ethernet-phy@0 { + reg = <0>; + }; + }; -- 2.53.0 ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 1/3] dt-bindings: net: Add Cortina CS7542 MDIO controller 2026-11-23 18:41 ` [PATCH net-next 1/3] dt-bindings: net: Add Cortina CS7542 MDIO controller Fil Dunsky via B4 Relay @ 2026-11-24 19:07 ` netdev-bot+sashiko 2026-11-24 19:28 ` Andrew Lunn 0 siblings, 1 reply; 12+ messages in thread From: netdev-bot+sashiko @ 2026-11-24 19:07 UTC (permalink / raw) To: filipp.dunsky Cc: davem, edumazet, kuba, pabeni, robh, krzk+dt, conor+dt, andrew, hkallweit1, linux, andrew+netdev, netdev, devicetree, linux-kernel Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 1 · Low: 1 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [Medium] The binding states the CS7542 MDIO block has an MDC prescaler. - [Low] The CS7542 MDIO binding (Documentation/devicetree/bindings/net/cortina,cs7542-mdio.yaml)… -- dt-bindings: net: Add Cortina CS7542 MDIO controller This adds a YAML binding for the Cortina CS7542 Clause 22 MDIO controller. The binding references mdio.yaml and requires compatible, reg and the cell properties. It disallows clock-frequency and suppress-preamble because the MDC prescaler set by firmware is kept as is. > diff --git a/Documentation/devicetree/bindings/net/cortina,cs7542-mdio.yaml b/Documentation/devicetree/bindings/net/cortina,cs7542-mdio.yaml > new file mode 100644 > index 0000000000000..77b5e2f09f423 > --- /dev/null > +++ b/Documentation/devicetree/bindings/net/cortina,cs7542-mdio.yaml > @@ -0,0 +1,48 @@ [ ... ] > +description: > + Clause 22 MDIO controller. Firmware configures the MDC prescaler before > + the operating system starts; the driver retains this setting. > + > +allOf: > + - $ref: mdio.yaml# > + > +properties: > + compatible: > + const: cortina,cs7542-mdio > + > + reg: > + maxItems: 1 > + > + clock-frequency: false > + suppress-preamble: false [Severity: Low] Do these two false constraints describe a hardware limit, or only what the current driver does? The description talks about what "the driver retains". The MDC prescaler also looks like a programmable register. cs75xx_mdio_probe() in drivers/net/mdio/mdio-cs75xx.c, added later in this series, reads it and writes it back: cfg = readl(priv->base + PER_MDIO_CFG); /* The firmware configures the MDC rate; retain its prescaler. */ cfg |= MDIO_CFG_MANUAL; writel(cfg, priv->base + PER_MDIO_CFG); So the hardware seems able to set the MDC rate. Rejecting clock-frequency then only reflects that the Linux driver doesn't implement it. Nothing in the binding says the hardware can't suppress the preamble either. Documentation/devicetree/bindings/writing-bindings.rst says bindings should not refer to Linux or "device driver". It also says they should be based on what the hardware has, not on what an OS and driver currently support. With this binding, a board whose PHYs need a different MDC rate has no valid way to say so. dt_binding_check also rejects these standard mdio.yaml properties. The commit message has the same problem: clock-frequency and preamble suppression are not supported. This reads like a hardware limitation. Could the description be reworded to describe the hardware? And could the false entries be dropped unless the hardware really lacks these features? > + > +required: > + - compatible > + - reg > + - "#address-cells" > + - "#size-cells" > + > +unevaluatedProperties: false [Severity: Medium] Is this schema missing an input clock, and possibly a reset? The description says the block has an MDC prescaler, which means it divides some input clock. The schema only adds compatible and reg on top of mdio.yaml. With unevaluatedProperties: false, any DT node that has a clocks or resets property fails validation. writing-bindings.rst asks for complete bindings in this case: - DO attempt to make bindings complete even if a driver doesn't support some features. cs75xx_mdio_probe(), added later in the series, never gets or enables a clock: priv->base = devm_platform_ioremap_resource(pdev, 0); ... return devm_of_mdiobus_register(dev, bus, dev->of_node); What if a Linux clock driver manages the parent clock? clk_disable_unused() could gate it at late_initcall. Every access would then time out in the readl_poll_timeout_atomic() call in cs75xx_mdio_wait(), and the attached PHYs would be unusable. A rate change on a shared parent clock would also change MDC without notice, since the driver keeps the firmware divider and never recomputes it. That could push MDC above the 2.5 MHz Clause 22 limit. There is no CS7542 clock driver or DTS in the tree yet. So the runtime failure depends on whether that clock can actually be gated or changed. If a required clocks property is added later, though, existing DTs written against this binding would stop validating. Would it be better to describe the clock now? -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123-b4-cs7542-mdio-v1-0-626d0a0e3b4d%40gmail.com ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 1/3] dt-bindings: net: Add Cortina CS7542 MDIO controller 2026-11-24 19:07 ` netdev-bot+sashiko @ 2026-11-24 19:28 ` Andrew Lunn 2026-11-24 19:39 ` Fil Dunsky 0 siblings, 1 reply; 12+ messages in thread From: Andrew Lunn @ 2026-11-24 19:28 UTC (permalink / raw) To: netdev-bot+sashiko Cc: filipp.dunsky, davem, edumazet, kuba, pabeni, robh, krzk+dt, conor+dt, hkallweit1, linux, andrew+netdev, netdev, devicetree, linux-kernel > [Severity: Medium] > Is this schema missing an input clock, and possibly a reset? > > The description says the block has an MDC prescaler, which means it > divides some input clock. The schema only adds compatible and reg on top of > mdio.yaml. With unevaluatedProperties: false, any DT node that has a clocks > or resets property fails validation. It does get messy to add this later, since you have to keep backwards compatibility to old DT blobs which don't have it. If you can add the clock to the SoC .dtsi file now, it will make things simpler later, even if the current driver does not use it. Andrew ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 1/3] dt-bindings: net: Add Cortina CS7542 MDIO controller 2026-11-24 19:28 ` Andrew Lunn @ 2026-11-24 19:39 ` Fil Dunsky 0 siblings, 0 replies; 12+ messages in thread From: Fil Dunsky @ 2026-11-24 19:39 UTC (permalink / raw) To: Andrew Lunn Cc: netdev-bot+sashiko, davem, edumazet, kuba, pabeni, robh, krzk+dt, conor+dt, hkallweit1, linux, andrew+netdev, netdev, devicetree, linux-kernel Hi Andrew, I agree about describing the input clock before the binding is merged. The vendor U-Boot sets bit 5 of the MDC prescaler, and the kernel SDK writes 0x20 to that field. Neither source identifies the clock feeding it. I have not found a CS7542 clock diagram that ties it to the APB clock, so I am checking that connection before adding the phandle to the SoC .dtsi. The U-Boot and SDK sites I checked are below. https://github.com/futuretekinc/cortina/blob/aafa3821f0934eebe8137726d4e6d5994c1ac3fa/u-boot/drivers/net/g2_ni_mfe.c#L724-L727 https://github.com/drvlabo/linux_kernel_cs75xx/blob/8bb3f7dc796a59d992572a118448ba196f547ed6/drivers/net/ethernet/cs752x/src/ni/cs752x_eth.c#L3529-L3534 Thanks, Fil ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH net-next 2/3] net: mdio: Add Cortina CS7542 bus controller 2026-11-23 18:41 [PATCH net-next 0/3] Add Cortina Systems CS7542 MDIO controller support Fil Dunsky via B4 Relay 2026-11-23 18:41 ` [PATCH net-next 1/3] dt-bindings: net: Add Cortina CS7542 MDIO controller Fil Dunsky via B4 Relay @ 2026-11-23 18:41 ` Fil Dunsky via B4 Relay 2026-11-23 19:40 ` Andrew Lunn 2026-11-24 19:07 ` netdev-bot+sashiko 2026-11-23 18:41 ` [PATCH net-next 3/3] MAINTAINERS: Add Cortina CS7542 MDIO controller entry Fil Dunsky via B4 Relay 2 siblings, 2 replies; 12+ messages in thread From: Fil Dunsky via B4 Relay @ 2026-11-23 18:41 UTC (permalink / raw) To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Andrew Lunn, Heiner Kallweit, Russell King, Andrew Lunn Cc: netdev, devicetree, linux-kernel From: Fil Dunsky <filipp.dunsky@gmail.com> Support Clause 22 reads and writes through the CS7542 management interface. Retain the firmware-configured prescaler and unrelated configuration bits while enabling manual operation. Poll short transactions with microsecond delays and a bounded timeout. After a timeout, wait for the outstanding frame before programming another address so a late completion cannot be mistaken for the next transaction. Use managed bus allocation and registration to cover probe failures and removal. Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com> --- drivers/net/mdio/Kconfig | 13 ++++ drivers/net/mdio/Makefile | 1 + drivers/net/mdio/mdio-cs75xx.c | 136 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 150 insertions(+) diff --git a/drivers/net/mdio/Kconfig b/drivers/net/mdio/Kconfig index d44278f26..a20fec805 100644 --- a/drivers/net/mdio/Kconfig +++ b/drivers/net/mdio/Kconfig @@ -291,3 +291,16 @@ config MDIO_BUS_MUX_MMIOREG endmenu endmenu + +config MDIO_CS75XX + tristate "Cortina Systems CS7542 MDIO controller" + depends on OF_MDIO && HAS_IOMEM + help + Support Clause 22 PHY register access through the CS7542 MDIO + controller, retaining the prescaler configured by platform firmware. + Transactions use bounded polling and recover from late completion. + Device Tree describes the PHYs sharing this management bus. + + To compile this driver as a module, choose M here: the module + will be called mdio-cs75xx. + diff --git a/drivers/net/mdio/Makefile b/drivers/net/mdio/Makefile index 048586746..2afa6066f 100644 --- a/drivers/net/mdio/Makefile +++ b/drivers/net/mdio/Makefile @@ -35,3 +35,4 @@ obj-$(CONFIG_MDIO_BUS_MUX_MESON_G12A) += mdio-mux-meson-g12a.o obj-$(CONFIG_MDIO_BUS_MUX_MESON_GXL) += mdio-mux-meson-gxl.o obj-$(CONFIG_MDIO_BUS_MUX_MMIOREG) += mdio-mux-mmioreg.o obj-$(CONFIG_MDIO_BUS_MUX_MULTIPLEXER) += mdio-mux-multiplexer.o +obj-$(CONFIG_MDIO_CS75XX) += mdio-cs75xx.o diff --git a/drivers/net/mdio/mdio-cs75xx.c b/drivers/net/mdio/mdio-cs75xx.c new file mode 100644 index 000000000..0761d3cef --- /dev/null +++ b/drivers/net/mdio/mdio-cs75xx.c @@ -0,0 +1,136 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <linux/bitfield.h> +#include <linux/bits.h> +#include <linux/io.h> +#include <linux/iopoll.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_mdio.h> +#include <linux/phy.h> +#include <linux/platform_device.h> + +#define PER_MDIO_CFG 0x00 +#define MDIO_CFG_MANUAL BIT(0) +#define PER_MDIO_ADDR 0x04 +#define MDIO_ADDR_PHY GENMASK(4, 0) +#define MDIO_ADDR_REG GENMASK(12, 8) +#define MDIO_ADDR_READ BIT(15) +#define PER_MDIO_WRDATA 0x08 +#define PER_MDIO_RDDATA 0x0c +#define PER_MDIO_CTRL 0x10 +#define MDIO_CTRL_DONE BIT(0) +#define MDIO_CTRL_START BIT(7) + +#define CS75XX_MDIO_TIMEOUT_US 10000 + +struct cs75xx_mdio { + void __iomem *base; + struct mii_bus *bus; + bool pending; +}; + +static int cs75xx_mdio_wait(struct cs75xx_mdio *priv) +{ + u32 val; + int ret; + + ret = readl_poll_timeout_atomic(priv->base + PER_MDIO_CTRL, val, + val & MDIO_CTRL_DONE, 1, + CS75XX_MDIO_TIMEOUT_US); + if (!ret) { + writel(MDIO_CTRL_DONE, priv->base + PER_MDIO_CTRL); + priv->pending = false; + } + return ret; +} + +static int cs75xx_mdio_read(struct mii_bus *bus, int phy, int reg) +{ + struct cs75xx_mdio *priv = bus->priv; + int ret; + + /* A timed-out frame must finish before programming another address. */ + if (priv->pending) { + ret = cs75xx_mdio_wait(priv); + if (ret) + return ret; + } + writel(MDIO_CTRL_DONE, priv->base + PER_MDIO_CTRL); + writel(MDIO_ADDR_READ | FIELD_PREP(MDIO_ADDR_REG, reg) | + FIELD_PREP(MDIO_ADDR_PHY, phy), priv->base + PER_MDIO_ADDR); + priv->pending = true; + writel(MDIO_CTRL_START, priv->base + PER_MDIO_CTRL); + ret = cs75xx_mdio_wait(priv); + if (ret) + return ret; + return readl(priv->base + PER_MDIO_RDDATA) & 0xffff; +} + +static int cs75xx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val) +{ + struct cs75xx_mdio *priv = bus->priv; + int ret; + + if (priv->pending) { + ret = cs75xx_mdio_wait(priv); + if (ret) + return ret; + } + writel(MDIO_CTRL_DONE, priv->base + PER_MDIO_CTRL); + writel(FIELD_PREP(MDIO_ADDR_REG, reg) | FIELD_PREP(MDIO_ADDR_PHY, phy), + priv->base + PER_MDIO_ADDR); + writel(val, priv->base + PER_MDIO_WRDATA); + priv->pending = true; + writel(MDIO_CTRL_START, priv->base + PER_MDIO_CTRL); + return cs75xx_mdio_wait(priv); +} + +static int cs75xx_mdio_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct cs75xx_mdio *priv; + struct mii_bus *bus; + u32 cfg; + + bus = devm_mdiobus_alloc_size(dev, sizeof(*priv)); + if (!bus) + return -ENOMEM; + + priv = bus->priv; + priv->bus = bus; + priv->base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(priv->base)) + return PTR_ERR(priv->base); + + cfg = readl(priv->base + PER_MDIO_CFG); + /* The firmware configures the MDC rate; retain its prescaler. */ + cfg |= MDIO_CFG_MANUAL; + writel(cfg, priv->base + PER_MDIO_CFG); + writel(MDIO_CTRL_DONE, priv->base + PER_MDIO_CTRL); + + bus->name = "cs75xx-mdio"; + bus->read = cs75xx_mdio_read; + bus->write = cs75xx_mdio_write; + bus->parent = dev; + snprintf(bus->id, MII_BUS_ID_SIZE, "%s", dev_name(dev)); + + return devm_of_mdiobus_register(dev, bus, dev->of_node); +} + +static const struct of_device_id cs75xx_mdio_of_match[] = { + { .compatible = "cortina,cs7542-mdio" }, + { } +}; +MODULE_DEVICE_TABLE(of, cs75xx_mdio_of_match); + +static struct platform_driver cs75xx_mdio_driver = { + .probe = cs75xx_mdio_probe, + .driver = { + .name = "cs75xx-mdio", + .of_match_table = cs75xx_mdio_of_match, + }, +}; +module_platform_driver(cs75xx_mdio_driver); + +MODULE_DESCRIPTION("Cortina CS75xx MDIO bus driver"); +MODULE_LICENSE("GPL"); -- 2.53.0 ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 2/3] net: mdio: Add Cortina CS7542 bus controller 2026-11-23 18:41 ` [PATCH net-next 2/3] net: mdio: Add Cortina CS7542 bus controller Fil Dunsky via B4 Relay @ 2026-11-23 19:40 ` Andrew Lunn 2026-11-23 20:41 ` Fil Dunsky 2026-11-24 19:07 ` netdev-bot+sashiko 1 sibling, 1 reply; 12+ messages in thread From: Andrew Lunn @ 2026-11-23 19:40 UTC (permalink / raw) To: filipp.dunsky Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Heiner Kallweit, Russell King, Andrew Lunn, netdev, devicetree, linux-kernel > +++ b/drivers/net/mdio/Kconfig > @@ -291,3 +291,16 @@ config MDIO_BUS_MUX_MMIOREG > > endmenu > endmenu > + > +config MDIO_CS75XX > + tristate "Cortina Systems CS7542 MDIO controller" This file is sorted by tristate string. So this goes between Broadcom UniMAC MDIO bus controller and GPIO lib-based bitbanged MDIO buses MDIO_CAVIUM is an odd ball. I suggest after it. > + depends on OF_MDIO && HAS_IOMEM > + help > + Support Clause 22 PHY register access through the CS7542 MDIO > + controller, retaining the prescaler configured by platform firmware. > + Transactions use bounded polling and recover from late completion. > + Device Tree describes the PHYs sharing this management bus. > + > + To compile this driver as a module, choose M here: the module > + will be called mdio-cs75xx. > + > diff --git a/drivers/net/mdio/Makefile b/drivers/net/mdio/Makefile > index 048586746..2afa6066f 100644 > --- a/drivers/net/mdio/Makefile > +++ b/drivers/net/mdio/Makefile > @@ -35,3 +35,4 @@ obj-$(CONFIG_MDIO_BUS_MUX_MESON_G12A) += mdio-mux-meson-g12a.o > obj-$(CONFIG_MDIO_BUS_MUX_MESON_GXL) += mdio-mux-meson-gxl.o > obj-$(CONFIG_MDIO_BUS_MUX_MMIOREG) += mdio-mux-mmioreg.o > obj-$(CONFIG_MDIO_BUS_MUX_MULTIPLEXER) += mdio-mux-multiplexer.o > +obj-$(CONFIG_MDIO_CS75XX) += mdio-cs75xx.o This file is also sorted. > +struct cs75xx_mdio { > + void __iomem *base; > + struct mii_bus *bus; > + bool pending; This pending is odd. > +static int cs75xx_mdio_wait(struct cs75xx_mdio *priv) > +{ > + u32 val; > + int ret; > + > + ret = readl_poll_timeout_atomic(priv->base + PER_MDIO_CTRL, val, > + val & MDIO_CTRL_DONE, 1, > + CS75XX_MDIO_TIMEOUT_US); > + if (!ret) { > + writel(MDIO_CTRL_DONE, priv->base + PER_MDIO_CTRL); > + priv->pending = false; > + } Have you seen this fail? MDIO busses are simple things, it is just a big shift register. They pretty much don't fail, except if the clock is not ticking. Any failure is generally fatal, and you can expect cascading failures, the next operation is going to fail, and the one after that etc. So i would throw away pending. Andrew --- pw-bot: cr ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 2/3] net: mdio: Add Cortina CS7542 bus controller 2026-11-23 19:40 ` Andrew Lunn @ 2026-11-23 20:41 ` Fil Dunsky 0 siblings, 0 replies; 12+ messages in thread From: Fil Dunsky @ 2026-11-23 20:41 UTC (permalink / raw) To: Andrew Lunn Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Heiner Kallweit, Russell King, netdev, devicetree, linux-kernel Hi Andrew, I have only seen the timeout in a deliberate RAM fault-injection test: I temporarily slowed MDC with the prescaler. I have not observed it at the normal firmware-selected rate. The pending state was intended to handle that injected late completion. I removed that state, kept one bounded transaction/poll per operation, and sorted the Kconfig and Makefile entries as you suggested. Full independent ARM builds with the driver=y and=m and COMPILE_TEST=n pass. The revised driver also passed the Almond+ RAM test: PHY IDs, same-value advertisement write/readback and the controlled MDC timeout/restore. Your Reviewed-by is applied to the MAINTAINERS patch only. I sent v2: https://lore.kernel.org/all/20261123-b4-cs7542-mdio-v2-0-30465e831853@gmail.com/ Thanks, Fil ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 2/3] net: mdio: Add Cortina CS7542 bus controller 2026-11-23 18:41 ` [PATCH net-next 2/3] net: mdio: Add Cortina CS7542 bus controller Fil Dunsky via B4 Relay 2026-11-23 19:40 ` Andrew Lunn @ 2026-11-24 19:07 ` netdev-bot+sashiko 2026-11-24 19:31 ` Andrew Lunn 1 sibling, 1 reply; 12+ messages in thread From: netdev-bot+sashiko @ 2026-11-24 19:07 UTC (permalink / raw) To: filipp.dunsky Cc: davem, edumazet, kuba, pabeni, robh, krzk+dt, conor+dt, andrew, hkallweit1, linux, andrew+netdev, netdev, devicetree, linux-kernel Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 2 · Low: 2 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [Medium] In drivers/net/mdio/mdio-cs75xx.c, a single transaction timeout can leave the MDIO bus permanently unusable. - [Medium] cs75xx_mdio_probe() sets MDIO_CFG_MANUAL while keeping all other firmware CFG bits (lines 105-108). - [Low] In drivers/net/mdio/mdio-cs75xx.c, cs75xx_mdio_wait() polls with readl_poll_timeout_atomic() (1 us udelay steps, 10 ms timeout). - [Low] In drivers/net/mdio/Kconfig, `config MDIO_CS75XX` is added after both `endmenu` lines (lines 292-293). -- net: mdio: Add Cortina CS7542 bus controller This adds a platform MDIO bus driver for the Cortina CS7542. It does Clause 22 reads and writes and keeps the firmware-programmed prescaler while it switches the controller to manual mode. Transactions are polled with a bounded timeout, and a pending flag makes the driver wait for a timed-out frame before it programs the next one. > diff --git a/drivers/net/mdio/Kconfig b/drivers/net/mdio/Kconfig > index d44278f26fabe..a20fec8058da9 100644 > --- a/drivers/net/mdio/Kconfig > +++ b/drivers/net/mdio/Kconfig > @@ -291,3 +291,16 @@ config MDIO_BUS_MUX_MMIOREG > > endmenu > endmenu > + > +config MDIO_CS75XX > + tristate "Cortina Systems CS7542 MDIO controller" > + depends on OF_MDIO && HAS_IOMEM [Severity: Low] Should this entry go inside the "MDIO controller drivers" menu instead of after both endmenu lines? Where it is now, it falls outside that menu and its "depends on PHYLIB", and also outside "MDIO Multiplexers". So it shows up directly under "Network device support" in menuconfig. PHYLIB still applies, but only indirectly through OF_MDIO. The Makefile entry is also added after the mux entries rather than with the other controllers: obj-$(CONFIG_MDIO_CS75XX) += mdio-cs75xx.o This Kconfig hunk also leaves a trailing blank line at the end of the file. Sibling platform controllers (MDIO_AIROHA, MDIO_SUN4I, MDIO_XGENE, MDIO_ASPEED) also use "depends on ARCH_xxx || COMPILE_TEST". No ARCH symbol for this SoC exists in the tree yet, so that gate can't be copied directly. [ ... ] > diff --git a/drivers/net/mdio/mdio-cs75xx.c b/drivers/net/mdio/mdio-cs75xx.c > new file mode 100644 > index 0000000000000..0761d3cefaa4f > --- /dev/null > +++ b/drivers/net/mdio/mdio-cs75xx.c > @@ -0,0 +1,136 @@ [ ... ] > +static int cs75xx_mdio_wait(struct cs75xx_mdio *priv) > +{ > + u32 val; > + int ret; > + > + ret = readl_poll_timeout_atomic(priv->base + PER_MDIO_CTRL, val, > + val & MDIO_CTRL_DONE, 1, > + CS75XX_MDIO_TIMEOUT_US); [Severity: Low] Is the atomic poll variant needed here? The only path to cs75xx_mdio_wait() is through the bus->read and bus->write callbacks, called from __mdiobus_read() and __mdiobus_write(). Those assert that bus->mdio_lock (a mutex) is held and must not be called from interrupt context, so sleeping is allowed here. On a timeout this spins in udelay() for the full 10 ms while holding the mutex. Because of the pending handling in cs75xx_mdio_read() and cs75xx_mdio_write(), every later access spins another 10 ms before it returns -ETIMEDOUT. A bus scan or phylib polling repeats that. Most other drivers in drivers/net/mdio/ (aspeed, hisi-femac, ipq4019, bcm-unimac, iproc, pic64hpsc) use readl_poll_timeout() or read_poll_timeout() instead. > + if (!ret) { > + writel(MDIO_CTRL_DONE, priv->base + PER_MDIO_CTRL); > + priv->pending = false; > + } > + return ret; > +} > + > +static int cs75xx_mdio_read(struct mii_bus *bus, int phy, int reg) > +{ > + struct cs75xx_mdio *priv = bus->priv; > + int ret; > + > + /* A timed-out frame must finish before programming another address. */ > + if (priv->pending) { > + ret = cs75xx_mdio_wait(priv); > + if (ret) > + return ret; > + } [Severity: Medium] Can one timeout leave the bus permanently unusable? priv->pending is set before MDIO_CTRL_START is written. cs75xx_mdio_wait() clears it only when it sees MDIO_CTRL_DONE, so after -ETIMEDOUT it stays true. Every later cs75xx_mdio_read() or cs75xx_mdio_write() takes this branch first. If that wait also times out, the function returns before it touches PER_MDIO_ADDR or PER_MDIO_CTRL, so no new frame is ever started. Nothing else clears pending: there is no bus->reset, no retry limit and no controller re-arm. Suppose the controller never reports DONE for the timed-out frame (START not latched, frame dropped, MDC stopped). Then every access to every PHY on this bus fails with -ETIMEDOUT after a 10 ms spin, until the driver is unbound and rebound. A Clause 22 frame normally takes tens of microseconds, so a 10 ms timeout probably means DONE will never arrive. That is exactly the case where this guard turns one failure into a permanent one. The hardware documentation doesn't say whether a completion can be lost. The Kconfig help text says: Transactions use bounded polling and recover from late completion. That covers a completion that arrives late, but there doesn't seem to be any recovery when it never arrives. cs75xx_mdio_write() has the same pre-wait. The other patches in the series (dt-bindings and MAINTAINERS) don't touch the driver, so this is still present at the end of the series. > + writel(MDIO_CTRL_DONE, priv->base + PER_MDIO_CTRL); > + writel(MDIO_ADDR_READ | FIELD_PREP(MDIO_ADDR_REG, reg) | > + FIELD_PREP(MDIO_ADDR_PHY, phy), priv->base + PER_MDIO_ADDR); > + priv->pending = true; > + writel(MDIO_CTRL_START, priv->base + PER_MDIO_CTRL); > + ret = cs75xx_mdio_wait(priv); > + if (ret) > + return ret; > + return readl(priv->base + PER_MDIO_RDDATA) & 0xffff; > +} [ ... ] > +static int cs75xx_mdio_probe(struct platform_device *pdev) > +{ [ ... ] > + cfg = readl(priv->base + PER_MDIO_CFG); > + /* The firmware configures the MDC rate; retain its prescaler. */ > + cfg |= MDIO_CFG_MANUAL; > + writel(cfg, priv->base + PER_MDIO_CFG); > + writel(MDIO_CTRL_DONE, priv->base + PER_MDIO_CTRL); [Severity: Medium] What happens if a frame is still in flight when probe runs? Probe sets MDIO_CFG_MANUAL and clears DONE once. It leaves priv->pending at its zero-initialized false and never checks that the controller is idle. A frame could still be outstanding in two cases: - a firmware-driven or non-manual mode, which MDIO_CFG_MANUAL implies exists - a previous driver instance that was unbound after a timeout The first cs75xx_mdio_read() then skips the drain step. Suppose the old frame completes after the DONE clear at the top of cs75xx_mdio_read() but before the poll. readl_poll_timeout_atomic() would then see the old frame's DONE, and the function would return that frame's PER_MDIO_RDDATA as the value for the new phy/reg. That could give a wrong PHY ID during the of_mdiobus_register() scan, or a wrong BMSR value. The commit message says: After a timeout, wait for the outstanding frame before programming another address so a late completion cannot be mistaken for the next transaction. Should probe also make sure the controller is idle, so the first transaction after probe gets the same protection? [ ... ] -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123-b4-cs7542-mdio-v1-0-626d0a0e3b4d%40gmail.com ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 2/3] net: mdio: Add Cortina CS7542 bus controller 2026-11-24 19:07 ` netdev-bot+sashiko @ 2026-11-24 19:31 ` Andrew Lunn 0 siblings, 0 replies; 12+ messages in thread From: Andrew Lunn @ 2026-11-24 19:31 UTC (permalink / raw) To: netdev-bot+sashiko Cc: filipp.dunsky, davem, edumazet, kuba, pabeni, robh, krzk+dt, conor+dt, hkallweit1, linux, andrew+netdev, netdev, devicetree, linux-kernel > [Severity: Medium] > Can one timeout leave the bus permanently unusable? Yes, but that is expected and not recoverable. The LLM often makes comments like this, it does not really have the concept of the hardware being dead, there is no recovery. Andrew ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH net-next 3/3] MAINTAINERS: Add Cortina CS7542 MDIO controller entry 2026-11-23 18:41 [PATCH net-next 0/3] Add Cortina Systems CS7542 MDIO controller support Fil Dunsky via B4 Relay 2026-11-23 18:41 ` [PATCH net-next 1/3] dt-bindings: net: Add Cortina CS7542 MDIO controller Fil Dunsky via B4 Relay 2026-11-23 18:41 ` [PATCH net-next 2/3] net: mdio: Add Cortina CS7542 bus controller Fil Dunsky via B4 Relay @ 2026-11-23 18:41 ` Fil Dunsky via B4 Relay 2026-11-23 19:41 ` Andrew Lunn 2 siblings, 1 reply; 12+ messages in thread From: Fil Dunsky via B4 Relay @ 2026-11-23 18:41 UTC (permalink / raw) To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Andrew Lunn, Heiner Kallweit, Russell King, Andrew Lunn Cc: netdev, devicetree, linux-kernel From: Fil Dunsky <filipp.dunsky@gmail.com> List the binding and driver under the author maintaining the Almond+ platform support, together with the appropriate subsystem mailing list. Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com> --- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 44540a1eb..312d3b4af 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -6918,6 +6918,13 @@ S: Maintained F: Documentation/hwmon/corsair-psu.rst F: drivers/hwmon/corsair-psu.c +CORTINA SYSTEMS CS7542 MDIO CONTROLLER +M: Fil Dunsky <filipp.dunsky@gmail.com> +L: netdev@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/net/cortina,cs7542-mdio.yaml +F: drivers/net/mdio/mdio-cs75xx.c + COUNTER SUBSYSTEM M: William Breathitt Gray <wbg@kernel.org> L: linux-iio@vger.kernel.org -- 2.53.0 ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 3/3] MAINTAINERS: Add Cortina CS7542 MDIO controller entry 2026-11-23 18:41 ` [PATCH net-next 3/3] MAINTAINERS: Add Cortina CS7542 MDIO controller entry Fil Dunsky via B4 Relay @ 2026-11-23 19:41 ` Andrew Lunn 0 siblings, 0 replies; 12+ messages in thread From: Andrew Lunn @ 2026-11-23 19:41 UTC (permalink / raw) To: filipp.dunsky Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Heiner Kallweit, Russell King, Andrew Lunn, netdev, devicetree, linux-kernel On Mon, Nov 23, 2026 at 09:41:44PM +0300, Fil Dunsky via B4 Relay wrote: > From: Fil Dunsky <filipp.dunsky@gmail.com> > > List the binding and driver under the author maintaining the Almond+ > platform support, together with the appropriate subsystem mailing list. > > Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Andrew ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2026-11-24 19:40 UTC | newest] Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2026-11-23 18:41 [PATCH net-next 0/3] Add Cortina Systems CS7542 MDIO controller support Fil Dunsky via B4 Relay 2026-11-23 18:41 ` [PATCH net-next 1/3] dt-bindings: net: Add Cortina CS7542 MDIO controller Fil Dunsky via B4 Relay 2026-11-24 19:07 ` netdev-bot+sashiko 2026-11-24 19:28 ` Andrew Lunn 2026-11-24 19:39 ` Fil Dunsky 2026-11-23 18:41 ` [PATCH net-next 2/3] net: mdio: Add Cortina CS7542 bus controller Fil Dunsky via B4 Relay 2026-11-23 19:40 ` Andrew Lunn 2026-11-23 20:41 ` Fil Dunsky 2026-11-24 19:07 ` netdev-bot+sashiko 2026-11-24 19:31 ` Andrew Lunn 2026-11-23 18:41 ` [PATCH net-next 3/3] MAINTAINERS: Add Cortina CS7542 MDIO controller entry Fil Dunsky via B4 Relay 2026-11-23 19:41 ` Andrew Lunn
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®