Skip to content

Commit 8bf47e4

Browse files
oleremkuba-moo
authored andcommitted
net: phy: Add support for driver-specific next update time
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 <o.rempel@pengutronix.de> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Link: https://patch.msgid.link/20250210082358.200751-2-o.rempel@pengutronix.de Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 1273919 commit 8bf47e4

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

drivers/net/phy/phy.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,24 @@ void phy_free_interrupt(struct phy_device *phydev)
15011501
}
15021502
EXPORT_SYMBOL(phy_free_interrupt);
15031503

1504+
/**
1505+
* phy_get_next_update_time - Determine the next PHY update time
1506+
* @phydev: Pointer to the phy_device structure
1507+
*
1508+
* This function queries the PHY driver to get the time for the next polling
1509+
* event. If the driver does not implement the callback, a default value is
1510+
* used.
1511+
*
1512+
* Return: The time for the next polling event in jiffies
1513+
*/
1514+
static unsigned int phy_get_next_update_time(struct phy_device *phydev)
1515+
{
1516+
if (phydev->drv && phydev->drv->get_next_update_time)
1517+
return phydev->drv->get_next_update_time(phydev);
1518+
1519+
return PHY_STATE_TIME;
1520+
}
1521+
15041522
enum phy_state_work {
15051523
PHY_STATE_WORK_NONE,
15061524
PHY_STATE_WORK_ANEG,
@@ -1580,7 +1598,8 @@ static enum phy_state_work _phy_state_machine(struct phy_device *phydev)
15801598
* called from phy_disconnect() synchronously.
15811599
*/
15821600
if (phy_polling_mode(phydev) && phy_is_started(phydev))
1583-
phy_queue_state_machine(phydev, PHY_STATE_TIME);
1601+
phy_queue_state_machine(phydev,
1602+
phy_get_next_update_time(phydev));
15841603

15851604
return state_work;
15861605
}

include/linux/phy.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,19 @@ struct phy_driver {
12701270
*/
12711271
int (*led_polarity_set)(struct phy_device *dev, int index,
12721272
unsigned long modes);
1273+
1274+
/**
1275+
* @get_next_update_time: Get the time until the next update event
1276+
* @dev: PHY device
1277+
*
1278+
* Callback to determine the time (in jiffies) until the next
1279+
* update event for the PHY state machine. Allows PHY drivers to
1280+
* dynamically adjust polling intervals based on link state or other
1281+
* conditions.
1282+
*
1283+
* Returns the time in jiffies until the next update event.
1284+
*/
1285+
unsigned int (*get_next_update_time)(struct phy_device *dev);
12731286
};
12741287
#define to_phy_driver(d) container_of_const(to_mdio_common_driver(d), \
12751288
struct phy_driver, mdiodrv)

0 commit comments

Comments
 (0)