1 From 9f374df14572a9b4fb0940d8d6721c930bc27da1 Mon Sep 17 00:00:00 2001
2 From: Vladimir Oltean <vladimir.oltean@nxp.com>
3 Date: Sat, 9 Nov 2019 15:02:52 +0200
4 Subject: [PATCH] net: mscc: ocelot: refactor struct ocelot_port out of
7 The ocelot_port structure has a net_device embedded in it, which makes
8 it unsuitable for leaving it in the driver implementation functions.
10 Leave ocelot_flower.c untouched. In that file, ocelot_port is used as an
11 interface to the tc shared blocks. That will be addressed in the next
14 Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
15 Signed-off-by: David S. Miller <davem@davemloft.net>
17 drivers/net/ethernet/mscc/ocelot.c | 79 ++++++++++++++-----------------
18 drivers/net/ethernet/mscc/ocelot_police.c | 36 +++++++-------
19 drivers/net/ethernet/mscc/ocelot_police.h | 4 +-
20 drivers/net/ethernet/mscc/ocelot_tc.c | 5 +-
21 4 files changed, 59 insertions(+), 65 deletions(-)
23 --- a/drivers/net/ethernet/mscc/ocelot.c
24 +++ b/drivers/net/ethernet/mscc/ocelot.c
25 @@ -133,11 +133,11 @@ static void ocelot_mact_init(struct ocel
26 ocelot_write(ocelot, MACACCESS_CMD_INIT, ANA_TABLES_MACACCESS);
29 -static void ocelot_vcap_enable(struct ocelot *ocelot, struct ocelot_port *port)
30 +static void ocelot_vcap_enable(struct ocelot *ocelot, int port)
32 ocelot_write_gix(ocelot, ANA_PORT_VCAP_S2_CFG_S2_ENA |
33 ANA_PORT_VCAP_S2_CFG_S2_IP6_CFG(0xa),
34 - ANA_PORT_VCAP_S2_CFG, port->chip_port);
35 + ANA_PORT_VCAP_S2_CFG, port);
38 static inline u32 ocelot_vlant_read_vlanaccess(struct ocelot *ocelot)
39 @@ -170,19 +170,17 @@ static int ocelot_vlant_set_mask(struct
40 return ocelot_vlant_wait_for_completion(ocelot);
43 -static void ocelot_vlan_mode(struct ocelot_port *port,
44 +static void ocelot_vlan_mode(struct ocelot *ocelot, int port,
45 netdev_features_t features)
47 - struct ocelot *ocelot = port->ocelot;
48 - u8 p = port->chip_port;
52 val = ocelot_read(ocelot, ANA_VLANMASK);
53 if (features & NETIF_F_HW_VLAN_CTAG_FILTER)
59 ocelot_write(ocelot, val, ANA_VLANMASK);
62 @@ -1034,18 +1032,20 @@ static int ocelot_vlan_rx_kill_vid(struc
63 static int ocelot_set_features(struct net_device *dev,
64 netdev_features_t features)
66 - struct ocelot_port *port = netdev_priv(dev);
67 netdev_features_t changed = dev->features ^ features;
68 + struct ocelot_port *ocelot_port = netdev_priv(dev);
69 + struct ocelot *ocelot = ocelot_port->ocelot;
70 + int port = ocelot_port->chip_port;
72 if ((dev->features & NETIF_F_HW_TC) > (features & NETIF_F_HW_TC) &&
73 - port->tc.offload_cnt) {
74 + ocelot_port->tc.offload_cnt) {
76 "Cannot disable HW TC offload while offloads active\n");
80 if (changed & NETIF_F_HW_VLAN_CTAG_FILTER)
81 - ocelot_vlan_mode(port, features);
82 + ocelot_vlan_mode(ocelot, port, features);
86 @@ -1583,11 +1583,9 @@ static int ocelot_port_obj_del(struct ne
90 -static int ocelot_port_bridge_join(struct ocelot_port *ocelot_port,
91 +static int ocelot_port_bridge_join(struct ocelot *ocelot, int port,
92 struct net_device *bridge)
94 - struct ocelot *ocelot = ocelot_port->ocelot;
96 if (!ocelot->bridge_mask) {
97 ocelot->hw_bridge_dev = bridge;
99 @@ -1597,17 +1595,14 @@ static int ocelot_port_bridge_join(struc
103 - ocelot->bridge_mask |= BIT(ocelot_port->chip_port);
104 + ocelot->bridge_mask |= BIT(port);
109 -static int ocelot_port_bridge_leave(struct ocelot_port *ocelot_port,
110 +static int ocelot_port_bridge_leave(struct ocelot *ocelot, int port,
111 struct net_device *bridge)
113 - struct ocelot *ocelot = ocelot_port->ocelot;
114 - int port = ocelot_port->chip_port;
116 ocelot->bridge_mask &= ~BIT(port);
118 if (!ocelot->bridge_mask)
119 @@ -1676,14 +1671,12 @@ static void ocelot_setup_lag(struct ocel
123 -static int ocelot_port_lag_join(struct ocelot_port *ocelot_port,
124 +static int ocelot_port_lag_join(struct ocelot *ocelot, int port,
125 struct net_device *bond)
127 - struct ocelot *ocelot = ocelot_port->ocelot;
128 - int p = ocelot_port->chip_port;
130 struct net_device *ndev;
135 for_each_netdev_in_bond_rcu(bond, ndev) {
136 @@ -1698,17 +1691,17 @@ static int ocelot_port_lag_join(struct o
137 /* If the new port is the lowest one, use it as the logical port from
142 - ocelot->lags[p] = bond_mask;
143 - bond_mask &= ~BIT(p);
146 + ocelot->lags[port] = bond_mask;
147 + bond_mask &= ~BIT(port);
149 lp = __ffs(bond_mask);
150 ocelot->lags[lp] = 0;
154 - ocelot->lags[lp] |= BIT(p);
155 + ocelot->lags[lp] |= BIT(port);
158 ocelot_setup_lag(ocelot, lag);
159 @@ -1717,34 +1710,32 @@ static int ocelot_port_lag_join(struct o
163 -static void ocelot_port_lag_leave(struct ocelot_port *ocelot_port,
164 +static void ocelot_port_lag_leave(struct ocelot *ocelot, int port,
165 struct net_device *bond)
167 - struct ocelot *ocelot = ocelot_port->ocelot;
168 - int p = ocelot_port->chip_port;
172 /* Remove port from any lag */
173 for (i = 0; i < ocelot->num_phys_ports; i++)
174 - ocelot->lags[i] &= ~BIT(ocelot_port->chip_port);
175 + ocelot->lags[i] &= ~BIT(port);
177 /* if it was the logical port of the lag, move the lag config to the
180 - if (ocelot->lags[p]) {
181 - int n = __ffs(ocelot->lags[p]);
182 + if (ocelot->lags[port]) {
183 + int n = __ffs(ocelot->lags[port]);
185 - ocelot->lags[n] = ocelot->lags[p];
186 - ocelot->lags[p] = 0;
187 + ocelot->lags[n] = ocelot->lags[port];
188 + ocelot->lags[port] = 0;
190 ocelot_setup_lag(ocelot, n);
193 - port_cfg = ocelot_read_gix(ocelot, ANA_PORT_PORT_CFG, p);
194 + port_cfg = ocelot_read_gix(ocelot, ANA_PORT_PORT_CFG, port);
195 port_cfg &= ~ANA_PORT_PORT_CFG_PORTID_VAL_M;
196 - ocelot_write_gix(ocelot, port_cfg | ANA_PORT_PORT_CFG_PORTID_VAL(p),
197 - ANA_PORT_PORT_CFG, p);
198 + ocelot_write_gix(ocelot, port_cfg | ANA_PORT_PORT_CFG_PORTID_VAL(port),
199 + ANA_PORT_PORT_CFG, port);
201 ocelot_set_aggr_pgids(ocelot);
203 @@ -1760,24 +1751,26 @@ static int ocelot_netdevice_port_event(s
204 struct netdev_notifier_changeupper_info *info)
206 struct ocelot_port *ocelot_port = netdev_priv(dev);
207 + struct ocelot *ocelot = ocelot_port->ocelot;
208 + int port = ocelot_port->chip_port;
212 case NETDEV_CHANGEUPPER:
213 if (netif_is_bridge_master(info->upper_dev)) {
215 - err = ocelot_port_bridge_join(ocelot_port,
216 + err = ocelot_port_bridge_join(ocelot, port,
219 - err = ocelot_port_bridge_leave(ocelot_port,
220 + err = ocelot_port_bridge_leave(ocelot, port,
223 if (netif_is_lag_master(info->upper_dev)) {
225 - err = ocelot_port_lag_join(ocelot_port,
226 + err = ocelot_port_lag_join(ocelot, port,
229 - ocelot_port_lag_leave(ocelot_port,
230 + ocelot_port_lag_leave(ocelot, port,
234 @@ -2135,7 +2128,7 @@ int ocelot_probe_port(struct ocelot *oce
235 REW_PORT_VLAN_CFG, port);
237 /* Enable vcap lookups */
238 - ocelot_vcap_enable(ocelot, ocelot_port);
239 + ocelot_vcap_enable(ocelot, port);
243 --- a/drivers/net/ethernet/mscc/ocelot_police.c
244 +++ b/drivers/net/ethernet/mscc/ocelot_police.c
245 @@ -40,13 +40,12 @@ struct qos_policer_conf {
246 u8 ipg; /* Size of IPG when MSCC_QOS_RATE_MODE_LINE is chosen */
249 -static int qos_policer_conf_set(struct ocelot_port *port, u32 pol_ix,
250 +static int qos_policer_conf_set(struct ocelot *ocelot, int port, u32 pol_ix,
251 struct qos_policer_conf *conf)
253 u32 cf = 0, cir_ena = 0, frm_mode = POL_MODE_LINERATE;
254 u32 cir = 0, cbs = 0, pir = 0, pbs = 0;
255 bool cir_discard = 0, pir_discard = 0;
256 - struct ocelot *ocelot = port->ocelot;
257 u32 pbs_max = 0, cbs_max = 0;
260 @@ -123,22 +122,26 @@ static int qos_policer_conf_set(struct o
263 if (pir > GENMASK(15, 0)) {
264 - netdev_err(port->dev, "Invalid pir\n");
265 + dev_err(ocelot->dev, "Invalid pir for port %d: %u (max %lu)\n",
266 + port, pir, GENMASK(15, 0));
270 if (cir > GENMASK(15, 0)) {
271 - netdev_err(port->dev, "Invalid cir\n");
272 + dev_err(ocelot->dev, "Invalid cir for port %d: %u (max %lu)\n",
273 + port, cir, GENMASK(15, 0));
278 - netdev_err(port->dev, "Invalid pbs\n");
279 + dev_err(ocelot->dev, "Invalid pbs for port %d: %u (max %u)\n",
280 + port, pbs, pbs_max);
285 - netdev_err(port->dev, "Invalid cbs\n");
286 + dev_err(ocelot->dev, "Invalid cbs for port %d: %u (max %u)\n",
287 + port, cbs, cbs_max);
291 @@ -171,10 +174,9 @@ static int qos_policer_conf_set(struct o
295 -int ocelot_port_policer_add(struct ocelot_port *port,
296 +int ocelot_port_policer_add(struct ocelot *ocelot, int port,
297 struct ocelot_policer *pol)
299 - struct ocelot *ocelot = port->ocelot;
300 struct qos_policer_conf pp = { 0 };
303 @@ -185,11 +187,10 @@ int ocelot_port_policer_add(struct ocelo
307 - netdev_dbg(port->dev,
308 - "%s: port %u pir %u kbps, pbs %u bytes\n",
309 - __func__, port->chip_port, pp.pir, pp.pbs);
310 + dev_dbg(ocelot->dev, "%s: port %u pir %u kbps, pbs %u bytes\n",
311 + __func__, port, pp.pir, pp.pbs);
313 - err = qos_policer_conf_set(port, POL_IX_PORT + port->chip_port, &pp);
314 + err = qos_policer_conf_set(ocelot, port, POL_IX_PORT + port, &pp);
318 @@ -198,22 +199,21 @@ int ocelot_port_policer_add(struct ocelo
319 ANA_PORT_POL_CFG_POL_ORDER(POL_ORDER),
320 ANA_PORT_POL_CFG_PORT_POL_ENA |
321 ANA_PORT_POL_CFG_POL_ORDER_M,
322 - ANA_PORT_POL_CFG, port->chip_port);
323 + ANA_PORT_POL_CFG, port);
328 -int ocelot_port_policer_del(struct ocelot_port *port)
329 +int ocelot_port_policer_del(struct ocelot *ocelot, int port)
331 - struct ocelot *ocelot = port->ocelot;
332 struct qos_policer_conf pp = { 0 };
335 - netdev_dbg(port->dev, "%s: port %u\n", __func__, port->chip_port);
336 + dev_dbg(ocelot->dev, "%s: port %u\n", __func__, port);
338 pp.mode = MSCC_QOS_RATE_MODE_DISABLED;
340 - err = qos_policer_conf_set(port, POL_IX_PORT + port->chip_port, &pp);
341 + err = qos_policer_conf_set(ocelot, port, POL_IX_PORT + port, &pp);
345 @@ -221,7 +221,7 @@ int ocelot_port_policer_del(struct ocelo
346 ANA_PORT_POL_CFG_POL_ORDER(POL_ORDER),
347 ANA_PORT_POL_CFG_PORT_POL_ENA |
348 ANA_PORT_POL_CFG_POL_ORDER_M,
349 - ANA_PORT_POL_CFG, port->chip_port);
350 + ANA_PORT_POL_CFG, port);
354 --- a/drivers/net/ethernet/mscc/ocelot_police.h
355 +++ b/drivers/net/ethernet/mscc/ocelot_police.h
356 @@ -14,9 +14,9 @@ struct ocelot_policer {
357 u32 burst; /* bytes */
360 -int ocelot_port_policer_add(struct ocelot_port *port,
361 +int ocelot_port_policer_add(struct ocelot *ocelot, int port,
362 struct ocelot_policer *pol);
364 -int ocelot_port_policer_del(struct ocelot_port *port);
365 +int ocelot_port_policer_del(struct ocelot *ocelot, int port);
367 #endif /* _MSCC_OCELOT_POLICE_H_ */
368 --- a/drivers/net/ethernet/mscc/ocelot_tc.c
369 +++ b/drivers/net/ethernet/mscc/ocelot_tc.c
370 @@ -58,7 +58,8 @@ static int ocelot_setup_tc_cls_matchall(
371 PSCHED_NS2TICKS(action->police.burst),
372 PSCHED_TICKS_PER_SEC);
374 - err = ocelot_port_policer_add(port, &pol);
375 + err = ocelot_port_policer_add(port->ocelot, port->chip_port,
378 NL_SET_ERR_MSG_MOD(extack, "Could not add policer\n");
380 @@ -71,7 +72,7 @@ static int ocelot_setup_tc_cls_matchall(
381 if (port->tc.police_id != f->cookie)
384 - err = ocelot_port_policer_del(port);
385 + err = ocelot_port_policer_del(port->ocelot, port->chip_port);
387 NL_SET_ERR_MSG_MOD(extack,
388 "Could not delete policer\n");