1 /* 2 * Copyright (c) 2013-2017 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 /** 20 * DOC: osdep 21 * This file provides OS abstraction for osdependent APIs. 22 */ 23 24 #ifndef _OSDEP_H 25 #define _OSDEP_H 26 27 #include <qdf_types.h> 28 #include <qdf_mem.h> 29 #include <qdf_lock.h> 30 #include <qdf_time.h> 31 #include <qdf_timer.h> 32 #include <qdf_defer.h> 33 #include <qdf_nbuf.h> 34 #include <i_osdep.h> 35 36 /* 37 * ATH_DEBUG - 38 * Control whether debug features (printouts, assertions) are compiled 39 * into the driver. 40 */ 41 #ifndef ATH_DEBUG 42 #define ATH_DEBUG 1 /* default: include debug code */ 43 #endif 44 45 #if ATH_DEBUG 46 #ifndef ASSERT 47 #define ASSERT(expr) qdf_assert(expr) 48 #endif 49 #else 50 #define ASSERT(expr) 51 #endif /* ATH_DEBUG */ 52 53 /* 54 * Need to define byte order based on the CPU configuration. 55 */ 56 #ifndef _LITTLE_ENDIAN 57 #define _LITTLE_ENDIAN 1234 58 #endif 59 #ifndef _BIG_ENDIAN 60 #define _BIG_ENDIAN 4321 61 #endif 62 #ifdef __BIG_ENDIAN 63 #define _BYTE_ORDER _BIG_ENDIAN 64 #else 65 #define _BYTE_ORDER _LITTLE_ENDIAN 66 #endif 67 68 /* 69 * Deduce if tasklets are available. If not then 70 * fall back to using the immediate work queue. 71 */ 72 #define qdf_sysctl_decl(f, ctl, write, filp, buffer, lenp, ppos) \ 73 f(struct ctl_table *ctl, int32_t write, void *buffer, \ 74 size_t *lenp, loff_t *ppos) 75 76 #define QDF_SYSCTL_PROC_DOINTVEC(ctl, write, filp, buffer, lenp, ppos) \ 77 __QDF_SYSCTL_PROC_DOINTVEC(ctl, write, filp, buffer, lenp, ppos) 78 79 #define QDF_SYSCTL_PROC_DOSTRING(ctl, write, filp, buffer, lenp, ppos) \ 80 __QDF_SYSCTL_PROC_DOSTRING(ctl, write, filp, buffer, lenp, ppos) 81 82 #define EOK (0) 83 84 #ifndef false 85 #define false 0 86 #endif 87 #ifndef true 88 #define true 1 89 #endif 90 91 #ifndef ARPHRD_IEEE80211 92 #define ARPHRD_IEEE80211 801 /* IEEE 802.11. */ 93 #endif 94 95 /* 96 * Normal Delay functions. Time specified in microseconds. 97 */ 98 #define OS_DELAY(_us) qdf_udelay(_us) 99 100 /* 101 * memory data manipulation functions. 102 */ 103 #define OS_MEMCPY(_dst, _src, _len) qdf_mem_copy(_dst, _src, _len) 104 #define OS_MEMMOVE(_dst, _src, _len) qdf_mem_move(_dst, _src, _len) 105 #define OS_MEMZERO(_buf, _len) qdf_mem_zero(_buf, _len) 106 #define OS_MEMSET(_buf, _ch, _len) qdf_mem_set(_buf, _len, _ch) 107 #define OS_MEMCMP(_mem1, _mem2, _len) qdf_mem_cmp(_mem1, _mem2, _len) 108 109 110 /* 111 * System time interface 112 */ 113 typedef qdf_time_t systime_t; 114 typedef qdf_time_t systick_t; 115 116 /** 117 * os_get_timestamp() - gives the timestamp in ticks 118 * Return: unsigned long 119 */ 120 static inline qdf_time_t os_get_timestamp(void) 121 { 122 /* Fix double conversion from jiffies to ms */ 123 return qdf_system_ticks(); 124 } 125 126 struct _NIC_DEV; 127 128 static inline unsigned char *os_malloc(osdev_t nic_dev, 129 unsigned long size_in_bytes, 130 int32_t gfp) 131 { 132 return qdf_mem_malloc(size_in_bytes); 133 } 134 135 #define OS_FREE(_p) qdf_mem_free(_p) 136 137 #define OS_DMA_MEM_CONTEXT(context) \ 138 dma_addr_t context 139 140 #define OS_GET_DMA_MEM_CONTEXT(var, field) \ 141 &(var->field) 142 143 #define OS_COPY_DMA_MEM_CONTEXT(dst, src) \ 144 *dst = *src 145 146 #define OS_ZERO_DMA_MEM_CONTEXT(context) \ 147 *context = 0 148 149 /* 150 * Timer Interfaces. Use these macros to declare timer 151 * and retrieve timer argument. This is mainly for resolving 152 * different argument types for timer function in different OS. 153 */ 154 #define os_timer_func(_fn) \ 155 void _fn(void *timer_arg) 156 157 #define OS_GET_TIMER_ARG(_arg, _type) \ 158 ((_arg) = (_type)(timer_arg)) 159 160 #define OS_DECLARE_TIMER(_fn) void _fn(void *) 161 162 #define OS_INIT_TIMER(_osdev, _timer, _fn, _ctx, type) \ 163 qdf_timer_init(_osdev, _timer, _fn, _ctx, type) 164 165 #define OS_SET_TIMER(_timer, _ms) qdf_timer_mod(_timer, _ms) 166 167 #define OS_CANCEL_TIMER(_timer) qdf_timer_stop(_timer) 168 169 #define OS_FREE_TIMER(_timer) qdf_timer_stop(_timer) 170 171 /* 172 * These are required for network manager support 173 */ 174 #ifndef SET_NETDEV_DEV 175 #define SET_NETDEV_DEV(ndev, pdev) 176 #endif 177 178 #endif /* end of _OSDEP_H */ 179