locks: remove fl_copy_lock lock_manager operation
[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/smp_lock.h>
26 #include <linux/netdevice.h>
27 #include <linux/skbuff.h>
28 #include <linux/usb.h>
29 #include <linux/usb/ch9.h>
30 #include <linux/io.h>
31 #include <linux/circ_buf.h>
32 #include <linux/uaccess.h>
33 #include <asm/byteorder.h>
34 #include <asm/atomic.h>
35 #include <linux/wireless.h>
36 #include <linux/rtnetlink.h>
37 #include "ethernet.h"
38 #include <linux/if_arp.h>
39 #include <linux/firmware.h>
40 #define   _usb_alloc_urb(x, y)       usb_alloc_urb(x, y)
41 #define   _usb_submit_urb(x, y)     usb_submit_urb(x, y)
42
43 struct  __queue {
44         struct  list_head       queue;
45         spinlock_t lock;
46 };
47
48 #define _pkt struct sk_buff
49 #define _buffer unsigned char
50 #define thread_exit() complete_and_exit(NULL, 0)
51 #define _workitem struct work_struct
52 #define MSECS(t)        (HZ * ((t) / 1000) + (HZ * ((t) % 1000)) / 1000)
53
54 #define _init_queue(pqueue)                             \
55         do {                                            \
56                 _init_listhead(&((pqueue)->queue));     \
57                 spin_lock_init(&((pqueue)->lock));      \
58         } while (0)
59
60 static inline void *_netdev_priv(struct net_device *dev)
61 {
62         return netdev_priv(dev);
63 }
64
65 static inline void os_free_netdev(struct net_device *dev)
66 {
67         free_netdev(dev);
68 }
69
70 static inline struct list_head *get_next(struct list_head *list)
71 {
72         return list->next;
73 }
74
75 static inline struct list_head *get_list_head(struct  __queue *queue)
76 {
77         return &(queue->queue);
78 }
79
80 #define LIST_CONTAINOR(ptr, type, member) \
81         ((type *)((char *)(ptr)-(SIZE_T)(&((type *)0)->member)))
82
83 static inline void _enter_hwio_critical(struct semaphore *prwlock,
84                                         unsigned long *pirqL)
85 {
86         down(prwlock);
87 }
88
89 static inline void _exit_hwio_critical(struct semaphore *prwlock,
90                                        unsigned long *pirqL)
91 {
92         up(prwlock);
93 }
94
95 static inline void list_delete(struct list_head *plist)
96 {
97         list_del_init(plist);
98 }
99
100 static inline void _init_timer(struct timer_list *ptimer,
101                                struct  net_device *padapter,
102                                void *pfunc, void *cntx)
103 {
104         ptimer->function = pfunc;
105         ptimer->data = (addr_t)cntx;
106         init_timer(ptimer);
107 }
108
109 static inline void _set_timer(struct timer_list *ptimer, u32 delay_time)
110 {
111         mod_timer(ptimer, (jiffies+(delay_time*HZ/1000)));
112 }
113
114 static inline void _cancel_timer(struct timer_list *ptimer, u8 *bcancelled)
115 {
116         del_timer(ptimer);
117         *bcancelled = true; /*true ==1; false==0*/
118 }
119
120 static inline void _init_workitem(_workitem *pwork, void *pfunc, void *cntx)
121 {
122         INIT_WORK(pwork, pfunc);
123 }
124
125 static inline void _set_workitem(_workitem *pwork)
126 {
127         schedule_work(pwork);
128 }
129
130 #include "rtl871x_byteorder.h"
131
132 #ifndef BIT
133         #define BIT(x)  (1 << (x))
134 #endif
135
136 /*
137 For the following list_xxx operations,
138 caller must guarantee the atomic context.
139 Otherwise, there will be racing condition.
140 */
141 static inline u32 is_list_empty(struct list_head *phead)
142 {
143         if (list_empty(phead))
144                 return true;
145         else
146                 return false;
147 }
148
149 static inline void list_insert_tail(struct list_head *plist, 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         init_MUTEX(prwlock);
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         u8 *pbuf;
200
201         pbuf =  kmalloc(sz, GFP_ATOMIC);
202         return pbuf;
203 }
204
205 static inline unsigned char _cancel_timer_ex(struct timer_list *ptimer)
206 {
207         return del_timer(ptimer);
208 }
209
210 static inline void thread_enter(void *context)
211 {
212         daemonize("%s", "RTKTHREAD");
213         allow_signal(SIGTERM);
214 }
215
216 static inline void flush_signals_thread(void)
217 {
218         if (signal_pending(current))
219                 flush_signals(current);
220 }
221
222 static inline u32 _RND8(u32 sz)
223 {
224         u32     val;
225
226         val = ((sz >> 3) + ((sz & 7) ? 1 : 0)) << 3;
227         return val;
228 }
229
230 static inline u32 _RND128(u32 sz)
231 {
232         u32     val;
233
234         val = ((sz >> 7) + ((sz & 127) ? 1 : 0)) << 7;
235         return val;
236 }
237
238 static inline u32 _RND256(u32 sz)
239 {
240         u32     val;
241
242         val = ((sz >> 8) + ((sz & 255) ? 1 : 0)) << 8;
243         return val;
244 }
245
246 static inline u32 _RND512(u32 sz)
247 {
248         u32     val;
249
250         val = ((sz >> 9) + ((sz & 511) ? 1 : 0)) << 9;
251         return val;
252 }
253
254 #define STRUCT_PACKED __attribute__ ((packed))
255
256 #endif
257