12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 291da11f8SLennert Buytenhek /* 391da11f8SLennert Buytenhek * net/dsa/slave.c - Slave device handling 4e84665c9SLennert Buytenhek * Copyright (c) 2008-2009 Marvell Semiconductor 591da11f8SLennert Buytenhek */ 691da11f8SLennert Buytenhek 791da11f8SLennert Buytenhek #include <linux/list.h> 8df02c6ffSLennert Buytenhek #include <linux/etherdevice.h> 9b73adef6SFlorian Fainelli #include <linux/netdevice.h> 1091da11f8SLennert Buytenhek #include <linux/phy.h> 11a2820543SFlorian Fainelli #include <linux/phy_fixed.h> 12aab9c406SFlorian Fainelli #include <linux/phylink.h> 130d8bcdd3SFlorian Fainelli #include <linux/of_net.h> 140d8bcdd3SFlorian Fainelli #include <linux/of_mdio.h> 157f854420SAndrew Lunn #include <linux/mdio.h> 16b73adef6SFlorian Fainelli #include <net/rtnetlink.h> 17f50f2127SFlorian Fainelli #include <net/pkt_cls.h> 18f50f2127SFlorian Fainelli #include <net/tc_act/tc_mirred.h> 19b73adef6SFlorian Fainelli #include <linux/if_bridge.h> 2004ff53f9SFlorian Fainelli #include <linux/netpoll.h> 2190af1059SBrandon Streiff #include <linux/ptp_classify.h> 22ea5dd34bSVivien Didelot 2391da11f8SLennert Buytenhek #include "dsa_priv.h" 2491da11f8SLennert Buytenhek 2591da11f8SLennert Buytenhek /* slave mii_bus handling ***************************************************/ 2691da11f8SLennert Buytenhek static int dsa_slave_phy_read(struct mii_bus *bus, int addr, int reg) 2791da11f8SLennert Buytenhek { 2891da11f8SLennert Buytenhek struct dsa_switch *ds = bus->priv; 2991da11f8SLennert Buytenhek 300d8bcdd3SFlorian Fainelli if (ds->phys_mii_mask & (1 << addr)) 319d490b4eSVivien Didelot return ds->ops->phy_read(ds, addr, reg); 3291da11f8SLennert Buytenhek 3391da11f8SLennert Buytenhek return 0xffff; 3491da11f8SLennert Buytenhek } 3591da11f8SLennert Buytenhek 3691da11f8SLennert Buytenhek static int dsa_slave_phy_write(struct mii_bus *bus, int addr, int reg, u16 val) 3791da11f8SLennert Buytenhek { 3891da11f8SLennert Buytenhek struct dsa_switch *ds = bus->priv; 3991da11f8SLennert Buytenhek 400d8bcdd3SFlorian Fainelli if (ds->phys_mii_mask & (1 << addr)) 419d490b4eSVivien Didelot return ds->ops->phy_write(ds, addr, reg, val); 4291da11f8SLennert Buytenhek 4391da11f8SLennert Buytenhek return 0; 4491da11f8SLennert Buytenhek } 4591da11f8SLennert Buytenhek 4691da11f8SLennert Buytenhek void dsa_slave_mii_bus_init(struct dsa_switch *ds) 4791da11f8SLennert Buytenhek { 4891da11f8SLennert Buytenhek ds->slave_mii_bus->priv = (void *)ds; 4991da11f8SLennert Buytenhek ds->slave_mii_bus->name = "dsa slave smi"; 5091da11f8SLennert Buytenhek ds->slave_mii_bus->read = dsa_slave_phy_read; 5191da11f8SLennert Buytenhek ds->slave_mii_bus->write = dsa_slave_phy_write; 520b7b498dSFlorian Fainelli snprintf(ds->slave_mii_bus->id, MII_BUS_ID_SIZE, "dsa-%d.%d", 5349463b7fSVivien Didelot ds->dst->index, ds->index); 54c33063d6SAndrew Lunn ds->slave_mii_bus->parent = ds->dev; 5524df8986SVivien Didelot ds->slave_mii_bus->phy_mask = ~ds->phys_mii_mask; 5691da11f8SLennert Buytenhek } 5791da11f8SLennert Buytenhek 5891da11f8SLennert Buytenhek 5991da11f8SLennert Buytenhek /* slave device handling ****************************************************/ 60abd2be00SNicolas Dichtel static int dsa_slave_get_iflink(const struct net_device *dev) 61c0840801SLennert Buytenhek { 62d0006b00SVivien Didelot return dsa_slave_to_master(dev)->ifindex; 63c0840801SLennert Buytenhek } 64c0840801SLennert Buytenhek 6591da11f8SLennert Buytenhek static int dsa_slave_open(struct net_device *dev) 6691da11f8SLennert Buytenhek { 67d0006b00SVivien Didelot struct net_device *master = dsa_slave_to_master(dev); 68d945097bSVivien Didelot struct dsa_port *dp = dsa_slave_to_port(dev); 69df02c6ffSLennert Buytenhek int err; 70df02c6ffSLennert Buytenhek 71df02c6ffSLennert Buytenhek if (!(master->flags & IFF_UP)) 72df02c6ffSLennert Buytenhek return -ENETDOWN; 73df02c6ffSLennert Buytenhek 748feedbb4SJoe Perches if (!ether_addr_equal(dev->dev_addr, master->dev_addr)) { 75a748ee24SJiri Pirko err = dev_uc_add(master, dev->dev_addr); 76df02c6ffSLennert Buytenhek if (err < 0) 77df02c6ffSLennert Buytenhek goto out; 78df02c6ffSLennert Buytenhek } 79df02c6ffSLennert Buytenhek 80df02c6ffSLennert Buytenhek if (dev->flags & IFF_ALLMULTI) { 81df02c6ffSLennert Buytenhek err = dev_set_allmulti(master, 1); 82df02c6ffSLennert Buytenhek if (err < 0) 83df02c6ffSLennert Buytenhek goto del_unicast; 84df02c6ffSLennert Buytenhek } 85df02c6ffSLennert Buytenhek if (dev->flags & IFF_PROMISC) { 86df02c6ffSLennert Buytenhek err = dev_set_promiscuity(master, 1); 87df02c6ffSLennert Buytenhek if (err < 0) 88df02c6ffSLennert Buytenhek goto clear_allmulti; 89df02c6ffSLennert Buytenhek } 90df02c6ffSLennert Buytenhek 918640f8dcSRussell King err = dsa_port_enable_rt(dp, dev->phydev); 92b2f2af21SFlorian Fainelli if (err) 93b2f2af21SFlorian Fainelli goto clear_promisc; 94b73adef6SFlorian Fainelli 9591da11f8SLennert Buytenhek return 0; 96df02c6ffSLennert Buytenhek 97b2f2af21SFlorian Fainelli clear_promisc: 98b2f2af21SFlorian Fainelli if (dev->flags & IFF_PROMISC) 994fdeddfeSGilad Ben-Yossef dev_set_promiscuity(master, -1); 100df02c6ffSLennert Buytenhek clear_allmulti: 101df02c6ffSLennert Buytenhek if (dev->flags & IFF_ALLMULTI) 102df02c6ffSLennert Buytenhek dev_set_allmulti(master, -1); 103df02c6ffSLennert Buytenhek del_unicast: 1048feedbb4SJoe Perches if (!ether_addr_equal(dev->dev_addr, master->dev_addr)) 105a748ee24SJiri Pirko dev_uc_del(master, dev->dev_addr); 106df02c6ffSLennert Buytenhek out: 107df02c6ffSLennert Buytenhek return err; 10891da11f8SLennert Buytenhek } 10991da11f8SLennert Buytenhek 11091da11f8SLennert Buytenhek static int dsa_slave_close(struct net_device *dev) 11191da11f8SLennert Buytenhek { 112d0006b00SVivien Didelot struct net_device *master = dsa_slave_to_master(dev); 113d945097bSVivien Didelot struct dsa_port *dp = dsa_slave_to_port(dev); 114df02c6ffSLennert Buytenhek 1158640f8dcSRussell King dsa_port_disable_rt(dp); 1166457edfeSVivien Didelot 117df02c6ffSLennert Buytenhek dev_mc_unsync(master, dev); 118a748ee24SJiri Pirko dev_uc_unsync(master, dev); 119df02c6ffSLennert Buytenhek if (dev->flags & IFF_ALLMULTI) 120df02c6ffSLennert Buytenhek dev_set_allmulti(master, -1); 121df02c6ffSLennert Buytenhek if (dev->flags & IFF_PROMISC) 122df02c6ffSLennert Buytenhek dev_set_promiscuity(master, -1); 123df02c6ffSLennert Buytenhek 1248feedbb4SJoe Perches if (!ether_addr_equal(dev->dev_addr, master->dev_addr)) 125a748ee24SJiri Pirko dev_uc_del(master, dev->dev_addr); 126df02c6ffSLennert Buytenhek 12791da11f8SLennert Buytenhek return 0; 12891da11f8SLennert Buytenhek } 12991da11f8SLennert Buytenhek 13091da11f8SLennert Buytenhek static void dsa_slave_change_rx_flags(struct net_device *dev, int change) 13191da11f8SLennert Buytenhek { 132d0006b00SVivien Didelot struct net_device *master = dsa_slave_to_master(dev); 13317ab4f61SRundong Ge if (dev->flags & IFF_UP) { 13491da11f8SLennert Buytenhek if (change & IFF_ALLMULTI) 13517ab4f61SRundong Ge dev_set_allmulti(master, 13617ab4f61SRundong Ge dev->flags & IFF_ALLMULTI ? 1 : -1); 13791da11f8SLennert Buytenhek if (change & IFF_PROMISC) 13817ab4f61SRundong Ge dev_set_promiscuity(master, 13917ab4f61SRundong Ge dev->flags & IFF_PROMISC ? 1 : -1); 14017ab4f61SRundong Ge } 14191da11f8SLennert Buytenhek } 14291da11f8SLennert Buytenhek 14391da11f8SLennert Buytenhek static void dsa_slave_set_rx_mode(struct net_device *dev) 14491da11f8SLennert Buytenhek { 145d0006b00SVivien Didelot struct net_device *master = dsa_slave_to_master(dev); 14691da11f8SLennert Buytenhek 14791da11f8SLennert Buytenhek dev_mc_sync(master, dev); 148a748ee24SJiri Pirko dev_uc_sync(master, dev); 14991da11f8SLennert Buytenhek } 15091da11f8SLennert Buytenhek 151df02c6ffSLennert Buytenhek static int dsa_slave_set_mac_address(struct net_device *dev, void *a) 15291da11f8SLennert Buytenhek { 153d0006b00SVivien Didelot struct net_device *master = dsa_slave_to_master(dev); 154df02c6ffSLennert Buytenhek struct sockaddr *addr = a; 155df02c6ffSLennert Buytenhek int err; 156df02c6ffSLennert Buytenhek 157df02c6ffSLennert Buytenhek if (!is_valid_ether_addr(addr->sa_data)) 158df02c6ffSLennert Buytenhek return -EADDRNOTAVAIL; 159df02c6ffSLennert Buytenhek 160df02c6ffSLennert Buytenhek if (!(dev->flags & IFF_UP)) 161df02c6ffSLennert Buytenhek goto out; 162df02c6ffSLennert Buytenhek 1638feedbb4SJoe Perches if (!ether_addr_equal(addr->sa_data, master->dev_addr)) { 164a748ee24SJiri Pirko err = dev_uc_add(master, addr->sa_data); 165df02c6ffSLennert Buytenhek if (err < 0) 166df02c6ffSLennert Buytenhek return err; 167df02c6ffSLennert Buytenhek } 168df02c6ffSLennert Buytenhek 1698feedbb4SJoe Perches if (!ether_addr_equal(dev->dev_addr, master->dev_addr)) 170a748ee24SJiri Pirko dev_uc_del(master, dev->dev_addr); 171df02c6ffSLennert Buytenhek 172df02c6ffSLennert Buytenhek out: 173d08f161aSJoe Perches ether_addr_copy(dev->dev_addr, addr->sa_data); 17491da11f8SLennert Buytenhek 17591da11f8SLennert Buytenhek return 0; 17691da11f8SLennert Buytenhek } 17791da11f8SLennert Buytenhek 1782bedde1aSArkadi Sharshevsky struct dsa_slave_dump_ctx { 1792bedde1aSArkadi Sharshevsky struct net_device *dev; 1802bedde1aSArkadi Sharshevsky struct sk_buff *skb; 1812bedde1aSArkadi Sharshevsky struct netlink_callback *cb; 1822bedde1aSArkadi Sharshevsky int idx; 1832bedde1aSArkadi Sharshevsky }; 1842bedde1aSArkadi Sharshevsky 1852bedde1aSArkadi Sharshevsky static int 1862bedde1aSArkadi Sharshevsky dsa_slave_port_fdb_do_dump(const unsigned char *addr, u16 vid, 1872bedde1aSArkadi Sharshevsky bool is_static, void *data) 1882bedde1aSArkadi Sharshevsky { 1892bedde1aSArkadi Sharshevsky struct dsa_slave_dump_ctx *dump = data; 1902bedde1aSArkadi Sharshevsky u32 portid = NETLINK_CB(dump->cb->skb).portid; 1912bedde1aSArkadi Sharshevsky u32 seq = dump->cb->nlh->nlmsg_seq; 1922bedde1aSArkadi Sharshevsky struct nlmsghdr *nlh; 1932bedde1aSArkadi Sharshevsky struct ndmsg *ndm; 1942bedde1aSArkadi Sharshevsky 1952bedde1aSArkadi Sharshevsky if (dump->idx < dump->cb->args[2]) 1962bedde1aSArkadi Sharshevsky goto skip; 1972bedde1aSArkadi Sharshevsky 1982bedde1aSArkadi Sharshevsky nlh = nlmsg_put(dump->skb, portid, seq, RTM_NEWNEIGH, 1992bedde1aSArkadi Sharshevsky sizeof(*ndm), NLM_F_MULTI); 2002bedde1aSArkadi Sharshevsky if (!nlh) 2012bedde1aSArkadi Sharshevsky return -EMSGSIZE; 2022bedde1aSArkadi Sharshevsky 2032bedde1aSArkadi Sharshevsky ndm = nlmsg_data(nlh); 2042bedde1aSArkadi Sharshevsky ndm->ndm_family = AF_BRIDGE; 2052bedde1aSArkadi Sharshevsky ndm->ndm_pad1 = 0; 2062bedde1aSArkadi Sharshevsky ndm->ndm_pad2 = 0; 2072bedde1aSArkadi Sharshevsky ndm->ndm_flags = NTF_SELF; 2082bedde1aSArkadi Sharshevsky ndm->ndm_type = 0; 2092bedde1aSArkadi Sharshevsky ndm->ndm_ifindex = dump->dev->ifindex; 2102bedde1aSArkadi Sharshevsky ndm->ndm_state = is_static ? NUD_NOARP : NUD_REACHABLE; 2112bedde1aSArkadi Sharshevsky 2122bedde1aSArkadi Sharshevsky if (nla_put(dump->skb, NDA_LLADDR, ETH_ALEN, addr)) 2132bedde1aSArkadi Sharshevsky goto nla_put_failure; 2142bedde1aSArkadi Sharshevsky 2152bedde1aSArkadi Sharshevsky if (vid && nla_put_u16(dump->skb, NDA_VLAN, vid)) 2162bedde1aSArkadi Sharshevsky goto nla_put_failure; 2172bedde1aSArkadi Sharshevsky 2182bedde1aSArkadi Sharshevsky nlmsg_end(dump->skb, nlh); 2192bedde1aSArkadi Sharshevsky 2202bedde1aSArkadi Sharshevsky skip: 2212bedde1aSArkadi Sharshevsky dump->idx++; 2222bedde1aSArkadi Sharshevsky return 0; 2232bedde1aSArkadi Sharshevsky 2242bedde1aSArkadi Sharshevsky nla_put_failure: 2252bedde1aSArkadi Sharshevsky nlmsg_cancel(dump->skb, nlh); 2262bedde1aSArkadi Sharshevsky return -EMSGSIZE; 2272bedde1aSArkadi Sharshevsky } 2282bedde1aSArkadi Sharshevsky 2292bedde1aSArkadi Sharshevsky static int 2302bedde1aSArkadi Sharshevsky dsa_slave_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb, 2312bedde1aSArkadi Sharshevsky struct net_device *dev, struct net_device *filter_dev, 2322bedde1aSArkadi Sharshevsky int *idx) 2332bedde1aSArkadi Sharshevsky { 234d945097bSVivien Didelot struct dsa_port *dp = dsa_slave_to_port(dev); 2352bedde1aSArkadi Sharshevsky struct dsa_slave_dump_ctx dump = { 2362bedde1aSArkadi Sharshevsky .dev = dev, 2372bedde1aSArkadi Sharshevsky .skb = skb, 2382bedde1aSArkadi Sharshevsky .cb = cb, 2392bedde1aSArkadi Sharshevsky .idx = *idx, 2402bedde1aSArkadi Sharshevsky }; 2412bedde1aSArkadi Sharshevsky int err; 2422bedde1aSArkadi Sharshevsky 243de40fc5dSVivien Didelot err = dsa_port_fdb_dump(dp, dsa_slave_port_fdb_do_dump, &dump); 2442bedde1aSArkadi Sharshevsky *idx = dump.idx; 245de40fc5dSVivien Didelot 2462bedde1aSArkadi Sharshevsky return err; 2472bedde1aSArkadi Sharshevsky } 2482bedde1aSArkadi Sharshevsky 24991da11f8SLennert Buytenhek static int dsa_slave_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) 25091da11f8SLennert Buytenhek { 2510336369dSBrandon Streiff struct dsa_slave_priv *p = netdev_priv(dev); 2520336369dSBrandon Streiff struct dsa_switch *ds = p->dp->ds; 2530336369dSBrandon Streiff int port = p->dp->index; 2540336369dSBrandon Streiff 2550336369dSBrandon Streiff /* Pass through to switch driver if it supports timestamping */ 2560336369dSBrandon Streiff switch (cmd) { 2570336369dSBrandon Streiff case SIOCGHWTSTAMP: 2580336369dSBrandon Streiff if (ds->ops->port_hwtstamp_get) 2590336369dSBrandon Streiff return ds->ops->port_hwtstamp_get(ds, port, ifr); 2600336369dSBrandon Streiff break; 2610336369dSBrandon Streiff case SIOCSHWTSTAMP: 2620336369dSBrandon Streiff if (ds->ops->port_hwtstamp_set) 2630336369dSBrandon Streiff return ds->ops->port_hwtstamp_set(ds, port, ifr); 2640336369dSBrandon Streiff break; 2650336369dSBrandon Streiff } 2660336369dSBrandon Streiff 267aab9c406SFlorian Fainelli return phylink_mii_ioctl(p->dp->pl, ifr, cmd); 26891da11f8SLennert Buytenhek } 26991da11f8SLennert Buytenhek 27035636062SScott Feldman static int dsa_slave_port_attr_set(struct net_device *dev, 271f7fadf30SJiri Pirko const struct switchdev_attr *attr, 2727ea6eb3fSJiri Pirko struct switchdev_trans *trans) 27335636062SScott Feldman { 274d945097bSVivien Didelot struct dsa_port *dp = dsa_slave_to_port(dev); 275b8d866acSVivien Didelot int ret; 27635636062SScott Feldman 27735636062SScott Feldman switch (attr->id) { 2781f868398SJiri Pirko case SWITCHDEV_ATTR_ID_PORT_STP_STATE: 279fd364541SVivien Didelot ret = dsa_port_set_state(dp, attr->u.stp_state, trans); 28035636062SScott Feldman break; 281fb2dabadSVivien Didelot case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING: 282c02c4175SVivien Didelot ret = dsa_port_vlan_filtering(dp, attr->u.vlan_filtering, 283c02c4175SVivien Didelot trans); 284fb2dabadSVivien Didelot break; 28534a79f63SVivien Didelot case SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME: 286072bb190SVivien Didelot ret = dsa_port_ageing_time(dp, attr->u.ageing_time, trans); 28734a79f63SVivien Didelot break; 288ea87005aSFlorian Fainelli case SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS: 289ea87005aSFlorian Fainelli ret = dsa_port_pre_bridge_flags(dp, attr->u.brport_flags, 290ea87005aSFlorian Fainelli trans); 291ea87005aSFlorian Fainelli break; 29257652796SRussell King case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS: 29357652796SRussell King ret = dsa_port_bridge_flags(dp, attr->u.brport_flags, trans); 29457652796SRussell King break; 29508cc83ccSVivien Didelot case SWITCHDEV_ATTR_ID_BRIDGE_MROUTER: 29608cc83ccSVivien Didelot ret = dsa_port_mrouter(dp->cpu_dp, attr->u.mrouter, trans); 29708cc83ccSVivien Didelot break; 29835636062SScott Feldman default: 29935636062SScott Feldman ret = -EOPNOTSUPP; 30035636062SScott Feldman break; 30135636062SScott Feldman } 30235636062SScott Feldman 30335636062SScott Feldman return ret; 30435636062SScott Feldman } 30535636062SScott Feldman 306bdcff080SVivien Didelot static int dsa_slave_vlan_add(struct net_device *dev, 307bdcff080SVivien Didelot const struct switchdev_obj *obj, 308bdcff080SVivien Didelot struct switchdev_trans *trans) 309bdcff080SVivien Didelot { 310bdcff080SVivien Didelot struct dsa_port *dp = dsa_slave_to_port(dev); 311bdcff080SVivien Didelot struct switchdev_obj_port_vlan vlan; 312bdcff080SVivien Didelot int err; 313bdcff080SVivien Didelot 314bdcff080SVivien Didelot if (obj->orig_dev != dev) 315bdcff080SVivien Didelot return -EOPNOTSUPP; 316bdcff080SVivien Didelot 317c5335d73SVivien Didelot if (dp->bridge_dev && !br_vlan_enabled(dp->bridge_dev)) 318c5335d73SVivien Didelot return 0; 319c5335d73SVivien Didelot 320bdcff080SVivien Didelot vlan = *SWITCHDEV_OBJ_PORT_VLAN(obj); 321bdcff080SVivien Didelot 322bdcff080SVivien Didelot err = dsa_port_vlan_add(dp, &vlan, trans); 323bdcff080SVivien Didelot if (err) 324bdcff080SVivien Didelot return err; 325bdcff080SVivien Didelot 326b9499904SVivien Didelot /* We need the dedicated CPU port to be a member of the VLAN as well. 327b9499904SVivien Didelot * Even though drivers often handle CPU membership in special ways, 328b9499904SVivien Didelot * it doesn't make sense to program a PVID, so clear this flag. 329b9499904SVivien Didelot */ 330b9499904SVivien Didelot vlan.flags &= ~BRIDGE_VLAN_INFO_PVID; 331b9499904SVivien Didelot 3327e1741b4SVivien Didelot err = dsa_port_vlan_add(dp->cpu_dp, &vlan, trans); 3337e1741b4SVivien Didelot if (err) 3347e1741b4SVivien Didelot return err; 3357e1741b4SVivien Didelot 336bdcff080SVivien Didelot return 0; 337bdcff080SVivien Didelot } 338bdcff080SVivien Didelot 339ba14d9ebSVivien Didelot static int dsa_slave_port_obj_add(struct net_device *dev, 340648b4a99SJiri Pirko const struct switchdev_obj *obj, 34179b139f4SVivien Didelot struct switchdev_trans *trans, 34279b139f4SVivien Didelot struct netlink_ext_ack *extack) 343ba14d9ebSVivien Didelot { 344d945097bSVivien Didelot struct dsa_port *dp = dsa_slave_to_port(dev); 345ba14d9ebSVivien Didelot int err; 346ba14d9ebSVivien Didelot 347ba14d9ebSVivien Didelot /* For the prepare phase, ensure the full set of changes is feasable in 348ba14d9ebSVivien Didelot * one go in order to signal a failure properly. If an operation is not 349ba14d9ebSVivien Didelot * supported, return -EOPNOTSUPP. 350ba14d9ebSVivien Didelot */ 351ba14d9ebSVivien Didelot 3529e8f4a54SJiri Pirko switch (obj->id) { 3538df30255SVivien Didelot case SWITCHDEV_OBJ_ID_PORT_MDB: 35479b139f4SVivien Didelot if (obj->orig_dev != dev) 35579b139f4SVivien Didelot return -EOPNOTSUPP; 356bcebb976SVivien Didelot err = dsa_port_mdb_add(dp, SWITCHDEV_OBJ_PORT_MDB(obj), trans); 3578df30255SVivien Didelot break; 3585f4dbc50SAndrew Lunn case SWITCHDEV_OBJ_ID_HOST_MDB: 3595f4dbc50SAndrew Lunn /* DSA can directly translate this to a normal MDB add, 3605f4dbc50SAndrew Lunn * but on the CPU port. 3615f4dbc50SAndrew Lunn */ 3625f4dbc50SAndrew Lunn err = dsa_port_mdb_add(dp->cpu_dp, SWITCHDEV_OBJ_PORT_MDB(obj), 3635f4dbc50SAndrew Lunn trans); 3645f4dbc50SAndrew Lunn break; 36557d80838SJiri Pirko case SWITCHDEV_OBJ_ID_PORT_VLAN: 366bdcff080SVivien Didelot err = dsa_slave_vlan_add(dev, obj, trans); 36711149536SVivien Didelot break; 368ba14d9ebSVivien Didelot default: 369ba14d9ebSVivien Didelot err = -EOPNOTSUPP; 370ba14d9ebSVivien Didelot break; 371ba14d9ebSVivien Didelot } 372ba14d9ebSVivien Didelot 373ba14d9ebSVivien Didelot return err; 374ba14d9ebSVivien Didelot } 375ba14d9ebSVivien Didelot 376bdcff080SVivien Didelot static int dsa_slave_vlan_del(struct net_device *dev, 377bdcff080SVivien Didelot const struct switchdev_obj *obj) 378bdcff080SVivien Didelot { 379bdcff080SVivien Didelot struct dsa_port *dp = dsa_slave_to_port(dev); 380bdcff080SVivien Didelot 381bdcff080SVivien Didelot if (obj->orig_dev != dev) 382bdcff080SVivien Didelot return -EOPNOTSUPP; 383bdcff080SVivien Didelot 384c5335d73SVivien Didelot if (dp->bridge_dev && !br_vlan_enabled(dp->bridge_dev)) 385c5335d73SVivien Didelot return 0; 386c5335d73SVivien Didelot 3877e1741b4SVivien Didelot /* Do not deprogram the CPU port as it may be shared with other user 3887e1741b4SVivien Didelot * ports which can be members of this VLAN as well. 3897e1741b4SVivien Didelot */ 390bdcff080SVivien Didelot return dsa_port_vlan_del(dp, SWITCHDEV_OBJ_PORT_VLAN(obj)); 391bdcff080SVivien Didelot } 392bdcff080SVivien Didelot 393ba14d9ebSVivien Didelot static int dsa_slave_port_obj_del(struct net_device *dev, 394648b4a99SJiri Pirko const struct switchdev_obj *obj) 395ba14d9ebSVivien Didelot { 396d945097bSVivien Didelot struct dsa_port *dp = dsa_slave_to_port(dev); 397ba14d9ebSVivien Didelot int err; 398ba14d9ebSVivien Didelot 3999e8f4a54SJiri Pirko switch (obj->id) { 4008df30255SVivien Didelot case SWITCHDEV_OBJ_ID_PORT_MDB: 40179b139f4SVivien Didelot if (obj->orig_dev != dev) 40279b139f4SVivien Didelot return -EOPNOTSUPP; 403bcebb976SVivien Didelot err = dsa_port_mdb_del(dp, SWITCHDEV_OBJ_PORT_MDB(obj)); 4048df30255SVivien Didelot break; 4055f4dbc50SAndrew Lunn case SWITCHDEV_OBJ_ID_HOST_MDB: 4065f4dbc50SAndrew Lunn /* DSA can directly translate this to a normal MDB add, 4075f4dbc50SAndrew Lunn * but on the CPU port. 4085f4dbc50SAndrew Lunn */ 4095f4dbc50SAndrew Lunn err = dsa_port_mdb_del(dp->cpu_dp, SWITCHDEV_OBJ_PORT_MDB(obj)); 4105f4dbc50SAndrew Lunn break; 41157d80838SJiri Pirko case SWITCHDEV_OBJ_ID_PORT_VLAN: 412bdcff080SVivien Didelot err = dsa_slave_vlan_del(dev, obj); 41311149536SVivien Didelot break; 414ba14d9ebSVivien Didelot default: 415ba14d9ebSVivien Didelot err = -EOPNOTSUPP; 416ba14d9ebSVivien Didelot break; 417ba14d9ebSVivien Didelot } 418ba14d9ebSVivien Didelot 419ba14d9ebSVivien Didelot return err; 420ba14d9ebSVivien Didelot } 421ba14d9ebSVivien Didelot 422929d6c14SFlorian Fainelli static int dsa_slave_get_port_parent_id(struct net_device *dev, 423929d6c14SFlorian Fainelli struct netdev_phys_item_id *ppid) 424b73adef6SFlorian Fainelli { 425d945097bSVivien Didelot struct dsa_port *dp = dsa_slave_to_port(dev); 426d945097bSVivien Didelot struct dsa_switch *ds = dp->ds; 427a42c8e33SAndrew Lunn struct dsa_switch_tree *dst = ds->dst; 428b73adef6SFlorian Fainelli 42915b04aceSJiri Pirko /* For non-legacy ports, devlink is used and it takes 43015b04aceSJiri Pirko * care of the name generation. This ndo implementation 43115b04aceSJiri Pirko * should be removed with legacy support. 43215b04aceSJiri Pirko */ 43315b04aceSJiri Pirko if (dp->ds->devlink) 43415b04aceSJiri Pirko return -EOPNOTSUPP; 43515b04aceSJiri Pirko 436929d6c14SFlorian Fainelli ppid->id_len = sizeof(dst->index); 437929d6c14SFlorian Fainelli memcpy(&ppid->id, &dst->index, ppid->id_len); 438929d6c14SFlorian Fainelli 439929d6c14SFlorian Fainelli return 0; 440929d6c14SFlorian Fainelli } 441929d6c14SFlorian Fainelli 4424fa7b718SVivien Didelot static inline netdev_tx_t dsa_slave_netpoll_send_skb(struct net_device *dev, 44304ff53f9SFlorian Fainelli struct sk_buff *skb) 44404ff53f9SFlorian Fainelli { 44504ff53f9SFlorian Fainelli #ifdef CONFIG_NET_POLL_CONTROLLER 4464fa7b718SVivien Didelot struct dsa_slave_priv *p = netdev_priv(dev); 4474fa7b718SVivien Didelot 44804ff53f9SFlorian Fainelli if (p->netpoll) 44904ff53f9SFlorian Fainelli netpoll_send_skb(p->netpoll, skb); 45004ff53f9SFlorian Fainelli #else 45104ff53f9SFlorian Fainelli BUG(); 45204ff53f9SFlorian Fainelli #endif 45304ff53f9SFlorian Fainelli return NETDEV_TX_OK; 45404ff53f9SFlorian Fainelli } 45504ff53f9SFlorian Fainelli 45690af1059SBrandon Streiff static void dsa_skb_tx_timestamp(struct dsa_slave_priv *p, 45790af1059SBrandon Streiff struct sk_buff *skb) 45890af1059SBrandon Streiff { 45990af1059SBrandon Streiff struct dsa_switch *ds = p->dp->ds; 46090af1059SBrandon Streiff struct sk_buff *clone; 46190af1059SBrandon Streiff unsigned int type; 46290af1059SBrandon Streiff 46390af1059SBrandon Streiff type = ptp_classify_raw(skb); 46490af1059SBrandon Streiff if (type == PTP_CLASS_NONE) 46590af1059SBrandon Streiff return; 46690af1059SBrandon Streiff 46790af1059SBrandon Streiff if (!ds->ops->port_txtstamp) 46890af1059SBrandon Streiff return; 46990af1059SBrandon Streiff 47090af1059SBrandon Streiff clone = skb_clone_sk(skb); 47190af1059SBrandon Streiff if (!clone) 47290af1059SBrandon Streiff return; 47390af1059SBrandon Streiff 474146d442cSVladimir Oltean DSA_SKB_CB(skb)->clone = clone; 475146d442cSVladimir Oltean 47690af1059SBrandon Streiff if (ds->ops->port_txtstamp(ds, p->dp->index, clone, type)) 47790af1059SBrandon Streiff return; 47890af1059SBrandon Streiff 47990af1059SBrandon Streiff kfree_skb(clone); 48090af1059SBrandon Streiff } 48190af1059SBrandon Streiff 48297a69a0dSVladimir Oltean netdev_tx_t dsa_enqueue_skb(struct sk_buff *skb, struct net_device *dev) 48397a69a0dSVladimir Oltean { 48497a69a0dSVladimir Oltean /* SKB for netpoll still need to be mangled with the protocol-specific 48597a69a0dSVladimir Oltean * tag to be successfully transmitted 48697a69a0dSVladimir Oltean */ 48797a69a0dSVladimir Oltean if (unlikely(netpoll_tx_running(dev))) 48897a69a0dSVladimir Oltean return dsa_slave_netpoll_send_skb(dev, skb); 48997a69a0dSVladimir Oltean 49097a69a0dSVladimir Oltean /* Queue the SKB for transmission on the parent interface, but 49197a69a0dSVladimir Oltean * do not modify its EtherType 49297a69a0dSVladimir Oltean */ 49397a69a0dSVladimir Oltean skb->dev = dsa_slave_to_master(dev); 49497a69a0dSVladimir Oltean dev_queue_xmit(skb); 49597a69a0dSVladimir Oltean 49697a69a0dSVladimir Oltean return NETDEV_TX_OK; 49797a69a0dSVladimir Oltean } 49897a69a0dSVladimir Oltean EXPORT_SYMBOL_GPL(dsa_enqueue_skb); 49997a69a0dSVladimir Oltean 5003e8a72d1SFlorian Fainelli static netdev_tx_t dsa_slave_xmit(struct sk_buff *skb, struct net_device *dev) 5013e8a72d1SFlorian Fainelli { 5023e8a72d1SFlorian Fainelli struct dsa_slave_priv *p = netdev_priv(dev); 5035f6b4e14SFlorian Fainelli struct pcpu_sw_netstats *s; 5044ed70ce9SFlorian Fainelli struct sk_buff *nskb; 5053e8a72d1SFlorian Fainelli 5065f6b4e14SFlorian Fainelli s = this_cpu_ptr(p->stats64); 5075f6b4e14SFlorian Fainelli u64_stats_update_begin(&s->syncp); 5085f6b4e14SFlorian Fainelli s->tx_packets++; 5095f6b4e14SFlorian Fainelli s->tx_bytes += skb->len; 5105f6b4e14SFlorian Fainelli u64_stats_update_end(&s->syncp); 5113e8a72d1SFlorian Fainelli 512146d442cSVladimir Oltean DSA_SKB_CB(skb)->clone = NULL; 51387671375SVladimir Oltean 51490af1059SBrandon Streiff /* Identify PTP protocol packets, clone them, and pass them to the 51590af1059SBrandon Streiff * switch driver 51690af1059SBrandon Streiff */ 51790af1059SBrandon Streiff dsa_skb_tx_timestamp(p, skb); 51890af1059SBrandon Streiff 519fe47d563SVivien Didelot /* Transmit function may have to reallocate the original SKB, 520fe47d563SVivien Didelot * in which case it must have freed it. Only free it here on error. 521fe47d563SVivien Didelot */ 5224ed70ce9SFlorian Fainelli nskb = p->xmit(skb, dev); 523fe47d563SVivien Didelot if (!nskb) { 524fe47d563SVivien Didelot kfree_skb(skb); 5254ed70ce9SFlorian Fainelli return NETDEV_TX_OK; 526fe47d563SVivien Didelot } 5275aed85ceSFlorian Fainelli 52897a69a0dSVladimir Oltean return dsa_enqueue_skb(nskb, dev); 52997a69a0dSVladimir Oltean } 53004ff53f9SFlorian Fainelli 53191da11f8SLennert Buytenhek /* ethtool operations *******************************************************/ 53291da11f8SLennert Buytenhek 53391da11f8SLennert Buytenhek static void dsa_slave_get_drvinfo(struct net_device *dev, 53491da11f8SLennert Buytenhek struct ethtool_drvinfo *drvinfo) 53591da11f8SLennert Buytenhek { 5367826d43fSJiri Pirko strlcpy(drvinfo->driver, "dsa", sizeof(drvinfo->driver)); 5377826d43fSJiri Pirko strlcpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version)); 5387826d43fSJiri Pirko strlcpy(drvinfo->bus_info, "platform", sizeof(drvinfo->bus_info)); 53991da11f8SLennert Buytenhek } 54091da11f8SLennert Buytenhek 5413d762a0fSGuenter Roeck static int dsa_slave_get_regs_len(struct net_device *dev) 5423d762a0fSGuenter Roeck { 543d945097bSVivien Didelot struct dsa_port *dp = dsa_slave_to_port(dev); 544d945097bSVivien Didelot struct dsa_switch *ds = dp->ds; 5453d762a0fSGuenter Roeck 5469d490b4eSVivien Didelot if (ds->ops->get_regs_len) 547d945097bSVivien Didelot return ds->ops->get_regs_len(ds, dp->index); 5483d762a0fSGuenter Roeck 5493d762a0fSGuenter Roeck return -EOPNOTSUPP; 5503d762a0fSGuenter Roeck } 5513d762a0fSGuenter Roeck 5523d762a0fSGuenter Roeck static void 5533d762a0fSGuenter Roeck dsa_slave_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *_p) 5543d762a0fSGuenter Roeck { 555d945097bSVivien Didelot struct dsa_port *dp = dsa_slave_to_port(dev); 556d945097bSVivien Didelot struct dsa_switch *ds = dp->ds; 5573d762a0fSGuenter Roeck 5589d490b4eSVivien Didelot if (ds->ops->get_regs) 559d945097bSVivien Didelot ds->ops->get_regs(ds, dp->index, regs, _p); 5603d762a0fSGuenter Roeck } 5613d762a0fSGuenter Roeck 562aab9c406SFlorian Fainelli static int dsa_slave_nway_reset(struct net_device *dev) 563aab9c406SFlorian Fainelli { 564aab9c406SFlorian Fainelli struct dsa_port *dp = dsa_slave_to_port(dev); 565aab9c406SFlorian Fainelli 566aab9c406SFlorian Fainelli return phylink_ethtool_nway_reset(dp->pl); 567aab9c406SFlorian Fainelli } 568aab9c406SFlorian Fainelli 5696793abb4SGuenter Roeck static int dsa_slave_get_eeprom_len(struct net_device *dev) 5706793abb4SGuenter Roeck { 571d945097bSVivien Didelot struct dsa_port *dp = dsa_slave_to_port(dev); 572d945097bSVivien Didelot struct dsa_switch *ds = dp->ds; 5736793abb4SGuenter Roeck 5740e576044SAndrew Lunn if (ds->cd && ds->cd->eeprom_len) 575ff04955cSAndrew Lunn return ds->cd->eeprom_len; 5766793abb4SGuenter Roeck 5779d490b4eSVivien Didelot if (ds->ops->get_eeprom_len) 5789d490b4eSVivien Didelot return ds->ops->get_eeprom_len(ds); 5796793abb4SGuenter Roeck 5806793abb4SGuenter Roeck return 0; 5816793abb4SGuenter Roeck } 5826793abb4SGuenter Roeck 5836793abb4SGuenter Roeck static int dsa_slave_get_eeprom(struct net_device *dev, 5846793abb4SGuenter Roeck struct ethtool_eeprom *eeprom, u8 *data) 5856793abb4SGuenter Roeck { 586d945097bSVivien Didelot struct dsa_port *dp = dsa_slave_to_port(dev); 587d945097bSVivien Didelot struct dsa_switch *ds = dp->ds; 5886793abb4SGuenter Roeck 5899d490b4eSVivien Didelot if (ds->ops->get_eeprom) 5909d490b4eSVivien Didelot return ds->ops->get_eeprom(ds, eeprom, data); 5916793abb4SGuenter Roeck 5926793abb4SGuenter Roeck return -EOPNOTSUPP; 5936793abb4SGuenter Roeck } 5946793abb4SGuenter Roeck 5956793abb4SGuenter Roeck static int dsa_slave_set_eeprom(struct net_device *dev, 5966793abb4SGuenter Roeck struct ethtool_eeprom *eeprom, u8 *data) 5976793abb4SGuenter Roeck { 598d945097bSVivien Didelot struct dsa_port *dp = dsa_slave_to_port(dev); 599d945097bSVivien Didelot struct dsa_switch *ds = dp->ds; 6006793abb4SGuenter Roeck 6019d490b4eSVivien Didelot if (ds->ops->set_eeprom) 6029d490b4eSVivien Didelot return ds->ops->set_eeprom(ds, eeprom, data); 6036793abb4SGuenter Roeck 6046793abb4SGuenter Roeck return -EOPNOTSUPP; 6056793abb4SGuenter Roeck } 6066793abb4SGuenter Roeck 60791da11f8SLennert Buytenhek static void dsa_slave_get_strings(struct net_device *dev, 60891da11f8SLennert Buytenhek uint32_t stringset, uint8_t *data) 60991da11f8SLennert Buytenhek { 610d945097bSVivien Didelot struct dsa_port *dp = dsa_slave_to_port(dev); 611d945097bSVivien Didelot struct dsa_switch *ds = dp->ds; 61291da11f8SLennert Buytenhek 61391da11f8SLennert Buytenhek if (stringset == ETH_SS_STATS) { 61491da11f8SLennert Buytenhek int len = ETH_GSTRING_LEN; 61591da11f8SLennert Buytenhek 61691da11f8SLennert Buytenhek strncpy(data, "tx_packets", len); 61791da11f8SLennert Buytenhek strncpy(data + len, "tx_bytes", len); 61891da11f8SLennert Buytenhek strncpy(data + 2 * len, "rx_packets", len); 61991da11f8SLennert Buytenhek strncpy(data + 3 * len, "rx_bytes", len); 6209d490b4eSVivien Didelot if (ds->ops->get_strings) 62189f09048SFlorian Fainelli ds->ops->get_strings(ds, dp->index, stringset, 62289f09048SFlorian Fainelli data + 4 * len); 62391da11f8SLennert Buytenhek } 62491da11f8SLennert Buytenhek } 62591da11f8SLennert Buytenhek 62691da11f8SLennert Buytenhek static void dsa_slave_get_ethtool_stats(struct net_device *dev, 62791da11f8SLennert Buytenhek struct ethtool_stats *stats, 62891da11f8SLennert Buytenhek uint64_t *data) 62991da11f8SLennert Buytenhek { 630d945097bSVivien Didelot struct dsa_port *dp = dsa_slave_to_port(dev); 63191da11f8SLennert Buytenhek struct dsa_slave_priv *p = netdev_priv(dev); 632d945097bSVivien Didelot struct dsa_switch *ds = dp->ds; 6335f6b4e14SFlorian Fainelli struct pcpu_sw_netstats *s; 634f613ed66SFlorian Fainelli unsigned int start; 6355f6b4e14SFlorian Fainelli int i; 63691da11f8SLennert Buytenhek 6375f6b4e14SFlorian Fainelli for_each_possible_cpu(i) { 6385f6b4e14SFlorian Fainelli u64 tx_packets, tx_bytes, rx_packets, rx_bytes; 6395f6b4e14SFlorian Fainelli 6405f6b4e14SFlorian Fainelli s = per_cpu_ptr(p->stats64, i); 641f613ed66SFlorian Fainelli do { 6425f6b4e14SFlorian Fainelli start = u64_stats_fetch_begin_irq(&s->syncp); 6435f6b4e14SFlorian Fainelli tx_packets = s->tx_packets; 6445f6b4e14SFlorian Fainelli tx_bytes = s->tx_bytes; 6455f6b4e14SFlorian Fainelli rx_packets = s->rx_packets; 6465f6b4e14SFlorian Fainelli rx_bytes = s->rx_bytes; 6475f6b4e14SFlorian Fainelli } while (u64_stats_fetch_retry_irq(&s->syncp, start)); 6485f6b4e14SFlorian Fainelli data[0] += tx_packets; 6495f6b4e14SFlorian Fainelli data[1] += tx_bytes; 6505f6b4e14SFlorian Fainelli data[2] += rx_packets; 6515f6b4e14SFlorian Fainelli data[3] += rx_bytes; 6525f6b4e14SFlorian Fainelli } 6539d490b4eSVivien Didelot if (ds->ops->get_ethtool_stats) 654d945097bSVivien Didelot ds->ops->get_ethtool_stats(ds, dp->index, data + 4); 65591da11f8SLennert Buytenhek } 65691da11f8SLennert Buytenhek 65791da11f8SLennert Buytenhek static int dsa_slave_get_sset_count(struct net_device *dev, int sset) 65891da11f8SLennert Buytenhek { 659d945097bSVivien Didelot struct dsa_port *dp = dsa_slave_to_port(dev); 660d945097bSVivien Didelot struct dsa_switch *ds = dp->ds; 66191da11f8SLennert Buytenhek 66291da11f8SLennert Buytenhek if (sset == ETH_SS_STATS) { 66391da11f8SLennert Buytenhek int count; 66491da11f8SLennert Buytenhek 66591da11f8SLennert Buytenhek count = 4; 6669d490b4eSVivien Didelot if (ds->ops->get_sset_count) 66789f09048SFlorian Fainelli count += ds->ops->get_sset_count(ds, dp->index, sset); 66891da11f8SLennert Buytenhek 66991da11f8SLennert Buytenhek return count; 67091da11f8SLennert Buytenhek } 67191da11f8SLennert Buytenhek 67291da11f8SLennert Buytenhek return -EOPNOTSUPP; 67391da11f8SLennert Buytenhek } 67491da11f8SLennert Buytenhek 67519e57c4eSFlorian Fainelli static void dsa_slave_get_wol(struct net_device *dev, struct ethtool_wolinfo *w) 67619e57c4eSFlorian Fainelli { 677d945097bSVivien Didelot struct dsa_port *dp = dsa_slave_to_port(dev); 678d945097bSVivien Didelot struct dsa_switch *ds = dp->ds; 67919e57c4eSFlorian Fainelli 680aab9c406SFlorian Fainelli phylink_ethtool_get_wol(dp->pl, w); 681aab9c406SFlorian Fainelli 6829d490b4eSVivien Didelot if (ds->ops->get_wol) 683d945097bSVivien Didelot ds->ops->get_wol(ds, dp->index, w); 68419e57c4eSFlorian Fainelli } 68519e57c4eSFlorian Fainelli 68619e57c4eSFlorian Fainelli static int dsa_slave_set_wol(struct net_device *dev, struct ethtool_wolinfo *w) 68719e57c4eSFlorian Fainelli { 688d945097bSVivien Didelot struct dsa_port *dp = dsa_slave_to_port(dev); 689d945097bSVivien Didelot struct dsa_switch *ds = dp->ds; 69019e57c4eSFlorian Fainelli int ret = -EOPNOTSUPP; 69119e57c4eSFlorian Fainelli 692aab9c406SFlorian Fainelli phylink_ethtool_set_wol(dp->pl, w); 693aab9c406SFlorian Fainelli 6949d490b4eSVivien Didelot if (ds->ops->set_wol) 695d945097bSVivien Didelot ret = ds->ops->set_wol(ds, dp->index, w); 69619e57c4eSFlorian Fainelli 69719e57c4eSFlorian Fainelli return ret; 69819e57c4eSFlorian Fainelli } 69919e57c4eSFlorian Fainelli 7007905288fSFlorian Fainelli static int dsa_slave_set_eee(struct net_device *dev, struct ethtool_eee *e) 7017905288fSFlorian Fainelli { 702d945097bSVivien Didelot struct dsa_port *dp = dsa_slave_to_port(dev); 703d945097bSVivien Didelot struct dsa_switch *ds = dp->ds; 7047905288fSFlorian Fainelli int ret; 7057905288fSFlorian Fainelli 7067b9cc738SVivien Didelot /* Port's PHY and MAC both need to be EEE capable */ 70700670cb8SDan Carpenter if (!dev->phydev || !dp->pl) 7087b9cc738SVivien Didelot return -ENODEV; 7097b9cc738SVivien Didelot 71008f50061SVivien Didelot if (!ds->ops->set_mac_eee) 7117905288fSFlorian Fainelli return -EOPNOTSUPP; 7127905288fSFlorian Fainelli 713d945097bSVivien Didelot ret = ds->ops->set_mac_eee(ds, dp->index, e); 7147905288fSFlorian Fainelli if (ret) 7157905288fSFlorian Fainelli return ret; 7167905288fSFlorian Fainelli 717aab9c406SFlorian Fainelli return phylink_ethtool_set_eee(dp->pl, e); 7187905288fSFlorian Fainelli } 7197905288fSFlorian Fainelli 7207905288fSFlorian Fainelli static int dsa_slave_get_eee(struct net_device *dev, struct ethtool_eee *e) 7217905288fSFlorian Fainelli { 722d945097bSVivien Didelot struct dsa_port *dp = dsa_slave_to_port(dev); 723d945097bSVivien Didelot struct dsa_switch *ds = dp->ds; 7247905288fSFlorian Fainelli int ret; 7257905288fSFlorian Fainelli 7267b9cc738SVivien Didelot /* Port's PHY and MAC both need to be EEE capable */ 72700670cb8SDan Carpenter if (!dev->phydev || !dp->pl) 7287b9cc738SVivien Didelot return -ENODEV; 7297b9cc738SVivien Didelot 73008f50061SVivien Didelot if (!ds->ops->get_mac_eee) 7317905288fSFlorian Fainelli return -EOPNOTSUPP; 7327905288fSFlorian Fainelli 733d945097bSVivien Didelot ret = ds->ops->get_mac_eee(ds, dp->index, e); 7347905288fSFlorian Fainelli if (ret) 7357905288fSFlorian Fainelli return ret; 7367905288fSFlorian Fainelli 737aab9c406SFlorian Fainelli return phylink_ethtool_get_eee(dp->pl, e); 738aab9c406SFlorian Fainelli } 739aab9c406SFlorian Fainelli 740aab9c406SFlorian Fainelli static int dsa_slave_get_link_ksettings(struct net_device *dev, 741aab9c406SFlorian Fainelli struct ethtool_link_ksettings *cmd) 742aab9c406SFlorian Fainelli { 743aab9c406SFlorian Fainelli struct dsa_port *dp = dsa_slave_to_port(dev); 744aab9c406SFlorian Fainelli 745aab9c406SFlorian Fainelli return phylink_ethtool_ksettings_get(dp->pl, cmd); 746aab9c406SFlorian Fainelli } 747aab9c406SFlorian Fainelli 748aab9c406SFlorian Fainelli static int dsa_slave_set_link_ksettings(struct net_device *dev, 749aab9c406SFlorian Fainelli const struct ethtool_link_ksettings *cmd) 750aab9c406SFlorian Fainelli { 751aab9c406SFlorian Fainelli struct dsa_port *dp = dsa_slave_to_port(dev); 752aab9c406SFlorian Fainelli 753aab9c406SFlorian Fainelli return phylink_ethtool_ksettings_set(dp->pl, cmd); 7547905288fSFlorian Fainelli } 7557905288fSFlorian Fainelli 756a2a1a13bSHeiner Kallweit static void dsa_slave_get_pauseparam(struct net_device *dev, 757a2a1a13bSHeiner Kallweit struct ethtool_pauseparam *pause) 758a2a1a13bSHeiner Kallweit { 759a2a1a13bSHeiner Kallweit struct dsa_port *dp = dsa_slave_to_port(dev); 760a2a1a13bSHeiner Kallweit 761a2a1a13bSHeiner Kallweit phylink_ethtool_get_pauseparam(dp->pl, pause); 762a2a1a13bSHeiner Kallweit } 763a2a1a13bSHeiner Kallweit 764a2a1a13bSHeiner Kallweit static int dsa_slave_set_pauseparam(struct net_device *dev, 765a2a1a13bSHeiner Kallweit struct ethtool_pauseparam *pause) 766a2a1a13bSHeiner Kallweit { 767a2a1a13bSHeiner Kallweit struct dsa_port *dp = dsa_slave_to_port(dev); 768a2a1a13bSHeiner Kallweit 769a2a1a13bSHeiner Kallweit return phylink_ethtool_set_pauseparam(dp->pl, pause); 770a2a1a13bSHeiner Kallweit } 771a2a1a13bSHeiner Kallweit 77204ff53f9SFlorian Fainelli #ifdef CONFIG_NET_POLL_CONTROLLER 77304ff53f9SFlorian Fainelli static int dsa_slave_netpoll_setup(struct net_device *dev, 77404ff53f9SFlorian Fainelli struct netpoll_info *ni) 77504ff53f9SFlorian Fainelli { 776d0006b00SVivien Didelot struct net_device *master = dsa_slave_to_master(dev); 77704ff53f9SFlorian Fainelli struct dsa_slave_priv *p = netdev_priv(dev); 77804ff53f9SFlorian Fainelli struct netpoll *netpoll; 77904ff53f9SFlorian Fainelli int err = 0; 78004ff53f9SFlorian Fainelli 78104ff53f9SFlorian Fainelli netpoll = kzalloc(sizeof(*netpoll), GFP_KERNEL); 78204ff53f9SFlorian Fainelli if (!netpoll) 78304ff53f9SFlorian Fainelli return -ENOMEM; 78404ff53f9SFlorian Fainelli 78504ff53f9SFlorian Fainelli err = __netpoll_setup(netpoll, master); 78604ff53f9SFlorian Fainelli if (err) { 78704ff53f9SFlorian Fainelli kfree(netpoll); 78804ff53f9SFlorian Fainelli goto out; 78904ff53f9SFlorian Fainelli } 79004ff53f9SFlorian Fainelli 79104ff53f9SFlorian Fainelli p->netpoll = netpoll; 79204ff53f9SFlorian Fainelli out: 79304ff53f9SFlorian Fainelli return err; 79404ff53f9SFlorian Fainelli } 79504ff53f9SFlorian Fainelli 79604ff53f9SFlorian Fainelli static void dsa_slave_netpoll_cleanup(struct net_device *dev) 79704ff53f9SFlorian Fainelli { 79804ff53f9SFlorian Fainelli struct dsa_slave_priv *p = netdev_priv(dev); 79904ff53f9SFlorian Fainelli struct netpoll *netpoll = p->netpoll; 80004ff53f9SFlorian Fainelli 80104ff53f9SFlorian Fainelli if (!netpoll) 80204ff53f9SFlorian Fainelli return; 80304ff53f9SFlorian Fainelli 80404ff53f9SFlorian Fainelli p->netpoll = NULL; 80504ff53f9SFlorian Fainelli 806c9fbd71fSDebabrata Banerjee __netpoll_free(netpoll); 80704ff53f9SFlorian Fainelli } 80804ff53f9SFlorian Fainelli 80904ff53f9SFlorian Fainelli static void dsa_slave_poll_controller(struct net_device *dev) 81004ff53f9SFlorian Fainelli { 81104ff53f9SFlorian Fainelli } 81204ff53f9SFlorian Fainelli #endif 81304ff53f9SFlorian Fainelli 81444bb765cSFlorian Fainelli static int dsa_slave_get_phys_port_name(struct net_device *dev, 81544bb765cSFlorian Fainelli char *name, size_t len) 81644bb765cSFlorian Fainelli { 817d945097bSVivien Didelot struct dsa_port *dp = dsa_slave_to_port(dev); 81844bb765cSFlorian Fainelli 819d484210bSJiri Pirko /* For non-legacy ports, devlink is used and it takes 820d484210bSJiri Pirko * care of the name generation. This ndo implementation 821d484210bSJiri Pirko * should be removed with legacy support. 822d484210bSJiri Pirko */ 823d484210bSJiri Pirko if (dp->ds->devlink) 824d484210bSJiri Pirko return -EOPNOTSUPP; 825d484210bSJiri Pirko 826d945097bSVivien Didelot if (snprintf(name, len, "p%d", dp->index) >= len) 82744bb765cSFlorian Fainelli return -EINVAL; 8283a543ef4SFlorian Fainelli 8293a543ef4SFlorian Fainelli return 0; 8303a543ef4SFlorian Fainelli } 8313a543ef4SFlorian Fainelli 832f50f2127SFlorian Fainelli static struct dsa_mall_tc_entry * 8334fa7b718SVivien Didelot dsa_slave_mall_tc_entry_find(struct net_device *dev, unsigned long cookie) 834f50f2127SFlorian Fainelli { 8354fa7b718SVivien Didelot struct dsa_slave_priv *p = netdev_priv(dev); 836f50f2127SFlorian Fainelli struct dsa_mall_tc_entry *mall_tc_entry; 837f50f2127SFlorian Fainelli 838f50f2127SFlorian Fainelli list_for_each_entry(mall_tc_entry, &p->mall_tc_list, list) 839f50f2127SFlorian Fainelli if (mall_tc_entry->cookie == cookie) 840f50f2127SFlorian Fainelli return mall_tc_entry; 841f50f2127SFlorian Fainelli 842f50f2127SFlorian Fainelli return NULL; 843f50f2127SFlorian Fainelli } 844f50f2127SFlorian Fainelli 845e13c2075SVladimir Oltean static int 846e13c2075SVladimir Oltean dsa_slave_add_cls_matchall_mirred(struct net_device *dev, 847f50f2127SFlorian Fainelli struct tc_cls_matchall_offload *cls, 848f50f2127SFlorian Fainelli bool ingress) 849f50f2127SFlorian Fainelli { 850d945097bSVivien Didelot struct dsa_port *dp = dsa_slave_to_port(dev); 851f50f2127SFlorian Fainelli struct dsa_slave_priv *p = netdev_priv(dev); 852e13c2075SVladimir Oltean struct dsa_mall_mirror_tc_entry *mirror; 853f50f2127SFlorian Fainelli struct dsa_mall_tc_entry *mall_tc_entry; 854d945097bSVivien Didelot struct dsa_switch *ds = dp->ds; 8559681e8b3SPieter Jansen van Vuuren struct flow_action_entry *act; 856d945097bSVivien Didelot struct dsa_port *to_dp; 857e13c2075SVladimir Oltean int err; 858e13c2075SVladimir Oltean 859e13c2075SVladimir Oltean act = &cls->rule->action.entries[0]; 860f50f2127SFlorian Fainelli 861f50f2127SFlorian Fainelli if (!ds->ops->port_mirror_add) 86234297176SVladimir Oltean return -EOPNOTSUPP; 863f50f2127SFlorian Fainelli 864e13c2075SVladimir Oltean if (!act->dev) 865e13c2075SVladimir Oltean return -EINVAL; 866f50f2127SFlorian Fainelli 86753eca1f3SJakub Kicinski if (!flow_action_basic_hw_stats_check(&cls->rule->action, 868319a1d19SJiri Pirko cls->common.extack)) 86934297176SVladimir Oltean return -EOPNOTSUPP; 870319a1d19SJiri Pirko 8719681e8b3SPieter Jansen van Vuuren act = &cls->rule->action.entries[0]; 872f50f2127SFlorian Fainelli 8739681e8b3SPieter Jansen van Vuuren if (!dsa_slave_dev_check(act->dev)) 874f50f2127SFlorian Fainelli return -EOPNOTSUPP; 875f50f2127SFlorian Fainelli 876f50f2127SFlorian Fainelli mall_tc_entry = kzalloc(sizeof(*mall_tc_entry), GFP_KERNEL); 877f50f2127SFlorian Fainelli if (!mall_tc_entry) 878f50f2127SFlorian Fainelli return -ENOMEM; 879f50f2127SFlorian Fainelli 880f50f2127SFlorian Fainelli mall_tc_entry->cookie = cls->cookie; 881f50f2127SFlorian Fainelli mall_tc_entry->type = DSA_PORT_MALL_MIRROR; 882f50f2127SFlorian Fainelli mirror = &mall_tc_entry->mirror; 883f50f2127SFlorian Fainelli 8849681e8b3SPieter Jansen van Vuuren to_dp = dsa_slave_to_port(act->dev); 885f50f2127SFlorian Fainelli 886d945097bSVivien Didelot mirror->to_local_port = to_dp->index; 887f50f2127SFlorian Fainelli mirror->ingress = ingress; 888f50f2127SFlorian Fainelli 889d945097bSVivien Didelot err = ds->ops->port_mirror_add(ds, dp->index, mirror, ingress); 890f50f2127SFlorian Fainelli if (err) { 891f50f2127SFlorian Fainelli kfree(mall_tc_entry); 892f50f2127SFlorian Fainelli return err; 893f50f2127SFlorian Fainelli } 894f50f2127SFlorian Fainelli 895f50f2127SFlorian Fainelli list_add_tail(&mall_tc_entry->list, &p->mall_tc_list); 896e13c2075SVladimir Oltean 897e13c2075SVladimir Oltean return err; 898f50f2127SFlorian Fainelli } 899f50f2127SFlorian Fainelli 90034297176SVladimir Oltean static int 90134297176SVladimir Oltean dsa_slave_add_cls_matchall_police(struct net_device *dev, 90234297176SVladimir Oltean struct tc_cls_matchall_offload *cls, 90334297176SVladimir Oltean bool ingress) 90434297176SVladimir Oltean { 90534297176SVladimir Oltean struct netlink_ext_ack *extack = cls->common.extack; 90634297176SVladimir Oltean struct dsa_port *dp = dsa_slave_to_port(dev); 90734297176SVladimir Oltean struct dsa_slave_priv *p = netdev_priv(dev); 90834297176SVladimir Oltean struct dsa_mall_policer_tc_entry *policer; 90934297176SVladimir Oltean struct dsa_mall_tc_entry *mall_tc_entry; 91034297176SVladimir Oltean struct dsa_switch *ds = dp->ds; 91134297176SVladimir Oltean struct flow_action_entry *act; 91234297176SVladimir Oltean int err; 91334297176SVladimir Oltean 91434297176SVladimir Oltean if (!ds->ops->port_policer_add) { 91534297176SVladimir Oltean NL_SET_ERR_MSG_MOD(extack, 91634297176SVladimir Oltean "Policing offload not implemented\n"); 91734297176SVladimir Oltean return -EOPNOTSUPP; 91834297176SVladimir Oltean } 91934297176SVladimir Oltean 92034297176SVladimir Oltean if (!ingress) { 92134297176SVladimir Oltean NL_SET_ERR_MSG_MOD(extack, 92234297176SVladimir Oltean "Only supported on ingress qdisc\n"); 92334297176SVladimir Oltean return -EOPNOTSUPP; 92434297176SVladimir Oltean } 92534297176SVladimir Oltean 92634297176SVladimir Oltean if (!flow_action_basic_hw_stats_check(&cls->rule->action, 92734297176SVladimir Oltean cls->common.extack)) 92834297176SVladimir Oltean return -EOPNOTSUPP; 92934297176SVladimir Oltean 93034297176SVladimir Oltean list_for_each_entry(mall_tc_entry, &p->mall_tc_list, list) { 93134297176SVladimir Oltean if (mall_tc_entry->type == DSA_PORT_MALL_POLICER) { 93234297176SVladimir Oltean NL_SET_ERR_MSG_MOD(extack, 93334297176SVladimir Oltean "Only one port policer allowed\n"); 93434297176SVladimir Oltean return -EEXIST; 93534297176SVladimir Oltean } 93634297176SVladimir Oltean } 93734297176SVladimir Oltean 93834297176SVladimir Oltean act = &cls->rule->action.entries[0]; 93934297176SVladimir Oltean 94034297176SVladimir Oltean mall_tc_entry = kzalloc(sizeof(*mall_tc_entry), GFP_KERNEL); 94134297176SVladimir Oltean if (!mall_tc_entry) 94234297176SVladimir Oltean return -ENOMEM; 94334297176SVladimir Oltean 94434297176SVladimir Oltean mall_tc_entry->cookie = cls->cookie; 94534297176SVladimir Oltean mall_tc_entry->type = DSA_PORT_MALL_POLICER; 94634297176SVladimir Oltean policer = &mall_tc_entry->policer; 94734297176SVladimir Oltean policer->rate_bytes_per_sec = act->police.rate_bytes_ps; 94834297176SVladimir Oltean policer->burst = act->police.burst; 94934297176SVladimir Oltean 95034297176SVladimir Oltean err = ds->ops->port_policer_add(ds, dp->index, policer); 95134297176SVladimir Oltean if (err) { 95234297176SVladimir Oltean kfree(mall_tc_entry); 95334297176SVladimir Oltean return err; 95434297176SVladimir Oltean } 95534297176SVladimir Oltean 95634297176SVladimir Oltean list_add_tail(&mall_tc_entry->list, &p->mall_tc_list); 95734297176SVladimir Oltean 95834297176SVladimir Oltean return err; 95934297176SVladimir Oltean } 96034297176SVladimir Oltean 961e13c2075SVladimir Oltean static int dsa_slave_add_cls_matchall(struct net_device *dev, 962e13c2075SVladimir Oltean struct tc_cls_matchall_offload *cls, 963e13c2075SVladimir Oltean bool ingress) 964e13c2075SVladimir Oltean { 965e13c2075SVladimir Oltean int err = -EOPNOTSUPP; 966e13c2075SVladimir Oltean 967e13c2075SVladimir Oltean if (cls->common.protocol == htons(ETH_P_ALL) && 968e13c2075SVladimir Oltean flow_offload_has_one_action(&cls->rule->action) && 969e13c2075SVladimir Oltean cls->rule->action.entries[0].id == FLOW_ACTION_MIRRED) 970e13c2075SVladimir Oltean err = dsa_slave_add_cls_matchall_mirred(dev, cls, ingress); 97134297176SVladimir Oltean else if (flow_offload_has_one_action(&cls->rule->action) && 97234297176SVladimir Oltean cls->rule->action.entries[0].id == FLOW_ACTION_POLICE) 97334297176SVladimir Oltean err = dsa_slave_add_cls_matchall_police(dev, cls, ingress); 974e13c2075SVladimir Oltean 975e13c2075SVladimir Oltean return err; 976f50f2127SFlorian Fainelli } 977f50f2127SFlorian Fainelli 978f50f2127SFlorian Fainelli static void dsa_slave_del_cls_matchall(struct net_device *dev, 979f50f2127SFlorian Fainelli struct tc_cls_matchall_offload *cls) 980f50f2127SFlorian Fainelli { 981d945097bSVivien Didelot struct dsa_port *dp = dsa_slave_to_port(dev); 982f50f2127SFlorian Fainelli struct dsa_mall_tc_entry *mall_tc_entry; 983d945097bSVivien Didelot struct dsa_switch *ds = dp->ds; 984f50f2127SFlorian Fainelli 9854fa7b718SVivien Didelot mall_tc_entry = dsa_slave_mall_tc_entry_find(dev, cls->cookie); 986f50f2127SFlorian Fainelli if (!mall_tc_entry) 987f50f2127SFlorian Fainelli return; 988f50f2127SFlorian Fainelli 989f50f2127SFlorian Fainelli list_del(&mall_tc_entry->list); 990f50f2127SFlorian Fainelli 991f50f2127SFlorian Fainelli switch (mall_tc_entry->type) { 992f50f2127SFlorian Fainelli case DSA_PORT_MALL_MIRROR: 99334297176SVladimir Oltean if (ds->ops->port_mirror_del) 99434297176SVladimir Oltean ds->ops->port_mirror_del(ds, dp->index, 99534297176SVladimir Oltean &mall_tc_entry->mirror); 99634297176SVladimir Oltean break; 99734297176SVladimir Oltean case DSA_PORT_MALL_POLICER: 99834297176SVladimir Oltean if (ds->ops->port_policer_del) 99934297176SVladimir Oltean ds->ops->port_policer_del(ds, dp->index); 1000f50f2127SFlorian Fainelli break; 1001f50f2127SFlorian Fainelli default: 1002f50f2127SFlorian Fainelli WARN_ON(1); 1003f50f2127SFlorian Fainelli } 1004f50f2127SFlorian Fainelli 1005f50f2127SFlorian Fainelli kfree(mall_tc_entry); 1006f50f2127SFlorian Fainelli } 1007f50f2127SFlorian Fainelli 10083fbae382SJiri Pirko static int dsa_slave_setup_tc_cls_matchall(struct net_device *dev, 10096b3eb752SJiri Pirko struct tc_cls_matchall_offload *cls, 10106b3eb752SJiri Pirko bool ingress) 1011f50f2127SFlorian Fainelli { 10125fd9fc4eSJiri Pirko if (cls->common.chain_index) 1013a5fcf8a6SJiri Pirko return -EOPNOTSUPP; 1014f50f2127SFlorian Fainelli 10153fbae382SJiri Pirko switch (cls->command) { 10163fbae382SJiri Pirko case TC_CLSMATCHALL_REPLACE: 10175fd9fc4eSJiri Pirko return dsa_slave_add_cls_matchall(dev, cls, ingress); 10183fbae382SJiri Pirko case TC_CLSMATCHALL_DESTROY: 10193fbae382SJiri Pirko dsa_slave_del_cls_matchall(dev, cls); 10203fbae382SJiri Pirko return 0; 10213fbae382SJiri Pirko default: 10223fbae382SJiri Pirko return -EOPNOTSUPP; 10233fbae382SJiri Pirko } 10243fbae382SJiri Pirko } 10253fbae382SJiri Pirko 1026ed11bb1fSVladimir Oltean static int dsa_slave_add_cls_flower(struct net_device *dev, 1027ed11bb1fSVladimir Oltean struct flow_cls_offload *cls, 1028ed11bb1fSVladimir Oltean bool ingress) 1029ed11bb1fSVladimir Oltean { 1030ed11bb1fSVladimir Oltean struct dsa_port *dp = dsa_slave_to_port(dev); 1031ed11bb1fSVladimir Oltean struct dsa_switch *ds = dp->ds; 1032ed11bb1fSVladimir Oltean int port = dp->index; 1033ed11bb1fSVladimir Oltean 1034ed11bb1fSVladimir Oltean if (!ds->ops->cls_flower_add) 1035ed11bb1fSVladimir Oltean return -EOPNOTSUPP; 1036ed11bb1fSVladimir Oltean 1037ed11bb1fSVladimir Oltean return ds->ops->cls_flower_add(ds, port, cls, ingress); 1038ed11bb1fSVladimir Oltean } 1039ed11bb1fSVladimir Oltean 1040ed11bb1fSVladimir Oltean static int dsa_slave_del_cls_flower(struct net_device *dev, 1041ed11bb1fSVladimir Oltean struct flow_cls_offload *cls, 1042ed11bb1fSVladimir Oltean bool ingress) 1043ed11bb1fSVladimir Oltean { 1044ed11bb1fSVladimir Oltean struct dsa_port *dp = dsa_slave_to_port(dev); 1045ed11bb1fSVladimir Oltean struct dsa_switch *ds = dp->ds; 1046ed11bb1fSVladimir Oltean int port = dp->index; 1047ed11bb1fSVladimir Oltean 1048ed11bb1fSVladimir Oltean if (!ds->ops->cls_flower_del) 1049ed11bb1fSVladimir Oltean return -EOPNOTSUPP; 1050ed11bb1fSVladimir Oltean 1051ed11bb1fSVladimir Oltean return ds->ops->cls_flower_del(ds, port, cls, ingress); 1052ed11bb1fSVladimir Oltean } 1053ed11bb1fSVladimir Oltean 1054ed11bb1fSVladimir Oltean static int dsa_slave_stats_cls_flower(struct net_device *dev, 1055ed11bb1fSVladimir Oltean struct flow_cls_offload *cls, 1056ed11bb1fSVladimir Oltean bool ingress) 1057ed11bb1fSVladimir Oltean { 1058ed11bb1fSVladimir Oltean struct dsa_port *dp = dsa_slave_to_port(dev); 1059ed11bb1fSVladimir Oltean struct dsa_switch *ds = dp->ds; 1060ed11bb1fSVladimir Oltean int port = dp->index; 1061ed11bb1fSVladimir Oltean 1062ed11bb1fSVladimir Oltean if (!ds->ops->cls_flower_stats) 1063ed11bb1fSVladimir Oltean return -EOPNOTSUPP; 1064ed11bb1fSVladimir Oltean 1065ed11bb1fSVladimir Oltean return ds->ops->cls_flower_stats(ds, port, cls, ingress); 1066ed11bb1fSVladimir Oltean } 1067ed11bb1fSVladimir Oltean 1068ed11bb1fSVladimir Oltean static int dsa_slave_setup_tc_cls_flower(struct net_device *dev, 1069ed11bb1fSVladimir Oltean struct flow_cls_offload *cls, 1070ed11bb1fSVladimir Oltean bool ingress) 1071ed11bb1fSVladimir Oltean { 1072ed11bb1fSVladimir Oltean switch (cls->command) { 1073ed11bb1fSVladimir Oltean case FLOW_CLS_REPLACE: 1074ed11bb1fSVladimir Oltean return dsa_slave_add_cls_flower(dev, cls, ingress); 1075ed11bb1fSVladimir Oltean case FLOW_CLS_DESTROY: 1076ed11bb1fSVladimir Oltean return dsa_slave_del_cls_flower(dev, cls, ingress); 1077ed11bb1fSVladimir Oltean case FLOW_CLS_STATS: 1078ed11bb1fSVladimir Oltean return dsa_slave_stats_cls_flower(dev, cls, ingress); 1079ed11bb1fSVladimir Oltean default: 1080ed11bb1fSVladimir Oltean return -EOPNOTSUPP; 1081ed11bb1fSVladimir Oltean } 1082ed11bb1fSVladimir Oltean } 1083ed11bb1fSVladimir Oltean 10846b3eb752SJiri Pirko static int dsa_slave_setup_tc_block_cb(enum tc_setup_type type, void *type_data, 10856b3eb752SJiri Pirko void *cb_priv, bool ingress) 10866b3eb752SJiri Pirko { 10876b3eb752SJiri Pirko struct net_device *dev = cb_priv; 10886b3eb752SJiri Pirko 108944ae12a7SJiri Pirko if (!tc_can_offload(dev)) 109044ae12a7SJiri Pirko return -EOPNOTSUPP; 109144ae12a7SJiri Pirko 10926b3eb752SJiri Pirko switch (type) { 10936b3eb752SJiri Pirko case TC_SETUP_CLSMATCHALL: 10946b3eb752SJiri Pirko return dsa_slave_setup_tc_cls_matchall(dev, type_data, ingress); 1095ed11bb1fSVladimir Oltean case TC_SETUP_CLSFLOWER: 1096ed11bb1fSVladimir Oltean return dsa_slave_setup_tc_cls_flower(dev, type_data, ingress); 10976b3eb752SJiri Pirko default: 10986b3eb752SJiri Pirko return -EOPNOTSUPP; 10996b3eb752SJiri Pirko } 11006b3eb752SJiri Pirko } 11016b3eb752SJiri Pirko 11026b3eb752SJiri Pirko static int dsa_slave_setup_tc_block_cb_ig(enum tc_setup_type type, 11036b3eb752SJiri Pirko void *type_data, void *cb_priv) 11046b3eb752SJiri Pirko { 11056b3eb752SJiri Pirko return dsa_slave_setup_tc_block_cb(type, type_data, cb_priv, true); 11066b3eb752SJiri Pirko } 11076b3eb752SJiri Pirko 11086b3eb752SJiri Pirko static int dsa_slave_setup_tc_block_cb_eg(enum tc_setup_type type, 11096b3eb752SJiri Pirko void *type_data, void *cb_priv) 11106b3eb752SJiri Pirko { 11116b3eb752SJiri Pirko return dsa_slave_setup_tc_block_cb(type, type_data, cb_priv, false); 11126b3eb752SJiri Pirko } 11136b3eb752SJiri Pirko 1114955bcb6eSPablo Neira Ayuso static LIST_HEAD(dsa_slave_block_cb_list); 1115955bcb6eSPablo Neira Ayuso 11166b3eb752SJiri Pirko static int dsa_slave_setup_tc_block(struct net_device *dev, 1117955bcb6eSPablo Neira Ayuso struct flow_block_offload *f) 11186b3eb752SJiri Pirko { 1119955bcb6eSPablo Neira Ayuso struct flow_block_cb *block_cb; 1120a7323311SPablo Neira Ayuso flow_setup_cb_t *cb; 11216b3eb752SJiri Pirko 112232f8c409SPablo Neira Ayuso if (f->binder_type == FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS) 11236b3eb752SJiri Pirko cb = dsa_slave_setup_tc_block_cb_ig; 112432f8c409SPablo Neira Ayuso else if (f->binder_type == FLOW_BLOCK_BINDER_TYPE_CLSACT_EGRESS) 11256b3eb752SJiri Pirko cb = dsa_slave_setup_tc_block_cb_eg; 11266b3eb752SJiri Pirko else 11276b3eb752SJiri Pirko return -EOPNOTSUPP; 11286b3eb752SJiri Pirko 1129955bcb6eSPablo Neira Ayuso f->driver_block_list = &dsa_slave_block_cb_list; 1130955bcb6eSPablo Neira Ayuso 11316b3eb752SJiri Pirko switch (f->command) { 11329c0e189eSPablo Neira Ayuso case FLOW_BLOCK_BIND: 11330d4fd02eSPablo Neira Ayuso if (flow_block_cb_is_busy(cb, dev, &dsa_slave_block_cb_list)) 11340d4fd02eSPablo Neira Ayuso return -EBUSY; 11350d4fd02eSPablo Neira Ayuso 11360c7294ddSPablo Neira Ayuso block_cb = flow_block_cb_alloc(cb, dev, dev, NULL); 1137955bcb6eSPablo Neira Ayuso if (IS_ERR(block_cb)) 1138955bcb6eSPablo Neira Ayuso return PTR_ERR(block_cb); 1139955bcb6eSPablo Neira Ayuso 1140955bcb6eSPablo Neira Ayuso flow_block_cb_add(block_cb, f); 1141955bcb6eSPablo Neira Ayuso list_add_tail(&block_cb->driver_list, &dsa_slave_block_cb_list); 1142955bcb6eSPablo Neira Ayuso return 0; 11439c0e189eSPablo Neira Ayuso case FLOW_BLOCK_UNBIND: 114414bfb13fSPablo Neira Ayuso block_cb = flow_block_cb_lookup(f->block, cb, dev); 1145955bcb6eSPablo Neira Ayuso if (!block_cb) 1146955bcb6eSPablo Neira Ayuso return -ENOENT; 1147955bcb6eSPablo Neira Ayuso 1148955bcb6eSPablo Neira Ayuso flow_block_cb_remove(block_cb, f); 1149955bcb6eSPablo Neira Ayuso list_del(&block_cb->driver_list); 11506b3eb752SJiri Pirko return 0; 11516b3eb752SJiri Pirko default: 11526b3eb752SJiri Pirko return -EOPNOTSUPP; 11536b3eb752SJiri Pirko } 11546b3eb752SJiri Pirko } 11556b3eb752SJiri Pirko 11563fbae382SJiri Pirko static int dsa_slave_setup_tc(struct net_device *dev, enum tc_setup_type type, 1157de4784caSJiri Pirko void *type_data) 11583fbae382SJiri Pirko { 115947d23af2SVladimir Oltean struct dsa_port *dp = dsa_slave_to_port(dev); 116047d23af2SVladimir Oltean struct dsa_switch *ds = dp->ds; 116147d23af2SVladimir Oltean 116247d23af2SVladimir Oltean if (type == TC_SETUP_BLOCK) 11636b3eb752SJiri Pirko return dsa_slave_setup_tc_block(dev, type_data); 116447d23af2SVladimir Oltean 116547d23af2SVladimir Oltean if (!ds->ops->port_setup_tc) 1166a5fcf8a6SJiri Pirko return -EOPNOTSUPP; 116747d23af2SVladimir Oltean 116847d23af2SVladimir Oltean return ds->ops->port_setup_tc(ds, dp->index, type, type_data); 1169f50f2127SFlorian Fainelli } 1170f50f2127SFlorian Fainelli 1171f613ed66SFlorian Fainelli static void dsa_slave_get_stats64(struct net_device *dev, 1172f613ed66SFlorian Fainelli struct rtnl_link_stats64 *stats) 1173f613ed66SFlorian Fainelli { 1174f613ed66SFlorian Fainelli struct dsa_slave_priv *p = netdev_priv(dev); 11755f6b4e14SFlorian Fainelli struct pcpu_sw_netstats *s; 1176f613ed66SFlorian Fainelli unsigned int start; 11775f6b4e14SFlorian Fainelli int i; 1178f613ed66SFlorian Fainelli 1179f613ed66SFlorian Fainelli netdev_stats_to_stats64(stats, &dev->stats); 11805f6b4e14SFlorian Fainelli for_each_possible_cpu(i) { 11815f6b4e14SFlorian Fainelli u64 tx_packets, tx_bytes, rx_packets, rx_bytes; 11825f6b4e14SFlorian Fainelli 11835f6b4e14SFlorian Fainelli s = per_cpu_ptr(p->stats64, i); 1184f613ed66SFlorian Fainelli do { 11855f6b4e14SFlorian Fainelli start = u64_stats_fetch_begin_irq(&s->syncp); 11865f6b4e14SFlorian Fainelli tx_packets = s->tx_packets; 11875f6b4e14SFlorian Fainelli tx_bytes = s->tx_bytes; 11885f6b4e14SFlorian Fainelli rx_packets = s->rx_packets; 11895f6b4e14SFlorian Fainelli rx_bytes = s->rx_bytes; 11905f6b4e14SFlorian Fainelli } while (u64_stats_fetch_retry_irq(&s->syncp, start)); 11915f6b4e14SFlorian Fainelli 11925f6b4e14SFlorian Fainelli stats->tx_packets += tx_packets; 11935f6b4e14SFlorian Fainelli stats->tx_bytes += tx_bytes; 11945f6b4e14SFlorian Fainelli stats->rx_packets += rx_packets; 11955f6b4e14SFlorian Fainelli stats->rx_bytes += rx_bytes; 11965f6b4e14SFlorian Fainelli } 1197f613ed66SFlorian Fainelli } 1198f613ed66SFlorian Fainelli 1199bf9f2648SFlorian Fainelli static int dsa_slave_get_rxnfc(struct net_device *dev, 1200bf9f2648SFlorian Fainelli struct ethtool_rxnfc *nfc, u32 *rule_locs) 1201bf9f2648SFlorian Fainelli { 1202d945097bSVivien Didelot struct dsa_port *dp = dsa_slave_to_port(dev); 1203d945097bSVivien Didelot struct dsa_switch *ds = dp->ds; 1204bf9f2648SFlorian Fainelli 1205bf9f2648SFlorian Fainelli if (!ds->ops->get_rxnfc) 1206bf9f2648SFlorian Fainelli return -EOPNOTSUPP; 1207bf9f2648SFlorian Fainelli 1208d945097bSVivien Didelot return ds->ops->get_rxnfc(ds, dp->index, nfc, rule_locs); 1209bf9f2648SFlorian Fainelli } 1210bf9f2648SFlorian Fainelli 1211bf9f2648SFlorian Fainelli static int dsa_slave_set_rxnfc(struct net_device *dev, 1212bf9f2648SFlorian Fainelli struct ethtool_rxnfc *nfc) 1213bf9f2648SFlorian Fainelli { 1214d945097bSVivien Didelot struct dsa_port *dp = dsa_slave_to_port(dev); 1215d945097bSVivien Didelot struct dsa_switch *ds = dp->ds; 1216bf9f2648SFlorian Fainelli 1217bf9f2648SFlorian Fainelli if (!ds->ops->set_rxnfc) 1218bf9f2648SFlorian Fainelli return -EOPNOTSUPP; 1219bf9f2648SFlorian Fainelli 1220d945097bSVivien Didelot return ds->ops->set_rxnfc(ds, dp->index, nfc); 1221bf9f2648SFlorian Fainelli } 1222bf9f2648SFlorian Fainelli 12230336369dSBrandon Streiff static int dsa_slave_get_ts_info(struct net_device *dev, 12240336369dSBrandon Streiff struct ethtool_ts_info *ts) 12250336369dSBrandon Streiff { 12260336369dSBrandon Streiff struct dsa_slave_priv *p = netdev_priv(dev); 12270336369dSBrandon Streiff struct dsa_switch *ds = p->dp->ds; 12280336369dSBrandon Streiff 12290336369dSBrandon Streiff if (!ds->ops->get_ts_info) 12300336369dSBrandon Streiff return -EOPNOTSUPP; 12310336369dSBrandon Streiff 12320336369dSBrandon Streiff return ds->ops->get_ts_info(ds, p->dp->index, ts); 12330336369dSBrandon Streiff } 12340336369dSBrandon Streiff 1235061f6a50SFlorian Fainelli static int dsa_slave_vlan_rx_add_vid(struct net_device *dev, __be16 proto, 1236061f6a50SFlorian Fainelli u16 vid) 1237061f6a50SFlorian Fainelli { 1238061f6a50SFlorian Fainelli struct dsa_port *dp = dsa_slave_to_port(dev); 1239061f6a50SFlorian Fainelli struct bridge_vlan_info info; 1240061f6a50SFlorian Fainelli int ret; 1241061f6a50SFlorian Fainelli 1242061f6a50SFlorian Fainelli /* Check for a possible bridge VLAN entry now since there is no 1243061f6a50SFlorian Fainelli * need to emulate the switchdev prepare + commit phase. 1244061f6a50SFlorian Fainelli */ 1245061f6a50SFlorian Fainelli if (dp->bridge_dev) { 1246c5335d73SVivien Didelot if (!br_vlan_enabled(dp->bridge_dev)) 1247c5335d73SVivien Didelot return 0; 1248c5335d73SVivien Didelot 1249061f6a50SFlorian Fainelli /* br_vlan_get_info() returns -EINVAL or -ENOENT if the 1250061f6a50SFlorian Fainelli * device, respectively the VID is not found, returning 1251061f6a50SFlorian Fainelli * 0 means success, which is a failure for us here. 1252061f6a50SFlorian Fainelli */ 1253061f6a50SFlorian Fainelli ret = br_vlan_get_info(dp->bridge_dev, vid, &info); 1254061f6a50SFlorian Fainelli if (ret == 0) 1255061f6a50SFlorian Fainelli return -EBUSY; 1256061f6a50SFlorian Fainelli } 1257061f6a50SFlorian Fainelli 1258cf360866SVivien Didelot ret = dsa_port_vid_add(dp, vid, 0); 12599b236d2aSVladimir Oltean if (ret) 1260cf360866SVivien Didelot return ret; 1261cf360866SVivien Didelot 12627e1741b4SVivien Didelot ret = dsa_port_vid_add(dp->cpu_dp, vid, 0); 12639b236d2aSVladimir Oltean if (ret) 12647e1741b4SVivien Didelot return ret; 12657e1741b4SVivien Didelot 1266cf360866SVivien Didelot return 0; 1267061f6a50SFlorian Fainelli } 1268061f6a50SFlorian Fainelli 1269061f6a50SFlorian Fainelli static int dsa_slave_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, 1270061f6a50SFlorian Fainelli u16 vid) 1271061f6a50SFlorian Fainelli { 1272061f6a50SFlorian Fainelli struct dsa_port *dp = dsa_slave_to_port(dev); 1273061f6a50SFlorian Fainelli struct bridge_vlan_info info; 1274061f6a50SFlorian Fainelli int ret; 1275061f6a50SFlorian Fainelli 1276061f6a50SFlorian Fainelli /* Check for a possible bridge VLAN entry now since there is no 1277061f6a50SFlorian Fainelli * need to emulate the switchdev prepare + commit phase. 1278061f6a50SFlorian Fainelli */ 1279061f6a50SFlorian Fainelli if (dp->bridge_dev) { 1280c5335d73SVivien Didelot if (!br_vlan_enabled(dp->bridge_dev)) 1281c5335d73SVivien Didelot return 0; 1282c5335d73SVivien Didelot 1283061f6a50SFlorian Fainelli /* br_vlan_get_info() returns -EINVAL or -ENOENT if the 1284061f6a50SFlorian Fainelli * device, respectively the VID is not found, returning 1285061f6a50SFlorian Fainelli * 0 means success, which is a failure for us here. 1286061f6a50SFlorian Fainelli */ 1287061f6a50SFlorian Fainelli ret = br_vlan_get_info(dp->bridge_dev, vid, &info); 1288061f6a50SFlorian Fainelli if (ret == 0) 1289061f6a50SFlorian Fainelli return -EBUSY; 1290061f6a50SFlorian Fainelli } 1291061f6a50SFlorian Fainelli 12927e1741b4SVivien Didelot /* Do not deprogram the CPU port as it may be shared with other user 12937e1741b4SVivien Didelot * ports which can be members of this VLAN as well. 12947e1741b4SVivien Didelot */ 12959b236d2aSVladimir Oltean return dsa_port_vid_del(dp, vid); 1296061f6a50SFlorian Fainelli } 1297061f6a50SFlorian Fainelli 1298bff33f7eSVladimir Oltean struct dsa_hw_port { 1299bff33f7eSVladimir Oltean struct list_head list; 1300bff33f7eSVladimir Oltean struct net_device *dev; 1301bff33f7eSVladimir Oltean int old_mtu; 1302bff33f7eSVladimir Oltean }; 1303bff33f7eSVladimir Oltean 1304bff33f7eSVladimir Oltean static int dsa_hw_port_list_set_mtu(struct list_head *hw_port_list, int mtu) 1305bff33f7eSVladimir Oltean { 1306bff33f7eSVladimir Oltean const struct dsa_hw_port *p; 1307bff33f7eSVladimir Oltean int err; 1308bff33f7eSVladimir Oltean 1309bff33f7eSVladimir Oltean list_for_each_entry(p, hw_port_list, list) { 1310bff33f7eSVladimir Oltean if (p->dev->mtu == mtu) 1311bff33f7eSVladimir Oltean continue; 1312bff33f7eSVladimir Oltean 1313bff33f7eSVladimir Oltean err = dev_set_mtu(p->dev, mtu); 1314bff33f7eSVladimir Oltean if (err) 1315bff33f7eSVladimir Oltean goto rollback; 1316bff33f7eSVladimir Oltean } 1317bff33f7eSVladimir Oltean 1318bff33f7eSVladimir Oltean return 0; 1319bff33f7eSVladimir Oltean 1320bff33f7eSVladimir Oltean rollback: 1321bff33f7eSVladimir Oltean list_for_each_entry_continue_reverse(p, hw_port_list, list) { 1322bff33f7eSVladimir Oltean if (p->dev->mtu == p->old_mtu) 1323bff33f7eSVladimir Oltean continue; 1324bff33f7eSVladimir Oltean 1325bff33f7eSVladimir Oltean if (dev_set_mtu(p->dev, p->old_mtu)) 1326bff33f7eSVladimir Oltean netdev_err(p->dev, "Failed to restore MTU\n"); 1327bff33f7eSVladimir Oltean } 1328bff33f7eSVladimir Oltean 1329bff33f7eSVladimir Oltean return err; 1330bff33f7eSVladimir Oltean } 1331bff33f7eSVladimir Oltean 1332bff33f7eSVladimir Oltean static void dsa_hw_port_list_free(struct list_head *hw_port_list) 1333bff33f7eSVladimir Oltean { 1334bff33f7eSVladimir Oltean struct dsa_hw_port *p, *n; 1335bff33f7eSVladimir Oltean 1336bff33f7eSVladimir Oltean list_for_each_entry_safe(p, n, hw_port_list, list) 1337bff33f7eSVladimir Oltean kfree(p); 1338bff33f7eSVladimir Oltean } 1339bff33f7eSVladimir Oltean 1340bff33f7eSVladimir Oltean /* Make the hardware datapath to/from @dev limited to a common MTU */ 1341bf88dc32Skbuild test robot static void dsa_bridge_mtu_normalization(struct dsa_port *dp) 1342bff33f7eSVladimir Oltean { 1343bff33f7eSVladimir Oltean struct list_head hw_port_list; 1344bff33f7eSVladimir Oltean struct dsa_switch_tree *dst; 1345bff33f7eSVladimir Oltean int min_mtu = ETH_MAX_MTU; 1346bff33f7eSVladimir Oltean struct dsa_port *other_dp; 1347bff33f7eSVladimir Oltean int err; 1348bff33f7eSVladimir Oltean 1349bff33f7eSVladimir Oltean if (!dp->ds->mtu_enforcement_ingress) 1350bff33f7eSVladimir Oltean return; 1351bff33f7eSVladimir Oltean 1352bff33f7eSVladimir Oltean if (!dp->bridge_dev) 1353bff33f7eSVladimir Oltean return; 1354bff33f7eSVladimir Oltean 1355bff33f7eSVladimir Oltean INIT_LIST_HEAD(&hw_port_list); 1356bff33f7eSVladimir Oltean 1357bff33f7eSVladimir Oltean /* Populate the list of ports that are part of the same bridge 1358bff33f7eSVladimir Oltean * as the newly added/modified port 1359bff33f7eSVladimir Oltean */ 1360bff33f7eSVladimir Oltean list_for_each_entry(dst, &dsa_tree_list, list) { 1361bff33f7eSVladimir Oltean list_for_each_entry(other_dp, &dst->ports, list) { 1362bff33f7eSVladimir Oltean struct dsa_hw_port *hw_port; 1363bff33f7eSVladimir Oltean struct net_device *slave; 1364bff33f7eSVladimir Oltean 1365bff33f7eSVladimir Oltean if (other_dp->type != DSA_PORT_TYPE_USER) 1366bff33f7eSVladimir Oltean continue; 1367bff33f7eSVladimir Oltean 1368bff33f7eSVladimir Oltean if (other_dp->bridge_dev != dp->bridge_dev) 1369bff33f7eSVladimir Oltean continue; 1370bff33f7eSVladimir Oltean 1371bff33f7eSVladimir Oltean if (!other_dp->ds->mtu_enforcement_ingress) 1372bff33f7eSVladimir Oltean continue; 1373bff33f7eSVladimir Oltean 1374bff33f7eSVladimir Oltean slave = other_dp->slave; 1375bff33f7eSVladimir Oltean 1376bff33f7eSVladimir Oltean if (min_mtu > slave->mtu) 1377bff33f7eSVladimir Oltean min_mtu = slave->mtu; 1378bff33f7eSVladimir Oltean 1379bff33f7eSVladimir Oltean hw_port = kzalloc(sizeof(*hw_port), GFP_KERNEL); 1380bff33f7eSVladimir Oltean if (!hw_port) 1381bff33f7eSVladimir Oltean goto out; 1382bff33f7eSVladimir Oltean 1383bff33f7eSVladimir Oltean hw_port->dev = slave; 1384bff33f7eSVladimir Oltean hw_port->old_mtu = slave->mtu; 1385bff33f7eSVladimir Oltean 1386bff33f7eSVladimir Oltean list_add(&hw_port->list, &hw_port_list); 1387bff33f7eSVladimir Oltean } 1388bff33f7eSVladimir Oltean } 1389bff33f7eSVladimir Oltean 1390bff33f7eSVladimir Oltean /* Attempt to configure the entire hardware bridge to the newly added 1391bff33f7eSVladimir Oltean * interface's MTU first, regardless of whether the intention of the 1392bff33f7eSVladimir Oltean * user was to raise or lower it. 1393bff33f7eSVladimir Oltean */ 1394bff33f7eSVladimir Oltean err = dsa_hw_port_list_set_mtu(&hw_port_list, dp->slave->mtu); 1395bff33f7eSVladimir Oltean if (!err) 1396bff33f7eSVladimir Oltean goto out; 1397bff33f7eSVladimir Oltean 1398bff33f7eSVladimir Oltean /* Clearly that didn't work out so well, so just set the minimum MTU on 1399bff33f7eSVladimir Oltean * all hardware bridge ports now. If this fails too, then all ports will 1400bff33f7eSVladimir Oltean * still have their old MTU rolled back anyway. 1401bff33f7eSVladimir Oltean */ 1402bff33f7eSVladimir Oltean dsa_hw_port_list_set_mtu(&hw_port_list, min_mtu); 1403bff33f7eSVladimir Oltean 1404bff33f7eSVladimir Oltean out: 1405bff33f7eSVladimir Oltean dsa_hw_port_list_free(&hw_port_list); 1406bff33f7eSVladimir Oltean } 1407bff33f7eSVladimir Oltean 1408bfcb8132SVladimir Oltean static int dsa_slave_change_mtu(struct net_device *dev, int new_mtu) 1409bfcb8132SVladimir Oltean { 1410bfcb8132SVladimir Oltean struct net_device *master = dsa_slave_to_master(dev); 1411bfcb8132SVladimir Oltean struct dsa_port *dp = dsa_slave_to_port(dev); 1412bfcb8132SVladimir Oltean struct dsa_slave_priv *p = netdev_priv(dev); 1413bfcb8132SVladimir Oltean struct dsa_switch *ds = p->dp->ds; 1414bfcb8132SVladimir Oltean struct dsa_port *cpu_dp; 1415bfcb8132SVladimir Oltean int port = p->dp->index; 1416bfcb8132SVladimir Oltean int largest_mtu = 0; 1417bfcb8132SVladimir Oltean int new_master_mtu; 1418bfcb8132SVladimir Oltean int old_master_mtu; 1419bfcb8132SVladimir Oltean int mtu_limit; 1420bfcb8132SVladimir Oltean int cpu_mtu; 1421bfcb8132SVladimir Oltean int err, i; 1422bfcb8132SVladimir Oltean 1423bfcb8132SVladimir Oltean if (!ds->ops->port_change_mtu) 1424bfcb8132SVladimir Oltean return -EOPNOTSUPP; 1425bfcb8132SVladimir Oltean 1426bfcb8132SVladimir Oltean for (i = 0; i < ds->num_ports; i++) { 1427bfcb8132SVladimir Oltean int slave_mtu; 1428bfcb8132SVladimir Oltean 1429bfcb8132SVladimir Oltean if (!dsa_is_user_port(ds, i)) 1430bfcb8132SVladimir Oltean continue; 1431bfcb8132SVladimir Oltean 1432bfcb8132SVladimir Oltean /* During probe, this function will be called for each slave 1433bfcb8132SVladimir Oltean * device, while not all of them have been allocated. That's 1434bfcb8132SVladimir Oltean * ok, it doesn't change what the maximum is, so ignore it. 1435bfcb8132SVladimir Oltean */ 1436bfcb8132SVladimir Oltean if (!dsa_to_port(ds, i)->slave) 1437bfcb8132SVladimir Oltean continue; 1438bfcb8132SVladimir Oltean 1439bfcb8132SVladimir Oltean /* Pretend that we already applied the setting, which we 1440bfcb8132SVladimir Oltean * actually haven't (still haven't done all integrity checks) 1441bfcb8132SVladimir Oltean */ 1442bfcb8132SVladimir Oltean if (i == port) 1443bfcb8132SVladimir Oltean slave_mtu = new_mtu; 1444bfcb8132SVladimir Oltean else 1445bfcb8132SVladimir Oltean slave_mtu = dsa_to_port(ds, i)->slave->mtu; 1446bfcb8132SVladimir Oltean 1447bfcb8132SVladimir Oltean if (largest_mtu < slave_mtu) 1448bfcb8132SVladimir Oltean largest_mtu = slave_mtu; 1449bfcb8132SVladimir Oltean } 1450bfcb8132SVladimir Oltean 1451bfcb8132SVladimir Oltean cpu_dp = dsa_to_port(ds, port)->cpu_dp; 1452bfcb8132SVladimir Oltean 1453bfcb8132SVladimir Oltean mtu_limit = min_t(int, master->max_mtu, dev->max_mtu); 1454bfcb8132SVladimir Oltean old_master_mtu = master->mtu; 1455bfcb8132SVladimir Oltean new_master_mtu = largest_mtu + cpu_dp->tag_ops->overhead; 1456bfcb8132SVladimir Oltean if (new_master_mtu > mtu_limit) 1457bfcb8132SVladimir Oltean return -ERANGE; 1458bfcb8132SVladimir Oltean 1459bfcb8132SVladimir Oltean /* If the master MTU isn't over limit, there's no need to check the CPU 1460bfcb8132SVladimir Oltean * MTU, since that surely isn't either. 1461bfcb8132SVladimir Oltean */ 1462bfcb8132SVladimir Oltean cpu_mtu = largest_mtu; 1463bfcb8132SVladimir Oltean 1464bfcb8132SVladimir Oltean /* Start applying stuff */ 1465bfcb8132SVladimir Oltean if (new_master_mtu != old_master_mtu) { 1466bfcb8132SVladimir Oltean err = dev_set_mtu(master, new_master_mtu); 1467bfcb8132SVladimir Oltean if (err < 0) 1468bfcb8132SVladimir Oltean goto out_master_failed; 1469bfcb8132SVladimir Oltean 1470bfcb8132SVladimir Oltean /* We only need to propagate the MTU of the CPU port to 1471bfcb8132SVladimir Oltean * upstream switches. 1472bfcb8132SVladimir Oltean */ 1473bfcb8132SVladimir Oltean err = dsa_port_mtu_change(cpu_dp, cpu_mtu, true); 1474bfcb8132SVladimir Oltean if (err) 1475bfcb8132SVladimir Oltean goto out_cpu_failed; 1476bfcb8132SVladimir Oltean } 1477bfcb8132SVladimir Oltean 1478bfcb8132SVladimir Oltean err = dsa_port_mtu_change(dp, new_mtu, false); 1479bfcb8132SVladimir Oltean if (err) 1480bfcb8132SVladimir Oltean goto out_port_failed; 1481bfcb8132SVladimir Oltean 1482bfcb8132SVladimir Oltean dev->mtu = new_mtu; 1483bfcb8132SVladimir Oltean 1484bff33f7eSVladimir Oltean dsa_bridge_mtu_normalization(dp); 1485bff33f7eSVladimir Oltean 1486bfcb8132SVladimir Oltean return 0; 1487bfcb8132SVladimir Oltean 1488bfcb8132SVladimir Oltean out_port_failed: 1489bfcb8132SVladimir Oltean if (new_master_mtu != old_master_mtu) 1490bfcb8132SVladimir Oltean dsa_port_mtu_change(cpu_dp, old_master_mtu - 1491bfcb8132SVladimir Oltean cpu_dp->tag_ops->overhead, 1492bfcb8132SVladimir Oltean true); 1493bfcb8132SVladimir Oltean out_cpu_failed: 1494bfcb8132SVladimir Oltean if (new_master_mtu != old_master_mtu) 1495bfcb8132SVladimir Oltean dev_set_mtu(master, old_master_mtu); 1496bfcb8132SVladimir Oltean out_master_failed: 1497bfcb8132SVladimir Oltean return err; 1498bfcb8132SVladimir Oltean } 1499bfcb8132SVladimir Oltean 150091da11f8SLennert Buytenhek static const struct ethtool_ops dsa_slave_ethtool_ops = { 150191da11f8SLennert Buytenhek .get_drvinfo = dsa_slave_get_drvinfo, 15023d762a0fSGuenter Roeck .get_regs_len = dsa_slave_get_regs_len, 15033d762a0fSGuenter Roeck .get_regs = dsa_slave_get_regs, 1504aab9c406SFlorian Fainelli .nway_reset = dsa_slave_nway_reset, 1505c4aef9fcSFlorian Fainelli .get_link = ethtool_op_get_link, 15066793abb4SGuenter Roeck .get_eeprom_len = dsa_slave_get_eeprom_len, 15076793abb4SGuenter Roeck .get_eeprom = dsa_slave_get_eeprom, 15086793abb4SGuenter Roeck .set_eeprom = dsa_slave_set_eeprom, 150991da11f8SLennert Buytenhek .get_strings = dsa_slave_get_strings, 151091da11f8SLennert Buytenhek .get_ethtool_stats = dsa_slave_get_ethtool_stats, 151191da11f8SLennert Buytenhek .get_sset_count = dsa_slave_get_sset_count, 151219e57c4eSFlorian Fainelli .set_wol = dsa_slave_set_wol, 151319e57c4eSFlorian Fainelli .get_wol = dsa_slave_get_wol, 15147905288fSFlorian Fainelli .set_eee = dsa_slave_set_eee, 15157905288fSFlorian Fainelli .get_eee = dsa_slave_get_eee, 1516aab9c406SFlorian Fainelli .get_link_ksettings = dsa_slave_get_link_ksettings, 1517aab9c406SFlorian Fainelli .set_link_ksettings = dsa_slave_set_link_ksettings, 1518a2a1a13bSHeiner Kallweit .get_pauseparam = dsa_slave_get_pauseparam, 1519a2a1a13bSHeiner Kallweit .set_pauseparam = dsa_slave_set_pauseparam, 1520bf9f2648SFlorian Fainelli .get_rxnfc = dsa_slave_get_rxnfc, 1521bf9f2648SFlorian Fainelli .set_rxnfc = dsa_slave_set_rxnfc, 15220336369dSBrandon Streiff .get_ts_info = dsa_slave_get_ts_info, 152391da11f8SLennert Buytenhek }; 152491da11f8SLennert Buytenhek 15252a93c1a3SFlorian Fainelli /* legacy way, bypassing the bridge *****************************************/ 15262a93c1a3SFlorian Fainelli int dsa_legacy_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], 15272a93c1a3SFlorian Fainelli struct net_device *dev, 15282a93c1a3SFlorian Fainelli const unsigned char *addr, u16 vid, 152987b0984eSPetr Machata u16 flags, 153087b0984eSPetr Machata struct netlink_ext_ack *extack) 15312a93c1a3SFlorian Fainelli { 15322a93c1a3SFlorian Fainelli struct dsa_port *dp = dsa_slave_to_port(dev); 15332a93c1a3SFlorian Fainelli 15342a93c1a3SFlorian Fainelli return dsa_port_fdb_add(dp, addr, vid); 15352a93c1a3SFlorian Fainelli } 15362a93c1a3SFlorian Fainelli 15372a93c1a3SFlorian Fainelli int dsa_legacy_fdb_del(struct ndmsg *ndm, struct nlattr *tb[], 15382a93c1a3SFlorian Fainelli struct net_device *dev, 15392a93c1a3SFlorian Fainelli const unsigned char *addr, u16 vid) 15402a93c1a3SFlorian Fainelli { 15412a93c1a3SFlorian Fainelli struct dsa_port *dp = dsa_slave_to_port(dev); 15422a93c1a3SFlorian Fainelli 15432a93c1a3SFlorian Fainelli return dsa_port_fdb_del(dp, addr, vid); 15442a93c1a3SFlorian Fainelli } 15452a93c1a3SFlorian Fainelli 1546716efee2SJiri Pirko static struct devlink_port *dsa_slave_get_devlink_port(struct net_device *dev) 1547716efee2SJiri Pirko { 1548716efee2SJiri Pirko struct dsa_port *dp = dsa_slave_to_port(dev); 1549716efee2SJiri Pirko 1550716efee2SJiri Pirko return dp->ds->devlink ? &dp->devlink_port : NULL; 1551716efee2SJiri Pirko } 1552716efee2SJiri Pirko 15533e8a72d1SFlorian Fainelli static const struct net_device_ops dsa_slave_netdev_ops = { 1554d442ad4aSStephen Hemminger .ndo_open = dsa_slave_open, 1555d442ad4aSStephen Hemminger .ndo_stop = dsa_slave_close, 15563e8a72d1SFlorian Fainelli .ndo_start_xmit = dsa_slave_xmit, 1557d442ad4aSStephen Hemminger .ndo_change_rx_flags = dsa_slave_change_rx_flags, 1558d442ad4aSStephen Hemminger .ndo_set_rx_mode = dsa_slave_set_rx_mode, 1559d442ad4aSStephen Hemminger .ndo_set_mac_address = dsa_slave_set_mac_address, 156037b8da1aSArkadi Sharshevsky .ndo_fdb_add = dsa_legacy_fdb_add, 156137b8da1aSArkadi Sharshevsky .ndo_fdb_del = dsa_legacy_fdb_del, 15622bedde1aSArkadi Sharshevsky .ndo_fdb_dump = dsa_slave_fdb_dump, 1563d442ad4aSStephen Hemminger .ndo_do_ioctl = dsa_slave_ioctl, 1564abd2be00SNicolas Dichtel .ndo_get_iflink = dsa_slave_get_iflink, 156504ff53f9SFlorian Fainelli #ifdef CONFIG_NET_POLL_CONTROLLER 156604ff53f9SFlorian Fainelli .ndo_netpoll_setup = dsa_slave_netpoll_setup, 156704ff53f9SFlorian Fainelli .ndo_netpoll_cleanup = dsa_slave_netpoll_cleanup, 156804ff53f9SFlorian Fainelli .ndo_poll_controller = dsa_slave_poll_controller, 156904ff53f9SFlorian Fainelli #endif 157044bb765cSFlorian Fainelli .ndo_get_phys_port_name = dsa_slave_get_phys_port_name, 1571f50f2127SFlorian Fainelli .ndo_setup_tc = dsa_slave_setup_tc, 1572f613ed66SFlorian Fainelli .ndo_get_stats64 = dsa_slave_get_stats64, 1573929d6c14SFlorian Fainelli .ndo_get_port_parent_id = dsa_slave_get_port_parent_id, 1574061f6a50SFlorian Fainelli .ndo_vlan_rx_add_vid = dsa_slave_vlan_rx_add_vid, 1575061f6a50SFlorian Fainelli .ndo_vlan_rx_kill_vid = dsa_slave_vlan_rx_kill_vid, 1576716efee2SJiri Pirko .ndo_get_devlink_port = dsa_slave_get_devlink_port, 1577bfcb8132SVladimir Oltean .ndo_change_mtu = dsa_slave_change_mtu, 157898237d43SScott Feldman }; 157998237d43SScott Feldman 1580f37db85dSFlorian Fainelli static struct device_type dsa_type = { 1581f37db85dSFlorian Fainelli .name = "dsa", 1582f37db85dSFlorian Fainelli }; 1583f37db85dSFlorian Fainelli 1584aab9c406SFlorian Fainelli void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up) 1585aab9c406SFlorian Fainelli { 1586aab9c406SFlorian Fainelli const struct dsa_port *dp = dsa_to_port(ds, port); 1587aab9c406SFlorian Fainelli 1588765bda93SRussell King if (dp->pl) 1589aab9c406SFlorian Fainelli phylink_mac_change(dp->pl, up); 1590aab9c406SFlorian Fainelli } 1591aab9c406SFlorian Fainelli EXPORT_SYMBOL_GPL(dsa_port_phylink_mac_change); 1592aab9c406SFlorian Fainelli 1593*5c05c1dbSRussell King static void dsa_slave_phylink_fixed_state(struct phylink_config *config, 1594aab9c406SFlorian Fainelli struct phylink_link_state *state) 1595aab9c406SFlorian Fainelli { 1596*5c05c1dbSRussell King struct dsa_port *dp = container_of(config, struct dsa_port, pl_config); 1597aab9c406SFlorian Fainelli struct dsa_switch *ds = dp->ds; 1598aab9c406SFlorian Fainelli 1599aab9c406SFlorian Fainelli /* No need to check that this operation is valid, the callback would 1600aab9c406SFlorian Fainelli * not be called if it was not. 1601aab9c406SFlorian Fainelli */ 1602aab9c406SFlorian Fainelli ds->ops->phylink_fixed_state(ds, dp->index, state); 1603ce31b31cSFlorian Fainelli } 1604ce31b31cSFlorian Fainelli 160591da11f8SLennert Buytenhek /* slave device setup *******************************************************/ 16064fa7b718SVivien Didelot static int dsa_slave_phy_connect(struct net_device *slave_dev, int addr) 1607c305c165SFlorian Fainelli { 1608d945097bSVivien Didelot struct dsa_port *dp = dsa_slave_to_port(slave_dev); 1609d945097bSVivien Didelot struct dsa_switch *ds = dp->ds; 1610c305c165SFlorian Fainelli 16110115dcd1SVivien Didelot slave_dev->phydev = mdiobus_get_phy(ds->slave_mii_bus, addr); 16120115dcd1SVivien Didelot if (!slave_dev->phydev) { 1613d25b8e74SRussell King netdev_err(slave_dev, "no phy at %d\n", addr); 1614c305c165SFlorian Fainelli return -ENODEV; 1615d25b8e74SRussell King } 1616c305c165SFlorian Fainelli 1617aab9c406SFlorian Fainelli return phylink_connect_phy(dp->pl, slave_dev->phydev); 1618c305c165SFlorian Fainelli } 1619c305c165SFlorian Fainelli 16204fa7b718SVivien Didelot static int dsa_slave_phy_setup(struct net_device *slave_dev) 16210d8bcdd3SFlorian Fainelli { 1622d945097bSVivien Didelot struct dsa_port *dp = dsa_slave_to_port(slave_dev); 1623d945097bSVivien Didelot struct device_node *port_dn = dp->dn; 1624d945097bSVivien Didelot struct dsa_switch *ds = dp->ds; 16250c65b2b9SAndrew Lunn phy_interface_t mode; 16266819563eSFlorian Fainelli u32 phy_flags = 0; 16270c65b2b9SAndrew Lunn int ret; 16280d8bcdd3SFlorian Fainelli 16290c65b2b9SAndrew Lunn ret = of_get_phy_mode(port_dn, &mode); 16300c65b2b9SAndrew Lunn if (ret) 163119334920SGuenter Roeck mode = PHY_INTERFACE_MODE_NA; 16320d8bcdd3SFlorian Fainelli 163344cc27e4SIoana Ciornei dp->pl_config.dev = &slave_dev->dev; 163444cc27e4SIoana Ciornei dp->pl_config.type = PHYLINK_NETDEV; 163544cc27e4SIoana Ciornei 1636*5c05c1dbSRussell King /* The get_fixed_state callback takes precedence over polling the 1637*5c05c1dbSRussell King * link GPIO in PHYLINK (see phylink_get_fixed_state). Only set 1638*5c05c1dbSRussell King * this if the switch provides such a callback. 1639*5c05c1dbSRussell King */ 1640*5c05c1dbSRussell King if (ds->ops->phylink_fixed_state) { 1641*5c05c1dbSRussell King dp->pl_config.get_fixed_state = dsa_slave_phylink_fixed_state; 1642*5c05c1dbSRussell King dp->pl_config.poll_fixed_state = true; 1643*5c05c1dbSRussell King } 1644*5c05c1dbSRussell King 164544cc27e4SIoana Ciornei dp->pl = phylink_create(&dp->pl_config, of_fwnode_handle(port_dn), mode, 164677373d49SIoana Ciornei &dsa_port_phylink_mac_ops); 1647aab9c406SFlorian Fainelli if (IS_ERR(dp->pl)) { 1648aab9c406SFlorian Fainelli netdev_err(slave_dev, 1649aab9c406SFlorian Fainelli "error creating PHYLINK: %ld\n", PTR_ERR(dp->pl)); 1650aab9c406SFlorian Fainelli return PTR_ERR(dp->pl); 1651aab9c406SFlorian Fainelli } 1652aab9c406SFlorian Fainelli 16539d490b4eSVivien Didelot if (ds->ops->get_phy_flags) 1654d945097bSVivien Didelot phy_flags = ds->ops->get_phy_flags(ds, dp->index); 16556819563eSFlorian Fainelli 1656aab9c406SFlorian Fainelli ret = phylink_of_phy_connect(dp->pl, port_dn, phy_flags); 16576146dd45SVladimir Oltean if (ret == -ENODEV && ds->slave_mii_bus) { 16586146dd45SVladimir Oltean /* We could not connect to a designated PHY or SFP, so try to 16596146dd45SVladimir Oltean * use the switch internal MDIO bus instead 16600d8bcdd3SFlorian Fainelli */ 1661d945097bSVivien Didelot ret = dsa_slave_phy_connect(slave_dev, dp->index); 1662d25b8e74SRussell King if (ret) { 1663aab9c406SFlorian Fainelli netdev_err(slave_dev, 1664aab9c406SFlorian Fainelli "failed to connect to port %d: %d\n", 1665d945097bSVivien Didelot dp->index, ret); 1666aab9c406SFlorian Fainelli phylink_destroy(dp->pl); 1667c305c165SFlorian Fainelli return ret; 1668d25b8e74SRussell King } 16690d8bcdd3SFlorian Fainelli } 16709697f1cdSFlorian Fainelli 16716146dd45SVladimir Oltean return ret; 1672b31f65fbSAndrew Lunn } 16730d8bcdd3SFlorian Fainelli 167424462549SFlorian Fainelli int dsa_slave_suspend(struct net_device *slave_dev) 167524462549SFlorian Fainelli { 1676aab9c406SFlorian Fainelli struct dsa_port *dp = dsa_slave_to_port(slave_dev); 167724462549SFlorian Fainelli 1678a94c689eSFlorian Fainelli if (!netif_running(slave_dev)) 1679a94c689eSFlorian Fainelli return 0; 1680a94c689eSFlorian Fainelli 1681f154be24SFlorian Fainelli netif_device_detach(slave_dev); 1682f154be24SFlorian Fainelli 1683aab9c406SFlorian Fainelli rtnl_lock(); 1684aab9c406SFlorian Fainelli phylink_stop(dp->pl); 1685aab9c406SFlorian Fainelli rtnl_unlock(); 168624462549SFlorian Fainelli 168724462549SFlorian Fainelli return 0; 168824462549SFlorian Fainelli } 168924462549SFlorian Fainelli 169024462549SFlorian Fainelli int dsa_slave_resume(struct net_device *slave_dev) 169124462549SFlorian Fainelli { 1692aab9c406SFlorian Fainelli struct dsa_port *dp = dsa_slave_to_port(slave_dev); 1693aab9c406SFlorian Fainelli 1694a94c689eSFlorian Fainelli if (!netif_running(slave_dev)) 1695a94c689eSFlorian Fainelli return 0; 1696a94c689eSFlorian Fainelli 169724462549SFlorian Fainelli netif_device_attach(slave_dev); 169824462549SFlorian Fainelli 1699aab9c406SFlorian Fainelli rtnl_lock(); 1700aab9c406SFlorian Fainelli phylink_start(dp->pl); 1701aab9c406SFlorian Fainelli rtnl_unlock(); 170224462549SFlorian Fainelli 170324462549SFlorian Fainelli return 0; 170424462549SFlorian Fainelli } 170524462549SFlorian Fainelli 17066158eaa7SVivien Didelot static void dsa_slave_notify(struct net_device *dev, unsigned long val) 17076158eaa7SVivien Didelot { 1708d0006b00SVivien Didelot struct net_device *master = dsa_slave_to_master(dev); 1709d945097bSVivien Didelot struct dsa_port *dp = dsa_slave_to_port(dev); 17106158eaa7SVivien Didelot struct dsa_notifier_register_info rinfo = { 17116158eaa7SVivien Didelot .switch_number = dp->ds->index, 17126158eaa7SVivien Didelot .port_number = dp->index, 17136158eaa7SVivien Didelot .master = master, 17146158eaa7SVivien Didelot .info.dev = dev, 17156158eaa7SVivien Didelot }; 17166158eaa7SVivien Didelot 17176158eaa7SVivien Didelot call_dsa_notifiers(val, dev, &rinfo.info); 17186158eaa7SVivien Didelot } 17196158eaa7SVivien Didelot 1720951259aaSVivien Didelot int dsa_slave_create(struct dsa_port *port) 172191da11f8SLennert Buytenhek { 172224a9332aSVivien Didelot const struct dsa_port *cpu_dp = port->cpu_dp; 1723f8b8b1cdSVivien Didelot struct net_device *master = cpu_dp->master; 17244cfbf09cSVivien Didelot struct dsa_switch *ds = port->ds; 1725951259aaSVivien Didelot const char *name = port->name; 172691da11f8SLennert Buytenhek struct net_device *slave_dev; 172791da11f8SLennert Buytenhek struct dsa_slave_priv *p; 172891da11f8SLennert Buytenhek int ret; 172991da11f8SLennert Buytenhek 173055199df6SFlorian Fainelli if (!ds->num_tx_queues) 173155199df6SFlorian Fainelli ds->num_tx_queues = 1; 173255199df6SFlorian Fainelli 173355199df6SFlorian Fainelli slave_dev = alloc_netdev_mqs(sizeof(struct dsa_slave_priv), name, 173455199df6SFlorian Fainelli NET_NAME_UNKNOWN, ether_setup, 173555199df6SFlorian Fainelli ds->num_tx_queues, 1); 173691da11f8SLennert Buytenhek if (slave_dev == NULL) 1737d87d6f44SGuenter Roeck return -ENOMEM; 173891da11f8SLennert Buytenhek 17399b236d2aSVladimir Oltean slave_dev->features = master->vlan_features | NETIF_F_HW_TC; 17409b236d2aSVladimir Oltean if (ds->ops->port_vlan_add && ds->ops->port_vlan_del) 17419b236d2aSVladimir Oltean slave_dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; 1742f50f2127SFlorian Fainelli slave_dev->hw_features |= NETIF_F_HW_TC; 17437ad24ea4SWilfried Klaebe slave_dev->ethtool_ops = &dsa_slave_ethtool_ops; 17444974f9b7SPetr Štetiar if (!IS_ERR_OR_NULL(port->mac)) 1745a2c7023fSXiaofei Shen ether_addr_copy(slave_dev->dev_addr, port->mac); 1746a2c7023fSXiaofei Shen else 17472fcc8005SBjørn Mork eth_hw_addr_inherit(slave_dev, master); 17480a5f107bSPhil Sutter slave_dev->priv_flags |= IFF_NO_QUEUE; 17493e8a72d1SFlorian Fainelli slave_dev->netdev_ops = &dsa_slave_netdev_ops; 17508b1efc0fSJarod Wilson slave_dev->min_mtu = 0; 1751bfcb8132SVladimir Oltean if (ds->ops->port_max_mtu) 1752bfcb8132SVladimir Oltean slave_dev->max_mtu = ds->ops->port_max_mtu(ds, port->index); 1753bfcb8132SVladimir Oltean else 17548b1efc0fSJarod Wilson slave_dev->max_mtu = ETH_MAX_MTU; 1755f37db85dSFlorian Fainelli SET_NETDEV_DEVTYPE(slave_dev, &dsa_type); 1756d442ad4aSStephen Hemminger 17574cfbf09cSVivien Didelot SET_NETDEV_DEV(slave_dev, port->ds->dev); 17584cfbf09cSVivien Didelot slave_dev->dev.of_node = port->dn; 175991da11f8SLennert Buytenhek slave_dev->vlan_features = master->vlan_features; 176091da11f8SLennert Buytenhek 176191da11f8SLennert Buytenhek p = netdev_priv(slave_dev); 17625f6b4e14SFlorian Fainelli p->stats64 = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats); 17635f6b4e14SFlorian Fainelli if (!p->stats64) { 17645f6b4e14SFlorian Fainelli free_netdev(slave_dev); 17655f6b4e14SFlorian Fainelli return -ENOMEM; 17665f6b4e14SFlorian Fainelli } 1767e131a563SAlexander Lobakin 1768e131a563SAlexander Lobakin ret = gro_cells_init(&p->gcells, slave_dev); 1769e131a563SAlexander Lobakin if (ret) 1770e131a563SAlexander Lobakin goto out_free; 1771e131a563SAlexander Lobakin 17724cfbf09cSVivien Didelot p->dp = port; 1773f50f2127SFlorian Fainelli INIT_LIST_HEAD(&p->mall_tc_list); 177415240248SVivien Didelot p->xmit = cpu_dp->tag_ops->xmit; 1775f8b8b1cdSVivien Didelot port->slave = slave_dev; 177691da11f8SLennert Buytenhek 1777bfcb8132SVladimir Oltean rtnl_lock(); 1778bfcb8132SVladimir Oltean ret = dsa_slave_change_mtu(slave_dev, ETH_DATA_LEN); 1779bfcb8132SVladimir Oltean rtnl_unlock(); 1780bfcb8132SVladimir Oltean if (ret && ret != -EOPNOTSUPP) { 1781bfcb8132SVladimir Oltean dev_err(ds->dev, "error %d setting MTU on port %d\n", 1782bfcb8132SVladimir Oltean ret, port->index); 1783bfcb8132SVladimir Oltean goto out_free; 1784bfcb8132SVladimir Oltean } 1785bfcb8132SVladimir Oltean 178691da11f8SLennert Buytenhek netif_carrier_off(slave_dev); 178791da11f8SLennert Buytenhek 17884fa7b718SVivien Didelot ret = dsa_slave_phy_setup(slave_dev); 17890071f56eSAndrew Lunn if (ret) { 17900071f56eSAndrew Lunn netdev_err(master, "error %d setting up slave phy\n", ret); 1791e131a563SAlexander Lobakin goto out_gcells; 1792e804441cSFlorian Fainelli } 1793e804441cSFlorian Fainelli 17946158eaa7SVivien Didelot dsa_slave_notify(slave_dev, DSA_PORT_REGISTER); 179560724d4bSFlorian Fainelli 1796e804441cSFlorian Fainelli ret = register_netdev(slave_dev); 1797e804441cSFlorian Fainelli if (ret) { 1798e804441cSFlorian Fainelli netdev_err(master, "error %d registering interface %s\n", 1799e804441cSFlorian Fainelli ret, slave_dev->name); 1800e804441cSFlorian Fainelli goto out_phy; 18010071f56eSAndrew Lunn } 18020071f56eSAndrew Lunn 1803d87d6f44SGuenter Roeck return 0; 1804e804441cSFlorian Fainelli 1805e804441cSFlorian Fainelli out_phy: 1806aab9c406SFlorian Fainelli rtnl_lock(); 1807aab9c406SFlorian Fainelli phylink_disconnect_phy(p->dp->pl); 1808aab9c406SFlorian Fainelli rtnl_unlock(); 1809aab9c406SFlorian Fainelli phylink_destroy(p->dp->pl); 1810e131a563SAlexander Lobakin out_gcells: 1811e131a563SAlexander Lobakin gro_cells_destroy(&p->gcells); 1812e804441cSFlorian Fainelli out_free: 1813e804441cSFlorian Fainelli free_percpu(p->stats64); 1814e804441cSFlorian Fainelli free_netdev(slave_dev); 1815f8b8b1cdSVivien Didelot port->slave = NULL; 1816e804441cSFlorian Fainelli return ret; 181791da11f8SLennert Buytenhek } 1818b73adef6SFlorian Fainelli 1819cda5c15bSNeil Armstrong void dsa_slave_destroy(struct net_device *slave_dev) 1820cda5c15bSNeil Armstrong { 1821d945097bSVivien Didelot struct dsa_port *dp = dsa_slave_to_port(slave_dev); 1822cda5c15bSNeil Armstrong struct dsa_slave_priv *p = netdev_priv(slave_dev); 1823cda5c15bSNeil Armstrong 1824cda5c15bSNeil Armstrong netif_carrier_off(slave_dev); 1825aab9c406SFlorian Fainelli rtnl_lock(); 1826aab9c406SFlorian Fainelli phylink_disconnect_phy(dp->pl); 1827aab9c406SFlorian Fainelli rtnl_unlock(); 1828881eadabSJohan Hovold 18296158eaa7SVivien Didelot dsa_slave_notify(slave_dev, DSA_PORT_UNREGISTER); 1830cda5c15bSNeil Armstrong unregister_netdev(slave_dev); 1831aab9c406SFlorian Fainelli phylink_destroy(dp->pl); 1832e131a563SAlexander Lobakin gro_cells_destroy(&p->gcells); 18335f6b4e14SFlorian Fainelli free_percpu(p->stats64); 1834cda5c15bSNeil Armstrong free_netdev(slave_dev); 1835cda5c15bSNeil Armstrong } 1836cda5c15bSNeil Armstrong 18374d776482SFlorian Fainelli bool dsa_slave_dev_check(const struct net_device *dev) 1838b73adef6SFlorian Fainelli { 1839b73adef6SFlorian Fainelli return dev->netdev_ops == &dsa_slave_netdev_ops; 1840b73adef6SFlorian Fainelli } 1841b73adef6SFlorian Fainelli 18428e92ab3aSVivien Didelot static int dsa_slave_changeupper(struct net_device *dev, 18438e92ab3aSVivien Didelot struct netdev_notifier_changeupper_info *info) 1844b73adef6SFlorian Fainelli { 1845d945097bSVivien Didelot struct dsa_port *dp = dsa_slave_to_port(dev); 18468e92ab3aSVivien Didelot int err = NOTIFY_DONE; 1847b73adef6SFlorian Fainelli 18488e92ab3aSVivien Didelot if (netif_is_bridge_master(info->upper_dev)) { 18498e92ab3aSVivien Didelot if (info->linking) { 185017d7802bSVivien Didelot err = dsa_port_bridge_join(dp, info->upper_dev); 1851bff33f7eSVladimir Oltean if (!err) 1852bff33f7eSVladimir Oltean dsa_bridge_mtu_normalization(dp); 18538e92ab3aSVivien Didelot err = notifier_from_errno(err); 18548e92ab3aSVivien Didelot } else { 185517d7802bSVivien Didelot dsa_port_bridge_leave(dp, info->upper_dev); 18568e92ab3aSVivien Didelot err = NOTIFY_OK; 18578e92ab3aSVivien Didelot } 18586debb68aSVivien Didelot } 1859b73adef6SFlorian Fainelli 18608e92ab3aSVivien Didelot return err; 1861b73adef6SFlorian Fainelli } 1862b73adef6SFlorian Fainelli 1863cc1d5bdaSFlorian Fainelli static int dsa_slave_upper_vlan_check(struct net_device *dev, 1864cc1d5bdaSFlorian Fainelli struct netdev_notifier_changeupper_info * 1865cc1d5bdaSFlorian Fainelli info) 1866cc1d5bdaSFlorian Fainelli { 1867cc1d5bdaSFlorian Fainelli struct netlink_ext_ack *ext_ack; 1868cc1d5bdaSFlorian Fainelli struct net_device *slave; 1869cc1d5bdaSFlorian Fainelli struct dsa_port *dp; 1870cc1d5bdaSFlorian Fainelli 1871cc1d5bdaSFlorian Fainelli ext_ack = netdev_notifier_info_to_extack(&info->info); 1872cc1d5bdaSFlorian Fainelli 1873cc1d5bdaSFlorian Fainelli if (!is_vlan_dev(dev)) 1874cc1d5bdaSFlorian Fainelli return NOTIFY_DONE; 1875cc1d5bdaSFlorian Fainelli 1876cc1d5bdaSFlorian Fainelli slave = vlan_dev_real_dev(dev); 1877cc1d5bdaSFlorian Fainelli if (!dsa_slave_dev_check(slave)) 1878cc1d5bdaSFlorian Fainelli return NOTIFY_DONE; 1879cc1d5bdaSFlorian Fainelli 1880cc1d5bdaSFlorian Fainelli dp = dsa_slave_to_port(slave); 1881cc1d5bdaSFlorian Fainelli if (!dp->bridge_dev) 1882cc1d5bdaSFlorian Fainelli return NOTIFY_DONE; 1883cc1d5bdaSFlorian Fainelli 1884cc1d5bdaSFlorian Fainelli /* Deny enslaving a VLAN device into a VLAN-aware bridge */ 1885cc1d5bdaSFlorian Fainelli if (br_vlan_enabled(dp->bridge_dev) && 1886cc1d5bdaSFlorian Fainelli netif_is_bridge_master(info->upper_dev) && info->linking) { 1887cc1d5bdaSFlorian Fainelli NL_SET_ERR_MSG_MOD(ext_ack, 1888cc1d5bdaSFlorian Fainelli "Cannot enslave VLAN device into VLAN aware bridge"); 1889cc1d5bdaSFlorian Fainelli return notifier_from_errno(-EINVAL); 1890cc1d5bdaSFlorian Fainelli } 1891cc1d5bdaSFlorian Fainelli 1892cc1d5bdaSFlorian Fainelli return NOTIFY_DONE; 1893cc1d5bdaSFlorian Fainelli } 1894cc1d5bdaSFlorian Fainelli 189588e4f0caSVivien Didelot static int dsa_slave_netdevice_event(struct notifier_block *nb, 1896b73adef6SFlorian Fainelli unsigned long event, void *ptr) 1897b73adef6SFlorian Fainelli { 18986debb68aSVivien Didelot struct net_device *dev = netdev_notifier_info_to_dev(ptr); 1899b73adef6SFlorian Fainelli 1900cc1d5bdaSFlorian Fainelli if (event == NETDEV_CHANGEUPPER) { 190153bade8aSFlorian Fainelli if (!dsa_slave_dev_check(dev)) 1902cc1d5bdaSFlorian Fainelli return dsa_slave_upper_vlan_check(dev, ptr); 19038e92ab3aSVivien Didelot 19048e92ab3aSVivien Didelot return dsa_slave_changeupper(dev, ptr); 1905cc1d5bdaSFlorian Fainelli } 1906b73adef6SFlorian Fainelli 1907b73adef6SFlorian Fainelli return NOTIFY_DONE; 1908b73adef6SFlorian Fainelli } 190988e4f0caSVivien Didelot 1910c9eb3e0fSArkadi Sharshevsky struct dsa_switchdev_event_work { 1911c9eb3e0fSArkadi Sharshevsky struct work_struct work; 1912c9eb3e0fSArkadi Sharshevsky struct switchdev_notifier_fdb_info fdb_info; 1913c9eb3e0fSArkadi Sharshevsky struct net_device *dev; 1914c9eb3e0fSArkadi Sharshevsky unsigned long event; 1915c9eb3e0fSArkadi Sharshevsky }; 1916c9eb3e0fSArkadi Sharshevsky 1917c9eb3e0fSArkadi Sharshevsky static void dsa_slave_switchdev_event_work(struct work_struct *work) 1918c9eb3e0fSArkadi Sharshevsky { 1919c9eb3e0fSArkadi Sharshevsky struct dsa_switchdev_event_work *switchdev_work = 1920c9eb3e0fSArkadi Sharshevsky container_of(work, struct dsa_switchdev_event_work, work); 1921c9eb3e0fSArkadi Sharshevsky struct net_device *dev = switchdev_work->dev; 1922c9eb3e0fSArkadi Sharshevsky struct switchdev_notifier_fdb_info *fdb_info; 1923d945097bSVivien Didelot struct dsa_port *dp = dsa_slave_to_port(dev); 1924c9eb3e0fSArkadi Sharshevsky int err; 1925c9eb3e0fSArkadi Sharshevsky 1926c9eb3e0fSArkadi Sharshevsky rtnl_lock(); 1927c9eb3e0fSArkadi Sharshevsky switch (switchdev_work->event) { 1928c9eb3e0fSArkadi Sharshevsky case SWITCHDEV_FDB_ADD_TO_DEVICE: 1929c9eb3e0fSArkadi Sharshevsky fdb_info = &switchdev_work->fdb_info; 1930a37fb855SVivien Didelot if (!fdb_info->added_by_user) 1931a37fb855SVivien Didelot break; 1932a37fb855SVivien Didelot 1933d945097bSVivien Didelot err = dsa_port_fdb_add(dp, fdb_info->addr, fdb_info->vid); 1934c9eb3e0fSArkadi Sharshevsky if (err) { 1935c9eb3e0fSArkadi Sharshevsky netdev_dbg(dev, "fdb add failed err=%d\n", err); 1936c9eb3e0fSArkadi Sharshevsky break; 1937c9eb3e0fSArkadi Sharshevsky } 1938e9ba0fbcSIdo Schimmel fdb_info->offloaded = true; 1939c9eb3e0fSArkadi Sharshevsky call_switchdev_notifiers(SWITCHDEV_FDB_OFFLOADED, dev, 19406685987cSPetr Machata &fdb_info->info, NULL); 1941c9eb3e0fSArkadi Sharshevsky break; 1942c9eb3e0fSArkadi Sharshevsky 1943c9eb3e0fSArkadi Sharshevsky case SWITCHDEV_FDB_DEL_TO_DEVICE: 1944c9eb3e0fSArkadi Sharshevsky fdb_info = &switchdev_work->fdb_info; 1945a37fb855SVivien Didelot if (!fdb_info->added_by_user) 1946a37fb855SVivien Didelot break; 1947a37fb855SVivien Didelot 1948d945097bSVivien Didelot err = dsa_port_fdb_del(dp, fdb_info->addr, fdb_info->vid); 1949c9eb3e0fSArkadi Sharshevsky if (err) { 1950c9eb3e0fSArkadi Sharshevsky netdev_dbg(dev, "fdb del failed err=%d\n", err); 1951c9eb3e0fSArkadi Sharshevsky dev_close(dev); 1952c9eb3e0fSArkadi Sharshevsky } 1953c9eb3e0fSArkadi Sharshevsky break; 1954c9eb3e0fSArkadi Sharshevsky } 1955c9eb3e0fSArkadi Sharshevsky rtnl_unlock(); 1956c9eb3e0fSArkadi Sharshevsky 1957c9eb3e0fSArkadi Sharshevsky kfree(switchdev_work->fdb_info.addr); 1958c9eb3e0fSArkadi Sharshevsky kfree(switchdev_work); 1959c9eb3e0fSArkadi Sharshevsky dev_put(dev); 1960c9eb3e0fSArkadi Sharshevsky } 1961c9eb3e0fSArkadi Sharshevsky 1962c9eb3e0fSArkadi Sharshevsky static int 1963c9eb3e0fSArkadi Sharshevsky dsa_slave_switchdev_fdb_work_init(struct dsa_switchdev_event_work * 1964c9eb3e0fSArkadi Sharshevsky switchdev_work, 1965c9eb3e0fSArkadi Sharshevsky const struct switchdev_notifier_fdb_info * 1966c9eb3e0fSArkadi Sharshevsky fdb_info) 1967c9eb3e0fSArkadi Sharshevsky { 1968c9eb3e0fSArkadi Sharshevsky memcpy(&switchdev_work->fdb_info, fdb_info, 1969c9eb3e0fSArkadi Sharshevsky sizeof(switchdev_work->fdb_info)); 1970c9eb3e0fSArkadi Sharshevsky switchdev_work->fdb_info.addr = kzalloc(ETH_ALEN, GFP_ATOMIC); 1971c9eb3e0fSArkadi Sharshevsky if (!switchdev_work->fdb_info.addr) 1972c9eb3e0fSArkadi Sharshevsky return -ENOMEM; 1973c9eb3e0fSArkadi Sharshevsky ether_addr_copy((u8 *)switchdev_work->fdb_info.addr, 1974c9eb3e0fSArkadi Sharshevsky fdb_info->addr); 1975c9eb3e0fSArkadi Sharshevsky return 0; 1976c9eb3e0fSArkadi Sharshevsky } 1977c9eb3e0fSArkadi Sharshevsky 1978c9eb3e0fSArkadi Sharshevsky /* Called under rcu_read_lock() */ 1979c9eb3e0fSArkadi Sharshevsky static int dsa_slave_switchdev_event(struct notifier_block *unused, 1980c9eb3e0fSArkadi Sharshevsky unsigned long event, void *ptr) 1981c9eb3e0fSArkadi Sharshevsky { 1982c9eb3e0fSArkadi Sharshevsky struct net_device *dev = switchdev_notifier_info_to_dev(ptr); 1983c9eb3e0fSArkadi Sharshevsky struct dsa_switchdev_event_work *switchdev_work; 198479b139f4SVivien Didelot int err; 198579b139f4SVivien Didelot 198679b139f4SVivien Didelot if (event == SWITCHDEV_PORT_ATTR_SET) { 198779b139f4SVivien Didelot err = switchdev_handle_port_attr_set(dev, ptr, 198879b139f4SVivien Didelot dsa_slave_dev_check, 198979b139f4SVivien Didelot dsa_slave_port_attr_set); 199079b139f4SVivien Didelot return notifier_from_errno(err); 199179b139f4SVivien Didelot } 1992c9eb3e0fSArkadi Sharshevsky 1993c9eb3e0fSArkadi Sharshevsky if (!dsa_slave_dev_check(dev)) 1994c9eb3e0fSArkadi Sharshevsky return NOTIFY_DONE; 1995c9eb3e0fSArkadi Sharshevsky 1996c9eb3e0fSArkadi Sharshevsky switchdev_work = kzalloc(sizeof(*switchdev_work), GFP_ATOMIC); 1997c9eb3e0fSArkadi Sharshevsky if (!switchdev_work) 1998c9eb3e0fSArkadi Sharshevsky return NOTIFY_BAD; 1999c9eb3e0fSArkadi Sharshevsky 2000c9eb3e0fSArkadi Sharshevsky INIT_WORK(&switchdev_work->work, 2001c9eb3e0fSArkadi Sharshevsky dsa_slave_switchdev_event_work); 2002c9eb3e0fSArkadi Sharshevsky switchdev_work->dev = dev; 2003c9eb3e0fSArkadi Sharshevsky switchdev_work->event = event; 2004c9eb3e0fSArkadi Sharshevsky 2005c9eb3e0fSArkadi Sharshevsky switch (event) { 2006c9eb3e0fSArkadi Sharshevsky case SWITCHDEV_FDB_ADD_TO_DEVICE: /* fall through */ 2007c9eb3e0fSArkadi Sharshevsky case SWITCHDEV_FDB_DEL_TO_DEVICE: 2008a37fb855SVivien Didelot if (dsa_slave_switchdev_fdb_work_init(switchdev_work, ptr)) 2009c9eb3e0fSArkadi Sharshevsky goto err_fdb_work_init; 2010c9eb3e0fSArkadi Sharshevsky dev_hold(dev); 2011c9eb3e0fSArkadi Sharshevsky break; 2012c9eb3e0fSArkadi Sharshevsky default: 2013c9eb3e0fSArkadi Sharshevsky kfree(switchdev_work); 2014c9eb3e0fSArkadi Sharshevsky return NOTIFY_DONE; 2015c9eb3e0fSArkadi Sharshevsky } 2016c9eb3e0fSArkadi Sharshevsky 2017c9eb3e0fSArkadi Sharshevsky dsa_schedule_work(&switchdev_work->work); 2018c9eb3e0fSArkadi Sharshevsky return NOTIFY_OK; 2019c9eb3e0fSArkadi Sharshevsky 2020c9eb3e0fSArkadi Sharshevsky err_fdb_work_init: 2021c9eb3e0fSArkadi Sharshevsky kfree(switchdev_work); 2022c9eb3e0fSArkadi Sharshevsky return NOTIFY_BAD; 2023c9eb3e0fSArkadi Sharshevsky } 2024c9eb3e0fSArkadi Sharshevsky 20252b239f67SPetr Machata static int dsa_slave_switchdev_blocking_event(struct notifier_block *unused, 20262b239f67SPetr Machata unsigned long event, void *ptr) 20272b239f67SPetr Machata { 20282b239f67SPetr Machata struct net_device *dev = switchdev_notifier_info_to_dev(ptr); 202979b139f4SVivien Didelot int err; 20302b239f67SPetr Machata 20312b239f67SPetr Machata switch (event) { 203279b139f4SVivien Didelot case SWITCHDEV_PORT_OBJ_ADD: 203379b139f4SVivien Didelot err = switchdev_handle_port_obj_add(dev, ptr, 203479b139f4SVivien Didelot dsa_slave_dev_check, 203579b139f4SVivien Didelot dsa_slave_port_obj_add); 203679b139f4SVivien Didelot return notifier_from_errno(err); 20372b239f67SPetr Machata case SWITCHDEV_PORT_OBJ_DEL: 203879b139f4SVivien Didelot err = switchdev_handle_port_obj_del(dev, ptr, 203979b139f4SVivien Didelot dsa_slave_dev_check, 204079b139f4SVivien Didelot dsa_slave_port_obj_del); 204179b139f4SVivien Didelot return notifier_from_errno(err); 20429ed1ecedSFlorian Fainelli case SWITCHDEV_PORT_ATTR_SET: 204379b139f4SVivien Didelot err = switchdev_handle_port_attr_set(dev, ptr, 204479b139f4SVivien Didelot dsa_slave_dev_check, 204579b139f4SVivien Didelot dsa_slave_port_attr_set); 204679b139f4SVivien Didelot return notifier_from_errno(err); 20472b239f67SPetr Machata } 20482b239f67SPetr Machata 20492b239f67SPetr Machata return NOTIFY_DONE; 20502b239f67SPetr Machata } 20512b239f67SPetr Machata 205288e4f0caSVivien Didelot static struct notifier_block dsa_slave_nb __read_mostly = { 205388e4f0caSVivien Didelot .notifier_call = dsa_slave_netdevice_event, 205488e4f0caSVivien Didelot }; 205588e4f0caSVivien Didelot 2056c9eb3e0fSArkadi Sharshevsky static struct notifier_block dsa_slave_switchdev_notifier = { 2057c9eb3e0fSArkadi Sharshevsky .notifier_call = dsa_slave_switchdev_event, 2058c9eb3e0fSArkadi Sharshevsky }; 2059c9eb3e0fSArkadi Sharshevsky 20602b239f67SPetr Machata static struct notifier_block dsa_slave_switchdev_blocking_notifier = { 20612b239f67SPetr Machata .notifier_call = dsa_slave_switchdev_blocking_event, 20622b239f67SPetr Machata }; 20632b239f67SPetr Machata 206488e4f0caSVivien Didelot int dsa_slave_register_notifier(void) 206588e4f0caSVivien Didelot { 20662b239f67SPetr Machata struct notifier_block *nb; 2067c9eb3e0fSArkadi Sharshevsky int err; 2068c9eb3e0fSArkadi Sharshevsky 2069c9eb3e0fSArkadi Sharshevsky err = register_netdevice_notifier(&dsa_slave_nb); 2070c9eb3e0fSArkadi Sharshevsky if (err) 2071c9eb3e0fSArkadi Sharshevsky return err; 2072c9eb3e0fSArkadi Sharshevsky 2073c9eb3e0fSArkadi Sharshevsky err = register_switchdev_notifier(&dsa_slave_switchdev_notifier); 2074c9eb3e0fSArkadi Sharshevsky if (err) 2075c9eb3e0fSArkadi Sharshevsky goto err_switchdev_nb; 2076c9eb3e0fSArkadi Sharshevsky 20772b239f67SPetr Machata nb = &dsa_slave_switchdev_blocking_notifier; 20782b239f67SPetr Machata err = register_switchdev_blocking_notifier(nb); 20792b239f67SPetr Machata if (err) 20802b239f67SPetr Machata goto err_switchdev_blocking_nb; 20812b239f67SPetr Machata 2082c9eb3e0fSArkadi Sharshevsky return 0; 2083c9eb3e0fSArkadi Sharshevsky 20842b239f67SPetr Machata err_switchdev_blocking_nb: 20852b239f67SPetr Machata unregister_switchdev_notifier(&dsa_slave_switchdev_notifier); 2086c9eb3e0fSArkadi Sharshevsky err_switchdev_nb: 2087c9eb3e0fSArkadi Sharshevsky unregister_netdevice_notifier(&dsa_slave_nb); 2088c9eb3e0fSArkadi Sharshevsky return err; 208988e4f0caSVivien Didelot } 209088e4f0caSVivien Didelot 209188e4f0caSVivien Didelot void dsa_slave_unregister_notifier(void) 209288e4f0caSVivien Didelot { 20932b239f67SPetr Machata struct notifier_block *nb; 209488e4f0caSVivien Didelot int err; 209588e4f0caSVivien Didelot 20962b239f67SPetr Machata nb = &dsa_slave_switchdev_blocking_notifier; 20972b239f67SPetr Machata err = unregister_switchdev_blocking_notifier(nb); 20982b239f67SPetr Machata if (err) 20992b239f67SPetr Machata pr_err("DSA: failed to unregister switchdev blocking notifier (%d)\n", err); 21002b239f67SPetr Machata 2101c9eb3e0fSArkadi Sharshevsky err = unregister_switchdev_notifier(&dsa_slave_switchdev_notifier); 2102c9eb3e0fSArkadi Sharshevsky if (err) 2103c9eb3e0fSArkadi Sharshevsky pr_err("DSA: failed to unregister switchdev notifier (%d)\n", err); 2104c9eb3e0fSArkadi Sharshevsky 210588e4f0caSVivien Didelot err = unregister_netdevice_notifier(&dsa_slave_nb); 210688e4f0caSVivien Didelot if (err) 210788e4f0caSVivien Didelot pr_err("DSA: failed to unregister slave notifier (%d)\n", err); 210888e4f0caSVivien Didelot } 2109