wifi: rtl8xxxu: Support new chip RTL8710BU aka RTL8188GU
PATCH v3 1/1 wifi: rtl8xxxu: Support new chip RTL8710BU aka RTL8188GU
This chip is found in cheap "free driver" USB adapters from Aliexpress. Initially they pretend to be a CD-ROM containing the driver for Windows. "Ejecting" switches the device to wifi mode.
Features: 2.4 GHz, b/g/n mode, 1T1R, 150 Mbps.
This chip is more unique than other Realtek chips:
* The registers at addresses 0x0-0xff, which all the other chips use, can't be used here. New registers at 0x8000-0x80ff must be used instead. And it's not a simple matter of adding 0x8000: 0x2 (REG_SYS_FUNC) became 0x8004, 0x80 (REG_MCU_FW_DL) became 0x8090, etc.
* Also there are a few new registers which must be accessed indirectly because their addresses don't fit in 16 bits. No other chips seem to have these.
* The vendor driver compiles to 8188gu.ko, but the code calls the chip RTL8710B(U) pretty much everywhere, including messages visible to the user.
Another difference compared to the other chips supported by rtl8xxxu is that it has a new PHY status struct, or three of them actually, from which we extract the RSSI, among other things. This is not unique, though, just new. The chips supported by rtw88 also use it.
---
v3:
- Suggestions from Ping-Ke Shih:
- Use IS_ALIGNED macro in rtl8710b_indirect_read32() and
rtl8710b_indirect_write32().
- Initialise sec_ch_above in rtl8710bu_config_channel() and move an if statement in rtl8710bu_phy_iq_calibrate() in order to silence warnings about possibly uninitialised variables.
v2:
- Suggestions from Ping-Ke Shih:
- Add comma after the last member of enum rtl8xxxu_rtl_chip.
- Add comment about struct mutex syson_indirect_access_mutex.
- Declare variables in reverse Christmas tree order in
rtl8710b_read_efuse().
- Remove unnecessary variable ret from rtl8710bu_identify_chip().
- Add definition for register 0xaac.
- Use the existing macros REG_SYS_FUNC, SYS_FUNC_BBRSTB, and SYS_FUNC_BB_GLB_RSTN instead of magic numbers in rtl8710bu_active_to_lps().
- Declare reg_mcu_fw_dl separately in rtl8xxxu_download_firmware().
- Add spaces after /* and before */ in some comments.
- Rearrange the declarations in rtl8710b_read_efuse8() as well.
- Load the right firmware based on the chip manufacturer (UMC/SMIC).
- Use the mask 0xc0 instead of 0xf0 to detect the chip manufacturer in rtl8710bu_identify_chip(). There was an extra shift in the vendor driver which I missed.
- Make the vid and pid fields of struct rtl8710bu_efuse two bytes each, and the filler field res7 one byte shorter.
- I was lazy and didn't do some things the right way in v1. I thought surely there are no more chips to support. But since then I discovered that the RTL8192FU can be bought from Aliexpress for 6.66 $. 😄 It will need the same PHY status parsing as the RTL8710BU, which is why there are these extra changes:
- Initialise priv->cck_new_agc in rtl8xxxu_init_device() always, regardless of the chip family.
- Pass the PHY status structs to the CCK RSSI functions.
- Move the "old AGC" CCK RSSI calculation from rtl8710bu_rx_parse_phystats_type0() to a new function rtl8710b_cck_rssi().
- Rename the functions rtl8710bu_rx_parse_phystats* to jaguar2_rx_parse_phystats* and move them to rtl8xxxu_core.c.
- Modify the functions jaguar2_rx_parse_phystats_type{1,2} to handle 2T2R chips as well.
--- drivers/net/wireless/realtek/rtl8xxxu/Kconfig | 2 +- .../net/wireless/realtek/rtl8xxxu/Makefile | 2 +- .../net/wireless/realtek/rtl8xxxu/rtl8xxxu.h | 313 ++- .../realtek/rtl8xxxu/rtl8xxxu_8188e.c | 5 +- .../realtek/rtl8xxxu/rtl8xxxu_8188f.c | 7 +- .../realtek/rtl8xxxu/rtl8xxxu_8192c.c | 2 + .../realtek/rtl8xxxu/rtl8xxxu_8192e.c | 5 +- .../realtek/rtl8xxxu/rtl8xxxu_8710b.c | 1878 +++++++++++++++++ .../realtek/rtl8xxxu/rtl8xxxu_8723a.c | 5 +- .../realtek/rtl8xxxu/rtl8xxxu_8723b.c | 5 +- .../wireless/realtek/rtl8xxxu/rtl8xxxu_core.c | 275 ++- .../wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h | 44 + 12 files changed, 2481 insertions(+), 62 deletions(-) create mode 100644 drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c
drivers/net/wireless/realtek/rtl8xxxu/Kconfig +1 -1
@@ -11,7 +11,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, - RTL8188FU, and RTL8188EU devices. + RTL8188FU, RTL8188EU, and RTL8710BU (aka RTL8188GU) 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 +1 -1
@@ -3,4 +3,4 @@ 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_8188e.o + rtl8xxxu_8188e.o rtl8xxxu_8710b.o
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h +310 -3
400 lines not on this page · raw message
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188e.c +4 -1
@@ -1326,13 +1326,14 @@ static void rtl8188e_usb_quirks(struct rtl8xxxu_priv *priv)rtl8xxxu_write8 (priv,REG_EARLY_MODE_CONTROL_8188E +3 ,0x01 ); } -static s8 rtl8188e_cck_rssi (struct rtl8xxxu_priv *priv,u8 cck_agc_rpt) +static s8 rtl8188e_cck_rssi (struct rtl8xxxu_priv *priv,struct rtl8723au_phy_stats *phy_stats) {/* only use lna 0/1/2/3/7 */ static const s8 lna_gain_table_0[8 ] = {17 ,-1 ,-13 ,-29 ,-32 ,-35 ,-38 ,-41 };/* only use lna 3/7 */ static const s8 lna_gain_table_1[8 ] = {29 ,20 ,12 ,3 ,-6 ,-15 ,-24 ,-33 }; +u8 cck_agc_rpt = phy_stats->cck_agc_rpt_ofdm_cfosho_a;s8 rx_pwr_all =0x00 ;u8 vga_idx, lna_idx;s8 lna_gain =0 ;
@@ -1856,6 +1857,7 @@ struct rtl8xxxu_fileops rtl8188eu_fops = { .load_firmware = rtl8188eu_load_firmware, .power_on = rtl8188eu_power_on, .power_off = rtl8188eu_power_off, + .read_efuse = rtl8xxxu_read_efuse, .reset_8051 = rtl8188eu_reset_8051, .llt_init = rtl8xxxu_init_llt_table, .init_phy_bb = rtl8188eu_init_phy_bb,
@@ -1864,6 +1866,7 @@ struct rtl8xxxu_fileops rtl8188eu_fops = { .phy_iq_calibrate = rtl8188eu_phy_iq_calibrate, .config_channel = rtl8188eu_config_channel, .parse_rx_desc = rtl8xxxu_parse_rxdesc16, + .parse_phystats = rtl8723au_rx_parse_phystats, .init_aggregation = rtl8188eu_init_aggregation, .enable_rf = rtl8188e_enable_rf, .disable_rf = rtl8188e_disable_rf,
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188f.c +5 -2
@@ -791,7 +791,7 @@ static int rtl8188fu_init_phy_rf(struct rtl8xxxu_priv *priv)return ret; } -static void rtl8188f_phy_lc_calibrate (struct rtl8xxxu_priv *priv) +void rtl8188f_phy_lc_calibrate (struct rtl8xxxu_priv *priv) {u32 val32;u32 rf_amode, lstf;
@@ -1677,8 +1677,9 @@ void rtl8188f_set_crystal_cap(struct rtl8xxxu_priv *priv, u8 crystal_cap) cfo->crystal_cap = crystal_cap; } -static s8 rtl8188f_cck_rssi (struct rtl8xxxu_priv *priv,u8 cck_agc_rpt) +static s8 rtl8188f_cck_rssi (struct rtl8xxxu_priv *priv,struct rtl8723au_phy_stats *phy_stats) { +u8 cck_agc_rpt = phy_stats->cck_agc_rpt_ofdm_cfosho_a;s8 rx_pwr_all =0x00 ;u8 vga_idx, lna_idx;
@@ -1714,6 +1715,7 @@ struct rtl8xxxu_fileops rtl8188fu_fops = { .load_firmware = rtl8188fu_load_firmware, .power_on = rtl8188fu_power_on, .power_off = rtl8188fu_power_off, + .read_efuse = rtl8xxxu_read_efuse, .reset_8051 = rtl8xxxu_reset_8051, .llt_init = rtl8xxxu_auto_llt_table, .init_phy_bb = rtl8188fu_init_phy_bb,
@@ -1723,6 +1725,7 @@ struct rtl8xxxu_fileops rtl8188fu_fops = { .phy_iq_calibrate = rtl8188fu_phy_iq_calibrate, .config_channel = rtl8188fu_config_channel, .parse_rx_desc = rtl8xxxu_parse_rxdesc24, + .parse_phystats = rtl8723au_rx_parse_phystats, .init_aggregation = rtl8188fu_init_aggregation, .init_statistics = rtl8188fu_init_statistics, .init_burst = rtl8xxxu_init_burst,
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192c.c +2 -0
@@ -594,6 +594,7 @@ struct rtl8xxxu_fileops rtl8192cu_fops = { .load_firmware = rtl8192cu_load_firmware, .power_on = rtl8192cu_power_on, .power_off = rtl8xxxu_power_off, + .read_efuse = rtl8xxxu_read_efuse, .reset_8051 = rtl8xxxu_reset_8051, .llt_init = rtl8xxxu_init_llt_table, .init_phy_bb = rtl8xxxu_gen1_init_phy_bb,
@@ -602,6 +603,7 @@ struct rtl8xxxu_fileops rtl8192cu_fops = { .phy_iq_calibrate = rtl8xxxu_gen1_phy_iq_calibrate, .config_channel = rtl8xxxu_gen1_config_channel, .parse_rx_desc = rtl8xxxu_parse_rxdesc16, + .parse_phystats = rtl8723au_rx_parse_phystats, .init_aggregation = rtl8xxxu_gen1_init_aggregation, .enable_rf = rtl8xxxu_gen1_enable_rf, .disable_rf = rtl8xxxu_gen1_disable_rf,
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c +4 -1
@@ -1742,11 +1742,12 @@ static void rtl8192e_enable_rf(struct rtl8xxxu_priv *priv)rtl8xxxu_write8 (priv,REG_TXPAUSE ,0x00 ); } -static s8 rtl8192e_cck_rssi (struct rtl8xxxu_priv *priv,u8 cck_agc_rpt) +static s8 rtl8192e_cck_rssi (struct rtl8xxxu_priv *priv,struct rtl8723au_phy_stats *phy_stats) {static const s8 lna_gain_table_0[8 ] = {15 ,9 ,-10 ,-21 ,-23 ,-27 ,-43 ,-44 };static const s8 lna_gain_table_1[8 ] = {24 ,18 ,13 ,-4 ,-11 ,-18 ,-31 ,-36 }; +u8 cck_agc_rpt = phy_stats->cck_agc_rpt_ofdm_cfosho_a;s8 rx_pwr_all =0x00 ;u8 vga_idx, lna_idx;s8 lna_gain =0 ;
@@ -1793,6 +1794,7 @@ struct rtl8xxxu_fileops rtl8192eu_fops = { .load_firmware = rtl8192eu_load_firmware, .power_on = rtl8192eu_power_on, .power_off = rtl8192eu_power_off, + .read_efuse = rtl8xxxu_read_efuse, .reset_8051 = rtl8xxxu_reset_8051, .llt_init = rtl8xxxu_auto_llt_table, .init_phy_bb = rtl8192eu_init_phy_bb,
@@ -1801,6 +1803,7 @@ struct rtl8xxxu_fileops rtl8192eu_fops = { .phy_iq_calibrate = rtl8192eu_phy_iq_calibrate, .config_channel = rtl8xxxu_gen2_config_channel, .parse_rx_desc = rtl8xxxu_parse_rxdesc24, + .parse_phystats = rtl8723au_rx_parse_phystats, .enable_rf = rtl8192e_enable_rf, .disable_rf = rtl8xxxu_gen2_disable_rf, .usb_quirks = rtl8xxxu_gen2_usb_quirks,
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +1878 -0
1,878 lines not on this page · raw message
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723a.c +4 -1
@@ -435,8 +435,9 @@ void rtl8723a_set_crystal_cap(struct rtl8xxxu_priv *priv, u8 crystal_cap) cfo->crystal_cap = crystal_cap; } -s8 rtl8723a_cck_rssi (struct rtl8xxxu_priv *priv,u8 cck_agc_rpt) +s8 rtl8723a_cck_rssi (struct rtl8xxxu_priv *priv,struct rtl8723au_phy_stats *phy_stats) { +u8 cck_agc_rpt = phy_stats->cck_agc_rpt_ofdm_cfosho_a;s8 rx_pwr_all =0x00 ;switch (cck_agc_rpt &0xc0 ) {
@@ -487,6 +488,7 @@ struct rtl8xxxu_fileops rtl8723au_fops = { .load_firmware = rtl8723au_load_firmware, .power_on = rtl8723au_power_on, .power_off = rtl8xxxu_power_off, + .read_efuse = rtl8xxxu_read_efuse, .reset_8051 = rtl8xxxu_reset_8051, .llt_init = rtl8xxxu_init_llt_table, .init_phy_bb = rtl8xxxu_gen1_init_phy_bb,
@@ -495,6 +497,7 @@ struct rtl8xxxu_fileops rtl8723au_fops = { .phy_iq_calibrate = rtl8xxxu_gen1_phy_iq_calibrate, .config_channel = rtl8xxxu_gen1_config_channel, .parse_rx_desc = rtl8xxxu_parse_rxdesc16, + .parse_phystats = rtl8723au_rx_parse_phystats, .init_aggregation = rtl8xxxu_gen1_init_aggregation, .enable_rf = rtl8xxxu_gen1_enable_rf, .disable_rf = rtl8xxxu_gen1_disable_rf,
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723b.c +4 -1
@@ -1675,8 +1675,9 @@ static void rtl8723bu_init_statistics(struct rtl8xxxu_priv *priv)rtl8xxxu_write32 (priv,REG_OFDM0_FA_RSTC , val32); } -static s8 rtl8723b_cck_rssi (struct rtl8xxxu_priv *priv,u8 cck_agc_rpt) +static s8 rtl8723b_cck_rssi (struct rtl8xxxu_priv *priv,struct rtl8723au_phy_stats *phy_stats) { +u8 cck_agc_rpt = phy_stats->cck_agc_rpt_ofdm_cfosho_a;s8 rx_pwr_all =0x00 ;u8 vga_idx, lna_idx;
@@ -1709,6 +1710,7 @@ struct rtl8xxxu_fileops rtl8723bu_fops = { .load_firmware = rtl8723bu_load_firmware, .power_on = rtl8723bu_power_on, .power_off = rtl8723bu_power_off, + .read_efuse = rtl8xxxu_read_efuse, .reset_8051 = rtl8723bu_reset_8051, .llt_init = rtl8xxxu_auto_llt_table, .init_phy_bb = rtl8723bu_init_phy_bb,
@@ -1718,6 +1720,7 @@ struct rtl8xxxu_fileops rtl8723bu_fops = { .phy_iq_calibrate = rtl8723bu_phy_iq_calibrate, .config_channel = rtl8xxxu_gen2_config_channel, .parse_rx_desc = rtl8xxxu_parse_rxdesc24, + .parse_phystats = rtl8723au_rx_parse_phystats, .init_aggregation = rtl8723bu_init_aggregation, .init_statistics = rtl8723bu_init_statistics, .init_burst = rtl8xxxu_init_burst,
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c +224 -51
559 lines not on this page · raw message
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h +44 -0
44 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.39.2
Part of the diff is not shown here. View the raw message.
Quoted 31 lines
-----Original Message-----
From: Bitterblue Smith <[email protected]>
Sent: Monday, March 13, 2023 9:58 PM
To: [email protected]
Cc: Jes Sorensen <[email protected]>; Ping-Ke Shih <[email protected]>; Jiajie Chen <[email protected]>
Subject: [PATCH v3] wifi: rtl8xxxu: Support new chip RTL8710BU aka RTL8188GUThis chip is found in cheap "free driver" USB adapters from Aliexpress. Initially they pretend to be a CD-ROM containing the driver for Windows. "Ejecting" switches the device to wifi mode.
Features: 2.4 GHz, b/g/n mode, 1T1R, 150 Mbps.
This chip is more unique than other Realtek chips:
* The registers at addresses 0x0-0xff, which all the other chips use, can't be used here. New registers at 0x8000-0x80ff must be used instead. And it's not a simple matter of adding
0x8000:0x2(REG_SYS_FUNC) became0x8004,0x80(REG_MCU_FW_DL) became0x8090, etc.* Also there are a few new registers which must be accessed indirectly because their addresses don't fit in 16 bits. No other chips seem to have these.
* The vendor driver compiles to 8188gu.ko, but the code calls the chip RTL8710B(U) pretty much everywhere, including messages visible to the user.
Quoted 6 lines
Another difference compared to the other chips supported by rtl8xxxu is that it has a new PHY status struct, or three of them actually, from which we extract the RSSI, among other things. This is not unique, though, just new. The chips supported by rtw88 also use it.
Signed-off-by Bitterblue Smith <[email protected]>
Thanks for this nice work.
Quoted 22 lines · Bitterblue Smith
This chip is found in cheap "free driver" USB adapters from Aliexpress. Initially they pretend to be a CD-ROM containing the driver for Windows. "Ejecting" switches the device to wifi mode.
Features: 2.4 GHz, b/g/n mode, 1T1R, 150 Mbps.
This chip is more unique than other Realtek chips:
* The registers at addresses 0x0-0xff, which all the other chips use, can't be used here. New registers at 0x8000-0x80ff must be used instead. And it's not a simple matter of adding
0x8000:0x2(REG_SYS_FUNC) became0x8004,0x80(REG_MCU_FW_DL) became0x8090, etc.* Also there are a few new registers which must be accessed indirectly because their addresses don't fit in 16 bits. No other chips seem to have these.
* The vendor driver compiles to 8188gu.ko, but the code calls the chip RTL8710B(U) pretty much everywhere, including messages visible to the user.
Quoted 6 lines
Another difference compared to the other chips supported by rtl8xxxu is that it has a new PHY status struct, or three of them actually, from which we extract the RSSI, among other things. This is not unique, though, just new. The chips supported by rtw88 also use it.
Signed-off-by Bitterblue Smith <[email protected]>
Tested Chip: RTL8188EU
Quoted 22 lines · Bitterblue Smith
This chip is found in cheap "free driver" USB adapters from Aliexpress. Initially they pretend to be a CD-ROM containing the driver for Windows. "Ejecting" switches the device to wifi mode.
Features: 2.4 GHz, b/g/n mode, 1T1R, 150 Mbps.
This chip is more unique than other Realtek chips:
* The registers at addresses 0x0-0xff, which all the other chips use, can't be used here. New registers at 0x8000-0x80ff must be used instead. And it's not a simple matter of adding
0x8000:0x2(REG_SYS_FUNC) became0x8004,0x80(REG_MCU_FW_DL) became0x8090, etc.* Also there are a few new registers which must be accessed indirectly because their addresses don't fit in 16 bits. No other chips seem to have these.
* The vendor driver compiles to 8188gu.ko, but the code calls the chip RTL8710B(U) pretty much everywhere, including messages visible to the user.
Quoted 8 lines
Another difference compared to the other chips supported by rtl8xxxu is that it has a new PHY status struct, or three of them actually, from which we extract the RSSI, among other things. This is not unique, though, just new. The chips supported by rtw88 also use it.
Signed-off-by Bitterblue Smith <[email protected]>Reviewed-by Ping-Ke Shih <[email protected]>
Patch applied to wireless-next.git, thanks.
70664495e3d2 wifi: rtl8xxxu: Support new chip RTL8710BU aka RTL8188GU
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches