upload tizen1.0 source
[kernel/linux-2.6.36.git] / drivers / net / wireless / bcm4330 / src / include / linuxver.h
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,v 13.53.2.2 2010-12-22 23:47:26 $
26  */
27
28 #ifndef _linuxver_h_
29 #define _linuxver_h_
30
31 #include <linux/version.h>
32 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
33 #include <linux/config.h>
34 #else
35 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33))
36 #include <generated/autoconf.h>
37 #else
38 #include <linux/autoconf.h>
39 #endif
40 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)) */
41 #include <linux/module.h>
42
43 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0))
44 /* __NO_VERSION__ must be defined for all linkables except one in 2.2 */
45 #ifdef __UNDEF_NO_VERSION__
46 #undef __NO_VERSION__
47 #else
48 #define __NO_VERSION__
49 #endif
50 #endif  /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0) */
51
52 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0)
53 #define module_param(_name_, _type_, _perm_)    MODULE_PARM(_name_, "i")
54 #define module_param_string(_name_, _string_, _size_, _perm_) \
55                 MODULE_PARM(_string_, "c" __MODULE_STRING(_size_))
56 #endif
57
58 /* linux/malloc.h is deprecated, use linux/slab.h instead. */
59 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 9))
60 #include <linux/malloc.h>
61 #else
62 #include <linux/slab.h>
63 #endif
64
65 #include <linux/types.h>
66 #include <linux/init.h>
67 #include <linux/mm.h>
68 #include <linux/string.h>
69 #include <linux/pci.h>
70 #include <linux/interrupt.h>
71 #include <linux/netdevice.h>
72 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
73 #undef IP_TOS
74 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28)) */
75 #include <asm/io.h>
76
77 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 41))
78 #include <linux/workqueue.h>
79 #else
80 #include <linux/tqueue.h>
81 #ifndef work_struct
82 #define work_struct tq_struct
83 #endif
84 #ifndef INIT_WORK
85 #define INIT_WORK(_work, _func, _data) INIT_TQUEUE((_work), (_func), (_data))
86 #endif
87 #ifndef schedule_work
88 #define schedule_work(_work) schedule_task((_work))
89 #endif
90 #ifndef flush_scheduled_work
91 #define flush_scheduled_work() flush_scheduled_tasks()
92 #endif
93 #endif  /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 41) */
94
95 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
96 #define MY_INIT_WORK(_work, _func)      INIT_WORK(_work, _func)
97 #else
98 #define MY_INIT_WORK(_work, _func)      INIT_WORK(_work, _func, _work)
99 typedef void (*work_func_t)(void *work);
100 #endif  /* >= 2.6.20 */
101
102 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
103 /* Some distributions have their own 2.6.x compatibility layers */
104 #ifndef IRQ_NONE
105 typedef void irqreturn_t;
106 #define IRQ_NONE
107 #define IRQ_HANDLED
108 #define IRQ_RETVAL(x)
109 #endif
110 #else
111 typedef irqreturn_t(*FN_ISR) (int irq, void *dev_id, struct pt_regs *ptregs);
112 #endif  /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) */
113
114 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
115 #define IRQF_SHARED     SA_SHIRQ
116 #endif /* < 2.6.18 */
117
118 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 17)
119 #ifdef  CONFIG_NET_RADIO
120 #define CONFIG_WIRELESS_EXT
121 #endif
122 #endif  /* < 2.6.17 */
123
124 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 67)
125 #define MOD_INC_USE_COUNT
126 #define MOD_DEC_USE_COUNT
127 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 67) */
128
129 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32)
130 #include <linux/sched.h>
131 #endif
132
133 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)
134 #include <net/lib80211.h>
135 #endif
136 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30)
137 #include <linux/ieee80211.h>
138 #else
139 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 14)
140 #include <net/ieee80211.h>
141 #endif
142 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30) */
143
144
145 #ifndef __exit
146 #define __exit
147 #endif
148 #ifndef __devexit
149 #define __devexit
150 #endif
151 #ifndef __devinit
152 #define __devinit       __init
153 #endif
154 #ifndef __devinitdata
155 #define __devinitdata
156 #endif
157 #ifndef __devexit_p
158 #define __devexit_p(x)  x
159 #endif
160
161 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0))
162
163 #define pci_get_drvdata(dev)            (dev)->sysdata
164 #define pci_set_drvdata(dev, value)     (dev)->sysdata = (value)
165
166 /*
167  * New-style (2.4.x) PCI/hot-pluggable PCI/CardBus registration
168  */
169
170 struct pci_device_id {
171         unsigned int vendor, device;            /* Vendor and device ID or PCI_ANY_ID */
172         unsigned int subvendor, subdevice;      /* Subsystem ID's or PCI_ANY_ID */
173         unsigned int class, class_mask;         /* (class,subclass,prog-if) triplet */
174         unsigned long driver_data;              /* Data private to the driver */
175 };
176
177 struct pci_driver {
178         struct list_head node;
179         char *name;
180         const struct pci_device_id *id_table;   /* NULL if wants all devices */
181         int (*probe)(struct pci_dev *dev,
182                      const struct pci_device_id *id); /* New device inserted */
183         void (*remove)(struct pci_dev *dev);    /* Device removed (NULL if not a hot-plug
184                                                  * capable driver)
185                                                  */
186         void (*suspend)(struct pci_dev *dev);   /* Device suspended */
187         void (*resume)(struct pci_dev *dev);    /* Device woken up */
188 };
189
190 #define MODULE_DEVICE_TABLE(type, name)
191 #define PCI_ANY_ID (~0)
192
193 /* compatpci.c */
194 #define pci_module_init pci_register_driver
195 extern int pci_register_driver(struct pci_driver *drv);
196 extern void pci_unregister_driver(struct pci_driver *drv);
197
198 #endif /* PCI registration */
199
200 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18))
201 #define pci_module_init pci_register_driver
202 #endif
203
204 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 18))
205 #ifdef MODULE
206 #define module_init(x) int init_module(void) { return x(); }
207 #define module_exit(x) void cleanup_module(void) { x(); }
208 #else
209 #define module_init(x)  __initcall(x);
210 #define module_exit(x)  __exitcall(x);
211 #endif
212 #endif  /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 18) */
213
214 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)
215 #define WL_USE_NETDEV_OPS
216 #else
217 #undef WL_USE_NETDEV_OPS
218 #endif
219
220 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31)) && defined(CONFIG_RFKILL_INPUT)
221 #define WL_CONFIG_RFKILL_INPUT
222 #else
223 #undef WL_CONFIG_RFKILL_INPUT
224 #endif
225
226 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 48))
227 #define list_for_each(pos, head) \
228         for (pos = (head)->next; pos != (head); pos = pos->next)
229 #endif
230
231 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 13))
232 #define pci_resource_start(dev, bar)    ((dev)->base_address[(bar)])
233 #elif (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 44))
234 #define pci_resource_start(dev, bar)    ((dev)->resource[(bar)].start)
235 #endif
236
237 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 23))
238 #define pci_enable_device(dev) do { } while (0)
239 #endif
240
241 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 14))
242 #define net_device device
243 #endif
244
245 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 42))
246
247 /*
248  * DMA mapping
249  *
250  * See linux/Documentation/DMA-mapping.txt
251  */
252
253 #ifndef PCI_DMA_TODEVICE
254 #define PCI_DMA_TODEVICE        1
255 #define PCI_DMA_FROMDEVICE      2
256 #endif
257
258 typedef u32 dma_addr_t;
259
260 /* Pure 2^n version of get_order */
261 static inline int get_order(unsigned long size)
262 {
263         int order;
264
265         size = (size-1) >> (PAGE_SHIFT-1);
266         order = -1;
267         do {
268                 size >>= 1;
269                 order++;
270         } while (size);
271         return order;
272 }
273
274 static inline void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
275                                          dma_addr_t *dma_handle)
276 {
277         void *ret;
278         int gfp = GFP_ATOMIC | GFP_DMA;
279
280         ret = (void *)__get_free_pages(gfp, get_order(size));
281
282         if (ret != NULL) {
283                 memset(ret, 0, size);
284                 *dma_handle = virt_to_bus(ret);
285         }
286         return ret;
287 }
288 static inline void pci_free_consistent(struct pci_dev *hwdev, size_t size,
289                                        void *vaddr, dma_addr_t dma_handle)
290 {
291         free_pages((unsigned long)vaddr, get_order(size));
292 }
293 #define pci_map_single(cookie, address, size, dir)      virt_to_bus(address)
294 #define pci_unmap_single(cookie, address, size, dir)
295
296 #endif /* DMA mapping */
297
298 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 43))
299
300 #define dev_kfree_skb_any(a)            dev_kfree_skb(a)
301 #define netif_down(dev)                 do { (dev)->start = 0; } while (0)
302
303 /* pcmcia-cs provides its own netdevice compatibility layer */
304 #ifndef _COMPAT_NETDEVICE_H
305
306 /*
307  * SoftNet
308  *
309  * For pre-softnet kernels we need to tell the upper layer not to
310  * re-enter start_xmit() while we are in there. However softnet
311  * guarantees not to enter while we are in there so there is no need
312  * to do the netif_stop_queue() dance unless the transmit queue really
313  * gets stuck. This should also improve performance according to tests
314  * done by Aman Singla.
315  */
316
317 #define dev_kfree_skb_irq(a)    dev_kfree_skb(a)
318 #define netif_wake_queue(dev) \
319                 do { clear_bit(0, &(dev)->tbusy); mark_bh(NET_BH); } while (0)
320 #define netif_stop_queue(dev)   set_bit(0, &(dev)->tbusy)
321
322 static inline void netif_start_queue(struct net_device *dev)
323 {
324         dev->tbusy = 0;
325         dev->interrupt = 0;
326         dev->start = 1;
327 }
328
329 #define netif_queue_stopped(dev)        (dev)->tbusy
330 #define netif_running(dev)              (dev)->start
331
332 #endif /* _COMPAT_NETDEVICE_H */
333
334 #define netif_device_attach(dev)        netif_start_queue(dev)
335 #define netif_device_detach(dev)        netif_stop_queue(dev)
336
337 /* 2.4.x renamed bottom halves to tasklets */
338 #define tasklet_struct                          tq_struct
339 static inline void tasklet_schedule(struct tasklet_struct *tasklet)
340 {
341         queue_task(tasklet, &tq_immediate);
342         mark_bh(IMMEDIATE_BH);
343 }
344
345 static inline void tasklet_init(struct tasklet_struct *tasklet,
346                                 void (*func)(unsigned long),
347                                 unsigned long data)
348 {
349         tasklet->next = NULL;
350         tasklet->sync = 0;
351         tasklet->routine = (void (*)(void *))func;
352         tasklet->data = (void *)data;
353 }
354 #define tasklet_kill(tasklet)   { do {} while (0); }
355
356 /* 2.4.x introduced del_timer_sync() */
357 #define del_timer_sync(timer) del_timer(timer)
358
359 #else
360
361 #define netif_down(dev)
362
363 #endif /* SoftNet */
364
365 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 3))
366
367 /*
368  * Emit code to initialise a tq_struct's routine and data pointers
369  */
370 #define PREPARE_TQUEUE(_tq, _routine, _data)                    \
371         do {                                                    \
372                 (_tq)->routine = _routine;                      \
373                 (_tq)->data = _data;                            \
374         } while (0)
375
376 /*
377  * Emit code to initialise all of a tq_struct
378  */
379 #define INIT_TQUEUE(_tq, _routine, _data)                       \
380         do {                                                    \
381                 INIT_LIST_HEAD(&(_tq)->list);                   \
382                 (_tq)->sync = 0;                                \
383                 PREPARE_TQUEUE((_tq), (_routine), (_data));     \
384         } while (0)
385
386 #endif  /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 3) */
387
388 /* Power management related macro & routines */
389 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 9)
390 #define PCI_SAVE_STATE(a, b)    pci_save_state(a)
391 #define PCI_RESTORE_STATE(a, b) pci_restore_state(a)
392 #else
393 #define PCI_SAVE_STATE(a, b)    pci_save_state(a, b)
394 #define PCI_RESTORE_STATE(a, b) pci_restore_state(a, b)
395 #endif
396
397 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 6))
398 static inline int
399 pci_save_state(struct pci_dev *dev, u32 *buffer)
400 {
401         int i;
402         if (buffer) {
403                 for (i = 0; i < 16; i++)
404                         pci_read_config_dword(dev, i * 4, &buffer[i]);
405         }
406         return 0;
407 }
408
409 static inline int
410 pci_restore_state(struct pci_dev *dev, u32 *buffer)
411 {
412         int i;
413
414         if (buffer) {
415                 for (i = 0; i < 16; i++)
416                         pci_write_config_dword(dev, i * 4, buffer[i]);
417         }
418         /*
419          * otherwise, write the context information we know from bootup.
420          * This works around a problem where warm-booting from Windows
421          * combined with a D3(hot)->D0 transition causes PCI config
422          * header data to be forgotten.
423          */
424         else {
425                 for (i = 0; i < 6; i ++)
426                         pci_write_config_dword(dev,
427                                                PCI_BASE_ADDRESS_0 + (i * 4),
428                                                pci_resource_start(dev, i));
429                 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
430         }
431         return 0;
432 }
433 #endif /* PCI power management */
434
435 /* Old cp0 access macros deprecated in 2.4.19 */
436 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 19))
437 #define read_c0_count() read_32bit_cp0_register(CP0_COUNT)
438 #endif
439
440 /* Module refcount handled internally in 2.6.x */
441 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24))
442 #ifndef SET_MODULE_OWNER
443 #define SET_MODULE_OWNER(dev)           do {} while (0)
444 #define OLD_MOD_INC_USE_COUNT           MOD_INC_USE_COUNT
445 #define OLD_MOD_DEC_USE_COUNT           MOD_DEC_USE_COUNT
446 #else
447 #define OLD_MOD_INC_USE_COUNT           do {} while (0)
448 #define OLD_MOD_DEC_USE_COUNT           do {} while (0)
449 #endif
450 #else /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24) */
451 #ifndef SET_MODULE_OWNER
452 #define SET_MODULE_OWNER(dev)           do {} while (0)
453 #endif
454 #ifndef MOD_INC_USE_COUNT
455 #define MOD_INC_USE_COUNT                       do {} while (0)
456 #endif
457 #ifndef MOD_DEC_USE_COUNT
458 #define MOD_DEC_USE_COUNT                       do {} while (0)
459 #endif
460 #define OLD_MOD_INC_USE_COUNT           MOD_INC_USE_COUNT
461 #define OLD_MOD_DEC_USE_COUNT           MOD_DEC_USE_COUNT
462 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24) */
463
464 #ifndef SET_NETDEV_DEV
465 #define SET_NETDEV_DEV(net, pdev)       do {} while (0)
466 #endif
467
468 #ifndef HAVE_FREE_NETDEV
469 #define free_netdev(dev)                kfree(dev)
470 #endif
471
472 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
473 /* struct packet_type redefined in 2.6.x */
474 #define af_packet_priv                  data
475 #endif
476
477 /* suspend args */
478 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
479 #define DRV_SUSPEND_STATE_TYPE pm_message_t
480 #else
481 #define DRV_SUSPEND_STATE_TYPE uint32
482 #endif
483
484 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
485 #define CHECKSUM_HW     CHECKSUM_PARTIAL
486 #endif
487
488 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
489 #define KILL_PROC(nr, sig) \
490 { \
491 struct task_struct *tsk; \
492 struct pid *pid;    \
493 pid = find_get_pid((pid_t)nr);    \
494 tsk = pid_task(pid, PIDTYPE_PID);    \
495 if (tsk) send_sig(sig, tsk, 1); \
496 }
497 #else
498 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && (LINUX_VERSION_CODE <= \
499         KERNEL_VERSION(2, 6, 30))
500 #define KILL_PROC(pid, sig) \
501 { \
502         struct task_struct *tsk; \
503         tsk = find_task_by_vpid(pid); \
504         if (tsk) send_sig(sig, tsk, 1); \
505 }
506 #else
507 #define KILL_PROC(pid, sig) \
508 { \
509         kill_proc(pid, sig, 1); \
510 }
511 #endif
512 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31) */
513
514 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
515 #include <linux/time.h>
516 #include <linux/wait.h>
517 #else
518 #include <linux/sched.h>
519
520 #define __wait_event_interruptible_timeout(wq, condition, ret)          \
521 do {                                                                    \
522         wait_queue_t __wait;                                            \
523         init_waitqueue_entry(&__wait, current);                         \
524                                                                         \
525         add_wait_queue(&wq, &__wait);                                   \
526         for (;;) {                                                      \
527                 set_current_state(TASK_INTERRUPTIBLE);                  \
528                 if (condition)                                          \
529                         break;                                          \
530                 if (!signal_pending(current)) {                         \
531                         ret = schedule_timeout(ret);                    \
532                         if (!ret)                                       \
533                                 break;                                  \
534                         continue;                                       \
535                 }                                                       \
536                 ret = -ERESTARTSYS;                                     \
537                 break;                                                  \
538         }                                                               \
539         current->state = TASK_RUNNING;                                  \
540         remove_wait_queue(&wq, &__wait);                                \
541 } while (0)
542
543 #define wait_event_interruptible_timeout(wq, condition, timeout)        \
544 ({                                                                      \
545         long __ret = timeout;                                           \
546         if (!(condition))                                               \
547                 __wait_event_interruptible_timeout(wq, condition, __ret); \
548         __ret;                                                          \
549 })
550
551 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)) */
552
553 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)
554 #define WL_DEV_IF(dev)          ((wl_if_t*)netdev_priv(dev))
555 #else
556 #define WL_DEV_IF(dev)          ((wl_if_t*)(dev)->priv)
557 #endif
558
559 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20)
560 #define WL_ISR(i, d, p)         wl_isr((i), (d))
561 #else
562 #define WL_ISR(i, d, p)         wl_isr((i), (d), (p))
563 #endif  /* < 2.6.20 */
564
565 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
566 #define netdev_priv(dev) dev->priv
567 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)) */
568
569 #endif /* _linuxver_h_ */