Netdev List
 help / color / mirror / Atom feed
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 4/4] net: phy: microchip_t1s: fix collision detection for LAN867X Rev.D0
Date: Tue, 1 Dec 2026 13:55:41 +0000	[thread overview]
Message-ID: <db4859aa-e943-4ce6-9855-bd92d60025a8@microchip.com> (raw)
In-Reply-To: <179561192987.3135.7922944334571014404@kernel.org>

On 25/11/26 6:35 pm, netdev-bot+sashiko@kernel.org wrote:
>> @@ -582,6 +620,20 @@ static int lan867x_revd0_config_init(struct phy_device *phydev)
>>                        return ret;
>>        }
>>
>> +     /* AN1699: Configure CCMFC (Collision Counting and MAC Forwarding
>> +      * Control) to OA default (0x1) so that the hardware autonomously gates
>> +      * collision forwarding to the MAC based on the live PLCA_Status:
>> +      * collisions are neither counted nor forwarded when PLCA_Status is OK,
>> +      * and are counted/forwarded when not OK. This eliminates the need for
>> +      * software-driven CDEN toggling. CDEN defaults to enabled on Rev.D0
>> +      * and remains enabled.
>> +      */
>> +     ret = phy_modify_mmd(phydev, MDIO_MMD_VEND2, LAN86XX_REG_COL_DET_CTRL0,
>> +                          COL_DET_CTRL0_CCMFC_MASK,
>> +                          COL_DET_CTRL0_CCMFC_OA_DEFAULT);
> 
> [Severity: Medium]
> Is CDEN (COL_DET_CTRL0 bit 15) guaranteed to be set at this point? The
> mask covers only bits 10:9, so bit 15 keeps whatever value the register
> already held.
> 
> The new comments say "CDEN defaults to enabled on Rev.D0 and remains
> enabled" and "CDEN remains permanently enabled in config_init()".
> However, no Rev.D0 path writes bit 15.
> 
> Older kernels do clear it on Rev.D0. There, lan86xx_plca_set_cfg() did
> this:
> 
>          if (plca_cfg->enabled)
>                  return phy_modify_mmd(phydev, MDIO_MMD_VEND2,
>                                        LAN86XX_REG_COL_DET_CTRL0,
>                                        COL_DET_CTRL0_ENABLE_BIT_MASK,
>                                        COL_DET_DISABLE);
> 
> In that check, -1 counts as non-zero.
> 
> Rev.D0 has no .soft_reset, and lan867x_check_reset_complete() only reads
> STS2. Without a reset GPIO or a power cycle, a CDEN=0 left by an earlier
> kernel (for example across kexec) or by a bootloader carries over into
> this driver.
> 
> After this patch, nothing on Rev.D0 corrects it.
> lan86xx_plca_set_cfg() now returns early:
> 
>          if (phydev->phy_id == PHY_ID_LAN867X_REVD0)
>                  return 0;
> 
> The new interrupt handler does not touch COL_DET_CTRL0 either.
> 
> CCMFC only gates counting and forwarding of collisions the detector
> reports. With CDEN=0, would the MAC see any collisions in CSMA/CD
> operation (PLCA disabled, or fallback without BEACON)?
> 
> Would adding COL_DET_CTRL0_ENABLE_BIT_MASK / COL_DET_ENABLE to this
> phy_modify_mmd() call make the comment true?

Agreed. I will update the code to widen the mask and value to explicitly 
set CDEN:

ret = phy_modify_mmd(phydev, MDIO_MMD_VEND2, LAN86XX_REG_COL_DET_CTRL0,
                      COL_DET_CTRL0_CCMFC_MASK |
                      COL_DET_CTRL0_ENABLE_BIT_MASK,
                      COL_DET_CTRL0_CCMFC_OA_DEFAULT | COL_DET_ENABLE);

This makes "CDEN remains permanently enabled" unambiguously true for all
scenarios including kexec from an older kernel that cleared bit 15.

