Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[linux-btrfs-devel.git] / drivers / staging / rtl8712 / osdep_service.h
blob1ee943a58c4c74311377ed99c09b6b43e9f929c1
1 /******************************************************************************
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved.
21 * Contact information:
22 * WLAN FAE <wlanfae@realtek.com>
23 * Larry Finger <Larry.Finger@lwfinger.net>
25 ******************************************************************************/
26 #ifndef __OSDEP_SERVICE_H_
27 #define __OSDEP_SERVICE_H_
29 #define _SUCCESS 1
30 #define _FAIL 0
32 #include <linux/version.h>
33 #include <linux/spinlock.h>
35 #include <linux/interrupt.h>
36 #include <linux/semaphore.h>
37 #include <linux/sched.h>
38 #include <linux/sem.h>
39 #include <linux/netdevice.h>
40 #include <linux/etherdevice.h>
41 #include <net/iw_handler.h>
42 #include <linux/proc_fs.h> /* Necessary because we use the proc fs */
44 #include "basic_types.h"
46 struct __queue {
47 struct list_head queue;
48 spinlock_t lock;
51 #define _pkt struct sk_buff
52 #define _buffer unsigned char
53 #define thread_exit() complete_and_exit(NULL, 0)
54 #define _workitem struct work_struct
56 #define _init_queue(pqueue) \
57 do { \
58 _init_listhead(&((pqueue)->queue)); \
59 spin_lock_init(&((pqueue)->lock)); \
60 } while (0)
62 static inline struct list_head *get_next(struct list_head *list)
64 return list->next;
67 static inline struct list_head *get_list_head(struct __queue *queue)
69 return &(queue->queue);
72 #define LIST_CONTAINOR(ptr, type, member) \
73 ((type *)((char *)(ptr)-(SIZE_T)(&((type *)0)->member)))
75 static inline void _enter_hwio_critical(struct semaphore *prwlock,
76 unsigned long *pirqL)
78 down(prwlock);
81 static inline void _exit_hwio_critical(struct semaphore *prwlock,
82 unsigned long *pirqL)
84 up(prwlock);
87 static inline void list_delete(struct list_head *plist)
89 list_del_init(plist);
92 static inline void _init_timer(struct timer_list *ptimer,
93 struct net_device *padapter,
94 void *pfunc, void *cntx)
96 ptimer->function = pfunc;
97 ptimer->data = (addr_t)cntx;
98 init_timer(ptimer);
101 static inline void _set_timer(struct timer_list *ptimer, u32 delay_time)
103 mod_timer(ptimer, (jiffies+(delay_time*HZ/1000)));
106 static inline void _cancel_timer(struct timer_list *ptimer, u8 *bcancelled)
108 del_timer(ptimer);
109 *bcancelled = true; /*true ==1; false==0*/
112 static inline void _init_workitem(_workitem *pwork, void *pfunc, void *cntx)
114 INIT_WORK(pwork, pfunc);
117 static inline void _set_workitem(_workitem *pwork)
119 schedule_work(pwork);
122 #include "rtl871x_byteorder.h"
124 #ifndef BIT
125 #define BIT(x) (1 << (x))
126 #endif
129 For the following list_xxx operations,
130 caller must guarantee the atomic context.
131 Otherwise, there will be racing condition.
133 static inline u32 is_list_empty(struct list_head *phead)
135 if (list_empty(phead))
136 return true;
137 else
138 return false;
141 static inline void list_insert_tail(struct list_head *plist,
142 struct list_head *phead)
144 list_add_tail(plist, phead);
147 static inline u32 _down_sema(struct semaphore *sema)
149 if (down_interruptible(sema))
150 return _FAIL;
151 else
152 return _SUCCESS;
155 static inline void _rtl_rwlock_init(struct semaphore *prwlock)
157 sema_init(prwlock, 1);
160 static inline void _init_listhead(struct list_head *list)
162 INIT_LIST_HEAD(list);
165 static inline u32 _queue_empty(struct __queue *pqueue)
167 return is_list_empty(&(pqueue->queue));
170 static inline u32 end_of_queue_search(struct list_head *head, struct list_head *plist)
172 if (head == plist)
173 return true;
174 else
175 return false;
178 static inline void sleep_schedulable(int ms)
180 u32 delta;
182 delta = (ms * HZ) / 1000;/*(ms)*/
183 if (delta == 0)
184 delta = 1;/* 1 ms */
185 set_current_state(TASK_INTERRUPTIBLE);
186 if (schedule_timeout(delta) != 0)
187 return ;
190 static inline u8 *_malloc(u32 sz)
192 return kmalloc(sz, GFP_ATOMIC);
195 static inline unsigned char _cancel_timer_ex(struct timer_list *ptimer)
197 return del_timer(ptimer);
200 static inline void thread_enter(void *context)
202 allow_signal(SIGTERM);
205 static inline void flush_signals_thread(void)
207 if (signal_pending(current))
208 flush_signals(current);
211 static inline u32 _RND8(u32 sz)
213 return ((sz >> 3) + ((sz & 7) ? 1 : 0)) << 3;
216 static inline u32 _RND128(u32 sz)
218 return ((sz >> 7) + ((sz & 127) ? 1 : 0)) << 7;
221 static inline u32 _RND256(u32 sz)
223 return ((sz >> 8) + ((sz & 255) ? 1 : 0)) << 8;
226 static inline u32 _RND512(u32 sz)
228 return ((sz >> 9) + ((sz & 511) ? 1 : 0)) << 9;
231 #endif