From patchwork Tue Nov 29 09:16:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deren Wu X-Patchwork-Id: 629458 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1015C4332F for ; Tue, 29 Nov 2022 09:17:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229797AbiK2JRN (ORCPT ); Tue, 29 Nov 2022 04:17:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229774AbiK2JRM (ORCPT ); Tue, 29 Nov 2022 04:17:12 -0500 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A7675655F for ; Tue, 29 Nov 2022 01:17:07 -0800 (PST) X-UUID: 470a8632d5264003a1798683f8a55651-20221129 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=vPZP8OXAsUHf4FSEg8/nwXU6njDiIjCMBp/8fZvopqI=; b=Kh8a4iLaWFBBw1W1JG/j113TLlO4YdsCdOydnClfdB9pZWxMfsTwLhvkdp0TYOoGN+gik/g+NCYbdTYP5kwZTdkQlm5fRPnOBcvUlWTbQbeKAde/JSyM0ZuQfdFII8fonH5hB7C3EzhcFy7oglUQ3oBWZxpi5MEbWTPe425O+L0=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.14, REQID:bd631a99-6455-483a-b545-b6aa740feca3, IP:0, U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:dcaaed0, CLOUDID:80749d1e-5e1d-4ab5-ab8e-3e04efc02b30, B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 X-UUID: 470a8632d5264003a1798683f8a55651-20221129 Received: from mtkmbs11n2.mediatek.inc [(172.21.101.187)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 830181379; Tue, 29 Nov 2022 17:17:02 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) 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.15; Tue, 29 Nov 2022 17:17:00 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs13n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Tue, 29 Nov 2022 17:17:00 +0800 From: Deren Wu To: Felix Fietkau , Lorenzo Bianconi CC: Sean Wang , Soul Huang , YN Chen , Leon Yen , Eric-SY Chang , Deren Wu , KM Lin , Robin Chiu , CH Yeh , Posh Sun , Stella Chang , Evelyn Tsai , Ryder Lee , Shayne Chen , linux-wireless , linux-mediatek , Deren Wu Subject: [PATCH v2 1/2] wifi: mt76: introduce reboot notifier support Date: Tue, 29 Nov 2022 17:16:37 +0800 Message-ID: X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Some combinations of hosts cannnot detect wifi chip after reboot. The interoperability issue is caused by the status mismatch between host and chip fw. In such cases, the driver should stop chip activities and reset chip to default state before reboot. This is a preliminary patch to add mt7921e reboot notifier support. Reviewed-by: Shayne Chen Signed-off-by: Deren Wu --- drivers/net/wireless/mediatek/mt76/mac80211.c | 21 +++++++++++++++++++ drivers/net/wireless/mediatek/mt76/mt76.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c b/drivers/net/wireless/mediatek/mt76/mac80211.c index fc608b369b3c..a8515cb2527e 100644 --- a/drivers/net/wireless/mediatek/mt76/mac80211.c +++ b/drivers/net/wireless/mediatek/mt76/mac80211.c @@ -230,6 +230,22 @@ static void mt76_led_cleanup(struct mt76_dev *dev) led_classdev_unregister(&dev->led_cdev); } +static int mt76_notifier_init(struct mt76_dev *dev) +{ + if (!dev->reboot_nb.notifier_call) + return 0; + + return register_reboot_notifier(&dev->reboot_nb); +} + +static void mt76_notifier_cleanup(struct mt76_dev *dev) +{ + if (!dev->reboot_nb.notifier_call) + return; + + unregister_reboot_notifier(&dev->reboot_nb); +} + static void mt76_init_stream_cap(struct mt76_phy *phy, struct ieee80211_supported_band *sband, bool vht) @@ -658,6 +674,10 @@ int mt76_register_device(struct mt76_dev *dev, bool vht, return ret; } + ret = mt76_notifier_init(dev); + if (ret) + return ret; + ret = ieee80211_register_hw(hw); if (ret) return ret; @@ -675,6 +695,7 @@ void mt76_unregister_device(struct mt76_dev *dev) if (IS_ENABLED(CONFIG_MT76_LEDS)) mt76_led_cleanup(dev); + mt76_notifier_cleanup(dev); mt76_tx_status_check(dev, true); ieee80211_unregister_hw(hw); } diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h index 32a77a0ae9da..73a504016288 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76.h +++ b/drivers/net/wireless/mediatek/mt76/mt76.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include "util.h" @@ -835,6 +836,7 @@ struct mt76_dev { struct mt76_usb usb; struct mt76_sdio sdio; }; + struct notifier_block reboot_nb; }; struct mt76_power_limits { From patchwork Tue Nov 29 09:16:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deren Wu X-Patchwork-Id: 629873 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 718C5C46467 for ; Tue, 29 Nov 2022 09:17:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230126AbiK2JRQ (ORCPT ); Tue, 29 Nov 2022 04:17:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230054AbiK2JRP (ORCPT ); Tue, 29 Nov 2022 04:17:15 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DF894FFB4 for ; Tue, 29 Nov 2022 01:17:11 -0800 (PST) X-UUID: 8e384f1d5597417597f6305d81585628-20221129 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=hGI849UFbeArvUGAYymChJry3M7MR3AoHOIh4fuiXYs=; b=WFl9wSsFdWvMg86+e6pQGlJkvklIjPU0xQs2erZ+H/lQoUUymnOeWYHQ/3VQ3/uPwRh7XcOtwh6HR+3DGvLwyebM3ZA9XAZngXS/VaBjrs7WhbzYljLEmhfX4+dAZ7BKdbzpGoT8Stz6IEmJPD5lhAqtCGrsZeCne2bx/uXehJ0=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.14, REQID:7e6b4f49-ce9b-40d5-a530-8b271f2d2ce3, IP:0, U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:95 X-CID-INFO: VERSION:1.1.14, REQID:7e6b4f49-ce9b-40d5-a530-8b271f2d2ce3, IP:0, URL :0,TC:0,Content:0,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Spam_GS981B3D,ACTION :quarantine,TS:95 X-CID-META: VersionHash:dcaaed0, CLOUDID:41588917-81a9-4b5f-95c6-b6b92590fd73, B ulkID:221129171707NNKM31J0,BulkQuantity:0,Recheck:0,SF:38|28|17|19|48,TC:n il,Content:0,EDM:-3,IP:nil,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 X-UUID: 8e384f1d5597417597f6305d81585628-20221129 Received: from mtkmbs13n1.mediatek.inc [(172.21.101.193)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1368778600; Tue, 29 Nov 2022 17:17:04 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by mtkmbs13n1.mediatek.inc (172.21.101.193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.15; Tue, 29 Nov 2022 17:17:02 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs13n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Tue, 29 Nov 2022 17:17:02 +0800 From: Deren Wu To: Felix Fietkau , Lorenzo Bianconi CC: Sean Wang , Soul Huang , YN Chen , Leon Yen , Eric-SY Chang , Deren Wu , KM Lin , Robin Chiu , CH Yeh , Posh Sun , Stella Chang , Evelyn Tsai , Ryder Lee , Shayne Chen , linux-wireless , linux-mediatek , Deren Wu Subject: [PATCH v2 2/2] wifi: mt76: mt7921e: add reboot notifier support Date: Tue, 29 Nov 2022 17:16:38 +0800 Message-ID: X-Mailer: git-send-email 2.18.0 In-Reply-To: References: MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Leon Yen cleanup/reset chip fw before reboot to avoid unstable problems in next run. Co-developed-by: Deren Wu Signed-off-by: Deren Wu Signed-off-by: Leon Yen --- .../net/wireless/mediatek/mt76/mt7921/pci.c | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/pci.c b/drivers/net/wireless/mediatek/mt76/mt7921/pci.c index 28342ec940f0..4e9021c349b9 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/pci.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/pci.c @@ -226,6 +226,25 @@ static u32 mt7921_rmw(struct mt76_dev *mdev, u32 offset, u32 mask, u32 val) return dev->bus_ops->rmw(mdev, addr, mask, val); } +static int mt7921e_reboot_notifier(struct notifier_block *nb, + unsigned long code, void *unused) +{ + struct mt76_dev *mdev = container_of(nb, struct mt76_dev, + reboot_nb); + struct mt7921_dev *dev = container_of(mdev, struct mt7921_dev, mt76); + struct mt76_connac_pm *pm = &dev->pm; + + cancel_delayed_work_sync(&pm->ps_work); + cancel_work_sync(&pm->wake_work); + + /* chip cleanup before reboot */ + mt7921_mcu_drv_pmctrl(dev); + mt7921_dma_cleanup(dev); + mt7921_wfsys_reset(dev); + + return NOTIFY_DONE; +} + static int mt7921_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) { @@ -357,6 +376,8 @@ static int mt7921_pci_probe(struct pci_dev *pdev, if (ret) goto err_free_irq; + mdev->reboot_nb.notifier_call = mt7921e_reboot_notifier; + ret = mt7921_register_device(dev); if (ret) goto err_free_irq;