]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - net/dsa/slave.c
net: flow_offload: remove netns parameter from flow_block_cb_alloc()
[mirror_ubuntu-hirsute-kernel.git] / net / dsa / slave.c
CommitLineData
2874c5fd 1// SPDX-License-Identifier: GPL-2.0-or-later
91da11f8
LB
2/*
3 * net/dsa/slave.c - Slave device handling
e84665c9 4 * Copyright (c) 2008-2009 Marvell Semiconductor
91da11f8
LB
5 */
6
7#include <linux/list.h>
df02c6ff 8#include <linux/etherdevice.h>
b73adef6 9#include <linux/netdevice.h>
91da11f8 10#include <linux/phy.h>
a2820543 11#include <linux/phy_fixed.h>
aab9c406 12#include <linux/phylink.h>
0d8bcdd3
FF
13#include <linux/of_net.h>
14#include <linux/of_mdio.h>
7f854420 15#include <linux/mdio.h>
b73adef6 16#include <net/rtnetlink.h>
f50f2127
FF
17#include <net/pkt_cls.h>
18#include <net/tc_act/tc_mirred.h>
b73adef6 19#include <linux/if_bridge.h>
04ff53f9 20#include <linux/netpoll.h>
90af1059 21#include <linux/ptp_classify.h>
ea5dd34b 22
91da11f8
LB
23#include "dsa_priv.h"
24
f3b78049 25static bool dsa_slave_dev_check(const struct net_device *dev);
f50f2127 26
91da11f8
LB
27/* slave mii_bus handling ***************************************************/
28static int dsa_slave_phy_read(struct mii_bus *bus, int addr, int reg)
29{
30 struct dsa_switch *ds = bus->priv;
31
0d8bcdd3 32 if (ds->phys_mii_mask & (1 << addr))
9d490b4e 33 return ds->ops->phy_read(ds, addr, reg);
91da11f8
LB
34
35 return 0xffff;
36}
37
38static int dsa_slave_phy_write(struct mii_bus *bus, int addr, int reg, u16 val)
39{
40 struct dsa_switch *ds = bus->priv;
41
0d8bcdd3 42 if (ds->phys_mii_mask & (1 << addr))
9d490b4e 43 return ds->ops->phy_write(ds, addr, reg, val);
91da11f8
LB
44
45 return 0;
46}
47
48void dsa_slave_mii_bus_init(struct dsa_switch *ds)
49{
50 ds->slave_mii_bus->priv = (void *)ds;
51 ds->slave_mii_bus->name = "dsa slave smi";
52 ds->slave_mii_bus->read = dsa_slave_phy_read;
53 ds->slave_mii_bus->write = dsa_slave_phy_write;
0b7b498d 54 snprintf(ds->slave_mii_bus->id, MII_BUS_ID_SIZE, "dsa-%d.%d",
49463b7f 55 ds->dst->index, ds->index);
c33063d6 56 ds->slave_mii_bus->parent = ds->dev;
24df8986 57 ds->slave_mii_bus->phy_mask = ~ds->phys_mii_mask;
91da11f8
LB
58}
59
60
61/* slave device handling ****************************************************/
abd2be00 62static int dsa_slave_get_iflink(const struct net_device *dev)
c0840801 63{
d0006b00 64 return dsa_slave_to_master(dev)->ifindex;
c0840801
LB
65}
66
91da11f8
LB
67static int dsa_slave_open(struct net_device *dev)
68{
d0006b00 69 struct net_device *master = dsa_slave_to_master(dev);
d945097b 70 struct dsa_port *dp = dsa_slave_to_port(dev);
df02c6ff
LB
71 int err;
72
73 if (!(master->flags & IFF_UP))
74 return -ENETDOWN;
75
8feedbb4 76 if (!ether_addr_equal(dev->dev_addr, master->dev_addr)) {
a748ee24 77 err = dev_uc_add(master, dev->dev_addr);
df02c6ff
LB
78 if (err < 0)
79 goto out;
80 }
81
82 if (dev->flags & IFF_ALLMULTI) {
83 err = dev_set_allmulti(master, 1);
84 if (err < 0)
85 goto del_unicast;
86 }
87 if (dev->flags & IFF_PROMISC) {
88 err = dev_set_promiscuity(master, 1);
89 if (err < 0)
90 goto clear_allmulti;
91 }
92
0115dcd1 93 err = dsa_port_enable(dp, dev->phydev);
fb8a6a2b
VD
94 if (err)
95 goto clear_promisc;
b73adef6 96
aab9c406 97 phylink_start(dp->pl);
f7f1de51 98
91da11f8 99 return 0;
df02c6ff 100
b2f2af21
FF
101clear_promisc:
102 if (dev->flags & IFF_PROMISC)
4fdeddfe 103 dev_set_promiscuity(master, -1);
df02c6ff
LB
104clear_allmulti:
105 if (dev->flags & IFF_ALLMULTI)
106 dev_set_allmulti(master, -1);
107del_unicast:
8feedbb4 108 if (!ether_addr_equal(dev->dev_addr, master->dev_addr))
a748ee24 109 dev_uc_del(master, dev->dev_addr);
df02c6ff
LB
110out:
111 return err;
91da11f8
LB
112}
113
114static int dsa_slave_close(struct net_device *dev)
115{
d0006b00 116 struct net_device *master = dsa_slave_to_master(dev);
d945097b 117 struct dsa_port *dp = dsa_slave_to_port(dev);
df02c6ff 118
97a69a0d
VO
119 cancel_work_sync(&dp->xmit_work);
120 skb_queue_purge(&dp->xmit_queue);
121
aab9c406 122 phylink_stop(dp->pl);
f7f1de51 123
75104db0 124 dsa_port_disable(dp);
6457edfe 125
df02c6ff 126 dev_mc_unsync(master, dev);
a748ee24 127 dev_uc_unsync(master, dev);
df02c6ff
LB
128 if (dev->flags & IFF_ALLMULTI)
129 dev_set_allmulti(master, -1);
130 if (dev->flags & IFF_PROMISC)
131 dev_set_promiscuity(master, -1);
132
8feedbb4 133 if (!ether_addr_equal(dev->dev_addr, master->dev_addr))
a748ee24 134 dev_uc_del(master, dev->dev_addr);
df02c6ff 135
91da11f8
LB
136 return 0;
137}
138
139static void dsa_slave_change_rx_flags(struct net_device *dev, int change)
140{
d0006b00 141 struct net_device *master = dsa_slave_to_master(dev);
17ab4f61
RG
142 if (dev->flags & IFF_UP) {
143 if (change & IFF_ALLMULTI)
144 dev_set_allmulti(master,
145 dev->flags & IFF_ALLMULTI ? 1 : -1);
146 if (change & IFF_PROMISC)
147 dev_set_promiscuity(master,
148 dev->flags & IFF_PROMISC ? 1 : -1);
149 }
91da11f8
LB
150}
151
152static void dsa_slave_set_rx_mode(struct net_device *dev)
153{
d0006b00 154 struct net_device *master = dsa_slave_to_master(dev);
91da11f8
LB
155
156 dev_mc_sync(master, dev);
a748ee24 157 dev_uc_sync(master, dev);
91da11f8
LB
158}
159
df02c6ff 160static int dsa_slave_set_mac_address(struct net_device *dev, void *a)
91da11f8 161{
d0006b00 162 struct net_device *master = dsa_slave_to_master(dev);
df02c6ff
LB
163 struct sockaddr *addr = a;
164 int err;
165
166 if (!is_valid_ether_addr(addr->sa_data))
167 return -EADDRNOTAVAIL;
168
169 if (!(dev->flags & IFF_UP))
170 goto out;
171
8feedbb4 172 if (!ether_addr_equal(addr->sa_data, master->dev_addr)) {
a748ee24 173 err = dev_uc_add(master, addr->sa_data);
df02c6ff
LB
174 if (err < 0)
175 return err;
176 }
177
8feedbb4 178 if (!ether_addr_equal(dev->dev_addr, master->dev_addr))
a748ee24 179 dev_uc_del(master, dev->dev_addr);
df02c6ff
LB
180
181out:
d08f161a 182 ether_addr_copy(dev->dev_addr, addr->sa_data);
91da11f8
LB
183
184 return 0;
185}
186
2bedde1a
AS
187struct dsa_slave_dump_ctx {
188 struct net_device *dev;
189 struct sk_buff *skb;
190 struct netlink_callback *cb;
191 int idx;
192};
193
194static int
195dsa_slave_port_fdb_do_dump(const unsigned char *addr, u16 vid,
196 bool is_static, void *data)
197{
198 struct dsa_slave_dump_ctx *dump = data;
199 u32 portid = NETLINK_CB(dump->cb->skb).portid;
200 u32 seq = dump->cb->nlh->nlmsg_seq;
201 struct nlmsghdr *nlh;
202 struct ndmsg *ndm;
203
204 if (dump->idx < dump->cb->args[2])
205 goto skip;
206
207 nlh = nlmsg_put(dump->skb, portid, seq, RTM_NEWNEIGH,
208 sizeof(*ndm), NLM_F_MULTI);
209 if (!nlh)
210 return -EMSGSIZE;
211
212 ndm = nlmsg_data(nlh);
213 ndm->ndm_family = AF_BRIDGE;
214 ndm->ndm_pad1 = 0;
215 ndm->ndm_pad2 = 0;
216 ndm->ndm_flags = NTF_SELF;
217 ndm->ndm_type = 0;
218 ndm->ndm_ifindex = dump->dev->ifindex;
219 ndm->ndm_state = is_static ? NUD_NOARP : NUD_REACHABLE;
220
221 if (nla_put(dump->skb, NDA_LLADDR, ETH_ALEN, addr))
222 goto nla_put_failure;
223
224 if (vid && nla_put_u16(dump->skb, NDA_VLAN, vid))
225 goto nla_put_failure;
226
227 nlmsg_end(dump->skb, nlh);
228
229skip:
230 dump->idx++;
231 return 0;
232
233nla_put_failure:
234 nlmsg_cancel(dump->skb, nlh);
235 return -EMSGSIZE;
236}
237
238static int
239dsa_slave_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
240 struct net_device *dev, struct net_device *filter_dev,
241 int *idx)
242{
d945097b 243 struct dsa_port *dp = dsa_slave_to_port(dev);
2bedde1a
AS
244 struct dsa_slave_dump_ctx dump = {
245 .dev = dev,
246 .skb = skb,
247 .cb = cb,
248 .idx = *idx,
249 };
2bedde1a
AS
250 int err;
251
de40fc5d 252 err = dsa_port_fdb_dump(dp, dsa_slave_port_fdb_do_dump, &dump);
2bedde1a 253 *idx = dump.idx;
de40fc5d 254
2bedde1a
AS
255 return err;
256}
257
91da11f8
LB
258static int dsa_slave_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
259{
0336369d
BS
260 struct dsa_slave_priv *p = netdev_priv(dev);
261 struct dsa_switch *ds = p->dp->ds;
262 int port = p->dp->index;
263
264 /* Pass through to switch driver if it supports timestamping */
265 switch (cmd) {
266 case SIOCGHWTSTAMP:
267 if (ds->ops->port_hwtstamp_get)
268 return ds->ops->port_hwtstamp_get(ds, port, ifr);
269 break;
270 case SIOCSHWTSTAMP:
271 if (ds->ops->port_hwtstamp_set)
272 return ds->ops->port_hwtstamp_set(ds, port, ifr);
273 break;
274 }
275
aab9c406 276 return phylink_mii_ioctl(p->dp->pl, ifr, cmd);
91da11f8
LB
277}
278
35636062 279static int dsa_slave_port_attr_set(struct net_device *dev,
f7fadf30 280 const struct switchdev_attr *attr,
7ea6eb3f 281 struct switchdev_trans *trans)
35636062 282{
d945097b 283 struct dsa_port *dp = dsa_slave_to_port(dev);
b8d866ac 284 int ret;
35636062
SF
285
286 switch (attr->id) {
1f868398 287 case SWITCHDEV_ATTR_ID_PORT_STP_STATE:
fd364541 288 ret = dsa_port_set_state(dp, attr->u.stp_state, trans);
35636062 289 break;
fb2dabad 290 case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING:
c02c4175
VD
291 ret = dsa_port_vlan_filtering(dp, attr->u.vlan_filtering,
292 trans);
fb2dabad 293 break;
34a79f63 294 case SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME:
072bb190 295 ret = dsa_port_ageing_time(dp, attr->u.ageing_time, trans);
34a79f63 296 break;
ea87005a
FF
297 case SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS:
298 ret = dsa_port_pre_bridge_flags(dp, attr->u.brport_flags,
299 trans);
300 break;
57652796
RK
301 case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS:
302 ret = dsa_port_bridge_flags(dp, attr->u.brport_flags, trans);
303 break;
08cc83cc
VD
304 case SWITCHDEV_ATTR_ID_BRIDGE_MROUTER:
305 ret = dsa_port_mrouter(dp->cpu_dp, attr->u.mrouter, trans);
306 break;
35636062
SF
307 default:
308 ret = -EOPNOTSUPP;
309 break;
310 }
311
312 return ret;
313}
314
ba14d9eb 315static int dsa_slave_port_obj_add(struct net_device *dev,
648b4a99 316 const struct switchdev_obj *obj,
79b139f4
VD
317 struct switchdev_trans *trans,
318 struct netlink_ext_ack *extack)
ba14d9eb 319{
d945097b 320 struct dsa_port *dp = dsa_slave_to_port(dev);
ba14d9eb
VD
321 int err;
322
323 /* For the prepare phase, ensure the full set of changes is feasable in
324 * one go in order to signal a failure properly. If an operation is not
325 * supported, return -EOPNOTSUPP.
326 */
327
9e8f4a54 328 switch (obj->id) {
8df30255 329 case SWITCHDEV_OBJ_ID_PORT_MDB:
79b139f4
VD
330 if (obj->orig_dev != dev)
331 return -EOPNOTSUPP;
bcebb976 332 err = dsa_port_mdb_add(dp, SWITCHDEV_OBJ_PORT_MDB(obj), trans);
8df30255 333 break;
5f4dbc50
AL
334 case SWITCHDEV_OBJ_ID_HOST_MDB:
335 /* DSA can directly translate this to a normal MDB add,
336 * but on the CPU port.
337 */
338 err = dsa_port_mdb_add(dp->cpu_dp, SWITCHDEV_OBJ_PORT_MDB(obj),
339 trans);
340 break;
57d80838 341 case SWITCHDEV_OBJ_ID_PORT_VLAN:
79b139f4
VD
342 if (obj->orig_dev != dev)
343 return -EOPNOTSUPP;
01676d12
VD
344 err = dsa_port_vlan_add(dp, SWITCHDEV_OBJ_PORT_VLAN(obj),
345 trans);
11149536 346 break;
ba14d9eb
VD
347 default:
348 err = -EOPNOTSUPP;
349 break;
350 }
351
352 return err;
353}
354
355static int dsa_slave_port_obj_del(struct net_device *dev,
648b4a99 356 const struct switchdev_obj *obj)
ba14d9eb 357{
d945097b 358 struct dsa_port *dp = dsa_slave_to_port(dev);
ba14d9eb
VD
359 int err;
360
9e8f4a54 361 switch (obj->id) {
8df30255 362 case SWITCHDEV_OBJ_ID_PORT_MDB:
79b139f4
VD
363 if (obj->orig_dev != dev)
364 return -EOPNOTSUPP;
bcebb976 365 err = dsa_port_mdb_del(dp, SWITCHDEV_OBJ_PORT_MDB(obj));
8df30255 366 break;
5f4dbc50
AL
367 case SWITCHDEV_OBJ_ID_HOST_MDB:
368 /* DSA can directly translate this to a normal MDB add,
369 * but on the CPU port.
370 */
371 err = dsa_port_mdb_del(dp->cpu_dp, SWITCHDEV_OBJ_PORT_MDB(obj));
372 break;
57d80838 373 case SWITCHDEV_OBJ_ID_PORT_VLAN:
79b139f4
VD
374 if (obj->orig_dev != dev)
375 return -EOPNOTSUPP;
01676d12 376 err = dsa_port_vlan_del(dp, SWITCHDEV_OBJ_PORT_VLAN(obj));
11149536 377 break;
ba14d9eb
VD
378 default:
379 err = -EOPNOTSUPP;
380 break;
381 }
382
383 return err;
384}
385
929d6c14
FF
386static int dsa_slave_get_port_parent_id(struct net_device *dev,
387 struct netdev_phys_item_id *ppid)
b73adef6 388{
d945097b
VD
389 struct dsa_port *dp = dsa_slave_to_port(dev);
390 struct dsa_switch *ds = dp->ds;
a42c8e33 391 struct dsa_switch_tree *dst = ds->dst;
b73adef6 392
15b04ace
JP
393 /* For non-legacy ports, devlink is used and it takes
394 * care of the name generation. This ndo implementation
395 * should be removed with legacy support.
396 */
397 if (dp->ds->devlink)
398 return -EOPNOTSUPP;
399
929d6c14
FF
400 ppid->id_len = sizeof(dst->index);
401 memcpy(&ppid->id, &dst->index, ppid->id_len);
402
403 return 0;
404}
405
4fa7b718
VD
406static inline netdev_tx_t dsa_slave_netpoll_send_skb(struct net_device *dev,
407 struct sk_buff *skb)
04ff53f9
FF
408{
409#ifdef CONFIG_NET_POLL_CONTROLLER
4fa7b718
VD
410 struct dsa_slave_priv *p = netdev_priv(dev);
411
04ff53f9
FF
412 if (p->netpoll)
413 netpoll_send_skb(p->netpoll, skb);
414#else
415 BUG();
416#endif
417 return NETDEV_TX_OK;
418}
419
90af1059
BS
420static void dsa_skb_tx_timestamp(struct dsa_slave_priv *p,
421 struct sk_buff *skb)
422{
423 struct dsa_switch *ds = p->dp->ds;
424 struct sk_buff *clone;
425 unsigned int type;
426
427 type = ptp_classify_raw(skb);
428 if (type == PTP_CLASS_NONE)
429 return;
430
431 if (!ds->ops->port_txtstamp)
432 return;
433
434 clone = skb_clone_sk(skb);
435 if (!clone)
436 return;
437
146d442c
VO
438 DSA_SKB_CB(skb)->clone = clone;
439
90af1059
BS
440 if (ds->ops->port_txtstamp(ds, p->dp->index, clone, type))
441 return;
442
443 kfree_skb(clone);
444}
445
97a69a0d
VO
446netdev_tx_t dsa_enqueue_skb(struct sk_buff *skb, struct net_device *dev)
447{
448 /* SKB for netpoll still need to be mangled with the protocol-specific
449 * tag to be successfully transmitted
450 */
451 if (unlikely(netpoll_tx_running(dev)))
452 return dsa_slave_netpoll_send_skb(dev, skb);
453
454 /* Queue the SKB for transmission on the parent interface, but
455 * do not modify its EtherType
456 */
457 skb->dev = dsa_slave_to_master(dev);
458 dev_queue_xmit(skb);
459
460 return NETDEV_TX_OK;
461}
462EXPORT_SYMBOL_GPL(dsa_enqueue_skb);
463
3e8a72d1
FF
464static netdev_tx_t dsa_slave_xmit(struct sk_buff *skb, struct net_device *dev)
465{
466 struct dsa_slave_priv *p = netdev_priv(dev);
5f6b4e14 467 struct pcpu_sw_netstats *s;
4ed70ce9 468 struct sk_buff *nskb;
3e8a72d1 469
5f6b4e14
FF
470 s = this_cpu_ptr(p->stats64);
471 u64_stats_update_begin(&s->syncp);
472 s->tx_packets++;
473 s->tx_bytes += skb->len;
474 u64_stats_update_end(&s->syncp);
3e8a72d1 475
87671375 476 DSA_SKB_CB(skb)->deferred_xmit = false;
146d442c 477 DSA_SKB_CB(skb)->clone = NULL;
87671375 478
90af1059
BS
479 /* Identify PTP protocol packets, clone them, and pass them to the
480 * switch driver
481 */
482 dsa_skb_tx_timestamp(p, skb);
483
fe47d563
VD
484 /* Transmit function may have to reallocate the original SKB,
485 * in which case it must have freed it. Only free it here on error.
486 */
4ed70ce9 487 nskb = p->xmit(skb, dev);
fe47d563 488 if (!nskb) {
97a69a0d
VO
489 if (!DSA_SKB_CB(skb)->deferred_xmit)
490 kfree_skb(skb);
4ed70ce9 491 return NETDEV_TX_OK;
fe47d563 492 }
5aed85ce 493
97a69a0d
VO
494 return dsa_enqueue_skb(nskb, dev);
495}
04ff53f9 496
97a69a0d
VO
497void *dsa_defer_xmit(struct sk_buff *skb, struct net_device *dev)
498{
499 struct dsa_port *dp = dsa_slave_to_port(dev);
5aed85ce 500
97a69a0d
VO
501 DSA_SKB_CB(skb)->deferred_xmit = true;
502
503 skb_queue_tail(&dp->xmit_queue, skb);
504 schedule_work(&dp->xmit_work);
505 return NULL;
506}
507EXPORT_SYMBOL_GPL(dsa_defer_xmit);
508
509static void dsa_port_xmit_work(struct work_struct *work)
510{
511 struct dsa_port *dp = container_of(work, struct dsa_port, xmit_work);
512 struct dsa_switch *ds = dp->ds;
513 struct sk_buff *skb;
514
515 if (unlikely(!ds->ops->port_deferred_xmit))
516 return;
517
518 while ((skb = skb_dequeue(&dp->xmit_queue)) != NULL)
519 ds->ops->port_deferred_xmit(ds, dp->index, skb);
5aed85ce
FF
520}
521
91da11f8 522/* ethtool operations *******************************************************/
91da11f8 523
91da11f8
LB
524static void dsa_slave_get_drvinfo(struct net_device *dev,
525 struct ethtool_drvinfo *drvinfo)
526{
7826d43f 527 strlcpy(drvinfo->driver, "dsa", sizeof(drvinfo->driver));
7826d43f
JP
528 strlcpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version));
529 strlcpy(drvinfo->bus_info, "platform", sizeof(drvinfo->bus_info));
91da11f8
LB
530}
531
3d762a0f
GR
532static int dsa_slave_get_regs_len(struct net_device *dev)
533{
d945097b
VD
534 struct dsa_port *dp = dsa_slave_to_port(dev);
535 struct dsa_switch *ds = dp->ds;
3d762a0f 536
9d490b4e 537 if (ds->ops->get_regs_len)
d945097b 538 return ds->ops->get_regs_len(ds, dp->index);
3d762a0f
GR
539
540 return -EOPNOTSUPP;
541}
542
543static void
544dsa_slave_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *_p)
545{
d945097b
VD
546 struct dsa_port *dp = dsa_slave_to_port(dev);
547 struct dsa_switch *ds = dp->ds;
3d762a0f 548
9d490b4e 549 if (ds->ops->get_regs)
d945097b 550 ds->ops->get_regs(ds, dp->index, regs, _p);
3d762a0f
GR
551}
552
aab9c406
FF
553static int dsa_slave_nway_reset(struct net_device *dev)
554{
555 struct dsa_port *dp = dsa_slave_to_port(dev);
556
557 return phylink_ethtool_nway_reset(dp->pl);
558}
559
6793abb4
GR
560static int dsa_slave_get_eeprom_len(struct net_device *dev)
561{
d945097b
VD
562 struct dsa_port *dp = dsa_slave_to_port(dev);
563 struct dsa_switch *ds = dp->ds;
6793abb4 564
0e576044 565 if (ds->cd && ds->cd->eeprom_len)
ff04955c 566 return ds->cd->eeprom_len;
6793abb4 567
9d490b4e
VD
568 if (ds->ops->get_eeprom_len)
569 return ds->ops->get_eeprom_len(ds);
6793abb4
GR
570
571 return 0;
572}
573
574static int dsa_slave_get_eeprom(struct net_device *dev,
575 struct ethtool_eeprom *eeprom, u8 *data)
576{
d945097b
VD
577 struct dsa_port *dp = dsa_slave_to_port(dev);
578 struct dsa_switch *ds = dp->ds;
6793abb4 579
9d490b4e
VD
580 if (ds->ops->get_eeprom)
581 return ds->ops->get_eeprom(ds, eeprom, data);
6793abb4
GR
582
583 return -EOPNOTSUPP;
584}
585
586static int dsa_slave_set_eeprom(struct net_device *dev,
587 struct ethtool_eeprom *eeprom, u8 *data)
588{
d945097b
VD
589 struct dsa_port *dp = dsa_slave_to_port(dev);
590 struct dsa_switch *ds = dp->ds;
6793abb4 591
9d490b4e
VD
592 if (ds->ops->set_eeprom)
593 return ds->ops->set_eeprom(ds, eeprom, data);
6793abb4
GR
594
595 return -EOPNOTSUPP;
596}
597
91da11f8
LB
598static void dsa_slave_get_strings(struct net_device *dev,
599 uint32_t stringset, uint8_t *data)
600{
d945097b
VD
601 struct dsa_port *dp = dsa_slave_to_port(dev);
602 struct dsa_switch *ds = dp->ds;
91da11f8
LB
603
604 if (stringset == ETH_SS_STATS) {
605 int len = ETH_GSTRING_LEN;
606
607 strncpy(data, "tx_packets", len);
608 strncpy(data + len, "tx_bytes", len);
609 strncpy(data + 2 * len, "rx_packets", len);
610 strncpy(data + 3 * len, "rx_bytes", len);
9d490b4e 611 if (ds->ops->get_strings)
89f09048
FF
612 ds->ops->get_strings(ds, dp->index, stringset,
613 data + 4 * len);
91da11f8
LB
614 }
615}
616
617static void dsa_slave_get_ethtool_stats(struct net_device *dev,
618 struct ethtool_stats *stats,
619 uint64_t *data)
620{
d945097b 621 struct dsa_port *dp = dsa_slave_to_port(dev);
91da11f8 622 struct dsa_slave_priv *p = netdev_priv(dev);
d945097b 623 struct dsa_switch *ds = dp->ds;
5f6b4e14 624 struct pcpu_sw_netstats *s;
f613ed66 625 unsigned int start;
5f6b4e14
FF
626 int i;
627
628 for_each_possible_cpu(i) {
629 u64 tx_packets, tx_bytes, rx_packets, rx_bytes;
630
631 s = per_cpu_ptr(p->stats64, i);
632 do {
633 start = u64_stats_fetch_begin_irq(&s->syncp);
634 tx_packets = s->tx_packets;
635 tx_bytes = s->tx_bytes;
636 rx_packets = s->rx_packets;
637 rx_bytes = s->rx_bytes;
638 } while (u64_stats_fetch_retry_irq(&s->syncp, start));
639 data[0] += tx_packets;
640 data[1] += tx_bytes;
641 data[2] += rx_packets;
642 data[3] += rx_bytes;
643 }
9d490b4e 644 if (ds->ops->get_ethtool_stats)
d945097b 645 ds->ops->get_ethtool_stats(ds, dp->index, data + 4);
91da11f8
LB
646}
647
648static int dsa_slave_get_sset_count(struct net_device *dev, int sset)
649{
d945097b
VD
650 struct dsa_port *dp = dsa_slave_to_port(dev);
651 struct dsa_switch *ds = dp->ds;
91da11f8
LB
652
653 if (sset == ETH_SS_STATS) {
654 int count;
655
656 count = 4;
9d490b4e 657 if (ds->ops->get_sset_count)
89f09048 658 count += ds->ops->get_sset_count(ds, dp->index, sset);
91da11f8
LB
659
660 return count;
661 }
662
663 return -EOPNOTSUPP;
664}
665
19e57c4e
FF
666static void dsa_slave_get_wol(struct net_device *dev, struct ethtool_wolinfo *w)
667{
d945097b
VD
668 struct dsa_port *dp = dsa_slave_to_port(dev);
669 struct dsa_switch *ds = dp->ds;
19e57c4e 670
aab9c406
FF
671 phylink_ethtool_get_wol(dp->pl, w);
672
9d490b4e 673 if (ds->ops->get_wol)
d945097b 674 ds->ops->get_wol(ds, dp->index, w);
19e57c4e
FF
675}
676
677static int dsa_slave_set_wol(struct net_device *dev, struct ethtool_wolinfo *w)
678{
d945097b
VD
679 struct dsa_port *dp = dsa_slave_to_port(dev);
680 struct dsa_switch *ds = dp->ds;
19e57c4e
FF
681 int ret = -EOPNOTSUPP;
682
aab9c406
FF
683 phylink_ethtool_set_wol(dp->pl, w);
684
9d490b4e 685 if (ds->ops->set_wol)
d945097b 686 ret = ds->ops->set_wol(ds, dp->index, w);
19e57c4e
FF
687
688 return ret;
689}
690
7905288f
FF
691static int dsa_slave_set_eee(struct net_device *dev, struct ethtool_eee *e)
692{
d945097b
VD
693 struct dsa_port *dp = dsa_slave_to_port(dev);
694 struct dsa_switch *ds = dp->ds;
7905288f
FF
695 int ret;
696
7b9cc738 697 /* Port's PHY and MAC both need to be EEE capable */
00670cb8 698 if (!dev->phydev || !dp->pl)
7b9cc738
VD
699 return -ENODEV;
700
08f50061 701 if (!ds->ops->set_mac_eee)
7905288f
FF
702 return -EOPNOTSUPP;
703
d945097b 704 ret = ds->ops->set_mac_eee(ds, dp->index, e);
7905288f
FF
705 if (ret)
706 return ret;
707
aab9c406 708 return phylink_ethtool_set_eee(dp->pl, e);
7905288f
FF
709}
710
711static int dsa_slave_get_eee(struct net_device *dev, struct ethtool_eee *e)
712{
d945097b
VD
713 struct dsa_port *dp = dsa_slave_to_port(dev);
714 struct dsa_switch *ds = dp->ds;
7905288f
FF
715 int ret;
716
7b9cc738 717 /* Port's PHY and MAC both need to be EEE capable */
00670cb8 718 if (!dev->phydev || !dp->pl)
7b9cc738
VD
719 return -ENODEV;
720
08f50061 721 if (!ds->ops->get_mac_eee)
7905288f
FF
722 return -EOPNOTSUPP;
723
d945097b 724 ret = ds->ops->get_mac_eee(ds, dp->index, e);
7905288f
FF
725 if (ret)
726 return ret;
727
aab9c406
FF
728 return phylink_ethtool_get_eee(dp->pl, e);
729}
730
731static int dsa_slave_get_link_ksettings(struct net_device *dev,
732 struct ethtool_link_ksettings *cmd)
733{
734 struct dsa_port *dp = dsa_slave_to_port(dev);
735
736 return phylink_ethtool_ksettings_get(dp->pl, cmd);
737}
738
739static int dsa_slave_set_link_ksettings(struct net_device *dev,
740 const struct ethtool_link_ksettings *cmd)
741{
742 struct dsa_port *dp = dsa_slave_to_port(dev);
743
744 return phylink_ethtool_ksettings_set(dp->pl, cmd);
7905288f
FF
745}
746
04ff53f9
FF
747#ifdef CONFIG_NET_POLL_CONTROLLER
748static int dsa_slave_netpoll_setup(struct net_device *dev,
749 struct netpoll_info *ni)
750{
d0006b00 751 struct net_device *master = dsa_slave_to_master(dev);
04ff53f9 752 struct dsa_slave_priv *p = netdev_priv(dev);
04ff53f9
FF
753 struct netpoll *netpoll;
754 int err = 0;
755
756 netpoll = kzalloc(sizeof(*netpoll), GFP_KERNEL);
757 if (!netpoll)
758 return -ENOMEM;
759
760 err = __netpoll_setup(netpoll, master);
761 if (err) {
762 kfree(netpoll);
763 goto out;
764 }
765
766 p->netpoll = netpoll;
767out:
768 return err;
769}
770
771static void dsa_slave_netpoll_cleanup(struct net_device *dev)
772{
773 struct dsa_slave_priv *p = netdev_priv(dev);
774 struct netpoll *netpoll = p->netpoll;
775
776 if (!netpoll)
777 return;
778
779 p->netpoll = NULL;
780
c9fbd71f 781 __netpoll_free(netpoll);
04ff53f9
FF
782}
783
784static void dsa_slave_poll_controller(struct net_device *dev)
785{
786}
787#endif
788
44bb765c
FF
789static int dsa_slave_get_phys_port_name(struct net_device *dev,
790 char *name, size_t len)
791{
d945097b 792 struct dsa_port *dp = dsa_slave_to_port(dev);
44bb765c 793
d484210b
JP
794 /* For non-legacy ports, devlink is used and it takes
795 * care of the name generation. This ndo implementation
796 * should be removed with legacy support.
797 */
798 if (dp->ds->devlink)
799 return -EOPNOTSUPP;
800
d945097b 801 if (snprintf(name, len, "p%d", dp->index) >= len)
44bb765c 802 return -EINVAL;
3a543ef4
FF
803
804 return 0;
805}
806
f50f2127 807static struct dsa_mall_tc_entry *
4fa7b718 808dsa_slave_mall_tc_entry_find(struct net_device *dev, unsigned long cookie)
f50f2127 809{
4fa7b718 810 struct dsa_slave_priv *p = netdev_priv(dev);
f50f2127
FF
811 struct dsa_mall_tc_entry *mall_tc_entry;
812
813 list_for_each_entry(mall_tc_entry, &p->mall_tc_list, list)
814 if (mall_tc_entry->cookie == cookie)
815 return mall_tc_entry;
816
817 return NULL;
818}
819
820static int dsa_slave_add_cls_matchall(struct net_device *dev,
f50f2127
FF
821 struct tc_cls_matchall_offload *cls,
822 bool ingress)
823{
d945097b 824 struct dsa_port *dp = dsa_slave_to_port(dev);
f50f2127
FF
825 struct dsa_slave_priv *p = netdev_priv(dev);
826 struct dsa_mall_tc_entry *mall_tc_entry;
5fd9fc4e 827 __be16 protocol = cls->common.protocol;
d945097b 828 struct dsa_switch *ds = dp->ds;
9681e8b3 829 struct flow_action_entry *act;
d945097b 830 struct dsa_port *to_dp;
f50f2127 831 int err = -EOPNOTSUPP;
f50f2127
FF
832
833 if (!ds->ops->port_mirror_add)
834 return err;
835
9681e8b3 836 if (!flow_offload_has_one_action(&cls->rule->action))
f50f2127
FF
837 return err;
838
9681e8b3 839 act = &cls->rule->action.entries[0];
f50f2127 840
9681e8b3 841 if (act->id == FLOW_ACTION_MIRRED && protocol == htons(ETH_P_ALL)) {
f50f2127
FF
842 struct dsa_mall_mirror_tc_entry *mirror;
843
9681e8b3 844 if (!act->dev)
f50f2127
FF
845 return -EINVAL;
846
9681e8b3 847 if (!dsa_slave_dev_check(act->dev))
f50f2127
FF
848 return -EOPNOTSUPP;
849
850 mall_tc_entry = kzalloc(sizeof(*mall_tc_entry), GFP_KERNEL);
851 if (!mall_tc_entry)
852 return -ENOMEM;
853
854 mall_tc_entry->cookie = cls->cookie;
855 mall_tc_entry->type = DSA_PORT_MALL_MIRROR;
856 mirror = &mall_tc_entry->mirror;
857
9681e8b3 858 to_dp = dsa_slave_to_port(act->dev);
f50f2127 859
d945097b 860 mirror->to_local_port = to_dp->index;
f50f2127
FF
861 mirror->ingress = ingress;
862
d945097b 863 err = ds->ops->port_mirror_add(ds, dp->index, mirror, ingress);
f50f2127
FF
864 if (err) {
865 kfree(mall_tc_entry);
866 return err;
867 }
868
869 list_add_tail(&mall_tc_entry->list, &p->mall_tc_list);
870 }
871
872 return 0;
873}
874
875static void dsa_slave_del_cls_matchall(struct net_device *dev,
876 struct tc_cls_matchall_offload *cls)
877{
d945097b 878 struct dsa_port *dp = dsa_slave_to_port(dev);
f50f2127 879 struct dsa_mall_tc_entry *mall_tc_entry;
d945097b 880 struct dsa_switch *ds = dp->ds;
f50f2127
FF
881
882 if (!ds->ops->port_mirror_del)
883 return;
884
4fa7b718 885 mall_tc_entry = dsa_slave_mall_tc_entry_find(dev, cls->cookie);
f50f2127
FF
886 if (!mall_tc_entry)
887 return;
888
889 list_del(&mall_tc_entry->list);
890
891 switch (mall_tc_entry->type) {
892 case DSA_PORT_MALL_MIRROR:
d945097b 893 ds->ops->port_mirror_del(ds, dp->index, &mall_tc_entry->mirror);
f50f2127
FF
894 break;
895 default:
896 WARN_ON(1);
897 }
898
899 kfree(mall_tc_entry);
900}
901
3fbae382 902static int dsa_slave_setup_tc_cls_matchall(struct net_device *dev,
6b3eb752
JP
903 struct tc_cls_matchall_offload *cls,
904 bool ingress)
f50f2127 905{
5fd9fc4e 906 if (cls->common.chain_index)
a5fcf8a6 907 return -EOPNOTSUPP;
f50f2127 908
3fbae382
JP
909 switch (cls->command) {
910 case TC_CLSMATCHALL_REPLACE:
5fd9fc4e 911 return dsa_slave_add_cls_matchall(dev, cls, ingress);
3fbae382
JP
912 case TC_CLSMATCHALL_DESTROY:
913 dsa_slave_del_cls_matchall(dev, cls);
914 return 0;
915 default:
916 return -EOPNOTSUPP;
917 }
918}
919
6b3eb752
JP
920static int dsa_slave_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
921 void *cb_priv, bool ingress)
922{
923 struct net_device *dev = cb_priv;
924
44ae12a7
JP
925 if (!tc_can_offload(dev))
926 return -EOPNOTSUPP;
927
6b3eb752
JP
928 switch (type) {
929 case TC_SETUP_CLSMATCHALL:
930 return dsa_slave_setup_tc_cls_matchall(dev, type_data, ingress);
931 default:
932 return -EOPNOTSUPP;
933 }
934}
935
936static int dsa_slave_setup_tc_block_cb_ig(enum tc_setup_type type,
937 void *type_data, void *cb_priv)
938{
939 return dsa_slave_setup_tc_block_cb(type, type_data, cb_priv, true);
940}
941
942static int dsa_slave_setup_tc_block_cb_eg(enum tc_setup_type type,
943 void *type_data, void *cb_priv)
944{
945 return dsa_slave_setup_tc_block_cb(type, type_data, cb_priv, false);
946}
947
955bcb6e
PNA
948static LIST_HEAD(dsa_slave_block_cb_list);
949
6b3eb752 950static int dsa_slave_setup_tc_block(struct net_device *dev,
955bcb6e 951 struct flow_block_offload *f)
6b3eb752 952{
955bcb6e 953 struct flow_block_cb *block_cb;
6b3eb752
JP
954 tc_setup_cb_t *cb;
955
32f8c409 956 if (f->binder_type == FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
6b3eb752 957 cb = dsa_slave_setup_tc_block_cb_ig;
32f8c409 958 else if (f->binder_type == FLOW_BLOCK_BINDER_TYPE_CLSACT_EGRESS)
6b3eb752
JP
959 cb = dsa_slave_setup_tc_block_cb_eg;
960 else
961 return -EOPNOTSUPP;
962
955bcb6e
PNA
963 f->driver_block_list = &dsa_slave_block_cb_list;
964
6b3eb752 965 switch (f->command) {
9c0e189e 966 case FLOW_BLOCK_BIND:
0d4fd02e
PNA
967 if (flow_block_cb_is_busy(cb, dev, &dsa_slave_block_cb_list))
968 return -EBUSY;
969
0c7294dd 970 block_cb = flow_block_cb_alloc(cb, dev, dev, NULL);
955bcb6e
PNA
971 if (IS_ERR(block_cb))
972 return PTR_ERR(block_cb);
973
974 flow_block_cb_add(block_cb, f);
975 list_add_tail(&block_cb->driver_list, &dsa_slave_block_cb_list);
976 return 0;
9c0e189e 977 case FLOW_BLOCK_UNBIND:
955bcb6e
PNA
978 block_cb = flow_block_cb_lookup(f, cb, dev);
979 if (!block_cb)
980 return -ENOENT;
981
982 flow_block_cb_remove(block_cb, f);
983 list_del(&block_cb->driver_list);
6b3eb752
JP
984 return 0;
985 default:
986 return -EOPNOTSUPP;
987 }
988}
989
3fbae382 990static int dsa_slave_setup_tc(struct net_device *dev, enum tc_setup_type type,
de4784ca 991 void *type_data)
3fbae382 992{
2572ac53 993 switch (type) {
6b3eb752
JP
994 case TC_SETUP_BLOCK:
995 return dsa_slave_setup_tc_block(dev, type_data);
f50f2127 996 default:
a5fcf8a6 997 return -EOPNOTSUPP;
f50f2127 998 }
f50f2127
FF
999}
1000
f613ed66
FF
1001static void dsa_slave_get_stats64(struct net_device *dev,
1002 struct rtnl_link_stats64 *stats)
1003{
1004 struct dsa_slave_priv *p = netdev_priv(dev);
5f6b4e14 1005 struct pcpu_sw_netstats *s;
f613ed66 1006 unsigned int start;
5f6b4e14 1007 int i;
f613ed66
FF
1008
1009 netdev_stats_to_stats64(stats, &dev->stats);
5f6b4e14
FF
1010 for_each_possible_cpu(i) {
1011 u64 tx_packets, tx_bytes, rx_packets, rx_bytes;
1012
1013 s = per_cpu_ptr(p->stats64, i);
1014 do {
1015 start = u64_stats_fetch_begin_irq(&s->syncp);
1016 tx_packets = s->tx_packets;
1017 tx_bytes = s->tx_bytes;
1018 rx_packets = s->rx_packets;
1019 rx_bytes = s->rx_bytes;
1020 } while (u64_stats_fetch_retry_irq(&s->syncp, start));
1021
1022 stats->tx_packets += tx_packets;
1023 stats->tx_bytes += tx_bytes;
1024 stats->rx_packets += rx_packets;
1025 stats->rx_bytes += rx_bytes;
1026 }
f613ed66
FF
1027}
1028
bf9f2648
FF
1029static int dsa_slave_get_rxnfc(struct net_device *dev,
1030 struct ethtool_rxnfc *nfc, u32 *rule_locs)
1031{
d945097b
VD
1032 struct dsa_port *dp = dsa_slave_to_port(dev);
1033 struct dsa_switch *ds = dp->ds;
bf9f2648
FF
1034
1035 if (!ds->ops->get_rxnfc)
1036 return -EOPNOTSUPP;
1037
d945097b 1038 return ds->ops->get_rxnfc(ds, dp->index, nfc, rule_locs);
bf9f2648
FF
1039}
1040
1041static int dsa_slave_set_rxnfc(struct net_device *dev,
1042 struct ethtool_rxnfc *nfc)
1043{
d945097b
VD
1044 struct dsa_port *dp = dsa_slave_to_port(dev);
1045 struct dsa_switch *ds = dp->ds;
bf9f2648
FF
1046
1047 if (!ds->ops->set_rxnfc)
1048 return -EOPNOTSUPP;
1049
d945097b 1050 return ds->ops->set_rxnfc(ds, dp->index, nfc);
bf9f2648
FF
1051}
1052
0336369d
BS
1053static int dsa_slave_get_ts_info(struct net_device *dev,
1054 struct ethtool_ts_info *ts)
1055{
1056 struct dsa_slave_priv *p = netdev_priv(dev);
1057 struct dsa_switch *ds = p->dp->ds;
1058
1059 if (!ds->ops->get_ts_info)
1060 return -EOPNOTSUPP;
1061
1062 return ds->ops->get_ts_info(ds, p->dp->index, ts);
1063}
1064
061f6a50
FF
1065static int dsa_slave_vlan_rx_add_vid(struct net_device *dev, __be16 proto,
1066 u16 vid)
1067{
1068 struct dsa_port *dp = dsa_slave_to_port(dev);
061f6a50
FF
1069 struct bridge_vlan_info info;
1070 int ret;
1071
1072 /* Check for a possible bridge VLAN entry now since there is no
1073 * need to emulate the switchdev prepare + commit phase.
1074 */
1075 if (dp->bridge_dev) {
1076 /* br_vlan_get_info() returns -EINVAL or -ENOENT if the
1077 * device, respectively the VID is not found, returning
1078 * 0 means success, which is a failure for us here.
1079 */
1080 ret = br_vlan_get_info(dp->bridge_dev, vid, &info);
1081 if (ret == 0)
1082 return -EBUSY;
1083 }
1084
314f76d7
VO
1085 /* This API only allows programming tagged, non-PVID VIDs */
1086 return dsa_port_vid_add(dp, vid, 0);
061f6a50
FF
1087}
1088
1089static int dsa_slave_vlan_rx_kill_vid(struct net_device *dev, __be16 proto,
1090 u16 vid)
1091{
1092 struct dsa_port *dp = dsa_slave_to_port(dev);
061f6a50
FF
1093 struct bridge_vlan_info info;
1094 int ret;
1095
1096 /* Check for a possible bridge VLAN entry now since there is no
1097 * need to emulate the switchdev prepare + commit phase.
1098 */
1099 if (dp->bridge_dev) {
1100 /* br_vlan_get_info() returns -EINVAL or -ENOENT if the
1101 * device, respectively the VID is not found, returning
1102 * 0 means success, which is a failure for us here.
1103 */
1104 ret = br_vlan_get_info(dp->bridge_dev, vid, &info);
1105 if (ret == 0)
1106 return -EBUSY;
1107 }
1108
314f76d7 1109 ret = dsa_port_vid_del(dp, vid);
061f6a50
FF
1110 if (ret == -EOPNOTSUPP)
1111 ret = 0;
1112
1113 return ret;
1114}
1115
91da11f8 1116static const struct ethtool_ops dsa_slave_ethtool_ops = {
91da11f8 1117 .get_drvinfo = dsa_slave_get_drvinfo,
3d762a0f
GR
1118 .get_regs_len = dsa_slave_get_regs_len,
1119 .get_regs = dsa_slave_get_regs,
aab9c406 1120 .nway_reset = dsa_slave_nway_reset,
c4aef9fc 1121 .get_link = ethtool_op_get_link,
6793abb4
GR
1122 .get_eeprom_len = dsa_slave_get_eeprom_len,
1123 .get_eeprom = dsa_slave_get_eeprom,
1124 .set_eeprom = dsa_slave_set_eeprom,
91da11f8
LB
1125 .get_strings = dsa_slave_get_strings,
1126 .get_ethtool_stats = dsa_slave_get_ethtool_stats,
1127 .get_sset_count = dsa_slave_get_sset_count,
19e57c4e
FF
1128 .set_wol = dsa_slave_set_wol,
1129 .get_wol = dsa_slave_get_wol,
7905288f
FF
1130 .set_eee = dsa_slave_set_eee,
1131 .get_eee = dsa_slave_get_eee,
aab9c406
FF
1132 .get_link_ksettings = dsa_slave_get_link_ksettings,
1133 .set_link_ksettings = dsa_slave_set_link_ksettings,
bf9f2648
FF
1134 .get_rxnfc = dsa_slave_get_rxnfc,
1135 .set_rxnfc = dsa_slave_set_rxnfc,
0336369d 1136 .get_ts_info = dsa_slave_get_ts_info,
91da11f8
LB
1137};
1138
2a93c1a3
FF
1139/* legacy way, bypassing the bridge *****************************************/
1140int dsa_legacy_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
1141 struct net_device *dev,
1142 const unsigned char *addr, u16 vid,
87b0984e
PM
1143 u16 flags,
1144 struct netlink_ext_ack *extack)
2a93c1a3
FF
1145{
1146 struct dsa_port *dp = dsa_slave_to_port(dev);
1147
1148 return dsa_port_fdb_add(dp, addr, vid);
1149}
1150
1151int dsa_legacy_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
1152 struct net_device *dev,
1153 const unsigned char *addr, u16 vid)
1154{
1155 struct dsa_port *dp = dsa_slave_to_port(dev);
1156
1157 return dsa_port_fdb_del(dp, addr, vid);
1158}
1159
716efee2
JP
1160static struct devlink_port *dsa_slave_get_devlink_port(struct net_device *dev)
1161{
1162 struct dsa_port *dp = dsa_slave_to_port(dev);
1163
1164 return dp->ds->devlink ? &dp->devlink_port : NULL;
1165}
1166
3e8a72d1 1167static const struct net_device_ops dsa_slave_netdev_ops = {
d442ad4a
SH
1168 .ndo_open = dsa_slave_open,
1169 .ndo_stop = dsa_slave_close,
3e8a72d1 1170 .ndo_start_xmit = dsa_slave_xmit,
d442ad4a
SH
1171 .ndo_change_rx_flags = dsa_slave_change_rx_flags,
1172 .ndo_set_rx_mode = dsa_slave_set_rx_mode,
d442ad4a 1173 .ndo_set_mac_address = dsa_slave_set_mac_address,
37b8da1a
AS
1174 .ndo_fdb_add = dsa_legacy_fdb_add,
1175 .ndo_fdb_del = dsa_legacy_fdb_del,
2bedde1a 1176 .ndo_fdb_dump = dsa_slave_fdb_dump,
d442ad4a 1177 .ndo_do_ioctl = dsa_slave_ioctl,
abd2be00 1178 .ndo_get_iflink = dsa_slave_get_iflink,
04ff53f9
FF
1179#ifdef CONFIG_NET_POLL_CONTROLLER
1180 .ndo_netpoll_setup = dsa_slave_netpoll_setup,
1181 .ndo_netpoll_cleanup = dsa_slave_netpoll_cleanup,
1182 .ndo_poll_controller = dsa_slave_poll_controller,
1183#endif
44bb765c 1184 .ndo_get_phys_port_name = dsa_slave_get_phys_port_name,
f50f2127 1185 .ndo_setup_tc = dsa_slave_setup_tc,
f613ed66 1186 .ndo_get_stats64 = dsa_slave_get_stats64,
929d6c14 1187 .ndo_get_port_parent_id = dsa_slave_get_port_parent_id,
061f6a50
FF
1188 .ndo_vlan_rx_add_vid = dsa_slave_vlan_rx_add_vid,
1189 .ndo_vlan_rx_kill_vid = dsa_slave_vlan_rx_kill_vid,
716efee2 1190 .ndo_get_devlink_port = dsa_slave_get_devlink_port,
98237d43
SF
1191};
1192
f37db85d
FF
1193static struct device_type dsa_type = {
1194 .name = "dsa",
1195};
1196
aab9c406
FF
1197void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up)
1198{
1199 const struct dsa_port *dp = dsa_to_port(ds, port);
1200
1201 phylink_mac_change(dp->pl, up);
1202}
1203EXPORT_SYMBOL_GPL(dsa_port_phylink_mac_change);
1204
1205static void dsa_slave_phylink_fixed_state(struct net_device *dev,
1206 struct phylink_link_state *state)
1207{
1208 struct dsa_port *dp = dsa_slave_to_port(dev);
1209 struct dsa_switch *ds = dp->ds;
1210
1211 /* No need to check that this operation is valid, the callback would
1212 * not be called if it was not.
1213 */
1214 ds->ops->phylink_fixed_state(ds, dp->index, state);
ce31b31c
FF
1215}
1216
91da11f8 1217/* slave device setup *******************************************************/
4fa7b718 1218static int dsa_slave_phy_connect(struct net_device *slave_dev, int addr)
c305c165 1219{
d945097b 1220 struct dsa_port *dp = dsa_slave_to_port(slave_dev);
d945097b 1221 struct dsa_switch *ds = dp->ds;
c305c165 1222
0115dcd1
VD
1223 slave_dev->phydev = mdiobus_get_phy(ds->slave_mii_bus, addr);
1224 if (!slave_dev->phydev) {
d25b8e74 1225 netdev_err(slave_dev, "no phy at %d\n", addr);
c305c165 1226 return -ENODEV;
d25b8e74 1227 }
c305c165 1228
aab9c406 1229 return phylink_connect_phy(dp->pl, slave_dev->phydev);
11d8f3dd 1230}
11d8f3dd 1231
4fa7b718 1232static int dsa_slave_phy_setup(struct net_device *slave_dev)
0d8bcdd3 1233{
d945097b 1234 struct dsa_port *dp = dsa_slave_to_port(slave_dev);
d945097b
VD
1235 struct device_node *port_dn = dp->dn;
1236 struct dsa_switch *ds = dp->ds;
6819563e 1237 u32 phy_flags = 0;
19334920 1238 int mode, ret;
0d8bcdd3 1239
19334920
GR
1240 mode = of_get_phy_mode(port_dn);
1241 if (mode < 0)
1242 mode = PHY_INTERFACE_MODE_NA;
0d8bcdd3 1243
44cc27e4
IC
1244 dp->pl_config.dev = &slave_dev->dev;
1245 dp->pl_config.type = PHYLINK_NETDEV;
1246
1247 dp->pl = phylink_create(&dp->pl_config, of_fwnode_handle(port_dn), mode,
77373d49 1248 &dsa_port_phylink_mac_ops);
aab9c406
FF
1249 if (IS_ERR(dp->pl)) {
1250 netdev_err(slave_dev,
1251 "error creating PHYLINK: %ld\n", PTR_ERR(dp->pl));
1252 return PTR_ERR(dp->pl);
0d8bcdd3
FF
1253 }
1254
aab9c406
FF
1255 /* Register only if the switch provides such a callback, since this
1256 * callback takes precedence over polling the link GPIO in PHYLINK
1257 * (see phylink_get_fixed_state).
1258 */
1259 if (ds->ops->phylink_fixed_state)
1260 phylink_fixed_state_cb(dp->pl, dsa_slave_phylink_fixed_state);
1261
9d490b4e 1262 if (ds->ops->get_phy_flags)
d945097b 1263 phy_flags = ds->ops->get_phy_flags(ds, dp->index);
6819563e 1264
aab9c406 1265 ret = phylink_of_phy_connect(dp->pl, port_dn, phy_flags);
6146dd45
VO
1266 if (ret == -ENODEV && ds->slave_mii_bus) {
1267 /* We could not connect to a designated PHY or SFP, so try to
1268 * use the switch internal MDIO bus instead
aab9c406 1269 */
d945097b 1270 ret = dsa_slave_phy_connect(slave_dev, dp->index);
d25b8e74 1271 if (ret) {
aab9c406
FF
1272 netdev_err(slave_dev,
1273 "failed to connect to port %d: %d\n",
d945097b 1274 dp->index, ret);
aab9c406 1275 phylink_destroy(dp->pl);
c305c165 1276 return ret;
d25b8e74 1277 }
b31f65fb 1278 }
9697f1cd 1279
6146dd45 1280 return ret;
0d8bcdd3
FF
1281}
1282
448b4482
AL
1283static struct lock_class_key dsa_slave_netdev_xmit_lock_key;
1284static void dsa_slave_set_lockdep_class_one(struct net_device *dev,
1285 struct netdev_queue *txq,
1286 void *_unused)
1287{
1288 lockdep_set_class(&txq->_xmit_lock,
1289 &dsa_slave_netdev_xmit_lock_key);
1290}
1291
24462549
FF
1292int dsa_slave_suspend(struct net_device *slave_dev)
1293{
aab9c406 1294 struct dsa_port *dp = dsa_slave_to_port(slave_dev);
24462549 1295
a94c689e
FF
1296 if (!netif_running(slave_dev))
1297 return 0;
1298
97a69a0d
VO
1299 cancel_work_sync(&dp->xmit_work);
1300 skb_queue_purge(&dp->xmit_queue);
1301
f154be24
FF
1302 netif_device_detach(slave_dev);
1303
aab9c406
FF
1304 rtnl_lock();
1305 phylink_stop(dp->pl);
1306 rtnl_unlock();
24462549
FF
1307
1308 return 0;
1309}
1310
1311int dsa_slave_resume(struct net_device *slave_dev)
1312{
aab9c406
FF
1313 struct dsa_port *dp = dsa_slave_to_port(slave_dev);
1314
a94c689e
FF
1315 if (!netif_running(slave_dev))
1316 return 0;
1317
24462549
FF
1318 netif_device_attach(slave_dev);
1319
aab9c406
FF
1320 rtnl_lock();
1321 phylink_start(dp->pl);
1322 rtnl_unlock();
24462549
FF
1323
1324 return 0;
1325}
1326
6158eaa7
VD
1327static void dsa_slave_notify(struct net_device *dev, unsigned long val)
1328{
d0006b00 1329 struct net_device *master = dsa_slave_to_master(dev);
d945097b 1330 struct dsa_port *dp = dsa_slave_to_port(dev);
6158eaa7
VD
1331 struct dsa_notifier_register_info rinfo = {
1332 .switch_number = dp->ds->index,
1333 .port_number = dp->index,
1334 .master = master,
1335 .info.dev = dev,
1336 };
1337
1338 call_dsa_notifiers(val, dev, &rinfo.info);
1339}
1340
951259aa 1341int dsa_slave_create(struct dsa_port *port)
91da11f8 1342{
24a9332a 1343 const struct dsa_port *cpu_dp = port->cpu_dp;
f8b8b1cd 1344 struct net_device *master = cpu_dp->master;
4cfbf09c 1345 struct dsa_switch *ds = port->ds;
951259aa 1346 const char *name = port->name;
91da11f8
LB
1347 struct net_device *slave_dev;
1348 struct dsa_slave_priv *p;
1349 int ret;
1350
55199df6
FF
1351 if (!ds->num_tx_queues)
1352 ds->num_tx_queues = 1;
1353
1354 slave_dev = alloc_netdev_mqs(sizeof(struct dsa_slave_priv), name,
1355 NET_NAME_UNKNOWN, ether_setup,
1356 ds->num_tx_queues, 1);
91da11f8 1357 if (slave_dev == NULL)
d87d6f44 1358 return -ENOMEM;
91da11f8 1359
061f6a50
FF
1360 slave_dev->features = master->vlan_features | NETIF_F_HW_TC |
1361 NETIF_F_HW_VLAN_CTAG_FILTER;
f50f2127 1362 slave_dev->hw_features |= NETIF_F_HW_TC;
7ad24ea4 1363 slave_dev->ethtool_ops = &dsa_slave_ethtool_ops;
4974f9b7 1364 if (!IS_ERR_OR_NULL(port->mac))
a2c7023f
XS
1365 ether_addr_copy(slave_dev->dev_addr, port->mac);
1366 else
1367 eth_hw_addr_inherit(slave_dev, master);
0a5f107b 1368 slave_dev->priv_flags |= IFF_NO_QUEUE;
3e8a72d1 1369 slave_dev->netdev_ops = &dsa_slave_netdev_ops;
8b1efc0f
JW
1370 slave_dev->min_mtu = 0;
1371 slave_dev->max_mtu = ETH_MAX_MTU;
f37db85d 1372 SET_NETDEV_DEVTYPE(slave_dev, &dsa_type);
d442ad4a 1373
448b4482
AL
1374 netdev_for_each_tx_queue(slave_dev, dsa_slave_set_lockdep_class_one,
1375 NULL);
1376
4cfbf09c
VD
1377 SET_NETDEV_DEV(slave_dev, port->ds->dev);
1378 slave_dev->dev.of_node = port->dn;
5075314e
AD
1379 slave_dev->vlan_features = master->vlan_features;
1380
1381 p = netdev_priv(slave_dev);
5f6b4e14
FF
1382 p->stats64 = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
1383 if (!p->stats64) {
1384 free_netdev(slave_dev);
1385 return -ENOMEM;
1386 }
4cfbf09c 1387 p->dp = port;
f50f2127 1388 INIT_LIST_HEAD(&p->mall_tc_list);
97a69a0d
VO
1389 INIT_WORK(&port->xmit_work, dsa_port_xmit_work);
1390 skb_queue_head_init(&port->xmit_queue);
15240248 1391 p->xmit = cpu_dp->tag_ops->xmit;
f8b8b1cd 1392 port->slave = slave_dev;
91da11f8
LB
1393
1394 netif_carrier_off(slave_dev);
1395
4fa7b718 1396 ret = dsa_slave_phy_setup(slave_dev);
0071f56e
AL
1397 if (ret) {
1398 netdev_err(master, "error %d setting up slave phy\n", ret);
e804441c
FF
1399 goto out_free;
1400 }
1401
6158eaa7 1402 dsa_slave_notify(slave_dev, DSA_PORT_REGISTER);
60724d4b 1403
e804441c
FF
1404 ret = register_netdev(slave_dev);
1405 if (ret) {
1406 netdev_err(master, "error %d registering interface %s\n",
1407 ret, slave_dev->name);
1408 goto out_phy;
0071f56e
AL
1409 }
1410
d87d6f44 1411 return 0;
e804441c
FF
1412
1413out_phy:
aab9c406
FF
1414 rtnl_lock();
1415 phylink_disconnect_phy(p->dp->pl);
1416 rtnl_unlock();
1417 phylink_destroy(p->dp->pl);
e804441c
FF
1418out_free:
1419 free_percpu(p->stats64);
1420 free_netdev(slave_dev);
f8b8b1cd 1421 port->slave = NULL;
e804441c 1422 return ret;
91da11f8 1423}
b73adef6 1424
cda5c15b
NA
1425void dsa_slave_destroy(struct net_device *slave_dev)
1426{
d945097b 1427 struct dsa_port *dp = dsa_slave_to_port(slave_dev);
cda5c15b
NA
1428 struct dsa_slave_priv *p = netdev_priv(slave_dev);
1429
1430 netif_carrier_off(slave_dev);
aab9c406
FF
1431 rtnl_lock();
1432 phylink_disconnect_phy(dp->pl);
1433 rtnl_unlock();
881eadab 1434
6158eaa7 1435 dsa_slave_notify(slave_dev, DSA_PORT_UNREGISTER);
cda5c15b 1436 unregister_netdev(slave_dev);
aab9c406 1437 phylink_destroy(dp->pl);
5f6b4e14 1438 free_percpu(p->stats64);
cda5c15b
NA
1439 free_netdev(slave_dev);
1440}
1441
f3b78049 1442static bool dsa_slave_dev_check(const struct net_device *dev)
b73adef6
FF
1443{
1444 return dev->netdev_ops == &dsa_slave_netdev_ops;
1445}
1446
8e92ab3a
VD
1447static int dsa_slave_changeupper(struct net_device *dev,
1448 struct netdev_notifier_changeupper_info *info)
b73adef6 1449{
d945097b 1450 struct dsa_port *dp = dsa_slave_to_port(dev);
8e92ab3a 1451 int err = NOTIFY_DONE;
b73adef6 1452
8e92ab3a
VD
1453 if (netif_is_bridge_master(info->upper_dev)) {
1454 if (info->linking) {
17d7802b 1455 err = dsa_port_bridge_join(dp, info->upper_dev);
8e92ab3a
VD
1456 err = notifier_from_errno(err);
1457 } else {
17d7802b 1458 dsa_port_bridge_leave(dp, info->upper_dev);
8e92ab3a 1459 err = NOTIFY_OK;
6debb68a 1460 }
6debb68a 1461 }
b73adef6 1462
8e92ab3a 1463 return err;
6debb68a 1464}
b73adef6 1465
cc1d5bda
FF
1466static int dsa_slave_upper_vlan_check(struct net_device *dev,
1467 struct netdev_notifier_changeupper_info *
1468 info)
1469{
1470 struct netlink_ext_ack *ext_ack;
1471 struct net_device *slave;
1472 struct dsa_port *dp;
1473
1474 ext_ack = netdev_notifier_info_to_extack(&info->info);
1475
1476 if (!is_vlan_dev(dev))
1477 return NOTIFY_DONE;
1478
1479 slave = vlan_dev_real_dev(dev);
1480 if (!dsa_slave_dev_check(slave))
1481 return NOTIFY_DONE;
1482
1483 dp = dsa_slave_to_port(slave);
1484 if (!dp->bridge_dev)
1485 return NOTIFY_DONE;
1486
1487 /* Deny enslaving a VLAN device into a VLAN-aware bridge */
1488 if (br_vlan_enabled(dp->bridge_dev) &&
1489 netif_is_bridge_master(info->upper_dev) && info->linking) {
1490 NL_SET_ERR_MSG_MOD(ext_ack,
1491 "Cannot enslave VLAN device into VLAN aware bridge");
1492 return notifier_from_errno(-EINVAL);
1493 }
1494
1495 return NOTIFY_DONE;
1496}
1497
88e4f0ca
VD
1498static int dsa_slave_netdevice_event(struct notifier_block *nb,
1499 unsigned long event, void *ptr)
6debb68a
VD
1500{
1501 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
1502
cc1d5bda
FF
1503 if (event == NETDEV_CHANGEUPPER) {
1504 if (!dsa_slave_dev_check(dev))
1505 return dsa_slave_upper_vlan_check(dev, ptr);
8e92ab3a 1506
8e92ab3a 1507 return dsa_slave_changeupper(dev, ptr);
cc1d5bda 1508 }
b73adef6 1509
b73adef6
FF
1510 return NOTIFY_DONE;
1511}
88e4f0ca 1512
c9eb3e0f
AS
1513struct dsa_switchdev_event_work {
1514 struct work_struct work;
1515 struct switchdev_notifier_fdb_info fdb_info;
1516 struct net_device *dev;
1517 unsigned long event;
1518};
1519
1520static void dsa_slave_switchdev_event_work(struct work_struct *work)
1521{
1522 struct dsa_switchdev_event_work *switchdev_work =
1523 container_of(work, struct dsa_switchdev_event_work, work);
1524 struct net_device *dev = switchdev_work->dev;
1525 struct switchdev_notifier_fdb_info *fdb_info;
d945097b 1526 struct dsa_port *dp = dsa_slave_to_port(dev);
c9eb3e0f
AS
1527 int err;
1528
1529 rtnl_lock();
1530 switch (switchdev_work->event) {
1531 case SWITCHDEV_FDB_ADD_TO_DEVICE:
1532 fdb_info = &switchdev_work->fdb_info;
a37fb855
VD
1533 if (!fdb_info->added_by_user)
1534 break;
1535
d945097b 1536 err = dsa_port_fdb_add(dp, fdb_info->addr, fdb_info->vid);
c9eb3e0f
AS
1537 if (err) {
1538 netdev_dbg(dev, "fdb add failed err=%d\n", err);
1539 break;
1540 }
e9ba0fbc 1541 fdb_info->offloaded = true;
c9eb3e0f 1542 call_switchdev_notifiers(SWITCHDEV_FDB_OFFLOADED, dev,
6685987c 1543 &fdb_info->info, NULL);
c9eb3e0f
AS
1544 break;
1545
1546 case SWITCHDEV_FDB_DEL_TO_DEVICE:
1547 fdb_info = &switchdev_work->fdb_info;
a37fb855
VD
1548 if (!fdb_info->added_by_user)
1549 break;
1550
d945097b 1551 err = dsa_port_fdb_del(dp, fdb_info->addr, fdb_info->vid);
c9eb3e0f
AS
1552 if (err) {
1553 netdev_dbg(dev, "fdb del failed err=%d\n", err);
1554 dev_close(dev);
1555 }
1556 break;
1557 }
1558 rtnl_unlock();
1559
1560 kfree(switchdev_work->fdb_info.addr);
1561 kfree(switchdev_work);
1562 dev_put(dev);
1563}
1564
1565static int
1566dsa_slave_switchdev_fdb_work_init(struct dsa_switchdev_event_work *
1567 switchdev_work,
1568 const struct switchdev_notifier_fdb_info *
1569 fdb_info)
1570{
1571 memcpy(&switchdev_work->fdb_info, fdb_info,
1572 sizeof(switchdev_work->fdb_info));
1573 switchdev_work->fdb_info.addr = kzalloc(ETH_ALEN, GFP_ATOMIC);
1574 if (!switchdev_work->fdb_info.addr)
1575 return -ENOMEM;
1576 ether_addr_copy((u8 *)switchdev_work->fdb_info.addr,
1577 fdb_info->addr);
1578 return 0;
1579}
1580
1581/* Called under rcu_read_lock() */
1582static int dsa_slave_switchdev_event(struct notifier_block *unused,
1583 unsigned long event, void *ptr)
1584{
1585 struct net_device *dev = switchdev_notifier_info_to_dev(ptr);
1586 struct dsa_switchdev_event_work *switchdev_work;
79b139f4
VD
1587 int err;
1588
1589 if (event == SWITCHDEV_PORT_ATTR_SET) {
1590 err = switchdev_handle_port_attr_set(dev, ptr,
1591 dsa_slave_dev_check,
1592 dsa_slave_port_attr_set);
1593 return notifier_from_errno(err);
1594 }
c9eb3e0f
AS
1595
1596 if (!dsa_slave_dev_check(dev))
1597 return NOTIFY_DONE;
1598
1599 switchdev_work = kzalloc(sizeof(*switchdev_work), GFP_ATOMIC);
1600 if (!switchdev_work)
1601 return NOTIFY_BAD;
1602
1603 INIT_WORK(&switchdev_work->work,
1604 dsa_slave_switchdev_event_work);
1605 switchdev_work->dev = dev;
1606 switchdev_work->event = event;
1607
1608 switch (event) {
1609 case SWITCHDEV_FDB_ADD_TO_DEVICE: /* fall through */
1610 case SWITCHDEV_FDB_DEL_TO_DEVICE:
a37fb855 1611 if (dsa_slave_switchdev_fdb_work_init(switchdev_work, ptr))
c9eb3e0f
AS
1612 goto err_fdb_work_init;
1613 dev_hold(dev);
1614 break;
1615 default:
1616 kfree(switchdev_work);
1617 return NOTIFY_DONE;
1618 }
1619
1620 dsa_schedule_work(&switchdev_work->work);
1621 return NOTIFY_OK;
1622
1623err_fdb_work_init:
1624 kfree(switchdev_work);
1625 return NOTIFY_BAD;
1626}
1627
2b239f67
PM
1628static int dsa_slave_switchdev_blocking_event(struct notifier_block *unused,
1629 unsigned long event, void *ptr)
1630{
1631 struct net_device *dev = switchdev_notifier_info_to_dev(ptr);
79b139f4 1632 int err;
2b239f67
PM
1633
1634 switch (event) {
79b139f4
VD
1635 case SWITCHDEV_PORT_OBJ_ADD:
1636 err = switchdev_handle_port_obj_add(dev, ptr,
1637 dsa_slave_dev_check,
1638 dsa_slave_port_obj_add);
1639 return notifier_from_errno(err);
2b239f67 1640 case SWITCHDEV_PORT_OBJ_DEL:
79b139f4
VD
1641 err = switchdev_handle_port_obj_del(dev, ptr,
1642 dsa_slave_dev_check,
1643 dsa_slave_port_obj_del);
1644 return notifier_from_errno(err);
9ed1eced 1645 case SWITCHDEV_PORT_ATTR_SET:
79b139f4
VD
1646 err = switchdev_handle_port_attr_set(dev, ptr,
1647 dsa_slave_dev_check,
1648 dsa_slave_port_attr_set);
1649 return notifier_from_errno(err);
2b239f67
PM
1650 }
1651
1652 return NOTIFY_DONE;
1653}
1654
88e4f0ca 1655static struct notifier_block dsa_slave_nb __read_mostly = {
c9eb3e0f
AS
1656 .notifier_call = dsa_slave_netdevice_event,
1657};
1658
1659static struct notifier_block dsa_slave_switchdev_notifier = {
1660 .notifier_call = dsa_slave_switchdev_event,
88e4f0ca
VD
1661};
1662
2b239f67
PM
1663static struct notifier_block dsa_slave_switchdev_blocking_notifier = {
1664 .notifier_call = dsa_slave_switchdev_blocking_event,
1665};
1666
88e4f0ca
VD
1667int dsa_slave_register_notifier(void)
1668{
2b239f67 1669 struct notifier_block *nb;
c9eb3e0f
AS
1670 int err;
1671
1672 err = register_netdevice_notifier(&dsa_slave_nb);
1673 if (err)
1674 return err;
1675
1676 err = register_switchdev_notifier(&dsa_slave_switchdev_notifier);
1677 if (err)
1678 goto err_switchdev_nb;
1679
2b239f67
PM
1680 nb = &dsa_slave_switchdev_blocking_notifier;
1681 err = register_switchdev_blocking_notifier(nb);
1682 if (err)
1683 goto err_switchdev_blocking_nb;
1684
c9eb3e0f
AS
1685 return 0;
1686
2b239f67
PM
1687err_switchdev_blocking_nb:
1688 unregister_switchdev_notifier(&dsa_slave_switchdev_notifier);
c9eb3e0f
AS
1689err_switchdev_nb:
1690 unregister_netdevice_notifier(&dsa_slave_nb);
1691 return err;
88e4f0ca
VD
1692}
1693
1694void dsa_slave_unregister_notifier(void)
1695{
2b239f67 1696 struct notifier_block *nb;
88e4f0ca
VD
1697 int err;
1698
2b239f67
PM
1699 nb = &dsa_slave_switchdev_blocking_notifier;
1700 err = unregister_switchdev_blocking_notifier(nb);
1701 if (err)
1702 pr_err("DSA: failed to unregister switchdev blocking notifier (%d)\n", err);
1703
c9eb3e0f
AS
1704 err = unregister_switchdev_notifier(&dsa_slave_switchdev_notifier);
1705 if (err)
1706 pr_err("DSA: failed to unregister switchdev notifier (%d)\n", err);
1707
88e4f0ca
VD
1708 err = unregister_netdevice_notifier(&dsa_slave_nb);
1709 if (err)
1710 pr_err("DSA: failed to unregister slave notifier (%d)\n", err);
1711}