generic: 5.15: qca8k: refresh backport patches
[openwrt/staging/ldir.git] / target / linux / generic / backport-5.15 / 760-net-next-net-dsa-qca8k-add-set_ageing_time-support.patch
1 From 6a3bdc5209f45d2af83aa92433ab6e5cf2297aa4 Mon Sep 17 00:00:00 2001
2 From: Ansuel Smith <ansuelsmth@gmail.com>
3 Date: Mon, 22 Nov 2021 16:23:47 +0100
4 Subject: net: dsa: qca8k: add set_ageing_time support
5
6 qca8k support setting ageing time in step of 7s. Add support for it and
7 set the max value accepted of 7645m.
8 Documentation talks about support for 10000m but that values doesn't
9 make sense as the value doesn't match the max value in the reg.
10
11 Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
12 Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
13 Signed-off-by: David S. Miller <davem@davemloft.net>
14 ---
15 drivers/net/dsa/qca8k.c | 25 +++++++++++++++++++++++++
16 drivers/net/dsa/qca8k.h | 3 +++
17 2 files changed, 28 insertions(+)
18
19 diff --git a/drivers/net/dsa/qca8k.c b/drivers/net/dsa/qca8k.c
20 index d988df913ae02..45e769b9166b8 100644
21 --- a/drivers/net/dsa/qca8k.c
22 +++ b/drivers/net/dsa/qca8k.c
23 @@ -1257,6 +1257,10 @@ qca8k_setup(struct dsa_switch *ds)
24 /* We don't have interrupts for link changes, so we need to poll */
25 ds->pcs_poll = true;
26
27 + /* Set min a max ageing value supported */
28 + ds->ageing_time_min = 7000;
29 + ds->ageing_time_max = 458745000;
30 +
31 return 0;
32 }
33
34 @@ -1796,6 +1800,26 @@ qca8k_port_fast_age(struct dsa_switch *ds, int port)
35 mutex_unlock(&priv->reg_mutex);
36 }
37
38 +static int
39 +qca8k_set_ageing_time(struct dsa_switch *ds, unsigned int msecs)
40 +{
41 + struct qca8k_priv *priv = ds->priv;
42 + unsigned int secs = msecs / 1000;
43 + u32 val;
44 +
45 + /* AGE_TIME reg is set in 7s step */
46 + val = secs / 7;
47 +
48 + /* Handle case with 0 as val to NOT disable
49 + * learning
50 + */
51 + if (!val)
52 + val = 1;
53 +
54 + return regmap_update_bits(priv->regmap, QCA8K_REG_ATU_CTRL, QCA8K_ATU_AGE_TIME_MASK,
55 + QCA8K_ATU_AGE_TIME(val));
56 +}
57 +
58 static int
59 qca8k_port_enable(struct dsa_switch *ds, int port,
60 struct phy_device *phy)
61 @@ -1995,6 +2019,7 @@ static const struct dsa_switch_ops qca8k_switch_ops = {
62 .get_strings = qca8k_get_strings,
63 .get_ethtool_stats = qca8k_get_ethtool_stats,
64 .get_sset_count = qca8k_get_sset_count,
65 + .set_ageing_time = qca8k_set_ageing_time,
66 .get_mac_eee = qca8k_get_mac_eee,
67 .set_mac_eee = qca8k_set_mac_eee,
68 .port_enable = qca8k_port_enable,
69 diff --git a/drivers/net/dsa/qca8k.h b/drivers/net/dsa/qca8k.h
70 index a533b8cf143be..40ec8012622f7 100644
71 --- a/drivers/net/dsa/qca8k.h
72 +++ b/drivers/net/dsa/qca8k.h
73 @@ -175,6 +175,9 @@
74 #define QCA8K_VTU_FUNC1_BUSY BIT(31)
75 #define QCA8K_VTU_FUNC1_VID_MASK GENMASK(27, 16)
76 #define QCA8K_VTU_FUNC1_FULL BIT(4)
77 +#define QCA8K_REG_ATU_CTRL 0x618
78 +#define QCA8K_ATU_AGE_TIME_MASK GENMASK(15, 0)
79 +#define QCA8K_ATU_AGE_TIME(x) FIELD_PREP(QCA8K_ATU_AGE_TIME_MASK, (x))
80 #define QCA8K_REG_GLOBAL_FW_CTRL0 0x620
81 #define QCA8K_GLOBAL_FW_CTRL0_CPU_PORT_EN BIT(10)
82 #define QCA8K_REG_GLOBAL_FW_CTRL1 0x624
83 --
84 cgit 1.2.3-1.el7
85