add downloading script (with md5sum checking and sourceforge downloading support)
[openwrt.git] / openwrt / package / linux / kernel-source / include / linuxver.h
1 /*
2 * Linux-specific abstractions to gain some independence from linux kernel versions.
3 * Pave over some 2.2 versus 2.4 versus 2.6 kernel differences.
4 *
5 * Copyright 2004, Broadcom Corporation
6 * All Rights Reserved.
7 *
8 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
9 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
10 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
11 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
12 *
13 * $Id$
14 */
15
16 #ifndef _linuxver_h_
17 #define _linuxver_h_
18
19 #include <linux/config.h>
20 #include <linux/version.h>
21
22 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0))
23 /* __NO_VERSION__ must be defined for all linkables except one in 2.2 */
24 #ifdef __UNDEF_NO_VERSION__
25 #undef __NO_VERSION__
26 #else
27 #define __NO_VERSION__
28 #endif
29 #endif
30
31 #if defined(MODULE) && defined(MODVERSIONS)
32 #include <linux/modversions.h>
33 #endif
34
35 /* linux/malloc.h is deprecated, use linux/slab.h instead. */
36 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,9))
37 #include <linux/malloc.h>
38 #else
39 #include <linux/slab.h>
40 #endif
41
42 #include <linux/types.h>
43 #include <linux/init.h>
44 #include <linux/module.h>
45 #include <linux/mm.h>
46 #include <linux/string.h>
47 #include <linux/pci.h>
48 #include <linux/interrupt.h>
49 #include <linux/netdevice.h>
50 #include <asm/io.h>
51
52 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,41))
53 #include <linux/workqueue.h>
54 #else
55 #include <linux/tqueue.h>
56 #define work_struct tq_struct
57 #define INIT_WORK(_work, _func, _data) INIT_TQUEUE((_work), (_func), (_data))
58 #define schedule_work(_work) schedule_task((_work))
59 #define flush_scheduled_work() flush_scheduled_tasks()
60 #endif
61
62 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
63 /* Some distributions have their own 2.6.x compatibility layers */
64 #ifndef IRQ_NONE
65 typedef void irqreturn_t;
66 #define IRQ_NONE
67 #define IRQ_HANDLED
68 #define IRQ_RETVAL(x)
69 #endif
70 #endif
71
72 #if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
73
74 #include <pcmcia/version.h>
75 #include <pcmcia/cs_types.h>
76 #include <pcmcia/cs.h>
77 #include <pcmcia/cistpl.h>
78 #include <pcmcia/cisreg.h>
79 #include <pcmcia/ds.h>
80
81 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,69))
82 /* In 2.5 (as of 2.5.69 at least) there is a cs_error exported which
83 * does this, but it's not in 2.4 so we do our own for now. */
84 static inline void
85 cs_error(client_handle_t handle, int func, int ret)
86 {
87 error_info_t err = { func, ret };
88 CardServices(ReportError, handle, &err);
89 }
90 #endif
91
92 #endif /* CONFIG_PCMCIA */
93
94 #ifndef __exit
95 #define __exit
96 #endif
97 #ifndef __devexit
98 #define __devexit
99 #endif
100 #ifndef __devinit
101 #define __devinit __init
102 #endif
103 #ifndef __devinitdata
104 #define __devinitdata
105 #endif
106 #ifndef __devexit_p
107 #define __devexit_p(x) x
108 #endif
109
110 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0))
111
112 #define pci_get_drvdata(dev) (dev)->sysdata
113 #define pci_set_drvdata(dev, value) (dev)->sysdata=(value)
114
115 /*
116 * New-style (2.4.x) PCI/hot-pluggable PCI/CardBus registration
117 */
118
119 struct pci_device_id {
120 unsigned int vendor, device; /* Vendor and device ID or PCI_ANY_ID */
121 unsigned int subvendor, subdevice; /* Subsystem ID's or PCI_ANY_ID */
122 unsigned int class, class_mask; /* (class,subclass,prog-if) triplet */
123 unsigned long driver_data; /* Data private to the driver */
124 };
125
126 struct pci_driver {
127 struct list_head node;
128 char *name;
129 const struct pci_device_id *id_table; /* NULL if wants all devices */
130 int (*probe)(struct pci_dev *dev, const struct pci_device_id *id); /* New device inserted */
131 void (*remove)(struct pci_dev *dev); /* Device removed (NULL if not a hot-plug capable driver) */
132 void (*suspend)(struct pci_dev *dev); /* Device suspended */
133 void (*resume)(struct pci_dev *dev); /* Device woken up */
134 };
135
136 #define MODULE_DEVICE_TABLE(type, name)
137 #define PCI_ANY_ID (~0)
138
139 /* compatpci.c */
140 #define pci_module_init pci_register_driver
141 extern int pci_register_driver(struct pci_driver *drv);
142 extern void pci_unregister_driver(struct pci_driver *drv);
143
144 #endif /* PCI registration */
145
146 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18))
147 #ifdef MODULE
148 #define module_init(x) int init_module(void) { return x(); }
149 #define module_exit(x) void cleanup_module(void) { x(); }
150 #else
151 #define module_init(x) __initcall(x);
152 #define module_exit(x) __exitcall(x);
153 #endif
154 #endif
155
156 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,48))
157 #define list_for_each(pos, head) \
158 for (pos = (head)->next; pos != (head); pos = pos->next)
159 #endif
160
161 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,13))
162 #define pci_resource_start(dev, bar) ((dev)->base_address[(bar)])
163 #elif (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,44))
164 #define pci_resource_start(dev, bar) ((dev)->resource[(bar)].start)
165 #endif
166
167 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,23))
168 #define pci_enable_device(dev) do { } while (0)
169 #endif
170
171 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,14))
172 #define net_device device
173 #endif
174
175 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,42))
176
177 /*
178 * DMA mapping
179 *
180 * See linux/Documentation/DMA-mapping.txt
181 */
182
183 #ifndef PCI_DMA_TODEVICE
184 #define PCI_DMA_TODEVICE 1
185 #define PCI_DMA_FROMDEVICE 2
186 #endif
187
188 typedef u32 dma_addr_t;
189
190 /* Pure 2^n version of get_order */
191 static inline int get_order(unsigned long size)
192 {
193 int order;
194
195 size = (size-1) >> (PAGE_SHIFT-1);
196 order = -1;
197 do {
198 size >>= 1;
199 order++;
200 } while (size);
201 return order;
202 }
203
204 static inline void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
205 dma_addr_t *dma_handle)
206 {
207 void *ret;
208 int gfp = GFP_ATOMIC | GFP_DMA;
209
210 ret = (void *)__get_free_pages(gfp, get_order(size));
211
212 if (ret != NULL) {
213 memset(ret, 0, size);
214 *dma_handle = virt_to_bus(ret);
215 }
216 return ret;
217 }
218 static inline void pci_free_consistent(struct pci_dev *hwdev, size_t size,
219 void *vaddr, dma_addr_t dma_handle)
220 {
221 free_pages((unsigned long)vaddr, get_order(size));
222 }
223 #ifdef ILSIM
224 extern uint pci_map_single(void *dev, void *va, uint size, int direction);
225 extern void pci_unmap_single(void *dev, uint pa, uint size, int direction);
226 #else
227 #define pci_map_single(cookie, address, size, dir) virt_to_bus(address)
228 #define pci_unmap_single(cookie, address, size, dir)
229 #endif
230
231 #endif /* DMA mapping */
232
233 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,43))
234
235 #define dev_kfree_skb_any(a) dev_kfree_skb(a)
236 #define netif_down(dev) do { (dev)->start = 0; } while(0)
237
238 /* pcmcia-cs provides its own netdevice compatibility layer */
239 #ifndef _COMPAT_NETDEVICE_H
240
241 /*
242 * SoftNet
243 *
244 * For pre-softnet kernels we need to tell the upper layer not to
245 * re-enter start_xmit() while we are in there. However softnet
246 * guarantees not to enter while we are in there so there is no need
247 * to do the netif_stop_queue() dance unless the transmit queue really
248 * gets stuck. This should also improve performance according to tests
249 * done by Aman Singla.
250 */
251
252 #define dev_kfree_skb_irq(a) dev_kfree_skb(a)
253 #define netif_wake_queue(dev) do { clear_bit(0, &(dev)->tbusy); mark_bh(NET_BH); } while(0)
254 #define netif_stop_queue(dev) set_bit(0, &(dev)->tbusy)
255
256 static inline void netif_start_queue(struct net_device *dev)
257 {
258 dev->tbusy = 0;
259 dev->interrupt = 0;
260 dev->start = 1;
261 }
262
263 #define netif_queue_stopped(dev) (dev)->tbusy
264 #define netif_running(dev) (dev)->start
265
266 #endif /* _COMPAT_NETDEVICE_H */
267
268 #define netif_device_attach(dev) netif_start_queue(dev)
269 #define netif_device_detach(dev) netif_stop_queue(dev)
270
271 /* 2.4.x renamed bottom halves to tasklets */
272 #define tasklet_struct tq_struct
273 static inline void tasklet_schedule(struct tasklet_struct *tasklet)
274 {
275 queue_task(tasklet, &tq_immediate);
276 mark_bh(IMMEDIATE_BH);
277 }
278
279 static inline void tasklet_init(struct tasklet_struct *tasklet,
280 void (*func)(unsigned long),
281 unsigned long data)
282 {
283 tasklet->next = NULL;
284 tasklet->sync = 0;
285 tasklet->routine = (void (*)(void *))func;
286 tasklet->data = (void *)data;
287 }
288 #define tasklet_kill(tasklet) {do{} while(0);}
289
290 /* 2.4.x introduced del_timer_sync() */
291 #define del_timer_sync(timer) del_timer(timer)
292
293 #else
294
295 #define netif_down(dev)
296
297 #endif /* SoftNet */
298
299 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,3))
300
301 /*
302 * Emit code to initialise a tq_struct's routine and data pointers
303 */
304 #define PREPARE_TQUEUE(_tq, _routine, _data) \
305 do { \
306 (_tq)->routine = _routine; \
307 (_tq)->data = _data; \
308 } while (0)
309
310 /*
311 * Emit code to initialise all of a tq_struct
312 */
313 #define INIT_TQUEUE(_tq, _routine, _data) \
314 do { \
315 INIT_LIST_HEAD(&(_tq)->list); \
316 (_tq)->sync = 0; \
317 PREPARE_TQUEUE((_tq), (_routine), (_data)); \
318 } while (0)
319
320 #endif
321
322 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,6))
323
324 /* Power management related routines */
325
326 static inline int
327 pci_save_state(struct pci_dev *dev, u32 *buffer)
328 {
329 int i;
330 if (buffer) {
331 for (i = 0; i < 16; i++)
332 pci_read_config_dword(dev, i * 4,&buffer[i]);
333 }
334 return 0;
335 }
336
337 static inline int
338 pci_restore_state(struct pci_dev *dev, u32 *buffer)
339 {
340 int i;
341
342 if (buffer) {
343 for (i = 0; i < 16; i++)
344 pci_write_config_dword(dev,i * 4, buffer[i]);
345 }
346 /*
347 * otherwise, write the context information we know from bootup.
348 * This works around a problem where warm-booting from Windows
349 * combined with a D3(hot)->D0 transition causes PCI config
350 * header data to be forgotten.
351 */
352 else {
353 for (i = 0; i < 6; i ++)
354 pci_write_config_dword(dev,
355 PCI_BASE_ADDRESS_0 + (i * 4),
356 pci_resource_start(dev, i));
357 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
358 }
359 return 0;
360 }
361
362 #endif /* PCI power management */
363
364 /* Old cp0 access macros deprecated in 2.4.19 */
365 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,19))
366 #define read_c0_count() read_32bit_cp0_register(CP0_COUNT)
367 #endif
368
369 /* Module refcount handled internally in 2.6.x */
370 #ifndef SET_MODULE_OWNER
371 #define SET_MODULE_OWNER(dev) do {} while (0)
372 #define OLD_MOD_INC_USE_COUNT MOD_INC_USE_COUNT
373 #define OLD_MOD_DEC_USE_COUNT MOD_DEC_USE_COUNT
374 #else
375 #define OLD_MOD_INC_USE_COUNT do {} while (0)
376 #define OLD_MOD_DEC_USE_COUNT do {} while (0)
377 #endif
378
379 #ifndef SET_NETDEV_DEV
380 #define SET_NETDEV_DEV(net, pdev) do {} while (0)
381 #endif
382
383 #ifndef HAVE_FREE_NETDEV
384 #define free_netdev(dev) kfree(dev)
385 #endif
386
387 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
388 /* struct packet_type redefined in 2.6.x */
389 #define af_packet_priv data
390 #endif
391
392 #endif /* _linuxver_h_ */
This page took 0.058548 seconds and 5 git commands to generate.