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