From nobody Mon Dec 15 21:29:44 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 5A6F91C174E for ; Mon, 10 Feb 2025 08:24:16 +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=1739175858; cv=none; b=cLloSRhMc6borwS9118FmBwp0SyG1fgx+/yauYp5RVqr5Xj3FZohKIHF7oZppdVnmSuCf9JLTcZ9Gq/SJsjZ0E7ZNJLDDRdIf9aDWiqVHWt8NtPRPwlk3SUS3DLMNEPjnvzQsjoaKo/GqgCR9rBo/YdaKgxLrPj+XQPLlD1nREI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739175858; c=relaxed/simple; bh=8uZ3Bd2+9Y2lL4JbcJ3q0uxnHCxYlNxJIRDfPT99dOI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gv1posZeTXTe8JvcW54EvIuQZ/OLQVLJlrxcakC6nt4OA9lRP7OEkBXM314dabO8I4vi0fPQCPg8qdB6bzfRoxIQhU+Z44BbXlo8ygY1UTK9Vc2+qXGNWGz7eErAOX4I1ik38i0AoMizcc82u6m+MgW7gW6W8nt4x/loAJUKpZk= 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 1thP5E-0001zK-SJ; Mon, 10 Feb 2025 09:24:00 +0100 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 1thP5D-000DBl-15; Mon, 10 Feb 2025 09:23:59 +0100 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1thP5D-000qEb-0s; Mon, 10 Feb 2025 09:23:59 +0100 From: Oleksij Rempel To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next v4 1/2] net: phy: Add support for driver-specific next update time Date: Mon, 10 Feb 2025 09:23:57 +0100 Message-Id: <20250210082358.200751-2-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250210082358.200751-1-o.rempel@pengutronix.de> References: <20250210082358.200751-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" Introduce the `phy_get_next_update_time` function to allow PHY drivers to dynamically determine the time (in jiffies) until the next state update event. This enables more flexible and adaptive polling intervals based on the link state or other conditions. Signed-off-by: Oleksij Rempel Reviewed-by: Andrew Lunn --- changes v4: - fix comment width - fix copy paste artifact in the comment changes v3: - use jiffies instead of milliseconds changes v2: - phy_get_next_update_time: remove useless variable --- drivers/net/phy/phy.c | 21 ++++++++++++++++++++- include/linux/phy.h | 13 +++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index d0c1718e2b16..347ad1b64497 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -1501,6 +1501,24 @@ void phy_free_interrupt(struct phy_device *phydev) } EXPORT_SYMBOL(phy_free_interrupt); =20 +/** + * phy_get_next_update_time - Determine the next PHY update time + * @phydev: Pointer to the phy_device structure + * + * This function queries the PHY driver to get the time for the next polli= ng + * event. If the driver does not implement the callback, a default value is + * used. + * + * Return: The time for the next polling event in jiffies + */ +static unsigned int phy_get_next_update_time(struct phy_device *phydev) +{ + if (phydev->drv && phydev->drv->get_next_update_time) + return phydev->drv->get_next_update_time(phydev); + + return PHY_STATE_TIME; +} + enum phy_state_work { PHY_STATE_WORK_NONE, PHY_STATE_WORK_ANEG, @@ -1580,7 +1598,8 @@ static enum phy_state_work _phy_state_machine(struct = phy_device *phydev) * called from phy_disconnect() synchronously. */ if (phy_polling_mode(phydev) && phy_is_started(phydev)) - phy_queue_state_machine(phydev, PHY_STATE_TIME); + phy_queue_state_machine(phydev, + phy_get_next_update_time(phydev)); =20 return state_work; } diff --git a/include/linux/phy.h b/include/linux/phy.h index 19f076a71f94..0493553ed60b 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1273,6 +1273,19 @@ struct phy_driver { */ int (*led_polarity_set)(struct phy_device *dev, int index, unsigned long modes); + + /** + * @get_next_update_time: Get the time until the next update event + * @dev: PHY device + * + * Callback to determine the time (in jiffies) until the next + * update event for the PHY state machine. Allows PHY drivers to + * dynamically adjust polling intervals based on link state or other + * conditions. + * + * Returns the time in jiffies until the next update event. + */ + unsigned int (*get_next_update_time)(struct phy_device *dev); }; #define to_phy_driver(d) container_of_const(to_mdio_common_driver(d), \ struct phy_driver, mdiodrv) --=20 2.39.5