diff mbox series

[net-next,v2,1/7] net: phy: add PHY_F_RXC_ALWAYS_ON to PHY dev flags

Message ID 20240130-rxc_bugfix-v2-1-5e6c3168e5f0@bootlin.com (mailing list archive)
State New, archived
Headers show
Series Fix missing PHY-to-MAC RX clock | expand

Commit Message

Romain Gantois Jan. 30, 2024, 9:28 a.m. UTC
From: Russell King <linux@armlinux.org.uk>

Some MAC controllers (e.g. stmmac) require their connected PHY to
continuously provide a receive clock signal. This can cause issues in two
cases:

  1. The clock signal hasn't been started yet by the time the MAC driver
     initializes its hardware. This can make the initialization fail, as in
      the case of the rzn1 GMAC1 driver.
  2. The clock signal is cut during a power saving event. By the time the
     MAC is brought back up, the clock signal is still not active since
     phylink_start hasn't been called yet. This brings us back to case 1.

If a PHY driver reads this flag, it should ensure that the receive clock
signal is started as soon as possible, and that it isn't brought down when
the PHY goes into suspend.

Signed-off-by: Russell King <linux@armlinux.org.uk>
[rgantois: commit log]
Signed-off-by: Romain Gantois <romain.gantois@bootlin.com>
---
 drivers/net/phy/phylink.c | 10 +++++++++-
 include/linux/phy.h       |  1 +
 include/linux/phylink.h   |  4 ++++
 3 files changed, 14 insertions(+), 1 deletion(-)

Comments

Russell King (Oracle) Jan. 30, 2024, 9:57 a.m. UTC | #1
On Tue, Jan 30, 2024 at 10:28:36AM +0100, Romain Gantois wrote:
> From: Russell King <linux@armlinux.org.uk>
> 
> Some MAC controllers (e.g. stmmac) require their connected PHY to
> continuously provide a receive clock signal. This can cause issues in two
> cases:
> 
>   1. The clock signal hasn't been started yet by the time the MAC driver
>      initializes its hardware. This can make the initialization fail, as in
>       the case of the rzn1 GMAC1 driver.
>   2. The clock signal is cut during a power saving event. By the time the
>      MAC is brought back up, the clock signal is still not active since
>      phylink_start hasn't been called yet. This brings us back to case 1.
> 
> If a PHY driver reads this flag, it should ensure that the receive clock
> signal is started as soon as possible, and that it isn't brought down when
> the PHY goes into suspend.
> 
> Signed-off-by: Russell King <linux@armlinux.org.uk>
> [rgantois: commit log]
> Signed-off-by: Romain Gantois <romain.gantois@bootlin.com>

You seem to have combined two of my patches into this one, which touch
two different bits of code. I'm fine with that, but please adjust the
subject line to match the _majority_ of the code that is being touched,
which is phylink (having the prefix net: phylink:), rather than phylib
(having the prefix net: phy:).

