xref: /wlan-dirver/qca-wifi-host-cmn/hif/src/hif_main.h (revision 6ecd284e5a94a1c96e26d571dd47419ac305990d)
1 /*
2  * Copyright (c) 2013-2018 The Linux Foundation. All rights reserved.
3  *
4  * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5  *
6  *
7  * Permission to use, copy, modify, and/or distribute this software for
8  * any purpose with or without fee is hereby granted, provided that the
9  * above copyright notice and this permission notice appear in all
10  * copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19  * PERFORMANCE OF THIS SOFTWARE.
20  */
21 
22 /*
23  * This file was originally distributed by Qualcomm Atheros, Inc.
24  * under proprietary terms before Copyright ownership was assigned
25  * to the Linux Foundation.
26  */
27 
28 /*
29  * NB: Inappropriate references to "HTC" are used in this (and other)
30  * HIF implementations.  HTC is typically the calling layer, but it
31  * theoretically could be some alternative.
32  */
33 
34 /*
35  * This holds all state needed to process a pending send/recv interrupt.
36  * The information is saved here as soon as the interrupt occurs (thus
37  * allowing the underlying CE to re-use the ring descriptor). The
38  * information here is eventually processed by a completion processing
39  * thread.
40  */
41 
42 #ifndef __HIF_MAIN_H__
43 #define __HIF_MAIN_H__
44 
45 #include <qdf_atomic.h>         /* qdf_atomic_read */
46 #include "qdf_lock.h"
47 #include "cepci.h"
48 #include "hif.h"
49 #include "multibus.h"
50 #include "hif_unit_test_suspend_i.h"
51 
52 #define HIF_MIN_SLEEP_INACTIVITY_TIME_MS     50
53 #define HIF_SLEEP_INACTIVITY_TIMER_PERIOD_MS 60
54 
55 #define HIF_MAX_BUDGET 0xFFFF
56 
57 /*
58  * This macro implementation is exposed for efficiency only.
59  * The implementation may change and callers should
60  * consider the targid to be a completely opaque handle.
61  */
62 #define TARGID_TO_PCI_ADDR(targid) (*((A_target_id_t *)(targid)))
63 
64 #ifdef QCA_WIFI_3_0
65 #define DISABLE_L1SS_STATES 1
66 #endif
67 
68 #define MAX_NUM_OF_RECEIVES HIF_NAPI_MAX_RECEIVES
69 
70 #ifdef QCA_WIFI_3_0_ADRASTEA
71 #define ADRASTEA_BU 1
72 #else
73 #define ADRASTEA_BU 0
74 #endif
75 
76 #ifdef QCA_WIFI_3_0
77 #define HAS_FW_INDICATOR 0
78 #else
79 #define HAS_FW_INDICATOR 1
80 #endif
81 
82 
83 #define AR9888_DEVICE_ID (0x003c)
84 #define AR6320_DEVICE_ID (0x003e)
85 #define AR6320_FW_1_1  (0x11)
86 #define AR6320_FW_1_3  (0x13)
87 #define AR6320_FW_2_0  (0x20)
88 #define AR6320_FW_3_0  (0x30)
89 #define AR6320_FW_3_2  (0x32)
90 #define QCA6290_EMULATION_DEVICE_ID (0xabcd)
91 #define QCA6290_DEVICE_ID (0x1100)
92 #define ADRASTEA_DEVICE_ID_P2_E12 (0x7021)
93 #define AR9887_DEVICE_ID    (0x0050)
94 #define AR900B_DEVICE_ID    (0x0040)
95 #define QCA9984_DEVICE_ID   (0x0046)
96 #define QCA9888_DEVICE_ID   (0x0056)
97 #ifndef IPQ4019_DEVICE_ID
98 #define IPQ4019_DEVICE_ID   (0x12ef)
99 #endif
100 #define QCA8074_DEVICE_ID   (0xffff) /* Todo: replace this with
101 					actual number once available.
102 					currently defining this to 0xffff for
103 					emulation purpose */
104 #define RUMIM2M_DEVICE_ID_NODE0	0xabc0
105 #define RUMIM2M_DEVICE_ID_NODE1	0xabc1
106 #define RUMIM2M_DEVICE_ID_NODE2	0xabc2
107 #define RUMIM2M_DEVICE_ID_NODE3	0xabc3
108 
109 #define HIF_GET_PCI_SOFTC(scn) ((struct hif_pci_softc *)scn)
110 #define HIF_GET_CE_STATE(scn) ((struct HIF_CE_state *)scn)
111 #define HIF_GET_SDIO_SOFTC(scn) ((struct hif_sdio_softc *)scn)
112 #define HIF_GET_USB_SOFTC(scn) ((struct hif_usb_softc *)scn)
113 #define HIF_GET_USB_DEVICE(scn) ((struct HIF_DEVICE_USB *)scn)
114 #define HIF_GET_SOFTC(scn) ((struct hif_softc *)scn)
115 #define GET_HIF_OPAQUE_HDL(scn) ((struct hif_opaque_softc *)scn)
116 
117 struct hif_ce_stats {
118 	int hif_pipe_no_resrc_count;
119 	int ce_ring_delta_fail_count;
120 };
121 
122 /*
123  * Note: For MCL, #if defined (HIF_CONFIG_SLUB_DEBUG_ON) needs to be checked
124  * for defined here
125  */
126 #if HIF_CE_DEBUG_DATA_BUF
127 struct ce_desc_hist {
128 	qdf_atomic_t history_index[CE_COUNT_MAX];
129 	uint32_t enable[CE_COUNT_MAX];
130 	uint32_t data_enable[CE_COUNT_MAX];
131 	uint32_t hist_index;
132 	uint32_t hist_id;
133 	void *hist_ev[CE_COUNT_MAX];
134 };
135 #endif /* #if defined(HIF_CONFIG_SLUB_DEBUG_ON) || HIF_CE_DEBUG_DATA_BUF */
136 
137 struct hif_softc {
138 	struct hif_opaque_softc osc;
139 	struct hif_config_info hif_config;
140 	struct hif_target_info target_info;
141 	void __iomem *mem;
142 	enum qdf_bus_type bus_type;
143 	struct hif_bus_ops bus_ops;
144 	void *ce_id_to_state[CE_COUNT_MAX];
145 	qdf_device_t qdf_dev;
146 	bool hif_init_done;
147 	bool request_irq_done;
148 	bool ext_grp_irq_configured;
149 	/* Packet statistics */
150 	struct hif_ce_stats pkt_stats;
151 	enum hif_target_status target_status;
152 
153 	struct targetdef_s *targetdef;
154 	struct ce_reg_def *target_ce_def;
155 	struct hostdef_s *hostdef;
156 	struct host_shadow_regs_s *host_shadow_regs;
157 
158 	bool recovery;
159 	bool notice_send;
160 	bool per_ce_irq;
161 	uint32_t ce_irq_summary;
162 	/* No of copy engines supported */
163 	unsigned int ce_count;
164 	atomic_t active_tasklet_cnt;
165 	atomic_t active_grp_tasklet_cnt;
166 	atomic_t link_suspended;
167 	uint32_t *vaddr_rri_on_ddr;
168 	qdf_dma_addr_t paddr_rri_on_ddr;
169 	int linkstate_vote;
170 	bool fastpath_mode_on;
171 	bool polled_mode_on;
172 	atomic_t tasklet_from_intr;
173 	int htc_htt_tx_endpoint;
174 	qdf_dma_addr_t mem_pa;
175 	bool athdiag_procfs_inited;
176 #ifdef FEATURE_NAPI
177 	struct qca_napi_data napi_data;
178 #endif /* FEATURE_NAPI */
179 	struct hif_driver_state_callbacks callbacks;
180 	uint32_t hif_con_param;
181 #ifdef QCA_NSS_WIFI_OFFLOAD_SUPPORT
182 	uint32_t nss_wifi_ol_mode;
183 #endif
184 	void *hal_soc;
185 	struct hif_ut_suspend_context ut_suspend_ctx;
186 	uint32_t hif_attribute;
187 	int wake_irq;
188 	void (*initial_wakeup_cb)(void *);
189 	void *initial_wakeup_priv;
190 #ifdef REMOVE_PKT_LOG
191 	/* Handle to pktlog device */
192 	void *pktlog_dev;
193 #endif
194 
195 /*
196  * Note: For MCL, #if defined (HIF_CONFIG_SLUB_DEBUG_ON) needs to be checked
197  * for defined here
198  */
199 #if HIF_CE_DEBUG_DATA_BUF
200 	struct ce_desc_hist hif_ce_desc_hist;
201 #endif /* #if defined(HIF_CONFIG_SLUB_DEBUG_ON) || HIF_CE_DEBUG_DATA_BUF */
202 #ifdef IPA_OFFLOAD
203 	qdf_shared_mem_t *ipa_ce_ring;
204 #endif
205 };
206 
207 static inline void *hif_get_hal_handle(void *hif_hdl)
208 {
209 	struct hif_softc *sc = (struct hif_softc *)hif_hdl;
210 	return sc->hal_soc;
211 }
212 
213 #ifdef QCA_NSS_WIFI_OFFLOAD_SUPPORT
214 static inline bool hif_is_nss_wifi_enabled(struct hif_softc *sc)
215 {
216 	return !!(sc->nss_wifi_ol_mode);
217 }
218 #else
219 static inline bool hif_is_nss_wifi_enabled(struct hif_softc *sc)
220 {
221 	return false;
222 }
223 #endif
224 
225 static inline uint8_t hif_is_attribute_set(struct hif_softc *sc,
226 						uint32_t hif_attrib)
227 {
228 	return sc->hif_attribute == hif_attrib;
229 }
230 
231 A_target_id_t hif_get_target_id(struct hif_softc *scn);
232 void hif_dump_pipe_debug_count(struct hif_softc *scn);
233 void hif_display_bus_stats(struct hif_opaque_softc *scn);
234 void hif_clear_bus_stats(struct hif_opaque_softc *scn);
235 bool hif_max_num_receives_reached(struct hif_softc *scn, unsigned int count);
236 void hif_shutdown_device(struct hif_opaque_softc *hif_ctx);
237 int hif_bus_configure(struct hif_softc *scn);
238 void hif_cancel_deferred_target_sleep(struct hif_softc *scn);
239 int hif_config_ce(struct hif_softc *scn);
240 void hif_unconfig_ce(struct hif_softc *scn);
241 void hif_ce_prepare_config(struct hif_softc *scn);
242 QDF_STATUS hif_ce_open(struct hif_softc *scn);
243 void hif_ce_close(struct hif_softc *scn);
244 int athdiag_procfs_init(void *scn);
245 void athdiag_procfs_remove(void);
246 /* routine to modify the initial buffer count to be allocated on an os
247  * platform basis. Platform owner will need to modify this as needed
248  */
249 qdf_size_t init_buffer_count(qdf_size_t maxSize);
250 
251 irqreturn_t hif_fw_interrupt_handler(int irq, void *arg);
252 int hif_get_device_type(uint32_t device_id,
253 			uint32_t revision_id,
254 			uint32_t *hif_type, uint32_t *target_type);
255 /*These functions are exposed to HDD*/
256 void hif_nointrs(struct hif_softc *scn);
257 void hif_bus_close(struct hif_softc *ol_sc);
258 QDF_STATUS hif_bus_open(struct hif_softc *ol_sc,
259 	enum qdf_bus_type bus_type);
260 QDF_STATUS hif_enable_bus(struct hif_softc *ol_sc, struct device *dev,
261 	void *bdev, const struct hif_bus_id *bid, enum hif_enable_type type);
262 void hif_disable_bus(struct hif_softc *scn);
263 void hif_bus_prevent_linkdown(struct hif_softc *scn, bool flag);
264 int hif_bus_get_context_size(enum qdf_bus_type bus_type);
265 void hif_read_phy_mem_base(struct hif_softc *scn, qdf_dma_addr_t *bar_value);
266 uint32_t hif_get_conparam(struct hif_softc *scn);
267 struct hif_driver_state_callbacks *hif_get_callbacks_handle(
268 							struct hif_softc *scn);
269 bool hif_is_driver_unloading(struct hif_softc *scn);
270 bool hif_is_load_or_unload_in_progress(struct hif_softc *scn);
271 bool hif_is_recovery_in_progress(struct hif_softc *scn);
272 bool hif_is_target_ready(struct hif_softc *scn);
273 void hif_wlan_disable(struct hif_softc *scn);
274 int hif_target_sleep_state_adjust(struct hif_softc *scn,
275 					 bool sleep_ok,
276 					 bool wait_for_it);
277 int hif_get_rx_ctx_id(int ctx_id, struct hif_opaque_softc *hif_hdl);
278 void hif_ramdump_handler(struct hif_opaque_softc *scn);
279 #ifdef HIF_USB
280 void hif_usb_get_hw_info(struct hif_softc *scn);
281 void hif_usb_ramdump_handler(struct hif_opaque_softc *scn);
282 #else
283 static inline void hif_usb_get_hw_info(struct hif_softc *scn) {}
284 static inline void hif_usb_ramdump_handler(struct hif_opaque_softc *scn) {}
285 #endif
286 
287 /**
288  * hif_wake_interrupt_handler() - interrupt handler for standalone wake irq
289  * @irq: the irq number that fired
290  * @context: the opaque pointer passed to request_irq()
291  *
292  * Return: an irq return type
293  */
294 irqreturn_t hif_wake_interrupt_handler(int irq, void *context);
295 
296 #ifdef HIF_SNOC
297 bool hif_is_target_register_access_allowed(struct hif_softc *hif_sc);
298 #else
299 static inline
300 bool hif_is_target_register_access_allowed(struct hif_softc *hif_sc)
301 {
302 	return true;
303 }
304 #endif
305 
306 #ifdef ADRASTEA_RRI_ON_DDR
307 void hif_uninit_rri_on_ddr(struct hif_softc *scn);
308 #else
309 static inline
310 void hif_uninit_rri_on_ddr(struct hif_softc *scn) {}
311 #endif
312 #endif /* __HIF_MAIN_H__ */
313