1 From 472fcea160f27a5d9b7526093d9d8d89ba0b6137 Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Wed, 27 Jul 2022 13:35:16 +0200
4 Subject: [PATCH 07/14] net: dsa: qca8k: move port set status/eee/ethtool stats
5 function to common code
7 The same logic to disable/enable port, set eee and get ethtool stats is
8 used by drivers based on qca8k family switch.
9 Move it to common code to make it accessible also by other drivers.
10 While at it also drop unnecessary qca8k_priv cast for void pointers.
12 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
13 Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
14 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
16 drivers/net/dsa/qca/qca8k-8xxx.c | 105 -----------------------------
17 drivers/net/dsa/qca/qca8k-common.c | 102 ++++++++++++++++++++++++++++
18 drivers/net/dsa/qca/qca8k.h | 11 +++
19 3 files changed, 113 insertions(+), 105 deletions(-)
21 --- a/drivers/net/dsa/qca/qca8k-8xxx.c
22 +++ b/drivers/net/dsa/qca/qca8k-8xxx.c
23 @@ -768,21 +768,6 @@ out:
28 -qca8k_port_set_status(struct qca8k_priv *priv, int port, int enable)
30 - u32 mask = QCA8K_PORT_STATUS_TXMAC | QCA8K_PORT_STATUS_RXMAC;
32 - /* Port 0 and 6 have no internal PHY */
33 - if (port > 0 && port < 6)
34 - mask |= QCA8K_PORT_STATUS_LINK_AUTO;
37 - regmap_set_bits(priv->regmap, QCA8K_REG_PORT_STATUS(port), mask);
39 - regmap_clear_bits(priv->regmap, QCA8K_REG_PORT_STATUS(port), mask);
43 qca8k_phy_eth_busy_wait(struct qca8k_mgmt_eth_data *mgmt_eth_data,
44 struct sk_buff *read_skb, u32 *val)
45 @@ -1974,20 +1959,6 @@ qca8k_phylink_mac_link_up(struct dsa_swi
46 qca8k_write(priv, QCA8K_REG_PORT_STATUS(port), reg);
50 -qca8k_get_strings(struct dsa_switch *ds, int port, u32 stringset, uint8_t *data)
52 - struct qca8k_priv *priv = ds->priv;
55 - if (stringset != ETH_SS_STATS)
58 - for (i = 0; i < priv->info->mib_count; i++)
59 - strncpy(data + i * ETH_GSTRING_LEN, ar8327_mib[i].name,
63 static void qca8k_mib_autocast_handler(struct dsa_switch *ds, struct sk_buff *skb)
65 struct qca8k_mib_eth_data *mib_eth_data;
66 @@ -2078,82 +2049,6 @@ exit:
70 -qca8k_get_ethtool_stats(struct dsa_switch *ds, int port,
73 - struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
74 - const struct qca8k_mib_desc *mib;
79 - if (priv->mgmt_master && priv->info->ops->autocast_mib &&
80 - priv->info->ops->autocast_mib(ds, port, data) > 0)
83 - for (i = 0; i < priv->info->mib_count; i++) {
84 - mib = &ar8327_mib[i];
85 - reg = QCA8K_PORT_MIB_COUNTER(port) + mib->offset;
87 - ret = qca8k_read(priv, reg, &val);
91 - if (mib->size == 2) {
92 - ret = qca8k_read(priv, reg + 4, &hi);
99 - data[i] |= (u64)hi << 32;
104 -qca8k_get_sset_count(struct dsa_switch *ds, int port, int sset)
106 - struct qca8k_priv *priv = ds->priv;
108 - if (sset != ETH_SS_STATS)
111 - return priv->info->mib_count;
115 -qca8k_set_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *eee)
117 - struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
118 - u32 lpi_en = QCA8K_REG_EEE_CTRL_LPI_EN(port);
122 - mutex_lock(&priv->reg_mutex);
123 - ret = qca8k_read(priv, QCA8K_REG_EEE_CTRL, ®);
127 - if (eee->eee_enabled)
131 - ret = qca8k_write(priv, QCA8K_REG_EEE_CTRL, reg);
134 - mutex_unlock(&priv->reg_mutex);
139 -qca8k_get_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e)
141 - /* Nothing to do on the port's MAC */
146 qca8k_port_stp_state_set(struct dsa_switch *ds, int port, u8 state)
148 struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
149 --- a/drivers/net/dsa/qca/qca8k-common.c
150 +++ b/drivers/net/dsa/qca/qca8k-common.c
151 @@ -174,3 +174,105 @@ exit:
152 mutex_unlock(&priv->reg_mutex);
156 +void qca8k_port_set_status(struct qca8k_priv *priv, int port, int enable)
158 + u32 mask = QCA8K_PORT_STATUS_TXMAC | QCA8K_PORT_STATUS_RXMAC;
160 + /* Port 0 and 6 have no internal PHY */
161 + if (port > 0 && port < 6)
162 + mask |= QCA8K_PORT_STATUS_LINK_AUTO;
165 + regmap_set_bits(priv->regmap, QCA8K_REG_PORT_STATUS(port), mask);
167 + regmap_clear_bits(priv->regmap, QCA8K_REG_PORT_STATUS(port), mask);
170 +void qca8k_get_strings(struct dsa_switch *ds, int port, u32 stringset,
173 + struct qca8k_priv *priv = ds->priv;
176 + if (stringset != ETH_SS_STATS)
179 + for (i = 0; i < priv->info->mib_count; i++)
180 + strncpy(data + i * ETH_GSTRING_LEN, ar8327_mib[i].name,
184 +void qca8k_get_ethtool_stats(struct dsa_switch *ds, int port,
187 + struct qca8k_priv *priv = ds->priv;
188 + const struct qca8k_mib_desc *mib;
193 + if (priv->mgmt_master && priv->info->ops->autocast_mib &&
194 + priv->info->ops->autocast_mib(ds, port, data) > 0)
197 + for (i = 0; i < priv->info->mib_count; i++) {
198 + mib = &ar8327_mib[i];
199 + reg = QCA8K_PORT_MIB_COUNTER(port) + mib->offset;
201 + ret = qca8k_read(priv, reg, &val);
205 + if (mib->size == 2) {
206 + ret = qca8k_read(priv, reg + 4, &hi);
212 + if (mib->size == 2)
213 + data[i] |= (u64)hi << 32;
217 +int qca8k_get_sset_count(struct dsa_switch *ds, int port, int sset)
219 + struct qca8k_priv *priv = ds->priv;
221 + if (sset != ETH_SS_STATS)
224 + return priv->info->mib_count;
227 +int qca8k_set_mac_eee(struct dsa_switch *ds, int port,
228 + struct ethtool_eee *eee)
230 + u32 lpi_en = QCA8K_REG_EEE_CTRL_LPI_EN(port);
231 + struct qca8k_priv *priv = ds->priv;
235 + mutex_lock(&priv->reg_mutex);
236 + ret = qca8k_read(priv, QCA8K_REG_EEE_CTRL, ®);
240 + if (eee->eee_enabled)
244 + ret = qca8k_write(priv, QCA8K_REG_EEE_CTRL, reg);
247 + mutex_unlock(&priv->reg_mutex);
251 +int qca8k_get_mac_eee(struct dsa_switch *ds, int port,
252 + struct ethtool_eee *e)
254 + /* Nothing to do on the port's MAC */
257 --- a/drivers/net/dsa/qca/qca8k.h
258 +++ b/drivers/net/dsa/qca/qca8k.h
259 @@ -423,6 +423,7 @@ struct qca8k_fdb {
260 extern const struct qca8k_mib_desc ar8327_mib[];
261 extern const struct regmap_access_table qca8k_readable_table;
262 int qca8k_mib_init(struct qca8k_priv *priv);
263 +void qca8k_port_set_status(struct qca8k_priv *priv, int port, int enable);
265 /* Common read/write/rmw function */
266 int qca8k_read(struct qca8k_priv *priv, u32 reg, u32 *val);
267 @@ -435,4 +436,14 @@ int qca8k_bulk_write(struct qca8k_priv *
268 /* Common ops function */
269 int qca8k_busy_wait(struct qca8k_priv *priv, u32 reg, u32 mask);
271 +/* Common ethtool stats function */
272 +void qca8k_get_strings(struct dsa_switch *ds, int port, u32 stringset, uint8_t *data);
273 +void qca8k_get_ethtool_stats(struct dsa_switch *ds, int port,
275 +int qca8k_get_sset_count(struct dsa_switch *ds, int port, int sset);
277 +/* Common eee function */
278 +int qca8k_set_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *eee);
279 +int qca8k_get_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e);
281 #endif /* __QCA8K_H */