Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp647538pxb; Tue, 5 Apr 2022 17:12:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzYv0O9JTBEpR/Bqu+WPmAz0RpAPZDWRsDDqHOEXQix2aF4ApKtS0JR/fGSyvH4b5xVVLGg X-Received: by 2002:a17:90b:4b0f:b0:1c7:718e:a567 with SMTP id lx15-20020a17090b4b0f00b001c7718ea567mr6942983pjb.83.1649203966753; Tue, 05 Apr 2022 17:12:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649203966; cv=none; d=google.com; s=arc-20160816; b=Hfc7OysCGWUrHBZgTKgZXeNDh1Mq6oXndpL3mDcPf9fyD7UFT9JHLtJRSAMdF7pleu x5ZpJclehmoGGl32UcirfVt73iOqjX+4gr6TOix27hi/NHHEXUFUEI+r7c22Ut+1tvIp P0qp43odcdpOS+loi2tLizMZv6CTRad+GAW8OLNE3f5difyivEW+Ac3pAS9cS6OL31Ge ByINlIC+1ugrwlXOpEOJGxIrZ9QFoGvSUZas4A+uPS0xwmesl7S0MBGp4ETfumagn/jP xILQsmaEnkPYpalkQS/K/Ujg/V2ixr7qTq8TImEhigS/i7EQFxcnBaDRsFUI9aFutnGf /ELQ== 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=fmcID+hIDvpOl7z54yTXtm3m43TpfpIONj9yu9MLUeQ=; b=V4UrmoWVFQ/9H+RcTWpQVLzn0ZSQYIezlCT7t/nGH3SA9hCQ8vzpGGjaXbkaVDgG0P mg4QnxzP065HRS0LNEIw0FRoSOsbifZT4zP3SPTLhy1v+qNAaCUPjBF7VZBty0RI/Inf AUtjRn3Eaz5sRJCHSNp7ndeu/MbS8WI5PWrjYe1d3kAppBfmA4lzjxBixTkhdhOGzG7i Oj+pRvR+F7QoCflMEZ4A2l9XzBWQP+wTAXNQwdcqIi6C6/BQswFsddo9pdq3+oqmrpe3 ZTY5OzGTx6WsKzB/DYAQFY26YtqNLpTXFFrQdCVo7LgObFRoamr8TpVjxaravmXJBy8Q vv0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="o/8vg2Pn"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id v9-20020a63f849000000b00398a43ddfa3si14495993pgj.19.2022.04.05.17.12.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 17:12:46 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="o/8vg2Pn"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DD871181B0C; Tue, 5 Apr 2022 16:57:01 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245309AbiDEM31 (ORCPT + 99 others); Tue, 5 Apr 2022 08:29:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245340AbiDEIzH (ORCPT ); Tue, 5 Apr 2022 04:55:07 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BFE1101F5; Tue, 5 Apr 2022 01:52:15 -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 1840E61003; Tue, 5 Apr 2022 08:52:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27D8AC385A1; Tue, 5 Apr 2022 08:52:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649148734; bh=WvuNd515yfCemETt0J5SFAOnaL3gooZmvJup2s+DEBo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o/8vg2PnHBTdcbSVHJRp4ZynE9NJDklS420L536EJf02jJ+b0F+wuJgfKPiOkJBd8 F66+0FfFNq2Dfp28HaPYxGb+bKr8LgP2bRduaz10VDiBcUwNxomW3cJxNvWL5LXMqf bIz+JXZU7U+11C+n4uxsPE06j+IeIq7ozW6nqCgk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Wang , Leon Yen , Felix Fietkau , Sasha Levin Subject: [PATCH 5.16 0461/1017] mt76: mt7921s: fix mt7921s_mcu_[fw|drv]_pmctrl Date: Tue, 5 Apr 2022 09:22:54 +0200 Message-Id: <20220405070407.983142060@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 From: Leon Yen [ Upstream commit b12deb5e86fa36dc6f3aa3321f5da27addec4f1f ] According to the firmware behavior (even the oldest one in linux-firmware) If the firmware is downloaded, MT7921S must rely on the additional mailbox mechanism that resides in firmware to check if the device is the right state for mt7921s_mcu_[fw|drv]_pmctrl. Otherwise, we still apply the old way for that. That is a necessary patch before we enable runtime pm for mt7921s as default. Fixes: 48fab5bbef40 ("mt76: mt7921: introduce mt7921s support") Co-developed-by: Sean Wang Signed-off-by: Sean Wang Signed-off-by: Leon Yen Signed-off-by: Felix Fietkau Signed-off-by: Sasha Levin --- .../wireless/mediatek/mt76/mt7921/sdio_mcu.c | 38 +++++++++++++++++++ drivers/net/wireless/mediatek/mt76/sdio.h | 2 + 2 files changed, 40 insertions(+) diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/sdio_mcu.c b/drivers/net/wireless/mediatek/mt76/mt7921/sdio_mcu.c index 437cddad9a90..353d99fef065 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/sdio_mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/sdio_mcu.c @@ -49,6 +49,26 @@ mt7921s_mcu_send_message(struct mt76_dev *mdev, struct sk_buff *skb, return ret; } +static u32 mt7921s_read_rm3r(struct mt7921_dev *dev) +{ + struct mt76_sdio *sdio = &dev->mt76.sdio; + + return sdio_readl(sdio->func, MCR_D2HRM3R, NULL); +} + +static u32 mt7921s_clear_rm3r_drv_own(struct mt7921_dev *dev) +{ + struct mt76_sdio *sdio = &dev->mt76.sdio; + u32 val; + + val = sdio_readl(sdio->func, MCR_D2HRM3R, NULL); + if (val) + sdio_writel(sdio->func, H2D_SW_INT_CLEAR_MAILBOX_ACK, + MCR_WSICR, NULL); + + return val; +} + int mt7921s_mcu_init(struct mt7921_dev *dev) { static const struct mt76_mcu_ops mt7921s_mcu_ops = { @@ -88,6 +108,12 @@ int mt7921s_mcu_drv_pmctrl(struct mt7921_dev *dev) err = readx_poll_timeout(mt76s_read_pcr, &dev->mt76, status, status & WHLPCR_IS_DRIVER_OWN, 2000, 1000000); + + if (!err && test_bit(MT76_STATE_MCU_RUNNING, &dev->mphy.state)) + err = readx_poll_timeout(mt7921s_read_rm3r, dev, status, + status & D2HRM3R_IS_DRIVER_OWN, + 2000, 1000000); + sdio_release_host(func); if (err < 0) { @@ -115,12 +141,24 @@ int mt7921s_mcu_fw_pmctrl(struct mt7921_dev *dev) sdio_claim_host(func); + if (test_bit(MT76_STATE_MCU_RUNNING, &dev->mphy.state)) { + err = readx_poll_timeout(mt7921s_clear_rm3r_drv_own, + dev, status, + !(status & D2HRM3R_IS_DRIVER_OWN), + 2000, 1000000); + if (err < 0) { + dev_err(dev->mt76.dev, "mailbox ACK not cleared\n"); + goto err; + } + } + sdio_writel(func, WHLPCR_FW_OWN_REQ_SET, MCR_WHLPCR, NULL); err = readx_poll_timeout(mt76s_read_pcr, &dev->mt76, status, !(status & WHLPCR_IS_DRIVER_OWN), 2000, 1000000); sdio_release_host(func); +err: if (err < 0) { dev_err(dev->mt76.dev, "firmware own failed\n"); clear_bit(MT76_STATE_PM, &mphy->state); diff --git a/drivers/net/wireless/mediatek/mt76/sdio.h b/drivers/net/wireless/mediatek/mt76/sdio.h index 99db4ad93b7c..27d5d2077eba 100644 --- a/drivers/net/wireless/mediatek/mt76/sdio.h +++ b/drivers/net/wireless/mediatek/mt76/sdio.h @@ -65,6 +65,7 @@ #define MCR_H2DSM0R 0x0070 #define H2D_SW_INT_READ BIT(16) #define H2D_SW_INT_WRITE BIT(17) +#define H2D_SW_INT_CLEAR_MAILBOX_ACK BIT(22) #define MCR_H2DSM1R 0x0074 #define MCR_D2HRM0R 0x0078 @@ -109,6 +110,7 @@ #define MCR_H2DSM2R 0x0160 /* supported in CONNAC2 */ #define MCR_H2DSM3R 0x0164 /* supported in CONNAC2 */ #define MCR_D2HRM3R 0x0174 /* supported in CONNAC2 */ +#define D2HRM3R_IS_DRIVER_OWN BIT(0) #define MCR_WTQCR8 0x0190 /* supported in CONNAC2 */ #define MCR_WTQCR9 0x0194 /* supported in CONNAC2 */ #define MCR_WTQCR10 0x0198 /* supported in CONNAC2 */ -- 2.34.1