>> +static int lan867x_revd0_config_intr(struct phy_device *phydev)
>> +{
>> +     u16 mask = LAN86XX_STS1_PLCA_STS_CHANGED |
>> +                LAN86XX_STS1_LINK_STS_CHANGED;
>> +     struct lan86xx_priv *priv = phydev->priv;
>> +     int sts1, ret;
>> +
>> +     if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
>> +             /* Read to clear any pending status before enabling. */
>> +             sts1 = lan86xx_read_clear_sts1(phydev);
>> +             if (sts1 < 0)
>> +                     return sts1;
>> +
>> +             /* STS1 may have cleared a pending PSTC while masked, and a
>> +              * missed PSTC leaves no trace to key off, so unconditionally
>> +              * resync the link-status-selection source from the current
>> +              * PLCA enable state and fallback configuration.
>> +              */
>> +             ret = lan867x_revd0_update_link_selection(phydev,
>> +                                                       priv->plca_enabled);
> 
> [Severity: Medium]
> Can this resync run with a stale priv->plca_enabled? The value is a
> software cache that only lan86xx_plca_set_cfg() writes. priv is allocated
> once in lan86xx_probe(), so the cache survives PHY resets.
> 
> One way this happens: phy_detach_internal() asserts the reset GPIO with
> phy_device_reset(phydev, 1), and phy_init_hw() deasserts it on re-attach.
> The same happens on resume if the PHY lost power. The PLCA registers are
> then back at their defaults (PLCA disabled), but priv->plca_enabled is
> still 1.
> 
> The sequence is then:
> 
> phy_init_hw()
>    lan867x_revd0_config_init()
>      lan867x_revd0_link_active_selection(phydev, false)  /* semaphore */
> lan867x_revd0_config_intr()   /* PHY_INTERRUPT_ENABLED */
>    lan867x_revd0_update_link_selection(phydev, priv->plca_enabled == 1)
>      lan867x_revd0_link_active_selection(phydev, true)   /* PLCA_STATUS */
> 
> If PRSCTL1 bit 10 is clear after reset, LINK_STATUS_CTRL now selects
> PLCA_STATUS while PLCA is disabled in hardware. PLCA_Status never becomes
> OK. Would the link then stay down until ethtool --set-plca-cfg is run
> again? Each later PSTC in lan867x_revd0_handle_interrupt() re-applies the
> same stale value.
> 
> There is a second path through the error handling in
> lan86xx_plca_set_cfg(). With enabled = 0, the code first calls
> lan867x_revd0_update_link_selection(phydev, 0), which writes the
> semaphore selection. genphy_c45_plca_set_cfg() then clears PLCA_EN and
> fails on a later CTRL1/TOTMR/BURST write:
> 
>          ret = genphy_c45_plca_set_cfg(phydev, plca_cfg);
>          if (ret)
>                  return ret;
> 
>          if (plca_cfg->enabled != -1)
>                  priv->plca_enabled = plca_cfg->enabled;
> 
> priv->plca_enabled stays 1. Disabling PLCA changes the PLCA status, which
> raises PSTC, and the new handler writes the PLCA_STATUS selection back.
> 
> Before this patch, Rev.D0 had no config_intr/handle_interrupt, so the
> semaphore selection from config_init stayed in place.
> 
> Would reading the enable state from PLCA_CTRL0 EN (for example via
> genphy_c45_plca_get_cfg()) avoid this?

Resolved by dropping PSTC handling from Rev.D0 entirely (see reply to 
the [Low] comment below). With PSTC removed from both 
lan867x_revd0_config_intr() and lan867x_revd0_handle_interrupt(),
priv->plca_enabled is no longer referenced in the Rev.D0 interrupt path,
eliminating both divergence scenarios you describe.

> 
> [ ... ]
> 
>> +     if (sts1 & LAN86XX_STS1_PLCA_STS_CHANGED) {
>> +             /* Re-evaluate the link-status selection when PLCA status
>> +              * changes. A resulting link-status change raises
>> +              * LINK_STS_CHANGED, which triggers the PHY state machine.
>> +              */
>> +             ret = lan867x_revd0_update_link_selection(phydev,
>> +                                                       priv->plca_enabled);
> 
> [Severity: Low]
> Can this PSTC branch ever change the register?
> lan867x_revd0_update_link_selection() depends on only two inputs:
> PRSCTL1 bit 10, read via lan86xx_fallback_to_csmacd(), and the cached
> priv->plca_enabled. A PLCA status transition changes neither of them.
> 
> The driver never writes PRSCTL1, and none of the lan867x_revd0_fixup_regs
> entries is 0x0035. priv->plca_enabled only changes in
> lan86xx_plca_set_cfg(), which already reprograms LINK_STATUS_CTRL.
> 
> So each PSTC rewrites the value LAN867X_REG_LINK_STATUS_CTRL already
> holds. That costs an interrupt, a PRSCTL1 read and a LINK_STATUS_CTRL
> write on every BEACON transition. It also gives the stale cache above a
> second place to re-apply a wrong value.
> 
> The comment says "A resulting link-status change raises
> LINK_STS_CHANGED", and the commit message says:
> 
>      The PSTC interrupt handler for Rev.D0
>      therefore only needs to update the link status selection on each PLCA
>      transition.
> 
> Writing the same selection value cannot cause a link-status change. When
> PLCA_STATUS is selected, the hardware drives the link bit and raises
> LINK_STS_CHANGED by itself.
> 
> Should the selection be based on the live PLCA status instead? Or should
> the PSTC handling be dropped and the explanation updated?

Agreed. The PSTC branch is a no-op. I will drop PSTC handling from Rev.D0:

1. lan867x_revd0_config_intr(): change mask to only
    LAN86XX_STS1_LINK_STS_CHANGED and remove the unconditional
    update_link_selection() resync (added solely to recover missed PSTC
    events that are no longer monitored).

2. lan867x_revd0_handle_interrupt(): drop the PSTC branch entirely.

When PLCA goes offline, the hardware directly raises LINK_STS_CHANGED,
which the handler already processes to trigger the phylib state machine.
No PSTC-driven software intervention is needed. The commit message will
be updated accordingly.

Thanks,
Parthiban V


  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
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 [this message]
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=db4859aa-e943-4ce6-9855-bd92d60025a8@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