From patchwork Sat Oct 22 07:21:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7308 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1093355wrr; Sat, 22 Oct 2022 00:56:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4/j2dOikojZS9+oq0QxIFpcm45X3PJdcwKK7Xg/PuvNeG6Do0MCDJUP3Yhpkv/7ejpLxe+ X-Received: by 2002:a65:4c0c:0:b0:45f:f12d:f46f with SMTP id u12-20020a654c0c000000b0045ff12df46fmr19633881pgq.579.1666425418866; Sat, 22 Oct 2022 00:56:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666425418; cv=none; d=google.com; s=arc-20160816; b=usu6SeW9NXL65SfhH9TnzYZti4fu5vjzlPvi6Oglz9D/WlbER10i2rRQsnROn+yoN5 aLMAEqKWi1Vv5DG8C2JTqzpJkUN9+1QIu2ODbnZmVzLs0SGa4umffNPhbWm3BQUBOhR/ qrf17AAT3lMqY5FYbwINBWfTW0kxhbLjxrGlkP1u6fu4IeQ6GAGs89pJ4O2E+hp6GnTy 6sHu+uSRVIprS8iyxgJ5sSJydM09z6gAmFVI3AK99d/5RO1uU6vXqB3A4/ZqD+KaAbgK QqJlksiBjjALDN29MKDY28QfLv3oUT0xg0kVcCylGhWtDV/lCqDzEQlfCkmQ+nvfYKfW yvmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=CPAiZ8LxqUuUbJ57SYwBf90RYJhKPSO+BnS3dk141NU=; b=MTfjX05+1K3nDTXnfCLOMfOY44P5DNh/pRb70I71UDRpfhppzYhbha8dzz2dGMmVfT leKiJWelaFxrXJUENG85qSeTmiPI0JBzTRvXsYSgrPgUSB8NhE01uvfkuWBMlHnhG43T +116SvbWP3FkCuDBaKkrtZ8xnFkqb5utrh9RZx5BM07glygenS3w+92jV6yTijg1zOCB 2aTqJOK0cQUpNXI1Vt7NItToDWU/UJ/c7K1MwmEyCixEo31WaVBBMmc45lHLwzEx2tAv Uw/PlW6t9+kXEN/OWfwqeBgokW8rhvhvfL1FqrX7vspaorXwF0Nh0baGKwADJiyB3Tcq +pUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lNLMWu41; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d5-20020aa78e45000000b005635bfe397bsi24630791pfr.218.2022.10.22.00.56.45; Sat, 22 Oct 2022 00:56:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lNLMWu41; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232283AbiJVH4W (ORCPT + 99 others); Sat, 22 Oct 2022 03:56:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231826AbiJVHwi (ORCPT ); Sat, 22 Oct 2022 03:52:38 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65ACF2C6EB7; Sat, 22 Oct 2022 00:46:50 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7C11E60BB5; Sat, 22 Oct 2022 07:44:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8AED6C433D6; Sat, 22 Oct 2022 07:44:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424681; bh=Ezjo1GhHEo9V8xJkef95aeBkTOtIzA4CqJ/f1m1eZJc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lNLMWu419+CvpvQqVMNNw7kWJaVbNC9ePPdDJHD4Itgdp0crUUTMvo8W3VeSbvgmE F7+CcnMx9xNjQdQtbllsC5YNp9y2fYSxGICrM8nC+G9od7gn8ovZS5rrhWxYKxCjZz hejcNuvdfS4sAAb6ioCY0qiQybiWZrDkUbvjFMPg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, YN Chen , Sean Wang , Felix Fietkau , Sasha Levin Subject: [PATCH 5.19 237/717] wifi: mt76: mt7921e: fix race issue between reset and suspend/resume Date: Sat, 22 Oct 2022 09:21:56 +0200 Message-Id: <20221022072456.938168436@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747373700036756747?= X-GMAIL-MSGID: =?utf-8?q?1747373700036756747?= From: Sean Wang [ Upstream commit ff6c4a6449793e9718ef2e9ad46864b63022648e ] It is unexpected that the reset work is running simultaneously with the suspend or resume context and it is possible that reset work is still running even after mt7921 is suspended if we don't fix the race issue. Thus, the suspend procedure should be waiting until the reset is completed at the beginning and ignore the subsequent the reset requests. In case there is an error that happens during either suspend or resume handler, we will schedule a reset task to recover the error before returning the error code to ensure we can immediately fix the error there. Fixes: 0c1ce9884607 ("mt76: mt7921: add wifi reset support") Co-developed-by: YN Chen Signed-off-by: YN Chen Signed-off-by: Sean Wang Signed-off-by: Felix Fietkau Signed-off-by: Sasha Levin --- drivers/net/wireless/mediatek/mt76/mt7921/mac.c | 5 +++++ drivers/net/wireless/mediatek/mt76/mt7921/pci.c | 13 +++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c index 2a2ea7b9977a..7e0cddc2aeab 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c @@ -1215,6 +1215,7 @@ void mt7921_mac_reset_work(struct work_struct *work) void mt7921_reset(struct mt76_dev *mdev) { struct mt7921_dev *dev = container_of(mdev, struct mt7921_dev, mt76); + struct mt76_connac_pm *pm = &dev->pm; if (!dev->hw_init_done) return; @@ -1222,8 +1223,12 @@ void mt7921_reset(struct mt76_dev *mdev) if (dev->hw_full_reset) return; + if (pm->suspended) + return; + queue_work(dev->mt76.wq, &dev->reset_work); } +EXPORT_SYMBOL_GPL(mt7921_reset); void mt7921_mac_update_mib_stats(struct mt7921_phy *phy) { diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/pci.c b/drivers/net/wireless/mediatek/mt76/mt7921/pci.c index b5fb22b8e086..295c21586273 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/pci.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/pci.c @@ -368,6 +368,7 @@ static int mt7921_pci_suspend(struct pci_dev *pdev, pm_message_t state) int i, err; pm->suspended = true; + flush_work(&dev->reset_work); cancel_delayed_work_sync(&pm->ps_work); cancel_work_sync(&pm->wake_work); @@ -433,6 +434,9 @@ static int mt7921_pci_suspend(struct pci_dev *pdev, pm_message_t state) restore_suspend: pm->suspended = false; + if (err < 0) + mt7921_reset(&dev->mt76); + return err; } @@ -451,7 +455,7 @@ static int mt7921_pci_resume(struct pci_dev *pdev) err = mt7921_mcu_drv_pmctrl(dev); if (err < 0) - return err; + goto failed; mt7921_wpdma_reinit_cond(dev); @@ -481,11 +485,12 @@ static int mt7921_pci_resume(struct pci_dev *pdev) mt76_connac_mcu_set_deep_sleep(&dev->mt76, false); err = mt76_connac_mcu_set_hif_suspend(mdev, false); - if (err) - return err; - +failed: pm->suspended = false; + if (err < 0) + mt7921_reset(&dev->mt76); + return err; } #endif /* CONFIG_PM */