From: Mateusz Polchlopek <mateusz.polchlopek@intel.com>
To: Oleksij Rempel <o.rempel@pengutronix.de>,
Andrew Lunn <andrew@lunn.ch>,
Heiner Kallweit <hkallweit1@gmail.com>,
Russell King <linux@armlinux.org.uk>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: <kernel@pengutronix.de>, <linux-kernel@vger.kernel.org>,
<netdev@vger.kernel.org>
Subject: Re: [PATCH net-next v1 1/2] net: phy: Add support for driver-specific next update time
Date: Tue, 4 Feb 2025 12:50:36 +0100 [thread overview]
Message-ID: <0f42a6ef-9d7a-4dfa-909f-36578a027320@intel.com> (raw)
In-Reply-To: <20250204093239.2427263-2-o.rempel@pengutronix.de>
On 2/4/2025 10:32 AM, Oleksij Rempel wrote:
> Introduce the `phy_get_next_update_time` function to allow PHY drivers
> to dynamically determine the time (in milliseconds) 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>
> ---
> drivers/net/phy/phy.c | 28 ++++++++++++++++++++++++++--
> include/linux/phy.h | 13 +++++++++++++
> 2 files changed, 39 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
> index d0c1718e2b16..77ed7bfdf200 100644
> --- a/drivers/net/phy/phy.c
> +++ b/drivers/net/phy/phy.c
> @@ -1501,6 +1501,25 @@ void phy_free_interrupt(struct phy_device *phydev)
> }
> EXPORT_SYMBOL(phy_free_interrupt);
>
> +/**
> + * 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 polling
> + * event. If the driver does not implement the callback, a default value is used.
> + *
> + * Return: The time for the next polling event in milliseconds
> + */
> +static unsigned int phy_get_next_update_time(struct phy_device *phydev)
> +{
> + const unsigned int default_time = PHY_STATE_TIME;
Why you create this variable? It is used only in return, so I would
rather just simplify by doing:
return PHY_STATE_TIME;
> +
> + if (phydev->drv && phydev->drv->get_next_update_time)
> + return phydev->drv->get_next_update_time(phydev);
> +
> + return default_time;
> +}
> +
> enum phy_state_work {
> PHY_STATE_WORK_NONE,
> PHY_STATE_WORK_ANEG,
> @@ -1579,8 +1598,13 @@ static enum phy_state_work _phy_state_machine(struct phy_device *phydev)
> * 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_STATE_TIME);
> + if (phy_polling_mode(phydev) && phy_is_started(phydev)) {
> + unsigned int next_update_time =
> + phy_get_next_update_time(phydev);
> +
> + phy_queue_state_machine(phydev,
> + msecs_to_jiffies(next_update_time));
> + }
>
> return state_work;
> }
> diff --git a/include/linux/phy.h b/include/linux/phy.h
> index 19f076a71f94..d5cf979f4a6b 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 which has the LED
> + *
> + * Callback to determine the time (in milliseconds) 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 milliseconds 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)
next prev parent reply other threads:[~2025-02-04 11:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-04 9:32 [PATCH net-next v1 0/2] Use PHYlib for reset randomization and adjustable polling Oleksij Rempel
2025-02-04 9:32 ` [PATCH net-next v1 1/2] net: phy: Add support for driver-specific next update time Oleksij Rempel
2025-02-04 11:50 ` Mateusz Polchlopek [this message]
2025-02-04 9:32 ` [PATCH net-next v1 2/2] net: phy: dp83tg720: Add randomized polling intervals for unstable link detection Oleksij Rempel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0f42a6ef-9d7a-4dfa-909f-36578a027320@intel.com \
--to=mateusz.polchlopek@intel.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hkallweit1@gmail.com \
--cc=kernel@pengutronix.de \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=o.rempel@pengutronix.de \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®