Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp3268022rwl; Thu, 13 Apr 2023 19:13:58 -0700 (PDT) X-Google-Smtp-Source: AKy350bQTBzZE5VOxNiPT+t57iDNp638jzmyYGgDbvIHwoL2VL1E5Wf11NtpxmPNZLRGcl/9YAeu X-Received: by 2002:a17:902:e801:b0:1a6:4714:5cb2 with SMTP id u1-20020a170902e80100b001a647145cb2mr1424373plg.2.1681438437974; Thu, 13 Apr 2023 19:13:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681438437; cv=none; d=google.com; s=arc-20160816; b=TCrj9k5MiNrTC2jnyZxbGmacklT2lu6iO3hgKO82rnBzJypP/lIikLbTKhVfrItl8y fOTUqug1jAptO8dJaT5mGuA98HmyCGXj4aixrjrZ3DFhE5eON257szQKf+CWelDeCpK9 Lx8Ngj7okfGKizsEbSdbcesJMKJKbUMnAy0RLxUDPiPSpNZrFwyIkVKwYvHDfBk/WO7Q 1NjIyS6nAG+Pvsva6BQpVwFQkWG/qiA3+6yv3qXcPMGF/sQ3s/O5pAkjG5H63HJCmNdI lAMXsJt1dPMfahZiAbQtgW9W90QS2nWdNS9ItNABD8tY0XZN+Qg25DQo2KlsWp7m/nap 2Qvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from:authenticated-by; bh=79MRZimDD6tkDcs5ZU1kUv2+E8jWSaZIBBLNnaW2rG0=; b=iuBKUDBwPZ9QK0sCLXWoBsLnghRlvzR1NADe2+PeDi66qyeT5IAYH2A0IsNY1TUU6r /zPHrt5xb/F9esP6XpM3MET36Qpd4nn1bllH/APX1zMa5NWn42vhJRbnx3xxn+LYPpaO BhrjJc7A6xLjqyxLgac5GG3FcMddTGzbH4M654xP1A8Dm9iDxvIvZbKQs14dOeA3L5ov sh3RDatlWU6s7qy8p8LMtJ+8XWF9325TzTbvGLjlPbQYZ+hWOhZ123GDErsoytVNMo+o RFeyLjAXupeqZcTDGF5A7q4MhWA7hAkrnaPAvKBrwVs1I5lL38UqwSLW3BTA6bjKit68 FF4w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h1-20020a170902f7c100b001a060012dfcsi3325098plw.114.2023.04.13.19.13.18; Thu, 13 Apr 2023 19:13:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-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; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229724AbjDNCGu convert rfc822-to-8bit (ORCPT + 61 others); Thu, 13 Apr 2023 22:06:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229597AbjDNCGu (ORCPT ); Thu, 13 Apr 2023 22:06:50 -0400 Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44B573C3A; Thu, 13 Apr 2023 19:06:47 -0700 (PDT) Authenticated-By: X-SpamFilter-By: ArmorX SpamTrap 5.77 with qID 33E25M9L0008987, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (rtexh36505.realtek.com.tw[172.21.6.25]) by rtits2.realtek.com.tw (8.15.2/2.81/5.90) with ESMTPS id 33E25M9L0008987 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=OK); Fri, 14 Apr 2023 10:05:22 +0800 Received: from RTEXMBS01.realtek.com.tw (172.21.6.94) by RTEXH36505.realtek.com.tw (172.21.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.32; Fri, 14 Apr 2023 10:05:44 +0800 Received: from RTEXMBS04.realtek.com.tw (172.21.6.97) by RTEXMBS01.realtek.com.tw (172.21.6.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Fri, 14 Apr 2023 10:05:44 +0800 Received: from RTEXMBS04.realtek.com.tw ([fe80::b4a2:2bcc:48d1:8b02]) by RTEXMBS04.realtek.com.tw ([fe80::b4a2:2bcc:48d1:8b02%5]) with mapi id 15.01.2375.007; Fri, 14 Apr 2023 10:05:44 +0800 From: Ping-Ke Shih To: Sascha Hauer CC: linux-wireless , Hans Ulli Kroll , Larry Finger , Tim K , "Alex G ." , Nick Morrow , Viktor Petrenko , Andreas Henriksson , ValdikSS , "kernel@pengutronix.de" , "stable@vger.kernel.org" Subject: RE: [PATCH v2 2/2] wifi: rtw88: rtw8821c: Fix rfe_option field width Thread-Topic: [PATCH v2 2/2] wifi: rtw88: rtw8821c: Fix rfe_option field width Thread-Index: AQHZZsamg/4VwhlxlEqb+Fqs2PgqWa8dhrAAgAfltoCABKdF8A== Date: Fri, 14 Apr 2023 02:05:44 +0000 Message-ID: <303221420e8e467dba0857261970d254@realtek.com> References: <20230404072508.578056-1-s.hauer@pengutronix.de> <20230404072508.578056-3-s.hauer@pengutronix.de> <20230411102609.GB19113@pengutronix.de> In-Reply-To: <20230411102609.GB19113@pengutronix.de> Accept-Language: en-US, zh-TW Content-Language: zh-TW X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.21.69.188] x-kse-serverinfo: RTEXMBS01.realtek.com.tw, 9 x-kse-antispam-interceptor-info: fallback x-kse-antivirus-interceptor-info: fallback Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-ServerInfo: RTEXH36505.realtek.com.tw, 9 X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-Antivirus-Interceptor-Info: fallback X-KSE-AntiSpam-Interceptor-Info: fallback X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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-wireless@vger.kernel.org > -----Original Message----- > From: Sascha Hauer > Sent: Tuesday, April 11, 2023 6:26 PM > To: Ping-Ke Shih > Cc: linux-wireless ; Hans Ulli Kroll ; Larry Finger > ; Tim K ; Alex G . ; Nick Morrow > ; Viktor Petrenko ; Andreas Henriksson ; > ValdikSS ; kernel@pengutronix.de; stable@vger.kernel.org > Subject: Re: [PATCH v2 2/2] wifi: rtw88: rtw8821c: Fix rfe_option field width > > On Thu, Apr 06, 2023 at 01:54:55AM +0000, Ping-Ke Shih wrote: > > > > > > > -----Original Message----- > > > From: Sascha Hauer > > > Sent: Tuesday, April 4, 2023 3:25 PM > > > To: linux-wireless > > > Cc: Hans Ulli Kroll ; Larry Finger ; Ping-Ke Shih > > > ; Tim K ; Alex G . ; Nick Morrow > > > ; Viktor Petrenko ; Andreas Henriksson ; > > > ValdikSS ; kernel@pengutronix.de; Sascha Hauer ; > > > stable@vger.kernel.org > > > Subject: [PATCH v2 2/2] wifi: rtw88: rtw8821c: Fix rfe_option field width > > > > > > On my RTW8821CU chipset rfe_option reads as 0x22. Looking at the > > > downstream driver suggests that the field width of rfe_option is 5 bit, > > > so rfe_option should be masked with 0x1f. > > > > I don't aware of this. Could you point where you get it? > > See > https://github.com/morrownr/8821cu-20210916/blob/main/hal/btc/halbtc8821c1ant.c#L2480 > and > https://github.com/morrownr/8821cu-20210916/blob/main/hal/btc/halbtc8821c2ant.c#L2519 > > But I now see that this masked value is only used at the places I > pointed to, there are other places in the driver that use the unmasked > value. After I read vendor driver, there are three variety of rfe_option for 8821C. 1. raw value from efuse hal->rfe_type = map[EEPROM_RFE_OPTION_8821C]; 2. BT-coexistence rfe_type->rfe_module_type = board_info->rfe_type & 0x1f; 3. PHY dm->rfe_type_expand = hal->rfe_type = raw value dm->rfe_type = dm->rfe_type_expand >> 3; For rtw88, there are only two variety, but they are identical coex_rfe->rfe_module_type = efuse->rfe_option; The flaws are rfe_type->rfe_module_type of item 2 and dm->rfe_type of item 3 above, and most things are addressed by your draft patch. Exception is check_positive() check dm->rfe_type, but we don't have this conversion in rtw88 (i.e. cond.rfe = efuse->rfe_option; in rtw_phy_setup_phy_cond()). Since I don't have a hardware with rfe_option larger than 8, could you please give below patch a try? --- a/phy.c +++ b/phy.c @@ -1048,6 +1048,9 @@ void rtw_phy_setup_phy_cond(struct rtw_dev *rtwdev, u32 pkg) cond.plat = 0x04; cond.rfe = efuse->rfe_option; + if (rtwdev->chip->id == RTW_CHIP_TYPE_8821C) + cond.rfe = efuse->rfe_option >> 3; + switch (rtw_hci_type(rtwdev)) { case RTW_HCI_TYPE_USB: cond.intf = INTF_USB; 8821C is more complex than others, and I'm not familiar with it, so maybe I could miss something. Please correct me if any. > > > > > As I check it internally, 0x22 is expected, so I suggest to have 0x22 entry > > as below > > > > - [34] = RTW_DEF_RFE(8821c, 0, 0), > > + [34] = RTW_DEF_RFE_EXT(8821c, 0, 0, 2), // copy from type 2 > > That alone is not enough. There are other places in rtw8821c.c that > compare with rfe_option. See below for a patch with annotations where to > find the corresponding code in the downstream driver. Note how BIT(5) is > irrelevant for all decisions. I can't tell of course if that's just by > chance or by intent. You're right. I miss these points. > > I don't know where to go from here. It looks like we really only want to > make a decision between SWITCH_TO_WLG and SWITCH_TO_BTG at most places, > so it might be better to store a flag somewhere rather than having the > big switch/case in multiple places. > Agreed. Add something like: --- a/main.h +++ b/main.h @@ -2076,6 +2076,7 @@ struct rtw_hal { u8 mp_chip; u8 oem_id; struct rtw_phy_cond phy_cond; + bool rfe_btg; u8 ps_mode; u8 current_channel; --- a/rtw8821c.c +++ b/rtw8821c.c @@ -47,6 +47,7 @@ enum rtw8821ce_rf_set { static int rtw8821c_read_efuse(struct rtw_dev *rtwdev, u8 *log_map) { + struct rtw_hal *hal = &rtwdev->hal; struct rtw_efuse *efuse = &rtwdev->efuse; struct rtw8821c_efuse *map; int i; @@ -91,6 +92,12 @@ static int rtw8821c_read_efuse(struct rtw_dev *rtwdev, u8 *log_map) return -ENOTSUPP; } + switch (efuse->rfe_option) { + case 0x02: case 0x22: // ... + hal->rfe_btg = true; + break; + } + return 0; } [...] > static const struct rtw_rfe_def rtw8821c_rfe_defs[] = { > - [0] = RTW_DEF_RFE(8821c, 0, 0), > - [2] = RTW_DEF_RFE_EXT(8821c, 0, 0, 2), > - [4] = RTW_DEF_RFE_EXT(8821c, 0, 0, 2), > - [6] = RTW_DEF_RFE(8821c, 0, 0), > - [34] = RTW_DEF_RFE(8821c, 0, 0), > + [0x00] = RTW_DEF_RFE(8821c, 0, 0), > + [0x01] = RTW_DEF_RFE(8821c, 0, 0), > + [0x02] = RTW_DEF_RFE_EXT(8821c, 0, 0, 2), > + [0x03] = RTW_DEF_RFE(8821c, 0, 0), > + [0x04] = RTW_DEF_RFE_EXT(8821c, 0, 0, 2), > + [0x05] = RTW_DEF_RFE(8821c, 0, 0), > + [0x06] = RTW_DEF_RFE(8821c, 0, 0), > + [0x07] = RTW_DEF_RFE_EXT(8821c, 0, 0, 2), > + [0x20] = RTW_DEF_RFE(8821c, 0, 0), > + [0x21] = RTW_DEF_RFE(8821c, 0, 0), > + [0x22] = RTW_DEF_RFE_EXT(8821c, 0, 0, 2), > + [0x23] = RTW_DEF_RFE(8821c, 0, 0), > + [0x24] = RTW_DEF_RFE_EXT(8821c, 0, 0, 2), > + [0x25] = RTW_DEF_RFE(8821c, 0, 0), > + [0x26] = RTW_DEF_RFE(8821c, 0, 0), > + [0x27] = RTW_DEF_RFE_EXT(8821c, 0, 0, 2), > + [0x28] = RTW_DEF_RFE(8821c, 0, 0), > + [0x29] = RTW_DEF_RFE(8821c, 0, 0), > + [0x2a] = RTW_DEF_RFE_EXT(8821c, 0, 0, 2), > + [0x2b] = RTW_DEF_RFE(8821c, 0, 0), > + [0x2c] = RTW_DEF_RFE_EXT(8821c, 0, 0, 2), > + [0x2d] = RTW_DEF_RFE(8821c, 0, 0), > + [0x2e] = RTW_DEF_RFE(8821c, 0, 0), > + [0x2f] = RTW_DEF_RFE_EXT(8821c, 0, 0, 2), I'm not sure if we add all of them, since some aren't tested, but maybe it would be better than nothing. Ping-Ke