2
0

705-07-v5.19-net-dsa-mt7530-partially-convert-to-phylink_pcs.patch 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. From fd993fd59d96d5e2d5972ec4ca1f9651025c987b Mon Sep 17 00:00:00 2001
  2. From: "Russell King (Oracle)" <[email protected]>
  3. Date: Mon, 11 Apr 2022 10:46:27 +0100
  4. Subject: [PATCH 07/13] net: dsa: mt7530: partially convert to phylink_pcs
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. Partially convert the mt7530 driver to use phylink's PCS support. This
  9. is a partial implementation as we don't move anything into the
  10. pcs_config method yet - this driver supports SGMII or 1000BASE-X
  11. without in-band.
  12. Tested-by: Marek Behún <[email protected]>
  13. Signed-off-by: Russell King (Oracle) <[email protected]>
  14. Signed-off-by: Paolo Abeni <[email protected]>
  15. ---
  16. drivers/net/dsa/mt7530.c | 144 +++++++++++++++++++++++----------------
  17. drivers/net/dsa/mt7530.h | 21 +++---
  18. 2 files changed, 95 insertions(+), 70 deletions(-)
  19. --- a/drivers/net/dsa/mt7530.c
  20. +++ b/drivers/net/dsa/mt7530.c
  21. @@ -25,6 +25,11 @@
  22. #include "mt7530.h"
  23. +static struct mt753x_pcs *pcs_to_mt753x_pcs(struct phylink_pcs *pcs)
  24. +{
  25. + return container_of(pcs, struct mt753x_pcs, pcs);
  26. +}
  27. +
  28. /* String, offset, and register size in bytes if different from 4 bytes */
  29. static const struct mt7530_mib_desc mt7530_mib[] = {
  30. MIB_DESC(1, 0x00, "TxDrop"),
  31. @@ -2631,12 +2636,11 @@ static int mt7531_rgmii_setup(struct mt7
  32. return 0;
  33. }
  34. -static void
  35. -mt7531_sgmii_link_up_force(struct dsa_switch *ds, int port,
  36. - unsigned int mode, phy_interface_t interface,
  37. - int speed, int duplex)
  38. +static void mt7531_pcs_link_up(struct phylink_pcs *pcs, unsigned int mode,
  39. + phy_interface_t interface, int speed, int duplex)
  40. {
  41. - struct mt7530_priv *priv = ds->priv;
  42. + struct mt7530_priv *priv = pcs_to_mt753x_pcs(pcs)->priv;
  43. + int port = pcs_to_mt753x_pcs(pcs)->port;
  44. unsigned int val;
  45. /* For adjusting speed and duplex of SGMII force mode. */
  46. @@ -2662,6 +2666,9 @@ mt7531_sgmii_link_up_force(struct dsa_sw
  47. /* MT7531 SGMII 1G force mode can only work in full duplex mode,
  48. * no matter MT7531_SGMII_FORCE_HALF_DUPLEX is set or not.
  49. + *
  50. + * The speed check is unnecessary as the MAC capabilities apply
  51. + * this restriction. --rmk
  52. */
  53. if ((speed == SPEED_10 || speed == SPEED_100) &&
  54. duplex != DUPLEX_FULL)
  55. @@ -2737,9 +2744,10 @@ static int mt7531_sgmii_setup_mode_an(st
  56. return 0;
  57. }
  58. -static void mt7531_sgmii_restart_an(struct dsa_switch *ds, int port)
  59. +static void mt7531_pcs_an_restart(struct phylink_pcs *pcs)
  60. {
  61. - struct mt7530_priv *priv = ds->priv;
  62. + struct mt7530_priv *priv = pcs_to_mt753x_pcs(pcs)->priv;
  63. + int port = pcs_to_mt753x_pcs(pcs)->port;
  64. u32 val;
  65. /* Only restart AN when AN is enabled */
  66. @@ -2796,6 +2804,24 @@ mt753x_mac_config(struct dsa_switch *ds,
  67. return priv->info->mac_port_config(ds, port, mode, state->interface);
  68. }
  69. +static struct phylink_pcs *
  70. +mt753x_phylink_mac_select_pcs(struct dsa_switch *ds, int port,
  71. + phy_interface_t interface)
  72. +{
  73. + struct mt7530_priv *priv = ds->priv;
  74. +
  75. + switch (interface) {
  76. + case PHY_INTERFACE_MODE_TRGMII:
  77. + case PHY_INTERFACE_MODE_SGMII:
  78. + case PHY_INTERFACE_MODE_1000BASEX:
  79. + case PHY_INTERFACE_MODE_2500BASEX:
  80. + return &priv->pcs[port].pcs;
  81. +
  82. + default:
  83. + return NULL;
  84. + }
  85. +}
  86. +
  87. static void
  88. mt753x_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode,
  89. const struct phylink_link_state *state)
  90. @@ -2857,17 +2883,6 @@ unsupported:
  91. mt7530_write(priv, MT7530_PMCR_P(port), mcr_new);
  92. }
  93. -static void
  94. -mt753x_phylink_mac_an_restart(struct dsa_switch *ds, int port)
  95. -{
  96. - struct mt7530_priv *priv = ds->priv;
  97. -
  98. - if (!priv->info->mac_pcs_an_restart)
  99. - return;
  100. -
  101. - priv->info->mac_pcs_an_restart(ds, port);
  102. -}
  103. -
  104. static void mt753x_phylink_mac_link_down(struct dsa_switch *ds, int port,
  105. unsigned int mode,
  106. phy_interface_t interface)
  107. @@ -2877,16 +2892,13 @@ static void mt753x_phylink_mac_link_down
  108. mt7530_clear(priv, MT7530_PMCR_P(port), PMCR_LINK_SETTINGS_MASK);
  109. }
  110. -static void mt753x_mac_pcs_link_up(struct dsa_switch *ds, int port,
  111. - unsigned int mode, phy_interface_t interface,
  112. - int speed, int duplex)
  113. +static void mt753x_phylink_pcs_link_up(struct phylink_pcs *pcs,
  114. + unsigned int mode,
  115. + phy_interface_t interface,
  116. + int speed, int duplex)
  117. {
  118. - struct mt7530_priv *priv = ds->priv;
  119. -
  120. - if (!priv->info->mac_pcs_link_up)
  121. - return;
  122. -
  123. - priv->info->mac_pcs_link_up(ds, port, mode, interface, speed, duplex);
  124. + if (pcs->ops->pcs_link_up)
  125. + pcs->ops->pcs_link_up(pcs, mode, interface, speed, duplex);
  126. }
  127. static void mt753x_phylink_mac_link_up(struct dsa_switch *ds, int port,
  128. @@ -2899,8 +2911,6 @@ static void mt753x_phylink_mac_link_up(s
  129. struct mt7530_priv *priv = ds->priv;
  130. u32 mcr;
  131. - mt753x_mac_pcs_link_up(ds, port, mode, interface, speed, duplex);
  132. -
  133. mcr = PMCR_RX_EN | PMCR_TX_EN | PMCR_FORCE_LNK;
  134. /* MT753x MAC works in 1G full duplex mode for all up-clocked
  135. @@ -2978,6 +2988,8 @@ mt7531_cpu_port_config(struct dsa_switch
  136. return ret;
  137. mt7530_write(priv, MT7530_PMCR_P(port),
  138. PMCR_CPU_PORT_SETTING(priv->id));
  139. + mt753x_phylink_pcs_link_up(&priv->pcs[port].pcs, MLO_AN_FIXED,
  140. + interface, speed, DUPLEX_FULL);
  141. mt753x_phylink_mac_link_up(ds, port, MLO_AN_FIXED, interface, NULL,
  142. speed, DUPLEX_FULL, true, true);
  143. @@ -3017,16 +3029,13 @@ mt753x_phylink_validate(struct dsa_switc
  144. linkmode_and(state->advertising, state->advertising, mask);
  145. }
  146. -static int
  147. -mt7530_phylink_mac_link_state(struct dsa_switch *ds, int port,
  148. - struct phylink_link_state *state)
  149. +static void mt7530_pcs_get_state(struct phylink_pcs *pcs,
  150. + struct phylink_link_state *state)
  151. {
  152. - struct mt7530_priv *priv = ds->priv;
  153. + struct mt7530_priv *priv = pcs_to_mt753x_pcs(pcs)->priv;
  154. + int port = pcs_to_mt753x_pcs(pcs)->port;
  155. u32 pmsr;
  156. - if (port < 0 || port >= MT7530_NUM_PORTS)
  157. - return -EINVAL;
  158. -
  159. pmsr = mt7530_read(priv, MT7530_PMSR_P(port));
  160. state->link = (pmsr & PMSR_LINK);
  161. @@ -3053,8 +3062,6 @@ mt7530_phylink_mac_link_state(struct dsa
  162. state->pause |= MLO_PAUSE_RX;
  163. if (pmsr & PMSR_TX_FC)
  164. state->pause |= MLO_PAUSE_TX;
  165. -
  166. - return 1;
  167. }
  168. static int
  169. @@ -3096,32 +3103,49 @@ mt7531_sgmii_pcs_get_state_an(struct mt7
  170. return 0;
  171. }
  172. -static int
  173. -mt7531_phylink_mac_link_state(struct dsa_switch *ds, int port,
  174. - struct phylink_link_state *state)
  175. +static void mt7531_pcs_get_state(struct phylink_pcs *pcs,
  176. + struct phylink_link_state *state)
  177. {
  178. - struct mt7530_priv *priv = ds->priv;
  179. + struct mt7530_priv *priv = pcs_to_mt753x_pcs(pcs)->priv;
  180. + int port = pcs_to_mt753x_pcs(pcs)->port;
  181. if (state->interface == PHY_INTERFACE_MODE_SGMII)
  182. - return mt7531_sgmii_pcs_get_state_an(priv, port, state);
  183. -
  184. - return -EOPNOTSUPP;
  185. + mt7531_sgmii_pcs_get_state_an(priv, port, state);
  186. + else
  187. + state->link = false;
  188. }
  189. -static int
  190. -mt753x_phylink_mac_link_state(struct dsa_switch *ds, int port,
  191. - struct phylink_link_state *state)
  192. +static int mt753x_pcs_config(struct phylink_pcs *pcs, unsigned int mode,
  193. + phy_interface_t interface,
  194. + const unsigned long *advertising,
  195. + bool permit_pause_to_mac)
  196. {
  197. - struct mt7530_priv *priv = ds->priv;
  198. + return 0;
  199. +}
  200. - return priv->info->mac_port_get_state(ds, port, state);
  201. +static void mt7530_pcs_an_restart(struct phylink_pcs *pcs)
  202. +{
  203. }
  204. +static const struct phylink_pcs_ops mt7530_pcs_ops = {
  205. + .pcs_get_state = mt7530_pcs_get_state,
  206. + .pcs_config = mt753x_pcs_config,
  207. + .pcs_an_restart = mt7530_pcs_an_restart,
  208. +};
  209. +
  210. +static const struct phylink_pcs_ops mt7531_pcs_ops = {
  211. + .pcs_get_state = mt7531_pcs_get_state,
  212. + .pcs_config = mt753x_pcs_config,
  213. + .pcs_an_restart = mt7531_pcs_an_restart,
  214. + .pcs_link_up = mt7531_pcs_link_up,
  215. +};
  216. +
  217. static int
  218. mt753x_setup(struct dsa_switch *ds)
  219. {
  220. struct mt7530_priv *priv = ds->priv;
  221. int ret = priv->info->sw_setup(ds);
  222. + int i;
  223. if (ret)
  224. return ret;
  225. @@ -3134,6 +3158,13 @@ mt753x_setup(struct dsa_switch *ds)
  226. if (ret && priv->irq)
  227. mt7530_free_irq_common(priv);
  228. + /* Initialise the PCS devices */
  229. + for (i = 0; i < priv->ds->num_ports; i++) {
  230. + priv->pcs[i].pcs.ops = priv->info->pcs_ops;
  231. + priv->pcs[i].priv = priv;
  232. + priv->pcs[i].port = i;
  233. + }
  234. +
  235. return ret;
  236. }
  237. @@ -3195,9 +3226,8 @@ static const struct dsa_switch_ops mt753
  238. .port_mirror_del = mt753x_port_mirror_del,
  239. .phylink_get_caps = mt753x_phylink_get_caps,
  240. .phylink_validate = mt753x_phylink_validate,
  241. - .phylink_mac_link_state = mt753x_phylink_mac_link_state,
  242. + .phylink_mac_select_pcs = mt753x_phylink_mac_select_pcs,
  243. .phylink_mac_config = mt753x_phylink_mac_config,
  244. - .phylink_mac_an_restart = mt753x_phylink_mac_an_restart,
  245. .phylink_mac_link_down = mt753x_phylink_mac_link_down,
  246. .phylink_mac_link_up = mt753x_phylink_mac_link_up,
  247. .get_mac_eee = mt753x_get_mac_eee,
  248. @@ -3207,36 +3237,34 @@ static const struct dsa_switch_ops mt753
  249. static const struct mt753x_info mt753x_table[] = {
  250. [ID_MT7621] = {
  251. .id = ID_MT7621,
  252. + .pcs_ops = &mt7530_pcs_ops,
  253. .sw_setup = mt7530_setup,
  254. .phy_read = mt7530_phy_read,
  255. .phy_write = mt7530_phy_write,
  256. .pad_setup = mt7530_pad_clk_setup,
  257. .mac_port_get_caps = mt7530_mac_port_get_caps,
  258. - .mac_port_get_state = mt7530_phylink_mac_link_state,
  259. .mac_port_config = mt7530_mac_config,
  260. },
  261. [ID_MT7530] = {
  262. .id = ID_MT7530,
  263. + .pcs_ops = &mt7530_pcs_ops,
  264. .sw_setup = mt7530_setup,
  265. .phy_read = mt7530_phy_read,
  266. .phy_write = mt7530_phy_write,
  267. .pad_setup = mt7530_pad_clk_setup,
  268. .mac_port_get_caps = mt7530_mac_port_get_caps,
  269. - .mac_port_get_state = mt7530_phylink_mac_link_state,
  270. .mac_port_config = mt7530_mac_config,
  271. },
  272. [ID_MT7531] = {
  273. .id = ID_MT7531,
  274. + .pcs_ops = &mt7531_pcs_ops,
  275. .sw_setup = mt7531_setup,
  276. .phy_read = mt7531_ind_phy_read,
  277. .phy_write = mt7531_ind_phy_write,
  278. .pad_setup = mt7531_pad_setup,
  279. .cpu_port_config = mt7531_cpu_port_config,
  280. .mac_port_get_caps = mt7531_mac_port_get_caps,
  281. - .mac_port_get_state = mt7531_phylink_mac_link_state,
  282. .mac_port_config = mt7531_mac_config,
  283. - .mac_pcs_an_restart = mt7531_sgmii_restart_an,
  284. - .mac_pcs_link_up = mt7531_sgmii_link_up_force,
  285. },
  286. };
  287. @@ -3294,7 +3322,7 @@ mt7530_probe(struct mdio_device *mdiodev
  288. if (!priv->info->sw_setup || !priv->info->pad_setup ||
  289. !priv->info->phy_read || !priv->info->phy_write ||
  290. !priv->info->mac_port_get_caps ||
  291. - !priv->info->mac_port_get_state || !priv->info->mac_port_config)
  292. + !priv->info->mac_port_config)
  293. return -EINVAL;
  294. priv->id = priv->info->id;
  295. --- a/drivers/net/dsa/mt7530.h
  296. +++ b/drivers/net/dsa/mt7530.h
  297. @@ -768,6 +768,12 @@ static const char *p5_intf_modes(unsigne
  298. struct mt7530_priv;
  299. +struct mt753x_pcs {
  300. + struct phylink_pcs pcs;
  301. + struct mt7530_priv *priv;
  302. + int port;
  303. +};
  304. +
  305. /* struct mt753x_info - This is the main data structure for holding the specific
  306. * part for each supported device
  307. * @sw_setup: Holding the handler to a device initialization
  308. @@ -779,18 +785,14 @@ struct mt7530_priv;
  309. * port
  310. * @mac_port_validate: Holding the way to set addition validate type for a
  311. * certan MAC port
  312. - * @mac_port_get_state: Holding the way getting the MAC/PCS state for a certain
  313. - * MAC port
  314. * @mac_port_config: Holding the way setting up the PHY attribute to a
  315. * certain MAC port
  316. - * @mac_pcs_an_restart Holding the way restarting PCS autonegotiation for a
  317. - * certain MAC port
  318. - * @mac_pcs_link_up: Holding the way setting up the PHY attribute to the pcs
  319. - * of the certain MAC port
  320. */
  321. struct mt753x_info {
  322. enum mt753x_id id;
  323. + const struct phylink_pcs_ops *pcs_ops;
  324. +
  325. int (*sw_setup)(struct dsa_switch *ds);
  326. int (*phy_read)(struct mt7530_priv *priv, int port, int regnum);
  327. int (*phy_write)(struct mt7530_priv *priv, int port, int regnum, u16 val);
  328. @@ -801,15 +803,9 @@ struct mt753x_info {
  329. void (*mac_port_validate)(struct dsa_switch *ds, int port,
  330. phy_interface_t interface,
  331. unsigned long *supported);
  332. - int (*mac_port_get_state)(struct dsa_switch *ds, int port,
  333. - struct phylink_link_state *state);
  334. int (*mac_port_config)(struct dsa_switch *ds, int port,
  335. unsigned int mode,
  336. phy_interface_t interface);
  337. - void (*mac_pcs_an_restart)(struct dsa_switch *ds, int port);
  338. - void (*mac_pcs_link_up)(struct dsa_switch *ds, int port,
  339. - unsigned int mode, phy_interface_t interface,
  340. - int speed, int duplex);
  341. };
  342. /* struct mt7530_priv - This is the main data structure for holding the state
  343. @@ -851,6 +847,7 @@ struct mt7530_priv {
  344. u8 mirror_tx;
  345. struct mt7530_port ports[MT7530_NUM_PORTS];
  346. + struct mt753x_pcs pcs[MT7530_NUM_PORTS];
  347. /* protect among processes for registers access*/
  348. struct mutex reg_mutex;
  349. int irq;