osapi_linux.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. /* This file contains the definitions of the basic atheros data types. */
  20. /* It is used to map the data types in atheros files to a platform specific */
  21. /* type. */
  22. /* ------------------------------------------------------------------------------ */
  23. #ifndef _OSAPI_LINUX_H_
  24. #define _OSAPI_LINUX_H_
  25. #ifdef __KERNEL__
  26. #include <linux/version.h>
  27. #include <generated/autoconf.h>
  28. #include <linux/types.h>
  29. #include <linux/kernel.h>
  30. #include <linux/string.h>
  31. #include <linux/skbuff.h>
  32. #include <linux/netdevice.h>
  33. #include <linux/jiffies.h>
  34. #include <linux/timer.h>
  35. #include <linux/delay.h>
  36. #include <linux/wait.h>
  37. #include <linux/semaphore.h>
  38. #include <linux/cache.h>
  39. /* #include <linux/kthread.h> */
  40. #include "a_types.h"
  41. #ifdef __GNUC__
  42. #define __ATTRIB_PACK __attribute__ ((packed))
  43. #define __ATTRIB_PRINTF __attribute__ ((format (printf, 1, 2)))
  44. #define __ATTRIB_NORETURN __attribute__ ((noreturn))
  45. #ifndef INLINE
  46. #define INLINE __inline__
  47. #endif
  48. #else /* Not GCC */
  49. #define __ATTRIB_PACK
  50. #define __ATTRIB_PRINTF
  51. #define __ATTRIB_NORETURN
  52. #ifndef INLINE
  53. #define INLINE __inline
  54. #endif
  55. #endif /* End __GNUC__ */
  56. #define PREPACK
  57. #define POSTPACK __ATTRIB_PACK
  58. #define A_MEMCPY(dst, src, len) memcpy((A_UINT8 *)(dst), (src), (len))
  59. #define A_MEMZERO(addr, len) memset(addr, 0, len)
  60. #define A_MEMSET(addr, value, size) memset((addr), (value), (size))
  61. #define A_MEMCMP(addr1, addr2, len) memcmp((addr1), (addr2), (len))
  62. #define A_LOGGER(mask, mod, args ...) \
  63. QDF_TRACE_ERROR(QDF_MODULE_ID_QDF, args)
  64. #define A_PRINTF(args ...) \
  65. QDF_TRACE_ERROR(QDF_MODULE_ID_QDF, args)
  66. #define A_SNPRINTF(buf, len, args ...) snprintf(buf, len, args)
  67. #define A_OFFSETOF(type, field) offsetof(type, field)
  68. /*
  69. * Timer Functions
  70. */
  71. #define A_MSLEEP(msecs) \
  72. { \
  73. set_current_state(TASK_INTERRUPTIBLE); \
  74. schedule_timeout((HZ * (msecs)) / 1000); \
  75. set_current_state(TASK_RUNNING); \
  76. }
  77. typedef struct timer_list A_TIMER;
  78. /*
  79. * Wait Queue related functions
  80. */
  81. #ifndef wait_event_interruptible_timeout
  82. #define __wait_event_interruptible_timeout(wq, condition, ret) \
  83. do { \
  84. wait_queue_t __wait; \
  85. init_waitqueue_entry(&__wait, current); \
  86. \
  87. add_wait_queue(&wq, &__wait); \
  88. for (;; ) { \
  89. set_current_state(TASK_INTERRUPTIBLE); \
  90. if (condition) \
  91. break; \
  92. if (!signal_pending(current)) { \
  93. ret = schedule_timeout(ret); \
  94. if (!ret) \
  95. break; \
  96. continue; \
  97. } \
  98. ret = -ERESTARTSYS; \
  99. break; \
  100. } \
  101. current->state = TASK_RUNNING; \
  102. remove_wait_queue(&wq, &__wait); \
  103. } while (0)
  104. #define wait_event_interruptible_timeout(wq, condition, timeout) \
  105. ({ \
  106. long __ret = timeout; \
  107. if (!(condition)) \
  108. __wait_event_interruptible_timeout(wq, condition, __ret); \
  109. __ret; \
  110. })
  111. #endif /* wait_event_interruptible_timeout */
  112. #ifdef WLAN_DEBUG
  113. #ifdef A_SIMOS_DEVHOST
  114. extern unsigned int panic_on_assert;
  115. #define A_ASSERT(expr) \
  116. if (!(expr)) { \
  117. printk(KERN_ALERT "Debug Assert Caught, File %s, Line: %d, Test:%s\n", __FILE__, __LINE__, # expr); \
  118. if (panic_on_assert) panic(# expr); \
  119. }
  120. #else
  121. #define A_ASSERT(expr) \
  122. if (!(expr)) { \
  123. printk(KERN_ALERT "Debug Assert Caught, File %s, Line: %d, Test:%s\n", __FILE__, __LINE__, # expr); \
  124. }
  125. #endif
  126. #else
  127. #define A_ASSERT(expr)
  128. #endif /* DEBUG */
  129. #ifdef ANDROID_ENV
  130. struct firmware;
  131. int android_request_firmware(const struct firmware **firmware_p,
  132. const char *filename, struct device *device);
  133. void android_release_firmware(const struct firmware *firmware);
  134. #define A_REQUEST_FIRMWARE(_ppf, _pfile, _dev) android_request_firmware(_ppf, _pfile, _dev)
  135. #define A_RELEASE_FIRMWARE(_pf) android_release_firmware(_pf)
  136. #else
  137. #define A_REQUEST_FIRMWARE(_ppf, _pfile, _dev) request_firmware(_ppf, _pfile, _dev)
  138. #define A_RELEASE_FIRMWARE(_pf) release_firmware(_pf)
  139. #endif
  140. /*
  141. * Network buffer queue support
  142. */
  143. typedef struct sk_buff_head A_NETBUF_QUEUE_T;
  144. #define A_NETBUF_FREE(bufPtr) \
  145. a_netbuf_free(bufPtr)
  146. #define A_NETBUF_LEN(bufPtr) \
  147. a_netbuf_to_len(bufPtr)
  148. #define A_NETBUF_PUSH(bufPtr, len) \
  149. a_netbuf_push(bufPtr, len)
  150. #define A_NETBUF_PUT(bufPtr, len) \
  151. a_netbuf_put(bufPtr, len)
  152. #define A_NETBUF_TRIM(bufPtr, len) \
  153. a_netbuf_trim(bufPtr, len)
  154. #define A_NETBUF_PULL(bufPtr, len) \
  155. a_netbuf_pull(bufPtr, len)
  156. #define A_NETBUF_HEADROOM(bufPtr) \
  157. a_netbuf_headroom(bufPtr)
  158. #define A_NETBUF_SETLEN(bufPtr, len) \
  159. a_netbuf_setlen(bufPtr, len)
  160. /* Add data to end of a buffer */
  161. #define A_NETBUF_PUT_DATA(bufPtr, srcPtr, len) \
  162. a_netbuf_put_data(bufPtr, srcPtr, len)
  163. /* Add data to start of the buffer */
  164. #define A_NETBUF_PUSH_DATA(bufPtr, srcPtr, len) \
  165. a_netbuf_push_data(bufPtr, srcPtr, len)
  166. /* Remove data at start of the buffer */
  167. #define A_NETBUF_PULL_DATA(bufPtr, dstPtr, len) \
  168. a_netbuf_pull_data(bufPtr, dstPtr, len)
  169. /* Remove data from the end of the buffer */
  170. #define A_NETBUF_TRIM_DATA(bufPtr, dstPtr, len) \
  171. a_netbuf_trim_data(bufPtr, dstPtr, len)
  172. /* View data as "size" contiguous bytes of type "t" */
  173. #define A_NETBUF_VIEW_DATA(bufPtr, t, size) \
  174. (t)(((struct skbuf *)(bufPtr))->data)
  175. /* return the beginning of the headroom for the buffer */
  176. #define A_NETBUF_HEAD(bufPtr) \
  177. ((((struct sk_buff *)(bufPtr))->head))
  178. /*
  179. * OS specific network buffer access routines
  180. */
  181. void a_netbuf_free(void *bufPtr);
  182. void *a_netbuf_to_data(void *bufPtr);
  183. A_UINT32 a_netbuf_to_len(void *bufPtr);
  184. A_STATUS a_netbuf_push(void *bufPtr, A_INT32 len);
  185. A_STATUS a_netbuf_push_data(void *bufPtr, char *srcPtr, A_INT32 len);
  186. A_STATUS a_netbuf_put(void *bufPtr, A_INT32 len);
  187. A_STATUS a_netbuf_put_data(void *bufPtr, char *srcPtr, A_INT32 len);
  188. A_STATUS a_netbuf_pull(void *bufPtr, A_INT32 len);
  189. A_STATUS a_netbuf_pull_data(void *bufPtr, char *dstPtr, A_INT32 len);
  190. A_STATUS a_netbuf_trim(void *bufPtr, A_INT32 len);
  191. A_STATUS a_netbuf_trim_data(void *bufPtr, char *dstPtr, A_INT32 len);
  192. A_STATUS a_netbuf_setlen(void *bufPtr, A_INT32 len);
  193. A_INT32 a_netbuf_headroom(void *bufPtr);
  194. void a_netbuf_enqueue(A_NETBUF_QUEUE_T *q, void *pkt);
  195. void a_netbuf_prequeue(A_NETBUF_QUEUE_T *q, void *pkt);
  196. void *a_netbuf_dequeue(A_NETBUF_QUEUE_T *q);
  197. int a_netbuf_queue_size(A_NETBUF_QUEUE_T *q);
  198. int a_netbuf_queue_empty(A_NETBUF_QUEUE_T *q);
  199. int a_netbuf_queue_empty(A_NETBUF_QUEUE_T *q);
  200. void a_netbuf_queue_init(A_NETBUF_QUEUE_T *q);
  201. #ifdef QCA_PARTNER_PLATFORM
  202. #include "ath_carr_pltfrm.h"
  203. #endif /* QCA_PARTNER_PLATFORM */
  204. #else /* __KERNEL__ */
  205. #ifdef __GNUC__
  206. #define __ATTRIB_PACK __attribute__ ((packed))
  207. #define __ATTRIB_PRINTF __attribute__ ((format (printf, 1, 2)))
  208. #define __ATTRIB_NORETURN __attribute__ ((noreturn))
  209. #ifndef inline
  210. #define inline __inline__
  211. #endif
  212. #ifndef INLINE
  213. #define INLINE __inline__
  214. #endif
  215. #else /* Not GCC */
  216. #define __ATTRIB_PACK
  217. #define __ATTRIB_PRINTF
  218. #define __ATTRIB_NORETURN
  219. #ifndef inline
  220. #define inline __inline
  221. #endif
  222. #ifndef INLINE
  223. #define INLINE __inline
  224. #endif
  225. #endif /* End __GNUC__ */
  226. #define PREPACK
  227. #define POSTPACK __ATTRIB_PACK
  228. #define A_MEMCPY(dst, src, len) memcpy((dst), (src), (len))
  229. #define A_MEMSET(addr, value, size) memset((addr), (value), (size))
  230. #define A_MEMZERO(addr, len) memset((addr), 0, (len))
  231. #define A_MEMCMP(addr1, addr2, len) memcmp((addr1), (addr2), (len))
  232. #ifdef ANDROID
  233. #ifndef err
  234. #include <linux/errno.h>
  235. #define err(_s, args ...) do { \
  236. fprintf(stderr, "%s: line %d ", __FILE__, __LINE__); \
  237. fprintf(stderr, args); fprintf(stderr, ": %d\n", errno); \
  238. exit(_s); } while (0)
  239. #endif
  240. #else
  241. #include <linux/err.h>
  242. #endif
  243. #endif /* __KERNEL__ */
  244. #endif /* _OSAPI_LINUX_H_ */