747-v5.16-06-net-dsa-qca8k-rework-rgmii-delay-logic-and-scan-for-.patch 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. From 5654ec78dd7e64b1e04777b24007344329e6a63b Mon Sep 17 00:00:00 2001
  2. From: Ansuel Smith <[email protected]>
  3. Date: Thu, 14 Oct 2021 00:39:11 +0200
  4. Subject: net: dsa: qca8k: rework rgmii delay logic and scan for cpu port 6
  5. Future proof commit. This switch have 2 CPU ports and one valid
  6. configuration is first CPU port set to sgmii and second CPU port set to
  7. rgmii-id. The current implementation detects delay only for CPU port
  8. zero set to rgmii and doesn't count any delay set in a secondary CPU
  9. port. Drop the current delay scan function and move it to the sgmii
  10. parser function to generalize and implicitly add support for secondary
  11. CPU port set to rgmii-id. Introduce new logic where delay is enabled
  12. also with internal delay binding declared and rgmii set as PHY mode.
  13. Signed-off-by: Ansuel Smith <[email protected]>
  14. Signed-off-by: David S. Miller <[email protected]>
  15. ---
  16. drivers/net/dsa/qca8k.c | 165 ++++++++++++++++++++++++------------------------
  17. drivers/net/dsa/qca8k.h | 10 ++-
  18. 2 files changed, 89 insertions(+), 86 deletions(-)
  19. --- a/drivers/net/dsa/qca8k.c
  20. +++ b/drivers/net/dsa/qca8k.c
  21. @@ -889,68 +889,6 @@ qca8k_setup_mdio_bus(struct qca8k_priv *
  22. }
  23. static int
  24. -qca8k_setup_of_rgmii_delay(struct qca8k_priv *priv)
  25. -{
  26. - struct device_node *port_dn;
  27. - phy_interface_t mode;
  28. - struct dsa_port *dp;
  29. - u32 val;
  30. -
  31. - /* CPU port is already checked */
  32. - dp = dsa_to_port(priv->ds, 0);
  33. -
  34. - port_dn = dp->dn;
  35. -
  36. - /* Check if port 0 is set to the correct type */
  37. - of_get_phy_mode(port_dn, &mode);
  38. - if (mode != PHY_INTERFACE_MODE_RGMII_ID &&
  39. - mode != PHY_INTERFACE_MODE_RGMII_RXID &&
  40. - mode != PHY_INTERFACE_MODE_RGMII_TXID) {
  41. - return 0;
  42. - }
  43. -
  44. - switch (mode) {
  45. - case PHY_INTERFACE_MODE_RGMII_ID:
  46. - case PHY_INTERFACE_MODE_RGMII_RXID:
  47. - if (of_property_read_u32(port_dn, "rx-internal-delay-ps", &val))
  48. - val = 2;
  49. - else
  50. - /* Switch regs accept value in ns, convert ps to ns */
  51. - val = val / 1000;
  52. -
  53. - if (val > QCA8K_MAX_DELAY) {
  54. - dev_err(priv->dev, "rgmii rx delay is limited to a max value of 3ns, setting to the max value");
  55. - val = 3;
  56. - }
  57. -
  58. - priv->rgmii_rx_delay = val;
  59. - /* Stop here if we need to check only for rx delay */
  60. - if (mode != PHY_INTERFACE_MODE_RGMII_ID)
  61. - break;
  62. -
  63. - fallthrough;
  64. - case PHY_INTERFACE_MODE_RGMII_TXID:
  65. - if (of_property_read_u32(port_dn, "tx-internal-delay-ps", &val))
  66. - val = 1;
  67. - else
  68. - /* Switch regs accept value in ns, convert ps to ns */
  69. - val = val / 1000;
  70. -
  71. - if (val > QCA8K_MAX_DELAY) {
  72. - dev_err(priv->dev, "rgmii tx delay is limited to a max value of 3ns, setting to the max value");
  73. - val = 3;
  74. - }
  75. -
  76. - priv->rgmii_tx_delay = val;
  77. - break;
  78. - default:
  79. - return 0;
  80. - }
  81. -
  82. - return 0;
  83. -}
  84. -
  85. -static int
  86. qca8k_setup_mac_pwr_sel(struct qca8k_priv *priv)
  87. {
  88. u32 mask = 0;
  89. @@ -996,19 +934,21 @@ static int qca8k_find_cpu_port(struct ds
  90. static int
  91. qca8k_parse_port_config(struct qca8k_priv *priv)
  92. {
  93. + int port, cpu_port_index = 0, ret;
  94. struct device_node *port_dn;
  95. phy_interface_t mode;
  96. struct dsa_port *dp;
  97. - int port, ret;
  98. + u32 delay;
  99. /* We have 2 CPU port. Check them */
  100. - for (port = 0; port < QCA8K_NUM_PORTS; port++) {
  101. + for (port = 0; port < QCA8K_NUM_PORTS && cpu_port_index < QCA8K_NUM_CPU_PORTS; port++) {
  102. /* Skip every other port */
  103. if (port != 0 && port != 6)
  104. continue;
  105. dp = dsa_to_port(priv->ds, port);
  106. port_dn = dp->dn;
  107. + cpu_port_index++;
  108. if (!of_device_is_available(port_dn))
  109. continue;
  110. @@ -1017,12 +957,54 @@ qca8k_parse_port_config(struct qca8k_pri
  111. if (ret)
  112. continue;
  113. - if (mode == PHY_INTERFACE_MODE_SGMII) {
  114. + switch (mode) {
  115. + case PHY_INTERFACE_MODE_RGMII:
  116. + case PHY_INTERFACE_MODE_RGMII_ID:
  117. + case PHY_INTERFACE_MODE_RGMII_TXID:
  118. + case PHY_INTERFACE_MODE_RGMII_RXID:
  119. + delay = 0;
  120. +
  121. + if (!of_property_read_u32(port_dn, "tx-internal-delay-ps", &delay))
  122. + /* Switch regs accept value in ns, convert ps to ns */
  123. + delay = delay / 1000;
  124. + else if (mode == PHY_INTERFACE_MODE_RGMII_ID ||
  125. + mode == PHY_INTERFACE_MODE_RGMII_TXID)
  126. + delay = 1;
  127. +
  128. + if (delay > QCA8K_MAX_DELAY) {
  129. + dev_err(priv->dev, "rgmii tx delay is limited to a max value of 3ns, setting to the max value");
  130. + delay = 3;
  131. + }
  132. +
  133. + priv->rgmii_tx_delay[cpu_port_index] = delay;
  134. +
  135. + delay = 0;
  136. +
  137. + if (!of_property_read_u32(port_dn, "rx-internal-delay-ps", &delay))
  138. + /* Switch regs accept value in ns, convert ps to ns */
  139. + delay = delay / 1000;
  140. + else if (mode == PHY_INTERFACE_MODE_RGMII_ID ||
  141. + mode == PHY_INTERFACE_MODE_RGMII_RXID)
  142. + delay = 2;
  143. +
  144. + if (delay > QCA8K_MAX_DELAY) {
  145. + dev_err(priv->dev, "rgmii rx delay is limited to a max value of 3ns, setting to the max value");
  146. + delay = 3;
  147. + }
  148. +
  149. + priv->rgmii_rx_delay[cpu_port_index] = delay;
  150. +
  151. + break;
  152. + case PHY_INTERFACE_MODE_SGMII:
  153. if (of_property_read_bool(port_dn, "qca,sgmii-txclk-falling-edge"))
  154. priv->sgmii_tx_clk_falling_edge = true;
  155. if (of_property_read_bool(port_dn, "qca,sgmii-rxclk-falling-edge"))
  156. priv->sgmii_rx_clk_falling_edge = true;
  157. +
  158. + break;
  159. + default:
  160. + continue;
  161. }
  162. }
  163. @@ -1059,10 +1041,6 @@ qca8k_setup(struct dsa_switch *ds)
  164. if (ret)
  165. return ret;
  166. - ret = qca8k_setup_of_rgmii_delay(priv);
  167. - if (ret)
  168. - return ret;
  169. -
  170. ret = qca8k_setup_mac_pwr_sel(priv);
  171. if (ret)
  172. return ret;
  173. @@ -1229,8 +1207,8 @@ qca8k_phylink_mac_config(struct dsa_swit
  174. const struct phylink_link_state *state)
  175. {
  176. struct qca8k_priv *priv = ds->priv;
  177. - u32 reg, val;
  178. - int ret;
  179. + int cpu_port_index, ret;
  180. + u32 reg, val, delay;
  181. switch (port) {
  182. case 0: /* 1st CPU port */
  183. @@ -1242,6 +1220,7 @@ qca8k_phylink_mac_config(struct dsa_swit
  184. return;
  185. reg = QCA8K_REG_PORT0_PAD_CTRL;
  186. + cpu_port_index = QCA8K_CPU_PORT0;
  187. break;
  188. case 1:
  189. case 2:
  190. @@ -1260,6 +1239,7 @@ qca8k_phylink_mac_config(struct dsa_swit
  191. return;
  192. reg = QCA8K_REG_PORT6_PAD_CTRL;
  193. + cpu_port_index = QCA8K_CPU_PORT6;
  194. break;
  195. default:
  196. dev_err(ds->dev, "%s: unsupported port: %i\n", __func__, port);
  197. @@ -1274,23 +1254,40 @@ qca8k_phylink_mac_config(struct dsa_swit
  198. switch (state->interface) {
  199. case PHY_INTERFACE_MODE_RGMII:
  200. - /* RGMII mode means no delay so don't enable the delay */
  201. - qca8k_write(priv, reg, QCA8K_PORT_PAD_RGMII_EN);
  202. - break;
  203. case PHY_INTERFACE_MODE_RGMII_ID:
  204. case PHY_INTERFACE_MODE_RGMII_TXID:
  205. case PHY_INTERFACE_MODE_RGMII_RXID:
  206. - /* RGMII_ID needs internal delay. This is enabled through
  207. - * PORT5_PAD_CTRL for all ports, rather than individual port
  208. - * registers
  209. + val = QCA8K_PORT_PAD_RGMII_EN;
  210. +
  211. + /* Delay can be declared in 3 different way.
  212. + * Mode to rgmii and internal-delay standard binding defined
  213. + * rgmii-id or rgmii-tx/rx phy mode set.
  214. + * The parse logic set a delay different than 0 only when one
  215. + * of the 3 different way is used. In all other case delay is
  216. + * not enabled. With ID or TX/RXID delay is enabled and set
  217. + * to the default and recommended value.
  218. + */
  219. + if (priv->rgmii_tx_delay[cpu_port_index]) {
  220. + delay = priv->rgmii_tx_delay[cpu_port_index];
  221. +
  222. + val |= QCA8K_PORT_PAD_RGMII_TX_DELAY(delay) |
  223. + QCA8K_PORT_PAD_RGMII_TX_DELAY_EN;
  224. + }
  225. +
  226. + if (priv->rgmii_rx_delay[cpu_port_index]) {
  227. + delay = priv->rgmii_rx_delay[cpu_port_index];
  228. +
  229. + val |= QCA8K_PORT_PAD_RGMII_RX_DELAY(delay) |
  230. + QCA8K_PORT_PAD_RGMII_RX_DELAY_EN;
  231. + }
  232. +
  233. + /* Set RGMII delay based on the selected values */
  234. + qca8k_write(priv, reg, val);
  235. +
  236. + /* QCA8337 requires to set rgmii rx delay for all ports.
  237. + * This is enabled through PORT5_PAD_CTRL for all ports,
  238. + * rather than individual port registers.
  239. */
  240. - qca8k_write(priv, reg,
  241. - QCA8K_PORT_PAD_RGMII_EN |
  242. - QCA8K_PORT_PAD_RGMII_TX_DELAY(priv->rgmii_tx_delay) |
  243. - QCA8K_PORT_PAD_RGMII_RX_DELAY(priv->rgmii_rx_delay) |
  244. - QCA8K_PORT_PAD_RGMII_TX_DELAY_EN |
  245. - QCA8K_PORT_PAD_RGMII_RX_DELAY_EN);
  246. - /* QCA8337 requires to set rgmii rx delay */
  247. if (priv->switch_id == QCA8K_ID_QCA8337)
  248. qca8k_write(priv, QCA8K_REG_PORT5_PAD_CTRL,
  249. QCA8K_PORT_PAD_RGMII_RX_DELAY_EN);
  250. --- a/drivers/net/dsa/qca8k.h
  251. +++ b/drivers/net/dsa/qca8k.h
  252. @@ -13,6 +13,7 @@
  253. #include <linux/gpio.h>
  254. #define QCA8K_NUM_PORTS 7
  255. +#define QCA8K_NUM_CPU_PORTS 2
  256. #define QCA8K_MAX_MTU 9000
  257. #define PHY_ID_QCA8327 0x004dd034
  258. @@ -255,13 +256,18 @@ struct qca8k_match_data {
  259. u8 id;
  260. };
  261. +enum {
  262. + QCA8K_CPU_PORT0,
  263. + QCA8K_CPU_PORT6,
  264. +};
  265. +
  266. struct qca8k_priv {
  267. u8 switch_id;
  268. u8 switch_revision;
  269. - u8 rgmii_tx_delay;
  270. - u8 rgmii_rx_delay;
  271. bool sgmii_rx_clk_falling_edge;
  272. bool sgmii_tx_clk_falling_edge;
  273. + u8 rgmii_rx_delay[QCA8K_NUM_CPU_PORTS]; /* 0: CPU port0, 1: CPU port6 */
  274. + u8 rgmii_tx_delay[QCA8K_NUM_CPU_PORTS]; /* 0: CPU port0, 1: CPU port6 */
  275. bool legacy_phy_port_mapping;
  276. struct regmap *regmap;
  277. struct mii_bus *bus;