From patchwork Sun Apr 18 16:36:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Wang X-Patchwork-Id: 12210233 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=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, USER_AGENT_GIT autolearn=unavailable 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 707C8C433B4 for ; Sun, 18 Apr 2021 16:36:48 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E8E4F61165 for ; Sun, 18 Apr 2021 16:36:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E8E4F61165 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=mediatek.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+lJbEb8T+pBRbalnzcP25hUPCZCSyMQbkKu81sU5Muc=; b=ORfcP2+fJGdgLj1gESjWP4hBu oesOzvsL2MOiGsFkIJWHZh8F1NVAeW98OwAYdHRunOXxAWpRnMeBNp1x3bcf4agbRR3CVGVY0Yevy oNSATz2mMn+iqwgXXiydSHxFIacen2GvGkJ0o2JWQfS+y96VIq3qy68wMgLIPnproY6MC5KVzc34C mfuVLioazp7cM4HQAoXImMzsQYw3hzvo0GCNv563ree1lZjXi8K/jiRe5/uauzqJ3Y2tZQB5qSzzp r6jahdWGQol3l5I9bk+yssQ8cEVDtD8XevGjiSanFH5AzFo5wJ6+Lu7TS0yWtXFBohdqy20rRMQFs 5tz+VGRTw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lYAPO-008Jyz-9K; Sun, 18 Apr 2021 16:36:30 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lYAPI-008Jxv-Mj for linux-mediatek@desiato.infradead.org; Sun, 18 Apr 2021 16:36:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC: To:From:Sender:Reply-To:Content-ID:Content-Description; bh=5MVvoCEKVTG7o4ngMaLW6BWz7pIQW0m1uTGHVpIEpn0=; b=VNKwZ9ShbRygLMloUuIFo0r3d7 pQYG32qlPNfqqW1NqYvqIxdFIyF12KZoSgddxJpSMB1rNW89YCb1wHvuiD0jm2qfMirTI0ckTYLqn MCSqmp5eWw6H/j08ZXvJLWzOQJM/szrwBbkmPdn4zlj5zpmyUM/5y00v4GmN8RFGD2EOLUoiqeIZy tMwn4rCPTeBtz1zggdAJfv792amk/bZoFYfioXL8DH5MtGVki+0JTfO7IC5dOHJKNZQT9hn7DCAKx ZKoNDl05u/YmfVwMlkUNJP8xv2yHfNyyNiSfdiBrhVKS4kJ4GGEwq5utTbdigMkxNuQ06wG/VmArt qMuimlfg==; Received: from mailgw01.mediatek.com ([216.200.240.184]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lYAPF-00AVnw-Rk for linux-mediatek@lists.infradead.org; Sun, 18 Apr 2021 16:36:23 +0000 X-UUID: d7731bd780ad4e7781e47849c7034b94-20210418 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=5MVvoCEKVTG7o4ngMaLW6BWz7pIQW0m1uTGHVpIEpn0=; b=mck/snMfANBc7vai5V7MFXkRShDaZtuaXbXMDgSivcKOEwXiodHRT/z8hmiJRC3kdY+YNBtDXlONjhjUV/geznzg1DsFw8EH/gPKnnhWp5GZVwZzZOeVd+AF+/Ab8FPt3IFG/FFQgyoXuC717JHYH/GtDxip7W8e2DpP4d1vAiI=; X-UUID: d7731bd780ad4e7781e47849c7034b94-20210418 Received: from mtkcas67.mediatek.inc [(172.29.193.45)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 367804595; Sun, 18 Apr 2021 09:36:19 -0700 Received: from MTKMBS01N2.mediatek.inc (172.21.101.79) by MTKMBS62N1.mediatek.inc (172.29.193.41) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sun, 18 Apr 2021 09:36:17 -0700 Received: from mtkcas11.mediatek.inc (172.21.101.40) by mtkmbs01n2.mediatek.inc (172.21.101.79) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 19 Apr 2021 00:36:09 +0800 Received: from mtkswgap22.mediatek.inc (172.21.77.33) by mtkcas11.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 19 Apr 2021 00:36:09 +0800 From: To: , CC: , , , , , , , , , , , , , Leon Yen , Lorenzo Bianconi Subject: [PATCH 4/6] mt76: mt7921: introduce mt7921_wpdma_reinit_cond utility routine Date: Mon, 19 Apr 2021 00:36:05 +0800 Message-ID: <1618763767-1292-5-git-send-email-sean.wang@mediatek.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1618763767-1292-1-git-send-email-sean.wang@mediatek.com> References: <1618763767-1292-1-git-send-email-sean.wang@mediatek.com> MIME-Version: 1.0 X-TM-SNTS-SMTP: 01C456E25688B0D85D405DE075C71174F0D2B1E6ACDEB96D220DE24DE2B40C082000:8 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210418_093621_942336_0BED111A X-CRM114-Status: GOOD ( 12.38 ) 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 Add mt7921_wpdma_reinit_cond to check dummy reg if driver needs to reinitialized WPDMA after driver_own operation Co-developed-by: Leon Yen Signed-off-by: Leon Yen Signed-off-by: Lorenzo Bianconi Signed-off-by: Sean Wang --- .../net/wireless/mediatek/mt76/mt76_connac.h | 4 +++ .../wireless/mediatek/mt76/mt7921/debugfs.c | 13 ++++++++++ .../net/wireless/mediatek/mt76/mt7921/dma.c | 25 +++++++++++++++++++ .../wireless/mediatek/mt76/mt7921/mt7921.h | 6 +++++ 4 files changed, 48 insertions(+) diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac.h b/drivers/net/wireless/mediatek/mt76/mt76_connac.h index b811f3c410a1..3b5bff80a462 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76_connac.h +++ b/drivers/net/wireless/mediatek/mt76/mt76_connac.h @@ -58,6 +58,10 @@ struct mt76_connac_pm { struct delayed_work ps_work; unsigned long last_activity; unsigned long idle_timeout; + + struct { + unsigned int lp_wake; + } stats; }; struct mt76_connac_coredump { diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt7921/debugfs.c index 5a54cd8d2ce4..bd2aca654767 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/debugfs.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/debugfs.c @@ -256,6 +256,17 @@ mt7921_pm_get(void *data, u64 *val) DEFINE_DEBUGFS_ATTRIBUTE(fops_pm, mt7921_pm_get, mt7921_pm_set, "%lld\n"); +static int +mt7921_pm_stats(struct seq_file *s, void *data) +{ + struct mt7921_dev *dev = dev_get_drvdata(s->private); + struct mt76_connac_pm *pm = &dev->pm; + + seq_printf(s, "low power wakes: %9d\n", pm->stats.lp_wake); + + return 0; +} + static int mt7921_pm_idle_timeout_set(void *data, u64 val) { @@ -322,6 +333,8 @@ int mt7921_init_debugfs(struct mt7921_dev *dev) debugfs_create_file("idle-timeout", 0600, dir, dev, &fops_pm_idle_timeout); debugfs_create_file("chip_reset", 0600, dir, dev, &fops_reset); + debugfs_create_devm_seqfile(dev->mt76.dev, "runtime_pm_stats", dir, + mt7921_pm_stats); return 0; } diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/dma.c b/drivers/net/wireless/mediatek/mt76/mt7921/dma.c index 8c556ff3ae93..72f5704f8f11 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/dma.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/dma.c @@ -329,6 +329,31 @@ int mt7921_wpdma_reset(struct mt7921_dev *dev, bool force) return 0; } +int mt7921_wpdma_reinit_cond(struct mt7921_dev *dev) +{ + struct mt76_connac_pm *pm = &dev->pm; + int err; + + /* check if the wpdma must be reinitialized */ + if (mt7921_dma_need_reinit(dev)) { + /* disable interrutpts */ + mt76_wr(dev, MT_WFDMA0_HOST_INT_ENA, 0); + mt76_wr(dev, MT_PCIE_MAC_INT_ENABLE, 0x0); + + err = mt7921_wpdma_reset(dev, false); + if (err) { + dev_err(dev->mt76.dev, "wpdma reset failed\n"); + return err; + } + + /* enable interrutpts */ + mt76_wr(dev, MT_PCIE_MAC_INT_ENABLE, 0xff); + pm->stats.lp_wake++; + } + + return 0; +} + int mt7921_dma_init(struct mt7921_dev *dev) { /* Increase buffer size to receive large VHT/HE MPDUs */ diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h b/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h index 06a85d2d1c6f..bb4961d3969a 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h +++ b/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h @@ -254,6 +254,7 @@ int mt7921_eeprom_get_target_power(struct mt7921_dev *dev, void mt7921_eeprom_init_sku(struct mt7921_dev *dev); int mt7921_dma_init(struct mt7921_dev *dev); int mt7921_wpdma_reset(struct mt7921_dev *dev, bool force); +int mt7921_wpdma_reinit_cond(struct mt7921_dev *dev); void mt7921_dma_cleanup(struct mt7921_dev *dev); int mt7921_run_firmware(struct mt7921_dev *dev); int mt7921_mcu_init(struct mt7921_dev *dev); @@ -317,6 +318,11 @@ mt7921_l1_rmw(struct mt7921_dev *dev, u32 addr, u32 mask, u32 val) #define mt7921_l1_set(dev, addr, val) mt7921_l1_rmw(dev, addr, 0, val) #define mt7921_l1_clear(dev, addr, val) mt7921_l1_rmw(dev, addr, val, 0) +static inline bool mt7921_dma_need_reinit(struct mt7921_dev *dev) +{ + return !mt76_get_field(dev, MT_WFDMA_DUMMY_CR, MT_WFDMA_NEED_REINIT); +} + void mt7921_mac_init(struct mt7921_dev *dev); bool mt7921_mac_wtbl_update(struct mt7921_dev *dev, int idx, u32 mask); void mt7921_mac_reset_counters(struct mt7921_phy *phy);