diff mbox series

[rtw-next,v1,05/13] wifi: rtw89: Add hfc_param_ini_usb

Message ID 348b0c94-2db6-4ae9-819c-6fa7f9c3ac56@gmail.com
State New
Headers show
Series wifi: rtw89: Add support for USB devices | expand

Commit Message

Bitterblue Smith May 4, 2025, 8:51 p.m. UTC
Add hfc_param_ini_usb to struct rtw89_chip_info. For now initialise it
only for RTL8851B.

Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
---
 drivers/net/wireless/realtek/rtw89/core.h     |  1 +
 drivers/net/wireless/realtek/rtw89/mac.c      |  6 ++-
 drivers/net/wireless/realtek/rtw89/rtw8851b.c | 43 +++++++++++++++++++
 drivers/net/wireless/realtek/rtw89/rtw8852a.c |  1 +
 drivers/net/wireless/realtek/rtw89/rtw8852b.c |  1 +
 .../net/wireless/realtek/rtw89/rtw8852bt.c    |  1 +
 drivers/net/wireless/realtek/rtw89/rtw8852c.c |  1 +
 drivers/net/wireless/realtek/rtw89/rtw8922a.c |  1 +
 8 files changed, 54 insertions(+), 1 deletion(-)

Comments

Ping-Ke Shih May 13, 2025, 3:12 a.m. UTC | #1
Bitterblue Smith <rtl8821cerfe2@gmail.com> wrote:
> Add hfc_param_ini_usb to struct rtw89_chip_info. For now initialise it
> only for RTL8851B.
> 
> Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
> ---

[...]


