Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp588334rdb; Tue, 19 Sep 2023 04:52:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFvTh26Xem4GpaC1YERNhS0pZW/vnVYDmY82AzOI63aM6dpNODcIBUBNzlOjHVkPJzPBupj X-Received: by 2002:a05:6358:41a1:b0:142:dc9c:11f7 with SMTP id w33-20020a05635841a100b00142dc9c11f7mr15417337rwc.25.1695124356473; Tue, 19 Sep 2023 04:52:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695124356; cv=none; d=google.com; s=arc-20160816; b=IqFl2fBn8DSFfhennhZK9DqtwVyfe7CnydvhTlnpMPlOwQ5v6LsLACptJe3gMZ1UtI d/x2dwJf9MTVlh8kmOvyzsRGrVawpPwT4n1fApxVYUu7fRDCiOcj1i9f63JIpdp2jyym HB5je4cojWtXMfjzMNpk2Ddo89e0oLX7r3lpu5y2+YWdItgTUoEsHYEAtK81K+AgMrUo B8QD3ow4ePGB0yYXzDlxqoqMsb3s/70D5pa6cNQKawHAEMojFSGF78nivoD+3Jw0PXgF UcMmw0tLR/Zom85i3yv//eYsH5Frof5b2hAvnMHk8zIZUrpcKfPn5vungFi9NtQI5uhw tnDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:autocrypt :references:cc:to:from:content-language:subject:user-agent :mime-version:date:message-id:dkim-signature; bh=cMsL4MK7I6/ZD1+C0QicbTcb5pPFl1P9ecu8LYF0cKU=; fh=5QhN4uqePvr3qfdaXV8VzBd9YlBAuR5fZo2k8xfyV0s=; b=xQKRrVFA/cXfmUdSzxEaTzVPUFGjrdh54ohTRI+Ep2Ly05IkftdCwNzG4B8U6xmDjw e8tKbP0ard7rIs/FxNdbxv8oxK9Oss4lXkgV2Q02miOZujib3NlR6J0OLwq4mwdIO2bR Teo4UUvUcb2x8W7DSkJ0PTF8KC6YMGVvjZwdPppeum8HZS1rhNh2PDRXHDhIKT3T8kI3 Y59D1Mg+195L5DwTmY0OnNE6t6D94UxruDLbq89F1BBBHqOH0g3iu65gPeXD+JV4cG34 WRbk9x3lYc6XDjmjMEBELQyNpQ5F3xokq2qYl1ugQaDr09xQBax0drJny1wN3FgV6gDX Jt3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=avUdFm+0; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nbd.name Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id az1-20020a056a02004100b00565eee2d0fesi9588538pgb.324.2023.09.19.04.52.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 04:52:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=avUdFm+0; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nbd.name Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 262D88074514; Tue, 19 Sep 2023 04:39:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229690AbjISLj6 (ORCPT + 56 others); Tue, 19 Sep 2023 07:39:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229988AbjISLj5 (ORCPT ); Tue, 19 Sep 2023 07:39:57 -0400 Received: from nbd.name (nbd.name [46.4.11.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B346ABA for ; Tue, 19 Sep 2023 04:39:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nbd.name; s=20160729; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:References: Cc:To:From:Subject:MIME-Version:Date:Message-ID:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=cMsL4MK7I6/ZD1+C0QicbTcb5pPFl1P9ecu8LYF0cKU=; b=avUdFm+0GqxWrxJ/9Pb7v93YFQ DVyVUWA1kNJfhcCM5yfpZVUgd+sZvDEoS2HFbFQzQi4xRawfwO5QAR5NiaO+PUozXU1ydmyVqMOkn 7bEkSW2cHPJ5AAPEAxMbJK27tasdJo4yoRhPeDw9NIhIEAglrQsL8CY+x+Y9Yg99Hfgs=; Received: from p54ae986d.dip0.t-ipconnect.de ([84.174.152.109] helo=nf.local) by ds12 with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qiZ52-004Oq0-Rn; Tue, 19 Sep 2023 13:39:48 +0200 Message-ID: <9ca15b75-390f-4647-bc70-3f2f8994db27@nbd.name> Date: Tue, 19 Sep 2023 13:39:48 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] wifi: mt76: mt76x02: correct external LNA gain Content-Language: en-US From: Felix Fietkau To: Shiji Yang , linux-wireless@vger.kernel.org Cc: Kalle Valo , Lorenzo Bianconi , Ryder Lee , Shayne Chen , Sean Wang References: <8af6de3f-0248-4f86-82fb-bd437f00c61c@nbd.name> Autocrypt: addr=n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jYoqk wu++3117AAMFB/9S0Sj7qFFQcD4laADVsabTpNNpaV4wAgVTRHKV/kC9luItzwDnUcsZUPdQ f3MueRJ3jIHU0UmRBG3uQftqbZJj3ikhnfvyLmkCNe+/hXhPu9sGvXyi2D4vszICvc1KL4RD aLSrOsROx22eZ26KqcW4ny7+va2FnvjsZgI8h4sDmaLzKczVRIiLITiMpLFEU/VoSv0m1F4B FtRgoiyjFzigWG0MsTdAN6FJzGh4mWWGIlE7o5JraNhnTd+yTUIPtw3ym6l8P+gbvfoZida0 TspgwBWLnXQvP5EDvlZnNaKa/3oBes6z0QdaSOwZCRA3QSLHBwtgUsrT6RxRSweLrcabwkkE GBECAAkFAkah5FQCGwwACgkQ130UHQKnbvW2GgCeMncXpbbWNT2AtoAYICrKyX5R3iMAoMhw cL98efvrjdstUfTCP2pfetyN In-Reply-To: <8af6de3f-0248-4f86-82fb-bd437f00c61c@nbd.name> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 19 Sep 2023 04:39:56 -0700 (PDT) On 19.09.23 13:24, Felix Fietkau wrote: > On 19.09.23 06:48, Shiji Yang wrote: >> Referring to the MT761{0,2} EEPROM content, setting the corresponding >> EEPROM control bit means enabling external LNA. In this case, we >> should use the EEMROM LNA gain instead of 0. >> >> Signed-off-by: Shiji Yang >> --- >> drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.c >> index 0acabba2d..a0b95509a 100644 >> --- a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.c >> +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.c >> @@ -135,9 +135,9 @@ u8 mt76x02_get_lna_gain(struct mt76x02_dev *dev, >> u8 lna; >> >> val = mt76x02_eeprom_get(dev, MT_EE_NIC_CONF_1); >> - if (val & MT_EE_NIC_CONF_1_LNA_EXT_2G) >> + if (!(val & MT_EE_NIC_CONF_1_LNA_EXT_2G)) >> *lna_2g = 0; >> - if (val & MT_EE_NIC_CONF_1_LNA_EXT_5G) >> + if (!(val & MT_EE_NIC_CONF_1_LNA_EXT_5G)) >> memset(lna_5g, 0, sizeof(s8) * 3); >> >> if (chan->band == NL80211_BAND_2GHZ) > > I took a closer look at the interpretation of these flags and how they > are handled in the vendor driver. From what I can tell, on MT76x2 LNA > gain should only be used as part of the RSSI calculation for internal > LNA devices. In the MT76x0 code, I see no such checks, so the LNA gain > should be used unconditionally. > What do you think about this patch? > > Thanks, > > - Felix Sorry, there was a missing line in the last patch. Here is the right version: --- a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.c @@ -131,15 +131,8 @@ u8 mt76x02_get_lna_gain(struct mt76x02_dev *dev, s8 *lna_2g, s8 *lna_5g, struct ieee80211_channel *chan) { - u16 val; u8 lna; - val = mt76x02_eeprom_get(dev, MT_EE_NIC_CONF_1); - if (val & MT_EE_NIC_CONF_1_LNA_EXT_2G) - *lna_2g = 0; - if (val & MT_EE_NIC_CONF_1_LNA_EXT_5G) - memset(lna_5g, 0, sizeof(s8) * 3); - if (chan->band == NL80211_BAND_2GHZ) lna = *lna_2g; else if (chan->hw_value <= 64) --- a/drivers/net/wireless/mediatek/mt76/mt76x2/eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2/eeprom.c @@ -256,7 +256,8 @@ void mt76x2_read_rx_gain(struct mt76x02_dev *dev) struct ieee80211_channel *chan = dev->mphy.chandef.chan; int channel = chan->hw_value; s8 lna_5g[3], lna_2g; - u8 lna; + bool use_lna; + u8 lna = 0; u16 val; if (chan->band == NL80211_BAND_2GHZ) @@ -275,7 +276,15 @@ void mt76x2_read_rx_gain(struct mt76x02_dev *dev) dev->cal.rx.mcu_gain |= (lna_5g[1] & 0xff) << 16; dev->cal.rx.mcu_gain |= (lna_5g[2] & 0xff) << 24; - lna = mt76x02_get_lna_gain(dev, &lna_2g, lna_5g, chan); + val = mt76x02_eeprom_get(dev, MT_EE_NIC_CONF_1); + if (chan->band == NL80211_BAND_2GHZ) + use_lna = !(val & MT_EE_NIC_CONF_1_LNA_EXT_2G); + else + use_lna = !(val & MT_EE_NIC_CONF_1_LNA_EXT_5G); + + if (use_lna) + lna = mt76x02_get_lna_gain(dev, &lna_2g, lna_5g, chan); + dev->cal.rx.lna_gain = mt76x02_sign_extend(lna, 8); } EXPORT_SYMBOL_GPL(mt76x2_read_rx_gain);