libata: use WARN_ON_ONCE on hot paths
[safe/jmp/linux-2.6] / drivers / ata / pata_legacy.c
index f13f10a..6c1d778 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *   pata-legacy.c - Legacy port PATA/SATA controller driver.
- *   Copyright 2005/2006 Red Hat <alan@redhat.com>, all rights reserved.
+ *   Copyright 2005/2006 Red Hat, all rights reserved.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -194,15 +194,12 @@ static int legacy_set_mode(struct ata_link *link, struct ata_device **unused)
 {
        struct ata_device *dev;
 
-       ata_link_for_each_dev(dev, link) {
-               if (ata_dev_enabled(dev)) {
-                       ata_dev_printk(dev, KERN_INFO,
-                                               "configured for PIO\n");
-                       dev->pio_mode = XFER_PIO_0;
-                       dev->xfer_mode = XFER_PIO_0;
-                       dev->xfer_shift = ATA_SHIFT_PIO;
-                       dev->flags |= ATA_DFLAG_PIO;
-               }
+       ata_for_each_dev(dev, link, ENABLED) {
+               ata_dev_printk(dev, KERN_INFO, "configured for PIO\n");
+               dev->pio_mode = XFER_PIO_0;
+               dev->xfer_mode = XFER_PIO_0;
+               dev->xfer_shift = ATA_SHIFT_PIO;
+               dev->flags |= ATA_DFLAG_PIO;
        }
        return 0;
 }
@@ -226,12 +223,12 @@ static const struct ata_port_operations legacy_base_port_ops = {
 
 static struct ata_port_operations simple_port_ops = {
        .inherits       = &legacy_base_port_ops,
-       .data_xfer      = ata_sff_data_xfer_noirq,
+       .sff_data_xfer  = ata_sff_data_xfer_noirq,
 };
 
 static struct ata_port_operations legacy_port_ops = {
        .inherits       = &legacy_base_port_ops,
-       .data_xfer      = ata_sff_data_xfer_noirq,
+       .sff_data_xfer  = ata_sff_data_xfer_noirq,
        .set_mode       = legacy_set_mode,
 };
 
@@ -305,7 +302,7 @@ static unsigned int pdc_data_xfer_vlb(struct ata_device *dev,
                        iowrite32_rep(ap->ioaddr.data_addr, buf, buflen >> 2);
 
                if (unlikely(slop)) {
-                       u32 pad;
+                       __le32 pad;
                        if (rw == READ) {
                                pad = cpu_to_le32(ioread32(ap->ioaddr.data_addr));
                                memcpy(buf + buflen - slop, &pad, slop);
@@ -325,7 +322,7 @@ static unsigned int pdc_data_xfer_vlb(struct ata_device *dev,
 static struct ata_port_operations pdc20230_port_ops = {
        .inherits       = &legacy_base_port_ops,
        .set_piomode    = pdc20230_set_piomode,
-       .data_xfer      = pdc_data_xfer_vlb,
+       .sff_data_xfer  = pdc_data_xfer_vlb,
 };
 
 /*
@@ -343,8 +340,8 @@ static void ht6560a_set_piomode(struct ata_port *ap, struct ata_device *adev)
        /* Get the timing data in cycles. For now play safe at 50Mhz */
        ata_timing_compute(adev, adev->pio_mode, &t, 20000, 1000);
 
-       active = FIT(t.active, 2, 15);
-       recover = FIT(t.recover, 4, 15);
+       active = clamp_val(t.active, 2, 15);
+       recover = clamp_val(t.recover, 4, 15);
 
        inb(0x3E6);
        inb(0x3E6);
@@ -377,8 +374,8 @@ static void ht6560b_set_piomode(struct ata_port *ap, struct ata_device *adev)
        /* Get the timing data in cycles. For now play safe at 50Mhz */
        ata_timing_compute(adev, adev->pio_mode, &t, 20000, 1000);
 
-       active = FIT(t.active, 2, 15);
-       recover = FIT(t.recover, 2, 16);
+       active = clamp_val(t.active, 2, 15);
+       recover = clamp_val(t.recover, 2, 16);
        recover &= 0x15;
 
        inb(0x3E6);
@@ -462,9 +459,9 @@ static void opti82c611a_set_piomode(struct ata_port *ap,
                ata_timing_merge(&t, &tp, &t, ATA_TIMING_SETUP);
        }
 
-       active = FIT(t.active, 2, 17) - 2;
-       recover = FIT(t.recover, 1, 16) - 1;
-       setup = FIT(t.setup, 1, 4) - 1;
+       active = clamp_val(t.active, 2, 17) - 2;
+       recover = clamp_val(t.recover, 1, 16) - 1;
+       setup = clamp_val(t.setup, 1, 4) - 1;
 
        /* Select the right timing bank for write timing */
        rc = ioread8(ap->ioaddr.lbal_addr);
@@ -541,9 +538,9 @@ static void opti82c46x_set_piomode(struct ata_port *ap, struct ata_device *adev)
                ata_timing_merge(&t, &tp, &t, ATA_TIMING_SETUP);
        }
 
-       active = FIT(t.active, 2, 17) - 2;
-       recover = FIT(t.recover, 1, 16) - 1;
-       setup = FIT(t.setup, 1, 4) - 1;
+       active = clamp_val(t.active, 2, 17) - 2;
+       recover = clamp_val(t.recover, 1, 16) - 1;
+       setup = clamp_val(t.setup, 1, 4) - 1;
 
        /* Select the right timing bank for write timing */
        rc = ioread8(ap->ioaddr.lbal_addr);
@@ -624,11 +621,11 @@ static void qdi6500_set_piomode(struct ata_port *ap, struct ata_device *adev)
        ata_timing_compute(adev, adev->pio_mode, &t, 30303, 1000);
 
        if (ld_qdi->fast) {
-               active = 8 - FIT(t.active, 1, 8);
-               recovery = 18 - FIT(t.recover, 3, 18);
+               active = 8 - clamp_val(t.active, 1, 8);
+               recovery = 18 - clamp_val(t.recover, 3, 18);
        } else {
-               active = 9 - FIT(t.active, 2, 9);
-               recovery = 15 - FIT(t.recover, 0, 15);
+               active = 9 - clamp_val(t.active, 2, 9);
+               recovery = 15 - clamp_val(t.recover, 0, 15);
        }
        timing = (recovery << 4) | active | 0x08;
 
@@ -641,7 +638,6 @@ static void qdi6500_set_piomode(struct ata_port *ap, struct ata_device *adev)
  *     qdi6580dp_set_piomode           -       PIO setup for dual channel
  *     @ap: Port
  *     @adev: Device
- *     @irq: interrupt line
  *
  *     In dual channel mode the 6580 has one clock per channel and we have
  *     to software clockswitch in qc_issue.
@@ -658,11 +654,11 @@ static void qdi6580dp_set_piomode(struct ata_port *ap, struct ata_device *adev)
        ata_timing_compute(adev, adev->pio_mode, &t, 30303, 1000);
 
        if (ld_qdi->fast) {
-               active = 8 - FIT(t.active, 1, 8);
-               recovery = 18 - FIT(t.recover, 3, 18);
+               active = 8 - clamp_val(t.active, 1, 8);
+               recovery = 18 - clamp_val(t.recover, 3, 18);
        } else {
-               active = 9 - FIT(t.active, 2, 9);
-               recovery = 15 - FIT(t.recover, 0, 15);
+               active = 9 - clamp_val(t.active, 2, 9);
+               recovery = 15 - clamp_val(t.recover, 0, 15);
        }
        timing = (recovery << 4) | active | 0x08;
 
@@ -695,11 +691,11 @@ static void qdi6580_set_piomode(struct ata_port *ap, struct ata_device *adev)
        ata_timing_compute(adev, adev->pio_mode, &t, 30303, 1000);
 
        if (ld_qdi->fast) {
-               active = 8 - FIT(t.active, 1, 8);
-               recovery = 18 - FIT(t.recover, 3, 18);
+               active = 8 - clamp_val(t.active, 1, 8);
+               recovery = 18 - clamp_val(t.recover, 3, 18);
        } else {
-               active = 9 - FIT(t.active, 2, 9);
-               recovery = 15 - FIT(t.recover, 0, 15);
+               active = 9 - clamp_val(t.active, 2, 9);
+               recovery = 15 - clamp_val(t.recover, 0, 15);
        }
        timing = (recovery << 4) | active | 0x08;
        ld_qdi->clock[adev->devno] = timing;
@@ -746,14 +742,12 @@ static unsigned int vlb32_data_xfer(struct ata_device *adev, unsigned char *buf,
                        ioread32_rep(ap->ioaddr.data_addr, buf, buflen >> 2);
 
                if (unlikely(slop)) {
-                       u32 pad;
+                       __le32 pad;
                        if (rw == WRITE) {
                                memcpy(&pad, buf + buflen - slop, slop);
-                               pad = le32_to_cpu(pad);
-                               iowrite32(pad, ap->ioaddr.data_addr);
+                               iowrite32(le32_to_cpu(pad), ap->ioaddr.data_addr);
                        } else {
-                               pad = ioread32(ap->ioaddr.data_addr);
-                               pad = cpu_to_le32(pad);
+                               pad = cpu_to_le32(ioread32(ap->ioaddr.data_addr));
                                memcpy(buf + buflen - slop, &pad, slop);
                        }
                }
@@ -775,19 +769,19 @@ static struct ata_port_operations qdi6500_port_ops = {
        .inherits       = &legacy_base_port_ops,
        .set_piomode    = qdi6500_set_piomode,
        .qc_issue       = qdi_qc_issue,
-       .data_xfer      = vlb32_data_xfer,
+       .sff_data_xfer  = vlb32_data_xfer,
 };
 
 static struct ata_port_operations qdi6580_port_ops = {
        .inherits       = &legacy_base_port_ops,
        .set_piomode    = qdi6580_set_piomode,
-       .data_xfer      = vlb32_data_xfer,
+       .sff_data_xfer  = vlb32_data_xfer,
 };
 
 static struct ata_port_operations qdi6580dp_port_ops = {
        .inherits       = &legacy_base_port_ops,
        .set_piomode    = qdi6580dp_set_piomode,
-       .data_xfer      = vlb32_data_xfer,
+       .sff_data_xfer  = vlb32_data_xfer,
 };
 
 static DEFINE_SPINLOCK(winbond_lock);
@@ -830,8 +824,8 @@ static void winbond_set_piomode(struct ata_port *ap, struct ata_device *adev)
        else
                ata_timing_compute(adev, adev->pio_mode, &t, 30303, 1000);
 
-       active = (FIT(t.active, 3, 17) - 1) & 0x0F;
-       recovery = (FIT(t.recover, 1, 15) + 1) & 0x0F;
+       active = (clamp_val(t.active, 3, 17) - 1) & 0x0F;
+       recovery = (clamp_val(t.recover, 1, 15) + 1) & 0x0F;
        timing = (active << 4) | recovery;
        winbond_writecfg(ld_winbond->timing, timing, reg);
 
@@ -842,7 +836,7 @@ static void winbond_set_piomode(struct ata_port *ap, struct ata_device *adev)
                reg |= 0x08;    /* FIFO off */
        if (!ata_pio_need_iordy(adev))
                reg |= 0x02;    /* IORDY off */
-       reg |= (FIT(t.setup, 0, 3) << 6);
+       reg |= (clamp_val(t.setup, 0, 3) << 6);
        winbond_writecfg(ld_winbond->timing, timing + 1, reg);
 }
 
@@ -858,7 +852,7 @@ static int winbond_port(struct platform_device *dev,
 static struct ata_port_operations winbond_port_ops = {
        .inherits       = &legacy_base_port_ops,
        .set_piomode    = winbond_set_piomode,
-       .data_xfer      = vlb32_data_xfer,
+       .sff_data_xfer  = vlb32_data_xfer,
 };
 
 static struct legacy_controller controllers[] = {
@@ -1030,7 +1024,7 @@ static __init int legacy_init_one(struct legacy_probe *probe)
        /* Nothing found means we drop the port as its probably not there */
 
        ret = -ENODEV;
-       ata_link_for_each_dev(dev, &ap->link) {
+       ata_for_each_dev(dev, &ap->link, ALL) {
                if (!ata_dev_absent(dev)) {
                        legacy_host[probe->slot] = host;
                        ld->platform_dev = pdev;