Resync with broadcom drivers 5.100.138.20 and utilities.
[tomato.git] / release / src-rt / include / linuxver.h
blob8aa2184f50003898939a7eb18b2b8f1ef8c91204
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) 2010, Broadcom Corporation. All Rights Reserved.
6 *
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
14 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
16 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
17 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 * $Id: linuxver.h,v 13.53.12.4 2010-10-12 23:10:02 Exp $
22 #ifndef _linuxver_h_
23 #define _linuxver_h_
25 #include <linux/version.h>
26 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
27 #include <linux/config.h>
28 #else
30 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33))
31 #include <linux/autoconf.h>
32 #else
33 #include <generated/autoconf.h>
34 #endif
36 #endif /* >= 2.6.0 */
37 #include <linux/module.h>
39 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0))
40 /* __NO_VERSION__ must be defined for all linkables except one in 2.2 */
41 #ifdef __UNDEF_NO_VERSION__
42 #undef __NO_VERSION__
43 #else
44 #define __NO_VERSION__
45 #endif
46 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0) */
48 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0)
49 #define module_param(_name_, _type_, _perm_) MODULE_PARM(_name_, "i")
50 #define module_param_string(_name_, _string_, _size_, _perm_) \
51 MODULE_PARM(_string_, "c" __MODULE_STRING(_size_))
52 #endif
54 /* linux/malloc.h is deprecated, use linux/slab.h instead. */
55 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 9))
56 #include <linux/malloc.h>
57 #else
58 #include <linux/slab.h>
59 #endif
61 #include <linux/types.h>
62 #include <linux/init.h>
63 #include <linux/mm.h>
64 #include <linux/string.h>
65 #include <linux/pci.h>
66 #include <linux/interrupt.h>
67 #include <linux/netdevice.h>
68 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
69 #undef IP_TOS
70 #endif
71 #include <asm/io.h>
73 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 41))
74 #include <linux/workqueue.h>
75 #else
76 #include <linux/tqueue.h>
77 #ifndef work_struct
78 #define work_struct tq_struct
79 #endif
80 #ifndef INIT_WORK
81 #define INIT_WORK(_work, _func, _data) INIT_TQUEUE((_work), (_func), (_data))
82 #endif
83 #ifndef schedule_work
84 #define schedule_work(_work) schedule_task((_work))
85 #endif
86 #ifndef flush_scheduled_work
87 #define flush_scheduled_work() flush_scheduled_tasks()
88 #endif
89 #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 41) */
91 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20)
92 #define MY_INIT_WORK(_work, _func) INIT_WORK(_work, _func)
93 #else
94 #define MY_INIT_WORK(_work, _func) INIT_WORK(_work, _func, _work)
95 typedef void (*work_func_t)(void *work);
96 #endif /* >= 2.6.20 */
98 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
99 /* Some distributions have their own 2.6.x compatibility layers */
100 #ifndef IRQ_NONE
101 typedef void irqreturn_t;
102 #define IRQ_NONE
103 #define IRQ_HANDLED
104 #define IRQ_RETVAL(x)
105 #endif
106 #else
107 typedef irqreturn_t(*FN_ISR) (int irq, void *dev_id, struct pt_regs *ptregs);
108 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) */
110 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
111 #define IRQF_SHARED SA_SHIRQ
112 #endif /* < 2.6.18 */
114 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 17)
115 #ifdef CONFIG_NET_RADIO
116 #define CONFIG_WIRELESS_EXT
117 #endif
118 #endif /* < 2.6.17 */
120 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 67)
121 #ifndef SANDGATE2G
122 #define MOD_INC_USE_COUNT
123 #define MOD_DEC_USE_COUNT
124 #endif /* not SANDGATE2G */
125 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 67) */
127 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32)
128 #include <linux/sched.h>
129 #endif
131 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)
132 #include <net/lib80211.h>
133 #endif
134 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30)
135 #include <linux/ieee80211.h>
136 #else
137 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 14)
138 #include <net/ieee80211.h>
139 #endif
140 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30) */
142 #if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
144 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 27)
145 #include <pcmcia/version.h>
146 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 27) */
148 #include <pcmcia/cs_types.h>
149 #include <pcmcia/cs.h>
150 #include <pcmcia/cistpl.h>
151 #include <pcmcia/cisreg.h>
152 #include <pcmcia/ds.h>
154 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 69))
155 /* In 2.5 (as of 2.5.69 at least) there is a cs_error exported which
156 * does this, but it's not in 2.4 so we do our own for now.
158 static inline void
159 cs_error(client_handle_t handle, int func, int ret)
161 error_info_t err = { func, ret };
162 CardServices(ReportError, handle, &err);
164 #endif
166 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 16))
168 typedef struct pcmcia_device dev_link_t;
170 #endif
172 #endif /* CONFIG_PCMCIA */
174 #ifndef __exit
175 #define __exit
176 #endif
177 #ifndef __devexit
178 #define __devexit
179 #endif
180 #ifndef __devinit
181 #define __devinit __init
182 #endif
183 #ifndef __devinitdata
184 #define __devinitdata
185 #endif
186 #ifndef __devexit_p
187 #define __devexit_p(x) x
188 #endif
190 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0))
192 #define pci_get_drvdata(dev) (dev)->sysdata
193 #define pci_set_drvdata(dev, value) (dev)->sysdata = (value)
196 * New-style (2.4.x) PCI/hot-pluggable PCI/CardBus registration
199 struct pci_device_id {
200 unsigned int vendor, device; /* Vendor and device ID or PCI_ANY_ID */
201 unsigned int subvendor, subdevice; /* Subsystem ID's or PCI_ANY_ID */
202 unsigned int class, class_mask; /* (class,subclass,prog-if) triplet */
203 unsigned long driver_data; /* Data private to the driver */
206 struct pci_driver {
207 struct list_head node;
208 char *name;
209 const struct pci_device_id *id_table; /* NULL if wants all devices */
210 int (*probe)(struct pci_dev *dev,
211 const struct pci_device_id *id); /* New device inserted */
212 void (*remove)(struct pci_dev *dev); /* Device removed (NULL if not a hot-plug
213 * capable driver)
215 void (*suspend)(struct pci_dev *dev); /* Device suspended */
216 void (*resume)(struct pci_dev *dev); /* Device woken up */
219 #define MODULE_DEVICE_TABLE(type, name)
220 #define PCI_ANY_ID (~0)
222 /* compatpci.c */
223 #define pci_module_init pci_register_driver
224 extern int pci_register_driver(struct pci_driver *drv);
225 extern void pci_unregister_driver(struct pci_driver *drv);
227 #endif /* PCI registration */
229 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18))
230 #define pci_module_init pci_register_driver
231 #endif
233 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 18))
234 #ifdef MODULE
235 #define module_init(x) int init_module(void) { return x(); }
236 #define module_exit(x) void cleanup_module(void) { x(); }
237 #else
238 #define module_init(x) __initcall(x);
239 #define module_exit(x) __exitcall(x);
240 #endif
241 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 18) */
243 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)
244 #define WL_USE_NETDEV_OPS
245 #else
246 #undef WL_USE_NETDEV_OPS
247 #endif
249 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)) && defined(CONFIG_RFKILL)
250 #define WL_CONFIG_RFKILL
251 #else
252 #undef WL_CONFIG_RFKILL
253 #endif
255 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 48))
256 #define list_for_each(pos, head) \
257 for (pos = (head)->next; pos != (head); pos = pos->next)
258 #endif
260 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 13))
261 #define pci_resource_start(dev, bar) ((dev)->base_address[(bar)])
262 #elif (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 44))
263 #define pci_resource_start(dev, bar) ((dev)->resource[(bar)].start)
264 #endif
266 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 23))
267 #define pci_enable_device(dev) do { } while (0)
268 #endif
270 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 14))
271 #define net_device device
272 #endif
274 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 42))
277 * DMA mapping
279 * See linux/Documentation/DMA-mapping.txt
282 #ifndef PCI_DMA_TODEVICE
283 #define PCI_DMA_TODEVICE 1
284 #define PCI_DMA_FROMDEVICE 2
285 #endif
287 typedef u32 dma_addr_t;
289 /* Pure 2^n version of get_order */
290 static inline int get_order(unsigned long size)
292 int order;
294 size = (size-1) >> (PAGE_SHIFT-1);
295 order = -1;
296 do {
297 size >>= 1;
298 order++;
299 } while (size);
300 return order;
303 static inline void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
304 dma_addr_t *dma_handle)
306 void *ret;
307 int gfp = GFP_ATOMIC | GFP_DMA;
309 ret = (void *)__get_free_pages(gfp, get_order(size));
311 if (ret != NULL) {
312 memset(ret, 0, size);
313 *dma_handle = virt_to_bus(ret);
315 return ret;
317 static inline void pci_free_consistent(struct pci_dev *hwdev, size_t size,
318 void *vaddr, dma_addr_t dma_handle)
320 free_pages((unsigned long)vaddr, get_order(size));
322 #ifdef ILSIM
323 extern uint pci_map_single(void *dev, void *va, uint size, int direction);
324 extern void pci_unmap_single(void *dev, uint pa, uint size, int direction);
325 #else
326 #define pci_map_single(cookie, address, size, dir) virt_to_bus(address)
327 #define pci_unmap_single(cookie, address, size, dir)
328 #endif
330 #endif /* DMA mapping */
332 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 43))
334 #define dev_kfree_skb_any(a) dev_kfree_skb(a)
335 #define netif_down(dev) do { (dev)->start = 0; } while (0)
337 /* pcmcia-cs provides its own netdevice compatibility layer */
338 #ifndef _COMPAT_NETDEVICE_H
341 * SoftNet
343 * For pre-softnet kernels we need to tell the upper layer not to
344 * re-enter start_xmit() while we are in there. However softnet
345 * guarantees not to enter while we are in there so there is no need
346 * to do the netif_stop_queue() dance unless the transmit queue really
347 * gets stuck. This should also improve performance according to tests
348 * done by Aman Singla.
351 #define dev_kfree_skb_irq(a) dev_kfree_skb(a)
352 #define netif_wake_queue(dev) \
353 do { clear_bit(0, &(dev)->tbusy); mark_bh(NET_BH); } while (0)
354 #define netif_stop_queue(dev) set_bit(0, &(dev)->tbusy)
356 static inline void netif_start_queue(struct net_device *dev)
358 dev->tbusy = 0;
359 dev->interrupt = 0;
360 dev->start = 1;
363 #define netif_queue_stopped(dev) (dev)->tbusy
364 #define netif_running(dev) (dev)->start
366 #endif /* _COMPAT_NETDEVICE_H */
368 #define netif_device_attach(dev) netif_start_queue(dev)
369 #define netif_device_detach(dev) netif_stop_queue(dev)
371 /* 2.4.x renamed bottom halves to tasklets */
372 #define tasklet_struct tq_struct
373 static inline void tasklet_schedule(struct tasklet_struct *tasklet)
375 queue_task(tasklet, &tq_immediate);
376 mark_bh(IMMEDIATE_BH);
379 static inline void tasklet_init(struct tasklet_struct *tasklet,
380 void (*func)(unsigned long),
381 unsigned long data)
383 tasklet->next = NULL;
384 tasklet->sync = 0;
385 tasklet->routine = (void (*)(void *))func;
386 tasklet->data = (void *)data;
388 #define tasklet_kill(tasklet) { do {} while (0); }
390 /* 2.4.x introduced del_timer_sync() */
391 #define del_timer_sync(timer) del_timer(timer)
393 #else
395 #define netif_down(dev)
397 #endif /* SoftNet */
399 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 22))
400 #define skb_reset_mac_header(skb) (skb)->mac.raw = (skb)->data
401 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 3) */
403 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 9))
404 #define eth_hdr(skb) ((struct ethhdr *)((skb)->mac.raw))
405 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 9) */
407 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 3))
410 * Emit code to initialise a tq_struct's routine and data pointers
412 #define PREPARE_TQUEUE(_tq, _routine, _data) \
413 do { \
414 (_tq)->routine = _routine; \
415 (_tq)->data = _data; \
416 } while (0)
419 * Emit code to initialise all of a tq_struct
421 #define INIT_TQUEUE(_tq, _routine, _data) \
422 do { \
423 INIT_LIST_HEAD(&(_tq)->list); \
424 (_tq)->sync = 0; \
425 PREPARE_TQUEUE((_tq), (_routine), (_data)); \
426 } while (0)
428 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 3) */
430 /* Power management related macro & routines */
431 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 9)
432 #define PCI_SAVE_STATE(a, b) pci_save_state(a)
433 #define PCI_RESTORE_STATE(a, b) pci_restore_state(a)
434 #else
435 #define PCI_SAVE_STATE(a, b) pci_save_state(a, b)
436 #define PCI_RESTORE_STATE(a, b) pci_restore_state(a, b)
437 #endif
439 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 6))
440 static inline int
441 pci_save_state(struct pci_dev *dev, u32 *buffer)
443 int i;
444 if (buffer) {
445 for (i = 0; i < 16; i++)
446 pci_read_config_dword(dev, i * 4, &buffer[i]);
448 return 0;
451 static inline int
452 pci_restore_state(struct pci_dev *dev, u32 *buffer)
454 int i;
456 if (buffer) {
457 for (i = 0; i < 16; i++)
458 pci_write_config_dword(dev, i * 4, buffer[i]);
461 * otherwise, write the context information we know from bootup.
462 * This works around a problem where warm-booting from Windows
463 * combined with a D3(hot)->D0 transition causes PCI config
464 * header data to be forgotten.
466 else {
467 for (i = 0; i < 6; i ++)
468 pci_write_config_dword(dev,
469 PCI_BASE_ADDRESS_0 + (i * 4),
470 pci_resource_start(dev, i));
471 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
473 return 0;
475 #endif /* PCI power management */
477 /* Old cp0 access macros deprecated in 2.4.19 */
478 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 19))
479 #define read_c0_count() read_32bit_cp0_register(CP0_COUNT)
480 #endif
482 /* Module refcount handled internally in 2.6.x */
483 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24))
484 #ifndef SET_MODULE_OWNER
485 #define SET_MODULE_OWNER(dev) do {} while (0)
486 #define OLD_MOD_INC_USE_COUNT MOD_INC_USE_COUNT
487 #define OLD_MOD_DEC_USE_COUNT MOD_DEC_USE_COUNT
488 #else
489 #define OLD_MOD_INC_USE_COUNT do {} while (0)
490 #define OLD_MOD_DEC_USE_COUNT do {} while (0)
491 #endif
492 #else /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24) */
493 #ifndef SET_MODULE_OWNER
494 #define SET_MODULE_OWNER(dev) do {} while (0)
495 #endif
496 #ifndef MOD_INC_USE_COUNT
497 #define MOD_INC_USE_COUNT do {} while (0)
498 #endif
499 #ifndef MOD_DEC_USE_COUNT
500 #define MOD_DEC_USE_COUNT do {} while (0)
501 #endif
502 #define OLD_MOD_INC_USE_COUNT MOD_INC_USE_COUNT
503 #define OLD_MOD_DEC_USE_COUNT MOD_DEC_USE_COUNT
504 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24) */
506 #ifndef SET_NETDEV_DEV
507 #define SET_NETDEV_DEV(net, pdev) do {} while (0)
508 #endif
510 #ifndef HAVE_FREE_NETDEV
511 #define free_netdev(dev) kfree(dev)
512 #endif
514 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
515 /* struct packet_type redefined in 2.6.x */
516 #define af_packet_priv data
517 #endif
519 /* suspend args */
520 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
521 #define DRV_SUSPEND_STATE_TYPE pm_message_t
522 #else
523 #define DRV_SUSPEND_STATE_TYPE uint32
524 #endif
526 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
527 #define CHECKSUM_HW CHECKSUM_PARTIAL
528 #endif
530 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
531 #include <linux/time.h>
532 #include <linux/wait.h>
533 #else
534 #include <linux/sched.h>
536 #define __wait_event_interruptible_timeout(wq, condition, ret) \
537 do { \
538 wait_queue_t __wait; \
539 init_waitqueue_entry(&__wait, current); \
541 add_wait_queue(&wq, &__wait); \
542 for (;;) { \
543 set_current_state(TASK_INTERRUPTIBLE); \
544 if (condition) \
545 break; \
546 if (!signal_pending(current)) { \
547 ret = schedule_timeout(ret); \
548 if (!ret) \
549 break; \
550 continue; \
552 ret = -ERESTARTSYS; \
553 break; \
555 current->state = TASK_RUNNING; \
556 remove_wait_queue(&wq, &__wait); \
557 } while (0)
559 #define wait_event_interruptible_timeout(wq, condition, timeout) \
560 ({ \
561 long __ret = timeout; \
562 if (!(condition)) \
563 __wait_event_interruptible_timeout(wq, condition, __ret); \
564 __ret; \
567 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)) */
569 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
570 #define KILL_PROC(pid, sig) \
572 struct task_struct *tsk; \
573 tsk = find_task_by_vpid(pid); \
574 if (tsk) send_sig(sig, tsk, 1); \
576 #else
577 #define KILL_PROC(pid, sig) \
579 kill_proc(pid, sig, 1); \
581 #endif
583 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)
584 #define WL_DEV_IF(dev) ((wl_if_t*)netdev_priv(dev))
585 #else
586 #define WL_DEV_IF(dev) ((wl_if_t*)(dev)->priv)
587 #endif
589 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20)
590 #define WL_ISR(i, d, p) wl_isr((i), (d))
591 #else
592 #define WL_ISR(i, d, p) wl_isr((i), (d), (p))
593 #endif /* < 2.6.20 */
595 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)
596 #define NETDEV_PRIV(dev) (netdev_priv(dev))
597 #else
598 #define NETDEV_PRIV(dev) ((dev)->priv)
599 #endif
601 #endif /* _linuxver_h_ */