blob: 5fc87ee539052eea4c6ec3335218074c9313f76f [file] [log] [blame]
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001/*
2 * net/dsa/slave.c - Slave device handling
Lennert Buytenheke84665c2009-03-20 09:52:09 +00003 * Copyright (c) 2008-2009 Marvell Semiconductor
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00004 *
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>
Lennert Buytenhekdf02c6f2008-11-10 21:53:12 -080012#include <linux/etherdevice.h>
Florian Fainellib73adef2015-02-24 13:15:33 -080013#include <linux/netdevice.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000014#include <linux/phy.h>
Florian Fainellia2820542014-10-17 16:02:13 -070015#include <linux/phy_fixed.h>
Florian Fainelli0d8bcdd2014-08-27 17:04:51 -070016#include <linux/of_net.h>
17#include <linux/of_mdio.h>
Florian Fainellib73adef2015-02-24 13:15:33 -080018#include <net/rtnetlink.h>
Scott Feldman98237d42015-03-15 21:07:15 -070019#include <net/switchdev.h>
Florian Fainellib73adef2015-02-24 13:15:33 -080020#include <linux/if_bridge.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000021#include "dsa_priv.h"
22
23/* slave mii_bus handling ***************************************************/
24static int dsa_slave_phy_read(struct mii_bus *bus, int addr, int reg)
25{
26 struct dsa_switch *ds = bus->priv;
27
Florian Fainelli0d8bcdd2014-08-27 17:04:51 -070028 if (ds->phys_mii_mask & (1 << addr))
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000029 return ds->drv->phy_read(ds, addr, reg);
30
31 return 0xffff;
32}
33
34static int dsa_slave_phy_write(struct mii_bus *bus, int addr, int reg, u16 val)
35{
36 struct dsa_switch *ds = bus->priv;
37
Florian Fainelli0d8bcdd2014-08-27 17:04:51 -070038 if (ds->phys_mii_mask & (1 << addr))
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000039 return ds->drv->phy_write(ds, addr, reg, val);
40
41 return 0;
42}
43
44void dsa_slave_mii_bus_init(struct dsa_switch *ds)
45{
46 ds->slave_mii_bus->priv = (void *)ds;
47 ds->slave_mii_bus->name = "dsa slave smi";
48 ds->slave_mii_bus->read = dsa_slave_phy_read;
49 ds->slave_mii_bus->write = dsa_slave_phy_write;
Florian Fainellif490be02013-01-21 09:58:50 +000050 snprintf(ds->slave_mii_bus->id, MII_BUS_ID_SIZE, "dsa-%d:%.2x",
51 ds->index, ds->pd->sw_addr);
Alexander Duyckb4d23942014-09-15 13:00:27 -040052 ds->slave_mii_bus->parent = ds->master_dev;
Vivien Didelot24df8982015-01-20 19:13:32 -050053 ds->slave_mii_bus->phy_mask = ~ds->phys_mii_mask;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000054}
55
56
57/* slave device handling ****************************************************/
Nicolas Dichtelabd2be02015-04-02 17:07:08 +020058static int dsa_slave_get_iflink(const struct net_device *dev)
Lennert Buytenhekc0840802009-03-20 09:49:49 +000059{
60 struct dsa_slave_priv *p = netdev_priv(dev);
Lennert Buytenhekc0840802009-03-20 09:49:49 +000061
Nicolas Dichtelabd2be02015-04-02 17:07:08 +020062 return p->parent->dst->master_netdev->ifindex;
Lennert Buytenhekc0840802009-03-20 09:49:49 +000063}
64
Florian Fainellib73adef2015-02-24 13:15:33 -080065static inline bool dsa_port_is_bridged(struct dsa_slave_priv *p)
66{
67 return !!p->bridge_dev;
68}
69
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000070static int dsa_slave_open(struct net_device *dev)
71{
Lennert Buytenhekdf02c6f2008-11-10 21:53:12 -080072 struct dsa_slave_priv *p = netdev_priv(dev);
Lennert Buytenheke84665c2009-03-20 09:52:09 +000073 struct net_device *master = p->parent->dst->master_netdev;
Florian Fainellib2f2af22014-09-24 17:05:18 -070074 struct dsa_switch *ds = p->parent;
Florian Fainellib73adef2015-02-24 13:15:33 -080075 u8 stp_state = dsa_port_is_bridged(p) ?
76 BR_STATE_BLOCKING : BR_STATE_FORWARDING;
Lennert Buytenhekdf02c6f2008-11-10 21:53:12 -080077 int err;
78
79 if (!(master->flags & IFF_UP))
80 return -ENETDOWN;
81
Joe Perches8feedbb2012-05-08 18:56:57 +000082 if (!ether_addr_equal(dev->dev_addr, master->dev_addr)) {
Jiri Pirkoa748ee22010-04-01 21:22:09 +000083 err = dev_uc_add(master, dev->dev_addr);
Lennert Buytenhekdf02c6f2008-11-10 21:53:12 -080084 if (err < 0)
85 goto out;
86 }
87
88 if (dev->flags & IFF_ALLMULTI) {
89 err = dev_set_allmulti(master, 1);
90 if (err < 0)
91 goto del_unicast;
92 }
93 if (dev->flags & IFF_PROMISC) {
94 err = dev_set_promiscuity(master, 1);
95 if (err < 0)
96 goto clear_allmulti;
97 }
98
Florian Fainellib2f2af22014-09-24 17:05:18 -070099 if (ds->drv->port_enable) {
100 err = ds->drv->port_enable(ds, p->port, p->phy);
101 if (err)
102 goto clear_promisc;
103 }
104
Florian Fainellib73adef2015-02-24 13:15:33 -0800105 if (ds->drv->port_stp_update)
106 ds->drv->port_stp_update(ds, p->port, stp_state);
107
Florian Fainellif7f1de52014-09-24 17:05:17 -0700108 if (p->phy)
109 phy_start(p->phy);
110
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000111 return 0;
Lennert Buytenhekdf02c6f2008-11-10 21:53:12 -0800112
Florian Fainellib2f2af22014-09-24 17:05:18 -0700113clear_promisc:
114 if (dev->flags & IFF_PROMISC)
Gilad Ben-Yossef4fdeddf2015-06-25 16:50:13 +0300115 dev_set_promiscuity(master, -1);
Lennert Buytenhekdf02c6f2008-11-10 21:53:12 -0800116clear_allmulti:
117 if (dev->flags & IFF_ALLMULTI)
118 dev_set_allmulti(master, -1);
119del_unicast:
Joe Perches8feedbb2012-05-08 18:56:57 +0000120 if (!ether_addr_equal(dev->dev_addr, master->dev_addr))
Jiri Pirkoa748ee22010-04-01 21:22:09 +0000121 dev_uc_del(master, dev->dev_addr);
Lennert Buytenhekdf02c6f2008-11-10 21:53:12 -0800122out:
123 return err;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000124}
125
126static int dsa_slave_close(struct net_device *dev)
127{
Lennert Buytenhekdf02c6f2008-11-10 21:53:12 -0800128 struct dsa_slave_priv *p = netdev_priv(dev);
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000129 struct net_device *master = p->parent->dst->master_netdev;
Florian Fainellib2f2af22014-09-24 17:05:18 -0700130 struct dsa_switch *ds = p->parent;
Lennert Buytenhekdf02c6f2008-11-10 21:53:12 -0800131
Florian Fainellif7f1de52014-09-24 17:05:17 -0700132 if (p->phy)
133 phy_stop(p->phy);
134
Lennert Buytenhekdf02c6f2008-11-10 21:53:12 -0800135 dev_mc_unsync(master, dev);
Jiri Pirkoa748ee22010-04-01 21:22:09 +0000136 dev_uc_unsync(master, dev);
Lennert Buytenhekdf02c6f2008-11-10 21:53:12 -0800137 if (dev->flags & IFF_ALLMULTI)
138 dev_set_allmulti(master, -1);
139 if (dev->flags & IFF_PROMISC)
140 dev_set_promiscuity(master, -1);
141
Joe Perches8feedbb2012-05-08 18:56:57 +0000142 if (!ether_addr_equal(dev->dev_addr, master->dev_addr))
Jiri Pirkoa748ee22010-04-01 21:22:09 +0000143 dev_uc_del(master, dev->dev_addr);
Lennert Buytenhekdf02c6f2008-11-10 21:53:12 -0800144
Florian Fainellib2f2af22014-09-24 17:05:18 -0700145 if (ds->drv->port_disable)
146 ds->drv->port_disable(ds, p->port, p->phy);
147
Florian Fainellib73adef2015-02-24 13:15:33 -0800148 if (ds->drv->port_stp_update)
149 ds->drv->port_stp_update(ds, p->port, BR_STATE_DISABLED);
150
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000151 return 0;
152}
153
154static void dsa_slave_change_rx_flags(struct net_device *dev, int change)
155{
156 struct dsa_slave_priv *p = netdev_priv(dev);
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000157 struct net_device *master = p->parent->dst->master_netdev;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000158
159 if (change & IFF_ALLMULTI)
160 dev_set_allmulti(master, dev->flags & IFF_ALLMULTI ? 1 : -1);
161 if (change & IFF_PROMISC)
162 dev_set_promiscuity(master, dev->flags & IFF_PROMISC ? 1 : -1);
163}
164
165static void dsa_slave_set_rx_mode(struct net_device *dev)
166{
167 struct dsa_slave_priv *p = netdev_priv(dev);
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000168 struct net_device *master = p->parent->dst->master_netdev;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000169
170 dev_mc_sync(master, dev);
Jiri Pirkoa748ee22010-04-01 21:22:09 +0000171 dev_uc_sync(master, dev);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000172}
173
Lennert Buytenhekdf02c6f2008-11-10 21:53:12 -0800174static int dsa_slave_set_mac_address(struct net_device *dev, void *a)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000175{
Lennert Buytenhekdf02c6f2008-11-10 21:53:12 -0800176 struct dsa_slave_priv *p = netdev_priv(dev);
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000177 struct net_device *master = p->parent->dst->master_netdev;
Lennert Buytenhekdf02c6f2008-11-10 21:53:12 -0800178 struct sockaddr *addr = a;
179 int err;
180
181 if (!is_valid_ether_addr(addr->sa_data))
182 return -EADDRNOTAVAIL;
183
184 if (!(dev->flags & IFF_UP))
185 goto out;
186
Joe Perches8feedbb2012-05-08 18:56:57 +0000187 if (!ether_addr_equal(addr->sa_data, master->dev_addr)) {
Jiri Pirkoa748ee22010-04-01 21:22:09 +0000188 err = dev_uc_add(master, addr->sa_data);
Lennert Buytenhekdf02c6f2008-11-10 21:53:12 -0800189 if (err < 0)
190 return err;
191 }
192
Joe Perches8feedbb2012-05-08 18:56:57 +0000193 if (!ether_addr_equal(dev->dev_addr, master->dev_addr))
Jiri Pirkoa748ee22010-04-01 21:22:09 +0000194 dev_uc_del(master, dev->dev_addr);
Lennert Buytenhekdf02c6f2008-11-10 21:53:12 -0800195
196out:
Joe Perchesd08f1612014-01-20 09:52:20 -0800197 ether_addr_copy(dev->dev_addr, addr->sa_data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000198
199 return 0;
200}
201
Guenter Roeck339d8262015-03-26 18:36:37 -0700202static int dsa_slave_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
203 struct net_device *dev,
204 const unsigned char *addr, u16 vid, u16 nlm_flags)
205{
206 struct dsa_slave_priv *p = netdev_priv(dev);
207 struct dsa_switch *ds = p->parent;
208 int ret = -EOPNOTSUPP;
209
210 if (ds->drv->fdb_add)
211 ret = ds->drv->fdb_add(ds, p->port, addr, vid);
212
213 return ret;
214}
215
216static int dsa_slave_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
217 struct net_device *dev,
218 const unsigned char *addr, u16 vid)
219{
220 struct dsa_slave_priv *p = netdev_priv(dev);
221 struct dsa_switch *ds = p->parent;
222 int ret = -EOPNOTSUPP;
223
224 if (ds->drv->fdb_del)
225 ret = ds->drv->fdb_del(ds, p->port, addr, vid);
226
227 return ret;
228}
229
230static int dsa_slave_fill_info(struct net_device *dev, struct sk_buff *skb,
231 const unsigned char *addr, u16 vid,
232 bool is_static,
233 u32 portid, u32 seq, int type,
234 unsigned int flags)
235{
236 struct nlmsghdr *nlh;
237 struct ndmsg *ndm;
238
239 nlh = nlmsg_put(skb, portid, seq, type, sizeof(*ndm), flags);
240 if (!nlh)
241 return -EMSGSIZE;
242
243 ndm = nlmsg_data(nlh);
244 ndm->ndm_family = AF_BRIDGE;
245 ndm->ndm_pad1 = 0;
246 ndm->ndm_pad2 = 0;
247 ndm->ndm_flags = NTF_EXT_LEARNED;
248 ndm->ndm_type = 0;
249 ndm->ndm_ifindex = dev->ifindex;
250 ndm->ndm_state = is_static ? NUD_NOARP : NUD_REACHABLE;
251
252 if (nla_put(skb, NDA_LLADDR, ETH_ALEN, addr))
253 goto nla_put_failure;
254
255 if (vid && nla_put_u16(skb, NDA_VLAN, vid))
256 goto nla_put_failure;
257
258 nlmsg_end(skb, nlh);
259 return 0;
260
261nla_put_failure:
262 nlmsg_cancel(skb, nlh);
263 return -EMSGSIZE;
264}
265
266/* Dump information about entries, in response to GETNEIGH */
267static int dsa_slave_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
268 struct net_device *dev,
269 struct net_device *filter_dev, int idx)
270{
271 struct dsa_slave_priv *p = netdev_priv(dev);
272 struct dsa_switch *ds = p->parent;
273 unsigned char addr[ETH_ALEN] = { 0 };
274 int ret;
275
276 if (!ds->drv->fdb_getnext)
277 return -EOPNOTSUPP;
278
279 for (; ; idx++) {
280 bool is_static;
281
282 ret = ds->drv->fdb_getnext(ds, p->port, addr, &is_static);
283 if (ret < 0)
284 break;
285
286 if (idx < cb->args[0])
287 continue;
288
289 ret = dsa_slave_fill_info(dev, skb, addr, 0,
290 is_static,
291 NETLINK_CB(cb->skb).portid,
292 cb->nlh->nlmsg_seq,
293 RTM_NEWNEIGH, NLM_F_MULTI);
294 if (ret < 0)
295 break;
296 }
297
298 return idx;
299}
300
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000301static int dsa_slave_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
302{
303 struct dsa_slave_priv *p = netdev_priv(dev);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000304
305 if (p->phy != NULL)
Richard Cochran28b04112010-07-17 08:48:55 +0000306 return phy_mii_ioctl(p->phy, ifr, cmd);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000307
308 return -EOPNOTSUPP;
309}
310
Florian Fainellib73adef2015-02-24 13:15:33 -0800311/* Return a bitmask of all ports being currently bridged within a given bridge
312 * device. Note that on leave, the mask will still return the bitmask of ports
313 * currently bridged, prior to port removal, and this is exactly what we want.
314 */
315static u32 dsa_slave_br_port_mask(struct dsa_switch *ds,
316 struct net_device *bridge)
317{
318 struct dsa_slave_priv *p;
319 unsigned int port;
320 u32 mask = 0;
321
322 for (port = 0; port < DSA_MAX_PORTS; port++) {
Guenter Roeckd79d2102015-02-24 23:02:02 -0800323 if (!dsa_is_port_initialized(ds, port))
Florian Fainellib73adef2015-02-24 13:15:33 -0800324 continue;
325
326 p = netdev_priv(ds->ports[port]);
327
328 if (ds->ports[port]->priv_flags & IFF_BRIDGE_PORT &&
329 p->bridge_dev == bridge)
330 mask |= 1 << port;
331 }
332
333 return mask;
334}
335
336static int dsa_slave_stp_update(struct net_device *dev, u8 state)
337{
338 struct dsa_slave_priv *p = netdev_priv(dev);
339 struct dsa_switch *ds = p->parent;
340 int ret = -EOPNOTSUPP;
341
342 if (ds->drv->port_stp_update)
343 ret = ds->drv->port_stp_update(ds, p->port, state);
344
345 return ret;
346}
347
Scott Feldman35636062015-05-10 09:47:51 -0700348static int dsa_slave_port_attr_set(struct net_device *dev,
349 struct switchdev_attr *attr)
350{
351 int ret = 0;
352
353 switch (attr->id) {
354 case SWITCHDEV_ATTR_PORT_STP_STATE:
355 if (attr->trans == SWITCHDEV_TRANS_COMMIT)
Scott Feldman42275bd2015-05-13 11:16:50 -0700356 ret = dsa_slave_stp_update(dev, attr->u.stp_state);
Scott Feldman35636062015-05-10 09:47:51 -0700357 break;
358 default:
359 ret = -EOPNOTSUPP;
360 break;
361 }
362
363 return ret;
364}
365
Florian Fainellib73adef2015-02-24 13:15:33 -0800366static int dsa_slave_bridge_port_join(struct net_device *dev,
367 struct net_device *br)
368{
369 struct dsa_slave_priv *p = netdev_priv(dev);
370 struct dsa_switch *ds = p->parent;
371 int ret = -EOPNOTSUPP;
372
373 p->bridge_dev = br;
374
375 if (ds->drv->port_join_bridge)
376 ret = ds->drv->port_join_bridge(ds, p->port,
377 dsa_slave_br_port_mask(ds, br));
378
379 return ret;
380}
381
382static int dsa_slave_bridge_port_leave(struct net_device *dev)
383{
384 struct dsa_slave_priv *p = netdev_priv(dev);
385 struct dsa_switch *ds = p->parent;
386 int ret = -EOPNOTSUPP;
387
388
389 if (ds->drv->port_leave_bridge)
390 ret = ds->drv->port_leave_bridge(ds, p->port,
391 dsa_slave_br_port_mask(ds, p->bridge_dev));
392
393 p->bridge_dev = NULL;
394
395 /* Port left the bridge, put in BR_STATE_DISABLED by the bridge layer,
396 * so allow it to be in BR_STATE_FORWARDING to be kept functional
397 */
398 dsa_slave_stp_update(dev, BR_STATE_FORWARDING);
399
400 return ret;
401}
402
Scott Feldmanf8e20a92015-05-10 09:47:49 -0700403static int dsa_slave_port_attr_get(struct net_device *dev,
404 struct switchdev_attr *attr)
Florian Fainellib73adef2015-02-24 13:15:33 -0800405{
406 struct dsa_slave_priv *p = netdev_priv(dev);
407 struct dsa_switch *ds = p->parent;
408
Scott Feldmanf8e20a92015-05-10 09:47:49 -0700409 switch (attr->id) {
410 case SWITCHDEV_ATTR_PORT_PARENT_ID:
Scott Feldman42275bd2015-05-13 11:16:50 -0700411 attr->u.ppid.id_len = sizeof(ds->index);
412 memcpy(&attr->u.ppid.id, &ds->index, attr->u.ppid.id_len);
Scott Feldmanf8e20a92015-05-10 09:47:49 -0700413 break;
414 default:
415 return -EOPNOTSUPP;
416 }
Florian Fainellib73adef2015-02-24 13:15:33 -0800417
418 return 0;
419}
420
Florian Fainelli3e8a72d2014-08-27 17:04:46 -0700421static netdev_tx_t dsa_slave_xmit(struct sk_buff *skb, struct net_device *dev)
422{
423 struct dsa_slave_priv *p = netdev_priv(dev);
Florian Fainelli4ed70ce2015-07-31 11:42:56 -0700424 struct sk_buff *nskb;
Florian Fainelli3e8a72d2014-08-27 17:04:46 -0700425
Florian Fainelli4ed70ce2015-07-31 11:42:56 -0700426 dev->stats.tx_packets++;
427 dev->stats.tx_bytes += skb->len;
Florian Fainelli3e8a72d2014-08-27 17:04:46 -0700428
Florian Fainelli4ed70ce2015-07-31 11:42:56 -0700429 /* Transmit function may have to reallocate the original SKB */
430 nskb = p->xmit(skb, dev);
431 if (!nskb)
432 return NETDEV_TX_OK;
Florian Fainelli5aed85c2014-08-27 17:04:52 -0700433
Florian Fainelli4ed70ce2015-07-31 11:42:56 -0700434 /* Queue the SKB for transmission on the parent interface, but
435 * do not modify its EtherType
436 */
437 nskb->dev = p->parent->dst->master_netdev;
438 dev_queue_xmit(nskb);
Florian Fainelli5aed85c2014-08-27 17:04:52 -0700439
440 return NETDEV_TX_OK;
441}
442
Florian Fainelli4ed70ce2015-07-31 11:42:56 -0700443static struct sk_buff *dsa_slave_notag_xmit(struct sk_buff *skb,
444 struct net_device *dev)
445{
446 /* Just return the original SKB */
447 return skb;
448}
449
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000450
451/* ethtool operations *******************************************************/
452static int
453dsa_slave_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
454{
455 struct dsa_slave_priv *p = netdev_priv(dev);
456 int err;
457
458 err = -EOPNOTSUPP;
459 if (p->phy != NULL) {
460 err = phy_read_status(p->phy);
461 if (err == 0)
462 err = phy_ethtool_gset(p->phy, cmd);
463 }
464
465 return err;
466}
467
468static int
469dsa_slave_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
470{
471 struct dsa_slave_priv *p = netdev_priv(dev);
472
473 if (p->phy != NULL)
474 return phy_ethtool_sset(p->phy, cmd);
475
476 return -EOPNOTSUPP;
477}
478
479static void dsa_slave_get_drvinfo(struct net_device *dev,
480 struct ethtool_drvinfo *drvinfo)
481{
Jiri Pirko7826d432013-01-06 00:44:26 +0000482 strlcpy(drvinfo->driver, "dsa", sizeof(drvinfo->driver));
483 strlcpy(drvinfo->version, dsa_driver_version, sizeof(drvinfo->version));
484 strlcpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version));
485 strlcpy(drvinfo->bus_info, "platform", sizeof(drvinfo->bus_info));
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000486}
487
Guenter Roeck3d762a02014-10-29 10:45:04 -0700488static int dsa_slave_get_regs_len(struct net_device *dev)
489{
490 struct dsa_slave_priv *p = netdev_priv(dev);
491 struct dsa_switch *ds = p->parent;
492
493 if (ds->drv->get_regs_len)
494 return ds->drv->get_regs_len(ds, p->port);
495
496 return -EOPNOTSUPP;
497}
498
499static void
500dsa_slave_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *_p)
501{
502 struct dsa_slave_priv *p = netdev_priv(dev);
503 struct dsa_switch *ds = p->parent;
504
505 if (ds->drv->get_regs)
506 ds->drv->get_regs(ds, p->port, regs, _p);
507}
508
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000509static int dsa_slave_nway_reset(struct net_device *dev)
510{
511 struct dsa_slave_priv *p = netdev_priv(dev);
512
513 if (p->phy != NULL)
514 return genphy_restart_aneg(p->phy);
515
516 return -EOPNOTSUPP;
517}
518
519static u32 dsa_slave_get_link(struct net_device *dev)
520{
521 struct dsa_slave_priv *p = netdev_priv(dev);
522
523 if (p->phy != NULL) {
524 genphy_update_link(p->phy);
525 return p->phy->link;
526 }
527
528 return -EOPNOTSUPP;
529}
530
Guenter Roeck6793abb2014-10-29 10:45:01 -0700531static int dsa_slave_get_eeprom_len(struct net_device *dev)
532{
533 struct dsa_slave_priv *p = netdev_priv(dev);
534 struct dsa_switch *ds = p->parent;
535
536 if (ds->pd->eeprom_len)
537 return ds->pd->eeprom_len;
538
539 if (ds->drv->get_eeprom_len)
540 return ds->drv->get_eeprom_len(ds);
541
542 return 0;
543}
544
545static int dsa_slave_get_eeprom(struct net_device *dev,
546 struct ethtool_eeprom *eeprom, u8 *data)
547{
548 struct dsa_slave_priv *p = netdev_priv(dev);
549 struct dsa_switch *ds = p->parent;
550
551 if (ds->drv->get_eeprom)
552 return ds->drv->get_eeprom(ds, eeprom, data);
553
554 return -EOPNOTSUPP;
555}
556
557static int dsa_slave_set_eeprom(struct net_device *dev,
558 struct ethtool_eeprom *eeprom, u8 *data)
559{
560 struct dsa_slave_priv *p = netdev_priv(dev);
561 struct dsa_switch *ds = p->parent;
562
563 if (ds->drv->set_eeprom)
564 return ds->drv->set_eeprom(ds, eeprom, data);
565
566 return -EOPNOTSUPP;
567}
568
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000569static void dsa_slave_get_strings(struct net_device *dev,
570 uint32_t stringset, uint8_t *data)
571{
572 struct dsa_slave_priv *p = netdev_priv(dev);
573 struct dsa_switch *ds = p->parent;
574
575 if (stringset == ETH_SS_STATS) {
576 int len = ETH_GSTRING_LEN;
577
578 strncpy(data, "tx_packets", len);
579 strncpy(data + len, "tx_bytes", len);
580 strncpy(data + 2 * len, "rx_packets", len);
581 strncpy(data + 3 * len, "rx_bytes", len);
582 if (ds->drv->get_strings != NULL)
583 ds->drv->get_strings(ds, p->port, data + 4 * len);
584 }
585}
586
587static void dsa_slave_get_ethtool_stats(struct net_device *dev,
588 struct ethtool_stats *stats,
589 uint64_t *data)
590{
591 struct dsa_slave_priv *p = netdev_priv(dev);
592 struct dsa_switch *ds = p->parent;
593
594 data[0] = p->dev->stats.tx_packets;
595 data[1] = p->dev->stats.tx_bytes;
596 data[2] = p->dev->stats.rx_packets;
597 data[3] = p->dev->stats.rx_bytes;
598 if (ds->drv->get_ethtool_stats != NULL)
599 ds->drv->get_ethtool_stats(ds, p->port, data + 4);
600}
601
602static int dsa_slave_get_sset_count(struct net_device *dev, int sset)
603{
604 struct dsa_slave_priv *p = netdev_priv(dev);
605 struct dsa_switch *ds = p->parent;
606
607 if (sset == ETH_SS_STATS) {
608 int count;
609
610 count = 4;
611 if (ds->drv->get_sset_count != NULL)
612 count += ds->drv->get_sset_count(ds);
613
614 return count;
615 }
616
617 return -EOPNOTSUPP;
618}
619
Florian Fainelli19e57c42014-09-18 17:31:24 -0700620static void dsa_slave_get_wol(struct net_device *dev, struct ethtool_wolinfo *w)
621{
622 struct dsa_slave_priv *p = netdev_priv(dev);
623 struct dsa_switch *ds = p->parent;
624
625 if (ds->drv->get_wol)
626 ds->drv->get_wol(ds, p->port, w);
627}
628
629static int dsa_slave_set_wol(struct net_device *dev, struct ethtool_wolinfo *w)
630{
631 struct dsa_slave_priv *p = netdev_priv(dev);
632 struct dsa_switch *ds = p->parent;
633 int ret = -EOPNOTSUPP;
634
635 if (ds->drv->set_wol)
636 ret = ds->drv->set_wol(ds, p->port, w);
637
638 return ret;
639}
640
Florian Fainelli79052882014-09-24 17:05:21 -0700641static int dsa_slave_set_eee(struct net_device *dev, struct ethtool_eee *e)
642{
643 struct dsa_slave_priv *p = netdev_priv(dev);
644 struct dsa_switch *ds = p->parent;
645 int ret;
646
647 if (!ds->drv->set_eee)
648 return -EOPNOTSUPP;
649
650 ret = ds->drv->set_eee(ds, p->port, p->phy, e);
651 if (ret)
652 return ret;
653
654 if (p->phy)
655 ret = phy_ethtool_set_eee(p->phy, e);
656
657 return ret;
658}
659
660static int dsa_slave_get_eee(struct net_device *dev, struct ethtool_eee *e)
661{
662 struct dsa_slave_priv *p = netdev_priv(dev);
663 struct dsa_switch *ds = p->parent;
664 int ret;
665
666 if (!ds->drv->get_eee)
667 return -EOPNOTSUPP;
668
669 ret = ds->drv->get_eee(ds, p->port, e);
670 if (ret)
671 return ret;
672
673 if (p->phy)
674 ret = phy_ethtool_get_eee(p->phy, e);
675
676 return ret;
677}
678
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000679static const struct ethtool_ops dsa_slave_ethtool_ops = {
680 .get_settings = dsa_slave_get_settings,
681 .set_settings = dsa_slave_set_settings,
682 .get_drvinfo = dsa_slave_get_drvinfo,
Guenter Roeck3d762a02014-10-29 10:45:04 -0700683 .get_regs_len = dsa_slave_get_regs_len,
684 .get_regs = dsa_slave_get_regs,
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000685 .nway_reset = dsa_slave_nway_reset,
686 .get_link = dsa_slave_get_link,
Guenter Roeck6793abb2014-10-29 10:45:01 -0700687 .get_eeprom_len = dsa_slave_get_eeprom_len,
688 .get_eeprom = dsa_slave_get_eeprom,
689 .set_eeprom = dsa_slave_set_eeprom,
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000690 .get_strings = dsa_slave_get_strings,
691 .get_ethtool_stats = dsa_slave_get_ethtool_stats,
692 .get_sset_count = dsa_slave_get_sset_count,
Florian Fainelli19e57c42014-09-18 17:31:24 -0700693 .set_wol = dsa_slave_set_wol,
694 .get_wol = dsa_slave_get_wol,
Florian Fainelli79052882014-09-24 17:05:21 -0700695 .set_eee = dsa_slave_set_eee,
696 .get_eee = dsa_slave_get_eee,
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000697};
698
Florian Fainelli3e8a72d2014-08-27 17:04:46 -0700699static const struct net_device_ops dsa_slave_netdev_ops = {
Stephen Hemmingerd442ad42009-01-06 16:45:26 -0800700 .ndo_open = dsa_slave_open,
701 .ndo_stop = dsa_slave_close,
Florian Fainelli3e8a72d2014-08-27 17:04:46 -0700702 .ndo_start_xmit = dsa_slave_xmit,
Stephen Hemmingerd442ad42009-01-06 16:45:26 -0800703 .ndo_change_rx_flags = dsa_slave_change_rx_flags,
704 .ndo_set_rx_mode = dsa_slave_set_rx_mode,
Stephen Hemmingerd442ad42009-01-06 16:45:26 -0800705 .ndo_set_mac_address = dsa_slave_set_mac_address,
Guenter Roeck339d8262015-03-26 18:36:37 -0700706 .ndo_fdb_add = dsa_slave_fdb_add,
707 .ndo_fdb_del = dsa_slave_fdb_del,
708 .ndo_fdb_dump = dsa_slave_fdb_dump,
Stephen Hemmingerd442ad42009-01-06 16:45:26 -0800709 .ndo_do_ioctl = dsa_slave_ioctl,
Nicolas Dichtelabd2be02015-04-02 17:07:08 +0200710 .ndo_get_iflink = dsa_slave_get_iflink,
Scott Feldman98237d42015-03-15 21:07:15 -0700711};
712
Jiri Pirko9d47c0a2015-05-10 09:47:47 -0700713static const struct switchdev_ops dsa_slave_switchdev_ops = {
Scott Feldmanf8e20a92015-05-10 09:47:49 -0700714 .switchdev_port_attr_get = dsa_slave_port_attr_get,
Scott Feldman35636062015-05-10 09:47:51 -0700715 .switchdev_port_attr_set = dsa_slave_port_attr_set,
Stephen Hemmingerd442ad42009-01-06 16:45:26 -0800716};
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000717
Florian Fainelli0d8bcdd2014-08-27 17:04:51 -0700718static void dsa_slave_adjust_link(struct net_device *dev)
719{
720 struct dsa_slave_priv *p = netdev_priv(dev);
Florian Fainelliec9436b2014-08-27 17:04:53 -0700721 struct dsa_switch *ds = p->parent;
Florian Fainelli0d8bcdd2014-08-27 17:04:51 -0700722 unsigned int status_changed = 0;
723
724 if (p->old_link != p->phy->link) {
725 status_changed = 1;
726 p->old_link = p->phy->link;
727 }
728
729 if (p->old_duplex != p->phy->duplex) {
730 status_changed = 1;
731 p->old_duplex = p->phy->duplex;
732 }
733
734 if (p->old_pause != p->phy->pause) {
735 status_changed = 1;
736 p->old_pause = p->phy->pause;
737 }
738
Florian Fainelliec9436b2014-08-27 17:04:53 -0700739 if (ds->drv->adjust_link && status_changed)
740 ds->drv->adjust_link(ds, p->port, p->phy);
741
Florian Fainelli0d8bcdd2014-08-27 17:04:51 -0700742 if (status_changed)
743 phy_print_status(p->phy);
744}
745
Florian Fainellice31b312014-08-27 17:04:54 -0700746static int dsa_slave_fixed_link_update(struct net_device *dev,
747 struct fixed_phy_status *status)
748{
749 struct dsa_slave_priv *p = netdev_priv(dev);
750 struct dsa_switch *ds = p->parent;
751
752 if (ds->drv->fixed_link_update)
753 ds->drv->fixed_link_update(ds, p->port, status);
754
755 return 0;
756}
757
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000758/* slave device setup *******************************************************/
Florian Fainellic305c162015-03-10 16:57:12 -0700759static int dsa_slave_phy_connect(struct dsa_slave_priv *p,
Florian Fainellicd28a1a2015-03-10 16:57:13 -0700760 struct net_device *slave_dev,
761 int addr)
Florian Fainellic305c162015-03-10 16:57:12 -0700762{
763 struct dsa_switch *ds = p->parent;
764
Florian Fainellicd28a1a2015-03-10 16:57:13 -0700765 p->phy = ds->slave_mii_bus->phy_map[addr];
Florian Fainellic305c162015-03-10 16:57:12 -0700766 if (!p->phy)
767 return -ENODEV;
768
769 /* Use already configured phy mode */
770 p->phy_interface = p->phy->interface;
771 phy_connect_direct(slave_dev, p->phy, dsa_slave_adjust_link,
772 p->phy_interface);
773
774 return 0;
775}
776
Florian Fainelli9697f1c2014-12-11 12:49:16 -0800777static int dsa_slave_phy_setup(struct dsa_slave_priv *p,
Florian Fainelli0d8bcdd2014-08-27 17:04:51 -0700778 struct net_device *slave_dev)
779{
780 struct dsa_switch *ds = p->parent;
781 struct dsa_chip_data *cd = ds->pd;
782 struct device_node *phy_dn, *port_dn;
Florian Fainellice31b312014-08-27 17:04:54 -0700783 bool phy_is_fixed = false;
Florian Fainelli68195632014-09-19 13:07:54 -0700784 u32 phy_flags = 0;
Guenter Roeck19334922015-02-16 21:23:51 -0800785 int mode, ret;
Florian Fainelli0d8bcdd2014-08-27 17:04:51 -0700786
787 port_dn = cd->port_dn[p->port];
Guenter Roeck19334922015-02-16 21:23:51 -0800788 mode = of_get_phy_mode(port_dn);
789 if (mode < 0)
790 mode = PHY_INTERFACE_MODE_NA;
791 p->phy_interface = mode;
Florian Fainelli0d8bcdd2014-08-27 17:04:51 -0700792
793 phy_dn = of_parse_phandle(port_dn, "phy-handle", 0);
794 if (of_phy_is_fixed_link(port_dn)) {
795 /* In the case of a fixed PHY, the DT node associated
796 * to the fixed PHY is the Port DT node
797 */
798 ret = of_phy_register_fixed_link(port_dn);
799 if (ret) {
Joe Perchesa2ae6002014-11-09 16:32:46 -0800800 netdev_err(slave_dev, "failed to register fixed PHY\n");
Florian Fainelli9697f1c2014-12-11 12:49:16 -0800801 return ret;
Florian Fainelli0d8bcdd2014-08-27 17:04:51 -0700802 }
Florian Fainellice31b312014-08-27 17:04:54 -0700803 phy_is_fixed = true;
Florian Fainelli0d8bcdd2014-08-27 17:04:51 -0700804 phy_dn = port_dn;
805 }
806
Florian Fainelli68195632014-09-19 13:07:54 -0700807 if (ds->drv->get_phy_flags)
808 phy_flags = ds->drv->get_phy_flags(ds, p->port);
809
Florian Fainellicd28a1a2015-03-10 16:57:13 -0700810 if (phy_dn) {
811 ret = of_mdio_parse_addr(&slave_dev->dev, phy_dn);
812 /* If this PHY address is part of phys_mii_mask, which means
813 * that we need to divert reads and writes to/from it, then we
814 * want to bind this device using the slave MII bus created by
815 * DSA to make that happen.
816 */
Florian Fainelli96026d02015-03-14 13:21:59 -0700817 if (!phy_is_fixed && ret >= 0 &&
818 (ds->phys_mii_mask & (1 << ret))) {
Florian Fainellicd28a1a2015-03-10 16:57:13 -0700819 ret = dsa_slave_phy_connect(p, slave_dev, ret);
820 if (ret)
821 return ret;
822 } else {
823 p->phy = of_phy_connect(slave_dev, phy_dn,
824 dsa_slave_adjust_link,
825 phy_flags,
826 p->phy_interface);
827 }
828 }
Florian Fainelli0d8bcdd2014-08-27 17:04:51 -0700829
Florian Fainellice31b312014-08-27 17:04:54 -0700830 if (p->phy && phy_is_fixed)
831 fixed_phy_set_link_update(p->phy, dsa_slave_fixed_link_update);
832
Florian Fainelli0d8bcdd2014-08-27 17:04:51 -0700833 /* We could not connect to a designated PHY, so use the switch internal
834 * MDIO bus instead
835 */
Andrew Lunnb31f65f2014-11-05 19:47:28 +0100836 if (!p->phy) {
Florian Fainellicd28a1a2015-03-10 16:57:13 -0700837 ret = dsa_slave_phy_connect(p, slave_dev, p->port);
Florian Fainellic305c162015-03-10 16:57:12 -0700838 if (ret)
839 return ret;
Andrew Lunnb31f65f2014-11-05 19:47:28 +0100840 } else {
Joe Perchesa2ae6002014-11-09 16:32:46 -0800841 netdev_info(slave_dev, "attached PHY at address %d [%s]\n",
842 p->phy->addr, p->phy->drv->name);
Andrew Lunnb31f65f2014-11-05 19:47:28 +0100843 }
Florian Fainelli9697f1c2014-12-11 12:49:16 -0800844
845 return 0;
Florian Fainelli0d8bcdd2014-08-27 17:04:51 -0700846}
847
Andrew Lunn448b4482015-05-06 01:09:56 +0200848static struct lock_class_key dsa_slave_netdev_xmit_lock_key;
849static void dsa_slave_set_lockdep_class_one(struct net_device *dev,
850 struct netdev_queue *txq,
851 void *_unused)
852{
853 lockdep_set_class(&txq->_xmit_lock,
854 &dsa_slave_netdev_xmit_lock_key);
855}
856
Florian Fainelli24462542014-09-18 17:31:22 -0700857int dsa_slave_suspend(struct net_device *slave_dev)
858{
859 struct dsa_slave_priv *p = netdev_priv(slave_dev);
860
Florian Fainelli24462542014-09-18 17:31:22 -0700861 if (p->phy) {
862 phy_stop(p->phy);
863 p->old_pause = -1;
864 p->old_link = -1;
865 p->old_duplex = -1;
866 phy_suspend(p->phy);
867 }
868
869 return 0;
870}
871
872int dsa_slave_resume(struct net_device *slave_dev)
873{
874 struct dsa_slave_priv *p = netdev_priv(slave_dev);
875
876 netif_device_attach(slave_dev);
877
878 if (p->phy) {
879 phy_resume(p->phy);
880 phy_start(p->phy);
881 }
882
883 return 0;
884}
885
Guenter Roeckd87d6f42015-02-24 13:15:32 -0800886int dsa_slave_create(struct dsa_switch *ds, struct device *parent,
887 int port, char *name)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000888{
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000889 struct net_device *master = ds->dst->master_netdev;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000890 struct net_device *slave_dev;
891 struct dsa_slave_priv *p;
892 int ret;
893
Tom Gundersenc835a672014-07-14 16:37:24 +0200894 slave_dev = alloc_netdev(sizeof(struct dsa_slave_priv), name,
895 NET_NAME_UNKNOWN, ether_setup);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000896 if (slave_dev == NULL)
Guenter Roeckd87d6f42015-02-24 13:15:32 -0800897 return -ENOMEM;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000898
899 slave_dev->features = master->vlan_features;
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +0000900 slave_dev->ethtool_ops = &dsa_slave_ethtool_ops;
Bjørn Mork2fcc8002013-08-30 18:08:46 +0200901 eth_hw_addr_inherit(slave_dev, master);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000902 slave_dev->tx_queue_len = 0;
Florian Fainelli3e8a72d2014-08-27 17:04:46 -0700903 slave_dev->netdev_ops = &dsa_slave_netdev_ops;
Jiri Pirko9d47c0a2015-05-10 09:47:47 -0700904 slave_dev->switchdev_ops = &dsa_slave_switchdev_ops;
Stephen Hemmingerd442ad42009-01-06 16:45:26 -0800905
Andrew Lunn448b4482015-05-06 01:09:56 +0200906 netdev_for_each_tx_queue(slave_dev, dsa_slave_set_lockdep_class_one,
907 NULL);
908
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000909 SET_NETDEV_DEV(slave_dev, parent);
Florian Fainellibd474972014-08-27 17:04:50 -0700910 slave_dev->dev.of_node = ds->pd->port_dn[port];
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000911 slave_dev->vlan_features = master->vlan_features;
912
913 p = netdev_priv(slave_dev);
914 p->dev = slave_dev;
915 p->parent = ds;
916 p->port = port;
Florian Fainelli0d8bcdd2014-08-27 17:04:51 -0700917
Alexander Duyck50753142014-09-15 13:00:19 -0400918 switch (ds->dst->tag_protocol) {
919#ifdef CONFIG_NET_DSA_TAG_DSA
920 case DSA_TAG_PROTO_DSA:
921 p->xmit = dsa_netdev_ops.xmit;
922 break;
923#endif
924#ifdef CONFIG_NET_DSA_TAG_EDSA
925 case DSA_TAG_PROTO_EDSA:
926 p->xmit = edsa_netdev_ops.xmit;
927 break;
928#endif
929#ifdef CONFIG_NET_DSA_TAG_TRAILER
930 case DSA_TAG_PROTO_TRAILER:
931 p->xmit = trailer_netdev_ops.xmit;
932 break;
933#endif
934#ifdef CONFIG_NET_DSA_TAG_BRCM
935 case DSA_TAG_PROTO_BRCM:
936 p->xmit = brcm_netdev_ops.xmit;
937 break;
938#endif
939 default:
940 p->xmit = dsa_slave_notag_xmit;
941 break;
942 }
943
Florian Fainelli0d8bcdd2014-08-27 17:04:51 -0700944 p->old_pause = -1;
945 p->old_link = -1;
946 p->old_duplex = -1;
947
Florian Fainelli9697f1c2014-12-11 12:49:16 -0800948 ret = dsa_slave_phy_setup(p, slave_dev);
949 if (ret) {
950 free_netdev(slave_dev);
Guenter Roeckd87d6f42015-02-24 13:15:32 -0800951 return ret;
Florian Fainelli9697f1c2014-12-11 12:49:16 -0800952 }
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000953
Guenter Roeckd87d6f42015-02-24 13:15:32 -0800954 ds->ports[port] = slave_dev;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000955 ret = register_netdev(slave_dev);
956 if (ret) {
Joe Perchesa2ae6002014-11-09 16:32:46 -0800957 netdev_err(master, "error %d registering interface %s\n",
958 ret, slave_dev->name);
Florian Fainelli9697f1c2014-12-11 12:49:16 -0800959 phy_disconnect(p->phy);
Guenter Roeckd87d6f42015-02-24 13:15:32 -0800960 ds->ports[port] = NULL;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000961 free_netdev(slave_dev);
Guenter Roeckd87d6f42015-02-24 13:15:32 -0800962 return ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000963 }
964
965 netif_carrier_off(slave_dev);
966
Guenter Roeckd87d6f42015-02-24 13:15:32 -0800967 return 0;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000968}
Florian Fainellib73adef2015-02-24 13:15:33 -0800969
970static bool dsa_slave_dev_check(struct net_device *dev)
971{
972 return dev->netdev_ops == &dsa_slave_netdev_ops;
973}
974
975static int dsa_slave_master_changed(struct net_device *dev)
976{
977 struct net_device *master = netdev_master_upper_dev_get(dev);
Guenter Roeckb06b1072015-03-25 08:08:37 -0700978 struct dsa_slave_priv *p = netdev_priv(dev);
Florian Fainellib73adef2015-02-24 13:15:33 -0800979 int err = 0;
980
981 if (master && master->rtnl_link_ops &&
982 !strcmp(master->rtnl_link_ops->kind, "bridge"))
983 err = dsa_slave_bridge_port_join(dev, master);
Guenter Roeckb06b1072015-03-25 08:08:37 -0700984 else if (dsa_port_is_bridged(p))
Florian Fainellib73adef2015-02-24 13:15:33 -0800985 err = dsa_slave_bridge_port_leave(dev);
986
987 return err;
988}
989
990int dsa_slave_netdevice_event(struct notifier_block *unused,
991 unsigned long event, void *ptr)
992{
993 struct net_device *dev;
994 int err = 0;
995
996 switch (event) {
997 case NETDEV_CHANGEUPPER:
998 dev = netdev_notifier_info_to_dev(ptr);
999 if (!dsa_slave_dev_check(dev))
1000 goto out;
1001
1002 err = dsa_slave_master_changed(dev);
1003 if (err)
1004 netdev_warn(dev, "failed to reflect master change\n");
1005
1006 break;
1007 }
1008
1009out:
1010 return NOTIFY_DONE;
1011}