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