747-v5.16-05-net-dsa-qca8k-add-support-for-cpu-port-6.patch 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. From 3fcf734aa482487df83cf8f18608438fcf59127f Mon Sep 17 00:00:00 2001
  2. From: Ansuel Smith <[email protected]>
  3. Date: Thu, 14 Oct 2021 00:39:10 +0200
  4. Subject: net: dsa: qca8k: add support for cpu port 6
  5. Currently CPU port is always hardcoded to port 0. This switch have 2 CPU
  6. ports. The original intention of this driver seems to be use the
  7. mac06_exchange bit to swap MAC0 with MAC6 in the strange configuration
  8. where device have connected only the CPU port 6. To skip the
  9. introduction of a new binding, rework the driver to address the
  10. secondary CPU port as primary and drop any reference of hardcoded port.
  11. With configuration of mac06 exchange, just skip the definition of port0
  12. and define the CPU port as a secondary. The driver will autoconfigure
  13. the switch to use that as the primary CPU port.
  14. Signed-off-by: Ansuel Smith <[email protected]>
  15. Signed-off-by: David S. Miller <[email protected]>
  16. ---
  17. drivers/net/dsa/qca8k.c | 51 ++++++++++++++++++++++++++++++++++---------------
  18. drivers/net/dsa/qca8k.h | 2 --
  19. 2 files changed, 36 insertions(+), 17 deletions(-)
  20. --- a/drivers/net/dsa/qca8k.c
  21. +++ b/drivers/net/dsa/qca8k.c
  22. @@ -977,6 +977,22 @@ qca8k_setup_mac_pwr_sel(struct qca8k_pri
  23. return ret;
  24. }
  25. +static int qca8k_find_cpu_port(struct dsa_switch *ds)
  26. +{
  27. + struct qca8k_priv *priv = ds->priv;
  28. +
  29. + /* Find the connected cpu port. Valid port are 0 or 6 */
  30. + if (dsa_is_cpu_port(ds, 0))
  31. + return 0;
  32. +
  33. + dev_dbg(priv->dev, "port 0 is not the CPU port. Checking port 6");
  34. +
  35. + if (dsa_is_cpu_port(ds, 6))
  36. + return 6;
  37. +
  38. + return -EINVAL;
  39. +}
  40. +
  41. static int
  42. qca8k_parse_port_config(struct qca8k_priv *priv)
  43. {
  44. @@ -1017,13 +1033,13 @@ static int
  45. qca8k_setup(struct dsa_switch *ds)
  46. {
  47. struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
  48. - int ret, i;
  49. + int cpu_port, ret, i;
  50. u32 mask;
  51. - /* Make sure that port 0 is the cpu port */
  52. - if (!dsa_is_cpu_port(ds, 0)) {
  53. - dev_err(priv->dev, "port 0 is not the CPU port");
  54. - return -EINVAL;
  55. + cpu_port = qca8k_find_cpu_port(ds);
  56. + if (cpu_port < 0) {
  57. + dev_err(priv->dev, "No cpu port configured in both cpu port0 and port6");
  58. + return cpu_port;
  59. }
  60. /* Parse CPU port config to be later used in phy_link mac_config */
  61. @@ -1065,7 +1081,7 @@ qca8k_setup(struct dsa_switch *ds)
  62. dev_warn(priv->dev, "mib init failed");
  63. /* Enable QCA header mode on the cpu port */
  64. - ret = qca8k_write(priv, QCA8K_REG_PORT_HDR_CTRL(QCA8K_CPU_PORT),
  65. + ret = qca8k_write(priv, QCA8K_REG_PORT_HDR_CTRL(cpu_port),
  66. QCA8K_PORT_HDR_CTRL_ALL << QCA8K_PORT_HDR_CTRL_TX_S |
  67. QCA8K_PORT_HDR_CTRL_ALL << QCA8K_PORT_HDR_CTRL_RX_S);
  68. if (ret) {
  69. @@ -1087,10 +1103,10 @@ qca8k_setup(struct dsa_switch *ds)
  70. /* Forward all unknown frames to CPU port for Linux processing */
  71. ret = qca8k_write(priv, QCA8K_REG_GLOBAL_FW_CTRL1,
  72. - BIT(0) << QCA8K_GLOBAL_FW_CTRL1_IGMP_DP_S |
  73. - BIT(0) << QCA8K_GLOBAL_FW_CTRL1_BC_DP_S |
  74. - BIT(0) << QCA8K_GLOBAL_FW_CTRL1_MC_DP_S |
  75. - BIT(0) << QCA8K_GLOBAL_FW_CTRL1_UC_DP_S);
  76. + BIT(cpu_port) << QCA8K_GLOBAL_FW_CTRL1_IGMP_DP_S |
  77. + BIT(cpu_port) << QCA8K_GLOBAL_FW_CTRL1_BC_DP_S |
  78. + BIT(cpu_port) << QCA8K_GLOBAL_FW_CTRL1_MC_DP_S |
  79. + BIT(cpu_port) << QCA8K_GLOBAL_FW_CTRL1_UC_DP_S);
  80. if (ret)
  81. return ret;
  82. @@ -1098,7 +1114,7 @@ qca8k_setup(struct dsa_switch *ds)
  83. for (i = 0; i < QCA8K_NUM_PORTS; i++) {
  84. /* CPU port gets connected to all user ports of the switch */
  85. if (dsa_is_cpu_port(ds, i)) {
  86. - ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(QCA8K_CPU_PORT),
  87. + ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(cpu_port),
  88. QCA8K_PORT_LOOKUP_MEMBER, dsa_user_ports(ds));
  89. if (ret)
  90. return ret;
  91. @@ -1110,7 +1126,7 @@ qca8k_setup(struct dsa_switch *ds)
  92. ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(i),
  93. QCA8K_PORT_LOOKUP_MEMBER,
  94. - BIT(QCA8K_CPU_PORT));
  95. + BIT(cpu_port));
  96. if (ret)
  97. return ret;
  98. @@ -1616,9 +1632,12 @@ static int
  99. qca8k_port_bridge_join(struct dsa_switch *ds, int port, struct net_device *br)
  100. {
  101. struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
  102. - int port_mask = BIT(QCA8K_CPU_PORT);
  103. + int port_mask, cpu_port;
  104. int i, ret;
  105. + cpu_port = dsa_to_port(ds, port)->cpu_dp->index;
  106. + port_mask = BIT(cpu_port);
  107. +
  108. for (i = 1; i < QCA8K_NUM_PORTS; i++) {
  109. if (dsa_to_port(ds, i)->bridge_dev != br)
  110. continue;
  111. @@ -1645,7 +1664,9 @@ static void
  112. qca8k_port_bridge_leave(struct dsa_switch *ds, int port, struct net_device *br)
  113. {
  114. struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
  115. - int i;
  116. + int cpu_port, i;
  117. +
  118. + cpu_port = dsa_to_port(ds, port)->cpu_dp->index;
  119. for (i = 1; i < QCA8K_NUM_PORTS; i++) {
  120. if (dsa_to_port(ds, i)->bridge_dev != br)
  121. @@ -1662,7 +1683,7 @@ qca8k_port_bridge_leave(struct dsa_switc
  122. * this port
  123. */
  124. qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(port),
  125. - QCA8K_PORT_LOOKUP_MEMBER, BIT(QCA8K_CPU_PORT));
  126. + QCA8K_PORT_LOOKUP_MEMBER, BIT(cpu_port));
  127. }
  128. static int
  129. --- a/drivers/net/dsa/qca8k.h
  130. +++ b/drivers/net/dsa/qca8k.h
  131. @@ -24,8 +24,6 @@
  132. #define QCA8K_NUM_FDB_RECORDS 2048
  133. -#define QCA8K_CPU_PORT 0
  134. -
  135. #define QCA8K_PORT_VID_DEF 1
  136. /* Global control registers */