Netdev List
 help / color / mirror / Atom feed
From: Florian Fainelli <florian.fainelli@broadcom.com>
To: netdev-bot+sashiko@kernel.org
Cc: netdev@vger.kernel.org, carlos.soto@broadcom.com,
	justin.chen@broadcom.com, opendmb@gmail.com, nb@tipi-net.de,
	bcm-kernel-feedback-list@broadcom.com, andrew@lunn.ch,
	hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net,
	edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
	linux-kernel@vger.kernel.org, kudzo51@gmail.com
Subject: Re: [PATCH net-next 3/3] net: mdio: mdio-bcm-unimac: Add Clause 45 support
Date: Tue, 17 Nov 2026 15:16:31 -0800	[thread overview]
Message-ID: <10d589b6-67af-4ff8-b2ad-5bb79537acbb@broadcom.com> (raw)
In-Reply-To: <179495158559.3136.13854046342906426133@kernel.org>

On 11/17/26 13:39, netdev-bot+sashiko@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 4 potential
> issue(s) to consider.
> 
> Critical: 0 · High: 1 · Medium: 2 · 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).
> 
> - [High] This patch sets bus->read_c45 unconditionally.
> - [Medium] In the new two-cycle C45 sequence, the only completion check
>    for the ADDR cycle is the return value of priv->wait_func().
> - [Medium] MDIO_CFG now has two read-modify-write paths that share no
>    lock.
> - [Low] C45 callbacks and the MDIO_CFG clause switch are turned on for
>    every compatible in unimac_mdio_ids: brcm,asp-v3.0/v2.2/v2.1-mdio,…
> 
> --
> 
> net: mdio: mdio-bcm-unimac: Add Clause 45 support
> 
> This commit adds Clause 45 read/write callbacks to the UniMAC MDIO driver.
> Each C45 access issues an ADDR cycle followed by a READ/WRITE cycle, and
> MDIO_CFG is switched between C22 and C45 mode as needed. The BMSR
> workaround read in unimac_mdio_reset() is also skipped for children
> compatible with "ethernet-phy-ieee802.3-c45".
> 
>> diff --git a/drivers/net/mdio/mdio-bcm-unimac.c b/drivers/net/mdio/mdio-bcm-unimac.c
>> index df267bb826966..6059b32580c54 100644
>> --- a/drivers/net/mdio/mdio-bcm-unimac.c
>> +++ b/drivers/net/mdio/mdio-bcm-unimac.c
> 
> [ ... ]
> 
>> @@ -96,7 +102,43 @@ static int unimac_mdio_poll(void *wait_func_data)
> 
> [ ... ]
> 
>> +static void unimac_mdio_set_clause(struct unimac_mdio_priv *priv, bool is_c45)
>> +{
>> +	u32 cfg = unimac_mdio_readl(priv, MDIO_CFG);
>> +	u32 new_cfg = cfg;
>> +
>> +	if (is_c45)
>> +		new_cfg &= ~MDIO_C22;
>> +	else
>> +		new_cfg |= MDIO_C22;
>> +
> 
> [Severity: Low]
> Do all of the IP revisions in unimac_mdio_ids support the MDIO_CFG clause
> bit and the C45 opcodes (ADDR=0b00, READ=0b11)?
> 
> The C45 callbacks and this MDIO_CFG read-modify-write are now enabled for
> every compatible: brcm,asp-v3.0/v2.2/v2.1-mdio, brcm,bcm6846-mdio,
> brcm,genet-mdio-v1..v5 and brcm,unimac-mdio. They are also enabled for the
> non-DT GENET pdata instantiation. Nothing gates this per compatible through
> match data, and unimac_mdio_set_clause() also runs on every C22 access.
> 
> If a revision lacks C45 support, C45 accesses would put undefined frames
> on the bus. Those accesses can come from the core C45 scan on an unmasked
> bus or from SIOCGMIIREG with a C45 phy_id.
> 
> Could the commit message say whether all of these revisions implement C45?
> 
>> +	if (new_cfg != cfg)
>> +		unimac_mdio_writel(priv, new_cfg, MDIO_CFG);
>> +}
> 
> [Severity: Medium]
> Can this read-modify-write of MDIO_CFG race with unimac_mdio_clk_set()?
> 
> unimac_mdio_set_clause() runs under bus->mdio_lock. unimac_mdio_clk_set()
> writes the same register with no lock held:
> 
> unimac_mdio_clk_set() {
>      ...
> 	reg = unimac_mdio_readl(priv, MDIO_CFG);
> 	reg &= ~(MDIO_CLK_DIV_MASK << MDIO_CLK_DIV_SHIFT);
> 	reg |= div << MDIO_CLK_DIV_SHIFT;
> 	unimac_mdio_writel(priv, reg, MDIO_CFG);
>      ...
> }
> 
> It is reached from unimac_mdio_resume() after the bus is registered.
> Before this patch, bus accesses never wrote MDIO_CFG.
> 
> The GENET parent resumes first. bcmgenet_resume() calls
> phy_start_machine() (or phy_start() through bcmgenet_netif_start()). With
> mac_managed_pm set, the PHY state machine work can then issue MDIO
> accesses while the child unimac resume is running clk_set.
> 
> Two interleavings look possible:
> 
> (a) clk_set reads cfg, set_clause flips MDIO_C22, then clk_set writes
> back the stale clause bit. The next ADDR and data cycles go out in the
> wrong framing. For example, a WR_C45 becomes a C22 write of val to
> register devad.
> 
> (b) set_clause reads cfg, clk_set writes the new MDC divider, then
> set_clause writes back the old divider. The restored MDIO clock frequency
> is lost until the next resume.
> 
> This needs a "clock-frequency" property, otherwise clk_set returns early,
> plus mixed C22/C45 traffic so that the clause bit actually changes.
> 
> [ ... ]
> 
>> @@ -107,8 +149,19 @@ static int unimac_mdio_read(struct mii_bus *bus, int phy_id, int reg)
>>   		return ret;
>>   
>>   	/* Prepare the read operation */
>> -	cmd = MDIO_RD_C22 | (phy_id << MDIO_PMD_SHIFT) |
>> -		(reg << MDIO_REG_SHIFT);
>> +	unimac_mdio_set_clause(priv, is_c45);
>> +	if (is_c45) {
>> +		ret = unimac_mdio_addr_c45(priv, phy_id, devad, reg);
>> +		if (ret)
>> +			goto out;
>> +
>> +		cmd = MDIO_RD_C45 | (phy_id << MDIO_PMD_SHIFT) |
>> +			unimac_mdio_c45_devad(devad) |
>> +			(reg & MDIO_C45_REG_MASK);
>> +	} else {
>> +		cmd = MDIO_RD_C22 | (phy_id << MDIO_PMD_SHIFT) |
>> +			(reg << MDIO_REG_SHIFT);
>> +	}
>>   	unimac_mdio_writel(priv, cmd, MDIO_CMD);
> 
> [Severity: Medium]
> Is the ADDR cycle guaranteed to have finished before MDIO_CMD is
> overwritten here?
> 
> The only completion check is the return value of priv->wait_func() in
> unimac_mdio_addr_c45(). For GENET-instantiated buses, that is
> bcmgenet_mii_wait():
> 
> bcmgenet_mii_wait() {
>      ...
> 	wait_event_timeout(priv->wq,
> 			   !(bcmgenet_umac_readl(priv, UMAC_MDIO_CMD)
> 			   & MDIO_START_BUSY),
> 			   HZ / 100);
> 	return 0;
> }
> 
> It returns 0 even when the wait timed out with START_BUSY still set. With
> HZ=100, HZ / 100 is a single jiffy. That can expire well before a ~25 us
> MDIO frame completes, and the same happens if the MDIO_DONE interrupt is
> delayed.
> 
> In that case unimac_mdio_addr_c45() reports success while the ADDR frame
> is still in flight. unimac_mdio_do_read() and unimac_mdio_do_write() then
> write the RD_C45/WR_C45 command and set START_BUSY again without checking
> that the controller is idle. Could this corrupt the frame, return data
> from an incomplete read, or send a C45 write to the wrong register?
> 
> bcmgenet_mii_wait() behaves this way independently of this patch. What
> this patch adds is the dependency of the data cycle on the ADDR cycle.
> The "if (ret) goto out" after the ADDR cycle can never trigger on GENET
> buses.
> 
> [ ... ]
> 
>> @@ -301,6 +390,8 @@ static int unimac_mdio_probe(struct platform_device *pdev)
>>   	bus->parent = &pdev->dev;
>>   	bus->read = unimac_mdio_read;
>>   	bus->write = unimac_mdio_write;
>> +	bus->read_c45 = unimac_mdio_read_c45;
>> +	bus->write_c45 = unimac_mdio_write_c45;
> 
> [Severity: High]
> Can setting read_c45 unconditionally make bus registration fail on the
> non-DT GENET path?
> 
> With read_c45 set, __mdiobus_register() runs mdiobus_scan_bus_c45() on
> every address that is not masked and has no C22 device. On an empty
> address, a C45 read sets MDIO_READ_FAIL, and unimac_mdio_do_read()
> returns -EIO:
> 
> 	if (!(bus->phy_ignore_ta_mask & 1 << phy_id) && (cmd & MDIO_READ_FAIL)) {
> 		ret = -EIO;
> 		goto out;
> 	}
> 
> get_phy_c22_id() converts -EIO to -ENODEV. get_phy_c45_ids() does not:
> 
> 	phy_reg = get_phy_c45_devs_in_pkg(bus, addr, i, &devs_in_pkg);
> 	if (phy_reg < 0)
> 		return -EIO;
> 
> mdiobus_scan_bus_c45() then aborts on any error other than -ENODEV:
> 
> 	if (IS_ERR(phydev) && (PTR_ERR(phydev) != -ENODEV))
> 		return PTR_ERR(phydev);
> 
> On the non-DT GENET path, bcmgenet_mii_register() does:
> 
> 	if (dn)
> 		platform_device_set_of_node(ppdev, bcmgenet_mii_of_find_mdio(priv));
> 	else
> 		ppd.phy_mask = ~0;
> 
> That leaves bus->phy_mask = ~pdata->phy_mask = 0. With np == NULL,
> of_mdiobus_register() calls __mdiobus_register() directly, so all 32
> addresses are scanned.
> 
> The C45 scan starts at address 0. With a PHY at address 1, as on ACPI
> systems such as RPi4 BCM6E4E, the first empty address returns -EIO.
> __mdiobus_register() then removes the C22 PHYs it already found, and
> unimac_mdio_probe() fails with "MDIO bus registration failed". The MAC
> is left without a PHY.
> 
> DT-described buses are not affected, because __of_mdiobus_register()
> forces phy_mask = ~0.
> 
> Should C45 read failures on empty addresses be reported as -ENODEV (or
> 0xffff) instead of -EIO, or should the C45 callbacks be limited to buses
> where the scan is masked?
> 

