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 bool delayed; 1664 1665 req = kzalloc(sizeof(*req), GFP_KERNEL); 1666 if (!req) 1667 return -ENOMEM; 1668 1669 memset(&resp, 0, sizeof(resp)); 1670 1671 /* For QCA6390 by default FW requests a block of ~4M contiguous 1672 * DMA memory, it's hard to allocate from OS. So host returns 1673 * failure to FW and FW will then request mulitple blocks of small 1674 * chunk size memory. 1675 */ 1676 if (!ab->bus_params.fixed_mem_region && ab->qmi.target_mem_delayed) { 1677 delayed = true; 1678 ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi delays mem_request %d\n", 1679 ab->qmi.mem_seg_count); 1680 memset(req, 0, sizeof(*req)); 1681 } else { 1682 delayed = false; 1683 req->mem_seg_len = ab->qmi.mem_seg_count; 1684 1685 for (i = 0; i < req->mem_seg_len ; i++) { 1686 req->mem_seg[i].addr = ab->qmi.target_mem[i].paddr; 1687 req->mem_seg[i].size = ab->qmi.target_mem[i].size; 1688 req->mem_seg[i].type = ab->qmi.target_mem[i].type; 1689 ath11k_dbg(ab, ATH11K_DBG_QMI, 1690 "qmi req mem_seg[%d] %pad %u %u\n", i, 1691 &ab->qmi.target_mem[i].paddr, 1692 ab->qmi.target_mem[i].size, 1693 ab->qmi.target_mem[i].type); 1694 } 1695 } 1696 1697 ret = qmi_txn_init(&ab->qmi.handle, &txn, 1698 qmi_wlanfw_respond_mem_resp_msg_v01_ei, &resp); 1699 if (ret < 0) 1700 goto out; 1701 1702 ret = qmi_send_request(&ab->qmi.handle, NULL, &txn, 1703 QMI_WLANFW_RESPOND_MEM_REQ_V01, 1704 QMI_WLANFW_RESPOND_MEM_REQ_MSG_V01_MAX_LEN, 1705 qmi_wlanfw_respond_mem_req_msg_v01_ei, req); 1706 if (ret < 0) { 1707 ath11k_warn(ab, "qmi failed to respond memory request, err = %d\n", 1708 ret); 1709 goto out; 1710 } 1711 1712 ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH11K_QMI_WLANFW_TIMEOUT_MS)); 1713 if (ret < 0) { 1714 ath11k_warn(ab, "qmi failed memory request, err = %d\n", ret); 1715 goto out; 1716 } 1717 1718 if (resp.resp.result != QMI_RESULT_SUCCESS_V01) { 1719 /* the error response is expected when 1720 * target_mem_delayed is true. 1721 */ 1722 if (delayed && resp.resp.error == 0) 1723 goto out; 1724 1725 ath11k_warn(ab, "Respond mem req failed, result: %d, err: %d\n", 1726 resp.resp.result, resp.resp.error); 1727 ret = -EINVAL; 1728 goto out; 1729 } 1730 out: 1731 kfree(req); 1732 return ret; 1733 } 1734 1735 static void ath11k_qmi_free_target_mem_chunk(struct ath11k_base *ab) 1736 { 1737 int i; 1738 1739 if (ab->bus_params.fixed_mem_region) 1740 return; 1741 1742 for (i = 0; i < ab->qmi.mem_seg_count; i++) { 1743 if (!ab->qmi.target_mem[i].vaddr) 1744 continue; 1745 1746 dma_free_coherent(ab->dev, 1747 ab->qmi.target_mem[i].size, 1748 ab->qmi.target_mem[i].vaddr, 1749 ab->qmi.target_mem[i].paddr); 1750 ab->qmi.target_mem[i].vaddr = NULL; 1751 } 1752 } 1753 1754 static int ath11k_qmi_alloc_target_mem_chunk(struct ath11k_base *ab) 1755 { 1756 int i; 1757 struct target_mem_chunk *chunk; 1758 1759 ab->qmi.target_mem_delayed = false; 1760 1761 for (i = 0; i < ab->qmi.mem_seg_count; i++) { 1762 chunk = &ab->qmi.target_mem[i]; 1763 chunk->vaddr = dma_alloc_coherent(ab->dev, 1764 chunk->size, 1765 &chunk->paddr, 1766 GFP_KERNEL); 1767 if (!chunk->vaddr) { 1768 if (ab->qmi.mem_seg_count <= 2) { 1769 ath11k_dbg(ab, ATH11K_DBG_QMI, 1770 "qmi dma allocation failed (%d B type %u), will try later with small size\n", 1771 chunk->size, 1772 chunk->type); 1773 ath11k_qmi_free_target_mem_chunk(ab); 1774 ab->qmi.target_mem_delayed = true; 1775 return 0; 1776 } 1777 ath11k_err(ab, "failed to alloc memory, size: 0x%x, type: %u\n", 1778 chunk->size, 1779 chunk->type); 1780 return -EINVAL; 1781 } 1782 } 1783 1784 return 0; 1785 } 1786 1787 static int ath11k_qmi_assign_target_mem_chunk(struct ath11k_base *ab) 1788 { 1789 int i, idx; 1790 1791 for (i = 0, idx = 0; i < ab->qmi.mem_seg_count; i++) { 1792 switch (ab->qmi.target_mem[i].type) { 1793 case BDF_MEM_REGION_TYPE: 1794 ab->qmi.target_mem[idx].paddr = ab->hw_params.bdf_addr; 1795 ab->qmi.target_mem[idx].vaddr = NULL; 1796 ab->qmi.target_mem[idx].size = ab->qmi.target_mem[i].size; 1797 ab->qmi.target_mem[idx].type = ab->qmi.target_mem[i].type; 1798 idx++; 1799 break; 1800 case CALDB_MEM_REGION_TYPE: 1801 if (ab->qmi.target_mem[i].size > ATH11K_QMI_CALDB_SIZE) { 1802 ath11k_warn(ab, "qmi mem size is low to load caldata\n"); 1803 return -EINVAL; 1804 } 1805 1806 if (ath11k_cold_boot_cal && ab->hw_params.cold_boot_calib) { 1807 ab->qmi.target_mem[idx].paddr = 1808 ATH11K_QMI_CALDB_ADDRESS; 1809 ab->qmi.target_mem[idx].vaddr = 1810 (void *)ATH11K_QMI_CALDB_ADDRESS; 1811 } else { 1812 ab->qmi.target_mem[idx].paddr = 0; 1813 ab->qmi.target_mem[idx].vaddr = NULL; 1814 } 1815 ab->qmi.target_mem[idx].size = ab->qmi.target_mem[i].size; 1816 ab->qmi.target_mem[idx].type = ab->qmi.target_mem[i].type; 1817 idx++; 1818 break; 1819 default: 1820 ath11k_warn(ab, "qmi ignore invalid mem req type %d\n", 1821 ab->qmi.target_mem[i].type); 1822 break; 1823 } 1824 } 1825 ab->qmi.mem_seg_count = idx; 1826 1827 return 0; 1828 } 1829 1830 static int ath11k_qmi_request_target_cap(struct ath11k_base *ab) 1831 { 1832 struct qmi_wlanfw_cap_req_msg_v01 req; 1833 struct qmi_wlanfw_cap_resp_msg_v01 resp; 1834 struct qmi_txn txn = {}; 1835 int ret = 0; 1836 int r; 1837 1838 memset(&req, 0, sizeof(req)); 1839 memset(&resp, 0, sizeof(resp)); 1840 1841 ret = qmi_txn_init(&ab->qmi.handle, &txn, 1842 qmi_wlanfw_cap_resp_msg_v01_ei, &resp); 1843 if (ret < 0) 1844 goto out; 1845 1846 ret = qmi_send_request(&ab->qmi.handle, NULL, &txn, 1847 QMI_WLANFW_CAP_REQ_V01, 1848 QMI_WLANFW_CAP_REQ_MSG_V01_MAX_LEN, 1849 qmi_wlanfw_cap_req_msg_v01_ei, &req); 1850 if (ret < 0) { 1851 ath11k_warn(ab, "qmi failed to send target cap request, err = %d\n", 1852 ret); 1853 goto out; 1854 } 1855 1856 ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH11K_QMI_WLANFW_TIMEOUT_MS)); 1857 if (ret < 0) { 1858 ath11k_warn(ab, "qmi failed target cap request %d\n", ret); 1859 goto out; 1860 } 1861 1862 if (resp.resp.result != QMI_RESULT_SUCCESS_V01) { 1863 ath11k_warn(ab, "qmi targetcap req failed, result: %d, err: %d\n", 1864 resp.resp.result, resp.resp.error); 1865 ret = -EINVAL; 1866 goto out; 1867 } 1868 1869 if (resp.chip_info_valid) { 1870 ab->qmi.target.chip_id = resp.chip_info.chip_id; 1871 ab->qmi.target.chip_family = resp.chip_info.chip_family; 1872 } 1873 1874 if (resp.board_info_valid) 1875 ab->qmi.target.board_id = resp.board_info.board_id; 1876 else 1877 ab->qmi.target.board_id = 0xFF; 1878 1879 if (resp.soc_info_valid) 1880 ab->qmi.target.soc_id = resp.soc_info.soc_id; 1881 1882 if (resp.fw_version_info_valid) { 1883 ab->qmi.target.fw_version = resp.fw_version_info.fw_version; 1884 strlcpy(ab->qmi.target.fw_build_timestamp, 1885 resp.fw_version_info.fw_build_timestamp, 1886 sizeof(ab->qmi.target.fw_build_timestamp)); 1887 } 1888 1889 if (resp.fw_build_id_valid) 1890 strlcpy(ab->qmi.target.fw_build_id, resp.fw_build_id, 1891 sizeof(ab->qmi.target.fw_build_id)); 1892 1893 ath11k_info(ab, "chip_id 0x%x chip_family 0x%x board_id 0x%x soc_id 0x%x\n", 1894 ab->qmi.target.chip_id, ab->qmi.target.chip_family, 1895 ab->qmi.target.board_id, ab->qmi.target.soc_id); 1896 1897 ath11k_info(ab, "fw_version 0x%x fw_build_timestamp %s fw_build_id %s", 1898 ab->qmi.target.fw_version, 1899 ab->qmi.target.fw_build_timestamp, 1900 ab->qmi.target.fw_build_id); 1901 1902 r = ath11k_core_check_dt(ab); 1903 if (r) 1904 ath11k_dbg(ab, ATH11K_DBG_QMI, "DT bdf variant name not set.\n"); 1905 1906 out: 1907 return ret; 1908 } 1909 1910 static int 1911 ath11k_qmi_prepare_bdf_download(struct ath11k_base *ab, int type, 1912 struct qmi_wlanfw_bdf_download_req_msg_v01 *req, 1913 void __iomem *bdf_addr) 1914 { 1915 const struct firmware *fw_entry; 1916 struct ath11k_board_data bd; 1917 u32 fw_size; 1918 int ret; 1919 1920 switch (type) { 1921 case ATH11K_QMI_FILE_TYPE_BDF_GOLDEN: 1922 memset(&bd, 0, sizeof(bd)); 1923 1924 ret = ath11k_core_fetch_bdf(ab, &bd); 1925 if (ret) { 1926 ath11k_warn(ab, "qmi failed to load BDF\n"); 1927 return ret; 1928 } 1929 1930 fw_size = min_t(u32, ab->hw_params.fw.board_size, bd.len); 1931 memcpy_toio(bdf_addr, bd.data, fw_size); 1932 ath11k_core_free_bdf(ab, &bd); 1933 break; 1934 case ATH11K_QMI_FILE_TYPE_CALDATA: 1935 fw_entry = ath11k_core_firmware_request(ab, ATH11K_DEFAULT_CAL_FILE); 1936 if (IS_ERR(fw_entry)) { 1937 ret = PTR_ERR(fw_entry); 1938 ath11k_warn(ab, "failed to load %s: %d\n", 1939 ATH11K_DEFAULT_CAL_FILE, ret); 1940 return ret; 1941 } 1942 1943 fw_size = min_t(u32, ab->hw_params.fw.board_size, 1944 fw_entry->size); 1945 1946 memcpy_toio(bdf_addr + ATH11K_QMI_CALDATA_OFFSET, 1947 fw_entry->data, fw_size); 1948 1949 release_firmware(fw_entry); 1950 break; 1951 default: 1952 return -EINVAL; 1953 } 1954 1955 req->total_size = fw_size; 1956 return 0; 1957 } 1958 1959 static int ath11k_qmi_load_bdf_fixed_addr(struct ath11k_base *ab) 1960 { 1961 struct qmi_wlanfw_bdf_download_req_msg_v01 *req; 1962 struct qmi_wlanfw_bdf_download_resp_msg_v01 resp; 1963 struct qmi_txn txn = {}; 1964 void __iomem *bdf_addr = NULL; 1965 int type, ret; 1966 1967 req = kzalloc(sizeof(*req), GFP_KERNEL); 1968 if (!req) 1969 return -ENOMEM; 1970 memset(&resp, 0, sizeof(resp)); 1971 1972 bdf_addr = ioremap(ab->hw_params.bdf_addr, ATH11K_QMI_BDF_MAX_SIZE); 1973 if (!bdf_addr) { 1974 ath11k_warn(ab, "qmi ioremap error for BDF\n"); 1975 ret = -EIO; 1976 goto out; 1977 } 1978 1979 for (type = 0; type < ATH11K_QMI_MAX_FILE_TYPE; type++) { 1980 req->valid = 1; 1981 req->file_id_valid = 1; 1982 req->file_id = ab->qmi.target.board_id; 1983 req->total_size_valid = 1; 1984 req->seg_id_valid = 1; 1985 req->seg_id = type; 1986 req->data_valid = 0; 1987 req->data_len = ATH11K_QMI_MAX_BDF_FILE_NAME_SIZE; 1988 req->bdf_type = 0; 1989 req->bdf_type_valid = 0; 1990 req->end_valid = 1; 1991 req->end = 1; 1992 1993 ret = ath11k_qmi_prepare_bdf_download(ab, type, req, bdf_addr); 1994 if (ret < 0) 1995 goto out_qmi_bdf; 1996 1997 ret = qmi_txn_init(&ab->qmi.handle, &txn, 1998 qmi_wlanfw_bdf_download_resp_msg_v01_ei, 1999 &resp); 2000 if (ret < 0) 2001 goto out_qmi_bdf; 2002 2003 ret = qmi_send_request(&ab->qmi.handle, NULL, &txn, 2004 QMI_WLANFW_BDF_DOWNLOAD_REQ_V01, 2005 QMI_WLANFW_BDF_DOWNLOAD_REQ_MSG_V01_MAX_LEN, 2006 qmi_wlanfw_bdf_download_req_msg_v01_ei, req); 2007 if (ret < 0) { 2008 qmi_txn_cancel(&txn); 2009 goto out_qmi_bdf; 2010 } 2011 2012 ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH11K_QMI_WLANFW_TIMEOUT_MS)); 2013 if (ret < 0) 2014 goto out_qmi_bdf; 2015 2016 if (resp.resp.result != QMI_RESULT_SUCCESS_V01) { 2017 ath11k_warn(ab, "qmi BDF download failed, result: %d, err: %d\n", 2018 resp.resp.result, resp.resp.error); 2019 ret = -EINVAL; 2020 goto out_qmi_bdf; 2021 } 2022 } 2023 2024 out_qmi_bdf: 2025 iounmap(bdf_addr); 2026 out: 2027 kfree(req); 2028 return ret; 2029 } 2030 2031 static int ath11k_qmi_load_bdf_qmi(struct ath11k_base *ab) 2032 { 2033 struct qmi_wlanfw_bdf_download_req_msg_v01 *req; 2034 struct qmi_wlanfw_bdf_download_resp_msg_v01 resp; 2035 struct ath11k_board_data bd; 2036 unsigned int remaining; 2037 struct qmi_txn txn = {}; 2038 int ret; 2039 const u8 *temp; 2040 int bdf_type; 2041 2042 req = kzalloc(sizeof(*req), GFP_KERNEL); 2043 if (!req) 2044 return -ENOMEM; 2045 memset(&resp, 0, sizeof(resp)); 2046 2047 memset(&bd, 0, sizeof(bd)); 2048 ret = ath11k_core_fetch_bdf(ab, &bd); 2049 if (ret) { 2050 ath11k_warn(ab, "qmi failed to load bdf:\n"); 2051 goto out; 2052 } 2053 2054 temp = bd.data; 2055 remaining = bd.len; 2056 2057 if (bd.len >= SELFMAG && memcmp(bd.data, ELFMAG, SELFMAG) == 0) 2058 bdf_type = ATH11K_QMI_BDF_TYPE_ELF; 2059 else 2060 bdf_type = ATH11K_QMI_BDF_TYPE_BIN; 2061 2062 ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi bdf_type %d\n", bdf_type); 2063 2064 while (remaining) { 2065 req->valid = 1; 2066 req->file_id_valid = 1; 2067 req->file_id = ab->qmi.target.board_id; 2068 req->total_size_valid = 1; 2069 req->total_size = bd.len; 2070 req->seg_id_valid = 1; 2071 req->data_valid = 1; 2072 req->data_len = ATH11K_QMI_MAX_BDF_FILE_NAME_SIZE; 2073 req->bdf_type = bdf_type; 2074 req->bdf_type_valid = 1; 2075 req->end_valid = 1; 2076 req->end = 0; 2077 2078 if (remaining > QMI_WLANFW_MAX_DATA_SIZE_V01) { 2079 req->data_len = QMI_WLANFW_MAX_DATA_SIZE_V01; 2080 } else { 2081 req->data_len = remaining; 2082 req->end = 1; 2083 } 2084 2085 memcpy(req->data, temp, req->data_len); 2086 2087 ret = qmi_txn_init(&ab->qmi.handle, &txn, 2088 qmi_wlanfw_bdf_download_resp_msg_v01_ei, 2089 &resp); 2090 if (ret < 0) 2091 goto out_qmi_bdf; 2092 2093 ret = qmi_send_request(&ab->qmi.handle, NULL, &txn, 2094 QMI_WLANFW_BDF_DOWNLOAD_REQ_V01, 2095 QMI_WLANFW_BDF_DOWNLOAD_REQ_MSG_V01_MAX_LEN, 2096 qmi_wlanfw_bdf_download_req_msg_v01_ei, req); 2097 if (ret < 0) { 2098 qmi_txn_cancel(&txn); 2099 goto out_qmi_bdf; 2100 } 2101 2102 ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH11K_QMI_WLANFW_TIMEOUT_MS)); 2103 if (ret < 0) 2104 goto out_qmi_bdf; 2105 2106 if (resp.resp.result != QMI_RESULT_SUCCESS_V01) { 2107 ath11k_warn(ab, "qmi BDF download failed, result: %d, err: %d\n", 2108 resp.resp.result, resp.resp.error); 2109 ret = resp.resp.result; 2110 goto out_qmi_bdf; 2111 } 2112 remaining -= req->data_len; 2113 temp += req->data_len; 2114 req->seg_id++; 2115 } 2116 2117 out_qmi_bdf: 2118 ath11k_core_free_bdf(ab, &bd); 2119 2120 out: 2121 kfree(req); 2122 return ret; 2123 } 2124 2125 static int ath11k_qmi_m3_load(struct ath11k_base *ab) 2126 { 2127 struct m3_mem_region *m3_mem = &ab->qmi.m3_mem; 2128 const struct firmware *fw; 2129 char path[100]; 2130 int ret; 2131 2132 if (m3_mem->vaddr || m3_mem->size) 2133 return 0; 2134 2135 fw = ath11k_core_firmware_request(ab, ATH11K_M3_FILE); 2136 if (IS_ERR(fw)) { 2137 ret = PTR_ERR(fw); 2138 ath11k_core_create_firmware_path(ab, ATH11K_M3_FILE, 2139 path, sizeof(path)); 2140 ath11k_err(ab, "failed to load %s: %d\n", path, ret); 2141 return ret; 2142 } 2143 2144 m3_mem->vaddr = dma_alloc_coherent(ab->dev, 2145 fw->size, &m3_mem->paddr, 2146 GFP_KERNEL); 2147 if (!m3_mem->vaddr) { 2148 ath11k_err(ab, "failed to allocate memory for M3 with size %zu\n", 2149 fw->size); 2150 release_firmware(fw); 2151 return -ENOMEM; 2152 } 2153 2154 memcpy(m3_mem->vaddr, fw->data, fw->size); 2155 m3_mem->size = fw->size; 2156 release_firmware(fw); 2157 2158 return 0; 2159 } 2160 2161 static void ath11k_qmi_m3_free(struct ath11k_base *ab) 2162 { 2163 struct m3_mem_region *m3_mem = &ab->qmi.m3_mem; 2164 2165 if (!ab->bus_params.m3_fw_support || !m3_mem->vaddr) 2166 return; 2167 2168 dma_free_coherent(ab->dev, m3_mem->size, 2169 m3_mem->vaddr, m3_mem->paddr); 2170 m3_mem->vaddr = NULL; 2171 } 2172 2173 static int ath11k_qmi_wlanfw_m3_info_send(struct ath11k_base *ab) 2174 { 2175 struct m3_mem_region *m3_mem = &ab->qmi.m3_mem; 2176 struct qmi_wlanfw_m3_info_req_msg_v01 req; 2177 struct qmi_wlanfw_m3_info_resp_msg_v01 resp; 2178 struct qmi_txn txn = {}; 2179 int ret = 0; 2180 2181 memset(&req, 0, sizeof(req)); 2182 memset(&resp, 0, sizeof(resp)); 2183 2184 if (ab->bus_params.m3_fw_support) { 2185 ret = ath11k_qmi_m3_load(ab); 2186 if (ret) { 2187 ath11k_err(ab, "failed to load m3 firmware: %d", ret); 2188 return ret; 2189 } 2190 2191 req.addr = m3_mem->paddr; 2192 req.size = m3_mem->size; 2193 } else { 2194 req.addr = 0; 2195 req.size = 0; 2196 } 2197 2198 ret = qmi_txn_init(&ab->qmi.handle, &txn, 2199 qmi_wlanfw_m3_info_resp_msg_v01_ei, &resp); 2200 if (ret < 0) 2201 goto out; 2202 2203 ret = qmi_send_request(&ab->qmi.handle, NULL, &txn, 2204 QMI_WLANFW_M3_INFO_REQ_V01, 2205 QMI_WLANFW_M3_INFO_REQ_MSG_V01_MAX_MSG_LEN, 2206 qmi_wlanfw_m3_info_req_msg_v01_ei, &req); 2207 if (ret < 0) { 2208 ath11k_warn(ab, "qmi failed to send M3 information request, err = %d\n", 2209 ret); 2210 goto out; 2211 } 2212 2213 ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH11K_QMI_WLANFW_TIMEOUT_MS)); 2214 if (ret < 0) { 2215 ath11k_warn(ab, "qmi failed M3 information request %d\n", ret); 2216 goto out; 2217 } 2218 2219 if (resp.resp.result != QMI_RESULT_SUCCESS_V01) { 2220 ath11k_warn(ab, "qmi M3 info request failed, result: %d, err: %d\n", 2221 resp.resp.result, resp.resp.error); 2222 ret = -EINVAL; 2223 goto out; 2224 } 2225 out: 2226 return ret; 2227 } 2228 2229 static int ath11k_qmi_wlanfw_mode_send(struct ath11k_base *ab, 2230 u32 mode) 2231 { 2232 struct qmi_wlanfw_wlan_mode_req_msg_v01 req; 2233 struct qmi_wlanfw_wlan_mode_resp_msg_v01 resp; 2234 struct qmi_txn txn = {}; 2235 int ret = 0; 2236 2237 memset(&req, 0, sizeof(req)); 2238 memset(&resp, 0, sizeof(resp)); 2239 2240 req.mode = mode; 2241 req.hw_debug_valid = 1; 2242 req.hw_debug = 0; 2243 2244 ret = qmi_txn_init(&ab->qmi.handle, &txn, 2245 qmi_wlanfw_wlan_mode_resp_msg_v01_ei, &resp); 2246 if (ret < 0) 2247 goto out; 2248 2249 ret = qmi_send_request(&ab->qmi.handle, NULL, &txn, 2250 QMI_WLANFW_WLAN_MODE_REQ_V01, 2251 QMI_WLANFW_WLAN_MODE_REQ_MSG_V01_MAX_LEN, 2252 qmi_wlanfw_wlan_mode_req_msg_v01_ei, &req); 2253 if (ret < 0) { 2254 ath11k_warn(ab, "qmi failed to send mode request, mode: %d, err = %d\n", 2255 mode, ret); 2256 goto out; 2257 } 2258 2259 ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH11K_QMI_WLANFW_TIMEOUT_MS)); 2260 if (ret < 0) { 2261 if (mode == ATH11K_FIRMWARE_MODE_OFF && ret == -ENETRESET) { 2262 ath11k_warn(ab, "WLFW service is dis-connected\n"); 2263 return 0; 2264 } 2265 ath11k_warn(ab, "qmi failed set mode request, mode: %d, err = %d\n", 2266 mode, ret); 2267 goto out; 2268 } 2269 2270 if (resp.resp.result != QMI_RESULT_SUCCESS_V01) { 2271 ath11k_warn(ab, "Mode request failed, mode: %d, result: %d err: %d\n", 2272 mode, resp.resp.result, resp.resp.error); 2273 ret = -EINVAL; 2274 goto out; 2275 } 2276 2277 out: 2278 return ret; 2279 } 2280 2281 static int ath11k_qmi_wlanfw_wlan_cfg_send(struct ath11k_base *ab) 2282 { 2283 struct qmi_wlanfw_wlan_cfg_req_msg_v01 *req; 2284 struct qmi_wlanfw_wlan_cfg_resp_msg_v01 resp; 2285 struct ce_pipe_config *ce_cfg; 2286 struct service_to_pipe *svc_cfg; 2287 struct qmi_txn txn = {}; 2288 int ret = 0, pipe_num; 2289 2290 ce_cfg = (struct ce_pipe_config *)ab->qmi.ce_cfg.tgt_ce; 2291 svc_cfg = (struct service_to_pipe *)ab->qmi.ce_cfg.svc_to_ce_map; 2292 2293 req = kzalloc(sizeof(*req), GFP_KERNEL); 2294 if (!req) 2295 return -ENOMEM; 2296 2297 memset(&resp, 0, sizeof(resp)); 2298 2299 req->host_version_valid = 1; 2300 strlcpy(req->host_version, ATH11K_HOST_VERSION_STRING, 2301 sizeof(req->host_version)); 2302 2303 req->tgt_cfg_valid = 1; 2304 /* This is number of CE configs */ 2305 req->tgt_cfg_len = ab->qmi.ce_cfg.tgt_ce_len; 2306 for (pipe_num = 0; pipe_num < req->tgt_cfg_len ; pipe_num++) { 2307 req->tgt_cfg[pipe_num].pipe_num = ce_cfg[pipe_num].pipenum; 2308 req->tgt_cfg[pipe_num].pipe_dir = ce_cfg[pipe_num].pipedir; 2309 req->tgt_cfg[pipe_num].nentries = ce_cfg[pipe_num].nentries; 2310 req->tgt_cfg[pipe_num].nbytes_max = ce_cfg[pipe_num].nbytes_max; 2311 req->tgt_cfg[pipe_num].flags = ce_cfg[pipe_num].flags; 2312 } 2313 2314 req->svc_cfg_valid = 1; 2315 /* This is number of Service/CE configs */ 2316 req->svc_cfg_len = ab->qmi.ce_cfg.svc_to_ce_map_len; 2317 for (pipe_num = 0; pipe_num < req->svc_cfg_len; pipe_num++) { 2318 req->svc_cfg[pipe_num].service_id = svc_cfg[pipe_num].service_id; 2319 req->svc_cfg[pipe_num].pipe_dir = svc_cfg[pipe_num].pipedir; 2320 req->svc_cfg[pipe_num].pipe_num = svc_cfg[pipe_num].pipenum; 2321 } 2322 req->shadow_reg_valid = 0; 2323 2324 /* set shadow v2 configuration */ 2325 if (ab->hw_params.supports_shadow_regs) { 2326 req->shadow_reg_v2_valid = 1; 2327 req->shadow_reg_v2_len = min_t(u32, 2328 ab->qmi.ce_cfg.shadow_reg_v2_len, 2329 QMI_WLANFW_MAX_NUM_SHADOW_REG_V2_V01); 2330 memcpy(&req->shadow_reg_v2, ab->qmi.ce_cfg.shadow_reg_v2, 2331 sizeof(u32) * req->shadow_reg_v2_len); 2332 } else { 2333 req->shadow_reg_v2_valid = 0; 2334 } 2335 2336 ret = qmi_txn_init(&ab->qmi.handle, &txn, 2337 qmi_wlanfw_wlan_cfg_resp_msg_v01_ei, &resp); 2338 if (ret < 0) 2339 goto out; 2340 2341 ret = qmi_send_request(&ab->qmi.handle, NULL, &txn, 2342 QMI_WLANFW_WLAN_CFG_REQ_V01, 2343 QMI_WLANFW_WLAN_CFG_REQ_MSG_V01_MAX_LEN, 2344 qmi_wlanfw_wlan_cfg_req_msg_v01_ei, req); 2345 if (ret < 0) { 2346 ath11k_warn(ab, "qmi failed to send wlan config request, err = %d\n", 2347 ret); 2348 goto out; 2349 } 2350 2351 ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH11K_QMI_WLANFW_TIMEOUT_MS)); 2352 if (ret < 0) { 2353 ath11k_warn(ab, "qmi failed wlan config request, err = %d\n", ret); 2354 goto out; 2355 } 2356 2357 if (resp.resp.result != QMI_RESULT_SUCCESS_V01) { 2358 ath11k_warn(ab, "qmi wlan config request failed, result: %d, err: %d\n", 2359 resp.resp.result, resp.resp.error); 2360 ret = -EINVAL; 2361 goto out; 2362 } 2363 2364 out: 2365 kfree(req); 2366 return ret; 2367 } 2368 2369 void ath11k_qmi_firmware_stop(struct ath11k_base *ab) 2370 { 2371 int ret; 2372 2373 ret = ath11k_qmi_wlanfw_mode_send(ab, ATH11K_FIRMWARE_MODE_OFF); 2374 if (ret < 0) { 2375 ath11k_warn(ab, "qmi failed to send wlan mode off\n"); 2376 return; 2377 } 2378 } 2379 2380 int ath11k_qmi_firmware_start(struct ath11k_base *ab, 2381 u32 mode) 2382 { 2383 int ret; 2384 2385 ret = ath11k_qmi_wlanfw_wlan_cfg_send(ab); 2386 if (ret < 0) { 2387 ath11k_warn(ab, "qmi failed to send wlan cfg:%d\n", ret); 2388 return ret; 2389 } 2390 2391 ret = ath11k_qmi_wlanfw_mode_send(ab, mode); 2392 if (ret < 0) { 2393 ath11k_warn(ab, "qmi failed to send wlan fw mode:%d\n", ret); 2394 return ret; 2395 } 2396 2397 return 0; 2398 } 2399 2400 static int ath11k_qmi_process_coldboot_calibration(struct ath11k_base *ab) 2401 { 2402 int timeout; 2403 int ret; 2404 2405 ret = ath11k_qmi_wlanfw_mode_send(ab, ATH11K_FIRMWARE_MODE_COLD_BOOT); 2406 if (ret < 0) { 2407 ath11k_warn(ab, "qmi failed to send wlan fw mode:%d\n", ret); 2408 return ret; 2409 } 2410 2411 ath11k_dbg(ab, ATH11K_DBG_QMI, "Coldboot calibration wait started\n"); 2412 2413 timeout = wait_event_timeout(ab->qmi.cold_boot_waitq, 2414 (ab->qmi.cal_done == 1), 2415 ATH11K_COLD_BOOT_FW_RESET_DELAY); 2416 if (timeout <= 0) { 2417 ath11k_warn(ab, "Coldboot Calibration failed - wait ended\n"); 2418 return 0; 2419 } 2420 2421 ath11k_dbg(ab, ATH11K_DBG_QMI, "Coldboot calibration done\n"); 2422 2423 return 0; 2424 } 2425 2426 static int 2427 ath11k_qmi_driver_event_post(struct ath11k_qmi *qmi, 2428 enum ath11k_qmi_event_type type, 2429 void *data) 2430 { 2431 struct ath11k_qmi_driver_event *event; 2432 2433 event = kzalloc(sizeof(*event), GFP_ATOMIC); 2434 if (!event) 2435 return -ENOMEM; 2436 2437 event->type = type; 2438 event->data = data; 2439 2440 spin_lock(&qmi->event_lock); 2441 list_add_tail(&event->list, &qmi->event_list); 2442 spin_unlock(&qmi->event_lock); 2443 2444 queue_work(qmi->event_wq, &qmi->event_work); 2445 2446 return 0; 2447 } 2448 2449 static int ath11k_qmi_event_server_arrive(struct ath11k_qmi *qmi) 2450 { 2451 struct ath11k_base *ab = qmi->ab; 2452 int ret; 2453 2454 ret = ath11k_qmi_fw_ind_register_send(ab); 2455 if (ret < 0) { 2456 ath11k_warn(ab, "qmi failed to send FW indication QMI:%d\n", ret); 2457 return ret; 2458 } 2459 2460 ret = ath11k_qmi_host_cap_send(ab); 2461 if (ret < 0) { 2462 ath11k_warn(ab, "qmi failed to send host cap QMI:%d\n", ret); 2463 return ret; 2464 } 2465 2466 return ret; 2467 } 2468 2469 static int ath11k_qmi_event_mem_request(struct ath11k_qmi *qmi) 2470 { 2471 struct ath11k_base *ab = qmi->ab; 2472 int ret; 2473 2474 ret = ath11k_qmi_respond_fw_mem_request(ab); 2475 if (ret < 0) { 2476 ath11k_warn(ab, "qmi failed to respond fw mem req:%d\n", ret); 2477 return ret; 2478 } 2479 2480 return ret; 2481 } 2482 2483 static int ath11k_qmi_event_load_bdf(struct ath11k_qmi *qmi) 2484 { 2485 struct ath11k_base *ab = qmi->ab; 2486 int ret; 2487 2488 ret = ath11k_qmi_request_target_cap(ab); 2489 if (ret < 0) { 2490 ath11k_warn(ab, "qmi failed to req target capabilities:%d\n", ret); 2491 return ret; 2492 } 2493 2494 if (ab->bus_params.fixed_bdf_addr) 2495 ret = ath11k_qmi_load_bdf_fixed_addr(ab); 2496 else 2497 ret = ath11k_qmi_load_bdf_qmi(ab); 2498 if (ret < 0) { 2499 ath11k_warn(ab, "qmi failed to load board data file:%d\n", ret); 2500 return ret; 2501 } 2502 2503 ret = ath11k_qmi_wlanfw_m3_info_send(ab); 2504 if (ret < 0) { 2505 ath11k_warn(ab, "qmi failed to send m3 info req:%d\n", ret); 2506 return ret; 2507 } 2508 2509 return ret; 2510 } 2511 2512 static void ath11k_qmi_msg_mem_request_cb(struct qmi_handle *qmi_hdl, 2513 struct sockaddr_qrtr *sq, 2514 struct qmi_txn *txn, 2515 const void *data) 2516 { 2517 struct ath11k_qmi *qmi = container_of(qmi_hdl, struct ath11k_qmi, handle); 2518 struct ath11k_base *ab = qmi->ab; 2519 const struct qmi_wlanfw_request_mem_ind_msg_v01 *msg = data; 2520 int i, ret; 2521 2522 ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi firmware request memory request\n"); 2523 2524 if (msg->mem_seg_len == 0 || 2525 msg->mem_seg_len > ATH11K_QMI_WLANFW_MAX_NUM_MEM_SEG_V01) 2526 ath11k_warn(ab, "Invalid memory segment length: %u\n", 2527 msg->mem_seg_len); 2528 2529 ab->qmi.mem_seg_count = msg->mem_seg_len; 2530 2531 for (i = 0; i < qmi->mem_seg_count ; i++) { 2532 ab->qmi.target_mem[i].type = msg->mem_seg[i].type; 2533 ab->qmi.target_mem[i].size = msg->mem_seg[i].size; 2534 ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi mem seg type %d size %d\n", 2535 msg->mem_seg[i].type, msg->mem_seg[i].size); 2536 } 2537 2538 if (ab->bus_params.fixed_mem_region) { 2539 ret = ath11k_qmi_assign_target_mem_chunk(ab); 2540 if (ret) { 2541 ath11k_warn(ab, "qmi failed to assign target memory: %d\n", 2542 ret); 2543 return; 2544 } 2545 } else { 2546 ret = ath11k_qmi_alloc_target_mem_chunk(ab); 2547 if (ret) { 2548 ath11k_warn(ab, "qmi failed to alloc target memory: %d\n", 2549 ret); 2550 return; 2551 } 2552 } 2553 2554 ath11k_qmi_driver_event_post(qmi, ATH11K_QMI_EVENT_REQUEST_MEM, NULL); 2555 } 2556 2557 static void ath11k_qmi_msg_mem_ready_cb(struct qmi_handle *qmi_hdl, 2558 struct sockaddr_qrtr *sq, 2559 struct qmi_txn *txn, 2560 const void *decoded) 2561 { 2562 struct ath11k_qmi *qmi = container_of(qmi_hdl, struct ath11k_qmi, handle); 2563 struct ath11k_base *ab = qmi->ab; 2564 2565 ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi firmware memory ready indication\n"); 2566 ath11k_qmi_driver_event_post(qmi, ATH11K_QMI_EVENT_FW_MEM_READY, NULL); 2567 } 2568 2569 static void ath11k_qmi_msg_fw_ready_cb(struct qmi_handle *qmi_hdl, 2570 struct sockaddr_qrtr *sq, 2571 struct qmi_txn *txn, 2572 const void *decoded) 2573 { 2574 struct ath11k_qmi *qmi = container_of(qmi_hdl, struct ath11k_qmi, handle); 2575 struct ath11k_base *ab = qmi->ab; 2576 2577 ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi firmware ready\n"); 2578 ath11k_qmi_driver_event_post(qmi, ATH11K_QMI_EVENT_FW_READY, NULL); 2579 } 2580 2581 static void ath11k_qmi_msg_cold_boot_cal_done_cb(struct qmi_handle *qmi_hdl, 2582 struct sockaddr_qrtr *sq, 2583 struct qmi_txn *txn, 2584 const void *decoded) 2585 { 2586 struct ath11k_qmi *qmi = container_of(qmi_hdl, 2587 struct ath11k_qmi, handle); 2588 struct ath11k_base *ab = qmi->ab; 2589 2590 ab->qmi.cal_done = 1; 2591 wake_up(&ab->qmi.cold_boot_waitq); 2592 ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi cold boot calibration done\n"); 2593 } 2594 2595 static const struct qmi_msg_handler ath11k_qmi_msg_handlers[] = { 2596 { 2597 .type = QMI_INDICATION, 2598 .msg_id = QMI_WLFW_REQUEST_MEM_IND_V01, 2599 .ei = qmi_wlanfw_request_mem_ind_msg_v01_ei, 2600 .decoded_size = sizeof(struct qmi_wlanfw_request_mem_ind_msg_v01), 2601 .fn = ath11k_qmi_msg_mem_request_cb, 2602 }, 2603 { 2604 .type = QMI_INDICATION, 2605 .msg_id = QMI_WLFW_FW_MEM_READY_IND_V01, 2606 .ei = qmi_wlanfw_mem_ready_ind_msg_v01_ei, 2607 .decoded_size = sizeof(struct qmi_wlanfw_fw_mem_ready_ind_msg_v01), 2608 .fn = ath11k_qmi_msg_mem_ready_cb, 2609 }, 2610 { 2611 .type = QMI_INDICATION, 2612 .msg_id = QMI_WLFW_FW_READY_IND_V01, 2613 .ei = qmi_wlanfw_fw_ready_ind_msg_v01_ei, 2614 .decoded_size = sizeof(struct qmi_wlanfw_fw_ready_ind_msg_v01), 2615 .fn = ath11k_qmi_msg_fw_ready_cb, 2616 }, 2617 { 2618 .type = QMI_INDICATION, 2619 .msg_id = QMI_WLFW_COLD_BOOT_CAL_DONE_IND_V01, 2620 .ei = qmi_wlanfw_cold_boot_cal_done_ind_msg_v01_ei, 2621 .decoded_size = 2622 sizeof(struct qmi_wlanfw_fw_cold_cal_done_ind_msg_v01), 2623 .fn = ath11k_qmi_msg_cold_boot_cal_done_cb, 2624 }, 2625 }; 2626 2627 static int ath11k_qmi_ops_new_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 struct sockaddr_qrtr *sq = &qmi->sq; 2633 int ret; 2634 2635 sq->sq_family = AF_QIPCRTR; 2636 sq->sq_node = service->node; 2637 sq->sq_port = service->port; 2638 2639 ret = kernel_connect(qmi_hdl->sock, (struct sockaddr *)sq, 2640 sizeof(*sq), 0); 2641 if (ret) { 2642 ath11k_warn(ab, "qmi failed to connect to remote service %d\n", ret); 2643 return ret; 2644 } 2645 2646 ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi wifi fw qmi service connected\n"); 2647 ath11k_qmi_driver_event_post(qmi, ATH11K_QMI_EVENT_SERVER_ARRIVE, NULL); 2648 2649 return ret; 2650 } 2651 2652 static void ath11k_qmi_ops_del_server(struct qmi_handle *qmi_hdl, 2653 struct qmi_service *service) 2654 { 2655 struct ath11k_qmi *qmi = container_of(qmi_hdl, struct ath11k_qmi, handle); 2656 struct ath11k_base *ab = qmi->ab; 2657 2658 ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi wifi fw del server\n"); 2659 ath11k_qmi_driver_event_post(qmi, ATH11K_QMI_EVENT_SERVER_EXIT, NULL); 2660 } 2661 2662 static const struct qmi_ops ath11k_qmi_ops = { 2663 .new_server = ath11k_qmi_ops_new_server, 2664 .del_server = ath11k_qmi_ops_del_server, 2665 }; 2666 2667 static void ath11k_qmi_driver_event_work(struct work_struct *work) 2668 { 2669 struct ath11k_qmi *qmi = container_of(work, struct ath11k_qmi, 2670 event_work); 2671 struct ath11k_qmi_driver_event *event; 2672 struct ath11k_base *ab = qmi->ab; 2673 int ret; 2674 2675 spin_lock(&qmi->event_lock); 2676 while (!list_empty(&qmi->event_list)) { 2677 event = list_first_entry(&qmi->event_list, 2678 struct ath11k_qmi_driver_event, list); 2679 list_del(&event->list); 2680 spin_unlock(&qmi->event_lock); 2681 2682 if (test_bit(ATH11K_FLAG_UNREGISTERING, &ab->dev_flags)) 2683 return; 2684 2685 switch (event->type) { 2686 case ATH11K_QMI_EVENT_SERVER_ARRIVE: 2687 ret = ath11k_qmi_event_server_arrive(qmi); 2688 if (ret < 0) 2689 set_bit(ATH11K_FLAG_QMI_FAIL, &ab->dev_flags); 2690 break; 2691 case ATH11K_QMI_EVENT_SERVER_EXIT: 2692 set_bit(ATH11K_FLAG_CRASH_FLUSH, &ab->dev_flags); 2693 set_bit(ATH11K_FLAG_RECOVERY, &ab->dev_flags); 2694 break; 2695 case ATH11K_QMI_EVENT_REQUEST_MEM: 2696 ret = ath11k_qmi_event_mem_request(qmi); 2697 if (ret < 0) 2698 set_bit(ATH11K_FLAG_QMI_FAIL, &ab->dev_flags); 2699 break; 2700 case ATH11K_QMI_EVENT_FW_MEM_READY: 2701 ret = ath11k_qmi_event_load_bdf(qmi); 2702 if (ret < 0) 2703 set_bit(ATH11K_FLAG_QMI_FAIL, &ab->dev_flags); 2704 break; 2705 case ATH11K_QMI_EVENT_FW_READY: 2706 clear_bit(ATH11K_FLAG_QMI_FAIL, &ab->dev_flags); 2707 if (test_bit(ATH11K_FLAG_REGISTERED, &ab->dev_flags)) { 2708 ath11k_hal_dump_srng_stats(ab); 2709 queue_work(ab->workqueue, &ab->restart_work); 2710 break; 2711 } 2712 2713 if (ath11k_cold_boot_cal && ab->qmi.cal_done == 0 && 2714 ab->hw_params.cold_boot_calib) { 2715 ath11k_qmi_process_coldboot_calibration(ab); 2716 } else { 2717 clear_bit(ATH11K_FLAG_CRASH_FLUSH, 2718 &ab->dev_flags); 2719 clear_bit(ATH11K_FLAG_RECOVERY, &ab->dev_flags); 2720 ath11k_core_qmi_firmware_ready(ab); 2721 set_bit(ATH11K_FLAG_REGISTERED, &ab->dev_flags); 2722 } 2723 2724 break; 2725 case ATH11K_QMI_EVENT_COLD_BOOT_CAL_DONE: 2726 break; 2727 default: 2728 ath11k_warn(ab, "invalid event type: %d", event->type); 2729 break; 2730 } 2731 kfree(event); 2732 spin_lock(&qmi->event_lock); 2733 } 2734 spin_unlock(&qmi->event_lock); 2735 } 2736 2737 int ath11k_qmi_init_service(struct ath11k_base *ab) 2738 { 2739 int ret; 2740 2741 memset(&ab->qmi.target, 0, sizeof(struct target_info)); 2742 memset(&ab->qmi.target_mem, 0, sizeof(struct target_mem_chunk)); 2743 ab->qmi.ab = ab; 2744 2745 ab->qmi.target_mem_mode = ATH11K_QMI_TARGET_MEM_MODE_DEFAULT; 2746 ret = qmi_handle_init(&ab->qmi.handle, ATH11K_QMI_RESP_LEN_MAX, 2747 &ath11k_qmi_ops, ath11k_qmi_msg_handlers); 2748 if (ret < 0) { 2749 ath11k_warn(ab, "failed to initialize qmi handle\n"); 2750 return ret; 2751 } 2752 2753 ab->qmi.event_wq = alloc_workqueue("ath11k_qmi_driver_event", 2754 WQ_UNBOUND, 1); 2755 if (!ab->qmi.event_wq) { 2756 ath11k_err(ab, "failed to allocate workqueue\n"); 2757 return -EFAULT; 2758 } 2759 2760 INIT_LIST_HEAD(&ab->qmi.event_list); 2761 spin_lock_init(&ab->qmi.event_lock); 2762 INIT_WORK(&ab->qmi.event_work, ath11k_qmi_driver_event_work); 2763 2764 ret = qmi_add_lookup(&ab->qmi.handle, ATH11K_QMI_WLFW_SERVICE_ID_V01, 2765 ATH11K_QMI_WLFW_SERVICE_VERS_V01, 2766 ab->qmi.service_ins_id); 2767 if (ret < 0) { 2768 ath11k_warn(ab, "failed to add qmi lookup\n"); 2769 destroy_workqueue(ab->qmi.event_wq); 2770 return ret; 2771 } 2772 2773 return ret; 2774 } 2775 2776 void ath11k_qmi_deinit_service(struct ath11k_base *ab) 2777 { 2778 qmi_handle_release(&ab->qmi.handle); 2779 cancel_work_sync(&ab->qmi.event_work); 2780 destroy_workqueue(ab->qmi.event_wq); 2781 ath11k_qmi_m3_free(ab); 2782 ath11k_qmi_free_target_mem_chunk(ab); 2783 } 2784 EXPORT_SYMBOL(ath11k_qmi_deinit_service); 2785 2786