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