733-v6.3-16-net-ethernet-mtk_eth_soc-only-write-values-if-needed.patch 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. From 6e933a804c7db8be64f367f33e63cd7dcc302ebb Mon Sep 17 00:00:00 2001
  2. From: Daniel Golle <[email protected]>
  3. Date: Tue, 14 Mar 2023 00:34:45 +0000
  4. Subject: [PATCH 2/2] net: ethernet: mtk_eth_soc: only write values if needed
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. Only restart auto-negotiation and write link timer if actually
  9. necessary. This prevents losing the link in case of minor
  10. changes.
  11. Fixes: 7e538372694b ("net: ethernet: mediatek: Re-add support SGMII")
  12. Reviewed-by: Russell King (Oracle) <[email protected]>
  13. Tested-by: Bjørn Mork <[email protected]>
  14. Signed-off-by: Daniel Golle <[email protected]>
  15. Signed-off-by: David S. Miller <[email protected]>
  16. ---
  17. drivers/net/ethernet/mediatek/mtk_sgmii.c | 24 +++++++++++------------
  18. 1 file changed, 12 insertions(+), 12 deletions(-)
  19. --- a/drivers/net/ethernet/mediatek/mtk_sgmii.c
  20. +++ b/drivers/net/ethernet/mediatek/mtk_sgmii.c
  21. @@ -38,20 +38,16 @@ static int mtk_pcs_config(struct phylink
  22. const unsigned long *advertising,
  23. bool permit_pause_to_mac)
  24. {
  25. + bool mode_changed = false, changed, use_an;
  26. struct mtk_pcs *mpcs = pcs_to_mtk_pcs(pcs);
  27. unsigned int rgc3, sgm_mode, bmcr;
  28. int advertise, link_timer;
  29. - bool changed, use_an;
  30. advertise = phylink_mii_c22_pcs_encode_advertisement(interface,
  31. advertising);
  32. if (advertise < 0)
  33. return advertise;
  34. - link_timer = phylink_get_link_timer_ns(interface);
  35. - if (link_timer < 0)
  36. - return link_timer;
  37. -
  38. /* Clearing IF_MODE_BIT0 switches the PCS to BASE-X mode, and
  39. * we assume that fixes it's speed at bitrate = line rate (in
  40. * other words, 1000Mbps or 2500Mbps).
  41. @@ -77,13 +73,16 @@ static int mtk_pcs_config(struct phylink
  42. }
  43. if (use_an) {
  44. - /* FIXME: Do we need to set AN_RESTART here? */
  45. - bmcr = SGMII_AN_RESTART | SGMII_AN_ENABLE;
  46. + bmcr = SGMII_AN_ENABLE;
  47. } else {
  48. bmcr = 0;
  49. }
  50. if (mpcs->interface != interface) {
  51. + link_timer = phylink_get_link_timer_ns(interface);
  52. + if (link_timer < 0)
  53. + return link_timer;
  54. +
  55. /* PHYA power down */
  56. regmap_update_bits(mpcs->regmap, SGMSYS_QPHY_PWR_STATE_CTRL,
  57. SGMII_PHYA_PWD, SGMII_PHYA_PWD);
  58. @@ -101,16 +100,17 @@ static int mtk_pcs_config(struct phylink
  59. regmap_update_bits(mpcs->regmap, mpcs->ana_rgc3,
  60. RG_PHY_SPEED_3_125G, rgc3);
  61. + /* Setup the link timer */
  62. + regmap_write(mpcs->regmap, SGMSYS_PCS_LINK_TIMER, link_timer / 2 / 8);
  63. +
  64. mpcs->interface = interface;
  65. + mode_changed = true;
  66. }
  67. /* Update the advertisement, noting whether it has changed */
  68. regmap_update_bits_check(mpcs->regmap, SGMSYS_PCS_ADVERTISE,
  69. SGMII_ADVERTISE, advertise, &changed);
  70. - /* Setup the link timer and QPHY power up inside SGMIISYS */
  71. - regmap_write(mpcs->regmap, SGMSYS_PCS_LINK_TIMER, link_timer / 2 / 8);
  72. -
  73. /* Update the sgmsys mode register */
  74. regmap_update_bits(mpcs->regmap, SGMSYS_SGMII_MODE,
  75. SGMII_REMOTE_FAULT_DIS | SGMII_SPEED_DUPLEX_AN |
  76. @@ -118,7 +118,7 @@ static int mtk_pcs_config(struct phylink
  77. /* Update the BMCR */
  78. regmap_update_bits(mpcs->regmap, SGMSYS_PCS_CONTROL_1,
  79. - SGMII_AN_RESTART | SGMII_AN_ENABLE, bmcr);
  80. + SGMII_AN_ENABLE, bmcr);
  81. /* Release PHYA power down state
  82. * Only removing bit SGMII_PHYA_PWD isn't enough.
  83. @@ -132,7 +132,7 @@ static int mtk_pcs_config(struct phylink
  84. usleep_range(50, 100);
  85. regmap_write(mpcs->regmap, SGMSYS_QPHY_PWR_STATE_CTRL, 0);
  86. - return changed;
  87. + return changed || mode_changed;
  88. }
  89. static void mtk_pcs_restart_an(struct phylink_pcs *pcs)