Merge branch 'upstream'
authorJeff Garzik <jeff@garzik.org>
Fri, 24 Mar 2006 14:24:04 +0000 (09:24 -0500)
committerJeff Garzik <jeff@garzik.org>
Fri, 24 Mar 2006 14:24:04 +0000 (09:24 -0500)
Conflicts:

drivers/scsi/sata_vsc.c

1  2 
drivers/scsi/libata-core.c
drivers/scsi/pdc_adma.c
drivers/scsi/sata_mv.c
drivers/scsi/sata_nv.c
drivers/scsi/sata_promise.c
drivers/scsi/sata_qstor.c
drivers/scsi/sata_sx4.c
drivers/scsi/sata_vsc.c
include/linux/ata.h
include/linux/libata.h

@@@ -65,14 -65,13 +65,14 @@@ static unsigned int ata_dev_init_params
                                        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 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;
  
- int atapi_enabled = 0;
+ int atapi_enabled = 1;
  module_param(atapi_enabled, int, 0444);
  MODULE_PARM_DESC(atapi_enabled, "Enable discovery of ATAPI devices (0=off, 1=on)");
  
@@@ -820,7 -819,10 +820,10 @@@ static unsigned int ata_id_xfermask(con
        }
  
        mwdma_mask = id[ATA_ID_MWDMA_MODES] & 0x07;
-       udma_mask = id[ATA_ID_UDMA_MODES] & 0xff;
+       udma_mask = 0;
+       if (id[ATA_ID_FIELD_VALID] & (1 << 2))
+               udma_mask = id[ATA_ID_UDMA_MODES] & 0xff;
  
        return ata_pack_xfermask(pio_mask, mwdma_mask, udma_mask);
  }
