From 0767b8aac1b97a1df186868e13125ddae11af147 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Wed, 18 Nov 2026 03:47:22 -0600 Subject: [PATCH 01/11] wifi: centauri T6050 wedge hold (15ms) and transport recovery 15ms scan settle after channels/disconnect (M5 journals: failing gaps 0.34, 2.25, 2.51 ms; good 39.51, 43.04, 46.65 ms; no good pair <10.79 ms). Transport recovery via centauri_t6050.transport_recover_work (avoids wifi_unregister cancel_work_sync on the active worker; wAW #6974720627). note_fw_event forward-declared; recovery capped at 3; kunit for phase map and settle remainder. debugfs force_transport_fault. Based on integration/aurora. --- .../wireless/apple/centauri/t6050/Makefile | 2 +- .../apple/centauri/t6050/centauri_pci.c | 9 +- .../apple/centauri/t6050/centauri_recovery.c | 241 ++++++++++++++++++ .../apple/centauri/t6050/centauri_recovery.h | 25 ++ .../apple/centauri/t6050/centauri_t6050.h | 2 + .../apple/centauri/t6050/centauri_wifi.c | 108 +++++++- 6 files changed, 374 insertions(+), 13 deletions(-) create mode 100644 drivers/net/wireless/apple/centauri/t6050/centauri_recovery.c create mode 100644 drivers/net/wireless/apple/centauri/t6050/centauri_recovery.h diff --git a/drivers/net/wireless/apple/centauri/t6050/Makefile b/drivers/net/wireless/apple/centauri/t6050/Makefile index ec75629ea1272..5632d74c0d127 100644 --- a/drivers/net/wireless/apple/centauri/t6050/Makefile +++ b/drivers/net/wireless/apple/centauri/t6050/Makefile @@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_APPLE_CENTAURI_T6050) += apple_centauri_t6050.o apple_centauri_t6050-y := centauri_pci.o centauri_ipc.o -apple_centauri_t6050-$(CONFIG_APPLE_CENTAURI_T6050_WIFI) += centauri_wifi.o +apple_centauri_t6050-$(CONFIG_APPLE_CENTAURI_T6050_WIFI) += centauri_wifi.o centauri_recovery.o diff --git a/drivers/net/wireless/apple/centauri/t6050/centauri_pci.c b/drivers/net/wireless/apple/centauri/t6050/centauri_pci.c index a656bc89b8ed8..802136c4a95c2 100644 --- a/drivers/net/wireless/apple/centauri/t6050/centauri_pci.c +++ b/drivers/net/wireless/apple/centauri/t6050/centauri_pci.c @@ -23,6 +23,7 @@ #include #include "centauri_t6050.h" +#include "centauri_recovery.h" /* Registry owns one reference, registrations and queued work own additional ones. */ struct centauri_t6050_rewake { @@ -472,8 +473,10 @@ static void centauri_t6050_boot_worker(struct work_struct *work) break; case CEN_BOOT_IPC: ret = centauri_t6050_start_ipc(c); - if (!ret) + if (!ret) { c->boot_phase = CEN_BOOT_READY; + c->transport_recover_count = 0; + } break; default: goto out; @@ -519,6 +522,8 @@ static int centauri_t6050_probe(struct pci_dev *pdev, const struct pci_device_id c->link_ready = true; mutex_init(&c->boot_lock); INIT_DELAYED_WORK(&c->boot_work, centauri_t6050_boot_worker); + if (IS_ENABLED(CONFIG_APPLE_CENTAURI_T6050_WIFI)) + centauri_t6050_transport_recover_init(c); c->boot_phase = CEN_BOOT_ROM; ret = device_property_read_string(&pdev->dev, "firmware-name", &c->firmware_name); if (ret) @@ -775,6 +780,8 @@ static int centauri_t6050_quiesce(struct centauri_t6050 *c) WRITE_ONCE(c->removing, true); /* Pairs with control_ready: no new consumer can attach. */ smp_store_release(&c->ready, false); + if (IS_ENABLED(CONFIG_APPLE_CENTAURI_T6050_WIFI)) + centauri_t6050_transport_recover_cancel(c); cancel_delayed_work_sync(&c->boot_work); /* Never hold boot_lock over an HCI close or Bluetooth work cancellation. */ ret = centauri_t6050_beta_call(c->recovery, false); diff --git a/drivers/net/wireless/apple/centauri/t6050/centauri_recovery.c b/drivers/net/wireless/apple/centauri/t6050/centauri_recovery.c new file mode 100644 index 0000000000000..ae733d74a5033 --- /dev/null +++ b/drivers/net/wireless/apple/centauri/t6050/centauri_recovery.c @@ -0,0 +1,241 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include +#include +#include +#include + +#include "centauri_recovery.h" + +s64 centauri_fw_event_scan_settle_remainder_ms(bool event_valid, ktime_t event_at, + ktime_t now, unsigned settle_ms) +{ + s64 elapsed; + + if (!event_valid || !settle_ms) + return 0; + elapsed = ktime_to_ms(ktime_sub(now, event_at)); + if (elapsed < 0) + elapsed = 0; + if (elapsed >= settle_ms) + return 0; + return settle_ms - elapsed; +} +EXPORT_SYMBOL_GPL(centauri_fw_event_scan_settle_remainder_ms); + +int centauri_t6050_boot_phase_for_control_stage(u32 control_stage, + enum centauri_t6050_boot_phase *phase) +{ + if (!phase) + return -EINVAL; + + switch (control_stage) { + case 0: + *phase = CEN_BOOT_ROM; + return 0; + case 1: + *phase = CEN_BOOT_IPC; + return 0; + case 4: + *phase = CEN_BOOT_CYCLE; + return 0; + case 2: + case 3: + return -EOPNOTSUPP; + default: + return -EINVAL; + } +} +EXPORT_SYMBOL_GPL(centauri_t6050_boot_phase_for_control_stage); + +#define CEN_TRANSPORT_RECOVER_MAX 3 + +static void centauri_t6050_transport_recover_worker(struct work_struct *work) +{ + struct centauri_t6050 *c = + container_of(work, struct centauri_t6050, transport_recover_work); + + c->transport_recover_count++; + centauri_t6050_schedule_transport_recover(c); +} + +void centauri_t6050_transport_recover_init(struct centauri_t6050 *c) +{ + INIT_WORK(&c->transport_recover_work, centauri_t6050_transport_recover_worker); + c->transport_recover_count = 0; +} + +void centauri_t6050_transport_recover_cancel(struct centauri_t6050 *c) +{ + cancel_work_sync(&c->transport_recover_work); +} + +void centauri_t6050_request_transport_recover(struct centauri_t6050 *c) +{ + if (!c || READ_ONCE(c->removing)) + return; + if (c->transport_recover_count >= CEN_TRANSPORT_RECOVER_MAX) { + dev_err(&c->pdev->dev, + "Wi-Fi transport recovery limit (%u) reached\n", + CEN_TRANSPORT_RECOVER_MAX); + return; + } + schedule_work(&c->transport_recover_work); +} +EXPORT_SYMBOL_GPL(centauri_t6050_request_transport_recover); + +void centauri_t6050_schedule_transport_recover(struct centauri_t6050 *c) +{ + enum centauri_t6050_boot_phase phase; + u32 control; + int ret; + + if (!c || READ_ONCE(c->removing)) + return; + + mutex_lock(&c->boot_lock); + if (c->boot_phase == CEN_BOOT_STOPPED || c->boot_phase == CEN_BOOT_FAILED) + goto out_unlock; + + control = readl(c->bar + 0x8000); + ret = centauri_t6050_boot_phase_for_control_stage(control, &phase); + if (ret) { + dev_err(&c->pdev->dev, + "Wi-Fi transport recovery unsupported (control stage=%#x): %d\n", + control, ret); + c->boot_phase = CEN_BOOT_FAILED; + goto out_unlock; + } + + WRITE_ONCE(c->ready, false); + centauri_t6050_free_ipc(c); + if (phase == CEN_BOOT_ROM) + c->boot_attempted = false; + c->boot_phase = phase; + mutex_unlock(&c->boot_lock); + queue_delayed_work(system_long_wq, &c->boot_work, 0); + return; + +out_unlock: + mutex_unlock(&c->boot_lock); +} +EXPORT_SYMBOL_GPL(centauri_t6050_schedule_transport_recover); + +#if IS_ENABLED(CONFIG_KUNIT) + +#include + +static void recover_phase_rom(struct kunit *test) +{ + enum centauri_t6050_boot_phase phase = CEN_BOOT_FAILED; + + KUNIT_EXPECT_EQ(test, centauri_t6050_boot_phase_for_control_stage(0, &phase), 0); + KUNIT_EXPECT_EQ(test, phase, CEN_BOOT_ROM); +} + +static void recover_phase_ipc(struct kunit *test) +{ + enum centauri_t6050_boot_phase phase = CEN_BOOT_FAILED; + + KUNIT_EXPECT_EQ(test, centauri_t6050_boot_phase_for_control_stage(1, &phase), 0); + KUNIT_EXPECT_EQ(test, phase, CEN_BOOT_IPC); +} + +static void recover_phase_cycle(struct kunit *test) +{ + enum centauri_t6050_boot_phase phase = CEN_BOOT_FAILED; + + KUNIT_EXPECT_EQ(test, centauri_t6050_boot_phase_for_control_stage(4, &phase), 0); + KUNIT_EXPECT_EQ(test, phase, CEN_BOOT_CYCLE); +} + +static void recover_phase_stop23(struct kunit *test) +{ + enum centauri_t6050_boot_phase phase = CEN_BOOT_READY; + + KUNIT_EXPECT_EQ(test, + centauri_t6050_boot_phase_for_control_stage(2, &phase), + -EOPNOTSUPP); + KUNIT_EXPECT_EQ(test, + centauri_t6050_boot_phase_for_control_stage(3, &phase), + -EOPNOTSUPP); +} + +static void recover_phase_null(struct kunit *test) +{ + KUNIT_EXPECT_EQ(test, + centauri_t6050_boot_phase_for_control_stage(1, NULL), + -EINVAL); +} + +static void scan_settle_remainder_inside(struct kunit *test) +{ + ktime_t event = ktime_set(1000, 0); + ktime_t now = ktime_add_ms(event, 2); + + KUNIT_EXPECT_EQ(test, + centauri_fw_event_scan_settle_remainder_ms(true, event, + now, 15), + 13); +} + +static void scan_settle_remainder_waits_out(struct kunit *test) +{ + ktime_t event = ktime_set(0, 0); + ktime_t now = ktime_add_ms(event, 10); + + KUNIT_EXPECT_EQ(test, + centauri_fw_event_scan_settle_remainder_ms(true, event, + now, 15), + 5); +} + +static void scan_settle_remainder_outside(struct kunit *test) +{ + ktime_t event = ktime_set(0, 0); + ktime_t now = ktime_add_ms(event, 15); + + KUNIT_EXPECT_EQ(test, + centauri_fw_event_scan_settle_remainder_ms(true, event, + now, 15), + 0); + now = ktime_add_ms(event, 20); + KUNIT_EXPECT_EQ(test, + centauri_fw_event_scan_settle_remainder_ms(true, event, + now, 15), + 0); +} + +static void scan_settle_remainder_no_event(struct kunit *test) +{ + ktime_t event = ktime_set(0, 0); + ktime_t now = ktime_add_ms(event, 2); + + KUNIT_EXPECT_EQ(test, + centauri_fw_event_scan_settle_remainder_ms(false, event, + now, 15), + 0); +} + +static struct kunit_case centauri_recovery_cases[] = { + KUNIT_CASE(recover_phase_rom), + KUNIT_CASE(recover_phase_ipc), + KUNIT_CASE(recover_phase_cycle), + KUNIT_CASE(recover_phase_stop23), + KUNIT_CASE(recover_phase_null), + KUNIT_CASE(scan_settle_remainder_inside), + KUNIT_CASE(scan_settle_remainder_waits_out), + KUNIT_CASE(scan_settle_remainder_outside), + KUNIT_CASE(scan_settle_remainder_no_event), + {} +}; + +static struct kunit_suite centauri_recovery_suite = { + .name = "centauri_t6050_recovery", + .test_cases = centauri_recovery_cases, +}; +kunit_test_suite(centauri_recovery_suite); + +#endif /* CONFIG_KUNIT */ diff --git a/drivers/net/wireless/apple/centauri/t6050/centauri_recovery.h b/drivers/net/wireless/apple/centauri/t6050/centauri_recovery.h new file mode 100644 index 0000000000000..bf8eb287483fc --- /dev/null +++ b/drivers/net/wireless/apple/centauri/t6050/centauri_recovery.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef AURORA_CENTAURI_RECOVERY_H +#define AURORA_CENTAURI_RECOVERY_H + +#include +#include "centauri_t6050.h" + +/* + * M5 journal (channels/disconnect event -> scan cmd 0x1000f): failing boots + * 0.34, 2.25, 2.51 ms; good 39.51, 43.04, 46.65 ms; no good pair under 10.79 ms. + */ +#define CEN_FW_EVENT_SCAN_SETTLE_MS 15 + +int centauri_t6050_boot_phase_for_control_stage(u32 control_stage, + enum centauri_t6050_boot_phase *phase); + +void centauri_t6050_transport_recover_init(struct centauri_t6050 *c); +void centauri_t6050_transport_recover_cancel(struct centauri_t6050 *c); +void centauri_t6050_request_transport_recover(struct centauri_t6050 *c); +void centauri_t6050_schedule_transport_recover(struct centauri_t6050 *c); + +s64 centauri_fw_event_scan_settle_remainder_ms(bool event_valid, ktime_t event_at, + ktime_t now, unsigned settle_ms); + +#endif diff --git a/drivers/net/wireless/apple/centauri/t6050/centauri_t6050.h b/drivers/net/wireless/apple/centauri/t6050/centauri_t6050.h index 3701dd5619472..41a1b8e6e1c04 100644 --- a/drivers/net/wireless/apple/centauri/t6050/centauri_t6050.h +++ b/drivers/net/wireless/apple/centauri/t6050/centauri_t6050.h @@ -48,6 +48,8 @@ struct centauri_t6050 { struct dentry *debug; struct mutex boot_lock; struct delayed_work boot_work; + struct work_struct transport_recover_work; + unsigned int transport_recover_count; enum centauri_t6050_boot_phase boot_phase; bool removing, ready; void *firmware, *descriptor; diff --git a/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c b/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c index f5c7ca87a6230..c5f93f10414d0 100644 --- a/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c +++ b/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -12,6 +13,7 @@ #include #include #include "centauri_t6050.h" +#include "centauri_recovery.h" #define CR_BASE 0x100000 #define TR_BASE 0x400000 @@ -58,6 +60,8 @@ struct centauri_t6050_wifi { struct work_struct scan_work; struct work_struct connect_work; struct work_struct link_work; + ktime_t last_fw_event_at; + bool last_fw_event_valid; bool irq_ready; struct cfg80211_scan_request *scan_request; struct mutex lock; /* Serializes firmware commands and ring consumers. */ @@ -113,6 +117,33 @@ struct centauri_t6050_wifi { }; static int query_link_status(struct centauri_t6050_wifi *wifi); +static void note_fw_event(struct centauri_t6050_wifi *wifi); +static void command_fault(struct centauri_t6050_wifi *wifi, u32 id, + u32 wifi_stage, const char *reason); + +static ssize_t force_transport_fault_write(struct file *file, + const char __user *user_buf, + size_t count, loff_t *ppos) +{ + struct centauri_t6050_wifi *wifi = file->private_data; + + if (count == 0) + return 0; + mutex_lock(&wifi->lock); + if (!smp_load_acquire(&wifi->irq_ready)) { + mutex_unlock(&wifi->lock); + return -ENODEV; + } + command_fault(wifi, 0, readl(wifi->a.bar + 8), "debugfs forced"); + mutex_unlock(&wifi->lock); + return count; +} + +static const struct file_operations force_transport_fault_fops = { + .write = force_transport_fault_write, + .open = simple_open, + .llseek = no_llseek, +}; static const u32 rx_buffer[5] = { 0, 0, 0x620000, 0x680000, 0x700000 }; static const u16 ring_size[5] = { 0, 64, 192, 96, 192 }; @@ -604,8 +635,10 @@ static void drain(struct centauri_t6050_wifi *wifi) if (ring == 4) { report_beacon(wifi, packet + 24, size - 24); } else if (command & BIT(31)) { - if (command == 0x80000030) + if (command == 0x80000030) { wifi->channels_seen++; + note_fw_event(wifi); + } if (command == 0x80000005) { wifi->scans_done++; wifi->scan_status = status; @@ -618,6 +651,7 @@ static void drain(struct centauri_t6050_wifi *wifi) command == 0x80000004) { wifi->disconnect_event = true; wifi->disconnect_status = status; + note_fw_event(wifi); } if (command == 0x80000004) wifi->disconnect_pending = false; @@ -652,15 +686,68 @@ static void drain(struct centauri_t6050_wifi *wifi) drain_data_tx(wifi); } +static void note_fw_event(struct centauri_t6050_wifi *wifi) +{ + wifi->last_fw_event_at = ktime_get(); + wifi->last_fw_event_valid = true; +} + +static s64 fw_event_gap_ms(struct centauri_t6050_wifi *wifi) +{ + if (!wifi->last_fw_event_valid) + return -1; + + return ktime_to_ms(ktime_sub(ktime_get(), wifi->last_fw_event_at)); +} + +static void wait_fw_event_before_scan(struct centauri_t6050_wifi *wifi) +{ + s64 remainder; + + for (;;) { + remainder = centauri_fw_event_scan_settle_remainder_ms( + wifi->last_fw_event_valid, wifi->last_fw_event_at, + ktime_get(), CEN_FW_EVENT_SCAN_SETTLE_MS); + if (remainder <= 0) + break; + drain(wifi); + if (remainder > 0) + msleep(remainder); + } +} + +static void log_transport_fault(struct centauri_t6050_wifi *wifi, u32 id, + u32 wifi_stage, const char *reason) +{ + u32 control = wifi->control->ipc ? + readl(wifi->control->bar + 0x8000) : ~0U; + s64 gap_ms = fw_event_gap_ms(wifi); + + if (gap_ms >= 0) { + dev_err(&wifi->control->pdev->dev, + "Wi-Fi transport fault (%s) cmd=%#x wifi_stage=%#x control_stage=%#x gap_ms=%lld rx=%u\n", + reason, id, wifi_stage, control, gap_ms, + wifi->rx_seen[2]); + } else { + dev_err(&wifi->control->pdev->dev, + "Wi-Fi transport fault (%s) cmd=%#x wifi_stage=%#x control_stage=%#x gap_ms=unknown rx=%u\n", + reason, id, wifi_stage, control, wifi->rx_seen[2]); + } +} + /* Caller holds wifi->lock. Unknown completion keeps DMA payloads owned. */ -static void command_fault(struct centauri_t6050_wifi *wifi) +static void command_fault(struct centauri_t6050_wifi *wifi, u32 id, + u32 wifi_stage, const char *reason) { + log_transport_fault(wifi, id, wifi_stage, reason); wifi->command_failed = true; wifi->configured = false; wifi->data_failed = true; - netif_stop_queue(wifi->netdev); + if (wifi->netdev) + netif_stop_queue(wifi->netdev); if (smp_load_acquire(&wifi->irq_ready)) schedule_work(&wifi->link_work); + centauri_t6050_request_transport_recover(wifi->control); } static bool command_payload_consumed(struct centauri_t6050_wifi *wifi, u16 slot) @@ -724,17 +811,14 @@ static int command_reply(struct centauri_t6050_wifi *wifi, u32 id, do { if (READ_ONCE(wifi->stopping) || READ_ONCE(wifi->control->removing)) { - command_fault(wifi); + command_fault(wifi, id, readl(wifi->a.bar + 8), "cancel"); ret = -ECANCELED; goto out; } drain(wifi); stage = readl(wifi->a.bar + 8); if (stage != 2) { - dev_err(&wifi->control->pdev->dev, - "Wi-Fi command %#x lost transport: stage=%#x sequence=%u rx=%u\n", - id, stage, sequence, wifi->rx_seen[2]); - command_fault(wifi); + command_fault(wifi, id, stage, "lost transport"); ret = -EIO; goto out; } @@ -754,9 +838,7 @@ static int command_reply(struct centauri_t6050_wifi *wifi, u32 id, } usleep_range(500, 1000); } while (time_before(jiffies, deadline)); - dev_err(&wifi->control->pdev->dev, - "Wi-Fi command %#x timed out (rx=%u)\n", id, wifi->rx_seen[2]); - command_fault(wifi); + command_fault(wifi, id, readl(wifi->a.bar + 8), "timeout"); ret = -ETIMEDOUT; out: wifi->reply_buffer = NULL; @@ -887,6 +969,7 @@ static void channels_apply(struct centauri_t6050_wifi *wifi) if (!(channel->flags & IEEE80211_CHAN_DISABLED)) counted[band]++; } + note_fw_event(wifi); dev_info(&wifi->control->pdev->dev, "Wi-Fi firmware channels: 2.4 GHz %u, 5 GHz %u, 6 GHz %u (%u entries)\n", counted[0], counted[1], counted[2], list[0]); @@ -1112,6 +1195,7 @@ static int scan_profile27(struct centauri_t6050_wifi *wifi) memcpy(scan + size + 6, ssid->ssid, ssid->ssid_len); size += 6 + ssid->ssid_len; } + wait_fw_event_before_scan(wifi); ret = command(wifi, 65551, scan, size); if (ret) { command_refused(wifi, "scan", ret); @@ -2484,6 +2568,8 @@ int centauri_t6050_wifi_register(struct centauri_t6050 *c) if (ret) goto failed; wifi->registered = true; + debugfs_create_file("force_transport_fault", 0200, wifi->wiphy->debugfsdir, + wifi, &force_transport_fault_fops); debugfs_create_blob("hw_channels", 0400, wifi->wiphy->debugfsdir, &wifi->hw_channels_blob); debugfs_create_blob("system_caps", 0400, wifi->wiphy->debugfsdir, From 60d1f28378f8b451fb5a3b8447bf01bd67505b7b Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Wed, 18 Nov 2026 04:46:17 -0600 Subject: [PATCH 02/11] wifi: centauri use noop_llseek for daily 7.3 tree --- drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c b/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c index c5f93f10414d0..4ccab5a480bc5 100644 --- a/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c +++ b/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c @@ -142,7 +142,7 @@ static ssize_t force_transport_fault_write(struct file *file, static const struct file_operations force_transport_fault_fops = { .write = force_transport_fault_write, .open = simple_open, - .llseek = no_llseek, + .llseek = noop_llseek, }; static const u32 rx_buffer[5] = { 0, 0, 0x620000, 0x680000, 0x700000 }; From a57a28194ed02ff878bb61606d30aacf7fc5f9de Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Wed, 18 Nov 2026 04:55:11 -0600 Subject: [PATCH 03/11] wifi: centauri T6050 kunit overlay for built-in recovery suite --- drivers/net/wireless/apple/centauri/t6050/.kunitconfig | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 drivers/net/wireless/apple/centauri/t6050/.kunitconfig diff --git a/drivers/net/wireless/apple/centauri/t6050/.kunitconfig b/drivers/net/wireless/apple/centauri/t6050/.kunitconfig new file mode 100644 index 0000000000000..d73990b2ac0d8 --- /dev/null +++ b/drivers/net/wireless/apple/centauri/t6050/.kunitconfig @@ -0,0 +1,9 @@ +CONFIG_COMPILE_TEST=y +CONFIG_KUNIT=y +CONFIG_WLAN=y +CONFIG_WLAN_VENDOR_APPLE=y +CONFIG_CFG80211=y +CONFIG_DEBUG_FS=y +CONFIG_PCIE_APPLE=y +CONFIG_APPLE_CENTAURI_T6050=y +CONFIG_APPLE_CENTAURI_T6050_WIFI=y From f0911fc3add7fce51f2e3d3ce298709d84101982 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Wed, 18 Nov 2026 04:57:00 -0600 Subject: [PATCH 04/11] wifi: centauri T6050 recovery KUnit as COMPILE_TEST built-in Add APPLE_CENTAURI_T6050_RECOVERY_KUNIT so kunit.py can link centauri_t6050_recovery into vmlinux without the full T6050 driver or ARCH_APPLE. Trim t6050/.kunitconfig to that fragment only. --- drivers/net/wireless/apple/Kconfig | 8 ++++++++ drivers/net/wireless/apple/centauri/Makefile | 1 + drivers/net/wireless/apple/centauri/t6050/.kunitconfig | 6 +----- drivers/net/wireless/apple/centauri/t6050/Makefile | 7 ++++++- .../net/wireless/apple/centauri/t6050/centauri_recovery.c | 2 +- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/drivers/net/wireless/apple/Kconfig b/drivers/net/wireless/apple/Kconfig index d9b13a9785de2..a62e14a17f706 100644 --- a/drivers/net/wireless/apple/Kconfig +++ b/drivers/net/wireless/apple/Kconfig @@ -41,4 +41,12 @@ config APPLE_CENTAURI_T6050_WIFI help Add scanning and station connections for the T6050 protocol profile. +config APPLE_CENTAURI_T6050_RECOVERY_KUNIT + bool "KUnit: Centauri T6050 recovery helpers (built-in, COMPILE_TEST)" + depends on KUNIT && COMPILE_TEST + depends on !APPLE_CENTAURI_T6050 + help + Build only centauri_recovery.c into vmlinux with its KUnit suite so + kunit.py can run centauri_t6050_recovery without the full T6050 driver. + endif diff --git a/drivers/net/wireless/apple/centauri/Makefile b/drivers/net/wireless/apple/centauri/Makefile index 235e1090294dc..be1d286fdb0e9 100644 --- a/drivers/net/wireless/apple/centauri/Makefile +++ b/drivers/net/wireless/apple/centauri/Makefile @@ -2,3 +2,4 @@ obj-$(CONFIG_APPLE_CENTAURI) += apple_centauri.o apple_centauri-y := centauri_pci.o centauri_port.o centauri_ipc.o centauri_wifi.o obj-$(CONFIG_APPLE_CENTAURI_T6050) += t6050/ +obj-$(CONFIG_APPLE_CENTAURI_T6050_RECOVERY_KUNIT) += t6050/ diff --git a/drivers/net/wireless/apple/centauri/t6050/.kunitconfig b/drivers/net/wireless/apple/centauri/t6050/.kunitconfig index d73990b2ac0d8..55b2ca4863ddb 100644 --- a/drivers/net/wireless/apple/centauri/t6050/.kunitconfig +++ b/drivers/net/wireless/apple/centauri/t6050/.kunitconfig @@ -2,8 +2,4 @@ CONFIG_COMPILE_TEST=y CONFIG_KUNIT=y CONFIG_WLAN=y CONFIG_WLAN_VENDOR_APPLE=y -CONFIG_CFG80211=y -CONFIG_DEBUG_FS=y -CONFIG_PCIE_APPLE=y -CONFIG_APPLE_CENTAURI_T6050=y -CONFIG_APPLE_CENTAURI_T6050_WIFI=y +CONFIG_APPLE_CENTAURI_T6050_RECOVERY_KUNIT=y \ No newline at end of file diff --git a/drivers/net/wireless/apple/centauri/t6050/Makefile b/drivers/net/wireless/apple/centauri/t6050/Makefile index 5632d74c0d127..239727c5c57f1 100644 --- a/drivers/net/wireless/apple/centauri/t6050/Makefile +++ b/drivers/net/wireless/apple/centauri/t6050/Makefile @@ -1,4 +1,9 @@ # SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_APPLE_CENTAURI_T6050_RECOVERY_KUNIT) += centauri_recovery.o + obj-$(CONFIG_APPLE_CENTAURI_T6050) += apple_centauri_t6050.o apple_centauri_t6050-y := centauri_pci.o centauri_ipc.o -apple_centauri_t6050-$(CONFIG_APPLE_CENTAURI_T6050_WIFI) += centauri_wifi.o centauri_recovery.o +apple_centauri_t6050-$(CONFIG_APPLE_CENTAURI_T6050_WIFI) += centauri_wifi.o +ifneq ($(CONFIG_APPLE_CENTAURI_T6050_RECOVERY_KUNIT),y) +apple_centauri_t6050-$(CONFIG_APPLE_CENTAURI_T6050_WIFI) += centauri_recovery.o +endif \ No newline at end of file diff --git a/drivers/net/wireless/apple/centauri/t6050/centauri_recovery.c b/drivers/net/wireless/apple/centauri/t6050/centauri_recovery.c index ae733d74a5033..b8e10e14123c9 100644 --- a/drivers/net/wireless/apple/centauri/t6050/centauri_recovery.c +++ b/drivers/net/wireless/apple/centauri/t6050/centauri_recovery.c @@ -123,7 +123,7 @@ void centauri_t6050_schedule_transport_recover(struct centauri_t6050 *c) } EXPORT_SYMBOL_GPL(centauri_t6050_schedule_transport_recover); -#if IS_ENABLED(CONFIG_KUNIT) +#if IS_ENABLED(CONFIG_APPLE_CENTAURI_T6050_RECOVERY_KUNIT) #include From 9d1c1d6eab5a8e36df36a1d2e48ba90dde31536f Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Wed, 18 Nov 2026 05:00:11 -0600 Subject: [PATCH 05/11] wifi: expand t6050 kunit fragment for netdev deps --- drivers/net/wireless/apple/centauri/t6050/.kunitconfig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/wireless/apple/centauri/t6050/.kunitconfig b/drivers/net/wireless/apple/centauri/t6050/.kunitconfig index 55b2ca4863ddb..9f673918aaa8b 100644 --- a/drivers/net/wireless/apple/centauri/t6050/.kunitconfig +++ b/drivers/net/wireless/apple/centauri/t6050/.kunitconfig @@ -1,5 +1,9 @@ CONFIG_COMPILE_TEST=y CONFIG_KUNIT=y +CONFIG_NET=y +CONFIG_INET=y +CONFIG_NETDEVICES=y +CONFIG_WIRELESS=y CONFIG_WLAN=y CONFIG_WLAN_VENDOR_APPLE=y CONFIG_APPLE_CENTAURI_T6050_RECOVERY_KUNIT=y \ No newline at end of file From cebd7ae1d143f476d80571fd44db38aca1cc2d6b Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Wed, 18 Nov 2026 05:03:50 -0600 Subject: [PATCH 06/11] wifi: omit T6050 transport recover from RECOVERY_KUNIT link --- drivers/net/wireless/apple/centauri/t6050/centauri_recovery.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/wireless/apple/centauri/t6050/centauri_recovery.c b/drivers/net/wireless/apple/centauri/t6050/centauri_recovery.c index b8e10e14123c9..5eb5d90b909bf 100644 --- a/drivers/net/wireless/apple/centauri/t6050/centauri_recovery.c +++ b/drivers/net/wireless/apple/centauri/t6050/centauri_recovery.c @@ -50,6 +50,8 @@ int centauri_t6050_boot_phase_for_control_stage(u32 control_stage, } EXPORT_SYMBOL_GPL(centauri_t6050_boot_phase_for_control_stage); +#if IS_ENABLED(CONFIG_APPLE_CENTAURI_T6050) + #define CEN_TRANSPORT_RECOVER_MAX 3 static void centauri_t6050_transport_recover_worker(struct work_struct *work) @@ -123,6 +125,8 @@ void centauri_t6050_schedule_transport_recover(struct centauri_t6050 *c) } EXPORT_SYMBOL_GPL(centauri_t6050_schedule_transport_recover); +#endif /* CONFIG_APPLE_CENTAURI_T6050 */ + #if IS_ENABLED(CONFIG_APPLE_CENTAURI_T6050_RECOVERY_KUNIT) #include From 0c30fd0224183a31938c1c4b392311f9b9a301b6 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Wed, 18 Nov 2026 05:20:33 -0600 Subject: [PATCH 07/11] wifi: sync centauri host tests with T6050 driver mocks centauri-wifi-pm-tests: match command_fault signature from centauri_wifi.c. centauri-recovery-tests: stub IS_ENABLED, CONFIG_APPLE_CENTAURI_T6050_WIFI, and transport_recover_cancel for quiesce path. Proof: python3 tools/asahi/centauri-wifi-pm-tests.py (+ --negative-controls) && centauri-recovery-tests.py (+ --negative-controls) all pass at this tree. --- tools/asahi/centauri-recovery-tests.py | 4 ++++ tools/asahi/centauri-wifi-pm-tests.py | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) mode change 100644 => 100755 tools/asahi/centauri-recovery-tests.py mode change 100644 => 100755 tools/asahi/centauri-wifi-pm-tests.py diff --git a/tools/asahi/centauri-recovery-tests.py b/tools/asahi/centauri-recovery-tests.py old mode 100644 new mode 100755 index dd9f9cf43aebe..7d1d7a342a12c --- a/tools/asahi/centauri-recovery-tests.py +++ b/tools/asahi/centauri-recovery-tests.py @@ -37,6 +37,8 @@ def block(name): #include #include #include +#define CONFIG_APPLE_CENTAURI_T6050_WIFI 1 +#define IS_ENABLED(option) ((option) ? 1 : 0) #define WRITE_ONCE(x,v) ((x)=(v)) #define smp_store_release(p,v) (*(p)=(v)) #define PCI_DEVFN(s,f) (((s)<<3)|(f)) @@ -93,6 +95,8 @@ def block(name): static bool centauri_t6050_ipc_fenced(struct centauri_t6050_ipc *p) { return !p || p->fenced; } static void cancel_delayed_work_sync(int *p) { (void)p; event(STOP_BOOT); } +static void centauri_t6050_transport_recover_cancel(struct centauri_t6050 *c) +{ (void)c; } static int centauri_t6050_beta_call(struct centauri_t6050_rewake *r, bool release) { struct centauri_t6050 *c = r->control->dev.data; diff --git a/tools/asahi/centauri-wifi-pm-tests.py b/tools/asahi/centauri-wifi-pm-tests.py old mode 100644 new mode 100755 index 930c08839bbaf..70e6f023c08ed --- a/tools/asahi/centauri-wifi-pm-tests.py +++ b/tools/asahi/centauri-wifi-pm-tests.py @@ -96,7 +96,9 @@ def block(source, name): static void put_unaligned_le16(u16 value, void *p) { memcpy(p, &value, 2); } static void put_unaligned_le32(u32 value, void *p) { memcpy(p, &value, 4); } static void put_unaligned_le64(uint64_t value, void *p) { memcpy(p, &value, 8); } -static void command_fault(struct centauri_t6050_wifi *wifi) { wifi->command_failed = true; } +static void command_fault(struct centauri_t6050_wifi *wifi, u32 id, + u32 wifi_stage, const char *reason) +{ (void)id; (void)wifi_stage; (void)reason; wifi->command_failed = true; } static void drain(struct centauri_t6050_wifi *wifi) { assert(wifi->lock); From 17a01b6878cc45e77f3712f9fc12c69ff1ae989e Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Thu, 19 Nov 2026 18:25:00 -0600 Subject: [PATCH 08/11] wifi: centauri: skip transport recovery once Wi-Fi is stopping Retain fault bookkeeping for unconfirmed DMA, but do not queue a rebuild on stop or removal. Exercise the actual command_fault body in the Wi-Fi PM host harness; the new assertion fails without the guard. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- .../apple/centauri/t6050/centauri_wifi.c | 3 +- tools/asahi/centauri-wifi-pm-tests.py | 28 +++++++++++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c b/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c index 4ccab5a480bc5..61ac4786c6e9e 100644 --- a/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c +++ b/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c @@ -747,7 +747,8 @@ static void command_fault(struct centauri_t6050_wifi *wifi, u32 id, netif_stop_queue(wifi->netdev); if (smp_load_acquire(&wifi->irq_ready)) schedule_work(&wifi->link_work); - centauri_t6050_request_transport_recover(wifi->control); + if (!READ_ONCE(wifi->stopping) && !READ_ONCE(wifi->control->removing)) + centauri_t6050_request_transport_recover(wifi->control); } static bool command_payload_consumed(struct centauri_t6050_wifi *wifi, u16 slot) diff --git a/tools/asahi/centauri-wifi-pm-tests.py b/tools/asahi/centauri-wifi-pm-tests.py index 70e6f023c08ed..dcff4f1578d3e 100755 --- a/tools/asahi/centauri-wifi-pm-tests.py +++ b/tools/asahi/centauri-wifi-pm-tests.py @@ -17,7 +17,7 @@ def block(source, name): - match = re.search(r"^(?:static )?(?:int|void) " + re.escape(name) + r"\(", source, re.M) + match = re.search(r"^(?:static )?(?:int|void) " + re.escape(name) + r"\([^;]*?\)\n\{", source, re.M) if not match: raise RuntimeError(f"Production function {name} missing") brace = source.index("{", match.start()) @@ -66,7 +66,8 @@ def block(source, name): struct { u8 *window, *bar; uint64_t window_dma; } a; int lock, connect_work, link_work, data_tx_queue; bool command_failed, stopping, connect_abort, disconnect_pending, connected; - bool reply_valid, pm_prepared; + bool reply_valid, pm_prepared, configured, data_failed, irq_ready; + struct net_device *netdev; u16 command_head, sequence, reply_capture, reply_sequence, reply_status; u32 reply_command; u8 *reply_buffer; @@ -96,9 +97,14 @@ def block(source, name): static void put_unaligned_le16(u16 value, void *p) { memcpy(p, &value, 2); } static void put_unaligned_le32(u32 value, void *p) { memcpy(p, &value, 4); } static void put_unaligned_le64(uint64_t value, void *p) { memcpy(p, &value, 8); } -static void command_fault(struct centauri_t6050_wifi *wifi, u32 id, - u32 wifi_stage, const char *reason) -{ (void)id; (void)wifi_stage; (void)reason; wifi->command_failed = true; } +static unsigned int recovery_requests; +#define smp_load_acquire(p) (*(p)) +static void log_transport_fault(struct centauri_t6050_wifi *wifi, u32 id, + u32 stage, const char *reason) +{ (void)wifi; (void)id; (void)stage; (void)reason; } +static void schedule_work(int *work) { (void)work; } +static void centauri_t6050_request_transport_recover(struct centauri_t6050 *control) +{ (void)control; recovery_requests++; } static void drain(struct centauri_t6050_wifi *wifi) { assert(wifi->lock); @@ -241,6 +247,16 @@ def block(source, name): assert(!wifi.pm_disconnect.submitted && !wifi.pm_disconnect.replied); expect_error(-ENOSPC); + prepare(); + recovery_requests = 0; + wifi.stopping = true; + wifi.configured = true; + mutex_lock(&wifi.lock); + command_fault(&wifi, 0, 2, "cancel"); + mutex_unlock(&wifi.lock); + assert(wifi.command_failed && wifi.data_failed && !wifi.configured); + assert(recovery_requests == 0); + prepare(); transport_mode = LOST; assert(disconnect() == -EIO); @@ -312,7 +328,7 @@ def main(): receipt = re.search(r"struct centauri_wifi_disconnect_receipt \{.*?\n\};", source, re.S) if not receipt: raise RuntimeError("Production receipt structure missing") - names = ["command_reply", "wait_disconnect", "wifi_disconnect", + names = ["command_fault", "command_reply", "wait_disconnect", "wifi_disconnect", "centauri_t6050_wifi_pm_prepare", "centauri_t6050_wifi_pm_error", "centauri_t6050_wifi_pm_complete", "wifi_suspend"] has_resume = bool(re.search(r"^static int wifi_resume\(", source, re.M)) From 27ce6b00d179a5dfbff537a79d808b13aa324519 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Fri, 20 Nov 2026 09:34:20 -0600 Subject: [PATCH 09/11] wifi: centauri: wait for control idle before publishing commands Country updates use the same command ring as scans. Replace the scan-only delay with one bounded gate before descriptor publication when a firmware event was observed. Fail without publishing when the control stage is unstable or the previous slot remains in flight; cancel cleanly on teardown. The host fixture reproduced command 9 publishing before idle and now asserts no publication or doorbell on timeout. Centauri host tests: 6/6 passed, including negative controls. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- .../apple/centauri/t6050/centauri_recovery.c | 84 +++++++------------ .../apple/centauri/t6050/centauri_recovery.h | 11 +-- .../apple/centauri/t6050/centauri_wifi.c | 42 +++++++--- tools/asahi/centauri-wifi-pm-tests.py | 24 ++++-- 4 files changed, 82 insertions(+), 79 deletions(-) diff --git a/drivers/net/wireless/apple/centauri/t6050/centauri_recovery.c b/drivers/net/wireless/apple/centauri/t6050/centauri_recovery.c index 5eb5d90b909bf..47bf87c21ad47 100644 --- a/drivers/net/wireless/apple/centauri/t6050/centauri_recovery.c +++ b/drivers/net/wireless/apple/centauri/t6050/centauri_recovery.c @@ -9,21 +9,17 @@ #include "centauri_recovery.h" -s64 centauri_fw_event_scan_settle_remainder_ms(bool event_valid, ktime_t event_at, - ktime_t now, unsigned settle_ms) +bool centauri_control_idle_ready(bool event_valid, u32 stage_first, + u32 stage_second, bool ring_drained) { - s64 elapsed; - - if (!event_valid || !settle_ms) - return 0; - elapsed = ktime_to_ms(ktime_sub(now, event_at)); - if (elapsed < 0) - elapsed = 0; - if (elapsed >= settle_ms) - return 0; - return settle_ms - elapsed; + if (!event_valid) + return true; + /* Settled: the control stage reads running twice in a row and the + * command ring has drained, so no slot is in flight from a pre-event + * command. */ + return stage_first == 2 && stage_first == stage_second && ring_drained; } -EXPORT_SYMBOL_GPL(centauri_fw_event_scan_settle_remainder_ms); +EXPORT_SYMBOL_GPL(centauri_control_idle_ready); int centauri_t6050_boot_phase_for_control_stage(u32 control_stage, enum centauri_t6050_boot_phase *phase) @@ -174,53 +170,34 @@ static void recover_phase_null(struct kunit *test) -EINVAL); } -static void scan_settle_remainder_inside(struct kunit *test) +static void control_idle_no_event(struct kunit *test) { - ktime_t event = ktime_set(1000, 0); - ktime_t now = ktime_add_ms(event, 2); - - KUNIT_EXPECT_EQ(test, - centauri_fw_event_scan_settle_remainder_ms(true, event, - now, 15), - 13); + KUNIT_EXPECT_TRUE(test, + centauri_control_idle_ready(false, 0, 0, false)); } -static void scan_settle_remainder_waits_out(struct kunit *test) +static void control_idle_settled(struct kunit *test) { - ktime_t event = ktime_set(0, 0); - ktime_t now = ktime_add_ms(event, 10); - - KUNIT_EXPECT_EQ(test, - centauri_fw_event_scan_settle_remainder_ms(true, event, - now, 15), - 5); + KUNIT_EXPECT_TRUE(test, + centauri_control_idle_ready(true, 2, 2, true)); } -static void scan_settle_remainder_outside(struct kunit *test) +static void control_idle_unstable_stage(struct kunit *test) { - ktime_t event = ktime_set(0, 0); - ktime_t now = ktime_add_ms(event, 15); - - KUNIT_EXPECT_EQ(test, - centauri_fw_event_scan_settle_remainder_ms(true, event, - now, 15), - 0); - now = ktime_add_ms(event, 20); - KUNIT_EXPECT_EQ(test, - centauri_fw_event_scan_settle_remainder_ms(true, event, - now, 15), - 0); + KUNIT_EXPECT_FALSE(test, + centauri_control_idle_ready(true, 2, 3, true)); } -static void scan_settle_remainder_no_event(struct kunit *test) +static void control_idle_transitional_stage(struct kunit *test) { - ktime_t event = ktime_set(0, 0); - ktime_t now = ktime_add_ms(event, 2); + KUNIT_EXPECT_FALSE(test, + centauri_control_idle_ready(true, 3, 3, true)); +} - KUNIT_EXPECT_EQ(test, - centauri_fw_event_scan_settle_remainder_ms(false, event, - now, 15), - 0); +static void control_idle_slot_in_flight(struct kunit *test) +{ + KUNIT_EXPECT_FALSE(test, + centauri_control_idle_ready(true, 2, 2, false)); } static struct kunit_case centauri_recovery_cases[] = { @@ -229,10 +206,11 @@ static struct kunit_case centauri_recovery_cases[] = { KUNIT_CASE(recover_phase_cycle), KUNIT_CASE(recover_phase_stop23), KUNIT_CASE(recover_phase_null), - KUNIT_CASE(scan_settle_remainder_inside), - KUNIT_CASE(scan_settle_remainder_waits_out), - KUNIT_CASE(scan_settle_remainder_outside), - KUNIT_CASE(scan_settle_remainder_no_event), + KUNIT_CASE(control_idle_no_event), + KUNIT_CASE(control_idle_settled), + KUNIT_CASE(control_idle_unstable_stage), + KUNIT_CASE(control_idle_transitional_stage), + KUNIT_CASE(control_idle_slot_in_flight), {} }; diff --git a/drivers/net/wireless/apple/centauri/t6050/centauri_recovery.h b/drivers/net/wireless/apple/centauri/t6050/centauri_recovery.h index bf8eb287483fc..e55db30655305 100644 --- a/drivers/net/wireless/apple/centauri/t6050/centauri_recovery.h +++ b/drivers/net/wireless/apple/centauri/t6050/centauri_recovery.h @@ -3,14 +3,9 @@ #define AURORA_CENTAURI_RECOVERY_H #include +#include #include "centauri_t6050.h" -/* - * M5 journal (channels/disconnect event -> scan cmd 0x1000f): failing boots - * 0.34, 2.25, 2.51 ms; good 39.51, 43.04, 46.65 ms; no good pair under 10.79 ms. - */ -#define CEN_FW_EVENT_SCAN_SETTLE_MS 15 - int centauri_t6050_boot_phase_for_control_stage(u32 control_stage, enum centauri_t6050_boot_phase *phase); @@ -19,7 +14,7 @@ void centauri_t6050_transport_recover_cancel(struct centauri_t6050 *c); void centauri_t6050_request_transport_recover(struct centauri_t6050 *c); void centauri_t6050_schedule_transport_recover(struct centauri_t6050 *c); -s64 centauri_fw_event_scan_settle_remainder_ms(bool event_valid, ktime_t event_at, - ktime_t now, unsigned settle_ms); +bool centauri_control_idle_ready(bool event_valid, u32 stage_first, + u32 stage_second, bool ring_drained); #endif diff --git a/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c b/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c index 61ac4786c6e9e..034390675a201 100644 --- a/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c +++ b/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c @@ -700,19 +700,28 @@ static s64 fw_event_gap_ms(struct centauri_t6050_wifi *wifi) return ktime_to_ms(ktime_sub(ktime_get(), wifi->last_fw_event_at)); } -static void wait_fw_event_before_scan(struct centauri_t6050_wifi *wifi) +/* Firmware events have no separate completion reply; sample the control and command ring. */ +static int centauri_wait_control_idle(struct centauri_t6050_wifi *wifi) { - s64 remainder; + unsigned long deadline = jiffies + msecs_to_jiffies(1500); for (;;) { - remainder = centauri_fw_event_scan_settle_remainder_ms( - wifi->last_fw_event_valid, wifi->last_fw_event_at, - ktime_get(), CEN_FW_EVENT_SCAN_SETTLE_MS); - if (remainder <= 0) - break; - drain(wifi); - if (remainder > 0) - msleep(remainder); + u32 first, stage; + + if (READ_ONCE(wifi->stopping) || READ_ONCE(wifi->control->removing)) + return -ECANCELED; + if (!wifi->last_fw_event_valid) + return 0; + first = readl(wifi->control->bar + 0x8000); + usleep_range(1000, 2000); + if (READ_ONCE(wifi->stopping) || READ_ONCE(wifi->control->removing)) + return -ECANCELED; + stage = readl(wifi->control->bar + 0x8000); + if (centauri_control_idle_ready(true, first, stage, + index_read(wifi, 1, 1) == wifi->command_head)) + return 0; + if (time_after_eq(jiffies, deadline)) + return -ETIMEDOUT; } } @@ -770,11 +779,11 @@ static int command_reply(struct centauri_t6050_wifi *wifi, u32 id, const void *payload, size_t size, void *reply, size_t *reply_size, bool *submitted) { - u16 slot = wifi->command_head, sequence = ++wifi->sequence; + u16 slot = wifi->command_head, sequence; int ret; u32 stage; u8 *packet, *descriptor; - unsigned long deadline = jiffies + msecs_to_jiffies(1500); + unsigned long deadline; if (submitted) *submitted = false; @@ -782,8 +791,16 @@ static int command_reply(struct centauri_t6050_wifi *wifi, u32 id, return -EIO; if (size > BUFFER_SIZE - 24) return -EMSGSIZE; + ret = centauri_wait_control_idle(wifi); + if (ret) { + if (ret == -ETIMEDOUT) + command_fault(wifi, id, readl(wifi->a.bar + 8), "control idle timeout"); + return ret; + } if ((slot + 1) % ring_size[1] == index_read(wifi, 1, 1)) return -ENOSPC; + sequence = ++wifi->sequence; + deadline = jiffies + msecs_to_jiffies(1500); packet = wifi->a.window + TX_BUFFER + slot * BUFFER_SIZE; memset(packet, 0, 24 + size); put_unaligned_le16(24 + size, packet + 0x10); @@ -1196,7 +1213,6 @@ static int scan_profile27(struct centauri_t6050_wifi *wifi) memcpy(scan + size + 6, ssid->ssid, ssid->ssid_len); size += 6 + ssid->ssid_len; } - wait_fw_event_before_scan(wifi); ret = command(wifi, 65551, scan, size); if (ret) { command_refused(wifi, "scan", ret); diff --git a/tools/asahi/centauri-wifi-pm-tests.py b/tools/asahi/centauri-wifi-pm-tests.py index dcff4f1578d3e..a360e317a5df8 100755 --- a/tools/asahi/centauri-wifi-pm-tests.py +++ b/tools/asahi/centauri-wifi-pm-tests.py @@ -17,7 +17,7 @@ def block(source, name): - match = re.search(r"^(?:static )?(?:int|void) " + re.escape(name) + r"\([^;]*?\)\n\{", source, re.M) + match = re.search(r"^(?:static )?(?:bool|int|void) " + re.escape(name) + r"\([^;]*?\)\n\{", source, re.M) if not match: raise RuntimeError(f"Production function {name} missing") brace = source.index("{", match.start()) @@ -54,7 +54,7 @@ def block(source, name): #define time_after_eq(a, b) (!time_before(a, b)) static unsigned long jiffies; struct centauri_t6050_wifi; -struct centauri_t6050 { struct centauri_t6050_wifi *wifi; bool removing; }; +struct centauri_t6050 { struct centauri_t6050_wifi *wifi; u8 *bar; bool removing; }; struct wiphy { struct centauri_t6050_wifi *wifi; }; struct net_device { int unused; }; struct cfg80211_wowlan { int unused; }; @@ -67,6 +67,7 @@ def block(source, name): int lock, connect_work, link_work, data_tx_queue; bool command_failed, stopping, connect_abort, disconnect_pending, connected; bool reply_valid, pm_prepared, configured, data_failed, irq_ready; + bool last_fw_event_valid; struct net_device *netdev; u16 command_head, sequence, reply_capture, reply_sequence, reply_status; u32 reply_command; @@ -136,12 +137,12 @@ def block(source, name): static struct centauri_t6050_wifi wifi; static struct wiphy wiphy; static struct net_device netdev; -static u8 window[16384], bar[8192]; +static u8 window[16384], bar[8192], control_bar[0x8004]; static void reset(void) { memset(&wifi, 0, sizeof(wifi)); memset(window, 0, sizeof(window)); - control = (struct centauri_t6050) { .wifi = &wifi }; + control = (struct centauri_t6050) { .wifi = &wifi, .bar = control_bar }; wifi.control = &control; wifi.a.window = window; wifi.a.bar = bar; @@ -303,12 +304,23 @@ def block(source, name): centauri_t6050_wifi_pm_complete(&control); prepare(); bool published = false; + wifi.last_fw_event_valid = true; submission_probe = &published; mutex_lock(&wifi.lock); assert(command_reply(&wifi, 131073, NULL, 0, NULL, NULL, &published) == 0); mutex_unlock(&wifi.lock); assert(published); submission_probe = NULL; + reset(); + unsigned int requests_before = recovery_requests; + wifi.last_fw_event_valid = true; + consumer = 1; /* Ring is not empty, but has room for another command. */ + wifi.command_head = 2; + mutex_lock(&wifi.lock); + assert(command_reply(&wifi, 9, NULL, 0, NULL, NULL, &published) == -ETIMEDOUT); + mutex_unlock(&wifi.lock); + assert(!published && !doorbells && wifi.command_head == 2); + assert(recovery_requests == requests_before + 1); puts("PASS: production disconnect/transport/PM callbacks and first-error retention"); return 0; } @@ -328,13 +340,15 @@ def main(): receipt = re.search(r"struct centauri_wifi_disconnect_receipt \{.*?\n\};", source, re.S) if not receipt: raise RuntimeError("Production receipt structure missing") - names = ["command_fault", "command_reply", "wait_disconnect", "wifi_disconnect", + names = ["centauri_wait_control_idle", "command_fault", "command_reply", "wait_disconnect", "wifi_disconnect", "centauri_t6050_wifi_pm_prepare", "centauri_t6050_wifi_pm_error", "centauri_t6050_wifi_pm_complete", "wifi_suspend"] has_resume = bool(re.search(r"^static int wifi_resume\(", source, re.M)) if has_resume: names.append("wifi_resume") production = "\n\n".join(block(source, name) for name in names) + recovery = (root / "drivers/net/wireless/apple/centauri/t6050/centauri_recovery.c").read_text() + production = block(recovery, "centauri_control_idle_ready") + "\n\n" + production ops = re.search(r"static const struct cfg80211_ops wifi_ops = \{(.*?)\n\};", source, re.S) registration = re.search(r"\.suspend\s*=\s*(\w+)", ops.group(1)) if ops else None suspend = registration.group(1) if registration else "NULL" From 1fee120beb50d3fc16174db933ef24f459da2184 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Fri, 20 Nov 2026 09:46:00 -0600 Subject: [PATCH 10/11] wifi: centauri: route wedged control stages through fenced recovery The firmware-preserving stage-4 cycle cannot recover a wedge during IPC. Dispatch stages 2 and 3 through the same DMA-fenced teardown, reset and re-enumeration worker used for wake recovery. Force a fresh reset for a runtime wedge; a previous wake marker does not prove this wedge was reset. The routing test failed first on the unsupported stage. Centauri host tests pass 6/6, with a negative control that rejects reusing the stale wake reset. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- .../apple/centauri/t6050/centauri_pci.c | 26 ++++++++-- .../apple/centauri/t6050/centauri_recovery.c | 26 ++++++---- .../apple/centauri/t6050/centauri_t6050.h | 2 + tools/asahi/centauri-recovery-tests.py | 50 ++++++++++++++++--- 4 files changed, 83 insertions(+), 21 deletions(-) diff --git a/drivers/net/wireless/apple/centauri/t6050/centauri_pci.c b/drivers/net/wireless/apple/centauri/t6050/centauri_pci.c index 802136c4a95c2..1bb40c7e99bf1 100644 --- a/drivers/net/wireless/apple/centauri/t6050/centauri_pci.c +++ b/drivers/net/wireless/apple/centauri/t6050/centauri_pci.c @@ -32,7 +32,7 @@ struct centauri_t6050_rewake { struct work_struct work; struct pci_dev *bridge; unsigned int slot; - bool active, rerun; + bool active, rerun, force_reset; unsigned int generation, work_generation; int error; struct pci_dev *control; @@ -159,7 +159,7 @@ void apple_centauri_sleep_unregister(struct pci_dev *fn) } EXPORT_SYMBOL_GPL(apple_centauri_sleep_unregister); -void apple_centauri_sleep_recovery_needed(struct pci_dev *fn, int error) +void centauri_t6050_request_rewake(struct pci_dev *fn, int error, bool force_reset) { struct centauri_t6050_rewake *rw; @@ -171,6 +171,7 @@ void apple_centauri_sleep_recovery_needed(struct pci_dev *fn, int error) continue; if (error && !rw->error) rw->error = error; + rw->force_reset |= force_reset; /* One owner and one work reference even while the work is running. */ if (rw->active && rw->generation != rw->work_generation) rw->rerun = true; @@ -183,6 +184,11 @@ void apple_centauri_sleep_recovery_needed(struct pci_dev *fn, int error) return; } } + +void apple_centauri_sleep_recovery_needed(struct pci_dev *fn, int error) +{ + centauri_t6050_request_rewake(fn, error, false); +} EXPORT_SYMBOL_GPL(apple_centauri_sleep_recovery_needed); static struct pci_driver centauri_t6050_driver; @@ -873,6 +879,19 @@ static int centauri_t6050_rewake_teardown(struct centauri_t6050_rewake *rw) return ret; } +static bool centauri_t6050_rewake_already_reset(struct centauri_t6050_rewake *rw) +{ + bool force_reset; + + mutex_lock(&cen_recovery_lock); + force_reset = rw->force_reset; + rw->force_reset = false; + mutex_unlock(&cen_recovery_lock); + + /* A prior wake's reset does not recover a subsequent runtime wedge. */ + return !force_reset && apple_pcie_t6050_warm_reset_done(rw->bridge); +} + /* * The functions are removed while their link is still up, then the warm reset, then the link * (if it went down, until it is back), then a new enumeration, all under the rescan lock: no @@ -915,7 +934,7 @@ static void centauri_t6050_rewake_worker(struct work_struct *work) * here, on a trained link, would take the link down for good: after a suspend that kept the * link the host takes the port down and up around the reset instead. */ - if (apple_pcie_t6050_warm_reset_done(bridge)) { + if (centauri_t6050_rewake_already_reset(rw)) { pci_dbg(bridge, "N1 after the sleep: reset by the host before its port came up\n"); ret = 0; } else { @@ -994,6 +1013,7 @@ static void centauri_t6050_rewake_worker(struct work_struct *work) } rw->active = false; rw->error = 0; + rw->force_reset = false; mutex_unlock(&cen_recovery_lock); kref_put(&rw->ref, centauri_t6050_owner_free); } diff --git a/drivers/net/wireless/apple/centauri/t6050/centauri_recovery.c b/drivers/net/wireless/apple/centauri/t6050/centauri_recovery.c index 47bf87c21ad47..7e8d888cacf5a 100644 --- a/drivers/net/wireless/apple/centauri/t6050/centauri_recovery.c +++ b/drivers/net/wireless/apple/centauri/t6050/centauri_recovery.c @@ -39,7 +39,8 @@ int centauri_t6050_boot_phase_for_control_stage(u32 control_stage, return 0; case 2: case 3: - return -EOPNOTSUPP; + *phase = CEN_BOOT_REWAKE; + return 0; default: return -EINVAL; } @@ -94,7 +95,8 @@ void centauri_t6050_schedule_transport_recover(struct centauri_t6050 *c) return; mutex_lock(&c->boot_lock); - if (c->boot_phase == CEN_BOOT_STOPPED || c->boot_phase == CEN_BOOT_FAILED) + if (READ_ONCE(c->removing) || c->boot_phase == CEN_BOOT_STOPPED || + c->boot_phase == CEN_BOOT_FAILED) goto out_unlock; control = readl(c->bar + 0x8000); @@ -106,6 +108,11 @@ void centauri_t6050_schedule_transport_recover(struct centauri_t6050 *c) c->boot_phase = CEN_BOOT_FAILED; goto out_unlock; } + if (phase == CEN_BOOT_REWAKE) { + mutex_unlock(&c->boot_lock); + centauri_t6050_request_rewake(c->pdev, -EIO, true); + return; + } WRITE_ONCE(c->ready, false); centauri_t6050_free_ipc(c); @@ -151,16 +158,15 @@ static void recover_phase_cycle(struct kunit *test) KUNIT_EXPECT_EQ(test, phase, CEN_BOOT_CYCLE); } -static void recover_phase_stop23(struct kunit *test) +static void recover_phase_rewake23(struct kunit *test) { enum centauri_t6050_boot_phase phase = CEN_BOOT_READY; - KUNIT_EXPECT_EQ(test, - centauri_t6050_boot_phase_for_control_stage(2, &phase), - -EOPNOTSUPP); - KUNIT_EXPECT_EQ(test, - centauri_t6050_boot_phase_for_control_stage(3, &phase), - -EOPNOTSUPP); + KUNIT_ASSERT_EQ(test, centauri_t6050_boot_phase_for_control_stage(2, &phase), 0); + KUNIT_EXPECT_EQ(test, phase, CEN_BOOT_REWAKE); + phase = CEN_BOOT_READY; + KUNIT_ASSERT_EQ(test, centauri_t6050_boot_phase_for_control_stage(3, &phase), 0); + KUNIT_EXPECT_EQ(test, phase, CEN_BOOT_REWAKE); } static void recover_phase_null(struct kunit *test) @@ -204,7 +210,7 @@ static struct kunit_case centauri_recovery_cases[] = { KUNIT_CASE(recover_phase_rom), KUNIT_CASE(recover_phase_ipc), KUNIT_CASE(recover_phase_cycle), - KUNIT_CASE(recover_phase_stop23), + KUNIT_CASE(recover_phase_rewake23), KUNIT_CASE(recover_phase_null), KUNIT_CASE(control_idle_no_event), KUNIT_CASE(control_idle_settled), diff --git a/drivers/net/wireless/apple/centauri/t6050/centauri_t6050.h b/drivers/net/wireless/apple/centauri/t6050/centauri_t6050.h index 41a1b8e6e1c04..f6e653034a782 100644 --- a/drivers/net/wireless/apple/centauri/t6050/centauri_t6050.h +++ b/drivers/net/wireless/apple/centauri/t6050/centauri_t6050.h @@ -35,6 +35,7 @@ enum centauri_t6050_boot_phase { CEN_BOOT_READY, CEN_BOOT_FAILED, CEN_BOOT_STOPPED, + CEN_BOOT_REWAKE, /* Dispatch to the recovery owner, not boot_work. */ }; struct centauri_t6050 { @@ -76,6 +77,7 @@ bool centauri_t6050_ipc_fenced(struct centauri_t6050_ipc *ipc); void centauri_t6050_detach_ipc(struct centauri_t6050_ipc *ipc); int centauri_t6050_alpha_resources(struct centauri_t6050 *c, struct cen_alpha_resources *resources); bool centauri_t6050_stop_dma(struct pci_dev *pdev); +void centauri_t6050_request_rewake(struct pci_dev *fn, int error, bool force_reset); #if IS_ENABLED(CONFIG_APPLE_CENTAURI_T6050_WIFI) irqreturn_t centauri_t6050_alpha_irq(int irq, void *data); diff --git a/tools/asahi/centauri-recovery-tests.py b/tools/asahi/centauri-recovery-tests.py index 7d1d7a342a12c..88221db0d40a2 100755 --- a/tools/asahi/centauri-recovery-tests.py +++ b/tools/asahi/centauri-recovery-tests.py @@ -16,18 +16,20 @@ ROOT = Path(__file__).resolve().parents[2] SOURCE = (ROOT / 'drivers/net/wireless/apple/centauri/t6050/centauri_pci.c').read_text() +RECOVERY = (ROOT / 'drivers/net/wireless/apple/centauri/t6050/centauri_recovery.c').read_text() +HEADER = (ROOT / 'drivers/net/wireless/apple/centauri/t6050/centauri_t6050.h').read_text() -def block(name): - match = re.search(r'^(?:static )?(?:int|void|bool) ' + name + r'\([^;]*?\)\n\{', SOURCE, re.M) +def block(name, source=SOURCE): + match = re.search(r'^(?:static )?(?:int|void|bool) ' + name + r'\([^;]*?\)\n\{', source, re.M) if not match: raise RuntimeError(f'Missing production function: {name}') - brace = SOURCE.index('{', match.start()) + brace = source.index('{', match.start()) depth, end = 1, brace + 1 while depth: - depth += (SOURCE[end] == '{') - (SOURCE[end] == '}') + depth += (source[end] == '{') - (source[end] == '}') end += 1 - return SOURCE[match.start():end] + return source[match.start():end] PRELUDE = r''' @@ -40,10 +42,11 @@ def block(name): #define CONFIG_APPLE_CENTAURI_T6050_WIFI 1 #define IS_ENABLED(option) ((option) ? 1 : 0) #define WRITE_ONCE(x,v) ((x)=(v)) +#define READ_ONCE(x) (x) +#define dev_err(...) ((void)0) #define smp_store_release(p,v) (*(p)=(v)) #define PCI_DEVFN(s,f) (((s)<<3)|(f)) #define PCI_SLOT(f) ((f)>>3) -#define CEN_BOOT_STOPPED 5 #define guard(x) mock_guard #define list_for_each_entry(v,h,n) for ((v)=owner; (v); (v)=NULL) struct device { int lock; void *data; }; @@ -56,7 +59,7 @@ def block(name): struct centauri_t6050_rewake { struct pci_dev *bridge, *control, *beta; unsigned slot, generation, work_generation; - bool active, rerun; + bool active, rerun, force_reset; int error, node; void *arena; struct kref ref; @@ -67,11 +70,22 @@ def block(name): struct pci_dev *pdev; struct centauri_t6050_ipc *ipc; bool removing, ready, firmware_sleep, pm_prepared; + bool boot_attempted; + unsigned char *bar; int boot_work, boot_lock, alpha_irqs, irqs, boot_phase; void *firmware, *descriptor; }; static int cen_recovery_lock, cen_recovery_owners, cen_rewake_wq; static bool cen_exiting, supported_sleep=true; +static int system_long_wq; +static unsigned control_stage; +static bool wake_reset_done; +static unsigned readl(void *bar) { (void)bar; return control_stage; } +static void queue_delayed_work(int wq, int *work, int delay) +{ (void)wq; (void)delay; (*work)++; } +static void centauri_t6050_free_ipc(struct centauri_t6050 *c) { c->ipc = NULL; } +static bool apple_pcie_t6050_warm_reset_done(struct pci_dev *p) +{ (void)p; return wake_reset_done; } static struct centauri_t6050_rewake *owner; static struct pci_dev *slots[3]; static int events[100], nevents, stop_error, beta_error, release_error; @@ -148,6 +162,17 @@ def block(name): struct pci_dev fn[3], bridge; struct pci_bus bus; struct centauri_t6050_ipc ipc={.fenced=true}; + static unsigned char bar[0x8004]; + for (unsigned stage=2; stage<=3; stage++) { + reset(&c,&rw,fn,&bridge,&bus); + c.bar=bar; c.boot_phase=CEN_BOOT_READY; c.ipc=&ipc; + control_stage=stage; wake_reset_done=true; + centauri_t6050_schedule_transport_recover(&c); + apple_centauri_sleep_recovery_needed(&fn[2], -EIO); + assert(queues==1 && c.ipc==&ipc && !c.boot_work && !c.boot_lock); + assert(!centauri_t6050_rewake_already_reset(&rw)); + assert(centauri_t6050_rewake_already_reset(&rw)); /* Once per runtime request. */ + } reset(&c,&rw,fn,&bridge,&bus); c.ipc=&ipc; c.firmware=&c; c.descriptor=&rw; assert(!centauri_t6050_quiesce(&c)); @@ -481,10 +506,18 @@ def run(): parser.add_argument('--out', type=Path) parser.add_argument('--negative-controls', action='store_true') args = parser.parse_args() - names = ['apple_centauri_sleep_recovery_needed', 'centauri_t6050_domain_fence', + names = ['centauri_t6050_request_rewake', 'apple_centauri_sleep_recovery_needed', + 'centauri_t6050_rewake_already_reset', 'centauri_t6050_domain_fence', 'centauri_t6050_quiesce', 'centauri_t6050_prepare', 'centauri_t6050_complete'] bodies = '\n'.join(block(name) for name in names) + boot_phases = re.search(r'enum centauri_t6050_boot_phase \{.*?\n\};', HEADER, re.DOTALL) + if boot_phases is None: + raise RuntimeError('Production boot phase enum missing') + bodies = 'typedef unsigned u32;\n' + boot_phases.group() + '\n' + block( + 'centauri_t6050_boot_phase_for_control_stage', RECOVERY) + '\n' + bodies + '\n' + block( + 'centauri_t6050_schedule_transport_recover', RECOVERY) variants = [('baseline', bodies), + ('negative-reuse-old-wake-reset', bodies.replace('rw->force_reset |= force_reset;', '(void)force_reset;')), ('negative-skip-fence', bodies.replace('!centauri_t6050_domain_fence(c->recovery)', 'false')), ('negative-skip-release', bodies.replace('ret = centauri_t6050_beta_call(c->recovery, true);', 'ret = 0;')), ('negative-lost-pm-error', bodies.replace('error = centauri_t6050_wifi_pm_error(c);', 'error = 0;')), @@ -502,6 +535,7 @@ def run(): '\tif (!ret)\n\t\tret = centauri_t6050_beta_call(rw, true);', '\tdevice_unlock(&fn->dev);\n\tif (!ret)\n\t\tret = centauri_t6050_beta_call(rw, true);'))] failures = { + 'negative-reuse-old-wake-reset': '!centauri_t6050_rewake_already_reset(&rw)', 'negative-unlock-before-tuples': '!remove_done && original->dev.locked && rw->control==original', 'negative-skip-fence': 'first(WIFI_STOP)first(FENCE) && first(FREE)>first(RELEASE)', From 016a839089beec31139732aa7c28386acc49fb07 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Fri, 20 Nov 2026 11:12:39 -0600 Subject: [PATCH 11/11] wifi: centauri: sync physical recovery fixture with transport recovery Extract the recovery cancellation and warm-reset helpers from the driver. Model pending recovery work so teardown must cancel it before Wi-Fi unregisters. The baseline passes and all eight mutations fail at model assertions. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- tools/asahi/centauri-physical-recovery-tests.c | 12 +++++++++--- tools/asahi/centauri-physical-recovery-tests.py | 11 +++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/tools/asahi/centauri-physical-recovery-tests.c b/tools/asahi/centauri-physical-recovery-tests.c index 4c765125fe737..8a5dd7c51a8f8 100644 --- a/tools/asahi/centauri-physical-recovery-tests.c +++ b/tools/asahi/centauri-physical-recovery-tests.c @@ -20,6 +20,8 @@ #define PCI_COMMAND_MASTER 4 #define PCI_EXP_LNKSTA 18 #define PCI_EXP_LNKSTA_DLLLA 0x2000 +#define CONFIG_APPLE_CENTAURI_T6050_WIFI 1 +#define IS_ENABLED(option) (option) #define CEN_BOOT_STOPPED 5 #define SZ_16K 16384 #define CEN_ARENA_SIZE 65536 @@ -37,7 +39,7 @@ struct pci_dev { int devfn, refs, command, reads, writes; bool visible, pending; }; -struct work_struct { int unused; }; +struct work_struct { bool pending; }; struct kref { int count; }; struct centauri_t6050_ipc { bool owned[3]; struct pci_dev *function[3]; void *buffer; @@ -51,7 +53,7 @@ struct centauri_t6050_rewake { struct work_struct work; struct kref ref; struct pci_dev *bridge, *control, *beta; unsigned int slot, generation, work_generation; - bool active, rerun, control_lease, beta_lease; + bool active, rerun, force_reset, control_lease, beta_lease; int error; struct centauri_t6050_ipc *ipc; void *firmware, *descriptor, *arena, *data; @@ -69,6 +71,7 @@ struct centauri_t6050 { size_t firmware_size; bool removing, ready, firmware_sleep, link_ready, boot_attempted; int boot_lock, boot_work, boot_phase; + struct work_struct transport_recover_work; struct centauri_t6050_irqs irqs, alpha_irqs; }; struct cen_bt { @@ -116,9 +119,11 @@ static int pcibios_err_to_errno(int x) { return x ? -EIO : 0; } static bool pci_wait_for_pending_transaction(struct pci_dev *p) { return can_config(p) && !p->pending && !force_pending; } static int work_busy(int *p) { return *p; } +static void cancel_work_sync(struct work_struct *p) +{ assert(control.removing && !control.ready && !control.boot_lock); p->pending = false; } static void cancel_delayed_work_sync(int *p) { *p = 0; boot_users = 0; } static void centauri_t6050_wifi_unregister(struct centauri_t6050 *c) -{ assert(c->removing); wifi_users = 0; } +{ assert(c->removing && !c->transport_recover_work.pending); wifi_users = 0; } static int pci_irq_vector(struct pci_dev *p, int n) { (void)p; return n; } static void free_irq(int n, void *c) { (void)n; (void)c; irq_users = 0; } static void centauri_t6050_free_irqs(struct centauri_t6050_irqs *p) @@ -230,6 +235,7 @@ static void fixture(void) owner.ops = &ops; owner.data = β control.pdev = &devs[0]; control.recovery = &owner; control.link_ready = true; control.boot_attempted = control.ready = true; + control.transport_recover_work.pending = true; control.irqs.pdev = &devs[0]; control.alpha_irqs.pdev = &devs[1]; control.irqs.count = control.alpha_irqs.count = 1; devs[0].dev.driver = ¢auri_t6050_driver.driver; devs[0].drvdata = &control; diff --git a/tools/asahi/centauri-physical-recovery-tests.py b/tools/asahi/centauri-physical-recovery-tests.py index d9c843d666c5b..34b731305e80b 100644 --- a/tools/asahi/centauri-physical-recovery-tests.py +++ b/tools/asahi/centauri-physical-recovery-tests.py @@ -20,6 +20,7 @@ ROOT = Path(__file__).resolve().parents[2] PCI = 'drivers/net/wireless/apple/centauri/t6050/centauri_pci.c' IPC = 'drivers/net/wireless/apple/centauri/t6050/centauri_ipc.c' +RECOVERY = 'drivers/net/wireless/apple/centauri/t6050/centauri_recovery.c' BT = 'drivers/bluetooth/btcentauri_t6050.c' GUARDS = { 'bound': '(c->ipc || c->firmware || c->descriptor || c->recovery->arena) &&\n\t ', @@ -73,12 +74,14 @@ def generate(sources, mutation): function(sources[BT], 'cen_retained'), function(sources[BT], 'cen_stop'), function(sources[IPC], 'centauri_t6050_ipc_fenced'), - function(sources[IPC], 'centauri_t6050_free_ipc')] + function(sources[IPC], 'centauri_t6050_free_ipc'), + function(sources[RECOVERY], 'centauri_t6050_transport_recover_cancel')] chunks += [function(source, name) for name in ( 'centauri_t6050_free_boot', 'centauri_t6050_beta_call', 'centauri_t6050_domain_fence', 'centauri_t6050_quiesce', 'centauri_t6050_remove', 'centauri_t6050_rewake_teardown', - 'centauri_t6050_link_active', 'centauri_t6050_rewake_worker')] + 'centauri_t6050_link_active', 'centauri_t6050_rewake_already_reset', + 'centauri_t6050_rewake_worker')] fixture = Path(__file__).with_suffix('.c').read_text() marker = '/* ACTUAL_FUNCTIONS */' if fixture.count(marker) != 1: @@ -88,7 +91,7 @@ def generate(sources, mutation): def run(args, out): out.mkdir(parents=True, exist_ok=True) - sources = {path: (ROOT / path).read_text() for path in (PCI, IPC, BT)} + sources = {path: (ROOT / path).read_text() for path in (PCI, IPC, BT, RECOVERY)} c = out / 'centauri-recovery.c' binary = out / 'centauri-recovery' c.write_text(generate(sources, args.mutation)) @@ -102,7 +105,7 @@ def run(args, out): (out / 'model.log').write_text(result.stdout + result.stderr) (out / 'result.json').write_text(json.dumps({ 'mutation': args.mutation, 'exit': result.returncode, - 'extracted_functions': 15, 'compiler_command': command, + 'extracted_functions': 17, 'compiler_command': command, 'sources': {path: hashlib.sha256(text.encode()).hexdigest() for path, text in sources.items()}, }, indent=2) + '\n')