790-41-v6.9-net-dsa-mt7530-get-rid-of-priv-info-cpu_port_config.patch 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. From 8554f6a7914d28b179671540f527897d85c88809 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Ar=C4=B1n=C3=A7=20=C3=9CNAL?= <[email protected]>
  3. Date: Fri, 1 Mar 2024 12:43:01 +0200
  4. Subject: [PATCH 41/48] net: dsa: mt7530: get rid of
  5. priv->info->cpu_port_config()
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. priv->info->cpu_port_config() is used for MT7531 and the switch on the
  10. MT7988 SoC. It sets up the ports described as a CPU port earlier than the
  11. phylink code path would do.
  12. This function is useless as:
  13. - Configuring the MACs can be done from the phylink_mac_config code path
  14. instead.
  15. - All the link configuration it does on the CPU ports are later undone with
  16. the port_enable, phylink_mac_config, and then phylink_mac_link_up code
  17. path [1].
  18. priv->p5_interface and priv->p6_interface were being used to prevent
  19. configuring the MACs from the phylink_mac_config code path. Remove them now
  20. that they hold no purpose.
  21. Remove priv->info->cpu_port_config(). On mt753x_phylink_mac_config, switch
  22. to if statements to simplify the code.
  23. Remove the overwriting of the speed and duplex interfaces for certain
  24. interface modes. Phylink already provides the speed and duplex variables
  25. with proper values. Phylink already sets the max speed of TRGMII to
  26. SPEED_1000. Add SPEED_2500 for PHY_INTERFACE_MODE_2500BASEX to where the
  27. speed and EEE bits are set instead.
  28. On the switch on the MT7988 SoC, PHY_INTERFACE_MODE_INTERNAL is being used
  29. to describe the interface mode of the 10G MAC, which is of port 6. On
  30. mt7988_cpu_port_config() PMCR_FORCE_SPEED_1000 was set via the
  31. PMCR_CPU_PORT_SETTING() mask. Add SPEED_10000 case to where the speed bits
  32. are set to cover this. No need to add it to where the EEE bits are set as
  33. the "MT7988A Wi-Fi 7 Generation Router Platform: Datasheet (Open Version)
  34. v0.1" document shows that these bits don't exist on the MT7530_PMCR_P(6)
  35. register.
  36. Remove the definition of PMCR_CPU_PORT_SETTING() now that it holds no
  37. purpose.
  38. Change mt753x_cpu_port_enable() to void now that there're no error cases
  39. left.
  40. Link: https://lore.kernel.org/netdev/[email protected]/ [1]
  41. Suggested-by: Russell King (Oracle) <[email protected]>
  42. Signed-off-by: Arınç ÜNAL <[email protected]>
  43. Signed-off-by: Paolo Abeni <[email protected]>
  44. ---
  45. drivers/net/dsa/mt7530.c | 114 +++------------------------------------
  46. drivers/net/dsa/mt7530.h | 11 ----
  47. 2 files changed, 7 insertions(+), 118 deletions(-)
  48. --- a/drivers/net/dsa/mt7530.c
  49. +++ b/drivers/net/dsa/mt7530.c
  50. @@ -995,18 +995,10 @@ mt753x_trap_frames(struct mt7530_priv *p
  51. MT753X_BPDU_CPU_ONLY);
  52. }
  53. -static int
  54. +static void
  55. mt753x_cpu_port_enable(struct dsa_switch *ds, int port)
  56. {
  57. struct mt7530_priv *priv = ds->priv;
  58. - int ret;
  59. -
  60. - /* Setup max capability of CPU port at first */
  61. - if (priv->info->cpu_port_config) {
  62. - ret = priv->info->cpu_port_config(ds, port);
  63. - if (ret)
  64. - return ret;
  65. - }
  66. /* Enable Mediatek header mode on the cpu port */
  67. mt7530_write(priv, MT7530_PVC_P(port),
  68. @@ -1032,8 +1024,6 @@ mt753x_cpu_port_enable(struct dsa_switch
  69. /* Set to fallback mode for independent VLAN learning */
  70. mt7530_rmw(priv, MT7530_PCR_P(port), PCR_PORT_VLAN_MASK,
  71. MT7530_PORT_FALLBACK_MODE);
  72. -
  73. - return 0;
  74. }
  75. static int
  76. @@ -2288,8 +2278,6 @@ mt7530_setup(struct dsa_switch *ds)
  77. val |= MHWTRAP_MANUAL;
  78. mt7530_write(priv, MT7530_MHWTRAP, val);
  79. - priv->p6_interface = PHY_INTERFACE_MODE_NA;
  80. -
  81. mt753x_trap_frames(priv);
  82. /* Enable and reset MIB counters */
  83. @@ -2304,9 +2292,7 @@ mt7530_setup(struct dsa_switch *ds)
  84. mt7530_set(priv, MT7530_PSC_P(i), SA_DIS);
  85. if (dsa_is_cpu_port(ds, i)) {
  86. - ret = mt753x_cpu_port_enable(ds, i);
  87. - if (ret)
  88. - return ret;
  89. + mt753x_cpu_port_enable(ds, i);
  90. } else {
  91. mt7530_port_disable(ds, i);
  92. @@ -2410,9 +2396,7 @@ mt7531_setup_common(struct dsa_switch *d
  93. mt7530_set(priv, MT7531_DBG_CNT(i), MT7531_DIS_CLR);
  94. if (dsa_is_cpu_port(ds, i)) {
  95. - ret = mt753x_cpu_port_enable(ds, i);
  96. - if (ret)
  97. - return ret;
  98. + mt753x_cpu_port_enable(ds, i);
  99. } else {
  100. mt7530_port_disable(ds, i);
  101. @@ -2501,10 +2485,6 @@ mt7531_setup(struct dsa_switch *ds)
  102. mt7530_rmw(priv, MT7531_GPIO_MODE0, MT7531_GPIO0_MASK,
  103. MT7531_GPIO0_INTERRUPT);
  104. - /* Let phylink decide the interface later. */
  105. - priv->p5_interface = PHY_INTERFACE_MODE_NA;
  106. - priv->p6_interface = PHY_INTERFACE_MODE_NA;
  107. -
  108. /* Enable PHY core PLL, since phy_device has not yet been created
  109. * provided for phy_[read,write]_mmd_indirect is called, we provide
  110. * our own mt7531_ind_mmd_phy_[read,write] to complete this
  111. @@ -2716,26 +2696,9 @@ mt753x_phylink_mac_config(struct dsa_swi
  112. struct mt7530_priv *priv = ds->priv;
  113. u32 mcr_cur, mcr_new;
  114. - switch (port) {
  115. - case 5:
  116. - if (priv->p5_interface == state->interface)
  117. - break;
  118. -
  119. + if (port == 5 || port == 6)
  120. mt753x_mac_config(ds, port, mode, state);
  121. - if (priv->p5_intf_sel != P5_DISABLED)
  122. - priv->p5_interface = state->interface;
  123. - break;
  124. - case 6:
  125. - if (priv->p6_interface == state->interface)
  126. - break;
  127. -
  128. - mt753x_mac_config(ds, port, mode, state);
  129. -
  130. - priv->p6_interface = state->interface;
  131. - break;
  132. - }
  133. -
  134. mcr_cur = mt7530_read(priv, MT7530_PMCR_P(port));
  135. mcr_new = mcr_cur;
  136. mcr_new &= ~PMCR_LINK_SETTINGS_MASK;
  137. @@ -2771,17 +2734,10 @@ static void mt753x_phylink_mac_link_up(s
  138. mcr = PMCR_RX_EN | PMCR_TX_EN | PMCR_FORCE_LNK;
  139. - /* MT753x MAC works in 1G full duplex mode for all up-clocked
  140. - * variants.
  141. - */
  142. - if (interface == PHY_INTERFACE_MODE_TRGMII ||
  143. - (phy_interface_mode_is_8023z(interface))) {
  144. - speed = SPEED_1000;
  145. - duplex = DUPLEX_FULL;
  146. - }
  147. -
  148. switch (speed) {
  149. case SPEED_1000:
  150. + case SPEED_2500:
  151. + case SPEED_10000:
  152. mcr |= PMCR_FORCE_SPEED_1000;
  153. break;
  154. case SPEED_100:
  155. @@ -2799,6 +2755,7 @@ static void mt753x_phylink_mac_link_up(s
  156. if (mode == MLO_AN_PHY && phydev && phy_init_eee(phydev, false) >= 0) {
  157. switch (speed) {
  158. case SPEED_1000:
  159. + case SPEED_2500:
  160. mcr |= PMCR_FORCE_EEE1G;
  161. break;
  162. case SPEED_100:
  163. @@ -2810,61 +2767,6 @@ static void mt753x_phylink_mac_link_up(s
  164. mt7530_set(priv, MT7530_PMCR_P(port), mcr);
  165. }
  166. -static int
  167. -mt7531_cpu_port_config(struct dsa_switch *ds, int port)
  168. -{
  169. - struct mt7530_priv *priv = ds->priv;
  170. - phy_interface_t interface;
  171. - int speed;
  172. -
  173. - switch (port) {
  174. - case 5:
  175. - if (!priv->p5_sgmii)
  176. - interface = PHY_INTERFACE_MODE_RGMII;
  177. - else
  178. - interface = PHY_INTERFACE_MODE_2500BASEX;
  179. -
  180. - priv->p5_interface = interface;
  181. - break;
  182. - case 6:
  183. - interface = PHY_INTERFACE_MODE_2500BASEX;
  184. -
  185. - priv->p6_interface = interface;
  186. - break;
  187. - default:
  188. - return -EINVAL;
  189. - }
  190. -
  191. - if (interface == PHY_INTERFACE_MODE_2500BASEX)
  192. - speed = SPEED_2500;
  193. - else
  194. - speed = SPEED_1000;
  195. -
  196. - mt7531_mac_config(ds, port, MLO_AN_FIXED, interface);
  197. -
  198. - mt7530_write(priv, MT7530_PMCR_P(port),
  199. - PMCR_CPU_PORT_SETTING(priv->id));
  200. - mt753x_phylink_mac_link_up(ds, port, MLO_AN_FIXED, interface, NULL,
  201. - speed, DUPLEX_FULL, true, true);
  202. -
  203. - return 0;
  204. -}
  205. -
  206. -static int
  207. -mt7988_cpu_port_config(struct dsa_switch *ds, int port)
  208. -{
  209. - struct mt7530_priv *priv = ds->priv;
  210. -
  211. - mt7530_write(priv, MT7530_PMCR_P(port),
  212. - PMCR_CPU_PORT_SETTING(priv->id));
  213. -
  214. - mt753x_phylink_mac_link_up(ds, port, MLO_AN_FIXED,
  215. - PHY_INTERFACE_MODE_INTERNAL, NULL,
  216. - SPEED_10000, DUPLEX_FULL, true, true);
  217. -
  218. - return 0;
  219. -}
  220. -
  221. static void mt753x_phylink_get_caps(struct dsa_switch *ds, int port,
  222. struct phylink_config *config)
  223. {
  224. @@ -3122,7 +3024,6 @@ const struct mt753x_info mt753x_table[]
  225. .sw_setup = mt7531_setup,
  226. .phy_read = mt7531_ind_phy_read,
  227. .phy_write = mt7531_ind_phy_write,
  228. - .cpu_port_config = mt7531_cpu_port_config,
  229. .mac_port_get_caps = mt7531_mac_port_get_caps,
  230. .mac_port_config = mt7531_mac_config,
  231. },
  232. @@ -3132,7 +3033,6 @@ const struct mt753x_info mt753x_table[]
  233. .sw_setup = mt7988_setup,
  234. .phy_read = mt7531_ind_phy_read,
  235. .phy_write = mt7531_ind_phy_write,
  236. - .cpu_port_config = mt7988_cpu_port_config,
  237. .mac_port_get_caps = mt7988_mac_port_get_caps,
  238. },
  239. };
  240. --- a/drivers/net/dsa/mt7530.h
  241. +++ b/drivers/net/dsa/mt7530.h
  242. @@ -331,13 +331,6 @@ enum mt7530_vlan_port_acc_frm {
  243. PMCR_TX_FC_EN | PMCR_RX_FC_EN | \
  244. PMCR_FORCE_FDX | PMCR_FORCE_LNK | \
  245. PMCR_FORCE_EEE1G | PMCR_FORCE_EEE100)
  246. -#define PMCR_CPU_PORT_SETTING(id) (PMCR_FORCE_MODE_ID((id)) | \
  247. - PMCR_IFG_XMIT(1) | PMCR_MAC_MODE | \
  248. - PMCR_BACKOFF_EN | PMCR_BACKPR_EN | \
  249. - PMCR_TX_EN | PMCR_RX_EN | \
  250. - PMCR_TX_FC_EN | PMCR_RX_FC_EN | \
  251. - PMCR_FORCE_SPEED_1000 | \
  252. - PMCR_FORCE_FDX | PMCR_FORCE_LNK)
  253. #define MT7530_PMEEECR_P(x) (0x3004 + (x) * 0x100)
  254. #define WAKEUP_TIME_1000(x) (((x) & 0xFF) << 24)
  255. @@ -737,7 +730,6 @@ struct mt753x_info {
  256. int (*sw_setup)(struct dsa_switch *ds);
  257. int (*phy_read)(struct mt7530_priv *priv, int port, int regnum);
  258. int (*phy_write)(struct mt7530_priv *priv, int port, int regnum, u16 val);
  259. - int (*cpu_port_config)(struct dsa_switch *ds, int port);
  260. void (*mac_port_get_caps)(struct dsa_switch *ds, int port,
  261. struct phylink_config *config);
  262. void (*mac_port_validate)(struct dsa_switch *ds, int port,
  263. @@ -763,7 +755,6 @@ struct mt753x_info {
  264. * @ports: Holding the state among ports
  265. * @reg_mutex: The lock for protecting among process accessing
  266. * registers
  267. - * @p6_interface Holding the current port 6 interface
  268. * @p5_intf_sel: Holding the current port 5 interface select
  269. * @p5_sgmii: Flag for distinguishing if port 5 of the MT7531 switch
  270. * has got SGMII
  271. @@ -785,8 +776,6 @@ struct mt7530_priv {
  272. const struct mt753x_info *info;
  273. unsigned int id;
  274. bool mcm;
  275. - phy_interface_t p6_interface;
  276. - phy_interface_t p5_interface;
  277. enum p5_interface_select p5_intf_sel;
  278. bool p5_sgmii;
  279. u8 mirror_rx;