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