2 * net/dsa/dsa.c - Hardware switch handling
3 * Copyright (c) 2008-2009 Marvell Semiconductor
4 * Copyright (c) 2013 Florian Fainelli <florian@openwrt.org>
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.
12 #include <linux/ctype.h>
13 #include <linux/device.h>
14 #include <linux/hwmon.h>
15 #include <linux/list.h>
16 #include <linux/platform_device.h>
17 #include <linux/slab.h>
18 #include <linux/module.h>
21 #include <linux/of_mdio.h>
22 #include <linux/of_platform.h>
23 #include <linux/of_net.h>
24 #include <linux/sysfs.h>
25 #include <linux/phy_fixed.h>
28 char dsa_driver_version
[] = "0.1";
31 /* switch driver registration ***********************************************/
32 static DEFINE_MUTEX(dsa_switch_drivers_mutex
);
33 static LIST_HEAD(dsa_switch_drivers
);
35 void register_switch_driver(struct dsa_switch_driver
*drv
)
37 mutex_lock(&dsa_switch_drivers_mutex
);
38 list_add_tail(&drv
->list
, &dsa_switch_drivers
);
39 mutex_unlock(&dsa_switch_drivers_mutex
);
41 EXPORT_SYMBOL_GPL(register_switch_driver
);
43 void unregister_switch_driver(struct dsa_switch_driver
*drv
)
45 mutex_lock(&dsa_switch_drivers_mutex
);
46 list_del_init(&drv
->list
);
47 mutex_unlock(&dsa_switch_drivers_mutex
);
49 EXPORT_SYMBOL_GPL(unregister_switch_driver
);
51 static struct dsa_switch_driver
*
52 dsa_switch_probe(struct device
*host_dev
, int sw_addr
, char **_name
)
54 struct dsa_switch_driver
*ret
;
55 struct list_head
*list
;
61 mutex_lock(&dsa_switch_drivers_mutex
);
62 list_for_each(list
, &dsa_switch_drivers
) {
63 struct dsa_switch_driver
*drv
;
65 drv
= list_entry(list
, struct dsa_switch_driver
, list
);
67 name
= drv
->probe(host_dev
, sw_addr
);
73 mutex_unlock(&dsa_switch_drivers_mutex
);
80 /* hwmon support ************************************************************/
82 #ifdef CONFIG_NET_DSA_HWMON
84 static ssize_t
temp1_input_show(struct device
*dev
,
85 struct device_attribute
*attr
, char *buf
)
87 struct dsa_switch
*ds
= dev_get_drvdata(dev
);
90 ret
= ds
->drv
->get_temp(ds
, &temp
);
94 return sprintf(buf
, "%d\n", temp
* 1000);
96 static DEVICE_ATTR_RO(temp1_input
);
98 static ssize_t
temp1_max_show(struct device
*dev
,
99 struct device_attribute
*attr
, char *buf
)
101 struct dsa_switch
*ds
= dev_get_drvdata(dev
);
104 ret
= ds
->drv
->get_temp_limit(ds
, &temp
);
108 return sprintf(buf
, "%d\n", temp
* 1000);
111 static ssize_t
temp1_max_store(struct device
*dev
,
112 struct device_attribute
*attr
, const char *buf
,
115 struct dsa_switch
*ds
= dev_get_drvdata(dev
);
118 ret
= kstrtoint(buf
, 0, &temp
);
122 ret
= ds
->drv
->set_temp_limit(ds
, DIV_ROUND_CLOSEST(temp
, 1000));
128 static DEVICE_ATTR_RW(temp1_max
);
130 static ssize_t
temp1_max_alarm_show(struct device
*dev
,
131 struct device_attribute
*attr
, char *buf
)
133 struct dsa_switch
*ds
= dev_get_drvdata(dev
);
137 ret
= ds
->drv
->get_temp_alarm(ds
, &alarm
);
141 return sprintf(buf
, "%d\n", alarm
);
143 static DEVICE_ATTR_RO(temp1_max_alarm
);
145 static struct attribute
*dsa_hwmon_attrs
[] = {
146 &dev_attr_temp1_input
.attr
, /* 0 */
147 &dev_attr_temp1_max
.attr
, /* 1 */
148 &dev_attr_temp1_max_alarm
.attr
, /* 2 */
152 static umode_t
dsa_hwmon_attrs_visible(struct kobject
*kobj
,
153 struct attribute
*attr
, int index
)
155 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
156 struct dsa_switch
*ds
= dev_get_drvdata(dev
);
157 struct dsa_switch_driver
*drv
= ds
->drv
;
158 umode_t mode
= attr
->mode
;
161 if (!drv
->get_temp_limit
)
163 else if (!drv
->set_temp_limit
)
165 } else if (index
== 2 && !drv
->get_temp_alarm
) {
171 static const struct attribute_group dsa_hwmon_group
= {
172 .attrs
= dsa_hwmon_attrs
,
173 .is_visible
= dsa_hwmon_attrs_visible
,
175 __ATTRIBUTE_GROUPS(dsa_hwmon
);
177 #endif /* CONFIG_NET_DSA_HWMON */
179 /* basic switch operations **************************************************/
180 static int dsa_cpu_dsa_setup(struct dsa_switch
*ds
, struct net_device
*master
)
182 struct dsa_chip_data
*cd
= ds
->pd
;
183 struct device_node
*port_dn
;
184 struct phy_device
*phydev
;
187 for (port
= 0; port
< DSA_MAX_PORTS
; port
++) {
188 if (!(dsa_is_cpu_port(ds
, port
) || dsa_is_dsa_port(ds
, port
)))
191 port_dn
= cd
->port_dn
[port
];
192 if (of_phy_is_fixed_link(port_dn
)) {
193 ret
= of_phy_register_fixed_link(port_dn
);
196 "failed to register fixed PHY\n");
199 phydev
= of_phy_find_device(port_dn
);
201 mode
= of_get_phy_mode(port_dn
);
203 mode
= PHY_INTERFACE_MODE_NA
;
204 phydev
->interface
= mode
;
206 genphy_config_init(phydev
);
207 genphy_read_status(phydev
);
208 if (ds
->drv
->adjust_link
)
209 ds
->drv
->adjust_link(ds
, port
, phydev
);
215 static int dsa_switch_setup_one(struct dsa_switch
*ds
, struct device
*parent
)
217 struct dsa_switch_driver
*drv
= ds
->drv
;
218 struct dsa_switch_tree
*dst
= ds
->dst
;
219 struct dsa_chip_data
*pd
= ds
->pd
;
220 bool valid_name_found
= false;
221 int index
= ds
->index
;
225 * Validate supplied switch configuration.
227 for (i
= 0; i
< DSA_MAX_PORTS
; i
++) {
230 name
= pd
->port_names
[i
];
234 if (!strcmp(name
, "cpu")) {
235 if (dst
->cpu_switch
!= -1) {
236 netdev_err(dst
->master_netdev
,
237 "multiple cpu ports?!\n");
241 dst
->cpu_switch
= index
;
243 } else if (!strcmp(name
, "dsa")) {
244 ds
->dsa_port_mask
|= 1 << i
;
246 ds
->phys_port_mask
|= 1 << i
;
248 valid_name_found
= true;
251 if (!valid_name_found
&& i
== DSA_MAX_PORTS
) {
256 /* Make the built-in MII bus mask match the number of ports,
257 * switch drivers can override this later
259 ds
->phys_mii_mask
= ds
->phys_port_mask
;
262 * If the CPU connects to this switch, set the switch tree
263 * tagging protocol to the preferred tagging format of this
266 if (dst
->cpu_switch
== index
) {
267 switch (ds
->tag_protocol
) {
268 #ifdef CONFIG_NET_DSA_TAG_DSA
269 case DSA_TAG_PROTO_DSA
:
270 dst
->rcv
= dsa_netdev_ops
.rcv
;
273 #ifdef CONFIG_NET_DSA_TAG_EDSA
274 case DSA_TAG_PROTO_EDSA
:
275 dst
->rcv
= edsa_netdev_ops
.rcv
;
278 #ifdef CONFIG_NET_DSA_TAG_TRAILER
279 case DSA_TAG_PROTO_TRAILER
:
280 dst
->rcv
= trailer_netdev_ops
.rcv
;
283 #ifdef CONFIG_NET_DSA_TAG_BRCM
284 case DSA_TAG_PROTO_BRCM
:
285 dst
->rcv
= brcm_netdev_ops
.rcv
;
288 case DSA_TAG_PROTO_NONE
:
295 dst
->tag_protocol
= ds
->tag_protocol
;
299 * Do basic register setup.
301 ret
= drv
->setup(ds
);
305 ret
= drv
->set_addr(ds
, dst
->master_netdev
->dev_addr
);
309 ds
->slave_mii_bus
= devm_mdiobus_alloc(parent
);
310 if (ds
->slave_mii_bus
== NULL
) {
314 dsa_slave_mii_bus_init(ds
);
316 ret
= mdiobus_register(ds
->slave_mii_bus
);
322 * Create network devices for physical switch ports.
324 for (i
= 0; i
< DSA_MAX_PORTS
; i
++) {
325 if (!(ds
->phys_port_mask
& (1 << i
)))
328 ret
= dsa_slave_create(ds
, parent
, i
, pd
->port_names
[i
]);
330 netdev_err(dst
->master_netdev
, "[%d]: can't create dsa slave device for port %d(%s)\n",
331 index
, i
, pd
->port_names
[i
]);
336 /* Perform configuration of the CPU and DSA ports */
337 ret
= dsa_cpu_dsa_setup(ds
, dst
->master_netdev
);
339 netdev_err(dst
->master_netdev
, "[%d] : can't configure CPU and DSA ports\n",
344 #ifdef CONFIG_NET_DSA_HWMON
345 /* If the switch provides a temperature sensor,
346 * register with hardware monitoring subsystem.
347 * Treat registration error as non-fatal and ignore it.
350 const char *netname
= netdev_name(dst
->master_netdev
);
351 char hname
[IFNAMSIZ
+ 1];
354 /* Create valid hwmon 'name' attribute */
355 for (i
= j
= 0; i
< IFNAMSIZ
&& netname
[i
]; i
++) {
356 if (isalnum(netname
[i
]))
357 hname
[j
++] = netname
[i
];
360 scnprintf(ds
->hwmon_name
, sizeof(ds
->hwmon_name
), "%s_dsa%d",
362 ds
->hwmon_dev
= hwmon_device_register_with_groups(NULL
,
363 ds
->hwmon_name
, ds
, dsa_hwmon_groups
);
364 if (IS_ERR(ds
->hwmon_dev
))
365 ds
->hwmon_dev
= NULL
;
367 #endif /* CONFIG_NET_DSA_HWMON */
375 static struct dsa_switch
*
376 dsa_switch_setup(struct dsa_switch_tree
*dst
, int index
,
377 struct device
*parent
, struct device
*host_dev
)
379 struct dsa_chip_data
*pd
= dst
->pd
->chip
+ index
;
380 struct dsa_switch_driver
*drv
;
381 struct dsa_switch
*ds
;
386 * Probe for switch model.
388 drv
= dsa_switch_probe(host_dev
, pd
->sw_addr
, &name
);
390 netdev_err(dst
->master_netdev
, "[%d]: could not detect attached switch\n",
392 return ERR_PTR(-EINVAL
);
394 netdev_info(dst
->master_netdev
, "[%d]: detected a %s switch\n",
399 * Allocate and initialise switch state.
401 ds
= devm_kzalloc(parent
, sizeof(*ds
) + drv
->priv_size
, GFP_KERNEL
);
403 return ERR_PTR(-ENOMEM
);
409 ds
->tag_protocol
= drv
->tag_protocol
;
410 ds
->master_dev
= host_dev
;
412 ret
= dsa_switch_setup_one(ds
, parent
);
419 static void dsa_switch_destroy(struct dsa_switch
*ds
)
421 struct device_node
*port_dn
;
422 struct phy_device
*phydev
;
423 struct dsa_chip_data
*cd
= ds
->pd
;
426 #ifdef CONFIG_NET_DSA_HWMON
428 hwmon_device_unregister(ds
->hwmon_dev
);
431 /* Disable configuration of the CPU and DSA ports */
432 for (port
= 0; port
< DSA_MAX_PORTS
; port
++) {
433 if (!(dsa_is_cpu_port(ds
, port
) || dsa_is_dsa_port(ds
, port
)))
436 port_dn
= cd
->port_dn
[port
];
437 if (of_phy_is_fixed_link(port_dn
)) {
438 phydev
= of_phy_find_device(port_dn
);
440 int addr
= phydev
->addr
;
442 phy_device_free(phydev
);
443 of_node_put(port_dn
);
449 /* Destroy network devices for physical switch ports. */
450 for (port
= 0; port
< DSA_MAX_PORTS
; port
++) {
451 if (!(ds
->phys_port_mask
& (1 << port
)))
454 if (!ds
->ports
[port
])
457 unregister_netdev(ds
->ports
[port
]);
458 free_netdev(ds
->ports
[port
]);
461 mdiobus_unregister(ds
->slave_mii_bus
);
464 #ifdef CONFIG_PM_SLEEP
465 static int dsa_switch_suspend(struct dsa_switch
*ds
)
469 /* Suspend slave network devices */
470 for (i
= 0; i
< DSA_MAX_PORTS
; i
++) {
471 if (!dsa_is_port_initialized(ds
, i
))
474 ret
= dsa_slave_suspend(ds
->ports
[i
]);
479 if (ds
->drv
->suspend
)
480 ret
= ds
->drv
->suspend(ds
);
485 static int dsa_switch_resume(struct dsa_switch
*ds
)
490 ret
= ds
->drv
->resume(ds
);
495 /* Resume slave network devices */
496 for (i
= 0; i
< DSA_MAX_PORTS
; i
++) {
497 if (!dsa_is_port_initialized(ds
, i
))
500 ret
= dsa_slave_resume(ds
->ports
[i
]);
510 /* link polling *************************************************************/
511 static void dsa_link_poll_work(struct work_struct
*ugly
)
513 struct dsa_switch_tree
*dst
;
516 dst
= container_of(ugly
, struct dsa_switch_tree
, link_poll_work
);
518 for (i
= 0; i
< dst
->pd
->nr_chips
; i
++) {
519 struct dsa_switch
*ds
= dst
->ds
[i
];
521 if (ds
!= NULL
&& ds
->drv
->poll_link
!= NULL
)
522 ds
->drv
->poll_link(ds
);
525 mod_timer(&dst
->link_poll_timer
, round_jiffies(jiffies
+ HZ
));
528 static void dsa_link_poll_timer(unsigned long _dst
)
530 struct dsa_switch_tree
*dst
= (void *)_dst
;
532 schedule_work(&dst
->link_poll_work
);
536 /* platform driver init and cleanup *****************************************/
537 static int dev_is_class(struct device
*dev
, void *class)
539 if (dev
->class != NULL
&& !strcmp(dev
->class->name
, class))
545 static struct device
*dev_find_class(struct device
*parent
, char *class)
547 if (dev_is_class(parent
, class)) {
552 return device_find_child(parent
, class, dev_is_class
);
555 struct mii_bus
*dsa_host_dev_to_mii_bus(struct device
*dev
)
559 d
= dev_find_class(dev
, "mdio_bus");
571 EXPORT_SYMBOL_GPL(dsa_host_dev_to_mii_bus
);
573 static struct net_device
*dev_to_net_device(struct device
*dev
)
577 d
= dev_find_class(dev
, "net");
579 struct net_device
*nd
;
592 static int dsa_of_setup_routing_table(struct dsa_platform_data
*pd
,
593 struct dsa_chip_data
*cd
,
594 int chip_index
, int port_index
,
595 struct device_node
*link
)
599 struct device_node
*parent_sw
;
602 parent_sw
= of_get_parent(link
);
606 reg
= of_get_property(parent_sw
, "reg", &len
);
607 if (!reg
|| (len
!= sizeof(*reg
) * 2))
611 * Get the destination switch number from the second field of its 'reg'
612 * property, i.e. for "reg = <0x19 1>" sw_addr is '1'.
614 link_sw_addr
= be32_to_cpup(reg
+ 1);
616 if (link_sw_addr
>= pd
->nr_chips
)
619 /* First time routing table allocation */
621 cd
->rtable
= kmalloc_array(pd
->nr_chips
, sizeof(s8
),
626 /* default to no valid uplink/downlink */
627 memset(cd
->rtable
, -1, pd
->nr_chips
* sizeof(s8
));
630 cd
->rtable
[link_sw_addr
] = port_index
;
635 static int dsa_of_probe_links(struct dsa_platform_data
*pd
,
636 struct dsa_chip_data
*cd
,
637 int chip_index
, int port_index
,
638 struct device_node
*port
,
639 const char *port_name
)
641 struct device_node
*link
;
645 for (link_index
= 0;; link_index
++) {
646 link
= of_parse_phandle(port
, "link", link_index
);
650 if (!strcmp(port_name
, "dsa") && pd
->nr_chips
> 1) {
651 ret
= dsa_of_setup_routing_table(pd
, cd
, chip_index
,
660 static void dsa_of_free_platform_data(struct dsa_platform_data
*pd
)
665 for (i
= 0; i
< pd
->nr_chips
; i
++) {
667 while (port_index
< DSA_MAX_PORTS
) {
668 kfree(pd
->chip
[i
].port_names
[port_index
]);
671 kfree(pd
->chip
[i
].rtable
);
673 /* Drop our reference to the MDIO bus device */
674 if (pd
->chip
[i
].host_dev
)
675 put_device(pd
->chip
[i
].host_dev
);
680 static int dsa_of_probe(struct device
*dev
)
682 struct device_node
*np
= dev
->of_node
;
683 struct device_node
*child
, *mdio
, *ethernet
, *port
;
684 struct mii_bus
*mdio_bus
, *mdio_bus_switch
;
685 struct net_device
*ethernet_dev
;
686 struct dsa_platform_data
*pd
;
687 struct dsa_chip_data
*cd
;
688 const char *port_name
;
689 int chip_index
, port_index
;
690 const unsigned int *sw_addr
, *port_reg
;
694 mdio
= of_parse_phandle(np
, "dsa,mii-bus", 0);
698 mdio_bus
= of_mdio_find_bus(mdio
);
700 return -EPROBE_DEFER
;
702 ethernet
= of_parse_phandle(np
, "dsa,ethernet", 0);
708 ethernet_dev
= of_find_net_device_by_node(ethernet
);
714 pd
= kzalloc(sizeof(*pd
), GFP_KERNEL
);
717 goto out_put_ethernet
;
720 dev
->platform_data
= pd
;
721 pd
->of_netdev
= ethernet_dev
;
722 pd
->nr_chips
= of_get_available_child_count(np
);
723 if (pd
->nr_chips
> DSA_MAX_SWITCHES
)
724 pd
->nr_chips
= DSA_MAX_SWITCHES
;
726 pd
->chip
= kcalloc(pd
->nr_chips
, sizeof(struct dsa_chip_data
),
734 for_each_available_child_of_node(np
, child
) {
736 cd
= &pd
->chip
[chip_index
];
740 /* When assigning the host device, increment its refcount */
741 cd
->host_dev
= get_device(&mdio_bus
->dev
);
743 sw_addr
= of_get_property(child
, "reg", NULL
);
747 cd
->sw_addr
= be32_to_cpup(sw_addr
);
748 if (cd
->sw_addr
>= PHY_MAX_ADDR
)
751 if (!of_property_read_u32(child
, "eeprom-length", &eeprom_len
))
752 cd
->eeprom_len
= eeprom_len
;
754 mdio
= of_parse_phandle(child
, "mii-bus", 0);
756 mdio_bus_switch
= of_mdio_find_bus(mdio
);
757 if (!mdio_bus_switch
) {
762 /* Drop the mdio_bus device ref, replacing the host
763 * device with the mdio_bus_switch device, keeping
764 * the refcount from of_mdio_find_bus() above.
766 put_device(cd
->host_dev
);
767 cd
->host_dev
= &mdio_bus_switch
->dev
;
770 for_each_available_child_of_node(child
, port
) {
771 port_reg
= of_get_property(port
, "reg", NULL
);
775 port_index
= be32_to_cpup(port_reg
);
776 if (port_index
>= DSA_MAX_PORTS
)
779 port_name
= of_get_property(port
, "label", NULL
);
783 cd
->port_dn
[port_index
] = port
;
785 cd
->port_names
[port_index
] = kstrdup(port_name
,
787 if (!cd
->port_names
[port_index
]) {
792 ret
= dsa_of_probe_links(pd
, cd
, chip_index
,
793 port_index
, port
, port_name
);
800 /* The individual chips hold their own refcount on the mdio bus,
802 put_device(&mdio_bus
->dev
);
807 dsa_of_free_platform_data(pd
);
810 dev
->platform_data
= NULL
;
812 put_device(ðernet_dev
->dev
);
814 put_device(&mdio_bus
->dev
);
818 static void dsa_of_remove(struct device
*dev
)
820 struct dsa_platform_data
*pd
= dev
->platform_data
;
825 dsa_of_free_platform_data(pd
);
826 put_device(&pd
->of_netdev
->dev
);
830 static inline int dsa_of_probe(struct device
*dev
)
835 static inline void dsa_of_remove(struct device
*dev
)
840 static int dsa_setup_dst(struct dsa_switch_tree
*dst
, struct net_device
*dev
,
841 struct device
*parent
, struct dsa_platform_data
*pd
)
844 unsigned configured
= 0;
847 dst
->master_netdev
= dev
;
848 dst
->cpu_switch
= -1;
851 for (i
= 0; i
< pd
->nr_chips
; i
++) {
852 struct dsa_switch
*ds
;
854 ds
= dsa_switch_setup(dst
, i
, parent
, pd
->chip
[i
].host_dev
);
856 netdev_err(dev
, "[%d]: couldn't create dsa switch instance (error %ld)\n",
862 if (ds
->drv
->poll_link
!= NULL
)
863 dst
->link_poll_needed
= 1;
869 * If no switch was found, exit cleanly
872 return -EPROBE_DEFER
;
875 * If we use a tagging format that doesn't have an ethertype
876 * field, make sure that all packets from this point on get
877 * sent to the tag format's receive function.
880 dev
->dsa_ptr
= (void *)dst
;
882 if (dst
->link_poll_needed
) {
883 INIT_WORK(&dst
->link_poll_work
, dsa_link_poll_work
);
884 init_timer(&dst
->link_poll_timer
);
885 dst
->link_poll_timer
.data
= (unsigned long)dst
;
886 dst
->link_poll_timer
.function
= dsa_link_poll_timer
;
887 dst
->link_poll_timer
.expires
= round_jiffies(jiffies
+ HZ
);
888 add_timer(&dst
->link_poll_timer
);
894 static int dsa_probe(struct platform_device
*pdev
)
896 struct dsa_platform_data
*pd
= pdev
->dev
.platform_data
;
897 struct net_device
*dev
;
898 struct dsa_switch_tree
*dst
;
901 pr_notice_once("Distributed Switch Architecture driver version %s\n",
904 if (pdev
->dev
.of_node
) {
905 ret
= dsa_of_probe(&pdev
->dev
);
909 pd
= pdev
->dev
.platform_data
;
912 if (pd
== NULL
|| (pd
->netdev
== NULL
&& pd
->of_netdev
== NULL
))
919 dev
= dev_to_net_device(pd
->netdev
);
926 if (dev
->dsa_ptr
!= NULL
) {
932 dst
= devm_kzalloc(&pdev
->dev
, sizeof(*dst
), GFP_KERNEL
);
939 platform_set_drvdata(pdev
, dst
);
941 ret
= dsa_setup_dst(dst
, dev
, &pdev
->dev
, pd
);
948 dsa_of_remove(&pdev
->dev
);
953 static void dsa_remove_dst(struct dsa_switch_tree
*dst
)
957 if (dst
->link_poll_needed
)
958 del_timer_sync(&dst
->link_poll_timer
);
960 flush_work(&dst
->link_poll_work
);
962 for (i
= 0; i
< dst
->pd
->nr_chips
; i
++) {
963 struct dsa_switch
*ds
= dst
->ds
[i
];
966 dsa_switch_destroy(ds
);
970 static int dsa_remove(struct platform_device
*pdev
)
972 struct dsa_switch_tree
*dst
= platform_get_drvdata(pdev
);
975 dsa_of_remove(&pdev
->dev
);
980 static void dsa_shutdown(struct platform_device
*pdev
)
984 static int dsa_switch_rcv(struct sk_buff
*skb
, struct net_device
*dev
,
985 struct packet_type
*pt
, struct net_device
*orig_dev
)
987 struct dsa_switch_tree
*dst
= dev
->dsa_ptr
;
989 if (unlikely(dst
== NULL
)) {
994 return dst
->rcv(skb
, dev
, pt
, orig_dev
);
997 static struct packet_type dsa_pack_type __read_mostly
= {
998 .type
= cpu_to_be16(ETH_P_XDSA
),
999 .func
= dsa_switch_rcv
,
1002 static struct notifier_block dsa_netdevice_nb __read_mostly
= {
1003 .notifier_call
= dsa_slave_netdevice_event
,
1006 #ifdef CONFIG_PM_SLEEP
1007 static int dsa_suspend(struct device
*d
)
1009 struct platform_device
*pdev
= to_platform_device(d
);
1010 struct dsa_switch_tree
*dst
= platform_get_drvdata(pdev
);
1013 for (i
= 0; i
< dst
->pd
->nr_chips
; i
++) {
1014 struct dsa_switch
*ds
= dst
->ds
[i
];
1017 ret
= dsa_switch_suspend(ds
);
1023 static int dsa_resume(struct device
*d
)
1025 struct platform_device
*pdev
= to_platform_device(d
);
1026 struct dsa_switch_tree
*dst
= platform_get_drvdata(pdev
);
1029 for (i
= 0; i
< dst
->pd
->nr_chips
; i
++) {
1030 struct dsa_switch
*ds
= dst
->ds
[i
];
1033 ret
= dsa_switch_resume(ds
);
1040 static SIMPLE_DEV_PM_OPS(dsa_pm_ops
, dsa_suspend
, dsa_resume
);
1042 static const struct of_device_id dsa_of_match_table
[] = {
1043 { .compatible
= "brcm,bcm7445-switch-v4.0" },
1044 { .compatible
= "marvell,dsa", },
1047 MODULE_DEVICE_TABLE(of
, dsa_of_match_table
);
1049 static struct platform_driver dsa_driver
= {
1051 .remove
= dsa_remove
,
1052 .shutdown
= dsa_shutdown
,
1055 .of_match_table
= dsa_of_match_table
,
1060 static int __init
dsa_init_module(void)
1064 register_netdevice_notifier(&dsa_netdevice_nb
);
1066 rc
= platform_driver_register(&dsa_driver
);
1070 dev_add_pack(&dsa_pack_type
);
1074 module_init(dsa_init_module
);
1076 static void __exit
dsa_cleanup_module(void)
1078 unregister_netdevice_notifier(&dsa_netdevice_nb
);
1079 dev_remove_pack(&dsa_pack_type
);
1080 platform_driver_unregister(&dsa_driver
);
1082 module_exit(dsa_cleanup_module
);
1084 MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
1085 MODULE_DESCRIPTION("Driver for Distributed Switch Architecture switch chips");
1086 MODULE_LICENSE("GPL");
1087 MODULE_ALIAS("platform:dsa");