The clause bit is present on every GENET v1–v5, ASP and UniMAC block in 
the RDB (register data base), and that C45 is only functionally 
validated on the the ASP/GENET and 4908.

Regarding the other findings:

   - High (read_c45 set unconditionally): fixed by "[PATCH net-next v2 
1/4] net: phy: Map C45 probe read errors to -ENODEV during bus scan" in 
the v2 posting. It maps C45 probe read errors to -ENODEV, so the 
empty-address -EIO no longer aborts the scan.

   - Medium (ADDR cycle completion): valid. bcmgenet_mii_wait() returns 
0 even when wait_event_timeout() expires with START_BUSY still set. I 
will add an unimac_mdio_poll() call at the end of 
unimac_mdio_addr_c45(), so the data cycle never starts on a busy 
controller. The C22 path has the same weakness today, and I left it 
alone. Making bcmgenet_mii_wait() return -ETIMEDOUT would be a separate 
GENET patch.

   - Medium (MDIO_CFG race): valid, but only in the resume path. 
unimac_mdio_resume() now takes bus->mdio_lock around 
unimac_mdio_clk_set(). I didn't lock inside clk_set itself, because 
probe calls it before __mdiobus_register() has initialised the mutex.

pw-bot: cr
-- 
Florian

  reply	other threads:[~2026-11-17 23:16 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13 21:15 [PATCH net-next 0/3] net: mdio: Clause 45 support for Florian Fainelli
2026-11-13 21:15 ` [PATCH net-next 1/3] net: mdio: mdio-bcm-unimac: Define MDIO_OP_SHIFT Florian Fainelli
2026-11-13 21:55   ` Andrew Lunn
2026-11-15 18:49   ` Nicolai Buchwitz
2026-11-13 21:15 ` [PATCH net-next 2/3] net: mdio: mdio-bcm-unimac: Poll for completion at 1us granularity Florian Fainelli
2026-11-13 21:58   ` Andrew Lunn
2026-11-15 18:51   ` Nicolai Buchwitz
2026-11-13 21:15 ` [PATCH net-next 3/3] net: mdio: mdio-bcm-unimac: Add Clause 45 support Florian Fainelli
2026-11-13 22:04   ` Andrew Lunn
2026-11-13 22:14     ` Florian Fainelli
2026-11-15 18:59   ` Nicolai Buchwitz
2026-11-16 18:54     ` Florian Fainelli
2026-11-17  9:32       ` Nicolai Buchwitz
2026-11-17 21:39   ` netdev-bot+sashiko
2026-11-17 23:16     ` Florian Fainelli [this message]
2026-11-14  0:00 ` [PATCH net-next 0/3] net: mdio: Clause 45 support for Kordian Chmielewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=10d589b6-67af-4ff8-b2ad-5bb79537acbb@broadcom.com \
    --to=florian.fainelli@broadcom.com \
    --cc=andrew@lunn.ch \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=carlos.soto@broadcom.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=hkallweit1@gmail.com \
    --cc=justin.chen@broadcom.com \
    --cc=kuba@kernel.org \
    --cc=kudzo51@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=nb@tipi-net.de \
    --cc=netdev-bot+sashiko@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=opendmb@gmail.com \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox