1 #ifndef __OSDEP_SERVICE_H_
2 #define __OSDEP_SERVICE_H_
7 #include "basic_types.h"
8 #include <linux/version.h>
9 #include <linux/spinlock.h>
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>
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>
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)
43 struct list_head queue
;
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)
53 #define _init_queue(pqueue) \
55 _init_listhead(&((pqueue)->queue)); \
56 spin_lock_init(&((pqueue)->lock)); \
59 static inline void *_netdev_priv(struct net_device
*dev
)
61 return netdev_priv(dev
);
64 static inline void os_free_netdev(struct net_device
*dev
)
69 static inline struct list_head
*get_next(struct list_head
*list
)
74 static inline struct list_head
*get_list_head(struct __queue
*queue
)
76 return &(queue
->queue
);
79 #define LIST_CONTAINOR(ptr, type, member) \
80 ((type *)((char *)(ptr)-(SIZE_T)(&((type *)0)->member)))
82 static inline void _enter_hwio_critical(struct semaphore
*prwlock
,
88 static inline void _exit_hwio_critical(struct semaphore
*prwlock
,
94 static inline void list_delete(struct list_head
*plist
)
99 static inline void _init_timer(struct timer_list
*ptimer
,
100 struct net_device
*padapter
,
101 void *pfunc
, void *cntx
)
103 ptimer
->function
= pfunc
;
104 ptimer
->data
= (addr_t
)cntx
;
108 static inline void _set_timer(struct timer_list
*ptimer
, u32 delay_time
)
110 mod_timer(ptimer
, (jiffies
+(delay_time
*HZ
/1000)));
113 static inline void _cancel_timer(struct timer_list
*ptimer
, u8
*bcancelled
)
116 *bcancelled
= true; /*true ==1; false==0*/
119 static inline void _init_workitem(_workitem
*pwork
, void *pfunc
, void *cntx
)
121 INIT_WORK(pwork
, pfunc
);
124 static inline void _set_workitem(_workitem
*pwork
)
126 schedule_work(pwork
);
129 #include "rtl871x_byteorder.h"
132 #define BIT(x) (1 << (x))
136 For the following list_xxx operations,
137 caller must guarantee the atomic context.
138 Otherwise, there will be racing condition.
140 static inline u32
is_list_empty(struct list_head
*phead
)
142 if (list_empty(phead
))
148 static inline void list_insert_tail(struct list_head
*plist
,
149 struct list_head
*phead
)
151 list_add_tail(plist
, phead
);
154 static inline u32
_down_sema(struct semaphore
*sema
)
156 if (down_interruptible(sema
))
162 static inline void _rtl_rwlock_init(struct semaphore
*prwlock
)
164 sema_init(prwlock
, 1);
167 static inline void _init_listhead(struct list_head
*list
)
169 INIT_LIST_HEAD(list
);
172 static inline u32
_queue_empty(struct __queue
*pqueue
)
174 return is_list_empty(&(pqueue
->queue
));
177 static inline u32
end_of_queue_search(struct list_head
*head
, struct list_head
*plist
)
185 static inline void sleep_schedulable(int ms
)
189 delta
= (ms
* HZ
) / 1000;/*(ms)*/
192 set_current_state(TASK_INTERRUPTIBLE
);
193 if (schedule_timeout(delta
) != 0)
197 static inline u8
*_malloc(u32 sz
)
199 return kmalloc(sz
, GFP_ATOMIC
);
202 static inline unsigned char _cancel_timer_ex(struct timer_list
*ptimer
)
204 return del_timer(ptimer
);
207 static inline void thread_enter(void *context
)
209 daemonize("%s", "RTKTHREAD");
210 allow_signal(SIGTERM
);
213 static inline void flush_signals_thread(void)
215 if (signal_pending(current
))
216 flush_signals(current
);
219 static inline u32
_RND8(u32 sz
)
221 return ((sz
>> 3) + ((sz
& 7) ? 1 : 0)) << 3;
224 static inline u32
_RND128(u32 sz
)
226 return ((sz
>> 7) + ((sz
& 127) ? 1 : 0)) << 7;
229 static inline u32
_RND256(u32 sz
)
231 return ((sz
>> 8) + ((sz
& 255) ? 1 : 0)) << 8;
234 static inline u32
_RND512(u32 sz
)
236 return ((sz
>> 9) + ((sz
& 511) ? 1 : 0)) << 9;
239 #define STRUCT_PACKED __attribute__ ((packed))