From nobody Thu Sep 24 15:11:48 2026 Received: from mail-wr2-f12.google.com (mail-wr2-f12.google.com [74.125.225.76]) (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 5F7365540B3 for ; Tue, 22 Sep 2026 13:20:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.225.76 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790083206; cv=none; b=BW+TPPaJPJrD52RxsZpAMEtPPCx14etj5PtzBK2LnW0iebNc5UepD45ZAqISh9J/nEk22PPdcOxuCdzsSLUwCp52s1gXbduHn6A5GL5Q12zaiVFbbuu0JYrPONCJcDHYTmAlr5UhnGzp3FXDfDZrfrV+9aAvq/4Ry6QGDSdopz4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790083206; c=relaxed/simple; bh=gsZuiBomw3OKmUFOOZhVWmaCJMauX66p+dFd5DJwGMw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r5FtZ2g7rEKqWPJqPKgZT7lfWGlD21vP8UadJPNfL2VqGO5hZgMWWLeoVTxuU56dX/pUAu9srbV4qowk8LoTCI82ypBuklQcZQxKClm7Dm4yoK23VxaNfX8JTAUtV9s0VMq/IrrMXlM9sb45Auzv2uWIUzIxy4trQ7MrCPrvS6w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=lex.la; spf=pass smtp.mailfrom=lex.la; dkim=pass (2048-bit key) header.d=lex.la header.i=@lex.la header.b=SYyPRLPA; arc=none smtp.client-ip=74.125.225.76 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=lex.la Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lex.la Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lex.la header.i=@lex.la header.b="SYyPRLPA" Received: by mail-wr2-f12.google.com with SMTP id ffacd0b85a97d-482f6350faaso2282020f8f.0 for ; Tue, 22 Sep 2026 06:20:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lex.la; s=google; t=1790083202; x=1790688002; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=WM/b3m0dUk2cSRvU8lTJOAFjkhu3257/FQCic/mBT/0=; b=SYyPRLPAYd52HJR/59Bsd8Q39z4geiy+V/3vca1I/EX5gZ4GhHOO/7A8R4GNJFFcvf +MRvLrZ6xYpYmU/h8ODjRPKyZ4BxwktgpmWGfb5AfwunEERYW5aPqVCw9AdwIoq46t8W TryDakjsOnmZOP8357uaUtt+zmKYN6gkiuhkUcHChRXG30FzJ3XrcA/imQgFlVFlKNTN ds2nNyycuLsyS2dBkDbAYYHGf8aHAF8doTcj/2dmbYGmJFbh8le/z6oAM+oD7mhn6G+4 TmNUv54ynW4bqG7JapZMwtOJncVmymy08HLU+lv2Sgt0JXKVaZWCAvl591S+BHXubDhQ NfKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790083202; x=1790688002; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=WM/b3m0dUk2cSRvU8lTJOAFjkhu3257/FQCic/mBT/0=; b=v97BgV6cUiC2S10S0Wigu0OOWgBy6TCR0V14qUPCK3LHvCvdMGhGL/oVGaH/9w5LU6 TFScQEC2GufwDuK2RAlyNF5CtKGHIbuLg1t4s+6AOvQ0nBC2KJPIIRfj2GDWAVgE8GLQ 99ilxx01kGJLeR5q6QNOpSG0e2qm0v0KL905QPzZChvAAIVPywy5iTSM6KfrkWtxwr6I Lv5nw5/ie7c2+XeVfSLWs4l/4BxVWTY8UsvcglXuqfLExCHE4sY7nk8A1n/6vXcn16SR Ddce5ioxxHiPooWlkLFVNDtd8fjw55dbXBnln2Kn0q6koL09/YS0RagroKSdYvMbKTrc 1qWA== X-Forwarded-Encrypted: i=1; AKwUvBz7dz/BZBJQ9r8i8DKGpMeCcQ0viVoO/fz9EBf6TDkmMP/aItaKVDby0YZ261EHlYuFOt62yXr/0fZqo70=@vger.kernel.org X-Gm-Message-State: AFuF++kobW2uz05RPugNmsVU+YAVoQA55hA+4sIpSUQTTB+oo6/T5AWb DQuHr+McQ4P9gKefDbGDdd9otadkanPczfufXtRgRmVKC1RuIJ1N2ImO6NOhILFlheA= X-Gm-Gg: AYBFou3mpnXJvnTUuPBiSM3/3ZUcJ7prWkgef7eaJYN0chwaj8Kt8ZTktRcZIFEF5PE hIqT2pIpVho4gxjXAnBV1Wv4K4kEj7CsXWq0c3wR3MkBon+Jv7up+T0lZLjo0NKQSjnDmmD3Yav xsMRCLpSH7fUy1zoWXGPErXPdw/rrud+Vl+zSkjed/Kh9fAT3Aw/Evs8pIct0InxX04PX7t/jQh QaAbwHaUpM0ztpz2kAfj/BNoYYFNwB7d7XijSNGZTCxOalh/9rbgtA5OcFq/+7ZKAopLfch4HwL ynNKf0+HeyGK4nVDyKZSkWb8V5tSHPigHgqX/LoFn0z50VmL+1d5pMV6oZ4oJbX+1STeFcNr76H Wu3IlnEuj/7p/1HmrUfFcSC4eKUhqtXM5NBM/bHbOPgOZu9R44uBvIeXxm0C96dLCbZNdu+ve9U NjT7voeiHfEUOKUAEItk61zMBG0abb7+pAPd49NOz3D1eYneKtrg== X-Received: by 2002:a05:6000:2409:b0:487:489:7af1 with SMTP id ffacd0b85a97d-4871e3645a7mr23836578f8f.48.1790083202495; Tue, 22 Sep 2026 06:20:02 -0700 (PDT) Received: from remote-01 ([84.17.55.230]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-488627929a4sm4085220f8f.35.2026.09.22.06.20.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2026 06:20:02 -0700 (PDT) From: Aleksei Sviridkin To: netdev@vger.kernel.org Cc: andrew@lunn.ch, andrew+netdev@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, olteanv@gmail.com, Thangaraj.S@microchip.com, UNGLinuxDriver@microchip.com, steve.glendinning@shawell.net, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Aleksei Sviridkin Subject: [PATCH net v10 1/4] net: usb: lan78xx: register the PHY interrupt with the MDIO bus Date: Tue, 22 Sep 2026 16:19:52 +0300 Message-ID: <20260922131955.4175785-2-f@lex.la> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260922131955.4175785-1-f@lex.la> References: <20260922131955.4175785-1-f@lex.la> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The interrupt this driver maps for its PHY is written only into phydev->irq, while the bus table mdiobus->irq[] keeps reading PHY_POLL for the same address. That table is where phylib records what the bus described - phy_device_create() seeds phydev->irq from it - so the number lives only as long as nothing else writes that one field. Put it in the table before the bus is registered, so that the PHY the scan creates is born with the number, and drop the write to phydev->irq that phylib then makes by itself. Fill the whole table rather than one entry: for 7801 the address is not known until the scan, and for the other two phy_mask leaves only address 1 readable, so a loop costs less than a second switch on the chip id. A devicetree PHY node still overrides that. Found going through the drivers that keep a PHY interrupt outside the bus table, so that the restore on detach later in this series has a number to hand back here as well. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin --- Notes: Compile-tested only; I have no LAN78xx device. =20 No Fixes: tag on this one. On its own it fixes nothing - nothing reads = the bus table back until patch 3 - which is also why it sorts ahead of that patch rather than after it. =20 lan78xx_setup_irq_domain() runs before lan78xx_mdio_init() in lan78xx_bind(), so the number is already mapped where the table is fill= ed. The fill covers the whole table because only the 7801 case leaves the address open until of_mdiobus_register() has scanned; 7800 and 7850 set phy_mask a few lines above, so every entry but address 1 is unreachable and writing them costs nothing. =20 The fill is a default rather than an override. For a PHY node that describes an interrupt, fwnode_mdiobus_phy_device_register() writes the devicetree number over the table entry, and into phydev->irq, once the device exists. That inverts the old order, where the driver's own number was written last and won. Neither in-tree lan78xx PHY node carries an interrupts property, so nothing in tree changes, but a devicetree that described one would now be believed. =20 Teardown order keeps the number live for as long as it is read: lan78xx_disconnect() detaches the PHY through phylink_disconnect_phy(),= and lan78xx_unbind() calls lan78xx_remove_irq_domain() only afterwards. drivers/net/usb/lan78xx.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c index cb782d81d84f..d7472d894c8d 100644 --- a/drivers/net/usb/lan78xx.c +++ b/drivers/net/usb/lan78xx.c @@ -2092,6 +2092,7 @@ static int lan78xx_mdio_init(struct lan78xx_net *dev) { struct device_node *node; int ret; + int i; =20 dev->mdiobus =3D mdiobus_alloc(); if (!dev->mdiobus) { @@ -2118,6 +2119,10 @@ static int lan78xx_mdio_init(struct lan78xx_net *dev) break; } =20 + if (dev->domain_data.phyirq > 0) + for (i =3D 0; i < PHY_MAX_ADDR; i++) + dev->mdiobus->irq[i] =3D dev->domain_data.phyirq; + node =3D of_get_child_by_name(dev->udev->dev.of_node, "mdio"); ret =3D of_mdiobus_register(dev->mdiobus, node); of_node_put(node); @@ -2892,13 +2897,6 @@ static int lan78xx_phy_init(struct lan78xx_net *dev) return 0; } =20 - /* if phyirq is not set, use polling mode in phylib */ - if (dev->domain_data.phyirq > 0) - phydev->irq =3D dev->domain_data.phyirq; - else - phydev->irq =3D PHY_POLL; - netdev_dbg(dev->net, "phydev->irq =3D %d\n", phydev->irq); - ret =3D phylink_connect_phy(dev->phylink, phydev); if (ret) { netdev_err(dev->net, "can't attach PHY to %s, error %pe\n", --=20 2.53.0 From nobody Thu Sep 24 15:11:48 2026 Received: from mail-wr2-f12.google.com (mail-wr2-f12.google.com [74.125.225.76]) (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 290CD556BB5 for ; Tue, 22 Sep 2026 13:20:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.225.76 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790083208; cv=none; b=hFK9V845iHzVaGSvHWS8/ISCKWHNSCUk5fpXVhXOeV6/Ky8PDAa5S8qUDLlCpXghpweoFLCyZen9gAlQpwAeTA/T3mlUu18KTGqpZ3t3sgUbzl0HKGWCxv4EtFJB4bIy7sTMWwrWcSBJvUpGDTOX4IPxP264Hjr5aGWnGOyVIw8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790083208; c=relaxed/simple; bh=Sgp77iYbLIi+6Rz08RYYMpSvbU+J3sLsxaKpfNa+/AM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NtVXsQeLC0cm8HH/FlhdN1v//ivgOlVXe4Q04Vzu//z+cDp+wDi/dervc+rLMQrhBjclGxXrgZDx301NjRjKkckPh7kVcHQcNF2fYXWqtOd7OHx7gmHLZEK3EhSHHOYLG4dj4fQ4ob680qWyPNB9wCRPNamck5OE8/WxlA3jQ4I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=lex.la; spf=pass smtp.mailfrom=lex.la; dkim=pass (2048-bit key) header.d=lex.la header.i=@lex.la header.b=B0kAQczk; arc=none smtp.client-ip=74.125.225.76 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=lex.la Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lex.la Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lex.la header.i=@lex.la header.b="B0kAQczk" Received: by mail-wr2-f12.google.com with SMTP id ffacd0b85a97d-485b1d2874aso3044416f8f.1 for ; Tue, 22 Sep 2026 06:20:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lex.la; s=google; t=1790083204; x=1790688004; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=TzOBEh/e/FQTnUBYv6JcL5S3LbvXz87hjn6nnrCmcuo=; b=B0kAQczkt4MnvF3N/Ax0VYDUdL7f12dSVBWJp46XG3nyq/d563WIJBbeuEKEHXLVjn kn0Ttkwxloc4LNcL9var4Tjh1SBHtyLDf0luNo382KPeNmJPDqrp0nuMQhiX0+RZpNsl ffOmhRvw+0ClxxioQrhHjNCW/eO+XOaM59Qs60fSTz5xGbdxSY8jA9DLNyVPpabc+VIb kNzDiZ8e/IfEhMbjqdh/70txA7FeOoyO/h/Amz0bdrS6Tt3y7b0fxviQJgmxmU+4jpwz jTiuN9KJMk03kEBf4GnSLQzWLzS8EHZF3sH3AORXezORVBfgHmFefcE5t3qk6bViyR0r jtVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790083204; x=1790688004; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=TzOBEh/e/FQTnUBYv6JcL5S3LbvXz87hjn6nnrCmcuo=; b=FJuCwF4d6JC960IZnj+yVLCnRrhX8moBLKtlEEDcVQOZ79mTU10T4Amuxtf1NHS8b0 ElHiXdjzQGUr4/I0tdWLIzJvGwIP3IKegzX6d7sOqU1iiOLkOZGP0yFe5XuCgegNRsyX te1hBcN3sKsEiKRQQi9xk2pW8UlhfmhHdFWJBKOenntjOlAs7cjD4nvPQAxurZsfUI8L ZOih72dVquM+6Vv7oEhHMBKvTJFi+1A5IxADj37RHwjKlBQTLI6jTu0imKUmkk+HnWWj WiidsGlKkz44JGefv74hAKdBYnrGEEjeVJVu5Zspx8sUQ9K/Whxp8Li1XsJsuleRoa5P izaw== X-Forwarded-Encrypted: i=1; AKwUvBzz1J6IiWOyo7C7mOUEyVksNkVqyrMuYSaNjfqVVfSvZVab2AUz7I3U3fo2Ifl4LLXiHi9CA11O7SaWzDs=@vger.kernel.org X-Gm-Message-State: AFuF++m2Vbf8QpITdcA5cYS/JKVCn2lBj1rnSshxqlA+eloePoICQCVM fS/AHcsPWHPa1leDqpsgphae9r7wq5uYtoVFaXxq4I10JYfS3YAA9h0OybuKJfqGiuo= X-Gm-Gg: AYBFou12PVH6su3GZtI7M4PN6ek7d6NqBy5LsPt41sTHOx2yaZzdGo46/rTZkMnXj5r zICcZpMPip8+C62jxEc9bG8SadBuV71hHhfHwwodq0W/Nx4wnzLVstRMAZhId9+50ppvgP+nfL0 vHjuDI+zlwNCF42Oc61YC/2UfTwbC7x0rYYlUokG1r+pGY/OcqIJftS/9jgbhgibokEYF3UTcwC bzxXB7RZRk1ebCXaqDuQ5mbpXahn3Le4YIe0ZCJj8zRoVtLv4WNMA2f6Z3DX2e7fO0Yb9Gs1kHG FJOsjQx/Q6TlJ1ecuvwuDmAwqYBOT9D1meN4dLsWaK8mrKNpnUjlo2oPKqtyrzkPlO41AI2bMLm 3FnXwfjfDTQMSggxumP+yoB8H+SwPTEeWCafk4XduInyOty43XV4qp16pW12I0nlyuocGO4H1q0 Lz7Dkoul8l0EAYkJI3TBIzxSCKqGUiiGXHXQejueyxeDo6ogPhVKP6Sn+w+oOi X-Received: by 2002:a5d:64e6:0:b0:487:27f9:83b with SMTP id ffacd0b85a97d-48727f90bbfmr16658287f8f.48.1790083204353; Tue, 22 Sep 2026 06:20:04 -0700 (PDT) Received: from remote-01 ([84.17.55.230]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-488627929a4sm4085220f8f.35.2026.09.22.06.20.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2026 06:20:03 -0700 (PDT) From: Aleksei Sviridkin To: netdev@vger.kernel.org Cc: andrew@lunn.ch, andrew+netdev@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, olteanv@gmail.com, Thangaraj.S@microchip.com, UNGLinuxDriver@microchip.com, steve.glendinning@shawell.net, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Aleksei Sviridkin Subject: [PATCH net v10 2/4] net: usb: smsc95xx: register the PHY interrupt with the MDIO bus Date: Tue, 22 Sep 2026 16:19:53 +0300 Message-ID: <20260922131955.4175785-3-f@lex.la> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260922131955.4175785-1-f@lex.la> References: <20260922131955.4175785-1-f@lex.la> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The interrupt this driver maps for its PHY is written only into phydev->irq, while the bus table mdiobus->irq[] keeps reading PHY_POLL for the same address. That table is where phylib records what the bus described - phy_device_create() seeds phydev->irq from it - so the number lives only as long as nothing else writes that one field. The bus is the one this function is about to register, so put the number in its table first and let the scan seed the PHY from there. The whole table gets it: with an external PHY the address is not known until the scan, and with the internal one phy_mask has already left a single reachable entry, so a loop costs less than a branch on which case this is. Found going through the drivers that keep a PHY interrupt outside the bus table, so that the restore on detach later in this series has a number to hand back here as well. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin --- Notes: Compile-tested only; I have no LAN95xx device. =20 No Fixes: tag, for the same reason as patch 1: the write has no reader = until patch 3 lands. =20 The mapping is created before mdiobus_alloc(), so the number is in hand where the table is filled, and mdiobus_alloc_size() is the only thing i= n the tree that writes PHY_POLL into that table - a fill placed after the all= oc and before mdiobus_register() is not undone by the scan. The fill cover= s the whole table because the external-PHY case leaves the address to phy_find_first() afterwards; on the internal path phy_mask has already reduced it to one entry. =20 Teardown order keeps the number live for as long as it is read: smsc95xx_unbind() disconnects the PHY before it disposes the interrupt mapping. drivers/net/usb/smsc95xx.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c index 42e4048b574b..b629092b94c2 100644 --- a/drivers/net/usb/smsc95xx.c +++ b/drivers/net/usb/smsc95xx.c @@ -1147,8 +1147,8 @@ static void smsc95xx_handle_link_change(struct net_de= vice *net) static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf) { struct smsc95xx_priv *pdata; + int ret, phy_irq, i; char usb_path[64]; - int ret, phy_irq; u32 val; =20 ret =3D usbnet_get_endpoints(dev, intf); @@ -1239,6 +1239,9 @@ static int smsc95xx_bind(struct usbnet *dev, struct u= sb_interface *intf) snprintf(pdata->mdiobus->id, ARRAY_SIZE(pdata->mdiobus->id), "usb-%03d:%03d", dev->udev->bus->busnum, dev->udev->devnum); =20 + for (i =3D 0; i < PHY_MAX_ADDR; i++) + pdata->mdiobus->irq[i] =3D phy_irq; + ret =3D mdiobus_register(pdata->mdiobus); if (ret) { netdev_err(dev->net, "Could not register MDIO bus\n"); @@ -1252,7 +1255,6 @@ static int smsc95xx_bind(struct usbnet *dev, struct u= sb_interface *intf) goto unregister_mdio; } =20 - pdata->phydev->irq =3D phy_irq; pdata->phydev->is_internal =3D pdata->is_internal_phy; =20 /* detect device revision as different features may be available */ --=20 2.53.0 From nobody Thu Sep 24 15:11:48 2026 Received: from mail-wm2-f13.google.com (mail-wm2-f13.google.com [74.125.225.141]) (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 0B8795540B7 for ; Tue, 22 Sep 2026 13:20:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.225.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790083212; cv=none; b=m0mnft8s97kJfywwwSaUUdklB+UN6d2qWT4nEoLfaXvam0HI+8MmIuuzkQ9BBlXy3DbdK/pfKJdcDmXwUU+SzFEHdPWLBE44Jsd01fAPBKid5O3sU0NCfYcJ0P1lljr2v9OjK5o1xuTXm10m9g94zQKoz5fr/d20vT59qCGe5IM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790083212; c=relaxed/simple; bh=76YuJDk/ToPumJbJj0kPrNX6C79HKPGffU2gQ88Qo8c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C4geit9MfgV7Ep1C/yGA3GvlrbQyqguB0v1ECUqYGrAW9uXjSEPrJfjRs7yLa5HSUszFupqf4+vGRadNlA9LSUMB846d19yWb3D6NWxlJTH4ebU5mTP8OLDEsSzPsCH+V0Q+j78xLSDmf4GUykCg6NeB3+P9qBzu4BsmhsQtmEg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=lex.la; spf=pass smtp.mailfrom=lex.la; dkim=pass (2048-bit key) header.d=lex.la header.i=@lex.la header.b=bLPsGv0m; arc=none smtp.client-ip=74.125.225.141 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=lex.la Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lex.la Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lex.la header.i=@lex.la header.b="bLPsGv0m" Received: by mail-wm2-f13.google.com with SMTP id 5b1f17b1804b1-49e71cdb22bso31079135e9.2 for ; Tue, 22 Sep 2026 06:20:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lex.la; s=google; t=1790083206; x=1790688006; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=/r9/s40OVqaWQoJJX5HKzXk1f8k5fiwKzjrgvKjOXIM=; b=bLPsGv0m8/GRIIE5SaVs2tHKyuAFngSSrqiv/uHUzI7w2LIix900J1zEmsJgJcF7Zg bSRc126PidblmnfmsaIEzulQciwpCdd8Y6NwDQXR60MYAwyanROxJYvCKbtMG3CMjlti wR3eFbjy5O8X5MYo/oYq8y1/35Tb057tyNeThFYBme51HyiJsRe2A/A7OgXXjWYmE0sb XYz737W4+k0Z2gWV7T/EMrGJKQQH6ptuaZhJi8DnucHqyv48bItCXBFnfI6dpM2ZyvXd 25aLGja7t3t7ZutgFA5gO3K6Gaw6cj8nuPIonyotIW33/VL8jSjPXClatYxrkKML0k3L kepg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790083206; x=1790688006; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=/r9/s40OVqaWQoJJX5HKzXk1f8k5fiwKzjrgvKjOXIM=; b=levG839hKd8zKAheZ6K/ktSjY8rW2I/5RU+1nKyplSbxzGaupoDO0w3/mVf1JeDrgI G4iI4OToRGd8uXy4l2pEAYRoC5NF3dLMkt51fx4mqW/tCYccjG2n9+7fZV/tDSdn74l/ wFswb5wvvBIkeUghCTLL7ghxr1cKqpsB408vzNBuO6gIQFOIsww8kofHOwdkJyUErfT9 oCWk+/Ak3Mehdz9IfhcnSV354Eb0fcFfRsIFQxbqAZkfkJ3hkvxkZMPD2rPt6URaEWzf 3cYb2wkUDOLDg7d3y/+jnlNvlSnh5F39gDbKjSQDdhso5kj2/U+Xia5adL48He1ry4QP drbQ== X-Forwarded-Encrypted: i=1; AKwUvBxBL9BhxPsi6SAvVAlH7E9otau/stRFsjuvB+ggLa+fR+cWULOn48anVs3Wtl5R51+tTtKZGvphScAzafg=@vger.kernel.org X-Gm-Message-State: AFuF++kuux3cl5Ifk6pqqW/tR1FgRDnPnLljxC7H4V4FVVtFaODBx8Wf pPhDGWRIXan5tjsqv+6cOQVgoond3r0arcb0nSX7J5mejOsZhofCAmhHEKbwgZ+Xpi0= X-Gm-Gg: AYBFou2kFoLXQ+K3sR9LCDhVQz5MLTxPaDUTevyPICKgLm/InNMmr+ygkpJ+R4pQyNN u6Cp8xAlRs6nZC53SNk9q39BQRnFGGYSqwBmblbPapK3TGfrFxXsLIz4Wl5BFLexSXi27eAIjxG QampyfaFAih/laWt7JrQLzg6F2SO37wJ3g6jArWbsGr76XGouT/FX815fil6tzlyckNSsJ6yvIR n/lr5yWMyjDUUZ8TxbHMEBxEz1rGJwI7CykmMFh9oRm9umUz1Tuf3l094/JExkV4VGOKmHQkUMy 1FBDiZ7g8lIyXLbNCu2E0elmRbVhb7QjxuOtVG6RkBQ8gKM2/mcX7qpe3d29+jVddXeYssgL9dz /EbAiLO0JNpv47Ma3IbnO4BHI24Usfe43tsS4Si9/YOn165i9GjbK8b4VAB0FahCI/gMnjqTUQo qnAyYoxcq8NFiJCH5d8m23HfQsTqMBsXvCJBHniqbrCbHJD1hyAw== X-Received: by 2002:a05:6000:2c06:b0:486:f767:8be0 with SMTP id ffacd0b85a97d-4871e216279mr21356887f8f.12.1790083205807; Tue, 22 Sep 2026 06:20:05 -0700 (PDT) Received: from remote-01 ([84.17.55.230]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-488627929a4sm4085220f8f.35.2026.09.22.06.20.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2026 06:20:05 -0700 (PDT) From: Aleksei Sviridkin To: netdev@vger.kernel.org Cc: andrew@lunn.ch, andrew+netdev@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, olteanv@gmail.com, Thangaraj.S@microchip.com, UNGLinuxDriver@microchip.com, steve.glendinning@shawell.net, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Aleksei Sviridkin Subject: [PATCH net v10 3/4] net: phy: take the interrupt back from the bus on detach Date: Tue, 22 Sep 2026 16:19:54 +0300 Message-ID: <20260922131955.4175785-4-f@lex.la> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260922131955.4175785-1-f@lex.la> References: <20260922131955.4175785-1-f@lex.la> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A PHY whose own driver is a module on a filesystem that is not mounted when the MAC probes gets the generic driver first. phy_probe() replaces phydev->irq with PHY_POLL because that driver has no interrupt support, nothing puts it back, and the PHY polls for the rest of the uptime once its real driver takes over. That is where an MT7981B board here stands, with an Airoha EN8811H behind an MT7531 port and its driver on the root filesystem: the devicetree gives the PHY interrupt 15, and once the real driver has taken over the field reads -1. Take the number back in phy_detach(), from mdiobus->irq[], which is where phy_device_create() seeded phydev->irq from and where the bus that described the interrupt still holds it. Only under is_genphy_driven, since that is the substitution being undone: elsewhere the field belongs to whoever wrote it, a MAC installing PHY_MAC_INTERRUPT writes phydev->irq alone, and a phy_request_interrupt() that failed leaves PHY_POLL there while the bus table still holds the number that could not be requested. Do it before device_release_driver() rather than after. That call returns with the mdio device bindable and the device lock dropped, so from then on a phy_probe() on another CPU is the other writer of this field. Until it runs the generic driver is still bound and the driver core turns a probe away with -EBUSY. That is ordering, not exclusion: nothing on this side holds the device lock. Fixes: 00db8189d984 ("This patch adds a PHY Abstraction Layer to the Linux = Kernel, enabling ethernet drivers to remain as ignorant as is reasonable of= the connected PHY's design and operation details.") Assisted-by: LLM Signed-off-by: Aleksei Sviridkin --- Notes: Found and measured on an MT7981B board with an MT7531 switch and an Air= oha EN8811H behind lan4, whose interrupt the devicetree describes and whose driver is a module. =20 The one condition arranged for the run is that the PHY driver module lo= ads after the root filesystem rather than from the early boot list this distribution normally puts it in. The distribution's own late-PHY handl= ing was also removed, that being the one patch which could have changed the outcome; upstream has nothing like it. The kernel is still a distributi= on one and its remaining patches to phylink and phy_device do run on these paths - none of them writes phydev->irq. =20 DSA then sets the port up at 1.87 s, the generic driver is bound by han= d, phy_probe() replaces the interrupt with PHY_POLL, and phylink rejects 2500base-x against it: =20 lan4 (uninitialized): validation of 2500base-x ... failed: -EINVAL lan4 (uninitialized): failed to connect to PHY: -EINVAL =20 The real driver arrives between 13.4 and 13.6 s depending on the boot, = and binds. phydev->irq then reads -1 without this patch and 15 with it, 15 being what the devicetree gave that PHY. The three switch ports alongsi= de read 79, 80 and 81 in both runs, so the reading distinguishes rather th= an printing one answer. The field has no sysfs attribute of its own, so it= was read with a debug-only module parameter that walks the MDIO bus and pri= nts it. =20 The reading predates the is_genphy_driven guard the store now sits unde= r, which should not be implied away. On the measured path the flag is set: phylink_connect_phy() calls phy_detach() from its own failure check, and the three writes of that flag are all in phy_device.c, none of them bet= ween the hand-bind and that call. So the guard passes and the store is the o= ne the reading came from. Its other side, a detach with a real driver boun= d, was not measured. drivers/net/phy/phy_device.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 94b2e85e00a3..a9c71a286118 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1965,6 +1965,8 @@ void phy_detach(struct phy_device *phydev) * real driver could be loaded */ if (phydev->is_genphy_driven) { + /* The release below lets phy_probe() write this field. */ + phydev->irq =3D phydev->mdio.bus->irq[phydev->mdio.addr]; device_release_driver(&phydev->mdio.dev); phydev->is_genphy_driven =3D 0; } --=20 2.53.0 From nobody Thu Sep 24 15:11:48 2026 Received: from mail-wm2-f13.google.com (mail-wm2-f13.google.com [74.125.225.141]) (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 E61DF566C4F for ; Tue, 22 Sep 2026 13:20:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.225.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790083212; cv=none; b=lP+tBXadn3N75bSK23AlioA/BdROFjzeqd/RXlmqnOfHVpQqoRqtTlcAU6BUVq5pwVC4QGVQd+sNoA37AHZz8nTcKEIaz6Sff5aqzL2SNL5oYGsyJf66fW+yI8ZoejetJKIki2X5Xd0th3dGYuMCwfR4TapNdQmHqCilrcp0xXg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790083212; c=relaxed/simple; bh=cjPhgMl06Gz4v8vlPzDnw8UWAHAvj1+3h2RWkeYhBNU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Dr2iJ0lHdB+edPKFQhmREozPKeWOqRFF/RJQsOOnIG5bgQZXI9bc9eW6a+e/uxTKFUMOiXywtmr7bPabILrK6JscKEby15JlPuU8m95Z6n1Y3fePIb7IOPdblrd1LhERt/LSTnvbGE/oSnH3icm9WXlYg9E81wVrgmNPxtc9j7Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=lex.la; spf=pass smtp.mailfrom=lex.la; dkim=pass (2048-bit key) header.d=lex.la header.i=@lex.la header.b=lQZM1P8z; arc=none smtp.client-ip=74.125.225.141 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=lex.la Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lex.la Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lex.la header.i=@lex.la header.b="lQZM1P8z" Received: by mail-wm2-f13.google.com with SMTP id 5b1f17b1804b1-49e71cdb22bso31079565e9.2 for ; Tue, 22 Sep 2026 06:20:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lex.la; s=google; t=1790083207; x=1790688007; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=S2+N1IorirZjTQOoiJkqviwvBkdqoi6Ht3FnwQDKUlk=; b=lQZM1P8zL9NkQ3eDkCXkNCLyr7zr8b7b5lA5BG9jnBAckSezhgtQ+oHsLk599TbMqv R6KkTviMw2LC+DHOchlh/DbvhyNgF0fHiiKComW6+DwPJiHnA20t5SkmsxxDh/SIQQZW qauI0UGxe53kR7TvHnR1icEPj2nB7ufspzhfnFomP6BwTMEZISPPNerWU065Lw3Qd8bE a06R3zSxwr+I8nPISfp+ThhZXU7hB24dJp6q6WK1Mq4EOHlRHIEalwUbw+u7qMwBuaOq D7fyGYv37PqeRyWehrSulswsBol7IpLSznZZ2KX34gkKKIP4+sWV2sYKLCncsO63/rG9 Fn4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790083207; x=1790688007; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=S2+N1IorirZjTQOoiJkqviwvBkdqoi6Ht3FnwQDKUlk=; b=CgR91wgd1ryh/lE3m6zd92OqRdnlh9+R+Vn4ondowvckjg9jJ100RBy1JRX9o6hc72 +gS0hkGnqdGfNXF8yv1DGQ4tR/8psovu0XAoopXhzxWZ7Z1B6z/CrhgkvJVYKKuLX3GC P6aaaQkzwMiEZ5GZcj3HyS4hFLuKfEsJNrm6dQUBot86GmyVP02CDDmjRJYYs/wIFG2u FtDcxJdg1+YnL3fFMG1jKVmA59TO2bXxxSjwJLJo0wovkK09W/N3e0fG/ko/QHDwWUwI ZEMITGgCfkAGDEjSJs6EB/d2L0BAwy2R8sAJ9fhQx6zyK+1dccVMOppglvEOzst40v8N rqoQ== X-Forwarded-Encrypted: i=1; AKwUvBwB7MXaoL3esySQ8VDCpoNEgVjt9V3fenwYxBpS4nyUbGB+LSfEO8CSa5n8YR/XqdFsShOLuSdEBZTt+jA=@vger.kernel.org X-Gm-Message-State: AFuF++nACA7Mh+uS/72Pg/RZe6Tm4nGfYeNSknOSUkeOUcIBZEpKQpsX otxaFP+XJsho2KkpMHcUwfbX99ibVxxW1RjRIq0Zy75YlmRn3XuK0O0J1td2Ronl4Zg= X-Gm-Gg: AYBFou2h0H81KD88ay3MNyaxQRWXWzF7X46L5FdC90B0ME+2pGyXjYuZD8OgN00fZ31 x2IzSHh1lhr7qHfEi/klj/BdSTkBOmn4F3eJjxisLC3qEtPsvACLtDRz6Dioz+GaINdP0HNyPWd 0KW3sw/9EsmxuT+FepR3VFjqWK4dEEJ1TbwoSFYdJmzTXPBd0X5H5SU6IGgmp0luDS8kN8oFG49 01oodN/AmLsfaPaCGQXmVaRi6/VA8NJCzdwK0Dpcc1tcQ9/DW9Yyn9uOWtKhhoE+zIHNGNPziey O0QMqdeFBNN2TajvGJJAPzDXVp1EG/P6xnhVQXEoAgF4sSAJOvDoed9NWyfGxMrZ1Toj2GTnLEl CPDqW2D7M44CCRkd1MdKdJeVFilCzam+l+z40aixfaEfcHKrLn4b0nfaBQ6P+kmJmDejmV0THUR s6ftaACgoGuceSuk1DoCS9YuwEgHQFrC1HJKAFJQiSAewqvGE8110= X-Received: by 2002:a05:600c:35c9:b0:49f:bcce:13f5 with SMTP id 5b1f17b1804b1-49fc5736229mr230926025e9.24.1790083207537; Tue, 22 Sep 2026 06:20:07 -0700 (PDT) Received: from remote-01 ([84.17.55.230]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-488627929a4sm4085220f8f.35.2026.09.22.06.20.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2026 06:20:06 -0700 (PDT) From: Aleksei Sviridkin To: netdev@vger.kernel.org Cc: andrew@lunn.ch, andrew+netdev@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, olteanv@gmail.com, Thangaraj.S@microchip.com, UNGLinuxDriver@microchip.com, steve.glendinning@shawell.net, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Aleksei Sviridkin Subject: [PATCH net v10 4/4] net: phy: restore the interrupt when the generic bind cycle fails Date: Tue, 22 Sep 2026 16:19:55 +0300 Message-ID: <20260922131955.4175785-5-f@lex.la> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260922131955.4175785-1-f@lex.la> References: <20260922131955.4175785-1-f@lex.la> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" phy_attach_direct() binds the generic driver by hand, and the probe it calls is phy_probe(), which replaces phydev->irq with PHY_POLL before either of the points it can fail at. That failure unwinds on a label of its own, which does not go through phy_detach(), so the substitution outlives a bind cycle that never completed and a later attach finds a PHY that can only be polled. Found while placing the restore of the previous patch, as the other exit of the same bind cycle. Take the number back on that label as well, before it clears d->driver. That store is what reopens the device to the driver core: until it runs, the core turns a probe away with -EBUSY. That is ordering, not exclusion - this bind and its unwind run without the device lock device_bind_driver() asks its callers to hold. Fixes: 6d9f66ac7fec ("net: phy: Fix PHY module checks and NULL deref in phy= _attach_direct()") Assisted-by: LLM Signed-off-by: Aleksei Sviridkin --- Notes: Both points the hand-bind can fail at are reachable. phy_probe() reaches genphy_read_abilities() through genphy_driver's .get_features, and that returns the error from phy_read(phydev, MII_BMSR); device_bind_driver() returns whatever driver_sysfs_add() got, from either of its two sysfs_create_link() calls or from the coredump attribute. =20 A failed genphy bind leaves the device with no driver bound at all, so = the next driver to arrive binds directly and never goes through phy_detach(= ). That is why patch 3 cannot cover this path, and why the Fixes: tag here= is 6d9f66ac7fec rather than the one patch 3 carries. That commit did not introduce the lost number - the substitution is far older - it created = this second exit from the bind cycle, splitting the failure off the label th= at calls phy_detach(). Before it, patch 3 alone would have covered this, so that is where the backport range for this one starts. =20 Exercised on the board described in patch 3, with a debug-only module parameter that fails the hand-bound generic probe once for one MDIO address. The connect then ends in -EIO rather than the -EINVAL of the validation path, so the unwind takes the label this patch touches. phydev->irq afterwards reads -1 with patch 3 alone and 15 with this one. =20 One difference between the injector and a real failure, since it does n= ot affect what was measured but should not be implied away: a genuine error inside phy_probe() leaves through its out: label, which re-asserts the = PHY reset before returning, while the injector returns earlier than that. Neither path touches phydev->irq. drivers/net/phy/phy_device.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index a9c71a286118..06161a73fe3f 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1896,6 +1896,8 @@ int phy_attach_direct(struct net_device *dev, struct = phy_device *phydev, =20 error_module_put: module_put(d->driver->owner); + /* The NULL below lets phy_probe() write this field. */ + phydev->irq =3D bus->irq[phydev->mdio.addr]; phydev->is_genphy_driven =3D 0; d->driver =3D NULL; error_put_device: --=20 2.53.0