Merge branch 'upstream'
authorJeff Garzik <jgarzik@pobox.com>
Mon, 20 Feb 2006 10:13:31 +0000 (05:13 -0500)
committerJeff Garzik <jgarzik@pobox.com>
Mon, 20 Feb 2006 10:13:31 +0000 (05:13 -0500)
1  2 
drivers/scsi/libata-core.c
drivers/scsi/sata_mv.c
drivers/scsi/sata_vsc.c
include/linux/libata.h

index d1803c91b81fba6b18abba7eeab7244f69ff988e,76621463b4995248363065f8f75976fc28e01219..ed852348ba24e145e509f882347b9b0eedfeef1a
@@@ -62,7 -62,8 +62,8 @@@
  #include "libata.h"
  
  static void ata_dev_reread_id(struct ata_port *ap, struct ata_device *dev);
- static void ata_dev_init_params(struct ata_port *ap, struct ata_device *dev);
+ 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_get_mode_mask(const struct ata_port *ap, int shift);
@@@ -70,7 -71,6 +71,7 @@@ static int fgb(u32 bitmap)
  static int ata_choose_xfer_mode(const struct ata_port *ap,
                                u8 *xfer_mode_out,
                                unsigned int *xfer_shift_out);
 +static void ata_pio_error(struct ata_port *ap);
  
  static unsigned int ata_unique_id = 1;
  static struct workqueue_struct *ata_wq;
@@@ -487,7 -487,7 +488,7 @@@ ata_dev_try_classify(struct ata_port *a
  }
  
  /**
-  *    ata_dev_id_string - Convert IDENTIFY DEVICE page into string
+  *    ata_id_string - Convert IDENTIFY DEVICE page into string
   *    @id: IDENTIFY DEVICE results we will examine
   *    @s: string into which data is output
   *    @ofs: offset into identify device page
   *    caller.
   */
  
- void ata_dev_id_string(const u16 *id, unsigned char *s,
-                      unsigned int ofs, unsigned int len)
+ void ata_id_string(const u16 *id, unsigned char *s,
+                  unsigned int ofs, unsigned int len)
  {
        unsigned int c;
  
  }
  
  /**
-  *    ata_dev_id_c_string - Convert IDENTIFY DEVICE page into C string
+  *    ata_id_c_string - Convert IDENTIFY DEVICE page into C string
   *    @id: IDENTIFY DEVICE results we will examine
   *    @s: string into which data is output
   *    @ofs: offset into identify device page
   *    @len: length of string to return. must be an odd number.
   *
-  *    This function is identical to ata_dev_id_string except that it
+  *    This function is identical to ata_id_string except that it
   *    trims trailing spaces and terminates the resulting string with
   *    null.  @len must be actual maximum length (even number) + 1.
   *
   *    LOCKING:
   *    caller.
   */
