1*5113495bSYour Name /* 2*5113495bSYour Name * Copyright (c) 2013-2018, 2021 The Linux Foundation. All rights reserved. 3*5113495bSYour Name * 4*5113495bSYour Name * Permission to use, copy, modify, and/or distribute this software for 5*5113495bSYour Name * any purpose with or without fee is hereby granted, provided that the 6*5113495bSYour Name * above copyright notice and this permission notice appear in all 7*5113495bSYour Name * copies. 8*5113495bSYour Name * 9*5113495bSYour Name * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 10*5113495bSYour Name * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 11*5113495bSYour Name * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 12*5113495bSYour Name * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 13*5113495bSYour Name * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 14*5113495bSYour Name * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 15*5113495bSYour Name * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 16*5113495bSYour Name * PERFORMANCE OF THIS SOFTWARE. 17*5113495bSYour Name */ 18*5113495bSYour Name 19*5113495bSYour Name /* ------------------------------------------------------------------------------ */ 20*5113495bSYour Name /* This file contains the definitions of the basic atheros data types. */ 21*5113495bSYour Name /* It is used to map the data types in atheros files to a platform specific */ 22*5113495bSYour Name /* type. */ 23*5113495bSYour Name /* ------------------------------------------------------------------------------ */ 24*5113495bSYour Name 25*5113495bSYour Name #ifndef _OSAPI_LINUX_H_ 26*5113495bSYour Name #define _OSAPI_LINUX_H_ 27*5113495bSYour Name 28*5113495bSYour Name #ifdef __KERNEL__ 29*5113495bSYour Name 30*5113495bSYour Name #include <linux/version.h> 31*5113495bSYour Name #include <generated/autoconf.h> 32*5113495bSYour Name #include <linux/types.h> 33*5113495bSYour Name #include <linux/kernel.h> 34*5113495bSYour Name #include <linux/string.h> 35*5113495bSYour Name #include <linux/skbuff.h> 36*5113495bSYour Name #include <linux/netdevice.h> 37*5113495bSYour Name #include <linux/jiffies.h> 38*5113495bSYour Name #include <linux/timer.h> 39*5113495bSYour Name #include <linux/delay.h> 40*5113495bSYour Name #include <linux/wait.h> 41*5113495bSYour Name #include <linux/semaphore.h> 42*5113495bSYour Name 43*5113495bSYour Name #include <linux/cache.h> 44*5113495bSYour Name /* #include <linux/kthread.h> */ 45*5113495bSYour Name #include "a_types.h" 46*5113495bSYour Name 47*5113495bSYour Name #ifdef __GNUC__ 48*5113495bSYour Name #define __ATTRIB_PACK __attribute__ ((packed)) 49*5113495bSYour Name #define __ATTRIB_PRINTF __attribute__ ((format (printf, 1, 2))) 50*5113495bSYour Name #define __ATTRIB_NORETURN __attribute__ ((noreturn)) 51*5113495bSYour Name #ifndef INLINE 52*5113495bSYour Name #define INLINE __inline__ 53*5113495bSYour Name #endif 54*5113495bSYour Name #else /* Not GCC */ 55*5113495bSYour Name #define __ATTRIB_PACK 56*5113495bSYour Name #define __ATTRIB_PRINTF 57*5113495bSYour Name #define __ATTRIB_NORETURN 58*5113495bSYour Name #ifndef INLINE 59*5113495bSYour Name #define INLINE __inline 60*5113495bSYour Name #endif 61*5113495bSYour Name #endif /* End __GNUC__ */ 62*5113495bSYour Name 63*5113495bSYour Name #define PREPACK 64*5113495bSYour Name #define POSTPACK __ATTRIB_PACK 65*5113495bSYour Name 66*5113495bSYour Name #define A_MEMCPY(dst, src, len) memcpy((A_UINT8 *)(dst), (src), (len)) 67*5113495bSYour Name #define A_MEMZERO(addr, len) memset(addr, 0, len) 68*5113495bSYour Name #define A_MEMSET(addr, value, size) memset((addr), (value), (size)) 69*5113495bSYour Name #define A_MEMCMP(addr1, addr2, len) memcmp((addr1), (addr2), (len)) 70*5113495bSYour Name 71*5113495bSYour Name #define A_LOGGER(mask, mod, args ...) \ 72*5113495bSYour Name QDF_TRACE_ERROR(QDF_MODULE_ID_QDF, args) 73*5113495bSYour Name #define A_PRINTF(args ...) \ 74*5113495bSYour Name QDF_TRACE_ERROR(QDF_MODULE_ID_QDF, args) 75*5113495bSYour Name #define A_SNPRINTF(buf, len, args ...) snprintf(buf, len, args) 76*5113495bSYour Name #define A_OFFSETOF(type, field) offsetof(type, field) 77*5113495bSYour Name 78*5113495bSYour Name /* 79*5113495bSYour Name * Timer Functions 80*5113495bSYour Name */ 81*5113495bSYour Name #define A_MSLEEP(msecs) \ 82*5113495bSYour Name { \ 83*5113495bSYour Name set_current_state(TASK_INTERRUPTIBLE); \ 84*5113495bSYour Name schedule_timeout((HZ * (msecs)) / 1000); \ 85*5113495bSYour Name set_current_state(TASK_RUNNING); \ 86*5113495bSYour Name } 87*5113495bSYour Name 88*5113495bSYour Name typedef struct timer_list A_TIMER; 89*5113495bSYour Name 90*5113495bSYour Name /* 91*5113495bSYour Name * Wait Queue related functions 92*5113495bSYour Name */ 93*5113495bSYour Name #ifndef wait_event_interruptible_timeout 94*5113495bSYour Name #define __wait_event_interruptible_timeout(wq, condition, ret) \ 95*5113495bSYour Name do { \ 96*5113495bSYour Name wait_queue_t __wait; \ 97*5113495bSYour Name init_waitqueue_entry(&__wait, current); \ 98*5113495bSYour Name \ 99*5113495bSYour Name add_wait_queue(&wq, &__wait); \ 100*5113495bSYour Name for (;; ) { \ 101*5113495bSYour Name set_current_state(TASK_INTERRUPTIBLE); \ 102*5113495bSYour Name if (condition) \ 103*5113495bSYour Name break; \ 104*5113495bSYour Name if (!signal_pending(current)) { \ 105*5113495bSYour Name ret = schedule_timeout(ret); \ 106*5113495bSYour Name if (!ret) \ 107*5113495bSYour Name break; \ 108*5113495bSYour Name continue; \ 109*5113495bSYour Name } \ 110*5113495bSYour Name ret = -ERESTARTSYS; \ 111*5113495bSYour Name break; \ 112*5113495bSYour Name } \ 113*5113495bSYour Name current->state = TASK_RUNNING; \ 114*5113495bSYour Name remove_wait_queue(&wq, &__wait); \ 115*5113495bSYour Name } while (0) 116*5113495bSYour Name 117*5113495bSYour Name #define wait_event_interruptible_timeout(wq, condition, timeout) \ 118*5113495bSYour Name ({ \ 119*5113495bSYour Name long __ret = timeout; \ 120*5113495bSYour Name if (!(condition)) \ 121*5113495bSYour Name __wait_event_interruptible_timeout(wq, condition, __ret); \ 122*5113495bSYour Name __ret; \ 123*5113495bSYour Name }) 124*5113495bSYour Name #endif /* wait_event_interruptible_timeout */ 125*5113495bSYour Name 126*5113495bSYour Name #ifdef WLAN_DEBUG 127*5113495bSYour Name #ifdef A_SIMOS_DEVHOST 128*5113495bSYour Name extern unsigned int panic_on_assert; 129*5113495bSYour Name #define A_ASSERT(expr) \ 130*5113495bSYour Name if (!(expr)) { \ 131*5113495bSYour Name printk(KERN_ALERT "Debug Assert Caught, File %s, Line: %d, Test:%s\n", __FILE__, __LINE__, # expr); \ 132*5113495bSYour Name if (panic_on_assert) panic(# expr); \ 133*5113495bSYour Name } 134*5113495bSYour Name #else 135*5113495bSYour Name #define A_ASSERT(expr) \ 136*5113495bSYour Name if (!(expr)) { \ 137*5113495bSYour Name printk(KERN_ALERT "Debug Assert Caught, File %s, Line: %d, Test:%s\n", __FILE__, __LINE__, # expr); \ 138*5113495bSYour Name } 139*5113495bSYour Name #endif 140*5113495bSYour Name #else 141*5113495bSYour Name #define A_ASSERT(expr) 142*5113495bSYour Name #endif /* DEBUG */ 143*5113495bSYour Name 144*5113495bSYour Name #ifdef ANDROID_ENV 145*5113495bSYour Name struct firmware; 146*5113495bSYour Name int android_request_firmware(const struct firmware **firmware_p, 147*5113495bSYour Name const char *filename, struct device *device); 148*5113495bSYour Name void android_release_firmware(const struct firmware *firmware); 149*5113495bSYour Name #define A_REQUEST_FIRMWARE(_ppf, _pfile, _dev) android_request_firmware(_ppf, _pfile, _dev) 150*5113495bSYour Name #define A_RELEASE_FIRMWARE(_pf) android_release_firmware(_pf) 151*5113495bSYour Name #else 152*5113495bSYour Name #define A_REQUEST_FIRMWARE(_ppf, _pfile, _dev) request_firmware(_ppf, _pfile, _dev) 153*5113495bSYour Name #define A_RELEASE_FIRMWARE(_pf) release_firmware(_pf) 154*5113495bSYour Name #endif 155*5113495bSYour Name 156*5113495bSYour Name /* 157*5113495bSYour Name * Network buffer queue support 158*5113495bSYour Name */ 159*5113495bSYour Name typedef struct sk_buff_head A_NETBUF_QUEUE_T; 160*5113495bSYour Name 161*5113495bSYour Name #define A_NETBUF_FREE(bufPtr) \ 162*5113495bSYour Name a_netbuf_free(bufPtr) 163*5113495bSYour Name #define A_NETBUF_LEN(bufPtr) \ 164*5113495bSYour Name a_netbuf_to_len(bufPtr) 165*5113495bSYour Name #define A_NETBUF_PUSH(bufPtr, len) \ 166*5113495bSYour Name a_netbuf_push(bufPtr, len) 167*5113495bSYour Name #define A_NETBUF_PUT(bufPtr, len) \ 168*5113495bSYour Name a_netbuf_put(bufPtr, len) 169*5113495bSYour Name #define A_NETBUF_TRIM(bufPtr, len) \ 170*5113495bSYour Name a_netbuf_trim(bufPtr, len) 171*5113495bSYour Name #define A_NETBUF_PULL(bufPtr, len) \ 172*5113495bSYour Name a_netbuf_pull(bufPtr, len) 173*5113495bSYour Name #define A_NETBUF_HEADROOM(bufPtr) \ 174*5113495bSYour Name a_netbuf_headroom(bufPtr) 175*5113495bSYour Name #define A_NETBUF_SETLEN(bufPtr, len) \ 176*5113495bSYour Name a_netbuf_setlen(bufPtr, len) 177*5113495bSYour Name 178*5113495bSYour Name /* Add data to end of a buffer */ 179*5113495bSYour Name #define A_NETBUF_PUT_DATA(bufPtr, srcPtr, len) \ 180*5113495bSYour Name a_netbuf_put_data(bufPtr, srcPtr, len) 181*5113495bSYour Name 182*5113495bSYour Name /* Add data to start of the buffer */ 183*5113495bSYour Name #define A_NETBUF_PUSH_DATA(bufPtr, srcPtr, len) \ 184*5113495bSYour Name a_netbuf_push_data(bufPtr, srcPtr, len) 185*5113495bSYour Name 186*5113495bSYour Name /* Remove data at start of the buffer */ 187*5113495bSYour Name #define A_NETBUF_PULL_DATA(bufPtr, dstPtr, len) \ 188*5113495bSYour Name a_netbuf_pull_data(bufPtr, dstPtr, len) 189*5113495bSYour Name 190*5113495bSYour Name /* Remove data from the end of the buffer */ 191*5113495bSYour Name #define A_NETBUF_TRIM_DATA(bufPtr, dstPtr, len) \ 192*5113495bSYour Name a_netbuf_trim_data(bufPtr, dstPtr, len) 193*5113495bSYour Name 194*5113495bSYour Name /* View data as "size" contiguous bytes of type "t" */ 195*5113495bSYour Name #define A_NETBUF_VIEW_DATA(bufPtr, t, size) \ 196*5113495bSYour Name (t)(((struct skbuf *)(bufPtr))->data) 197*5113495bSYour Name 198*5113495bSYour Name /* return the beginning of the headroom for the buffer */ 199*5113495bSYour Name #define A_NETBUF_HEAD(bufPtr) \ 200*5113495bSYour Name ((((struct sk_buff *)(bufPtr))->head)) 201*5113495bSYour Name 202*5113495bSYour Name /* 203*5113495bSYour Name * OS specific network buffer access routines 204*5113495bSYour Name */ 205*5113495bSYour Name void a_netbuf_free(void *bufPtr); 206*5113495bSYour Name void *a_netbuf_to_data(void *bufPtr); 207*5113495bSYour Name A_UINT32 a_netbuf_to_len(void *bufPtr); 208*5113495bSYour Name A_STATUS a_netbuf_push(void *bufPtr, A_INT32 len); 209*5113495bSYour Name A_STATUS a_netbuf_push_data(void *bufPtr, char *srcPtr, A_INT32 len); 210*5113495bSYour Name A_STATUS a_netbuf_put(void *bufPtr, A_INT32 len); 211*5113495bSYour Name A_STATUS a_netbuf_put_data(void *bufPtr, char *srcPtr, A_INT32 len); 212*5113495bSYour Name A_STATUS a_netbuf_pull(void *bufPtr, A_INT32 len); 213*5113495bSYour Name A_STATUS a_netbuf_pull_data(void *bufPtr, char *dstPtr, A_INT32 len); 214*5113495bSYour Name A_STATUS a_netbuf_trim(void *bufPtr, A_INT32 len); 215*5113495bSYour Name A_STATUS a_netbuf_trim_data(void *bufPtr, char *dstPtr, A_INT32 len); 216*5113495bSYour Name A_STATUS a_netbuf_setlen(void *bufPtr, A_INT32 len); 217*5113495bSYour Name A_INT32 a_netbuf_headroom(void *bufPtr); 218*5113495bSYour Name void a_netbuf_enqueue(A_NETBUF_QUEUE_T *q, void *pkt); 219*5113495bSYour Name void a_netbuf_prequeue(A_NETBUF_QUEUE_T *q, void *pkt); 220*5113495bSYour Name void *a_netbuf_dequeue(A_NETBUF_QUEUE_T *q); 221*5113495bSYour Name int a_netbuf_queue_size(A_NETBUF_QUEUE_T *q); 222*5113495bSYour Name int a_netbuf_queue_empty(A_NETBUF_QUEUE_T *q); 223*5113495bSYour Name int a_netbuf_queue_empty(A_NETBUF_QUEUE_T *q); 224*5113495bSYour Name void a_netbuf_queue_init(A_NETBUF_QUEUE_T *q); 225*5113495bSYour Name 226*5113495bSYour Name #ifdef QCA_PARTNER_PLATFORM 227*5113495bSYour Name #include "ath_carr_pltfrm.h" 228*5113495bSYour Name #endif /* QCA_PARTNER_PLATFORM */ 229*5113495bSYour Name 230*5113495bSYour Name #else /* __KERNEL__ */ 231*5113495bSYour Name 232*5113495bSYour Name #ifdef __GNUC__ 233*5113495bSYour Name #define __ATTRIB_PACK __attribute__ ((packed)) 234*5113495bSYour Name #define __ATTRIB_PRINTF __attribute__ ((format (printf, 1, 2))) 235*5113495bSYour Name #define __ATTRIB_NORETURN __attribute__ ((noreturn)) 236*5113495bSYour Name #ifndef inline 237*5113495bSYour Name #define inline __inline__ 238*5113495bSYour Name #endif 239*5113495bSYour Name #ifndef INLINE 240*5113495bSYour Name #define INLINE __inline__ 241*5113495bSYour Name #endif 242*5113495bSYour Name #else /* Not GCC */ 243*5113495bSYour Name #define __ATTRIB_PACK 244*5113495bSYour Name #define __ATTRIB_PRINTF 245*5113495bSYour Name #define __ATTRIB_NORETURN 246*5113495bSYour Name #ifndef inline 247*5113495bSYour Name #define inline __inline 248*5113495bSYour Name #endif 249*5113495bSYour Name #ifndef INLINE 250*5113495bSYour Name #define INLINE __inline 251*5113495bSYour Name #endif 252*5113495bSYour Name #endif /* End __GNUC__ */ 253*5113495bSYour Name 254*5113495bSYour Name #define PREPACK 255*5113495bSYour Name #define POSTPACK __ATTRIB_PACK 256*5113495bSYour Name 257*5113495bSYour Name #define A_MEMCPY(dst, src, len) memcpy((dst), (src), (len)) 258*5113495bSYour Name #define A_MEMSET(addr, value, size) memset((addr), (value), (size)) 259*5113495bSYour Name #define A_MEMZERO(addr, len) memset((addr), 0, (len)) 260*5113495bSYour Name #define A_MEMCMP(addr1, addr2, len) memcmp((addr1), (addr2), (len)) 261*5113495bSYour Name 262*5113495bSYour Name #ifdef ANDROID 263*5113495bSYour Name #ifndef err 264*5113495bSYour Name #include <linux/errno.h> 265*5113495bSYour Name #define err(_s, args ...) do { \ 266*5113495bSYour Name fprintf(stderr, "%s: line %d ", __FILE__, __LINE__); \ 267*5113495bSYour Name fprintf(stderr, args); fprintf(stderr, ": %d\n", errno); \ 268*5113495bSYour Name exit(_s); } while (0) 269*5113495bSYour Name #endif 270*5113495bSYour Name #else 271*5113495bSYour Name #include <linux/err.h> 272*5113495bSYour Name #endif 273*5113495bSYour Name 274*5113495bSYour Name #endif /* __KERNEL__ */ 275*5113495bSYour Name 276*5113495bSYour Name #endif /* _OSAPI_LINUX_H_ */ 277