From patchwork Sun Apr 18 16:45:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 423929 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45866C433ED for ; Sun, 18 Apr 2021 16:46:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 278916135A for ; Sun, 18 Apr 2021 16:46:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231953AbhDRQq1 (ORCPT ); Sun, 18 Apr 2021 12:46:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:49706 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231844AbhDRQq0 (ORCPT ); Sun, 18 Apr 2021 12:46:26 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5E62261359; Sun, 18 Apr 2021 16:45:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618764358; bh=w2CK4bFzudJhD34L7P7Ztg+tIF929ttsnYfncIacNAA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AgAzdmfWiaZKc7husPbqz/iux7Oiuc98YNawIPqhBCss7QVkhPGKK1R0uPBuvcbHf fjM+Y4FTg+OuCDt94f74aWW34y3RqfeCwMpwkT5gIkI9DEDyIcYb4UvmMKWpTw7gk4 Ia3C8HlSP6QYHqavkQr88oXH0oH+7kbO4QgSLXu47a4w9VxIgQh+pqNJPjem60fSdw BZQLOwEjqiDI3Z44r9vf5KGg1lrLyNmHY4xJ+b7qWJtOplYcRqZ7CXxNgB6bzv5Pay 2Y5wSL0Ml1JStSUZoE7V+CavU98rOSE0bDnopcknoeKE3MNmNePWXB0xvHr75iWiem cpHcbaWqVT5cA== From: Lorenzo Bianconi 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 Message-Id: <732fb9447efb541029536b7d48f0cdfa1c585c0a.1618763001.git.lorenzo@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.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 --- .../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; } From patchwork Sun Apr 18 16:45:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 423928 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 943DDC43460 for ; Sun, 18 Apr 2021 16:46:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7686561359 for ; Sun, 18 Apr 2021 16:46:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232057AbhDRQq3 (ORCPT ); Sun, 18 Apr 2021 12:46:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:49740 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231844AbhDRQq3 (ORCPT ); Sun, 18 Apr 2021 12:46:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 092896101E; Sun, 18 Apr 2021 16:45:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618764361; bh=uYkF5D1feXrV77PQBJ32Nbzlrk9cY6STAzRxc0GJj6k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wqhk2j6ExrCLSZhfdiWpDuGLebbUTrsp1/bk99iJCkcpyAuHahUqoeO0QGHCXXEm8 nxNyEuRAMTw1fi7W1HB8oDPSHMyqwEcdglBFSsqPVcmpQ5mOK77Ht/2XnwJJLtbjLa 8dvNmRCSJGsHctrq8NAK/NNVXu9emgWJdGPlzMwYhdMAak205NniZEvLJTuZB4e3q1 7JUQifMh30UhKMwQQObYg1eEEMir2Vl3M/3To5jtOEXKKgj7y1RWyX3Y5ZVMrempv0 YHQ3QInTGJk0g521N9h4QiSSOJzM4f5kO/ufe4ltT3I/8yjuOd6nd0Bh1OJWJdRLD/ J+2p7hGA8wyoA== From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org, lorenzo.bianconi@redhat.com, sean.wang@mediatek.com Subject: [PATCH 04/19] mt76: mt7921: rely on mt76_connac_pm_ref/mt76_connac_pm_unref in tx path Date: Sun, 18 Apr 2021 18:45:30 +0200 Message-Id: <78aa0a8b660d2334be224d66a0ad7190a8782011.1618763001.git.lorenzo@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Introduce mt7921_tx_worker routine as mt76 tx worker callback for mt7921. Rely on mt76_connac_pm_ref/mt76_connac_pm_unref to check PM state and increment/decrement wake counter Signed-off-by: Lorenzo Bianconi --- .../net/wireless/mediatek/mt76/mt7921/init.c | 2 ++ .../net/wireless/mediatek/mt76/mt7921/main.c | 23 ++++++++----------- .../wireless/mediatek/mt76/mt7921/mt7921.h | 2 ++ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/init.c b/drivers/net/wireless/mediatek/mt76/mt7921/init.c index 0b8a5a7f4362..ce0e231ab772 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/init.c @@ -219,9 +219,11 @@ int mt7921_register_device(struct mt7921_dev *dev) dev->phy.dev = dev; dev->phy.mt76 = &dev->mt76.phy; dev->mt76.phy.priv = &dev->phy; + dev->mt76.tx_worker.fn = mt7921_tx_worker; INIT_DELAYED_WORK(&dev->pm.ps_work, mt7921_pm_power_save_work); INIT_WORK(&dev->pm.wake_work, mt7921_pm_wake_work); + spin_lock_init(&dev->pm.wake.lock); mutex_init(&dev->pm.mutex); init_completion(&dev->pm.wake_cmpl); spin_lock_init(&dev->pm.txq_lock); diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/main.c b/drivers/net/wireless/mediatek/mt76/mt7921/main.c index 25591e2c510c..95e1775c5c00 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/main.c @@ -725,23 +725,18 @@ void mt7921_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif, mt76_connac_power_save_sched(&dev->mphy, &dev->pm); } -static void -mt7921_wake_tx_queue(struct ieee80211_hw *hw, struct ieee80211_txq *txq) +void mt7921_tx_worker(struct mt76_worker *w) { - struct mt7921_dev *dev = mt7921_hw_dev(hw); - struct mt7921_phy *phy = mt7921_hw_phy(hw); - struct mt76_phy *mphy = phy->mt76; - - if (!test_bit(MT76_STATE_RUNNING, &mphy->state)) - return; + struct mt7921_dev *dev = container_of(w, struct mt7921_dev, + mt76.tx_worker); - if (test_bit(MT76_STATE_PM, &mphy->state)) { + if (!mt76_connac_pm_ref(&dev->mphy, &dev->pm)) { queue_work(dev->mt76.wq, &dev->pm.wake_work); return; } - dev->pm.last_activity = jiffies; - mt76_worker_schedule(&dev->mt76.tx_worker); + mt76_txq_schedule_all(&dev->mphy); + mt76_connac_pm_unref(&dev->pm); } static void mt7921_tx(struct ieee80211_hw *hw, @@ -769,9 +764,9 @@ static void mt7921_tx(struct ieee80211_hw *hw, wcid = &mvif->sta.wcid; } - if (!test_bit(MT76_STATE_PM, &mphy->state)) { - dev->pm.last_activity = jiffies; + if (mt76_connac_pm_ref(mphy, &dev->pm)) { mt76_tx(mphy, control->sta, wcid, skb); + mt76_connac_pm_unref(&dev->pm); return; } @@ -1200,7 +1195,7 @@ const struct ieee80211_ops mt7921_ops = { .set_key = mt7921_set_key, .ampdu_action = mt7921_ampdu_action, .set_rts_threshold = mt7921_set_rts_threshold, - .wake_tx_queue = mt7921_wake_tx_queue, + .wake_tx_queue = mt76_wake_tx_queue, .release_buffered_frames = mt76_release_buffered_frames, .get_txpower = mt76_get_txpower, .get_stats = mt7921_get_stats, diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h b/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h index 3780a7f4cb16..a794c074867e 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h +++ b/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h @@ -336,6 +336,8 @@ int mt7921_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, enum mt76_txq_id qid, struct mt76_wcid *wcid, struct ieee80211_sta *sta, struct mt76_tx_info *tx_info); + +void mt7921_tx_worker(struct mt76_worker *w); void mt7921_tx_complete_skb(struct mt76_dev *mdev, struct mt76_queue_entry *e); int mt7921_init_tx_queues(struct mt7921_phy *phy, int idx, int n_desc); void mt7921_tx_token_put(struct mt7921_dev *dev); From patchwork Sun Apr 18 16:45:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 423927 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56F19C433B4 for ; Sun, 18 Apr 2021 16:46:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1E7C46135D for ; Sun, 18 Apr 2021 16:46:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232139AbhDRQqc (ORCPT ); Sun, 18 Apr 2021 12:46:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:49768 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232095AbhDRQqc (ORCPT ); Sun, 18 Apr 2021 12:46:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 003C561359; Sun, 18 Apr 2021 16:46:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618764363; bh=66hlXLarDesDxkZA7wSHszoVWGrSkqeypnELQBfKPwo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j2x3SUjaGWzw//eiGQb+S5Z6GktdDyNgoZXSLq6fpFy8K9RLXsUbRZrDP1bwqETaU LRHhWdbXXxmAOd1dLugE5dMMyvBlWtlCLNr2H12q8CQ/Hn1oD3uNcJeeKy5pB5ETNE +uZrQ2mbX1GSuHDuYE3ote1up83USqqtnKatdZGHzZyPatVtgdKP1MxS3qkcTHEqa5 LZzpdox4gk88oN1vPTpmz6+kz//BG7CsSH2cCCe919oiZ62mGm06NrR+4CXZ8m4UtJ hwqux8OkUr9gRFnWSC19br1LZpf8Ne8HV2xGuPARSqQegkKN5rbWXmVc+D3fjrO2s9 WDDnDoFomGljw== From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org, lorenzo.bianconi@redhat.com, sean.wang@mediatek.com Subject: [PATCH 06/19] mt76: dma: add the capability to define a custom rx napi poll routine Date: Sun, 18 Apr 2021 18:45:32 +0200 Message-Id: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Add the capability to define a custom rx napi callback for each driver. This is a preliminary patch to properly support runtime-pm on rx side Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/dma.c | 10 +++++----- drivers/net/wireless/mediatek/mt76/dma.h | 1 + drivers/net/wireless/mediatek/mt76/mt76.h | 5 +++-- drivers/net/wireless/mediatek/mt76/mt7603/dma.c | 2 +- drivers/net/wireless/mediatek/mt76/mt7615/dma.c | 2 +- drivers/net/wireless/mediatek/mt76/mt76x02_mmio.c | 2 +- drivers/net/wireless/mediatek/mt76/mt7915/dma.c | 2 +- drivers/net/wireless/mediatek/mt76/mt7921/dma.c | 2 +- 8 files changed, 14 insertions(+), 12 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/dma.c b/drivers/net/wireless/mediatek/mt76/dma.c index 6ea58aecca41..72b1cc0ecfda 100644 --- a/drivers/net/wireless/mediatek/mt76/dma.c +++ b/drivers/net/wireless/mediatek/mt76/dma.c @@ -602,8 +602,7 @@ mt76_dma_rx_process(struct mt76_dev *dev, struct mt76_queue *q, int budget) return done; } -static int -mt76_dma_rx_poll(struct napi_struct *napi, int budget) +int mt76_dma_rx_poll(struct napi_struct *napi, int budget) { struct mt76_dev *dev; int qid, done = 0, cur; @@ -626,9 +625,11 @@ mt76_dma_rx_poll(struct napi_struct *napi, int budget) return done; } +EXPORT_SYMBOL_GPL(mt76_dma_rx_poll); static int -mt76_dma_init(struct mt76_dev *dev) +mt76_dma_init(struct mt76_dev *dev, + int (*poll)(struct napi_struct *napi, int budget)) { int i; @@ -639,8 +640,7 @@ mt76_dma_init(struct mt76_dev *dev) dev->napi_dev.threaded = 1; mt76_for_each_q_rx(dev, i) { - netif_napi_add(&dev->napi_dev, &dev->napi[i], mt76_dma_rx_poll, - 64); + netif_napi_add(&dev->napi_dev, &dev->napi[i], poll, 64); mt76_dma_rx_fill(dev, &dev->q_rx[i]); napi_enable(&dev->napi[i]); } diff --git a/drivers/net/wireless/mediatek/mt76/dma.h b/drivers/net/wireless/mediatek/mt76/dma.h index e7c27697ef04..fdf786f975ea 100644 --- a/drivers/net/wireless/mediatek/mt76/dma.h +++ b/drivers/net/wireless/mediatek/mt76/dma.h @@ -45,6 +45,7 @@ enum mt76_mcu_evt_type { EVT_EVENT_DFS_DETECT_RSP, }; +int mt76_dma_rx_poll(struct napi_struct *napi, int budget); void mt76_dma_attach(struct mt76_dev *dev); void mt76_dma_cleanup(struct mt76_dev *dev); diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h index 0660b708156d..49f3e5985422 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76.h +++ b/drivers/net/wireless/mediatek/mt76/mt76.h @@ -170,7 +170,8 @@ struct mt76_mcu_ops { }; struct mt76_queue_ops { - int (*init)(struct mt76_dev *dev); + int (*init)(struct mt76_dev *dev, + int (*poll)(struct napi_struct *napi, int budget)); int (*alloc)(struct mt76_dev *dev, struct mt76_queue *q, int idx, int n_desc, int bufsize, @@ -802,7 +803,7 @@ static inline u16 mt76_rev(struct mt76_dev *dev) #define mt76xx_chip(dev) mt76_chip(&((dev)->mt76)) #define mt76xx_rev(dev) mt76_rev(&((dev)->mt76)) -#define mt76_init_queues(dev) (dev)->mt76.queue_ops->init(&((dev)->mt76)) +#define mt76_init_queues(dev, ...) (dev)->mt76.queue_ops->init(&((dev)->mt76), __VA_ARGS__) #define mt76_queue_alloc(dev, ...) (dev)->mt76.queue_ops->alloc(&((dev)->mt76), __VA_ARGS__) #define mt76_tx_queue_skb_raw(dev, ...) (dev)->mt76.queue_ops->tx_queue_skb_raw(&((dev)->mt76), __VA_ARGS__) #define mt76_tx_queue_skb(dev, ...) (dev)->mt76.queue_ops->tx_queue_skb(&((dev)->mt76), __VA_ARGS__) diff --git a/drivers/net/wireless/mediatek/mt76/mt7603/dma.c b/drivers/net/wireless/mediatek/mt76/mt7603/dma.c index 2b6244116842..415ea17b9be6 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7603/dma.c +++ b/drivers/net/wireless/mediatek/mt76/mt7603/dma.c @@ -219,7 +219,7 @@ int mt7603_dma_init(struct mt7603_dev *dev) return ret; mt76_wr(dev, MT_DELAY_INT_CFG, 0); - ret = mt76_init_queues(dev); + ret = mt76_init_queues(dev, mt76_dma_rx_poll); if (ret) return ret; diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/dma.c b/drivers/net/wireless/mediatek/mt76/mt7615/dma.c index 642b4eab0d8b..d658555f5965 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/dma.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/dma.c @@ -261,7 +261,7 @@ int mt7615_dma_init(struct mt7615_dev *dev) mt76_wr(dev, MT_DELAY_INT_CFG, 0); - ret = mt76_init_queues(dev); + ret = mt76_init_queues(dev, mt76_dma_rx_poll); if (ret < 0) return ret; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_mmio.c b/drivers/net/wireless/mediatek/mt76/mt76x02_mmio.c index ce1e9ad23fec..b50084bbe83d 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_mmio.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_mmio.c @@ -226,7 +226,7 @@ int mt76x02_dma_init(struct mt76x02_dev *dev) if (ret) return ret; - ret = mt76_init_queues(dev); + ret = mt76_init_queues(dev, mt76_dma_rx_poll); if (ret) return ret; diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/dma.c b/drivers/net/wireless/mediatek/mt76/mt7915/dma.c index 9fe09870f8f0..11d0b760abd7 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7915/dma.c +++ b/drivers/net/wireless/mediatek/mt76/mt7915/dma.c @@ -213,7 +213,7 @@ int mt7915_dma_init(struct mt7915_dev *dev) return ret; } - ret = mt76_init_queues(dev); + ret = mt76_init_queues(dev, mt76_dma_rx_poll); if (ret < 0) return ret; diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/dma.c b/drivers/net/wireless/mediatek/mt76/mt7921/dma.c index 992faf82ad09..b056ac15f09a 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/dma.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/dma.c @@ -295,7 +295,7 @@ int mt7921_dma_init(struct mt7921_dev *dev) if (ret) return ret; - ret = mt76_init_queues(dev); + ret = mt76_init_queues(dev, mt76_dma_rx_poll); if (ret < 0) return ret; From patchwork Sun Apr 18 16:45:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 423926 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8F36C433ED for ; Sun, 18 Apr 2021 16:46:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B6EA361359 for ; Sun, 18 Apr 2021 16:46:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229783AbhDRQqf (ORCPT ); Sun, 18 Apr 2021 12:46:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:49800 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232095AbhDRQqe (ORCPT ); Sun, 18 Apr 2021 12:46:34 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9EFF76101E; Sun, 18 Apr 2021 16:46:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618764366; bh=+nlxpZTvYyG9QYGOyai7tZy+TZ7WYjEbAS1b1F1OKXY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AjHu0FCSE70eUSN7TPF06XNJDgTEDTcj2cqXS9883og53P/IDL2A2QpGopHD5h39H VJmNifRjJ2vo36WXRsr8LA7jHFKp6jQigXYAzjdXe+DXJTe0cJSnJbDSq3/dyjWPtR rpD8WNy+ST6qkeiv+qeetXcXyVcCUhAgK1brOCd6IN+kkZomVU1uQ4Zsr6XC/u8/5B TEoeVQCDTA6uJ5ftwPlpwdEV3c/1RxLrNOItUwyeroArEFa7ouLTxDMgu+1H6h42Jx WbJac21qzVl5gCAkis9oNu1Y64lHKAJ+6GDKp668KIUVGuDUa0lhbNp0ByjJgpMkHE /dHDgjPmIP0bA== From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org, lorenzo.bianconi@redhat.com, sean.wang@mediatek.com Subject: [PATCH 08/19] mt76: mt7663: rely on mt76_connac_pm_ref/mt76_connac_pm_unref in tx/rx napi Date: Sun, 18 Apr 2021 18:45:34 +0200 Message-Id: <3bc75d18c09275187c2595da9f033efd7abca019.1618763001.git.lorenzo@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Introduce mt7615_poll_rx rx napi callback for mt7663. Do not access device registers in tx/rx napi if the device is not awake. Signed-off-by: Lorenzo Bianconi --- .../net/wireless/mediatek/mt76/mt7615/dma.c | 30 +++++++++++++++++-- .../net/wireless/mediatek/mt76/mt7615/mac.c | 10 +++++-- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/dma.c b/drivers/net/wireless/mediatek/mt76/mt7615/dma.c index d658555f5965..8004ae5c16a9 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/dma.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/dma.c @@ -71,15 +71,39 @@ static int mt7615_poll_tx(struct napi_struct *napi, int budget) struct mt7615_dev *dev; dev = container_of(napi, struct mt7615_dev, mt76.tx_napi); + if (!mt76_connac_pm_ref(&dev->mphy, &dev->pm)) { + napi_complete(napi); + queue_work(dev->mt76.wq, &dev->pm.wake_work); + return 0; + } mt76_queue_tx_cleanup(dev, dev->mt76.q_mcu[MT_MCUQ_WM], false); - - if (napi_complete_done(napi, 0)) + if (napi_complete(napi)) mt7615_irq_enable(dev, mt7615_tx_mcu_int_mask(dev)); + mt76_connac_pm_unref(&dev->pm); + return 0; } +static int mt7615_poll_rx(struct napi_struct *napi, int budget) +{ + struct mt7615_dev *dev; + int done; + + dev = container_of(napi->dev, struct mt7615_dev, mt76.napi_dev); + + if (!mt76_connac_pm_ref(&dev->mphy, &dev->pm)) { + napi_complete(napi); + queue_work(dev->mt76.wq, &dev->pm.wake_work); + return 0; + } + done = mt76_dma_rx_poll(napi, budget); + mt76_connac_pm_unref(&dev->pm); + + return done; +} + int mt7615_wait_pdma_busy(struct mt7615_dev *dev) { struct mt76_dev *mdev = &dev->mt76; @@ -261,7 +285,7 @@ int mt7615_dma_init(struct mt7615_dev *dev) mt76_wr(dev, MT_DELAY_INT_CFG, 0); - ret = mt76_init_queues(dev, mt76_dma_rx_poll); + ret = mt76_init_queues(dev, mt7615_poll_rx); if (ret < 0) return ret; diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c index 0b386030dbd8..e81c7d322811 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c @@ -1913,10 +1913,14 @@ void mt7615_pm_wake_work(struct work_struct *work) pm.wake_work); mphy = dev->phy.mt76; - if (!mt7615_mcu_set_drv_ctrl(dev)) + if (!mt7615_mcu_set_drv_ctrl(dev)) { + int i; + + mt76_for_each_q_rx(&dev->mt76, i) + napi_schedule(&dev->mt76.napi[i]); mt76_connac_pm_dequeue_skbs(mphy, &dev->pm); - else - dev_err(mphy->dev->dev, "failed to wake device\n"); + mt76_queue_tx_cleanup(dev, dev->mt76.q_mcu[MT_MCUQ_WM], false); + } ieee80211_wake_queues(mphy->hw); complete_all(&dev->pm.wake_cmpl); From patchwork Sun Apr 18 16:45:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 423925 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0AD84C433B4 for ; Sun, 18 Apr 2021 16:46:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D0AD76101E for ; Sun, 18 Apr 2021 16:46:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232179AbhDRQqh (ORCPT ); Sun, 18 Apr 2021 12:46:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:49822 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232095AbhDRQqh (ORCPT ); Sun, 18 Apr 2021 12:46:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4577961359; Sun, 18 Apr 2021 16:46:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618764369; bh=QW/N+KulcNzOg7fnGEiWu0qI3VA43sk7aMpeDzAyo3s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RfB2snVLm6+LAHBQaIvRXq7unHKlIqMIgXYbZs5IHbxV6Pz3JHPliHtfeakmdzImD IdlieLU0AcnO47/6CWuBJZ0anzOJTAqP8bYWAQkWnvrwEH5V0VGtxW3dQUas0b1b+N dMcP631pBeJfh1rUhr40GZPdW6veMbZPfD7fpuuDcbyoS4+Aqm42SMhVd7KpBeaUwV z7K47iyo/NR4pl7Euccb6SS98uVETiguJWhvKjZgV47gg7zXT0R0LkrXEhKVCiLSZS GmHP5x94JkooOJRAEyWfXkCeror2IpCkrE4qYk3nAnILWUrUup6GoZga9ADBoDrPFp HYtIn0IcMDa8g== From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org, lorenzo.bianconi@redhat.com, sean.wang@mediatek.com Subject: [PATCH 10/19] mt76: connac: check wake refcount in mcu_fw_pmctrl Date: Sun, 18 Apr 2021 18:45:36 +0200 Message-Id: <79586a8114bf0831b78181a41fbf2994c4010da2.1618763001.git.lorenzo@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org In order to avoid synchronization races between tx and rx path, rely on mt76_connac_skip_fw_pmctrl putting the chip in sleep mode for mt7921 and mt7663 devices Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/mt7615/mcu.c | 2 +- drivers/net/wireless/mediatek/mt76/mt76_connac.h | 12 ++++++++++++ drivers/net/wireless/mediatek/mt76/mt7921/mcu.c | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7615/mcu.c index 5890fee98d97..45c6fb5832b8 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/mcu.c @@ -358,7 +358,7 @@ static int mt7615_mcu_fw_pmctrl(struct mt7615_dev *dev) mutex_lock(&dev->pm.mutex); - if (test_and_set_bit(MT76_STATE_PM, &mphy->state)) + if (mt76_connac_skip_fw_pmctrl(mphy, &dev->pm)) goto out; mt7622_trigger_hif_int(dev, true); diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac.h b/drivers/net/wireless/mediatek/mt76/mt76_connac.h index 85846eab8d7d..116d800c9f9d 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76_connac.h +++ b/drivers/net/wireless/mediatek/mt76/mt76_connac.h @@ -116,6 +116,18 @@ mt76_connac_pm_unref(struct mt76_connac_pm *pm) spin_unlock_bh(&pm->wake.lock); } +static inline bool +mt76_connac_skip_fw_pmctrl(struct mt76_phy *phy, struct mt76_connac_pm *pm) +{ + bool ret; + + spin_lock_bh(&pm->wake.lock); + ret = pm->wake.count || test_and_set_bit(MT76_STATE_PM, &phy->state); + spin_unlock_bh(&pm->wake.lock); + + return ret; +} + static inline void mt76_connac_mutex_acquire(struct mt76_dev *dev, struct mt76_connac_pm *pm) __acquires(&dev->mutex) diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c index 44f02cbf9cc7..1204f5d324f8 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c @@ -1304,7 +1304,7 @@ int mt7921_mcu_fw_pmctrl(struct mt7921_dev *dev) mutex_lock(&dev->pm.mutex); - if (test_and_set_bit(MT76_STATE_PM, &mphy->state)) + if (mt76_connac_skip_fw_pmctrl(mphy, &dev->pm)) goto out; for (i = 0; i < MT7921_DRV_OWN_RETRY_COUNT; i++) { From patchwork Sun Apr 18 16:45:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 423924 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A7C3C433B4 for ; Sun, 18 Apr 2021 16:46:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6036361359 for ; Sun, 18 Apr 2021 16:46:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233754AbhDRQqk (ORCPT ); Sun, 18 Apr 2021 12:46:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:49890 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232284AbhDRQqk (ORCPT ); Sun, 18 Apr 2021 12:46:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E440C613AA; Sun, 18 Apr 2021 16:46:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618764371; bh=MVBORasL4C85D65v0E9u0AsjP1dv7j+jSdghNDwL24o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bbJ8D2D+oCQy811WUroJqU08e1BTzeHXwQjLuCuhSxD0+rLuS3xt5WxNie0TjsrCs qb5s++vi7IGWcrHyWCgrVf0ua7DPhNFfzWykf5S3PP//z/Yj+K300zzIJ3A32YtzXS Jx5yg+2hDzupAMeGly8g8yq9cLcq1GVuHNIF3Q0XxEc+zy8/kCNxZjNmMmGHYJkYiY uiXF33LBsXqJQtd3NkiT28hRuifPg87y+tM24/9WZQcV2k+Rxa7r85/qnYANXqofyO gS6YlFO2yiWk0HcctmoK96Sdjbkjy6SpTICPjA2aDfeMbTx3H/z1+qBIC7v4Eq4YJv FVL5qIGF/SUoQ== From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org, lorenzo.bianconi@redhat.com, sean.wang@mediatek.com Subject: [PATCH 12/19] mt76: mt7921: get rid of useless MT76_STATE_PM in mt7921_mac_work Date: Sun, 18 Apr 2021 18:45:38 +0200 Message-Id: <0641ddea8aa1cf4b04a7b191d48aad1d646bebb6.1618763001.git.lorenzo@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Remove useless MT76_STATE_PM check in mt7921_mac_work since mt7921_mutex_acquire will wake up the device if necessary Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/mt7921/mac.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c index a8247a6d5bc7..5dcb574a2768 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c @@ -1493,9 +1493,6 @@ void mt7921_mac_work(struct work_struct *work) mac_work.work); phy = mphy->priv; - if (test_bit(MT76_STATE_PM, &mphy->state)) - goto out; - mt7921_mutex_acquire(phy->dev); mt76_update_survey(mphy->dev); @@ -1510,8 +1507,6 @@ void mt7921_mac_work(struct work_struct *work) } mt7921_mutex_release(phy->dev); - -out: ieee80211_queue_delayed_work(phy->mt76->hw, &mphy->mac_work, MT7921_WATCHDOG_TIME); } From patchwork Sun Apr 18 16:45:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 423923 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9F12C433ED for ; Sun, 18 Apr 2021 16:46:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A0D6061359 for ; Sun, 18 Apr 2021 16:46:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234846AbhDRQqn (ORCPT ); Sun, 18 Apr 2021 12:46:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:49934 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232212AbhDRQqm (ORCPT ); Sun, 18 Apr 2021 12:46:42 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8CCD761359; Sun, 18 Apr 2021 16:46:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618764374; bh=Qcyjit270av8s5rkw1lAptBR1FzoPr89sm1FbOGdEZc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PFAjWJi24YKxW9eep46oZYAKtiesEfN/ITqORsA+RdCxK/37th8EB1osAoXjSezQs nYj921GRXdt9xfzGFpSNby81/9+aZpv9oWijPf4AwvWHEm8sMwDnSaoC7DKyJMTw6j nUX3thO+7Vm6fDw9226DHWhEEUtjxJha0k/GususjCdI/oVJcX7aP0ENsaLKbPBR8W sQOhX9dcZ2qLic5I+P/+KdAy0tDxACz0Kk6nblW/nHEZvdgjHwbiaDG6isBcoy+iHP EmvzUgClrCcbEBJg8q3npG+h6ZsgV9tqF93zp0L3OzMWp4hIEa+ottLMBS7voagbF/ 5QPnv/JT4IHFg== From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org, lorenzo.bianconi@redhat.com, sean.wang@mediatek.com Subject: [PATCH 14/19] mt76: mt7615: rely on pm refcounting in mt7615_led_set_config Date: Sun, 18 Apr 2021 18:45:40 +0200 Message-Id: <8ca5f4f25fbf630bc6ab23852d2f76b710c47c21.1618763001.git.lorenzo@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Rely on mt76_connac_pm_ref/mt76_connac_pm_unref utility routines in mt7615_led_set_config Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/mt7615/pci_init.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/pci_init.c b/drivers/net/wireless/mediatek/mt76/mt7615/pci_init.c index 49540b00519d..736d19699a03 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/pci_init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/pci_init.c @@ -82,7 +82,7 @@ mt7615_led_set_config(struct led_classdev *led_cdev, mt76 = container_of(led_cdev, struct mt76_dev, led_cdev); dev = container_of(mt76, struct mt7615_dev, mt76); - if (test_bit(MT76_STATE_PM, &mt76->phy.state)) + if (!mt76_connac_pm_ref(&dev->mphy, &dev->pm)) return; val = FIELD_PREP(MT_LED_STATUS_DURATION, 0xffff) | @@ -100,6 +100,8 @@ mt7615_led_set_config(struct led_classdev *led_cdev, val |= MT_LED_CTRL_POLARITY(mt76->led_pin); addr = mt7615_reg_map(dev, MT_LED_CTRL); mt76_wr(dev, addr, val); + + mt76_connac_pm_unref(&dev->pm); } static int From patchwork Sun Apr 18 16:45:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 423922 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9A65C43460 for ; Sun, 18 Apr 2021 16:46:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9D6476135A for ; Sun, 18 Apr 2021 16:46:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235404AbhDRQqp (ORCPT ); Sun, 18 Apr 2021 12:46:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:49982 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232291AbhDRQqp (ORCPT ); Sun, 18 Apr 2021 12:46:45 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 37E996101E; Sun, 18 Apr 2021 16:46:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618764377; bh=niXP5WXX4SN7ofupoo66EXBu0NvWD0d7lxl9KQfiIeg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RCy5BtJbcg0YugvdlD1h9nE8cC8aOIU4RLFhLyP/PIbM+SgFZZOQ+Wf+YKEMvaouT GVSFWerWFeDjYgbga22GZG47/dAQurTOf16UaVoB14D8mUVT0c9nXeoFUQLx16Jj44 x9VgoPWL6l11KeAY5PU6uE/kxvyMRUZIdkyVWrqjZ2CEfKe7KjGAmpsRJEQ1E6ZzM5 KV89jRhPThY/oSMESLWQ+rKyRsnl0sJme9rJDABUiGqOgXufCrbdLskJb/DX4RLfUM /UYYR/W0UNuQLgRl6dE5WaWWrm3qPyurGVNWFY+M3foCmNEWrd3pVGRc8QEu9vrwE2 uxG/S2WyNvMOA== From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org, lorenzo.bianconi@redhat.com, sean.wang@mediatek.com Subject: [PATCH 16/19] mt76: connac: use waitqueue for runtime-pm Date: Sun, 18 Apr 2021 18:45:42 +0200 Message-Id: <3a23a827d4ed990bb89bdfa988d0c3c072ce06ac.1618763001.git.lorenzo@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Simplify the code using a wait_queue_head_t instead of a completion to wait the chip is fully awake in mt76_connac_pm_wake routine Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/mt7615/init.c | 2 +- drivers/net/wireless/mediatek/mt76/mt7615/mac.c | 2 +- drivers/net/wireless/mediatek/mt76/mt76_connac.h | 2 +- drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c | 8 ++++---- drivers/net/wireless/mediatek/mt76/mt7921/init.c | 2 +- drivers/net/wireless/mediatek/mt76/mt7921/mac.c | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/init.c b/drivers/net/wireless/mediatek/mt76/mt7615/init.c index 3ef6bcdf38c4..894b2588e075 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/init.c @@ -508,7 +508,7 @@ void mt7615_init_device(struct mt7615_dev *dev) INIT_WORK(&dev->pm.wake_work, mt7615_pm_wake_work); spin_lock_init(&dev->pm.wake.lock); mutex_init(&dev->pm.mutex); - init_completion(&dev->pm.wake_cmpl); + init_waitqueue_head(&dev->pm.wait); spin_lock_init(&dev->pm.txq_lock); set_bit(MT76_STATE_PM, &dev->mphy.state); INIT_DELAYED_WORK(&dev->mphy.mac_work, mt7615_mac_work); diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c index adbc726149a9..747bf90f9d8a 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c @@ -1919,7 +1919,7 @@ void mt7615_pm_wake_work(struct work_struct *work) } ieee80211_wake_queues(mphy->hw); - complete_all(&dev->pm.wake_cmpl); + wake_up(&dev->pm.wait); } void mt7615_pm_power_save_work(struct work_struct *work) diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac.h b/drivers/net/wireless/mediatek/mt76/mt76_connac.h index 116d800c9f9d..e3937f6d3640 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76_connac.h +++ b/drivers/net/wireless/mediatek/mt76/mt76_connac.h @@ -53,7 +53,7 @@ struct mt76_connac_pm { } tx_q[IEEE80211_NUM_ACS]; struct work_struct wake_work; - struct completion wake_cmpl; + wait_queue_head_t wait; struct { spinlock_t lock; diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c b/drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c index a263921d9f42..66f1667481e6 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c @@ -17,10 +17,10 @@ int mt76_connac_pm_wake(struct mt76_phy *phy, struct mt76_connac_pm *pm) if (!test_bit(MT76_STATE_PM, &phy->state)) return 0; - if (queue_work(dev->wq, &pm->wake_work)) - reinit_completion(&pm->wake_cmpl); - - if (!wait_for_completion_timeout(&pm->wake_cmpl, 3 * HZ)) { + queue_work(dev->wq, &pm->wake_work); + if (!wait_event_timeout(pm->wait, + !test_bit(MT76_STATE_PM, &phy->state), + 3 * HZ)) { ieee80211_wake_queues(phy->hw); return -ETIMEDOUT; } diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/init.c b/drivers/net/wireless/mediatek/mt76/mt7921/init.c index ce0e231ab772..2d8dba000d0b 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/init.c @@ -225,7 +225,7 @@ int mt7921_register_device(struct mt7921_dev *dev) INIT_WORK(&dev->pm.wake_work, mt7921_pm_wake_work); spin_lock_init(&dev->pm.wake.lock); mutex_init(&dev->pm.mutex); - init_completion(&dev->pm.wake_cmpl); + init_waitqueue_head(&dev->pm.wait); spin_lock_init(&dev->pm.txq_lock); set_bit(MT76_STATE_PM, &dev->mphy.state); INIT_LIST_HEAD(&dev->phy.stats_list); diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c index 90ede75cfba8..7b5323181fac 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c @@ -1530,7 +1530,7 @@ void mt7921_pm_wake_work(struct work_struct *work) } ieee80211_wake_queues(mphy->hw); - complete_all(&dev->pm.wake_cmpl); + wake_up(&dev->pm.wait); } void mt7921_pm_power_save_work(struct work_struct *work) From patchwork Sun Apr 18 16:45:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 423921 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19223C43460 for ; Sun, 18 Apr 2021 16:46:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F321961359 for ; Sun, 18 Apr 2021 16:46:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236053AbhDRQqu (ORCPT ); Sun, 18 Apr 2021 12:46:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:50020 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232244AbhDRQqt (ORCPT ); Sun, 18 Apr 2021 12:46:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 33F636101E; Sun, 18 Apr 2021 16:46:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618764381; bh=8j9daaZcdcyMeM2RuAEOtcGEB3oidV4RfPEbvh+83Ls=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XUniaRM4Jpu49MWaNCKRAIvG47FEYLT9jC21fSQQ/RE546X2da7ERiZRegOLG1dtk KC/6jDsw533HCwlQcoQNPoD6anuYuIwpGNR2ZtVx8qZI8ICNA7ZHCjnuu8DcGtx4r5 pRteXR7B1msowXXGUHf1t6DCq9B2Eq0UR3jRtk4M9CF6sleLshFIizo29qG9vw0Eua o22ITKFI9XGlpTl4KtTgG+JGKWvW2jiuQ/rp9qXj8FeC18UKP9kE0mt/Z6TiOhmX5i b+00Pa3QgMTG3DkJyyGUOBkR72yx6PmHhHBFVX0DUwFkU7i5IE7sev4sAjJXgWSjmk tb19ZNM8LYtvw== From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org, lorenzo.bianconi@redhat.com, sean.wang@mediatek.com Subject: [PATCH 19/19] mt76: mt7921: enable sw interrupts Date: Sun, 18 Apr 2021 18:45:45 +0200 Message-Id: <5893f370bb33bf8adf7e41afe0f2da51a8366418.1618763001.git.lorenzo@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Enable sw interrupts in order to wake the device from deep sleep receiving packets Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/mt7921/dma.c | 1 + drivers/net/wireless/mediatek/mt76/mt7921/mac.c | 1 + drivers/net/wireless/mediatek/mt76/mt7921/pci.c | 13 +++++++++++++ .../net/wireless/mediatek/mt76/mt7921/regs.h | 17 ++++++++++------- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/dma.c b/drivers/net/wireless/mediatek/mt76/mt7921/dma.c index c26979614113..7ada8339b74f 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/dma.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/dma.c @@ -351,6 +351,7 @@ int mt7921_dma_init(struct mt7921_dev *dev) /* enable interrupts for TX/RX rings */ mt7921_irq_enable(dev, MT_INT_RX_DONE_ALL | MT_INT_TX_DONE_ALL | MT_INT_MCU_CMD); + mt76_set(dev, MT_MCU2HOST_SW_INT_ENA, MT_MCU_CMD_WAKE_RX_PCIE); return 0; } diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c index 7b5323181fac..8770e0d93f45 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c @@ -1276,6 +1276,7 @@ mt7921_dma_reset(struct mt7921_dev *dev) mt7921_irq_enable(dev, MT_INT_RX_DONE_ALL | MT_INT_TX_DONE_ALL | MT_INT_MCU_CMD); + mt76_set(dev, MT_MCU2HOST_SW_INT_ENA, MT_MCU_CMD_WAKE_RX_PCIE); } void mt7921_tx_token_put(struct mt7921_dev *dev) diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/pci.c b/drivers/net/wireless/mediatek/mt76/mt7921/pci.c index 40e2086d075c..d5da98d36f63 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/pci.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/pci.c @@ -61,6 +61,18 @@ static void mt7921_irq_tasklet(unsigned long data) if (intr & MT_INT_TX_DONE_MCU) mask |= MT_INT_TX_DONE_MCU; + if (intr & MT_INT_MCU_CMD) { + u32 intr_sw; + + intr_sw = mt76_rr(dev, MT_MCU_CMD); + /* ack MCU2HOST_SW_INT_STA */ + mt76_wr(dev, MT_MCU_CMD, intr_sw); + if (intr_sw & MT_MCU_CMD_WAKE_RX_PCIE) { + mask |= MT_INT_RX_DONE_DATA; + intr |= MT_INT_RX_DONE_DATA; + } + } + mt76_set_irq_mask(&dev->mt76, MT_WFDMA0_HOST_INT_ENA, mask, 0); if (intr & MT_INT_TX_DONE_ALL) @@ -253,6 +265,7 @@ static int mt7921_pci_resume(struct pci_dev *pdev) mt76_wr(dev, MT_PCIE_MAC_INT_ENABLE, 0xff); mt7921_irq_enable(dev, MT_INT_RX_DONE_ALL | MT_INT_TX_DONE_ALL | MT_INT_MCU_CMD); + mt76_set(dev, MT_MCU2HOST_SW_INT_ENA, MT_MCU_CMD_WAKE_RX_PCIE); /* put dma enabled */ mt76_set(dev, MT_WFDMA0_GLO_CFG, diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/regs.h b/drivers/net/wireless/mediatek/mt76/mt7921/regs.h index 76ecfea21dce..b6944c867a57 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/regs.h +++ b/drivers/net/wireless/mediatek/mt76/mt7921/regs.h @@ -251,13 +251,16 @@ #define MT_WFDMA0_BUSY_ENA_TX_FIFO1 BIT(1) #define MT_WFDMA0_BUSY_ENA_RX_FIFO BIT(2) -#define MT_MCU_CMD MT_WFDMA0(0x1f0) -#define MT_MCU_CMD_STOP_DMA_FW_RELOAD BIT(1) -#define MT_MCU_CMD_STOP_DMA BIT(2) -#define MT_MCU_CMD_RESET_DONE BIT(3) -#define MT_MCU_CMD_RECOVERY_DONE BIT(4) -#define MT_MCU_CMD_NORMAL_STATE BIT(5) -#define MT_MCU_CMD_ERROR_MASK GENMASK(5, 1) +#define MT_MCU_CMD MT_WFDMA0(0x1f0) +#define MT_MCU_CMD_WAKE_RX_PCIE BIT(0) +#define MT_MCU_CMD_STOP_DMA_FW_RELOAD BIT(1) +#define MT_MCU_CMD_STOP_DMA BIT(2) +#define MT_MCU_CMD_RESET_DONE BIT(3) +#define MT_MCU_CMD_RECOVERY_DONE BIT(4) +#define MT_MCU_CMD_NORMAL_STATE BIT(5) +#define MT_MCU_CMD_ERROR_MASK GENMASK(5, 1) + +#define MT_MCU2HOST_SW_INT_ENA MT_WFDMA0(0x1f4) #define MT_WFDMA0_HOST_INT_STA MT_WFDMA0(0x200) #define HOST_RX_DONE_INT_STS0 BIT(0) /* Rx mcu */