790-v6.4-0010-net-dsa-mt7530-split-off-common-parts-from-mt7531_se.patch 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. From 7f54cc9772ced2d76ac11832f0ada43798443ac9 Mon Sep 17 00:00:00 2001
  2. From: Daniel Golle <[email protected]>
  3. Date: Mon, 3 Apr 2023 02:19:02 +0100
  4. Subject: [PATCH 13/16] net: dsa: mt7530: split-off common parts from
  5. mt7531_setup
  6. MT7988 shares a significant part of the setup function with MT7531.
  7. Split-off those parts into a shared function which is going to be used
  8. also by mt7988_setup.
  9. Signed-off-by: Daniel Golle <[email protected]>
  10. Reviewed-by: Andrew Lunn <[email protected]>
  11. Signed-off-by: David S. Miller <[email protected]>
  12. ---
  13. drivers/net/dsa/mt7530.c | 99 ++++++++++++++++++++++------------------
  14. 1 file changed, 55 insertions(+), 44 deletions(-)
  15. --- a/drivers/net/dsa/mt7530.c
  16. +++ b/drivers/net/dsa/mt7530.c
  17. @@ -2348,11 +2348,64 @@ mt7530_setup(struct dsa_switch *ds)
  18. }
  19. static int
  20. +mt7531_setup_common(struct dsa_switch *ds)
  21. +{
  22. + struct mt7530_priv *priv = ds->priv;
  23. + struct dsa_port *cpu_dp;
  24. + int ret, i;
  25. +
  26. + /* BPDU to CPU port */
  27. + dsa_switch_for_each_cpu_port(cpu_dp, ds) {
  28. + mt7530_rmw(priv, MT7531_CFC, MT7531_CPU_PMAP_MASK,
  29. + BIT(cpu_dp->index));
  30. + break;
  31. + }
  32. + mt7530_rmw(priv, MT753X_BPC, MT753X_BPDU_PORT_FW_MASK,
  33. + MT753X_BPDU_CPU_ONLY);
  34. +
  35. + /* Enable and reset MIB counters */
  36. + mt7530_mib_reset(ds);
  37. +
  38. + for (i = 0; i < MT7530_NUM_PORTS; i++) {
  39. + /* Disable forwarding by default on all ports */
  40. + mt7530_rmw(priv, MT7530_PCR_P(i), PCR_MATRIX_MASK,
  41. + PCR_MATRIX_CLR);
  42. +
  43. + /* Disable learning by default on all ports */
  44. + mt7530_set(priv, MT7530_PSC_P(i), SA_DIS);
  45. +
  46. + mt7530_set(priv, MT7531_DBG_CNT(i), MT7531_DIS_CLR);
  47. +
  48. + if (dsa_is_cpu_port(ds, i)) {
  49. + ret = mt753x_cpu_port_enable(ds, i);
  50. + if (ret)
  51. + return ret;
  52. + } else {
  53. + mt7530_port_disable(ds, i);
  54. +
  55. + /* Set default PVID to 0 on all user ports */
  56. + mt7530_rmw(priv, MT7530_PPBV1_P(i), G0_PORT_VID_MASK,
  57. + G0_PORT_VID_DEF);
  58. + }
  59. +
  60. + /* Enable consistent egress tag */
  61. + mt7530_rmw(priv, MT7530_PVC_P(i), PVC_EG_TAG_MASK,
  62. + PVC_EG_TAG(MT7530_VLAN_EG_CONSISTENT));
  63. + }
  64. +
  65. + /* Flush the FDB table */
  66. + ret = mt7530_fdb_cmd(priv, MT7530_FDB_FLUSH, NULL);
  67. + if (ret < 0)
  68. + return ret;
  69. +
  70. + return 0;
  71. +}
  72. +
  73. +static int
  74. mt7531_setup(struct dsa_switch *ds)
  75. {
  76. struct mt7530_priv *priv = ds->priv;
  77. struct mt7530_dummy_poll p;
  78. - struct dsa_port *cpu_dp;
  79. u32 val, id;
  80. int ret, i;
  81. @@ -2426,44 +2479,7 @@ mt7531_setup(struct dsa_switch *ds)
  82. mt7531_ind_c45_phy_write(priv, MT753X_CTRL_PHY_ADDR, MDIO_MMD_VEND2,
  83. CORE_PLL_GROUP4, val);
  84. - /* BPDU to CPU port */
  85. - dsa_switch_for_each_cpu_port(cpu_dp, ds) {
  86. - mt7530_rmw(priv, MT7531_CFC, MT7531_CPU_PMAP_MASK,
  87. - BIT(cpu_dp->index));
  88. - break;
  89. - }
  90. - mt7530_rmw(priv, MT753X_BPC, MT753X_BPDU_PORT_FW_MASK,
  91. - MT753X_BPDU_CPU_ONLY);
  92. -
  93. - /* Enable and reset MIB counters */
  94. - mt7530_mib_reset(ds);
  95. -
  96. - for (i = 0; i < MT7530_NUM_PORTS; i++) {
  97. - /* Disable forwarding by default on all ports */
  98. - mt7530_rmw(priv, MT7530_PCR_P(i), PCR_MATRIX_MASK,
  99. - PCR_MATRIX_CLR);
  100. -
  101. - /* Disable learning by default on all ports */
  102. - mt7530_set(priv, MT7530_PSC_P(i), SA_DIS);
  103. -
  104. - mt7530_set(priv, MT7531_DBG_CNT(i), MT7531_DIS_CLR);
  105. -
  106. - if (dsa_is_cpu_port(ds, i)) {
  107. - ret = mt753x_cpu_port_enable(ds, i);
  108. - if (ret)
  109. - return ret;
  110. - } else {
  111. - mt7530_port_disable(ds, i);
  112. -
  113. - /* Set default PVID to 0 on all user ports */
  114. - mt7530_rmw(priv, MT7530_PPBV1_P(i), G0_PORT_VID_MASK,
  115. - G0_PORT_VID_DEF);
  116. - }
  117. -
  118. - /* Enable consistent egress tag */
  119. - mt7530_rmw(priv, MT7530_PVC_P(i), PVC_EG_TAG_MASK,
  120. - PVC_EG_TAG(MT7530_VLAN_EG_CONSISTENT));
  121. - }
  122. + mt7531_setup_common(ds);
  123. /* Setup VLAN ID 0 for VLAN-unaware bridges */
  124. ret = mt7530_setup_vlan0(priv);
  125. @@ -2473,11 +2489,6 @@ mt7531_setup(struct dsa_switch *ds)
  126. ds->assisted_learning_on_cpu_port = true;
  127. ds->mtu_enforcement_ingress = true;
  128. - /* Flush the FDB table */
  129. - ret = mt7530_fdb_cmd(priv, MT7530_FDB_FLUSH, NULL);
  130. - if (ret < 0)
  131. - return ret;
  132. -
  133. return 0;
  134. }