Repository navigation
wifi: apple: centauri: fix roaming (-EALREADY, disconnect wait) and cfg80211 disconnect race - #4285
Conversation
…disconnect Like the T6050 Centauri driver (commit 019e4b0), the base Centauri Wi-Fi firmware has no in-place reassociation, yet wifi_connect() refused a connect while connected with -EBUSY. On a roam attempt wpa_supplicant then marks the target BSS failed ("Association request to the driver failed"), adds it to its ignore list for 10 s, and falls back to another AP. In addition, drain_control() stripped BIT(30) (more-data-pending) before recording wifi->reply_command and wifi_disconnect() did not wait for the firmware's asynchronous disconnect completion event (0x80000004). When wpa_supplicant immediately disconnects and retries a connect, command 0x20000 races with the in-flight teardown and is rejected by firmware with status 333 (CTRL-EVENT-ASSOC-REJECT status_code=1). Fix both halves so wpa_supplicant roams cleanly: - Return -EALREADY from wifi_connect() when wifi->connected is set, so wpa_supplicant explicitly disconnects and retries the same target BSS. - Preserve wire_command (including BIT(30)) in wifi->reply_command, track wifi->disconnect_pending until event 0x80000004 arrives, wait for it in wifi_disconnect() when BIT(30) is set, and guard scan/connect/MAC/PM paths while disconnect_pending is set. - Guard link_worker() with was_connected so a worker racing with wifi_disconnect() does not emit a duplicate cfg80211_disconnected() or re-arm itself. - Add a KUnit test covering the wifi_connect()/wifi_scan() state guards. Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
…D on connect When a FullMAC driver reports disconnect synchronously from ops->disconnect() via cfg80211_disconnected(), EVENT_DISCONNECTED is queued asynchronously onto wdev->event_list. If userspace (such as wpa_supplicant handling -EALREADY on a roam) immediately calls NL80211_CMD_CONNECT before cfg80211_wq runs, the stale EVENT_DISCONNECTED fires after the new connect has started, emitting a spurious disconnect for the new target and clearing wdev->u.client.ssid_len. When that new connect completes, __cfg80211_connect_result() only restored wdev->u.client.ssid_len after checking for a Country IE; on any AP without a Country IE it returned early, leaving wdev->connected == true with wdev->u.client.ssid_len == 0. Subsequent cfg80211_disconnect() calls then skipped rdev_disconnect() completely because ssid_len was 0, permanently wedging the interface in a connected state. Fix both bugs: - In __cfg80211_connect_result(), restore wdev->u.client.ssid_len before the optional Country IE handling so it is never skipped. - In cfg80211_disconnect(), check wdev->connected alongside wdev->u.client.ssid_len and call cfg80211_process_wdev_events(wdev) after rdev_disconnect() so synchronously queued disconnect events are delivered before nl80211_disconnect() returns. Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
|
Merge readiness at
Areas: none matched in CODEOWNERS Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Review at c448d9ad8e11, merged onto main a9f1fabc2493 (merge tree 18ff24983e55, same as GitHub's merge ref). Not approving yet: one small fix in the Centauri wait, and the second-generation rows are queued.
Needs a fix: a disconnect timeout wedges the interface and blocks deep sleep.
In wifi_disconnect(), when wait_disconnect() returns -ETIMEDOUT (Alpha still at stage 2, no 0x80000004 within 5 s), disconnect_pending stays set. The same happens when command() itself times out. Nothing clears it afterwards. Only drain_control() does, on 0x80000004, and nothing drains the control ring while the interface is disconnected: centauri_wifi_kick() and link_worker() only run while connected, and scan/connect refuse before they send a command. From then on wifi_scan(), wifi_connect() and net_set_mac_address() return -EBUSY, and centauri_wifi_suspend() returns -EBUSY, which aborts every deep sleep until the module is rebound. Before this PR the worst case was a status 333 reject that wpa_supplicant retries. The recovery request after a command timeout doesn't help: the worker restarts the chip only when centauri_wifi_stalled() is true, and it isn't while Alpha is at stage 2.
Suggestion: on a wait timeout, log it and clear disconnect_pending (the next connect then sees, at worst, the old status 333), or drain once in wifi_connect()/wifi_scan()/suspend when the flag is set, so a late event is consumed. The merged T6050 wait_disconnect() has the same shape and could get the same follow-up.
cfg80211 (sme.c): looks right.
- Locking:
cfg80211_disconnect()already asserts the wiphy lock. Draining the wdev event list right after a disconnect is whatcfg80211_change_iface()(util.c, aftercfg80211_leave_locked()) andwiphy_suspend()(sysfs.c, aftercfg80211_leave_all()) already do. - No double report: each event is taken off the list under
event_lockbefore it is handled, socfg80211_event_workcan't deliver it again. The handler calls back into the driver (del_key,set_qos_map,crit_proto_stop) with no driver lock held, the same as from the worker. A nested drain (EVENT_STOPPED ->cfg80211_leave_locked()->cfg80211_disconnect()) is safe for the same reason. - Userspace now gets NL80211_CMD_DISCONNECT before the disconnect command's ack. mac80211 already does that (its deauth path reports synchronously), so wpa_supplicant handles it.
- Other drivers: only FullMAC drivers with
.disconnecttake this branch. brcmfmac (BCM4388 on J516s/J773g) callscfg80211_disconnected()frombrcmf_cfg80211_disconnect()unconditionally, and mt7932 (J700) and the T6050 Centauri driver (J714s) report from their disconnect paths too, so their disconnect event is now delivered synchronously. Hence the rows below. - The
ssid_lenmove: for APs that send a Country IE nothing changes (regulatory_hint_country_ie()doesn't read the SSID). The restore now also runs when there is no Country IE or thekmemdup()fails, which is the bug.|| wdev->connectedonly adds the connected-without-SSID state. Both halves fix upstream code and are worth sending to linux-wireless.
Small things, no blocker:
- The 5000 ms wait matches the T6050 driver. A one-line comment on where it comes from (next to the 500 ms budget in the payload) would help.
scripts/ci/apple-kunit.py planmaps the centauri files to no suite, so hosted CI never runscentauri_connect_state_guards_test. A table entry would keep it running.
Checked locally on the merge tree:
make ARCH=arm64 LLVM=1 W=1(clang 23.1.3, defconfig + asahi.config, Rust off, KUnit on) ofnet/wireless/ drivers/net/wireless/apple/centauri/ drivers/net/wireless/mediatek/mt7932/ drivers/net/wireless/broadcom/brcm80211/brcmfmac/: no warning in the PR's files. One warning in untouchednet/wireless/reg.c:112(-Wunused-but-set-global, clang 23, not from this PR).centauri_connect_state_guards_testcompiles; not run here (no QEMU on our build hosts, and MFD_MACSMC doesn't build on UML).tools/asahi/run-host-tests.py --only centauri: 22/22 pass.- Hosted CI: apple-build passed; KUnit mt7932 and host-tests were still running when I wrote this.
Rows queued, this head's sme.c, module-only:
- J516s (M3 Pro, brcmfmac, stock
7.3.0-f3822):cfg80211.kowith thissme.cswapped in at run time, stock module as the control first. Connect, disconnect, three immediate reconnects, a BSSID switch if one is in range, a suspend/resume with Wi-Fi up, 0 WARN/Oops, stock module back at the end. - J714s (M5 Pro, T6050 Centauri, trial
7.3.0-main571a6c45): the same sequence with the newcfg80211.koloaded at boot.
Not yet: J813 exact-head row (peer row). A connected suspend/resume on a base Centauri Mac (J813 or J873g) at this head, since the new wait now runs inside cfg80211's suspend-time disconnect and the driver refuses to suspend while disconnect_pending is set.
…t returns If command(131073) or wait_disconnect() times out (or hits a transient fault) while Alpha stays at stage 2, nothing drains the control ring while the interface is disconnected. Leaving disconnect_pending latched would permanently wedge wifi_scan(), wifi_connect(), net_set_mac_address(), and centauri_wifi_suspend() until module rebind. Log the pre-clear pending state in dev_dbg() and clear wifi->disconnect_pending before releasing wifi->lock. Also note why wait_disconnect() uses a 5000 ms deadline alongside the 500 ms firmware payload budget. Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
Add drivers/net/wireless/apple/centauri/centauri.kunitconfig and wire it into scripts/ci/apple-kunit.py so hosted arm64 KUnit CI runs apple-centauri-wifi* (centauri_station_stats_len_test and centauri_connect_state_guards_test) whenever centauri files change. Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
|
Addressed review feedback on top of
|
DjDeveloperr
left a comment
There was a problem hiding this comment.
Re-review at 18740d123634 (two new commits since c448d9ad8e11; net/wireless/sme.c unchanged, still blob bcf2d612). Merged locally onto main be72f78e54d6 (merge tree 5e6b3517). The blocker from the last review is fixed, and nothing new is wrong. Approving the code. Please don't merge yet: two rows are still owed (listed at the end).
The disconnect wedge is fixed.
disconnect_pendingis set in one place only:wifi_disconnect(), underwifi->lock. The new unconditional clear runs before the unlock on every way out: acommand()error or timeout,-EREMOTEIO,wait_disconnect()returning-ETIMEDOUT, and-EIOfromstoppingor Alpha leaving stage 2. There is no early return between setting and clearing it, andcommand()andwait_disconnect()don't drop the lock.- So scan, connect, set-MAC and
centauri_wifi_suspend()can no longer stay stuck at -EBUSY after a timeout. A disconnect that times out during cfg80211's suspend-time disconnect no longer blocks deep sleep. - Locking: the change is one store under a lock that is already held. Lock order and the sleep under
wifi->lock(up to 5 s, a mutex) are the same as before.cancel_work_sync(connect_work)still runs before the lock is taken, andcancel_delayed_work_sync(link_work)andcfg80211_disconnected()still run after it is released. - A firmware disconnect event (0x80000004) that arrives late after a timeout can't wedge anything. While disconnected nothing drains the ring, so the event waits there.
connect_worker()drains the ring and clearsdisconnect_eventbefore it sends the join, so the event is dropped there. If the firmware posts it after that drain, it fails that one join (-ENOTCONN), or, after a join that succeeded, it makeslink_worker()report one disconnect. wpa_supplicant retries either way. That is the same worst case as before this PR (a rejected join), and it needs the firmware to be more than 5 s late.
Small things, no blocker:
- All six places that read
disconnect_pending(scan, connect, set-MAC, fwlog, host_wakeup, suspend) holdwifi->lock, so they can never see it set now. The guards and thedisconnect_pending = truestep incentauri_connect_state_guards_testtest a state that can't happen anymore. They are harmless. You could drop them in a follow-up, or leave them as a safety net. scripts/ci/apple-kunit.py: the entry has the same shape as its neighbours (a glob filter likeapple-dart*/apple_sep*). It selects the right suite: the suite name isapple-centauri-wifi, andplanmaps the three centauri files tocentauriandsme.ctomt7932. One gap for later: the pathdrivers/net/wireless/apple/centauri/also matchest6050/, but the kunitconfig doesn't turn on the T6050 tests (apple-centauri-t6050-sleep,centauri_t6050_wifi). So a T6050-only change would run only the base suite. Not this PR's job.
Checked locally on the merge tree (Mini, clang 23.1.3):
make ARCH=arm64 LLVM=1 W=1 net/wireless/ drivers/net/wireless/apple/centauri/(defconfig + asahi.config, Rust off, KUnit on, base Centauri and T6050 as modules with their KUnit tests): no warning in the PR's files. The only warning is in untouchednet/wireless/reg.c:112(-Wunused-but-set-global, also on main).tools/asahi/run-host-tests.py --only centauri: 22/22 pass.kunit.py build --arch=arm64 --make_options LLVM=1 --kunitconfig=drivers/net/wireless/apple/centauri/centauri.kunitconfig: builds in 244 s. All of its options end up set, andcentauri_wifi_suitewith both cases is in vmlinux. It was built only, not run: our build hosts have no QEMU, and UML can't host this suite. The hosted KUnit job that runs it (apple-sio centauri mt7932 asahi) was still queued when I wrote this. Hostedapple-buildandhost-testspassed at this head.
Still owed before merge:
- J516s row (brcmfmac, stock
7.3.0-f3822, module-onlycfg80211.kowith thissme.c): the first run gave no verdict because of a fault in our test kit, not in this PR. After the module swap the running wpa_supplicant lost the device, on the stock module too, with 0 kernel warnings. The kit is being resealed to restart wpa_supplicant after the swap and to usememsleep. The M3 lead runs it next. - Your J813 exact-head row with a connected suspend/resume, since your J873g config has no
CONFIG_SUSPEND. It is the only row that runs the new wait inside cfg80211's suspend-time disconnect on base Centauri. - The hosted centauri KUnit job finishing green.
|
J516s (M3 Pro) row: PAIRED PASS for Kit
Arm B steps: initial connect, disconnect, connect and 3 reconnects OK. Then 3 deep sleeps ( Still owed before merge: the author's J813 connected suspend/resume row at this head (the centauri half), and the hosted KUnit job that covers centauri (running). |
|
Field report for the IWD path, which the J714s (MacBook Pro 14" M5 Pro, T6050) on IWD does not react to the error the way wpa_supplicant does. So as tested (wpa_supplicant on J873g) this PR does not fix the iwd backend on the same driver. Two ways to cover it:
The PR lists "J714s ( |
|
J813 (MacBook Air 13" M5, T8142,
Hosted CI is also 15/15 GREEN (including Thanks @andyholst for the IWD trace in #4290 — agreed that IWD's handling of |
What: Fix roaming failures on the base
apple_centauriWi-Fi driver (J813/J815/J873g/J804) by returning-EALREADYonwifi_connect()while connected (matching T6050 commit019e4b0e0946/ #3954), waiting for the firmware's asynchronous disconnect completion event (0x80000004) inwifi_disconnect()without latchingdisconnect_pendingon timeout/fault, registeringapple-centauri-wifiinscripts/ci/apple-kunit.py, and fixing thecfg80211net/wireless/sme.cdisconnect-event / missing-Country-IE SSID race exposed by immediate disconnect-then-connect retries.Tested:
18740d123634(boot4ee44a1a-67db-4dab-853c-415afc210c8c): 6/6 consecutive cross-band roams (2.4 GHz <-> 5 GHz ch 44) in 225–227 ms each, 0 ignore-list entries, 3/3 explicit disconnect + immediate reconnects, 10/10Wi-Fi disconnect: rc=0 status=0 reply_cmd=0x40020001 pending=0, 0firmware_status=333, 20/20 (0% loss) gateway pings on 5 GHz, 0 failed units, 0 oops/WARN/BUG.18740d123634(boot317f08ad-d877-4de2-87a5-fa6e097a00e9): 3/3wpa_cli roamwhile connected (ignore=[]), 3/3 explicit disconnect + immediate reconnect, 1/1 connecteds2idle(rtcwake -m freeze -s 10, Wi-Fi back in 5.65 s, 5/5 pings), 2/2 connected hardwaredeepsleep (rtcwake -m mem -s 15, full SoC commit + radio PCIe retrain each wake, Wi-Fi back in 5.66 s, 5/5 pings + immediate post-wake disconnect/reconnect OK each time), 20/20 (0% loss) final gateway pings, 0firmware_status=333, 0 sleep refusals, 0ASSOC-REJECT, 0 WARN/BUG/Oops.brcmfmac, paired arm A/Bcfg80211.koby @DjDeveloperr): PASS including 3 deep sleeps + reconnects, 0 WARN/Oops/BUG.apple-build,host-tests, full arm64 KUnit matrix includingcentauriapple-centauri-wifi*2/2 PASS);tools/asahi/run-host-tests.py --only centauri22/22 PASS;W=10 warnings.Risk: two-way door · N1 Centauri Macs (
apple_centauri: J813/J815/J873g/J804) and sharedcfg80211(net/wireless/sme.c, all Macs).Not yet: Separate follow-up for IWD userspace roam behavior (t6050 centauri: a roam dead-ends the station — every CMD_CONNECT refused until reboot (J714s, v272-28) #4290), where IWD does not issue
CMD_DISCONNECTafter aCMD_CONNECTerror.Details
Three interlocking bugs caused
wpa_supplicantroams onapple_centaurito fail, blacklist the better 5 GHz BSSID, and wedge disconnect handling:wifi_connect()returned-EBUSYwhile connected (drivers/net/wireless/apple/centauri/centauri_wifi.c):Just like the T6050 driver before wifi: apple: centauri: t6050: return -EALREADY to a connect while connected #3954 (
019e4b0e0946), returning-EBUSYmakeswpa_supplicantlogAssociation request to the driver failed, ignore the target BSSID for 10 s, and fall back to a weaker AP. Returning-EALREADYmakeswpa_supplicantdisconnect explicitly and retry the same target BSS.wifi_disconnect()did not wait for firmware disconnect completion (drivers/net/wireless/apple/centauri/centauri_wifi.c):drain_control()strippedBIT(30)(more-data-pending) before storingwifi->reply_command, andwifi_disconnect()returned immediately after the initial0x40020001ack without waiting for event0x80000004. On the immediate roam retry, firmware rejected command0x20000withfirmware_status=333(CTRL-EVENT-ASSOC-REJECT status_code=1). Preservingwire_commandinwifi->reply_command, trackingwifi->disconnect_pendinguntil0x80000004, waiting inwifi_disconnect()whenBIT(30)is set (clearingdisconnect_pendingbefore unlockingwifi->lockso a timeout or fault never wedges scan/connect/suspend), guarding scan/connect/MAC/PM/debugfs paths ondisconnect_pending, and guardinglink_worker()withwas_connectedeliminates both thestatus=333rejection and duplicatecfg80211_disconnected()notifications.cfg80211queued disconnect-event race + early return before SSID restore (net/wireless/sme.c):When an
ops->disconnect()callback callscfg80211_disconnected(),EVENT_DISCONNECTEDis queued asynchronously ontowdev->event_list. Whenwpa_supplicantimmediately sendsNL80211_CMD_CONNECTon the same thread after-EALREADY,EVENT_DISCONNECTEDran after the new connect started, emitting a spurious disconnect for the new target and clearingwdev->u.client.ssid_len = 0. When that connect completed on an AP without a Country IE,__cfg80211_connect_result()returned early on!country_elembefore theif (!wdev->u.client.ssid_len)fallback, leavingwdev->connected == truewithwdev->u.client.ssid_len == 0— making every subsequentcfg80211_disconnect()(else if (wdev->u.client.ssid_len)) a silent no-op and wedging the interface.__cfg80211_connect_result()sowdev->u.client.ssid_lenis restored before the optional Country IE lookup.cfg80211_disconnect(), checkwdev->u.client.ssid_len || wdev->connectedand callcfg80211_process_wdev_events(wdev)afterrdev_disconnect()(under the heldwiphylock) so synchronously queued disconnect events are delivered beforenl80211_disconnect()returns.drivers/net/wireless/apple/centauri/centauri.kunitconfig,scripts/ci/apple-kunit.py):Register the
centaurisuite (apple-centauri-wifi*) socentauri_station_stats_len_testandcentauri_connect_state_guards_testrun automatically in hosted arm64 KUnit CI.Evidence
18740d123634(basemainac0201f5287a)./scripts/checkpatch.pl --strict: 0 errors, 0 warnings on C changes (centauri.kunitconfigtriggers only the standard new-file MAINTAINERS note)make ARCH=arm64 LLVM=-19 W=1 drivers/net/wireless/apple/centauri/ net/wireless/sme.o: 0 warningsKUnit apple-sio centauri mt7932 asahi(apple-centauri-wifi*: 2/2 PASS)python3 -I tools/asahi/run-host-tests.py --only centauri: 22/22 PASS7.3.0-aurora-j873-main+, unpatched):wpa_cli roam->Association request to the driver failed, target added to ignore list; subsequent connect rejected withWi-Fi command 0x20000 rejected: firmware_status=333->CTRL-EVENT-ASSOC-REJECT status_code=1.7.3.0-aurora-centauri-roam+at18740d123634, boot4ee44a1a-67db-4dab-853c-415afc210c8c, one-shotaura-try):wpa_cli roamtransitions (2437 -> 5220 -> 2462 -> 5220 -> 2437 -> 5220 MHz): 225–227 ms each,ignore_list: []after every roam.wpa_cli disconnect+ immediatewpa_cli reconnect-> cleanly reconnected on 5220 MHz.Wi-Fi disconnect: rc=0 status=0 reply_cmd=0x40020001 pending=0, 0firmware_status=333, 0CTRL-EVENT-ASSOC-REJECT, 0 timeouts.rtt min/avg/max = 2.148/3.040/8.022 ms).systemctl --failed: 0 failed units; 0 kernel oops/WARN/BUG; clean reboot back to default kernel7.3.0-aurora-j873-main+.7.3.0-aurora-j813-roam+at18740d123634, boot317f08ad-d877-4de2-87a5-fa6e097a00e9, one-shotaura-try):wpa_cli roamwhile connected (ignore=[]), 3/3 explicitwpa_cli disconnect+ immediatewpa_cli reconnect(ignore=[]), each completing full firmware supplicant handshake (result=0 phase=7).s2idle(rtcwake -d rtc0 -m freeze -s 10):rc=0, Wi-Fi reconnected in 5.65 s, 5/5 (0% loss) gateway pings.deepsleep (rtcwake -d rtc0 -m mem -s 15,s2idle [deep]): bothrc=0, full SoC commit (apple-sleep: wake: 9 cores started in one burst; stop/sys/e/p now 0/0/0/0,the radio's PCIe link trained again after the wake), Wi-Fi reconnected in 5.66 s, 5/5 (0% loss) gateway pings + post-wakedisconnect/reconnectPASS (203 ms / 210 ms) after each wake.rtt min/avg/max = 4.447/12.851/84.350 ms).dmesg+wpa_supplicantcheck: 0firmware_status=333, 0 disconnect timeouts, 0 sleep refusals, 0ASSOC-REJECT, 0WARNING/BUG/Oops/Call trace.