@@@ -960,6 -962,8 +963,8 @@@ ata_exec_internal(struct ata_port *ap, 
        spin_unlock_irqrestore(&ap->host_set->lock, flags);
  
        if (!wait_for_completion_timeout(&wait, ATA_TMOUT_INTERNAL)) {
+               ata_port_flush_task(ap);
                spin_lock_irqsave(&ap->host_set->lock, flags);
  
                /* We're racing with irq here.  If we lose, the
@@@ -1118,12 -1122,6 +1123,6 @@@ static int ata_dev_read_id(struct ata_p
  
        swap_buf_le16(id, ATA_ID_WORDS);
  
-       /* print device capabilities */
-       printk(KERN_DEBUG "ata%u: dev %u cfg "
-              "49:%04x 82:%04x 83:%04x 84:%04x 85:%04x 86:%04x 87:%04x 88:%04x\n",
-              ap->id, dev->devno,
-              id[49], id[82], id[83], id[84], id[85], id[86], id[87], id[88]);
        /* sanity check */
        if ((class == ATA_DEV_ATA) != ata_id_is_ata(id)) {
                rc = -EINVAL;
@@@ -1191,6 -1189,7 +1190,7 @@@ static inline u8 ata_dev_knobble(const 
  static int ata_dev_configure(struct ata_port *ap, struct ata_device *dev,
                             int print_info)
  {
+       const u16 *id = dev->id;
        unsigned int xfer_mask;
        int i, rc;
  
  
        DPRINTK("ENTER, host %u, dev %u\n", ap->id, dev->devno);
  
+       /* print device capabilities */
+       if (print_info)
+               printk(KERN_DEBUG "ata%u: dev %u cfg 49:%04x 82:%04x 83:%04x "
+                      "84:%04x 85:%04x 86:%04x 87:%04x 88:%04x\n",
+                      ap->id, dev->devno, id[49], id[82], id[83],
+                      id[84], id[85], id[86], id[87], id[88]);
        /* initialize to-be-configured parameters */
        dev->flags = 0;
        dev->max_sectors = 0;
         * common ATA, ATAPI feature tests
         */
  
-       /* we require DMA support (bits 8 of word 49) */
-       if (!ata_id_has_dma(dev->id)) {
-               printk(KERN_DEBUG "ata%u: no dma\n", ap->id);
-               rc = -EINVAL;
-               goto err_out_nosup;
-       }
        /* find max transfer mode; for printk only */
-       xfer_mask = ata_id_xfermask(dev->id);
+       xfer_mask = ata_id_xfermask(id);
  
-       ata_dump_id(dev->id);
+       ata_dump_id(id);
  
        /* ATA-specific feature tests */
        if (dev->class == ATA_DEV_ATA) {
-               dev->n_sectors = ata_id_n_sectors(dev->id);
+               dev->n_sectors = ata_id_n_sectors(id);
  
-               if (ata_id_has_lba(dev->id)) {
+               if (ata_id_has_lba(id)) {
                        const char *lba_desc;
  
                        lba_desc = "LBA";
                        dev->flags |= ATA_DFLAG_LBA;
-                       if (ata_id_has_lba48(dev->id)) {
+                       if (ata_id_has_lba48(id)) {
                                dev->flags |= ATA_DFLAG_LBA48;
                                lba_desc = "LBA48";
                        }
                                printk(KERN_INFO "ata%u: dev %u ATA-%d, "
                                       "max %s, %Lu sectors: %s\n",
                                       ap->id, dev->devno,
-                                      ata_id_major_version(dev->id),
+                                      ata_id_major_version(id),
                                       ata_mode_string(xfer_mask),
                                       (unsigned long long)dev->n_sectors,
                                       lba_desc);
                        /* CHS */
  
                        /* Default translation */
-                       dev->cylinders  = dev->id[1];
-                       dev->heads      = dev->id[3];
-                       dev->sectors    = dev->id[6];
+                       dev->cylinders  = id[1];
+                       dev->heads      = id[3];
+                       dev->sectors    = id[6];
  
-                       if (ata_id_current_chs_valid(dev->id)) {
+                       if (ata_id_current_chs_valid(id)) {
                                /* Current CHS translation is valid. */
-                               dev->cylinders = dev->id[54];
-                               dev->heads     = dev->id[55];
-                               dev->sectors   = dev->id[56];
+                               dev->cylinders = id[54];
+                               dev->heads     = id[55];
+                               dev->sectors   = id[56];
                        }
  
                        /* print device info to dmesg */
                                printk(KERN_INFO "ata%u: dev %u ATA-%d, "
                                       "max %s, %Lu sectors: CHS %u/%u/%u\n",
                                       ap->id, dev->devno,
-                                      ata_id_major_version(dev->id),
+                                      ata_id_major_version(id),
                                       ata_mode_string(xfer_mask),
                                       (unsigned long long)dev->n_sectors,
                                       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 */
        else if (dev->class == ATA_DEV_ATAPI) {
-               rc = atapi_cdb_len(dev->id);
+               rc = atapi_cdb_len(id);
                if ((rc < 12) || (rc > ATAPI_CDB_LEN)) {
                        printk(KERN_WARNING "ata%u: unsupported CDB len\n", ap->id);
                        rc = -EINVAL;
                }
                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",
@@@ -1353,32 -1344,30 +1353,30 @@@ static int ata_bus_probe(struct ata_por
  
        ata_port_probe(ap);
  
-       /* reset */
-       if (ap->ops->probe_reset) {
-               for (i = 0; i < ATA_MAX_DEVICES; i++)
-                       classes[i] = ATA_DEV_UNKNOWN;
+       /* reset and determine device classes */
+       for (i = 0; i < ATA_MAX_DEVICES; i++)
+               classes[i] = ATA_DEV_UNKNOWN;
  
+       if (ap->ops->probe_reset) {
                rc = ap->ops->probe_reset(ap, classes);
                if (rc) {
                        printk("ata%u: reset failed (errno=%d)\n", ap->id, rc);
                        return rc;
                }
-               for (i = 0; i < ATA_MAX_DEVICES; i++)
-                       if (classes[i] == ATA_DEV_UNKNOWN)
-                               classes[i] = ATA_DEV_NONE;
        } else {
                ap->ops->phy_reset(ap);
  
-               for (i = 0; i < ATA_MAX_DEVICES; i++) {
-                       if (!(ap->flags & ATA_FLAG_PORT_DISABLED))
+               if (!(ap->flags & ATA_FLAG_PORT_DISABLED))
+                       for (i = 0; i < ATA_MAX_DEVICES; i++)
                                classes[i] = ap->device[i].class;
-                       else
-                               ap->device[i].class = ATA_DEV_UNKNOWN;
-               }
                ata_port_probe(ap);
        }
  
+       for (i = 0; i < ATA_MAX_DEVICES; i++)
+               if (classes[i] == ATA_DEV_UNKNOWN)
+                       classes[i] = ATA_DEV_NONE;
        /* read IDENTIFY page and configure devices */
        for (i = 0; i < ATA_MAX_DEVICES; i++) {
                struct ata_device *dev = &ap->device[i];
@@@ -1743,7 -1732,7 +1741,7 @@@ static int ata_host_set_pio(struct ata_
                        continue;
  
                if (!dev->pio_mode) {
-                       printk(KERN_WARNING "ata%u: no PIO support\n", ap->id);
+                       printk(KERN_WARNING "ata%u: no PIO support for device %d.\n", ap->id, i);
                        return -1;
                }
  
@@@ -2005,9 -1994,19 +2003,19 @@@ static unsigned int ata_bus_softreset(s
         * status is checked.  Because waiting for "a while" before
         * checking status is fine, post SRST, we perform this magic
         * delay here as well.
+        *
+        * Old drivers/ide uses the 2mS rule and then waits for ready
         */
        msleep(150);
  
+       
+       /* 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 */
        ata_bus_post_reset(ap, devmask);
  
        return 0;
@@@ -2557,48 -2556,72 +2565,72 @@@ int ata_dev_revalidate(struct ata_port 
  }
  
  static const char * const ata_dma_blacklist [] = {
-       "WDC AC11000H",
-       "WDC AC22100H",
-       "WDC AC32500H",
-       "WDC AC33100H",
-       "WDC AC31600H",
-       "WDC AC32100H",
-       "WDC AC23200L",
-       "Compaq CRD-8241B",
-       "CRD-8400B",
-       "CRD-8480B",
-       "CRD-8482B",
-       "CRD-84",
-       "SanDisk SDP3B",
-       "SanDisk SDP3B-64",
-       "SANYO CD-ROM CRD",
-       "HITACHI CDR-8",
-       "HITACHI CDR-8335",
-       "HITACHI CDR-8435",
-       "Toshiba CD-ROM XM-6202B",
-       "TOSHIBA CD-ROM XM-1702BC",
-       "CD-532E-A",
-       "E-IDE CD-ROM CR-840",
-       "CD-ROM Drive/F5A",
-       "WPI CDD-820",
-       "SAMSUNG CD-ROM SC-148C",
-       "SAMSUNG CD-ROM SC",
-       "SanDisk SDP3B-64",
-       "ATAPI CD-ROM DRIVE 40X MAXIMUM",
-       "_NEC DV5800A",
+       "WDC AC11000H", NULL,
+       "WDC AC22100H", NULL,
+       "WDC AC32500H", NULL,
+       "WDC AC33100H", NULL,
+       "WDC AC31600H", NULL,
+       "WDC AC32100H", "24.09P07",
+       "WDC AC23200L", "21.10N21",
+       "Compaq CRD-8241B",  NULL,
+       "CRD-8400B", NULL,
+       "CRD-8480B", NULL,
+       "CRD-8482B", NULL,
+       "CRD-84", NULL,
+       "SanDisk SDP3B", NULL,
+       "SanDisk SDP3B-64", NULL,
+       "SANYO CD-ROM CRD", NULL,
+       "HITACHI CDR-8", 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, 
+       "SAMSUNG CD-ROM SC-148C", 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);
+       /* ATAPI specifies that empty space is blank-filled; remove blanks */
+       while ((len > 0) && (s[len - 1] == ' ')) {
+               len--;
+               s[len] = 0;
+       }
+       return len;
+ }
  
  static int ata_dma_blacklisted(const struct ata_device *dev)
  {
-       unsigned char model_num[41];
+       unsigned char model_num[40];
+       unsigned char model_rev[16];
+       unsigned int nlen, rlen;
        int i;
  
-       ata_id_c_string(dev->id, model_num, ATA_ID_PROD_OFS, sizeof(model_num));
-       for (i = 0; i < ARRAY_SIZE(ata_dma_blacklist); i++)
-               if (!strcmp(ata_dma_blacklist[i], model_num))
-                       return 1;
+       ata_id_string(dev->id, model_num, ATA_ID_PROD_OFS,
+                         sizeof(model_num));
+       ata_id_string(dev->id, model_rev, ATA_ID_FW_REV_OFS,
+                         sizeof(model_rev));
+       nlen = ata_strim(model_num, sizeof(model_num));
+       rlen = ata_strim(model_rev, sizeof(model_rev));
  
+       for (i = 0; i < ARRAY_SIZE(ata_dma_blacklist); i += 2) {
+               if (!strncmp(ata_dma_blacklist[i], model_num, nlen)) {
+                       if (ata_dma_blacklist[i+1] == NULL)
+                               return 1;
+                       if (!strncmp(ata_dma_blacklist[i], model_rev, rlen))
+                               return 1;
+               }
+       }
        return 0;
  }
  
@@@ -2869,6 -2892,8 +2901,8 @@@ void ata_qc_prep(struct ata_queued_cmd 
        ata_fill_sg(qc);
  }
  
+ void ata_noop_qc_prep(struct ata_queued_cmd *qc) { }
  /**
   *    ata_sg_init_one - Associate command with memory buffer
   *    @qc: Command to be associated
@@@ -3090,6 -3115,7 +3124,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);
@@@ -3155,8 -3181,7 +3189,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;
  }
  
  
@@@ -3371,23 -3396,7 +3405,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 */
  }
  
  /**
@@@ -3608,23 -3478,7 +3642,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;
  }
@@@ -3671,8 -3532,6 +3705,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;
@@@ -3743,10 -3602,8 +3777,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)
@@@ -3773,23 -3630,22 +3807,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;
  }
  
@@@ -3866,8 -3718,7 +3900,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 */
@@@ -3939,10 -3790,8 +3973,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;
        }
  
@@@ -4089,7 -3938,6 +4123,6 @@@ static inline int ata_should_dma_map(st
  
        case ATA_PROT_ATAPI:
        case ATA_PROT_PIO:
-       case ATA_PROT_PIO_MULT:
                if (ap->flags & ATA_FLAG_PIO_DMA)
                        return 1;
  
@@@ -4169,104 -4017,43 +4202,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:
  }
  
  /**
-  *    ata_bmdma_setup_mmio - Set up PCI IDE BMDMA transaction
-  *    @qc: Info associated with this ATA transaction.
-  *
-  *    LOCKING:
-  *    spin_lock_irqsave(host_set lock)
-  */
- static void ata_bmdma_setup_mmio (struct ata_queued_cmd *qc)
- {
-       struct ata_port *ap = qc->ap;
-       unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE);
-       u8 dmactl;
-       void __iomem *mmio = (void __iomem *) ap->ioaddr.bmdma_addr;
-       /* load PRD table addr. */
-       mb();   /* make sure PRD table writes are visible to controller */
-       writel(ap->prd_dma, mmio + ATA_DMA_TABLE_OFS);
-       /* specify data direction, triple-check start bit is clear */
-       dmactl = readb(mmio + ATA_DMA_CMD);
-       dmactl &= ~(ATA_DMA_WR | ATA_DMA_START);
-       if (!rw)
-               dmactl |= ATA_DMA_WR;
-       writeb(dmactl, mmio + ATA_DMA_CMD);
-       /* issue r/w command */
-       ap->ops->exec_command(ap, &qc->tf);
- }
- /**
-  *    ata_bmdma_start_mmio - Start a PCI IDE BMDMA transaction
-  *    @qc: Info associated with this ATA transaction.
-  *
-  *    LOCKING:
-  *    spin_lock_irqsave(host_set lock)
-  */
- static void ata_bmdma_start_mmio (struct ata_queued_cmd *qc)
- {
-       struct ata_port *ap = qc->ap;
-       void __iomem *mmio = (void __iomem *) ap->ioaddr.bmdma_addr;
-       u8 dmactl;
-       /* start host DMA transaction */
-       dmactl = readb(mmio + ATA_DMA_CMD);
-       writeb(dmactl | ATA_DMA_START, mmio + ATA_DMA_CMD);
-       /* Strictly, one may wish to issue a readb() here, to
-        * flush the mmio write.  However, control also passes
-        * to the hardware at this point, and it will interrupt
-        * us when we are to resume control.  So, in effect,
-        * we don't care when the mmio write flushes.
-        * Further, a read of the DMA status register _immediately_
-        * following the write may not be what certain flaky hardware
-        * is expected, so I think it is best to not add a readb()
-        * without first all the MMIO ATA cards/mobos.
-        * Or maybe I'm just being paranoid.
-        */
- }
- /**
-  *    ata_bmdma_setup_pio - Set up PCI IDE BMDMA transaction (PIO)
-  *    @qc: Info associated with this ATA transaction.
-  *
-  *    LOCKING:
-  *    spin_lock_irqsave(host_set lock)
-  */
- static void ata_bmdma_setup_pio (struct ata_queued_cmd *qc)
- {
-       struct ata_port *ap = qc->ap;
-       unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE);
-       u8 dmactl;
-       /* load PRD table addr. */
-       outl(ap->prd_dma, ap->ioaddr.bmdma_addr + ATA_DMA_TABLE_OFS);
-       /* specify data direction, triple-check start bit is clear */
-       dmactl = inb(ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
-       dmactl &= ~(ATA_DMA_WR | ATA_DMA_START);
-       if (!rw)
-               dmactl |= ATA_DMA_WR;
-       outb(dmactl, ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
-       /* issue r/w command */
-       ap->ops->exec_command(ap, &qc->tf);
- }
- /**
-  *    ata_bmdma_start_pio - Start a PCI IDE BMDMA transaction (PIO)
-  *    @qc: Info associated with this ATA transaction.
-  *
-  *    LOCKING:
-  *    spin_lock_irqsave(host_set lock)
-  */
- static void ata_bmdma_start_pio (struct ata_queued_cmd *qc)
- {
-       struct ata_port *ap = qc->ap;
-       u8 dmactl;
-       /* start host DMA transaction */
-       dmactl = inb(ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
-       outb(dmactl | ATA_DMA_START,
-            ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
- }
- /**
-  *    ata_bmdma_start - Start a PCI IDE BMDMA transaction
-  *    @qc: Info associated with this ATA transaction.
-  *
-  *    Writes the ATA_DMA_START flag to the DMA command register.
-  *
-  *    May be used as the bmdma_start() entry in ata_port_operations.
-  *
-  *    LOCKING:
-  *    spin_lock_irqsave(host_set lock)
-  */
- void ata_bmdma_start(struct ata_queued_cmd *qc)
- {
-       if (qc->ap->flags & ATA_FLAG_MMIO)
-               ata_bmdma_start_mmio(qc);
-       else
-               ata_bmdma_start_pio(qc);
- }
- /**
-  *    ata_bmdma_setup - Set up PCI IDE BMDMA transaction
-  *    @qc: Info associated with this ATA transaction.
-  *
-  *    Writes address of PRD table to device's PRD Table Address
-  *    register, sets the DMA control register, and calls
-  *    ops->exec_command() to start the transfer.
-  *
-  *    May be used as the bmdma_setup() entry in ata_port_operations.
-  *
-  *    LOCKING:
-  *    spin_lock_irqsave(host_set lock)
-  */
- void ata_bmdma_setup(struct ata_queued_cmd *qc)
- {
-       if (qc->ap->flags & ATA_FLAG_MMIO)
-               ata_bmdma_setup_mmio(qc);
-       else
-               ata_bmdma_setup_pio(qc);
- }
- /**
-  *    ata_bmdma_irq_clear - Clear PCI IDE BMDMA interrupt.
-  *    @ap: Port associated with this ATA transaction.
-  *
-  *    Clear interrupt and error flags in DMA status register.
-  *
-  *    May be used as the irq_clear() entry in ata_port_operations.
-  *
-  *    LOCKING:
-  *    spin_lock_irqsave(host_set lock)
-  */
- void ata_bmdma_irq_clear(struct ata_port *ap)
- {
-     if (ap->flags & ATA_FLAG_MMIO) {
-         void __iomem *mmio = ((void __iomem *) ap->ioaddr.bmdma_addr) + ATA_DMA_STATUS;
-         writeb(readb(mmio), mmio);
-     } else {
-         unsigned long addr = ap->ioaddr.bmdma_addr + ATA_DMA_STATUS;
-         outb(inb(addr), addr);
-     }
- }
- /**
-  *    ata_bmdma_status - Read PCI IDE BMDMA status
-  *    @ap: Port associated with this ATA transaction.
-  *
-  *    Read and return BMDMA status register.
-  *
-  *    May be used as the bmdma_status() entry in ata_port_operations.
-  *
-  *    LOCKING:
-  *    spin_lock_irqsave(host_set lock)
-  */
- u8 ata_bmdma_status(struct ata_port *ap)
- {
-       u8 host_stat;
-       if (ap->flags & ATA_FLAG_MMIO) {
-               void __iomem *mmio = (void __iomem *) ap->ioaddr.bmdma_addr;
-               host_stat = readb(mmio + ATA_DMA_STATUS);
-       } else
-               host_stat = inb(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);
-       return host_stat;
- }
- /**
-  *    ata_bmdma_stop - Stop PCI IDE BMDMA transfer
-  *    @qc: Command we are ending DMA for
-  *
-  *    Clears the ATA_DMA_START flag in the dma control register
-  *
-  *    May be used as the bmdma_stop() entry in ata_port_operations.
-  *
-  *    LOCKING:
-  *    spin_lock_irqsave(host_set lock)
-  */
- void ata_bmdma_stop(struct ata_queued_cmd *qc)
- {
-       struct ata_port *ap = qc->ap;
-       if (ap->flags & ATA_FLAG_MMIO) {
-               void __iomem *mmio = (void __iomem *) ap->ioaddr.bmdma_addr;
-               /* clear start/stop bit */
-               writeb(readb(mmio + ATA_DMA_CMD) & ~ATA_DMA_START,
-                       mmio + ATA_DMA_CMD);
-       } else {
-               /* clear start/stop bit */
-               outb(inb(ap->ioaddr.bmdma_addr + ATA_DMA_CMD) & ~ATA_DMA_START,
-                       ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
-       }
-       /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */
-       ata_altstatus(ap);        /* dummy read */
- }
- /**
   *    ata_host_intr - Handle host interrupt for given (port, task)
   *    @ap: Port on which interrupt arrived (possibly...)
   *    @qc: Taskfile currently active in engine
  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;
        }
@@@ -4692,9 -4136,9 +4494,9 @@@ idle_irq
  
  #ifdef ATA_IRQ_TRAP
        if ((ap->stats.idle_irq % 1000) == 0) {
-               handled = 1;
                ata_irq_ack(ap, 0); /* debug trap */
                printk(KERN_WARNING "ata%d: irq trap\n", ap->id);
+               return 1;
        }
  #endif
        return 0;       /* irq not handled */
@@@ -4731,11 -4175,11 +4533,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);
                }
@@@ -5008,6 -4452,8 +4810,8 @@@ static struct ata_port * ata_host_add(c
        if (!host)
                return NULL;
  
+       host->transportt = &ata_scsi_transport_template;
        ap = (struct ata_port *) &host->hostdata[0];
  
        ata_host_init(ap, host, host_set, ent, port_no);
@@@ -5417,6 -4863,7 +5221,7 @@@ EXPORT_SYMBOL_GPL(ata_port_stop)
  EXPORT_SYMBOL_GPL(ata_host_stop);
  EXPORT_SYMBOL_GPL(ata_interrupt);
  EXPORT_SYMBOL_GPL(ata_qc_prep);
+ EXPORT_SYMBOL_GPL(ata_noop_qc_prep);
  EXPORT_SYMBOL_GPL(ata_bmdma_setup);
  EXPORT_SYMBOL_GPL(ata_bmdma_start);
  EXPORT_SYMBOL_GPL(ata_bmdma_irq_clear);
@@@ -5439,7 -4886,6 +5244,6 @@@ EXPORT_SYMBOL_GPL(ata_busy_sleep)
  EXPORT_SYMBOL_GPL(ata_port_queue_task);
  EXPORT_SYMBOL_GPL(ata_scsi_ioctl);
  EXPORT_SYMBOL_GPL(ata_scsi_queuecmd);
- EXPORT_SYMBOL_GPL(ata_scsi_timed_out);
  EXPORT_SYMBOL_GPL(ata_scsi_error);
  EXPORT_SYMBOL_GPL(ata_scsi_slave_config);
  EXPORT_SYMBOL_GPL(ata_scsi_release);
@@@ -5463,6 -4909,8 +5267,8 @@@ EXPORT_SYMBOL_GPL(ata_pci_init_one)
  EXPORT_SYMBOL_GPL(ata_pci_remove_one);
  EXPORT_SYMBOL_GPL(ata_pci_device_suspend);
  EXPORT_SYMBOL_GPL(ata_pci_device_resume);
+ EXPORT_SYMBOL_GPL(ata_pci_default_filter);
+ EXPORT_SYMBOL_GPL(ata_pci_clear_simplex);
  #endif /* CONFIG_PCI */
  
  EXPORT_SYMBOL_GPL(ata_device_suspend);
diff --combined drivers/scsi/pdc_adma.c
@@@ -143,7 -143,6 +143,6 @@@ static struct scsi_host_template adma_a
        .name                   = DRV_NAME,
        .ioctl                  = ata_scsi_ioctl,
        .queuecommand           = ata_scsi_queuecmd,
-       .eh_timed_out           = ata_scsi_timed_out,
        .eh_strategy_handler    = ata_scsi_error,
        .can_queue              = ATA_DEF_QUEUE,
        .this_id                = ATA_SHT_THIS_ID,
@@@ -322,7 -321,7 +321,7 @@@ static int adma_fill_sg(struct ata_queu
                        = (pFLAGS & pEND) ? 0 : cpu_to_le32(pp->pkt_dma + i + 4);
                i += 4;
  
-               VPRINTK("PRD[%u] = (0x%lX, 0x%X)\n", nelem,
+               VPRINTK("PRD[%u] = (0x%lX, 0x%X)\n", i/4,
                                        (unsigned long)addr, len);
        }
        return i;
@@@ -457,13 -456,13 +456,13 @@@ static inline unsigned int adma_intr_pk
                        continue;
                handled = 1;
                adma_enter_reg_mode(ap);
 -              if (ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR))
 +              if (ap->flags & ATA_FLAG_PORT_DISABLED)
                        continue;
                pp = ap->private_data;
                if (!pp || pp->state != adma_state_pkt)
                        continue;
                qc = ata_qc_from_tag(ap, ap->active_tag);
 -              if (qc && (!(qc->tf.ctl & ATA_NIEN))) {
 +              if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING))) {
                        if ((status & (aPERR | aPSD | aUIRQ)))
                                qc->err_mask |= AC_ERR_OTHER;
                        else if (pp->pkt[0] != cDONE)
@@@ -482,13 -481,13 +481,13 @@@ static inline unsigned int adma_intr_mm
        for (port_no = 0; port_no < host_set->n_ports; ++port_no) {
                struct ata_port *ap;
                ap = host_set->ports[port_no];
 -              if (ap && (!(ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR)))) {
 +              if (ap && (!(ap->flags & ATA_FLAG_PORT_DISABLED))) {
                        struct ata_queued_cmd *qc;
                        struct adma_port_priv *pp = ap->private_data;
                        if (!pp || pp->state != adma_state_mmio)
                                continue;
                        qc = ata_qc_from_tag(ap, ap->active_tag);
 -                      if (qc && (!(qc->tf.ctl & ATA_NIEN))) {
 +                      if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING))) {
  
                                /* check main status, clearing INTRQ */
                                u8 status = ata_check_status(ap);
diff --combined drivers/scsi/sata_mv.c
@@@ -87,7 -87,7 +87,7 @@@ enum 
        MV_FLAG_IRQ_COALESCE    = (1 << 29),  /* IRQ coalescing capability */
        MV_COMMON_FLAGS         = (ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
                                   ATA_FLAG_SATA_RESET | ATA_FLAG_MMIO |
 -                                 ATA_FLAG_NO_ATAPI),
 +                                 ATA_FLAG_PIO_POLLING),
        MV_6XXX_FLAGS           = MV_FLAG_IRQ_COALESCE,
  
        CRQB_FLAG_READ          = (1 << 0),
@@@ -378,7 -378,6 +378,6 @@@ static struct scsi_host_template mv_sh
        .name                   = DRV_NAME,
        .ioctl                  = ata_scsi_ioctl,
        .queuecommand           = ata_scsi_queuecmd,
-       .eh_timed_out           = ata_scsi_timed_out,
        .eh_strategy_handler    = ata_scsi_error,
        .can_queue              = MV_USE_Q_DEPTH,
        .this_id                = ATA_SHT_THIS_ID,
@@@ -1263,6 -1262,7 +1262,7 @@@ static u8 mv_get_crpb_status(struct ata
        void __iomem *port_mmio = mv_ap_base(ap);
        struct mv_port_priv *pp = ap->private_data;
        u32 out_ptr;
+       u8 ata_status;
  
        out_ptr = readl(port_mmio + EDMA_RSP_Q_OUT_PTR_OFS);
  
        WARN_ON(((out_ptr >> EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) !=
                pp->rsp_consumer);
  
+       ata_status = pp->crpb[pp->rsp_consumer].flags >> CRPB_FLAG_STATUS_SHIFT;
        /* increment our consumer index... */
        pp->rsp_consumer = mv_inc_q_index(&pp->rsp_consumer);
  
        writelfl(out_ptr, port_mmio + EDMA_RSP_Q_OUT_PTR_OFS);
  
        /* Return ATA status register for completed CRPB */
-       return (pp->crpb[pp->rsp_consumer].flags >> CRPB_FLAG_STATUS_SHIFT);
+       return ata_status;
  }
  
  /**
@@@ -1353,7 -1355,6 +1355,6 @@@ static void mv_host_intr(struct ata_hos
        u32 hc_irq_cause;
        int shift, port, port0, hard_port, handled;
        unsigned int err_mask;
-       u8 ata_status = 0;
  
        if (hc == 0) {
                port0 = 0;
                hc,relevant,hc_irq_cause);
  
        for (port = port0; port < port0 + MV_PORTS_PER_HC; port++) {
+               u8 ata_status = 0;
                ap = host_set->ports[port];
                hard_port = port & MV_PORT_MASK;        /* range 0-3 */
                handled = 0;    /* ensure ata_status is set if handled++ */
                        handled++;
                }
  
 -              if (ap &&
 -                  (ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR)))
 +              if (ap && (ap->flags & ATA_FLAG_PORT_DISABLED))
                        continue;
  
                err_mask = ac_err_mask(ata_status);
                                VPRINTK("port %u IRQ found for qc, "
                                        "ata_status 0x%x\n", port,ata_status);
                                /* mark qc status appropriately */
 -                              if (!(qc->tf.ctl & ATA_NIEN)) {
 +                              if (!(qc->tf.flags & ATA_TFLAG_POLLING)) {
                                        qc->err_mask |= err_mask;
                                        ata_qc_complete(qc);
                                }
diff --combined drivers/scsi/sata_nv.c
   *  NV-specific details such as register offsets, SATA phy location,
   *  hotplug info, etc.
   *
-  *  0.10
-  *     - Fixed spurious interrupts issue seen with the Maxtor 6H500F0 500GB
-  *       drive.  Also made the check_hotplug() callbacks return whether there
-  *       was a hotplug interrupt or not.  This was not the source of the
-  *       spurious interrupts, but is the right thing to do anyway.
-  *
-  *  0.09
-  *     - Fixed bug introduced by 0.08's MCP51 and MCP55 support.
-  *
-  *  0.08
-  *     - Added support for MCP51 and MCP55.
-  *
-  *  0.07
-  *     - Added support for RAID class code.
-  *
-  *  0.06
-  *     - Added generic SATA support by using a pci_device_id that filters on
-  *       the IDE storage class code.
-  *
-  *  0.03
-  *     - Fixed a bug where the hotplug handlers for non-CK804/MCP04 were using
-  *       mmio_base, which is only set for the CK804/MCP04 case.
-  *
-  *  0.02
-  *     - Added support for CK804 SATA controller.
-  *
-  *  0.01
-  *     - Initial revision.
   */
  
  #include <linux/config.h>
  #define DRV_NAME                      "sata_nv"
  #define DRV_VERSION                   "0.8"
  
- #define NV_PORTS                      2
- #define NV_PIO_MASK                   0x1f
- #define NV_MWDMA_MASK                 0x07
- #define NV_UDMA_MASK                  0x7f
- #define NV_PORT0_SCR_REG_OFFSET               0x00
- #define NV_PORT1_SCR_REG_OFFSET               0x40
- #define NV_INT_STATUS                 0x10
- #define NV_INT_STATUS_CK804           0x440
- #define NV_INT_STATUS_PDEV_INT                0x01
- #define NV_INT_STATUS_PDEV_PM         0x02
- #define NV_INT_STATUS_PDEV_ADDED      0x04
- #define NV_INT_STATUS_PDEV_REMOVED    0x08
- #define NV_INT_STATUS_SDEV_INT                0x10
- #define NV_INT_STATUS_SDEV_PM         0x20
- #define NV_INT_STATUS_SDEV_ADDED      0x40
- #define NV_INT_STATUS_SDEV_REMOVED    0x80
- #define NV_INT_STATUS_PDEV_HOTPLUG    (NV_INT_STATUS_PDEV_ADDED | \
-                                       NV_INT_STATUS_PDEV_REMOVED)
- #define NV_INT_STATUS_SDEV_HOTPLUG    (NV_INT_STATUS_SDEV_ADDED | \
-                                       NV_INT_STATUS_SDEV_REMOVED)
- #define NV_INT_STATUS_HOTPLUG         (NV_INT_STATUS_PDEV_HOTPLUG | \
-                                       NV_INT_STATUS_SDEV_HOTPLUG)
- #define NV_INT_ENABLE                 0x11
- #define NV_INT_ENABLE_CK804           0x441
- #define NV_INT_ENABLE_PDEV_MASK               0x01
- #define NV_INT_ENABLE_PDEV_PM         0x02
- #define NV_INT_ENABLE_PDEV_ADDED      0x04
- #define NV_INT_ENABLE_PDEV_REMOVED    0x08
- #define NV_INT_ENABLE_SDEV_MASK               0x10
- #define NV_INT_ENABLE_SDEV_PM         0x20
- #define NV_INT_ENABLE_SDEV_ADDED      0x40
- #define NV_INT_ENABLE_SDEV_REMOVED    0x80
- #define NV_INT_ENABLE_PDEV_HOTPLUG    (NV_INT_ENABLE_PDEV_ADDED | \
-                                       NV_INT_ENABLE_PDEV_REMOVED)
- #define NV_INT_ENABLE_SDEV_HOTPLUG    (NV_INT_ENABLE_SDEV_ADDED | \
-                                       NV_INT_ENABLE_SDEV_REMOVED)
- #define NV_INT_ENABLE_HOTPLUG         (NV_INT_ENABLE_PDEV_HOTPLUG | \
-                                       NV_INT_ENABLE_SDEV_HOTPLUG)
- #define NV_INT_CONFIG                 0x12
- #define NV_INT_CONFIG_METHD           0x01 // 0 = INT, 1 = SMI
- // For PCI config register 20
- #define NV_MCP_SATA_CFG_20            0x50
- #define NV_MCP_SATA_CFG_20_SATA_SPACE_EN      0x04
+ enum {
+       NV_PORTS                        = 2,
+       NV_PIO_MASK                     = 0x1f,
+       NV_MWDMA_MASK                   = 0x07,
+       NV_UDMA_MASK                    = 0x7f,
+       NV_PORT0_SCR_REG_OFFSET         = 0x00,
+       NV_PORT1_SCR_REG_OFFSET         = 0x40,
+       NV_INT_STATUS                   = 0x10,
+       NV_INT_STATUS_CK804             = 0x440,
+       NV_INT_STATUS_PDEV_INT          = 0x01,
+       NV_INT_STATUS_PDEV_PM           = 0x02,
+       NV_INT_STATUS_PDEV_ADDED        = 0x04,
+       NV_INT_STATUS_PDEV_REMOVED      = 0x08,
+       NV_INT_STATUS_SDEV_INT          = 0x10,
+       NV_INT_STATUS_SDEV_PM           = 0x20,
+       NV_INT_STATUS_SDEV_ADDED        = 0x40,
+       NV_INT_STATUS_SDEV_REMOVED      = 0x80,
+       NV_INT_STATUS_PDEV_HOTPLUG      = (NV_INT_STATUS_PDEV_ADDED |
+                                          NV_INT_STATUS_PDEV_REMOVED),
+       NV_INT_STATUS_SDEV_HOTPLUG      = (NV_INT_STATUS_SDEV_ADDED |
+                                          NV_INT_STATUS_SDEV_REMOVED),
+       NV_INT_STATUS_HOTPLUG           = (NV_INT_STATUS_PDEV_HOTPLUG |
+                                          NV_INT_STATUS_SDEV_HOTPLUG),
+       NV_INT_ENABLE                   = 0x11,
+       NV_INT_ENABLE_CK804             = 0x441,
+       NV_INT_ENABLE_PDEV_MASK         = 0x01,
+       NV_INT_ENABLE_PDEV_PM           = 0x02,
+       NV_INT_ENABLE_PDEV_ADDED        = 0x04,
+       NV_INT_ENABLE_PDEV_REMOVED      = 0x08,
+       NV_INT_ENABLE_SDEV_MASK         = 0x10,
+       NV_INT_ENABLE_SDEV_PM           = 0x20,
+       NV_INT_ENABLE_SDEV_ADDED        = 0x40,
+       NV_INT_ENABLE_SDEV_REMOVED      = 0x80,
+       NV_INT_ENABLE_PDEV_HOTPLUG      = (NV_INT_ENABLE_PDEV_ADDED |
+                                          NV_INT_ENABLE_PDEV_REMOVED),
+       NV_INT_ENABLE_SDEV_HOTPLUG      = (NV_INT_ENABLE_SDEV_ADDED |
+                                          NV_INT_ENABLE_SDEV_REMOVED),
+       NV_INT_ENABLE_HOTPLUG           = (NV_INT_ENABLE_PDEV_HOTPLUG |
+                                          NV_INT_ENABLE_SDEV_HOTPLUG),
+       NV_INT_CONFIG                   = 0x12,
+       NV_INT_CONFIG_METHD             = 0x01, // 0 = INT, 1 = SMI
+       // For PCI config register 20
+       NV_MCP_SATA_CFG_20              = 0x50,
+       NV_MCP_SATA_CFG_20_SATA_SPACE_EN = 0x04,
+ };
  
  static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
  static irqreturn_t nv_interrupt (int irq, void *dev_instance,
@@@ -175,8 -149,6 +149,6 @@@ static const struct pci_device_id nv_pc
        { 0, } /* terminate list */
  };
  
- #define NV_HOST_FLAGS_SCR_MMIO        0x00000001
  struct nv_host_desc
  {
        enum nv_host_type       host_type;
@@@ -229,7 -201,6 +201,6 @@@ static struct scsi_host_template nv_sh
        .name                   = DRV_NAME,
        .ioctl                  = ata_scsi_ioctl,
        .queuecommand           = ata_scsi_queuecmd,
-       .eh_timed_out           = ata_scsi_timed_out,
        .eh_strategy_handler    = ata_scsi_error,
        .can_queue              = ATA_DEF_QUEUE,
        .this_id                = ATA_SHT_THIS_ID,
@@@ -309,11 -280,11 +280,11 @@@ static irqreturn_t nv_interrupt (int ir
  
                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)))
                                handled += ata_host_intr(ap, qc);
                        else
                                // No request pending?  Clear interrupt status
  
  static u32 nv_scr_read (struct ata_port *ap, unsigned int sc_reg)
  {
-       struct ata_host_set *host_set = ap->host_set;
-       struct nv_host *host = host_set->private_data;
        if (sc_reg > SCR_CONTROL)
                return 0xffffffffU;
  
-       if (host->host_flags & NV_HOST_FLAGS_SCR_MMIO)
-               return readl((void __iomem *)ap->ioaddr.scr_addr + (sc_reg * 4));
-       else
-               return inl(ap->ioaddr.scr_addr + (sc_reg * 4));
+       return ioread32((void __iomem *)ap->ioaddr.scr_addr + (sc_reg * 4));
  }
  
  static void nv_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
  {
-       struct ata_host_set *host_set = ap->host_set;
-       struct nv_host *host = host_set->private_data;
        if (sc_reg > SCR_CONTROL)
                return;
  
-       if (host->host_flags & NV_HOST_FLAGS_SCR_MMIO)
-               writel(val, (void __iomem *)ap->ioaddr.scr_addr + (sc_reg * 4));
-       else
-               outl(val, ap->ioaddr.scr_addr + (sc_reg * 4));
+       iowrite32(val, (void __iomem *)ap->ioaddr.scr_addr + (sc_reg * 4));
  }
  
  static void nv_host_stop (struct ata_host_set *host_set)
  {
        struct nv_host *host = host_set->private_data;
-       struct pci_dev *pdev = to_pci_dev(host_set->dev);
  
        // Disable hotplug event interrupts.
        if (host->host_desc->disable_hotplug)
  
        kfree(host);
  
-       if (host_set->mmio_base)
-               pci_iounmap(pdev, host_set->mmio_base);
+       ata_pci_host_stop(host_set);
  }
  
  static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
        int pci_dev_busy = 0;
        int rc;
        u32 bar;
+       unsigned long base;
  
          // Make sure this is a SATA controller by counting the number of bars
          // (NVIDIA SATA controllers will always have six bars).  Otherwise,
  
        probe_ent->private_data = host;
  
-       if (pci_resource_flags(pdev, 5) & IORESOURCE_MEM)
-               host->host_flags |= NV_HOST_FLAGS_SCR_MMIO;
-       if (host->host_flags & NV_HOST_FLAGS_SCR_MMIO) {
-               unsigned long base;
-               probe_ent->mmio_base = pci_iomap(pdev, 5, 0);
-               if (probe_ent->mmio_base == NULL) {
-                       rc = -EIO;
-                       goto err_out_free_host;
-               }
-               base = (unsigned long)probe_ent->mmio_base;
+       probe_ent->mmio_base = pci_iomap(pdev, 5, 0);
+       if (!probe_ent->mmio_base) {
+               rc = -EIO;
+               goto err_out_free_host;
+       }
  
-               probe_ent->port[0].scr_addr =
-                       base + NV_PORT0_SCR_REG_OFFSET;
-               probe_ent->port[1].scr_addr =
-                       base + NV_PORT1_SCR_REG_OFFSET;
-       } else {
+       base = (unsigned long)probe_ent->mmio_base;
  
-               probe_ent->port[0].scr_addr =
-                       pci_resource_start(pdev, 5) | NV_PORT0_SCR_REG_OFFSET;
-               probe_ent->port[1].scr_addr =
-                       pci_resource_start(pdev, 5) | NV_PORT1_SCR_REG_OFFSET;
-       }
+       probe_ent->port[0].scr_addr = base + NV_PORT0_SCR_REG_OFFSET;
+       probe_ent->port[1].scr_addr = base + NV_PORT1_SCR_REG_OFFSET;
  
        pci_set_master(pdev);
  
        return 0;
  
  err_out_iounmap:
-       if (host->host_flags & NV_HOST_FLAGS_SCR_MMIO)
-               pci_iounmap(pdev, probe_ent->mmio_base);
+       pci_iounmap(pdev, probe_ent->mmio_base);
  err_out_free_host:
        kfree(host);
  err_out_free_ent:
@@@ -76,8 -76,7 +76,8 @@@ enum 
        PDC_RESET               = (1 << 11), /* HDMA reset */
  
        PDC_COMMON_FLAGS        = ATA_FLAG_NO_LEGACY | ATA_FLAG_SRST |
 -                                ATA_FLAG_MMIO | ATA_FLAG_NO_ATAPI,
 +                                ATA_FLAG_MMIO | ATA_FLAG_NO_ATAPI |
 +                                ATA_FLAG_PIO_POLLING,
  };
  
  
@@@ -112,7 -111,6 +112,6 @@@ static struct scsi_host_template pdc_at
        .name                   = DRV_NAME,
        .ioctl                  = ata_scsi_ioctl,
        .queuecommand           = ata_scsi_queuecmd,
-       .eh_timed_out           = ata_scsi_timed_out,
        .eh_strategy_handler    = ata_scsi_error,
        .can_queue              = ATA_DEF_QUEUE,
        .this_id                = ATA_SHT_THIS_ID,
@@@ -536,11 -534,11 +535,11 @@@ static irqreturn_t pdc_interrupt (int i
                ap = host_set->ports[i];
                tmp = mask & (1 << (i + 1));
                if (tmp && 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)))
                                handled += pdc_host_intr(ap, qc);
                }
        }
@@@ -132,7 -132,6 +132,6 @@@ static struct scsi_host_template qs_ata
        .name                   = DRV_NAME,
        .ioctl                  = ata_scsi_ioctl,
        .queuecommand           = ata_scsi_queuecmd,
-       .eh_timed_out           = ata_scsi_timed_out,
        .eh_strategy_handler    = ata_scsi_error,
        .can_queue              = ATA_DEF_QUEUE,
        .this_id                = ATA_SHT_THIS_ID,
@@@ -177,7 -176,7 +176,7 @@@ static const struct ata_port_info qs_po
                .host_flags     = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
                                  ATA_FLAG_SATA_RESET |
                                  //FIXME ATA_FLAG_SRST |
 -                                ATA_FLAG_MMIO,
 +                                ATA_FLAG_MMIO | ATA_FLAG_PIO_POLLING,
                .pio_mask       = 0x10, /* pio4 */
                .udma_mask      = 0x7f, /* udma0-6 */
                .port_ops       = &qs_ata_ops,
@@@ -396,13 -395,14 +395,13 @@@ static inline unsigned int qs_intr_pkt(
                        DPRINTK("SFF=%08x%08x: sCHAN=%u sHST=%d sDST=%02x\n",
                                        sff1, sff0, port_no, sHST, sDST);
                        handled = 1;
 -                      if (ap && !(ap->flags &
 -                                  (ATA_FLAG_PORT_DISABLED|ATA_FLAG_NOINTR))) {
 +                      if (ap && !(ap->flags & ATA_FLAG_PORT_DISABLED)) {
                                struct ata_queued_cmd *qc;
                                struct qs_port_priv *pp = ap->private_data;
                                if (!pp || pp->state != qs_state_pkt)
                                        continue;
                                qc = ata_qc_from_tag(ap, ap->active_tag);
 -                              if (qc && (!(qc->tf.ctl & ATA_NIEN))) {
 +                              if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING))) {
                                        switch (sHST) {
                                        case 0: /* successful CPB */
                                        case 3: /* device error */
@@@ -429,13 -429,13 +428,13 @@@ static inline unsigned int qs_intr_mmio
                struct ata_port *ap;
                ap = host_set->ports[port_no];
                if (ap &&
 -                  !(ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR))) {
 +                  !(ap->flags & ATA_FLAG_PORT_DISABLED)) {
                        struct ata_queued_cmd *qc;
                        struct qs_port_priv *pp = ap->private_data;
                        if (!pp || pp->state != qs_state_mmio)
                                continue;
                        qc = ata_qc_from_tag(ap, ap->active_tag);
 -                      if (qc && (!(qc->tf.ctl & ATA_NIEN))) {
 +                      if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING))) {
  
                                /* check main status, clearing INTRQ */
                                u8 status = ata_check_status(ap);
diff --combined drivers/scsi/sata_sx4.c
@@@ -182,7 -182,6 +182,6 @@@ static struct scsi_host_template pdc_sa
        .name                   = DRV_NAME,
        .ioctl                  = ata_scsi_ioctl,
        .queuecommand           = ata_scsi_queuecmd,
-       .eh_timed_out           = ata_scsi_timed_out,
        .eh_strategy_handler    = ata_scsi_error,
        .can_queue              = ATA_DEF_QUEUE,
        .this_id                = ATA_SHT_THIS_ID,
@@@ -220,7 -219,7 +219,7 @@@ static const struct ata_port_info pdc_p
                .sht            = &pdc_sata_sht,
                .host_flags     = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
                                  ATA_FLAG_SRST | ATA_FLAG_MMIO |
 -                                ATA_FLAG_NO_ATAPI,
 +                                ATA_FLAG_PIO_POLLING,
                .pio_mask       = 0x1f, /* pio0-4 */
                .mwdma_mask     = 0x07, /* mwdma0-2 */
                .udma_mask      = 0x7f, /* udma0-6 ; FIXME */
@@@ -835,11 -834,11 +834,11 @@@ static irqreturn_t pdc20621_interrupt (
                tmp = mask & (1 << i);
                VPRINTK("seq %u, port_no %u, ap %p, tmp %x\n", i, port_no, ap, tmp);
                if (tmp && 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)))
                                handled += pdc20621_host_intr(ap, qc, (i > 4),
                                                              mmio_base);
                }
diff --combined drivers/scsi/sata_vsc.c
  #include <linux/libata.h>
  
  #define DRV_NAME      "sata_vsc"
- #define DRV_VERSION   "1.1"
- /* Interrupt register offsets (from chip base address) */
- #define VSC_SATA_INT_STAT_OFFSET      0x00
- #define VSC_SATA_INT_MASK_OFFSET      0x04
- /* Taskfile registers offsets */
- #define VSC_SATA_TF_CMD_OFFSET                0x00
- #define VSC_SATA_TF_DATA_OFFSET               0x00
- #define VSC_SATA_TF_ERROR_OFFSET      0x04
- #define VSC_SATA_TF_FEATURE_OFFSET    0x06
- #define VSC_SATA_TF_NSECT_OFFSET      0x08
- #define VSC_SATA_TF_LBAL_OFFSET               0x0c
- #define VSC_SATA_TF_LBAM_OFFSET               0x10
- #define VSC_SATA_TF_LBAH_OFFSET               0x14
- #define VSC_SATA_TF_DEVICE_OFFSET     0x18
- #define VSC_SATA_TF_STATUS_OFFSET     0x1c
- #define VSC_SATA_TF_COMMAND_OFFSET    0x1d
- #define VSC_SATA_TF_ALTSTATUS_OFFSET  0x28
- #define VSC_SATA_TF_CTL_OFFSET                0x29
- /* DMA base */
- #define VSC_SATA_UP_DESCRIPTOR_OFFSET 0x64
- #define VSC_SATA_UP_DATA_BUFFER_OFFSET        0x6C
- #define VSC_SATA_DMA_CMD_OFFSET               0x70
- /* SCRs base */
- #define VSC_SATA_SCR_STATUS_OFFSET    0x100
- #define VSC_SATA_SCR_ERROR_OFFSET     0x104
- #define VSC_SATA_SCR_CONTROL_OFFSET   0x108
- /* Port stride */
- #define VSC_SATA_PORT_OFFSET          0x200
- /* Error interrupt status bit offsets */
- #define VSC_SATA_INT_ERROR_E_OFFSET   2
- #define VSC_SATA_INT_ERROR_P_OFFSET   4
- #define VSC_SATA_INT_ERROR_T_OFFSET   5
- #define VSC_SATA_INT_ERROR_M_OFFSET   1
+ #define DRV_VERSION   "1.2"
+ enum {
+       /* Interrupt register offsets (from chip base address) */
+       VSC_SATA_INT_STAT_OFFSET        = 0x00,
+       VSC_SATA_INT_MASK_OFFSET        = 0x04,
+       /* Taskfile registers offsets */
+       VSC_SATA_TF_CMD_OFFSET          = 0x00,
+       VSC_SATA_TF_DATA_OFFSET         = 0x00,
+       VSC_SATA_TF_ERROR_OFFSET        = 0x04,
+       VSC_SATA_TF_FEATURE_OFFSET      = 0x06,
+       VSC_SATA_TF_NSECT_OFFSET        = 0x08,
+       VSC_SATA_TF_LBAL_OFFSET         = 0x0c,
+       VSC_SATA_TF_LBAM_OFFSET         = 0x10,
+       VSC_SATA_TF_LBAH_OFFSET         = 0x14,
+       VSC_SATA_TF_DEVICE_OFFSET       = 0x18,
+       VSC_SATA_TF_STATUS_OFFSET       = 0x1c,
+       VSC_SATA_TF_COMMAND_OFFSET      = 0x1d,
+       VSC_SATA_TF_ALTSTATUS_OFFSET    = 0x28,
+       VSC_SATA_TF_CTL_OFFSET          = 0x29,
+       /* DMA base */
+       VSC_SATA_UP_DESCRIPTOR_OFFSET   = 0x64,
+       VSC_SATA_UP_DATA_BUFFER_OFFSET  = 0x6C,
+       VSC_SATA_DMA_CMD_OFFSET         = 0x70,
+       /* SCRs base */
+       VSC_SATA_SCR_STATUS_OFFSET      = 0x100,
+       VSC_SATA_SCR_ERROR_OFFSET       = 0x104,
+       VSC_SATA_SCR_CONTROL_OFFSET     = 0x108,
+       /* Port stride */
+       VSC_SATA_PORT_OFFSET            = 0x200,
+       /* Error interrupt status bit offsets */
+       VSC_SATA_INT_ERROR_CRC          = 0x40,
+       VSC_SATA_INT_ERROR_T            = 0x20,
+       VSC_SATA_INT_ERROR_P            = 0x10,
+       VSC_SATA_INT_ERROR_R            = 0x8,
+       VSC_SATA_INT_ERROR_E            = 0x4,
+       VSC_SATA_INT_ERROR_M            = 0x2,
+       VSC_SATA_INT_PHY_CHANGE         = 0x1,
+       VSC_SATA_INT_ERROR = (VSC_SATA_INT_ERROR_CRC  | VSC_SATA_INT_ERROR_T | \
+                             VSC_SATA_INT_ERROR_P    | VSC_SATA_INT_ERROR_R | \
+                             VSC_SATA_INT_ERROR_E    | VSC_SATA_INT_ERROR_M | \
+                             VSC_SATA_INT_PHY_CHANGE),
+ };
  #define is_vsc_sata_int_err(port_idx, int_status) \
-        (int_status & ((1 << (VSC_SATA_INT_ERROR_E_OFFSET + (8 * port_idx))) | \
-                       (1 << (VSC_SATA_INT_ERROR_P_OFFSET + (8 * port_idx))) | \
-                       (1 << (VSC_SATA_INT_ERROR_T_OFFSET + (8 * port_idx))) | \
-                       (1 << (VSC_SATA_INT_ERROR_M_OFFSET + (8 * port_idx)))   \
-                      )\
-        )
+        (int_status & (VSC_SATA_INT_ERROR << (8 * port_idx)))
  
  
  static u32 vsc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg)
@@@ -215,26 -221,33 +221,41 @@@ static irqreturn_t vsc_sata_interrupt (
  
                        ap = host_set->ports[i];
  
-                       if (ap && !(ap->flags & ATA_FLAG_PORT_DISABLED)) {
 +                      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|ATA_FLAG_NOINTR))) {
                                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 {
-                                       printk(KERN_DEBUG "%s: ignoring interrupt(s)\n", __FUNCTION__);
+                               } else if (is_vsc_sata_int_err(i, int_status)) {
+                                       /*
+                                        * 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 
+                                        * later.
+                                        */
+                                       u32 err_status;
+                                       err_status = vsc_sata_scr_read(ap, SCR_ERROR);
+                                       printk(KERN_DEBUG "%s: clearing interrupt, "
+                                              "status %x; sata err status %x\n",
+                                              __FUNCTION__,
+                                              int_status, err_status);
+                                       vsc_sata_scr_write(ap, SCR_ERROR, err_status);
+                                       /* Clear interrupt status */
                                        ata_chk_status(ap);
                                        handled++;
                                }
                        }
                }
        }
