12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 2f2f23566SVivien Didelot /* 3f2f23566SVivien Didelot * Handling of a master device, switching frames via its switch fabric CPU port 4f2f23566SVivien Didelot * 5f2f23566SVivien Didelot * Copyright (c) 2017 Savoir-faire Linux Inc. 6f2f23566SVivien Didelot * Vivien Didelot <vivien.didelot@savoirfairelinux.com> 7f2f23566SVivien Didelot */ 8f2f23566SVivien Didelot 9f2f23566SVivien Didelot #include "dsa_priv.h" 10f2f23566SVivien Didelot 1148e23311SVivien Didelot static int dsa_master_get_regs_len(struct net_device *dev) 1248e23311SVivien Didelot { 1348e23311SVivien Didelot struct dsa_port *cpu_dp = dev->dsa_ptr; 1448e23311SVivien Didelot const struct ethtool_ops *ops = cpu_dp->orig_ethtool_ops; 1548e23311SVivien Didelot struct dsa_switch *ds = cpu_dp->ds; 1648e23311SVivien Didelot int port = cpu_dp->index; 1748e23311SVivien Didelot int ret = 0; 1848e23311SVivien Didelot int len; 1948e23311SVivien Didelot 2048e23311SVivien Didelot if (ops->get_regs_len) { 2148e23311SVivien Didelot len = ops->get_regs_len(dev); 2248e23311SVivien Didelot if (len < 0) 2348e23311SVivien Didelot return len; 2448e23311SVivien Didelot ret += len; 2548e23311SVivien Didelot } 2648e23311SVivien Didelot 2748e23311SVivien Didelot ret += sizeof(struct ethtool_drvinfo); 2848e23311SVivien Didelot ret += sizeof(struct ethtool_regs); 2948e23311SVivien Didelot 3048e23311SVivien Didelot if (ds->ops->get_regs_len) { 3148e23311SVivien Didelot len = ds->ops->get_regs_len(ds, port); 3248e23311SVivien Didelot if (len < 0) 3348e23311SVivien Didelot return len; 3448e23311SVivien Didelot ret += len; 3548e23311SVivien Didelot } 3648e23311SVivien Didelot 3748e23311SVivien Didelot return ret; 3848e23311SVivien Didelot } 3948e23311SVivien Didelot 4048e23311SVivien Didelot static void dsa_master_get_regs(struct net_device *dev, 4148e23311SVivien Didelot struct ethtool_regs *regs, void *data) 4248e23311SVivien Didelot { 4348e23311SVivien Didelot struct dsa_port *cpu_dp = dev->dsa_ptr; 4448e23311SVivien Didelot const struct ethtool_ops *ops = cpu_dp->orig_ethtool_ops; 4548e23311SVivien Didelot struct dsa_switch *ds = cpu_dp->ds; 4648e23311SVivien Didelot struct ethtool_drvinfo *cpu_info; 4748e23311SVivien Didelot struct ethtool_regs *cpu_regs; 4848e23311SVivien Didelot int port = cpu_dp->index; 4948e23311SVivien Didelot int len; 5048e23311SVivien Didelot 5148e23311SVivien Didelot if (ops->get_regs_len && ops->get_regs) { 5248e23311SVivien Didelot len = ops->get_regs_len(dev); 5348e23311SVivien Didelot if (len < 0) 5448e23311SVivien Didelot return; 5548e23311SVivien Didelot regs->len = len; 5648e23311SVivien Didelot ops->get_regs(dev, regs, data); 5748e23311SVivien Didelot data += regs->len; 5848e23311SVivien Didelot } 5948e23311SVivien Didelot 6048e23311SVivien Didelot cpu_info = (struct ethtool_drvinfo *)data; 6148e23311SVivien Didelot strlcpy(cpu_info->driver, "dsa", sizeof(cpu_info->driver)); 6248e23311SVivien Didelot data += sizeof(*cpu_info); 6348e23311SVivien Didelot cpu_regs = (struct ethtool_regs *)data; 6448e23311SVivien Didelot data += sizeof(*cpu_regs); 6548e23311SVivien Didelot 6648e23311SVivien Didelot if (ds->ops->get_regs_len && ds->ops->get_regs) { 6748e23311SVivien Didelot len = ds->ops->get_regs_len(ds, port); 6848e23311SVivien Didelot if (len < 0) 6948e23311SVivien Didelot return; 7048e23311SVivien Didelot cpu_regs->len = len; 7148e23311SVivien Didelot ds->ops->get_regs(ds, port, cpu_regs, data); 7248e23311SVivien Didelot } 7348e23311SVivien Didelot } 7448e23311SVivien Didelot 75f2f23566SVivien Didelot static void dsa_master_get_ethtool_stats(struct net_device *dev, 76f2f23566SVivien Didelot struct ethtool_stats *stats, 77f2f23566SVivien Didelot uint64_t *data) 78f2f23566SVivien Didelot { 792f657a60SVivien Didelot struct dsa_port *cpu_dp = dev->dsa_ptr; 807ec764eeSVivien Didelot const struct ethtool_ops *ops = cpu_dp->orig_ethtool_ops; 817ec764eeSVivien Didelot struct dsa_switch *ds = cpu_dp->ds; 827ec764eeSVivien Didelot int port = cpu_dp->index; 83f2f23566SVivien Didelot int count = 0; 84f2f23566SVivien Didelot 851d1e79f1SFlorian Fainelli if (ops->get_sset_count && ops->get_ethtool_stats) { 86f2f23566SVivien Didelot count = ops->get_sset_count(dev, ETH_SS_STATS); 87f2f23566SVivien Didelot ops->get_ethtool_stats(dev, stats, data); 88f2f23566SVivien Didelot } 89f2f23566SVivien Didelot 90f2f23566SVivien Didelot if (ds->ops->get_ethtool_stats) 917ec764eeSVivien Didelot ds->ops->get_ethtool_stats(ds, port, data + count); 92f2f23566SVivien Didelot } 93f2f23566SVivien Didelot 94cf963573SFlorian Fainelli static void dsa_master_get_ethtool_phy_stats(struct net_device *dev, 95cf963573SFlorian Fainelli struct ethtool_stats *stats, 96cf963573SFlorian Fainelli uint64_t *data) 97cf963573SFlorian Fainelli { 98cf963573SFlorian Fainelli struct dsa_port *cpu_dp = dev->dsa_ptr; 99cf963573SFlorian Fainelli const struct ethtool_ops *ops = cpu_dp->orig_ethtool_ops; 100cf963573SFlorian Fainelli struct dsa_switch *ds = cpu_dp->ds; 101cf963573SFlorian Fainelli int port = cpu_dp->index; 102cf963573SFlorian Fainelli int count = 0; 103cf963573SFlorian Fainelli 104cf963573SFlorian Fainelli if (dev->phydev && !ops->get_ethtool_phy_stats) { 105cf963573SFlorian Fainelli count = phy_ethtool_get_sset_count(dev->phydev); 106cf963573SFlorian Fainelli if (count >= 0) 107cf963573SFlorian Fainelli phy_ethtool_get_stats(dev->phydev, stats, data); 108cf963573SFlorian Fainelli } else if (ops->get_sset_count && ops->get_ethtool_phy_stats) { 109cf963573SFlorian Fainelli count = ops->get_sset_count(dev, ETH_SS_PHY_STATS); 110cf963573SFlorian Fainelli ops->get_ethtool_phy_stats(dev, stats, data); 111cf963573SFlorian Fainelli } 112cf963573SFlorian Fainelli 113cf963573SFlorian Fainelli if (count < 0) 114cf963573SFlorian Fainelli count = 0; 115cf963573SFlorian Fainelli 116cf963573SFlorian Fainelli if (ds->ops->get_ethtool_phy_stats) 117cf963573SFlorian Fainelli ds->ops->get_ethtool_phy_stats(ds, port, data + count); 118cf963573SFlorian Fainelli } 119cf963573SFlorian Fainelli 120f2f23566SVivien Didelot static int dsa_master_get_sset_count(struct net_device *dev, int sset) 121f2f23566SVivien Didelot { 1222f657a60SVivien Didelot struct dsa_port *cpu_dp = dev->dsa_ptr; 1237ec764eeSVivien Didelot const struct ethtool_ops *ops = cpu_dp->orig_ethtool_ops; 1247ec764eeSVivien Didelot struct dsa_switch *ds = cpu_dp->ds; 125f2f23566SVivien Didelot int count = 0; 126f2f23566SVivien Didelot 127cf963573SFlorian Fainelli if (sset == ETH_SS_PHY_STATS && dev->phydev && 128cf963573SFlorian Fainelli !ops->get_ethtool_phy_stats) 129cf963573SFlorian Fainelli count = phy_ethtool_get_sset_count(dev->phydev); 130cf963573SFlorian Fainelli else if (ops->get_sset_count) 13189f09048SFlorian Fainelli count = ops->get_sset_count(dev, sset); 132cf963573SFlorian Fainelli 13389f09048SFlorian Fainelli if (count < 0) 13489f09048SFlorian Fainelli count = 0; 135f2f23566SVivien Didelot 13689f09048SFlorian Fainelli if (ds->ops->get_sset_count) 13789f09048SFlorian Fainelli count += ds->ops->get_sset_count(ds, cpu_dp->index, sset); 138f2f23566SVivien Didelot 139f2f23566SVivien Didelot return count; 140f2f23566SVivien Didelot } 141f2f23566SVivien Didelot 142f2f23566SVivien Didelot static void dsa_master_get_strings(struct net_device *dev, uint32_t stringset, 143f2f23566SVivien Didelot uint8_t *data) 144f2f23566SVivien Didelot { 1452f657a60SVivien Didelot struct dsa_port *cpu_dp = dev->dsa_ptr; 1467ec764eeSVivien Didelot const struct ethtool_ops *ops = cpu_dp->orig_ethtool_ops; 1477ec764eeSVivien Didelot struct dsa_switch *ds = cpu_dp->ds; 1487ec764eeSVivien Didelot int port = cpu_dp->index; 149f2f23566SVivien Didelot int len = ETH_GSTRING_LEN; 150f2f23566SVivien Didelot int mcount = 0, count; 151f2f23566SVivien Didelot unsigned int i; 152f2f23566SVivien Didelot uint8_t pfx[4]; 153f2f23566SVivien Didelot uint8_t *ndata; 154f2f23566SVivien Didelot 1557ec764eeSVivien Didelot snprintf(pfx, sizeof(pfx), "p%.2d", port); 156f2f23566SVivien Didelot /* We do not want to be NULL-terminated, since this is a prefix */ 157f2f23566SVivien Didelot pfx[sizeof(pfx) - 1] = '_'; 158f2f23566SVivien Didelot 159cf963573SFlorian Fainelli if (stringset == ETH_SS_PHY_STATS && dev->phydev && 160cf963573SFlorian Fainelli !ops->get_ethtool_phy_stats) { 161cf963573SFlorian Fainelli mcount = phy_ethtool_get_sset_count(dev->phydev); 162cf963573SFlorian Fainelli if (mcount < 0) 163cf963573SFlorian Fainelli mcount = 0; 164cf963573SFlorian Fainelli else 165cf963573SFlorian Fainelli phy_ethtool_get_strings(dev->phydev, data); 166cf963573SFlorian Fainelli } else if (ops->get_sset_count && ops->get_strings) { 16789f09048SFlorian Fainelli mcount = ops->get_sset_count(dev, stringset); 16889f09048SFlorian Fainelli if (mcount < 0) 16989f09048SFlorian Fainelli mcount = 0; 170f2f23566SVivien Didelot ops->get_strings(dev, stringset, data); 171f2f23566SVivien Didelot } 172f2f23566SVivien Didelot 17389f09048SFlorian Fainelli if (ds->ops->get_strings) { 174f2f23566SVivien Didelot ndata = data + mcount * len; 175f2f23566SVivien Didelot /* This function copies ETH_GSTRINGS_LEN bytes, we will mangle 176f2f23566SVivien Didelot * the output after to prepend our CPU port prefix we 177f2f23566SVivien Didelot * constructed earlier 178f2f23566SVivien Didelot */ 17989f09048SFlorian Fainelli ds->ops->get_strings(ds, port, stringset, ndata); 18089f09048SFlorian Fainelli count = ds->ops->get_sset_count(ds, port, stringset); 181f2f23566SVivien Didelot for (i = 0; i < count; i++) { 182f2f23566SVivien Didelot memmove(ndata + (i * len + sizeof(pfx)), 183f2f23566SVivien Didelot ndata + i * len, len - sizeof(pfx)); 184f2f23566SVivien Didelot memcpy(ndata + i * len, pfx, sizeof(pfx)); 185f2f23566SVivien Didelot } 186f2f23566SVivien Didelot } 187f2f23566SVivien Didelot } 188f2f23566SVivien Didelot 189da7b9e9bSFlorian Fainelli static int dsa_master_get_phys_port_name(struct net_device *dev, 190da7b9e9bSFlorian Fainelli char *name, size_t len) 191da7b9e9bSFlorian Fainelli { 192da7b9e9bSFlorian Fainelli struct dsa_port *cpu_dp = dev->dsa_ptr; 193da7b9e9bSFlorian Fainelli 194da7b9e9bSFlorian Fainelli if (snprintf(name, len, "p%d", cpu_dp->index) >= len) 195da7b9e9bSFlorian Fainelli return -EINVAL; 196da7b9e9bSFlorian Fainelli 197da7b9e9bSFlorian Fainelli return 0; 198da7b9e9bSFlorian Fainelli } 199da7b9e9bSFlorian Fainelli 200*f685e609SVladimir Oltean static int dsa_master_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) 201*f685e609SVladimir Oltean { 202*f685e609SVladimir Oltean struct dsa_port *cpu_dp = dev->dsa_ptr; 203*f685e609SVladimir Oltean struct dsa_switch *ds = cpu_dp->ds; 204*f685e609SVladimir Oltean struct dsa_switch_tree *dst; 205*f685e609SVladimir Oltean int err = -EOPNOTSUPP; 206*f685e609SVladimir Oltean struct dsa_port *dp; 207*f685e609SVladimir Oltean 208*f685e609SVladimir Oltean dst = ds->dst; 209*f685e609SVladimir Oltean 210*f685e609SVladimir Oltean switch (cmd) { 211*f685e609SVladimir Oltean case SIOCGHWTSTAMP: 212*f685e609SVladimir Oltean case SIOCSHWTSTAMP: 213*f685e609SVladimir Oltean /* Deny PTP operations on master if there is at least one 214*f685e609SVladimir Oltean * switch in the tree that is PTP capable. 215*f685e609SVladimir Oltean */ 216*f685e609SVladimir Oltean list_for_each_entry(dp, &dst->ports, list) 217*f685e609SVladimir Oltean if (dp->ds->ops->port_hwtstamp_get || 218*f685e609SVladimir Oltean dp->ds->ops->port_hwtstamp_set) 219*f685e609SVladimir Oltean return -EBUSY; 220*f685e609SVladimir Oltean break; 221*f685e609SVladimir Oltean } 222*f685e609SVladimir Oltean 223*f685e609SVladimir Oltean if (cpu_dp->orig_ndo_ops && cpu_dp->orig_ndo_ops->ndo_do_ioctl) 224*f685e609SVladimir Oltean err = cpu_dp->orig_ndo_ops->ndo_do_ioctl(dev, ifr, cmd); 225*f685e609SVladimir Oltean 226*f685e609SVladimir Oltean return err; 227*f685e609SVladimir Oltean } 228*f685e609SVladimir Oltean 22917a22fcfSVivien Didelot static int dsa_master_ethtool_setup(struct net_device *dev) 230f2f23566SVivien Didelot { 2312f657a60SVivien Didelot struct dsa_port *cpu_dp = dev->dsa_ptr; 2327ec764eeSVivien Didelot struct dsa_switch *ds = cpu_dp->ds; 233f2f23566SVivien Didelot struct ethtool_ops *ops; 234f2f23566SVivien Didelot 235f2f23566SVivien Didelot ops = devm_kzalloc(ds->dev, sizeof(*ops), GFP_KERNEL); 236f2f23566SVivien Didelot if (!ops) 237f2f23566SVivien Didelot return -ENOMEM; 238f2f23566SVivien Didelot 2397ec764eeSVivien Didelot cpu_dp->orig_ethtool_ops = dev->ethtool_ops; 2407ec764eeSVivien Didelot if (cpu_dp->orig_ethtool_ops) 2417ec764eeSVivien Didelot memcpy(ops, cpu_dp->orig_ethtool_ops, sizeof(*ops)); 242f2f23566SVivien Didelot 24348e23311SVivien Didelot ops->get_regs_len = dsa_master_get_regs_len; 24448e23311SVivien Didelot ops->get_regs = dsa_master_get_regs; 245f2f23566SVivien Didelot ops->get_sset_count = dsa_master_get_sset_count; 246f2f23566SVivien Didelot ops->get_ethtool_stats = dsa_master_get_ethtool_stats; 247f2f23566SVivien Didelot ops->get_strings = dsa_master_get_strings; 248cf963573SFlorian Fainelli ops->get_ethtool_phy_stats = dsa_master_get_ethtool_phy_stats; 249f2f23566SVivien Didelot 250f2f23566SVivien Didelot dev->ethtool_ops = ops; 251f2f23566SVivien Didelot 252f2f23566SVivien Didelot return 0; 253f2f23566SVivien Didelot } 254f2f23566SVivien Didelot 25517a22fcfSVivien Didelot static void dsa_master_ethtool_teardown(struct net_device *dev) 256f2f23566SVivien Didelot { 2572f657a60SVivien Didelot struct dsa_port *cpu_dp = dev->dsa_ptr; 258f2f23566SVivien Didelot 2597ec764eeSVivien Didelot dev->ethtool_ops = cpu_dp->orig_ethtool_ops; 2607ec764eeSVivien Didelot cpu_dp->orig_ethtool_ops = NULL; 261f2f23566SVivien Didelot } 26217a22fcfSVivien Didelot 263da7b9e9bSFlorian Fainelli static int dsa_master_ndo_setup(struct net_device *dev) 264da7b9e9bSFlorian Fainelli { 265da7b9e9bSFlorian Fainelli struct dsa_port *cpu_dp = dev->dsa_ptr; 266da7b9e9bSFlorian Fainelli struct dsa_switch *ds = cpu_dp->ds; 267da7b9e9bSFlorian Fainelli struct net_device_ops *ops; 268da7b9e9bSFlorian Fainelli 269da7b9e9bSFlorian Fainelli if (dev->netdev_ops->ndo_get_phys_port_name) 270da7b9e9bSFlorian Fainelli return 0; 271da7b9e9bSFlorian Fainelli 272da7b9e9bSFlorian Fainelli ops = devm_kzalloc(ds->dev, sizeof(*ops), GFP_KERNEL); 273da7b9e9bSFlorian Fainelli if (!ops) 274da7b9e9bSFlorian Fainelli return -ENOMEM; 275da7b9e9bSFlorian Fainelli 276da7b9e9bSFlorian Fainelli cpu_dp->orig_ndo_ops = dev->netdev_ops; 277da7b9e9bSFlorian Fainelli if (cpu_dp->orig_ndo_ops) 278da7b9e9bSFlorian Fainelli memcpy(ops, cpu_dp->orig_ndo_ops, sizeof(*ops)); 279da7b9e9bSFlorian Fainelli 280da7b9e9bSFlorian Fainelli ops->ndo_get_phys_port_name = dsa_master_get_phys_port_name; 281*f685e609SVladimir Oltean ops->ndo_do_ioctl = dsa_master_ioctl; 282da7b9e9bSFlorian Fainelli 283da7b9e9bSFlorian Fainelli dev->netdev_ops = ops; 284da7b9e9bSFlorian Fainelli 285da7b9e9bSFlorian Fainelli return 0; 286da7b9e9bSFlorian Fainelli } 287da7b9e9bSFlorian Fainelli 288da7b9e9bSFlorian Fainelli static void dsa_master_ndo_teardown(struct net_device *dev) 289da7b9e9bSFlorian Fainelli { 290da7b9e9bSFlorian Fainelli struct dsa_port *cpu_dp = dev->dsa_ptr; 291da7b9e9bSFlorian Fainelli 292da7b9e9bSFlorian Fainelli dev->netdev_ops = cpu_dp->orig_ndo_ops; 293da7b9e9bSFlorian Fainelli cpu_dp->orig_ndo_ops = NULL; 294da7b9e9bSFlorian Fainelli } 295da7b9e9bSFlorian Fainelli 296a3d7e01dSFlorian Fainelli static ssize_t tagging_show(struct device *d, struct device_attribute *attr, 297a3d7e01dSFlorian Fainelli char *buf) 298a3d7e01dSFlorian Fainelli { 299a3d7e01dSFlorian Fainelli struct net_device *dev = to_net_dev(d); 300a3d7e01dSFlorian Fainelli struct dsa_port *cpu_dp = dev->dsa_ptr; 301a3d7e01dSFlorian Fainelli 302a3d7e01dSFlorian Fainelli return sprintf(buf, "%s\n", 303a3d7e01dSFlorian Fainelli dsa_tag_protocol_to_str(cpu_dp->tag_ops)); 304a3d7e01dSFlorian Fainelli } 305a3d7e01dSFlorian Fainelli static DEVICE_ATTR_RO(tagging); 306a3d7e01dSFlorian Fainelli 307a3d7e01dSFlorian Fainelli static struct attribute *dsa_slave_attrs[] = { 308a3d7e01dSFlorian Fainelli &dev_attr_tagging.attr, 309a3d7e01dSFlorian Fainelli NULL 310a3d7e01dSFlorian Fainelli }; 311a3d7e01dSFlorian Fainelli 312a3d7e01dSFlorian Fainelli static const struct attribute_group dsa_group = { 313a3d7e01dSFlorian Fainelli .name = "dsa", 314a3d7e01dSFlorian Fainelli .attrs = dsa_slave_attrs, 315a3d7e01dSFlorian Fainelli }; 316a3d7e01dSFlorian Fainelli 317a60956edSAndrew Lunn static void dsa_master_set_mtu(struct net_device *dev, struct dsa_port *cpu_dp) 318dc0fe7d4SAndrew Lunn { 319dc0fe7d4SAndrew Lunn unsigned int mtu = ETH_DATA_LEN + cpu_dp->tag_ops->overhead; 320dc0fe7d4SAndrew Lunn int err; 321dc0fe7d4SAndrew Lunn 322dc0fe7d4SAndrew Lunn rtnl_lock(); 323dc0fe7d4SAndrew Lunn if (mtu <= dev->max_mtu) { 324dc0fe7d4SAndrew Lunn err = dev_set_mtu(dev, mtu); 325dc0fe7d4SAndrew Lunn if (err) 326dc0fe7d4SAndrew Lunn netdev_dbg(dev, "Unable to set MTU to include for DSA overheads\n"); 327dc0fe7d4SAndrew Lunn } 328dc0fe7d4SAndrew Lunn rtnl_unlock(); 329dc0fe7d4SAndrew Lunn } 330dc0fe7d4SAndrew Lunn 33191ba4795SAndrew Lunn static void dsa_master_reset_mtu(struct net_device *dev) 33291ba4795SAndrew Lunn { 33391ba4795SAndrew Lunn int err; 33491ba4795SAndrew Lunn 33591ba4795SAndrew Lunn rtnl_lock(); 33691ba4795SAndrew Lunn err = dev_set_mtu(dev, ETH_DATA_LEN); 33791ba4795SAndrew Lunn if (err) 33891ba4795SAndrew Lunn netdev_dbg(dev, 33991ba4795SAndrew Lunn "Unable to reset MTU to exclude DSA overheads\n"); 34091ba4795SAndrew Lunn rtnl_unlock(); 34191ba4795SAndrew Lunn } 34291ba4795SAndrew Lunn 34317a22fcfSVivien Didelot int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp) 34417a22fcfSVivien Didelot { 345a3d7e01dSFlorian Fainelli int ret; 346a3d7e01dSFlorian Fainelli 347dc0fe7d4SAndrew Lunn dsa_master_set_mtu(dev, cpu_dp); 348dc0fe7d4SAndrew Lunn 34917a22fcfSVivien Didelot /* If we use a tagging format that doesn't have an ethertype 35017a22fcfSVivien Didelot * field, make sure that all packets from this point on get 35117a22fcfSVivien Didelot * sent to the tag format's receive function. 35217a22fcfSVivien Didelot */ 35317a22fcfSVivien Didelot wmb(); 35417a22fcfSVivien Didelot 35517a22fcfSVivien Didelot dev->dsa_ptr = cpu_dp; 356a3d7e01dSFlorian Fainelli ret = dsa_master_ethtool_setup(dev); 357a3d7e01dSFlorian Fainelli if (ret) 358a3d7e01dSFlorian Fainelli return ret; 359a3d7e01dSFlorian Fainelli 360da7b9e9bSFlorian Fainelli ret = dsa_master_ndo_setup(dev); 361da7b9e9bSFlorian Fainelli if (ret) 362da7b9e9bSFlorian Fainelli goto out_err_ethtool_teardown; 363da7b9e9bSFlorian Fainelli 364a3d7e01dSFlorian Fainelli ret = sysfs_create_group(&dev->dev.kobj, &dsa_group); 365a3d7e01dSFlorian Fainelli if (ret) 366da7b9e9bSFlorian Fainelli goto out_err_ndo_teardown; 367a3d7e01dSFlorian Fainelli 368a3d7e01dSFlorian Fainelli return ret; 369da7b9e9bSFlorian Fainelli 370da7b9e9bSFlorian Fainelli out_err_ndo_teardown: 371da7b9e9bSFlorian Fainelli dsa_master_ndo_teardown(dev); 372da7b9e9bSFlorian Fainelli out_err_ethtool_teardown: 373da7b9e9bSFlorian Fainelli dsa_master_ethtool_teardown(dev); 374da7b9e9bSFlorian Fainelli return ret; 37517a22fcfSVivien Didelot } 37617a22fcfSVivien Didelot 37717a22fcfSVivien Didelot void dsa_master_teardown(struct net_device *dev) 37817a22fcfSVivien Didelot { 379a3d7e01dSFlorian Fainelli sysfs_remove_group(&dev->dev.kobj, &dsa_group); 380da7b9e9bSFlorian Fainelli dsa_master_ndo_teardown(dev); 38117a22fcfSVivien Didelot dsa_master_ethtool_teardown(dev); 38291ba4795SAndrew Lunn dsa_master_reset_mtu(dev); 38317a22fcfSVivien Didelot 38417a22fcfSVivien Didelot dev->dsa_ptr = NULL; 38517a22fcfSVivien Didelot 38617a22fcfSVivien Didelot /* If we used a tagging format that doesn't have an ethertype 38717a22fcfSVivien Didelot * field, make sure that all packets from this point get sent 38817a22fcfSVivien Didelot * without the tag and go through the regular receive path. 38917a22fcfSVivien Didelot */ 39017a22fcfSVivien Didelot wmb(); 39117a22fcfSVivien Didelot } 392