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, struct list_head *phead)
150 list_add_tail(plist, phead);
153 static inline u32 _down_sema(struct semaphore *sema)
155 if (down_interruptible(sema))
161 static inline void _rtl_rwlock_init(struct semaphore *prwlock)
163 sema_init(prwlock, 1);
166 static inline void _init_listhead(struct list_head *list)
168 INIT_LIST_HEAD(list);
171 static inline u32 _queue_empty(struct __queue *pqueue)
173 return is_list_empty(&(pqueue->queue));
176 static inline u32 end_of_queue_search(struct list_head *head, struct list_head *plist)
184 static inline void sleep_schedulable(int ms)
188 delta = (ms * HZ) / 1000;/*(ms)*/
191 set_current_state(TASK_INTERRUPTIBLE);
192 if (schedule_timeout(delta) != 0)
196 static inline u8 *_malloc(u32 sz)
198 return kmalloc(sz, GFP_ATOMIC);
201 static inline unsigned char _cancel_timer_ex(struct timer_list *ptimer)
203 return del_timer(ptimer);
206 static inline void thread_enter(void *context)
208 daemonize("%s", "RTKTHREAD");
209 allow_signal(SIGTERM);
212 static inline void flush_signals_thread(void)
214 if (signal_pending(current))
215 flush_signals(current);
218 static inline u32 _RND8(u32 sz)
220 return ((sz >> 3) + ((sz & 7) ? 1 : 0)) << 3;
223 static inline u32 _RND128(u32 sz)
225 return ((sz >> 7) + ((sz & 127) ? 1 : 0)) << 7;
228 static inline u32 _RND256(u32 sz)
230 return ((sz >> 8) + ((sz & 255) ? 1 : 0)) << 8;
233 static inline u32 _RND512(u32 sz)
235 return ((sz >> 9) + ((sz & 511) ? 1 : 0)) << 9;
238 #define STRUCT_PACKED __attribute__ ((packed))