netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] rtl8xxxu: Fill up more TX information
@ 2022-03-18  2:42 Chris Chiu
  2022-03-18  2:42 ` [PATCH v2 1/2] rtl8xxxu: feed antenna information for cfg80211 Chris Chiu
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Chris Chiu @ 2022-03-18  2:42 UTC (permalink / raw)
  To: kvalo, Jes.Sorensen, davem, kuba
  Cc: code, linux-wireless, netdev, linux-kernel, Chris Chiu

The antenna information is missing in rtl8xxxu and txrate is NULL
in 8188cu and 8192cu. Fill up the missing information for iw
commands.

Chris Chiu (2):
  rtl8xxxu: feed antenna information for cfg80211
  rtl8xxxu: fill up txrate info for gen1 chips

 .../wireless/realtek/rtl8xxxu/rtl8xxxu_core.c | 75 +++++++++++++++++++
 1 file changed, 75 insertions(+)

-- 
2.20.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/2] rtl8xxxu: feed antenna information for cfg80211
  2022-03-18  2:42 [PATCH v2 0/2] rtl8xxxu: Fill up more TX information Chris Chiu
@ 2022-03-18  2:42 ` Chris Chiu
  2022-03-18  2:42 ` [PATCH v2 2/2] rtl8xxxu: fill up txrate info for gen1 chips Chris Chiu
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Chris Chiu @ 2022-03-18  2:42 UTC (permalink / raw)
  To: kvalo, Jes.Sorensen, davem, kuba
  Cc: code, linux-wireless, netdev, linux-kernel, Chris Chiu

Fill up the available TX/RX antenna so the iw commands can show
correct antenna information for different chips.

Signed-off-by: Chris Chiu <chris.chiu@canonical.com>
---
 .../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,
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/2] rtl8xxxu: fill up txrate info for gen1 chips
  2022-03-18  2:42 [PATCH v2 0/2] rtl8xxxu: Fill up more TX information Chris Chiu
  2022-03-18  2:42 ` [PATCH v2 1/2] rtl8xxxu: feed antenna information for cfg80211 Chris Chiu
@ 2022-03-18  2:42 ` Chris Chiu
  2022-03-24 16:35   ` Reto Schneider
  2022-03-18  6:55 ` [PATCH v2 0/2] rtl8xxxu: Fill up more TX information Reto Schneider
  2022-03-24 16:32 ` Reto Schneider
  3 siblings, 1 reply; 7+ messages in thread
From: Chris Chiu @ 2022-03-18  2:42 UTC (permalink / raw)
  To: kvalo, Jes.Sorensen, davem, kuba
  Cc: code, linux-wireless, netdev, linux-kernel, Chris Chiu

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 <chris.chiu@canonical.com>
---

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;
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 0/2] rtl8xxxu: Fill up more TX information
  2022-03-18  2:42 [PATCH v2 0/2] rtl8xxxu: Fill up more TX information Chris Chiu
  2022-03-18  2:42 ` [PATCH v2 1/2] rtl8xxxu: feed antenna information for cfg80211 Chris Chiu
  2022-03-18  2:42 ` [PATCH v2 2/2] rtl8xxxu: fill up txrate info for gen1 chips Chris Chiu
@ 2022-03-18  6:55 ` Reto Schneider
  2022-03-24 16:32 ` Reto Schneider
  3 siblings, 0 replies; 7+ messages in thread
From: Reto Schneider @ 2022-03-18  6:55 UTC (permalink / raw)
  To: Chris Chiu, kvalo, Jes.Sorensen, davem, kuba
  Cc: linux-wireless, netdev, linux-kernel

Hi

On 18.03.22 03:42, Chris Chiu wrote:
> The antenna information is missing in rtl8xxxu and txrate is NULL
> in 8188cu and 8192cu. Fill up the missing information for iw
> commands.

I tested older versions of this and it worked well. Will give this set a 
try during next week.

Kind regards,
Reto

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 0/2] rtl8xxxu: Fill up more TX information
  2022-03-18  2:42 [PATCH v2 0/2] rtl8xxxu: Fill up more TX information Chris Chiu
                   ` (2 preceding siblings ...)
  2022-03-18  6:55 ` [PATCH v2 0/2] rtl8xxxu: Fill up more TX information Reto Schneider
