/drivers/net/wireless/bcmdhd/include/linuxver.h

https://bitbucket.org/slukk/jb-tsm-kernel-4.2 · C Header · 614 lines · 476 code · 112 blank · 26 comment · 37 complexity · bce1a5c476978be7018b8fe914374d67 MD5 · raw file

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