• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4  *
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.
8  *
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.
13  *
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
17  *
18  * Modifications for inclusion into the Linux staging tree are
19  * Copyright(c) 2010 Larry Finger. All rights reserved.
20  *
21  * Contact information:
22  * WLAN FAE <wlanfae@realtek.com>
23  * Larry Finger <Larry.Finger@lwfinger.net>
24  *
25  ******************************************************************************/
26 #ifndef __OSDEP_SERVICE_H_
27 #define __OSDEP_SERVICE_H_
28 
29 #define _SUCCESS	1
30 #define _FAIL		0
31 
32 #include <linux/version.h>
33 #include <linux/spinlock.h>
34 
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 */
43 
44 #include "basic_types.h"
45 
46 struct	__queue	{
47 	struct	list_head	queue;
48 	spinlock_t lock;
49 };
50 
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
55 
56 #define _init_queue(pqueue)				\
57 	do {						\
58 		_init_listhead(&((pqueue)->queue));	\
59 		spin_lock_init(&((pqueue)->lock));	\
60 	} while (0)
61 
get_next(struct list_head * list)62 static inline struct list_head *get_next(struct list_head *list)
63 {
64 	return list->next;
65 }
66 
get_list_head(struct __queue * queue)67 static inline struct list_head *get_list_head(struct  __queue *queue)
68 {
69 	return &(queue->queue);
70 }
71 
72 #define LIST_CONTAINOR(ptr, type, member) \
73 	((type *)((char *)(ptr)-(SIZE_T)(&((type *)0)->member)))
74 
list_delete(struct list_head * plist)75 static inline void list_delete(struct list_head *plist)
76 {
77 	list_del_init(plist);
78 }
79 
_init_timer(struct timer_list * ptimer,struct net_device * padapter,void * pfunc,void * cntx)80 static inline void _init_timer(struct timer_list *ptimer,
81 			       struct  net_device *padapter,
82 			       void *pfunc, void *cntx)
83 {
84 	ptimer->function = pfunc;
85 	ptimer->data = (addr_t)cntx;
86 	init_timer(ptimer);
87 }
88 
_set_timer(struct timer_list * ptimer,u32 delay_time)89 static inline void _set_timer(struct timer_list *ptimer, u32 delay_time)
90 {
91 	mod_timer(ptimer, (jiffies+(delay_time*HZ/1000)));
92 }
93 
_cancel_timer(struct timer_list * ptimer,u8 * bcancelled)94 static inline void _cancel_timer(struct timer_list *ptimer, u8 *bcancelled)
95 {
96 	del_timer(ptimer);
97 	*bcancelled = true; /*true ==1; false==0*/
98 }
99 
_init_workitem(_workitem * pwork,void * pfunc,void * cntx)100 static inline void _init_workitem(_workitem *pwork, void *pfunc, void *cntx)
101 {
102 	INIT_WORK(pwork, pfunc);
103 }
104 
_set_workitem(_workitem * pwork)105 static inline void _set_workitem(_workitem *pwork)
106 {
107 	schedule_work(pwork);
108 }
109 
110 #include "rtl871x_byteorder.h"
111 
112 #ifndef BIT
113 	#define BIT(x)	(1 << (x))
114 #endif
115 
116 /*
117 For the following list_xxx operations,
118 caller must guarantee the atomic context.
119 Otherwise, there will be racing condition.
120 */
is_list_empty(struct list_head * phead)121 static inline u32 is_list_empty(struct list_head *phead)
122 {
123 	if (list_empty(phead))
124 		return true;
125 	else
126 		return false;
127 }
128 
list_insert_tail(struct list_head * plist,struct list_head * phead)129 static inline void list_insert_tail(struct list_head *plist,
130 				    struct list_head *phead)
131 {
132 	list_add_tail(plist, phead);
133 }
134 
_down_sema(struct semaphore * sema)135 static inline u32 _down_sema(struct semaphore *sema)
136 {
137 	if (down_interruptible(sema))
138 		return _FAIL;
139 	else
140 		return _SUCCESS;
141 }
142 
_init_listhead(struct list_head * list)143 static inline void _init_listhead(struct list_head *list)
144 {
145 	INIT_LIST_HEAD(list);
146 }
147 
_queue_empty(struct __queue * pqueue)148 static inline u32 _queue_empty(struct  __queue *pqueue)
149 {
150 	return is_list_empty(&(pqueue->queue));
151 }
152 
end_of_queue_search(struct list_head * head,struct list_head * plist)153 static inline u32 end_of_queue_search(struct list_head *head, struct list_head *plist)
154 {
155 	if (head == plist)
156 		return true;
157 	else
158 		return false;
159 }
160 
sleep_schedulable(int ms)161 static inline void sleep_schedulable(int ms)
162 {
163 	u32 delta;
164 
165 	delta = (ms * HZ) / 1000;/*(ms)*/
166 	if (delta == 0)
167 		delta = 1;/* 1 ms */
168 	set_current_state(TASK_INTERRUPTIBLE);
169 	if (schedule_timeout(delta) != 0)
170 		return ;
171 }
172 
_malloc(u32 sz)173 static inline u8 *_malloc(u32 sz)
174 {
175 	return	kmalloc(sz, GFP_ATOMIC);
176 }
177 
_cancel_timer_ex(struct timer_list * ptimer)178 static inline unsigned char _cancel_timer_ex(struct timer_list *ptimer)
179 {
180 	return del_timer(ptimer);
181 }
182 
thread_enter(void * context)183 static inline void thread_enter(void *context)
184 {
185 	allow_signal(SIGTERM);
186 }
187 
flush_signals_thread(void)188 static inline void flush_signals_thread(void)
189 {
190 	if (signal_pending(current))
191 		flush_signals(current);
192 }
193 
_RND8(u32 sz)194 static inline u32 _RND8(u32 sz)
195 {
196 	return ((sz >> 3) + ((sz & 7) ? 1 : 0)) << 3;
197 }
198 
_RND128(u32 sz)199 static inline u32 _RND128(u32 sz)
200 {
201 	return ((sz >> 7) + ((sz & 127) ? 1 : 0)) << 7;
202 }
203 
_RND256(u32 sz)204 static inline u32 _RND256(u32 sz)
205 {
206 	return ((sz >> 8) + ((sz & 255) ? 1 : 0)) << 8;
207 }
208 
_RND512(u32 sz)209 static inline u32 _RND512(u32 sz)
210 {
211 	return ((sz >> 9) + ((sz & 511) ? 1 : 0)) << 9;
212 }
213 
214 #endif
215 
216