101-16-net-mediatek-connect-switch-to-PSE-only-when-startin.patch 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. From a0405999ebecf21ed9f76f1dc9420682cd3feba0 Mon Sep 17 00:00:00 2001
  2. From: Weijie Gao <[email protected]>
  3. Date: Wed, 19 Jul 2023 17:16:54 +0800
  4. Subject: [PATCH 16/29] net: mediatek: connect switch to PSE only when starting
  5. eth is requested
  6. So far the switch is initialized in probe stage and is connected to PSE
  7. unconditionally. This will cause all packets being flooded to PSE and may
  8. cause PSE hang before entering linux.
  9. This patch changes the connection between switch and PSE:
  10. - Still initialize switch in probe stage, but disconnect it with PSE
  11. - Connect switch with PSE on eth start
  12. - Disconnect on eth stop
  13. Signed-off-by: Weijie Gao <[email protected]>
  14. ---
  15. drivers/net/mtk_eth.c | 44 ++++++++++++++++++++++++++++++++++++++++---
  16. 1 file changed, 41 insertions(+), 3 deletions(-)
  17. --- a/drivers/net/mtk_eth.c
  18. +++ b/drivers/net/mtk_eth.c
  19. @@ -123,8 +123,10 @@ struct mtk_eth_priv {
  20. enum mtk_switch sw;
  21. int (*switch_init)(struct mtk_eth_priv *priv);
  22. + void (*switch_mac_control)(struct mtk_eth_priv *priv, bool enable);
  23. u32 mt753x_smi_addr;
  24. u32 mt753x_phy_base;
  25. + u32 mt753x_pmcr;
  26. struct gpio_desc rst_gpio;
  27. int mcm;
  28. @@ -613,6 +615,16 @@ static int mt7530_pad_clk_setup(struct m
  29. return 0;
  30. }
  31. +static void mt7530_mac_control(struct mtk_eth_priv *priv, bool enable)
  32. +{
  33. + u32 pmcr = FORCE_MODE;
  34. +
  35. + if (enable)
  36. + pmcr = priv->mt753x_pmcr;
  37. +
  38. + mt753x_reg_write(priv, PMCR_REG(6), pmcr);
  39. +}
  40. +
  41. static int mt7530_setup(struct mtk_eth_priv *priv)
  42. {
  43. u16 phy_addr, phy_val;
  44. @@ -663,11 +675,14 @@ static int mt7530_setup(struct mtk_eth_p
  45. FORCE_DPX | FORCE_LINK;
  46. /* MT7530 Port6: Forced 1000M/FD, FC disabled */
  47. - mt753x_reg_write(priv, PMCR_REG(6), val);
  48. + priv->mt753x_pmcr = val;
  49. /* MT7530 Port5: Forced link down */
  50. mt753x_reg_write(priv, PMCR_REG(5), FORCE_MODE);
  51. + /* Keep MAC link down before starting eth */
  52. + mt753x_reg_write(priv, PMCR_REG(6), FORCE_MODE);
  53. +
  54. /* MT7530 Port6: Set to RGMII */
  55. mt753x_reg_rmw(priv, MT7530_P6ECR, P6_INTF_MODE_M, P6_INTF_MODE_RGMII);
  56. @@ -823,6 +838,17 @@ static void mt7531_phy_setting(struct mt
  57. }
  58. }
  59. +static void mt7531_mac_control(struct mtk_eth_priv *priv, bool enable)
  60. +{
  61. + u32 pmcr = FORCE_MODE_LNK;
  62. +
  63. + if (enable)
  64. + pmcr = priv->mt753x_pmcr;
  65. +
  66. + mt753x_reg_write(priv, PMCR_REG(5), pmcr);
  67. + mt753x_reg_write(priv, PMCR_REG(6), pmcr);
  68. +}
  69. +
  70. static int mt7531_setup(struct mtk_eth_priv *priv)
  71. {
  72. u16 phy_addr, phy_val;
  73. @@ -882,8 +908,11 @@ static int mt7531_setup(struct mtk_eth_p
  74. (SPEED_1000M << FORCE_SPD_S) | FORCE_DPX |
  75. FORCE_LINK;
  76. - mt753x_reg_write(priv, PMCR_REG(5), pmcr);
  77. - mt753x_reg_write(priv, PMCR_REG(6), pmcr);
  78. + priv->mt753x_pmcr = pmcr;
  79. +
  80. + /* Keep MAC link down before starting eth */
  81. + mt753x_reg_write(priv, PMCR_REG(5), FORCE_MODE_LNK);
  82. + mt753x_reg_write(priv, PMCR_REG(6), FORCE_MODE_LNK);
  83. /* Turn on PHYs */
  84. for (i = 0; i < MT753X_NUM_PHYS; i++) {
  85. @@ -1227,6 +1256,9 @@ static int mtk_eth_start(struct udevice
  86. mtk_eth_fifo_init(priv);
  87. + if (priv->switch_mac_control)
  88. + priv->switch_mac_control(priv, true);
  89. +
  90. /* Start PHY */
  91. if (priv->sw == SW_NONE) {
  92. ret = mtk_phy_start(priv);
  93. @@ -1245,6 +1277,9 @@ static void mtk_eth_stop(struct udevice
  94. {
  95. struct mtk_eth_priv *priv = dev_get_priv(dev);
  96. + if (priv->switch_mac_control)
  97. + priv->switch_mac_control(priv, false);
  98. +
  99. mtk_pdma_rmw(priv, PDMA_GLO_CFG_REG,
  100. TX_WB_DDONE | RX_DMA_EN | TX_DMA_EN, 0);
  101. udelay(500);
  102. @@ -1484,16 +1519,19 @@ static int mtk_eth_of_to_plat(struct ude
  103. /* check for switch first, otherwise phy will be used */
  104. priv->sw = SW_NONE;
  105. priv->switch_init = NULL;
  106. + priv->switch_mac_control = NULL;
  107. str = dev_read_string(dev, "mediatek,switch");
  108. if (str) {
  109. if (!strcmp(str, "mt7530")) {
  110. priv->sw = SW_MT7530;
  111. priv->switch_init = mt7530_setup;
  112. + priv->switch_mac_control = mt7530_mac_control;
  113. priv->mt753x_smi_addr = MT753X_DFL_SMI_ADDR;
  114. } else if (!strcmp(str, "mt7531")) {
  115. priv->sw = SW_MT7531;
  116. priv->switch_init = mt7531_setup;
  117. + priv->switch_mac_control = mt7531_mac_control;
  118. priv->mt753x_smi_addr = MT753X_DFL_SMI_ADDR;
  119. } else {
  120. printf("error: unsupported switch\n");