From patchwork Wed Nov 23 21:30:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bitterblue Smith X-Patchwork-Id: 13054363 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2286C433FE for ; Wed, 23 Nov 2022 21:30:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237891AbiKWVan (ORCPT ); Wed, 23 Nov 2022 16:30:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235215AbiKWVam (ORCPT ); Wed, 23 Nov 2022 16:30:42 -0500 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 543A9942DE for ; Wed, 23 Nov 2022 13:30:40 -0800 (PST) Received: by mail-ej1-x62f.google.com with SMTP id n20so222683ejh.0 for ; Wed, 23 Nov 2022 13:30:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:subject:from:cc:to:content-language :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=AM8MTmsKK4jhGM5CZp4XeMVfIEpojaLXrg9jUBCEeCc=; b=Tq0y1tIHjlGLk1S1Hf/oWvXsns8FZ0OoTJrC9uoaEejXlD6R2ESNpNsNOsIYV8lbbw dV4zAmL1WJUQQjyQC6fGIlUULEEUueTjIGYvW4K++OarIC0WutWHvHyVcclrM4xq69/i J5XxVuu39hmSaCwLAhO3BrgfeuHtBn2NnWUGPNxeIp7kh0wqx6UpXTq1qBt37bx9ZsqG qJL4IPl5l/QF2HCFK988ciUk9rZ3Cf7+iwyX7zjvkCtGgn5dZAfE1CQ1bDnTuMo0MYSY XtbVp6xMRLbU47lo2AhmSws95HDka9kaMS8DX3cFMjqYCAOC0CQxpXeVCWhmCL11a/da I1xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:subject:from:cc:to:content-language :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=AM8MTmsKK4jhGM5CZp4XeMVfIEpojaLXrg9jUBCEeCc=; b=N3OsuUWoyfsIZsX7TksnCxEKu1U1dAe1HZ71cF+SPw7KIQNgse9MToPuKo0ddreEgH qEl5S54J4IWT6GDWPmftUNv8z4jqIODADs8i3DIxMhcQz7m2GFSJ6eP/rva003RtgLGt vbVzLONaSzzxFtbJ6w036Ws5gLYlZT4u2NwYLXbW7G6ZjVJ2LfuTxdrEGFVxVIXYb5Dl 4PiLUMasS3+t1GSOOCPu8cGkrU5BsOUzB9RWEPYNM+Wy427vdBImd1/v+pyV275q2i6F wwDH5LfB1vPMZgEhi725XeJhoIt5Yyi2HuRVfaNFQyG/BZnAkO2s3WstTah0sUgSKUfK gYww== X-Gm-Message-State: ANoB5plGu7BkoYZyJx4Fol655h5wsljIA4N+MEQ+EuzJpxcedk3TWgcW +RxTFxf2J5mAA7cv9PiDHiZv7o/k9m0= X-Google-Smtp-Source: AA0mqf5JP/PDwlil+gddiam/EeOK9Uj678SjoodOJyhn9YDnvvCN/KYuJaqnsiIa1gEXCT8HjqmvjQ== X-Received: by 2002:a17:906:1b48:b0:78d:a136:732b with SMTP id p8-20020a1709061b4800b0078da136732bmr10171741ejg.135.1669239038784; Wed, 23 Nov 2022 13:30:38 -0800 (PST) Received: from [192.168.1.50] ([79.119.240.254]) by smtp.gmail.com with ESMTPSA id k21-20020a17090632d500b007ae32daf4b9sm7584162ejk.106.2022.11.23.13.30.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 23 Nov 2022 13:30:38 -0800 (PST) Message-ID: <00489244-ba7c-797a-28f0-8788a40f7974@gmail.com> Date: Wed, 23 Nov 2022 23:30:36 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.3 Content-Language: en-US To: "linux-wireless@vger.kernel.org" Cc: Jes Sorensen , Ping-Ke Shih From: Bitterblue Smith Subject: [PATCH 1/2] wifi: rtl8xxxu: Fix the channel width reporting Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org The gen 2 chips RTL8192EU and RTL8188FU periodically send the driver reports about the TX rate, and the driver passes these reports to sta_statistics. The reports from RTL8192EU may or may not include the channel width. The reports from RTL8188FU do not include it. Only access the c2h->ra_report.bw field if the report (skb) is big enough. The other problem fixed here is that the code was actually never changing the channel width initially reported by rtl8xxxu_bss_info_changed because the value of RATE_INFO_BW_20 is 0. Fixes: 0985d3a410ac ("rtl8xxxu: Feed current txrate information for mac80211") Signed-off-by: Bitterblue Smith --- drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c index 28f136064297..1c29d0bf09e2 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c @@ -5569,7 +5569,6 @@ static void rtl8xxxu_c2hcmd_callback(struct work_struct *work) rarpt->txrate.flags = 0; rate = c2h->ra_report.rate; sgi = c2h->ra_report.sgi; - bw = c2h->ra_report.bw; if (rate < DESC_RATE_MCS0) { rarpt->txrate.legacy = @@ -5586,8 +5585,13 @@ static void rtl8xxxu_c2hcmd_callback(struct work_struct *work) RATE_INFO_FLAGS_SHORT_GI; } - if (bw == RATE_INFO_BW_20) - rarpt->txrate.bw |= RATE_INFO_BW_20; + if (skb->len >= 2 + 7) { + if (c2h->ra_report.bw == RTL8XXXU_CHANNEL_WIDTH_40) + bw = RATE_INFO_BW_40; + else + bw = RATE_INFO_BW_20; + rarpt->txrate.bw = bw; + } } bit_rate = cfg80211_calculate_bitrate(&rarpt->txrate); rarpt->bit_rate = bit_rate; From patchwork Wed Nov 23 21:33:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bitterblue Smith X-Patchwork-Id: 13054364 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E252C4332F for ; Wed, 23 Nov 2022 21:34:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238403AbiKWVd7 (ORCPT ); Wed, 23 Nov 2022 16:33:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230195AbiKWVd5 (ORCPT ); Wed, 23 Nov 2022 16:33:57 -0500 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75AC7A4163 for ; Wed, 23 Nov 2022 13:33:56 -0800 (PST) Received: by mail-ed1-x531.google.com with SMTP id b8so54751edf.11 for ; Wed, 23 Nov 2022 13:33:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=H9bTz8VHgeo8q8URZijCaaS1KYFG/IcZr1qltyg9JV4=; b=UVZMCKDsLbGKZ/LBcCYT9Sn3yF7BQzx7Uwph+xf/xr8v6nFC7PEvO3n/D5gpVb4FST 5EG7kIhYVuVhkaGVsUtF+XC50IvvZQHhB7BkSRzGbXvwYFc4arly2kfgwzgGg9sorPCk 2h9jaG1NsmVscv0+ZnHN1A5D/NQgYhuME+tbZoisZWcB8GmVtTVepQS6lLpNsz3FhXyU 2otno6csO5uxX8/jYmUPEOL4lAE1a31sPfPlhjoAKWlmdOkS+YPw8Rhd+5R0R/GKm0NY KCB3aO30qDrpGLTvcyIMiid2neJ8GXgY0/qX88ppCpIXz3x7jM8EtstoEzVZEhSroWDu ftTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=H9bTz8VHgeo8q8URZijCaaS1KYFG/IcZr1qltyg9JV4=; b=nv3vskoD2wTAFtlqqrXPi55mYA6C9quWl24zM/2HI3ZOBm08I6G92zvSYZDvudhK+x +Fx1gJ9F+zKeAmU9DwZnsJxGYAiLgWuhatghYrh1vJDee3JZ4nzSgRIdO3CJzkZUeBeA CJ9M/1MYNLwFykHDOfl/nJmSu3P6dCMS7a+WFm6VlGmggyu4cWNQAhSZssQYMQh9eCz1 nmhwOGsEFc2xFeytTyj3cpI27v+uYem1WcrsRuy7PmDjXjDRSaJReOPuZxt9ZNmafjvh jBfRBhVgIc6L6+0eL3aBYKyLscvBuYoCVOohAX8PCqQNw0NvkUqVcA9UGAQqiL8V5ZYp NO4w== X-Gm-Message-State: ANoB5pnZVYR0bcrr8D6sYthJapDIOIhAwQebV8g2mRoisFZLUUMr37QQ uoKpmYiuMXwjvFCbpaMhnrE35dI55BU= X-Google-Smtp-Source: AA0mqf6PTJRAbdeuKwLGlFYMC48YrcpPul7ybuZh/JzF8lCCWh2F/Hm6CQ5YBs0rJYMJ5Z3MqJKUTg== X-Received: by 2002:aa7:c941:0:b0:469:172:4f46 with SMTP id h1-20020aa7c941000000b0046901724f46mr24670803edt.130.1669239234914; Wed, 23 Nov 2022 13:33:54 -0800 (PST) Received: from [192.168.1.50] ([79.119.240.254]) by smtp.gmail.com with ESMTPSA id x2-20020a170906296200b00782539a02absm7600420ejd.194.2022.11.23.13.33.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 23 Nov 2022 13:33:54 -0800 (PST) Message-ID: Date: Wed, 23 Nov 2022 23:33:53 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.3 Subject: [PATCH 2/2] wifi: rtl8xxxu: Introduce rtl8xxxu_update_ra_report Content-Language: en-US From: Bitterblue Smith To: "linux-wireless@vger.kernel.org" Cc: Jes Sorensen , Ping-Ke Shih References: <00489244-ba7c-797a-28f0-8788a40f7974@gmail.com> In-Reply-To: <00489244-ba7c-797a-28f0-8788a40f7974@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org The ra_report struct is used for reporting the TX rate via sta_statistics. The code which fills it out is duplicated in two places, and the RTL8188EU will need it in a third place. Move this code into a new function rtl8xxxu_update_ra_report. Signed-off-by: Bitterblue Smith --- This patch should be applied after my other patch: "[PATCH v2] wifi: rtl8xxxu: Fix use after rcu_read_unlock in rtl8xxxu_bss_info_changed" --- .../wireless/realtek/rtl8xxxu/rtl8xxxu_core.c | 105 ++++++++---------- 1 file changed, 45 insertions(+), 60 deletions(-) diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c index 1c29d0bf09e2..2c8798cb3b4b 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c @@ -4598,6 +4598,32 @@ static void rtl8xxxu_set_aifs(struct rtl8xxxu_priv *priv, u8 slot_time) } } +static void rtl8xxxu_update_ra_report(struct rtl8xxxu_ra_report *rarpt, + u8 rate, u8 sgi, u8 bw) +{ + u8 mcs, nss; + + rarpt->txrate.flags = 0; + + if (rate < DESC_RATE_MCS0) { + rarpt->txrate.legacy = rtl8xxxu_legacy_ratetable[rate].bitrate; + } else { + rtl8xxxu_desc_to_mcsrate(rate, &mcs, &nss); + rarpt->txrate.flags |= RATE_INFO_FLAGS_MCS; + + rarpt->txrate.mcs = mcs; + rarpt->txrate.nss = nss; + + if (sgi) + rarpt->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI; + + rarpt->txrate.bw = bw; + } + + rarpt->bit_rate = cfg80211_calculate_bitrate(&rarpt->txrate); + rarpt->desc_rate = rate; +} + static void rtl8xxxu_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_bss_conf *bss_conf, u64 changed) @@ -4620,9 +4646,7 @@ rtl8xxxu_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u32 ramask; int sgi = 0; u8 highest_rate; - u8 mcs = 0, nss = 0; - u32 bit_rate; - + u8 bw; rcu_read_lock(); sta = ieee80211_find_sta(vif, bss_conf->bssid); @@ -4647,37 +4671,19 @@ rtl8xxxu_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif, sgi = 1; highest_rate = fls(ramask) - 1; - if (highest_rate < DESC_RATE_MCS0) { - rarpt->txrate.legacy = - rtl8xxxu_legacy_ratetable[highest_rate].bitrate; - } else { - rtl8xxxu_desc_to_mcsrate(highest_rate, - &mcs, &nss); - rarpt->txrate.flags |= RATE_INFO_FLAGS_MCS; - - rarpt->txrate.mcs = mcs; - rarpt->txrate.nss = nss; - - if (sgi) { - rarpt->txrate.flags |= - RATE_INFO_FLAGS_SHORT_GI; - } - - if (rtl8xxxu_ht40_2g && - (sta->deflink.ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) - rarpt->txrate.bw = RATE_INFO_BW_40; - else - rarpt->txrate.bw = RATE_INFO_BW_20; - } + if (rtl8xxxu_ht40_2g && + (sta->deflink.ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) + bw = RATE_INFO_BW_40; + else + bw = RATE_INFO_BW_20; rcu_read_unlock(); - bit_rate = cfg80211_calculate_bitrate(&rarpt->txrate); - rarpt->bit_rate = bit_rate; - rarpt->desc_rate = highest_rate; + + rtl8xxxu_update_ra_report(rarpt, highest_rate, sgi, bw); priv->vif = vif; priv->rssi_level = RTL8XXXU_RATR_STA_INIT; - priv->fops->update_rate_mask(priv, ramask, 0, sgi, rarpt->txrate.bw == RATE_INFO_BW_40); + priv->fops->update_rate_mask(priv, ramask, 0, sgi, bw == RATE_INFO_BW_40); rtl8xxxu_write8(priv, REG_BCN_MAX_ERR, 0xff); @@ -5538,9 +5544,7 @@ static void rtl8xxxu_c2hcmd_callback(struct work_struct *work) u8 bt_info = 0; struct rtl8xxxu_btcoex *btcoex; struct rtl8xxxu_ra_report *rarpt; - u8 rate, sgi, bw; - u32 bit_rate; - u8 mcs = 0, nss = 0; + u8 bw; priv = container_of(work, struct rtl8xxxu_priv, c2hcmd_work); btcoex = &priv->bt_coex; @@ -5566,36 +5570,17 @@ static void rtl8xxxu_c2hcmd_callback(struct work_struct *work) rtl8723bu_handle_bt_info(priv); break; case C2H_8723B_RA_REPORT: - rarpt->txrate.flags = 0; - rate = c2h->ra_report.rate; - sgi = c2h->ra_report.sgi; - - if (rate < DESC_RATE_MCS0) { - rarpt->txrate.legacy = - rtl8xxxu_legacy_ratetable[rate].bitrate; - } else { - rtl8xxxu_desc_to_mcsrate(rate, &mcs, &nss); - rarpt->txrate.flags |= RATE_INFO_FLAGS_MCS; + bw = rarpt->txrate.bw; - rarpt->txrate.mcs = mcs; - rarpt->txrate.nss = nss; - - if (sgi) { - rarpt->txrate.flags |= - RATE_INFO_FLAGS_SHORT_GI; - } - - if (skb->len >= 2 + 7) { - if (c2h->ra_report.bw == RTL8XXXU_CHANNEL_WIDTH_40) - bw = RATE_INFO_BW_40; - else - bw = RATE_INFO_BW_20; - rarpt->txrate.bw = bw; - } + if (skb->len >= 2 + 7) { + if (c2h->ra_report.bw == RTL8XXXU_CHANNEL_WIDTH_40) + bw = RATE_INFO_BW_40; + else + bw = RATE_INFO_BW_20; } - bit_rate = cfg80211_calculate_bitrate(&rarpt->txrate); - rarpt->bit_rate = bit_rate; - rarpt->desc_rate = rate; + + rtl8xxxu_update_ra_report(rarpt, c2h->ra_report.rate, + c2h->ra_report.sgi, bw); break; default: break;