btrfs: fix sizeof format specifier in btrfs_check_super_valid()
[linux/fpc-iii.git] / net / hsr / hsr_main.c
blob779d28b65417a6e62b687d8f5ea36d6be285f417
1 /* Copyright 2011-2014 Autronica Fire and Security AS
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the Free
5 * Software Foundation; either version 2 of the License, or (at your option)
6 * any later version.
8 * Author(s):
9 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
12 #include <linux/netdevice.h>
13 #include <linux/rculist.h>
14 #include <linux/timer.h>
15 #include <linux/etherdevice.h>
16 #include "hsr_main.h"
17 #include "hsr_device.h"
18 #include "hsr_netlink.h"
19 #include "hsr_framereg.h"
20 #include "hsr_slave.h"
23 static int hsr_netdev_notify(struct notifier_block *nb, unsigned long event,
24 void *ptr)
26 struct net_device *dev;
27 struct hsr_port *port, *master;
28 struct hsr_priv *hsr;
29 int mtu_max;
30 int res;
32 dev = netdev_notifier_info_to_dev(ptr);
33 port = hsr_port_get_rtnl(dev);
34 if (port == NULL) {
35 if (!is_hsr_master(dev))
36 return NOTIFY_DONE; /* Not an HSR device */
37 hsr = netdev_priv(dev);
38 port = hsr_port_get_hsr(hsr, HSR_PT_MASTER);
39 } else {
40 hsr = port->hsr;
43 switch (event) {
44 case NETDEV_UP: /* Administrative state DOWN */
45 case NETDEV_DOWN: /* Administrative state UP */
46 case NETDEV_CHANGE: /* Link (carrier) state changes */
47 hsr_check_carrier_and_operstate(hsr);
48 break;
49 case NETDEV_CHANGEADDR:
50 if (port->type == HSR_PT_MASTER) {
51 /* This should not happen since there's no
52 * ndo_set_mac_address() for HSR devices - i.e. not
53 * supported.
55 break;
58 master = hsr_port_get_hsr(hsr, HSR_PT_MASTER);
60 if (port->type == HSR_PT_SLAVE_A) {
61 ether_addr_copy(master->dev->dev_addr, dev->dev_addr);
62 call_netdevice_notifiers(NETDEV_CHANGEADDR, master->dev);
65 /* Make sure we recognize frames from ourselves in hsr_rcv() */
66 port = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_B);
67 res = hsr_create_self_node(&hsr->self_node_db,
68 master->dev->dev_addr,
69 port ?
70 port->dev->dev_addr :
71 master->dev->dev_addr);
72 if (res)
73 netdev_warn(master->dev,
74 "Could not update HSR node address.\n");
75 break;
76 case NETDEV_CHANGEMTU:
77 if (port->type == HSR_PT_MASTER)
78 break; /* Handled in ndo_change_mtu() */
79 mtu_max = hsr_get_max_mtu(port->hsr);
80 master = hsr_port_get_hsr(port->hsr, HSR_PT_MASTER);
81 master->dev->mtu = mtu_max;
82 break;
83 case NETDEV_UNREGISTER:
84 hsr_del_port(port);
85 break;
86 case NETDEV_PRE_TYPE_CHANGE:
87 /* HSR works only on Ethernet devices. Refuse slave to change
88 * its type.
90 return NOTIFY_BAD;
93 return NOTIFY_DONE;
97 struct hsr_port *hsr_port_get_hsr(struct hsr_priv *hsr, enum hsr_port_type pt)
99 struct hsr_port *port;
101 hsr_for_each_port(hsr, port)
102 if (port->type == pt)
103 return port;
104 return NULL;
107 static struct notifier_block hsr_nb = {
108 .notifier_call = hsr_netdev_notify, /* Slave event notifications */
112 static int __init hsr_init(void)
114 int res;
116 BUILD_BUG_ON(sizeof(struct hsr_tag) != HSR_HLEN);
118 register_netdevice_notifier(&hsr_nb);
119 res = hsr_netlink_init();
121 return res;
124 static void __exit hsr_exit(void)
126 unregister_netdevice_notifier(&hsr_nb);
127 hsr_netlink_exit();
130 module_init(hsr_init);
131 module_exit(hsr_exit);
132 MODULE_LICENSE("GPL");