osapi_linux.h 8.7 KB

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