2 * $Id: //depot/sw/releases/olca2.0-GPL/host/os/linux/include/osapi_linux.h#1 $
4 * This file contains the definitions of the basic atheros data types.
5 * It is used to map the data types in atheros files to a platform specific
8 * Copyright 2003-2005 Atheros Communications, Inc., All Rights Reserved.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation;
15 * Software distributed under the License is distributed on an "AS
16 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
17 * implied. See the License for the specific language governing
18 * rights and limitations under the License.
24 #ifndef _OSAPI_LINUX_H_
25 #define _OSAPI_LINUX_H_
29 #include <linux/version.h>
30 #include <linux/types.h>
31 #include <linux/kernel.h>
32 #include <linux/string.h>
33 #include <linux/skbuff.h>
34 #include <linux/netdevice.h>
35 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
36 #include <linux/jiffies.h>
38 #include <linux/timer.h>
39 #include <linux/delay.h>
40 #include <linux/wait.h>
42 #include <asm/arch/irq.h>
47 #define __ATTRIB_PACK __attribute__ ((packed))
48 #define __ATTRIB_PRINTF __attribute__ ((format (printf, 1, 2)))
49 #define __ATTRIB_NORETURN __attribute__ ((noreturn))
51 #define INLINE __inline__
55 #define __ATTRIB_PRINTF
56 #define __ATTRIB_NORETURN
58 #define INLINE __inline
60 #endif /* End __GNUC__ */
63 #define POSTPACK __ATTRIB_PACK
68 #define A_BE2CPU8(x) ntohb(x)
69 #define A_BE2CPU16(x) ntohs(x)
70 #define A_BE2CPU32(x) ntohl(x)
72 #define A_LE2CPU8(x) (x)
73 #define A_LE2CPU16(x) (x)
74 #define A_LE2CPU32(x) (x)
76 #define A_CPU2BE8(x) htonb(x)
77 #define A_CPU2BE16(x) htons(x)
78 #define A_CPU2BE32(x) htonl(x)
80 #define A_MEMCPY(dst, src, len) memcpy((A_UINT8 *)(dst), (src), (len))
81 #define A_MEMZERO(addr, len) memset(addr, 0, len)
82 #define A_MEMCMP(addr1, addr2, len) memcmp((addr1), (addr2), (len))
83 #define A_MALLOC(size) kmalloc((size), GFP_KERNEL)
84 #define A_MALLOC_NOWAIT(size) kmalloc((size), GFP_ATOMIC)
85 #define A_FREE(addr) kfree(addr)
86 #define A_PRINTF(args...) printk(args)
88 /* Mutual Exclusion */
89 typedef spinlock_t A_MUTEX_T
;
90 #define A_MUTEX_INIT(mutex) spin_lock_init(mutex)
91 #define A_MUTEX_LOCK(mutex) spin_lock_bh(mutex)
92 #define A_MUTEX_UNLOCK(mutex) spin_unlock_bh(mutex)
93 #define A_IS_MUTEX_VALID(mutex) TRUE /* okay to return true, since A_MUTEX_DELETE does nothing */
94 #define A_MUTEX_DELETE(mutex) /* spin locks are not kernel resources so nothing to free.. */
96 /* Get current time in ms adding a constant offset (in ms) */
97 #define A_GET_MS(offset) \
98 (jiffies + ((offset) / 1000) * HZ)
103 #define A_MDELAY(msecs) mdelay(msecs)
104 typedef struct timer_list A_TIMER
;
106 #define A_INIT_TIMER(pTimer, pFunction, pArg) do { \
107 init_timer(pTimer); \
108 (pTimer)->function = (pFunction); \
109 (pTimer)->data = (unsigned long)(pArg); \
113 * Start a Timer that elapses after 'periodMSec' milli-seconds
114 * Support is provided for a one-shot timer. The 'repeatFlag' is
117 #define A_TIMEOUT_MS(pTimer, periodMSec, repeatFlag) do { \
119 printk("\n" __FILE__ ":%d: Timer Repeat requested\n",__LINE__); \
120 panic("Timer Repeat"); \
122 mod_timer((pTimer), jiffies + HZ * (periodMSec) / 1000); \
128 #define A_UNTIMEOUT(pTimer) do { \
129 del_timer((pTimer)); \
132 #define A_DELETE_TIMER(pTimer) do { \
136 * Wait Queue related functions
138 typedef wait_queue_head_t A_WAITQUEUE_HEAD
;
139 #define A_INIT_WAITQUEUE_HEAD(head) init_waitqueue_head(head)
140 #ifndef wait_event_interruptible_timeout
141 #define __wait_event_interruptible_timeout(wq, condition, ret) \
143 wait_queue_t __wait; \
144 init_waitqueue_entry(&__wait, current); \
146 add_wait_queue(&wq, &__wait); \
148 set_current_state(TASK_INTERRUPTIBLE); \
151 if (!signal_pending(current)) { \
152 ret = schedule_timeout(ret); \
157 ret = -ERESTARTSYS; \
160 current->state = TASK_RUNNING; \
161 remove_wait_queue(&wq, &__wait); \
164 #define wait_event_interruptible_timeout(wq, condition, timeout) \
166 long __ret = timeout; \
168 __wait_event_interruptible_timeout(wq, condition, __ret); \
171 #endif /* wait_event_interruptible_timeout */
173 #define A_WAIT_EVENT_INTERRUPTIBLE_TIMEOUT(head, condition, timeout) do { \
174 wait_event_interruptible_timeout(head, condition, timeout); \
177 #define A_WAKE_UP(head) wake_up(head)
180 #define A_ASSERT(expr) \
182 printk(KERN_ALERT "\n" __FILE__ ":%d: Assertion " #expr " failed!\n",__LINE__); \
187 #define A_ASSERT(expr)
191 * Initialization of the network buffer subsystem
193 #define A_NETBUF_INIT()
196 * Network buffer queue support
198 typedef struct sk_buff_head A_NETBUF_QUEUE_T
;
200 #define A_NETBUF_QUEUE_INIT(q) \
201 a_netbuf_queue_init(q)
203 #define A_NETBUF_ENQUEUE(q, pkt) \
204 a_netbuf_enqueue((q), (pkt))
205 #define A_NETBUF_PREQUEUE(q, pkt) \
206 a_netbuf_prequeue((q), (pkt))
207 #define A_NETBUF_DEQUEUE(q) \
208 (a_netbuf_dequeue(q))
209 #define A_NETBUF_QUEUE_SIZE(q) \
210 a_netbuf_queue_size(q)
211 #define A_NETBUF_QUEUE_EMPTY(q) \
212 a_netbuf_queue_empty(q)
215 * Network buffer support
217 #define A_NETBUF_ALLOC(size) \
219 #define A_NETBUF_ALLOC_RAW(size) \
220 a_netbuf_alloc_raw(size)
221 #define A_NETBUF_FREE(bufPtr) \
222 a_netbuf_free(bufPtr)
223 #define A_NETBUF_DATA(bufPtr) \
224 a_netbuf_to_data(bufPtr)
225 #define A_NETBUF_LEN(bufPtr) \
226 a_netbuf_to_len(bufPtr)
227 #define A_NETBUF_PUSH(bufPtr, len) \
228 a_netbuf_push(bufPtr, len)
229 #define A_NETBUF_PUT(bufPtr, len) \
230 a_netbuf_put(bufPtr, len)
231 #define A_NETBUF_TRIM(bufPtr,len) \
232 a_netbuf_trim(bufPtr, len)
233 #define A_NETBUF_PULL(bufPtr, len) \
234 a_netbuf_pull(bufPtr, len)
235 #define A_NETBUF_HEADROOM(bufPtr)\
236 a_netbuf_headroom(bufPtr)
237 #define A_NETBUF_SETLEN(bufPtr,len) \
238 a_netbuf_setlen(bufPtr, len)
240 /* Add data to end of a buffer */
241 #define A_NETBUF_PUT_DATA(bufPtr, srcPtr, len) \
242 a_netbuf_put_data(bufPtr, srcPtr, len)
244 /* Add data to start of the buffer */
245 #define A_NETBUF_PUSH_DATA(bufPtr, srcPtr, len) \
246 a_netbuf_push_data(bufPtr, srcPtr, len)
248 /* Remove data at start of the buffer */
249 #define A_NETBUF_PULL_DATA(bufPtr, dstPtr, len) \
250 a_netbuf_pull_data(bufPtr, dstPtr, len)
252 /* Remove data from the end of the buffer */
253 #define A_NETBUF_TRIM_DATA(bufPtr, dstPtr, len) \
254 a_netbuf_trim_data(bufPtr, dstPtr, len)
256 /* View data as "size" contiguous bytes of type "t" */
257 #define A_NETBUF_VIEW_DATA(bufPtr, t, size) \
258 (t )( ((struct skbuf *)(bufPtr))->data)
260 /* return the beginning of the headroom for the buffer */
261 #define A_NETBUF_HEAD(bufPtr) \
262 ((((struct sk_buff *)(bufPtr))->head))
265 * OS specific network buffer access routines
267 void *a_netbuf_alloc(int size
);
268 void *a_netbuf_alloc_raw(int size
);
269 void a_netbuf_free(void *bufPtr
);
270 void *a_netbuf_to_data(void *bufPtr
);
271 A_UINT32
a_netbuf_to_len(void *bufPtr
);
272 A_STATUS
a_netbuf_push(void *bufPtr
, A_INT32 len
);
273 A_STATUS
a_netbuf_push_data(void *bufPtr
, char *srcPtr
, A_INT32 len
);
274 A_STATUS
a_netbuf_put(void *bufPtr
, A_INT32 len
);
275 A_STATUS
a_netbuf_put_data(void *bufPtr
, char *srcPtr
, A_INT32 len
);
276 A_STATUS
a_netbuf_pull(void *bufPtr
, A_INT32 len
);
277 A_STATUS
a_netbuf_pull_data(void *bufPtr
, char *dstPtr
, A_INT32 len
);
278 A_STATUS
a_netbuf_trim(void *bufPtr
, A_INT32 len
);
279 A_STATUS
a_netbuf_trim_data(void *bufPtr
, char *dstPtr
, A_INT32 len
);
280 A_STATUS
a_netbuf_setlen(void *bufPtr
, A_INT32 len
);
281 A_INT32
a_netbuf_headroom(void *bufPtr
);
282 void a_netbuf_enqueue(A_NETBUF_QUEUE_T
*q
, void *pkt
);
283 void a_netbuf_prequeue(A_NETBUF_QUEUE_T
*q
, void *pkt
);
284 void *a_netbuf_dequeue(A_NETBUF_QUEUE_T
*q
);
285 int a_netbuf_queue_size(A_NETBUF_QUEUE_T
*q
);
286 int a_netbuf_queue_empty(A_NETBUF_QUEUE_T
*q
);
287 int a_netbuf_queue_empty(A_NETBUF_QUEUE_T
*q
);
288 void a_netbuf_queue_init(A_NETBUF_QUEUE_T
*q
);
291 * Kernel v.s User space functions
293 A_UINT32
a_copy_to_user(void *to
, const void *from
, A_UINT32 n
);
294 A_UINT32
a_copy_from_user(void *to
, const void *from
, A_UINT32 n
);
296 #else /* __KERNEL__ */
299 #define __ATTRIB_PACK __attribute__ ((packed))
300 #define __ATTRIB_PRINTF __attribute__ ((format (printf, 1, 2)))
301 #define __ATTRIB_NORETURN __attribute__ ((noreturn))
303 #define INLINE __inline__
306 #define __ATTRIB_PACK
307 #define __ATTRIB_PRINTF
308 #define __ATTRIB_NORETURN
310 #define INLINE __inline
312 #endif /* End __GNUC__ */
315 #define POSTPACK __ATTRIB_PACK
317 #endif /* __KERNEL__ */
319 #endif /* _OSAPI_LINUX_H_ */