792-03-v6.6-net-phylink-add-pcs_enable-pcs_disable-methods.patch 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. From 90ef0a7b0622c62758b2638604927867775479ea Mon Sep 17 00:00:00 2001
  2. From: "Russell King (Oracle)" <[email protected]>
  3. Date: Thu, 13 Jul 2023 09:42:07 +0100
  4. Subject: [PATCH] net: phylink: add pcs_enable()/pcs_disable() methods
  5. Add phylink PCS enable/disable callbacks that will allow us to place
  6. IEEE 802.3 register compliant PCS in power-down mode while not being
  7. used.
  8. Signed-off-by: Russell King (Oracle) <[email protected]>
  9. Signed-off-by: David S. Miller <[email protected]>
  10. ---
  11. drivers/net/phy/phylink.c | 48 +++++++++++++++++++++++++++++++--------
  12. include/linux/phylink.h | 16 +++++++++++++
  13. 2 files changed, 55 insertions(+), 9 deletions(-)
  14. --- a/drivers/net/phy/phylink.c
  15. +++ b/drivers/net/phy/phylink.c
  16. @@ -34,6 +34,10 @@ enum {
  17. PHYLINK_DISABLE_STOPPED,
  18. PHYLINK_DISABLE_LINK,
  19. PHYLINK_DISABLE_MAC_WOL,
  20. +
  21. + PCS_STATE_DOWN = 0,
  22. + PCS_STATE_STARTING,
  23. + PCS_STATE_STARTED,
  24. };
  25. /**
  26. @@ -72,6 +76,7 @@ struct phylink {
  27. struct mutex state_mutex;
  28. struct phylink_link_state phy_state;
  29. struct work_struct resolve;
  30. + unsigned int pcs_state;
  31. bool mac_link_dropped;
  32. bool using_mac_select_pcs;
  33. @@ -798,6 +803,22 @@ static void phylink_mac_pcs_an_restart(s
  34. }
  35. }
  36. +static void phylink_pcs_disable(struct phylink_pcs *pcs)
  37. +{
  38. + if (pcs && pcs->ops->pcs_disable)
  39. + pcs->ops->pcs_disable(pcs);
  40. +}
  41. +
  42. +static int phylink_pcs_enable(struct phylink_pcs *pcs)
  43. +{
  44. + int err = 0;
  45. +
  46. + if (pcs && pcs->ops->pcs_enable)
  47. + err = pcs->ops->pcs_enable(pcs);
  48. +
  49. + return err;
  50. +}
  51. +
  52. static void phylink_major_config(struct phylink *pl, bool restart,
  53. const struct phylink_link_state *state)
  54. {
  55. @@ -835,12 +856,16 @@ static void phylink_major_config(struct
  56. * for the change.
  57. */
  58. if (pcs_changed) {
  59. + phylink_pcs_disable(pl->pcs);
  60. pl->pcs = pcs;
  61. pl->pcs_ops = pcs->ops;
  62. }
  63. phylink_mac_config(pl, state);
  64. + if (pl->pcs_state == PCS_STATE_STARTING || pcs_changed)
  65. + phylink_pcs_enable(pl->pcs);
  66. +
  67. if (pl->pcs_ops) {
  68. err = pl->pcs_ops->pcs_config(pl->pcs, pl->cur_link_an_mode,
  69. state->interface,
  70. @@ -1264,6 +1289,7 @@ struct phylink *phylink_create(struct ph
  71. pl->link_config.speed = SPEED_UNKNOWN;
  72. pl->link_config.duplex = DUPLEX_UNKNOWN;
  73. pl->link_config.an_enabled = true;
  74. + pl->pcs_state = PCS_STATE_DOWN;
  75. pl->mac_ops = mac_ops;
  76. __set_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state);
  77. timer_setup(&pl->link_poll, phylink_fixed_poll, 0);
  78. @@ -1655,6 +1681,8 @@ void phylink_start(struct phylink *pl)
  79. if (pl->netdev)
  80. netif_carrier_off(pl->netdev);
  81. + pl->pcs_state = PCS_STATE_STARTING;
  82. +
  83. /* Apply the link configuration to the MAC when starting. This allows
  84. * a fixed-link to start with the correct parameters, and also
  85. * ensures that we set the appropriate advertisement for Serdes links.
  86. @@ -1665,6 +1693,8 @@ void phylink_start(struct phylink *pl)
  87. */
  88. phylink_mac_initial_config(pl, true);
  89. + pl->pcs_state = PCS_STATE_STARTED;
  90. +
  91. clear_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state);
  92. phylink_run_resolve(pl);
  93. @@ -1684,16 +1714,9 @@ void phylink_start(struct phylink *pl)
  94. poll = true;
  95. }
  96. - switch (pl->cfg_link_an_mode) {
  97. - case MLO_AN_FIXED:
  98. + if (pl->cfg_link_an_mode == MLO_AN_FIXED)
  99. poll |= pl->config->poll_fixed_state;
  100. - break;
  101. - case MLO_AN_INBAND:
  102. - poll |= pl->config->pcs_poll;
  103. - if (pl->pcs)
  104. - poll |= pl->pcs->poll;
  105. - break;
  106. - }
  107. +
  108. if (poll)
  109. mod_timer(&pl->link_poll, jiffies + HZ);
  110. if (pl->phydev)
  111. @@ -1730,6 +1753,10 @@ void phylink_stop(struct phylink *pl)
  112. }
  113. phylink_run_resolve_and_disable(pl, PHYLINK_DISABLE_STOPPED);
  114. +
  115. + pl->pcs_state = PCS_STATE_DOWN;
  116. +
  117. + phylink_pcs_disable(pl->pcs);
  118. }
  119. EXPORT_SYMBOL_GPL(phylink_stop);
  120. --- a/include/linux/phylink.h
  121. +++ b/include/linux/phylink.h
  122. @@ -419,6 +419,8 @@ struct phylink_pcs {
  123. /**
  124. * struct phylink_pcs_ops - MAC PCS operations structure.
  125. * @pcs_validate: validate the link configuration.
  126. + * @pcs_enable: enable the PCS.
  127. + * @pcs_disable: disable the PCS.
  128. * @pcs_get_state: read the current MAC PCS link state from the hardware.
  129. * @pcs_config: configure the MAC PCS for the selected mode and state.
  130. * @pcs_an_restart: restart 802.3z BaseX autonegotiation.
  131. @@ -428,6 +430,8 @@ struct phylink_pcs {
  132. struct phylink_pcs_ops {
  133. int (*pcs_validate)(struct phylink_pcs *pcs, unsigned long *supported,
  134. const struct phylink_link_state *state);
  135. + int (*pcs_enable)(struct phylink_pcs *pcs);
  136. + void (*pcs_disable)(struct phylink_pcs *pcs);
  137. void (*pcs_get_state)(struct phylink_pcs *pcs,
  138. struct phylink_link_state *state);
  139. int (*pcs_config)(struct phylink_pcs *pcs, unsigned int mode,
  140. @@ -458,6 +462,18 @@ int pcs_validate(struct phylink_pcs *pcs
  141. const struct phylink_link_state *state);
  142. /**
  143. + * pcs_enable() - enable the PCS.
  144. + * @pcs: a pointer to a &struct phylink_pcs.
  145. + */
  146. +int pcs_enable(struct phylink_pcs *pcs);
  147. +
  148. +/**
  149. + * pcs_disable() - disable the PCS.
  150. + * @pcs: a pointer to a &struct phylink_pcs.
  151. + */
  152. +void pcs_disable(struct phylink_pcs *pcs);
  153. +
  154. +/**
  155. * pcs_get_state() - Read the current inband link state from the hardware
  156. * @pcs: a pointer to a &struct phylink_pcs.
  157. * @state: a pointer to a &struct phylink_link_state.