]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
Merge branch 'upstream'
authorJeff Garzik <jeff@garzik.org>
Fri, 24 Mar 2006 17:29:39 +0000 (12:29 -0500)
committerJeff Garzik <jeff@garzik.org>
Fri, 24 Mar 2006 17:29:39 +0000 (12:29 -0500)
Conflicts:

drivers/scsi/libata-core.c

1  2 
drivers/scsi/libata-core.c
drivers/scsi/sata_vsc.c
include/linux/libata.h

index dcce0f494d4a3fb42d0f03fe23a64a1da5495f35,0aff888d9ecdd42b9756f17fb983336c946de86d..c3c4263fdb123927a7c113be09b34f30ab5ed1f3
  static unsigned int ata_dev_init_params(struct ata_port *ap,
                                        struct ata_device *dev);
  static void ata_set_mode(struct ata_port *ap);
- static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev);
+ static unsigned int ata_dev_set_xfermode(struct ata_port *ap,
+                                        struct ata_device *dev);
+ static void ata_dev_xfermask(struct ata_port *ap, struct ata_device *dev);
 +static void ata_pio_error(struct ata_port *ap);
- static unsigned int ata_dev_xfermask(struct ata_port *ap,
-                                    struct ata_device *dev);
  
  static unsigned int ata_unique_id = 1;
  static struct workqueue_struct *ata_wq;
@@@ -191,7 -190,7 +191,7 @@@ static const u8 ata_rw_cmds[] = 
   *    ata_rwcmd_protocol - set taskfile r/w commands and protocol
   *    @qc: command to examine and configure
   *
-  *    Examine the device configuration and tf->flags to calculate 
+  *    Examine the device configuration and tf->flags to calculate
   *    the proper read/write commands and protocol to use.
   *
   *    LOCKING:
@@@ -204,7 -203,7 +204,7 @@@ int ata_rwcmd_protocol(struct ata_queue
        u8 cmd;
  
        int index, fua, lba48, write;
-  
        fua = (tf->flags & ATA_TFLAG_FUA) ? 4 : 0;
        lba48 = (tf->flags & ATA_TFLAG_LBA48) ? 2 : 0;
        write = (tf->flags & ATA_TFLAG_WRITE) ? 1 : 0;
@@@ -253,6 -252,29 +253,29 @@@ static unsigned int ata_pack_xfermask(u
                ((udma_mask << ATA_SHIFT_UDMA) & ATA_MASK_UDMA);
  }
  
+ /**
+  *    ata_unpack_xfermask - Unpack xfer_mask into pio, mwdma and udma masks
+  *    @xfer_mask: xfer_mask to unpack
+  *    @pio_mask: resulting pio_mask
+  *    @mwdma_mask: resulting mwdma_mask
+  *    @udma_mask: resulting udma_mask
+  *
+  *    Unpack @xfer_mask into @pio_mask, @mwdma_mask and @udma_mask.
+  *    Any NULL distination masks will be ignored.
+  */
+ static void ata_unpack_xfermask(unsigned int xfer_mask,
+                               unsigned int *pio_mask,
+                               unsigned int *mwdma_mask,
+                               unsigned int *udma_mask)
+ {
+       if (pio_mask)
+               *pio_mask = (xfer_mask & ATA_MASK_PIO) >> ATA_SHIFT_PIO;
+       if (mwdma_mask)
+               *mwdma_mask = (xfer_mask & ATA_MASK_MWDMA) >> ATA_SHIFT_MWDMA;
+       if (udma_mask)
+               *udma_mask = (xfer_mask & ATA_MASK_UDMA) >> ATA_SHIFT_UDMA;
+ }
  static const struct ata_xfer_ent {
        unsigned int shift, bits;
        u8 base;
@@@ -373,6 -395,15 +396,15 @@@ static const char *ata_mode_string(unsi
        return "<n/a>";
  }
  
+ static void ata_dev_disable(struct ata_port *ap, struct ata_device *dev)
+ {
+       if (ata_dev_present(dev)) {
+               printk(KERN_WARNING "ata%u: dev %u disabled\n",
+                      ap->id, dev->devno);
+               dev->class++;
+       }
+ }
  /**
   *    ata_pio_devchk - PATA device presence detection
   *    @ap: ATA channel to examine
@@@ -988,6 -1019,22 +1020,22 @@@ ata_exec_internal(struct ata_port *ap, 
  
        ata_qc_free(qc);
  
+       /* XXX - Some LLDDs (sata_mv) disable port on command failure.
+        * Until those drivers are fixed, we detect the condition
+        * here, fail the command with AC_ERR_SYSTEM and reenable the
+        * port.
+        *
+        * Note that this doesn't change any behavior as internal
+        * command failure results in disabling the device in the
+        * higher layer for LLDDs without new reset/EH callbacks.
+        *
+        * Kill the following code as soon as those drivers are fixed.
+        */
+       if (ap->flags & ATA_FLAG_PORT_DISABLED) {
+               err_mask |= AC_ERR_SYSTEM;
+               ata_port_probe(ap);
+       }
        return err_mask;
  }
  
@@@ -1008,7 -1055,7 +1056,7 @@@ unsigned int ata_pio_need_iordy(const s
                return 0;
        if (speed > 2)
                return 1;
-               
        /* If we have no drive specific rule, then PIO 2 is non IORDY */
  
        if (adev->id[ATA_ID_FIELD_VALID] & 2) { /* EIDE */
   *
   *    Read ID data from the specified device.  ATA_CMD_ID_ATA is
   *    performed on ATA devices and ATA_CMD_ID_ATAPI on ATAPI
-  *    devices.  This function also takes care of EDD signature
-  *    misreporting (to be removed once EDD support is gone) and
-  *    issues ATA_CMD_INIT_DEV_PARAMS for pre-ATA4 drives.
+  *    devices.  This function also issues ATA_CMD_INIT_DEV_PARAMS
+  *    for pre-ATA4 drives.
   *
   *    LOCKING:
   *    Kernel thread context (may sleep)
@@@ -1048,7 -1094,6 +1095,6 @@@ static int ata_dev_read_id(struct ata_p
                           unsigned int *p_class, int post_reset, u16 **p_id)
  {
        unsigned int class = *p_class;
-       unsigned int using_edd;
        struct ata_taskfile tf;
        unsigned int err_mask = 0;
        u16 *id;
  
        DPRINTK("ENTER, host %u, dev %u\n", ap->id, dev->devno);
  
-       if (ap->ops->probe_reset ||
-           ap->flags & (ATA_FLAG_SRST | ATA_FLAG_SATA_RESET))
-               using_edd = 0;
-       else
-               using_edd = 1;
        ata_dev_select(ap, dev->devno, 1, 1); /* select device 0/1 */
  
        id = kmalloc(sizeof(id[0]) * ATA_ID_WORDS, GFP_KERNEL);
  
        err_mask = ata_exec_internal(ap, dev, &tf, DMA_FROM_DEVICE,
                                     id, sizeof(id[0]) * ATA_ID_WORDS);
        if (err_mask) {
                rc = -EIO;
                reason = "I/O error";
-               if (err_mask & ~AC_ERR_DEV)
-                       goto err_out;
-               /*
-                * arg!  EDD works for all test cases, but seems to return
-                * the ATA signature for some ATAPI devices.  Until the
-                * reason for this is found and fixed, we fix up the mess
-                * here.  If IDENTIFY DEVICE returns command aborted
-                * (as ATAPI devices do), then we issue an
-                * IDENTIFY PACKET DEVICE.
-                *
-                * ATA software reset (SRST, the default) does not appear
-                * to have this problem.
-                */
-               if ((using_edd) && (class == ATA_DEV_ATA)) {
-                       u8 err = tf.feature;
-                       if (err & ATA_ABORTED) {
-                               class = ATA_DEV_ATAPI;
-                               goto retry;
-                       }
-               }
                goto err_out;
        }
  
@@@ -1276,12 -1292,7 +1293,12 @@@ static int ata_dev_configure(struct ata
                                       dev->cylinders, dev->heads, dev->sectors);
                }
  
 -              dev->cdb_len = 16;
 +              if (dev->id[59] & 0x100) {
 +                      dev->multi_count = dev->id[59] & 0xff;
 +                      DPRINTK("ata%u: dev %u multi count %u\n",
 +                              ap->id, device, dev->multi_count);
 +              }
 +
        }
  
        /* ATAPI-specific feature tests */
                }
                dev->cdb_len = (unsigned int) rc;
  
 +              if (ata_id_cdb_intr(dev->id))
 +                      dev->flags |= ATA_DFLAG_CDB_INTR;
 +
                /* print device info to dmesg */
                if (print_info)
                        printk(KERN_INFO "ata%u: dev %u ATAPI, max %s\n",
                if (print_info)
                        printk(KERN_INFO "ata%u(%u): applying bridge limits\n",
                               ap->id, dev->devno);
-               ap->udma_mask &= ATA_UDMA5;
+               dev->udma_mask &= ATA_UDMA5;
                dev->max_sectors = ATA_MAX_SECTORS;
        }
  
        return 0;
  
  err_out_nosup:
-       printk(KERN_WARNING "ata%u: dev %u not supported, ignoring\n",
-              ap->id, dev->devno);
        DPRINTK("EXIT, err\n");
        return rc;
  }