- void ata_dev_id_c_string(const u16 *id, unsigned char *s,
-                        unsigned int ofs, unsigned int len)
+ void ata_id_c_string(const u16 *id, unsigned char *s,
+                    unsigned int ofs, unsigned int len)
  {
        unsigned char *p;
  
        WARN_ON(!(len & 1));
  
-       ata_dev_id_string(id, s, ofs, len - 1);
+       ata_id_string(id, s, ofs, len - 1);
  
        p = s + strnlen(s, len - 1);
        while (p > s && p[-1] == ' ')
@@@ -718,6 -718,13 +719,6 @@@ static unsigned int ata_pio_modes(cons
           timing API will get this right anyway */
  }
  
 -static inline void
 -ata_queue_packet_task(struct ata_port *ap)
 -{
 -      if (!(ap->flags & ATA_FLAG_FLUSH_PIO_TASK))
 -              queue_work(ata_wq, &ap->packet_task);
 -}
 -
  static inline void
  ata_queue_pio_task(struct ata_port *ap)
  {
@@@ -733,10 -740,10 +734,10 @@@ ata_queue_delayed_pio_task(struct ata_p
  }
  
  /**
 - *    ata_flush_pio_tasks - Flush pio_task and packet_task
 + *    ata_flush_pio_tasks - Flush pio_task
   *    @ap: the target ata_port
   *
 - *    After this function completes, pio_task and packet_task are
 + *    After this function completes, pio_task is
   *    guranteed not to be running or scheduled.
   *
   *    LOCKING:
@@@ -763,6 -770,7 +764,6 @@@ static void ata_flush_pio_tasks(struct 
         * Cancel and flush.
         */
        tmp |= cancel_delayed_work(&ap->pio_task);
 -      tmp |= cancel_delayed_work(&ap->packet_task);
        if (!tmp) {
                DPRINTK("flush #2\n");
                flush_workqueue(ata_wq);
@@@ -1034,7 -1042,12 +1035,12 @@@ retry
                 * Some drives were very specific about that exact sequence.
                 */
                if (major_version < 4 || (!ata_id_has_lba(dev->id))) {
-                       ata_dev_init_params(ap, dev);
+                       err_mask = ata_dev_init_params(ap, dev);
+                       if (err_mask) {
+                               printk(KERN_ERR "ata%u: failed to init "
+                                      "parameters, disabled\n", ap->id);
+                               goto err_out;
+                       }
  
                        /* current CHS translation info (id[53-58]) might be
                         * changed. reread the identify device info.
  
                }
  
 -              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 */
                printk(KERN_INFO "ata%u: dev %u ATAPI, max %s\n",
                       ap->id, device,
@@@ -2316,8 -2321,7 +2322,7 @@@ static int ata_dma_blacklisted(const st
        unsigned char model_num[41];
        int i;
  
-       ata_dev_id_c_string(dev->id, model_num, ATA_ID_PROD_OFS,
-                           sizeof(model_num));
+       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))
@@@ -2532,17 -2536,23 +2537,23 @@@ err_out
   *    @dev: Device to which command will be sent
   *
   *    LOCKING:
+  *    Kernel thread context (may sleep)
+  *
+  *    RETURNS:
+  *    0 on success, AC_ERR_* mask otherwise.
   */
  
- static void ata_dev_init_params(struct ata_port *ap, struct ata_device *dev)
+ static unsigned int ata_dev_init_params(struct ata_port *ap,
+                                       struct ata_device *dev)
  {
        struct ata_taskfile tf;
+       unsigned int err_mask;
        u16 sectors = dev->id[6];
        u16 heads   = dev->id[3];
  
        /* Number of sectors per track 1-255. Number of heads 1-16 */
        if (sectors < 1 || sectors > 255 || heads < 1 || heads > 16)
-               return;
+               return 0;
  
        /* set up init dev params taskfile */
        DPRINTK("init dev params \n");
        tf.nsect = sectors;
        tf.device |= (heads - 1) & 0x0f; /* max head = num. of heads - 1 */
  
-       if (ata_exec_internal(ap, dev, &tf, DMA_NONE, NULL, 0)) {
-               printk(KERN_ERR "ata%u: failed to init parameters, 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;
  }
  
  /**
@@@ -2932,6 -2939,7 +2940,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);
@@@ -2997,8 -3005,7 +3005,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;
  }
  
  
@@@ -3213,23 -3220,7 +3221,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;
 +
 +              WARN_ON(qc->dev->multi_count == 0);
 +
 +              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;
 +      }
  
 -      /* do the actual data transfer */
 -      do_write = (qc->tf.flags & ATA_TFLAG_WRITE);
 -      ata_data_xfer(ap, buf, ATA_SECT_SIZE, do_write);
 +      /* 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);
  
 -      kunmap(page);
 +      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 */
  }
  
  /**
@@@ -3450,23 -3302,7 +3458,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;
  }
@@@ -3513,8 -3356,6 +3521,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;
@@@ -3585,10 -3426,8 +3593,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)
@@@ -3615,23 -3454,22 +3623,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_queue_delayed_pio_task(ap, timeout);
 -      else if (!qc_completed)
 +      else if (has_next)
                goto fsm_start;
  }
  
@@@ -3709,10 -3543,8 +3717,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;
        }
  
@@@ -3939,104 -3771,43 +3947,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_queue_pio_task(ap);
 +
                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_queue_pio_task(ap);
 -              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_queue_packet_task(ap);
 +
 +              if (qc->tf.flags & ATA_TFLAG_WRITE) {
 +                      /* PIO data out protocol */
 +                      ap->hsm_task_state = HSM_ST_FIRST;
 +                      ata_queue_pio_task(ap);
 +
 +                      /* 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_queue_pio_task(ap);
 +
 +                      /* 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_queue_packet_task(ap);
 +
 +              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_queue_pio_task(ap);
                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_queue_packet_task(ap);
 +              ap->hsm_task_state = HSM_ST_FIRST;
 +
 +              /* send cdb by polling if no cdb interrupt */
 +              if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR))
 +                      ata_queue_pio_task(ap);
                break;
  
        default:
@@@ -4297,160 -4068,48 +4305,160 @@@ void ata_bmdma_stop(struct ata_queued_c
  inline unsigned int ata_host_intr (struct ata_port *ap,
                                   struct ata_queued_cmd *qc)
  {
 -      u8 status, host_stat;
 +      u8 status, host_stat = 0;
  
 -      switch (qc->tf.protocol) {
 +      VPRINTK("ata%u: protocol %d task_state %d\n",
 +              ap->id, qc->tf.protocol, ap->hsm_task_state);
  
 -      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);
 -
 -              /* 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;
        }
@@@ -4501,11 -4160,11 +4509,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);
                }
        return IRQ_RETVAL(handled);
  }
  
 -/**
 - *    atapi_packet_task - Write CDB bytes to hardware
 - *    @_data: Port to which ATAPI device is attached.
 - *
 - *    When device has indicated its readiness to accept
 - *    a CDB, this function is called.  Send the CDB.
 - *    If DMA is to be performed, exit immediately.
 - *    Otherwise, we are in polling mode, so poll
 - *    status under operation succeeds or fails.
 - *
 - *    LOCKING:
 - *    Kernel thread context (may sleep)
 - */
 -
 -static void atapi_packet_task(void *_data)
 -{
 -      struct ata_port *ap = _data;
 -      struct ata_queued_cmd *qc;
 -      u8 status;
 -
 -      qc = ata_qc_from_tag(ap, ap->active_tag);
 -      WARN_ON(qc == NULL);
 -      WARN_ON(!(qc->flags & ATA_QCFLAG_ACTIVE));
 -
 -      /* sleep-wait for BSY to clear */
 -      DPRINTK("busy wait\n");
 -      if (ata_busy_sleep(ap, ATA_TMOUT_CDB_QUICK, ATA_TMOUT_CDB)) {
 -              qc->err_mask |= AC_ERR_TIMEOUT;
 -              goto err_out;
 -      }
 -
 -      /* make sure DRQ is set */
 -      status = ata_chk_status(ap);
 -      if ((status & (ATA_BUSY | ATA_DRQ)) != ATA_DRQ) {
 -              qc->err_mask |= AC_ERR_HSM;
 -              goto err_out;
 -      }
 -
 -      /* send SCSI cdb */
 -      DPRINTK("send cdb\n");
 -      WARN_ON(qc->dev->cdb_len < 12);
 -
 -      if (qc->tf.protocol == ATA_PROT_ATAPI_DMA ||
 -          qc->tf.protocol == ATA_PROT_ATAPI_NODATA) {
 -              unsigned long flags;
 -
 -              /* Once we're done issuing command and kicking bmdma,
 -               * irq handler takes over.  To not lose irq, we need
 -               * to clear NOINTR flag before sending cdb, but
 -               * interrupt handler shouldn't be invoked before we're
 -               * finished.  Hence, the following locking.
 -               */
 -              spin_lock_irqsave(&ap->host_set->lock, flags);
 -              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 */
 -              spin_unlock_irqrestore(&ap->host_set->lock, flags);
 -      } else {
 -              ata_data_xfer(ap, qc->cdb, qc->dev->cdb_len, 1);
 -
 -              /* PIO commands are handled by polling */
 -              ap->hsm_task_state = HSM_ST;
 -              ata_queue_pio_task(ap);
 -      }
 -
 -      return;
 -
 -err_out:
 -      ata_poll_qc_complete(qc);
 -}
 -
 -
  /*
   * Execute a 'simple' command, that only consists of the opcode 'cmd' itself,
   * without filling any other registers
@@@ -4735,6 -4467,7 +4743,6 @@@ static void ata_host_init(struct ata_po
        ap->active_tag = ATA_TAG_POISON;
        ap->last_ctl = 0xFF;
  
 -      INIT_WORK(&ap->packet_task, atapi_packet_task, ap);
        INIT_WORK(&ap->pio_task, ata_pio_task, ap);
        INIT_LIST_HEAD(&ap->eh_done_q);
  
@@@ -5209,8 -4942,8 +5217,8 @@@ 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_dev_id_string);
- EXPORT_SYMBOL_GPL(ata_dev_id_c_string);
+ EXPORT_SYMBOL_GPL(ata_id_string);
+ EXPORT_SYMBOL_GPL(ata_id_c_string);
  EXPORT_SYMBOL_GPL(ata_dev_config);
  EXPORT_SYMBOL_GPL(ata_scsi_simulate);
  EXPORT_SYMBOL_GPL(ata_eh_qc_complete);
diff --combined drivers/scsi/sata_mv.c
index e05751e7aad4be0d04c7da0b5afb60fa87a03fa4,aceaf56999a55156a6dc4824174daaaedbc6a481..692c63bdcff89ad5049980bac8dec95a6477d26e
@@@ -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),
@@@ -1091,6 -1091,7 +1091,7 @@@ static void mv_qc_prep(struct ata_queue
        case ATA_CMD_READ_EXT:
        case ATA_CMD_WRITE:
        case ATA_CMD_WRITE_EXT:
+       case ATA_CMD_WRITE_FUA_EXT:
                mv_crqb_pack_cmd(cw++, tf->hob_nsect, ATA_REG_NSECT, 0);
                break;
  #ifdef LIBATA_NCQ             /* FIXME: remove this line when NCQ added */
@@@ -1387,7 -1388,8 +1388,7 @@@ static void mv_host_intr(struct ata_hos
                        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_vsc.c
index 976a6b124af94f7173629f12b9eff70992379098,b574379a7a82168542cbd6914dea268148c4fd76..2d448e84889cfceed5810a6f0fbe502fc2e7f9dd
  /* 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 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)))   \
+                      )\
+        )
  
  static u32 vsc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg)
  {
@@@ -201,13 -214,28 +214,27 @@@ static irqreturn_t vsc_sata_interrupt (
                        struct ata_port *ap;
  
                        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))) {
++                      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 {
+                                       printk(KERN_DEBUG "%s: ignoring interrupt(s)\n", __FUNCTION__);
+                                       ata_chk_status(ap);
+                                       handled++;
+                               }
                        }
                }
        }
diff --combined include/linux/libata.h
index 67d07c44b2e735a2a5fce8b15631cb8e1ac342b3,0d6bf50ad02958ca598aaf5bb4ba263e9cb93e64..63500881acc628ddbaf1db861e411e26e14ecd23
@@@ -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 {
@@@ -393,6 -388,8 +393,6 @@@ struct ata_port 
        struct ata_host_stats   stats;
        struct ata_host_set     *host_set;
  
 -      struct work_struct      packet_task;
 -
        struct work_struct      pio_task;
        unsigned int            hsm_task_state;
        unsigned long           pio_task_timeout;
@@@ -541,10 -538,10 +541,10 @@@ extern void ata_sg_init_one(struct ata_
  extern void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg,
                 unsigned int n_elem);
  extern unsigned int ata_dev_classify(const struct ata_taskfile *tf);
- extern void ata_dev_id_string(const u16 *id, unsigned char *s,
-                             unsigned int ofs, unsigned int len);
- extern void ata_dev_id_c_string(const u16 *id, unsigned char *s,
-                               unsigned int ofs, unsigned int len);
+ extern void ata_id_string(const u16 *id, unsigned char *s,
+                         unsigned int ofs, unsigned int len);
+ extern void ata_id_c_string(const u16 *id, unsigned char *s,
+                           unsigned int ofs, unsigned int len);
  extern void ata_dev_config(struct ata_port *ap, unsigned int i);
  extern void ata_bmdma_setup (struct ata_queued_cmd *qc);
  extern void ata_bmdma_start (struct ata_queued_cmd *qc);
This page took 0.04819 seconds and 5 git commands to generate.