All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Joseph Telaak" <joseph@telaak.dev>
Cc: intel-wired-lan@lists.osuosl.org, devicetree@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH iwl-next v2 3/4] e1000: attach a CE4100 PHY through phylink
Date: Fri, 04 Dec 2026 06:14:06 +0000	[thread overview]
Message-ID: <sashiko-outbox-249196@kernel.org> (raw)
In-Reply-To: <20261203-e1000-phylink-v2-3-0a8f80515363@telaak.dev>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] e1000: unchecked reg shift in
  e1000_ce4100_mdio_read()/write()
- [Medium] e1000: e1000_mdio_register() rejects valid DT mdio nodes
  without phylink
- [Medium] e1000: PHY state machine left polling BAR 1 MDIO in D3hot
  with WoL enabled
--

commit 37b0dd6aa7b1616c73701607700385f94c7c3b35
Author: Joseph Telaak <joseph@telaak.dev>

e1000: attach a CE4100 PHY through phylink

This commit extends CE4100 phylink support to attach a PHY described by
phy-handle on open, and registers the MAC's MDIO bus when an mdio child
node is present in the device tree.

> diff --git a/drivers/net/ethernet/intel/e1000/e1000_hw.c b/drivers/net/ethernet/intel/e1000/e1000_hw.c
> index f367b87938f14..3a2a9713e3b20 100644
> --- a/drivers/net/ethernet/intel/e1000/e1000_hw.c
> +++ b/drivers/net/ethernet/intel/e1000/e1000_hw.c

[ ... ]

> +int e1000_ce4100_mdio_read(struct e1000_hw *hw, int addr, int reg)
> +{
> +	int ret;
> +	u32 sts;
> +
> +	ret = e1000_ce4100_mdio_cmd(hw, (reg << E1000_MDIC_REG_SHIFT) |
> +				    (addr << E1000_MDIC_PHY_SHIFT) |
> +				    INTEL_CE_GBE_MDIC_OP_READ);
> +	if (ret)
> +		return ret;
> +
> +	sts = readl(E1000_MDIO_STS);
> +	if (sts & INTEL_CE_GBE_MDIC_READ_ERROR)
> +		return -EIO;
> +
> +	return sts & 0xffff;
> +}
> +
> +/**
> + * e1000_ce4100_mdio_write - write a register of a PHY on the CE4100 MDIO bus
> + * @hw: Struct containing variables accessed by shared code
> + * @addr: PHY address
> + * @reg: register number
> + * @val: value to write
> + *
> + * Return: 0, or a negative error code.
> + */
> +int e1000_ce4100_mdio_write(struct e1000_hw *hw, int addr, int reg, u16 val)
> +{
> +	return e1000_ce4100_mdio_cmd(hw, val | (reg << E1000_MDIC_REG_SHIFT) |
> +				     (addr << E1000_MDIC_PHY_SHIFT) |
> +				     INTEL_CE_GBE_MDIC_OP_WRITE);
> +}

[Severity: Medium]
Can an out-of-range reg value in e1000_ce4100_mdio_read() or
e1000_ce4100_mdio_write() corrupt adjacent fields in E1000_MDIO_CMD?

e1000_mii_ioctl() delegates SIOCGMIIREG and SIOCSMIIREG to
phylink_mii_ioctl(), which passes the 16-bit mii->reg_num through
__mdiobus_read() and __mdiobus_write() without range-checking regnum.

Shifting reg left by E1000_MDIC_REG_SHIFT (16) unmasked lets bits 9:5
overwrite the PHY address field and bit 10 set INTEL_CE_GBE_MDIC_OP_WRITE,
turning a read-only SIOCGMIIREG into a write of 0x0000.  Values with
reg >= 0x8000 also shift into the sign bit of signed int reg.

Validating reg <= MAX_PHY_REG_ADDRESS (returning -EINVAL, as in
e1000_read_phy_reg_ex()) or using FIELD_PREP() after bounds-checking would
avoid this.

