datapath: compat: Fix compilation for 2.6.32 kernel
[cascardo/ovs.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 #include <linux/if_bridge.h>
6
7 struct net;
8
9 #include <linux/version.h>
10
11 #ifndef IFF_TX_SKB_SHARING
12 #define IFF_TX_SKB_SHARING 0
13 #endif
14
15 #ifndef IFF_OVS_DATAPATH
16 #define IFF_OVS_DATAPATH 0
17 #else
18 #define HAVE_OVS_DATAPATH
19 #endif
20
21 #ifndef IFF_LIVE_ADDR_CHANGE
22 #define IFF_LIVE_ADDR_CHANGE 0
23 #endif
24
25 #ifndef to_net_dev
26 #define to_net_dev(class) container_of(class, struct net_device, NETDEV_DEV_MEMBER)
27 #endif
28
29 #ifndef HAVE_NET_NAME_UNKNOWN
30 #undef alloc_netdev
31 #define NET_NAME_UNKNOWN 0
32 #define alloc_netdev(sizeof_priv, name, name_assign_type, setup) \
33         alloc_netdev_mq(sizeof_priv, name, setup, 1)
34 #endif
35
36 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)
37 extern void unregister_netdevice_queue(struct net_device *dev,
38                                         struct list_head *head);
39 extern void unregister_netdevice_many(struct list_head *head);
40 #endif
41
42 #ifndef HAVE_DEV_DISABLE_LRO
43 extern void dev_disable_lro(struct net_device *dev);
44 #endif
45
46 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) || \
47     defined HAVE_RHEL_OVS_HOOK
48
49 #ifdef HAVE_RHEL_OVS_HOOK
50 typedef struct sk_buff *(openvswitch_handle_frame_hook_t)(struct sk_buff *skb);
51 extern openvswitch_handle_frame_hook_t *openvswitch_handle_frame_hook;
52
53 int netdev_rx_handler_register(struct net_device *dev,
54                                openvswitch_handle_frame_hook_t *hook,
55                                void *rx_handler_data);
56 #else
57
58 int netdev_rx_handler_register(struct net_device *dev,
59                                struct sk_buff *(*netdev_hook)(struct net_bridge_port *p,
60                                                              struct sk_buff *skb),
61                                void *rx_handler_data);
62 #endif
63
64 void netdev_rx_handler_unregister(struct net_device *dev);
65 #endif
66
67 #ifndef HAVE_DEV_GET_BY_INDEX_RCU
68 static inline struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
69 {
70         struct net_device *dev;
71
72         read_lock(&dev_base_lock);
73         dev = __dev_get_by_index(net, ifindex);
74         read_unlock(&dev_base_lock);
75
76         return dev;
77 }
78 #endif
79
80 #ifndef NETIF_F_FSO
81 #define NETIF_F_FSO 0
82 #endif
83
84 #ifndef HAVE_NETDEV_FEATURES_T
85 typedef u32 netdev_features_t;
86 #endif
87
88 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,16,0)
89 #define skb_gso_segment rpl_skb_gso_segment
90 struct sk_buff *rpl_skb_gso_segment(struct sk_buff *skb,
91                                     netdev_features_t features);
92 #endif
93
94 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38)
95 #define netif_skb_features rpl_netif_skb_features
96 netdev_features_t rpl_netif_skb_features(struct sk_buff *skb);
97
98 #define netif_needs_gso rpl_netif_needs_gso
99 static inline int rpl_netif_needs_gso(struct sk_buff *skb, int features)
100 {
101         return skb_is_gso(skb) && (!skb_gso_ok(skb, features) ||
102                 unlikely(skb->ip_summed != CHECKSUM_PARTIAL));
103 }
104 #endif
105
106 #ifndef HAVE___SKB_GSO_SEGMENT
107 static inline struct sk_buff *__skb_gso_segment(struct sk_buff *skb,
108                                                 netdev_features_t features,
109                                                 bool tx_path)
110 {
111         return skb_gso_segment(skb, features);
112 }
113 #endif
114
115 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0)
116
117 /* XEN dom0 networking assumes dev->master is bond device
118  * and it tries to access bond private structure from dev->master
119  * ptr on receive path. This causes panic. Therefore it is better
120  * not to backport this API.
121  **/
122 static inline int netdev_master_upper_dev_link(struct net_device *dev,
123                                                struct net_device *upper_dev)
124 {
125         return 0;
126 }
127
128 static inline void netdev_upper_dev_unlink(struct net_device *dev,
129                                            struct net_device *upper_dev)
130 {
131 }
132
133 static inline struct net_device *netdev_master_upper_dev_get(struct net_device *dev)
134 {
135         return NULL;
136 }
137 #endif
138
139 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,16,0)
140 #define dev_queue_xmit rpl_dev_queue_xmit
141 int dev_queue_xmit(struct sk_buff *skb);
142 #endif
143
144 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,11,0)
145 static inline struct net_device *netdev_notifier_info_to_dev(void *info)
146 {
147         return info;
148 }
149 #endif
150
151 #ifndef HAVE_PCPU_SW_NETSTATS
152
153 #include <linux/u64_stats_sync.h>
154
155 struct pcpu_sw_netstats {
156         u64     rx_packets;
157         u64     rx_bytes;
158         u64     tx_packets;
159         u64     tx_bytes;
160         struct u64_stats_sync   syncp;
161 };
162 #endif
163
164 #ifndef netdev_alloc_pcpu_stats
165 #define netdev_alloc_pcpu_stats(type)                           \
166 ({                                                              \
167         typeof(type) __percpu *pcpu_stats = alloc_percpu(type); \
168         if (pcpu_stats) {                                       \
169                 int ____i;                                      \
170                 for_each_possible_cpu(____i) {                  \
171                         typeof(type) *stat;                     \
172                         stat = per_cpu_ptr(pcpu_stats, ____i);  \
173                         u64_stats_init(&stat->syncp);           \
174                 }                                               \
175         }                                                       \
176         pcpu_stats;                                             \
177 })
178 #endif
179
180 #endif