1 /* 2 * Copyright (c) 2014-2018 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 /** 29 * DOC: i_qdf_types.h 30 * This file provides OS dependent types API's. 31 */ 32 33 #if !defined(__I_QDF_TYPES_H) 34 #define __I_QDF_TYPES_H 35 36 #include <qdf_status.h> 37 38 #ifndef __KERNEL__ 39 #define __iomem 40 #endif 41 #include <asm/types.h> 42 #include <asm/byteorder.h> 43 #include <linux/version.h> 44 45 #ifndef __ahdecl 46 #ifdef __i386__ 47 #define __ahdecl __attribute__((regparm(0))) 48 #else 49 #define __ahdecl 50 #endif 51 #endif 52 53 #ifdef __KERNEL__ 54 #include <generated/autoconf.h> 55 #include <linux/list.h> 56 #include <linux/mutex.h> 57 #include <linux/types.h> 58 #include <linux/ctype.h> 59 #include <linux/sched.h> 60 #include <linux/completion.h> 61 #include <linux/string.h> 62 #include <linux/slab.h> 63 #include <linux/interrupt.h> 64 #include <linux/version.h> 65 #include <asm/div64.h> 66 #include <linux/compiler.h> 67 #include <linux/dma-mapping.h> 68 #include <linux/wireless.h> 69 #include <linux/if.h> 70 #ifdef IPA_OFFLOAD 71 #include <linux/ipa.h> 72 #endif 73 74 typedef struct sg_table __sgtable_t; 75 76 /* 77 * The IDs of the various system clocks 78 */ 79 #define __QDF_CLOCK_REALTIME CLOCK_REALTIME 80 #define __QDF_CLOCK_MONOTONIC CLOCK_MONOTONIC 81 82 /* 83 * Return values for the qdf_hrtimer_data_t callback function 84 */ 85 #define __QDF_HRTIMER_NORESTART HRTIMER_NORESTART 86 #define __QDF_HRTIMER_RESTART HRTIMER_RESTART 87 88 /* 89 * Mode arguments of qdf_hrtimer_data_t related functions 90 */ 91 #define __QDF_HRTIMER_MODE_ABS HRTIMER_MODE_ABS 92 #define __QDF_HRTIMER_MODE_REL HRTIMER_MODE_REL 93 #define __QDF_HRTIMER_MODE_PINNED HRTIMER_MODE_PINNED 94 95 #else 96 97 /* 98 * Hack - coexist with prior defs of dma_addr_t. 99 * Eventually all other defs of dma_addr_t should be removed. 100 * At that point, the "already_defined" wrapper can be removed. 101 */ 102 #ifndef __dma_addr_t_already_defined__ 103 #define __dma_addr_t_already_defined__ 104 typedef unsigned long dma_addr_t; 105 #endif 106 107 typedef unsigned long phys_addr_t; 108 typedef unsigned long __sgtable_t; 109 110 #define SIOCGIWAP 0 111 #define IWEVCUSTOM 0 112 #define IWEVREGISTERED 0 113 #define IWEVEXPIRED 0 114 #define SIOCGIWSCAN 0 115 #define DMA_TO_DEVICE 0 116 #define DMA_BIDIRECTIONAL 0 117 #define DMA_FROM_DEVICE 0 118 #define __QDF_CLOCK_REALTIME 0 119 #define __QDF_CLOCK_MONOTONIC 0 120 #define __QDF_HRTIMER_MODE_ABS 0 121 #define __QDF_HRTIMER_MODE_REL 0 122 #define __QDF_HRTIMER_MODE_PINNED 0 123 #define __QDF_HRTIMER_NORESTART 0 124 #define __QDF_HRTIMER_RESTART 0 125 #define __iomem 126 #endif /* __KERNEL__ */ 127 128 /* 129 * max sg that we support 130 */ 131 #define __QDF_MAX_SCATTER 1 132 #define __QDF_NSEC_PER_MSEC NSEC_PER_MSEC 133 134 #if defined(__LITTLE_ENDIAN_BITFIELD) 135 #define QDF_LITTLE_ENDIAN_MACHINE 136 #elif defined(__BIG_ENDIAN_BITFIELD) 137 #define QDF_BIG_ENDIAN_MACHINE 138 #else 139 #error "Please fix <asm/byteorder.h>" 140 #endif 141 142 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20) || !defined(__KERNEL__) 143 #ifndef __bool_already_defined__ 144 #define __bool_already_defined__ 145 146 /** 147 * bool - This is an enum for boolean 148 * @false: zero 149 * @true: one 150 */ 151 typedef enum bool { 152 false = 0, 153 true = 1, 154 } bool; 155 #endif /* __bool_already_defined__ */ 156 #endif 157 158 #define __qdf_packed __attribute__((packed)) 159 160 typedef int (*__qdf_os_intr)(void *); 161 /** 162 * Private definitions of general data types 163 */ 164 typedef dma_addr_t __qdf_dma_addr_t; 165 typedef size_t __qdf_dma_size_t; 166 typedef dma_addr_t __qdf_dma_context_t; 167 typedef struct net_device *__qdf_netdev_t; 168 typedef __le16 __qdf_le16_t; 169 typedef __le32 __qdf_le32_t; 170 typedef __le64 __qdf_le64_t; 171 typedef __be16 __qdf_be16_t; 172 typedef __be32 __qdf_be32_t; 173 typedef __be64 __qdf_be64_t; 174 175 #ifdef IPA_OFFLOAD 176 typedef struct ipa_wdi_buffer_info __qdf_mem_info_t; 177 #else 178 /** 179 * struct __qdf_shared_mem_info - shared mem info struct 180 * @pa : physical address 181 * @iova: i/o virtual address 182 * @size: allocated memory size 183 * @result: status 184 */ 185 typedef struct __qdf_shared_mem_info { 186 phys_addr_t pa; 187 unsigned long iova; 188 size_t size; 189 int result; 190 } __qdf_mem_info_t; 191 #endif /* IPA_OFFLOAD */ 192 193 #define qdf_dma_mem_context(context) dma_addr_t context 194 #define qdf_get_dma_mem_context(var, field) ((qdf_dma_context_t)(var->field)) 195 196 /** 197 * typedef struct __qdf_resource_t - qdf resource type 198 * @paddr: Physical address 199 * @paddr: Virtual address 200 * @len: Length 201 */ 202 typedef struct __qdf_resource { 203 unsigned long paddr; 204 void __iomem *vaddr; 205 unsigned long len; 206 } __qdf_resource_t; 207 208 struct __qdf_mempool_ctxt; 209 210 #define MAX_MEM_POOLS 64 211 212 /** 213 * enum qdf_bus_type - Supported Bus types 214 * @QDF_BUS_TYPE_NONE: None Bus type for error check 215 * @QDF_BUS_TYPE_PCI: PCI Bus 216 * @QDF_BUS_TYPE_AHB: AHB Bus 217 * @QDF_BUS_TYPE_SNOC: SNOC Bus 218 * @QDF_BUS_TYPE_SIM: Simulator 219 * @QDF_BUS_TYPE_USB: USB Bus 220 */ 221 enum qdf_bus_type { 222 QDF_BUS_TYPE_NONE = -1, 223 QDF_BUS_TYPE_PCI = 0, 224 QDF_BUS_TYPE_AHB, 225 QDF_BUS_TYPE_SNOC, 226 QDF_BUS_TYPE_SIM, 227 QDF_BUS_TYPE_SDIO, 228 QDF_BUS_TYPE_USB 229 }; 230 231 /** 232 * struct __qdf_device - generic qdf device type 233 * @drv: Pointer to driver 234 * @drv_hdl: Pointer to driver handle 235 * @drv_name: Pointer to driver name 236 * @irq: IRQ 237 * @dev: Pointer to device 238 * @res: QDF resource 239 * @func: Interrupt handler 240 * @mem_pool: array of pointers to mem pool context 241 * @bus_type: Bus type 242 * @bid: Bus ID 243 * @smmu_s1_enabled: SMMU S1 enabled or not 244 * @iommu_mapping: DMA iommu mapping pointer 245 */ 246 struct __qdf_device { 247 void *drv; 248 void *drv_hdl; 249 char *drv_name; 250 int irq; 251 struct device *dev; 252 __qdf_resource_t res; 253 __qdf_os_intr func; 254 struct __qdf_mempool_ctxt *mem_pool[MAX_MEM_POOLS]; 255 enum qdf_bus_type bus_type; 256 #ifdef CONFIG_MCL 257 const struct hif_bus_id *bid; 258 #endif 259 bool smmu_s1_enabled; 260 struct dma_iommu_mapping *iommu_mapping; 261 }; 262 typedef struct __qdf_device *__qdf_device_t; 263 264 typedef size_t __qdf_size_t; 265 typedef off_t __qdf_off_t; 266 typedef uint8_t __iomem *__qdf_iomem_t; 267 268 typedef uint32_t ath_dma_addr_t; 269 270 /** 271 * typedef __qdf_segment_t - segment of memory 272 * @daddr: dma address 273 * @len: lenght of segment 274 */ 275 typedef struct __qdf_segment { 276 dma_addr_t daddr; 277 uint32_t len; 278 } __qdf_segment_t; 279 280 /** 281 * __qdf_dma_map - dma map of memory 282 * @mapped: mapped address 283 * @nsegs: number of segments 284 * @coherent: coherency status 285 * @seg: segment of memory 286 */ 287 struct __qdf_dma_map { 288 uint32_t mapped; 289 uint32_t nsegs; 290 uint32_t coherent; 291 __qdf_segment_t seg[__QDF_MAX_SCATTER]; 292 }; 293 typedef struct __qdf_dma_map *__qdf_dma_map_t; 294 295 /** 296 * __qdf_net_wireless_evcode - enum for event code 297 * @__QDF_IEEE80211_ASSOC: association event code 298 * @__QDF_IEEE80211_REASSOC: reassociation event code 299 * @__QDF_IEEE80211_DISASSOC: disassociation event code 300 * @__QDF_IEEE80211_JOIN: join event code 301 * @__QDF_IEEE80211_LEAVE: leave event code 302 * @__QDF_IEEE80211_SCAN: scan event code 303 * @__QDF_IEEE80211_REPLAY: replay event code 304 * @__QDF_IEEE80211_MICHAEL:michael event code 305 * @__QDF_IEEE80211_REJOIN: rejoin event code 306 * @__QDF_CUSTOM_PUSH_BUTTON: push button event code 307 */ 308 enum __qdf_net_wireless_evcode { 309 __QDF_IEEE80211_ASSOC = SIOCGIWAP, 310 __QDF_IEEE80211_REASSOC = IWEVCUSTOM, 311 __QDF_IEEE80211_DISASSOC = SIOCGIWAP, 312 __QDF_IEEE80211_JOIN = IWEVREGISTERED, 313 __QDF_IEEE80211_LEAVE = IWEVEXPIRED, 314 __QDF_IEEE80211_SCAN = SIOCGIWSCAN, 315 __QDF_IEEE80211_REPLAY = IWEVCUSTOM, 316 __QDF_IEEE80211_MICHAEL = IWEVCUSTOM, 317 __QDF_IEEE80211_REJOIN = IWEVCUSTOM, 318 __QDF_CUSTOM_PUSH_BUTTON = IWEVCUSTOM, 319 }; 320 321 #define __qdf_print printk 322 #define __qdf_vprint vprintk 323 #define __qdf_snprint snprintf 324 #define __qdf_vsnprint vsnprintf 325 #define __qdf_toupper toupper 326 327 #define __QDF_DMA_BIDIRECTIONAL DMA_BIDIRECTIONAL 328 #define __QDF_DMA_TO_DEVICE DMA_TO_DEVICE 329 #ifndef __ubicom32__ 330 #define __QDF_DMA_FROM_DEVICE DMA_FROM_DEVICE 331 #else 332 #define __QDF_DMA_FROM_DEVICE DMA_TO_DEVICE 333 #endif 334 #define __qdf_inline inline 335 336 /* 337 * 1. GNU C/C++ Compiler 338 * 339 * How to detect gcc : __GNUC__ 340 * How to detect gcc version : 341 * major version : __GNUC__ (2 = 2.x, 3 = 3.x, 4 = 4.x) 342 * minor version : __GNUC_MINOR__ 343 * 344 * 2. Microsoft C/C++ Compiler 345 * 346 * How to detect msc : _MSC_VER 347 * How to detect msc version : 348 * _MSC_VER (1200 = MSVC 6.0, 1300 = MSVC 7.0, ...) 349 * 350 */ 351 352 /* 353 * MACROs to help with compiler and OS specifics. May need to get a little 354 * more sophisticated than this and define these to specific 'VERSIONS' of 355 * the compiler and OS. Until we have a need for that, lets go with this 356 */ 357 #if defined(_MSC_VER) 358 359 #define QDF_COMPILER_MSC 360 /* assuming that if we build with MSC, OS is WinMobile */ 361 #define QDF_OS_WINMOBILE 362 363 #elif defined(__GNUC__) 364 365 #define QDF_COMPILER_GNUC 366 #define QDF_OS_LINUX /* assuming if building with GNUC, OS is Linux */ 367 368 #endif 369 370 #if defined(QDF_COMPILER_MSC) 371 372 373 /* 374 * Does nothing on Windows. packing individual structs is not 375 * supported on the Windows compiler 376 */ 377 #define QDF_PACK_STRUCT_1 378 #define QDF_PACK_STRUCT_2 379 #define QDF_PACK_STRUCT_4 380 #define QDF_PACK_STRUCT_8 381 #define QDF_PACK_STRUCT_16 382 383 #elif defined(QDF_COMPILER_GNUC) 384 385 #else 386 #error "Compiling with an unknown compiler!!" 387 #endif 388 389 #endif /* __I_QDF_TYPES_H */ 390