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