Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 1 | /* |
| 2 | * net/dsa/dsa.c - Hardware switch handling |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 3 | * Copyright (c) 2008-2009 Marvell Semiconductor |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 4 | * Copyright (c) 2013 Florian Fainelli <florian@openwrt.org> |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | */ |
| 11 | |
Guenter Roeck | 51579c3 | 2014-10-29 10:44:58 -0700 | [diff] [blame] | 12 | #include <linux/device.h> |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 13 | #include <linux/list.h> |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 14 | #include <linux/platform_device.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 15 | #include <linux/slab.h> |
Paul Gortmaker | 3a9a231 | 2011-05-27 09:12:25 -0400 | [diff] [blame] | 16 | #include <linux/module.h> |
Florian Fainelli | 60724d4 | 2017-10-11 10:57:48 -0700 | [diff] [blame] | 17 | #include <linux/notifier.h> |
Florian Fainelli | 5e95329b | 2013-03-22 10:50:50 +0000 | [diff] [blame] | 18 | #include <linux/of.h> |
| 19 | #include <linux/of_mdio.h> |
| 20 | #include <linux/of_platform.h> |
Florian Fainelli | 769a020 | 2015-03-09 14:31:21 -0700 | [diff] [blame] | 21 | #include <linux/of_net.h> |
Andrew Lunn | c6e970a | 2017-03-28 23:45:06 +0200 | [diff] [blame] | 22 | #include <linux/netdevice.h> |
Guenter Roeck | 51579c3 | 2014-10-29 10:44:58 -0700 | [diff] [blame] | 23 | #include <linux/sysfs.h> |
Neil Armstrong | cbc5d90 | 2015-10-06 15:40:32 +0100 | [diff] [blame] | 24 | #include <linux/phy_fixed.h> |
Brandon Streiff | 90af105 | 2018-02-14 01:07:49 +0100 | [diff] [blame] | 25 | #include <linux/ptp_classify.h> |
Florian Fainelli | a86d8be | 2017-04-08 08:55:23 -0700 | [diff] [blame] | 26 | #include <linux/etherdevice.h> |
Vivien Didelot | ea5dd34 | 2017-05-17 15:46:03 -0400 | [diff] [blame] | 27 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 28 | #include "dsa_priv.h" |
| 29 | |
Andrew Lunn | bdc6fe5 | 2019-04-28 19:37:16 +0200 | [diff] [blame] | 30 | static LIST_HEAD(dsa_tag_drivers_list); |
| 31 | static DEFINE_MUTEX(dsa_tag_drivers_lock); |
| 32 | |
Andrew Lunn | 39a7f2a | 2016-06-04 21:17:03 +0200 | [diff] [blame] | 33 | static struct sk_buff *dsa_slave_notag_xmit(struct sk_buff *skb, |
| 34 | struct net_device *dev) |
| 35 | { |
| 36 | /* Just return the original SKB */ |
| 37 | return skb; |
| 38 | } |
| 39 | |
| 40 | static const struct dsa_device_ops none_ops = { |
Andrew Lunn | 875138f | 2019-04-28 19:37:11 +0200 | [diff] [blame] | 41 | .name = "none", |
Andrew Lunn | 056eed2 | 2019-04-28 19:37:14 +0200 | [diff] [blame] | 42 | .proto = DSA_TAG_PROTO_NONE, |
Andrew Lunn | 39a7f2a | 2016-06-04 21:17:03 +0200 | [diff] [blame] | 43 | .xmit = dsa_slave_notag_xmit, |
| 44 | .rcv = NULL, |
| 45 | }; |
| 46 | |
Andrew Lunn | 409065b | 2019-04-28 19:37:17 +0200 | [diff] [blame^] | 47 | DSA_TAG_DRIVER(none_ops); |
| 48 | |
Andrew Lunn | 39a7f2a | 2016-06-04 21:17:03 +0200 | [diff] [blame] | 49 | const struct dsa_device_ops *dsa_device_ops[DSA_TAG_LAST] = { |
Andrew Lunn | eb7b721 | 2017-05-16 22:40:07 +0200 | [diff] [blame] | 50 | #ifdef CONFIG_NET_DSA_TAG_BRCM |
| 51 | [DSA_TAG_PROTO_BRCM] = &brcm_netdev_ops, |
| 52 | #endif |
Florian Fainelli | b74b70c | 2017-11-10 15:22:54 -0800 | [diff] [blame] | 53 | #ifdef CONFIG_NET_DSA_TAG_BRCM_PREPEND |
| 54 | [DSA_TAG_PROTO_BRCM_PREPEND] = &brcm_prepend_netdev_ops, |
| 55 | #endif |
Andrew Lunn | 39a7f2a | 2016-06-04 21:17:03 +0200 | [diff] [blame] | 56 | #ifdef CONFIG_NET_DSA_TAG_DSA |
| 57 | [DSA_TAG_PROTO_DSA] = &dsa_netdev_ops, |
| 58 | #endif |
| 59 | #ifdef CONFIG_NET_DSA_TAG_EDSA |
| 60 | [DSA_TAG_PROTO_EDSA] = &edsa_netdev_ops, |
| 61 | #endif |
Hauke Mehrtens | 7969119 | 2018-09-09 22:16:43 +0200 | [diff] [blame] | 62 | #ifdef CONFIG_NET_DSA_TAG_GSWIP |
| 63 | [DSA_TAG_PROTO_GSWIP] = &gswip_netdev_ops, |
| 64 | #endif |
Tristram Ha | 39d6b96 | 2018-12-15 01:58:04 +0100 | [diff] [blame] | 65 | #ifdef CONFIG_NET_DSA_TAG_KSZ9477 |
| 66 | [DSA_TAG_PROTO_KSZ9477] = &ksz9477_netdev_ops, |
Tristram Ha | 88b573a | 2019-02-28 19:57:23 -0800 | [diff] [blame] | 67 | [DSA_TAG_PROTO_KSZ9893] = &ksz9893_netdev_ops, |
Woojung Huh | 8b8010f | 2017-05-31 20:19:06 +0000 | [diff] [blame] | 68 | #endif |
Andrew Lunn | eb7b721 | 2017-05-16 22:40:07 +0200 | [diff] [blame] | 69 | #ifdef CONFIG_NET_DSA_TAG_LAN9303 |
| 70 | [DSA_TAG_PROTO_LAN9303] = &lan9303_netdev_ops, |
John Crispin | cafdc45 | 2016-09-15 16:26:40 +0200 | [diff] [blame] | 71 | #endif |
Sean Wang | 5cd8985 | 2017-04-07 16:45:06 +0800 | [diff] [blame] | 72 | #ifdef CONFIG_NET_DSA_TAG_MTK |
| 73 | [DSA_TAG_PROTO_MTK] = &mtk_netdev_ops, |
| 74 | #endif |
Andrew Lunn | eb7b721 | 2017-05-16 22:40:07 +0200 | [diff] [blame] | 75 | #ifdef CONFIG_NET_DSA_TAG_QCA |
| 76 | [DSA_TAG_PROTO_QCA] = &qca_netdev_ops, |
| 77 | #endif |
| 78 | #ifdef CONFIG_NET_DSA_TAG_TRAILER |
| 79 | [DSA_TAG_PROTO_TRAILER] = &trailer_netdev_ops, |
Juergen Beisert | e8fe177 | 2017-04-18 10:48:24 +0200 | [diff] [blame] | 80 | #endif |
Andrew Lunn | 39a7f2a | 2016-06-04 21:17:03 +0200 | [diff] [blame] | 81 | [DSA_TAG_PROTO_NONE] = &none_ops, |
| 82 | }; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 83 | |
Andrew Lunn | bdc6fe5 | 2019-04-28 19:37:16 +0200 | [diff] [blame] | 84 | static void dsa_tag_driver_register(struct dsa_tag_driver *dsa_tag_driver, |
| 85 | struct module *owner) |
| 86 | { |
| 87 | dsa_tag_driver->owner = owner; |
| 88 | |
| 89 | mutex_lock(&dsa_tag_drivers_lock); |
| 90 | list_add_tail(&dsa_tag_driver->list, &dsa_tag_drivers_list); |
| 91 | mutex_unlock(&dsa_tag_drivers_lock); |
| 92 | } |
| 93 | |
Andrew Lunn | d3b8c04 | 2019-04-28 19:37:15 +0200 | [diff] [blame] | 94 | void dsa_tag_drivers_register(struct dsa_tag_driver *dsa_tag_driver_array[], |
| 95 | unsigned int count, struct module *owner) |
| 96 | { |
Andrew Lunn | bdc6fe5 | 2019-04-28 19:37:16 +0200 | [diff] [blame] | 97 | unsigned int i; |
| 98 | |
| 99 | for (i = 0; i < count; i++) |
| 100 | dsa_tag_driver_register(dsa_tag_driver_array[i], owner); |
| 101 | } |
| 102 | |
| 103 | static void dsa_tag_driver_unregister(struct dsa_tag_driver *dsa_tag_driver) |
| 104 | { |
| 105 | mutex_lock(&dsa_tag_drivers_lock); |
| 106 | list_del(&dsa_tag_driver->list); |
| 107 | mutex_unlock(&dsa_tag_drivers_lock); |
Andrew Lunn | d3b8c04 | 2019-04-28 19:37:15 +0200 | [diff] [blame] | 108 | } |
| 109 | EXPORT_SYMBOL_GPL(dsa_tag_drivers_register); |
| 110 | |
| 111 | void dsa_tag_drivers_unregister(struct dsa_tag_driver *dsa_tag_driver_array[], |
| 112 | unsigned int count) |
| 113 | { |
Andrew Lunn | bdc6fe5 | 2019-04-28 19:37:16 +0200 | [diff] [blame] | 114 | unsigned int i; |
| 115 | |
| 116 | for (i = 0; i < count; i++) |
| 117 | dsa_tag_driver_unregister(dsa_tag_driver_array[i]); |
Andrew Lunn | d3b8c04 | 2019-04-28 19:37:15 +0200 | [diff] [blame] | 118 | } |
| 119 | EXPORT_SYMBOL_GPL(dsa_tag_drivers_unregister); |
| 120 | |
Florian Fainelli | 98cdb48 | 2018-09-07 11:09:02 -0700 | [diff] [blame] | 121 | const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops) |
| 122 | { |
Andrew Lunn | 875138f | 2019-04-28 19:37:11 +0200 | [diff] [blame] | 123 | return ops->name; |
Florian Fainelli | 98cdb48 | 2018-09-07 11:09:02 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
Andrew Lunn | 39a7f2a | 2016-06-04 21:17:03 +0200 | [diff] [blame] | 126 | const struct dsa_device_ops *dsa_resolve_tag_protocol(int tag_protocol) |
| 127 | { |
| 128 | const struct dsa_device_ops *ops; |
| 129 | |
| 130 | if (tag_protocol >= DSA_TAG_LAST) |
| 131 | return ERR_PTR(-EINVAL); |
| 132 | ops = dsa_device_ops[tag_protocol]; |
| 133 | |
| 134 | if (!ops) |
| 135 | return ERR_PTR(-ENOPROTOOPT); |
| 136 | |
| 137 | return ops; |
| 138 | } |
| 139 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 140 | static int dev_is_class(struct device *dev, void *class) |
| 141 | { |
| 142 | if (dev->class != NULL && !strcmp(dev->class->name, class)) |
| 143 | return 1; |
| 144 | |
| 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | static struct device *dev_find_class(struct device *parent, char *class) |
| 149 | { |
| 150 | if (dev_is_class(parent, class)) { |
| 151 | get_device(parent); |
| 152 | return parent; |
| 153 | } |
| 154 | |
| 155 | return device_find_child(parent, class, dev_is_class); |
| 156 | } |
| 157 | |
Florian Fainelli | 14b89f3 | 2017-02-04 13:02:42 -0800 | [diff] [blame] | 158 | struct net_device *dsa_dev_to_net_device(struct device *dev) |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 159 | { |
| 160 | struct device *d; |
| 161 | |
| 162 | d = dev_find_class(dev, "net"); |
| 163 | if (d != NULL) { |
| 164 | struct net_device *nd; |
| 165 | |
| 166 | nd = to_net_dev(d); |
| 167 | dev_hold(nd); |
| 168 | put_device(d); |
| 169 | |
| 170 | return nd; |
| 171 | } |
| 172 | |
| 173 | return NULL; |
| 174 | } |
Florian Fainelli | 14b89f3 | 2017-02-04 13:02:42 -0800 | [diff] [blame] | 175 | EXPORT_SYMBOL_GPL(dsa_dev_to_net_device); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 176 | |
Brandon Streiff | 90af105 | 2018-02-14 01:07:49 +0100 | [diff] [blame] | 177 | /* Determine if we should defer delivery of skb until we have a rx timestamp. |
| 178 | * |
| 179 | * Called from dsa_switch_rcv. For now, this will only work if tagging is |
| 180 | * enabled on the switch. Normally the MAC driver would retrieve the hardware |
| 181 | * timestamp when it reads the packet out of the hardware. However in a DSA |
| 182 | * switch, the DSA driver owning the interface to which the packet is |
| 183 | * delivered is never notified unless we do so here. |
| 184 | */ |
| 185 | static bool dsa_skb_defer_rx_timestamp(struct dsa_slave_priv *p, |
| 186 | struct sk_buff *skb) |
| 187 | { |
| 188 | struct dsa_switch *ds = p->dp->ds; |
| 189 | unsigned int type; |
| 190 | |
| 191 | if (skb_headroom(skb) < ETH_HLEN) |
| 192 | return false; |
| 193 | |
| 194 | __skb_push(skb, ETH_HLEN); |
| 195 | |
| 196 | type = ptp_classify_raw(skb); |
| 197 | |
| 198 | __skb_pull(skb, ETH_HLEN); |
| 199 | |
| 200 | if (type == PTP_CLASS_NONE) |
| 201 | return false; |
| 202 | |
| 203 | if (likely(ds->ops->port_rxtstamp)) |
| 204 | return ds->ops->port_rxtstamp(ds, p->dp->index, skb, type); |
| 205 | |
| 206 | return false; |
| 207 | } |
| 208 | |
Florian Fainelli | 3e8a72d | 2014-08-27 17:04:46 -0700 | [diff] [blame] | 209 | static int dsa_switch_rcv(struct sk_buff *skb, struct net_device *dev, |
Florian Westphal | 89e4950 | 2017-08-17 16:47:00 +0200 | [diff] [blame] | 210 | struct packet_type *pt, struct net_device *unused) |
Florian Fainelli | 3e8a72d | 2014-08-27 17:04:46 -0700 | [diff] [blame] | 211 | { |
Vivien Didelot | 2f657a6 | 2017-09-29 17:19:20 -0400 | [diff] [blame] | 212 | struct dsa_port *cpu_dp = dev->dsa_ptr; |
Florian Fainelli | a86d8be | 2017-04-08 08:55:23 -0700 | [diff] [blame] | 213 | struct sk_buff *nskb = NULL; |
Florian Fainelli | 5f6b4e14 | 2017-08-03 21:33:27 -0700 | [diff] [blame] | 214 | struct pcpu_sw_netstats *s; |
Florian Fainelli | f613ed6 | 2017-08-01 15:00:36 -0700 | [diff] [blame] | 215 | struct dsa_slave_priv *p; |
Florian Fainelli | 3e8a72d | 2014-08-27 17:04:46 -0700 | [diff] [blame] | 216 | |
Vivien Didelot | 2f657a6 | 2017-09-29 17:19:20 -0400 | [diff] [blame] | 217 | if (unlikely(!cpu_dp)) { |
Florian Fainelli | 3e8a72d | 2014-08-27 17:04:46 -0700 | [diff] [blame] | 218 | kfree_skb(skb); |
| 219 | return 0; |
| 220 | } |
| 221 | |
Florian Fainelli | 16c5dcb | 2017-04-08 08:55:22 -0700 | [diff] [blame] | 222 | skb = skb_unshare(skb, GFP_ATOMIC); |
| 223 | if (!skb) |
| 224 | return 0; |
| 225 | |
Vivien Didelot | 2f657a6 | 2017-09-29 17:19:20 -0400 | [diff] [blame] | 226 | nskb = cpu_dp->rcv(skb, dev, pt); |
Florian Fainelli | a86d8be | 2017-04-08 08:55:23 -0700 | [diff] [blame] | 227 | if (!nskb) { |
| 228 | kfree_skb(skb); |
| 229 | return 0; |
| 230 | } |
| 231 | |
| 232 | skb = nskb; |
Florian Fainelli | f613ed6 | 2017-08-01 15:00:36 -0700 | [diff] [blame] | 233 | p = netdev_priv(skb->dev); |
Florian Fainelli | a86d8be | 2017-04-08 08:55:23 -0700 | [diff] [blame] | 234 | skb_push(skb, ETH_HLEN); |
| 235 | skb->pkt_type = PACKET_HOST; |
| 236 | skb->protocol = eth_type_trans(skb, skb->dev); |
| 237 | |
Florian Fainelli | 5f6b4e14 | 2017-08-03 21:33:27 -0700 | [diff] [blame] | 238 | s = this_cpu_ptr(p->stats64); |
| 239 | u64_stats_update_begin(&s->syncp); |
| 240 | s->rx_packets++; |
| 241 | s->rx_bytes += skb->len; |
| 242 | u64_stats_update_end(&s->syncp); |
Florian Fainelli | a86d8be | 2017-04-08 08:55:23 -0700 | [diff] [blame] | 243 | |
Brandon Streiff | 90af105 | 2018-02-14 01:07:49 +0100 | [diff] [blame] | 244 | if (dsa_skb_defer_rx_timestamp(p, skb)) |
| 245 | return 0; |
| 246 | |
Florian Fainelli | a86d8be | 2017-04-08 08:55:23 -0700 | [diff] [blame] | 247 | netif_receive_skb(skb); |
| 248 | |
| 249 | return 0; |
Florian Fainelli | 3e8a72d | 2014-08-27 17:04:46 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Florian Fainelli | ac2629a | 2017-06-01 19:53:04 -0700 | [diff] [blame] | 252 | #ifdef CONFIG_PM_SLEEP |
Vivien Didelot | e7d53ad | 2017-07-18 16:23:56 -0400 | [diff] [blame] | 253 | static bool dsa_is_port_initialized(struct dsa_switch *ds, int p) |
| 254 | { |
Vivien Didelot | 4a5b85f | 2017-10-26 11:22:55 -0400 | [diff] [blame] | 255 | return dsa_is_user_port(ds, p) && ds->ports[p].slave; |
Vivien Didelot | e7d53ad | 2017-07-18 16:23:56 -0400 | [diff] [blame] | 256 | } |
| 257 | |
Florian Fainelli | ac2629a | 2017-06-01 19:53:04 -0700 | [diff] [blame] | 258 | int dsa_switch_suspend(struct dsa_switch *ds) |
| 259 | { |
| 260 | int i, ret = 0; |
| 261 | |
| 262 | /* Suspend slave network devices */ |
| 263 | for (i = 0; i < ds->num_ports; i++) { |
| 264 | if (!dsa_is_port_initialized(ds, i)) |
| 265 | continue; |
| 266 | |
Vivien Didelot | f8b8b1c | 2017-10-16 11:12:18 -0400 | [diff] [blame] | 267 | ret = dsa_slave_suspend(ds->ports[i].slave); |
Florian Fainelli | ac2629a | 2017-06-01 19:53:04 -0700 | [diff] [blame] | 268 | if (ret) |
| 269 | return ret; |
| 270 | } |
| 271 | |
| 272 | if (ds->ops->suspend) |
| 273 | ret = ds->ops->suspend(ds); |
| 274 | |
| 275 | return ret; |
| 276 | } |
| 277 | EXPORT_SYMBOL_GPL(dsa_switch_suspend); |
| 278 | |
| 279 | int dsa_switch_resume(struct dsa_switch *ds) |
| 280 | { |
| 281 | int i, ret = 0; |
| 282 | |
| 283 | if (ds->ops->resume) |
| 284 | ret = ds->ops->resume(ds); |
| 285 | |
| 286 | if (ret) |
| 287 | return ret; |
| 288 | |
| 289 | /* Resume slave network devices */ |
| 290 | for (i = 0; i < ds->num_ports; i++) { |
| 291 | if (!dsa_is_port_initialized(ds, i)) |
| 292 | continue; |
| 293 | |
Vivien Didelot | f8b8b1c | 2017-10-16 11:12:18 -0400 | [diff] [blame] | 294 | ret = dsa_slave_resume(ds->ports[i].slave); |
Florian Fainelli | ac2629a | 2017-06-01 19:53:04 -0700 | [diff] [blame] | 295 | if (ret) |
| 296 | return ret; |
| 297 | } |
| 298 | |
| 299 | return 0; |
| 300 | } |
| 301 | EXPORT_SYMBOL_GPL(dsa_switch_resume); |
| 302 | #endif |
| 303 | |
Florian Fainelli | 61b7363 | 2014-08-29 12:42:07 -0700 | [diff] [blame] | 304 | static struct packet_type dsa_pack_type __read_mostly = { |
Florian Fainelli | 3e8a72d | 2014-08-27 17:04:46 -0700 | [diff] [blame] | 305 | .type = cpu_to_be16(ETH_P_XDSA), |
| 306 | .func = dsa_switch_rcv, |
| 307 | }; |
| 308 | |
Arkadi Sharshevsky | c9eb3e0 | 2017-08-06 16:15:42 +0300 | [diff] [blame] | 309 | static struct workqueue_struct *dsa_owq; |
| 310 | |
| 311 | bool dsa_schedule_work(struct work_struct *work) |
| 312 | { |
| 313 | return queue_work(dsa_owq, work); |
| 314 | } |
| 315 | |
Florian Fainelli | 60724d4 | 2017-10-11 10:57:48 -0700 | [diff] [blame] | 316 | static ATOMIC_NOTIFIER_HEAD(dsa_notif_chain); |
| 317 | |
| 318 | int register_dsa_notifier(struct notifier_block *nb) |
| 319 | { |
| 320 | return atomic_notifier_chain_register(&dsa_notif_chain, nb); |
| 321 | } |
| 322 | EXPORT_SYMBOL_GPL(register_dsa_notifier); |
| 323 | |
| 324 | int unregister_dsa_notifier(struct notifier_block *nb) |
| 325 | { |
| 326 | return atomic_notifier_chain_unregister(&dsa_notif_chain, nb); |
| 327 | } |
| 328 | EXPORT_SYMBOL_GPL(unregister_dsa_notifier); |
| 329 | |
| 330 | int call_dsa_notifiers(unsigned long val, struct net_device *dev, |
| 331 | struct dsa_notifier_info *info) |
| 332 | { |
| 333 | info->dev = dev; |
| 334 | return atomic_notifier_call_chain(&dsa_notif_chain, val, info); |
| 335 | } |
| 336 | EXPORT_SYMBOL_GPL(call_dsa_notifiers); |
| 337 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 338 | static int __init dsa_init_module(void) |
| 339 | { |
Ben Hutchings | 7df899c | 2011-11-25 14:35:02 +0000 | [diff] [blame] | 340 | int rc; |
| 341 | |
Arkadi Sharshevsky | c9eb3e0 | 2017-08-06 16:15:42 +0300 | [diff] [blame] | 342 | dsa_owq = alloc_ordered_workqueue("dsa_ordered", |
| 343 | WQ_MEM_RECLAIM); |
| 344 | if (!dsa_owq) |
| 345 | return -ENOMEM; |
| 346 | |
Vivien Didelot | 88e4f0c | 2017-02-03 13:20:16 -0500 | [diff] [blame] | 347 | rc = dsa_slave_register_notifier(); |
| 348 | if (rc) |
| 349 | return rc; |
Florian Fainelli | b73adef | 2015-02-24 13:15:33 -0800 | [diff] [blame] | 350 | |
Vivien Didelot | a6a71f1 | 2017-04-12 12:45:03 -0400 | [diff] [blame] | 351 | rc = dsa_legacy_register(); |
Ben Hutchings | 7df899c | 2011-11-25 14:35:02 +0000 | [diff] [blame] | 352 | if (rc) |
| 353 | return rc; |
| 354 | |
Florian Fainelli | 3e8a72d | 2014-08-27 17:04:46 -0700 | [diff] [blame] | 355 | dev_add_pack(&dsa_pack_type); |
| 356 | |
Andrew Lunn | 409065b | 2019-04-28 19:37:17 +0200 | [diff] [blame^] | 357 | dsa_tag_driver_register(&DSA_TAG_DRIVER_NAME(none_ops), |
| 358 | THIS_MODULE); |
| 359 | |
Ben Hutchings | 7df899c | 2011-11-25 14:35:02 +0000 | [diff] [blame] | 360 | return 0; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 361 | } |
| 362 | module_init(dsa_init_module); |
| 363 | |
| 364 | static void __exit dsa_cleanup_module(void) |
| 365 | { |
Andrew Lunn | 409065b | 2019-04-28 19:37:17 +0200 | [diff] [blame^] | 366 | dsa_tag_driver_unregister(&DSA_TAG_DRIVER_NAME(none_ops)); |
| 367 | |
Vivien Didelot | 88e4f0c | 2017-02-03 13:20:16 -0500 | [diff] [blame] | 368 | dsa_slave_unregister_notifier(); |
Florian Fainelli | 3e8a72d | 2014-08-27 17:04:46 -0700 | [diff] [blame] | 369 | dev_remove_pack(&dsa_pack_type); |
Vivien Didelot | a6a71f1 | 2017-04-12 12:45:03 -0400 | [diff] [blame] | 370 | dsa_legacy_unregister(); |
Arkadi Sharshevsky | c9eb3e0 | 2017-08-06 16:15:42 +0300 | [diff] [blame] | 371 | destroy_workqueue(dsa_owq); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 372 | } |
| 373 | module_exit(dsa_cleanup_module); |
| 374 | |
Rusty Russell | 577d6a7 | 2011-01-24 14:32:52 -0600 | [diff] [blame] | 375 | MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>"); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 376 | MODULE_DESCRIPTION("Driver for Distributed Switch Architecture switch chips"); |
| 377 | MODULE_LICENSE("GPL"); |
| 378 | MODULE_ALIAS("platform:dsa"); |