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)
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>
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
,
26 struct net_device
*dev
;
27 struct hsr_port
*port
, *master
;
32 dev
= netdev_notifier_info_to_dev(ptr
);
33 port
= hsr_port_get_rtnl(dev
);
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
);
40 /* Resend of notification concerning removed device? */
48 case NETDEV_UP
: /* Administrative state DOWN */
49 case NETDEV_DOWN
: /* Administrative state UP */
50 case NETDEV_CHANGE
: /* Link (carrier) state changes */
51 hsr_check_carrier_and_operstate(hsr
);
53 case NETDEV_CHANGEADDR
:
54 if (port
->type
== HSR_PT_MASTER
) {
55 /* This should not happen since there's no
56 * ndo_set_mac_address() for HSR devices - i.e. not
62 master
= hsr_port_get_hsr(hsr
, HSR_PT_MASTER
);
64 if (port
->type
== HSR_PT_SLAVE_A
) {
65 ether_addr_copy(master
->dev
->dev_addr
, dev
->dev_addr
);
66 call_netdevice_notifiers(NETDEV_CHANGEADDR
, master
->dev
);
69 /* Make sure we recognize frames from ourselves in hsr_rcv() */
70 port
= hsr_port_get_hsr(hsr
, HSR_PT_SLAVE_B
);
71 res
= hsr_create_self_node(&hsr
->self_node_db
,
72 master
->dev
->dev_addr
,
75 master
->dev
->dev_addr
);
77 netdev_warn(master
->dev
,
78 "Could not update HSR node address.\n");
80 case NETDEV_CHANGEMTU
:
81 if (port
->type
== HSR_PT_MASTER
)
82 break; /* Handled in ndo_change_mtu() */
83 mtu_max
= hsr_get_max_mtu(port
->hsr
);
84 master
= hsr_port_get_hsr(port
->hsr
, HSR_PT_MASTER
);
85 master
->dev
->mtu
= mtu_max
;
87 case NETDEV_UNREGISTER
:
90 case NETDEV_PRE_TYPE_CHANGE
:
91 /* HSR works only on Ethernet devices. Refuse slave to change
101 struct hsr_port
*hsr_port_get_hsr(struct hsr_priv
*hsr
, enum hsr_port_type pt
)
103 struct hsr_port
*port
;
105 hsr_for_each_port(hsr
, port
)
106 if (port
->type
== pt
)
111 static struct notifier_block hsr_nb
= {
112 .notifier_call
= hsr_netdev_notify
, /* Slave event notifications */
116 static int __init
hsr_init(void)
120 BUILD_BUG_ON(sizeof(struct hsr_tag
) != HSR_HLEN
);
122 register_netdevice_notifier(&hsr_nb
);
123 res
= hsr_netlink_init();
128 static void __exit
hsr_exit(void)
130 unregister_netdevice_notifier(&hsr_nb
);
134 module_init(hsr_init
);
135 module_exit(hsr_exit
);
136 MODULE_LICENSE("GPL");