blob: f7f5d126a7048dc04caf7d1b4ed8c638266dd9e1 [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 Fainelliaab9c402018-05-10 13:17:36 -070016#include <linux/phylink.h>
Florian Fainelli0d8bcdd2014-08-27 17:04:51 -070017#include <linux/of_net.h>
18#include <linux/of_mdio.h>
Andrew Lunn7f854422016-01-06 20:11:18 +010019#include <linux/mdio.h>
Florian Fainellib73adef2015-02-24 13:15:33 -080020#include <net/rtnetlink.h>
Florian Fainellif50f2122017-01-30 12:41:40 -080021#include <net/pkt_cls.h>
22#include <net/tc_act/tc_mirred.h>
Florian Fainellib73adef2015-02-24 13:15:33 -080023#include <linux/if_bridge.h>
Florian Fainelli04ff53f2015-07-31 11:42:57 -070024#include <linux/netpoll.h>
Brandon Streiff90af1052018-02-14 01:07:49 +010025#include <linux/ptp_classify.h>
Vivien Didelotea5dd342017-05-17 15:46:03 -040026
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000027#include "dsa_priv.h"
28
Florian Fainellif50f2122017-01-30 12:41:40 -080029static bool dsa_slave_dev_check(struct net_device *dev);
30
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000031/* slave mii_bus handling ***************************************************/
32static int dsa_slave_phy_read(struct mii_bus *bus, int addr, int reg)
33{
34 struct dsa_switch *ds = bus->priv;
35
Florian Fainelli0d8bcdd2014-08-27 17:04:51 -070036 if (ds->phys_mii_mask & (1 << addr))
Vivien Didelot9d490b42016-08-23 12:38:56 -040037 return ds->ops->phy_read(ds, addr, reg);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000038
39 return 0xffff;
40}
41
42static int dsa_slave_phy_write(struct mii_bus *bus, int addr, int reg, u16 val)
43{
44 struct dsa_switch *ds = bus->priv;
45
Florian Fainelli0d8bcdd2014-08-27 17:04:51 -070046 if (ds->phys_mii_mask & (1 << addr))
Vivien Didelot9d490b42016-08-23 12:38:56 -040047 return ds->ops->phy_write(ds, addr, reg, val);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000048
49 return 0;
50}
51
52void dsa_slave_mii_bus_init(struct dsa_switch *ds)
53{
54 ds->slave_mii_bus->priv = (void *)ds;
55 ds->slave_mii_bus->name = "dsa slave smi";
56 ds->slave_mii_bus->read = dsa_slave_phy_read;
57 ds->slave_mii_bus->write = dsa_slave_phy_write;
Florian Fainelli0b7b4982016-06-07 16:32:38 -070058 snprintf(ds->slave_mii_bus->id, MII_BUS_ID_SIZE, "dsa-%d.%d",
Vivien Didelot49463b72017-11-03 19:05:21 -040059 ds->dst->index, ds->index);
Andrew Lunnc33063d2016-05-10 23:27:23 +020060 ds->slave_mii_bus->parent = ds->dev;
Vivien Didelot24df8982015-01-20 19:13:32 -050061 ds->slave_mii_bus->phy_mask = ~ds->phys_mii_mask;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000062}
63
64
65/* slave device handling ****************************************************/
Nicolas Dichtelabd2be02015-04-02 17:07:08 +020066static int dsa_slave_get_iflink(const struct net_device *dev)
Lennert Buytenhekc0840802009-03-20 09:49:49 +000067{
Vivien Didelotd0006b02017-10-16 11:12:16 -040068 return dsa_slave_to_master(dev)->ifindex;
Lennert Buytenhekc0840802009-03-20 09:49:49 +000069}
70
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000071static int dsa_slave_open(struct net_device *dev)
72{
Vivien Didelotd0006b02017-10-16 11:12:16 -040073 struct net_device *master = dsa_slave_to_master(dev);
Vivien Didelotd9450972017-10-16 11:12:15 -040074 struct dsa_port *dp = dsa_slave_to_port(dev);
Lennert Buytenhekdf02c6f2008-11-10 21:53:12 -080075 int err;
76
77 if (!(master->flags & IFF_UP))
78 return -ENETDOWN;
79
Joe Perches8feedbb2012-05-08 18:56:57 +000080 if (!ether_addr_equal(dev->dev_addr, master->dev_addr)) {
Jiri Pirkoa748ee22010-04-01 21:22:09 +000081 err = dev_uc_add(master, dev->dev_addr);
Lennert Buytenhekdf02c6f2008-11-10 21:53:12 -080082 if (err < 0)
83 goto out;
84 }
85
86 if (dev->flags & IFF_ALLMULTI) {
87 err = dev_set_allmulti(master, 1);
88 if (err < 0)
89 goto del_unicast;
90 }
91 if (dev->flags & IFF_PROMISC) {
92 err = dev_set_promiscuity(master, 1);
93 if (err < 0)
94 goto clear_allmulti;
95 }
96
Vivien Didelot0115dcd2017-09-26 17:15:32 -040097 err = dsa_port_enable(dp, dev->phydev);
Vivien Didelotfb8a6a22017-09-22 19:01:56 -040098 if (err)
99 goto clear_promisc;
Florian Fainellib73adef2015-02-24 13:15:33 -0800100
Florian Fainelliaab9c402018-05-10 13:17:36 -0700101 phylink_start(dp->pl);
Florian Fainellif7f1de52014-09-24 17:05:17 -0700102
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000103 return 0;
Lennert Buytenhekdf02c6f2008-11-10 21:53:12 -0800104
Florian Fainellib2f2af22014-09-24 17:05:18 -0700105clear_promisc:
106 if (dev->flags & IFF_PROMISC)
Gilad Ben-Yossef4fdeddf2015-06-25 16:50:13 +0300107 dev_set_promiscuity(master, -1);
Lennert Buytenhekdf02c6f2008-11-10 21:53:12 -0800108clear_allmulti:
109 if (dev->flags & IFF_ALLMULTI)
110 dev_set_allmulti(master, -1);
111del_unicast:
Joe Perches8feedbb2012-05-08 18:56:57 +0000112 if (!ether_addr_equal(dev->dev_addr, master->dev_addr))
Jiri Pirkoa748ee22010-04-01 21:22:09 +0000113 dev_uc_del(master, dev->dev_addr);
Lennert Buytenhekdf02c6f2008-11-10 21:53:12 -0800114out:
115 return err;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000116}
117
118static int dsa_slave_close(struct net_device *dev)
119{
Vivien Didelotd0006b02017-10-16 11:12:16 -0400120 struct net_device *master = dsa_slave_to_master(dev);
Vivien Didelotd9450972017-10-16 11:12:15 -0400121 struct dsa_port *dp = dsa_slave_to_port(dev);
Lennert Buytenhekdf02c6f2008-11-10 21:53:12 -0800122
Florian Fainelliaab9c402018-05-10 13:17:36 -0700123 phylink_stop(dp->pl);
Florian Fainellif7f1de52014-09-24 17:05:17 -0700124
Vivien Didelot0115dcd2017-09-26 17:15:32 -0400125 dsa_port_disable(dp, dev->phydev);
Vivien Didelot6457edf2017-09-22 19:01:55 -0400126
Lennert Buytenhekdf02c6f2008-11-10 21:53:12 -0800127 dev_mc_unsync(master, dev);
Jiri Pirkoa748ee22010-04-01 21:22:09 +0000128 dev_uc_unsync(master, dev);
Lennert Buytenhekdf02c6f2008-11-10 21:53:12 -0800129 if (dev->flags & IFF_ALLMULTI)
130 dev_set_allmulti(master, -1);
131 if (dev->flags & IFF_PROMISC)
132 dev_set_promiscuity(master, -1);
133
Joe Perches8feedbb2012-05-08 18:56:57 +0000134 if (!ether_addr_equal(dev->dev_addr, master->dev_addr))
Jiri Pirkoa748ee22010-04-01 21:22:09 +0000135 dev_uc_del(master, dev->dev_addr);
Lennert Buytenhekdf02c6f2008-11-10 21:53:12 -0800136
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000137 return 0;
138}
139
140static void dsa_slave_change_rx_flags(struct net_device *dev, int change)
141{
Vivien Didelotd0006b02017-10-16 11:12:16 -0400142 struct net_device *master = dsa_slave_to_master(dev);
Rundong Ge17ab4f62019-02-02 14:29:35 +0000143 if (dev->flags & IFF_UP) {
144 if (change & IFF_ALLMULTI)
145 dev_set_allmulti(master,
146 dev->flags & IFF_ALLMULTI ? 1 : -1);
147 if (change & IFF_PROMISC)
148 dev_set_promiscuity(master,
149 dev->flags & IFF_PROMISC ? 1 : -1);
150 }
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000151}
152
153static void dsa_slave_set_rx_mode(struct net_device *dev)
154{
Vivien Didelotd0006b02017-10-16 11:12:16 -0400155 struct net_device *master = dsa_slave_to_master(dev);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000156
157 dev_mc_sync(master, dev);
Jiri Pirkoa748ee22010-04-01 21:22:09 +0000158 dev_uc_sync(master, dev);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000159}
160
Lennert Buytenhekdf02c6f2008-11-10 21:53:12 -0800161static int dsa_slave_set_mac_address(struct net_device *dev, void *a)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000162{
Vivien Didelotd0006b02017-10-16 11:12:16 -0400163 struct net_device *master = dsa_slave_to_master(dev);
Lennert Buytenhekdf02c6f2008-11-10 21:53:12 -0800164 struct sockaddr *addr = a;
165 int err;
166
167 if (!is_valid_ether_addr(addr->sa_data))
168 return -EADDRNOTAVAIL;
169
170 if (!(dev->flags & IFF_UP))
171 goto out;
172
Joe Perches8feedbb2012-05-08 18:56:57 +0000173 if (!ether_addr_equal(addr->sa_data, master->dev_addr)) {
Jiri Pirkoa748ee22010-04-01 21:22:09 +0000174 err = dev_uc_add(master, addr->sa_data);
Lennert Buytenhekdf02c6f2008-11-10 21:53:12 -0800175 if (err < 0)
176 return err;
177 }
178
Joe Perches8feedbb2012-05-08 18:56:57 +0000179 if (!ether_addr_equal(dev->dev_addr, master->dev_addr))
Jiri Pirkoa748ee22010-04-01 21:22:09 +0000180 dev_uc_del(master, dev->dev_addr);
Lennert Buytenhekdf02c6f2008-11-10 21:53:12 -0800181
182out:
Joe Perchesd08f1612014-01-20 09:52:20 -0800183 ether_addr_copy(dev->dev_addr, addr->sa_data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000184
185 return 0;
186}
187
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +0300188struct dsa_slave_dump_ctx {
189 struct net_device *dev;
190 struct sk_buff *skb;
191 struct netlink_callback *cb;
192 int idx;
193};
194
195static int
196dsa_slave_port_fdb_do_dump(const unsigned char *addr, u16 vid,
197 bool is_static, void *data)
198{
199 struct dsa_slave_dump_ctx *dump = data;
200 u32 portid = NETLINK_CB(dump->cb->skb).portid;
201 u32 seq = dump->cb->nlh->nlmsg_seq;
202 struct nlmsghdr *nlh;
203 struct ndmsg *ndm;
204
205 if (dump->idx < dump->cb->args[2])
206 goto skip;
207
208 nlh = nlmsg_put(dump->skb, portid, seq, RTM_NEWNEIGH,
209 sizeof(*ndm), NLM_F_MULTI);
210 if (!nlh)
211 return -EMSGSIZE;
212
213 ndm = nlmsg_data(nlh);
214 ndm->ndm_family = AF_BRIDGE;
215 ndm->ndm_pad1 = 0;
216 ndm->ndm_pad2 = 0;
217 ndm->ndm_flags = NTF_SELF;
218 ndm->ndm_type = 0;
219 ndm->ndm_ifindex = dump->dev->ifindex;
220 ndm->ndm_state = is_static ? NUD_NOARP : NUD_REACHABLE;
221
222 if (nla_put(dump->skb, NDA_LLADDR, ETH_ALEN, addr))
223 goto nla_put_failure;
224
225 if (vid && nla_put_u16(dump->skb, NDA_VLAN, vid))
226 goto nla_put_failure;
227
228 nlmsg_end(dump->skb, nlh);
229
230skip:
231 dump->idx++;
232 return 0;
233
234nla_put_failure:
235 nlmsg_cancel(dump->skb, nlh);
236 return -EMSGSIZE;
237}
238
239static int
240dsa_slave_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
241 struct net_device *dev, struct net_device *filter_dev,
242 int *idx)
243{
Vivien Didelotd9450972017-10-16 11:12:15 -0400244 struct dsa_port *dp = dsa_slave_to_port(dev);
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +0300245 struct dsa_slave_dump_ctx dump = {
246 .dev = dev,
247 .skb = skb,
248 .cb = cb,
249 .idx = *idx,
250 };
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +0300251 int err;
252
Vivien Didelotde40fc52017-09-20 19:32:14 -0400253 err = dsa_port_fdb_dump(dp, dsa_slave_port_fdb_do_dump, &dump);
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +0300254 *idx = dump.idx;
Vivien Didelotde40fc52017-09-20 19:32:14 -0400255
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +0300256 return err;
257}
258
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000259static int dsa_slave_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
260{
Brandon Streiff03363692018-02-14 01:07:48 +0100261 struct dsa_slave_priv *p = netdev_priv(dev);
262 struct dsa_switch *ds = p->dp->ds;
263 int port = p->dp->index;
264
265 /* Pass through to switch driver if it supports timestamping */
266 switch (cmd) {
267 case SIOCGHWTSTAMP:
268 if (ds->ops->port_hwtstamp_get)
269 return ds->ops->port_hwtstamp_get(ds, port, ifr);
270 break;
271 case SIOCSHWTSTAMP:
272 if (ds->ops->port_hwtstamp_set)
273 return ds->ops->port_hwtstamp_set(ds, port, ifr);
274 break;
275 }
276
Florian Fainelliaab9c402018-05-10 13:17:36 -0700277 return phylink_mii_ioctl(p->dp->pl, ifr, cmd);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000278}
279
Scott Feldman35636062015-05-10 09:47:51 -0700280static int dsa_slave_port_attr_set(struct net_device *dev,
Jiri Pirkof7fadf32015-10-14 19:40:49 +0200281 const struct switchdev_attr *attr,
Jiri Pirko7ea6eb32015-09-24 10:02:41 +0200282 struct switchdev_trans *trans)
Scott Feldman35636062015-05-10 09:47:51 -0700283{
Vivien Didelotd9450972017-10-16 11:12:15 -0400284 struct dsa_port *dp = dsa_slave_to_port(dev);
Vivien Didelotb8d866a2015-09-29 12:38:36 -0400285 int ret;
Scott Feldman35636062015-05-10 09:47:51 -0700286
287 switch (attr->id) {
Jiri Pirko1f868392015-10-01 11:03:42 +0200288 case SWITCHDEV_ATTR_ID_PORT_STP_STATE:
Vivien Didelotfd364542017-05-19 17:00:36 -0400289 ret = dsa_port_set_state(dp, attr->u.stp_state, trans);
Scott Feldman35636062015-05-10 09:47:51 -0700290 break;
Vivien Didelotfb2daba2016-02-26 13:16:00 -0500291 case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING:
Vivien Didelotc02c4172017-05-19 17:00:42 -0400292 ret = dsa_port_vlan_filtering(dp, attr->u.vlan_filtering,
293 trans);
Vivien Didelotfb2daba2016-02-26 13:16:00 -0500294 break;
Vivien Didelot34a79f62016-07-18 20:45:38 -0400295 case SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME:
Vivien Didelot072bb192017-05-19 17:00:43 -0400296 ret = dsa_port_ageing_time(dp, attr->u.ageing_time, trans);
Vivien Didelot34a79f62016-07-18 20:45:38 -0400297 break;
Florian Fainelliea870052019-02-20 16:58:22 -0800298 case SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS:
299 ret = dsa_port_pre_bridge_flags(dp, attr->u.brport_flags,
300 trans);
301 break;
Russell King57652792019-02-20 15:35:04 -0800302 case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS:
303 ret = dsa_port_bridge_flags(dp, attr->u.brport_flags, trans);
304 break;
Scott Feldman35636062015-05-10 09:47:51 -0700305 default:
306 ret = -EOPNOTSUPP;
307 break;
308 }
309
310 return ret;
311}
312
Vivien Didelotba14d9e2015-08-10 09:09:53 -0400313static int dsa_slave_port_obj_add(struct net_device *dev,
Jiri Pirko648b4a92015-10-01 11:03:45 +0200314 const struct switchdev_obj *obj,
Jiri Pirko7ea6eb32015-09-24 10:02:41 +0200315 struct switchdev_trans *trans)
Vivien Didelotba14d9e2015-08-10 09:09:53 -0400316{
Vivien Didelotd9450972017-10-16 11:12:15 -0400317 struct dsa_port *dp = dsa_slave_to_port(dev);
Vivien Didelotba14d9e2015-08-10 09:09:53 -0400318 int err;
319
320 /* For the prepare phase, ensure the full set of changes is feasable in
321 * one go in order to signal a failure properly. If an operation is not
322 * supported, return -EOPNOTSUPP.
323 */
324
Jiri Pirko9e8f4a52015-10-01 11:03:46 +0200325 switch (obj->id) {
Vivien Didelot8df30252016-08-31 11:50:03 -0400326 case SWITCHDEV_OBJ_ID_PORT_MDB:
Vivien Didelotbcebb972017-05-19 17:00:40 -0400327 err = dsa_port_mdb_add(dp, SWITCHDEV_OBJ_PORT_MDB(obj), trans);
Vivien Didelot8df30252016-08-31 11:50:03 -0400328 break;
Andrew Lunn5f4dbc52017-11-09 23:11:00 +0100329 case SWITCHDEV_OBJ_ID_HOST_MDB:
330 /* DSA can directly translate this to a normal MDB add,
331 * but on the CPU port.
332 */
333 err = dsa_port_mdb_add(dp->cpu_dp, SWITCHDEV_OBJ_PORT_MDB(obj),
334 trans);
335 break;
Jiri Pirko57d80832015-10-01 11:03:41 +0200336 case SWITCHDEV_OBJ_ID_PORT_VLAN:
Vivien Didelot01676d122017-05-19 17:00:41 -0400337 err = dsa_port_vlan_add(dp, SWITCHDEV_OBJ_PORT_VLAN(obj),
338 trans);
Vivien Didelot11149532015-08-13 12:52:17 -0400339 break;
Vivien Didelotba14d9e2015-08-10 09:09:53 -0400340 default:
341 err = -EOPNOTSUPP;
342 break;
343 }
344
345 return err;
346}
347
348static int dsa_slave_port_obj_del(struct net_device *dev,
Jiri Pirko648b4a92015-10-01 11:03:45 +0200349 const struct switchdev_obj *obj)
Vivien Didelotba14d9e2015-08-10 09:09:53 -0400350{
Vivien Didelotd9450972017-10-16 11:12:15 -0400351 struct dsa_port *dp = dsa_slave_to_port(dev);
Vivien Didelotba14d9e2015-08-10 09:09:53 -0400352 int err;
353
Jiri Pirko9e8f4a52015-10-01 11:03:46 +0200354 switch (obj->id) {
Vivien Didelot8df30252016-08-31 11:50:03 -0400355 case SWITCHDEV_OBJ_ID_PORT_MDB:
Vivien Didelotbcebb972017-05-19 17:00:40 -0400356 err = dsa_port_mdb_del(dp, SWITCHDEV_OBJ_PORT_MDB(obj));
Vivien Didelot8df30252016-08-31 11:50:03 -0400357 break;
Andrew Lunn5f4dbc52017-11-09 23:11:00 +0100358 case SWITCHDEV_OBJ_ID_HOST_MDB:
359 /* DSA can directly translate this to a normal MDB add,
360 * but on the CPU port.
361 */
362 err = dsa_port_mdb_del(dp->cpu_dp, SWITCHDEV_OBJ_PORT_MDB(obj));
363 break;
Jiri Pirko57d80832015-10-01 11:03:41 +0200364 case SWITCHDEV_OBJ_ID_PORT_VLAN:
Vivien Didelot01676d122017-05-19 17:00:41 -0400365 err = dsa_port_vlan_del(dp, SWITCHDEV_OBJ_PORT_VLAN(obj));
Vivien Didelot11149532015-08-13 12:52:17 -0400366 break;
Vivien Didelotba14d9e2015-08-10 09:09:53 -0400367 default:
368 err = -EOPNOTSUPP;
369 break;
370 }
371
372 return err;
373}
374
Florian Fainelli929d6c12019-02-06 09:45:45 -0800375static int dsa_slave_get_port_parent_id(struct net_device *dev,
376 struct netdev_phys_item_id *ppid)
Florian Fainellib73adef2015-02-24 13:15:33 -0800377{
Vivien Didelotd9450972017-10-16 11:12:15 -0400378 struct dsa_port *dp = dsa_slave_to_port(dev);
379 struct dsa_switch *ds = dp->ds;
Andrew Lunna42c8e32017-11-09 22:29:51 +0100380 struct dsa_switch_tree *dst = ds->dst;
Florian Fainellib73adef2015-02-24 13:15:33 -0800381
Florian Fainelli929d6c12019-02-06 09:45:45 -0800382 ppid->id_len = sizeof(dst->index);
383 memcpy(&ppid->id, &dst->index, ppid->id_len);
384
385 return 0;
386}
387
Vivien Didelot4fa7b712017-09-20 19:31:57 -0400388static inline netdev_tx_t dsa_slave_netpoll_send_skb(struct net_device *dev,
389 struct sk_buff *skb)
Florian Fainelli04ff53f2015-07-31 11:42:57 -0700390{
391#ifdef CONFIG_NET_POLL_CONTROLLER
Vivien Didelot4fa7b712017-09-20 19:31:57 -0400392 struct dsa_slave_priv *p = netdev_priv(dev);
393
Florian Fainelli04ff53f2015-07-31 11:42:57 -0700394 if (p->netpoll)
395 netpoll_send_skb(p->netpoll, skb);
396#else
397 BUG();
398#endif
399 return NETDEV_TX_OK;
400}
401
Brandon Streiff90af1052018-02-14 01:07:49 +0100402static void dsa_skb_tx_timestamp(struct dsa_slave_priv *p,
403 struct sk_buff *skb)
404{
405 struct dsa_switch *ds = p->dp->ds;
406 struct sk_buff *clone;
407 unsigned int type;
408
409 type = ptp_classify_raw(skb);
410 if (type == PTP_CLASS_NONE)
411 return;
412
413 if (!ds->ops->port_txtstamp)
414 return;
415
416 clone = skb_clone_sk(skb);
417 if (!clone)
418 return;
419
420 if (ds->ops->port_txtstamp(ds, p->dp->index, clone, type))
421 return;
422
423 kfree_skb(clone);
424}
425
Florian Fainelli3e8a72d2014-08-27 17:04:46 -0700426static netdev_tx_t dsa_slave_xmit(struct sk_buff *skb, struct net_device *dev)
427{
428 struct dsa_slave_priv *p = netdev_priv(dev);
Florian Fainelli5f6b4e142017-08-03 21:33:27 -0700429 struct pcpu_sw_netstats *s;
Florian Fainelli4ed70ce2015-07-31 11:42:56 -0700430 struct sk_buff *nskb;
Florian Fainelli3e8a72d2014-08-27 17:04:46 -0700431
Florian Fainelli5f6b4e142017-08-03 21:33:27 -0700432 s = this_cpu_ptr(p->stats64);
433 u64_stats_update_begin(&s->syncp);
434 s->tx_packets++;
435 s->tx_bytes += skb->len;
436 u64_stats_update_end(&s->syncp);
Florian Fainelli3e8a72d2014-08-27 17:04:46 -0700437
Brandon Streiff90af1052018-02-14 01:07:49 +0100438 /* Identify PTP protocol packets, clone them, and pass them to the
439 * switch driver
440 */
441 dsa_skb_tx_timestamp(p, skb);
442
Vivien Didelotfe47d562017-06-01 16:07:15 -0400443 /* Transmit function may have to reallocate the original SKB,
444 * in which case it must have freed it. Only free it here on error.
445 */
Florian Fainelli4ed70ce2015-07-31 11:42:56 -0700446 nskb = p->xmit(skb, dev);
Vivien Didelotfe47d562017-06-01 16:07:15 -0400447 if (!nskb) {
448 kfree_skb(skb);
Florian Fainelli4ed70ce2015-07-31 11:42:56 -0700449 return NETDEV_TX_OK;
Vivien Didelotfe47d562017-06-01 16:07:15 -0400450 }
Florian Fainelli5aed85c2014-08-27 17:04:52 -0700451
Florian Fainelli04ff53f2015-07-31 11:42:57 -0700452 /* SKB for netpoll still need to be mangled with the protocol-specific
453 * tag to be successfully transmitted
454 */
455 if (unlikely(netpoll_tx_running(dev)))
Vivien Didelot4fa7b712017-09-20 19:31:57 -0400456 return dsa_slave_netpoll_send_skb(dev, nskb);
Florian Fainelli04ff53f2015-07-31 11:42:57 -0700457
Florian Fainelli4ed70ce2015-07-31 11:42:56 -0700458 /* Queue the SKB for transmission on the parent interface, but
459 * do not modify its EtherType
460 */
Vivien Didelotd0006b02017-10-16 11:12:16 -0400461 nskb->dev = dsa_slave_to_master(dev);
Florian Fainelli4ed70ce2015-07-31 11:42:56 -0700462 dev_queue_xmit(nskb);
Florian Fainelli5aed85c2014-08-27 17:04:52 -0700463
464 return NETDEV_TX_OK;
465}
466
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000467/* ethtool operations *******************************************************/
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000468
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000469static void dsa_slave_get_drvinfo(struct net_device *dev,
470 struct ethtool_drvinfo *drvinfo)
471{
Jiri Pirko7826d432013-01-06 00:44:26 +0000472 strlcpy(drvinfo->driver, "dsa", sizeof(drvinfo->driver));
Jiri Pirko7826d432013-01-06 00:44:26 +0000473 strlcpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version));
474 strlcpy(drvinfo->bus_info, "platform", sizeof(drvinfo->bus_info));
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000475}
476
Guenter Roeck3d762a02014-10-29 10:45:04 -0700477static int dsa_slave_get_regs_len(struct net_device *dev)
478{
Vivien Didelotd9450972017-10-16 11:12:15 -0400479 struct dsa_port *dp = dsa_slave_to_port(dev);
480 struct dsa_switch *ds = dp->ds;
Guenter Roeck3d762a02014-10-29 10:45:04 -0700481
Vivien Didelot9d490b42016-08-23 12:38:56 -0400482 if (ds->ops->get_regs_len)
Vivien Didelotd9450972017-10-16 11:12:15 -0400483 return ds->ops->get_regs_len(ds, dp->index);
Guenter Roeck3d762a02014-10-29 10:45:04 -0700484
485 return -EOPNOTSUPP;
486}
487
488static void
489dsa_slave_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *_p)
490{
Vivien Didelotd9450972017-10-16 11:12:15 -0400491 struct dsa_port *dp = dsa_slave_to_port(dev);
492 struct dsa_switch *ds = dp->ds;
Guenter Roeck3d762a02014-10-29 10:45:04 -0700493
Vivien Didelot9d490b42016-08-23 12:38:56 -0400494 if (ds->ops->get_regs)
Vivien Didelotd9450972017-10-16 11:12:15 -0400495 ds->ops->get_regs(ds, dp->index, regs, _p);
Guenter Roeck3d762a02014-10-29 10:45:04 -0700496}
497
Florian Fainelliaab9c402018-05-10 13:17:36 -0700498static int dsa_slave_nway_reset(struct net_device *dev)
499{
500 struct dsa_port *dp = dsa_slave_to_port(dev);
501
502 return phylink_ethtool_nway_reset(dp->pl);
503}
504
Guenter Roeck6793abb2014-10-29 10:45:01 -0700505static int dsa_slave_get_eeprom_len(struct net_device *dev)
506{
Vivien Didelotd9450972017-10-16 11:12:15 -0400507 struct dsa_port *dp = dsa_slave_to_port(dev);
508 struct dsa_switch *ds = dp->ds;
Guenter Roeck6793abb2014-10-29 10:45:01 -0700509
Andrew Lunn0e576042016-06-04 21:16:52 +0200510 if (ds->cd && ds->cd->eeprom_len)
Andrew Lunnff049552016-05-10 23:27:24 +0200511 return ds->cd->eeprom_len;
Guenter Roeck6793abb2014-10-29 10:45:01 -0700512
Vivien Didelot9d490b42016-08-23 12:38:56 -0400513 if (ds->ops->get_eeprom_len)
514 return ds->ops->get_eeprom_len(ds);
Guenter Roeck6793abb2014-10-29 10:45:01 -0700515
516 return 0;
517}
518
519static int dsa_slave_get_eeprom(struct net_device *dev,
520 struct ethtool_eeprom *eeprom, u8 *data)
521{
Vivien Didelotd9450972017-10-16 11:12:15 -0400522 struct dsa_port *dp = dsa_slave_to_port(dev);
523 struct dsa_switch *ds = dp->ds;
Guenter Roeck6793abb2014-10-29 10:45:01 -0700524
Vivien Didelot9d490b42016-08-23 12:38:56 -0400525 if (ds->ops->get_eeprom)
526 return ds->ops->get_eeprom(ds, eeprom, data);
Guenter Roeck6793abb2014-10-29 10:45:01 -0700527
528 return -EOPNOTSUPP;
529}
530
531static int dsa_slave_set_eeprom(struct net_device *dev,
532 struct ethtool_eeprom *eeprom, u8 *data)
533{
Vivien Didelotd9450972017-10-16 11:12:15 -0400534 struct dsa_port *dp = dsa_slave_to_port(dev);
535 struct dsa_switch *ds = dp->ds;
Guenter Roeck6793abb2014-10-29 10:45:01 -0700536
Vivien Didelot9d490b42016-08-23 12:38:56 -0400537 if (ds->ops->set_eeprom)
538 return ds->ops->set_eeprom(ds, eeprom, data);
Guenter Roeck6793abb2014-10-29 10:45:01 -0700539
540 return -EOPNOTSUPP;
541}
542
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000543static void dsa_slave_get_strings(struct net_device *dev,
544 uint32_t stringset, uint8_t *data)
545{
Vivien Didelotd9450972017-10-16 11:12:15 -0400546 struct dsa_port *dp = dsa_slave_to_port(dev);
547 struct dsa_switch *ds = dp->ds;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000548
549 if (stringset == ETH_SS_STATS) {
550 int len = ETH_GSTRING_LEN;
551
552 strncpy(data, "tx_packets", len);
553 strncpy(data + len, "tx_bytes", len);
554 strncpy(data + 2 * len, "rx_packets", len);
555 strncpy(data + 3 * len, "rx_bytes", len);
Vivien Didelot9d490b42016-08-23 12:38:56 -0400556 if (ds->ops->get_strings)
Florian Fainelli89f09042018-04-25 12:12:50 -0700557 ds->ops->get_strings(ds, dp->index, stringset,
558 data + 4 * len);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000559 }
560}
561
562static void dsa_slave_get_ethtool_stats(struct net_device *dev,
563 struct ethtool_stats *stats,
564 uint64_t *data)
565{
Vivien Didelotd9450972017-10-16 11:12:15 -0400566 struct dsa_port *dp = dsa_slave_to_port(dev);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000567 struct dsa_slave_priv *p = netdev_priv(dev);
Vivien Didelotd9450972017-10-16 11:12:15 -0400568 struct dsa_switch *ds = dp->ds;
Florian Fainelli5f6b4e142017-08-03 21:33:27 -0700569 struct pcpu_sw_netstats *s;
Florian Fainellif613ed62017-08-01 15:00:36 -0700570 unsigned int start;
Florian Fainelli5f6b4e142017-08-03 21:33:27 -0700571 int i;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000572
Florian Fainelli5f6b4e142017-08-03 21:33:27 -0700573 for_each_possible_cpu(i) {
574 u64 tx_packets, tx_bytes, rx_packets, rx_bytes;
575
576 s = per_cpu_ptr(p->stats64, i);
577 do {
578 start = u64_stats_fetch_begin_irq(&s->syncp);
579 tx_packets = s->tx_packets;
580 tx_bytes = s->tx_bytes;
581 rx_packets = s->rx_packets;
582 rx_bytes = s->rx_bytes;
583 } while (u64_stats_fetch_retry_irq(&s->syncp, start));
584 data[0] += tx_packets;
585 data[1] += tx_bytes;
586 data[2] += rx_packets;
587 data[3] += rx_bytes;
588 }
Vivien Didelot9d490b42016-08-23 12:38:56 -0400589 if (ds->ops->get_ethtool_stats)
Vivien Didelotd9450972017-10-16 11:12:15 -0400590 ds->ops->get_ethtool_stats(ds, dp->index, data + 4);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000591}
592
593static int dsa_slave_get_sset_count(struct net_device *dev, int sset)
594{
Vivien Didelotd9450972017-10-16 11:12:15 -0400595 struct dsa_port *dp = dsa_slave_to_port(dev);
596 struct dsa_switch *ds = dp->ds;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000597
598 if (sset == ETH_SS_STATS) {
599 int count;
600
601 count = 4;
Vivien Didelot9d490b42016-08-23 12:38:56 -0400602 if (ds->ops->get_sset_count)
Florian Fainelli89f09042018-04-25 12:12:50 -0700603 count += ds->ops->get_sset_count(ds, dp->index, sset);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000604
605 return count;
606 }
607
608 return -EOPNOTSUPP;
609}
610
Florian Fainelli19e57c42014-09-18 17:31:24 -0700611static void dsa_slave_get_wol(struct net_device *dev, struct ethtool_wolinfo *w)
612{
Vivien Didelotd9450972017-10-16 11:12:15 -0400613 struct dsa_port *dp = dsa_slave_to_port(dev);
614 struct dsa_switch *ds = dp->ds;
Florian Fainelli19e57c42014-09-18 17:31:24 -0700615
Florian Fainelliaab9c402018-05-10 13:17:36 -0700616 phylink_ethtool_get_wol(dp->pl, w);
617
Vivien Didelot9d490b42016-08-23 12:38:56 -0400618 if (ds->ops->get_wol)
Vivien Didelotd9450972017-10-16 11:12:15 -0400619 ds->ops->get_wol(ds, dp->index, w);
Florian Fainelli19e57c42014-09-18 17:31:24 -0700620}
621
622static int dsa_slave_set_wol(struct net_device *dev, struct ethtool_wolinfo *w)
623{
Vivien Didelotd9450972017-10-16 11:12:15 -0400624 struct dsa_port *dp = dsa_slave_to_port(dev);
625 struct dsa_switch *ds = dp->ds;
Florian Fainelli19e57c42014-09-18 17:31:24 -0700626 int ret = -EOPNOTSUPP;
627
Florian Fainelliaab9c402018-05-10 13:17:36 -0700628 phylink_ethtool_set_wol(dp->pl, w);
629
Vivien Didelot9d490b42016-08-23 12:38:56 -0400630 if (ds->ops->set_wol)
Vivien Didelotd9450972017-10-16 11:12:15 -0400631 ret = ds->ops->set_wol(ds, dp->index, w);
Florian Fainelli19e57c42014-09-18 17:31:24 -0700632
633 return ret;
634}
635
Florian Fainelli79052882014-09-24 17:05:21 -0700636static int dsa_slave_set_eee(struct net_device *dev, struct ethtool_eee *e)
637{
Vivien Didelotd9450972017-10-16 11:12:15 -0400638 struct dsa_port *dp = dsa_slave_to_port(dev);
639 struct dsa_switch *ds = dp->ds;
Florian Fainelli79052882014-09-24 17:05:21 -0700640 int ret;
641
Vivien Didelot7b9cc732017-08-01 16:32:31 -0400642 /* Port's PHY and MAC both need to be EEE capable */
Dan Carpenter00670cb2019-02-06 18:35:15 +0300643 if (!dev->phydev || !dp->pl)
Vivien Didelot7b9cc732017-08-01 16:32:31 -0400644 return -ENODEV;
645
Vivien Didelot08f50062017-08-01 16:32:41 -0400646 if (!ds->ops->set_mac_eee)
Florian Fainelli79052882014-09-24 17:05:21 -0700647 return -EOPNOTSUPP;
648
Vivien Didelotd9450972017-10-16 11:12:15 -0400649 ret = ds->ops->set_mac_eee(ds, dp->index, e);
Florian Fainelli79052882014-09-24 17:05:21 -0700650 if (ret)
651 return ret;
652
Florian Fainelliaab9c402018-05-10 13:17:36 -0700653 return phylink_ethtool_set_eee(dp->pl, e);
Florian Fainelli79052882014-09-24 17:05:21 -0700654}
655
656static int dsa_slave_get_eee(struct net_device *dev, struct ethtool_eee *e)
657{
Vivien Didelotd9450972017-10-16 11:12:15 -0400658 struct dsa_port *dp = dsa_slave_to_port(dev);
659 struct dsa_switch *ds = dp->ds;
Florian Fainelli79052882014-09-24 17:05:21 -0700660 int ret;
661
Vivien Didelot7b9cc732017-08-01 16:32:31 -0400662 /* Port's PHY and MAC both need to be EEE capable */
Dan Carpenter00670cb2019-02-06 18:35:15 +0300663 if (!dev->phydev || !dp->pl)
Vivien Didelot7b9cc732017-08-01 16:32:31 -0400664 return -ENODEV;
665
Vivien Didelot08f50062017-08-01 16:32:41 -0400666 if (!ds->ops->get_mac_eee)
Florian Fainelli79052882014-09-24 17:05:21 -0700667 return -EOPNOTSUPP;
668
Vivien Didelotd9450972017-10-16 11:12:15 -0400669 ret = ds->ops->get_mac_eee(ds, dp->index, e);
Florian Fainelli79052882014-09-24 17:05:21 -0700670 if (ret)
671 return ret;
672
Florian Fainelliaab9c402018-05-10 13:17:36 -0700673 return phylink_ethtool_get_eee(dp->pl, e);
674}
675
676static int dsa_slave_get_link_ksettings(struct net_device *dev,
677 struct ethtool_link_ksettings *cmd)
678{
679 struct dsa_port *dp = dsa_slave_to_port(dev);
680
681 return phylink_ethtool_ksettings_get(dp->pl, cmd);
682}
683
684static int dsa_slave_set_link_ksettings(struct net_device *dev,
685 const struct ethtool_link_ksettings *cmd)
686{
687 struct dsa_port *dp = dsa_slave_to_port(dev);
688
689 return phylink_ethtool_ksettings_set(dp->pl, cmd);
Florian Fainelli79052882014-09-24 17:05:21 -0700690}
691
Florian Fainelli04ff53f2015-07-31 11:42:57 -0700692#ifdef CONFIG_NET_POLL_CONTROLLER
693static int dsa_slave_netpoll_setup(struct net_device *dev,
694 struct netpoll_info *ni)
695{
Vivien Didelotd0006b02017-10-16 11:12:16 -0400696 struct net_device *master = dsa_slave_to_master(dev);
Florian Fainelli04ff53f2015-07-31 11:42:57 -0700697 struct dsa_slave_priv *p = netdev_priv(dev);
Florian Fainelli04ff53f2015-07-31 11:42:57 -0700698 struct netpoll *netpoll;
699 int err = 0;
700
701 netpoll = kzalloc(sizeof(*netpoll), GFP_KERNEL);
702 if (!netpoll)
703 return -ENOMEM;
704
705 err = __netpoll_setup(netpoll, master);
706 if (err) {
707 kfree(netpoll);
708 goto out;
709 }
710
711 p->netpoll = netpoll;
712out:
713 return err;
714}
715
716static void dsa_slave_netpoll_cleanup(struct net_device *dev)
717{
718 struct dsa_slave_priv *p = netdev_priv(dev);
719 struct netpoll *netpoll = p->netpoll;
720
721 if (!netpoll)
722 return;
723
724 p->netpoll = NULL;
725
Debabrata Banerjeec9fbd712018-10-18 11:18:26 -0400726 __netpoll_free(netpoll);
Florian Fainelli04ff53f2015-07-31 11:42:57 -0700727}
728
729static void dsa_slave_poll_controller(struct net_device *dev)
730{
731}
732#endif
733
Florian Fainelli44bb7652017-01-10 12:32:36 -0800734static int dsa_slave_get_phys_port_name(struct net_device *dev,
735 char *name, size_t len)
736{
Vivien Didelotd9450972017-10-16 11:12:15 -0400737 struct dsa_port *dp = dsa_slave_to_port(dev);
Florian Fainelli44bb7652017-01-10 12:32:36 -0800738
Vivien Didelotd9450972017-10-16 11:12:15 -0400739 if (snprintf(name, len, "p%d", dp->index) >= len)
Florian Fainelli44bb7652017-01-10 12:32:36 -0800740 return -EINVAL;
Florian Fainelli3a543ef2016-12-29 14:20:56 -0800741
742 return 0;
743}
744
Florian Fainellif50f2122017-01-30 12:41:40 -0800745static struct dsa_mall_tc_entry *
Vivien Didelot4fa7b712017-09-20 19:31:57 -0400746dsa_slave_mall_tc_entry_find(struct net_device *dev, unsigned long cookie)
Florian Fainellif50f2122017-01-30 12:41:40 -0800747{
Vivien Didelot4fa7b712017-09-20 19:31:57 -0400748 struct dsa_slave_priv *p = netdev_priv(dev);
Florian Fainellif50f2122017-01-30 12:41:40 -0800749 struct dsa_mall_tc_entry *mall_tc_entry;
750
751 list_for_each_entry(mall_tc_entry, &p->mall_tc_list, list)
752 if (mall_tc_entry->cookie == cookie)
753 return mall_tc_entry;
754
755 return NULL;
756}
757
758static int dsa_slave_add_cls_matchall(struct net_device *dev,
Florian Fainellif50f2122017-01-30 12:41:40 -0800759 struct tc_cls_matchall_offload *cls,
760 bool ingress)
761{
Vivien Didelotd9450972017-10-16 11:12:15 -0400762 struct dsa_port *dp = dsa_slave_to_port(dev);
Florian Fainellif50f2122017-01-30 12:41:40 -0800763 struct dsa_slave_priv *p = netdev_priv(dev);
764 struct dsa_mall_tc_entry *mall_tc_entry;
Jiri Pirko5fd9fc42017-08-07 10:15:29 +0200765 __be16 protocol = cls->common.protocol;
Vivien Didelotd9450972017-10-16 11:12:15 -0400766 struct dsa_switch *ds = dp->ds;
Florian Fainellif50f2122017-01-30 12:41:40 -0800767 struct net_device *to_dev;
768 const struct tc_action *a;
Vivien Didelotd9450972017-10-16 11:12:15 -0400769 struct dsa_port *to_dp;
Florian Fainellif50f2122017-01-30 12:41:40 -0800770 int err = -EOPNOTSUPP;
Florian Fainellif50f2122017-01-30 12:41:40 -0800771
772 if (!ds->ops->port_mirror_add)
773 return err;
774
Jiri Pirko3bcc0ce2017-08-04 14:28:58 +0200775 if (!tcf_exts_has_one_action(cls->exts))
Florian Fainellif50f2122017-01-30 12:41:40 -0800776 return err;
777
Cong Wang244cd962018-08-19 12:22:09 -0700778 a = tcf_exts_first_action(cls->exts);
Florian Fainellif50f2122017-01-30 12:41:40 -0800779
780 if (is_tcf_mirred_egress_mirror(a) && protocol == htons(ETH_P_ALL)) {
781 struct dsa_mall_mirror_tc_entry *mirror;
782
Cong Wang9f8a7392017-12-05 16:17:26 -0800783 to_dev = tcf_mirred_dev(a);
Florian Fainellif50f2122017-01-30 12:41:40 -0800784 if (!to_dev)
785 return -EINVAL;
786
787 if (!dsa_slave_dev_check(to_dev))
788 return -EOPNOTSUPP;
789
790 mall_tc_entry = kzalloc(sizeof(*mall_tc_entry), GFP_KERNEL);
791 if (!mall_tc_entry)
792 return -ENOMEM;
793
794 mall_tc_entry->cookie = cls->cookie;
795 mall_tc_entry->type = DSA_PORT_MALL_MIRROR;
796 mirror = &mall_tc_entry->mirror;
797
Vivien Didelotd9450972017-10-16 11:12:15 -0400798 to_dp = dsa_slave_to_port(to_dev);
Florian Fainellif50f2122017-01-30 12:41:40 -0800799
Vivien Didelotd9450972017-10-16 11:12:15 -0400800 mirror->to_local_port = to_dp->index;
Florian Fainellif50f2122017-01-30 12:41:40 -0800801 mirror->ingress = ingress;
802
Vivien Didelotd9450972017-10-16 11:12:15 -0400803 err = ds->ops->port_mirror_add(ds, dp->index, mirror, ingress);
Florian Fainellif50f2122017-01-30 12:41:40 -0800804 if (err) {
805 kfree(mall_tc_entry);
806 return err;
807 }
808
809 list_add_tail(&mall_tc_entry->list, &p->mall_tc_list);
810 }
811
812 return 0;
813}
814
815static void dsa_slave_del_cls_matchall(struct net_device *dev,
816 struct tc_cls_matchall_offload *cls)
817{
Vivien Didelotd9450972017-10-16 11:12:15 -0400818 struct dsa_port *dp = dsa_slave_to_port(dev);
Florian Fainellif50f2122017-01-30 12:41:40 -0800819 struct dsa_mall_tc_entry *mall_tc_entry;
Vivien Didelotd9450972017-10-16 11:12:15 -0400820 struct dsa_switch *ds = dp->ds;
Florian Fainellif50f2122017-01-30 12:41:40 -0800821
822 if (!ds->ops->port_mirror_del)
823 return;
824
Vivien Didelot4fa7b712017-09-20 19:31:57 -0400825 mall_tc_entry = dsa_slave_mall_tc_entry_find(dev, cls->cookie);
Florian Fainellif50f2122017-01-30 12:41:40 -0800826 if (!mall_tc_entry)
827 return;
828
829 list_del(&mall_tc_entry->list);
830
831 switch (mall_tc_entry->type) {
832 case DSA_PORT_MALL_MIRROR:
Vivien Didelotd9450972017-10-16 11:12:15 -0400833 ds->ops->port_mirror_del(ds, dp->index, &mall_tc_entry->mirror);
Florian Fainellif50f2122017-01-30 12:41:40 -0800834 break;
835 default:
836 WARN_ON(1);
837 }
838
839 kfree(mall_tc_entry);
840}
841
Jiri Pirko3fbae382017-08-07 10:15:26 +0200842static int dsa_slave_setup_tc_cls_matchall(struct net_device *dev,
Jiri Pirko6b3eb752017-10-19 15:50:45 +0200843 struct tc_cls_matchall_offload *cls,
844 bool ingress)
Florian Fainellif50f2122017-01-30 12:41:40 -0800845{
Jiri Pirko5fd9fc42017-08-07 10:15:29 +0200846 if (cls->common.chain_index)
Jiri Pirkoa5fcf8a2017-06-06 17:00:16 +0200847 return -EOPNOTSUPP;
Florian Fainellif50f2122017-01-30 12:41:40 -0800848
Jiri Pirko3fbae382017-08-07 10:15:26 +0200849 switch (cls->command) {
850 case TC_CLSMATCHALL_REPLACE:
Jiri Pirko5fd9fc42017-08-07 10:15:29 +0200851 return dsa_slave_add_cls_matchall(dev, cls, ingress);
Jiri Pirko3fbae382017-08-07 10:15:26 +0200852 case TC_CLSMATCHALL_DESTROY:
853 dsa_slave_del_cls_matchall(dev, cls);
854 return 0;
855 default:
856 return -EOPNOTSUPP;
857 }
858}
859
Jiri Pirko6b3eb752017-10-19 15:50:45 +0200860static int dsa_slave_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
861 void *cb_priv, bool ingress)
862{
863 struct net_device *dev = cb_priv;
864
Jiri Pirko44ae12a2017-11-01 11:47:39 +0100865 if (!tc_can_offload(dev))
866 return -EOPNOTSUPP;
867
Jiri Pirko6b3eb752017-10-19 15:50:45 +0200868 switch (type) {
869 case TC_SETUP_CLSMATCHALL:
870 return dsa_slave_setup_tc_cls_matchall(dev, type_data, ingress);
871 default:
872 return -EOPNOTSUPP;
873 }
874}
875
876static int dsa_slave_setup_tc_block_cb_ig(enum tc_setup_type type,
877 void *type_data, void *cb_priv)
878{
879 return dsa_slave_setup_tc_block_cb(type, type_data, cb_priv, true);
880}
881
882static int dsa_slave_setup_tc_block_cb_eg(enum tc_setup_type type,
883 void *type_data, void *cb_priv)
884{
885 return dsa_slave_setup_tc_block_cb(type, type_data, cb_priv, false);
886}
887
888static int dsa_slave_setup_tc_block(struct net_device *dev,
889 struct tc_block_offload *f)
890{
891 tc_setup_cb_t *cb;
892
893 if (f->binder_type == TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
894 cb = dsa_slave_setup_tc_block_cb_ig;
895 else if (f->binder_type == TCF_BLOCK_BINDER_TYPE_CLSACT_EGRESS)
896 cb = dsa_slave_setup_tc_block_cb_eg;
897 else
898 return -EOPNOTSUPP;
899
900 switch (f->command) {
901 case TC_BLOCK_BIND:
John Hurley60513bd2018-06-25 14:30:04 -0700902 return tcf_block_cb_register(f->block, cb, dev, dev, f->extack);
Jiri Pirko6b3eb752017-10-19 15:50:45 +0200903 case TC_BLOCK_UNBIND:
904 tcf_block_cb_unregister(f->block, cb, dev);
905 return 0;
906 default:
907 return -EOPNOTSUPP;
908 }
909}
910
Jiri Pirko3fbae382017-08-07 10:15:26 +0200911static int dsa_slave_setup_tc(struct net_device *dev, enum tc_setup_type type,
Jiri Pirkode4784c2017-08-07 10:15:32 +0200912 void *type_data)
Jiri Pirko3fbae382017-08-07 10:15:26 +0200913{
Jiri Pirko2572ac52017-08-07 10:15:17 +0200914 switch (type) {
Jiri Pirko6b3eb752017-10-19 15:50:45 +0200915 case TC_SETUP_BLOCK:
916 return dsa_slave_setup_tc_block(dev, type_data);
Florian Fainellif50f2122017-01-30 12:41:40 -0800917 default:
Jiri Pirkoa5fcf8a2017-06-06 17:00:16 +0200918 return -EOPNOTSUPP;
Florian Fainellif50f2122017-01-30 12:41:40 -0800919 }
Florian Fainellif50f2122017-01-30 12:41:40 -0800920}
921
Florian Fainellif613ed62017-08-01 15:00:36 -0700922static void dsa_slave_get_stats64(struct net_device *dev,
923 struct rtnl_link_stats64 *stats)
924{
925 struct dsa_slave_priv *p = netdev_priv(dev);
Florian Fainelli5f6b4e142017-08-03 21:33:27 -0700926 struct pcpu_sw_netstats *s;
Florian Fainellif613ed62017-08-01 15:00:36 -0700927 unsigned int start;
Florian Fainelli5f6b4e142017-08-03 21:33:27 -0700928 int i;
Florian Fainellif613ed62017-08-01 15:00:36 -0700929
930 netdev_stats_to_stats64(stats, &dev->stats);
Florian Fainelli5f6b4e142017-08-03 21:33:27 -0700931 for_each_possible_cpu(i) {
932 u64 tx_packets, tx_bytes, rx_packets, rx_bytes;
933
934 s = per_cpu_ptr(p->stats64, i);
935 do {
936 start = u64_stats_fetch_begin_irq(&s->syncp);
937 tx_packets = s->tx_packets;
938 tx_bytes = s->tx_bytes;
939 rx_packets = s->rx_packets;
940 rx_bytes = s->rx_bytes;
941 } while (u64_stats_fetch_retry_irq(&s->syncp, start));
942
943 stats->tx_packets += tx_packets;
944 stats->tx_bytes += tx_bytes;
945 stats->rx_packets += rx_packets;
946 stats->rx_bytes += rx_bytes;
947 }
Florian Fainellif613ed62017-08-01 15:00:36 -0700948}
949
Florian Fainellibf9f2642017-01-30 09:48:40 -0800950static int dsa_slave_get_rxnfc(struct net_device *dev,
951 struct ethtool_rxnfc *nfc, u32 *rule_locs)
952{
Vivien Didelotd9450972017-10-16 11:12:15 -0400953 struct dsa_port *dp = dsa_slave_to_port(dev);
954 struct dsa_switch *ds = dp->ds;
Florian Fainellibf9f2642017-01-30 09:48:40 -0800955
956 if (!ds->ops->get_rxnfc)
957 return -EOPNOTSUPP;
958
Vivien Didelotd9450972017-10-16 11:12:15 -0400959 return ds->ops->get_rxnfc(ds, dp->index, nfc, rule_locs);
Florian Fainellibf9f2642017-01-30 09:48:40 -0800960}
961
962static int dsa_slave_set_rxnfc(struct net_device *dev,
963 struct ethtool_rxnfc *nfc)
964{
Vivien Didelotd9450972017-10-16 11:12:15 -0400965 struct dsa_port *dp = dsa_slave_to_port(dev);
966 struct dsa_switch *ds = dp->ds;
Florian Fainellibf9f2642017-01-30 09:48:40 -0800967
968 if (!ds->ops->set_rxnfc)
969 return -EOPNOTSUPP;
970
Vivien Didelotd9450972017-10-16 11:12:15 -0400971 return ds->ops->set_rxnfc(ds, dp->index, nfc);
Florian Fainellibf9f2642017-01-30 09:48:40 -0800972}
973
Brandon Streiff03363692018-02-14 01:07:48 +0100974static int dsa_slave_get_ts_info(struct net_device *dev,
975 struct ethtool_ts_info *ts)
976{
977 struct dsa_slave_priv *p = netdev_priv(dev);
978 struct dsa_switch *ds = p->dp->ds;
979
980 if (!ds->ops->get_ts_info)
981 return -EOPNOTSUPP;
982
983 return ds->ops->get_ts_info(ds, p->dp->index, ts);
984}
985
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000986static const struct ethtool_ops dsa_slave_ethtool_ops = {
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000987 .get_drvinfo = dsa_slave_get_drvinfo,
Guenter Roeck3d762a02014-10-29 10:45:04 -0700988 .get_regs_len = dsa_slave_get_regs_len,
989 .get_regs = dsa_slave_get_regs,
Florian Fainelliaab9c402018-05-10 13:17:36 -0700990 .nway_reset = dsa_slave_nway_reset,
Florian Fainellic4aef9f2018-05-10 13:17:34 -0700991 .get_link = ethtool_op_get_link,
Guenter Roeck6793abb2014-10-29 10:45:01 -0700992 .get_eeprom_len = dsa_slave_get_eeprom_len,
993 .get_eeprom = dsa_slave_get_eeprom,
994 .set_eeprom = dsa_slave_set_eeprom,
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000995 .get_strings = dsa_slave_get_strings,
996 .get_ethtool_stats = dsa_slave_get_ethtool_stats,
997 .get_sset_count = dsa_slave_get_sset_count,
Florian Fainelli19e57c42014-09-18 17:31:24 -0700998 .set_wol = dsa_slave_set_wol,
999 .get_wol = dsa_slave_get_wol,
Florian Fainelli79052882014-09-24 17:05:21 -07001000 .set_eee = dsa_slave_set_eee,
1001 .get_eee = dsa_slave_get_eee,
Florian Fainelliaab9c402018-05-10 13:17:36 -07001002 .get_link_ksettings = dsa_slave_get_link_ksettings,
1003 .set_link_ksettings = dsa_slave_set_link_ksettings,
Florian Fainellibf9f2642017-01-30 09:48:40 -08001004 .get_rxnfc = dsa_slave_get_rxnfc,
1005 .set_rxnfc = dsa_slave_set_rxnfc,
Brandon Streiff03363692018-02-14 01:07:48 +01001006 .get_ts_info = dsa_slave_get_ts_info,
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001007};
1008
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08001009/* legacy way, bypassing the bridge *****************************************/
1010int dsa_legacy_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
1011 struct net_device *dev,
1012 const unsigned char *addr, u16 vid,
Petr Machata87b09842019-01-16 23:06:50 +00001013 u16 flags,
1014 struct netlink_ext_ack *extack)
Florian Fainelli2a93c1a2017-12-06 15:03:33 -08001015{
1016 struct dsa_port *dp = dsa_slave_to_port(dev);
1017
1018 return dsa_port_fdb_add(dp, addr, vid);
1019}
1020
1021int dsa_legacy_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
1022 struct net_device *dev,
1023 const unsigned char *addr, u16 vid)
1024{
1025 struct dsa_port *dp = dsa_slave_to_port(dev);
1026
1027 return dsa_port_fdb_del(dp, addr, vid);
1028}
1029
Florian Fainelli3e8a72d2014-08-27 17:04:46 -07001030static const struct net_device_ops dsa_slave_netdev_ops = {
Stephen Hemmingerd442ad42009-01-06 16:45:26 -08001031 .ndo_open = dsa_slave_open,
1032 .ndo_stop = dsa_slave_close,
Florian Fainelli3e8a72d2014-08-27 17:04:46 -07001033 .ndo_start_xmit = dsa_slave_xmit,
Stephen Hemmingerd442ad42009-01-06 16:45:26 -08001034 .ndo_change_rx_flags = dsa_slave_change_rx_flags,
1035 .ndo_set_rx_mode = dsa_slave_set_rx_mode,
Stephen Hemmingerd442ad42009-01-06 16:45:26 -08001036 .ndo_set_mac_address = dsa_slave_set_mac_address,
Arkadi Sharshevsky37b8da12017-08-06 16:15:43 +03001037 .ndo_fdb_add = dsa_legacy_fdb_add,
1038 .ndo_fdb_del = dsa_legacy_fdb_del,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001039 .ndo_fdb_dump = dsa_slave_fdb_dump,
Stephen Hemmingerd442ad42009-01-06 16:45:26 -08001040 .ndo_do_ioctl = dsa_slave_ioctl,
Nicolas Dichtelabd2be02015-04-02 17:07:08 +02001041 .ndo_get_iflink = dsa_slave_get_iflink,
Florian Fainelli04ff53f2015-07-31 11:42:57 -07001042#ifdef CONFIG_NET_POLL_CONTROLLER
1043 .ndo_netpoll_setup = dsa_slave_netpoll_setup,
1044 .ndo_netpoll_cleanup = dsa_slave_netpoll_cleanup,
1045 .ndo_poll_controller = dsa_slave_poll_controller,
1046#endif
Florian Fainelli44bb7652017-01-10 12:32:36 -08001047 .ndo_get_phys_port_name = dsa_slave_get_phys_port_name,
Florian Fainellif50f2122017-01-30 12:41:40 -08001048 .ndo_setup_tc = dsa_slave_setup_tc,
Florian Fainellif613ed62017-08-01 15:00:36 -07001049 .ndo_get_stats64 = dsa_slave_get_stats64,
Florian Fainelli929d6c12019-02-06 09:45:45 -08001050 .ndo_get_port_parent_id = dsa_slave_get_port_parent_id,
Scott Feldman98237d42015-03-15 21:07:15 -07001051};
1052
Jiri Pirko9d47c0a2015-05-10 09:47:47 -07001053static const struct switchdev_ops dsa_slave_switchdev_ops = {
Scott Feldman35636062015-05-10 09:47:51 -07001054 .switchdev_port_attr_set = dsa_slave_port_attr_set,
Stephen Hemmingerd442ad42009-01-06 16:45:26 -08001055};
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001056
Florian Fainellif37db852015-09-23 18:19:58 -07001057static struct device_type dsa_type = {
1058 .name = "dsa",
1059};
1060
Florian Fainelliaab9c402018-05-10 13:17:36 -07001061static void dsa_slave_phylink_validate(struct net_device *dev,
1062 unsigned long *supported,
1063 struct phylink_link_state *state)
Florian Fainelli0d8bcdd2014-08-27 17:04:51 -07001064{
Vivien Didelotd9450972017-10-16 11:12:15 -04001065 struct dsa_port *dp = dsa_slave_to_port(dev);
Vivien Didelotd9450972017-10-16 11:12:15 -04001066 struct dsa_switch *ds = dp->ds;
Florian Fainelli0d8bcdd2014-08-27 17:04:51 -07001067
Florian Fainelliaab9c402018-05-10 13:17:36 -07001068 if (!ds->ops->phylink_validate)
1069 return;
Florian Fainelli0d8bcdd2014-08-27 17:04:51 -07001070
Florian Fainelliaab9c402018-05-10 13:17:36 -07001071 ds->ops->phylink_validate(ds, dp->index, supported, state);
Florian Fainelli0d8bcdd2014-08-27 17:04:51 -07001072}
1073
Florian Fainelliaab9c402018-05-10 13:17:36 -07001074static int dsa_slave_phylink_mac_link_state(struct net_device *dev,
1075 struct phylink_link_state *state)
Florian Fainellice31b312014-08-27 17:04:54 -07001076{
Florian Fainelliaab9c402018-05-10 13:17:36 -07001077 struct dsa_port *dp = dsa_slave_to_port(dev);
1078 struct dsa_switch *ds = dp->ds;
Florian Fainellice31b312014-08-27 17:04:54 -07001079
Florian Fainelliaab9c402018-05-10 13:17:36 -07001080 /* Only called for SGMII and 802.3z */
1081 if (!ds->ops->phylink_mac_link_state)
1082 return -EOPNOTSUPP;
1083
1084 return ds->ops->phylink_mac_link_state(ds, dp->index, state);
1085}
1086
1087static void dsa_slave_phylink_mac_config(struct net_device *dev,
1088 unsigned int mode,
1089 const struct phylink_link_state *state)
1090{
1091 struct dsa_port *dp = dsa_slave_to_port(dev);
1092 struct dsa_switch *ds = dp->ds;
1093
1094 if (!ds->ops->phylink_mac_config)
1095 return;
1096
1097 ds->ops->phylink_mac_config(ds, dp->index, mode, state);
1098}
1099
1100static void dsa_slave_phylink_mac_an_restart(struct net_device *dev)
1101{
1102 struct dsa_port *dp = dsa_slave_to_port(dev);
1103 struct dsa_switch *ds = dp->ds;
1104
1105 if (!ds->ops->phylink_mac_an_restart)
1106 return;
1107
1108 ds->ops->phylink_mac_an_restart(ds, dp->index);
1109}
1110
1111static void dsa_slave_phylink_mac_link_down(struct net_device *dev,
1112 unsigned int mode,
1113 phy_interface_t interface)
1114{
1115 struct dsa_port *dp = dsa_slave_to_port(dev);
1116 struct dsa_switch *ds = dp->ds;
1117
1118 if (!ds->ops->phylink_mac_link_down) {
1119 if (ds->ops->adjust_link && dev->phydev)
1120 ds->ops->adjust_link(ds, dp->index, dev->phydev);
1121 return;
Andrew Lunnb71be352016-03-12 00:01:37 +01001122 }
Florian Fainellice31b312014-08-27 17:04:54 -07001123
Florian Fainelliaab9c402018-05-10 13:17:36 -07001124 ds->ops->phylink_mac_link_down(ds, dp->index, mode, interface);
1125}
1126
1127static void dsa_slave_phylink_mac_link_up(struct net_device *dev,
1128 unsigned int mode,
1129 phy_interface_t interface,
1130 struct phy_device *phydev)
1131{
1132 struct dsa_port *dp = dsa_slave_to_port(dev);
1133 struct dsa_switch *ds = dp->ds;
1134
1135 if (!ds->ops->phylink_mac_link_up) {
1136 if (ds->ops->adjust_link && dev->phydev)
1137 ds->ops->adjust_link(ds, dp->index, dev->phydev);
1138 return;
1139 }
1140
1141 ds->ops->phylink_mac_link_up(ds, dp->index, mode, interface, phydev);
1142}
1143
1144static const struct phylink_mac_ops dsa_slave_phylink_mac_ops = {
1145 .validate = dsa_slave_phylink_validate,
1146 .mac_link_state = dsa_slave_phylink_mac_link_state,
1147 .mac_config = dsa_slave_phylink_mac_config,
1148 .mac_an_restart = dsa_slave_phylink_mac_an_restart,
1149 .mac_link_down = dsa_slave_phylink_mac_link_down,
1150 .mac_link_up = dsa_slave_phylink_mac_link_up,
1151};
1152
1153void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up)
1154{
1155 const struct dsa_port *dp = dsa_to_port(ds, port);
1156
1157 phylink_mac_change(dp->pl, up);
1158}
1159EXPORT_SYMBOL_GPL(dsa_port_phylink_mac_change);
1160
1161static void dsa_slave_phylink_fixed_state(struct net_device *dev,
1162 struct phylink_link_state *state)
1163{
1164 struct dsa_port *dp = dsa_slave_to_port(dev);
1165 struct dsa_switch *ds = dp->ds;
1166
1167 /* No need to check that this operation is valid, the callback would
1168 * not be called if it was not.
1169 */
1170 ds->ops->phylink_fixed_state(ds, dp->index, state);
Florian Fainellice31b312014-08-27 17:04:54 -07001171}
1172
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001173/* slave device setup *******************************************************/
Vivien Didelot4fa7b712017-09-20 19:31:57 -04001174static int dsa_slave_phy_connect(struct net_device *slave_dev, int addr)
Florian Fainellic305c162015-03-10 16:57:12 -07001175{
Vivien Didelotd9450972017-10-16 11:12:15 -04001176 struct dsa_port *dp = dsa_slave_to_port(slave_dev);
Vivien Didelotd9450972017-10-16 11:12:15 -04001177 struct dsa_switch *ds = dp->ds;
Florian Fainellic305c162015-03-10 16:57:12 -07001178
Vivien Didelot0115dcd2017-09-26 17:15:32 -04001179 slave_dev->phydev = mdiobus_get_phy(ds->slave_mii_bus, addr);
1180 if (!slave_dev->phydev) {
Russell Kingd25b8e72015-10-03 18:09:07 +01001181 netdev_err(slave_dev, "no phy at %d\n", addr);
Florian Fainellic305c162015-03-10 16:57:12 -07001182 return -ENODEV;
Russell Kingd25b8e72015-10-03 18:09:07 +01001183 }
Florian Fainellic305c162015-03-10 16:57:12 -07001184
Florian Fainelliaab9c402018-05-10 13:17:36 -07001185 return phylink_connect_phy(dp->pl, slave_dev->phydev);
Florian Fainellic305c162015-03-10 16:57:12 -07001186}
1187
Vivien Didelot4fa7b712017-09-20 19:31:57 -04001188static int dsa_slave_phy_setup(struct net_device *slave_dev)
Florian Fainelli0d8bcdd2014-08-27 17:04:51 -07001189{
Vivien Didelotd9450972017-10-16 11:12:15 -04001190 struct dsa_port *dp = dsa_slave_to_port(slave_dev);
Vivien Didelotd9450972017-10-16 11:12:15 -04001191 struct device_node *port_dn = dp->dn;
1192 struct dsa_switch *ds = dp->ds;
Florian Fainelli68195632014-09-19 13:07:54 -07001193 u32 phy_flags = 0;
Guenter Roeck19334922015-02-16 21:23:51 -08001194 int mode, ret;
Florian Fainelli0d8bcdd2014-08-27 17:04:51 -07001195
Guenter Roeck19334922015-02-16 21:23:51 -08001196 mode = of_get_phy_mode(port_dn);
1197 if (mode < 0)
1198 mode = PHY_INTERFACE_MODE_NA;
Florian Fainelli0d8bcdd2014-08-27 17:04:51 -07001199
Florian Fainelliaab9c402018-05-10 13:17:36 -07001200 dp->pl = phylink_create(slave_dev, of_fwnode_handle(port_dn), mode,
1201 &dsa_slave_phylink_mac_ops);
1202 if (IS_ERR(dp->pl)) {
1203 netdev_err(slave_dev,
1204 "error creating PHYLINK: %ld\n", PTR_ERR(dp->pl));
1205 return PTR_ERR(dp->pl);
Florian Fainelli0d8bcdd2014-08-27 17:04:51 -07001206 }
1207
Florian Fainelliaab9c402018-05-10 13:17:36 -07001208 /* Register only if the switch provides such a callback, since this
1209 * callback takes precedence over polling the link GPIO in PHYLINK
1210 * (see phylink_get_fixed_state).
1211 */
1212 if (ds->ops->phylink_fixed_state)
1213 phylink_fixed_state_cb(dp->pl, dsa_slave_phylink_fixed_state);
1214
Vivien Didelot9d490b42016-08-23 12:38:56 -04001215 if (ds->ops->get_phy_flags)
Vivien Didelotd9450972017-10-16 11:12:15 -04001216 phy_flags = ds->ops->get_phy_flags(ds, dp->index);
Florian Fainelli68195632014-09-19 13:07:54 -07001217
Florian Fainelliaab9c402018-05-10 13:17:36 -07001218 ret = phylink_of_phy_connect(dp->pl, port_dn, phy_flags);
1219 if (ret == -ENODEV) {
1220 /* We could not connect to a designated PHY or SFP, so use the
1221 * switch internal MDIO bus instead
1222 */
Vivien Didelotd9450972017-10-16 11:12:15 -04001223 ret = dsa_slave_phy_connect(slave_dev, dp->index);
Russell Kingd25b8e72015-10-03 18:09:07 +01001224 if (ret) {
Florian Fainelliaab9c402018-05-10 13:17:36 -07001225 netdev_err(slave_dev,
1226 "failed to connect to port %d: %d\n",
Vivien Didelotd9450972017-10-16 11:12:15 -04001227 dp->index, ret);
Florian Fainelliaab9c402018-05-10 13:17:36 -07001228 phylink_destroy(dp->pl);
Florian Fainellic305c162015-03-10 16:57:12 -07001229 return ret;
Russell Kingd25b8e72015-10-03 18:09:07 +01001230 }
Andrew Lunnb31f65f2014-11-05 19:47:28 +01001231 }
Florian Fainelli9697f1c2014-12-11 12:49:16 -08001232
1233 return 0;
Florian Fainelli0d8bcdd2014-08-27 17:04:51 -07001234}
1235
Andrew Lunn448b4482015-05-06 01:09:56 +02001236static struct lock_class_key dsa_slave_netdev_xmit_lock_key;
1237static void dsa_slave_set_lockdep_class_one(struct net_device *dev,
1238 struct netdev_queue *txq,
1239 void *_unused)
1240{
1241 lockdep_set_class(&txq->_xmit_lock,
1242 &dsa_slave_netdev_xmit_lock_key);
1243}
1244
Florian Fainelli24462542014-09-18 17:31:22 -07001245int dsa_slave_suspend(struct net_device *slave_dev)
1246{
Florian Fainelliaab9c402018-05-10 13:17:36 -07001247 struct dsa_port *dp = dsa_slave_to_port(slave_dev);
Florian Fainelli24462542014-09-18 17:31:22 -07001248
Florian Fainellia94c6892018-07-31 17:12:52 -07001249 if (!netif_running(slave_dev))
1250 return 0;
1251
Florian Fainellif154be22017-01-25 09:10:41 -08001252 netif_device_detach(slave_dev);
1253
Florian Fainelliaab9c402018-05-10 13:17:36 -07001254 rtnl_lock();
1255 phylink_stop(dp->pl);
1256 rtnl_unlock();
Florian Fainelli24462542014-09-18 17:31:22 -07001257
1258 return 0;
1259}
1260
1261int dsa_slave_resume(struct net_device *slave_dev)
1262{
Florian Fainelliaab9c402018-05-10 13:17:36 -07001263 struct dsa_port *dp = dsa_slave_to_port(slave_dev);
1264
Florian Fainellia94c6892018-07-31 17:12:52 -07001265 if (!netif_running(slave_dev))
1266 return 0;
1267
Florian Fainelli24462542014-09-18 17:31:22 -07001268 netif_device_attach(slave_dev);
1269
Florian Fainelliaab9c402018-05-10 13:17:36 -07001270 rtnl_lock();
1271 phylink_start(dp->pl);
1272 rtnl_unlock();
Florian Fainelli24462542014-09-18 17:31:22 -07001273
1274 return 0;
1275}
1276
Vivien Didelot6158eaa2017-10-16 11:12:14 -04001277static void dsa_slave_notify(struct net_device *dev, unsigned long val)
1278{
Vivien Didelotd0006b02017-10-16 11:12:16 -04001279 struct net_device *master = dsa_slave_to_master(dev);
Vivien Didelotd9450972017-10-16 11:12:15 -04001280 struct dsa_port *dp = dsa_slave_to_port(dev);
Vivien Didelot6158eaa2017-10-16 11:12:14 -04001281 struct dsa_notifier_register_info rinfo = {
1282 .switch_number = dp->ds->index,
1283 .port_number = dp->index,
1284 .master = master,
1285 .info.dev = dev,
1286 };
1287
1288 call_dsa_notifiers(val, dev, &rinfo.info);
1289}
1290
Vivien Didelot951259aa2017-10-27 15:55:19 -04001291int dsa_slave_create(struct dsa_port *port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001292{
Vivien Didelot24a93322017-11-06 16:11:43 -05001293 const struct dsa_port *cpu_dp = port->cpu_dp;
Vivien Didelotf8b8b1c2017-10-16 11:12:18 -04001294 struct net_device *master = cpu_dp->master;
Vivien Didelot4cfbf092017-08-05 16:20:19 -04001295 struct dsa_switch *ds = port->ds;
Vivien Didelot951259aa2017-10-27 15:55:19 -04001296 const char *name = port->name;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001297 struct net_device *slave_dev;
1298 struct dsa_slave_priv *p;
1299 int ret;
1300
Florian Fainelli55199df2017-09-03 20:27:00 -07001301 if (!ds->num_tx_queues)
1302 ds->num_tx_queues = 1;
1303
1304 slave_dev = alloc_netdev_mqs(sizeof(struct dsa_slave_priv), name,
1305 NET_NAME_UNKNOWN, ether_setup,
1306 ds->num_tx_queues, 1);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001307 if (slave_dev == NULL)
Guenter Roeckd87d6f42015-02-24 13:15:32 -08001308 return -ENOMEM;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001309
Florian Fainellif50f2122017-01-30 12:41:40 -08001310 slave_dev->features = master->vlan_features | NETIF_F_HW_TC;
1311 slave_dev->hw_features |= NETIF_F_HW_TC;
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00001312 slave_dev->ethtool_ops = &dsa_slave_ethtool_ops;
Bjørn Mork2fcc8002013-08-30 18:08:46 +02001313 eth_hw_addr_inherit(slave_dev, master);
Phil Sutter0a5f1072015-08-18 10:30:41 +02001314 slave_dev->priv_flags |= IFF_NO_QUEUE;
Florian Fainelli3e8a72d2014-08-27 17:04:46 -07001315 slave_dev->netdev_ops = &dsa_slave_netdev_ops;
Jiri Pirko9d47c0a2015-05-10 09:47:47 -07001316 slave_dev->switchdev_ops = &dsa_slave_switchdev_ops;
Jarod Wilson8b1efc02016-10-20 23:25:27 -04001317 slave_dev->min_mtu = 0;
1318 slave_dev->max_mtu = ETH_MAX_MTU;
Florian Fainellif37db852015-09-23 18:19:58 -07001319 SET_NETDEV_DEVTYPE(slave_dev, &dsa_type);
Stephen Hemmingerd442ad42009-01-06 16:45:26 -08001320
Andrew Lunn448b4482015-05-06 01:09:56 +02001321 netdev_for_each_tx_queue(slave_dev, dsa_slave_set_lockdep_class_one,
1322 NULL);
1323
Vivien Didelot4cfbf092017-08-05 16:20:19 -04001324 SET_NETDEV_DEV(slave_dev, port->ds->dev);
1325 slave_dev->dev.of_node = port->dn;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001326 slave_dev->vlan_features = master->vlan_features;
1327
1328 p = netdev_priv(slave_dev);
Florian Fainelli5f6b4e142017-08-03 21:33:27 -07001329 p->stats64 = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
1330 if (!p->stats64) {
1331 free_netdev(slave_dev);
1332 return -ENOMEM;
1333 }
Vivien Didelot4cfbf092017-08-05 16:20:19 -04001334 p->dp = port;
Florian Fainellif50f2122017-01-30 12:41:40 -08001335 INIT_LIST_HEAD(&p->mall_tc_list);
Vivien Didelot15240242017-09-29 17:19:18 -04001336 p->xmit = cpu_dp->tag_ops->xmit;
Vivien Didelotf8b8b1c2017-10-16 11:12:18 -04001337 port->slave = slave_dev;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001338
1339 netif_carrier_off(slave_dev);
1340
Vivien Didelot4fa7b712017-09-20 19:31:57 -04001341 ret = dsa_slave_phy_setup(slave_dev);
Andrew Lunn0071f562016-01-06 20:11:20 +01001342 if (ret) {
1343 netdev_err(master, "error %d setting up slave phy\n", ret);
Florian Fainellie8044412017-09-25 15:55:53 -07001344 goto out_free;
1345 }
1346
Vivien Didelot6158eaa2017-10-16 11:12:14 -04001347 dsa_slave_notify(slave_dev, DSA_PORT_REGISTER);
Florian Fainelli60724d42017-10-11 10:57:48 -07001348
Florian Fainellie8044412017-09-25 15:55:53 -07001349 ret = register_netdev(slave_dev);
1350 if (ret) {
1351 netdev_err(master, "error %d registering interface %s\n",
1352 ret, slave_dev->name);
1353 goto out_phy;
Andrew Lunn0071f562016-01-06 20:11:20 +01001354 }
1355
Guenter Roeckd87d6f42015-02-24 13:15:32 -08001356 return 0;
Florian Fainellie8044412017-09-25 15:55:53 -07001357
1358out_phy:
Florian Fainelliaab9c402018-05-10 13:17:36 -07001359 rtnl_lock();
1360 phylink_disconnect_phy(p->dp->pl);
1361 rtnl_unlock();
1362 phylink_destroy(p->dp->pl);
Florian Fainellie8044412017-09-25 15:55:53 -07001363out_free:
1364 free_percpu(p->stats64);
1365 free_netdev(slave_dev);
Vivien Didelotf8b8b1c2017-10-16 11:12:18 -04001366 port->slave = NULL;
Florian Fainellie8044412017-09-25 15:55:53 -07001367 return ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001368}
Florian Fainellib73adef2015-02-24 13:15:33 -08001369
Neil Armstrongcda5c152015-12-07 13:57:35 +01001370void dsa_slave_destroy(struct net_device *slave_dev)
1371{
Vivien Didelotd9450972017-10-16 11:12:15 -04001372 struct dsa_port *dp = dsa_slave_to_port(slave_dev);
Neil Armstrongcda5c152015-12-07 13:57:35 +01001373 struct dsa_slave_priv *p = netdev_priv(slave_dev);
1374
1375 netif_carrier_off(slave_dev);
Florian Fainelliaab9c402018-05-10 13:17:36 -07001376 rtnl_lock();
1377 phylink_disconnect_phy(dp->pl);
1378 rtnl_unlock();
Johan Hovold881eada2016-11-28 19:25:09 +01001379
Vivien Didelot6158eaa2017-10-16 11:12:14 -04001380 dsa_slave_notify(slave_dev, DSA_PORT_UNREGISTER);
Neil Armstrongcda5c152015-12-07 13:57:35 +01001381 unregister_netdev(slave_dev);
Florian Fainelliaab9c402018-05-10 13:17:36 -07001382 phylink_destroy(dp->pl);
Florian Fainelli5f6b4e142017-08-03 21:33:27 -07001383 free_percpu(p->stats64);
Neil Armstrongcda5c152015-12-07 13:57:35 +01001384 free_netdev(slave_dev);
1385}
1386
Florian Fainellib73adef2015-02-24 13:15:33 -08001387static bool dsa_slave_dev_check(struct net_device *dev)
1388{
1389 return dev->netdev_ops == &dsa_slave_netdev_ops;
1390}
1391
Vivien Didelot8e92ab32017-02-03 13:20:17 -05001392static int dsa_slave_changeupper(struct net_device *dev,
1393 struct netdev_notifier_changeupper_info *info)
Florian Fainellib73adef2015-02-24 13:15:33 -08001394{
Vivien Didelotd9450972017-10-16 11:12:15 -04001395 struct dsa_port *dp = dsa_slave_to_port(dev);
Vivien Didelot8e92ab32017-02-03 13:20:17 -05001396 int err = NOTIFY_DONE;
Florian Fainellib73adef2015-02-24 13:15:33 -08001397
Vivien Didelot8e92ab32017-02-03 13:20:17 -05001398 if (netif_is_bridge_master(info->upper_dev)) {
1399 if (info->linking) {
Vivien Didelot17d78022017-05-19 17:00:38 -04001400 err = dsa_port_bridge_join(dp, info->upper_dev);
Vivien Didelot8e92ab32017-02-03 13:20:17 -05001401 err = notifier_from_errno(err);
1402 } else {
Vivien Didelot17d78022017-05-19 17:00:38 -04001403 dsa_port_bridge_leave(dp, info->upper_dev);
Vivien Didelot8e92ab32017-02-03 13:20:17 -05001404 err = NOTIFY_OK;
Vivien Didelot6debb682016-03-13 16:21:34 -04001405 }
Vivien Didelot6debb682016-03-13 16:21:34 -04001406 }
1407
Vivien Didelot8e92ab32017-02-03 13:20:17 -05001408 return err;
Florian Fainellib73adef2015-02-24 13:15:33 -08001409}
1410
Florian Fainellicc1d5bd2019-02-20 14:35:38 -08001411static int dsa_slave_upper_vlan_check(struct net_device *dev,
1412 struct netdev_notifier_changeupper_info *
1413 info)
1414{
1415 struct netlink_ext_ack *ext_ack;
1416 struct net_device *slave;
1417 struct dsa_port *dp;
1418
1419 ext_ack = netdev_notifier_info_to_extack(&info->info);
1420
1421 if (!is_vlan_dev(dev))
1422 return NOTIFY_DONE;
1423
1424 slave = vlan_dev_real_dev(dev);
1425 if (!dsa_slave_dev_check(slave))
1426 return NOTIFY_DONE;
1427
1428 dp = dsa_slave_to_port(slave);
1429 if (!dp->bridge_dev)
1430 return NOTIFY_DONE;
1431
1432 /* Deny enslaving a VLAN device into a VLAN-aware bridge */
1433 if (br_vlan_enabled(dp->bridge_dev) &&
1434 netif_is_bridge_master(info->upper_dev) && info->linking) {
1435 NL_SET_ERR_MSG_MOD(ext_ack,
1436 "Cannot enslave VLAN device into VLAN aware bridge");
1437 return notifier_from_errno(-EINVAL);
1438 }
1439
1440 return NOTIFY_DONE;
1441}
1442
Vivien Didelot88e4f0c2017-02-03 13:20:16 -05001443static int dsa_slave_netdevice_event(struct notifier_block *nb,
1444 unsigned long event, void *ptr)
Florian Fainellib73adef2015-02-24 13:15:33 -08001445{
Vivien Didelot6debb682016-03-13 16:21:34 -04001446 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
Florian Fainellib73adef2015-02-24 13:15:33 -08001447
Florian Fainellicc1d5bd2019-02-20 14:35:38 -08001448 if (event == NETDEV_CHANGEUPPER) {
1449 if (!dsa_slave_dev_check(dev))
1450 return dsa_slave_upper_vlan_check(dev, ptr);
Vivien Didelot8e92ab32017-02-03 13:20:17 -05001451
Vivien Didelot8e92ab32017-02-03 13:20:17 -05001452 return dsa_slave_changeupper(dev, ptr);
Florian Fainellicc1d5bd2019-02-20 14:35:38 -08001453 }
Florian Fainellib73adef2015-02-24 13:15:33 -08001454
Florian Fainellib73adef2015-02-24 13:15:33 -08001455 return NOTIFY_DONE;
1456}
Vivien Didelot88e4f0c2017-02-03 13:20:16 -05001457
Arkadi Sharshevskyc9eb3e02017-08-06 16:15:42 +03001458struct dsa_switchdev_event_work {
1459 struct work_struct work;
1460 struct switchdev_notifier_fdb_info fdb_info;
1461 struct net_device *dev;
1462 unsigned long event;
1463};
1464
1465static void dsa_slave_switchdev_event_work(struct work_struct *work)
1466{
1467 struct dsa_switchdev_event_work *switchdev_work =
1468 container_of(work, struct dsa_switchdev_event_work, work);
1469 struct net_device *dev = switchdev_work->dev;
1470 struct switchdev_notifier_fdb_info *fdb_info;
Vivien Didelotd9450972017-10-16 11:12:15 -04001471 struct dsa_port *dp = dsa_slave_to_port(dev);
Arkadi Sharshevskyc9eb3e02017-08-06 16:15:42 +03001472 int err;
1473
1474 rtnl_lock();
1475 switch (switchdev_work->event) {
1476 case SWITCHDEV_FDB_ADD_TO_DEVICE:
1477 fdb_info = &switchdev_work->fdb_info;
Vivien Didelota37fb852018-05-08 23:03:12 -04001478 if (!fdb_info->added_by_user)
1479 break;
1480
Vivien Didelotd9450972017-10-16 11:12:15 -04001481 err = dsa_port_fdb_add(dp, fdb_info->addr, fdb_info->vid);
Arkadi Sharshevskyc9eb3e02017-08-06 16:15:42 +03001482 if (err) {
1483 netdev_dbg(dev, "fdb add failed err=%d\n", err);
1484 break;
1485 }
Ido Schimmele9ba0fb2018-10-17 08:53:29 +00001486 fdb_info->offloaded = true;
Arkadi Sharshevskyc9eb3e02017-08-06 16:15:42 +03001487 call_switchdev_notifiers(SWITCHDEV_FDB_OFFLOADED, dev,
Petr Machata66859872019-01-16 23:06:56 +00001488 &fdb_info->info, NULL);
Arkadi Sharshevskyc9eb3e02017-08-06 16:15:42 +03001489 break;
1490
1491 case SWITCHDEV_FDB_DEL_TO_DEVICE:
1492 fdb_info = &switchdev_work->fdb_info;
Vivien Didelota37fb852018-05-08 23:03:12 -04001493 if (!fdb_info->added_by_user)
1494 break;
1495
Vivien Didelotd9450972017-10-16 11:12:15 -04001496 err = dsa_port_fdb_del(dp, fdb_info->addr, fdb_info->vid);
Arkadi Sharshevskyc9eb3e02017-08-06 16:15:42 +03001497 if (err) {
1498 netdev_dbg(dev, "fdb del failed err=%d\n", err);
1499 dev_close(dev);
1500 }
1501 break;
1502 }
1503 rtnl_unlock();
1504
1505 kfree(switchdev_work->fdb_info.addr);
1506 kfree(switchdev_work);
1507 dev_put(dev);
1508}
1509
1510static int
1511dsa_slave_switchdev_fdb_work_init(struct dsa_switchdev_event_work *
1512 switchdev_work,
1513 const struct switchdev_notifier_fdb_info *
1514 fdb_info)
1515{
1516 memcpy(&switchdev_work->fdb_info, fdb_info,
1517 sizeof(switchdev_work->fdb_info));
1518 switchdev_work->fdb_info.addr = kzalloc(ETH_ALEN, GFP_ATOMIC);
1519 if (!switchdev_work->fdb_info.addr)
1520 return -ENOMEM;
1521 ether_addr_copy((u8 *)switchdev_work->fdb_info.addr,
1522 fdb_info->addr);
1523 return 0;
1524}
1525
1526/* Called under rcu_read_lock() */
1527static int dsa_slave_switchdev_event(struct notifier_block *unused,
1528 unsigned long event, void *ptr)
1529{
1530 struct net_device *dev = switchdev_notifier_info_to_dev(ptr);
1531 struct dsa_switchdev_event_work *switchdev_work;
1532
1533 if (!dsa_slave_dev_check(dev))
1534 return NOTIFY_DONE;
1535
1536 switchdev_work = kzalloc(sizeof(*switchdev_work), GFP_ATOMIC);
1537 if (!switchdev_work)
1538 return NOTIFY_BAD;
1539
1540 INIT_WORK(&switchdev_work->work,
1541 dsa_slave_switchdev_event_work);
1542 switchdev_work->dev = dev;
1543 switchdev_work->event = event;
1544
1545 switch (event) {
1546 case SWITCHDEV_FDB_ADD_TO_DEVICE: /* fall through */
1547 case SWITCHDEV_FDB_DEL_TO_DEVICE:
Vivien Didelota37fb852018-05-08 23:03:12 -04001548 if (dsa_slave_switchdev_fdb_work_init(switchdev_work, ptr))
Arkadi Sharshevskyc9eb3e02017-08-06 16:15:42 +03001549 goto err_fdb_work_init;
1550 dev_hold(dev);
1551 break;
1552 default:
1553 kfree(switchdev_work);
1554 return NOTIFY_DONE;
1555 }
1556
1557 dsa_schedule_work(&switchdev_work->work);
1558 return NOTIFY_OK;
1559
1560err_fdb_work_init:
1561 kfree(switchdev_work);
1562 return NOTIFY_BAD;
1563}
1564
Petr Machata2b239f62018-11-22 23:29:05 +00001565static int
1566dsa_slave_switchdev_port_obj_event(unsigned long event,
1567 struct net_device *netdev,
1568 struct switchdev_notifier_port_obj_info *port_obj_info)
1569{
1570 int err = -EOPNOTSUPP;
1571
1572 switch (event) {
1573 case SWITCHDEV_PORT_OBJ_ADD:
1574 err = dsa_slave_port_obj_add(netdev, port_obj_info->obj,
1575 port_obj_info->trans);
1576 break;
1577 case SWITCHDEV_PORT_OBJ_DEL:
1578 err = dsa_slave_port_obj_del(netdev, port_obj_info->obj);
1579 break;
1580 }
1581
1582 port_obj_info->handled = true;
1583 return notifier_from_errno(err);
1584}
1585
1586static int dsa_slave_switchdev_blocking_event(struct notifier_block *unused,
1587 unsigned long event, void *ptr)
1588{
1589 struct net_device *dev = switchdev_notifier_info_to_dev(ptr);
1590
1591 if (!dsa_slave_dev_check(dev))
1592 return NOTIFY_DONE;
1593
1594 switch (event) {
1595 case SWITCHDEV_PORT_OBJ_ADD: /* fall through */
1596 case SWITCHDEV_PORT_OBJ_DEL:
1597 return dsa_slave_switchdev_port_obj_event(event, dev, ptr);
1598 }
1599
1600 return NOTIFY_DONE;
1601}
1602
Vivien Didelot88e4f0c2017-02-03 13:20:16 -05001603static struct notifier_block dsa_slave_nb __read_mostly = {
Arkadi Sharshevskyc9eb3e02017-08-06 16:15:42 +03001604 .notifier_call = dsa_slave_netdevice_event,
1605};
1606
1607static struct notifier_block dsa_slave_switchdev_notifier = {
1608 .notifier_call = dsa_slave_switchdev_event,
Vivien Didelot88e4f0c2017-02-03 13:20:16 -05001609};
1610
Petr Machata2b239f62018-11-22 23:29:05 +00001611static struct notifier_block dsa_slave_switchdev_blocking_notifier = {
1612 .notifier_call = dsa_slave_switchdev_blocking_event,
1613};
1614
Vivien Didelot88e4f0c2017-02-03 13:20:16 -05001615int dsa_slave_register_notifier(void)
1616{
Petr Machata2b239f62018-11-22 23:29:05 +00001617 struct notifier_block *nb;
Arkadi Sharshevskyc9eb3e02017-08-06 16:15:42 +03001618 int err;
1619
1620 err = register_netdevice_notifier(&dsa_slave_nb);
1621 if (err)
1622 return err;
1623
1624 err = register_switchdev_notifier(&dsa_slave_switchdev_notifier);
1625 if (err)
1626 goto err_switchdev_nb;
1627
Petr Machata2b239f62018-11-22 23:29:05 +00001628 nb = &dsa_slave_switchdev_blocking_notifier;
1629 err = register_switchdev_blocking_notifier(nb);
1630 if (err)
1631 goto err_switchdev_blocking_nb;
1632
Arkadi Sharshevskyc9eb3e02017-08-06 16:15:42 +03001633 return 0;
1634
Petr Machata2b239f62018-11-22 23:29:05 +00001635err_switchdev_blocking_nb:
1636 unregister_switchdev_notifier(&dsa_slave_switchdev_notifier);
Arkadi Sharshevskyc9eb3e02017-08-06 16:15:42 +03001637err_switchdev_nb:
1638 unregister_netdevice_notifier(&dsa_slave_nb);
1639 return err;
Vivien Didelot88e4f0c2017-02-03 13:20:16 -05001640}
1641
1642void dsa_slave_unregister_notifier(void)
1643{
Petr Machata2b239f62018-11-22 23:29:05 +00001644 struct notifier_block *nb;
Vivien Didelot88e4f0c2017-02-03 13:20:16 -05001645 int err;
1646
Petr Machata2b239f62018-11-22 23:29:05 +00001647 nb = &dsa_slave_switchdev_blocking_notifier;
1648 err = unregister_switchdev_blocking_notifier(nb);
1649 if (err)
1650 pr_err("DSA: failed to unregister switchdev blocking notifier (%d)\n", err);
1651
Arkadi Sharshevskyc9eb3e02017-08-06 16:15:42 +03001652 err = unregister_switchdev_notifier(&dsa_slave_switchdev_notifier);
1653 if (err)
1654 pr_err("DSA: failed to unregister switchdev notifier (%d)\n", err);
1655
Vivien Didelot88e4f0c2017-02-03 13:20:16 -05001656 err = unregister_netdevice_notifier(&dsa_slave_nb);
1657 if (err)
1658 pr_err("DSA: failed to unregister slave notifier (%d)\n", err);
1659}