blob: 75c69b794e5838741e145d140c44fe49121dc450 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Anurag Chouhan6d760662016-02-20 16:05:43 +05302 * Copyright (c) 2013-2016 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/* ------------------------------------------------------------------------------ */
29/* This file contains the definitions of the basic atheros data types. */
30/* It is used to map the data types in atheros files to a platform specific */
31/* type. */
32/* ------------------------------------------------------------------------------ */
33
34#ifndef _OSAPI_LINUX_H_
35#define _OSAPI_LINUX_H_
36
37#ifdef __KERNEL__
38
39#include <linux/version.h>
40#include <generated/autoconf.h>
41#include <linux/types.h>
42#include <linux/kernel.h>
43#include <linux/string.h>
44#include <linux/skbuff.h>
45#include <linux/netdevice.h>
46#include <linux/jiffies.h>
47#include <linux/timer.h>
48#include <linux/delay.h>
49#include <linux/wait.h>
50#include <linux/semaphore.h>
51
52#include <linux/cache.h>
53/* #include <linux/kthread.h> */
54#include "a_types.h"
55
56#ifdef __GNUC__
57#define __ATTRIB_PACK __attribute__ ((packed))
58#define __ATTRIB_PRINTF __attribute__ ((format (printf, 1, 2)))
59#define __ATTRIB_NORETURN __attribute__ ((noreturn))
60#else /* Not GCC */
61#define __ATTRIB_PACK
62#define __ATTRIB_PRINTF
63#define __ATTRIB_NORETURN
64#endif /* End __GNUC__ */
65
66#define PREPACK
67#define POSTPACK __ATTRIB_PACK
68
69#define A_MEMCPY(dst, src, len) memcpy((A_UINT8 *)(dst), (src), (len))
70#define A_MEMZERO(addr, len) memset(addr, 0, len)
71#define A_MEMSET(addr, value, size) memset((addr), (value), (size))
72#define A_MEMCMP(addr1, addr2, len) memcmp((addr1), (addr2), (len))
73
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080074#define A_LOGGER(mask, mod, args ...) \
Anurag Chouhan6d760662016-02-20 16:05:43 +053075 CDF_TRACE(QDF_MODULE_ID_QDF, CDF_TRACE_LEVEL_ERROR, ## args)
Houston Hoffman04507d32015-11-17 21:30:21 -080076#define A_PRINTF(args ...) \
Anurag Chouhan6d760662016-02-20 16:05:43 +053077 CDF_TRACE(QDF_MODULE_ID_QDF, CDF_TRACE_LEVEL_ERROR, ## args)
Houston Hoffman04507d32015-11-17 21:30:21 -080078#define A_PRINTF_LOG(args ...) \
Anurag Chouhan6d760662016-02-20 16:05:43 +053079 CDF_TRACE(QDF_MODULE_ID_QDF, CDF_TRACE_LEVEL_ERROR, ## args)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080080#define A_SNPRINTF(buf, len, args ...) snprintf (buf, len, args)
81
82/*
83 * Timer Functions
84 */
85#define A_MSLEEP(msecs) \
86 { \
87 set_current_state(TASK_INTERRUPTIBLE); \
88 schedule_timeout((HZ * (msecs)) / 1000); \
89 set_current_state(TASK_RUNNING); \
90 }
91
92typedef struct timer_list A_TIMER;
93
94/*
95 * Wait Queue related functions
96 */
97#ifndef wait_event_interruptible_timeout
98#define __wait_event_interruptible_timeout(wq, condition, ret) \
99 do { \
100 wait_queue_t __wait; \
101 init_waitqueue_entry(&__wait, current); \
102 \
103 add_wait_queue(&wq, &__wait); \
104 for (;; ) { \
105 set_current_state(TASK_INTERRUPTIBLE); \
106 if (condition) \
107 break; \
108 if (!signal_pending(current)) { \
109 ret = schedule_timeout(ret); \
110 if (!ret) \
111 break; \
112 continue; \
113 } \
114 ret = -ERESTARTSYS; \
115 break; \
116 } \
117 current->state = TASK_RUNNING; \
118 remove_wait_queue(&wq, &__wait); \
119 } while (0)
120
121#define wait_event_interruptible_timeout(wq, condition, timeout) \
122 ({ \
123 long __ret = timeout; \
124 if (!(condition)) \
125 __wait_event_interruptible_timeout(wq, condition, __ret); \
126 __ret; \
127 })
128#endif /* wait_event_interruptible_timeout */
129
130#ifdef DEBUG
131#ifdef A_SIMOS_DEVHOST
132extern unsigned int panic_on_assert;
133#define A_ASSERT(expr) \
134 if (!(expr)) { \
Anurag Chouhan6d760662016-02-20 16:05:43 +0530135 printk(KERN_ALERT "Debug Assert Caught, File %s, Line: %d, Test:%s \n", __FILE__, __LINE__, # expr); \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800136 if (panic_on_assert) panic(# expr); \
137 }
138#else
139#define A_ASSERT(expr) \
140 if (!(expr)) { \
Anurag Chouhan6d760662016-02-20 16:05:43 +0530141 printk(KERN_ALERT "Debug Assert Caught, File %s, Line: %d, Test:%s \n", __FILE__, __LINE__, # expr); \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800142 }
143#endif
144#else
145#define A_ASSERT(expr)
146#endif /* DEBUG */
147
148#ifdef ANDROID_ENV
149struct firmware;
150int android_request_firmware(const struct firmware **firmware_p,
151 const char *filename, struct device *device);
152void android_release_firmware(const struct firmware *firmware);
153#define A_REQUEST_FIRMWARE(_ppf, _pfile, _dev) android_request_firmware(_ppf, _pfile, _dev)
154#define A_RELEASE_FIRMWARE(_pf) android_release_firmware(_pf)
155#else
156#define A_REQUEST_FIRMWARE(_ppf, _pfile, _dev) request_firmware(_ppf, _pfile, _dev)
157#define A_RELEASE_FIRMWARE(_pf) release_firmware(_pf)
158#endif
159
160/*
161 * Network buffer queue support
162 */
163typedef struct sk_buff_head A_NETBUF_QUEUE_T;
164
165#define A_NETBUF_FREE(bufPtr) \
166 a_netbuf_free(bufPtr)
167#define A_NETBUF_LEN(bufPtr) \
168 a_netbuf_to_len(bufPtr)
169#define A_NETBUF_PUSH(bufPtr, len) \
170 a_netbuf_push(bufPtr, len)
171#define A_NETBUF_PUT(bufPtr, len) \
172 a_netbuf_put(bufPtr, len)
Anurag Chouhan6d760662016-02-20 16:05:43 +0530173#define A_NETBUF_TRIM(bufPtr, len) \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800174 a_netbuf_trim(bufPtr, len)
175#define A_NETBUF_PULL(bufPtr, len) \
176 a_netbuf_pull(bufPtr, len)
177#define A_NETBUF_HEADROOM(bufPtr) \
178 a_netbuf_headroom(bufPtr)
Anurag Chouhan6d760662016-02-20 16:05:43 +0530179#define A_NETBUF_SETLEN(bufPtr, len) \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800180 a_netbuf_setlen(bufPtr, len)
181
182/* Add data to end of a buffer */
183#define A_NETBUF_PUT_DATA(bufPtr, srcPtr, len) \
184 a_netbuf_put_data(bufPtr, srcPtr, len)
185
186/* Add data to start of the buffer */
187#define A_NETBUF_PUSH_DATA(bufPtr, srcPtr, len) \
188 a_netbuf_push_data(bufPtr, srcPtr, len)
189
190/* Remove data at start of the buffer */
191#define A_NETBUF_PULL_DATA(bufPtr, dstPtr, len) \
192 a_netbuf_pull_data(bufPtr, dstPtr, len)
193
194/* Remove data from the end of the buffer */
195#define A_NETBUF_TRIM_DATA(bufPtr, dstPtr, len) \
196 a_netbuf_trim_data(bufPtr, dstPtr, len)
197
198/* View data as "size" contiguous bytes of type "t" */
199#define A_NETBUF_VIEW_DATA(bufPtr, t, size) \
Anurag Chouhan6d760662016-02-20 16:05:43 +0530200 (t)(((struct skbuf *)(bufPtr))->data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800201
202/* return the beginning of the headroom for the buffer */
203#define A_NETBUF_HEAD(bufPtr) \
204 ((((struct sk_buff *)(bufPtr))->head))
205
206/*
207 * OS specific network buffer access routines
208 */
209void a_netbuf_free(void *bufPtr);
210void *a_netbuf_to_data(void *bufPtr);
211A_UINT32 a_netbuf_to_len(void *bufPtr);
212A_STATUS a_netbuf_push(void *bufPtr, A_INT32 len);
213A_STATUS a_netbuf_push_data(void *bufPtr, char *srcPtr, A_INT32 len);
214A_STATUS a_netbuf_put(void *bufPtr, A_INT32 len);
215A_STATUS a_netbuf_put_data(void *bufPtr, char *srcPtr, A_INT32 len);
216A_STATUS a_netbuf_pull(void *bufPtr, A_INT32 len);
217A_STATUS a_netbuf_pull_data(void *bufPtr, char *dstPtr, A_INT32 len);
218A_STATUS a_netbuf_trim(void *bufPtr, A_INT32 len);
219A_STATUS a_netbuf_trim_data(void *bufPtr, char *dstPtr, A_INT32 len);
220A_STATUS a_netbuf_setlen(void *bufPtr, A_INT32 len);
221A_INT32 a_netbuf_headroom(void *bufPtr);
222void a_netbuf_enqueue(A_NETBUF_QUEUE_T *q, void *pkt);
223void a_netbuf_prequeue(A_NETBUF_QUEUE_T *q, void *pkt);
224void *a_netbuf_dequeue(A_NETBUF_QUEUE_T *q);
225int a_netbuf_queue_size(A_NETBUF_QUEUE_T *q);
226int a_netbuf_queue_empty(A_NETBUF_QUEUE_T *q);
227int a_netbuf_queue_empty(A_NETBUF_QUEUE_T *q);
228void a_netbuf_queue_init(A_NETBUF_QUEUE_T *q);
229
230#ifdef QCA_PARTNER_PLATFORM
231#include "ath_carr_pltfrm.h"
232#endif /* QCA_PARTNER_PLATFORM */
233
234#else /* __KERNEL__ */
235
236#ifdef __GNUC__
237#define __ATTRIB_PACK __attribute__ ((packed))
238#define __ATTRIB_PRINTF __attribute__ ((format (printf, 1, 2)))
239#define __ATTRIB_NORETURN __attribute__ ((noreturn))
240#ifndef INLINE
241#define INLINE __inline__
242#endif
243#else /* Not GCC */
244#define __ATTRIB_PACK
245#define __ATTRIB_PRINTF
246#define __ATTRIB_NORETURN
247#ifndef INLINE
248#define INLINE __inline
249#endif
250#endif /* End __GNUC__ */
251
252#define PREPACK
253#define POSTPACK __ATTRIB_PACK
254
255#define A_MEMCPY(dst, src, len) memcpy((dst), (src), (len))
256#define A_MEMSET(addr, value, size) memset((addr), (value), (size))
257#define A_MEMZERO(addr, len) memset((addr), 0, (len))
258#define A_MEMCMP(addr1, addr2, len) memcmp((addr1), (addr2), (len))
259
260#ifdef ANDROID
261#ifndef err
262#include <errno.h>
263#define err(_s, args ...) do { \
264 fprintf(stderr, "%s: line %d ", __FILE__, __LINE__); \
265 fprintf(stderr, args); fprintf(stderr, ": %d\n", errno); \
266 exit(_s); } while (0)
267#endif
268#else
269#include <err.h>
270#endif
271
272#endif /* __KERNEL__ */
273
274#endif /* _OSAPI_LINUX_H_ */