Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 2 | /* |
| 3 | * net/dsa/dsa2.c - Hardware switch handling, binding version 2 |
| 4 | * Copyright (c) 2008-2009 Marvell Semiconductor |
| 5 | * Copyright (c) 2013 Florian Fainelli <florian@openwrt.org> |
| 6 | * Copyright (c) 2016 Andrew Lunn <andrew@lunn.ch> |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/device.h> |
| 10 | #include <linux/err.h> |
| 11 | #include <linux/list.h> |
Andrew Lunn | c6e970a | 2017-03-28 23:45:06 +0200 | [diff] [blame] | 12 | #include <linux/netdevice.h> |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 13 | #include <linux/slab.h> |
| 14 | #include <linux/rtnetlink.h> |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 15 | #include <linux/of.h> |
| 16 | #include <linux/of_net.h> |
Jiri Pirko | 402f99e5 | 2019-03-24 11:14:26 +0100 | [diff] [blame] | 17 | #include <net/devlink.h> |
Vivien Didelot | ea5dd34 | 2017-05-17 15:46:03 -0400 | [diff] [blame] | 18 | |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 19 | #include "dsa_priv.h" |
| 20 | |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 21 | static DEFINE_MUTEX(dsa2_mutex); |
Vladimir Oltean | bff33f7 | 2020-03-27 21:55:43 +0200 | [diff] [blame] | 22 | LIST_HEAD(dsa_tree_list); |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 23 | |
Vladimir Oltean | f5e165e | 2021-08-19 20:55:00 +0300 | [diff] [blame] | 24 | /* Track the bridges with forwarding offload enabled */ |
| 25 | static unsigned long dsa_fwd_offloading_bridges; |
| 26 | |
Tobias Waldekranz | 058102a | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 27 | /** |
Vladimir Oltean | 886f8e2 | 2021-01-29 03:00:04 +0200 | [diff] [blame] | 28 | * dsa_tree_notify - Execute code for all switches in a DSA switch tree. |
| 29 | * @dst: collection of struct dsa_switch devices to notify. |
| 30 | * @e: event, must be of type DSA_NOTIFIER_* |
| 31 | * @v: event-specific value. |
| 32 | * |
| 33 | * Given a struct dsa_switch_tree, this can be used to run a function once for |
| 34 | * each member DSA switch. The other alternative of traversing the tree is only |
| 35 | * through its ports list, which does not uniquely list the switches. |
| 36 | */ |
| 37 | int dsa_tree_notify(struct dsa_switch_tree *dst, unsigned long e, void *v) |
| 38 | { |
| 39 | struct raw_notifier_head *nh = &dst->nh; |
| 40 | int err; |
| 41 | |
| 42 | err = raw_notifier_call_chain(nh, e, v); |
| 43 | |
| 44 | return notifier_to_errno(err); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * dsa_broadcast - Notify all DSA trees in the system. |
| 49 | * @e: event, must be of type DSA_NOTIFIER_* |
| 50 | * @v: event-specific value. |
| 51 | * |
| 52 | * Can be used to notify the switching fabric of events such as cross-chip |
| 53 | * bridging between disjoint trees (such as islands of tagger-compatible |
| 54 | * switches bridged by an incompatible middle switch). |
Vladimir Oltean | 724395f | 2021-08-11 16:46:06 +0300 | [diff] [blame] | 55 | * |
| 56 | * WARNING: this function is not reliable during probe time, because probing |
| 57 | * between trees is asynchronous and not all DSA trees might have probed. |
Vladimir Oltean | 886f8e2 | 2021-01-29 03:00:04 +0200 | [diff] [blame] | 58 | */ |
| 59 | int dsa_broadcast(unsigned long e, void *v) |
| 60 | { |
| 61 | struct dsa_switch_tree *dst; |
| 62 | int err = 0; |
| 63 | |
| 64 | list_for_each_entry(dst, &dsa_tree_list, list) { |
| 65 | err = dsa_tree_notify(dst, e, v); |
| 66 | if (err) |
| 67 | break; |
| 68 | } |
| 69 | |
| 70 | return err; |
| 71 | } |
| 72 | |
| 73 | /** |
Tobias Waldekranz | 058102a | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 74 | * dsa_lag_map() - Map LAG netdev to a linear LAG ID |
| 75 | * @dst: Tree in which to record the mapping. |
| 76 | * @lag: Netdev that is to be mapped to an ID. |
| 77 | * |
| 78 | * dsa_lag_id/dsa_lag_dev can then be used to translate between the |
| 79 | * two spaces. The size of the mapping space is determined by the |
| 80 | * driver by setting ds->num_lag_ids. It is perfectly legal to leave |
| 81 | * it unset if it is not needed, in which case these functions become |
| 82 | * no-ops. |
| 83 | */ |
| 84 | void dsa_lag_map(struct dsa_switch_tree *dst, struct net_device *lag) |
| 85 | { |
| 86 | unsigned int id; |
| 87 | |
| 88 | if (dsa_lag_id(dst, lag) >= 0) |
| 89 | /* Already mapped */ |
| 90 | return; |
| 91 | |
| 92 | for (id = 0; id < dst->lags_len; id++) { |
| 93 | if (!dsa_lag_dev(dst, id)) { |
| 94 | dst->lags[id] = lag; |
| 95 | return; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | /* No IDs left, which is OK. Some drivers do not need it. The |
| 100 | * ones that do, e.g. mv88e6xxx, will discover that dsa_lag_id |
| 101 | * returns an error for this device when joining the LAG. The |
| 102 | * driver can then return -EOPNOTSUPP back to DSA, which will |
| 103 | * fall back to a software LAG. |
| 104 | */ |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * dsa_lag_unmap() - Remove a LAG ID mapping |
| 109 | * @dst: Tree in which the mapping is recorded. |
| 110 | * @lag: Netdev that was mapped. |
| 111 | * |
| 112 | * As there may be multiple users of the mapping, it is only removed |
| 113 | * if there are no other references to it. |
| 114 | */ |
| 115 | void dsa_lag_unmap(struct dsa_switch_tree *dst, struct net_device *lag) |
| 116 | { |
| 117 | struct dsa_port *dp; |
| 118 | unsigned int id; |
| 119 | |
| 120 | dsa_lag_foreach_port(dp, dst, lag) |
| 121 | /* There are remaining users of this mapping */ |
| 122 | return; |
| 123 | |
| 124 | dsa_lags_foreach_id(id, dst) { |
| 125 | if (dsa_lag_dev(dst, id) == lag) { |
| 126 | dst->lags[id] = NULL; |
| 127 | break; |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
Vladimir Oltean | f5e165e | 2021-08-19 20:55:00 +0300 | [diff] [blame] | 132 | static int dsa_bridge_num_find(const struct net_device *bridge_dev) |
| 133 | { |
| 134 | struct dsa_switch_tree *dst; |
| 135 | struct dsa_port *dp; |
| 136 | |
| 137 | /* When preparing the offload for a port, it will have a valid |
| 138 | * dp->bridge_dev pointer but a not yet valid dp->bridge_num. |
| 139 | * However there might be other ports having the same dp->bridge_dev |
| 140 | * and a valid dp->bridge_num, so just ignore this port. |
| 141 | */ |
| 142 | list_for_each_entry(dst, &dsa_tree_list, list) |
| 143 | list_for_each_entry(dp, &dst->ports, list) |
Vladimir Oltean | 3f9bb03 | 2021-12-06 18:57:47 +0200 | [diff] [blame] | 144 | if (dp->bridge_dev == bridge_dev && dp->bridge_num) |
Vladimir Oltean | f5e165e | 2021-08-19 20:55:00 +0300 | [diff] [blame] | 145 | return dp->bridge_num; |
| 146 | |
Vladimir Oltean | 3f9bb03 | 2021-12-06 18:57:47 +0200 | [diff] [blame] | 147 | return 0; |
Vladimir Oltean | f5e165e | 2021-08-19 20:55:00 +0300 | [diff] [blame] | 148 | } |
| 149 | |
Vladimir Oltean | 3f9bb03 | 2021-12-06 18:57:47 +0200 | [diff] [blame] | 150 | unsigned int dsa_bridge_num_get(const struct net_device *bridge_dev, int max) |
Vladimir Oltean | f5e165e | 2021-08-19 20:55:00 +0300 | [diff] [blame] | 151 | { |
Vladimir Oltean | 3f9bb03 | 2021-12-06 18:57:47 +0200 | [diff] [blame] | 152 | unsigned int bridge_num = dsa_bridge_num_find(bridge_dev); |
Vladimir Oltean | f5e165e | 2021-08-19 20:55:00 +0300 | [diff] [blame] | 153 | |
Vladimir Oltean | 3f9bb03 | 2021-12-06 18:57:47 +0200 | [diff] [blame] | 154 | if (!bridge_num) { |
Vladimir Oltean | 947c874 | 2021-12-06 18:57:48 +0200 | [diff] [blame^] | 155 | /* First port that requests FDB isolation or TX forwarding |
| 156 | * offload for this bridge |
| 157 | */ |
Vladimir Oltean | 3f9bb03 | 2021-12-06 18:57:47 +0200 | [diff] [blame] | 158 | bridge_num = find_next_zero_bit(&dsa_fwd_offloading_bridges, |
| 159 | DSA_MAX_NUM_OFFLOADING_BRIDGES, |
| 160 | 1); |
Vladimir Oltean | f5e165e | 2021-08-19 20:55:00 +0300 | [diff] [blame] | 161 | if (bridge_num >= max) |
Vladimir Oltean | 3f9bb03 | 2021-12-06 18:57:47 +0200 | [diff] [blame] | 162 | return 0; |
Vladimir Oltean | f5e165e | 2021-08-19 20:55:00 +0300 | [diff] [blame] | 163 | |
| 164 | set_bit(bridge_num, &dsa_fwd_offloading_bridges); |
| 165 | } |
| 166 | |
| 167 | return bridge_num; |
| 168 | } |
| 169 | |
Vladimir Oltean | 3f9bb03 | 2021-12-06 18:57:47 +0200 | [diff] [blame] | 170 | void dsa_bridge_num_put(const struct net_device *bridge_dev, |
| 171 | unsigned int bridge_num) |
Vladimir Oltean | f5e165e | 2021-08-19 20:55:00 +0300 | [diff] [blame] | 172 | { |
| 173 | /* Check if the bridge is still in use, otherwise it is time |
| 174 | * to clean it up so we can reuse this bridge_num later. |
| 175 | */ |
Vladimir Oltean | 3f9bb03 | 2021-12-06 18:57:47 +0200 | [diff] [blame] | 176 | if (!dsa_bridge_num_find(bridge_dev)) |
Vladimir Oltean | f5e165e | 2021-08-19 20:55:00 +0300 | [diff] [blame] | 177 | clear_bit(bridge_num, &dsa_fwd_offloading_bridges); |
| 178 | } |
| 179 | |
Vladimir Oltean | 3b7bc1f | 2020-05-10 19:37:42 +0300 | [diff] [blame] | 180 | struct dsa_switch *dsa_switch_find(int tree_index, int sw_index) |
| 181 | { |
| 182 | struct dsa_switch_tree *dst; |
| 183 | struct dsa_port *dp; |
| 184 | |
| 185 | list_for_each_entry(dst, &dsa_tree_list, list) { |
| 186 | if (dst->index != tree_index) |
| 187 | continue; |
| 188 | |
| 189 | list_for_each_entry(dp, &dst->ports, list) { |
| 190 | if (dp->ds->index != sw_index) |
| 191 | continue; |
| 192 | |
| 193 | return dp->ds; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | return NULL; |
| 198 | } |
| 199 | EXPORT_SYMBOL_GPL(dsa_switch_find); |
| 200 | |
Vivien Didelot | 1ca28ec | 2017-11-03 19:05:24 -0400 | [diff] [blame] | 201 | static struct dsa_switch_tree *dsa_tree_find(int index) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 202 | { |
| 203 | struct dsa_switch_tree *dst; |
| 204 | |
Vivien Didelot | 1ca28ec | 2017-11-03 19:05:24 -0400 | [diff] [blame] | 205 | list_for_each_entry(dst, &dsa_tree_list, list) |
Vivien Didelot | 8e5bf97 | 2017-11-03 19:05:22 -0400 | [diff] [blame] | 206 | if (dst->index == index) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 207 | return dst; |
Vivien Didelot | 8e5bf97 | 2017-11-03 19:05:22 -0400 | [diff] [blame] | 208 | |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 209 | return NULL; |
| 210 | } |
| 211 | |
Vivien Didelot | 1ca28ec | 2017-11-03 19:05:24 -0400 | [diff] [blame] | 212 | static struct dsa_switch_tree *dsa_tree_alloc(int index) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 213 | { |
| 214 | struct dsa_switch_tree *dst; |
| 215 | |
| 216 | dst = kzalloc(sizeof(*dst), GFP_KERNEL); |
| 217 | if (!dst) |
| 218 | return NULL; |
Vivien Didelot | 1ca28ec | 2017-11-03 19:05:24 -0400 | [diff] [blame] | 219 | |
Vivien Didelot | 49463b7 | 2017-11-03 19:05:21 -0400 | [diff] [blame] | 220 | dst->index = index; |
Vivien Didelot | 1ca28ec | 2017-11-03 19:05:24 -0400 | [diff] [blame] | 221 | |
Vivien Didelot | c5f5176 | 2019-10-30 22:09:13 -0400 | [diff] [blame] | 222 | INIT_LIST_HEAD(&dst->rtable); |
| 223 | |
Vivien Didelot | ab8ccae | 2019-10-21 16:51:16 -0400 | [diff] [blame] | 224 | INIT_LIST_HEAD(&dst->ports); |
| 225 | |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 226 | INIT_LIST_HEAD(&dst->list); |
Vivien Didelot | 50c7d2ba | 2019-10-18 17:02:46 -0400 | [diff] [blame] | 227 | list_add_tail(&dst->list, &dsa_tree_list); |
Vivien Didelot | 8e5bf97 | 2017-11-03 19:05:22 -0400 | [diff] [blame] | 228 | |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 229 | kref_init(&dst->refcount); |
| 230 | |
| 231 | return dst; |
| 232 | } |
| 233 | |
Vivien Didelot | 6525410 | 2017-11-03 19:05:23 -0400 | [diff] [blame] | 234 | static void dsa_tree_free(struct dsa_switch_tree *dst) |
| 235 | { |
Vladimir Oltean | 357f203 | 2021-01-29 03:00:05 +0200 | [diff] [blame] | 236 | if (dst->tag_ops) |
| 237 | dsa_tag_driver_put(dst->tag_ops); |
Vivien Didelot | 6525410 | 2017-11-03 19:05:23 -0400 | [diff] [blame] | 238 | list_del(&dst->list); |
| 239 | kfree(dst); |
| 240 | } |
| 241 | |
Vivien Didelot | 9e74104 | 2017-11-24 11:36:06 -0500 | [diff] [blame] | 242 | static struct dsa_switch_tree *dsa_tree_get(struct dsa_switch_tree *dst) |
| 243 | { |
| 244 | if (dst) |
| 245 | kref_get(&dst->refcount); |
| 246 | |
| 247 | return dst; |
| 248 | } |
| 249 | |
Vivien Didelot | 1ca28ec | 2017-11-03 19:05:24 -0400 | [diff] [blame] | 250 | static struct dsa_switch_tree *dsa_tree_touch(int index) |
| 251 | { |
| 252 | struct dsa_switch_tree *dst; |
| 253 | |
| 254 | dst = dsa_tree_find(index); |
Vivien Didelot | 9e74104 | 2017-11-24 11:36:06 -0500 | [diff] [blame] | 255 | if (dst) |
| 256 | return dsa_tree_get(dst); |
| 257 | else |
| 258 | return dsa_tree_alloc(index); |
Vivien Didelot | 6525410 | 2017-11-03 19:05:23 -0400 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | static void dsa_tree_release(struct kref *ref) |
| 262 | { |
| 263 | struct dsa_switch_tree *dst; |
| 264 | |
| 265 | dst = container_of(ref, struct dsa_switch_tree, refcount); |
| 266 | |
| 267 | dsa_tree_free(dst); |
| 268 | } |
| 269 | |
| 270 | static void dsa_tree_put(struct dsa_switch_tree *dst) |
| 271 | { |
Vivien Didelot | 9e74104 | 2017-11-24 11:36:06 -0500 | [diff] [blame] | 272 | if (dst) |
| 273 | kref_put(&dst->refcount, dsa_tree_release); |
Vivien Didelot | 6525410 | 2017-11-03 19:05:23 -0400 | [diff] [blame] | 274 | } |
| 275 | |
Vivien Didelot | f163da8 | 2017-11-06 16:11:49 -0500 | [diff] [blame] | 276 | static struct dsa_port *dsa_tree_find_port_by_node(struct dsa_switch_tree *dst, |
| 277 | struct device_node *dn) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 278 | { |
Vivien Didelot | f163da8 | 2017-11-06 16:11:49 -0500 | [diff] [blame] | 279 | struct dsa_port *dp; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 280 | |
Vivien Didelot | 764b7e6 | 2019-10-21 16:51:21 -0400 | [diff] [blame] | 281 | list_for_each_entry(dp, &dst->ports, list) |
| 282 | if (dp->dn == dn) |
| 283 | return dp; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 284 | |
| 285 | return NULL; |
| 286 | } |
| 287 | |
Ben Dooks (Codethink) | 4e2ce6e | 2019-12-17 11:20:38 +0000 | [diff] [blame] | 288 | static struct dsa_link *dsa_link_touch(struct dsa_port *dp, |
| 289 | struct dsa_port *link_dp) |
Vivien Didelot | c5f5176 | 2019-10-30 22:09:13 -0400 | [diff] [blame] | 290 | { |
| 291 | struct dsa_switch *ds = dp->ds; |
| 292 | struct dsa_switch_tree *dst; |
| 293 | struct dsa_link *dl; |
| 294 | |
| 295 | dst = ds->dst; |
| 296 | |
| 297 | list_for_each_entry(dl, &dst->rtable, list) |
| 298 | if (dl->dp == dp && dl->link_dp == link_dp) |
| 299 | return dl; |
| 300 | |
| 301 | dl = kzalloc(sizeof(*dl), GFP_KERNEL); |
| 302 | if (!dl) |
| 303 | return NULL; |
| 304 | |
| 305 | dl->dp = dp; |
| 306 | dl->link_dp = link_dp; |
| 307 | |
| 308 | INIT_LIST_HEAD(&dl->list); |
| 309 | list_add_tail(&dl->list, &dst->rtable); |
| 310 | |
| 311 | return dl; |
| 312 | } |
| 313 | |
Vivien Didelot | 34c09a8 | 2017-11-06 16:11:51 -0500 | [diff] [blame] | 314 | static bool dsa_port_setup_routing_table(struct dsa_port *dp) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 315 | { |
Vivien Didelot | 34c09a8 | 2017-11-06 16:11:51 -0500 | [diff] [blame] | 316 | struct dsa_switch *ds = dp->ds; |
| 317 | struct dsa_switch_tree *dst = ds->dst; |
| 318 | struct device_node *dn = dp->dn; |
Vivien Didelot | c528666 | 2017-11-06 16:11:50 -0500 | [diff] [blame] | 319 | struct of_phandle_iterator it; |
Vivien Didelot | f163da8 | 2017-11-06 16:11:49 -0500 | [diff] [blame] | 320 | struct dsa_port *link_dp; |
Vivien Didelot | c5f5176 | 2019-10-30 22:09:13 -0400 | [diff] [blame] | 321 | struct dsa_link *dl; |
Vivien Didelot | c528666 | 2017-11-06 16:11:50 -0500 | [diff] [blame] | 322 | int err; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 323 | |
Vivien Didelot | c528666 | 2017-11-06 16:11:50 -0500 | [diff] [blame] | 324 | of_for_each_phandle(&it, err, dn, "link", NULL, 0) { |
| 325 | link_dp = dsa_tree_find_port_by_node(dst, it.node); |
| 326 | if (!link_dp) { |
| 327 | of_node_put(it.node); |
Vivien Didelot | 34c09a8 | 2017-11-06 16:11:51 -0500 | [diff] [blame] | 328 | return false; |
Vivien Didelot | c528666 | 2017-11-06 16:11:50 -0500 | [diff] [blame] | 329 | } |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 330 | |
Vivien Didelot | c5f5176 | 2019-10-30 22:09:13 -0400 | [diff] [blame] | 331 | dl = dsa_link_touch(dp, link_dp); |
| 332 | if (!dl) { |
| 333 | of_node_put(it.node); |
| 334 | return false; |
| 335 | } |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 336 | } |
| 337 | |
Vivien Didelot | 34c09a8 | 2017-11-06 16:11:51 -0500 | [diff] [blame] | 338 | return true; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 339 | } |
| 340 | |
Vivien Didelot | 3774ecd | 2019-10-30 22:09:15 -0400 | [diff] [blame] | 341 | static bool dsa_tree_setup_routing_table(struct dsa_switch_tree *dst) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 342 | { |
Vivien Didelot | 34c09a8 | 2017-11-06 16:11:51 -0500 | [diff] [blame] | 343 | bool complete = true; |
| 344 | struct dsa_port *dp; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 345 | |
Vivien Didelot | 86bfb2c | 2019-10-21 16:51:20 -0400 | [diff] [blame] | 346 | list_for_each_entry(dp, &dst->ports, list) { |
Vivien Didelot | 3774ecd | 2019-10-30 22:09:15 -0400 | [diff] [blame] | 347 | if (dsa_port_is_dsa(dp)) { |
Vivien Didelot | 34c09a8 | 2017-11-06 16:11:51 -0500 | [diff] [blame] | 348 | complete = dsa_port_setup_routing_table(dp); |
| 349 | if (!complete) |
| 350 | break; |
| 351 | } |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 352 | } |
| 353 | |
Vivien Didelot | 34c09a8 | 2017-11-06 16:11:51 -0500 | [diff] [blame] | 354 | return complete; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 355 | } |
| 356 | |
Vivien Didelot | f070464 | 2017-11-06 16:11:44 -0500 | [diff] [blame] | 357 | static struct dsa_port *dsa_tree_find_first_cpu(struct dsa_switch_tree *dst) |
| 358 | { |
Vivien Didelot | f070464 | 2017-11-06 16:11:44 -0500 | [diff] [blame] | 359 | struct dsa_port *dp; |
Vivien Didelot | f070464 | 2017-11-06 16:11:44 -0500 | [diff] [blame] | 360 | |
Vivien Didelot | c0b7362 | 2019-10-21 16:51:23 -0400 | [diff] [blame] | 361 | list_for_each_entry(dp, &dst->ports, list) |
| 362 | if (dsa_port_is_cpu(dp)) |
| 363 | return dp; |
Vivien Didelot | f070464 | 2017-11-06 16:11:44 -0500 | [diff] [blame] | 364 | |
| 365 | return NULL; |
| 366 | } |
| 367 | |
Vladimir Oltean | 2c0b032 | 2021-08-04 16:54:30 +0300 | [diff] [blame] | 368 | /* Assign the default CPU port (the first one in the tree) to all ports of the |
| 369 | * fabric which don't already have one as part of their own switch. |
| 370 | */ |
Vivien Didelot | f070464 | 2017-11-06 16:11:44 -0500 | [diff] [blame] | 371 | static int dsa_tree_setup_default_cpu(struct dsa_switch_tree *dst) |
| 372 | { |
Vivien Didelot | da4561c | 2019-10-21 16:51:24 -0400 | [diff] [blame] | 373 | struct dsa_port *cpu_dp, *dp; |
Vivien Didelot | f070464 | 2017-11-06 16:11:44 -0500 | [diff] [blame] | 374 | |
Vivien Didelot | da4561c | 2019-10-21 16:51:24 -0400 | [diff] [blame] | 375 | cpu_dp = dsa_tree_find_first_cpu(dst); |
| 376 | if (!cpu_dp) { |
| 377 | pr_err("DSA: tree %d has no CPU port\n", dst->index); |
Vivien Didelot | f070464 | 2017-11-06 16:11:44 -0500 | [diff] [blame] | 378 | return -EINVAL; |
| 379 | } |
| 380 | |
Vladimir Oltean | 2c0b032 | 2021-08-04 16:54:30 +0300 | [diff] [blame] | 381 | list_for_each_entry(dp, &dst->ports, list) { |
| 382 | if (dp->cpu_dp) |
| 383 | continue; |
| 384 | |
Vivien Didelot | da4561c | 2019-10-21 16:51:24 -0400 | [diff] [blame] | 385 | if (dsa_port_is_user(dp) || dsa_port_is_dsa(dp)) |
| 386 | dp->cpu_dp = cpu_dp; |
Vladimir Oltean | 2c0b032 | 2021-08-04 16:54:30 +0300 | [diff] [blame] | 387 | } |
Vivien Didelot | f070464 | 2017-11-06 16:11:44 -0500 | [diff] [blame] | 388 | |
| 389 | return 0; |
| 390 | } |
| 391 | |
Vladimir Oltean | 2c0b032 | 2021-08-04 16:54:30 +0300 | [diff] [blame] | 392 | /* Perform initial assignment of CPU ports to user ports and DSA links in the |
| 393 | * fabric, giving preference to CPU ports local to each switch. Default to |
| 394 | * using the first CPU port in the switch tree if the port does not have a CPU |
| 395 | * port local to this switch. |
| 396 | */ |
| 397 | static int dsa_tree_setup_cpu_ports(struct dsa_switch_tree *dst) |
| 398 | { |
| 399 | struct dsa_port *cpu_dp, *dp; |
| 400 | |
| 401 | list_for_each_entry(cpu_dp, &dst->ports, list) { |
| 402 | if (!dsa_port_is_cpu(cpu_dp)) |
| 403 | continue; |
| 404 | |
Vladimir Oltean | 65c563a | 2021-10-20 20:49:51 +0300 | [diff] [blame] | 405 | /* Prefer a local CPU port */ |
| 406 | dsa_switch_for_each_port(dp, cpu_dp->ds) { |
Vladimir Oltean | 2c0b032 | 2021-08-04 16:54:30 +0300 | [diff] [blame] | 407 | /* Prefer the first local CPU port found */ |
| 408 | if (dp->cpu_dp) |
| 409 | continue; |
| 410 | |
| 411 | if (dsa_port_is_user(dp) || dsa_port_is_dsa(dp)) |
| 412 | dp->cpu_dp = cpu_dp; |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | return dsa_tree_setup_default_cpu(dst); |
| 417 | } |
| 418 | |
Vladimir Oltean | 0e8eb9a | 2021-08-04 16:54:29 +0300 | [diff] [blame] | 419 | static void dsa_tree_teardown_cpu_ports(struct dsa_switch_tree *dst) |
Vivien Didelot | f070464 | 2017-11-06 16:11:44 -0500 | [diff] [blame] | 420 | { |
Vivien Didelot | da4561c | 2019-10-21 16:51:24 -0400 | [diff] [blame] | 421 | struct dsa_port *dp; |
| 422 | |
| 423 | list_for_each_entry(dp, &dst->ports, list) |
| 424 | if (dsa_port_is_user(dp) || dsa_port_is_dsa(dp)) |
| 425 | dp->cpu_dp = NULL; |
Vivien Didelot | f070464 | 2017-11-06 16:11:44 -0500 | [diff] [blame] | 426 | } |
| 427 | |
Vivien Didelot | 1d27732 | 2017-11-06 16:11:48 -0500 | [diff] [blame] | 428 | static int dsa_port_setup(struct dsa_port *dp) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 429 | { |
Vivien Didelot | 955222c | 2019-08-19 16:00:48 -0400 | [diff] [blame] | 430 | struct devlink_port *dlp = &dp->devlink_port; |
Vladimir Oltean | 4ba0ebb | 2019-08-31 15:46:19 +0300 | [diff] [blame] | 431 | bool dsa_port_link_registered = false; |
Vladimir Oltean | fd292c1 | 2021-09-17 17:29:16 +0300 | [diff] [blame] | 432 | struct dsa_switch *ds = dp->ds; |
Vladimir Oltean | 4ba0ebb | 2019-08-31 15:46:19 +0300 | [diff] [blame] | 433 | bool dsa_port_enabled = false; |
| 434 | int err = 0; |
Andrew Lunn | 96567d5 | 2017-03-28 23:45:07 +0200 | [diff] [blame] | 435 | |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 436 | if (dp->setup) |
| 437 | return 0; |
| 438 | |
Vladimir Oltean | 338a3a47 | 2021-10-24 20:17:54 +0300 | [diff] [blame] | 439 | mutex_init(&dp->addr_lists_lock); |
Vladimir Oltean | 3f6e32f | 2021-06-29 17:06:52 +0300 | [diff] [blame] | 440 | INIT_LIST_HEAD(&dp->fdbs); |
Vladimir Oltean | 161ca59 | 2021-06-29 17:06:50 +0300 | [diff] [blame] | 441 | INIT_LIST_HEAD(&dp->mdbs); |
| 442 | |
Vladimir Oltean | fd292c1 | 2021-09-17 17:29:16 +0300 | [diff] [blame] | 443 | if (ds->ops->port_setup) { |
| 444 | err = ds->ops->port_setup(ds, dp->index); |
| 445 | if (err) |
| 446 | return err; |
| 447 | } |
| 448 | |
Vivien Didelot | 1d27732 | 2017-11-06 16:11:48 -0500 | [diff] [blame] | 449 | switch (dp->type) { |
| 450 | case DSA_PORT_TYPE_UNUSED: |
Vivien Didelot | 0394a63 | 2019-08-19 16:00:50 -0400 | [diff] [blame] | 451 | dsa_port_disable(dp); |
Vivien Didelot | 1d27732 | 2017-11-06 16:11:48 -0500 | [diff] [blame] | 452 | break; |
| 453 | case DSA_PORT_TYPE_CPU: |
Jiri Pirko | da07739 | 2018-05-18 09:29:03 +0200 | [diff] [blame] | 454 | err = dsa_port_link_register_of(dp); |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 455 | if (err) |
Vladimir Oltean | 4ba0ebb | 2019-08-31 15:46:19 +0300 | [diff] [blame] | 456 | break; |
| 457 | dsa_port_link_registered = true; |
Vivien Didelot | 0394a63 | 2019-08-19 16:00:50 -0400 | [diff] [blame] | 458 | |
| 459 | err = dsa_port_enable(dp, NULL); |
| 460 | if (err) |
Vladimir Oltean | 4ba0ebb | 2019-08-31 15:46:19 +0300 | [diff] [blame] | 461 | break; |
| 462 | dsa_port_enabled = true; |
| 463 | |
Jiri Pirko | da07739 | 2018-05-18 09:29:03 +0200 | [diff] [blame] | 464 | break; |
Vivien Didelot | 1d27732 | 2017-11-06 16:11:48 -0500 | [diff] [blame] | 465 | case DSA_PORT_TYPE_DSA: |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 466 | err = dsa_port_link_register_of(dp); |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 467 | if (err) |
Vladimir Oltean | 4ba0ebb | 2019-08-31 15:46:19 +0300 | [diff] [blame] | 468 | break; |
| 469 | dsa_port_link_registered = true; |
Vivien Didelot | 0394a63 | 2019-08-19 16:00:50 -0400 | [diff] [blame] | 470 | |
| 471 | err = dsa_port_enable(dp, NULL); |
| 472 | if (err) |
Vladimir Oltean | 4ba0ebb | 2019-08-31 15:46:19 +0300 | [diff] [blame] | 473 | break; |
| 474 | dsa_port_enabled = true; |
| 475 | |
Vivien Didelot | 1d27732 | 2017-11-06 16:11:48 -0500 | [diff] [blame] | 476 | break; |
| 477 | case DSA_PORT_TYPE_USER: |
Michael Walle | 83216e3 | 2021-04-12 19:47:17 +0200 | [diff] [blame] | 478 | of_get_mac_address(dp->dn, dp->mac); |
Vivien Didelot | 1d27732 | 2017-11-06 16:11:48 -0500 | [diff] [blame] | 479 | err = dsa_slave_create(dp); |
| 480 | if (err) |
Vladimir Oltean | 4ba0ebb | 2019-08-31 15:46:19 +0300 | [diff] [blame] | 481 | break; |
Vivien Didelot | 955222c | 2019-08-19 16:00:48 -0400 | [diff] [blame] | 482 | |
| 483 | devlink_port_type_eth_set(dlp, dp->slave); |
Vivien Didelot | 1d27732 | 2017-11-06 16:11:48 -0500 | [diff] [blame] | 484 | break; |
| 485 | } |
Andrew Lunn | 96567d5 | 2017-03-28 23:45:07 +0200 | [diff] [blame] | 486 | |
Vladimir Oltean | 4ba0ebb | 2019-08-31 15:46:19 +0300 | [diff] [blame] | 487 | if (err && dsa_port_enabled) |
| 488 | dsa_port_disable(dp); |
| 489 | if (err && dsa_port_link_registered) |
| 490 | dsa_port_link_unregister_of(dp); |
Vladimir Oltean | fd292c1 | 2021-09-17 17:29:16 +0300 | [diff] [blame] | 491 | if (err) { |
| 492 | if (ds->ops->port_teardown) |
| 493 | ds->ops->port_teardown(ds, dp->index); |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 494 | return err; |
Vladimir Oltean | fd292c1 | 2021-09-17 17:29:16 +0300 | [diff] [blame] | 495 | } |
Vladimir Oltean | 4ba0ebb | 2019-08-31 15:46:19 +0300 | [diff] [blame] | 496 | |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 497 | dp->setup = true; |
| 498 | |
| 499 | return 0; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 500 | } |
| 501 | |
Andrew Lunn | 3122433 | 2020-10-04 18:12:53 +0200 | [diff] [blame] | 502 | static int dsa_port_devlink_setup(struct dsa_port *dp) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 503 | { |
Vivien Didelot | 955222c | 2019-08-19 16:00:48 -0400 | [diff] [blame] | 504 | struct devlink_port *dlp = &dp->devlink_port; |
Andrew Lunn | 3122433 | 2020-10-04 18:12:53 +0200 | [diff] [blame] | 505 | struct dsa_switch_tree *dst = dp->ds->dst; |
| 506 | struct devlink_port_attrs attrs = {}; |
| 507 | struct devlink *dl = dp->ds->devlink; |
| 508 | const unsigned char *id; |
| 509 | unsigned char len; |
| 510 | int err; |
Vivien Didelot | 1d27732 | 2017-11-06 16:11:48 -0500 | [diff] [blame] | 511 | |
Andrew Lunn | 3122433 | 2020-10-04 18:12:53 +0200 | [diff] [blame] | 512 | id = (const unsigned char *)&dst->index; |
| 513 | len = sizeof(dst->index); |
| 514 | |
| 515 | attrs.phys.port_number = dp->index; |
| 516 | memcpy(attrs.switch_id.id, id, len); |
| 517 | attrs.switch_id.id_len = len; |
| 518 | memset(dlp, 0, sizeof(*dlp)); |
| 519 | |
| 520 | switch (dp->type) { |
| 521 | case DSA_PORT_TYPE_UNUSED: |
| 522 | attrs.flavour = DEVLINK_PORT_FLAVOUR_UNUSED; |
| 523 | break; |
| 524 | case DSA_PORT_TYPE_CPU: |
| 525 | attrs.flavour = DEVLINK_PORT_FLAVOUR_CPU; |
| 526 | break; |
| 527 | case DSA_PORT_TYPE_DSA: |
| 528 | attrs.flavour = DEVLINK_PORT_FLAVOUR_DSA; |
| 529 | break; |
| 530 | case DSA_PORT_TYPE_USER: |
| 531 | attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL; |
| 532 | break; |
| 533 | } |
| 534 | |
| 535 | devlink_port_attrs_set(dlp, &attrs); |
| 536 | err = devlink_port_register(dl, dlp, dp->index); |
| 537 | |
| 538 | if (!err) |
| 539 | dp->devlink_port_setup = true; |
| 540 | |
| 541 | return err; |
| 542 | } |
| 543 | |
| 544 | static void dsa_port_teardown(struct dsa_port *dp) |
| 545 | { |
Vladimir Oltean | 91158e1 | 2021-01-12 02:48:31 +0200 | [diff] [blame] | 546 | struct devlink_port *dlp = &dp->devlink_port; |
Vladimir Oltean | fd292c1 | 2021-09-17 17:29:16 +0300 | [diff] [blame] | 547 | struct dsa_switch *ds = dp->ds; |
Vladimir Oltean | 161ca59 | 2021-06-29 17:06:50 +0300 | [diff] [blame] | 548 | struct dsa_mac_addr *a, *tmp; |
Vladimir Oltean | 91158e1 | 2021-01-12 02:48:31 +0200 | [diff] [blame] | 549 | |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 550 | if (!dp->setup) |
| 551 | return; |
| 552 | |
Vladimir Oltean | fd292c1 | 2021-09-17 17:29:16 +0300 | [diff] [blame] | 553 | if (ds->ops->port_teardown) |
| 554 | ds->ops->port_teardown(ds, dp->index); |
| 555 | |
Vladimir Oltean | 91158e1 | 2021-01-12 02:48:31 +0200 | [diff] [blame] | 556 | devlink_port_type_clear(dlp); |
| 557 | |
Vivien Didelot | 1d27732 | 2017-11-06 16:11:48 -0500 | [diff] [blame] | 558 | switch (dp->type) { |
| 559 | case DSA_PORT_TYPE_UNUSED: |
| 560 | break; |
| 561 | case DSA_PORT_TYPE_CPU: |
Vivien Didelot | 0394a63 | 2019-08-19 16:00:50 -0400 | [diff] [blame] | 562 | dsa_port_disable(dp); |
Vivien Didelot | 955222c | 2019-08-19 16:00:48 -0400 | [diff] [blame] | 563 | dsa_port_link_unregister_of(dp); |
| 564 | break; |
Vivien Didelot | 1d27732 | 2017-11-06 16:11:48 -0500 | [diff] [blame] | 565 | case DSA_PORT_TYPE_DSA: |
Vivien Didelot | 0394a63 | 2019-08-19 16:00:50 -0400 | [diff] [blame] | 566 | dsa_port_disable(dp); |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 567 | dsa_port_link_unregister_of(dp); |
Vivien Didelot | 1d27732 | 2017-11-06 16:11:48 -0500 | [diff] [blame] | 568 | break; |
| 569 | case DSA_PORT_TYPE_USER: |
| 570 | if (dp->slave) { |
| 571 | dsa_slave_destroy(dp->slave); |
| 572 | dp->slave = NULL; |
| 573 | } |
| 574 | break; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 575 | } |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 576 | |
Vladimir Oltean | 3f6e32f | 2021-06-29 17:06:52 +0300 | [diff] [blame] | 577 | list_for_each_entry_safe(a, tmp, &dp->fdbs, list) { |
| 578 | list_del(&a->list); |
| 579 | kfree(a); |
| 580 | } |
| 581 | |
Vladimir Oltean | 161ca59 | 2021-06-29 17:06:50 +0300 | [diff] [blame] | 582 | list_for_each_entry_safe(a, tmp, &dp->mdbs, list) { |
| 583 | list_del(&a->list); |
| 584 | kfree(a); |
| 585 | } |
| 586 | |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 587 | dp->setup = false; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 588 | } |
| 589 | |
Andrew Lunn | 3122433 | 2020-10-04 18:12:53 +0200 | [diff] [blame] | 590 | static void dsa_port_devlink_teardown(struct dsa_port *dp) |
| 591 | { |
| 592 | struct devlink_port *dlp = &dp->devlink_port; |
| 593 | |
| 594 | if (dp->devlink_port_setup) |
| 595 | devlink_port_unregister(dlp); |
| 596 | dp->devlink_port_setup = false; |
| 597 | } |
| 598 | |
Vladimir Oltean | fd292c1 | 2021-09-17 17:29:16 +0300 | [diff] [blame] | 599 | /* Destroy the current devlink port, and create a new one which has the UNUSED |
| 600 | * flavour. At this point, any call to ds->ops->port_setup has been already |
| 601 | * balanced out by a call to ds->ops->port_teardown, so we know that any |
| 602 | * devlink port regions the driver had are now unregistered. We then call its |
| 603 | * ds->ops->port_setup again, in order for the driver to re-create them on the |
| 604 | * new devlink port. |
| 605 | */ |
| 606 | static int dsa_port_reinit_as_unused(struct dsa_port *dp) |
| 607 | { |
| 608 | struct dsa_switch *ds = dp->ds; |
| 609 | int err; |
| 610 | |
| 611 | dsa_port_devlink_teardown(dp); |
| 612 | dp->type = DSA_PORT_TYPE_UNUSED; |
| 613 | err = dsa_port_devlink_setup(dp); |
| 614 | if (err) |
| 615 | return err; |
| 616 | |
| 617 | if (ds->ops->port_setup) { |
| 618 | /* On error, leave the devlink port registered, |
| 619 | * dsa_switch_teardown will clean it up later. |
| 620 | */ |
| 621 | err = ds->ops->port_setup(ds, dp->index); |
| 622 | if (err) |
| 623 | return err; |
| 624 | } |
| 625 | |
| 626 | return 0; |
| 627 | } |
| 628 | |
Andrew Lunn | 0f06b85 | 2020-09-18 21:11:08 +0200 | [diff] [blame] | 629 | static int dsa_devlink_info_get(struct devlink *dl, |
| 630 | struct devlink_info_req *req, |
| 631 | struct netlink_ext_ack *extack) |
| 632 | { |
| 633 | struct dsa_switch *ds = dsa_devlink_to_ds(dl); |
| 634 | |
| 635 | if (ds->ops->devlink_info_get) |
| 636 | return ds->ops->devlink_info_get(ds, req, extack); |
| 637 | |
| 638 | return -EOPNOTSUPP; |
| 639 | } |
| 640 | |
Vladimir Oltean | 2a6ef76 | 2021-01-15 04:11:13 +0200 | [diff] [blame] | 641 | static int dsa_devlink_sb_pool_get(struct devlink *dl, |
| 642 | unsigned int sb_index, u16 pool_index, |
| 643 | struct devlink_sb_pool_info *pool_info) |
| 644 | { |
| 645 | struct dsa_switch *ds = dsa_devlink_to_ds(dl); |
| 646 | |
| 647 | if (!ds->ops->devlink_sb_pool_get) |
| 648 | return -EOPNOTSUPP; |
| 649 | |
| 650 | return ds->ops->devlink_sb_pool_get(ds, sb_index, pool_index, |
| 651 | pool_info); |
| 652 | } |
| 653 | |
| 654 | static int dsa_devlink_sb_pool_set(struct devlink *dl, unsigned int sb_index, |
| 655 | u16 pool_index, u32 size, |
| 656 | enum devlink_sb_threshold_type threshold_type, |
| 657 | struct netlink_ext_ack *extack) |
| 658 | { |
| 659 | struct dsa_switch *ds = dsa_devlink_to_ds(dl); |
| 660 | |
| 661 | if (!ds->ops->devlink_sb_pool_set) |
| 662 | return -EOPNOTSUPP; |
| 663 | |
| 664 | return ds->ops->devlink_sb_pool_set(ds, sb_index, pool_index, size, |
| 665 | threshold_type, extack); |
| 666 | } |
| 667 | |
| 668 | static int dsa_devlink_sb_port_pool_get(struct devlink_port *dlp, |
| 669 | unsigned int sb_index, u16 pool_index, |
| 670 | u32 *p_threshold) |
| 671 | { |
| 672 | struct dsa_switch *ds = dsa_devlink_port_to_ds(dlp); |
| 673 | int port = dsa_devlink_port_to_port(dlp); |
| 674 | |
| 675 | if (!ds->ops->devlink_sb_port_pool_get) |
| 676 | return -EOPNOTSUPP; |
| 677 | |
| 678 | return ds->ops->devlink_sb_port_pool_get(ds, port, sb_index, |
| 679 | pool_index, p_threshold); |
| 680 | } |
| 681 | |
| 682 | static int dsa_devlink_sb_port_pool_set(struct devlink_port *dlp, |
| 683 | unsigned int sb_index, u16 pool_index, |
| 684 | u32 threshold, |
| 685 | struct netlink_ext_ack *extack) |
| 686 | { |
| 687 | struct dsa_switch *ds = dsa_devlink_port_to_ds(dlp); |
| 688 | int port = dsa_devlink_port_to_port(dlp); |
| 689 | |
| 690 | if (!ds->ops->devlink_sb_port_pool_set) |
| 691 | return -EOPNOTSUPP; |
| 692 | |
| 693 | return ds->ops->devlink_sb_port_pool_set(ds, port, sb_index, |
| 694 | pool_index, threshold, extack); |
| 695 | } |
| 696 | |
| 697 | static int |
| 698 | dsa_devlink_sb_tc_pool_bind_get(struct devlink_port *dlp, |
| 699 | unsigned int sb_index, u16 tc_index, |
| 700 | enum devlink_sb_pool_type pool_type, |
| 701 | u16 *p_pool_index, u32 *p_threshold) |
| 702 | { |
| 703 | struct dsa_switch *ds = dsa_devlink_port_to_ds(dlp); |
| 704 | int port = dsa_devlink_port_to_port(dlp); |
| 705 | |
| 706 | if (!ds->ops->devlink_sb_tc_pool_bind_get) |
| 707 | return -EOPNOTSUPP; |
| 708 | |
| 709 | return ds->ops->devlink_sb_tc_pool_bind_get(ds, port, sb_index, |
| 710 | tc_index, pool_type, |
| 711 | p_pool_index, p_threshold); |
| 712 | } |
| 713 | |
| 714 | static int |
| 715 | dsa_devlink_sb_tc_pool_bind_set(struct devlink_port *dlp, |
| 716 | unsigned int sb_index, u16 tc_index, |
| 717 | enum devlink_sb_pool_type pool_type, |
| 718 | u16 pool_index, u32 threshold, |
| 719 | struct netlink_ext_ack *extack) |
| 720 | { |
| 721 | struct dsa_switch *ds = dsa_devlink_port_to_ds(dlp); |
| 722 | int port = dsa_devlink_port_to_port(dlp); |
| 723 | |
| 724 | if (!ds->ops->devlink_sb_tc_pool_bind_set) |
| 725 | return -EOPNOTSUPP; |
| 726 | |
| 727 | return ds->ops->devlink_sb_tc_pool_bind_set(ds, port, sb_index, |
| 728 | tc_index, pool_type, |
| 729 | pool_index, threshold, |
| 730 | extack); |
| 731 | } |
| 732 | |
| 733 | static int dsa_devlink_sb_occ_snapshot(struct devlink *dl, |
| 734 | unsigned int sb_index) |
| 735 | { |
| 736 | struct dsa_switch *ds = dsa_devlink_to_ds(dl); |
| 737 | |
| 738 | if (!ds->ops->devlink_sb_occ_snapshot) |
| 739 | return -EOPNOTSUPP; |
| 740 | |
| 741 | return ds->ops->devlink_sb_occ_snapshot(ds, sb_index); |
| 742 | } |
| 743 | |
| 744 | static int dsa_devlink_sb_occ_max_clear(struct devlink *dl, |
| 745 | unsigned int sb_index) |
| 746 | { |
| 747 | struct dsa_switch *ds = dsa_devlink_to_ds(dl); |
| 748 | |
| 749 | if (!ds->ops->devlink_sb_occ_max_clear) |
| 750 | return -EOPNOTSUPP; |
| 751 | |
| 752 | return ds->ops->devlink_sb_occ_max_clear(ds, sb_index); |
| 753 | } |
| 754 | |
| 755 | static int dsa_devlink_sb_occ_port_pool_get(struct devlink_port *dlp, |
| 756 | unsigned int sb_index, |
| 757 | u16 pool_index, u32 *p_cur, |
| 758 | u32 *p_max) |
| 759 | { |
| 760 | struct dsa_switch *ds = dsa_devlink_port_to_ds(dlp); |
| 761 | int port = dsa_devlink_port_to_port(dlp); |
| 762 | |
| 763 | if (!ds->ops->devlink_sb_occ_port_pool_get) |
| 764 | return -EOPNOTSUPP; |
| 765 | |
| 766 | return ds->ops->devlink_sb_occ_port_pool_get(ds, port, sb_index, |
| 767 | pool_index, p_cur, p_max); |
| 768 | } |
| 769 | |
| 770 | static int |
| 771 | dsa_devlink_sb_occ_tc_port_bind_get(struct devlink_port *dlp, |
| 772 | unsigned int sb_index, u16 tc_index, |
| 773 | enum devlink_sb_pool_type pool_type, |
| 774 | u32 *p_cur, u32 *p_max) |
| 775 | { |
| 776 | struct dsa_switch *ds = dsa_devlink_port_to_ds(dlp); |
| 777 | int port = dsa_devlink_port_to_port(dlp); |
| 778 | |
| 779 | if (!ds->ops->devlink_sb_occ_tc_port_bind_get) |
| 780 | return -EOPNOTSUPP; |
| 781 | |
| 782 | return ds->ops->devlink_sb_occ_tc_port_bind_get(ds, port, |
| 783 | sb_index, tc_index, |
| 784 | pool_type, p_cur, |
| 785 | p_max); |
| 786 | } |
| 787 | |
Andrew Lunn | 0f06b85 | 2020-09-18 21:11:08 +0200 | [diff] [blame] | 788 | static const struct devlink_ops dsa_devlink_ops = { |
Vladimir Oltean | 2a6ef76 | 2021-01-15 04:11:13 +0200 | [diff] [blame] | 789 | .info_get = dsa_devlink_info_get, |
| 790 | .sb_pool_get = dsa_devlink_sb_pool_get, |
| 791 | .sb_pool_set = dsa_devlink_sb_pool_set, |
| 792 | .sb_port_pool_get = dsa_devlink_sb_port_pool_get, |
| 793 | .sb_port_pool_set = dsa_devlink_sb_port_pool_set, |
| 794 | .sb_tc_pool_bind_get = dsa_devlink_sb_tc_pool_bind_get, |
| 795 | .sb_tc_pool_bind_set = dsa_devlink_sb_tc_pool_bind_set, |
| 796 | .sb_occ_snapshot = dsa_devlink_sb_occ_snapshot, |
| 797 | .sb_occ_max_clear = dsa_devlink_sb_occ_max_clear, |
| 798 | .sb_occ_port_pool_get = dsa_devlink_sb_occ_port_pool_get, |
| 799 | .sb_occ_tc_port_bind_get = dsa_devlink_sb_occ_tc_port_bind_get, |
Andrew Lunn | 0f06b85 | 2020-09-18 21:11:08 +0200 | [diff] [blame] | 800 | }; |
| 801 | |
Tobias Waldekranz | deff710 | 2021-04-20 20:53:10 +0200 | [diff] [blame] | 802 | static int dsa_switch_setup_tag_protocol(struct dsa_switch *ds) |
| 803 | { |
| 804 | const struct dsa_device_ops *tag_ops = ds->dst->tag_ops; |
| 805 | struct dsa_switch_tree *dst = ds->dst; |
Vladimir Oltean | d0004a0 | 2021-10-20 20:49:50 +0300 | [diff] [blame] | 806 | struct dsa_port *cpu_dp; |
| 807 | int err; |
Tobias Waldekranz | deff710 | 2021-04-20 20:53:10 +0200 | [diff] [blame] | 808 | |
| 809 | if (tag_ops->proto == dst->default_proto) |
| 810 | return 0; |
| 811 | |
Vladimir Oltean | d0004a0 | 2021-10-20 20:49:50 +0300 | [diff] [blame] | 812 | dsa_switch_for_each_cpu_port(cpu_dp, ds) { |
Vladimir Oltean | 1951b3f | 2021-10-09 15:26:07 +0300 | [diff] [blame] | 813 | rtnl_lock(); |
Vladimir Oltean | d0004a0 | 2021-10-20 20:49:50 +0300 | [diff] [blame] | 814 | err = ds->ops->change_tag_protocol(ds, cpu_dp->index, |
| 815 | tag_ops->proto); |
Vladimir Oltean | 1951b3f | 2021-10-09 15:26:07 +0300 | [diff] [blame] | 816 | rtnl_unlock(); |
Tobias Waldekranz | deff710 | 2021-04-20 20:53:10 +0200 | [diff] [blame] | 817 | if (err) { |
| 818 | dev_err(ds->dev, "Unable to use tag protocol \"%s\": %pe\n", |
| 819 | tag_ops->name, ERR_PTR(err)); |
| 820 | return err; |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | return 0; |
| 825 | } |
| 826 | |
Vivien Didelot | 1f08f9e | 2017-11-06 16:11:47 -0500 | [diff] [blame] | 827 | static int dsa_switch_setup(struct dsa_switch *ds) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 828 | { |
Andrew Lunn | 6b29752 | 2019-10-25 01:03:51 +0200 | [diff] [blame] | 829 | struct dsa_devlink_priv *dl_priv; |
Andrew Lunn | 3122433 | 2020-10-04 18:12:53 +0200 | [diff] [blame] | 830 | struct dsa_port *dp; |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 831 | int err; |
| 832 | |
| 833 | if (ds->setup) |
| 834 | return 0; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 835 | |
Florian Fainelli | 6e830d8 | 2016-06-07 16:32:39 -0700 | [diff] [blame] | 836 | /* Initialize ds->phys_mii_mask before registering the slave MDIO bus |
Vivien Didelot | 9d490b4 | 2016-08-23 12:38:56 -0400 | [diff] [blame] | 837 | * driver and before ops->setup() has run, since the switch drivers and |
Florian Fainelli | 6e830d8 | 2016-06-07 16:32:39 -0700 | [diff] [blame] | 838 | * the slave MDIO bus driver rely on these values for probing PHY |
| 839 | * devices or not |
| 840 | */ |
Vivien Didelot | 02bc6e5 | 2017-10-26 11:22:56 -0400 | [diff] [blame] | 841 | ds->phys_mii_mask |= dsa_user_ports(ds); |
Florian Fainelli | 6e830d8 | 2016-06-07 16:32:39 -0700 | [diff] [blame] | 842 | |
Andrew Lunn | 96567d5 | 2017-03-28 23:45:07 +0200 | [diff] [blame] | 843 | /* Add the switch to devlink before calling setup, so that setup can |
| 844 | * add dpipe tables |
| 845 | */ |
Leon Romanovsky | 919d13a | 2021-08-08 21:57:43 +0300 | [diff] [blame] | 846 | ds->devlink = |
| 847 | devlink_alloc(&dsa_devlink_ops, sizeof(*dl_priv), ds->dev); |
Andrew Lunn | 96567d5 | 2017-03-28 23:45:07 +0200 | [diff] [blame] | 848 | if (!ds->devlink) |
| 849 | return -ENOMEM; |
Andrew Lunn | 6b29752 | 2019-10-25 01:03:51 +0200 | [diff] [blame] | 850 | dl_priv = devlink_priv(ds->devlink); |
| 851 | dl_priv->ds = ds; |
Andrew Lunn | 96567d5 | 2017-03-28 23:45:07 +0200 | [diff] [blame] | 852 | |
Andrew Lunn | 3122433 | 2020-10-04 18:12:53 +0200 | [diff] [blame] | 853 | /* Setup devlink port instances now, so that the switch |
| 854 | * setup() can register regions etc, against the ports |
| 855 | */ |
Vladimir Oltean | 65c563a | 2021-10-20 20:49:51 +0300 | [diff] [blame] | 856 | dsa_switch_for_each_port(dp, ds) { |
| 857 | err = dsa_port_devlink_setup(dp); |
| 858 | if (err) |
| 859 | goto unregister_devlink_ports; |
Andrew Lunn | 3122433 | 2020-10-04 18:12:53 +0200 | [diff] [blame] | 860 | } |
| 861 | |
Vivien Didelot | f515f19 | 2017-02-03 13:20:20 -0500 | [diff] [blame] | 862 | err = dsa_switch_register_notifier(ds); |
| 863 | if (err) |
Andrew Lunn | 3122433 | 2020-10-04 18:12:53 +0200 | [diff] [blame] | 864 | goto unregister_devlink_ports; |
Vivien Didelot | f515f19 | 2017-02-03 13:20:20 -0500 | [diff] [blame] | 865 | |
Vladimir Oltean | 0ee2af4 | 2021-01-16 01:19:19 +0200 | [diff] [blame] | 866 | ds->configure_vlan_while_not_filtering = true; |
| 867 | |
Vladimir Oltean | b2243b3 | 2019-05-05 13:19:20 +0300 | [diff] [blame] | 868 | err = ds->ops->setup(ds); |
| 869 | if (err < 0) |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 870 | goto unregister_notifier; |
Vladimir Oltean | b2243b3 | 2019-05-05 13:19:20 +0300 | [diff] [blame] | 871 | |
Tobias Waldekranz | deff710 | 2021-04-20 20:53:10 +0200 | [diff] [blame] | 872 | err = dsa_switch_setup_tag_protocol(ds); |
| 873 | if (err) |
| 874 | goto teardown; |
| 875 | |
Vivien Didelot | 9d490b4 | 2016-08-23 12:38:56 -0400 | [diff] [blame] | 876 | if (!ds->slave_mii_bus && ds->ops->phy_read) { |
Vladimir Oltean | 5135e96 | 2021-09-21 00:42:08 +0300 | [diff] [blame] | 877 | ds->slave_mii_bus = mdiobus_alloc(); |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 878 | if (!ds->slave_mii_bus) { |
| 879 | err = -ENOMEM; |
Vladimir Oltean | 8fd54a7 | 2021-02-04 18:33:51 +0200 | [diff] [blame] | 880 | goto teardown; |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 881 | } |
Florian Fainelli | 1eb5944 | 2016-06-07 16:32:40 -0700 | [diff] [blame] | 882 | |
| 883 | dsa_slave_mii_bus_init(ds); |
| 884 | |
| 885 | err = mdiobus_register(ds->slave_mii_bus); |
| 886 | if (err < 0) |
Vladimir Oltean | 5135e96 | 2021-09-21 00:42:08 +0300 | [diff] [blame] | 887 | goto free_slave_mii_bus; |
Florian Fainelli | 1eb5944 | 2016-06-07 16:32:40 -0700 | [diff] [blame] | 888 | } |
| 889 | |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 890 | ds->setup = true; |
Leon Romanovsky | bd936bd | 2021-09-25 14:23:01 +0300 | [diff] [blame] | 891 | devlink_register(ds->devlink); |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 892 | return 0; |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 893 | |
Vladimir Oltean | 5135e96 | 2021-09-21 00:42:08 +0300 | [diff] [blame] | 894 | free_slave_mii_bus: |
| 895 | if (ds->slave_mii_bus && ds->ops->phy_read) |
| 896 | mdiobus_free(ds->slave_mii_bus); |
Vladimir Oltean | 8fd54a7 | 2021-02-04 18:33:51 +0200 | [diff] [blame] | 897 | teardown: |
| 898 | if (ds->ops->teardown) |
| 899 | ds->ops->teardown(ds); |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 900 | unregister_notifier: |
| 901 | dsa_switch_unregister_notifier(ds); |
Andrew Lunn | 3122433 | 2020-10-04 18:12:53 +0200 | [diff] [blame] | 902 | unregister_devlink_ports: |
Vladimir Oltean | 65c563a | 2021-10-20 20:49:51 +0300 | [diff] [blame] | 903 | dsa_switch_for_each_port(dp, ds) |
| 904 | dsa_port_devlink_teardown(dp); |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 905 | devlink_free(ds->devlink); |
| 906 | ds->devlink = NULL; |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 907 | return err; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 908 | } |
| 909 | |
Vivien Didelot | 1f08f9e | 2017-11-06 16:11:47 -0500 | [diff] [blame] | 910 | static void dsa_switch_teardown(struct dsa_switch *ds) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 911 | { |
Andrew Lunn | 3122433 | 2020-10-04 18:12:53 +0200 | [diff] [blame] | 912 | struct dsa_port *dp; |
| 913 | |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 914 | if (!ds->setup) |
| 915 | return; |
| 916 | |
Leon Romanovsky | bd936bd | 2021-09-25 14:23:01 +0300 | [diff] [blame] | 917 | if (ds->devlink) |
| 918 | devlink_unregister(ds->devlink); |
| 919 | |
Vladimir Oltean | 5135e96 | 2021-09-21 00:42:08 +0300 | [diff] [blame] | 920 | if (ds->slave_mii_bus && ds->ops->phy_read) { |
Florian Fainelli | 1eb5944 | 2016-06-07 16:32:40 -0700 | [diff] [blame] | 921 | mdiobus_unregister(ds->slave_mii_bus); |
Vladimir Oltean | 5135e96 | 2021-09-21 00:42:08 +0300 | [diff] [blame] | 922 | mdiobus_free(ds->slave_mii_bus); |
| 923 | ds->slave_mii_bus = NULL; |
| 924 | } |
Vivien Didelot | f515f19 | 2017-02-03 13:20:20 -0500 | [diff] [blame] | 925 | |
Vladimir Oltean | 5e3f847 | 2019-06-08 15:04:28 +0300 | [diff] [blame] | 926 | if (ds->ops->teardown) |
| 927 | ds->ops->teardown(ds); |
| 928 | |
Vladimir Oltean | 39e222b | 2021-10-12 15:37:35 +0300 | [diff] [blame] | 929 | dsa_switch_unregister_notifier(ds); |
| 930 | |
Andrew Lunn | 96567d5 | 2017-03-28 23:45:07 +0200 | [diff] [blame] | 931 | if (ds->devlink) { |
Vladimir Oltean | 65c563a | 2021-10-20 20:49:51 +0300 | [diff] [blame] | 932 | dsa_switch_for_each_port(dp, ds) |
| 933 | dsa_port_devlink_teardown(dp); |
Andrew Lunn | 96567d5 | 2017-03-28 23:45:07 +0200 | [diff] [blame] | 934 | devlink_free(ds->devlink); |
| 935 | ds->devlink = NULL; |
| 936 | } |
| 937 | |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 938 | ds->setup = false; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 939 | } |
| 940 | |
Vladimir Oltean | a57d8c21 | 2021-09-14 16:47:26 +0300 | [diff] [blame] | 941 | /* First tear down the non-shared, then the shared ports. This ensures that |
| 942 | * all work items scheduled by our switchdev handlers for user ports have |
| 943 | * completed before we destroy the refcounting kept on the shared ports. |
| 944 | */ |
| 945 | static void dsa_tree_teardown_ports(struct dsa_switch_tree *dst) |
| 946 | { |
| 947 | struct dsa_port *dp; |
| 948 | |
| 949 | list_for_each_entry(dp, &dst->ports, list) |
| 950 | if (dsa_port_is_user(dp) || dsa_port_is_unused(dp)) |
| 951 | dsa_port_teardown(dp); |
| 952 | |
| 953 | dsa_flush_workqueue(); |
| 954 | |
| 955 | list_for_each_entry(dp, &dst->ports, list) |
| 956 | if (dsa_port_is_dsa(dp) || dsa_port_is_cpu(dp)) |
| 957 | dsa_port_teardown(dp); |
| 958 | } |
| 959 | |
| 960 | static void dsa_tree_teardown_switches(struct dsa_switch_tree *dst) |
| 961 | { |
| 962 | struct dsa_port *dp; |
| 963 | |
| 964 | list_for_each_entry(dp, &dst->ports, list) |
| 965 | dsa_switch_teardown(dp->ds); |
| 966 | } |
| 967 | |
Vivien Didelot | 1f08f9e | 2017-11-06 16:11:47 -0500 | [diff] [blame] | 968 | static int dsa_tree_setup_switches(struct dsa_switch_tree *dst) |
| 969 | { |
Vivien Didelot | 1d27732 | 2017-11-06 16:11:48 -0500 | [diff] [blame] | 970 | struct dsa_port *dp; |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 971 | int err; |
Vivien Didelot | 1f08f9e | 2017-11-06 16:11:47 -0500 | [diff] [blame] | 972 | |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 973 | list_for_each_entry(dp, &dst->ports, list) { |
| 974 | err = dsa_switch_setup(dp->ds); |
Vivien Didelot | 1f08f9e | 2017-11-06 16:11:47 -0500 | [diff] [blame] | 975 | if (err) |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 976 | goto teardown; |
| 977 | } |
Vivien Didelot | 1d27732 | 2017-11-06 16:11:48 -0500 | [diff] [blame] | 978 | |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 979 | list_for_each_entry(dp, &dst->ports, list) { |
| 980 | err = dsa_port_setup(dp); |
Maxim Kochetkov | fb6ec87 | 2021-03-29 18:30:16 +0300 | [diff] [blame] | 981 | if (err) { |
Vladimir Oltean | fd292c1 | 2021-09-17 17:29:16 +0300 | [diff] [blame] | 982 | err = dsa_port_reinit_as_unused(dp); |
Maxim Kochetkov | fb6ec87 | 2021-03-29 18:30:16 +0300 | [diff] [blame] | 983 | if (err) |
| 984 | goto teardown; |
Maxim Kochetkov | fb6ec87 | 2021-03-29 18:30:16 +0300 | [diff] [blame] | 985 | } |
Vivien Didelot | 1f08f9e | 2017-11-06 16:11:47 -0500 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | return 0; |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 989 | |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 990 | teardown: |
Vladimir Oltean | a57d8c21 | 2021-09-14 16:47:26 +0300 | [diff] [blame] | 991 | dsa_tree_teardown_ports(dst); |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 992 | |
Vladimir Oltean | a57d8c21 | 2021-09-14 16:47:26 +0300 | [diff] [blame] | 993 | dsa_tree_teardown_switches(dst); |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 994 | |
| 995 | return err; |
Vivien Didelot | 1f08f9e | 2017-11-06 16:11:47 -0500 | [diff] [blame] | 996 | } |
| 997 | |
Vivien Didelot | 17a22fc | 2017-11-06 16:11:45 -0500 | [diff] [blame] | 998 | static int dsa_tree_setup_master(struct dsa_switch_tree *dst) |
| 999 | { |
Vivien Didelot | 0cfec58 | 2019-10-21 16:51:22 -0400 | [diff] [blame] | 1000 | struct dsa_port *dp; |
| 1001 | int err; |
Vivien Didelot | 17a22fc | 2017-11-06 16:11:45 -0500 | [diff] [blame] | 1002 | |
Vivien Didelot | 0cfec58 | 2019-10-21 16:51:22 -0400 | [diff] [blame] | 1003 | list_for_each_entry(dp, &dst->ports, list) { |
| 1004 | if (dsa_port_is_cpu(dp)) { |
| 1005 | err = dsa_master_setup(dp->master, dp); |
| 1006 | if (err) |
| 1007 | return err; |
| 1008 | } |
| 1009 | } |
| 1010 | |
| 1011 | return 0; |
Vivien Didelot | 17a22fc | 2017-11-06 16:11:45 -0500 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | static void dsa_tree_teardown_master(struct dsa_switch_tree *dst) |
| 1015 | { |
Vivien Didelot | 0cfec58 | 2019-10-21 16:51:22 -0400 | [diff] [blame] | 1016 | struct dsa_port *dp; |
Vivien Didelot | 17a22fc | 2017-11-06 16:11:45 -0500 | [diff] [blame] | 1017 | |
Vivien Didelot | 0cfec58 | 2019-10-21 16:51:22 -0400 | [diff] [blame] | 1018 | list_for_each_entry(dp, &dst->ports, list) |
| 1019 | if (dsa_port_is_cpu(dp)) |
| 1020 | dsa_master_teardown(dp->master); |
Vivien Didelot | 17a22fc | 2017-11-06 16:11:45 -0500 | [diff] [blame] | 1021 | } |
| 1022 | |
Tobias Waldekranz | 058102a | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 1023 | static int dsa_tree_setup_lags(struct dsa_switch_tree *dst) |
| 1024 | { |
| 1025 | unsigned int len = 0; |
| 1026 | struct dsa_port *dp; |
| 1027 | |
| 1028 | list_for_each_entry(dp, &dst->ports, list) { |
| 1029 | if (dp->ds->num_lag_ids > len) |
| 1030 | len = dp->ds->num_lag_ids; |
| 1031 | } |
| 1032 | |
| 1033 | if (!len) |
| 1034 | return 0; |
| 1035 | |
| 1036 | dst->lags = kcalloc(len, sizeof(*dst->lags), GFP_KERNEL); |
| 1037 | if (!dst->lags) |
| 1038 | return -ENOMEM; |
| 1039 | |
| 1040 | dst->lags_len = len; |
| 1041 | return 0; |
| 1042 | } |
| 1043 | |
| 1044 | static void dsa_tree_teardown_lags(struct dsa_switch_tree *dst) |
| 1045 | { |
| 1046 | kfree(dst->lags); |
| 1047 | } |
| 1048 | |
Vivien Didelot | ec15dd4 | 2017-11-06 16:11:46 -0500 | [diff] [blame] | 1049 | static int dsa_tree_setup(struct dsa_switch_tree *dst) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 1050 | { |
Vivien Didelot | 34c09a8 | 2017-11-06 16:11:51 -0500 | [diff] [blame] | 1051 | bool complete; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 1052 | int err; |
| 1053 | |
Vivien Didelot | ec15dd4 | 2017-11-06 16:11:46 -0500 | [diff] [blame] | 1054 | if (dst->setup) { |
| 1055 | pr_err("DSA: tree %d already setup! Disjoint trees?\n", |
| 1056 | dst->index); |
| 1057 | return -EEXIST; |
| 1058 | } |
| 1059 | |
Vivien Didelot | 34c09a8 | 2017-11-06 16:11:51 -0500 | [diff] [blame] | 1060 | complete = dsa_tree_setup_routing_table(dst); |
| 1061 | if (!complete) |
| 1062 | return 0; |
| 1063 | |
Vladimir Oltean | 2c0b032 | 2021-08-04 16:54:30 +0300 | [diff] [blame] | 1064 | err = dsa_tree_setup_cpu_ports(dst); |
Vivien Didelot | f070464 | 2017-11-06 16:11:44 -0500 | [diff] [blame] | 1065 | if (err) |
| 1066 | return err; |
| 1067 | |
Vivien Didelot | 1f08f9e | 2017-11-06 16:11:47 -0500 | [diff] [blame] | 1068 | err = dsa_tree_setup_switches(dst); |
| 1069 | if (err) |
Vladimir Oltean | 0e8eb9a | 2021-08-04 16:54:29 +0300 | [diff] [blame] | 1070 | goto teardown_cpu_ports; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 1071 | |
Vivien Didelot | 17a22fc | 2017-11-06 16:11:45 -0500 | [diff] [blame] | 1072 | err = dsa_tree_setup_master(dst); |
Vivien Didelot | 1943563 | 2017-09-19 11:56:59 -0400 | [diff] [blame] | 1073 | if (err) |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 1074 | goto teardown_switches; |
Vivien Didelot | 1943563 | 2017-09-19 11:56:59 -0400 | [diff] [blame] | 1075 | |
Tobias Waldekranz | 058102a | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 1076 | err = dsa_tree_setup_lags(dst); |
| 1077 | if (err) |
| 1078 | goto teardown_master; |
| 1079 | |
Vivien Didelot | ec15dd4 | 2017-11-06 16:11:46 -0500 | [diff] [blame] | 1080 | dst->setup = true; |
| 1081 | |
| 1082 | pr_info("DSA: tree %d setup\n", dst->index); |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 1083 | |
| 1084 | return 0; |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 1085 | |
Tobias Waldekranz | 058102a | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 1086 | teardown_master: |
| 1087 | dsa_tree_teardown_master(dst); |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 1088 | teardown_switches: |
Vladimir Oltean | e5845aa | 2021-09-21 01:49:18 +0300 | [diff] [blame] | 1089 | dsa_tree_teardown_ports(dst); |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 1090 | dsa_tree_teardown_switches(dst); |
Vladimir Oltean | 0e8eb9a | 2021-08-04 16:54:29 +0300 | [diff] [blame] | 1091 | teardown_cpu_ports: |
| 1092 | dsa_tree_teardown_cpu_ports(dst); |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 1093 | |
| 1094 | return err; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 1095 | } |
| 1096 | |
Vivien Didelot | ec15dd4 | 2017-11-06 16:11:46 -0500 | [diff] [blame] | 1097 | static void dsa_tree_teardown(struct dsa_switch_tree *dst) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 1098 | { |
Vivien Didelot | c5f5176 | 2019-10-30 22:09:13 -0400 | [diff] [blame] | 1099 | struct dsa_link *dl, *next; |
| 1100 | |
Vivien Didelot | ec15dd4 | 2017-11-06 16:11:46 -0500 | [diff] [blame] | 1101 | if (!dst->setup) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 1102 | return; |
| 1103 | |
Tobias Waldekranz | 058102a | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 1104 | dsa_tree_teardown_lags(dst); |
| 1105 | |
Vivien Didelot | 17a22fc | 2017-11-06 16:11:45 -0500 | [diff] [blame] | 1106 | dsa_tree_teardown_master(dst); |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 1107 | |
Vladimir Oltean | a57d8c21 | 2021-09-14 16:47:26 +0300 | [diff] [blame] | 1108 | dsa_tree_teardown_ports(dst); |
| 1109 | |
Vivien Didelot | 1f08f9e | 2017-11-06 16:11:47 -0500 | [diff] [blame] | 1110 | dsa_tree_teardown_switches(dst); |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 1111 | |
Vladimir Oltean | 0e8eb9a | 2021-08-04 16:54:29 +0300 | [diff] [blame] | 1112 | dsa_tree_teardown_cpu_ports(dst); |
Florian Fainelli | 0c73c52 | 2016-06-07 16:32:42 -0700 | [diff] [blame] | 1113 | |
Vivien Didelot | c5f5176 | 2019-10-30 22:09:13 -0400 | [diff] [blame] | 1114 | list_for_each_entry_safe(dl, next, &dst->rtable, list) { |
| 1115 | list_del(&dl->list); |
| 1116 | kfree(dl); |
| 1117 | } |
| 1118 | |
Vivien Didelot | ec15dd4 | 2017-11-06 16:11:46 -0500 | [diff] [blame] | 1119 | pr_info("DSA: tree %d torn down\n", dst->index); |
| 1120 | |
| 1121 | dst->setup = false; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 1122 | } |
| 1123 | |
Vladimir Oltean | 53da0eb | 2021-01-29 03:00:06 +0200 | [diff] [blame] | 1124 | /* Since the dsa/tagging sysfs device attribute is per master, the assumption |
| 1125 | * is that all DSA switches within a tree share the same tagger, otherwise |
| 1126 | * they would have formed disjoint trees (different "dsa,member" values). |
| 1127 | */ |
| 1128 | int dsa_tree_change_tag_proto(struct dsa_switch_tree *dst, |
| 1129 | struct net_device *master, |
| 1130 | const struct dsa_device_ops *tag_ops, |
| 1131 | const struct dsa_device_ops *old_tag_ops) |
| 1132 | { |
| 1133 | struct dsa_notifier_tag_proto_info info; |
| 1134 | struct dsa_port *dp; |
| 1135 | int err = -EBUSY; |
| 1136 | |
| 1137 | if (!rtnl_trylock()) |
| 1138 | return restart_syscall(); |
| 1139 | |
| 1140 | /* At the moment we don't allow changing the tag protocol under |
| 1141 | * traffic. The rtnl_mutex also happens to serialize concurrent |
| 1142 | * attempts to change the tagging protocol. If we ever lift the IFF_UP |
| 1143 | * restriction, there needs to be another mutex which serializes this. |
| 1144 | */ |
| 1145 | if (master->flags & IFF_UP) |
| 1146 | goto out_unlock; |
| 1147 | |
| 1148 | list_for_each_entry(dp, &dst->ports, list) { |
Vladimir Oltean | d0004a0 | 2021-10-20 20:49:50 +0300 | [diff] [blame] | 1149 | if (!dsa_port_is_user(dp)) |
Vladimir Oltean | 53da0eb | 2021-01-29 03:00:06 +0200 | [diff] [blame] | 1150 | continue; |
| 1151 | |
| 1152 | if (dp->slave->flags & IFF_UP) |
| 1153 | goto out_unlock; |
| 1154 | } |
| 1155 | |
| 1156 | info.tag_ops = tag_ops; |
| 1157 | err = dsa_tree_notify(dst, DSA_NOTIFIER_TAG_PROTO, &info); |
| 1158 | if (err) |
| 1159 | goto out_unwind_tagger; |
| 1160 | |
| 1161 | dst->tag_ops = tag_ops; |
| 1162 | |
| 1163 | rtnl_unlock(); |
| 1164 | |
| 1165 | return 0; |
| 1166 | |
| 1167 | out_unwind_tagger: |
| 1168 | info.tag_ops = old_tag_ops; |
| 1169 | dsa_tree_notify(dst, DSA_NOTIFIER_TAG_PROTO, &info); |
| 1170 | out_unlock: |
| 1171 | rtnl_unlock(); |
| 1172 | return err; |
| 1173 | } |
| 1174 | |
Vivien Didelot | ab8ccae | 2019-10-21 16:51:16 -0400 | [diff] [blame] | 1175 | static struct dsa_port *dsa_port_touch(struct dsa_switch *ds, int index) |
| 1176 | { |
| 1177 | struct dsa_switch_tree *dst = ds->dst; |
| 1178 | struct dsa_port *dp; |
| 1179 | |
Vladimir Oltean | 65c563a | 2021-10-20 20:49:51 +0300 | [diff] [blame] | 1180 | dsa_switch_for_each_port(dp, ds) |
| 1181 | if (dp->index == index) |
Vivien Didelot | 05f294a | 2019-10-21 16:51:29 -0400 | [diff] [blame] | 1182 | return dp; |
| 1183 | |
| 1184 | dp = kzalloc(sizeof(*dp), GFP_KERNEL); |
| 1185 | if (!dp) |
| 1186 | return NULL; |
Vivien Didelot | ab8ccae | 2019-10-21 16:51:16 -0400 | [diff] [blame] | 1187 | |
| 1188 | dp->ds = ds; |
| 1189 | dp->index = index; |
| 1190 | |
| 1191 | INIT_LIST_HEAD(&dp->list); |
| 1192 | list_add_tail(&dp->list, &dst->ports); |
| 1193 | |
| 1194 | return dp; |
| 1195 | } |
| 1196 | |
Vivien Didelot | 06e24d0 | 2017-11-03 19:05:29 -0400 | [diff] [blame] | 1197 | static int dsa_port_parse_user(struct dsa_port *dp, const char *name) |
| 1198 | { |
| 1199 | if (!name) |
| 1200 | name = "eth%d"; |
| 1201 | |
| 1202 | dp->type = DSA_PORT_TYPE_USER; |
| 1203 | dp->name = name; |
| 1204 | |
| 1205 | return 0; |
| 1206 | } |
| 1207 | |
| 1208 | static int dsa_port_parse_dsa(struct dsa_port *dp) |
| 1209 | { |
| 1210 | dp->type = DSA_PORT_TYPE_DSA; |
| 1211 | |
| 1212 | return 0; |
| 1213 | } |
| 1214 | |
Florian Fainelli | 4d77648 | 2020-01-07 21:06:05 -0800 | [diff] [blame] | 1215 | static enum dsa_tag_protocol dsa_get_tag_protocol(struct dsa_port *dp, |
| 1216 | struct net_device *master) |
| 1217 | { |
| 1218 | enum dsa_tag_protocol tag_protocol = DSA_TAG_PROTO_NONE; |
| 1219 | struct dsa_switch *mds, *ds = dp->ds; |
| 1220 | unsigned int mdp_upstream; |
| 1221 | struct dsa_port *mdp; |
| 1222 | |
| 1223 | /* It is possible to stack DSA switches onto one another when that |
| 1224 | * happens the switch driver may want to know if its tagging protocol |
| 1225 | * is going to work in such a configuration. |
| 1226 | */ |
| 1227 | if (dsa_slave_dev_check(master)) { |
| 1228 | mdp = dsa_slave_to_port(master); |
| 1229 | mds = mdp->ds; |
| 1230 | mdp_upstream = dsa_upstream_port(mds, mdp->index); |
| 1231 | tag_protocol = mds->ops->get_tag_protocol(mds, mdp_upstream, |
| 1232 | DSA_TAG_PROTO_NONE); |
| 1233 | } |
| 1234 | |
| 1235 | /* If the master device is not itself a DSA slave in a disjoint DSA |
| 1236 | * tree, then return immediately. |
| 1237 | */ |
| 1238 | return ds->ops->get_tag_protocol(ds, dp->index, tag_protocol); |
| 1239 | } |
| 1240 | |
Tobias Waldekranz | deff710 | 2021-04-20 20:53:10 +0200 | [diff] [blame] | 1241 | static int dsa_port_parse_cpu(struct dsa_port *dp, struct net_device *master, |
| 1242 | const char *user_protocol) |
Vivien Didelot | 06e24d0 | 2017-11-03 19:05:29 -0400 | [diff] [blame] | 1243 | { |
Vivien Didelot | 7354fcb | 2017-11-03 19:05:30 -0400 | [diff] [blame] | 1244 | struct dsa_switch *ds = dp->ds; |
| 1245 | struct dsa_switch_tree *dst = ds->dst; |
George McCollister | e0c755a | 2021-03-22 15:26:50 -0500 | [diff] [blame] | 1246 | const struct dsa_device_ops *tag_ops; |
Tobias Waldekranz | deff710 | 2021-04-20 20:53:10 +0200 | [diff] [blame] | 1247 | enum dsa_tag_protocol default_proto; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 1248 | |
Tobias Waldekranz | deff710 | 2021-04-20 20:53:10 +0200 | [diff] [blame] | 1249 | /* Find out which protocol the switch would prefer. */ |
| 1250 | default_proto = dsa_get_tag_protocol(dp, master); |
| 1251 | if (dst->default_proto) { |
| 1252 | if (dst->default_proto != default_proto) { |
Vladimir Oltean | 357f203 | 2021-01-29 03:00:05 +0200 | [diff] [blame] | 1253 | dev_err(ds->dev, |
| 1254 | "A DSA switch tree can have only one tagging protocol\n"); |
| 1255 | return -EINVAL; |
| 1256 | } |
Vladimir Oltean | 357f203 | 2021-01-29 03:00:05 +0200 | [diff] [blame] | 1257 | } else { |
Tobias Waldekranz | deff710 | 2021-04-20 20:53:10 +0200 | [diff] [blame] | 1258 | dst->default_proto = default_proto; |
| 1259 | } |
| 1260 | |
| 1261 | /* See if the user wants to override that preference. */ |
| 1262 | if (user_protocol) { |
| 1263 | if (!ds->ops->change_tag_protocol) { |
| 1264 | dev_err(ds->dev, "Tag protocol cannot be modified\n"); |
| 1265 | return -EINVAL; |
Vladimir Oltean | 357f203 | 2021-01-29 03:00:05 +0200 | [diff] [blame] | 1266 | } |
George McCollister | e0c755a | 2021-03-22 15:26:50 -0500 | [diff] [blame] | 1267 | |
Tobias Waldekranz | deff710 | 2021-04-20 20:53:10 +0200 | [diff] [blame] | 1268 | tag_ops = dsa_find_tagger_by_name(user_protocol); |
| 1269 | } else { |
| 1270 | tag_ops = dsa_tag_driver_get(default_proto); |
| 1271 | } |
| 1272 | |
| 1273 | if (IS_ERR(tag_ops)) { |
| 1274 | if (PTR_ERR(tag_ops) == -ENOPROTOOPT) |
| 1275 | return -EPROBE_DEFER; |
| 1276 | |
| 1277 | dev_warn(ds->dev, "No tagger for this switch\n"); |
| 1278 | return PTR_ERR(tag_ops); |
| 1279 | } |
| 1280 | |
| 1281 | if (dst->tag_ops) { |
| 1282 | if (dst->tag_ops != tag_ops) { |
| 1283 | dev_err(ds->dev, |
| 1284 | "A DSA switch tree can have only one tagging protocol\n"); |
| 1285 | |
| 1286 | dsa_tag_driver_put(tag_ops); |
| 1287 | return -EINVAL; |
| 1288 | } |
| 1289 | |
| 1290 | /* In the case of multiple CPU ports per switch, the tagging |
| 1291 | * protocol is still reference-counted only per switch tree. |
| 1292 | */ |
| 1293 | dsa_tag_driver_put(tag_ops); |
| 1294 | } else { |
George McCollister | e0c755a | 2021-03-22 15:26:50 -0500 | [diff] [blame] | 1295 | dst->tag_ops = tag_ops; |
Florian Fainelli | 9f9e772 | 2017-07-24 10:49:23 -0700 | [diff] [blame] | 1296 | } |
| 1297 | |
Florian Fainelli | 4d77648 | 2020-01-07 21:06:05 -0800 | [diff] [blame] | 1298 | dp->master = master; |
Vivien Didelot | 7354fcb | 2017-11-03 19:05:30 -0400 | [diff] [blame] | 1299 | dp->type = DSA_PORT_TYPE_CPU; |
Vladimir Oltean | 53da0eb | 2021-01-29 03:00:06 +0200 | [diff] [blame] | 1300 | dsa_port_set_tag_protocol(dp, dst->tag_ops); |
Vivien Didelot | 7354fcb | 2017-11-03 19:05:30 -0400 | [diff] [blame] | 1301 | dp->dst = dst; |
Vivien Didelot | 3e41f93 | 2017-09-29 17:19:19 -0400 | [diff] [blame] | 1302 | |
Tobias Waldekranz | deff710 | 2021-04-20 20:53:10 +0200 | [diff] [blame] | 1303 | /* At this point, the tree may be configured to use a different |
| 1304 | * tagger than the one chosen by the switch driver during |
| 1305 | * .setup, in the case when a user selects a custom protocol |
| 1306 | * through the DT. |
| 1307 | * |
| 1308 | * This is resolved by syncing the driver with the tree in |
| 1309 | * dsa_switch_setup_tag_protocol once .setup has run and the |
| 1310 | * driver is ready to accept calls to .change_tag_protocol. If |
| 1311 | * the driver does not support the custom protocol at that |
| 1312 | * point, the tree is wholly rejected, thereby ensuring that the |
| 1313 | * tree and driver are always in agreement on the protocol to |
| 1314 | * use. |
| 1315 | */ |
Vivien Didelot | 7354fcb | 2017-11-03 19:05:30 -0400 | [diff] [blame] | 1316 | return 0; |
| 1317 | } |
| 1318 | |
Vivien Didelot | fd223e2 | 2017-10-27 15:55:14 -0400 | [diff] [blame] | 1319 | static int dsa_port_parse_of(struct dsa_port *dp, struct device_node *dn) |
| 1320 | { |
Vivien Didelot | 6d4e5c5 | 2017-10-27 15:55:15 -0400 | [diff] [blame] | 1321 | struct device_node *ethernet = of_parse_phandle(dn, "ethernet", 0); |
Vivien Didelot | 1838fa8 | 2017-10-27 15:55:18 -0400 | [diff] [blame] | 1322 | const char *name = of_get_property(dn, "label", NULL); |
Vivien Didelot | 54df6fa | 2017-11-03 19:05:28 -0400 | [diff] [blame] | 1323 | bool link = of_property_read_bool(dn, "link"); |
Vivien Didelot | 6d4e5c5 | 2017-10-27 15:55:15 -0400 | [diff] [blame] | 1324 | |
Vivien Didelot | 06e24d0 | 2017-11-03 19:05:29 -0400 | [diff] [blame] | 1325 | dp->dn = dn; |
| 1326 | |
Vivien Didelot | 6d4e5c5 | 2017-10-27 15:55:15 -0400 | [diff] [blame] | 1327 | if (ethernet) { |
Vivien Didelot | cbabb0a | 2017-10-27 15:55:17 -0400 | [diff] [blame] | 1328 | struct net_device *master; |
Tobias Waldekranz | deff710 | 2021-04-20 20:53:10 +0200 | [diff] [blame] | 1329 | const char *user_protocol; |
Vivien Didelot | cbabb0a | 2017-10-27 15:55:17 -0400 | [diff] [blame] | 1330 | |
| 1331 | master = of_find_net_device_by_node(ethernet); |
| 1332 | if (!master) |
| 1333 | return -EPROBE_DEFER; |
| 1334 | |
Tobias Waldekranz | deff710 | 2021-04-20 20:53:10 +0200 | [diff] [blame] | 1335 | user_protocol = of_get_property(dn, "dsa-tag-protocol", NULL); |
| 1336 | return dsa_port_parse_cpu(dp, master, user_protocol); |
Vivien Didelot | 6d4e5c5 | 2017-10-27 15:55:15 -0400 | [diff] [blame] | 1337 | } |
| 1338 | |
Vivien Didelot | 06e24d0 | 2017-11-03 19:05:29 -0400 | [diff] [blame] | 1339 | if (link) |
| 1340 | return dsa_port_parse_dsa(dp); |
Vivien Didelot | fd223e2 | 2017-10-27 15:55:14 -0400 | [diff] [blame] | 1341 | |
Vivien Didelot | 06e24d0 | 2017-11-03 19:05:29 -0400 | [diff] [blame] | 1342 | return dsa_port_parse_user(dp, name); |
Vivien Didelot | fd223e2 | 2017-10-27 15:55:14 -0400 | [diff] [blame] | 1343 | } |
| 1344 | |
Vivien Didelot | 975e6e3 | 2017-11-03 19:05:27 -0400 | [diff] [blame] | 1345 | static int dsa_switch_parse_ports_of(struct dsa_switch *ds, |
| 1346 | struct device_node *dn) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 1347 | { |
Vivien Didelot | 5b32fe0 | 2017-10-27 15:55:13 -0400 | [diff] [blame] | 1348 | struct device_node *ports, *port; |
Vivien Didelot | fd223e2 | 2017-10-27 15:55:14 -0400 | [diff] [blame] | 1349 | struct dsa_port *dp; |
Wen Yang | 9919a36 | 2019-02-25 15:22:19 +0800 | [diff] [blame] | 1350 | int err = 0; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 1351 | u32 reg; |
Vivien Didelot | 5b32fe0 | 2017-10-27 15:55:13 -0400 | [diff] [blame] | 1352 | |
| 1353 | ports = of_get_child_by_name(dn, "ports"); |
| 1354 | if (!ports) { |
Kurt Kanzenbach | 85e05d2 | 2020-07-20 14:49:39 +0200 | [diff] [blame] | 1355 | /* The second possibility is "ethernet-ports" */ |
| 1356 | ports = of_get_child_by_name(dn, "ethernet-ports"); |
| 1357 | if (!ports) { |
| 1358 | dev_err(ds->dev, "no ports child node found\n"); |
| 1359 | return -EINVAL; |
| 1360 | } |
Vivien Didelot | 5b32fe0 | 2017-10-27 15:55:13 -0400 | [diff] [blame] | 1361 | } |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 1362 | |
| 1363 | for_each_available_child_of_node(ports, port) { |
| 1364 | err = of_property_read_u32(port, "reg", ®); |
Christophe JAILLET | ba69fd9 | 2021-10-18 21:59:00 +0200 | [diff] [blame] | 1365 | if (err) { |
| 1366 | of_node_put(port); |
Wen Yang | 9919a36 | 2019-02-25 15:22:19 +0800 | [diff] [blame] | 1367 | goto out_put_node; |
Christophe JAILLET | ba69fd9 | 2021-10-18 21:59:00 +0200 | [diff] [blame] | 1368 | } |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 1369 | |
Wen Yang | 9919a36 | 2019-02-25 15:22:19 +0800 | [diff] [blame] | 1370 | if (reg >= ds->num_ports) { |
Rafał Miłecki | 8209f5b | 2021-01-06 10:09:15 +0100 | [diff] [blame] | 1371 | dev_err(ds->dev, "port %pOF index %u exceeds num_ports (%zu)\n", |
| 1372 | port, reg, ds->num_ports); |
Christophe JAILLET | ba69fd9 | 2021-10-18 21:59:00 +0200 | [diff] [blame] | 1373 | of_node_put(port); |
Wen Yang | 9919a36 | 2019-02-25 15:22:19 +0800 | [diff] [blame] | 1374 | err = -EINVAL; |
| 1375 | goto out_put_node; |
| 1376 | } |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 1377 | |
Vivien Didelot | 68bb8ea | 2019-10-21 16:51:15 -0400 | [diff] [blame] | 1378 | dp = dsa_to_port(ds, reg); |
Vivien Didelot | fd223e2 | 2017-10-27 15:55:14 -0400 | [diff] [blame] | 1379 | |
| 1380 | err = dsa_port_parse_of(dp, port); |
Christophe JAILLET | ba69fd9 | 2021-10-18 21:59:00 +0200 | [diff] [blame] | 1381 | if (err) { |
| 1382 | of_node_put(port); |
Wen Yang | 9919a36 | 2019-02-25 15:22:19 +0800 | [diff] [blame] | 1383 | goto out_put_node; |
Christophe JAILLET | ba69fd9 | 2021-10-18 21:59:00 +0200 | [diff] [blame] | 1384 | } |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 1385 | } |
| 1386 | |
Wen Yang | 9919a36 | 2019-02-25 15:22:19 +0800 | [diff] [blame] | 1387 | out_put_node: |
| 1388 | of_node_put(ports); |
| 1389 | return err; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 1390 | } |
| 1391 | |
Vivien Didelot | 975e6e3 | 2017-11-03 19:05:27 -0400 | [diff] [blame] | 1392 | static int dsa_switch_parse_member_of(struct dsa_switch *ds, |
| 1393 | struct device_node *dn) |
| 1394 | { |
| 1395 | u32 m[2] = { 0, 0 }; |
| 1396 | int sz; |
| 1397 | |
| 1398 | /* Don't error out if this optional property isn't found */ |
| 1399 | sz = of_property_read_variable_u32_array(dn, "dsa,member", m, 2, 2); |
| 1400 | if (sz < 0 && sz != -EINVAL) |
| 1401 | return sz; |
| 1402 | |
| 1403 | ds->index = m[1]; |
Vivien Didelot | 975e6e3 | 2017-11-03 19:05:27 -0400 | [diff] [blame] | 1404 | |
| 1405 | ds->dst = dsa_tree_touch(m[0]); |
| 1406 | if (!ds->dst) |
| 1407 | return -ENOMEM; |
| 1408 | |
Vladimir Oltean | 8674f8d | 2021-06-21 19:42:14 +0300 | [diff] [blame] | 1409 | if (dsa_switch_find(ds->dst->index, ds->index)) { |
| 1410 | dev_err(ds->dev, |
| 1411 | "A DSA switch with index %d already exists in tree %d\n", |
| 1412 | ds->index, ds->dst->index); |
| 1413 | return -EEXIST; |
| 1414 | } |
| 1415 | |
Vladimir Oltean | 5b22d36 | 2021-07-22 18:55:39 +0300 | [diff] [blame] | 1416 | if (ds->dst->last_switch < ds->index) |
| 1417 | ds->dst->last_switch = ds->index; |
| 1418 | |
Vivien Didelot | 975e6e3 | 2017-11-03 19:05:27 -0400 | [diff] [blame] | 1419 | return 0; |
| 1420 | } |
| 1421 | |
Vivien Didelot | ab8ccae | 2019-10-21 16:51:16 -0400 | [diff] [blame] | 1422 | static int dsa_switch_touch_ports(struct dsa_switch *ds) |
| 1423 | { |
| 1424 | struct dsa_port *dp; |
| 1425 | int port; |
| 1426 | |
| 1427 | for (port = 0; port < ds->num_ports; port++) { |
| 1428 | dp = dsa_port_touch(ds, port); |
| 1429 | if (!dp) |
| 1430 | return -ENOMEM; |
| 1431 | } |
| 1432 | |
| 1433 | return 0; |
| 1434 | } |
| 1435 | |
Vivien Didelot | 975e6e3 | 2017-11-03 19:05:27 -0400 | [diff] [blame] | 1436 | static int dsa_switch_parse_of(struct dsa_switch *ds, struct device_node *dn) |
| 1437 | { |
| 1438 | int err; |
| 1439 | |
| 1440 | err = dsa_switch_parse_member_of(ds, dn); |
| 1441 | if (err) |
| 1442 | return err; |
| 1443 | |
Vivien Didelot | ab8ccae | 2019-10-21 16:51:16 -0400 | [diff] [blame] | 1444 | err = dsa_switch_touch_ports(ds); |
| 1445 | if (err) |
| 1446 | return err; |
| 1447 | |
Vivien Didelot | 975e6e3 | 2017-11-03 19:05:27 -0400 | [diff] [blame] | 1448 | return dsa_switch_parse_ports_of(ds, dn); |
| 1449 | } |
| 1450 | |
Vivien Didelot | fd223e2 | 2017-10-27 15:55:14 -0400 | [diff] [blame] | 1451 | static int dsa_port_parse(struct dsa_port *dp, const char *name, |
| 1452 | struct device *dev) |
| 1453 | { |
Vivien Didelot | 6d4e5c5 | 2017-10-27 15:55:15 -0400 | [diff] [blame] | 1454 | if (!strcmp(name, "cpu")) { |
Vivien Didelot | cbabb0a | 2017-10-27 15:55:17 -0400 | [diff] [blame] | 1455 | struct net_device *master; |
| 1456 | |
| 1457 | master = dsa_dev_to_net_device(dev); |
| 1458 | if (!master) |
| 1459 | return -EPROBE_DEFER; |
| 1460 | |
| 1461 | dev_put(master); |
| 1462 | |
Tobias Waldekranz | deff710 | 2021-04-20 20:53:10 +0200 | [diff] [blame] | 1463 | return dsa_port_parse_cpu(dp, master, NULL); |
Vivien Didelot | 6d4e5c5 | 2017-10-27 15:55:15 -0400 | [diff] [blame] | 1464 | } |
| 1465 | |
Vivien Didelot | 06e24d0 | 2017-11-03 19:05:29 -0400 | [diff] [blame] | 1466 | if (!strcmp(name, "dsa")) |
| 1467 | return dsa_port_parse_dsa(dp); |
Vivien Didelot | fd223e2 | 2017-10-27 15:55:14 -0400 | [diff] [blame] | 1468 | |
Vivien Didelot | 06e24d0 | 2017-11-03 19:05:29 -0400 | [diff] [blame] | 1469 | return dsa_port_parse_user(dp, name); |
Vivien Didelot | fd223e2 | 2017-10-27 15:55:14 -0400 | [diff] [blame] | 1470 | } |
| 1471 | |
Vivien Didelot | 975e6e3 | 2017-11-03 19:05:27 -0400 | [diff] [blame] | 1472 | static int dsa_switch_parse_ports(struct dsa_switch *ds, |
| 1473 | struct dsa_chip_data *cd) |
Florian Fainelli | 71e0bbd | 2017-02-04 13:02:43 -0800 | [diff] [blame] | 1474 | { |
| 1475 | bool valid_name_found = false; |
Vivien Didelot | fd223e2 | 2017-10-27 15:55:14 -0400 | [diff] [blame] | 1476 | struct dsa_port *dp; |
| 1477 | struct device *dev; |
| 1478 | const char *name; |
Florian Fainelli | 71e0bbd | 2017-02-04 13:02:43 -0800 | [diff] [blame] | 1479 | unsigned int i; |
Vivien Didelot | fd223e2 | 2017-10-27 15:55:14 -0400 | [diff] [blame] | 1480 | int err; |
Florian Fainelli | 71e0bbd | 2017-02-04 13:02:43 -0800 | [diff] [blame] | 1481 | |
| 1482 | for (i = 0; i < DSA_MAX_PORTS; i++) { |
Vivien Didelot | fd223e2 | 2017-10-27 15:55:14 -0400 | [diff] [blame] | 1483 | name = cd->port_names[i]; |
| 1484 | dev = cd->netdev[i]; |
Vivien Didelot | 68bb8ea | 2019-10-21 16:51:15 -0400 | [diff] [blame] | 1485 | dp = dsa_to_port(ds, i); |
Vivien Didelot | fd223e2 | 2017-10-27 15:55:14 -0400 | [diff] [blame] | 1486 | |
| 1487 | if (!name) |
Florian Fainelli | 71e0bbd | 2017-02-04 13:02:43 -0800 | [diff] [blame] | 1488 | continue; |
| 1489 | |
Vivien Didelot | fd223e2 | 2017-10-27 15:55:14 -0400 | [diff] [blame] | 1490 | err = dsa_port_parse(dp, name, dev); |
| 1491 | if (err) |
| 1492 | return err; |
| 1493 | |
Florian Fainelli | 71e0bbd | 2017-02-04 13:02:43 -0800 | [diff] [blame] | 1494 | valid_name_found = true; |
| 1495 | } |
| 1496 | |
| 1497 | if (!valid_name_found && i == DSA_MAX_PORTS) |
| 1498 | return -EINVAL; |
| 1499 | |
| 1500 | return 0; |
| 1501 | } |
| 1502 | |
Vivien Didelot | 975e6e3 | 2017-11-03 19:05:27 -0400 | [diff] [blame] | 1503 | static int dsa_switch_parse(struct dsa_switch *ds, struct dsa_chip_data *cd) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 1504 | { |
Vivien Didelot | ab8ccae | 2019-10-21 16:51:16 -0400 | [diff] [blame] | 1505 | int err; |
| 1506 | |
Vivien Didelot | 975e6e3 | 2017-11-03 19:05:27 -0400 | [diff] [blame] | 1507 | ds->cd = cd; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 1508 | |
Vivien Didelot | 975e6e3 | 2017-11-03 19:05:27 -0400 | [diff] [blame] | 1509 | /* We don't support interconnected switches nor multiple trees via |
| 1510 | * platform data, so this is the unique switch of the tree. |
| 1511 | */ |
| 1512 | ds->index = 0; |
| 1513 | ds->dst = dsa_tree_touch(0); |
| 1514 | if (!ds->dst) |
| 1515 | return -ENOMEM; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 1516 | |
Vivien Didelot | ab8ccae | 2019-10-21 16:51:16 -0400 | [diff] [blame] | 1517 | err = dsa_switch_touch_ports(ds); |
| 1518 | if (err) |
| 1519 | return err; |
| 1520 | |
Vivien Didelot | 975e6e3 | 2017-11-03 19:05:27 -0400 | [diff] [blame] | 1521 | return dsa_switch_parse_ports(ds, cd); |
Florian Fainelli | 71e0bbd | 2017-02-04 13:02:43 -0800 | [diff] [blame] | 1522 | } |
| 1523 | |
Vladimir Oltean | 6dc43cd | 2020-01-25 23:01:11 +0200 | [diff] [blame] | 1524 | static void dsa_switch_release_ports(struct dsa_switch *ds) |
| 1525 | { |
Vladimir Oltean | 6dc43cd | 2020-01-25 23:01:11 +0200 | [diff] [blame] | 1526 | struct dsa_port *dp, *next; |
| 1527 | |
Vladimir Oltean | 65c563a | 2021-10-20 20:49:51 +0300 | [diff] [blame] | 1528 | dsa_switch_for_each_port_safe(dp, next, ds) { |
Vladimir Oltean | 6dc43cd | 2020-01-25 23:01:11 +0200 | [diff] [blame] | 1529 | list_del(&dp->list); |
| 1530 | kfree(dp); |
| 1531 | } |
| 1532 | } |
| 1533 | |
Vivien Didelot | b4fbb34 | 2017-11-06 16:11:53 -0500 | [diff] [blame] | 1534 | static int dsa_switch_probe(struct dsa_switch *ds) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 1535 | { |
Vivien Didelot | 8e5cb84 | 2019-10-30 22:09:17 -0400 | [diff] [blame] | 1536 | struct dsa_switch_tree *dst; |
Colin Ian King | 556f124 | 2019-10-24 11:32:18 +0100 | [diff] [blame] | 1537 | struct dsa_chip_data *pdata; |
| 1538 | struct device_node *np; |
Vivien Didelot | 34c09a8 | 2017-11-06 16:11:51 -0500 | [diff] [blame] | 1539 | int err; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 1540 | |
Vivien Didelot | 7e99e34 | 2019-10-21 16:51:30 -0400 | [diff] [blame] | 1541 | if (!ds->dev) |
| 1542 | return -ENODEV; |
| 1543 | |
Colin Ian King | 556f124 | 2019-10-24 11:32:18 +0100 | [diff] [blame] | 1544 | pdata = ds->dev->platform_data; |
| 1545 | np = ds->dev->of_node; |
| 1546 | |
Vivien Didelot | 7e99e34 | 2019-10-21 16:51:30 -0400 | [diff] [blame] | 1547 | if (!ds->num_ports) |
| 1548 | return -EINVAL; |
| 1549 | |
Vladimir Oltean | 6dc43cd | 2020-01-25 23:01:11 +0200 | [diff] [blame] | 1550 | if (np) { |
Vivien Didelot | 975e6e3 | 2017-11-03 19:05:27 -0400 | [diff] [blame] | 1551 | err = dsa_switch_parse_of(ds, np); |
Vladimir Oltean | 6dc43cd | 2020-01-25 23:01:11 +0200 | [diff] [blame] | 1552 | if (err) |
| 1553 | dsa_switch_release_ports(ds); |
| 1554 | } else if (pdata) { |
Vivien Didelot | 975e6e3 | 2017-11-03 19:05:27 -0400 | [diff] [blame] | 1555 | err = dsa_switch_parse(ds, pdata); |
Vladimir Oltean | 6dc43cd | 2020-01-25 23:01:11 +0200 | [diff] [blame] | 1556 | if (err) |
| 1557 | dsa_switch_release_ports(ds); |
| 1558 | } else { |
Vivien Didelot | 975e6e3 | 2017-11-03 19:05:27 -0400 | [diff] [blame] | 1559 | err = -ENODEV; |
Vladimir Oltean | 6dc43cd | 2020-01-25 23:01:11 +0200 | [diff] [blame] | 1560 | } |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 1561 | |
Vivien Didelot | 975e6e3 | 2017-11-03 19:05:27 -0400 | [diff] [blame] | 1562 | if (err) |
| 1563 | return err; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 1564 | |
Vivien Didelot | 8e5cb84 | 2019-10-30 22:09:17 -0400 | [diff] [blame] | 1565 | dst = ds->dst; |
| 1566 | dsa_tree_get(dst); |
| 1567 | err = dsa_tree_setup(dst); |
Vladimir Oltean | 6dc43cd | 2020-01-25 23:01:11 +0200 | [diff] [blame] | 1568 | if (err) { |
| 1569 | dsa_switch_release_ports(ds); |
Vivien Didelot | 8e5cb84 | 2019-10-30 22:09:17 -0400 | [diff] [blame] | 1570 | dsa_tree_put(dst); |
Vladimir Oltean | 6dc43cd | 2020-01-25 23:01:11 +0200 | [diff] [blame] | 1571 | } |
Vivien Didelot | 8e5cb84 | 2019-10-30 22:09:17 -0400 | [diff] [blame] | 1572 | |
| 1573 | return err; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 1574 | } |
| 1575 | |
Vivien Didelot | 23c9ee4 | 2017-05-26 18:12:51 -0400 | [diff] [blame] | 1576 | int dsa_register_switch(struct dsa_switch *ds) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 1577 | { |
| 1578 | int err; |
| 1579 | |
| 1580 | mutex_lock(&dsa2_mutex); |
Vivien Didelot | b4fbb34 | 2017-11-06 16:11:53 -0500 | [diff] [blame] | 1581 | err = dsa_switch_probe(ds); |
Vivien Didelot | 9e74104 | 2017-11-24 11:36:06 -0500 | [diff] [blame] | 1582 | dsa_tree_put(ds->dst); |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 1583 | mutex_unlock(&dsa2_mutex); |
| 1584 | |
| 1585 | return err; |
| 1586 | } |
| 1587 | EXPORT_SYMBOL_GPL(dsa_register_switch); |
| 1588 | |
Vivien Didelot | b4fbb34 | 2017-11-06 16:11:53 -0500 | [diff] [blame] | 1589 | static void dsa_switch_remove(struct dsa_switch *ds) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 1590 | { |
| 1591 | struct dsa_switch_tree *dst = ds->dst; |
Vivien Didelot | 05f294a | 2019-10-21 16:51:29 -0400 | [diff] [blame] | 1592 | |
Florian Fainelli | c058f6d | 2019-11-02 20:13:26 -0700 | [diff] [blame] | 1593 | dsa_tree_teardown(dst); |
Vladimir Oltean | 6dc43cd | 2020-01-25 23:01:11 +0200 | [diff] [blame] | 1594 | dsa_switch_release_ports(ds); |
Vivien Didelot | 8e5cb84 | 2019-10-30 22:09:17 -0400 | [diff] [blame] | 1595 | dsa_tree_put(dst); |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 1596 | } |
| 1597 | |
| 1598 | void dsa_unregister_switch(struct dsa_switch *ds) |
| 1599 | { |
| 1600 | mutex_lock(&dsa2_mutex); |
Vivien Didelot | b4fbb34 | 2017-11-06 16:11:53 -0500 | [diff] [blame] | 1601 | dsa_switch_remove(ds); |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 1602 | mutex_unlock(&dsa2_mutex); |
| 1603 | } |
| 1604 | EXPORT_SYMBOL_GPL(dsa_unregister_switch); |
Vladimir Oltean | 0650bf5 | 2021-09-17 16:34:33 +0300 | [diff] [blame] | 1605 | |
| 1606 | /* If the DSA master chooses to unregister its net_device on .shutdown, DSA is |
| 1607 | * blocking that operation from completion, due to the dev_hold taken inside |
| 1608 | * netdev_upper_dev_link. Unlink the DSA slave interfaces from being uppers of |
| 1609 | * the DSA master, so that the system can reboot successfully. |
| 1610 | */ |
| 1611 | void dsa_switch_shutdown(struct dsa_switch *ds) |
| 1612 | { |
| 1613 | struct net_device *master, *slave_dev; |
| 1614 | LIST_HEAD(unregister_list); |
| 1615 | struct dsa_port *dp; |
| 1616 | |
| 1617 | mutex_lock(&dsa2_mutex); |
| 1618 | rtnl_lock(); |
| 1619 | |
Vladimir Oltean | 65c563a | 2021-10-20 20:49:51 +0300 | [diff] [blame] | 1620 | dsa_switch_for_each_user_port(dp, ds) { |
Vladimir Oltean | 0650bf5 | 2021-09-17 16:34:33 +0300 | [diff] [blame] | 1621 | master = dp->cpu_dp->master; |
| 1622 | slave_dev = dp->slave; |
| 1623 | |
| 1624 | netdev_upper_dev_unlink(master, slave_dev); |
| 1625 | /* Just unlinking ourselves as uppers of the master is not |
| 1626 | * sufficient. When the master net device unregisters, that will |
| 1627 | * also call dev_close, which we will catch as NETDEV_GOING_DOWN |
| 1628 | * and trigger a dev_close on our own devices (dsa_slave_close). |
| 1629 | * In turn, that will call dev_mc_unsync on the master's net |
| 1630 | * device. If the master is also a DSA switch port, this will |
| 1631 | * trigger dsa_slave_set_rx_mode which will call dev_mc_sync on |
| 1632 | * its own master. Lockdep will complain about the fact that |
| 1633 | * all cascaded masters have the same dsa_master_addr_list_lock_key, |
| 1634 | * which it normally would not do if the cascaded masters would |
| 1635 | * be in a proper upper/lower relationship, which we've just |
| 1636 | * destroyed. |
| 1637 | * To suppress the lockdep warnings, let's actually unregister |
| 1638 | * the DSA slave interfaces too, to avoid the nonsensical |
| 1639 | * multicast address list synchronization on shutdown. |
| 1640 | */ |
| 1641 | unregister_netdevice_queue(slave_dev, &unregister_list); |
| 1642 | } |
| 1643 | unregister_netdevice_many(&unregister_list); |
| 1644 | |
| 1645 | rtnl_unlock(); |
| 1646 | mutex_unlock(&dsa2_mutex); |
| 1647 | } |
| 1648 | EXPORT_SYMBOL_GPL(dsa_switch_shutdown); |