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 3/7] net: dsa: mediatek: add support for passthrough mode
Date: Tue, 17 Nov 2026 18:35:06 +0000	[thread overview]
Message-ID: <sashiko-outbox-219352@kernel.org> (raw)
In-Reply-To: <20261116183332.168858-4-cjd@cjdns.fr>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] net: dsa: mt7530: wrong upstream port in
  mt753x_conduit_state_change()
- [Medium] net: dsa: mt7530: broken CPU port fallback in
  mt753x_upstream_port_index()
- [Medium] net: dsa: mt7530: NULL dp->user dereference in
  mt7531_mac_config() on DSA port
- [Medium] net: dsa: mt7530: unchecked MT753X_MTRAP write in
  mt753x_cpu_port_enable()
- [Low] net: dsa: mt7530: dead no-op callbacks in
  mt7530_passthrough_switch_ops
--

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

net: dsa: mediatek: add support for passthrough mode

This commit adds passthrough mode support to the mt7530 DSA driver so an
upstream MediaTek switch can forward traffic unaltered to and from a
downstream MediaTek switch.

> diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
> index 3bfe29b3b93e2..09b7e9d2d0253 100644
> --- a/drivers/net/dsa/mt7530.c
> +++ b/drivers/net/dsa/mt7530.c

[ ... ]

> @@ -1286,13 +1297,81 @@ mt753x_trap_frames(struct mt7530_priv *priv)
> +/* If this switch is downstream of another switch that is in passthrough mode,
> + * the "CPU" port is actually a DSA port.
> + */
>  static void
>  mt753x_cpu_port_enable(struct dsa_switch *ds, int port)
>  {
>  	struct mt7530_priv *priv = ds->priv;
>  
> -	/* Enable Mediatek header mode on the cpu port */
> -	regmap_write(priv->regmap, MT7530_PVC_P(port), PORT_SPEC_TAG);
> +	if (priv->is_passthrough) {
> +		/* Disable parsing of the DSA tag, it will be forwarded blindly
> +		 * to the downstream switch.
> +		 */
> +		regmap_write(priv->regmap, MT7530_PVC_P(port),
> +			     VLAN_ATTR(MT7530_VLAN_TRANSPARENT) |
> +			     PVC_EG_TAG(MT7530_VLAN_EG_DISABLED));
> +
> +		/* The port is not configured to parse DSA tags, so they are
> +		 * liable to be confused for length fields, so length check is
> +		 * disabled.
> +		 */
> +		regmap_clear_bits(priv->regmap, MT753X_AGC, AGC_L2LEN_CHK);
> +
> +		/* In passthrough mode, MTU is only enforced downstream */
> +		mt7530_port_change_mtu(ds, port, MT7530_MAX_MTU);
> +
> +		/* Loop detection has no value in passthrough mode */
> +		regmap_set_bits(priv->regmap, MT753X_MTRAP,
> +				MT7530_LOOP_DET_DISABLE);

[Severity: Medium]
Should this MT753X_MTRAP write be guarded by a priv->id check?

mt753x_cpu_port_enable() runs from both mt7530_setup() and
mt7531_setup_common(), and MT753X_MTRAP (0x7804) has a different bit layout
on MT7531-family switches (where other MT7530_* trap accesses in
mt7530_port_enable() and mt7530_port_disable() check priv->id first).  Also,
on ID_EN7528 (an MT7530 core initialized via mt7988_setup()),
MT7530_CHG_TRAP is never set before modifying MT753X_MTRAP.

[ ... ]

> @@ -1318,12 +1397,36 @@ mt753x_cpu_port_enable(struct dsa_switch *ds, int port)
>  			   PCR_PORT_VLAN_MASK, MT7530_PORT_FALLBACK_MODE);
>  }
>  
> +/**
> + * mt753x_upstream_port_index - get the index of the upstream port.
> + *
> + * If the CPU port is local then this is the upstream port, but in the case of
> + * hierarchy the CPU port may be on another switch and the upstream port is
> + * then the DSA port pointing toward that CPU port. Note that
> + * dsa_switch_upstream_port() is not reliable because the conduit for a given
> + * port can be customized.
> + */
> +static int
> +mt753x_upstream_port_index(struct dsa_port *dp)
> +{
> +	struct dsa_port *cpu_dp = dp->cpu_dp;
> +
> +	/* Early port_enable on CPU port happens before cpu_dp is set. */
> +	if (!cpu_dp)
> +		return dsa_switch_upstream_port(dp->ds);
> +
> +	return dsa_towards_port(dp->ds, cpu_dp->ds->index, cpu_dp->index);
> +}

[Severity: Medium]
Does mt753x_upstream_port_index() return the wrong port when called on a
non-default CPU port?

In DSA, dp->cpu_dp is only populated on user and DSA ports and remains NULL
on CPU ports.  On a switch with multiple CPU ports (such as MT7531 with
ports 5 and 6), calling mt753x_upstream_port_index() on CPU port 5 hits the
!cpu_dp branch and returns dsa_switch_upstream_port(dp->ds) (port 6).  In
mt7530_hw_vlan_add(), the check:

	if (dp->index == mt753x_upstream_port_index(dp))
		val = MT7530_VLAN_EGRESS_STACK;

then evaluates to false for CPU port 5, configuring it as untagged or
tagged instead of MT7530_VLAN_EGRESS_STACK.

dsa_upstream_port(ds, port) and dsa_is_upstream_port(ds, port) in
include/net/dsa.h already handle both per-port dp->cpu_dp routing and
returning port directly when dp->cpu_dp is NULL, so using those helpers
avoids this regression.  Also, the /** kernel-doc comment on
mt753x_upstream_port_index() omits @dp, which triggers a W=1 kernel-doc
warning.

[ ... ]

> @@ -2635,7 +2818,7 @@ mt7531_setup_common(struct dsa_switch *ds)
>  		regmap_set_bits(priv->regmap, MT7531_DBG_CNT(i),
>  				MT7531_DIS_CLR);
>  
> -		if (dsa_is_cpu_port(ds, i)) {
> +		if (dsa_is_upstream_port(ds, i)) {
>  			mt753x_cpu_port_enable(ds, i);
>  		} else {
>  			mt7530_port_disable(ds, i);

[Severity: Medium]
Can enabling a DSA cascade port on MT7531 cause a NULL pointer dereference
in mt7531_mac_config()?

When port 5 on an MT7531 switch is configured in RGMII mode as an upstream
or downstream DSA link port (DSA_PORT_TYPE_DSA), dp->user is NULL, but
mt7531_mac_config() unconditionally dereferences it during phylink startup:

drivers/net/dsa/mt7530.c:mt7531_mac_config() {
	...
	if (phy_interface_mode_is_rgmii(interface)) {
		dp = dsa_to_port(ds, port);
		phydev = dp->user->phydev;
		mt7531_rgmii_setup(priv, interface, phydev);
	}
	...
}

[ ... ]

> @@ -3402,6 +3600,96 @@ static int mt7988_setup(struct dsa_switch *ds)
> +/* No manipulation of forwarding rules allowed in passthrough mode */
> +static const struct dsa_switch_ops mt7530_passthrough_switch_ops = {
> +	.get_tag_protocol       = mtk_get_tag_protocol,
> +	.setup                  = mt753x_setup,
> +	.teardown               = mt753x_teardown,
> +	.preferred_default_local_cpu_port = mt753x_preferred_default_local_cpu_port,
> +	.port_change_conduit	= mt753x_passthrough_port_change_conduit,
> +	.get_strings            = mt7530_get_strings,
> +	.get_ethtool_stats      = mt7530_get_ethtool_stats,
> +	.get_sset_count         = mt7530_get_sset_count,
> +	.get_eth_mac_stats      = mt7530_get_eth_mac_stats,
> +	.get_rmon_stats         = mt7530_get_rmon_stats,
> +	.get_eth_ctrl_stats     = mt7530_get_eth_ctrl_stats,
> +	.get_stats64            = mt7530_get_stats64,
> +	.set_ageing_time	= mt7530_passthrough_set_ageing_time,
> +	.port_enable            = mt7530_port_enable,
> +	.port_disable           = mt7530_port_disable,
> +	.port_change_mtu	= mt7530_passthrough_port_change_mtu,
> +	.port_max_mtu		= mt7530_port_max_mtu,
> +	.port_stp_state_set	= mt7530_passthrough_stp_state_set,
> +	.port_pre_bridge_flags	= mt7530_port_pre_bridge_flags,
> +	.port_bridge_flags	= mt7530_passthrough_port_bridge_flags,
> +	.port_bridge_join	= mt7530_passthrough_port_bridge_join,
> +	.port_bridge_leave	= mt7530_passthrough_port_bridge_leave,
> +	.port_fast_age		= mt7530_passthrough_port_fast_age,
> +	.port_fdb_add		= mt7530_passthrough_port_fdb_add,
> +	.port_fdb_del		= mt7530_passthrough_port_fdb_del,
> +	.port_fdb_dump		= mt7530_port_fdb_dump,
> +	.port_mdb_add		= mt7530_passthrough_port_mdb_add,
> +	.port_mdb_del		= mt7530_passthrough_port_mdb_del,
> +	.port_vlan_filtering	= mt7530_passthrough_port_vlan_filtering,
> +	.port_vlan_add		= mt7530_passthrough_port_vlan_add,
> +	.port_vlan_del		= mt7530_passthrough_port_vlan_del,
> +	.port_mirror_add	= mt753x_passthrough_port_mirror_add,
> +	.port_mirror_del	= mt753x_passthrough_port_mirror_del,
> +	.phylink_get_caps       = mt753x_phylink_get_caps,
> +	.support_eee            = dsa_supports_eee,
> +	.set_mac_eee            = mt753x_set_mac_eee,

[Severity: Low]
This isn't a bug, but most of the new no-op callbacks in
mt7530_passthrough_switch_ops appear unnecessary.  Because
mt753x_check_passthrough() requires the switch to have only one CPU port
and one DSA link port (and no user ports), only the tree-wide notifier
callbacks (.port_change_mtu, .port_fdb_add, .port_fdb_del, .port_mdb_add,
.port_mdb_del, .port_vlan_add, and .port_vlan_del) need no-op stubs to
avoid returning -EOPNOTSUPP.

.set_ageing_time, .port_stp_state_set, and .port_fast_age already default
to no-ops in the DSA core when left NULL, while .port_bridge_join,
.port_bridge_leave, .port_bridge_flags, .port_vlan_filtering,
.port_mirror_add, .port_mirror_del, .port_change_conduit, and
.port_setup_tc (along with user-port-only callbacks like
.port_pre_bridge_flags, .port_fdb_dump, .port_max_mtu, .support_eee,
.set_mac_eee, .port_hsr_join, and .port_hsr_leave) are never called on a
switch with no user ports.

> +	.conduit_state_change   = mt753x_conduit_state_change,

[Severity: Medium]
Does mt753x_conduit_state_change() program the wrong CPU port on a
downstream switch?

DSA broadcasts DSA_NOTIFIER_CONDUIT_STATE_CHANGE to every switch in the
tree, with cpu_dp = conduit->dsa_ptr pointing to the CPU port on the
upstream switch:

drivers/net/dsa/mt7530.c:mt753x_conduit_state_change() {
	...
	mask = BIT(cpu_dp->index);

	if (operational)
		priv->active_cpu_ports |= mask;
	else
		priv->active_cpu_ports &= ~mask;

	if (priv->active_cpu_ports) {
		val = MT7530_CPU_EN |
		      MT7530_CPU_PORT(__ffs(priv->active_cpu_ports));
	}

	regmap_update_bits(priv->regmap, MT753X_MFC,
			   MT7530_CPU_EN | MT7530_CPU_PORT_MASK, val);
	...
}

When a downstream switch's local upstream DSA port index differs from the
upstream switch's CPU port index (for example, upstream CPU port 6 wired to
downstream port 5), MT7530_CPU_PORT is set to cpu_dp->index instead of
dsa_towards_port(ds, cpu_dp->ds->index, cpu_dp->index), sending trapped
control frames (BPDUs, PAE, LLDP, LACP) to the wrong port on the downstream
switch.  In addition, wiring mt753x_conduit_state_change() in
mt7530_passthrough_switch_ops sets MT7530_CPU_EN on the passthrough switch
even though trapping is disabled in passthrough mode.

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

  parent 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 [this message]
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

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-219352@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