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/smp_lock.h>
26 #include <linux/netdevice.h>
27 #include <linux/skbuff.h>
28 #include <linux/usb.h>
29 #include <linux/usb/ch9.h>
31 #include <linux/circ_buf.h>
32 #include <linux/uaccess.h>
33 #include <asm/byteorder.h>
34 #include <asm/atomic.h>
35 #include <linux/wireless.h>
36 #include <linux/rtnetlink.h>
38 #include <linux/if_arp.h>
39 #include <linux/firmware.h>
40 #define _usb_alloc_urb(x, y) usb_alloc_urb(x, y)
41 #define _usb_submit_urb(x, y) usb_submit_urb(x, y)
44 struct list_head queue;
48 #define _pkt struct sk_buff
49 #define _buffer unsigned char
50 #define thread_exit() complete_and_exit(NULL, 0)
51 #define _workitem struct work_struct
52 #define MSECS(t) (HZ * ((t) / 1000) + (HZ * ((t) % 1000)) / 1000)
54 #define _init_queue(pqueue) \
56 _init_listhead(&((pqueue)->queue)); \
57 spin_lock_init(&((pqueue)->lock)); \
60 static inline void *_netdev_priv(struct net_device *dev)
62 return netdev_priv(dev);
65 static inline void os_free_netdev(struct net_device *dev)
70 static inline struct list_head *get_next(struct list_head *list)
75 static inline struct list_head *get_list_head(struct __queue *queue)
77 return &(queue->queue);
80 #define LIST_CONTAINOR(ptr, type, member) \
81 ((type *)((char *)(ptr)-(SIZE_T)(&((type *)0)->member)))
83 static inline void _enter_hwio_critical(struct semaphore *prwlock,
89 static inline void _exit_hwio_critical(struct semaphore *prwlock,
95 static inline void list_delete(struct list_head *plist)
100 static inline void _init_timer(struct timer_list *ptimer,
101 struct net_device *padapter,
102 void *pfunc, void *cntx)
104 ptimer->function = pfunc;
105 ptimer->data = (addr_t)cntx;
109 static inline void _set_timer(struct timer_list *ptimer, u32 delay_time)
111 mod_timer(ptimer, (jiffies+(delay_time*HZ/1000)));
114 static inline void _cancel_timer(struct timer_list *ptimer, u8 *bcancelled)
117 *bcancelled = true; /*true ==1; false==0*/
120 static inline void _init_workitem(_workitem *pwork, void *pfunc, void *cntx)
122 INIT_WORK(pwork, pfunc);
125 static inline void _set_workitem(_workitem *pwork)
127 schedule_work(pwork);
130 #include "rtl871x_byteorder.h"
133 #define BIT(x) (1 << (x))
137 For the following list_xxx operations,
138 caller must guarantee the atomic context.
139 Otherwise, there will be racing condition.
141 static inline u32 is_list_empty(struct list_head *phead)
143 if (list_empty(phead))
149 static inline void list_insert_tail(struct list_head *plist, 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)
201 pbuf = kmalloc(sz, GFP_ATOMIC);
205 static inline unsigned char _cancel_timer_ex(struct timer_list *ptimer)
207 return del_timer(ptimer);
210 static inline void thread_enter(void *context)
212 daemonize("%s", "RTKTHREAD");
213 allow_signal(SIGTERM);
216 static inline void flush_signals_thread(void)
218 if (signal_pending(current))
219 flush_signals(current);
222 static inline u32 _RND8(u32 sz)
226 val = ((sz >> 3) + ((sz & 7) ? 1 : 0)) << 3;
230 static inline u32 _RND128(u32 sz)
234 val = ((sz >> 7) + ((sz & 127) ? 1 : 0)) << 7;
238 static inline u32 _RND256(u32 sz)
242 val = ((sz >> 8) + ((sz & 255) ? 1 : 0)) << 8;
246 static inline u32 _RND512(u32 sz)
250 val = ((sz >> 9) + ((sz & 511) ? 1 : 0)) << 9;
254 #define STRUCT_PACKED __attribute__ ((packed))