704-18-v5.19-net-mtk_eth_soc-partially-convert-to-phylink_pcs.patch 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. From 14a44ab0330d290fade1403a920e299cc56d7300 Mon Sep 17 00:00:00 2001
  2. From: "Russell King (Oracle)" <[email protected]>
  3. Date: Wed, 18 May 2022 15:55:28 +0100
  4. Subject: [PATCH 12/12] net: mtk_eth_soc: partially convert to phylink_pcs
  5. Partially convert mtk_eth_soc to phylink_pcs, moving the configuration,
  6. link up and AN restart over. However, it seems mac_pcs_get_state()
  7. doesn't actually get the state from the PCS, so we can't convert that
  8. over without a better understanding of the hardware.
  9. Signed-off-by: Russell King (Oracle) <[email protected]>
  10. Signed-off-by: Jakub Kicinski <[email protected]>
  11. ---
  12. drivers/net/ethernet/mediatek/mtk_eth_soc.c | 49 ++++++++----------
  13. drivers/net/ethernet/mediatek/mtk_eth_soc.h | 7 ++-
  14. drivers/net/ethernet/mediatek/mtk_sgmii.c | 55 +++++++++++----------
  15. 3 files changed, 53 insertions(+), 58 deletions(-)
  16. --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
  17. +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
  18. @@ -310,6 +310,25 @@ static void mtk_gmac0_rgmii_adjust(struc
  19. mtk_w32(eth, val, TRGMII_TCK_CTRL);
  20. }
  21. +static struct phylink_pcs *mtk_mac_select_pcs(struct phylink_config *config,
  22. + phy_interface_t interface)
  23. +{
  24. + struct mtk_mac *mac = container_of(config, struct mtk_mac,
  25. + phylink_config);
  26. + struct mtk_eth *eth = mac->hw;
  27. + unsigned int sid;
  28. +
  29. + if (interface == PHY_INTERFACE_MODE_SGMII ||
  30. + phy_interface_mode_is_8023z(interface)) {
  31. + sid = (MTK_HAS_CAPS(eth->soc->caps, MTK_SHARED_SGMII)) ?
  32. + 0 : mac->id;
  33. +
  34. + return mtk_sgmii_select_pcs(eth->sgmii, sid);
  35. + }
  36. +
  37. + return NULL;
  38. +}
  39. +
  40. static void mtk_mac_config(struct phylink_config *config, unsigned int mode,
  41. const struct phylink_link_state *state)
  42. {
  43. @@ -317,7 +336,7 @@ static void mtk_mac_config(struct phylin
  44. phylink_config);
  45. struct mtk_eth *eth = mac->hw;
  46. int val, ge_mode, err = 0;
  47. - u32 sid, i;
  48. + u32 i;
  49. /* MT76x8 has no hardware settings between for the MAC */
  50. if (!MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628) &&
  51. @@ -438,15 +457,6 @@ static void mtk_mac_config(struct phylin
  52. SYSCFG0_SGMII_MASK,
  53. ~(u32)SYSCFG0_SGMII_MASK);
  54. - /* Decide how GMAC and SGMIISYS be mapped */
  55. - sid = (MTK_HAS_CAPS(eth->soc->caps, MTK_SHARED_SGMII)) ?
  56. - 0 : mac->id;
  57. -
  58. - /* Setup SGMIISYS with the determined property */
  59. - err = mtk_sgmii_config(eth->sgmii, sid, mode, state->interface);
  60. - if (err)
  61. - goto init_err;
  62. -
  63. /* Save the syscfg0 value for mac_finish */
  64. mac->syscfg0 = val;
  65. } else if (phylink_autoneg_inband(mode)) {
  66. @@ -526,14 +536,6 @@ static void mtk_mac_pcs_get_state(struct
  67. state->pause |= MLO_PAUSE_TX;
  68. }
  69. -static void mtk_mac_an_restart(struct phylink_config *config)
  70. -{
  71. - struct mtk_mac *mac = container_of(config, struct mtk_mac,
  72. - phylink_config);
  73. -
  74. - mtk_sgmii_restart_an(mac->hw, mac->id);
  75. -}
  76. -
  77. static void mtk_mac_link_down(struct phylink_config *config, unsigned int mode,
  78. phy_interface_t interface)
  79. {
  80. @@ -554,15 +556,6 @@ static void mtk_mac_link_up(struct phyli
  81. phylink_config);
  82. u32 mcr;
  83. - if (phy_interface_mode_is_8023z(interface)) {
  84. - struct mtk_eth *eth = mac->hw;
  85. -
  86. - /* Decide how GMAC and SGMIISYS be mapped */
  87. - int sid = (MTK_HAS_CAPS(eth->soc->caps, MTK_SHARED_SGMII)) ?
  88. - 0 : mac->id;
  89. - mtk_sgmii_link_up(eth->sgmii, sid, speed, duplex);
  90. - }
  91. -
  92. mcr = mtk_r32(mac->hw, MTK_MAC_MCR(mac->id));
  93. mcr &= ~(MAC_MCR_SPEED_100 | MAC_MCR_SPEED_1000 |
  94. MAC_MCR_FORCE_DPX | MAC_MCR_FORCE_TX_FC |
  95. @@ -595,8 +588,8 @@ static void mtk_mac_link_up(struct phyli
  96. static const struct phylink_mac_ops mtk_phylink_ops = {
  97. .validate = phylink_generic_validate,
  98. + .mac_select_pcs = mtk_mac_select_pcs,
  99. .mac_pcs_get_state = mtk_mac_pcs_get_state,
  100. - .mac_an_restart = mtk_mac_an_restart,
  101. .mac_config = mtk_mac_config,
  102. .mac_finish = mtk_mac_finish,
  103. .mac_link_down = mtk_mac_link_down,
  104. --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
  105. +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
  106. @@ -964,10 +964,12 @@ struct mtk_soc_data {
  107. * @regmap: The register map pointing at the range used to setup
  108. * SGMII modes
  109. * @ana_rgc3: The offset refers to register ANA_RGC3 related to regmap
  110. + * @pcs: Phylink PCS structure
  111. */
  112. struct mtk_pcs {
  113. struct regmap *regmap;
  114. u32 ana_rgc3;
  115. + struct phylink_pcs pcs;
  116. };
  117. /* struct mtk_sgmii - This is the structure holding sgmii regmap and its
  118. @@ -1107,12 +1109,9 @@ void mtk_stats_update_mac(struct mtk_mac
  119. void mtk_w32(struct mtk_eth *eth, u32 val, unsigned reg);
  120. u32 mtk_r32(struct mtk_eth *eth, unsigned reg);
  121. +struct phylink_pcs *mtk_sgmii_select_pcs(struct mtk_sgmii *ss, int id);
  122. int mtk_sgmii_init(struct mtk_sgmii *ss, struct device_node *np,
  123. u32 ana_rgc3);
  124. -int mtk_sgmii_config(struct mtk_sgmii *ss, int id, unsigned int mode,
  125. - phy_interface_t interface);
  126. -void mtk_sgmii_link_up(struct mtk_sgmii *ss, int id, int speed, int duplex);
  127. -void mtk_sgmii_restart_an(struct mtk_eth *eth, int mac_id);
  128. int mtk_gmac_sgmii_path_setup(struct mtk_eth *eth, int mac_id);
  129. int mtk_gmac_gephy_path_setup(struct mtk_eth *eth, int mac_id);
  130. --- a/drivers/net/ethernet/mediatek/mtk_sgmii.c
  131. +++ b/drivers/net/ethernet/mediatek/mtk_sgmii.c
  132. @@ -14,14 +14,16 @@
  133. #include "mtk_eth_soc.h"
  134. +static struct mtk_pcs *pcs_to_mtk_pcs(struct phylink_pcs *pcs)
  135. +{
  136. + return container_of(pcs, struct mtk_pcs, pcs);
  137. +}
  138. +
  139. /* For SGMII interface mode */
  140. static int mtk_pcs_setup_mode_an(struct mtk_pcs *mpcs)
  141. {
  142. unsigned int val;
  143. - if (!mpcs->regmap)
  144. - return -EINVAL;
  145. -
  146. /* Setup the link timer and QPHY power up inside SGMIISYS */
  147. regmap_write(mpcs->regmap, SGMSYS_PCS_LINK_TIMER,
  148. SGMII_LINK_TIMER_DEFAULT);
  149. @@ -50,9 +52,6 @@ static int mtk_pcs_setup_mode_force(stru
  150. {
  151. unsigned int val;
  152. - if (!mpcs->regmap)
  153. - return -EINVAL;
  154. -
  155. regmap_read(mpcs->regmap, mpcs->ana_rgc3, &val);
  156. val &= ~RG_PHY_SPEED_MASK;
  157. if (interface == PHY_INTERFACE_MODE_2500BASEX)
  158. @@ -78,10 +77,12 @@ static int mtk_pcs_setup_mode_force(stru
  159. return 0;
  160. }
  161. -int mtk_sgmii_config(struct mtk_sgmii *ss, int id, unsigned int mode,
  162. - phy_interface_t interface)
  163. +static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode,
  164. + phy_interface_t interface,
  165. + const unsigned long *advertising,
  166. + bool permit_pause_to_mac)
  167. {
  168. - struct mtk_pcs *mpcs = &ss->pcs[id];
  169. + struct mtk_pcs *mpcs = pcs_to_mtk_pcs(pcs);
  170. int err = 0;
  171. /* Setup SGMIISYS with the determined property */
  172. @@ -93,22 +94,25 @@ int mtk_sgmii_config(struct mtk_sgmii *s
  173. return err;
  174. }
  175. -static void mtk_pcs_restart_an(struct mtk_pcs *mpcs)
  176. +static void mtk_pcs_restart_an(struct phylink_pcs *pcs)
  177. {
  178. + struct mtk_pcs *mpcs = pcs_to_mtk_pcs(pcs);
  179. unsigned int val;
  180. - if (!mpcs->regmap)
  181. - return;
  182. -
  183. regmap_read(mpcs->regmap, SGMSYS_PCS_CONTROL_1, &val);
  184. val |= SGMII_AN_RESTART;
  185. regmap_write(mpcs->regmap, SGMSYS_PCS_CONTROL_1, val);
  186. }
  187. -static void mtk_pcs_link_up(struct mtk_pcs *mpcs, int speed, int duplex)
  188. +static void mtk_pcs_link_up(struct phylink_pcs *pcs, unsigned int mode,
  189. + phy_interface_t interface, int speed, int duplex)
  190. {
  191. + struct mtk_pcs *mpcs = pcs_to_mtk_pcs(pcs);
  192. unsigned int val;
  193. + if (!phy_interface_mode_is_8023z(interface))
  194. + return;
  195. +
  196. /* SGMII force duplex setting */
  197. regmap_read(mpcs->regmap, SGMSYS_SGMII_MODE, &val);
  198. val &= ~SGMII_DUPLEX_FULL;
  199. @@ -118,11 +122,11 @@ static void mtk_pcs_link_up(struct mtk_p
  200. regmap_write(mpcs->regmap, SGMSYS_SGMII_MODE, val);
  201. }
  202. -/* For 1000BASE-X and 2500BASE-X interface modes */
  203. -void mtk_sgmii_link_up(struct mtk_sgmii *ss, int id, int speed, int duplex)
  204. -{
  205. - mtk_pcs_link_up(&ss->pcs[id], speed, duplex);
  206. -}
  207. +static const struct phylink_pcs_ops mtk_pcs_ops = {
  208. + .pcs_config = mtk_pcs_config,
  209. + .pcs_an_restart = mtk_pcs_restart_an,
  210. + .pcs_link_up = mtk_pcs_link_up,
  211. +};
  212. int mtk_sgmii_init(struct mtk_sgmii *ss, struct device_node *r, u32 ana_rgc3)
  213. {
  214. @@ -139,18 +143,17 @@ int mtk_sgmii_init(struct mtk_sgmii *ss,
  215. of_node_put(np);
  216. if (IS_ERR(ss->pcs[i].regmap))
  217. return PTR_ERR(ss->pcs[i].regmap);
  218. +
  219. + ss->pcs[i].pcs.ops = &mtk_pcs_ops;
  220. }
  221. return 0;
  222. }
  223. -void mtk_sgmii_restart_an(struct mtk_eth *eth, int mac_id)
  224. +struct phylink_pcs *mtk_sgmii_select_pcs(struct mtk_sgmii *ss, int id)
  225. {
  226. - unsigned int sid;
  227. -
  228. - /* Decide how GMAC and SGMIISYS be mapped */
  229. - sid = (MTK_HAS_CAPS(eth->soc->caps, MTK_SHARED_SGMII)) ?
  230. - 0 : mac_id;
  231. + if (!ss->pcs[id].regmap)
  232. + return NULL;
  233. - mtk_pcs_restart_an(&eth->sgmii->pcs[sid]);
  234. + return &ss->pcs[id].pcs;
  235. }