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