731-v5.13-net-dsa-mt7530-Add-support-for-EEE-features.patch 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. From 40b5d2f15c091fa9c854acde91ad2acb504027d7 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Ren=C3=A9=20van=20Dorst?= <[email protected]>
  3. Date: Mon, 12 Apr 2021 08:50:31 +0200
  4. Subject: [PATCH] net: dsa: mt7530: Add support for EEE features
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. This patch adds EEE support.
  9. Signed-off-by: René van Dorst <[email protected]>
  10. Signed-off-by: David S. Miller <[email protected]>
  11. ---
  12. drivers/net/dsa/mt7530.c | 43 ++++++++++++++++++++++++++++++++++++++++
  13. drivers/net/dsa/mt7530.h | 14 ++++++++++++-
  14. 2 files changed, 56 insertions(+), 1 deletion(-)
  15. --- a/drivers/net/dsa/mt7530.c
  16. +++ b/drivers/net/dsa/mt7530.c
  17. @@ -2366,6 +2366,17 @@ static void mt753x_phylink_mac_link_up(s
  18. mcr |= PMCR_RX_FC_EN;
  19. }
  20. + if (mode == MLO_AN_PHY && phydev && phy_init_eee(phydev, 0) >= 0) {
  21. + switch (speed) {
  22. + case SPEED_1000:
  23. + mcr |= PMCR_FORCE_EEE1G;
  24. + break;
  25. + case SPEED_100:
  26. + mcr |= PMCR_FORCE_EEE100;
  27. + break;
  28. + }
  29. + }
  30. +
  31. mt7530_set(priv, MT7530_PMCR_P(port), mcr);
  32. }
  33. @@ -2596,6 +2607,36 @@ mt753x_phy_write(struct dsa_switch *ds,
  34. return priv->info->phy_write(ds, port, regnum, val);
  35. }
  36. +static int mt753x_get_mac_eee(struct dsa_switch *ds, int port,
  37. + struct ethtool_eee *e)
  38. +{
  39. + struct mt7530_priv *priv = ds->priv;
  40. + u32 eeecr = mt7530_read(priv, MT7530_PMEEECR_P(port));
  41. +
  42. + e->tx_lpi_enabled = !(eeecr & LPI_MODE_EN);
  43. + e->tx_lpi_timer = GET_LPI_THRESH(eeecr);
  44. +
  45. + return 0;
  46. +}
  47. +
  48. +static int mt753x_set_mac_eee(struct dsa_switch *ds, int port,
  49. + struct ethtool_eee *e)
  50. +{
  51. + struct mt7530_priv *priv = ds->priv;
  52. + u32 set, mask = LPI_THRESH_MASK | LPI_MODE_EN;
  53. +
  54. + if (e->tx_lpi_timer > 0xFFF)
  55. + return -EINVAL;
  56. +
  57. + set = SET_LPI_THRESH(e->tx_lpi_timer);
  58. + if (!e->tx_lpi_enabled)
  59. + /* Force LPI Mode without a delay */
  60. + set |= LPI_MODE_EN;
  61. + mt7530_rmw(priv, MT7530_PMEEECR_P(port), mask, set);
  62. +
  63. + return 0;
  64. +}
  65. +
  66. static const struct dsa_switch_ops mt7530_switch_ops = {
  67. .get_tag_protocol = mtk_get_tag_protocol,
  68. .setup = mt753x_setup,
  69. @@ -2624,6 +2665,8 @@ static const struct dsa_switch_ops mt753
  70. .phylink_mac_an_restart = mt753x_phylink_mac_an_restart,
  71. .phylink_mac_link_down = mt753x_phylink_mac_link_down,
  72. .phylink_mac_link_up = mt753x_phylink_mac_link_up,
  73. + .get_mac_eee = mt753x_get_mac_eee,
  74. + .set_mac_eee = mt753x_set_mac_eee,
  75. };
  76. static const struct mt753x_info mt753x_table[] = {
  77. --- a/drivers/net/dsa/mt7530.h
  78. +++ b/drivers/net/dsa/mt7530.h
  79. @@ -240,6 +240,8 @@ enum mt7530_vlan_port_attr {
  80. #define PMCR_RX_EN BIT(13)
  81. #define PMCR_BACKOFF_EN BIT(9)
  82. #define PMCR_BACKPR_EN BIT(8)
  83. +#define PMCR_FORCE_EEE1G BIT(7)
  84. +#define PMCR_FORCE_EEE100 BIT(6)
  85. #define PMCR_TX_FC_EN BIT(5)
  86. #define PMCR_RX_FC_EN BIT(4)
  87. #define PMCR_FORCE_SPEED_1000 BIT(3)
  88. @@ -264,7 +266,8 @@ enum mt7530_vlan_port_attr {
  89. #define PMCR_LINK_SETTINGS_MASK (PMCR_TX_EN | PMCR_FORCE_SPEED_1000 | \
  90. PMCR_RX_EN | PMCR_FORCE_SPEED_100 | \
  91. PMCR_TX_FC_EN | PMCR_RX_FC_EN | \
  92. - PMCR_FORCE_FDX | PMCR_FORCE_LNK)
  93. + PMCR_FORCE_FDX | PMCR_FORCE_LNK | \
  94. + PMCR_FORCE_EEE1G | PMCR_FORCE_EEE100)
  95. #define PMCR_CPU_PORT_SETTING(id) (PMCR_FORCE_MODE_ID((id)) | \
  96. PMCR_IFG_XMIT(1) | PMCR_MAC_MODE | \
  97. PMCR_BACKOFF_EN | PMCR_BACKPR_EN | \
  98. @@ -273,6 +276,15 @@ enum mt7530_vlan_port_attr {
  99. PMCR_FORCE_SPEED_1000 | \
  100. PMCR_FORCE_FDX | PMCR_FORCE_LNK)
  101. +#define MT7530_PMEEECR_P(x) (0x3004 + (x) * 0x100)
  102. +#define WAKEUP_TIME_1000(x) (((x) & 0xFF) << 24)
  103. +#define WAKEUP_TIME_100(x) (((x) & 0xFF) << 16)
  104. +#define LPI_THRESH_MASK GENMASK(15, 4)
  105. +#define LPI_THRESH_SHT 4
  106. +#define SET_LPI_THRESH(x) (((x) << LPI_THRESH_SHT) & LPI_THRESH_MASK)
  107. +#define GET_LPI_THRESH(x) (((x) & LPI_THRESH_MASK) >> LPI_THRESH_SHT)
  108. +#define LPI_MODE_EN BIT(0)
  109. +
  110. #define MT7530_PMSR_P(x) (0x3008 + (x) * 0x100)
  111. #define PMSR_EEE1G BIT(7)
  112. #define PMSR_EEE100M BIT(6)