]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/scsi/libata-core.c
Merge rsync://rsync.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[linux-2.6-omap-h63xx.git] / drivers / scsi / libata-core.c
index 99bae8369ab294b3983517a799b3e1738bcc762d..4f91b0dc572bb5b1aea66a6aed56df874808eac8 100644 (file)
@@ -82,6 +82,10 @@ int atapi_enabled = 0;
 module_param(atapi_enabled, int, 0444);
 MODULE_PARM_DESC(atapi_enabled, "Enable discovery of ATAPI devices (0=off, 1=on)");
 
+int libata_fua = 0;
+module_param_named(fua, libata_fua, int, 0444);
+MODULE_PARM_DESC(fua, "FUA support (0=off, 1=on)");
+
 MODULE_AUTHOR("Jeff Garzik");
 MODULE_DESCRIPTION("Library module for ATA devices");
 MODULE_LICENSE("GPL");
@@ -611,6 +615,10 @@ int ata_rwcmd_protocol(struct ata_queued_cmd *qc)
        if (dev->flags & ATA_DFLAG_PIO) {
                tf->protocol = ATA_PROT_PIO;
                index = dev->multi_count ? 0 : 8;
+       } else if (lba48 && (qc->ap->flags & ATA_FLAG_PIO_LBA48)) {
+               /* Unable to use DMA due to host limitation */
+               tf->protocol = ATA_PROT_PIO;
+               index = dev->multi_count ? 0 : 8;
        } else {
                tf->protocol = ATA_PROT_DMA;
                index = 16;
@@ -1051,18 +1059,22 @@ static unsigned int ata_pio_modes(const struct ata_device *adev)
 {
        u16 modes;
 
-       /* Usual case. Word 53 indicates word 88 is valid */
-       if (adev->id[ATA_ID_FIELD_VALID] & (1 << 2)) {
+       /* Usual case. Word 53 indicates word 64 is valid */
+       if (adev->id[ATA_ID_FIELD_VALID] & (1 << 1)) {
                modes = adev->id[ATA_ID_PIO_MODES] & 0x03;
                modes <<= 3;
                modes |= 0x7;
                return modes;
        }
 
-       /* If word 88 isn't valid then Word 51 holds the PIO timing number
-          for the maximum. Turn it into a mask and return it */
-       modes = (2 << (adev->id[ATA_ID_OLD_PIO_MODES] & 0xFF)) - 1 ;
+       /* If word 64 isn't valid then Word 51 high byte holds the PIO timing
+          number for the maximum. Turn it into a mask and return it */
+       modes = (2 << ((adev->id[ATA_ID_OLD_PIO_MODES] >> 8) & 0xFF)) - 1 ;
        return modes;
+       /* But wait.. there's more. Design your standards by committee and
+          you too can get a free iordy field to process. However its the 
+          speeds not the modes that are supported... Note drivers using the
+          timing API will get this right anyway */
 }
 
 struct ata_exec_internal_arg {
@@ -1164,6 +1176,39 @@ ata_exec_internal(struct ata_port *ap, struct ata_device *dev,
        return AC_ERR_OTHER;
 }
 
+/**
+ *     ata_pio_need_iordy      -       check if iordy needed
+ *     @adev: ATA device
+ *
+ *     Check if the current speed of the device requires IORDY. Used
+ *     by various controllers for chip configuration.
+ */
+
+unsigned int ata_pio_need_iordy(const struct ata_device *adev)
+{
+       int pio;
+       int speed = adev->pio_mode - XFER_PIO_0;
+
+       if (speed < 2)
+               return 0;
+       if (speed > 2)
+               return 1;
+               
+       /* If we have no drive specific rule, then PIO 2 is non IORDY */
+
+       if (adev->id[ATA_ID_FIELD_VALID] & 2) { /* EIDE */
+               pio = adev->id[ATA_ID_EIDE_PIO];
+               /* Is the speed faster than the drive allows non IORDY ? */
+               if (pio) {
+                       /* This is cycle times not frequency - watch the logic! */
+                       if (pio > 240)  /* PIO2 is 240nS per cycle */
+                               return 1;
+                       return 0;
+               }
+       }
+       return 0;
+}
+
 /**
  *     ata_dev_identify - obtain IDENTIFY x DEVICE page
  *     @ap: port on which device we wish to probe resides
@@ -1415,7 +1460,7 @@ void ata_dev_config(struct ata_port *ap, unsigned int i)
                ap->udma_mask &= ATA_UDMA5;
                ap->host->max_sectors = ATA_MAX_SECTORS;
                ap->host->hostt->max_sectors = ATA_MAX_SECTORS;
-               ap->device->flags |= ATA_DFLAG_LOCK_SECTORS;
+               ap->device[i].flags |= ATA_DFLAG_LOCK_SECTORS;
        }
 
        if (ap->ops->dev_config)
@@ -2473,7 +2518,7 @@ static void ata_sg_clean(struct ata_queued_cmd *qc)
        assert(sg != NULL);
 
        if (qc->flags & ATA_QCFLAG_SINGLE)
-               assert(qc->n_elem == 1);
+               assert(qc->n_elem <= 1);
 
        VPRINTK("unmapping %u sg elements\n", qc->n_elem);
 
@@ -2496,7 +2541,7 @@ static void ata_sg_clean(struct ata_queued_cmd *qc)
                        kunmap_atomic(addr, KM_IRQ0);
                }
        } else {
-               if (sg_dma_len(&sg[0]) > 0)
+               if (qc->n_elem)
                        dma_unmap_single(ap->host_set->dev,
                                sg_dma_address(&sg[0]), sg_dma_len(&sg[0]),
                                dir);
@@ -2529,7 +2574,7 @@ static void ata_fill_sg(struct ata_queued_cmd *qc)
        unsigned int idx;
 
        assert(qc->__sg != NULL);
-       assert(qc->n_elem > 0);
+       assert(qc->n_elem > 0 || qc->pad_len > 0);
 
        idx = 0;
        ata_for_each_sg(sg, qc) {
@@ -2674,6 +2719,7 @@ static int ata_sg_setup_one(struct ata_queued_cmd *qc)
        int dir = qc->dma_dir;
        struct scatterlist *sg = qc->__sg;
        dma_addr_t dma_address;
+       int trim_sg = 0;
 
        /* we must lengthen transfers to end on a 32-bit boundary */
        qc->pad_len = sg->length & 3;
@@ -2693,13 +2739,15 @@ static int ata_sg_setup_one(struct ata_queued_cmd *qc)
                sg_dma_len(psg) = ATA_DMA_PAD_SZ;
                /* trim sg */
                sg->length -= qc->pad_len;
+               if (sg->length == 0)
+                       trim_sg = 1;
 
                DPRINTK("padding done, sg->length=%u pad_len=%u\n",
                        sg->length, qc->pad_len);
        }
 
-       if (!sg->length) {
-               sg_dma_address(sg) = 0;
+       if (trim_sg) {
+               qc->n_elem--;
                goto skip_map;
        }
 
@@ -2712,9 +2760,9 @@ static int ata_sg_setup_one(struct ata_queued_cmd *qc)
        }
 
        sg_dma_address(sg) = dma_address;
-skip_map:
        sg_dma_len(sg) = sg->length;
 
+skip_map:
        DPRINTK("mapped buffer of %d bytes for %s\n", sg_dma_len(sg),
                qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read");
 
@@ -3056,10 +3104,21 @@ static void ata_pio_data_xfer(struct ata_port *ap, unsigned char *buf,
 static void ata_data_xfer(struct ata_port *ap, unsigned char *buf,
                          unsigned int buflen, int do_write)
 {
-       if (ap->flags & ATA_FLAG_MMIO)
-               ata_mmio_data_xfer(ap, buf, buflen, do_write);
-       else
-               ata_pio_data_xfer(ap, buf, buflen, do_write);
+       /* Make the crap hardware pay the costs not the good stuff */
+       if (unlikely(ap->flags & ATA_FLAG_IRQ_MASK)) {
+               unsigned long flags;
+               local_irq_save(flags);
+               if (ap->flags & ATA_FLAG_MMIO)
+                       ata_mmio_data_xfer(ap, buf, buflen, do_write);
+               else
+                       ata_pio_data_xfer(ap, buf, buflen, do_write);
+               local_irq_restore(flags);
+       } else {
+               if (ap->flags & ATA_FLAG_MMIO)
+                       ata_mmio_data_xfer(ap, buf, buflen, do_write);
+               else
+                       ata_pio_data_xfer(ap, buf, buflen, do_write);
+       }
 }
 
 /**
@@ -3305,11 +3364,12 @@ static void ata_pio_error(struct ata_port *ap)
 {
        struct ata_queued_cmd *qc;
 
-       printk(KERN_WARNING "ata%u: PIO error\n", ap->id);
-
        qc = ata_qc_from_tag(ap, ap->active_tag);
        assert(qc != NULL);
 
+       if (qc->tf.command != ATA_CMD_PACKET)
+               printk(KERN_WARNING "ata%u: PIO error\n", ap->id);
+
        /* make sure qc->err_mask is available to 
         * know what's wrong and recover
         */
@@ -5122,6 +5182,7 @@ EXPORT_SYMBOL_GPL(ata_dev_id_string);
 EXPORT_SYMBOL_GPL(ata_dev_config);
 EXPORT_SYMBOL_GPL(ata_scsi_simulate);
 
+EXPORT_SYMBOL_GPL(ata_pio_need_iordy);
 EXPORT_SYMBOL_GPL(ata_timing_compute);
 EXPORT_SYMBOL_GPL(ata_timing_merge);