xref: /wlan-dirver/qca-wifi-host-cmn/qdf/linux/src/i_osdep.h (revision 4865edfd190c086bbe2c69aae12a8226f877b91e)
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: i_osdep
21  *  QCA driver framework OS dependent types
22  */
23 
24 #ifndef _I_OSDEP_H
25 #define _I_OSDEP_H
26 
27 #ifdef CONFIG_MCL
28 #include <cds_queue.h>
29 #include <cds_if_upperproto.h>
30 #else
31 #include <sys/queue.h>
32 #endif
33 
34 /*
35  * Byte Order stuff
36  */
37 #define    le16toh(_x)    le16_to_cpu(_x)
38 #define    htole16(_x)    cpu_to_le16(_x)
39 #define    htobe16(_x)    cpu_to_be16(_x)
40 #define    le32toh(_x)    le32_to_cpu(_x)
41 #define    htole32(_x)    cpu_to_le32(_x)
42 #define    be16toh(_x)    be16_to_cpu(_x)
43 #define    be32toh(_x)    be32_to_cpu(_x)
44 #define    htobe32(_x)    cpu_to_be32(_x)
45 
46 typedef struct timer_list os_timer_t;
47 
48 #ifdef CONFIG_SMP
49 /* Undo the one provided by the kernel to debug spin locks */
50 #undef spin_lock
51 #undef spin_unlock
52 #undef spin_trylock
53 
54 #define spin_lock(x)  spin_lock_bh(x)
55 
56 #define spin_unlock(x) \
57 	do { \
58 		if (!spin_is_locked(x)) { \
59 			WARN_ON(1); \
60 			printk(KERN_EMERG " %s:%d unlock addr=%pK, %s \n", __func__,  __LINE__, x, \
61 			       !spin_is_locked(x) ? "Not locked" : "");	\
62 		} \
63 		spin_unlock_bh(x); \
64 	} while (0)
65 #define spin_trylock(x) spin_trylock_bh(x)
66 #define OS_SUPPORT_ASYNC_Q 1    /* support for handling asyn function calls */
67 
68 #else
69 #define OS_SUPPORT_ASYNC_Q 0
70 #endif /* ifdef CONFIG_SMP */
71 
72 /**
73  * struct os_mest_t - maintain attributes of message
74  * @mesg_next: pointer to the nexgt message
75  * @mest_type: type of message
76  * @mesg_len: length of the message
77  */
78 typedef struct _os_mesg_t {
79 	STAILQ_ENTRY(_os_mesg_t) mesg_next;
80 	uint16_t mesg_type;
81 	uint16_t mesg_len;
82 } os_mesg_t;
83 
84 /**
85  * struct qdf_bus_context - Bus to hal context handoff
86  * @bc_tag: bus context tag
87  * @cal_in_flash: calibration data stored in flash
88  * @bc_handle: bus context handle
89  * @bc_bustype: bus type
90  */
91 typedef struct qdf_bus_context {
92 	void *bc_tag;
93 	int cal_in_flash;
94 	char *bc_handle;
95 	enum qdf_bus_type bc_bustype;
96 } QDF_BUS_CONTEXT;
97 
98 typedef struct _NIC_DEV *osdev_t;
99 
100 typedef void (*os_mesg_handler_t)(void *ctx, uint16_t mesg_type,
101 				  uint16_t mesg_len,
102 				  void *mesg);
103 
104 
105 /**
106  * typedef os_mesg_queue_t - Object to maintain message queue
107  * @dev_handle: OS handle
108  * @num_queued: number of queued messages
109  * @mesg_len: message length
110  * @mesg_queue_buf: pointer to message queue buffer
111  * @mesg_head: queued mesg buffers
112  * @mesg_free_head: free mesg buffers
113  * @lock: spinlock object
114  * @ev_handler_lock: spinlock object to event handler
115  * @task: pointer to task
116  * @_timer: instance of timer
117  * @handler: message handler
118  * @ctx: pointer to context
119  * @is_synchronous: bit to save synchronous status
120  * @del_progress: delete in progress
121  */
122 typedef struct {
123 	osdev_t dev_handle;
124 	int32_t num_queued;
125 	int32_t mesg_len;
126 	uint8_t *mesg_queue_buf;
127 
128 	STAILQ_HEAD(, _os_mesg_t) mesg_head;
129 	STAILQ_HEAD(, _os_mesg_t) mesg_free_head;
130 	spinlock_t lock;
131 	spinlock_t ev_handler_lock;
132 #ifdef USE_SOFTINTR
133 	void *_task;
134 #else
135 	os_timer_t _timer;
136 #endif
137 	os_mesg_handler_t handler;
138 	void *ctx;
139 	uint8_t is_synchronous:1;
140 	uint8_t del_progress;
141 } os_mesg_queue_t;
142 
143 /**
144  * struct _NIC_DEV - Definition of OS-dependent device structure.
145  * It'll be opaque to the actual ATH layer.
146  * @qdf_dev: qdf device
147  * @bdev: bus device handle
148  * @netdev: net device handle (wifi%d)
149  * @intr_tq: tasklet
150  * @devstats: net device statistics
151  * @bc: hal bus context
152  * @device: generic device
153  * @event_queue: instance to wait queue
154  * @is_device_asleep: keep device status, sleep or awakei
155  * @acfg_event_list: event list
156  * @acfg_event_queue_lock: queue lock
157  * @acfg_event_os_work: schedule or create work
158  * @acfg_netlink_wq_init_done: Work queue ready
159  * @osdev_acfg_handle: acfg handle
160  * @vap_hardstart: Tx function specific to the radio
161  * 		   initiailzed during VAP create
162  */
163 struct _NIC_DEV {
164 	qdf_device_t qdf_dev;
165 	void *bdev;
166 	struct net_device *netdev;
167 	qdf_bh_t intr_tq;
168 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36)
169 	struct rtnl_link_stats64 devstats;
170 #else
171 	struct net_device_stats devstats;
172 #endif
173 	QDF_BUS_CONTEXT bc;
174 #ifdef ATH_PERF_PWR_OFFLOAD
175 	struct device *device;
176 	wait_queue_head_t event_queue;
177 #endif /* PERF_PWR_OFFLOAD */
178 #if OS_SUPPORT_ASYNC_Q
179 	os_mesg_queue_t async_q;
180 #endif
181 #ifdef ATH_BUS_PM
182 	uint8_t is_device_asleep;
183 #endif /* ATH_BUS_PM */
184 	qdf_nbuf_queue_t acfg_event_list;
185 	qdf_spinlock_t acfg_event_queue_lock;
186 	qdf_work_t acfg_event_os_work;
187 	uint8_t acfg_netlink_wq_init_done;
188 
189 #ifdef UMAC_SUPPORT_ACFG
190 #ifdef ACFG_NETLINK_TX
191 	void *osdev_acfg_handle;
192 #endif /* ACFG_NETLINK_TX */
193 #endif /* UMAC_SUPPORT_ACFG */
194 	int (*vap_hardstart)(struct sk_buff *skb, struct net_device *dev);
195 };
196 
197 #define __QDF_SYSCTL_PROC_DOINTVEC(ctl, write, filp, buffer, lenp, ppos) \
198 	proc_dointvec(ctl, write, buffer, lenp, ppos)
199 
200 #define __QDF_SYSCTL_PROC_DOSTRING(ctl, write, filp, buffer, lenp, ppos) \
201 	proc_dostring(ctl, write, filp, buffer, lenp, ppos)
202 
203 #endif /* _I_OSDEP_H */
204