2024-02-29 22:32:57

by Bitterblue Smith

[permalink] [raw]
Subject: [PATCH v2 1/4] wifi: rtw88: 8821cu: Fix firmware upload fail

RTL8822CU, RTL8822BU, and RTL8821CU need an extra register write after
reading and writing certain addresses.

Without this, the firmware upload fails approximately more than 50% of
the time.

Tested with RTL8811CU (Tenda U9 V2.0) which is the same as RTL8821CU
but without Bluetooth.

Fixes: a82dfd33d123 ("wifi: rtw88: Add common USB chip support")
Signed-off-by: Bitterblue Smith <[email protected]>
---
v2:
- Simplify the code and add comments, as suggested.
---
drivers/net/wireless/realtek/rtw88/usb.c | 40 ++++++++++++++++++++++++
1 file changed, 40 insertions(+)

diff --git a/drivers/net/wireless/realtek/rtw88/usb.c b/drivers/net/wireless/realtek/rtw88/usb.c
index 3c4f28c306a9..3be6cbbf9ad8 100644
--- a/drivers/net/wireless/realtek/rtw88/usb.c
+++ b/drivers/net/wireless/realtek/rtw88/usb.c
@@ -33,6 +33,36 @@ static void rtw_usb_fill_tx_checksum(struct rtw_usb *rtwusb,
rtw_tx_fill_txdesc_checksum(rtwdev, &pkt_info, skb->data);
}

+static void rtw_usb_reg_sec(struct rtw_dev *rtwdev, u32 addr, __le32 *data)
+{
+ struct rtw_usb *rtwusb = rtw_get_usb_priv(rtwdev);
+ struct usb_device *udev = rtwusb->udev;
+ bool reg_on_section = false;
+ u16 t_reg = 0x4e0;
+ u8 t_len = 1;
+ int status;
+
+ /* There are three sections:
+ * 1. on (0x00~0xFF; 0x1000~0x10FF): this section is always powered on
+ * 2. off (< 0xFE00, excluding "on" section): this section could be
+ * powered off
+ * 3. local (>= 0xFE00): usb specific registers section
+ */
+ if (addr <= 0xff || (addr >= 0x1000 && addr <= 0x10ff))
+ reg_on_section = true;
+
+ if (!reg_on_section)
+ return;
+
+ status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
+ RTW_USB_CMD_REQ, RTW_USB_CMD_WRITE,
+ t_reg, 0, data, t_len, 500);
+
+ if (status != t_len && status != -ENODEV)
+ rtw_err(rtwdev, "%s: reg 0x%x, usb write %u fail, status: %d\n",
+ __func__, t_reg, t_len, status);
+}
+
static u32 rtw_usb_read(struct rtw_dev *rtwdev, u32 addr, u16 len)
{
struct rtw_usb *rtwusb = rtw_get_usb_priv(rtwdev);
@@ -58,6 +88,11 @@ static u32 rtw_usb_read(struct rtw_dev *rtwdev, u32 addr, u16 len)
rtw_err(rtwdev, "read register 0x%x failed with %d\n",
addr, ret);

+ if (rtwdev->chip->id == RTW_CHIP_TYPE_8822C ||
+ rtwdev->chip->id == RTW_CHIP_TYPE_8822B ||
+ rtwdev->chip->id == RTW_CHIP_TYPE_8821C)
+ rtw_usb_reg_sec(rtwdev, addr, data);
+
return le32_to_cpu(*data);
}

@@ -111,6 +146,11 @@ static void rtw_usb_write(struct rtw_dev *rtwdev, u32 addr, u32 val, int len)
if (ret < 0 && ret != -ENODEV && count++ < 4)
rtw_err(rtwdev, "write register 0x%x failed with %d\n",
addr, ret);
+
+ if (rtwdev->chip->id == RTW_CHIP_TYPE_8822C ||
+ rtwdev->chip->id == RTW_CHIP_TYPE_8822B ||
+ rtwdev->chip->id == RTW_CHIP_TYPE_8821C)
+ rtw_usb_reg_sec(rtwdev, addr, data);
}

static void rtw_usb_write8(struct rtw_dev *rtwdev, u32 addr, u8 val)
--
2.43.2


