On 11/25/19 6:02 PM, Stanislaw Gruszka wrote: > On Mon, Nov 25, 2019 at 04:32:42PM +0100, Markus Theil wrote: >> On 11/25/19 3:51 PM, Markus Theil wrote: >>> On 11/25/19 2:04 PM, Stanislaw Gruszka wrote: >>>> On Thu, Nov 21, 2019 at 07:00:01PM +0100, Markus Theil wrote: >>>>> diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_usb_core.c b/drivers/net/wireless/mediatek/mt76/mt76x02_usb_core.c >>>>> index 90c024f12302..b9bd6bfb2a9d 100644 >>>>> --- a/drivers/net/wireless/mediatek/mt76/mt76x02_usb_core.c >>>>> +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_usb_core.c >>>>> @@ -210,6 +210,12 @@ static void mt76x02u_pre_tbtt_work(struct work_struct *work) >>>>> >>>>> mt76x02_mac_set_beacon_prepare(dev); >>>>> >>>>> + mt76_csa_check(&dev->mt76); >>>>> + if (dev->mt76.csa_complete) { >>>>> + mt76_csa_finish(&dev->mt76); >>>>> + goto out; >>>>> + } >>>> mmio counterpart setup beacons on CSA, but do not sent buffered >>>> PS frames. Perhaps here we should do the same. However not sending >>>> beacons on one TBTT looks ok to me as well. >>>> >>>> Stanislaw >>>> >>> If I change the order of beacon iteration and csa check, the following warning in mac80211 gets triggered: >>> >>> /* the counter should never reach 0 */ >>> WARN_ON_ONCE(!beacon->csa_current_counter); >>> >>> Dmesg output looks like this: >>> >>> [ 153.829617] ------------[ cut here ]------------ >>> [ 153.829752] WARNING: CPU: 0 PID: 224 at net/mac80211/tx.c:4318 __ieee80211_csa_update_counter.isra.0.part.0+0x5/0x10 [mac80211] >>> [ 153.829756] Modules linked in: ccm bridge stp llc nft_masq nft_chain_nat nf_nat nft_reject_inet nf_reject_ipv4 nf_reject_ipv6 nft_reject nft_ct nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 libcrc32c nf_tables_set nf_tables nfnetlink ath10k_pci amd64_edac_mod mt76x2u edac_mce_amd mt76x2_common ath10k_core mt76x02_usb kvm_amd mt76_usb mt76x02_lib mt76 kvm ath mac80211 irqbypass crct10dif_pclmul crc32_pclmul ghash_clmulni_intel cfg80211 pcengines_apuv2 gpio_keys_polled aesni_intel input_polldev crypto_simd gpio_amd_fch cryptd glue_helper igb pcspkr k10temp fam15h_power rfkill sp5100_tco i2c_piix4 libarc4 ccp i2c_algo_bit dca rng_core uio_pdrv_genirq uio leds_gpio evdev mac_hid pinctrl_amd coreboot_table acpi_cpufreq ip_tables x_tables ext4 crc32c_generic crc16 mbcache jbd2 sd_mod ahci sdhci_pci libahci cqhci libata sdhci crc32c_intel xhci_pci ehci_pci mmc_core xhci_hcd scsi_mod ehci_hcd gpio_keys >>> [ 153.829948] CPU: 0 PID: 224 Comm: kworker/0:1H Not tainted 5.4.0-rc7-1-01110-g19b7e21c55c8 #32 >>> [ 153.829952] Hardware name: PC Engines apu2/apu2, BIOS v4.10.0.3 11/07/2019 >>> [ 153.829966] Workqueue: events_highpri mt76x02u_pre_tbtt_work [mt76x02_usb] >>> [ 153.830067] RIP: 0010:__ieee80211_csa_update_counter.isra.0.part.0+0x5/0x10 [mac80211] >>> [ 153.830077] Code: 4c 89 4a 18 c3 48 8b 47 10 4c 89 4f 10 48 89 4e 18 48 89 46 20 4c 89 08 eb a1 66 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 <0f> 0b c3 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 41 54 53 48 89 fb >>> [ 153.830082] RSP: 0018:ffffbde8803d7c80 EFLAGS: 00010246 >>> [ 153.830089] RAX: 0000000000000003 RBX: ffffbde8803d7d20 RCX: ffffa3b01df8f658 >>> [ 153.830093] RDX: ffffbde8803d7d20 RSI: ffffa3b02901d450 RDI: ffffbde8803d7ce0 >>> [ 153.830097] RBP: ffffa3b0267007a0 R08: ffffffff8d011040 R09: 0000000000000000 >>> [ 153.830101] R10: ffffa3b029908098 R11: ffffa3b02ab2ab38 R12: 0000000000000000 >>> [ 153.830105] R13: ffffa3b02901d450 R14: 0000000000000000 R15: ffffa3b0284eae00 >>> [ 153.830111] FS: 0000000000000000(0000) GS:ffffa3b02aa00000(0000) knlGS:0000000000000000 >>> [ 153.830115] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 >>> [ 153.830119] CR2: 00007fbb6b5c9f30 CR3: 0000000126ee2000 CR4: 00000000000406f0 >>> [ 153.830124] Call Trace: >>> [ 153.830203] __ieee80211_beacon_get+0x4c2/0x4d0 [mac80211] >>> [ 153.830312] ieee80211_beacon_get_tim+0x41/0x150 [mac80211] >>> [ 153.830336] mt76x02_update_beacon_iter+0x2d/0x40 [mt76x02_lib] >>> [ 153.830352] ? mt76x02_add_buffered_bc+0x80/0x80 [mt76x02_lib] >>> [ 153.830420] __iterate_interfaces+0x74/0x110 [mac80211] >>> [ 153.830469] ? mt76x02_add_buffered_bc+0x80/0x80 [mt76x02_lib] >>> [ 153.830566] ieee80211_iterate_interfaces+0x3a/0x50 [mac80211] >>> [ 153.830580] mt76x02u_pre_tbtt_work+0x96/0x220 [mt76x02_usb] >>> [ 153.830600] process_one_work+0x1e2/0x3b0 >>> [ 153.830610] worker_thread+0x4a/0x3d0 >>> [ 153.830623] kthread+0xfb/0x130 >>> [ 153.830631] ? process_one_work+0x3b0/0x3b0 >>> [ 153.830639] ? kthread_park+0x90/0x90 >>> [ 153.830650] ret_from_fork+0x22/0x40 >>> [ 153.830665] ---[ end trace 7a658e5cbfd0f9d1 ]--- >>> >>> Markus >>> >> In my current local changes I've decoupled checking csa_check and mt76_csa_finish, like it is in the mmio case. As usb has no tbtt interrupt, >> I just schedule a delayed work around the estimated beacon transmission time and finish csa there. I'll send another series, if this works. > I would prefer not to add yet another delayed work. Does the warning > still happen if you arrange code like this? > > mt76x02_mac_set_beacon_prepare(dev); > > ieee80211_iterate_active_interfaces(mt76_hw(dev), > IEEE80211_IFACE_ITER_RESUME_ALL, > mt76x02_update_beacon_iter, dev); > > mt76_csa_check(&dev->mt76); > if (dev->mt76.csa_complete) { > mt76_csa_finish(&dev->mt76); > goto out; > } > > nbeacons = hweight8(dev->mt76.beacon_mask); > mt76x02_enqueue_buffered_bc(dev, &data, N_BCN_SLOTS - nbeacons); > ... > out: > mt76x02_mac_set_beacon_finish(dev); > mt76x02u_restart_pre_tbtt_timer(dev); > > You're code works, if I add some locking. ieee80211_iterate_active_interfaces -> ieee80211_iterate_active_interfaces_atomic did the trick for me. Otherwise I get the dmesg output from above. After using ieee80211_iterate_active_interfaces_atomic I got the following dmesg output after/while a channel switch: [ 63.115806] divide error: 0000 [#1] PREEMPT SMP NOPTI [ 63.121054] CPU: 0 PID: 225 Comm: kworker/u8:2 Tainted: G W 5.4.0-rc7-1-01110-g19b7e21c55c8 #39 [ 63.131331] Hardware name: PC Engines apu2/apu2, BIOS v4.10.0.3 11/07/2019 [ 63.138399] Workqueue: mt76u mt76u_tx_status_data [mt76_usb] [ 63.144258] RIP: 0010:mt76_calc_rx_airtime+0x12b/0x150 [mt76] [ 63.150281] Code: 8d 34 76 48 8d 34 b1 0f b6 4e 07 66 85 c9 74 25 66 83 f9 01 75 1c b9 24 00 00 00 89 d0 0f b7 76 04 c1 e0 05 8d 04 d0 01 c0 99 <f7> fe 01 c8 c3 31 c0 c3 0f 0b c3 44 89 c8 83 e0 01 3c 01 19 c9 83 [ 63.169699] RSP: 0018:ffffbd694032fcf0 EFLAGS: 00010216 [ 63.175176] RAX: 0000000000002850 RBX: 0000000000000001 RCX: 00000000000000ca [ 63.182535] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffffa20068253538 [ 63.189983] RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000 [ 63.197381] R10: 0000000000000000 R11: ffffbd694032fcb0 R12: ffffbd694032fdb0 [ 63.204782] R13: 0000000000000000 R14: ffffbd694032fd00 R15: ffffa20068251e40 [ 63.212228] FS: 0000000000000000(0000) GS:ffffa2006aa00000(0000) knlGS:0000000000000000 [ 63.220614] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 63.226500] CR2: 00007fe65ba85cb0 CR3: 00000001293b6000 CR4: 00000000000406f0 [ 63.233841] Call Trace: [ 63.236410] mt76_calc_tx_airtime+0xf4/0x190 [mt76] [ 63.241464] mt76x02_send_tx_status+0x1cd/0x3f0 [mt76x02_lib] [ 63.247430] mt76x02_tx_status_data+0x54/0x80 [mt76x02_lib] [ 63.253186] mt76u_tx_status_data+0x63/0xc0 [mt76_usb] [ 63.258451] process_one_work+0x1e2/0x3b0 [ 63.262533] worker_thread+0x4a/0x3d0 [ 63.266306] kthread+0xfb/0x130 [ 63.269550] ? process_one_work+0x3b0/0x3b0 [ 63.273893] ? kthread_park+0x90/0x90 [ 63.277677] ret_from_fork+0x22/0x40 [ 63.281411] Modules linked in: ccm bridge stp llc mt76x2u mt76x2_common mt76x02_usb mt76_usb mt76x02_lib mt76 nft_masq nft_chain_nat nf_nat nft_reject_inet nf_reject_ipv4 nf_reject_ipv6 nft_reject nft_ct nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 libcrc32c nf_tables_set nf_tables nfnetlink ath10k_pci ath10k_core amd64_edac_mod edac_mce_amd ath kvm_amd mac80211 kvm irqbypass crct10dif_pclmul crc32_pclmul ghash_clmulni_intel aesni_intel pcengines_apuv2 cfg80211 gpio_keys_polled crypto_simd input_polldev gpio_amd_fch cryptd igb glue_helper pcspkr fam15h_power sp5100_tco k10temp i2c_piix4 rfkill i2c_algo_bit ccp libarc4 dca rng_core uio_pdrv_genirq evdev leds_gpio uio mac_hid coreboot_table acpi_cpufreq pinctrl_amd sr_mod cdrom ip_tables x_tables ext4 crc32c_generic crc16 mbcache jbd2 sd_mod usb_storage ahci libahci libata xhci_pci sdhci_pci xhci_hcd scsi_mod cqhci sdhci ehci_pci crc32c_intel ehci_hcd mmc_core gpio_keys [ 63.365937] ---[ end trace f13e9cdc5f55db9e ]--- [ 63.370802] RIP: 0010:mt76_calc_rx_airtime+0x12b/0x150 [mt76] [ 63.376807] Code: 8d 34 76 48 8d 34 b1 0f b6 4e 07 66 85 c9 74 25 66 83 f9 01 75 1c b9 24 00 00 00 89 d0 0f b7 76 04 c1 e0 05 8d 04 d0 01 c0 99 <f7> fe 01 c8 c3 31 c0 c3 0f 0b c3 44 89 c8 83 e0 01 3c 01 19 c9 83 [ 63.396220] RSP: 0018:ffffbd694032fcf0 EFLAGS: 00010216 [ 63.401660] RAX: 0000000000002850 RBX: 0000000000000001 RCX: 00000000000000ca [ 63.409145] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffffa20068253538 [ 63.416505] RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000 [ 63.423988] R10: 0000000000000000 R11: ffffbd694032fcb0 R12: ffffbd694032fdb0 [ 63.431425] R13: 0000000000000000 R14: ffffbd694032fd00 R15: ffffa20068251e40 [ 63.438793] FS: 0000000000000000(0000) GS:ffffa2006aa00000(0000) knlGS:0000000000000000 [ 63.447141] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 63.453216] CR2: 00007fe65ba85cb0 CR3: 00000001293b6000 CR4: 00000000000406f0 I would guess, that mt76_calc_legacy_rate_duration: duration += (len * 10) / rate->bitrate; triggers this kind of message.