| 1 | |
| 2 | |
| 3 | * net/dsa/user.c - user device handling
|
| 4 | * Copyright (c) 2008-2009 Marvell Semiconductor
|
| 5 |
|
| 6 |
|
| 7 | #include <linux/list.h>
|
| 8 | #include <linux/etherdevice.h>
|
| 9 | #include <linux/netdevice.h>
|
| 10 | #include <linux/phy.h>
|
| 11 | #include <linux/phy_fixed.h>
|
| 12 | #include <linux/phylink.h>
|
| 13 | #include <linux/of_net.h>
|
| 14 | #include <linux/of_mdio.h>
|
| 15 | #include <linux/mdio.h>
|
| 16 | #include <net/netdev_lock.h>
|
| 17 | #include <net/rtnetlink.h>
|
| 18 | #include <net/pkt_cls.h>
|
| 19 | #include <net/selftests.h>
|
| 20 | #include <net/tc_act/tc_mirred.h>
|
| 21 | #include <linux/if_bridge.h>
|
| 22 | #include <linux/if_hsr.h>
|
| 23 | #include <net/dcbnl.h>
|
| 24 | #include <linux/netpoll.h>
|
| 25 | #include <linux/string.h>
|
| 26 |
|
| 27 | #include "conduit.h"
|
| 28 | #include "dsa.h"
|
| 29 | #include "netlink.h"
|
| 30 | #include "port.h"
|
| 31 | #include "switch.h"
|
| 32 | #include "tag.h"
|
| 33 | #include "user.h"
|
| 34 |
|
| 35 | struct dsa_switchdev_event_work {
|
| 36 | struct net_device *dev;
|
| 37 | struct net_device *orig_dev;
|
| 38 | struct work_struct work;
|
| 39 | unsigned long event;
|
| 40 | |
| 41 | * SWITCHDEV_FDB_DEL_TO_DEVICE
|
| 42 |
|
| 43 | unsigned char addr[ETH_ALEN];
|
| 44 | u16 vid;
|
| 45 | bool host_addr;
|
| 46 | };
|
| 47 |
|
| 48 | enum dsa_standalone_event {
|
| 49 | DSA_UC_ADD,
|
| 50 | DSA_UC_DEL,
|
| 51 | DSA_MC_ADD,
|
| 52 | DSA_MC_DEL,
|
| 53 | };
|
| 54 |
|
| 55 | struct dsa_standalone_event_work {
|
| 56 | struct work_struct work;
|
| 57 | struct net_device *dev;
|
| 58 | enum dsa_standalone_event event;
|
| 59 | unsigned char addr[ETH_ALEN];
|
| 60 | u16 vid;
|
| 61 | };
|
| 62 |
|
| 63 | struct dsa_host_vlan_rx_filtering_ctx {
|
| 64 | struct net_device *dev;
|
| 65 | const unsigned char *addr;
|
| 66 | enum dsa_standalone_event event;
|
| 67 | };
|
| 68 |
|
| 69 | static bool dsa_switch_supports_uc_filtering(struct dsa_switch *ds)
|
| 70 | {
|
| 71 | return ds->ops->port_fdb_add && ds->ops->port_fdb_del &&
|
| 72 | ds->fdb_isolation && !ds->vlan_filtering_is_global &&
|
| 73 | !ds->needs_standalone_vlan_filtering;
|
| 74 | }
|
| 75 |
|
| 76 | static bool dsa_switch_supports_mc_filtering(struct dsa_switch *ds)
|
| 77 | {
|
| 78 | return ds->ops->port_mdb_add && ds->ops->port_mdb_del &&
|
| 79 | ds->fdb_isolation && !ds->vlan_filtering_is_global &&
|
| 80 | !ds->needs_standalone_vlan_filtering;
|
| 81 | }
|
| 82 |
|
| 83 | static void dsa_user_standalone_event_work(struct work_struct *work)
|
| 84 | {
|
| 85 | struct dsa_standalone_event_work *standalone_work =
|
| 86 | container_of(work, struct dsa_standalone_event_work, work);
|
| 87 | const unsigned char *addr = standalone_work->addr;
|
| 88 | struct net_device *dev = standalone_work->dev;
|
| 89 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 90 | struct switchdev_obj_port_mdb mdb;
|
| 91 | struct dsa_switch *ds = dp->ds;
|
| 92 | u16 vid = standalone_work->vid;
|
| 93 | int err;
|
| 94 |
|
| 95 | switch (standalone_work->event) {
|
| 96 | case DSA_UC_ADD:
|
| 97 | err = dsa_port_standalone_host_fdb_add(dp, addr, vid);
|
| 98 | if (err) {
|
| 99 | dev_err(ds->dev,
|
| 100 | "port %d failed to add %pM vid %d to fdb: %d\n",
|
| 101 | dp->index, addr, vid, err);
|
| 102 | break;
|
| 103 | }
|
| 104 | break;
|
| 105 |
|
| 106 | case DSA_UC_DEL:
|
| 107 | err = dsa_port_standalone_host_fdb_del(dp, addr, vid);
|
| 108 | if (err) {
|
| 109 | dev_err(ds->dev,
|
| 110 | "port %d failed to delete %pM vid %d from fdb: %d\n",
|
| 111 | dp->index, addr, vid, err);
|
| 112 | }
|
| 113 |
|
| 114 | break;
|
| 115 | case DSA_MC_ADD:
|
| 116 | ether_addr_copy(mdb.addr, addr);
|
| 117 | mdb.vid = vid;
|
| 118 |
|
| 119 | err = dsa_port_standalone_host_mdb_add(dp, &mdb);
|
| 120 | if (err) {
|
| 121 | dev_err(ds->dev,
|
| 122 | "port %d failed to add %pM vid %d to mdb: %d\n",
|
| 123 | dp->index, addr, vid, err);
|
| 124 | break;
|
| 125 | }
|
| 126 | break;
|
| 127 | case DSA_MC_DEL:
|
| 128 | ether_addr_copy(mdb.addr, addr);
|
| 129 | mdb.vid = vid;
|
| 130 |
|
| 131 | err = dsa_port_standalone_host_mdb_del(dp, &mdb);
|
| 132 | if (err) {
|
| 133 | dev_err(ds->dev,
|
| 134 | "port %d failed to delete %pM vid %d from mdb: %d\n",
|
| 135 | dp->index, addr, vid, err);
|
| 136 | }
|
| 137 |
|
| 138 | break;
|
| 139 | }
|
| 140 |
|
| 141 | kfree(standalone_work);
|
| 142 | }
|
| 143 |
|
| 144 | static int dsa_user_schedule_standalone_work(struct net_device *dev,
|
| 145 | enum dsa_standalone_event event,
|
| 146 | const unsigned char *addr,
|
| 147 | u16 vid)
|
| 148 | {
|
| 149 | struct dsa_standalone_event_work *standalone_work;
|
| 150 |
|
| 151 | standalone_work = kzalloc_obj(*standalone_work, GFP_ATOMIC);
|
| 152 | if (!standalone_work)
|
| 153 | return -ENOMEM;
|
| 154 |
|
| 155 | INIT_WORK(&standalone_work->work, dsa_user_standalone_event_work);
|
| 156 | standalone_work->event = event;
|
| 157 | standalone_work->dev = dev;
|
| 158 |
|
| 159 | ether_addr_copy(standalone_work->addr, addr);
|
| 160 | standalone_work->vid = vid;
|
| 161 |
|
| 162 | dsa_schedule_work(&standalone_work->work);
|
| 163 |
|
| 164 | return 0;
|
| 165 | }
|
| 166 |
|
| 167 | static int dsa_user_host_vlan_rx_filtering(void *arg, int vid)
|
| 168 | {
|
| 169 | struct dsa_host_vlan_rx_filtering_ctx *ctx = arg;
|
| 170 |
|
| 171 | return dsa_user_schedule_standalone_work(ctx->dev, ctx->event,
|
| 172 | ctx->addr, vid);
|
| 173 | }
|
| 174 |
|
| 175 | static int dsa_user_vlan_for_each(struct net_device *dev,
|
| 176 | int (*cb)(void *arg, int vid), void *arg)
|
| 177 | {
|
| 178 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 179 | struct dsa_vlan *v;
|
| 180 | int err;
|
| 181 |
|
| 182 | lockdep_assert_held(&dev->addr_list_lock);
|
| 183 |
|
| 184 | err = cb(arg, 0);
|
| 185 | if (err)
|
| 186 | return err;
|
| 187 |
|
| 188 | list_for_each_entry(v, &dp->user_vlans, list) {
|
| 189 | err = cb(arg, v->vid);
|
| 190 | if (err)
|
| 191 | return err;
|
| 192 | }
|
| 193 |
|
| 194 | return 0;
|
| 195 | }
|
| 196 |
|
| 197 | static int dsa_user_sync_uc(struct net_device *dev,
|
| 198 | const unsigned char *addr)
|
| 199 | {
|
| 200 | struct net_device *conduit = dsa_user_to_conduit(dev);
|
| 201 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 202 | struct dsa_host_vlan_rx_filtering_ctx ctx = {
|
| 203 | .dev = dev,
|
| 204 | .addr = addr,
|
| 205 | .event = DSA_UC_ADD,
|
| 206 | };
|
| 207 |
|
| 208 | dev_uc_add(conduit, addr);
|
| 209 |
|
| 210 | if (!dsa_switch_supports_uc_filtering(dp->ds))
|
| 211 | return 0;
|
| 212 |
|
| 213 | return dsa_user_vlan_for_each(dev, dsa_user_host_vlan_rx_filtering,
|
| 214 | &ctx);
|
| 215 | }
|
| 216 |
|
| 217 | static int dsa_user_unsync_uc(struct net_device *dev,
|
| 218 | const unsigned char *addr)
|
| 219 | {
|
| 220 | struct net_device *conduit = dsa_user_to_conduit(dev);
|
| 221 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 222 | struct dsa_host_vlan_rx_filtering_ctx ctx = {
|
| 223 | .dev = dev,
|
| 224 | .addr = addr,
|
| 225 | .event = DSA_UC_DEL,
|
| 226 | };
|
| 227 |
|
| 228 | dev_uc_del(conduit, addr);
|
| 229 |
|
| 230 | if (!dsa_switch_supports_uc_filtering(dp->ds))
|
| 231 | return 0;
|
| 232 |
|
| 233 | return dsa_user_vlan_for_each(dev, dsa_user_host_vlan_rx_filtering,
|
| 234 | &ctx);
|
| 235 | }
|
| 236 |
|
| 237 | static int dsa_user_sync_mc(struct net_device *dev,
|
| 238 | const unsigned char *addr)
|
| 239 | {
|
| 240 | struct net_device *conduit = dsa_user_to_conduit(dev);
|
| 241 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 242 | struct dsa_host_vlan_rx_filtering_ctx ctx = {
|
| 243 | .dev = dev,
|
| 244 | .addr = addr,
|
| 245 | .event = DSA_MC_ADD,
|
| 246 | };
|
| 247 |
|
| 248 | dev_mc_add(conduit, addr);
|
| 249 |
|
| 250 | if (!dsa_switch_supports_mc_filtering(dp->ds))
|
| 251 | return 0;
|
| 252 |
|
| 253 | return dsa_user_vlan_for_each(dev, dsa_user_host_vlan_rx_filtering,
|
| 254 | &ctx);
|
| 255 | }
|
| 256 |
|
| 257 | static int dsa_user_unsync_mc(struct net_device *dev,
|
| 258 | const unsigned char *addr)
|
| 259 | {
|
| 260 | struct net_device *conduit = dsa_user_to_conduit(dev);
|
| 261 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 262 | struct dsa_host_vlan_rx_filtering_ctx ctx = {
|
| 263 | .dev = dev,
|
| 264 | .addr = addr,
|
| 265 | .event = DSA_MC_DEL,
|
| 266 | };
|
| 267 |
|
| 268 | dev_mc_del(conduit, addr);
|
| 269 |
|
| 270 | if (!dsa_switch_supports_mc_filtering(dp->ds))
|
| 271 | return 0;
|
| 272 |
|
| 273 | return dsa_user_vlan_for_each(dev, dsa_user_host_vlan_rx_filtering,
|
| 274 | &ctx);
|
| 275 | }
|
| 276 |
|
| 277 | void dsa_user_sync_ha(struct net_device *dev)
|
| 278 | {
|
| 279 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 280 | struct dsa_switch *ds = dp->ds;
|
| 281 | struct netdev_hw_addr *ha;
|
| 282 |
|
| 283 | netif_addr_lock_bh(dev);
|
| 284 |
|
| 285 | netdev_for_each_synced_mc_addr(ha, dev)
|
| 286 | dsa_user_sync_mc(dev, ha->addr);
|
| 287 |
|
| 288 | netdev_for_each_synced_uc_addr(ha, dev)
|
| 289 | dsa_user_sync_uc(dev, ha->addr);
|
| 290 |
|
| 291 | netif_addr_unlock_bh(dev);
|
| 292 |
|
| 293 | if (dsa_switch_supports_uc_filtering(ds) ||
|
| 294 | dsa_switch_supports_mc_filtering(ds))
|
| 295 | dsa_flush_workqueue();
|
| 296 | }
|
| 297 |
|
| 298 | void dsa_user_unsync_ha(struct net_device *dev)
|
| 299 | {
|
| 300 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 301 | struct dsa_switch *ds = dp->ds;
|
| 302 | struct netdev_hw_addr *ha;
|
| 303 |
|
| 304 | netif_addr_lock_bh(dev);
|
| 305 |
|
| 306 | netdev_for_each_synced_uc_addr(ha, dev)
|
| 307 | dsa_user_unsync_uc(dev, ha->addr);
|
| 308 |
|
| 309 | netdev_for_each_synced_mc_addr(ha, dev)
|
| 310 | dsa_user_unsync_mc(dev, ha->addr);
|
| 311 |
|
| 312 | netif_addr_unlock_bh(dev);
|
| 313 |
|
| 314 | if (dsa_switch_supports_uc_filtering(ds) ||
|
| 315 | dsa_switch_supports_mc_filtering(ds))
|
| 316 | dsa_flush_workqueue();
|
| 317 | }
|
| 318 |
|
| 319 |
|
| 320 | static int dsa_user_phy_read(struct mii_bus *bus, int addr, int reg)
|
| 321 | {
|
| 322 | struct dsa_switch *ds = bus->priv;
|
| 323 |
|
| 324 | if (ds->phys_mii_mask & (1 << addr))
|
| 325 | return ds->ops->phy_read(ds, addr, reg);
|
| 326 |
|
| 327 | return 0xffff;
|
| 328 | }
|
| 329 |
|
| 330 | static int dsa_user_phy_write(struct mii_bus *bus, int addr, int reg, u16 val)
|
| 331 | {
|
| 332 | struct dsa_switch *ds = bus->priv;
|
| 333 |
|
| 334 | if (ds->phys_mii_mask & (1 << addr))
|
| 335 | return ds->ops->phy_write(ds, addr, reg, val);
|
| 336 |
|
| 337 | return 0;
|
| 338 | }
|
| 339 |
|
| 340 | void dsa_user_mii_bus_init(struct dsa_switch *ds)
|
| 341 | {
|
| 342 | ds->user_mii_bus->priv = (void *)ds;
|
| 343 | ds->user_mii_bus->name = "dsa user smi";
|
| 344 | ds->user_mii_bus->read = dsa_user_phy_read;
|
| 345 | ds->user_mii_bus->write = dsa_user_phy_write;
|
| 346 | snprintf(ds->user_mii_bus->id, MII_BUS_ID_SIZE, "dsa-%d.%d",
|
| 347 | ds->dst->index, ds->index);
|
| 348 | ds->user_mii_bus->parent = ds->dev;
|
| 349 | ds->user_mii_bus->phy_mask = ~ds->phys_mii_mask;
|
| 350 | }
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 | static int dsa_user_get_iflink(const struct net_device *dev)
|
| 355 | {
|
| 356 | return READ_ONCE(dsa_user_to_conduit(dev)->ifindex);
|
| 357 | }
|
| 358 |
|
| 359 | int dsa_user_host_uc_install(struct net_device *dev, const u8 *addr)
|
| 360 | {
|
| 361 | struct net_device *conduit = dsa_user_to_conduit(dev);
|
| 362 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 363 | struct dsa_switch *ds = dp->ds;
|
| 364 | int err;
|
| 365 |
|
| 366 | if (dsa_switch_supports_uc_filtering(ds)) {
|
| 367 | err = dsa_port_standalone_host_fdb_add(dp, addr, 0);
|
| 368 | if (err)
|
| 369 | goto out;
|
| 370 | }
|
| 371 |
|
| 372 | if (!ether_addr_equal(addr, conduit->dev_addr)) {
|
| 373 | err = dev_uc_add(conduit, addr);
|
| 374 | if (err < 0)
|
| 375 | goto del_host_addr;
|
| 376 | }
|
| 377 |
|
| 378 | return 0;
|
| 379 |
|
| 380 | del_host_addr:
|
| 381 | if (dsa_switch_supports_uc_filtering(ds))
|
| 382 | dsa_port_standalone_host_fdb_del(dp, addr, 0);
|
| 383 | out:
|
| 384 | return err;
|
| 385 | }
|
| 386 |
|
| 387 | void dsa_user_host_uc_uninstall(struct net_device *dev)
|
| 388 | {
|
| 389 | struct net_device *conduit = dsa_user_to_conduit(dev);
|
| 390 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 391 | struct dsa_switch *ds = dp->ds;
|
| 392 |
|
| 393 | if (!ether_addr_equal(dev->dev_addr, conduit->dev_addr))
|
| 394 | dev_uc_del(conduit, dev->dev_addr);
|
| 395 |
|
| 396 | if (dsa_switch_supports_uc_filtering(ds))
|
| 397 | dsa_port_standalone_host_fdb_del(dp, dev->dev_addr, 0);
|
| 398 | }
|
| 399 |
|
| 400 | static int dsa_user_open(struct net_device *dev)
|
| 401 | {
|
| 402 | struct net_device *conduit = dsa_user_to_conduit(dev);
|
| 403 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 404 | int err;
|
| 405 |
|
| 406 | err = dev_open(conduit, NULL);
|
| 407 | if (err < 0) {
|
| 408 | netdev_err(dev, "failed to open conduit %s\n", conduit->name);
|
| 409 | goto out;
|
| 410 | }
|
| 411 |
|
| 412 | err = dsa_user_host_uc_install(dev, dev->dev_addr);
|
| 413 | if (err)
|
| 414 | goto out;
|
| 415 |
|
| 416 | err = dsa_port_enable_rt(dp, dev->phydev);
|
| 417 | if (err)
|
| 418 | goto out_del_host_uc;
|
| 419 |
|
| 420 | return 0;
|
| 421 |
|
| 422 | out_del_host_uc:
|
| 423 | dsa_user_host_uc_uninstall(dev);
|
| 424 | out:
|
| 425 | return err;
|
| 426 | }
|
| 427 |
|
| 428 | static int dsa_user_close(struct net_device *dev)
|
| 429 | {
|
| 430 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 431 |
|
| 432 | dsa_port_disable_rt(dp);
|
| 433 |
|
| 434 | dsa_user_host_uc_uninstall(dev);
|
| 435 |
|
| 436 | return 0;
|
| 437 | }
|
| 438 |
|
| 439 | static void dsa_user_manage_host_flood(struct net_device *dev)
|
| 440 | {
|
| 441 | bool mc = dev->flags & (IFF_PROMISC | IFF_ALLMULTI);
|
| 442 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 443 | bool uc = dev->flags & IFF_PROMISC;
|
| 444 |
|
| 445 | dsa_port_set_host_flood(dp, uc, mc);
|
| 446 | }
|
| 447 |
|
| 448 | static void dsa_user_change_rx_flags(struct net_device *dev, int change)
|
| 449 | {
|
| 450 | struct net_device *conduit = dsa_user_to_conduit(dev);
|
| 451 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 452 | struct dsa_switch *ds = dp->ds;
|
| 453 |
|
| 454 | if (change & IFF_ALLMULTI)
|
| 455 | dev_set_allmulti(conduit,
|
| 456 | dev->flags & IFF_ALLMULTI ? 1 : -1);
|
| 457 | if (change & IFF_PROMISC)
|
| 458 | dev_set_promiscuity(conduit,
|
| 459 | dev->flags & IFF_PROMISC ? 1 : -1);
|
| 460 |
|
| 461 | if (dsa_switch_supports_uc_filtering(ds) &&
|
| 462 | dsa_switch_supports_mc_filtering(ds))
|
| 463 | dsa_user_manage_host_flood(dev);
|
| 464 | }
|
| 465 |
|
| 466 | static void dsa_user_set_rx_mode(struct net_device *dev)
|
| 467 | {
|
| 468 | __dev_mc_sync(dev, dsa_user_sync_mc, dsa_user_unsync_mc);
|
| 469 | __dev_uc_sync(dev, dsa_user_sync_uc, dsa_user_unsync_uc);
|
| 470 | }
|
| 471 |
|
| 472 | static int dsa_user_set_mac_address(struct net_device *dev, void *a)
|
| 473 | {
|
| 474 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 475 | struct dsa_switch *ds = dp->ds;
|
| 476 | struct sockaddr *addr = a;
|
| 477 | int err;
|
| 478 |
|
| 479 | if (!is_valid_ether_addr(addr->sa_data))
|
| 480 | return -EADDRNOTAVAIL;
|
| 481 |
|
| 482 | if (ds->ops->port_set_mac_address) {
|
| 483 | err = ds->ops->port_set_mac_address(ds, dp->index,
|
| 484 | addr->sa_data);
|
| 485 | if (err)
|
| 486 | return err;
|
| 487 | }
|
| 488 |
|
| 489 | |
| 490 | * to the DSA conduit, so there is nothing to change.
|
| 491 |
|
| 492 | if (!(dev->flags & IFF_UP))
|
| 493 | goto out_change_dev_addr;
|
| 494 |
|
| 495 | err = dsa_user_host_uc_install(dev, addr->sa_data);
|
| 496 | if (err)
|
| 497 | return err;
|
| 498 |
|
| 499 | dsa_user_host_uc_uninstall(dev);
|
| 500 |
|
| 501 | out_change_dev_addr:
|
| 502 | eth_hw_addr_set(dev, addr->sa_data);
|
| 503 |
|
| 504 | return 0;
|
| 505 | }
|
| 506 |
|
| 507 | struct dsa_user_dump_ctx {
|
| 508 | struct net_device *dev;
|
| 509 | struct sk_buff *skb;
|
| 510 | struct netlink_callback *cb;
|
| 511 | int idx;
|
| 512 | };
|
| 513 |
|
| 514 | static int
|
| 515 | dsa_user_port_fdb_do_dump(const unsigned char *addr, u16 vid,
|
| 516 | bool is_static, void *data)
|
| 517 | {
|
| 518 | struct dsa_user_dump_ctx *dump = data;
|
| 519 | struct ndo_fdb_dump_context *ctx = (void *)dump->cb->ctx;
|
| 520 | u32 portid = NETLINK_CB(dump->cb->skb).portid;
|
| 521 | u32 seq = dump->cb->nlh->nlmsg_seq;
|
| 522 | struct nlmsghdr *nlh;
|
| 523 | struct ndmsg *ndm;
|
| 524 |
|
| 525 | if (dump->idx < ctx->fdb_idx)
|
| 526 | goto skip;
|
| 527 |
|
| 528 | nlh = nlmsg_put(dump->skb, portid, seq, RTM_NEWNEIGH,
|
| 529 | sizeof(*ndm), NLM_F_MULTI);
|
| 530 | if (!nlh)
|
| 531 | return -EMSGSIZE;
|
| 532 |
|
| 533 | ndm = nlmsg_data(nlh);
|
| 534 | ndm->ndm_family = AF_BRIDGE;
|
| 535 | ndm->ndm_pad1 = 0;
|
| 536 | ndm->ndm_pad2 = 0;
|
| 537 | ndm->ndm_flags = NTF_SELF;
|
| 538 | ndm->ndm_type = 0;
|
| 539 | ndm->ndm_ifindex = dump->dev->ifindex;
|
| 540 | ndm->ndm_state = is_static ? NUD_NOARP : NUD_REACHABLE;
|
| 541 |
|
| 542 | if (nla_put(dump->skb, NDA_LLADDR, ETH_ALEN, addr))
|
| 543 | goto nla_put_failure;
|
| 544 |
|
| 545 | if (vid && nla_put_u16(dump->skb, NDA_VLAN, vid))
|
| 546 | goto nla_put_failure;
|
| 547 |
|
| 548 | nlmsg_end(dump->skb, nlh);
|
| 549 |
|
| 550 | skip:
|
| 551 | dump->idx++;
|
| 552 | return 0;
|
| 553 |
|
| 554 | nla_put_failure:
|
| 555 | nlmsg_cancel(dump->skb, nlh);
|
| 556 | return -EMSGSIZE;
|
| 557 | }
|
| 558 |
|
| 559 | static int
|
| 560 | dsa_user_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
|
| 561 | struct net_device *dev, struct net_device *filter_dev,
|
| 562 | int *idx)
|
| 563 | {
|
| 564 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 565 | struct dsa_user_dump_ctx dump = {
|
| 566 | .dev = dev,
|
| 567 | .skb = skb,
|
| 568 | .cb = cb,
|
| 569 | .idx = *idx,
|
| 570 | };
|
| 571 | int err;
|
| 572 |
|
| 573 | err = dsa_port_fdb_dump(dp, dsa_user_port_fdb_do_dump, &dump);
|
| 574 | *idx = dump.idx;
|
| 575 |
|
| 576 | return err;
|
| 577 | }
|
| 578 |
|
| 579 | static int dsa_user_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
|
| 580 | {
|
| 581 | struct dsa_user_priv *p = netdev_priv(dev);
|
| 582 |
|
| 583 | return phylink_mii_ioctl(p->dp->pl, ifr, cmd);
|
| 584 | }
|
| 585 |
|
| 586 | static int dsa_user_port_attr_set(struct net_device *dev, const void *ctx,
|
| 587 | const struct switchdev_attr *attr,
|
| 588 | struct netlink_ext_ack *extack)
|
| 589 | {
|
| 590 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 591 | int ret;
|
| 592 |
|
| 593 | if (ctx && ctx != dp)
|
| 594 | return 0;
|
| 595 |
|
| 596 | switch (attr->id) {
|
| 597 | case SWITCHDEV_ATTR_ID_PORT_STP_STATE:
|
| 598 | if (!dsa_port_offloads_bridge_port(dp, attr->orig_dev))
|
| 599 | return -EOPNOTSUPP;
|
| 600 |
|
| 601 | ret = dsa_port_set_state(dp, attr->u.stp_state, true);
|
| 602 | break;
|
| 603 | case SWITCHDEV_ATTR_ID_PORT_MST_STATE:
|
| 604 | if (!dsa_port_offloads_bridge_port(dp, attr->orig_dev))
|
| 605 | return -EOPNOTSUPP;
|
| 606 |
|
| 607 | ret = dsa_port_set_mst_state(dp, &attr->u.mst_state, extack);
|
| 608 | break;
|
| 609 | case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING:
|
| 610 | if (!dsa_port_offloads_bridge_dev(dp, attr->orig_dev))
|
| 611 | return -EOPNOTSUPP;
|
| 612 |
|
| 613 | ret = dsa_port_vlan_filtering(dp, attr->u.vlan_filtering,
|
| 614 | extack);
|
| 615 | break;
|
| 616 | case SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME:
|
| 617 | if (!dsa_port_offloads_bridge_dev(dp, attr->orig_dev))
|
| 618 | return -EOPNOTSUPP;
|
| 619 |
|
| 620 | ret = dsa_port_ageing_time(dp, attr->u.ageing_time);
|
| 621 | break;
|
| 622 | case SWITCHDEV_ATTR_ID_BRIDGE_MST:
|
| 623 | if (!dsa_port_offloads_bridge_dev(dp, attr->orig_dev))
|
| 624 | return -EOPNOTSUPP;
|
| 625 |
|
| 626 | ret = dsa_port_mst_enable(dp, attr->u.mst, extack);
|
| 627 | break;
|
| 628 | case SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS:
|
| 629 | if (!dsa_port_offloads_bridge_port(dp, attr->orig_dev))
|
| 630 | return -EOPNOTSUPP;
|
| 631 |
|
| 632 | ret = dsa_port_pre_bridge_flags(dp, attr->u.brport_flags,
|
| 633 | extack);
|
| 634 | break;
|
| 635 | case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS:
|
| 636 | if (!dsa_port_offloads_bridge_port(dp, attr->orig_dev))
|
| 637 | return -EOPNOTSUPP;
|
| 638 |
|
| 639 | ret = dsa_port_bridge_flags(dp, attr->u.brport_flags, extack);
|
| 640 | break;
|
| 641 | case SWITCHDEV_ATTR_ID_VLAN_MSTI:
|
| 642 | if (!dsa_port_offloads_bridge_dev(dp, attr->orig_dev))
|
| 643 | return -EOPNOTSUPP;
|
| 644 |
|
| 645 | ret = dsa_port_vlan_msti(dp, &attr->u.vlan_msti);
|
| 646 | break;
|
| 647 | default:
|
| 648 | ret = -EOPNOTSUPP;
|
| 649 | break;
|
| 650 | }
|
| 651 |
|
| 652 | return ret;
|
| 653 | }
|
| 654 |
|
| 655 |
|
| 656 | static int
|
| 657 | dsa_user_vlan_check_for_8021q_uppers(struct net_device *user,
|
| 658 | const struct switchdev_obj_port_vlan *vlan)
|
| 659 | {
|
| 660 | struct net_device *upper_dev;
|
| 661 | struct list_head *iter;
|
| 662 |
|
| 663 | netdev_for_each_upper_dev_rcu(user, upper_dev, iter) {
|
| 664 | u16 vid;
|
| 665 |
|
| 666 | if (!is_vlan_dev(upper_dev))
|
| 667 | continue;
|
| 668 |
|
| 669 | vid = vlan_dev_vlan_id(upper_dev);
|
| 670 | if (vid == vlan->vid)
|
| 671 | return -EBUSY;
|
| 672 | }
|
| 673 |
|
| 674 | return 0;
|
| 675 | }
|
| 676 |
|
| 677 | static int dsa_user_vlan_add(struct net_device *dev,
|
| 678 | const struct switchdev_obj *obj,
|
| 679 | struct netlink_ext_ack *extack)
|
| 680 | {
|
| 681 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 682 | struct switchdev_obj_port_vlan *vlan;
|
| 683 | int err;
|
| 684 |
|
| 685 | if (dsa_port_skip_vlan_configuration(dp)) {
|
| 686 | NL_SET_ERR_MSG_MOD(extack, "skipping configuration of VLAN");
|
| 687 | return 0;
|
| 688 | }
|
| 689 |
|
| 690 | vlan = SWITCHDEV_OBJ_PORT_VLAN(obj);
|
| 691 |
|
| 692 | |
| 693 | * the same VID.
|
| 694 |
|
| 695 | if (br_vlan_enabled(dsa_port_bridge_dev_get(dp))) {
|
| 696 | rcu_read_lock();
|
| 697 | err = dsa_user_vlan_check_for_8021q_uppers(dev, vlan);
|
| 698 | rcu_read_unlock();
|
| 699 | if (err) {
|
| 700 | NL_SET_ERR_MSG_MOD(extack,
|
| 701 | "Port already has a VLAN upper with this VID");
|
| 702 | return err;
|
| 703 | }
|
| 704 | }
|
| 705 |
|
| 706 | return dsa_port_vlan_add(dp, vlan, extack);
|
| 707 | }
|
| 708 |
|
| 709 | |
| 710 | * installing it as a VLAN towards the CPU port.
|
| 711 |
|
| 712 | static int dsa_user_host_vlan_add(struct net_device *dev,
|
| 713 | const struct switchdev_obj *obj,
|
| 714 | struct netlink_ext_ack *extack)
|
| 715 | {
|
| 716 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 717 | struct switchdev_obj_port_vlan vlan;
|
| 718 |
|
| 719 |
|
| 720 | if (!dp->bridge)
|
| 721 | return -EOPNOTSUPP;
|
| 722 |
|
| 723 | if (dsa_port_skip_vlan_configuration(dp)) {
|
| 724 | NL_SET_ERR_MSG_MOD(extack, "skipping configuration of VLAN");
|
| 725 | return 0;
|
| 726 | }
|
| 727 |
|
| 728 | vlan = *SWITCHDEV_OBJ_PORT_VLAN(obj);
|
| 729 |
|
| 730 | |
| 731 | * it doesn't make sense to program a PVID, so clear this flag.
|
| 732 |
|
| 733 | vlan.flags &= ~BRIDGE_VLAN_INFO_PVID;
|
| 734 |
|
| 735 | return dsa_port_host_vlan_add(dp, &vlan, extack);
|
| 736 | }
|
| 737 |
|
| 738 | static int dsa_user_port_obj_add(struct net_device *dev, const void *ctx,
|
| 739 | const struct switchdev_obj *obj,
|
| 740 | struct netlink_ext_ack *extack)
|
| 741 | {
|
| 742 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 743 | int err;
|
| 744 |
|
| 745 | if (ctx && ctx != dp)
|
| 746 | return 0;
|
| 747 |
|
| 748 | switch (obj->id) {
|
| 749 | case SWITCHDEV_OBJ_ID_PORT_MDB:
|
| 750 | if (!dsa_port_offloads_bridge_port(dp, obj->orig_dev))
|
| 751 | return -EOPNOTSUPP;
|
| 752 |
|
| 753 | err = dsa_port_mdb_add(dp, SWITCHDEV_OBJ_PORT_MDB(obj));
|
| 754 | break;
|
| 755 | case SWITCHDEV_OBJ_ID_HOST_MDB:
|
| 756 | if (!dsa_port_offloads_bridge_dev(dp, obj->orig_dev))
|
| 757 | return -EOPNOTSUPP;
|
| 758 |
|
| 759 | err = dsa_port_bridge_host_mdb_add(dp, SWITCHDEV_OBJ_PORT_MDB(obj));
|
| 760 | break;
|
| 761 | case SWITCHDEV_OBJ_ID_PORT_VLAN:
|
| 762 | if (dsa_port_offloads_bridge_port(dp, obj->orig_dev))
|
| 763 | err = dsa_user_vlan_add(dev, obj, extack);
|
| 764 | else
|
| 765 | err = dsa_user_host_vlan_add(dev, obj, extack);
|
| 766 | break;
|
| 767 | case SWITCHDEV_OBJ_ID_MRP:
|
| 768 | if (!dsa_port_offloads_bridge_dev(dp, obj->orig_dev))
|
| 769 | return -EOPNOTSUPP;
|
| 770 |
|
| 771 | err = dsa_port_mrp_add(dp, SWITCHDEV_OBJ_MRP(obj));
|
| 772 | break;
|
| 773 | case SWITCHDEV_OBJ_ID_RING_ROLE_MRP:
|
| 774 | if (!dsa_port_offloads_bridge_dev(dp, obj->orig_dev))
|
| 775 | return -EOPNOTSUPP;
|
| 776 |
|
| 777 | err = dsa_port_mrp_add_ring_role(dp,
|
| 778 | SWITCHDEV_OBJ_RING_ROLE_MRP(obj));
|
| 779 | break;
|
| 780 | default:
|
| 781 | err = -EOPNOTSUPP;
|
| 782 | break;
|
| 783 | }
|
| 784 |
|
| 785 | return err;
|
| 786 | }
|
| 787 |
|
| 788 | static int dsa_user_vlan_del(struct net_device *dev,
|
| 789 | const struct switchdev_obj *obj)
|
| 790 | {
|
| 791 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 792 | struct switchdev_obj_port_vlan *vlan;
|
| 793 |
|
| 794 | if (dsa_port_skip_vlan_configuration(dp))
|
| 795 | return 0;
|
| 796 |
|
| 797 | vlan = SWITCHDEV_OBJ_PORT_VLAN(obj);
|
| 798 |
|
| 799 | return dsa_port_vlan_del(dp, vlan);
|
| 800 | }
|
| 801 |
|
| 802 | static int dsa_user_host_vlan_del(struct net_device *dev,
|
| 803 | const struct switchdev_obj *obj)
|
| 804 | {
|
| 805 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 806 | struct switchdev_obj_port_vlan *vlan;
|
| 807 |
|
| 808 |
|
| 809 | if (!dp->bridge)
|
| 810 | return -EOPNOTSUPP;
|
| 811 |
|
| 812 | if (dsa_port_skip_vlan_configuration(dp))
|
| 813 | return 0;
|
| 814 |
|
| 815 | vlan = SWITCHDEV_OBJ_PORT_VLAN(obj);
|
| 816 |
|
| 817 | return dsa_port_host_vlan_del(dp, vlan);
|
| 818 | }
|
| 819 |
|
| 820 | static int dsa_user_port_obj_del(struct net_device *dev, const void *ctx,
|
| 821 | const struct switchdev_obj *obj)
|
| 822 | {
|
| 823 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 824 | int err;
|
| 825 |
|
| 826 | if (ctx && ctx != dp)
|
| 827 | return 0;
|
| 828 |
|
| 829 | switch (obj->id) {
|
| 830 | case SWITCHDEV_OBJ_ID_PORT_MDB:
|
| 831 | if (!dsa_port_offloads_bridge_port(dp, obj->orig_dev))
|
| 832 | return -EOPNOTSUPP;
|
| 833 |
|
| 834 | err = dsa_port_mdb_del(dp, SWITCHDEV_OBJ_PORT_MDB(obj));
|
| 835 | break;
|
| 836 | case SWITCHDEV_OBJ_ID_HOST_MDB:
|
| 837 | if (!dsa_port_offloads_bridge_dev(dp, obj->orig_dev))
|
| 838 | return -EOPNOTSUPP;
|
| 839 |
|
| 840 | err = dsa_port_bridge_host_mdb_del(dp, SWITCHDEV_OBJ_PORT_MDB(obj));
|
| 841 | break;
|
| 842 | case SWITCHDEV_OBJ_ID_PORT_VLAN:
|
| 843 | if (dsa_port_offloads_bridge_port(dp, obj->orig_dev))
|
| 844 | err = dsa_user_vlan_del(dev, obj);
|
| 845 | else
|
| 846 | err = dsa_user_host_vlan_del(dev, obj);
|
| 847 | break;
|
| 848 | case SWITCHDEV_OBJ_ID_MRP:
|
| 849 | if (!dsa_port_offloads_bridge_dev(dp, obj->orig_dev))
|
| 850 | return -EOPNOTSUPP;
|
| 851 |
|
| 852 | err = dsa_port_mrp_del(dp, SWITCHDEV_OBJ_MRP(obj));
|
| 853 | break;
|
| 854 | case SWITCHDEV_OBJ_ID_RING_ROLE_MRP:
|
| 855 | if (!dsa_port_offloads_bridge_dev(dp, obj->orig_dev))
|
| 856 | return -EOPNOTSUPP;
|
| 857 |
|
| 858 | err = dsa_port_mrp_del_ring_role(dp,
|
| 859 | SWITCHDEV_OBJ_RING_ROLE_MRP(obj));
|
| 860 | break;
|
| 861 | default:
|
| 862 | err = -EOPNOTSUPP;
|
| 863 | break;
|
| 864 | }
|
| 865 |
|
| 866 | return err;
|
| 867 | }
|
| 868 |
|
| 869 | static netdev_tx_t dsa_user_netpoll_send_skb(struct net_device *dev,
|
| 870 | struct sk_buff *skb)
|
| 871 | {
|
| 872 | #ifdef CONFIG_NET_POLL_CONTROLLER
|
| 873 | struct dsa_user_priv *p = netdev_priv(dev);
|
| 874 |
|
| 875 | return netpoll_send_skb(p->netpoll, skb);
|
| 876 | #else
|
| 877 | BUG();
|
| 878 | return NETDEV_TX_OK;
|
| 879 | #endif
|
| 880 | }
|
| 881 |
|
| 882 | static void dsa_skb_tx_timestamp(struct dsa_user_priv *p,
|
| 883 | struct sk_buff *skb)
|
| 884 | {
|
| 885 | struct dsa_switch *ds = p->dp->ds;
|
| 886 |
|
| 887 | if (!(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP_NOBPF))
|
| 888 | return;
|
| 889 |
|
| 890 | if (!ds->ops->port_txtstamp)
|
| 891 | return;
|
| 892 |
|
| 893 | ds->ops->port_txtstamp(ds, p->dp->index, skb);
|
| 894 | }
|
| 895 |
|
| 896 | netdev_tx_t dsa_enqueue_skb(struct sk_buff *skb, struct net_device *dev)
|
| 897 | {
|
| 898 | |
| 899 | * tag to be successfully transmitted
|
| 900 |
|
| 901 | if (unlikely(netpoll_tx_running(dev)))
|
| 902 | return dsa_user_netpoll_send_skb(dev, skb);
|
| 903 |
|
| 904 | |
| 905 | * do not modify its EtherType
|
| 906 |
|
| 907 | skb->dev = dsa_user_to_conduit(dev);
|
| 908 | dev_queue_xmit(skb);
|
| 909 |
|
| 910 | return NETDEV_TX_OK;
|
| 911 | }
|
| 912 | EXPORT_SYMBOL_GPL(dsa_enqueue_skb);
|
| 913 |
|
| 914 | static netdev_tx_t dsa_user_xmit(struct sk_buff *skb, struct net_device *dev)
|
| 915 | {
|
| 916 | struct dsa_user_priv *p = netdev_priv(dev);
|
| 917 | struct sk_buff *nskb;
|
| 918 |
|
| 919 | dev_sw_netstats_tx_add(dev, 1, skb->len);
|
| 920 |
|
| 921 | memset(skb->cb, 0, sizeof(skb->cb));
|
| 922 |
|
| 923 |
|
| 924 | dsa_skb_tx_timestamp(p, skb);
|
| 925 |
|
| 926 | if (skb_ensure_writable_head_tail(skb, dev)) {
|
| 927 | dev_kfree_skb_any(skb);
|
| 928 | return NETDEV_TX_OK;
|
| 929 | }
|
| 930 |
|
| 931 | |
| 932 | * skb_ensure_writable_head_tail(), which has also ensured that
|
| 933 | * padding is safe.
|
| 934 |
|
| 935 | if (dev->needed_tailroom)
|
| 936 | eth_skb_pad(skb);
|
| 937 |
|
| 938 | |
| 939 | * in which case it must have freed it. Taggers will drop the
|
| 940 | * passed skb on error.
|
| 941 |
|
| 942 | nskb = p->xmit(skb, dev);
|
| 943 | if (!nskb)
|
| 944 | return NETDEV_TX_OK;
|
| 945 |
|
| 946 | return dsa_enqueue_skb(nskb, dev);
|
| 947 | }
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 | static void dsa_user_get_drvinfo(struct net_device *dev,
|
| 952 | struct ethtool_drvinfo *drvinfo)
|
| 953 | {
|
| 954 | strscpy(drvinfo->driver, "dsa", sizeof(drvinfo->driver));
|
| 955 | strscpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version));
|
| 956 | strscpy(drvinfo->bus_info, "platform", sizeof(drvinfo->bus_info));
|
| 957 | }
|
| 958 |
|
| 959 | static int dsa_user_get_regs_len(struct net_device *dev)
|
| 960 | {
|
| 961 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 962 | struct dsa_switch *ds = dp->ds;
|
| 963 |
|
| 964 | if (ds->ops->get_regs_len)
|
| 965 | return ds->ops->get_regs_len(ds, dp->index);
|
| 966 |
|
| 967 | return -EOPNOTSUPP;
|
| 968 | }
|
| 969 |
|
| 970 | static void
|
| 971 | dsa_user_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *_p)
|
| 972 | {
|
| 973 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 974 | struct dsa_switch *ds = dp->ds;
|
| 975 |
|
| 976 | if (ds->ops->get_regs)
|
| 977 | ds->ops->get_regs(ds, dp->index, regs, _p);
|
| 978 | }
|
| 979 |
|
| 980 | static int dsa_user_nway_reset(struct net_device *dev)
|
| 981 | {
|
| 982 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 983 |
|
| 984 | return phylink_ethtool_nway_reset(dp->pl);
|
| 985 | }
|
| 986 |
|
| 987 | static int dsa_user_get_eeprom_len(struct net_device *dev)
|
| 988 | {
|
| 989 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 990 | struct dsa_switch *ds = dp->ds;
|
| 991 |
|
| 992 | if (ds->cd && ds->cd->eeprom_len)
|
| 993 | return ds->cd->eeprom_len;
|
| 994 |
|
| 995 | if (ds->ops->get_eeprom_len)
|
| 996 | return ds->ops->get_eeprom_len(ds);
|
| 997 |
|
| 998 | return 0;
|
| 999 | }
|
| 1000 |
|
| 1001 | static int dsa_user_get_eeprom(struct net_device *dev,
|
| 1002 | struct ethtool_eeprom *eeprom, u8 *data)
|
| 1003 | {
|
| 1004 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1005 | struct dsa_switch *ds = dp->ds;
|
| 1006 |
|
| 1007 | if (ds->ops->get_eeprom)
|
| 1008 | return ds->ops->get_eeprom(ds, eeprom, data);
|
| 1009 |
|
| 1010 | return -EOPNOTSUPP;
|
| 1011 | }
|
| 1012 |
|
| 1013 | static int dsa_user_set_eeprom(struct net_device *dev,
|
| 1014 | struct ethtool_eeprom *eeprom, u8 *data)
|
| 1015 | {
|
| 1016 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1017 | struct dsa_switch *ds = dp->ds;
|
| 1018 |
|
| 1019 | if (ds->ops->set_eeprom)
|
| 1020 | return ds->ops->set_eeprom(ds, eeprom, data);
|
| 1021 |
|
| 1022 | return -EOPNOTSUPP;
|
| 1023 | }
|
| 1024 |
|
| 1025 | static void dsa_user_get_strings(struct net_device *dev,
|
| 1026 | uint32_t stringset, uint8_t *data)
|
| 1027 | {
|
| 1028 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1029 | struct dsa_switch *ds = dp->ds;
|
| 1030 |
|
| 1031 | if (stringset == ETH_SS_STATS) {
|
| 1032 | ethtool_puts(&data, "tx_packets");
|
| 1033 | ethtool_puts(&data, "tx_bytes");
|
| 1034 | ethtool_puts(&data, "rx_packets");
|
| 1035 | ethtool_puts(&data, "rx_bytes");
|
| 1036 | if (ds->ops->get_strings)
|
| 1037 | ds->ops->get_strings(ds, dp->index, stringset, data);
|
| 1038 | } else if (stringset == ETH_SS_TEST) {
|
| 1039 | net_selftest_get_strings(data);
|
| 1040 | }
|
| 1041 |
|
| 1042 | }
|
| 1043 |
|
| 1044 | static void dsa_user_get_ethtool_stats(struct net_device *dev,
|
| 1045 | struct ethtool_stats *stats,
|
| 1046 | uint64_t *data)
|
| 1047 | {
|
| 1048 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1049 | struct dsa_switch *ds = dp->ds;
|
| 1050 | struct pcpu_sw_netstats *s;
|
| 1051 | unsigned int start;
|
| 1052 | int i;
|
| 1053 |
|
| 1054 | for_each_possible_cpu(i) {
|
| 1055 | u64 tx_packets, tx_bytes, rx_packets, rx_bytes;
|
| 1056 |
|
| 1057 | s = per_cpu_ptr(dev->tstats, i);
|
| 1058 | do {
|
| 1059 | start = u64_stats_fetch_begin(&s->syncp);
|
| 1060 | tx_packets = u64_stats_read(&s->tx_packets);
|
| 1061 | tx_bytes = u64_stats_read(&s->tx_bytes);
|
| 1062 | rx_packets = u64_stats_read(&s->rx_packets);
|
| 1063 | rx_bytes = u64_stats_read(&s->rx_bytes);
|
| 1064 | } while (u64_stats_fetch_retry(&s->syncp, start));
|
| 1065 | data[0] += tx_packets;
|
| 1066 | data[1] += tx_bytes;
|
| 1067 | data[2] += rx_packets;
|
| 1068 | data[3] += rx_bytes;
|
| 1069 | }
|
| 1070 | if (ds->ops->get_ethtool_stats)
|
| 1071 | ds->ops->get_ethtool_stats(ds, dp->index, data + 4);
|
| 1072 | }
|
| 1073 |
|
| 1074 | static int dsa_user_get_sset_count(struct net_device *dev, int sset)
|
| 1075 | {
|
| 1076 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1077 | struct dsa_switch *ds = dp->ds;
|
| 1078 |
|
| 1079 | if (sset == ETH_SS_STATS) {
|
| 1080 | int count = 0;
|
| 1081 |
|
| 1082 | if (ds->ops->get_sset_count) {
|
| 1083 | count = ds->ops->get_sset_count(ds, dp->index, sset);
|
| 1084 | if (count < 0)
|
| 1085 | return count;
|
| 1086 | }
|
| 1087 |
|
| 1088 | return count + 4;
|
| 1089 | } else if (sset == ETH_SS_TEST) {
|
| 1090 | return net_selftest_get_count();
|
| 1091 | }
|
| 1092 |
|
| 1093 | return -EOPNOTSUPP;
|
| 1094 | }
|
| 1095 |
|
| 1096 | static void dsa_user_get_eth_phy_stats(struct net_device *dev,
|
| 1097 | struct ethtool_eth_phy_stats *phy_stats)
|
| 1098 | {
|
| 1099 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1100 | struct dsa_switch *ds = dp->ds;
|
| 1101 |
|
| 1102 | if (ds->ops->get_eth_phy_stats)
|
| 1103 | ds->ops->get_eth_phy_stats(ds, dp->index, phy_stats);
|
| 1104 | }
|
| 1105 |
|
| 1106 | static void dsa_user_get_eth_mac_stats(struct net_device *dev,
|
| 1107 | struct ethtool_eth_mac_stats *mac_stats)
|
| 1108 | {
|
| 1109 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1110 | struct dsa_switch *ds = dp->ds;
|
| 1111 |
|
| 1112 | if (ds->ops->get_eth_mac_stats)
|
| 1113 | ds->ops->get_eth_mac_stats(ds, dp->index, mac_stats);
|
| 1114 | }
|
| 1115 |
|
| 1116 | static void
|
| 1117 | dsa_user_get_eth_ctrl_stats(struct net_device *dev,
|
| 1118 | struct ethtool_eth_ctrl_stats *ctrl_stats)
|
| 1119 | {
|
| 1120 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1121 | struct dsa_switch *ds = dp->ds;
|
| 1122 |
|
| 1123 | if (ds->ops->get_eth_ctrl_stats)
|
| 1124 | ds->ops->get_eth_ctrl_stats(ds, dp->index, ctrl_stats);
|
| 1125 | }
|
| 1126 |
|
| 1127 | static void
|
| 1128 | dsa_user_get_rmon_stats(struct net_device *dev,
|
| 1129 | struct ethtool_rmon_stats *rmon_stats,
|
| 1130 | const struct ethtool_rmon_hist_range **ranges)
|
| 1131 | {
|
| 1132 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1133 | struct dsa_switch *ds = dp->ds;
|
| 1134 |
|
| 1135 | if (ds->ops->get_rmon_stats)
|
| 1136 | ds->ops->get_rmon_stats(ds, dp->index, rmon_stats, ranges);
|
| 1137 | }
|
| 1138 |
|
| 1139 | static void dsa_user_get_ts_stats(struct net_device *dev,
|
| 1140 | struct ethtool_ts_stats *ts_stats)
|
| 1141 | {
|
| 1142 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1143 | struct dsa_switch *ds = dp->ds;
|
| 1144 |
|
| 1145 | if (ds->ops->get_ts_stats)
|
| 1146 | ds->ops->get_ts_stats(ds, dp->index, ts_stats);
|
| 1147 | }
|
| 1148 |
|
| 1149 | static void dsa_user_net_selftest(struct net_device *ndev,
|
| 1150 | struct ethtool_test *etest, u64 *buf)
|
| 1151 | {
|
| 1152 | struct dsa_port *dp = dsa_user_to_port(ndev);
|
| 1153 | struct dsa_switch *ds = dp->ds;
|
| 1154 |
|
| 1155 | if (ds->ops->self_test) {
|
| 1156 | ds->ops->self_test(ds, dp->index, etest, buf);
|
| 1157 | return;
|
| 1158 | }
|
| 1159 |
|
| 1160 | net_selftest(ndev, etest, buf);
|
| 1161 | }
|
| 1162 |
|
| 1163 | static int dsa_user_get_mm(struct net_device *dev,
|
| 1164 | struct ethtool_mm_state *state)
|
| 1165 | {
|
| 1166 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1167 | struct dsa_switch *ds = dp->ds;
|
| 1168 |
|
| 1169 | if (!ds->ops->get_mm)
|
| 1170 | return -EOPNOTSUPP;
|
| 1171 |
|
| 1172 | return ds->ops->get_mm(ds, dp->index, state);
|
| 1173 | }
|
| 1174 |
|
| 1175 | static int dsa_user_set_mm(struct net_device *dev, struct ethtool_mm_cfg *cfg,
|
| 1176 | struct netlink_ext_ack *extack)
|
| 1177 | {
|
| 1178 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1179 | struct dsa_switch *ds = dp->ds;
|
| 1180 |
|
| 1181 | if (!ds->ops->set_mm)
|
| 1182 | return -EOPNOTSUPP;
|
| 1183 |
|
| 1184 | return ds->ops->set_mm(ds, dp->index, cfg, extack);
|
| 1185 | }
|
| 1186 |
|
| 1187 | static void dsa_user_get_mm_stats(struct net_device *dev,
|
| 1188 | struct ethtool_mm_stats *stats)
|
| 1189 | {
|
| 1190 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1191 | struct dsa_switch *ds = dp->ds;
|
| 1192 |
|
| 1193 | if (ds->ops->get_mm_stats)
|
| 1194 | ds->ops->get_mm_stats(ds, dp->index, stats);
|
| 1195 | }
|
| 1196 |
|
| 1197 | static void dsa_user_get_wol(struct net_device *dev, struct ethtool_wolinfo *w)
|
| 1198 | {
|
| 1199 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1200 | struct dsa_switch *ds = dp->ds;
|
| 1201 |
|
| 1202 | phylink_ethtool_get_wol(dp->pl, w);
|
| 1203 |
|
| 1204 | if (ds->ops->get_wol)
|
| 1205 | ds->ops->get_wol(ds, dp->index, w);
|
| 1206 | }
|
| 1207 |
|
| 1208 | static int dsa_user_set_wol(struct net_device *dev, struct ethtool_wolinfo *w)
|
| 1209 | {
|
| 1210 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1211 | struct dsa_switch *ds = dp->ds;
|
| 1212 | int ret = -EOPNOTSUPP;
|
| 1213 |
|
| 1214 | phylink_ethtool_set_wol(dp->pl, w);
|
| 1215 |
|
| 1216 | if (ds->ops->set_wol)
|
| 1217 | ret = ds->ops->set_wol(ds, dp->index, w);
|
| 1218 |
|
| 1219 | return ret;
|
| 1220 | }
|
| 1221 |
|
| 1222 | static int dsa_user_set_eee(struct net_device *dev, struct ethtool_keee *e)
|
| 1223 | {
|
| 1224 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1225 | struct dsa_switch *ds = dp->ds;
|
| 1226 | int ret;
|
| 1227 |
|
| 1228 |
|
| 1229 | if (!ds->ops->support_eee || !ds->ops->support_eee(ds, dp->index))
|
| 1230 | return -EOPNOTSUPP;
|
| 1231 |
|
| 1232 | |
| 1233 | * set_mac_eee() is permissible.
|
| 1234 |
|
| 1235 | if (!phylink_mac_implements_lpi(ds->phylink_mac_ops)) {
|
| 1236 |
|
| 1237 | if (!dev->phydev)
|
| 1238 | return -ENODEV;
|
| 1239 |
|
| 1240 | if (!ds->ops->set_mac_eee)
|
| 1241 | return -EOPNOTSUPP;
|
| 1242 |
|
| 1243 | ret = ds->ops->set_mac_eee(ds, dp->index, e);
|
| 1244 | if (ret)
|
| 1245 | return ret;
|
| 1246 | } else if (ds->ops->set_mac_eee) {
|
| 1247 | ret = ds->ops->set_mac_eee(ds, dp->index, e);
|
| 1248 | if (ret)
|
| 1249 | return ret;
|
| 1250 | }
|
| 1251 |
|
| 1252 | return phylink_ethtool_set_eee(dp->pl, e);
|
| 1253 | }
|
| 1254 |
|
| 1255 | static int dsa_user_get_eee(struct net_device *dev, struct ethtool_keee *e)
|
| 1256 | {
|
| 1257 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1258 | struct dsa_switch *ds = dp->ds;
|
| 1259 |
|
| 1260 |
|
| 1261 | if (!ds->ops->support_eee || !ds->ops->support_eee(ds, dp->index))
|
| 1262 | return -EOPNOTSUPP;
|
| 1263 |
|
| 1264 |
|
| 1265 | if (!dev->phydev)
|
| 1266 | return -ENODEV;
|
| 1267 |
|
| 1268 | return phylink_ethtool_get_eee(dp->pl, e);
|
| 1269 | }
|
| 1270 |
|
| 1271 | static int dsa_user_get_link_ksettings(struct net_device *dev,
|
| 1272 | struct ethtool_link_ksettings *cmd)
|
| 1273 | {
|
| 1274 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1275 |
|
| 1276 | return phylink_ethtool_ksettings_get(dp->pl, cmd);
|
| 1277 | }
|
| 1278 |
|
| 1279 | static int dsa_user_set_link_ksettings(struct net_device *dev,
|
| 1280 | const struct ethtool_link_ksettings *cmd)
|
| 1281 | {
|
| 1282 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1283 |
|
| 1284 | return phylink_ethtool_ksettings_set(dp->pl, cmd);
|
| 1285 | }
|
| 1286 |
|
| 1287 | static void dsa_user_get_pause_stats(struct net_device *dev,
|
| 1288 | struct ethtool_pause_stats *pause_stats)
|
| 1289 | {
|
| 1290 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1291 | struct dsa_switch *ds = dp->ds;
|
| 1292 |
|
| 1293 | if (ds->ops->get_pause_stats)
|
| 1294 | ds->ops->get_pause_stats(ds, dp->index, pause_stats);
|
| 1295 | }
|
| 1296 |
|
| 1297 | static void dsa_user_get_pauseparam(struct net_device *dev,
|
| 1298 | struct ethtool_pauseparam *pause)
|
| 1299 | {
|
| 1300 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1301 |
|
| 1302 | phylink_ethtool_get_pauseparam(dp->pl, pause);
|
| 1303 | }
|
| 1304 |
|
| 1305 | static int dsa_user_set_pauseparam(struct net_device *dev,
|
| 1306 | struct ethtool_pauseparam *pause)
|
| 1307 | {
|
| 1308 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1309 |
|
| 1310 | return phylink_ethtool_set_pauseparam(dp->pl, pause);
|
| 1311 | }
|
| 1312 |
|
| 1313 | #ifdef CONFIG_NET_POLL_CONTROLLER
|
| 1314 | static int dsa_user_netpoll_setup(struct net_device *dev)
|
| 1315 | {
|
| 1316 | struct net_device *conduit = dsa_user_to_conduit(dev);
|
| 1317 | struct dsa_user_priv *p = netdev_priv(dev);
|
| 1318 | struct netpoll *netpoll;
|
| 1319 | int err = 0;
|
| 1320 |
|
| 1321 | netpoll = kzalloc_obj(*netpoll);
|
| 1322 | if (!netpoll)
|
| 1323 | return -ENOMEM;
|
| 1324 |
|
| 1325 | err = __netpoll_setup(netpoll, conduit);
|
| 1326 | if (err) {
|
| 1327 | kfree(netpoll);
|
| 1328 | goto out;
|
| 1329 | }
|
| 1330 |
|
| 1331 | p->netpoll = netpoll;
|
| 1332 | out:
|
| 1333 | return err;
|
| 1334 | }
|
| 1335 |
|
| 1336 | static void dsa_user_netpoll_cleanup(struct net_device *dev)
|
| 1337 | {
|
| 1338 | struct dsa_user_priv *p = netdev_priv(dev);
|
| 1339 | struct netpoll *netpoll = p->netpoll;
|
| 1340 |
|
| 1341 | if (!netpoll)
|
| 1342 | return;
|
| 1343 |
|
| 1344 | p->netpoll = NULL;
|
| 1345 |
|
| 1346 | __netpoll_free(netpoll);
|
| 1347 | }
|
| 1348 |
|
| 1349 | static void dsa_user_poll_controller(struct net_device *dev)
|
| 1350 | {
|
| 1351 | }
|
| 1352 | #endif
|
| 1353 |
|
| 1354 | static struct dsa_mall_tc_entry *
|
| 1355 | dsa_user_mall_tc_entry_find(struct net_device *dev, unsigned long cookie)
|
| 1356 | {
|
| 1357 | struct dsa_user_priv *p = netdev_priv(dev);
|
| 1358 | struct dsa_mall_tc_entry *mall_tc_entry;
|
| 1359 |
|
| 1360 | list_for_each_entry(mall_tc_entry, &p->mall_tc_list, list)
|
| 1361 | if (mall_tc_entry->cookie == cookie)
|
| 1362 | return mall_tc_entry;
|
| 1363 |
|
| 1364 | return NULL;
|
| 1365 | }
|
| 1366 |
|
| 1367 | static int
|
| 1368 | dsa_user_add_cls_matchall_mirred(struct net_device *dev,
|
| 1369 | struct tc_cls_matchall_offload *cls,
|
| 1370 | bool ingress, bool ingress_target)
|
| 1371 | {
|
| 1372 | struct netlink_ext_ack *extack = cls->common.extack;
|
| 1373 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1374 | struct dsa_user_priv *p = netdev_priv(dev);
|
| 1375 | struct dsa_mall_mirror_tc_entry *mirror;
|
| 1376 | struct dsa_mall_tc_entry *mall_tc_entry;
|
| 1377 | struct dsa_switch *ds = dp->ds;
|
| 1378 | struct flow_action_entry *act;
|
| 1379 | struct dsa_port *to_dp;
|
| 1380 | int err;
|
| 1381 |
|
| 1382 | if (cls->common.protocol != htons(ETH_P_ALL)) {
|
| 1383 | NL_SET_ERR_MSG_MOD(extack,
|
| 1384 | "Can only offload \"protocol all\" matchall filter");
|
| 1385 | return -EOPNOTSUPP;
|
| 1386 | }
|
| 1387 |
|
| 1388 | if (!ds->ops->port_mirror_add) {
|
| 1389 | NL_SET_ERR_MSG_MOD(extack,
|
| 1390 | "Switch does not support mirroring operation");
|
| 1391 | return -EOPNOTSUPP;
|
| 1392 | }
|
| 1393 |
|
| 1394 | if (!flow_action_basic_hw_stats_check(&cls->rule->action, extack))
|
| 1395 | return -EOPNOTSUPP;
|
| 1396 |
|
| 1397 | act = &cls->rule->action.entries[0];
|
| 1398 |
|
| 1399 | if (!act->dev)
|
| 1400 | return -EINVAL;
|
| 1401 |
|
| 1402 | if (dsa_user_dev_check(act->dev)) {
|
| 1403 | if (ingress_target) {
|
| 1404 |
|
| 1405 | if (cls->common.skip_sw) {
|
| 1406 | NL_SET_ERR_MSG_MOD(extack,
|
| 1407 | "Can only mirred to ingress of DSA user port if filter also runs in software");
|
| 1408 | return -EOPNOTSUPP;
|
| 1409 | }
|
| 1410 | to_dp = dp->cpu_dp;
|
| 1411 | } else {
|
| 1412 | to_dp = dsa_user_to_port(act->dev);
|
| 1413 | }
|
| 1414 | } else {
|
| 1415 | |
| 1416 | * the CPU. The software tc rule will take the packets from
|
| 1417 | * there.
|
| 1418 |
|
| 1419 | if (cls->common.skip_sw) {
|
| 1420 | NL_SET_ERR_MSG_MOD(extack,
|
| 1421 | "Can only mirred to CPU if filter also runs in software");
|
| 1422 | return -EOPNOTSUPP;
|
| 1423 | }
|
| 1424 | to_dp = dp->cpu_dp;
|
| 1425 | }
|
| 1426 |
|
| 1427 | if (dp->ds != to_dp->ds) {
|
| 1428 | NL_SET_ERR_MSG_MOD(extack,
|
| 1429 | "Cross-chip mirroring not implemented");
|
| 1430 | return -EOPNOTSUPP;
|
| 1431 | }
|
| 1432 |
|
| 1433 | mall_tc_entry = kzalloc_obj(*mall_tc_entry);
|
| 1434 | if (!mall_tc_entry)
|
| 1435 | return -ENOMEM;
|
| 1436 |
|
| 1437 | mall_tc_entry->cookie = cls->cookie;
|
| 1438 | mall_tc_entry->type = DSA_PORT_MALL_MIRROR;
|
| 1439 | mirror = &mall_tc_entry->mirror;
|
| 1440 | mirror->to_local_port = to_dp->index;
|
| 1441 | mirror->ingress = ingress;
|
| 1442 |
|
| 1443 | err = ds->ops->port_mirror_add(ds, dp->index, mirror, ingress, extack);
|
| 1444 | if (err) {
|
| 1445 | kfree(mall_tc_entry);
|
| 1446 | return err;
|
| 1447 | }
|
| 1448 |
|
| 1449 | list_add_tail(&mall_tc_entry->list, &p->mall_tc_list);
|
| 1450 |
|
| 1451 | return err;
|
| 1452 | }
|
| 1453 |
|
| 1454 | static int
|
| 1455 | dsa_user_add_cls_matchall_police(struct net_device *dev,
|
| 1456 | struct tc_cls_matchall_offload *cls,
|
| 1457 | bool ingress)
|
| 1458 | {
|
| 1459 | struct netlink_ext_ack *extack = cls->common.extack;
|
| 1460 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1461 | struct dsa_user_priv *p = netdev_priv(dev);
|
| 1462 | struct dsa_mall_tc_entry *mall_tc_entry;
|
| 1463 | struct flow_action_police *policer;
|
| 1464 | struct dsa_switch *ds = dp->ds;
|
| 1465 | struct flow_action_entry *act;
|
| 1466 | int err;
|
| 1467 |
|
| 1468 | if (!ds->ops->port_policer_add) {
|
| 1469 | NL_SET_ERR_MSG_MOD(extack,
|
| 1470 | "Policing offload not implemented");
|
| 1471 | return -EOPNOTSUPP;
|
| 1472 | }
|
| 1473 |
|
| 1474 | if (!ingress) {
|
| 1475 | NL_SET_ERR_MSG_MOD(extack,
|
| 1476 | "Only supported on ingress qdisc");
|
| 1477 | return -EOPNOTSUPP;
|
| 1478 | }
|
| 1479 |
|
| 1480 | if (!flow_action_basic_hw_stats_check(&cls->rule->action, extack))
|
| 1481 | return -EOPNOTSUPP;
|
| 1482 |
|
| 1483 | list_for_each_entry(mall_tc_entry, &p->mall_tc_list, list) {
|
| 1484 | if (mall_tc_entry->type == DSA_PORT_MALL_POLICER) {
|
| 1485 | NL_SET_ERR_MSG_MOD(extack,
|
| 1486 | "Only one port policer allowed");
|
| 1487 | return -EEXIST;
|
| 1488 | }
|
| 1489 | }
|
| 1490 |
|
| 1491 | act = &cls->rule->action.entries[0];
|
| 1492 |
|
| 1493 | mall_tc_entry = kzalloc_obj(*mall_tc_entry);
|
| 1494 | if (!mall_tc_entry)
|
| 1495 | return -ENOMEM;
|
| 1496 |
|
| 1497 | mall_tc_entry->cookie = cls->cookie;
|
| 1498 | mall_tc_entry->type = DSA_PORT_MALL_POLICER;
|
| 1499 | policer = &mall_tc_entry->policer;
|
| 1500 | *policer = act->police;
|
| 1501 |
|
| 1502 | err = ds->ops->port_policer_add(ds, dp->index, policer, extack);
|
| 1503 | if (err) {
|
| 1504 | kfree(mall_tc_entry);
|
| 1505 | return err;
|
| 1506 | }
|
| 1507 |
|
| 1508 | list_add_tail(&mall_tc_entry->list, &p->mall_tc_list);
|
| 1509 |
|
| 1510 | return err;
|
| 1511 | }
|
| 1512 |
|
| 1513 | static int dsa_user_add_cls_matchall(struct net_device *dev,
|
| 1514 | struct tc_cls_matchall_offload *cls,
|
| 1515 | bool ingress)
|
| 1516 | {
|
| 1517 | const struct flow_action *action = &cls->rule->action;
|
| 1518 | struct netlink_ext_ack *extack = cls->common.extack;
|
| 1519 |
|
| 1520 | if (!flow_offload_has_one_action(action)) {
|
| 1521 | NL_SET_ERR_MSG_MOD(extack,
|
| 1522 | "Cannot offload matchall filter with more than one action");
|
| 1523 | return -EOPNOTSUPP;
|
| 1524 | }
|
| 1525 |
|
| 1526 | switch (action->entries[0].id) {
|
| 1527 | case FLOW_ACTION_MIRRED:
|
| 1528 | return dsa_user_add_cls_matchall_mirred(dev, cls, ingress,
|
| 1529 | false);
|
| 1530 | case FLOW_ACTION_MIRRED_INGRESS:
|
| 1531 | return dsa_user_add_cls_matchall_mirred(dev, cls, ingress,
|
| 1532 | true);
|
| 1533 | case FLOW_ACTION_POLICE:
|
| 1534 | return dsa_user_add_cls_matchall_police(dev, cls, ingress);
|
| 1535 | default:
|
| 1536 | NL_SET_ERR_MSG_MOD(extack, "Unknown action");
|
| 1537 | break;
|
| 1538 | }
|
| 1539 |
|
| 1540 | return -EOPNOTSUPP;
|
| 1541 | }
|
| 1542 |
|
| 1543 | static void dsa_user_del_cls_matchall(struct net_device *dev,
|
| 1544 | struct tc_cls_matchall_offload *cls)
|
| 1545 | {
|
| 1546 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1547 | struct dsa_mall_tc_entry *mall_tc_entry;
|
| 1548 | struct dsa_switch *ds = dp->ds;
|
| 1549 |
|
| 1550 | mall_tc_entry = dsa_user_mall_tc_entry_find(dev, cls->cookie);
|
| 1551 | if (!mall_tc_entry)
|
| 1552 | return;
|
| 1553 |
|
| 1554 | list_del(&mall_tc_entry->list);
|
| 1555 |
|
| 1556 | switch (mall_tc_entry->type) {
|
| 1557 | case DSA_PORT_MALL_MIRROR:
|
| 1558 | if (ds->ops->port_mirror_del)
|
| 1559 | ds->ops->port_mirror_del(ds, dp->index,
|
| 1560 | &mall_tc_entry->mirror);
|
| 1561 | break;
|
| 1562 | case DSA_PORT_MALL_POLICER:
|
| 1563 | if (ds->ops->port_policer_del)
|
| 1564 | ds->ops->port_policer_del(ds, dp->index);
|
| 1565 | break;
|
| 1566 | default:
|
| 1567 | WARN_ON(1);
|
| 1568 | }
|
| 1569 |
|
| 1570 | kfree(mall_tc_entry);
|
| 1571 | }
|
| 1572 |
|
| 1573 | static int dsa_user_setup_tc_cls_matchall(struct net_device *dev,
|
| 1574 | struct tc_cls_matchall_offload *cls,
|
| 1575 | bool ingress)
|
| 1576 | {
|
| 1577 | if (cls->common.chain_index)
|
| 1578 | return -EOPNOTSUPP;
|
| 1579 |
|
| 1580 | switch (cls->command) {
|
| 1581 | case TC_CLSMATCHALL_REPLACE:
|
| 1582 | return dsa_user_add_cls_matchall(dev, cls, ingress);
|
| 1583 | case TC_CLSMATCHALL_DESTROY:
|
| 1584 | dsa_user_del_cls_matchall(dev, cls);
|
| 1585 | return 0;
|
| 1586 | default:
|
| 1587 | return -EOPNOTSUPP;
|
| 1588 | }
|
| 1589 | }
|
| 1590 |
|
| 1591 | static int dsa_user_add_cls_flower(struct net_device *dev,
|
| 1592 | struct flow_cls_offload *cls,
|
| 1593 | bool ingress)
|
| 1594 | {
|
| 1595 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1596 | struct dsa_switch *ds = dp->ds;
|
| 1597 | int port = dp->index;
|
| 1598 |
|
| 1599 | if (!ds->ops->cls_flower_add)
|
| 1600 | return -EOPNOTSUPP;
|
| 1601 |
|
| 1602 | return ds->ops->cls_flower_add(ds, port, cls, ingress);
|
| 1603 | }
|
| 1604 |
|
| 1605 | static int dsa_user_del_cls_flower(struct net_device *dev,
|
| 1606 | struct flow_cls_offload *cls,
|
| 1607 | bool ingress)
|
| 1608 | {
|
| 1609 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1610 | struct dsa_switch *ds = dp->ds;
|
| 1611 | int port = dp->index;
|
| 1612 |
|
| 1613 | if (!ds->ops->cls_flower_del)
|
| 1614 | return -EOPNOTSUPP;
|
| 1615 |
|
| 1616 | return ds->ops->cls_flower_del(ds, port, cls, ingress);
|
| 1617 | }
|
| 1618 |
|
| 1619 | static int dsa_user_stats_cls_flower(struct net_device *dev,
|
| 1620 | struct flow_cls_offload *cls,
|
| 1621 | bool ingress)
|
| 1622 | {
|
| 1623 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1624 | struct dsa_switch *ds = dp->ds;
|
| 1625 | int port = dp->index;
|
| 1626 |
|
| 1627 | if (!ds->ops->cls_flower_stats)
|
| 1628 | return -EOPNOTSUPP;
|
| 1629 |
|
| 1630 | return ds->ops->cls_flower_stats(ds, port, cls, ingress);
|
| 1631 | }
|
| 1632 |
|
| 1633 | static int dsa_user_setup_tc_cls_flower(struct net_device *dev,
|
| 1634 | struct flow_cls_offload *cls,
|
| 1635 | bool ingress)
|
| 1636 | {
|
| 1637 | switch (cls->command) {
|
| 1638 | case FLOW_CLS_REPLACE:
|
| 1639 | return dsa_user_add_cls_flower(dev, cls, ingress);
|
| 1640 | case FLOW_CLS_DESTROY:
|
| 1641 | return dsa_user_del_cls_flower(dev, cls, ingress);
|
| 1642 | case FLOW_CLS_STATS:
|
| 1643 | return dsa_user_stats_cls_flower(dev, cls, ingress);
|
| 1644 | default:
|
| 1645 | return -EOPNOTSUPP;
|
| 1646 | }
|
| 1647 | }
|
| 1648 |
|
| 1649 | static int dsa_user_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
|
| 1650 | void *cb_priv, bool ingress)
|
| 1651 | {
|
| 1652 | struct net_device *dev = cb_priv;
|
| 1653 |
|
| 1654 | if (!tc_can_offload(dev))
|
| 1655 | return -EOPNOTSUPP;
|
| 1656 |
|
| 1657 | switch (type) {
|
| 1658 | case TC_SETUP_CLSMATCHALL:
|
| 1659 | return dsa_user_setup_tc_cls_matchall(dev, type_data, ingress);
|
| 1660 | case TC_SETUP_CLSFLOWER:
|
| 1661 | return dsa_user_setup_tc_cls_flower(dev, type_data, ingress);
|
| 1662 | default:
|
| 1663 | return -EOPNOTSUPP;
|
| 1664 | }
|
| 1665 | }
|
| 1666 |
|
| 1667 | static int dsa_user_setup_tc_block_cb_ig(enum tc_setup_type type,
|
| 1668 | void *type_data, void *cb_priv)
|
| 1669 | {
|
| 1670 | return dsa_user_setup_tc_block_cb(type, type_data, cb_priv, true);
|
| 1671 | }
|
| 1672 |
|
| 1673 | static int dsa_user_setup_tc_block_cb_eg(enum tc_setup_type type,
|
| 1674 | void *type_data, void *cb_priv)
|
| 1675 | {
|
| 1676 | return dsa_user_setup_tc_block_cb(type, type_data, cb_priv, false);
|
| 1677 | }
|
| 1678 |
|
| 1679 | static LIST_HEAD(dsa_user_block_cb_list);
|
| 1680 |
|
| 1681 | static int dsa_user_setup_tc_block(struct net_device *dev,
|
| 1682 | struct flow_block_offload *f)
|
| 1683 | {
|
| 1684 | struct flow_block_cb *block_cb;
|
| 1685 | flow_setup_cb_t *cb;
|
| 1686 |
|
| 1687 | if (f->binder_type == FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
|
| 1688 | cb = dsa_user_setup_tc_block_cb_ig;
|
| 1689 | else if (f->binder_type == FLOW_BLOCK_BINDER_TYPE_CLSACT_EGRESS)
|
| 1690 | cb = dsa_user_setup_tc_block_cb_eg;
|
| 1691 | else
|
| 1692 | return -EOPNOTSUPP;
|
| 1693 |
|
| 1694 | f->driver_block_list = &dsa_user_block_cb_list;
|
| 1695 |
|
| 1696 | switch (f->command) {
|
| 1697 | case FLOW_BLOCK_BIND:
|
| 1698 | if (flow_block_cb_is_busy(cb, dev, &dsa_user_block_cb_list))
|
| 1699 | return -EBUSY;
|
| 1700 |
|
| 1701 | block_cb = flow_block_cb_alloc(cb, dev, dev, NULL);
|
| 1702 | if (IS_ERR(block_cb))
|
| 1703 | return PTR_ERR(block_cb);
|
| 1704 |
|
| 1705 | flow_block_cb_add(block_cb, f);
|
| 1706 | list_add_tail(&block_cb->driver_list, &dsa_user_block_cb_list);
|
| 1707 | return 0;
|
| 1708 | case FLOW_BLOCK_UNBIND:
|
| 1709 | block_cb = flow_block_cb_lookup(f->block, cb, dev);
|
| 1710 | if (!block_cb)
|
| 1711 | return -ENOENT;
|
| 1712 |
|
| 1713 | flow_block_cb_remove(block_cb, f);
|
| 1714 | list_del(&block_cb->driver_list);
|
| 1715 | return 0;
|
| 1716 | default:
|
| 1717 | return -EOPNOTSUPP;
|
| 1718 | }
|
| 1719 | }
|
| 1720 |
|
| 1721 | static int dsa_user_setup_ft_block(struct dsa_switch *ds, int port,
|
| 1722 | void *type_data)
|
| 1723 | {
|
| 1724 | struct net_device *conduit = dsa_port_to_conduit(dsa_to_port(ds, port));
|
| 1725 |
|
| 1726 | if (!conduit->netdev_ops->ndo_setup_tc)
|
| 1727 | return -EOPNOTSUPP;
|
| 1728 |
|
| 1729 | return conduit->netdev_ops->ndo_setup_tc(conduit, TC_SETUP_FT, type_data);
|
| 1730 | }
|
| 1731 |
|
| 1732 | static int dsa_user_setup_tc(struct net_device *dev, enum tc_setup_type type,
|
| 1733 | void *type_data)
|
| 1734 | {
|
| 1735 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1736 | struct dsa_switch *ds = dp->ds;
|
| 1737 |
|
| 1738 | switch (type) {
|
| 1739 | case TC_SETUP_BLOCK:
|
| 1740 | return dsa_user_setup_tc_block(dev, type_data);
|
| 1741 | case TC_SETUP_FT:
|
| 1742 | return dsa_user_setup_ft_block(ds, dp->index, type_data);
|
| 1743 | default:
|
| 1744 | break;
|
| 1745 | }
|
| 1746 |
|
| 1747 | if (!ds->ops->port_setup_tc)
|
| 1748 | return -EOPNOTSUPP;
|
| 1749 |
|
| 1750 | return ds->ops->port_setup_tc(ds, dp->index, type, type_data);
|
| 1751 | }
|
| 1752 |
|
| 1753 | static int dsa_user_get_rxnfc(struct net_device *dev,
|
| 1754 | struct ethtool_rxnfc *nfc, u32 *rule_locs)
|
| 1755 | {
|
| 1756 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1757 | struct dsa_switch *ds = dp->ds;
|
| 1758 |
|
| 1759 | if (!ds->ops->get_rxnfc)
|
| 1760 | return -EOPNOTSUPP;
|
| 1761 |
|
| 1762 | return ds->ops->get_rxnfc(ds, dp->index, nfc, rule_locs);
|
| 1763 | }
|
| 1764 |
|
| 1765 | static int dsa_user_set_rxnfc(struct net_device *dev,
|
| 1766 | struct ethtool_rxnfc *nfc)
|
| 1767 | {
|
| 1768 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1769 | struct dsa_switch *ds = dp->ds;
|
| 1770 |
|
| 1771 | if (!ds->ops->set_rxnfc)
|
| 1772 | return -EOPNOTSUPP;
|
| 1773 |
|
| 1774 | return ds->ops->set_rxnfc(ds, dp->index, nfc);
|
| 1775 | }
|
| 1776 |
|
| 1777 | static int dsa_user_get_ts_info(struct net_device *dev,
|
| 1778 | struct kernel_ethtool_ts_info *ts)
|
| 1779 | {
|
| 1780 | struct dsa_user_priv *p = netdev_priv(dev);
|
| 1781 | struct dsa_switch *ds = p->dp->ds;
|
| 1782 |
|
| 1783 | if (!ds->ops->get_ts_info)
|
| 1784 | return -EOPNOTSUPP;
|
| 1785 |
|
| 1786 | return ds->ops->get_ts_info(ds, p->dp->index, ts);
|
| 1787 | }
|
| 1788 |
|
| 1789 | static int dsa_user_vlan_rx_add_vid(struct net_device *dev, __be16 proto,
|
| 1790 | u16 vid)
|
| 1791 | {
|
| 1792 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1793 | struct switchdev_obj_port_vlan vlan = {
|
| 1794 | .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
|
| 1795 | .vid = vid,
|
| 1796 |
|
| 1797 | .flags = 0,
|
| 1798 | };
|
| 1799 | struct netlink_ext_ack extack = {0};
|
| 1800 | struct dsa_switch *ds = dp->ds;
|
| 1801 | struct netdev_hw_addr *ha;
|
| 1802 | struct dsa_vlan *v;
|
| 1803 | int ret;
|
| 1804 |
|
| 1805 |
|
| 1806 | ret = dsa_port_vlan_add(dp, &vlan, &extack);
|
| 1807 | if (ret) {
|
| 1808 | if (extack._msg)
|
| 1809 | netdev_err(dev, "%s\n", extack._msg);
|
| 1810 | return ret;
|
| 1811 | }
|
| 1812 |
|
| 1813 |
|
| 1814 | ret = dsa_port_host_vlan_add(dp, &vlan, &extack);
|
| 1815 | if (ret) {
|
| 1816 | if (extack._msg)
|
| 1817 | netdev_err(dev, "CPU port %d: %s\n", dp->cpu_dp->index,
|
| 1818 | extack._msg);
|
| 1819 | return ret;
|
| 1820 | }
|
| 1821 |
|
| 1822 | if (!dsa_switch_supports_uc_filtering(ds) &&
|
| 1823 | !dsa_switch_supports_mc_filtering(ds))
|
| 1824 | return 0;
|
| 1825 |
|
| 1826 | v = kzalloc_obj(*v);
|
| 1827 | if (!v) {
|
| 1828 | ret = -ENOMEM;
|
| 1829 | goto rollback;
|
| 1830 | }
|
| 1831 |
|
| 1832 | netif_addr_lock_bh(dev);
|
| 1833 |
|
| 1834 | v->vid = vid;
|
| 1835 | list_add_tail(&v->list, &dp->user_vlans);
|
| 1836 |
|
| 1837 | if (dsa_switch_supports_mc_filtering(ds)) {
|
| 1838 | netdev_for_each_synced_mc_addr(ha, dev) {
|
| 1839 | dsa_user_schedule_standalone_work(dev, DSA_MC_ADD,
|
| 1840 | ha->addr, vid);
|
| 1841 | }
|
| 1842 | }
|
| 1843 |
|
| 1844 | if (dsa_switch_supports_uc_filtering(ds)) {
|
| 1845 | netdev_for_each_synced_uc_addr(ha, dev) {
|
| 1846 | dsa_user_schedule_standalone_work(dev, DSA_UC_ADD,
|
| 1847 | ha->addr, vid);
|
| 1848 | }
|
| 1849 | }
|
| 1850 |
|
| 1851 | netif_addr_unlock_bh(dev);
|
| 1852 |
|
| 1853 | dsa_flush_workqueue();
|
| 1854 |
|
| 1855 | return 0;
|
| 1856 |
|
| 1857 | rollback:
|
| 1858 | dsa_port_host_vlan_del(dp, &vlan);
|
| 1859 | dsa_port_vlan_del(dp, &vlan);
|
| 1860 |
|
| 1861 | return ret;
|
| 1862 | }
|
| 1863 |
|
| 1864 | static int dsa_user_vlan_rx_kill_vid(struct net_device *dev, __be16 proto,
|
| 1865 | u16 vid)
|
| 1866 | {
|
| 1867 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 1868 | struct switchdev_obj_port_vlan vlan = {
|
| 1869 | .vid = vid,
|
| 1870 |
|
| 1871 | .flags = 0,
|
| 1872 | };
|
| 1873 | struct dsa_switch *ds = dp->ds;
|
| 1874 | struct netdev_hw_addr *ha;
|
| 1875 | struct dsa_vlan *v;
|
| 1876 | int err;
|
| 1877 |
|
| 1878 | err = dsa_port_vlan_del(dp, &vlan);
|
| 1879 | if (err)
|
| 1880 | return err;
|
| 1881 |
|
| 1882 | err = dsa_port_host_vlan_del(dp, &vlan);
|
| 1883 | if (err)
|
| 1884 | return err;
|
| 1885 |
|
| 1886 | if (!dsa_switch_supports_uc_filtering(ds) &&
|
| 1887 | !dsa_switch_supports_mc_filtering(ds))
|
| 1888 | return 0;
|
| 1889 |
|
| 1890 | netif_addr_lock_bh(dev);
|
| 1891 |
|
| 1892 | v = dsa_vlan_find(&dp->user_vlans, &vlan);
|
| 1893 | if (!v) {
|
| 1894 | netif_addr_unlock_bh(dev);
|
| 1895 | return -ENOENT;
|
| 1896 | }
|
| 1897 |
|
| 1898 | list_del(&v->list);
|
| 1899 | kfree(v);
|
| 1900 |
|
| 1901 | if (dsa_switch_supports_mc_filtering(ds)) {
|
| 1902 | netdev_for_each_synced_mc_addr(ha, dev) {
|
| 1903 | dsa_user_schedule_standalone_work(dev, DSA_MC_DEL,
|
| 1904 | ha->addr, vid);
|
| 1905 | }
|
| 1906 | }
|
| 1907 |
|
| 1908 | if (dsa_switch_supports_uc_filtering(ds)) {
|
| 1909 | netdev_for_each_synced_uc_addr(ha, dev) {
|
| 1910 | dsa_user_schedule_standalone_work(dev, DSA_UC_DEL,
|
| 1911 | ha->addr, vid);
|
| 1912 | }
|
| 1913 | }
|
| 1914 |
|
| 1915 | netif_addr_unlock_bh(dev);
|
| 1916 |
|
| 1917 | dsa_flush_workqueue();
|
| 1918 |
|
| 1919 | return 0;
|
| 1920 | }
|
| 1921 |
|
| 1922 | static int dsa_user_restore_vlan(struct net_device *vdev, int vid, void *arg)
|
| 1923 | {
|
| 1924 | __be16 proto = vdev ? vlan_dev_vlan_proto(vdev) : htons(ETH_P_8021Q);
|
| 1925 |
|
| 1926 | return dsa_user_vlan_rx_add_vid(arg, proto, vid);
|
| 1927 | }
|
| 1928 |
|
| 1929 | static int dsa_user_clear_vlan(struct net_device *vdev, int vid, void *arg)
|
| 1930 | {
|
| 1931 | __be16 proto = vdev ? vlan_dev_vlan_proto(vdev) : htons(ETH_P_8021Q);
|
| 1932 |
|
| 1933 | return dsa_user_vlan_rx_kill_vid(arg, proto, vid);
|
| 1934 | }
|
| 1935 |
|
| 1936 | |
| 1937 | * filtering is enabled. The baseline is that only ports that offload a
|
| 1938 | * VLAN-aware bridge are VLAN-aware, and standalone ports are VLAN-unaware,
|
| 1939 | * but there are exceptions for quirky hardware.
|
| 1940 | *
|
| 1941 | * If ds->vlan_filtering_is_global = true, then standalone ports which share
|
| 1942 | * the same switch with other ports that offload a VLAN-aware bridge are also
|
| 1943 | * inevitably VLAN-aware.
|
| 1944 | *
|
| 1945 | * To summarize, a DSA switch port offloads:
|
| 1946 | *
|
| 1947 | * - If standalone (this includes software bridge, software LAG):
|
| 1948 | * - if ds->needs_standalone_vlan_filtering = true, OR if
|
| 1949 | * (ds->vlan_filtering_is_global = true AND there are bridges spanning
|
| 1950 | * this switch chip which have vlan_filtering=1)
|
| 1951 | * - the 8021q upper VLANs
|
| 1952 | * - else (standalone VLAN filtering is not needed, VLAN filtering is not
|
| 1953 | * global, or it is, but no port is under a VLAN-aware bridge):
|
| 1954 | * - no VLAN (any 8021q upper is a software VLAN)
|
| 1955 | *
|
| 1956 | * - If under a vlan_filtering=0 bridge which it offload:
|
| 1957 | * - if ds->configure_vlan_while_not_filtering = true (default):
|
| 1958 | * - the bridge VLANs. These VLANs are committed to hardware but inactive.
|
| 1959 | * - else (deprecated):
|
| 1960 | * - no VLAN. The bridge VLANs are not restored when VLAN awareness is
|
| 1961 | * enabled, so this behavior is broken and discouraged.
|
| 1962 | *
|
| 1963 | * - If under a vlan_filtering=1 bridge which it offload:
|
| 1964 | * - the bridge VLANs
|
| 1965 | * - the 8021q upper VLANs
|
| 1966 |
|
| 1967 | int dsa_user_manage_vlan_filtering(struct net_device *user,
|
| 1968 | bool vlan_filtering)
|
| 1969 | {
|
| 1970 | int err;
|
| 1971 |
|
| 1972 | if (vlan_filtering) {
|
| 1973 | user->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
|
| 1974 |
|
| 1975 | err = vlan_for_each(user, dsa_user_restore_vlan, user);
|
| 1976 | if (err) {
|
| 1977 | vlan_for_each(user, dsa_user_clear_vlan, user);
|
| 1978 | user->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
|
| 1979 | return err;
|
| 1980 | }
|
| 1981 | } else {
|
| 1982 | err = vlan_for_each(user, dsa_user_clear_vlan, user);
|
| 1983 | if (err)
|
| 1984 | return err;
|
| 1985 |
|
| 1986 | user->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
|
| 1987 | }
|
| 1988 |
|
| 1989 | return 0;
|
| 1990 | }
|
| 1991 |
|
| 1992 | struct dsa_hw_port {
|
| 1993 | struct list_head list;
|
| 1994 | struct net_device *dev;
|
| 1995 | int old_mtu;
|
| 1996 | };
|
| 1997 |
|
| 1998 | static int dsa_hw_port_list_set_mtu(struct list_head *hw_port_list, int mtu)
|
| 1999 | {
|
| 2000 | const struct dsa_hw_port *p;
|
| 2001 | int err;
|
| 2002 |
|
| 2003 | list_for_each_entry(p, hw_port_list, list) {
|
| 2004 | if (p->dev->mtu == mtu)
|
| 2005 | continue;
|
| 2006 |
|
| 2007 | err = dev_set_mtu(p->dev, mtu);
|
| 2008 | if (err)
|
| 2009 | goto rollback;
|
| 2010 | }
|
| 2011 |
|
| 2012 | return 0;
|
| 2013 |
|
| 2014 | rollback:
|
| 2015 | list_for_each_entry_continue_reverse(p, hw_port_list, list) {
|
| 2016 | if (p->dev->mtu == p->old_mtu)
|
| 2017 | continue;
|
| 2018 |
|
| 2019 | if (dev_set_mtu(p->dev, p->old_mtu))
|
| 2020 | netdev_err(p->dev, "Failed to restore MTU\n");
|
| 2021 | }
|
| 2022 |
|
| 2023 | return err;
|
| 2024 | }
|
| 2025 |
|
| 2026 | static void dsa_hw_port_list_free(struct list_head *hw_port_list)
|
| 2027 | {
|
| 2028 | struct dsa_hw_port *p, *n;
|
| 2029 |
|
| 2030 | list_for_each_entry_safe(p, n, hw_port_list, list)
|
| 2031 | kfree(p);
|
| 2032 | }
|
| 2033 |
|
| 2034 |
|
| 2035 | static void dsa_bridge_mtu_normalization(struct dsa_port *dp)
|
| 2036 | {
|
| 2037 | struct list_head hw_port_list;
|
| 2038 | struct dsa_switch_tree *dst;
|
| 2039 | int min_mtu = ETH_MAX_MTU;
|
| 2040 | struct dsa_port *other_dp;
|
| 2041 | int err;
|
| 2042 |
|
| 2043 | if (!dp->ds->mtu_enforcement_ingress)
|
| 2044 | return;
|
| 2045 |
|
| 2046 | if (!dp->bridge)
|
| 2047 | return;
|
| 2048 |
|
| 2049 | INIT_LIST_HEAD(&hw_port_list);
|
| 2050 |
|
| 2051 | |
| 2052 | * as the newly added/modified port
|
| 2053 |
|
| 2054 | list_for_each_entry(dst, &dsa_tree_list, list) {
|
| 2055 | list_for_each_entry(other_dp, &dst->ports, list) {
|
| 2056 | struct dsa_hw_port *hw_port;
|
| 2057 | struct net_device *user;
|
| 2058 |
|
| 2059 | if (other_dp->type != DSA_PORT_TYPE_USER)
|
| 2060 | continue;
|
| 2061 |
|
| 2062 | if (!dsa_port_bridge_same(dp, other_dp))
|
| 2063 | continue;
|
| 2064 |
|
| 2065 | if (!other_dp->ds->mtu_enforcement_ingress)
|
| 2066 | continue;
|
| 2067 |
|
| 2068 | user = other_dp->user;
|
| 2069 |
|
| 2070 | if (min_mtu > user->mtu)
|
| 2071 | min_mtu = user->mtu;
|
| 2072 |
|
| 2073 | hw_port = kzalloc_obj(*hw_port);
|
| 2074 | if (!hw_port)
|
| 2075 | goto out;
|
| 2076 |
|
| 2077 | hw_port->dev = user;
|
| 2078 | hw_port->old_mtu = user->mtu;
|
| 2079 |
|
| 2080 | list_add(&hw_port->list, &hw_port_list);
|
| 2081 | }
|
| 2082 | }
|
| 2083 |
|
| 2084 | |
| 2085 | * interface's MTU first, regardless of whether the intention of the
|
| 2086 | * user was to raise or lower it.
|
| 2087 |
|
| 2088 | err = dsa_hw_port_list_set_mtu(&hw_port_list, dp->user->mtu);
|
| 2089 | if (!err)
|
| 2090 | goto out;
|
| 2091 |
|
| 2092 | |
| 2093 | * all hardware bridge ports now. If this fails too, then all ports will
|
| 2094 | * still have their old MTU rolled back anyway.
|
| 2095 |
|
| 2096 | dsa_hw_port_list_set_mtu(&hw_port_list, min_mtu);
|
| 2097 |
|
| 2098 | out:
|
| 2099 | dsa_hw_port_list_free(&hw_port_list);
|
| 2100 | }
|
| 2101 |
|
| 2102 | int dsa_user_change_mtu(struct net_device *dev, int new_mtu)
|
| 2103 | {
|
| 2104 | struct net_device *conduit = dsa_user_to_conduit(dev);
|
| 2105 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 2106 | struct dsa_port *cpu_dp = dp->cpu_dp;
|
| 2107 | struct dsa_switch *ds = dp->ds;
|
| 2108 | struct dsa_port *other_dp;
|
| 2109 | int largest_mtu = 0;
|
| 2110 | int new_conduit_mtu;
|
| 2111 | int old_conduit_mtu;
|
| 2112 | int mtu_limit;
|
| 2113 | int overhead;
|
| 2114 | int cpu_mtu;
|
| 2115 | int err;
|
| 2116 |
|
| 2117 | if (!ds->ops->port_change_mtu)
|
| 2118 | return -EOPNOTSUPP;
|
| 2119 |
|
| 2120 | dsa_tree_for_each_user_port(other_dp, ds->dst) {
|
| 2121 | int user_mtu;
|
| 2122 |
|
| 2123 | |
| 2124 | * device, while not all of them have been allocated. That's
|
| 2125 | * ok, it doesn't change what the maximum is, so ignore it.
|
| 2126 |
|
| 2127 | if (!other_dp->user)
|
| 2128 | continue;
|
| 2129 |
|
| 2130 | |
| 2131 | * actually haven't (still haven't done all integrity checks)
|
| 2132 |
|
| 2133 | if (dp == other_dp)
|
| 2134 | user_mtu = new_mtu;
|
| 2135 | else
|
| 2136 | user_mtu = other_dp->user->mtu;
|
| 2137 |
|
| 2138 | if (largest_mtu < user_mtu)
|
| 2139 | largest_mtu = user_mtu;
|
| 2140 | }
|
| 2141 |
|
| 2142 | overhead = dsa_tag_protocol_overhead(cpu_dp->tag_ops);
|
| 2143 | mtu_limit = min_t(int, conduit->max_mtu, dev->max_mtu + overhead);
|
| 2144 | old_conduit_mtu = conduit->mtu;
|
| 2145 | new_conduit_mtu = largest_mtu + overhead;
|
| 2146 | if (new_conduit_mtu > mtu_limit)
|
| 2147 | return -ERANGE;
|
| 2148 |
|
| 2149 | |
| 2150 | * MTU, since that surely isn't either.
|
| 2151 |
|
| 2152 | cpu_mtu = largest_mtu;
|
| 2153 |
|
| 2154 |
|
| 2155 | if (new_conduit_mtu != old_conduit_mtu) {
|
| 2156 | err = dev_set_mtu(conduit, new_conduit_mtu);
|
| 2157 | if (err < 0)
|
| 2158 | goto out_conduit_failed;
|
| 2159 |
|
| 2160 | |
| 2161 | * upstream switches, so emit a notifier which updates them.
|
| 2162 |
|
| 2163 | err = dsa_port_mtu_change(cpu_dp, cpu_mtu);
|
| 2164 | if (err)
|
| 2165 | goto out_cpu_failed;
|
| 2166 | }
|
| 2167 |
|
| 2168 | err = ds->ops->port_change_mtu(ds, dp->index, new_mtu);
|
| 2169 | if (err)
|
| 2170 | goto out_port_failed;
|
| 2171 |
|
| 2172 | WRITE_ONCE(dev->mtu, new_mtu);
|
| 2173 |
|
| 2174 | dsa_bridge_mtu_normalization(dp);
|
| 2175 |
|
| 2176 | return 0;
|
| 2177 |
|
| 2178 | out_port_failed:
|
| 2179 | if (new_conduit_mtu != old_conduit_mtu)
|
| 2180 | dsa_port_mtu_change(cpu_dp, old_conduit_mtu - overhead);
|
| 2181 | out_cpu_failed:
|
| 2182 | if (new_conduit_mtu != old_conduit_mtu)
|
| 2183 | dev_set_mtu(conduit, old_conduit_mtu);
|
| 2184 | out_conduit_failed:
|
| 2185 | return err;
|
| 2186 | }
|
| 2187 |
|
| 2188 | static int __maybe_unused
|
| 2189 | dsa_user_dcbnl_set_apptrust(struct net_device *dev, u8 *sel, int nsel)
|
| 2190 | {
|
| 2191 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 2192 | struct dsa_switch *ds = dp->ds;
|
| 2193 | int port = dp->index;
|
| 2194 |
|
| 2195 | if (!ds->ops->port_set_apptrust)
|
| 2196 | return -EOPNOTSUPP;
|
| 2197 |
|
| 2198 | return ds->ops->port_set_apptrust(ds, port, sel, nsel);
|
| 2199 | }
|
| 2200 |
|
| 2201 | static int __maybe_unused
|
| 2202 | dsa_user_dcbnl_get_apptrust(struct net_device *dev, u8 *sel, int *nsel)
|
| 2203 | {
|
| 2204 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 2205 | struct dsa_switch *ds = dp->ds;
|
| 2206 | int port = dp->index;
|
| 2207 |
|
| 2208 | if (!ds->ops->port_get_apptrust)
|
| 2209 | return -EOPNOTSUPP;
|
| 2210 |
|
| 2211 | return ds->ops->port_get_apptrust(ds, port, sel, nsel);
|
| 2212 | }
|
| 2213 |
|
| 2214 | static int __maybe_unused
|
| 2215 | dsa_user_dcbnl_set_default_prio(struct net_device *dev, struct dcb_app *app)
|
| 2216 | {
|
| 2217 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 2218 | struct dsa_switch *ds = dp->ds;
|
| 2219 | unsigned long mask, new_prio;
|
| 2220 | int err, port = dp->index;
|
| 2221 |
|
| 2222 | if (!ds->ops->port_set_default_prio)
|
| 2223 | return -EOPNOTSUPP;
|
| 2224 |
|
| 2225 | err = dcb_ieee_setapp(dev, app);
|
| 2226 | if (err)
|
| 2227 | return err;
|
| 2228 |
|
| 2229 | mask = dcb_ieee_getapp_mask(dev, app);
|
| 2230 | new_prio = __fls(mask);
|
| 2231 |
|
| 2232 | err = ds->ops->port_set_default_prio(ds, port, new_prio);
|
| 2233 | if (err) {
|
| 2234 | dcb_ieee_delapp(dev, app);
|
| 2235 | return err;
|
| 2236 | }
|
| 2237 |
|
| 2238 | return 0;
|
| 2239 | }
|
| 2240 |
|
| 2241 | |
| 2242 | * the switch supports global DSCP prio instead of per port DSCP prios.
|
| 2243 |
|
| 2244 | static int dsa_user_dcbnl_ieee_global_dscp_setdel(struct net_device *dev,
|
| 2245 | struct dcb_app *app, bool del)
|
| 2246 | {
|
| 2247 | int (*setdel)(struct net_device *dev, struct dcb_app *app);
|
| 2248 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 2249 | struct dsa_switch *ds = dp->ds;
|
| 2250 | struct dsa_port *other_dp;
|
| 2251 | int err, restore_err;
|
| 2252 |
|
| 2253 | if (del)
|
| 2254 | setdel = dcb_ieee_delapp;
|
| 2255 | else
|
| 2256 | setdel = dcb_ieee_setapp;
|
| 2257 |
|
| 2258 | dsa_switch_for_each_user_port(other_dp, ds) {
|
| 2259 | struct net_device *user = other_dp->user;
|
| 2260 |
|
| 2261 | if (!user || user == dev)
|
| 2262 | continue;
|
| 2263 |
|
| 2264 | err = setdel(user, app);
|
| 2265 | if (err)
|
| 2266 | goto err_try_to_restore;
|
| 2267 | }
|
| 2268 |
|
| 2269 | return 0;
|
| 2270 |
|
| 2271 | err_try_to_restore:
|
| 2272 |
|
| 2273 |
|
| 2274 | if (!del)
|
| 2275 | setdel = dcb_ieee_delapp;
|
| 2276 | else
|
| 2277 | setdel = dcb_ieee_setapp;
|
| 2278 |
|
| 2279 | dsa_switch_for_each_user_port_continue_reverse(other_dp, ds) {
|
| 2280 | struct net_device *user = other_dp->user;
|
| 2281 |
|
| 2282 | if (!user || user == dev)
|
| 2283 | continue;
|
| 2284 |
|
| 2285 | restore_err = setdel(user, app);
|
| 2286 | if (restore_err)
|
| 2287 | netdev_err(user, "Failed to restore DSCP prio entry configuration\n");
|
| 2288 | }
|
| 2289 |
|
| 2290 | return err;
|
| 2291 | }
|
| 2292 |
|
| 2293 | static int __maybe_unused
|
| 2294 | dsa_user_dcbnl_add_dscp_prio(struct net_device *dev, struct dcb_app *app)
|
| 2295 | {
|
| 2296 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 2297 | struct dsa_switch *ds = dp->ds;
|
| 2298 | unsigned long mask, new_prio;
|
| 2299 | int err, port = dp->index;
|
| 2300 | u8 dscp = app->protocol;
|
| 2301 |
|
| 2302 | if (!ds->ops->port_add_dscp_prio)
|
| 2303 | return -EOPNOTSUPP;
|
| 2304 |
|
| 2305 | if (dscp >= 64) {
|
| 2306 | netdev_err(dev, "DSCP APP entry with protocol value %u is invalid\n",
|
| 2307 | dscp);
|
| 2308 | return -EINVAL;
|
| 2309 | }
|
| 2310 |
|
| 2311 | err = dcb_ieee_setapp(dev, app);
|
| 2312 | if (err)
|
| 2313 | return err;
|
| 2314 |
|
| 2315 | mask = dcb_ieee_getapp_mask(dev, app);
|
| 2316 | new_prio = __fls(mask);
|
| 2317 |
|
| 2318 | err = ds->ops->port_add_dscp_prio(ds, port, dscp, new_prio);
|
| 2319 | if (err) {
|
| 2320 | dcb_ieee_delapp(dev, app);
|
| 2321 | return err;
|
| 2322 | }
|
| 2323 |
|
| 2324 | if (!ds->dscp_prio_mapping_is_global)
|
| 2325 | return 0;
|
| 2326 |
|
| 2327 | err = dsa_user_dcbnl_ieee_global_dscp_setdel(dev, app, false);
|
| 2328 | if (err) {
|
| 2329 | if (ds->ops->port_del_dscp_prio)
|
| 2330 | ds->ops->port_del_dscp_prio(ds, port, dscp, new_prio);
|
| 2331 | dcb_ieee_delapp(dev, app);
|
| 2332 | return err;
|
| 2333 | }
|
| 2334 |
|
| 2335 | return 0;
|
| 2336 | }
|
| 2337 |
|
| 2338 | static int __maybe_unused dsa_user_dcbnl_ieee_setapp(struct net_device *dev,
|
| 2339 | struct dcb_app *app)
|
| 2340 | {
|
| 2341 | switch (app->selector) {
|
| 2342 | case IEEE_8021QAZ_APP_SEL_ETHERTYPE:
|
| 2343 | switch (app->protocol) {
|
| 2344 | case 0:
|
| 2345 | return dsa_user_dcbnl_set_default_prio(dev, app);
|
| 2346 | default:
|
| 2347 | return -EOPNOTSUPP;
|
| 2348 | }
|
| 2349 | break;
|
| 2350 | case IEEE_8021QAZ_APP_SEL_DSCP:
|
| 2351 | return dsa_user_dcbnl_add_dscp_prio(dev, app);
|
| 2352 | default:
|
| 2353 | return -EOPNOTSUPP;
|
| 2354 | }
|
| 2355 | }
|
| 2356 |
|
| 2357 | static int __maybe_unused
|
| 2358 | dsa_user_dcbnl_del_default_prio(struct net_device *dev, struct dcb_app *app)
|
| 2359 | {
|
| 2360 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 2361 | struct dsa_switch *ds = dp->ds;
|
| 2362 | unsigned long mask, new_prio;
|
| 2363 | int err, port = dp->index;
|
| 2364 |
|
| 2365 | if (!ds->ops->port_set_default_prio)
|
| 2366 | return -EOPNOTSUPP;
|
| 2367 |
|
| 2368 | err = dcb_ieee_delapp(dev, app);
|
| 2369 | if (err)
|
| 2370 | return err;
|
| 2371 |
|
| 2372 | mask = dcb_ieee_getapp_mask(dev, app);
|
| 2373 | new_prio = mask ? __fls(mask) : 0;
|
| 2374 |
|
| 2375 | err = ds->ops->port_set_default_prio(ds, port, new_prio);
|
| 2376 | if (err) {
|
| 2377 | dcb_ieee_setapp(dev, app);
|
| 2378 | return err;
|
| 2379 | }
|
| 2380 |
|
| 2381 | return 0;
|
| 2382 | }
|
| 2383 |
|
| 2384 | static int __maybe_unused
|
| 2385 | dsa_user_dcbnl_del_dscp_prio(struct net_device *dev, struct dcb_app *app)
|
| 2386 | {
|
| 2387 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 2388 | struct dsa_switch *ds = dp->ds;
|
| 2389 | int err, port = dp->index;
|
| 2390 | u8 dscp = app->protocol;
|
| 2391 |
|
| 2392 | if (!ds->ops->port_del_dscp_prio)
|
| 2393 | return -EOPNOTSUPP;
|
| 2394 |
|
| 2395 | err = dcb_ieee_delapp(dev, app);
|
| 2396 | if (err)
|
| 2397 | return err;
|
| 2398 |
|
| 2399 | err = ds->ops->port_del_dscp_prio(ds, port, dscp, app->priority);
|
| 2400 | if (err) {
|
| 2401 | dcb_ieee_setapp(dev, app);
|
| 2402 | return err;
|
| 2403 | }
|
| 2404 |
|
| 2405 | if (!ds->dscp_prio_mapping_is_global)
|
| 2406 | return 0;
|
| 2407 |
|
| 2408 | err = dsa_user_dcbnl_ieee_global_dscp_setdel(dev, app, true);
|
| 2409 | if (err) {
|
| 2410 | if (ds->ops->port_add_dscp_prio)
|
| 2411 | ds->ops->port_add_dscp_prio(ds, port, dscp,
|
| 2412 | app->priority);
|
| 2413 | dcb_ieee_setapp(dev, app);
|
| 2414 | return err;
|
| 2415 | }
|
| 2416 |
|
| 2417 | return 0;
|
| 2418 | }
|
| 2419 |
|
| 2420 | static int __maybe_unused dsa_user_dcbnl_ieee_delapp(struct net_device *dev,
|
| 2421 | struct dcb_app *app)
|
| 2422 | {
|
| 2423 | switch (app->selector) {
|
| 2424 | case IEEE_8021QAZ_APP_SEL_ETHERTYPE:
|
| 2425 | switch (app->protocol) {
|
| 2426 | case 0:
|
| 2427 | return dsa_user_dcbnl_del_default_prio(dev, app);
|
| 2428 | default:
|
| 2429 | return -EOPNOTSUPP;
|
| 2430 | }
|
| 2431 | break;
|
| 2432 | case IEEE_8021QAZ_APP_SEL_DSCP:
|
| 2433 | return dsa_user_dcbnl_del_dscp_prio(dev, app);
|
| 2434 | default:
|
| 2435 | return -EOPNOTSUPP;
|
| 2436 | }
|
| 2437 | }
|
| 2438 |
|
| 2439 | |
| 2440 | * configured during switch setup, which we read from hardware here.
|
| 2441 |
|
| 2442 | static int dsa_user_dcbnl_init(struct net_device *dev)
|
| 2443 | {
|
| 2444 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 2445 | struct dsa_switch *ds = dp->ds;
|
| 2446 | int port = dp->index;
|
| 2447 | int err;
|
| 2448 |
|
| 2449 | if (ds->ops->port_get_default_prio) {
|
| 2450 | int prio = ds->ops->port_get_default_prio(ds, port);
|
| 2451 | struct dcb_app app = {
|
| 2452 | .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
|
| 2453 | .protocol = 0,
|
| 2454 | .priority = prio,
|
| 2455 | };
|
| 2456 |
|
| 2457 | if (prio < 0)
|
| 2458 | return prio;
|
| 2459 |
|
| 2460 | err = dcb_ieee_setapp(dev, &app);
|
| 2461 | if (err)
|
| 2462 | return err;
|
| 2463 | }
|
| 2464 |
|
| 2465 | if (ds->ops->port_get_dscp_prio) {
|
| 2466 | int protocol;
|
| 2467 |
|
| 2468 | for (protocol = 0; protocol < 64; protocol++) {
|
| 2469 | struct dcb_app app = {
|
| 2470 | .selector = IEEE_8021QAZ_APP_SEL_DSCP,
|
| 2471 | .protocol = protocol,
|
| 2472 | };
|
| 2473 | int prio;
|
| 2474 |
|
| 2475 | prio = ds->ops->port_get_dscp_prio(ds, port, protocol);
|
| 2476 | if (prio == -EOPNOTSUPP)
|
| 2477 | continue;
|
| 2478 | if (prio < 0)
|
| 2479 | return prio;
|
| 2480 |
|
| 2481 | app.priority = prio;
|
| 2482 |
|
| 2483 | err = dcb_ieee_setapp(dev, &app);
|
| 2484 | if (err)
|
| 2485 | return err;
|
| 2486 | }
|
| 2487 | }
|
| 2488 |
|
| 2489 | return 0;
|
| 2490 | }
|
| 2491 |
|
| 2492 | static const struct ethtool_ops dsa_user_ethtool_ops = {
|
| 2493 | .get_drvinfo = dsa_user_get_drvinfo,
|
| 2494 | .get_regs_len = dsa_user_get_regs_len,
|
| 2495 | .get_regs = dsa_user_get_regs,
|
| 2496 | .nway_reset = dsa_user_nway_reset,
|
| 2497 | .get_link = ethtool_op_get_link,
|
| 2498 | .get_eeprom_len = dsa_user_get_eeprom_len,
|
| 2499 | .get_eeprom = dsa_user_get_eeprom,
|
| 2500 | .set_eeprom = dsa_user_set_eeprom,
|
| 2501 | .get_strings = dsa_user_get_strings,
|
| 2502 | .get_ethtool_stats = dsa_user_get_ethtool_stats,
|
| 2503 | .get_sset_count = dsa_user_get_sset_count,
|
| 2504 | .get_eth_phy_stats = dsa_user_get_eth_phy_stats,
|
| 2505 | .get_eth_mac_stats = dsa_user_get_eth_mac_stats,
|
| 2506 | .get_eth_ctrl_stats = dsa_user_get_eth_ctrl_stats,
|
| 2507 | .get_rmon_stats = dsa_user_get_rmon_stats,
|
| 2508 | .get_ts_stats = dsa_user_get_ts_stats,
|
| 2509 | .set_wol = dsa_user_set_wol,
|
| 2510 | .get_wol = dsa_user_get_wol,
|
| 2511 | .set_eee = dsa_user_set_eee,
|
| 2512 | .get_eee = dsa_user_get_eee,
|
| 2513 | .get_link_ksettings = dsa_user_get_link_ksettings,
|
| 2514 | .set_link_ksettings = dsa_user_set_link_ksettings,
|
| 2515 | .get_pause_stats = dsa_user_get_pause_stats,
|
| 2516 | .get_pauseparam = dsa_user_get_pauseparam,
|
| 2517 | .set_pauseparam = dsa_user_set_pauseparam,
|
| 2518 | .get_rxnfc = dsa_user_get_rxnfc,
|
| 2519 | .set_rxnfc = dsa_user_set_rxnfc,
|
| 2520 | .get_ts_info = dsa_user_get_ts_info,
|
| 2521 | .self_test = dsa_user_net_selftest,
|
| 2522 | .get_mm = dsa_user_get_mm,
|
| 2523 | .set_mm = dsa_user_set_mm,
|
| 2524 | .get_mm_stats = dsa_user_get_mm_stats,
|
| 2525 | };
|
| 2526 |
|
| 2527 | static const struct dcbnl_rtnl_ops __maybe_unused dsa_user_dcbnl_ops = {
|
| 2528 | .ieee_setapp = dsa_user_dcbnl_ieee_setapp,
|
| 2529 | .ieee_delapp = dsa_user_dcbnl_ieee_delapp,
|
| 2530 | .dcbnl_setapptrust = dsa_user_dcbnl_set_apptrust,
|
| 2531 | .dcbnl_getapptrust = dsa_user_dcbnl_get_apptrust,
|
| 2532 | };
|
| 2533 |
|
| 2534 | static void dsa_user_get_stats64(struct net_device *dev,
|
| 2535 | struct rtnl_link_stats64 *s)
|
| 2536 | {
|
| 2537 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 2538 | struct dsa_switch *ds = dp->ds;
|
| 2539 |
|
| 2540 | if (ds->ops->get_stats64)
|
| 2541 | ds->ops->get_stats64(ds, dp->index, s);
|
| 2542 | else
|
| 2543 | dev_get_tstats64(dev, s);
|
| 2544 | }
|
| 2545 |
|
| 2546 | static int dsa_user_fill_forward_path(struct net_device_path_ctx *ctx,
|
| 2547 | struct net_device_path *path)
|
| 2548 | {
|
| 2549 | struct dsa_port *dp = dsa_user_to_port(ctx->dev);
|
| 2550 | struct dsa_port *cpu_dp = dp->cpu_dp;
|
| 2551 |
|
| 2552 | path->dev = ctx->dev;
|
| 2553 | path->type = DEV_PATH_DSA;
|
| 2554 | path->dsa.proto = cpu_dp->tag_ops->proto;
|
| 2555 | path->dsa.port = dp->index;
|
| 2556 | ctx->dev = NULL;
|
| 2557 |
|
| 2558 | return 0;
|
| 2559 | }
|
| 2560 |
|
| 2561 | static int dsa_user_hwtstamp_get(struct net_device *dev,
|
| 2562 | struct kernel_hwtstamp_config *cfg)
|
| 2563 | {
|
| 2564 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 2565 | struct dsa_switch *ds = dp->ds;
|
| 2566 |
|
| 2567 | if (!ds->ops->port_hwtstamp_get)
|
| 2568 | return -EOPNOTSUPP;
|
| 2569 |
|
| 2570 | return ds->ops->port_hwtstamp_get(ds, dp->index, cfg);
|
| 2571 | }
|
| 2572 |
|
| 2573 | static int dsa_user_hwtstamp_set(struct net_device *dev,
|
| 2574 | struct kernel_hwtstamp_config *cfg,
|
| 2575 | struct netlink_ext_ack *extack)
|
| 2576 | {
|
| 2577 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 2578 | struct dsa_switch *ds = dp->ds;
|
| 2579 |
|
| 2580 | if (!ds->ops->port_hwtstamp_set)
|
| 2581 | return -EOPNOTSUPP;
|
| 2582 |
|
| 2583 | return ds->ops->port_hwtstamp_set(ds, dp->index, cfg, extack);
|
| 2584 | }
|
| 2585 |
|
| 2586 | static const struct net_device_ops dsa_user_netdev_ops = {
|
| 2587 | .ndo_open = dsa_user_open,
|
| 2588 | .ndo_stop = dsa_user_close,
|
| 2589 | .ndo_start_xmit = dsa_user_xmit,
|
| 2590 | .ndo_change_rx_flags = dsa_user_change_rx_flags,
|
| 2591 | .ndo_set_rx_mode = dsa_user_set_rx_mode,
|
| 2592 | .ndo_set_mac_address = dsa_user_set_mac_address,
|
| 2593 | .ndo_fdb_dump = dsa_user_fdb_dump,
|
| 2594 | .ndo_eth_ioctl = dsa_user_ioctl,
|
| 2595 | .ndo_get_iflink = dsa_user_get_iflink,
|
| 2596 | #ifdef CONFIG_NET_POLL_CONTROLLER
|
| 2597 | .ndo_netpoll_setup = dsa_user_netpoll_setup,
|
| 2598 | .ndo_netpoll_cleanup = dsa_user_netpoll_cleanup,
|
| 2599 | .ndo_poll_controller = dsa_user_poll_controller,
|
| 2600 | #endif
|
| 2601 | .ndo_setup_tc = dsa_user_setup_tc,
|
| 2602 | .ndo_get_stats64 = dsa_user_get_stats64,
|
| 2603 | .ndo_vlan_rx_add_vid = dsa_user_vlan_rx_add_vid,
|
| 2604 | .ndo_vlan_rx_kill_vid = dsa_user_vlan_rx_kill_vid,
|
| 2605 | .ndo_change_mtu = dsa_user_change_mtu,
|
| 2606 | .ndo_fill_forward_path = dsa_user_fill_forward_path,
|
| 2607 | .ndo_hwtstamp_get = dsa_user_hwtstamp_get,
|
| 2608 | .ndo_hwtstamp_set = dsa_user_hwtstamp_set,
|
| 2609 | };
|
| 2610 |
|
| 2611 | static const struct device_type dsa_type = {
|
| 2612 | .name = "dsa",
|
| 2613 | };
|
| 2614 |
|
| 2615 | void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up)
|
| 2616 | {
|
| 2617 | const struct dsa_port *dp = dsa_to_port(ds, port);
|
| 2618 |
|
| 2619 | if (dp->pl)
|
| 2620 | phylink_mac_change(dp->pl, up);
|
| 2621 | }
|
| 2622 | EXPORT_SYMBOL_GPL(dsa_port_phylink_mac_change);
|
| 2623 |
|
| 2624 | static void dsa_user_phylink_fixed_state(struct phylink_config *config,
|
| 2625 | struct phylink_link_state *state)
|
| 2626 | {
|
| 2627 | struct dsa_port *dp = dsa_phylink_to_port(config);
|
| 2628 | struct dsa_switch *ds = dp->ds;
|
| 2629 |
|
| 2630 | |
| 2631 | * not be called if it was not.
|
| 2632 |
|
| 2633 | ds->ops->phylink_fixed_state(ds, dp->index, state);
|
| 2634 | }
|
| 2635 |
|
| 2636 |
|
| 2637 | static int dsa_user_phy_connect(struct net_device *user_dev, int addr,
|
| 2638 | u32 flags)
|
| 2639 | {
|
| 2640 | struct dsa_port *dp = dsa_user_to_port(user_dev);
|
| 2641 | struct dsa_switch *ds = dp->ds;
|
| 2642 |
|
| 2643 | user_dev->phydev = mdiobus_get_phy(ds->user_mii_bus, addr);
|
| 2644 | if (!user_dev->phydev) {
|
| 2645 | netdev_err(user_dev, "no phy at %d\n", addr);
|
| 2646 | return -ENODEV;
|
| 2647 | }
|
| 2648 |
|
| 2649 | user_dev->phydev->dev_flags |= flags;
|
| 2650 |
|
| 2651 | return phylink_connect_phy(dp->pl, user_dev->phydev);
|
| 2652 | }
|
| 2653 |
|
| 2654 | static int dsa_user_phy_setup(struct net_device *user_dev)
|
| 2655 | {
|
| 2656 | struct dsa_port *dp = dsa_user_to_port(user_dev);
|
| 2657 | struct device_node *port_dn = dp->dn;
|
| 2658 | struct dsa_switch *ds = dp->ds;
|
| 2659 | u32 phy_flags = 0;
|
| 2660 | int ret;
|
| 2661 |
|
| 2662 | dp->pl_config.dev = &user_dev->dev;
|
| 2663 | dp->pl_config.type = PHYLINK_NETDEV;
|
| 2664 |
|
| 2665 | |
| 2666 | * link GPIO in PHYLINK (see phylink_get_fixed_state). Only set
|
| 2667 | * this if the switch provides such a callback.
|
| 2668 |
|
| 2669 | if (ds->ops->phylink_fixed_state) {
|
| 2670 | dp->pl_config.get_fixed_state = dsa_user_phylink_fixed_state;
|
| 2671 | dp->pl_config.poll_fixed_state = true;
|
| 2672 | }
|
| 2673 |
|
| 2674 | ret = dsa_port_phylink_create(dp);
|
| 2675 | if (ret)
|
| 2676 | return ret;
|
| 2677 |
|
| 2678 | if (ds->ops->get_phy_flags)
|
| 2679 | phy_flags = ds->ops->get_phy_flags(ds, dp->index);
|
| 2680 |
|
| 2681 | ret = phylink_of_phy_connect(dp->pl, port_dn, phy_flags);
|
| 2682 | if (ret == -ENODEV && ds->user_mii_bus) {
|
| 2683 | |
| 2684 | * use the switch internal MDIO bus instead
|
| 2685 |
|
| 2686 | ret = dsa_user_phy_connect(user_dev, dp->index, phy_flags);
|
| 2687 | }
|
| 2688 | if (ret) {
|
| 2689 | netdev_err(user_dev, "failed to connect to PHY: %pe\n",
|
| 2690 | ERR_PTR(ret));
|
| 2691 | dsa_port_phylink_destroy(dp);
|
| 2692 | }
|
| 2693 |
|
| 2694 | return ret;
|
| 2695 | }
|
| 2696 |
|
| 2697 | void dsa_user_setup_tagger(struct net_device *user)
|
| 2698 | {
|
| 2699 | struct dsa_port *dp = dsa_user_to_port(user);
|
| 2700 | struct net_device *conduit = dsa_port_to_conduit(dp);
|
| 2701 | struct dsa_user_priv *p = netdev_priv(user);
|
| 2702 | const struct dsa_port *cpu_dp = dp->cpu_dp;
|
| 2703 | const struct dsa_switch *ds = dp->ds;
|
| 2704 |
|
| 2705 | user->needed_headroom = cpu_dp->tag_ops->needed_headroom;
|
| 2706 | user->needed_tailroom = cpu_dp->tag_ops->needed_tailroom;
|
| 2707 | |
| 2708 | * by also inheriting the conduit's needed headroom and tailroom.
|
| 2709 | * The 8021q driver also does this.
|
| 2710 |
|
| 2711 | user->needed_headroom += conduit->needed_headroom;
|
| 2712 | user->needed_tailroom += conduit->needed_tailroom;
|
| 2713 |
|
| 2714 | p->xmit = cpu_dp->tag_ops->xmit;
|
| 2715 |
|
| 2716 | user->features = conduit->vlan_features | NETIF_F_HW_TC;
|
| 2717 | user->hw_features |= NETIF_F_HW_TC;
|
| 2718 | if (user->needed_tailroom)
|
| 2719 | user->features &= ~(NETIF_F_SG | NETIF_F_FRAGLIST);
|
| 2720 | if (ds->needs_standalone_vlan_filtering)
|
| 2721 | user->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
|
| 2722 |
|
| 2723 | user->lltx = true;
|
| 2724 | }
|
| 2725 |
|
| 2726 | int dsa_user_suspend(struct net_device *user_dev)
|
| 2727 | {
|
| 2728 | struct dsa_port *dp = dsa_user_to_port(user_dev);
|
| 2729 |
|
| 2730 | if (!netif_running(user_dev))
|
| 2731 | return 0;
|
| 2732 |
|
| 2733 | netif_device_detach(user_dev);
|
| 2734 |
|
| 2735 | rtnl_lock();
|
| 2736 | phylink_stop(dp->pl);
|
| 2737 | rtnl_unlock();
|
| 2738 |
|
| 2739 | return 0;
|
| 2740 | }
|
| 2741 |
|
| 2742 | int dsa_user_resume(struct net_device *user_dev)
|
| 2743 | {
|
| 2744 | struct dsa_port *dp = dsa_user_to_port(user_dev);
|
| 2745 |
|
| 2746 | if (!netif_running(user_dev))
|
| 2747 | return 0;
|
| 2748 |
|
| 2749 | netif_device_attach(user_dev);
|
| 2750 |
|
| 2751 | rtnl_lock();
|
| 2752 | phylink_start(dp->pl);
|
| 2753 | rtnl_unlock();
|
| 2754 |
|
| 2755 | return 0;
|
| 2756 | }
|
| 2757 |
|
| 2758 | int dsa_user_create(struct dsa_port *port)
|
| 2759 | {
|
| 2760 | struct net_device *conduit = dsa_port_to_conduit(port);
|
| 2761 | struct dsa_switch *ds = port->ds;
|
| 2762 | struct net_device *user_dev;
|
| 2763 | struct dsa_user_priv *p;
|
| 2764 | const char *name;
|
| 2765 | int assign_type;
|
| 2766 | int ret;
|
| 2767 |
|
| 2768 | if (!ds->num_tx_queues)
|
| 2769 | ds->num_tx_queues = 1;
|
| 2770 |
|
| 2771 | if (port->name) {
|
| 2772 | name = port->name;
|
| 2773 | assign_type = NET_NAME_PREDICTABLE;
|
| 2774 | } else {
|
| 2775 | name = "eth%d";
|
| 2776 | assign_type = NET_NAME_ENUM;
|
| 2777 | }
|
| 2778 |
|
| 2779 | user_dev = alloc_netdev_mqs(sizeof(struct dsa_user_priv), name,
|
| 2780 | assign_type, ether_setup,
|
| 2781 | ds->num_tx_queues, 1);
|
| 2782 | if (!user_dev)
|
| 2783 | return -ENOMEM;
|
| 2784 |
|
| 2785 | user_dev->rtnl_link_ops = &dsa_link_ops;
|
| 2786 | user_dev->ethtool_ops = &dsa_user_ethtool_ops;
|
| 2787 | #if IS_ENABLED(CONFIG_DCB)
|
| 2788 | user_dev->dcbnl_ops = &dsa_user_dcbnl_ops;
|
| 2789 | #endif
|
| 2790 | if (!is_zero_ether_addr(port->mac))
|
| 2791 | eth_hw_addr_set(user_dev, port->mac);
|
| 2792 | else
|
| 2793 | eth_hw_addr_inherit(user_dev, conduit);
|
| 2794 | user_dev->priv_flags |= IFF_NO_QUEUE;
|
| 2795 | if (dsa_switch_supports_uc_filtering(ds))
|
| 2796 | user_dev->priv_flags |= IFF_UNICAST_FLT;
|
| 2797 | user_dev->netdev_ops = &dsa_user_netdev_ops;
|
| 2798 | if (ds->ops->port_max_mtu)
|
| 2799 | user_dev->max_mtu = ds->ops->port_max_mtu(ds, port->index);
|
| 2800 | SET_NETDEV_DEVTYPE(user_dev, &dsa_type);
|
| 2801 |
|
| 2802 | SET_NETDEV_DEV(user_dev, port->ds->dev);
|
| 2803 | SET_NETDEV_DEVLINK_PORT(user_dev, &port->devlink_port);
|
| 2804 | user_dev->dev.of_node = port->dn;
|
| 2805 | user_dev->vlan_features = conduit->vlan_features;
|
| 2806 |
|
| 2807 | p = netdev_priv(user_dev);
|
| 2808 | user_dev->pcpu_stat_type = NETDEV_PCPU_STAT_TSTATS;
|
| 2809 |
|
| 2810 | ret = gro_cells_init(&p->gcells, user_dev);
|
| 2811 | if (ret)
|
| 2812 | goto out_free;
|
| 2813 |
|
| 2814 | p->dp = port;
|
| 2815 | INIT_LIST_HEAD(&p->mall_tc_list);
|
| 2816 | port->user = user_dev;
|
| 2817 | dsa_user_setup_tagger(user_dev);
|
| 2818 |
|
| 2819 | netif_carrier_off(user_dev);
|
| 2820 |
|
| 2821 | ret = dsa_user_phy_setup(user_dev);
|
| 2822 | if (ret) {
|
| 2823 | netdev_err(user_dev,
|
| 2824 | "error %d setting up PHY for tree %d, switch %d, port %d\n",
|
| 2825 | ret, ds->dst->index, ds->index, port->index);
|
| 2826 | goto out_gcells;
|
| 2827 | }
|
| 2828 |
|
| 2829 | rtnl_lock();
|
| 2830 |
|
| 2831 | ret = dsa_user_change_mtu(user_dev, ETH_DATA_LEN);
|
| 2832 | if (ret && ret != -EOPNOTSUPP)
|
| 2833 | dev_warn(ds->dev, "nonfatal error %d setting MTU to %d on port %d\n",
|
| 2834 | ret, ETH_DATA_LEN, port->index);
|
| 2835 |
|
| 2836 | ret = register_netdevice(user_dev);
|
| 2837 | if (ret) {
|
| 2838 | netdev_err(conduit, "error %d registering interface %s\n",
|
| 2839 | ret, user_dev->name);
|
| 2840 | rtnl_unlock();
|
| 2841 | goto out_phy;
|
| 2842 | }
|
| 2843 |
|
| 2844 | if (IS_ENABLED(CONFIG_DCB)) {
|
| 2845 | ret = dsa_user_dcbnl_init(user_dev);
|
| 2846 | if (ret) {
|
| 2847 | netdev_err(user_dev,
|
| 2848 | "failed to initialize DCB: %pe\n",
|
| 2849 | ERR_PTR(ret));
|
| 2850 | rtnl_unlock();
|
| 2851 | goto out_unregister;
|
| 2852 | }
|
| 2853 | }
|
| 2854 |
|
| 2855 | ret = netdev_upper_dev_link(conduit, user_dev, NULL);
|
| 2856 |
|
| 2857 | rtnl_unlock();
|
| 2858 |
|
| 2859 | if (ret)
|
| 2860 | goto out_unregister;
|
| 2861 |
|
| 2862 | return 0;
|
| 2863 |
|
| 2864 | out_unregister:
|
| 2865 | unregister_netdev(user_dev);
|
| 2866 | out_phy:
|
| 2867 | rtnl_lock();
|
| 2868 | phylink_disconnect_phy(p->dp->pl);
|
| 2869 | rtnl_unlock();
|
| 2870 | dsa_port_phylink_destroy(p->dp);
|
| 2871 | out_gcells:
|
| 2872 | gro_cells_destroy(&p->gcells);
|
| 2873 | out_free:
|
| 2874 | free_netdev(user_dev);
|
| 2875 | port->user = NULL;
|
| 2876 | return ret;
|
| 2877 | }
|
| 2878 |
|
| 2879 | void dsa_user_destroy(struct net_device *user_dev)
|
| 2880 | {
|
| 2881 | struct net_device *conduit = dsa_user_to_conduit(user_dev);
|
| 2882 | struct dsa_port *dp = dsa_user_to_port(user_dev);
|
| 2883 | struct dsa_user_priv *p = netdev_priv(user_dev);
|
| 2884 |
|
| 2885 | netif_carrier_off(user_dev);
|
| 2886 | rtnl_lock();
|
| 2887 | netdev_upper_dev_unlink(conduit, user_dev);
|
| 2888 | unregister_netdevice(user_dev);
|
| 2889 | phylink_disconnect_phy(dp->pl);
|
| 2890 | rtnl_unlock();
|
| 2891 |
|
| 2892 | dsa_port_phylink_destroy(dp);
|
| 2893 | gro_cells_destroy(&p->gcells);
|
| 2894 | free_netdev(user_dev);
|
| 2895 | }
|
| 2896 |
|
| 2897 | int dsa_user_change_conduit(struct net_device *dev, struct net_device *conduit,
|
| 2898 | struct netlink_ext_ack *extack)
|
| 2899 | {
|
| 2900 | struct net_device *old_conduit = dsa_user_to_conduit(dev);
|
| 2901 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 2902 | struct dsa_switch *ds = dp->ds;
|
| 2903 | struct net_device *upper;
|
| 2904 | struct list_head *iter;
|
| 2905 | int err;
|
| 2906 |
|
| 2907 | if (conduit == old_conduit)
|
| 2908 | return 0;
|
| 2909 |
|
| 2910 | if (!ds->ops->port_change_conduit) {
|
| 2911 | NL_SET_ERR_MSG_MOD(extack,
|
| 2912 | "Driver does not support changing DSA conduit");
|
| 2913 | return -EOPNOTSUPP;
|
| 2914 | }
|
| 2915 |
|
| 2916 | if (!netdev_uses_dsa(conduit)) {
|
| 2917 | NL_SET_ERR_MSG_MOD(extack,
|
| 2918 | "Interface not eligible as DSA conduit");
|
| 2919 | return -EOPNOTSUPP;
|
| 2920 | }
|
| 2921 |
|
| 2922 | netdev_for_each_upper_dev_rcu(conduit, upper, iter) {
|
| 2923 | if (dsa_user_dev_check(upper))
|
| 2924 | continue;
|
| 2925 | if (netif_is_bridge_master(upper))
|
| 2926 | continue;
|
| 2927 | NL_SET_ERR_MSG_MOD(extack, "Cannot join conduit with unknown uppers");
|
| 2928 | return -EOPNOTSUPP;
|
| 2929 | }
|
| 2930 |
|
| 2931 | |
| 2932 | * DSA conduit when the user port opens => we need to ensure that the
|
| 2933 | * new DSA conduit is open too.
|
| 2934 |
|
| 2935 | if (dev->flags & IFF_UP) {
|
| 2936 | err = dev_open(conduit, extack);
|
| 2937 | if (err)
|
| 2938 | return err;
|
| 2939 | }
|
| 2940 |
|
| 2941 | netdev_upper_dev_unlink(old_conduit, dev);
|
| 2942 |
|
| 2943 | err = netdev_upper_dev_link(conduit, dev, extack);
|
| 2944 | if (err)
|
| 2945 | goto out_revert_old_conduit_unlink;
|
| 2946 |
|
| 2947 | err = dsa_port_change_conduit(dp, conduit, extack);
|
| 2948 | if (err)
|
| 2949 | goto out_revert_conduit_link;
|
| 2950 |
|
| 2951 |
|
| 2952 | err = dsa_user_change_mtu(dev, dev->mtu);
|
| 2953 | if (err && err != -EOPNOTSUPP) {
|
| 2954 | netdev_warn(dev,
|
| 2955 | "nonfatal error updating MTU with new conduit: %pe\n",
|
| 2956 | ERR_PTR(err));
|
| 2957 | }
|
| 2958 |
|
| 2959 | return 0;
|
| 2960 |
|
| 2961 | out_revert_conduit_link:
|
| 2962 | netdev_upper_dev_unlink(conduit, dev);
|
| 2963 | out_revert_old_conduit_unlink:
|
| 2964 | netdev_upper_dev_link(old_conduit, dev, NULL);
|
| 2965 | return err;
|
| 2966 | }
|
| 2967 |
|
| 2968 | bool dsa_user_dev_check(const struct net_device *dev)
|
| 2969 | {
|
| 2970 | return dev->netdev_ops == &dsa_user_netdev_ops;
|
| 2971 | }
|
| 2972 | EXPORT_SYMBOL_GPL(dsa_user_dev_check);
|
| 2973 |
|
| 2974 | static int dsa_user_changeupper(struct net_device *dev,
|
| 2975 | struct netdev_notifier_changeupper_info *info)
|
| 2976 | {
|
| 2977 | struct netlink_ext_ack *extack;
|
| 2978 | int err = NOTIFY_DONE;
|
| 2979 | struct dsa_port *dp;
|
| 2980 |
|
| 2981 | if (!dsa_user_dev_check(dev))
|
| 2982 | return err;
|
| 2983 |
|
| 2984 | dp = dsa_user_to_port(dev);
|
| 2985 | extack = netdev_notifier_info_to_extack(&info->info);
|
| 2986 |
|
| 2987 | if (netif_is_bridge_master(info->upper_dev)) {
|
| 2988 | if (info->linking) {
|
| 2989 | err = dsa_port_bridge_join(dp, info->upper_dev, extack);
|
| 2990 | if (!err)
|
| 2991 | dsa_bridge_mtu_normalization(dp);
|
| 2992 | if (err == -EOPNOTSUPP) {
|
| 2993 | NL_SET_ERR_MSG_WEAK_MOD(extack,
|
| 2994 | "Offloading not supported");
|
| 2995 | err = 0;
|
| 2996 | }
|
| 2997 | err = notifier_from_errno(err);
|
| 2998 | } else {
|
| 2999 | dsa_port_bridge_leave(dp, info->upper_dev);
|
| 3000 | err = NOTIFY_OK;
|
| 3001 | }
|
| 3002 | } else if (netif_is_lag_master(info->upper_dev)) {
|
| 3003 | if (info->linking) {
|
| 3004 | err = dsa_port_lag_join(dp, info->upper_dev,
|
| 3005 | info->upper_info, extack);
|
| 3006 | if (err == -EOPNOTSUPP) {
|
| 3007 | NL_SET_ERR_MSG_WEAK_MOD(extack,
|
| 3008 | "Offloading not supported");
|
| 3009 | err = 0;
|
| 3010 | }
|
| 3011 | err = notifier_from_errno(err);
|
| 3012 | } else {
|
| 3013 | dsa_port_lag_leave(dp, info->upper_dev);
|
| 3014 | err = NOTIFY_OK;
|
| 3015 | }
|
| 3016 | } else if (is_hsr_master(info->upper_dev)) {
|
| 3017 | if (info->linking) {
|
| 3018 | err = dsa_port_hsr_join(dp, info->upper_dev, extack);
|
| 3019 | if (err == -EOPNOTSUPP) {
|
| 3020 | NL_SET_ERR_MSG_WEAK_MOD(extack,
|
| 3021 | "Offloading not supported");
|
| 3022 | err = 0;
|
| 3023 | }
|
| 3024 | err = notifier_from_errno(err);
|
| 3025 | } else {
|
| 3026 | dsa_port_hsr_leave(dp, info->upper_dev);
|
| 3027 | err = NOTIFY_OK;
|
| 3028 | }
|
| 3029 | }
|
| 3030 |
|
| 3031 | return err;
|
| 3032 | }
|
| 3033 |
|
| 3034 | static int dsa_user_prechangeupper(struct net_device *dev,
|
| 3035 | struct netdev_notifier_changeupper_info *info)
|
| 3036 | {
|
| 3037 | struct dsa_port *dp;
|
| 3038 |
|
| 3039 | if (!dsa_user_dev_check(dev))
|
| 3040 | return NOTIFY_DONE;
|
| 3041 |
|
| 3042 | dp = dsa_user_to_port(dev);
|
| 3043 |
|
| 3044 | if (netif_is_bridge_master(info->upper_dev) && !info->linking)
|
| 3045 | dsa_port_pre_bridge_leave(dp, info->upper_dev);
|
| 3046 | else if (netif_is_lag_master(info->upper_dev) && !info->linking)
|
| 3047 | dsa_port_pre_lag_leave(dp, info->upper_dev);
|
| 3048 | |
| 3049 | * meaningfully placed under a bridge yet
|
| 3050 |
|
| 3051 |
|
| 3052 | return NOTIFY_DONE;
|
| 3053 | }
|
| 3054 |
|
| 3055 | static int
|
| 3056 | dsa_user_lag_changeupper(struct net_device *dev,
|
| 3057 | struct netdev_notifier_changeupper_info *info)
|
| 3058 | {
|
| 3059 | struct net_device *lower;
|
| 3060 | struct list_head *iter;
|
| 3061 | int err = NOTIFY_DONE;
|
| 3062 | struct dsa_port *dp;
|
| 3063 |
|
| 3064 | if (!netif_is_lag_master(dev))
|
| 3065 | return err;
|
| 3066 |
|
| 3067 | netdev_for_each_lower_dev(dev, lower, iter) {
|
| 3068 | if (!dsa_user_dev_check(lower))
|
| 3069 | continue;
|
| 3070 |
|
| 3071 | dp = dsa_user_to_port(lower);
|
| 3072 | if (!dp->lag)
|
| 3073 |
|
| 3074 | continue;
|
| 3075 |
|
| 3076 | err = dsa_user_changeupper(lower, info);
|
| 3077 | if (notifier_to_errno(err))
|
| 3078 | break;
|
| 3079 | }
|
| 3080 |
|
| 3081 | return err;
|
| 3082 | }
|
| 3083 |
|
| 3084 | |
| 3085 | * dsa_user_prechangeupper()
|
| 3086 |
|
| 3087 | static int
|
| 3088 | dsa_user_lag_prechangeupper(struct net_device *dev,
|
| 3089 | struct netdev_notifier_changeupper_info *info)
|
| 3090 | {
|
| 3091 | struct net_device *lower;
|
| 3092 | struct list_head *iter;
|
| 3093 | int err = NOTIFY_DONE;
|
| 3094 | struct dsa_port *dp;
|
| 3095 |
|
| 3096 | if (!netif_is_lag_master(dev))
|
| 3097 | return err;
|
| 3098 |
|
| 3099 | netdev_for_each_lower_dev(dev, lower, iter) {
|
| 3100 | if (!dsa_user_dev_check(lower))
|
| 3101 | continue;
|
| 3102 |
|
| 3103 | dp = dsa_user_to_port(lower);
|
| 3104 | if (!dp->lag)
|
| 3105 |
|
| 3106 | continue;
|
| 3107 |
|
| 3108 | err = dsa_user_prechangeupper(lower, info);
|
| 3109 | if (notifier_to_errno(err))
|
| 3110 | break;
|
| 3111 | }
|
| 3112 |
|
| 3113 | return err;
|
| 3114 | }
|
| 3115 |
|
| 3116 | static int
|
| 3117 | dsa_prevent_bridging_8021q_upper(struct net_device *dev,
|
| 3118 | struct netdev_notifier_changeupper_info *info)
|
| 3119 | {
|
| 3120 | struct netlink_ext_ack *ext_ack;
|
| 3121 | struct net_device *user, *br;
|
| 3122 | struct dsa_port *dp;
|
| 3123 |
|
| 3124 | ext_ack = netdev_notifier_info_to_extack(&info->info);
|
| 3125 |
|
| 3126 | if (!is_vlan_dev(dev))
|
| 3127 | return NOTIFY_DONE;
|
| 3128 |
|
| 3129 | user = vlan_dev_real_dev(dev);
|
| 3130 | if (!dsa_user_dev_check(user))
|
| 3131 | return NOTIFY_DONE;
|
| 3132 |
|
| 3133 | dp = dsa_user_to_port(user);
|
| 3134 | br = dsa_port_bridge_dev_get(dp);
|
| 3135 | if (!br)
|
| 3136 | return NOTIFY_DONE;
|
| 3137 |
|
| 3138 |
|
| 3139 | if (br_vlan_enabled(br) &&
|
| 3140 | netif_is_bridge_master(info->upper_dev) && info->linking) {
|
| 3141 | NL_SET_ERR_MSG_MOD(ext_ack,
|
| 3142 | "Cannot make VLAN device join VLAN-aware bridge");
|
| 3143 | return notifier_from_errno(-EINVAL);
|
| 3144 | }
|
| 3145 |
|
| 3146 | return NOTIFY_DONE;
|
| 3147 | }
|
| 3148 |
|
| 3149 | static int
|
| 3150 | dsa_user_check_8021q_upper(struct net_device *dev,
|
| 3151 | struct netdev_notifier_changeupper_info *info)
|
| 3152 | {
|
| 3153 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 3154 | struct net_device *br = dsa_port_bridge_dev_get(dp);
|
| 3155 | struct bridge_vlan_info br_info;
|
| 3156 | struct netlink_ext_ack *extack;
|
| 3157 | int err = NOTIFY_DONE;
|
| 3158 | u16 vid;
|
| 3159 |
|
| 3160 | if (!br || !br_vlan_enabled(br))
|
| 3161 | return NOTIFY_DONE;
|
| 3162 |
|
| 3163 | extack = netdev_notifier_info_to_extack(&info->info);
|
| 3164 | vid = vlan_dev_vlan_id(info->upper_dev);
|
| 3165 |
|
| 3166 | |
| 3167 | * device, respectively the VID is not found, returning
|
| 3168 | * 0 means success, which is a failure for us here.
|
| 3169 |
|
| 3170 | err = br_vlan_get_info(br, vid, &br_info);
|
| 3171 | if (err == 0) {
|
| 3172 | NL_SET_ERR_MSG_MOD(extack,
|
| 3173 | "This VLAN is already configured by the bridge");
|
| 3174 | return notifier_from_errno(-EBUSY);
|
| 3175 | }
|
| 3176 |
|
| 3177 | return NOTIFY_DONE;
|
| 3178 | }
|
| 3179 |
|
| 3180 | static int
|
| 3181 | dsa_user_prechangeupper_sanity_check(struct net_device *dev,
|
| 3182 | struct netdev_notifier_changeupper_info *info)
|
| 3183 | {
|
| 3184 | struct dsa_switch *ds;
|
| 3185 | struct dsa_port *dp;
|
| 3186 | int err;
|
| 3187 |
|
| 3188 | if (!dsa_user_dev_check(dev))
|
| 3189 | return dsa_prevent_bridging_8021q_upper(dev, info);
|
| 3190 |
|
| 3191 | dp = dsa_user_to_port(dev);
|
| 3192 | ds = dp->ds;
|
| 3193 |
|
| 3194 | if (ds->ops->port_prechangeupper) {
|
| 3195 | err = ds->ops->port_prechangeupper(ds, dp->index, info);
|
| 3196 | if (err)
|
| 3197 | return notifier_from_errno(err);
|
| 3198 | }
|
| 3199 |
|
| 3200 | if (is_vlan_dev(info->upper_dev))
|
| 3201 | return dsa_user_check_8021q_upper(dev, info);
|
| 3202 |
|
| 3203 | return NOTIFY_DONE;
|
| 3204 | }
|
| 3205 |
|
| 3206 | |
| 3207 | * eligible DSA conduits. Additionally, all LAG slaves must be DSA conduits of
|
| 3208 | * switches in the same switch tree.
|
| 3209 |
|
| 3210 | static int dsa_lag_conduit_validate(struct net_device *lag_dev,
|
| 3211 | struct netlink_ext_ack *extack)
|
| 3212 | {
|
| 3213 | struct net_device *lower1, *lower2;
|
| 3214 | struct list_head *iter1, *iter2;
|
| 3215 |
|
| 3216 | netdev_for_each_lower_dev(lag_dev, lower1, iter1) {
|
| 3217 | netdev_for_each_lower_dev(lag_dev, lower2, iter2) {
|
| 3218 | if (!netdev_uses_dsa(lower1) ||
|
| 3219 | !netdev_uses_dsa(lower2)) {
|
| 3220 | NL_SET_ERR_MSG_MOD(extack,
|
| 3221 | "All LAG ports must be eligible as DSA conduits");
|
| 3222 | return notifier_from_errno(-EINVAL);
|
| 3223 | }
|
| 3224 |
|
| 3225 | if (lower1 == lower2)
|
| 3226 | continue;
|
| 3227 |
|
| 3228 | if (!dsa_port_tree_same(lower1->dsa_ptr,
|
| 3229 | lower2->dsa_ptr)) {
|
| 3230 | NL_SET_ERR_MSG_MOD(extack,
|
| 3231 | "LAG contains DSA conduits of disjoint switch trees");
|
| 3232 | return notifier_from_errno(-EINVAL);
|
| 3233 | }
|
| 3234 | }
|
| 3235 | }
|
| 3236 |
|
| 3237 | return NOTIFY_DONE;
|
| 3238 | }
|
| 3239 |
|
| 3240 | static int
|
| 3241 | dsa_conduit_prechangeupper_sanity_check(struct net_device *conduit,
|
| 3242 | struct netdev_notifier_changeupper_info *info)
|
| 3243 | {
|
| 3244 | struct netlink_ext_ack *extack = netdev_notifier_info_to_extack(&info->info);
|
| 3245 |
|
| 3246 | if (!netdev_uses_dsa(conduit))
|
| 3247 | return NOTIFY_DONE;
|
| 3248 |
|
| 3249 | if (!info->linking)
|
| 3250 | return NOTIFY_DONE;
|
| 3251 |
|
| 3252 |
|
| 3253 | if (dsa_user_dev_check(info->upper_dev))
|
| 3254 | return NOTIFY_DONE;
|
| 3255 |
|
| 3256 | |
| 3257 | * restrictions in dsa_bridge_prechangelower_sanity_check()
|
| 3258 |
|
| 3259 | if (netif_is_bridge_master(info->upper_dev))
|
| 3260 | return NOTIFY_DONE;
|
| 3261 |
|
| 3262 | |
| 3263 | * dsa_lag_conduit_prechangelower_sanity_check()
|
| 3264 |
|
| 3265 | if (netif_is_lag_master(info->upper_dev))
|
| 3266 | return dsa_lag_conduit_validate(info->upper_dev, extack);
|
| 3267 |
|
| 3268 | NL_SET_ERR_MSG_MOD(extack,
|
| 3269 | "DSA conduit cannot join unknown upper interfaces");
|
| 3270 | return notifier_from_errno(-EBUSY);
|
| 3271 | }
|
| 3272 |
|
| 3273 | static int
|
| 3274 | dsa_lag_conduit_prechangelower_sanity_check(struct net_device *dev,
|
| 3275 | struct netdev_notifier_changeupper_info *info)
|
| 3276 | {
|
| 3277 | struct netlink_ext_ack *extack = netdev_notifier_info_to_extack(&info->info);
|
| 3278 | struct net_device *lag_dev = info->upper_dev;
|
| 3279 | struct net_device *lower;
|
| 3280 | struct list_head *iter;
|
| 3281 |
|
| 3282 | if (!netdev_uses_dsa(lag_dev) || !netif_is_lag_master(lag_dev))
|
| 3283 | return NOTIFY_DONE;
|
| 3284 |
|
| 3285 | if (!info->linking)
|
| 3286 | return NOTIFY_DONE;
|
| 3287 |
|
| 3288 | if (!netdev_uses_dsa(dev)) {
|
| 3289 | NL_SET_ERR_MSG(extack,
|
| 3290 | "Only DSA conduits can join a LAG DSA conduit");
|
| 3291 | return notifier_from_errno(-EINVAL);
|
| 3292 | }
|
| 3293 |
|
| 3294 | netdev_for_each_lower_dev(lag_dev, lower, iter) {
|
| 3295 | if (!dsa_port_tree_same(dev->dsa_ptr, lower->dsa_ptr)) {
|
| 3296 | NL_SET_ERR_MSG(extack,
|
| 3297 | "Interface is DSA conduit for a different switch tree than this LAG");
|
| 3298 | return notifier_from_errno(-EINVAL);
|
| 3299 | }
|
| 3300 |
|
| 3301 | break;
|
| 3302 | }
|
| 3303 |
|
| 3304 | return NOTIFY_DONE;
|
| 3305 | }
|
| 3306 |
|
| 3307 | |
| 3308 | * prevents the DSA fake ethertype handler to be invoked, so we don't get the
|
| 3309 | * chance to strip off and parse the DSA switch tag protocol header (the bridge
|
| 3310 | * layer just returns RX_HANDLER_CONSUMED, stopping RX processing for these
|
| 3311 | * frames).
|
| 3312 | * The only case where that would not be an issue is when bridging can already
|
| 3313 | * be offloaded, such as when the DSA conduit is itself a DSA or plain switchdev
|
| 3314 | * port, and is bridged only with other ports from the same hardware device.
|
| 3315 |
|
| 3316 | static int
|
| 3317 | dsa_bridge_prechangelower_sanity_check(struct net_device *new_lower,
|
| 3318 | struct netdev_notifier_changeupper_info *info)
|
| 3319 | {
|
| 3320 | struct net_device *br = info->upper_dev;
|
| 3321 | struct netlink_ext_ack *extack;
|
| 3322 | struct net_device *lower;
|
| 3323 | struct list_head *iter;
|
| 3324 |
|
| 3325 | if (!netif_is_bridge_master(br))
|
| 3326 | return NOTIFY_DONE;
|
| 3327 |
|
| 3328 | if (!info->linking)
|
| 3329 | return NOTIFY_DONE;
|
| 3330 |
|
| 3331 | extack = netdev_notifier_info_to_extack(&info->info);
|
| 3332 |
|
| 3333 | netdev_for_each_lower_dev(br, lower, iter) {
|
| 3334 | if (!netdev_uses_dsa(new_lower) && !netdev_uses_dsa(lower))
|
| 3335 | continue;
|
| 3336 |
|
| 3337 | if (!netdev_port_same_parent_id(lower, new_lower)) {
|
| 3338 | NL_SET_ERR_MSG(extack,
|
| 3339 | "Cannot do software bridging with a DSA conduit");
|
| 3340 | return notifier_from_errno(-EINVAL);
|
| 3341 | }
|
| 3342 | }
|
| 3343 |
|
| 3344 | return NOTIFY_DONE;
|
| 3345 | }
|
| 3346 |
|
| 3347 | static void dsa_tree_migrate_ports_from_lag_conduit(struct dsa_switch_tree *dst,
|
| 3348 | struct net_device *lag_dev)
|
| 3349 | {
|
| 3350 | struct net_device *new_conduit = dsa_tree_find_first_conduit(dst);
|
| 3351 | struct dsa_port *dp;
|
| 3352 | int err;
|
| 3353 |
|
| 3354 | dsa_tree_for_each_user_port(dp, dst) {
|
| 3355 | if (dsa_port_to_conduit(dp) != lag_dev)
|
| 3356 | continue;
|
| 3357 |
|
| 3358 | err = dsa_user_change_conduit(dp->user, new_conduit, NULL);
|
| 3359 | if (err) {
|
| 3360 | netdev_err(dp->user,
|
| 3361 | "failed to restore conduit to %s: %pe\n",
|
| 3362 | new_conduit->name, ERR_PTR(err));
|
| 3363 | }
|
| 3364 | }
|
| 3365 | }
|
| 3366 |
|
| 3367 | static int dsa_conduit_lag_join(struct net_device *conduit,
|
| 3368 | struct net_device *lag_dev,
|
| 3369 | struct netdev_lag_upper_info *uinfo,
|
| 3370 | struct netlink_ext_ack *extack)
|
| 3371 | {
|
| 3372 | struct dsa_port *cpu_dp = conduit->dsa_ptr;
|
| 3373 | struct dsa_switch_tree *dst = cpu_dp->dst;
|
| 3374 | struct dsa_port *dp;
|
| 3375 | int err;
|
| 3376 |
|
| 3377 | err = dsa_conduit_lag_setup(lag_dev, cpu_dp, uinfo, extack);
|
| 3378 | if (err)
|
| 3379 | return err;
|
| 3380 |
|
| 3381 | dsa_tree_for_each_user_port(dp, dst) {
|
| 3382 | if (dsa_port_to_conduit(dp) != conduit)
|
| 3383 | continue;
|
| 3384 |
|
| 3385 | err = dsa_user_change_conduit(dp->user, lag_dev, extack);
|
| 3386 | if (err)
|
| 3387 | goto restore;
|
| 3388 | }
|
| 3389 |
|
| 3390 | return 0;
|
| 3391 |
|
| 3392 | restore:
|
| 3393 | dsa_tree_for_each_user_port_continue_reverse(dp, dst) {
|
| 3394 | if (dsa_port_to_conduit(dp) != lag_dev)
|
| 3395 | continue;
|
| 3396 |
|
| 3397 | err = dsa_user_change_conduit(dp->user, conduit, NULL);
|
| 3398 | if (err) {
|
| 3399 | netdev_err(dp->user,
|
| 3400 | "failed to restore conduit to %s: %pe\n",
|
| 3401 | conduit->name, ERR_PTR(err));
|
| 3402 | }
|
| 3403 | }
|
| 3404 |
|
| 3405 | dsa_conduit_lag_teardown(lag_dev, conduit->dsa_ptr);
|
| 3406 |
|
| 3407 | return err;
|
| 3408 | }
|
| 3409 |
|
| 3410 | static void dsa_conduit_lag_leave(struct net_device *conduit,
|
| 3411 | struct net_device *lag_dev)
|
| 3412 | {
|
| 3413 | struct dsa_port *dp, *cpu_dp = lag_dev->dsa_ptr;
|
| 3414 | struct dsa_switch_tree *dst = cpu_dp->dst;
|
| 3415 | struct dsa_port *new_cpu_dp = NULL;
|
| 3416 | struct net_device *lower;
|
| 3417 | struct list_head *iter;
|
| 3418 |
|
| 3419 | netdev_for_each_lower_dev(lag_dev, lower, iter) {
|
| 3420 | if (netdev_uses_dsa(lower)) {
|
| 3421 | new_cpu_dp = lower->dsa_ptr;
|
| 3422 | break;
|
| 3423 | }
|
| 3424 | }
|
| 3425 |
|
| 3426 | if (new_cpu_dp) {
|
| 3427 | |
| 3428 | * so that dsa_port_to_conduit() continues to work properly
|
| 3429 |
|
| 3430 | dsa_tree_for_each_user_port(dp, dst)
|
| 3431 | if (dsa_port_to_conduit(dp) == lag_dev)
|
| 3432 | dp->cpu_dp = new_cpu_dp;
|
| 3433 |
|
| 3434 | |
| 3435 | * physical CPU port
|
| 3436 |
|
| 3437 | lag_dev->dsa_ptr = new_cpu_dp;
|
| 3438 | wmb();
|
| 3439 | } else {
|
| 3440 | |
| 3441 | * user ports to the first physical CPU port
|
| 3442 |
|
| 3443 | dsa_tree_migrate_ports_from_lag_conduit(dst, lag_dev);
|
| 3444 | }
|
| 3445 |
|
| 3446 | |
| 3447 | * the CPU port leave the hardware LAG as well
|
| 3448 |
|
| 3449 | dsa_conduit_lag_teardown(lag_dev, conduit->dsa_ptr);
|
| 3450 | }
|
| 3451 |
|
| 3452 | static int dsa_conduit_changeupper(struct net_device *dev,
|
| 3453 | struct netdev_notifier_changeupper_info *info)
|
| 3454 | {
|
| 3455 | struct netlink_ext_ack *extack;
|
| 3456 | int err = NOTIFY_DONE;
|
| 3457 |
|
| 3458 | if (!netdev_uses_dsa(dev))
|
| 3459 | return err;
|
| 3460 |
|
| 3461 | extack = netdev_notifier_info_to_extack(&info->info);
|
| 3462 |
|
| 3463 | if (netif_is_lag_master(info->upper_dev)) {
|
| 3464 | if (info->linking) {
|
| 3465 | err = dsa_conduit_lag_join(dev, info->upper_dev,
|
| 3466 | info->upper_info, extack);
|
| 3467 | err = notifier_from_errno(err);
|
| 3468 | } else {
|
| 3469 | dsa_conduit_lag_leave(dev, info->upper_dev);
|
| 3470 | err = NOTIFY_OK;
|
| 3471 | }
|
| 3472 | }
|
| 3473 |
|
| 3474 | return err;
|
| 3475 | }
|
| 3476 |
|
| 3477 | static int dsa_user_netdevice_event(struct notifier_block *nb,
|
| 3478 | unsigned long event, void *ptr)
|
| 3479 | {
|
| 3480 | struct net_device *dev = netdev_notifier_info_to_dev(ptr);
|
| 3481 |
|
| 3482 | switch (event) {
|
| 3483 | case NETDEV_PRECHANGEUPPER: {
|
| 3484 | struct netdev_notifier_changeupper_info *info = ptr;
|
| 3485 | int err;
|
| 3486 |
|
| 3487 | err = dsa_user_prechangeupper_sanity_check(dev, info);
|
| 3488 | if (notifier_to_errno(err))
|
| 3489 | return err;
|
| 3490 |
|
| 3491 | err = dsa_conduit_prechangeupper_sanity_check(dev, info);
|
| 3492 | if (notifier_to_errno(err))
|
| 3493 | return err;
|
| 3494 |
|
| 3495 | err = dsa_lag_conduit_prechangelower_sanity_check(dev, info);
|
| 3496 | if (notifier_to_errno(err))
|
| 3497 | return err;
|
| 3498 |
|
| 3499 | err = dsa_bridge_prechangelower_sanity_check(dev, info);
|
| 3500 | if (notifier_to_errno(err))
|
| 3501 | return err;
|
| 3502 |
|
| 3503 | err = dsa_user_prechangeupper(dev, ptr);
|
| 3504 | if (notifier_to_errno(err))
|
| 3505 | return err;
|
| 3506 |
|
| 3507 | err = dsa_user_lag_prechangeupper(dev, ptr);
|
| 3508 | if (notifier_to_errno(err))
|
| 3509 | return err;
|
| 3510 |
|
| 3511 | break;
|
| 3512 | }
|
| 3513 | case NETDEV_CHANGEUPPER: {
|
| 3514 | int err;
|
| 3515 |
|
| 3516 | err = dsa_user_changeupper(dev, ptr);
|
| 3517 | if (notifier_to_errno(err))
|
| 3518 | return err;
|
| 3519 |
|
| 3520 | err = dsa_user_lag_changeupper(dev, ptr);
|
| 3521 | if (notifier_to_errno(err))
|
| 3522 | return err;
|
| 3523 |
|
| 3524 | err = dsa_conduit_changeupper(dev, ptr);
|
| 3525 | if (notifier_to_errno(err))
|
| 3526 | return err;
|
| 3527 |
|
| 3528 | break;
|
| 3529 | }
|
| 3530 | case NETDEV_CHANGELOWERSTATE: {
|
| 3531 | struct netdev_notifier_changelowerstate_info *info = ptr;
|
| 3532 | struct dsa_port *dp;
|
| 3533 | int err = 0;
|
| 3534 |
|
| 3535 | if (dsa_user_dev_check(dev)) {
|
| 3536 | dp = dsa_user_to_port(dev);
|
| 3537 |
|
| 3538 | err = dsa_port_lag_change(dp, info->lower_state_info);
|
| 3539 | }
|
| 3540 |
|
| 3541 | |
| 3542 | * a LAG towards their respective switch CPU ports
|
| 3543 |
|
| 3544 | if (netdev_uses_dsa(dev)) {
|
| 3545 | dp = dev->dsa_ptr;
|
| 3546 |
|
| 3547 | err = dsa_port_lag_change(dp, info->lower_state_info);
|
| 3548 | }
|
| 3549 |
|
| 3550 | return notifier_from_errno(err);
|
| 3551 | }
|
| 3552 | case NETDEV_CHANGE:
|
| 3553 | case NETDEV_UP: {
|
| 3554 | |
| 3555 | * DSA driver may require the conduit port (and indirectly
|
| 3556 | * the tagger) to be available for some special operation.
|
| 3557 |
|
| 3558 | if (netdev_uses_dsa(dev)) {
|
| 3559 | struct dsa_port *cpu_dp = dev->dsa_ptr;
|
| 3560 | struct dsa_switch_tree *dst = cpu_dp->ds->dst;
|
| 3561 |
|
| 3562 |
|
| 3563 | dsa_tree_conduit_oper_state_change(dst, dev,
|
| 3564 | netif_oper_up(dev));
|
| 3565 |
|
| 3566 | |
| 3567 | * packet.
|
| 3568 | * NETDEV_UP event is not enough to flag a port as ready.
|
| 3569 | * We also have to wait for linkwatch_do_dev to dev_activate
|
| 3570 | * and emit a NETDEV_CHANGE event.
|
| 3571 | * We check if a conduit port is ready by checking if the dev
|
| 3572 | * have a qdisc assigned and is not noop.
|
| 3573 |
|
| 3574 | dsa_tree_conduit_admin_state_change(dst, dev,
|
| 3575 | !qdisc_tx_is_noop(dev));
|
| 3576 |
|
| 3577 | return NOTIFY_OK;
|
| 3578 | }
|
| 3579 |
|
| 3580 | return NOTIFY_DONE;
|
| 3581 | }
|
| 3582 | case NETDEV_GOING_DOWN: {
|
| 3583 | struct dsa_port *dp, *cpu_dp;
|
| 3584 | struct dsa_switch_tree *dst;
|
| 3585 | LIST_HEAD(close_list);
|
| 3586 |
|
| 3587 | if (!netdev_uses_dsa(dev))
|
| 3588 | return NOTIFY_DONE;
|
| 3589 |
|
| 3590 | cpu_dp = dev->dsa_ptr;
|
| 3591 | dst = cpu_dp->ds->dst;
|
| 3592 |
|
| 3593 | dsa_tree_conduit_admin_state_change(dst, dev, false);
|
| 3594 |
|
| 3595 | list_for_each_entry(dp, &dst->ports, list) {
|
| 3596 | if (!dsa_port_is_user(dp))
|
| 3597 | continue;
|
| 3598 |
|
| 3599 | if (dp->cpu_dp != cpu_dp)
|
| 3600 | continue;
|
| 3601 |
|
| 3602 | if (!(dp->user->flags & IFF_UP))
|
| 3603 | continue;
|
| 3604 |
|
| 3605 | list_add_tail(&dp->user->close_list, &close_list);
|
| 3606 | netdev_lock_ops(dp->user);
|
| 3607 | }
|
| 3608 |
|
| 3609 | netif_close_many(&close_list, false);
|
| 3610 |
|
| 3611 | while (!list_empty(&close_list)) {
|
| 3612 | struct net_device *user_dev;
|
| 3613 |
|
| 3614 | user_dev = list_first_entry(&close_list,
|
| 3615 | struct net_device,
|
| 3616 | close_list);
|
| 3617 | netdev_unlock_ops(user_dev);
|
| 3618 | list_del_init(&user_dev->close_list);
|
| 3619 | }
|
| 3620 |
|
| 3621 | return NOTIFY_OK;
|
| 3622 | }
|
| 3623 | default:
|
| 3624 | break;
|
| 3625 | }
|
| 3626 |
|
| 3627 | return NOTIFY_DONE;
|
| 3628 | }
|
| 3629 |
|
| 3630 | static void
|
| 3631 | dsa_fdb_offload_notify(struct dsa_switchdev_event_work *switchdev_work)
|
| 3632 | {
|
| 3633 | struct switchdev_notifier_fdb_info info = {};
|
| 3634 |
|
| 3635 | info.addr = switchdev_work->addr;
|
| 3636 | info.vid = switchdev_work->vid;
|
| 3637 | info.offloaded = true;
|
| 3638 | call_switchdev_notifiers(SWITCHDEV_FDB_OFFLOADED,
|
| 3639 | switchdev_work->orig_dev, &info.info, NULL);
|
| 3640 | }
|
| 3641 |
|
| 3642 | static void dsa_user_switchdev_event_work(struct work_struct *work)
|
| 3643 | {
|
| 3644 | struct dsa_switchdev_event_work *switchdev_work =
|
| 3645 | container_of(work, struct dsa_switchdev_event_work, work);
|
| 3646 | const unsigned char *addr = switchdev_work->addr;
|
| 3647 | struct net_device *dev = switchdev_work->dev;
|
| 3648 | u16 vid = switchdev_work->vid;
|
| 3649 | struct dsa_switch *ds;
|
| 3650 | struct dsa_port *dp;
|
| 3651 | int err;
|
| 3652 |
|
| 3653 | dp = dsa_user_to_port(dev);
|
| 3654 | ds = dp->ds;
|
| 3655 |
|
| 3656 | switch (switchdev_work->event) {
|
| 3657 | case SWITCHDEV_FDB_ADD_TO_DEVICE:
|
| 3658 | if (switchdev_work->host_addr)
|
| 3659 | err = dsa_port_bridge_host_fdb_add(dp, addr, vid);
|
| 3660 | else if (dp->lag)
|
| 3661 | err = dsa_port_lag_fdb_add(dp, addr, vid);
|
| 3662 | else
|
| 3663 | err = dsa_port_fdb_add(dp, addr, vid);
|
| 3664 | if (err) {
|
| 3665 | dev_err(ds->dev,
|
| 3666 | "port %d failed to add %pM vid %d to fdb: %d\n",
|
| 3667 | dp->index, addr, vid, err);
|
| 3668 | break;
|
| 3669 | }
|
| 3670 | dsa_fdb_offload_notify(switchdev_work);
|
| 3671 | break;
|
| 3672 |
|
| 3673 | case SWITCHDEV_FDB_DEL_TO_DEVICE:
|
| 3674 | if (switchdev_work->host_addr)
|
| 3675 | err = dsa_port_bridge_host_fdb_del(dp, addr, vid);
|
| 3676 | else if (dp->lag)
|
| 3677 | err = dsa_port_lag_fdb_del(dp, addr, vid);
|
| 3678 | else
|
| 3679 | err = dsa_port_fdb_del(dp, addr, vid);
|
| 3680 | if (err) {
|
| 3681 | dev_err(ds->dev,
|
| 3682 | "port %d failed to delete %pM vid %d from fdb: %d\n",
|
| 3683 | dp->index, addr, vid, err);
|
| 3684 | }
|
| 3685 |
|
| 3686 | break;
|
| 3687 | }
|
| 3688 |
|
| 3689 | kfree(switchdev_work);
|
| 3690 | }
|
| 3691 |
|
| 3692 | static bool dsa_foreign_dev_check(const struct net_device *dev,
|
| 3693 | const struct net_device *foreign_dev)
|
| 3694 | {
|
| 3695 | const struct dsa_port *dp = dsa_user_to_port(dev);
|
| 3696 | struct dsa_switch_tree *dst = dp->ds->dst;
|
| 3697 |
|
| 3698 | if (netif_is_bridge_master(foreign_dev))
|
| 3699 | return !dsa_tree_offloads_bridge_dev(dst, foreign_dev);
|
| 3700 |
|
| 3701 | if (netif_is_bridge_port(foreign_dev))
|
| 3702 | return !dsa_tree_offloads_bridge_port(dst, foreign_dev);
|
| 3703 |
|
| 3704 |
|
| 3705 | return true;
|
| 3706 | }
|
| 3707 |
|
| 3708 | static int dsa_user_fdb_event(struct net_device *dev,
|
| 3709 | struct net_device *orig_dev,
|
| 3710 | unsigned long event, const void *ctx,
|
| 3711 | const struct switchdev_notifier_fdb_info *fdb_info)
|
| 3712 | {
|
| 3713 | struct dsa_switchdev_event_work *switchdev_work;
|
| 3714 | struct dsa_port *dp = dsa_user_to_port(dev);
|
| 3715 | bool host_addr = fdb_info->is_local;
|
| 3716 | struct dsa_switch *ds = dp->ds;
|
| 3717 |
|
| 3718 | if (ctx && ctx != dp)
|
| 3719 | return 0;
|
| 3720 |
|
| 3721 | if (!dp->bridge)
|
| 3722 | return 0;
|
| 3723 |
|
| 3724 | if (switchdev_fdb_is_dynamically_learned(fdb_info)) {
|
| 3725 | if (dsa_port_offloads_bridge_port(dp, orig_dev))
|
| 3726 | return 0;
|
| 3727 |
|
| 3728 | |
| 3729 | * bridge ports should be installed as host addresses only if
|
| 3730 | * the driver requests assisted learning.
|
| 3731 |
|
| 3732 | if (!ds->assisted_learning_on_cpu_port)
|
| 3733 | return 0;
|
| 3734 | }
|
| 3735 |
|
| 3736 | |
| 3737 | * addresses.
|
| 3738 |
|
| 3739 | if (dsa_foreign_dev_check(dev, orig_dev))
|
| 3740 | host_addr = true;
|
| 3741 |
|
| 3742 | |
| 3743 | * Host addresses on LAG ports still require regular FDB ops,
|
| 3744 | * since the CPU port isn't in a LAG.
|
| 3745 |
|
| 3746 | if (dp->lag && !host_addr) {
|
| 3747 | if (!ds->ops->lag_fdb_add || !ds->ops->lag_fdb_del)
|
| 3748 | return -EOPNOTSUPP;
|
| 3749 | } else {
|
| 3750 | if (!ds->ops->port_fdb_add || !ds->ops->port_fdb_del)
|
| 3751 | return -EOPNOTSUPP;
|
| 3752 | }
|
| 3753 |
|
| 3754 | switchdev_work = kzalloc_obj(*switchdev_work, GFP_ATOMIC);
|
| 3755 | if (!switchdev_work)
|
| 3756 | return -ENOMEM;
|
| 3757 |
|
| 3758 | netdev_dbg(dev, "%s FDB entry towards %s, addr %pM vid %d%s\n",
|
| 3759 | event == SWITCHDEV_FDB_ADD_TO_DEVICE ? "Adding" : "Deleting",
|
| 3760 | orig_dev->name, fdb_info->addr, fdb_info->vid,
|
| 3761 | host_addr ? " as host address" : "");
|
| 3762 |
|
| 3763 | INIT_WORK(&switchdev_work->work, dsa_user_switchdev_event_work);
|
| 3764 | switchdev_work->event = event;
|
| 3765 | switchdev_work->dev = dev;
|
| 3766 | switchdev_work->orig_dev = orig_dev;
|
| 3767 |
|
| 3768 | ether_addr_copy(switchdev_work->addr, fdb_info->addr);
|
| 3769 | switchdev_work->vid = fdb_info->vid;
|
| 3770 | switchdev_work->host_addr = host_addr;
|
| 3771 |
|
| 3772 | dsa_schedule_work(&switchdev_work->work);
|
| 3773 |
|
| 3774 | return 0;
|
| 3775 | }
|
| 3776 |
|
| 3777 |
|
| 3778 | static int dsa_user_switchdev_event(struct notifier_block *unused,
|
| 3779 | unsigned long event, void *ptr)
|
| 3780 | {
|
| 3781 | struct net_device *dev = switchdev_notifier_info_to_dev(ptr);
|
| 3782 | int err;
|
| 3783 |
|
| 3784 | switch (event) {
|
| 3785 | case SWITCHDEV_PORT_ATTR_SET:
|
| 3786 | err = switchdev_handle_port_attr_set(dev, ptr,
|
| 3787 | dsa_user_dev_check,
|
| 3788 | dsa_user_port_attr_set);
|
| 3789 | return notifier_from_errno(err);
|
| 3790 | case SWITCHDEV_FDB_ADD_TO_DEVICE:
|
| 3791 | case SWITCHDEV_FDB_DEL_TO_DEVICE:
|
| 3792 | err = switchdev_handle_fdb_event_to_device(dev, event, ptr,
|
| 3793 | dsa_user_dev_check,
|
| 3794 | dsa_foreign_dev_check,
|
| 3795 | dsa_user_fdb_event);
|
| 3796 | return notifier_from_errno(err);
|
| 3797 | default:
|
| 3798 | return NOTIFY_DONE;
|
| 3799 | }
|
| 3800 |
|
| 3801 | return NOTIFY_OK;
|
| 3802 | }
|
| 3803 |
|
| 3804 | static int dsa_user_switchdev_blocking_event(struct notifier_block *unused,
|
| 3805 | unsigned long event, void *ptr)
|
| 3806 | {
|
| 3807 | struct net_device *dev = switchdev_notifier_info_to_dev(ptr);
|
| 3808 | int err;
|
| 3809 |
|
| 3810 | switch (event) {
|
| 3811 | case SWITCHDEV_PORT_OBJ_ADD:
|
| 3812 | err = switchdev_handle_port_obj_add_foreign(dev, ptr,
|
| 3813 | dsa_user_dev_check,
|
| 3814 | dsa_foreign_dev_check,
|
| 3815 | dsa_user_port_obj_add);
|
| 3816 | return notifier_from_errno(err);
|
| 3817 | case SWITCHDEV_PORT_OBJ_DEL:
|
| 3818 | err = switchdev_handle_port_obj_del_foreign(dev, ptr,
|
| 3819 | dsa_user_dev_check,
|
| 3820 | dsa_foreign_dev_check,
|
| 3821 | dsa_user_port_obj_del);
|
| 3822 | return notifier_from_errno(err);
|
| 3823 | case SWITCHDEV_PORT_ATTR_SET:
|
| 3824 | err = switchdev_handle_port_attr_set(dev, ptr,
|
| 3825 | dsa_user_dev_check,
|
| 3826 | dsa_user_port_attr_set);
|
| 3827 | return notifier_from_errno(err);
|
| 3828 | }
|
| 3829 |
|
| 3830 | return NOTIFY_DONE;
|
| 3831 | }
|
| 3832 |
|
| 3833 | static struct notifier_block dsa_user_nb __read_mostly = {
|
| 3834 | .notifier_call = dsa_user_netdevice_event,
|
| 3835 | };
|
| 3836 |
|
| 3837 | struct notifier_block dsa_user_switchdev_notifier = {
|
| 3838 | .notifier_call = dsa_user_switchdev_event,
|
| 3839 | };
|
| 3840 |
|
| 3841 | struct notifier_block dsa_user_switchdev_blocking_notifier = {
|
| 3842 | .notifier_call = dsa_user_switchdev_blocking_event,
|
| 3843 | };
|
| 3844 |
|
| 3845 | int dsa_user_register_notifier(void)
|
| 3846 | {
|
| 3847 | struct notifier_block *nb;
|
| 3848 | int err;
|
| 3849 |
|
| 3850 | err = register_netdevice_notifier(&dsa_user_nb);
|
| 3851 | if (err)
|
| 3852 | return err;
|
| 3853 |
|
| 3854 | err = register_switchdev_notifier(&dsa_user_switchdev_notifier);
|
| 3855 | if (err)
|
| 3856 | goto err_switchdev_nb;
|
| 3857 |
|
| 3858 | nb = &dsa_user_switchdev_blocking_notifier;
|
| 3859 | err = register_switchdev_blocking_notifier(nb);
|
| 3860 | if (err)
|
| 3861 | goto err_switchdev_blocking_nb;
|
| 3862 |
|
| 3863 | return 0;
|
| 3864 |
|
| 3865 | err_switchdev_blocking_nb:
|
| 3866 | unregister_switchdev_notifier(&dsa_user_switchdev_notifier);
|
| 3867 | err_switchdev_nb:
|
| 3868 | unregister_netdevice_notifier(&dsa_user_nb);
|
| 3869 | return err;
|
| 3870 | }
|
| 3871 |
|
| 3872 | void dsa_user_unregister_notifier(void)
|
| 3873 | {
|
| 3874 | struct notifier_block *nb;
|
| 3875 | int err;
|
| 3876 |
|
| 3877 | nb = &dsa_user_switchdev_blocking_notifier;
|
| 3878 | err = unregister_switchdev_blocking_notifier(nb);
|
| 3879 | if (err)
|
| 3880 | pr_err("DSA: failed to unregister switchdev blocking notifier (%d)\n", err);
|
| 3881 |
|
| 3882 | err = unregister_switchdev_notifier(&dsa_user_switchdev_notifier);
|
| 3883 | if (err)
|
| 3884 | pr_err("DSA: failed to unregister switchdev notifier (%d)\n", err);
|
| 3885 |
|
| 3886 | err = unregister_netdevice_notifier(&dsa_user_nb);
|
| 3887 | if (err)
|
| 3888 | pr_err("DSA: failed to unregister user notifier (%d)\n", err);
|
| 3889 | }
|