780-v6.6-04-net-dsa-qca8k-use-dsa_for_each-macro-instead-of-for-.patch 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. From 01e6f8ad8d26ced14b0cf288c42e55d03a7c5070 Mon Sep 17 00:00:00 2001
  2. From: Christian Marangi <[email protected]>
  3. Date: Sun, 30 Jul 2023 09:41:13 +0200
  4. Subject: [PATCH 4/4] net: dsa: qca8k: use dsa_for_each macro instead of for
  5. loop
  6. Convert for loop to dsa_for_each macro to save some redundant write on
  7. unconnected/unused port and tidy things up.
  8. Signed-off-by: Christian Marangi <[email protected]>
  9. Reviewed-by: Florian Fainelli <[email protected]>
  10. Link: https://lore.kernel.org/r/[email protected]
  11. Signed-off-by: Paolo Abeni <[email protected]>
  12. ---
  13. drivers/net/dsa/qca/qca8k-8xxx.c | 107 ++++++++++++++++---------------
  14. 1 file changed, 54 insertions(+), 53 deletions(-)
  15. --- a/drivers/net/dsa/qca/qca8k-8xxx.c
  16. +++ b/drivers/net/dsa/qca/qca8k-8xxx.c
  17. @@ -1828,7 +1828,8 @@ static int
  18. qca8k_setup(struct dsa_switch *ds)
  19. {
  20. struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
  21. - int cpu_port, ret, i;
  22. + struct dsa_port *dp;
  23. + int cpu_port, ret;
  24. u32 mask;
  25. cpu_port = qca8k_find_cpu_port(ds);
  26. @@ -1879,27 +1880,27 @@ qca8k_setup(struct dsa_switch *ds)
  27. dev_warn(priv->dev, "mib init failed");
  28. /* Initial setup of all ports */
  29. - for (i = 0; i < QCA8K_NUM_PORTS; i++) {
  30. + dsa_switch_for_each_port(dp, ds) {
  31. /* Disable forwarding by default on all ports */
  32. - ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(i),
  33. + ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(dp->index),
  34. QCA8K_PORT_LOOKUP_MEMBER, 0);
  35. if (ret)
  36. return ret;
  37. + }
  38. - /* Enable QCA header mode on all cpu ports */
  39. - if (dsa_is_cpu_port(ds, i)) {
  40. - ret = qca8k_write(priv, QCA8K_REG_PORT_HDR_CTRL(i),
  41. - FIELD_PREP(QCA8K_PORT_HDR_CTRL_TX_MASK, QCA8K_PORT_HDR_CTRL_ALL) |
  42. - FIELD_PREP(QCA8K_PORT_HDR_CTRL_RX_MASK, QCA8K_PORT_HDR_CTRL_ALL));
  43. - if (ret) {
  44. - dev_err(priv->dev, "failed enabling QCA header mode");
  45. - return ret;
  46. - }
  47. + /* Disable MAC by default on all user ports */
  48. + dsa_switch_for_each_user_port(dp, ds)
  49. + qca8k_port_set_status(priv, dp->index, 0);
  50. +
  51. + /* Enable QCA header mode on all cpu ports */
  52. + dsa_switch_for_each_cpu_port(dp, ds) {
  53. + ret = qca8k_write(priv, QCA8K_REG_PORT_HDR_CTRL(dp->index),
  54. + FIELD_PREP(QCA8K_PORT_HDR_CTRL_TX_MASK, QCA8K_PORT_HDR_CTRL_ALL) |
  55. + FIELD_PREP(QCA8K_PORT_HDR_CTRL_RX_MASK, QCA8K_PORT_HDR_CTRL_ALL));
  56. + if (ret) {
  57. + dev_err(priv->dev, "failed enabling QCA header mode on port %d", dp->index);
  58. + return ret;
  59. }
  60. -
  61. - /* Disable MAC by default on all user ports */
  62. - if (dsa_is_user_port(ds, i))
  63. - qca8k_port_set_status(priv, i, 0);
  64. }
  65. /* Forward all unknown frames to CPU port for Linux processing
  66. @@ -1921,48 +1922,48 @@ qca8k_setup(struct dsa_switch *ds)
  67. return ret;
  68. /* Setup connection between CPU port & user ports
  69. - * Configure specific switch configuration for ports
  70. + * Individual user ports get connected to CPU port only
  71. */
  72. - for (i = 0; i < QCA8K_NUM_PORTS; i++) {
  73. - /* Individual user ports get connected to CPU port only */
  74. - if (dsa_is_user_port(ds, i)) {
  75. - ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(i),
  76. - QCA8K_PORT_LOOKUP_MEMBER,
  77. - BIT(cpu_port));
  78. - if (ret)
  79. - return ret;
  80. -
  81. - ret = regmap_clear_bits(priv->regmap, QCA8K_PORT_LOOKUP_CTRL(i),
  82. - QCA8K_PORT_LOOKUP_LEARN);
  83. - if (ret)
  84. - return ret;
  85. -
  86. - /* For port based vlans to work we need to set the
  87. - * default egress vid
  88. - */
  89. - ret = qca8k_rmw(priv, QCA8K_EGRESS_VLAN(i),
  90. - QCA8K_EGREES_VLAN_PORT_MASK(i),
  91. - QCA8K_EGREES_VLAN_PORT(i, QCA8K_PORT_VID_DEF));
  92. - if (ret)
  93. - return ret;
  94. -
  95. - ret = qca8k_write(priv, QCA8K_REG_PORT_VLAN_CTRL0(i),
  96. - QCA8K_PORT_VLAN_CVID(QCA8K_PORT_VID_DEF) |
  97. - QCA8K_PORT_VLAN_SVID(QCA8K_PORT_VID_DEF));
  98. - if (ret)
  99. - return ret;
  100. - }
  101. + dsa_switch_for_each_user_port(dp, ds) {
  102. + u8 port = dp->index;
  103. - /* The port 5 of the qca8337 have some problem in flood condition. The
  104. - * original legacy driver had some specific buffer and priority settings
  105. - * for the different port suggested by the QCA switch team. Add this
  106. - * missing settings to improve switch stability under load condition.
  107. - * This problem is limited to qca8337 and other qca8k switch are not affected.
  108. + ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(port),
  109. + QCA8K_PORT_LOOKUP_MEMBER,
  110. + BIT(cpu_port));
  111. + if (ret)
  112. + return ret;
  113. +
  114. + ret = regmap_clear_bits(priv->regmap, QCA8K_PORT_LOOKUP_CTRL(port),
  115. + QCA8K_PORT_LOOKUP_LEARN);
  116. + if (ret)
  117. + return ret;
  118. +
  119. + /* For port based vlans to work we need to set the
  120. + * default egress vid
  121. */
  122. - if (priv->switch_id == QCA8K_ID_QCA8337)
  123. - qca8k_setup_hol_fixup(priv, i);
  124. + ret = qca8k_rmw(priv, QCA8K_EGRESS_VLAN(port),
  125. + QCA8K_EGREES_VLAN_PORT_MASK(port),
  126. + QCA8K_EGREES_VLAN_PORT(port, QCA8K_PORT_VID_DEF));
  127. + if (ret)
  128. + return ret;
  129. +
  130. + ret = qca8k_write(priv, QCA8K_REG_PORT_VLAN_CTRL0(port),
  131. + QCA8K_PORT_VLAN_CVID(QCA8K_PORT_VID_DEF) |
  132. + QCA8K_PORT_VLAN_SVID(QCA8K_PORT_VID_DEF));
  133. + if (ret)
  134. + return ret;
  135. }
  136. + /* The port 5 of the qca8337 have some problem in flood condition. The
  137. + * original legacy driver had some specific buffer and priority settings
  138. + * for the different port suggested by the QCA switch team. Add this
  139. + * missing settings to improve switch stability under load condition.
  140. + * This problem is limited to qca8337 and other qca8k switch are not affected.
  141. + */
  142. + if (priv->switch_id == QCA8K_ID_QCA8337)
  143. + dsa_switch_for_each_available_port(dp, ds)
  144. + qca8k_setup_hol_fixup(priv, dp->index);
  145. +
  146. /* Special GLOBAL_FC_THRESH value are needed for ar8327 switch */
  147. if (priv->switch_id == QCA8K_ID_QCA8327) {
  148. mask = QCA8K_GLOBAL_FC_GOL_XON_THRES(288) |