From patchwork Wed Mar 18 08:26:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Chiu X-Patchwork-Id: 11444709 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 24A261820 for ; Wed, 18 Mar 2020 08:27:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F3A442076F for ; Wed, 18 Mar 2020 08:27:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=endlessm-com.20150623.gappssmtp.com header.i=@endlessm-com.20150623.gappssmtp.com header.b="etWxABcQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727480AbgCRI1Z (ORCPT ); Wed, 18 Mar 2020 04:27:25 -0400 Received: from mail-pj1-f66.google.com ([209.85.216.66]:33188 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727361AbgCRI1N (ORCPT ); Wed, 18 Mar 2020 04:27:13 -0400 Received: by mail-pj1-f66.google.com with SMTP id dw20so908551pjb.0 for ; Wed, 18 Mar 2020 01:27:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=endlessm-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Gz7OMO0V/9gwDQsyrVVJj38Jk+MVAm8kgbfcul1v0lY=; b=etWxABcQQBRhpZIfQEpTNqzTqtzyDg8w+T9b824roKZQN/UqL6N/gCA17IOuTeE6J2 qtmH6Zm7O7h3N9L9ZqZzSVwD+zpw1LHci1QRQAxiRzVjGlSvNKpu+ArsFW3O+KXblh04 rzvvw4ca64rAPy7nBlQ0MOpURPhTaGar/uYS+DxoTtXyD/zDuEl3vEFkvVlHUE/UQ4/4 W5jV64HSQ886VQJbZsd5GZ5mx2YI2P/4TjrGbK3fjBy5e4dchbOY3sVdKq1nITnzIRVP DPliOYOf1V6PfhUP2ujH86VpMOcoYwDJmXFfD8YYfzAVPEFYG6f5wAvMihIVTFR6cgM4 YWkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Gz7OMO0V/9gwDQsyrVVJj38Jk+MVAm8kgbfcul1v0lY=; b=lBnGP1XFTXKbuJq+1ecauhcVjbZNqw+2fAkkJIP0wvB7Rd693NEhtDkDBv+GxBVYGZ mnpM5Cr5pB/LClLOAklHIZGmwFdIeVehkIjOtF1HaZH8EDJ0csrFS/6naYZIfRBFRjr/ WYdVFzrr4T0d/zD1j9NEPTXATVYjkptlwr2Arw/xM5lFgcl0FKtUSMMfHJvPfmSDowKU mSKu9UUFWkks/WST/lYuUbYdSaTzpDVG6BrFtXyTMODgH0xOorosj9egOkUDYNediLUy 6ZtLlEjRByc1XzQmv5FxDH1AzkzCj43d+iIq5sJIdZ6W8XUhrEmvcpGvV0gmZveCBSkr B34g== X-Gm-Message-State: ANhLgQ0FSfqQBy0V9bL86Z+sqgqRuFN2Rt2hOqVPuD+zU/OaG7HNOBOq Fpfbl3ZCn52Xeul6JTPSx9suSw== X-Google-Smtp-Source: ADFU+vtln86LHcgYuQ6icKMWjY8Hj+LSNv+iEJI7dLh4orE2kJf17XDSIkHPUhy1QcKRtyCZcwwo1A== X-Received: by 2002:a17:90a:26ed:: with SMTP id m100mr3494583pje.130.1584520031740; Wed, 18 Mar 2020 01:27:11 -0700 (PDT) Received: from localhost.localdomain (59-127-47-126.HINET-IP.hinet.net. [59.127.47.126]) by smtp.gmail.com with ESMTPSA id 18sm5492148pfj.140.2020.03.18.01.27.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Mar 2020 01:27:11 -0700 (PDT) From: Chris Chiu To: Jes.Sorensen@gmail.com, kvalo@codeaurora.org, davem@davemloft.net Cc: linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux@endlessm.com Subject: [PATCH 1/2] rtl8xxxu: add enumeration for channel bandwidth Date: Wed, 18 Mar 2020 16:26:59 +0800 Message-Id: <20200318082700.71875-2-chiu@endlessm.com> X-Mailer: git-send-email 2.21.1 (Apple Git-122.3) In-Reply-To: <20200318082700.71875-1-chiu@endlessm.com> References: <20200318082700.71875-1-chiu@endlessm.com> MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org There's a data field in H2C and C2H commands which is used to carry channel bandwidth information. Add enumeration to make it more descriptive in code. Signed-off-by: Chris Chiu --- drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h | 9 +++++++++ drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h index 6598c8d786ea..86d1d50511a8 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h @@ -1133,6 +1133,15 @@ enum bt_mp_oper_opcode_8723b { BT_MP_OP_ENABLE_CFO_TRACKING = 0x24, }; +enum rtl8xxxu_bw_mode { + RTL8XXXU_CHANNEL_WIDTH_20 = 0, + RTL8XXXU_CHANNEL_WIDTH_40 = 1, + RTL8XXXU_CHANNEL_WIDTH_80 = 2, + RTL8XXXU_CHANNEL_WIDTH_160 = 3, + RTL8XXXU_CHANNEL_WIDTH_80_80 = 4, + RTL8XXXU_CHANNEL_WIDTH_MAX = 5, +}; + struct rtl8723bu_c2h { u8 id; u8 seq; diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c index 54a1a4ea107b..511a3b4ed72a 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c @@ -4328,7 +4328,7 @@ void rtl8xxxu_gen2_update_rate_mask(struct rtl8xxxu_priv *priv, u32 ramask, u8 rateid, int sgi) { struct h2c_cmd h2c; - u8 bw = 0; + u8 bw = RTL8XXXU_CHANNEL_WIDTH_20; memset(&h2c, 0, sizeof(struct h2c_cmd)); From patchwork Wed Mar 18 08:27:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Chiu X-Patchwork-Id: 11444707 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8B86E17E6 for ; Wed, 18 Mar 2020 08:27:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 619372076F for ; Wed, 18 Mar 2020 08:27:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=endlessm-com.20150623.gappssmtp.com header.i=@endlessm-com.20150623.gappssmtp.com header.b="wHavSO3d" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727439AbgCRI1X (ORCPT ); Wed, 18 Mar 2020 04:27:23 -0400 Received: from mail-pj1-f68.google.com ([209.85.216.68]:53163 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727351AbgCRI1Q (ORCPT ); Wed, 18 Mar 2020 04:27:16 -0400 Received: by mail-pj1-f68.google.com with SMTP id ng8so1015072pjb.2 for ; Wed, 18 Mar 2020 01:27:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=endlessm-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=q67Jyo84FepUkmWaE2l8NSTdFx5oALdllapMnZWigOw=; b=wHavSO3dYWfl8aL69jLUhaa20mvMeN5gq65qxD00+zKON5m2BDMlFYBJIKejkHQT5d j87RoCEVWiPjqj4LMYZo2t0KyrYu0ME88f3cfVO0aJuaRtkz1gTosPNTzcsi3TSf5Gfb NEUxLdLi/BUiOv8AWH0ISIMvf+JfgjYJ1L5jqM47FbX302UU0xMdaCvzMR47pHxPzKvM esUYSGbNR1cot3O/3gxiTWJdidYafGQkr5fyxK2UPGv60YswB4m9JduicFRB3CifQHvN WZjDLT5oO0Wqjrzy6pP6Tv/PkZ4xaX364PxxnLugVt9nEUFwGvk4me/n/cr2byJLcdHB 825Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=q67Jyo84FepUkmWaE2l8NSTdFx5oALdllapMnZWigOw=; b=kYPE1GFebPxVOSP1pKOIExkseoO2zKdEW1hPDBgksbFyEx0rsXqgYTG0fFty9PwqRv I5xPUk4CAgoeA/TPuE9IjUZDSwouIx8w9asszfiLCNt5CAeoC6eQu8swpKw3V2P/QTmo rSUzhr2jVxvo3SRF6xKfw4K8lZiDhNL49nA7P2nmJBB1+Vi9WbL1JlYfXU14LOAv1/ka kY9w/JA043RK/uwrreMwC5KnsDo87a50k20yeKFNbSLEPoDZcq5JgdkthHTC7+QW+zWj 2sCswCl+AgIE7mw59WQXXMERDm5IyllDZSED9ZNT4kIVknYMq1eq7MUSiyh3OxM2ZQmB PP+A== X-Gm-Message-State: ANhLgQ1wuY51Ri6ASmZ58w9Nl5DQ8WgfXG0RbDn9vecrpo5hU4Bh3smK pguqyI6aQ4CQ/7+7NYGtM8XH82UJUT4= X-Google-Smtp-Source: ADFU+vv2OTPgHhQTQt1hhMqYhaFSeGVb5tFFleZIVG/GUUbGBVVXxMBNdJQBOh55SIWNsHqiVtnBaQ== X-Received: by 2002:a17:90a:1946:: with SMTP id 6mr405387pjh.42.1584520034178; Wed, 18 Mar 2020 01:27:14 -0700 (PDT) Received: from localhost.localdomain (59-127-47-126.HINET-IP.hinet.net. [59.127.47.126]) by smtp.gmail.com with ESMTPSA id 18sm5492148pfj.140.2020.03.18.01.27.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Mar 2020 01:27:13 -0700 (PDT) From: Chris Chiu To: Jes.Sorensen@gmail.com, kvalo@codeaurora.org, davem@davemloft.net Cc: linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux@endlessm.com Subject: [PATCH 2/2] rtl8xxxu: Feed current txrate information for mac80211 Date: Wed, 18 Mar 2020 16:27:00 +0800 Message-Id: <20200318082700.71875-3-chiu@endlessm.com> X-Mailer: git-send-email 2.21.1 (Apple Git-122.3) In-Reply-To: <20200318082700.71875-1-chiu@endlessm.com> References: <20200318082700.71875-1-chiu@endlessm.com> MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org The nl80211 commands such as 'iw link' can't get current txrate information from the driver. This commit fills in the tx rate information from the C2H RA report in the sta_statistics function. Signed-off-by: Chris Chiu Reported-by: kbuild test robot --- .../net/wireless/realtek/rtl8xxxu/rtl8xxxu.h | 12 ++- .../wireless/realtek/rtl8xxxu/rtl8xxxu_core.c | 75 ++++++++++++++++++- 2 files changed, 85 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h index 86d1d50511a8..e6fd1ecaca9c 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h @@ -1183,13 +1183,16 @@ struct rtl8723bu_c2h { } __packed bt_info; struct { u8 rate:7; - u8 dummy0_0:1; + u8 sgi:1; u8 macid; u8 ldpc:1; u8 txbf:1; u8 noisy_state:1; u8 dummy2_0:5; u8 dummy3_0; + u8 dummy4_0; + u8 dummy5_0; + u8 bw; } __packed ra_report; }; }; @@ -1269,6 +1272,12 @@ struct rtl8xxxu_btcoex { #define RTL8XXXU_SNR_THRESH_HIGH 50 #define RTL8XXXU_SNR_THRESH_LOW 20 +struct rtl8xxxu_ra_report { + struct rate_info txrate; + u32 bit_rate; + u8 desc_rate; +}; + struct rtl8xxxu_priv { struct ieee80211_hw *hw; struct usb_device *udev; @@ -1384,6 +1393,7 @@ struct rtl8xxxu_priv { struct sk_buff_head c2hcmd_queue; spinlock_t c2hcmd_lock; struct rtl8xxxu_btcoex bt_coex; + struct rtl8xxxu_ra_report ra_report; }; struct rtl8xxxu_rx_urb { diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c index 511a3b4ed72a..49dfa32b572a 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c @@ -5389,6 +5389,35 @@ void rtl8723bu_handle_bt_info(struct rtl8xxxu_priv *priv) } } +static struct ieee80211_rate rtl8xxxu_legacy_ratetable[] = { + {.bitrate = 10, .hw_value = 0x00,}, + {.bitrate = 20, .hw_value = 0x01,}, + {.bitrate = 55, .hw_value = 0x02,}, + {.bitrate = 110, .hw_value = 0x03,}, + {.bitrate = 60, .hw_value = 0x04,}, + {.bitrate = 90, .hw_value = 0x05,}, + {.bitrate = 120, .hw_value = 0x06,}, + {.bitrate = 180, .hw_value = 0x07,}, + {.bitrate = 240, .hw_value = 0x08,}, + {.bitrate = 360, .hw_value = 0x09,}, + {.bitrate = 480, .hw_value = 0x0a,}, + {.bitrate = 540, .hw_value = 0x0b,}, +}; + +void rtl8xxxu_desc_to_mcsrate(u16 rate, u8 *mcs, u8 *nss) +{ + if (rate <= DESC_RATE_54M) + return; + + if (rate >= DESC_RATE_MCS0 && rate <= DESC_RATE_MCS15) { + if (rate < DESC_RATE_MCS8) + *nss = 1; + else + *nss = 2; + *mcs = rate - DESC_RATE_MCS0; + } +} + static void rtl8xxxu_c2hcmd_callback(struct work_struct *work) { struct rtl8xxxu_priv *priv; @@ -5397,9 +5426,14 @@ static void rtl8xxxu_c2hcmd_callback(struct work_struct *work) unsigned long flags; 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; priv = container_of(work, struct rtl8xxxu_priv, c2hcmd_work); btcoex = &priv->bt_coex; + rarpt = &priv->ra_report; if (priv->rf_paths > 1) goto out; @@ -5422,6 +5456,34 @@ 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; + bw = c2h->ra_report.bw; + + 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; + } + + if (bw == RATE_INFO_BW_20) + rarpt->txrate.bw |= RATE_INFO_BW_20; + } + bit_rate = cfg80211_calculate_bitrate(&rarpt->txrate); + rarpt->bit_rate = bit_rate; + rarpt->desc_rate = rate; + break; default: break; } @@ -5465,7 +5527,7 @@ static void rtl8723bu_handle_c2h(struct rtl8xxxu_priv *priv, case C2H_8723B_RA_REPORT: dev_dbg(dev, "C2H RA RPT: rate %02x, unk %i, macid %02x, noise %i\n", - c2h->ra_report.rate, c2h->ra_report.dummy0_0, + c2h->ra_report.rate, c2h->ra_report.sgi, c2h->ra_report.macid, c2h->ra_report.noisy_state); break; default: @@ -6069,6 +6131,16 @@ rtl8xxxu_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif, return 0; } +static void +rtl8xxxu_sta_statistics(struct ieee80211_hw *hw, struct ieee80211_vif *vif, + struct ieee80211_sta *sta, struct station_info *sinfo) +{ + struct rtl8xxxu_priv *priv = hw->priv; + + sinfo->txrate = priv->ra_report.txrate; + sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE); +} + static u8 rtl8xxxu_signal_to_snr(int signal) { if (signal < RTL8XXXU_NOISE_FLOOR_MIN) @@ -6371,6 +6443,7 @@ static const struct ieee80211_ops rtl8xxxu_ops = { .sw_scan_complete = rtl8xxxu_sw_scan_complete, .set_key = rtl8xxxu_set_key, .ampdu_action = rtl8xxxu_ampdu_action, + .sta_statistics = rtl8xxxu_sta_statistics, }; static int rtl8xxxu_parse_usb(struct rtl8xxxu_priv *priv,