linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lorenzo Bianconi <lorenzo@kernel.org>
To: nbd@nbd.name
Cc: linux-wireless@vger.kernel.org, lorenzo.bianconi@redhat.com,
	sean.wang@mediatek.com
Subject: [PATCH 02/19] mt76: mt7663: fix a race between mt7615_mcu_drv_pmctrl and mt7615_mcu_fw_pmctrl
Date: Sun, 18 Apr 2021 18:45:28 +0200	[thread overview]
Message-ID: <732fb9447efb541029536b7d48f0cdfa1c585c0a.1618763001.git.lorenzo@kernel.org> (raw)
In-Reply-To: <cover.1618763000.git.lorenzo@kernel.org>

Introduce a mutex in order to avoid a race between mt7615_mcu_lp_drv_pmctrl and
mt7615_mcu_fw_pmctrl routines since they are run two independent works

Fixes: 1f549009b5b2 ("mt76: mt7615: do not request {driver,fw}_own if already granted")
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 .../net/wireless/mediatek/mt76/mt7615/init.c  |  1 +
 .../net/wireless/mediatek/mt76/mt7615/mcu.c   | 20 +++++++++++++------
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/init.c b/drivers/net/wireless/mediatek/mt76/mt7615/init.c
index d84662fb0304..5429536e8d43 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7615/init.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7615/init.c
@@ -505,6 +505,7 @@ void mt7615_init_device(struct mt7615_dev *dev)
 
 	INIT_DELAYED_WORK(&dev->pm.ps_work, mt7615_pm_power_save_work);
 	INIT_WORK(&dev->pm.wake_work, mt7615_pm_wake_work);
+	mutex_init(&dev->pm.mutex);
 	init_completion(&dev->pm.wake_cmpl);
 	spin_lock_init(&dev->pm.txq_lock);
 	set_bit(MT76_STATE_PM, &dev->mphy.state);
diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7615/mcu.c
index 364daef4b0be..7081bb4a28bd 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7615/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7615/mcu.c
@@ -323,9 +323,11 @@ static int mt7615_mcu_drv_pmctrl(struct mt7615_dev *dev)
 static int mt7615_mcu_lp_drv_pmctrl(struct mt7615_dev *dev)
 {
 	struct mt76_phy *mphy = &dev->mt76.phy;
-	int i;
+	int i, err = 0;
+
+	mutex_lock(&dev->pm.mutex);
 
-	if (!test_and_clear_bit(MT76_STATE_PM, &mphy->state))
+	if (!test_bit(MT76_STATE_PM, &mphy->state))
 		goto out;
 
 	for (i = 0; i < MT7615_DRV_OWN_RETRY_COUNT; i++) {
@@ -337,14 +339,16 @@ static int mt7615_mcu_lp_drv_pmctrl(struct mt7615_dev *dev)
 
 	if (i == MT7615_DRV_OWN_RETRY_COUNT) {
 		dev_err(dev->mt76.dev, "driver own failed\n");
-		set_bit(MT76_STATE_PM, &mphy->state);
-		return -EIO;
+		err = -EIO;
+		goto out;
 	}
+	clear_bit(MT76_STATE_PM, &mphy->state);
 
 out:
 	dev->pm.last_activity = jiffies;
+	mutex_unlock(&dev->pm.mutex);
 
-	return 0;
+	return err;
 }
 
 static int mt7615_mcu_fw_pmctrl(struct mt7615_dev *dev)
@@ -353,8 +357,10 @@ static int mt7615_mcu_fw_pmctrl(struct mt7615_dev *dev)
 	int err = 0;
 	u32 addr;
 
+	mutex_lock(&dev->pm.mutex);
+
 	if (test_and_set_bit(MT76_STATE_PM, &mphy->state))
-		return 0;
+		goto out;
 
 	mt7622_trigger_hif_int(dev, true);
 
@@ -370,6 +376,8 @@ static int mt7615_mcu_fw_pmctrl(struct mt7615_dev *dev)
 	}
 
 	mt7622_trigger_hif_int(dev, false);
+out:
+	mutex_unlock(&dev->pm.mutex);
 
 	return err;
 }
-- 
2.30.2


  parent reply	other threads:[~2021-04-18 16:46 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-18 16:45 [PATCH 00/19] mt76: improve runtime-pm support Lorenzo Bianconi
2021-04-18 16:45 ` [PATCH 01/19] mt76: mt7921: fix a race between mt7921_mcu_drv_pmctrl and mt7921_mcu_fw_pmctrl Lorenzo Bianconi
2021-04-18 16:45 ` Lorenzo Bianconi [this message]
2021-04-18 16:45 ` [PATCH 03/19] mt76: connac: introduce wake counter for fw_pmctrl synchronization Lorenzo Bianconi
2021-04-18 16:45 ` [PATCH 04/19] mt76: mt7921: rely on mt76_connac_pm_ref/mt76_connac_pm_unref in tx path Lorenzo Bianconi
2021-04-18 16:45 ` [PATCH 05/19] mt76: mt7663: " Lorenzo Bianconi
2021-04-18 16:45 ` [PATCH 06/19] mt76: dma: add the capability to define a custom rx napi poll routine Lorenzo Bianconi
2021-04-18 16:45 ` [PATCH 07/19] mt76: mt7921: rely on mt76_connac_pm_ref/mt76_connac_pm_unref in tx/rx napi Lorenzo Bianconi
2021-04-18 16:45 ` [PATCH 08/19] mt76: mt7663: " Lorenzo Bianconi
2021-04-18 16:45 ` [PATCH 09/19] mt76: connac: unschedule ps_work in mt76_connac_pm_wake Lorenzo Bianconi
2021-04-18 16:45 ` [PATCH 10/19] mt76: connac: check wake refcount in mcu_fw_pmctrl Lorenzo Bianconi
2021-04-18 16:45 ` [PATCH 11/19] mt76: connac: remove MT76_STATE_PM in mac_tx_free Lorenzo Bianconi
2021-04-18 16:45 ` [PATCH 12/19] mt76: mt7921: get rid of useless MT76_STATE_PM in mt7921_mac_work Lorenzo Bianconi
2021-04-18 16:45 ` [PATCH 13/19] mt76: connac: alaways wake the device before scanning Lorenzo Bianconi
2021-04-18 16:45 ` [PATCH 14/19] mt76: mt7615: rely on pm refcounting in mt7615_led_set_config Lorenzo Bianconi
2021-04-18 16:45 ` [PATCH 15/19] mt76: connac: do not run mt76_txq_schedule_all directly Lorenzo Bianconi
2021-04-18 16:45 ` [PATCH 16/19] mt76: connac: use waitqueue for runtime-pm Lorenzo Bianconi
2021-04-18 16:45 ` [PATCH 17/19] mt76: remove MT76_STATE_PM in tx path Lorenzo Bianconi
2021-04-18 16:45 ` [PATCH 18/19] mt76: mt7921: add awake and doze time accounting Lorenzo Bianconi
2021-04-18 16:45 ` [PATCH 19/19] mt76: mt7921: enable sw interrupts Lorenzo Bianconi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=732fb9447efb541029536b7d48f0cdfa1c585c0a.1618763001.git.lorenzo@kernel.org \
    --to=lorenzo@kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=lorenzo.bianconi@redhat.com \
    --cc=nbd@nbd.name \
    --cc=sean.wang@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).