1 /* 2 * Copyright (c) 2014-2020 The Linux Foundation. All rights reserved. 3 * Copyright (c) 2021-2022 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 napi_struct __qdf_napi_struct; 175 typedef struct net_device *__qdf_netdev_t; 176 typedef struct net_device_stats __qdf_net_dev_stats; 177 typedef struct cpumask __qdf_cpu_mask; 178 typedef __le16 __qdf_le16_t; 179 typedef __le32 __qdf_le32_t; 180 typedef __le64 __qdf_le64_t; 181 typedef __be16 __qdf_be16_t; 182 typedef __be32 __qdf_be32_t; 183 typedef __be64 __qdf_be64_t; 184 185 #if defined(IPA_OFFLOAD) && defined(__KERNEL__) 186 typedef struct ipa_wdi_buffer_info __qdf_mem_info_t; 187 #else 188 /** 189 * struct __qdf_shared_mem_info - shared mem info struct 190 * @pa : physical address 191 * @iova: i/o virtual address 192 * @size: allocated memory size 193 * @result: status 194 */ 195 typedef struct __qdf_shared_mem_info { 196 phys_addr_t pa; 197 unsigned long iova; 198 size_t size; 199 int result; 200 } __qdf_mem_info_t; 201 #endif /* IPA_OFFLOAD */ 202 203 #define qdf_dma_mem_context(context) dma_addr_t context 204 #define qdf_get_dma_mem_context(var, field) ((qdf_dma_context_t)(var->field)) 205 206 /** 207 * typedef struct __qdf_resource_t - qdf resource type 208 * @paddr: Physical address 209 * @paddr: Virtual address 210 * @len: Length 211 */ 212 typedef struct __qdf_resource { 213 unsigned long paddr; 214 void __iomem *vaddr; 215 unsigned long len; 216 } __qdf_resource_t; 217 218 struct __qdf_mempool_ctxt; 219 220 #define MAX_MEM_POOLS 64 221 222 /** 223 * enum qdf_bus_type - Supported Bus types 224 * @QDF_BUS_TYPE_NONE: None Bus type for error check 225 * @QDF_BUS_TYPE_PCI: PCI Bus 226 * @QDF_BUS_TYPE_AHB: AHB Bus 227 * @QDF_BUS_TYPE_SNOC: SNOC Bus 228 * @QDF_BUS_TYPE_SIM: Simulator 229 * @QDF_BUS_TYPE_USB: USB Bus 230 * @QDF_BUS_TYPE_IPCI: IPCI Bus 231 */ 232 enum qdf_bus_type { 233 QDF_BUS_TYPE_NONE = -1, 234 QDF_BUS_TYPE_PCI = 0, 235 QDF_BUS_TYPE_AHB, 236 QDF_BUS_TYPE_SNOC, 237 QDF_BUS_TYPE_SIM, 238 QDF_BUS_TYPE_SDIO, 239 QDF_BUS_TYPE_USB, 240 QDF_BUS_TYPE_IPCI 241 }; 242 243 /** 244 * struct __qdf_device - generic qdf device type 245 * @drv: Pointer to driver 246 * @drv_hdl: Pointer to driver handle 247 * @drv_name: Pointer to driver name 248 * @cnss_pdev: Pointer to platform device 249 * @irq: IRQ 250 * @dev: Pointer to device 251 * @res: QDF resource 252 * @func: Interrupt handler 253 * @mem_pool: array of pointers to mem pool context 254 * @bus_type: Bus type 255 * @bid: Bus ID 256 * @smmu_s1_enabled: SMMU S1 enabled or not 257 * @iommu_mapping: DMA iommu mapping pointer 258 */ 259 struct __qdf_device { 260 void *drv; 261 void *drv_hdl; 262 char *drv_name; 263 void *cnss_pdev; 264 int irq; 265 struct device *dev; 266 __qdf_resource_t res; 267 __qdf_os_intr func; 268 struct __qdf_mempool_ctxt *mem_pool[MAX_MEM_POOLS]; 269 enum qdf_bus_type bus_type; 270 const struct hif_bus_id *bid; 271 bool smmu_s1_enabled; 272 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)) 273 struct iommu_domain *domain; 274 #else 275 #ifdef ENABLE_SMMU_S1_TRANSLATION 276 struct dma_iommu_mapping *iommu_mapping; 277 #endif 278 #endif 279 }; 280 typedef struct __qdf_device *__qdf_device_t; 281 282 typedef size_t __qdf_size_t; 283 typedef off_t __qdf_off_t; 284 typedef void __iomem* __qdf_iomem_t; 285 286 typedef uint32_t ath_dma_addr_t; 287 288 /** 289 * typedef __qdf_segment_t - segment of memory 290 * @daddr: dma address 291 * @len: length of segment 292 */ 293 typedef struct __qdf_segment { 294 dma_addr_t daddr; 295 uint32_t len; 296 } __qdf_segment_t; 297 298 /** 299 * __qdf_dma_map - dma map of memory 300 * @mapped: mapped address 301 * @nsegs: number of segments 302 * @coherent: coherency status 303 * @seg: segment of memory 304 */ 305 struct __qdf_dma_map { 306 uint32_t mapped; 307 uint32_t nsegs; 308 uint32_t coherent; 309 __qdf_segment_t seg[__QDF_MAX_SCATTER]; 310 }; 311 typedef struct __qdf_dma_map *__qdf_dma_map_t; 312 313 /** 314 * __qdf_net_wireless_evcode - enum for event code 315 * @__QDF_IEEE80211_ASSOC: association event code 316 * @__QDF_IEEE80211_REASSOC: reassociation event code 317 * @__QDF_IEEE80211_DISASSOC: disassociation event code 318 * @__QDF_IEEE80211_JOIN: join event code 319 * @__QDF_IEEE80211_LEAVE: leave event code 320 * @__QDF_IEEE80211_SCAN: scan event code 321 * @__QDF_IEEE80211_REPLAY: replay event code 322 * @__QDF_IEEE80211_MICHAEL:michael event code 323 * @__QDF_IEEE80211_REJOIN: rejoin event code 324 * @__QDF_CUSTOM_PUSH_BUTTON: push button event code 325 */ 326 enum __qdf_net_wireless_evcode { 327 __QDF_IEEE80211_ASSOC = SIOCGIWAP, 328 __QDF_IEEE80211_REASSOC = IWEVCUSTOM, 329 __QDF_IEEE80211_DISASSOC = SIOCGIWAP, 330 __QDF_IEEE80211_JOIN = IWEVREGISTERED, 331 __QDF_IEEE80211_LEAVE = IWEVEXPIRED, 332 __QDF_IEEE80211_SCAN = SIOCGIWSCAN, 333 __QDF_IEEE80211_REPLAY = IWEVCUSTOM, 334 __QDF_IEEE80211_MICHAEL = IWEVCUSTOM, 335 __QDF_IEEE80211_REJOIN = IWEVCUSTOM, 336 __QDF_CUSTOM_PUSH_BUTTON = IWEVCUSTOM, 337 }; 338 339 #define __qdf_snprint snprintf 340 #define __qdf_vsnprint vsnprintf 341 #define __qdf_toupper toupper 342 #define qdf_kstrtoint __qdf_kstrtoint 343 #define qdf_kstrtouint __qdf_kstrtouint 344 345 #define __qdf_kstrtoint kstrtoint 346 #define __qdf_kstrtouint kstrtouint 347 348 #define __QDF_DMA_BIDIRECTIONAL DMA_BIDIRECTIONAL 349 #define __QDF_DMA_TO_DEVICE DMA_TO_DEVICE 350 #ifndef __ubicom32__ 351 #define __QDF_DMA_FROM_DEVICE DMA_FROM_DEVICE 352 #else 353 #define __QDF_DMA_FROM_DEVICE DMA_TO_DEVICE 354 #endif 355 #define __qdf_inline inline 356 357 /* 358 * 1. GNU C/C++ Compiler 359 * 360 * How to detect gcc : __GNUC__ 361 * How to detect gcc version : 362 * major version : __GNUC__ (2 = 2.x, 3 = 3.x, 4 = 4.x) 363 * minor version : __GNUC_MINOR__ 364 * 365 * 2. Microsoft C/C++ Compiler 366 * 367 * How to detect msc : _MSC_VER 368 * How to detect msc version : 369 * _MSC_VER (1200 = MSVC 6.0, 1300 = MSVC 7.0, ...) 370 * 371 */ 372 373 /* 374 * MACROs to help with compiler and OS specifics. May need to get a little 375 * more sophisticated than this and define these to specific 'VERSIONS' of 376 * the compiler and OS. Until we have a need for that, lets go with this 377 */ 378 #if defined(_MSC_VER) 379 380 #define QDF_COMPILER_MSC 381 /* assuming that if we build with MSC, OS is WinMobile */ 382 #define QDF_OS_WINMOBILE 383 384 #elif defined(__GNUC__) 385 386 #define QDF_COMPILER_GNUC 387 #define QDF_OS_LINUX /* assuming if building with GNUC, OS is Linux */ 388 389 #endif 390 391 #if defined(QDF_COMPILER_MSC) 392 393 394 /* 395 * Does nothing on Windows. packing individual structs is not 396 * supported on the Windows compiler 397 */ 398 #define QDF_PACK_STRUCT_1 399 #define QDF_PACK_STRUCT_2 400 #define QDF_PACK_STRUCT_4 401 #define QDF_PACK_STRUCT_8 402 #define QDF_PACK_STRUCT_16 403 404 #elif defined(QDF_COMPILER_GNUC) 405 406 #else 407 #error "Compiling with an unknown compiler!!" 408 #endif 409 410 #ifndef fallthrough 411 412 #define fallthrough do {} while (0) /* fallthrough */ 413 414 #endif 415 416 #endif /* __I_QDF_TYPES_H */ 417