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