Commit 3a009876 authored by Sean Wang's avatar Sean Wang Committed by Felix Fietkau

mt76: mt7921: robustify hardware initialization flow

Robustify hardware initialization in the current driver probing flow
to get rid of the device is possibly lost after the machine boot due
to possible firmware abnormal state by trying to recover the failure
with more chances.
Tested-by: default avatarLeon Yen <Leon.Yen@mediatek.com>
Tested-by: default avatarYN Chen <YN.Chen@mediatek.com>
Signed-off-by: default avatarSean Wang <sean.wang@mediatek.com>
Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
parent e500c947
......@@ -146,32 +146,59 @@ int mt7921_mac_init(struct mt7921_dev *dev)
return mt76_connac_mcu_set_rts_thresh(&dev->mt76, 0x92b, 0);
}
static int mt7921_init_hardware(struct mt7921_dev *dev)
static int __mt7921_init_hardware(struct mt7921_dev *dev)
{
int ret, idx;
ret = mt7921_dma_init(dev);
if (ret)
return ret;
set_bit(MT76_STATE_INITIALIZED, &dev->mphy.state);
struct mt76_dev *mdev = &dev->mt76;
int ret;
/* force firmware operation mode into normal state,
* which should be set before firmware download stage.
*/
mt76_wr(dev, MT_SWDEF_MODE, MT_SWDEF_NORMAL_MODE);
ret = mt7921_mcu_init(dev);
if (ret)
return ret;
goto out;
ret = mt7921_eeprom_init(dev);
if (ret < 0)
return ret;
if (ret)
goto out;
ret = mt7921_mcu_set_eeprom(dev);
if (ret)
goto out;
ret = mt7921_mac_init(dev);
out:
if (ret && mdev->eeprom.data) {
devm_kfree(mdev->dev, mdev->eeprom.data);
mdev->eeprom.data = NULL;
}
return ret;
}
static int mt7921_init_hardware(struct mt7921_dev *dev)
{
int ret, idx, i;
ret = mt7921_dma_init(dev);
if (ret)
return ret;
set_bit(MT76_STATE_INITIALIZED, &dev->mphy.state);
for (i = 0; i < MT7921_MCU_INIT_RETRY_COUNT; i++) {
ret = __mt7921_init_hardware(dev);
if (!ret)
break;
mt7921_wpdma_reset(dev, true);
}
if (i == MT7921_MCU_INIT_RETRY_COUNT) {
dev_err(dev->mt76.dev, "hardware init failed\n");
return ret;
}
/* Beacon and mgmt frames should occupy wcid 0 */
idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT7921_WTBL_STA - 1);
......@@ -183,7 +210,7 @@ static int mt7921_init_hardware(struct mt7921_dev *dev)
dev->mt76.global_wcid.tx_info |= MT_WCID_TX_INFO_SET;
rcu_assign_pointer(dev->mt76.wcid[idx], &dev->mt76.global_wcid);
return mt7921_mac_init(dev);
return 0;
}
int mt7921_register_device(struct mt7921_dev *dev)
......
......@@ -29,6 +29,7 @@
#define MT7921_RX_MCU_RING_SIZE 512
#define MT7921_DRV_OWN_RETRY_COUNT 10
#define MT7921_MCU_INIT_RETRY_COUNT 10
#define MT7921_FIRMWARE_WM "mediatek/WIFI_RAM_CODE_MT7961_1.bin"
#define MT7921_ROM_PATCH "mediatek/WIFI_MT7961_patch_mcu_1_2_hdr.bin"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment