public inbox for linuxppc-dev@ozlabs.org
 help / color / mirror / Atom feed
From: Wei Fang <wei.fang@nxp.com>
To: Jakub Kicinski <kuba@kernel.org>,
	Vladimir Oltean <vladimir.oltean@nxp.com>
Cc: Claudiu Manoil <claudiu.manoil@nxp.com>,
	Clark Wang <xiaoning.wang@nxp.com>,
	"andrew+netdev@lunn.ch" <andrew+netdev@lunn.ch>,
	"davem@davemloft.net" <davem@davemloft.net>,
	"edumazet@google.com" <edumazet@google.com>,
	"pabeni@redhat.com" <pabeni@redhat.com>,
	"robh@kernel.org" <robh@kernel.org>,
	"krzk+dt@kernel.org" <krzk+dt@kernel.org>,
	"conor+dt@kernel.org" <conor+dt@kernel.org>,
	"f.fainelli@gmail.com" <f.fainelli@gmail.com>,
	Frank Li <frank.li@nxp.com>,
	"chleroy@kernel.org" <chleroy@kernel.org>,
	"horms@kernel.org" <horms@kernel.org>,
	"linux@armlinux.org.uk" <linux@armlinux.org.uk>,
	"andrew@lunn.ch" <andrew@lunn.ch>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"imx@lists.linux.dev" <imx@lists.linux.dev>
Subject: RE: [PATCH v4 net-next 10/14] net: dsa: netc: introduce NXP NETC switch driver for i.MX94
Date: Wed, 8 Apr 2026 08:59:24 +0000	[thread overview]
Message-ID: <AM8PR04MB72840DBFC7F3FD578DFF6AF8885BA@AM8PR04MB7284.eurprd04.prod.outlook.com> (raw)
In-Reply-To: <20260403011738.1795644-1-kuba@kernel.org>

> > +static int netc_init_switch_id(struct netc_switch *priv)
> > +{
> > +	struct netc_switch_regs *regs = &priv->regs;
> > +	struct dsa_switch *ds = priv->ds;
> > +
> > +	/* The value of 0 is reserved for the VEPA switch and cannot
> > +	 * be used.
> > +	 */
> > +	if (ds->index > SWCR_SWID || !ds->index) {
> > +		dev_err(priv->dev, "Switch index %d out of range\n",
> > +			ds->index);
> > +		return -ERANGE;
> > +	}
> 
> Does this check cause the probe to fail unconditionally for standard
> single-switch topologies?
> 
> The DSA core typically assigns ds->index = 0 by default for the first switch.
> Because !ds->index evaluates to true for index 0, this setup function will
> always fail unless the dsa,member property is explicitly overridden in the
> device tree.

As I mentioned in another mail, we added the 'dsa,member' property to the
netc switch DT-binding doc, specifying that the 'member' (switch index) value
cannot be 0. And 'dsa,member' is a required property for netc switch.

> 
> Could the driver translate the hardware ID internally, for example by writing
> ds->index + 1 to NETC_SWCR, rather than forcing this hardware-specific
> restriction onto the software DSA index?

The current approach is based on Vladimir's suggestion. I need to confirm with
Vladimir which approach is better.

Hi Vladimir,

What are your thoughts on this suggestion? Is this approach better?

> 
> [ ... ]
> > +	for_each_available_child_of_node_scoped(ports, child) {
> > +		/* If the node does not have phy-handle property, then
> > +		 * the port does not connect to a PHY, so the port is
> > +		 * not the EMDIO consumer.
> > +		 */
> > +		phy_node = of_parse_phandle(child, "phy-handle", 0);
> > +		if (!phy_node)
> > +			continue;
> > +
> > +		if (!netc_port_is_emdio_consumer(child)) {
> > +			of_node_put(phy_node);
> > +			continue;
> > +		}
> > +
> > +		phydev = of_phy_find_device(phy_node);
> > +		of_node_put(phy_node);
> > +		if (!phydev) {
> > +			err = -EPROBE_DEFER;
> > +			goto out;
> > +		}
> 
> Could this logic cause an infinite probe deferral loop for ports sharing an
> internal MDIO bus?
> 
> The netc_port_is_emdio_consumer() function assumes any port node without
> an
> mdio child is an EMDIO consumer waiting for an external controller. However,
> if multiple sibling ports on the same switch share a single internal MDIO bus
> defined under one port, the other ports will lack an mdio child node.
> 
> This would cause those ports to be mistakenly treated as external EMDIO
> consumers, calling of_phy_find_device(). Because the internal MDIO bus is not
> registered until later in netc_setup(), the PHY device cannot be found, and
> the driver returns -EPROBE_DEFER.
> 
> Since netc_setup() is never reached, the MDIO bus is never registered,
> causing an infinite deferral loop. Could the driver more accurately identify
> whether the PHY belongs to its own switch before deferring?

This case will not be true, from the hardware perspective, the switch ports
do not support share a single internal MDIO bus defined under one port.
The internal MDIO bus of a port can only access its own external PHY. So
a switch port must either use EMDIO to access its PHY or its internal MDIO
bus to access its PHY.

> 
> > +
> > +		put_device(&phydev->mdio.dev);
> > +	}
> > +
> > +out:
> > +	of_node_put(ports);
> > +
> > +	return err;
> > +}
> > +
> > +static int netc_switch_pci_init(struct pci_dev *pdev)
> > +{
> [ ... ]
> > +	regs->base = pci_ioremap_bar(pdev, NETC_REGS_BAR);
> > +	if (!regs->base) {
> > +		err = -ENXIO;
> > +		dev_err(dev, "pci_ioremap_bar() failed\n");
> > +		goto release_mem_regions;
> > +	}
> [ ... ]
> > +static void netc_switch_pci_destroy(struct pci_dev *pdev)
> > +{
> > +	struct netc_switch *priv = pci_get_drvdata(pdev);
> > +
> > +	iounmap(priv->regs.base);
> > +	pci_release_mem_regions(pdev);
> > +	pci_disable_device(pdev);
> > +}
> 
> Does unmapping the memory here introduce a use-after-unmap issue when the
> MDIO bus is unregistered?
> 
> The driver registers the MDIO bus using devm_of_mdiobus_register(), meaning
> devres cleans it up asynchronously after the remove function returns or when
> probe fails.
> 
> However, in netc_switch_pci_destroy(), the driver explicitly unmaps the PCI
> I/O memory via iounmap(). Since netc_switch_pci_destroy() is called
> synchronously inside the remove function and probe error paths, the memory is
> unmapped before the MDIO bus is unregistered by devres.
> 
> When devres eventually unregisters the MDIO bus, it detaches PHY devices,
> which often perform MDIO transactions during removal. Because the
> underlying
> memory priv->regs.base is already unmapped, these MDIO read/write callbacks
> could trigger a synchronous external abort or kernel panic.
> 
> Would it be better to use pcim_iomap() to tie the memory mapping lifecycle to
> devres, ensuring it outlives the MDIO bus?

Great, I will pcim_iomap().



  reply	other threads:[~2026-04-08  8:59 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-31 11:30 [PATCH v4 net-next 00/14] Add preliminary NETC switch support for i.MX94 Wei Fang
2026-03-31 11:30 ` [PATCH v4 net-next 01/14] dt-bindings: net: dsa: update the description of 'dsa,member' property Wei Fang
2026-04-08 13:40   ` Rob Herring (Arm)
2026-03-31 11:30 ` [PATCH v4 net-next 02/14] dt-bindings: net: dsa: add NETC switch Wei Fang
2026-04-08 13:43   ` Rob Herring
2026-03-31 11:30 ` [PATCH v4 net-next 03/14] net: enetc: add pre-boot initialization for i.MX94 switch Wei Fang
2026-04-03  1:17   ` Jakub Kicinski
2026-04-08  6:55     ` Wei Fang
2026-03-31 11:30 ` [PATCH v4 net-next 04/14] net: enetc: add basic operations to the FDB table Wei Fang
2026-04-03  1:17   ` Jakub Kicinski
2026-04-08  7:04     ` Wei Fang
2026-03-31 11:30 ` [PATCH v4 net-next 05/14] net: enetc: add support for the "Add" operation to VLAN filter table Wei Fang
2026-04-03  1:17   ` Jakub Kicinski
2026-04-08  7:12     ` Wei Fang
2026-03-31 11:30 ` [PATCH v4 net-next 06/14] net: enetc: add support for the "Update" operation to buffer pool table Wei Fang
2026-04-03  1:17   ` Jakub Kicinski
2026-04-08  7:25     ` Wei Fang
2026-03-31 11:30 ` [PATCH v4 net-next 07/14] net: enetc: add support for "Add" and "Delete" operations to IPFT Wei Fang
2026-04-03  1:17   ` Jakub Kicinski
2026-04-08  7:37     ` Wei Fang
2026-03-31 11:30 ` [PATCH v4 net-next 08/14] net: enetc: add multiple command BD rings support Wei Fang
2026-03-31 11:30 ` [PATCH v4 net-next 09/14] net: dsa: add NETC switch tag support Wei Fang
2026-04-03  1:17   ` Jakub Kicinski
2026-04-08  8:35     ` Wei Fang
2026-03-31 11:30 ` [PATCH v4 net-next 10/14] net: dsa: netc: introduce NXP NETC switch driver for i.MX94 Wei Fang
2026-04-03  1:17   ` Jakub Kicinski
2026-04-08  8:59     ` Wei Fang [this message]
2026-04-09  8:07       ` Vladimir Oltean
2026-03-31 11:30 ` [PATCH v4 net-next 11/14] net: dsa: netc: add phylink MAC operations Wei Fang
2026-04-03  1:17   ` Jakub Kicinski
2026-04-08  9:44     ` Wei Fang
2026-03-31 11:30 ` [PATCH v4 net-next 12/14] net: dsa: netc: add more basic functions support Wei Fang
2026-04-03  1:17   ` Jakub Kicinski
2026-04-08 11:09     ` Wei Fang
2026-03-31 11:30 ` [PATCH v4 net-next 13/14] net: dsa: netc: initialize buffer bool table and implement flow-control Wei Fang
2026-04-03  1:17   ` Jakub Kicinski
2026-04-08 11:16     ` Wei Fang
2026-03-31 11:30 ` [PATCH v4 net-next 14/14] net: dsa: netc: add support for the standardized counters Wei Fang

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=AM8PR04MB72840DBFC7F3FD578DFF6AF8885BA@AM8PR04MB7284.eurprd04.prod.outlook.com \
    --to=wei.fang@nxp.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=andrew@lunn.ch \
    --cc=chleroy@kernel.org \
    --cc=claudiu.manoil@nxp.com \
    --cc=conor+dt@kernel.org \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@google.com \
    --cc=f.fainelli@gmail.com \
    --cc=frank.li@nxp.com \
    --cc=horms@kernel.org \
    --cc=imx@lists.linux.dev \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=robh@kernel.org \
    --cc=vladimir.oltean@nxp.com \
    --cc=xiaoning.wang@nxp.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