a39a55b89b4b6b1a229d9c801de3069ae3e35f79
[openwrt/staging/blogic.git] /
1 From fce1ec0c4e2d03d9c62ffc615a42bdba78eb4c14 Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Wed, 27 Jul 2022 13:35:15 +0200
4 Subject: [PATCH 06/14] net: dsa: qca8k: move mib init function to common code
5
6 The same mib function is used by drivers based on qca8k family switch.
7 Move it to common code to make it accessible also by other drivers.
8
9 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
10 Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
11 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
12 ---
13 drivers/net/dsa/qca/qca8k-8xxx.c | 37 ------------------------------
14 drivers/net/dsa/qca/qca8k-common.c | 35 ++++++++++++++++++++++++++++
15 drivers/net/dsa/qca/qca8k.h | 4 ++++
16 3 files changed, 39 insertions(+), 37 deletions(-)
17
18 --- a/drivers/net/dsa/qca/qca8k-8xxx.c
19 +++ b/drivers/net/dsa/qca/qca8k-8xxx.c
20 @@ -442,15 +442,6 @@ static struct regmap_config qca8k_regmap
21 };
22
23 static int
24 -qca8k_busy_wait(struct qca8k_priv *priv, u32 reg, u32 mask)
25 -{
26 - u32 val;
27 -
28 - return regmap_read_poll_timeout(priv->regmap, reg, val, !(val & mask), 0,
29 - QCA8K_BUSY_WAIT_TIMEOUT * USEC_PER_MSEC);
30 -}
31 -
32 -static int
33 qca8k_fdb_read(struct qca8k_priv *priv, struct qca8k_fdb *fdb)
34 {
35 u32 reg[3];
36 @@ -777,34 +768,6 @@ out:
37 return ret;
38 }
39
40 -static int
41 -qca8k_mib_init(struct qca8k_priv *priv)
42 -{
43 - int ret;
44 -
45 - mutex_lock(&priv->reg_mutex);
46 - ret = regmap_update_bits(priv->regmap, QCA8K_REG_MIB,
47 - QCA8K_MIB_FUNC | QCA8K_MIB_BUSY,
48 - FIELD_PREP(QCA8K_MIB_FUNC, QCA8K_MIB_FLUSH) |
49 - QCA8K_MIB_BUSY);
50 - if (ret)
51 - goto exit;
52 -
53 - ret = qca8k_busy_wait(priv, QCA8K_REG_MIB, QCA8K_MIB_BUSY);
54 - if (ret)
55 - goto exit;
56 -
57 - ret = regmap_set_bits(priv->regmap, QCA8K_REG_MIB, QCA8K_MIB_CPU_KEEP);
58 - if (ret)
59 - goto exit;
60 -
61 - ret = qca8k_write(priv, QCA8K_REG_MODULE_EN, QCA8K_MODULE_EN_MIB);
62 -
63 -exit:
64 - mutex_unlock(&priv->reg_mutex);
65 - return ret;
66 -}
67 -
68 static void
69 qca8k_port_set_status(struct qca8k_priv *priv, int port, int enable)
70 {
71 --- a/drivers/net/dsa/qca/qca8k-common.c
72 +++ b/drivers/net/dsa/qca/qca8k-common.c
73 @@ -7,6 +7,7 @@
74 */
75
76 #include <linux/netdevice.h>
77 +#include <linux/bitfield.h>
78 #include <net/dsa.h>
79
80 #include "qca8k.h"
81 @@ -138,3 +139,38 @@ int qca8k_bulk_write(struct qca8k_priv *
82
83 return 0;
84 }
85 +
86 +int qca8k_busy_wait(struct qca8k_priv *priv, u32 reg, u32 mask)
87 +{
88 + u32 val;
89 +
90 + return regmap_read_poll_timeout(priv->regmap, reg, val, !(val & mask), 0,
91 + QCA8K_BUSY_WAIT_TIMEOUT * USEC_PER_MSEC);
92 +}
93 +
94 +int qca8k_mib_init(struct qca8k_priv *priv)
95 +{
96 + int ret;
97 +
98 + mutex_lock(&priv->reg_mutex);
99 + ret = regmap_update_bits(priv->regmap, QCA8K_REG_MIB,
100 + QCA8K_MIB_FUNC | QCA8K_MIB_BUSY,
101 + FIELD_PREP(QCA8K_MIB_FUNC, QCA8K_MIB_FLUSH) |
102 + QCA8K_MIB_BUSY);
103 + if (ret)
104 + goto exit;
105 +
106 + ret = qca8k_busy_wait(priv, QCA8K_REG_MIB, QCA8K_MIB_BUSY);
107 + if (ret)
108 + goto exit;
109 +
110 + ret = regmap_set_bits(priv->regmap, QCA8K_REG_MIB, QCA8K_MIB_CPU_KEEP);
111 + if (ret)
112 + goto exit;
113 +
114 + ret = qca8k_write(priv, QCA8K_REG_MODULE_EN, QCA8K_MODULE_EN_MIB);
115 +
116 +exit:
117 + mutex_unlock(&priv->reg_mutex);
118 + return ret;
119 +}
120 --- a/drivers/net/dsa/qca/qca8k.h
121 +++ b/drivers/net/dsa/qca/qca8k.h
122 @@ -422,6 +422,7 @@ struct qca8k_fdb {
123 /* Common setup function */
124 extern const struct qca8k_mib_desc ar8327_mib[];
125 extern const struct regmap_access_table qca8k_readable_table;
126 +int qca8k_mib_init(struct qca8k_priv *priv);
127
128 /* Common read/write/rmw function */
129 int qca8k_read(struct qca8k_priv *priv, u32 reg, u32 *val);
130 @@ -431,4 +432,7 @@ int qca8k_rmw(struct qca8k_priv *priv, u
131 int qca8k_bulk_read(struct qca8k_priv *priv, u32 reg, u32 *val, int len);
132 int qca8k_bulk_write(struct qca8k_priv *priv, u32 reg, u32 *val, int len);
133
134 +/* Common ops function */
135 +int qca8k_busy_wait(struct qca8k_priv *priv, u32 reg, u32 mask);
136 +
137 #endif /* __QCA8K_H */