Merge branch 'upstream' of git://git.linux-mips.org/pub/scm/upstream-linus
[linux-btrfs-devel.git] / drivers / staging / rtl8712 / osdep_service.h
blobc683d7609e6c7063f546a5941c770b0cfb6fafed
1 #ifndef __OSDEP_SERVICE_H_
2 #define __OSDEP_SERVICE_H_
4 #define _SUCCESS 1
5 #define _FAIL 0
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)
39 struct __queue {
40 struct list_head queue;
41 spinlock_t lock;
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)
50 #define _init_queue(pqueue) \
51 do { \
52 _init_listhead(&((pqueue)->queue)); \
53 spin_lock_init(&((pqueue)->lock)); \
54 } while (0)
56 static inline void *_netdev_priv(struct net_device *dev)
58 return netdev_priv(dev);
61 static inline void os_free_netdev(struct net_device *dev)
63 free_netdev(dev);
66 static inline struct list_head *get_next(struct list_head *list)
68 return list->next;
71 static inline struct list_head *get_list_head(struct __queue *queue)
73 return &(queue->queue);
76 #define LIST_CONTAINOR(ptr, type, member) \
77 ((type *)((char *)(ptr)-(SIZE_T)(&((type *)0)->member)))
79 static inline void _enter_hwio_critical(struct semaphore *prwlock,
80 unsigned long *pirqL)
82 down(prwlock);
85 static inline void _exit_hwio_critical(struct semaphore *prwlock,
86 unsigned long *pirqL)
88 up(prwlock);
91 static inline void list_delete(struct list_head *plist)
93 list_del_init(plist);
96 static inline void _init_timer(struct timer_list *ptimer,
97 struct net_device *padapter,
98 void *pfunc, void *cntx)
100 ptimer->function = pfunc;
101 ptimer->data = (addr_t)cntx;
102 init_timer(ptimer);
105 static inline void _set_timer(struct timer_list *ptimer, u32 delay_time)
107 mod_timer(ptimer, (jiffies+(delay_time*HZ/1000)));
110 static inline void _cancel_timer(struct timer_list *ptimer, u8 *bcancelled)
112 del_timer(ptimer);
113 *bcancelled = true; /*true ==1; false==0*/
116 static inline void _init_workitem(_workitem *pwork, void *pfunc, void *cntx)
118 INIT_WORK(pwork, pfunc);
121 static inline void _set_workitem(_workitem *pwork)
123 schedule_work(pwork);
126 #include "rtl871x_byteorder.h"
128 #ifndef BIT
129 #define BIT(x) (1 << (x))
130 #endif
133 For the following list_xxx operations,
134 caller must guarantee the atomic context.
135 Otherwise, there will be racing condition.
137 static inline u32 is_list_empty(struct list_head *phead)
139 if (list_empty(phead))
140 return true;
141 else
142 return false;
145 static inline void list_insert_tail(struct list_head *plist,
146 struct list_head *phead)
148 list_add_tail(plist, phead);
151 static inline u32 _down_sema(struct semaphore *sema)
153 if (down_interruptible(sema))
154 return _FAIL;
155 else
156 return _SUCCESS;
159 static inline void _rtl_rwlock_init(struct semaphore *prwlock)
161 sema_init(prwlock, 1);
164 static inline void _init_listhead(struct list_head *list)
166 INIT_LIST_HEAD(list);
169 static inline u32 _queue_empty(struct __queue *pqueue)
171 return is_list_empty(&(pqueue->queue));
174 static inline u32 end_of_queue_search(struct list_head *head, struct list_head *plist)
176 if (head == plist)
177 return true;
178 else
179 return false;
182 static inline void sleep_schedulable(int ms)
184 u32 delta;
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 ;
194 static inline u8 *_malloc(u32 sz)
196 return kmalloc(sz, GFP_ATOMIC);
199 static inline unsigned char _cancel_timer_ex(struct timer_list *ptimer)
201 return del_timer(ptimer);
204 static inline void thread_enter(void *context)
206 daemonize("%s", "RTKTHREAD");
207 allow_signal(SIGTERM);
210 static inline void flush_signals_thread(void)
212 if (signal_pending(current))
213 flush_signals(current);
216 static inline u32 _RND8(u32 sz)
218 return ((sz >> 3) + ((sz & 7) ? 1 : 0)) << 3;
221 static inline u32 _RND128(u32 sz)
223 return ((sz >> 7) + ((sz & 127) ? 1 : 0)) << 7;
226 static inline u32 _RND256(u32 sz)
228 return ((sz >> 8) + ((sz & 255) ? 1 : 0)) << 8;
231 static inline u32 _RND512(u32 sz)
233 return ((sz >> 9) + ((sz & 511) ? 1 : 0)) << 9;
236 #endif