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
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.
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>
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(-)
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
24 -qca8k_busy_wait(struct qca8k_priv *priv, u32 reg, u32 mask)
28 - return regmap_read_poll_timeout(priv->regmap, reg, val, !(val & mask), 0,
29 - QCA8K_BUSY_WAIT_TIMEOUT * USEC_PER_MSEC);
33 qca8k_fdb_read(struct qca8k_priv *priv, struct qca8k_fdb *fdb)
36 @@ -777,34 +768,6 @@ out:
41 -qca8k_mib_init(struct qca8k_priv *priv)
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) |
53 - ret = qca8k_busy_wait(priv, QCA8K_REG_MIB, QCA8K_MIB_BUSY);
57 - ret = regmap_set_bits(priv->regmap, QCA8K_REG_MIB, QCA8K_MIB_CPU_KEEP);
61 - ret = qca8k_write(priv, QCA8K_REG_MODULE_EN, QCA8K_MODULE_EN_MIB);
64 - mutex_unlock(&priv->reg_mutex);
69 qca8k_port_set_status(struct qca8k_priv *priv, int port, int enable)
71 --- a/drivers/net/dsa/qca/qca8k-common.c
72 +++ b/drivers/net/dsa/qca/qca8k-common.c
76 #include <linux/netdevice.h>
77 +#include <linux/bitfield.h>
81 @@ -138,3 +139,38 @@ int qca8k_bulk_write(struct qca8k_priv *
86 +int qca8k_busy_wait(struct qca8k_priv *priv, u32 reg, u32 mask)
90 + return regmap_read_poll_timeout(priv->regmap, reg, val, !(val & mask), 0,
91 + QCA8K_BUSY_WAIT_TIMEOUT * USEC_PER_MSEC);
94 +int qca8k_mib_init(struct qca8k_priv *priv)
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) |
106 + ret = qca8k_busy_wait(priv, QCA8K_REG_MIB, QCA8K_MIB_BUSY);
110 + ret = regmap_set_bits(priv->regmap, QCA8K_REG_MIB, QCA8K_MIB_CPU_KEEP);
114 + ret = qca8k_write(priv, QCA8K_REG_MODULE_EN, QCA8K_MODULE_EN_MIB);
117 + mutex_unlock(&priv->reg_mutex);
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);
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);
134 +/* Common ops function */
135 +int qca8k_busy_wait(struct qca8k_priv *priv, u32 reg, u32 mask);
137 #endif /* __QCA8K_H */