mcu.c (fe0195f7563314a88cf08a1e7e528d3c0266fbbe) | mcu.c (48fab5bbef4092d925ab3214773ad12e68807223) |
---|---|
1// SPDX-License-Identifier: ISC 2/* Copyright (C) 2020 MediaTek Inc. */ 3 4#include <linux/firmware.h> 5#include <linux/fs.h> 6#include "mt7921.h" 7#include "mt7921_trace.h" 8#include "mcu.h" --- 636 unchanged lines hidden (view full) --- 645 646 return ret; 647} 648 649static int mt7921_load_patch(struct mt7921_dev *dev) 650{ 651 const struct mt7921_patch_hdr *hdr; 652 const struct firmware *fw = NULL; | 1// SPDX-License-Identifier: ISC 2/* Copyright (C) 2020 MediaTek Inc. */ 3 4#include <linux/firmware.h> 5#include <linux/fs.h> 6#include "mt7921.h" 7#include "mt7921_trace.h" 8#include "mcu.h" --- 636 unchanged lines hidden (view full) --- 645 646 return ret; 647} 648 649static int mt7921_load_patch(struct mt7921_dev *dev) 650{ 651 const struct mt7921_patch_hdr *hdr; 652 const struct firmware *fw = NULL; |
653 int i, ret, sem; | 653 int i, ret, sem, max_len; |
654 | 654 |
655 max_len = mt76_is_sdio(&dev->mt76) ? 2048 : 4096; 656 |
|
655 sem = mt76_connac_mcu_patch_sem_ctrl(&dev->mt76, true); 656 switch (sem) { 657 case PATCH_IS_DL: 658 return 0; 659 case PATCH_NOT_DL_SEM_SUCCESS: 660 break; 661 default: 662 dev_err(dev->mt76.dev, "Failed to get patch semaphore\n"); --- 38 unchanged lines hidden (view full) --- 701 ret = mt76_connac_mcu_init_download(&dev->mt76, addr, len, 702 mode); 703 if (ret) { 704 dev_err(dev->mt76.dev, "Download request failed\n"); 705 goto out; 706 } 707 708 ret = __mt76_mcu_send_firmware(&dev->mt76, MCU_CMD_FW_SCATTER, | 657 sem = mt76_connac_mcu_patch_sem_ctrl(&dev->mt76, true); 658 switch (sem) { 659 case PATCH_IS_DL: 660 return 0; 661 case PATCH_NOT_DL_SEM_SUCCESS: 662 break; 663 default: 664 dev_err(dev->mt76.dev, "Failed to get patch semaphore\n"); --- 38 unchanged lines hidden (view full) --- 703 ret = mt76_connac_mcu_init_download(&dev->mt76, addr, len, 704 mode); 705 if (ret) { 706 dev_err(dev->mt76.dev, "Download request failed\n"); 707 goto out; 708 } 709 710 ret = __mt76_mcu_send_firmware(&dev->mt76, MCU_CMD_FW_SCATTER, |
709 dl, len, 4096); | 711 dl, len, max_len); |
710 if (ret) { 711 dev_err(dev->mt76.dev, "Failed to send patch\n"); 712 goto out; 713 } 714 } 715 716 ret = mt76_connac_mcu_start_patch(&dev->mt76); 717 if (ret) --- 30 unchanged lines hidden (view full) --- 748 return ret; 749} 750 751static int 752mt7921_mcu_send_ram_firmware(struct mt7921_dev *dev, 753 const struct mt7921_fw_trailer *hdr, 754 const u8 *data, bool is_wa) 755{ | 712 if (ret) { 713 dev_err(dev->mt76.dev, "Failed to send patch\n"); 714 goto out; 715 } 716 } 717 718 ret = mt76_connac_mcu_start_patch(&dev->mt76); 719 if (ret) --- 30 unchanged lines hidden (view full) --- 750 return ret; 751} 752 753static int 754mt7921_mcu_send_ram_firmware(struct mt7921_dev *dev, 755 const struct mt7921_fw_trailer *hdr, 756 const u8 *data, bool is_wa) 757{ |
756 int i, offset = 0; | 758 int i, offset = 0, max_len; |
757 u32 override = 0, option = 0; 758 | 759 u32 override = 0, option = 0; 760 |
761 max_len = mt76_is_sdio(&dev->mt76) ? 2048 : 4096; 762 |
|
759 for (i = 0; i < hdr->n_region; i++) { 760 const struct mt7921_fw_region *region; 761 int err; 762 u32 len, addr, mode; 763 764 region = (const struct mt7921_fw_region *)((const u8 *)hdr - 765 (hdr->n_region - i) * sizeof(*region)); 766 mode = mt7921_mcu_gen_dl_mode(region->feature_set, is_wa); --- 6 unchanged lines hidden (view full) --- 773 err = mt76_connac_mcu_init_download(&dev->mt76, addr, len, 774 mode); 775 if (err) { 776 dev_err(dev->mt76.dev, "Download request failed\n"); 777 return err; 778 } 779 780 err = __mt76_mcu_send_firmware(&dev->mt76, MCU_CMD_FW_SCATTER, | 763 for (i = 0; i < hdr->n_region; i++) { 764 const struct mt7921_fw_region *region; 765 int err; 766 u32 len, addr, mode; 767 768 region = (const struct mt7921_fw_region *)((const u8 *)hdr - 769 (hdr->n_region - i) * sizeof(*region)); 770 mode = mt7921_mcu_gen_dl_mode(region->feature_set, is_wa); --- 6 unchanged lines hidden (view full) --- 777 err = mt76_connac_mcu_init_download(&dev->mt76, addr, len, 778 mode); 779 if (err) { 780 dev_err(dev->mt76.dev, "Download request failed\n"); 781 return err; 782 } 783 784 err = __mt76_mcu_send_firmware(&dev->mt76, MCU_CMD_FW_SCATTER, |
781 data + offset, len, 4096); | 785 data + offset, len, max_len); |
782 if (err) { 783 dev_err(dev->mt76.dev, "Failed to send firmware.\n"); 784 return err; 785 } 786 787 offset += len; 788 } 789 --- 56 unchanged lines hidden (view full) --- 846 return ret; 847} 848 849static int mt7921_load_firmware(struct mt7921_dev *dev) 850{ 851 int ret; 852 853 ret = mt76_get_field(dev, MT_CONN_ON_MISC, MT_TOP_MISC2_FW_N9_RDY); | 786 if (err) { 787 dev_err(dev->mt76.dev, "Failed to send firmware.\n"); 788 return err; 789 } 790 791 offset += len; 792 } 793 --- 56 unchanged lines hidden (view full) --- 850 return ret; 851} 852 853static int mt7921_load_firmware(struct mt7921_dev *dev) 854{ 855 int ret; 856 857 ret = mt76_get_field(dev, MT_CONN_ON_MISC, MT_TOP_MISC2_FW_N9_RDY); |
854 if (ret) { | 858 if (ret && mt76_is_mmio(&dev->mt76)) { |
855 dev_dbg(dev->mt76.dev, "Firmware is already download\n"); 856 goto fw_loaded; 857 } 858 859 ret = mt7921_load_patch(dev); 860 if (ret) 861 return ret; 862 --- 490 unchanged lines hidden --- | 859 dev_dbg(dev->mt76.dev, "Firmware is already download\n"); 860 goto fw_loaded; 861 } 862 863 ret = mt7921_load_patch(dev); 864 if (ret) 865 return ret; 866 --- 490 unchanged lines hidden --- |