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, nb@tipi-net.de, opendmb@gmail.com,
	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 v3 4/4] net: mdio: mdio-bcm-unimac: Add Clause 45 support
Date: Thu, 19 Nov 2026 21:15:02 -0800	[thread overview]
Message-ID: <700b62af-5d33-49aa-844b-53d63aa2e52f@broadcom.com> (raw)
In-Reply-To: <179514208239.3136.3516165434506848044@kernel.org>



On 11/19/2026 6:34 PM, netdev-bot+sashiko@kernel.org wrote:
> 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] In drivers/net/mdio/mdio-bcm-unimac.c, the patch's own comment
>    in unimac_mdio_addr_c45() says some wait_func implementations…
> - [Low] The commit message does not mention the change to
>    unimac_mdio_resume() in drivers/net/mdio/mdio-bcm-unimac.c.
> 
> --
> 
> net: mdio: mdio-bcm-unimac: Add Clause 45 support
> 
> This adds Clause 45 read and write callbacks to the UniMAC MDIO driver.
> Each access does an ADDR cycle followed by a READ or WRITE cycle, and
> MDIO_CFG is switched between C22 and C45 mode as needed. It also skips the
> BMSR workaround read 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..ec0f2e8070eeb 100644
>> --- a/drivers/net/mdio/mdio-bcm-unimac.c
>> +++ b/drivers/net/mdio/mdio-bcm-unimac.c
> 
> [ ... ]
> 
>> @@ -96,7 +102,53 @@ static int unimac_mdio_poll(void *wait_func_data)
> 
> [ ... ]
> 
>> +	/* Some wait_func implementations (e.g.: bcmgenet_mii_wait()) return 0
>> +	 * even when they timed out with the controller still busy. The data
>> +	 * cycle must not be started before the ADDR cycle has completed, so
>> +	 * make sure the controller is idle.
>> +	 */
>> +	return unimac_mdio_poll(priv);
>> +}
> 
> [ ... ]
> 
>> @@ -107,8 +159,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);
> 
> [Severity: Medium]
> The comment in unimac_mdio_addr_c45() says bcmgenet_mii_wait() can return
> 0 while MDIO_START_BUSY is still set. The extra unimac_mdio_poll() runs
> only after the ADDR cycle. Can the same early return happen on the C45
> READ data cycle?
> 
> bcmgenet_mii_wait() returns 0 every time:
> 
> drivers/net/ethernet/broadcom/genet/bcmmii.c:bcmgenet_mii_wait() {
> 	wait_event_timeout(priv->wq,
> 			   !(bcmgenet_umac_readl(priv, UMAC_MDIO_CMD)
> 			   & MDIO_START_BUSY),
> 			   HZ / 100);
> 	return 0;
> }
> 
> At probe time, the GENET ISR that calls wake_up(&priv->wq) is not
> installed yet, because request_irq() happens later in bcmgenet_open().
> On v1/v2, UMAC_IRQ_MDIO_EVENT is not enabled at all. In both cases these
> waits depend only on the timeout. With HZ=100 the timeout is one jiffy,
> which can expire at the next tick.
> 
> The RD_C45 command places reg in MDIO_CMD[15:0]. After wait_func(),
> unimac_mdio_do_read() does this without checking MDIO_START_BUSY:
> 
> 	cmd = unimac_mdio_readl(priv, MDIO_CMD);
> 	...
> 	ret = cmd & 0xffff;
> 
> If MDIO_CMD[15:0] still holds reg until the hardware writes the read
> data, could an early return give the caller reg as the PHY data? This
> would also happen before MDIO_READ_FAIL is latched. For example, a read
> of MDIO_DEVS2 would return 6 and a read of MDIO_DEVS1 would return 5.
> get_phy_c45_devs_in_pkg() could accept that as a plausible devs_in_pkg.
> 
> read_c45 is now set, and the non-DT GENET path leaves bus->phy_mask at 0.
> So __mdiobus_register()->mdiobus_scan_bus_c45() issues these reads on
> every address that has no C22 device. Could get_phy_c45_ids() then
> register a bogus C45 PHY?
> 
> The write side looks similar. unimac_mdio_do_write() returns 0 after
> wait_func() even if the C45 WRITE is still in flight. Could the next
> access's unimac_mdio_set_clause() then flip the MDIO_C22 bit in MDIO_CFG,
> or write its ADDR command to MDIO_CMD, while the previous frame is still
> going out?
> 
> The C22 data cycle already returned early in the same way before this
> patch. The reg-as-data result and the MDIO_CFG switch mid-frame are new,
> though.
> 
> Would it make sense to have bcmgenet_mii_wait() return -ETIMEDOUT on
> timeout, or to run the idle poll after every cycle and not only between
> ADDR and DATA?
> 
> [ ... ]
> 
>> @@ -336,8 +437,16 @@ static void unimac_mdio_remove(struct platform_device *pdev)
>>   static int __maybe_unused unimac_mdio_resume(struct device *d)
>>   {
>>   	struct unimac_mdio_priv *priv = dev_get_drvdata(d);
>> +	int ret;
>> +
>> +	/* MDIO_CFG is also modified by the MDIO accessors to switch between
>> +	 * Clause 22 and Clause 45, which run under the bus lock.
>> +	 */
>> +	mutex_lock(&priv->mii_bus->mdio_lock);
>> +	ret = unimac_mdio_clk_set(priv);
>> +	mutex_unlock(&priv->mii_bus->mdio_lock);
> 
> [Severity: Low]
> This isn't a bug, but the commit message doesn't mention this change to
> unimac_mdio_resume(). The resume callback now holds
> priv->mii_bus->mdio_lock around unimac_mdio_clk_set(), because
> unimac_mdio_set_clause() does a read-modify-write of MDIO_CFG, the same
> register that holds the clock divider.
> 
> The message covers the C45 accessors, the BMSR workaround skip and the
> C45 scan. Could it also describe this locking change in the resume path?
> 
>>   
>> -	return unimac_mdio_clk_set(priv);
>> +	return ret;
>>   }
> 