2024-02-29 22:35:18

by Bitterblue Smith

[permalink] [raw]
Subject: [PATCH v2 3/4] wifi: rtw88: 8821c: Fix beacon loss and disconnect

Tenda U9 V2.0, which contains RTL8811CU, is practically unusable because
of frequent disconnections:

Feb 23 14:46:45 ideapad2 wpa_supplicant[427]: wlp3s0f3u2: CTRL-EVENT-BEACON-LOSS
Feb 23 14:46:46 ideapad2 wpa_supplicant[427]: wlp3s0f3u2: CTRL-EVENT-DISCONNECTED
bssid=90:55:de:__:__:__ reason=4 locally_generated=1

Feb 23 14:46:52 ideapad2 wpa_supplicant[427]: wlp3s0f3u2: CTRL-EVENT-CONNECTED
- Connection to 90:55:de:__:__:__ completed [id=0 id_str=]
Feb 23 14:46:54 ideapad2 wpa_supplicant[427]: wlp3s0f3u2: CTRL-EVENT-BEACON-LOSS
Feb 23 14:46:55 ideapad2 wpa_supplicant[427]: wlp3s0f3u2: CTRL-EVENT-DISCONNECTED
bssid=90:55:de:__:__:__ reason=4 locally_generated=1

Feb 23 14:47:01 ideapad2 wpa_supplicant[427]: wlp3s0f3u2: CTRL-EVENT-CONNECTED
- Connection to 90:55:de:__:__:__ completed [id=0 id_str=]
Feb 23 14:47:04 ideapad2 wpa_supplicant[427]: wlp3s0f3u2: CTRL-EVENT-BEACON-LOSS
Feb 23 14:47:05 ideapad2 wpa_supplicant[427]: wlp3s0f3u2: CTRL-EVENT-DISCONNECTED
bssid=90:55:de:__:__:__ reason=4 locally_generated=1

This is caused by a mistake in the chip initialisation. This version of
the chip requires loading an extra AGC table right after the main one,
but the extra table is being loaded at the wrong time, in
rtw_chip_board_info_setup().

Move the extra AGC table loading to the right place, in
rtw_phy_load_tables().

The rtw_chip_board_info_setup() can only do "software" things, and
rtw_phy_load_tables() can really do IO.

Fixes: 5d6651fe8583 ("rtw88: 8821c: support RFE type2 wifi NIC")
Signed-off-by: Bitterblue Smith <[email protected]>
---
v2:
- Add more information in the commit message.
---
drivers/net/wireless/realtek/rtw88/main.c | 2 --
drivers/net/wireless/realtek/rtw88/phy.c | 3 +++
2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtw88/main.c b/drivers/net/wireless/realtek/rtw88/main.c
index 6d22628129d0..ffba6b88f392 100644
--- a/drivers/net/wireless/realtek/rtw88/main.c
+++ b/drivers/net/wireless/realtek/rtw88/main.c
@@ -2032,8 +2032,6 @@ static int rtw_chip_board_info_setup(struct rtw_dev *rtwdev)
rtw_phy_setup_phy_cond(rtwdev, hal->pkg_type);

rtw_phy_init_tx_power(rtwdev);
- if (rfe_def->agc_btg_tbl)
- rtw_load_table(rtwdev, rfe_def->agc_btg_tbl);
rtw_load_table(rtwdev, rfe_def->phy_pg_tbl);
rtw_load_table(rtwdev, rfe_def->txpwr_lmt_tbl);
rtw_phy_tx_power_by_rate_config(hal);
diff --git a/drivers/net/wireless/realtek/rtw88/phy.c b/drivers/net/wireless/realtek/rtw88/phy.c
index 128e75a81bf3..37ef80c9091d 100644
--- a/drivers/net/wireless/realtek/rtw88/phy.c
+++ b/drivers/net/wireless/realtek/rtw88/phy.c
@@ -1761,12 +1761,15 @@ static void rtw_load_rfk_table(struct rtw_dev *rtwdev)

