blob: 9ba603310fdc359dc793b09cfa9e74bfe86c5eff [file] [log] [blame]
Ali Baharcf3e6882011-09-04 03:14:04 +08001/******************************************************************************
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 ******************************************************************************/
Larry Finger2865d422010-08-20 10:15:30 -050026#ifndef __OSDEP_SERVICE_H_
27#define __OSDEP_SERVICE_H_
28
29#define _SUCCESS 1
30#define _FAIL 0
31
Ali Bahar359140a2011-09-04 03:14:11 +080032#include <linux/version.h>
Larry Finger2865d422010-08-20 10:15:30 -050033#include <linux/spinlock.h>
Ali Bahar359140a2011-09-04 03:14:11 +080034
35#include <linux/interrupt.h>
Larry Finger2865d422010-08-20 10:15:30 -050036#include <linux/semaphore.h>
Ali Bahar359140a2011-09-04 03:14:11 +080037#include <linux/sched.h>
Larry Finger2865d422010-08-20 10:15:30 -050038#include <linux/sem.h>
39#include <linux/netdevice.h>
40#include <linux/etherdevice.h>
41#include <net/iw_handler.h>
Ali Bahar359140a2011-09-04 03:14:11 +080042#include <linux/proc_fs.h> /* Necessary because we use the proc fs */
43
44#include "basic_types.h"
Larry Finger2865d422010-08-20 10:15:30 -050045
46struct __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
Larry Finger2865d422010-08-20 10:15:30 -050055
56#define _init_queue(pqueue) \
57 do { \
58 _init_listhead(&((pqueue)->queue)); \
59 spin_lock_init(&((pqueue)->lock)); \
60 } while (0)
61
Larry Finger2865d422010-08-20 10:15:30 -050062static inline struct list_head *get_next(struct list_head *list)
63{
64 return list->next;
65}
66
67static 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
Larry Finger2865d422010-08-20 10:15:30 -050075static inline void list_delete(struct list_head *plist)
76{
77 list_del_init(plist);
78}
79
80static 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
89static inline void _set_timer(struct timer_list *ptimer, u32 delay_time)
90{
91 mod_timer(ptimer, (jiffies+(delay_time*HZ/1000)));
92}
93
94static inline void _cancel_timer(struct timer_list *ptimer, u8 *bcancelled)
95{
96 del_timer(ptimer);
97 *bcancelled = true; /*true ==1; false==0*/
98}
99
100static inline void _init_workitem(_workitem *pwork, void *pfunc, void *cntx)
101{
102 INIT_WORK(pwork, pfunc);
103}
104
105static 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/*
117For the following list_xxx operations,
118caller must guarantee the atomic context.
119Otherwise, there will be racing condition.
120*/
121static 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
Javier M. Mellid05937582011-04-02 03:01:49 +0200129static inline void list_insert_tail(struct list_head *plist,
130 struct list_head *phead)
Larry Finger2865d422010-08-20 10:15:30 -0500131{
132 list_add_tail(plist, phead);
133}
134
135static inline u32 _down_sema(struct semaphore *sema)
136{
137 if (down_interruptible(sema))
138 return _FAIL;
139 else
140 return _SUCCESS;
141}
142
Larry Finger2865d422010-08-20 10:15:30 -0500143static inline void _init_listhead(struct list_head *list)
144{
145 INIT_LIST_HEAD(list);
146}
147
148static inline u32 _queue_empty(struct __queue *pqueue)
149{
150 return is_list_empty(&(pqueue->queue));
151}
152
153static 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
161static 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
173static inline u8 *_malloc(u32 sz)
174{
Jesper Juhla2ac9d62010-11-07 12:22:18 -0600175 return kmalloc(sz, GFP_ATOMIC);
Larry Finger2865d422010-08-20 10:15:30 -0500176}
177
178static inline unsigned char _cancel_timer_ex(struct timer_list *ptimer)
179{
180 return del_timer(ptimer);
181}
182
183static inline void thread_enter(void *context)
184{
Larry Finger2865d422010-08-20 10:15:30 -0500185 allow_signal(SIGTERM);
186}
187
188static inline void flush_signals_thread(void)
189{
190 if (signal_pending(current))
191 flush_signals(current);
192}
193
194static inline u32 _RND8(u32 sz)
195{
Larry Finger4c510e92010-11-07 12:22:18 -0600196 return ((sz >> 3) + ((sz & 7) ? 1 : 0)) << 3;
Larry Finger2865d422010-08-20 10:15:30 -0500197}
198
199static inline u32 _RND128(u32 sz)
200{
Larry Finger4c510e92010-11-07 12:22:18 -0600201 return ((sz >> 7) + ((sz & 127) ? 1 : 0)) << 7;
Larry Finger2865d422010-08-20 10:15:30 -0500202}
203
204static inline u32 _RND256(u32 sz)
205{
Larry Finger4c510e92010-11-07 12:22:18 -0600206 return ((sz >> 8) + ((sz & 255) ? 1 : 0)) << 8;
Larry Finger2865d422010-08-20 10:15:30 -0500207}
208
209static inline u32 _RND512(u32 sz)
210{
Larry Finger4c510e92010-11-07 12:22:18 -0600211 return ((sz >> 9) + ((sz & 511) ? 1 : 0)) << 9;
Larry Finger2865d422010-08-20 10:15:30 -0500212}
213
Larry Finger2865d422010-08-20 10:15:30 -0500214#endif
215