aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/libata-core.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/libata-core.c')
-rw-r--r--drivers/scsi/libata-core.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index 46c4cdbaee86..5f1d7580218d 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -614,7 +614,7 @@ int ata_rwcmd_protocol(struct ata_queued_cmd *qc)
614 } else if (lba48 && (qc->ap->flags & ATA_FLAG_PIO_LBA48)) { 614 } else if (lba48 && (qc->ap->flags & ATA_FLAG_PIO_LBA48)) {
615 /* Unable to use DMA due to host limitation */ 615 /* Unable to use DMA due to host limitation */
616 tf->protocol = ATA_PROT_PIO; 616 tf->protocol = ATA_PROT_PIO;
617 index = dev->multi_count ? 0 : 4; 617 index = dev->multi_count ? 0 : 8;
618 } else { 618 } else {
619 tf->protocol = ATA_PROT_DMA; 619 tf->protocol = ATA_PROT_DMA;
620 index = 16; 620 index = 16;
@@ -2514,7 +2514,7 @@ static void ata_sg_clean(struct ata_queued_cmd *qc)
2514 assert(sg != NULL); 2514 assert(sg != NULL);
2515 2515
2516 if (qc->flags & ATA_QCFLAG_SINGLE) 2516 if (qc->flags & ATA_QCFLAG_SINGLE)
2517 assert(qc->n_elem == 1); 2517 assert(qc->n_elem <= 1);
2518 2518
2519 VPRINTK("unmapping %u sg elements\n", qc->n_elem); 2519 VPRINTK("unmapping %u sg elements\n", qc->n_elem);
2520 2520
@@ -2537,7 +2537,7 @@ static void ata_sg_clean(struct ata_queued_cmd *qc)
2537 kunmap_atomic(addr, KM_IRQ0); 2537 kunmap_atomic(addr, KM_IRQ0);
2538 } 2538 }
2539 } else { 2539 } else {
2540 if (sg_dma_len(&sg[0]) > 0) 2540 if (qc->n_elem)
2541 dma_unmap_single(ap->host_set->dev, 2541 dma_unmap_single(ap->host_set->dev,
2542 sg_dma_address(&sg[0]), sg_dma_len(&sg[0]), 2542 sg_dma_address(&sg[0]), sg_dma_len(&sg[0]),
2543 dir); 2543 dir);
@@ -2570,7 +2570,7 @@ static void ata_fill_sg(struct ata_queued_cmd *qc)
2570 unsigned int idx; 2570 unsigned int idx;
2571 2571
2572 assert(qc->__sg != NULL); 2572 assert(qc->__sg != NULL);
2573 assert(qc->n_elem > 0); 2573 assert(qc->n_elem > 0 || qc->pad_len > 0);
2574 2574
2575 idx = 0; 2575 idx = 0;
2576 ata_for_each_sg(sg, qc) { 2576 ata_for_each_sg(sg, qc) {
@@ -2715,6 +2715,7 @@ static int ata_sg_setup_one(struct ata_queued_cmd *qc)
2715 int dir = qc->dma_dir; 2715 int dir = qc->dma_dir;
2716 struct scatterlist *sg = qc->__sg; 2716 struct scatterlist *sg = qc->__sg;
2717 dma_addr_t dma_address; 2717 dma_addr_t dma_address;
2718 int trim_sg = 0;
2718 2719
2719 /* we must lengthen transfers to end on a 32-bit boundary */ 2720 /* we must lengthen transfers to end on a 32-bit boundary */
2720 qc->pad_len = sg->length & 3; 2721 qc->pad_len = sg->length & 3;
@@ -2734,13 +2735,15 @@ static int ata_sg_setup_one(struct ata_queued_cmd *qc)
2734 sg_dma_len(psg) = ATA_DMA_PAD_SZ; 2735 sg_dma_len(psg) = ATA_DMA_PAD_SZ;
2735 /* trim sg */ 2736 /* trim sg */
2736 sg->length -= qc->pad_len; 2737 sg->length -= qc->pad_len;
2738 if (sg->length == 0)
2739 trim_sg = 1;
2737 2740
2738 DPRINTK("padding done, sg->length=%u pad_len=%u\n", 2741 DPRINTK("padding done, sg->length=%u pad_len=%u\n",
2739 sg->length, qc->pad_len); 2742 sg->length, qc->pad_len);
2740 } 2743 }
2741 2744
2742 if (!sg->length) { 2745 if (trim_sg) {
2743 sg_dma_address(sg) = 0; 2746 qc->n_elem--;
2744 goto skip_map; 2747 goto skip_map;
2745 } 2748 }
2746 2749
@@ -2753,9 +2756,9 @@ static int ata_sg_setup_one(struct ata_queued_cmd *qc)
2753 } 2756 }
2754 2757
2755 sg_dma_address(sg) = dma_address; 2758 sg_dma_address(sg) = dma_address;
2756skip_map:
2757 sg_dma_len(sg) = sg->length; 2759 sg_dma_len(sg) = sg->length;
2758 2760
2761skip_map:
2759 DPRINTK("mapped buffer of %d bytes for %s\n", sg_dma_len(sg), 2762 DPRINTK("mapped buffer of %d bytes for %s\n", sg_dma_len(sg),
2760 qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read"); 2763 qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read");
2761 2764
@@ -3357,11 +3360,12 @@ static void ata_pio_error(struct ata_port *ap)
3357{ 3360{
3358 struct ata_queued_cmd *qc; 3361 struct ata_queued_cmd *qc;
3359 3362
3360 printk(KERN_WARNING "ata%u: PIO error\n", ap->id);
3361
3362 qc = ata_qc_from_tag(ap, ap->active_tag); 3363 qc = ata_qc_from_tag(ap, ap->active_tag);
3363 assert(qc != NULL); 3364 assert(qc != NULL);
3364 3365
3366 if (qc->tf.command != ATA_CMD_PACKET)
3367 printk(KERN_WARNING "ata%u: PIO error\n", ap->id);
3368
3365 /* make sure qc->err_mask is available to 3369 /* make sure qc->err_mask is available to
3366 * know what's wrong and recover 3370 * know what's wrong and recover
3367 */ 3371 */