xref: /freebsd/sys/contrib/dev/athk/ath11k/qmi.h (revision d91f8db5f1822c43cd256f19aae1d059e4b25a26)
1 /* SPDX-License-Identifier: BSD-3-Clause-Clear */
2 /*
3  * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
4  */
5 
6 #ifndef ATH11K_QMI_H
7 #define ATH11K_QMI_H
8 
9 #if defined(__FreeBSD__)
10 #include <linux/types.h>
11 #include <linux/list.h>
12 #endif
13 #include <linux/mutex.h>
14 #include <linux/soc/qcom/qmi.h>
15 
16 #define ATH11K_HOST_VERSION_STRING		"WIN"
17 #define ATH11K_QMI_WLANFW_TIMEOUT_MS		10000
18 #define ATH11K_QMI_MAX_BDF_FILE_NAME_SIZE	64
19 #define ATH11K_QMI_CALDB_ADDRESS		0x4BA00000
20 #define ATH11K_QMI_WLANFW_MAX_BUILD_ID_LEN_V01	128
21 #define ATH11K_QMI_WLFW_SERVICE_ID_V01		0x45
22 #define ATH11K_QMI_WLFW_SERVICE_VERS_V01	0x01
23 #define ATH11K_QMI_WLFW_SERVICE_INS_ID_V01	0x02
24 #define ATH11K_QMI_WLFW_SERVICE_INS_ID_V01_QCA6390	0x01
25 #define ATH11K_QMI_WLFW_SERVICE_INS_ID_V01_IPQ8074	0x02
26 #define ATH11K_QMI_WLFW_SERVICE_INS_ID_V01_QCN9074	0x07
27 #define ATH11K_QMI_WLANFW_MAX_TIMESTAMP_LEN_V01	32
28 #define ATH11K_QMI_RESP_LEN_MAX			8192
29 #define ATH11K_QMI_WLANFW_MAX_NUM_MEM_SEG_V01	52
30 #define ATH11K_QMI_CALDB_SIZE			0x480000
31 #define ATH11K_QMI_BDF_EXT_STR_LENGTH		0x20
32 #define ATH11K_QMI_FW_MEM_REQ_SEGMENT_CNT	3
33 
34 #define QMI_WLFW_REQUEST_MEM_IND_V01		0x0035
35 #define QMI_WLFW_FW_MEM_READY_IND_V01		0x0037
36 #define QMI_WLFW_COLD_BOOT_CAL_DONE_IND_V01	0x0021
37 #define QMI_WLFW_FW_READY_IND_V01		0x0038
38 
39 #define QMI_WLANFW_MAX_DATA_SIZE_V01		6144
40 #define ATH11K_FIRMWARE_MODE_OFF		4
41 #define ATH11K_COLD_BOOT_FW_RESET_DELAY		(40 * HZ)
42 
43 struct ath11k_base;
44 
45 enum ath11k_qmi_file_type {
46 	ATH11K_QMI_FILE_TYPE_BDF_GOLDEN,
47 	ATH11K_QMI_FILE_TYPE_CALDATA = 2,
48 	ATH11K_QMI_FILE_TYPE_EEPROM,
49 	ATH11K_QMI_MAX_FILE_TYPE,
50 };
51 
52 enum ath11k_qmi_bdf_type {
53 	ATH11K_QMI_BDF_TYPE_BIN			= 0,
54 	ATH11K_QMI_BDF_TYPE_ELF			= 1,
55 	ATH11K_QMI_BDF_TYPE_REGDB		= 4,
56 };
57 
58 enum ath11k_qmi_event_type {
59 	ATH11K_QMI_EVENT_SERVER_ARRIVE,
60 	ATH11K_QMI_EVENT_SERVER_EXIT,
61 	ATH11K_QMI_EVENT_REQUEST_MEM,
62 	ATH11K_QMI_EVENT_FW_MEM_READY,
63 	ATH11K_QMI_EVENT_FW_READY,
64 	ATH11K_QMI_EVENT_COLD_BOOT_CAL_START,
65 	ATH11K_QMI_EVENT_COLD_BOOT_CAL_DONE,
66 	ATH11K_QMI_EVENT_REGISTER_DRIVER,
67 	ATH11K_QMI_EVENT_UNREGISTER_DRIVER,
68 	ATH11K_QMI_EVENT_RECOVERY,
69 	ATH11K_QMI_EVENT_FORCE_FW_ASSERT,
70 	ATH11K_QMI_EVENT_POWER_UP,
71 	ATH11K_QMI_EVENT_POWER_DOWN,
72 	ATH11K_QMI_EVENT_MAX,
73 };
74 
75 struct ath11k_qmi_driver_event {
76 	struct list_head list;
77 	enum ath11k_qmi_event_type type;
78 	void *data;
79 };
80 
81 struct ath11k_qmi_ce_cfg {
82 	const struct ce_pipe_config *tgt_ce;
83 	int tgt_ce_len;
84 	const struct service_to_pipe *svc_to_ce_map;
85 	int svc_to_ce_map_len;
86 	const u8 *shadow_reg;
87 	int shadow_reg_len;
88 	u32 *shadow_reg_v2;
89 	int shadow_reg_v2_len;
90 };
91 
92 struct ath11k_qmi_event_msg {
93 	struct list_head list;
94 	enum ath11k_qmi_event_type type;
95 };
96 
97 struct target_mem_chunk {
98 	u32 size;
99 	u32 type;
100 	dma_addr_t paddr;
101 	u32 *vaddr;
102 	void __iomem *iaddr;
103 };
104 
105 struct target_info {
106 	u32 chip_id;
107 	u32 chip_family;
108 	u32 board_id;
109 	u32 soc_id;
110 	u32 fw_version;
111 	u32 eeprom_caldata;
112 	char fw_build_timestamp[ATH11K_QMI_WLANFW_MAX_TIMESTAMP_LEN_V01 + 1];
113 	char fw_build_id[ATH11K_QMI_WLANFW_MAX_BUILD_ID_LEN_V01 + 1];
114 	char bdf_ext[ATH11K_QMI_BDF_EXT_STR_LENGTH];
115 };
116 
117 struct m3_mem_region {
118 	u32 size;
119 	dma_addr_t paddr;
120 	void *vaddr;
121 };
122 
123 struct ath11k_qmi {
124 	struct ath11k_base *ab;
125 	struct qmi_handle handle;
126 	struct sockaddr_qrtr sq;
127 	struct work_struct event_work;
128 	struct workqueue_struct *event_wq;
129 	struct list_head event_list;
130 	spinlock_t event_lock; /* spinlock for qmi event list */
131 	struct ath11k_qmi_ce_cfg ce_cfg;
132 	struct target_mem_chunk target_mem[ATH11K_QMI_WLANFW_MAX_NUM_MEM_SEG_V01];
133 	u32 mem_seg_count;
134 	u32 target_mem_mode;
135 	bool target_mem_delayed;
136 	u8 cal_done;
137 	struct target_info target;
138 	struct m3_mem_region m3_mem;
139 	unsigned int service_ins_id;
140 	wait_queue_head_t cold_boot_waitq;
141 };
142 
143 #define QMI_WLANFW_HOST_CAP_REQ_MSG_V01_MAX_LEN		261
144 #define QMI_WLANFW_HOST_CAP_REQ_V01			0x0034
145 #define QMI_WLANFW_HOST_CAP_RESP_MSG_V01_MAX_LEN	7
146 #define QMI_WLFW_HOST_CAP_RESP_V01			0x0034
147 #define QMI_WLFW_MAX_NUM_GPIO_V01			32
148 #define QMI_IPQ8074_FW_MEM_MODE				0xFF
149 #define HOST_DDR_REGION_TYPE				0x1
150 #define BDF_MEM_REGION_TYPE				0x2
151 #define M3_DUMP_REGION_TYPE				0x3
152 #define CALDB_MEM_REGION_TYPE				0x4
153 
154 struct qmi_wlanfw_host_cap_req_msg_v01 {
155 	u8 num_clients_valid;
156 	u32 num_clients;
157 	u8 wake_msi_valid;
158 	u32 wake_msi;
159 	u8 gpios_valid;
160 	u32 gpios_len;
161 	u32 gpios[QMI_WLFW_MAX_NUM_GPIO_V01];
162 	u8 nm_modem_valid;
163 	u8 nm_modem;
164 	u8 bdf_support_valid;
165 	u8 bdf_support;
166 	u8 bdf_cache_support_valid;
167 	u8 bdf_cache_support;
168 	u8 m3_support_valid;
169 	u8 m3_support;
170 	u8 m3_cache_support_valid;
171 	u8 m3_cache_support;
172 	u8 cal_filesys_support_valid;
173 	u8 cal_filesys_support;
174 	u8 cal_cache_support_valid;
175 	u8 cal_cache_support;
176 	u8 cal_done_valid;
177 	u8 cal_done;
178 	u8 mem_bucket_valid;
179 	u32 mem_bucket;
180 	u8 mem_cfg_mode_valid;
181 	u8 mem_cfg_mode;
182 };
183 
184 struct qmi_wlanfw_host_cap_resp_msg_v01 {
185 	struct qmi_response_type_v01 resp;
186 };
187 
188 #define QMI_WLANFW_IND_REGISTER_REQ_MSG_V01_MAX_LEN		54
189 #define QMI_WLANFW_IND_REGISTER_REQ_V01				0x0020
190 #define QMI_WLANFW_IND_REGISTER_RESP_MSG_V01_MAX_LEN		18
191 #define QMI_WLANFW_IND_REGISTER_RESP_V01			0x0020
192 #define QMI_WLANFW_CLIENT_ID					0x4b4e454c
193 
194 struct qmi_wlanfw_ind_register_req_msg_v01 {
195 	u8 fw_ready_enable_valid;
196 	u8 fw_ready_enable;
197 	u8 initiate_cal_download_enable_valid;
198 	u8 initiate_cal_download_enable;
199 	u8 initiate_cal_update_enable_valid;
200 	u8 initiate_cal_update_enable;
201 	u8 msa_ready_enable_valid;
202 	u8 msa_ready_enable;
203 	u8 pin_connect_result_enable_valid;
204 	u8 pin_connect_result_enable;
205 	u8 client_id_valid;
206 	u32 client_id;
207 	u8 request_mem_enable_valid;
208 	u8 request_mem_enable;
209 	u8 fw_mem_ready_enable_valid;
210 	u8 fw_mem_ready_enable;
211 	u8 fw_init_done_enable_valid;
212 	u8 fw_init_done_enable;
213 	u8 rejuvenate_enable_valid;
214 	u32 rejuvenate_enable;
215 	u8 xo_cal_enable_valid;
216 	u8 xo_cal_enable;
217 	u8 cal_done_enable_valid;
218 	u8 cal_done_enable;
219 };
220 
221 struct qmi_wlanfw_ind_register_resp_msg_v01 {
222 	struct qmi_response_type_v01 resp;
223 	u8 fw_status_valid;
224 	u64 fw_status;
225 };
226 
227 #define QMI_WLANFW_REQUEST_MEM_IND_MSG_V01_MAX_LEN	1824
228 #define QMI_WLANFW_RESPOND_MEM_REQ_MSG_V01_MAX_LEN	888
229 #define QMI_WLANFW_RESPOND_MEM_RESP_MSG_V01_MAX_LEN	7
230 #define QMI_WLANFW_REQUEST_MEM_IND_V01			0x0035
231 #define QMI_WLANFW_RESPOND_MEM_REQ_V01			0x0036
232 #define QMI_WLANFW_RESPOND_MEM_RESP_V01			0x0036
233 #define QMI_WLANFW_MAX_NUM_MEM_CFG_V01			2
234 
235 struct qmi_wlanfw_mem_cfg_s_v01 {
236 	u64 offset;
237 	u32 size;
238 	u8 secure_flag;
239 };
240 
241 enum qmi_wlanfw_mem_type_enum_v01 {
242 	WLANFW_MEM_TYPE_ENUM_MIN_VAL_V01 = INT_MIN,
243 	QMI_WLANFW_MEM_TYPE_MSA_V01 = 0,
244 	QMI_WLANFW_MEM_TYPE_DDR_V01 = 1,
245 	QMI_WLANFW_MEM_BDF_V01 = 2,
246 	QMI_WLANFW_MEM_M3_V01 = 3,
247 	QMI_WLANFW_MEM_CAL_V01 = 4,
248 	QMI_WLANFW_MEM_DPD_V01 = 5,
249 	WLANFW_MEM_TYPE_ENUM_MAX_VAL_V01 = INT_MAX,
250 };
251 
252 struct qmi_wlanfw_mem_seg_s_v01 {
253 	u32 size;
254 	enum qmi_wlanfw_mem_type_enum_v01 type;
255 	u32 mem_cfg_len;
256 	struct qmi_wlanfw_mem_cfg_s_v01 mem_cfg[QMI_WLANFW_MAX_NUM_MEM_CFG_V01];
257 };
258 
259 struct qmi_wlanfw_request_mem_ind_msg_v01 {
260 	u32 mem_seg_len;
261 	struct qmi_wlanfw_mem_seg_s_v01 mem_seg[ATH11K_QMI_WLANFW_MAX_NUM_MEM_SEG_V01];
262 };
263 
264 struct qmi_wlanfw_mem_seg_resp_s_v01 {
265 	u64 addr;
266 	u32 size;
267 	enum qmi_wlanfw_mem_type_enum_v01 type;
268 	u8 restore;
269 };
270 
271 struct qmi_wlanfw_respond_mem_req_msg_v01 {
272 	u32 mem_seg_len;
273 	struct qmi_wlanfw_mem_seg_resp_s_v01 mem_seg[ATH11K_QMI_WLANFW_MAX_NUM_MEM_SEG_V01];
274 };
275 
276 struct qmi_wlanfw_respond_mem_resp_msg_v01 {
277 	struct qmi_response_type_v01 resp;
278 };
279 
280 struct qmi_wlanfw_fw_mem_ready_ind_msg_v01 {
281 	char placeholder;
282 };
283 
284 struct qmi_wlanfw_fw_ready_ind_msg_v01 {
285 	char placeholder;
286 };
287 
288 struct qmi_wlanfw_fw_cold_cal_done_ind_msg_v01 {
289 	char placeholder;
290 };
291 
292 #define QMI_WLANFW_CAP_REQ_MSG_V01_MAX_LEN	0
293 #define QMI_WLANFW_CAP_RESP_MSG_V01_MAX_LEN	235
294 #define QMI_WLANFW_CAP_REQ_V01			0x0024
295 #define QMI_WLANFW_CAP_RESP_V01			0x0024
296 
297 enum qmi_wlanfw_pipedir_enum_v01 {
298 	QMI_WLFW_PIPEDIR_NONE_V01 = 0,
299 	QMI_WLFW_PIPEDIR_IN_V01 = 1,
300 	QMI_WLFW_PIPEDIR_OUT_V01 = 2,
301 	QMI_WLFW_PIPEDIR_INOUT_V01 = 3,
302 };
303 
304 struct qmi_wlanfw_ce_tgt_pipe_cfg_s_v01 {
305 	__le32 pipe_num;
306 	__le32 pipe_dir;
307 	__le32 nentries;
308 	__le32 nbytes_max;
309 	__le32 flags;
310 };
311 
312 struct qmi_wlanfw_ce_svc_pipe_cfg_s_v01 {
313 	__le32 service_id;
314 	__le32 pipe_dir;
315 	__le32 pipe_num;
316 };
317 
318 struct qmi_wlanfw_shadow_reg_cfg_s_v01 {
319 	u16 id;
320 	u16 offset;
321 };
322 
323 struct qmi_wlanfw_shadow_reg_v2_cfg_s_v01 {
324 	u32 addr;
325 };
326 
327 struct qmi_wlanfw_memory_region_info_s_v01 {
328 	u64 region_addr;
329 	u32 size;
330 	u8 secure_flag;
331 };
332 
333 struct qmi_wlanfw_rf_chip_info_s_v01 {
334 	u32 chip_id;
335 	u32 chip_family;
336 };
337 
338 struct qmi_wlanfw_rf_board_info_s_v01 {
339 	u32 board_id;
340 };
341 
342 struct qmi_wlanfw_soc_info_s_v01 {
343 	u32 soc_id;
344 };
345 
346 struct qmi_wlanfw_fw_version_info_s_v01 {
347 	u32 fw_version;
348 	char fw_build_timestamp[ATH11K_QMI_WLANFW_MAX_TIMESTAMP_LEN_V01 + 1];
349 };
350 
351 enum qmi_wlanfw_cal_temp_id_enum_v01 {
352 	QMI_WLANFW_CAL_TEMP_IDX_0_V01 = 0,
353 	QMI_WLANFW_CAL_TEMP_IDX_1_V01 = 1,
354 	QMI_WLANFW_CAL_TEMP_IDX_2_V01 = 2,
355 	QMI_WLANFW_CAL_TEMP_IDX_3_V01 = 3,
356 	QMI_WLANFW_CAL_TEMP_IDX_4_V01 = 4,
357 	QMI_WLANFW_CAL_TEMP_ID_MAX_V01 = 0xFF,
358 };
359 
360 struct qmi_wlanfw_cap_resp_msg_v01 {
361 	struct qmi_response_type_v01 resp;
362 	u8 chip_info_valid;
363 	struct qmi_wlanfw_rf_chip_info_s_v01 chip_info;
364 	u8 board_info_valid;
365 	struct qmi_wlanfw_rf_board_info_s_v01 board_info;
366 	u8 soc_info_valid;
367 	struct qmi_wlanfw_soc_info_s_v01 soc_info;
368 	u8 fw_version_info_valid;
369 	struct qmi_wlanfw_fw_version_info_s_v01 fw_version_info;
370 	u8 fw_build_id_valid;
371 	char fw_build_id[ATH11K_QMI_WLANFW_MAX_BUILD_ID_LEN_V01 + 1];
372 	u8 num_macs_valid;
373 	u8 num_macs;
374 	u8 voltage_mv_valid;
375 	u32 voltage_mv;
376 	u8 time_freq_hz_valid;
377 	u32 time_freq_hz;
378 	u8 otp_version_valid;
379 	u32 otp_version;
380 	u8 eeprom_read_timeout_valid;
381 	u32 eeprom_read_timeout;
382 };
383 
384 struct qmi_wlanfw_cap_req_msg_v01 {
385 	char placeholder;
386 };
387 
388 #define QMI_WLANFW_BDF_DOWNLOAD_REQ_MSG_V01_MAX_LEN	6182
389 #define QMI_WLANFW_BDF_DOWNLOAD_RESP_MSG_V01_MAX_LEN	7
390 #define QMI_WLANFW_BDF_DOWNLOAD_RESP_V01		0x0025
391 #define QMI_WLANFW_BDF_DOWNLOAD_REQ_V01			0x0025
392 /* TODO: Need to check with MCL and FW team that data can be pointer and
393  * can be last element in structure
394  */
395 struct qmi_wlanfw_bdf_download_req_msg_v01 {
396 	u8 valid;
397 	u8 file_id_valid;
398 	enum qmi_wlanfw_cal_temp_id_enum_v01 file_id;
399 	u8 total_size_valid;
400 	u32 total_size;
401 	u8 seg_id_valid;
402 	u32 seg_id;
403 	u8 data_valid;
404 	u32 data_len;
405 	u8 data[QMI_WLANFW_MAX_DATA_SIZE_V01];
406 	u8 end_valid;
407 	u8 end;
408 	u8 bdf_type_valid;
409 	u8 bdf_type;
410 
411 };
412 
413 struct qmi_wlanfw_bdf_download_resp_msg_v01 {
414 	struct qmi_response_type_v01 resp;
415 };
416 
417 #define QMI_WLANFW_M3_INFO_REQ_MSG_V01_MAX_MSG_LEN	18
418 #define QMI_WLANFW_M3_INFO_RESP_MSG_V01_MAX_MSG_LEN	7
419 #define QMI_WLANFW_M3_INFO_RESP_V01		0x003C
420 #define QMI_WLANFW_M3_INFO_REQ_V01		0x003C
421 
422 struct qmi_wlanfw_m3_info_req_msg_v01 {
423 	u64 addr;
424 	u32 size;
425 };
426 
427 struct qmi_wlanfw_m3_info_resp_msg_v01 {
428 	struct qmi_response_type_v01 resp;
429 };
430 
431 #define QMI_WLANFW_WLAN_MODE_REQ_MSG_V01_MAX_LEN	11
432 #define QMI_WLANFW_WLAN_MODE_RESP_MSG_V01_MAX_LEN	7
433 #define QMI_WLANFW_WLAN_CFG_REQ_MSG_V01_MAX_LEN		803
434 #define QMI_WLANFW_WLAN_CFG_RESP_MSG_V01_MAX_LEN	7
435 #define QMI_WLANFW_WLAN_INI_REQ_MSG_V01_MAX_LEN		4
436 #define QMI_WLANFW_WLAN_MODE_REQ_V01			0x0022
437 #define QMI_WLANFW_WLAN_MODE_RESP_V01			0x0022
438 #define QMI_WLANFW_WLAN_CFG_REQ_V01			0x0023
439 #define QMI_WLANFW_WLAN_CFG_RESP_V01			0x0023
440 #define QMI_WLANFW_WLAN_INI_REQ_V01			0x002F
441 #define QMI_WLANFW_MAX_STR_LEN_V01			16
442 #define QMI_WLANFW_MAX_NUM_CE_V01			12
443 #define QMI_WLANFW_MAX_NUM_SVC_V01			24
444 #define QMI_WLANFW_MAX_NUM_SHADOW_REG_V01		24
445 #define QMI_WLANFW_MAX_NUM_SHADOW_REG_V2_V01		36
446 
447 struct qmi_wlanfw_wlan_mode_req_msg_v01 {
448 	u32 mode;
449 	u8 hw_debug_valid;
450 	u8 hw_debug;
451 };
452 
453 struct qmi_wlanfw_wlan_mode_resp_msg_v01 {
454 	struct qmi_response_type_v01 resp;
455 };
456 
457 struct qmi_wlanfw_wlan_cfg_req_msg_v01 {
458 	u8 host_version_valid;
459 	char host_version[QMI_WLANFW_MAX_STR_LEN_V01 + 1];
460 	u8  tgt_cfg_valid;
461 	u32  tgt_cfg_len;
462 	struct qmi_wlanfw_ce_tgt_pipe_cfg_s_v01
463 			tgt_cfg[QMI_WLANFW_MAX_NUM_CE_V01];
464 	u8  svc_cfg_valid;
465 	u32 svc_cfg_len;
466 	struct qmi_wlanfw_ce_svc_pipe_cfg_s_v01
467 			svc_cfg[QMI_WLANFW_MAX_NUM_SVC_V01];
468 	u8 shadow_reg_valid;
469 	u32 shadow_reg_len;
470 	struct qmi_wlanfw_shadow_reg_cfg_s_v01
471 		shadow_reg[QMI_WLANFW_MAX_NUM_SHADOW_REG_V01];
472 	u8 shadow_reg_v2_valid;
473 	u32 shadow_reg_v2_len;
474 	struct qmi_wlanfw_shadow_reg_v2_cfg_s_v01
475 		shadow_reg_v2[QMI_WLANFW_MAX_NUM_SHADOW_REG_V2_V01];
476 };
477 
478 struct qmi_wlanfw_wlan_cfg_resp_msg_v01 {
479 	struct qmi_response_type_v01 resp;
480 };
481 
482 struct qmi_wlanfw_wlan_ini_req_msg_v01 {
483 	/* Must be set to true if enablefwlog is being passed */
484 	u8 enablefwlog_valid;
485 	u8 enablefwlog;
486 };
487 
488 struct qmi_wlanfw_wlan_ini_resp_msg_v01 {
489 	struct qmi_response_type_v01 resp;
490 };
491 
492 int ath11k_qmi_firmware_start(struct ath11k_base *ab,
493 			      u32 mode);
494 void ath11k_qmi_firmware_stop(struct ath11k_base *ab);
495 void ath11k_qmi_event_work(struct work_struct *work);
496 void ath11k_qmi_msg_recv_work(struct work_struct *work);
497 void ath11k_qmi_deinit_service(struct ath11k_base *ab);
498 int ath11k_qmi_init_service(struct ath11k_base *ab);
499 
500 #endif
501