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