1 #ifndef __OSDEP_SERVICE_H_
2 #define __OSDEP_SERVICE_H_
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>
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>
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)
40 struct list_head queue
;
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) \
52 _init_listhead(&((pqueue)->queue)); \
53 spin_lock_init(&((pqueue)->lock)); \
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
)
66 static inline struct list_head
*get_next(struct list_head
*list
)
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
,
85 static inline void _exit_hwio_critical(struct semaphore
*prwlock
,
91 static inline void list_delete(struct list_head
*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
;
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
)
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"
129 #define BIT(x) (1 << (x))
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
))
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
))
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
)
182 static inline void sleep_schedulable(int ms
)
186 delta
= (ms
* HZ
) / 1000;/*(ms)*/
189 set_current_state(TASK_INTERRUPTIBLE
);
190 if (schedule_timeout(delta
) != 0)
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;