datapath: Add support for Linux 3.11
[sliver-openvswitch.git] / datapath / linux / compat / include / linux / netdevice.h
1 #ifndef __LINUX_NETDEVICE_WRAPPER_H
2 #define __LINUX_NETDEVICE_WRAPPER_H 1
3
4 #include_next <linux/netdevice.h>
5
6 struct net;
7
8 #include <linux/version.h>
9
10 #ifndef to_net_dev
11 #define to_net_dev(class) container_of(class, struct net_device, NETDEV_DEV_MEMBER)
12 #endif
13
14 #ifdef HAVE_RHEL_OVS_HOOK
15 extern struct sk_buff *(*openvswitch_handle_frame_hook)(struct sk_buff *skb);
16 extern int nr_bridges;
17 #endif
18
19 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)
20 extern void unregister_netdevice_queue(struct net_device *dev,
21                                         struct list_head *head);
22 extern void unregister_netdevice_many(struct list_head *head);
23 #endif
24
25 #ifndef HAVE_DEV_DISABLE_LRO
26 extern void dev_disable_lro(struct net_device *dev);
27 #endif
28
29 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) || \
30     defined HAVE_RHEL_OVS_HOOK
31 static inline int netdev_rx_handler_register(struct net_device *dev,
32                                              void *rx_handler,
33                                              void *rx_handler_data)
34 {
35 #ifdef HAVE_RHEL_OVS_HOOK
36         rcu_assign_pointer(dev->ax25_ptr, rx_handler_data);
37         nr_bridges++;
38         rcu_assign_pointer(openvswitch_handle_frame_hook, rx_handler);
39 #else
40         if (dev->br_port)
41                 return -EBUSY;
42         rcu_assign_pointer(dev->br_port, rx_handler_data);
43 #endif
44         return 0;
45 }
46 static inline void netdev_rx_handler_unregister(struct net_device *dev)
47 {
48 #ifdef HAVE_RHEL_OVS_HOOK
49         rcu_assign_pointer(dev->ax25_ptr, NULL);
50
51         if (--nr_bridges <= 0)
52                 rcu_assign_pointer(openvswitch_handle_frame_hook, NULL);
53 #else
54         rcu_assign_pointer(dev->br_port, NULL);
55 #endif
56 }
57 #endif
58
59 #ifndef HAVE_DEV_GET_BY_INDEX_RCU
60 static inline struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
61 {
62         struct net_device *dev;
63
64         read_lock(&dev_base_lock);
65         dev = __dev_get_by_index(net, ifindex);
66         read_unlock(&dev_base_lock);
67
68         return dev;
69 }
70 #endif
71
72 #ifndef NETIF_F_FSO
73 #define NETIF_F_FSO 0
74 #endif
75
76 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38)
77 #define skb_gso_segment rpl_skb_gso_segment
78 struct sk_buff *rpl_skb_gso_segment(struct sk_buff *skb, u32 features);
79
80 #define netif_skb_features rpl_netif_skb_features
81 u32 rpl_netif_skb_features(struct sk_buff *skb);
82
83 #define netif_needs_gso rpl_netif_needs_gso
84 static inline int rpl_netif_needs_gso(struct sk_buff *skb, int features)
85 {
86         return skb_is_gso(skb) && (!skb_gso_ok(skb, features) ||
87                 unlikely(skb->ip_summed != CHECKSUM_PARTIAL));
88 }
89 #endif
90
91 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0)
92 typedef u32 netdev_features_t;
93 #endif
94
95 #ifndef HAVE___SKB_GSO_SEGMENT
96 static inline struct sk_buff *__skb_gso_segment(struct sk_buff *skb,
97                                                 netdev_features_t features,
98                                                 bool tx_path)
99 {
100         return skb_gso_segment(skb, features);
101 }
102 #endif
103
104 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0)
105
106 /* XEN dom0 networking assumes dev->master is bond device
107  * and it tries to access bond private structure from dev->master
108  * ptr on receive path. This causes panic. Therefore it is better
109  * not to backport this API.
110  **/
111 static inline int netdev_master_upper_dev_link(struct net_device *dev,
112                                                struct net_device *upper_dev)
113 {
114         return 0;
115 }
116
117 static inline void netdev_upper_dev_unlink(struct net_device *dev,
118                                            struct net_device *upper_dev)
119 {
120 }
121
122 static inline struct net_device *netdev_master_upper_dev_get(struct net_device *dev)
123 {
124         return NULL;
125 }
126 #endif
127
128 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37)
129 #define dev_queue_xmit rpl_dev_queue_xmit
130 int dev_queue_xmit(struct sk_buff *skb);
131 #endif
132
133 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,11,0)
134 static inline struct net_device *netdev_notifier_info_to_dev(void *info)
135 {
136         return info;
137 }
138 #endif
139
140 #endif