OSDN Git Service

mt76: mt7663s: rely on pm reference counting
authorLorenzo Bianconi <lorenzo@kernel.org>
Fri, 18 Jun 2021 08:08:21 +0000 (10:08 +0200)
committerFelix Fietkau <nbd@nbd.name>
Sat, 19 Jun 2021 07:22:51 +0000 (09:22 +0200)
As already done for mt7921 and mt7663e, rely on pm reference counting in
drv/fw_own

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/mt7615/sdio_mcu.c

index d1be78b..6c23c6d 100644 (file)
@@ -55,6 +55,7 @@ static int __mt7663s_mcu_drv_pmctrl(struct mt7615_dev *dev)
 {
        struct sdio_func *func = dev->mt76.sdio.func;
        struct mt76_phy *mphy = &dev->mt76.phy;
+       struct mt76_connac_pm *pm = &dev->pm;
        u32 status;
        int ret;
 
@@ -64,39 +65,44 @@ static int __mt7663s_mcu_drv_pmctrl(struct mt7615_dev *dev)
 
        ret = readx_poll_timeout(mt7663s_read_pcr, dev, status,
                                 status & WHLPCR_IS_DRIVER_OWN, 2000, 1000000);
-       if (ret < 0) {
+       if (ret < 0)
                dev_err(dev->mt76.dev, "Cannot get ownership from device");
-               set_bit(MT76_STATE_PM, &mphy->state);
-               sdio_release_host(func);
-
-               return ret;
-       }
+       else
+               clear_bit(MT76_STATE_PM, &mphy->state);
 
        sdio_release_host(func);
-       dev->pm.last_activity = jiffies;
+       pm->last_activity = jiffies;
 
-       return 0;
+       return ret;
 }
 
 static int mt7663s_mcu_drv_pmctrl(struct mt7615_dev *dev)
 {
        struct mt76_phy *mphy = &dev->mt76.phy;
+       int ret = 0;
 
-       if (test_and_clear_bit(MT76_STATE_PM, &mphy->state))
-               return __mt7663s_mcu_drv_pmctrl(dev);
+       mutex_lock(&dev->pm.mutex);
 
-       return 0;
+       if (test_bit(MT76_STATE_PM, &mphy->state))
+               ret = __mt7663s_mcu_drv_pmctrl(dev);
+
+       mutex_unlock(&dev->pm.mutex);
+
+       return ret;
 }
 
 static int mt7663s_mcu_fw_pmctrl(struct mt7615_dev *dev)
 {
        struct sdio_func *func = dev->mt76.sdio.func;
        struct mt76_phy *mphy = &dev->mt76.phy;
+       struct mt76_connac_pm *pm = &dev->pm;
+       int ret = 0;
        u32 status;
-       int ret;
 
-       if (test_and_set_bit(MT76_STATE_PM, &mphy->state))
-               return 0;
+       mutex_lock(&pm->mutex);
+
+       if (mt76_connac_skip_fw_pmctrl(mphy, pm))
+               goto out;
 
        sdio_claim_host(func);
 
@@ -110,6 +116,8 @@ static int mt7663s_mcu_fw_pmctrl(struct mt7615_dev *dev)
        }
 
        sdio_release_host(func);
+out:
+       mutex_unlock(&pm->mutex);
 
        return ret;
 }