Skip to contentSkip to conversation

wifi: rtw89: usb: Support switching to USB 3 mode

PATCH Superseded Bitterblue Smith 2 participants 4 messages May 16 – May 20 Realtek wireless driver (rtw89)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 wifi: rtw89: usb: Support switching to USB 3 mode

The Realtek wifi 6/7 devices which support USB 3 are weird: when first plugged in, they pretend to be USB 2. The driver needs to send some commands to the device, which make it disappear and come back as a USB 3 device.

Implement the required commands in rtw89.

Add a new function rtw89_usb_write32_quiet() to avoid the warnings when writing to R_{AX,BE}_PAD_CTRL2. Even though the write succeeds, usb_control_msg() returns -EPROTO, probably because the USB device disappears immediately. This results in some confusing warnings in the kernel log.

When a USB 3 device is plugged into a USB 2 port, rtw89 will try to switch it to USB 3 mode only once. The device will disappear and come back still in USB 2 mode, of course.

Tested with RTL8832AU, RTL8832BU, RTL8832CU, and RTL8912AU.

---
v3:
- Avoid crash when trying to switch.
- Remove the unwanted module parameter.
- Support RTL8922AU as well.
- Use more bit names.
- Hide the warnings when writing R_AX_PAD_CTRL2.

---
 drivers/net/wireless/realtek/rtw89/reg.h |  27 ++++++
 drivers/net/wireless/realtek/rtw89/usb.c | 112 +++++++++++++++++++++--
 2 files changed, 130 insertions(+), 9 deletions(-)
drivers/net/wireless/realtek/rtw89/reg.h +27 -0
index 716747c3a10e..c9816ead834d 100644
@@ -164,6 +164,19 @@
 #define R_AX_DBG_PORT_SEL 0x00C0
 #define B_AX_DEBUG_ST_MASK GENMASK(31, 0)
 
+#define R_AX_PAD_CTRL2 0x00C4
+#define B_AX_FORCE_U3_CK BIT(23)
+#define B_AX_USB2_FORCE BIT(22)
+#define B_AX_USB3_FORCE BIT(21)
+#define B_AX_USB3_USB2_TRANSITION BIT(20)
+#define B_AX_USB23_SW_MODE_V1 GENMASK(19, 18)
+#define USB_MODE_U2 0x1
+#define USB_MODE_U3 0x2
+#define B_AX_NO_PDN_CHIPOFF_V1 BIT(17)
+#define B_AX_RSM_EN_V1 BIT(16)
+#define B_AX_MATCH_CNT GENMASK(15, 8)
+#define USB_SWITCH_DELAY 0xF
+
 #define R_AX_PMC_DBG_CTRL2 0x00CC
 #define B_AX_SYSON_DIS_PMCR_AX_WRMSK BIT(2)
 
@@ -4235,6 +4248,20 @@
 #define B_BE_TOGGLE BIT(31)
 #define B_BE_DATA_LINE_MASK GENMASK(30, 0)
 
+#define R_BE_PAD_CTRL2 0x00C4
+#define B_BE_USB23_SW_MODE BIT(31)
+#define B_BE_USB3_GEN_MODE BIT(30)
+#define B_BE_USB3_LANE_MODE BIT(29)
+#define B_BE_USB_AUTO_INSTALL_MASK BIT(28)
+#define B_BE_FORCE_CLK_U2 BIT(25)
+#define B_BE_FORCE_U2_CK BIT(24)
+#define B_BE_FORCE_U3_CK BIT(23)
+#define B_BE_USB2_FORCE BIT(22)
+#define B_BE_USB3_FORCE BIT(21)
+#define B_BE_NO_PDN_CHIPOFF_V1 BIT(17)
+#define B_BE_RSM_EN_V1 BIT(16)
+#define B_BE_MATCH_CNT GENMASK(15, 8)
+
 #define R_BE_PMC_DBG_CTRL2 0x00CC
 #define B_BE_EFUSE_BURN_GNT_MASK GENMASK(31, 24)
 #define B_BE_DIS_IOWRAP_TIMEOUT BIT(16)
drivers/net/wireless/realtek/rtw89/usb.c +103 -9

178 lines not on this page · raw message

Signature · 1 line
2.53.0
maintainer Acked-by on v3 1/1
#1 lore raw
Quoted 13 lines · Bitterblue Smith

