Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame^] | 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 | /* |
| 23 | * This file was originally distributed by Qualcomm Atheros, Inc. |
| 24 | * under proprietary terms before Copyright ownership was assigned |
| 25 | * to the Linux Foundation. |
| 26 | */ |
| 27 | |
| 28 | #ifndef _OSDEP_H |
| 29 | #define _OSDEP_H |
| 30 | |
| 31 | #include <cdf_types.h> |
| 32 | #include <cdf_memory.h> |
| 33 | #include <cdf_lock.h> |
| 34 | #include <cdf_time.h> |
| 35 | #include <cdf_softirq_timer.h> |
| 36 | #include <cdf_defer.h> |
| 37 | #include <cdf_nbuf.h> |
| 38 | #include <cds_if_upperproto.h> |
| 39 | |
| 40 | #include <cds_queue.h> |
| 41 | |
| 42 | /** |
| 43 | * enum ath_hal_bus_type - Supported Bus types |
| 44 | * @HAL_BUS_TYPE_PCI: PCI Bus |
| 45 | * @HAL_BUS_TYPE_AHB: AHB Bus |
| 46 | * @HAL_BUS_TYPE_SNOC: SNOC Bus |
| 47 | * @HAL_BUS_TYPE_SIM: Simulator |
| 48 | */ |
| 49 | enum ath_hal_bus_type { |
| 50 | HAL_BUS_TYPE_PCI, |
| 51 | HAL_BUS_TYPE_AHB, |
| 52 | HAL_BUS_TYPE_SNOC, |
| 53 | HAL_BUS_TYPE_SIM |
| 54 | }; |
| 55 | |
| 56 | /** |
| 57 | * sturct hal_bus_context - Bus to hal context handoff |
| 58 | * @bc_tag: bus context tag |
| 59 | * @bc_handle: bus context handle |
| 60 | * @bc_bustype: bus type |
| 61 | */ |
| 62 | typedef struct hal_bus_context { |
| 63 | int bc_tag; |
| 64 | char *bc_handle; |
| 65 | enum ath_hal_bus_type bc_bustype; |
| 66 | } HAL_BUS_CONTEXT; |
| 67 | |
| 68 | #define INLINE inline |
| 69 | |
| 70 | /* ATH_DEBUG - |
| 71 | * Control whether debug features (printouts, assertions) are compiled |
| 72 | * into the driver. |
| 73 | */ |
| 74 | #ifndef ATH_DEBUG |
| 75 | #define ATH_DEBUG 1 /* default: include debug code */ |
| 76 | #endif |
| 77 | |
| 78 | #if ATH_DEBUG |
| 79 | #ifndef ASSERT |
| 80 | #define ASSERT(expr) cdf_assert(expr) |
| 81 | #endif |
| 82 | #else |
| 83 | #define ASSERT(expr) |
| 84 | #endif /* ATH_DEBUG */ |
| 85 | |
| 86 | /* |
| 87 | * Need to define byte order based on the CPU configuration. |
| 88 | */ |
| 89 | #ifndef _LITTLE_ENDIAN |
| 90 | #define _LITTLE_ENDIAN 1234 |
| 91 | #endif |
| 92 | #ifndef _BIG_ENDIAN |
| 93 | #define _BIG_ENDIAN 4321 |
| 94 | #endif |
| 95 | #ifdef __BIG_ENDIAN |
| 96 | #define _BYTE_ORDER _BIG_ENDIAN |
| 97 | #else |
| 98 | #define _BYTE_ORDER _LITTLE_ENDIAN |
| 99 | #endif |
| 100 | |
| 101 | /* |
| 102 | * Deduce if tasklets are available. If not then |
| 103 | * fall back to using the immediate work queue. |
| 104 | */ |
| 105 | #define ath_sysctl_decl(f, ctl, write, filp, buffer, lenp, ppos) \ |
| 106 | f(struct ctl_table *ctl, int write, void *buffer, \ |
| 107 | size_t *lenp, loff_t *ppos) |
| 108 | #define ATH_SYSCTL_PROC_DOINTVEC(ctl, write, filp, buffer, lenp, ppos) \ |
| 109 | proc_dointvec(ctl, write, buffer, lenp, ppos) |
| 110 | #define ATH_SYSCTL_PROC_DOSTRING(ctl, write, filp, buffer, lenp, ppos) \ |
| 111 | proc_dostring(ctl, write, filp, buffer, lenp, ppos) |
| 112 | |
| 113 | /* |
| 114 | * Byte Order stuff |
| 115 | */ |
| 116 | #define le16toh(_x) le16_to_cpu(_x) |
| 117 | #define htole16(_x) cpu_to_le16(_x) |
| 118 | #define htobe16(_x) cpu_to_be16(_x) |
| 119 | #define le32toh(_x) le32_to_cpu(_x) |
| 120 | #define htole32(_x) cpu_to_le32(_x) |
| 121 | #define be16toh(_x) be16_to_cpu(_x) |
| 122 | #define be32toh(_x) be32_to_cpu(_x) |
| 123 | #define htobe32(_x) cpu_to_be32(_x) |
| 124 | |
| 125 | #define EOK (0) |
| 126 | |
| 127 | #ifndef false |
| 128 | #define false 0 |
| 129 | #endif |
| 130 | #ifndef true |
| 131 | #define true 1 |
| 132 | #endif |
| 133 | |
| 134 | #ifndef ARPHRD_IEEE80211 |
| 135 | #define ARPHRD_IEEE80211 801 /* IEEE 802.11. */ |
| 136 | #endif |
| 137 | |
| 138 | /* |
| 139 | * Normal Delay functions. Time specified in microseconds. |
| 140 | */ |
| 141 | #define OS_DELAY(_us) cdf_udelay(_us) |
| 142 | |
| 143 | /* |
| 144 | * memory data manipulation functions. |
| 145 | */ |
| 146 | #define OS_MEMCPY(_dst, _src, _len) cdf_mem_copy(_dst, _src, _len) |
| 147 | #define OS_MEMMOVE(_dst, _src, _len) cdf_mem_move(_dst, _src, _len) |
| 148 | #define OS_MEMZERO(_buf, _len) cdf_mem_zero(_buf, _len) |
| 149 | #define OS_MEMSET(_buf, _ch, _len) cdf_mem_set(_buf, _len, _ch) |
| 150 | #define OS_MEMCMP(_mem1, _mem2, _len) cdf_mem_compare(_mem1, _mem2, _len) |
| 151 | |
| 152 | #ifdef CONFIG_SMP |
| 153 | /* Undo the one provided by the kernel to debug spin locks */ |
| 154 | #undef spin_lock |
| 155 | #undef spin_unlock |
| 156 | #undef spin_trylock |
| 157 | |
| 158 | #define spin_lock(x) \ |
| 159 | do { \ |
| 160 | spin_lock_bh(x); \ |
| 161 | } while (0) |
| 162 | |
| 163 | #define spin_unlock(x) \ |
| 164 | do { \ |
| 165 | if (!spin_is_locked(x)) { \ |
| 166 | WARN_ON(1); \ |
| 167 | printk(KERN_EMERG " %s:%d unlock addr=%p, %s \n", __func__, __LINE__, x, \ |
| 168 | !spin_is_locked(x) ? "Not locked" : ""); \ |
| 169 | } \ |
| 170 | spin_unlock_bh(x); \ |
| 171 | } while (0) |
| 172 | |
| 173 | #define spin_trylock(x) spin_trylock_bh(x) |
| 174 | |
| 175 | #define OS_SUPPORT_ASYNC_Q 1 /* support for handling asyn function calls */ |
| 176 | |
| 177 | #else |
| 178 | #define OS_SUPPORT_ASYNC_Q 0 |
| 179 | #endif /* ifdef CONFIG_SMP */ |
| 180 | |
| 181 | |
| 182 | /* |
| 183 | * System time interface |
| 184 | */ |
| 185 | typedef cdf_time_t systime_t; |
| 186 | typedef cdf_time_t systick_t; |
| 187 | |
| 188 | static INLINE cdf_time_t os_get_timestamp(void) |
| 189 | { |
| 190 | return cdf_system_ticks(); /* Fix double conversion from jiffies to ms */ |
| 191 | } |
| 192 | |
| 193 | struct _NIC_DEV; |
| 194 | |
| 195 | typedef struct _NIC_DEV *osdev_t; |
| 196 | |
| 197 | typedef struct timer_list os_timer_t; |
| 198 | |
| 199 | typedef struct _os_mesg_t { |
| 200 | STAILQ_ENTRY(_os_mesg_t) mesg_next; |
| 201 | uint16_t mesg_type; |
| 202 | uint16_t mesg_len; |
| 203 | /* followed by mesg_len bytes */ |
| 204 | } os_mesg_t; |
| 205 | |
| 206 | typedef void (*os_mesg_handler_t)(void *ctx, |
| 207 | uint16_t mesg_type, |
| 208 | uint16_t mesg_len, void *mesg); |
| 209 | |
| 210 | typedef struct { |
| 211 | osdev_t dev_handle; |
| 212 | int32_t num_queued; |
| 213 | int32_t mesg_len; |
| 214 | uint8_t *mesg_queue_buf; |
| 215 | STAILQ_HEAD(, _os_mesg_t) mesg_head; /* queued mesg buffers */ |
| 216 | STAILQ_HEAD(, _os_mesg_t) mesg_free_head; /* free mesg buffers */ |
| 217 | spinlock_t lock; |
| 218 | spinlock_t ev_handler_lock; |
| 219 | #ifdef USE_SOFTINTR |
| 220 | void *_task; |
| 221 | #else |
| 222 | os_timer_t _timer; |
| 223 | #endif |
| 224 | os_mesg_handler_t handler; |
| 225 | void *ctx; |
| 226 | uint8_t is_synchronous : 1; |
| 227 | } os_mesg_queue_t; |
| 228 | |
| 229 | /* |
| 230 | * Definition of OS-dependent device structure. |
| 231 | * It'll be opaque to the actual ATH layer. |
| 232 | */ |
| 233 | struct _NIC_DEV { |
| 234 | void *bdev; /* bus device handle */ |
| 235 | struct net_device *netdev; /* net device handle (wifi%d) */ |
| 236 | cdf_bh_t intr_tq; /* tasklet */ |
| 237 | struct net_device_stats devstats; /* net device statisitics */ |
| 238 | HAL_BUS_CONTEXT bc; |
| 239 | #ifdef ATH_PERF_PWR_OFFLOAD |
| 240 | struct device *device; /* generic device */ |
| 241 | wait_queue_head_t event_queue; |
| 242 | #endif /* PERF_PWR_OFFLOAD */ |
| 243 | #if OS_SUPPORT_ASYNC_Q |
| 244 | os_mesg_queue_t async_q; /* mesgq to handle async calls */ |
| 245 | #endif |
| 246 | #ifdef ATH_BUS_PM |
| 247 | uint8_t isDeviceAsleep; |
| 248 | #endif /* ATH_BUS_PM */ |
| 249 | }; |
| 250 | |
| 251 | static INLINE unsigned char *os_malloc(osdev_t pNicDev, |
| 252 | unsigned long ulSizeInBytes, int gfp) |
| 253 | { |
| 254 | return cdf_mem_malloc(ulSizeInBytes); |
| 255 | } |
| 256 | |
| 257 | #define OS_FREE(_p) cdf_mem_free(_p) |
| 258 | |
| 259 | #define OS_DMA_MEM_CONTEXT(context) \ |
| 260 | dma_addr_t context; |
| 261 | |
| 262 | #define OS_GET_DMA_MEM_CONTEXT(var, field) \ |
| 263 | &(var->field) |
| 264 | |
| 265 | #define OS_COPY_DMA_MEM_CONTEXT(dst, src) \ |
| 266 | *dst = *src |
| 267 | |
| 268 | #define OS_ZERO_DMA_MEM_CONTEXT(context) \ |
| 269 | *context = 0 |
| 270 | |
| 271 | /* |
| 272 | * Timer Interfaces. Use these macros to declare timer |
| 273 | * and retrieve timer argument. This is mainly for resolving |
| 274 | * different argument types for timer function in different OS. |
| 275 | */ |
| 276 | #define OS_DECLARE_TIMER(_fn) void _fn(void *) |
| 277 | |
| 278 | #define os_timer_func(_fn) \ |
| 279 | void _fn(void *timer_arg) |
| 280 | |
| 281 | #define OS_GET_TIMER_ARG(_arg, _type) \ |
| 282 | (_arg) = (_type)(timer_arg) |
| 283 | |
| 284 | #define OS_INIT_TIMER(_osdev, _timer, _fn, _ctx, type) \ |
| 285 | cdf_softirq_timer_init(_osdev, _timer, _fn, _ctx, type) |
| 286 | |
| 287 | #define OS_SET_TIMER(_timer, _ms) cdf_softirq_timer_mod(_timer, _ms) |
| 288 | |
| 289 | #define OS_CANCEL_TIMER(_timer) cdf_softirq_timer_cancel(_timer) |
| 290 | |
| 291 | #define OS_FREE_TIMER(_timer) cdf_softirq_timer_cancel(_timer) |
| 292 | |
| 293 | /* |
| 294 | * These are required for network manager support |
| 295 | */ |
| 296 | #ifndef SET_NETDEV_DEV |
| 297 | #define SET_NETDEV_DEV(ndev, pdev) |
| 298 | #endif |
| 299 | |
| 300 | #endif /* end of _OSDEP_H */ |