wifi: rtl8xxxu: Support new chip RTL8710BU aka RTL8188GU
PATCH 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.
This was tested with a device from vendor SMIC with romver 1. It's possible devices from vendor UMC and/or with romver 2 will fail to upload the firmware. The vendor driver has that problem.
--- drivers/net/wireless/realtek/rtl8xxxu/Kconfig | 2 +- .../net/wireless/realtek/rtl8xxxu/Makefile | 2 +- .../net/wireless/realtek/rtl8xxxu/rtl8xxxu.h | 304 ++- .../realtek/rtl8xxxu/rtl8xxxu_8188e.c | 2 + .../realtek/rtl8xxxu/rtl8xxxu_8188f.c | 4 +- .../realtek/rtl8xxxu/rtl8xxxu_8192c.c | 2 + .../realtek/rtl8xxxu/rtl8xxxu_8192e.c | 2 + .../realtek/rtl8xxxu/rtl8xxxu_8710b.c | 1942 +++++++++++++++++ .../realtek/rtl8xxxu/rtl8xxxu_8723a.c | 2 + .../realtek/rtl8xxxu/rtl8xxxu_8723b.c | 2 + .../wireless/realtek/rtl8xxxu/rtl8xxxu_core.c | 181 +- .../wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h | 43 + 12 files changed, 2435 insertions(+), 53 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 +303 -1
380 lines not on this page · raw message
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188e.c +2 -0
@@ -1856,6 +1856,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 +1865,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 +3 -1
@@ -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;
@@ -1714,6 +1714,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 +1724,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 +2 -0
@@ -1793,6 +1793,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 +1802,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 +1942 -0
1,942 lines not on this page · raw message
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723a.c +2 -0
@@ -487,6 +487,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 +496,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 +2 -0
@@ -1709,6 +1709,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 +1719,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 +132 -49
464 lines not on this page · raw message
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h +43 -0
73 lines not on this page · raw message
Signature · 1 line
2.39.1
Quoted 31 lines
-----Original Message-----
From: Bitterblue Smith <[email protected]>
Sent: Tuesday, February 21, 2023 12:11 AM
To: [email protected]
Cc: Jes Sorensen <[email protected]>; Ping-Ke Shih <[email protected]>
Subject: [PATCH] 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 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.
This was tested with a device from vendor SMIC with romver 1. It's possible devices from vendor UMC and/or with romver 2 will fail to upload the firmware. The vendor driver has that problem.
Can I know the version of vendor driver you use?
Quoted 18 lines
Signed-off-by Bitterblue Smith <[email protected]>--- drivers/net/wireless/realtek/rtl8xxxu/Kconfig | 2 +- .../net/wireless/realtek/rtl8xxxu/Makefile | 2 +- .../net/wireless/realtek/rtl8xxxu/rtl8xxxu.h | 304 ++- .../realtek/rtl8xxxu/rtl8xxxu_8188e.c | 2 + .../realtek/rtl8xxxu/rtl8xxxu_8188f.c | 4 +- .../realtek/rtl8xxxu/rtl8xxxu_8192c.c | 2 + .../realtek/rtl8xxxu/rtl8xxxu_8192e.c | 2 + .../realtek/rtl8xxxu/rtl8xxxu_8710b.c | 1942 +++++++++++++++++ .../realtek/rtl8xxxu/rtl8xxxu_8723a.c | 2 + .../realtek/rtl8xxxu/rtl8xxxu_8723b.c | 2 + .../wireless/realtek/rtl8xxxu/rtl8xxxu_core.c | 181 +- .../wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h | 43 + 12 files changed, 2435 insertions(+), 53 deletions(-) create mode 100644 drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c
[...]
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h enum rtl8xxxu_rtl_chip { · line 107
Quoted 12 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h +2
-1@@ -103,7 +103,8 @@ enum rtl8xxxu_rtl_chip {RTL8822B =0x8822b ,RTL8703B =0x8703b ,RTL8195A =0x8195a , -RTL8188F =0x8188f +RTL8188F =0x8188f , +RTL8710B =0x8710b
Add a trailing comma, and then you don't need to stir the last line when adding an new chip in the future.
[...]
Quoted 20 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h +2
-0struct rtl8xxxu_reg8val {u16 reg;u8 val;@@ -1486,6 +1769,7 @@ struct rtl8xxxu_priv {struct rtl8723au_idx ht20_tx_power_diff[RTL8723B_TX_COUNT ];struct rtl8723au_idx ht40_tx_power_diff[RTL8723B_TX_COUNT ];struct rtl8xxxu_power_base *power_base; +u8 package_type; u32 chip_cut:4; u32 rom_rev:4; u32 is_multi_func:1;@@ -1505,6 +1789,7 @@ struct rtl8xxxu_priv { u32 ep_tx_low_queue:1; u32 rx_buf_aggregation:1; u32 cck_agc_report_type:1; + u32 cck_new_agc:1;u8 default_crystal_cap;unsigned int pipe_interrupt;unsigned int pipe_in;
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h struct rtl8xxxu_priv { · line 1812
Quoted 5 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h +2
-0@@ -1523,6 +1808,8 @@ struct rtl8xxxu_priv {struct mutex h2c_mutex; +struct mutex syson_indirect_access_mutex; +
I remember checkpatch will warn if you don't add a comment for mutex/lock. Though the naming is clear, just follow the rule.
[...]
Quoted 6 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +0
-0
[...]
Quoted 10 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +10
-0+static u32 rtl8710b_indirect_read32 (struct rtl8xxxu_priv *priv,u32 addr) +{ +struct device *dev = &priv->udev->dev; +u32 val32, value =0xffffffff ; +u8 polling_count =0xff ; + +if (addr &3 ) { +dev_warn (dev,"%s: Aborting because 0x%x is not a multiple of 4.\n" , + __func__, addr); +return value;
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c line 498
Quoted 10 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +10
-0+ } + +mutex_lock (&priv->syson_indirect_access_mutex); + +rtl8xxxu_write32 (priv,REG_USB_HOST_INDIRECT_ADDR_8710B , addr); +rtl8xxxu_write32 (priv,REG_EFUSE_INDIRECT_CTRL_8710B ,NORMAL_REG_READ_OFFSET ); + +do + val32 =rtl8xxxu_read32 (priv,REG_EFUSE_INDIRECT_CTRL_8710B ); +while ((val32 &BIT (31 )) && (--polling_count >0 ));
Without a pair of brace, that looks a little odd to me, but the result should be correct.
[...]
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c line 592
Quoted 6 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +6
-0+static int rtl8710bu_identify_chip (struct rtl8xxxu_priv *priv) +{ +struct device *dev = &priv->udev->dev; +u32 cfg0, cfg2, vendor; +u8 package_type =0x7 ;/* a nonsense value */ +int ret =0 ;
No need '=0'. Even, don't need 'ret'.
Just return rtl8xxxu_config_endpoints_no_sie();
[...]
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c line 678
Quoted 13 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +13
-0+ + ret =rtl8xxxu_config_endpoints_no_sie (priv); + +return ret; +} + +static void rtl8710b_revise_cck_tx_psf (struct rtl8xxxu_priv *priv,u8 channel) +{ +if (channel ==13 ) { +/* Normal values */ +rtl8xxxu_write32 (priv,REG_CCK0_TX_FILTER2 ,0x64B80C1C ); +rtl8xxxu_write32 (priv,REG_CCK0_DEBUG_PORT ,0x00008810 ); +rtl8xxxu_write32 (priv,0xaac ,0x01235667 );
0xaac is another TX filter, so
#define REG_CCK0_TX_FILTER3 0x0aac
Quoted 18 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +18
-0+/* Special value for channel 13 */ +rtl8xxxu_write32 (priv,REG_CCK0_TX_FILTER1 ,0xd1d80001 ); + }else if (channel ==14 ) { +/* Special values for channel 14 */ +rtl8xxxu_write32 (priv,REG_CCK0_TX_FILTER2 ,0x0000B81C ); +rtl8xxxu_write32 (priv,REG_CCK0_DEBUG_PORT ,0x00000000 ); +rtl8xxxu_write32 (priv,0xaac ,0x00003667 ); +/* Normal value */ +rtl8xxxu_write32 (priv,REG_CCK0_TX_FILTER1 ,0xE82C0001 ); + }else { +/* Restore normal values from the phy init table */ +rtl8xxxu_write32 (priv,REG_CCK0_TX_FILTER2 ,0x64B80C1C ); +rtl8xxxu_write32 (priv,REG_CCK0_DEBUG_PORT ,0x00008810 ); +rtl8xxxu_write32 (priv,0xaac ,0x01235667 ); +rtl8xxxu_write32 (priv,REG_CCK0_TX_FILTER1 ,0xE82C0001 ); + } +} +
[...]
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c line 870
Quoted 4 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +4
-0+static int rtl8710b_read_efuse (struct rtl8xxxu_priv *priv) +{ +struct device *dev = &priv->udev->dev; +int i, ret =0 ;
move these two downward to 'val32'. Declarations should be in reverse Xmas tree order.
Quoted 8 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +8
-0+u8 val8, word_mask, header, extheader; +u16 efuse_addr, offset; +u32 val32; + + val32 =rtl8710b_read_syson_reg (priv,REG_SYS_EEPROM_CTRL0_8710B ); + priv->boot_eeprom =u32_get_bits (val32,EEPROM_BOOT ); + priv->has_eeprom =u32_get_bits (val32,EEPROM_ENABLE ); +
[...]
Quoted 25 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +25
-0+static int rtl8710bu_active_to_lps (struct rtl8xxxu_priv *priv) +{ +struct device *dev = &priv->udev->dev; +u8 val8; +u16 val16; +u32 val32; +int retry, retval; + +/* Tx Pause */ +rtl8xxxu_write8 (priv,REG_TXPAUSE ,0xff ); + + retry =100 ; + retval = -EBUSY ; +/* +* Poll 32 bit wide REG_SCH_TX_CMD for 0x00000000 to ensure no TX is pending. +*/ +do { + val32 =rtl8xxxu_read32 (priv,REG_SCH_TX_CMD ); +if (!val32) { + retval =0 ; +break ; + } +udelay (10 ); + }while (retry--); +
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c line 1597
Quoted 10 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +10
-0+if (!retry) { +dev_warn (dev,"Failed to flush TX queue\n" ); + retval = -EBUSY ; +return retval; + } + +/* Disable CCK and OFDM, clock gated */ + val8 =rtl8xxxu_read8 (priv,0x02 ); + val8 &= ~BIT (0 ); +rtl8xxxu_write8 (priv,0x02 , val8);
rtl8xxxu has already defined these:
#define REG_SYS_FUNC 0x0002
#define SYS_FUNC_BBRSTB BIT(0)
#define SYS_FUNC_BB_GLB_RSTN BIT(1)
Quoted 22 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +22
-0+ +udelay (2 ); + +/*Whole BB is reset*/ + val8 =rtl8xxxu_read8 (priv,0x02 ); + val8 &= ~BIT (1 ); +rtl8xxxu_write8 (priv,0x02 , val8); + +/* Reset MAC TRX */ + val16 =rtl8xxxu_read16 (priv,REG_CR ); + val16 &=0xff00 ; + val16 |=CR_HCI_RXDMA_ENABLE |CR_HCI_TXDMA_ENABLE ; + val16 &= ~CR_SECURITY_ENABLE ; +rtl8xxxu_write16 (priv,REG_CR , val16); + +/*Respond TxOK to scheduler*/ + val8 =rtl8xxxu_read8 (priv,REG_DUAL_TSF_RST ); + val8 |=DUAL_TSF_TX_OK ; +rtl8xxxu_write8 (priv,REG_DUAL_TSF_RST , val8); + +return retval; +}
[...]
Quoted 5 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c +0
-0
[...]
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c static int rtl8xxxu_download_firmware(struct rtl8xxxu_priv *priv) · line 1932
Quoted 6 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c +1
-1@@ -1904,41 +1929,54 @@ static int rtl8xxxu_download_firmware(struct rtl8xxxu_priv *priv) {int pages, remainder, i, ret;u8 val8; -u16 val16; +u16 val16, reg_mcu_fw_dl;
nit: define reg_mcu_fw_dl separately
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c static int rtl8xxxu_download_firmware(struct rtl8xxxu_priv *priv) · line 1940
Quoted 11 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c +4
-3u32 val32;u8 *fwptr; - val8 =rtl8xxxu_read8 (priv,REG_SYS_FUNC +1 ); - val8 |=4 ; -rtl8xxxu_write8 (priv,REG_SYS_FUNC +1 , val8); +if (priv->rtl_chip ==RTL8710B ) { + reg_mcu_fw_dl =REG_8051FW_CTRL_V1_8710B ; + }else { + reg_mcu_fw_dl =REG_MCU_FW_DL ;
[...]
Only some small suggestions.
Thanks for this nice work.
Ping-Ke
Quoted 36 lines · Ping-Ke Shih
Quoted 36 lines
-----Original Message-----
From: Bitterblue Smith <[email protected]>
Sent: Tuesday, February 21, 2023 12:11 AM
To: [email protected]
Cc: Jes Sorensen <[email protected]>; Ping-Ke Shih <[email protected]>
Subject: [PATCH] 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.
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.
Quoted 6 lines
Quoted 3 lines
This was tested with a device from vendor SMIC with romver 1. It's possible devices from vendor UMC and/or with romver 2 will fail to upload the firmware. The vendor driver has that problem.
Can I know the version of vendor driver you use?
I have v5.2.20.2_28373.20180619 from here:
https://github.com/McMCCRU/rtl8188gu
Most likely it's a copy of Larry Finger's repo--with some fixes, because the driver Larry Finger received from Realtek had some problems (unrelated to the firmware upload issue).
https://github.com/lwfinger/rtl8188gu
Quoted 94 lines
Quoted 18 lines
Signed-off-by Bitterblue Smith <[email protected]>--- drivers/net/wireless/realtek/rtl8xxxu/Kconfig | 2 +- .../net/wireless/realtek/rtl8xxxu/Makefile | 2 +- .../net/wireless/realtek/rtl8xxxu/rtl8xxxu.h | 304 ++- .../realtek/rtl8xxxu/rtl8xxxu_8188e.c | 2 + .../realtek/rtl8xxxu/rtl8xxxu_8188f.c | 4 +- .../realtek/rtl8xxxu/rtl8xxxu_8192c.c | 2 + .../realtek/rtl8xxxu/rtl8xxxu_8192e.c | 2 + .../realtek/rtl8xxxu/rtl8xxxu_8710b.c | 1942 +++++++++++++++++ .../realtek/rtl8xxxu/rtl8xxxu_8723a.c | 2 + .../realtek/rtl8xxxu/rtl8xxxu_8723b.c | 2 + .../wireless/realtek/rtl8xxxu/rtl8xxxu_core.c | 181 +- .../wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h | 43 + 12 files changed, 2435 insertions(+), 53 deletions(-) create mode 100644 drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c[...]
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h enum rtl8xxxu_rtl_chip { · line 107
Quoted 12 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h +2
-1@@ -103,7 +103,8 @@ enum rtl8xxxu_rtl_chip {RTL8822B =0x8822b ,RTL8703B =0x8703b ,RTL8195A =0x8195a , -RTL8188F =0x8188f +RTL8188F =0x8188f , +RTL8710B =0x8710b Add a trailing comma, and then you don't need to stir the last line when adding an new chip in the future.
[...]
Quoted 20 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h +2
-0struct rtl8xxxu_reg8val {u16 reg;u8 val;@@ -1486,6 +1769,7 @@ struct rtl8xxxu_priv {struct rtl8723au_idx ht20_tx_power_diff[RTL8723B_TX_COUNT ];struct rtl8723au_idx ht40_tx_power_diff[RTL8723B_TX_COUNT ];struct rtl8xxxu_power_base *power_base; +u8 package_type; u32 chip_cut:4; u32 rom_rev:4; u32 is_multi_func:1;@@ -1505,6 +1789,7 @@ struct rtl8xxxu_priv { u32 ep_tx_low_queue:1; u32 rx_buf_aggregation:1; u32 cck_agc_report_type:1; + u32 cck_new_agc:1;u8 default_crystal_cap;unsigned int pipe_interrupt;unsigned int pipe_in;drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h struct rtl8xxxu_priv { · line 1812
Quoted 5 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h +2
-0@@ -1523,6 +1808,8 @@ struct rtl8xxxu_priv {struct mutex h2c_mutex; +struct mutex syson_indirect_access_mutex; +I remember checkpatch will warn if you don't add a comment for mutex/lock. Though the naming is clear, just follow the rule.
[...]
Quoted 6 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +0
-0[...]
Quoted 15 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +15
-0+static u32 rtl8710b_indirect_read32 (struct rtl8xxxu_priv *priv,u32 addr) +{ +struct device *dev = &priv->udev->dev; +u32 val32, value =0xffffffff ; +u8 polling_count =0xff ; + +if (addr &3 ) { +dev_warn (dev,"%s: Aborting because 0x%x is not a multiple of 4.\n" , + __func__, addr); +return value; + } + +mutex_lock (&priv->syson_indirect_access_mutex); + +rtl8xxxu_write32 (priv,REG_USB_HOST_INDIRECT_ADDR_8710B , addr);
Quoted 9 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c line 498
Quoted 5 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +5
-0+rtl8xxxu_write32 (priv,REG_EFUSE_INDIRECT_CTRL_8710B ,NORMAL_REG_READ_OFFSET ); + +do + val32 =rtl8xxxu_read32 (priv,REG_EFUSE_INDIRECT_CTRL_8710B ); +while ((val32 &BIT (31 )) && (--polling_count >0 ));Without a pair of brace, that looks a little odd to me, but the result should be correct.
I think the rule is that we should not use braces when there is a single line inside. I assumed that applies to do...while loops too.
Quoted 166 lines
[...]
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c line 592
Quoted 6 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +6
-0+static int rtl8710bu_identify_chip (struct rtl8xxxu_priv *priv) +{ +struct device *dev = &priv->udev->dev; +u32 cfg0, cfg2, vendor; +u8 package_type =0x7 ;/* a nonsense value */ +int ret =0 ;No need '=0'. Even, don't need 'ret'.
Just returnrtl8xxxu_config_endpoints_no_sie();[...]
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c line 678
Quoted 13 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +13
-0+ + ret =rtl8xxxu_config_endpoints_no_sie (priv); + +return ret; +} + +static void rtl8710b_revise_cck_tx_psf (struct rtl8xxxu_priv *priv,u8 channel) +{ +if (channel ==13 ) { +/* Normal values */ +rtl8xxxu_write32 (priv,REG_CCK0_TX_FILTER2 ,0x64B80C1C ); +rtl8xxxu_write32 (priv,REG_CCK0_DEBUG_PORT ,0x00008810 ); +rtl8xxxu_write32 (priv,0xaac ,0x01235667 );
0xaacis another TX filter, so
#defineREG_CCK0_TX_FILTER30x0aacQuoted 18 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +18
-0+/* Special value for channel 13 */ +rtl8xxxu_write32 (priv,REG_CCK0_TX_FILTER1 ,0xd1d80001 ); + }else if (channel ==14 ) { +/* Special values for channel 14 */ +rtl8xxxu_write32 (priv,REG_CCK0_TX_FILTER2 ,0x0000B81C ); +rtl8xxxu_write32 (priv,REG_CCK0_DEBUG_PORT ,0x00000000 ); +rtl8xxxu_write32 (priv,0xaac ,0x00003667 ); +/* Normal value */ +rtl8xxxu_write32 (priv,REG_CCK0_TX_FILTER1 ,0xE82C0001 ); + }else { +/* Restore normal values from the phy init table */ +rtl8xxxu_write32 (priv,REG_CCK0_TX_FILTER2 ,0x64B80C1C ); +rtl8xxxu_write32 (priv,REG_CCK0_DEBUG_PORT ,0x00008810 ); +rtl8xxxu_write32 (priv,0xaac ,0x01235667 ); +rtl8xxxu_write32 (priv,REG_CCK0_TX_FILTER1 ,0xE82C0001 ); + } +} +[...]
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c line 870
Quoted 4 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +4
-0+static int rtl8710b_read_efuse (struct rtl8xxxu_priv *priv) +{ +struct device *dev = &priv->udev->dev; +int i, ret =0 ;move these two downward to 'val32'. Declarations should be in reverse Xmas tree order.
Quoted 8 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +8
-0+u8 val8, word_mask, header, extheader; +u16 efuse_addr, offset; +u32 val32; + + val32 =rtl8710b_read_syson_reg (priv,REG_SYS_EEPROM_CTRL0_8710B ); + priv->boot_eeprom =u32_get_bits (val32,EEPROM_BOOT ); + priv->has_eeprom =u32_get_bits (val32,EEPROM_ENABLE ); +[...]
Quoted 25 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +25
-0+static int rtl8710bu_active_to_lps (struct rtl8xxxu_priv *priv) +{ +struct device *dev = &priv->udev->dev; +u8 val8; +u16 val16; +u32 val32; +int retry, retval; + +/* Tx Pause */ +rtl8xxxu_write8 (priv,REG_TXPAUSE ,0xff ); + + retry =100 ; + retval = -EBUSY ; +/* +* Poll 32 bit wide REG_SCH_TX_CMD for 0x00000000 to ensure no TX is pending. +*/ +do { + val32 =rtl8xxxu_read32 (priv,REG_SCH_TX_CMD ); +if (!val32) { + retval =0 ; +break ; + } +udelay (10 ); + }while (retry--); +drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c line 1597
Quoted 10 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +10
-0+if (!retry) { +dev_warn (dev,"Failed to flush TX queue\n" ); + retval = -EBUSY ; +return retval; + } + +/* Disable CCK and OFDM, clock gated */ + val8 =rtl8xxxu_read8 (priv,0x02 ); + val8 &= ~BIT (0 ); +rtl8xxxu_write8 (priv,0x02 , val8);rtl8xxxu has already defined these:
#define
REG_SYS_FUNC0x0002
#defineSYS_FUNC_BBRSTBBIT(0)
#defineSYS_FUNC_BB_GLB_RSTNBIT(1)Quoted 22 lines
Quoted 1 line
+
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +21
-0+udelay (2 ); + +/*Whole BB is reset*/ + val8 =rtl8xxxu_read8 (priv,0x02 ); + val8 &= ~BIT (1 ); +rtl8xxxu_write8 (priv,0x02 , val8); + +/* Reset MAC TRX */ + val16 =rtl8xxxu_read16 (priv,REG_CR ); + val16 &=0xff00 ; + val16 |=CR_HCI_RXDMA_ENABLE |CR_HCI_TXDMA_ENABLE ; + val16 &= ~CR_SECURITY_ENABLE ; +rtl8xxxu_write16 (priv,REG_CR , val16); + +/*Respond TxOK to scheduler*/ + val8 =rtl8xxxu_read8 (priv,REG_DUAL_TSF_RST ); + val8 |=DUAL_TSF_TX_OK ; +rtl8xxxu_write8 (priv,REG_DUAL_TSF_RST , val8); + +return retval; +}[...]
Quoted 5 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c +0
-0[...]
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c static int rtl8xxxu_download_firmware(struct rtl8xxxu_priv *priv) · line 1932
Quoted 6 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c +1
-1@@ -1904,41 +1929,54 @@ static int rtl8xxxu_download_firmware(struct rtl8xxxu_priv *priv) {int pages, remainder, i, ret;u8 val8; -u16 val16; +u16 val16, reg_mcu_fw_dl;nit: define
reg_mcu_fw_dlseparatelydrivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c static int rtl8xxxu_download_firmware(struct rtl8xxxu_priv *priv) · line 1940
Quoted 11 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c +4
-3u32 val32;u8 *fwptr; - val8 =rtl8xxxu_read8 (priv,REG_SYS_FUNC +1 ); - val8 |=4 ; -rtl8xxxu_write8 (priv,REG_SYS_FUNC +1 , val8); +if (priv->rtl_chip ==RTL8710B ) { + reg_mcu_fw_dl =REG_8051FW_CTRL_V1_8710B ; + }else { + reg_mcu_fw_dl =REG_MCU_FW_DL ;
Quoted 7 lines
[...]
Only some small suggestions.
Thanks for this nice work.Ping-Ke
Thank you for your review. I'll make the changes.
Quoted 24 lines
-----Original Message-----
From: Bitterblue Smith <[email protected]>
Sent: Wednesday, February 22, 2023 2:50 AM
To: Ping-Ke Shih <[email protected]>; [email protected]
Cc: Jes Sorensen <[email protected]>
Subject: Re: [PATCH] wifi: rtl8xxxu: Support new chip RTL8710BU aka RTL8188GUQuoted 14 lines · Ping-Ke Shih
Quoted 13 lines
-----Original Message-----
From: Bitterblue Smith <[email protected]>
Sent: Tuesday, February 21, 2023 12:11 AM
To: [email protected]
Cc: Jes Sorensen <[email protected]>; Ping-Ke Shih <[email protected]>
Subject: [PATCH] wifi: rtl8xxxu: Support new chip RTL8710BU aka RTL8188GUdrivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +4
-0+ +do + val32 =rtl8xxxu_read32 (priv,REG_EFUSE_INDIRECT_CTRL_8710B ); +while ((val32 &BIT (31 )) && (--polling_count >0 ));
Quoted 5 lines
Quoted 3 lines
Without a pair of brace, that looks a little odd to me, but the result should be correct.
I think the rule is that we should not use braces when there is a single line inside. I assumed that applies to do...while loops too.
I give it a try about this, and the results are
checkpatch warns 'while':
+ while (1) {
+ x = 1;
+ }
But, don't warn 'do...while'. (your case)
+ do {
+ x = 1;
+ } while (1);
Looking into checkpatch, I found it checks single statement under these conditions 'if|while|for|else'.
Ping-Ke
Nice job, tested with three USB dongles with RTL8188GU chipset. Comments below.
Quoted 48 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.
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.
This was tested with a device from vendor SMIC with romver 1. It's possible devices from vendor UMC and/or with romver 2 will fail to upload the firmware. The vendor driver has that problem.
Signed-off-by Bitterblue Smith <[email protected]>--- drivers/net/wireless/realtek/rtl8xxxu/Kconfig | 2 +- .../net/wireless/realtek/rtl8xxxu/Makefile | 2 +- .../net/wireless/realtek/rtl8xxxu/rtl8xxxu.h | 304 ++- .../realtek/rtl8xxxu/rtl8xxxu_8188e.c | 2 + .../realtek/rtl8xxxu/rtl8xxxu_8188f.c | 4 +- .../realtek/rtl8xxxu/rtl8xxxu_8192c.c | 2 + .../realtek/rtl8xxxu/rtl8xxxu_8192e.c | 2 + .../realtek/rtl8xxxu/rtl8xxxu_8710b.c | 1942 +++++++++++++++++ .../realtek/rtl8xxxu/rtl8xxxu_8723a.c | 2 + .../realtek/rtl8xxxu/rtl8xxxu_8723b.c | 2 + .../wireless/realtek/rtl8xxxu/rtl8xxxu_core.c | 181 +- .../wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h | 43 + 12 files changed, 2435 insertions(+), 53 deletions(-)create mode 100644
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c
[...]
Quoted 40 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +40
-0+static void rtl8710b_indirect_write32 (struct rtl8xxxu_priv *priv,u32 addr,u32 val) +{ +struct device *dev = &priv->udev->dev; +u8 polling_count =0xff ; +u32 val32; + +if (addr &3 ) { +dev_warn (dev,"%s: Aborting because 0x%x is not a multiple of 4.\n" , + __func__, addr); +return ; + } + +mutex_lock (&priv->syson_indirect_access_mutex); + +rtl8xxxu_write32 (priv,REG_USB_HOST_INDIRECT_ADDR_8710B , addr); +rtl8xxxu_write32 (priv,REG_USB_HOST_INDIRECT_DATA_8710B , val); +rtl8xxxu_write32 (priv,REG_EFUSE_INDIRECT_CTRL_8710B ,NORMAL_REG_WRITE_OFFSET ); + +do + val32 =rtl8xxxu_read32 (priv,REG_EFUSE_INDIRECT_CTRL_8710B ); +while ((val32 &BIT (31 )) && (--polling_count >0 )); + +if (polling_count ==0 ) +dev_warn (dev,"%s: Failed to write 0x%x to 0x%x, 0x806c = 0x%x\n" , + __func__, val, addr, val32); + +mutex_unlock (&priv->syson_indirect_access_mutex); + +if (rtl8xxxu_debug &RTL8XXXU_DEBUG_REG_WRITE ) +dev_info (dev,"%s(%04x) = 0x%08x\n" , __func__, addr, val); +} + +static u32 rtl8710b_read_syson_reg (struct rtl8xxxu_priv *priv,u32 addr) +{ +return rtl8710b_indirect_read32 (priv, addr |SYSON_REG_BASE_ADDR_8710B ); +} + +static void rtl8710b_write_syson_reg (struct rtl8xxxu_priv *priv,u32 addr,u32 val) +{ +rtl8710b_indirect_write32 (priv, addr |SYSON_REG_BASE_ADDR_8710B , val);
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c line 563
Quoted 10 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +10
-0+} + +static int rtl8710b_read_efuse8 (struct rtl8xxxu_priv *priv,u16 offset,u8 *data) +{ +int i; +u32 val32; + +/* Write Address */ +rtl8xxxu_write32 (priv,REG_USB_HOST_INDIRECT_ADDR_8710B , offset); +
Isn't it required to lock 'priv->syson_indirect_access_mutex' here?
Quoted 23 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +23
-0+rtl8xxxu_write32 (priv,REG_EFUSE_INDIRECT_CTRL_8710B ,EFUSE_READ_OFFSET ); + +/* Poll for data read */ + val32 =rtl8xxxu_read32 (priv,REG_EFUSE_INDIRECT_CTRL_8710B ); +for (i =0 ; i <RTL8XXXU_MAX_REG_POLL ; i++) { + val32 =rtl8xxxu_read32 (priv,REG_EFUSE_INDIRECT_CTRL_8710B ); +if (!(val32 &BIT (31 ))) +break ; + } + +if (i ==RTL8XXXU_MAX_REG_POLL ) +return -EIO ; + + val32 =rtl8xxxu_read32 (priv,REG_USB_HOST_INDIRECT_DATA_8710B ); + + *data = val32 &0xff ; +return 0 ; +} + +#define EEPROM_PACKAGE_TYPE_8710B 0xF8 +#define PACKAGE_QFN48M_U 0xee +#define PACKAGE_QFN48M_S 0xfe +
[...]
Quoted 29 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +29
-0+static int rtl8710bu_active_to_lps (struct rtl8xxxu_priv *priv) +{ +struct device *dev = &priv->udev->dev; +u8 val8; +u16 val16; +u32 val32; +int retry, retval; + +/* Tx Pause */ +rtl8xxxu_write8 (priv,REG_TXPAUSE ,0xff ); + + retry =100 ; + retval = -EBUSY ; +/* +* Poll 32 bit wide REG_SCH_TX_CMD for 0x00000000 to ensure no TX is pending. +*/ +do { + val32 =rtl8xxxu_read32 (priv,REG_SCH_TX_CMD ); +if (!val32) { + retval =0 ; +break ; + } +udelay (10 ); + }while (retry--); + +if (!retry) { +dev_warn (dev,"Failed to flush TX queue\n" ); + retval = -EBUSY ; +return retval;
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c line 1601
Quoted 10 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +10
-0+ } + +/* Disable CCK and OFDM, clock gated */ + val8 =rtl8xxxu_read8 (priv,0x02 ); + val8 &= ~BIT (0 ); +rtl8xxxu_write8 (priv,0x02 , val8); + +udelay (2 ); + +/*Whole BB is reset*/
There are missing spaces between "/*" and "Whole", "reset" and "*/".
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c line 1613
Quoted 12 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +12
-0+ val8 =rtl8xxxu_read8 (priv,0x02 ); + val8 &= ~BIT (1 ); +rtl8xxxu_write8 (priv,0x02 , val8); + +/* Reset MAC TRX */ + val16 =rtl8xxxu_read16 (priv,REG_CR ); + val16 &=0xff00 ; + val16 |=CR_HCI_RXDMA_ENABLE |CR_HCI_TXDMA_ENABLE ; + val16 &= ~CR_SECURITY_ENABLE ; +rtl8xxxu_write16 (priv,REG_CR , val16); + +/*Respond TxOK to scheduler*/
Same here.
Quoted 7 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +7
-0+ val8 =rtl8xxxu_read8 (priv,REG_DUAL_TSF_RST ); + val8 |=DUAL_TSF_TX_OK ; +rtl8xxxu_write8 (priv,REG_DUAL_TSF_RST , val8); + +return retval; +} +
Quoted 2 lines · Jiajie Chen
Nice job, tested with three USB dongles with RTL8188GU chipset. Comments below.
Cool! Are the chips made by UMC or SMIC? See this line in dmesg:
usb 1-2: RTL8710BU rev A (SMIC) romver 1, 1T1R, TX queues 3, WiFi=1, BT=0, GPS=0, HI PA=0
Quoted 95 lines · Bitterblue Smith
Quoted 48 lines
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.
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.
This was tested with a device from vendor SMIC with romver 1. It's possible devices from vendor UMC and/or with romver 2 will fail to upload the firmware. The vendor driver has that problem.
Signed-off-by Bitterblue Smith <[email protected]>---
drivers/net/wireless/realtek/rtl8xxxu/Kconfig| 2 +- .../net/wireless/realtek/rtl8xxxu/Makefile | 2 +- .../net/wireless/realtek/rtl8xxxu/rtl8xxxu.h | 304 ++-.../realtek/rtl8xxxu/rtl8xxxu_8188e.c | 2 + .../realtek/rtl8xxxu/rtl8xxxu_8188f.c | 4 +- .../realtek/rtl8xxxu/rtl8xxxu_8192c.c | 2 + .../realtek/rtl8xxxu/rtl8xxxu_8192e.c | 2 + .../realtek/rtl8xxxu/rtl8xxxu_8710b.c | 1942 +++++++++++++++++ .../realtek/rtl8xxxu/rtl8xxxu_8723a.c | 2 + .../realtek/rtl8xxxu/rtl8xxxu_8723b.c | 2 + .../wireless/realtek/rtl8xxxu/rtl8xxxu_core.c | 181 +- .../wireless/realtek/rtl8xxxu/rtl8xxxu_regs.h | 43 + 12 files changed, 2435 insertions(+), 53 deletions(-)create mode 100644
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c[...]
Quoted 44 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +44
-0+static void rtl8710b_indirect_write32 (struct rtl8xxxu_priv *priv,u32 addr,u32 val) +{ + struct device *dev = &priv->udev->dev; + u8 polling_count = 0xff; + u32 val32; + + if (addr & 3) { + dev_warn(dev, "%s: Aborting because 0x%x is not a multiple of 4.\n", + __func__, addr); + return; + } + + mutex_lock(&priv->syson_indirect_access_mutex); + + rtl8xxxu_write32(priv, REG_USB_HOST_INDIRECT_ADDR_8710B, addr); + rtl8xxxu_write32(priv, REG_USB_HOST_INDIRECT_DATA_8710B, val); + rtl8xxxu_write32(priv, REG_EFUSE_INDIRECT_CTRL_8710B, NORMAL_REG_WRITE_OFFSET); + + do + val32 = rtl8xxxu_read32(priv, REG_EFUSE_INDIRECT_CTRL_8710B); + while ((val32 & BIT(31)) && (--polling_count > 0)); + + if (polling_count == 0) + dev_warn(dev, "%s: Failed to write 0x%x to 0x%x, 0x806c = 0x%x\n", + __func__, val, addr, val32); + + mutex_unlock(&priv->syson_indirect_access_mutex); + + if (rtl8xxxu_debug & RTL8XXXU_DEBUG_REG_WRITE) + dev_info(dev, "%s(%04x) = 0x%08x\n", __func__, addr, val); +} + +static u32 rtl8710b_read_syson_reg (struct rtl8xxxu_priv *priv,u32 addr) +{ + return rtl8710b_indirect_read32(priv, addr | SYSON_REG_BASE_ADDR_8710B); +} + +static void rtl8710b_write_syson_reg (struct rtl8xxxu_priv *priv,u32 addr,u32 val) +{ + rtl8710b_indirect_write32(priv, addr | SYSON_REG_BASE_ADDR_8710B, val); +} + +static int rtl8710b_read_efuse8 (struct rtl8xxxu_priv *priv,u16 offset,u8 *data) +{
Quoted 9 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c line 563
Quoted 6 lines
+ int i;
+ u32 val32;drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +4
-0+ + /* Write Address */ + rtl8xxxu_write32(priv, REG_USB_HOST_INDIRECT_ADDR_8710B, offset); +Isn't it required to lock '
priv->syson_indirect_access_mutex' here?
Probably not. This function is called only from rtl8710bu_identify_chip() and rtl8710b_read_efuse(), and they are only called from rtl8xxxu_probe(). rtl8710b_read_syson_reg() and rtl8710b_write_syson_reg() are only called after rtl8xxxu_probe() returns.
Quoted 57 lines
Quoted 23 lines
+
rtl8xxxu_write32(priv, REG_EFUSE_INDIRECT_CTRL_8710B, EFUSE_READ_OFFSET);drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +22
-0+ + /* Poll for data read */ + val32 = rtl8xxxu_read32(priv, REG_EFUSE_INDIRECT_CTRL_8710B); + for (i = 0; i < RTL8XXXU_MAX_REG_POLL; i++) { + val32 = rtl8xxxu_read32(priv, REG_EFUSE_INDIRECT_CTRL_8710B); + if (!(val32 & BIT(31))) + break; + } + + if (i == RTL8XXXU_MAX_REG_POLL) + return -EIO; + + val32 = rtl8xxxu_read32(priv, REG_USB_HOST_INDIRECT_DATA_8710B); + + *data = val32 & 0xff; + return 0; +} + +#define EEPROM_PACKAGE_TYPE_8710B 0xF8 +#define PACKAGE_QFN48M_U 0xee +#define PACKAGE_QFN48M_S 0xfe +[...]
Quoted 33 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +33
-0+static int rtl8710bu_active_to_lps (struct rtl8xxxu_priv *priv) +{ + struct device *dev = &priv->udev->dev; + u8 val8; + u16 val16; + u32 val32; + int retry, retval; + + /* Tx Pause */ + rtl8xxxu_write8(priv, REG_TXPAUSE, 0xff); + + retry = 100; + retval = -EBUSY; + /* + * Poll 32 bit wide REG_SCH_TX_CMD for 0x00000000 to ensure no TX is pending. + */ + do { + val32 = rtl8xxxu_read32(priv, REG_SCH_TX_CMD); + if (!val32) { + retval = 0; + break; + } + udelay(10); + } while (retry--); + + if (!retry) { + dev_warn(dev, "Failed to flush TX queue\n"); + retval = -EBUSY; + return retval; + } + + /* Disable CCK and OFDM, clock gated */ + val8 = rtl8xxxu_read8(priv, 0x02);
Quoted 9 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c line 1601
Quoted 6 lines
+ val8 &= ~BIT(0);
+rtl8xxxu_write8(priv, 0x02, val8);drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +4
-0+ + udelay(2); + + /*Whole BB is reset*/There are missing spaces between "/*" and "Whole", "reset" and "*/".
Right. I'll fix that.
Quoted 22 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c line 1613
Quoted 12 lines
+ val8 =
rtl8xxxu_read8(priv, 0x02);
+ val8 &= ~BIT(1);
+rtl8xxxu_write8(priv, 0x02, val8);drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +9
-0+ + /* Reset MAC TRX */ + val16 = rtl8xxxu_read16(priv, REG_CR); + val16 &= 0xff00; + val16 |= CR_HCI_RXDMA_ENABLE | CR_HCI_TXDMA_ENABLE; + val16 &= ~CR_SECURITY_ENABLE; + rtl8xxxu_write16(priv, REG_CR, val16); + + /*Respond TxOK to scheduler*/Same here.
Quoted 7 lines
+ val8 =
rtl8xxxu_read8(priv, REG_DUAL_TSF_RST); + val8 |=DUAL_TSF_TX_OK;
+rtl8xxxu_write8(priv, REG_DUAL_TSF_RST, val8);drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c new file +4
-0+ + return retval; +} +
Quoted 6 lines · Bitterblue Smith
Quoted 2 lines · Jiajie Chen
Nice job, tested with three USB dongles with RTL8188GU chipset. Comments below.
Cool! Are the chips made by UMC or SMIC? See this line in dmesg:
usb 1-2: RTL8710BU rev A (SMIC) romver 1, 1T1R, TX queues 3, WiFi=1, BT=0, GPS=0, HI PA=0
They are all made by SMIC:
EDUP EP-N8566
[39672.643323] usb 3-1.4: new high-speed USB device number 15 using xhci_hcd [39672.744277] usb 3-1.4: New USB device found, idVendor=0bda, idProduct=b711, bcdDevice= 2.00 [39672.744288] usb 3-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [39672.744292] usb 3-1.4: Product: 802.11n WLAN Adapter [39672.744294] usb 3-1.4: Manufacturer: Realtek [39672.744297] usb 3-1.4: SerialNumber: 00E04CB82101 [39672.763531] usb 3-1.4: RTL8710BU rev A (SMIC) romver 1, 1T1R, TX queues 3, WiFi=1, BT=0, GPS=0, HI PA=0 [39672.763534] usb 3-1.4: RTL8710BU MAC: xx:xx:xx:xx:xx:xx [39672.763535] usb 3-1.4: rtl8xxxu: Loading firmware rtlwifi/rtl8710bufw.bin [39672.763559] usb 3-1.4: Firmware revision 16.0 (signature 0x10b1) [39672.765248] usb 3-1.4: Firmware is already running, resetting the MCU.
Mercury MW150US v2
[39688.892911] usb 3-1.3: RTL8710BU rev A (SMIC) romver 1, 1T1R, TX queues 3, WiFi=1, BT=0, GPS=0, HI PA=0
Tenda W311MI
[39702.424956] usb 3-1.2: RTL8710BU rev A (SMIC) romver 1, 1T1R, TX queues 3, WiFi=1, BT=0, GPS=0, HI PA=0