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) { |
| 23 | struct dsa_port *dp = &ds->ports[i]; |
| 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; |
| 36 | struct switchdev_trans *trans = info->trans; |
| 37 | |
Vivien Didelot | 1faabf7 | 2017-05-19 17:00:52 -0400 | [diff] [blame] | 38 | if (switchdev_trans_ph_prepare(trans)) { |
| 39 | if (ds->ageing_time_min && ageing_time < ds->ageing_time_min) |
| 40 | return -ERANGE; |
| 41 | if (ds->ageing_time_max && ageing_time > ds->ageing_time_max) |
| 42 | return -ERANGE; |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | /* Program the fastest ageing time in case of multiple bridges */ |
| 47 | ageing_time = dsa_switch_fastest_ageing_time(ds, ageing_time); |
| 48 | |
| 49 | if (ds->ops->set_ageing_time) |
| 50 | return ds->ops->set_ageing_time(ds, ageing_time); |
| 51 | |
| 52 | return 0; |
| 53 | } |
| 54 | |
Vivien Didelot | 04d3a4c | 2017-02-03 13:20:21 -0500 | [diff] [blame] | 55 | static int dsa_switch_bridge_join(struct dsa_switch *ds, |
| 56 | struct dsa_notifier_bridge_info *info) |
| 57 | { |
| 58 | if (ds->index == info->sw_index && ds->ops->port_bridge_join) |
| 59 | return ds->ops->port_bridge_join(ds, info->port, info->br); |
| 60 | |
Vivien Didelot | 40ef2c9 | 2017-03-30 17:37:14 -0400 | [diff] [blame] | 61 | if (ds->index != info->sw_index && ds->ops->crosschip_bridge_join) |
| 62 | return ds->ops->crosschip_bridge_join(ds, info->sw_index, |
| 63 | info->port, info->br); |
Vivien Didelot | 04d3a4c | 2017-02-03 13:20:21 -0500 | [diff] [blame] | 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | static int dsa_switch_bridge_leave(struct dsa_switch *ds, |
| 69 | struct dsa_notifier_bridge_info *info) |
| 70 | { |
Vladimir Oltean | d371b7c | 2019-04-28 21:45:46 +0300 | [diff] [blame] | 71 | bool unset_vlan_filtering = br_vlan_enabled(info->br); |
| 72 | int err, i; |
| 73 | |
Vivien Didelot | 04d3a4c | 2017-02-03 13:20:21 -0500 | [diff] [blame] | 74 | if (ds->index == info->sw_index && ds->ops->port_bridge_leave) |
| 75 | ds->ops->port_bridge_leave(ds, info->port, info->br); |
| 76 | |
Vivien Didelot | 40ef2c9 | 2017-03-30 17:37:14 -0400 | [diff] [blame] | 77 | if (ds->index != info->sw_index && ds->ops->crosschip_bridge_leave) |
| 78 | ds->ops->crosschip_bridge_leave(ds, info->sw_index, info->port, |
| 79 | info->br); |
Vivien Didelot | 04d3a4c | 2017-02-03 13:20:21 -0500 | [diff] [blame] | 80 | |
Vladimir Oltean | d371b7c | 2019-04-28 21:45:46 +0300 | [diff] [blame] | 81 | /* If the bridge was vlan_filtering, the bridge core doesn't trigger an |
| 82 | * event for changing vlan_filtering setting upon slave ports leaving |
| 83 | * it. That is a good thing, because that lets us handle it and also |
| 84 | * handle the case where the switch's vlan_filtering setting is global |
| 85 | * (not per port). When that happens, the correct moment to trigger the |
| 86 | * vlan_filtering callback is only when the last port left this bridge. |
| 87 | */ |
| 88 | if (unset_vlan_filtering && ds->vlan_filtering_is_global) { |
| 89 | for (i = 0; i < ds->num_ports; i++) { |
| 90 | if (i == info->port) |
| 91 | continue; |
| 92 | if (dsa_to_port(ds, i)->bridge_dev == info->br) { |
| 93 | unset_vlan_filtering = false; |
| 94 | break; |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | if (unset_vlan_filtering) { |
| 99 | struct switchdev_trans trans = {0}; |
| 100 | |
| 101 | err = dsa_port_vlan_filtering(&ds->ports[info->port], |
| 102 | false, &trans); |
| 103 | if (err && err != EOPNOTSUPP) |
| 104 | return err; |
| 105 | } |
Vivien Didelot | 04d3a4c | 2017-02-03 13:20:21 -0500 | [diff] [blame] | 106 | return 0; |
| 107 | } |
| 108 | |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 109 | static int dsa_switch_fdb_add(struct dsa_switch *ds, |
| 110 | struct dsa_notifier_fdb_info *info) |
| 111 | { |
Vivien Didelot | 3169241 | 2017-11-30 12:56:43 -0500 | [diff] [blame] | 112 | int port = dsa_towards_port(ds, info->sw_index, info->port); |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 113 | |
Arkadi Sharshevsky | 1b6dd55 | 2017-08-06 16:15:40 +0300 | [diff] [blame] | 114 | if (!ds->ops->port_fdb_add) |
| 115 | return -EOPNOTSUPP; |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 116 | |
Vivien Didelot | 3169241 | 2017-11-30 12:56:43 -0500 | [diff] [blame] | 117 | return ds->ops->port_fdb_add(ds, port, info->addr, info->vid); |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | static int dsa_switch_fdb_del(struct dsa_switch *ds, |
| 121 | struct dsa_notifier_fdb_info *info) |
| 122 | { |
Vivien Didelot | 3169241 | 2017-11-30 12:56:43 -0500 | [diff] [blame] | 123 | int port = dsa_towards_port(ds, info->sw_index, info->port); |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 124 | |
| 125 | if (!ds->ops->port_fdb_del) |
| 126 | return -EOPNOTSUPP; |
| 127 | |
Vivien Didelot | 3169241 | 2017-11-30 12:56:43 -0500 | [diff] [blame] | 128 | return ds->ops->port_fdb_del(ds, port, info->addr, info->vid); |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 129 | } |
| 130 | |
Vivien Didelot | e6db98d | 2017-11-30 11:24:00 -0500 | [diff] [blame] | 131 | static int |
| 132 | dsa_switch_mdb_prepare_bitmap(struct dsa_switch *ds, |
| 133 | const struct switchdev_obj_port_mdb *mdb, |
| 134 | const unsigned long *bitmap) |
| 135 | { |
| 136 | int port, err; |
| 137 | |
| 138 | if (!ds->ops->port_mdb_prepare || !ds->ops->port_mdb_add) |
| 139 | return -EOPNOTSUPP; |
| 140 | |
| 141 | for_each_set_bit(port, bitmap, ds->num_ports) { |
| 142 | err = ds->ops->port_mdb_prepare(ds, port, mdb); |
| 143 | if (err) |
| 144 | return err; |
| 145 | } |
| 146 | |
| 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | static void dsa_switch_mdb_add_bitmap(struct dsa_switch *ds, |
| 151 | const struct switchdev_obj_port_mdb *mdb, |
| 152 | const unsigned long *bitmap) |
| 153 | { |
| 154 | int port; |
| 155 | |
Chen-Yu Tsai | 5879986 | 2019-08-11 22:18:25 +0800 | [diff] [blame] | 156 | if (!ds->ops->port_mdb_add) |
| 157 | return; |
| 158 | |
Vivien Didelot | e6db98d | 2017-11-30 11:24:00 -0500 | [diff] [blame] | 159 | for_each_set_bit(port, bitmap, ds->num_ports) |
| 160 | ds->ops->port_mdb_add(ds, port, mdb); |
| 161 | } |
| 162 | |
Vivien Didelot | 8ae5bcd | 2017-05-19 17:00:54 -0400 | [diff] [blame] | 163 | static int dsa_switch_mdb_add(struct dsa_switch *ds, |
| 164 | struct dsa_notifier_mdb_info *info) |
| 165 | { |
| 166 | const struct switchdev_obj_port_mdb *mdb = info->mdb; |
| 167 | struct switchdev_trans *trans = info->trans; |
Vivien Didelot | e6db98d | 2017-11-30 11:24:00 -0500 | [diff] [blame] | 168 | int port; |
Vivien Didelot | 8ae5bcd | 2017-05-19 17:00:54 -0400 | [diff] [blame] | 169 | |
Vivien Didelot | a1a6b7e | 2017-06-15 16:14:48 -0400 | [diff] [blame] | 170 | /* Build a mask of Multicast group members */ |
Salvatore Mesoraca | 0015b80 | 2018-07-16 21:10:34 -0700 | [diff] [blame] | 171 | bitmap_zero(ds->bitmap, ds->num_ports); |
Vivien Didelot | a1a6b7e | 2017-06-15 16:14:48 -0400 | [diff] [blame] | 172 | if (ds->index == info->sw_index) |
Salvatore Mesoraca | 0015b80 | 2018-07-16 21:10:34 -0700 | [diff] [blame] | 173 | set_bit(info->port, ds->bitmap); |
Vivien Didelot | a1a6b7e | 2017-06-15 16:14:48 -0400 | [diff] [blame] | 174 | for (port = 0; port < ds->num_ports; port++) |
Andrew Lunn | ae45102 | 2017-11-09 23:11:02 +0100 | [diff] [blame] | 175 | if (dsa_is_dsa_port(ds, port)) |
Salvatore Mesoraca | 0015b80 | 2018-07-16 21:10:34 -0700 | [diff] [blame] | 176 | set_bit(port, ds->bitmap); |
Vivien Didelot | 8ae5bcd | 2017-05-19 17:00:54 -0400 | [diff] [blame] | 177 | |
Vivien Didelot | e6db98d | 2017-11-30 11:24:00 -0500 | [diff] [blame] | 178 | if (switchdev_trans_ph_prepare(trans)) |
Salvatore Mesoraca | 0015b80 | 2018-07-16 21:10:34 -0700 | [diff] [blame] | 179 | return dsa_switch_mdb_prepare_bitmap(ds, mdb, ds->bitmap); |
Vivien Didelot | 8ae5bcd | 2017-05-19 17:00:54 -0400 | [diff] [blame] | 180 | |
Salvatore Mesoraca | 0015b80 | 2018-07-16 21:10:34 -0700 | [diff] [blame] | 181 | dsa_switch_mdb_add_bitmap(ds, mdb, ds->bitmap); |
Vivien Didelot | 8ae5bcd | 2017-05-19 17:00:54 -0400 | [diff] [blame] | 182 | |
| 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | static int dsa_switch_mdb_del(struct dsa_switch *ds, |
| 187 | struct dsa_notifier_mdb_info *info) |
| 188 | { |
| 189 | const struct switchdev_obj_port_mdb *mdb = info->mdb; |
| 190 | |
Vivien Didelot | 8ae5bcd | 2017-05-19 17:00:54 -0400 | [diff] [blame] | 191 | if (!ds->ops->port_mdb_del) |
| 192 | return -EOPNOTSUPP; |
| 193 | |
Vivien Didelot | a1a6b7e | 2017-06-15 16:14:48 -0400 | [diff] [blame] | 194 | if (ds->index == info->sw_index) |
| 195 | return ds->ops->port_mdb_del(ds, info->port, mdb); |
| 196 | |
| 197 | return 0; |
Vivien Didelot | 8ae5bcd | 2017-05-19 17:00:54 -0400 | [diff] [blame] | 198 | } |
| 199 | |
Florian Fainelli | 061f6a5 | 2019-02-20 14:35:39 -0800 | [diff] [blame] | 200 | static int dsa_port_vlan_device_check(struct net_device *vlan_dev, |
| 201 | int vlan_dev_vid, |
| 202 | void *arg) |
| 203 | { |
| 204 | struct switchdev_obj_port_vlan *vlan = arg; |
| 205 | u16 vid; |
| 206 | |
| 207 | for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) { |
| 208 | if (vid == vlan_dev_vid) |
| 209 | return -EBUSY; |
| 210 | } |
| 211 | |
| 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | static int dsa_port_vlan_check(struct dsa_switch *ds, int port, |
| 216 | const struct switchdev_obj_port_vlan *vlan) |
| 217 | { |
| 218 | const struct dsa_port *dp = dsa_to_port(ds, port); |
| 219 | int err = 0; |
| 220 | |
| 221 | /* Device is not bridged, let it proceed with the VLAN device |
| 222 | * creation. |
| 223 | */ |
| 224 | if (!dp->bridge_dev) |
| 225 | return err; |
| 226 | |
Vladimir Oltean | 85478d7 | 2019-04-28 21:45:42 +0300 | [diff] [blame] | 227 | /* dsa_slave_vlan_rx_{add,kill}_vid() cannot use the prepare phase and |
Florian Fainelli | 061f6a5 | 2019-02-20 14:35:39 -0800 | [diff] [blame] | 228 | * already checks whether there is an overlapping bridge VLAN entry |
| 229 | * with the same VID, so here we only need to check that if we are |
| 230 | * adding a bridge VLAN entry there is not an overlapping VLAN device |
| 231 | * claiming that VID. |
| 232 | */ |
| 233 | return vlan_for_each(dp->slave, dsa_port_vlan_device_check, |
| 234 | (void *)vlan); |
| 235 | } |
| 236 | |
Vivien Didelot | 9c428c5 | 2017-11-30 11:23:59 -0500 | [diff] [blame] | 237 | static int |
| 238 | dsa_switch_vlan_prepare_bitmap(struct dsa_switch *ds, |
| 239 | const struct switchdev_obj_port_vlan *vlan, |
| 240 | const unsigned long *bitmap) |
| 241 | { |
| 242 | int port, err; |
| 243 | |
| 244 | if (!ds->ops->port_vlan_prepare || !ds->ops->port_vlan_add) |
| 245 | return -EOPNOTSUPP; |
| 246 | |
| 247 | for_each_set_bit(port, bitmap, ds->num_ports) { |
Florian Fainelli | 061f6a5 | 2019-02-20 14:35:39 -0800 | [diff] [blame] | 248 | err = dsa_port_vlan_check(ds, port, vlan); |
| 249 | if (err) |
| 250 | return err; |
| 251 | |
Vivien Didelot | 9c428c5 | 2017-11-30 11:23:59 -0500 | [diff] [blame] | 252 | err = ds->ops->port_vlan_prepare(ds, port, vlan); |
| 253 | if (err) |
| 254 | return err; |
| 255 | } |
| 256 | |
| 257 | return 0; |
| 258 | } |
| 259 | |
| 260 | static void |
| 261 | dsa_switch_vlan_add_bitmap(struct dsa_switch *ds, |
| 262 | const struct switchdev_obj_port_vlan *vlan, |
| 263 | const unsigned long *bitmap) |
| 264 | { |
| 265 | int port; |
| 266 | |
| 267 | for_each_set_bit(port, bitmap, ds->num_ports) |
| 268 | ds->ops->port_vlan_add(ds, port, vlan); |
| 269 | } |
| 270 | |
Vivien Didelot | d0c627b | 2017-05-19 17:00:55 -0400 | [diff] [blame] | 271 | static int dsa_switch_vlan_add(struct dsa_switch *ds, |
| 272 | struct dsa_notifier_vlan_info *info) |
| 273 | { |
| 274 | const struct switchdev_obj_port_vlan *vlan = info->vlan; |
| 275 | struct switchdev_trans *trans = info->trans; |
Vivien Didelot | 9c428c5 | 2017-11-30 11:23:59 -0500 | [diff] [blame] | 276 | int port; |
Vivien Didelot | d0c627b | 2017-05-19 17:00:55 -0400 | [diff] [blame] | 277 | |
Vivien Didelot | 1ca4aa9 | 2017-06-07 18:12:14 -0400 | [diff] [blame] | 278 | /* Build a mask of VLAN members */ |
Salvatore Mesoraca | 0015b80 | 2018-07-16 21:10:34 -0700 | [diff] [blame] | 279 | bitmap_zero(ds->bitmap, ds->num_ports); |
Vivien Didelot | 1ca4aa9 | 2017-06-07 18:12:14 -0400 | [diff] [blame] | 280 | if (ds->index == info->sw_index) |
Salvatore Mesoraca | 0015b80 | 2018-07-16 21:10:34 -0700 | [diff] [blame] | 281 | set_bit(info->port, ds->bitmap); |
Vivien Didelot | b2f81d3 | 2017-06-07 18:12:15 -0400 | [diff] [blame] | 282 | for (port = 0; port < ds->num_ports; port++) |
| 283 | if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) |
Salvatore Mesoraca | 0015b80 | 2018-07-16 21:10:34 -0700 | [diff] [blame] | 284 | set_bit(port, ds->bitmap); |
Vivien Didelot | d0c627b | 2017-05-19 17:00:55 -0400 | [diff] [blame] | 285 | |
Vivien Didelot | 9c428c5 | 2017-11-30 11:23:59 -0500 | [diff] [blame] | 286 | if (switchdev_trans_ph_prepare(trans)) |
Salvatore Mesoraca | 0015b80 | 2018-07-16 21:10:34 -0700 | [diff] [blame] | 287 | return dsa_switch_vlan_prepare_bitmap(ds, vlan, ds->bitmap); |
Vivien Didelot | d0c627b | 2017-05-19 17:00:55 -0400 | [diff] [blame] | 288 | |
Salvatore Mesoraca | 0015b80 | 2018-07-16 21:10:34 -0700 | [diff] [blame] | 289 | dsa_switch_vlan_add_bitmap(ds, vlan, ds->bitmap); |
Vivien Didelot | d0c627b | 2017-05-19 17:00:55 -0400 | [diff] [blame] | 290 | |
| 291 | return 0; |
| 292 | } |
| 293 | |
| 294 | static int dsa_switch_vlan_del(struct dsa_switch *ds, |
| 295 | struct dsa_notifier_vlan_info *info) |
| 296 | { |
| 297 | const struct switchdev_obj_port_vlan *vlan = info->vlan; |
| 298 | |
Vivien Didelot | d0c627b | 2017-05-19 17:00:55 -0400 | [diff] [blame] | 299 | if (!ds->ops->port_vlan_del) |
| 300 | return -EOPNOTSUPP; |
| 301 | |
Vivien Didelot | 1ca4aa9 | 2017-06-07 18:12:14 -0400 | [diff] [blame] | 302 | if (ds->index == info->sw_index) |
| 303 | return ds->ops->port_vlan_del(ds, info->port, vlan); |
| 304 | |
| 305 | return 0; |
Vivien Didelot | d0c627b | 2017-05-19 17:00:55 -0400 | [diff] [blame] | 306 | } |
| 307 | |
Vivien Didelot | f515f19 | 2017-02-03 13:20:20 -0500 | [diff] [blame] | 308 | static int dsa_switch_event(struct notifier_block *nb, |
| 309 | unsigned long event, void *info) |
| 310 | { |
| 311 | struct dsa_switch *ds = container_of(nb, struct dsa_switch, nb); |
| 312 | int err; |
| 313 | |
| 314 | switch (event) { |
Vivien Didelot | 1faabf7 | 2017-05-19 17:00:52 -0400 | [diff] [blame] | 315 | case DSA_NOTIFIER_AGEING_TIME: |
| 316 | err = dsa_switch_ageing_time(ds, info); |
| 317 | break; |
Vivien Didelot | 04d3a4c | 2017-02-03 13:20:21 -0500 | [diff] [blame] | 318 | case DSA_NOTIFIER_BRIDGE_JOIN: |
| 319 | err = dsa_switch_bridge_join(ds, info); |
| 320 | break; |
| 321 | case DSA_NOTIFIER_BRIDGE_LEAVE: |
| 322 | err = dsa_switch_bridge_leave(ds, info); |
| 323 | break; |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 324 | case DSA_NOTIFIER_FDB_ADD: |
| 325 | err = dsa_switch_fdb_add(ds, info); |
| 326 | break; |
| 327 | case DSA_NOTIFIER_FDB_DEL: |
| 328 | err = dsa_switch_fdb_del(ds, info); |
| 329 | break; |
Vivien Didelot | 8ae5bcd | 2017-05-19 17:00:54 -0400 | [diff] [blame] | 330 | case DSA_NOTIFIER_MDB_ADD: |
| 331 | err = dsa_switch_mdb_add(ds, info); |
| 332 | break; |
| 333 | case DSA_NOTIFIER_MDB_DEL: |
| 334 | err = dsa_switch_mdb_del(ds, info); |
| 335 | break; |
Vivien Didelot | d0c627b | 2017-05-19 17:00:55 -0400 | [diff] [blame] | 336 | case DSA_NOTIFIER_VLAN_ADD: |
| 337 | err = dsa_switch_vlan_add(ds, info); |
| 338 | break; |
| 339 | case DSA_NOTIFIER_VLAN_DEL: |
| 340 | err = dsa_switch_vlan_del(ds, info); |
| 341 | break; |
Vivien Didelot | f515f19 | 2017-02-03 13:20:20 -0500 | [diff] [blame] | 342 | default: |
| 343 | err = -EOPNOTSUPP; |
| 344 | break; |
| 345 | } |
| 346 | |
| 347 | /* Non-switchdev operations cannot be rolled back. If a DSA driver |
| 348 | * returns an error during the chained call, switch chips may be in an |
| 349 | * inconsistent state. |
| 350 | */ |
| 351 | if (err) |
| 352 | dev_dbg(ds->dev, "breaking chain for DSA event %lu (%d)\n", |
| 353 | event, err); |
| 354 | |
| 355 | return notifier_from_errno(err); |
| 356 | } |
| 357 | |
| 358 | int dsa_switch_register_notifier(struct dsa_switch *ds) |
| 359 | { |
| 360 | ds->nb.notifier_call = dsa_switch_event; |
| 361 | |
| 362 | return raw_notifier_chain_register(&ds->dst->nh, &ds->nb); |
| 363 | } |
| 364 | |
| 365 | void dsa_switch_unregister_notifier(struct dsa_switch *ds) |
| 366 | { |
| 367 | int err; |
| 368 | |
| 369 | err = raw_notifier_chain_unregister(&ds->dst->nh, &ds->nb); |
| 370 | if (err) |
| 371 | dev_err(ds->dev, "failed to unregister notifier (%d)\n", err); |
| 372 | } |