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