xref: /wlan-dirver/qcacld-3.0/uapi/linux/osapi_linux.h (revision 63d7e2a202b3cd37d6c1c20a39582b297a267b6b)
17090c5fdSPrakash Dhavali /*
2*63d7e2a2SSandeep Puligilla  * Copyright (c) 2013-2018, 2021 The Linux Foundation. All rights reserved.
37090c5fdSPrakash Dhavali  *
47090c5fdSPrakash Dhavali  * Permission to use, copy, modify, and/or distribute this software for
57090c5fdSPrakash Dhavali  * any purpose with or without fee is hereby granted, provided that the
67090c5fdSPrakash Dhavali  * above copyright notice and this permission notice appear in all
77090c5fdSPrakash Dhavali  * copies.
87090c5fdSPrakash Dhavali  *
97090c5fdSPrakash Dhavali  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
107090c5fdSPrakash Dhavali  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
117090c5fdSPrakash Dhavali  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
127090c5fdSPrakash Dhavali  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
137090c5fdSPrakash Dhavali  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
147090c5fdSPrakash Dhavali  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
157090c5fdSPrakash Dhavali  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
167090c5fdSPrakash Dhavali  * PERFORMANCE OF THIS SOFTWARE.
177090c5fdSPrakash Dhavali  */
187090c5fdSPrakash Dhavali 
197090c5fdSPrakash Dhavali /* ------------------------------------------------------------------------------ */
207090c5fdSPrakash Dhavali /* This file contains the definitions of the basic atheros data types. */
217090c5fdSPrakash Dhavali /* It is used to map the data types in atheros files to a platform specific */
227090c5fdSPrakash Dhavali /* type. */
237090c5fdSPrakash Dhavali /* ------------------------------------------------------------------------------ */
247090c5fdSPrakash Dhavali 
257090c5fdSPrakash Dhavali #ifndef _OSAPI_LINUX_H_
267090c5fdSPrakash Dhavali #define _OSAPI_LINUX_H_
277090c5fdSPrakash Dhavali 
287090c5fdSPrakash Dhavali #ifdef __KERNEL__
297090c5fdSPrakash Dhavali 
307090c5fdSPrakash Dhavali #include <linux/version.h>
317090c5fdSPrakash Dhavali #include <generated/autoconf.h>
327090c5fdSPrakash Dhavali #include <linux/types.h>
337090c5fdSPrakash Dhavali #include <linux/kernel.h>
347090c5fdSPrakash Dhavali #include <linux/string.h>
357090c5fdSPrakash Dhavali #include <linux/skbuff.h>
367090c5fdSPrakash Dhavali #include <linux/netdevice.h>
377090c5fdSPrakash Dhavali #include <linux/jiffies.h>
387090c5fdSPrakash Dhavali #include <linux/timer.h>
397090c5fdSPrakash Dhavali #include <linux/delay.h>
407090c5fdSPrakash Dhavali #include <linux/wait.h>
417090c5fdSPrakash Dhavali #include <linux/semaphore.h>
427090c5fdSPrakash Dhavali 
437090c5fdSPrakash Dhavali #include <linux/cache.h>
447090c5fdSPrakash Dhavali /* #include <linux/kthread.h> */
457090c5fdSPrakash Dhavali #include "a_types.h"
467090c5fdSPrakash Dhavali 
477090c5fdSPrakash Dhavali #ifdef __GNUC__
487090c5fdSPrakash Dhavali #define __ATTRIB_PACK           __attribute__ ((packed))
497090c5fdSPrakash Dhavali #define __ATTRIB_PRINTF         __attribute__ ((format (printf, 1, 2)))
507090c5fdSPrakash Dhavali #define __ATTRIB_NORETURN       __attribute__ ((noreturn))
515b48620cSGovind Singh #ifndef INLINE
525b48620cSGovind Singh #define INLINE                  __inline__
535b48620cSGovind Singh #endif
547090c5fdSPrakash Dhavali #else                           /* Not GCC */
557090c5fdSPrakash Dhavali #define __ATTRIB_PACK
567090c5fdSPrakash Dhavali #define __ATTRIB_PRINTF
577090c5fdSPrakash Dhavali #define __ATTRIB_NORETURN
585b48620cSGovind Singh #ifndef INLINE
595b48620cSGovind Singh #define INLINE                  __inline
605b48620cSGovind Singh #endif
617090c5fdSPrakash Dhavali #endif /* End __GNUC__ */
627090c5fdSPrakash Dhavali 
637090c5fdSPrakash Dhavali #define PREPACK
647090c5fdSPrakash Dhavali #define POSTPACK                __ATTRIB_PACK
657090c5fdSPrakash Dhavali 
667090c5fdSPrakash Dhavali #define A_MEMCPY(dst, src, len)         memcpy((A_UINT8 *)(dst), (src), (len))
677090c5fdSPrakash Dhavali #define A_MEMZERO(addr, len)            memset(addr, 0, len)
687090c5fdSPrakash Dhavali #define A_MEMSET(addr, value, size)     memset((addr), (value), (size))
697090c5fdSPrakash Dhavali #define A_MEMCMP(addr1, addr2, len)     memcmp((addr1), (addr2), (len))
707090c5fdSPrakash Dhavali 
717090c5fdSPrakash Dhavali #define A_LOGGER(mask, mod, args ...) \
7299923a83SNirav Shah 	QDF_TRACE_ERROR(QDF_MODULE_ID_QDF, args)
7304507d3cSHouston Hoffman #define A_PRINTF(args ...) \
7499923a83SNirav Shah 	QDF_TRACE_ERROR(QDF_MODULE_ID_QDF, args)
757090c5fdSPrakash Dhavali #define A_SNPRINTF(buf, len, args ...)   snprintf(buf, len, args)
76*63d7e2a2SSandeep Puligilla #define A_OFFSETOF(type, field)   offsetof(type, field)
777090c5fdSPrakash Dhavali 
787090c5fdSPrakash Dhavali /*
797090c5fdSPrakash Dhavali  * Timer Functions
807090c5fdSPrakash Dhavali  */
817090c5fdSPrakash Dhavali #define A_MSLEEP(msecs)							   \
827090c5fdSPrakash Dhavali 	{									   \
837090c5fdSPrakash Dhavali 		set_current_state(TASK_INTERRUPTIBLE);				       \
847090c5fdSPrakash Dhavali 		schedule_timeout((HZ * (msecs)) / 1000);			       \
857090c5fdSPrakash Dhavali 		set_current_state(TASK_RUNNING);				       \
867090c5fdSPrakash Dhavali 	}
877090c5fdSPrakash Dhavali 
887090c5fdSPrakash Dhavali typedef struct timer_list A_TIMER;
897090c5fdSPrakash Dhavali 
907090c5fdSPrakash Dhavali /*
917090c5fdSPrakash Dhavali  * Wait Queue related functions
927090c5fdSPrakash Dhavali  */
937090c5fdSPrakash Dhavali #ifndef wait_event_interruptible_timeout
947090c5fdSPrakash Dhavali #define __wait_event_interruptible_timeout(wq, condition, ret)		\
957090c5fdSPrakash Dhavali 	do {									\
967090c5fdSPrakash Dhavali 		wait_queue_t __wait;						\
977090c5fdSPrakash Dhavali 		init_waitqueue_entry(&__wait, current);				\
987090c5fdSPrakash Dhavali 									\
997090c5fdSPrakash Dhavali 		add_wait_queue(&wq, &__wait);					\
1007090c5fdSPrakash Dhavali 		for (;; ) {							 \
1017090c5fdSPrakash Dhavali 			set_current_state(TASK_INTERRUPTIBLE);			\
1027090c5fdSPrakash Dhavali 			if (condition)						\
1037090c5fdSPrakash Dhavali 				break;						\
1047090c5fdSPrakash Dhavali 			if (!signal_pending(current)) {				\
1057090c5fdSPrakash Dhavali 				ret = schedule_timeout(ret);			\
1067090c5fdSPrakash Dhavali 				if (!ret)					\
1077090c5fdSPrakash Dhavali 					break;					\
1087090c5fdSPrakash Dhavali 				continue;					\
1097090c5fdSPrakash Dhavali 			}							\
1107090c5fdSPrakash Dhavali 			ret = -ERESTARTSYS;					\
1117090c5fdSPrakash Dhavali 			break;							\
1127090c5fdSPrakash Dhavali 		}								\
1137090c5fdSPrakash Dhavali 		current->state = TASK_RUNNING;					\
1147090c5fdSPrakash Dhavali 		remove_wait_queue(&wq, &__wait);				\
1157090c5fdSPrakash Dhavali 	} while (0)
1167090c5fdSPrakash Dhavali 
1177090c5fdSPrakash Dhavali #define wait_event_interruptible_timeout(wq, condition, timeout)	\
1187090c5fdSPrakash Dhavali 	({									\
1197090c5fdSPrakash Dhavali 		long __ret = timeout;						 \
1207090c5fdSPrakash Dhavali 		if (!(condition))						 \
1217090c5fdSPrakash Dhavali 			__wait_event_interruptible_timeout(wq, condition, __ret); \
1227090c5fdSPrakash Dhavali 		__ret;								 \
1237090c5fdSPrakash Dhavali 	 })
1247090c5fdSPrakash Dhavali #endif /* wait_event_interruptible_timeout */
1257090c5fdSPrakash Dhavali 
1266147c58dSSrinivas Girigowda #ifdef WLAN_DEBUG
1277090c5fdSPrakash Dhavali #ifdef A_SIMOS_DEVHOST
1287090c5fdSPrakash Dhavali extern unsigned int panic_on_assert;
1297090c5fdSPrakash Dhavali #define A_ASSERT(expr)	\
1307090c5fdSPrakash Dhavali 	if (!(expr)) {	 \
1317090c5fdSPrakash Dhavali 		printk(KERN_ALERT "Debug Assert Caught, File %s, Line: %d, Test:%s\n", __FILE__, __LINE__, # expr); \
1327090c5fdSPrakash Dhavali 		if (panic_on_assert) panic(# expr);								  \
1337090c5fdSPrakash Dhavali 	}
1347090c5fdSPrakash Dhavali #else
1357090c5fdSPrakash Dhavali #define A_ASSERT(expr)	\
1367090c5fdSPrakash Dhavali 	if (!(expr)) {	 \
1377090c5fdSPrakash Dhavali 		printk(KERN_ALERT "Debug Assert Caught, File %s, Line: %d, Test:%s\n", __FILE__, __LINE__, # expr); \
1387090c5fdSPrakash Dhavali 	}
1397090c5fdSPrakash Dhavali #endif
1407090c5fdSPrakash Dhavali #else
1417090c5fdSPrakash Dhavali #define A_ASSERT(expr)
1427090c5fdSPrakash Dhavali #endif /* DEBUG */
1437090c5fdSPrakash Dhavali 
1447090c5fdSPrakash Dhavali #ifdef ANDROID_ENV
1457090c5fdSPrakash Dhavali struct firmware;
1467090c5fdSPrakash Dhavali int android_request_firmware(const struct firmware **firmware_p,
1477090c5fdSPrakash Dhavali 			     const char *filename, struct device *device);
1487090c5fdSPrakash Dhavali void android_release_firmware(const struct firmware *firmware);
1497090c5fdSPrakash Dhavali #define A_REQUEST_FIRMWARE(_ppf, _pfile, _dev) android_request_firmware(_ppf, _pfile, _dev)
1507090c5fdSPrakash Dhavali #define A_RELEASE_FIRMWARE(_pf) android_release_firmware(_pf)
1517090c5fdSPrakash Dhavali #else
1527090c5fdSPrakash Dhavali #define A_REQUEST_FIRMWARE(_ppf, _pfile, _dev) request_firmware(_ppf, _pfile, _dev)
1537090c5fdSPrakash Dhavali #define A_RELEASE_FIRMWARE(_pf) release_firmware(_pf)
1547090c5fdSPrakash Dhavali #endif
1557090c5fdSPrakash Dhavali 
1567090c5fdSPrakash Dhavali /*
1577090c5fdSPrakash Dhavali  * Network buffer queue support
1587090c5fdSPrakash Dhavali  */
1597090c5fdSPrakash Dhavali typedef struct sk_buff_head A_NETBUF_QUEUE_T;
1607090c5fdSPrakash Dhavali 
1617090c5fdSPrakash Dhavali #define A_NETBUF_FREE(bufPtr) \
1627090c5fdSPrakash Dhavali 	a_netbuf_free(bufPtr)
1637090c5fdSPrakash Dhavali #define A_NETBUF_LEN(bufPtr) \
1647090c5fdSPrakash Dhavali 	a_netbuf_to_len(bufPtr)
1657090c5fdSPrakash Dhavali #define A_NETBUF_PUSH(bufPtr, len) \
1667090c5fdSPrakash Dhavali 	a_netbuf_push(bufPtr, len)
1677090c5fdSPrakash Dhavali #define A_NETBUF_PUT(bufPtr, len) \
1687090c5fdSPrakash Dhavali 	a_netbuf_put(bufPtr, len)
1697090c5fdSPrakash Dhavali #define A_NETBUF_TRIM(bufPtr, len) \
1707090c5fdSPrakash Dhavali 	a_netbuf_trim(bufPtr, len)
1717090c5fdSPrakash Dhavali #define A_NETBUF_PULL(bufPtr, len) \
1727090c5fdSPrakash Dhavali 	a_netbuf_pull(bufPtr, len)
1737090c5fdSPrakash Dhavali #define A_NETBUF_HEADROOM(bufPtr) \
1747090c5fdSPrakash Dhavali 	a_netbuf_headroom(bufPtr)
1757090c5fdSPrakash Dhavali #define A_NETBUF_SETLEN(bufPtr, len) \
1767090c5fdSPrakash Dhavali 	a_netbuf_setlen(bufPtr, len)
1777090c5fdSPrakash Dhavali 
1787090c5fdSPrakash Dhavali /* Add data to end of a buffer  */
1797090c5fdSPrakash Dhavali #define A_NETBUF_PUT_DATA(bufPtr, srcPtr,  len)	\
1807090c5fdSPrakash Dhavali 	a_netbuf_put_data(bufPtr, srcPtr, len)
1817090c5fdSPrakash Dhavali 
1827090c5fdSPrakash Dhavali /* Add data to start of the  buffer */
1837090c5fdSPrakash Dhavali #define A_NETBUF_PUSH_DATA(bufPtr, srcPtr,  len) \
1847090c5fdSPrakash Dhavali 	a_netbuf_push_data(bufPtr, srcPtr, len)
1857090c5fdSPrakash Dhavali 
1867090c5fdSPrakash Dhavali /* Remove data at start of the buffer */
1877090c5fdSPrakash Dhavali #define A_NETBUF_PULL_DATA(bufPtr, dstPtr, len)	\
1887090c5fdSPrakash Dhavali 	a_netbuf_pull_data(bufPtr, dstPtr, len)
1897090c5fdSPrakash Dhavali 
1907090c5fdSPrakash Dhavali /* Remove data from the end of the buffer */
1917090c5fdSPrakash Dhavali #define A_NETBUF_TRIM_DATA(bufPtr, dstPtr, len)	\
1927090c5fdSPrakash Dhavali 	a_netbuf_trim_data(bufPtr, dstPtr, len)
1937090c5fdSPrakash Dhavali 
1947090c5fdSPrakash Dhavali /* View data as "size" contiguous bytes of type "t" */
1957090c5fdSPrakash Dhavali #define A_NETBUF_VIEW_DATA(bufPtr, t, size) \
1967090c5fdSPrakash Dhavali 	(t)(((struct skbuf *)(bufPtr))->data)
1977090c5fdSPrakash Dhavali 
1987090c5fdSPrakash Dhavali /* return the beginning of the headroom for the buffer */
1997090c5fdSPrakash Dhavali #define A_NETBUF_HEAD(bufPtr) \
2007090c5fdSPrakash Dhavali 	((((struct sk_buff *)(bufPtr))->head))
2017090c5fdSPrakash Dhavali 
2027090c5fdSPrakash Dhavali /*
2037090c5fdSPrakash Dhavali  * OS specific network buffer access routines
2047090c5fdSPrakash Dhavali  */
2057090c5fdSPrakash Dhavali void a_netbuf_free(void *bufPtr);
2067090c5fdSPrakash Dhavali void *a_netbuf_to_data(void *bufPtr);
2077090c5fdSPrakash Dhavali A_UINT32 a_netbuf_to_len(void *bufPtr);
2087090c5fdSPrakash Dhavali A_STATUS a_netbuf_push(void *bufPtr, A_INT32 len);
2097090c5fdSPrakash Dhavali A_STATUS a_netbuf_push_data(void *bufPtr, char *srcPtr, A_INT32 len);
2107090c5fdSPrakash Dhavali A_STATUS a_netbuf_put(void *bufPtr, A_INT32 len);
2117090c5fdSPrakash Dhavali A_STATUS a_netbuf_put_data(void *bufPtr, char *srcPtr, A_INT32 len);
2127090c5fdSPrakash Dhavali A_STATUS a_netbuf_pull(void *bufPtr, A_INT32 len);
2137090c5fdSPrakash Dhavali A_STATUS a_netbuf_pull_data(void *bufPtr, char *dstPtr, A_INT32 len);
2147090c5fdSPrakash Dhavali A_STATUS a_netbuf_trim(void *bufPtr, A_INT32 len);
2157090c5fdSPrakash Dhavali A_STATUS a_netbuf_trim_data(void *bufPtr, char *dstPtr, A_INT32 len);
2167090c5fdSPrakash Dhavali A_STATUS a_netbuf_setlen(void *bufPtr, A_INT32 len);
2177090c5fdSPrakash Dhavali A_INT32 a_netbuf_headroom(void *bufPtr);
2187090c5fdSPrakash Dhavali void a_netbuf_enqueue(A_NETBUF_QUEUE_T *q, void *pkt);
2197090c5fdSPrakash Dhavali void a_netbuf_prequeue(A_NETBUF_QUEUE_T *q, void *pkt);
2207090c5fdSPrakash Dhavali void *a_netbuf_dequeue(A_NETBUF_QUEUE_T *q);
2217090c5fdSPrakash Dhavali int a_netbuf_queue_size(A_NETBUF_QUEUE_T *q);
2227090c5fdSPrakash Dhavali int a_netbuf_queue_empty(A_NETBUF_QUEUE_T *q);
2237090c5fdSPrakash Dhavali int a_netbuf_queue_empty(A_NETBUF_QUEUE_T *q);
2247090c5fdSPrakash Dhavali void a_netbuf_queue_init(A_NETBUF_QUEUE_T *q);
2257090c5fdSPrakash Dhavali 
2267090c5fdSPrakash Dhavali #ifdef QCA_PARTNER_PLATFORM
2277090c5fdSPrakash Dhavali #include "ath_carr_pltfrm.h"
2287090c5fdSPrakash Dhavali #endif /* QCA_PARTNER_PLATFORM */
2297090c5fdSPrakash Dhavali 
2307090c5fdSPrakash Dhavali #else                           /* __KERNEL__ */
2317090c5fdSPrakash Dhavali 
2327090c5fdSPrakash Dhavali #ifdef __GNUC__
2337090c5fdSPrakash Dhavali #define __ATTRIB_PACK           __attribute__ ((packed))
2347090c5fdSPrakash Dhavali #define __ATTRIB_PRINTF         __attribute__ ((format (printf, 1, 2)))
2357090c5fdSPrakash Dhavali #define __ATTRIB_NORETURN       __attribute__ ((noreturn))
2362ed1fcedSAnurag Chouhan #ifndef inline
2372ed1fcedSAnurag Chouhan #define inline                  __inline__
2387090c5fdSPrakash Dhavali #endif
239d5a7bcd1SGovind Singh #ifndef INLINE
240d5a7bcd1SGovind Singh #define INLINE                  __inline__
241d5a7bcd1SGovind Singh #endif
2427090c5fdSPrakash Dhavali #else                           /* Not GCC */
2437090c5fdSPrakash Dhavali #define __ATTRIB_PACK
2447090c5fdSPrakash Dhavali #define __ATTRIB_PRINTF
2457090c5fdSPrakash Dhavali #define __ATTRIB_NORETURN
2462ed1fcedSAnurag Chouhan #ifndef inline
2472ed1fcedSAnurag Chouhan #define inline                  __inline
2487090c5fdSPrakash Dhavali #endif
249d5a7bcd1SGovind Singh #ifndef INLINE
250d5a7bcd1SGovind Singh #define INLINE                  __inline
251d5a7bcd1SGovind Singh #endif
2527090c5fdSPrakash Dhavali #endif /* End __GNUC__ */
2537090c5fdSPrakash Dhavali 
2547090c5fdSPrakash Dhavali #define PREPACK
2557090c5fdSPrakash Dhavali #define POSTPACK                __ATTRIB_PACK
2567090c5fdSPrakash Dhavali 
2577090c5fdSPrakash Dhavali #define A_MEMCPY(dst, src, len)         memcpy((dst), (src), (len))
2587090c5fdSPrakash Dhavali #define A_MEMSET(addr, value, size)     memset((addr), (value), (size))
2597090c5fdSPrakash Dhavali #define A_MEMZERO(addr, len)            memset((addr), 0, (len))
2607090c5fdSPrakash Dhavali #define A_MEMCMP(addr1, addr2, len)     memcmp((addr1), (addr2), (len))
2617090c5fdSPrakash Dhavali 
2627090c5fdSPrakash Dhavali #ifdef ANDROID
2637090c5fdSPrakash Dhavali #ifndef err
2640bec9a92SDustin Brown #include <linux/errno.h>
2657090c5fdSPrakash Dhavali #define err(_s, args ...) do { \
2667090c5fdSPrakash Dhavali 		fprintf(stderr, "%s: line %d ", __FILE__, __LINE__); \
2677090c5fdSPrakash Dhavali 		fprintf(stderr, args); fprintf(stderr, ": %d\n", errno); \
2687090c5fdSPrakash Dhavali 		exit(_s); } while (0)
2697090c5fdSPrakash Dhavali #endif
2707090c5fdSPrakash Dhavali #else
2710bec9a92SDustin Brown #include <linux/err.h>
2727090c5fdSPrakash Dhavali #endif
2737090c5fdSPrakash Dhavali 
2747090c5fdSPrakash Dhavali #endif /* __KERNEL__ */
2757090c5fdSPrakash Dhavali 
2767090c5fdSPrakash Dhavali #endif /* _OSAPI_LINUX_H_ */
277