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 | |
Vivien Didelot | 1ca28ec | 2017-11-03 19:05:24 -0400 | [diff] [blame] | 21 | static LIST_HEAD(dsa_tree_list); |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 22 | static DEFINE_MUTEX(dsa2_mutex); |
| 23 | |
Andrew Lunn | 96567d5 | 2017-03-28 23:45:07 +0200 | [diff] [blame] | 24 | static const struct devlink_ops dsa_devlink_ops = { |
| 25 | }; |
| 26 | |
Vivien Didelot | 1ca28ec | 2017-11-03 19:05:24 -0400 | [diff] [blame] | 27 | static struct dsa_switch_tree *dsa_tree_find(int index) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 28 | { |
| 29 | struct dsa_switch_tree *dst; |
| 30 | |
Vivien Didelot | 1ca28ec | 2017-11-03 19:05:24 -0400 | [diff] [blame] | 31 | list_for_each_entry(dst, &dsa_tree_list, list) |
Vivien Didelot | 8e5bf97 | 2017-11-03 19:05:22 -0400 | [diff] [blame] | 32 | if (dst->index == index) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 33 | return dst; |
Vivien Didelot | 8e5bf97 | 2017-11-03 19:05:22 -0400 | [diff] [blame] | 34 | |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 35 | return NULL; |
| 36 | } |
| 37 | |
Vivien Didelot | 1ca28ec | 2017-11-03 19:05:24 -0400 | [diff] [blame] | 38 | static struct dsa_switch_tree *dsa_tree_alloc(int index) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 39 | { |
| 40 | struct dsa_switch_tree *dst; |
| 41 | |
| 42 | dst = kzalloc(sizeof(*dst), GFP_KERNEL); |
| 43 | if (!dst) |
| 44 | return NULL; |
Vivien Didelot | 1ca28ec | 2017-11-03 19:05:24 -0400 | [diff] [blame] | 45 | |
Vivien Didelot | 49463b7 | 2017-11-03 19:05:21 -0400 | [diff] [blame] | 46 | dst->index = index; |
Vivien Didelot | 1ca28ec | 2017-11-03 19:05:24 -0400 | [diff] [blame] | 47 | |
Vivien Didelot | ab8ccae | 2019-10-21 16:51:16 -0400 | [diff] [blame] | 48 | INIT_LIST_HEAD(&dst->ports); |
| 49 | |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 50 | INIT_LIST_HEAD(&dst->list); |
Vivien Didelot | 50c7d2ba | 2019-10-18 17:02:46 -0400 | [diff] [blame] | 51 | list_add_tail(&dst->list, &dsa_tree_list); |
Vivien Didelot | 8e5bf97 | 2017-11-03 19:05:22 -0400 | [diff] [blame] | 52 | |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 53 | kref_init(&dst->refcount); |
| 54 | |
| 55 | return dst; |
| 56 | } |
| 57 | |
Vivien Didelot | 6525410 | 2017-11-03 19:05:23 -0400 | [diff] [blame] | 58 | static void dsa_tree_free(struct dsa_switch_tree *dst) |
| 59 | { |
| 60 | list_del(&dst->list); |
| 61 | kfree(dst); |
| 62 | } |
| 63 | |
Vivien Didelot | 9e74104 | 2017-11-24 11:36:06 -0500 | [diff] [blame] | 64 | static struct dsa_switch_tree *dsa_tree_get(struct dsa_switch_tree *dst) |
| 65 | { |
| 66 | if (dst) |
| 67 | kref_get(&dst->refcount); |
| 68 | |
| 69 | return dst; |
| 70 | } |
| 71 | |
Vivien Didelot | 1ca28ec | 2017-11-03 19:05:24 -0400 | [diff] [blame] | 72 | static struct dsa_switch_tree *dsa_tree_touch(int index) |
| 73 | { |
| 74 | struct dsa_switch_tree *dst; |
| 75 | |
| 76 | dst = dsa_tree_find(index); |
Vivien Didelot | 9e74104 | 2017-11-24 11:36:06 -0500 | [diff] [blame] | 77 | if (dst) |
| 78 | return dsa_tree_get(dst); |
| 79 | else |
| 80 | return dsa_tree_alloc(index); |
Vivien Didelot | 6525410 | 2017-11-03 19:05:23 -0400 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | static void dsa_tree_release(struct kref *ref) |
| 84 | { |
| 85 | struct dsa_switch_tree *dst; |
| 86 | |
| 87 | dst = container_of(ref, struct dsa_switch_tree, refcount); |
| 88 | |
| 89 | dsa_tree_free(dst); |
| 90 | } |
| 91 | |
| 92 | static void dsa_tree_put(struct dsa_switch_tree *dst) |
| 93 | { |
Vivien Didelot | 9e74104 | 2017-11-24 11:36:06 -0500 | [diff] [blame] | 94 | if (dst) |
| 95 | kref_put(&dst->refcount, dsa_tree_release); |
Vivien Didelot | 6525410 | 2017-11-03 19:05:23 -0400 | [diff] [blame] | 96 | } |
| 97 | |
Florian Fainelli | 293784a | 2017-01-26 10:45:52 -0800 | [diff] [blame] | 98 | static bool dsa_port_is_dsa(struct dsa_port *port) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 99 | { |
Vivien Didelot | 6d4e5c5 | 2017-10-27 15:55:15 -0400 | [diff] [blame] | 100 | return port->type == DSA_PORT_TYPE_DSA; |
Florian Fainelli | 293784a | 2017-01-26 10:45:52 -0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | static bool dsa_port_is_cpu(struct dsa_port *port) |
| 104 | { |
Vivien Didelot | 6d4e5c5 | 2017-10-27 15:55:15 -0400 | [diff] [blame] | 105 | return port->type == DSA_PORT_TYPE_CPU; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 106 | } |
| 107 | |
Vivien Didelot | f070464 | 2017-11-06 16:11:44 -0500 | [diff] [blame] | 108 | static bool dsa_port_is_user(struct dsa_port *dp) |
| 109 | { |
| 110 | return dp->type == DSA_PORT_TYPE_USER; |
| 111 | } |
| 112 | |
Vivien Didelot | f163da8 | 2017-11-06 16:11:49 -0500 | [diff] [blame] | 113 | static struct dsa_port *dsa_tree_find_port_by_node(struct dsa_switch_tree *dst, |
| 114 | struct device_node *dn) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 115 | { |
| 116 | struct dsa_switch *ds; |
Vivien Didelot | f163da8 | 2017-11-06 16:11:49 -0500 | [diff] [blame] | 117 | struct dsa_port *dp; |
| 118 | int device, port; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 119 | |
Vivien Didelot | f163da8 | 2017-11-06 16:11:49 -0500 | [diff] [blame] | 120 | for (device = 0; device < DSA_MAX_SWITCHES; device++) { |
| 121 | ds = dst->ds[device]; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 122 | if (!ds) |
| 123 | continue; |
| 124 | |
Vivien Didelot | f163da8 | 2017-11-06 16:11:49 -0500 | [diff] [blame] | 125 | for (port = 0; port < ds->num_ports; port++) { |
| 126 | dp = &ds->ports[port]; |
| 127 | |
| 128 | if (dp->dn == dn) |
| 129 | return dp; |
| 130 | } |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | return NULL; |
| 134 | } |
| 135 | |
Vivien Didelot | 34c09a8 | 2017-11-06 16:11:51 -0500 | [diff] [blame] | 136 | static bool dsa_port_setup_routing_table(struct dsa_port *dp) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 137 | { |
Vivien Didelot | 34c09a8 | 2017-11-06 16:11:51 -0500 | [diff] [blame] | 138 | struct dsa_switch *ds = dp->ds; |
| 139 | struct dsa_switch_tree *dst = ds->dst; |
| 140 | struct device_node *dn = dp->dn; |
Vivien Didelot | c528666 | 2017-11-06 16:11:50 -0500 | [diff] [blame] | 141 | struct of_phandle_iterator it; |
Vivien Didelot | f163da8 | 2017-11-06 16:11:49 -0500 | [diff] [blame] | 142 | struct dsa_port *link_dp; |
Vivien Didelot | c528666 | 2017-11-06 16:11:50 -0500 | [diff] [blame] | 143 | int err; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 144 | |
Vivien Didelot | c528666 | 2017-11-06 16:11:50 -0500 | [diff] [blame] | 145 | of_for_each_phandle(&it, err, dn, "link", NULL, 0) { |
| 146 | link_dp = dsa_tree_find_port_by_node(dst, it.node); |
| 147 | if (!link_dp) { |
| 148 | of_node_put(it.node); |
Vivien Didelot | 34c09a8 | 2017-11-06 16:11:51 -0500 | [diff] [blame] | 149 | return false; |
Vivien Didelot | c528666 | 2017-11-06 16:11:50 -0500 | [diff] [blame] | 150 | } |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 151 | |
Vivien Didelot | 34c09a8 | 2017-11-06 16:11:51 -0500 | [diff] [blame] | 152 | ds->rtable[link_dp->ds->index] = dp->index; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 153 | } |
| 154 | |
Vivien Didelot | 34c09a8 | 2017-11-06 16:11:51 -0500 | [diff] [blame] | 155 | return true; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 156 | } |
| 157 | |
Vivien Didelot | 34c09a8 | 2017-11-06 16:11:51 -0500 | [diff] [blame] | 158 | static bool dsa_switch_setup_routing_table(struct dsa_switch *ds) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 159 | { |
Vivien Didelot | 86bfb2c | 2019-10-21 16:51:20 -0400 | [diff] [blame^] | 160 | struct dsa_switch_tree *dst = ds->dst; |
Vivien Didelot | 34c09a8 | 2017-11-06 16:11:51 -0500 | [diff] [blame] | 161 | bool complete = true; |
| 162 | struct dsa_port *dp; |
| 163 | int i; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 164 | |
Vivien Didelot | 34c09a8 | 2017-11-06 16:11:51 -0500 | [diff] [blame] | 165 | for (i = 0; i < DSA_MAX_SWITCHES; i++) |
| 166 | ds->rtable[i] = DSA_RTABLE_NONE; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 167 | |
Vivien Didelot | 86bfb2c | 2019-10-21 16:51:20 -0400 | [diff] [blame^] | 168 | list_for_each_entry(dp, &dst->ports, list) { |
| 169 | if (dp->ds == ds && dsa_port_is_dsa(dp)) { |
Vivien Didelot | 34c09a8 | 2017-11-06 16:11:51 -0500 | [diff] [blame] | 170 | complete = dsa_port_setup_routing_table(dp); |
| 171 | if (!complete) |
| 172 | break; |
| 173 | } |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 174 | } |
| 175 | |
Vivien Didelot | 34c09a8 | 2017-11-06 16:11:51 -0500 | [diff] [blame] | 176 | return complete; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 177 | } |
| 178 | |
Vivien Didelot | 34c09a8 | 2017-11-06 16:11:51 -0500 | [diff] [blame] | 179 | static bool dsa_tree_setup_routing_table(struct dsa_switch_tree *dst) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 180 | { |
| 181 | struct dsa_switch *ds; |
Vivien Didelot | 34c09a8 | 2017-11-06 16:11:51 -0500 | [diff] [blame] | 182 | bool complete = true; |
| 183 | int device; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 184 | |
Vivien Didelot | 34c09a8 | 2017-11-06 16:11:51 -0500 | [diff] [blame] | 185 | for (device = 0; device < DSA_MAX_SWITCHES; device++) { |
| 186 | ds = dst->ds[device]; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 187 | if (!ds) |
| 188 | continue; |
| 189 | |
Vivien Didelot | 34c09a8 | 2017-11-06 16:11:51 -0500 | [diff] [blame] | 190 | complete = dsa_switch_setup_routing_table(ds); |
| 191 | if (!complete) |
| 192 | break; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 193 | } |
| 194 | |
Vivien Didelot | 34c09a8 | 2017-11-06 16:11:51 -0500 | [diff] [blame] | 195 | return complete; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 196 | } |
| 197 | |
Vivien Didelot | f070464 | 2017-11-06 16:11:44 -0500 | [diff] [blame] | 198 | static struct dsa_port *dsa_tree_find_first_cpu(struct dsa_switch_tree *dst) |
| 199 | { |
| 200 | struct dsa_switch *ds; |
| 201 | struct dsa_port *dp; |
| 202 | int device, port; |
| 203 | |
| 204 | for (device = 0; device < DSA_MAX_SWITCHES; device++) { |
| 205 | ds = dst->ds[device]; |
| 206 | if (!ds) |
| 207 | continue; |
| 208 | |
| 209 | for (port = 0; port < ds->num_ports; port++) { |
| 210 | dp = &ds->ports[port]; |
| 211 | |
| 212 | if (dsa_port_is_cpu(dp)) |
| 213 | return dp; |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | return NULL; |
| 218 | } |
| 219 | |
| 220 | static int dsa_tree_setup_default_cpu(struct dsa_switch_tree *dst) |
| 221 | { |
| 222 | struct dsa_switch *ds; |
| 223 | struct dsa_port *dp; |
| 224 | int device, port; |
| 225 | |
| 226 | /* DSA currently only supports a single CPU port */ |
| 227 | dst->cpu_dp = dsa_tree_find_first_cpu(dst); |
| 228 | if (!dst->cpu_dp) { |
| 229 | pr_warn("Tree has no master device\n"); |
| 230 | return -EINVAL; |
| 231 | } |
| 232 | |
| 233 | /* Assign the default CPU port to all ports of the fabric */ |
| 234 | for (device = 0; device < DSA_MAX_SWITCHES; device++) { |
| 235 | ds = dst->ds[device]; |
| 236 | if (!ds) |
| 237 | continue; |
| 238 | |
| 239 | for (port = 0; port < ds->num_ports; port++) { |
| 240 | dp = &ds->ports[port]; |
| 241 | |
Vivien Didelot | 986d7cc | 2017-12-05 15:34:12 -0500 | [diff] [blame] | 242 | if (dsa_port_is_user(dp) || dsa_port_is_dsa(dp)) |
Vivien Didelot | f070464 | 2017-11-06 16:11:44 -0500 | [diff] [blame] | 243 | dp->cpu_dp = dst->cpu_dp; |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | return 0; |
| 248 | } |
| 249 | |
| 250 | static void dsa_tree_teardown_default_cpu(struct dsa_switch_tree *dst) |
| 251 | { |
| 252 | /* DSA currently only supports a single CPU port */ |
| 253 | dst->cpu_dp = NULL; |
| 254 | } |
| 255 | |
Vivien Didelot | 1d27732 | 2017-11-06 16:11:48 -0500 | [diff] [blame] | 256 | static int dsa_port_setup(struct dsa_port *dp) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 257 | { |
Vivien Didelot | 1d27732 | 2017-11-06 16:11:48 -0500 | [diff] [blame] | 258 | struct dsa_switch *ds = dp->ds; |
Jiri Pirko | 15b04ac | 2019-04-03 14:24:26 +0200 | [diff] [blame] | 259 | struct dsa_switch_tree *dst = ds->dst; |
Vivien Didelot | 955222c | 2019-08-19 16:00:48 -0400 | [diff] [blame] | 260 | const unsigned char *id = (const unsigned char *)&dst->index; |
| 261 | const unsigned char len = sizeof(dst->index); |
| 262 | struct devlink_port *dlp = &dp->devlink_port; |
Vladimir Oltean | 4ba0ebb | 2019-08-31 15:46:19 +0300 | [diff] [blame] | 263 | bool dsa_port_link_registered = false; |
| 264 | bool devlink_port_registered = false; |
Vivien Didelot | 955222c | 2019-08-19 16:00:48 -0400 | [diff] [blame] | 265 | struct devlink *dl = ds->devlink; |
Vladimir Oltean | 4ba0ebb | 2019-08-31 15:46:19 +0300 | [diff] [blame] | 266 | bool dsa_port_enabled = false; |
| 267 | int err = 0; |
Andrew Lunn | 96567d5 | 2017-03-28 23:45:07 +0200 | [diff] [blame] | 268 | |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 269 | if (dp->setup) |
| 270 | return 0; |
| 271 | |
Vivien Didelot | 1d27732 | 2017-11-06 16:11:48 -0500 | [diff] [blame] | 272 | switch (dp->type) { |
| 273 | case DSA_PORT_TYPE_UNUSED: |
Vivien Didelot | 0394a63 | 2019-08-19 16:00:50 -0400 | [diff] [blame] | 274 | dsa_port_disable(dp); |
Vivien Didelot | 1d27732 | 2017-11-06 16:11:48 -0500 | [diff] [blame] | 275 | break; |
| 276 | case DSA_PORT_TYPE_CPU: |
Vivien Didelot | 955222c | 2019-08-19 16:00:48 -0400 | [diff] [blame] | 277 | memset(dlp, 0, sizeof(*dlp)); |
| 278 | devlink_port_attrs_set(dlp, DEVLINK_PORT_FLAVOUR_CPU, |
| 279 | dp->index, false, 0, id, len); |
| 280 | err = devlink_port_register(dl, dlp, dp->index); |
| 281 | if (err) |
Vladimir Oltean | 4ba0ebb | 2019-08-31 15:46:19 +0300 | [diff] [blame] | 282 | break; |
| 283 | devlink_port_registered = true; |
Vivien Didelot | 955222c | 2019-08-19 16:00:48 -0400 | [diff] [blame] | 284 | |
Jiri Pirko | da07739 | 2018-05-18 09:29:03 +0200 | [diff] [blame] | 285 | err = dsa_port_link_register_of(dp); |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 286 | if (err) |
Vladimir Oltean | 4ba0ebb | 2019-08-31 15:46:19 +0300 | [diff] [blame] | 287 | break; |
| 288 | dsa_port_link_registered = true; |
Vivien Didelot | 0394a63 | 2019-08-19 16:00:50 -0400 | [diff] [blame] | 289 | |
| 290 | err = dsa_port_enable(dp, NULL); |
| 291 | if (err) |
Vladimir Oltean | 4ba0ebb | 2019-08-31 15:46:19 +0300 | [diff] [blame] | 292 | break; |
| 293 | dsa_port_enabled = true; |
| 294 | |
Jiri Pirko | da07739 | 2018-05-18 09:29:03 +0200 | [diff] [blame] | 295 | break; |
Vivien Didelot | 1d27732 | 2017-11-06 16:11:48 -0500 | [diff] [blame] | 296 | case DSA_PORT_TYPE_DSA: |
Vivien Didelot | 955222c | 2019-08-19 16:00:48 -0400 | [diff] [blame] | 297 | memset(dlp, 0, sizeof(*dlp)); |
| 298 | devlink_port_attrs_set(dlp, DEVLINK_PORT_FLAVOUR_DSA, |
| 299 | dp->index, false, 0, id, len); |
| 300 | err = devlink_port_register(dl, dlp, dp->index); |
| 301 | if (err) |
Vladimir Oltean | 4ba0ebb | 2019-08-31 15:46:19 +0300 | [diff] [blame] | 302 | break; |
| 303 | devlink_port_registered = true; |
Vivien Didelot | 955222c | 2019-08-19 16:00:48 -0400 | [diff] [blame] | 304 | |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 305 | err = dsa_port_link_register_of(dp); |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 306 | if (err) |
Vladimir Oltean | 4ba0ebb | 2019-08-31 15:46:19 +0300 | [diff] [blame] | 307 | break; |
| 308 | dsa_port_link_registered = true; |
Vivien Didelot | 0394a63 | 2019-08-19 16:00:50 -0400 | [diff] [blame] | 309 | |
| 310 | err = dsa_port_enable(dp, NULL); |
| 311 | if (err) |
Vladimir Oltean | 4ba0ebb | 2019-08-31 15:46:19 +0300 | [diff] [blame] | 312 | break; |
| 313 | dsa_port_enabled = true; |
| 314 | |
Vivien Didelot | 1d27732 | 2017-11-06 16:11:48 -0500 | [diff] [blame] | 315 | break; |
| 316 | case DSA_PORT_TYPE_USER: |
Vivien Didelot | 955222c | 2019-08-19 16:00:48 -0400 | [diff] [blame] | 317 | memset(dlp, 0, sizeof(*dlp)); |
| 318 | devlink_port_attrs_set(dlp, DEVLINK_PORT_FLAVOUR_PHYSICAL, |
| 319 | dp->index, false, 0, id, len); |
| 320 | err = devlink_port_register(dl, dlp, dp->index); |
| 321 | if (err) |
Vladimir Oltean | 4ba0ebb | 2019-08-31 15:46:19 +0300 | [diff] [blame] | 322 | break; |
| 323 | devlink_port_registered = true; |
Vivien Didelot | 955222c | 2019-08-19 16:00:48 -0400 | [diff] [blame] | 324 | |
| 325 | dp->mac = of_get_mac_address(dp->dn); |
Vivien Didelot | 1d27732 | 2017-11-06 16:11:48 -0500 | [diff] [blame] | 326 | err = dsa_slave_create(dp); |
| 327 | if (err) |
Vladimir Oltean | 4ba0ebb | 2019-08-31 15:46:19 +0300 | [diff] [blame] | 328 | break; |
Vivien Didelot | 955222c | 2019-08-19 16:00:48 -0400 | [diff] [blame] | 329 | |
| 330 | devlink_port_type_eth_set(dlp, dp->slave); |
Vivien Didelot | 1d27732 | 2017-11-06 16:11:48 -0500 | [diff] [blame] | 331 | break; |
| 332 | } |
Andrew Lunn | 96567d5 | 2017-03-28 23:45:07 +0200 | [diff] [blame] | 333 | |
Vladimir Oltean | 4ba0ebb | 2019-08-31 15:46:19 +0300 | [diff] [blame] | 334 | if (err && dsa_port_enabled) |
| 335 | dsa_port_disable(dp); |
| 336 | if (err && dsa_port_link_registered) |
| 337 | dsa_port_link_unregister_of(dp); |
| 338 | if (err && devlink_port_registered) |
| 339 | devlink_port_unregister(dlp); |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 340 | if (err) |
| 341 | return err; |
Vladimir Oltean | 4ba0ebb | 2019-08-31 15:46:19 +0300 | [diff] [blame] | 342 | |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 343 | dp->setup = true; |
| 344 | |
| 345 | return 0; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 346 | } |
| 347 | |
Vivien Didelot | 1d27732 | 2017-11-06 16:11:48 -0500 | [diff] [blame] | 348 | static void dsa_port_teardown(struct dsa_port *dp) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 349 | { |
Vivien Didelot | 955222c | 2019-08-19 16:00:48 -0400 | [diff] [blame] | 350 | struct devlink_port *dlp = &dp->devlink_port; |
Vivien Didelot | 1d27732 | 2017-11-06 16:11:48 -0500 | [diff] [blame] | 351 | |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 352 | if (!dp->setup) |
| 353 | return; |
| 354 | |
Vivien Didelot | 1d27732 | 2017-11-06 16:11:48 -0500 | [diff] [blame] | 355 | switch (dp->type) { |
| 356 | case DSA_PORT_TYPE_UNUSED: |
| 357 | break; |
| 358 | case DSA_PORT_TYPE_CPU: |
Vivien Didelot | 0394a63 | 2019-08-19 16:00:50 -0400 | [diff] [blame] | 359 | dsa_port_disable(dp); |
Andrew Lunn | 4dad81e | 2019-04-28 19:37:19 +0200 | [diff] [blame] | 360 | dsa_tag_driver_put(dp->tag_ops); |
Vivien Didelot | 955222c | 2019-08-19 16:00:48 -0400 | [diff] [blame] | 361 | devlink_port_unregister(dlp); |
| 362 | dsa_port_link_unregister_of(dp); |
| 363 | break; |
Vivien Didelot | 1d27732 | 2017-11-06 16:11:48 -0500 | [diff] [blame] | 364 | case DSA_PORT_TYPE_DSA: |
Vivien Didelot | 0394a63 | 2019-08-19 16:00:50 -0400 | [diff] [blame] | 365 | dsa_port_disable(dp); |
Vivien Didelot | 955222c | 2019-08-19 16:00:48 -0400 | [diff] [blame] | 366 | devlink_port_unregister(dlp); |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 367 | dsa_port_link_unregister_of(dp); |
Vivien Didelot | 1d27732 | 2017-11-06 16:11:48 -0500 | [diff] [blame] | 368 | break; |
| 369 | case DSA_PORT_TYPE_USER: |
Vivien Didelot | 955222c | 2019-08-19 16:00:48 -0400 | [diff] [blame] | 370 | devlink_port_unregister(dlp); |
Vivien Didelot | 1d27732 | 2017-11-06 16:11:48 -0500 | [diff] [blame] | 371 | if (dp->slave) { |
| 372 | dsa_slave_destroy(dp->slave); |
| 373 | dp->slave = NULL; |
| 374 | } |
| 375 | break; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 376 | } |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 377 | |
| 378 | dp->setup = false; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 379 | } |
| 380 | |
Vivien Didelot | 1f08f9e | 2017-11-06 16:11:47 -0500 | [diff] [blame] | 381 | static int dsa_switch_setup(struct dsa_switch *ds) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 382 | { |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 383 | int err; |
| 384 | |
| 385 | if (ds->setup) |
| 386 | return 0; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 387 | |
Florian Fainelli | 6e830d8 | 2016-06-07 16:32:39 -0700 | [diff] [blame] | 388 | /* Initialize ds->phys_mii_mask before registering the slave MDIO bus |
Vivien Didelot | 9d490b4 | 2016-08-23 12:38:56 -0400 | [diff] [blame] | 389 | * driver and before ops->setup() has run, since the switch drivers and |
Florian Fainelli | 6e830d8 | 2016-06-07 16:32:39 -0700 | [diff] [blame] | 390 | * the slave MDIO bus driver rely on these values for probing PHY |
| 391 | * devices or not |
| 392 | */ |
Vivien Didelot | 02bc6e5 | 2017-10-26 11:22:56 -0400 | [diff] [blame] | 393 | ds->phys_mii_mask |= dsa_user_ports(ds); |
Florian Fainelli | 6e830d8 | 2016-06-07 16:32:39 -0700 | [diff] [blame] | 394 | |
Andrew Lunn | 96567d5 | 2017-03-28 23:45:07 +0200 | [diff] [blame] | 395 | /* Add the switch to devlink before calling setup, so that setup can |
| 396 | * add dpipe tables |
| 397 | */ |
| 398 | ds->devlink = devlink_alloc(&dsa_devlink_ops, 0); |
| 399 | if (!ds->devlink) |
| 400 | return -ENOMEM; |
| 401 | |
| 402 | err = devlink_register(ds->devlink, ds->dev); |
| 403 | if (err) |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 404 | goto free_devlink; |
Andrew Lunn | 96567d5 | 2017-03-28 23:45:07 +0200 | [diff] [blame] | 405 | |
Vivien Didelot | f515f19 | 2017-02-03 13:20:20 -0500 | [diff] [blame] | 406 | err = dsa_switch_register_notifier(ds); |
| 407 | if (err) |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 408 | goto unregister_devlink; |
Vivien Didelot | f515f19 | 2017-02-03 13:20:20 -0500 | [diff] [blame] | 409 | |
Vladimir Oltean | b2243b3 | 2019-05-05 13:19:20 +0300 | [diff] [blame] | 410 | err = ds->ops->setup(ds); |
| 411 | if (err < 0) |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 412 | goto unregister_notifier; |
Vladimir Oltean | b2243b3 | 2019-05-05 13:19:20 +0300 | [diff] [blame] | 413 | |
Vivien Didelot | 9d490b4 | 2016-08-23 12:38:56 -0400 | [diff] [blame] | 414 | if (!ds->slave_mii_bus && ds->ops->phy_read) { |
Florian Fainelli | 1eb5944 | 2016-06-07 16:32:40 -0700 | [diff] [blame] | 415 | ds->slave_mii_bus = devm_mdiobus_alloc(ds->dev); |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 416 | if (!ds->slave_mii_bus) { |
| 417 | err = -ENOMEM; |
| 418 | goto unregister_notifier; |
| 419 | } |
Florian Fainelli | 1eb5944 | 2016-06-07 16:32:40 -0700 | [diff] [blame] | 420 | |
| 421 | dsa_slave_mii_bus_init(ds); |
| 422 | |
| 423 | err = mdiobus_register(ds->slave_mii_bus); |
| 424 | if (err < 0) |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 425 | goto unregister_notifier; |
Florian Fainelli | 1eb5944 | 2016-06-07 16:32:40 -0700 | [diff] [blame] | 426 | } |
| 427 | |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 428 | ds->setup = true; |
| 429 | |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 430 | return 0; |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 431 | |
| 432 | unregister_notifier: |
| 433 | dsa_switch_unregister_notifier(ds); |
| 434 | unregister_devlink: |
| 435 | devlink_unregister(ds->devlink); |
| 436 | free_devlink: |
| 437 | devlink_free(ds->devlink); |
| 438 | ds->devlink = NULL; |
| 439 | |
| 440 | return err; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 441 | } |
| 442 | |
Vivien Didelot | 1f08f9e | 2017-11-06 16:11:47 -0500 | [diff] [blame] | 443 | static void dsa_switch_teardown(struct dsa_switch *ds) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 444 | { |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 445 | if (!ds->setup) |
| 446 | return; |
| 447 | |
Vivien Didelot | 9d490b4 | 2016-08-23 12:38:56 -0400 | [diff] [blame] | 448 | if (ds->slave_mii_bus && ds->ops->phy_read) |
Florian Fainelli | 1eb5944 | 2016-06-07 16:32:40 -0700 | [diff] [blame] | 449 | mdiobus_unregister(ds->slave_mii_bus); |
Vivien Didelot | f515f19 | 2017-02-03 13:20:20 -0500 | [diff] [blame] | 450 | |
| 451 | dsa_switch_unregister_notifier(ds); |
Andrew Lunn | 96567d5 | 2017-03-28 23:45:07 +0200 | [diff] [blame] | 452 | |
Vladimir Oltean | 5e3f847 | 2019-06-08 15:04:28 +0300 | [diff] [blame] | 453 | if (ds->ops->teardown) |
| 454 | ds->ops->teardown(ds); |
| 455 | |
Andrew Lunn | 96567d5 | 2017-03-28 23:45:07 +0200 | [diff] [blame] | 456 | if (ds->devlink) { |
| 457 | devlink_unregister(ds->devlink); |
| 458 | devlink_free(ds->devlink); |
| 459 | ds->devlink = NULL; |
| 460 | } |
| 461 | |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 462 | ds->setup = false; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 463 | } |
| 464 | |
Vivien Didelot | 1f08f9e | 2017-11-06 16:11:47 -0500 | [diff] [blame] | 465 | static int dsa_tree_setup_switches(struct dsa_switch_tree *dst) |
| 466 | { |
Vivien Didelot | 1d27732 | 2017-11-06 16:11:48 -0500 | [diff] [blame] | 467 | struct dsa_port *dp; |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 468 | int err; |
Vivien Didelot | 1f08f9e | 2017-11-06 16:11:47 -0500 | [diff] [blame] | 469 | |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 470 | list_for_each_entry(dp, &dst->ports, list) { |
| 471 | err = dsa_switch_setup(dp->ds); |
Vivien Didelot | 1f08f9e | 2017-11-06 16:11:47 -0500 | [diff] [blame] | 472 | if (err) |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 473 | goto teardown; |
| 474 | } |
Vivien Didelot | 1d27732 | 2017-11-06 16:11:48 -0500 | [diff] [blame] | 475 | |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 476 | list_for_each_entry(dp, &dst->ports, list) { |
| 477 | err = dsa_port_setup(dp); |
| 478 | if (err) |
| 479 | goto teardown; |
Vivien Didelot | 1f08f9e | 2017-11-06 16:11:47 -0500 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | return 0; |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 483 | |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 484 | teardown: |
| 485 | list_for_each_entry(dp, &dst->ports, list) |
| 486 | dsa_port_teardown(dp); |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 487 | |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 488 | list_for_each_entry(dp, &dst->ports, list) |
| 489 | dsa_switch_teardown(dp->ds); |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 490 | |
| 491 | return err; |
Vivien Didelot | 1f08f9e | 2017-11-06 16:11:47 -0500 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | static void dsa_tree_teardown_switches(struct dsa_switch_tree *dst) |
| 495 | { |
Vivien Didelot | 1d27732 | 2017-11-06 16:11:48 -0500 | [diff] [blame] | 496 | struct dsa_port *dp; |
Vivien Didelot | 1f08f9e | 2017-11-06 16:11:47 -0500 | [diff] [blame] | 497 | |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 498 | list_for_each_entry(dp, &dst->ports, list) |
| 499 | dsa_port_teardown(dp); |
Vivien Didelot | 1f08f9e | 2017-11-06 16:11:47 -0500 | [diff] [blame] | 500 | |
Vivien Didelot | fb35c60 | 2019-10-21 16:51:19 -0400 | [diff] [blame] | 501 | list_for_each_entry(dp, &dst->ports, list) |
| 502 | dsa_switch_teardown(dp->ds); |
Vivien Didelot | 1f08f9e | 2017-11-06 16:11:47 -0500 | [diff] [blame] | 503 | } |
| 504 | |
Vivien Didelot | 17a22fc | 2017-11-06 16:11:45 -0500 | [diff] [blame] | 505 | static int dsa_tree_setup_master(struct dsa_switch_tree *dst) |
| 506 | { |
| 507 | struct dsa_port *cpu_dp = dst->cpu_dp; |
| 508 | struct net_device *master = cpu_dp->master; |
| 509 | |
| 510 | /* DSA currently supports a single pair of CPU port and master device */ |
| 511 | return dsa_master_setup(master, cpu_dp); |
| 512 | } |
| 513 | |
| 514 | static void dsa_tree_teardown_master(struct dsa_switch_tree *dst) |
| 515 | { |
| 516 | struct dsa_port *cpu_dp = dst->cpu_dp; |
| 517 | struct net_device *master = cpu_dp->master; |
| 518 | |
| 519 | return dsa_master_teardown(master); |
| 520 | } |
| 521 | |
Vivien Didelot | ec15dd4 | 2017-11-06 16:11:46 -0500 | [diff] [blame] | 522 | static int dsa_tree_setup(struct dsa_switch_tree *dst) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 523 | { |
Vivien Didelot | 34c09a8 | 2017-11-06 16:11:51 -0500 | [diff] [blame] | 524 | bool complete; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 525 | int err; |
| 526 | |
Vivien Didelot | ec15dd4 | 2017-11-06 16:11:46 -0500 | [diff] [blame] | 527 | if (dst->setup) { |
| 528 | pr_err("DSA: tree %d already setup! Disjoint trees?\n", |
| 529 | dst->index); |
| 530 | return -EEXIST; |
| 531 | } |
| 532 | |
Vivien Didelot | 34c09a8 | 2017-11-06 16:11:51 -0500 | [diff] [blame] | 533 | complete = dsa_tree_setup_routing_table(dst); |
| 534 | if (!complete) |
| 535 | return 0; |
| 536 | |
Vivien Didelot | f070464 | 2017-11-06 16:11:44 -0500 | [diff] [blame] | 537 | err = dsa_tree_setup_default_cpu(dst); |
| 538 | if (err) |
| 539 | return err; |
| 540 | |
Vivien Didelot | 1f08f9e | 2017-11-06 16:11:47 -0500 | [diff] [blame] | 541 | err = dsa_tree_setup_switches(dst); |
| 542 | if (err) |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 543 | goto teardown_default_cpu; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 544 | |
Vivien Didelot | 17a22fc | 2017-11-06 16:11:45 -0500 | [diff] [blame] | 545 | err = dsa_tree_setup_master(dst); |
Vivien Didelot | 1943563 | 2017-09-19 11:56:59 -0400 | [diff] [blame] | 546 | if (err) |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 547 | goto teardown_switches; |
Vivien Didelot | 1943563 | 2017-09-19 11:56:59 -0400 | [diff] [blame] | 548 | |
Vivien Didelot | ec15dd4 | 2017-11-06 16:11:46 -0500 | [diff] [blame] | 549 | dst->setup = true; |
| 550 | |
| 551 | pr_info("DSA: tree %d setup\n", dst->index); |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 552 | |
| 553 | return 0; |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 554 | |
| 555 | teardown_switches: |
| 556 | dsa_tree_teardown_switches(dst); |
| 557 | teardown_default_cpu: |
| 558 | dsa_tree_teardown_default_cpu(dst); |
| 559 | |
| 560 | return err; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 561 | } |
| 562 | |
Vivien Didelot | ec15dd4 | 2017-11-06 16:11:46 -0500 | [diff] [blame] | 563 | static void dsa_tree_teardown(struct dsa_switch_tree *dst) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 564 | { |
Vivien Didelot | ec15dd4 | 2017-11-06 16:11:46 -0500 | [diff] [blame] | 565 | if (!dst->setup) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 566 | return; |
| 567 | |
Vivien Didelot | 17a22fc | 2017-11-06 16:11:45 -0500 | [diff] [blame] | 568 | dsa_tree_teardown_master(dst); |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 569 | |
Vivien Didelot | 1f08f9e | 2017-11-06 16:11:47 -0500 | [diff] [blame] | 570 | dsa_tree_teardown_switches(dst); |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 571 | |
Vivien Didelot | f070464 | 2017-11-06 16:11:44 -0500 | [diff] [blame] | 572 | dsa_tree_teardown_default_cpu(dst); |
Florian Fainelli | 0c73c52 | 2016-06-07 16:32:42 -0700 | [diff] [blame] | 573 | |
Vivien Didelot | ec15dd4 | 2017-11-06 16:11:46 -0500 | [diff] [blame] | 574 | pr_info("DSA: tree %d torn down\n", dst->index); |
| 575 | |
| 576 | dst->setup = false; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 577 | } |
| 578 | |
Vivien Didelot | 6da2a94 | 2017-11-03 19:05:25 -0400 | [diff] [blame] | 579 | static void dsa_tree_remove_switch(struct dsa_switch_tree *dst, |
| 580 | unsigned int index) |
| 581 | { |
Vivien Didelot | 3081735 | 2017-11-06 16:11:52 -0500 | [diff] [blame] | 582 | dsa_tree_teardown(dst); |
| 583 | |
Vivien Didelot | 6da2a94 | 2017-11-03 19:05:25 -0400 | [diff] [blame] | 584 | dst->ds[index] = NULL; |
| 585 | dsa_tree_put(dst); |
| 586 | } |
| 587 | |
| 588 | static int dsa_tree_add_switch(struct dsa_switch_tree *dst, |
| 589 | struct dsa_switch *ds) |
| 590 | { |
| 591 | unsigned int index = ds->index; |
Vivien Didelot | 3081735 | 2017-11-06 16:11:52 -0500 | [diff] [blame] | 592 | int err; |
Vivien Didelot | 6da2a94 | 2017-11-03 19:05:25 -0400 | [diff] [blame] | 593 | |
| 594 | if (dst->ds[index]) |
| 595 | return -EBUSY; |
| 596 | |
| 597 | dsa_tree_get(dst); |
| 598 | dst->ds[index] = ds; |
| 599 | |
Vivien Didelot | 3081735 | 2017-11-06 16:11:52 -0500 | [diff] [blame] | 600 | err = dsa_tree_setup(dst); |
Ioana Ciornei | e70c7aa | 2019-05-30 09:09:07 +0300 | [diff] [blame] | 601 | if (err) { |
| 602 | dst->ds[index] = NULL; |
| 603 | dsa_tree_put(dst); |
| 604 | } |
Vivien Didelot | 3081735 | 2017-11-06 16:11:52 -0500 | [diff] [blame] | 605 | |
| 606 | return err; |
Vivien Didelot | 6da2a94 | 2017-11-03 19:05:25 -0400 | [diff] [blame] | 607 | } |
| 608 | |
Vivien Didelot | ab8ccae | 2019-10-21 16:51:16 -0400 | [diff] [blame] | 609 | static struct dsa_port *dsa_port_touch(struct dsa_switch *ds, int index) |
| 610 | { |
| 611 | struct dsa_switch_tree *dst = ds->dst; |
| 612 | struct dsa_port *dp; |
| 613 | |
| 614 | dp = &ds->ports[index]; |
| 615 | |
| 616 | dp->ds = ds; |
| 617 | dp->index = index; |
| 618 | |
| 619 | INIT_LIST_HEAD(&dp->list); |
| 620 | list_add_tail(&dp->list, &dst->ports); |
| 621 | |
| 622 | return dp; |
| 623 | } |
| 624 | |
Vivien Didelot | 06e24d0 | 2017-11-03 19:05:29 -0400 | [diff] [blame] | 625 | static int dsa_port_parse_user(struct dsa_port *dp, const char *name) |
| 626 | { |
| 627 | if (!name) |
| 628 | name = "eth%d"; |
| 629 | |
| 630 | dp->type = DSA_PORT_TYPE_USER; |
| 631 | dp->name = name; |
| 632 | |
| 633 | return 0; |
| 634 | } |
| 635 | |
| 636 | static int dsa_port_parse_dsa(struct dsa_port *dp) |
| 637 | { |
| 638 | dp->type = DSA_PORT_TYPE_DSA; |
| 639 | |
| 640 | return 0; |
| 641 | } |
| 642 | |
| 643 | static int dsa_port_parse_cpu(struct dsa_port *dp, struct net_device *master) |
| 644 | { |
Vivien Didelot | 7354fcb | 2017-11-03 19:05:30 -0400 | [diff] [blame] | 645 | struct dsa_switch *ds = dp->ds; |
| 646 | struct dsa_switch_tree *dst = ds->dst; |
Vivien Didelot | 62fc958 | 2017-09-29 17:19:17 -0400 | [diff] [blame] | 647 | const struct dsa_device_ops *tag_ops; |
Andrew Lunn | 7b31436 | 2016-08-22 16:01:01 +0200 | [diff] [blame] | 648 | enum dsa_tag_protocol tag_protocol; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 649 | |
Florian Fainelli | 5ed4e3e | 2017-11-10 15:22:52 -0800 | [diff] [blame] | 650 | tag_protocol = ds->ops->get_tag_protocol(ds, dp->index); |
Andrew Lunn | c39e2a1 | 2019-04-28 19:37:18 +0200 | [diff] [blame] | 651 | tag_ops = dsa_tag_driver_get(tag_protocol); |
Vivien Didelot | 62fc958 | 2017-09-29 17:19:17 -0400 | [diff] [blame] | 652 | if (IS_ERR(tag_ops)) { |
Andrew Lunn | 23426a2 | 2019-09-12 15:16:45 +0200 | [diff] [blame] | 653 | if (PTR_ERR(tag_ops) == -ENOPROTOOPT) |
| 654 | return -EPROBE_DEFER; |
Florian Fainelli | 9f9e772 | 2017-07-24 10:49:23 -0700 | [diff] [blame] | 655 | dev_warn(ds->dev, "No tagger for this switch\n"); |
Vivien Didelot | 62fc958 | 2017-09-29 17:19:17 -0400 | [diff] [blame] | 656 | return PTR_ERR(tag_ops); |
Florian Fainelli | 9f9e772 | 2017-07-24 10:49:23 -0700 | [diff] [blame] | 657 | } |
| 658 | |
Vivien Didelot | 7354fcb | 2017-11-03 19:05:30 -0400 | [diff] [blame] | 659 | dp->type = DSA_PORT_TYPE_CPU; |
Vladimir Oltean | cc1939e | 2019-05-05 13:19:23 +0300 | [diff] [blame] | 660 | dp->filter = tag_ops->filter; |
Vivien Didelot | 7354fcb | 2017-11-03 19:05:30 -0400 | [diff] [blame] | 661 | dp->rcv = tag_ops->rcv; |
| 662 | dp->tag_ops = tag_ops; |
| 663 | dp->master = master; |
| 664 | dp->dst = dst; |
Vivien Didelot | 3e41f93 | 2017-09-29 17:19:19 -0400 | [diff] [blame] | 665 | |
Vivien Didelot | 7354fcb | 2017-11-03 19:05:30 -0400 | [diff] [blame] | 666 | return 0; |
| 667 | } |
| 668 | |
Vivien Didelot | fd223e2 | 2017-10-27 15:55:14 -0400 | [diff] [blame] | 669 | static int dsa_port_parse_of(struct dsa_port *dp, struct device_node *dn) |
| 670 | { |
Vivien Didelot | 6d4e5c5 | 2017-10-27 15:55:15 -0400 | [diff] [blame] | 671 | struct device_node *ethernet = of_parse_phandle(dn, "ethernet", 0); |
Vivien Didelot | 1838fa8 | 2017-10-27 15:55:18 -0400 | [diff] [blame] | 672 | const char *name = of_get_property(dn, "label", NULL); |
Vivien Didelot | 54df6fa | 2017-11-03 19:05:28 -0400 | [diff] [blame] | 673 | bool link = of_property_read_bool(dn, "link"); |
Vivien Didelot | 6d4e5c5 | 2017-10-27 15:55:15 -0400 | [diff] [blame] | 674 | |
Vivien Didelot | 06e24d0 | 2017-11-03 19:05:29 -0400 | [diff] [blame] | 675 | dp->dn = dn; |
| 676 | |
Vivien Didelot | 6d4e5c5 | 2017-10-27 15:55:15 -0400 | [diff] [blame] | 677 | if (ethernet) { |
Vivien Didelot | cbabb0a | 2017-10-27 15:55:17 -0400 | [diff] [blame] | 678 | struct net_device *master; |
| 679 | |
| 680 | master = of_find_net_device_by_node(ethernet); |
| 681 | if (!master) |
| 682 | return -EPROBE_DEFER; |
| 683 | |
Vivien Didelot | 06e24d0 | 2017-11-03 19:05:29 -0400 | [diff] [blame] | 684 | return dsa_port_parse_cpu(dp, master); |
Vivien Didelot | 6d4e5c5 | 2017-10-27 15:55:15 -0400 | [diff] [blame] | 685 | } |
| 686 | |
Vivien Didelot | 06e24d0 | 2017-11-03 19:05:29 -0400 | [diff] [blame] | 687 | if (link) |
| 688 | return dsa_port_parse_dsa(dp); |
Vivien Didelot | fd223e2 | 2017-10-27 15:55:14 -0400 | [diff] [blame] | 689 | |
Vivien Didelot | 06e24d0 | 2017-11-03 19:05:29 -0400 | [diff] [blame] | 690 | return dsa_port_parse_user(dp, name); |
Vivien Didelot | fd223e2 | 2017-10-27 15:55:14 -0400 | [diff] [blame] | 691 | } |
| 692 | |
Vivien Didelot | 975e6e3 | 2017-11-03 19:05:27 -0400 | [diff] [blame] | 693 | static int dsa_switch_parse_ports_of(struct dsa_switch *ds, |
| 694 | struct device_node *dn) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 695 | { |
Vivien Didelot | 5b32fe0 | 2017-10-27 15:55:13 -0400 | [diff] [blame] | 696 | struct device_node *ports, *port; |
Vivien Didelot | fd223e2 | 2017-10-27 15:55:14 -0400 | [diff] [blame] | 697 | struct dsa_port *dp; |
Wen Yang | 9919a36 | 2019-02-25 15:22:19 +0800 | [diff] [blame] | 698 | int err = 0; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 699 | u32 reg; |
Vivien Didelot | 5b32fe0 | 2017-10-27 15:55:13 -0400 | [diff] [blame] | 700 | |
| 701 | ports = of_get_child_by_name(dn, "ports"); |
| 702 | if (!ports) { |
| 703 | dev_err(ds->dev, "no ports child node found\n"); |
| 704 | return -EINVAL; |
| 705 | } |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 706 | |
| 707 | for_each_available_child_of_node(ports, port) { |
| 708 | err = of_property_read_u32(port, "reg", ®); |
| 709 | if (err) |
Wen Yang | 9919a36 | 2019-02-25 15:22:19 +0800 | [diff] [blame] | 710 | goto out_put_node; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 711 | |
Wen Yang | 9919a36 | 2019-02-25 15:22:19 +0800 | [diff] [blame] | 712 | if (reg >= ds->num_ports) { |
| 713 | err = -EINVAL; |
| 714 | goto out_put_node; |
| 715 | } |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 716 | |
Vivien Didelot | 68bb8ea | 2019-10-21 16:51:15 -0400 | [diff] [blame] | 717 | dp = dsa_to_port(ds, reg); |
Vivien Didelot | fd223e2 | 2017-10-27 15:55:14 -0400 | [diff] [blame] | 718 | |
| 719 | err = dsa_port_parse_of(dp, port); |
| 720 | if (err) |
Wen Yang | 9919a36 | 2019-02-25 15:22:19 +0800 | [diff] [blame] | 721 | goto out_put_node; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 722 | } |
| 723 | |
Wen Yang | 9919a36 | 2019-02-25 15:22:19 +0800 | [diff] [blame] | 724 | out_put_node: |
| 725 | of_node_put(ports); |
| 726 | return err; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 727 | } |
| 728 | |
Vivien Didelot | 975e6e3 | 2017-11-03 19:05:27 -0400 | [diff] [blame] | 729 | static int dsa_switch_parse_member_of(struct dsa_switch *ds, |
| 730 | struct device_node *dn) |
| 731 | { |
| 732 | u32 m[2] = { 0, 0 }; |
| 733 | int sz; |
| 734 | |
| 735 | /* Don't error out if this optional property isn't found */ |
| 736 | sz = of_property_read_variable_u32_array(dn, "dsa,member", m, 2, 2); |
| 737 | if (sz < 0 && sz != -EINVAL) |
| 738 | return sz; |
| 739 | |
| 740 | ds->index = m[1]; |
| 741 | if (ds->index >= DSA_MAX_SWITCHES) |
| 742 | return -EINVAL; |
| 743 | |
| 744 | ds->dst = dsa_tree_touch(m[0]); |
| 745 | if (!ds->dst) |
| 746 | return -ENOMEM; |
| 747 | |
| 748 | return 0; |
| 749 | } |
| 750 | |
Vivien Didelot | ab8ccae | 2019-10-21 16:51:16 -0400 | [diff] [blame] | 751 | static int dsa_switch_touch_ports(struct dsa_switch *ds) |
| 752 | { |
| 753 | struct dsa_port *dp; |
| 754 | int port; |
| 755 | |
| 756 | for (port = 0; port < ds->num_ports; port++) { |
| 757 | dp = dsa_port_touch(ds, port); |
| 758 | if (!dp) |
| 759 | return -ENOMEM; |
| 760 | } |
| 761 | |
| 762 | return 0; |
| 763 | } |
| 764 | |
Vivien Didelot | 975e6e3 | 2017-11-03 19:05:27 -0400 | [diff] [blame] | 765 | static int dsa_switch_parse_of(struct dsa_switch *ds, struct device_node *dn) |
| 766 | { |
| 767 | int err; |
| 768 | |
| 769 | err = dsa_switch_parse_member_of(ds, dn); |
| 770 | if (err) |
| 771 | return err; |
| 772 | |
Vivien Didelot | ab8ccae | 2019-10-21 16:51:16 -0400 | [diff] [blame] | 773 | err = dsa_switch_touch_ports(ds); |
| 774 | if (err) |
| 775 | return err; |
| 776 | |
Vivien Didelot | 975e6e3 | 2017-11-03 19:05:27 -0400 | [diff] [blame] | 777 | return dsa_switch_parse_ports_of(ds, dn); |
| 778 | } |
| 779 | |
Vivien Didelot | fd223e2 | 2017-10-27 15:55:14 -0400 | [diff] [blame] | 780 | static int dsa_port_parse(struct dsa_port *dp, const char *name, |
| 781 | struct device *dev) |
| 782 | { |
Vivien Didelot | 6d4e5c5 | 2017-10-27 15:55:15 -0400 | [diff] [blame] | 783 | if (!strcmp(name, "cpu")) { |
Vivien Didelot | cbabb0a | 2017-10-27 15:55:17 -0400 | [diff] [blame] | 784 | struct net_device *master; |
| 785 | |
| 786 | master = dsa_dev_to_net_device(dev); |
| 787 | if (!master) |
| 788 | return -EPROBE_DEFER; |
| 789 | |
| 790 | dev_put(master); |
| 791 | |
Vivien Didelot | 06e24d0 | 2017-11-03 19:05:29 -0400 | [diff] [blame] | 792 | return dsa_port_parse_cpu(dp, master); |
Vivien Didelot | 6d4e5c5 | 2017-10-27 15:55:15 -0400 | [diff] [blame] | 793 | } |
| 794 | |
Vivien Didelot | 06e24d0 | 2017-11-03 19:05:29 -0400 | [diff] [blame] | 795 | if (!strcmp(name, "dsa")) |
| 796 | return dsa_port_parse_dsa(dp); |
Vivien Didelot | fd223e2 | 2017-10-27 15:55:14 -0400 | [diff] [blame] | 797 | |
Vivien Didelot | 06e24d0 | 2017-11-03 19:05:29 -0400 | [diff] [blame] | 798 | return dsa_port_parse_user(dp, name); |
Vivien Didelot | fd223e2 | 2017-10-27 15:55:14 -0400 | [diff] [blame] | 799 | } |
| 800 | |
Vivien Didelot | 975e6e3 | 2017-11-03 19:05:27 -0400 | [diff] [blame] | 801 | static int dsa_switch_parse_ports(struct dsa_switch *ds, |
| 802 | struct dsa_chip_data *cd) |
Florian Fainelli | 71e0bbd | 2017-02-04 13:02:43 -0800 | [diff] [blame] | 803 | { |
| 804 | bool valid_name_found = false; |
Vivien Didelot | fd223e2 | 2017-10-27 15:55:14 -0400 | [diff] [blame] | 805 | struct dsa_port *dp; |
| 806 | struct device *dev; |
| 807 | const char *name; |
Florian Fainelli | 71e0bbd | 2017-02-04 13:02:43 -0800 | [diff] [blame] | 808 | unsigned int i; |
Vivien Didelot | fd223e2 | 2017-10-27 15:55:14 -0400 | [diff] [blame] | 809 | int err; |
Florian Fainelli | 71e0bbd | 2017-02-04 13:02:43 -0800 | [diff] [blame] | 810 | |
| 811 | for (i = 0; i < DSA_MAX_PORTS; i++) { |
Vivien Didelot | fd223e2 | 2017-10-27 15:55:14 -0400 | [diff] [blame] | 812 | name = cd->port_names[i]; |
| 813 | dev = cd->netdev[i]; |
Vivien Didelot | 68bb8ea | 2019-10-21 16:51:15 -0400 | [diff] [blame] | 814 | dp = dsa_to_port(ds, i); |
Vivien Didelot | fd223e2 | 2017-10-27 15:55:14 -0400 | [diff] [blame] | 815 | |
| 816 | if (!name) |
Florian Fainelli | 71e0bbd | 2017-02-04 13:02:43 -0800 | [diff] [blame] | 817 | continue; |
| 818 | |
Vivien Didelot | fd223e2 | 2017-10-27 15:55:14 -0400 | [diff] [blame] | 819 | err = dsa_port_parse(dp, name, dev); |
| 820 | if (err) |
| 821 | return err; |
| 822 | |
Florian Fainelli | 71e0bbd | 2017-02-04 13:02:43 -0800 | [diff] [blame] | 823 | valid_name_found = true; |
| 824 | } |
| 825 | |
| 826 | if (!valid_name_found && i == DSA_MAX_PORTS) |
| 827 | return -EINVAL; |
| 828 | |
| 829 | return 0; |
| 830 | } |
| 831 | |
Vivien Didelot | 975e6e3 | 2017-11-03 19:05:27 -0400 | [diff] [blame] | 832 | 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] | 833 | { |
Vivien Didelot | ab8ccae | 2019-10-21 16:51:16 -0400 | [diff] [blame] | 834 | int err; |
| 835 | |
Vivien Didelot | 975e6e3 | 2017-11-03 19:05:27 -0400 | [diff] [blame] | 836 | ds->cd = cd; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 837 | |
Vivien Didelot | 975e6e3 | 2017-11-03 19:05:27 -0400 | [diff] [blame] | 838 | /* We don't support interconnected switches nor multiple trees via |
| 839 | * platform data, so this is the unique switch of the tree. |
| 840 | */ |
| 841 | ds->index = 0; |
| 842 | ds->dst = dsa_tree_touch(0); |
| 843 | if (!ds->dst) |
| 844 | return -ENOMEM; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 845 | |
Vivien Didelot | ab8ccae | 2019-10-21 16:51:16 -0400 | [diff] [blame] | 846 | err = dsa_switch_touch_ports(ds); |
| 847 | if (err) |
| 848 | return err; |
| 849 | |
Vivien Didelot | 975e6e3 | 2017-11-03 19:05:27 -0400 | [diff] [blame] | 850 | return dsa_switch_parse_ports(ds, cd); |
Florian Fainelli | 71e0bbd | 2017-02-04 13:02:43 -0800 | [diff] [blame] | 851 | } |
| 852 | |
Vivien Didelot | 3081735 | 2017-11-06 16:11:52 -0500 | [diff] [blame] | 853 | static int dsa_switch_add(struct dsa_switch *ds) |
| 854 | { |
| 855 | struct dsa_switch_tree *dst = ds->dst; |
| 856 | |
| 857 | return dsa_tree_add_switch(dst, ds); |
| 858 | } |
| 859 | |
Vivien Didelot | b4fbb34 | 2017-11-06 16:11:53 -0500 | [diff] [blame] | 860 | static int dsa_switch_probe(struct dsa_switch *ds) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 861 | { |
Vivien Didelot | 23c9ee4 | 2017-05-26 18:12:51 -0400 | [diff] [blame] | 862 | struct dsa_chip_data *pdata = ds->dev->platform_data; |
| 863 | struct device_node *np = ds->dev->of_node; |
Vivien Didelot | 34c09a8 | 2017-11-06 16:11:51 -0500 | [diff] [blame] | 864 | int err; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 865 | |
Vivien Didelot | 975e6e3 | 2017-11-03 19:05:27 -0400 | [diff] [blame] | 866 | if (np) |
| 867 | err = dsa_switch_parse_of(ds, np); |
| 868 | else if (pdata) |
| 869 | err = dsa_switch_parse(ds, pdata); |
| 870 | else |
| 871 | err = -ENODEV; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 872 | |
Vivien Didelot | 975e6e3 | 2017-11-03 19:05:27 -0400 | [diff] [blame] | 873 | if (err) |
| 874 | return err; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 875 | |
Vivien Didelot | 3081735 | 2017-11-06 16:11:52 -0500 | [diff] [blame] | 876 | return dsa_switch_add(ds); |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 877 | } |
| 878 | |
Vivien Didelot | a0c0216 | 2017-01-27 15:29:36 -0500 | [diff] [blame] | 879 | struct dsa_switch *dsa_switch_alloc(struct device *dev, size_t n) |
| 880 | { |
Vivien Didelot | a0c0216 | 2017-01-27 15:29:36 -0500 | [diff] [blame] | 881 | struct dsa_switch *ds; |
| 882 | |
Gustavo A. R. Silva | 33b363e | 2019-02-07 19:16:03 -0600 | [diff] [blame] | 883 | ds = devm_kzalloc(dev, struct_size(ds, ports, n), GFP_KERNEL); |
Vivien Didelot | a0c0216 | 2017-01-27 15:29:36 -0500 | [diff] [blame] | 884 | if (!ds) |
| 885 | return NULL; |
| 886 | |
| 887 | ds->dev = dev; |
| 888 | ds->num_ports = n; |
| 889 | |
| 890 | return ds; |
| 891 | } |
| 892 | EXPORT_SYMBOL_GPL(dsa_switch_alloc); |
| 893 | |
Vivien Didelot | 23c9ee4 | 2017-05-26 18:12:51 -0400 | [diff] [blame] | 894 | int dsa_register_switch(struct dsa_switch *ds) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 895 | { |
| 896 | int err; |
| 897 | |
| 898 | mutex_lock(&dsa2_mutex); |
Vivien Didelot | b4fbb34 | 2017-11-06 16:11:53 -0500 | [diff] [blame] | 899 | err = dsa_switch_probe(ds); |
Vivien Didelot | 9e74104 | 2017-11-24 11:36:06 -0500 | [diff] [blame] | 900 | dsa_tree_put(ds->dst); |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 901 | mutex_unlock(&dsa2_mutex); |
| 902 | |
| 903 | return err; |
| 904 | } |
| 905 | EXPORT_SYMBOL_GPL(dsa_register_switch); |
| 906 | |
Vivien Didelot | b4fbb34 | 2017-11-06 16:11:53 -0500 | [diff] [blame] | 907 | static void dsa_switch_remove(struct dsa_switch *ds) |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 908 | { |
| 909 | struct dsa_switch_tree *dst = ds->dst; |
Vivien Didelot | 6da2a94 | 2017-11-03 19:05:25 -0400 | [diff] [blame] | 910 | unsigned int index = ds->index; |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 911 | |
Vivien Didelot | 6da2a94 | 2017-11-03 19:05:25 -0400 | [diff] [blame] | 912 | dsa_tree_remove_switch(dst, index); |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | void dsa_unregister_switch(struct dsa_switch *ds) |
| 916 | { |
| 917 | mutex_lock(&dsa2_mutex); |
Vivien Didelot | b4fbb34 | 2017-11-06 16:11:53 -0500 | [diff] [blame] | 918 | dsa_switch_remove(ds); |
Andrew Lunn | 83c0afa | 2016-06-04 21:17:07 +0200 | [diff] [blame] | 919 | mutex_unlock(&dsa2_mutex); |
| 920 | } |
| 921 | EXPORT_SYMBOL_GPL(dsa_unregister_switch); |