> diff --git a/drivers/net/ethernet/intel/e1000/e1000_main.c b/drivers/net/ethernet/intel/e1000/e1000_main.c
> index f07afc451d098..1ac21f2c18b8f 100644
> --- a/drivers/net/ethernet/intel/e1000/e1000_main.c
> +++ b/drivers/net/ethernet/intel/e1000/e1000_main.c

[ ... ]

> +static int e1000_mdio_register(struct e1000_adapter *adapter)
> +{
> +	struct device *dev = &adapter->pdev->dev;
> +	struct device_node *np;
> +	struct mii_bus *bus;
> +	int err;
> +
> +	np = of_get_available_child_by_name(dev->of_node, "mdio");
> +	if (!np)
> +		return 0;
> +
> +	/* Without phylink, e1000's own PHY code would drive the bus too */
> +	if (!adapter->phylink) {
> +		e_dev_err("an mdio node needs a phy-handle or a fixed-link\n");
> +		err = -EINVAL;
> +		goto out;
> +	}

[Severity: Medium]
As reported by Maxime Chevallier on v1 [1], should e1000_mdio_register()
register the MDIO bus whenever an mdio child node is present instead of
returning -EINVAL without phylink?

Documentation/devicetree/bindings/net/intel,ce4100-gbe.yaml allows an mdio
child node without phy-handle or fixed-link (for example, when another MAC
or a switch uses devices on this bus), so returning -EINVAL here aborts
e1000_probe() on valid DT configurations.

Serializing CE4100 MDIO register access with e1000_phy_lock would allow
registering the bus independently of phylink.

[ ... ]

> @@ -1549,6 +1631,13 @@ int e1000_open(struct net_device *netdev)
>  
>  	netif_carrier_off(netdev);
>  
> +	if (adapter->phylink) {
> +		err = phylink_of_phy_connect(adapter->phylink,
> +					     adapter->pdev->dev.of_node, 0);
> +		if (err)
> +			return err;
> +	}

[Severity: Medium]
With Wake-on-LAN enabled, can the PHY state machine keep polling BAR 1
MDIO registers after the PCI device enters PCI_D3hot?

e1000_phylink_init() sets mac_managed_pm = true, so mdio_bus_phy_suspend()
skips phy_stop_machine().  When WoL is enabled, __e1000_shutdown() passes
mac_wol = true to phylink_suspend(), which takes the MAC-WoL branch and
also skips phylink_stop() and phy_stop().

Because phydev->state_queue runs on the non-freezable
system_power_efficient_wq, it can fire after pci_prepare_to_sleep() or
e1000_shutdown() puts the device into PCI_D3hot.

e1000_ce4100_mdio_cmd() then reads 0xffffffff and returns -ETIMEDOUT,
causing _phy_state_machine() to trigger WARN(1) via phy_error_precise()
and leave the PHY stuck in PHY_ERROR after phylink_resume().

[1] https://lore.kernel.org/r/80f76cd1-5fac-4809-8ab9-c6ccbce647fd@bootlin.com

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-e1000-phylink-v2-0-0a8f80515363@telaak.dev?part=3

  reply	other threads:[~2026-12-04  6:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  6:13 [PATCH iwl-next v2 0/4] e1000: phylink for the Intel CE4100 GbE Joseph Telaak
2026-12-03  6:13 ` [PATCH iwl-next v2 1/4] dt-bindings: net: add " Joseph Telaak
2026-12-03 14:52   ` Krzysztof Kozlowski
2026-12-03 23:02     ` Joseph Telaak
2026-12-03  6:13 ` [PATCH iwl-next v2 2/4] e1000: use phylink for a CE4100 fixed link Joseph Telaak
2026-12-04  6:14   ` sashiko-bot
2026-12-03  6:13 ` [PATCH iwl-next v2 3/4] e1000: attach a CE4100 PHY through phylink Joseph Telaak
2026-12-04  6:14   ` sashiko-bot [this message]
2026-12-03  6:13 ` [PATCH iwl-next v2 4/4] e1000: disable EEE on a CE4100 PHY under phylink Joseph Telaak

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=sashiko-outbox-249196@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=joseph@telaak.dev \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.