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) 1999-2011, Broadcom Corporation
7 * Unless you and Broadcom execute a separate written software license
8 * agreement governing use of this software, this software is licensed to you
9 * under the terms of the GNU General Public License version 2 (the "GPL"),
10 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
11 * following added to such license:
13 * As a special exception, the copyright holders of this software give you
14 * permission to link this software with independent modules, and to copy and
15 * distribute the resulting executable under terms of your choice, provided that
16 * you also meet, for each linked independent module, the terms and conditions of
17 * the license of that module. An independent module is a module which is not
18 * derived from this software. The special exception does not apply to any
19 * modifications of the software.
21 * Notwithstanding the above, under no circumstances may you combine this
22 * software in any way with any other Broadcom software provided under a license
23 * other than the GPL, without Broadcom's express prior written consent.
25 * $Id: linuxver.h,v 13.53.2.2 2010-12-22 23:47:26 $
31 #include <linux/version.h>
32 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
33 #include <linux/config.h>
35 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33))
36 #include <generated/autoconf.h>
38 #include <linux/autoconf.h>
40 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)) */
41 #include <linux/module.h>
43 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0))
44 /* __NO_VERSION__ must be defined for all linkables except one in 2.2 */
45 #ifdef __UNDEF_NO_VERSION__
48 #define __NO_VERSION__
50 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0) */
52 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0)
53 #define module_param(_name_, _type_, _perm_) MODULE_PARM(_name_, "i")
54 #define module_param_string(_name_, _string_, _size_, _perm_) \
55 MODULE_PARM(_string_, "c" __MODULE_STRING(_size_))
58 /* linux/malloc.h is deprecated, use linux/slab.h instead. */
59 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 9))
60 #include <linux/malloc.h>
62 #include <linux/slab.h>
65 #include <linux/types.h>
66 #include <linux/init.h>
68 #include <linux/string.h>
69 #include <linux/pci.h>
70 #include <linux/interrupt.h>
71 #include <linux/netdevice.h>
72 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
74 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28)) */
77 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 41))
78 #include <linux/workqueue.h>
80 #include <linux/tqueue.h>
82 #define work_struct tq_struct
85 #define INIT_WORK(_work, _func, _data) INIT_TQUEUE((_work), (_func), (_data))
88 #define schedule_work(_work) schedule_task((_work))
90 #ifndef flush_scheduled_work
91 #define flush_scheduled_work() flush_scheduled_tasks()
93 #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 41) */
95 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
96 #define MY_INIT_WORK(_work, _func) INIT_WORK(_work, _func)
98 #define MY_INIT_WORK(_work, _func) INIT_WORK(_work, _func, _work)
99 typedef void (*work_func_t)(void *work);
100 #endif /* >= 2.6.20 */
102 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
103 /* Some distributions have their own 2.6.x compatibility layers */
105 typedef void irqreturn_t;
108 #define IRQ_RETVAL(x)
111 typedef irqreturn_t(*FN_ISR) (int irq, void *dev_id, struct pt_regs *ptregs);
112 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) */
114 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
115 #define IRQF_SHARED SA_SHIRQ
116 #endif /* < 2.6.18 */
118 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 17)
119 #ifdef CONFIG_NET_RADIO
120 #define CONFIG_WIRELESS_EXT
122 #endif /* < 2.6.17 */
124 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 67)
125 #define MOD_INC_USE_COUNT
126 #define MOD_DEC_USE_COUNT
127 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 67) */
129 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32)
130 #include <linux/sched.h>
133 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)
134 #include <net/lib80211.h>
136 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30)
137 #include <linux/ieee80211.h>
139 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 14)
140 #include <net/ieee80211.h>
142 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30) */
152 #define __devinit __init
154 #ifndef __devinitdata
155 #define __devinitdata
158 #define __devexit_p(x) x
161 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0))
163 #define pci_get_drvdata(dev) (dev)->sysdata
164 #define pci_set_drvdata(dev, value) (dev)->sysdata = (value)
167 * New-style (2.4.x) PCI/hot-pluggable PCI/CardBus registration
170 struct pci_device_id {
171 unsigned int vendor, device; /* Vendor and device ID or PCI_ANY_ID */
172 unsigned int subvendor, subdevice; /* Subsystem ID's or PCI_ANY_ID */
173 unsigned int class, class_mask; /* (class,subclass,prog-if) triplet */
174 unsigned long driver_data; /* Data private to the driver */
178 struct list_head node;
180 const struct pci_device_id *id_table; /* NULL if wants all devices */
181 int (*probe)(struct pci_dev *dev,
182 const struct pci_device_id *id); /* New device inserted */
183 void (*remove)(struct pci_dev *dev); /* Device removed (NULL if not a hot-plug
186 void (*suspend)(struct pci_dev *dev); /* Device suspended */
187 void (*resume)(struct pci_dev *dev); /* Device woken up */
190 #define MODULE_DEVICE_TABLE(type, name)
191 #define PCI_ANY_ID (~0)
194 #define pci_module_init pci_register_driver
195 extern int pci_register_driver(struct pci_driver *drv);
196 extern void pci_unregister_driver(struct pci_driver *drv);
198 #endif /* PCI registration */
200 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18))
201 #define pci_module_init pci_register_driver
204 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 18))
206 #define module_init(x) int init_module(void) { return x(); }
207 #define module_exit(x) void cleanup_module(void) { x(); }
209 #define module_init(x) __initcall(x);
210 #define module_exit(x) __exitcall(x);
212 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 18) */
214 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)
215 #define WL_USE_NETDEV_OPS
217 #undef WL_USE_NETDEV_OPS
220 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31)) && defined(CONFIG_RFKILL_INPUT)
221 #define WL_CONFIG_RFKILL_INPUT
223 #undef WL_CONFIG_RFKILL_INPUT
226 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 48))
227 #define list_for_each(pos, head) \
228 for (pos = (head)->next; pos != (head); pos = pos->next)
231 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 13))
232 #define pci_resource_start(dev, bar) ((dev)->base_address[(bar)])
233 #elif (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 44))
234 #define pci_resource_start(dev, bar) ((dev)->resource[(bar)].start)
237 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 23))
238 #define pci_enable_device(dev) do { } while (0)
241 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 14))
242 #define net_device device
245 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 42))
250 * See linux/Documentation/DMA-mapping.txt
253 #ifndef PCI_DMA_TODEVICE
254 #define PCI_DMA_TODEVICE 1
255 #define PCI_DMA_FROMDEVICE 2
258 typedef u32 dma_addr_t;
260 /* Pure 2^n version of get_order */
261 static inline int get_order(unsigned long size)
265 size = (size-1) >> (PAGE_SHIFT-1);
274 static inline void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
275 dma_addr_t *dma_handle)
278 int gfp = GFP_ATOMIC | GFP_DMA;
280 ret = (void *)__get_free_pages(gfp, get_order(size));
283 memset(ret, 0, size);
284 *dma_handle = virt_to_bus(ret);
288 static inline void pci_free_consistent(struct pci_dev *hwdev, size_t size,
289 void *vaddr, dma_addr_t dma_handle)
291 free_pages((unsigned long)vaddr, get_order(size));
293 #define pci_map_single(cookie, address, size, dir) virt_to_bus(address)
294 #define pci_unmap_single(cookie, address, size, dir)
296 #endif /* DMA mapping */
298 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 43))
300 #define dev_kfree_skb_any(a) dev_kfree_skb(a)
301 #define netif_down(dev) do { (dev)->start = 0; } while (0)
303 /* pcmcia-cs provides its own netdevice compatibility layer */
304 #ifndef _COMPAT_NETDEVICE_H
309 * For pre-softnet kernels we need to tell the upper layer not to
310 * re-enter start_xmit() while we are in there. However softnet
311 * guarantees not to enter while we are in there so there is no need
312 * to do the netif_stop_queue() dance unless the transmit queue really
313 * gets stuck. This should also improve performance according to tests
314 * done by Aman Singla.
317 #define dev_kfree_skb_irq(a) dev_kfree_skb(a)
318 #define netif_wake_queue(dev) \
319 do { clear_bit(0, &(dev)->tbusy); mark_bh(NET_BH); } while (0)
320 #define netif_stop_queue(dev) set_bit(0, &(dev)->tbusy)
322 static inline void netif_start_queue(struct net_device *dev)
329 #define netif_queue_stopped(dev) (dev)->tbusy
330 #define netif_running(dev) (dev)->start
332 #endif /* _COMPAT_NETDEVICE_H */
334 #define netif_device_attach(dev) netif_start_queue(dev)
335 #define netif_device_detach(dev) netif_stop_queue(dev)
337 /* 2.4.x renamed bottom halves to tasklets */
338 #define tasklet_struct tq_struct
339 static inline void tasklet_schedule(struct tasklet_struct *tasklet)
341 queue_task(tasklet, &tq_immediate);
342 mark_bh(IMMEDIATE_BH);
345 static inline void tasklet_init(struct tasklet_struct *tasklet,
346 void (*func)(unsigned long),
349 tasklet->next = NULL;
351 tasklet->routine = (void (*)(void *))func;
352 tasklet->data = (void *)data;
354 #define tasklet_kill(tasklet) { do {} while (0); }
356 /* 2.4.x introduced del_timer_sync() */
357 #define del_timer_sync(timer) del_timer(timer)
361 #define netif_down(dev)
365 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 3))
368 * Emit code to initialise a tq_struct's routine and data pointers
370 #define PREPARE_TQUEUE(_tq, _routine, _data) \
372 (_tq)->routine = _routine; \
373 (_tq)->data = _data; \
377 * Emit code to initialise all of a tq_struct
379 #define INIT_TQUEUE(_tq, _routine, _data) \
381 INIT_LIST_HEAD(&(_tq)->list); \
383 PREPARE_TQUEUE((_tq), (_routine), (_data)); \
386 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 3) */
388 /* Power management related macro & routines */
389 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 9)
390 #define PCI_SAVE_STATE(a, b) pci_save_state(a)
391 #define PCI_RESTORE_STATE(a, b) pci_restore_state(a)
393 #define PCI_SAVE_STATE(a, b) pci_save_state(a, b)
394 #define PCI_RESTORE_STATE(a, b) pci_restore_state(a, b)
397 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 6))
399 pci_save_state(struct pci_dev *dev, u32 *buffer)
403 for (i = 0; i < 16; i++)
404 pci_read_config_dword(dev, i * 4, &buffer[i]);
410 pci_restore_state(struct pci_dev *dev, u32 *buffer)
415 for (i = 0; i < 16; i++)
416 pci_write_config_dword(dev, i * 4, buffer[i]);
419 * otherwise, write the context information we know from bootup.
420 * This works around a problem where warm-booting from Windows
421 * combined with a D3(hot)->D0 transition causes PCI config
422 * header data to be forgotten.
425 for (i = 0; i < 6; i ++)
426 pci_write_config_dword(dev,
427 PCI_BASE_ADDRESS_0 + (i * 4),
428 pci_resource_start(dev, i));
429 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
433 #endif /* PCI power management */
435 /* Old cp0 access macros deprecated in 2.4.19 */
436 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 19))
437 #define read_c0_count() read_32bit_cp0_register(CP0_COUNT)
440 /* Module refcount handled internally in 2.6.x */
441 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24))
442 #ifndef SET_MODULE_OWNER
443 #define SET_MODULE_OWNER(dev) do {} while (0)
444 #define OLD_MOD_INC_USE_COUNT MOD_INC_USE_COUNT
445 #define OLD_MOD_DEC_USE_COUNT MOD_DEC_USE_COUNT
447 #define OLD_MOD_INC_USE_COUNT do {} while (0)
448 #define OLD_MOD_DEC_USE_COUNT do {} while (0)
450 #else /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24) */
451 #ifndef SET_MODULE_OWNER
452 #define SET_MODULE_OWNER(dev) do {} while (0)
454 #ifndef MOD_INC_USE_COUNT
455 #define MOD_INC_USE_COUNT do {} while (0)
457 #ifndef MOD_DEC_USE_COUNT
458 #define MOD_DEC_USE_COUNT do {} while (0)
460 #define OLD_MOD_INC_USE_COUNT MOD_INC_USE_COUNT
461 #define OLD_MOD_DEC_USE_COUNT MOD_DEC_USE_COUNT
462 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24) */
464 #ifndef SET_NETDEV_DEV
465 #define SET_NETDEV_DEV(net, pdev) do {} while (0)
468 #ifndef HAVE_FREE_NETDEV
469 #define free_netdev(dev) kfree(dev)
472 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
473 /* struct packet_type redefined in 2.6.x */
474 #define af_packet_priv data
478 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
479 #define DRV_SUSPEND_STATE_TYPE pm_message_t
481 #define DRV_SUSPEND_STATE_TYPE uint32
484 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
485 #define CHECKSUM_HW CHECKSUM_PARTIAL
488 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
489 #define KILL_PROC(nr, sig) \
491 struct task_struct *tsk; \
493 pid = find_get_pid((pid_t)nr); \
494 tsk = pid_task(pid, PIDTYPE_PID); \
495 if (tsk) send_sig(sig, tsk, 1); \
498 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && (LINUX_VERSION_CODE <= \
499 KERNEL_VERSION(2, 6, 30))
500 #define KILL_PROC(pid, sig) \
502 struct task_struct *tsk; \
503 tsk = find_task_by_vpid(pid); \
504 if (tsk) send_sig(sig, tsk, 1); \
507 #define KILL_PROC(pid, sig) \
509 kill_proc(pid, sig, 1); \
512 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31) */
514 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
515 #include <linux/time.h>
516 #include <linux/wait.h>
518 #include <linux/sched.h>
520 #define __wait_event_interruptible_timeout(wq, condition, ret) \
522 wait_queue_t __wait; \
523 init_waitqueue_entry(&__wait, current); \
525 add_wait_queue(&wq, &__wait); \
527 set_current_state(TASK_INTERRUPTIBLE); \
530 if (!signal_pending(current)) { \
531 ret = schedule_timeout(ret); \
536 ret = -ERESTARTSYS; \
539 current->state = TASK_RUNNING; \
540 remove_wait_queue(&wq, &__wait); \
543 #define wait_event_interruptible_timeout(wq, condition, timeout) \
545 long __ret = timeout; \
547 __wait_event_interruptible_timeout(wq, condition, __ret); \
551 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)) */
553 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)
554 #define WL_DEV_IF(dev) ((wl_if_t*)netdev_priv(dev))
556 #define WL_DEV_IF(dev) ((wl_if_t*)(dev)->priv)
559 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20)
560 #define WL_ISR(i, d, p) wl_isr((i), (d))
562 #define WL_ISR(i, d, p) wl_isr((i), (d), (p))
563 #endif /* < 2.6.20 */
565 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
566 #define netdev_priv(dev) dev->priv
567 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)) */
569 #endif /* _linuxver_h_ */