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