xref: /wlan-dirver/qca-wifi-host-cmn/hif/src/ce/ce_main.h (revision 1b9674e21e24478fba4530f5ae7396b9555e9c6a)
1 /*
2  * Copyright (c) 2015-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 #ifndef __CE_H__
20 #define __CE_H__
21 
22 #include "qdf_atomic.h"
23 #include "qdf_lock.h"
24 #include "hif_main.h"
25 #include "qdf_util.h"
26 #include "hif_exec.h"
27 
28 #define CE_HTT_T2H_MSG 1
29 #define CE_HTT_H2T_MSG 4
30 
31 #define CE_OFFSET		0x00000400
32 #define CE_USEFUL_SIZE		0x00000058
33 #define CE_ALL_BITMAP  0xFFFF
34 
35 /**
36  * enum ce_id_type
37  *
38  * @ce_id_type: Copy engine ID
39  */
40 enum ce_id_type {
41 	CE_ID_0,
42 	CE_ID_1,
43 	CE_ID_2,
44 	CE_ID_3,
45 	CE_ID_4,
46 	CE_ID_5,
47 	CE_ID_6,
48 	CE_ID_7,
49 	CE_ID_8,
50 	CE_ID_9,
51 	CE_ID_10,
52 	CE_ID_11,
53 	CE_ID_MAX
54 };
55 
56 #ifdef CONFIG_WIN
57 #define QWLAN_VERSIONSTR "WIN"
58 #endif
59 
60 enum ol_ath_hif_pkt_ecodes {
61 	HIF_PIPE_NO_RESOURCE = 0
62 };
63 
64 struct HIF_CE_state;
65 
66 /* Per-pipe state. */
67 struct HIF_CE_pipe_info {
68 	/* Handle of underlying Copy Engine */
69 	struct CE_handle *ce_hdl;
70 
71 	/* Our pipe number; facilitiates use of pipe_info ptrs. */
72 	uint8_t pipe_num;
73 
74 	/* Convenience back pointer to HIF_CE_state. */
75 	struct HIF_CE_state *HIF_CE_state;
76 
77 	/* Instantaneous number of receive buffers that should be posted */
78 	atomic_t recv_bufs_needed;
79 	qdf_size_t buf_sz;
80 	qdf_spinlock_t recv_bufs_needed_lock;
81 
82 	qdf_spinlock_t completion_freeq_lock;
83 	/* Limit the number of outstanding send requests. */
84 	int num_sends_allowed;
85 
86 	/* adding three counts for debugging ring buffer errors */
87 	uint32_t nbuf_alloc_err_count;
88 	uint32_t nbuf_dma_err_count;
89 	uint32_t nbuf_ce_enqueue_err_count;
90 	struct hif_msg_callbacks pipe_callbacks;
91 };
92 
93 /**
94  * struct ce_tasklet_entry
95  *
96  * @intr_tq: intr_tq
97  * @ce_id: ce_id
98  * @inited: inited
99  * @hif_ce_state: hif_ce_state
100  * @from_irq: from_irq
101  */
102 struct ce_tasklet_entry {
103 	struct tasklet_struct intr_tq;
104 	enum ce_id_type ce_id;
105 	bool inited;
106 	void *hif_ce_state;
107 };
108 
109 static inline bool hif_dummy_grp_done(struct hif_exec_context *grp_entry, int
110 				      work_done)
111 {
112 	return true;
113 }
114 
115 extern struct hif_execution_ops tasklet_sched_ops;
116 extern struct hif_execution_ops napi_sched_ops;
117 
118 struct ce_stats {
119 	uint32_t ce_per_cpu[CE_COUNT_MAX][QDF_MAX_AVAILABLE_CPU];
120 };
121 
122 struct HIF_CE_state {
123 	struct hif_softc ol_sc;
124 	bool started;
125 	struct ce_tasklet_entry tasklets[CE_COUNT_MAX];
126 	struct hif_exec_context *hif_ext_group[HIF_MAX_GROUP];
127 	uint32_t hif_num_extgroup;
128 	qdf_spinlock_t keep_awake_lock;
129 	qdf_spinlock_t irq_reg_lock;
130 	unsigned int keep_awake_count;
131 	bool verified_awake;
132 	bool fake_sleep;
133 	qdf_timer_t sleep_timer;
134 	bool sleep_timer_init;
135 	qdf_time_t sleep_ticks;
136 	uint32_t ce_register_irq_done;
137 
138 	struct CE_pipe_config *target_ce_config;
139 	struct CE_attr *host_ce_config;
140 	uint32_t target_ce_config_sz;
141 	/* Per-pipe state. */
142 	struct HIF_CE_pipe_info pipe_info[CE_COUNT_MAX];
143 	/* to be activated after BMI_DONE */
144 	struct hif_msg_callbacks msg_callbacks_pending;
145 	/* current msg callbacks in use */
146 	struct hif_msg_callbacks msg_callbacks_current;
147 
148 	/* Target address used to signal a pending firmware event */
149 	uint32_t fw_indicator_address;
150 
151 	/* Copy Engine used for Diagnostic Accesses */
152 	struct CE_handle *ce_diag;
153 	struct ce_stats stats;
154 	struct ce_ops *ce_services;
155 };
156 
157 /*
158  * HIA Map Definition
159  */
160 struct host_interest_area_t {
161 	uint32_t hi_interconnect_state;
162 	uint32_t hi_early_alloc;
163 	uint32_t hi_option_flag2;
164 	uint32_t hi_board_data;
165 	uint32_t hi_board_data_initialized;
166 	uint32_t hi_failure_state;
167 	uint32_t hi_rddi_msi_num;
168 	uint32_t hi_pcie_perst_couple_en;
169 	uint32_t hi_sw_protocol_version;
170 };
171 
172 struct shadow_reg_cfg {
173 	uint16_t ce_id;
174 	uint16_t reg_offset;
175 };
176 
177 struct shadow_reg_v2_cfg {
178 	uint32_t reg_value;
179 };
180 
181 void hif_ce_stop(struct hif_softc *scn);
182 int hif_dump_ce_registers(struct hif_softc *scn);
183 void
184 hif_ce_dump_target_memory(struct hif_softc *scn, void *ramdump_base,
185 			  uint32_t address, uint32_t size);
186 
187 #ifdef IPA_OFFLOAD
188 void hif_ce_ipa_get_ce_resource(struct hif_softc *scn,
189 			     qdf_shared_mem_t **ce_sr,
190 			     uint32_t *ce_sr_ring_size,
191 			     qdf_dma_addr_t *ce_reg_paddr);
192 #else
193 static inline
194 void hif_ce_ipa_get_ce_resource(struct hif_softc *scn,
195 			     qdf_shared_mem_t **ce_sr,
196 			     uint32_t *ce_sr_ring_size,
197 			     qdf_dma_addr_t *ce_reg_paddr)
198 {
199 }
200 
201 #endif
202 int hif_wlan_enable(struct hif_softc *scn);
203 void ce_enable_polling(void *cestate);
204 void ce_disable_polling(void *cestate);
205 void hif_wlan_disable(struct hif_softc *scn);
206 void hif_get_target_ce_config(struct hif_softc *scn,
207 		struct CE_pipe_config **target_ce_config_ret,
208 		uint32_t *target_ce_config_sz_ret,
209 		struct service_to_pipe **target_service_to_ce_map_ret,
210 		uint32_t *target_service_to_ce_map_sz_ret,
211 		struct shadow_reg_cfg **target_shadow_reg_cfg_v1_ret,
212 		uint32_t *shadow_cfg_v1_sz_ret);
213 
214 #ifdef WLAN_FEATURE_EPPING
215 void hif_ce_prepare_epping_config(struct HIF_CE_state *hif_state);
216 void hif_select_epping_service_to_pipe_map(struct service_to_pipe
217 					   **tgt_svc_map_to_use,
218 					   uint32_t *sz_tgt_svc_map_to_use);
219 
220 #else
221 static inline
222 void hif_ce_prepare_epping_config(struct HIF_CE_state *hif_state)
223 { }
224 static inline
225 void hif_select_epping_service_to_pipe_map(struct service_to_pipe
226 					   **tgt_svc_map_to_use,
227 					   uint32_t *sz_tgt_svc_map_to_use)
228 { }
229 #endif
230 
231 #endif /* __CE_H__ */
232