From patchwork Fri Mar 18 02:42:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Chiu X-Patchwork-Id: 12784807 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 45AF6C433EF for ; Fri, 18 Mar 2022 02:43:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231879AbiCRCoW (ORCPT ); Thu, 17 Mar 2022 22:44:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231842AbiCRCoV (ORCPT ); Thu, 17 Mar 2022 22:44:21 -0400 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF6E4C6EFA for ; Thu, 17 Mar 2022 19:43:00 -0700 (PDT) Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 3B38D3F325 for ; Fri, 18 Mar 2022 02:42:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1647571377; bh=IsQNvnrYzFlByVho6HFj26Mu5PXAjpXD97Wru1aaDTM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Q/bTcGQrI2ntRSQUP5/O5IB6Pe8MaHpDYBytW0dEBlkf/hp7LbqZQgij08fbYjfDh IxJIN5iWSK4ux+eB2LNsIfITmqqQtuvjEdITpRv3R93Mtd7YXoiCoZqOGrEQRUZj26 UF/JPAXIwdCsreXPTg9/KFbc9injf5kfzQyyEVAVU151q7s0Ks8Wy+lq7TZqCqPzfU 4vQZoXtynO4Lz/VWdV+kRnjfapQq4c5zqLSWkT6DD/RvnXiwLrK0Fxki7ehcZgmT86 YMM9Ndhfo/QZtazT4VOR4PvFRlKFvFI53ou4/+hKgP9tVdHfDqaceW8R1/pSMnrCKB szbgh9Z3Z3yKA== Received: by mail-pf1-f199.google.com with SMTP id t184-20020a6281c1000000b004e103c5f726so4515472pfd.8 for ; Thu, 17 Mar 2022 19:42:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IsQNvnrYzFlByVho6HFj26Mu5PXAjpXD97Wru1aaDTM=; b=JO1lIfKpGpG1pNUbvix6uDkFpHPsBJk/rvFt7ca5REfeuh71PpNEQyvB/Wvw7wnQ14 Z+fuBESm6FiFIww+hzx4ANgk0MVFUgUkyNA7OyFjFIWqSSu4rRzk5oTUkWvKYapS34bf eBoBA7iEvBnva/uXz9f1OLCJOuBptRzP4HwCHirD4jbjxUBFli1FzdHFh1ffkxOPblRc AL7UPxJPYwd7lL5XeN7DwSquzSXVzNhTG5Wto2Er9w84q/MMp1sit7KYeNVSlRWvwsB0 ErUNjOcx5L1NhRieSR6Orjp9cSAdD9VI77y3HKJthCMESVcGWTMzbXkj2jlqE9UgGit0 C6dw== X-Gm-Message-State: AOAM531sVNvAeCcSDKA4WzD0VHTYsBXYmS6yg0w2iG3d6owNwS2Fi05i cj/8dChaopr+Lciw8iQs/aWtZIi5loBSzKYwpxzezmHPzT5D+eesY4cvM42XJZtjgVcbmCv6Ec0 agphB+RVgpqTxHDaHAjdycS/sU+hvlAQBE9bV4t5TRb2q X-Received: by 2002:a17:902:be14:b0:14f:ce67:d0a1 with SMTP id r20-20020a170902be1400b0014fce67d0a1mr7647156pls.29.1647571375717; Thu, 17 Mar 2022 19:42:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyWDlX7R0u3bbFhyd2lD9L026rsWS+K74zpJKVsaJKOqtXpz80a93XUCWWuMOjElFNq5i7sfw== X-Received: by 2002:a17:902:be14:b0:14f:ce67:d0a1 with SMTP id r20-20020a170902be1400b0014fce67d0a1mr7647141pls.29.1647571375385; Thu, 17 Mar 2022 19:42:55 -0700 (PDT) Received: from localhost.localdomain (2001-b400-e287-a413-5915-32ac-82c3-a966.emome-ip6.hinet.net. [2001:b400:e287:a413:5915:32ac:82c3:a966]) by smtp.gmail.com with ESMTPSA id v16-20020a056a00149000b004f7ae2cbd3asm8191232pfu.166.2022.03.17.19.42.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 19:42:55 -0700 (PDT) From: Chris Chiu To: kvalo@kernel.org, Jes.Sorensen@gmail.com, davem@davemloft.net, kuba@kernel.org Cc: code@reto-schneider.ch, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Chris Chiu Subject: [PATCH v2 1/2] rtl8xxxu: feed antenna information for cfg80211 Date: Fri, 18 Mar 2022 10:42:15 +0800 Message-Id: <20220318024216.42204-2-chris.chiu@canonical.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220318024216.42204-1-chris.chiu@canonical.com> References: <20220318024216.42204-1-chris.chiu@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Fill up the available TX/RX antenna so the iw commands can show correct antenna information for different chips. Signed-off-by: Chris Chiu --- .../wireless/realtek/rtl8xxxu/rtl8xxxu_core.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c index 06d59ffb7444..d225a1257530 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c @@ -1607,6 +1607,7 @@ static void rtl8xxxu_print_chipinfo(struct rtl8xxxu_priv *priv) static int rtl8xxxu_identify_chip(struct rtl8xxxu_priv *priv) { struct device *dev = &priv->udev->dev; + struct ieee80211_hw *hw = priv->hw; u32 val32, bonding; u16 val16; @@ -1684,6 +1685,9 @@ static int rtl8xxxu_identify_chip(struct rtl8xxxu_priv *priv) priv->has_wifi = 1; } + hw->wiphy->available_antennas_tx = BIT(priv->tx_paths) - 1; + hw->wiphy->available_antennas_rx = BIT(priv->rx_paths) - 1; + switch (priv->rtl_chip) { case RTL8188E: case RTL8192E: @@ -4282,6 +4286,17 @@ static void rtl8xxxu_cam_write(struct rtl8xxxu_priv *priv, rtl8xxxu_debug = tmp_debug; } +static +int rtl8xxxu_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant) +{ + struct rtl8xxxu_priv *priv = hw->priv; + + *tx_ant = BIT(priv->tx_paths) - 1; + *rx_ant = BIT(priv->rx_paths) - 1; + + return 0; +} + static void rtl8xxxu_sw_scan_start(struct ieee80211_hw *hw, struct ieee80211_vif *vif, const u8 *mac) { @@ -6472,6 +6487,7 @@ static const struct ieee80211_ops rtl8xxxu_ops = { .set_key = rtl8xxxu_set_key, .ampdu_action = rtl8xxxu_ampdu_action, .sta_statistics = rtl8xxxu_sta_statistics, + .get_antenna = rtl8xxxu_get_antenna, }; static int rtl8xxxu_parse_usb(struct rtl8xxxu_priv *priv, From patchwork Fri Mar 18 02:42:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Chiu X-Patchwork-Id: 12784809 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 4E714C43217 for ; Fri, 18 Mar 2022 02:43:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231902AbiCRCo0 (ORCPT ); Thu, 17 Mar 2022 22:44:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231889AbiCRCoX (ORCPT ); Thu, 17 Mar 2022 22:44:23 -0400 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 259DE99ED9 for ; Thu, 17 Mar 2022 19:43:02 -0700 (PDT) Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id ACFDE3F316 for ; Fri, 18 Mar 2022 02:43:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1647571380; bh=f9EJWx0pz9xYZ/T46QT2nYRC6HKLvwA6csw+2PrRGps=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jtCE/InJ+GruWdOE7E6qEyNqh9qV2UCi6hAAAObf+lXi9fcNO6Qfk6wxOBU06VA5/ 7XsbmwxEhnumP7XGLx56/aXTreNJSowZTbb8/kV1f6e9dl4+da8MfQEdxtVHbPtXzf ZPULGDZ68s6fExGYmWrFqWsMl8bbNqidbjSHHcIL5WWWXh/kYYcZSEmF6gPg4bo+mE Un3qKU+tWeCNPG4mUi/qg8G6RORJTKOCxRLI4DIwCgMDfSa69PDBlfPTeFqySKIlIh +h1vYk0taIR5Y9RlopQPwyXuAFAr+QZmTcQxhCzLfq8BwPwmuVAPMqy4jLtTLada3p YOeUDX7YiV6mw== Received: by mail-pf1-f200.google.com with SMTP id u67-20020a627946000000b004fa6338bd77so1269580pfc.10 for ; Thu, 17 Mar 2022 19:43:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=f9EJWx0pz9xYZ/T46QT2nYRC6HKLvwA6csw+2PrRGps=; b=TMFp3wHE5mDb5DDAo3eYl7VX6u22k+srJbVAJZCkWJhpgZgLDD43+KFIgqJqx35Ya0 SY59w1MRDydVJDTVgCo6p3TkSA+tAyXRN8oWhgGyfrxr7RzuBvqzfFFwvBMe6PD17E3x HfCbpiK9V6VkHTcP+0g9skWq1wiBv173KkzDPwrVAKmfiFOaHKuzX5+mFhOXTD0sVFrD +tOy2jUllf1Fz+C1REO/LJiOht7Vk2ylJ1YSFM+LGAoqVQ/VECYtTynQ9ErEgbhLqJ1K V5KUqPTY2/qQWBm5lovSGBSmBJB0ApNefqqcRjFgclLBqQW+r7/1k0JuI7E+sKxSWkP9 u6KA== X-Gm-Message-State: AOAM532+xxTr+P3fVI1U2fmGZeKJ2xEiF8TNmZKq8+OaTXgWC7OSH3hL 7CGWPEnM4hQjVTdnyy29ps9V0VOlT6tTqdaoB4tAoVRo3YnKevL8U7sgRLtP9jjak2swP8Ad7zK CHRVbbRUd/YziTHCyl+V1+YDEEP1HrFBLb+9JpSPPsV2y X-Received: by 2002:a17:902:bd87:b0:153:ceb:3a6d with SMTP id q7-20020a170902bd8700b001530ceb3a6dmr7811837pls.146.1647571379133; Thu, 17 Mar 2022 19:42:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykrTwLqVp8lScEdbYiq8EeLrP9LGRMLzx7tFiMg0QnklPTnrHP6GdA0fMNW/PbHzHpC5KKgQ== X-Received: by 2002:a17:902:bd87:b0:153:ceb:3a6d with SMTP id q7-20020a170902bd8700b001530ceb3a6dmr7811824pls.146.1647571378831; Thu, 17 Mar 2022 19:42:58 -0700 (PDT) Received: from localhost.localdomain (2001-b400-e287-a413-5915-32ac-82c3-a966.emome-ip6.hinet.net. [2001:b400:e287:a413:5915:32ac:82c3:a966]) by smtp.gmail.com with ESMTPSA id v16-20020a056a00149000b004f7ae2cbd3asm8191232pfu.166.2022.03.17.19.42.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 19:42:58 -0700 (PDT) From: Chris Chiu To: kvalo@kernel.org, Jes.Sorensen@gmail.com, davem@davemloft.net, kuba@kernel.org Cc: code@reto-schneider.ch, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Chris Chiu Subject: [PATCH v2 2/2] rtl8xxxu: fill up txrate info for gen1 chips Date: Fri, 18 Mar 2022 10:42:16 +0800 Message-Id: <20220318024216.42204-3-chris.chiu@canonical.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220318024216.42204-1-chris.chiu@canonical.com> References: <20220318024216.42204-1-chris.chiu@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org RTL8188CUS/RTL8192CU(gen1) don't support rate adatptive report hence no real txrate info can be retrieved. The vendor driver reports the highest rate in HT capabilities from the IEs to avoid empty txrate. This commit initiates the txrate information with the highest supported rate negotiated with AP. The gen2 chip keeps update the txrate from the rate adaptive reports, and gen1 chips at least have non-NULL txrate after associated. Signed-off-by: Chris Chiu --- Changelog: v2: - Use the 'static const' for rtl8xxxu_legacy_ratetable[] .../wireless/realtek/rtl8xxxu/rtl8xxxu_core.c | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c index d225a1257530..cc9d14e9c4c4 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c @@ -4473,6 +4473,35 @@ void rtl8xxxu_gen1_init_aggregation(struct rtl8xxxu_priv *priv) priv->rx_buf_aggregation = 1; } +static const 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,}, +}; + +static 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_set_basic_rates(struct rtl8xxxu_priv *priv, u32 rate_cfg) { struct ieee80211_hw *hw = priv->hw; @@ -4534,9 +4563,12 @@ rtl8xxxu_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct rtl8xxxu_priv *priv = hw->priv; struct device *dev = &priv->udev->dev; struct ieee80211_sta *sta; + struct rtl8xxxu_ra_report *rarpt; u32 val32; u8 val8; + rarpt = &priv->ra_report; + if (changed & BSS_CHANGED_ASSOC) { dev_dbg(dev, "Changed ASSOC: %i!\n", bss_conf->assoc); @@ -4545,6 +4577,10 @@ rtl8xxxu_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif, if (bss_conf->assoc) { u32 ramask; int sgi = 0; + u8 highest_rate; + u8 mcs = 0, nss = 0; + u32 bit_rate; + rcu_read_lock(); sta = ieee80211_find_sta(vif, bss_conf->bssid); @@ -4569,6 +4605,29 @@ rtl8xxxu_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif, sgi = 1; rcu_read_unlock(); + 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; + } + + rarpt->txrate.bw |= RATE_INFO_BW_20; + } + bit_rate = cfg80211_calculate_bitrate(&rarpt->txrate); + rarpt->bit_rate = bit_rate; + rarpt->desc_rate = highest_rate; + priv->vif = vif; priv->rssi_level = RTL8XXXU_RATR_STA_INIT;