osapi_linux.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. #if defined(ANDROID_ENV) && defined(CONFIG_ANDROID_LOGGER)
  65. extern unsigned int enablelogcat;
  66. extern int android_logger_lv(void *module, int mask);
  67. enum logidx { LOG_MAIN_IDX = 0 };
  68. extern int logger_write(const enum logidx idx,
  69. const unsigned char prio,
  70. const char __kernel *const tag,
  71. const char __kernel *const fmt, ...);
  72. #define A_ANDROID_PRINTF(mask, module, tags, args ...) do { \
  73. if (enablelogcat) \
  74. logger_write(LOG_MAIN_IDX, android_logger_lv(module, mask), tags, args); \
  75. else \
  76. printk(KERN_ALERT args); \
  77. } while (0)
  78. #ifdef DEBUG
  79. #define A_LOGGER_MODULE_NAME(x) # x
  80. #define A_LOGGER(mask, mod, args ...) \
  81. A_ANDROID_PRINTF(mask, &GET_ATH_MODULE_DEBUG_VAR_NAME(mod), "ar6k_" A_LOGGER_MODULE_NAME(mod), args);
  82. #endif
  83. #define A_PRINTF(args ...) A_ANDROID_PRINTF(ATH_DEBUG_INFO, NULL, "ar6k_driver", args)
  84. #else
  85. #define A_LOGGER(mask, mod, args ...) printk(args)
  86. #define A_PRINTF(args ...) printk(args)
  87. #endif /* ANDROID */
  88. #define A_PRINTF_LOG(args ...) printk(args)
  89. #define A_SNPRINTF(buf, len, args ...) snprintf (buf, len, args)
  90. /*
  91. * Timer Functions
  92. */
  93. #define A_MSLEEP(msecs) \
  94. { \
  95. set_current_state(TASK_INTERRUPTIBLE); \
  96. schedule_timeout((HZ * (msecs)) / 1000); \
  97. set_current_state(TASK_RUNNING); \
  98. }
  99. typedef struct timer_list A_TIMER;
  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. #define wait_event_interruptible_timeout(wq, condition, timeout) \
  127. ({ \
  128. long __ret = timeout; \
  129. if (!(condition)) \
  130. __wait_event_interruptible_timeout(wq, condition, __ret); \
  131. __ret; \
  132. })
  133. #endif /* wait_event_interruptible_timeout */
  134. #ifdef DEBUG
  135. #ifdef A_SIMOS_DEVHOST
  136. extern unsigned int panic_on_assert;
  137. #define A_ASSERT(expr) \
  138. if (!(expr)) { \
  139. printk(KERN_ALERT "Debug Assert Caught, File %s, Line: %d, Test:%s \n",__FILE__, __LINE__,# expr); \
  140. if (panic_on_assert) panic(# expr); \
  141. }
  142. #else
  143. #define A_ASSERT(expr) \
  144. if (!(expr)) { \
  145. printk(KERN_ALERT "Debug Assert Caught, File %s, Line: %d, Test:%s \n",__FILE__, __LINE__,# expr); \
  146. }
  147. #endif
  148. #else
  149. #define A_ASSERT(expr)
  150. #endif /* DEBUG */
  151. #ifdef ANDROID_ENV
  152. struct firmware;
  153. int android_request_firmware(const struct firmware **firmware_p,
  154. const char *filename, struct device *device);
  155. void android_release_firmware(const struct firmware *firmware);
  156. #define A_REQUEST_FIRMWARE(_ppf, _pfile, _dev) android_request_firmware(_ppf, _pfile, _dev)
  157. #define A_RELEASE_FIRMWARE(_pf) android_release_firmware(_pf)
  158. #else
  159. #define A_REQUEST_FIRMWARE(_ppf, _pfile, _dev) request_firmware(_ppf, _pfile, _dev)
  160. #define A_RELEASE_FIRMWARE(_pf) release_firmware(_pf)
  161. #endif
  162. /*
  163. * Network buffer queue support
  164. */
  165. typedef struct sk_buff_head A_NETBUF_QUEUE_T;
  166. #define A_NETBUF_FREE(bufPtr) \
  167. a_netbuf_free(bufPtr)
  168. #define A_NETBUF_LEN(bufPtr) \
  169. a_netbuf_to_len(bufPtr)
  170. #define A_NETBUF_PUSH(bufPtr, len) \
  171. a_netbuf_push(bufPtr, len)
  172. #define A_NETBUF_PUT(bufPtr, len) \
  173. a_netbuf_put(bufPtr, len)
  174. #define A_NETBUF_TRIM(bufPtr,len) \
  175. a_netbuf_trim(bufPtr, len)
  176. #define A_NETBUF_PULL(bufPtr, len) \
  177. a_netbuf_pull(bufPtr, len)
  178. #define A_NETBUF_HEADROOM(bufPtr) \
  179. a_netbuf_headroom(bufPtr)
  180. #define A_NETBUF_SETLEN(bufPtr,len) \
  181. a_netbuf_setlen(bufPtr, len)
  182. /* Add data to end of a buffer */
  183. #define A_NETBUF_PUT_DATA(bufPtr, srcPtr, len) \
  184. a_netbuf_put_data(bufPtr, srcPtr, len)
  185. /* Add data to start of the buffer */
  186. #define A_NETBUF_PUSH_DATA(bufPtr, srcPtr, len) \
  187. a_netbuf_push_data(bufPtr, srcPtr, len)
  188. /* Remove data at start of the buffer */
  189. #define A_NETBUF_PULL_DATA(bufPtr, dstPtr, len) \
  190. a_netbuf_pull_data(bufPtr, dstPtr, len)
  191. /* Remove data from the end of the buffer */
  192. #define A_NETBUF_TRIM_DATA(bufPtr, dstPtr, len) \
  193. a_netbuf_trim_data(bufPtr, dstPtr, len)
  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. /* return the beginning of the headroom for the buffer */
  198. #define A_NETBUF_HEAD(bufPtr) \
  199. ((((struct sk_buff *)(bufPtr))->head))
  200. /*
  201. * OS specific network buffer access routines
  202. */
  203. void a_netbuf_free(void *bufPtr);
  204. void *a_netbuf_to_data(void *bufPtr);
  205. A_UINT32 a_netbuf_to_len(void *bufPtr);
  206. A_STATUS a_netbuf_push(void *bufPtr, A_INT32 len);
  207. A_STATUS a_netbuf_push_data(void *bufPtr, char *srcPtr, A_INT32 len);
  208. A_STATUS a_netbuf_put(void *bufPtr, A_INT32 len);
  209. A_STATUS a_netbuf_put_data(void *bufPtr, char *srcPtr, A_INT32 len);
  210. A_STATUS a_netbuf_pull(void *bufPtr, A_INT32 len);
  211. A_STATUS a_netbuf_pull_data(void *bufPtr, char *dstPtr, A_INT32 len);
  212. A_STATUS a_netbuf_trim(void *bufPtr, A_INT32 len);
  213. A_STATUS a_netbuf_trim_data(void *bufPtr, char *dstPtr, A_INT32 len);
  214. A_STATUS a_netbuf_setlen(void *bufPtr, A_INT32 len);
  215. A_INT32 a_netbuf_headroom(void *bufPtr);
  216. void a_netbuf_enqueue(A_NETBUF_QUEUE_T *q, void *pkt);
  217. void a_netbuf_prequeue(A_NETBUF_QUEUE_T *q, void *pkt);
  218. void *a_netbuf_dequeue(A_NETBUF_QUEUE_T *q);
  219. int a_netbuf_queue_size(A_NETBUF_QUEUE_T *q);
  220. int a_netbuf_queue_empty(A_NETBUF_QUEUE_T *q);
  221. int a_netbuf_queue_empty(A_NETBUF_QUEUE_T *q);
  222. void a_netbuf_queue_init(A_NETBUF_QUEUE_T *q);
  223. #ifdef QCA_PARTNER_PLATFORM
  224. #include "ath_carr_pltfrm.h"
  225. #endif /* QCA_PARTNER_PLATFORM */
  226. #else /* __KERNEL__ */
  227. #ifdef __GNUC__
  228. #define __ATTRIB_PACK __attribute__ ((packed))
  229. #define __ATTRIB_PRINTF __attribute__ ((format (printf, 1, 2)))
  230. #define __ATTRIB_NORETURN __attribute__ ((noreturn))
  231. #ifndef INLINE
  232. #define INLINE __inline__
  233. #endif
  234. #else /* Not GCC */
  235. #define __ATTRIB_PACK
  236. #define __ATTRIB_PRINTF
  237. #define __ATTRIB_NORETURN
  238. #ifndef INLINE
  239. #define INLINE __inline
  240. #endif
  241. #endif /* End __GNUC__ */
  242. #define PREPACK
  243. #define POSTPACK __ATTRIB_PACK
  244. #define A_MEMCPY(dst, src, len) memcpy((dst), (src), (len))
  245. #define A_MEMSET(addr, value, size) memset((addr), (value), (size))
  246. #define A_MEMZERO(addr, len) memset((addr), 0, (len))
  247. #define A_MEMCMP(addr1, addr2, len) memcmp((addr1), (addr2), (len))
  248. #ifdef ANDROID
  249. #ifndef err
  250. #include <errno.h>
  251. #define err(_s, args ...) do { \
  252. fprintf(stderr, "%s: line %d ", __FILE__, __LINE__); \
  253. fprintf(stderr, args); fprintf(stderr, ": %d\n", errno); \
  254. exit(_s); } while (0)
  255. #endif
  256. #else
  257. #include <err.h>
  258. #endif
  259. #endif /* __KERNEL__ */
  260. #endif /* _OSAPI_LINUX_H_ */