> +
> +static const struct rtw89_hfc_param_ini rtw8851b_hfc_param_ini_usb[] = {
> +       [RTW89_QTA_SCC] = {rtw8851b_hfc_chcfg_usb, &rtw8851b_hfc_pubcfg_usb,
> +                          &rtw8851b_hfc_preccfg_usb, RTW89_HCIFC_STF},

[RTW89_QTA_WOW] is missing. I'm not sure if current can handle this correctly.
Could you try to do WoWLAN with USB? At least, it shouldn't crash. 


> +       [RTW89_QTA_DLFW] = {NULL, NULL,
> +                          &rtw8851b_hfc_preccfg_usb, RTW89_HCIFC_STF},
> +       [RTW89_QTA_INVALID] = {NULL},
> +};
> +
>  static const struct rtw89_dle_mem rtw8851b_dle_mem_pcie[] = {
>         [RTW89_QTA_SCC] = {RTW89_QTA_SCC, &rtw89_mac_size.wde_size6,
>                            &rtw89_mac_size.ple_size6, &rtw89_mac_size.wde_qt6,

[...]
Bitterblue Smith May 25, 2025, 9:55 p.m. UTC | #2
On 13/05/2025 06:12, Ping-Ke Shih wrote:
> Bitterblue Smith <rtl8821cerfe2@gmail.com> wrote:
>> Add hfc_param_ini_usb to struct rtw89_chip_info. For now initialise it
>> only for RTL8851B.
>>
>> Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
>> ---
> 
> [...]
> 
> 
>> +
>> +static const struct rtw89_hfc_param_ini rtw8851b_hfc_param_ini_usb[] = {
>> +       [RTW89_QTA_SCC] = {rtw8851b_hfc_chcfg_usb, &rtw8851b_hfc_pubcfg_usb,
>> +                          &rtw8851b_hfc_preccfg_usb, RTW89_HCIFC_STF},
> 
> [RTW89_QTA_WOW] is missing. I'm not sure if current can handle this correctly.
> Could you try to do WoWLAN with USB? At least, it shouldn't crash. 
> 

RTW89_QTA_WOW is missing because I didn't find an equivalent in
enum mac_ax_qta_mode in the vendor driver.

I enabled WOWLAN with this command:

iw phy0 wowlan enable disconnect

Then I put the computer to sleep (suspend to RAM). There was no crash,
just some error messages. The computer went to sleep and woke up without
any other problems. Of course it didn't stay connected to the access
point during sleep.

May 23 20:19:46 ideapad2 kernel: rtw89_8851bu 1-2:1.2: qta mode unmatch!
May 23 20:19:47 ideapad2 kernel: rtw89_8851bu 1-2:1.2: [ERR]get_dle_mem_cfg
May 23 20:19:47 ideapad2 kernel: rtw89_8851bu 1-2:1.2: [ERR]patch rx qta -22
May 23 20:19:47 ideapad2 kernel: rtw89_8851bu 1-2:1.2: failed to config mac
May 23 20:19:47 ideapad2 kernel: rtw89_8851bu 1-2:1.2: wow: failed to enable trx_post
May 23 20:19:47 ideapad2 kernel: rtw89_8851bu 1-2:1.2: failed to enable wow
May 23 20:19:47 ideapad2 kernel: rtw89_8851bu 1-2:1.2: failed to suspend for wow -22

That was without RTW89_QTA_WOW.

Then I tried to copy RTW89_QTA_SCC in rtw8851b_hfc_param_ini_usb and
rtw8851b_dle_mem_usb2. With that I think it was able to upload the WOW
firmware and it stayed connected to the access point, but something
didn't let the computer go to sleep. It sat there for several minutes
with a black screen, the power LED on, and connected to the access
point (but without an IP address), until I clicked the "Disconnect"
button in the access point's web interface to disconnect this station.
That's when the computer finally went to sleep.

So WOWLAN with RTL8851BU needs more work.

> 
>> +       [RTW89_QTA_DLFW] = {NULL, NULL,
>> +                          &rtw8851b_hfc_preccfg_usb, RTW89_HCIFC_STF},
>> +       [RTW89_QTA_INVALID] = {NULL},
>> +};
>> +
>>  static const struct rtw89_dle_mem rtw8851b_dle_mem_pcie[] = {
>>         [RTW89_QTA_SCC] = {RTW89_QTA_SCC, &rtw89_mac_size.wde_size6,
>>                            &rtw89_mac_size.ple_size6, &rtw89_mac_size.wde_qt6,
> 
> [...]
>
Ping-Ke Shih May 26, 2025, 1:51 a.m. UTC | #3
Bitterblue Smith <rtl8821cerfe2@gmail.com> wrote:
> On 13/05/2025 06:12, Ping-Ke Shih wrote:
> > Bitterblue Smith <rtl8821cerfe2@gmail.com> wrote:
> >> Add hfc_param_ini_usb to struct rtw89_chip_info. For now initialise it
> >> only for RTL8851B.
> >>
> >> Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
> >> ---
> >
> > [...]
> >
> >
> >> +
> >> +static const struct rtw89_hfc_param_ini rtw8851b_hfc_param_ini_usb[] = {
> >> +       [RTW89_QTA_SCC] = {rtw8851b_hfc_chcfg_usb, &rtw8851b_hfc_pubcfg_usb,
> >> +                          &rtw8851b_hfc_preccfg_usb, RTW89_HCIFC_STF},
> >
> > [RTW89_QTA_WOW] is missing. I'm not sure if current can handle this correctly.
> > Could you try to do WoWLAN with USB? At least, it shouldn't crash.
> >
> 
> RTW89_QTA_WOW is missing because I didn't find an equivalent in
> enum mac_ax_qta_mode in the vendor driver.

Yes, vendor driver doesn't have that. As I know, it does some modifications
from original normal operation quota, such as RTW89_QTA_SCC, because we want
constant definition in upstream driver. I will check internally and get back
to you how it should be for USB devices. 

> 
> I enabled WOWLAN with this command:
> 
> iw phy0 wowlan enable disconnect
> 
> Then I put the computer to sleep (suspend to RAM). There was no crash,
> just some error messages. The computer went to sleep and woke up without
> any other problems. Of course it didn't stay connected to the access
> point during sleep.
> 
> May 23 20:19:46 ideapad2 kernel: rtw89_8851bu 1-2:1.2: qta mode unmatch!
> May 23 20:19:47 ideapad2 kernel: rtw89_8851bu 1-2:1.2: [ERR]get_dle_mem_cfg
> May 23 20:19:47 ideapad2 kernel: rtw89_8851bu 1-2:1.2: [ERR]patch rx qta -22
> May 23 20:19:47 ideapad2 kernel: rtw89_8851bu 1-2:1.2: failed to config mac
> May 23 20:19:47 ideapad2 kernel: rtw89_8851bu 1-2:1.2: wow: failed to enable trx_post
> May 23 20:19:47 ideapad2 kernel: rtw89_8851bu 1-2:1.2: failed to enable wow
> May 23 20:19:47 ideapad2 kernel: rtw89_8851bu 1-2:1.2: failed to suspend for wow -22
> 
> That was without RTW89_QTA_WOW.
> 
> Then I tried to copy RTW89_QTA_SCC in rtw8851b_hfc_param_ini_usb and
> rtw8851b_dle_mem_usb2. With that I think it was able to upload the WOW
> firmware and it stayed connected to the access point, but something
> didn't let the computer go to sleep. It sat there for several minutes
> with a black screen, the power LED on, and connected to the access
> point (but without an IP address), until I clicked the "Disconnect"
> button in the access point's web interface to disconnect this station.
> That's when the computer finally went to sleep.
> 
> So WOWLAN with RTL8851BU needs more work.

Thanks for the test. I'd ask internal experts if USB devices can support
WoW already. But, I guess the answer is yes. Have you tested WoW with
vendor driver?
Ping-Ke Shih May 26, 2025, 6:29 a.m. UTC | #4
Ping-Ke Shih <pkshih@realtek.com> wrote:
> Bitterblue Smith <rtl8821cerfe2@gmail.com> wrote:
> > On 13/05/2025 06:12, Ping-Ke Shih wrote:
> > > Bitterblue Smith <rtl8821cerfe2@gmail.com> wrote:
> > >> Add hfc_param_ini_usb to struct rtw89_chip_info. For now initialise it
> > >> only for RTL8851B.
> > >>
> > >> Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
> > >> ---
> > >
> > > [...]
> > >
> > >
> > >> +
> > >> +static const struct rtw89_hfc_param_ini rtw8851b_hfc_param_ini_usb[] = {
> > >> +       [RTW89_QTA_SCC] = {rtw8851b_hfc_chcfg_usb, &rtw8851b_hfc_pubcfg_usb,
> > >> +                          &rtw8851b_hfc_preccfg_usb, RTW89_HCIFC_STF},
> > >
> > > [RTW89_QTA_WOW] is missing. I'm not sure if current can handle this correctly.
> > > Could you try to do WoWLAN with USB? At least, it shouldn't crash.
> > >
> >
> > RTW89_QTA_WOW is missing because I didn't find an equivalent in
> > enum mac_ax_qta_mode in the vendor driver.
> 
> Yes, vendor driver doesn't have that. As I know, it does some modifications
> from original normal operation quota, such as RTW89_QTA_SCC, because we want
> constant definition in upstream driver. I will check internally and get back
> to you how it should be for USB devices.

The main function to get QTA_WOW is redu_wowlan_rx_qta(). 

Take RTL8851BE as an example, 

Based on RTW89_QTA_SCC:
  cfg->ple_size->pge_size =>rtw89_mac_size.ple_size6
  =>.ple_size6 = {RTW89_PLE_PG_128, 496, 16,},
  rdu_pg_num = PLE_QTA_PG128B_12KB = 96

QTA6:
  .ple_qt18 = {147, 0, 16, 20, 17, 13, 89, 0, 32, 14, 8, 0,}, //min
  .ple_qt58 = {147, 0, 16, 20, 157, 13, 229, 0, 172, 14, 24, 0,}, //max
                                       ^^^^
  qta_min = 89
  qta_max = 229

  new_qta = (qta_max - qta_min) < rdu_pg_num ?
          qta_min : (qta_max - rdu_pg_num);
        = 229 - 96 = 133

QTA7:

  .ple_qt18 = {147, 0, 16, 20, 17, 13, 89, 0, 32, 14, 8, 0,}, //min
  .ple_qt58 = {147, 0, 16, 20, 157, 13, 229, 0, 172, 14, 24, 0,}, //max
                                           ^^^^

  qta_min = 0 
  qta_max = 0

  new_qta = (qta_max - qta_min) < rdu_pg_num ?
          qta_min : (qta_max - rdu_pg_num);
          = 0

Finally:

  .ple_qt_51b_wow = {147, 0, 16, 20, 157, 13, 133, 0, 172, 14, 24, 0,},
                                              ^^^^^^

A way is to induce the quota by eyes. Another way is to add debug message
in vendor driver to show these quota -- this would be much simpler.
Bitterblue Smith May 31, 2025, 8:54 p.m. UTC | #5
On 26/05/2025 04:51, Ping-Ke Shih wrote:
> Bitterblue Smith <rtl8821cerfe2@gmail.com> wrote:
>> On 13/05/2025 06:12, Ping-Ke Shih wrote:
>>> Bitterblue Smith <rtl8821cerfe2@gmail.com> wrote:
>>>> Add hfc_param_ini_usb to struct rtw89_chip_info. For now initialise it
>>>> only for RTL8851B.
>>>>
>>>> Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
>>>> ---
>>>
>>> [...]
>>>
>>>
>>>> +
>>>> +static const struct rtw89_hfc_param_ini rtw8851b_hfc_param_ini_usb[] = {
>>>> +       [RTW89_QTA_SCC] = {rtw8851b_hfc_chcfg_usb, &rtw8851b_hfc_pubcfg_usb,
>>>> +                          &rtw8851b_hfc_preccfg_usb, RTW89_HCIFC_STF},
>>>
>>> [RTW89_QTA_WOW] is missing. I'm not sure if current can handle this correctly.
>>> Could you try to do WoWLAN with USB? At least, it shouldn't crash.
>>>
>>
>> RTW89_QTA_WOW is missing because I didn't find an equivalent in
>> enum mac_ax_qta_mode in the vendor driver.
> 
> Yes, vendor driver doesn't have that. As I know, it does some modifications
> from original normal operation quota, such as RTW89_QTA_SCC, because we want
> constant definition in upstream driver. I will check internally and get back
> to you how it should be for USB devices. 
> 
>>
>> I enabled WOWLAN with this command:
>>
>> iw phy0 wowlan enable disconnect
>>
>> Then I put the computer to sleep (suspend to RAM). There was no crash,
>> just some error messages. The computer went to sleep and woke up without
>> any other problems. Of course it didn't stay connected to the access
>> point during sleep.
>>
>> May 23 20:19:46 ideapad2 kernel: rtw89_8851bu 1-2:1.2: qta mode unmatch!
>> May 23 20:19:47 ideapad2 kernel: rtw89_8851bu 1-2:1.2: [ERR]get_dle_mem_cfg
>> May 23 20:19:47 ideapad2 kernel: rtw89_8851bu 1-2:1.2: [ERR]patch rx qta -22
>> May 23 20:19:47 ideapad2 kernel: rtw89_8851bu 1-2:1.2: failed to config mac
>> May 23 20:19:47 ideapad2 kernel: rtw89_8851bu 1-2:1.2: wow: failed to enable trx_post
>> May 23 20:19:47 ideapad2 kernel: rtw89_8851bu 1-2:1.2: failed to enable wow
>> May 23 20:19:47 ideapad2 kernel: rtw89_8851bu 1-2:1.2: failed to suspend for wow -22
>>
>> That was without RTW89_QTA_WOW.
>>
>> Then I tried to copy RTW89_QTA_SCC in rtw8851b_hfc_param_ini_usb and
>> rtw8851b_dle_mem_usb2. With that I think it was able to upload the WOW
>> firmware and it stayed connected to the access point, but something
>> didn't let the computer go to sleep. It sat there for several minutes
>> with a black screen, the power LED on, and connected to the access
>> point (but without an IP address), until I clicked the "Disconnect"
>> button in the access point's web interface to disconnect this station.
>> That's when the computer finally went to sleep.
>>
>> So WOWLAN with RTL8851BU needs more work.
> 
> Thanks for the test. I'd ask internal experts if USB devices can support
> WoW already. But, I guess the answer is yes. Have you tested WoW with
> vendor driver? 
> 
> 

Yes, it works. I can wake up the computer with a Magic Packet.
Bitterblue Smith May 31, 2025, 8:57 p.m. UTC | #6
On 26/05/2025 09:29, Ping-Ke Shih wrote:
> Ping-Ke Shih <pkshih@realtek.com> wrote:
>> Bitterblue Smith <rtl8821cerfe2@gmail.com> wrote:
>>> On 13/05/2025 06:12, Ping-Ke Shih wrote:
>>>> Bitterblue Smith <rtl8821cerfe2@gmail.com> wrote:
>>>>> Add hfc_param_ini_usb to struct rtw89_chip_info. For now initialise it
>>>>> only for RTL8851B.
>>>>>
>>>>> Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
>>>>> ---
>>>>
>>>> [...]
>>>>
>>>>
>>>>> +
>>>>> +static const struct rtw89_hfc_param_ini rtw8851b_hfc_param_ini_usb[] = {
>>>>> +       [RTW89_QTA_SCC] = {rtw8851b_hfc_chcfg_usb, &rtw8851b_hfc_pubcfg_usb,
>>>>> +                          &rtw8851b_hfc_preccfg_usb, RTW89_HCIFC_STF},
>>>>
>>>> [RTW89_QTA_WOW] is missing. I'm not sure if current can handle this correctly.
>>>> Could you try to do WoWLAN with USB? At least, it shouldn't crash.
>>>>
>>>
>>> RTW89_QTA_WOW is missing because I didn't find an equivalent in
>>> enum mac_ax_qta_mode in the vendor driver.
>>
>> Yes, vendor driver doesn't have that. As I know, it does some modifications
>> from original normal operation quota, such as RTW89_QTA_SCC, because we want
>> constant definition in upstream driver. I will check internally and get back
>> to you how it should be for USB devices.
> 
> The main function to get QTA_WOW is redu_wowlan_rx_qta(). 
> 
> Take RTL8851BE as an example, 
> 
> Based on RTW89_QTA_SCC:
>   cfg->ple_size->pge_size =>rtw89_mac_size.ple_size6
>   =>.ple_size6 = {RTW89_PLE_PG_128, 496, 16,},
>   rdu_pg_num = PLE_QTA_PG128B_12KB = 96
> 
> QTA6:
>   .ple_qt18 = {147, 0, 16, 20, 17, 13, 89, 0, 32, 14, 8, 0,}, //min
>   .ple_qt58 = {147, 0, 16, 20, 157, 13, 229, 0, 172, 14, 24, 0,}, //max
>                                        ^^^^
>   qta_min = 89
>   qta_max = 229
> 
>   new_qta = (qta_max - qta_min) < rdu_pg_num ?
>           qta_min : (qta_max - rdu_pg_num);
>         = 229 - 96 = 133
> 
> QTA7:
> 
>   .ple_qt18 = {147, 0, 16, 20, 17, 13, 89, 0, 32, 14, 8, 0,}, //min
>   .ple_qt58 = {147, 0, 16, 20, 157, 13, 229, 0, 172, 14, 24, 0,}, //max
>                                            ^^^^
> 
>   qta_min = 0 
>   qta_max = 0
> 
>   new_qta = (qta_max - qta_min) < rdu_pg_num ?
>           qta_min : (qta_max - rdu_pg_num);
>           = 0
> 
> Finally:
> 
>   .ple_qt_51b_wow = {147, 0, 16, 20, 157, 13, 133, 0, 172, 14, 24, 0,},
>                                               ^^^^^^
> 
> A way is to induce the quota by eyes. Another way is to add debug message
> in vendor driver to show these quota -- this would be much simpler. 
> 
> 

Thank you for the explanation. I calculated the quotas like you showed
above and got WOWLAN to work with RTL8851BU. Well, it goes to sleep
and I can wake it up with a Magic Packet, but there are still problems:

1) "c2h reg timeout" error from rtw89_wow_suspend() ->
rtw89_wow_enable() -> rtw89_wow_enable_trx_post() ->
rtw89_wow_config_mac() -> rtw89_wow_config_mac_ax() ->
rtw89_mac_cpu_io_rx() -> rtw89_fw_msg_reg().

The vendor driver doesn't have this problem.

2) It takes ~250 seconds for the above "c2h reg timeout" error to appear
because rtw89_fw_read_c2h_reg() doesn't take into account that it takes
~250 µs to send a USB control message. It uses read_poll_timeout_atomic()
with a timeout of 1000000 µs and a delay of 1 µs. Changing the delay to
250 µs makes read_poll_timeout_atomic() finish after just 2 seconds.

3) There is a warning when the computer wakes up:

May 28 23:14:59 ideapad2 kernel: ------------[ cut here ]------------
May 28 23:14:59 ideapad2 kernel: WARNING: CPU: 2 PID: 3124 at net/mac80211/iface.c:680 ieee80211_do_stop+0x936/0x950 [mac80211]
May 28 23:14:59 ideapad2 kernel: Modules linked in: ccm rtw89_8852bu(OE) rtw89_8851bu(OE) rtw89_8852b(OE) rtw89_8851b(OE) rtw89_8852b_common(OE) rtw89_usb(OE) rtw89_core(>
May 28 23:14:59 ideapad2 kernel:  snd_hda_codec mousedev sha512_ssse3 snd_rpl_pci_acp6x snd_acp_pci sha256_ssse3 sha1_ssse3 ee1004 snd_hda_core snd_acp_legacy_common snd_>
May 28 23:14:59 ideapad2 kernel: Unloaded tainted modules: 8851bu(OE):1 [last unloaded: 8851bu(OE)]
May 28 23:14:59 ideapad2 kernel: CPU: 2 UID: 0 PID: 3124 Comm: kworker/u16:31 Tainted: G           OE      6.14.2-arch1-1 #1 51440b8a0cc8bb91764dac94f6c2b53455e5a907
May 28 23:14:59 ideapad2 kernel: Tainted: [O]=OOT_MODULE, [E]=UNSIGNED_MODULE
May 28 23:14:59 ideapad2 kernel: Hardware name: LENOVO 82KR/LNVNB161216, BIOS HBCN18WW 08/27/2021
May 28 23:14:59 ideapad2 kernel: Workqueue: async async_run_entry_fn
May 28 23:14:59 ideapad2 kernel: RIP: 0010:ieee80211_do_stop+0x936/0x950 [mac80211]
May 28 23:14:59 ideapad2 kernel: Code: 34 ea e9 92 f9 ff ff 0f b7 f0 48 c7 c7 60 d0 28 c2 e8 9e 1b 3e e9 0f 0b e9 89 f8 ff ff 4c 89 e7 e8 7f f3 ff ff e9 03 fd ff ff <0f> >
May 28 23:14:59 ideapad2 kernel: RSP: 0018:ffff97e05b28ba80 EFLAGS: 00010202
May 28 23:14:59 ideapad2 kernel: RAX: 0000000000000004 RBX: ffff8cc46a388a80 RCX: 0000000000000000
May 28 23:14:59 ideapad2 kernel: RDX: 0000000000000001 RSI: 0000000000000000 RDI: ffff8cc51c4810ec
May 28 23:14:59 ideapad2 kernel: RBP: ffff97e05b28bb20 R08: ffff8cc5783ad200 R09: 000000008010000d
May 28 23:14:59 ideapad2 kernel: R10: 000000008010000d R11: 0000000000000246 R12: ffff8cc51c480900
May 28 23:14:59 ideapad2 kernel: R13: ffff97e05b28bab0 R14: ffff97e05b28bab0 R15: 0000000000000000
May 28 23:14:59 ideapad2 kernel: FS:  0000000000000000(0000) GS:ffff8cc653500000(0000) knlGS:0000000000000000
May 28 23:14:59 ideapad2 kernel: CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
May 28 23:14:59 ideapad2 kernel: CR2: 0000000000000000 CR3: 0000000140822000 CR4: 00000000003506f0
May 28 23:14:59 ideapad2 kernel: Call Trace:
May 28 23:14:59 ideapad2 kernel:  <TASK>
May 28 23:14:59 ideapad2 kernel:  ? psi_group_change+0x13b/0x310
May 28 23:14:59 ideapad2 kernel:  ieee80211_stop+0x5b/0x1a0 [mac80211 682e229732a6bfe53cb0bbcde81ec2801d27c374]
May 28 23:14:59 ideapad2 kernel:  __dev_close_many+0xaa/0x150
May 28 23:14:59 ideapad2 kernel:  dev_close_many+0xbe/0x1a0
May 28 23:14:59 ideapad2 kernel:  dev_close+0x6f/0xa0
May 28 23:14:59 ideapad2 kernel:  cfg80211_shutdown_all_interfaces+0x4d/0xf0 [cfg80211 fca8a1144424bca742e19d88b98aa1afb064fec0]
May 28 23:14:59 ideapad2 kernel:  ieee80211_remove_interfaces+0x4d/0x230 [mac80211 682e229732a6bfe53cb0bbcde81ec2801d27c374]
May 28 23:14:59 ideapad2 kernel:  ? __pfx_wait_rcu_exp_gp+0x10/0x10
May 28 23:14:59 ideapad2 kernel:  ieee80211_unregister_hw+0x4a/0x130 [mac80211 682e229732a6bfe53cb0bbcde81ec2801d27c374]
May 28 23:14:59 ideapad2 kernel:  rtw89_core_unregister+0x3a/0x50 [rtw89_core 6d9cf325b1126b69ab43ddd6b0b9a561d4ea24f8]
May 28 23:14:59 ideapad2 kernel:  rtw89_usb_disconnect+0x53/0xe0 [rtw89_usb 2cf966e0c4b7fe950d436a899adc081e9902c1d8]
May 28 23:14:59 ideapad2 kernel:  usb_unbind_interface+0x90/0x290
May 28 23:14:59 ideapad2 kernel:  device_release_driver_internal+0x19c/0x200
May 28 23:14:59 ideapad2 kernel:  ? __pfx_usb_dev_resume+0x10/0x10
May 28 23:14:59 ideapad2 kernel:  usb_forced_unbind_intf+0x75/0xb0
May 28 23:14:59 ideapad2 kernel:  ? __pfx_usb_dev_resume+0x10/0x10
May 28 23:14:59 ideapad2 kernel:  unbind_marked_interfaces.isra.0+0x59/0x80
May 28 23:14:59 ideapad2 kernel:  usb_resume+0x5a/0x60
May 28 23:14:59 ideapad2 kernel:  dpm_run_callback+0x48/0x150
May 28 23:14:59 ideapad2 kernel:  device_resume+0x140/0x240
May 28 23:14:59 ideapad2 kernel:  async_resume+0x1d/0x30
May 28 23:14:59 ideapad2 kernel:  async_run_entry_fn+0x31/0x140
May 28 23:14:59 ideapad2 kernel:  process_one_work+0x17b/0x330
May 28 23:14:59 ideapad2 kernel:  worker_thread+0x2ce/0x3f0
May 28 23:14:59 ideapad2 kernel:  ? __pfx_worker_thread+0x10/0x10
May 28 23:14:59 ideapad2 kernel:  kthread+0xec/0x230
May 28 23:14:59 ideapad2 kernel:  ? __pfx_kthread+0x10/0x10
May 28 23:14:59 ideapad2 kernel:  ret_from_fork+0x31/0x50
May 28 23:14:59 ideapad2 kernel:  ? __pfx_kthread+0x10/0x10
May 28 23:14:59 ideapad2 kernel:  ret_from_fork_asm+0x1a/0x30
May 28 23:14:59 ideapad2 kernel:  </TASK>
May 28 23:14:59 ideapad2 kernel: ---[ end trace 0000000000000000 ]---

It's this one in ieee80211_do_stop():

	/*
	 * If the interface goes down while suspended, presumably because
	 * the device was unplugged and that happens before our resume,
	 * then the driver is already unconfigured and the remainder of
	 * this function isn't needed.
	 * XXX: what about WoWLAN? If the device has software state, e.g.
	 *	memory allocated, it might expect teardown commands from
	 *	mac80211 here?
	 */
	if (local->suspended) {
		WARN_ON(local->wowlan);

I would like to leave the WOWLAN fixes for later, to keep this set of
patches small.
diff mbox series

Patch

diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h
index 335d2314699b..f17f046e773f 100644
--- a/drivers/net/wireless/realtek/rtw89/core.h
+++ b/drivers/net/wireless/realtek/rtw89/core.h
@@ -4273,6 +4273,7 @@  struct rtw89_chip_info {
 	bool dis_2g_40m_ul_ofdma;
 	u32 rsvd_ple_ofst;
 	const struct rtw89_hfc_param_ini *hfc_param_ini_pcie;
+	const struct rtw89_hfc_param_ini *hfc_param_ini_usb;
 	const struct rtw89_dle_mem *dle_mem_pcie;
 	const struct rtw89_dle_mem *dle_mem_usb2;
 	const struct rtw89_dle_mem *dle_mem_usb3;
diff --git a/drivers/net/wireless/realtek/rtw89/mac.c b/drivers/net/wireless/realtek/rtw89/mac.c
index 4a5d1a5926e9..a316864ad137 100644
--- a/drivers/net/wireless/realtek/rtw89/mac.c
+++ b/drivers/net/wireless/realtek/rtw89/mac.c
@@ -882,12 +882,16 @@  static int hfc_reset_param(struct rtw89_dev *rtwdev)
 	switch (rtwdev->hci.type) {
 	case RTW89_HCI_TYPE_PCIE:
 		param_ini = rtwdev->chip->hfc_param_ini_pcie[qta_mode];
-		param->en = 0;
+		break;
+	case RTW89_HCI_TYPE_USB:
+		param_ini = rtwdev->chip->hfc_param_ini_usb[qta_mode];
 		break;
 	default:
 		return -EINVAL;
 	}
 
+	param->en = 0;
+
 	if (param_ini.pub_cfg)
 		param->pub_cfg = *param_ini.pub_cfg;
 
diff --git a/drivers/net/wireless/realtek/rtw89/rtw8851b.c b/drivers/net/wireless/realtek/rtw89/rtw8851b.c
index d42bfdcac849..35417cdde8d5 100644
--- a/drivers/net/wireless/realtek/rtw89/rtw8851b.c
+++ b/drivers/net/wireless/realtek/rtw89/rtw8851b.c
@@ -51,6 +51,48 @@  static const struct rtw89_hfc_param_ini rtw8851b_hfc_param_ini_pcie[] = {
 	[RTW89_QTA_INVALID] = {NULL},
 };
 
+static const struct rtw89_hfc_ch_cfg rtw8851b_hfc_chcfg_usb[] = {
+	{18, 152, grp_0}, /* ACH 0 */
+	{18, 152, grp_0}, /* ACH 1 */
+	{18, 152, grp_0}, /* ACH 2 */
+	{18, 152, grp_0}, /* ACH 3 */
+	{0, 0, grp_0}, /* ACH 4 */
+	{0, 0, grp_0}, /* ACH 5 */
+	{0, 0, grp_0}, /* ACH 6 */
+	{0, 0, grp_0}, /* ACH 7 */
+	{18, 152, grp_0}, /* B0MGQ */
+	{18, 152, grp_0}, /* B0HIQ */
+	{0, 0, grp_0}, /* B1MGQ */
+	{0, 0, grp_0}, /* B1HIQ */
+	{0, 0, 0} /* FWCMDQ */
+};
+
+static const struct rtw89_hfc_pub_cfg rtw8851b_hfc_pubcfg_usb = {
+	152, /* Group 0 */
+	0, /* Group 1 */
+	152, /* Public Max */
+	0 /* WP threshold */
+};
+
+static const struct rtw89_hfc_prec_cfg rtw8851b_hfc_preccfg_usb = {
+	9, /* CH 0-11 pre-cost */
+	32, /* H2C pre-cost */
+	64, /* WP CH 0-7 pre-cost */
+	24, /* WP CH 8-11 pre-cost */
+	1, /* CH 0-11 full condition */
+	1, /* H2C full condition */
+	1, /* WP CH 0-7 full condition */
+	1, /* WP CH 8-11 full condition */
+};
+
+static const struct rtw89_hfc_param_ini rtw8851b_hfc_param_ini_usb[] = {
+	[RTW89_QTA_SCC] = {rtw8851b_hfc_chcfg_usb, &rtw8851b_hfc_pubcfg_usb,
+			   &rtw8851b_hfc_preccfg_usb, RTW89_HCIFC_STF},
+	[RTW89_QTA_DLFW] = {NULL, NULL,
+			   &rtw8851b_hfc_preccfg_usb, RTW89_HCIFC_STF},
+	[RTW89_QTA_INVALID] = {NULL},
+};
+
 static const struct rtw89_dle_mem rtw8851b_dle_mem_pcie[] = {
 	[RTW89_QTA_SCC] = {RTW89_QTA_SCC, &rtw89_mac_size.wde_size6,
 			   &rtw89_mac_size.ple_size6, &rtw89_mac_size.wde_qt6,
@@ -2491,6 +2533,7 @@  const struct rtw89_chip_info rtw8851b_chip_info = {
 	.dis_2g_40m_ul_ofdma	= true,
 	.rsvd_ple_ofst		= 0x2f800,
 	.hfc_param_ini_pcie	= rtw8851b_hfc_param_ini_pcie,
+	.hfc_param_ini_usb	= rtw8851b_hfc_param_ini_usb,
 	.dle_mem_pcie		= rtw8851b_dle_mem_pcie,
 	.dle_mem_usb2		= rtw8851b_dle_mem_usb2,
 	.dle_mem_usb3		= rtw8851b_dle_mem_usb3,
diff --git a/drivers/net/wireless/realtek/rtw89/rtw8852a.c b/drivers/net/wireless/realtek/rtw89/rtw8852a.c
index b4be32ba8d37..9d0cb83d15a0 100644
--- a/drivers/net/wireless/realtek/rtw89/rtw8852a.c
+++ b/drivers/net/wireless/realtek/rtw89/rtw8852a.c
@@ -2184,6 +2184,7 @@  const struct rtw89_chip_info rtw8852a_chip_info = {
 	.dis_2g_40m_ul_ofdma	= true,
 	.rsvd_ple_ofst		= 0x6f800,
 	.hfc_param_ini_pcie	= rtw8852a_hfc_param_ini_pcie,
+	.hfc_param_ini_usb	= NULL,
 	.dle_mem_pcie		= rtw8852a_dle_mem_pcie,
 	.dle_mem_usb2		= NULL,
 	.dle_mem_usb3		= NULL,
diff --git a/drivers/net/wireless/realtek/rtw89/rtw8852b.c b/drivers/net/wireless/realtek/rtw89/rtw8852b.c
index cde7965860e8..9349d1a34bf6 100644
--- a/drivers/net/wireless/realtek/rtw89/rtw8852b.c
+++ b/drivers/net/wireless/realtek/rtw89/rtw8852b.c
@@ -820,6 +820,7 @@  const struct rtw89_chip_info rtw8852b_chip_info = {
 	.dis_2g_40m_ul_ofdma	= true,
 	.rsvd_ple_ofst		= 0x2f800,
 	.hfc_param_ini_pcie	= rtw8852b_hfc_param_ini_pcie,
+	.hfc_param_ini_usb	= NULL,
 	.dle_mem_pcie		= rtw8852b_dle_mem_pcie,
 	.dle_mem_usb2		= NULL,
 	.dle_mem_usb3		= NULL,
diff --git a/drivers/net/wireless/realtek/rtw89/rtw8852bt.c b/drivers/net/wireless/realtek/rtw89/rtw8852bt.c
index 35624f17de6d..e32c6a1a25a8 100644
--- a/drivers/net/wireless/realtek/rtw89/rtw8852bt.c
+++ b/drivers/net/wireless/realtek/rtw89/rtw8852bt.c
@@ -754,6 +754,7 @@  const struct rtw89_chip_info rtw8852bt_chip_info = {
 	.dis_2g_40m_ul_ofdma	= true,
 	.rsvd_ple_ofst		= 0x6f800,
 	.hfc_param_ini_pcie	= rtw8852bt_hfc_param_ini_pcie,
+	.hfc_param_ini_usb	= NULL,
 	.dle_mem_pcie		= rtw8852bt_dle_mem_pcie,
 	.dle_mem_usb2		= NULL,
 	.dle_mem_usb3		= NULL,
diff --git a/drivers/net/wireless/realtek/rtw89/rtw8852c.c b/drivers/net/wireless/realtek/rtw89/rtw8852c.c
index f96bc3036578..edbfca5bee3f 100644
--- a/drivers/net/wireless/realtek/rtw89/rtw8852c.c
+++ b/drivers/net/wireless/realtek/rtw89/rtw8852c.c
@@ -3004,6 +3004,7 @@  const struct rtw89_chip_info rtw8852c_chip_info = {
 	.dis_2g_40m_ul_ofdma	= false,
 	.rsvd_ple_ofst		= 0x6f800,
 	.hfc_param_ini_pcie	= rtw8852c_hfc_param_ini_pcie,
+	.hfc_param_ini_usb	= NULL,
 	.dle_mem_pcie		= rtw8852c_dle_mem_pcie,
 	.dle_mem_usb2		= NULL,
 	.dle_mem_usb3		= NULL,
diff --git a/drivers/net/wireless/realtek/rtw89/rtw8922a.c b/drivers/net/wireless/realtek/rtw89/rtw8922a.c
index ee2a664a7cce..59e7e7a4d829 100644
--- a/drivers/net/wireless/realtek/rtw89/rtw8922a.c
+++ b/drivers/net/wireless/realtek/rtw89/rtw8922a.c
@@ -2816,6 +2816,7 @@  const struct rtw89_chip_info rtw8922a_chip_info = {
 	.dis_2g_40m_ul_ofdma	= false,
 	.rsvd_ple_ofst		= 0x8f800,
 	.hfc_param_ini_pcie	= rtw8922a_hfc_param_ini_pcie,
+	.hfc_param_ini_usb	= NULL,
 	.dle_mem_pcie		= rtw8922a_dle_mem_pcie,
 	.dle_mem_usb2		= NULL,
 	.dle_mem_usb3		= NULL,