aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/scsi/ahci.c31
-rw-r--r--drivers/scsi/libata-core.c64
-rw-r--r--drivers/scsi/libata-scsi.c77
-rw-r--r--drivers/scsi/libata.h2
-rw-r--r--include/linux/libata.h14
5 files changed, 111 insertions, 77 deletions
diff --git a/drivers/scsi/ahci.c b/drivers/scsi/ahci.c
index 4e96ec5f2ff9..894e7113e0b3 100644
--- a/drivers/scsi/ahci.c
+++ b/drivers/scsi/ahci.c
@@ -565,6 +565,17 @@ static void ahci_intr_error(struct ata_port *ap, u32 irq_stat)
565 u32 tmp; 565 u32 tmp;
566 int work; 566 int work;
567 567
568 printk(KERN_WARNING "ata%u: port reset, "
569 "p_is %x is %x pis %x cmd %x tf %x ss %x se %x\n",
570 ap->id,
571 irq_stat,
572 readl(mmio + HOST_IRQ_STAT),
573 readl(port_mmio + PORT_IRQ_STAT),
574 readl(port_mmio + PORT_CMD),
575 readl(port_mmio + PORT_TFDATA),
576 readl(port_mmio + PORT_SCR_STAT),
577 readl(port_mmio + PORT_SCR_ERR));
578
568 /* stop DMA */ 579 /* stop DMA */
569 tmp = readl(port_mmio + PORT_CMD); 580 tmp = readl(port_mmio + PORT_CMD);
570 tmp &= ~PORT_CMD_START; 581 tmp &= ~PORT_CMD_START;
@@ -602,8 +613,6 @@ static void ahci_intr_error(struct ata_port *ap, u32 irq_stat)
602 tmp |= PORT_CMD_START; 613 tmp |= PORT_CMD_START;
603 writel(tmp, port_mmio + PORT_CMD); 614 writel(tmp, port_mmio + PORT_CMD);
604 readl(port_mmio + PORT_CMD); /* flush */ 615 readl(port_mmio + PORT_CMD); /* flush */
605
606 printk(KERN_WARNING "ata%u: error occurred, port reset\n", ap->id);
607} 616}
608 617
609static void ahci_eng_timeout(struct ata_port *ap) 618static void ahci_eng_timeout(struct ata_port *ap)
@@ -614,17 +623,17 @@ static void ahci_eng_timeout(struct ata_port *ap)
614 struct ata_queued_cmd *qc; 623 struct ata_queued_cmd *qc;
615 unsigned long flags; 624 unsigned long flags;
616 625
617 DPRINTK("ENTER\n"); 626 printk(KERN_WARNING "ata%u: handling error/timeout\n", ap->id);
618 627
619 spin_lock_irqsave(&host_set->lock, flags); 628 spin_lock_irqsave(&host_set->lock, flags);
620 629
621 ahci_intr_error(ap, readl(port_mmio + PORT_IRQ_STAT));
622
623 qc = ata_qc_from_tag(ap, ap->active_tag); 630 qc = ata_qc_from_tag(ap, ap->active_tag);
624 if (!qc) { 631 if (!qc) {
625 printk(KERN_ERR "ata%u: BUG: timeout without command\n", 632 printk(KERN_ERR "ata%u: BUG: timeout without command\n",
626 ap->id); 633 ap->id);
627 } else { 634 } else {
635 ahci_intr_error(ap, readl(port_mmio + PORT_IRQ_STAT));
636
628 /* hack alert! We cannot use the supplied completion 637 /* hack alert! We cannot use the supplied completion
629 * function from inside the ->eh_strategy_handler() thread. 638 * function from inside the ->eh_strategy_handler() thread.
630 * libata is the only user of ->eh_strategy_handler() in 639 * libata is the only user of ->eh_strategy_handler() in
@@ -659,9 +668,19 @@ static inline int ahci_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc)
659 } 668 }
660 669
661 if (status & PORT_IRQ_FATAL) { 670 if (status & PORT_IRQ_FATAL) {
671 unsigned int err_mask;
672 if (status & PORT_IRQ_TF_ERR)
673 err_mask = AC_ERR_DEV;
674 else if (status & PORT_IRQ_IF_ERR)
675 err_mask = AC_ERR_ATA_BUS;
676 else
677 err_mask = AC_ERR_HOST_BUS;
678
679 /* command processing has stopped due to error; restart */
662 ahci_intr_error(ap, status); 680 ahci_intr_error(ap, status);
681
663 if (qc) 682 if (qc)
664 ata_qc_complete(qc, AC_ERR_OTHER); 683 ata_qc_complete(qc, err_mask);
665 } 684 }
666 685
667 return 1; 686 return 1;
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index d81db3a3d4b9..ba1eb8b38e00 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -1263,7 +1263,7 @@ retry:
1263 } 1263 }
1264 1264
1265 /* ATAPI-specific feature tests */ 1265 /* ATAPI-specific feature tests */
1266 else { 1266 else if (dev->class == ATA_DEV_ATAPI) {
1267 if (ata_id_is_ata(dev->id)) /* sanity check */ 1267 if (ata_id_is_ata(dev->id)) /* sanity check */
1268 goto err_out_nosup; 1268 goto err_out_nosup;
1269 1269
@@ -2399,7 +2399,7 @@ static void ata_sg_clean(struct ata_queued_cmd *qc)
2399 if (qc->flags & ATA_QCFLAG_SINGLE) 2399 if (qc->flags & ATA_QCFLAG_SINGLE)
2400 assert(qc->n_elem == 1); 2400 assert(qc->n_elem == 1);
2401 2401
2402 DPRINTK("unmapping %u sg elements\n", qc->n_elem); 2402 VPRINTK("unmapping %u sg elements\n", qc->n_elem);
2403 2403
2404 /* if we padded the buffer out to 32-bit bound, and data 2404 /* if we padded the buffer out to 32-bit bound, and data
2405 * xfer direction is from-device, we must copy from the 2405 * xfer direction is from-device, we must copy from the
@@ -2409,7 +2409,8 @@ static void ata_sg_clean(struct ata_queued_cmd *qc)
2409 pad_buf = ap->pad + (qc->tag * ATA_DMA_PAD_SZ); 2409 pad_buf = ap->pad + (qc->tag * ATA_DMA_PAD_SZ);
2410 2410
2411 if (qc->flags & ATA_QCFLAG_SG) { 2411 if (qc->flags & ATA_QCFLAG_SG) {
2412 dma_unmap_sg(ap->host_set->dev, sg, qc->n_elem, dir); 2412 if (qc->n_elem)
2413 dma_unmap_sg(ap->host_set->dev, sg, qc->n_elem, dir);
2413 /* restore last sg */ 2414 /* restore last sg */
2414 sg[qc->orig_n_elem - 1].length += qc->pad_len; 2415 sg[qc->orig_n_elem - 1].length += qc->pad_len;
2415 if (pad_buf) { 2416 if (pad_buf) {
@@ -2419,8 +2420,10 @@ static void ata_sg_clean(struct ata_queued_cmd *qc)
2419 kunmap_atomic(psg->page, KM_IRQ0); 2420 kunmap_atomic(psg->page, KM_IRQ0);
2420 } 2421 }
2421 } else { 2422 } else {
2422 dma_unmap_single(ap->host_set->dev, sg_dma_address(&sg[0]), 2423 if (sg_dma_len(&sg[0]) > 0)
2423 sg_dma_len(&sg[0]), dir); 2424 dma_unmap_single(ap->host_set->dev,
2425 sg_dma_address(&sg[0]), sg_dma_len(&sg[0]),
2426 dir);
2424 /* restore sg */ 2427 /* restore sg */
2425 sg->length += qc->pad_len; 2428 sg->length += qc->pad_len;
2426 if (pad_buf) 2429 if (pad_buf)
@@ -2619,6 +2622,11 @@ static int ata_sg_setup_one(struct ata_queued_cmd *qc)
2619 sg->length, qc->pad_len); 2622 sg->length, qc->pad_len);
2620 } 2623 }
2621 2624
2625 if (!sg->length) {
2626 sg_dma_address(sg) = 0;
2627 goto skip_map;
2628 }
2629
2622 dma_address = dma_map_single(ap->host_set->dev, qc->buf_virt, 2630 dma_address = dma_map_single(ap->host_set->dev, qc->buf_virt,
2623 sg->length, dir); 2631 sg->length, dir);
2624 if (dma_mapping_error(dma_address)) { 2632 if (dma_mapping_error(dma_address)) {
@@ -2628,6 +2636,7 @@ static int ata_sg_setup_one(struct ata_queued_cmd *qc)
2628 } 2636 }
2629 2637
2630 sg_dma_address(sg) = dma_address; 2638 sg_dma_address(sg) = dma_address;
2639skip_map:
2631 sg_dma_len(sg) = sg->length; 2640 sg_dma_len(sg) = sg->length;
2632 2641
2633 DPRINTK("mapped buffer of %d bytes for %s\n", sg_dma_len(sg), 2642 DPRINTK("mapped buffer of %d bytes for %s\n", sg_dma_len(sg),
@@ -2655,7 +2664,7 @@ static int ata_sg_setup(struct ata_queued_cmd *qc)
2655 struct ata_port *ap = qc->ap; 2664 struct ata_port *ap = qc->ap;
2656 struct scatterlist *sg = qc->__sg; 2665 struct scatterlist *sg = qc->__sg;
2657 struct scatterlist *lsg = &sg[qc->n_elem - 1]; 2666 struct scatterlist *lsg = &sg[qc->n_elem - 1];
2658 int n_elem, dir; 2667 int n_elem, pre_n_elem, dir, trim_sg = 0;
2659 2668
2660 VPRINTK("ENTER, ata%u\n", ap->id); 2669 VPRINTK("ENTER, ata%u\n", ap->id);
2661 assert(qc->flags & ATA_QCFLAG_SG); 2670 assert(qc->flags & ATA_QCFLAG_SG);
@@ -2689,13 +2698,24 @@ static int ata_sg_setup(struct ata_queued_cmd *qc)
2689 sg_dma_len(psg) = ATA_DMA_PAD_SZ; 2698 sg_dma_len(psg) = ATA_DMA_PAD_SZ;
2690 /* trim last sg */ 2699 /* trim last sg */
2691 lsg->length -= qc->pad_len; 2700 lsg->length -= qc->pad_len;
2701 if (lsg->length == 0)
2702 trim_sg = 1;
2692 2703
2693 DPRINTK("padding done, sg[%d].length=%u pad_len=%u\n", 2704 DPRINTK("padding done, sg[%d].length=%u pad_len=%u\n",
2694 qc->n_elem - 1, lsg->length, qc->pad_len); 2705 qc->n_elem - 1, lsg->length, qc->pad_len);
2695 } 2706 }
2696 2707
2708 pre_n_elem = qc->n_elem;
2709 if (trim_sg && pre_n_elem)
2710 pre_n_elem--;
2711