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