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-2016, 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.
26 * <<Broadcom-WL-IPTag/Open:>>
28 * $Id: linuxver.h 604758 2015-12-08 12:01:08Z $
34 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
35 #pragma GCC diagnostic push
36 #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
37 #pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
41 #include <linux/version.h>
42 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
43 #include <linux/config.h>
45 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33))
46 #include <generated/autoconf.h>
48 #include <linux/autoconf.h>
50 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)) */
52 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0))
53 #include <linux/kconfig.h>
55 #include <linux/module.h>
57 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0))
58 /* __NO_VERSION__ must be defined for all linkables except one in 2.2 */
59 #ifdef __UNDEF_NO_VERSION__
62 #define __NO_VERSION__
64 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0) */
66 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0)
67 #define module_param(_name_, _type_, _perm_) MODULE_PARM(_name_, "i")
68 #define module_param_string(_name_, _string_, _size_, _perm_) \
69 MODULE_PARM(_string_, "c" __MODULE_STRING(_size_))
72 /* linux/malloc.h is deprecated, use linux/slab.h instead. */
73 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 9))
74 #include <linux/malloc.h>
76 #include <linux/slab.h>
79 #include <linux/types.h>
80 #include <linux/init.h>
82 #include <linux/string.h>
83 #include <linux/pci.h>
84 #include <linux/interrupt.h>
85 #include <linux/kthread.h>
86 #include <linux/netdevice.h>
87 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
88 #include <linux/semaphore.h>
90 #include <asm/semaphore.h>
91 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) */
92 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
94 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28)) */
97 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 41))
98 #include <linux/workqueue.h>
100 #include <linux/tqueue.h>
102 #define work_struct tq_struct
105 #define INIT_WORK(_work, _func, _data) INIT_TQUEUE((_work), (_func), (_data))
107 #ifndef schedule_work
108 #define schedule_work(_work) schedule_task((_work))
110 #ifndef flush_scheduled_work
111 #define flush_scheduled_work() flush_scheduled_tasks()
113 #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 41) */
115 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
116 #define DAEMONIZE(a) do { \
117 allow_signal(SIGKILL); \
118 allow_signal(SIGTERM); \
120 #elif ((LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0)) && \
121 (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)))
122 #define DAEMONIZE(a) daemonize(a); \
123 allow_signal(SIGKILL); \
124 allow_signal(SIGTERM);
125 #else /* Linux 2.4 (w/o preemption patch) */
126 #define RAISE_RX_SOFTIRQ() \
127 cpu_raise_softirq(smp_processor_id(), NET_RX_SOFTIRQ)
128 #define DAEMONIZE(a) daemonize(); \
130 strncpy(current->comm, a, MIN(sizeof(current->comm), (strlen(a)))); \
132 #endif /* LINUX_VERSION_CODE */
134 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
135 #define MY_INIT_WORK(_work, _func) INIT_WORK(_work, _func)
137 #define MY_INIT_WORK(_work, _func) INIT_WORK(_work, _func, _work)
138 #if !(LINUX_VERSION_CODE == KERNEL_VERSION(2, 6, 18) && defined(RHEL_MAJOR) && \
141 typedef void (*work_func_t)(void *work);
143 #endif /* >= 2.6.20 */
145 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
146 /* Some distributions have their own 2.6.x compatibility layers */
148 typedef void irqreturn_t;
151 #define IRQ_RETVAL(x)
154 typedef irqreturn_t(*FN_ISR) (int irq, void *dev_id, struct pt_regs *ptregs);
155 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) */
157 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
158 #define IRQF_SHARED SA_SHIRQ
159 #endif /* < 2.6.18 */
161 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 17)
162 #ifdef CONFIG_NET_RADIO
163 #define CONFIG_WIRELESS_EXT
165 #endif /* < 2.6.17 */
167 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 67)
168 #define MOD_INC_USE_COUNT
169 #define MOD_DEC_USE_COUNT
170 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 67) */
172 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32)
173 #include <linux/sched.h>
174 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32) */
176 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
177 #include <linux/sched/rt.h>
178 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0) */
180 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)
181 #include <net/lib80211.h>
183 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)
184 #include <linux/ieee80211.h>
186 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 14)
187 #include <net/ieee80211.h>
189 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30) */
199 # if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0))
200 # define __devinit __init
202 /* All devices are hotpluggable since linux 3.8.0 */
205 #endif /* !__devinit */
206 #ifndef __devinitdata
207 #define __devinitdata
210 #define __devexit_p(x) x
213 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0))
215 #define pci_get_drvdata(dev) (dev)->sysdata
216 #define pci_set_drvdata(dev, value) (dev)->sysdata = (value)
219 * New-style (2.4.x) PCI/hot-pluggable PCI/CardBus registration
222 struct pci_device_id {
223 unsigned int vendor, device; /* Vendor and device ID or PCI_ANY_ID */
224 unsigned int subvendor, subdevice; /* Subsystem ID's or PCI_ANY_ID */
225 unsigned int class, class_mask; /* (class,subclass,prog-if) triplet */
226 unsigned long driver_data; /* Data private to the driver */
230 struct list_head node;
232 const struct pci_device_id *id_table; /* NULL if wants all devices */
233 int (*probe)(struct pci_dev *dev,
234 const struct pci_device_id *id); /* New device inserted */
235 void (*remove)(struct pci_dev *dev); /* Device removed (NULL if not a hot-plug
238 void (*suspend)(struct pci_dev *dev); /* Device suspended */
239 void (*resume)(struct pci_dev *dev); /* Device woken up */
242 #define MODULE_DEVICE_TABLE(type, name)
243 #define PCI_ANY_ID (~0)
246 #define pci_module_init pci_register_driver
247 extern int pci_register_driver(struct pci_driver *drv);
248 extern void pci_unregister_driver(struct pci_driver *drv);
250 #endif /* PCI registration */
252 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18))
253 #define pci_module_init pci_register_driver
256 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 18))
258 #define module_init(x) int init_module(void) { return x(); }
259 #define module_exit(x) void cleanup_module(void) { x(); }
261 #define module_init(x) __initcall(x);
262 #define module_exit(x) __exitcall(x);
264 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 18) */
266 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)
267 #define WL_USE_NETDEV_OPS
269 #undef WL_USE_NETDEV_OPS
272 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)) && defined(CONFIG_RFKILL)
273 #define WL_CONFIG_RFKILL
275 #undef WL_CONFIG_RFKILL
278 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 48))
279 #define list_for_each(pos, head) \
280 for (pos = (head)->next; pos != (head); pos = pos->next)
283 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 13))
284 #define pci_resource_start(dev, bar) ((dev)->base_address[(bar)])
285 #elif (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 44))
286 #define pci_resource_start(dev, bar) ((dev)->resource[(bar)].start)
289 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 23))
290 #define pci_enable_device(dev) do { } while (0)
293 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 14))
294 #define net_device device
297 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 42))
302 * See linux/Documentation/DMA-mapping.txt
305 #ifndef PCI_DMA_TODEVICE
306 #define PCI_DMA_TODEVICE 1
307 #define PCI_DMA_FROMDEVICE 2
310 typedef u32 dma_addr_t;
312 /* Pure 2^n version of get_order */
313 static inline int get_order(unsigned long size)
317 size = (size-1) >> (PAGE_SHIFT-1);
326 static inline void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
327 dma_addr_t *dma_handle)
330 int gfp = GFP_ATOMIC | GFP_DMA;
332 ret = (void *)__get_free_pages(gfp, get_order(size));
335 memset(ret, 0, size);
336 *dma_handle = virt_to_bus(ret);
340 static inline void pci_free_consistent(struct pci_dev *hwdev, size_t size,
341 void *vaddr, dma_addr_t dma_handle)
343 free_pages((unsigned long)vaddr, get_order(size));
345 #define pci_map_single(cookie, address, size, dir) virt_to_bus(address)
346 #define pci_unmap_single(cookie, address, size, dir)
348 #endif /* DMA mapping */
350 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 43))
352 #define dev_kfree_skb_any(a) dev_kfree_skb(a)
353 #define netif_down(dev) do { (dev)->start = 0; } while (0)
355 /* pcmcia-cs provides its own netdevice compatibility layer */
356 #ifndef _COMPAT_NETDEVICE_H
361 * For pre-softnet kernels we need to tell the upper layer not to
362 * re-enter start_xmit() while we are in there. However softnet
363 * guarantees not to enter while we are in there so there is no need
364 * to do the netif_stop_queue() dance unless the transmit queue really
365 * gets stuck. This should also improve performance according to tests
366 * done by Aman Singla.
369 #define dev_kfree_skb_irq(a) dev_kfree_skb(a)
370 #define netif_wake_queue(dev) \
371 do { clear_bit(0, &(dev)->tbusy); mark_bh(NET_BH); } while (0)
372 #define netif_stop_queue(dev) set_bit(0, &(dev)->tbusy)
374 static inline void netif_start_queue(struct net_device *dev)
381 #define netif_queue_stopped(dev) (dev)->tbusy
382 #define netif_running(dev) (dev)->start
384 #endif /* _COMPAT_NETDEVICE_H */
386 #define netif_device_attach(dev) netif_start_queue(dev)
387 #define netif_device_detach(dev) netif_stop_queue(dev)
389 /* 2.4.x renamed bottom halves to tasklets */
390 #define tasklet_struct tq_struct
391 static inline void tasklet_schedule(struct tasklet_struct *tasklet)
393 queue_task(tasklet, &tq_immediate);
394 mark_bh(IMMEDIATE_BH);
397 static inline void tasklet_init(struct tasklet_struct *tasklet,
398 void (*func)(unsigned long),
401 tasklet->next = NULL;
403 tasklet->routine = (void (*)(void *))func;
404 tasklet->data = (void *)data;
406 #define tasklet_kill(tasklet) { do {} while (0); }
408 /* 2.4.x introduced del_timer_sync() */
409 #define del_timer_sync(timer) del_timer(timer)
413 #define netif_down(dev)
417 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 3))
420 * Emit code to initialise a tq_struct's routine and data pointers
422 #define PREPARE_TQUEUE(_tq, _routine, _data) \
424 (_tq)->routine = _routine; \
425 (_tq)->data = _data; \
429 * Emit code to initialise all of a tq_struct
431 #define INIT_TQUEUE(_tq, _routine, _data) \
433 INIT_LIST_HEAD(&(_tq)->list); \
435 PREPARE_TQUEUE((_tq), (_routine), (_data)); \
438 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 3) */
440 /* Power management related macro & routines */
441 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 9)
442 #define PCI_SAVE_STATE(a, b) pci_save_state(a)
443 #define PCI_RESTORE_STATE(a, b) pci_restore_state(a)
445 #define PCI_SAVE_STATE(a, b) pci_save_state(a, b)
446 #define PCI_RESTORE_STATE(a, b) pci_restore_state(a, b)
449 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 6))
451 pci_save_state(struct pci_dev *dev, u32 *buffer)
455 for (i = 0; i < 16; i++)
456 pci_read_config_dword(dev, i * 4, &buffer[i]);
462 pci_restore_state(struct pci_dev *dev, u32 *buffer)
467 for (i = 0; i < 16; i++)
468 pci_write_config_dword(dev, i * 4, buffer[i]);
471 * otherwise, write the context information we know from bootup.
472 * This works around a problem where warm-booting from Windows
473 * combined with a D3(hot)->D0 transition causes PCI config
474 * header data to be forgotten.
477 for (i = 0; i < 6; i ++)
478 pci_write_config_dword(dev,
479 PCI_BASE_ADDRESS_0 + (i * 4),
480 pci_resource_start(dev, i));
481 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
485 #endif /* PCI power management */
487 /* Old cp0 access macros deprecated in 2.4.19 */
488 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 19))
489 #define read_c0_count() read_32bit_cp0_register(CP0_COUNT)
492 /* Module refcount handled internally in 2.6.x */
493 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24))
494 #ifndef SET_MODULE_OWNER
495 #define SET_MODULE_OWNER(dev) do {} while (0)
496 #define OLD_MOD_INC_USE_COUNT MOD_INC_USE_COUNT
497 #define OLD_MOD_DEC_USE_COUNT MOD_DEC_USE_COUNT
499 #define OLD_MOD_INC_USE_COUNT do {} while (0)
500 #define OLD_MOD_DEC_USE_COUNT do {} while (0)
502 #else /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24) */
503 #ifndef SET_MODULE_OWNER
504 #define SET_MODULE_OWNER(dev) do {} while (0)
506 #ifndef MOD_INC_USE_COUNT
507 #define MOD_INC_USE_COUNT do {} while (0)
509 #ifndef MOD_DEC_USE_COUNT
510 #define MOD_DEC_USE_COUNT do {} while (0)
512 #define OLD_MOD_INC_USE_COUNT MOD_INC_USE_COUNT
513 #define OLD_MOD_DEC_USE_COUNT MOD_DEC_USE_COUNT
514 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24) */
516 #ifndef SET_NETDEV_DEV
517 #define SET_NETDEV_DEV(net, pdev) do {} while (0)
520 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 1, 0))
521 #ifndef HAVE_FREE_NETDEV
522 #define free_netdev(dev) kfree(dev)
524 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 1, 0) */
526 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
527 /* struct packet_type redefined in 2.6.x */
528 #define af_packet_priv data
532 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
533 #define DRV_SUSPEND_STATE_TYPE pm_message_t
535 #define DRV_SUSPEND_STATE_TYPE uint32
538 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
539 #define CHECKSUM_HW CHECKSUM_PARTIAL
543 void *parent; /* some external entity that the thread supposed to work for */
545 struct task_struct *p_task;
547 int prio; /* priority */
548 struct semaphore sema;
550 struct completion completed;
556 /* requires tsk_ctl_t tsk argument, the caller's priv data is passed in owner ptr */
557 /* note this macro assumes there may be only one context waiting on thread's completion */
559 #define DBG_THR(x) printk x
564 static inline bool binary_sema_down(tsk_ctl_t *tsk)
566 if (down_interruptible(&tsk->sema) == 0) {
567 unsigned long flags = 0;
568 spin_lock_irqsave(&tsk->spinlock, flags);
569 if (tsk->up_cnt == 1)
572 DBG_THR(("dhd_dpc_thread: Unexpected up_cnt %d\n", tsk->up_cnt));
574 spin_unlock_irqrestore(&tsk->spinlock, flags);
580 static inline bool binary_sema_up(tsk_ctl_t *tsk)
583 unsigned long flags = 0;
585 spin_lock_irqsave(&tsk->spinlock, flags);
586 if (tsk->up_cnt == 0) {
589 } else if (tsk->up_cnt == 1) {
590 /* dhd_sched_dpc: dpc is alread up! */
592 DBG_THR(("dhd_sched_dpc: unexpected up cnt %d!\n", tsk->up_cnt));
594 spin_unlock_irqrestore(&tsk->spinlock, flags);
602 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
603 #define SMP_RD_BARRIER_DEPENDS(x) smp_read_barrier_depends(x)
605 #define SMP_RD_BARRIER_DEPENDS(x) smp_rmb(x)
608 #define PROC_START(thread_func, owner, tsk_ctl, flags, name) \
610 sema_init(&((tsk_ctl)->sema), 0); \
611 init_completion(&((tsk_ctl)->completed)); \
612 (tsk_ctl)->parent = owner; \
613 (tsk_ctl)->proc_name = name; \
614 (tsk_ctl)->terminated = FALSE; \
615 (tsk_ctl)->p_task = kthread_run(thread_func, tsk_ctl, (char*)name); \
616 if (IS_ERR((tsk_ctl)->p_task)) { \
617 (tsk_ctl)->thr_pid = DHD_PID_KT_INVALID; \
618 DBG_THR(("%s(): thread:%s:%lx failed\n", __FUNCTION__, \
619 (tsk_ctl)->proc_name, (tsk_ctl)->thr_pid)); \
621 (tsk_ctl)->thr_pid = (tsk_ctl)->p_task->pid; \
622 spin_lock_init(&((tsk_ctl)->spinlock)); \
623 DBG_THR(("%s(): thread:%s:%lx started\n", __FUNCTION__, \
624 (tsk_ctl)->proc_name, (tsk_ctl)->thr_pid)); \
628 #define PROC_STOP(tsk_ctl) \
630 (tsk_ctl)->terminated = TRUE; \
632 up(&((tsk_ctl)->sema)); \
633 wait_for_completion(&((tsk_ctl)->completed)); \
634 DBG_THR(("%s(): thread:%s:%lx terminated OK\n", __FUNCTION__, \
635 (tsk_ctl)->proc_name, (tsk_ctl)->thr_pid)); \
636 (tsk_ctl)->thr_pid = -1; \
639 /* ----------------------- */
641 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
642 #define KILL_PROC(nr, sig) \
644 struct task_struct *tsk; \
646 pid = find_get_pid((pid_t)nr); \
647 tsk = pid_task(pid, PIDTYPE_PID); \
648 if (tsk) send_sig(sig, tsk, 1); \
651 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && (LINUX_VERSION_CODE <= \
652 KERNEL_VERSION(2, 6, 30))
653 #define KILL_PROC(pid, sig) \
655 struct task_struct *tsk; \
656 tsk = find_task_by_vpid(pid); \
657 if (tsk) send_sig(sig, tsk, 1); \
660 #define KILL_PROC(pid, sig) \
662 kill_proc(pid, sig, 1); \
665 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31) */
667 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
668 #include <linux/time.h>
669 #include <linux/wait.h>
671 #include <linux/sched.h>
673 #define __wait_event_interruptible_timeout(wq, condition, ret) \
675 wait_queue_t __wait; \
676 init_waitqueue_entry(&__wait, current); \
678 add_wait_queue(&wq, &__wait); \
680 set_current_state(TASK_INTERRUPTIBLE); \
683 if (!signal_pending(current)) { \
684 ret = schedule_timeout(ret); \
689 ret = -ERESTARTSYS; \
692 current->state = TASK_RUNNING; \
693 remove_wait_queue(&wq, &__wait); \
696 #define wait_event_interruptible_timeout(wq, condition, timeout) \
698 long __ret = timeout; \
700 __wait_event_interruptible_timeout(wq, condition, __ret); \
704 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)) */
707 For < 2.6.24, wl creates its own netdev but doesn't
708 align the priv area like the genuine alloc_netdev().
709 Since netdev_priv() always gives us the aligned address, it will
710 not match our unaligned address for < 2.6.24
712 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24))
713 #define DEV_PRIV(dev) (dev->priv)
715 #define DEV_PRIV(dev) netdev_priv(dev)
718 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20)
719 #define WL_ISR(i, d, p) wl_isr((i), (d))
721 #define WL_ISR(i, d, p) wl_isr((i), (d), (p))
722 #endif /* < 2.6.20 */
724 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
725 #define netdev_priv(dev) dev->priv
726 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)) */
728 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
729 #define CAN_SLEEP() ((!in_atomic() && !irqs_disabled()))
731 #define CAN_SLEEP() (FALSE)
734 #define KMALLOC_FLAG (CAN_SLEEP() ? GFP_KERNEL: GFP_ATOMIC)
736 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
737 #define RANDOM32 prandom_u32
739 #define RANDOM32 random32
740 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) */
742 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
743 #define SRANDOM32(entropy) prandom_seed(entropy)
745 #define SRANDOM32(entropy) srandom32(entropy)
746 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) */
749 * Overide latest kfifo functions with
750 * older version to work on older kernels
752 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33))
753 #define kfifo_in_spinlocked(a, b, c, d) kfifo_put(a, (u8 *)b, c)
754 #define kfifo_out_spinlocked(a, b, c, d) kfifo_get(a, (u8 *)b, c)
755 #define kfifo_esize(a) 1
756 #elif (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32)) && \
757 (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36)) && !defined(WL_COMPAT_WIRELESS)
758 #define kfifo_in_spinlocked(a, b, c, d) kfifo_in_locked(a, b, c, d)
759 #define kfifo_out_spinlocked(a, b, c, d) kfifo_out_locked(a, b, c, d)
760 #define kfifo_esize(a) 1
761 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)) */
763 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
764 #pragma GCC diagnostic pop
767 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0))
768 static inline struct inode *file_inode(const struct file *f)
770 return f->f_dentry->d_inode;
772 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0)) */
774 #endif /* _linuxver_h_ */