Skip to contentSkip to conversation

wifi: rtl8xxxu: Deduplicate the efuse dumping code

PATCH In review Bitterblue Smith 3 participants 11 messages Dec 17, 2022 – Dec 21, 2022 RTL8XXXU wireless driver (rtl8xxxu)

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/5 wifi: rtl8xxxu: Deduplicate the efuse dumping code

Every chip family except RTL8723AU has a copy of the efuse dumping code. Remove this and dump the efuse from a single place using a new function rtl8xxxu_dump_efuse().

Also, use print_hex_dump() to print the efuse instead of a loop and dev_info(). It shows the ASCII interpretation of the bytes, which is nice.

---
v3:
- Implement suggestion from Ping-Ke Shih:
- Use EFUSE_MAP_LEN instead of EFUSE_REAL_CONTENT_LEN_8723A. They have the same value.

v2:
- Patch is new in v2.

---
 .../net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188f.c  | 11 -----------
 .../net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192c.c  | 10 ----------
 .../net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c  |  9 ---------
 .../net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723b.c  | 11 -----------
 .../net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c   | 13 +++++++++++++
 5 files changed, 13 insertions(+), 41 deletions(-)
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188f.c +0 -11
index 2c4f403ba68f..ba28a4c00d3b 100644
@@ -716,7 +716,6 @@ static void rtl8188fu_init_statistics(struct rtl8xxxu_priv *priv)
 static int rtl8188fu_parse_efuse(struct rtl8xxxu_priv *priv)
 {
 	struct rtl8188fu_efuse *efuse = &priv->efuse_wifi.efuse8188fu;
-	int i;
 
 	if (efuse->rtl_id != cpu_to_le16(0x8129))
 		return -EINVAL;
@@ -738,16 +737,6 @@ static int rtl8188fu_parse_efuse(struct rtl8xxxu_priv *priv)
 	dev_info(&priv->udev->dev, "Vendor: %.7s\n", efuse->vendor_name);
 	dev_info(&priv->udev->dev, "Product: %.7s\n", efuse->device_name);
 
-	if (rtl8xxxu_debug & RTL8XXXU_DEBUG_EFUSE) {
-		unsigned char *raw = priv->efuse_wifi.raw;
-
-		dev_info(&priv->udev->dev,
-			 "%s: dumping efuse (0x%02zx bytes):\n",
-			 __func__, sizeof(struct rtl8188fu_efuse));
-		for (i = 0; i < sizeof(struct rtl8188fu_efuse); i += 8)
-			dev_info(&priv->udev->dev, "%02x: %8ph\n", i, &raw[i]);
-	}
-
 	return 0;
 }
 
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192c.c +0 -10
index 3bef9ffc8b02..d43f8afeb876 100644
@@ -404,7 +404,6 @@ static int rtl8192cu_load_firmware(struct rtl8xxxu_priv *priv)
 static int rtl8192cu_parse_efuse(struct rtl8xxxu_priv *priv)
 {
 	struct rtl8192cu_efuse *efuse = &priv->efuse_wifi.efuse8192;
-	int i;
 
 	if (efuse->rtl_id != cpu_to_le16(0x8129))
 		return -EINVAL;
@@ -457,15 +456,6 @@ static int rtl8192cu_parse_efuse(struct rtl8xxxu_priv *priv)
 		priv->power_base = &rtl8188r_power_base;
 	}
 
-	if (rtl8xxxu_debug & RTL8XXXU_DEBUG_EFUSE) {
-		unsigned char *raw = priv->efuse_wifi.raw;
-
-		dev_info(&priv->udev->dev,
-			 "%s: dumping efuse (0x%02zx bytes):\n",
-			 __func__, sizeof(struct rtl8192cu_efuse));
-		for (i = 0; i < sizeof(struct rtl8192cu_efuse); i += 8)
-			dev_info(&priv->udev->dev, "%02x: %8ph\n", i, &raw[i]);
-	}
 	return 0;
 }
 
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c +0 -9
index 6dc1e5858e77..91f018f6fca0 100644
@@ -704,15 +704,6 @@ static int rtl8192eu_parse_efuse(struct rtl8xxxu_priv *priv)
 	rtl8192eu_log_next_device_info(priv, "Product", efuse->device_info, &record_offset);
 	rtl8192eu_log_next_device_info(priv, "Serial", efuse->device_info, &record_offset);
 
-	if (rtl8xxxu_debug & RTL8XXXU_DEBUG_EFUSE) {
-		unsigned char *raw = priv->efuse_wifi.raw;
-
-		dev_info(&priv->udev->dev,
-			 "%s: dumping efuse (0x%02zx bytes):\n",
-			 __func__, sizeof(struct rtl8192eu_efuse));
-		for (i = 0; i < sizeof(struct rtl8192eu_efuse); i += 8)
-			dev_info(&priv->udev->dev, "%02x: %8ph\n", i, &raw[i]);
-	}
 	return 0;
 }
 
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723b.c +0 -11
index a0ec895b61a4..b26737447035 100644
@@ -497,17 +497,6 @@ static int rtl8723bu_parse_efuse(struct rtl8xxxu_priv *priv)
 	dev_info(&priv->udev->dev, "Vendor: %.7s\n", efuse->vendor_name);
 	dev_info(&priv->udev->dev, "Product: %.41s\n", efuse->device_name);
 