Thanks.
Andrew Lunn Jan. 30, 2024, 1:55 p.m. UTC | #2
> @@ -768,6 +768,7 @@ struct phy_device {
>  
>  /* Generic phy_device::dev_flags */
>  #define PHY_F_NO_IRQ		0x80000000
> +#define PHY_F_RXC_ALWAYS_ON	BIT(30)

It is a bit odd mixing 0x numbers and BIT() macros for the same class
of thing. I would use 0x40000000, or convert PHY_F_NO_IRQ to BIT(31)
  
	Andrew
Russell King (Oracle) Jan. 30, 2024, 2:02 p.m. UTC | #3
On Tue, Jan 30, 2024 at 02:55:50PM +0100, Andrew Lunn wrote:
> > @@ -768,6 +768,7 @@ struct phy_device {
> >  
> >  /* Generic phy_device::dev_flags */
> >  #define PHY_F_NO_IRQ		0x80000000
> > +#define PHY_F_RXC_ALWAYS_ON	BIT(30)
> 
> It is a bit odd mixing 0x numbers and BIT() macros for the same class
> of thing. I would use 0x40000000, or convert PHY_F_NO_IRQ to BIT(31)

If I used 0x40000000, there would be review comments suggesting the use
of BIT(). Can't win!
Andrew Lunn Jan. 31, 2024, 1:53 p.m. UTC | #4
On Tue, Jan 30, 2024 at 02:02:12PM +0000, Russell King (Oracle) wrote:
> On Tue, Jan 30, 2024 at 02:55:50PM +0100, Andrew Lunn wrote:
> > > @@ -768,6 +768,7 @@ struct phy_device {
> > >  
> > >  /* Generic phy_device::dev_flags */
> > >  #define PHY_F_NO_IRQ		0x80000000
> > > +#define PHY_F_RXC_ALWAYS_ON	BIT(30)
> > 
> > It is a bit odd mixing 0x numbers and BIT() macros for the same class
> > of thing. I would use 0x40000000, or convert PHY_F_NO_IRQ to BIT(31)
> 
> If I used 0x40000000, there would be review comments suggesting the use
> of BIT(). Can't win!

No, you cannot win, but at least it would be consistent :-)

    Andrew
diff mbox series

Patch

diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index ed0b4ccaa6a6..851049096488 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -1923,6 +1923,8 @@  static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy,
 static int phylink_attach_phy(struct phylink *pl, struct phy_device *phy,
 			      phy_interface_t interface)
 {
+	u32 flags = 0;
+
 	if (WARN_ON(pl->cfg_link_an_mode == MLO_AN_FIXED ||
 		    (pl->cfg_link_an_mode == MLO_AN_INBAND &&
 		     phy_interface_mode_is_8023z(interface) && !pl->sfp_bus)))
@@ -1931,7 +1933,10 @@  static int phylink_attach_phy(struct phylink *pl, struct phy_device *phy,
 	if (pl->phydev)
 		return -EBUSY;
 
-	return phy_attach_direct(pl->netdev, phy, 0, interface);
+	if (pl->config->mac_requires_rxc)
+		flags |= PHY_F_RXC_ALWAYS_ON;
+
+	return phy_attach_direct(pl->netdev, phy, flags, interface);
 }
 
 /**
@@ -2034,6 +2039,9 @@  int phylink_fwnode_phy_connect(struct phylink *pl,
 		pl->link_config.interface = pl->link_interface;
 	}
 
+	if (pl->config->mac_requires_rxc)
+		flags |= PHY_F_RXC_ALWAYS_ON;
+
 	ret = phy_attach_direct(pl->netdev, phy_dev, flags,
 				pl->link_interface);
 	phy_device_free(phy_dev);
diff --git a/include/linux/phy.h b/include/linux/phy.h
index c9994a59ca2e..3ef30f035bc0 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -768,6 +768,7 @@  struct phy_device {
 
 /* Generic phy_device::dev_flags */
 #define PHY_F_NO_IRQ		0x80000000
+#define PHY_F_RXC_ALWAYS_ON	BIT(30)
 
 static inline struct phy_device *to_phy_device(const struct device *dev)
 {
diff --git a/include/linux/phylink.h b/include/linux/phylink.h
index d589f89c612c..fcee99632964 100644
--- a/include/linux/phylink.h
+++ b/include/linux/phylink.h
@@ -138,6 +138,9 @@  enum phylink_op_type {
  * @poll_fixed_state: if true, starts link_poll,
  *		      if MAC link is at %MLO_AN_FIXED mode.
  * @mac_managed_pm: if true, indicate the MAC driver is responsible for PHY PM.
+ * @mac_requires_rxc: if true, the MAC always requires a receive clock from PHY.
+ *                    The PHY driver should start the clock signal as soon as
+ *                    possible and avoid stopping it during suspend events.
  * @ovr_an_inband: if true, override PCS to MLO_AN_INBAND
  * @get_fixed_state: callback to execute to determine the fixed link state,
  *		     if MAC link is at %MLO_AN_FIXED mode.
@@ -150,6 +153,7 @@  struct phylink_config {
 	enum phylink_op_type type;
 	bool poll_fixed_state;
 	bool mac_managed_pm;
+	bool mac_requires_rxc;
 	bool ovr_an_inband;
 	void (*get_fixed_state)(struct phylink_config *config,
 				struct phylink_link_state *state);