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