.. | .. |
---|
1 | | -/* SPDX-License-Identifier: GPL-2.0 */ |
---|
2 | 1 | /* |
---|
3 | 2 | * Linux-specific abstractions to gain some independence from linux kernel versions. |
---|
4 | 3 | * Pave over some 2.2 versus 2.4 versus 2.6 kernel differences. |
---|
5 | 4 | * |
---|
6 | | - * Copyright (C) 1999-2019, Broadcom Corporation |
---|
7 | | - * |
---|
| 5 | + * Portions of this code are copyright (c) 2022 Cypress Semiconductor Corporation |
---|
| 6 | + * |
---|
| 7 | + * Copyright (C) 1999-2017, Broadcom Corporation |
---|
| 8 | + * |
---|
8 | 9 | * Unless you and Broadcom execute a separate written software license |
---|
9 | 10 | * agreement governing use of this software, this software is licensed to you |
---|
10 | 11 | * under the terms of the GNU General Public License version 2 (the "GPL"), |
---|
11 | 12 | * available at http://www.broadcom.com/licenses/GPLv2.php, with the |
---|
12 | 13 | * following added to such license: |
---|
13 | | - * |
---|
| 14 | + * |
---|
14 | 15 | * As a special exception, the copyright holders of this software give you |
---|
15 | 16 | * permission to link this software with independent modules, and to copy and |
---|
16 | 17 | * distribute the resulting executable under terms of your choice, provided that |
---|
.. | .. |
---|
18 | 19 | * the license of that module. An independent module is a module which is not |
---|
19 | 20 | * derived from this software. The special exception does not apply to any |
---|
20 | 21 | * modifications of the software. |
---|
21 | | - * |
---|
| 22 | + * |
---|
22 | 23 | * Notwithstanding the above, under no circumstances may you combine this |
---|
23 | 24 | * software in any way with any other Broadcom software provided under a license |
---|
24 | 25 | * other than the GPL, without Broadcom's express prior written consent. |
---|
.. | .. |
---|
26 | 27 | * |
---|
27 | 28 | * <<Broadcom-WL-IPTag/Open:>> |
---|
28 | 29 | * |
---|
29 | | - * $Id: linuxver.h 514727 2014-11-12 03:02:48Z $ |
---|
| 30 | + * $Id: linuxver.h 646730 2016-06-30 13:01:49Z $ |
---|
30 | 31 | */ |
---|
31 | 32 | |
---|
32 | 33 | #ifndef _linuxver_h_ |
---|
.. | .. |
---|
36 | 37 | #pragma GCC diagnostic push |
---|
37 | 38 | #pragma GCC diagnostic ignored "-Wunused-but-set-variable" |
---|
38 | 39 | #pragma GCC diagnostic ignored "-Wunused-but-set-parameter" |
---|
39 | | -#endif |
---|
| 40 | +#endif // endif |
---|
40 | 41 | |
---|
41 | 42 | #include <typedefs.h> |
---|
42 | 43 | #include <linux/version.h> |
---|
.. | .. |
---|
47 | 48 | #include <generated/autoconf.h> |
---|
48 | 49 | #else |
---|
49 | 50 | #include <linux/autoconf.h> |
---|
50 | | -#endif |
---|
| 51 | +#endif // endif |
---|
51 | 52 | #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)) */ |
---|
52 | 53 | |
---|
53 | 54 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0)) |
---|
54 | 55 | #include <linux/kconfig.h> |
---|
55 | | -#endif |
---|
| 56 | +#endif // endif |
---|
56 | 57 | #include <linux/module.h> |
---|
57 | 58 | |
---|
58 | 59 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0)) |
---|
.. | .. |
---|
61 | 62 | #undef __NO_VERSION__ |
---|
62 | 63 | #else |
---|
63 | 64 | #define __NO_VERSION__ |
---|
64 | | -#endif |
---|
| 65 | +#endif // endif |
---|
65 | 66 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0) */ |
---|
66 | 67 | |
---|
67 | 68 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0) |
---|
68 | 69 | #define module_param(_name_, _type_, _perm_) MODULE_PARM(_name_, "i") |
---|
69 | 70 | #define module_param_string(_name_, _string_, _size_, _perm_) \ |
---|
70 | 71 | MODULE_PARM(_string_, "c" __MODULE_STRING(_size_)) |
---|
71 | | -#endif |
---|
| 72 | +#endif // endif |
---|
72 | 73 | |
---|
73 | 74 | /* linux/malloc.h is deprecated, use linux/slab.h instead. */ |
---|
74 | 75 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 9)) |
---|
75 | 76 | #include <linux/malloc.h> |
---|
76 | 77 | #else |
---|
77 | 78 | #include <linux/slab.h> |
---|
78 | | -#endif |
---|
| 79 | +#endif // endif |
---|
79 | 80 | |
---|
80 | 81 | #include <linux/types.h> |
---|
81 | 82 | #include <linux/init.h> |
---|
.. | .. |
---|
101 | 102 | #include <linux/tqueue.h> |
---|
102 | 103 | #ifndef work_struct |
---|
103 | 104 | #define work_struct tq_struct |
---|
104 | | -#endif |
---|
| 105 | +#endif // endif |
---|
105 | 106 | #ifndef INIT_WORK |
---|
106 | 107 | #define INIT_WORK(_work, _func, _data) INIT_TQUEUE((_work), (_func), (_data)) |
---|
107 | | -#endif |
---|
| 108 | +#endif // endif |
---|
108 | 109 | #ifndef schedule_work |
---|
109 | 110 | #define schedule_work(_work) schedule_task((_work)) |
---|
110 | | -#endif |
---|
| 111 | +#endif // endif |
---|
111 | 112 | #ifndef flush_scheduled_work |
---|
112 | 113 | #define flush_scheduled_work() flush_scheduled_tasks() |
---|
113 | | -#endif |
---|
| 114 | +#endif // endif |
---|
114 | 115 | #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 41) */ |
---|
115 | 116 | |
---|
116 | 117 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0)) |
---|
.. | .. |
---|
140 | 141 | (RHEL_MAJOR == 5)) |
---|
141 | 142 | /* Exclude RHEL 5 */ |
---|
142 | 143 | typedef void (*work_func_t)(void *work); |
---|
143 | | -#endif |
---|
| 144 | +#endif // endif |
---|
144 | 145 | #endif /* >= 2.6.20 */ |
---|
145 | 146 | |
---|
146 | 147 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)) |
---|
.. | .. |
---|
150 | 151 | #define IRQ_NONE |
---|
151 | 152 | #define IRQ_HANDLED |
---|
152 | 153 | #define IRQ_RETVAL(x) |
---|
153 | | -#endif |
---|
| 154 | +#endif // endif |
---|
154 | 155 | #else |
---|
155 | 156 | typedef irqreturn_t(*FN_ISR) (int irq, void *dev_id, struct pt_regs *ptregs); |
---|
156 | 157 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) */ |
---|
.. | .. |
---|
162 | 163 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 17) |
---|
163 | 164 | #ifdef CONFIG_NET_RADIO |
---|
164 | 165 | #define CONFIG_WIRELESS_EXT |
---|
165 | | -#endif |
---|
| 166 | +#endif // endif |
---|
166 | 167 | #endif /* < 2.6.17 */ |
---|
167 | 168 | |
---|
168 | 169 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 67) |
---|
.. | .. |
---|
174 | 175 | #include <linux/sched.h> |
---|
175 | 176 | #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32) */ |
---|
176 | 177 | |
---|
| 178 | +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)) |
---|
| 179 | +#include <linux/signal.h> |
---|
| 180 | +#include <linux/sched/signal.h> |
---|
| 181 | +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0) */ |
---|
| 182 | + |
---|
177 | 183 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)) |
---|
178 | 184 | #include <linux/sched/rt.h> |
---|
179 | 185 | #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0) */ |
---|
180 | 186 | |
---|
181 | 187 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29) |
---|
182 | 188 | #include <net/lib80211.h> |
---|
183 | | -#endif |
---|
| 189 | +#endif // endif |
---|
184 | 190 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29) |
---|
185 | 191 | #include <linux/ieee80211.h> |
---|
186 | 192 | #else |
---|
187 | 193 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 14) |
---|
188 | 194 | #include <net/ieee80211.h> |
---|
189 | | -#endif |
---|
| 195 | +#endif // endif |
---|
190 | 196 | #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30) */ |
---|
191 | | - |
---|
192 | 197 | |
---|
193 | 198 | #ifndef __exit |
---|
194 | 199 | #define __exit |
---|
195 | | -#endif |
---|
| 200 | +#endif // endif |
---|
196 | 201 | #ifndef __devexit |
---|
197 | 202 | #define __devexit |
---|
198 | | -#endif |
---|
| 203 | +#endif // endif |
---|
199 | 204 | #ifndef __devinit |
---|
200 | 205 | # if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0)) |
---|
201 | 206 | # define __devinit __init |
---|
.. | .. |
---|
206 | 211 | #endif /* !__devinit */ |
---|
207 | 212 | #ifndef __devinitdata |
---|
208 | 213 | #define __devinitdata |
---|
209 | | -#endif |
---|
| 214 | +#endif // endif |
---|
210 | 215 | #ifndef __devexit_p |
---|
211 | 216 | #define __devexit_p(x) x |
---|
212 | | -#endif |
---|
| 217 | +#endif // endif |
---|
213 | 218 | |
---|
214 | 219 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0)) |
---|
215 | 220 | |
---|
.. | .. |
---|
252 | 257 | |
---|
253 | 258 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18)) |
---|
254 | 259 | #define pci_module_init pci_register_driver |
---|
255 | | -#endif |
---|
| 260 | +#endif // endif |
---|
256 | 261 | |
---|
257 | 262 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 18)) |
---|
258 | 263 | #ifdef MODULE |
---|
.. | .. |
---|
261 | 266 | #else |
---|
262 | 267 | #define module_init(x) __initcall(x); |
---|
263 | 268 | #define module_exit(x) __exitcall(x); |
---|
264 | | -#endif |
---|
| 269 | +#endif // endif |
---|
265 | 270 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 18) */ |
---|
266 | 271 | |
---|
267 | 272 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31) |
---|
268 | 273 | #define WL_USE_NETDEV_OPS |
---|
269 | 274 | #else |
---|
270 | 275 | #undef WL_USE_NETDEV_OPS |
---|
271 | | -#endif |
---|
| 276 | +#endif // endif |
---|
272 | 277 | |
---|
273 | 278 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)) && defined(CONFIG_RFKILL) |
---|
274 | 279 | #define WL_CONFIG_RFKILL |
---|
275 | 280 | #else |
---|
276 | 281 | #undef WL_CONFIG_RFKILL |
---|
277 | | -#endif |
---|
| 282 | +#endif // endif |
---|
278 | 283 | |
---|
279 | 284 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 48)) |
---|
280 | 285 | #define list_for_each(pos, head) \ |
---|
281 | 286 | for (pos = (head)->next; pos != (head); pos = pos->next) |
---|
282 | | -#endif |
---|
| 287 | +#endif // endif |
---|
283 | 288 | |
---|
284 | 289 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 13)) |
---|
285 | 290 | #define pci_resource_start(dev, bar) ((dev)->base_address[(bar)]) |
---|
286 | 291 | #elif (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 44)) |
---|
287 | 292 | #define pci_resource_start(dev, bar) ((dev)->resource[(bar)].start) |
---|
288 | | -#endif |
---|
| 293 | +#endif // endif |
---|
289 | 294 | |
---|
290 | 295 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 23)) |
---|
291 | 296 | #define pci_enable_device(dev) do { } while (0) |
---|
292 | | -#endif |
---|
| 297 | +#endif // endif |
---|
293 | 298 | |
---|
294 | 299 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 14)) |
---|
295 | 300 | #define net_device device |
---|
296 | | -#endif |
---|
| 301 | +#endif // endif |
---|
297 | 302 | |
---|
298 | 303 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 42)) |
---|
299 | 304 | |
---|
.. | .. |
---|
306 | 311 | #ifndef PCI_DMA_TODEVICE |
---|
307 | 312 | #define PCI_DMA_TODEVICE 1 |
---|
308 | 313 | #define PCI_DMA_FROMDEVICE 2 |
---|
309 | | -#endif |
---|
| 314 | +#endif // endif |
---|
310 | 315 | |
---|
311 | 316 | typedef u32 dma_addr_t; |
---|
312 | 317 | |
---|
.. | .. |
---|
347 | 352 | #define pci_unmap_single(cookie, address, size, dir) |
---|
348 | 353 | |
---|
349 | 354 | #endif /* DMA mapping */ |
---|
| 355 | + |
---|
| 356 | +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 15, 0) |
---|
| 357 | +typedef struct timer_list timer_list_compat_t; |
---|
| 358 | + |
---|
| 359 | +#define init_timer_compat(timer_compat, cb, priv) \ |
---|
| 360 | + init_timer(timer_compat); \ |
---|
| 361 | + (timer_compat)->data = (ulong)priv; \ |
---|
| 362 | + (timer_compat)->function = cb |
---|
| 363 | +#define timer_set_private(timer_compat, priv) (timer_compat)->data = (ulong)priv |
---|
| 364 | +#define timer_expires(timer_compat) (timer_compat)->expires |
---|
| 365 | + |
---|
| 366 | +#else /* LINUX_VERSION_CODE < KERNEL_VERSION(4, 15, 0) */ |
---|
| 367 | + |
---|
| 368 | +typedef struct timer_list_compat { |
---|
| 369 | + struct timer_list timer; |
---|
| 370 | + void *arg; |
---|
| 371 | + void (*callback)(ulong arg); |
---|
| 372 | +} timer_list_compat_t; |
---|
| 373 | + |
---|
| 374 | +extern void timer_cb_compat(struct timer_list *tl); |
---|
| 375 | + |
---|
| 376 | +#define init_timer_compat(timer_compat, cb, priv) \ |
---|
| 377 | + (timer_compat)->arg = priv; \ |
---|
| 378 | + (timer_compat)->callback = cb; \ |
---|
| 379 | + timer_setup(&(timer_compat)->timer, timer_cb_compat, 0); |
---|
| 380 | +#define timer_set_private(timer_compat, priv) (timer_compat)->arg = priv |
---|
| 381 | +#define timer_expires(timer_compat) (timer_compat)->timer.expires |
---|
| 382 | + |
---|
| 383 | +#define del_timer(t) del_timer(&((t)->timer)) |
---|
| 384 | +#define del_timer_sync(t) del_timer_sync(&((t)->timer)) |
---|
| 385 | +#define timer_pending(t) timer_pending(&((t)->timer)) |
---|
| 386 | +#define add_timer(t) add_timer(&((t)->timer)) |
---|
| 387 | +#define mod_timer(t, j) mod_timer(&((t)->timer), j) |
---|
| 388 | + |
---|
| 389 | +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(4, 15, 0) */ |
---|
350 | 390 | |
---|
351 | 391 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 43)) |
---|
352 | 392 | |
---|
.. | .. |
---|
445 | 485 | #else |
---|
446 | 486 | #define PCI_SAVE_STATE(a, b) pci_save_state(a, b) |
---|
447 | 487 | #define PCI_RESTORE_STATE(a, b) pci_restore_state(a, b) |
---|
448 | | -#endif |
---|
| 488 | +#endif // endif |
---|
449 | 489 | |
---|
450 | 490 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 6)) |
---|
451 | 491 | static inline int |
---|
.. | .. |
---|
488 | 528 | /* Old cp0 access macros deprecated in 2.4.19 */ |
---|
489 | 529 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 19)) |
---|
490 | 530 | #define read_c0_count() read_32bit_cp0_register(CP0_COUNT) |
---|
491 | | -#endif |
---|
| 531 | +#endif // endif |
---|
492 | 532 | |
---|
493 | 533 | /* Module refcount handled internally in 2.6.x */ |
---|
494 | 534 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)) |
---|
.. | .. |
---|
499 | 539 | #else |
---|
500 | 540 | #define OLD_MOD_INC_USE_COUNT do {} while (0) |
---|
501 | 541 | #define OLD_MOD_DEC_USE_COUNT do {} while (0) |
---|
502 | | -#endif |
---|
| 542 | +#endif // endif |
---|
503 | 543 | #else /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24) */ |
---|
504 | 544 | #ifndef SET_MODULE_OWNER |
---|
505 | 545 | #define SET_MODULE_OWNER(dev) do {} while (0) |
---|
506 | | -#endif |
---|
| 546 | +#endif // endif |
---|
507 | 547 | #ifndef MOD_INC_USE_COUNT |
---|
508 | 548 | #define MOD_INC_USE_COUNT do {} while (0) |
---|
509 | | -#endif |
---|
| 549 | +#endif // endif |
---|
510 | 550 | #ifndef MOD_DEC_USE_COUNT |
---|
511 | 551 | #define MOD_DEC_USE_COUNT do {} while (0) |
---|
512 | | -#endif |
---|
| 552 | +#endif // endif |
---|
513 | 553 | #define OLD_MOD_INC_USE_COUNT MOD_INC_USE_COUNT |
---|
514 | 554 | #define OLD_MOD_DEC_USE_COUNT MOD_DEC_USE_COUNT |
---|
515 | 555 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24) */ |
---|
516 | 556 | |
---|
517 | 557 | #ifndef SET_NETDEV_DEV |
---|
518 | 558 | #define SET_NETDEV_DEV(net, pdev) do {} while (0) |
---|
519 | | -#endif |
---|
| 559 | +#endif // endif |
---|
520 | 560 | |
---|
521 | 561 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 1, 0)) |
---|
522 | 562 | #ifndef HAVE_FREE_NETDEV |
---|
523 | 563 | #define free_netdev(dev) kfree(dev) |
---|
524 | | -#endif |
---|
| 564 | +#endif // endif |
---|
525 | 565 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 1, 0) */ |
---|
526 | 566 | |
---|
527 | 567 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)) |
---|
528 | 568 | /* struct packet_type redefined in 2.6.x */ |
---|
529 | 569 | #define af_packet_priv data |
---|
530 | | -#endif |
---|
| 570 | +#endif // endif |
---|
531 | 571 | |
---|
532 | 572 | /* suspend args */ |
---|
533 | 573 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11) |
---|
534 | 574 | #define DRV_SUSPEND_STATE_TYPE pm_message_t |
---|
535 | 575 | #else |
---|
536 | 576 | #define DRV_SUSPEND_STATE_TYPE uint32 |
---|
537 | | -#endif |
---|
| 577 | +#endif // endif |
---|
538 | 578 | |
---|
539 | 579 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19) |
---|
540 | 580 | #define CHECKSUM_HW CHECKSUM_PARTIAL |
---|
541 | | -#endif |
---|
| 581 | +#endif // endif |
---|
542 | 582 | |
---|
543 | 583 | typedef struct { |
---|
544 | 584 | void *parent; /* some external entity that the thread supposed to work for */ |
---|
.. | .. |
---|
549 | 589 | struct semaphore sema; |
---|
550 | 590 | int terminated; |
---|
551 | 591 | struct completion completed; |
---|
| 592 | + int flush_ind; |
---|
| 593 | + struct completion flushed; |
---|
552 | 594 | spinlock_t spinlock; |
---|
553 | 595 | int up_cnt; |
---|
554 | 596 | } tsk_ctl_t; |
---|
555 | | - |
---|
556 | 597 | |
---|
557 | 598 | /* requires tsk_ctl_t tsk argument, the caller's priv data is passed in owner ptr */ |
---|
558 | 599 | /* note this macro assumes there may be only one context waiting on thread's completion */ |
---|
.. | .. |
---|
560 | 601 | #define DBG_THR(x) printk x |
---|
561 | 602 | #else |
---|
562 | 603 | #define DBG_THR(x) |
---|
563 | | -#endif |
---|
| 604 | +#endif // endif |
---|
564 | 605 | |
---|
565 | 606 | static inline bool binary_sema_down(tsk_ctl_t *tsk) |
---|
566 | 607 | { |
---|
.. | .. |
---|
600 | 641 | return sem_up; |
---|
601 | 642 | } |
---|
602 | 643 | |
---|
603 | | -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)) |
---|
| 644 | +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 9, 0)) |
---|
| 645 | +#define SMP_RD_BARRIER_DEPENDS(x) |
---|
| 646 | +#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)) |
---|
604 | 647 | #define SMP_RD_BARRIER_DEPENDS(x) smp_read_barrier_depends(x) |
---|
605 | 648 | #else |
---|
606 | 649 | #define SMP_RD_BARRIER_DEPENDS(x) smp_rmb(x) |
---|
607 | | -#endif |
---|
| 650 | +#endif // endif |
---|
608 | 651 | |
---|
609 | 652 | #define PROC_START(thread_func, owner, tsk_ctl, flags, name) \ |
---|
610 | 653 | { \ |
---|
611 | 654 | sema_init(&((tsk_ctl)->sema), 0); \ |
---|
612 | 655 | init_completion(&((tsk_ctl)->completed)); \ |
---|
| 656 | + init_completion(&((tsk_ctl)->flushed)); \ |
---|
613 | 657 | (tsk_ctl)->parent = owner; \ |
---|
614 | 658 | (tsk_ctl)->proc_name = name; \ |
---|
615 | 659 | (tsk_ctl)->terminated = FALSE; \ |
---|
| 660 | + (tsk_ctl)->flush_ind = FALSE; \ |
---|
| 661 | + (tsk_ctl)->up_cnt = 0; \ |
---|
616 | 662 | (tsk_ctl)->p_task = kthread_run(thread_func, tsk_ctl, (char*)name); \ |
---|
617 | | - (tsk_ctl)->thr_pid = (tsk_ctl)->p_task->pid; \ |
---|
618 | | - spin_lock_init(&((tsk_ctl)->spinlock)); \ |
---|
619 | | - DBG_THR(("%s(): thread:%s:%lx started\n", __FUNCTION__, \ |
---|
620 | | - (tsk_ctl)->proc_name, (tsk_ctl)->thr_pid)); \ |
---|
| 663 | + if (IS_ERR((tsk_ctl)->p_task)) { \ |
---|
| 664 | + (tsk_ctl)->thr_pid = -1; \ |
---|
| 665 | + DBG_THR(("%s(): thread:%s create failed\n", __FUNCTION__, \ |
---|
| 666 | + (tsk_ctl)->proc_name)); \ |
---|
| 667 | + } else { \ |
---|
| 668 | + (tsk_ctl)->thr_pid = (tsk_ctl)->p_task->pid; \ |
---|
| 669 | + spin_lock_init(&((tsk_ctl)->spinlock)); \ |
---|
| 670 | + DBG_THR(("%s(): thread:%s:%lx started\n", __FUNCTION__, \ |
---|
| 671 | + (tsk_ctl)->proc_name, (tsk_ctl)->thr_pid)); \ |
---|
| 672 | + }; \ |
---|
621 | 673 | } |
---|
| 674 | + |
---|
| 675 | +#define PROC_WAIT_TIMEOUT_MSEC 5000 /* 5 seconds */ |
---|
622 | 676 | |
---|
623 | 677 | #define PROC_STOP(tsk_ctl) \ |
---|
624 | 678 | { \ |
---|
| 679 | + uint timeout = (uint)msecs_to_jiffies(PROC_WAIT_TIMEOUT_MSEC); \ |
---|
625 | 680 | (tsk_ctl)->terminated = TRUE; \ |
---|
626 | 681 | smp_wmb(); \ |
---|
627 | 682 | up(&((tsk_ctl)->sema)); \ |
---|
628 | | - wait_for_completion(&((tsk_ctl)->completed)); \ |
---|
629 | | - DBG_THR(("%s(): thread:%s:%lx terminated OK\n", __FUNCTION__, \ |
---|
| 683 | + DBG_THR(("%s(): thread:%s:%lx wait for terminate\n", __FUNCTION__, \ |
---|
630 | 684 | (tsk_ctl)->proc_name, (tsk_ctl)->thr_pid)); \ |
---|
| 685 | + timeout = (uint)wait_for_completion_timeout(&((tsk_ctl)->completed), timeout); \ |
---|
| 686 | + if (timeout == 0) \ |
---|
| 687 | + DBG_THR(("%s(): thread:%s:%lx terminate timeout\n", __FUNCTION__, \ |
---|
| 688 | + (tsk_ctl)->proc_name, (tsk_ctl)->thr_pid)); \ |
---|
| 689 | + else \ |
---|
| 690 | + DBG_THR(("%s(): thread:%s:%lx terminated OK\n", __FUNCTION__, \ |
---|
| 691 | + (tsk_ctl)->proc_name, (tsk_ctl)->thr_pid)); \ |
---|
| 692 | + (tsk_ctl)->parent = NULL; \ |
---|
| 693 | + (tsk_ctl)->proc_name = NULL; \ |
---|
631 | 694 | (tsk_ctl)->thr_pid = -1; \ |
---|
| 695 | + (tsk_ctl)->up_cnt = 0; \ |
---|
| 696 | +} |
---|
| 697 | + |
---|
| 698 | +#define PROC_STOP_USING_BINARY_SEMA(tsk_ctl) \ |
---|
| 699 | +{ \ |
---|
| 700 | + uint timeout = (uint)msecs_to_jiffies(PROC_WAIT_TIMEOUT_MSEC); \ |
---|
| 701 | + (tsk_ctl)->terminated = TRUE; \ |
---|
| 702 | + smp_wmb(); \ |
---|
| 703 | + binary_sema_up(tsk_ctl); \ |
---|
| 704 | + DBG_THR(("%s(): thread:%s:%lx wait for terminate\n", __FUNCTION__, \ |
---|
| 705 | + (tsk_ctl)->proc_name, (tsk_ctl)->thr_pid)); \ |
---|
| 706 | + timeout = (uint)wait_for_completion_timeout(&((tsk_ctl)->completed), timeout); \ |
---|
| 707 | + if (timeout == 0) \ |
---|
| 708 | + DBG_THR(("%s(): thread:%s:%lx terminate timeout\n", __FUNCTION__, \ |
---|
| 709 | + (tsk_ctl)->proc_name, (tsk_ctl)->thr_pid)); \ |
---|
| 710 | + else \ |
---|
| 711 | + DBG_THR(("%s(): thread:%s:%lx terminated OK\n", __FUNCTION__, \ |
---|
| 712 | + (tsk_ctl)->proc_name, (tsk_ctl)->thr_pid)); \ |
---|
| 713 | + (tsk_ctl)->parent = NULL; \ |
---|
| 714 | + (tsk_ctl)->proc_name = NULL; \ |
---|
| 715 | + (tsk_ctl)->thr_pid = -1; \ |
---|
| 716 | +} |
---|
| 717 | + |
---|
| 718 | +/* |
---|
| 719 | +* Flush is non-rentrant, so callers must make sure |
---|
| 720 | +* there is no race condition. |
---|
| 721 | +* For safer exit, added wait_for_completion_timeout |
---|
| 722 | +* with 1 sec timeout. |
---|
| 723 | +*/ |
---|
| 724 | +#define PROC_FLUSH_USING_BINARY_SEMA(tsk_ctl) \ |
---|
| 725 | +{ \ |
---|
| 726 | + uint timeout = (uint)msecs_to_jiffies(PROC_WAIT_TIMEOUT_MSEC); \ |
---|
| 727 | + (tsk_ctl)->flush_ind = TRUE; \ |
---|
| 728 | + smp_wmb(); \ |
---|
| 729 | + binary_sema_up(tsk_ctl); \ |
---|
| 730 | + DBG_THR(("%s(): thread:%s:%lx wait for flush\n", __FUNCTION__, \ |
---|
| 731 | + (tsk_ctl)->proc_name, (tsk_ctl)->thr_pid)); \ |
---|
| 732 | + timeout = (uint)wait_for_completion_timeout(&((tsk_ctl)->flushed), timeout); \ |
---|
| 733 | + if (timeout == 0) \ |
---|
| 734 | + DBG_THR(("%s(): thread:%s:%lx flush timeout\n", __FUNCTION__, \ |
---|
| 735 | + (tsk_ctl)->proc_name, (tsk_ctl)->thr_pid)); \ |
---|
| 736 | + else \ |
---|
| 737 | + DBG_THR(("%s(): thread:%s:%lx flushed OK\n", __FUNCTION__, \ |
---|
| 738 | + (tsk_ctl)->proc_name, (tsk_ctl)->thr_pid)); \ |
---|
632 | 739 | } |
---|
633 | 740 | |
---|
634 | 741 | /* ----------------------- */ |
---|
635 | 742 | |
---|
636 | 743 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)) |
---|
| 744 | +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0) |
---|
| 745 | +/* send_sig declaration moved */ |
---|
| 746 | +#include <linux/sched/signal.h> |
---|
| 747 | +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0) */ |
---|
| 748 | + |
---|
637 | 749 | #define KILL_PROC(nr, sig) \ |
---|
638 | 750 | { \ |
---|
639 | 751 | struct task_struct *tsk; \ |
---|
.. | .. |
---|
656 | 768 | { \ |
---|
657 | 769 | kill_proc(pid, sig, 1); \ |
---|
658 | 770 | } |
---|
659 | | -#endif |
---|
| 771 | +#endif // endif |
---|
660 | 772 | #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31) */ |
---|
661 | 773 | |
---|
662 | 774 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)) |
---|
.. | .. |
---|
708 | 820 | #define DEV_PRIV(dev) (dev->priv) |
---|
709 | 821 | #else |
---|
710 | 822 | #define DEV_PRIV(dev) netdev_priv(dev) |
---|
711 | | -#endif |
---|
| 823 | +#endif // endif |
---|
712 | 824 | |
---|
713 | 825 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20) |
---|
714 | 826 | #define WL_ISR(i, d, p) wl_isr((i), (d)) |
---|
.. | .. |
---|
724 | 836 | #define CAN_SLEEP() ((!in_atomic() && !irqs_disabled())) |
---|
725 | 837 | #else |
---|
726 | 838 | #define CAN_SLEEP() (FALSE) |
---|
727 | | -#endif |
---|
| 839 | +#endif // endif |
---|
728 | 840 | |
---|
729 | 841 | #define KMALLOC_FLAG (CAN_SLEEP() ? GFP_KERNEL: GFP_ATOMIC) |
---|
730 | 842 | |
---|
731 | 843 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0)) |
---|
732 | 844 | #define RANDOM32 prandom_u32 |
---|
| 845 | +#define RANDOM_BYTES prandom_bytes |
---|
733 | 846 | #else |
---|
734 | 847 | #define RANDOM32 random32 |
---|
| 848 | +#define RANDOM_BYTES get_random_bytes |
---|
735 | 849 | #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) */ |
---|
736 | 850 | |
---|
737 | 851 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0)) |
---|
.. | .. |
---|
744 | 858 | * Overide latest kfifo functions with |
---|
745 | 859 | * older version to work on older kernels |
---|
746 | 860 | */ |
---|
747 | | -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)) |
---|
| 861 | +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)) && !defined(WL_COMPAT_WIRELESS) |
---|
748 | 862 | #define kfifo_in_spinlocked(a, b, c, d) kfifo_put(a, (u8 *)b, c) |
---|
749 | 863 | #define kfifo_out_spinlocked(a, b, c, d) kfifo_get(a, (u8 *)b, c) |
---|
750 | 864 | #define kfifo_esize(a) 1 |
---|
.. | .. |
---|
757 | 871 | |
---|
758 | 872 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) |
---|
759 | 873 | #pragma GCC diagnostic pop |
---|
760 | | -#endif |
---|
| 874 | +#endif // endif |
---|
| 875 | + |
---|
| 876 | +#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0)) |
---|
| 877 | +static inline struct inode *file_inode(const struct file *f) |
---|
| 878 | +{ |
---|
| 879 | + return f->f_dentry->d_inode; |
---|
| 880 | +} |
---|
| 881 | +#endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0)) */ |
---|
| 882 | + |
---|
| 883 | +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0) |
---|
| 884 | +#define vfs_write(fp, buf, len, pos) kernel_write(fp, buf, len, pos) |
---|
| 885 | +#define vfs_read(fp, buf, len, pos) kernel_read(fp, buf, len, pos) |
---|
| 886 | +int kernel_read_compat(struct file *file, loff_t offset, char *addr, unsigned long count); |
---|
| 887 | +#else /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0) */ |
---|
| 888 | +#define kernel_read_compat(file, offset, addr, count) kernel_read(file, offset, addr, count) |
---|
| 889 | +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0) */ |
---|
| 890 | + |
---|
| 891 | +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0) |
---|
| 892 | +#define timespec64 timespec |
---|
| 893 | +#define ktime_get_real_ts64(timespec) ktime_get_real_ts(timespec) |
---|
| 894 | +#define ktime_to_timespec64(timespec) ktime_to_timespec(timespec) |
---|
| 895 | +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0) */ |
---|
| 896 | + |
---|
| 897 | +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0) |
---|
| 898 | +#define rtc_time_to_tm(time, tm) rtc_time64_to_tm(time, tm) |
---|
| 899 | +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(5, 6, 0) */ |
---|
761 | 900 | |
---|
762 | 901 | #endif /* _linuxver_h_ */ |
---|