blob: 4e61a5e21f9e04977427f73ece4489222223d3ac [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))
Govind Singh5b486202016-06-09 18:29:42 +053060#ifndef INLINE
61#define INLINE __inline__
62#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080063#else /* Not GCC */
64#define __ATTRIB_PACK
65#define __ATTRIB_PRINTF
66#define __ATTRIB_NORETURN
Govind Singh5b486202016-06-09 18:29:42 +053067#ifndef INLINE
68#define INLINE __inline
69#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080070#endif /* End __GNUC__ */
71
72#define PREPACK
73#define POSTPACK __ATTRIB_PACK
74
75#define A_MEMCPY(dst, src, len) memcpy((A_UINT8 *)(dst), (src), (len))
76#define A_MEMZERO(addr, len) memset(addr, 0, len)
77#define A_MEMSET(addr, value, size) memset((addr), (value), (size))
78#define A_MEMCMP(addr1, addr2, len) memcmp((addr1), (addr2), (len))
79
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080080#define A_LOGGER(mask, mod, args ...) \
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053081 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR, ## args)
Houston Hoffman04507d32015-11-17 21:30:21 -080082#define A_PRINTF(args ...) \
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053083 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR, ## args)
Houston Hoffman04507d32015-11-17 21:30:21 -080084#define A_PRINTF_LOG(args ...) \
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053085 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR, ## args)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080086#define A_SNPRINTF(buf, len, args ...) snprintf (buf, len, args)
87
88/*
89 * Timer Functions
90 */
91#define A_MSLEEP(msecs) \
92 { \
93 set_current_state(TASK_INTERRUPTIBLE); \
94 schedule_timeout((HZ * (msecs)) / 1000); \
95 set_current_state(TASK_RUNNING); \
96 }
97
98typedef struct timer_list A_TIMER;
99
100/*
101 * Wait Queue related functions
102 */
103#ifndef wait_event_interruptible_timeout
104#define __wait_event_interruptible_timeout(wq, condition, ret) \
105 do { \
106 wait_queue_t __wait; \
107 init_waitqueue_entry(&__wait, current); \
108 \
109 add_wait_queue(&wq, &__wait); \
110 for (;; ) { \
111 set_current_state(TASK_INTERRUPTIBLE); \
112 if (condition) \
113 break; \
114 if (!signal_pending(current)) { \
115 ret = schedule_timeout(ret); \
116 if (!ret) \
117 break; \
118 continue; \
119 } \
120 ret = -ERESTARTSYS; \
121 break; \
122 } \
123 current->state = TASK_RUNNING; \
124 remove_wait_queue(&wq, &__wait); \
125 } while (0)
126
127#define wait_event_interruptible_timeout(wq, condition, timeout) \
128 ({ \
129 long __ret = timeout; \
130 if (!(condition)) \
131 __wait_event_interruptible_timeout(wq, condition, __ret); \
132 __ret; \
133 })
134#endif /* wait_event_interruptible_timeout */
135
Srinivas Girigowda6147c582016-10-18 12:26:15 -0700136#ifdef WLAN_DEBUG
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800137#ifdef A_SIMOS_DEVHOST
138extern unsigned int panic_on_assert;
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 if (panic_on_assert) panic(# expr); \
143 }
144#else
145#define A_ASSERT(expr) \
146 if (!(expr)) { \
Anurag Chouhan6d760662016-02-20 16:05:43 +0530147 printk(KERN_ALERT "Debug Assert Caught, File %s, Line: %d, Test:%s \n", __FILE__, __LINE__, # expr); \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800148 }
149#endif
150#else
151#define A_ASSERT(expr)
152#endif /* DEBUG */
153
154#ifdef ANDROID_ENV
155struct firmware;
156int android_request_firmware(const struct firmware **firmware_p,
157 const char *filename, struct device *device);
158void android_release_firmware(const struct firmware *firmware);
159#define A_REQUEST_FIRMWARE(_ppf, _pfile, _dev) android_request_firmware(_ppf, _pfile, _dev)
160#define A_RELEASE_FIRMWARE(_pf) android_release_firmware(_pf)
161#else
162#define A_REQUEST_FIRMWARE(_ppf, _pfile, _dev) request_firmware(_ppf, _pfile, _dev)
163#define A_RELEASE_FIRMWARE(_pf) release_firmware(_pf)
164#endif
165
166/*
167 * Network buffer queue support
168 */
169typedef struct sk_buff_head A_NETBUF_QUEUE_T;
170
171#define A_NETBUF_FREE(bufPtr) \
172 a_netbuf_free(bufPtr)
173#define A_NETBUF_LEN(bufPtr) \
174 a_netbuf_to_len(bufPtr)
175#define A_NETBUF_PUSH(bufPtr, len) \
176 a_netbuf_push(bufPtr, len)
177#define A_NETBUF_PUT(bufPtr, len) \
178 a_netbuf_put(bufPtr, len)
Anurag Chouhan6d760662016-02-20 16:05:43 +0530179#define A_NETBUF_TRIM(bufPtr, len) \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800180 a_netbuf_trim(bufPtr, len)
181#define A_NETBUF_PULL(bufPtr, len) \
182 a_netbuf_pull(bufPtr, len)
183#define A_NETBUF_HEADROOM(bufPtr) \
184 a_netbuf_headroom(bufPtr)
Anurag Chouhan6d760662016-02-20 16:05:43 +0530185#define A_NETBUF_SETLEN(bufPtr, len) \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800186 a_netbuf_setlen(bufPtr, len)
187
188/* Add data to end of a buffer */
189#define A_NETBUF_PUT_DATA(bufPtr, srcPtr, len) \
190 a_netbuf_put_data(bufPtr, srcPtr, len)
191
192/* Add data to start of the buffer */
193#define A_NETBUF_PUSH_DATA(bufPtr, srcPtr, len) \
194 a_netbuf_push_data(bufPtr, srcPtr, len)
195
196/* Remove data at start of the buffer */
197#define A_NETBUF_PULL_DATA(bufPtr, dstPtr, len) \
198 a_netbuf_pull_data(bufPtr, dstPtr, len)
199
200/* Remove data from the end of the buffer */
201#define A_NETBUF_TRIM_DATA(bufPtr, dstPtr, len) \
202 a_netbuf_trim_data(bufPtr, dstPtr, len)
203
204/* View data as "size" contiguous bytes of type "t" */
205#define A_NETBUF_VIEW_DATA(bufPtr, t, size) \
Anurag Chouhan6d760662016-02-20 16:05:43 +0530206 (t)(((struct skbuf *)(bufPtr))->data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800207
208/* return the beginning of the headroom for the buffer */
209#define A_NETBUF_HEAD(bufPtr) \
210 ((((struct sk_buff *)(bufPtr))->head))
211
212/*
213 * OS specific network buffer access routines
214 */
215void a_netbuf_free(void *bufPtr);
216void *a_netbuf_to_data(void *bufPtr);
217A_UINT32 a_netbuf_to_len(void *bufPtr);
218A_STATUS a_netbuf_push(void *bufPtr, A_INT32 len);
219A_STATUS a_netbuf_push_data(void *bufPtr, char *srcPtr, A_INT32 len);
220A_STATUS a_netbuf_put(void *bufPtr, A_INT32 len);
221A_STATUS a_netbuf_put_data(void *bufPtr, char *srcPtr, A_INT32 len);
222A_STATUS a_netbuf_pull(void *bufPtr, A_INT32 len);
223A_STATUS a_netbuf_pull_data(void *bufPtr, char *dstPtr, A_INT32 len);
224A_STATUS a_netbuf_trim(void *bufPtr, A_INT32 len);
225A_STATUS a_netbuf_trim_data(void *bufPtr, char *dstPtr, A_INT32 len);
226A_STATUS a_netbuf_setlen(void *bufPtr, A_INT32 len);
227A_INT32 a_netbuf_headroom(void *bufPtr);
228void a_netbuf_enqueue(A_NETBUF_QUEUE_T *q, void *pkt);
229void a_netbuf_prequeue(A_NETBUF_QUEUE_T *q, void *pkt);
230void *a_netbuf_dequeue(A_NETBUF_QUEUE_T *q);
231int a_netbuf_queue_size(A_NETBUF_QUEUE_T *q);
232int a_netbuf_queue_empty(A_NETBUF_QUEUE_T *q);
233int a_netbuf_queue_empty(A_NETBUF_QUEUE_T *q);
234void a_netbuf_queue_init(A_NETBUF_QUEUE_T *q);
235
236#ifdef QCA_PARTNER_PLATFORM
237#include "ath_carr_pltfrm.h"
238#endif /* QCA_PARTNER_PLATFORM */
239
240#else /* __KERNEL__ */
241
242#ifdef __GNUC__
243#define __ATTRIB_PACK __attribute__ ((packed))
244#define __ATTRIB_PRINTF __attribute__ ((format (printf, 1, 2)))
245#define __ATTRIB_NORETURN __attribute__ ((noreturn))
Anurag Chouhan2ed1fce2016-02-22 15:07:01 +0530246#ifndef inline
247#define inline __inline__
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800248#endif
Govind Singhd5a7bcd2016-05-18 12:27:37 +0530249#ifndef INLINE
250#define INLINE __inline__
251#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800252#else /* Not GCC */
253#define __ATTRIB_PACK
254#define __ATTRIB_PRINTF
255#define __ATTRIB_NORETURN
Anurag Chouhan2ed1fce2016-02-22 15:07:01 +0530256#ifndef inline
257#define inline __inline
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800258#endif
Govind Singhd5a7bcd2016-05-18 12:27:37 +0530259#ifndef INLINE
260#define INLINE __inline
261#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800262#endif /* End __GNUC__ */
263
264#define PREPACK
265#define POSTPACK __ATTRIB_PACK
266
267#define A_MEMCPY(dst, src, len) memcpy((dst), (src), (len))
268#define A_MEMSET(addr, value, size) memset((addr), (value), (size))
269#define A_MEMZERO(addr, len) memset((addr), 0, (len))
270#define A_MEMCMP(addr1, addr2, len) memcmp((addr1), (addr2), (len))
271
272#ifdef ANDROID
273#ifndef err
274#include <errno.h>
275#define err(_s, args ...) do { \
276 fprintf(stderr, "%s: line %d ", __FILE__, __LINE__); \
277 fprintf(stderr, args); fprintf(stderr, ": %d\n", errno); \
278 exit(_s); } while (0)
279#endif
280#else
281#include <err.h>
282#endif
283
284#endif /* __KERNEL__ */
285
286#endif /* _OSAPI_LINUX_H_ */