blob: 163910699db75cd3e2543fcb69fe1eaf19f06466 [file] [log] [blame]
Vivien Didelota6a71f12017-04-12 12:45:03 -04001/*
2 * net/dsa/legacy.c - Hardware switch handling
3 * Copyright (c) 2008-2009 Marvell Semiconductor
4 * Copyright (c) 2013 Florian Fainelli <florian@openwrt.org>
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
12#include <linux/device.h>
13#include <linux/list.h>
14#include <linux/platform_device.h>
15#include <linux/slab.h>
16#include <linux/module.h>
17#include <linux/of.h>
18#include <linux/of_mdio.h>
19#include <linux/of_platform.h>
20#include <linux/of_net.h>
21#include <linux/netdevice.h>
22#include <linux/sysfs.h>
23#include <linux/phy_fixed.h>
24#include <linux/etherdevice.h>
Vivien Didelotea5dd342017-05-17 15:46:03 -040025
Vivien Didelota6a71f12017-04-12 12:45:03 -040026#include "dsa_priv.h"
27
28/* switch driver registration ***********************************************/
29static DEFINE_MUTEX(dsa_switch_drivers_mutex);
30static LIST_HEAD(dsa_switch_drivers);
31
32void register_switch_driver(struct dsa_switch_driver *drv)
33{
34 mutex_lock(&dsa_switch_drivers_mutex);
35 list_add_tail(&drv->list, &dsa_switch_drivers);
36 mutex_unlock(&dsa_switch_drivers_mutex);
37}
38EXPORT_SYMBOL_GPL(register_switch_driver);
39
40void unregister_switch_driver(struct dsa_switch_driver *drv)
41{
42 mutex_lock(&dsa_switch_drivers_mutex);
43 list_del_init(&drv->list);
44 mutex_unlock(&dsa_switch_drivers_mutex);
45}
46EXPORT_SYMBOL_GPL(unregister_switch_driver);
47
48static const struct dsa_switch_ops *
49dsa_switch_probe(struct device *parent, struct device *host_dev, int sw_addr,
50 const char **_name, void **priv)
51{
52 const struct dsa_switch_ops *ret;
53 struct list_head *list;
54 const char *name;
55
56 ret = NULL;
57 name = NULL;
58
59 mutex_lock(&dsa_switch_drivers_mutex);
60 list_for_each(list, &dsa_switch_drivers) {
61 const struct dsa_switch_ops *ops;
62 struct dsa_switch_driver *drv;
63
64 drv = list_entry(list, struct dsa_switch_driver, list);
65 ops = drv->ops;
66
67 name = ops->probe(parent, host_dev, sw_addr, priv);
68 if (name != NULL) {
69 ret = ops;
70 break;
71 }
72 }
73 mutex_unlock(&dsa_switch_drivers_mutex);
74
75 *_name = name;
76
77 return ret;
78}
79
80/* basic switch operations **************************************************/
Vivien Didelot206e41f2017-08-05 16:20:17 -040081static int dsa_cpu_dsa_setups(struct dsa_switch *ds)
Vivien Didelota6a71f12017-04-12 12:45:03 -040082{
Vivien Didelota6a71f12017-04-12 12:45:03 -040083 int ret, port;
84
85 for (port = 0; port < ds->num_ports; port++) {
86 if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)))
87 continue;
88
Vivien Didelot47d0dcc2017-08-05 16:20:18 -040089 ret = dsa_cpu_dsa_setup(&ds->ports[port]);
Vivien Didelota6a71f12017-04-12 12:45:03 -040090 if (ret)
91 return ret;
92 }
93 return 0;
94}
95
Vivien Didelot206e41f2017-08-05 16:20:17 -040096static int dsa_switch_setup_one(struct dsa_switch *ds,
97 struct net_device *master)
Vivien Didelota6a71f12017-04-12 12:45:03 -040098{
99 const struct dsa_switch_ops *ops = ds->ops;
100 struct dsa_switch_tree *dst = ds->dst;
101 struct dsa_chip_data *cd = ds->cd;
102 bool valid_name_found = false;
103 int index = ds->index;
104 int i, ret;
105
106 /*
107 * Validate supplied switch configuration.
108 */
109 for (i = 0; i < ds->num_ports; i++) {
110 char *name;
111
112 name = cd->port_names[i];
113 if (name == NULL)
114 continue;
115
116 if (!strcmp(name, "cpu")) {
Vivien Didelot8b0d3ea2017-05-16 14:10:33 -0400117 if (dst->cpu_dp) {
Florian Fainelli6d3c8c02017-06-13 13:27:19 -0700118 netdev_err(master,
Vivien Didelota6a71f12017-04-12 12:45:03 -0400119 "multiple cpu ports?!\n");
120 return -EINVAL;
121 }
Vivien Didelot8b0d3ea2017-05-16 14:10:33 -0400122 dst->cpu_dp = &ds->ports[i];
Florian Fainelli06d4d452017-06-16 16:42:11 -0700123 dst->cpu_dp->netdev = master;
Vivien Didelota6a71f12017-04-12 12:45:03 -0400124 ds->cpu_port_mask |= 1 << i;
125 } else if (!strcmp(name, "dsa")) {
126 ds->dsa_port_mask |= 1 << i;
127 } else {
128 ds->enabled_port_mask |= 1 << i;
129 }
130 valid_name_found = true;
131 }
132
133 if (!valid_name_found && i == ds->num_ports)
134 return -EINVAL;
135
136 /* Make the built-in MII bus mask match the number of ports,
137 * switch drivers can override this later
138 */
139 ds->phys_mii_mask = ds->enabled_port_mask;
140
141 /*
142 * If the CPU connects to this switch, set the switch tree
143 * tagging protocol to the preferred tagging format of this
144 * switch.
145 */
Vivien Didelot8b0d3ea2017-05-16 14:10:33 -0400146 if (dst->cpu_dp->ds == ds) {
Vivien Didelota6a71f12017-04-12 12:45:03 -0400147 enum dsa_tag_protocol tag_protocol;
148
149 tag_protocol = ops->get_tag_protocol(ds);
150 dst->tag_ops = dsa_resolve_tag_protocol(tag_protocol);
151 if (IS_ERR(dst->tag_ops))
152 return PTR_ERR(dst->tag_ops);
153
154 dst->rcv = dst->tag_ops->rcv;
155 }
156
157 memcpy(ds->rtable, cd->rtable, sizeof(ds->rtable));
158
159 /*
160 * Do basic register setup.
161 */
162 ret = ops->setup(ds);
163 if (ret < 0)
164 return ret;
165
166 ret = dsa_switch_register_notifier(ds);
167 if (ret)
168 return ret;
169
170 if (ops->set_addr) {
Florian Fainelli6d3c8c02017-06-13 13:27:19 -0700171 ret = ops->set_addr(ds, master->dev_addr);
Vivien Didelota6a71f12017-04-12 12:45:03 -0400172 if (ret < 0)
173 return ret;
174 }
175
176 if (!ds->slave_mii_bus && ops->phy_read) {
Vivien Didelot206e41f2017-08-05 16:20:17 -0400177 ds->slave_mii_bus = devm_mdiobus_alloc(ds->dev);
Vivien Didelota6a71f12017-04-12 12:45:03 -0400178 if (!ds->slave_mii_bus)
179 return -ENOMEM;
180 dsa_slave_mii_bus_init(ds);
181
182 ret = mdiobus_register(ds->slave_mii_bus);
183 if (ret < 0)
184 return ret;
185 }
186
187 /*
188 * Create network devices for physical switch ports.
189 */
190 for (i = 0; i < ds->num_ports; i++) {
191 ds->ports[i].dn = cd->port_dn[i];
Florian Fainelli06d4d452017-06-16 16:42:11 -0700192 ds->ports[i].cpu_dp = dst->cpu_dp;
Vivien Didelota6a71f12017-04-12 12:45:03 -0400193
194 if (!(ds->enabled_port_mask & (1 << i)))
195 continue;
196
Vivien Didelot4cfbf092017-08-05 16:20:19 -0400197 ret = dsa_slave_create(&ds->ports[i], cd->port_names[i]);
Vivien Didelota6a71f12017-04-12 12:45:03 -0400198 if (ret < 0)
Florian Fainelli6d3c8c02017-06-13 13:27:19 -0700199 netdev_err(master, "[%d]: can't create dsa slave device for port %d(%s): %d\n",
Vivien Didelota6a71f12017-04-12 12:45:03 -0400200 index, i, cd->port_names[i], ret);
201 }
202
203 /* Perform configuration of the CPU and DSA ports */
Vivien Didelot206e41f2017-08-05 16:20:17 -0400204 ret = dsa_cpu_dsa_setups(ds);
Vivien Didelota6a71f12017-04-12 12:45:03 -0400205 if (ret < 0)
Florian Fainelli6d3c8c02017-06-13 13:27:19 -0700206 netdev_err(master, "[%d] : can't configure CPU and DSA ports\n",
Vivien Didelota6a71f12017-04-12 12:45:03 -0400207 index);
208
Vivien Didelota6a71f12017-04-12 12:45:03 -0400209 return 0;
210}
211
212static struct dsa_switch *
Florian Fainelli06d4d452017-06-16 16:42:11 -0700213dsa_switch_setup(struct dsa_switch_tree *dst, struct net_device *master,
214 int index, struct device *parent, struct device *host_dev)
Vivien Didelota6a71f12017-04-12 12:45:03 -0400215{
216 struct dsa_chip_data *cd = dst->pd->chip + index;
217 const struct dsa_switch_ops *ops;
218 struct dsa_switch *ds;
219 int ret;
220 const char *name;
221 void *priv;
222
223 /*
224 * Probe for switch model.
225 */
226 ops = dsa_switch_probe(parent, host_dev, cd->sw_addr, &name, &priv);
227 if (!ops) {
Florian Fainelli6d3c8c02017-06-13 13:27:19 -0700228 netdev_err(master, "[%d]: could not detect attached switch\n",
Vivien Didelota6a71f12017-04-12 12:45:03 -0400229 index);
230 return ERR_PTR(-EINVAL);
231 }
Florian Fainelli6d3c8c02017-06-13 13:27:19 -0700232 netdev_info(master, "[%d]: detected a %s switch\n",
Vivien Didelota6a71f12017-04-12 12:45:03 -0400233 index, name);
234
235
236 /*
237 * Allocate and initialise switch state.
238 */
239 ds = dsa_switch_alloc(parent, DSA_MAX_PORTS);
240 if (!ds)
241 return ERR_PTR(-ENOMEM);
242
243 ds->dst = dst;
244 ds->index = index;
245 ds->cd = cd;
246 ds->ops = ops;
247 ds->priv = priv;
248
Vivien Didelot206e41f2017-08-05 16:20:17 -0400249 ret = dsa_switch_setup_one(ds, master);
Vivien Didelota6a71f12017-04-12 12:45:03 -0400250 if (ret)
251 return ERR_PTR(ret);
252
253 return ds;
254}
255
256static void dsa_switch_destroy(struct dsa_switch *ds)
257{
258 int port;
259
260 /* Destroy network devices for physical switch ports. */
261 for (port = 0; port < ds->num_ports; port++) {
262 if (!(ds->enabled_port_mask & (1 << port)))
263 continue;
264
265 if (!ds->ports[port].netdev)
266 continue;
267
268 dsa_slave_destroy(ds->ports[port].netdev);
269 }
270
271 /* Disable configuration of the CPU and DSA ports */
272 for (port = 0; port < ds->num_ports; port++) {
273 if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)))
274 continue;
275 dsa_cpu_dsa_destroy(&ds->ports[port]);
276
277 /* Clearing a bit which is not set does no harm */
278 ds->cpu_port_mask |= ~(1 << port);
279 ds->dsa_port_mask |= ~(1 << port);
280 }
281
282 if (ds->slave_mii_bus && ds->ops->phy_read)
283 mdiobus_unregister(ds->slave_mii_bus);
284
285 dsa_switch_unregister_notifier(ds);
286}
287
Vivien Didelota6a71f12017-04-12 12:45:03 -0400288/* platform driver init and cleanup *****************************************/
289static int dev_is_class(struct device *dev, void *class)
290{
291 if (dev->class != NULL && !strcmp(dev->class->name, class))
292 return 1;
293
294 return 0;
295}
296
297static struct device *dev_find_class(struct device *parent, char *class)
298{
299 if (dev_is_class(parent, class)) {
300 get_device(parent);
301 return parent;
302 }
303
304 return device_find_child(parent, class, dev_is_class);
305}
306
307struct mii_bus *dsa_host_dev_to_mii_bus(struct device *dev)
308{
309 struct device *d;
310
311 d = dev_find_class(dev, "mdio_bus");
312 if (d != NULL) {
313 struct mii_bus *bus;
314
315 bus = to_mii_bus(d);
316 put_device(d);
317
318 return bus;
319 }
320
321 return NULL;
322}
323EXPORT_SYMBOL_GPL(dsa_host_dev_to_mii_bus);
324
325#ifdef CONFIG_OF
326static int dsa_of_setup_routing_table(struct dsa_platform_data *pd,
327 struct dsa_chip_data *cd,
328 int chip_index, int port_index,
329 struct device_node *link)
330{
331 const __be32 *reg;
332 int link_sw_addr;
333 struct device_node *parent_sw;
334 int len;
335
336 parent_sw = of_get_parent(link);
337 if (!parent_sw)
338 return -EINVAL;
339
340 reg = of_get_property(parent_sw, "reg", &len);
341 if (!reg || (len != sizeof(*reg) * 2))
342 return -EINVAL;
343
344 /*
345 * Get the destination switch number from the second field of its 'reg'
346 * property, i.e. for "reg = <0x19 1>" sw_addr is '1'.
347 */
348 link_sw_addr = be32_to_cpup(reg + 1);
349
350 if (link_sw_addr >= pd->nr_chips)
351 return -EINVAL;
352
353 cd->rtable[link_sw_addr] = port_index;
354
355 return 0;
356}
357
358static int dsa_of_probe_links(struct dsa_platform_data *pd,
359 struct dsa_chip_data *cd,
360 int chip_index, int port_index,
361 struct device_node *port,
362 const char *port_name)
363{
364 struct device_node *link;
365 int link_index;
366 int ret;
367
368 for (link_index = 0;; link_index++) {
369 link = of_parse_phandle(port, "link", link_index);
370 if (!link)
371 break;
372
373 if (!strcmp(port_name, "dsa") && pd->nr_chips > 1) {
374 ret = dsa_of_setup_routing_table(pd, cd, chip_index,
375 port_index, link);
376 if (ret)
377 return ret;
378 }
379 }
380 return 0;
381}
382
383static void dsa_of_free_platform_data(struct dsa_platform_data *pd)
384{
385 int i;
386 int port_index;
387
388 for (i = 0; i < pd->nr_chips; i++) {
389 port_index = 0;
390 while (port_index < DSA_MAX_PORTS) {
391 kfree(pd->chip[i].port_names[port_index]);
392 port_index++;
393 }
394
395 /* Drop our reference to the MDIO bus device */
396 if (pd->chip[i].host_dev)
397 put_device(pd->chip[i].host_dev);
398 }
399 kfree(pd->chip);
400}
401
402static int dsa_of_probe(struct device *dev)
403{
404 struct device_node *np = dev->of_node;
405 struct device_node *child, *mdio, *ethernet, *port;
406 struct mii_bus *mdio_bus, *mdio_bus_switch;
407 struct net_device *ethernet_dev;
408 struct dsa_platform_data *pd;
409 struct dsa_chip_data *cd;
410 const char *port_name;
411 int chip_index, port_index;
412 const unsigned int *sw_addr, *port_reg;
413 u32 eeprom_len;
414 int ret;
415
416 mdio = of_parse_phandle(np, "dsa,mii-bus", 0);
417 if (!mdio)
418 return -EINVAL;
419
420 mdio_bus = of_mdio_find_bus(mdio);
421 if (!mdio_bus)
422 return -EPROBE_DEFER;
423
424 ethernet = of_parse_phandle(np, "dsa,ethernet", 0);
425 if (!ethernet) {
426 ret = -EINVAL;
427 goto out_put_mdio;
428 }
429
430 ethernet_dev = of_find_net_device_by_node(ethernet);
431 if (!ethernet_dev) {
432 ret = -EPROBE_DEFER;
433 goto out_put_mdio;
434 }
435
436 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
437 if (!pd) {
438 ret = -ENOMEM;
439 goto out_put_ethernet;
440 }
441
442 dev->platform_data = pd;
443 pd->of_netdev = ethernet_dev;
444 pd->nr_chips = of_get_available_child_count(np);
445 if (pd->nr_chips > DSA_MAX_SWITCHES)
446 pd->nr_chips = DSA_MAX_SWITCHES;
447
448 pd->chip = kcalloc(pd->nr_chips, sizeof(struct dsa_chip_data),
449 GFP_KERNEL);
450 if (!pd->chip) {
451 ret = -ENOMEM;
452 goto out_free;
453 }
454
455 chip_index = -1;
456 for_each_available_child_of_node(np, child) {
457 int i;
458
459 chip_index++;
460 cd = &pd->chip[chip_index];
461
462 cd->of_node = child;
463
464 /* Initialize the routing table */
465 for (i = 0; i < DSA_MAX_SWITCHES; ++i)
466 cd->rtable[i] = DSA_RTABLE_NONE;
467
468 /* When assigning the host device, increment its refcount */
469 cd->host_dev = get_device(&mdio_bus->dev);
470
471 sw_addr = of_get_property(child, "reg", NULL);
472 if (!sw_addr)
473 continue;
474
475 cd->sw_addr = be32_to_cpup(sw_addr);
476 if (cd->sw_addr >= PHY_MAX_ADDR)
477 continue;
478
479 if (!of_property_read_u32(child, "eeprom-length", &eeprom_len))
480 cd->eeprom_len = eeprom_len;
481
482 mdio = of_parse_phandle(child, "mii-bus", 0);
483 if (mdio) {
484 mdio_bus_switch = of_mdio_find_bus(mdio);
485 if (!mdio_bus_switch) {
486 ret = -EPROBE_DEFER;
487 goto out_free_chip;
488 }
489
490 /* Drop the mdio_bus device ref, replacing the host
491 * device with the mdio_bus_switch device, keeping
492 * the refcount from of_mdio_find_bus() above.
493 */
494 put_device(cd->host_dev);
495 cd->host_dev = &mdio_bus_switch->dev;
496 }
497
498 for_each_available_child_of_node(child, port) {
499 port_reg = of_get_property(port, "reg", NULL);
500 if (!port_reg)
501 continue;
502
503 port_index = be32_to_cpup(port_reg);
504 if (port_index >= DSA_MAX_PORTS)
505 break;
506
507 port_name = of_get_property(port, "label", NULL);
508 if (!port_name)
509 continue;
510
511 cd->port_dn[port_index] = port;
512
513 cd->port_names[port_index] = kstrdup(port_name,
514 GFP_KERNEL);
515 if (!cd->port_names[port_index]) {
516 ret = -ENOMEM;
517 goto out_free_chip;
518 }
519
520 ret = dsa_of_probe_links(pd, cd, chip_index,
521 port_index, port, port_name);
522 if (ret)
523 goto out_free_chip;
524
525 }
526 }
527
528 /* The individual chips hold their own refcount on the mdio bus,
529 * so drop ours */
530 put_device(&mdio_bus->dev);
531
532 return 0;
533
534out_free_chip:
535 dsa_of_free_platform_data(pd);
536out_free:
537 kfree(pd);
538 dev->platform_data = NULL;
539out_put_ethernet:
540 put_device(&ethernet_dev->dev);
541out_put_mdio:
542 put_device(&mdio_bus->dev);
543 return ret;
544}
545
546static void dsa_of_remove(struct device *dev)
547{
548 struct dsa_platform_data *pd = dev->platform_data;
549
550 if (!dev->of_node)
551 return;
552
553 dsa_of_free_platform_data(pd);
554 put_device(&pd->of_netdev->dev);
555 kfree(pd);
556}
557#else
558static inline int dsa_of_probe(struct device *dev)
559{
560 return 0;
561}
562
563static inline void dsa_of_remove(struct device *dev)
564{
565}
566#endif
567
568static int dsa_setup_dst(struct dsa_switch_tree *dst, struct net_device *dev,
569 struct device *parent, struct dsa_platform_data *pd)
570{
571 int i;
572 unsigned configured = 0;
573
574 dst->pd = pd;
Vivien Didelota6a71f12017-04-12 12:45:03 -0400575
576 for (i = 0; i < pd->nr_chips; i++) {
577 struct dsa_switch *ds;
578
Florian Fainelli06d4d452017-06-16 16:42:11 -0700579 ds = dsa_switch_setup(dst, dev, i, parent, pd->chip[i].host_dev);
Vivien Didelota6a71f12017-04-12 12:45:03 -0400580 if (IS_ERR(ds)) {
581 netdev_err(dev, "[%d]: couldn't create dsa switch instance (error %ld)\n",
582 i, PTR_ERR(ds));
583 continue;
584 }
585
586 dst->ds[i] = ds;
587
588 ++configured;
589 }
590
591 /*
592 * If no switch was found, exit cleanly
593 */
594 if (!configured)
595 return -EPROBE_DEFER;
596
597 /*
598 * If we use a tagging format that doesn't have an ethertype
599 * field, make sure that all packets from this point on get
600 * sent to the tag format's receive function.
601 */
602 wmb();
Vivien Didelot02f840c2017-06-01 16:07:12 -0400603 dev->dsa_ptr = dst;
Vivien Didelota6a71f12017-04-12 12:45:03 -0400604
Vivien Didelot19435632017-09-19 11:56:59 -0400605 return dsa_cpu_port_ethtool_setup(dst->cpu_dp);
Vivien Didelota6a71f12017-04-12 12:45:03 -0400606}
607
608static int dsa_probe(struct platform_device *pdev)
609{
610 struct dsa_platform_data *pd = pdev->dev.platform_data;
611 struct net_device *dev;
612 struct dsa_switch_tree *dst;
613 int ret;
614
615 if (pdev->dev.of_node) {
616 ret = dsa_of_probe(&pdev->dev);
617 if (ret)
618 return ret;
619
620 pd = pdev->dev.platform_data;
621 }
622
623 if (pd == NULL || (pd->netdev == NULL && pd->of_netdev == NULL))
624 return -EINVAL;
625
626 if (pd->of_netdev) {
627 dev = pd->of_netdev;
628 dev_hold(dev);
629 } else {
630 dev = dsa_dev_to_net_device(pd->netdev);
631 }
632 if (dev == NULL) {
633 ret = -EPROBE_DEFER;
634 goto out;
635 }
636
637 if (dev->dsa_ptr != NULL) {
638 dev_put(dev);
639 ret = -EEXIST;
640 goto out;
641 }
642
643 dst = devm_kzalloc(&pdev->dev, sizeof(*dst), GFP_KERNEL);
644 if (dst == NULL) {
645 dev_put(dev);
646 ret = -ENOMEM;
647 goto out;
648 }
649
650 platform_set_drvdata(pdev, dst);
651
652 ret = dsa_setup_dst(dst, dev, &pdev->dev, pd);
653 if (ret) {
654 dev_put(dev);
655 goto out;
656 }
657
658 return 0;
659
660out:
661 dsa_of_remove(&pdev->dev);
662
663 return ret;
664}
665
666static void dsa_remove_dst(struct dsa_switch_tree *dst)
667{
668 int i;
669
Vivien Didelot19435632017-09-19 11:56:59 -0400670 dsa_cpu_port_ethtool_restore(dst->cpu_dp);
671
Florian Fainelli6d3c8c02017-06-13 13:27:19 -0700672 dst->cpu_dp->netdev->dsa_ptr = NULL;
Vivien Didelota6a71f12017-04-12 12:45:03 -0400673
674 /* If we used a tagging format that doesn't have an ethertype
675 * field, make sure that all packets from this point get sent
676 * without the tag and go through the regular receive path.
677 */
678 wmb();
679
680 for (i = 0; i < dst->pd->nr_chips; i++) {
681 struct dsa_switch *ds = dst->ds[i];
682
683 if (ds)
684 dsa_switch_destroy(ds);
685 }
686
Florian Fainelli6d3c8c02017-06-13 13:27:19 -0700687 dev_put(dst->cpu_dp->netdev);
Vivien Didelota6a71f12017-04-12 12:45:03 -0400688}
689
690static int dsa_remove(struct platform_device *pdev)
691{
692 struct dsa_switch_tree *dst = platform_get_drvdata(pdev);
693
694 dsa_remove_dst(dst);
695 dsa_of_remove(&pdev->dev);
696
697 return 0;
698}
699
700static void dsa_shutdown(struct platform_device *pdev)
701{
702}
703
704#ifdef CONFIG_PM_SLEEP
705static int dsa_suspend(struct device *d)
706{
707 struct platform_device *pdev = to_platform_device(d);
708 struct dsa_switch_tree *dst = platform_get_drvdata(pdev);
709 int i, ret = 0;
710
711 for (i = 0; i < dst->pd->nr_chips; i++) {
712 struct dsa_switch *ds = dst->ds[i];
713
714 if (ds != NULL)
715 ret = dsa_switch_suspend(ds);
716 }
717
718 return ret;
719}
720
721static int dsa_resume(struct device *d)
722{
723 struct platform_device *pdev = to_platform_device(d);
724 struct dsa_switch_tree *dst = platform_get_drvdata(pdev);
725 int i, ret = 0;
726
727 for (i = 0; i < dst->pd->nr_chips; i++) {
728 struct dsa_switch *ds = dst->ds[i];
729
730 if (ds != NULL)
731 ret = dsa_switch_resume(ds);
732 }
733
734 return ret;
735}
736#endif
737
Arkadi Sharshevsky37b8da12017-08-06 16:15:43 +0300738/* legacy way, bypassing the bridge *****************************************/
739int dsa_legacy_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
740 struct net_device *dev,
741 const unsigned char *addr, u16 vid,
742 u16 flags)
743{
744 struct dsa_slave_priv *p = netdev_priv(dev);
745 struct dsa_port *dp = p->dp;
746
747 return dsa_port_fdb_add(dp, addr, vid);
748}
749
750int dsa_legacy_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
751 struct net_device *dev,
752 const unsigned char *addr, u16 vid)
753{
754 struct dsa_slave_priv *p = netdev_priv(dev);
755 struct dsa_port *dp = p->dp;
756
757 return dsa_port_fdb_del(dp, addr, vid);
758}
759
Vivien Didelota6a71f12017-04-12 12:45:03 -0400760static SIMPLE_DEV_PM_OPS(dsa_pm_ops, dsa_suspend, dsa_resume);
761
762static const struct of_device_id dsa_of_match_table[] = {
763 { .compatible = "marvell,dsa", },
764 {}
765};
766MODULE_DEVICE_TABLE(of, dsa_of_match_table);
767
768static struct platform_driver dsa_driver = {
769 .probe = dsa_probe,
770 .remove = dsa_remove,
771 .shutdown = dsa_shutdown,
772 .driver = {
773 .name = "dsa",
774 .of_match_table = dsa_of_match_table,
775 .pm = &dsa_pm_ops,
776 },
777};
778
779int dsa_legacy_register(void)
780{
781 return platform_driver_register(&dsa_driver);
782}
783
784void dsa_legacy_unregister(void)
785{
786 platform_driver_unregister(&dsa_driver);
787}