Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Christian Marangi" <ansuelsmth@gmail.com>,
	mfd@lists.linux.dev, devicetree@vger.kernel.org
Cc: robh@kernel.org, conor+dt@kernel.org, lee@kernel.org
Subject: Re: [PATCH net-next v22 5/9] net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY
Date: Fri, 30 Oct 2026 04:54:35 +0000	[thread overview]
Message-ID: <sashiko-outbox-190513@kernel.org> (raw)
In-Reply-To: <20260915123812.14747-6-ansuelsmth@gmail.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] net/phy: flawed calibration lookup logic corrupts valid efuse values
- [Medium] net/phy: phy_write_mmd zeroing out adjacent fields in RXADC registers
- [Low] net/phy: downshift tunable ignores requested count violating ethtool API
--

commit 86e9fad6319a9402e15a273e59be80e0d645c59c
Author: Christian Marangi <ansuelsmth@gmail.com>

net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY

This commit adds a simple PHY driver to support the Airoha AN8855
Internal Switch Gigabit PHY, including configuration and calibration
using NVMEM cells.

> diff --git a/drivers/net/phy/air_an8855.c b/drivers/net/phy/air_an8855.c
> new file mode 100644
> index 0000000000000..bc22256fd5f95
> --- /dev/null
> +++ b/drivers/net/phy/air_an8855.c
[ ... ]
> +static int an8855_get_r50ohm_val(struct device *dev, const char *calib_name,
> +				 u8 *dest)
> +{
> +	u32 shift_sel, val;
> +	int ret;
> +	int i;
> +
> +	ret = nvmem_cell_read_u32(dev, calib_name, &val);
> +	if (ret)
> +		return ret;
> +
> +	shift_sel = FIELD_GET(AN8855_SWITCH_EFUSE_R50O, val);
> +	for (i = 0; i < ARRAY_SIZE(dsa_r50ohm_table); i++)
> +		if (dsa_r50ohm_table[i] == shift_sel)
> +			break;
> +
> +	if (i < 8 || i >= ARRAY_SIZE(dsa_r50ohm_table))
> +		*dest = dsa_r50ohm_table[25];
> +	else
> +		*dest = dsa_r50ohm_table[i - 8];
> +
> +	return 0;
> +}

[Severity: High]
Does this logic incorrectly map valid top-end EFUSE values to a fallback?

If the hardware EFUSE provides 127 (which is the first entry in
dsa_r50ohm_table), the loop immediately matches at i = 0. The code then
evaluates if (i < 8) as true, forcing dest to a hardcoded fallback of
dsa_r50ohm_table[25] (which is 94). 

However, a slightly lower value like 126 matches at i = 17, bypasses the
check, and maps to dsa_r50ohm_table[9] (which correctly yields 127). Will
this discontinuity erroneously penalize top-end calibration values and
drop them to 94, potentially corrupting PHY TX pair calibration?

[ ... ]
> +static int an8855_set_downshift(struct phy_device *phydev, u8 cnt)
> +{
> +	u16 ds = cnt != DOWNSHIFT_DEV_DISABLE ? AN8855_PHY_EN_DOWN_SHIFT : 0;
> +
> +	return phy_modify_paged(phydev, AN8855_PHY_PAGE_EXTENDED_1,
> +				AN8855_PHY_EXT_REG_14, AN8855_PHY_EN_DOWN_SHIFT,
> +				ds);
> +}

[Severity: Low]
Does this downshift tunable ignore the requested retry count?

The ethtool API for ETHTOOL_PHY_DOWNSHIFT accepts a specific retry count via
the cnt parameter, but here cnt != DOWNSHIFT_DEV_DISABLE is used as a simple
boolean toggle. 

If userspace requests a specific unsupported downshift count, won't the driver
enable the hardware default and return 0 (success) instead of rejecting the
invalid count with -EOPNOTSUPP or -EINVAL?

