Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp579303rdb; Tue, 19 Sep 2023 04:33:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHhIEEDfSF14eL/8G1iNFfAWKWXIO7NwUKlbCX2693OIcUVXF+ffsqBj112EIT6xhE+qL1p X-Received: by 2002:a05:6a00:2da2:b0:690:38b6:b2da with SMTP id fb34-20020a056a002da200b0069038b6b2damr11790066pfb.2.1695123193785; Tue, 19 Sep 2023 04:33:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695123193; cv=none; d=google.com; s=arc-20160816; b=YdEOVHrHj4tlbJeEqCvYUld8gzSY2u5auwOW/R6M6KH82a7K9wlHyH8Vo7N1OR23wT Be+6lzML2V2tJBoqNL8wvnNrENddChOD/fDE9OZSanoxYlzI1c9Lib1uQYLNeH13Lp77 k1k/JkiOzqHgq5Gh/Qj+f0yTNZXtDVgqP48H/xDZGzdlQHir4weYdw1oOyNYgJu+w04/ bf2wQsecQw/YJMjxZc45jbIgnWQEO1OcLAc08hCacyjcS+Ew0EyuK456jI83u/jPCkC9 Do9QLZ8Wd66gMzMRjEcxTruvgXNoGDuukdJ1XS0ws/YJtJDRaD0AT3afJQz8zXRHmhR3 SG9w== 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 :from:references:cc:to:content-language:subject:user-agent :mime-version:date:message-id:dkim-signature; bh=nz9zy64piDIMjKVico5bSyWsHNkVnY1RNGYYRHL51Zw=; fh=5QhN4uqePvr3qfdaXV8VzBd9YlBAuR5fZo2k8xfyV0s=; b=SRJTinQoqbHNS9Zv0TSzrMxFRiMQLth2tamb7W4wbneC71ND+Lo0avTtHfGqzE2Y+w 2mlw9LcMvh9TqKiDUjCXqn5ZMGGNY0kPpOr2MJHUJz6jTXMI76yglTCdufNj9lgExXMw RScSbVwXGCSQap5F6uJ+gdnyj8PBIKp/3imqtcfaAFyI1+IU6mwIU5BeK8Bae1BDYxIm zxuJ4c6Y9tI+BNRwphLTnWfdLKf1/B9Lq//RF66u8Lb8LcWLsC824i1Z2bH5DcNwZ1BE e5/Pt9G6BfE7CYniA0KRsU3gAiEjiM3KunQnUnHlD0ShDCcxyTyqfyAEl0/lkDOUZf+N 0mMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=aNOOktZO; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id y136-20020a62ce8e000000b00690bc21d900si1583171pfg.136.2023.09.19.04.33.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 04:33:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=aNOOktZO; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 5B07680B2327; Tue, 19 Sep 2023 04:24:51 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229534AbjISLYv (ORCPT + 56 others); Tue, 19 Sep 2023 07:24:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbjISLYu (ORCPT ); Tue, 19 Sep 2023 07:24:50 -0400 Received: from nbd.name (nbd.name [46.4.11.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94E15B8 for ; Tue, 19 Sep 2023 04:24:44 -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:From: References:Cc:To: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=nz9zy64piDIMjKVico5bSyWsHNkVnY1RNGYYRHL51Zw=; b=aNOOktZO6O52E/flwiUp8tEJ3G T0tQrqe6oLZvU4zr71v11Q/up3KwcImcNhA2pBcb73A4M+Rlsy6SOsGhmzci/9Ib6wQ/Ojf2xFled xT+DLiTs/SONj8r/ugk3r+6B0UUc1NoQ3ybis6VDRWnGY1WPr0784Ybax6WE3gR0tGg4=; 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 1qiYqP-004Ocv-IP; Tue, 19 Sep 2023 13:24:41 +0200 Message-ID: <8af6de3f-0248-4f86-82fb-bd437f00c61c@nbd.name> Date: Tue, 19 Sep 2023 13:24:41 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] wifi: mt76: mt76x02: correct external LNA gain Content-Language: en-US To: Shiji Yang , linux-wireless@vger.kernel.org Cc: Kalle Valo , Lorenzo Bianconi , Ryder Lee , Shayne Chen , Sean Wang References: From: Felix Fietkau Autocrypt: addr=nbd@nbd.name; keydata= xsDiBEah5CcRBADIY7pu4LIv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TpNNpaV4wAgVTRHKV/kC9luItzwDnUcsZUPdQ f3MueRJ3jIHU0UmRBG3uQftqbZJj3ikhnfvyLmkCNe+/hXhPu9sGvXyi2D4vszICvc1KL4RD aLSrOsROx22eZ26KqcW4ny7+va2FnvjsZgI8h4sDmaLzKczVRIiLITiMpLFEU/VoSv0m1F4B FtRgoiyjFzigWG0MsTdAN6FJzGh4mWWGIlE7o5JraNhnTd+yTUIPtw3ym6l8P+gbvfoZida0 TspgwBWLnXQvP5EDvlZnNaKa/3oBes6z0QdaSOwZCRA3QSLHBwtgUsrT6RxRSweLrcabwkkE GBECAAkFAkah5FQCGwwACgkQ130UHQKnbvW2GgCeMncXpbbWNT2AtoAYICrKyX5R3iMAoMhw cL98efvrjdstUfTCP2pfetyN In-Reply-To: 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 (snail.vger.email [0.0.0.0]); Tue, 19 Sep 2023 04:24:51 -0700 (PDT) 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 --- --- 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,14 @@ 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); + 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);