staging: ath6kl: Convert enum A_STATUS to int
[linux-2.6.git] / drivers / staging / ath6kl / os / linux / include / osapi_linux.h
bloba1dd024040030f9ede59bdfbdd30ec013d30a90f
1 //------------------------------------------------------------------------------
2 // This file contains the definitions of the basic atheros data types.
3 // It is used to map the data types in atheros files to a platform specific
4 // type.
5 // Copyright (c) 2004-2010 Atheros Communications Inc.
6 // All rights reserved.
7 //
8 //
9 //
10 // Permission to use, copy, modify, and/or distribute this software for any
11 // purpose with or without fee is hereby granted, provided that the above
12 // copyright notice and this permission notice appear in all copies.
14 // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
15 // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16 // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
17 // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18 // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19 // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20 // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 // Author(s): ="Atheros"
25 //------------------------------------------------------------------------------
27 #ifndef _OSAPI_LINUX_H_
28 #define _OSAPI_LINUX_H_
30 #ifdef __KERNEL__
32 #include <linux/version.h>
33 #include <linux/types.h>
34 #include <linux/kernel.h>
35 #include <linux/string.h>
36 #include <linux/skbuff.h>
37 #include <linux/netdevice.h>
38 #include <linux/jiffies.h>
39 #include <linux/timer.h>
40 #include <linux/delay.h>
41 #include <linux/wait.h>
42 #include <linux/semaphore.h>
43 #include <linux/cache.h>
45 #ifdef __GNUC__
46 #define __ATTRIB_PACK __attribute__ ((packed))
47 #define __ATTRIB_PRINTF __attribute__ ((format (printf, 1, 2)))
48 #define __ATTRIB_NORETURN __attribute__ ((noreturn))
49 #ifndef INLINE
50 #define INLINE __inline__
51 #endif
52 #else /* Not GCC */
53 #define __ATTRIB_PACK
54 #define __ATTRIB_PRINTF
55 #define __ATTRIB_NORETURN
56 #ifndef INLINE
57 #define INLINE __inline
58 #endif
59 #endif /* End __GNUC__ */
61 #define PREPACK
62 #define POSTPACK __ATTRIB_PACK
65 * Endianes macros
67 #define A_BE2CPU8(x) ntohb(x)
68 #define A_BE2CPU16(x) ntohs(x)
69 #define A_BE2CPU32(x) ntohl(x)
71 #define A_LE2CPU8(x) (x)
72 #define A_LE2CPU16(x) (x)
73 #define A_LE2CPU32(x) (x)
75 #define A_CPU2BE8(x) htonb(x)
76 #define A_CPU2BE16(x) htons(x)
77 #define A_CPU2BE32(x) htonl(x)
79 #define A_MEMCPY(dst, src, len) memcpy((A_UINT8 *)(dst), (src), (len))
80 #define A_MEMZERO(addr, len) memset(addr, 0, len)
81 #define A_MEMCMP(addr1, addr2, len) memcmp((addr1), (addr2), (len))
82 #define A_MALLOC(size) kmalloc((size), GFP_KERNEL)
83 #define A_MALLOC_NOWAIT(size) kmalloc((size), GFP_ATOMIC)
84 #define A_FREE(addr) kfree(addr)
86 #if defined(ANDROID_ENV) && defined(CONFIG_ANDROID_LOGGER)
87 extern unsigned int enablelogcat;
88 extern int android_logger_lv(void* module, int mask);
89 enum logidx { LOG_MAIN_IDX = 0 };
90 extern int logger_write(const enum logidx idx,
91 const unsigned char prio,
92 const char __kernel * const tag,
93 const char __kernel * const fmt,
94 ...);
95 #define A_ANDROID_PRINTF(mask, module, tags, args...) do { \
96 if (enablelogcat) \
97 logger_write(LOG_MAIN_IDX, android_logger_lv(module, mask), tags, args); \
98 else \
99 printk(KERN_ALERT args); \
100 } while (0)
101 #ifdef DEBUG
102 #define A_LOGGER_MODULE_NAME(x) #x
103 #define A_LOGGER(mask, mod, args...) \
104 A_ANDROID_PRINTF(mask, &GET_ATH_MODULE_DEBUG_VAR_NAME(mod), "ar6k_" A_LOGGER_MODULE_NAME(mod), args);
105 #endif
106 #define A_PRINTF(args...) A_ANDROID_PRINTF(ATH_DEBUG_INFO, NULL, "ar6k_driver", args)
107 #else
108 #define A_LOGGER(mask, mod, args...) printk(KERN_ALERT args)
109 #define A_PRINTF(args...) printk(KERN_ALERT args)
110 #endif /* ANDROID */
111 #define A_PRINTF_LOG(args...) printk(args)
112 #define A_SPRINTF(buf, args...) sprintf (buf, args)
114 /* Mutual Exclusion */
115 typedef spinlock_t A_MUTEX_T;
116 #define A_MUTEX_INIT(mutex) spin_lock_init(mutex)
117 #define A_MUTEX_LOCK(mutex) spin_lock_bh(mutex)
118 #define A_MUTEX_UNLOCK(mutex) spin_unlock_bh(mutex)
119 #define A_IS_MUTEX_VALID(mutex) TRUE /* okay to return true, since A_MUTEX_DELETE does nothing */
120 #define A_MUTEX_DELETE(mutex) /* spin locks are not kernel resources so nothing to free.. */
122 /* Get current time in ms adding a constant offset (in ms) */
123 #define A_GET_MS(offset) \
124 (jiffies + ((offset) / 1000) * HZ)
127 * Timer Functions
129 #define A_MDELAY(msecs) mdelay(msecs)
130 typedef struct timer_list A_TIMER;
132 #define A_INIT_TIMER(pTimer, pFunction, pArg) do { \
133 init_timer(pTimer); \
134 (pTimer)->function = (pFunction); \
135 (pTimer)->data = (unsigned long)(pArg); \
136 } while (0)
139 * Start a Timer that elapses after 'periodMSec' milli-seconds
140 * Support is provided for a one-shot timer. The 'repeatFlag' is
141 * ignored.
143 #define A_TIMEOUT_MS(pTimer, periodMSec, repeatFlag) do { \
144 if (repeatFlag) { \
145 printk("\n" __FILE__ ":%d: Timer Repeat requested\n",__LINE__); \
146 panic("Timer Repeat"); \
148 mod_timer((pTimer), jiffies + HZ * (periodMSec) / 1000); \
149 } while (0)
152 * Cancel the Timer.
154 #define A_UNTIMEOUT(pTimer) do { \
155 del_timer((pTimer)); \
156 } while (0)
158 #define A_DELETE_TIMER(pTimer) do { \
159 } while (0)
162 * Wait Queue related functions
164 typedef wait_queue_head_t A_WAITQUEUE_HEAD;
165 #define A_INIT_WAITQUEUE_HEAD(head) init_waitqueue_head(head)
166 #ifndef wait_event_interruptible_timeout
167 #define __wait_event_interruptible_timeout(wq, condition, ret) \
168 do { \
169 wait_queue_t __wait; \
170 init_waitqueue_entry(&__wait, current); \
172 add_wait_queue(&wq, &__wait); \
173 for (;;) { \
174 set_current_state(TASK_INTERRUPTIBLE); \
175 if (condition) \
176 break; \
177 if (!signal_pending(current)) { \
178 ret = schedule_timeout(ret); \
179 if (!ret) \
180 break; \
181 continue; \
183 ret = -ERESTARTSYS; \
184 break; \
186 current->state = TASK_RUNNING; \
187 remove_wait_queue(&wq, &__wait); \
188 } while (0)
190 #define wait_event_interruptible_timeout(wq, condition, timeout) \
191 ({ \
192 long __ret = timeout; \
193 if (!(condition)) \
194 __wait_event_interruptible_timeout(wq, condition, __ret); \
195 __ret; \
197 #endif /* wait_event_interruptible_timeout */
199 #define A_WAIT_EVENT_INTERRUPTIBLE_TIMEOUT(head, condition, timeout) do { \
200 wait_event_interruptible_timeout(head, condition, timeout); \
201 } while (0)
203 #define A_WAKE_UP(head) wake_up(head)
205 #ifdef DEBUG
206 extern unsigned int panic_on_assert;
207 #define A_ASSERT(expr) \
208 if (!(expr)) { \
209 printk(KERN_ALERT"Debug Assert Caught, File %s, Line: %d, Test:%s \n",__FILE__, __LINE__,#expr); \
210 if (panic_on_assert) panic(#expr); \
212 #else
213 #define A_ASSERT(expr)
214 #endif /* DEBUG */
216 #ifdef ANDROID_ENV
217 struct firmware;
218 int android_request_firmware(const struct firmware **firmware_p, const char *filename,
219 struct device *device);
220 void android_release_firmware(const struct firmware *firmware);
221 #define A_REQUEST_FIRMWARE(_ppf, _pfile, _dev) android_request_firmware(_ppf, _pfile, _dev)
222 #define A_RELEASE_FIRMWARE(_pf) android_release_firmware(_pf)
223 #else
224 #define A_REQUEST_FIRMWARE(_ppf, _pfile, _dev) request_firmware(_ppf, _pfile, _dev)
225 #define A_RELEASE_FIRMWARE(_pf) release_firmware(_pf)
226 #endif
229 * Initialization of the network buffer subsystem
231 #define A_NETBUF_INIT()
234 * Network buffer queue support
236 typedef struct sk_buff_head A_NETBUF_QUEUE_T;
238 #define A_NETBUF_QUEUE_INIT(q) \
239 a_netbuf_queue_init(q)
241 #define A_NETBUF_ENQUEUE(q, pkt) \
242 a_netbuf_enqueue((q), (pkt))
243 #define A_NETBUF_PREQUEUE(q, pkt) \
244 a_netbuf_prequeue((q), (pkt))
245 #define A_NETBUF_DEQUEUE(q) \
246 (a_netbuf_dequeue(q))
247 #define A_NETBUF_QUEUE_SIZE(q) \
248 a_netbuf_queue_size(q)
249 #define A_NETBUF_QUEUE_EMPTY(q) \
250 a_netbuf_queue_empty(q)
253 * Network buffer support
255 #define A_NETBUF_ALLOC(size) \
256 a_netbuf_alloc(size)
257 #define A_NETBUF_ALLOC_RAW(size) \
258 a_netbuf_alloc_raw(size)
259 #define A_NETBUF_FREE(bufPtr) \
260 a_netbuf_free(bufPtr)
261 #define A_NETBUF_DATA(bufPtr) \
262 a_netbuf_to_data(bufPtr)
263 #define A_NETBUF_LEN(bufPtr) \
264 a_netbuf_to_len(bufPtr)
265 #define A_NETBUF_PUSH(bufPtr, len) \
266 a_netbuf_push(bufPtr, len)
267 #define A_NETBUF_PUT(bufPtr, len) \
268 a_netbuf_put(bufPtr, len)
269 #define A_NETBUF_TRIM(bufPtr,len) \
270 a_netbuf_trim(bufPtr, len)
271 #define A_NETBUF_PULL(bufPtr, len) \
272 a_netbuf_pull(bufPtr, len)
273 #define A_NETBUF_HEADROOM(bufPtr)\
274 a_netbuf_headroom(bufPtr)
275 #define A_NETBUF_SETLEN(bufPtr,len) \
276 a_netbuf_setlen(bufPtr, len)
278 /* Add data to end of a buffer */
279 #define A_NETBUF_PUT_DATA(bufPtr, srcPtr, len) \
280 a_netbuf_put_data(bufPtr, srcPtr, len)
282 /* Add data to start of the buffer */
283 #define A_NETBUF_PUSH_DATA(bufPtr, srcPtr, len) \
284 a_netbuf_push_data(bufPtr, srcPtr, len)
286 /* Remove data at start of the buffer */
287 #define A_NETBUF_PULL_DATA(bufPtr, dstPtr, len) \
288 a_netbuf_pull_data(bufPtr, dstPtr, len)
290 /* Remove data from the end of the buffer */
291 #define A_NETBUF_TRIM_DATA(bufPtr, dstPtr, len) \
292 a_netbuf_trim_data(bufPtr, dstPtr, len)
294 /* View data as "size" contiguous bytes of type "t" */
295 #define A_NETBUF_VIEW_DATA(bufPtr, t, size) \
296 (t )( ((struct skbuf *)(bufPtr))->data)
298 /* return the beginning of the headroom for the buffer */
299 #define A_NETBUF_HEAD(bufPtr) \
300 ((((struct sk_buff *)(bufPtr))->head))
303 * OS specific network buffer access routines
305 void *a_netbuf_alloc(int size);
306 void *a_netbuf_alloc_raw(int size);
307 void a_netbuf_free(void *bufPtr);
308 void *a_netbuf_to_data(void *bufPtr);
309 A_UINT32 a_netbuf_to_len(void *bufPtr);
310 int a_netbuf_push(void *bufPtr, A_INT32 len);
311 int a_netbuf_push_data(void *bufPtr, char *srcPtr, A_INT32 len);
312 int a_netbuf_put(void *bufPtr, A_INT32 len);
313 int a_netbuf_put_data(void *bufPtr, char *srcPtr, A_INT32 len);
314 int a_netbuf_pull(void *bufPtr, A_INT32 len);
315 int a_netbuf_pull_data(void *bufPtr, char *dstPtr, A_INT32 len);
316 int a_netbuf_trim(void *bufPtr, A_INT32 len);
317 int a_netbuf_trim_data(void *bufPtr, char *dstPtr, A_INT32 len);
318 int a_netbuf_setlen(void *bufPtr, A_INT32 len);
319 A_INT32 a_netbuf_headroom(void *bufPtr);
320 void a_netbuf_enqueue(A_NETBUF_QUEUE_T *q, void *pkt);
321 void a_netbuf_prequeue(A_NETBUF_QUEUE_T *q, void *pkt);
322 void *a_netbuf_dequeue(A_NETBUF_QUEUE_T *q);
323 int a_netbuf_queue_size(A_NETBUF_QUEUE_T *q);
324 int a_netbuf_queue_empty(A_NETBUF_QUEUE_T *q);
325 int a_netbuf_queue_empty(A_NETBUF_QUEUE_T *q);
326 void a_netbuf_queue_init(A_NETBUF_QUEUE_T *q);
329 * Kernel v.s User space functions
331 A_UINT32 a_copy_to_user(void *to, const void *from, A_UINT32 n);
332 A_UINT32 a_copy_from_user(void *to, const void *from, A_UINT32 n);
334 /* In linux, WLAN Rx and Tx run in different contexts, so no need to check
335 * for any commands/data queued for WLAN */
336 #define A_CHECK_DRV_TX()
338 #define A_GET_CACHE_LINE_BYTES() L1_CACHE_BYTES
340 #define A_CACHE_LINE_PAD 128
342 static inline void *A_ALIGN_TO_CACHE_LINE(void *ptr) {
343 return (void *)L1_CACHE_ALIGN((unsigned long)ptr);
346 #else /* __KERNEL__ */
348 #ifdef __GNUC__
349 #define __ATTRIB_PACK __attribute__ ((packed))
350 #define __ATTRIB_PRINTF __attribute__ ((format (printf, 1, 2)))
351 #define __ATTRIB_NORETURN __attribute__ ((noreturn))
352 #ifndef INLINE
353 #define INLINE __inline__
354 #endif
355 #else /* Not GCC */
356 #define __ATTRIB_PACK
357 #define __ATTRIB_PRINTF
358 #define __ATTRIB_NORETURN
359 #ifndef INLINE
360 #define INLINE __inline
361 #endif
362 #endif /* End __GNUC__ */
364 #define PREPACK
365 #define POSTPACK __ATTRIB_PACK
367 #define A_MEMCPY(dst, src, len) memcpy((dst), (src), (len))
368 #define A_MEMZERO(addr, len) memset((addr), 0, (len))
369 #define A_MEMCMP(addr1, addr2, len) memcmp((addr1), (addr2), (len))
370 #define A_MALLOC(size) malloc(size)
371 #define A_FREE(addr) free(addr)
373 #ifdef ANDROID
374 #ifndef err
375 #include <errno.h>
376 #define err(_s, args...) do { \
377 fprintf(stderr, "%s: line %d ", __FILE__, __LINE__); \
378 fprintf(stderr, args); fprintf(stderr, ": %d\n", errno); \
379 exit(_s); } while (0)
380 #endif
381 #else
382 #include <err.h>
383 #endif
385 #endif /* __KERNEL__ */
387 #endif /* _OSAPI_LINUX_H_ */