1

wifi: mt76: mt7921: move runtime-pm pci code in mt792x-lib

Move the following runtime-pm pci routines in mt792x-lib since they are
shared between mt7921 and mt7925 chipsets:
- __mt7921e_mcu_drv_pmctrl
- mt7921e_mcu_drv_pmctrl
- mt7921e_mcu_fw_pmctrl

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
Lorenzo Bianconi 2023-06-28 15:07:17 +08:00 committed by Felix Fietkau
parent c21a7f9f40
commit 1c0254967d
8 changed files with 85 additions and 81 deletions

View File

@ -128,7 +128,7 @@ static int mt7921_init_hardware(struct mt792x_dev *dev)
set_bit(MT76_STATE_INITIALIZED, &dev->mphy.state);
for (i = 0; i < MT7921_MCU_INIT_RETRY_COUNT; i++) {
for (i = 0; i < MT792x_MCU_INIT_RETRY_COUNT; i++) {
ret = __mt7921_init_hardware(dev);
if (!ret)
break;
@ -136,7 +136,7 @@ static int mt7921_init_hardware(struct mt792x_dev *dev)
mt792x_init_reset(dev);
}
if (i == MT7921_MCU_INIT_RETRY_COUNT) {
if (i == MT792x_MCU_INIT_RETRY_COUNT) {
dev_err(dev->mt76.dev, "hardware init failed\n");
return ret;
}

View File

@ -18,10 +18,6 @@
#define MT7921_RX_RING_SIZE 1536
#define MT7921_RX_MCU_RING_SIZE 512
#define MT7921_DRV_OWN_RETRY_COUNT 10
#define MT7921_MCU_INIT_RETRY_COUNT 10
#define MT7921_WFSYS_INIT_RETRY_COUNT 2
#define MT7921_FIRMWARE_WM "mediatek/WIFI_RAM_CODE_MT7961_1.bin"
#define MT7921_ROM_PATCH "mediatek/WIFI_MT7961_patch_mcu_1_2_hdr.bin"
@ -312,9 +308,6 @@ int mt7921e_mcu_init(struct mt792x_dev *dev);
int mt7921s_wfsys_reset(struct mt792x_dev *dev);
int mt7921s_mac_reset(struct mt792x_dev *dev);
int mt7921s_init_reset(struct mt792x_dev *dev);
int __mt7921e_mcu_drv_pmctrl(struct mt792x_dev *dev);
int mt7921e_mcu_drv_pmctrl(struct mt792x_dev *dev);
int mt7921e_mcu_fw_pmctrl(struct mt792x_dev *dev);
int mt7921s_mcu_init(struct mt792x_dev *dev);
int mt7921s_mcu_drv_pmctrl(struct mt792x_dev *dev);

View File

@ -181,8 +181,8 @@ static int mt7921_pci_probe(struct pci_dev *pdev,
.init_reset = mt7921e_init_reset,
.reset = mt7921e_mac_reset,
.mcu_init = mt7921e_mcu_init,
.drv_own = mt7921e_mcu_drv_pmctrl,
.fw_own = mt7921e_mcu_fw_pmctrl,
.drv_own = mt792xe_mcu_drv_pmctrl,
.fw_own = mt792xe_mcu_fw_pmctrl,
};
static const struct mt792x_irq_map irq_map = {
.host_irq_enable = MT_WFDMA0_HOST_INT_ENA,
@ -268,11 +268,11 @@ static int mt7921_pci_probe(struct pci_dev *pdev,
bus_ops->rmw = mt7921_rmw;
dev->mt76.bus = bus_ops;
ret = mt7921e_mcu_fw_pmctrl(dev);
ret = mt792xe_mcu_fw_pmctrl(dev);
if (ret)
goto err_free_dev;
ret = __mt7921e_mcu_drv_pmctrl(dev);
ret = __mt792xe_mcu_drv_pmctrl(dev);
if (ret)
goto err_free_dev;

View File

@ -57,7 +57,7 @@ int mt7921e_mac_reset(struct mt792x_dev *dev)
{
int i, err;
mt7921e_mcu_drv_pmctrl(dev);
mt792xe_mcu_drv_pmctrl(dev);
mt76_connac_free_pending_tx_skbs(&dev->pm, NULL);

View File

@ -61,68 +61,3 @@ int mt7921e_mcu_init(struct mt792x_dev *dev)
return err;
}
int __mt7921e_mcu_drv_pmctrl(struct mt792x_dev *dev)
{
int i, err = 0;
for (i = 0; i < MT7921_DRV_OWN_RETRY_COUNT; i++) {
mt76_wr(dev, MT_CONN_ON_LPCTL, PCIE_LPCR_HOST_CLR_OWN);
if (mt76_poll_msec_tick(dev, MT_CONN_ON_LPCTL,
PCIE_LPCR_HOST_OWN_SYNC, 0, 50, 1))
break;
}
if (i == MT7921_DRV_OWN_RETRY_COUNT) {
dev_err(dev->mt76.dev, "driver own failed\n");
err = -EIO;
}
return err;
}
int mt7921e_mcu_drv_pmctrl(struct mt792x_dev *dev)
{
struct mt76_phy *mphy = &dev->mt76.phy;
struct mt76_connac_pm *pm = &dev->pm;
int err;
err = __mt7921e_mcu_drv_pmctrl(dev);
if (err < 0)
goto out;
mt792x_wpdma_reinit_cond(dev);
clear_bit(MT76_STATE_PM, &mphy->state);
pm->stats.last_wake_event = jiffies;
pm->stats.doze_time += pm->stats.last_wake_event -
pm->stats.last_doze_event;
out:
return err;
}
int mt7921e_mcu_fw_pmctrl(struct mt792x_dev *dev)
{
struct mt76_phy *mphy = &dev->mt76.phy;
struct mt76_connac_pm *pm = &dev->pm;
int i;
for (i = 0; i < MT7921_DRV_OWN_RETRY_COUNT; i++) {
mt76_wr(dev, MT_CONN_ON_LPCTL, PCIE_LPCR_HOST_SET_OWN);
if (mt76_poll_msec_tick(dev, MT_CONN_ON_LPCTL,
PCIE_LPCR_HOST_OWN_SYNC, 4, 50, 1))
break;
}
if (i == MT7921_DRV_OWN_RETRY_COUNT) {
dev_err(dev->mt76.dev, "firmware own failed\n");
clear_bit(MT76_STATE_PM, &mphy->state);
return -EIO;
}
pm->stats.last_doze_event = jiffies;
pm->stats.awake_time += pm->stats.last_doze_event -
pm->stats.last_wake_event;
return 0;
}

View File

@ -166,7 +166,7 @@ int mt7921u_wfsys_reset(struct mt792x_dev *dev)
mt7921u_uhw_wr(&dev->mt76, MT_CBTOP_RGU_WF_SUBSYS_RST, val);
mt7921u_uhw_wr(&dev->mt76, MT_UDMA_CONN_INFRA_STATUS_SEL, 0);
for (i = 0; i < MT7921_WFSYS_INIT_RETRY_COUNT; i++) {
for (i = 0; i < MT792x_WFSYS_INIT_RETRY_COUNT; i++) {
val = mt7921u_uhw_rr(&dev->mt76, MT_UDMA_CONN_INFRA_STATUS);
if (val & MT_UDMA_CONN_WFSYS_INIT_DONE)
break;
@ -174,7 +174,7 @@ int mt7921u_wfsys_reset(struct mt792x_dev *dev)
msleep(100);
}
if (i == MT7921_WFSYS_INIT_RETRY_COUNT)
if (i == MT792x_WFSYS_INIT_RETRY_COUNT)
return -ETIMEDOUT;
return 0;

View File

@ -26,6 +26,10 @@
#define MT792x_WATCHDOG_TIME (HZ / 4)
#define MT792x_DRV_OWN_RETRY_COUNT 10
#define MT792x_MCU_INIT_RETRY_COUNT 10
#define MT792x_WFSYS_INIT_RETRY_COUNT 2
struct mt792x_vif;
struct mt792x_sta;
@ -289,4 +293,8 @@ int mt792x_init_wcid(struct mt792x_dev *dev);
int mt792x_mcu_drv_pmctrl(struct mt792x_dev *dev);
int mt792x_mcu_fw_pmctrl(struct mt792x_dev *dev);
int __mt792xe_mcu_drv_pmctrl(struct mt792x_dev *dev);
int mt792xe_mcu_drv_pmctrl(struct mt792x_dev *dev);
int mt792xe_mcu_fw_pmctrl(struct mt792x_dev *dev);
#endif /* __MT7925_H */

View File

@ -736,5 +736,73 @@ out:
}
EXPORT_SYMBOL_GPL(mt792x_mcu_fw_pmctrl);
int __mt792xe_mcu_drv_pmctrl(struct mt792x_dev *dev)
{
int i, err = 0;
for (i = 0; i < MT792x_DRV_OWN_RETRY_COUNT; i++) {
mt76_wr(dev, MT_CONN_ON_LPCTL, PCIE_LPCR_HOST_CLR_OWN);
if (mt76_poll_msec_tick(dev, MT_CONN_ON_LPCTL,
PCIE_LPCR_HOST_OWN_SYNC, 0, 50, 1))
break;
}
if (i == MT792x_DRV_OWN_RETRY_COUNT) {
dev_err(dev->mt76.dev, "driver own failed\n");
err = -EIO;
}
return err;
}
EXPORT_SYMBOL_GPL(__mt792xe_mcu_drv_pmctrl);
int mt792xe_mcu_drv_pmctrl(struct mt792x_dev *dev)
{
struct mt76_phy *mphy = &dev->mt76.phy;
struct mt76_connac_pm *pm = &dev->pm;
int err;
err = __mt792xe_mcu_drv_pmctrl(dev);
if (err < 0)
goto out;
mt792x_wpdma_reinit_cond(dev);
clear_bit(MT76_STATE_PM, &mphy->state);
pm->stats.last_wake_event = jiffies;
pm->stats.doze_time += pm->stats.last_wake_event -
pm->stats.last_doze_event;
out:
return err;
}
EXPORT_SYMBOL_GPL(mt792xe_mcu_drv_pmctrl);
int mt792xe_mcu_fw_pmctrl(struct mt792x_dev *dev)
{
struct mt76_phy *mphy = &dev->mt76.phy;
struct mt76_connac_pm *pm = &dev->pm;
int i;
for (i = 0; i < MT792x_DRV_OWN_RETRY_COUNT; i++) {
mt76_wr(dev, MT_CONN_ON_LPCTL, PCIE_LPCR_HOST_SET_OWN);
if (mt76_poll_msec_tick(dev, MT_CONN_ON_LPCTL,
PCIE_LPCR_HOST_OWN_SYNC, 4, 50, 1))
break;
}
if (i == MT792x_DRV_OWN_RETRY_COUNT) {
dev_err(dev->mt76.dev, "firmware own failed\n");
clear_bit(MT76_STATE_PM, &mphy->state);
return -EIO;
}
pm->stats.last_doze_event = jiffies;
pm->stats.awake_time += pm->stats.last_doze_event -
pm->stats.last_wake_event;
return 0;
}
EXPORT_SYMBOL_GPL(mt792xe_mcu_fw_pmctrl);
MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("Lorenzo Bianconi <lorenzo@kernel.org>");