Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp4745671rwe; Mon, 17 Apr 2023 18:29:36 -0700 (PDT) X-Google-Smtp-Source: AKy350Z9KxQhoL3kOtuB6pdNi4hI9toojH/O5g5cNtzZ/ImHx5ABIjBYT8nID5oY1pAmcYAufqNh X-Received: by 2002:a17:903:2591:b0:1a2:8c7e:f315 with SMTP id jb17-20020a170903259100b001a28c7ef315mr457822plb.21.1681781376184; Mon, 17 Apr 2023 18:29:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681781376; cv=none; d=google.com; s=arc-20160816; b=ETzyWJFfOSpIp2Rba+KcyCl4dNqIuqXCokqJEe0/lwIqOz+l8NxR0pZP7dd0XurNAS Kt6FG6IrXQmIBCR9IliYxiAbA4877SsFp3zig1An8peeWkZC1Cs0xTMZ1ExqAdssanu/ jqatcwFnTTjE3T4yZK+Tn4eV25d248lD3vaerpe6+jWMlttx/4gfasRzv3ldK38QJ30c XC4Wo1UNh0OZZPeE8boAqTgVVShxArM3tIgiBcyiHvyknq4HHdrBQ8x+2H7MiLpYyccT z5ue3ivbV8MVL5i7qlJlbNGH2qYkS9Hlqb6egSbFfJCaMeEgzoYkmDlvvKXgLNCzNKJX zjRg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :authenticated-by; bh=qcC2ZgCCi0zTFqI2R1rs70IGstx5Q4CNtghhzul4p/A=; b=GCD0ErRYlKiXp/w9T3Bw4px5YVcytuiG9XLiP7m//SXt6k+MCiXG41GKfnnJwNA/S7 TnM7Sy8C7fZDu8rU7hC6/DFkTo2xuBUWrj7EGwMx07to2HZYFVhUkXHPGoSmDGmgas0T G0lOqm+JObRZ0nb4amoL1mutyVgUIzMT4idJmNLFIbdTlDEpQqARXSkKsn+Z8q9f/S66 dbRam8BB6x7Lxt7iGMJJ97iKQWHnRP8292IlXZOdkqdEft6vo4GmEJWNfrMUeN6WwNJ5 1CQbcvK1GLsAR6oehcL4LCLtjFTKLcZILJqF2nu22JBX3cr/tHgT9dd5ZpPZVDy50zy4 LZVg== 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 c2-20020a170903234200b001a68d4a42bfsi13068368plh.90.2023.04.17.18.29.28; Mon, 17 Apr 2023 18:29:36 -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 S229741AbjDRB3G (ORCPT + 63 others); Mon, 17 Apr 2023 21:29:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230189AbjDRB3C (ORCPT ); Mon, 17 Apr 2023 21:29:02 -0400 Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E2865B9B for ; Mon, 17 Apr 2023 18:28:49 -0700 (PDT) Authenticated-By: X-SpamFilter-By: ArmorX SpamTrap 5.77 with qID 33I1SiwiE015091, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (rtexh36506.realtek.com.tw[172.21.6.27]) by rtits2.realtek.com.tw (8.15.2/2.81/5.90) with ESMTPS id 33I1SiwiE015091 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=OK); Tue, 18 Apr 2023 09:28:44 +0800 Received: from RTEXMBS04.realtek.com.tw (172.21.6.97) by RTEXH36506.realtek.com.tw (172.21.6.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.17; Tue, 18 Apr 2023 09:28:44 +0800 Received: from localhost (172.21.69.188) by RTEXMBS04.realtek.com.tw (172.21.6.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Tue, 18 Apr 2023 09:28:44 +0800 From: Ping-Ke Shih To: CC: , Subject: [PATCH v2 7/7] wifi: rtw89: add EVM for antenna diversity Date: Tue, 18 Apr 2023 09:28:20 +0800 Message-ID: <20230418012820.5139-8-pkshih@realtek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230418012820.5139-1-pkshih@realtek.com> References: <20230418012820.5139-1-pkshih@realtek.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [172.21.69.188] X-ClientProxiedBy: RTEXMBS02.realtek.com.tw (172.21.6.95) To RTEXMBS04.realtek.com.tw (172.21.6.97) X-KSE-ServerInfo: RTEXMBS04.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,T_SCC_BODY_TEXT_LINE 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 From: Eric Huang Take EVM into consideration when doing antenna diversity, and the priority is higher than RSSI. Since EVM is more relevant to performance than RSSI, especially in OTA environment. Signed-off-by: Eric Huang Signed-off-by: Ping-Ke Shih --- drivers/net/wireless/realtek/rtw89/core.h | 1 + drivers/net/wireless/realtek/rtw89/phy.c | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h index ca9d6e9258ffa..40406ecce5bd3 100644 --- a/drivers/net/wireless/realtek/rtw89/core.h +++ b/drivers/net/wireless/realtek/rtw89/core.h @@ -3134,6 +3134,7 @@ struct rtw89_antdiv_stats { u16 pkt_cnt_cck; u16 pkt_cnt_ofdm; u16 pkt_cnt_non_legacy; + u32 evm; }; struct rtw89_antdiv_info { diff --git a/drivers/net/wireless/realtek/rtw89/phy.c b/drivers/net/wireless/realtek/rtw89/phy.c index b9a3ebc2e7901..5eac00cd51881 100644 --- a/drivers/net/wireless/realtek/rtw89/phy.c +++ b/drivers/net/wireless/realtek/rtw89/phy.c @@ -2956,6 +2956,7 @@ void rtw89_phy_antdiv_sts_instance_reset(struct rtw89_antdiv_stats *antdiv_sts) antdiv_sts->pkt_cnt_cck = 0; antdiv_sts->pkt_cnt_ofdm = 0; antdiv_sts->pkt_cnt_non_legacy = 0; + antdiv_sts->evm = 0; } static void rtw89_phy_antdiv_sts_instance_add(struct rtw89_dev *rtwdev, @@ -2969,10 +2970,12 @@ static void rtw89_phy_antdiv_sts_instance_add(struct rtw89_dev *rtwdev, } else { ewma_rssi_add(&stats->ofdm_rssi_avg, phy_ppdu->rssi_avg); stats->pkt_cnt_ofdm++; + stats->evm += phy_ppdu->ofdm.evm_min; } } else { ewma_rssi_add(&stats->non_legacy_rssi_avg, phy_ppdu->rssi_avg); stats->pkt_cnt_non_legacy++; + stats->evm += phy_ppdu->ofdm.evm_min; } } @@ -2988,6 +2991,11 @@ static u8 rtw89_phy_antdiv_sts_instance_get_rssi(struct rtw89_antdiv_stats *stat return ewma_rssi_read(&stats->cck_rssi_avg); } +static u8 rtw89_phy_antdiv_sts_instance_get_evm(struct rtw89_antdiv_stats *stats) +{ + return phy_div(stats->evm, stats->pkt_cnt_non_legacy + stats->pkt_cnt_ofdm); +} + void rtw89_phy_antdiv_parse(struct rtw89_dev *rtwdev, struct rtw89_rx_phy_ppdu *phy_ppdu) { @@ -4270,15 +4278,22 @@ static void rtw89_phy_antdiv_decision_state(struct rtw89_dev *rtwdev) struct rtw89_hal *hal = &rtwdev->hal; bool no_change = false; u8 main_rssi, aux_rssi; + u8 main_evm, aux_evm; u32 candidate; antdiv->get_stats = false; antdiv->training_count = 0; main_rssi = rtw89_phy_antdiv_sts_instance_get_rssi(&antdiv->main_stats); + main_evm = rtw89_phy_antdiv_sts_instance_get_evm(&antdiv->main_stats); aux_rssi = rtw89_phy_antdiv_sts_instance_get_rssi(&antdiv->aux_stats); + aux_evm = rtw89_phy_antdiv_sts_instance_get_evm(&antdiv->aux_stats); - if (main_rssi > aux_rssi + RTW89_TX_DIV_RSSI_RAW_TH) + if (main_evm > aux_evm + ANTDIV_EVM_DIFF_TH) + candidate = RF_A; + else if (aux_evm > main_evm + ANTDIV_EVM_DIFF_TH) + candidate = RF_B; + else if (main_rssi > aux_rssi + RTW89_TX_DIV_RSSI_RAW_TH) candidate = RF_A; else if (aux_rssi > main_rssi + RTW89_TX_DIV_RSSI_RAW_TH) candidate = RF_B; -- 2.25.1