1 From b3a302b171f73425b41de8d3357fae3fa7057322 Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Wed, 27 Jul 2022 13:35:18 +0200
4 Subject: [PATCH 09/14] net: dsa: qca8k: move set age/MTU/port enable/disable
5 functions to common code
7 The same set age, MTU and port enable/disable function are used by
8 driver based on qca8k family switch.
9 Move them to common code to make them 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 | 88 ------------------------------
17 drivers/net/dsa/qca/qca8k-common.c | 85 +++++++++++++++++++++++++++++
18 drivers/net/dsa/qca/qca8k.h | 12 ++++
19 3 files changed, 97 insertions(+), 88 deletions(-)
21 --- a/drivers/net/dsa/qca/qca8k-8xxx.c
22 +++ b/drivers/net/dsa/qca/qca8k-8xxx.c
23 @@ -2059,94 +2059,6 @@ qca8k_port_fast_age(struct dsa_switch *d
27 -qca8k_set_ageing_time(struct dsa_switch *ds, unsigned int msecs)
29 - struct qca8k_priv *priv = ds->priv;
30 - unsigned int secs = msecs / 1000;
33 - /* AGE_TIME reg is set in 7s step */
36 - /* Handle case with 0 as val to NOT disable
42 - return regmap_update_bits(priv->regmap, QCA8K_REG_ATU_CTRL, QCA8K_ATU_AGE_TIME_MASK,
43 - QCA8K_ATU_AGE_TIME(val));
47 -qca8k_port_enable(struct dsa_switch *ds, int port,
48 - struct phy_device *phy)
50 - struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
52 - qca8k_port_set_status(priv, port, 1);
53 - priv->port_enabled_map |= BIT(port);
55 - if (dsa_is_user_port(ds, port))
56 - phy_support_asym_pause(phy);
62 -qca8k_port_disable(struct dsa_switch *ds, int port)
64 - struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
66 - qca8k_port_set_status(priv, port, 0);
67 - priv->port_enabled_map &= ~BIT(port);
71 -qca8k_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
73 - struct qca8k_priv *priv = ds->priv;
76 - /* We have only have a general MTU setting.
77 - * DSA always set the CPU port's MTU to the largest MTU of the slave
79 - * Setting MTU just for the CPU port is sufficient to correctly set a
80 - * value for every port.
82 - if (!dsa_is_cpu_port(ds, port))
85 - /* To change the MAX_FRAME_SIZE the cpu ports must be off or
86 - * the switch panics.
87 - * Turn off both cpu ports before applying the new value to prevent
90 - if (priv->port_enabled_map & BIT(0))
91 - qca8k_port_set_status(priv, 0, 0);
93 - if (priv->port_enabled_map & BIT(6))
94 - qca8k_port_set_status(priv, 6, 0);
96 - /* Include L2 header / FCS length */
97 - ret = qca8k_write(priv, QCA8K_MAX_FRAME_SIZE, new_mtu + ETH_HLEN + ETH_FCS_LEN);
99 - if (priv->port_enabled_map & BIT(0))
100 - qca8k_port_set_status(priv, 0, 1);
102 - if (priv->port_enabled_map & BIT(6))
103 - qca8k_port_set_status(priv, 6, 1);
109 -qca8k_port_max_mtu(struct dsa_switch *ds, int port)
111 - return QCA8K_MAX_MTU;
115 qca8k_port_fdb_insert(struct qca8k_priv *priv, const u8 *addr,
116 u16 port_mask, u16 vid)
118 --- a/drivers/net/dsa/qca/qca8k-common.c
119 +++ b/drivers/net/dsa/qca/qca8k-common.c
120 @@ -367,3 +367,88 @@ void qca8k_port_bridge_leave(struct dsa_
121 qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(port),
122 QCA8K_PORT_LOOKUP_MEMBER, BIT(cpu_port));
125 +int qca8k_set_ageing_time(struct dsa_switch *ds, unsigned int msecs)
127 + struct qca8k_priv *priv = ds->priv;
128 + unsigned int secs = msecs / 1000;
131 + /* AGE_TIME reg is set in 7s step */
134 + /* Handle case with 0 as val to NOT disable
140 + return regmap_update_bits(priv->regmap, QCA8K_REG_ATU_CTRL,
141 + QCA8K_ATU_AGE_TIME_MASK,
142 + QCA8K_ATU_AGE_TIME(val));
145 +int qca8k_port_enable(struct dsa_switch *ds, int port,
146 + struct phy_device *phy)
148 + struct qca8k_priv *priv = ds->priv;
150 + qca8k_port_set_status(priv, port, 1);
151 + priv->port_enabled_map |= BIT(port);
153 + if (dsa_is_user_port(ds, port))
154 + phy_support_asym_pause(phy);
159 +void qca8k_port_disable(struct dsa_switch *ds, int port)
161 + struct qca8k_priv *priv = ds->priv;
163 + qca8k_port_set_status(priv, port, 0);
164 + priv->port_enabled_map &= ~BIT(port);
167 +int qca8k_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
169 + struct qca8k_priv *priv = ds->priv;
172 + /* We have only have a general MTU setting.
173 + * DSA always set the CPU port's MTU to the largest MTU of the slave
175 + * Setting MTU just for the CPU port is sufficient to correctly set a
176 + * value for every port.
178 + if (!dsa_is_cpu_port(ds, port))
181 + /* To change the MAX_FRAME_SIZE the cpu ports must be off or
182 + * the switch panics.
183 + * Turn off both cpu ports before applying the new value to prevent
186 + if (priv->port_enabled_map & BIT(0))
187 + qca8k_port_set_status(priv, 0, 0);
189 + if (priv->port_enabled_map & BIT(6))
190 + qca8k_port_set_status(priv, 6, 0);
192 + /* Include L2 header / FCS length */
193 + ret = qca8k_write(priv, QCA8K_MAX_FRAME_SIZE, new_mtu +
194 + ETH_HLEN + ETH_FCS_LEN);
196 + if (priv->port_enabled_map & BIT(0))
197 + qca8k_port_set_status(priv, 0, 1);
199 + if (priv->port_enabled_map & BIT(6))
200 + qca8k_port_set_status(priv, 6, 1);
205 +int qca8k_port_max_mtu(struct dsa_switch *ds, int port)
207 + return QCA8K_MAX_MTU;
209 --- a/drivers/net/dsa/qca/qca8k.h
210 +++ b/drivers/net/dsa/qca/qca8k.h
211 @@ -453,4 +453,16 @@ int qca8k_port_bridge_join(struct dsa_sw
212 void qca8k_port_bridge_leave(struct dsa_switch *ds, int port,
213 struct net_device *br);
215 +/* Common port enable/disable function */
216 +int qca8k_port_enable(struct dsa_switch *ds, int port,
217 + struct phy_device *phy);
218 +void qca8k_port_disable(struct dsa_switch *ds, int port);
220 +/* Common MTU function */
221 +int qca8k_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu);
222 +int qca8k_port_max_mtu(struct dsa_switch *ds, int port);
224 +/* Common fast age function */
225 +int qca8k_set_ageing_time(struct dsa_switch *ds, unsigned int msecs);
227 #endif /* __QCA8K_H */