From: <Parthiban.Veerasooran@microchip.com>
To: <netdev-bot+sashiko@kernel.org>
Cc: <andrew+netdev@lunn.ch>, <davem@davemloft.net>,
<edumazet@kernel.org>, <kuba@kernel.org>, <pabeni@redhat.com>,
<hkallweit1@gmail.com>, <linux@armlinux.org.uk>,
<netdev@vger.kernel.org>, <UNGLinuxDriver@microchip.com>
Subject: Re: [PATCH net-next RESEND v4 1/4] net: phy: microchip_t1s: fix collision detection on PLCA status change
Date: Tue, 1 Dec 2026 13:55:18 +0000 [thread overview]
Message-ID: <7129f6bf-37bc-4521-b3e8-7dc47bea9584@microchip.com> (raw)
In-Reply-To: <179561192599.3135.16135249584970983112@kernel.org>
On 25/11/26 6:35 pm, netdev-bot+sashiko@kernel.org wrote:
>> +static int lan86xx_update_cden(struct phy_device *phydev)
>> +{
>> + struct lan86xx_priv *priv = phydev->priv;
>> + struct phy_plca_status plca_st;
>> + int fallback, ret;
>> + u16 cden;
>> +
>> + fallback = lan86xx_fallback_to_csmacd(phydev);
>> + if (fallback < 0)
>> + return fallback;
>> +
>> + ret = genphy_c45_plca_get_status(phydev, &plca_st);
>> + if (ret < 0)
>> + return ret;
>> +
>> + /* PLCA disabled -> CDEN enabled
>> + * PLCA enabled + BEACON -> CDEN disabled
>> + * PLCA enabled + no BEACON + fallback -> CDEN enabled
>> + * PLCA enabled + no BEACON + no fallback -> CDEN disabled
>> + */
>> + if (!priv->plca_enabled)
>> + cden = COL_DET_ENABLE;
>> + else if (plca_st.pst)
>> + cden = COL_DET_DISABLE;
>> + else if (fallback)
>> + cden = COL_DET_ENABLE;
>> + else
>> + cden = COL_DET_DISABLE;
>
> [Severity: Medium]
> Can priv->plca_enabled get out of sync with the hardware PLCA enable bit
> (MDIO_OATC14_PLCA_CTRL0.EN) here? lan86xx_read_status() now calls this on
> every phylib poll. A stale cached value would therefore keep re-applying
> the wrong CDEN setting for as long as the mismatch lasts.
>
> The cached value seems able to diverge in a few ways.
>
> First, lan86xx_plca_set_cfg() only stores priv->plca_enabled after
> genphy_c45_plca_set_cfg() returns 0. With enabled == 0, that helper clears
> PLCA_EN first and then does more MDIO accesses that can fail:
>
> drivers/net/phy/phy-c45.c:genphy_c45_plca_set_cfg() {
> ...
> // first of all, disable PLCA if required
> if (plca_cfg->enabled == 0) {
> ret = phy_clear_bits_mmd(phydev, MDIO_MMD_VEND2,
> MDIO_OATC14_PLCA_CTRL0,
> MDIO_OATC14_PLCA_EN);
> ...
> if (plca_cfg->to_tmr >= 0) {
> ret = phy_write_mmd(phydev, MDIO_MMD_VEND2,
> MDIO_OATC14_PLCA_TOTMR,
> plca_cfg->to_tmr);
>
> if (ret < 0)
> return ret;
> }
> ...
> }
>
> If one of the later writes fails, PLCA is off in hardware but
> priv->plca_enabled is still 1.
>
> Second, phy_detach() asserts the PHY reset line through
> phy_device_reset(phydev, 1), and phy_attach()->phy_init_hw() releases it
> on the next attach. That clears PLCA_CTRL0.EN. However, priv belongs to the
> driver binding, so plca_enabled stays 1. Nothing in config_init reads the
> hardware value back.
>
> Third, the opposite case: an unbind and rebind without a reset GPIO leaves
> PLCA enabled in hardware. lan86xx_probe() then allocates a zeroed priv
> with plca_enabled == 0.
>
> In the first two cases, assume the PRSCTL1 fallback bit is clear. This
> function then sees plca_enabled == 1 and pst == 0, and writes
> COL_DET_DISABLE while the PHY is actually running plain CSMA/CD. Isn't that
> the "CDEN stayed disabled, leaving CSMA/CD running unprotected" situation
> the commit message describes?
>
> In the rebind case, every poll forces COL_DET_ENABLE while the PHY runs
> PLCA with BEACONs. Meanwhile genphy_c45_plca_get_cfg() reports PLCA as
> enabled to userspace.
>
> The Rev.D0 follow-on patch also passes priv->plca_enabled into its
> link-selection logic. Would reading PLCA_CTRL0.EN directly inside
> lan86xx_update_cden() remove the need for the cached copy?
Agreed. All three divergence scenarios you describe are real.
I will update the code to read PLCA_CTRL0.EN directly from hardware in
lan86xx_update_cden() using MDIO_OATC14_PLCA_CTRL0 / MDIO_OATC14_PLCA_EN
from mdio-open-alliance.h, replacing the priv->plca_enabled check.
priv->plca_enabled will also be fully removed: the Rev.D0 interrupt
paths in Patch 4 that reference it are being dropped (see reply to Patch
4), making the field dead code.
>> +static irqreturn_t lan86xx_handle_interrupt(struct phy_device *phydev)
>> +{
>> + struct lan86xx_priv *priv = phydev->priv;
>> + irqreturn_t ret_irq = IRQ_NONE;
>> + int sts1, ret;
>> +
>> + /* Reading the status register clears the latched event bits. */
>> + sts1 = lan86xx_read_clear_sts1(phydev);
>> + if (sts1 < 0) {
>> + phy_error(phydev);
>> + return IRQ_NONE;
>> + }
>> +
>> + if (sts1 & LAN86XX_STS1_PLCA_STS_CHANGED) {
>
> [ ... ]
>
>> + ret_irq = IRQ_HANDLED;
>> + }
>> +
>> + return ret_irq;
>> +}
>
> [Severity: Low]
> lan86xx_config_intr() only changes the PSTC bit in IMSK1 through
> lan86xx_set_intr_mask(). The other IMSK1 bits keep whatever state the
> reset default or a bootloader left them in. What happens if another STS1
> source is unmasked?
>
> lan86xx_handle_interrupt() reads STS1, which acks every latched bit. It
> returns IRQ_NONE unless PSTC is set, so each such event would be reported
> as an unhandled PHY interrupt.
>
> phylib doesn't poll read_status() in interrupt mode. If the spurious IRQ
> detector ends up disabling the line, PSTC-based CDEN tracking would stop
> entirely.
>
> On the disable path, those other sources would also stay armed while
> phylib considers interrupts off.
>
> I couldn't confirm the IMSK1 reset default. If it masks every source, this
> has no visible effect. Would it be more robust to program the whole IMSK1
> register, with everything masked except PSTC when enabling and everything
> masked when disabling?
>
> The Rev.D0 config_intr added later in the series uses the same
> read-modify-write helper.
IMSK1 (0x001C) resets to 0xFFFF on both LAN867X and LAN865X - all
sources masked by default, confirmed in the datasheets. No bootloader or
prior driver unmasks any IMSK1 source other than PSTC.
The read-modify-write is therefore safe: only PSTC is toggled; all other
bits remain at their masked reset state throughout. The spurious IRQ
detector concern does not apply.
pw-bot: cr
Thanks,
Parthiban V
next prev parent reply other threads:[~2026-12-01 13:55 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 12:49 [PATCH net-next RESEND v4 0/4] net: microchip_t1s: fix collision detection on PLCA status change Parthiban Veerasooran
2026-11-24 12:49 ` [PATCH net-next RESEND v4 1/4] net: phy: " Parthiban Veerasooran
2026-11-25 13:05 ` netdev-bot+sashiko
2026-11-27 5:23 ` Parthiban.Veerasooran
2026-12-01 13:55 ` Parthiban.Veerasooran [this message]
2026-11-24 12:49 ` [PATCH net-next RESEND v4 2/4] net: ethernet: oa_tc6: deliver the PHY interrupt to phylib Parthiban Veerasooran
2026-11-25 13:05 ` netdev-bot+sashiko
2026-12-01 13:55 ` Parthiban.Veerasooran
2026-11-24 12:49 ` [PATCH net-next RESEND v4 3/4] microchip: lan865x: enable PHY interrupt via virtual IRQ Parthiban Veerasooran
2026-11-25 13:05 ` netdev-bot+sashiko
2026-12-01 13:55 ` Parthiban.Veerasooran
2026-11-24 12:49 ` [PATCH net-next RESEND v4 4/4] net: phy: microchip_t1s: fix collision detection for LAN867X Rev.D0 Parthiban Veerasooran
2026-11-25 13:05 ` netdev-bot+sashiko
2026-12-01 13:55 ` Parthiban.Veerasooran
2026-11-24 12:52 ` [PATCH net-next RESEND v4 0/4] net: microchip_t1s: fix collision detection on PLCA status change netdev-bot+sinfo
2026-11-25 3:28 ` Parthiban.Veerasooran
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=7129f6bf-37bc-4521-b3e8-7dc47bea9584@microchip.com \
--to=parthiban.veerasooran@microchip.com \
--cc=UNGLinuxDriver@microchip.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev-bot+sashiko@kernel.org \
--cc=netdev@vger.kernel.org \
--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