old mode 100644new mode 100755.. | .. |
---|
13 | 13 | |
---|
14 | 14 | #include <linux/list.h> |
---|
15 | 15 | #include <linux/version.h> |
---|
| 16 | +#include <linux/firmware.h> |
---|
16 | 17 | #include "aicsdio_txrxif.h" |
---|
17 | 18 | #include "aicsdio.h" |
---|
18 | 19 | #include "aic_bsp_driver.h" |
---|
| 20 | + |
---|
| 21 | +static u8 binding_enc_data[16]; |
---|
| 22 | +static bool need_binding_verify; |
---|
| 23 | + |
---|
| 24 | +int wcn_bind_verify_calculate_verify_data(uint8_t *din, uint8_t *dout); |
---|
| 25 | +#ifndef CONFIG_PLATFORM_ALLWINNER |
---|
| 26 | +int wcn_bind_verify_calculate_verify_data(uint8_t *din, uint8_t *dout) |
---|
| 27 | +{ |
---|
| 28 | + return 0; |
---|
| 29 | +} |
---|
| 30 | +#endif |
---|
19 | 31 | |
---|
20 | 32 | static void cmd_dump(const struct rwnx_cmd *cmd) |
---|
21 | 33 | { |
---|
.. | .. |
---|
45 | 57 | static int cmd_mgr_queue(struct rwnx_cmd_mgr *cmd_mgr, struct rwnx_cmd *cmd) |
---|
46 | 58 | { |
---|
47 | 59 | bool defer_push = false; |
---|
| 60 | + int err = 0; |
---|
48 | 61 | |
---|
49 | 62 | spin_lock_bh(&cmd_mgr->lock); |
---|
50 | 63 | |
---|
.. | .. |
---|
98 | 111 | |
---|
99 | 112 | if (!(cmd->flags & RWNX_CMD_FLAG_NONBLOCK)) { |
---|
100 | 113 | unsigned long tout = msecs_to_jiffies(RWNX_80211_CMD_TIMEOUT_MS * cmd_mgr->queue_sz); |
---|
101 | | - if (!wait_for_completion_killable_timeout(&cmd->complete, tout)) { |
---|
| 114 | + if (!wait_for_completion_timeout(&cmd->complete, tout)) { |
---|
102 | 115 | printk(KERN_CRIT"cmd timed-out\n"); |
---|
103 | 116 | cmd_dump(cmd); |
---|
104 | 117 | spin_lock_bh(&cmd_mgr->lock); |
---|
.. | .. |
---|
108 | 121 | cmd_complete(cmd_mgr, cmd); |
---|
109 | 122 | } |
---|
110 | 123 | spin_unlock_bh(&cmd_mgr->lock); |
---|
| 124 | + err = -ETIMEDOUT; |
---|
111 | 125 | } else { |
---|
112 | 126 | kfree(cmd); |
---|
113 | 127 | } |
---|
.. | .. |
---|
115 | 129 | cmd->result = 0; |
---|
116 | 130 | } |
---|
117 | 131 | |
---|
118 | | - return 0; |
---|
| 132 | + return err; |
---|
119 | 133 | } |
---|
120 | 134 | |
---|
121 | 135 | static int cmd_mgr_run_callback(struct rwnx_cmd_mgr *cmd_mgr, struct rwnx_cmd *cmd, |
---|
.. | .. |
---|
178 | 192 | struct rwnx_cmd *cur; |
---|
179 | 193 | |
---|
180 | 194 | spin_lock_bh(&cmd_mgr->lock); |
---|
181 | | - printk("q_sz/max: %2d / %2d - next tkn: %d\n", |
---|
182 | | - cmd_mgr->queue_sz, cmd_mgr->max_queue_sz, |
---|
183 | | - cmd_mgr->next_tkn); |
---|
184 | 195 | list_for_each_entry(cur, &cmd_mgr->cmds, list) { |
---|
185 | 196 | cmd_dump(cur); |
---|
186 | 197 | } |
---|
.. | .. |
---|
301 | 312 | struct lmac_msg *msg; |
---|
302 | 313 | struct rwnx_cmd *cmd; |
---|
303 | 314 | bool nonblock; |
---|
304 | | - int ret; |
---|
| 315 | + int ret = 0; |
---|
305 | 316 | |
---|
306 | 317 | msg = container_of((void *)msg_params, struct lmac_msg, param); |
---|
307 | 318 | if (sdiodev->bus_if->state == BUS_DOWN_ST) { |
---|
.. | .. |
---|
332 | 343 | if (!reqcfm) |
---|
333 | 344 | kfree(cmd); |
---|
334 | 345 | |
---|
335 | | - return 0; |
---|
| 346 | + return ret; |
---|
336 | 347 | } |
---|
337 | 348 | |
---|
338 | 349 | |
---|
.. | .. |
---|
413 | 424 | return rwnx_send_msg(sdiodev, mem_mask_write_req, 1, DBG_MEM_MASK_WRITE_CFM, NULL); |
---|
414 | 425 | } |
---|
415 | 426 | |
---|
| 427 | +int rwnx_send_dbg_binding_req(struct aic_sdio_dev *sdiodev, u8 *dout, u8 *binding_status) |
---|
| 428 | +{ |
---|
| 429 | + struct dbg_binding_req *binding_req; |
---|
416 | 430 | |
---|
417 | | -int rwnx_send_dbg_start_app_req(struct aic_sdio_dev *sdiodev, u32 boot_addr, u32 boot_type) |
---|
| 431 | + /* Build the DBG_BINDING_REQ message */ |
---|
| 432 | + binding_req = rwnx_msg_zalloc(DBG_BINDING_REQ, TASK_DBG, DRV_TASK_ID, |
---|
| 433 | + sizeof(struct dbg_binding_req)); |
---|
| 434 | + if (!binding_req) |
---|
| 435 | + return -ENOMEM; |
---|
| 436 | + |
---|
| 437 | + memcpy(binding_req->driver_data, dout, 16); |
---|
| 438 | + |
---|
| 439 | + /* Send the DBG_MEM_MASK_WRITE_REQ message to LMAC FW */ |
---|
| 440 | + return rwnx_send_msg(sdiodev, binding_req, 1, DBG_BINDING_CFM, binding_status); |
---|
| 441 | +} |
---|
| 442 | + |
---|
| 443 | +int rwnx_send_dbg_start_app_req(struct aic_sdio_dev *sdiodev, u32 boot_addr, u32 boot_type, struct dbg_start_app_cfm *start_app_cfm) |
---|
418 | 444 | { |
---|
419 | 445 | struct dbg_start_app_req *start_app_req; |
---|
420 | 446 | |
---|
421 | 447 | /* Build the DBG_START_APP_REQ message */ |
---|
422 | 448 | start_app_req = rwnx_msg_zalloc(DBG_START_APP_REQ, TASK_DBG, DRV_TASK_ID, |
---|
423 | 449 | sizeof(struct dbg_start_app_req)); |
---|
424 | | - if (!start_app_req) |
---|
| 450 | + if (!start_app_req) { |
---|
| 451 | + printk("start app nomen\n"); |
---|
425 | 452 | return -ENOMEM; |
---|
| 453 | + } |
---|
426 | 454 | |
---|
427 | 455 | /* Set parameters for the DBG_START_APP_REQ message */ |
---|
428 | 456 | start_app_req->bootaddr = boot_addr; |
---|
429 | 457 | start_app_req->boottype = boot_type; |
---|
430 | 458 | |
---|
431 | 459 | /* Send the DBG_START_APP_REQ message to LMAC FW */ |
---|
432 | | - return rwnx_send_msg(sdiodev, start_app_req, 1, DBG_START_APP_CFM, NULL); |
---|
| 460 | + return rwnx_send_msg(sdiodev, start_app_req, 1, DBG_START_APP_CFM, start_app_cfm); |
---|
433 | 461 | } |
---|
434 | 462 | |
---|
| 463 | +static inline int dbg_binding_ind(struct rwnx_cmd *cmd, struct ipc_e2a_msg *msg) |
---|
| 464 | +{ |
---|
| 465 | + struct dbg_binding_ind *ind = (struct dbg_binding_ind *)msg->param; |
---|
| 466 | + memcpy(binding_enc_data, ind->enc_data, 16); |
---|
| 467 | + need_binding_verify = true; |
---|
| 468 | + |
---|
| 469 | + return 0; |
---|
| 470 | +} |
---|
435 | 471 | |
---|
436 | 472 | static msg_cb_fct dbg_hdlrs[MSG_I(DBG_MAX)] = { |
---|
| 473 | + [MSG_I(DBG_BINDING_IND)] = (msg_cb_fct)dbg_binding_ind, |
---|
437 | 474 | }; |
---|
438 | 475 | |
---|
439 | 476 | static msg_cb_fct *msg_hdlrs[] = { |
---|
.. | .. |
---|
446 | 483 | msg_hdlrs[MSG_T(msg->id)][MSG_I(msg->id)]); |
---|
447 | 484 | } |
---|
448 | 485 | |
---|
449 | | -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0) |
---|
450 | | -MODULE_IMPORT_NS(VFS_internal_I_am_really_a_filesystem_and_am_NOT_a_driver); |
---|
451 | | -#endif |
---|
452 | | - |
---|
453 | | -static int rwnx_load_firmware(u32 **fw_buf, const char *name, struct device *device) |
---|
454 | | -{ |
---|
455 | | - void *buffer = NULL; |
---|
456 | | - char *path = NULL; |
---|
457 | | - struct file *fp = NULL; |
---|
458 | | - int size = 0, len = 0, i = 0; |
---|
459 | | - ssize_t rdlen = 0; |
---|
460 | | - u32 *src = NULL, *dst = NULL; |
---|
461 | | - |
---|
462 | | - /* get the firmware path */ |
---|
463 | | - path = __getname(); |
---|
464 | | - if (!path) { |
---|
465 | | - *fw_buf = NULL; |
---|
466 | | - return -1; |
---|
467 | | - } |
---|
468 | | - |
---|
469 | | - len = snprintf(path, AICBSP_FW_PATH_MAX, "%s/%s", AICBSP_FW_PATH, name); |
---|
470 | | - if (len >= AICBSP_FW_PATH_MAX) { |
---|
471 | | - printk("%s: %s file's path too long\n", __func__, name); |
---|
472 | | - *fw_buf = NULL; |
---|
473 | | - __putname(path); |
---|
474 | | - return -1; |
---|
475 | | - } |
---|
476 | | - |
---|
477 | | - printk("%s :firmware path = %s \n", __func__, path); |
---|
478 | | - |
---|
479 | | - /* open the firmware file */ |
---|
480 | | - fp = filp_open(path, O_RDONLY, 0); |
---|
481 | | - if (IS_ERR_OR_NULL(fp)) { |
---|
482 | | - printk("%s: %s file failed to open\n", __func__, name); |
---|
483 | | - *fw_buf = NULL; |
---|
484 | | - __putname(path); |
---|
485 | | - fp = NULL; |
---|
486 | | - return -1; |
---|
487 | | - } |
---|
488 | | - |
---|
489 | | - size = i_size_read(file_inode(fp)); |
---|
490 | | - if (size <= 0) { |
---|
491 | | - printk("%s: %s file size invalid %d\n", __func__, name, size); |
---|
492 | | - *fw_buf = NULL; |
---|
493 | | - __putname(path); |
---|
494 | | - filp_close(fp, NULL); |
---|
495 | | - fp = NULL; |
---|
496 | | - return -1; |
---|
497 | | - } |
---|
498 | | - |
---|
499 | | - /* start to read from firmware file */ |
---|
500 | | - buffer = kzalloc(size, GFP_KERNEL); |
---|
501 | | - if (!buffer) { |
---|
502 | | - *fw_buf = NULL; |
---|
503 | | - __putname(path); |
---|
504 | | - filp_close(fp, NULL); |
---|
505 | | - fp = NULL; |
---|
506 | | - return -1; |
---|
507 | | - } |
---|
508 | | - |
---|
509 | | -#if LINUX_VERSION_CODE > KERNEL_VERSION(4, 13, 16) |
---|
510 | | - rdlen = kernel_read(fp, buffer, size, &fp->f_pos); |
---|
511 | | -#else |
---|
512 | | - rdlen = kernel_read(fp, fp->f_pos, buffer, size); |
---|
513 | | -#endif |
---|
514 | | - |
---|
515 | | - if (size != rdlen) { |
---|
516 | | - printk("%s: %s file rdlen invalid %ld\n", __func__, name, rdlen); |
---|
517 | | - *fw_buf = NULL; |
---|
518 | | - __putname(path); |
---|
519 | | - filp_close(fp, NULL); |
---|
520 | | - fp = NULL; |
---|
521 | | - kfree(buffer); |
---|
522 | | - buffer = NULL; |
---|
523 | | - return -1; |
---|
524 | | - } |
---|
525 | | - if (rdlen > 0) { |
---|
526 | | - fp->f_pos += rdlen; |
---|
527 | | - } |
---|
528 | | - |
---|
529 | | - /*start to transform the data format*/ |
---|
530 | | - src = (u32 *)buffer; |
---|
531 | | - dst = (u32 *)kzalloc(size, GFP_KERNEL); |
---|
532 | | - |
---|
533 | | - if (!dst) { |
---|
534 | | - *fw_buf = NULL; |
---|
535 | | - __putname(path); |
---|
536 | | - filp_close(fp, NULL); |
---|
537 | | - fp = NULL; |
---|
538 | | - kfree(buffer); |
---|
539 | | - buffer = NULL; |
---|
540 | | - return -1; |
---|
541 | | - } |
---|
542 | | - |
---|
543 | | - for (i = 0; i < (size/4); i++) { |
---|
544 | | - dst[i] = src[i]; |
---|
545 | | - } |
---|
546 | | - |
---|
547 | | - __putname(path); |
---|
548 | | - filp_close(fp, NULL); |
---|
549 | | - fp = NULL; |
---|
550 | | - kfree(buffer); |
---|
551 | | - buffer = NULL; |
---|
552 | | - *fw_buf = dst; |
---|
553 | | - |
---|
554 | | - return size; |
---|
555 | | -} |
---|
556 | | - |
---|
557 | 486 | int rwnx_plat_bin_fw_upload_android(struct aic_sdio_dev *sdiodev, u32 fw_addr, |
---|
558 | 487 | const char *filename) |
---|
559 | 488 | { |
---|
560 | | - struct device *dev = sdiodev->dev; |
---|
561 | 489 | unsigned int i = 0; |
---|
562 | 490 | int size; |
---|
563 | 491 | u32 *dst = NULL; |
---|
564 | 492 | int err = 0; |
---|
565 | 493 | |
---|
566 | | - /* load aic firmware */ |
---|
567 | | - size = rwnx_load_firmware(&dst, filename, dev); |
---|
| 494 | + const struct firmware *fw = NULL; |
---|
| 495 | + int ret = request_firmware(&fw, filename, NULL); |
---|
| 496 | + |
---|
| 497 | + printk("rwnx_request_firmware, name: %s\n", filename); |
---|
| 498 | + if (ret < 0) { |
---|
| 499 | + printk("Load %s fail\n", filename); |
---|
| 500 | + return ret; |
---|
| 501 | + } |
---|
| 502 | + |
---|
| 503 | + size = fw->size; |
---|
| 504 | + dst = (u32 *)fw->data; |
---|
| 505 | + |
---|
568 | 506 | if (size <= 0) { |
---|
569 | 507 | printk("wrong size of firmware file\n"); |
---|
570 | | - kfree(dst); |
---|
571 | | - dst = NULL; |
---|
| 508 | + release_firmware(fw); |
---|
572 | 509 | return -1; |
---|
573 | 510 | } |
---|
574 | 511 | |
---|
.. | .. |
---|
590 | 527 | } |
---|
591 | 528 | } |
---|
592 | 529 | |
---|
593 | | - if (dst) { |
---|
594 | | - kfree(dst); |
---|
595 | | - dst = NULL; |
---|
596 | | - } |
---|
597 | | - |
---|
| 530 | + release_firmware(fw); |
---|
598 | 531 | return err; |
---|
599 | 532 | } |
---|
600 | 533 | |
---|
.. | .. |
---|
618 | 551 | int size; |
---|
619 | 552 | struct aicbt_patch_table *head = NULL, *new = NULL, *cur = NULL; |
---|
620 | 553 | |
---|
621 | | - /* load aic firmware */ |
---|
622 | | - size = rwnx_load_firmware((u32 **)&rawdata, filename, NULL); |
---|
| 554 | + const struct firmware *fw = NULL; |
---|
| 555 | + int ret = request_firmware(&fw, filename, NULL); |
---|
| 556 | + |
---|
| 557 | + printk("rwnx_request_firmware, name: %s\n", filename); |
---|
| 558 | + if (ret < 0) { |
---|
| 559 | + printk("Load %s fail\n", filename); |
---|
| 560 | + return NULL; |
---|
| 561 | + } |
---|
| 562 | + |
---|
| 563 | + rawdata = (uint8_t *)fw->data; |
---|
| 564 | + size = fw->size; |
---|
| 565 | + |
---|
623 | 566 | if (size <= 0) { |
---|
624 | 567 | printk("wrong size of firmware file\n"); |
---|
625 | 568 | goto err; |
---|
.. | .. |
---|
657 | 600 | memcpy(cur->data, p, cur->len * 8); |
---|
658 | 601 | p += cur->len * 8; |
---|
659 | 602 | } |
---|
660 | | - kfree(rawdata); |
---|
| 603 | + release_firmware(fw); |
---|
661 | 604 | return head; |
---|
662 | 605 | |
---|
663 | 606 | err: |
---|
664 | 607 | aicbt_patch_table_free(&head); |
---|
665 | | - if (rawdata) |
---|
666 | | - kfree(rawdata); |
---|
| 608 | + release_firmware(fw); |
---|
667 | 609 | return NULL; |
---|
668 | 610 | } |
---|
669 | 611 | |
---|
670 | | -bool aicbt_patch_trap_data_load(struct aic_sdio_dev *sdiodev) |
---|
| 612 | +int aicbt_patch_trap_data_load(struct aic_sdio_dev *sdiodev) |
---|
671 | 613 | { |
---|
672 | | - if (rwnx_plat_bin_fw_upload_android(sdiodev, FW_RAM_ADID_BASE_ADDR, aicbsp_firmware_list[aicbsp_mode_index].bt_adid)) |
---|
673 | | - return false; |
---|
674 | | - if (rwnx_plat_bin_fw_upload_android(sdiodev, FW_RAM_PATCH_BASE_ADDR, aicbsp_firmware_list[aicbsp_mode_index].bt_patch)) |
---|
675 | | - return false; |
---|
676 | | - if (aicbsp_firmware_list[aicbsp_mode_index].bt_patch_test && |
---|
677 | | - rwnx_plat_bin_fw_upload_android(sdiodev, FW_PATCH_TEST_BASE_ADDR, aicbsp_firmware_list[aicbsp_mode_index].bt_patch_test)) |
---|
678 | | - return false; |
---|
679 | | - return true; |
---|
| 614 | + uint32_t fw_ram_adid_base_addr = FW_RAM_ADID_BASE_ADDR; |
---|
| 615 | + if (aicbsp_info.chip_rev != CHIP_REV_U02) |
---|
| 616 | + fw_ram_adid_base_addr = FW_RAM_ADID_BASE_ADDR_U03; |
---|
| 617 | + |
---|
| 618 | + if (rwnx_plat_bin_fw_upload_android(sdiodev, fw_ram_adid_base_addr, aicbsp_firmware_list[aicbsp_info.cpmode].bt_adid)) |
---|
| 619 | + return -1; |
---|
| 620 | + if (rwnx_plat_bin_fw_upload_android(sdiodev, FW_RAM_PATCH_BASE_ADDR, aicbsp_firmware_list[aicbsp_info.cpmode].bt_patch)) |
---|
| 621 | + return -1; |
---|
| 622 | + return 0; |
---|
680 | 623 | } |
---|
| 624 | + |
---|
| 625 | +static struct aicbt_info_t aicbt_info = { |
---|
| 626 | + .btmode = AICBT_BTMODE_DEFAULT, |
---|
| 627 | + .btport = AICBT_BTPORT_DEFAULT, |
---|
| 628 | + .uart_baud = AICBT_UART_BAUD_DEFAULT, |
---|
| 629 | + .uart_flowctrl = AICBT_UART_FC_DEFAULT, |
---|
| 630 | + .lpm_enable = AICBT_LPM_ENABLE_DEFAULT, |
---|
| 631 | + .txpwr_lvl = AICBT_TXPWR_LVL_DEFAULT, |
---|
| 632 | +}; |
---|
681 | 633 | |
---|
682 | 634 | int aicbt_patch_table_load(struct aic_sdio_dev *sdiodev) |
---|
683 | 635 | { |
---|
684 | 636 | struct aicbt_patch_table *head, *p; |
---|
685 | 637 | int ret = 0, i; |
---|
686 | 638 | uint32_t *data = NULL; |
---|
687 | | - head = aicbt_patch_table_alloc(aicbsp_firmware_list[aicbsp_mode_index].bt_table); |
---|
| 639 | + head = aicbt_patch_table_alloc(aicbsp_firmware_list[aicbsp_info.cpmode].bt_table); |
---|
688 | 640 | for (p = head; p != NULL; p = p->next) { |
---|
689 | 641 | data = p->data; |
---|
690 | 642 | if (AICBT_PT_BTMODE == p->type) { |
---|
691 | | - ret = rwnx_send_dbg_mem_write_req(sdiodev, *data, aicbsp_mode_index); |
---|
| 643 | + *(data + 1) = aicbsp_info.hwinfo < 0; |
---|
| 644 | + *(data + 3) = aicbsp_info.hwinfo; |
---|
| 645 | + *(data + 5) = aicbsp_info.cpmode; |
---|
| 646 | + |
---|
| 647 | + *(data + 7) = aicbt_info.btmode; |
---|
| 648 | + *(data + 9) = aicbt_info.btport; |
---|
| 649 | + *(data + 11) = aicbt_info.uart_baud; |
---|
| 650 | + *(data + 13) = aicbt_info.uart_flowctrl; |
---|
| 651 | + *(data + 15) = aicbt_info.lpm_enable; |
---|
| 652 | + *(data + 17) = aicbt_info.txpwr_lvl; |
---|
| 653 | + |
---|
| 654 | + printk("%s bt uart baud: %d, flowctrl: %d, lpm_enable: %d, tx_pwr: %d\n", __func__, |
---|
| 655 | + aicbt_info.uart_baud, aicbt_info.uart_flowctrl, aicbt_info.lpm_enable, aicbt_info.txpwr_lvl); |
---|
| 656 | + } |
---|
| 657 | + |
---|
| 658 | + if (AICBT_PT_VER == p->type) { |
---|
| 659 | + printk("aicbsp: bt patch version: %s\n", (char *)p->data); |
---|
692 | 660 | continue; |
---|
693 | 661 | } |
---|
| 662 | + |
---|
694 | 663 | for (i = 0; i < p->len; i++) { |
---|
695 | 664 | ret = rwnx_send_dbg_mem_write_req(sdiodev, *data, *(data + 1)); |
---|
696 | 665 | if (ret != 0) |
---|
.. | .. |
---|
704 | 673 | return 0; |
---|
705 | 674 | } |
---|
706 | 675 | |
---|
707 | | -void aicbt_init(struct aic_sdio_dev *sdiodev) |
---|
| 676 | +int aicbt_init(struct aic_sdio_dev *sdiodev) |
---|
708 | 677 | { |
---|
709 | | - aicbt_patch_trap_data_load(sdiodev); |
---|
710 | | - aicbt_patch_table_load(sdiodev); |
---|
| 678 | + if (aicbt_patch_trap_data_load(sdiodev)) { |
---|
| 679 | + printk("aicbt_patch_trap_data_load fail\n"); |
---|
| 680 | + return -1; |
---|
| 681 | + } |
---|
| 682 | + |
---|
| 683 | + if (aicbt_patch_table_load(sdiodev)) { |
---|
| 684 | + printk("aicbt_patch_table_load fail\n"); |
---|
| 685 | + return -1; |
---|
| 686 | + } |
---|
| 687 | + |
---|
| 688 | + return 0; |
---|
711 | 689 | } |
---|
712 | 690 | |
---|
713 | 691 | static int aicwifi_start_from_bootrom(struct aic_sdio_dev *sdiodev) |
---|
.. | .. |
---|
716 | 694 | |
---|
717 | 695 | /* memory access */ |
---|
718 | 696 | const u32 fw_addr = RAM_FMAC_FW_ADDR; |
---|
| 697 | + struct dbg_start_app_cfm start_app_cfm; |
---|
719 | 698 | |
---|
720 | 699 | /* fw start */ |
---|
721 | | - ret = rwnx_send_dbg_start_app_req(sdiodev, fw_addr, HOST_START_APP_AUTO); |
---|
| 700 | + ret = rwnx_send_dbg_start_app_req(sdiodev, fw_addr, HOST_START_APP_AUTO, &start_app_cfm); |
---|
722 | 701 | if (ret) { |
---|
723 | 702 | return -1; |
---|
724 | 703 | } |
---|
| 704 | + aicbsp_info.hwinfo_r = start_app_cfm.bootstatus & 0xFF; |
---|
| 705 | + |
---|
725 | 706 | return 0; |
---|
726 | 707 | } |
---|
727 | 708 | |
---|
.. | .. |
---|
736 | 717 | {0x40344058, 0x00800000, 0x00000000},// pll trx |
---|
737 | 718 | }; |
---|
738 | 719 | |
---|
739 | | -static void aicwifi_sys_config(struct aic_sdio_dev *sdiodev) |
---|
| 720 | +static int aicwifi_sys_config(struct aic_sdio_dev *sdiodev) |
---|
740 | 721 | { |
---|
741 | 722 | int ret, cnt; |
---|
742 | 723 | int syscfg_num = sizeof(syscfg_tbl_masked) / sizeof(u32) / 3; |
---|
.. | .. |
---|
745 | 726 | syscfg_tbl_masked[cnt][0], syscfg_tbl_masked[cnt][1], syscfg_tbl_masked[cnt][2]); |
---|
746 | 727 | if (ret) { |
---|
747 | 728 | printk("%x mask write fail: %d\n", syscfg_tbl_masked[cnt][0], ret); |
---|
| 729 | + return ret; |
---|
748 | 730 | } |
---|
749 | 731 | } |
---|
750 | 732 | |
---|
.. | .. |
---|
752 | 734 | rf_tbl_masked[0][0], rf_tbl_masked[0][1], rf_tbl_masked[0][2]); |
---|
753 | 735 | if (ret) { |
---|
754 | 736 | printk("rf config %x write fail: %d\n", rf_tbl_masked[0][0], ret); |
---|
| 737 | + return ret; |
---|
755 | 738 | } |
---|
| 739 | + |
---|
| 740 | + return 0; |
---|
756 | 741 | } |
---|
757 | 742 | |
---|
758 | | -static void aicwifi_patch_config(struct aic_sdio_dev *sdiodev) |
---|
| 743 | +static int aicwifi_patch_config(struct aic_sdio_dev *sdiodev) |
---|
759 | 744 | { |
---|
760 | 745 | const u32 rd_patch_addr = RAM_FMAC_FW_ADDR + 0x0180; |
---|
761 | 746 | u32 config_base; |
---|
.. | .. |
---|
765 | 750 | struct dbg_mem_read_cfm rd_patch_addr_cfm; |
---|
766 | 751 | int ret = 0; |
---|
767 | 752 | u16 cnt = 0; |
---|
| 753 | + u32 patch_addr_reg = 0x1e5318; |
---|
| 754 | + u32 patch_num_reg = 0x1e531c; |
---|
| 755 | + |
---|
| 756 | + if (aicbsp_info.cpmode == AICBSP_CPMODE_TEST) { |
---|
| 757 | + patch_addr_reg = 0x1e5304; |
---|
| 758 | + patch_num_reg = 0x1e5308; |
---|
| 759 | + } |
---|
768 | 760 | |
---|
769 | 761 | ret = rwnx_send_dbg_mem_read_req(sdiodev, rd_patch_addr, &rd_patch_addr_cfm); |
---|
770 | 762 | if (ret) { |
---|
771 | 763 | printk("patch rd fail\n"); |
---|
| 764 | + return ret; |
---|
772 | 765 | } |
---|
773 | 766 | |
---|
774 | 767 | config_base = rd_patch_addr_cfm.memdata; |
---|
775 | 768 | |
---|
776 | | - ret = rwnx_send_dbg_mem_write_req(sdiodev, 0x1e4d28, patch_addr); |
---|
| 769 | + ret = rwnx_send_dbg_mem_write_req(sdiodev, patch_addr_reg, patch_addr); |
---|
777 | 770 | if (ret) { |
---|
778 | | - printk("%x write fail\n", 0x1e4d28); |
---|
| 771 | + printk("0x%x write fail\n", patch_addr_reg); |
---|
| 772 | + return ret; |
---|
779 | 773 | } |
---|
780 | 774 | |
---|
781 | | - ret = rwnx_send_dbg_mem_write_req(sdiodev, 0x1e4d2c, patch_num); |
---|
| 775 | + ret = rwnx_send_dbg_mem_write_req(sdiodev, patch_num_reg, patch_num); |
---|
782 | 776 | if (ret) { |
---|
783 | | - printk("%x write fail\n", 0x1e4d2c); |
---|
| 777 | + printk("0x%x write fail\n", patch_num_reg); |
---|
| 778 | + return ret; |
---|
784 | 779 | } |
---|
785 | 780 | |
---|
786 | 781 | for (cnt = 0; cnt < patch_num/2; cnt += 1) { |
---|
787 | 782 | ret = rwnx_send_dbg_mem_write_req(sdiodev, start_addr+8*cnt, patch_tbl[cnt][0]+config_base); |
---|
788 | 783 | if (ret) { |
---|
789 | 784 | printk("%x write fail\n", start_addr+8*cnt); |
---|
| 785 | + return ret; |
---|
790 | 786 | } |
---|
791 | 787 | |
---|
792 | 788 | ret = rwnx_send_dbg_mem_write_req(sdiodev, start_addr+8*cnt+4, patch_tbl[cnt][1]); |
---|
793 | 789 | if (ret) { |
---|
794 | 790 | printk("%x write fail\n", start_addr+8*cnt+4); |
---|
| 791 | + return ret; |
---|
795 | 792 | } |
---|
796 | 793 | } |
---|
| 794 | + |
---|
| 795 | + return 0; |
---|
797 | 796 | } |
---|
798 | 797 | |
---|
799 | | -void aicwifi_init(struct aic_sdio_dev *sdiodev) |
---|
| 798 | +int aicwifi_init(struct aic_sdio_dev *sdiodev) |
---|
800 | 799 | { |
---|
801 | | - if (rwnx_plat_bin_fw_upload_android(sdiodev, FW_WIFI_RAM_ADDR, aicbsp_firmware_list[aicbsp_mode_index].wl_fw)) { |
---|
| 800 | + if (rwnx_plat_bin_fw_upload_android(sdiodev, RAM_FMAC_FW_ADDR, aicbsp_firmware_list[aicbsp_info.cpmode].wl_fw)) { |
---|
802 | 801 | printk("download wifi fw fail\n"); |
---|
803 | | - return; |
---|
| 802 | + return -1; |
---|
804 | 803 | } |
---|
805 | 804 | |
---|
806 | | - aicwifi_patch_config(sdiodev); |
---|
807 | | - aicwifi_sys_config(sdiodev); |
---|
| 805 | + if (aicwifi_patch_config(sdiodev)) { |
---|
| 806 | + printk("aicwifi_patch_config fail\n"); |
---|
| 807 | + return -1; |
---|
| 808 | + } |
---|
808 | 809 | |
---|
809 | | - aicwifi_start_from_bootrom(sdiodev); |
---|
| 810 | + if (aicwifi_sys_config(sdiodev)) { |
---|
| 811 | + printk("aicwifi_sys_config fail\n"); |
---|
| 812 | + return -1; |
---|
| 813 | + } |
---|
| 814 | + |
---|
| 815 | + if (aicwifi_start_from_bootrom(sdiodev)) { |
---|
| 816 | + printk("wifi start fail\n"); |
---|
| 817 | + return -1; |
---|
| 818 | + } |
---|
| 819 | + |
---|
| 820 | + return 0; |
---|
810 | 821 | } |
---|
811 | 822 | |
---|
812 | 823 | u32 aicbsp_syscfg_tbl[][2] = { |
---|
813 | | - {0x40500014, 0x00000102}, // 1) |
---|
814 | | - {0x40500018, 0x0000010D}, // 2) |
---|
| 824 | + {0x40500014, 0x00000101}, // 1) |
---|
| 825 | + {0x40500018, 0x00000109}, // 2) |
---|
815 | 826 | {0x40500004, 0x00000010}, // 3) the order should not be changed |
---|
816 | 827 | |
---|
817 | 828 | // def CONFIG_PMIC_SETTING |
---|
.. | .. |
---|
826 | 837 | {0x50017008, 0x00000000}, // 4) stop wdg |
---|
827 | 838 | }; |
---|
828 | 839 | |
---|
829 | | -static void aicbsp_system_config(struct aic_sdio_dev *sdiodev) |
---|
| 840 | +static int aicbsp_system_config(struct aic_sdio_dev *sdiodev) |
---|
830 | 841 | { |
---|
831 | 842 | int syscfg_num = sizeof(aicbsp_syscfg_tbl) / sizeof(u32) / 2; |
---|
832 | 843 | int ret, cnt; |
---|
.. | .. |
---|
834 | 845 | ret = rwnx_send_dbg_mem_write_req(sdiodev, aicbsp_syscfg_tbl[cnt][0], aicbsp_syscfg_tbl[cnt][1]); |
---|
835 | 846 | if (ret) { |
---|
836 | 847 | sdio_err("%x write fail: %d\n", aicbsp_syscfg_tbl[cnt][0], ret); |
---|
| 848 | + return ret; |
---|
837 | 849 | } |
---|
838 | 850 | } |
---|
| 851 | + return 0; |
---|
839 | 852 | } |
---|
840 | 853 | |
---|
841 | 854 | int aicbsp_platform_init(struct aic_sdio_dev *sdiodev) |
---|
842 | 855 | { |
---|
843 | 856 | rwnx_cmd_mgr_init(&sdiodev->cmd_mgr); |
---|
844 | 857 | sdiodev->cmd_mgr.sdiodev = (void *)sdiodev; |
---|
845 | | - aicbsp_system_config(sdiodev); |
---|
846 | 858 | return 0; |
---|
847 | 859 | } |
---|
848 | 860 | |
---|
.. | .. |
---|
851 | 863 | (void)sdiodev; |
---|
852 | 864 | } |
---|
853 | 865 | |
---|
854 | | -void aicbsp_driver_fw_init(struct aic_sdio_dev *sdiodev) |
---|
| 866 | +int aicbsp_driver_fw_init(struct aic_sdio_dev *sdiodev) |
---|
855 | 867 | { |
---|
856 | | - aicbt_init(sdiodev); |
---|
857 | | - aicwifi_init(sdiodev); |
---|
| 868 | + const u32 mem_addr = 0x40500000; |
---|
| 869 | + struct dbg_mem_read_cfm rd_mem_addr_cfm; |
---|
| 870 | + |
---|
| 871 | + uint8_t binding_status; |
---|
| 872 | + uint8_t dout[16]; |
---|
| 873 | + |
---|
| 874 | + need_binding_verify = false; |
---|
| 875 | + |
---|
| 876 | + if (rwnx_send_dbg_mem_read_req(sdiodev, mem_addr, &rd_mem_addr_cfm)) |
---|
| 877 | + return -1; |
---|
| 878 | + |
---|
| 879 | + aicbsp_info.chip_rev = (u8)(rd_mem_addr_cfm.memdata >> 16); |
---|
| 880 | + if (aicbsp_info.chip_rev != CHIP_REV_U02 && |
---|
| 881 | + aicbsp_info.chip_rev != CHIP_REV_U03 && |
---|
| 882 | + aicbsp_info.chip_rev != CHIP_REV_U04) { |
---|
| 883 | + pr_err("aicbsp: %s, unsupport chip rev: %d\n", __func__, aicbsp_info.chip_rev); |
---|
| 884 | + return -1; |
---|
| 885 | + } |
---|
| 886 | + |
---|
| 887 | + printk("aicbsp: %s, chip rev: %d\n", __func__, aicbsp_info.chip_rev); |
---|
| 888 | + |
---|
| 889 | + if (aicbsp_info.chip_rev != CHIP_REV_U02) |
---|
| 890 | + aicbsp_firmware_list = fw_u03; |
---|
| 891 | + |
---|
| 892 | + if (aicbsp_system_config(sdiodev)) |
---|
| 893 | + return -1; |
---|
| 894 | + |
---|
| 895 | + if (aicbt_init(sdiodev)) |
---|
| 896 | + return -1; |
---|
| 897 | + |
---|
| 898 | + if (aicwifi_init(sdiodev)) |
---|
| 899 | + return -1; |
---|
| 900 | + |
---|
| 901 | + if (need_binding_verify) { |
---|
| 902 | + printk("aicbsp: crypto data %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n", |
---|
| 903 | + binding_enc_data[0], binding_enc_data[1], binding_enc_data[2], binding_enc_data[3], |
---|
| 904 | + binding_enc_data[4], binding_enc_data[5], binding_enc_data[6], binding_enc_data[7], |
---|
| 905 | + binding_enc_data[8], binding_enc_data[9], binding_enc_data[10], binding_enc_data[11], |
---|
| 906 | + binding_enc_data[12], binding_enc_data[13], binding_enc_data[14], binding_enc_data[15]); |
---|
| 907 | + |
---|
| 908 | + /* calculate verify data from crypto data */ |
---|
| 909 | + if (wcn_bind_verify_calculate_verify_data(binding_enc_data, dout)) { |
---|
| 910 | + pr_err("aicbsp: %s, binding encrypt data incorrect\n", __func__); |
---|
| 911 | + return -1; |
---|
| 912 | + } |
---|
| 913 | + |
---|
| 914 | + printk("aicbsp: verify data %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n", |
---|
| 915 | + dout[0], dout[1], dout[2], dout[3], |
---|
| 916 | + dout[4], dout[5], dout[6], dout[7], |
---|
| 917 | + dout[8], dout[9], dout[10], dout[11], |
---|
| 918 | + dout[12], dout[13], dout[14], dout[15]); |
---|
| 919 | + |
---|
| 920 | + if (rwnx_send_dbg_binding_req(sdiodev, dout, &binding_status)) { |
---|
| 921 | + pr_err("aicbsp: %s, send binding request failn", __func__); |
---|
| 922 | + return -1; |
---|
| 923 | + } |
---|
| 924 | + |
---|
| 925 | + if (binding_status) { |
---|
| 926 | + pr_err("aicbsp: %s, binding verify fail\n", __func__); |
---|
| 927 | + return -1; |
---|
| 928 | + } |
---|
| 929 | + } |
---|
| 930 | + |
---|
| 931 | + if (aicwf_sdio_writeb(sdiodev, SDIOWIFI_WAKEUP_REG, 4)) { |
---|
| 932 | + sdio_err("reg:%d write failed!\n", SDIOWIFI_WAKEUP_REG); |
---|
| 933 | + return -1; |
---|
| 934 | + } |
---|
| 935 | + |
---|
| 936 | + return 0; |
---|
858 | 937 | } |
---|
859 | 938 | |
---|
860 | 939 | int aicbsp_get_feature(struct aicbsp_feature_t *feature) |
---|
861 | 940 | { |
---|
862 | 941 | feature->sdio_clock = FEATURE_SDIO_CLOCK; |
---|
863 | 942 | feature->sdio_phase = FEATURE_SDIO_PHASE; |
---|
864 | | - if (aicbsp_mode_index == AICBSP_MODE_BT_ONLY_SW && FEATURE_5G_SUPPORT) |
---|
865 | | - feature->band_5g_support = true; |
---|
| 943 | + feature->hwinfo = aicbsp_info.hwinfo; |
---|
| 944 | + feature->fwlog_en = aicbsp_info.fwlog_en; |
---|
866 | 945 | return 0; |
---|
867 | 946 | } |
---|
868 | 947 | EXPORT_SYMBOL_GPL(aicbsp_get_feature); |
---|
| 948 | + |
---|
| 949 | +#ifdef AICBSP_RESV_MEM_SUPPORT |
---|
| 950 | +static struct skb_buff_pool resv_skb[] = { |
---|
| 951 | + {AIC_RESV_MEM_TXDATA, 1536*64, "resv_mem_txdata", 0, NULL}, |
---|
| 952 | +}; |
---|
| 953 | + |
---|
| 954 | +int aicbsp_resv_mem_init(void) |
---|
| 955 | +{ |
---|
| 956 | + int i = 0; |
---|
| 957 | + for (i = 0; i < sizeof(resv_skb) / sizeof(resv_skb[0]); i++) { |
---|
| 958 | + resv_skb[i].skb = dev_alloc_skb(resv_skb[i].size); |
---|
| 959 | + } |
---|
| 960 | + return 0; |
---|
| 961 | +} |
---|
| 962 | + |
---|
| 963 | +int aicbsp_resv_mem_deinit(void) |
---|
| 964 | +{ |
---|
| 965 | + int i = 0; |
---|
| 966 | + for (i = 0; i < sizeof(resv_skb) / sizeof(resv_skb[0]); i++) { |
---|
| 967 | + if (resv_skb[i].used == 0 && resv_skb[i].skb) |
---|
| 968 | + dev_kfree_skb(resv_skb[i].skb); |
---|
| 969 | + } |
---|
| 970 | + return 0; |
---|
| 971 | +} |
---|
| 972 | + |
---|
| 973 | +struct sk_buff *aicbsp_resv_mem_alloc_skb(unsigned int length, uint32_t id) |
---|
| 974 | +{ |
---|
| 975 | + if (resv_skb[id].size < length) { |
---|
| 976 | + pr_err("aicbsp: %s, no enough mem\n", __func__); |
---|
| 977 | + goto fail; |
---|
| 978 | + } |
---|
| 979 | + |
---|
| 980 | + if (resv_skb[id].used) { |
---|
| 981 | + pr_err("aicbsp: %s, mem in use\n", __func__); |
---|
| 982 | + goto fail; |
---|
| 983 | + } |
---|
| 984 | + |
---|
| 985 | + if (resv_skb[id].skb == NULL) { |
---|
| 986 | + pr_err("aicbsp: %s, mem not initialazed\n", __func__); |
---|
| 987 | + resv_skb[id].skb = dev_alloc_skb(resv_skb[id].size); |
---|
| 988 | + if (resv_skb[id].skb == NULL) { |
---|
| 989 | + pr_err("aicbsp: %s, mem reinitial still fail\n", __func__); |
---|
| 990 | + goto fail; |
---|
| 991 | + } |
---|
| 992 | + } |
---|
| 993 | + |
---|
| 994 | + printk("aicbsp: %s, alloc %s succuss, id: %d, size: %d\n", __func__, |
---|
| 995 | + resv_skb[id].name, resv_skb[id].id, resv_skb[id].size); |
---|
| 996 | + |
---|
| 997 | + resv_skb[id].used = 1; |
---|
| 998 | + return resv_skb[id].skb; |
---|
| 999 | + |
---|
| 1000 | +fail: |
---|
| 1001 | + return NULL; |
---|
| 1002 | +} |
---|
| 1003 | +EXPORT_SYMBOL_GPL(aicbsp_resv_mem_alloc_skb); |
---|
| 1004 | + |
---|
| 1005 | +void aicbsp_resv_mem_kfree_skb(struct sk_buff *skb, uint32_t id) |
---|
| 1006 | +{ |
---|
| 1007 | + resv_skb[id].used = 0; |
---|
| 1008 | + printk("aicbsp: %s, free %s succuss, id: %d, size: %d\n", __func__, |
---|
| 1009 | + resv_skb[id].name, resv_skb[id].id, resv_skb[id].size); |
---|
| 1010 | +} |
---|
| 1011 | +EXPORT_SYMBOL_GPL(aicbsp_resv_mem_kfree_skb); |
---|
| 1012 | + |
---|
| 1013 | +#else |
---|
| 1014 | + |
---|
| 1015 | +int aicbsp_resv_mem_init(void) |
---|
| 1016 | +{ |
---|
| 1017 | + return 0; |
---|
| 1018 | +} |
---|
| 1019 | + |
---|
| 1020 | +int aicbsp_resv_mem_deinit(void) |
---|
| 1021 | +{ |
---|
| 1022 | + return 0; |
---|
| 1023 | +} |
---|
| 1024 | + |
---|
| 1025 | +#endif |
---|