xref: /wlan-dirver/qca-wifi-host-cmn/qdf/linux/src/i_qdf_types.h (revision bac753d968f39c1fab8507a7e5afb8e84db947ea)
1 /*
2  * Copyright (c) 2014-2017 The Linux Foundation. All rights reserved.
3  *
4  * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5  *
6  *
7  * Permission to use, copy, modify, and/or distribute this software for
8  * any purpose with or without fee is hereby granted, provided that the
9  * above copyright notice and this permission notice appear in all
10  * copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19  * PERFORMANCE OF THIS SOFTWARE.
20  */
21 
22 /*
23  * This file was originally distributed by Qualcomm Atheros, Inc.
24  * under proprietary terms before Copyright ownership was assigned
25  * to the Linux Foundation.
26  */
27 
28 /**
29  * DOC: i_qdf_types.h
30  * This file provides OS dependent types API's.
31  */
32 
33 #if !defined(__I_QDF_TYPES_H)
34 #define __I_QDF_TYPES_H
35 
36 #include <qdf_status.h>
37 
38 #ifndef __KERNEL__
39 #define __iomem
40 #endif
41 #include <asm/types.h>
42 #include <asm/byteorder.h>
43 #include <linux/version.h>
44 
45 #ifndef __ahdecl
46 #ifdef __i386__
47 #define __ahdecl   __attribute__((regparm(0)))
48 #else
49 #define __ahdecl
50 #endif
51 #endif
52 
53 #ifdef __KERNEL__
54 #include <generated/autoconf.h>
55 #include <linux/list.h>
56 #include <linux/mutex.h>
57 #include <linux/types.h>
58 #include <linux/sched.h>
59 #include <linux/completion.h>
60 #include <linux/string.h>
61 #include <linux/slab.h>
62 #include <linux/interrupt.h>
63 #include <linux/version.h>
64 #include <asm/div64.h>
65 #include <linux/compiler.h>
66 #include <linux/dma-mapping.h>
67 #include <linux/wireless.h>
68 #include <linux/if.h>
69 #else
70 
71 /*
72  * Hack - coexist with prior defs of dma_addr_t.
73  * Eventually all other defs of dma_addr_t should be removed.
74  * At that point, the "already_defined" wrapper can be removed.
75  */
76 #ifndef __dma_addr_t_already_defined__
77 #define __dma_addr_t_already_defined__
78 typedef unsigned long dma_addr_t;
79 #endif
80 
81 #define SIOCGIWAP       0
82 #define IWEVCUSTOM      0
83 #define IWEVREGISTERED  0
84 #define IWEVEXPIRED     0
85 #define SIOCGIWSCAN     0
86 #define DMA_TO_DEVICE   0
87 #define DMA_BIDIRECTIONAL 0
88 #define DMA_FROM_DEVICE 0
89 #define __iomem
90 #endif /* __KERNEL__ */
91 
92 /*
93  * max sg that we support
94  */
95 #define __QDF_MAX_SCATTER        1
96 
97 #if defined(__LITTLE_ENDIAN_BITFIELD)
98 #define QDF_LITTLE_ENDIAN_MACHINE
99 #elif defined(__BIG_ENDIAN_BITFIELD)
100 #define QDF_BIG_ENDIAN_MACHINE
101 #else
102 #error  "Please fix <asm/byteorder.h>"
103 #endif
104 
105 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20) || !defined(__KERNEL__)
106 #ifndef __bool_already_defined__
107 #define __bool_already_defined__
108 
109 /**
110  * bool - This is an enum for boolean
111  * @false: zero
112  * @true: one
113  */
114 typedef enum bool {
115 	false = 0,
116 	true  = 1,
117 } bool;
118 #endif /* __bool_already_defined__ */
119 #endif
120 
121 #define __qdf_packed    __attribute__((packed))
122 
123 typedef int (*__qdf_os_intr)(void *);
124 /**
125  * Private definitions of general data types
126  */
127 typedef dma_addr_t __qdf_dma_addr_t;
128 typedef size_t __qdf_dma_size_t;
129 typedef dma_addr_t __qdf_dma_context_t;
130 typedef struct net_device *__qdf_netdev_t;
131 
132 #define qdf_dma_mem_context(context) dma_addr_t context
133 #define qdf_get_dma_mem_context(var, field)   ((qdf_dma_context_t)(var->field))
134 
135 /**
136  * typedef struct __qdf_resource_t - qdf resource type
137  * @paddr: Physical address
138  * @paddr: Virtual address
139  * @len: Length
140  */
141 typedef struct __qdf_resource {
142 	unsigned long paddr;
143 	void __iomem *vaddr;
144 	unsigned long len;
145 } __qdf_resource_t;
146 
147 struct __qdf_mempool_ctxt;
148 
149 #define MAX_MEM_POOLS 64
150 
151 /**
152  * enum qdf_bus_type - Supported Bus types
153  * @QDF_BUS_TYPE_NONE: None Bus type for error check
154  * @QDF_BUS_TYPE_PCI: PCI Bus
155  * @QDF_BUS_TYPE_AHB: AHB Bus
156  * @QDF_BUS_TYPE_SNOC: SNOC Bus
157  * @QDF_BUS_TYPE_SIM: Simulator
158  * @QDF_BUS_TYPE_USB: USB Bus
159  */
160 enum qdf_bus_type {
161 	QDF_BUS_TYPE_NONE = -1,
162 	QDF_BUS_TYPE_PCI = 0,
163 	QDF_BUS_TYPE_AHB,
164 	QDF_BUS_TYPE_SNOC,
165 	QDF_BUS_TYPE_SIM,
166 	QDF_BUS_TYPE_SDIO,
167 	QDF_BUS_TYPE_USB
168 };
169 
170 /**
171  * struct __qdf_device - generic qdf device type
172  * @drv: Pointer to driver
173  * @drv_hdl: Pointer to driver handle
174  * @drv_name: Pointer to driver name
175  * @irq: IRQ
176  * @dev: Pointer to device
177  * @res: QDF resource
178  * @func: Interrupt handler
179  * @mem_pool: array to pointer to mem context
180  */
181 struct __qdf_device {
182 	void *drv;
183 	void *drv_hdl;
184 	char *drv_name;
185 	int irq;
186 	struct device *dev;
187 	__qdf_resource_t res;
188 	__qdf_os_intr func;
189 	struct __qdf_mempool_ctxt *mem_pool[MAX_MEM_POOLS];
190 	enum qdf_bus_type bus_type;
191 #ifdef CONFIG_MCL
192 	const struct hif_bus_id *bid;
193 #endif
194 };
195 typedef struct __qdf_device *__qdf_device_t;
196 
197 typedef size_t __qdf_size_t;
198 typedef off_t __qdf_off_t;
199 typedef uint8_t __iomem *__qdf_iomem_t;
200 
201 typedef uint32_t ath_dma_addr_t;
202 
203 /**
204  * typedef __qdf_segment_t - segment of memory
205  * @daddr: dma address
206  * @len: lenght of segment
207  */
208 typedef struct __qdf_segment {
209 	dma_addr_t  daddr;
210 	uint32_t    len;
211 } __qdf_segment_t;
212 
213 /**
214  * __qdf_dma_map - dma map of memory
215  * @mapped: mapped address
216  * @nsegs: number of segments
217  * @coherent: coherency status
218  * @seg: segment of memory
219  */
220 struct __qdf_dma_map {
221 	uint32_t                mapped;
222 	uint32_t                nsegs;
223 	uint32_t                coherent;
224 	__qdf_segment_t      seg[__QDF_MAX_SCATTER];
225 };
226 typedef struct  __qdf_dma_map  *__qdf_dma_map_t;
227 
228 /**
229  * __qdf_net_wireless_evcode - enum for event code
230  * @__QDF_IEEE80211_ASSOC: association event code
231  * @__QDF_IEEE80211_REASSOC: reassociation event code
232  * @__QDF_IEEE80211_DISASSOC: disassociation event code
233  * @__QDF_IEEE80211_JOIN: join event code
234  * @__QDF_IEEE80211_LEAVE: leave event code
235  * @__QDF_IEEE80211_SCAN: scan event code
236  * @__QDF_IEEE80211_REPLAY: replay event code
237  * @__QDF_IEEE80211_MICHAEL:michael event code
238  * @__QDF_IEEE80211_REJOIN: rejoin event code
239  * @__QDF_CUSTOM_PUSH_BUTTON: push button event code
240  */
241 enum __qdf_net_wireless_evcode {
242 	__QDF_IEEE80211_ASSOC = SIOCGIWAP,
243 	__QDF_IEEE80211_REASSOC = IWEVCUSTOM,
244 	__QDF_IEEE80211_DISASSOC = SIOCGIWAP,
245 	__QDF_IEEE80211_JOIN = IWEVREGISTERED,
246 	__QDF_IEEE80211_LEAVE = IWEVEXPIRED,
247 	__QDF_IEEE80211_SCAN = SIOCGIWSCAN,
248 	__QDF_IEEE80211_REPLAY = IWEVCUSTOM,
249 	__QDF_IEEE80211_MICHAEL = IWEVCUSTOM,
250 	__QDF_IEEE80211_REJOIN = IWEVCUSTOM,
251 	__QDF_CUSTOM_PUSH_BUTTON = IWEVCUSTOM,
252 };
253 
254 #define __qdf_print               printk
255 #define __qdf_vprint              vprintk
256 #define __qdf_snprint             snprintf
257 #define __qdf_vsnprint            vsnprintf
258 
259 #define __QDF_DMA_BIDIRECTIONAL  DMA_BIDIRECTIONAL
260 #define __QDF_DMA_TO_DEVICE      DMA_TO_DEVICE
261 #ifndef __ubicom32__
262 #define __QDF_DMA_FROM_DEVICE    DMA_FROM_DEVICE
263 #else
264 #define __QDF_DMA_FROM_DEVICE    DMA_TO_DEVICE
265 #endif
266 #define __qdf_inline             inline
267 
268 /*
269  * 1. GNU C/C++ Compiler
270  *
271  * How to detect gcc : __GNUC__
272  * How to detect gcc version :
273  *   major version : __GNUC__ (2 = 2.x, 3 = 3.x, 4 = 4.x)
274  *   minor version : __GNUC_MINOR__
275  *
276  * 2. Microsoft C/C++ Compiler
277  *
278  * How to detect msc : _MSC_VER
279  * How to detect msc version :
280  *   _MSC_VER (1200 = MSVC 6.0, 1300 = MSVC 7.0, ...)
281  *
282  */
283 
284 /*
285  * MACROs to help with compiler and OS specifics. May need to get a little
286  * more sophisticated than this and define these to specific 'VERSIONS' of
287  * the compiler and OS.  Until we have a need for that, lets go with this
288  */
289 #if defined(_MSC_VER)
290 
291 #define QDF_COMPILER_MSC
292 /* assuming that if we build with MSC, OS is WinMobile */
293 #define QDF_OS_WINMOBILE
294 
295 #elif defined(__GNUC__)
296 
297 #define QDF_COMPILER_GNUC
298 #define QDF_OS_LINUX /* assuming if building with GNUC, OS is Linux */
299 
300 #endif
301 
302 #if defined(QDF_COMPILER_MSC)
303 
304 
305 /*
306  * Does nothing on Windows.  packing individual structs is not
307  * supported on the Windows compiler
308  */
309 #define QDF_PACK_STRUCT_1
310 #define QDF_PACK_STRUCT_2
311 #define QDF_PACK_STRUCT_4
312 #define QDF_PACK_STRUCT_8
313 #define QDF_PACK_STRUCT_16
314 
315 #elif defined(QDF_COMPILER_GNUC)
316 
317 #else
318 #error "Compiling with an unknown compiler!!"
319 #endif
320 
321 #endif /* __I_QDF_TYPES_H */
322