@@@ -250,7 -263,6 +271,6 @@@ static struct scsi_host_template vsc_sa
        .name                   = DRV_NAME,
        .ioctl                  = ata_scsi_ioctl,
        .queuecommand           = ata_scsi_queuecmd,
-       .eh_timed_out           = ata_scsi_timed_out,
        .eh_strategy_handler    = ata_scsi_error,
        .can_queue              = ATA_DEF_QUEUE,
        .this_id                = ATA_SHT_THIS_ID,
diff --combined include/linux/ata.h
@@@ -146,6 -146,8 +146,8 @@@ enum 
        ATA_CMD_STANDBYNOW1     = 0xE0,
        ATA_CMD_IDLEIMMEDIATE   = 0xE1,
        ATA_CMD_INIT_DEV_PARAMS = 0x91,
+       ATA_CMD_READ_NATIVE_MAX = 0xF8,
+       ATA_CMD_READ_NATIVE_MAX_EXT = 0x27,
  
        /* SETFEATURES stuff */
        SETFEATURES_XFER        = 0x03,
        ATA_TFLAG_WRITE         = (1 << 3), /* data dir: host->dev==1 (write) */
        ATA_TFLAG_LBA           = (1 << 4), /* enable LBA */
        ATA_TFLAG_FUA           = (1 << 5), /* enable FUA */
 +      ATA_TFLAG_POLLING       = (1 << 6), /* set nIEN to 1 and use polling */
  };
  
  enum ata_tf_protocols {
        ATA_PROT_UNKNOWN,       /* unknown/invalid */
        ATA_PROT_NODATA,        /* no data */
        ATA_PROT_PIO,           /* PIO single sector */
-       ATA_PROT_PIO_MULT,      /* PIO multiple sector */
        ATA_PROT_DMA,           /* DMA */
        ATA_PROT_ATAPI,         /* packet command, PIO data xfer*/
        ATA_PROT_ATAPI_NODATA,  /* packet command, no data */
@@@ -248,18 -248,22 +249,22 @@@ struct ata_taskfile 
  };
  
  #define ata_id_is_ata(id)     (((id)[0] & (1 << 15)) == 0)
