764-v5.11-net-dsa-mt7530-support-setting-ageing-time.patch 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. From ea6d5c924e391872d402acac38461a5f8261e57f Mon Sep 17 00:00:00 2001
  2. From: DENG Qingfang <[email protected]>
  3. Date: Tue, 8 Dec 2020 15:00:28 +0800
  4. Subject: [PATCH] net: dsa: mt7530: support setting ageing time
  5. MT7530 has a global address age control register, so use it to set
  6. ageing time.
  7. The applied timer is (AGE_CNT + 1) * (AGE_UNIT + 1) seconds
  8. Signed-off-by: DENG Qingfang <[email protected]>
  9. Reviewed-by: Andrew Lunn <[email protected]>
  10. Reviewed-by: Vladimir Oltean <[email protected]>
  11. Reviewed-by: Florian Fainelli <[email protected]>
  12. Signed-off-by: David S. Miller <[email protected]>
  13. ---
  14. drivers/net/dsa/mt7530.c | 41 ++++++++++++++++++++++++++++++++++++++++
  15. drivers/net/dsa/mt7530.h | 13 +++++++++++++
  16. 2 files changed, 54 insertions(+)
  17. --- a/drivers/net/dsa/mt7530.c
  18. +++ b/drivers/net/dsa/mt7530.c
  19. @@ -870,6 +870,46 @@ mt7530_get_sset_count(struct dsa_switch
  20. return ARRAY_SIZE(mt7530_mib);
  21. }
  22. +static int
  23. +mt7530_set_ageing_time(struct dsa_switch *ds, unsigned int msecs)
  24. +{
  25. + struct mt7530_priv *priv = ds->priv;
  26. + unsigned int secs = msecs / 1000;
  27. + unsigned int tmp_age_count;
  28. + unsigned int error = -1;
  29. + unsigned int age_count;
  30. + unsigned int age_unit;
  31. +
  32. + /* Applied timer is (AGE_CNT + 1) * (AGE_UNIT + 1) seconds */
  33. + if (secs < 1 || secs > (AGE_CNT_MAX + 1) * (AGE_UNIT_MAX + 1))
  34. + return -ERANGE;
  35. +
  36. + /* iterate through all possible age_count to find the closest pair */
  37. + for (tmp_age_count = 0; tmp_age_count <= AGE_CNT_MAX; ++tmp_age_count) {
  38. + unsigned int tmp_age_unit = secs / (tmp_age_count + 1) - 1;
  39. +
  40. + if (tmp_age_unit <= AGE_UNIT_MAX) {
  41. + unsigned int tmp_error = secs -
  42. + (tmp_age_count + 1) * (tmp_age_unit + 1);
  43. +
  44. + /* found a closer pair */
  45. + if (error > tmp_error) {
  46. + error = tmp_error;
  47. + age_count = tmp_age_count;
  48. + age_unit = tmp_age_unit;
  49. + }
  50. +
  51. + /* found the exact match, so break the loop */
  52. + if (!error)
  53. + break;
  54. + }
  55. + }
  56. +
  57. + mt7530_write(priv, MT7530_AAC, AGE_CNT(age_count) | AGE_UNIT(age_unit));
  58. +
  59. + return 0;
  60. +}
  61. +
  62. static void mt7530_setup_port5(struct dsa_switch *ds, phy_interface_t interface)
  63. {
  64. struct mt7530_priv *priv = ds->priv;
  65. @@ -2694,6 +2734,7 @@ static const struct dsa_switch_ops mt753
  66. .phy_write = mt753x_phy_write,
  67. .get_ethtool_stats = mt7530_get_ethtool_stats,
  68. .get_sset_count = mt7530_get_sset_count,
  69. + .set_ageing_time = mt7530_set_ageing_time,
  70. .port_enable = mt7530_port_enable,
  71. .port_disable = mt7530_port_disable,
  72. .port_change_mtu = mt7530_port_change_mtu,
  73. --- a/drivers/net/dsa/mt7530.h
  74. +++ b/drivers/net/dsa/mt7530.h
  75. @@ -161,6 +161,19 @@ enum mt7530_vlan_egress_attr {
  76. MT7530_VLAN_EGRESS_STACK = 3,
  77. };
  78. +/* Register for address age control */
  79. +#define MT7530_AAC 0xa0
  80. +/* Disable ageing */
  81. +#define AGE_DIS BIT(20)
  82. +/* Age count */
  83. +#define AGE_CNT_MASK GENMASK(19, 12)
  84. +#define AGE_CNT_MAX 0xff
  85. +#define AGE_CNT(x) (AGE_CNT_MASK & ((x) << 12))
  86. +/* Age unit */
  87. +#define AGE_UNIT_MASK GENMASK(11, 0)
  88. +#define AGE_UNIT_MAX 0xfff
  89. +#define AGE_UNIT(x) (AGE_UNIT_MASK & (x))
  90. +
  91. /* Register for port STP state control */
  92. #define MT7530_SSP_P(x) (0x2000 + ((x) * 0x100))
  93. #define FID_PST(x) ((x) & 0x3)