xref: /wlan-dirver/qcacld-3.0/uapi/linux/osapi_linux.h (revision 6147c58dff00905c59dc4f432e6487aa8d278bb6)
1 /*
2  * Copyright (c) 2013-2016 The Linux Foundation. All rights reserved.
3  *
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 #ifndef INLINE
61 #define INLINE                  __inline__
62 #endif
63 #else                           /* Not GCC */
64 #define __ATTRIB_PACK
65 #define __ATTRIB_PRINTF
66 #define __ATTRIB_NORETURN
67 #ifndef INLINE
68 #define INLINE                  __inline
69 #endif
70 #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 
80 #define A_LOGGER(mask, mod, args ...) \
81 		QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR, ## args)
82 #define A_PRINTF(args ...) \
83 		QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR, ## args)
84 #define A_PRINTF_LOG(args ...) \
85 		QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR, ## args)
86 #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 
98 typedef 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 
136 #ifdef WLAN_DEBUG
137 #ifdef A_SIMOS_DEVHOST
138 extern unsigned int panic_on_assert;
139 #define A_ASSERT(expr)	\
140 	if (!(expr)) {	 \
141 		printk(KERN_ALERT "Debug Assert Caught, File %s, Line: %d, Test:%s \n", __FILE__, __LINE__, # expr); \
142 		if (panic_on_assert) panic(# expr);								  \
143 	}
144 #else
145 #define A_ASSERT(expr)	\
146 	if (!(expr)) {	 \
147 		printk(KERN_ALERT "Debug Assert Caught, File %s, Line: %d, Test:%s \n", __FILE__, __LINE__, # expr); \
148 	}
149 #endif
150 #else
151 #define A_ASSERT(expr)
152 #endif /* DEBUG */
153 
154 #ifdef ANDROID_ENV
155 struct firmware;
156 int android_request_firmware(const struct firmware **firmware_p,
157 			     const char *filename, struct device *device);
158 void 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  */
169 typedef 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)
179 #define A_NETBUF_TRIM(bufPtr, len) \
180 	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)
185 #define A_NETBUF_SETLEN(bufPtr, len) \
186 	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) \
206 	(t)(((struct skbuf *)(bufPtr))->data)
207 
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  */
215 void a_netbuf_free(void *bufPtr);
216 void *a_netbuf_to_data(void *bufPtr);
217 A_UINT32 a_netbuf_to_len(void *bufPtr);
218 A_STATUS a_netbuf_push(void *bufPtr, A_INT32 len);
219 A_STATUS a_netbuf_push_data(void *bufPtr, char *srcPtr, A_INT32 len);
220 A_STATUS a_netbuf_put(void *bufPtr, A_INT32 len);
221 A_STATUS a_netbuf_put_data(void *bufPtr, char *srcPtr, A_INT32 len);
222 A_STATUS a_netbuf_pull(void *bufPtr, A_INT32 len);
223 A_STATUS a_netbuf_pull_data(void *bufPtr, char *dstPtr, A_INT32 len);
224 A_STATUS a_netbuf_trim(void *bufPtr, A_INT32 len);
225 A_STATUS a_netbuf_trim_data(void *bufPtr, char *dstPtr, A_INT32 len);
226 A_STATUS a_netbuf_setlen(void *bufPtr, A_INT32 len);
227 A_INT32 a_netbuf_headroom(void *bufPtr);
228 void a_netbuf_enqueue(A_NETBUF_QUEUE_T *q, void *pkt);
229 void a_netbuf_prequeue(A_NETBUF_QUEUE_T *q, void *pkt);
230 void *a_netbuf_dequeue(A_NETBUF_QUEUE_T *q);
231 int a_netbuf_queue_size(A_NETBUF_QUEUE_T *q);
232 int a_netbuf_queue_empty(A_NETBUF_QUEUE_T *q);
233 int a_netbuf_queue_empty(A_NETBUF_QUEUE_T *q);
234 void 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))
246 #ifndef inline
247 #define inline                  __inline__
248 #endif
249 #ifndef INLINE
250 #define INLINE                  __inline__
251 #endif
252 #else                           /* Not GCC */
253 #define __ATTRIB_PACK
254 #define __ATTRIB_PRINTF
255 #define __ATTRIB_NORETURN
256 #ifndef inline
257 #define inline                  __inline
258 #endif
259 #ifndef INLINE
260 #define INLINE                  __inline
261 #endif
262 #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_ */
287