void rtw_phy_load_tables(struct rtw_dev *rtwdev)
{
+ const struct rtw_rfe_def *rfe_def = rtw_get_rfe_def(rtwdev);
const struct rtw_chip_info *chip = rtwdev->chip;
u8 rf_path;

rtw_load_table(rtwdev, chip->mac_tbl);
rtw_load_table(rtwdev, chip->bb_tbl);
rtw_load_table(rtwdev, chip->agc_tbl);
+ if (rfe_def->agc_btg_tbl)
+ rtw_load_table(rtwdev, rfe_def->agc_btg_tbl);
rtw_load_rfk_table(rtwdev);

for (rf_path = 0; rf_path < rtwdev->hal.rf_path_num; rf_path++) {
--
2.43.2

2024-02-29 22:36:08

by Bitterblue Smith

[permalink] [raw]
Subject: [PATCH v2 4/4] wifi: rtw88: 8821c: Fix false alarm count

total_fa_cnt is supposed to include cck_fa_cnt and ofdm_fa_cnt, not just
ofdm_fa_cnt.

Fixes: 960361238b86 ("rtw88: 8821c: add false alarm statistics")
Signed-off-by: Bitterblue Smith <[email protected]>
---
v2:
- No change.
---
drivers/net/wireless/realtek/rtw88/rtw8821c.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/wireless/realtek/rtw88/rtw8821c.c b/drivers/net/wireless/realtek/rtw88/rtw8821c.c
index 429bb420b056..fe5d8e188350 100644
--- a/drivers/net/wireless/realtek/rtw88/rtw8821c.c
+++ b/drivers/net/wireless/realtek/rtw88/rtw8821c.c
@@ -773,9 +773,9 @@ static void rtw8821c_false_alarm_statistics(struct rtw_dev *rtwdev)

dm_info->cck_fa_cnt = cck_fa_cnt;
dm_info->ofdm_fa_cnt = ofdm_fa_cnt;
+ dm_info->total_fa_cnt = ofdm_fa_cnt;
if (cck_enable)
dm_info->total_fa_cnt += cck_fa_cnt;
- dm_info->total_fa_cnt = ofdm_fa_cnt;

crc32_cnt = rtw_read32(rtwdev, REG_CRC_CCK);
dm_info->cck_ok_cnt = FIELD_GET(GENMASK(15, 0), crc32_cnt);
--
2.43.2

2024-02-29 22:37:49

by Bitterblue Smith

[permalink] [raw]
Subject: [PATCH v2 2/4] wifi: rtw88: 8821cu: Fix connection failure

Clear bit 8 of REG_SYS_STATUS1 after MAC power on.

Without this, some RTL8821CU and RTL8811CU cannot connect to any
network:

Feb 19 13:33:11 ideapad2 kernel: wlp3s0f3u2: send auth to
90:55:de:__:__:__ (try 1/3)
Feb 19 13:33:13 ideapad2 kernel: wlp3s0f3u2: send auth to
90:55:de:__:__:__ (try 2/3)
Feb 19 13:33:14 ideapad2 kernel: wlp3s0f3u2: send auth to
90:55:de:__:__:__ (try 3/3)
Feb 19 13:33:15 ideapad2 kernel: wlp3s0f3u2: authentication with
90:55:de:__:__:__ timed out

The RTL8822CU and RTL8822BU out-of-tree drivers do this as well, so do
it for all three types of chips.

Tested with RTL8811CU (Tenda U9 V2.0).

Signed-off-by: Bitterblue Smith <[email protected]>
---
v2:
- Check for pwr_on instead of pwr_seq == chip->pwr_on_seq.
---
drivers/net/wireless/realtek/rtw88/mac.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/drivers/net/wireless/realtek/rtw88/mac.c b/drivers/net/wireless/realtek/rtw88/mac.c
index 298663b03580..0c1c1ff31085 100644
--- a/drivers/net/wireless/realtek/rtw88/mac.c
+++ b/drivers/net/wireless/realtek/rtw88/mac.c
@@ -309,6 +309,13 @@ static int rtw_mac_power_switch(struct rtw_dev *rtwdev, bool pwr_on)
pwr_seq = pwr_on ? chip->pwr_on_seq : chip->pwr_off_seq;
ret = rtw_pwr_seq_parser(rtwdev, pwr_seq);

+ if (pwr_on && rtw_hci_type(rtwdev) == RTW_HCI_TYPE_USB) {
+ if (chip->id == RTW_CHIP_TYPE_8822C ||
+ chip->id == RTW_CHIP_TYPE_8822B ||
+ chip->id == RTW_CHIP_TYPE_8821C)
+ rtw_write8_clr(rtwdev, REG_SYS_STATUS1 + 1, BIT(0));
+ }
+
if (rtw_hci_type(rtwdev) == RTW_HCI_TYPE_SDIO)
rtw_write32(rtwdev, REG_SDIO_HIMR, imr);

--
2.43.2

2024-03-01 00:27:41

by Ping-Ke Shih

[permalink] [raw]
Subject: RE: [PATCH v2 1/4] wifi: rtw88: 8821cu: Fix firmware upload fail



> -----Original Message-----
> From: Bitterblue Smith <[email protected]>
> Sent: Friday, March 1, 2024 6:33 AM
> To: [email protected]
> Cc: Ping-Ke Shih <[email protected]>; Sascha Hauer <[email protected]>; Sean Mollet <[email protected]>
> Subject: [PATCH v2 1/4] wifi: rtw88: 8821cu: Fix firmware upload fail
>
> RTL8822CU, RTL8822BU, and RTL8821CU need an extra register write after
> reading and writing certain addresses.
>
> Without this, the firmware upload fails approximately more than 50% of
> the time.
>
> Tested with RTL8811CU (Tenda U9 V2.0) which is the same as RTL8821CU
> but without Bluetooth.
>
> Fixes: a82dfd33d123 ("wifi: rtw88: Add common USB chip support")
> Signed-off-by: Bitterblue Smith <[email protected]>

Acked-by: Ping-Ke Shih <[email protected]>

2024-03-01 00:28:15

by Ping-Ke Shih

[permalink] [raw]
Subject: RE: [PATCH v2 2/4] wifi: rtw88: 8821cu: Fix connection failure



> -----Original Message-----
> From: Bitterblue Smith <[email protected]>
> Sent: Friday, March 1, 2024 6:34 AM
> To: [email protected]
> Cc: Ping-Ke Shih <[email protected]>; Sascha Hauer <[email protected]>
> Subject: [PATCH v2 2/4] wifi: rtw88: 8821cu: Fix connection failure
>
> Clear bit 8 of REG_SYS_STATUS1 after MAC power on.
>
> Without this, some RTL8821CU and RTL8811CU cannot connect to any
> network:
>
> Feb 19 13:33:11 ideapad2 kernel: wlp3s0f3u2: send auth to
> 90:55:de:__:__:__ (try 1/3)
> Feb 19 13:33:13 ideapad2 kernel: wlp3s0f3u2: send auth to
> 90:55:de:__:__:__ (try 2/3)
> Feb 19 13:33:14 ideapad2 kernel: wlp3s0f3u2: send auth to
> 90:55:de:__:__:__ (try 3/3)
> Feb 19 13:33:15 ideapad2 kernel: wlp3s0f3u2: authentication with
> 90:55:de:__:__:__ timed out
>
> The RTL8822CU and RTL8822BU out-of-tree drivers do this as well, so do
> it for all three types of chips.
>
> Tested with RTL8811CU (Tenda U9 V2.0).
>
> Signed-off-by: Bitterblue Smith <[email protected]>

Acked-by: Ping-Ke Shih <[email protected]>

2024-03-01 00:28:56

by Ping-Ke Shih

[permalink] [raw]
Subject: RE: [PATCH v2 3/4] wifi: rtw88: 8821c: Fix beacon loss and disconnect



> -----Original Message-----
> From: Bitterblue Smith <[email protected]>
> Sent: Friday, March 1, 2024 6:35 AM
> To: [email protected]
> Cc: Ping-Ke Shih <[email protected]>; Sascha Hauer <[email protected]>
> Subject: [PATCH v2 3/4] wifi: rtw88: 8821c: Fix beacon loss and disconnect
>
> Tenda U9 V2.0, which contains RTL8811CU, is practically unusable because
> of frequent disconnections:
>
> Feb 23 14:46:45 ideapad2 wpa_supplicant[427]: wlp3s0f3u2: CTRL-EVENT-BEACON-LOSS
> Feb 23 14:46:46 ideapad2 wpa_supplicant[427]: wlp3s0f3u2: CTRL-EVENT-DISCONNECTED
> bssid=90:55:de:__:__:__ reason=4 locally_generated=1
>
> Feb 23 14:46:52 ideapad2 wpa_supplicant[427]: wlp3s0f3u2: CTRL-EVENT-CONNECTED
> - Connection to 90:55:de:__:__:__ completed [id=0 id_str=]
> Feb 23 14:46:54 ideapad2 wpa_supplicant[427]: wlp3s0f3u2: CTRL-EVENT-BEACON-LOSS
> Feb 23 14:46:55 ideapad2 wpa_supplicant[427]: wlp3s0f3u2: CTRL-EVENT-DISCONNECTED
> bssid=90:55:de:__:__:__ reason=4 locally_generated=1
>
> Feb 23 14:47:01 ideapad2 wpa_supplicant[427]: wlp3s0f3u2: CTRL-EVENT-CONNECTED
> - Connection to 90:55:de:__:__:__ completed [id=0 id_str=]
> Feb 23 14:47:04 ideapad2 wpa_supplicant[427]: wlp3s0f3u2: CTRL-EVENT-BEACON-LOSS
> Feb 23 14:47:05 ideapad2 wpa_supplicant[427]: wlp3s0f3u2: CTRL-EVENT-DISCONNECTED
> bssid=90:55:de:__:__:__ reason=4 locally_generated=1
>
> This is caused by a mistake in the chip initialisation. This version of
> the chip requires loading an extra AGC table right after the main one,
> but the extra table is being loaded at the wrong time, in
> rtw_chip_board_info_setup().
>
> Move the extra AGC table loading to the right place, in
> rtw_phy_load_tables().
>
> The rtw_chip_board_info_setup() can only do "software" things, and
> rtw_phy_load_tables() can really do IO.
>
> Fixes: 5d6651fe8583 ("rtw88: 8821c: support RFE type2 wifi NIC")
> Signed-off-by: Bitterblue Smith <[email protected]>

Acked-by: Ping-Ke Shih <[email protected]>



2024-03-01 00:29:54

by Ping-Ke Shih

[permalink] [raw]
Subject: RE: [PATCH v2 4/4] wifi: rtw88: 8821c: Fix false alarm count



> -----Original Message-----
> From: Bitterblue Smith <[email protected]>
> Sent: Friday, March 1, 2024 6:36 AM
> To: [email protected]
> Cc: Ping-Ke Shih <[email protected]>; Sascha Hauer <[email protected]>
> Subject: [PATCH v2 4/4] wifi: rtw88: 8821c: Fix false alarm count
>
> total_fa_cnt is supposed to include cck_fa_cnt and ofdm_fa_cnt, not just
> ofdm_fa_cnt.
>
> Fixes: 960361238b86 ("rtw88: 8821c: add false alarm statistics")
> Signed-off-by: Bitterblue Smith <[email protected]>

Acked-by: Ping-Ke Shih <[email protected]>

Thanks for your great work!

2024-03-05 17:44:41

by Kalle Valo

[permalink] [raw]
Subject: Re: [PATCH v2 1/4] wifi: rtw88: 8821cu: Fix firmware upload fail

Bitterblue Smith <[email protected]> wrote:

> RTL8822CU, RTL8822BU, and RTL8821CU need an extra register write after
> reading and writing certain addresses.
>
> Without this, the firmware upload fails approximately more than 50% of
> the time.
>
> Tested with RTL8811CU (Tenda U9 V2.0) which is the same as RTL8821CU
> but without Bluetooth.
>
> Fixes: a82dfd33d123 ("wifi: rtw88: Add common USB chip support")
> Signed-off-by: Bitterblue Smith <[email protected]>
> Acked-by: Ping-Ke Shih <[email protected]>

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

41a7acb7dde8 wifi: rtw88: 8821cu: Fix firmware upload fail
605d7c0b05ee wifi: rtw88: 8821cu: Fix connection failure
e1dfa21427ba wifi: rtw88: 8821c: Fix beacon loss and disconnect
c238adbc578e wifi: rtw88: 8821c: Fix false alarm count

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

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