2
2
* Linux-specific abstractions to gain some independence from linux kernel versions.
3
3
* Pave over some 2.2 versus 2.4 versus 2.6 kernel differences.
5
* Copyright (C) 2011, Broadcom Corporation. All Rights Reserved.
5
* Copyright (C) 2013, Broadcom Corporation. All Rights Reserved.
7
7
* Permission to use, copy, modify, and/or distribute this software for any
8
8
* purpose with or without fee is hereby granted, provided that the above
26
26
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
27
27
#include <linux/config.h>
30
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33))
29
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33))
30
#include <generated/autoconf.h>
31
32
#include <linux/autoconf.h>
33
#include <generated/autoconf.h>
36
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0))
37
#include <linux/kconfig.h>
37
40
#include <linux/module.h>
39
42
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0))
64
67
#include <linux/pci.h>
65
68
#include <linux/interrupt.h>
66
69
#include <linux/netdevice.h>
70
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
71
#include <linux/semaphore.h>
73
#include <asm/semaphore.h>
67
75
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
70
78
#include <asm/io.h>
72
80
#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 41))
90
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20)
98
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
99
#define DAEMONIZE(a) daemonize(a); \
100
allow_signal(SIGKILL); \
101
allow_signal(SIGTERM);
103
#define RAISE_RX_SOFTIRQ() \
104
cpu_raise_softirq(smp_processor_id(), NET_RX_SOFTIRQ)
105
#define DAEMONIZE(a) daemonize(); \
107
strncpy(current->comm, a, MIN(sizeof(current->comm), (strlen(a)))); \
111
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
91
112
#define MY_INIT_WORK(_work, _func) INIT_WORK(_work, _func)
93
114
#define MY_INIT_WORK(_work, _func) INIT_WORK(_work, _func, _work)
115
#if !(LINUX_VERSION_CODE == KERNEL_VERSION(2, 6, 18) && defined(RHEL_MAJOR) && \
94
118
typedef void (*work_func_t)(void *work);
97
122
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
125
150
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)
126
151
#include <net/lib80211.h>
128
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30)
153
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)
129
154
#include <linux/ieee80211.h>
131
156
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 14)
428
457
#define CHECKSUM_HW CHECKSUM_PARTIAL
462
struct task_struct *p_task;
465
struct semaphore sema;
467
struct completion completed;
472
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
473
#define SMP_RD_BARRIER_DEPENDS(x) smp_read_barrier_depends(x)
475
#define SMP_RD_BARRIER_DEPENDS(x) smp_rmb(x)
478
#define PROC_START(thread_func, owner, tsk_ctl, flags) \
480
sema_init(&((tsk_ctl)->sema), 0); \
481
init_completion(&((tsk_ctl)->completed)); \
482
(tsk_ctl)->parent = owner; \
483
(tsk_ctl)->terminated = FALSE; \
484
(tsk_ctl)->thr_pid = kernel_thread(thread_func, tsk_ctl, flags); \
485
if ((tsk_ctl)->thr_pid > 0) \
486
wait_for_completion(&((tsk_ctl)->completed)); \
487
DBG_THR(("%s thr:%lx started\n", __FUNCTION__, (tsk_ctl)->thr_pid)); \
490
#ifdef USE_KTHREAD_API
491
#define PROC_START2(thread_func, owner, tsk_ctl, flags, name) \
493
sema_init(&((tsk_ctl)->sema), 0); \
494
init_completion(&((tsk_ctl)->completed)); \
495
(tsk_ctl)->parent = owner; \
496
(tsk_ctl)->terminated = FALSE; \
497
(tsk_ctl)->p_task = kthread_run(thread_func, tsk_ctl, (char*)name); \
498
(tsk_ctl)->thr_pid = (tsk_ctl)->p_task->pid; \
499
DBG_THR(("%s thr:%lx created\n", __FUNCTION__, (tsk_ctl)->thr_pid)); \
503
#define PROC_STOP(tsk_ctl) \
505
(tsk_ctl)->terminated = TRUE; \
507
up(&((tsk_ctl)->sema)); \
508
wait_for_completion(&((tsk_ctl)->completed)); \
509
DBG_THR(("%s thr:%lx terminated OK\n", __FUNCTION__, (tsk_ctl)->thr_pid)); \
510
(tsk_ctl)->thr_pid = -1; \
513
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
514
#define KILL_PROC(nr, sig) \
516
struct task_struct *tsk; \
518
pid = find_get_pid((pid_t)nr); \
519
tsk = pid_task(pid, PIDTYPE_PID); \
520
if (tsk) send_sig(sig, tsk, 1); \
523
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && (LINUX_VERSION_CODE <= \
524
KERNEL_VERSION(2, 6, 30))
525
#define KILL_PROC(pid, sig) \
527
struct task_struct *tsk; \
528
tsk = find_task_by_vpid(pid); \
529
if (tsk) send_sig(sig, tsk, 1); \
532
#define KILL_PROC(pid, sig) \
534
kill_proc(pid, sig, 1); \
431
539
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
432
540
#include <linux/time.h>
433
541
#include <linux/wait.h>
470
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
471
#define KILL_PROC(nr, sig) \
473
struct task_struct *tsk; \
475
pid = find_get_pid((pid_t)nr); \
476
tsk = pid_task(pid, PIDTYPE_PID); \
477
if (tsk) send_sig(sig, tsk, 1); \
480
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && (LINUX_VERSION_CODE <= \
481
KERNEL_VERSION(2, 6, 30))
482
#define KILL_PROC(pid, sig) \
484
struct task_struct *tsk; \
485
tsk = find_task_by_vpid(pid); \
486
if (tsk) send_sig(sig, tsk, 1); \
489
#define KILL_PROC(pid, sig) \
491
kill_proc(pid, sig, 1); \
496
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
497
#define netdev_priv(dev) dev->priv
500
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)
501
#define WL_DEV_IF(dev) ((wl_if_t*)netdev_priv(dev))
503
#define WL_DEV_IF(dev) ((wl_if_t*)(dev)->priv)
578
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24))
579
#define DEV_PRIV(dev) (dev->priv)
581
#define DEV_PRIV(dev) netdev_priv(dev)
506
584
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20)
509
587
#define WL_ISR(i, d, p) wl_isr((i), (d), (p))
512
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)
513
#define NETDEV_PRIV(dev) (netdev_priv(dev))
515
#define NETDEV_PRIV(dev) ((dev)->priv)
590
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
591
#define netdev_priv(dev) dev->priv