unsigned int i;
        int have_msi;
 
-       for (i = 0; i < host->n_ports; i++)
-               ata_port_detach(host->ports[i]);
+       ata_host_detach(host);
 
        have_msi = hpriv->flags & AHCI_FLAG_MSI;
        free_irq(host->irq, host);
 
        scsi_remove_host(ap->scsi_host);
 }
 
+/**
+ *     ata_host_detach - Detach all ports of an ATA host
+ *     @host: Host to detach
+ *
+ *     Detach all ports of @host.
+ *
+ *     LOCKING:
+ *     Kernel thread context (may sleep).
+ */
+void ata_host_detach(struct ata_host *host)
+{
+       int i;
+
+       for (i = 0; i < host->n_ports; i++)
+               ata_port_detach(host->ports[i]);
+}
+
 /**
  *     ata_host_remove - PCI layer callback for device removal
  *     @host: ATA host set that was removed
 {
        unsigned int i;
 
-       for (i = 0; i < host->n_ports; i++)
-               ata_port_detach(host->ports[i]);
+       ata_host_detach(host);
 
        free_irq(host->irq, host);
        if (host->irq2)
 EXPORT_SYMBOL_GPL(ata_std_ports);
 EXPORT_SYMBOL_GPL(ata_host_init);
 EXPORT_SYMBOL_GPL(ata_device_add);
-EXPORT_SYMBOL_GPL(ata_port_detach);
+EXPORT_SYMBOL_GPL(ata_host_detach);
 EXPORT_SYMBOL_GPL(ata_host_remove);
 EXPORT_SYMBOL_GPL(ata_sg_init);
 EXPORT_SYMBOL_GPL(ata_sg_init_one);
 
 extern int ata_pci_clear_simplex(struct pci_dev *pdev);
 #endif /* CONFIG_PCI */
 extern int ata_device_add(const struct ata_probe_ent *ent);
-extern void ata_port_detach(struct ata_port *ap);
+extern void ata_host_detach(struct ata_host *host);
 extern void ata_host_init(struct ata_host *, struct device *,
                          unsigned long, const struct ata_port_operations *);
 extern void ata_host_remove(struct ata_host *host);