0705-v5.13-net-dsa-lantiq-allow-to-use-all-GPHYs-on-xRX300-and-.patch 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. From a09d042b086202735c4ed64573cdd79933020001 Mon Sep 17 00:00:00 2001
  2. From: Aleksander Jan Bajkowski <[email protected]>
  3. Date: Mon, 22 Mar 2021 21:37:15 +0100
  4. Subject: [PATCH] net: dsa: lantiq: allow to use all GPHYs on xRX300 and xRX330
  5. This patch allows to use all PHYs on GRX300 and GRX330. The ARX300
  6. has 3 and the GRX330 has 4 integrated PHYs connected to different
  7. ports compared to VRX200. Each integrated PHY can work as single
  8. Gigabit Ethernet PHY (GMII) or as double Fast Ethernet PHY (MII).
  9. Allowed port configurations:
  10. xRX200:
  11. GMAC0: RGMII, MII, REVMII or RMII port
  12. GMAC1: RGMII, MII, REVMII or RMII port
  13. GMAC2: GPHY0 (GMII)
  14. GMAC3: GPHY0 (MII)
  15. GMAC4: GPHY1 (GMII)
  16. GMAC5: GPHY1 (MII) or RGMII port
  17. xRX300:
  18. GMAC0: RGMII port
  19. GMAC1: GPHY2 (GMII)
  20. GMAC2: GPHY0 (GMII)
  21. GMAC3: GPHY0 (MII)
  22. GMAC4: GPHY1 (GMII)
  23. GMAC5: GPHY1 (MII) or RGMII port
  24. xRX330:
  25. GMAC0: RGMII, GMII or RMII port
  26. GMAC1: GPHY2 (GMII)
  27. GMAC2: GPHY0 (GMII)
  28. GMAC3: GPHY0 (MII) or GPHY3 (GMII)
  29. GMAC4: GPHY1 (GMII)
  30. GMAC5: GPHY1 (MII), RGMII or RMII port
  31. Tested on D-Link DWR966 (xRX330) with OpenWRT.
  32. Signed-off-by: Aleksander Jan Bajkowski <[email protected]>
  33. Acked-by: Hauke Mehrtens <[email protected]>
  34. Signed-off-by: David S. Miller <[email protected]>
  35. ---
  36. drivers/net/dsa/lantiq_gswip.c | 142 ++++++++++++++++++++++++++-------
  37. 1 file changed, 113 insertions(+), 29 deletions(-)
  38. --- a/drivers/net/dsa/lantiq_gswip.c
  39. +++ b/drivers/net/dsa/lantiq_gswip.c
  40. @@ -1,6 +1,6 @@
  41. // SPDX-License-Identifier: GPL-2.0
  42. /*
  43. - * Lantiq / Intel GSWIP switch driver for VRX200 SoCs
  44. + * Lantiq / Intel GSWIP switch driver for VRX200, xRX300 and xRX330 SoCs
  45. *
  46. * Copyright (C) 2010 Lantiq Deutschland
  47. * Copyright (C) 2012 John Crispin <[email protected]>
  48. @@ -104,6 +104,7 @@
  49. #define GSWIP_MII_CFG_MODE_RMIIP 0x2
  50. #define GSWIP_MII_CFG_MODE_RMIIM 0x3
  51. #define GSWIP_MII_CFG_MODE_RGMII 0x4
  52. +#define GSWIP_MII_CFG_MODE_GMII 0x9
  53. #define GSWIP_MII_CFG_MODE_MASK 0xf
  54. #define GSWIP_MII_CFG_RATE_M2P5 0x00
  55. #define GSWIP_MII_CFG_RATE_M25 0x10
  56. @@ -241,6 +242,7 @@
  57. struct gswip_hw_info {
  58. int max_ports;
  59. int cpu_port;
  60. + const struct dsa_switch_ops *ops;
  61. };
  62. struct xway_gphy_match_data {
  63. @@ -1438,12 +1440,42 @@ static int gswip_port_fdb_dump(struct ds
  64. return 0;
  65. }
  66. -static void gswip_phylink_validate(struct dsa_switch *ds, int port,
  67. - unsigned long *supported,
  68. - struct phylink_link_state *state)
  69. +static void gswip_phylink_set_capab(unsigned long *supported,
  70. + struct phylink_link_state *state)
  71. {
  72. __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
  73. + /* Allow all the expected bits */
  74. + phylink_set(mask, Autoneg);
  75. + phylink_set_port_modes(mask);
  76. + phylink_set(mask, Pause);
  77. + phylink_set(mask, Asym_Pause);
  78. +
  79. + /* With the exclusion of MII, Reverse MII and Reduced MII, we
  80. + * support Gigabit, including Half duplex
  81. + */
  82. + if (state->interface != PHY_INTERFACE_MODE_MII &&
  83. + state->interface != PHY_INTERFACE_MODE_REVMII &&
  84. + state->interface != PHY_INTERFACE_MODE_RMII) {
  85. + phylink_set(mask, 1000baseT_Full);
  86. + phylink_set(mask, 1000baseT_Half);
  87. + }
  88. +
  89. + phylink_set(mask, 10baseT_Half);
  90. + phylink_set(mask, 10baseT_Full);
  91. + phylink_set(mask, 100baseT_Half);
  92. + phylink_set(mask, 100baseT_Full);
  93. +
  94. + bitmap_and(supported, supported, mask,
  95. + __ETHTOOL_LINK_MODE_MASK_NBITS);
  96. + bitmap_and(state->advertising, state->advertising, mask,
  97. + __ETHTOOL_LINK_MODE_MASK_NBITS);
  98. +}
  99. +
  100. +static void gswip_xrx200_phylink_validate(struct dsa_switch *ds, int port,
  101. + unsigned long *supported,
  102. + struct phylink_link_state *state)
  103. +{
  104. switch (port) {
  105. case 0:
  106. case 1:
  107. @@ -1470,38 +1502,54 @@ static void gswip_phylink_validate(struc
  108. return;
  109. }
  110. - /* Allow all the expected bits */
  111. - phylink_set(mask, Autoneg);
  112. - phylink_set_port_modes(mask);
  113. - phylink_set(mask, Pause);
  114. - phylink_set(mask, Asym_Pause);
  115. + gswip_phylink_set_capab(supported, state);
  116. - /* With the exclusion of MII, Reverse MII and Reduced MII, we
  117. - * support Gigabit, including Half duplex
  118. - */
  119. - if (state->interface != PHY_INTERFACE_MODE_MII &&
  120. - state->interface != PHY_INTERFACE_MODE_REVMII &&
  121. - state->interface != PHY_INTERFACE_MODE_RMII) {
  122. - phylink_set(mask, 1000baseT_Full);
  123. - phylink_set(mask, 1000baseT_Half);
  124. + return;
  125. +
  126. +unsupported:
  127. + bitmap_zero(supported, __ETHTOOL_LINK_MODE_MASK_NBITS);
  128. + dev_err(ds->dev, "Unsupported interface '%s' for port %d\n",
  129. + phy_modes(state->interface), port);
  130. +}
  131. +
  132. +static void gswip_xrx300_phylink_validate(struct dsa_switch *ds, int port,
  133. + unsigned long *supported,
  134. + struct phylink_link_state *state)
  135. +{
  136. + switch (port) {
  137. + case 0:
  138. + if (!phy_interface_mode_is_rgmii(state->interface) &&
  139. + state->interface != PHY_INTERFACE_MODE_GMII &&
  140. + state->interface != PHY_INTERFACE_MODE_RMII)
  141. + goto unsupported;
  142. + break;
  143. + case 1:
  144. + case 2:
  145. + case 3:
  146. + case 4:
  147. + if (state->interface != PHY_INTERFACE_MODE_INTERNAL)
  148. + goto unsupported;
  149. + break;
  150. + case 5:
  151. + if (!phy_interface_mode_is_rgmii(state->interface) &&
  152. + state->interface != PHY_INTERFACE_MODE_INTERNAL &&
  153. + state->interface != PHY_INTERFACE_MODE_RMII)
  154. + goto unsupported;
  155. + break;
  156. + default:
  157. + bitmap_zero(supported, __ETHTOOL_LINK_MODE_MASK_NBITS);
  158. + dev_err(ds->dev, "Unsupported port: %i\n", port);
  159. + return;
  160. }
  161. - phylink_set(mask, 10baseT_Half);
  162. - phylink_set(mask, 10baseT_Full);
  163. - phylink_set(mask, 100baseT_Half);
  164. - phylink_set(mask, 100baseT_Full);
  165. + gswip_phylink_set_capab(supported, state);
  166. - bitmap_and(supported, supported, mask,
  167. - __ETHTOOL_LINK_MODE_MASK_NBITS);
  168. - bitmap_and(state->advertising, state->advertising, mask,
  169. - __ETHTOOL_LINK_MODE_MASK_NBITS);
  170. return;
  171. unsupported:
  172. bitmap_zero(supported, __ETHTOOL_LINK_MODE_MASK_NBITS);
  173. dev_err(ds->dev, "Unsupported interface '%s' for port %d\n",
  174. phy_modes(state->interface), port);
  175. - return;
  176. }
  177. static void gswip_port_set_link(struct gswip_priv *priv, int port, bool link)
  178. @@ -1636,6 +1684,9 @@ static void gswip_phylink_mac_config(str
  179. case PHY_INTERFACE_MODE_RGMII_TXID:
  180. miicfg |= GSWIP_MII_CFG_MODE_RGMII;
  181. break;
  182. + case PHY_INTERFACE_MODE_GMII:
  183. + miicfg |= GSWIP_MII_CFG_MODE_GMII;
  184. + break;
  185. default:
  186. dev_err(ds->dev,
  187. "Unsupported interface: %d\n", state->interface);
  188. @@ -1762,7 +1813,7 @@ static int gswip_get_sset_count(struct d
  189. return ARRAY_SIZE(gswip_rmon_cnt);
  190. }
  191. -static const struct dsa_switch_ops gswip_switch_ops = {
  192. +static const struct dsa_switch_ops gswip_xrx200_switch_ops = {
  193. .get_tag_protocol = gswip_get_tag_protocol,
  194. .setup = gswip_setup,
  195. .port_enable = gswip_port_enable,
  196. @@ -1778,7 +1829,31 @@ static const struct dsa_switch_ops gswip
  197. .port_fdb_add = gswip_port_fdb_add,
  198. .port_fdb_del = gswip_port_fdb_del,
  199. .port_fdb_dump = gswip_port_fdb_dump,
  200. - .phylink_validate = gswip_phylink_validate,
  201. + .phylink_validate = gswip_xrx200_phylink_validate,
  202. + .phylink_mac_config = gswip_phylink_mac_config,
  203. + .phylink_mac_link_down = gswip_phylink_mac_link_down,
  204. + .phylink_mac_link_up = gswip_phylink_mac_link_up,
  205. + .get_strings = gswip_get_strings,
  206. + .get_ethtool_stats = gswip_get_ethtool_stats,
  207. + .get_sset_count = gswip_get_sset_count,
  208. +};
  209. +
  210. +static const struct dsa_switch_ops gswip_xrx300_switch_ops = {
  211. + .get_tag_protocol = gswip_get_tag_protocol,
  212. + .setup = gswip_setup,
  213. + .port_enable = gswip_port_enable,
  214. + .port_disable = gswip_port_disable,
  215. + .port_bridge_join = gswip_port_bridge_join,
  216. + .port_bridge_leave = gswip_port_bridge_leave,
  217. + .port_fast_age = gswip_port_fast_age,
  218. + .port_vlan_filtering = gswip_port_vlan_filtering,
  219. + .port_vlan_add = gswip_port_vlan_add,
  220. + .port_vlan_del = gswip_port_vlan_del,
  221. + .port_stp_state_set = gswip_port_stp_state_set,
  222. + .port_fdb_add = gswip_port_fdb_add,
  223. + .port_fdb_del = gswip_port_fdb_del,
  224. + .port_fdb_dump = gswip_port_fdb_dump,
  225. + .phylink_validate = gswip_xrx300_phylink_validate,
  226. .phylink_mac_config = gswip_phylink_mac_config,
  227. .phylink_mac_link_down = gswip_phylink_mac_link_down,
  228. .phylink_mac_link_up = gswip_phylink_mac_link_up,
  229. @@ -2042,7 +2117,7 @@ static int gswip_probe(struct platform_d
  230. priv->ds->dev = dev;
  231. priv->ds->num_ports = priv->hw_info->max_ports;
  232. priv->ds->priv = priv;
  233. - priv->ds->ops = &gswip_switch_ops;
  234. + priv->ds->ops = priv->hw_info->ops;
  235. priv->dev = dev;
  236. version = gswip_switch_r(priv, GSWIP_VERSION);
  237. @@ -2126,10 +2201,19 @@ static int gswip_remove(struct platform_
  238. static const struct gswip_hw_info gswip_xrx200 = {
  239. .max_ports = 7,
  240. .cpu_port = 6,
  241. + .ops = &gswip_xrx200_switch_ops,
  242. +};
  243. +
  244. +static const struct gswip_hw_info gswip_xrx300 = {
  245. + .max_ports = 7,
  246. + .cpu_port = 6,
  247. + .ops = &gswip_xrx300_switch_ops,
  248. };
  249. static const struct of_device_id gswip_of_match[] = {
  250. { .compatible = "lantiq,xrx200-gswip", .data = &gswip_xrx200 },
  251. + { .compatible = "lantiq,xrx300-gswip", .data = &gswip_xrx300 },
  252. + { .compatible = "lantiq,xrx330-gswip", .data = &gswip_xrx300 },
  253. {},
  254. };
  255. MODULE_DEVICE_TABLE(of, gswip_of_match);