blob: 14fac4ed956939723cb87498a8e53b1b94135cb9 [file] [log] [blame]
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001/*
2 * net/dsa/dsa.c - Hardware switch handling
Lennert Buytenheke84665c2009-03-20 09:52:09 +00003 * Copyright (c) 2008-2009 Marvell Semiconductor
Florian Fainelli5e95329b2013-03-22 10:50:50 +00004 * Copyright (c) 2013 Florian Fainelli <florian@openwrt.org>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00005 *
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 Roeck51579c32014-10-29 10:44:58 -070012#include <linux/ctype.h>
13#include <linux/device.h>
14#include <linux/hwmon.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000015#include <linux/list.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000016#include <linux/platform_device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090017#include <linux/slab.h>
Paul Gortmaker3a9a2312011-05-27 09:12:25 -040018#include <linux/module.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000019#include <net/dsa.h>
Florian Fainelli5e95329b2013-03-22 10:50:50 +000020#include <linux/of.h>
21#include <linux/of_mdio.h>
22#include <linux/of_platform.h>
Florian Fainelli769a0202015-03-09 14:31:21 -070023#include <linux/of_net.h>
Guenter Roeck51579c32014-10-29 10:44:58 -070024#include <linux/sysfs.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000025#include "dsa_priv.h"
26
27char dsa_driver_version[] = "0.1";
28
29
30/* switch driver registration ***********************************************/
31static DEFINE_MUTEX(dsa_switch_drivers_mutex);
32static LIST_HEAD(dsa_switch_drivers);
33
34void register_switch_driver(struct dsa_switch_driver *drv)
35{
36 mutex_lock(&dsa_switch_drivers_mutex);
37 list_add_tail(&drv->list, &dsa_switch_drivers);
38 mutex_unlock(&dsa_switch_drivers_mutex);
39}
Ben Hutchingsad293b82011-11-25 14:34:07 +000040EXPORT_SYMBOL_GPL(register_switch_driver);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000041
42void unregister_switch_driver(struct dsa_switch_driver *drv)
43{
44 mutex_lock(&dsa_switch_drivers_mutex);
45 list_del_init(&drv->list);
46 mutex_unlock(&dsa_switch_drivers_mutex);
47}
Ben Hutchingsad293b82011-11-25 14:34:07 +000048EXPORT_SYMBOL_GPL(unregister_switch_driver);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000049
50static struct dsa_switch_driver *
Alexander Duyckb4d23942014-09-15 13:00:27 -040051dsa_switch_probe(struct device *host_dev, int sw_addr, char **_name)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000052{
53 struct dsa_switch_driver *ret;
54 struct list_head *list;
55 char *name;
56
57 ret = NULL;
58 name = NULL;
59
60 mutex_lock(&dsa_switch_drivers_mutex);
61 list_for_each(list, &dsa_switch_drivers) {
62 struct dsa_switch_driver *drv;
63
64 drv = list_entry(list, struct dsa_switch_driver, list);
65
Alexander Duyckb4d23942014-09-15 13:00:27 -040066 name = drv->probe(host_dev, sw_addr);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000067 if (name != NULL) {
68 ret = drv;
69 break;
70 }
71 }
72 mutex_unlock(&dsa_switch_drivers_mutex);
73
74 *_name = name;
75
76 return ret;
77}
78
Guenter Roeck51579c32014-10-29 10:44:58 -070079/* hwmon support ************************************************************/
80
81#ifdef CONFIG_NET_DSA_HWMON
82
83static ssize_t temp1_input_show(struct device *dev,
84 struct device_attribute *attr, char *buf)
85{
86 struct dsa_switch *ds = dev_get_drvdata(dev);
87 int temp, ret;
88
89 ret = ds->drv->get_temp(ds, &temp);
90 if (ret < 0)
91 return ret;
92
93 return sprintf(buf, "%d\n", temp * 1000);
94}
95static DEVICE_ATTR_RO(temp1_input);
96
97static ssize_t temp1_max_show(struct device *dev,
98 struct device_attribute *attr, char *buf)
99{
100 struct dsa_switch *ds = dev_get_drvdata(dev);
101 int temp, ret;
102
103 ret = ds->drv->get_temp_limit(ds, &temp);
104 if (ret < 0)
105 return ret;
106
107 return sprintf(buf, "%d\n", temp * 1000);
108}
109
110static ssize_t temp1_max_store(struct device *dev,
111 struct device_attribute *attr, const char *buf,
112 size_t count)
113{
114 struct dsa_switch *ds = dev_get_drvdata(dev);
115 int temp, ret;
116
117 ret = kstrtoint(buf, 0, &temp);
118 if (ret < 0)
119 return ret;
120
121 ret = ds->drv->set_temp_limit(ds, DIV_ROUND_CLOSEST(temp, 1000));
122 if (ret < 0)
123 return ret;
124
125 return count;
126}
Vivien Didelote3122b72015-04-17 15:12:25 -0400127static DEVICE_ATTR_RW(temp1_max);
Guenter Roeck51579c32014-10-29 10:44:58 -0700128
129static ssize_t temp1_max_alarm_show(struct device *dev,
130 struct device_attribute *attr, char *buf)
131{
132 struct dsa_switch *ds = dev_get_drvdata(dev);
133 bool alarm;
134 int ret;
135
136 ret = ds->drv->get_temp_alarm(ds, &alarm);
137 if (ret < 0)
138 return ret;
139
140 return sprintf(buf, "%d\n", alarm);
141}
142static DEVICE_ATTR_RO(temp1_max_alarm);
143
144static struct attribute *dsa_hwmon_attrs[] = {
145 &dev_attr_temp1_input.attr, /* 0 */
146 &dev_attr_temp1_max.attr, /* 1 */
147 &dev_attr_temp1_max_alarm.attr, /* 2 */
148 NULL
149};
150
151static umode_t dsa_hwmon_attrs_visible(struct kobject *kobj,
152 struct attribute *attr, int index)
153{
154 struct device *dev = container_of(kobj, struct device, kobj);
155 struct dsa_switch *ds = dev_get_drvdata(dev);
156 struct dsa_switch_driver *drv = ds->drv;
157 umode_t mode = attr->mode;
158
159 if (index == 1) {
160 if (!drv->get_temp_limit)
161 mode = 0;
Vivien Didelote3122b72015-04-17 15:12:25 -0400162 else if (!drv->set_temp_limit)
163 mode &= ~S_IWUSR;
Guenter Roeck51579c32014-10-29 10:44:58 -0700164 } else if (index == 2 && !drv->get_temp_alarm) {
165 mode = 0;
166 }
167 return mode;
168}
169
170static const struct attribute_group dsa_hwmon_group = {
171 .attrs = dsa_hwmon_attrs,
172 .is_visible = dsa_hwmon_attrs_visible,
173};
174__ATTRIBUTE_GROUPS(dsa_hwmon);
175
176#endif /* CONFIG_NET_DSA_HWMON */
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000177
178/* basic switch operations **************************************************/
Andrew Lunn39b0c702015-08-31 15:56:49 +0200179static int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct net_device *master)
180{
181 struct dsa_chip_data *cd = ds->pd;
182 struct device_node *port_dn;
183 struct phy_device *phydev;
Andrew Lunne4485342015-08-31 15:56:50 +0200184 int ret, port, mode;
Andrew Lunn39b0c702015-08-31 15:56:49 +0200185
186 for (port = 0; port < DSA_MAX_PORTS; port++) {
187 if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)))
188 continue;
189
190 port_dn = cd->port_dn[port];
191 if (of_phy_is_fixed_link(port_dn)) {
192 ret = of_phy_register_fixed_link(port_dn);
193 if (ret) {
194 netdev_err(master,
195 "failed to register fixed PHY\n");
196 return ret;
197 }
198 phydev = of_phy_find_device(port_dn);
Andrew Lunne4485342015-08-31 15:56:50 +0200199
200 mode = of_get_phy_mode(port_dn);
201 if (mode < 0)
202 mode = PHY_INTERFACE_MODE_NA;
203 phydev->interface = mode;
204
Andrew Lunn39b0c702015-08-31 15:56:49 +0200205 genphy_config_init(phydev);
206 genphy_read_status(phydev);
207 if (ds->drv->adjust_link)
208 ds->drv->adjust_link(ds, port, phydev);
209 }
210 }
211 return 0;
212}
213
Florian Fainellidf197192015-03-05 12:35:06 -0800214static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000215{
Florian Fainellidf197192015-03-05 12:35:06 -0800216 struct dsa_switch_driver *drv = ds->drv;
217 struct dsa_switch_tree *dst = ds->dst;
218 struct dsa_chip_data *pd = ds->pd;
Florian Fainellif9bf5a22013-01-21 09:58:51 +0000219 bool valid_name_found = false;
Florian Fainellidf197192015-03-05 12:35:06 -0800220 int index = ds->index;
221 int i, ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000222
223 /*
224 * Validate supplied switch configuration.
225 */
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000226 for (i = 0; i < DSA_MAX_PORTS; i++) {
227 char *name;
228
229 name = pd->port_names[i];
230 if (name == NULL)
231 continue;
232
233 if (!strcmp(name, "cpu")) {
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000234 if (dst->cpu_switch != -1) {
Joe Perchesa2ae6002014-11-09 16:32:46 -0800235 netdev_err(dst->master_netdev,
236 "multiple cpu ports?!\n");
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000237 ret = -EINVAL;
238 goto out;
239 }
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000240 dst->cpu_switch = index;
241 dst->cpu_port = i;
242 } else if (!strcmp(name, "dsa")) {
243 ds->dsa_port_mask |= 1 << i;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000244 } else {
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000245 ds->phys_port_mask |= 1 << i;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000246 }
Florian Fainellif9bf5a22013-01-21 09:58:51 +0000247 valid_name_found = true;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000248 }
249
Florian Fainellif9bf5a22013-01-21 09:58:51 +0000250 if (!valid_name_found && i == DSA_MAX_PORTS) {
251 ret = -EINVAL;
252 goto out;
253 }
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000254
Florian Fainelli0d8bcdd2014-08-27 17:04:51 -0700255 /* Make the built-in MII bus mask match the number of ports,
256 * switch drivers can override this later
257 */
258 ds->phys_mii_mask = ds->phys_port_mask;
259
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000260 /*
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000261 * If the CPU connects to this switch, set the switch tree
262 * tagging protocol to the preferred tagging format of this
263 * switch.
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000264 */
Alexander Duyck50753142014-09-15 13:00:19 -0400265 if (dst->cpu_switch == index) {
Florian Fainelli59299032015-03-05 12:35:07 -0800266 switch (ds->tag_protocol) {
Alexander Duyck50753142014-09-15 13:00:19 -0400267#ifdef CONFIG_NET_DSA_TAG_DSA
268 case DSA_TAG_PROTO_DSA:
269 dst->rcv = dsa_netdev_ops.rcv;
270 break;
271#endif
272#ifdef CONFIG_NET_DSA_TAG_EDSA
273 case DSA_TAG_PROTO_EDSA:
274 dst->rcv = edsa_netdev_ops.rcv;
275 break;
276#endif
277#ifdef CONFIG_NET_DSA_TAG_TRAILER
278 case DSA_TAG_PROTO_TRAILER:
279 dst->rcv = trailer_netdev_ops.rcv;
280 break;
281#endif
282#ifdef CONFIG_NET_DSA_TAG_BRCM
283 case DSA_TAG_PROTO_BRCM:
284 dst->rcv = brcm_netdev_ops.rcv;
285 break;
286#endif
Andrew Lunnae439282014-10-24 23:44:04 +0200287 case DSA_TAG_PROTO_NONE:
Alexander Duyck50753142014-09-15 13:00:19 -0400288 break;
Andrew Lunnae439282014-10-24 23:44:04 +0200289 default:
290 ret = -ENOPROTOOPT;
291 goto out;
Alexander Duyck50753142014-09-15 13:00:19 -0400292 }
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000293
Florian Fainelli59299032015-03-05 12:35:07 -0800294 dst->tag_protocol = ds->tag_protocol;
Alexander Duyck50753142014-09-15 13:00:19 -0400295 }
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000296
297 /*
298 * Do basic register setup.
299 */
300 ret = drv->setup(ds);
301 if (ret < 0)
302 goto out;
303
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000304 ret = drv->set_addr(ds, dst->master_netdev->dev_addr);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000305 if (ret < 0)
306 goto out;
307
308 ds->slave_mii_bus = mdiobus_alloc();
309 if (ds->slave_mii_bus == NULL) {
310 ret = -ENOMEM;
311 goto out;
312 }
313 dsa_slave_mii_bus_init(ds);
314
315 ret = mdiobus_register(ds->slave_mii_bus);
316 if (ret < 0)
317 goto out_free;
318
319
320 /*
321 * Create network devices for physical switch ports.
322 */
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000323 for (i = 0; i < DSA_MAX_PORTS; i++) {
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000324 if (!(ds->phys_port_mask & (1 << i)))
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000325 continue;
326
Guenter Roeckd87d6f42015-02-24 13:15:32 -0800327 ret = dsa_slave_create(ds, parent, i, pd->port_names[i]);
328 if (ret < 0) {
Joe Perchesa2ae6002014-11-09 16:32:46 -0800329 netdev_err(dst->master_netdev, "[%d]: can't create dsa slave device for port %d(%s)\n",
330 index, i, pd->port_names[i]);
Guenter Roeckd87d6f42015-02-24 13:15:32 -0800331 ret = 0;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000332 }
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000333 }
334
Andrew Lunn39b0c702015-08-31 15:56:49 +0200335 /* Perform configuration of the CPU and DSA ports */
336 ret = dsa_cpu_dsa_setup(ds, dst->master_netdev);
337 if (ret < 0) {
338 netdev_err(dst->master_netdev, "[%d] : can't configure CPU and DSA ports\n",
339 index);
340 ret = 0;
341 }
342
Guenter Roeck51579c32014-10-29 10:44:58 -0700343#ifdef CONFIG_NET_DSA_HWMON
344 /* If the switch provides a temperature sensor,
345 * register with hardware monitoring subsystem.
346 * Treat registration error as non-fatal and ignore it.
347 */
348 if (drv->get_temp) {
349 const char *netname = netdev_name(dst->master_netdev);
350 char hname[IFNAMSIZ + 1];
351 int i, j;
352
353 /* Create valid hwmon 'name' attribute */
354 for (i = j = 0; i < IFNAMSIZ && netname[i]; i++) {
355 if (isalnum(netname[i]))
356 hname[j++] = netname[i];
357 }
358 hname[j] = '\0';
359 scnprintf(ds->hwmon_name, sizeof(ds->hwmon_name), "%s_dsa%d",
360 hname, index);
361 ds->hwmon_dev = hwmon_device_register_with_groups(NULL,
362 ds->hwmon_name, ds, dsa_hwmon_groups);
363 if (IS_ERR(ds->hwmon_dev))
364 ds->hwmon_dev = NULL;
365 }
366#endif /* CONFIG_NET_DSA_HWMON */
367
Florian Fainellidf197192015-03-05 12:35:06 -0800368 return ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000369
370out_free:
371 mdiobus_free(ds->slave_mii_bus);
372out:
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000373 kfree(ds);
Florian Fainellidf197192015-03-05 12:35:06 -0800374 return ret;
375}
376
377static struct dsa_switch *
378dsa_switch_setup(struct dsa_switch_tree *dst, int index,
379 struct device *parent, struct device *host_dev)
380{
381 struct dsa_chip_data *pd = dst->pd->chip + index;
382 struct dsa_switch_driver *drv;
383 struct dsa_switch *ds;
384 int ret;
385 char *name;
386
387 /*
388 * Probe for switch model.
389 */
390 drv = dsa_switch_probe(host_dev, pd->sw_addr, &name);
391 if (drv == NULL) {
392 netdev_err(dst->master_netdev, "[%d]: could not detect attached switch\n",
393 index);
394 return ERR_PTR(-EINVAL);
395 }
396 netdev_info(dst->master_netdev, "[%d]: detected a %s switch\n",
397 index, name);
398
399
400 /*
401 * Allocate and initialise switch state.
402 */
403 ds = kzalloc(sizeof(*ds) + drv->priv_size, GFP_KERNEL);
404 if (ds == NULL)
Florian Fainelli24595342015-05-29 10:29:46 -0700405 return ERR_PTR(-ENOMEM);
Florian Fainellidf197192015-03-05 12:35:06 -0800406
407 ds->dst = dst;
408 ds->index = index;
409 ds->pd = pd;
410 ds->drv = drv;
Florian Fainelli59299032015-03-05 12:35:07 -0800411 ds->tag_protocol = drv->tag_protocol;
Florian Fainellidf197192015-03-05 12:35:06 -0800412 ds->master_dev = host_dev;
413
414 ret = dsa_switch_setup_one(ds, parent);
415 if (ret)
Florian Fainelli24595342015-05-29 10:29:46 -0700416 return ERR_PTR(ret);
Florian Fainellidf197192015-03-05 12:35:06 -0800417
418 return ds;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000419}
420
421static void dsa_switch_destroy(struct dsa_switch *ds)
422{
Guenter Roeck51579c32014-10-29 10:44:58 -0700423#ifdef CONFIG_NET_DSA_HWMON
424 if (ds->hwmon_dev)
425 hwmon_device_unregister(ds->hwmon_dev);
426#endif
Neil Armstronge410ddb2015-10-06 15:40:25 +0100427 mdiobus_unregister(ds->slave_mii_bus);
428 mdiobus_free(ds->slave_mii_bus);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000429}
430
Thierry Redinge506d402014-10-01 13:59:00 +0200431#ifdef CONFIG_PM_SLEEP
Florian Fainelli24462542014-09-18 17:31:22 -0700432static int dsa_switch_suspend(struct dsa_switch *ds)
433{
434 int i, ret = 0;
435
436 /* Suspend slave network devices */
437 for (i = 0; i < DSA_MAX_PORTS; i++) {
Guenter Roeckd79d2102015-02-24 23:02:02 -0800438 if (!dsa_is_port_initialized(ds, i))
Florian Fainelli24462542014-09-18 17:31:22 -0700439 continue;
440
441 ret = dsa_slave_suspend(ds->ports[i]);
442 if (ret)
443 return ret;
444 }
445
446 if (ds->drv->suspend)
447 ret = ds->drv->suspend(ds);
448
449 return ret;
450}
451
452static int dsa_switch_resume(struct dsa_switch *ds)
453{
454 int i, ret = 0;
455
456 if (ds->drv->resume)
457 ret = ds->drv->resume(ds);
458
459 if (ret)
460 return ret;
461
462 /* Resume slave network devices */
463 for (i = 0; i < DSA_MAX_PORTS; i++) {
Guenter Roeckd79d2102015-02-24 23:02:02 -0800464 if (!dsa_is_port_initialized(ds, i))
Florian Fainelli24462542014-09-18 17:31:22 -0700465 continue;
466
467 ret = dsa_slave_resume(ds->ports[i]);
468 if (ret)
469 return ret;
470 }
471
472 return 0;
473}
Thierry Redinge506d402014-10-01 13:59:00 +0200474#endif
Florian Fainelli24462542014-09-18 17:31:22 -0700475
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000476
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000477/* link polling *************************************************************/
478static void dsa_link_poll_work(struct work_struct *ugly)
479{
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000480 struct dsa_switch_tree *dst;
481 int i;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000482
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000483 dst = container_of(ugly, struct dsa_switch_tree, link_poll_work);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000484
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000485 for (i = 0; i < dst->pd->nr_chips; i++) {
486 struct dsa_switch *ds = dst->ds[i];
487
488 if (ds != NULL && ds->drv->poll_link != NULL)
489 ds->drv->poll_link(ds);
490 }
491
492 mod_timer(&dst->link_poll_timer, round_jiffies(jiffies + HZ));
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000493}
494
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000495static void dsa_link_poll_timer(unsigned long _dst)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000496{
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000497 struct dsa_switch_tree *dst = (void *)_dst;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000498
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000499 schedule_work(&dst->link_poll_work);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000500}
501
502
503/* platform driver init and cleanup *****************************************/
504static int dev_is_class(struct device *dev, void *class)
505{
506 if (dev->class != NULL && !strcmp(dev->class->name, class))
507 return 1;
508
509 return 0;
510}
511
512static struct device *dev_find_class(struct device *parent, char *class)
513{
514 if (dev_is_class(parent, class)) {
515 get_device(parent);
516 return parent;
517 }
518
519 return device_find_child(parent, class, dev_is_class);
520}
521
Alexander Duyckb4d23942014-09-15 13:00:27 -0400522struct mii_bus *dsa_host_dev_to_mii_bus(struct device *dev)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000523{
524 struct device *d;
525
526 d = dev_find_class(dev, "mdio_bus");
527 if (d != NULL) {
528 struct mii_bus *bus;
529
530 bus = to_mii_bus(d);
531 put_device(d);
532
533 return bus;
534 }
535
536 return NULL;
537}
Alexander Duyckb4d23942014-09-15 13:00:27 -0400538EXPORT_SYMBOL_GPL(dsa_host_dev_to_mii_bus);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000539
540static struct net_device *dev_to_net_device(struct device *dev)
541{
542 struct device *d;
543
544 d = dev_find_class(dev, "net");
545 if (d != NULL) {
546 struct net_device *nd;
547
548 nd = to_net_dev(d);
549 dev_hold(nd);
550 put_device(d);
551
552 return nd;
553 }
554
555 return NULL;
556}
557
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000558#ifdef CONFIG_OF
559static int dsa_of_setup_routing_table(struct dsa_platform_data *pd,
560 struct dsa_chip_data *cd,
Pavel Nakonechny30303812015-04-05 00:46:21 +0300561 int chip_index, int port_index,
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000562 struct device_node *link)
563{
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000564 const __be32 *reg;
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000565 int link_sw_addr;
566 struct device_node *parent_sw;
567 int len;
568
569 parent_sw = of_get_parent(link);
570 if (!parent_sw)
571 return -EINVAL;
572
573 reg = of_get_property(parent_sw, "reg", &len);
574 if (!reg || (len != sizeof(*reg) * 2))
575 return -EINVAL;
576
Pavel Nakonechny30303812015-04-05 00:46:21 +0300577 /*
578 * Get the destination switch number from the second field of its 'reg'
579 * property, i.e. for "reg = <0x19 1>" sw_addr is '1'.
580 */
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000581 link_sw_addr = be32_to_cpup(reg + 1);
582
583 if (link_sw_addr >= pd->nr_chips)
584 return -EINVAL;
585
586 /* First time routing table allocation */
587 if (!cd->rtable) {
Fabian Frederick5bc4b462014-11-14 19:36:42 +0100588 cd->rtable = kmalloc_array(pd->nr_chips, sizeof(s8),
589 GFP_KERNEL);
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000590 if (!cd->rtable)
591 return -ENOMEM;
592
593 /* default to no valid uplink/downlink */
594 memset(cd->rtable, -1, pd->nr_chips * sizeof(s8));
595 }
596
Pavel Nakonechny30303812015-04-05 00:46:21 +0300597 cd->rtable[link_sw_addr] = port_index;
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000598
599 return 0;
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000600}
601
Andrew Lunn1e72e6f2015-08-17 23:52:50 +0200602static int dsa_of_probe_links(struct dsa_platform_data *pd,
603 struct dsa_chip_data *cd,
604 int chip_index, int port_index,
605 struct device_node *port,
606 const char *port_name)
607{
608 struct device_node *link;
609 int link_index;
610 int ret;
611
612 for (link_index = 0;; link_index++) {
613 link = of_parse_phandle(port, "link", link_index);
614 if (!link)
615 break;
616
617 if (!strcmp(port_name, "dsa") && pd->nr_chips > 1) {
618 ret = dsa_of_setup_routing_table(pd, cd, chip_index,
619 port_index, link);
620 if (ret)
621 return ret;
622 }
623 }
624 return 0;
625}
626
Florian Fainelli21168242013-03-25 05:03:39 +0000627static void dsa_of_free_platform_data(struct dsa_platform_data *pd)
628{
629 int i;
630 int port_index;
631
632 for (i = 0; i < pd->nr_chips; i++) {
633 port_index = 0;
Florian Fainelli5f64a7d2013-03-25 05:03:40 +0000634 while (port_index < DSA_MAX_PORTS) {
Fabian Frederick1f747142014-06-23 19:32:47 +0200635 kfree(pd->chip[i].port_names[port_index]);
Florian Fainelli5f64a7d2013-03-25 05:03:40 +0000636 port_index++;
637 }
Florian Fainelli21168242013-03-25 05:03:39 +0000638 kfree(pd->chip[i].rtable);
Russell Kinge496ae62015-09-24 20:35:57 +0100639
640 /* Drop our reference to the MDIO bus device */
641 if (pd->chip[i].host_dev)
642 put_device(pd->chip[i].host_dev);
Florian Fainelli21168242013-03-25 05:03:39 +0000643 }
644 kfree(pd->chip);
645}
646
Florian Fainellif1a26a02015-03-05 12:35:04 -0800647static int dsa_of_probe(struct device *dev)
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000648{
Florian Fainellif1a26a02015-03-05 12:35:04 -0800649 struct device_node *np = dev->of_node;
Andrew Lunn1e72e6f2015-08-17 23:52:50 +0200650 struct device_node *child, *mdio, *ethernet, *port;
Andrew Lunn6bc6d0a2015-08-08 17:09:14 +0200651 struct mii_bus *mdio_bus, *mdio_bus_switch;
Florian Fainelli769a0202015-03-09 14:31:21 -0700652 struct net_device *ethernet_dev;
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000653 struct dsa_platform_data *pd;
654 struct dsa_chip_data *cd;
655 const char *port_name;
656 int chip_index, port_index;
657 const unsigned int *sw_addr, *port_reg;
Guenter Roeck6793abb2014-10-29 10:45:01 -0700658 u32 eeprom_len;
Florian Fainelli21168242013-03-25 05:03:39 +0000659 int ret;
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000660
661 mdio = of_parse_phandle(np, "dsa,mii-bus", 0);
662 if (!mdio)
663 return -EINVAL;
664
665 mdio_bus = of_mdio_find_bus(mdio);
666 if (!mdio_bus)
Florian Fainellib324c072015-03-05 12:35:05 -0800667 return -EPROBE_DEFER;
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000668
669 ethernet = of_parse_phandle(np, "dsa,ethernet", 0);
Russell Kinge496ae62015-09-24 20:35:57 +0100670 if (!ethernet) {
671 ret = -EINVAL;
672 goto out_put_mdio;
673 }
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000674
Florian Fainelli769a0202015-03-09 14:31:21 -0700675 ethernet_dev = of_find_net_device_by_node(ethernet);
Russell Kinge496ae62015-09-24 20:35:57 +0100676 if (!ethernet_dev) {
677 ret = -EPROBE_DEFER;
678 goto out_put_mdio;
679 }
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000680
681 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
Russell Kinge496ae62015-09-24 20:35:57 +0100682 if (!pd) {
683 ret = -ENOMEM;
Russell King9861f722015-09-24 20:36:33 +0100684 goto out_put_ethernet;
Russell Kinge496ae62015-09-24 20:35:57 +0100685 }
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000686
Florian Fainellif1a26a02015-03-05 12:35:04 -0800687 dev->platform_data = pd;
Florian Fainelli769a0202015-03-09 14:31:21 -0700688 pd->of_netdev = ethernet_dev;
Tobias Waldekranze04449f2015-02-05 14:54:09 +0100689 pd->nr_chips = of_get_available_child_count(np);
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000690 if (pd->nr_chips > DSA_MAX_SWITCHES)
691 pd->nr_chips = DSA_MAX_SWITCHES;
692
Fabian Frederick6f2aed62014-11-14 19:38:23 +0100693 pd->chip = kcalloc(pd->nr_chips, sizeof(struct dsa_chip_data),
694 GFP_KERNEL);
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000695 if (!pd->chip) {
696 ret = -ENOMEM;
697 goto out_free;
698 }
699
Fabian Godehardtd1c0b472014-05-16 06:21:44 +0200700 chip_index = -1;
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000701 for_each_available_child_of_node(np, child) {
Fabian Godehardtd1c0b472014-05-16 06:21:44 +0200702 chip_index++;
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000703 cd = &pd->chip[chip_index];
704
Florian Fainellifa981d92014-08-27 17:04:49 -0700705 cd->of_node = child;
Russell Kinge496ae62015-09-24 20:35:57 +0100706
707 /* When assigning the host device, increment its refcount */
708 cd->host_dev = get_device(&mdio_bus->dev);
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000709
710 sw_addr = of_get_property(child, "reg", NULL);
711 if (!sw_addr)
712 continue;
713
714 cd->sw_addr = be32_to_cpup(sw_addr);
Florian Fainellic8cf89f2015-07-11 18:02:11 -0700715 if (cd->sw_addr >= PHY_MAX_ADDR)
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000716 continue;
717
Guenter Roeck50d49642015-04-29 10:56:15 -0700718 if (!of_property_read_u32(child, "eeprom-length", &eeprom_len))
Guenter Roeck6793abb2014-10-29 10:45:01 -0700719 cd->eeprom_len = eeprom_len;
720
Andrew Lunn6bc6d0a2015-08-08 17:09:14 +0200721 mdio = of_parse_phandle(child, "mii-bus", 0);
722 if (mdio) {
723 mdio_bus_switch = of_mdio_find_bus(mdio);
724 if (!mdio_bus_switch) {
725 ret = -EPROBE_DEFER;
726 goto out_free_chip;
727 }
Russell Kinge496ae62015-09-24 20:35:57 +0100728
729 /* Drop the mdio_bus device ref, replacing the host
730 * device with the mdio_bus_switch device, keeping
731 * the refcount from of_mdio_find_bus() above.
732 */
733 put_device(cd->host_dev);
Andrew Lunn6bc6d0a2015-08-08 17:09:14 +0200734 cd->host_dev = &mdio_bus_switch->dev;
735 }
736
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000737 for_each_available_child_of_node(child, port) {
738 port_reg = of_get_property(port, "reg", NULL);
739 if (!port_reg)
740 continue;
741
742 port_index = be32_to_cpup(port_reg);
Florian Fainelli8f5063e2015-07-11 18:02:10 -0700743 if (port_index >= DSA_MAX_PORTS)
744 break;
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000745
746 port_name = of_get_property(port, "label", NULL);
747 if (!port_name)
748 continue;
749
Florian Fainellibd474972014-08-27 17:04:50 -0700750 cd->port_dn[port_index] = port;
751
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000752 cd->port_names[port_index] = kstrdup(port_name,
753 GFP_KERNEL);
754 if (!cd->port_names[port_index]) {
755 ret = -ENOMEM;
756 goto out_free_chip;
757 }
758
Andrew Lunn1e72e6f2015-08-17 23:52:50 +0200759 ret = dsa_of_probe_links(pd, cd, chip_index,
760 port_index, port, port_name);
761 if (ret)
762 goto out_free_chip;
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000763
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000764 }
765 }
766
Russell Kinge496ae62015-09-24 20:35:57 +0100767 /* The individual chips hold their own refcount on the mdio bus,
768 * so drop ours */
769 put_device(&mdio_bus->dev);
770
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000771 return 0;
772
773out_free_chip:
Florian Fainelli21168242013-03-25 05:03:39 +0000774 dsa_of_free_platform_data(pd);
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000775out_free:
776 kfree(pd);
Florian Fainellif1a26a02015-03-05 12:35:04 -0800777 dev->platform_data = NULL;
Russell King9861f722015-09-24 20:36:33 +0100778out_put_ethernet:
779 put_device(&ethernet_dev->dev);
Russell Kinge496ae62015-09-24 20:35:57 +0100780out_put_mdio:
781 put_device(&mdio_bus->dev);
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000782 return ret;
783}
784
Florian Fainellif1a26a02015-03-05 12:35:04 -0800785static void dsa_of_remove(struct device *dev)
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000786{
Florian Fainellif1a26a02015-03-05 12:35:04 -0800787 struct dsa_platform_data *pd = dev->platform_data;
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000788
Florian Fainellif1a26a02015-03-05 12:35:04 -0800789 if (!dev->of_node)
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000790 return;
791
Florian Fainelli21168242013-03-25 05:03:39 +0000792 dsa_of_free_platform_data(pd);
Russell King9861f722015-09-24 20:36:33 +0100793 put_device(&pd->of_netdev->dev);
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000794 kfree(pd);
795}
796#else
Florian Fainellif1a26a02015-03-05 12:35:04 -0800797static inline int dsa_of_probe(struct device *dev)
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000798{
799 return 0;
800}
801
Florian Fainellif1a26a02015-03-05 12:35:04 -0800802static inline void dsa_of_remove(struct device *dev)
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000803{
804}
805#endif
806
Florian Fainellic86e59b2015-03-05 12:35:08 -0800807static void dsa_setup_dst(struct dsa_switch_tree *dst, struct net_device *dev,
808 struct device *parent, struct dsa_platform_data *pd)
809{
810 int i;
811
812 dst->pd = pd;
813 dst->master_netdev = dev;
814 dst->cpu_switch = -1;
815 dst->cpu_port = -1;
816
817 for (i = 0; i < pd->nr_chips; i++) {
818 struct dsa_switch *ds;
819
820 ds = dsa_switch_setup(dst, i, parent, pd->chip[i].host_dev);
821 if (IS_ERR(ds)) {
822 netdev_err(dev, "[%d]: couldn't create dsa switch instance (error %ld)\n",
823 i, PTR_ERR(ds));
824 continue;
825 }
826
827 dst->ds[i] = ds;
828 if (ds->drv->poll_link != NULL)
829 dst->link_poll_needed = 1;
830 }
831
832 /*
833 * If we use a tagging format that doesn't have an ethertype
834 * field, make sure that all packets from this point on get
835 * sent to the tag format's receive function.
836 */
837 wmb();
838 dev->dsa_ptr = (void *)dst;
839
840 if (dst->link_poll_needed) {
841 INIT_WORK(&dst->link_poll_work, dsa_link_poll_work);
842 init_timer(&dst->link_poll_timer);
843 dst->link_poll_timer.data = (unsigned long)dst;
844 dst->link_poll_timer.function = dsa_link_poll_timer;
845 dst->link_poll_timer.expires = round_jiffies(jiffies + HZ);
846 add_timer(&dst->link_poll_timer);
847 }
848}
849
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000850static int dsa_probe(struct platform_device *pdev)
851{
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000852 struct dsa_platform_data *pd = pdev->dev.platform_data;
853 struct net_device *dev;
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000854 struct dsa_switch_tree *dst;
Florian Fainellic86e59b2015-03-05 12:35:08 -0800855 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000856
Joe Perchesa2ae6002014-11-09 16:32:46 -0800857 pr_notice_once("Distributed Switch Architecture driver version %s\n",
858 dsa_driver_version);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000859
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000860 if (pdev->dev.of_node) {
Florian Fainellif1a26a02015-03-05 12:35:04 -0800861 ret = dsa_of_probe(&pdev->dev);
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000862 if (ret)
863 return ret;
864
865 pd = pdev->dev.platform_data;
866 }
867
Florian Fainelli769a0202015-03-09 14:31:21 -0700868 if (pd == NULL || (pd->netdev == NULL && pd->of_netdev == NULL))
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000869 return -EINVAL;
870
Florian Fainelli769a0202015-03-09 14:31:21 -0700871 if (pd->of_netdev) {
872 dev = pd->of_netdev;
873 dev_hold(dev);
874 } else {
875 dev = dev_to_net_device(pd->netdev);
876 }
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000877 if (dev == NULL) {
Florian Fainellib324c072015-03-05 12:35:05 -0800878 ret = -EPROBE_DEFER;
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000879 goto out;
880 }
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000881
882 if (dev->dsa_ptr != NULL) {
883 dev_put(dev);
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000884 ret = -EEXIST;
885 goto out;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000886 }
887
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000888 dst = kzalloc(sizeof(*dst), GFP_KERNEL);
889 if (dst == NULL) {
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000890 dev_put(dev);
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000891 ret = -ENOMEM;
892 goto out;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000893 }
894
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000895 platform_set_drvdata(pdev, dst);
896
Florian Fainellic86e59b2015-03-05 12:35:08 -0800897 dsa_setup_dst(dst, dev, &pdev->dev, pd);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000898
899 return 0;
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000900
901out:
Florian Fainellif1a26a02015-03-05 12:35:04 -0800902 dsa_of_remove(&pdev->dev);
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000903
904 return ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000905}
906
Florian Fainellic86e59b2015-03-05 12:35:08 -0800907static void dsa_remove_dst(struct dsa_switch_tree *dst)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000908{
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000909 int i;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000910
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000911 if (dst->link_poll_needed)
912 del_timer_sync(&dst->link_poll_timer);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000913
Tejun Heo43829732012-08-20 14:51:24 -0700914 flush_work(&dst->link_poll_work);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000915
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000916 for (i = 0; i < dst->pd->nr_chips; i++) {
917 struct dsa_switch *ds = dst->ds[i];
918
Neil Armstrong1023d2e2015-10-06 15:39:53 +0100919 if (ds) {
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000920 dsa_switch_destroy(ds);
Neil Armstrong1023d2e2015-10-06 15:39:53 +0100921 kfree(ds);
922 }
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000923 }
Florian Fainellic86e59b2015-03-05 12:35:08 -0800924}
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000925
Florian Fainellic86e59b2015-03-05 12:35:08 -0800926static int dsa_remove(struct platform_device *pdev)
927{
928 struct dsa_switch_tree *dst = platform_get_drvdata(pdev);
929
930 dsa_remove_dst(dst);
Neil Armstrong1023d2e2015-10-06 15:39:53 +0100931 kfree(dst);
Florian Fainellif1a26a02015-03-05 12:35:04 -0800932 dsa_of_remove(&pdev->dev);
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000933
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000934 return 0;
935}
936
937static void dsa_shutdown(struct platform_device *pdev)
938{
939}
940
Florian Fainelli3e8a72d2014-08-27 17:04:46 -0700941static int dsa_switch_rcv(struct sk_buff *skb, struct net_device *dev,
942 struct packet_type *pt, struct net_device *orig_dev)
943{
944 struct dsa_switch_tree *dst = dev->dsa_ptr;
945
946 if (unlikely(dst == NULL)) {
947 kfree_skb(skb);
948 return 0;
949 }
950
Alexander Duyck50753142014-09-15 13:00:19 -0400951 return dst->rcv(skb, dev, pt, orig_dev);
Florian Fainelli3e8a72d2014-08-27 17:04:46 -0700952}
953
Florian Fainelli61b73632014-08-29 12:42:07 -0700954static struct packet_type dsa_pack_type __read_mostly = {
Florian Fainelli3e8a72d2014-08-27 17:04:46 -0700955 .type = cpu_to_be16(ETH_P_XDSA),
956 .func = dsa_switch_rcv,
957};
958
Florian Fainellib73adef2015-02-24 13:15:33 -0800959static struct notifier_block dsa_netdevice_nb __read_mostly = {
960 .notifier_call = dsa_slave_netdevice_event,
961};
962
Florian Fainelli24462542014-09-18 17:31:22 -0700963#ifdef CONFIG_PM_SLEEP
964static int dsa_suspend(struct device *d)
965{
966 struct platform_device *pdev = to_platform_device(d);
967 struct dsa_switch_tree *dst = platform_get_drvdata(pdev);
968 int i, ret = 0;
969
970 for (i = 0; i < dst->pd->nr_chips; i++) {
971 struct dsa_switch *ds = dst->ds[i];
972
973 if (ds != NULL)
974 ret = dsa_switch_suspend(ds);
975 }
976
977 return ret;
978}
979
980static int dsa_resume(struct device *d)
981{
982 struct platform_device *pdev = to_platform_device(d);
983 struct dsa_switch_tree *dst = platform_get_drvdata(pdev);
984 int i, ret = 0;
985
986 for (i = 0; i < dst->pd->nr_chips; i++) {
987 struct dsa_switch *ds = dst->ds[i];
988
989 if (ds != NULL)
990 ret = dsa_switch_resume(ds);
991 }
992
993 return ret;
994}
995#endif
996
997static SIMPLE_DEV_PM_OPS(dsa_pm_ops, dsa_suspend, dsa_resume);
998
Florian Fainelli5e95329b2013-03-22 10:50:50 +0000999static const struct of_device_id dsa_of_match_table[] = {
Florian Fainelli246d7f72014-08-27 17:04:56 -07001000 { .compatible = "brcm,bcm7445-switch-v4.0" },
Florian Fainelli5e95329b2013-03-22 10:50:50 +00001001 { .compatible = "marvell,dsa", },
1002 {}
1003};
1004MODULE_DEVICE_TABLE(of, dsa_of_match_table);
1005
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001006static struct platform_driver dsa_driver = {
1007 .probe = dsa_probe,
1008 .remove = dsa_remove,
1009 .shutdown = dsa_shutdown,
1010 .driver = {
1011 .name = "dsa",
Florian Fainelli5e95329b2013-03-22 10:50:50 +00001012 .of_match_table = dsa_of_match_table,
Florian Fainelli24462542014-09-18 17:31:22 -07001013 .pm = &dsa_pm_ops,
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001014 },
1015};
1016
1017static int __init dsa_init_module(void)
1018{
Ben Hutchings7df899c2011-11-25 14:35:02 +00001019 int rc;
1020
Florian Fainellib73adef2015-02-24 13:15:33 -08001021 register_netdevice_notifier(&dsa_netdevice_nb);
1022
Ben Hutchings7df899c2011-11-25 14:35:02 +00001023 rc = platform_driver_register(&dsa_driver);
1024 if (rc)
1025 return rc;
1026
Florian Fainelli3e8a72d2014-08-27 17:04:46 -07001027 dev_add_pack(&dsa_pack_type);
1028
Ben Hutchings7df899c2011-11-25 14:35:02 +00001029 return 0;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001030}
1031module_init(dsa_init_module);
1032
1033static void __exit dsa_cleanup_module(void)
1034{
Florian Fainellib73adef2015-02-24 13:15:33 -08001035 unregister_netdevice_notifier(&dsa_netdevice_nb);
Florian Fainelli3e8a72d2014-08-27 17:04:46 -07001036 dev_remove_pack(&dsa_pack_type);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001037 platform_driver_unregister(&dsa_driver);
1038}
1039module_exit(dsa_cleanup_module);
1040
Rusty Russell577d6a72011-01-24 14:32:52 -06001041MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001042MODULE_DESCRIPTION("Driver for Distributed Switch Architecture switch chips");
1043MODULE_LICENSE("GPL");
1044MODULE_ALIAS("platform:dsa");