From nobody Tue Oct 7 13:25:03 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6B2B28DB49 for ; Wed, 9 Jul 2025 10:42:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752057753; cv=none; b=lL18zy3JrtdeaofK4bimMlYrU+v72tEoyG5VJ86gXRXMYE993oYDfaejbPhcuXFKuvsQrmc8+hJMCv9ERjnXKAu0YdDOtVQcIaGg2R4v/+wDn6ja6pDq1TTdMrJDc0fMzr27lb33KJuBEJ2K2qKSRleOb7EpxbkBd77b1ay6txA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752057753; c=relaxed/simple; bh=IyPWsI1Cj47xSOp5+E79wdgdEyYTtJq4mJUYWfGQ6lk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CpNSTnhybnudzoAxojRbVCXqr84T9JAnG8a28CTS07cRvqPN+tEXb5Hxj6mpbLMJIuie8lDoTn0xeCZV82QkTToA/yuxRXCNM3m0uSD3bcCCEuLy+oFwZGdeSHRrywz5bklvkPwmsoAJqhdn1pCZopoVDe51P8y/KJE+VOxff9E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1uZSFh-0004mq-8w; Wed, 09 Jul 2025 12:42:13 +0200 Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uZSFf-007ZJj-2T; Wed, 09 Jul 2025 12:42:11 +0200 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1uZSFf-00FyRU-2D; Wed, 09 Jul 2025 12:42:11 +0200 From: Oleksij Rempel To: Andrew Lunn , Heiner Kallweit , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, Russell King , netdev@vger.kernel.org, Andre Edich , Lukas Wunner Subject: [PATCH net v2 1/3] net: phy: enable polling when driver implements get_next_update_time Date: Wed, 9 Jul 2025 12:42:08 +0200 Message-Id: <20250709104210.3807203-2-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250709104210.3807203-1-o.rempel@pengutronix.de> References: <20250709104210.3807203-1-o.rempel@pengutronix.de> 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 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Currently, phy_polling_mode() enables polling only if: - the PHY is in interrupt-less mode, or - the driver provides an update_stats() callback. This excludes drivers that implement get_next_update_time() to support adaptive polling but do not provide update_stats(). As a result, the state machine timer will not run, and the get_next_update_time() callback is never used. This patch extends the polling condition to include drivers that implement get_next_update_time(). This change is required to support adaptive polling in the SMSC LAN9512/LAN8700 PHY family, which cannot reliably use interrupts. No in-tree drivers rely on this mechanism yet, so existing behavior is unchanged. If any out-of-tree driver incorrectly implements get_next_update_time(), enabling polling is still the correct behavior. Fixes: 8bf47e4d7b87 ("net: phy: Add support for driver-specific next update= time") Signed-off-by: Oleksij Rempel Reviewed-by: Andrew Lunn --- changes v2: - update commit message --- include/linux/phy.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/phy.h b/include/linux/phy.h index 543a94751a6b..3d4e5c41235e 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1632,7 +1632,7 @@ static inline bool phy_polling_mode(struct phy_device= *phydev) if (phydev->drv->flags & PHY_POLL_CABLE_TEST) return true; =20 - if (phydev->drv->update_stats) + if (phydev->drv->update_stats || phydev->drv->get_next_update_time) return true; =20 return phydev->irq =3D=3D PHY_POLL; --=20 2.39.5 From nobody Tue Oct 7 13:25:03 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6B9228DB4C for ; Wed, 9 Jul 2025 10:42:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752057752; cv=none; b=R6OLLHfdPoHEgGcTK9UGQrnDHuFOhFtSXuz4J1IdHXbEpqsebE0Cv5SBxBw85KRxvYuXsCUH6wEq3nx2z0jsgr1lapih7LKrT6mtXiDPJLuyzTUNd3QRJqa1WWHWf+ntUNq7Q4pr8jjaCF5R8Gk4lDH3t5oEqgOWIKaf/1cmIRM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752057752; c=relaxed/simple; bh=Ymcc70jHfquLfmlPG/hjhuCZuqkpzSAmOGGo08LoEl4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IP3SB4i2qstsEd9+qmVF523MQtHhyxop7GbFjsTzU1xyKlWa+WBChS+icXNct3FsseDNN50Z5eVqU/YXGDxC2fvg47AogY1cI42+Ub9n6uo/avUgN5D9MP2UEvWIOyVjJHJ/Z82/X6XYoBIan7t/GBtJoaeM6KJ2QjKbzUCrz0Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1uZSFh-0004mr-8w; Wed, 09 Jul 2025 12:42:13 +0200 Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uZSFf-007ZJk-2X; Wed, 09 Jul 2025 12:42:11 +0200 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1uZSFf-00FyRe-2H; Wed, 09 Jul 2025 12:42:11 +0200 From: Oleksij Rempel To: Andrew Lunn , Heiner Kallweit , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, Russell King , netdev@vger.kernel.org, Andre Edich , Lukas Wunner Subject: [PATCH net v2 2/3] net: phy: allow drivers to disable polling via get_next_update_time() Date: Wed, 9 Jul 2025 12:42:09 +0200 Message-Id: <20250709104210.3807203-3-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250709104210.3807203-1-o.rempel@pengutronix.de> References: <20250709104210.3807203-1-o.rempel@pengutronix.de> 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 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Some PHY drivers can reliably report link-down events via IRQs, but may fail to generate reliable link-up IRQs. To support such cases, polling is often needed - but only selectively. Extend get_next_update_time() so drivers can return PHY_STATE_IRQ to indicate that polling is not needed and IRQs are sufficient. This allows finer control over PHY state machine behavior. Introduce PHY_STATE_IRQ (UINT_MAX) as a sentinel value, and move PHY_STATE_TIME to phy.h to allow consistent use across the codebase. This change complements the previous patch enabling polling when get_next_update_time() is present. Signed-off-by: Oleksij Rempel --- changes v2: - this patch is added --- drivers/net/phy/phy.c | 18 +++++++++++------- include/linux/phy.h | 10 +++++++++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 13df28445f02..faf9a48d3b6f 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -39,8 +39,6 @@ #include "phylib-internal.h" #include "phy-caps.h" =20 -#define PHY_STATE_TIME HZ - #define PHY_STATE_STR(_state) \ case PHY_##_state: \ return __stringify(_state); \ @@ -1575,16 +1573,22 @@ static enum phy_state_work _phy_state_machine(struc= t phy_device *phydev) phy_process_state_change(phydev, old_state); =20 /* Only re-schedule a PHY state machine change if we are polling the - * PHY, if PHY_MAC_INTERRUPT is set, then we will be moving - * between states from phy_mac_interrupt(). + * PHY. If PHY_MAC_INTERRUPT is set or get_next_update_time() returns + * PHY_STATE_IRQ, then we rely on interrupts for state changes. * * In state PHY_HALTED the PHY gets suspended, so rescheduling the * state machine would be pointless and possibly error prone when * called from phy_disconnect() synchronously. */ - if (phy_polling_mode(phydev) && phy_is_started(phydev)) - phy_queue_state_machine(phydev, - phy_get_next_update_time(phydev)); + if (phy_polling_mode(phydev) && phy_is_started(phydev)) { + unsigned int next_time =3D phy_get_next_update_time(phydev); + + /* Drivers returning PHY_STATE_IRQ opt out of polling. + * Use IRQ-only mode by not re-queuing the state machine. + */ + if (next_time !=3D PHY_STATE_IRQ) + phy_queue_state_machine(phydev, next_time); + } =20 return state_work; } diff --git a/include/linux/phy.h b/include/linux/phy.h index 3d4e5c41235e..d92258e3ac1a 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -66,6 +66,10 @@ extern const int phy_basic_ports_array[3]; #define PHY_ALWAYS_CALL_SUSPEND 0x00000008 #define MDIO_DEVICE_IS_PHY 0x80000000 =20 +#define PHY_STATE_TIME HZ +/* disable polling, rely on IRQs */ +#define PHY_STATE_IRQ UINT_MAX + /** * enum phy_interface_t - Interface Mode definitions * @@ -1257,7 +1261,11 @@ struct phy_driver { * dynamically adjust polling intervals based on link state or other * conditions. * - * Returns the time in jiffies until the next update event. + * Returning PHY_STATE_IRQ disables polling and indicates that the + * driver relies solely on IRQs for link state changes. + * + * Returns the time in jiffies until the next update event, or + * PHY_STATE_IRQ to disable polling. */ unsigned int (*get_next_update_time)(struct phy_device *dev); }; --=20 2.39.5 From nobody Tue Oct 7 13:25:03 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 54F2C28ECE3 for ; Wed, 9 Jul 2025 10:42:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752057754; cv=none; b=Tw3m7IG6ypIRA49lOrfSdKqzYTuLeeBPkKKZD80LYuB/J5lyvz2Nt4mbCKEAYTdt60UXzJ7hcYE5QjdhebZyasxhitLe0u3gSdbha5Rf28KIaUmQqe2IiDP/uHeYvK+1JfgdOIWKtXKc2XpgV5Kv/8Z3j2TG+SgGAM/cgNx41Qo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752057754; c=relaxed/simple; bh=KBBCA4ST0AIfZMPfEBu51s+rw1J0kOK14uQSN909J8M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YDGCLsnXPMwiEiBZ5T5iRbPjeiuUPOGtqP9a8j8yCxZpU6eV1POTRAU0ebaeqXZyo2rU88wJHZ8C/Ua++pSAg42KiEoo2SdEZVNGPvUEAIKLQc79tVPXKlIxWPBKOJJsiPyRLXPf7EGjvO1YeQpgEbcvgv7fMy0b8+0w87IplrI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1uZSFh-0004ms-8r; Wed, 09 Jul 2025 12:42:13 +0200 Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uZSFf-007ZJl-2d; Wed, 09 Jul 2025 12:42:11 +0200 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1uZSFf-00FyRn-2M; Wed, 09 Jul 2025 12:42:11 +0200 From: Oleksij Rempel To: Andrew Lunn , Heiner Kallweit , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Oleksij Rempel , Lukas Wunner , kernel@pengutronix.de, linux-kernel@vger.kernel.org, Russell King , netdev@vger.kernel.org, Andre Edich Subject: [PATCH net v2 3/3] net: phy: smsc: recover missed link-up IRQs on LAN8700 with adaptive polling Date: Wed, 9 Jul 2025 12:42:10 +0200 Message-Id: <20250709104210.3807203-4-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250709104210.3807203-1-o.rempel@pengutronix.de> References: <20250709104210.3807203-1-o.rempel@pengutronix.de> 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 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Fix unreliable link detection on the LAN8700 PHY (integrated in LAN9512 and related USB adapters) when configured for 10 Mbit/s half- or full-duplex with autonegotiation disabled, and connected to a link partner that still advertises autonegotiation. In this scenario, the PHY may emit several link-down interrupts during negotiation but fail to raise a final link-up interrupt. As a result, phylib never observes the transition and the kernel keeps the network interface down, even though the link is actually up. To handle this, add a get_next_update_time() callback that performs 1 Hz polling for up to 30 seconds after the last interrupt, but only while the PHY is in this problematic configuration and the link is still down. This ensures link-up detection without unnecessary long delays or full-time polling. After 30 seconds with no further interrupt, the driver switches back to IRQ-only mode. In all other configurations, IRQ-only mode is used immediately. This patch depends on: - commit 8bf47e4d7b87 ("net: phy: Add support for driver-specific next update time") - a prior patch in this series: net: phy: enable polling when driver implements get_next_update_time net: phy: allow drivers to disable polling via get_next_update_time() Fixes: 1ce8b37241ed ("usbnet: smsc95xx: Forward PHY interrupts to PHY drive= r to avoid polling") Signed-off-by: Oleksij Rempel Cc: Lukas Wunner --- changes v2: - Switch to hybrid approach: 1 Hz polling for 30 seconds after last IRQ instead of relaxed 30s polling while link is up - Only enable polling in problematic 10M autoneg-off mode while link is down - Return PHY_STATE_IRQ in all other configurations - Updated commit message and comments to reflect new logic --- drivers/net/phy/smsc.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/drivers/net/phy/smsc.c b/drivers/net/phy/smsc.c index b6489da5cfcd..88eb15700dbd 100644 --- a/drivers/net/phy/smsc.c +++ b/drivers/net/phy/smsc.c @@ -39,6 +39,9 @@ /* interval between phylib state machine runs in ms */ #define PHY_STATE_MACH_MS 1000 =20 +/* max retry window for missed link-up */ +#define SMSC_IRQ_MAX_POLLING_TIME secs_to_jiffies(30) + struct smsc_hw_stat { const char *string; u8 reg; @@ -54,6 +57,7 @@ struct smsc_phy_priv { unsigned int edpd_mode_set_by_user:1; unsigned int edpd_max_wait_ms; bool wol_arp; + unsigned long last_irq; }; =20 static int smsc_phy_ack_interrupt(struct phy_device *phydev) @@ -100,6 +104,7 @@ static int smsc_phy_config_edpd(struct phy_device *phyd= ev) =20 irqreturn_t smsc_phy_handle_interrupt(struct phy_device *phydev) { + struct smsc_phy_priv *priv =3D phydev->priv; int irq_status; =20 irq_status =3D phy_read(phydev, MII_LAN83C185_ISF); @@ -113,6 +118,8 @@ irqreturn_t smsc_phy_handle_interrupt(struct phy_device= *phydev) if (!(irq_status & MII_LAN83C185_ISF_INT_PHYLIB_EVENTS)) return IRQ_NONE; =20 + WRITE_ONCE(priv->last_irq, jiffies); + phy_trigger_machine(phydev); =20 return IRQ_HANDLED; @@ -684,6 +691,38 @@ int smsc_phy_probe(struct phy_device *phydev) } EXPORT_SYMBOL_GPL(smsc_phy_probe); =20 +static unsigned int smsc_phy_get_next_update(struct phy_device *phydev) +{ + struct smsc_phy_priv *priv =3D phydev->priv; + + /* If interrupts are disabled, fall back to default polling */ + if (phydev->irq =3D=3D PHY_POLL) + return PHY_STATE_TIME; + + /* + * LAN8700 may miss the final link-up IRQ when forced to 10 Mbps + * (half/full duplex) and connected to an autonegotiating partner. + * + * To recover, poll at 1 Hz for up to 30 seconds after the last + * interrupt - but only in this specific configuration and while + * the link is still down. + * + * This keeps link-up latency low in common cases while reliably + * detecting rare transitions. Outside of this mode, rely on IRQs. + */ + if (phydev->autoneg =3D=3D AUTONEG_DISABLE && phydev->speed =3D=3D SPEED_= 10 && + !phydev->link) { + unsigned long last_irq =3D READ_ONCE(priv->last_irq); + + if (!time_is_before_jiffies(last_irq + + SMSC_IRQ_MAX_POLLING_TIME)) + return PHY_STATE_TIME; + } + + /* switching to IRQ without polling */ + return PHY_STATE_IRQ; +} + static struct phy_driver smsc_phy_driver[] =3D { { .phy_id =3D 0x0007c0a0, /* OUI=3D0x00800f, Model#=3D0x0a */ @@ -749,6 +788,7 @@ static struct phy_driver smsc_phy_driver[] =3D { /* IRQ related */ .config_intr =3D smsc_phy_config_intr, .handle_interrupt =3D smsc_phy_handle_interrupt, + .get_next_update_time =3D smsc_phy_get_next_update, =20 /* Statistics */ .get_sset_count =3D smsc_get_sset_count, --=20 2.39.5