Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Caleb James DeLisle" <cjd@cjdns.fr>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [net-next v5 7/7] net: dsa: mediatek: support EN751221 switch
Date: Tue, 17 Nov 2026 18:35:09 +0000	[thread overview]
Message-ID: <sashiko-outbox-219356@kernel.org> (raw)
In-Reply-To: <20261116183332.168858-8-cjd@cjdns.fr>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] net: dsa: mt7530: missing dsa_unregister_switch() in
  mt7988_probe()
- [High] net: dsa: mt7530: premature mt7530_setup_mdio() before switch
  reset in mt7988_setup()
- [Medium] net: dsa: mt7530: peer phylink race and PMCR clobber in
  TRGMII calibration
- [Medium] net: dsa: mt7530: missing child_bus mdio_lock in core_write()
  and core_rmw()
- [Low] net: dsa: mt7530: comment and bit update mismatch in
  mt7988_setup()
--

commit 86fcc48d199eaeddf4405613e3b2f52247299102
Author: Caleb James DeLisle <cjd@cjdns.fr>

net: dsa: mediatek: support EN751221 switch

This commit adds support for the EcoNet EN751221 on-die MMIO MT7530 switch
and external MDIO MCM MT7530 switch, along with TRGMII calibration for the
inter-switch link between them.

