Broadcom SDK and wireless driver: another attempt to update to ver. 5.10.147.0
[tomato.git] / release / src-rt / include / linuxver.h
blobe39bbe235225978a9f42fac0e2e101f97f17d47b
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.
5 * Copyright (C) 2009, 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.
13 * $Id: linuxver.h,v 13.40.2.5 2008/12/15 18:36:58 Exp $
16 #ifndef _linuxver_h_
17 #define _linuxver_h_
19 #include <linux/version.h>
20 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
21 #include <linux/config.h>
22 #else
23 #include <linux/autoconf.h>
24 #endif
25 #include <linux/module.h>
27 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0))
28 /* __NO_VERSION__ must be defined for all linkables except one in 2.2 */
29 #ifdef __UNDEF_NO_VERSION__
30 #undef __NO_VERSION__
31 #else
32 #define __NO_VERSION__
33 #endif
34 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0) */
36 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0)
37 #define module_param(_name_, _type_, _perm_) MODULE_PARM(_name_, "i")
38 #define module_param_string(_name_, _string_, _size_, _perm_) \
39 MODULE_PARM(_string_, "c" __MODULE_STRING(_size_))
40 #endif
42 /* linux/malloc.h is deprecated, use linux/slab.h instead. */
43 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 9))
44 #include <linux/malloc.h>
45 #else
46 #include <linux/slab.h>
47 #endif
49 #include <linux/types.h>
50 #include <linux/init.h>
51 #include <linux/mm.h>
52 #include <linux/string.h>
53 #include <linux/pci.h>
54 #include <linux/interrupt.h>
55 #include <linux/netdevice.h>
56 #include <asm/io.h>
58 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 41))
59 #include <linux/workqueue.h>
60 #else
61 #include <linux/tqueue.h>
62 #ifndef work_struct
63 #define work_struct tq_struct
64 #endif
65 #ifndef INIT_WORK
66 #define INIT_WORK(_work, _func, _data) INIT_TQUEUE((_work), (_func), (_data))
67 #endif
68 #ifndef schedule_work
69 #define schedule_work(_work) schedule_task((_work))
70 #endif
71 #ifndef flush_scheduled_work
72 #define flush_scheduled_work() flush_scheduled_tasks()
73 #endif
74 #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 41) */
76 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
77 #define MY_INIT_WORK(_work, _func) INIT_WORK(_work, _func)
78 #else
79 #define MY_INIT_WORK(_work, _func) INIT_WORK(_work, _func, _work)
80 typedef void (*work_func_t)(void *work);
81 #endif /* >= 2.6.20 */
83 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
84 /* Some distributions have their own 2.6.x compatibility layers */
85 #ifndef IRQ_NONE
86 typedef void irqreturn_t;
87 #define IRQ_NONE
88 #define IRQ_HANDLED
89 #define IRQ_RETVAL(x)
90 #endif
91 #else
92 typedef irqreturn_t(*FN_ISR) (int irq, void *dev_id, struct pt_regs *ptregs);
93 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) */
95 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
96 #define IRQF_SHARED SA_SHIRQ
97 #endif /* < 2.6.18 */
99 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 17)
100 #ifdef CONFIG_NET_RADIO
101 #define CONFIG_WIRELESS_EXT
102 #endif
103 #endif /* < 2.6.17 */
105 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 67)
106 #ifndef SANDGATE2G
107 #define MOD_INC_USE_COUNT
108 #define MOD_DEC_USE_COUNT
109 #endif /* not SANDGATE2G */
110 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 67) */
112 #if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
114 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 27)
115 #include <pcmcia/version.h>
116 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 27) */
118 #include <pcmcia/cs_types.h>
119 #include <pcmcia/cs.h>
120 #include <pcmcia/cistpl.h>
121 #include <pcmcia/cisreg.h>
122 #include <pcmcia/ds.h>
124 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 69))
125 /* In 2.5 (as of 2.5.69 at least) there is a cs_error exported which
126 * does this, but it's not in 2.4 so we do our own for now.
128 static inline void
129 cs_error(client_handle_t handle, int func, int ret)
131 error_info_t err = { func, ret };
132 CardServices(ReportError, handle, &err);
134 #endif
136 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 16))
138 typedef struct pcmcia_device dev_link_t;
140 #endif
142 #endif /* CONFIG_PCMCIA */
144 #ifndef __exit
145 #define __exit
146 #endif
147 #ifndef __devexit
148 #define __devexit
149 #endif
150 #ifndef __devinit
151 #define __devinit __init
152 #endif
153 #ifndef __devinitdata
154 #define __devinitdata
155 #endif
156 #ifndef __devexit_p
157 #define __devexit_p(x) x
158 #endif
160 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0))
162 #define pci_get_drvdata(dev) (dev)->sysdata
163 #define pci_set_drvdata(dev, value) (dev)->sysdata = (value)
166 * New-style (2.4.x) PCI/hot-pluggable PCI/CardBus registration
169 struct pci_device_id {
170 unsigned int vendor, device; /* Vendor and device ID or PCI_ANY_ID */
171 unsigned int subvendor, subdevice; /* Subsystem ID's or PCI_ANY_ID */
172 unsigned int class, class_mask; /* (class,subclass,prog-if) triplet */
173 unsigned long driver_data; /* Data private to the driver */
176 struct pci_driver {
177 struct list_head node;
178 char *name;
179 const struct pci_device_id *id_table; /* NULL if wants all devices */
180 int (*probe)(struct pci_dev *dev,
181 const struct pci_device_id *id); /* New device inserted */
182 void (*remove)(struct pci_dev *dev); /* Device removed (NULL if not a hot-plug
183 * capable driver)
185 void (*suspend)(struct pci_dev *dev); /* Device suspended */
186 void (*resume)(struct pci_dev *dev); /* Device woken up */
189 #define MODULE_DEVICE_TABLE(type, name)
190 #define PCI_ANY_ID (~0)
192 /* compatpci.c */
193 #define pci_module_init pci_register_driver
194 extern int pci_register_driver(struct pci_driver *drv);
195 extern void pci_unregister_driver(struct pci_driver *drv);
197 #endif /* PCI registration */
199 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18))
200 #define pci_module_init pci_register_driver
201 #endif
203 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 18))
204 #ifdef MODULE
205 #define module_init(x) int init_module(void) { return x(); }
206 #define module_exit(x) void cleanup_module(void) { x(); }
207 #else
208 #define module_init(x) __initcall(x);
209 #define module_exit(x) __exitcall(x);
210 #endif
211 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 18) */
213 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 48))
214 #define list_for_each(pos, head) \
215 for (pos = (head)->next; pos != (head); pos = pos->next)
216 #endif
218 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 13))
219 #define pci_resource_start(dev, bar) ((dev)->base_address[(bar)])
220 #elif (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 44))
221 #define pci_resource_start(dev, bar) ((dev)->resource[(bar)].start)
222 #endif
224 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 23))
225 #define pci_enable_device(dev) do { } while (0)
226 #endif
228 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 14))
229 #define net_device device
230 #endif
232 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 42))
235 * DMA mapping
237 * See linux/Documentation/DMA-mapping.txt
240 #ifndef PCI_DMA_TODEVICE
241 #define PCI_DMA_TODEVICE 1
242 #define PCI_DMA_FROMDEVICE 2
243 #endif
245 typedef u32 dma_addr_t;
247 /* Pure 2^n version of get_order */
248 static inline int get_order(unsigned long size)
250 int order;
252 size = (size-1) >> (PAGE_SHIFT-1);
253 order = -1;
254 do {
255 size >>= 1;
256 order++;
257 } while (size);
258 return order;
261 static inline void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
262 dma_addr_t *dma_handle)
264 void *ret;
265 int gfp = GFP_ATOMIC | GFP_DMA;
267 ret = (void *)__get_free_pages(gfp, get_order(size));
269 if (ret != NULL) {
270 memset(ret, 0, size);
271 *dma_handle = virt_to_bus(ret);
273 return ret;
275 static inline void pci_free_consistent(struct pci_dev *hwdev, size_t size,
276 void *vaddr, dma_addr_t dma_handle)
278 free_pages((unsigned long)vaddr, get_order(size));
280 #ifdef ILSIM
281 extern uint pci_map_single(void *dev, void *va, uint size, int direction);
282 extern void pci_unmap_single(void *dev, uint pa, uint size, int direction);
283 #else
284 #define pci_map_single(cookie, address, size, dir) virt_to_bus(address)
285 #define pci_unmap_single(cookie, address, size, dir)
286 #endif
288 #endif /* DMA mapping */
290 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 43))
292 #define dev_kfree_skb_any(a) dev_kfree_skb(a)
293 #define netif_down(dev) do { (dev)->start = 0; } while (0)
295 /* pcmcia-cs provides its own netdevice compatibility layer */
296 #ifndef _COMPAT_NETDEVICE_H
299 * SoftNet
301 * For pre-softnet kernels we need to tell the upper layer not to
302 * re-enter start_xmit() while we are in there. However softnet
303 * guarantees not to enter while we are in there so there is no need
304 * to do the netif_stop_queue() dance unless the transmit queue really
305 * gets stuck. This should also improve performance according to tests
306 * done by Aman Singla.
309 #define dev_kfree_skb_irq(a) dev_kfree_skb(a)
310 #define netif_wake_queue(dev) \
311 do { clear_bit(0, &(dev)->tbusy); mark_bh(NET_BH); } while (0)
312 #define netif_stop_queue(dev) set_bit(0, &(dev)->tbusy)
314 static inline void netif_start_queue(struct net_device *dev)
316 dev->tbusy = 0;
317 dev->interrupt = 0;
318 dev->start = 1;
321 #define netif_queue_stopped(dev) (dev)->tbusy
322 #define netif_running(dev) (dev)->start
324 #endif /* _COMPAT_NETDEVICE_H */
326 #define netif_device_attach(dev) netif_start_queue(dev)
327 #define netif_device_detach(dev) netif_stop_queue(dev)
329 /* 2.4.x renamed bottom halves to tasklets */
330 #define tasklet_struct tq_struct
331 static inline void tasklet_schedule(struct tasklet_struct *tasklet)
333 queue_task(tasklet, &tq_immediate);
334 mark_bh(IMMEDIATE_BH);
337 static inline void tasklet_init(struct tasklet_struct *tasklet,
338 void (*func)(unsigned long),
339 unsigned long data)
341 tasklet->next = NULL;
342 tasklet->sync = 0;
343 tasklet->routine = (void (*)(void *))func;
344 tasklet->data = (void *)data;
346 #define tasklet_kill(tasklet) { do{} while (0); }
348 /* 2.4.x introduced del_timer_sync() */
349 #define del_timer_sync(timer) del_timer(timer)
351 #else
353 #define netif_down(dev)
355 #endif /* SoftNet */
357 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 3))
360 * Emit code to initialise a tq_struct's routine and data pointers
362 #define PREPARE_TQUEUE(_tq, _routine, _data) \
363 do { \
364 (_tq)->routine = _routine; \
365 (_tq)->data = _data; \
366 } while (0)
369 * Emit code to initialise all of a tq_struct
371 #define INIT_TQUEUE(_tq, _routine, _data) \
372 do { \
373 INIT_LIST_HEAD(&(_tq)->list); \
374 (_tq)->sync = 0; \
375 PREPARE_TQUEUE((_tq), (_routine), (_data)); \
376 } while (0)
378 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 3) */
380 /* Power management related macro & routines */
381 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 9)
382 #define PCI_SAVE_STATE(a, b) pci_save_state(a)
383 #define PCI_RESTORE_STATE(a, b) pci_restore_state(a)
384 #else
385 #define PCI_SAVE_STATE(a, b) pci_save_state(a, b)
386 #define PCI_RESTORE_STATE(a, b) pci_restore_state(a, b)
387 #endif
389 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 6))
390 static inline int
391 pci_save_state(struct pci_dev *dev, u32 *buffer)
393 int i;
394 if (buffer) {
395 for (i = 0; i < 16; i++)
396 pci_read_config_dword(dev, i * 4, &buffer[i]);
398 return 0;
401 static inline int
402 pci_restore_state(struct pci_dev *dev, u32 *buffer)
404 int i;
406 if (buffer) {
407 for (i = 0; i < 16; i++)
408 pci_write_config_dword(dev, i * 4, buffer[i]);
411 * otherwise, write the context information we know from bootup.
412 * This works around a problem where warm-booting from Windows
413 * combined with a D3(hot)->D0 transition causes PCI config
414 * header data to be forgotten.
416 else {
417 for (i = 0; i < 6; i ++)
418 pci_write_config_dword(dev,
419 PCI_BASE_ADDRESS_0 + (i * 4),
420 pci_resource_start(dev, i));
421 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
423 return 0;
425 #endif /* PCI power management */
427 /* Old cp0 access macros deprecated in 2.4.19 */
428 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 19))
429 #define read_c0_count() read_32bit_cp0_register(CP0_COUNT)
430 #endif
432 /* Module refcount handled internally in 2.6.x */
433 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24))
434 #ifndef SET_MODULE_OWNER
435 #define SET_MODULE_OWNER(dev) do {} while (0)
436 #define OLD_MOD_INC_USE_COUNT MOD_INC_USE_COUNT
437 #define OLD_MOD_DEC_USE_COUNT MOD_DEC_USE_COUNT
438 #else
439 #define OLD_MOD_INC_USE_COUNT do {} while (0)
440 #define OLD_MOD_DEC_USE_COUNT do {} while (0)
441 #endif
442 #else /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24) */
443 #ifndef SET_MODULE_OWNER
444 #define SET_MODULE_OWNER(dev) do {} while (0)
445 #endif
446 #ifndef MOD_INC_USE_COUNT
447 #define MOD_INC_USE_COUNT do {} while (0)
448 #endif
449 #ifndef MOD_DEC_USE_COUNT
450 #define MOD_DEC_USE_COUNT do {} while (0)
451 #endif
452 #define OLD_MOD_INC_USE_COUNT MOD_INC_USE_COUNT
453 #define OLD_MOD_DEC_USE_COUNT MOD_DEC_USE_COUNT
454 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24) */
456 #ifndef SET_NETDEV_DEV
457 #define SET_NETDEV_DEV(net, pdev) do {} while (0)
458 #endif
460 #ifndef HAVE_FREE_NETDEV
461 #define free_netdev(dev) kfree(dev)
462 #endif
464 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
465 /* struct packet_type redefined in 2.6.x */
466 #define af_packet_priv data
467 #endif
469 /* suspend args */
470 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
471 #define DRV_SUSPEND_STATE_TYPE pm_message_t
472 #else
473 #define DRV_SUSPEND_STATE_TYPE uint32
474 #endif
476 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
477 #define CHECKSUM_HW CHECKSUM_PARTIAL
478 #endif
480 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
481 #include <linux/time.h>
482 #include <linux/wait.h>
483 #else
484 #include <linux/sched.h>
486 #define __wait_event_interruptible_timeout(wq, condition, ret) \
487 do { \
488 wait_queue_t __wait; \
489 init_waitqueue_entry(&__wait, current); \
491 add_wait_queue(&wq, &__wait); \
492 for (;;) { \
493 set_current_state(TASK_INTERRUPTIBLE); \
494 if (condition) \
495 break; \
496 if (!signal_pending(current)) { \
497 ret = schedule_timeout(ret); \
498 if (!ret) \
499 break; \
500 continue; \
502 ret = -ERESTARTSYS; \
503 break; \
505 current->state = TASK_RUNNING; \
506 remove_wait_queue(&wq, &__wait); \
507 } while (0)
509 #define wait_event_interruptible_timeout(wq, condition, timeout) \
510 ({ \
511 long __ret = timeout; \
512 if (!(condition)) \
513 __wait_event_interruptible_timeout(wq, condition, __ret); \
514 __ret; \
517 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)) */
519 #endif /* _linuxver_h_ */