Root/target/linux/s3c24xx/files-2.6.30/drivers/ar6000/ar6000/osapi_linux.h

1/*
2 * $Id: //depot/sw/releases/olca2.0-GPL/host/os/linux/include/osapi_linux.h#1 $
3 *
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
6 * type.
7 *
8 * Copyright 2003-2005 Atheros Communications, Inc., All Rights Reserved.
9 *
10 *
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;
14 *
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.
19 *
20 *
21 *
22 */
23
24#ifndef _OSAPI_LINUX_H_
25#define _OSAPI_LINUX_H_
26
27#ifdef __KERNEL__
28
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>
37#endif
38#include <linux/timer.h>
39#include <linux/delay.h>
40#include <linux/wait.h>
41#ifdef KERNEL_2_4
42#include <asm/arch/irq.h>
43#include <asm/irq.h>
44#endif
45
46#ifdef __GNUC__
47#define __ATTRIB_PACK __attribute__ ((packed))
48#define __ATTRIB_PRINTF __attribute__ ((format (printf, 1, 2)))
49#define __ATTRIB_NORETURN __attribute__ ((noreturn))
50#ifndef INLINE
51#define INLINE __inline__
52#endif
53#else /* Not GCC */
54#define __ATTRIB_PACK
55#define __ATTRIB_PRINTF
56#define __ATTRIB_NORETURN
57#ifndef INLINE
58#define INLINE __inline
59#endif
60#endif /* End __GNUC__ */
61
62#define PREPACK
63#define POSTPACK __ATTRIB_PACK
64
65/*
66 * Endianes macros
67 */
68#define A_BE2CPU8(x) ntohb(x)
69#define A_BE2CPU16(x) ntohs(x)
70#define A_BE2CPU32(x) ntohl(x)
71
72#define A_LE2CPU8(x) (x)
73#define A_LE2CPU16(x) (x)
74#define A_LE2CPU32(x) (x)
75
76#define A_CPU2BE8(x) htonb(x)
77#define A_CPU2BE16(x) htons(x)
78#define A_CPU2BE32(x) htonl(x)
79
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)
87
88/* Mutual Exclusion */
89typedef 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.. */
95
96/* Get current time in ms adding a constant offset (in ms) */
97#define A_GET_MS(offset) \
98    (jiffies + ((offset) / 1000) * HZ)
99
100/*
101 * Timer Functions
102 */
103#define A_MDELAY(msecs) mdelay(msecs)
104typedef struct timer_list A_TIMER;
105
106#define A_INIT_TIMER(pTimer, pFunction, pArg) do { \
107    init_timer(pTimer); \
108    (pTimer)->function = (pFunction); \
109    (pTimer)->data = (unsigned long)(pArg); \
110} while (0)
111
112/*
113 * Start a Timer that elapses after 'periodMSec' milli-seconds
114 * Support is provided for a one-shot timer. The 'repeatFlag' is
115 * ignored.
116 */
117#define A_TIMEOUT_MS(pTimer, periodMSec, repeatFlag) do { \
118    if (repeatFlag) { \
119        printk("\n" __FILE__ ":%d: Timer Repeat requested\n",__LINE__); \
120        panic("Timer Repeat"); \
121    } \
122    mod_timer((pTimer), jiffies + HZ * (periodMSec) / 1000); \
123} while (0)
124
125/*
126 * Cancel the Timer.
127 */
128#define A_UNTIMEOUT(pTimer) do { \
129    del_timer((pTimer)); \
130} while (0)
131
132#define A_DELETE_TIMER(pTimer) do { \
133} while (0)
134
135/*
136 * Wait Queue related functions
137 */
138typedef 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) \
142do { \
143        wait_queue_t __wait; \
144        init_waitqueue_entry(&__wait, current); \
145                                                                        \
146        add_wait_queue(&wq, &__wait); \
147        for (;;) { \
148                set_current_state(TASK_INTERRUPTIBLE); \
149                if (condition) \
150                        break; \
151                if (!signal_pending(current)) { \
152                        ret = schedule_timeout(ret); \
153                        if (!ret) \
154                                break; \
155                        continue; \
156                } \
157                ret = -ERESTARTSYS; \
158                break; \
159        } \
160        current->state = TASK_RUNNING; \
161        remove_wait_queue(&wq, &__wait); \
162} while (0)
163
164#define wait_event_interruptible_timeout(wq, condition, timeout) \
165({ \
166        long __ret = timeout; \
167        if (!(condition)) \
168                __wait_event_interruptible_timeout(wq, condition, __ret); \
169        __ret; \
170})
171#endif /* wait_event_interruptible_timeout */
172
173#define A_WAIT_EVENT_INTERRUPTIBLE_TIMEOUT(head, condition, timeout) do { \
174    wait_event_interruptible_timeout(head, condition, timeout); \
175} while (0)
176
177#define A_WAKE_UP(head) wake_up(head)
178
179#ifdef DEBUG
180#define A_ASSERT(expr) \
181    if (!(expr)) { \
182        printk(KERN_ALERT "\n" __FILE__ ":%d: Assertion " #expr " failed!\n",__LINE__); \
183        panic(#expr); \
184    }
185
186#else
187#define A_ASSERT(expr)
188#endif /* DEBUG */
189
190/*
191 * Initialization of the network buffer subsystem
192 */
193#define A_NETBUF_INIT()
194
195/*
196 * Network buffer queue support
197 */
198typedef struct sk_buff_head A_NETBUF_QUEUE_T;
199
200#define A_NETBUF_QUEUE_INIT(q) \
201    a_netbuf_queue_init(q)
202
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)
213
214/*
215 * Network buffer support
216 */
217#define A_NETBUF_ALLOC(size) \
218    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)
239
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)
243
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)
247
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)
251
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)
255
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)
259
260/* return the beginning of the headroom for the buffer */
261#define A_NETBUF_HEAD(bufPtr) \
262        ((((struct sk_buff *)(bufPtr))->head))
263
264/*
265 * OS specific network buffer access routines
266 */
267void *a_netbuf_alloc(int size);
268void *a_netbuf_alloc_raw(int size);
269void a_netbuf_free(void *bufPtr);
270void *a_netbuf_to_data(void *bufPtr);
271A_UINT32 a_netbuf_to_len(void *bufPtr);
272A_STATUS a_netbuf_push(void *bufPtr, A_INT32 len);
273A_STATUS a_netbuf_push_data(void *bufPtr, char *srcPtr, A_INT32 len);
274A_STATUS a_netbuf_put(void *bufPtr, A_INT32 len);
275A_STATUS a_netbuf_put_data(void *bufPtr, char *srcPtr, A_INT32 len);
276A_STATUS a_netbuf_pull(void *bufPtr, A_INT32 len);
277A_STATUS a_netbuf_pull_data(void *bufPtr, char *dstPtr, A_INT32 len);
278A_STATUS a_netbuf_trim(void *bufPtr, A_INT32 len);
279A_STATUS a_netbuf_trim_data(void *bufPtr, char *dstPtr, A_INT32 len);
280A_STATUS a_netbuf_setlen(void *bufPtr, A_INT32 len);
281A_INT32 a_netbuf_headroom(void *bufPtr);
282void a_netbuf_enqueue(A_NETBUF_QUEUE_T *q, void *pkt);
283void a_netbuf_prequeue(A_NETBUF_QUEUE_T *q, void *pkt);
284void *a_netbuf_dequeue(A_NETBUF_QUEUE_T *q);
285int a_netbuf_queue_size(A_NETBUF_QUEUE_T *q);
286int a_netbuf_queue_empty(A_NETBUF_QUEUE_T *q);
287int a_netbuf_queue_empty(A_NETBUF_QUEUE_T *q);
288void a_netbuf_queue_init(A_NETBUF_QUEUE_T *q);
289
290/*
291 * Kernel v.s User space functions
292 */
293A_UINT32 a_copy_to_user(void *to, const void *from, A_UINT32 n);
294A_UINT32 a_copy_from_user(void *to, const void *from, A_UINT32 n);
295
296#else /* __KERNEL__ */
297
298#ifdef __GNUC__
299#define __ATTRIB_PACK __attribute__ ((packed))
300#define __ATTRIB_PRINTF __attribute__ ((format (printf, 1, 2)))
301#define __ATTRIB_NORETURN __attribute__ ((noreturn))
302#ifndef INLINE
303#define INLINE __inline__
304#endif
305#else /* Not GCC */
306#define __ATTRIB_PACK
307#define __ATTRIB_PRINTF
308#define __ATTRIB_NORETURN
309#ifndef INLINE
310#define INLINE __inline
311#endif
312#endif /* End __GNUC__ */
313
314#define PREPACK
315#define POSTPACK __ATTRIB_PACK
316
317#endif /* __KERNEL__ */
318
319#endif /* _OSAPI_LINUX_H_ */
320

Archive Download this file



interactive