[ ... ]
> +static int an8855_config_init(struct phy_device *phydev)
> +{
[ ... ]
> +	/* Apply values to reduce signal noise */
> +	ret = phy_modify_mmd(phydev, MDIO_MMD_VEND1, AN8855_PHY_TX_PAIR_DLY_SEL_GBE,
> +			     AN8855_PHY_CR_DA_TX_PAIR_DELAY_SEL_A_GBE |
> +			     AN8855_PHY_CR_DA_TX_PAIR_DELAY_SEL_C_GBE,
> +			     FIELD_PREP(AN8855_PHY_CR_DA_TX_PAIR_DELAY_SEL_A_GBE, 0x4) |
> +			     FIELD_PREP(AN8855_PHY_CR_DA_TX_PAIR_DELAY_SEL_C_GBE, 0x4));
> +	if (ret)
> +		return ret;
> +	ret = phy_set_bits_mmd(phydev, MDIO_MMD_VEND1, AN8855_PHY_RXADC_CTRL,
> +			       AN8855_PHY_RG_AD_SAMPLE_PHSEL_A |
> +			       AN8855_PHY_RG_AD_SAMPLE_PHSEL_C);
> +	if (ret)
> +		return ret;
> +	ret = phy_write_mmd(phydev, MDIO_MMD_VEND1, AN8855_PHY_RXADC_REV_0,
> +			    FIELD_PREP(AN8855_PHY_RG_AD_RESERVE0_A, 0x1));
> +	if (ret)
> +		return ret;
> +	ret = phy_write_mmd(phydev, MDIO_MMD_VEND1, AN8855_PHY_RXADC_REV_1,
> +			    FIELD_PREP(AN8855_PHY_RG_AD_RESERVE0_C, 0x1));
> +	if (ret)
> +		return ret;
> +
> +	return 0;
> +}

[Severity: Medium]
Will phy_write_mmd() inadvertently zero out adjacent fields in these
RXADC registers?

Earlier in this function, phy_modify_mmd() and phy_set_bits_mmd() are used
to carefully preserve the state of pairs B and D. But for the REV_0 and
REV_1 registers, phy_write_mmd() completely overwrites the 16-bit register.

By writing FIELD_PREP(AN8855_PHY_RG_AD_RESERVE0_A, 0x1) directly, won't this
implicitly zero out the adjacent AN8855_PHY_RG_AD_RESERVE0_B (bits 7:0),
breaking the read-modify-write pattern and wiping out hardware defaults for
pairs B and D?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260915123812.14747-1-ansuelsmth@gmail.com?part=5

  reply	other threads:[~2026-10-30  4:54 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-15 12:37 [PATCH net-next v22 0/9] net: dsa: Add Airoha AN8855 support Christian Marangi
2026-09-15 12:37 ` [PATCH net-next v22 1/9] dt-bindings: net: dsa: Document support for Airoha AN8855 DSA Switch Christian Marangi
2026-09-15 12:37 ` [PATCH net-next v22 2/9] dt-bindings: net: Document support for AN8855 Switch Internal PHY Christian Marangi
2026-09-15 12:38 ` [PATCH net-next v22 3/9] dt-bindings: mfd: Document support for Airoha AN8855 Switch SoC Christian Marangi
2026-09-24 15:28   ` Rob Herring (Arm)
2026-09-15 12:38 ` [PATCH net-next v22 4/9] mfd: an8855: Add support for Airoha AN8855 Switch Christian Marangi
2026-09-21 20:44   ` Jakub Kicinski
2026-09-22 10:14     ` Christian Marangi (Ansuel)
2026-09-23  0:21       ` Jakub Kicinski
2026-10-30  4:54   ` sashiko-bot
2026-09-15 12:38 ` [PATCH net-next v22 5/9] net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY Christian Marangi
2026-10-30  4:54   ` sashiko-bot [this message]
2026-09-15 12:38 ` [PATCH net-next v22 6/9] net: dsa: tag_mtk: add Airoha variant usage of this TAG Christian Marangi
2026-10-30  4:54   ` sashiko-bot
2026-09-15 12:38 ` [PATCH net-next v22 7/9] MAINTAINERS: add myself as maintainer for Airoha AN8855 Switch Christian Marangi
2026-09-15 12:38 ` [PATCH net-next v22 8/9] net: dsa: mt7530: generalize and move common function to lib module Christian Marangi
2026-09-15 12:38 ` [PATCH net-next v22 9/9] net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver Christian Marangi
2026-10-30  4:54   ` sashiko-bot

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-190513@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=ansuelsmth@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=lee@kernel.org \
    --cc=mfd@lists.linux.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox