From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 285204A3E for ; Tue, 10 Mar 2026 00:00:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773100840; cv=none; b=YennbGtYnshq1S5Fj3EOwSap1iHrmL7qPAB+jPeczFqPs7PW0aT6P84sliRy6brQckeuQyv4pjge8t+/b06uLut/mAi0a8yZB12/iUBYXe0qvvpCZt90NkhRqE1J4aw5yptZ9F1126Y53JV4sdN3s26J3p+X1YgZqWFtyLpvAUY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773100840; c=relaxed/simple; bh=zqGCUHDNKaaInbNIceds5soxbCDX+Zv/hdXElnUWUEY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZOudBamW4E6iercoq40Zujw3ku8MImiQdWR0WJakkp3SGuM9PRkOMnFAZ4ziC7MvR3yb3zUgUFzLm7XVrj+HMGmi4tApQ623fuopy1nAcvTeIrOGlUZfnKX3ba+BCtwei+Rpm/ZUpBu7+t15Zr34hc1mxGWfYtRMeG99VxGueqs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RhEZVGju; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RhEZVGju" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-485350d142fso233875e9.1 for ; Mon, 09 Mar 2026 17:00:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773100837; x=1773705637; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=qfyFhbiwKWBc/U44rcjHHugcqpfm6yBMuIx9Ifg+nvo=; b=RhEZVGju02C1/ZKkd/jRRxSPHEmTIu1gR6tAFdnFa5qpbYQ6jP5zs8hlpvxpAHxTPr ce8FDF8d9Nx2eUUHQVtJCl319d4WqwvTLwQTjR2XVRkgCnn5/RyEYuLzEWHtwSD6cFsD yZohXQJirc4dsjHJt9gfbhy+ZUCOANwbea+3DyVFMUKuN977iTXwWwZvcc06jEc7FLlS yupGm0C/JtMhFCG9VWqPvhifON+Q6syh27U2Ba1VP8sKRVQDGirHTR10j5RhL9EPmVyL YrhPgtK97m4Zu/p4CclKOtF5elUEj4VGhdsWY5a8M4RZIsD8+QdNssHTX4e44eomIgZM GapA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773100837; x=1773705637; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qfyFhbiwKWBc/U44rcjHHugcqpfm6yBMuIx9Ifg+nvo=; b=JyNcJU3d8geH89E7iNKmKa6pTyIBG1XXabqViAP+oiCtNRXPazmVBIA+LUPH6p3yLt pWW+XDi0z1SxZ4oe8e5+Y+GljIn2kF8g3RR8NctFVe9VdN13wfQuFGH1kJpZtYESTkiX yJ9pdrhdNptJarNoUzJw66BKuL2edFH14T95iOezhMLrMc71TR7Cs7GanXzx+TYDKaTL 2izVHsdWRyfT9FzLtlJF6J/lnnZRPzYqRZQSThbZP0Q2Z2YVA9oeFKMqpEtl8+wlx01C hv8+29hjmIeKDmH/VTbQnsN3q5+NpGlfjTt7GebPXBolaS18pMoyydz8xnDvFMa1NLXG +wfg== X-Forwarded-Encrypted: i=1; AJvYcCWNRvBkAqSch9c40QZnoEs5amOsKwtOPgACpkc1pNQU6Zvq0MqYv3z20wwJIAcZ6FyajMsS+XKjwBR64bM=@vger.kernel.org X-Gm-Message-State: AOJu0YzNw1FGYGXmEc8MQF6gg+K6iV9iRICGMqwlfRHyqCSRn4nYLB8+ GBZAnFQF+viG7qu3l5U44dLWY0XwvF1Yz3Lvjdd0VuAgiCfXUtqppdB4 X-Gm-Gg: ATEYQzxVx3Qt0M6p/6/d/eo+fhSzyb7FMkwP+7+MerNbnmYwyLA1V1n6SclUE3erMnw uSHx8Cgmtt047QhYm6JzmAxxwVgA0VpLJ4dUviXqC7flKOxG9tSh8+OiTk77DQEOj7dkC8OwQgl upKYnpffOrxpvkHrSlm7O1rOCr3hF6YzqRRcMO5HIcQZABunCN7BJJK7U4q20gp3AsfOrV+kKXS apJwKRdHeS4R4KvIbc1xrcz7T/XWgK+EhlWJz68iB3Sj1xSzyHK0aXqzVUncvynlQ6wfP634PRM wAgj75mb5nQiKuZEkAgvddFsK/v6hUCW4M/kgaPVraO11EoclTaYZID1/JpNUshFUGVVvGes9xJ WIzJEE5QOWpBtyPRnYmKdyFsXF05XWcvfOTntTq1IHyaJekOkdAc4LiwPsBjHH7e59U167z/i33 nfKIFXO047AqDnAA== X-Received: by 2002:a05:600c:3588:b0:485:385f:674f with SMTP id 5b1f17b1804b1-485385f693dmr70680995e9.6.1773100837086; Mon, 09 Mar 2026 17:00:37 -0700 (PDT) Received: from skbuf ([2a02:2f04:d00a:e00:8799:3a7d:3c86:3200]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-485244b6e9esm177773195e9.5.2026.03.09.17.00.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Mar 2026 17:00:36 -0700 (PDT) Date: Tue, 10 Mar 2026 02:00:33 +0200 From: Vladimir Oltean To: Daniel Golle Cc: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Russell King , Florian Fainelli , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net] net: dsa: skip user_mii_bus fallback if phy-handle is set Message-ID: <20260310000033.oj64hv7dhe4vaawk@skbuf> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Fri, Mar 06, 2026 at 03:16:32AM +0000, Daniel Golle wrote: > When phylink_of_phy_connect() returns -ENODEV, dsa_user_phy_setup() > falls back to connecting the port to the PHY at dp->index on the > switch's internal MDIO bus. This fallback was introduced to handle > switches where no explicit phy-handle is given in DT. However, if a > phy-handle property is present but the referenced PHY device is not > yet available at registration time, phylink_of_phy_connect() also > returns -ENODEV, causing the fallback to potentially attach the wrong > PHY device instead of propagating the error. > > This becomes a very weird bug on switches on which the PHY address > isn't equal to the corresponding DSA port's index, as failure to > attach the PHY with -ENOENT then just attaches another PHY, typically > rendering two ports unusable instead of just one (and until you read > and understand the code it looks like an alarming memory corruption > rather than just PHY not being ready on time). I think you've just discovered an undocumented requirement than actually fixing a bug with this patch. If anything, the bug is in mxl862xx. When making the comments that led to commit aefa52a28a36 ("net: dsa: mxl862xx: rename MDIO op arguments"), I missed the fact that mxl862xx_setup_mdio() is also setting ds->user_mii_bus. Please remove that. The only case when you can share the same function pointers between a normal MDIO bus ops and ds->user_mii_bus ops is when the MDIO addresses are equal to the port. Because otherwise, you need to translate the "port" given to the ds->user_mii_bus into an MDIO address. If you don't, you'll always connect to the wrong port using the ds->user_mii_bus, if the internal PHY is not described in OF. > Fix this by calling fwnode_get_phy_node() before falling back: > If a phy-handle fwnode exists, skip the internal bus fallback and let > the -ENODEV propagate to the caller. The fallback is only taken when > no phy-handle is present in DT, which was the original intent. > > Fixes: aab9c4067d238 ("net: dsa: Plug in PHYLINK support") > Signed-off-by: Daniel Golle > --- > net/dsa/user.c | 14 ++++++++++++-- > 1 file changed, 12 insertions(+), 2 deletions(-) > > diff --git a/net/dsa/user.c b/net/dsa/user.c > index c4bd6fe90b455..90e540f490bb3 100644 > --- a/net/dsa/user.c > +++ b/net/dsa/user.c > @@ -2656,6 +2656,7 @@ static int dsa_user_phy_setup(struct net_device *user_dev) > { > struct dsa_port *dp = dsa_user_to_port(user_dev); > struct device_node *port_dn = dp->dn; > + struct fwnode_handle *phy_fwnode; > struct dsa_switch *ds = dp->ds; > u32 phy_flags = 0; > int ret; > @@ -2682,9 +2683,18 @@ static int dsa_user_phy_setup(struct net_device *user_dev) > ret = phylink_of_phy_connect(dp->pl, port_dn, phy_flags); > if (ret == -ENODEV && ds->user_mii_bus) { > /* We could not connect to a designated PHY or SFP, so try to > - * use the switch internal MDIO bus instead > + * use the switch internal MDIO bus instead. Only fall back if > + * no phy-handle was specified in DT. If a phy-handle exists > + * but the PHY device is missing (e.g. not yet ready at > + * registration time), connecting to a PHY at dp->index would > + * attach the wrong PHY device. > */ > - ret = dsa_user_phy_connect(user_dev, dp->index, phy_flags); > + phy_fwnode = fwnode_get_phy_node(of_fwnode_handle(port_dn)); > + if (IS_ERR(phy_fwnode)) > + ret = dsa_user_phy_connect(user_dev, dp->index, > + phy_flags); > + else > + fwnode_handle_put(phy_fwnode); Yeah, phylib seems incapable of deferring probing of a MAC driver that connects to the PHY at probe time and doesn't find it. This is because the code is shared with drivers that connect to the PHY at ndo_open() time, and returning -EPROBE_DEFER to them wouldn't make any sense. So phylib doesn't return -EPROBE_DEFER to anyone. Actually this is one of the reasons why I was looking to upstream a change that moves the DSA PHY connection to ndo_open(). It allows the PHY probing to settle. I would appreciate not complicating this logic if we don't have to. > } > if (ret) { > netdev_err(user_dev, "failed to connect to PHY: %pe\n", > -- > 2.53.0