xref: /freebsd/sys/contrib/dev/athk/ath11k/qmi.c (revision 7ef62cebc2f965b0f640263e179276928885e33d)
1 // SPDX-License-Identifier: BSD-3-Clause-Clear
2 /*
3  * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
4  */
5 
6 #if defined(__FreeBSD__)
7 #define	LINUXKPI_PARAM_PREFIX	ath11k_qmi_
8 #endif
9 
10 #include <linux/elf.h>
11 
12 #if defined(__FreeBSD__)
13 #include <linux/workqueue.h>
14 #include <linux/firmware.h>
15 #include <linux/socket.h>
16 #include <linux/wait.h>
17 #endif
18 #include "qmi.h"
19 #include "core.h"
20 #include "debug.h"
21 #if defined(CONFIG_OF)
22 #include <linux/of.h>
23 #endif
24 #include <linux/of_address.h>
25 #include <linux/ioport.h>
26 #if defined(__linux__)
27 #include <linux/firmware.h>
28 #endif
29 
30 #define SLEEP_CLOCK_SELECT_INTERNAL_BIT	0x02
31 #define HOST_CSTATE_BIT			0x04
32 
33 bool ath11k_cold_boot_cal = 1;
34 EXPORT_SYMBOL(ath11k_cold_boot_cal);
35 module_param_named(cold_boot_cal, ath11k_cold_boot_cal, bool, 0644);
36 MODULE_PARM_DESC(cold_boot_cal,
37 		 "Decrease the channel switch time but increase the driver load time (Default: true)");
38 
39 static struct qmi_elem_info qmi_wlanfw_host_cap_req_msg_v01_ei[] = {
40 	{
41 		.data_type	= QMI_OPT_FLAG,
42 		.elem_len	= 1,
43 		.elem_size	= sizeof(u8),
44 		.array_type	= NO_ARRAY,
45 		.tlv_type	= 0x10,
46 		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
47 					   num_clients_valid),
48 	},
49 	{
50 		.data_type	= QMI_UNSIGNED_4_BYTE,
51 		.elem_len	= 1,
52 		.elem_size	= sizeof(u32),
53 		.array_type	= NO_ARRAY,
54 		.tlv_type	= 0x10,
55 		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
56 					   num_clients),
57 	},
58 	{
59 		.data_type	= QMI_OPT_FLAG,
60 		.elem_len	= 1,
61 		.elem_size	= sizeof(u8),
62 		.array_type	= NO_ARRAY,
63 		.tlv_type	= 0x11,
64 		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
65 					   wake_msi_valid),
66 	},
67 	{
68 		.data_type	= QMI_UNSIGNED_4_BYTE,
69 		.elem_len	= 1,
70 		.elem_size	= sizeof(u32),
71 		.array_type	= NO_ARRAY,
72 		.tlv_type	= 0x11,
73 		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
74 					   wake_msi),
75 	},
76 	{
77 		.data_type	= QMI_OPT_FLAG,
78 		.elem_len	= 1,
79 		.elem_size	= sizeof(u8),
80 		.array_type	= NO_ARRAY,
81 		.tlv_type	= 0x12,
82 		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
83 					   gpios_valid),
84 	},
85 	{
86 		.data_type	= QMI_DATA_LEN,
87 		.elem_len	= 1,
88 		.elem_size	= sizeof(u8),
89 		.array_type	= NO_ARRAY,
90 		.tlv_type	= 0x12,
91 		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
92 					   gpios_len),
93 	},
94 	{
95 		.data_type	= QMI_UNSIGNED_4_BYTE,
96 		.elem_len	= QMI_WLFW_MAX_NUM_GPIO_V01,
97 		.elem_size	= sizeof(u32),
98 		.array_type	= VAR_LEN_ARRAY,
99 		.tlv_type	= 0x12,
100 		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
101 					   gpios),
102 	},
103 	{
104 		.data_type	= QMI_OPT_FLAG,
105 		.elem_len	= 1,
106 		.elem_size	= sizeof(u8),
107 		.array_type	= NO_ARRAY,
108 		.tlv_type	= 0x13,
109 		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
110 					   nm_modem_valid),
111 	},
112 	{
113 		.data_type	= QMI_UNSIGNED_1_BYTE,
114 		.elem_len	= 1,
115 		.elem_size	= sizeof(u8),
116 		.array_type	= NO_ARRAY,
117 		.tlv_type	= 0x13,
118 		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
119 					   nm_modem),
120 	},
121 	{
122 		.data_type	= QMI_OPT_FLAG,
123 		.elem_len	= 1,
124 		.elem_size	= sizeof(u8),
125 		.array_type	= NO_ARRAY,
126 		.tlv_type	= 0x14,
127 		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
128 					   bdf_support_valid),
129 	},
130 	{
131 		.data_type	= QMI_UNSIGNED_1_BYTE,
132 		.elem_len	= 1,
133 		.elem_size	= sizeof(u8),
134 		.array_type	= NO_ARRAY,
135 		.tlv_type	= 0x14,
136 		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
137 					   bdf_support),
138 	},
139 	{
140 		.data_type	= QMI_OPT_FLAG,
141 		.elem_len	= 1,
142 		.elem_size	= sizeof(u8),
143 		.array_type	= NO_ARRAY,
144 		.tlv_type	= 0x15,
145 		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
146 					   bdf_cache_support_valid),
147 	},
148 	{
149 		.data_type	= QMI_UNSIGNED_1_BYTE,
150 		.elem_len	= 1,
151 		.elem_size	= sizeof(u8),
152 		.array_type	= NO_ARRAY,
153 		.tlv_type	= 0x15,
154 		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
155 					   bdf_cache_support),
156 	},
157 	{
158 		.data_type	= QMI_OPT_FLAG,
159 		.elem_len	= 1,
160 		.elem_size	= sizeof(u8),
161 		.array_type	= NO_ARRAY,
162 		.tlv_type	= 0x16,
163 		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
164 					   m3_support_valid),
165 	},
166 	{
167 		.data_type	= QMI_UNSIGNED_1_BYTE,
168 		.elem_len	= 1,
169 		.elem_size	= sizeof(u8),
170 		.array_type	= NO_ARRAY,
171 		.tlv_type	= 0x16,
172 		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
173 					   m3_support),
174 	},
175 	{
176 		.data_type	= QMI_OPT_FLAG,
177 		.elem_len	= 1,
178 		.elem_size	= sizeof(u8),
179 		.array_type	= NO_ARRAY,
180 		.tlv_type	= 0x17,
181 		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
182 					   m3_cache_support_valid),
183 	},
184 	{
185 		.data_type	= QMI_UNSIGNED_1_BYTE,
186 		.elem_len	= 1,
187 		.elem_size	= sizeof(u8),
188 		.array_type	= NO_ARRAY,
189 		.tlv_type	= 0x17,
190 		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
191 					   m3_cache_support),
192 	},
193 	{
194 		.data_type	= QMI_OPT_FLAG,
195 		.elem_len	= 1,
196 		.elem_size	= sizeof(u8),
197 		.array_type	= NO_ARRAY,
198 		.tlv_type	= 0x18,
199 		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
200 					   cal_filesys_support_valid),
201 	},
202 	{
203 		.data_type	= QMI_UNSIGNED_1_BYTE,
204 		.elem_len	= 1,
205 		.elem_size	= sizeof(u8),
206 		.array_type	= NO_ARRAY,
207 		.tlv_type	= 0x18,
208 		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
209 					   cal_filesys_support),
210 	},
211 	{
212 		.data_type	= QMI_OPT_FLAG,
213 		.elem_len	= 1,
214 		.elem_size	= sizeof(u8),
215 		.array_type	= NO_ARRAY,
216 		.tlv_type	= 0x19,
217 		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
218 					   cal_cache_support_valid),
219 	},
220 	{
221 		.data_type	= QMI_UNSIGNED_1_BYTE,
222 		.elem_len	= 1,
223 		.elem_size	= sizeof(u8),
224 		.array_type	= NO_ARRAY,
225 		.tlv_type	= 0x19,
226 		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
227 					   cal_cache_support),
228 	},
229 	{
230 		.data_type	= QMI_OPT_FLAG,
231 		.elem_len	= 1,
232 		.elem_size	= sizeof(u8),
233 		.array_type	= NO_ARRAY,
234 		.tlv_type	= 0x1A,
235 		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
236 					   cal_done_valid),
237 	},
238 	{
239 		.data_type	= QMI_UNSIGNED_1_BYTE,
240 		.elem_len	= 1,
241 		.elem_size	= sizeof(u8),
242 		.array_type	= NO_ARRAY,
243 		.tlv_type	= 0x1A,
244 		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
245 					   cal_done),
246 	},
247 	{
248 		.data_type	= QMI_OPT_FLAG,
249 		.elem_len	= 1,
250 		.elem_size	= sizeof(u8),
251 		.array_type	= NO_ARRAY,
252 		.tlv_type	= 0x1B,
253 		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
254 					   mem_bucket_valid),
255 	},
256 	{
257 		.data_type	= QMI_UNSIGNED_4_BYTE,
258 		.elem_len	= 1,
259 		.elem_size	= sizeof(u32),
260 		.array_type	= NO_ARRAY,
261 		.tlv_type	= 0x1B,
262 		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
263 					   mem_bucket),
264 	},
265 	{
266 		.data_type	= QMI_OPT_FLAG,
267 		.elem_len	= 1,
268 		.elem_size	= sizeof(u8),
269 		.array_type	= NO_ARRAY,
270 		.tlv_type	= 0x1C,
271 		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
272 					   mem_cfg_mode_valid),
273 	},
274 	{
275 		.data_type	= QMI_UNSIGNED_1_BYTE,
276 		.elem_len	= 1,
277 		.elem_size	= sizeof(u8),
278 		.array_type	= NO_ARRAY,
279 		.tlv_type	= 0x1C,
280 		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
281 					   mem_cfg_mode),
282 	},
283 	{
284 		.data_type	= QMI_EOTI,
285 		.array_type	= NO_ARRAY,
286 		.tlv_type	= QMI_COMMON_TLV_TYPE,
287 	},
288 };
289 
290 static struct qmi_elem_info qmi_wlanfw_host_cap_resp_msg_v01_ei[] = {
291 	{
292 		.data_type	= QMI_STRUCT,
293 		.elem_len	= 1,
294 		.elem_size	= sizeof(struct qmi_response_type_v01),
295 		.array_type	= NO_ARRAY,
296 		.tlv_type	= 0x02,
297 		.offset		= offsetof(struct qmi_wlanfw_host_cap_resp_msg_v01, resp),
298 		.ei_array	= qmi_response_type_v01_ei,
299 	},
300 	{
301 		.data_type	= QMI_EOTI,
302 		.array_type	= NO_ARRAY,
303 		.tlv_type	= QMI_COMMON_TLV_TYPE,
304 	},
305 };
306 
307 static struct qmi_elem_info qmi_wlanfw_ind_register_req_msg_v01_ei[] = {
308 	{
309 		.data_type	= QMI_OPT_FLAG,
310 		.elem_len	= 1,
311 		.elem_size	= sizeof(u8),
312 		.array_type	= NO_ARRAY,
313 		.tlv_type	= 0x10,
314 		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
315 					   fw_ready_enable_valid),
316 	},
317 	{
318 		.data_type	= QMI_UNSIGNED_1_BYTE,
319 		.elem_len	= 1,
320 		.elem_size	= sizeof(u8),
321 		.array_type	= NO_ARRAY,
322 		.tlv_type	= 0x10,
323 		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
324 					   fw_ready_enable),
325 	},
326 	{
327 		.data_type	= QMI_OPT_FLAG,
328 		.elem_len	= 1,
329 		.elem_size	= sizeof(u8),
330 		.array_type	= NO_ARRAY,
331 		.tlv_type	= 0x11,
332 		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
333 					   initiate_cal_download_enable_valid),
334 	},
335 	{
336 		.data_type	= QMI_UNSIGNED_1_BYTE,
337 		.elem_len	= 1,
338 		.elem_size	= sizeof(u8),
339 		.array_type	= NO_ARRAY,
340 		.tlv_type	= 0x11,
341 		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
342 					   initiate_cal_download_enable),
343 	},
344 	{
345 		.data_type	= QMI_OPT_FLAG,
346 		.elem_len	= 1,
347 		.elem_size	= sizeof(u8),
348 		.array_type	= NO_ARRAY,
349 		.tlv_type	= 0x12,
350 		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
351 					   initiate_cal_update_enable_valid),
352 	},
353 	{
354 		.data_type	= QMI_UNSIGNED_1_BYTE,
355 		.elem_len	= 1,
356 		.elem_size	= sizeof(u8),
357 		.array_type	= NO_ARRAY,
358 		.tlv_type	= 0x12,
359 		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
360 					   initiate_cal_update_enable),
361 	},
362 	{
363 		.data_type	= QMI_OPT_FLAG,
364 		.elem_len	= 1,
365 		.elem_size	= sizeof(u8),
366 		.array_type	= NO_ARRAY,
367 		.tlv_type	= 0x13,
368 		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
369 					   msa_ready_enable_valid),
370 	},
371 	{
372 		.data_type	= QMI_UNSIGNED_1_BYTE,
373 		.elem_len	= 1,
374 		.elem_size	= sizeof(u8),
375 		.array_type	= NO_ARRAY,
376 		.tlv_type	= 0x13,
377 		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
378 					   msa_ready_enable),
379 	},
380 	{
381 		.data_type	= QMI_OPT_FLAG,
382 		.elem_len	= 1,
383 		.elem_size	= sizeof(u8),
384 		.array_type	= NO_ARRAY,
385 		.tlv_type	= 0x14,
386 		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
387 					   pin_connect_result_enable_valid),
388 	},
389 	{
390 		.data_type	= QMI_UNSIGNED_1_BYTE,
391 		.elem_len	= 1,
392 		.elem_size	= sizeof(u8),
393 		.array_type	= NO_ARRAY,
394 		.tlv_type	= 0x14,
395 		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
396 					   pin_connect_result_enable),
397 	},
398 	{
399 		.data_type	= QMI_OPT_FLAG,
400 		.elem_len	= 1,
401 		.elem_size	= sizeof(u8),
402 		.array_type	= NO_ARRAY,
403 		.tlv_type	= 0x15,
404 		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
405 					   client_id_valid),
406 	},
407 	{
408 		.data_type	= QMI_UNSIGNED_4_BYTE,
409 		.elem_len	= 1,
410 		.elem_size	= sizeof(u32),
411 		.array_type	= NO_ARRAY,
412 		.tlv_type	= 0x15,
413 		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
414 					   client_id),
415 	},
416 	{
417 		.data_type	= QMI_OPT_FLAG,
418 		.elem_len	= 1,
419 		.elem_size	= sizeof(u8),
420 		.array_type	= NO_ARRAY,
421 		.tlv_type	= 0x16,
422 		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
423 					   request_mem_enable_valid),
424 	},
425 	{
426 		.data_type	= QMI_UNSIGNED_1_BYTE,
427 		.elem_len	= 1,
428 		.elem_size	= sizeof(u8),
429 		.array_type	= NO_ARRAY,
430 		.tlv_type	= 0x16,
431 		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
432 					   request_mem_enable),
433 	},
434 	{
435 		.data_type	= QMI_OPT_FLAG,
436 		.elem_len	= 1,
437 		.elem_size	= sizeof(u8),
438 		.array_type	= NO_ARRAY,
439 		.tlv_type	= 0x17,
440 		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
441 					   fw_mem_ready_enable_valid),
442 	},
443 	{
444 		.data_type	= QMI_UNSIGNED_1_BYTE,
445 		.elem_len	= 1,
446 		.elem_size	= sizeof(u8),
447 		.array_type	= NO_ARRAY,
448 		.tlv_type	= 0x17,
449 		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
450 					   fw_mem_ready_enable),
451 	},
452 	{
453 		.data_type	= QMI_OPT_FLAG,
454 		.elem_len	= 1,
455 		.elem_size	= sizeof(u8),
456 		.array_type	= NO_ARRAY,
457 		.tlv_type	= 0x18,
458 		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
459 					   fw_init_done_enable_valid),
460 	},
461 	{
462 		.data_type	= QMI_UNSIGNED_1_BYTE,
463 		.elem_len	= 1,
464 		.elem_size	= sizeof(u8),
465 		.array_type	= NO_ARRAY,
466 		.tlv_type	= 0x18,
467 		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
468 					   fw_init_done_enable),
469 	},
470 
471 	{
472 		.data_type	= QMI_OPT_FLAG,
473 		.elem_len	= 1,
474 		.elem_size	= sizeof(u8),
475 		.array_type	= NO_ARRAY,
476 		.tlv_type	= 0x19,
477 		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
478 					   rejuvenate_enable_valid),
479 	},
480 	{
481 		.data_type	= QMI_UNSIGNED_1_BYTE,
482 		.elem_len	= 1,
483 		.elem_size	= sizeof(u8),
484 		.array_type	= NO_ARRAY,
485 		.tlv_type	= 0x19,
486 		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
487 					   rejuvenate_enable),
488 	},
489 	{
490 		.data_type	= QMI_OPT_FLAG,
491 		.elem_len	= 1,
492 		.elem_size	= sizeof(u8),
493 		.array_type	= NO_ARRAY,
494 		.tlv_type	= 0x1A,
495 		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
496 					   xo_cal_enable_valid),
497 	},
498 	{
499 		.data_type	= QMI_UNSIGNED_1_BYTE,
500 		.elem_len	= 1,
501 		.elem_size	= sizeof(u8),
502 		.array_type	= NO_ARRAY,
503 		.tlv_type	= 0x1A,
504 		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
505 					   xo_cal_enable),
506 	},
507 	{
508 		.data_type	= QMI_OPT_FLAG,
509 		.elem_len	= 1,
510 		.elem_size	= sizeof(u8),
511 		.array_type	= NO_ARRAY,
512 		.tlv_type	= 0x1B,
513 		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
514 					   cal_done_enable_valid),
515 	},
516 	{
517 		.data_type	= QMI_UNSIGNED_1_BYTE,
518 		.elem_len	= 1,
519 		.elem_size	= sizeof(u8),
520 		.array_type	= NO_ARRAY,
521 		.tlv_type	= 0x1B,
522 		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
523 					   cal_done_enable),
524 	},
525 	{
526 		.data_type	= QMI_EOTI,
527 		.array_type	= NO_ARRAY,
528 		.tlv_type	= QMI_COMMON_TLV_TYPE,
529 	},
530 };
531 
532 static struct qmi_elem_info qmi_wlanfw_ind_register_resp_msg_v01_ei[] = {
533 	{
534 		.data_type	= QMI_STRUCT,
535 		.elem_len	= 1,
536 		.elem_size	= sizeof(struct qmi_response_type_v01),
537 		.array_type	= NO_ARRAY,
538 		.tlv_type	= 0x02,
539 		.offset		= offsetof(struct qmi_wlanfw_ind_register_resp_msg_v01,
540 					   resp),
541 		.ei_array	= qmi_response_type_v01_ei,
542 	},
543 	{
544 		.data_type	= QMI_OPT_FLAG,
545 		.elem_len	= 1,
546 		.elem_size	= sizeof(u8),
547 		.array_type	= NO_ARRAY,
548 		.tlv_type	= 0x10,
549 		.offset		= offsetof(struct qmi_wlanfw_ind_register_resp_msg_v01,
550 					   fw_status_valid),
551 	},
552 	{
553 		.data_type	= QMI_UNSIGNED_8_BYTE,
554 		.elem_len	= 1,
555 		.elem_size	= sizeof(u64),
556 		.array_type	= NO_ARRAY,
557 		.tlv_type	= 0x10,
558 		.offset		= offsetof(struct qmi_wlanfw_ind_register_resp_msg_v01,
559 					   fw_status),
560 	},
561 	{
562 		.data_type	= QMI_EOTI,
563 		.array_type	= NO_ARRAY,
564 		.tlv_type	= QMI_COMMON_TLV_TYPE,
565 	},
566 };
567 
568 static struct qmi_elem_info qmi_wlanfw_mem_cfg_s_v01_ei[] = {
569 	{
570 		.data_type	= QMI_UNSIGNED_8_BYTE,
571 		.elem_len	= 1,
572 		.elem_size	= sizeof(u64),
573 		.array_type	= NO_ARRAY,
574 		.tlv_type	= 0,
575 		.offset		= offsetof(struct qmi_wlanfw_mem_cfg_s_v01, offset),
576 	},
577 	{
578 		.data_type	= QMI_UNSIGNED_4_BYTE,
579 		.elem_len	= 1,
580 		.elem_size	= sizeof(u32),
581 		.array_type	= NO_ARRAY,
582 		.tlv_type	= 0,
583 		.offset		= offsetof(struct qmi_wlanfw_mem_cfg_s_v01, size),
584 	},
585 	{
586 		.data_type	= QMI_UNSIGNED_1_BYTE,
587 		.elem_len	= 1,
588 		.elem_size	= sizeof(u8),
589 		.array_type	= NO_ARRAY,
590 		.tlv_type	= 0,
591 		.offset		= offsetof(struct qmi_wlanfw_mem_cfg_s_v01, secure_flag),
592 	},
593 	{
594 		.data_type	= QMI_EOTI,
595 		.array_type	= NO_ARRAY,
596 		.tlv_type	= QMI_COMMON_TLV_TYPE,
597 	},
598 };
599 
600 static struct qmi_elem_info qmi_wlanfw_mem_seg_s_v01_ei[] = {
601 	{
602 		.data_type	= QMI_UNSIGNED_4_BYTE,
603 		.elem_len	= 1,
604 		.elem_size	= sizeof(u32),
605 		.array_type	= NO_ARRAY,
606 		.tlv_type	= 0,
607 		.offset		= offsetof(struct qmi_wlanfw_mem_seg_s_v01,
608 				  size),
609 	},
610 	{
611 		.data_type	= QMI_SIGNED_4_BYTE_ENUM,
612 		.elem_len	= 1,
613 		.elem_size	= sizeof(enum qmi_wlanfw_mem_type_enum_v01),
614 		.array_type	= NO_ARRAY,
615 		.tlv_type	= 0,
616 		.offset		= offsetof(struct qmi_wlanfw_mem_seg_s_v01, type),
617 	},
618 	{
619 		.data_type	= QMI_DATA_LEN,
620 		.elem_len	= 1,
621 		.elem_size	= sizeof(u8),
622 		.array_type	= NO_ARRAY,
623 		.tlv_type	= 0,
624 		.offset		= offsetof(struct qmi_wlanfw_mem_seg_s_v01, mem_cfg_len),
625 	},
626 	{
627 		.data_type	= QMI_STRUCT,
628 		.elem_len	= QMI_WLANFW_MAX_NUM_MEM_CFG_V01,
629 		.elem_size	= sizeof(struct qmi_wlanfw_mem_cfg_s_v01),
630 		.array_type	= VAR_LEN_ARRAY,
631 		.tlv_type	= 0,
632 		.offset		= offsetof(struct qmi_wlanfw_mem_seg_s_v01, mem_cfg),
633 		.ei_array	= qmi_wlanfw_mem_cfg_s_v01_ei,
634 	},
635 	{
636 		.data_type	= QMI_EOTI,
637 		.array_type	= NO_ARRAY,
638 		.tlv_type	= QMI_COMMON_TLV_TYPE,
639 	},
640 };
641 
642 static struct qmi_elem_info qmi_wlanfw_request_mem_ind_msg_v01_ei[] = {
643 	{
644 		.data_type	= QMI_DATA_LEN,
645 		.elem_len	= 1,
646 		.elem_size	= sizeof(u8),
647 		.array_type	= NO_ARRAY,
648 		.tlv_type	= 0x01,
649 		.offset		= offsetof(struct qmi_wlanfw_request_mem_ind_msg_v01,
650 					   mem_seg_len),
651 	},
652 	{
653 		.data_type	= QMI_STRUCT,
654 		.elem_len	= ATH11K_QMI_WLANFW_MAX_NUM_MEM_SEG_V01,
655 		.elem_size	= sizeof(struct qmi_wlanfw_mem_seg_s_v01),
656 		.array_type	= VAR_LEN_ARRAY,
657 		.tlv_type	= 0x01,
658 		.offset		= offsetof(struct qmi_wlanfw_request_mem_ind_msg_v01,
659 					   mem_seg),
660 		.ei_array	= qmi_wlanfw_mem_seg_s_v01_ei,
661 	},
662 	{
663 		.data_type	= QMI_EOTI,
664 		.array_type	= NO_ARRAY,
665 		.tlv_type	= QMI_COMMON_TLV_TYPE,
666 	},
667 };
668 
669 static struct qmi_elem_info qmi_wlanfw_mem_seg_resp_s_v01_ei[] = {
670 	{
671 		.data_type	= QMI_UNSIGNED_8_BYTE,
672 		.elem_len	= 1,
673 		.elem_size	= sizeof(u64),
674 		.array_type	= NO_ARRAY,
675 		.tlv_type	= 0,
676 		.offset		= offsetof(struct qmi_wlanfw_mem_seg_resp_s_v01, addr),
677 	},
678 	{
679 		.data_type	= QMI_UNSIGNED_4_BYTE,
680 		.elem_len	= 1,
681 		.elem_size	= sizeof(u32),
682 		.array_type	= NO_ARRAY,
683 		.tlv_type	= 0,
684 		.offset		= offsetof(struct qmi_wlanfw_mem_seg_resp_s_v01, size),
685 	},
686 	{
687 		.data_type	= QMI_SIGNED_4_BYTE_ENUM,
688 		.elem_len	= 1,
689 		.elem_size	= sizeof(enum qmi_wlanfw_mem_type_enum_v01),
690 		.array_type	= NO_ARRAY,
691 		.tlv_type	= 0,
692 		.offset		= offsetof(struct qmi_wlanfw_mem_seg_resp_s_v01, type),
693 	},
694 	{
695 		.data_type	= QMI_UNSIGNED_1_BYTE,
696 		.elem_len	= 1,
697 		.elem_size	= sizeof(u8),
698 		.array_type	= NO_ARRAY,
699 		.tlv_type	= 0,
700 		.offset		= offsetof(struct qmi_wlanfw_mem_seg_resp_s_v01, restore),
701 	},
702 	{
703 		.data_type	= QMI_EOTI,
704 		.array_type	= NO_ARRAY,
705 		.tlv_type	= QMI_COMMON_TLV_TYPE,
706 	},
707 };
708 
709 static struct qmi_elem_info qmi_wlanfw_respond_mem_req_msg_v01_ei[] = {
710 	{
711 		.data_type	= QMI_DATA_LEN,
712 		.elem_len	= 1,
713 		.elem_size	= sizeof(u8),
714 		.array_type	= NO_ARRAY,
715 		.tlv_type	= 0x01,
716 		.offset		= offsetof(struct qmi_wlanfw_respond_mem_req_msg_v01,
717 					   mem_seg_len),
718 	},
719 	{
720 		.data_type	= QMI_STRUCT,
721 		.elem_len	= ATH11K_QMI_WLANFW_MAX_NUM_MEM_SEG_V01,
722 		.elem_size	= sizeof(struct qmi_wlanfw_mem_seg_resp_s_v01),
723 		.array_type	= VAR_LEN_ARRAY,
724 		.tlv_type	= 0x01,
725 		.offset		= offsetof(struct qmi_wlanfw_respond_mem_req_msg_v01,
726 					   mem_seg),
727 		.ei_array	= qmi_wlanfw_mem_seg_resp_s_v01_ei,
728 	},
729 	{
730 		.data_type	= QMI_EOTI,
731 		.array_type	= NO_ARRAY,
732 		.tlv_type	= QMI_COMMON_TLV_TYPE,
733 	},
734 };
735 
736 static struct qmi_elem_info qmi_wlanfw_respond_mem_resp_msg_v01_ei[] = {
737 	{
738 		.data_type	= QMI_STRUCT,
739 		.elem_len	= 1,
740 		.elem_size	= sizeof(struct qmi_response_type_v01),
741 		.array_type	= NO_ARRAY,
742 		.tlv_type	= 0x02,
743 		.offset		= offsetof(struct qmi_wlanfw_respond_mem_resp_msg_v01,
744 					   resp),
745 		.ei_array	= qmi_response_type_v01_ei,
746 	},
747 	{
748 		.data_type	= QMI_EOTI,
749 		.array_type	= NO_ARRAY,
750 		.tlv_type	= QMI_COMMON_TLV_TYPE,
751 	},
752 };
753 
754 static struct qmi_elem_info qmi_wlanfw_cap_req_msg_v01_ei[] = {
755 	{
756 		.data_type	= QMI_EOTI,
757 		.array_type	= NO_ARRAY,
758 		.tlv_type	= QMI_COMMON_TLV_TYPE,
759 	},
760 };
761 
762 static struct qmi_elem_info qmi_wlanfw_rf_chip_info_s_v01_ei[] = {
763 	{
764 		.data_type	= QMI_UNSIGNED_4_BYTE,
765 		.elem_len	= 1,
766 		.elem_size	= sizeof(u32),
767 		.array_type	= NO_ARRAY,
768 		.tlv_type	= 0,
769 		.offset		= offsetof(struct qmi_wlanfw_rf_chip_info_s_v01,
770 					   chip_id),
771 	},
772 	{
773 		.data_type	= QMI_UNSIGNED_4_BYTE,
774 		.elem_len	= 1,
775 		.elem_size	= sizeof(u32),
776 		.array_type	= NO_ARRAY,
777 		.tlv_type	= 0,
778 		.offset		= offsetof(struct qmi_wlanfw_rf_chip_info_s_v01,
779 					   chip_family),
780 	},
781 	{
782 		.data_type	= QMI_EOTI,
783 		.array_type	= NO_ARRAY,
784 		.tlv_type	= QMI_COMMON_TLV_TYPE,
785 	},
786 };
787 
788 static struct qmi_elem_info qmi_wlanfw_rf_board_info_s_v01_ei[] = {
789 	{
790 		.data_type	= QMI_UNSIGNED_4_BYTE,
791 		.elem_len	= 1,
792 		.elem_size	= sizeof(u32),
793 		.array_type	= NO_ARRAY,
794 		.tlv_type	= 0,
795 		.offset		= offsetof(struct qmi_wlanfw_rf_board_info_s_v01,
796 					   board_id),
797 	},
798 	{
799 		.data_type	= QMI_EOTI,
800 		.array_type	= NO_ARRAY,
801 		.tlv_type	= QMI_COMMON_TLV_TYPE,
802 	},
803 };
804 
805 static struct qmi_elem_info qmi_wlanfw_soc_info_s_v01_ei[] = {
806 	{
807 		.data_type	= QMI_UNSIGNED_4_BYTE,
808 		.elem_len	= 1,
809 		.elem_size	= sizeof(u32),
810 		.array_type	= NO_ARRAY,
811 		.tlv_type	= 0,
812 		.offset		= offsetof(struct qmi_wlanfw_soc_info_s_v01, soc_id),
813 	},
814 	{
815 		.data_type	= QMI_EOTI,
816 		.array_type	= NO_ARRAY,
817 		.tlv_type	= QMI_COMMON_TLV_TYPE,
818 	},
819 };
820 
821 static struct qmi_elem_info qmi_wlanfw_fw_version_info_s_v01_ei[] = {
822 	{
823 		.data_type	= QMI_UNSIGNED_4_BYTE,
824 		.elem_len	= 1,
825 		.elem_size	= sizeof(u32),
826 		.array_type	= NO_ARRAY,
827 		.tlv_type	= 0,
828 		.offset		= offsetof(struct qmi_wlanfw_fw_version_info_s_v01,
829 					   fw_version),
830 	},
831 	{
832 		.data_type	= QMI_STRING,
833 		.elem_len	= ATH11K_QMI_WLANFW_MAX_TIMESTAMP_LEN_V01 + 1,
834 		.elem_size	= sizeof(char),
835 		.array_type	= NO_ARRAY,
836 		.tlv_type	= 0,
837 		.offset		= offsetof(struct qmi_wlanfw_fw_version_info_s_v01,
838 					   fw_build_timestamp),
839 	},
840 	{
841 		.data_type	= QMI_EOTI,
842 		.array_type	= NO_ARRAY,
843 		.tlv_type	= QMI_COMMON_TLV_TYPE,
844 	},
845 };
846 
847 static struct qmi_elem_info qmi_wlanfw_cap_resp_msg_v01_ei[] = {
848 	{
849 		.data_type	= QMI_STRUCT,
850 		.elem_len	= 1,
851 		.elem_size	= sizeof(struct qmi_response_type_v01),
852 		.array_type	= NO_ARRAY,
853 		.tlv_type	= 0x02,
854 		.offset		= offsetof(struct qmi_wlanfw_cap_resp_msg_v01, resp),
855 		.ei_array	= qmi_response_type_v01_ei,
856 	},
857 	{
858 		.data_type	= QMI_OPT_FLAG,
859 		.elem_len	= 1,
860 		.elem_size	= sizeof(u8),
861 		.array_type	= NO_ARRAY,
862 		.tlv_type	= 0x10,
863 		.offset		= offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
864 					   chip_info_valid),
865 	},
866 	{
867 		.data_type	= QMI_STRUCT,
868 		.elem_len	= 1,
869 		.elem_size	= sizeof(struct qmi_wlanfw_rf_chip_info_s_v01),
870 		.array_type	= NO_ARRAY,
871 		.tlv_type	= 0x10,
872 		.offset		= offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
873 					   chip_info),
874 		.ei_array	= qmi_wlanfw_rf_chip_info_s_v01_ei,
875 	},
876 	{
877 		.data_type	= QMI_OPT_FLAG,
878 		.elem_len	= 1,
879 		.elem_size	= sizeof(u8),
880 		.array_type	= NO_ARRAY,
881 		.tlv_type	= 0x11,
882 		.offset		= offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
883 					   board_info_valid),
884 	},
885 	{
886 		.data_type	= QMI_STRUCT,
887 		.elem_len	= 1,
888 		.elem_size	= sizeof(struct qmi_wlanfw_rf_board_info_s_v01),
889 		.array_type	= NO_ARRAY,
890 		.tlv_type	= 0x11,
891 		.offset		= offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
892 					   board_info),
893 		.ei_array	= qmi_wlanfw_rf_board_info_s_v01_ei,
894 	},
895 	{
896 		.data_type	= QMI_OPT_FLAG,
897 		.elem_len	= 1,
898 		.elem_size	= sizeof(u8),
899 		.array_type	= NO_ARRAY,
900 		.tlv_type	= 0x12,
901 		.offset		= offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
902 					   soc_info_valid),
903 	},
904 	{
905 		.data_type	= QMI_STRUCT,
906 		.elem_len	= 1,
907 		.elem_size	= sizeof(struct qmi_wlanfw_soc_info_s_v01),
908 		.array_type	= NO_ARRAY,
909 		.tlv_type	= 0x12,
910 		.offset		= offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
911 					   soc_info),
912 		.ei_array	= qmi_wlanfw_soc_info_s_v01_ei,
913 	},
914 	{
915 		.data_type	= QMI_OPT_FLAG,
916 		.elem_len	= 1,
917 		.elem_size	= sizeof(u8),
918 		.array_type	= NO_ARRAY,
919 		.tlv_type	= 0x13,
920 		.offset		= offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
921 					   fw_version_info_valid),
922 	},
923 	{
924 		.data_type	= QMI_STRUCT,
925 		.elem_len	= 1,
926 		.elem_size	= sizeof(struct qmi_wlanfw_fw_version_info_s_v01),
927 		.array_type	= NO_ARRAY,
928 		.tlv_type	= 0x13,
929 		.offset		= offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
930 					   fw_version_info),
931 		.ei_array	= qmi_wlanfw_fw_version_info_s_v01_ei,
932 	},
933 	{
934 		.data_type	= QMI_OPT_FLAG,
935 		.elem_len	= 1,
936 		.elem_size	= sizeof(u8),
937 		.array_type	= NO_ARRAY,
938 		.tlv_type	= 0x14,
939 		.offset		= offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
940 					   fw_build_id_valid),
941 	},
942 	{
943 		.data_type	= QMI_STRING,
944 		.elem_len	= ATH11K_QMI_WLANFW_MAX_BUILD_ID_LEN_V01 + 1,
945 		.elem_size	= sizeof(char),
946 		.array_type	= NO_ARRAY,
947 		.tlv_type	= 0x14,
948 		.offset		= offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
949 					   fw_build_id),
950 	},
951 	{
952 		.data_type	= QMI_OPT_FLAG,
953 		.elem_len	= 1,
954 		.elem_size	= sizeof(u8),
955 		.array_type	= NO_ARRAY,
956 		.tlv_type	= 0x15,
957 		.offset		= offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
958 					   num_macs_valid),
959 	},
960 	{
961 		.data_type	= QMI_UNSIGNED_1_BYTE,
962 		.elem_len	= 1,
963 		.elem_size	= sizeof(u8),
964 		.array_type	= NO_ARRAY,
965 		.tlv_type	= 0x15,
966 		.offset		= offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
967 					   num_macs),
968 	},
969 	{
970 		.data_type      = QMI_OPT_FLAG,
971 		.elem_len       = 1,
972 		.elem_size      = sizeof(u8),
973 		.array_type     = NO_ARRAY,
974 		.tlv_type       = 0x16,
975 		.offset         = offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
976 					   voltage_mv_valid),
977 	},
978 	{
979 		.data_type      = QMI_UNSIGNED_4_BYTE,
980 		.elem_len       = 1,
981 		.elem_size      = sizeof(u32),
982 		.array_type     = NO_ARRAY,
983 		.tlv_type       = 0x16,
984 		.offset         = offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
985 					   voltage_mv),
986 	},
987 	{
988 		.data_type      = QMI_OPT_FLAG,
989 		.elem_len       = 1,
990 		.elem_size      = sizeof(u8),
991 		.array_type     = NO_ARRAY,
992 		.tlv_type       = 0x17,
993 		.offset         = offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
994 					   time_freq_hz_valid),
995 	},
996 	{
997 		.data_type      = QMI_UNSIGNED_4_BYTE,
998 		.elem_len       = 1,
999 		.elem_size      = sizeof(u32),
1000 		.array_type     = NO_ARRAY,
1001 		.tlv_type       = 0x17,
1002 		.offset         = offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
1003 					   time_freq_hz),
1004 	},
1005 	{
1006 		.data_type      = QMI_OPT_FLAG,
1007 		.elem_len       = 1,
1008 		.elem_size      = sizeof(u8),
1009 		.array_type     = NO_ARRAY,
1010 		.tlv_type       = 0x18,
1011 		.offset         = offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
1012 					   otp_version_valid),
1013 	},
1014 	{
1015 		.data_type      = QMI_UNSIGNED_4_BYTE,
1016 		.elem_len       = 1,
1017 		.elem_size      = sizeof(u32),
1018 		.array_type     = NO_ARRAY,
1019 		.tlv_type       = 0x18,
1020 		.offset         = offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
1021 					   otp_version),
1022 	},
1023 	{
1024 		.data_type      = QMI_OPT_FLAG,
1025 		.elem_len       = 1,
1026 		.elem_size      = sizeof(u8),
1027 		.array_type     = NO_ARRAY,
1028 		.tlv_type       = 0x19,
1029 		.offset         = offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
1030 					   eeprom_read_timeout_valid),
1031 	},
1032 	{
1033 		.data_type      = QMI_UNSIGNED_4_BYTE,
1034 		.elem_len       = 1,
1035 		.elem_size      = sizeof(u32),
1036 		.array_type     = NO_ARRAY,
1037 		.tlv_type       = 0x19,
1038 		.offset         = offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
1039 					   eeprom_read_timeout),
1040 	},
1041 	{
1042 		.data_type	= QMI_EOTI,
1043 		.array_type	= NO_ARRAY,
1044 		.tlv_type	= QMI_COMMON_TLV_TYPE,
1045 	},
1046 };
1047 
1048 static struct qmi_elem_info qmi_wlanfw_bdf_download_req_msg_v01_ei[] = {
1049 	{
1050 		.data_type	= QMI_UNSIGNED_1_BYTE,
1051 		.elem_len	= 1,
1052 		.elem_size	= sizeof(u8),
1053 		.array_type	= NO_ARRAY,
1054 		.tlv_type	= 0x01,
1055 		.offset		= offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01,
1056 					   valid),
1057 	},
1058 	{
1059 		.data_type	= QMI_OPT_FLAG,
1060 		.elem_len	= 1,
1061 		.elem_size	= sizeof(u8),
1062 		.array_type	= NO_ARRAY,
1063 		.tlv_type	= 0x10,
1064 		.offset		= offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01,
1065 					   file_id_valid),
1066 	},
1067 	{
1068 		.data_type	= QMI_SIGNED_4_BYTE_ENUM,
1069 		.elem_len	= 1,
1070 		.elem_size	= sizeof(enum qmi_wlanfw_cal_temp_id_enum_v01),
1071 		.array_type	= NO_ARRAY,
1072 		.tlv_type	= 0x10,
1073 		.offset		= offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01,
1074 					   file_id),
1075 	},
1076 	{
1077 		.data_type	= QMI_OPT_FLAG,
1078 		.elem_len	= 1,
1079 		.elem_size	= sizeof(u8),
1080 		.array_type	= NO_ARRAY,
1081 		.tlv_type	= 0x11,
1082 		.offset		= offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01,
1083 					   total_size_valid),
1084 	},
1085 	{
1086 		.data_type	= QMI_UNSIGNED_4_BYTE,
1087 		.elem_len	= 1,
1088 		.elem_size	= sizeof(u32),
1089 		.array_type	= NO_ARRAY,
1090 		.tlv_type	= 0x11,
1091 		.offset		= offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01,
1092 					   total_size),
1093 	},
1094 	{
1095 		.data_type	= QMI_OPT_FLAG,
1096 		.elem_len	= 1,
1097 		.elem_size	= sizeof(u8),
1098 		.array_type	= NO_ARRAY,
1099 		.tlv_type	= 0x12,
1100 		.offset		= offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01,
1101 					   seg_id_valid),
1102 	},
1103 	{
1104 		.data_type	= QMI_UNSIGNED_4_BYTE,
1105 		.elem_len	= 1,
1106 		.elem_size	= sizeof(u32),
1107 		.array_type	= NO_ARRAY,
1108 		.tlv_type	= 0x12,
1109 		.offset		= offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01,
1110 					   seg_id),
1111 	},
1112 	{
1113 		.data_type	= QMI_OPT_FLAG,
1114 		.elem_len	= 1,
1115 		.elem_size	= sizeof(u8),
1116 		.array_type	= NO_ARRAY,
1117 		.tlv_type	= 0x13,
1118 		.offset		= offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01,
1119 					   data_valid),
1120 	},
1121 	{
1122 		.data_type	= QMI_DATA_LEN,
1123 		.elem_len	= 1,
1124 		.elem_size	= sizeof(u16),
1125 		.array_type	= NO_ARRAY,
1126 		.tlv_type	= 0x13,
1127 		.offset		= offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01,
1128 					   data_len),
1129 	},
1130 	{
1131 		.data_type	= QMI_UNSIGNED_1_BYTE,
1132 		.elem_len	= QMI_WLANFW_MAX_DATA_SIZE_V01,
1133 		.elem_size	= sizeof(u8),
1134 		.array_type	= VAR_LEN_ARRAY,
1135 		.tlv_type	= 0x13,
1136 		.offset		= offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01,
1137 					   data),
1138 	},
1139 	{
1140 		.data_type	= QMI_OPT_FLAG,
1141 		.elem_len	= 1,
1142 		.elem_size	= sizeof(u8),
1143 		.array_type	= NO_ARRAY,
1144 		.tlv_type	= 0x14,
1145 		.offset		= offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01,
1146 					   end_valid),
1147 	},
1148 	{
1149 		.data_type	= QMI_UNSIGNED_1_BYTE,
1150 		.elem_len	= 1,
1151 		.elem_size	= sizeof(u8),
1152 		.array_type	= NO_ARRAY,
1153 		.tlv_type	= 0x14,
1154 		.offset		= offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01,
1155 					   end),
1156 	},
1157 	{
1158 		.data_type	= QMI_OPT_FLAG,
1159 		.elem_len	= 1,
1160 		.elem_size	= sizeof(u8),
1161 		.array_type	= NO_ARRAY,
1162 		.tlv_type	= 0x15,
1163 		.offset		= offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01,
1164 					   bdf_type_valid),
1165 	},
1166 	{
1167 		.data_type	= QMI_UNSIGNED_1_BYTE,
1168 		.elem_len	= 1,
1169 		.elem_size	= sizeof(u8),
1170 		.array_type	= NO_ARRAY,
1171 		.tlv_type	= 0x15,
1172 		.offset		= offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01,
1173 					   bdf_type),
1174 	},
1175 
1176 	{
1177 		.data_type	= QMI_EOTI,
1178 		.array_type	= NO_ARRAY,
1179 		.tlv_type	= QMI_COMMON_TLV_TYPE,
1180 	},
1181 };
1182 
1183 static struct qmi_elem_info qmi_wlanfw_bdf_download_resp_msg_v01_ei[] = {
1184 	{
1185 		.data_type	= QMI_STRUCT,
1186 		.elem_len	= 1,
1187 		.elem_size	= sizeof(struct qmi_response_type_v01),
1188 		.array_type	= NO_ARRAY,
1189 		.tlv_type	= 0x02,
1190 		.offset		= offsetof(struct qmi_wlanfw_bdf_download_resp_msg_v01,
1191 					   resp),
1192 		.ei_array	= qmi_response_type_v01_ei,
1193 	},
1194 	{
1195 		.data_type	= QMI_EOTI,
1196 		.array_type	= NO_ARRAY,
1197 		.tlv_type	= QMI_COMMON_TLV_TYPE,
1198 	},
1199 };
1200 
1201 static struct qmi_elem_info qmi_wlanfw_m3_info_req_msg_v01_ei[] = {
1202 	{
1203 		.data_type	= QMI_UNSIGNED_8_BYTE,
1204 		.elem_len	= 1,
1205 		.elem_size	= sizeof(u64),
1206 		.array_type	= NO_ARRAY,
1207 		.tlv_type	= 0x01,
1208 		.offset		= offsetof(struct qmi_wlanfw_m3_info_req_msg_v01, addr),
1209 	},
1210 	{
1211 		.data_type	= QMI_UNSIGNED_4_BYTE,
1212 		.elem_len	= 1,
1213 		.elem_size	= sizeof(u32),
1214 		.array_type	= NO_ARRAY,
1215 		.tlv_type	= 0x02,
1216 		.offset		= offsetof(struct qmi_wlanfw_m3_info_req_msg_v01, size),
1217 	},
1218 	{
1219 		.data_type	= QMI_EOTI,
1220 		.array_type	= NO_ARRAY,
1221 		.tlv_type	= QMI_COMMON_TLV_TYPE,
1222 	},
1223 };
1224 
1225 static struct qmi_elem_info qmi_wlanfw_m3_info_resp_msg_v01_ei[] = {
1226 	{
1227 		.data_type	= QMI_STRUCT,
1228 		.elem_len	= 1,
1229 		.elem_size	= sizeof(struct qmi_response_type_v01),
1230 		.array_type	= NO_ARRAY,
1231 		.tlv_type	= 0x02,
1232 		.offset		= offsetof(struct qmi_wlanfw_m3_info_resp_msg_v01, resp),
1233 		.ei_array	= qmi_response_type_v01_ei,
1234 	},
1235 	{
1236 		.data_type	= QMI_EOTI,
1237 		.array_type	= NO_ARRAY,
1238 		.tlv_type	= QMI_COMMON_TLV_TYPE,
1239 	},
1240 };
1241 
1242 static struct qmi_elem_info qmi_wlanfw_ce_tgt_pipe_cfg_s_v01_ei[] = {
1243 	{
1244 		.data_type	= QMI_UNSIGNED_4_BYTE,
1245 		.elem_len	= 1,
1246 		.elem_size	= sizeof(u32),
1247 		.array_type	= NO_ARRAY,
1248 		.tlv_type	= 0,
1249 		.offset		= offsetof(struct qmi_wlanfw_ce_tgt_pipe_cfg_s_v01,
1250 					   pipe_num),
1251 	},
1252 	{
1253 		.data_type	= QMI_SIGNED_4_BYTE_ENUM,
1254 		.elem_len	= 1,
1255 		.elem_size	= sizeof(enum qmi_wlanfw_pipedir_enum_v01),
1256 		.array_type	= NO_ARRAY,
1257 		.tlv_type	= 0,
1258 		.offset		= offsetof(struct qmi_wlanfw_ce_tgt_pipe_cfg_s_v01,
1259 					   pipe_dir),
1260 	},
1261 	{
1262 		.data_type	= QMI_UNSIGNED_4_BYTE,
1263 		.elem_len	= 1,
1264 		.elem_size	= sizeof(u32),
1265 		.array_type	= NO_ARRAY,
1266 		.tlv_type	= 0,
1267 		.offset		= offsetof(struct qmi_wlanfw_ce_tgt_pipe_cfg_s_v01,
1268 					   nentries),
1269 	},
1270 	{
1271 		.data_type	= QMI_UNSIGNED_4_BYTE,
1272 		.elem_len	= 1,
1273 		.elem_size	= sizeof(u32),
1274 		.array_type	= NO_ARRAY,
1275 		.tlv_type	= 0,
1276 		.offset		= offsetof(struct qmi_wlanfw_ce_tgt_pipe_cfg_s_v01,
1277 					   nbytes_max),
1278 	},
1279 	{
1280 		.data_type	= QMI_UNSIGNED_4_BYTE,
1281 		.elem_len	= 1,
1282 		.elem_size	= sizeof(u32),
1283 		.array_type	= NO_ARRAY,
1284 		.tlv_type	= 0,
1285 		.offset		= offsetof(struct qmi_wlanfw_ce_tgt_pipe_cfg_s_v01,
1286 					   flags),
1287 	},
1288 	{
1289 		.data_type	= QMI_EOTI,
1290 		.array_type	= NO_ARRAY,
1291 		.tlv_type	= QMI_COMMON_TLV_TYPE,
1292 	},
1293 };
1294 
1295 static struct qmi_elem_info qmi_wlanfw_ce_svc_pipe_cfg_s_v01_ei[] = {
1296 	{
1297 		.data_type	= QMI_UNSIGNED_4_BYTE,
1298 		.elem_len	= 1,
1299 		.elem_size	= sizeof(u32),
1300 		.array_type	= NO_ARRAY,
1301 		.tlv_type	= 0,
1302 		.offset		= offsetof(struct qmi_wlanfw_ce_svc_pipe_cfg_s_v01,
1303 					   service_id),
1304 	},
1305 	{
1306 		.data_type	= QMI_SIGNED_4_BYTE_ENUM,
1307 		.elem_len	= 1,
1308 		.elem_size	= sizeof(enum qmi_wlanfw_pipedir_enum_v01),
1309 		.array_type	= NO_ARRAY,
1310 		.tlv_type	= 0,
1311 		.offset		= offsetof(struct qmi_wlanfw_ce_svc_pipe_cfg_s_v01,
1312 					   pipe_dir),
1313 	},
1314 	{
1315 		.data_type	= QMI_UNSIGNED_4_BYTE,
1316 		.elem_len	= 1,
1317 		.elem_size	= sizeof(u32),
1318 		.array_type	= NO_ARRAY,
1319 		.tlv_type	= 0,
1320 		.offset		= offsetof(struct qmi_wlanfw_ce_svc_pipe_cfg_s_v01,
1321 					   pipe_num),
1322 	},
1323 	{
1324 		.data_type	= QMI_EOTI,
1325 		.array_type	= NO_ARRAY,
1326 		.tlv_type	= QMI_COMMON_TLV_TYPE,
1327 	},
1328 };
1329 
1330 static struct qmi_elem_info qmi_wlanfw_shadow_reg_cfg_s_v01_ei[] = {
1331 	{
1332 		.data_type	= QMI_UNSIGNED_2_BYTE,
1333 		.elem_len	= 1,
1334 		.elem_size	= sizeof(u16),
1335 		.array_type	= NO_ARRAY,
1336 		.tlv_type	= 0,
1337 		.offset		= offsetof(struct qmi_wlanfw_shadow_reg_cfg_s_v01, id),
1338 	},
1339 	{
1340 		.data_type	= QMI_UNSIGNED_2_BYTE,
1341 		.elem_len	= 1,
1342 		.elem_size	= sizeof(u16),
1343 		.array_type	= NO_ARRAY,
1344 		.tlv_type	= 0,
1345 		.offset		= offsetof(struct qmi_wlanfw_shadow_reg_cfg_s_v01,
1346 					   offset),
1347 	},
1348 	{
1349 		.data_type	= QMI_EOTI,
1350 		.array_type	= QMI_COMMON_TLV_TYPE,
1351 	},
1352 };
1353 
1354 static struct qmi_elem_info qmi_wlanfw_shadow_reg_v2_cfg_s_v01_ei[] = {
1355 	{
1356 		.data_type	= QMI_UNSIGNED_4_BYTE,
1357 		.elem_len	= 1,
1358 		.elem_size	= sizeof(u32),
1359 		.array_type	= NO_ARRAY,
1360 		.tlv_type	= 0,
1361 		.offset		= offsetof(struct qmi_wlanfw_shadow_reg_v2_cfg_s_v01,
1362 					   addr),
1363 	},
1364 	{
1365 		.data_type	= QMI_EOTI,
1366 		.array_type	= NO_ARRAY,
1367 		.tlv_type	= QMI_COMMON_TLV_TYPE,
1368 	},
1369 };
1370 
1371 static struct qmi_elem_info qmi_wlanfw_wlan_mode_req_msg_v01_ei[] = {
1372 	{
1373 		.data_type	= QMI_UNSIGNED_4_BYTE,
1374 		.elem_len	= 1,
1375 		.elem_size	= sizeof(u32),
1376 		.array_type	= NO_ARRAY,
1377 		.tlv_type	= 0x01,
1378 		.offset		= offsetof(struct qmi_wlanfw_wlan_mode_req_msg_v01,
1379 					   mode),
1380 	},
1381 	{
1382 		.data_type	= QMI_OPT_FLAG,
1383 		.elem_len	= 1,
1384 		.elem_size	= sizeof(u8),
1385 		.array_type	= NO_ARRAY,
1386 		.tlv_type	= 0x10,
1387 		.offset		= offsetof(struct qmi_wlanfw_wlan_mode_req_msg_v01,
1388 					   hw_debug_valid),
1389 	},
1390 	{
1391 		.data_type	= QMI_UNSIGNED_1_BYTE,
1392 		.elem_len	= 1,
1393 		.elem_size	= sizeof(u8),
1394 		.array_type	= NO_ARRAY,
1395 		.tlv_type	= 0x10,
1396 		.offset		= offsetof(struct qmi_wlanfw_wlan_mode_req_msg_v01,
1397 					   hw_debug),
1398 	},
1399 	{
1400 		.data_type	= QMI_EOTI,
1401 		.array_type	= NO_ARRAY,
1402 		.tlv_type	= QMI_COMMON_TLV_TYPE,
1403 	},
1404 };
1405 
1406 static struct qmi_elem_info qmi_wlanfw_wlan_mode_resp_msg_v01_ei[] = {
1407 	{
1408 		.data_type	= QMI_STRUCT,
1409 		.elem_len	= 1,
1410 		.elem_size	= sizeof(struct qmi_response_type_v01),
1411 		.array_type	= NO_ARRAY,
1412 		.tlv_type	= 0x02,
1413 		.offset		= offsetof(struct qmi_wlanfw_wlan_mode_resp_msg_v01,
1414 					   resp),
1415 		.ei_array	= qmi_response_type_v01_ei,
1416 	},
1417 	{
1418 		.data_type	= QMI_EOTI,
1419 		.array_type	= NO_ARRAY,
1420 		.tlv_type	= QMI_COMMON_TLV_TYPE,
1421 	},
1422 };
1423 
1424 static struct qmi_elem_info qmi_wlanfw_wlan_cfg_req_msg_v01_ei[] = {
1425 	{
1426 		.data_type	= QMI_OPT_FLAG,
1427 		.elem_len	= 1,
1428 		.elem_size	= sizeof(u8),
1429 		.array_type	= NO_ARRAY,
1430 		.tlv_type	= 0x10,
1431 		.offset		= offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01,
1432 					   host_version_valid),
1433 	},
1434 	{
1435 		.data_type	= QMI_STRING,
1436 		.elem_len	= QMI_WLANFW_MAX_STR_LEN_V01 + 1,
1437 		.elem_size	= sizeof(char),
1438 		.array_type	= NO_ARRAY,
1439 		.tlv_type	= 0x10,
1440 		.offset		= offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01,
1441 					   host_version),
1442 	},
1443 	{
1444 		.data_type	= QMI_OPT_FLAG,
1445 		.elem_len	= 1,
1446 		.elem_size	= sizeof(u8),
1447 		.array_type	= NO_ARRAY,
1448 		.tlv_type	= 0x11,
1449 		.offset		= offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01,
1450 					   tgt_cfg_valid),
1451 	},
1452 	{
1453 		.data_type	= QMI_DATA_LEN,
1454 		.elem_len	= 1,
1455 		.elem_size	= sizeof(u8),
1456 		.array_type	= NO_ARRAY,
1457 		.tlv_type	= 0x11,
1458 		.offset		= offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01,
1459 					   tgt_cfg_len),
1460 	},
1461 	{
1462 		.data_type	= QMI_STRUCT,
1463 		.elem_len	= QMI_WLANFW_MAX_NUM_CE_V01,
1464 		.elem_size	= sizeof(
1465 				struct qmi_wlanfw_ce_tgt_pipe_cfg_s_v01),
1466 		.array_type	= VAR_LEN_ARRAY,
1467 		.tlv_type	= 0x11,
1468 		.offset		= offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01,
1469 					   tgt_cfg),
1470 		.ei_array	= qmi_wlanfw_ce_tgt_pipe_cfg_s_v01_ei,
1471 	},
1472 	{
1473 		.data_type	= QMI_OPT_FLAG,
1474 		.elem_len	= 1,
1475 		.elem_size	= sizeof(u8),
1476 		.array_type	= NO_ARRAY,
1477 		.tlv_type	= 0x12,
1478 		.offset		= offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01,
1479 					   svc_cfg_valid),
1480 	},
1481 	{
1482 		.data_type	= QMI_DATA_LEN,
1483 		.elem_len	= 1,
1484 		.elem_size	= sizeof(u8),
1485 		.array_type	= NO_ARRAY,
1486 		.tlv_type	= 0x12,
1487 		.offset		= offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01,
1488 					   svc_cfg_len),
1489 	},
1490 	{
1491 		.data_type	= QMI_STRUCT,
1492 		.elem_len	= QMI_WLANFW_MAX_NUM_SVC_V01,
1493 		.elem_size	= sizeof(struct qmi_wlanfw_ce_svc_pipe_cfg_s_v01),
1494 		.array_type	= VAR_LEN_ARRAY,
1495 		.tlv_type	= 0x12,
1496 		.offset		= offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01,
1497 					   svc_cfg),
1498 		.ei_array	= qmi_wlanfw_ce_svc_pipe_cfg_s_v01_ei,
1499 	},
1500 	{
1501 		.data_type	= QMI_OPT_FLAG,
1502 		.elem_len	= 1,
1503 		.elem_size	= sizeof(u8),
1504 		.array_type	= NO_ARRAY,
1505 		.tlv_type	= 0x13,
1506 		.offset		= offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01,
1507 					   shadow_reg_valid),
1508 	},
1509 	{
1510 		.data_type	= QMI_DATA_LEN,
1511 		.elem_len	= 1,
1512 		.elem_size	= sizeof(u8),
1513 		.array_type	= NO_ARRAY,
1514 		.tlv_type	= 0x13,
1515 		.offset		= offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01,
1516 					   shadow_reg_len),
1517 	},
1518 	{
1519 		.data_type	= QMI_STRUCT,
1520 		.elem_len	= QMI_WLANFW_MAX_NUM_SHADOW_REG_V01,
1521 		.elem_size	= sizeof(struct qmi_wlanfw_shadow_reg_cfg_s_v01),
1522 		.array_type	= VAR_LEN_ARRAY,
1523 		.tlv_type	= 0x13,
1524 		.offset		= offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01,
1525 					   shadow_reg),
1526 		.ei_array	= qmi_wlanfw_shadow_reg_cfg_s_v01_ei,
1527 	},
1528 	{
1529 		.data_type	= QMI_OPT_FLAG,
1530 		.elem_len	= 1,
1531 		.elem_size	= sizeof(u8),
1532 		.array_type	= NO_ARRAY,
1533 		.tlv_type	= 0x14,
1534 		.offset		= offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01,
1535 					   shadow_reg_v2_valid),
1536 	},
1537 	{
1538 		.data_type	= QMI_DATA_LEN,
1539 		.elem_len	= 1,
1540 		.elem_size	= sizeof(u8),
1541 		.array_type	= NO_ARRAY,
1542 		.tlv_type	= 0x14,
1543 		.offset		= offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01,
1544 					   shadow_reg_v2_len),
1545 	},
1546 	{
1547 		.data_type	= QMI_STRUCT,
1548 		.elem_len	= QMI_WLANFW_MAX_NUM_SHADOW_REG_V2_V01,
1549 		.elem_size	= sizeof(struct qmi_wlanfw_shadow_reg_v2_cfg_s_v01),
1550 		.array_type	= VAR_LEN_ARRAY,
1551 		.tlv_type	= 0x14,
1552 		.offset		= offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01,
1553 					   shadow_reg_v2),
1554 		.ei_array	= qmi_wlanfw_shadow_reg_v2_cfg_s_v01_ei,
1555 	},
1556 	{
1557 		.data_type	= QMI_EOTI,
1558 		.array_type	= NO_ARRAY,
1559 		.tlv_type	= QMI_COMMON_TLV_TYPE,
1560 	},
1561 };
1562 
1563 static struct qmi_elem_info qmi_wlanfw_wlan_cfg_resp_msg_v01_ei[] = {
1564 	{
1565 		.data_type	= QMI_STRUCT,
1566 		.elem_len	= 1,
1567 		.elem_size	= sizeof(struct qmi_response_type_v01),
1568 		.array_type	= NO_ARRAY,
1569 		.tlv_type	= 0x02,
1570 		.offset		= offsetof(struct qmi_wlanfw_wlan_cfg_resp_msg_v01, resp),
1571 		.ei_array	= qmi_response_type_v01_ei,
1572 	},
1573 	{
1574 		.data_type	= QMI_EOTI,
1575 		.array_type	= NO_ARRAY,
1576 		.tlv_type	= QMI_COMMON_TLV_TYPE,
1577 	},
1578 };
1579 
1580 static struct qmi_elem_info qmi_wlanfw_mem_ready_ind_msg_v01_ei[] = {
1581 	{
1582 		.data_type = QMI_EOTI,
1583 		.array_type = NO_ARRAY,
1584 	},
1585 };
1586 
1587 static struct qmi_elem_info qmi_wlanfw_fw_ready_ind_msg_v01_ei[] = {
1588 	{
1589 		.data_type = QMI_EOTI,
1590 		.array_type = NO_ARRAY,
1591 	},
1592 };
1593 
1594 static struct qmi_elem_info qmi_wlanfw_cold_boot_cal_done_ind_msg_v01_ei[] = {
1595 	{
1596 		.data_type = QMI_EOTI,
1597 		.array_type = NO_ARRAY,
1598 	},
1599 };
1600 
1601 static struct qmi_elem_info qmi_wlanfw_wlan_ini_req_msg_v01_ei[] = {
1602 	{
1603 		.data_type	= QMI_OPT_FLAG,
1604 		.elem_len	= 1,
1605 		.elem_size	= sizeof(u8),
1606 		.array_type	= NO_ARRAY,
1607 		.tlv_type	= 0x10,
1608 		.offset		= offsetof(struct qmi_wlanfw_wlan_ini_req_msg_v01,
1609 					   enablefwlog_valid),
1610 	},
1611 	{
1612 		.data_type	= QMI_UNSIGNED_1_BYTE,
1613 		.elem_len	= 1,
1614 		.elem_size	= sizeof(u8),
1615 		.array_type	= NO_ARRAY,
1616 		.tlv_type	= 0x10,
1617 		.offset		= offsetof(struct qmi_wlanfw_wlan_ini_req_msg_v01,
1618 					   enablefwlog),
1619 	},
1620 	{
1621 		.data_type	= QMI_EOTI,
1622 		.array_type	= NO_ARRAY,
1623 		.tlv_type	= QMI_COMMON_TLV_TYPE,
1624 	},
1625 };
1626 
1627 static struct qmi_elem_info qmi_wlanfw_wlan_ini_resp_msg_v01_ei[] = {
1628 	{
1629 		.data_type	= QMI_STRUCT,
1630 		.elem_len	= 1,
1631 		.elem_size	= sizeof(struct qmi_response_type_v01),
1632 		.array_type	= NO_ARRAY,
1633 		.tlv_type	= 0x02,
1634 		.offset		= offsetof(struct qmi_wlanfw_wlan_ini_resp_msg_v01,
1635 					   resp),
1636 		.ei_array	= qmi_response_type_v01_ei,
1637 	},
1638 	{
1639 		.data_type	= QMI_EOTI,
1640 		.array_type	= NO_ARRAY,
1641 		.tlv_type	= QMI_COMMON_TLV_TYPE,
1642 	},
1643 };
1644 
1645 static int ath11k_qmi_host_cap_send(struct ath11k_base *ab)
1646 {
1647 	struct qmi_wlanfw_host_cap_req_msg_v01 req;
1648 	struct qmi_wlanfw_host_cap_resp_msg_v01 resp;
1649 	struct qmi_txn txn;
1650 	int ret = 0;
1651 
1652 	memset(&req, 0, sizeof(req));
1653 	memset(&resp, 0, sizeof(resp));
1654 
1655 	req.num_clients_valid = 1;
1656 	req.num_clients = 1;
1657 	req.mem_cfg_mode = ab->qmi.target_mem_mode;
1658 	req.mem_cfg_mode_valid = 1;
1659 	req.bdf_support_valid = 1;
1660 	req.bdf_support = 1;
1661 
1662 	if (ab->bus_params.m3_fw_support) {
1663 		req.m3_support_valid = 1;
1664 		req.m3_support = 1;
1665 		req.m3_cache_support_valid = 1;
1666 		req.m3_cache_support = 1;
1667 	} else {
1668 		req.m3_support_valid = 0;
1669 		req.m3_support = 0;
1670 		req.m3_cache_support_valid = 0;
1671 		req.m3_cache_support = 0;
1672 	}
1673 
1674 	req.cal_done_valid = 1;
1675 	req.cal_done = ab->qmi.cal_done;
1676 
1677 	if (ab->hw_params.internal_sleep_clock) {
1678 		req.nm_modem_valid = 1;
1679 
1680 		/* Notify firmware that this is non-qualcomm platform. */
1681 		req.nm_modem |= HOST_CSTATE_BIT;
1682 
1683 		/* Notify firmware about the sleep clock selection,
1684 		 * nm_modem_bit[1] is used for this purpose. Host driver on
1685 		 * non-qualcomm platforms should select internal sleep
1686 		 * clock.
1687 		 */
1688 		req.nm_modem |= SLEEP_CLOCK_SELECT_INTERNAL_BIT;
1689 	}
1690 
1691 	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi host cap request\n");
1692 
1693 	ret = qmi_txn_init(&ab->qmi.handle, &txn,
1694 			   qmi_wlanfw_host_cap_resp_msg_v01_ei, &resp);
1695 	if (ret < 0)
1696 		goto out;
1697 
1698 	ret = qmi_send_request(&ab->qmi.handle, NULL, &txn,
1699 			       QMI_WLANFW_HOST_CAP_REQ_V01,
1700 			       QMI_WLANFW_HOST_CAP_REQ_MSG_V01_MAX_LEN,
1701 			       qmi_wlanfw_host_cap_req_msg_v01_ei, &req);
1702 	if (ret < 0) {
1703 		qmi_txn_cancel(&txn);
1704 		ath11k_warn(ab, "failed to send host capability request: %d\n", ret);
1705 		goto out;
1706 	}
1707 
1708 	ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH11K_QMI_WLANFW_TIMEOUT_MS));
1709 	if (ret < 0)
1710 		goto out;
1711 
1712 	if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
1713 		ath11k_warn(ab, "host capability request failed: %d %d\n",
1714 			    resp.resp.result, resp.resp.error);
1715 		ret = -EINVAL;
1716 		goto out;
1717 	}
1718 
1719 out:
1720 	return ret;
1721 }
1722 
1723 static int ath11k_qmi_fw_ind_register_send(struct ath11k_base *ab)
1724 {
1725 	struct qmi_wlanfw_ind_register_req_msg_v01 *req;
1726 	struct qmi_wlanfw_ind_register_resp_msg_v01 *resp;
1727 	struct qmi_handle *handle = &ab->qmi.handle;
1728 	struct qmi_txn txn;
1729 	int ret;
1730 
1731 	req = kzalloc(sizeof(*req), GFP_KERNEL);
1732 	if (!req)
1733 		return -ENOMEM;
1734 
1735 	resp = kzalloc(sizeof(*resp), GFP_KERNEL);
1736 	if (!resp) {
1737 		ret = -ENOMEM;
1738 		goto resp_out;
1739 	}
1740 
1741 	req->client_id_valid = 1;
1742 	req->client_id = QMI_WLANFW_CLIENT_ID;
1743 	req->fw_ready_enable_valid = 1;
1744 	req->fw_ready_enable = 1;
1745 	req->request_mem_enable_valid = 1;
1746 	req->request_mem_enable = 1;
1747 	req->fw_mem_ready_enable_valid = 1;
1748 	req->fw_mem_ready_enable = 1;
1749 	req->cal_done_enable_valid = 1;
1750 	req->cal_done_enable = 1;
1751 	req->fw_init_done_enable_valid = 1;
1752 	req->fw_init_done_enable = 1;
1753 
1754 	req->pin_connect_result_enable_valid = 0;
1755 	req->pin_connect_result_enable = 0;
1756 
1757 	ret = qmi_txn_init(handle, &txn,
1758 			   qmi_wlanfw_ind_register_resp_msg_v01_ei, resp);
1759 	if (ret < 0)
1760 		goto out;
1761 
1762 	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi indication register request\n");
1763 
1764 	ret = qmi_send_request(&ab->qmi.handle, NULL, &txn,
1765 			       QMI_WLANFW_IND_REGISTER_REQ_V01,
1766 			       QMI_WLANFW_IND_REGISTER_REQ_MSG_V01_MAX_LEN,
1767 			       qmi_wlanfw_ind_register_req_msg_v01_ei, req);
1768 	if (ret < 0) {
1769 		qmi_txn_cancel(&txn);
1770 		ath11k_warn(ab, "failed to send indication register request: %d\n",
1771 			    ret);
1772 		goto out;
1773 	}
1774 
1775 	ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH11K_QMI_WLANFW_TIMEOUT_MS));
1776 	if (ret < 0) {
1777 		ath11k_warn(ab, "failed to register fw indication: %d\n", ret);
1778 		goto out;
1779 	}
1780 
1781 	if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
1782 		ath11k_warn(ab, "firmware indication register request failed: %d %d\n",
1783 			    resp->resp.result, resp->resp.error);
1784 		ret = -EINVAL;
1785 		goto out;
1786 	}
1787 
1788 out:
1789 	kfree(resp);
1790 resp_out:
1791 	kfree(req);
1792 	return ret;
1793 }
1794 
1795 static int ath11k_qmi_respond_fw_mem_request(struct ath11k_base *ab)
1796 {
1797 	struct qmi_wlanfw_respond_mem_req_msg_v01 *req;
1798 	struct qmi_wlanfw_respond_mem_resp_msg_v01 resp;
1799 	struct qmi_txn txn;
1800 	int ret = 0, i;
1801 	bool delayed;
1802 
1803 	req = kzalloc(sizeof(*req), GFP_KERNEL);
1804 	if (!req)
1805 		return -ENOMEM;
1806 
1807 	memset(&resp, 0, sizeof(resp));
1808 
1809 	/* For QCA6390 by default FW requests a block of ~4M contiguous
1810 	 * DMA memory, it's hard to allocate from OS. So host returns
1811 	 * failure to FW and FW will then request mulitple blocks of small
1812 	 * chunk size memory.
1813 	 */
1814 	if (!(ab->bus_params.fixed_mem_region ||
1815 	      test_bit(ATH11K_FLAG_FIXED_MEM_RGN, &ab->dev_flags)) &&
1816 	      ab->qmi.target_mem_delayed) {
1817 		delayed = true;
1818 		ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi delays mem_request %d\n",
1819 			   ab->qmi.mem_seg_count);
1820 		memset(req, 0, sizeof(*req));
1821 	} else {
1822 		delayed = false;
1823 		req->mem_seg_len = ab->qmi.mem_seg_count;
1824 
1825 		for (i = 0; i < req->mem_seg_len ; i++) {
1826 			req->mem_seg[i].addr = ab->qmi.target_mem[i].paddr;
1827 			req->mem_seg[i].size = ab->qmi.target_mem[i].size;
1828 			req->mem_seg[i].type = ab->qmi.target_mem[i].type;
1829 			ath11k_dbg(ab, ATH11K_DBG_QMI,
1830 				   "qmi req mem_seg[%d] %pad %u %u\n", i,
1831 				    &ab->qmi.target_mem[i].paddr,
1832 				    ab->qmi.target_mem[i].size,
1833 				    ab->qmi.target_mem[i].type);
1834 		}
1835 	}
1836 
1837 	ret = qmi_txn_init(&ab->qmi.handle, &txn,
1838 			   qmi_wlanfw_respond_mem_resp_msg_v01_ei, &resp);
1839 	if (ret < 0)
1840 		goto out;
1841 
1842 	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi respond memory request delayed %i\n",
1843 		   delayed);
1844 
1845 	ret = qmi_send_request(&ab->qmi.handle, NULL, &txn,
1846 			       QMI_WLANFW_RESPOND_MEM_REQ_V01,
1847 			       QMI_WLANFW_RESPOND_MEM_REQ_MSG_V01_MAX_LEN,
1848 			       qmi_wlanfw_respond_mem_req_msg_v01_ei, req);
1849 	if (ret < 0) {
1850 		qmi_txn_cancel(&txn);
1851 		ath11k_warn(ab, "failed to respond qmi memory request: %d\n",
1852 			    ret);
1853 		goto out;
1854 	}
1855 
1856 	ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH11K_QMI_WLANFW_TIMEOUT_MS));
1857 	if (ret < 0) {
1858 		ath11k_warn(ab, "failed to wait qmi memory request: %d\n", ret);
1859 		goto out;
1860 	}
1861 
1862 	if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
1863 		/* the error response is expected when
1864 		 * target_mem_delayed is true.
1865 		 */
1866 		if (delayed && resp.resp.error == 0)
1867 			goto out;
1868 
1869 		ath11k_warn(ab, "qmi respond memory request failed: %d %d\n",
1870 			    resp.resp.result, resp.resp.error);
1871 		ret = -EINVAL;
1872 		goto out;
1873 	}
1874 out:
1875 	kfree(req);
1876 	return ret;
1877 }
1878 
1879 static void ath11k_qmi_free_target_mem_chunk(struct ath11k_base *ab)
1880 {
1881 	int i;
1882 
1883 	for (i = 0; i < ab->qmi.mem_seg_count; i++) {
1884 		if ((ab->bus_params.fixed_mem_region ||
1885 		     test_bit(ATH11K_FLAG_FIXED_MEM_RGN, &ab->dev_flags)) &&
1886 		     ab->qmi.target_mem[i].iaddr)
1887 			iounmap(ab->qmi.target_mem[i].iaddr);
1888 
1889 		if (!ab->qmi.target_mem[i].vaddr)
1890 			continue;
1891 
1892 		dma_free_coherent(ab->dev,
1893 				  ab->qmi.target_mem[i].size,
1894 				  ab->qmi.target_mem[i].vaddr,
1895 				  ab->qmi.target_mem[i].paddr);
1896 		ab->qmi.target_mem[i].vaddr = NULL;
1897 	}
1898 }
1899 
1900 static int ath11k_qmi_alloc_target_mem_chunk(struct ath11k_base *ab)
1901 {
1902 	int i;
1903 	struct target_mem_chunk *chunk;
1904 
1905 	ab->qmi.target_mem_delayed = false;
1906 
1907 	for (i = 0; i < ab->qmi.mem_seg_count; i++) {
1908 		chunk = &ab->qmi.target_mem[i];
1909 		chunk->vaddr = dma_alloc_coherent(ab->dev,
1910 						  chunk->size,
1911 						  &chunk->paddr,
1912 						  GFP_KERNEL | __GFP_NOWARN);
1913 		if (!chunk->vaddr) {
1914 			if (ab->qmi.mem_seg_count <= ATH11K_QMI_FW_MEM_REQ_SEGMENT_CNT) {
1915 				ath11k_dbg(ab, ATH11K_DBG_QMI,
1916 					   "qmi dma allocation failed (%d B type %u), will try later with small size\n",
1917 					    chunk->size,
1918 					    chunk->type);
1919 				ath11k_qmi_free_target_mem_chunk(ab);
1920 				ab->qmi.target_mem_delayed = true;
1921 				return 0;
1922 			}
1923 
1924 			ath11k_err(ab, "failed to allocate dma memory for qmi (%d B type %u)\n",
1925 				   chunk->size,
1926 				   chunk->type);
1927 			return -EINVAL;
1928 		}
1929 	}
1930 
1931 	return 0;
1932 }
1933 
1934 static int ath11k_qmi_assign_target_mem_chunk(struct ath11k_base *ab)
1935 {
1936 #if defined(__linux__)
1937 	struct device *dev = ab->dev;
1938 	struct device_node *hremote_node = NULL;
1939 	struct resource res;
1940 	u32 host_ddr_sz;
1941 	int i, idx, ret;
1942 #elif defined(__FreeBSD__)
1943 	int i, idx;
1944 #endif
1945 
1946 	for (i = 0, idx = 0; i < ab->qmi.mem_seg_count; i++) {
1947 		switch (ab->qmi.target_mem[i].type) {
1948 #if defined(__linux__)
1949 		case HOST_DDR_REGION_TYPE:
1950 			hremote_node = of_parse_phandle(dev->of_node, "memory-region", 0);
1951 			if (!hremote_node) {
1952 				ath11k_dbg(ab, ATH11K_DBG_QMI,
1953 					   "qmi fail to get hremote_node\n");
1954 				return -ENODEV;
1955 			}
1956 
1957 			ret = of_address_to_resource(hremote_node, 0, &res);
1958 			of_node_put(hremote_node);
1959 			if (ret) {
1960 				ath11k_dbg(ab, ATH11K_DBG_QMI,
1961 					   "qmi fail to get reg from hremote\n");
1962 				return ret;
1963 			}
1964 
1965 			if (res.end - res.start + 1 < ab->qmi.target_mem[i].size) {
1966 				ath11k_dbg(ab, ATH11K_DBG_QMI,
1967 					   "qmi fail to assign memory of sz\n");
1968 				return -EINVAL;
1969 			}
1970 
1971 			ab->qmi.target_mem[idx].paddr = res.start;
1972 			ab->qmi.target_mem[idx].iaddr =
1973 				ioremap(ab->qmi.target_mem[idx].paddr,
1974 					ab->qmi.target_mem[i].size);
1975 			ab->qmi.target_mem[idx].size = ab->qmi.target_mem[i].size;
1976 			host_ddr_sz = ab->qmi.target_mem[i].size;
1977 			ab->qmi.target_mem[idx].type = ab->qmi.target_mem[i].type;
1978 			idx++;
1979 			break;
1980 #endif
1981 		case BDF_MEM_REGION_TYPE:
1982 			ab->qmi.target_mem[idx].paddr = ab->hw_params.bdf_addr;
1983 			ab->qmi.target_mem[idx].vaddr = NULL;
1984 			ab->qmi.target_mem[idx].size = ab->qmi.target_mem[i].size;
1985 			ab->qmi.target_mem[idx].type = ab->qmi.target_mem[i].type;
1986 			idx++;
1987 			break;
1988 #if defined(__linux__)
1989 		case CALDB_MEM_REGION_TYPE:
1990 			if (ab->qmi.target_mem[i].size > ATH11K_QMI_CALDB_SIZE) {
1991 				ath11k_warn(ab, "qmi mem size is low to load caldata\n");
1992 				return -EINVAL;
1993 			}
1994 
1995 			if (ath11k_cold_boot_cal && ab->hw_params.cold_boot_calib) {
1996 				if (hremote_node) {
1997 					ab->qmi.target_mem[idx].paddr =
1998 							res.start + host_ddr_sz;
1999 					ab->qmi.target_mem[idx].iaddr =
2000 						ioremap(ab->qmi.target_mem[idx].paddr,
2001 							ab->qmi.target_mem[i].size);
2002 				} else {
2003 					ab->qmi.target_mem[idx].paddr =
2004 						ATH11K_QMI_CALDB_ADDRESS;
2005 				}
2006 			} else {
2007 				ab->qmi.target_mem[idx].paddr = 0;
2008 				ab->qmi.target_mem[idx].vaddr = NULL;
2009 			}
2010 			ab->qmi.target_mem[idx].size = ab->qmi.target_mem[i].size;
2011 			ab->qmi.target_mem[idx].type = ab->qmi.target_mem[i].type;
2012 			idx++;
2013 			break;
2014 #endif
2015 		default:
2016 			ath11k_warn(ab, "qmi ignore invalid mem req type %d\n",
2017 				    ab->qmi.target_mem[i].type);
2018 			break;
2019 		}
2020 	}
2021 	ab->qmi.mem_seg_count = idx;
2022 
2023 	return 0;
2024 }
2025 
2026 static int ath11k_qmi_request_target_cap(struct ath11k_base *ab)
2027 {
2028 	struct qmi_wlanfw_cap_req_msg_v01 req;
2029 	struct qmi_wlanfw_cap_resp_msg_v01 resp;
2030 	struct qmi_txn txn;
2031 	int ret = 0;
2032 	int r;
2033 
2034 	memset(&req, 0, sizeof(req));
2035 	memset(&resp, 0, sizeof(resp));
2036 
2037 	ret = qmi_txn_init(&ab->qmi.handle, &txn, qmi_wlanfw_cap_resp_msg_v01_ei,
2038 			   &resp);
2039 	if (ret < 0)
2040 		goto out;
2041 
2042 	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi target cap request\n");
2043 
2044 	ret = qmi_send_request(&ab->qmi.handle, NULL, &txn,
2045 			       QMI_WLANFW_CAP_REQ_V01,
2046 			       QMI_WLANFW_CAP_REQ_MSG_V01_MAX_LEN,
2047 			       qmi_wlanfw_cap_req_msg_v01_ei, &req);
2048 	if (ret < 0) {
2049 		qmi_txn_cancel(&txn);
2050 		ath11k_warn(ab, "failed to send qmi cap request: %d\n",
2051 			    ret);
2052 		goto out;
2053 	}
2054 
2055 	ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH11K_QMI_WLANFW_TIMEOUT_MS));
2056 	if (ret < 0) {
2057 		ath11k_warn(ab, "failed to wait qmi cap request: %d\n", ret);
2058 		goto out;
2059 	}
2060 
2061 	if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
2062 		ath11k_warn(ab, "qmi cap request failed: %d %d\n",
2063 			    resp.resp.result, resp.resp.error);
2064 		ret = -EINVAL;
2065 		goto out;
2066 	}
2067 
2068 	if (resp.chip_info_valid) {
2069 		ab->qmi.target.chip_id = resp.chip_info.chip_id;
2070 		ab->qmi.target.chip_family = resp.chip_info.chip_family;
2071 	}
2072 
2073 	if (resp.board_info_valid)
2074 		ab->qmi.target.board_id = resp.board_info.board_id;
2075 	else
2076 		ab->qmi.target.board_id = 0xFF;
2077 
2078 	if (resp.soc_info_valid)
2079 		ab->qmi.target.soc_id = resp.soc_info.soc_id;
2080 
2081 	if (resp.fw_version_info_valid) {
2082 		ab->qmi.target.fw_version = resp.fw_version_info.fw_version;
2083 		strlcpy(ab->qmi.target.fw_build_timestamp,
2084 			resp.fw_version_info.fw_build_timestamp,
2085 			sizeof(ab->qmi.target.fw_build_timestamp));
2086 	}
2087 
2088 	if (resp.fw_build_id_valid)
2089 		strlcpy(ab->qmi.target.fw_build_id, resp.fw_build_id,
2090 			sizeof(ab->qmi.target.fw_build_id));
2091 
2092 	if (resp.eeprom_read_timeout_valid) {
2093 		ab->qmi.target.eeprom_caldata =
2094 					resp.eeprom_read_timeout;
2095 		ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi cal data supported from eeprom\n");
2096 	}
2097 
2098 	ath11k_info(ab, "chip_id 0x%x chip_family 0x%x board_id 0x%x soc_id 0x%x\n",
2099 		    ab->qmi.target.chip_id, ab->qmi.target.chip_family,
2100 		    ab->qmi.target.board_id, ab->qmi.target.soc_id);
2101 
2102 	ath11k_info(ab, "fw_version 0x%x fw_build_timestamp %s fw_build_id %s",
2103 		    ab->qmi.target.fw_version,
2104 		    ab->qmi.target.fw_build_timestamp,
2105 		    ab->qmi.target.fw_build_id);
2106 
2107 	r = ath11k_core_check_dt(ab);
2108 	if (r)
2109 		ath11k_dbg(ab, ATH11K_DBG_QMI, "DT bdf variant name not set.\n");
2110 
2111 out:
2112 	return ret;
2113 }
2114 
2115 static int ath11k_qmi_load_file_target_mem(struct ath11k_base *ab,
2116 					   const u8 *data, u32 len, u8 type)
2117 {
2118 	struct qmi_wlanfw_bdf_download_req_msg_v01 *req;
2119 	struct qmi_wlanfw_bdf_download_resp_msg_v01 resp;
2120 	struct qmi_txn txn;
2121 	const u8 *temp = data;
2122 #if defined(__linux__)
2123 	void __iomem *bdf_addr = NULL;
2124 #elif defined(__FreeBSD__)
2125 	char __iomem *bdf_addr = NULL;
2126 #endif
2127 	int ret;
2128 	u32 remaining = len;
2129 
2130 	req = kzalloc(sizeof(*req), GFP_KERNEL);
2131 	if (!req)
2132 		return -ENOMEM;
2133 
2134 	memset(&resp, 0, sizeof(resp));
2135 
2136 	if (ab->bus_params.fixed_bdf_addr) {
2137 		bdf_addr = ioremap(ab->hw_params.bdf_addr, ab->hw_params.fw.board_size);
2138 		if (!bdf_addr) {
2139 			ath11k_warn(ab, "qmi ioremap error for bdf_addr\n");
2140 			ret = -EIO;
2141 			goto err_free_req;
2142 		}
2143 	}
2144 
2145 	while (remaining) {
2146 		req->valid = 1;
2147 		req->file_id_valid = 1;
2148 		req->file_id = ab->qmi.target.board_id;
2149 		req->total_size_valid = 1;
2150 		req->total_size = remaining;
2151 		req->seg_id_valid = 1;
2152 		req->data_valid = 1;
2153 		req->bdf_type = type;
2154 		req->bdf_type_valid = 1;
2155 		req->end_valid = 1;
2156 		req->end = 0;
2157 
2158 		if (remaining > QMI_WLANFW_MAX_DATA_SIZE_V01) {
2159 			req->data_len = QMI_WLANFW_MAX_DATA_SIZE_V01;
2160 		} else {
2161 			req->data_len = remaining;
2162 			req->end = 1;
2163 		}
2164 
2165 		if (ab->bus_params.fixed_bdf_addr ||
2166 		    type == ATH11K_QMI_FILE_TYPE_EEPROM) {
2167 			req->data_valid = 0;
2168 			req->end = 1;
2169 			req->data_len = ATH11K_QMI_MAX_BDF_FILE_NAME_SIZE;
2170 		} else {
2171 			memcpy(req->data, temp, req->data_len);
2172 		}
2173 
2174 		if (ab->bus_params.fixed_bdf_addr) {
2175 			if (type == ATH11K_QMI_FILE_TYPE_CALDATA)
2176 				bdf_addr += ab->hw_params.fw.cal_offset;
2177 
2178 			memcpy_toio(bdf_addr, temp, len);
2179 		}
2180 
2181 		ret = qmi_txn_init(&ab->qmi.handle, &txn,
2182 				   qmi_wlanfw_bdf_download_resp_msg_v01_ei,
2183 				   &resp);
2184 		if (ret < 0)
2185 			goto err_iounmap;
2186 
2187 		ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi bdf download req fixed addr type %d\n",
2188 			   type);
2189 
2190 		ret = qmi_send_request(&ab->qmi.handle, NULL, &txn,
2191 				       QMI_WLANFW_BDF_DOWNLOAD_REQ_V01,
2192 				       QMI_WLANFW_BDF_DOWNLOAD_REQ_MSG_V01_MAX_LEN,
2193 				       qmi_wlanfw_bdf_download_req_msg_v01_ei, req);
2194 		if (ret < 0) {
2195 			qmi_txn_cancel(&txn);
2196 			goto err_iounmap;
2197 		}
2198 
2199 		ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH11K_QMI_WLANFW_TIMEOUT_MS));
2200 		if (ret < 0) {
2201 			ath11k_warn(ab, "failed to wait board file download request: %d\n",
2202 				    ret);
2203 			goto err_iounmap;
2204 		}
2205 
2206 		if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
2207 			ath11k_warn(ab, "board file download request failed: %d %d\n",
2208 				    resp.resp.result, resp.resp.error);
2209 			ret = -EINVAL;
2210 			goto err_iounmap;
2211 		}
2212 
2213 		if (ab->bus_params.fixed_bdf_addr ||
2214 		    type == ATH11K_QMI_FILE_TYPE_EEPROM) {
2215 			remaining = 0;
2216 		} else {
2217 			remaining -= req->data_len;
2218 			temp += req->data_len;
2219 			req->seg_id++;
2220 			ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi bdf download request remaining %i\n",
2221 				   remaining);
2222 		}
2223 	}
2224 
2225 err_iounmap:
2226 	if (ab->bus_params.fixed_bdf_addr)
2227 		iounmap(bdf_addr);
2228 
2229 err_free_req:
2230 	kfree(req);
2231 
2232 	return ret;
2233 }
2234 
2235 static int ath11k_qmi_load_bdf_qmi(struct ath11k_base *ab,
2236 				   bool regdb)
2237 {
2238 	struct device *dev = ab->dev;
2239 	char filename[ATH11K_QMI_MAX_BDF_FILE_NAME_SIZE];
2240 	const struct firmware *fw_entry;
2241 	struct ath11k_board_data bd;
2242 	u32 fw_size, file_type;
2243 	int ret = 0, bdf_type;
2244 	const u8 *tmp;
2245 
2246 	memset(&bd, 0, sizeof(bd));
2247 
2248 	if (regdb) {
2249 		ret = ath11k_core_fetch_regdb(ab, &bd);
2250 	} else {
2251 		ret = ath11k_core_fetch_bdf(ab, &bd);
2252 		if (ret)
2253 			ath11k_warn(ab, "qmi failed to fetch board file: %d\n", ret);
2254 	}
2255 
2256 	if (ret)
2257 		goto out;
2258 
2259 	if (regdb)
2260 		bdf_type = ATH11K_QMI_BDF_TYPE_REGDB;
2261 	else if (bd.len >= SELFMAG && memcmp(bd.data, ELFMAG, SELFMAG) == 0)
2262 		bdf_type = ATH11K_QMI_BDF_TYPE_ELF;
2263 	else
2264 		bdf_type = ATH11K_QMI_BDF_TYPE_BIN;
2265 
2266 	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi bdf_type %d\n", bdf_type);
2267 
2268 	fw_size = min_t(u32, ab->hw_params.fw.board_size, bd.len);
2269 
2270 	ret = ath11k_qmi_load_file_target_mem(ab, bd.data, fw_size, bdf_type);
2271 	if (ret < 0) {
2272 		ath11k_warn(ab, "qmi failed to load bdf file\n");
2273 		goto out;
2274 	}
2275 
2276 	/* QCA6390/WCN6855 does not support cal data, skip it */
2277 	if (bdf_type == ATH11K_QMI_BDF_TYPE_ELF || bdf_type == ATH11K_QMI_BDF_TYPE_REGDB)
2278 		goto out;
2279 
2280 	if (ab->qmi.target.eeprom_caldata) {
2281 		file_type = ATH11K_QMI_FILE_TYPE_EEPROM;
2282 		tmp = filename;
2283 		fw_size = ATH11K_QMI_MAX_BDF_FILE_NAME_SIZE;
2284 	} else {
2285 		file_type = ATH11K_QMI_FILE_TYPE_CALDATA;
2286 
2287 		/* cal-<bus>-<id>.bin */
2288 		snprintf(filename, sizeof(filename), "cal-%s-%s.bin",
2289 			 ath11k_bus_str(ab->hif.bus), dev_name(dev));
2290 		fw_entry = ath11k_core_firmware_request(ab, filename);
2291 		if (!IS_ERR(fw_entry))
2292 			goto success;
2293 
2294 		fw_entry = ath11k_core_firmware_request(ab, ATH11K_DEFAULT_CAL_FILE);
2295 		if (IS_ERR(fw_entry)) {
2296 			ret = PTR_ERR(fw_entry);
2297 			ath11k_warn(ab,
2298 				    "qmi failed to load CAL data file:%s\n",
2299 				    filename);
2300 			goto out;
2301 		}
2302 success:
2303 		fw_size = min_t(u32, ab->hw_params.fw.board_size, fw_entry->size);
2304 		tmp = fw_entry->data;
2305 	}
2306 
2307 	ret = ath11k_qmi_load_file_target_mem(ab, tmp, fw_size, file_type);
2308 	if (ret < 0) {
2309 		ath11k_warn(ab, "qmi failed to load caldata\n");
2310 		goto out_qmi_cal;
2311 	}
2312 
2313 	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi caldata type: %u\n", file_type);
2314 
2315 out_qmi_cal:
2316 	if (!ab->qmi.target.eeprom_caldata)
2317 		release_firmware(fw_entry);
2318 out:
2319 	ath11k_core_free_bdf(ab, &bd);
2320 	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi BDF download sequence completed\n");
2321 
2322 	return ret;
2323 }
2324 
2325 static int ath11k_qmi_m3_load(struct ath11k_base *ab)
2326 {
2327 	struct m3_mem_region *m3_mem = &ab->qmi.m3_mem;
2328 	const struct firmware *fw;
2329 	char path[100];
2330 	int ret;
2331 
2332 	if (m3_mem->vaddr || m3_mem->size)
2333 		return 0;
2334 
2335 	fw = ath11k_core_firmware_request(ab, ATH11K_M3_FILE);
2336 	if (IS_ERR(fw)) {
2337 		ret = PTR_ERR(fw);
2338 		ath11k_core_create_firmware_path(ab, ATH11K_M3_FILE,
2339 						 path, sizeof(path));
2340 		ath11k_err(ab, "failed to load %s: %d\n", path, ret);
2341 		return ret;
2342 	}
2343 
2344 	m3_mem->vaddr = dma_alloc_coherent(ab->dev,
2345 					   fw->size, &m3_mem->paddr,
2346 					   GFP_KERNEL);
2347 	if (!m3_mem->vaddr) {
2348 		ath11k_err(ab, "failed to allocate memory for M3 with size %zu\n",
2349 			   fw->size);
2350 		release_firmware(fw);
2351 		return -ENOMEM;
2352 	}
2353 
2354 	memcpy(m3_mem->vaddr, fw->data, fw->size);
2355 	m3_mem->size = fw->size;
2356 	release_firmware(fw);
2357 
2358 	return 0;
2359 }
2360 
2361 static void ath11k_qmi_m3_free(struct ath11k_base *ab)
2362 {
2363 	struct m3_mem_region *m3_mem = &ab->qmi.m3_mem;
2364 
2365 	if (!ab->bus_params.m3_fw_support || !m3_mem->vaddr)
2366 		return;
2367 
2368 	dma_free_coherent(ab->dev, m3_mem->size,
2369 			  m3_mem->vaddr, m3_mem->paddr);
2370 	m3_mem->vaddr = NULL;
2371 }
2372 
2373 static int ath11k_qmi_wlanfw_m3_info_send(struct ath11k_base *ab)
2374 {
2375 	struct m3_mem_region *m3_mem = &ab->qmi.m3_mem;
2376 	struct qmi_wlanfw_m3_info_req_msg_v01 req;
2377 	struct qmi_wlanfw_m3_info_resp_msg_v01 resp;
2378 	struct qmi_txn txn;
2379 	int ret = 0;
2380 
2381 	memset(&req, 0, sizeof(req));
2382 	memset(&resp, 0, sizeof(resp));
2383 
2384 	if (ab->bus_params.m3_fw_support) {
2385 		ret = ath11k_qmi_m3_load(ab);
2386 		if (ret) {
2387 			ath11k_err(ab, "failed to load m3 firmware: %d", ret);
2388 			return ret;
2389 		}
2390 
2391 		req.addr = m3_mem->paddr;
2392 		req.size = m3_mem->size;
2393 	} else {
2394 		req.addr = 0;
2395 		req.size = 0;
2396 	}
2397 
2398 	ret = qmi_txn_init(&ab->qmi.handle, &txn,
2399 			   qmi_wlanfw_m3_info_resp_msg_v01_ei, &resp);
2400 	if (ret < 0)
2401 		goto out;
2402 
2403 	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi m3 info req\n");
2404 
2405 	ret = qmi_send_request(&ab->qmi.handle, NULL, &txn,
2406 			       QMI_WLANFW_M3_INFO_REQ_V01,
2407 			       QMI_WLANFW_M3_INFO_REQ_MSG_V01_MAX_MSG_LEN,
2408 			       qmi_wlanfw_m3_info_req_msg_v01_ei, &req);
2409 	if (ret < 0) {
2410 		qmi_txn_cancel(&txn);
2411 		ath11k_warn(ab, "failed to send m3 information request: %d\n",
2412 			    ret);
2413 		goto out;
2414 	}
2415 
2416 	ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH11K_QMI_WLANFW_TIMEOUT_MS));
2417 	if (ret < 0) {
2418 		ath11k_warn(ab, "failed to wait m3 information request: %d\n", ret);
2419 		goto out;
2420 	}
2421 
2422 	if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
2423 		ath11k_warn(ab, "m3 info request failed: %d %d\n",
2424 			    resp.resp.result, resp.resp.error);
2425 		ret = -EINVAL;
2426 		goto out;
2427 	}
2428 out:
2429 	return ret;
2430 }
2431 
2432 static int ath11k_qmi_wlanfw_mode_send(struct ath11k_base *ab,
2433 				       u32 mode)
2434 {
2435 	struct qmi_wlanfw_wlan_mode_req_msg_v01 req;
2436 	struct qmi_wlanfw_wlan_mode_resp_msg_v01 resp;
2437 	struct qmi_txn txn;
2438 	int ret = 0;
2439 
2440 	memset(&req, 0, sizeof(req));
2441 	memset(&resp, 0, sizeof(resp));
2442 
2443 	req.mode = mode;
2444 	req.hw_debug_valid = 1;
2445 	req.hw_debug = 0;
2446 
2447 	ret = qmi_txn_init(&ab->qmi.handle, &txn,
2448 			   qmi_wlanfw_wlan_mode_resp_msg_v01_ei, &resp);
2449 	if (ret < 0)
2450 		goto out;
2451 
2452 	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi wlan mode req mode %d\n", mode);
2453 
2454 	ret = qmi_send_request(&ab->qmi.handle, NULL, &txn,
2455 			       QMI_WLANFW_WLAN_MODE_REQ_V01,
2456 			       QMI_WLANFW_WLAN_MODE_REQ_MSG_V01_MAX_LEN,
2457 			       qmi_wlanfw_wlan_mode_req_msg_v01_ei, &req);
2458 	if (ret < 0) {
2459 		qmi_txn_cancel(&txn);
2460 		ath11k_warn(ab, "failed to send wlan mode request (mode %d): %d\n",
2461 			    mode, ret);
2462 		goto out;
2463 	}
2464 
2465 	ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH11K_QMI_WLANFW_TIMEOUT_MS));
2466 	if (ret < 0) {
2467 		if (mode == ATH11K_FIRMWARE_MODE_OFF && ret == -ENETRESET) {
2468 			ath11k_warn(ab, "WLFW service is dis-connected\n");
2469 			return 0;
2470 		}
2471 		ath11k_warn(ab, "failed to wait wlan mode request (mode %d): %d\n",
2472 			    mode, ret);
2473 		goto out;
2474 	}
2475 
2476 	if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
2477 		ath11k_warn(ab, "wlan mode request failed (mode: %d): %d %d\n",
2478 			    mode, resp.resp.result, resp.resp.error);
2479 		ret = -EINVAL;
2480 		goto out;
2481 	}
2482 
2483 out:
2484 	return ret;
2485 }
2486 
2487 static int ath11k_qmi_wlanfw_wlan_cfg_send(struct ath11k_base *ab)
2488 {
2489 	struct qmi_wlanfw_wlan_cfg_req_msg_v01 *req;
2490 	struct qmi_wlanfw_wlan_cfg_resp_msg_v01 resp;
2491 #if defined(__linux__)
2492 	struct ce_pipe_config *ce_cfg;
2493 	struct service_to_pipe *svc_cfg;
2494 #elif defined(__FreeBSD__)
2495 	const struct ce_pipe_config *ce_cfg;
2496 	const struct service_to_pipe *svc_cfg;
2497 #endif
2498 	struct qmi_txn txn;
2499 	int ret = 0, pipe_num;
2500 
2501 #if defined(__linux__)
2502 	ce_cfg	= (struct ce_pipe_config *)ab->qmi.ce_cfg.tgt_ce;
2503 	svc_cfg	= (struct service_to_pipe *)ab->qmi.ce_cfg.svc_to_ce_map;
2504 #elif defined(__FreeBSD__)
2505 	ce_cfg	= (const struct ce_pipe_config *)ab->qmi.ce_cfg.tgt_ce;
2506 	svc_cfg	= (const struct service_to_pipe *)ab->qmi.ce_cfg.svc_to_ce_map;
2507 #endif
2508 
2509 	req = kzalloc(sizeof(*req), GFP_KERNEL);
2510 	if (!req)
2511 		return -ENOMEM;
2512 
2513 	memset(&resp, 0, sizeof(resp));
2514 
2515 	req->host_version_valid = 1;
2516 	strlcpy(req->host_version, ATH11K_HOST_VERSION_STRING,
2517 		sizeof(req->host_version));
2518 
2519 	req->tgt_cfg_valid = 1;
2520 	/* This is number of CE configs */
2521 	req->tgt_cfg_len = ab->qmi.ce_cfg.tgt_ce_len;
2522 	for (pipe_num = 0; pipe_num < req->tgt_cfg_len ; pipe_num++) {
2523 		req->tgt_cfg[pipe_num].pipe_num = ce_cfg[pipe_num].pipenum;
2524 		req->tgt_cfg[pipe_num].pipe_dir = ce_cfg[pipe_num].pipedir;
2525 		req->tgt_cfg[pipe_num].nentries = ce_cfg[pipe_num].nentries;
2526 		req->tgt_cfg[pipe_num].nbytes_max = ce_cfg[pipe_num].nbytes_max;
2527 		req->tgt_cfg[pipe_num].flags = ce_cfg[pipe_num].flags;
2528 	}
2529 
2530 	req->svc_cfg_valid = 1;
2531 	/* This is number of Service/CE configs */
2532 	req->svc_cfg_len = ab->qmi.ce_cfg.svc_to_ce_map_len;
2533 	for (pipe_num = 0; pipe_num < req->svc_cfg_len; pipe_num++) {
2534 		req->svc_cfg[pipe_num].service_id = svc_cfg[pipe_num].service_id;
2535 		req->svc_cfg[pipe_num].pipe_dir = svc_cfg[pipe_num].pipedir;
2536 		req->svc_cfg[pipe_num].pipe_num = svc_cfg[pipe_num].pipenum;
2537 	}
2538 	req->shadow_reg_valid = 0;
2539 
2540 	/* set shadow v2 configuration */
2541 	if (ab->hw_params.supports_shadow_regs) {
2542 		req->shadow_reg_v2_valid = 1;
2543 		req->shadow_reg_v2_len = min_t(u32,
2544 					       ab->qmi.ce_cfg.shadow_reg_v2_len,
2545 					       QMI_WLANFW_MAX_NUM_SHADOW_REG_V2_V01);
2546 		memcpy(&req->shadow_reg_v2, ab->qmi.ce_cfg.shadow_reg_v2,
2547 		       sizeof(u32) * req->shadow_reg_v2_len);
2548 	} else {
2549 		req->shadow_reg_v2_valid = 0;
2550 	}
2551 
2552 	ret = qmi_txn_init(&ab->qmi.handle, &txn,
2553 			   qmi_wlanfw_wlan_cfg_resp_msg_v01_ei, &resp);
2554 	if (ret < 0)
2555 		goto out;
2556 
2557 	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi wlan cfg req\n");
2558 
2559 	ret = qmi_send_request(&ab->qmi.handle, NULL, &txn,
2560 			       QMI_WLANFW_WLAN_CFG_REQ_V01,
2561 			       QMI_WLANFW_WLAN_CFG_REQ_MSG_V01_MAX_LEN,
2562 			       qmi_wlanfw_wlan_cfg_req_msg_v01_ei, req);
2563 	if (ret < 0) {
2564 		qmi_txn_cancel(&txn);
2565 		ath11k_warn(ab, "failed to send wlan config request: %d\n",
2566 			    ret);
2567 		goto out;
2568 	}
2569 
2570 	ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH11K_QMI_WLANFW_TIMEOUT_MS));
2571 	if (ret < 0) {
2572 		ath11k_warn(ab, "failed to wait wlan config request: %d\n", ret);
2573 		goto out;
2574 	}
2575 
2576 	if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
2577 		ath11k_warn(ab, "wlan config request failed: %d %d\n",
2578 			    resp.resp.result, resp.resp.error);
2579 		ret = -EINVAL;
2580 		goto out;
2581 	}
2582 
2583 out:
2584 	kfree(req);
2585 	return ret;
2586 }
2587 
2588 static int ath11k_qmi_wlanfw_wlan_ini_send(struct ath11k_base *ab, bool enable)
2589 {
2590 	int ret;
2591 	struct qmi_txn txn;
2592 	struct qmi_wlanfw_wlan_ini_req_msg_v01 req = {};
2593 	struct qmi_wlanfw_wlan_ini_resp_msg_v01 resp = {};
2594 
2595 	req.enablefwlog_valid = true;
2596 	req.enablefwlog = enable ? 1 : 0;
2597 
2598 	ret = qmi_txn_init(&ab->qmi.handle, &txn,
2599 			   qmi_wlanfw_wlan_ini_resp_msg_v01_ei, &resp);
2600 	if (ret < 0)
2601 		goto out;
2602 
2603 	ret = qmi_send_request(&ab->qmi.handle, NULL, &txn,
2604 			       QMI_WLANFW_WLAN_INI_REQ_V01,
2605 			       QMI_WLANFW_WLAN_INI_REQ_MSG_V01_MAX_LEN,
2606 			       qmi_wlanfw_wlan_ini_req_msg_v01_ei, &req);
2607 	if (ret < 0) {
2608 		ath11k_warn(ab, "qmi failed to send wlan ini request, err = %d\n",
2609 			    ret);
2610 		qmi_txn_cancel(&txn);
2611 		goto out;
2612 	}
2613 
2614 	ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH11K_QMI_WLANFW_TIMEOUT_MS));
2615 	if (ret < 0) {
2616 		ath11k_warn(ab, "qmi failed wlan ini request, err = %d\n", ret);
2617 		goto out;
2618 	}
2619 
2620 	if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
2621 		ath11k_warn(ab, "qmi wlan ini request failed, result: %d, err: %d\n",
2622 			    resp.resp.result, resp.resp.error);
2623 		ret = -EINVAL;
2624 	}
2625 
2626 out:
2627 	return ret;
2628 }
2629 
2630 void ath11k_qmi_firmware_stop(struct ath11k_base *ab)
2631 {
2632 	int ret;
2633 
2634 	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi firmware stop\n");
2635 
2636 	ret = ath11k_qmi_wlanfw_mode_send(ab, ATH11K_FIRMWARE_MODE_OFF);
2637 	if (ret < 0) {
2638 		ath11k_warn(ab, "qmi failed to send wlan mode off: %d\n", ret);
2639 		return;
2640 	}
2641 }
2642 
2643 int ath11k_qmi_firmware_start(struct ath11k_base *ab,
2644 			      u32 mode)
2645 {
2646 	int ret;
2647 
2648 	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi firmware start\n");
2649 
2650 	if (ab->hw_params.fw_wmi_diag_event) {
2651 		ret = ath11k_qmi_wlanfw_wlan_ini_send(ab, true);
2652 		if (ret < 0) {
2653 			ath11k_warn(ab, "qmi failed to send wlan fw ini:%d\n", ret);
2654 			return ret;
2655 		}
2656 	}
2657 
2658 	ret = ath11k_qmi_wlanfw_wlan_cfg_send(ab);
2659 	if (ret < 0) {
2660 		ath11k_warn(ab, "qmi failed to send wlan cfg: %d\n", ret);
2661 		return ret;
2662 	}
2663 
2664 	ret = ath11k_qmi_wlanfw_mode_send(ab, mode);
2665 	if (ret < 0) {
2666 		ath11k_warn(ab, "qmi failed to send wlan fw mode: %d\n", ret);
2667 		return ret;
2668 	}
2669 
2670 	return 0;
2671 }
2672 
2673 static int ath11k_qmi_process_coldboot_calibration(struct ath11k_base *ab)
2674 {
2675 	int timeout;
2676 	int ret;
2677 
2678 	ret = ath11k_qmi_wlanfw_mode_send(ab, ATH11K_FIRMWARE_MODE_COLD_BOOT);
2679 	if (ret < 0) {
2680 		ath11k_warn(ab, "qmi failed to send wlan fw mode: %d\n", ret);
2681 		return ret;
2682 	}
2683 
2684 	ath11k_dbg(ab, ATH11K_DBG_QMI, "Coldboot calibration wait started\n");
2685 
2686 	timeout = wait_event_timeout(ab->qmi.cold_boot_waitq,
2687 				     (ab->qmi.cal_done  == 1),
2688 				     ATH11K_COLD_BOOT_FW_RESET_DELAY);
2689 	if (timeout <= 0) {
2690 		ath11k_warn(ab, "coldboot calibration timed out\n");
2691 		return 0;
2692 	}
2693 
2694 	ath11k_dbg(ab, ATH11K_DBG_QMI, "Coldboot calibration done\n");
2695 
2696 	return 0;
2697 }
2698 
2699 static int
2700 ath11k_qmi_driver_event_post(struct ath11k_qmi *qmi,
2701 			     enum ath11k_qmi_event_type type,
2702 			     void *data)
2703 {
2704 	struct ath11k_qmi_driver_event *event;
2705 
2706 	event = kzalloc(sizeof(*event), GFP_ATOMIC);
2707 	if (!event)
2708 		return -ENOMEM;
2709 
2710 	event->type = type;
2711 	event->data = data;
2712 
2713 	spin_lock(&qmi->event_lock);
2714 	list_add_tail(&event->list, &qmi->event_list);
2715 	spin_unlock(&qmi->event_lock);
2716 
2717 	queue_work(qmi->event_wq, &qmi->event_work);
2718 
2719 	return 0;
2720 }
2721 
2722 static int ath11k_qmi_event_server_arrive(struct ath11k_qmi *qmi)
2723 {
2724 	struct ath11k_base *ab = qmi->ab;
2725 	int ret;
2726 
2727 	ret = ath11k_qmi_fw_ind_register_send(ab);
2728 	if (ret < 0) {
2729 		ath11k_warn(ab, "failed to send qmi firmware indication: %d\n",
2730 			    ret);
2731 		return ret;
2732 	}
2733 
2734 	ret = ath11k_qmi_host_cap_send(ab);
2735 	if (ret < 0) {
2736 		ath11k_warn(ab, "failed to send qmi host cap: %d\n", ret);
2737 		return ret;
2738 	}
2739 
2740 	return ret;
2741 }
2742 
2743 static int ath11k_qmi_event_mem_request(struct ath11k_qmi *qmi)
2744 {
2745 	struct ath11k_base *ab = qmi->ab;
2746 	int ret;
2747 
2748 	ret = ath11k_qmi_respond_fw_mem_request(ab);
2749 	if (ret < 0) {
2750 		ath11k_warn(ab, "qmi failed to respond fw mem req: %d\n", ret);
2751 		return ret;
2752 	}
2753 
2754 	return ret;
2755 }
2756 
2757 static int ath11k_qmi_event_load_bdf(struct ath11k_qmi *qmi)
2758 {
2759 	struct ath11k_base *ab = qmi->ab;
2760 	int ret;
2761 
2762 	ret = ath11k_qmi_request_target_cap(ab);
2763 	if (ret < 0) {
2764 		ath11k_warn(ab, "failed to request qmi target capabilities: %d\n",
2765 			    ret);
2766 		return ret;
2767 	}
2768 
2769 	if (ab->hw_params.supports_regdb)
2770 		ath11k_qmi_load_bdf_qmi(ab, true);
2771 
2772 	ret = ath11k_qmi_load_bdf_qmi(ab, false);
2773 	if (ret < 0) {
2774 		ath11k_warn(ab, "failed to load board data file: %d\n", ret);
2775 		return ret;
2776 	}
2777 
2778 	ret = ath11k_qmi_wlanfw_m3_info_send(ab);
2779 	if (ret < 0) {
2780 		ath11k_warn(ab, "failed to send qmi m3 info req: %d\n", ret);
2781 		return ret;
2782 	}
2783 
2784 	return ret;
2785 }
2786 
2787 static void ath11k_qmi_msg_mem_request_cb(struct qmi_handle *qmi_hdl,
2788 					  struct sockaddr_qrtr *sq,
2789 					  struct qmi_txn *txn,
2790 					  const void *data)
2791 {
2792 	struct ath11k_qmi *qmi = container_of(qmi_hdl, struct ath11k_qmi, handle);
2793 	struct ath11k_base *ab = qmi->ab;
2794 	const struct qmi_wlanfw_request_mem_ind_msg_v01 *msg = data;
2795 	int i, ret;
2796 
2797 	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi firmware request memory request\n");
2798 
2799 	if (msg->mem_seg_len == 0 ||
2800 	    msg->mem_seg_len > ATH11K_QMI_WLANFW_MAX_NUM_MEM_SEG_V01)
2801 		ath11k_warn(ab, "invalid memory segment length: %u\n",
2802 			    msg->mem_seg_len);
2803 
2804 	ab->qmi.mem_seg_count = msg->mem_seg_len;
2805 
2806 	for (i = 0; i < qmi->mem_seg_count ; i++) {
2807 		ab->qmi.target_mem[i].type = msg->mem_seg[i].type;
2808 		ab->qmi.target_mem[i].size = msg->mem_seg[i].size;
2809 		ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi mem seg type %d size %d\n",
2810 			   msg->mem_seg[i].type, msg->mem_seg[i].size);
2811 	}
2812 
2813 	if (ab->bus_params.fixed_mem_region ||
2814 	    test_bit(ATH11K_FLAG_FIXED_MEM_RGN, &ab->dev_flags)) {
2815 		ret = ath11k_qmi_assign_target_mem_chunk(ab);
2816 		if (ret) {
2817 			ath11k_warn(ab, "failed to assign qmi target memory: %d\n",
2818 				    ret);
2819 			return;
2820 		}
2821 	} else {
2822 		ret = ath11k_qmi_alloc_target_mem_chunk(ab);
2823 		if (ret) {
2824 			ath11k_warn(ab, "failed to allocate qmi target memory: %d\n",
2825 				    ret);
2826 			return;
2827 		}
2828 	}
2829 
2830 	ath11k_qmi_driver_event_post(qmi, ATH11K_QMI_EVENT_REQUEST_MEM, NULL);
2831 }
2832 
2833 static void ath11k_qmi_msg_mem_ready_cb(struct qmi_handle *qmi_hdl,
2834 					struct sockaddr_qrtr *sq,
2835 					struct qmi_txn *txn,
2836 					const void *decoded)
2837 {
2838 	struct ath11k_qmi *qmi = container_of(qmi_hdl, struct ath11k_qmi, handle);
2839 	struct ath11k_base *ab = qmi->ab;
2840 
2841 	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi firmware memory ready indication\n");
2842 	ath11k_qmi_driver_event_post(qmi, ATH11K_QMI_EVENT_FW_MEM_READY, NULL);
2843 }
2844 
2845 static void ath11k_qmi_msg_fw_ready_cb(struct qmi_handle *qmi_hdl,
2846 				       struct sockaddr_qrtr *sq,
2847 				       struct qmi_txn *txn,
2848 				       const void *decoded)
2849 {
2850 	struct ath11k_qmi *qmi = container_of(qmi_hdl, struct ath11k_qmi, handle);
2851 	struct ath11k_base *ab = qmi->ab;
2852 
2853 	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi firmware ready\n");
2854 	ath11k_qmi_driver_event_post(qmi, ATH11K_QMI_EVENT_FW_READY, NULL);
2855 }
2856 
2857 static void ath11k_qmi_msg_cold_boot_cal_done_cb(struct qmi_handle *qmi_hdl,
2858 						 struct sockaddr_qrtr *sq,
2859 						 struct qmi_txn *txn,
2860 						 const void *decoded)
2861 {
2862 	struct ath11k_qmi *qmi = container_of(qmi_hdl,
2863 					      struct ath11k_qmi, handle);
2864 	struct ath11k_base *ab = qmi->ab;
2865 
2866 	ab->qmi.cal_done = 1;
2867 	wake_up(&ab->qmi.cold_boot_waitq);
2868 	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi cold boot calibration done\n");
2869 }
2870 
2871 static const struct qmi_msg_handler ath11k_qmi_msg_handlers[] = {
2872 	{
2873 		.type = QMI_INDICATION,
2874 		.msg_id = QMI_WLFW_REQUEST_MEM_IND_V01,
2875 		.ei = qmi_wlanfw_request_mem_ind_msg_v01_ei,
2876 		.decoded_size = sizeof(struct qmi_wlanfw_request_mem_ind_msg_v01),
2877 		.fn = ath11k_qmi_msg_mem_request_cb,
2878 	},
2879 	{
2880 		.type = QMI_INDICATION,
2881 		.msg_id = QMI_WLFW_FW_MEM_READY_IND_V01,
2882 		.ei = qmi_wlanfw_mem_ready_ind_msg_v01_ei,
2883 		.decoded_size = sizeof(struct qmi_wlanfw_fw_mem_ready_ind_msg_v01),
2884 		.fn = ath11k_qmi_msg_mem_ready_cb,
2885 	},
2886 	{
2887 		.type = QMI_INDICATION,
2888 		.msg_id = QMI_WLFW_FW_READY_IND_V01,
2889 		.ei = qmi_wlanfw_fw_ready_ind_msg_v01_ei,
2890 		.decoded_size = sizeof(struct qmi_wlanfw_fw_ready_ind_msg_v01),
2891 		.fn = ath11k_qmi_msg_fw_ready_cb,
2892 	},
2893 	{
2894 		.type = QMI_INDICATION,
2895 		.msg_id = QMI_WLFW_COLD_BOOT_CAL_DONE_IND_V01,
2896 		.ei = qmi_wlanfw_cold_boot_cal_done_ind_msg_v01_ei,
2897 		.decoded_size =
2898 			sizeof(struct qmi_wlanfw_fw_cold_cal_done_ind_msg_v01),
2899 		.fn = ath11k_qmi_msg_cold_boot_cal_done_cb,
2900 	},
2901 };
2902 
2903 static int ath11k_qmi_ops_new_server(struct qmi_handle *qmi_hdl,
2904 				     struct qmi_service *service)
2905 {
2906 	struct ath11k_qmi *qmi = container_of(qmi_hdl, struct ath11k_qmi, handle);
2907 	struct ath11k_base *ab = qmi->ab;
2908 	struct sockaddr_qrtr *sq = &qmi->sq;
2909 	int ret;
2910 
2911 	sq->sq_family = AF_QIPCRTR;
2912 	sq->sq_node = service->node;
2913 	sq->sq_port = service->port;
2914 
2915 	ret = kernel_connect(qmi_hdl->sock, (struct sockaddr *)sq,
2916 			     sizeof(*sq), 0);
2917 	if (ret) {
2918 		ath11k_warn(ab, "failed to connect to qmi remote service: %d\n", ret);
2919 		return ret;
2920 	}
2921 
2922 	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi wifi fw qmi service connected\n");
2923 	ath11k_qmi_driver_event_post(qmi, ATH11K_QMI_EVENT_SERVER_ARRIVE, NULL);
2924 
2925 	return ret;
2926 }
2927 
2928 static void ath11k_qmi_ops_del_server(struct qmi_handle *qmi_hdl,
2929 				      struct qmi_service *service)
2930 {
2931 	struct ath11k_qmi *qmi = container_of(qmi_hdl, struct ath11k_qmi, handle);
2932 	struct ath11k_base *ab = qmi->ab;
2933 
2934 	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi wifi fw del server\n");
2935 	ath11k_qmi_driver_event_post(qmi, ATH11K_QMI_EVENT_SERVER_EXIT, NULL);
2936 }
2937 
2938 static const struct qmi_ops ath11k_qmi_ops = {
2939 	.new_server = ath11k_qmi_ops_new_server,
2940 	.del_server = ath11k_qmi_ops_del_server,
2941 };
2942 
2943 static void ath11k_qmi_driver_event_work(struct work_struct *work)
2944 {
2945 	struct ath11k_qmi *qmi = container_of(work, struct ath11k_qmi,
2946 					      event_work);
2947 	struct ath11k_qmi_driver_event *event;
2948 	struct ath11k_base *ab = qmi->ab;
2949 	int ret;
2950 
2951 	spin_lock(&qmi->event_lock);
2952 	while (!list_empty(&qmi->event_list)) {
2953 		event = list_first_entry(&qmi->event_list,
2954 					 struct ath11k_qmi_driver_event, list);
2955 		list_del(&event->list);
2956 		spin_unlock(&qmi->event_lock);
2957 
2958 		if (test_bit(ATH11K_FLAG_UNREGISTERING, &ab->dev_flags)) {
2959 			kfree(event);
2960 			return;
2961 		}
2962 
2963 		switch (event->type) {
2964 		case ATH11K_QMI_EVENT_SERVER_ARRIVE:
2965 			ret = ath11k_qmi_event_server_arrive(qmi);
2966 			if (ret < 0)
2967 				set_bit(ATH11K_FLAG_QMI_FAIL, &ab->dev_flags);
2968 			break;
2969 		case ATH11K_QMI_EVENT_SERVER_EXIT:
2970 			set_bit(ATH11K_FLAG_CRASH_FLUSH, &ab->dev_flags);
2971 			set_bit(ATH11K_FLAG_RECOVERY, &ab->dev_flags);
2972 			break;
2973 		case ATH11K_QMI_EVENT_REQUEST_MEM:
2974 			ret = ath11k_qmi_event_mem_request(qmi);
2975 			if (ret < 0)
2976 				set_bit(ATH11K_FLAG_QMI_FAIL, &ab->dev_flags);
2977 			break;
2978 		case ATH11K_QMI_EVENT_FW_MEM_READY:
2979 			ret = ath11k_qmi_event_load_bdf(qmi);
2980 			if (ret < 0)
2981 				set_bit(ATH11K_FLAG_QMI_FAIL, &ab->dev_flags);
2982 			break;
2983 		case ATH11K_QMI_EVENT_FW_READY:
2984 			clear_bit(ATH11K_FLAG_QMI_FAIL, &ab->dev_flags);
2985 			if (test_bit(ATH11K_FLAG_REGISTERED, &ab->dev_flags)) {
2986 				ath11k_hal_dump_srng_stats(ab);
2987 				queue_work(ab->workqueue, &ab->restart_work);
2988 				break;
2989 			}
2990 
2991 			if (ath11k_cold_boot_cal && ab->qmi.cal_done == 0 &&
2992 			    ab->hw_params.cold_boot_calib) {
2993 				ath11k_qmi_process_coldboot_calibration(ab);
2994 			} else {
2995 				clear_bit(ATH11K_FLAG_CRASH_FLUSH,
2996 					  &ab->dev_flags);
2997 				clear_bit(ATH11K_FLAG_RECOVERY, &ab->dev_flags);
2998 				ath11k_core_qmi_firmware_ready(ab);
2999 				set_bit(ATH11K_FLAG_REGISTERED, &ab->dev_flags);
3000 			}
3001 
3002 			break;
3003 		case ATH11K_QMI_EVENT_COLD_BOOT_CAL_DONE:
3004 			break;
3005 		default:
3006 			ath11k_warn(ab, "invalid qmi event type: %d", event->type);
3007 			break;
3008 		}
3009 		kfree(event);
3010 		spin_lock(&qmi->event_lock);
3011 	}
3012 	spin_unlock(&qmi->event_lock);
3013 }
3014 
3015 int ath11k_qmi_init_service(struct ath11k_base *ab)
3016 {
3017 	int ret;
3018 
3019 	memset(&ab->qmi.target, 0, sizeof(struct target_info));
3020 	memset(&ab->qmi.target_mem, 0, sizeof(struct target_mem_chunk));
3021 	ab->qmi.ab = ab;
3022 
3023 	ab->qmi.target_mem_mode = ab->hw_params.fw_mem_mode;
3024 	ret = qmi_handle_init(&ab->qmi.handle, ATH11K_QMI_RESP_LEN_MAX,
3025 			      &ath11k_qmi_ops, ath11k_qmi_msg_handlers);
3026 	if (ret < 0) {
3027 		ath11k_warn(ab, "failed to initialize qmi handle: %d\n", ret);
3028 		return ret;
3029 	}
3030 
3031 	ab->qmi.event_wq = alloc_workqueue("ath11k_qmi_driver_event",
3032 					   WQ_UNBOUND, 1);
3033 	if (!ab->qmi.event_wq) {
3034 		ath11k_err(ab, "failed to allocate workqueue\n");
3035 		return -EFAULT;
3036 	}
3037 
3038 	INIT_LIST_HEAD(&ab->qmi.event_list);
3039 	spin_lock_init(&ab->qmi.event_lock);
3040 	INIT_WORK(&ab->qmi.event_work, ath11k_qmi_driver_event_work);
3041 
3042 	ret = qmi_add_lookup(&ab->qmi.handle, ATH11K_QMI_WLFW_SERVICE_ID_V01,
3043 			     ATH11K_QMI_WLFW_SERVICE_VERS_V01,
3044 			     ab->qmi.service_ins_id);
3045 	if (ret < 0) {
3046 		ath11k_warn(ab, "failed to add qmi lookup: %d\n", ret);
3047 		destroy_workqueue(ab->qmi.event_wq);
3048 		return ret;
3049 	}
3050 
3051 	return ret;
3052 }
3053 
3054 void ath11k_qmi_deinit_service(struct ath11k_base *ab)
3055 {
3056 	qmi_handle_release(&ab->qmi.handle);
3057 	cancel_work_sync(&ab->qmi.event_work);
3058 	destroy_workqueue(ab->qmi.event_wq);
3059 	ath11k_qmi_m3_free(ab);
3060 	ath11k_qmi_free_target_mem_chunk(ab);
3061 }
3062 EXPORT_SYMBOL(ath11k_qmi_deinit_service);
3063 
3064