@@@ -1393,7 -1399,7 +1408,7 @@@ static int ata_bus_probe(struct ata_por
                }
  
                if (ata_dev_configure(ap, dev, 1)) {
-                       dev->class++;   /* disable device */
+                       ata_dev_disable(ap, dev);
                        continue;
                }
  
@@@ -1538,6 -1544,23 +1553,23 @@@ void sata_phy_reset(struct ata_port *ap
        ata_bus_reset(ap);
  }
  
+ /**
+  *    ata_dev_pair            -       return other device on cable
+  *    @ap: port
+  *    @adev: device
+  *
+  *    Obtain the other device on the same cable, or if none is
+  *    present NULL is returned
+  */
+ struct ata_device *ata_dev_pair(struct ata_port *ap, struct ata_device *adev)
+ {
+       struct ata_device *pair = &ap->device[1 - adev->devno];
+       if (!ata_dev_present(pair))
+               return NULL;
+       return pair;
+ }
  /**
   *    ata_port_disable - Disable port.
   *    @ap: Port to be disabled.
@@@ -1566,7 -1589,7 +1598,7 @@@ void ata_port_disable(struct ata_port *
   * PIO 0-5, MWDMA 0-2 and UDMA 0-6 timings (in nanoseconds).
   * These were taken from ATA/ATAPI-6 standard, rev 0a, except
   * for PIO 5, which is a nonstandard extension and UDMA6, which
-  * is currently supported only by Maxtor drives. 
+  * is currently supported only by Maxtor drives.
   */
  
  static const struct ata_timing ata_timing[] = {
        { XFER_UDMA_0,     0,   0,   0,   0,   0,   0,   0, 120 },
  
  /*    { XFER_UDMA_SLOW,  0,   0,   0,   0,   0,   0,   0, 150 }, */
-                                           
        { XFER_MW_DMA_2,  25,   0,   0,   0,  70,  25, 120,   0 },
        { XFER_MW_DMA_1,  45,   0,   0,   0,  80,  50, 150,   0 },
        { XFER_MW_DMA_0,  60,   0,   0,   0, 215, 215, 480,   0 },
-                                           
        { XFER_SW_DMA_2,  60,   0,   0,   0, 120, 120, 240,   0 },
        { XFER_SW_DMA_1,  90,   0,   0,   0, 240, 240, 480,   0 },
        { XFER_SW_DMA_0, 120,   0,   0,   0, 480, 480, 960,   0 },
@@@ -1638,7 -1661,7 +1670,7 @@@ static const struct ata_timing* ata_tim
        for (t = ata_timing; t->mode != speed; t++)
                if (t->mode == 0xFF)
                        return NULL;
-       return t; 
+       return t;
  }
  
  int ata_timing_compute(struct ata_device *adev, unsigned short speed,
        struct ata_timing p;
  
        /*
-        * Find the mode. 
+        * Find the mode.
         */
  
        if (!(s = ata_timing_find_mode(speed)))
        return 0;
  }
  
