749-v5.16-net-dsa-qca8k-tidy-for-loop-in-setup-and-add-cpu-port-c.patch 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. From 040e926f5813a5f4cc18dbff7c942d1e52f368f2 Mon Sep 17 00:00:00 2001
  2. From: Ansuel Smith <[email protected]>
  3. Date: Tue, 19 Oct 2021 02:08:50 +0200
  4. Subject: net: dsa: qca8k: tidy for loop in setup and add cpu port check
  5. Tidy and organize qca8k setup function from multiple for loop.
  6. Change for loop in bridge leave/join to scan all port and skip cpu port.
  7. No functional change intended.
  8. Signed-off-by: Ansuel Smith <[email protected]>
  9. Signed-off-by: David S. Miller <[email protected]>
  10. ---
  11. drivers/net/dsa/qca8k.c | 74 +++++++++++++++++++++++++++++--------------------
  12. 1 file changed, 44 insertions(+), 30 deletions(-)
  13. --- a/drivers/net/dsa/qca8k.c
  14. +++ b/drivers/net/dsa/qca8k.c
  15. @@ -1122,28 +1122,34 @@ qca8k_setup(struct dsa_switch *ds)
  16. if (ret)
  17. dev_warn(priv->dev, "mib init failed");
  18. - /* Enable QCA header mode on the cpu port */
  19. - ret = qca8k_write(priv, QCA8K_REG_PORT_HDR_CTRL(cpu_port),
  20. - QCA8K_PORT_HDR_CTRL_ALL << QCA8K_PORT_HDR_CTRL_TX_S |
  21. - QCA8K_PORT_HDR_CTRL_ALL << QCA8K_PORT_HDR_CTRL_RX_S);
  22. - if (ret) {
  23. - dev_err(priv->dev, "failed enabling QCA header mode");
  24. - return ret;
  25. - }
  26. -
  27. - /* Disable forwarding by default on all ports */
  28. + /* Initial setup of all ports */
  29. for (i = 0; i < QCA8K_NUM_PORTS; i++) {
  30. + /* Disable forwarding by default on all ports */
  31. ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(i),
  32. QCA8K_PORT_LOOKUP_MEMBER, 0);
  33. if (ret)
  34. return ret;
  35. - }
  36. - /* Disable MAC by default on all ports */
  37. - for (i = 1; i < QCA8K_NUM_PORTS; i++)
  38. - qca8k_port_set_status(priv, i, 0);
  39. + /* Enable QCA header mode on all cpu ports */
  40. + if (dsa_is_cpu_port(ds, i)) {
  41. + ret = qca8k_write(priv, QCA8K_REG_PORT_HDR_CTRL(i),
  42. + QCA8K_PORT_HDR_CTRL_ALL << QCA8K_PORT_HDR_CTRL_TX_S |
  43. + QCA8K_PORT_HDR_CTRL_ALL << QCA8K_PORT_HDR_CTRL_RX_S);
  44. + if (ret) {
  45. + dev_err(priv->dev, "failed enabling QCA header mode");
  46. + return ret;
  47. + }
  48. + }
  49. +
  50. + /* Disable MAC by default on all user ports */
  51. + if (dsa_is_user_port(ds, i))
  52. + qca8k_port_set_status(priv, i, 0);
  53. + }
  54. - /* Forward all unknown frames to CPU port for Linux processing */
  55. + /* Forward all unknown frames to CPU port for Linux processing
  56. + * Notice that in multi-cpu config only one port should be set
  57. + * for igmp, unknown, multicast and broadcast packet
  58. + */
  59. ret = qca8k_write(priv, QCA8K_REG_GLOBAL_FW_CTRL1,
  60. BIT(cpu_port) << QCA8K_GLOBAL_FW_CTRL1_IGMP_DP_S |
  61. BIT(cpu_port) << QCA8K_GLOBAL_FW_CTRL1_BC_DP_S |
  62. @@ -1152,11 +1158,13 @@ qca8k_setup(struct dsa_switch *ds)
  63. if (ret)
  64. return ret;
  65. - /* Setup connection between CPU port & user ports */
  66. + /* Setup connection between CPU port & user ports
  67. + * Configure specific switch configuration for ports
  68. + */
  69. for (i = 0; i < QCA8K_NUM_PORTS; i++) {
  70. /* CPU port gets connected to all user ports of the switch */
  71. if (dsa_is_cpu_port(ds, i)) {
  72. - ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(cpu_port),
  73. + ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(i),
  74. QCA8K_PORT_LOOKUP_MEMBER, dsa_user_ports(ds));
  75. if (ret)
  76. return ret;
  77. @@ -1193,16 +1201,14 @@ qca8k_setup(struct dsa_switch *ds)
  78. if (ret)
  79. return ret;
  80. }
  81. - }
  82. - /* The port 5 of the qca8337 have some problem in flood condition. The
  83. - * original legacy driver had some specific buffer and priority settings
  84. - * for the different port suggested by the QCA switch team. Add this
  85. - * missing settings to improve switch stability under load condition.
  86. - * This problem is limited to qca8337 and other qca8k switch are not affected.
  87. - */
  88. - if (priv->switch_id == QCA8K_ID_QCA8337) {
  89. - for (i = 0; i < QCA8K_NUM_PORTS; i++) {
  90. + /* The port 5 of the qca8337 have some problem in flood condition. The
  91. + * original legacy driver had some specific buffer and priority settings
  92. + * for the different port suggested by the QCA switch team. Add this
  93. + * missing settings to improve switch stability under load condition.
  94. + * This problem is limited to qca8337 and other qca8k switch are not affected.
  95. + */
  96. + if (priv->switch_id == QCA8K_ID_QCA8337) {
  97. switch (i) {
  98. /* The 2 CPU port and port 5 requires some different
  99. * priority than any other ports.
  100. @@ -1238,6 +1244,12 @@ qca8k_setup(struct dsa_switch *ds)
  101. QCA8K_PORT_HOL_CTRL1_WRED_EN,
  102. mask);
  103. }
  104. +
  105. + /* Set initial MTU for every port.
  106. + * We have only have a general MTU setting. So track
  107. + * every port and set the max across all port.
  108. + */
  109. + priv->port_mtu[i] = ETH_FRAME_LEN + ETH_FCS_LEN;
  110. }
  111. /* Special GLOBAL_FC_THRESH value are needed for ar8327 switch */
  112. @@ -1251,8 +1263,6 @@ qca8k_setup(struct dsa_switch *ds)
  113. }
  114. /* Setup our port MTUs to match power on defaults */
  115. - for (i = 0; i < QCA8K_NUM_PORTS; i++)
  116. - priv->port_mtu[i] = ETH_FRAME_LEN + ETH_FCS_LEN;
  117. ret = qca8k_write(priv, QCA8K_MAX_FRAME_SIZE, ETH_FRAME_LEN + ETH_FCS_LEN);
  118. if (ret)
  119. dev_warn(priv->dev, "failed setting MTU settings");
  120. @@ -1728,7 +1738,9 @@ qca8k_port_bridge_join(struct dsa_switch
  121. cpu_port = dsa_to_port(ds, port)->cpu_dp->index;
  122. port_mask = BIT(cpu_port);
  123. - for (i = 1; i < QCA8K_NUM_PORTS; i++) {
  124. + for (i = 0; i < QCA8K_NUM_PORTS; i++) {
  125. + if (dsa_is_cpu_port(ds, i))
  126. + continue;
  127. if (dsa_to_port(ds, i)->bridge_dev != br)
  128. continue;
  129. /* Add this port to the portvlan mask of the other ports
  130. @@ -1758,7 +1770,9 @@ qca8k_port_bridge_leave(struct dsa_switc
  131. cpu_port = dsa_to_port(ds, port)->cpu_dp->index;
  132. - for (i = 1; i < QCA8K_NUM_PORTS; i++) {
  133. + for (i = 0; i < QCA8K_NUM_PORTS; i++) {
  134. + if (dsa_is_cpu_port(ds, i))
  135. + continue;
  136. if (dsa_to_port(ds, i)->bridge_dev != br)
  137. continue;
  138. /* Remove this port to the portvlan mask of the other ports