1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Handling of a single switch chip, part of a switch fabric 4 * 5 * Copyright (c) 2017 Savoir-faire Linux Inc. 6 * Vivien Didelot <vivien.didelot@savoirfairelinux.com> 7 */ 8 9 #include <linux/if_bridge.h> 10 #include <linux/netdevice.h> 11 #include <linux/notifier.h> 12 #include <linux/if_vlan.h> 13 #include <net/switchdev.h> 14 15 #include "dsa_priv.h" 16 17 static unsigned int dsa_switch_fastest_ageing_time(struct dsa_switch *ds, 18 unsigned int ageing_time) 19 { 20 struct dsa_port *dp; 21 22 dsa_switch_for_each_port(dp, ds) 23 if (dp->ageing_time && dp->ageing_time < ageing_time) 24 ageing_time = dp->ageing_time; 25 26 return ageing_time; 27 } 28 29 static int dsa_switch_ageing_time(struct dsa_switch *ds, 30 struct dsa_notifier_ageing_time_info *info) 31 { 32 unsigned int ageing_time = info->ageing_time; 33 34 if (ds->ageing_time_min && ageing_time < ds->ageing_time_min) 35 return -ERANGE; 36 37 if (ds->ageing_time_max && ageing_time > ds->ageing_time_max) 38 return -ERANGE; 39 40 /* Program the fastest ageing time in case of multiple bridges */ 41 ageing_time = dsa_switch_fastest_ageing_time(ds, ageing_time); 42 43 if (ds->ops->set_ageing_time) 44 return ds->ops->set_ageing_time(ds, ageing_time); 45 46 return 0; 47 } 48 49 static bool dsa_port_mtu_match(struct dsa_port *dp, 50 struct dsa_notifier_mtu_info *info) 51 { 52 if (dp->ds->index == info->sw_index && dp->index == info->port) 53 return true; 54 55 /* Do not propagate to other switches in the tree if the notifier was 56 * targeted for a single switch. 57 */ 58 if (info->targeted_match) 59 return false; 60 61 if (dsa_port_is_dsa(dp) || dsa_port_is_cpu(dp)) 62 return true; 63 64 return false; 65 } 66 67 static int dsa_switch_mtu(struct dsa_switch *ds, 68 struct dsa_notifier_mtu_info *info) 69 { 70 struct dsa_port *dp; 71 int ret; 72 73 if (!ds->ops->port_change_mtu) 74 return -EOPNOTSUPP; 75 76 dsa_switch_for_each_port(dp, ds) { 77 if (dsa_port_mtu_match(dp, info)) { 78 ret = ds->ops->port_change_mtu(ds, dp->index, 79 info->mtu); 80 if (ret) 81 return ret; 82 } 83 } 84 85 return 0; 86 } 87 88 static int dsa_switch_bridge_join(struct dsa_switch *ds, 89 struct dsa_notifier_bridge_info *info) 90 { 91 struct dsa_switch_tree *dst = ds->dst; 92 int err; 93 94 if (dst->index == info->tree_index && ds->index == info->sw_index) { 95 if (!ds->ops->port_bridge_join) 96 return -EOPNOTSUPP; 97 98 err = ds->ops->port_bridge_join(ds, info->port, info->bridge, 99 &info->tx_fwd_offload); 100 if (err) 101 return err; 102 } 103 104 if ((dst->index != info->tree_index || ds->index != info->sw_index) && 105 ds->ops->crosschip_bridge_join) { 106 err = ds->ops->crosschip_bridge_join(ds, info->tree_index, 107 info->sw_index, 108 info->port, info->bridge); 109 if (err) 110 return err; 111 } 112 113 return dsa_tag_8021q_bridge_join(ds, info); 114 } 115 116 static int dsa_switch_sync_vlan_filtering(struct dsa_switch *ds, 117 struct dsa_notifier_bridge_info *info) 118 { 119 struct netlink_ext_ack extack = {0}; 120 bool change_vlan_filtering = false; 121 bool vlan_filtering; 122 struct dsa_port *dp; 123 int err; 124 125 if (ds->needs_standalone_vlan_filtering && 126 !br_vlan_enabled(info->bridge.dev)) { 127 change_vlan_filtering = true; 128 vlan_filtering = true; 129 } else if (!ds->needs_standalone_vlan_filtering && 130 br_vlan_enabled(info->bridge.dev)) { 131 change_vlan_filtering = true; 132 vlan_filtering = false; 133 } 134 135 /* If the bridge was vlan_filtering, the bridge core doesn't trigger an 136 * event for changing vlan_filtering setting upon slave ports leaving 137 * it. That is a good thing, because that lets us handle it and also 138 * handle the case where the switch's vlan_filtering setting is global 139 * (not per port). When that happens, the correct moment to trigger the 140 * vlan_filtering callback is only when the last port leaves the last 141 * VLAN-aware bridge. 142 */ 143 if (change_vlan_filtering && ds->vlan_filtering_is_global) { 144 dsa_switch_for_each_port(dp, ds) { 145 struct net_device *br = dsa_port_bridge_dev_get(dp); 146 147 if (br && br_vlan_enabled(br)) { 148 change_vlan_filtering = false; 149 break; 150 } 151 } 152 } 153 154 if (change_vlan_filtering) { 155 err = dsa_port_vlan_filtering(dsa_to_port(ds, info->port), 156 vlan_filtering, &extack); 157 if (extack._msg) 158 dev_err(ds->dev, "port %d: %s\n", info->port, 159 extack._msg); 160 if (err && err != -EOPNOTSUPP) 161 return err; 162 } 163 164 return 0; 165 } 166 167 static int dsa_switch_bridge_leave(struct dsa_switch *ds, 168 struct dsa_notifier_bridge_info *info) 169 { 170 struct dsa_switch_tree *dst = ds->dst; 171 int err; 172 173 if (dst->index == info->tree_index && ds->index == info->sw_index && 174 ds->ops->port_bridge_leave) 175 ds->ops->port_bridge_leave(ds, info->port, info->bridge); 176 177 if ((dst->index != info->tree_index || ds->index != info->sw_index) && 178 ds->ops->crosschip_bridge_leave) 179 ds->ops->crosschip_bridge_leave(ds, info->tree_index, 180 info->sw_index, info->port, 181 info->bridge); 182 183 if (ds->dst->index == info->tree_index && ds->index == info->sw_index) { 184 err = dsa_switch_sync_vlan_filtering(ds, info); 185 if (err) 186 return err; 187 } 188 189 return dsa_tag_8021q_bridge_leave(ds, info); 190 } 191 192 /* Matches for all upstream-facing ports (the CPU port and all upstream-facing 193 * DSA links) that sit between the targeted port on which the notifier was 194 * emitted and its dedicated CPU port. 195 */ 196 static bool dsa_port_host_address_match(struct dsa_port *dp, 197 int info_sw_index, int info_port) 198 { 199 struct dsa_port *targeted_dp, *cpu_dp; 200 struct dsa_switch *targeted_ds; 201 202 targeted_ds = dsa_switch_find(dp->ds->dst->index, info_sw_index); 203 targeted_dp = dsa_to_port(targeted_ds, info_port); 204 cpu_dp = targeted_dp->cpu_dp; 205 206 if (dsa_switch_is_upstream_of(dp->ds, targeted_ds)) 207 return dp->index == dsa_towards_port(dp->ds, cpu_dp->ds->index, 208 cpu_dp->index); 209 210 return false; 211 } 212 213 static struct dsa_mac_addr *dsa_mac_addr_find(struct list_head *addr_list, 214 const unsigned char *addr, 215 u16 vid) 216 { 217 struct dsa_mac_addr *a; 218 219 list_for_each_entry(a, addr_list, list) 220 if (ether_addr_equal(a->addr, addr) && a->vid == vid) 221 return a; 222 223 return NULL; 224 } 225 226 static int dsa_port_do_mdb_add(struct dsa_port *dp, 227 const struct switchdev_obj_port_mdb *mdb) 228 { 229 struct dsa_switch *ds = dp->ds; 230 struct dsa_mac_addr *a; 231 int port = dp->index; 232 int err = 0; 233 234 /* No need to bother with refcounting for user ports */ 235 if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp))) 236 return ds->ops->port_mdb_add(ds, port, mdb); 237 238 mutex_lock(&dp->addr_lists_lock); 239 240 a = dsa_mac_addr_find(&dp->mdbs, mdb->addr, mdb->vid); 241 if (a) { 242 refcount_inc(&a->refcount); 243 goto out; 244 } 245 246 a = kzalloc(sizeof(*a), GFP_KERNEL); 247 if (!a) { 248 err = -ENOMEM; 249 goto out; 250 } 251 252 err = ds->ops->port_mdb_add(ds, port, mdb); 253 if (err) { 254 kfree(a); 255 goto out; 256 } 257 258 ether_addr_copy(a->addr, mdb->addr); 259 a->vid = mdb->vid; 260 refcount_set(&a->refcount, 1); 261 list_add_tail(&a->list, &dp->mdbs); 262 263 out: 264 mutex_unlock(&dp->addr_lists_lock); 265 266 return err; 267 } 268 269 static int dsa_port_do_mdb_del(struct dsa_port *dp, 270 const struct switchdev_obj_port_mdb *mdb) 271 { 272 struct dsa_switch *ds = dp->ds; 273 struct dsa_mac_addr *a; 274 int port = dp->index; 275 int err = 0; 276 277 /* No need to bother with refcounting for user ports */ 278 if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp))) 279 return ds->ops->port_mdb_del(ds, port, mdb); 280 281 mutex_lock(&dp->addr_lists_lock); 282 283 a = dsa_mac_addr_find(&dp->mdbs, mdb->addr, mdb->vid); 284 if (!a) { 285 err = -ENOENT; 286 goto out; 287 } 288 289 if (!refcount_dec_and_test(&a->refcount)) 290 goto out; 291 292 err = ds->ops->port_mdb_del(ds, port, mdb); 293 if (err) { 294 refcount_set(&a->refcount, 1); 295 goto out; 296 } 297 298 list_del(&a->list); 299 kfree(a); 300 301 out: 302 mutex_unlock(&dp->addr_lists_lock); 303 304 return err; 305 } 306 307 static int dsa_port_do_fdb_add(struct dsa_port *dp, const unsigned char *addr, 308 u16 vid) 309 { 310 struct dsa_switch *ds = dp->ds; 311 struct dsa_mac_addr *a; 312 int port = dp->index; 313 int err = 0; 314 315 /* No need to bother with refcounting for user ports */ 316 if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp))) 317 return ds->ops->port_fdb_add(ds, port, addr, vid); 318 319 mutex_lock(&dp->addr_lists_lock); 320 321 a = dsa_mac_addr_find(&dp->fdbs, addr, vid); 322 if (a) { 323 refcount_inc(&a->refcount); 324 goto out; 325 } 326 327 a = kzalloc(sizeof(*a), GFP_KERNEL); 328 if (!a) { 329 err = -ENOMEM; 330 goto out; 331 } 332 333 err = ds->ops->port_fdb_add(ds, port, addr, vid); 334 if (err) { 335 kfree(a); 336 goto out; 337 } 338 339 ether_addr_copy(a->addr, addr); 340 a->vid = vid; 341 refcount_set(&a->refcount, 1); 342 list_add_tail(&a->list, &dp->fdbs); 343 344 out: 345 mutex_unlock(&dp->addr_lists_lock); 346 347 return err; 348 } 349 350 static int dsa_port_do_fdb_del(struct dsa_port *dp, const unsigned char *addr, 351 u16 vid) 352 { 353 struct dsa_switch *ds = dp->ds; 354 struct dsa_mac_addr *a; 355 int port = dp->index; 356 int err = 0; 357 358 /* No need to bother with refcounting for user ports */ 359 if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp))) 360 return ds->ops->port_fdb_del(ds, port, addr, vid); 361 362 mutex_lock(&dp->addr_lists_lock); 363 364 a = dsa_mac_addr_find(&dp->fdbs, addr, vid); 365 if (!a) { 366 err = -ENOENT; 367 goto out; 368 } 369 370 if (!refcount_dec_and_test(&a->refcount)) 371 goto out; 372 373 err = ds->ops->port_fdb_del(ds, port, addr, vid); 374 if (err) { 375 refcount_set(&a->refcount, 1); 376 goto out; 377 } 378 379 list_del(&a->list); 380 kfree(a); 381 382 out: 383 mutex_unlock(&dp->addr_lists_lock); 384 385 return err; 386 } 387 388 static int dsa_switch_host_fdb_add(struct dsa_switch *ds, 389 struct dsa_notifier_fdb_info *info) 390 { 391 struct dsa_port *dp; 392 int err = 0; 393 394 if (!ds->ops->port_fdb_add) 395 return -EOPNOTSUPP; 396 397 dsa_switch_for_each_port(dp, ds) { 398 if (dsa_port_host_address_match(dp, info->sw_index, 399 info->port)) { 400 err = dsa_port_do_fdb_add(dp, info->addr, info->vid); 401 if (err) 402 break; 403 } 404 } 405 406 return err; 407 } 408 409 static int dsa_switch_host_fdb_del(struct dsa_switch *ds, 410 struct dsa_notifier_fdb_info *info) 411 { 412 struct dsa_port *dp; 413 int err = 0; 414 415 if (!ds->ops->port_fdb_del) 416 return -EOPNOTSUPP; 417 418 dsa_switch_for_each_port(dp, ds) { 419 if (dsa_port_host_address_match(dp, info->sw_index, 420 info->port)) { 421 err = dsa_port_do_fdb_del(dp, info->addr, info->vid); 422 if (err) 423 break; 424 } 425 } 426 427 return err; 428 } 429 430 static int dsa_switch_fdb_add(struct dsa_switch *ds, 431 struct dsa_notifier_fdb_info *info) 432 { 433 int port = dsa_towards_port(ds, info->sw_index, info->port); 434 struct dsa_port *dp = dsa_to_port(ds, port); 435 436 if (!ds->ops->port_fdb_add) 437 return -EOPNOTSUPP; 438 439 return dsa_port_do_fdb_add(dp, info->addr, info->vid); 440 } 441 442 static int dsa_switch_fdb_del(struct dsa_switch *ds, 443 struct dsa_notifier_fdb_info *info) 444 { 445 int port = dsa_towards_port(ds, info->sw_index, info->port); 446 struct dsa_port *dp = dsa_to_port(ds, port); 447 448 if (!ds->ops->port_fdb_del) 449 return -EOPNOTSUPP; 450 451 return dsa_port_do_fdb_del(dp, info->addr, info->vid); 452 } 453 454 static int dsa_switch_lag_change(struct dsa_switch *ds, 455 struct dsa_notifier_lag_info *info) 456 { 457 if (ds->index == info->sw_index && ds->ops->port_lag_change) 458 return ds->ops->port_lag_change(ds, info->port); 459 460 if (ds->index != info->sw_index && ds->ops->crosschip_lag_change) 461 return ds->ops->crosschip_lag_change(ds, info->sw_index, 462 info->port); 463 464 return 0; 465 } 466 467 static int dsa_switch_lag_join(struct dsa_switch *ds, 468 struct dsa_notifier_lag_info *info) 469 { 470 if (ds->index == info->sw_index && ds->ops->port_lag_join) 471 return ds->ops->port_lag_join(ds, info->port, info->lag, 472 info->info); 473 474 if (ds->index != info->sw_index && ds->ops->crosschip_lag_join) 475 return ds->ops->crosschip_lag_join(ds, info->sw_index, 476 info->port, info->lag, 477 info->info); 478 479 return -EOPNOTSUPP; 480 } 481 482 static int dsa_switch_lag_leave(struct dsa_switch *ds, 483 struct dsa_notifier_lag_info *info) 484 { 485 if (ds->index == info->sw_index && ds->ops->port_lag_leave) 486 return ds->ops->port_lag_leave(ds, info->port, info->lag); 487 488 if (ds->index != info->sw_index && ds->ops->crosschip_lag_leave) 489 return ds->ops->crosschip_lag_leave(ds, info->sw_index, 490 info->port, info->lag); 491 492 return -EOPNOTSUPP; 493 } 494 495 static int dsa_switch_mdb_add(struct dsa_switch *ds, 496 struct dsa_notifier_mdb_info *info) 497 { 498 int port = dsa_towards_port(ds, info->sw_index, info->port); 499 struct dsa_port *dp = dsa_to_port(ds, port); 500 501 if (!ds->ops->port_mdb_add) 502 return -EOPNOTSUPP; 503 504 return dsa_port_do_mdb_add(dp, info->mdb); 505 } 506 507 static int dsa_switch_mdb_del(struct dsa_switch *ds, 508 struct dsa_notifier_mdb_info *info) 509 { 510 int port = dsa_towards_port(ds, info->sw_index, info->port); 511 struct dsa_port *dp = dsa_to_port(ds, port); 512 513 if (!ds->ops->port_mdb_del) 514 return -EOPNOTSUPP; 515 516 return dsa_port_do_mdb_del(dp, info->mdb); 517 } 518 519 static int dsa_switch_host_mdb_add(struct dsa_switch *ds, 520 struct dsa_notifier_mdb_info *info) 521 { 522 struct dsa_port *dp; 523 int err = 0; 524 525 if (!ds->ops->port_mdb_add) 526 return -EOPNOTSUPP; 527 528 dsa_switch_for_each_port(dp, ds) { 529 if (dsa_port_host_address_match(dp, info->sw_index, 530 info->port)) { 531 err = dsa_port_do_mdb_add(dp, info->mdb); 532 if (err) 533 break; 534 } 535 } 536 537 return err; 538 } 539 540 static int dsa_switch_host_mdb_del(struct dsa_switch *ds, 541 struct dsa_notifier_mdb_info *info) 542 { 543 struct dsa_port *dp; 544 int err = 0; 545 546 if (!ds->ops->port_mdb_del) 547 return -EOPNOTSUPP; 548 549 dsa_switch_for_each_port(dp, ds) { 550 if (dsa_port_host_address_match(dp, info->sw_index, 551 info->port)) { 552 err = dsa_port_do_mdb_del(dp, info->mdb); 553 if (err) 554 break; 555 } 556 } 557 558 return err; 559 } 560 561 static bool dsa_port_vlan_match(struct dsa_port *dp, 562 struct dsa_notifier_vlan_info *info) 563 { 564 if (dp->ds->index == info->sw_index && dp->index == info->port) 565 return true; 566 567 if (dsa_port_is_dsa(dp)) 568 return true; 569 570 return false; 571 } 572 573 static int dsa_switch_vlan_add(struct dsa_switch *ds, 574 struct dsa_notifier_vlan_info *info) 575 { 576 struct dsa_port *dp; 577 int err; 578 579 if (!ds->ops->port_vlan_add) 580 return -EOPNOTSUPP; 581 582 dsa_switch_for_each_port(dp, ds) { 583 if (dsa_port_vlan_match(dp, info)) { 584 err = ds->ops->port_vlan_add(ds, dp->index, info->vlan, 585 info->extack); 586 if (err) 587 return err; 588 } 589 } 590 591 return 0; 592 } 593 594 static int dsa_switch_vlan_del(struct dsa_switch *ds, 595 struct dsa_notifier_vlan_info *info) 596 { 597 if (!ds->ops->port_vlan_del) 598 return -EOPNOTSUPP; 599 600 if (ds->index == info->sw_index) 601 return ds->ops->port_vlan_del(ds, info->port, info->vlan); 602 603 /* Do not deprogram the DSA links as they may be used as conduit 604 * for other VLAN members in the fabric. 605 */ 606 return 0; 607 } 608 609 static int dsa_switch_change_tag_proto(struct dsa_switch *ds, 610 struct dsa_notifier_tag_proto_info *info) 611 { 612 const struct dsa_device_ops *tag_ops = info->tag_ops; 613 struct dsa_port *dp, *cpu_dp; 614 int err; 615 616 if (!ds->ops->change_tag_protocol) 617 return -EOPNOTSUPP; 618 619 ASSERT_RTNL(); 620 621 dsa_switch_for_each_cpu_port(cpu_dp, ds) { 622 err = ds->ops->change_tag_protocol(ds, cpu_dp->index, 623 tag_ops->proto); 624 if (err) 625 return err; 626 627 dsa_port_set_tag_protocol(cpu_dp, tag_ops); 628 } 629 630 /* Now that changing the tag protocol can no longer fail, let's update 631 * the remaining bits which are "duplicated for faster access", and the 632 * bits that depend on the tagger, such as the MTU. 633 */ 634 dsa_switch_for_each_user_port(dp, ds) { 635 struct net_device *slave = dp->slave; 636 637 dsa_slave_setup_tagger(slave); 638 639 /* rtnl_mutex is held in dsa_tree_change_tag_proto */ 640 dsa_slave_change_mtu(slave, slave->mtu); 641 } 642 643 return 0; 644 } 645 646 /* We use the same cross-chip notifiers to inform both the tagger side, as well 647 * as the switch side, of connection and disconnection events. 648 * Since ds->tagger_data is owned by the tagger, it isn't a hard error if the 649 * switch side doesn't support connecting to this tagger, and therefore, the 650 * fact that we don't disconnect the tagger side doesn't constitute a memory 651 * leak: the tagger will still operate with persistent per-switch memory, just 652 * with the switch side unconnected to it. What does constitute a hard error is 653 * when the switch side supports connecting but fails. 654 */ 655 static int 656 dsa_switch_connect_tag_proto(struct dsa_switch *ds, 657 struct dsa_notifier_tag_proto_info *info) 658 { 659 const struct dsa_device_ops *tag_ops = info->tag_ops; 660 int err; 661 662 /* Notify the new tagger about the connection to this switch */ 663 if (tag_ops->connect) { 664 err = tag_ops->connect(ds); 665 if (err) 666 return err; 667 } 668 669 if (!ds->ops->connect_tag_protocol) 670 return -EOPNOTSUPP; 671 672 /* Notify the switch about the connection to the new tagger */ 673 err = ds->ops->connect_tag_protocol(ds, tag_ops->proto); 674 if (err) { 675 /* Revert the new tagger's connection to this tree */ 676 if (tag_ops->disconnect) 677 tag_ops->disconnect(ds); 678 return err; 679 } 680 681 return 0; 682 } 683 684 static int 685 dsa_switch_disconnect_tag_proto(struct dsa_switch *ds, 686 struct dsa_notifier_tag_proto_info *info) 687 { 688 const struct dsa_device_ops *tag_ops = info->tag_ops; 689 690 /* Notify the tagger about the disconnection from this switch */ 691 if (tag_ops->disconnect && ds->tagger_data) 692 tag_ops->disconnect(ds); 693 694 /* No need to notify the switch, since it shouldn't have any 695 * resources to tear down 696 */ 697 return 0; 698 } 699 700 static int 701 dsa_switch_master_state_change(struct dsa_switch *ds, 702 struct dsa_notifier_master_state_info *info) 703 { 704 if (!ds->ops->master_state_change) 705 return 0; 706 707 ds->ops->master_state_change(ds, info->master, info->operational); 708 709 return 0; 710 } 711 712 static int dsa_switch_event(struct notifier_block *nb, 713 unsigned long event, void *info) 714 { 715 struct dsa_switch *ds = container_of(nb, struct dsa_switch, nb); 716 int err; 717 718 switch (event) { 719 case DSA_NOTIFIER_AGEING_TIME: 720 err = dsa_switch_ageing_time(ds, info); 721 break; 722 case DSA_NOTIFIER_BRIDGE_JOIN: 723 err = dsa_switch_bridge_join(ds, info); 724 break; 725 case DSA_NOTIFIER_BRIDGE_LEAVE: 726 err = dsa_switch_bridge_leave(ds, info); 727 break; 728 case DSA_NOTIFIER_FDB_ADD: 729 err = dsa_switch_fdb_add(ds, info); 730 break; 731 case DSA_NOTIFIER_FDB_DEL: 732 err = dsa_switch_fdb_del(ds, info); 733 break; 734 case DSA_NOTIFIER_HOST_FDB_ADD: 735 err = dsa_switch_host_fdb_add(ds, info); 736 break; 737 case DSA_NOTIFIER_HOST_FDB_DEL: 738 err = dsa_switch_host_fdb_del(ds, info); 739 break; 740 case DSA_NOTIFIER_LAG_CHANGE: 741 err = dsa_switch_lag_change(ds, info); 742 break; 743 case DSA_NOTIFIER_LAG_JOIN: 744 err = dsa_switch_lag_join(ds, info); 745 break; 746 case DSA_NOTIFIER_LAG_LEAVE: 747 err = dsa_switch_lag_leave(ds, info); 748 break; 749 case DSA_NOTIFIER_MDB_ADD: 750 err = dsa_switch_mdb_add(ds, info); 751 break; 752 case DSA_NOTIFIER_MDB_DEL: 753 err = dsa_switch_mdb_del(ds, info); 754 break; 755 case DSA_NOTIFIER_HOST_MDB_ADD: 756 err = dsa_switch_host_mdb_add(ds, info); 757 break; 758 case DSA_NOTIFIER_HOST_MDB_DEL: 759 err = dsa_switch_host_mdb_del(ds, info); 760 break; 761 case DSA_NOTIFIER_VLAN_ADD: 762 err = dsa_switch_vlan_add(ds, info); 763 break; 764 case DSA_NOTIFIER_VLAN_DEL: 765 err = dsa_switch_vlan_del(ds, info); 766 break; 767 case DSA_NOTIFIER_MTU: 768 err = dsa_switch_mtu(ds, info); 769 break; 770 case DSA_NOTIFIER_TAG_PROTO: 771 err = dsa_switch_change_tag_proto(ds, info); 772 break; 773 case DSA_NOTIFIER_TAG_PROTO_CONNECT: 774 err = dsa_switch_connect_tag_proto(ds, info); 775 break; 776 case DSA_NOTIFIER_TAG_PROTO_DISCONNECT: 777 err = dsa_switch_disconnect_tag_proto(ds, info); 778 break; 779 case DSA_NOTIFIER_TAG_8021Q_VLAN_ADD: 780 err = dsa_switch_tag_8021q_vlan_add(ds, info); 781 break; 782 case DSA_NOTIFIER_TAG_8021Q_VLAN_DEL: 783 err = dsa_switch_tag_8021q_vlan_del(ds, info); 784 break; 785 case DSA_NOTIFIER_MASTER_STATE_CHANGE: 786 err = dsa_switch_master_state_change(ds, info); 787 break; 788 default: 789 err = -EOPNOTSUPP; 790 break; 791 } 792 793 if (err) 794 dev_dbg(ds->dev, "breaking chain for DSA event %lu (%d)\n", 795 event, err); 796 797 return notifier_from_errno(err); 798 } 799 800 int dsa_switch_register_notifier(struct dsa_switch *ds) 801 { 802 ds->nb.notifier_call = dsa_switch_event; 803 804 return raw_notifier_chain_register(&ds->dst->nh, &ds->nb); 805 } 806 807 void dsa_switch_unregister_notifier(struct dsa_switch *ds) 808 { 809 int err; 810 811 err = raw_notifier_chain_unregister(&ds->dst->nh, &ds->nb); 812 if (err) 813 dev_err(ds->dev, "failed to unregister notifier (%d)\n", err); 814 } 815