OSDN Git Service

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