CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
orangepi-xunlong

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: orangepi-xunlong/orangepi-build
Path: blob/next/external/cache/sources/wl/include/linuxver.h
Views: 3959
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.
4
*
5
* $Copyright Open Broadcom Corporation$
6
*
7
* $Id: linuxver.h 372519 2012-12-04 01:21:16Z $
8
*/
9
10
#ifndef _linuxver_h_
11
#define _linuxver_h_
12
13
#include <linux/version.h>
14
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
15
#include <linux/config.h>
16
#else
17
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33))
18
#include <generated/autoconf.h>
19
#else
20
#include <linux/autoconf.h>
21
#endif
22
#endif
23
24
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0))
25
#include <linux/kconfig.h>
26
#endif
27
28
#include <linux/module.h>
29
30
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0))
31
32
#ifdef __UNDEF_NO_VERSION__
33
#undef __NO_VERSION__
34
#else
35
#define __NO_VERSION__
36
#endif
37
#endif
38
39
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0)
40
#define module_param(_name_, _type_, _perm_) MODULE_PARM(_name_, "i")
41
#define module_param_string(_name_, _string_, _size_, _perm_) \
42
MODULE_PARM(_string_, "c" __MODULE_STRING(_size_))
43
#endif
44
45
46
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 9))
47
#include <linux/malloc.h>
48
#else
49
#include <linux/slab.h>
50
#endif
51
52
#include <linux/types.h>
53
#include <linux/init.h>
54
#include <linux/mm.h>
55
#include <linux/string.h>
56
#include <linux/pci.h>
57
#include <linux/interrupt.h>
58
#include <linux/netdevice.h>
59
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
60
#include <linux/semaphore.h>
61
#else
62
#include <asm/semaphore.h>
63
#endif
64
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
65
#undef IP_TOS
66
#endif
67
#include <asm/io.h>
68
69
#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 41))
70
#include <linux/workqueue.h>
71
#else
72
#include <linux/tqueue.h>
73
#ifndef work_struct
74
#define work_struct tq_struct
75
#endif
76
#ifndef INIT_WORK
77
#define INIT_WORK(_work, _func, _data) INIT_TQUEUE((_work), (_func), (_data))
78
#endif
79
#ifndef schedule_work
80
#define schedule_work(_work) schedule_task((_work))
81
#endif
82
#ifndef flush_scheduled_work
83
#define flush_scheduled_work() flush_scheduled_tasks()
84
#endif
85
#endif
86
87
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
88
#define DAEMONIZE(a) daemonize(a); \
89
allow_signal(SIGKILL); \
90
allow_signal(SIGTERM);
91
#else
92
#define RAISE_RX_SOFTIRQ() \
93
cpu_raise_softirq(smp_processor_id(), NET_RX_SOFTIRQ)
94
#define DAEMONIZE(a) daemonize(); \
95
do { if (a) \
96
strncpy(current->comm, a, MIN(sizeof(current->comm), (strlen(a)))); \
97
} while (0);
98
#endif
99
100
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
101
#define MY_INIT_WORK(_work, _func) INIT_WORK(_work, _func)
102
#else
103
#define MY_INIT_WORK(_work, _func) INIT_WORK(_work, _func, _work)
104
#if !(LINUX_VERSION_CODE == KERNEL_VERSION(2, 6, 18) && defined(RHEL_MAJOR) && \
105
(RHEL_MAJOR == 5))
106
107
typedef void (*work_func_t)(void *work);
108
#endif
109
#endif
110
111
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
112
113
#ifndef IRQ_NONE
114
typedef void irqreturn_t;
115
#define IRQ_NONE
116
#define IRQ_HANDLED
117
#define IRQ_RETVAL(x)
118
#endif
119
#else
120
typedef irqreturn_t(*FN_ISR) (int irq, void *dev_id, struct pt_regs *ptregs);
121
#endif
122
123
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
124
#define IRQF_SHARED SA_SHIRQ
125
#endif
126
127
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 17)
128
#ifdef CONFIG_NET_RADIO
129
#define CONFIG_WIRELESS_EXT
130
#endif
131
#endif
132
133
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 67)
134
#define MOD_INC_USE_COUNT
135
#define MOD_DEC_USE_COUNT
136
#endif
137
138
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32)
139
#include <linux/sched.h>
140
#endif
141
142
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)
143
#include <net/lib80211.h>
144
#endif
145
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)
146
#include <linux/ieee80211.h>
147
#else
148
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 14)
149
#include <net/ieee80211.h>
150
#endif
151
#endif
152
153
154
#ifdef CUSTOMER_HW4
155
#include <linux/kthread.h>
156
#endif
157
158
#ifndef __exit
159
#define __exit
160
#endif
161
#ifndef __devexit
162
#define __devexit
163
#endif
164
#ifndef __devinit
165
#define __devinit __init
166
#endif
167
#ifndef __devinitdata
168
#define __devinitdata
169
#endif
170
#ifndef __devexit_p
171
#define __devexit_p(x) x
172
#endif
173
174
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0))
175
176
#define pci_get_drvdata(dev) (dev)->sysdata
177
#define pci_set_drvdata(dev, value) (dev)->sysdata = (value)
178
179
180
181
struct pci_device_id {
182
unsigned int vendor, device;
183
unsigned int subvendor, subdevice;
184
unsigned int class, class_mask;
185
unsigned long driver_data;
186
};
187
188
struct pci_driver {
189
struct list_head node;
190
char *name;
191
const struct pci_device_id *id_table;
192
int (*probe)(struct pci_dev *dev,
193
const struct pci_device_id *id);
194
void (*remove)(struct pci_dev *dev);
195
void (*suspend)(struct pci_dev *dev);
196
void (*resume)(struct pci_dev *dev);
197
};
198
199
#define MODULE_DEVICE_TABLE(type, name)
200
#define PCI_ANY_ID (~0)
201
202
203
#define pci_module_init pci_register_driver
204
extern int pci_register_driver(struct pci_driver *drv);
205
extern void pci_unregister_driver(struct pci_driver *drv);
206
207
#endif
208
209
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18))
210
#define pci_module_init pci_register_driver
211
#endif
212
213
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 18))
214
#ifdef MODULE
215
#define module_init(x) int init_module(void) { return x(); }
216
#define module_exit(x) void cleanup_module(void) { x(); }
217
#else
218
#define module_init(x) __initcall(x);
219
#define module_exit(x) __exitcall(x);
220
#endif
221
#endif
222
223
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)
224
#define WL_USE_NETDEV_OPS
225
#else
226
#undef WL_USE_NETDEV_OPS
227
#endif
228
229
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)) && defined(CONFIG_RFKILL)
230
#define WL_CONFIG_RFKILL
231
#else
232
#undef WL_CONFIG_RFKILL
233
#endif
234
235
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 48))
236
#define list_for_each(pos, head) \
237
for (pos = (head)->next; pos != (head); pos = pos->next)
238
#endif
239
240
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 13))
241
#define pci_resource_start(dev, bar) ((dev)->base_address[(bar)])
242
#elif (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 44))
243
#define pci_resource_start(dev, bar) ((dev)->resource[(bar)].start)
244
#endif
245
246
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 23))
247
#define pci_enable_device(dev) do { } while (0)
248
#endif
249
250
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 14))
251
#define net_device device
252
#endif
253
254
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 42))
255
256
257
258
#ifndef PCI_DMA_TODEVICE
259
#define PCI_DMA_TODEVICE 1
260
#define PCI_DMA_FROMDEVICE 2
261
#endif
262
263
typedef u32 dma_addr_t;
264
265
266
static inline int get_order(unsigned long size)
267
{
268
int order;
269
270
size = (size-1) >> (PAGE_SHIFT-1);
271
order = -1;
272
do {
273
size >>= 1;
274
order++;
275
} while (size);
276
return order;
277
}
278
279
static inline void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
280
dma_addr_t *dma_handle)
281
{
282
void *ret;
283
int gfp = GFP_ATOMIC | GFP_DMA;
284
285
ret = (void *)__get_free_pages(gfp, get_order(size));
286
287
if (ret != NULL) {
288
memset(ret, 0, size);
289
*dma_handle = virt_to_bus(ret);
290
}
291
return ret;
292
}
293
static inline void pci_free_consistent(struct pci_dev *hwdev, size_t size,
294
void *vaddr, dma_addr_t dma_handle)
295
{
296
free_pages((unsigned long)vaddr, get_order(size));
297
}
298
#define pci_map_single(cookie, address, size, dir) virt_to_bus(address)
299
#define pci_unmap_single(cookie, address, size, dir)
300
301
#endif
302
303
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 43))
304
305
#define dev_kfree_skb_any(a) dev_kfree_skb(a)
306
#define netif_down(dev) do { (dev)->start = 0; } while (0)
307
308
309
#ifndef _COMPAT_NETDEVICE_H
310
311
312
313
#define dev_kfree_skb_irq(a) dev_kfree_skb(a)
314
#define netif_wake_queue(dev) \
315
do { clear_bit(0, &(dev)->tbusy); mark_bh(NET_BH); } while (0)
316
#define netif_stop_queue(dev) set_bit(0, &(dev)->tbusy)
317
318
static inline void netif_start_queue(struct net_device *dev)
319
{
320
dev->tbusy = 0;
321
dev->interrupt = 0;
322
dev->start = 1;
323
}
324
325
#define netif_queue_stopped(dev) (dev)->tbusy
326
#define netif_running(dev) (dev)->start
327
328
#endif
329
330
#define netif_device_attach(dev) netif_start_queue(dev)
331
#define netif_device_detach(dev) netif_stop_queue(dev)
332
333
334
#define tasklet_struct tq_struct
335
static inline void tasklet_schedule(struct tasklet_struct *tasklet)
336
{
337
queue_task(tasklet, &tq_immediate);
338
mark_bh(IMMEDIATE_BH);
339
}
340
341
static inline void tasklet_init(struct tasklet_struct *tasklet,
342
void (*func)(unsigned long),
343
unsigned long data)
344
{
345
tasklet->next = NULL;
346
tasklet->sync = 0;
347
tasklet->routine = (void (*)(void *))func;
348
tasklet->data = (void *)data;
349
}
350
#define tasklet_kill(tasklet) { do {} while (0); }
351
352
353
#define del_timer_sync(timer) del_timer(timer)
354
355
#else
356
357
#define netif_down(dev)
358
359
#endif
360
361
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 3))
362
363
364
#define PREPARE_TQUEUE(_tq, _routine, _data) \
365
do { \
366
(_tq)->routine = _routine; \
367
(_tq)->data = _data; \
368
} while (0)
369
370
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)
377
378
#endif
379
380
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
388
389
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 6))
390
static inline int
391
pci_save_state(struct pci_dev *dev, u32 *buffer)
392
{
393
int i;
394
if (buffer) {
395
for (i = 0; i < 16; i++)
396
pci_read_config_dword(dev, i * 4, &buffer[i]);
397
}
398
return 0;
399
}
400
401
static inline int
402
pci_restore_state(struct pci_dev *dev, u32 *buffer)
403
{
404
int i;
405
406
if (buffer) {
407
for (i = 0; i < 16; i++)
408
pci_write_config_dword(dev, i * 4, buffer[i]);
409
}
410
411
else {
412
for (i = 0; i < 6; i ++)
413
pci_write_config_dword(dev,
414
PCI_BASE_ADDRESS_0 + (i * 4),
415
pci_resource_start(dev, i));
416
pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
417
}
418
return 0;
419
}
420
#endif
421
422
423
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 19))
424
#define read_c0_count() read_32bit_cp0_register(CP0_COUNT)
425
#endif
426
427
428
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24))
429
#ifndef SET_MODULE_OWNER
430
#define SET_MODULE_OWNER(dev) do {} while (0)
431
#define OLD_MOD_INC_USE_COUNT MOD_INC_USE_COUNT
432
#define OLD_MOD_DEC_USE_COUNT MOD_DEC_USE_COUNT
433
#else
434
#define OLD_MOD_INC_USE_COUNT do {} while (0)
435
#define OLD_MOD_DEC_USE_COUNT do {} while (0)
436
#endif
437
#else
438
#ifndef SET_MODULE_OWNER
439
#define SET_MODULE_OWNER(dev) do {} while (0)
440
#endif
441
#ifndef MOD_INC_USE_COUNT
442
#define MOD_INC_USE_COUNT do {} while (0)
443
#endif
444
#ifndef MOD_DEC_USE_COUNT
445
#define MOD_DEC_USE_COUNT do {} while (0)
446
#endif
447
#define OLD_MOD_INC_USE_COUNT MOD_INC_USE_COUNT
448
#define OLD_MOD_DEC_USE_COUNT MOD_DEC_USE_COUNT
449
#endif
450
451
#ifndef SET_NETDEV_DEV
452
#define SET_NETDEV_DEV(net, pdev) do {} while (0)
453
#endif
454
455
#ifndef HAVE_FREE_NETDEV
456
#define free_netdev(dev) kfree(dev)
457
#endif
458
459
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
460
461
#define af_packet_priv data
462
#endif
463
464
465
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
466
#define DRV_SUSPEND_STATE_TYPE pm_message_t
467
#else
468
#define DRV_SUSPEND_STATE_TYPE uint32
469
#endif
470
471
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
472
#define CHECKSUM_HW CHECKSUM_PARTIAL
473
#endif
474
475
typedef struct {
476
void *parent;
477
struct task_struct *p_task;
478
long thr_pid;
479
int prio;
480
struct semaphore sema;
481
int terminated;
482
struct completion completed;
483
} tsk_ctl_t;
484
485
486
487
488
#ifdef DHD_DEBUG
489
#define DBG_THR(x) printk x
490
#else
491
#define DBG_THR(x)
492
#endif
493
494
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
495
#define SMP_RD_BARRIER_DEPENDS(x) smp_read_barrier_depends(x)
496
#else
497
#define SMP_RD_BARRIER_DEPENDS(x) smp_rmb(x)
498
#endif
499
500
501
#define PROC_START(thread_func, owner, tsk_ctl, flags) \
502
{ \
503
sema_init(&((tsk_ctl)->sema), 0); \
504
init_completion(&((tsk_ctl)->completed)); \
505
(tsk_ctl)->parent = owner; \
506
(tsk_ctl)->terminated = FALSE; \
507
(tsk_ctl)->thr_pid = kernel_thread(thread_func, tsk_ctl, flags); \
508
if ((tsk_ctl)->thr_pid > 0) \
509
wait_for_completion(&((tsk_ctl)->completed)); \
510
DBG_THR(("%s thr:%lx started\n", __FUNCTION__, (tsk_ctl)->thr_pid)); \
511
}
512
513
#ifdef USE_KTHREAD_API
514
#define PROC_START2(thread_func, owner, tsk_ctl, flags, name) \
515
{ \
516
sema_init(&((tsk_ctl)->sema), 0); \
517
init_completion(&((tsk_ctl)->completed)); \
518
(tsk_ctl)->parent = owner; \
519
(tsk_ctl)->terminated = FALSE; \
520
(tsk_ctl)->p_task = kthread_run(thread_func, tsk_ctl, (char*)name); \
521
(tsk_ctl)->thr_pid = (tsk_ctl)->p_task->pid; \
522
DBG_THR(("%s thr:%lx created\n", __FUNCTION__, (tsk_ctl)->thr_pid)); \
523
}
524
#endif
525
526
#define PROC_STOP(tsk_ctl) \
527
{ \
528
(tsk_ctl)->terminated = TRUE; \
529
smp_wmb(); \
530
up(&((tsk_ctl)->sema)); \
531
wait_for_completion(&((tsk_ctl)->completed)); \
532
DBG_THR(("%s thr:%lx terminated OK\n", __FUNCTION__, (tsk_ctl)->thr_pid)); \
533
(tsk_ctl)->thr_pid = -1; \
534
}
535
536
537
538
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
539
#define KILL_PROC(nr, sig) \
540
{ \
541
struct task_struct *tsk; \
542
struct pid *pid; \
543
pid = find_get_pid((pid_t)nr); \
544
tsk = pid_task(pid, PIDTYPE_PID); \
545
if (tsk) send_sig(sig, tsk, 1); \
546
}
547
#else
548
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && (LINUX_VERSION_CODE <= \
549
KERNEL_VERSION(2, 6, 30))
550
#define KILL_PROC(pid, sig) \
551
{ \
552
struct task_struct *tsk; \
553
tsk = find_task_by_vpid(pid); \
554
if (tsk) send_sig(sig, tsk, 1); \
555
}
556
#else
557
#define KILL_PROC(pid, sig) \
558
{ \
559
kill_proc(pid, sig, 1); \
560
}
561
#endif
562
#endif
563
564
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
565
#include <linux/time.h>
566
#include <linux/wait.h>
567
#else
568
#include <linux/sched.h>
569
570
#define __wait_event_interruptible_timeout(wq, condition, ret) \
571
do { \
572
wait_queue_t __wait; \
573
init_waitqueue_entry(&__wait, current); \
574
\
575
add_wait_queue(&wq, &__wait); \
576
for (;;) { \
577
set_current_state(TASK_INTERRUPTIBLE); \
578
if (condition) \
579
break; \
580
if (!signal_pending(current)) { \
581
ret = schedule_timeout(ret); \
582
if (!ret) \
583
break; \
584
continue; \
585
} \
586
ret = -ERESTARTSYS; \
587
break; \
588
} \
589
current->state = TASK_RUNNING; \
590
remove_wait_queue(&wq, &__wait); \
591
} while (0)
592
593
#define wait_event_interruptible_timeout(wq, condition, timeout) \
594
({ \
595
long __ret = timeout; \
596
if (!(condition)) \
597
__wait_event_interruptible_timeout(wq, condition, __ret); \
598
__ret; \
599
})
600
601
#endif
602
603
604
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24))
605
#define DEV_PRIV(dev) (dev->priv)
606
#else
607
#define DEV_PRIV(dev) netdev_priv(dev)
608
#endif
609
610
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20)
611
#define WL_ISR(i, d, p) wl_isr((i), (d))
612
#else
613
#define WL_ISR(i, d, p) wl_isr((i), (d), (p))
614
#endif
615
616
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
617
#define netdev_priv(dev) dev->priv
618
#endif
619
620
#endif
621
622