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