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