xref: /wlan-driver/qcacld-3.0/uapi/linux/osapi_linux.h (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2013-2018, 2021 The Linux Foundation. All rights reserved.
3  *
4  * 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 
19 /* ------------------------------------------------------------------------------ */
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))
51 #ifndef INLINE
52 #define INLINE                  __inline__
53 #endif
54 #else                           /* Not GCC */
55 #define __ATTRIB_PACK
56 #define __ATTRIB_PRINTF
57 #define __ATTRIB_NORETURN
58 #ifndef INLINE
59 #define INLINE                  __inline
60 #endif
61 #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 
71 #define A_LOGGER(mask, mod, args ...) \
72 	QDF_TRACE_ERROR(QDF_MODULE_ID_QDF, args)
73 #define A_PRINTF(args ...) \
74 	QDF_TRACE_ERROR(QDF_MODULE_ID_QDF, args)
75 #define A_SNPRINTF(buf, len, args ...)   snprintf(buf, len, args)
76 #define A_OFFSETOF(type, field)   offsetof(type, field)
77 
78 /*
79  * Timer Functions
80  */
81 #define A_MSLEEP(msecs)							   \
82 	{									   \
83 		set_current_state(TASK_INTERRUPTIBLE);				       \
84 		schedule_timeout((HZ * (msecs)) / 1000);			       \
85 		set_current_state(TASK_RUNNING);				       \
86 	}
87 
88 typedef struct timer_list A_TIMER;
89 
90 /*
91  * Wait Queue related functions
92  */
93 #ifndef wait_event_interruptible_timeout
94 #define __wait_event_interruptible_timeout(wq, condition, ret)		\
95 	do {									\
96 		wait_queue_t __wait;						\
97 		init_waitqueue_entry(&__wait, current);				\
98 									\
99 		add_wait_queue(&wq, &__wait);					\
100 		for (;; ) {							 \
101 			set_current_state(TASK_INTERRUPTIBLE);			\
102 			if (condition)						\
103 				break;						\
104 			if (!signal_pending(current)) {				\
105 				ret = schedule_timeout(ret);			\
106 				if (!ret)					\
107 					break;					\
108 				continue;					\
109 			}							\
110 			ret = -ERESTARTSYS;					\
111 			break;							\
112 		}								\
113 		current->state = TASK_RUNNING;					\
114 		remove_wait_queue(&wq, &__wait);				\
115 	} while (0)
116 
117 #define wait_event_interruptible_timeout(wq, condition, timeout)	\
118 	({									\
119 		long __ret = timeout;						 \
120 		if (!(condition))						 \
121 			__wait_event_interruptible_timeout(wq, condition, __ret); \
122 		__ret;								 \
123 	 })
124 #endif /* wait_event_interruptible_timeout */
125 
126 #ifdef WLAN_DEBUG
127 #ifdef A_SIMOS_DEVHOST
128 extern unsigned int panic_on_assert;
129 #define A_ASSERT(expr)	\
130 	if (!(expr)) {	 \
131 		printk(KERN_ALERT "Debug Assert Caught, File %s, Line: %d, Test:%s\n", __FILE__, __LINE__, # expr); \
132 		if (panic_on_assert) panic(# expr);								  \
133 	}
134 #else
135 #define A_ASSERT(expr)	\
136 	if (!(expr)) {	 \
137 		printk(KERN_ALERT "Debug Assert Caught, File %s, Line: %d, Test:%s\n", __FILE__, __LINE__, # expr); \
138 	}
139 #endif
140 #else
141 #define A_ASSERT(expr)
142 #endif /* DEBUG */
143 
144 #ifdef ANDROID_ENV
145 struct firmware;
146 int android_request_firmware(const struct firmware **firmware_p,
147 			     const char *filename, struct device *device);
148 void android_release_firmware(const struct firmware *firmware);
149 #define A_REQUEST_FIRMWARE(_ppf, _pfile, _dev) android_request_firmware(_ppf, _pfile, _dev)
150 #define A_RELEASE_FIRMWARE(_pf) android_release_firmware(_pf)
151 #else
152 #define A_REQUEST_FIRMWARE(_ppf, _pfile, _dev) request_firmware(_ppf, _pfile, _dev)
153 #define A_RELEASE_FIRMWARE(_pf) release_firmware(_pf)
154 #endif
155 
156 /*
157  * Network buffer queue support
158  */
159 typedef struct sk_buff_head A_NETBUF_QUEUE_T;
160 
161 #define A_NETBUF_FREE(bufPtr) \
162 	a_netbuf_free(bufPtr)
163 #define A_NETBUF_LEN(bufPtr) \
164 	a_netbuf_to_len(bufPtr)
165 #define A_NETBUF_PUSH(bufPtr, len) \
166 	a_netbuf_push(bufPtr, len)
167 #define A_NETBUF_PUT(bufPtr, len) \
168 	a_netbuf_put(bufPtr, len)
169 #define A_NETBUF_TRIM(bufPtr, len) \
170 	a_netbuf_trim(bufPtr, len)
171 #define A_NETBUF_PULL(bufPtr, len) \
172 	a_netbuf_pull(bufPtr, len)
173 #define A_NETBUF_HEADROOM(bufPtr) \
174 	a_netbuf_headroom(bufPtr)
175 #define A_NETBUF_SETLEN(bufPtr, len) \
176 	a_netbuf_setlen(bufPtr, len)
177 
178 /* Add data to end of a buffer  */
179 #define A_NETBUF_PUT_DATA(bufPtr, srcPtr,  len)	\
180 	a_netbuf_put_data(bufPtr, srcPtr, len)
181 
182 /* Add data to start of the  buffer */
183 #define A_NETBUF_PUSH_DATA(bufPtr, srcPtr,  len) \
184 	a_netbuf_push_data(bufPtr, srcPtr, len)
185 
186 /* Remove data at start of the buffer */
187 #define A_NETBUF_PULL_DATA(bufPtr, dstPtr, len)	\
188 	a_netbuf_pull_data(bufPtr, dstPtr, len)
189 
190 /* Remove data from the end of the buffer */
191 #define A_NETBUF_TRIM_DATA(bufPtr, dstPtr, len)	\
192 	a_netbuf_trim_data(bufPtr, dstPtr, len)
193 
194 /* View data as "size" contiguous bytes of type "t" */
195 #define A_NETBUF_VIEW_DATA(bufPtr, t, size) \
196 	(t)(((struct skbuf *)(bufPtr))->data)
197 
198 /* return the beginning of the headroom for the buffer */
199 #define A_NETBUF_HEAD(bufPtr) \
200 	((((struct sk_buff *)(bufPtr))->head))
201 
202 /*
203  * OS specific network buffer access routines
204  */
205 void a_netbuf_free(void *bufPtr);
206 void *a_netbuf_to_data(void *bufPtr);
207 A_UINT32 a_netbuf_to_len(void *bufPtr);
208 A_STATUS a_netbuf_push(void *bufPtr, A_INT32 len);
209 A_STATUS a_netbuf_push_data(void *bufPtr, char *srcPtr, A_INT32 len);
210 A_STATUS a_netbuf_put(void *bufPtr, A_INT32 len);
211 A_STATUS a_netbuf_put_data(void *bufPtr, char *srcPtr, A_INT32 len);
212 A_STATUS a_netbuf_pull(void *bufPtr, A_INT32 len);
213 A_STATUS a_netbuf_pull_data(void *bufPtr, char *dstPtr, A_INT32 len);
214 A_STATUS a_netbuf_trim(void *bufPtr, A_INT32 len);
215 A_STATUS a_netbuf_trim_data(void *bufPtr, char *dstPtr, A_INT32 len);
216 A_STATUS a_netbuf_setlen(void *bufPtr, A_INT32 len);
217 A_INT32 a_netbuf_headroom(void *bufPtr);
218 void a_netbuf_enqueue(A_NETBUF_QUEUE_T *q, void *pkt);
219 void a_netbuf_prequeue(A_NETBUF_QUEUE_T *q, void *pkt);
220 void *a_netbuf_dequeue(A_NETBUF_QUEUE_T *q);
221 int a_netbuf_queue_size(A_NETBUF_QUEUE_T *q);
222 int a_netbuf_queue_empty(A_NETBUF_QUEUE_T *q);
223 int a_netbuf_queue_empty(A_NETBUF_QUEUE_T *q);
224 void a_netbuf_queue_init(A_NETBUF_QUEUE_T *q);
225 
226 #ifdef QCA_PARTNER_PLATFORM
227 #include "ath_carr_pltfrm.h"
228 #endif /* QCA_PARTNER_PLATFORM */
229 
230 #else                           /* __KERNEL__ */
231 
232 #ifdef __GNUC__
233 #define __ATTRIB_PACK           __attribute__ ((packed))
234 #define __ATTRIB_PRINTF         __attribute__ ((format (printf, 1, 2)))
235 #define __ATTRIB_NORETURN       __attribute__ ((noreturn))
236 #ifndef inline
237 #define inline                  __inline__
238 #endif
239 #ifndef INLINE
240 #define INLINE                  __inline__
241 #endif
242 #else                           /* Not GCC */
243 #define __ATTRIB_PACK
244 #define __ATTRIB_PRINTF
245 #define __ATTRIB_NORETURN
246 #ifndef inline
247 #define inline                  __inline
248 #endif
249 #ifndef INLINE
250 #define INLINE                  __inline
251 #endif
252 #endif /* End __GNUC__ */
253 
254 #define PREPACK
255 #define POSTPACK                __ATTRIB_PACK
256 
257 #define A_MEMCPY(dst, src, len)         memcpy((dst), (src), (len))
258 #define A_MEMSET(addr, value, size)     memset((addr), (value), (size))
259 #define A_MEMZERO(addr, len)            memset((addr), 0, (len))
260 #define A_MEMCMP(addr1, addr2, len)     memcmp((addr1), (addr2), (len))
261 
262 #ifdef ANDROID
263 #ifndef err
264 #include <linux/errno.h>
265 #define err(_s, args ...) do { \
266 		fprintf(stderr, "%s: line %d ", __FILE__, __LINE__); \
267 		fprintf(stderr, args); fprintf(stderr, ": %d\n", errno); \
268 		exit(_s); } while (0)
269 #endif
270 #else
271 #include <linux/err.h>
272 #endif
273 
274 #endif /* __KERNEL__ */
275 
276 #endif /* _OSAPI_LINUX_H_ */
277