From patchwork Mon Mar 7 12:58:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Chiu X-Patchwork-Id: 549202 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 2E8CCC433F5 for ; Mon, 7 Mar 2022 12:59:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241636AbiCGNAN (ORCPT ); Mon, 7 Mar 2022 08:00:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233067AbiCGNAM (ORCPT ); Mon, 7 Mar 2022 08:00:12 -0500 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 48646673C7 for ; Mon, 7 Mar 2022 04:59:16 -0800 (PST) Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) (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 96AE13F60D for ; Mon, 7 Mar 2022 12:59:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1646657955; bh=IsQNvnrYzFlByVho6HFj26Mu5PXAjpXD97Wru1aaDTM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=e4K3khZ0KvNIrWbfam7wS4gDxTYDdMafvGSrIJIL0MMLUl40U1eXpguFdbBKUJCt3 C6BDr6SVqsApKBOEHNmeqzy/NDbzrxLCzLTd7PSeQUkSFpQK0wWHDUREX3OlLXlfVe IE96CfCQhLNdnJ0UF6c7AEdsKijMcfU5ESUNuOUyluRD+WYT0eCWWFgB2vy6U1RjWD Lzb21pSRUfqLyI4WMbAvGVE77G0GQSNTLx4RJLf97iSzUjZN4o+pPQZehByd2tCbOr Ygb8/w8rIs9vJ8UDzRiGSnyliX5lYjLOtfElo7hxcVk9q4WnQoxkpfu10gHfHa36Nd 8q+QHLltKjs0Q== Received: by mail-pf1-f197.google.com with SMTP id 184-20020a6215c1000000b004f6dc47ec08so3960656pfv.21 for ; Mon, 07 Mar 2022 04:59:15 -0800 (PST) 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=j+GiHTvZOhAejMVmYcv37mBsjSNSW1rKOqk1IPYFW97Nqyt7+HstVNQ3DQbnP35W8v KTQRf/N1ZwWivGmQv2XELxZTF78+n3ZXc3l7aRKVev5LLIWhnegZinTATg3XsyHfF2dA OJYE1odLuEMixc1L6YMgxWdqdmcfh+9UwmPecOJmYOzfJsRJgYvATJ+OG8zMLJc7PbUG NU+zTSV+QxpuCJF36SBqou2ZTjdxQOmGj6NM+5uwLdi4UwU3UxwqiFHy6E7f5WiC0Xcf 6MPcPUCTiNfgfHQgpfCrk8NjjpjGRxmPyzpkva6PIYSypflqrtFETzTPnsp117coRnXP ndPQ== X-Gm-Message-State: AOAM532zL11TKqjxIM1YzlnR9BxJfN7jwvQMPRsqVxKZjeM5UiHNCxwP QtSsqCOFEzatWvyzLXaZnJuGzYNhn4SJSmDsCSLhsxwPvbdO6mq/0V9BzsQC57GeIUISUBmyHdQ dz4h3ycSTaWMahQxc3emnidWCSs2lqckZHOu5xxNM8lUg X-Received: by 2002:a17:90a:19d5:b0:1bc:a5db:b655 with SMTP id 21-20020a17090a19d500b001bca5dbb655mr25236428pjj.46.1646657953399; Mon, 07 Mar 2022 04:59:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJyeisv63taSGAcKFYoPo3kwY7DTxoY58lBoTyjbrXxgaD5HZdiVOhc/XjBuDTTsNSX4B/Rprg== X-Received: by 2002:a17:90a:19d5:b0:1bc:a5db:b655 with SMTP id 21-20020a17090a19d500b001bca5dbb655mr25236399pjj.46.1646657953083; Mon, 07 Mar 2022 04:59:13 -0800 (PST) Received: from localhost.localdomain (59-115-216-226.dynamic-ip.hinet.net. [59.115.216.226]) by smtp.gmail.com with ESMTPSA id oj2-20020a17090b4d8200b001bef79ea006sm17545682pjb.29.2022.03.07.04.59.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Mar 2022 04:59:12 -0800 (PST) From: Chris Chiu To: Jes.Sorensen@gmail.com, kvalo@codeaurora.org, 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 1/2] rtl8xxxu: feed antenna information for cfg80211 Date: Mon, 7 Mar 2022 20:58:51 +0800 Message-Id: <20220307125852.13606-2-chris.chiu@canonical.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220307125852.13606-1-chris.chiu@canonical.com> References: <20220307125852.13606-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 Mon Mar 7 12:58:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Chiu X-Patchwork-Id: 549672 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 35305C433FE for ; Mon, 7 Mar 2022 12:59:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242674AbiCGNAX (ORCPT ); Mon, 7 Mar 2022 08:00:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242684AbiCGNAV (ORCPT ); Mon, 7 Mar 2022 08:00:21 -0500 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 BB00069CFC for ; Mon, 7 Mar 2022 04:59:24 -0800 (PST) Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) (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 A7A8B3F5F7 for ; Mon, 7 Mar 2022 12:59:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1646657959; bh=jMtPmKSRUvUYtvTflv22KoBJEK0aUxzC1RIZwVEFX+k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=m45azRDbEudGlZz0mRPtU2lIqZ0lbkH5WYNrwTWfWRtdvyi9ci4Zvy2JVKiXpK+nL iOSATs5NEa7bkD4cKf6trv9JYx5islRymEL8nel77G7rQw/oVj8MB/1G5t21ilgplF 1dD3ro8g2cMDYi5s4SIScBHpdJ6O1NE4pRNieDMIcoKRdnw+/5polr8X042T9CSj4k fCvynu6l8i73AktOOxd+hPvabqSfuQYjUjV99m/CiL2a1kuGdhr3aLPlEoCbx7K5mt wtB2h5NCSvxnV/M4gPpXQs+zmgurMRTABqdY3Hfq96zEU2+01nSGIFgTV/wrsb5Fbm BCxTAtH63lw8w== Received: by mail-pj1-f72.google.com with SMTP id cl16-20020a17090af69000b001beea61ada4so6225289pjb.5 for ; Mon, 07 Mar 2022 04:59:19 -0800 (PST) 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=jMtPmKSRUvUYtvTflv22KoBJEK0aUxzC1RIZwVEFX+k=; b=H5C+mI66HjS6R3bANk+vTR8GXLRfS3B+0s34da4+CgBXZyUI0p/QnNvwUa4/I+X7LQ GHIyTg3fAMSt+RJrp6rMqq/dVBAfphLBv4owYsCkrcP0fgpwmp3R+6OdnXiKh7H151x2 bZNzTe+qDwAyiwQFFWyyOOvtw36Y8lRGGBLMt9ipITFMcw88FGyLInr3A7jfZIlsWnHT 2S03p8KSRS02Bp6ObMt9KlW4B65QrTjQ9TUwOrEmbNJpbEQdI98QveQXH9B5OdYLkvFg l4YDReDHpO/9rC94Nv1IxJWsCtJ7S3jCTjZdI8cljEXMRyh2z8ebwJKkFv9xuEgva8Xk GJ+g== X-Gm-Message-State: AOAM531vG8eUT2diAU94AjRSRIc/QTPpaLTln43j27LFQwtxoYp4zGik +2rddv1ehjLEFPgdTQ3rEDV8LaTYSfwp6WjUloSxn9uWgKJsfd68nCLghviH0DNbnKlfkpHBgV8 4s7NJ6yaR7Yyt3FdgqwTwr/jY38m7hBVdntPB0zwRa9UN X-Received: by 2002:a05:6a00:124f:b0:4c0:6242:c14e with SMTP id u15-20020a056a00124f00b004c06242c14emr12392489pfi.83.1646657958312; Mon, 07 Mar 2022 04:59:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJwUGtcuE9+d9RFrcMdWxp59VW+xrbfIIprtBnMCCjgc9FCOCuS/oZygQdQTPUWW2SQOzqsgIQ== X-Received: by 2002:a05:6a00:124f:b0:4c0:6242:c14e with SMTP id u15-20020a056a00124f00b004c06242c14emr12392447pfi.83.1646657957964; Mon, 07 Mar 2022 04:59:17 -0800 (PST) Received: from localhost.localdomain (59-115-216-226.dynamic-ip.hinet.net. [59.115.216.226]) by smtp.gmail.com with ESMTPSA id oj2-20020a17090b4d8200b001bef79ea006sm17545682pjb.29.2022.03.07.04.59.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Mar 2022 04:59:17 -0800 (PST) From: Chris Chiu To: Jes.Sorensen@gmail.com, kvalo@codeaurora.org, 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 2/2] rtl8xxxu: fill up txrate info for gen1 chips Date: Mon, 7 Mar 2022 20:58:52 +0800 Message-Id: <20220307125852.13606-3-chris.chiu@canonical.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220307125852.13606-1-chris.chiu@canonical.com> References: <20220307125852.13606-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 --- .../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..285acf303e3d 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 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;