]>
Commit | Line | Data |
---|---|---|
91da11f8 LB |
1 | /* |
2 | * net/dsa/slave.c - Slave device handling | |
e84665c9 | 3 | * Copyright (c) 2008-2009 Marvell Semiconductor |
91da11f8 LB |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation; either version 2 of the License, or | |
8 | * (at your option) any later version. | |
9 | */ | |
10 | ||
11 | #include <linux/list.h> | |
df02c6ff | 12 | #include <linux/etherdevice.h> |
b73adef6 | 13 | #include <linux/netdevice.h> |
91da11f8 | 14 | #include <linux/phy.h> |
a2820543 | 15 | #include <linux/phy_fixed.h> |
0d8bcdd3 FF |
16 | #include <linux/of_net.h> |
17 | #include <linux/of_mdio.h> | |
7f854420 | 18 | #include <linux/mdio.h> |
f50f2127 | 19 | #include <linux/list.h> |
b73adef6 | 20 | #include <net/rtnetlink.h> |
f50f2127 FF |
21 | #include <net/pkt_cls.h> |
22 | #include <net/tc_act/tc_mirred.h> | |
b73adef6 | 23 | #include <linux/if_bridge.h> |
04ff53f9 | 24 | #include <linux/netpoll.h> |
ea5dd34b | 25 | |
91da11f8 LB |
26 | #include "dsa_priv.h" |
27 | ||
f50f2127 FF |
28 | static bool dsa_slave_dev_check(struct net_device *dev); |
29 | ||
91da11f8 LB |
30 | /* slave mii_bus handling ***************************************************/ |
31 | static int dsa_slave_phy_read(struct mii_bus *bus, int addr, int reg) | |
32 | { | |
33 | struct dsa_switch *ds = bus->priv; | |
34 | ||
0d8bcdd3 | 35 | if (ds->phys_mii_mask & (1 << addr)) |
9d490b4e | 36 | return ds->ops->phy_read(ds, addr, reg); |
91da11f8 LB |
37 | |
38 | return 0xffff; | |
39 | } | |
40 | ||
41 | static int dsa_slave_phy_write(struct mii_bus *bus, int addr, int reg, u16 val) | |
42 | { | |
43 | struct dsa_switch *ds = bus->priv; | |
44 | ||
0d8bcdd3 | 45 | if (ds->phys_mii_mask & (1 << addr)) |
9d490b4e | 46 | return ds->ops->phy_write(ds, addr, reg, val); |
91da11f8 LB |
47 | |
48 | return 0; | |
49 | } | |
50 | ||
51 | void dsa_slave_mii_bus_init(struct dsa_switch *ds) | |
52 | { | |
53 | ds->slave_mii_bus->priv = (void *)ds; | |
54 | ds->slave_mii_bus->name = "dsa slave smi"; | |
55 | ds->slave_mii_bus->read = dsa_slave_phy_read; | |
56 | ds->slave_mii_bus->write = dsa_slave_phy_write; | |
0b7b498d | 57 | snprintf(ds->slave_mii_bus->id, MII_BUS_ID_SIZE, "dsa-%d.%d", |
49463b7f | 58 | ds->dst->index, ds->index); |
c33063d6 | 59 | ds->slave_mii_bus->parent = ds->dev; |
24df8986 | 60 | ds->slave_mii_bus->phy_mask = ~ds->phys_mii_mask; |
91da11f8 LB |
61 | } |
62 | ||
63 | ||
64 | /* slave device handling ****************************************************/ | |
abd2be00 | 65 | static int dsa_slave_get_iflink(const struct net_device *dev) |
c0840801 | 66 | { |
d0006b00 | 67 | return dsa_slave_to_master(dev)->ifindex; |
c0840801 LB |
68 | } |
69 | ||
91da11f8 LB |
70 | static int dsa_slave_open(struct net_device *dev) |
71 | { | |
d0006b00 | 72 | struct net_device *master = dsa_slave_to_master(dev); |
d945097b | 73 | struct dsa_port *dp = dsa_slave_to_port(dev); |
df02c6ff LB |
74 | int err; |
75 | ||
76 | if (!(master->flags & IFF_UP)) | |
77 | return -ENETDOWN; | |
78 | ||
8feedbb4 | 79 | if (!ether_addr_equal(dev->dev_addr, master->dev_addr)) { |
a748ee24 | 80 | err = dev_uc_add(master, dev->dev_addr); |
df02c6ff LB |
81 | if (err < 0) |
82 | goto out; | |
83 | } | |
84 | ||
85 | if (dev->flags & IFF_ALLMULTI) { | |
86 | err = dev_set_allmulti(master, 1); | |
87 | if (err < 0) | |
88 | goto del_unicast; | |
89 | } | |
90 | if (dev->flags & IFF_PROMISC) { | |
91 | err = dev_set_promiscuity(master, 1); | |
92 | if (err < 0) | |
93 | goto clear_allmulti; | |
94 | } | |
95 | ||
0115dcd1 | 96 | err = dsa_port_enable(dp, dev->phydev); |
fb8a6a2b VD |
97 | if (err) |
98 | goto clear_promisc; | |
b73adef6 | 99 | |
0115dcd1 VD |
100 | if (dev->phydev) |
101 | phy_start(dev->phydev); | |
f7f1de51 | 102 | |
91da11f8 | 103 | return 0; |
df02c6ff | 104 | |
b2f2af21 FF |
105 | clear_promisc: |
106 | if (dev->flags & IFF_PROMISC) | |
4fdeddfe | 107 | dev_set_promiscuity(master, -1); |
df02c6ff LB |
108 | clear_allmulti: |
109 | if (dev->flags & IFF_ALLMULTI) | |
110 | dev_set_allmulti(master, -1); | |
111 | del_unicast: | |
8feedbb4 | 112 | if (!ether_addr_equal(dev->dev_addr, master->dev_addr)) |
a748ee24 | 113 | dev_uc_del(master, dev->dev_addr); |
df02c6ff LB |
114 | out: |
115 | return err; | |
91da11f8 LB |
116 | } |
117 | ||
118 | static int dsa_slave_close(struct net_device *dev) | |
119 | { | |
d0006b00 | 120 | struct net_device *master = dsa_slave_to_master(dev); |
d945097b | 121 | struct dsa_port *dp = dsa_slave_to_port(dev); |
df02c6ff | 122 | |
0115dcd1 VD |
123 | if (dev->phydev) |
124 | phy_stop(dev->phydev); | |
f7f1de51 | 125 | |
0115dcd1 | 126 | dsa_port_disable(dp, dev->phydev); |
6457edfe | 127 | |
df02c6ff | 128 | dev_mc_unsync(master, dev); |
a748ee24 | 129 | dev_uc_unsync(master, dev); |
df02c6ff LB |
130 | if (dev->flags & IFF_ALLMULTI) |
131 | dev_set_allmulti(master, -1); | |
132 | if (dev->flags & IFF_PROMISC) | |
133 | dev_set_promiscuity(master, -1); | |
134 | ||
8feedbb4 | 135 | if (!ether_addr_equal(dev->dev_addr, master->dev_addr)) |
a748ee24 | 136 | dev_uc_del(master, dev->dev_addr); |
df02c6ff | 137 | |
91da11f8 LB |
138 | return 0; |
139 | } | |
140 | ||
141 | static void dsa_slave_change_rx_flags(struct net_device *dev, int change) | |
142 | { | |
d0006b00 | 143 | struct net_device *master = dsa_slave_to_master(dev); |
91da11f8 LB |
144 | |
145 | if (change & IFF_ALLMULTI) | |
146 | dev_set_allmulti(master, dev->flags & IFF_ALLMULTI ? 1 : -1); | |
147 | if (change & IFF_PROMISC) | |
148 | dev_set_promiscuity(master, dev->flags & IFF_PROMISC ? 1 : -1); | |
149 | } | |
150 | ||
151 | static void dsa_slave_set_rx_mode(struct net_device *dev) | |
152 | { | |
d0006b00 | 153 | struct net_device *master = dsa_slave_to_master(dev); |
91da11f8 LB |
154 | |
155 | dev_mc_sync(master, dev); | |
a748ee24 | 156 | dev_uc_sync(master, dev); |
91da11f8 LB |
157 | } |
158 | ||
df02c6ff | 159 | static int dsa_slave_set_mac_address(struct net_device *dev, void *a) |
91da11f8 | 160 | { |
d0006b00 | 161 | struct net_device *master = dsa_slave_to_master(dev); |
df02c6ff LB |
162 | struct sockaddr *addr = a; |
163 | int err; | |
164 | ||
165 | if (!is_valid_ether_addr(addr->sa_data)) | |
166 | return -EADDRNOTAVAIL; | |
167 | ||
168 | if (!(dev->flags & IFF_UP)) | |
169 | goto out; | |
170 | ||
8feedbb4 | 171 | if (!ether_addr_equal(addr->sa_data, master->dev_addr)) { |
a748ee24 | 172 | err = dev_uc_add(master, addr->sa_data); |
df02c6ff LB |
173 | if (err < 0) |
174 | return err; | |
175 | } | |
176 | ||
8feedbb4 | 177 | if (!ether_addr_equal(dev->dev_addr, master->dev_addr)) |
a748ee24 | 178 | dev_uc_del(master, dev->dev_addr); |
df02c6ff LB |
179 | |
180 | out: | |
d08f161a | 181 | ether_addr_copy(dev->dev_addr, addr->sa_data); |
91da11f8 LB |
182 | |
183 | return 0; | |
184 | } | |
185 | ||
2bedde1a AS |
186 | struct dsa_slave_dump_ctx { |
187 | struct net_device *dev; | |
188 | struct sk_buff *skb; | |
189 | struct netlink_callback *cb; | |
190 | int idx; | |
191 | }; | |
192 | ||
193 | static int | |
194 | dsa_slave_port_fdb_do_dump(const unsigned char *addr, u16 vid, | |
195 | bool is_static, void *data) | |
196 | { | |
197 | struct dsa_slave_dump_ctx *dump = data; | |
198 | u32 portid = NETLINK_CB(dump->cb->skb).portid; | |
199 | u32 seq = dump->cb->nlh->nlmsg_seq; | |
200 | struct nlmsghdr *nlh; | |
201 | struct ndmsg *ndm; | |
202 | ||
203 | if (dump->idx < dump->cb->args[2]) | |
204 | goto skip; | |
205 | ||
206 | nlh = nlmsg_put(dump->skb, portid, seq, RTM_NEWNEIGH, | |
207 | sizeof(*ndm), NLM_F_MULTI); | |
208 | if (!nlh) | |
209 | return -EMSGSIZE; | |
210 | ||
211 | ndm = nlmsg_data(nlh); | |
212 | ndm->ndm_family = AF_BRIDGE; | |
213 | ndm->ndm_pad1 = 0; | |
214 | ndm->ndm_pad2 = 0; | |
215 | ndm->ndm_flags = NTF_SELF; | |
216 | ndm->ndm_type = 0; | |
217 | ndm->ndm_ifindex = dump->dev->ifindex; | |
218 | ndm->ndm_state = is_static ? NUD_NOARP : NUD_REACHABLE; | |
219 | ||
220 | if (nla_put(dump->skb, NDA_LLADDR, ETH_ALEN, addr)) | |
221 | goto nla_put_failure; | |
222 | ||
223 | if (vid && nla_put_u16(dump->skb, NDA_VLAN, vid)) | |
224 | goto nla_put_failure; | |
225 | ||
226 | nlmsg_end(dump->skb, nlh); | |
227 | ||
228 | skip: | |
229 | dump->idx++; | |
230 | return 0; | |
231 | ||
232 | nla_put_failure: | |
233 | nlmsg_cancel(dump->skb, nlh); | |
234 | return -EMSGSIZE; | |
235 | } | |
236 | ||
237 | static int | |
238 | dsa_slave_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb, | |
239 | struct net_device *dev, struct net_device *filter_dev, | |
240 | int *idx) | |
241 | { | |
d945097b | 242 | struct dsa_port *dp = dsa_slave_to_port(dev); |
2bedde1a AS |
243 | struct dsa_slave_dump_ctx dump = { |
244 | .dev = dev, | |
245 | .skb = skb, | |
246 | .cb = cb, | |
247 | .idx = *idx, | |
248 | }; | |
2bedde1a AS |
249 | int err; |
250 | ||
de40fc5d | 251 | err = dsa_port_fdb_dump(dp, dsa_slave_port_fdb_do_dump, &dump); |
2bedde1a | 252 | *idx = dump.idx; |
de40fc5d | 253 | |
2bedde1a AS |
254 | return err; |
255 | } | |
256 | ||
91da11f8 LB |
257 | static int dsa_slave_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
258 | { | |
0115dcd1 | 259 | if (!dev->phydev) |
f4344e0a | 260 | return -ENODEV; |
91da11f8 | 261 | |
0115dcd1 | 262 | return phy_mii_ioctl(dev->phydev, ifr, cmd); |
91da11f8 LB |
263 | } |
264 | ||
35636062 | 265 | static int dsa_slave_port_attr_set(struct net_device *dev, |
f7fadf30 | 266 | const struct switchdev_attr *attr, |
7ea6eb3f | 267 | struct switchdev_trans *trans) |
35636062 | 268 | { |
d945097b | 269 | struct dsa_port *dp = dsa_slave_to_port(dev); |
b8d866ac | 270 | int ret; |
35636062 SF |
271 | |
272 | switch (attr->id) { | |
1f868398 | 273 | case SWITCHDEV_ATTR_ID_PORT_STP_STATE: |
fd364541 | 274 | ret = dsa_port_set_state(dp, attr->u.stp_state, trans); |
35636062 | 275 | break; |
fb2dabad | 276 | case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING: |
c02c4175 VD |
277 | ret = dsa_port_vlan_filtering(dp, attr->u.vlan_filtering, |
278 | trans); | |
fb2dabad | 279 | break; |
34a79f63 | 280 | case SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME: |
072bb190 | 281 | ret = dsa_port_ageing_time(dp, attr->u.ageing_time, trans); |
34a79f63 | 282 | break; |
35636062 SF |
283 | default: |
284 | ret = -EOPNOTSUPP; | |
285 | break; | |
286 | } | |
287 | ||
288 | return ret; | |
289 | } | |
290 | ||
ba14d9eb | 291 | static int dsa_slave_port_obj_add(struct net_device *dev, |
648b4a99 | 292 | const struct switchdev_obj *obj, |
7ea6eb3f | 293 | struct switchdev_trans *trans) |
ba14d9eb | 294 | { |
d945097b | 295 | struct dsa_port *dp = dsa_slave_to_port(dev); |
ba14d9eb VD |
296 | int err; |
297 | ||
298 | /* For the prepare phase, ensure the full set of changes is feasable in | |
299 | * one go in order to signal a failure properly. If an operation is not | |
300 | * supported, return -EOPNOTSUPP. | |
301 | */ | |
302 | ||
9e8f4a54 | 303 | switch (obj->id) { |
8df30255 | 304 | case SWITCHDEV_OBJ_ID_PORT_MDB: |
bcebb976 | 305 | err = dsa_port_mdb_add(dp, SWITCHDEV_OBJ_PORT_MDB(obj), trans); |
8df30255 | 306 | break; |
5f4dbc50 AL |
307 | case SWITCHDEV_OBJ_ID_HOST_MDB: |
308 | /* DSA can directly translate this to a normal MDB add, | |
309 | * but on the CPU port. | |
310 | */ | |
311 | err = dsa_port_mdb_add(dp->cpu_dp, SWITCHDEV_OBJ_PORT_MDB(obj), | |
312 | trans); | |
313 | break; | |
57d80838 | 314 | case SWITCHDEV_OBJ_ID_PORT_VLAN: |
01676d12 VD |
315 | err = dsa_port_vlan_add(dp, SWITCHDEV_OBJ_PORT_VLAN(obj), |
316 | trans); | |
11149536 | 317 | break; |
ba14d9eb VD |
318 | default: |
319 | err = -EOPNOTSUPP; | |
320 | break; | |
321 | } | |
322 | ||
323 | return err; | |
324 | } | |
325 | ||
326 | static int dsa_slave_port_obj_del(struct net_device *dev, | |
648b4a99 | 327 | const struct switchdev_obj *obj) |
ba14d9eb | 328 | { |
d945097b | 329 | struct dsa_port *dp = dsa_slave_to_port(dev); |
ba14d9eb VD |
330 | int err; |
331 | ||
9e8f4a54 | 332 | switch (obj->id) { |
8df30255 | 333 | case SWITCHDEV_OBJ_ID_PORT_MDB: |
bcebb976 | 334 | err = dsa_port_mdb_del(dp, SWITCHDEV_OBJ_PORT_MDB(obj)); |
8df30255 | 335 | break; |
5f4dbc50 AL |
336 | case SWITCHDEV_OBJ_ID_HOST_MDB: |
337 | /* DSA can directly translate this to a normal MDB add, | |
338 | * but on the CPU port. | |
339 | */ | |
340 | err = dsa_port_mdb_del(dp->cpu_dp, SWITCHDEV_OBJ_PORT_MDB(obj)); | |
341 | break; | |
57d80838 | 342 | case SWITCHDEV_OBJ_ID_PORT_VLAN: |
01676d12 | 343 | err = dsa_port_vlan_del(dp, SWITCHDEV_OBJ_PORT_VLAN(obj)); |
11149536 | 344 | break; |
ba14d9eb VD |
345 | default: |
346 | err = -EOPNOTSUPP; | |
347 | break; | |
348 | } | |
349 | ||
350 | return err; | |
351 | } | |
352 | ||
f8e20a9f SF |
353 | static int dsa_slave_port_attr_get(struct net_device *dev, |
354 | struct switchdev_attr *attr) | |
b73adef6 | 355 | { |
d945097b VD |
356 | struct dsa_port *dp = dsa_slave_to_port(dev); |
357 | struct dsa_switch *ds = dp->ds; | |
b73adef6 | 358 | |
f8e20a9f | 359 | switch (attr->id) { |
1f868398 | 360 | case SWITCHDEV_ATTR_ID_PORT_PARENT_ID: |
42275bd8 SF |
361 | attr->u.ppid.id_len = sizeof(ds->index); |
362 | memcpy(&attr->u.ppid.id, &ds->index, attr->u.ppid.id_len); | |
f8e20a9f | 363 | break; |
c9e2105e AS |
364 | case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS_SUPPORT: |
365 | attr->u.brport_flags_support = 0; | |
366 | break; | |
f8e20a9f SF |
367 | default: |
368 | return -EOPNOTSUPP; | |
369 | } | |
b73adef6 FF |
370 | |
371 | return 0; | |
372 | } | |
373 | ||
4fa7b718 VD |
374 | static inline netdev_tx_t dsa_slave_netpoll_send_skb(struct net_device *dev, |
375 | struct sk_buff *skb) | |
04ff53f9 FF |
376 | { |
377 | #ifdef CONFIG_NET_POLL_CONTROLLER | |
4fa7b718 VD |
378 | struct dsa_slave_priv *p = netdev_priv(dev); |
379 | ||
04ff53f9 FF |
380 | if (p->netpoll) |
381 | netpoll_send_skb(p->netpoll, skb); | |
382 | #else | |
383 | BUG(); | |
384 | #endif | |
385 | return NETDEV_TX_OK; | |
386 | } | |
387 | ||
3e8a72d1 FF |
388 | static netdev_tx_t dsa_slave_xmit(struct sk_buff *skb, struct net_device *dev) |
389 | { | |
390 | struct dsa_slave_priv *p = netdev_priv(dev); | |
5f6b4e14 | 391 | struct pcpu_sw_netstats *s; |
4ed70ce9 | 392 | struct sk_buff *nskb; |
3e8a72d1 | 393 | |
5f6b4e14 FF |
394 | s = this_cpu_ptr(p->stats64); |
395 | u64_stats_update_begin(&s->syncp); | |
396 | s->tx_packets++; | |
397 | s->tx_bytes += skb->len; | |
398 | u64_stats_update_end(&s->syncp); | |
3e8a72d1 | 399 | |
fe47d563 VD |
400 | /* Transmit function may have to reallocate the original SKB, |
401 | * in which case it must have freed it. Only free it here on error. | |
402 | */ | |
4ed70ce9 | 403 | nskb = p->xmit(skb, dev); |
fe47d563 VD |
404 | if (!nskb) { |
405 | kfree_skb(skb); | |
4ed70ce9 | 406 | return NETDEV_TX_OK; |
fe47d563 | 407 | } |
5aed85ce | 408 | |
04ff53f9 FF |
409 | /* SKB for netpoll still need to be mangled with the protocol-specific |
410 | * tag to be successfully transmitted | |
411 | */ | |
412 | if (unlikely(netpoll_tx_running(dev))) | |
4fa7b718 | 413 | return dsa_slave_netpoll_send_skb(dev, nskb); |
04ff53f9 | 414 | |
4ed70ce9 FF |
415 | /* Queue the SKB for transmission on the parent interface, but |
416 | * do not modify its EtherType | |
417 | */ | |
d0006b00 | 418 | nskb->dev = dsa_slave_to_master(dev); |
4ed70ce9 | 419 | dev_queue_xmit(nskb); |
5aed85ce FF |
420 | |
421 | return NETDEV_TX_OK; | |
422 | } | |
423 | ||
91da11f8 | 424 | /* ethtool operations *******************************************************/ |
91da11f8 | 425 | |
91da11f8 LB |
426 | static void dsa_slave_get_drvinfo(struct net_device *dev, |
427 | struct ethtool_drvinfo *drvinfo) | |
428 | { | |
7826d43f | 429 | strlcpy(drvinfo->driver, "dsa", sizeof(drvinfo->driver)); |
7826d43f JP |
430 | strlcpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version)); |
431 | strlcpy(drvinfo->bus_info, "platform", sizeof(drvinfo->bus_info)); | |
91da11f8 LB |
432 | } |
433 | ||
3d762a0f GR |
434 | static int dsa_slave_get_regs_len(struct net_device *dev) |
435 | { | |
d945097b VD |
436 | struct dsa_port *dp = dsa_slave_to_port(dev); |
437 | struct dsa_switch *ds = dp->ds; | |
3d762a0f | 438 | |
9d490b4e | 439 | if (ds->ops->get_regs_len) |
d945097b | 440 | return ds->ops->get_regs_len(ds, dp->index); |
3d762a0f GR |
441 | |
442 | return -EOPNOTSUPP; | |
443 | } | |
444 | ||
445 | static void | |
446 | dsa_slave_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *_p) | |
447 | { | |
d945097b VD |
448 | struct dsa_port *dp = dsa_slave_to_port(dev); |
449 | struct dsa_switch *ds = dp->ds; | |
3d762a0f | 450 | |
9d490b4e | 451 | if (ds->ops->get_regs) |
d945097b | 452 | ds->ops->get_regs(ds, dp->index, regs, _p); |
3d762a0f GR |
453 | } |
454 | ||
91da11f8 LB |
455 | static u32 dsa_slave_get_link(struct net_device *dev) |
456 | { | |
0115dcd1 | 457 | if (!dev->phydev) |
f4344e0a | 458 | return -ENODEV; |
91da11f8 | 459 | |
0115dcd1 | 460 | genphy_update_link(dev->phydev); |
f4344e0a | 461 | |
0115dcd1 | 462 | return dev->phydev->link; |
91da11f8 LB |
463 | } |
464 | ||
6793abb4 GR |
465 | static int dsa_slave_get_eeprom_len(struct net_device *dev) |
466 | { | |
d945097b VD |
467 | struct dsa_port *dp = dsa_slave_to_port(dev); |
468 | struct dsa_switch *ds = dp->ds; | |
6793abb4 | 469 | |
0e576044 | 470 | if (ds->cd && ds->cd->eeprom_len) |
ff04955c | 471 | return ds->cd->eeprom_len; |
6793abb4 | 472 | |
9d490b4e VD |
473 | if (ds->ops->get_eeprom_len) |
474 | return ds->ops->get_eeprom_len(ds); | |
6793abb4 GR |
475 | |
476 | return 0; | |
477 | } | |
478 | ||
479 | static int dsa_slave_get_eeprom(struct net_device *dev, | |
480 | struct ethtool_eeprom *eeprom, u8 *data) | |
481 | { | |
d945097b VD |
482 | struct dsa_port *dp = dsa_slave_to_port(dev); |
483 | struct dsa_switch *ds = dp->ds; | |
6793abb4 | 484 | |
9d490b4e VD |
485 | if (ds->ops->get_eeprom) |
486 | return ds->ops->get_eeprom(ds, eeprom, data); | |
6793abb4 GR |
487 | |
488 | return -EOPNOTSUPP; | |
489 | } | |
490 | ||
491 | static int dsa_slave_set_eeprom(struct net_device *dev, | |
492 | struct ethtool_eeprom *eeprom, u8 *data) | |
493 | { | |
d945097b VD |
494 | struct dsa_port *dp = dsa_slave_to_port(dev); |
495 | struct dsa_switch *ds = dp->ds; | |
6793abb4 | 496 | |
9d490b4e VD |
497 | if (ds->ops->set_eeprom) |
498 | return ds->ops->set_eeprom(ds, eeprom, data); | |
6793abb4 GR |
499 | |
500 | return -EOPNOTSUPP; | |
501 | } | |
502 | ||
91da11f8 LB |
503 | static void dsa_slave_get_strings(struct net_device *dev, |
504 | uint32_t stringset, uint8_t *data) | |
505 | { | |
d945097b VD |
506 | struct dsa_port *dp = dsa_slave_to_port(dev); |
507 | struct dsa_switch *ds = dp->ds; | |
91da11f8 LB |
508 | |
509 | if (stringset == ETH_SS_STATS) { | |
510 | int len = ETH_GSTRING_LEN; | |
511 | ||
512 | strncpy(data, "tx_packets", len); | |
513 | strncpy(data + len, "tx_bytes", len); | |
514 | strncpy(data + 2 * len, "rx_packets", len); | |
515 | strncpy(data + 3 * len, "rx_bytes", len); | |
9d490b4e | 516 | if (ds->ops->get_strings) |
d945097b | 517 | ds->ops->get_strings(ds, dp->index, data + 4 * len); |
91da11f8 LB |
518 | } |
519 | } | |
520 | ||
521 | static void dsa_slave_get_ethtool_stats(struct net_device *dev, | |
522 | struct ethtool_stats *stats, | |
523 | uint64_t *data) | |
524 | { | |
d945097b | 525 | struct dsa_port *dp = dsa_slave_to_port(dev); |
91da11f8 | 526 | struct dsa_slave_priv *p = netdev_priv(dev); |
d945097b | 527 | struct dsa_switch *ds = dp->ds; |
5f6b4e14 | 528 | struct pcpu_sw_netstats *s; |
f613ed66 | 529 | unsigned int start; |
5f6b4e14 FF |
530 | int i; |
531 | ||
532 | for_each_possible_cpu(i) { | |
533 | u64 tx_packets, tx_bytes, rx_packets, rx_bytes; | |
534 | ||
535 | s = per_cpu_ptr(p->stats64, i); | |
536 | do { | |
537 | start = u64_stats_fetch_begin_irq(&s->syncp); | |
538 | tx_packets = s->tx_packets; | |
539 | tx_bytes = s->tx_bytes; | |
540 | rx_packets = s->rx_packets; | |
541 | rx_bytes = s->rx_bytes; | |
542 | } while (u64_stats_fetch_retry_irq(&s->syncp, start)); | |
543 | data[0] += tx_packets; | |
544 | data[1] += tx_bytes; | |
545 | data[2] += rx_packets; | |
546 | data[3] += rx_bytes; | |
547 | } | |
9d490b4e | 548 | if (ds->ops->get_ethtool_stats) |
d945097b | 549 | ds->ops->get_ethtool_stats(ds, dp->index, data + 4); |
91da11f8 LB |
550 | } |
551 | ||
552 | static int dsa_slave_get_sset_count(struct net_device *dev, int sset) | |
553 | { | |
d945097b VD |
554 | struct dsa_port *dp = dsa_slave_to_port(dev); |
555 | struct dsa_switch *ds = dp->ds; | |
91da11f8 LB |
556 | |
557 | if (sset == ETH_SS_STATS) { | |
558 | int count; | |
559 | ||
560 | count = 4; | |
9d490b4e VD |
561 | if (ds->ops->get_sset_count) |
562 | count += ds->ops->get_sset_count(ds); | |
91da11f8 LB |
563 | |
564 | return count; | |
565 | } | |
566 | ||
567 | return -EOPNOTSUPP; | |
568 | } | |
569 | ||
19e57c4e FF |
570 | static void dsa_slave_get_wol(struct net_device *dev, struct ethtool_wolinfo *w) |
571 | { | |
d945097b VD |
572 | struct dsa_port *dp = dsa_slave_to_port(dev); |
573 | struct dsa_switch *ds = dp->ds; | |
19e57c4e | 574 | |
9d490b4e | 575 | if (ds->ops->get_wol) |
d945097b | 576 | ds->ops->get_wol(ds, dp->index, w); |
19e57c4e FF |
577 | } |
578 | ||
579 | static int dsa_slave_set_wol(struct net_device *dev, struct ethtool_wolinfo *w) | |
580 | { | |
d945097b VD |
581 | struct dsa_port *dp = dsa_slave_to_port(dev); |
582 | struct dsa_switch *ds = dp->ds; | |
19e57c4e FF |
583 | int ret = -EOPNOTSUPP; |
584 | ||
9d490b4e | 585 | if (ds->ops->set_wol) |
d945097b | 586 | ret = ds->ops->set_wol(ds, dp->index, w); |
19e57c4e FF |
587 | |
588 | return ret; | |
589 | } | |
590 | ||
7905288f FF |
591 | static int dsa_slave_set_eee(struct net_device *dev, struct ethtool_eee *e) |
592 | { | |
d945097b VD |
593 | struct dsa_port *dp = dsa_slave_to_port(dev); |
594 | struct dsa_switch *ds = dp->ds; | |
7905288f FF |
595 | int ret; |
596 | ||
7b9cc738 | 597 | /* Port's PHY and MAC both need to be EEE capable */ |
0115dcd1 | 598 | if (!dev->phydev) |
7b9cc738 VD |
599 | return -ENODEV; |
600 | ||
08f50061 | 601 | if (!ds->ops->set_mac_eee) |
7905288f FF |
602 | return -EOPNOTSUPP; |
603 | ||
d945097b | 604 | ret = ds->ops->set_mac_eee(ds, dp->index, e); |
7905288f FF |
605 | if (ret) |
606 | return ret; | |
607 | ||
c48f7eb3 | 608 | if (e->eee_enabled) { |
0115dcd1 | 609 | ret = phy_init_eee(dev->phydev, 0); |
c48f7eb3 VD |
610 | if (ret) |
611 | return ret; | |
612 | } | |
613 | ||
0115dcd1 | 614 | return phy_ethtool_set_eee(dev->phydev, e); |
7905288f FF |
615 | } |
616 | ||
617 | static int dsa_slave_get_eee(struct net_device *dev, struct ethtool_eee *e) | |
618 | { | |
d945097b VD |
619 | struct dsa_port *dp = dsa_slave_to_port(dev); |
620 | struct dsa_switch *ds = dp->ds; | |
7905288f FF |
621 | int ret; |
622 | ||
7b9cc738 | 623 | /* Port's PHY and MAC both need to be EEE capable */ |
0115dcd1 | 624 | if (!dev->phydev) |
7b9cc738 VD |
625 | return -ENODEV; |
626 | ||
08f50061 | 627 | if (!ds->ops->get_mac_eee) |
7905288f FF |
628 | return -EOPNOTSUPP; |
629 | ||
d945097b | 630 | ret = ds->ops->get_mac_eee(ds, dp->index, e); |
7905288f FF |
631 | if (ret) |
632 | return ret; | |
633 | ||
0115dcd1 | 634 | return phy_ethtool_get_eee(dev->phydev, e); |
7905288f FF |
635 | } |
636 | ||
04ff53f9 FF |
637 | #ifdef CONFIG_NET_POLL_CONTROLLER |
638 | static int dsa_slave_netpoll_setup(struct net_device *dev, | |
639 | struct netpoll_info *ni) | |
640 | { | |
d0006b00 | 641 | struct net_device *master = dsa_slave_to_master(dev); |
04ff53f9 | 642 | struct dsa_slave_priv *p = netdev_priv(dev); |
04ff53f9 FF |
643 | struct netpoll *netpoll; |
644 | int err = 0; | |
645 | ||
646 | netpoll = kzalloc(sizeof(*netpoll), GFP_KERNEL); | |
647 | if (!netpoll) | |
648 | return -ENOMEM; | |
649 | ||
650 | err = __netpoll_setup(netpoll, master); | |
651 | if (err) { | |
652 | kfree(netpoll); | |
653 | goto out; | |
654 | } | |
655 | ||
656 | p->netpoll = netpoll; | |
657 | out: | |
658 | return err; | |
659 | } | |
660 | ||
661 | static void dsa_slave_netpoll_cleanup(struct net_device *dev) | |
662 | { | |
663 | struct dsa_slave_priv *p = netdev_priv(dev); | |
664 | struct netpoll *netpoll = p->netpoll; | |
665 | ||
666 | if (!netpoll) | |
667 | return; | |
668 | ||
669 | p->netpoll = NULL; | |
670 | ||
671 | __netpoll_free_async(netpoll); | |
672 | } | |
673 | ||
674 | static void dsa_slave_poll_controller(struct net_device *dev) | |
675 | { | |
676 | } | |
677 | #endif | |
678 | ||
44bb765c FF |
679 | static int dsa_slave_get_phys_port_name(struct net_device *dev, |
680 | char *name, size_t len) | |
681 | { | |
d945097b | 682 | struct dsa_port *dp = dsa_slave_to_port(dev); |
44bb765c | 683 | |
d945097b | 684 | if (snprintf(name, len, "p%d", dp->index) >= len) |
44bb765c | 685 | return -EINVAL; |
3a543ef4 FF |
686 | |
687 | return 0; | |
688 | } | |
689 | ||
f50f2127 | 690 | static struct dsa_mall_tc_entry * |
4fa7b718 | 691 | dsa_slave_mall_tc_entry_find(struct net_device *dev, unsigned long cookie) |
f50f2127 | 692 | { |
4fa7b718 | 693 | struct dsa_slave_priv *p = netdev_priv(dev); |
f50f2127 FF |
694 | struct dsa_mall_tc_entry *mall_tc_entry; |
695 | ||
696 | list_for_each_entry(mall_tc_entry, &p->mall_tc_list, list) | |
697 | if (mall_tc_entry->cookie == cookie) | |
698 | return mall_tc_entry; | |
699 | ||
700 | return NULL; | |
701 | } | |
702 | ||
703 | static int dsa_slave_add_cls_matchall(struct net_device *dev, | |
f50f2127 FF |
704 | struct tc_cls_matchall_offload *cls, |
705 | bool ingress) | |
706 | { | |
d945097b | 707 | struct dsa_port *dp = dsa_slave_to_port(dev); |
f50f2127 FF |
708 | struct dsa_slave_priv *p = netdev_priv(dev); |
709 | struct dsa_mall_tc_entry *mall_tc_entry; | |
5fd9fc4e | 710 | __be16 protocol = cls->common.protocol; |
f50f2127 | 711 | struct net *net = dev_net(dev); |
d945097b | 712 | struct dsa_switch *ds = dp->ds; |
f50f2127 FF |
713 | struct net_device *to_dev; |
714 | const struct tc_action *a; | |
d945097b | 715 | struct dsa_port *to_dp; |
f50f2127 FF |
716 | int err = -EOPNOTSUPP; |
717 | LIST_HEAD(actions); | |
718 | int ifindex; | |
719 | ||
720 | if (!ds->ops->port_mirror_add) | |
721 | return err; | |
722 | ||
3bcc0cec | 723 | if (!tcf_exts_has_one_action(cls->exts)) |
f50f2127 FF |
724 | return err; |
725 | ||
726 | tcf_exts_to_list(cls->exts, &actions); | |
727 | a = list_first_entry(&actions, struct tc_action, list); | |
728 | ||
729 | if (is_tcf_mirred_egress_mirror(a) && protocol == htons(ETH_P_ALL)) { | |
730 | struct dsa_mall_mirror_tc_entry *mirror; | |
731 | ||
732 | ifindex = tcf_mirred_ifindex(a); | |
733 | to_dev = __dev_get_by_index(net, ifindex); | |
734 | if (!to_dev) | |
735 | return -EINVAL; | |
736 | ||
737 | if (!dsa_slave_dev_check(to_dev)) | |
738 | return -EOPNOTSUPP; | |
739 | ||
740 | mall_tc_entry = kzalloc(sizeof(*mall_tc_entry), GFP_KERNEL); | |
741 | if (!mall_tc_entry) | |
742 | return -ENOMEM; | |
743 | ||
744 | mall_tc_entry->cookie = cls->cookie; | |
745 | mall_tc_entry->type = DSA_PORT_MALL_MIRROR; | |
746 | mirror = &mall_tc_entry->mirror; | |
747 | ||
d945097b | 748 | to_dp = dsa_slave_to_port(to_dev); |
f50f2127 | 749 | |
d945097b | 750 | mirror->to_local_port = to_dp->index; |
f50f2127 FF |
751 | mirror->ingress = ingress; |
752 | ||
d945097b | 753 | err = ds->ops->port_mirror_add(ds, dp->index, mirror, ingress); |
f50f2127 FF |
754 | if (err) { |
755 | kfree(mall_tc_entry); | |
756 | return err; | |
757 | } | |
758 | ||
759 | list_add_tail(&mall_tc_entry->list, &p->mall_tc_list); | |
760 | } | |
761 | ||
762 | return 0; | |
763 | } | |
764 | ||
765 | static void dsa_slave_del_cls_matchall(struct net_device *dev, | |
766 | struct tc_cls_matchall_offload *cls) | |
767 | { | |
d945097b | 768 | struct dsa_port *dp = dsa_slave_to_port(dev); |
f50f2127 | 769 | struct dsa_mall_tc_entry *mall_tc_entry; |
d945097b | 770 | struct dsa_switch *ds = dp->ds; |
f50f2127 FF |
771 | |
772 | if (!ds->ops->port_mirror_del) | |
773 | return; | |
774 | ||
4fa7b718 | 775 | mall_tc_entry = dsa_slave_mall_tc_entry_find(dev, cls->cookie); |
f50f2127 FF |
776 | if (!mall_tc_entry) |
777 | return; | |
778 | ||
779 | list_del(&mall_tc_entry->list); | |
780 | ||
781 | switch (mall_tc_entry->type) { | |
782 | case DSA_PORT_MALL_MIRROR: | |
d945097b | 783 | ds->ops->port_mirror_del(ds, dp->index, &mall_tc_entry->mirror); |
f50f2127 FF |
784 | break; |
785 | default: | |
786 | WARN_ON(1); | |
787 | } | |
788 | ||
789 | kfree(mall_tc_entry); | |
790 | } | |
791 | ||
3fbae382 | 792 | static int dsa_slave_setup_tc_cls_matchall(struct net_device *dev, |
6b3eb752 JP |
793 | struct tc_cls_matchall_offload *cls, |
794 | bool ingress) | |
f50f2127 | 795 | { |
5fd9fc4e | 796 | if (cls->common.chain_index) |
a5fcf8a6 | 797 | return -EOPNOTSUPP; |
f50f2127 | 798 | |
3fbae382 JP |
799 | switch (cls->command) { |
800 | case TC_CLSMATCHALL_REPLACE: | |
5fd9fc4e | 801 | return dsa_slave_add_cls_matchall(dev, cls, ingress); |
3fbae382 JP |
802 | case TC_CLSMATCHALL_DESTROY: |
803 | dsa_slave_del_cls_matchall(dev, cls); | |
804 | return 0; | |
805 | default: | |
806 | return -EOPNOTSUPP; | |
807 | } | |
808 | } | |
809 | ||
6b3eb752 JP |
810 | static int dsa_slave_setup_tc_block_cb(enum tc_setup_type type, void *type_data, |
811 | void *cb_priv, bool ingress) | |
812 | { | |
813 | struct net_device *dev = cb_priv; | |
814 | ||
44ae12a7 JP |
815 | if (!tc_can_offload(dev)) |
816 | return -EOPNOTSUPP; | |
817 | ||
6b3eb752 JP |
818 | switch (type) { |
819 | case TC_SETUP_CLSMATCHALL: | |
820 | return dsa_slave_setup_tc_cls_matchall(dev, type_data, ingress); | |
821 | default: | |
822 | return -EOPNOTSUPP; | |
823 | } | |
824 | } | |
825 | ||
826 | static int dsa_slave_setup_tc_block_cb_ig(enum tc_setup_type type, | |
827 | void *type_data, void *cb_priv) | |
828 | { | |
829 | return dsa_slave_setup_tc_block_cb(type, type_data, cb_priv, true); | |
830 | } | |
831 | ||
832 | static int dsa_slave_setup_tc_block_cb_eg(enum tc_setup_type type, | |
833 | void *type_data, void *cb_priv) | |
834 | { | |
835 | return dsa_slave_setup_tc_block_cb(type, type_data, cb_priv, false); | |
836 | } | |
837 | ||
838 | static int dsa_slave_setup_tc_block(struct net_device *dev, | |
839 | struct tc_block_offload *f) | |
840 | { | |
841 | tc_setup_cb_t *cb; | |
842 | ||
843 | if (f->binder_type == TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS) | |
844 | cb = dsa_slave_setup_tc_block_cb_ig; | |
845 | else if (f->binder_type == TCF_BLOCK_BINDER_TYPE_CLSACT_EGRESS) | |
846 | cb = dsa_slave_setup_tc_block_cb_eg; | |
847 | else | |
848 | return -EOPNOTSUPP; | |
849 | ||
850 | switch (f->command) { | |
851 | case TC_BLOCK_BIND: | |
852 | return tcf_block_cb_register(f->block, cb, dev, dev); | |
853 | case TC_BLOCK_UNBIND: | |
854 | tcf_block_cb_unregister(f->block, cb, dev); | |
855 | return 0; | |
856 | default: | |
857 | return -EOPNOTSUPP; | |
858 | } | |
859 | } | |
860 | ||
3fbae382 | 861 | static int dsa_slave_setup_tc(struct net_device *dev, enum tc_setup_type type, |
de4784ca | 862 | void *type_data) |
3fbae382 | 863 | { |
2572ac53 | 864 | switch (type) { |
6b3eb752 JP |
865 | case TC_SETUP_BLOCK: |
866 | return dsa_slave_setup_tc_block(dev, type_data); | |
f50f2127 | 867 | default: |
a5fcf8a6 | 868 | return -EOPNOTSUPP; |
f50f2127 | 869 | } |
f50f2127 FF |
870 | } |
871 | ||
f613ed66 FF |
872 | static void dsa_slave_get_stats64(struct net_device *dev, |
873 | struct rtnl_link_stats64 *stats) | |
874 | { | |
875 | struct dsa_slave_priv *p = netdev_priv(dev); | |
5f6b4e14 | 876 | struct pcpu_sw_netstats *s; |
f613ed66 | 877 | unsigned int start; |
5f6b4e14 | 878 | int i; |
f613ed66 FF |
879 | |
880 | netdev_stats_to_stats64(stats, &dev->stats); | |
5f6b4e14 FF |
881 | for_each_possible_cpu(i) { |
882 | u64 tx_packets, tx_bytes, rx_packets, rx_bytes; | |
883 | ||
884 | s = per_cpu_ptr(p->stats64, i); | |
885 | do { | |
886 | start = u64_stats_fetch_begin_irq(&s->syncp); | |
887 | tx_packets = s->tx_packets; | |
888 | tx_bytes = s->tx_bytes; | |
889 | rx_packets = s->rx_packets; | |
890 | rx_bytes = s->rx_bytes; | |
891 | } while (u64_stats_fetch_retry_irq(&s->syncp, start)); | |
892 | ||
893 | stats->tx_packets += tx_packets; | |
894 | stats->tx_bytes += tx_bytes; | |
895 | stats->rx_packets += rx_packets; | |
896 | stats->rx_bytes += rx_bytes; | |
897 | } | |
f613ed66 FF |
898 | } |
899 | ||
bf9f2648 FF |
900 | static int dsa_slave_get_rxnfc(struct net_device *dev, |
901 | struct ethtool_rxnfc *nfc, u32 *rule_locs) | |
902 | { | |
d945097b VD |
903 | struct dsa_port *dp = dsa_slave_to_port(dev); |
904 | struct dsa_switch *ds = dp->ds; | |
bf9f2648 FF |
905 | |
906 | if (!ds->ops->get_rxnfc) | |
907 | return -EOPNOTSUPP; | |
908 | ||
d945097b | 909 | return ds->ops->get_rxnfc(ds, dp->index, nfc, rule_locs); |
bf9f2648 FF |
910 | } |
911 | ||
912 | static int dsa_slave_set_rxnfc(struct net_device *dev, | |
913 | struct ethtool_rxnfc *nfc) | |
914 | { | |
d945097b VD |
915 | struct dsa_port *dp = dsa_slave_to_port(dev); |
916 | struct dsa_switch *ds = dp->ds; | |
bf9f2648 FF |
917 | |
918 | if (!ds->ops->set_rxnfc) | |
919 | return -EOPNOTSUPP; | |
920 | ||
d945097b | 921 | return ds->ops->set_rxnfc(ds, dp->index, nfc); |
bf9f2648 FF |
922 | } |
923 | ||
91da11f8 | 924 | static const struct ethtool_ops dsa_slave_ethtool_ops = { |
91da11f8 | 925 | .get_drvinfo = dsa_slave_get_drvinfo, |
3d762a0f GR |
926 | .get_regs_len = dsa_slave_get_regs_len, |
927 | .get_regs = dsa_slave_get_regs, | |
69b2c162 | 928 | .nway_reset = phy_ethtool_nway_reset, |
91da11f8 | 929 | .get_link = dsa_slave_get_link, |
6793abb4 GR |
930 | .get_eeprom_len = dsa_slave_get_eeprom_len, |
931 | .get_eeprom = dsa_slave_get_eeprom, | |
932 | .set_eeprom = dsa_slave_set_eeprom, | |
91da11f8 LB |
933 | .get_strings = dsa_slave_get_strings, |
934 | .get_ethtool_stats = dsa_slave_get_ethtool_stats, | |
935 | .get_sset_count = dsa_slave_get_sset_count, | |
19e57c4e FF |
936 | .set_wol = dsa_slave_set_wol, |
937 | .get_wol = dsa_slave_get_wol, | |
7905288f FF |
938 | .set_eee = dsa_slave_set_eee, |
939 | .get_eee = dsa_slave_get_eee, | |
771df31a | 940 | .get_link_ksettings = phy_ethtool_get_link_ksettings, |
aa62a8ca | 941 | .set_link_ksettings = phy_ethtool_set_link_ksettings, |
bf9f2648 FF |
942 | .get_rxnfc = dsa_slave_get_rxnfc, |
943 | .set_rxnfc = dsa_slave_set_rxnfc, | |
91da11f8 LB |
944 | }; |
945 | ||
3e8a72d1 | 946 | static const struct net_device_ops dsa_slave_netdev_ops = { |
d442ad4a SH |
947 | .ndo_open = dsa_slave_open, |
948 | .ndo_stop = dsa_slave_close, | |
3e8a72d1 | 949 | .ndo_start_xmit = dsa_slave_xmit, |
d442ad4a SH |
950 | .ndo_change_rx_flags = dsa_slave_change_rx_flags, |
951 | .ndo_set_rx_mode = dsa_slave_set_rx_mode, | |
d442ad4a | 952 | .ndo_set_mac_address = dsa_slave_set_mac_address, |
37b8da1a AS |
953 | .ndo_fdb_add = dsa_legacy_fdb_add, |
954 | .ndo_fdb_del = dsa_legacy_fdb_del, | |
2bedde1a | 955 | .ndo_fdb_dump = dsa_slave_fdb_dump, |
d442ad4a | 956 | .ndo_do_ioctl = dsa_slave_ioctl, |
abd2be00 | 957 | .ndo_get_iflink = dsa_slave_get_iflink, |
04ff53f9 FF |
958 | #ifdef CONFIG_NET_POLL_CONTROLLER |
959 | .ndo_netpoll_setup = dsa_slave_netpoll_setup, | |
960 | .ndo_netpoll_cleanup = dsa_slave_netpoll_cleanup, | |
961 | .ndo_poll_controller = dsa_slave_poll_controller, | |
962 | #endif | |
44bb765c | 963 | .ndo_get_phys_port_name = dsa_slave_get_phys_port_name, |
f50f2127 | 964 | .ndo_setup_tc = dsa_slave_setup_tc, |
f613ed66 | 965 | .ndo_get_stats64 = dsa_slave_get_stats64, |
98237d43 SF |
966 | }; |
967 | ||
9d47c0a2 | 968 | static const struct switchdev_ops dsa_slave_switchdev_ops = { |
f8e20a9f | 969 | .switchdev_port_attr_get = dsa_slave_port_attr_get, |
35636062 | 970 | .switchdev_port_attr_set = dsa_slave_port_attr_set, |
ba14d9eb VD |
971 | .switchdev_port_obj_add = dsa_slave_port_obj_add, |
972 | .switchdev_port_obj_del = dsa_slave_port_obj_del, | |
d442ad4a | 973 | }; |
91da11f8 | 974 | |
f37db85d FF |
975 | static struct device_type dsa_type = { |
976 | .name = "dsa", | |
977 | }; | |
978 | ||
0d8bcdd3 FF |
979 | static void dsa_slave_adjust_link(struct net_device *dev) |
980 | { | |
d945097b | 981 | struct dsa_port *dp = dsa_slave_to_port(dev); |
0d8bcdd3 | 982 | struct dsa_slave_priv *p = netdev_priv(dev); |
d945097b | 983 | struct dsa_switch *ds = dp->ds; |
0d8bcdd3 FF |
984 | unsigned int status_changed = 0; |
985 | ||
0115dcd1 | 986 | if (p->old_link != dev->phydev->link) { |
0d8bcdd3 | 987 | status_changed = 1; |
0115dcd1 | 988 | p->old_link = dev->phydev->link; |
0d8bcdd3 FF |
989 | } |
990 | ||
0115dcd1 | 991 | if (p->old_duplex != dev->phydev->duplex) { |
0d8bcdd3 | 992 | status_changed = 1; |
0115dcd1 | 993 | p->old_duplex = dev->phydev->duplex; |
0d8bcdd3 FF |
994 | } |
995 | ||
0115dcd1 | 996 | if (p->old_pause != dev->phydev->pause) { |
0d8bcdd3 | 997 | status_changed = 1; |
0115dcd1 | 998 | p->old_pause = dev->phydev->pause; |
0d8bcdd3 FF |
999 | } |
1000 | ||
9d490b4e | 1001 | if (ds->ops->adjust_link && status_changed) |
d945097b | 1002 | ds->ops->adjust_link(ds, dp->index, dev->phydev); |
ec9436ba | 1003 | |
0d8bcdd3 | 1004 | if (status_changed) |
0115dcd1 | 1005 | phy_print_status(dev->phydev); |
0d8bcdd3 FF |
1006 | } |
1007 | ||
ce31b31c FF |
1008 | static int dsa_slave_fixed_link_update(struct net_device *dev, |
1009 | struct fixed_phy_status *status) | |
1010 | { | |
b71be352 | 1011 | struct dsa_switch *ds; |
d945097b | 1012 | struct dsa_port *dp; |
b71be352 AL |
1013 | |
1014 | if (dev) { | |
d945097b VD |
1015 | dp = dsa_slave_to_port(dev); |
1016 | ds = dp->ds; | |
9d490b4e | 1017 | if (ds->ops->fixed_link_update) |
d945097b | 1018 | ds->ops->fixed_link_update(ds, dp->index, status); |
b71be352 | 1019 | } |
ce31b31c FF |
1020 | |
1021 | return 0; | |
1022 | } | |
1023 | ||
91da11f8 | 1024 | /* slave device setup *******************************************************/ |
4fa7b718 | 1025 | static int dsa_slave_phy_connect(struct net_device *slave_dev, int addr) |
c305c165 | 1026 | { |
d945097b | 1027 | struct dsa_port *dp = dsa_slave_to_port(slave_dev); |
4fa7b718 | 1028 | struct dsa_slave_priv *p = netdev_priv(slave_dev); |
d945097b | 1029 | struct dsa_switch *ds = dp->ds; |
c305c165 | 1030 | |
0115dcd1 VD |
1031 | slave_dev->phydev = mdiobus_get_phy(ds->slave_mii_bus, addr); |
1032 | if (!slave_dev->phydev) { | |
d25b8e74 | 1033 | netdev_err(slave_dev, "no phy at %d\n", addr); |
c305c165 | 1034 | return -ENODEV; |
d25b8e74 | 1035 | } |
c305c165 FF |
1036 | |
1037 | /* Use already configured phy mode */ | |
211c504a | 1038 | if (p->phy_interface == PHY_INTERFACE_MODE_NA) |
0115dcd1 VD |
1039 | p->phy_interface = slave_dev->phydev->interface; |
1040 | ||
1041 | return phy_connect_direct(slave_dev, slave_dev->phydev, | |
1042 | dsa_slave_adjust_link, p->phy_interface); | |
c305c165 FF |
1043 | } |
1044 | ||
4fa7b718 | 1045 | static int dsa_slave_phy_setup(struct net_device *slave_dev) |
0d8bcdd3 | 1046 | { |
d945097b | 1047 | struct dsa_port *dp = dsa_slave_to_port(slave_dev); |
4fa7b718 | 1048 | struct dsa_slave_priv *p = netdev_priv(slave_dev); |
d945097b VD |
1049 | struct device_node *port_dn = dp->dn; |
1050 | struct dsa_switch *ds = dp->ds; | |
1051 | struct device_node *phy_dn; | |
ce31b31c | 1052 | bool phy_is_fixed = false; |
6819563e | 1053 | u32 phy_flags = 0; |
19334920 | 1054 | int mode, ret; |
0d8bcdd3 | 1055 | |
19334920 GR |
1056 | mode = of_get_phy_mode(port_dn); |
1057 | if (mode < 0) | |
1058 | mode = PHY_INTERFACE_MODE_NA; | |
1059 | p->phy_interface = mode; | |
0d8bcdd3 FF |
1060 | |
1061 | phy_dn = of_parse_phandle(port_dn, "phy-handle", 0); | |
0d8f3c67 | 1062 | if (!phy_dn && of_phy_is_fixed_link(port_dn)) { |
0d8bcdd3 FF |
1063 | /* In the case of a fixed PHY, the DT node associated |
1064 | * to the fixed PHY is the Port DT node | |
1065 | */ | |
1066 | ret = of_phy_register_fixed_link(port_dn); | |
1067 | if (ret) { | |
d25b8e74 | 1068 | netdev_err(slave_dev, "failed to register fixed PHY: %d\n", ret); |
9697f1cd | 1069 | return ret; |
0d8bcdd3 | 1070 | } |
ce31b31c | 1071 | phy_is_fixed = true; |
0d8f3c67 | 1072 | phy_dn = of_node_get(port_dn); |
0d8bcdd3 FF |
1073 | } |
1074 | ||
9d490b4e | 1075 | if (ds->ops->get_phy_flags) |
d945097b | 1076 | phy_flags = ds->ops->get_phy_flags(ds, dp->index); |
6819563e | 1077 | |
cd28a1a9 | 1078 | if (phy_dn) { |
399ba77a FF |
1079 | slave_dev->phydev = of_phy_connect(slave_dev, phy_dn, |
1080 | dsa_slave_adjust_link, | |
1081 | phy_flags, | |
1082 | p->phy_interface); | |
0d8f3c67 | 1083 | of_node_put(phy_dn); |
cd28a1a9 | 1084 | } |
0d8bcdd3 | 1085 | |
0115dcd1 VD |
1086 | if (slave_dev->phydev && phy_is_fixed) |
1087 | fixed_phy_set_link_update(slave_dev->phydev, | |
1088 | dsa_slave_fixed_link_update); | |
ce31b31c | 1089 | |
0d8bcdd3 FF |
1090 | /* We could not connect to a designated PHY, so use the switch internal |
1091 | * MDIO bus instead | |
1092 | */ | |
0115dcd1 | 1093 | if (!slave_dev->phydev) { |
d945097b | 1094 | ret = dsa_slave_phy_connect(slave_dev, dp->index); |
d25b8e74 | 1095 | if (ret) { |
afdcf151 | 1096 | netdev_err(slave_dev, "failed to connect to port %d: %d\n", |
d945097b | 1097 | dp->index, ret); |
881eadab JH |
1098 | if (phy_is_fixed) |
1099 | of_phy_deregister_fixed_link(port_dn); | |
c305c165 | 1100 | return ret; |
d25b8e74 | 1101 | } |
b31f65fb | 1102 | } |
9697f1cd | 1103 | |
0115dcd1 | 1104 | phy_attached_info(slave_dev->phydev); |
2220943a | 1105 | |
9697f1cd | 1106 | return 0; |
0d8bcdd3 FF |
1107 | } |
1108 | ||
448b4482 AL |
1109 | static struct lock_class_key dsa_slave_netdev_xmit_lock_key; |
1110 | static void dsa_slave_set_lockdep_class_one(struct net_device *dev, | |
1111 | struct netdev_queue *txq, | |
1112 | void *_unused) | |
1113 | { | |
1114 | lockdep_set_class(&txq->_xmit_lock, | |
1115 | &dsa_slave_netdev_xmit_lock_key); | |
1116 | } | |
1117 | ||
24462549 FF |
1118 | int dsa_slave_suspend(struct net_device *slave_dev) |
1119 | { | |
1120 | struct dsa_slave_priv *p = netdev_priv(slave_dev); | |
1121 | ||
f154be24 FF |
1122 | netif_device_detach(slave_dev); |
1123 | ||
0115dcd1 VD |
1124 | if (slave_dev->phydev) { |
1125 | phy_stop(slave_dev->phydev); | |
24462549 FF |
1126 | p->old_pause = -1; |
1127 | p->old_link = -1; | |
1128 | p->old_duplex = -1; | |
0115dcd1 | 1129 | phy_suspend(slave_dev->phydev); |
24462549 FF |
1130 | } |
1131 | ||
1132 | return 0; | |
1133 | } | |
1134 | ||
1135 | int dsa_slave_resume(struct net_device *slave_dev) | |
1136 | { | |
24462549 FF |
1137 | netif_device_attach(slave_dev); |
1138 | ||
0115dcd1 VD |
1139 | if (slave_dev->phydev) { |
1140 | phy_resume(slave_dev->phydev); | |
1141 | phy_start(slave_dev->phydev); | |
24462549 FF |
1142 | } |
1143 | ||
1144 | return 0; | |
1145 | } | |
1146 | ||
6158eaa7 VD |
1147 | static void dsa_slave_notify(struct net_device *dev, unsigned long val) |
1148 | { | |
d0006b00 | 1149 | struct net_device *master = dsa_slave_to_master(dev); |
d945097b | 1150 | struct dsa_port *dp = dsa_slave_to_port(dev); |
6158eaa7 VD |
1151 | struct dsa_notifier_register_info rinfo = { |
1152 | .switch_number = dp->ds->index, | |
1153 | .port_number = dp->index, | |
1154 | .master = master, | |
1155 | .info.dev = dev, | |
1156 | }; | |
1157 | ||
1158 | call_dsa_notifiers(val, dev, &rinfo.info); | |
1159 | } | |
1160 | ||
951259aa | 1161 | int dsa_slave_create(struct dsa_port *port) |
91da11f8 | 1162 | { |
24a9332a | 1163 | const struct dsa_port *cpu_dp = port->cpu_dp; |
f8b8b1cd | 1164 | struct net_device *master = cpu_dp->master; |
4cfbf09c | 1165 | struct dsa_switch *ds = port->ds; |
951259aa | 1166 | const char *name = port->name; |
91da11f8 LB |
1167 | struct net_device *slave_dev; |
1168 | struct dsa_slave_priv *p; | |
1169 | int ret; | |
1170 | ||
55199df6 FF |
1171 | if (!ds->num_tx_queues) |
1172 | ds->num_tx_queues = 1; | |
1173 | ||
1174 | slave_dev = alloc_netdev_mqs(sizeof(struct dsa_slave_priv), name, | |
1175 | NET_NAME_UNKNOWN, ether_setup, | |
1176 | ds->num_tx_queues, 1); | |
91da11f8 | 1177 | if (slave_dev == NULL) |
d87d6f44 | 1178 | return -ENOMEM; |
91da11f8 | 1179 | |
f50f2127 FF |
1180 | slave_dev->features = master->vlan_features | NETIF_F_HW_TC; |
1181 | slave_dev->hw_features |= NETIF_F_HW_TC; | |
7ad24ea4 | 1182 | slave_dev->ethtool_ops = &dsa_slave_ethtool_ops; |
2fcc8005 | 1183 | eth_hw_addr_inherit(slave_dev, master); |
0a5f107b | 1184 | slave_dev->priv_flags |= IFF_NO_QUEUE; |
3e8a72d1 | 1185 | slave_dev->netdev_ops = &dsa_slave_netdev_ops; |
9d47c0a2 | 1186 | slave_dev->switchdev_ops = &dsa_slave_switchdev_ops; |
8b1efc0f JW |
1187 | slave_dev->min_mtu = 0; |
1188 | slave_dev->max_mtu = ETH_MAX_MTU; | |
f37db85d | 1189 | SET_NETDEV_DEVTYPE(slave_dev, &dsa_type); |
d442ad4a | 1190 | |
448b4482 AL |
1191 | netdev_for_each_tx_queue(slave_dev, dsa_slave_set_lockdep_class_one, |
1192 | NULL); | |
1193 | ||
4cfbf09c VD |
1194 | SET_NETDEV_DEV(slave_dev, port->ds->dev); |
1195 | slave_dev->dev.of_node = port->dn; | |
5075314e AD |
1196 | slave_dev->vlan_features = master->vlan_features; |
1197 | ||
1198 | p = netdev_priv(slave_dev); | |
5f6b4e14 FF |
1199 | p->stats64 = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats); |
1200 | if (!p->stats64) { | |
1201 | free_netdev(slave_dev); | |
1202 | return -ENOMEM; | |
1203 | } | |
4cfbf09c | 1204 | p->dp = port; |
f50f2127 | 1205 | INIT_LIST_HEAD(&p->mall_tc_list); |
15240248 | 1206 | p->xmit = cpu_dp->tag_ops->xmit; |
d442ad4a | 1207 | |
0d8bcdd3 FF |
1208 | p->old_pause = -1; |
1209 | p->old_link = -1; | |
1210 | p->old_duplex = -1; | |
1211 | ||
f8b8b1cd | 1212 | port->slave = slave_dev; |
91da11f8 LB |
1213 | |
1214 | netif_carrier_off(slave_dev); | |
1215 | ||
4fa7b718 | 1216 | ret = dsa_slave_phy_setup(slave_dev); |
0071f56e AL |
1217 | if (ret) { |
1218 | netdev_err(master, "error %d setting up slave phy\n", ret); | |
e804441c FF |
1219 | goto out_free; |
1220 | } | |
1221 | ||
6158eaa7 | 1222 | dsa_slave_notify(slave_dev, DSA_PORT_REGISTER); |
60724d4b | 1223 | |
e804441c FF |
1224 | ret = register_netdev(slave_dev); |
1225 | if (ret) { | |
1226 | netdev_err(master, "error %d registering interface %s\n", | |
1227 | ret, slave_dev->name); | |
1228 | goto out_phy; | |
0071f56e AL |
1229 | } |
1230 | ||
d87d6f44 | 1231 | return 0; |
e804441c FF |
1232 | |
1233 | out_phy: | |
53954cf8 | 1234 | phy_disconnect(slave_dev->phydev); |
d945097b VD |
1235 | if (of_phy_is_fixed_link(port->dn)) |
1236 | of_phy_deregister_fixed_link(port->dn); | |
e804441c FF |
1237 | out_free: |
1238 | free_percpu(p->stats64); | |
1239 | free_netdev(slave_dev); | |
f8b8b1cd | 1240 | port->slave = NULL; |
e804441c | 1241 | return ret; |
91da11f8 | 1242 | } |
b73adef6 | 1243 | |
cda5c15b NA |
1244 | void dsa_slave_destroy(struct net_device *slave_dev) |
1245 | { | |
d945097b | 1246 | struct dsa_port *dp = dsa_slave_to_port(slave_dev); |
cda5c15b | 1247 | struct dsa_slave_priv *p = netdev_priv(slave_dev); |
d945097b | 1248 | struct device_node *port_dn = dp->dn; |
cda5c15b NA |
1249 | |
1250 | netif_carrier_off(slave_dev); | |
0115dcd1 VD |
1251 | if (slave_dev->phydev) { |
1252 | phy_disconnect(slave_dev->phydev); | |
881eadab JH |
1253 | |
1254 | if (of_phy_is_fixed_link(port_dn)) | |
1255 | of_phy_deregister_fixed_link(port_dn); | |
1256 | } | |
6158eaa7 | 1257 | dsa_slave_notify(slave_dev, DSA_PORT_UNREGISTER); |
cda5c15b | 1258 | unregister_netdev(slave_dev); |
5f6b4e14 | 1259 | free_percpu(p->stats64); |
cda5c15b NA |
1260 | free_netdev(slave_dev); |
1261 | } | |
1262 | ||
b73adef6 FF |
1263 | static bool dsa_slave_dev_check(struct net_device *dev) |
1264 | { | |
1265 | return dev->netdev_ops == &dsa_slave_netdev_ops; | |
1266 | } | |
1267 | ||
8e92ab3a VD |
1268 | static int dsa_slave_changeupper(struct net_device *dev, |
1269 | struct netdev_notifier_changeupper_info *info) | |
b73adef6 | 1270 | { |
d945097b | 1271 | struct dsa_port *dp = dsa_slave_to_port(dev); |
8e92ab3a | 1272 | int err = NOTIFY_DONE; |
b73adef6 | 1273 | |
8e92ab3a VD |
1274 | if (netif_is_bridge_master(info->upper_dev)) { |
1275 | if (info->linking) { | |
17d7802b | 1276 | err = dsa_port_bridge_join(dp, info->upper_dev); |
8e92ab3a VD |
1277 | err = notifier_from_errno(err); |
1278 | } else { | |
17d7802b | 1279 | dsa_port_bridge_leave(dp, info->upper_dev); |
8e92ab3a | 1280 | err = NOTIFY_OK; |
6debb68a | 1281 | } |
6debb68a | 1282 | } |
b73adef6 | 1283 | |
8e92ab3a | 1284 | return err; |
6debb68a | 1285 | } |
b73adef6 | 1286 | |
88e4f0ca VD |
1287 | static int dsa_slave_netdevice_event(struct notifier_block *nb, |
1288 | unsigned long event, void *ptr) | |
6debb68a VD |
1289 | { |
1290 | struct net_device *dev = netdev_notifier_info_to_dev(ptr); | |
1291 | ||
53bade8a | 1292 | if (!dsa_slave_dev_check(dev)) |
8e92ab3a VD |
1293 | return NOTIFY_DONE; |
1294 | ||
1295 | if (event == NETDEV_CHANGEUPPER) | |
1296 | return dsa_slave_changeupper(dev, ptr); | |
b73adef6 | 1297 | |
b73adef6 FF |
1298 | return NOTIFY_DONE; |
1299 | } | |
88e4f0ca | 1300 | |
c9eb3e0f AS |
1301 | struct dsa_switchdev_event_work { |
1302 | struct work_struct work; | |
1303 | struct switchdev_notifier_fdb_info fdb_info; | |
1304 | struct net_device *dev; | |
1305 | unsigned long event; | |
1306 | }; | |
1307 | ||
1308 | static void dsa_slave_switchdev_event_work(struct work_struct *work) | |
1309 | { | |
1310 | struct dsa_switchdev_event_work *switchdev_work = | |
1311 | container_of(work, struct dsa_switchdev_event_work, work); | |
1312 | struct net_device *dev = switchdev_work->dev; | |
1313 | struct switchdev_notifier_fdb_info *fdb_info; | |
d945097b | 1314 | struct dsa_port *dp = dsa_slave_to_port(dev); |
c9eb3e0f AS |
1315 | int err; |
1316 | ||
1317 | rtnl_lock(); | |
1318 | switch (switchdev_work->event) { | |
1319 | case SWITCHDEV_FDB_ADD_TO_DEVICE: | |
1320 | fdb_info = &switchdev_work->fdb_info; | |
d945097b | 1321 | err = dsa_port_fdb_add(dp, fdb_info->addr, fdb_info->vid); |
c9eb3e0f AS |
1322 | if (err) { |
1323 | netdev_dbg(dev, "fdb add failed err=%d\n", err); | |
1324 | break; | |
1325 | } | |
1326 | call_switchdev_notifiers(SWITCHDEV_FDB_OFFLOADED, dev, | |
1327 | &fdb_info->info); | |
1328 | break; | |
1329 | ||
1330 | case SWITCHDEV_FDB_DEL_TO_DEVICE: | |
1331 | fdb_info = &switchdev_work->fdb_info; | |
d945097b | 1332 | err = dsa_port_fdb_del(dp, fdb_info->addr, fdb_info->vid); |
c9eb3e0f AS |
1333 | if (err) { |
1334 | netdev_dbg(dev, "fdb del failed err=%d\n", err); | |
1335 | dev_close(dev); | |
1336 | } | |
1337 | break; | |
1338 | } | |
1339 | rtnl_unlock(); | |
1340 | ||
1341 | kfree(switchdev_work->fdb_info.addr); | |
1342 | kfree(switchdev_work); | |
1343 | dev_put(dev); | |
1344 | } | |
1345 | ||
1346 | static int | |
1347 | dsa_slave_switchdev_fdb_work_init(struct dsa_switchdev_event_work * | |
1348 | switchdev_work, | |
1349 | const struct switchdev_notifier_fdb_info * | |
1350 | fdb_info) | |
1351 | { | |
1352 | memcpy(&switchdev_work->fdb_info, fdb_info, | |
1353 | sizeof(switchdev_work->fdb_info)); | |
1354 | switchdev_work->fdb_info.addr = kzalloc(ETH_ALEN, GFP_ATOMIC); | |
1355 | if (!switchdev_work->fdb_info.addr) | |
1356 | return -ENOMEM; | |
1357 | ether_addr_copy((u8 *)switchdev_work->fdb_info.addr, | |
1358 | fdb_info->addr); | |
1359 | return 0; | |
1360 | } | |
1361 | ||
1362 | /* Called under rcu_read_lock() */ | |
1363 | static int dsa_slave_switchdev_event(struct notifier_block *unused, | |
1364 | unsigned long event, void *ptr) | |
1365 | { | |
1366 | struct net_device *dev = switchdev_notifier_info_to_dev(ptr); | |
1367 | struct dsa_switchdev_event_work *switchdev_work; | |
1368 | ||
1369 | if (!dsa_slave_dev_check(dev)) | |
1370 | return NOTIFY_DONE; | |
1371 | ||
1372 | switchdev_work = kzalloc(sizeof(*switchdev_work), GFP_ATOMIC); | |
1373 | if (!switchdev_work) | |
1374 | return NOTIFY_BAD; | |
1375 | ||
1376 | INIT_WORK(&switchdev_work->work, | |
1377 | dsa_slave_switchdev_event_work); | |
1378 | switchdev_work->dev = dev; | |
1379 | switchdev_work->event = event; | |
1380 | ||
1381 | switch (event) { | |
1382 | case SWITCHDEV_FDB_ADD_TO_DEVICE: /* fall through */ | |
1383 | case SWITCHDEV_FDB_DEL_TO_DEVICE: | |
1384 | if (dsa_slave_switchdev_fdb_work_init(switchdev_work, | |
1385 | ptr)) | |
1386 | goto err_fdb_work_init; | |
1387 | dev_hold(dev); | |
1388 | break; | |
1389 | default: | |
1390 | kfree(switchdev_work); | |
1391 | return NOTIFY_DONE; | |
1392 | } | |
1393 | ||
1394 | dsa_schedule_work(&switchdev_work->work); | |
1395 | return NOTIFY_OK; | |
1396 | ||
1397 | err_fdb_work_init: | |
1398 | kfree(switchdev_work); | |
1399 | return NOTIFY_BAD; | |
1400 | } | |
1401 | ||
88e4f0ca | 1402 | static struct notifier_block dsa_slave_nb __read_mostly = { |
c9eb3e0f AS |
1403 | .notifier_call = dsa_slave_netdevice_event, |
1404 | }; | |
1405 | ||
1406 | static struct notifier_block dsa_slave_switchdev_notifier = { | |
1407 | .notifier_call = dsa_slave_switchdev_event, | |
88e4f0ca VD |
1408 | }; |
1409 | ||
1410 | int dsa_slave_register_notifier(void) | |
1411 | { | |
c9eb3e0f AS |
1412 | int err; |
1413 | ||
1414 | err = register_netdevice_notifier(&dsa_slave_nb); | |
1415 | if (err) | |
1416 | return err; | |
1417 | ||
1418 | err = register_switchdev_notifier(&dsa_slave_switchdev_notifier); | |
1419 | if (err) | |
1420 | goto err_switchdev_nb; | |
1421 | ||
1422 | return 0; | |
1423 | ||
1424 | err_switchdev_nb: | |
1425 | unregister_netdevice_notifier(&dsa_slave_nb); | |
1426 | return err; | |
88e4f0ca VD |
1427 | } |
1428 | ||
1429 | void dsa_slave_unregister_notifier(void) | |
1430 | { | |
1431 | int err; | |
1432 | ||
c9eb3e0f AS |
1433 | err = unregister_switchdev_notifier(&dsa_slave_switchdev_notifier); |
1434 | if (err) | |
1435 | pr_err("DSA: failed to unregister switchdev notifier (%d)\n", err); | |
1436 | ||
88e4f0ca VD |
1437 | err = unregister_netdevice_notifier(&dsa_slave_nb); |
1438 | if (err) | |
1439 | pr_err("DSA: failed to unregister slave notifier (%d)\n", err); | |
1440 | } |