Merge branch 'trivial' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild-2.6
[pandora-kernel.git] / drivers / staging / rtl8712 / osdep_service.h
1 #ifndef __OSDEP_SERVICE_H_
2 #define __OSDEP_SERVICE_H_
3
4 #define _SUCCESS        1
5 #define _FAIL           0
6
7 #include "basic_types.h"
8 #include <linux/version.h>
9 #include <linux/spinlock.h>
10
11 #include <linux/semaphore.h>
12 #include <linux/sem.h>
13 #include <linux/netdevice.h>
14 #include <linux/etherdevice.h>
15 #include <net/iw_handler.h>
16 #include <linux/proc_fs.h>      /* Necessary because we use the proc fs */
17 #include <linux/compiler.h>
18 #include <linux/kernel.h>
19 #include <linux/errno.h>
20 #include <linux/init.h>
21 #include <linux/slab.h>
22 #include <linux/module.h>
23 #include <linux/sched.h>
24 #include <linux/kref.h>
25 #include <linux/netdevice.h>
26 #include <linux/skbuff.h>
27 #include <linux/usb.h>
28 #include <linux/usb/ch9.h>
29 #include <linux/io.h>
30 #include <linux/circ_buf.h>
31 #include <linux/uaccess.h>
32 #include <asm/byteorder.h>
33 #include <asm/atomic.h>
34 #include <linux/wireless.h>
35 #include <linux/rtnetlink.h>
36 #include "ethernet.h"
37 #include <linux/if_arp.h>
38 #include <linux/firmware.h>
39 #define   _usb_alloc_urb(x, y)       usb_alloc_urb(x, y)
40 #define   _usb_submit_urb(x, y)     usb_submit_urb(x, y)
41
42 struct  __queue {
43         struct  list_head       queue;
44         spinlock_t lock;
45 };
46
47 #define _pkt struct sk_buff
48 #define _buffer unsigned char
49 #define thread_exit() complete_and_exit(NULL, 0)
50 #define _workitem struct work_struct
51 #define MSECS(t)        (HZ * ((t) / 1000) + (HZ * ((t) % 1000)) / 1000)
52
53 #define _init_queue(pqueue)                             \
54         do {                                            \
55                 _init_listhead(&((pqueue)->queue));     \
56                 spin_lock_init(&((pqueue)->lock));      \
57         } while (0)
58
59 static inline void *_netdev_priv(struct net_device *dev)
60 {
61         return netdev_priv(dev);
62 }
63
64 static inline void os_free_netdev(struct net_device *dev)
65 {
66         free_netdev(dev);
67 }
68
69 static inline struct list_head *get_next(struct list_head *list)
70 {
71         return list->next;
72 }
73
74 static inline struct list_head *get_list_head(struct  __queue *queue)
75 {
76         return &(queue->queue);
77 }
78
79 #define LIST_CONTAINOR(ptr, type, member) \
80         ((type *)((char *)(ptr)-(SIZE_T)(&((type *)0)->member)))
81
82 static inline void _enter_hwio_critical(struct semaphore *prwlock,
83                                         unsigned long *pirqL)
84 {
85         down(prwlock);
86 }
87
88 static inline void _exit_hwio_critical(struct semaphore *prwlock,
89                                        unsigned long *pirqL)
90 {
91         up(prwlock);
92 }
93
94 static inline void list_delete(struct list_head *plist)
95 {
96         list_del_init(plist);
97 }
98
99 static inline void _init_timer(struct timer_list *ptimer,
100                                struct  net_device *padapter,
101                                void *pfunc, void *cntx)
102 {
103         ptimer->function = pfunc;
104         ptimer->data = (addr_t)cntx;
105         init_timer(ptimer);
106 }
107
108 static inline void _set_timer(struct timer_list *ptimer, u32 delay_time)
109 {
110         mod_timer(ptimer, (jiffies+(delay_time*HZ/1000)));
111 }
112
113 static inline void _cancel_timer(struct timer_list *ptimer, u8 *bcancelled)
114 {
115         del_timer(ptimer);
116         *bcancelled = true; /*true ==1; false==0*/
117 }
118
119 static inline void _init_workitem(_workitem *pwork, void *pfunc, void *cntx)
120 {
121         INIT_WORK(pwork, pfunc);
122 }
123
124 static inline void _set_workitem(_workitem *pwork)
125 {
126         schedule_work(pwork);
127 }
128
129 #include "rtl871x_byteorder.h"
130
131 #ifndef BIT
132         #define BIT(x)  (1 << (x))
133 #endif
134
135 /*
136 For the following list_xxx operations,
137 caller must guarantee the atomic context.
138 Otherwise, there will be racing condition.
139 */
140 static inline u32 is_list_empty(struct list_head *phead)
141 {
142         if (list_empty(phead))
143                 return true;
144         else
145                 return false;
146 }
147
148 static inline void list_insert_tail(struct list_head *plist,
149                                     struct list_head *phead)
150 {
151         list_add_tail(plist, phead);
152 }
153
154 static inline u32 _down_sema(struct semaphore *sema)
155 {
156         if (down_interruptible(sema))
157                 return _FAIL;
158         else
159                 return _SUCCESS;
160 }
161
162 static inline void _rtl_rwlock_init(struct semaphore *prwlock)
163 {
164         sema_init(prwlock, 1);
165 }
166
167 static inline void _init_listhead(struct list_head *list)
168 {
169         INIT_LIST_HEAD(list);
170 }
171
172 static inline u32 _queue_empty(struct  __queue *pqueue)
173 {
174         return is_list_empty(&(pqueue->queue));
175 }
176
177 static inline u32 end_of_queue_search(struct list_head *head, struct list_head *plist)
178 {
179         if (head == plist)
180                 return true;
181         else
182                 return false;
183 }
184
185 static inline void sleep_schedulable(int ms)
186 {
187         u32 delta;
188
189         delta = (ms * HZ) / 1000;/*(ms)*/
190         if (delta == 0)
191                 delta = 1;/* 1 ms */
192         set_current_state(TASK_INTERRUPTIBLE);
193         if (schedule_timeout(delta) != 0)
194                 return ;
195 }
196
197 static inline u8 *_malloc(u32 sz)
198 {
199         return  kmalloc(sz, GFP_ATOMIC);
200 }
201
202 static inline unsigned char _cancel_timer_ex(struct timer_list *ptimer)
203 {
204         return del_timer(ptimer);
205 }
206
207 static inline void thread_enter(void *context)
208 {
209         daemonize("%s", "RTKTHREAD");
210         allow_signal(SIGTERM);
211 }
212
213 static inline void flush_signals_thread(void)
214 {
215         if (signal_pending(current))
216                 flush_signals(current);
217 }
218
219 static inline u32 _RND8(u32 sz)
220 {
221         return ((sz >> 3) + ((sz & 7) ? 1 : 0)) << 3;
222 }
223
224 static inline u32 _RND128(u32 sz)
225 {
226         return ((sz >> 7) + ((sz & 127) ? 1 : 0)) << 7;
227 }
228
229 static inline u32 _RND256(u32 sz)
230 {
231         return ((sz >> 8) + ((sz & 255) ? 1 : 0)) << 8;
232 }
233
234 static inline u32 _RND512(u32 sz)
235 {
236         return ((sz >> 9) + ((sz & 511) ? 1 : 0)) << 9;
237 }
238
239 #define STRUCT_PACKED __attribute__ ((packed))
240
241 #endif
242