diff --git a/drivers/net/wireless/apple/centauri/centauri.h b/drivers/net/wireless/apple/centauri/centauri.h index 17abbfb8352f2..891e53c7f6c4a 100644 --- a/drivers/net/wireless/apple/centauri/centauri.h +++ b/drivers/net/wireless/apple/centauri/centauri.h @@ -105,6 +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); +bool centauri_stop_dma(struct pci_dev *pdev); +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); diff --git a/drivers/net/wireless/apple/centauri/centauri_ipc.c b/drivers/net/wireless/apple/centauri/centauri_ipc.c index d657e6a4b5374..9493f0b3f071e 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); +} + +/* + * 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_stop_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,21 @@ 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; + 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); @@ -621,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 67d3a7884759f..a9513e2dda5f2 100644 --- a/drivers/net/wireless/apple/centauri/centauri_pci.c +++ b/drivers/net/wireless/apple/centauri/centauri_pci.c @@ -46,20 +46,26 @@ 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; + bool stopped; 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); + /* 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); - pci_clear_master(c->pdev); + 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) @@ -67,6 +73,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 +194,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