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