@ 2022-03-24 16:32 ` Reto Schneider
  2022-03-25  4:02   ` Chris Chiu
  3 siblings, 1 reply; 7+ messages in thread
From: Reto Schneider @ 2022-03-24 16:32 UTC (permalink / raw)
  To: Chris Chiu
  Cc: linux-wireless, netdev, linux-kernel, kvalo, Jes.Sorensen, davem, kuba


On 18.03.22 03:42, Chris Chiu wrote:
> The antenna information is missing in rtl8xxxu and txrate is NULL
> in 8188cu and 8192cu. Fill up the missing information for iw
> commands.
> 
> Chris Chiu (2):
>    rtl8xxxu: feed antenna information for cfg80211
>    rtl8xxxu: fill up txrate info for gen1 chips
> 
>   .../wireless/realtek/rtl8xxxu/rtl8xxxu_core.c | 75 +++++++++++++++++++
>   1 file changed, 75 insertions(+)
> 

Those two patches applied to most recent master 
(v5.17-4443-ged4643521e6a) do not compile as rtl8xxxu_legacy_ratetable[] 
and rtl8xxxu_desc_to_mcsrate() are defined twice.

Kind regards,
Reto

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/2] rtl8xxxu: fill up txrate info for gen1 chips
  2022-03-18  2:42 ` [PATCH v2 2/2] rtl8xxxu: fill up txrate info for gen1 chips Chris Chiu
@ 2022-03-24 16:35   ` Reto Schneider
  0 siblings, 0 replies; 7+ messages in thread
From: Reto Schneider @ 2022-03-24 16:35 UTC (permalink / raw)
  To: Chris Chiu
  Cc: linux-wireless, netdev, linux-kernel, kvalo, Jes.Sorensen, davem, kuba

On 18.03.22 03:42, Chris Chiu wrote:
> RTL8188CUS/RTL8192CU(gen1) don't support rate adatptive report hence
                                                 adaptive

> 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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 0/2] rtl8xxxu: Fill up more TX information
  2022-03-24 16:32 ` Reto Schneider
@ 2022-03-25  4:02   ` Chris Chiu
  0 siblings, 0 replies; 7+ messages in thread
From: Chris Chiu @ 2022-03-25  4:02 UTC (permalink / raw)
  To: Reto Schneider
  Cc: linux-wireless, netdev, linux-kernel, kvalo, Jes.Sorensen, davem, kuba

On Fri, Mar 25, 2022 at 12:32 AM Reto Schneider <code@reto-schneider.ch> wrote:
>
>
> On 18.03.22 03:42, Chris Chiu wrote:
> > The antenna information is missing in rtl8xxxu and txrate is NULL
> > in 8188cu and 8192cu. Fill up the missing information for iw
> > commands.
> >
> > Chris Chiu (2):
> >    rtl8xxxu: feed antenna information for cfg80211
> >    rtl8xxxu: fill up txrate info for gen1 chips
> >
> >   .../wireless/realtek/rtl8xxxu/rtl8xxxu_core.c | 75 +++++++++++++++++++
> >   1 file changed, 75 insertions(+)
> >
>
> Those two patches applied to most recent master
> (v5.17-4443-ged4643521e6a) do not compile as rtl8xxxu_legacy_ratetable[]
> and rtl8xxxu_desc_to_mcsrate() are defined twice.
>
> Kind regards,
> Reto

Thanks for pointing this out. I'll fix it in v3.

Chris

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-03-25  4:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-18  2:42 [PATCH v2 0/2] rtl8xxxu: Fill up more TX information Chris Chiu
2022-03-18  2:42 ` [PATCH v2 1/2] rtl8xxxu: feed antenna information for cfg80211 Chris Chiu
2022-03-18  2:42 ` [PATCH v2 2/2] rtl8xxxu: fill up txrate info for gen1 chips Chris Chiu
2022-03-24 16:35   ` Reto Schneider
2022-03-18  6:55 ` [PATCH v2 0/2] rtl8xxxu: Fill up more TX information Reto Schneider
2022-03-24 16:32 ` Reto Schneider
2022-03-25  4:02   ` Chris Chiu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).