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