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