xref: /linux/drivers/net/wireless/ath/ath12k/qmi.c (revision b6144dcdd445d1bf8b7973b73c9a2dd5b44661cf)
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_UNSIGNED_1_BYTE,
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 	if (ab->hw_params->qmi_cnss_feature_bitmap) {
1946 		req.feature_list_valid = 1;
1947 		req.feature_list = ab->hw_params->qmi_cnss_feature_bitmap;
1948 	}
1949 
1950 	/* BRINGUP: here we are piggybacking a lot of stuff using
1951 	 * internal_sleep_clock, should it be split?
1952 	 */
1953 	if (ab->hw_params->internal_sleep_clock) {
1954 		req.nm_modem_valid = 1;
1955 
1956 		/* Notify firmware that this is non-qualcomm platform. */
1957 		req.nm_modem |= HOST_CSTATE_BIT;
1958 
1959 		/* Notify firmware about the sleep clock selection,
1960 		 * nm_modem_bit[1] is used for this purpose. Host driver on
1961 		 * non-qualcomm platforms should select internal sleep
1962 		 * clock.
1963 		 */
1964 		req.nm_modem |= SLEEP_CLOCK_SELECT_INTERNAL_BIT;
1965 		req.nm_modem |= PLATFORM_CAP_PCIE_GLOBAL_RESET;
1966 
1967 		ath12k_host_cap_parse_mlo(&req);
1968 	}
1969 
1970 	ret = qmi_txn_init(&ab->qmi.handle, &txn,
1971 			   qmi_wlanfw_host_cap_resp_msg_v01_ei, &resp);
1972 	if (ret < 0)
1973 		goto out;
1974 
1975 	ret = qmi_send_request(&ab->qmi.handle, NULL, &txn,
1976 			       QMI_WLANFW_HOST_CAP_REQ_V01,
1977 			       QMI_WLANFW_HOST_CAP_REQ_MSG_V01_MAX_LEN,
1978 			       qmi_wlanfw_host_cap_req_msg_v01_ei, &req);
1979 	if (ret < 0) {
1980 		ath12k_warn(ab, "Failed to send host capability request,err = %d\n", ret);
1981 		goto out;
1982 	}
1983 
1984 	ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH12K_QMI_WLANFW_TIMEOUT_MS));
1985 	if (ret < 0)
1986 		goto out;
1987 
1988 	if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
1989 		ath12k_warn(ab, "Host capability request failed, result: %d, err: %d\n",
1990 			    resp.resp.result, resp.resp.error);
1991 		ret = -EINVAL;
1992 		goto out;
1993 	}
1994 
1995 out:
1996 	return ret;
1997 }
1998 
1999 static int ath12k_qmi_fw_ind_register_send(struct ath12k_base *ab)
2000 {
2001 	struct qmi_wlanfw_ind_register_req_msg_v01 *req;
2002 	struct qmi_wlanfw_ind_register_resp_msg_v01 *resp;
2003 	struct qmi_handle *handle = &ab->qmi.handle;
2004 	struct qmi_txn txn;
2005 	int ret;
2006 
2007 	req = kzalloc(sizeof(*req), GFP_KERNEL);
2008 	if (!req)
2009 		return -ENOMEM;
2010 
2011 	resp = kzalloc(sizeof(*resp), GFP_KERNEL);
2012 	if (!resp) {
2013 		ret = -ENOMEM;
2014 		goto resp_out;
2015 	}
2016 
2017 	req->client_id_valid = 1;
2018 	req->client_id = QMI_WLANFW_CLIENT_ID;
2019 	req->fw_ready_enable_valid = 1;
2020 	req->fw_ready_enable = 1;
2021 	req->request_mem_enable_valid = 1;
2022 	req->request_mem_enable = 1;
2023 	req->fw_mem_ready_enable_valid = 1;
2024 	req->fw_mem_ready_enable = 1;
2025 	req->cal_done_enable_valid = 1;
2026 	req->cal_done_enable = 1;
2027 	req->fw_init_done_enable_valid = 1;
2028 	req->fw_init_done_enable = 1;
2029 
2030 	req->pin_connect_result_enable_valid = 0;
2031 	req->pin_connect_result_enable = 0;
2032 
2033 	ret = qmi_txn_init(handle, &txn,
2034 			   qmi_wlanfw_ind_register_resp_msg_v01_ei, resp);
2035 	if (ret < 0)
2036 		goto out;
2037 
2038 	ret = qmi_send_request(&ab->qmi.handle, NULL, &txn,
2039 			       QMI_WLANFW_IND_REGISTER_REQ_V01,
2040 			       QMI_WLANFW_IND_REGISTER_REQ_MSG_V01_MAX_LEN,
2041 			       qmi_wlanfw_ind_register_req_msg_v01_ei, req);
2042 	if (ret < 0) {
2043 		ath12k_warn(ab, "Failed to send indication register request, err = %d\n",
2044 			    ret);
2045 		goto out;
2046 	}
2047 
2048 	ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH12K_QMI_WLANFW_TIMEOUT_MS));
2049 	if (ret < 0) {
2050 		ath12k_warn(ab, "failed to register fw indication %d\n", ret);
2051 		goto out;
2052 	}
2053 
2054 	if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
2055 		ath12k_warn(ab, "FW Ind register request failed, result: %d, err: %d\n",
2056 			    resp->resp.result, resp->resp.error);
2057 		ret = -EINVAL;
2058 		goto out;
2059 	}
2060 
2061 out:
2062 	kfree(resp);
2063 resp_out:
2064 	kfree(req);
2065 	return ret;
2066 }
2067 
2068 static int ath12k_qmi_respond_fw_mem_request(struct ath12k_base *ab)
2069 {
2070 	struct qmi_wlanfw_respond_mem_req_msg_v01 *req;
2071 	struct qmi_wlanfw_respond_mem_resp_msg_v01 resp;
2072 	struct qmi_txn txn = {};
2073 	int ret = 0, i;
2074 	bool delayed;
2075 
2076 	req = kzalloc(sizeof(*req), GFP_KERNEL);
2077 	if (!req)
2078 		return -ENOMEM;
2079 
2080 	memset(&resp, 0, sizeof(resp));
2081 
2082 	/* Some targets by default request a block of big contiguous
2083 	 * DMA memory, it's hard to allocate from kernel. So host returns
2084 	 * failure to firmware and firmware then request multiple blocks of
2085 	 * small chunk size memory.
2086 	 */
2087 	if (ab->qmi.target_mem_delayed) {
2088 		delayed = true;
2089 		ath12k_dbg(ab, ATH12K_DBG_QMI, "qmi delays mem_request %d\n",
2090 			   ab->qmi.mem_seg_count);
2091 		memset(req, 0, sizeof(*req));
2092 	} else {
2093 		delayed = false;
2094 		req->mem_seg_len = ab->qmi.mem_seg_count;
2095 		for (i = 0; i < req->mem_seg_len ; i++) {
2096 			req->mem_seg[i].addr = ab->qmi.target_mem[i].paddr;
2097 			req->mem_seg[i].size = ab->qmi.target_mem[i].size;
2098 			req->mem_seg[i].type = ab->qmi.target_mem[i].type;
2099 			ath12k_dbg(ab, ATH12K_DBG_QMI,
2100 				   "qmi req mem_seg[%d] %pad %u %u\n", i,
2101 				   &ab->qmi.target_mem[i].paddr,
2102 				   ab->qmi.target_mem[i].size,
2103 				   ab->qmi.target_mem[i].type);
2104 		}
2105 	}
2106 
2107 	ret = qmi_txn_init(&ab->qmi.handle, &txn,
2108 			   qmi_wlanfw_respond_mem_resp_msg_v01_ei, &resp);
2109 	if (ret < 0)
2110 		goto out;
2111 
2112 	ret = qmi_send_request(&ab->qmi.handle, NULL, &txn,
2113 			       QMI_WLANFW_RESPOND_MEM_REQ_V01,
2114 			       QMI_WLANFW_RESPOND_MEM_REQ_MSG_V01_MAX_LEN,
2115 			       qmi_wlanfw_respond_mem_req_msg_v01_ei, req);
2116 	if (ret < 0) {
2117 		ath12k_warn(ab, "qmi failed to respond memory request, err = %d\n",
2118 			    ret);
2119 		goto out;
2120 	}
2121 
2122 	ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH12K_QMI_WLANFW_TIMEOUT_MS));
2123 	if (ret < 0) {
2124 		ath12k_warn(ab, "qmi failed memory request, err = %d\n", ret);
2125 		goto out;
2126 	}
2127 
2128 	if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
2129 		/* the error response is expected when
2130 		 * target_mem_delayed is true.
2131 		 */
2132 		if (delayed && resp.resp.error == 0)
2133 			goto out;
2134 
2135 		ath12k_warn(ab, "Respond mem req failed, result: %d, err: %d\n",
2136 			    resp.resp.result, resp.resp.error);
2137 		ret = -EINVAL;
2138 		goto out;
2139 	}
2140 out:
2141 	kfree(req);
2142 	return ret;
2143 }
2144 
2145 static void ath12k_qmi_free_target_mem_chunk(struct ath12k_base *ab)
2146 {
2147 	int i;
2148 
2149 	for (i = 0; i < ab->qmi.mem_seg_count; i++) {
2150 		if (!ab->qmi.target_mem[i].v.addr)
2151 			continue;
2152 		dma_free_coherent(ab->dev,
2153 				  ab->qmi.target_mem[i].size,
2154 				  ab->qmi.target_mem[i].v.addr,
2155 				  ab->qmi.target_mem[i].paddr);
2156 		ab->qmi.target_mem[i].v.addr = NULL;
2157 	}
2158 }
2159 
2160 static int ath12k_qmi_alloc_target_mem_chunk(struct ath12k_base *ab)
2161 {
2162 	int i;
2163 	struct target_mem_chunk *chunk;
2164 
2165 	ab->qmi.target_mem_delayed = false;
2166 
2167 	for (i = 0; i < ab->qmi.mem_seg_count; i++) {
2168 		chunk = &ab->qmi.target_mem[i];
2169 
2170 		/* Allocate memory for the region and the functionality supported
2171 		 * on the host. For the non-supported memory region, host does not
2172 		 * allocate memory, assigns NULL and FW will handle this without crashing.
2173 		 */
2174 		switch (chunk->type) {
2175 		case HOST_DDR_REGION_TYPE:
2176 		case M3_DUMP_REGION_TYPE:
2177 		case PAGEABLE_MEM_REGION_TYPE:
2178 		case CALDB_MEM_REGION_TYPE:
2179 			chunk->v.addr = dma_alloc_coherent(ab->dev,
2180 							   chunk->size,
2181 							   &chunk->paddr,
2182 							   GFP_KERNEL | __GFP_NOWARN);
2183 			if (!chunk->v.addr) {
2184 				if (chunk->size > ATH12K_QMI_MAX_CHUNK_SIZE) {
2185 					ab->qmi.target_mem_delayed = true;
2186 					ath12k_warn(ab,
2187 						    "qmi dma allocation failed (%d B type %u), will try later with small size\n",
2188 						    chunk->size,
2189 						    chunk->type);
2190 					ath12k_qmi_free_target_mem_chunk(ab);
2191 					return 0;
2192 				}
2193 				ath12k_warn(ab, "memory allocation failure for %u size: %d\n",
2194 					    chunk->type, chunk->size);
2195 				return -ENOMEM;
2196 			}
2197 			break;
2198 		default:
2199 			ath12k_warn(ab, "memory type %u not supported\n",
2200 				    chunk->type);
2201 			chunk->paddr = 0;
2202 			chunk->v.addr = NULL;
2203 			break;
2204 		}
2205 	}
2206 	return 0;
2207 }
2208 
2209 static int ath12k_qmi_request_target_cap(struct ath12k_base *ab)
2210 {
2211 	struct qmi_wlanfw_cap_req_msg_v01 req;
2212 	struct qmi_wlanfw_cap_resp_msg_v01 resp;
2213 	struct qmi_txn txn = {};
2214 	unsigned int board_id = ATH12K_BOARD_ID_DEFAULT;
2215 	int ret = 0;
2216 	int r;
2217 	int i;
2218 
2219 	memset(&req, 0, sizeof(req));
2220 	memset(&resp, 0, sizeof(resp));
2221 
2222 	ret = qmi_txn_init(&ab->qmi.handle, &txn,
2223 			   qmi_wlanfw_cap_resp_msg_v01_ei, &resp);
2224 	if (ret < 0)
2225 		goto out;
2226 
2227 	ret = qmi_send_request(&ab->qmi.handle, NULL, &txn,
2228 			       QMI_WLANFW_CAP_REQ_V01,
2229 			       QMI_WLANFW_CAP_REQ_MSG_V01_MAX_LEN,
2230 			       qmi_wlanfw_cap_req_msg_v01_ei, &req);
2231 	if (ret < 0) {
2232 		ath12k_warn(ab, "qmi failed to send target cap request, err = %d\n",
2233 			    ret);
2234 		goto out;
2235 	}
2236 
2237 	ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH12K_QMI_WLANFW_TIMEOUT_MS));
2238 	if (ret < 0) {
2239 		ath12k_warn(ab, "qmi failed target cap request %d\n", ret);
2240 		goto out;
2241 	}
2242 
2243 	if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
2244 		ath12k_warn(ab, "qmi targetcap req failed, result: %d, err: %d\n",
2245 			    resp.resp.result, resp.resp.error);
2246 		ret = -EINVAL;
2247 		goto out;
2248 	}
2249 
2250 	if (resp.chip_info_valid) {
2251 		ab->qmi.target.chip_id = resp.chip_info.chip_id;
2252 		ab->qmi.target.chip_family = resp.chip_info.chip_family;
2253 	}
2254 
2255 	if (resp.board_info_valid)
2256 		ab->qmi.target.board_id = resp.board_info.board_id;
2257 	else
2258 		ab->qmi.target.board_id = board_id;
2259 
2260 	if (resp.soc_info_valid)
2261 		ab->qmi.target.soc_id = resp.soc_info.soc_id;
2262 
2263 	if (resp.fw_version_info_valid) {
2264 		ab->qmi.target.fw_version = resp.fw_version_info.fw_version;
2265 		strscpy(ab->qmi.target.fw_build_timestamp,
2266 			resp.fw_version_info.fw_build_timestamp,
2267 			sizeof(ab->qmi.target.fw_build_timestamp));
2268 	}
2269 
2270 	if (resp.fw_build_id_valid)
2271 		strscpy(ab->qmi.target.fw_build_id, resp.fw_build_id,
2272 			sizeof(ab->qmi.target.fw_build_id));
2273 
2274 	if (resp.dev_mem_info_valid) {
2275 		for (i = 0; i < ATH12K_QMI_WLFW_MAX_DEV_MEM_NUM_V01; i++) {
2276 			ab->qmi.dev_mem[i].start =
2277 				resp.dev_mem[i].start;
2278 			ab->qmi.dev_mem[i].size =
2279 				resp.dev_mem[i].size;
2280 			ath12k_dbg(ab, ATH12K_DBG_QMI,
2281 				   "devmem [%d] start ox%llx size %llu\n", i,
2282 				   ab->qmi.dev_mem[i].start,
2283 				   ab->qmi.dev_mem[i].size);
2284 		}
2285 	}
2286 
2287 	if (resp.eeprom_caldata_read_timeout_valid) {
2288 		ab->qmi.target.eeprom_caldata = resp.eeprom_caldata_read_timeout;
2289 		ath12k_dbg(ab, ATH12K_DBG_QMI, "qmi cal data supported from eeprom\n");
2290 	}
2291 
2292 	ath12k_info(ab, "chip_id 0x%x chip_family 0x%x board_id 0x%x soc_id 0x%x\n",
2293 		    ab->qmi.target.chip_id, ab->qmi.target.chip_family,
2294 		    ab->qmi.target.board_id, ab->qmi.target.soc_id);
2295 
2296 	ath12k_info(ab, "fw_version 0x%x fw_build_timestamp %s fw_build_id %s",
2297 		    ab->qmi.target.fw_version,
2298 		    ab->qmi.target.fw_build_timestamp,
2299 		    ab->qmi.target.fw_build_id);
2300 
2301 	r = ath12k_core_check_smbios(ab);
2302 	if (r)
2303 		ath12k_dbg(ab, ATH12K_DBG_QMI, "SMBIOS bdf variant name not set.\n");
2304 
2305 out:
2306 	return ret;
2307 }
2308 
2309 static int ath12k_qmi_load_file_target_mem(struct ath12k_base *ab,
2310 					   const u8 *data, u32 len, u8 type)
2311 {
2312 	struct qmi_wlanfw_bdf_download_req_msg_v01 *req;
2313 	struct qmi_wlanfw_bdf_download_resp_msg_v01 resp;
2314 	struct qmi_txn txn = {};
2315 	const u8 *temp = data;
2316 	int ret;
2317 	u32 remaining = len;
2318 
2319 	req = kzalloc(sizeof(*req), GFP_KERNEL);
2320 	if (!req)
2321 		return -ENOMEM;
2322 	memset(&resp, 0, sizeof(resp));
2323 
2324 	while (remaining) {
2325 		req->valid = 1;
2326 		req->file_id_valid = 1;
2327 		req->file_id = ab->qmi.target.board_id;
2328 		req->total_size_valid = 1;
2329 		req->total_size = remaining;
2330 		req->seg_id_valid = 1;
2331 		req->data_valid = 1;
2332 		req->bdf_type = type;
2333 		req->bdf_type_valid = 1;
2334 		req->end_valid = 1;
2335 		req->end = 0;
2336 
2337 		if (remaining > QMI_WLANFW_MAX_DATA_SIZE_V01) {
2338 			req->data_len = QMI_WLANFW_MAX_DATA_SIZE_V01;
2339 		} else {
2340 			req->data_len = remaining;
2341 			req->end = 1;
2342 		}
2343 
2344 		if (type == ATH12K_QMI_FILE_TYPE_EEPROM) {
2345 			req->data_valid = 0;
2346 			req->end = 1;
2347 			req->data_len = ATH12K_QMI_MAX_BDF_FILE_NAME_SIZE;
2348 		} else {
2349 			memcpy(req->data, temp, req->data_len);
2350 		}
2351 
2352 		ret = qmi_txn_init(&ab->qmi.handle, &txn,
2353 				   qmi_wlanfw_bdf_download_resp_msg_v01_ei,
2354 				   &resp);
2355 		if (ret < 0)
2356 			goto out;
2357 
2358 		ath12k_dbg(ab, ATH12K_DBG_QMI, "qmi bdf download req fixed addr type %d\n",
2359 			   type);
2360 
2361 		ret = qmi_send_request(&ab->qmi.handle, NULL, &txn,
2362 				       QMI_WLANFW_BDF_DOWNLOAD_REQ_V01,
2363 				       QMI_WLANFW_BDF_DOWNLOAD_REQ_MSG_V01_MAX_LEN,
2364 				       qmi_wlanfw_bdf_download_req_msg_v01_ei, req);
2365 		if (ret < 0) {
2366 			qmi_txn_cancel(&txn);
2367 			goto out;
2368 		}
2369 
2370 		ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH12K_QMI_WLANFW_TIMEOUT_MS));
2371 		if (ret < 0)
2372 			goto out;
2373 
2374 		if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
2375 			ath12k_warn(ab, "qmi BDF download failed, result: %d, err: %d\n",
2376 				    resp.resp.result, resp.resp.error);
2377 			ret = -EINVAL;
2378 			goto out;
2379 		}
2380 
2381 		if (type == ATH12K_QMI_FILE_TYPE_EEPROM) {
2382 			remaining = 0;
2383 		} else {
2384 			remaining -= req->data_len;
2385 			temp += req->data_len;
2386 			req->seg_id++;
2387 			ath12k_dbg(ab, ATH12K_DBG_QMI,
2388 				   "qmi bdf download request remaining %i\n",
2389 				   remaining);
2390 		}
2391 	}
2392 
2393 out:
2394 	kfree(req);
2395 	return ret;
2396 }
2397 
2398 static int ath12k_qmi_load_bdf_qmi(struct ath12k_base *ab,
2399 				   enum ath12k_qmi_bdf_type type)
2400 {
2401 	struct device *dev = ab->dev;
2402 	char filename[ATH12K_QMI_MAX_BDF_FILE_NAME_SIZE];
2403 	const struct firmware *fw_entry;
2404 	struct ath12k_board_data bd;
2405 	u32 fw_size, file_type;
2406 	int ret = 0;
2407 	const u8 *tmp;
2408 
2409 	memset(&bd, 0, sizeof(bd));
2410 
2411 	switch (type) {
2412 	case ATH12K_QMI_BDF_TYPE_ELF:
2413 		ret = ath12k_core_fetch_bdf(ab, &bd);
2414 		if (ret) {
2415 			ath12k_warn(ab, "qmi failed to load bdf:\n");
2416 			goto out;
2417 		}
2418 
2419 		if (bd.len >= SELFMAG && memcmp(bd.data, ELFMAG, SELFMAG) == 0)
2420 			type = ATH12K_QMI_BDF_TYPE_ELF;
2421 		else
2422 			type = ATH12K_QMI_BDF_TYPE_BIN;
2423 
2424 		break;
2425 	case ATH12K_QMI_BDF_TYPE_REGDB:
2426 		ret = ath12k_core_fetch_board_data_api_1(ab, &bd,
2427 							 ATH12K_REGDB_FILE_NAME);
2428 		if (ret) {
2429 			ath12k_warn(ab, "qmi failed to load regdb bin:\n");
2430 			goto out;
2431 		}
2432 		break;
2433 	case ATH12K_QMI_BDF_TYPE_CALIBRATION:
2434 
2435 		if (ab->qmi.target.eeprom_caldata) {
2436 			file_type = ATH12K_QMI_FILE_TYPE_EEPROM;
2437 			tmp = filename;
2438 			fw_size = ATH12K_QMI_MAX_BDF_FILE_NAME_SIZE;
2439 		} else {
2440 			file_type = ATH12K_QMI_FILE_TYPE_CALDATA;
2441 
2442 			/* cal-<bus>-<id>.bin */
2443 			snprintf(filename, sizeof(filename), "cal-%s-%s.bin",
2444 				 ath12k_bus_str(ab->hif.bus), dev_name(dev));
2445 			fw_entry = ath12k_core_firmware_request(ab, filename);
2446 			if (!IS_ERR(fw_entry))
2447 				goto success;
2448 
2449 			fw_entry = ath12k_core_firmware_request(ab,
2450 								ATH12K_DEFAULT_CAL_FILE);
2451 			if (IS_ERR(fw_entry)) {
2452 				ret = PTR_ERR(fw_entry);
2453 				ath12k_warn(ab,
2454 					    "qmi failed to load CAL data file:%s\n",
2455 					    filename);
2456 				goto out;
2457 			}
2458 
2459 success:
2460 			fw_size = min_t(u32, ab->hw_params->fw.board_size,
2461 					fw_entry->size);
2462 			tmp = fw_entry->data;
2463 		}
2464 		ret = ath12k_qmi_load_file_target_mem(ab, tmp, fw_size, file_type);
2465 		if (ret < 0) {
2466 			ath12k_warn(ab, "qmi failed to load caldata\n");
2467 			goto out_qmi_cal;
2468 		}
2469 
2470 		ath12k_dbg(ab, ATH12K_DBG_QMI, "qmi caldata downloaded: type: %u\n",
2471 			   file_type);
2472 
2473 out_qmi_cal:
2474 		if (!ab->qmi.target.eeprom_caldata)
2475 			release_firmware(fw_entry);
2476 		return ret;
2477 	default:
2478 		ath12k_warn(ab, "unknown file type for load %d", type);
2479 		goto out;
2480 	}
2481 
2482 	ath12k_dbg(ab, ATH12K_DBG_QMI, "qmi bdf_type %d\n", type);
2483 
2484 	fw_size = min_t(u32, ab->hw_params->fw.board_size, bd.len);
2485 
2486 	ret = ath12k_qmi_load_file_target_mem(ab, bd.data, fw_size, type);
2487 	if (ret < 0)
2488 		ath12k_warn(ab, "qmi failed to load bdf file\n");
2489 
2490 out:
2491 	ath12k_core_free_bdf(ab, &bd);
2492 	ath12k_dbg(ab, ATH12K_DBG_QMI, "qmi BDF download sequence completed\n");
2493 
2494 	return ret;
2495 }
2496 
2497 static int ath12k_qmi_m3_load(struct ath12k_base *ab)
2498 {
2499 	struct m3_mem_region *m3_mem = &ab->qmi.m3_mem;
2500 	const struct firmware *fw;
2501 	char path[100];
2502 	int ret;
2503 
2504 	if (m3_mem->vaddr || m3_mem->size)
2505 		return 0;
2506 
2507 	fw = ath12k_core_firmware_request(ab, ATH12K_M3_FILE);
2508 	if (IS_ERR(fw)) {
2509 		ret = PTR_ERR(fw);
2510 		ath12k_core_create_firmware_path(ab, ATH12K_M3_FILE,
2511 						 path, sizeof(path));
2512 		ath12k_err(ab, "failed to load %s: %d\n", path, ret);
2513 		return ret;
2514 	}
2515 
2516 	m3_mem->vaddr = dma_alloc_coherent(ab->dev,
2517 					   fw->size, &m3_mem->paddr,
2518 					   GFP_KERNEL);
2519 	if (!m3_mem->vaddr) {
2520 		ath12k_err(ab, "failed to allocate memory for M3 with size %zu\n",
2521 			   fw->size);
2522 		release_firmware(fw);
2523 		return -ENOMEM;
2524 	}
2525 
2526 	memcpy(m3_mem->vaddr, fw->data, fw->size);
2527 	m3_mem->size = fw->size;
2528 	release_firmware(fw);
2529 
2530 	return 0;
2531 }
2532 
2533 static void ath12k_qmi_m3_free(struct ath12k_base *ab)
2534 {
2535 	struct m3_mem_region *m3_mem = &ab->qmi.m3_mem;
2536 
2537 	if (!m3_mem->vaddr)
2538 		return;
2539 
2540 	dma_free_coherent(ab->dev, m3_mem->size,
2541 			  m3_mem->vaddr, m3_mem->paddr);
2542 	m3_mem->vaddr = NULL;
2543 	m3_mem->size = 0;
2544 }
2545 
2546 static int ath12k_qmi_wlanfw_m3_info_send(struct ath12k_base *ab)
2547 {
2548 	struct m3_mem_region *m3_mem = &ab->qmi.m3_mem;
2549 	struct qmi_wlanfw_m3_info_req_msg_v01 req;
2550 	struct qmi_wlanfw_m3_info_resp_msg_v01 resp;
2551 	struct qmi_txn txn = {};
2552 	int ret = 0;
2553 
2554 	memset(&req, 0, sizeof(req));
2555 	memset(&resp, 0, sizeof(resp));
2556 
2557 	ret = ath12k_qmi_m3_load(ab);
2558 	if (ret) {
2559 		ath12k_err(ab, "failed to load m3 firmware: %d", ret);
2560 		return ret;
2561 	}
2562 
2563 	req.addr = m3_mem->paddr;
2564 	req.size = m3_mem->size;
2565 
2566 	ret = qmi_txn_init(&ab->qmi.handle, &txn,
2567 			   qmi_wlanfw_m3_info_resp_msg_v01_ei, &resp);
2568 	if (ret < 0)
2569 		goto out;
2570 
2571 	ret = qmi_send_request(&ab->qmi.handle, NULL, &txn,
2572 			       QMI_WLANFW_M3_INFO_REQ_V01,
2573 			       QMI_WLANFW_M3_INFO_REQ_MSG_V01_MAX_MSG_LEN,
2574 			       qmi_wlanfw_m3_info_req_msg_v01_ei, &req);
2575 	if (ret < 0) {
2576 		ath12k_warn(ab, "qmi failed to send M3 information request, err = %d\n",
2577 			    ret);
2578 		goto out;
2579 	}
2580 
2581 	ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH12K_QMI_WLANFW_TIMEOUT_MS));
2582 	if (ret < 0) {
2583 		ath12k_warn(ab, "qmi failed M3 information request %d\n", ret);
2584 		goto out;
2585 	}
2586 
2587 	if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
2588 		ath12k_warn(ab, "qmi M3 info request failed, result: %d, err: %d\n",
2589 			    resp.resp.result, resp.resp.error);
2590 		ret = -EINVAL;
2591 		goto out;
2592 	}
2593 out:
2594 	return ret;
2595 }
2596 
2597 static int ath12k_qmi_wlanfw_mode_send(struct ath12k_base *ab,
2598 				       u32 mode)
2599 {
2600 	struct qmi_wlanfw_wlan_mode_req_msg_v01 req;
2601 	struct qmi_wlanfw_wlan_mode_resp_msg_v01 resp;
2602 	struct qmi_txn txn = {};
2603 	int ret = 0;
2604 
2605 	memset(&req, 0, sizeof(req));
2606 	memset(&resp, 0, sizeof(resp));
2607 
2608 	req.mode = mode;
2609 	req.hw_debug_valid = 1;
2610 	req.hw_debug = 0;
2611 
2612 	ret = qmi_txn_init(&ab->qmi.handle, &txn,
2613 			   qmi_wlanfw_wlan_mode_resp_msg_v01_ei, &resp);
2614 	if (ret < 0)
2615 		goto out;
2616 
2617 	ret = qmi_send_request(&ab->qmi.handle, NULL, &txn,
2618 			       QMI_WLANFW_WLAN_MODE_REQ_V01,
2619 			       QMI_WLANFW_WLAN_MODE_REQ_MSG_V01_MAX_LEN,
2620 			       qmi_wlanfw_wlan_mode_req_msg_v01_ei, &req);
2621 	if (ret < 0) {
2622 		ath12k_warn(ab, "qmi failed to send mode request, mode: %d, err = %d\n",
2623 			    mode, ret);
2624 		goto out;
2625 	}
2626 
2627 	ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH12K_QMI_WLANFW_TIMEOUT_MS));
2628 	if (ret < 0) {
2629 		if (mode == ATH12K_FIRMWARE_MODE_OFF && ret == -ENETRESET) {
2630 			ath12k_warn(ab, "WLFW service is dis-connected\n");
2631 			return 0;
2632 		}
2633 		ath12k_warn(ab, "qmi failed set mode request, mode: %d, err = %d\n",
2634 			    mode, ret);
2635 		goto out;
2636 	}
2637 
2638 	if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
2639 		ath12k_warn(ab, "Mode request failed, mode: %d, result: %d err: %d\n",
2640 			    mode, resp.resp.result, resp.resp.error);
2641 		ret = -EINVAL;
2642 		goto out;
2643 	}
2644 
2645 out:
2646 	return ret;
2647 }
2648 
2649 static int ath12k_qmi_wlanfw_wlan_cfg_send(struct ath12k_base *ab)
2650 {
2651 	struct qmi_wlanfw_wlan_cfg_req_msg_v01 *req;
2652 	struct qmi_wlanfw_wlan_cfg_resp_msg_v01 resp;
2653 	struct ce_pipe_config *ce_cfg;
2654 	struct service_to_pipe *svc_cfg;
2655 	struct qmi_txn txn = {};
2656 	int ret = 0, pipe_num;
2657 
2658 	ce_cfg	= (struct ce_pipe_config *)ab->qmi.ce_cfg.tgt_ce;
2659 	svc_cfg	= (struct service_to_pipe *)ab->qmi.ce_cfg.svc_to_ce_map;
2660 
2661 	req = kzalloc(sizeof(*req), GFP_KERNEL);
2662 	if (!req)
2663 		return -ENOMEM;
2664 
2665 	memset(&resp, 0, sizeof(resp));
2666 
2667 	req->host_version_valid = 1;
2668 	strscpy(req->host_version, ATH12K_HOST_VERSION_STRING,
2669 		sizeof(req->host_version));
2670 
2671 	req->tgt_cfg_valid = 1;
2672 	/* This is number of CE configs */
2673 	req->tgt_cfg_len = ab->qmi.ce_cfg.tgt_ce_len;
2674 	for (pipe_num = 0; pipe_num < req->tgt_cfg_len ; pipe_num++) {
2675 		req->tgt_cfg[pipe_num].pipe_num = ce_cfg[pipe_num].pipenum;
2676 		req->tgt_cfg[pipe_num].pipe_dir = ce_cfg[pipe_num].pipedir;
2677 		req->tgt_cfg[pipe_num].nentries = ce_cfg[pipe_num].nentries;
2678 		req->tgt_cfg[pipe_num].nbytes_max = ce_cfg[pipe_num].nbytes_max;
2679 		req->tgt_cfg[pipe_num].flags = ce_cfg[pipe_num].flags;
2680 	}
2681 
2682 	req->svc_cfg_valid = 1;
2683 	/* This is number of Service/CE configs */
2684 	req->svc_cfg_len = ab->qmi.ce_cfg.svc_to_ce_map_len;
2685 	for (pipe_num = 0; pipe_num < req->svc_cfg_len; pipe_num++) {
2686 		req->svc_cfg[pipe_num].service_id = svc_cfg[pipe_num].service_id;
2687 		req->svc_cfg[pipe_num].pipe_dir = svc_cfg[pipe_num].pipedir;
2688 		req->svc_cfg[pipe_num].pipe_num = svc_cfg[pipe_num].pipenum;
2689 	}
2690 
2691 	/* set shadow v3 configuration */
2692 	if (ab->hw_params->supports_shadow_regs) {
2693 		req->shadow_reg_v3_valid = 1;
2694 		req->shadow_reg_v3_len = min_t(u32,
2695 					       ab->qmi.ce_cfg.shadow_reg_v3_len,
2696 					       QMI_WLANFW_MAX_NUM_SHADOW_REG_V3_V01);
2697 		memcpy(&req->shadow_reg_v3, ab->qmi.ce_cfg.shadow_reg_v3,
2698 		       sizeof(u32) * req->shadow_reg_v3_len);
2699 	} else {
2700 		req->shadow_reg_v3_valid = 0;
2701 	}
2702 
2703 	ret = qmi_txn_init(&ab->qmi.handle, &txn,
2704 			   qmi_wlanfw_wlan_cfg_resp_msg_v01_ei, &resp);
2705 	if (ret < 0)
2706 		goto out;
2707 
2708 	ret = qmi_send_request(&ab->qmi.handle, NULL, &txn,
2709 			       QMI_WLANFW_WLAN_CFG_REQ_V01,
2710 			       QMI_WLANFW_WLAN_CFG_REQ_MSG_V01_MAX_LEN,
2711 			       qmi_wlanfw_wlan_cfg_req_msg_v01_ei, req);
2712 	if (ret < 0) {
2713 		ath12k_warn(ab, "qmi failed to send wlan config request, err = %d\n",
2714 			    ret);
2715 		goto out;
2716 	}
2717 
2718 	ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH12K_QMI_WLANFW_TIMEOUT_MS));
2719 	if (ret < 0) {
2720 		ath12k_warn(ab, "qmi failed wlan config request, err = %d\n", ret);
2721 		goto out;
2722 	}
2723 
2724 	if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
2725 		ath12k_warn(ab, "qmi wlan config request failed, result: %d, err: %d\n",
2726 			    resp.resp.result, resp.resp.error);
2727 		ret = -EINVAL;
2728 		goto out;
2729 	}
2730 
2731 out:
2732 	kfree(req);
2733 	return ret;
2734 }
2735 
2736 void ath12k_qmi_firmware_stop(struct ath12k_base *ab)
2737 {
2738 	int ret;
2739 
2740 	ret = ath12k_qmi_wlanfw_mode_send(ab, ATH12K_FIRMWARE_MODE_OFF);
2741 	if (ret < 0) {
2742 		ath12k_warn(ab, "qmi failed to send wlan mode off\n");
2743 		return;
2744 	}
2745 }
2746 
2747 int ath12k_qmi_firmware_start(struct ath12k_base *ab,
2748 			      u32 mode)
2749 {
2750 	int ret;
2751 
2752 	ret = ath12k_qmi_wlanfw_wlan_cfg_send(ab);
2753 	if (ret < 0) {
2754 		ath12k_warn(ab, "qmi failed to send wlan cfg:%d\n", ret);
2755 		return ret;
2756 	}
2757 
2758 	ret = ath12k_qmi_wlanfw_mode_send(ab, mode);
2759 	if (ret < 0) {
2760 		ath12k_warn(ab, "qmi failed to send wlan fw mode:%d\n", ret);
2761 		return ret;
2762 	}
2763 
2764 	return 0;
2765 }
2766 
2767 static int
2768 ath12k_qmi_driver_event_post(struct ath12k_qmi *qmi,
2769 			     enum ath12k_qmi_event_type type,
2770 			     void *data)
2771 {
2772 	struct ath12k_qmi_driver_event *event;
2773 
2774 	event = kzalloc(sizeof(*event), GFP_ATOMIC);
2775 	if (!event)
2776 		return -ENOMEM;
2777 
2778 	event->type = type;
2779 	event->data = data;
2780 
2781 	spin_lock(&qmi->event_lock);
2782 	list_add_tail(&event->list, &qmi->event_list);
2783 	spin_unlock(&qmi->event_lock);
2784 
2785 	queue_work(qmi->event_wq, &qmi->event_work);
2786 
2787 	return 0;
2788 }
2789 
2790 static int ath12k_qmi_event_server_arrive(struct ath12k_qmi *qmi)
2791 {
2792 	struct ath12k_base *ab = qmi->ab;
2793 	int ret;
2794 
2795 	ret = ath12k_qmi_fw_ind_register_send(ab);
2796 	if (ret < 0) {
2797 		ath12k_warn(ab, "qmi failed to send FW indication QMI:%d\n", ret);
2798 		return ret;
2799 	}
2800 
2801 	ret = ath12k_qmi_host_cap_send(ab);
2802 	if (ret < 0) {
2803 		ath12k_warn(ab, "qmi failed to send host cap QMI:%d\n", ret);
2804 		return ret;
2805 	}
2806 
2807 	return ret;
2808 }
2809 
2810 static int ath12k_qmi_event_mem_request(struct ath12k_qmi *qmi)
2811 {
2812 	struct ath12k_base *ab = qmi->ab;
2813 	int ret;
2814 
2815 	ret = ath12k_qmi_respond_fw_mem_request(ab);
2816 	if (ret < 0) {
2817 		ath12k_warn(ab, "qmi failed to respond fw mem req:%d\n", ret);
2818 		return ret;
2819 	}
2820 
2821 	return ret;
2822 }
2823 
2824 static int ath12k_qmi_event_load_bdf(struct ath12k_qmi *qmi)
2825 {
2826 	struct ath12k_base *ab = qmi->ab;
2827 	int ret;
2828 
2829 	ret = ath12k_qmi_request_target_cap(ab);
2830 	if (ret < 0) {
2831 		ath12k_warn(ab, "qmi failed to req target capabilities:%d\n", ret);
2832 		return ret;
2833 	}
2834 
2835 	ret = ath12k_qmi_load_bdf_qmi(ab, ATH12K_QMI_BDF_TYPE_REGDB);
2836 	if (ret < 0) {
2837 		ath12k_warn(ab, "qmi failed to load regdb file:%d\n", ret);
2838 		return ret;
2839 	}
2840 
2841 	ret = ath12k_qmi_load_bdf_qmi(ab, ATH12K_QMI_BDF_TYPE_ELF);
2842 	if (ret < 0) {
2843 		ath12k_warn(ab, "qmi failed to load board data file:%d\n", ret);
2844 		return ret;
2845 	}
2846 
2847 	if (ab->hw_params->download_calib) {
2848 		ret = ath12k_qmi_load_bdf_qmi(ab, ATH12K_QMI_BDF_TYPE_CALIBRATION);
2849 		if (ret < 0)
2850 			ath12k_warn(ab, "qmi failed to load calibrated data :%d\n", ret);
2851 	}
2852 
2853 	ret = ath12k_qmi_wlanfw_m3_info_send(ab);
2854 	if (ret < 0) {
2855 		ath12k_warn(ab, "qmi failed to send m3 info req:%d\n", ret);
2856 		return ret;
2857 	}
2858 
2859 	return ret;
2860 }
2861 
2862 static void ath12k_qmi_msg_mem_request_cb(struct qmi_handle *qmi_hdl,
2863 					  struct sockaddr_qrtr *sq,
2864 					  struct qmi_txn *txn,
2865 					  const void *data)
2866 {
2867 	struct ath12k_qmi *qmi = container_of(qmi_hdl, struct ath12k_qmi, handle);
2868 	struct ath12k_base *ab = qmi->ab;
2869 	const struct qmi_wlanfw_request_mem_ind_msg_v01 *msg = data;
2870 	int i, ret;
2871 
2872 	ath12k_dbg(ab, ATH12K_DBG_QMI, "qmi firmware request memory request\n");
2873 
2874 	if (msg->mem_seg_len == 0 ||
2875 	    msg->mem_seg_len > ATH12K_QMI_WLANFW_MAX_NUM_MEM_SEG_V01)
2876 		ath12k_warn(ab, "Invalid memory segment length: %u\n",
2877 			    msg->mem_seg_len);
2878 
2879 	ab->qmi.mem_seg_count = msg->mem_seg_len;
2880 
2881 	for (i = 0; i < qmi->mem_seg_count ; i++) {
2882 		ab->qmi.target_mem[i].type = msg->mem_seg[i].type;
2883 		ab->qmi.target_mem[i].size = msg->mem_seg[i].size;
2884 		ath12k_dbg(ab, ATH12K_DBG_QMI, "qmi mem seg type %d size %d\n",
2885 			   msg->mem_seg[i].type, msg->mem_seg[i].size);
2886 	}
2887 
2888 	ret = ath12k_qmi_alloc_target_mem_chunk(ab);
2889 	if (ret) {
2890 		ath12k_warn(ab, "qmi failed to alloc target memory: %d\n",
2891 			    ret);
2892 		return;
2893 	}
2894 
2895 	ath12k_qmi_driver_event_post(qmi, ATH12K_QMI_EVENT_REQUEST_MEM, NULL);
2896 }
2897 
2898 static void ath12k_qmi_msg_mem_ready_cb(struct qmi_handle *qmi_hdl,
2899 					struct sockaddr_qrtr *sq,
2900 					struct qmi_txn *txn,
2901 					const void *decoded)
2902 {
2903 	struct ath12k_qmi *qmi = container_of(qmi_hdl, struct ath12k_qmi, handle);
2904 	struct ath12k_base *ab = qmi->ab;
2905 
2906 	ath12k_dbg(ab, ATH12K_DBG_QMI, "qmi firmware memory ready indication\n");
2907 	ath12k_qmi_driver_event_post(qmi, ATH12K_QMI_EVENT_FW_MEM_READY, NULL);
2908 }
2909 
2910 static void ath12k_qmi_msg_fw_ready_cb(struct qmi_handle *qmi_hdl,
2911 				       struct sockaddr_qrtr *sq,
2912 				       struct qmi_txn *txn,
2913 				       const void *decoded)
2914 {
2915 	struct ath12k_qmi *qmi = container_of(qmi_hdl, struct ath12k_qmi, handle);
2916 	struct ath12k_base *ab = qmi->ab;
2917 
2918 	ath12k_dbg(ab, ATH12K_DBG_QMI, "qmi firmware ready\n");
2919 	ath12k_qmi_driver_event_post(qmi, ATH12K_QMI_EVENT_FW_READY, NULL);
2920 }
2921 
2922 static const struct qmi_msg_handler ath12k_qmi_msg_handlers[] = {
2923 	{
2924 		.type = QMI_INDICATION,
2925 		.msg_id = QMI_WLFW_REQUEST_MEM_IND_V01,
2926 		.ei = qmi_wlanfw_request_mem_ind_msg_v01_ei,
2927 		.decoded_size = sizeof(struct qmi_wlanfw_request_mem_ind_msg_v01),
2928 		.fn = ath12k_qmi_msg_mem_request_cb,
2929 	},
2930 	{
2931 		.type = QMI_INDICATION,
2932 		.msg_id = QMI_WLFW_FW_MEM_READY_IND_V01,
2933 		.ei = qmi_wlanfw_mem_ready_ind_msg_v01_ei,
2934 		.decoded_size = sizeof(struct qmi_wlanfw_fw_mem_ready_ind_msg_v01),
2935 		.fn = ath12k_qmi_msg_mem_ready_cb,
2936 	},
2937 	{
2938 		.type = QMI_INDICATION,
2939 		.msg_id = QMI_WLFW_FW_READY_IND_V01,
2940 		.ei = qmi_wlanfw_fw_ready_ind_msg_v01_ei,
2941 		.decoded_size = sizeof(struct qmi_wlanfw_fw_ready_ind_msg_v01),
2942 		.fn = ath12k_qmi_msg_fw_ready_cb,
2943 	},
2944 };
2945 
2946 static int ath12k_qmi_ops_new_server(struct qmi_handle *qmi_hdl,
2947 				     struct qmi_service *service)
2948 {
2949 	struct ath12k_qmi *qmi = container_of(qmi_hdl, struct ath12k_qmi, handle);
2950 	struct ath12k_base *ab = qmi->ab;
2951 	struct sockaddr_qrtr *sq = &qmi->sq;
2952 	int ret;
2953 
2954 	sq->sq_family = AF_QIPCRTR;
2955 	sq->sq_node = service->node;
2956 	sq->sq_port = service->port;
2957 
2958 	ret = kernel_connect(qmi_hdl->sock, (struct sockaddr *)sq,
2959 			     sizeof(*sq), 0);
2960 	if (ret) {
2961 		ath12k_warn(ab, "qmi failed to connect to remote service %d\n", ret);
2962 		return ret;
2963 	}
2964 
2965 	ath12k_dbg(ab, ATH12K_DBG_QMI, "qmi wifi fw qmi service connected\n");
2966 	ath12k_qmi_driver_event_post(qmi, ATH12K_QMI_EVENT_SERVER_ARRIVE, NULL);
2967 
2968 	return ret;
2969 }
2970 
2971 static void ath12k_qmi_ops_del_server(struct qmi_handle *qmi_hdl,
2972 				      struct qmi_service *service)
2973 {
2974 	struct ath12k_qmi *qmi = container_of(qmi_hdl, struct ath12k_qmi, handle);
2975 	struct ath12k_base *ab = qmi->ab;
2976 
2977 	ath12k_dbg(ab, ATH12K_DBG_QMI, "qmi wifi fw del server\n");
2978 	ath12k_qmi_driver_event_post(qmi, ATH12K_QMI_EVENT_SERVER_EXIT, NULL);
2979 }
2980 
2981 static const struct qmi_ops ath12k_qmi_ops = {
2982 	.new_server = ath12k_qmi_ops_new_server,
2983 	.del_server = ath12k_qmi_ops_del_server,
2984 };
2985 
2986 static void ath12k_qmi_driver_event_work(struct work_struct *work)
2987 {
2988 	struct ath12k_qmi *qmi = container_of(work, struct ath12k_qmi,
2989 					      event_work);
2990 	struct ath12k_qmi_driver_event *event;
2991 	struct ath12k_base *ab = qmi->ab;
2992 	int ret;
2993 
2994 	spin_lock(&qmi->event_lock);
2995 	while (!list_empty(&qmi->event_list)) {
2996 		event = list_first_entry(&qmi->event_list,
2997 					 struct ath12k_qmi_driver_event, list);
2998 		list_del(&event->list);
2999 		spin_unlock(&qmi->event_lock);
3000 
3001 		if (test_bit(ATH12K_FLAG_UNREGISTERING, &ab->dev_flags))
3002 			goto skip;
3003 
3004 		switch (event->type) {
3005 		case ATH12K_QMI_EVENT_SERVER_ARRIVE:
3006 			ret = ath12k_qmi_event_server_arrive(qmi);
3007 			if (ret < 0)
3008 				set_bit(ATH12K_FLAG_QMI_FAIL, &ab->dev_flags);
3009 			break;
3010 		case ATH12K_QMI_EVENT_SERVER_EXIT:
3011 			set_bit(ATH12K_FLAG_CRASH_FLUSH, &ab->dev_flags);
3012 			set_bit(ATH12K_FLAG_RECOVERY, &ab->dev_flags);
3013 			break;
3014 		case ATH12K_QMI_EVENT_REQUEST_MEM:
3015 			ret = ath12k_qmi_event_mem_request(qmi);
3016 			if (ret < 0)
3017 				set_bit(ATH12K_FLAG_QMI_FAIL, &ab->dev_flags);
3018 			break;
3019 		case ATH12K_QMI_EVENT_FW_MEM_READY:
3020 			ret = ath12k_qmi_event_load_bdf(qmi);
3021 			if (ret < 0)
3022 				set_bit(ATH12K_FLAG_QMI_FAIL, &ab->dev_flags);
3023 			break;
3024 		case ATH12K_QMI_EVENT_FW_READY:
3025 			clear_bit(ATH12K_FLAG_QMI_FAIL, &ab->dev_flags);
3026 			if (test_bit(ATH12K_FLAG_REGISTERED, &ab->dev_flags)) {
3027 				ath12k_hal_dump_srng_stats(ab);
3028 				queue_work(ab->workqueue, &ab->restart_work);
3029 				break;
3030 			}
3031 
3032 			clear_bit(ATH12K_FLAG_CRASH_FLUSH,
3033 				  &ab->dev_flags);
3034 			clear_bit(ATH12K_FLAG_RECOVERY, &ab->dev_flags);
3035 			ath12k_core_qmi_firmware_ready(ab);
3036 			set_bit(ATH12K_FLAG_REGISTERED, &ab->dev_flags);
3037 
3038 			break;
3039 		default:
3040 			ath12k_warn(ab, "invalid event type: %d", event->type);
3041 			break;
3042 		}
3043 
3044 skip:
3045 		kfree(event);
3046 		spin_lock(&qmi->event_lock);
3047 	}
3048 	spin_unlock(&qmi->event_lock);
3049 }
3050 
3051 int ath12k_qmi_init_service(struct ath12k_base *ab)
3052 {
3053 	int ret;
3054 
3055 	memset(&ab->qmi.target, 0, sizeof(struct target_info));
3056 	memset(&ab->qmi.target_mem, 0, sizeof(struct target_mem_chunk));
3057 	ab->qmi.ab = ab;
3058 
3059 	ab->qmi.target_mem_mode = ATH12K_QMI_TARGET_MEM_MODE_DEFAULT;
3060 	ret = qmi_handle_init(&ab->qmi.handle, ATH12K_QMI_RESP_LEN_MAX,
3061 			      &ath12k_qmi_ops, ath12k_qmi_msg_handlers);
3062 	if (ret < 0) {
3063 		ath12k_warn(ab, "failed to initialize qmi handle\n");
3064 		return ret;
3065 	}
3066 
3067 	ab->qmi.event_wq = alloc_ordered_workqueue("ath12k_qmi_driver_event", 0);
3068 	if (!ab->qmi.event_wq) {
3069 		ath12k_err(ab, "failed to allocate workqueue\n");
3070 		return -EFAULT;
3071 	}
3072 
3073 	INIT_LIST_HEAD(&ab->qmi.event_list);
3074 	spin_lock_init(&ab->qmi.event_lock);
3075 	INIT_WORK(&ab->qmi.event_work, ath12k_qmi_driver_event_work);
3076 
3077 	ret = qmi_add_lookup(&ab->qmi.handle, ATH12K_QMI_WLFW_SERVICE_ID_V01,
3078 			     ATH12K_QMI_WLFW_SERVICE_VERS_V01,
3079 			     ab->qmi.service_ins_id);
3080 	if (ret < 0) {
3081 		ath12k_warn(ab, "failed to add qmi lookup\n");
3082 		destroy_workqueue(ab->qmi.event_wq);
3083 		return ret;
3084 	}
3085 
3086 	return ret;
3087 }
3088 
3089 void ath12k_qmi_deinit_service(struct ath12k_base *ab)
3090 {
3091 	qmi_handle_release(&ab->qmi.handle);
3092 	cancel_work_sync(&ab->qmi.event_work);
3093 	destroy_workqueue(ab->qmi.event_wq);
3094 	ath12k_qmi_m3_free(ab);
3095 	ath12k_qmi_free_target_mem_chunk(ab);
3096 }
3097 
3098 void ath12k_qmi_free_resource(struct ath12k_base *ab)
3099 {
3100 	ath12k_qmi_free_target_mem_chunk(ab);
3101 	ath12k_qmi_m3_free(ab);
3102 }
3103