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