1 #ifndef LINUX_26_24_COMPAT_H
2 #define LINUX_26_24_COMPAT_H
4 #include <linux/autoconf.h>
5 #include <linux/version.h>
7 /* Compat work for 2.6.21, 2.6.22 and 2.6.23 */
8 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24))
10 #include <asm/atomic.h>
11 #include <linux/netdevice.h>
12 #include <linux/skbuff.h>
13 #include <linux/usb.h>
14 #include <linux/types.h>
15 #include <linux/list.h>
17 /* Added on 2.6.24 in include/linux/types.h by Al viro on commit 142956af */
18 typedef unsigned long uintptr_t;
20 /* From include/linux/net.h */
21 enum sock_shutdown_cmd {
27 #if (LINUX_VERSION_CODE == KERNEL_VERSION(2,6,23)) /* Local check */
28 /* Added as of 2.6.24 in include/linux/skbuff.h.
30 * Although 2.6.23 does support for CONFIG_NETDEVICES_MULTIQUEUE
31 * this helper was not added until 2.6.24. This implementation
32 * is exactly as it is on newer kernels.
34 * For older kernels we use the an internal mac80211 hack.
35 * For details see changes to include/net/mac80211.h through
36 * compat.diff and compat/mq_compat.h */
37 static inline u16 skb_get_queue_mapping(struct sk_buff *skb)
39 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
40 return skb->queue_mapping;
45 #endif /* Local 2.6.23 check */
47 /* On older kernels we handle this a bit differently, so we yield to that
48 * code for its implementation in mq_compat.h as we want to make
49 * use of the internal mac80211 __ieee80211_queue_stopped() which itself
50 * uses internal mac80211 data structure hacks. */
51 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)) /* Local check */
53 * netif_subqueue_stopped - test status of subqueue
54 * @dev: network device
55 * @queue_index: sub queue index
57 * Check individual transmit queue of a device with multiple transmit queues.
59 static inline int __netif_subqueue_stopped(const struct net_device *dev,
62 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
63 return test_bit(__LINK_STATE_XOFF,
64 &dev->egress_subqueue[queue_index].state);
70 /* Note: although the backport implementation for netif_subqueue_stopped
71 * on older kernels is identical to upstream __netif_subqueue_stopped()
72 * (except for a const qualifier) we implement netif_subqueue_stopped()
73 * as part of mac80211 as it relies on internal mac80211 structures we
74 * use for MQ support. We this implement it in mq_compat.h */
76 #endif /* Local 2.6.23 check */
79 * Force link bug if constructor is used, can't be done compatibly
80 * because constructor arguments were swapped since then!
82 extern void __incompatible_kmem_cache_create(void);
84 /* 2.6.21 and 2.6.22 kmem_cache_create() takes 6 arguments */
85 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23))
86 #define kmem_cache_create(name, objsize, align, flags, ctor) \
88 if (ctor) __incompatible_kmem_cache_create(); \
89 kmem_cache_create((name), (objsize), (align), \
90 (flags), NULL, NULL); \
94 /* 2.6.23 kmem_cache_create() takes 5 arguments */
95 #if (LINUX_VERSION_CODE == KERNEL_VERSION(2,6,23))
96 #define kmem_cache_create(name, objsize, align, flags, ctor) \
98 if (ctor) __incompatible_kmem_cache_create(); \
99 kmem_cache_create((name), (objsize), (align), \
104 /* From include/linux/mod_devicetable.h */
106 /* SSB core, see drivers/ssb/ */
108 struct ssb_device_id {
113 #define SSB_DEVICE(_vendor, _coreid, _revision) \
114 { .vendor = _vendor, .coreid = _coreid, .revision = _revision, }
115 #define SSB_DEVTABLE_END \
118 #define SSB_ANY_VENDOR 0xFFFF
119 #define SSB_ANY_ID 0xFFFF
120 #define SSB_ANY_REV 0xFF
124 /* Namespace stuff, introduced on 2.6.24 */
125 #define dev_get_by_index(a, b) dev_get_by_index(b)
126 #define __dev_get_by_index(a, b) __dev_get_by_index(b)
129 * Display a 6 byte device address (MAC) in a readable format.
131 #define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x"
132 extern char *print_mac(char *buf, const u8 *addr);
133 #define DECLARE_MAC_BUF(var) char var[18] __maybe_unused
135 extern int eth_header(struct sk_buff *skb, struct net_device *dev,
136 unsigned short type, void *daddr,
137 void *saddr, unsigned len);
138 extern int eth_rebuild_header(struct sk_buff *skb);
139 extern void eth_header_cache_update(struct hh_cache *hh, struct net_device *dev,
140 unsigned char * haddr);
141 extern int eth_header_cache(struct neighbour *neigh,
142 struct hh_cache *hh);
144 /* This structure is simply not present on 2.6.22 and 2.6.23 */
146 int (*create) (struct sk_buff *skb, struct net_device *dev,
147 unsigned short type, void *daddr,
148 void *saddr, unsigned len);
149 int (*parse)(const struct sk_buff *skb, unsigned char *haddr);
150 int (*rebuild)(struct sk_buff *skb);
151 #define HAVE_HEADER_CACHE
152 int (*cache)(struct neighbour *neigh, struct hh_cache *hh);
153 void (*cache_update)(struct hh_cache *hh,
154 struct net_device *dev,
155 unsigned char *haddr);
158 /* net/ieee80211/ieee80211_crypt_tkip uses sg_init_table. This was added on
159 * 2.6.24. CONFIG_DEBUG_SG was added in 2.6.24 as well, so lets just ignore
160 * the debug stuff. Note that adding this required changes to the struct
161 * scatterlist on include/asm/scatterlist*, so the right way to port this
162 * is to simply ignore the new structure changes and zero the scatterlist
163 * array. We lave the kdoc intact for reference.
167 * sg_mark_end - Mark the end of the scatterlist
168 * @sg: SG entryScatterlist
171 * Marks the passed in sg entry as the termination point for the sg
172 * table. A call to sg_next() on this entry will return NULL.
175 static inline void sg_mark_end(struct scatterlist *sg)
180 * sg_init_table - Initialize SG table
182 * @nents: Number of entries in table
185 * If this is part of a chained sg table, sg_mark_end() should be
186 * used only on the last table part.
189 static inline void sg_init_table(struct scatterlist *sgl, unsigned int nents)
191 memset(sgl, 0, sizeof(*sgl) * nents);
195 * usb_endpoint_num - get the endpoint's number
196 * @epd: endpoint to be checked
198 * Returns @epd's number: 0 to 15.
200 static inline int usb_endpoint_num(const struct usb_endpoint_descriptor *epd)
202 return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
205 /* Helper to make struct pci_dev is_pcie compatibility code smaller */
206 int compat_is_pcie(struct pci_dev *pdev);
208 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)) */
210 #endif /* LINUX_26_24_COMPAT_H */