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