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