From fb9278cf3f0d1346d3c0a0cdb7144518402b0178 Mon Sep 17 00:00:00 2001 From: Dj <43033058+DjDeveloperr@users.noreply.github.com> Date: Thu, 26 Nov 2026 02:47:41 -0500 Subject: [PATCH 1/2] wifi: apple: centauri: stop each function's DMA before freeing its buffers A restart, and removal, clear Bus Master on the N1's functions and free every buffer the firmware can write right after. Clearing Bus Master only stops new requests: writes a function issued before it can still be on their way. Before any buffer is freed, read each function's command register back after clearing Bus Master, which returns after the function's earlier posted writes, and wait for its pending transactions; the same for the boot DMA. If a function cannot be stopped, keep all the buffers. A restart is then not attempted, and the worker tries again in 10 s within its usual limit; removal leaves them allocated. The T6050 driver already does this in centauri_t6050_stop_dma(). Fixes: efa93c24e38d ("wifi: apple: add hardware-qualified N1 driver and J813 workbench") Fixes: 47706b5b629e ("wifi: apple: centauri: restart a stopped N1 firmware without a reboot") Signed-off-by: Dj <43033058+DjDeveloperr@users.noreply.github.com> --- .../net/wireless/apple/centauri/centauri.h | 3 +- .../wireless/apple/centauri/centauri_ipc.c | 31 +++++++++++++++++-- .../wireless/apple/centauri/centauri_pci.c | 20 +++++++++--- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/drivers/net/wireless/apple/centauri/centauri.h b/drivers/net/wireless/apple/centauri/centauri.h index 17abbfb8352f2..e6ebd80dd4388 100644 --- a/drivers/net/wireless/apple/centauri/centauri.h +++ b/drivers/net/wireless/apple/centauri/centauri.h @@ -105,7 +105,8 @@ int centauri_port_cycle(struct pci_dev *pdev, int *reset_ret); bool centauri_warm_reset_described(struct pci_dev *pdev); int centauri_start_ipc(struct centauri *c); bool centauri_beta_running(struct centauri *c); -void centauri_free_ipc(struct centauri *c); +bool centauri_stop_dma(struct pci_dev *pdev); +bool centauri_free_ipc(struct centauri *c); int centauri_alpha_resources(struct centauri *c, struct cen_alpha_resources *resources); int centauri_alpha_log_buffer(struct centauri *c, void **cpu, dma_addr_t *dma, size_t *size); int centauri_wifi_register(struct centauri *c); diff --git a/drivers/net/wireless/apple/centauri/centauri_ipc.c b/drivers/net/wireless/apple/centauri/centauri_ipc.c index d657e6a4b5374..98a16e11e5c21 100644 --- a/drivers/net/wireless/apple/centauri/centauri_ipc.c +++ b/drivers/net/wireless/apple/centauri/centauri_ipc.c @@ -563,15 +563,36 @@ bool centauri_beta_running(struct centauri *c) return bar && readl(bar + 0x18) == 2 && !readl(bar); } -void centauri_free_ipc(struct centauri *c) +/* + * Clearing Bus Master stops new requests only. The read back of the command + * register returns after the function's earlier posted writes, and the wait + * covers its requests still in flight. + */ +bool centauri_stop_dma(struct pci_dev *pdev) +{ + u16 command; + + pci_clear_master(pdev); + if (pci_read_config_word(pdev, PCI_COMMAND, &command) || + (command & PCI_COMMAND_MASTER)) + return false; + return pci_wait_for_pending_transaction(pdev); +} + +/* + * Returns false, with every IPC buffer kept, if a function's DMA could not be + * stopped. A later call (a retried restart, or removal) tries again. + */ +bool centauri_free_ipc(struct centauri *c) { struct centauri_ipc *ipc = c->ipc; struct cen_buffer *buffer, *next; + bool stopped = true; int i, cap; u16 control; if (!ipc) - return; + return true; for (i = 0; i < 3; i++) if (ipc->vectors[i]) free_vectors(c, i); @@ -587,6 +608,11 @@ void centauri_free_ipc(struct centauri *c) } pci_clear_master(ipc->function[i]); } + for (i = 0; i < 3; i++) + if (ipc->function[i] && !centauri_stop_dma(ipc->function[i])) + stopped = false; + if (!stopped) + return false; list_for_each_entry_safe(buffer, next, &ipc->buffers, list) { dma_free_coherent(buffer->dev, buffer->size, buffer->cpu, buffer->dma); list_del(&buffer->list); @@ -599,6 +625,7 @@ void centauri_free_ipc(struct centauri *c) } kfree(ipc); c->ipc = NULL; + return true; } int centauri_alpha_resources(struct centauri *c, struct cen_alpha_resources *resources) diff --git a/drivers/net/wireless/apple/centauri/centauri_pci.c b/drivers/net/wireless/apple/centauri/centauri_pci.c index 67d3a7884759f..6a9517c40e734 100644 --- a/drivers/net/wireless/apple/centauri/centauri_pci.c +++ b/drivers/net/wireless/apple/centauri/centauri_pci.c @@ -46,20 +46,27 @@ static int centauri_status_show(struct seq_file *s, void *unused) } DEFINE_SHOW_ATTRIBUTE(centauri_status); -static void centauri_free_boot(struct centauri *c) +/* Returns false, with the buffers kept, if the N1's DMA could not be stopped. */ +static bool centauri_free_boot(struct centauri *c) { struct device *dev = &c->pdev->dev; if (!c->link_ready && c->boot_attempted) { dev_warn(dev, "retaining DMA buffers after failed link transition; reboot required\n"); - return; + return false; } /* Stop device writes before any DMA storage is released. */ - centauri_free_ipc(c); + if (!centauri_free_ipc(c)) { + dev_err(dev, "retaining DMA buffers: a function's DMA did not stop\n"); + return false; + } if (c->msi_cap) pci_write_config_word(c->pdev, c->msi_cap + PCI_MSI_FLAGS, c->msi_original & ~PCI_MSI_FLAGS_ENABLE); - pci_clear_master(c->pdev); + if (!centauri_stop_dma(c->pdev)) { + dev_err(dev, "retaining DMA buffers: the boot DMA did not stop\n"); + return false; + } if (c->firmware) dma_free_coherent(dev, c->firmware_size, c->firmware, c->firmware_dma); if (c->descriptor) @@ -67,6 +74,7 @@ static void centauri_free_boot(struct centauri *c) if (c->msi_page) dma_free_coherent(dev, SZ_16K, c->msi_page, c->msi_dma); c->firmware = c->descriptor = c->msi_page = NULL; + return true; } static int centauri_rom_boot(struct centauri *c) @@ -187,7 +195,9 @@ static int centauri_recover(struct centauri *c) if (beta) device_release_driver(&beta->dev); pci_dev_put(beta); - centauri_free_boot(c); + /* Nothing is reset while the firmware's buffers are still its own. */ + if (!centauri_free_boot(c)) + return -EBUSY; /* * The warm reset puts the chip back in its single-function ROM personality and wipes * functions 1 and 2. Remove them now; the IPC start's rescan adds them again, as at From d14a25a36d6c585956b535463310d05b8a40f285 Mon Sep 17 00:00:00 2001 From: Dj <43033058+DjDeveloperr@users.noreply.github.com> Date: Thu, 26 Nov 2026 02:54:11 -0500 Subject: [PATCH 2/2] wifi: apple: centauri: free no buffer until the IPC and boot DMA have both stopped The previous change freed the IPC buffers as soon as the IPC functions had stopped, before the boot DMA's stop was checked. Split stopping the IPC from freeing it, so a failed stop of either keeps every buffer. Signed-off-by: Dj <43033058+DjDeveloperr@users.noreply.github.com> --- .../net/wireless/apple/centauri/centauri.h | 3 ++- .../wireless/apple/centauri/centauri_ipc.c | 25 +++++++++++++------ .../wireless/apple/centauri/centauri_pci.c | 13 +++++----- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/drivers/net/wireless/apple/centauri/centauri.h b/drivers/net/wireless/apple/centauri/centauri.h index e6ebd80dd4388..891e53c7f6c4a 100644 --- a/drivers/net/wireless/apple/centauri/centauri.h +++ b/drivers/net/wireless/apple/centauri/centauri.h @@ -106,7 +106,8 @@ bool centauri_warm_reset_described(struct pci_dev *pdev); int centauri_start_ipc(struct centauri *c); bool centauri_beta_running(struct centauri *c); bool centauri_stop_dma(struct pci_dev *pdev); -bool centauri_free_ipc(struct centauri *c); +bool centauri_stop_ipc(struct centauri *c); +void centauri_free_ipc(struct centauri *c); int centauri_alpha_resources(struct centauri *c, struct cen_alpha_resources *resources); int centauri_alpha_log_buffer(struct centauri *c, void **cpu, dma_addr_t *dma, size_t *size); int centauri_wifi_register(struct centauri *c); diff --git a/drivers/net/wireless/apple/centauri/centauri_ipc.c b/drivers/net/wireless/apple/centauri/centauri_ipc.c index 98a16e11e5c21..9493f0b3f071e 100644 --- a/drivers/net/wireless/apple/centauri/centauri_ipc.c +++ b/drivers/net/wireless/apple/centauri/centauri_ipc.c @@ -580,13 +580,13 @@ bool centauri_stop_dma(struct pci_dev *pdev) } /* - * Returns false, with every IPC buffer kept, if a function's DMA could not be - * stopped. A later call (a retried restart, or removal) tries again. + * Stop the IPC's interrupts and every function's DMA. Returns false if a + * function's DMA could not be stopped; a later call (a retried restart, or + * removal) tries again. */ -bool centauri_free_ipc(struct centauri *c) +bool centauri_stop_ipc(struct centauri *c) { struct centauri_ipc *ipc = c->ipc; - struct cen_buffer *buffer, *next; bool stopped = true; int i, cap; u16 control; @@ -611,8 +611,18 @@ bool centauri_free_ipc(struct centauri *c) for (i = 0; i < 3; i++) if (ipc->function[i] && !centauri_stop_dma(ipc->function[i])) stopped = false; - if (!stopped) - return false; + return stopped; +} + +/* Only after centauri_stop_ipc() and the boot DMA's stop both succeeded. */ +void centauri_free_ipc(struct centauri *c) +{ + struct centauri_ipc *ipc = c->ipc; + struct cen_buffer *buffer, *next; + int i; + + if (!ipc) + return; list_for_each_entry_safe(buffer, next, &ipc->buffers, list) { dma_free_coherent(buffer->dev, buffer->size, buffer->cpu, buffer->dma); list_del(&buffer->list); @@ -625,7 +635,6 @@ bool centauri_free_ipc(struct centauri *c) } kfree(ipc); c->ipc = NULL; - return true; } int centauri_alpha_resources(struct centauri *c, struct cen_alpha_resources *resources) @@ -648,7 +657,7 @@ int centauri_alpha_resources(struct centauri *c, struct cen_alpha_resources *res } /* Called once under the Wi-Fi lock. Published logging memory stays owned by - * IPC until every function has bus mastering disabled in centauri_free_ipc. + * IPC until every function's DMA has stopped in centauri_stop_ipc. */ int centauri_alpha_log_buffer(struct centauri *c, void **cpu, dma_addr_t *dma, size_t *size) { diff --git a/drivers/net/wireless/apple/centauri/centauri_pci.c b/drivers/net/wireless/apple/centauri/centauri_pci.c index 6a9517c40e734..a9513e2dda5f2 100644 --- a/drivers/net/wireless/apple/centauri/centauri_pci.c +++ b/drivers/net/wireless/apple/centauri/centauri_pci.c @@ -50,23 +50,22 @@ DEFINE_SHOW_ATTRIBUTE(centauri_status); static bool centauri_free_boot(struct centauri *c) { struct device *dev = &c->pdev->dev; + bool stopped; if (!c->link_ready && c->boot_attempted) { dev_warn(dev, "retaining DMA buffers after failed link transition; reboot required\n"); return false; } - /* Stop device writes before any DMA storage is released. */ - if (!centauri_free_ipc(c)) { - dev_err(dev, "retaining DMA buffers: a function's DMA did not stop\n"); - return false; - } + /* Stop all device writes before any DMA storage is released. */ + stopped = centauri_stop_ipc(c); if (c->msi_cap) pci_write_config_word(c->pdev, c->msi_cap + PCI_MSI_FLAGS, c->msi_original & ~PCI_MSI_FLAGS_ENABLE); - if (!centauri_stop_dma(c->pdev)) { - dev_err(dev, "retaining DMA buffers: the boot DMA did not stop\n"); + if (!centauri_stop_dma(c->pdev) || !stopped) { + dev_err(dev, "retaining DMA buffers: the N1's DMA did not stop\n"); return false; } + centauri_free_ipc(c); if (c->firmware) dma_free_coherent(dev, c->firmware_size, c->firmware, c->firmware_dma); if (c->descriptor)