-	if (rtl8xxxu_debug & RTL8XXXU_DEBUG_EFUSE) {
-		int i;
-		unsigned char *raw = priv->efuse_wifi.raw;
-
-		dev_info(&priv->udev->dev,
-			 "%s: dumping efuse (0x%02zx bytes):\n",
-			 __func__, sizeof(struct rtl8723bu_efuse));
-		for (i = 0; i < sizeof(struct rtl8723bu_efuse); i += 8)
-			dev_info(&priv->udev->dev, "%02x: %8ph\n", i, &raw[i]);
-	}
-
 	return 0;
 }
 
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c +13 -0
index 3ed435401e57..7f2adb1a9c70 100644
@@ -1813,6 +1813,16 @@ static int rtl8xxxu_read_efuse(struct rtl8xxxu_priv *priv)
 	return ret;
 }
 
+static void rtl8xxxu_dump_efuse(struct rtl8xxxu_priv *priv)
+{
+	dev_info(&priv->udev->dev,
+		 "Dumping efuse for RTL%s (0x%02x bytes):\n",
+		 priv->chip_name, EFUSE_MAP_LEN);
+
+	print_hex_dump(KERN_INFO, "", DUMP_PREFIX_OFFSET, 16, 1,
+		       priv->efuse_wifi.raw, EFUSE_MAP_LEN, true);
+}
+
 void rtl8xxxu_reset_8051(struct rtl8xxxu_priv *priv)
 {
 	u8 val8;
@@ -6839,6 +6849,9 @@ static int rtl8xxxu_probe(struct usb_interface *interface,
 		goto err_set_intfdata;
 	}
 
+	if (rtl8xxxu_debug & RTL8XXXU_DEBUG_EFUSE)
+		rtl8xxxu_dump_efuse(priv);
+
 	rtl8xxxu_print_chipinfo(priv);
 
 	ret = priv->fops->load_firmware(priv);
Signature · 1 line
2.38.0
#1 lore raw

PATCH v3 2/5 wifi: rtl8xxxu: Make rtl8xxxu_load_firmware take const char*

And pass const char* to it.

---
v3:
- No change.

v2:
- Patch is new in v2.

---
 drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h       | 2 +-
 drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188f.c | 2 +-
 drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192c.c | 2 +-
 drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c | 2 +-
 drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723a.c | 2 +-
 drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723b.c | 2 +-
 drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c  | 2 +-
 7 files changed, 7 insertions(+), 7 deletions(-)
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h +1 -1
index d26df4095da0..87758295d618 100644
@@ -1560,7 +1560,7 @@ int rtl8xxxu_init_phy_rf(struct rtl8xxxu_priv *priv,
 			 enum rtl8xxxu_rfpath path);
 int rtl8xxxu_init_phy_regs(struct rtl8xxxu_priv *priv,
 			   const struct rtl8xxxu_reg32val *array);
-int rtl8xxxu_load_firmware(struct rtl8xxxu_priv *priv, char *fw_name);
+int rtl8xxxu_load_firmware(struct rtl8xxxu_priv *priv, const char *fw_name);
 void rtl8xxxu_firmware_self_reset(struct rtl8xxxu_priv *priv);
 void rtl8xxxu_power_off(struct rtl8xxxu_priv *priv);
 void rtl8xxxu_identify_vendor_1bit(struct rtl8xxxu_priv *priv, u32 vendor);
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188f.c +1 -1
index ba28a4c00d3b..94fc4647075a 100644
@@ -742,7 +742,7 @@ static int rtl8188fu_parse_efuse(struct rtl8xxxu_priv *priv)
 
 static int rtl8188fu_load_firmware(struct rtl8xxxu_priv *priv)
 {
-	char *fw_name;
+	const char *fw_name;
 	int ret;
 
 	fw_name = "rtlwifi/rtl8188fufw.bin";
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192c.c +1 -1
index d43f8afeb876..8981a86c833f 100644
@@ -386,7 +386,7 @@ static int rtl8192cu_identify_chip(struct rtl8xxxu_priv *priv)
 
 static int rtl8192cu_load_firmware(struct rtl8xxxu_priv *priv)
 {
-	char *fw_name;
+	const char *fw_name;
 	int ret;
 
 	if (!priv->vendor_umc)
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c +1 -1
index 91f018f6fca0..c769d0eaa03c 100644
@@ -709,7 +709,7 @@ static int rtl8192eu_parse_efuse(struct rtl8xxxu_priv *priv)
 
 static int rtl8192eu_load_firmware(struct rtl8xxxu_priv *priv)
 {
-	char *fw_name;
+	const char *fw_name;
 	int ret;
 
 	fw_name = "rtlwifi/rtl8192eu_nic.bin";
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723a.c +1 -1
index 707ac48ecc83..e881ee33c6e8 100644
@@ -231,7 +231,7 @@ static int rtl8723au_parse_efuse(struct rtl8xxxu_priv *priv)
 
 static int rtl8723au_load_firmware(struct rtl8xxxu_priv *priv)
 {
-	char *fw_name;
+	const char *fw_name;
 	int ret;
 
 	switch (priv->chip_cut) {
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723b.c +1 -1
index b26737447035..65ebf9dcf5f9 100644
@@ -502,7 +502,7 @@ static int rtl8723bu_parse_efuse(struct rtl8xxxu_priv *priv)
 
 static int rtl8723bu_load_firmware(struct rtl8xxxu_priv *priv)
 {
-	char *fw_name;
+	const char *fw_name;
 	int ret;
 
 	if (priv->enable_bluetooth)
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c +1 -1
index 7f2adb1a9c70..7aa00442c3a5 100644
@@ -1980,7 +1980,7 @@ static int rtl8xxxu_download_firmware(struct rtl8xxxu_priv *priv)
 	return ret;
 }
 
-int rtl8xxxu_load_firmware(struct rtl8xxxu_priv *priv, char *fw_name)
+int rtl8xxxu_load_firmware(struct rtl8xxxu_priv *priv, const char *fw_name)
 {
 	struct device *dev = &priv->udev->dev;
 	const struct firmware *fw;
Signature · 1 line
2.38.0
Reviewed-by on v3 2/5
#2 lore raw

RE: [PATCH v3 2/5] wifi: rtl8xxxu: Make rtl8xxxu_load_firmware take const char*

Quoted 10 lines

-----Original Message-----
From: Bitterblue Smith <[email protected]>
Sent: Saturday, December 17, 2022 10:14 PM
To: [email protected]
Cc: Jes Sorensen <[email protected]>; Ping-Ke Shih <[email protected]>; Andrea Merello <[email protected]>; Taehee Yoo <[email protected]>
Subject: [PATCH v3 2/5] wifi: rtl8xxxu: Make rtl8xxxu_load_firmware take const char*

Quoted 3 lines

And pass const char* to it.

Quoted 16 lines

---
v3:
- No change.

v2:
- Patch is new in v2.

---
 drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h       | 2 +-
 drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188f.c | 2 +-
 drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192c.c | 2 +-
 drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c | 2 +-
 drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723a.c | 2 +-
 drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723b.c | 2 +-
 drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c  | 2 +-
 7 files changed, 7 insertions(+), 7 deletions(-)

[...]

#3 lore raw

PATCH v3 3/5 wifi: rtl8xxxu: Define masks for cck_agc_rpt bits

In reply to Bitterblue Smith

Define the constants CCK_AGC_RPT_LNA_IDX_MASK and CCK_AGC_RPT_VGA_IDX_MASK instead of using the same literals in four places.

And get the bits from cck_agc_rpt using u8_get_bits().

It's a cosmetic change only.

---
v3:
- No change.

v2:
- Patch is new in v2.

---
 drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h       | 3 +++
 drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188f.c | 4 ++--
 drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c | 4 ++--
 drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723b.c | 4 ++--
 4 files changed, 9 insertions(+), 6 deletions(-)
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h +3 -0
index 87758295d618..15bb2b5211a8 100644
@@ -562,6 +562,9 @@ struct phy_rx_agc_info {
 #endif
 };
 
+#define CCK_AGC_RPT_LNA_IDX_MASK	GENMASK(7, 5)
+#define CCK_AGC_RPT_VGA_IDX_MASK	GENMASK(4, 0)
+
 struct rtl8723au_phy_stats {
 	struct phy_rx_agc_info path_agc[RTL8723A_MAX_RF_PATHS];
 	u8	ch_corr[RTL8723A_MAX_RF_PATHS];
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188f.c +2 -2
index 94fc4647075a..54e136c964b4 100644
@@ -1682,8 +1682,8 @@ static s8 rtl8188f_cck_rssi(struct rtl8xxxu_priv *priv, u8 cck_agc_rpt)
 	s8 rx_pwr_all = 0x00;
 	u8 vga_idx, lna_idx;
 
-	lna_idx = (cck_agc_rpt & 0xE0) >> 5;
-	vga_idx = cck_agc_rpt & 0x1F;
+	lna_idx = u8_get_bits(cck_agc_rpt, CCK_AGC_RPT_LNA_IDX_MASK);
+	vga_idx = u8_get_bits(cck_agc_rpt, CCK_AGC_RPT_VGA_IDX_MASK);
 
 	switch (lna_idx) {
 	case 7:
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c +2 -2
index c769d0eaa03c..7ec6d8fb3c2b 100644
@@ -1717,8 +1717,8 @@ static s8 rtl8192e_cck_rssi(struct rtl8xxxu_priv *priv, u8 cck_agc_rpt)
 	u8 vga_idx, lna_idx;
 	s8 lna_gain = 0;
 
-	lna_idx = (cck_agc_rpt & 0xE0) >> 5;
-	vga_idx = cck_agc_rpt & 0x1F;
+	lna_idx = u8_get_bits(cck_agc_rpt, CCK_AGC_RPT_LNA_IDX_MASK);
+	vga_idx = u8_get_bits(cck_agc_rpt, CCK_AGC_RPT_VGA_IDX_MASK);
 
 	if (priv->cck_agc_report_type == 0)
 		lna_gain = lna_gain_table_0[lna_idx];
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723b.c +2 -2
index 65ebf9dcf5f9..0ed667d5ed25 100644
@@ -1680,8 +1680,8 @@ static s8 rtl8723b_cck_rssi(struct rtl8xxxu_priv *priv, u8 cck_agc_rpt)
 	s8 rx_pwr_all = 0x00;
 	u8 vga_idx, lna_idx;
 
-	lna_idx = (cck_agc_rpt & 0xE0) >> 5;
-	vga_idx = cck_agc_rpt & 0x1F;
+	lna_idx = u8_get_bits(cck_agc_rpt, CCK_AGC_RPT_LNA_IDX_MASK);
+	vga_idx = u8_get_bits(cck_agc_rpt, CCK_AGC_RPT_VGA_IDX_MASK);
 
 	switch (lna_idx) {
 	case 6:
Signature · 1 line
2.38.0
Reviewed-by on v3 3/5
#4 lore raw

RE: [PATCH v3 3/5] wifi: rtl8xxxu: Define masks for cck_agc_rpt bits

Quoted 14 lines

-----Original Message-----
From: Bitterblue Smith <[email protected]>
Sent: Saturday, December 17, 2022 10:15 PM
To: [email protected]
Cc: Jes Sorensen <[email protected]>; Ping-Ke Shih <[email protected]>; Andrea Merello <[email protected]>; Taehee Yoo <[email protected]>
Subject: [PATCH v3 3/5] wifi: rtl8xxxu: Define masks for cck_agc_rpt bits

Define the constants CCK_AGC_RPT_LNA_IDX_MASK and CCK_AGC_RPT_VGA_IDX_MASK instead of using the same literals in four places.

Quoted 5 lines

And get the bits from cck_agc_rpt using u8_get_bits().

It's a cosmetic change only.

Quoted 13 lines

---
v3:
- No change.

v2:
- Patch is new in v2.

---
 drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h       | 3 +++
 drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188f.c | 4 ++--
 drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c | 4 ++--
 drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723b.c | 4 ++--
 4 files changed, 9 insertions(+), 6 deletions(-)

[...]

#5 lore raw

PATCH v3 4/5 wifi: rtl8xxxu: Support new chip RTL8188EU

In reply to Bitterblue Smith

From: Jes Sorensen <[email protected]>

This chip is found in cheap USB devices from TP-Link, D-Link, etc.

Features: 2.4 GHz, b/g/n mode, 1T1R, 150 Mbps.

Chip versions older than "I cut" need software rate control. That will be in the next commit. Until then MCS7 is used for all data frames.

The "I cut" chips are not supported. They require different firmware and initialisation tables. Support can be added if someone has the hardware to test it.

---
So this patch is 52 of the 57 patches found here, squashed together:
https://git.kernel.org/pub/scm/linux/kernel/git/jes/linux.git/log/drivers/net/wireless/realtek/rtl8xxxu?h=rtl8xxxu-8188eu

Starting from c3f84ded6f76 ("rtl8xxxu: Accept firmware signature 0x88e0") up to a9b05c059510 ("rtl8xxxu: Add rpt_sel entry to struct rtl8xxxu_rxdesc16").

These patches were not needed:
3170622ccb61 ("rtl8xxxu: Detect 8188eu parts correctly") 8fb5bc92bce0 ("rtl8xxxu: Initialize GPIO settings for 8188eu") 6ab646adb585 ("rtl8xxxu: Implement rtl8188e_set_tx_power()") 2ccd1f1fc480 ("rtl8xxxu: properly detect RTL8188EU devices") 809a2e000cab ("rtl8xxxu: Do not set auto rate fallback on 8188eu")

On top of that, I made various changes required for today's kernel, plus changes to match the newer vendor driver more closely, plus some bug fixes.

v3:
- Implement suggestion from Ping-Ke Shih:
- Return -EOPNOTSUPP directly instead of using goto in

     rtl8188eu_identify_chip().

- Remove set but not used variable ht in rtl8188eu_config_channel().

v2:
- Implement suggestions from Ping-Ke Shih:
- Add __packed to struct rtl8188eu_efuse.
- Use u32p_replace_bits() in rtl8188eu_config_channel().
- Make fw_name const char*.
- Use the masks defined in patch 3/5 in rtl8188e_cck_rssi().
- Use u32_get_bits() in assignment to bit field priv->pi_enabled.
- Remove the efuse dumping code. It's not needed after patch 1/5.
- Update the module description.

---
 drivers/net/wireless/realtek/rtl8xxxu/Kconfig |    2 +-
 .../net/wireless/realtek/rtl8xxxu/Makefile    |    3 +-
 .../net/wireless/realtek/rtl8xxxu/rtl8xxxu.h  |   67 +-
 .../realtek/rtl8xxxu/rtl8xxxu_8188e.c         | 1280 +++++++++++++++++
 .../realtek/rtl8xxxu/rtl8xxxu_8188f.c         |    4 +-
 .../wireless/realtek/rtl8xxxu/rtl8xxxu_core.c |  201 ++-
 .../wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h |   40 +-
 7 files changed, 1572 insertions(+), 25 deletions(-)
 create mode 100644 drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188e.c
drivers/net/wireless/realtek/rtl8xxxu/Kconfig +1 -1
index 631d078278be..091d3ad98093 100644
@@ -10,7 +10,7 @@ config RTL8XXXU
 	  parts written to utilize the Linux mac80211 stack.
 	  The driver is known to work with a number of RTL8723AU,
 	  RL8188CU, RTL8188RU, RTL8191CU, RTL8192CU, RTL8723BU, RTL8192EU,
-	  and RTL8188FU devices.
+	  RTL8188FU, and RTL8188EU devices.
 
 	  This driver is under development and has a limited feature
 	  set. In particular it does not yet support 40MHz channels
drivers/net/wireless/realtek/rtl8xxxu/Makefile +2 -1
index c4ad5325f5e7..0cb58fb30228 100644
@@ -2,4 +2,5 @@
 obj-$(CONFIG_RTL8XXXU)	+= rtl8xxxu.o
 
 rtl8xxxu-y	:= rtl8xxxu_core.o rtl8xxxu_8192e.o rtl8xxxu_8723b.o \
-		   rtl8xxxu_8723a.o rtl8xxxu_8192c.o rtl8xxxu_8188f.o
+		   rtl8xxxu_8723a.o rtl8xxxu_8192c.o rtl8xxxu_8188f.o \
+		   rtl8xxxu_8188e.o
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h +65 -2

146 lines not on this page · raw message

drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188e.c new file +1280 -0

1,280 lines not on this page · raw message

drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188f.c +2 -2
index 54e136c964b4..63484ab1b4d7 100644
@@ -370,7 +370,7 @@ static void rtl8188f_channel_to_group(int channel, int *group, int *cck_group)
 		*cck_group = *group;
 }
 
-static void
+void
 rtl8188f_set_tx_power(struct rtl8xxxu_priv *priv, int channel, bool ht40)
 {
 	u32 val32, ofdm, mcs;
@@ -1651,7 +1651,7 @@ static void rtl8188f_usb_quirks(struct rtl8xxxu_priv *priv)
 #define XTAL1	GENMASK(22, 17)
 #define XTAL0	GENMASK(16, 11)
 
-static void rtl8188f_set_crystal_cap(struct rtl8xxxu_priv *priv, u8 crystal_cap)
+void rtl8188f_set_crystal_cap(struct rtl8xxxu_priv *priv, u8 crystal_cap)
 {
 	struct rtl8xxxu_cfo_tracking *cfo = &priv->cfo_tracking;
 	u32 val32;
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c +184 -17

322 lines not on this page · raw message

drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h +38 -2
index 3e79efdfb4c2..5818b2378bab 100644
@@ -371,6 +371,11 @@
 #define  PBP_PAGE_SIZE_512		0x3
 #define  PBP_PAGE_SIZE_1024		0x4
 
+/* 8188eu IOL magic */
+#define REG_PKT_BUF_ACCESS_CTRL		0x0106
+#define  PKT_BUF_ACCESS_CTRL_TX		0x69
+#define  PKT_BUF_ACCESS_CTRL_RX		0xa5
+
 #define REG_TRXDMA_CTRL			0x010c
 #define  TRXDMA_CTRL_RXDMA_AGG_EN	BIT(2)
 #define  TRXDMA_CTRL_VOQ_SHIFT		4
@@ -407,6 +412,8 @@
 #define REG_MBIST_START			0x0174
 #define REG_MBIST_DONE			0x0178
 #define REG_MBIST_FAIL			0x017c
+/* 8188EU */
+#define REG_32K_CTRL			0x0194
 #define REG_C2HEVT_MSG_NORMAL		0x01a0
 /* 8192EU/8723BU/8812 */
 #define REG_C2HEVT_CMD_ID_8723B		0x01ae
@@ -942,6 +949,16 @@
 #define REG_FPGA1_RF_MODE		0x0900
 
 #define REG_FPGA1_TX_INFO		0x090c
+#define  FPGA1_TX_ANT_MASK		0x0000000f
+#define  FPGA1_TX_ANT_L_MASK		0x000000f0
+#define  FPGA1_TX_ANT_NON_HT_MASK	0x00000f00
+#define  FPGA1_TX_ANT_HT1_MASK		0x0000f000
+#define  FPGA1_TX_ANT_HT2_MASK		0x000f0000
+#define  FPGA1_TX_ANT_HT_S1_MASK	0x00f00000
+#define  FPGA1_TX_ANT_NON_HT_S1_MASK	0x0f000000
+#define  FPGA1_TX_OFDM_TXSC_MASK	0x30000000
+
+#define REG_ANT_MAPPING1		0x0914
 #define REG_DPDT_CTRL			0x092c	/* 8723BU */
 #define REG_RFE_CTRL_ANTA_SRC		0x0930	/* 8723BU */
 #define REG_RFE_PATH_SELECT		0x0940	/* 8723BU */
@@ -954,9 +971,25 @@
 
 #define REG_CCK0_AFE_SETTING		0x0a04
 #define  CCK0_AFE_RX_MASK		0x0f000000
-#define  CCK0_AFE_RX_ANT_AB		BIT(24)
+#define  CCK0_AFE_TX_MASK		0xf0000000
 #define  CCK0_AFE_RX_ANT_A		0
-#define  CCK0_AFE_RX_ANT_B		(BIT(24) | BIT(26))
+#define  CCK0_AFE_RX_ANT_B		BIT(26)
+#define  CCK0_AFE_RX_ANT_C		BIT(27)
+#define  CCK0_AFE_RX_ANT_D		(BIT(26) | BIT(27))
+#define  CCK0_AFE_RX_ANT_OPTION_A	0
+#define  CCK0_AFE_RX_ANT_OPTION_B	BIT(24)
+#define  CCK0_AFE_RX_ANT_OPTION_C	BIT(25)
+#define  CCK0_AFE_RX_ANT_OPTION_D	(BIT(24) | BIT(25))
+#define  CCK0_AFE_TX_ANT_A		BIT(31)
+#define  CCK0_AFE_TX_ANT_B		BIT(30)
+
+#define REG_CCK_ANTDIV_PARA2		0x0a04
+#define REG_BB_POWER_SAVE4		0x0a74
+
+/* 8188eu */
+#define REG_LNA_SWITCH			0x0b2c
+#define  LNA_SWITCH_DISABLE_CSCG	BIT(22)
+#define  LNA_SWITCH_OUTPUT_CG		BIT(31)
 
 #define REG_CCK_PD_THRESH			0x0a0a
 #define  CCK_PD_TYPE1_LV0_TH		0x40
@@ -1020,6 +1053,9 @@
 
 #define REG_OFDM0_RX_IQ_EXT_ANTA	0x0ca0
 
+/* 8188eu */
+#define REG_ANTDIV_PARA1		0x0ca4
+
 /* 8723bu */
 #define REG_OFDM0_TX_PSDO_NOISE_WEIGHT	0x0ce4
 
Signature · 1 line
2.38.0
Reviewed-by on v3 4/5
#6 lore raw

RE: [PATCH v3 4/5] wifi: rtl8xxxu: Support new chip RTL8188EU

Quoted 23 lines

-----Original Message-----
From: Bitterblue Smith <[email protected]>
Sent: Saturday, December 17, 2022 10:18 PM
To: [email protected]
Cc: Jes Sorensen <[email protected]>; Ping-Ke Shih <[email protected]>; Andrea Merello <[email protected]>; Taehee Yoo <[email protected]>
Subject: [PATCH v3 4/5] wifi: rtl8xxxu: Support new chip RTL8188EU

From: Jes Sorensen <[email protected]>

This chip is found in cheap USB devices from TP-Link, D-Link, etc.

Features: 2.4 GHz, b/g/n mode, 1T1R, 150 Mbps.

Chip versions older than "I cut" need software rate control. That will be in the next commit. Until then MCS7 is used for all data frames.

The "I cut" chips are not supported. They require different firmware and initialisation tables. Support can be added if someone has the hardware to test it.

Quoted 7 lines
Quoted 46 lines

---
So this patch is 52 of the 57 patches found here, squashed together:
https://git.kernel.org/pub/scm/linux/kernel/git/jes/linux.git/log/drivers/net/wireless/realtek/rtl8xxx
u?h=rtl8xxxu-8188eu

Starting from c3f84ded6f76 ("rtl8xxxu: Accept firmware signature 0x88e0") up to a9b05c059510 ("rtl8xxxu: Add rpt_sel entry to struct rtl8xxxu_rxdesc16").

These patches were not needed:
3170622ccb61 ("rtl8xxxu: Detect 8188eu parts correctly") 8fb5bc92bce0 ("rtl8xxxu: Initialize GPIO settings for 8188eu") 6ab646adb585 ("rtl8xxxu: Implement rtl8188e_set_tx_power()") 2ccd1f1fc480 ("rtl8xxxu: properly detect RTL8188EU devices") 809a2e000cab ("rtl8xxxu: Do not set auto rate fallback on 8188eu")

On top of that, I made various changes required for today's kernel, plus changes to match the newer vendor driver more closely, plus some bug fixes.

v3:
- Implement suggestion from Ping-Ke Shih:
- Return -EOPNOTSUPP directly instead of using goto in

     rtl8188eu_identify_chip().

- Remove set but not used variable ht in rtl8188eu_config_channel().

v2:
- Implement suggestions from Ping-Ke Shih:
- Add __packed to struct rtl8188eu_efuse.
- Use u32p_replace_bits() in rtl8188eu_config_channel().
- Make fw_name const char*.
- Use the masks defined in patch 3/5 in rtl8188e_cck_rssi().
- Use u32_get_bits() in assignment to bit field priv->pi_enabled.
- Remove the efuse dumping code. It's not needed after patch 1/5.
- Update the module description.

---
 drivers/net/wireless/realtek/rtl8xxxu/Kconfig |    2 +-
 .../net/wireless/realtek/rtl8xxxu/Makefile    |    3 +-
 .../net/wireless/realtek/rtl8xxxu/rtl8xxxu.h  |   67 +-
 .../realtek/rtl8xxxu/rtl8xxxu_8188e.c         | 1280 +++++++++++++++++
 .../realtek/rtl8xxxu/rtl8xxxu_8188f.c         |    4 +-
 .../wireless/realtek/rtl8xxxu/rtl8xxxu_core.c |  201 ++-
 .../wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h |   40 +-
 7 files changed, 1572 insertions(+), 25 deletions(-)
 create mode 100644 drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188e.c

[...]

#7 lore raw

PATCH v3 5/5 wifi: rtl8xxxu: Add rate control code for RTL8188EU

In reply to Bitterblue Smith

Copied from the newer vendor driver, v5.2.2.4.

---
v3:
- Implement suggestions from Ping-Ke Shih:
- Remove unnecessary assignment in rtl8188e_power_training_try_state().
- Use >>= in rtl8188e_power_training_decision().
- Remove empty line in rtl8188e_handle_ra_tx_report2().
- Move closing parenthesis in rtl8xxxu_parse_rxdesc16().
- Remove unused arrays retry_penalty_up and trying_necessary.

v2:
- Implement suggestions from Ping-Ke Shih:
- Add missing break in two switch statements.
- Remove unnecessary initialisation of idx in rtl8188e_set_tx_rpt_timing().

---
 .../net/wireless/realtek/rtl8xxxu/rtl8xxxu.h  |  39 ++
 .../realtek/rtl8xxxu/rtl8xxxu_8188e.c         | 590 +++++++++++++++++-
 .../wireless/realtek/rtl8xxxu/rtl8xxxu_core.c | 130 +++-
 3 files changed, 729 insertions(+), 30 deletions(-)
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h +39 -0
index 29f5dbee16b0..be9479f969b7 100644
@@ -531,6 +531,7 @@ struct rtl8xxxu_txdesc40 {
 #define TXDESC32_CTS_SELF_ENABLE	BIT(11)
 #define TXDESC32_RTS_CTS_ENABLE		BIT(12)
 #define TXDESC32_HW_RTS_ENABLE		BIT(13)
+#define TXDESC32_PT_STAGE_MASK		GENMASK(17, 15)
 #define TXDESC_PRIME_CH_OFF_LOWER	BIT(20)
 #define TXDESC_PRIME_CH_OFF_UPPER	BIT(21)
 #define TXDESC32_SHORT_PREAMBLE		BIT(24)
@@ -1376,6 +1377,39 @@ struct rtl8xxxu_ra_report {
 	u8 desc_rate;
 };
 
+struct rtl8xxxu_ra_info {
+	u8 rate_id;
+	u32 rate_mask;
+	u32 ra_use_rate;
+	u8 rate_sgi;
+	u8 rssi_sta_ra;		/* Percentage */
+	u8 pre_rssi_sta_ra;
+	u8 sgi_enable;
+	u8 decision_rate;
+	u8 pre_rate;
+	u8 highest_rate;
+	u8 lowest_rate;
+	u32 nsc_up;
+	u32 nsc_down;
+	u32 total;
+	u16 retry[5];
+	u16 drop;
+	u16 rpt_time;
+	u16 pre_min_rpt_time;
+	u8 dynamic_tx_rpt_timing_counter;
+	u8 ra_waiting_counter;
+	u8 ra_pending_counter;
+	u8 ra_drop_after_down;
+	u8 pt_try_state;	/* 0 trying state, 1 for decision state */
+	u8 pt_stage;		/* 0~6 */
+	u8 pt_stop_count;	/* Stop PT counter */
+	u8 pt_pre_rate;		/* if rate change do PT */
+	u8 pt_pre_rssi;		/* if RSSI change 5% do PT */
+	u8 pt_mode_ss;		/* decide which rate should do PT */
+	u8 ra_stage;		/* StageRA, decide how many times RA will be done between PT */
+	u8 pt_smooth_factor;
+};
+
 #define CFO_TH_XTAL_HIGH	20 /* kHz */
 #define CFO_TH_XTAL_LOW	10 /* kHz */
 #define CFO_TH_ATC		80 /* kHz */
@@ -1509,6 +1543,7 @@ struct rtl8xxxu_priv {
 	struct rtl8xxxu_btcoex bt_coex;
 	struct rtl8xxxu_ra_report ra_report;
 	struct rtl8xxxu_cfo_tracking cfo_tracking;
+	struct rtl8xxxu_ra_info ra_info;
 };
 
 struct rtl8xxxu_rx_urb {
@@ -1684,6 +1719,10 @@ void rtl8723bu_phy_init_antenna_selection(struct rtl8xxxu_priv *priv);
 void rtl8723a_set_crystal_cap(struct rtl8xxxu_priv *priv, u8 crystal_cap);
 void rtl8188f_set_crystal_cap(struct rtl8xxxu_priv *priv, u8 crystal_cap);
 s8 rtl8723a_cck_rssi(struct rtl8xxxu_priv *priv, u8 cck_agc_rpt);
+void rtl8xxxu_update_ra_report(struct rtl8xxxu_ra_report *rarpt,
+			       u8 rate, u8 sgi, u8 bw);
+void rtl8188e_ra_info_init_all(struct rtl8xxxu_ra_info *ra);
+void rtl8188e_handle_ra_tx_report2(struct rtl8xxxu_priv *priv, struct sk_buff *skb);
 
 extern struct rtl8xxxu_fileops rtl8188fu_fops;
 extern struct rtl8xxxu_fileops rtl8188eu_fops;
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188e.c +589 -1

608 lines not on this page · raw message

drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c +101 -29

201 lines not on this page · raw message

Signature · 1 line
2.38.0
Reviewed-by on v3 5/5
#8 lore raw

RE: [PATCH v3 5/5] wifi: rtl8xxxu: Add rate control code for RTL8188EU

Quoted 10 lines

-----Original Message-----
From: Bitterblue Smith <[email protected]>
Sent: Saturday, December 17, 2022 10:22 PM
To: [email protected]
Cc: Jes Sorensen <[email protected]>; Ping-Ke Shih <[email protected]>; Andrea Merello <[email protected]>; Taehee Yoo <[email protected]>
Subject: [PATCH v3 5/5] wifi: rtl8xxxu: Add rate control code for RTL8188EU

Quoted 3 lines

Copied from the newer vendor driver, v5.2.2.4.

Quoted 20 lines

---
v3:
- Implement suggestions from Ping-Ke Shih:
- Remove unnecessary assignment in rtl8188e_power_training_try_state().
- Use >>= in rtl8188e_power_training_decision().
- Remove empty line in rtl8188e_handle_ra_tx_report2().
- Move closing parenthesis in rtl8xxxu_parse_rxdesc16().
- Remove unused arrays retry_penalty_up and trying_necessary.

v2:
- Implement suggestions from Ping-Ke Shih:
- Add missing break in two switch statements.
- Remove unnecessary initialisation of idx in rtl8188e_set_tx_rpt_timing().

---
 .../net/wireless/realtek/rtl8xxxu/rtl8xxxu.h  |  39 ++
 .../realtek/rtl8xxxu/rtl8xxxu_8188e.c         | 590 +++++++++++++++++-
 .../wireless/realtek/rtl8xxxu/rtl8xxxu_core.c | 130 +++-
 3 files changed, 729 insertions(+), 30 deletions(-)

[...]

Reviewed-by on v3 1/5
#9 lore raw
In reply to Bitterblue Smith
Quoted 14 lines

-----Original Message-----
From: Bitterblue Smith <[email protected]>
Sent: Saturday, December 17, 2022 10:12 PM
To: [email protected]
Cc: Jes Sorensen <[email protected]>; Ping-Ke Shih <[email protected]>; Andrea Merello <[email protected]>; Taehee Yoo <[email protected]>
Subject: [PATCH v3 1/5] wifi: rtl8xxxu: Deduplicate the efuse dumping code

Every chip family except RTL8723AU has a copy of the efuse dumping code. Remove this and dump the efuse from a single place using a new function rtl8xxxu_dump_efuse().

Quoted 5 lines

Also, use print_hex_dump() to print the efuse instead of a loop and dev_info(). It shows the ASCII interpretation of the bytes, which is nice.

Quoted 16 lines

---
v3:
- Implement suggestion from Ping-Ke Shih:
- Use EFUSE_MAP_LEN instead of EFUSE_REAL_CONTENT_LEN_8723A. They have the same value.

v2:
- Patch is new in v2.

---
 .../net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188f.c  | 11 -----------
 .../net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192c.c  | 10 ----------
 .../net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c  |  9 ---------
 .../net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723b.c  | 11 -----------
 .../net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c   | 13 +++++++++++++
 5 files changed, 13 insertions(+), 41 deletions(-)

[...]

#10 lore raw
In reply to Bitterblue Smith
Quoted 10 lines · Bitterblue Smith

Every chip family except RTL8723AU has a copy of the efuse dumping code. Remove this and dump the efuse from a single place using a new function rtl8xxxu_dump_efuse().

Also, use print_hex_dump() to print the efuse instead of a loop and dev_info(). It shows the ASCII interpretation of the bytes, which is nice.

5 patches applied to wireless-next.git, thanks.

4f198e720eab wifi: rtl8xxxu: Deduplicate the efuse dumping code d7a3705c9634 wifi: rtl8xxxu: Make rtl8xxxu_load_firmware take const char* b75289e89459 wifi: rtl8xxxu: Define masks for cck_agc_rpt bits 3dfb8e844fa3 wifi: rtl8xxxu: Support new chip RTL8188EU 8b9754b28f0f wifi: rtl8xxxu: Add rate control code for RTL8188EU

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches