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