compat-wireless-2010-03-10
[pandora-wifi.git] / include / linux / compat-2.6.24.h
1 #ifndef LINUX_26_24_COMPAT_H
2 #define LINUX_26_24_COMPAT_H
3
4 #include <linux/version.h>
5
6 /* Compat work for 2.6.21, 2.6.22 and 2.6.23 */
7 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24))
8
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>
16
17 #define KEY_BLUETOOTH   237
18 #define KEY_WLAN        238
19 #define KEY_UWB         239
20
21 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
22
23 struct proc_dir_entry;
24 struct net_device;
25 struct net {
26         atomic_t                count;          /* To decided when the network
27                                                  *  namespace should be freed.
28                                                  */
29         atomic_t                use_count;      /* To track references we
30                                                  * destroy on demand
31                                                  */
32         struct list_head        list;           /* list of network namespaces */
33         struct work_struct      work;           /* work struct for freeing */
34
35         struct proc_dir_entry   *proc_net;
36         struct proc_dir_entry   *proc_net_stat;
37         struct proc_dir_entry   *proc_net_root;
38
39         struct net_device       *loopback_dev;          /* The loopback */
40
41         struct list_head        dev_base_head;
42         struct hlist_head       *dev_name_head;
43         struct hlist_head       *dev_index_head;
44 };
45
46 #ifdef CONFIG_NET
47 /* Init's network namespace */
48 extern struct net init_net;
49 #define INIT_NET_NS(net_ns) .net_ns = &init_net,
50 #else
51 #define INIT_NET_NS(net_ns)
52 #endif
53
54 /* Added on 2.6.24 in include/linux/types.h by Al viro on commit 142956af */
55 typedef unsigned long               uintptr_t;
56
57 /* From include/linux/net.h */
58 enum sock_shutdown_cmd {
59         SHUT_RD         = 0,
60         SHUT_WR         = 1,
61         SHUT_RDWR       = 2,
62 };
63
64 #if (LINUX_VERSION_CODE == KERNEL_VERSION(2,6,23)) /* Local check */
65 /* Added as of 2.6.24 in include/linux/skbuff.h.
66  *
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.
70  *
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)
75 {
76 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
77         return skb->queue_mapping;
78 #else
79         return 0;
80 #endif
81 }
82 #endif /* Local 2.6.23 check */
83
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 */
89 /**
90  * netif_subqueue_stopped - test status of subqueue
91  * @dev: network device
92  * @queue_index: sub queue index
93  *
94  * Check individual transmit queue of a device with multiple transmit queues.
95  */
96 static inline int __netif_subqueue_stopped(const struct net_device *dev,
97                                         u16 queue_index)
98 {
99 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
100         return test_bit(__LINK_STATE_XOFF,
101         &dev->egress_subqueue[queue_index].state);
102 #else
103         return 0;
104 #endif
105 }
106
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 */
112
113 #endif /* Local 2.6.23 check */
114
115 /*
116  * Force link bug if constructor is used, can't be done compatibly
117  * because constructor arguments were swapped since then!
118  */
119 extern void __incompatible_kmem_cache_create(void);
120
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)    \
124         ({                                                      \
125                 if (ctor) __incompatible_kmem_cache_create();   \
126                 kmem_cache_create((name), (objsize), (align),   \
127                                   (flags), NULL, NULL);         \
128         })
129 #endif
130
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)    \
134         ({                                                      \
135                 if (ctor) __incompatible_kmem_cache_create();   \
136                 kmem_cache_create((name), (objsize), (align),   \
137                                   (flags), NULL);               \
138         })
139 #endif
140
141 /* From include/linux/mod_devicetable.h */
142
143 /* SSB core, see drivers/ssb/ */
144 #ifndef SSB_DEVICE
145 struct ssb_device_id {
146         __u16   vendor;
147         __u16   coreid;
148         __u8    revision;
149 };
150 #define SSB_DEVICE(_vendor, _coreid, _revision)  \
151         { .vendor = _vendor, .coreid = _coreid, .revision = _revision, }
152 #define SSB_DEVTABLE_END  \
153         { 0, },
154
155 #define SSB_ANY_VENDOR          0xFFFF
156 #define SSB_ANY_ID              0xFFFF
157 #define SSB_ANY_REV             0xFF
158 #endif
159
160
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)
164
165 /*
166  * Display a 6 byte device address (MAC) in a readable format.
167  */
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
171
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);
180
181 /* This structure is simply not present on 2.6.22 and 2.6.23 */
182 struct header_ops {
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);
193 };
194
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.
201  */
202
203 /**
204  * sg_mark_end - Mark the end of the scatterlist
205  * @sg:          SG entryScatterlist
206  *
207  * Description:
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.
210  *
211  **/
212 static inline void sg_mark_end(struct scatterlist *sg)
213 {
214 #ifdef CONFIG_DEBUG_SG
215         BUG_ON(sg->sg_magic != SG_MAGIC);
216 #endif
217 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24))
218         /*
219          * Set termination bit, clear potential chain bit
220         */
221         sg->page_link |= 0x02;
222         sg->page_link &= ~0x01;
223 #endif
224 }
225
226 /**
227  * sg_init_table - Initialize SG table
228  * @sgl:           The SG table
229  * @nents:         Number of entries in table
230  *
231  * Notes:
232  *   If this is part of a chained sg table, sg_mark_end() should be
233  *   used only on the last table part.
234  *
235  **/
236 static inline void sg_init_table(struct scatterlist *sgl, unsigned int nents)
237 {
238         memset(sgl, 0, sizeof(*sgl) * nents);
239 }
240
241 /**
242  * usb_endpoint_num - get the endpoint's number
243  * @epd: endpoint to be checked
244  *
245  * Returns @epd's number: 0 to 15.
246  */
247 static inline int usb_endpoint_num(const struct usb_endpoint_descriptor *epd)
248 {
249         return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
250 }
251
252 /* Helper to make struct pci_dev is_pcie compatibility code smaller */
253 int compat_is_pcie(struct pci_dev *pdev);
254
255 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)) */
256
257 #endif /* LINUX_26_24_COMPAT_H */