Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[sfrench/cifs-2.6.git] / drivers / ata / libata-core.c
index f8ec3896b793e21c14e5352c0589a11f22fa0c7b..667acd283364503c328fd4dcd7c1dbadc2ac5d85 100644 (file)
@@ -1037,7 +1037,7 @@ static unsigned int ata_id_xfermask(const u16 *id)
                 * the PIO timing number for the maximum. Turn it into
                 * a mask.
                 */
-               u8 mode = id[ATA_ID_OLD_PIO_MODES] & 0xFF;
+               u8 mode = (id[ATA_ID_OLD_PIO_MODES] >> 8) & 0xFF;
                if (mode < 5)   /* Valid PIO range */
                        pio_mask = (2 << mode) - 1;
                else
@@ -1081,7 +1081,7 @@ static unsigned int ata_id_xfermask(const u16 *id)
  *     ata_port_queue_task - Queue port_task
  *     @ap: The ata_port to queue port_task for
  *     @fn: workqueue function to be scheduled
- *     @data: data value to pass to workqueue function
+ *     @data: data for @fn to use
  *     @delay: delay time for workqueue function
  *
  *     Schedule @fn(@data) for execution after @delay jiffies using
@@ -1096,7 +1096,7 @@ static unsigned int ata_id_xfermask(const u16 *id)
  *     LOCKING:
  *     Inherited from caller.
  */
-void ata_port_queue_task(struct ata_port *ap, void (*fn)(void *), void *data,
+void ata_port_queue_task(struct ata_port *ap, work_func_t fn, void *data,
                         unsigned long delay)
 {
        int rc;
@@ -1104,12 +1104,10 @@ void ata_port_queue_task(struct ata_port *ap, void (*fn)(void *), void *data,
        if (ap->pflags & ATA_PFLAG_FLUSH_PORT_TASK)
                return;
 
-       PREPARE_WORK(&ap->port_task, fn, data);
+       PREPARE_DELAYED_WORK(&ap->port_task, fn);
+       ap->port_task_data = data;
 
-       if (!delay)
-               rc = queue_work(ata_wq, &ap->port_task);
-       else
-               rc = queue_delayed_work(ata_wq, &ap->port_task, delay);
+       rc = queue_delayed_work(ata_wq, &ap->port_task, delay);
 
        /* rc == 0 means that another user is using port task */
        WARN_ON(rc == 0);
@@ -1252,6 +1250,7 @@ unsigned ata_exec_internal_sg(struct ata_device *dev,
 
                ata_sg_init(qc, sg, n_elem);
                qc->nsect = buflen / ATA_SECT_SIZE;
+               qc->nbytes = buflen;
        }
 
        qc->private_data = &wait;
@@ -1334,7 +1333,7 @@ unsigned ata_exec_internal_sg(struct ata_device *dev,
 }
 
 /**
- *     ata_exec_internal_sg - execute libata internal command
+ *     ata_exec_internal - execute libata internal command
  *     @dev: Device to which the command is sent
  *     @tf: Taskfile registers for the command and the result
  *     @cdb: CDB for packet command
@@ -1355,11 +1354,17 @@ unsigned ata_exec_internal(struct ata_device *dev,
                           struct ata_taskfile *tf, const u8 *cdb,
                           int dma_dir, void *buf, unsigned int buflen)
 {
-       struct scatterlist sg;
+       struct scatterlist *psg = NULL, sg;
+       unsigned int n_elem = 0;
 
-       sg_init_one(&sg, buf, buflen);
+       if (dma_dir != DMA_NONE) {
+               WARN_ON(!buf);
+               sg_init_one(&sg, buf, buflen);
+               psg = &sg;
+               n_elem++;
+       }
 
-       return ata_exec_internal_sg(dev, tf, cdb, dma_dir, &sg, 1);
+       return ata_exec_internal_sg(dev, tf, cdb, dma_dir, psg, n_elem);
 }
 
 /**
@@ -2305,7 +2310,7 @@ int ata_timing_compute(struct ata_device *adev, unsigned short speed,
         * DMA cycle timing is slower/equal than the fastest PIO timing.
         */
 
-       if (speed > XFER_PIO_4) {
+       if (speed > XFER_PIO_6) {
                ata_timing_compute(adev, adev->pio_mode, &p, T, UT);
                ata_timing_merge(&p, t, t, ATA_TIMING_ALL);
        }
@@ -2427,18 +2432,8 @@ int ata_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev)
        int i, rc = 0, used_dma = 0, found = 0;
 
        /* has private set_mode? */
-       if (ap->ops->set_mode) {
-               /* FIXME: make ->set_mode handle no device case and
-                * return error code and failing device on failure.
-                */
-               for (i = 0; i < ATA_MAX_DEVICES; i++) {
-                       if (ata_dev_ready(&ap->device[i])) {
-                               ap->ops->set_mode(ap);
-                               break;
-                       }
-               }
-               return 0;
-       }
+       if (ap->ops->set_mode)
+               return ap->ops->set_mode(ap, r_failed_dev);
 
        /* step 1: calculate xfer_mask */
        for (i = 0; i < ATA_MAX_DEVICES; i++) {
@@ -4588,10 +4583,11 @@ fsm_start:
        return poll_next;
 }
 
-static void ata_pio_task(void *_data)
+static void ata_pio_task(struct work_struct *work)
 {
-       struct ata_queued_cmd *qc = _data;
-       struct ata_port *ap = qc->ap;
+       struct ata_port *ap =
+               container_of(work, struct ata_port, port_task.work);
+       struct ata_queued_cmd *qc = ap->port_task_data;
        u8 status;
        int poll_next;
 
@@ -4961,6 +4957,7 @@ unsigned int ata_qc_issue_prot(struct ata_queued_cmd *qc)
        if (ap->flags & ATA_FLAG_PIO_POLLING) {
                switch (qc->tf.protocol) {
                case ATA_PROT_PIO:
+               case ATA_PROT_NODATA:
                case ATA_PROT_ATAPI:
                case ATA_PROT_ATAPI_NODATA:
                        qc->tf.flags |= ATA_TFLAG_POLLING;
@@ -5635,9 +5632,9 @@ void ata_port_init(struct ata_port *ap, struct ata_host *host,
        ap->msg_enable = ATA_MSG_DRV | ATA_MSG_ERR | ATA_MSG_WARN;
 #endif
 
-       INIT_WORK(&ap->port_task, NULL, NULL);
-       INIT_WORK(&ap->hotplug_task, ata_scsi_hotplug, ap);
-       INIT_WORK(&ap->scsi_rescan_task, ata_scsi_dev_rescan, ap);
+       INIT_DELAYED_WORK(&ap->port_task, NULL);
+       INIT_DELAYED_WORK(&ap->hotplug_task, ata_scsi_hotplug);
+       INIT_WORK(&ap->scsi_rescan_task, ata_scsi_dev_rescan);
        INIT_LIST_HEAD(&ap->eh_done_q);
        init_waitqueue_head(&ap->eh_wait_q);