The Realtek wifi 6/7 devices which support USB 3 are weird: when first plugged in, they pretend to be USB 2. The driver needs to send some commands to the device, which make it disappear and come back as a USB 3 device.

Implement the required commands in rtw89.

Add a new function rtw89_usb_write32_quiet() to avoid the warnings when writing to R_{AX,BE}_PAD_CTRL2. Even though the write succeeds, usb_control_msg() returns -EPROTO, probably because the USB device disappears immediately. This results in some confusing warnings in the kernel log.

Quoted 3 lines

When a USB 3 device is plugged into a USB 2 port, rtw89 will try to switch it to USB 3 mode only once. The device will disappear and come back still in USB 2 mode, of course.

As we always try to switch USB 3, is it needed to add a hint to users to plug USB 2 port if he has a bad performance on 2GHz band?

Quoted 4 lines

Tested with RTL8832AU, RTL8832BU, RTL8832CU, and RTL8912AU.

Some minor suggestions. Otherwise,

[...]

Quoted 23 lines
drivers/net/wireless/realtek/rtw89/usb.c +2 -2
index c6d55e669776..bfe004a49ccc 100644
@@ -12,7 +12,7 @@
 static void rtw89_usb_read_port_complete(struct urb *urb);
 
 static void rtw89_usb_vendorreq(struct rtw89_dev *rtwdev, u32 addr,
-                               void *data, u16 len, u8 reqtype)
+                               void *data, u16 len, u8 reqtype, bool warn)
 {
        struct rtw89_usb *rtwusb = rtw89_usb_priv(rtwdev);
        struct usb_device *udev = rtwusb->udev;
@@ -52,7 +52,7 @@ static void rtw89_usb_vendorreq(struct rtw89_dev *rtwdev, u32 addr,
 
                if (ret == -ESHUTDOWN || ret == -ENODEV)
                        set_bit(RTW89_FLAG_UNPLUGGED, rtwdev->flags);
-               else if (ret < 0)
+               else if (ret < 0 && warn)
                        rtw89_warn(rtwdev,
                                   "usb %s%u 0x%x fail ret=%d value=0x%x attempt=%d\n",
                                   str_read_write(reqtype == RTW89_USB_VENQT_READ),

drivers/net/wireless/realtek/rtw89/usb.c static u32 rtw89_usb_read_cmac(struct rtw89_dev *rtwdev, u32 addr) · line 83

Quoted 5 lines
drivers/net/wireless/realtek/rtw89/usb.c +1 -1
@@ -80,7 +80,7 @@ static u32 rtw89_usb_read_cmac(struct rtw89_dev *rtwdev, u32 addr)
 
        for (count = 0; ; count++) {
                rtw89_usb_vendorreq(rtwdev, addr32, &data, 4,
-                                   RTW89_USB_VENQT_READ);
+                                   RTW89_USB_VENQT_READ, true);

Not sure if you like to implement a __rtw89_usb_vendorreq(), and preserve rtw89_usb_vendorreq() as a wrapper with original prototype. Then, no need to stir here.

I mean:

__rtw89_usb_vendorreq(..., bool warn);

static void rtw89_usb_vendorreq(struct rtw89_dev *rtwdev, u32 addr,
void *data, u16 len, u8 reqtype)

{
	__rtw89_usb_vendorreq(rtwdev, addr, data, len, reqtype, true);
}

(just a soft suggestion)

Quoted 3 lines
drivers/net/wireless/realtek/rtw89/usb.c +0 -0
                val32 = le32_to_cpu(data);
                if (val32 != RTW89_R32_DEAD)

[...]

#2 lore raw
Quoted 14 lines · Ping-Ke Shih
Quoted 13 lines · Bitterblue Smith

The Realtek wifi 6/7 devices which support USB 3 are weird: when first plugged in, they pretend to be USB 2. The driver needs to send some commands to the device, which make it disappear and come back as a USB 3 device.

Implement the required commands in rtw89.

Add a new function rtw89_usb_write32_quiet() to avoid the warnings when writing to R_{AX,BE}_PAD_CTRL2. Even though the write succeeds, usb_control_msg() returns -EPROTO, probably because the USB device disappears immediately. This results in some confusing warnings in the kernel log.

Quoted 7 lines
Quoted 3 lines

When a USB 3 device is plugged into a USB 2 port, rtw89 will try to switch it to USB 3 mode only once. The device will disappear and come back still in USB 2 mode, of course.

As we always try to switch USB 3, is it needed to add a hint to users to plug USB 2 port if he has a bad performance on 2GHz band?

I can add a message like "2.4 GHz performance may be better in a USB 2 port".

Quoted 48 lines
Quoted 4 lines

Tested with RTL8832AU, RTL8832BU, RTL8832CU, and RTL8912AU.

Some minor suggestions. Otherwise,

[...]

Quoted 23 lines
drivers/net/wireless/realtek/rtw89/usb.c +2 -2
index c6d55e669776..bfe004a49ccc 100644
@@ -12,7 +12,7 @@
 static void rtw89_usb_read_port_complete(struct urb *urb);
 
 static void rtw89_usb_vendorreq(struct rtw89_dev *rtwdev, u32 addr,
-                               void *data, u16 len, u8 reqtype)
+                               void *data, u16 len, u8 reqtype, bool warn)
 {
        struct rtw89_usb *rtwusb = rtw89_usb_priv(rtwdev);
        struct usb_device *udev = rtwusb->udev;
@@ -52,7 +52,7 @@ static void rtw89_usb_vendorreq(struct rtw89_dev *rtwdev, u32 addr,
 
                if (ret == -ESHUTDOWN || ret == -ENODEV)
                        set_bit(RTW89_FLAG_UNPLUGGED, rtwdev->flags);
-               else if (ret < 0)
+               else if (ret < 0 && warn)
                        rtw89_warn(rtwdev,
                                   "usb %s%u 0x%x fail ret=%d value=0x%x attempt=%d\n",
                                   str_read_write(reqtype == RTW89_USB_VENQT_READ),

drivers/net/wireless/realtek/rtw89/usb.c static u32 rtw89_usb_read_cmac(struct rtw89_dev *rtwdev, u32 addr) · line 83

Quoted 5 lines
drivers/net/wireless/realtek/rtw89/usb.c +1 -1
@@ -80,7 +80,7 @@ static u32 rtw89_usb_read_cmac(struct rtw89_dev *rtwdev, u32 addr)
 
        for (count = 0; ; count++) {
                rtw89_usb_vendorreq(rtwdev, addr32, &data, 4,
-                                   RTW89_USB_VENQT_READ);
+                                   RTW89_USB_VENQT_READ, true);

Not sure if you like to implement a __rtw89_usb_vendorreq(), and preserve rtw89_usb_vendorreq() as a wrapper with original prototype. Then, no need to stir here.

I mean:

__rtw89_usb_vendorreq(..., bool warn);

Quoted 8 lines

static void rtw89_usb_vendorreq(struct rtw89_dev *rtwdev, u32 addr,
void *data, u16 len, u8 reqtype)

{
	__rtw89_usb_vendorreq(rtwdev, addr, data, len, reqtype, true);
}

(just a soft suggestion)

Yes, that looks good.

Quoted 6 lines
Quoted 3 lines
drivers/net/wireless/realtek/rtw89/usb.c +0 -0
                val32 = le32_to_cpu(data);
                if (val32 != RTW89_R32_DEAD)

[...]

maintainer
#3 lore raw
Quoted 19 lines · Bitterblue Smith
Quoted 18 lines · Ping-Ke Shih
Quoted 16 lines · Bitterblue Smith

The Realtek wifi 6/7 devices which support USB 3 are weird: when first plugged in, they pretend to be USB 2. The driver needs to send some commands to the device, which make it disappear and come back as a USB 3 device.

Implement the required commands in rtw89.

Add a new function rtw89_usb_write32_quiet() to avoid the warnings when writing to R_{AX,BE}_PAD_CTRL2. Even though the write succeeds, usb_control_msg() returns -EPROTO, probably because the USB device disappears immediately. This results in some confusing warnings in the kernel log.

When a USB 3 device is plugged into a USB 2 port, rtw89 will try to switch it to USB 3 mode only once. The device will disappear and come back still in USB 2 mode, of course.

Quoted 6 lines
Quoted 3 lines

As we always try to switch USB 3, is it needed to add a hint to users to plug USB 2 port if he has a bad performance on 2GHz band?

I can add a message like "2.4 GHz performance may be better in a USB 2 port".

I suppose we should use rtw89_info().

I'll wait for v4.