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