On the Medium: this one is valid, thanks. wait_func() implementations 
such as bcmgenet_mii_wait() can return 0 with MDIO_START_BUSY still set, 
and v3 only guarded the ADDR -> DATA transition. A C45 READ that 
returned early would hand back MDIO_CMD[15:0] (the register address) as 
read data, and the next access could switch MDIO_CFG or rewrite MDIO_CMD 
while the previous frame was still in flight.

v4 adds unimac_mdio_wait(), which calls wait_func() and then polls for 
the controller to go idle. It is used after the ADDR, READ and WRITE 
cycles, so the idle check no longer depends on the wait_func() 
implementation. I kept the fix in the unimac driver rather than changing
bcmgenet_mii_wait() to return -ETIMEDOUT.

Side effect, now spelled out in the commit message: C22 accesses use the
same helper, so a C22 cycle that times out on a busy controller now 
returns -ETIMEDOUT instead of silently returning stale data.

On the Low: the commit message now describes the locking added to 
unimac_mdio_resume().

pw-bot: cr
-- 
Florian


      reply	other threads:[~2026-11-20  5:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 23:31 [PATCH net-next v3 0/4] net: mdio: Clause 45 support for mdio-bcm-unimac Florian Fainelli
2026-11-17 23:31 ` [PATCH net-next v3 1/4] net: phy: Map C45 probe read errors to -ENODEV during bus scan Florian Fainelli
2026-11-20  2:34   ` netdev-bot+sashiko
2026-11-20  5:03     ` Florian Fainelli
2026-11-17 23:31 ` [PATCH net-next v3 2/4] net: mdio: mdio-bcm-unimac: Define MDIO_OP_SHIFT Florian Fainelli
2026-11-17 23:31 ` [PATCH net-next v3 3/4] net: mdio: mdio-bcm-unimac: Poll for completion at 1us granularity Florian Fainelli
2026-11-17 23:31 ` [PATCH net-next v3 4/4] net: mdio: mdio-bcm-unimac: Add Clause 45 support Florian Fainelli
2026-11-18  8:49   ` Nicolai Buchwitz
2026-11-20  2:34   ` netdev-bot+sashiko
2026-11-20  5:15     ` Florian Fainelli [this message]

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=700b62af-5d33-49aa-844b-53d63aa2e52f@broadcom.com \
    --to=florian.fainelli@broadcom.com \
    --cc=andrew@lunn.ch \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=hkallweit1@gmail.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