1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * net/dsa/slave.c - Slave device handling
4 * Copyright (c) 2008-2009 Marvell Semiconductor
7 #include <linux/list.h>
8 #include <linux/etherdevice.h>
9 #include <linux/netdevice.h>
10 #include <linux/phy.h>
11 #include <linux/phy_fixed.h>
12 #include <linux/phylink.h>
13 #include <linux/of_net.h>
14 #include <linux/of_mdio.h>
15 #include <linux/mdio.h>
16 #include <net/rtnetlink.h>
17 #include <net/pkt_cls.h>
18 #include <net/tc_act/tc_mirred.h>
19 #include <linux/if_bridge.h>
20 #include <linux/netpoll.h>
21 #include <linux/ptp_classify.h>
25 static bool dsa_slave_dev_check(const struct net_device *dev);
27 /* slave mii_bus handling ***************************************************/
28 static int dsa_slave_phy_read(struct mii_bus *bus, int addr, int reg)
30 struct dsa_switch *ds = bus->priv;
32 if (ds->phys_mii_mask & (1 << addr))
33 return ds->ops->phy_read(ds, addr, reg);
38 static int dsa_slave_phy_write(struct mii_bus *bus, int addr, int reg, u16 val)
40 struct dsa_switch *ds = bus->priv;
42 if (ds->phys_mii_mask & (1 << addr))
43 return ds->ops->phy_write(ds, addr, reg, val);
48 void dsa_slave_mii_bus_init(struct dsa_switch *ds)
50 ds->slave_mii_bus->priv = (void *)ds;
51 ds->slave_mii_bus->name = "dsa slave smi";
52 ds->slave_mii_bus->read = dsa_slave_phy_read;
53 ds->slave_mii_bus->write = dsa_slave_phy_write;
54 snprintf(ds->slave_mii_bus->id, MII_BUS_ID_SIZE, "dsa-%d.%d",
55 ds->dst->index, ds->index);
56 ds->slave_mii_bus->parent = ds->dev;
57 ds->slave_mii_bus->phy_mask = ~ds->phys_mii_mask;
61 /* slave device handling ****************************************************/
62 static int dsa_slave_get_iflink(const struct net_device *dev)
64 return dsa_slave_to_master(dev)->ifindex;
67 static int dsa_slave_open(struct net_device *dev)
69 struct net_device *master = dsa_slave_to_master(dev);
70 struct dsa_port *dp = dsa_slave_to_port(dev);
73 if (!(master->flags & IFF_UP))
76 if (!ether_addr_equal(dev->dev_addr, master->dev_addr)) {
77 err = dev_uc_add(master, dev->dev_addr);
82 if (dev->flags & IFF_ALLMULTI) {
83 err = dev_set_allmulti(master, 1);
87 if (dev->flags & IFF_PROMISC) {
88 err = dev_set_promiscuity(master, 1);
93 err = dsa_port_enable(dp, dev->phydev);
97 phylink_start(dp->pl);
102 if (dev->flags & IFF_PROMISC)
103 dev_set_promiscuity(master, -1);
105 if (dev->flags & IFF_ALLMULTI)
106 dev_set_allmulti(master, -1);
108 if (!ether_addr_equal(dev->dev_addr, master->dev_addr))
109 dev_uc_del(master, dev->dev_addr);
114 static int dsa_slave_close(struct net_device *dev)
116 struct net_device *master = dsa_slave_to_master(dev);
117 struct dsa_port *dp = dsa_slave_to_port(dev);
119 cancel_work_sync(&dp->xmit_work);
120 skb_queue_purge(&dp->xmit_queue);
122 phylink_stop(dp->pl);
124 dsa_port_disable(dp);
126 dev_mc_unsync(master, dev);
127 dev_uc_unsync(master, dev);
128 if (dev->flags & IFF_ALLMULTI)
129 dev_set_allmulti(master, -1);
130 if (dev->flags & IFF_PROMISC)
131 dev_set_promiscuity(master, -1);
133 if (!ether_addr_equal(dev->dev_addr, master->dev_addr))
134 dev_uc_del(master, dev->dev_addr);
139 static void dsa_slave_change_rx_flags(struct net_device *dev, int change)
141 struct net_device *master = dsa_slave_to_master(dev);
142 if (dev->flags & IFF_UP) {
143 if (change & IFF_ALLMULTI)
144 dev_set_allmulti(master,
145 dev->flags & IFF_ALLMULTI ? 1 : -1);
146 if (change & IFF_PROMISC)
147 dev_set_promiscuity(master,
148 dev->flags & IFF_PROMISC ? 1 : -1);
152 static void dsa_slave_set_rx_mode(struct net_device *dev)
154 struct net_device *master = dsa_slave_to_master(dev);
156 dev_mc_sync(master, dev);
157 dev_uc_sync(master, dev);
160 static int dsa_slave_set_mac_address(struct net_device *dev, void *a)
162 struct net_device *master = dsa_slave_to_master(dev);
163 struct sockaddr *addr = a;
166 if (!is_valid_ether_addr(addr->sa_data))
167 return -EADDRNOTAVAIL;
169 if (!(dev->flags & IFF_UP))
172 if (!ether_addr_equal(addr->sa_data, master->dev_addr)) {
173 err = dev_uc_add(master, addr->sa_data);
178 if (!ether_addr_equal(dev->dev_addr, master->dev_addr))
179 dev_uc_del(master, dev->dev_addr);
182 ether_addr_copy(dev->dev_addr, addr->sa_data);
187 struct dsa_slave_dump_ctx {
188 struct net_device *dev;
190 struct netlink_callback *cb;
195 dsa_slave_port_fdb_do_dump(const unsigned char *addr, u16 vid,
196 bool is_static, void *data)
198 struct dsa_slave_dump_ctx *dump = data;
199 u32 portid = NETLINK_CB(dump->cb->skb).portid;
200 u32 seq = dump->cb->nlh->nlmsg_seq;
201 struct nlmsghdr *nlh;
204 if (dump->idx < dump->cb->args[2])
207 nlh = nlmsg_put(dump->skb, portid, seq, RTM_NEWNEIGH,
208 sizeof(*ndm), NLM_F_MULTI);
212 ndm = nlmsg_data(nlh);
213 ndm->ndm_family = AF_BRIDGE;
216 ndm->ndm_flags = NTF_SELF;
218 ndm->ndm_ifindex = dump->dev->ifindex;
219 ndm->ndm_state = is_static ? NUD_NOARP : NUD_REACHABLE;
221 if (nla_put(dump->skb, NDA_LLADDR, ETH_ALEN, addr))
222 goto nla_put_failure;
224 if (vid && nla_put_u16(dump->skb, NDA_VLAN, vid))
225 goto nla_put_failure;
227 nlmsg_end(dump->skb, nlh);
234 nlmsg_cancel(dump->skb, nlh);
239 dsa_slave_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
240 struct net_device *dev, struct net_device *filter_dev,
243 struct dsa_port *dp = dsa_slave_to_port(dev);
244 struct dsa_slave_dump_ctx dump = {
252 err = dsa_port_fdb_dump(dp, dsa_slave_port_fdb_do_dump, &dump);
258 static int dsa_slave_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
260 struct dsa_slave_priv *p = netdev_priv(dev);
261 struct dsa_switch *ds = p->dp->ds;
262 int port = p->dp->index;
264 /* Pass through to switch driver if it supports timestamping */
267 if (ds->ops->port_hwtstamp_get)
268 return ds->ops->port_hwtstamp_get(ds, port, ifr);
271 if (ds->ops->port_hwtstamp_set)
272 return ds->ops->port_hwtstamp_set(ds, port, ifr);
276 return phylink_mii_ioctl(p->dp->pl, ifr, cmd);
279 static int dsa_slave_port_attr_set(struct net_device *dev,
280 const struct switchdev_attr *attr,
281 struct switchdev_trans *trans)
283 struct dsa_port *dp = dsa_slave_to_port(dev);
287 case SWITCHDEV_ATTR_ID_PORT_STP_STATE:
288 ret = dsa_port_set_state(dp, attr->u.stp_state, trans);
290 case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING:
291 ret = dsa_port_vlan_filtering(dp, attr->u.vlan_filtering,
294 case SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME:
295 ret = dsa_port_ageing_time(dp, attr->u.ageing_time, trans);
297 case SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS:
298 ret = dsa_port_pre_bridge_flags(dp, attr->u.brport_flags,
301 case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS:
302 ret = dsa_port_bridge_flags(dp, attr->u.brport_flags, trans);
312 static int dsa_slave_port_obj_add(struct net_device *dev,
313 const struct switchdev_obj *obj,
314 struct switchdev_trans *trans,
315 struct netlink_ext_ack *extack)
317 struct dsa_port *dp = dsa_slave_to_port(dev);
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.
326 case SWITCHDEV_OBJ_ID_PORT_MDB:
327 if (obj->orig_dev != dev)
329 err = dsa_port_mdb_add(dp, SWITCHDEV_OBJ_PORT_MDB(obj), trans);
331 case SWITCHDEV_OBJ_ID_HOST_MDB:
332 /* DSA can directly translate this to a normal MDB add,
333 * but on the CPU port.
335 err = dsa_port_mdb_add(dp->cpu_dp, SWITCHDEV_OBJ_PORT_MDB(obj),
338 case SWITCHDEV_OBJ_ID_PORT_VLAN:
339 if (obj->orig_dev != dev)
341 err = dsa_port_vlan_add(dp, SWITCHDEV_OBJ_PORT_VLAN(obj),
352 static int dsa_slave_port_obj_del(struct net_device *dev,
353 const struct switchdev_obj *obj)
355 struct dsa_port *dp = dsa_slave_to_port(dev);
359 case SWITCHDEV_OBJ_ID_PORT_MDB:
360 if (obj->orig_dev != dev)
362 err = dsa_port_mdb_del(dp, SWITCHDEV_OBJ_PORT_MDB(obj));
364 case SWITCHDEV_OBJ_ID_HOST_MDB:
365 /* DSA can directly translate this to a normal MDB add,
366 * but on the CPU port.
368 err = dsa_port_mdb_del(dp->cpu_dp, SWITCHDEV_OBJ_PORT_MDB(obj));
370 case SWITCHDEV_OBJ_ID_PORT_VLAN:
371 if (obj->orig_dev != dev)
373 err = dsa_port_vlan_del(dp, SWITCHDEV_OBJ_PORT_VLAN(obj));
383 static int dsa_slave_get_port_parent_id(struct net_device *dev,
384 struct netdev_phys_item_id *ppid)
386 struct dsa_port *dp = dsa_slave_to_port(dev);
387 struct dsa_switch *ds = dp->ds;
388 struct dsa_switch_tree *dst = ds->dst;
390 /* For non-legacy ports, devlink is used and it takes
391 * care of the name generation. This ndo implementation
392 * should be removed with legacy support.
397 ppid->id_len = sizeof(dst->index);
398 memcpy(&ppid->id, &dst->index, ppid->id_len);
403 static inline netdev_tx_t dsa_slave_netpoll_send_skb(struct net_device *dev,
406 #ifdef CONFIG_NET_POLL_CONTROLLER
407 struct dsa_slave_priv *p = netdev_priv(dev);
410 netpoll_send_skb(p->netpoll, skb);
417 static void dsa_skb_tx_timestamp(struct dsa_slave_priv *p,
420 struct dsa_switch *ds = p->dp->ds;
421 struct sk_buff *clone;
424 type = ptp_classify_raw(skb);
425 if (type == PTP_CLASS_NONE)
428 if (!ds->ops->port_txtstamp)
431 clone = skb_clone_sk(skb);
435 DSA_SKB_CB(skb)->clone = clone;
437 if (ds->ops->port_txtstamp(ds, p->dp->index, clone, type))
443 netdev_tx_t dsa_enqueue_skb(struct sk_buff *skb, struct net_device *dev)
445 /* SKB for netpoll still need to be mangled with the protocol-specific
446 * tag to be successfully transmitted
448 if (unlikely(netpoll_tx_running(dev)))
449 return dsa_slave_netpoll_send_skb(dev, skb);
451 /* Queue the SKB for transmission on the parent interface, but
452 * do not modify its EtherType
454 skb->dev = dsa_slave_to_master(dev);
459 EXPORT_SYMBOL_GPL(dsa_enqueue_skb);
461 static netdev_tx_t dsa_slave_xmit(struct sk_buff *skb, struct net_device *dev)
463 struct dsa_slave_priv *p = netdev_priv(dev);
464 struct pcpu_sw_netstats *s;
465 struct sk_buff *nskb;
467 s = this_cpu_ptr(p->stats64);
468 u64_stats_update_begin(&s->syncp);
470 s->tx_bytes += skb->len;
471 u64_stats_update_end(&s->syncp);
473 DSA_SKB_CB(skb)->deferred_xmit = false;
474 DSA_SKB_CB(skb)->clone = NULL;
476 /* Identify PTP protocol packets, clone them, and pass them to the
479 dsa_skb_tx_timestamp(p, skb);
481 /* Transmit function may have to reallocate the original SKB,
482 * in which case it must have freed it. Only free it here on error.
484 nskb = p->xmit(skb, dev);
486 if (!DSA_SKB_CB(skb)->deferred_xmit)
491 return dsa_enqueue_skb(nskb, dev);
494 void *dsa_defer_xmit(struct sk_buff *skb, struct net_device *dev)
496 struct dsa_port *dp = dsa_slave_to_port(dev);
498 DSA_SKB_CB(skb)->deferred_xmit = true;
500 skb_queue_tail(&dp->xmit_queue, skb);
501 schedule_work(&dp->xmit_work);
504 EXPORT_SYMBOL_GPL(dsa_defer_xmit);
506 static void dsa_port_xmit_work(struct work_struct *work)
508 struct dsa_port *dp = container_of(work, struct dsa_port, xmit_work);
509 struct dsa_switch *ds = dp->ds;
512 if (unlikely(!ds->ops->port_deferred_xmit))
515 while ((skb = skb_dequeue(&dp->xmit_queue)) != NULL)
516 ds->ops->port_deferred_xmit(ds, dp->index, skb);
519 /* ethtool operations *******************************************************/
521 static void dsa_slave_get_drvinfo(struct net_device *dev,
522 struct ethtool_drvinfo *drvinfo)
524 strlcpy(drvinfo->driver, "dsa", sizeof(drvinfo->driver));
525 strlcpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version));
526 strlcpy(drvinfo->bus_info, "platform", sizeof(drvinfo->bus_info));
529 static int dsa_slave_get_regs_len(struct net_device *dev)
531 struct dsa_port *dp = dsa_slave_to_port(dev);
532 struct dsa_switch *ds = dp->ds;
534 if (ds->ops->get_regs_len)
535 return ds->ops->get_regs_len(ds, dp->index);
541 dsa_slave_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *_p)
543 struct dsa_port *dp = dsa_slave_to_port(dev);
544 struct dsa_switch *ds = dp->ds;
546 if (ds->ops->get_regs)
547 ds->ops->get_regs(ds, dp->index, regs, _p);
550 static int dsa_slave_nway_reset(struct net_device *dev)
552 struct dsa_port *dp = dsa_slave_to_port(dev);
554 return phylink_ethtool_nway_reset(dp->pl);
557 static int dsa_slave_get_eeprom_len(struct net_device *dev)
559 struct dsa_port *dp = dsa_slave_to_port(dev);
560 struct dsa_switch *ds = dp->ds;
562 if (ds->cd && ds->cd->eeprom_len)
563 return ds->cd->eeprom_len;
565 if (ds->ops->get_eeprom_len)
566 return ds->ops->get_eeprom_len(ds);
571 static int dsa_slave_get_eeprom(struct net_device *dev,
572 struct ethtool_eeprom *eeprom, u8 *data)
574 struct dsa_port *dp = dsa_slave_to_port(dev);
575 struct dsa_switch *ds = dp->ds;
577 if (ds->ops->get_eeprom)
578 return ds->ops->get_eeprom(ds, eeprom, data);
583 static int dsa_slave_set_eeprom(struct net_device *dev,
584 struct ethtool_eeprom *eeprom, u8 *data)
586 struct dsa_port *dp = dsa_slave_to_port(dev);
587 struct dsa_switch *ds = dp->ds;
589 if (ds->ops->set_eeprom)
590 return ds->ops->set_eeprom(ds, eeprom, data);
595 static void dsa_slave_get_strings(struct net_device *dev,
596 uint32_t stringset, uint8_t *data)
598 struct dsa_port *dp = dsa_slave_to_port(dev);
599 struct dsa_switch *ds = dp->ds;
601 if (stringset == ETH_SS_STATS) {
602 int len = ETH_GSTRING_LEN;
604 strncpy(data, "tx_packets", len);
605 strncpy(data + len, "tx_bytes", len);
606 strncpy(data + 2 * len, "rx_packets", len);
607 strncpy(data + 3 * len, "rx_bytes", len);
608 if (ds->ops->get_strings)
609 ds->ops->get_strings(ds, dp->index, stringset,
614 static void dsa_slave_get_ethtool_stats(struct net_device *dev,
615 struct ethtool_stats *stats,
618 struct dsa_port *dp = dsa_slave_to_port(dev);
619 struct dsa_slave_priv *p = netdev_priv(dev);
620 struct dsa_switch *ds = dp->ds;
621 struct pcpu_sw_netstats *s;
625 for_each_possible_cpu(i) {
626 u64 tx_packets, tx_bytes, rx_packets, rx_bytes;
628 s = per_cpu_ptr(p->stats64, i);
630 start = u64_stats_fetch_begin_irq(&s->syncp);
631 tx_packets = s->tx_packets;
632 tx_bytes = s->tx_bytes;
633 rx_packets = s->rx_packets;
634 rx_bytes = s->rx_bytes;
635 } while (u64_stats_fetch_retry_irq(&s->syncp, start));
636 data[0] += tx_packets;
638 data[2] += rx_packets;
641 if (ds->ops->get_ethtool_stats)
642 ds->ops->get_ethtool_stats(ds, dp->index, data + 4);
645 static int dsa_slave_get_sset_count(struct net_device *dev, int sset)
647 struct dsa_port *dp = dsa_slave_to_port(dev);
648 struct dsa_switch *ds = dp->ds;
650 if (sset == ETH_SS_STATS) {
654 if (ds->ops->get_sset_count)
655 count += ds->ops->get_sset_count(ds, dp->index, sset);
663 static void dsa_slave_get_wol(struct net_device *dev, struct ethtool_wolinfo *w)
665 struct dsa_port *dp = dsa_slave_to_port(dev);
666 struct dsa_switch *ds = dp->ds;
668 phylink_ethtool_get_wol(dp->pl, w);
670 if (ds->ops->get_wol)
671 ds->ops->get_wol(ds, dp->index, w);
674 static int dsa_slave_set_wol(struct net_device *dev, struct ethtool_wolinfo *w)
676 struct dsa_port *dp = dsa_slave_to_port(dev);
677 struct dsa_switch *ds = dp->ds;
678 int ret = -EOPNOTSUPP;
680 phylink_ethtool_set_wol(dp->pl, w);
682 if (ds->ops->set_wol)
683 ret = ds->ops->set_wol(ds, dp->index, w);
688 static int dsa_slave_set_eee(struct net_device *dev, struct ethtool_eee *e)
690 struct dsa_port *dp = dsa_slave_to_port(dev);
691 struct dsa_switch *ds = dp->ds;
694 /* Port's PHY and MAC both need to be EEE capable */
695 if (!dev->phydev || !dp->pl)
698 if (!ds->ops->set_mac_eee)
701 ret = ds->ops->set_mac_eee(ds, dp->index, e);
705 return phylink_ethtool_set_eee(dp->pl, e);
708 static int dsa_slave_get_eee(struct net_device *dev, struct ethtool_eee *e)
710 struct dsa_port *dp = dsa_slave_to_port(dev);
711 struct dsa_switch *ds = dp->ds;
714 /* Port's PHY and MAC both need to be EEE capable */
715 if (!dev->phydev || !dp->pl)
718 if (!ds->ops->get_mac_eee)
721 ret = ds->ops->get_mac_eee(ds, dp->index, e);
725 return phylink_ethtool_get_eee(dp->pl, e);
728 static int dsa_slave_get_link_ksettings(struct net_device *dev,
729 struct ethtool_link_ksettings *cmd)
731 struct dsa_port *dp = dsa_slave_to_port(dev);
733 return phylink_ethtool_ksettings_get(dp->pl, cmd);
736 static int dsa_slave_set_link_ksettings(struct net_device *dev,
737 const struct ethtool_link_ksettings *cmd)
739 struct dsa_port *dp = dsa_slave_to_port(dev);
741 return phylink_ethtool_ksettings_set(dp->pl, cmd);
744 #ifdef CONFIG_NET_POLL_CONTROLLER
745 static int dsa_slave_netpoll_setup(struct net_device *dev,
746 struct netpoll_info *ni)
748 struct net_device *master = dsa_slave_to_master(dev);
749 struct dsa_slave_priv *p = netdev_priv(dev);
750 struct netpoll *netpoll;
753 netpoll = kzalloc(sizeof(*netpoll), GFP_KERNEL);
757 err = __netpoll_setup(netpoll, master);
763 p->netpoll = netpoll;
768 static void dsa_slave_netpoll_cleanup(struct net_device *dev)
770 struct dsa_slave_priv *p = netdev_priv(dev);
771 struct netpoll *netpoll = p->netpoll;
778 __netpoll_free(netpoll);
781 static void dsa_slave_poll_controller(struct net_device *dev)
786 static int dsa_slave_get_phys_port_name(struct net_device *dev,
787 char *name, size_t len)
789 struct dsa_port *dp = dsa_slave_to_port(dev);
791 /* For non-legacy ports, devlink is used and it takes
792 * care of the name generation. This ndo implementation
793 * should be removed with legacy support.
798 if (snprintf(name, len, "p%d", dp->index) >= len)
804 static struct dsa_mall_tc_entry *
805 dsa_slave_mall_tc_entry_find(struct net_device *dev, unsigned long cookie)
807 struct dsa_slave_priv *p = netdev_priv(dev);
808 struct dsa_mall_tc_entry *mall_tc_entry;
810 list_for_each_entry(mall_tc_entry, &p->mall_tc_list, list)
811 if (mall_tc_entry->cookie == cookie)
812 return mall_tc_entry;
817 static int dsa_slave_add_cls_matchall(struct net_device *dev,
818 struct tc_cls_matchall_offload *cls,
821 struct dsa_port *dp = dsa_slave_to_port(dev);
822 struct dsa_slave_priv *p = netdev_priv(dev);
823 struct dsa_mall_tc_entry *mall_tc_entry;
824 __be16 protocol = cls->common.protocol;
825 struct dsa_switch *ds = dp->ds;
826 struct flow_action_entry *act;
827 struct dsa_port *to_dp;
828 int err = -EOPNOTSUPP;
830 if (!ds->ops->port_mirror_add)
833 if (!flow_offload_has_one_action(&cls->rule->action))
836 act = &cls->rule->action.entries[0];
838 if (act->id == FLOW_ACTION_MIRRED && protocol == htons(ETH_P_ALL)) {
839 struct dsa_mall_mirror_tc_entry *mirror;
844 if (!dsa_slave_dev_check(act->dev))
847 mall_tc_entry = kzalloc(sizeof(*mall_tc_entry), GFP_KERNEL);
851 mall_tc_entry->cookie = cls->cookie;
852 mall_tc_entry->type = DSA_PORT_MALL_MIRROR;
853 mirror = &mall_tc_entry->mirror;
855 to_dp = dsa_slave_to_port(act->dev);
857 mirror->to_local_port = to_dp->index;
858 mirror->ingress = ingress;
860 err = ds->ops->port_mirror_add(ds, dp->index, mirror, ingress);
862 kfree(mall_tc_entry);
866 list_add_tail(&mall_tc_entry->list, &p->mall_tc_list);
872 static void dsa_slave_del_cls_matchall(struct net_device *dev,
873 struct tc_cls_matchall_offload *cls)
875 struct dsa_port *dp = dsa_slave_to_port(dev);
876 struct dsa_mall_tc_entry *mall_tc_entry;
877 struct dsa_switch *ds = dp->ds;
879 if (!ds->ops->port_mirror_del)
882 mall_tc_entry = dsa_slave_mall_tc_entry_find(dev, cls->cookie);
886 list_del(&mall_tc_entry->list);
888 switch (mall_tc_entry->type) {
889 case DSA_PORT_MALL_MIRROR:
890 ds->ops->port_mirror_del(ds, dp->index, &mall_tc_entry->mirror);
896 kfree(mall_tc_entry);
899 static int dsa_slave_setup_tc_cls_matchall(struct net_device *dev,
900 struct tc_cls_matchall_offload *cls,
903 if (cls->common.chain_index)
906 switch (cls->command) {
907 case TC_CLSMATCHALL_REPLACE:
908 return dsa_slave_add_cls_matchall(dev, cls, ingress);
909 case TC_CLSMATCHALL_DESTROY:
910 dsa_slave_del_cls_matchall(dev, cls);
917 static int dsa_slave_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
918 void *cb_priv, bool ingress)
920 struct net_device *dev = cb_priv;
922 if (!tc_can_offload(dev))
926 case TC_SETUP_CLSMATCHALL:
927 return dsa_slave_setup_tc_cls_matchall(dev, type_data, ingress);
933 static int dsa_slave_setup_tc_block_cb_ig(enum tc_setup_type type,
934 void *type_data, void *cb_priv)
936 return dsa_slave_setup_tc_block_cb(type, type_data, cb_priv, true);
939 static int dsa_slave_setup_tc_block_cb_eg(enum tc_setup_type type,
940 void *type_data, void *cb_priv)
942 return dsa_slave_setup_tc_block_cb(type, type_data, cb_priv, false);
945 static int dsa_slave_setup_tc_block(struct net_device *dev,
946 struct tc_block_offload *f)
950 if (f->binder_type == TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
951 cb = dsa_slave_setup_tc_block_cb_ig;
952 else if (f->binder_type == TCF_BLOCK_BINDER_TYPE_CLSACT_EGRESS)
953 cb = dsa_slave_setup_tc_block_cb_eg;
957 switch (f->command) {
959 return tcf_block_cb_register(f->block, cb, dev, dev, f->extack);
960 case TC_BLOCK_UNBIND:
961 tcf_block_cb_unregister(f->block, cb, dev);
968 static int dsa_slave_setup_tc(struct net_device *dev, enum tc_setup_type type,
973 return dsa_slave_setup_tc_block(dev, type_data);
979 static void dsa_slave_get_stats64(struct net_device *dev,
980 struct rtnl_link_stats64 *stats)
982 struct dsa_slave_priv *p = netdev_priv(dev);
983 struct pcpu_sw_netstats *s;
987 netdev_stats_to_stats64(stats, &dev->stats);
988 for_each_possible_cpu(i) {
989 u64 tx_packets, tx_bytes, rx_packets, rx_bytes;
991 s = per_cpu_ptr(p->stats64, i);
993 start = u64_stats_fetch_begin_irq(&s->syncp);
994 tx_packets = s->tx_packets;
995 tx_bytes = s->tx_bytes;
996 rx_packets = s->rx_packets;
997 rx_bytes = s->rx_bytes;
998 } while (u64_stats_fetch_retry_irq(&s->syncp, start));
1000 stats->tx_packets += tx_packets;
1001 stats->tx_bytes += tx_bytes;
1002 stats->rx_packets += rx_packets;
1003 stats->rx_bytes += rx_bytes;
1007 static int dsa_slave_get_rxnfc(struct net_device *dev,
1008 struct ethtool_rxnfc *nfc, u32 *rule_locs)
1010 struct dsa_port *dp = dsa_slave_to_port(dev);
1011 struct dsa_switch *ds = dp->ds;
1013 if (!ds->ops->get_rxnfc)
1016 return ds->ops->get_rxnfc(ds, dp->index, nfc, rule_locs);
1019 static int dsa_slave_set_rxnfc(struct net_device *dev,
1020 struct ethtool_rxnfc *nfc)
1022 struct dsa_port *dp = dsa_slave_to_port(dev);
1023 struct dsa_switch *ds = dp->ds;
1025 if (!ds->ops->set_rxnfc)
1028 return ds->ops->set_rxnfc(ds, dp->index, nfc);
1031 static int dsa_slave_get_ts_info(struct net_device *dev,
1032 struct ethtool_ts_info *ts)
1034 struct dsa_slave_priv *p = netdev_priv(dev);
1035 struct dsa_switch *ds = p->dp->ds;
1037 if (!ds->ops->get_ts_info)
1040 return ds->ops->get_ts_info(ds, p->dp->index, ts);
1043 static int dsa_slave_vlan_rx_add_vid(struct net_device *dev, __be16 proto,
1046 struct dsa_port *dp = dsa_slave_to_port(dev);
1047 struct bridge_vlan_info info;
1050 /* Check for a possible bridge VLAN entry now since there is no
1051 * need to emulate the switchdev prepare + commit phase.
1053 if (dp->bridge_dev) {
1054 /* br_vlan_get_info() returns -EINVAL or -ENOENT if the
1055 * device, respectively the VID is not found, returning
1056 * 0 means success, which is a failure for us here.
1058 ret = br_vlan_get_info(dp->bridge_dev, vid, &info);
1063 /* This API only allows programming tagged, non-PVID VIDs */
1064 return dsa_port_vid_add(dp, vid, 0);
1067 static int dsa_slave_vlan_rx_kill_vid(struct net_device *dev, __be16 proto,
1070 struct dsa_port *dp = dsa_slave_to_port(dev);
1071 struct bridge_vlan_info info;
1074 /* Check for a possible bridge VLAN entry now since there is no
1075 * need to emulate the switchdev prepare + commit phase.
1077 if (dp->bridge_dev) {
1078 /* br_vlan_get_info() returns -EINVAL or -ENOENT if the
1079 * device, respectively the VID is not found, returning
1080 * 0 means success, which is a failure for us here.
1082 ret = br_vlan_get_info(dp->bridge_dev, vid, &info);
1087 ret = dsa_port_vid_del(dp, vid);
1088 if (ret == -EOPNOTSUPP)
1094 static const struct ethtool_ops dsa_slave_ethtool_ops = {
1095 .get_drvinfo = dsa_slave_get_drvinfo,
1096 .get_regs_len = dsa_slave_get_regs_len,
1097 .get_regs = dsa_slave_get_regs,
1098 .nway_reset = dsa_slave_nway_reset,
1099 .get_link = ethtool_op_get_link,
1100 .get_eeprom_len = dsa_slave_get_eeprom_len,
1101 .get_eeprom = dsa_slave_get_eeprom,
1102 .set_eeprom = dsa_slave_set_eeprom,
1103 .get_strings = dsa_slave_get_strings,
1104 .get_ethtool_stats = dsa_slave_get_ethtool_stats,
1105 .get_sset_count = dsa_slave_get_sset_count,
1106 .set_wol = dsa_slave_set_wol,
1107 .get_wol = dsa_slave_get_wol,
1108 .set_eee = dsa_slave_set_eee,
1109 .get_eee = dsa_slave_get_eee,
1110 .get_link_ksettings = dsa_slave_get_link_ksettings,
1111 .set_link_ksettings = dsa_slave_set_link_ksettings,
1112 .get_rxnfc = dsa_slave_get_rxnfc,
1113 .set_rxnfc = dsa_slave_set_rxnfc,
1114 .get_ts_info = dsa_slave_get_ts_info,
1117 /* legacy way, bypassing the bridge *****************************************/
1118 int dsa_legacy_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
1119 struct net_device *dev,
1120 const unsigned char *addr, u16 vid,
1122 struct netlink_ext_ack *extack)
1124 struct dsa_port *dp = dsa_slave_to_port(dev);
1126 return dsa_port_fdb_add(dp, addr, vid);
1129 int dsa_legacy_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
1130 struct net_device *dev,
1131 const unsigned char *addr, u16 vid)
1133 struct dsa_port *dp = dsa_slave_to_port(dev);
1135 return dsa_port_fdb_del(dp, addr, vid);
1138 static struct devlink_port *dsa_slave_get_devlink_port(struct net_device *dev)
1140 struct dsa_port *dp = dsa_slave_to_port(dev);
1142 return dp->ds->devlink ? &dp->devlink_port : NULL;
1145 static const struct net_device_ops dsa_slave_netdev_ops = {
1146 .ndo_open = dsa_slave_open,
1147 .ndo_stop = dsa_slave_close,
1148 .ndo_start_xmit = dsa_slave_xmit,
1149 .ndo_change_rx_flags = dsa_slave_change_rx_flags,
1150 .ndo_set_rx_mode = dsa_slave_set_rx_mode,
1151 .ndo_set_mac_address = dsa_slave_set_mac_address,
1152 .ndo_fdb_add = dsa_legacy_fdb_add,
1153 .ndo_fdb_del = dsa_legacy_fdb_del,
1154 .ndo_fdb_dump = dsa_slave_fdb_dump,
1155 .ndo_do_ioctl = dsa_slave_ioctl,
1156 .ndo_get_iflink = dsa_slave_get_iflink,
1157 #ifdef CONFIG_NET_POLL_CONTROLLER
1158 .ndo_netpoll_setup = dsa_slave_netpoll_setup,
1159 .ndo_netpoll_cleanup = dsa_slave_netpoll_cleanup,
1160 .ndo_poll_controller = dsa_slave_poll_controller,
1162 .ndo_get_phys_port_name = dsa_slave_get_phys_port_name,
1163 .ndo_setup_tc = dsa_slave_setup_tc,
1164 .ndo_get_stats64 = dsa_slave_get_stats64,
1165 .ndo_get_port_parent_id = dsa_slave_get_port_parent_id,
1166 .ndo_vlan_rx_add_vid = dsa_slave_vlan_rx_add_vid,
1167 .ndo_vlan_rx_kill_vid = dsa_slave_vlan_rx_kill_vid,
1168 .ndo_get_devlink_port = dsa_slave_get_devlink_port,
1171 static struct device_type dsa_type = {
1175 void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up)
1177 const struct dsa_port *dp = dsa_to_port(ds, port);
1179 phylink_mac_change(dp->pl, up);
1181 EXPORT_SYMBOL_GPL(dsa_port_phylink_mac_change);
1183 static void dsa_slave_phylink_fixed_state(struct net_device *dev,
1184 struct phylink_link_state *state)
1186 struct dsa_port *dp = dsa_slave_to_port(dev);
1187 struct dsa_switch *ds = dp->ds;
1189 /* No need to check that this operation is valid, the callback would
1190 * not be called if it was not.
1192 ds->ops->phylink_fixed_state(ds, dp->index, state);
1195 /* slave device setup *******************************************************/
1196 static int dsa_slave_phy_connect(struct net_device *slave_dev, int addr)
1198 struct dsa_port *dp = dsa_slave_to_port(slave_dev);
1199 struct dsa_switch *ds = dp->ds;
1201 slave_dev->phydev = mdiobus_get_phy(ds->slave_mii_bus, addr);
1202 if (!slave_dev->phydev) {
1203 netdev_err(slave_dev, "no phy at %d\n", addr);
1207 return phylink_connect_phy(dp->pl, slave_dev->phydev);
1210 static int dsa_slave_phy_setup(struct net_device *slave_dev)
1212 struct dsa_port *dp = dsa_slave_to_port(slave_dev);
1213 struct device_node *port_dn = dp->dn;
1214 struct dsa_switch *ds = dp->ds;
1218 mode = of_get_phy_mode(port_dn);
1220 mode = PHY_INTERFACE_MODE_NA;
1222 dp->pl_config.dev = &slave_dev->dev;
1223 dp->pl_config.type = PHYLINK_NETDEV;
1225 dp->pl = phylink_create(&dp->pl_config, of_fwnode_handle(port_dn), mode,
1226 &dsa_port_phylink_mac_ops);
1227 if (IS_ERR(dp->pl)) {
1228 netdev_err(slave_dev,
1229 "error creating PHYLINK: %ld\n", PTR_ERR(dp->pl));
1230 return PTR_ERR(dp->pl);
1233 /* Register only if the switch provides such a callback, since this
1234 * callback takes precedence over polling the link GPIO in PHYLINK
1235 * (see phylink_get_fixed_state).
1237 if (ds->ops->phylink_fixed_state)
1238 phylink_fixed_state_cb(dp->pl, dsa_slave_phylink_fixed_state);
1240 if (ds->ops->get_phy_flags)
1241 phy_flags = ds->ops->get_phy_flags(ds, dp->index);
1243 ret = phylink_of_phy_connect(dp->pl, port_dn, phy_flags);
1244 if (ret == -ENODEV && ds->slave_mii_bus) {
1245 /* We could not connect to a designated PHY or SFP, so try to
1246 * use the switch internal MDIO bus instead
1248 ret = dsa_slave_phy_connect(slave_dev, dp->index);
1250 netdev_err(slave_dev,
1251 "failed to connect to port %d: %d\n",
1253 phylink_destroy(dp->pl);
1261 static struct lock_class_key dsa_slave_netdev_xmit_lock_key;
1262 static void dsa_slave_set_lockdep_class_one(struct net_device *dev,
1263 struct netdev_queue *txq,
1266 lockdep_set_class(&txq->_xmit_lock,
1267 &dsa_slave_netdev_xmit_lock_key);
1270 int dsa_slave_suspend(struct net_device *slave_dev)
1272 struct dsa_port *dp = dsa_slave_to_port(slave_dev);
1274 if (!netif_running(slave_dev))
1277 cancel_work_sync(&dp->xmit_work);
1278 skb_queue_purge(&dp->xmit_queue);
1280 netif_device_detach(slave_dev);
1283 phylink_stop(dp->pl);
1289 int dsa_slave_resume(struct net_device *slave_dev)
1291 struct dsa_port *dp = dsa_slave_to_port(slave_dev);
1293 if (!netif_running(slave_dev))
1296 netif_device_attach(slave_dev);
1299 phylink_start(dp->pl);
1305 static void dsa_slave_notify(struct net_device *dev, unsigned long val)
1307 struct net_device *master = dsa_slave_to_master(dev);
1308 struct dsa_port *dp = dsa_slave_to_port(dev);
1309 struct dsa_notifier_register_info rinfo = {
1310 .switch_number = dp->ds->index,
1311 .port_number = dp->index,
1316 call_dsa_notifiers(val, dev, &rinfo.info);
1319 int dsa_slave_create(struct dsa_port *port)
1321 const struct dsa_port *cpu_dp = port->cpu_dp;
1322 struct net_device *master = cpu_dp->master;
1323 struct dsa_switch *ds = port->ds;
1324 const char *name = port->name;
1325 struct net_device *slave_dev;
1326 struct dsa_slave_priv *p;
1329 if (!ds->num_tx_queues)
1330 ds->num_tx_queues = 1;
1332 slave_dev = alloc_netdev_mqs(sizeof(struct dsa_slave_priv), name,
1333 NET_NAME_UNKNOWN, ether_setup,
1334 ds->num_tx_queues, 1);
1335 if (slave_dev == NULL)
1338 slave_dev->features = master->vlan_features | NETIF_F_HW_TC |
1339 NETIF_F_HW_VLAN_CTAG_FILTER;
1340 slave_dev->hw_features |= NETIF_F_HW_TC;
1341 slave_dev->ethtool_ops = &dsa_slave_ethtool_ops;
1342 if (!IS_ERR_OR_NULL(port->mac))
1343 ether_addr_copy(slave_dev->dev_addr, port->mac);
1345 eth_hw_addr_inherit(slave_dev, master);
1346 slave_dev->priv_flags |= IFF_NO_QUEUE;
1347 slave_dev->netdev_ops = &dsa_slave_netdev_ops;
1348 slave_dev->min_mtu = 0;
1349 slave_dev->max_mtu = ETH_MAX_MTU;
1350 SET_NETDEV_DEVTYPE(slave_dev, &dsa_type);
1352 netdev_for_each_tx_queue(slave_dev, dsa_slave_set_lockdep_class_one,
1355 SET_NETDEV_DEV(slave_dev, port->ds->dev);
1356 slave_dev->dev.of_node = port->dn;
1357 slave_dev->vlan_features = master->vlan_features;
1359 p = netdev_priv(slave_dev);
1360 p->stats64 = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
1362 free_netdev(slave_dev);
1366 INIT_LIST_HEAD(&p->mall_tc_list);
1367 INIT_WORK(&port->xmit_work, dsa_port_xmit_work);
1368 skb_queue_head_init(&port->xmit_queue);
1369 p->xmit = cpu_dp->tag_ops->xmit;
1370 port->slave = slave_dev;
1372 netif_carrier_off(slave_dev);
1374 ret = dsa_slave_phy_setup(slave_dev);
1376 netdev_err(master, "error %d setting up slave phy\n", ret);
1380 dsa_slave_notify(slave_dev, DSA_PORT_REGISTER);
1382 ret = register_netdev(slave_dev);
1384 netdev_err(master, "error %d registering interface %s\n",
1385 ret, slave_dev->name);
1393 phylink_disconnect_phy(p->dp->pl);
1395 phylink_destroy(p->dp->pl);
1397 free_percpu(p->stats64);
1398 free_netdev(slave_dev);
1403 void dsa_slave_destroy(struct net_device *slave_dev)
1405 struct dsa_port *dp = dsa_slave_to_port(slave_dev);
1406 struct dsa_slave_priv *p = netdev_priv(slave_dev);
1408 netif_carrier_off(slave_dev);
1410 phylink_disconnect_phy(dp->pl);
1413 dsa_slave_notify(slave_dev, DSA_PORT_UNREGISTER);
1414 unregister_netdev(slave_dev);
1415 phylink_destroy(dp->pl);
1416 free_percpu(p->stats64);
1417 free_netdev(slave_dev);
1420 static bool dsa_slave_dev_check(const struct net_device *dev)
1422 return dev->netdev_ops == &dsa_slave_netdev_ops;
1425 static int dsa_slave_changeupper(struct net_device *dev,
1426 struct netdev_notifier_changeupper_info *info)
1428 struct dsa_port *dp = dsa_slave_to_port(dev);
1429 int err = NOTIFY_DONE;
1431 if (netif_is_bridge_master(info->upper_dev)) {
1432 if (info->linking) {
1433 err = dsa_port_bridge_join(dp, info->upper_dev);
1434 err = notifier_from_errno(err);
1436 dsa_port_bridge_leave(dp, info->upper_dev);
1444 static int dsa_slave_upper_vlan_check(struct net_device *dev,
1445 struct netdev_notifier_changeupper_info *
1448 struct netlink_ext_ack *ext_ack;
1449 struct net_device *slave;
1450 struct dsa_port *dp;
1452 ext_ack = netdev_notifier_info_to_extack(&info->info);
1454 if (!is_vlan_dev(dev))
1457 slave = vlan_dev_real_dev(dev);
1458 if (!dsa_slave_dev_check(slave))
1461 dp = dsa_slave_to_port(slave);
1462 if (!dp->bridge_dev)
1465 /* Deny enslaving a VLAN device into a VLAN-aware bridge */
1466 if (br_vlan_enabled(dp->bridge_dev) &&
1467 netif_is_bridge_master(info->upper_dev) && info->linking) {
1468 NL_SET_ERR_MSG_MOD(ext_ack,
1469 "Cannot enslave VLAN device into VLAN aware bridge");
1470 return notifier_from_errno(-EINVAL);
1476 static int dsa_slave_netdevice_event(struct notifier_block *nb,
1477 unsigned long event, void *ptr)
1479 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
1481 if (event == NETDEV_CHANGEUPPER) {
1482 if (!dsa_slave_dev_check(dev))
1483 return dsa_slave_upper_vlan_check(dev, ptr);
1485 return dsa_slave_changeupper(dev, ptr);
1491 struct dsa_switchdev_event_work {
1492 struct work_struct work;
1493 struct switchdev_notifier_fdb_info fdb_info;
1494 struct net_device *dev;
1495 unsigned long event;
1498 static void dsa_slave_switchdev_event_work(struct work_struct *work)
1500 struct dsa_switchdev_event_work *switchdev_work =
1501 container_of(work, struct dsa_switchdev_event_work, work);
1502 struct net_device *dev = switchdev_work->dev;
1503 struct switchdev_notifier_fdb_info *fdb_info;
1504 struct dsa_port *dp = dsa_slave_to_port(dev);
1508 switch (switchdev_work->event) {
1509 case SWITCHDEV_FDB_ADD_TO_DEVICE:
1510 fdb_info = &switchdev_work->fdb_info;
1511 if (!fdb_info->added_by_user)
1514 err = dsa_port_fdb_add(dp, fdb_info->addr, fdb_info->vid);
1516 netdev_dbg(dev, "fdb add failed err=%d\n", err);
1519 fdb_info->offloaded = true;
1520 call_switchdev_notifiers(SWITCHDEV_FDB_OFFLOADED, dev,
1521 &fdb_info->info, NULL);
1524 case SWITCHDEV_FDB_DEL_TO_DEVICE:
1525 fdb_info = &switchdev_work->fdb_info;
1526 if (!fdb_info->added_by_user)
1529 err = dsa_port_fdb_del(dp, fdb_info->addr, fdb_info->vid);
1531 netdev_dbg(dev, "fdb del failed err=%d\n", err);
1538 kfree(switchdev_work->fdb_info.addr);
1539 kfree(switchdev_work);
1544 dsa_slave_switchdev_fdb_work_init(struct dsa_switchdev_event_work *
1546 const struct switchdev_notifier_fdb_info *
1549 memcpy(&switchdev_work->fdb_info, fdb_info,
1550 sizeof(switchdev_work->fdb_info));
1551 switchdev_work->fdb_info.addr = kzalloc(ETH_ALEN, GFP_ATOMIC);
1552 if (!switchdev_work->fdb_info.addr)
1554 ether_addr_copy((u8 *)switchdev_work->fdb_info.addr,
1559 /* Called under rcu_read_lock() */
1560 static int dsa_slave_switchdev_event(struct notifier_block *unused,
1561 unsigned long event, void *ptr)
1563 struct net_device *dev = switchdev_notifier_info_to_dev(ptr);
1564 struct dsa_switchdev_event_work *switchdev_work;
1567 if (event == SWITCHDEV_PORT_ATTR_SET) {
1568 err = switchdev_handle_port_attr_set(dev, ptr,
1569 dsa_slave_dev_check,
1570 dsa_slave_port_attr_set);
1571 return notifier_from_errno(err);
1574 if (!dsa_slave_dev_check(dev))
1577 switchdev_work = kzalloc(sizeof(*switchdev_work), GFP_ATOMIC);
1578 if (!switchdev_work)
1581 INIT_WORK(&switchdev_work->work,
1582 dsa_slave_switchdev_event_work);
1583 switchdev_work->dev = dev;
1584 switchdev_work->event = event;
1587 case SWITCHDEV_FDB_ADD_TO_DEVICE: /* fall through */
1588 case SWITCHDEV_FDB_DEL_TO_DEVICE:
1589 if (dsa_slave_switchdev_fdb_work_init(switchdev_work, ptr))
1590 goto err_fdb_work_init;
1594 kfree(switchdev_work);
1598 dsa_schedule_work(&switchdev_work->work);
1602 kfree(switchdev_work);
1606 static int dsa_slave_switchdev_blocking_event(struct notifier_block *unused,
1607 unsigned long event, void *ptr)
1609 struct net_device *dev = switchdev_notifier_info_to_dev(ptr);
1613 case SWITCHDEV_PORT_OBJ_ADD:
1614 err = switchdev_handle_port_obj_add(dev, ptr,
1615 dsa_slave_dev_check,
1616 dsa_slave_port_obj_add);
1617 return notifier_from_errno(err);
1618 case SWITCHDEV_PORT_OBJ_DEL:
1619 err = switchdev_handle_port_obj_del(dev, ptr,
1620 dsa_slave_dev_check,
1621 dsa_slave_port_obj_del);
1622 return notifier_from_errno(err);
1623 case SWITCHDEV_PORT_ATTR_SET:
1624 err = switchdev_handle_port_attr_set(dev, ptr,
1625 dsa_slave_dev_check,
1626 dsa_slave_port_attr_set);
1627 return notifier_from_errno(err);
1633 static struct notifier_block dsa_slave_nb __read_mostly = {
1634 .notifier_call = dsa_slave_netdevice_event,
1637 static struct notifier_block dsa_slave_switchdev_notifier = {
1638 .notifier_call = dsa_slave_switchdev_event,
1641 static struct notifier_block dsa_slave_switchdev_blocking_notifier = {
1642 .notifier_call = dsa_slave_switchdev_blocking_event,
1645 int dsa_slave_register_notifier(void)
1647 struct notifier_block *nb;
1650 err = register_netdevice_notifier(&dsa_slave_nb);
1654 err = register_switchdev_notifier(&dsa_slave_switchdev_notifier);
1656 goto err_switchdev_nb;
1658 nb = &dsa_slave_switchdev_blocking_notifier;
1659 err = register_switchdev_blocking_notifier(nb);
1661 goto err_switchdev_blocking_nb;
1665 err_switchdev_blocking_nb:
1666 unregister_switchdev_notifier(&dsa_slave_switchdev_notifier);
1668 unregister_netdevice_notifier(&dsa_slave_nb);
1672 void dsa_slave_unregister_notifier(void)
1674 struct notifier_block *nb;
1677 nb = &dsa_slave_switchdev_blocking_notifier;
1678 err = unregister_switchdev_blocking_notifier(nb);
1680 pr_err("DSA: failed to unregister switchdev blocking notifier (%d)\n", err);
1682 err = unregister_switchdev_notifier(&dsa_slave_switchdev_notifier);
1684 pr_err("DSA: failed to unregister switchdev notifier (%d)\n", err);
1686 err = unregister_netdevice_notifier(&dsa_slave_nb);
1688 pr_err("DSA: failed to unregister slave notifier (%d)\n", err);