datapath: Revert "datapath: rhel: Account for RHEL specific backports"
[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 /* Before 2.6.21, struct net_device has a "struct class_device" member named
10  * class_dev.  Beginning with 2.6.21, struct net_device instead has a "struct
11  * device" member named dev.  Otherwise the usage of these members is pretty
12  * much the same. */
13 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21)
14 #define NETDEV_DEV_MEMBER class_dev
15 #else
16 #define NETDEV_DEV_MEMBER dev
17 #endif
18
19 #ifndef to_net_dev
20 #define to_net_dev(class) container_of(class, struct net_device, NETDEV_DEV_MEMBER)
21 #endif
22
23 #ifdef HAVE_RHEL_OVS_HOOK
24 extern struct sk_buff *(*openvswitch_handle_frame_hook)(struct sk_buff *skb);
25 extern int nr_bridges;
26 #endif
27
28 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
29 static inline
30 struct net *dev_net(const struct net_device *dev)
31 {
32 #ifdef CONFIG_NET_NS
33         return dev->nd_net;
34 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25)
35         return &init_net;
36 #else
37         return NULL;
38 #endif
39 }
40
41 static inline
42 void dev_net_set(struct net_device *dev, const struct net *net)
43 {
44 #ifdef CONFIG_NET_NS
45         dev->nd_dev = net;
46 #endif
47 }
48 #endif /* linux kernel < 2.6.26 */
49
50 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
51 #define NETIF_F_NETNS_LOCAL 0
52 #endif
53
54 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
55 #define proc_net init_net.proc_net
56 #endif
57
58 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
59 typedef int netdev_tx_t;
60 #endif
61
62 #ifndef for_each_netdev
63 /* Linux before 2.6.22 didn't have for_each_netdev at all. */
64 #define for_each_netdev(net, d) for (d = dev_base; d; d = d->next)
65 #elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
66 /* Linux 2.6.24 added a network namespace pointer to the macro. */
67 #undef for_each_netdev
68 #define for_each_netdev(net, d) list_for_each_entry(d, &dev_base_head, dev_list)
69 #endif
70
71 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
72 #define net_xmit_eval(e)       ((e) == NET_XMIT_CN ? 0 : (e))
73 #endif
74
75 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)
76 extern void unregister_netdevice_queue(struct net_device *dev,
77                                         struct list_head *head);
78 extern void unregister_netdevice_many(struct list_head *head);
79 #endif
80
81 #ifndef HAVE_DEV_DISABLE_LRO
82 extern void dev_disable_lro(struct net_device *dev);
83 #endif
84
85 #define skb_checksum_help rpl_skb_checksum_help
86 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
87 extern int skb_checksum_help(struct sk_buff *skb, int);
88 #else
89 extern int skb_checksum_help(struct sk_buff *skb);
90 #endif
91
92 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) || \
93     defined HAVE_RHEL_OVS_HOOK
94 static inline int netdev_rx_handler_register(struct net_device *dev,
95                                              void *rx_handler,
96                                              void *rx_handler_data)
97 {
98 #ifdef HAVE_RHEL_OVS_HOOK
99         rcu_assign_pointer(dev->ax25_ptr, rx_handler_data);
100         nr_bridges++;
101         rcu_assign_pointer(openvswitch_handle_frame_hook, rx_handler_data);
102 #else
103         if (dev->br_port)
104                 return -EBUSY;
105         rcu_assign_pointer(dev->br_port, rx_handler_data);
106 #endif
107         return 0;
108 }
109 static inline void netdev_rx_handler_unregister(struct net_device *dev)
110 {
111 #ifdef HAVE_RHEL_OVS_HOOK
112         rcu_assign_pointer(dev->ax25_ptr, NULL);
113
114         if (--nr_bridges <= 0)
115                 rcu_assign_pointer(openvswitch_handle_frame_hook, NULL);
116 #else
117         rcu_assign_pointer(dev->br_port, NULL);
118 #endif
119 }
120 #endif
121
122 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
123 #undef SET_ETHTOOL_OPS
124 #define SET_ETHTOOL_OPS(netdev, ops) \
125         ((netdev)->ethtool_ops = (struct ethtool_ops *)(ops))
126 #endif
127
128 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
129 #define dev_get_by_name(net, name) dev_get_by_name(name)
130 #define dev_get_by_index(net, ifindex) dev_get_by_index(ifindex)
131 #define __dev_get_by_name(net, name) __dev_get_by_name(name)
132 #define __dev_get_by_index(net, ifindex) __dev_get_by_index(ifindex)
133 #define dev_get_by_index_rcu(net, ifindex) dev_get_by_index_rcu(ifindex)
134 #endif
135
136 #ifndef HAVE_DEV_GET_BY_INDEX_RCU
137 static inline struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
138 {
139         struct net_device *dev;
140
141         read_lock(&dev_base_lock);
142         dev = __dev_get_by_index(net, ifindex);
143         read_unlock(&dev_base_lock);
144
145         return dev;
146 }
147 #endif
148
149 #ifndef NETIF_F_FSO
150 #define NETIF_F_FSO 0
151 #endif
152
153 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
154 #define NETIF_F_FCOE_CRC        (1 << 24) /* FCoE CRC32 */
155 #endif
156
157 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
158 #define NETIF_F_IPV6_CSUM       16      /* Can checksum TCP/UDP over IPV6 */
159
160 #define NETIF_F_V4_CSUM         (NETIF_F_GEN_CSUM | NETIF_F_IP_CSUM)
161 #define NETIF_F_V6_CSUM         (NETIF_F_GEN_CSUM | NETIF_F_IPV6_CSUM)
162 #endif
163
164 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38)
165 #define skb_gso_segment rpl_skb_gso_segment
166 struct sk_buff *rpl_skb_gso_segment(struct sk_buff *skb, u32 features);
167
168 #define netif_skb_features rpl_netif_skb_features
169 u32 rpl_netif_skb_features(struct sk_buff *skb);
170
171 #define netif_needs_gso rpl_netif_needs_gso
172 static inline int rpl_netif_needs_gso(struct sk_buff *skb, int features)
173 {
174         return skb_is_gso(skb) && (!skb_gso_ok(skb, features) ||
175                 unlikely(skb->ip_summed != CHECKSUM_PARTIAL));
176 }
177 #endif
178
179 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0)
180 typedef u32 netdev_features_t;
181 #endif
182
183 #ifndef HAVE___SKB_GSO_SEGMENT
184 static inline struct sk_buff *__skb_gso_segment(struct sk_buff *skb,
185                                                 netdev_features_t features,
186                                                 bool tx_path)
187 {
188         return skb_gso_segment(skb, features);
189 }
190 #endif
191 #endif