net/hsr: Use list_head (and rcu) instead of array for slave devices.
[cascardo/linux.git] / net / hsr / hsr_slave.h
1 /* Copyright 2011-2014 Autronica Fire and Security AS
2  *
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.
7  *
8  * Author(s):
9  *      2011-2014 Arvid Brodin, arvid.brodin@alten.se
10  */
11
12 #ifndef __HSR_SLAVE_H
13 #define __HSR_SLAVE_H
14
15 #include <linux/skbuff.h>
16 #include <linux/netdevice.h>
17 #include <linux/rtnetlink.h>
18 #include "hsr_main.h"
19
20 int hsr_add_port(struct hsr_priv *hsr, struct net_device *dev,
21                  enum hsr_port_type pt);
22 void hsr_del_port(struct hsr_port *port);
23 rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb);
24
25
26 #define hsr_for_each_port(hsr, port) \
27         list_for_each_entry_rcu((port), &(hsr)->ports, port_list)
28
29
30 static inline bool hsr_port_exists(const struct net_device *dev)
31 {
32         return dev->rx_handler == hsr_handle_frame;
33 }
34
35 static inline struct hsr_port *hsr_port_get_rtnl(const struct net_device *dev)
36 {
37         ASSERT_RTNL();
38         return hsr_port_exists(dev) ?
39                                 rtnl_dereference(dev->rx_handler_data) : NULL;
40 }
41
42 static inline struct hsr_port *hsr_port_get_rcu(const struct net_device *dev)
43 {
44         return hsr_port_exists(dev) ?
45                                 rcu_dereference(dev->rx_handler_data) : NULL;
46 }
47
48 #endif /* __HSR_SLAVE_H */