- static void ata_dev_set_mode(struct ata_port *ap, struct ata_device *dev)
+ static int ata_dev_set_mode(struct ata_port *ap, struct ata_device *dev)
  {
-       if (!ata_dev_present(dev) || (ap->flags & ATA_FLAG_PORT_DISABLED))
-               return;
+       unsigned int err_mask;
+       int rc;
  
        if (dev->xfer_shift == ATA_SHIFT_PIO)
                dev->flags |= ATA_DFLAG_PIO;
  
-       ata_dev_set_xfermode(ap, dev);
+       err_mask = ata_dev_set_xfermode(ap, dev);
+       if (err_mask) {
+               printk(KERN_ERR
+                      "ata%u: failed to set xfermode (err_mask=0x%x)\n",
+                      ap->id, err_mask);
+               return -EIO;
+       }
  
-       if (ata_dev_revalidate(ap, dev, 0)) {
-               printk(KERN_ERR "ata%u: failed to revalidate after set "
-                      "xfermode, disabled\n", ap->id);
-               ata_port_disable(ap);
+       rc = ata_dev_revalidate(ap, dev, 0);
+       if (rc) {
+               printk(KERN_ERR
+                      "ata%u: failed to revalidate after set xfermode\n",
+                      ap->id);
+               return rc;
        }
  
        DPRINTK("xfer_shift=%u, xfer_mode=0x%x\n",
        printk(KERN_INFO "ata%u: dev %u configured for %s\n",
               ap->id, dev->devno,
               ata_mode_string(ata_xfer_mode2mask(dev->xfer_mode)));
+       return 0;
  }
  
  static int ata_host_set_pio(struct ata_port *ap)
@@@ -1787,16 -1819,19 +1828,19 @@@ static void ata_set_mode(struct ata_por
        /* step 1: calculate xfer_mask */
        for (i = 0; i < ATA_MAX_DEVICES; i++) {
                struct ata_device *dev = &ap->device[i];
-               unsigned int xfer_mask;
+               unsigned int pio_mask, dma_mask;
  
                if (!ata_dev_present(dev))
                        continue;
  
-               xfer_mask = ata_dev_xfermask(ap, dev);
+               ata_dev_xfermask(ap, dev);
+               /* TODO: let LLDD filter dev->*_mask here */
  
-               dev->pio_mode = ata_xfer_mask2mode(xfer_mask & ATA_MASK_PIO);
-               dev->dma_mode = ata_xfer_mask2mode(xfer_mask & (ATA_MASK_MWDMA |
-                                                               ATA_MASK_UDMA));
+               pio_mask = ata_pack_xfermask(dev->pio_mask, 0, 0);
+               dma_mask = ata_pack_xfermask(0, dev->mwdma_mask, dev->udma_mask);
+               dev->pio_mode = ata_xfer_mask2mode(pio_mask);
+               dev->dma_mode = ata_xfer_mask2mode(dma_mask);
        }
  
        /* step 2: always set host PIO timings */
        ata_host_set_dma(ap);
  
        /* step 4: update devices' xfer mode */
-       for (i = 0; i < ATA_MAX_DEVICES; i++)
-               ata_dev_set_mode(ap, &ap->device[i]);
+       for (i = 0; i < ATA_MAX_DEVICES; i++) {
+               struct ata_device *dev = &ap->device[i];
  
-       if (ap->flags & ATA_FLAG_PORT_DISABLED)
-               return;
+               if (!ata_dev_present(dev))
+                       continue;
+               if (ata_dev_set_mode(ap, dev))
+                       goto err_out;
+       }
  
        if (ap->ops->post_set_mode)
                ap->ops->post_set_mode(ap);
@@@ -1935,45 -1974,6 +1983,6 @@@ static void ata_bus_post_reset(struct a
                ap->ops->dev_select(ap, 0);
  }
  
- /**
-  *    ata_bus_edd - Issue EXECUTE DEVICE DIAGNOSTIC command.
-  *    @ap: Port to reset and probe
-  *
-  *    Use the EXECUTE DEVICE DIAGNOSTIC command to reset and
-  *    probe the bus.  Not often used these days.
-  *
-  *    LOCKING:
-  *    PCI/etc. bus probe sem.
-  *    Obtains host_set lock.
-  *
-  */
- static unsigned int ata_bus_edd(struct ata_port *ap)
- {
-       struct ata_taskfile tf;
-       unsigned long flags;
-       /* set up execute-device-diag (bus reset) taskfile */
-       /* also, take interrupts to a known state (disabled) */
-       DPRINTK("execute-device-diag\n");
-       ata_tf_init(ap, &tf, 0);
-       tf.ctl |= ATA_NIEN;
-       tf.command = ATA_CMD_EDD;
-       tf.protocol = ATA_PROT_NODATA;
-       /* do bus reset */
-       spin_lock_irqsave(&ap->host_set->lock, flags);
-       ata_tf_to_host(ap, &tf);
-       spin_unlock_irqrestore(&ap->host_set->lock, flags);
-       /* spec says at least 2ms.  but who knows with those
-        * crazy ATAPI devices...
-        */
-       msleep(150);
-       return ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT);
- }
  static unsigned int ata_bus_softreset(struct ata_port *ap,
                                      unsigned int devmask)
  {
         */
        msleep(150);
  
-       
-       /* Before we perform post reset processing we want to see if 
+       /* Before we perform post reset processing we want to see if
           the bus shows 0xFF because the odd clown forgets the D7 pulldown
           resistor */
-       
        if (ata_check_status(ap) == 0xFF)
                return 1;       /* Positive is failure for some reason */
  
@@@ -2046,7 -2046,7 +2055,7 @@@ void ata_bus_reset(struct ata_port *ap
        struct ata_ioports *ioaddr = &ap->ioaddr;
        unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS;
        u8 err;
-       unsigned int dev0, dev1 = 0, rc = 0, devmask = 0;
+       unsigned int dev0, dev1 = 0, devmask = 0;
  
        DPRINTK("ENTER, host %u, port %u\n", ap->id, ap->port_no);
  
  
        /* issue bus reset */
        if (ap->flags & ATA_FLAG_SRST)
-               rc = ata_bus_softreset(ap, devmask);
-       else if ((ap->flags & ATA_FLAG_SATA_RESET) == 0) {
-               /* set up device control */
-               if (ap->flags & ATA_FLAG_MMIO)
-                       writeb(ap->ctl, (void __iomem *) ioaddr->ctl_addr);
-               else
-                       outb(ap->ctl, ioaddr->ctl_addr);
-               rc = ata_bus_edd(ap);
-       }
-       if (rc)
-               goto err_out;
+               if (ata_bus_softreset(ap, devmask))
+                       goto err_out;
  
        /*
         * determine by signature whether we have ATA or ATAPI devices
@@@ -2581,22 -2571,22 +2580,22 @@@ static const char * const ata_dma_black
        "SanDisk SDP3B-64", NULL,
        "SANYO CD-ROM CRD", NULL,
        "HITACHI CDR-8", NULL,
-       "HITACHI CDR-8335", NULL, 
+       "HITACHI CDR-8335", NULL,
        "HITACHI CDR-8435", NULL,
-       "Toshiba CD-ROM XM-6202B", NULL, 
-       "TOSHIBA CD-ROM XM-1702BC", NULL, 
-       "CD-532E-A", NULL, 
-       "E-IDE CD-ROM CR-840", NULL, 
-       "CD-ROM Drive/F5A", NULL, 
-       "WPI CDD-820", NULL, 
+       "Toshiba CD-ROM XM-6202B", NULL,
+       "TOSHIBA CD-ROM XM-1702BC", NULL,
+       "CD-532E-A", NULL,
+       "E-IDE CD-ROM CR-840", NULL,
+       "CD-ROM Drive/F5A", NULL,
+       "WPI CDD-820", NULL,
        "SAMSUNG CD-ROM SC-148C", NULL,
-       "SAMSUNG CD-ROM SC", NULL, 
+       "SAMSUNG CD-ROM SC", NULL,
        "SanDisk SDP3B-64", NULL,
        "ATAPI CD-ROM DRIVE 40X MAXIMUM",NULL,
        "_NEC DV5800A", NULL,
        "SAMSUNG CD-ROM SN-124", "N001"
  };
-  
  static int ata_strim(char *s, size_t len)
  {
        len = strnlen(s, len);
@@@ -2639,18 -2629,15 +2638,15 @@@ static int ata_dma_blacklisted(const st
   *    @ap: Port on which the device to compute xfermask for resides
   *    @dev: Device to compute xfermask for
   *
-  *    Compute supported xfermask of @dev.  This function is
-  *    responsible for applying all known limits including host
-  *    controller limits, device blacklist, etc...
+  *    Compute supported xfermask of @dev and store it in
+  *    dev->*_mask.  This function is responsible for applying all
+  *    known limits including host controller limits, device
+  *    blacklist, etc...
   *
   *    LOCKING:
   *    None.
-  *
-  *    RETURNS:
-  *    Computed xfermask.
   */
- static unsigned int ata_dev_xfermask(struct ata_port *ap,
-                                    struct ata_device *dev)
+ static void ata_dev_xfermask(struct ata_port *ap, struct ata_device *dev)
  {
        unsigned long xfer_mask;
        int i;
                struct ata_device *d = &ap->device[i];
                if (!ata_dev_present(d))
                        continue;
+               xfer_mask &= ata_pack_xfermask(d->pio_mask, d->mwdma_mask,
+                                              d->udma_mask);
                xfer_mask &= ata_id_xfermask(d->id);
                if (ata_dma_blacklisted(d))
                        xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA);
                printk(KERN_WARNING "ata%u: dev %u is on DMA blacklist, "
                       "disabling DMA\n", ap->id, dev->devno);
  
-       return xfer_mask;
+       ata_unpack_xfermask(xfer_mask, &dev->pio_mask, &dev->mwdma_mask,
+                           &dev->udma_mask);
  }
  
  /**
   *
   *    LOCKING:
   *    PCI/etc. bus probe sem.
+  *
+  *    RETURNS:
+  *    0 on success, AC_ERR_* mask otherwise.
   */
  
- static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev)
+ static unsigned int ata_dev_set_xfermode(struct ata_port *ap,
+                                        struct ata_device *dev)
  {
        struct ata_taskfile tf;
+       unsigned int err_mask;
  
        /* set up set-features taskfile */
        DPRINTK("set features - xfer mode\n");
        tf.protocol = ATA_PROT_NODATA;
        tf.nsect = dev->xfer_mode;
  
-       if (ata_exec_internal(ap, dev, &tf, DMA_NONE, NULL, 0)) {
-               printk(KERN_ERR "ata%u: failed to set xfermode, disabled\n",
-                      ap->id);
-               ata_port_disable(ap);
-       }
+       err_mask = ata_exec_internal(ap, dev, &tf, DMA_NONE, NULL, 0);
  
-       DPRINTK("EXIT\n");
+       DPRINTK("EXIT, err_mask=%x\n", err_mask);
+       return err_mask;
  }
  
  /**
@@@ -2784,7 -2776,7 +2785,7 @@@ static void ata_sg_clean(struct ata_que
  
        if (qc->flags & ATA_QCFLAG_SG) {
                if (qc->n_elem)
-                       dma_unmap_sg(ap->host_set->dev, sg, qc->n_elem, dir);
+                       dma_unmap_sg(ap->dev, sg, qc->n_elem, dir);
                /* restore last sg */
                sg[qc->orig_n_elem - 1].length += qc->pad_len;
                if (pad_buf) {
                }
        } else {
                if (qc->n_elem)
-                       dma_unmap_single(ap->host_set->dev,
+                       dma_unmap_single(ap->dev,
                                sg_dma_address(&sg[0]), sg_dma_len(&sg[0]),
                                dir);
                /* restore sg */
@@@ -3006,7 -2998,7 +3007,7 @@@ static int ata_sg_setup_one(struct ata_
                goto skip_map;
        }
  
-       dma_address = dma_map_single(ap->host_set->dev, qc->buf_virt,
+       dma_address = dma_map_single(ap->dev, qc->buf_virt,
                                     sg->length, dir);
        if (dma_mapping_error(dma_address)) {
                /* restore sg */
@@@ -3094,7 -3086,7 +3095,7 @@@ static int ata_sg_setup(struct ata_queu
        }
  
        dir = qc->dma_dir;
-       n_elem = dma_map_sg(ap->host_set->dev, sg, pre_n_elem, dir);
+       n_elem = dma_map_sg(ap->dev, sg, pre_n_elem, dir);
        if (n_elem < 1) {
                /* restore last sg */
                lsg->length += qc->pad_len;
@@@ -3124,6 -3116,7 +3125,6 @@@ void ata_poll_qc_complete(struct ata_qu
        unsigned long flags;
  
        spin_lock_irqsave(&ap->host_set->lock, flags);
 -      ap->flags &= ~ATA_FLAG_NOINTR;
        ata_irq_on(ap);
        ata_qc_complete(qc);
        spin_unlock_irqrestore(&ap->host_set->lock, flags);
@@@ -3189,8 -3182,7 +3190,8 @@@ static unsigned long ata_pio_poll(struc
   *    None.  (executing in kernel thread context)
   *
   *    RETURNS:
 - *    Non-zero if qc completed, zero otherwise.
 + *    Zero if qc completed.
 + *    Non-zero if has next.
   */
  
  static int ata_pio_complete (struct ata_port *ap)
         * we enter, BSY will be cleared in a chk-status or two.  If not,
         * the drive is probably seeking or something.  Snooze for a couple
         * msecs, then chk-status again.  If still busy, fall back to
 -       * HSM_ST_POLL state.
 +       * HSM_ST_LAST_POLL state.
         */
        drv_stat = ata_busy_wait(ap, ATA_BUSY, 10);
        if (drv_stat & ATA_BUSY) {
                if (drv_stat & ATA_BUSY) {
                        ap->hsm_task_state = HSM_ST_LAST_POLL;
                        ap->pio_task_timeout = jiffies + ATA_TMOUT_PIO;
 -                      return 0;
 +                      return 1;
                }
        }
  
        if (!ata_ok(drv_stat)) {
                qc->err_mask |= __ac_err_mask(drv_stat);
                ap->hsm_task_state = HSM_ST_ERR;
 -              return 0;
 +              return 1;
        }
  
        ap->hsm_task_state = HSM_ST_IDLE;
  
        /* another command may start at this point */
  
 -      return 1;
 +      return 0;
  }
  
  
@@@ -3405,23 -3397,7 +3406,23 @@@ static void ata_pio_sector(struct ata_q
        page = nth_page(page, (offset >> PAGE_SHIFT));
        offset %= PAGE_SIZE;
  
 -      buf = kmap(page) + offset;
 +      DPRINTK("data %s\n", qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read");
 +
 +      if (PageHighMem(page)) {
 +              unsigned long flags;
 +
 +              local_irq_save(flags);
 +              buf = kmap_atomic(page, KM_IRQ0);
 +
 +              /* do the actual data transfer */
 +              ata_data_xfer(ap, buf + offset, ATA_SECT_SIZE, do_write);
 +
 +              kunmap_atomic(buf, KM_IRQ0);
 +              local_irq_restore(flags);
 +      } else {
 +              buf = page_address(page);
 +              ata_data_xfer(ap, buf + offset, ATA_SECT_SIZE, do_write);
 +      }
  
        qc->cursect++;
        qc->cursg_ofs++;
                qc->cursg++;
                qc->cursg_ofs = 0;
        }
 +}
  
 -      DPRINTK("data %s\n", qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read");
 +/**
 + *    ata_pio_sectors - Transfer one or many 512-byte sectors.
 + *    @qc: Command on going
 + *
 + *    Transfer one or many ATA_SECT_SIZE of data from/to the 
 + *    ATA device for the DRQ request.
 + *
 + *    LOCKING:
 + *    Inherited from caller.
 + */
 +
 +static void ata_pio_sectors(struct ata_queued_cmd *qc)
 +{
 +      if (is_multi_taskfile(&qc->tf)) {
 +              /* READ/WRITE MULTIPLE */
 +              unsigned int nsect;
  
 -      /* do the actual data transfer */
 -      do_write = (qc->tf.flags & ATA_TFLAG_WRITE);
 -      ata_data_xfer(ap, buf, ATA_SECT_SIZE, do_write);
 +              WARN_ON(qc->dev->multi_count == 0);
  
 -      kunmap(page);
 +              nsect = min(qc->nsect - qc->cursect, qc->dev->multi_count);
 +              while (nsect--)
 +                      ata_pio_sector(qc);
 +      } else
 +              ata_pio_sector(qc);
 +}
 +
 +/**
 + *    atapi_send_cdb - Write CDB bytes to hardware
 + *    @ap: Port to which ATAPI device is attached.
 + *    @qc: Taskfile currently active
 + *
 + *    When device has indicated its readiness to accept
 + *    a CDB, this function is called.  Send the CDB.
 + *
 + *    LOCKING:
 + *    caller.
 + */
 +
 +static void atapi_send_cdb(struct ata_port *ap, struct ata_queued_cmd *qc)
 +{
 +      /* send SCSI cdb */
 +      DPRINTK("send cdb\n");
 +      WARN_ON(qc->dev->cdb_len < 12);
 +
 +      ata_data_xfer(ap, qc->cdb, qc->dev->cdb_len, 1);
 +      ata_altstatus(ap); /* flush */
 +
 +      switch (qc->tf.protocol) {
 +      case ATA_PROT_ATAPI:
 +              ap->hsm_task_state = HSM_ST;
 +              break;
 +      case ATA_PROT_ATAPI_NODATA:
 +              ap->hsm_task_state = HSM_ST_LAST;
 +              break;
 +      case ATA_PROT_ATAPI_DMA:
 +              ap->hsm_task_state = HSM_ST_LAST;
 +              /* initiate bmdma */
 +              ap->ops->bmdma_start(qc);
 +              break;
 +      }
 +}
 +
 +/**
 + *    ata_pio_first_block - Write first data block to hardware
 + *    @ap: Port to which ATA/ATAPI device is attached.
 + *
 + *    When device has indicated its readiness to accept
 + *    the data, this function sends out the CDB or 
 + *    the first data block by PIO.
 + *    After this, 
 + *      - If polling, ata_pio_task() handles the rest.
 + *      - Otherwise, interrupt handler takes over.
 + *
 + *    LOCKING:
 + *    Kernel thread context (may sleep)
 + *
 + *    RETURNS:
 + *    Zero if irq handler takes over
 + *    Non-zero if has next (polling).
 + */
 +
 +static int ata_pio_first_block(struct ata_port *ap)
 +{
 +      struct ata_queued_cmd *qc;
 +      u8 status;
 +      unsigned long flags;
 +      int has_next;
 +
 +      qc = ata_qc_from_tag(ap, ap->active_tag);
 +      WARN_ON(qc == NULL);
 +      WARN_ON((qc->flags & ATA_QCFLAG_ACTIVE) == 0);
 +
 +      /* if polling, we will stay in the work queue after sending the data.
 +       * otherwise, interrupt handler takes over after sending the data.
 +       */
 +      has_next = (qc->tf.flags & ATA_TFLAG_POLLING);
 +
 +      /* sleep-wait for BSY to clear */
 +      DPRINTK("busy wait\n");
 +      if (ata_busy_sleep(ap, ATA_TMOUT_DATAOUT_QUICK, ATA_TMOUT_DATAOUT)) {
 +              qc->err_mask |= AC_ERR_TIMEOUT;
 +              ap->hsm_task_state = HSM_ST_TMOUT;
 +              goto err_out;
 +      }
 +
 +      /* make sure DRQ is set */
 +      status = ata_chk_status(ap);
 +      if ((status & (ATA_BUSY | ATA_DRQ)) != ATA_DRQ) {
 +              /* device status error */
 +              qc->err_mask |= AC_ERR_HSM;
 +              ap->hsm_task_state = HSM_ST_ERR;
 +              goto err_out;
 +      }
 +
 +      /* Send the CDB (atapi) or the first data block (ata pio out).
 +       * During the state transition, interrupt handler shouldn't
 +       * be invoked before the data transfer is complete and
 +       * hsm_task_state is changed. Hence, the following locking.
 +       */
 +      spin_lock_irqsave(&ap->host_set->lock, flags);
 +
 +      if (qc->tf.protocol == ATA_PROT_PIO) {
 +              /* PIO data out protocol.
 +               * send first data block.
 +               */
 +
 +              /* ata_pio_sectors() might change the state to HSM_ST_LAST.
 +               * so, the state is changed here before ata_pio_sectors().
 +               */
 +              ap->hsm_task_state = HSM_ST;
 +              ata_pio_sectors(qc);
 +              ata_altstatus(ap); /* flush */
 +      } else
 +              /* send CDB */
 +              atapi_send_cdb(ap, qc);
 +
 +      spin_unlock_irqrestore(&ap->host_set->lock, flags);
 +
 +      /* if polling, ata_pio_task() handles the rest.
 +       * otherwise, interrupt handler takes over from here.
 +       */
 +      return has_next;
 +
 +err_out:
 +      return 1; /* has next */
  }
  
  /**
@@@ -3642,23 -3479,7 +3643,23 @@@ next_sg
        /* don't cross page boundaries */
        count = min(count, (unsigned int)PAGE_SIZE - offset);
  
 -      buf = kmap(page) + offset;
 +      DPRINTK("data %s\n", qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read");
 +
 +      if (PageHighMem(page)) {
 +              unsigned long flags;
 +
 +              local_irq_save(flags);
 +              buf = kmap_atomic(page, KM_IRQ0);
 +
 +              /* do the actual data transfer */
 +              ata_data_xfer(ap, buf + offset, count, do_write);
 +
 +              kunmap_atomic(buf, KM_IRQ0);
 +              local_irq_restore(flags);
 +      } else {
 +              buf = page_address(page);
 +              ata_data_xfer(ap, buf + offset, count, do_write);
 +      }
  
        bytes -= count;
        qc->curbytes += count;
                qc->cursg_ofs = 0;
        }
  
 -      DPRINTK("data %s\n", qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read");
 -
 -      /* do the actual data transfer */
 -      ata_data_xfer(ap, buf, count, do_write);
 -
 -      kunmap(page);
 -
        if (bytes)
                goto next_sg;
  }
@@@ -3705,8 -3533,6 +3706,8 @@@ static void atapi_pio_bytes(struct ata_
        if (do_write != i_write)
                goto err_out;
  
 +      VPRINTK("ata%u: xfering %d bytes\n", ap->id, bytes);
 +
        __atapi_pio_bytes(qc, bytes);
  
        return;
@@@ -3777,10 -3603,8 +3778,10 @@@ static void ata_pio_block(struct ata_po
                        return;
                }
  
 -              ata_pio_sector(qc);
 +              ata_pio_sectors(qc);
        }
 +
 +      ata_altstatus(ap); /* flush */
  }
  
  static void ata_pio_error(struct ata_port *ap)
        if (qc->tf.command != ATA_CMD_PACKET)
                printk(KERN_WARNING "ata%u: PIO error\n", ap->id);
  
-       /* make sure qc->err_mask is available to 
+       /* make sure qc->err_mask is available to
         * know what's wrong and recover
         */
        WARN_ON(qc->err_mask == 0);
@@@ -3807,23 -3631,22 +3808,23 @@@ static void ata_pio_task(void *_data
  {
        struct ata_port *ap = _data;
        unsigned long timeout;
 -      int qc_completed;
 +      int has_next;
  
  fsm_start:
        timeout = 0;
 -      qc_completed = 0;
 +      has_next = 1;
  
        switch (ap->hsm_task_state) {
 -      case HSM_ST_IDLE:
 -              return;
 +      case HSM_ST_FIRST:
 +              has_next = ata_pio_first_block(ap);
 +              break;
  
        case HSM_ST:
                ata_pio_block(ap);
                break;
  
        case HSM_ST_LAST:
 -              qc_completed = ata_pio_complete(ap);
 +              has_next = ata_pio_complete(ap);
                break;
  
        case HSM_ST_POLL:
        case HSM_ST_ERR:
                ata_pio_error(ap);
                return;
 +
 +      default:
 +              BUG();
 +              return;
        }
  
        if (timeout)
                ata_port_queue_task(ap, ata_pio_task, ap, timeout);
 -      else if (!qc_completed)
 +      else if (has_next)
                goto fsm_start;
  }
  
@@@ -3900,8 -3719,7 +3901,8 @@@ static void atapi_packet_task(void *_da
                 * finished.  Hence, the following locking.
                 */
                spin_lock_irqsave(&ap->host_set->lock, flags);
 -              ap->flags &= ~ATA_FLAG_NOINTR;
 +#warning FIXME
 +              /* ap->flags &= ~ATA_FLAG_NOINTR; */
                ata_data_xfer(ap, qc->cdb, qc->dev->cdb_len, 1);
                if (qc->tf.protocol == ATA_PROT_ATAPI_DMA)
                        ap->ops->bmdma_start(qc);       /* initiate bmdma */
@@@ -3973,10 -3791,8 +3974,10 @@@ static void ata_qc_timeout(struct ata_q
                printk(KERN_ERR "ata%u: command 0x%x timeout, stat 0x%x host_stat 0x%x\n",
                       ap->id, qc->tf.command, drv_stat, host_stat);
  
 +              ap->hsm_task_state = HSM_ST_IDLE;
 +
                /* complete taskfile transaction */
 -              qc->err_mask |= ac_err_mask(drv_stat);
 +              qc->err_mask |= AC_ERR_TIMEOUT;
                break;
        }
  
@@@ -4202,104 -4018,43 +4203,104 @@@ unsigned int ata_qc_issue_prot(struct a
  {
        struct ata_port *ap = qc->ap;
  
 +      /* Use polling pio if the LLD doesn't handle
 +       * interrupt driven pio and atapi CDB interrupt.
 +       */
 +      if (ap->flags & ATA_FLAG_PIO_POLLING) {
 +              switch (qc->tf.protocol) {
 +              case ATA_PROT_PIO:
 +              case ATA_PROT_ATAPI:
 +              case ATA_PROT_ATAPI_NODATA:
 +                      qc->tf.flags |= ATA_TFLAG_POLLING;
 +                      break;
 +              case ATA_PROT_ATAPI_DMA:
 +                      if (qc->dev->flags & ATA_DFLAG_CDB_INTR)
 +                              BUG();
 +                      break;
 +              default:
 +                      break;
 +              }
 +      }
 +
 +      /* select the device */
        ata_dev_select(ap, qc->dev->devno, 1, 0);
  
 +      /* start the command */
        switch (qc->tf.protocol) {
        case ATA_PROT_NODATA:
 +              if (qc->tf.flags & ATA_TFLAG_POLLING)
 +                      ata_qc_set_polling(qc);
 +
                ata_tf_to_host(ap, &qc->tf);
 +              ap->hsm_task_state = HSM_ST_LAST;
 +
 +              if (qc->tf.flags & ATA_TFLAG_POLLING)
 +                      ata_port_queue_task(ap, ata_pio_task, ap, 0);
 +
                break;
  
        case ATA_PROT_DMA:
 +              WARN_ON(qc->tf.flags & ATA_TFLAG_POLLING);
 +
                ap->ops->tf_load(ap, &qc->tf);   /* load tf registers */
                ap->ops->bmdma_setup(qc);           /* set up bmdma */
                ap->ops->bmdma_start(qc);           /* initiate bmdma */
 +              ap->hsm_task_state = HSM_ST_LAST;
                break;
  
 -      case ATA_PROT_PIO: /* load tf registers, initiate polling pio */
 -              ata_qc_set_polling(qc);
 -              ata_tf_to_host(ap, &qc->tf);
 -              ap->hsm_task_state = HSM_ST;
 -              ata_port_queue_task(ap, ata_pio_task, ap, 0);
 -              break;
 +      case ATA_PROT_PIO:
 +              if (qc->tf.flags & ATA_TFLAG_POLLING)
 +                      ata_qc_set_polling(qc);
  
 -      case ATA_PROT_ATAPI:
 -              ata_qc_set_polling(qc);
                ata_tf_to_host(ap, &qc->tf);
 -              ata_port_queue_task(ap, atapi_packet_task, ap, 0);
 +
 +              if (qc->tf.flags & ATA_TFLAG_WRITE) {
 +                      /* PIO data out protocol */
 +                      ap->hsm_task_state = HSM_ST_FIRST;
 +                      ata_port_queue_task(ap, ata_pio_task, ap, 0);
 +
 +                      /* always send first data block using
 +                       * the ata_pio_task() codepath.
 +                       */
 +              } else {
 +                      /* PIO data in protocol */
 +                      ap->hsm_task_state = HSM_ST;
 +
 +                      if (qc->tf.flags & ATA_TFLAG_POLLING)
 +                              ata_port_queue_task(ap, ata_pio_task, ap, 0);
 +
 +                      /* if polling, ata_pio_task() handles the rest.
 +                       * otherwise, interrupt handler takes over from here.
 +                       */
 +              }
 +
                break;
  
 +      case ATA_PROT_ATAPI:
        case ATA_PROT_ATAPI_NODATA:
 -              ap->flags |= ATA_FLAG_NOINTR;
 +              if (qc->tf.flags & ATA_TFLAG_POLLING)
 +                      ata_qc_set_polling(qc);
 +
                ata_tf_to_host(ap, &qc->tf);
 -              ata_port_queue_task(ap, atapi_packet_task, ap, 0);
 +
 +              ap->hsm_task_state = HSM_ST_FIRST;
 +
 +              /* send cdb by polling if no cdb interrupt */
 +              if ((!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) ||
 +                  (qc->tf.flags & ATA_TFLAG_POLLING))
 +                      ata_port_queue_task(ap, atapi_packet_task, ap, 0);
                break;
  
        case ATA_PROT_ATAPI_DMA:
 -              ap->flags |= ATA_FLAG_NOINTR;
 +              WARN_ON(qc->tf.flags & ATA_TFLAG_POLLING);
 +
                ap->ops->tf_load(ap, &qc->tf);   /* load tf registers */
                ap->ops->bmdma_setup(qc);           /* set up bmdma */
 -              ata_port_queue_task(ap, atapi_packet_task, ap, 0);
 +              ap->hsm_task_state = HSM_ST_FIRST;
 +
 +              /* send cdb by polling if no cdb interrupt */
 +              if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR))
 +                      ata_port_queue_task(ap, atapi_packet_task, ap, 0);
                break;
  
        default:
  inline unsigned int ata_host_intr (struct ata_port *ap,
                                   struct ata_queued_cmd *qc)
  {
 -      u8 status, host_stat;
 -
 -      switch (qc->tf.protocol) {
 +      u8 status, host_stat = 0;
  
 -      case ATA_PROT_DMA:
 -      case ATA_PROT_ATAPI_DMA:
 -      case ATA_PROT_ATAPI:
 -              /* check status of DMA engine */
 -              host_stat = ap->ops->bmdma_status(ap);
 -              VPRINTK("ata%u: host_stat 0x%X\n", ap->id, host_stat);
 +      VPRINTK("ata%u: protocol %d task_state %d\n",
 +              ap->id, qc->tf.protocol, ap->hsm_task_state);
  
 -              /* if it's not our irq... */
 -              if (!(host_stat & ATA_DMA_INTR))
 +      /* Check whether we are expecting interrupt in this state */
 +      switch (ap->hsm_task_state) {
 +      case HSM_ST_FIRST:
 +              /* Check the ATA_DFLAG_CDB_INTR flag is enough here.
 +               * The flag was turned on only for atapi devices.
 +               * No need to check is_atapi_taskfile(&qc->tf) again.
 +               */
 +              if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR))
                        goto idle_irq;
 +              break;
 +      case HSM_ST_LAST:
 +              if (qc->tf.protocol == ATA_PROT_DMA ||
 +                  qc->tf.protocol == ATA_PROT_ATAPI_DMA) {
 +                      /* check status of DMA engine */
 +                      host_stat = ap->ops->bmdma_status(ap);
 +                      VPRINTK("ata%u: host_stat 0x%X\n", ap->id, host_stat);
 +
 +                      /* if it's not our irq... */
 +                      if (!(host_stat & ATA_DMA_INTR))
 +                              goto idle_irq;
 +
 +                      /* before we do anything else, clear DMA-Start bit */
 +                      ap->ops->bmdma_stop(qc);
 +
 +                      if (unlikely(host_stat & ATA_DMA_ERR)) {
 +                              /* error when transfering data to/from memory */
 +                              qc->err_mask |= AC_ERR_HOST_BUS;
 +                              ap->hsm_task_state = HSM_ST_ERR;
 +                      }
 +              }
 +              break;
 +      case HSM_ST:
 +              break;
 +      default:
 +              goto idle_irq;
 +      }
  
 -              /* before we do anything else, clear DMA-Start bit */
 -              ap->ops->bmdma_stop(qc);
 +      /* check altstatus */
 +      status = ata_altstatus(ap);
 +      if (status & ATA_BUSY)
 +              goto idle_irq;
  
 -              /* fall through */
 +      /* check main status, clearing INTRQ */
 +      status = ata_chk_status(ap);
 +      if (unlikely(status & ATA_BUSY))
 +              goto idle_irq;
  
 -      case ATA_PROT_ATAPI_NODATA:
 -      case ATA_PROT_NODATA:
 -              /* check altstatus */
 -              status = ata_altstatus(ap);
 -              if (status & ATA_BUSY)
 -                      goto idle_irq;
 +      DPRINTK("ata%u: protocol %d task_state %d (dev_stat 0x%X)\n",
 +              ap->id, qc->tf.protocol, ap->hsm_task_state, status);
  
 -              /* check main status, clearing INTRQ */
 -              status = ata_chk_status(ap);
 -              if (unlikely(status & ATA_BUSY))
 -                      goto idle_irq;
 -              DPRINTK("ata%u: protocol %d (dev_stat 0x%X)\n",
 -                      ap->id, qc->tf.protocol, status);
 +      /* ack bmdma irq events */
 +      ap->ops->irq_clear(ap);
  
 -              /* ack bmdma irq events */
 -              ap->ops->irq_clear(ap);
 +      /* check error */
 +      if (unlikely(status & (ATA_ERR | ATA_DF))) {
 +              qc->err_mask |= AC_ERR_DEV;
 +              ap->hsm_task_state = HSM_ST_ERR;
 +      }
 +
 +fsm_start:
 +      switch (ap->hsm_task_state) {
 +      case HSM_ST_FIRST:
 +              /* Some pre-ATAPI-4 devices assert INTRQ 
 +               * at this state when ready to receive CDB.
 +               */
 +
 +              /* check device status */
 +              if (unlikely((status & (ATA_BUSY | ATA_DRQ)) != ATA_DRQ)) {
 +                      /* Wrong status. Let EH handle this */
 +                      qc->err_mask |= AC_ERR_HSM;
 +                      ap->hsm_task_state = HSM_ST_ERR;
 +                      goto fsm_start;
 +              }
 +
 +              atapi_send_cdb(ap, qc);
 +
 +              break;
 +
 +      case HSM_ST:
 +              /* complete command or read/write the data register */
 +              if (qc->tf.protocol == ATA_PROT_ATAPI) {
 +                      /* ATAPI PIO protocol */
 +                      if ((status & ATA_DRQ) == 0) {
 +                              /* no more data to transfer */
 +                              ap->hsm_task_state = HSM_ST_LAST;
 +                              goto fsm_start;
 +                      }
 +                      
 +                      atapi_pio_bytes(qc);
 +
 +                      if (unlikely(ap->hsm_task_state == HSM_ST_ERR))
 +                              /* bad ireason reported by device */
 +                              goto fsm_start;
 +
 +              } else {
 +                      /* ATA PIO protocol */
 +                      if (unlikely((status & ATA_DRQ) == 0)) {
 +                              /* handle BSY=0, DRQ=0 as error */
 +                              qc->err_mask |= AC_ERR_HSM;
 +                              ap->hsm_task_state = HSM_ST_ERR;
 +                              goto fsm_start;
 +                      }
 +
 +                      ata_pio_sectors(qc);
 +
 +                      if (ap->hsm_task_state == HSM_ST_LAST &&
 +                          (!(qc->tf.flags & ATA_TFLAG_WRITE))) {
 +                              /* all data read */
 +                              ata_altstatus(ap);
 +                              status = ata_chk_status(ap);
 +                              goto fsm_start;
 +                      }
 +              }
 +
 +              ata_altstatus(ap); /* flush */
 +              break;
 +
 +      case HSM_ST_LAST:
 +              if (unlikely(status & ATA_DRQ)) {
 +                      /* handle DRQ=1 as error */
 +                      qc->err_mask |= AC_ERR_HSM;
 +                      ap->hsm_task_state = HSM_ST_ERR;
 +                      goto fsm_start;
 +              }
 +
 +              /* no more data to transfer */
 +              DPRINTK("ata%u: command complete, drv_stat 0x%x\n",
 +                      ap->id, status);
 +
 +              ap->hsm_task_state = HSM_ST_IDLE;
  
                /* complete taskfile transaction */
                qc->err_mask |= ac_err_mask(status);
                ata_qc_complete(qc);
                break;
  
 +      case HSM_ST_ERR:
 +              if (qc->tf.command != ATA_CMD_PACKET)
 +                      printk(KERN_ERR "ata%u: command error, drv_stat 0x%x host_stat 0x%x\n",
 +                             ap->id, status, host_stat);
 +
 +              /* make sure qc->err_mask is available to 
 +               * know what's wrong and recover
 +               */
 +              WARN_ON(qc->err_mask == 0);
 +
 +              ap->hsm_task_state = HSM_ST_IDLE;
 +              ata_qc_complete(qc);
 +              break;
        default:
                goto idle_irq;
        }
@@@ -4533,11 -4176,11 +4534,11 @@@ irqreturn_t ata_interrupt (int irq, voi
  
                ap = host_set->ports[i];
                if (ap &&
 -                  !(ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR))) {
 +                  !(ap->flags & ATA_FLAG_PORT_DISABLED)) {
                        struct ata_queued_cmd *qc;
  
                        qc = ata_qc_from_tag(ap, ap->active_tag);
 -                      if (qc && (!(qc->tf.ctl & ATA_NIEN)) &&
 +                      if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)) &&
                            (qc->flags & ATA_QCFLAG_ACTIVE))
                                handled |= ata_host_intr(ap, qc);
                }
@@@ -4630,14 -4273,15 +4631,15 @@@ int ata_device_resume(struct ata_port *
   *    Flush the cache on the drive, if appropriate, then issue a
   *    standbynow command.
   */
- int ata_device_suspend(struct ata_port *ap, struct ata_device *dev)
+ int ata_device_suspend(struct ata_port *ap, struct ata_device *dev, pm_message_t state)
  {
        if (!ata_dev_present(dev))
                return 0;
        if (dev->class == ATA_DEV_ATA)
                ata_flush_cache(ap, dev);
  
-       ata_standby_drive(ap, dev);
+       if (state.event != PM_EVENT_FREEZE)
+               ata_standby_drive(ap, dev);
        ap->flags |= ATA_FLAG_SUSPENDED;
        return 0;
  }
  
  int ata_port_start (struct ata_port *ap)
  {
-       struct device *dev = ap->host_set->dev;
+       struct device *dev = ap->dev;
        int rc;
  
        ap->prd = dma_alloc_coherent(dev, ATA_PRD_TBL_SZ, &ap->prd_dma, GFP_KERNEL);
  
  void ata_port_stop (struct ata_port *ap)
  {
-       struct device *dev = ap->host_set->dev;
+       struct device *dev = ap->dev;
  
        dma_free_coherent(dev, ATA_PRD_TBL_SZ, ap->prd, ap->prd_dma);
        ata_pad_free(ap, dev);
@@@ -4756,6 -4400,7 +4758,7 @@@ static void ata_host_init(struct ata_po
        ap->host = host;
        ap->ctl = ATA_DEVCTL_OBS;
        ap->host_set = host_set;
+       ap->dev = ent->dev;
        ap->port_no = port_no;
        ap->hard_port_no =
                ent->legacy_mode ? ent->hard_port_no : port_no;
        INIT_WORK(&ap->port_task, NULL, NULL);
        INIT_LIST_HEAD(&ap->eh_done_q);
  
-       for (i = 0; i < ATA_MAX_DEVICES; i++)
-               ap->device[i].devno = i;
+       for (i = 0; i < ATA_MAX_DEVICES; i++) {
+               struct ata_device *dev = &ap->device[i];
+               dev->devno = i;
+               dev->pio_mask = UINT_MAX;
+               dev->mwdma_mask = UINT_MAX;
+               dev->udma_mask = UINT_MAX;
+       }
  
  #ifdef ATA_IRQ_TRAP
        ap->stats.unhandled_irq = 1;
@@@ -4806,6 -4456,14 +4814,14 @@@ static struct ata_port * ata_host_add(c
        int rc;
  
        DPRINTK("ENTER\n");
+       if (!ent->port_ops->probe_reset &&
+           !(ent->host_flags & (ATA_FLAG_SATA_RESET | ATA_FLAG_SRST))) {
+               printk(KERN_ERR "ata%u: no reset mechanism available\n",
+                      port_no);
+               return NULL;
+       }
        host = scsi_host_alloc(ent->sht, sizeof(struct ata_port));
        if (!host)
                return NULL;
@@@ -4966,7 -4624,7 +4982,7 @@@ err_free_ret
   *    ata_host_set_remove - PCI layer callback for device removal
   *    @host_set: ATA host set that was removed
   *
-  *    Unregister all objects associated with this host set. Free those 
+  *    Unregister all objects associated with this host set. Free those
   *    objects.
   *
   *    LOCKING:
@@@ -5238,6 -4896,8 +5254,8 @@@ EXPORT_SYMBOL_GPL(ata_std_postreset)
  EXPORT_SYMBOL_GPL(ata_std_probe_reset);
  EXPORT_SYMBOL_GPL(ata_drive_probe_reset);
  EXPORT_SYMBOL_GPL(ata_dev_revalidate);
+ EXPORT_SYMBOL_GPL(ata_dev_classify);
+ EXPORT_SYMBOL_GPL(ata_dev_pair);
  EXPORT_SYMBOL_GPL(ata_port_disable);
  EXPORT_SYMBOL_GPL(ata_ratelimit);
  EXPORT_SYMBOL_GPL(ata_busy_sleep);
@@@ -5248,7 -4908,6 +5266,6 @@@ EXPORT_SYMBOL_GPL(ata_scsi_error)
  EXPORT_SYMBOL_GPL(ata_scsi_slave_config);
  EXPORT_SYMBOL_GPL(ata_scsi_release);
  EXPORT_SYMBOL_GPL(ata_host_intr);
- EXPORT_SYMBOL_GPL(ata_dev_classify);
  EXPORT_SYMBOL_GPL(ata_id_string);
  EXPORT_SYMBOL_GPL(ata_id_c_string);
  EXPORT_SYMBOL_GPL(ata_scsi_simulate);
diff --combined drivers/scsi/sata_vsc.c
index 9f621a97c977b95d077f1584fd5ad59e90ef1649,836bbbb26ff2c1c37cb76608821156babd9d776c..5af6d5f9f4bd43e8ffdfb016cac92581b75f30e2
@@@ -221,27 -221,20 +221,27 @@@ static irqreturn_t vsc_sata_interrupt (
  
                        ap = host_set->ports[i];
  
 -                      if (ap && !(ap->flags &
 -                                  (ATA_FLAG_PORT_DISABLED|ATA_FLAG_NOINTR))) {
 +                      if (is_vsc_sata_int_err(i, int_status)) {
 +                              u32 err_status;
 +                              printk(KERN_DEBUG "%s: ignoring interrupt(s)\n", __FUNCTION__);
 +                              err_status = ap ? vsc_sata_scr_read(ap, SCR_ERROR) : 0;
 +                              vsc_sata_scr_write(ap, SCR_ERROR, err_status);
 +                              handled++;
 +                      }
 +
 +                      if (ap && !(ap->flags & ATA_FLAG_PORT_DISABLED)) {
                                struct ata_queued_cmd *qc;
  
                                qc = ata_qc_from_tag(ap, ap->active_tag);
 -                              if (qc && (!(qc->tf.ctl & ATA_NIEN))) {
 +                              if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)))
                                        handled += ata_host_intr(ap, qc);
 -                              else if (is_vsc_sata_int_err(i, int_status)) {
 +                              else if (is_vsc_sata_int_err(i, int_status)) {
                                        /*
-                                        * On some chips (i.e. Intel 31244), an error 
+                                        * On some chips (i.e. Intel 31244), an error
                                         * interrupt will sneak in at initialization
                                         * time (phy state changes).  Clearing the SCR
                                         * error register is not required, but it prevents
-                                        * the phy state change interrupts from recurring 
+                                        * the phy state change interrupts from recurring
                                         * later.
                                         */
                                        u32 err_status;
diff --combined include/linux/libata.h
index b3d4c906e2424a8f103cec3665e721bc037c45a6,9fcc061e3adff2924e786a45079629a936ea2bc0..70ca99bbc6c7fe23da8b59be5e50956b2be239a2
@@@ -123,7 -123,6 +123,7 @@@ enum 
        ATA_DFLAG_LBA48         = (1 << 0), /* device supports LBA48 */
        ATA_DFLAG_PIO           = (1 << 1), /* device currently in PIO mode */
        ATA_DFLAG_LBA           = (1 << 2), /* device supports LBA */
 +      ATA_DFLAG_CDB_INTR      = (1 << 3), /* device asserts INTRQ when ready for CDB */
  
        ATA_DEV_UNKNOWN         = 0,    /* unknown device */
        ATA_DEV_ATA             = 1,    /* ATA device */
        ATA_FLAG_MMIO           = (1 << 6), /* use MMIO, not PIO */
        ATA_FLAG_SATA_RESET     = (1 << 7), /* (obsolete) use COMRESET */
        ATA_FLAG_PIO_DMA        = (1 << 8), /* PIO cmds via DMA */
 -      ATA_FLAG_NOINTR         = (1 << 9), /* FIXME: Remove this once
 -                                           * proper HSM is in place. */
 +      ATA_FLAG_PIO_POLLING    = (1 << 9), /* use polling PIO if LLD
 +                                           * doesn't handle PIO interrupts */
        ATA_FLAG_DEBUGMSG       = (1 << 10),
        ATA_FLAG_NO_ATAPI       = (1 << 11), /* No ATAPI support */
  
        ATA_QCFLAG_EH_SCHEDULED = (1 << 5), /* EH scheduled */
  
        /* various lengths of time */
-       ATA_TMOUT_EDD           = 5 * HZ,       /* heuristic */
        ATA_TMOUT_PIO           = 30 * HZ,
        ATA_TMOUT_BOOT          = 30 * HZ,      /* heuristic */
        ATA_TMOUT_BOOT_QUICK    = 7 * HZ,       /* heuristic */
 +      ATA_TMOUT_DATAOUT       = 30 * HZ,
 +      ATA_TMOUT_DATAOUT_QUICK = 5 * HZ,
        ATA_TMOUT_CDB           = 30 * HZ,
        ATA_TMOUT_CDB_QUICK     = 5 * HZ,
        ATA_TMOUT_INTERNAL      = 30 * HZ,
  };
  
  enum hsm_task_states {
 -      HSM_ST_UNKNOWN,
 -      HSM_ST_IDLE,
 -      HSM_ST_POLL,
 -      HSM_ST_TMOUT,
 -      HSM_ST,
 -      HSM_ST_LAST,
 -      HSM_ST_LAST_POLL,
 -      HSM_ST_ERR,
 +      HSM_ST_UNKNOWN,         /* state unknown */
 +      HSM_ST_IDLE,            /* no command on going */
 +      HSM_ST_POLL,            /* same as HSM_ST, waits longer */
 +      HSM_ST_TMOUT,           /* timeout */
 +      HSM_ST,                 /* (waiting the device to) transfer data */
 +      HSM_ST_LAST,            /* (waiting the device to) complete command */
 +      HSM_ST_LAST_POLL,       /* same as HSM_ST_LAST, waits longer */
 +      HSM_ST_ERR,             /* error */
 +      HSM_ST_FIRST,           /* (waiting the device to)
 +                                 write CDB or first data block */
  };
  
  enum ata_completion_errors {
@@@ -363,6 -357,11 +362,11 @@@ struct ata_device 
        unsigned int            max_sectors;    /* per-device max sectors */
        unsigned int            cdb_len;
  
+       /* per-dev xfer mask */
+       unsigned int            pio_mask;
+       unsigned int            mwdma_mask;
+       unsigned int            udma_mask;
        /* for CHS addressing */
        u16                     cylinders;      /* Number of cylinders */
        u16                     heads;          /* Number of heads */
@@@ -400,6 -399,7 +404,7 @@@ struct ata_port 
  
        struct ata_host_stats   stats;
        struct ata_host_set     *host_set;
+       struct device           *dev;
  
        struct work_struct      port_task;
  
@@@ -520,9 -520,9 +525,9 @@@ extern void ata_eh_qc_retry(struct ata_
  extern int ata_scsi_release(struct Scsi_Host *host);
  extern unsigned int ata_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc);
  extern int ata_scsi_device_resume(struct scsi_device *);
- extern int ata_scsi_device_suspend(struct scsi_device *);
+ extern int ata_scsi_device_suspend(struct scsi_device *, pm_message_t state);
  extern int ata_device_resume(struct ata_port *, struct ata_device *);
- extern int ata_device_suspend(struct ata_port *, struct ata_device *);
+ extern int ata_device_suspend(struct ata_port *, struct ata_device *, pm_message_t state);
  extern int ata_ratelimit(void);
  extern unsigned int ata_busy_sleep(struct ata_port *ap,
                                   unsigned long timeout_pat,
@@@ -573,6 -573,8 +578,8 @@@ extern int ata_std_bios_param(struct sc
                              struct block_device *bdev,
                              sector_t capacity, int geom[]);
  extern int ata_scsi_slave_config(struct scsi_device *sdev);
+ extern struct ata_device *ata_dev_pair(struct ata_port *ap, 
+                                      struct ata_device *adev);
  
  /*
   * Timing helpers