From d77eb3148dd16969ba4e6e42b60b6723d1e18366 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 27 Nov 2026 10:27:27 +0100 Subject: [PATCH] wifi: apple: centauri: enable function memory space before polling Beta BAR0 enumerate_functions() maps BAR 0 of functions 1 (Alpha Wi-Fi) and 2 (Beta Bluetooth) via pci_iomap(), but never called pci_enable_device_mem() on them. Function 1 happened to be enabled because apple_centauri itself probes 0x1902, while function 2 (0x1903) belongs to btcentauri. Since commit 227c89b69b65 ("wifi: apple: centauri: attach Bluetooth once Beta's firmware runs"), centauri_boot_write() calls centauri_attach_beta() -> centauri_beta_running() at the end of IPC bootstrap, which reads ipc->bar[2] + 0x18 and ipc->bar[2]. When btcentauri has not already probed function 2 (for example when btcentauri is blacklisted until a boot script loads it after rom_boot, or is built as a module before udev probes it), 0000:01:00.2 still has PCI_COMMAND_MEMORY cleared and the BAR0 read causes an immediate Asynchronous SError kernel panic on Apple Silicon PCIe. Call pci_enable_device_mem() (serialized with device_lock(), matching the t6050 backend) for functions 1 and 2 before pci_iomap() in enumerate_functions(), guard centauri_beta_running() on ipc->enabled[2], and balance with pci_disable_device() after pci_iounmap() in centauri_free_ipc(). Fixes: 227c89b69b65 ("wifi: apple: centauri: attach Bluetooth once Beta's firmware runs") Signed-off-by: Thomas Glanzmann --- .../wireless/apple/centauri/centauri_ipc.c | 22 ++++++++++++++++--- .../wireless/apple/centauri/centauri_pci.c | 7 +++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/drivers/net/wireless/apple/centauri/centauri_ipc.c b/drivers/net/wireless/apple/centauri/centauri_ipc.c index d657e6a4b5374..2905a7e56e8ce 100644 --- a/drivers/net/wireless/apple/centauri/centauri_ipc.c +++ b/drivers/net/wireless/apple/centauri/centauri_ipc.c @@ -33,6 +33,7 @@ struct centauri_ipc { struct list_head buffers; struct pci_dev *function[3]; void __iomem *bar[3]; + bool enabled[3]; struct cen_context control, alpha; struct cen_buffer *secondary, *window, *cchi_rx, *cchi_tx, *debug_rx; struct cen_buffer *alpha_log; @@ -426,7 +427,7 @@ static int enumerate_functions(struct centauri *c) { struct centauri_ipc *ipc = c->ipc; u16 control; - int i, cap; + int i, cap, ret; dma_addr_t msi; pci_lock_rescan_remove(); @@ -442,6 +443,14 @@ static int enumerate_functions(struct centauri *c) return -ENODEV; if (!(pci_resource_flags(ipc->function[i], 0) & IORESOURCE_MEM)) return -ENODEV; + if (i) { + device_lock(&ipc->function[i]->dev); + ret = pci_enable_device_mem(ipc->function[i]); + device_unlock(&ipc->function[i]->dev); + if (ret) + return ret; + ipc->enabled[i] = true; + } ipc->bar[i] = pci_iomap(ipc->function[i], 0, 0); if (!ipc->bar[i]) return -ENOMEM; @@ -558,9 +567,11 @@ int centauri_start_ipc(struct centauri *c) */ bool centauri_beta_running(struct centauri *c) { - void __iomem *bar = c->ipc ? c->ipc->bar[2] : NULL; + struct centauri_ipc *ipc = c->ipc; - return bar && readl(bar + 0x18) == 2 && !readl(bar); + if (!ipc || !ipc->enabled[2] || !ipc->bar[2]) + return false; + return readl(ipc->bar[2] + 0x18) == 2 && !readl(ipc->bar[2]); } void centauri_free_ipc(struct centauri *c) @@ -595,6 +606,11 @@ void centauri_free_ipc(struct centauri *c) for (i = 0; i < 3; i++) { if (ipc->bar[i]) pci_iounmap(ipc->function[i], ipc->bar[i]); + if (ipc->enabled[i]) { + device_lock(&ipc->function[i]->dev); + pci_disable_device(ipc->function[i]); + device_unlock(&ipc->function[i]->dev); + } pci_dev_put(ipc->function[i]); } kfree(ipc); diff --git a/drivers/net/wireless/apple/centauri/centauri_pci.c b/drivers/net/wireless/apple/centauri/centauri_pci.c index 67d3a7884759f..b2b1cd434a657 100644 --- a/drivers/net/wireless/apple/centauri/centauri_pci.c +++ b/drivers/net/wireless/apple/centauri/centauri_pci.c @@ -488,9 +488,10 @@ static int centauri_resume(struct device *dev) static DEFINE_SIMPLE_DEV_PM_OPS(centauri_pm_ops, centauri_suspend, centauri_resume); -/* 0x1903 is the Beta (Bluetooth) function: btcentauri claims it. This driver needs functions - * 0 and 1 (1 is enabled here, its BAR is used by the Wi-Fi code) and reaches function 2 only - * through config space and its struct device for DMA. +/* 0x1903 is the Beta (Bluetooth) function: btcentauri claims it. This driver binds functions + * 0 and 1 (1 is enabled here, its BAR is used by the Wi-Fi code) and enables function 2's + * memory space during IPC bootstrap so centauri_beta_running() can poll Beta's BAR0 safely + * even when btcentauri has not probed yet. */ static const struct pci_device_id centauri_ids[] = { { PCI_DEVICE(PCI_VENDOR_ID_APPLE, 0x1900), .driver_data = 0x8000 },