sata_promise: fix hardreset hotplug events, take 2

A Promise SATA controller will signal hotplug events when a hard
reset (COMRESET) is done on a port. These events aren't masked by
the driver, and the unexpected interrupts will cause a sequence
of failed reset attempts util libata's EH finally gives up.

This has not been a common problem so far, but the pending libata
hardreset-by-default changes makes it a critical issue.

The solution is to disable hotplug events before a reset, and to
reenable them afterwards. (Promise's driver does this too.)

This patch adds SATA-specific versions of ->freeze() and ->thaw()
that also disable and enable hotplug events. PATA ports continue
to use the old versions of ->freeze() and ->thaw().

Accesses to the hotplug register must be serialised via host->lock.
We rely on ap->lock == &ap->host->lock and that libata takes this
lock before ->freeze() and ->thaw(). Document this requirement.
The interrupt handler is adjusted so its hotplug register accesses
are inside the region protected by host->lock.

Tested on various chips (SATA300TX4, SATA300TX2plus, SATAII150TX4,
FastTrack TX4000) with various combinations of SATA and PATA disks,
with and without the pending hardreset-by-default changes.

Signed-off-by: Mikael Pettersson <mikpe@it.uu.se>
Acked-by: Tejun Heo <htejun@gmail.com>
Signed-off-by: Jeff Garzik <jeff@garzik.org>

authored by Mikael Pettersson and committed by Jeff Garzik c07a9c49 dda7aba1

+88 -21
+88 -21
drivers/ata/sata_promise.c
··· 46 46 #include "sata_promise.h" 47 47 48 48 #define DRV_NAME "sata_promise" 49 - #define DRV_VERSION "2.11" 49 + #define DRV_VERSION "2.12" 50 50 51 51 enum { 52 52 PDC_MAX_PORTS = 4, ··· 145 145 static void pdc_irq_clear(struct ata_port *ap); 146 146 static unsigned int pdc_qc_issue_prot(struct ata_queued_cmd *qc); 147 147 static void pdc_freeze(struct ata_port *ap); 148 + static void pdc_sata_freeze(struct ata_port *ap); 148 149 static void pdc_thaw(struct ata_port *ap); 150 + static void pdc_sata_thaw(struct ata_port *ap); 149 151 static void pdc_pata_error_handler(struct ata_port *ap); 150 152 static void pdc_sata_error_handler(struct ata_port *ap); 151 153 static void pdc_post_internal_cmd(struct ata_queued_cmd *qc); ··· 182 180 183 181 .qc_prep = pdc_qc_prep, 184 182 .qc_issue = pdc_qc_issue_prot, 185 - .freeze = pdc_freeze, 186 - .thaw = pdc_thaw, 183 + .freeze = pdc_sata_freeze, 184 + .thaw = pdc_sata_thaw, 187 185 .error_handler = pdc_sata_error_handler, 188 186 .post_internal_cmd = pdc_post_internal_cmd, 189 187 .cable_detect = pdc_sata_cable_detect, ··· 207 205 208 206 .qc_prep = pdc_qc_prep, 209 207 .qc_issue = pdc_qc_issue_prot, 210 - .freeze = pdc_freeze, 211 - .thaw = pdc_thaw, 208 + .freeze = pdc_sata_freeze, 209 + .thaw = pdc_sata_thaw, 212 210 .error_handler = pdc_sata_error_handler, 213 211 .post_internal_cmd = pdc_post_internal_cmd, 214 212 .cable_detect = pdc_sata_cable_detect, ··· 633 631 } 634 632 } 635 633 634 + static int pdc_is_sataii_tx4(unsigned long flags) 635 + { 636 + const unsigned long mask = PDC_FLAG_GEN_II | PDC_FLAG_4_PORTS; 637 + return (flags & mask) == mask; 638 + } 639 + 640 + static unsigned int pdc_port_no_to_ata_no(unsigned int port_no, 641 + int is_sataii_tx4) 642 + { 643 + static const unsigned char sataii_tx4_port_remap[4] = { 3, 1, 0, 2}; 644 + return is_sataii_tx4 ? sataii_tx4_port_remap[port_no] : port_no; 645 + } 646 + 647 + static unsigned int pdc_sata_nr_ports(const struct ata_port *ap) 648 + { 649 + return (ap->flags & PDC_FLAG_4_PORTS) ? 4 : 2; 650 + } 651 + 652 + static unsigned int pdc_sata_ata_port_to_ata_no(const struct ata_port *ap) 653 + { 654 + const struct ata_host *host = ap->host; 655 + unsigned int nr_ports = pdc_sata_nr_ports(ap); 656 + unsigned int i; 657 + 658 + for(i = 0; i < nr_ports && host->ports[i] != ap; ++i) 659 + ; 660 + BUG_ON(i >= nr_ports); 661 + return pdc_port_no_to_ata_no(i, pdc_is_sataii_tx4(ap->flags)); 662 + } 663 + 664 + static unsigned int pdc_sata_hotplug_offset(const struct ata_port *ap) 665 + { 666 + return (ap->flags & PDC_FLAG_GEN_II) ? PDC2_SATA_PLUG_CSR : PDC_SATA_PLUG_CSR; 667 + } 668 + 636 669 static void pdc_freeze(struct ata_port *ap) 637 670 { 638 671 void __iomem *mmio = ap->ioaddr.cmd_addr; ··· 678 641 tmp &= ~PDC_DMA_ENABLE; 679 642 writel(tmp, mmio + PDC_CTLSTAT); 680 643 readl(mmio + PDC_CTLSTAT); /* flush */ 644 + } 645 + 646 + static void pdc_sata_freeze(struct ata_port *ap) 647 + { 648 + struct ata_host *host = ap->host; 649 + void __iomem *host_mmio = host->iomap[PDC_MMIO_BAR]; 650 + unsigned int hotplug_offset = pdc_sata_hotplug_offset(ap); 651 + unsigned int ata_no = pdc_sata_ata_port_to_ata_no(ap); 652 + u32 hotplug_status; 653 + 654 + /* Disable hotplug events on this port. 655 + * 656 + * Locking: 657 + * 1) hotplug register accesses must be serialised via host->lock 658 + * 2) ap->lock == &ap->host->lock 659 + * 3) ->freeze() and ->thaw() are called with ap->lock held 660 + */ 661 + hotplug_status = readl(host_mmio + hotplug_offset); 662 + hotplug_status |= 0x11 << (ata_no + 16); 663 + writel(hotplug_status, host_mmio + hotplug_offset); 664 + readl(host_mmio + hotplug_offset); /* flush */ 665 + 666 + pdc_freeze(ap); 681 667 } 682 668 683 669 static void pdc_thaw(struct ata_port *ap) ··· 716 656 tmp &= ~PDC_IRQ_DISABLE; 717 657 writel(tmp, mmio + PDC_CTLSTAT); 718 658 readl(mmio + PDC_CTLSTAT); /* flush */ 659 + } 660 + 661 + static void pdc_sata_thaw(struct ata_port *ap) 662 + { 663 + struct ata_host *host = ap->host; 664 + void __iomem *host_mmio = host->iomap[PDC_MMIO_BAR]; 665 + unsigned int hotplug_offset = pdc_sata_hotplug_offset(ap); 666 + unsigned int ata_no = pdc_sata_ata_port_to_ata_no(ap); 667 + u32 hotplug_status; 668 + 669 + pdc_thaw(ap); 670 + 671 + /* Enable hotplug events on this port. 672 + * Locking: see pdc_sata_freeze(). 673 + */ 674 + hotplug_status = readl(host_mmio + hotplug_offset); 675 + hotplug_status |= 0x11 << ata_no; 676 + hotplug_status &= ~(0x11 << (ata_no + 16)); 677 + writel(hotplug_status, host_mmio + hotplug_offset); 678 + readl(host_mmio + hotplug_offset); /* flush */ 719 679 } 720 680 721 681 static void pdc_common_error_handler(struct ata_port *ap, ata_reset_fn_t hardreset) ··· 845 765 readl(mmio + PDC_INT_SEQMASK); 846 766 } 847 767 848 - static int pdc_is_sataii_tx4(unsigned long flags) 849 - { 850 - const unsigned long mask = PDC_FLAG_GEN_II | PDC_FLAG_4_PORTS; 851 - return (flags & mask) == mask; 852 - } 853 - 854 - static unsigned int pdc_port_no_to_ata_no(unsigned int port_no, 855 - int is_sataii_tx4) 856 - { 857 - static const unsigned char sataii_tx4_port_remap[4] = { 3, 1, 0, 2}; 858 - return is_sataii_tx4 ? sataii_tx4_port_remap[port_no] : port_no; 859 - } 860 - 861 768 static irqreturn_t pdc_interrupt(int irq, void *dev_instance) 862 769 { 863 770 struct ata_host *host = dev_instance; ··· 866 799 867 800 mmio_base = host->iomap[PDC_MMIO_BAR]; 868 801 802 + spin_lock(&host->lock); 803 + 869 804 /* read and clear hotplug flags for all ports */ 870 805 if (host->ports[0]->flags & PDC_FLAG_GEN_II) 871 806 hotplug_offset = PDC2_SATA_PLUG_CSR; ··· 883 814 884 815 if (mask == 0xffffffff && hotplug_status == 0) { 885 816 VPRINTK("QUICK EXIT 2\n"); 886 - return IRQ_NONE; 817 + goto done_irq; 887 818 } 888 - 889 - spin_lock(&host->lock); 890 819 891 820 mask &= 0xffff; /* only 16 tags possible */ 892 821 if (mask == 0 && hotplug_status == 0) {