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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 phylink_link_state phy_state;
  28. struct work_struct resolve;
  29. unsigned int pcs_neg_mode;
  30. + unsigned int pcs_state;
  31. bool mac_link_dropped;
  32. bool using_mac_select_pcs;
  33. @@ -992,6 +997,22 @@ static void phylink_resolve_an_pause(str
  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 int phylink_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode,
  53. const struct phylink_link_state *state,
  54. bool permit_pause_to_mac)
  55. @@ -1094,11 +1115,17 @@ static void phylink_major_config(struct
  56. /* If we have a new PCS, switch to the new PCS after preparing the MAC
  57. * for the change.
  58. */
  59. - if (pcs_changed)
  60. + if (pcs_changed) {
  61. + phylink_pcs_disable(pl->pcs);
  62. +
  63. pl->pcs = pcs;
  64. + }
  65. phylink_mac_config(pl, state);
  66. + if (pl->pcs_state == PCS_STATE_STARTING || pcs_changed)
  67. + phylink_pcs_enable(pl->pcs);
  68. +
  69. neg_mode = pl->cur_link_an_mode;
  70. if (pl->pcs && pl->pcs->neg_mode)
  71. neg_mode = pl->pcs_neg_mode;
  72. @@ -1586,6 +1613,7 @@ struct phylink *phylink_create(struct ph
  73. pl->link_config.pause = MLO_PAUSE_AN;
  74. pl->link_config.speed = SPEED_UNKNOWN;
  75. pl->link_config.duplex = DUPLEX_UNKNOWN;
  76. + pl->pcs_state = PCS_STATE_DOWN;
  77. pl->mac_ops = mac_ops;
  78. __set_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state);
  79. timer_setup(&pl->link_poll, phylink_fixed_poll, 0);
  80. @@ -1987,6 +2015,8 @@ void phylink_start(struct phylink *pl)
  81. if (pl->netdev)
  82. netif_carrier_off(pl->netdev);
  83. + pl->pcs_state = PCS_STATE_STARTING;
  84. +
  85. /* Apply the link configuration to the MAC when starting. This allows
  86. * a fixed-link to start with the correct parameters, and also
  87. * ensures that we set the appropriate advertisement for Serdes links.
  88. @@ -1997,6 +2027,8 @@ void phylink_start(struct phylink *pl)
  89. */
  90. phylink_mac_initial_config(pl, true);
  91. + pl->pcs_state = PCS_STATE_STARTED;
  92. +
  93. phylink_enable_and_run_resolve(pl, PHYLINK_DISABLE_STOPPED);
  94. if (pl->cfg_link_an_mode == MLO_AN_FIXED && pl->link_gpio) {
  95. @@ -2015,15 +2047,9 @@ void phylink_start(struct phylink *pl)
  96. poll = true;
  97. }
  98. - switch (pl->cfg_link_an_mode) {
  99. - case MLO_AN_FIXED:
  100. + if (pl->cfg_link_an_mode == MLO_AN_FIXED)
  101. poll |= pl->config->poll_fixed_state;
  102. - break;
  103. - case MLO_AN_INBAND:
  104. - if (pl->pcs)
  105. - poll |= pl->pcs->poll;
  106. - break;
  107. - }
  108. +
  109. if (poll)
  110. mod_timer(&pl->link_poll, jiffies + HZ);
  111. if (pl->phydev)
  112. @@ -2060,6 +2086,10 @@ void phylink_stop(struct phylink *pl)
  113. }
  114. phylink_run_resolve_and_disable(pl, PHYLINK_DISABLE_STOPPED);
  115. +
  116. + pl->pcs_state = PCS_STATE_DOWN;
  117. +
  118. + phylink_pcs_disable(pl->pcs);
  119. }
  120. EXPORT_SYMBOL_GPL(phylink_stop);
  121. --- a/include/linux/phylink.h
  122. +++ b/include/linux/phylink.h
  123. @@ -533,6 +533,8 @@ struct phylink_pcs {
  124. /**
  125. * struct phylink_pcs_ops - MAC PCS operations structure.
  126. * @pcs_validate: validate the link configuration.
  127. + * @pcs_enable: enable the PCS.
  128. + * @pcs_disable: disable the PCS.
  129. * @pcs_get_state: read the current MAC PCS link state from the hardware.
  130. * @pcs_config: configure the MAC PCS for the selected mode and state.
  131. * @pcs_an_restart: restart 802.3z BaseX autonegotiation.
  132. @@ -542,6 +544,8 @@ struct phylink_pcs {
  133. struct phylink_pcs_ops {
  134. int (*pcs_validate)(struct phylink_pcs *pcs, unsigned long *supported,
  135. const struct phylink_link_state *state);
  136. + int (*pcs_enable)(struct phylink_pcs *pcs);
  137. + void (*pcs_disable)(struct phylink_pcs *pcs);
  138. void (*pcs_get_state)(struct phylink_pcs *pcs,
  139. struct phylink_link_state *state);
  140. int (*pcs_config)(struct phylink_pcs *pcs, unsigned int neg_mode,
  141. @@ -572,6 +576,18 @@ int pcs_validate(struct phylink_pcs *pcs
  142. const struct phylink_link_state *state);
  143. /**
  144. + * pcs_enable() - enable the PCS.
  145. + * @pcs: a pointer to a &struct phylink_pcs.
  146. + */
  147. +int pcs_enable(struct phylink_pcs *pcs);
  148. +
  149. +/**
  150. + * pcs_disable() - disable the PCS.
  151. + * @pcs: a pointer to a &struct phylink_pcs.
  152. + */
  153. +void pcs_disable(struct phylink_pcs *pcs);
  154. +
  155. +/**
  156. * pcs_get_state() - Read the current inband link state from the hardware
  157. * @pcs: a pointer to a &struct phylink_pcs.
  158. * @state: a pointer to a &struct phylink_link_state.