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