1 #ifndef LINUX_26_24_COMPAT_H
2 #define LINUX_26_24_COMPAT_H
4 #include <linux/version.h>
6 /* Compat work for 2.6.21, 2.6.22 and 2.6.23 */
7 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24))
9 #include <asm/atomic.h>
10 #include <linux/netdevice.h>
11 #include <linux/skbuff.h>
12 #include <linux/usb.h>
13 #include <linux/types.h>
14 #include <linux/list.h>
15 #include <linux/scatterlist.h>
17 #define KEY_BLUETOOTH 237
21 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
23 struct proc_dir_entry;
26 atomic_t count; /* To decided when the network
27 * namespace should be freed.
29 atomic_t use_count; /* To track references we
32 struct list_head list; /* list of network namespaces */
33 struct work_struct work; /* work struct for freeing */
35 struct proc_dir_entry *proc_net;
36 struct proc_dir_entry *proc_net_stat;
37 struct proc_dir_entry *proc_net_root;
39 struct net_device *loopback_dev; /* The loopback */
41 struct list_head dev_base_head;
42 struct hlist_head *dev_name_head;
43 struct hlist_head *dev_index_head;
47 /* Init's network namespace */
48 extern struct net init_net;
49 #define INIT_NET_NS(net_ns) .net_ns = &init_net,
51 #define INIT_NET_NS(net_ns)
54 /* Added on 2.6.24 in include/linux/types.h by Al viro on commit 142956af */
55 typedef unsigned long uintptr_t;
57 /* From include/linux/net.h */
58 enum sock_shutdown_cmd {
64 #if (LINUX_VERSION_CODE == KERNEL_VERSION(2,6,23)) /* Local check */
65 /* Added as of 2.6.24 in include/linux/skbuff.h.
67 * Although 2.6.23 does support for CONFIG_NETDEVICES_MULTIQUEUE
68 * this helper was not added until 2.6.24. This implementation
69 * is exactly as it is on newer kernels.
71 * For older kernels we use the an internal mac80211 hack.
72 * For details see changes to include/net/mac80211.h through
73 * compat.diff and compat/mq_compat.h */
74 static inline u16 skb_get_queue_mapping(struct sk_buff *skb)
76 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
77 return skb->queue_mapping;
82 #endif /* Local 2.6.23 check */
84 /* On older kernels we handle this a bit differently, so we yield to that
85 * code for its implementation in mq_compat.h as we want to make
86 * use of the internal mac80211 __ieee80211_queue_stopped() which itself
87 * uses internal mac80211 data structure hacks. */
88 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)) /* Local check */
90 * netif_subqueue_stopped - test status of subqueue
91 * @dev: network device
92 * @queue_index: sub queue index
94 * Check individual transmit queue of a device with multiple transmit queues.
96 static inline int __netif_subqueue_stopped(const struct net_device *dev,
99 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
100 return test_bit(__LINK_STATE_XOFF,
101 &dev->egress_subqueue[queue_index].state);
107 /* Note: although the backport implementation for netif_subqueue_stopped
108 * on older kernels is identical to upstream __netif_subqueue_stopped()
109 * (except for a const qualifier) we implement netif_subqueue_stopped()
110 * as part of mac80211 as it relies on internal mac80211 structures we
111 * use for MQ support. We this implement it in mq_compat.h */
113 #endif /* Local 2.6.23 check */
116 * Force link bug if constructor is used, can't be done compatibly
117 * because constructor arguments were swapped since then!
119 extern void __incompatible_kmem_cache_create(void);
121 /* 2.6.21 and 2.6.22 kmem_cache_create() takes 6 arguments */
122 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23))
123 #define kmem_cache_create(name, objsize, align, flags, ctor) \
125 if (ctor) __incompatible_kmem_cache_create(); \
126 kmem_cache_create((name), (objsize), (align), \
127 (flags), NULL, NULL); \
131 /* 2.6.23 kmem_cache_create() takes 5 arguments */
132 #if (LINUX_VERSION_CODE == KERNEL_VERSION(2,6,23))
133 #define kmem_cache_create(name, objsize, align, flags, ctor) \
135 if (ctor) __incompatible_kmem_cache_create(); \
136 kmem_cache_create((name), (objsize), (align), \
141 /* From include/linux/mod_devicetable.h */
143 /* SSB core, see drivers/ssb/ */
145 struct ssb_device_id {
150 #define SSB_DEVICE(_vendor, _coreid, _revision) \
151 { .vendor = _vendor, .coreid = _coreid, .revision = _revision, }
152 #define SSB_DEVTABLE_END \
155 #define SSB_ANY_VENDOR 0xFFFF
156 #define SSB_ANY_ID 0xFFFF
157 #define SSB_ANY_REV 0xFF
161 /* Namespace stuff, introduced on 2.6.24 */
162 #define dev_get_by_index(a, b) dev_get_by_index(b)
163 #define __dev_get_by_index(a, b) __dev_get_by_index(b)
166 * Display a 6 byte device address (MAC) in a readable format.
168 #define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x"
169 extern char *print_mac(char *buf, const u8 *addr);
170 #define DECLARE_MAC_BUF(var) char var[18] __maybe_unused
172 extern int eth_header(struct sk_buff *skb, struct net_device *dev,
173 unsigned short type, void *daddr,
174 void *saddr, unsigned len);
175 extern int eth_rebuild_header(struct sk_buff *skb);
176 extern void eth_header_cache_update(struct hh_cache *hh, struct net_device *dev,
177 unsigned char * haddr);
178 extern int eth_header_cache(struct neighbour *neigh,
179 struct hh_cache *hh);
181 /* This structure is simply not present on 2.6.22 and 2.6.23 */
183 int (*create) (struct sk_buff *skb, struct net_device *dev,
184 unsigned short type, void *daddr,
185 void *saddr, unsigned len);
186 int (*parse)(const struct sk_buff *skb, unsigned char *haddr);
187 int (*rebuild)(struct sk_buff *skb);
188 #define HAVE_HEADER_CACHE
189 int (*cache)(struct neighbour *neigh, struct hh_cache *hh);
190 void (*cache_update)(struct hh_cache *hh,
191 struct net_device *dev,
192 unsigned char *haddr);
195 /* net/ieee80211/ieee80211_crypt_tkip uses sg_init_table. This was added on
196 * 2.6.24. CONFIG_DEBUG_SG was added in 2.6.24 as well, so lets just ignore
197 * the debug stuff. Note that adding this required changes to the struct
198 * scatterlist on include/asm/scatterlist*, so the right way to port this
199 * is to simply ignore the new structure changes and zero the scatterlist
200 * array. We lave the kdoc intact for reference.
204 * sg_mark_end - Mark the end of the scatterlist
205 * @sg: SG entryScatterlist
208 * Marks the passed in sg entry as the termination point for the sg
209 * table. A call to sg_next() on this entry will return NULL.
212 static inline void sg_mark_end(struct scatterlist *sg)
214 #ifdef CONFIG_DEBUG_SG
215 BUG_ON(sg->sg_magic != SG_MAGIC);
217 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24))
219 * Set termination bit, clear potential chain bit
221 sg->page_link |= 0x02;
222 sg->page_link &= ~0x01;
227 * sg_init_table - Initialize SG table
229 * @nents: Number of entries in table
232 * If this is part of a chained sg table, sg_mark_end() should be
233 * used only on the last table part.
236 static inline void sg_init_table(struct scatterlist *sgl, unsigned int nents)
238 memset(sgl, 0, sizeof(*sgl) * nents);
242 * usb_endpoint_num - get the endpoint's number
243 * @epd: endpoint to be checked
245 * Returns @epd's number: 0 to 15.
247 static inline int usb_endpoint_num(const struct usb_endpoint_descriptor *epd)
249 return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
252 /* Helper to make struct pci_dev is_pcie compatibility code smaller */
253 int compat_is_pcie(struct pci_dev *pdev);
255 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)) */
257 #endif /* LINUX_26_24_COMPAT_H */