xref: /wlan-dirver/qca-wifi-host-cmn/qdf/inc/osdep.h (revision 9b24afb720cd7079342f34d267eef718e719ce65)
1 /*
2  * Copyright (c) 2013-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: osdep
30  * This file provides OS abstraction for osdependent APIs.
31  */
32 
33 #ifndef _OSDEP_H
34 #define _OSDEP_H
35 
36 #include <qdf_types.h>
37 #include <qdf_mem.h>
38 #include <qdf_lock.h>
39 #include <qdf_time.h>
40 #include <qdf_timer.h>
41 #include <qdf_defer.h>
42 #include <qdf_nbuf.h>
43 #include <i_osdep.h>
44 
45 /*
46  * ATH_DEBUG -
47  * Control whether debug features (printouts, assertions) are compiled
48  * into the driver.
49  */
50 #ifndef ATH_DEBUG
51 #define ATH_DEBUG 1             /* default: include debug code */
52 #endif
53 
54 #if ATH_DEBUG
55 #ifndef ASSERT
56 #define ASSERT(expr)  qdf_assert(expr)
57 #endif
58 #else
59 #define ASSERT(expr)
60 #endif /* ATH_DEBUG */
61 
62 /*
63  * Need to define byte order based on the CPU configuration.
64  */
65 #ifndef _LITTLE_ENDIAN
66 #define _LITTLE_ENDIAN  1234
67 #endif
68 #ifndef _BIG_ENDIAN
69 #define _BIG_ENDIAN 4321
70 #endif
71 #ifdef __BIG_ENDIAN
72 #define _BYTE_ORDER    _BIG_ENDIAN
73 #else
74 #define _BYTE_ORDER    _LITTLE_ENDIAN
75 #endif
76 
77 /*
78  * Deduce if tasklets are available.  If not then
79  * fall back to using the immediate work queue.
80  */
81 #define qdf_sysctl_decl(f, ctl, write, filp, buffer, lenp, ppos) \
82 	f(struct ctl_table *ctl, int32_t write, void *buffer, \
83 	size_t *lenp, loff_t *ppos)
84 
85 #define QDF_SYSCTL_PROC_DOINTVEC(ctl, write, filp, buffer, lenp, ppos) \
86 	__QDF_SYSCTL_PROC_DOINTVEC(ctl, write, filp, buffer, lenp, ppos)
87 
88 #define QDF_SYSCTL_PROC_DOSTRING(ctl, write, filp, buffer, lenp, ppos) \
89 	__QDF_SYSCTL_PROC_DOSTRING(ctl, write, filp, buffer, lenp, ppos)
90 
91 #define EOK    (0)
92 
93 #ifndef false
94 #define false 0
95 #endif
96 #ifndef true
97 #define true  1
98 #endif
99 
100 #ifndef ARPHRD_IEEE80211
101 #define ARPHRD_IEEE80211 801    /* IEEE 802.11.  */
102 #endif
103 
104 /*
105  * Normal Delay functions. Time specified in microseconds.
106  */
107 #define OS_DELAY(_us)                     qdf_udelay(_us)
108 
109 /*
110  * memory data manipulation functions.
111  */
112 #define OS_MEMCPY(_dst, _src, _len)       qdf_mem_copy(_dst, _src, _len)
113 #define OS_MEMMOVE(_dst, _src, _len)      qdf_mem_move(_dst, _src, _len)
114 #define OS_MEMZERO(_buf, _len)            qdf_mem_zero(_buf, _len)
115 #define OS_MEMSET(_buf, _ch, _len)        qdf_mem_set(_buf, _len, _ch)
116 #define OS_MEMCMP(_mem1, _mem2, _len)     qdf_mem_cmp(_mem1, _mem2, _len)
117 
118 
119 /*
120  * System time interface
121  */
122 typedef qdf_time_t systime_t;
123 typedef qdf_time_t systick_t;
124 
125 /**
126  * os_get_timestamp() - gives the timestamp in ticks
127  * Return: unsigned long
128  */
129 static inline qdf_time_t os_get_timestamp(void)
130 {
131 	/* Fix double conversion from jiffies to ms */
132 	return qdf_system_ticks();
133 }
134 
135 struct _NIC_DEV;
136 
137 static inline unsigned char *os_malloc(osdev_t nic_dev,
138 				       unsigned long size_in_bytes,
139 				       int32_t gfp)
140 {
141 	return qdf_mem_malloc(size_in_bytes);
142 }
143 
144 #define OS_FREE(_p)                     qdf_mem_free(_p)
145 
146 #define OS_DMA_MEM_CONTEXT(context)	    \
147 		dma_addr_t context
148 
149 #define OS_GET_DMA_MEM_CONTEXT(var, field)  \
150 		&(var->field)
151 
152 #define OS_COPY_DMA_MEM_CONTEXT(dst, src)   \
153 		*dst = *src
154 
155 #define OS_ZERO_DMA_MEM_CONTEXT(context)   \
156 		*context = 0
157 
158 /*
159  * Timer Interfaces. Use these macros to declare timer
160  * and retrieve timer argument. This is mainly for resolving
161  * different argument types for timer function in different OS.
162  */
163 #define os_timer_func(_fn) \
164 	void _fn(void *timer_arg)
165 
166 #define OS_GET_TIMER_ARG(_arg, _type) \
167 	((_arg) = (_type)(timer_arg))
168 
169 #define OS_DECLARE_TIMER(_fn)                  void _fn(void *)
170 
171 #define OS_INIT_TIMER(_osdev, _timer, _fn, _ctx, type)  \
172 			qdf_timer_init(_osdev, _timer, _fn, _ctx, type)
173 
174 #define OS_SET_TIMER(_timer, _ms)      qdf_timer_mod(_timer, _ms)
175 
176 #define OS_CANCEL_TIMER(_timer)        qdf_timer_stop(_timer)
177 
178 #define OS_FREE_TIMER(_timer)          qdf_timer_stop(_timer)
179 
180 /*
181  * These are required for network manager support
182  */
183 #ifndef SET_NETDEV_DEV
184 #define    SET_NETDEV_DEV(ndev, pdev)
185 #endif
186 
187 #endif /* end of _OSDEP_H */
188