> diff --git a/drivers/net/dsa/mt7530-mmio.c b/drivers/net/dsa/mt7530-mmio.c
> index ab6d92ab3ec0b..989fe95ec4f36 100644
> --- a/drivers/net/dsa/mt7530-mmio.c
> +++ b/drivers/net/dsa/mt7530-mmio.c
> @@ -12,6 +12,7 @@
>  static const struct of_device_id mt7988_of_match[] = {
>  	{ .compatible = "airoha,an7583-switch", .data = &mt753x_table[ID_AN7583], },
>  	{ .compatible = "airoha,en7581-switch", .data = &mt753x_table[ID_EN7581], },
> +	{ .compatible = "econet,en751221-switch", .data = &mt753x_table[ID_EN751221], },
>  	{ .compatible = "econet,en7528-switch", .data = &mt753x_table[ID_EN7528], },
>  	{ .compatible = "mediatek,mt7988-switch", .data = &mt753x_table[ID_MT7988], },
>  	{ /* sentinel */ }

[Severity: High]
When econet,en751221-switch is paired with the downstream MDIO switch
econet,en751221-gswitch, can a failure in mt7530_setup_mdio() leave priv->ds
registered in the DSA tree after probe fails?

drivers/net/dsa/mt7530-mmio.c:mt7988_probe() {
    ...
	ret = dsa_register_switch(priv->ds);

	if (ret)
		return ret;
    ...
	mnp = of_get_child_by_name(pdev->dev.of_node, "mdio");
	if (mnp) {
		of_node_put(mnp);
		ret = mt7530_setup_mdio(priv);
	}

	return ret;
}

When mt7988_probe() runs before the downstream MDIO switch has been probed,
dsa_register_switch() links the switch's ports into dst->ports and returns 0
without calling mt753x_setup().  mt7988_probe() then calls
mt7530_setup_mdio(priv) for the first time, as introduced in commit "net: dsa:
mediatek: support MDIO switch downstream of MMIO switch".  If
mt7530_setup_mdio() fails (for example, if of_irq_get() in mt7530_setup_irq()
returns -EPROBE_DEFER), mt7988_probe() returns the error without calling
dsa_unregister_switch(priv->ds).  The driver core then frees the devm-managed
priv and priv->ds while dst->ports retains dangling dp->ds pointers and a
leaked reference on the conduit net_device, causing a use-after-free on the
next dsa_switch_find() walk during a probe retry.

> diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
> index 4390982a5e225..701e6b3b928f2 100644
> --- a/drivers/net/dsa/mt7530.c
> +++ b/drivers/net/dsa/mt7530.c
> @@ -49,6 +49,9 @@ static const struct mt7530_mib_desc mt7530_mib[] = {
>  static int
>  mt753x_ctrl_phy_addr(struct mt7530_priv *priv)
>  {
> +	if (priv->id == ID_EN751221)
> +		return 12;
> +
>  	if (WARN_ON_ONCE(!priv->mdiodev))
>  		return 0;
>  
> @@ -349,12 +352,19 @@ mt7530_setup_port6(struct dsa_switch *ds, phy_interface_t interface)
>  	regmap_read(priv->regmap, MT753X_MTRAP, &xtal);
>  	xtal &= MT7530_XTAL_MASK;
>  
> +	/* EN751221 on-die does not report clock speed in MTRAP */
> +	if (priv->id == ID_EN751221)
> +		xtal = MT7530_XTAL_25MHZ;
> +
>  	if (xtal == MT7530_XTAL_25MHZ)
>  		ssc_delta = 0x57;
>  	else
>  		ssc_delta = 0x87;
>  
> -	if (priv->id == ID_MT7621) {
> +	if (priv->id == ID_EN751221_EXT || priv->id == ID_EN751221) {
> +		/* PLL frequency: 362.5Mhz */
> +		ncpo1 = 0x1d00;
> +	} else if (priv->id == ID_MT7621) {

[Severity: Medium]
When mt7530_setup_port6() runs on the MMIO-based ID_EN751221 switch, do
core_write() and core_rmw() perform multi-step MMD sequences on
priv->child_bus without holding priv->child_bus->mdio_lock?

drivers/net/dsa/mt7530.c:mt7530_mutex_lock() {
	if (priv->bus)
		mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED);
}

drivers/net/dsa/mt7530.c:core_write() {
    ...
	if (!bus)
		bus = priv->child_bus;

	if (WARN_ON_ONCE(!bus))
		return;

	mt7530_mutex_lock(priv);

	/* Write the desired MMD Devad */
	ret = bus->write(bus, ctl_phy, MII_MMD_CTRL, MDIO_MMD_VEND2);
    ...
}

On ID_EN751221, priv->bus is NULL, so core_write() and core_rmw() fall back
to priv->child_bus, while mt7530_mutex_lock() is a no-op because it only
checks priv->bus.  Each bus->write() and bus->read() call only acquires
priv->reg_mutex for a single Clause 22 transfer, so concurrent MDIO traffic
on priv->child_bus (such as phylib polling PHY 12 or regmap accesses to the
downstream ID_EN751221_EXT switch) can interleave between the MII_MMD_CTRL
and MII_MMD_DATA transfers and corrupt the MMD register access:

CPU0                                  CPU1
mt7530_setup_port6()
  core_write(ondie, ...)
    mt7530_mutex_lock(ondie) [no-op]
    bus->write(..., MII_MMD_CTRL, ...)
    bus->write(..., MII_MMD_DATA, reg)
                                      phy_state_machine() / ext regmap
                                        mdiobus_read(ondie->child_bus, ...)
    bus->write(..., MII_MMD_CTRL, ...)
    bus->write(..., MII_MMD_DATA, val)  <-- interleaved MMD sequence

Locking and unlocking bus->mdio_lock on whichever bus (priv->bus or
priv->child_bus) is selected would serialize the full MMD sequence.

> @@ -471,6 +481,251 @@ mt7531_pll_setup(struct mt7530_priv *priv)
[ ... ]
> +static void
> +en751221_trgmii_pair_setup(struct mt7530_priv *ext, int ext_port,
> +			   struct mt7530_priv *ondie, int ondie_port)
> +{
> +	u8 default_taps_ondie[NUM_TRGMII_CTRL];
> +	u8 default_taps_ext[NUM_TRGMII_CTRL];
> +	u32 mcr_down, mcr_up;
> +	int channel;
> +	int reg_val;
> +
> +	/* BOTH: Put interfaces in a downed state */
> +	mcr_down = PMCR_IFG_XMIT(PMCR_IFG_XMIT_64) | PMCR_MAC_MODE |
> +		   MT7530_FORCE_MODE | PMCR_MAC_RX_EN | PMCR_BACKOFF_EN |
> +		   PMCR_BACKPR_EN | PMCR_FORCE_SPEED_1000 | PMCR_FORCE_FDX;
> +	regmap_write(ondie->regmap,  MT753X_PMCR_P(ondie_port), mcr_down);
> +	regmap_write(ext->regmap, MT753X_PMCR_P(ext_port), mcr_down);
> +	usleep_range(5000, 6000);
> +
> +	/* BOTH: Reset TX */
> +	regmap_set_bits(ext->regmap, MT7530_TRGMII_TXCTRL, TX_RST);
> +	regmap_set_bits(ondie->regmap, MT7530_TRGMII_TXCTRL, TX_RST);
> +	usleep_range(5000, 6000);
> +	regmap_clear_bits(ext->regmap, MT7530_TRGMII_TXCTRL, TX_RST);
> +	regmap_clear_bits(ondie->regmap, MT7530_TRGMII_TXCTRL, TX_RST);
> +
> +	/* BOTH: Reset RX controllers down */
> +	regmap_set_bits(ext->regmap, MT7530_TRGMII_RCK_CTRL, RX_RST);
> +	regmap_set_bits(ondie->regmap, MT7530_TRGMII_RCK_CTRL, RX_RST);
> +
> +	/* BOTH: Set TX drive strength, MCM uses more */
> +	en751221_set_tx_drive(ondie, 8, 8, 7, 7);
> +	en751221_set_tx_drive(ext, 11, 11, 15, 15);
> +
> +	/* BOTH: Reset RX controllers up */
> +	regmap_clear_bits(ext->regmap, MT7530_TRGMII_RCK_CTRL, RX_RST);
> +	regmap_clear_bits(ondie->regmap, MT7530_TRGMII_RCK_CTRL, RX_RST);
> +
> +	/* BOTH: Ports up */
> +	mcr_up = mcr_down | PMCR_MAC_TX_EN | PMCR_FORCE_LNK;
> +	regmap_write(ondie->regmap, MT753X_PMCR_P(ondie_port), mcr_up);
> +	regmap_write(ext->regmap, MT753X_PMCR_P(ext_port), mcr_up);
[ ... ]
> +static void
> +mt7530_cal_interswitch_trgmii(struct dsa_port *dp)
> +{
> +	struct dsa_switch *ds = dp->ds;
> +	struct dsa_switch *peer_ds;
> +	struct dsa_port *peer_dp;
> +	struct mt7530_priv *peer;
> +	struct mt7530_priv *priv;
> +	struct dsa_link *dl;
> +	u32 pmsr = 0;
> +
> +	priv = ds->priv;
> +
> +	if (priv->id != ID_EN751221_EXT)
> +		return;
> +
> +	if (dp->type != DSA_PORT_TYPE_DSA)
> +		return;
> +
> +	regmap_read(priv->regmap, MT7530_PMSR_P(dp->index), &pmsr);
> +
> +	if (!(pmsr & PMSR_LINK))
> +		return;
[ ... ]
> @@ -3263,6 +3564,9 @@ static void mt753x_phylink_mac_link_up(struct phylink_config *config,
>  	}
>  
>  	regmap_set_bits(priv->regmap, MT753X_PMCR_P(dp->index), mcr);
> +
> +	if (interface == PHY_INTERFACE_MODE_TRGMII)
> +		mt7530_cal_interswitch_trgmii(dp);
>  }

[Severity: Medium]
Does en751221_trgmii_pair_setup() clobber the flow-control bits in
MT753X_PMCR_P and race with the peer port's phylink_resolve() work item?

mt753x_phylink_mac_link_up() sets PMCR_FORCE_TX_FC_EN and PMCR_FORCE_RX_FC_EN
in MT753X_PMCR_P(dp->index) before calling mt7530_cal_interswitch_trgmii(dp),
which then overwrites MT753X_PMCR_P on both ondie_port and ext_port using
regmap_write(..., mcr_up), dropping both flow-control bits.

In addition, each port's phylink_resolve() work item is only serialized by its
own pl->state_mutex, and mt7530_cal_interswitch_trgmii() checks PMSR_LINK on
priv->regmap (which was just forced up) rather than on peer->regmap, and only
runs when priv->id == ID_EN751221_EXT.  While en751221_trgmii_pair_setup()
sleeps in usleep_range(5000, 6000) with both ports forced down for TRGMII
reset, on-die port 5's phylink_resolve() can run concurrently and re-enable
MT753X_PMCR_P(ondie_port) mid-reset, or resolve after external port 6 when
mt7530_cal_interswitch_trgmii() is skipped because priv->id != ID_EN751221_EXT:

kworker (ext port 6)                  kworker (ondie port 5)
mt753x_phylink_mac_link_up()
  regmap_set_bits(..., mcr)
  mt7530_cal_interswitch_trgmii()
    en751221_trgmii_pair_setup()
      regmap_write(ondie, PMCR, mcr_down)
      usleep_range(5000, 6000)
                                      mt753x_phylink_mac_link_up()
                                        regmap_set_bits(ondie, PMCR, mcr)
                                          <-- brings port up during reset
      regmap_set_bits(..., TX_RST)
      ...
      regmap_write(..., PMCR, mcr_up) <-- overwrites TX/RX flow control

[ ... ]

> @@ -3617,6 +3922,15 @@ static int mt7988_setup(struct dsa_switch *ds)
>  				   AN7583_CSR_PHY_CORE_REG_CLK_SEL |
>  				   FIELD_PREP(AN7583_CSR_ETHER_AFE_PWD, 0));
>  
> +	/*
> +	 * EN751221 is an MT7530 but it is MMIO so setup is largely the same
> +	 * as the MMIO MT7531, but CHG_TRAP and INDIRECT_ACCESS must be set.
> +	 */
> +	if (priv->id == ID_EN751221)
> +		regmap_update_bits(priv->regmap, MT753X_MTRAP,
> +				   MT7530_CHG_TRAP | MT7530_PHY_INDIRECT_ACCESS,
> +				   MT7530_CHG_TRAP);
> +
>  	/* Reset the switch PHYs */
>  	regmap_write(priv->regmap, MT7530_SYS_CTRL, SYS_CTRL_PHY_RST);

[Severity: High]
When ID_EN751221 has the downstream ID_EN751221_EXT switch on its MDIO bus,
does mt7988_setup() reset the on-die switch after mt7988_probe() has already
initialized its IRQ chip and MDIO bus?

During mt7988_probe() for ID_EN751221, dsa_register_switch() returns 0
without calling mt753x_setup() -> mt7988_setup() because ID_EN751221_EXT has
not been probed yet.  mt7988_probe() then calls mt7530_setup_mdio(priv),
which runs mt7530_setup_irq() (programming MT7530_SYS_INT_EN) and registers
the MDIO bus to probe ID_EN751221_EXT before priv->rstc has been deasserted
or MT753X_MTRAP has been configured.  Once ID_EN751221_EXT registers with DSA,
dsa_tree_setup_switches() runs mt7988_setup() on ID_EN751221, which asserts
and deasserts priv->rstc and writes SYS_CTRL_PHY_RST, wiping out the
interrupt controller state configured by mt7530_setup_irq(), while the second
mt7530_setup_mdio() call returns early because priv->child_bus is already
set.  Also, if the mdio child node is marked disabled in Device Tree,
mt7530_setup_mdio() leaves priv->child_bus NULL after calling
mt7530_setup_irq(), so the second mt7530_setup_mdio() call invokes
mt7530_setup_irq() a second time.

[Severity: Low]
The comment in mt7988_setup() says that both CHG_TRAP and INDIRECT_ACCESS
must be set, whereas the regmap_update_bits() call passes
MT7530_CHG_TRAP | MT7530_PHY_INDIRECT_ACCESS as the mask and only
MT7530_CHG_TRAP as the value, which clears MT7530_PHY_INDIRECT_ACCESS.  Was
MT7530_PHY_INDIRECT_ACCESS meant to be cleared here (as in mt7530_setup()) or
set?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261116183332.168858-1-cjd@cjdns.fr?part=7

      reply	other threads:[~2026-11-17 18:35 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 18:33 [net-next v5 0/7] net: dsa: mt7530: support EcoNet EN751221 Caleb James DeLisle
2026-11-16 18:33 ` [net-next v5 1/7] net: dsa: mt7530: get ctrl phy addr using a function Caleb James DeLisle
2026-11-16 18:33 ` [net-next v5 2/7] dt-bindings: net: dsa: mediatek,mt7530: describe 'passthrough' hierarchy Caleb James DeLisle
2026-11-16 18:33 ` [net-next v5 3/7] net: dsa: mediatek: add support for passthrough mode Caleb James DeLisle
2026-11-17  0:30   ` kernel test robot
2026-11-17 18:35   ` sashiko-bot
2026-11-16 18:33 ` [net-next v5 4/7] net: dsa: mediatek: support PLL setup on MMIO MT7530 Caleb James DeLisle
2026-11-17 18:35   ` sashiko-bot
2026-11-16 18:33 ` [net-next v5 5/7] net: dsa: mediatek: support MDIO switch downstream of MMIO switch Caleb James DeLisle
2026-11-17 18:35   ` sashiko-bot
2026-11-16 18:33 ` [net-next v5 6/7] dt-bindings: net: dsa: mediatek,mt7530: add EcoNet EN751221 switches Caleb James DeLisle
2026-11-17 18:35   ` sashiko-bot
2026-11-16 18:33 ` [net-next v5 7/7] net: dsa: mediatek: support EN751221 switch Caleb James DeLisle
2026-11-17 18:35   ` sashiko-bot [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=sashiko-outbox-219356@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=cjd@cjdns.fr \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --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