+ #define ata_id_is_cfa(id)     ((id)[0] == 0x848A)
  #define ata_id_is_sata(id)    ((id)[93] == 0)
  #define ata_id_rahead_enabled(id) ((id)[85] & (1 << 6))
  #define ata_id_wcache_enabled(id) ((id)[85] & (1 << 5))
+ #define ata_id_hpa_enabled(id)        ((id)[85] & (1 << 10))
  #define ata_id_has_fua(id)    ((id)[84] & (1 << 6))
  #define ata_id_has_flush(id)  ((id)[83] & (1 << 12))
  #define ata_id_has_flush_ext(id) ((id)[83] & (1 << 13))
  #define ata_id_has_lba48(id)  ((id)[83] & (1 << 10))
+ #define ata_id_has_hpa(id)    ((id)[82] & (1 << 10))
  #define ata_id_has_wcache(id) ((id)[82] & (1 << 5))
  #define ata_id_has_pm(id)     ((id)[82] & (1 << 3))
  #define ata_id_has_lba(id)    ((id)[49] & (1 << 9))
  #define ata_id_has_dma(id)    ((id)[49] & (1 << 8))
  #define ata_id_removeable(id) ((id)[0] & (1 << 7))
+ #define ata_id_has_dword_io(id)       ((id)[50] & (1 << 0))
  #define ata_id_u32(id,n)      \
        (((u32) (id)[(n) + 1] << 16) | ((u32) (id)[(n)]))
  #define ata_id_u64(id,n)      \
          ((u64) (id)[(n) + 1] << 16) | \
          ((u64) (id)[(n) + 0]) )
  
 +#define ata_id_cdb_intr(id)   (((id)[0] & 0x60) == 0x20)
 +
  static inline unsigned int ata_id_major_version(const u16 *id)
  {
        unsigned int mver;
@@@ -309,15 -311,6 +314,15 @@@ static inline int is_atapi_taskfile(con
               (tf->protocol == ATA_PROT_ATAPI_DMA);
  }
  
 +static inline int is_multi_taskfile(struct ata_taskfile *tf)
 +{
 +      return (tf->command == ATA_CMD_READ_MULTI) ||
 +             (tf->command == ATA_CMD_WRITE_MULTI) ||
 +             (tf->command == ATA_CMD_READ_MULTI_EXT) ||
 +             (tf->command == ATA_CMD_WRITE_MULTI_EXT) ||
 +             (tf->command == ATA_CMD_WRITE_MULTI_FUA_EXT);
 +}
 +
  static inline int ata_ok(u8 status)
  {
        return ((status & (ATA_BUSY | ATA_DRDY | ATA_DF | ATA_DRQ | ATA_ERR))
diff --combined include/linux/libata.h
@@@ -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_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 {
@@@ -507,13 -502,13 +507,13 @@@ extern int ata_pci_init_one (struct pci
  extern void ata_pci_remove_one (struct pci_dev *pdev);
  extern int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t state);
  extern int ata_pci_device_resume(struct pci_dev *pdev);
+ 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_host_set_remove(struct ata_host_set *host_set);
  extern int ata_scsi_detect(struct scsi_host_template *sht);
  extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg);
  extern int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *));
- extern enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd);
  extern int ata_scsi_error(struct Scsi_Host *host);
  extern void ata_eh_qc_complete(struct ata_queued_cmd *qc);
  extern void ata_eh_qc_retry(struct ata_queued_cmd *qc);
@@@ -548,6 -543,7 +548,7 @@@ extern void ata_port_stop (struct ata_p
  extern void ata_host_stop (struct ata_host_set *host_set);
  extern irqreturn_t ata_interrupt (int irq, void *dev_instance, struct pt_regs *regs);
  extern void ata_qc_prep(struct ata_queued_cmd *qc);
+ extern void ata_noop_qc_prep(struct ata_queued_cmd *qc);
  extern unsigned int ata_qc_issue_prot(struct ata_queued_cmd *qc);
  extern void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf,
                unsigned int buflen);
@@@ -614,7 -610,7 +615,7 @@@ extern void ata_pci_host_stop (struct a
  extern struct ata_probe_ent *
  ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port, int portmask);
  extern int pci_test_config_bits(struct pci_dev *pdev, const struct pci_bits *bits);
+ extern unsigned long ata_pci_default_filter(const struct ata_port *, struct ata_device *, unsigned long);
  #endif /* CONFIG_PCI */