Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Vivien Didelot | f2f2356 | 2017-09-19 11:57:00 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Handling of a master device, switching frames via its switch fabric CPU port |
| 4 | * |
| 5 | * Copyright (c) 2017 Savoir-faire Linux Inc. |
| 6 | * Vivien Didelot <vivien.didelot@savoirfairelinux.com> |
Vivien Didelot | f2f2356 | 2017-09-19 11:57:00 -0400 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include "dsa_priv.h" |
| 10 | |
Vivien Didelot | 48e2331 | 2019-08-02 15:34:55 -0400 | [diff] [blame] | 11 | static int dsa_master_get_regs_len(struct net_device *dev) |
| 12 | { |
| 13 | struct dsa_port *cpu_dp = dev->dsa_ptr; |
| 14 | const struct ethtool_ops *ops = cpu_dp->orig_ethtool_ops; |
| 15 | struct dsa_switch *ds = cpu_dp->ds; |
| 16 | int port = cpu_dp->index; |
| 17 | int ret = 0; |
| 18 | int len; |
| 19 | |
| 20 | if (ops->get_regs_len) { |
| 21 | len = ops->get_regs_len(dev); |
| 22 | if (len < 0) |
| 23 | return len; |
| 24 | ret += len; |
| 25 | } |
| 26 | |
| 27 | ret += sizeof(struct ethtool_drvinfo); |
| 28 | ret += sizeof(struct ethtool_regs); |
| 29 | |
| 30 | if (ds->ops->get_regs_len) { |
| 31 | len = ds->ops->get_regs_len(ds, port); |
| 32 | if (len < 0) |
| 33 | return len; |
| 34 | ret += len; |
| 35 | } |
| 36 | |
| 37 | return ret; |
| 38 | } |
| 39 | |
| 40 | static void dsa_master_get_regs(struct net_device *dev, |
| 41 | struct ethtool_regs *regs, void *data) |
| 42 | { |
| 43 | struct dsa_port *cpu_dp = dev->dsa_ptr; |
| 44 | const struct ethtool_ops *ops = cpu_dp->orig_ethtool_ops; |
| 45 | struct dsa_switch *ds = cpu_dp->ds; |
| 46 | struct ethtool_drvinfo *cpu_info; |
| 47 | struct ethtool_regs *cpu_regs; |
| 48 | int port = cpu_dp->index; |
| 49 | int len; |
| 50 | |
| 51 | if (ops->get_regs_len && ops->get_regs) { |
| 52 | len = ops->get_regs_len(dev); |
| 53 | if (len < 0) |
| 54 | return; |
| 55 | regs->len = len; |
| 56 | ops->get_regs(dev, regs, data); |
| 57 | data += regs->len; |
| 58 | } |
| 59 | |
| 60 | cpu_info = (struct ethtool_drvinfo *)data; |
| 61 | strlcpy(cpu_info->driver, "dsa", sizeof(cpu_info->driver)); |
| 62 | data += sizeof(*cpu_info); |
| 63 | cpu_regs = (struct ethtool_regs *)data; |
| 64 | data += sizeof(*cpu_regs); |
| 65 | |
| 66 | if (ds->ops->get_regs_len && ds->ops->get_regs) { |
| 67 | len = ds->ops->get_regs_len(ds, port); |
| 68 | if (len < 0) |
| 69 | return; |
| 70 | cpu_regs->len = len; |
| 71 | ds->ops->get_regs(ds, port, cpu_regs, data); |
| 72 | } |
| 73 | } |
| 74 | |
Vivien Didelot | f2f2356 | 2017-09-19 11:57:00 -0400 | [diff] [blame] | 75 | static void dsa_master_get_ethtool_stats(struct net_device *dev, |
| 76 | struct ethtool_stats *stats, |
| 77 | uint64_t *data) |
| 78 | { |
Vivien Didelot | 2f657a6 | 2017-09-29 17:19:20 -0400 | [diff] [blame] | 79 | struct dsa_port *cpu_dp = dev->dsa_ptr; |
Vivien Didelot | 7ec764e | 2017-09-29 17:19:16 -0400 | [diff] [blame] | 80 | const struct ethtool_ops *ops = cpu_dp->orig_ethtool_ops; |
| 81 | struct dsa_switch *ds = cpu_dp->ds; |
| 82 | int port = cpu_dp->index; |
Vivien Didelot | f2f2356 | 2017-09-19 11:57:00 -0400 | [diff] [blame] | 83 | int count = 0; |
| 84 | |
Florian Fainelli | 1d1e79f | 2018-04-25 12:12:49 -0700 | [diff] [blame] | 85 | if (ops->get_sset_count && ops->get_ethtool_stats) { |
Vivien Didelot | f2f2356 | 2017-09-19 11:57:00 -0400 | [diff] [blame] | 86 | count = ops->get_sset_count(dev, ETH_SS_STATS); |
| 87 | ops->get_ethtool_stats(dev, stats, data); |
| 88 | } |
| 89 | |
| 90 | if (ds->ops->get_ethtool_stats) |
Vivien Didelot | 7ec764e | 2017-09-29 17:19:16 -0400 | [diff] [blame] | 91 | ds->ops->get_ethtool_stats(ds, port, data + count); |
Vivien Didelot | f2f2356 | 2017-09-19 11:57:00 -0400 | [diff] [blame] | 92 | } |
| 93 | |
Florian Fainelli | cf96357 | 2018-04-25 12:12:52 -0700 | [diff] [blame] | 94 | static void dsa_master_get_ethtool_phy_stats(struct net_device *dev, |
| 95 | struct ethtool_stats *stats, |
| 96 | uint64_t *data) |
| 97 | { |
| 98 | struct dsa_port *cpu_dp = dev->dsa_ptr; |
| 99 | const struct ethtool_ops *ops = cpu_dp->orig_ethtool_ops; |
| 100 | struct dsa_switch *ds = cpu_dp->ds; |
| 101 | int port = cpu_dp->index; |
| 102 | int count = 0; |
| 103 | |
| 104 | if (dev->phydev && !ops->get_ethtool_phy_stats) { |
| 105 | count = phy_ethtool_get_sset_count(dev->phydev); |
| 106 | if (count >= 0) |
| 107 | phy_ethtool_get_stats(dev->phydev, stats, data); |
| 108 | } else if (ops->get_sset_count && ops->get_ethtool_phy_stats) { |
| 109 | count = ops->get_sset_count(dev, ETH_SS_PHY_STATS); |
| 110 | ops->get_ethtool_phy_stats(dev, stats, data); |
| 111 | } |
| 112 | |
| 113 | if (count < 0) |
| 114 | count = 0; |
| 115 | |
| 116 | if (ds->ops->get_ethtool_phy_stats) |
| 117 | ds->ops->get_ethtool_phy_stats(ds, port, data + count); |
| 118 | } |
| 119 | |
Vivien Didelot | f2f2356 | 2017-09-19 11:57:00 -0400 | [diff] [blame] | 120 | static int dsa_master_get_sset_count(struct net_device *dev, int sset) |
| 121 | { |
Vivien Didelot | 2f657a6 | 2017-09-29 17:19:20 -0400 | [diff] [blame] | 122 | struct dsa_port *cpu_dp = dev->dsa_ptr; |
Vivien Didelot | 7ec764e | 2017-09-29 17:19:16 -0400 | [diff] [blame] | 123 | const struct ethtool_ops *ops = cpu_dp->orig_ethtool_ops; |
| 124 | struct dsa_switch *ds = cpu_dp->ds; |
Vivien Didelot | f2f2356 | 2017-09-19 11:57:00 -0400 | [diff] [blame] | 125 | int count = 0; |
| 126 | |
Florian Fainelli | cf96357 | 2018-04-25 12:12:52 -0700 | [diff] [blame] | 127 | if (sset == ETH_SS_PHY_STATS && dev->phydev && |
| 128 | !ops->get_ethtool_phy_stats) |
| 129 | count = phy_ethtool_get_sset_count(dev->phydev); |
| 130 | else if (ops->get_sset_count) |
Florian Fainelli | 89f0904 | 2018-04-25 12:12:50 -0700 | [diff] [blame] | 131 | count = ops->get_sset_count(dev, sset); |
Florian Fainelli | cf96357 | 2018-04-25 12:12:52 -0700 | [diff] [blame] | 132 | |
| 133 | if (count < 0) |
| 134 | count = 0; |
Vivien Didelot | f2f2356 | 2017-09-19 11:57:00 -0400 | [diff] [blame] | 135 | |
Florian Fainelli | 89f0904 | 2018-04-25 12:12:50 -0700 | [diff] [blame] | 136 | if (ds->ops->get_sset_count) |
| 137 | count += ds->ops->get_sset_count(ds, cpu_dp->index, sset); |
Vivien Didelot | f2f2356 | 2017-09-19 11:57:00 -0400 | [diff] [blame] | 138 | |
| 139 | return count; |
| 140 | } |
| 141 | |
| 142 | static void dsa_master_get_strings(struct net_device *dev, uint32_t stringset, |
| 143 | uint8_t *data) |
| 144 | { |
Vivien Didelot | 2f657a6 | 2017-09-29 17:19:20 -0400 | [diff] [blame] | 145 | struct dsa_port *cpu_dp = dev->dsa_ptr; |
Vivien Didelot | 7ec764e | 2017-09-29 17:19:16 -0400 | [diff] [blame] | 146 | const struct ethtool_ops *ops = cpu_dp->orig_ethtool_ops; |
| 147 | struct dsa_switch *ds = cpu_dp->ds; |
| 148 | int port = cpu_dp->index; |
Vivien Didelot | f2f2356 | 2017-09-19 11:57:00 -0400 | [diff] [blame] | 149 | int len = ETH_GSTRING_LEN; |
| 150 | int mcount = 0, count; |
| 151 | unsigned int i; |
| 152 | uint8_t pfx[4]; |
| 153 | uint8_t *ndata; |
| 154 | |
Vivien Didelot | 7ec764e | 2017-09-29 17:19:16 -0400 | [diff] [blame] | 155 | snprintf(pfx, sizeof(pfx), "p%.2d", port); |
Vivien Didelot | f2f2356 | 2017-09-19 11:57:00 -0400 | [diff] [blame] | 156 | /* We do not want to be NULL-terminated, since this is a prefix */ |
| 157 | pfx[sizeof(pfx) - 1] = '_'; |
| 158 | |
Florian Fainelli | cf96357 | 2018-04-25 12:12:52 -0700 | [diff] [blame] | 159 | if (stringset == ETH_SS_PHY_STATS && dev->phydev && |
| 160 | !ops->get_ethtool_phy_stats) { |
| 161 | mcount = phy_ethtool_get_sset_count(dev->phydev); |
| 162 | if (mcount < 0) |
| 163 | mcount = 0; |
| 164 | else |
| 165 | phy_ethtool_get_strings(dev->phydev, data); |
| 166 | } else if (ops->get_sset_count && ops->get_strings) { |
Florian Fainelli | 89f0904 | 2018-04-25 12:12:50 -0700 | [diff] [blame] | 167 | mcount = ops->get_sset_count(dev, stringset); |
| 168 | if (mcount < 0) |
| 169 | mcount = 0; |
Vivien Didelot | f2f2356 | 2017-09-19 11:57:00 -0400 | [diff] [blame] | 170 | ops->get_strings(dev, stringset, data); |
| 171 | } |
| 172 | |
Florian Fainelli | 89f0904 | 2018-04-25 12:12:50 -0700 | [diff] [blame] | 173 | if (ds->ops->get_strings) { |
Vivien Didelot | f2f2356 | 2017-09-19 11:57:00 -0400 | [diff] [blame] | 174 | ndata = data + mcount * len; |
| 175 | /* This function copies ETH_GSTRINGS_LEN bytes, we will mangle |
| 176 | * the output after to prepend our CPU port prefix we |
| 177 | * constructed earlier |
| 178 | */ |
Florian Fainelli | 89f0904 | 2018-04-25 12:12:50 -0700 | [diff] [blame] | 179 | ds->ops->get_strings(ds, port, stringset, ndata); |
| 180 | count = ds->ops->get_sset_count(ds, port, stringset); |
Vivien Didelot | f2f2356 | 2017-09-19 11:57:00 -0400 | [diff] [blame] | 181 | for (i = 0; i < count; i++) { |
| 182 | memmove(ndata + (i * len + sizeof(pfx)), |
| 183 | ndata + i * len, len - sizeof(pfx)); |
| 184 | memcpy(ndata + i * len, pfx, sizeof(pfx)); |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | |
Florian Fainelli | da7b9e9 | 2019-01-15 14:43:04 -0800 | [diff] [blame] | 189 | static int dsa_master_get_phys_port_name(struct net_device *dev, |
| 190 | char *name, size_t len) |
| 191 | { |
| 192 | struct dsa_port *cpu_dp = dev->dsa_ptr; |
| 193 | |
| 194 | if (snprintf(name, len, "p%d", cpu_dp->index) >= len) |
| 195 | return -EINVAL; |
| 196 | |
| 197 | return 0; |
| 198 | } |
| 199 | |
Vladimir Oltean | f685e60 | 2019-12-28 15:30:46 +0200 | [diff] [blame] | 200 | static int dsa_master_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 201 | { |
| 202 | struct dsa_port *cpu_dp = dev->dsa_ptr; |
| 203 | struct dsa_switch *ds = cpu_dp->ds; |
| 204 | struct dsa_switch_tree *dst; |
| 205 | int err = -EOPNOTSUPP; |
| 206 | struct dsa_port *dp; |
| 207 | |
| 208 | dst = ds->dst; |
| 209 | |
| 210 | switch (cmd) { |
| 211 | case SIOCGHWTSTAMP: |
| 212 | case SIOCSHWTSTAMP: |
| 213 | /* Deny PTP operations on master if there is at least one |
| 214 | * switch in the tree that is PTP capable. |
| 215 | */ |
| 216 | list_for_each_entry(dp, &dst->ports, list) |
| 217 | if (dp->ds->ops->port_hwtstamp_get || |
| 218 | dp->ds->ops->port_hwtstamp_set) |
| 219 | return -EBUSY; |
| 220 | break; |
| 221 | } |
| 222 | |
| 223 | if (cpu_dp->orig_ndo_ops && cpu_dp->orig_ndo_ops->ndo_do_ioctl) |
| 224 | err = cpu_dp->orig_ndo_ops->ndo_do_ioctl(dev, ifr, cmd); |
| 225 | |
| 226 | return err; |
| 227 | } |
| 228 | |
Vivien Didelot | 17a22fc | 2017-11-06 16:11:45 -0500 | [diff] [blame] | 229 | static int dsa_master_ethtool_setup(struct net_device *dev) |
Vivien Didelot | f2f2356 | 2017-09-19 11:57:00 -0400 | [diff] [blame] | 230 | { |
Vivien Didelot | 2f657a6 | 2017-09-29 17:19:20 -0400 | [diff] [blame] | 231 | struct dsa_port *cpu_dp = dev->dsa_ptr; |
Vivien Didelot | 7ec764e | 2017-09-29 17:19:16 -0400 | [diff] [blame] | 232 | struct dsa_switch *ds = cpu_dp->ds; |
Vivien Didelot | f2f2356 | 2017-09-19 11:57:00 -0400 | [diff] [blame] | 233 | struct ethtool_ops *ops; |
| 234 | |
| 235 | ops = devm_kzalloc(ds->dev, sizeof(*ops), GFP_KERNEL); |
| 236 | if (!ops) |
| 237 | return -ENOMEM; |
| 238 | |
Vivien Didelot | 7ec764e | 2017-09-29 17:19:16 -0400 | [diff] [blame] | 239 | cpu_dp->orig_ethtool_ops = dev->ethtool_ops; |
| 240 | if (cpu_dp->orig_ethtool_ops) |
| 241 | memcpy(ops, cpu_dp->orig_ethtool_ops, sizeof(*ops)); |
Vivien Didelot | f2f2356 | 2017-09-19 11:57:00 -0400 | [diff] [blame] | 242 | |
Vivien Didelot | 48e2331 | 2019-08-02 15:34:55 -0400 | [diff] [blame] | 243 | ops->get_regs_len = dsa_master_get_regs_len; |
| 244 | ops->get_regs = dsa_master_get_regs; |
Vivien Didelot | f2f2356 | 2017-09-19 11:57:00 -0400 | [diff] [blame] | 245 | ops->get_sset_count = dsa_master_get_sset_count; |
| 246 | ops->get_ethtool_stats = dsa_master_get_ethtool_stats; |
| 247 | ops->get_strings = dsa_master_get_strings; |
Florian Fainelli | cf96357 | 2018-04-25 12:12:52 -0700 | [diff] [blame] | 248 | ops->get_ethtool_phy_stats = dsa_master_get_ethtool_phy_stats; |
Vivien Didelot | f2f2356 | 2017-09-19 11:57:00 -0400 | [diff] [blame] | 249 | |
| 250 | dev->ethtool_ops = ops; |
| 251 | |
| 252 | return 0; |
| 253 | } |
| 254 | |
Vivien Didelot | 17a22fc | 2017-11-06 16:11:45 -0500 | [diff] [blame] | 255 | static void dsa_master_ethtool_teardown(struct net_device *dev) |
Vivien Didelot | f2f2356 | 2017-09-19 11:57:00 -0400 | [diff] [blame] | 256 | { |
Vivien Didelot | 2f657a6 | 2017-09-29 17:19:20 -0400 | [diff] [blame] | 257 | struct dsa_port *cpu_dp = dev->dsa_ptr; |
Vivien Didelot | f2f2356 | 2017-09-19 11:57:00 -0400 | [diff] [blame] | 258 | |
Vivien Didelot | 7ec764e | 2017-09-29 17:19:16 -0400 | [diff] [blame] | 259 | dev->ethtool_ops = cpu_dp->orig_ethtool_ops; |
| 260 | cpu_dp->orig_ethtool_ops = NULL; |
Vivien Didelot | f2f2356 | 2017-09-19 11:57:00 -0400 | [diff] [blame] | 261 | } |
Vivien Didelot | 17a22fc | 2017-11-06 16:11:45 -0500 | [diff] [blame] | 262 | |
Florian Fainelli | da7b9e9 | 2019-01-15 14:43:04 -0800 | [diff] [blame] | 263 | static int dsa_master_ndo_setup(struct net_device *dev) |
| 264 | { |
| 265 | struct dsa_port *cpu_dp = dev->dsa_ptr; |
| 266 | struct dsa_switch *ds = cpu_dp->ds; |
| 267 | struct net_device_ops *ops; |
| 268 | |
| 269 | if (dev->netdev_ops->ndo_get_phys_port_name) |
| 270 | return 0; |
| 271 | |
| 272 | ops = devm_kzalloc(ds->dev, sizeof(*ops), GFP_KERNEL); |
| 273 | if (!ops) |
| 274 | return -ENOMEM; |
| 275 | |
| 276 | cpu_dp->orig_ndo_ops = dev->netdev_ops; |
| 277 | if (cpu_dp->orig_ndo_ops) |
| 278 | memcpy(ops, cpu_dp->orig_ndo_ops, sizeof(*ops)); |
| 279 | |
| 280 | ops->ndo_get_phys_port_name = dsa_master_get_phys_port_name; |
Vladimir Oltean | f685e60 | 2019-12-28 15:30:46 +0200 | [diff] [blame] | 281 | ops->ndo_do_ioctl = dsa_master_ioctl; |
Florian Fainelli | da7b9e9 | 2019-01-15 14:43:04 -0800 | [diff] [blame] | 282 | |
| 283 | dev->netdev_ops = ops; |
| 284 | |
| 285 | return 0; |
| 286 | } |
| 287 | |
| 288 | static void dsa_master_ndo_teardown(struct net_device *dev) |
| 289 | { |
| 290 | struct dsa_port *cpu_dp = dev->dsa_ptr; |
| 291 | |
| 292 | dev->netdev_ops = cpu_dp->orig_ndo_ops; |
| 293 | cpu_dp->orig_ndo_ops = NULL; |
| 294 | } |
| 295 | |
Florian Fainelli | a3d7e01 | 2018-11-28 13:40:04 -0800 | [diff] [blame] | 296 | static ssize_t tagging_show(struct device *d, struct device_attribute *attr, |
| 297 | char *buf) |
| 298 | { |
| 299 | struct net_device *dev = to_net_dev(d); |
| 300 | struct dsa_port *cpu_dp = dev->dsa_ptr; |
| 301 | |
| 302 | return sprintf(buf, "%s\n", |
| 303 | dsa_tag_protocol_to_str(cpu_dp->tag_ops)); |
| 304 | } |
| 305 | static DEVICE_ATTR_RO(tagging); |
| 306 | |
| 307 | static struct attribute *dsa_slave_attrs[] = { |
| 308 | &dev_attr_tagging.attr, |
| 309 | NULL |
| 310 | }; |
| 311 | |
| 312 | static const struct attribute_group dsa_group = { |
| 313 | .name = "dsa", |
| 314 | .attrs = dsa_slave_attrs, |
| 315 | }; |
| 316 | |
Andrew Lunn | a60956e | 2018-12-08 17:06:31 +0100 | [diff] [blame] | 317 | static void dsa_master_set_mtu(struct net_device *dev, struct dsa_port *cpu_dp) |
Andrew Lunn | dc0fe7d | 2018-12-06 11:36:05 +0100 | [diff] [blame] | 318 | { |
| 319 | unsigned int mtu = ETH_DATA_LEN + cpu_dp->tag_ops->overhead; |
| 320 | int err; |
| 321 | |
| 322 | rtnl_lock(); |
| 323 | if (mtu <= dev->max_mtu) { |
| 324 | err = dev_set_mtu(dev, mtu); |
| 325 | if (err) |
| 326 | netdev_dbg(dev, "Unable to set MTU to include for DSA overheads\n"); |
| 327 | } |
| 328 | rtnl_unlock(); |
| 329 | } |
| 330 | |
Andrew Lunn | 91ba479 | 2018-12-08 17:05:18 +0100 | [diff] [blame] | 331 | static void dsa_master_reset_mtu(struct net_device *dev) |
| 332 | { |
| 333 | int err; |
| 334 | |
| 335 | rtnl_lock(); |
| 336 | err = dev_set_mtu(dev, ETH_DATA_LEN); |
| 337 | if (err) |
| 338 | netdev_dbg(dev, |
| 339 | "Unable to reset MTU to exclude DSA overheads\n"); |
| 340 | rtnl_unlock(); |
| 341 | } |
| 342 | |
Vivien Didelot | 17a22fc | 2017-11-06 16:11:45 -0500 | [diff] [blame] | 343 | int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp) |
| 344 | { |
Florian Fainelli | a3d7e01 | 2018-11-28 13:40:04 -0800 | [diff] [blame] | 345 | int ret; |
| 346 | |
Andrew Lunn | dc0fe7d | 2018-12-06 11:36:05 +0100 | [diff] [blame] | 347 | dsa_master_set_mtu(dev, cpu_dp); |
| 348 | |
Vivien Didelot | 17a22fc | 2017-11-06 16:11:45 -0500 | [diff] [blame] | 349 | /* If we use a tagging format that doesn't have an ethertype |
| 350 | * field, make sure that all packets from this point on get |
| 351 | * sent to the tag format's receive function. |
| 352 | */ |
| 353 | wmb(); |
| 354 | |
| 355 | dev->dsa_ptr = cpu_dp; |
Florian Fainelli | a3d7e01 | 2018-11-28 13:40:04 -0800 | [diff] [blame] | 356 | ret = dsa_master_ethtool_setup(dev); |
| 357 | if (ret) |
| 358 | return ret; |
| 359 | |
Florian Fainelli | da7b9e9 | 2019-01-15 14:43:04 -0800 | [diff] [blame] | 360 | ret = dsa_master_ndo_setup(dev); |
| 361 | if (ret) |
| 362 | goto out_err_ethtool_teardown; |
| 363 | |
Florian Fainelli | a3d7e01 | 2018-11-28 13:40:04 -0800 | [diff] [blame] | 364 | ret = sysfs_create_group(&dev->dev.kobj, &dsa_group); |
| 365 | if (ret) |
Florian Fainelli | da7b9e9 | 2019-01-15 14:43:04 -0800 | [diff] [blame] | 366 | goto out_err_ndo_teardown; |
Florian Fainelli | a3d7e01 | 2018-11-28 13:40:04 -0800 | [diff] [blame] | 367 | |
| 368 | return ret; |
Florian Fainelli | da7b9e9 | 2019-01-15 14:43:04 -0800 | [diff] [blame] | 369 | |
| 370 | out_err_ndo_teardown: |
| 371 | dsa_master_ndo_teardown(dev); |
| 372 | out_err_ethtool_teardown: |
| 373 | dsa_master_ethtool_teardown(dev); |
| 374 | return ret; |
Vivien Didelot | 17a22fc | 2017-11-06 16:11:45 -0500 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | void dsa_master_teardown(struct net_device *dev) |
| 378 | { |
Florian Fainelli | a3d7e01 | 2018-11-28 13:40:04 -0800 | [diff] [blame] | 379 | sysfs_remove_group(&dev->dev.kobj, &dsa_group); |
Florian Fainelli | da7b9e9 | 2019-01-15 14:43:04 -0800 | [diff] [blame] | 380 | dsa_master_ndo_teardown(dev); |
Vivien Didelot | 17a22fc | 2017-11-06 16:11:45 -0500 | [diff] [blame] | 381 | dsa_master_ethtool_teardown(dev); |
Andrew Lunn | 91ba479 | 2018-12-08 17:05:18 +0100 | [diff] [blame] | 382 | dsa_master_reset_mtu(dev); |
Vivien Didelot | 17a22fc | 2017-11-06 16:11:45 -0500 | [diff] [blame] | 383 | |
| 384 | dev->dsa_ptr = NULL; |
| 385 | |
| 386 | /* If we used a tagging format that doesn't have an ethertype |
| 387 | * field, make sure that all packets from this point get sent |
| 388 | * without the tag and go through the regular receive path. |
| 389 | */ |
| 390 | wmb(); |
| 391 | } |