From patchwork Mon Jul 18 20:52:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Wang X-Patchwork-Id: 12921796 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 69240C433EF for ; Mon, 18 Jul 2022 21:33:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=/awS/rH49q2/UN8dXRT7sg2stJQKrk9+Sx8DfU1COWQ=; b=VmvhxKjXmqgCYuO4w+nQ++24/1 Gy8zCSF0+gvEYiFhZZ0nOrTesZssH4qJbr7GkXzwQyVEL38iIeXBA1vSlyzsb8aZqhvG/nW7njcSS Z18S5YOn+hQgUV0m1XNkgQI2SahY86Q+6SGO9R+7Nta4FlQFQZxFz52DjYDcGd3JN9v9/lmtbmkJ+ RIO+Th5t0N+4QOmwOWcfoEEAbgmGkxrrJxhUKA8mAmuyIz1Nc7tNlfQSHvLc7XmA3j39fELNsq+hB 5nBtRGOSYdMbQ0Qu7UsgOraK4ffjfAY9Tfwn+b8ywMW/L1g0Vdhu7QyAHnxp1ckBWrM5xYvbiUbpo Fia99RiA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oDYMY-001Yub-6S; Mon, 18 Jul 2022 21:33:10 +0000 Received: from mailgw01.mediatek.com ([216.200.240.184]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oDYMV-001YsA-E1 for linux-mediatek@lists.infradead.org; Mon, 18 Jul 2022 21:33:08 +0000 X-UUID: 2ed53e37666e4c589d74f11b7037d07c-20220718 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.8,REQID:6be14b08-f47f-4545-b513-975fe42eab0d,OB:0,LO B:0,IP:0,URL:5,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,RULE:Release_Ham,ACTI ON:release,TS:5 X-CID-META: VersionHash:0f94e32,CLOUDID:fd6c4e33-b9e4-42b8-b28a-6364427c76bb,C OID:IGNORED,Recheck:0,SF:nil,TC:nil,Content:0,EDM:-3,IP:nil,URL:1,File:nil ,QS:nil,BEC:nil,COL:0 X-UUID: 2ed53e37666e4c589d74f11b7037d07c-20220718 Received: from mtkmbs11n1.mediatek.inc [(172.21.101.185)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 250046544; Mon, 18 Jul 2022 14:32:57 -0700 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by mtkmbs11n1.mediatek.inc (172.21.101.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.3; Tue, 19 Jul 2022 04:52:17 +0800 Received: from mtkswgap22.mediatek.inc (172.21.77.33) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.3 via Frontend Transport; Tue, 19 Jul 2022 04:52:17 +0800 From: To: , CC: , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH 1/3] mt76: mt7921s: fix the deadlock caused by sdio->stat_work Date: Tue, 19 Jul 2022 04:52:13 +0800 Message-ID: X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220718_143307_511519_8D81AA70 X-CRM114-Status: GOOD ( 12.29 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org From: Sean Wang Because wake_work and sdio->stat_work share the same workqueue mt76->wq, if sdio->stat_work cannot acquire the mutex lock such as that was possibly held up by mt7921_mutex_acquire, we should exit immediately and schedule another stat_work to avoid blocking the mt7921_mutex_acquire. Also, if mt7921_mutex_acquire was called by sdio->stat_work self, the wake would be blocked by itself, so we have to changing into an unblocking wake (directly wakeup via mt7921_mcu_drv_pmctrl, not via the wake_work) in the context. Fixes: 48fab5bbef40 ("mt76: mt7921: introduce mt7921s support") Co-developed-by: YN Chen Signed-off-by: YN Chen Signed-off-by: Sean Wang --- .../net/wireless/mediatek/mt76/mt7921/mac.c | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c index 6bd9fc9228a2..75e719175e92 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c @@ -1080,10 +1080,28 @@ bool mt7921_usb_sdio_tx_status_data(struct mt76_dev *mdev, u8 *update) { struct mt7921_dev *dev = container_of(mdev, struct mt7921_dev, mt76); - mt7921_mutex_acquire(dev); + if (!mutex_trylock(&mdev->mutex)) { + /* Because wake_work and stat_work share the same workqueue + * mt76->wq, if sdio->stat_work cannot acquire the mutex lock, + * we should exit immediately and schedule another stat_work + * to avoid blocking the wake_work. + */ + struct work_struct *stat_work; + + stat_work = mt76_is_sdio(mdev) ? &mdev->sdio.stat_work : + &mdev->usb.stat_work; + queue_work(dev->mt76.wq, stat_work); + + goto out; + } + + mt7921_mcu_drv_pmctrl(dev); mt7921_mac_sta_poll(dev); - mt7921_mutex_release(dev); + mt76_connac_power_save_sched(&mdev->phy, &dev->pm); + mutex_unlock(&mdev->mutex); + +out: return false; } EXPORT_SYMBOL_GPL(mt7921_usb_sdio_tx_status_data); From patchwork Mon Jul 18 20:52:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Wang X-Patchwork-Id: 12921765 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 65AF1CCA479 for ; Mon, 18 Jul 2022 20:53:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:CC:To:From:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=nmKeM7/9lMLm5u9FkA2W991UUN5LuNBAidJ3ZeNlSWM=; b=378oKF4LXm2gEZcQPgH9EmClZG VdqNbJ1soJq16rRzt5nvywrc3GmOFMST39os3I0U+6rbwPxGiUmdbnAY3WK0GDyZIrZwSGwgK3EW/ hbeOS+jDIBYtEJgT2CDNuMjT9mKWt6AZEBA4Q92hhlGmvxUfRLL3AgRxkVNqCcmT42ICfpS2CEccS QPy4YykftW6PmnUOpe25J57YV4ddyT+R17sDXBtWXdz1F0Rw1gxNmk79yluXc/fP1A1BE3JB7T/w9 BSCyRq0/Fz6qNrTuaqsHAHpiqIUWvneeVX3XUeeBt2nJlOQlRl2Z8Qs6igDyDfQWTKzyLZvASEGMt OOEw4AhQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oDXjo-0018oz-KN; Mon, 18 Jul 2022 20:53:08 +0000 Received: from mailgw02.mediatek.com ([216.200.240.185]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oDXjl-0018Qy-Ig for linux-mediatek@lists.infradead.org; Mon, 18 Jul 2022 20:53:07 +0000 X-UUID: 584ab132f9f24dc3bb336f3fe7132bfe-20220718 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.8,REQID:5b98f3d1-2f0c-4279-abd9-1374d159c2e7,OB:0,LO B:0,IP:0,URL:5,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,RULE:Release_Ham,ACTI ON:release,TS:5 X-CID-META: VersionHash:0f94e32,CLOUDID:b14e9e64-0b3f-4b2c-b3a6-ed5c044366a0,C OID:IGNORED,Recheck:0,SF:nil,TC:nil,Content:0,EDM:-3,IP:nil,URL:1,File:nil ,QS:nil,BEC:nil,COL:0 X-UUID: 584ab132f9f24dc3bb336f3fe7132bfe-20220718 Received: from mtkmbs11n1.mediatek.inc [(172.21.101.185)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 706119631; Mon, 18 Jul 2022 13:52:54 -0700 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by mtkmbs11n2.mediatek.inc (172.21.101.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.3; Tue, 19 Jul 2022 04:52:17 +0800 Received: from mtkswgap22.mediatek.inc (172.21.77.33) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.3 via Frontend Transport; Tue, 19 Jul 2022 04:52:17 +0800 From: To: , CC: , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH 2/3] mt76: sdio: poll sta stat when device transmits data Date: Tue, 19 Jul 2022 04:52:14 +0800 Message-ID: <1655553ca765a8c18abd6f9bb7e861e9eb590b24.1658176763.git.sean.wang@kernel.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220718_135305_646314_FAD59DF1 X-CRM114-Status: GOOD ( 12.69 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org From: Sean Wang It is not meaningful to poll sta stat when there is no the data traffic. So polling sta stat when device have transmitted data instead to save CPU power. That implies that it is unallowed the stat_work to work while MCU is being initialized in the really early stage. That is a required patch for ("mt76: mt7663s: fix the deadlock caused by sdio->stat_work") because mt7615_mcu_set_drv_ctrl pointer isn't set done until MCU is ready. Fixes: d39b52e31aa6 ("mt76: introduce mt76_sdio module") Signed-off-by: Sean Wang --- drivers/net/wireless/mediatek/mt76/sdio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/sdio.c b/drivers/net/wireless/mediatek/mt76/sdio.c index aba2a9865821..3b9bb7cd08ad 100644 --- a/drivers/net/wireless/mediatek/mt76/sdio.c +++ b/drivers/net/wireless/mediatek/mt76/sdio.c @@ -478,7 +478,7 @@ static void mt76s_status_worker(struct mt76_worker *w) if (ndata_frames > 0) resched = true; - if (dev->drv->tx_status_data && + if (dev->drv->tx_status_data && ndata_frames > 0 && !test_and_set_bit(MT76_READING_STATS, &dev->phy.state) && !test_bit(MT76_STATE_SUSPEND, &dev->phy.state)) queue_work(dev->wq, &dev->sdio.stat_work); From patchwork Mon Jul 18 20:52:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Wang X-Patchwork-Id: 12921766 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5C6E1C43334 for ; Mon, 18 Jul 2022 20:53:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:CC:To:From:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=IKyc0EEVpAOHwGQI9XZsb3G7/aMJBcZHBfRBc52XVIo=; b=vodyVxMJ497ZwmnGPCXrUnOIkZ arQ7SKALVhQg1da56jq+6qce+KVnkoMi3iDcMXqNAHD+tRAIwiSavGIPJqXhT8Zu4SywpFgIxk/HK 8V+u/SnxBGeOkciqs7hrn4dkt+9D3YAqe4YQlcOQI4Z6dqQimCW8iChLjcfffB2Ib6agkbogZ0zmn ZJugT7G9qfgG8miSUpppsZWW+HHeKpt5hr+bQenrlBKVSitdEAOJ3/tE/7XbcE36X66Sp1d+AgfHl ipYU5Uz6xpqO8cGt0bx4kBloynUETJe6Fjk5r7THSgb5Tck6i1sUiMKG9gGsrnwuzAkZOLrhBFJoP nebxGFZw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oDXjp-0018qO-AH; Mon, 18 Jul 2022 20:53:09 +0000 Received: from mailgw02.mediatek.com ([216.200.240.185]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oDXjl-0018RM-J1 for linux-mediatek@lists.infradead.org; Mon, 18 Jul 2022 20:53:07 +0000 X-UUID: a216005d32be4bef8851dd00f3c85c0c-20220718 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.8,REQID:66b212c1-76a4-48c7-a2e0-888f379806b8,OB:0,LO B:0,IP:0,URL:5,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,RULE:Release_Ham,ACTI ON:release,TS:5 X-CID-META: VersionHash:0f94e32,CLOUDID:b24e9e64-0b3f-4b2c-b3a6-ed5c044366a0,C OID:IGNORED,Recheck:0,SF:nil,TC:nil,Content:0,EDM:-3,IP:nil,URL:1,File:nil ,QS:nil,BEC:nil,COL:0 X-UUID: a216005d32be4bef8851dd00f3c85c0c-20220718 Received: from mtkmbs11n1.mediatek.inc [(172.21.101.185)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1398668478; Mon, 18 Jul 2022 13:52:55 -0700 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by mtkmbs11n2.mediatek.inc (172.21.101.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.3; Tue, 19 Jul 2022 04:52:17 +0800 Received: from mtkswgap22.mediatek.inc (172.21.77.33) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.3 via Frontend Transport; Tue, 19 Jul 2022 04:52:17 +0800 From: To: , CC: , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH 3/3] mt76: mt7663s: fix the deadlock caused by sdio->stat_work Date: Tue, 19 Jul 2022 04:52:15 +0800 Message-ID: <106a510630a27440b49170e9586f9dfbe831848e.1658176763.git.sean.wang@kernel.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220718_135305_654492_39B937D4 X-CRM114-Status: GOOD ( 12.24 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org From: Sean Wang Because wake_work and sdio->stat_work share the same workqueue mt76->wq, if sdio->stat_work cannot acquire the mutex lock such as that was possibly held up by mt7615_mutex_acquire, we should exit immediately and schedule another stat_work to avoid blocking the mt7615_mutex_acquire. Also, if mt7615_mutex_acquire was called by sdio->stat_work self, the wake would be blocked by itself, so we have to changing into an unblocking wake (directly wakeup via mt7615_mcu_drv_pmctrl, not via the wake_work) in the context. Fixes: a66cbdd6573d ("mt76: mt7615: introduce mt7663s support") Co-developed-by: YN Chen Signed-off-by: YN Chen Signed-off-by: Sean Wang --- .../wireless/mediatek/mt76/mt7615/usb_sdio.c | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/usb_sdio.c b/drivers/net/wireless/mediatek/mt76/mt7615/usb_sdio.c index 0052d103e276..5991b23e0d13 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/usb_sdio.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/usb_sdio.c @@ -157,10 +157,29 @@ bool mt7663_usb_sdio_tx_status_data(struct mt76_dev *mdev, u8 *update) { struct mt7615_dev *dev = container_of(mdev, struct mt7615_dev, mt76); - mt7615_mutex_acquire(dev); + if (!mutex_trylock(&mdev->mutex)) { + /* Because wake_work and stat_work share the same workqueue + * mt76->wq, if sdio->stat_work cannot acquire the mutex lock, + * we should exit immediately and schedule another stat_work + * to avoid blocking the wake_work. + */ + struct work_struct *stat_work; + + stat_work = mt76_is_sdio(mdev) ? &mdev->sdio.stat_work : + &mdev->usb.stat_work; + queue_work(dev->mt76.wq, stat_work); + + goto out; + } + + mt7615_mcu_set_drv_ctrl(dev); + mt7615_mac_sta_poll(dev); - mt7615_mutex_release(dev); + mt76_connac_power_save_sched(&mdev->phy, &dev->pm); + mutex_unlock(&mdev->mutex); + +out: return false; } EXPORT_SYMBOL_GPL(mt7663_usb_sdio_tx_status_data);