Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'upstream-fixes' of master.kernel.org:/pub/scm/linux/kernel/git/jgarzik/libata-dev

+111 -77
+25 -6
drivers/scsi/ahci.c
··· 565 565 u32 tmp; 566 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 579 /* stop DMA */ 569 580 tmp = readl(port_mmio + PORT_CMD); 570 581 tmp &= ~PORT_CMD_START; ··· 613 602 tmp |= PORT_CMD_START; 614 603 writel(tmp, port_mmio + PORT_CMD); 615 604 readl(port_mmio + PORT_CMD); /* flush */ 616 - 617 - printk(KERN_WARNING "ata%u: error occurred, port reset\n", ap->id); 618 605 } 619 606 620 607 static void ahci_eng_timeout(struct ata_port *ap) ··· 623 614 struct ata_queued_cmd *qc; 624 615 unsigned long flags; 625 616 626 - DPRINTK("ENTER\n"); 617 + printk(KERN_WARNING "ata%u: handling error/timeout\n", ap->id); 627 618 628 619 spin_lock_irqsave(&host_set->lock, flags); 629 - 630 - ahci_intr_error(ap, readl(port_mmio + PORT_IRQ_STAT)); 631 620 632 621 qc = ata_qc_from_tag(ap, ap->active_tag); 633 622 if (!qc) { 634 623 printk(KERN_ERR "ata%u: BUG: timeout without command\n", 635 624 ap->id); 636 625 } else { 626 + ahci_intr_error(ap, readl(port_mmio + PORT_IRQ_STAT)); 627 + 637 628 /* hack alert! We cannot use the supplied completion 638 629 * function from inside the ->eh_strategy_handler() thread. 639 630 * libata is the only user of ->eh_strategy_handler() in ··· 668 659 } 669 660 670 661 if (status & PORT_IRQ_FATAL) { 662 + unsigned int err_mask; 663 + if (status & PORT_IRQ_TF_ERR) 664 + err_mask = AC_ERR_DEV; 665 + else if (status & PORT_IRQ_IF_ERR) 666 + err_mask = AC_ERR_ATA_BUS; 667 + else 668 + err_mask = AC_ERR_HOST_BUS; 669 + 670 + /* command processing has stopped due to error; restart */ 671 671 ahci_intr_error(ap, status); 672 + 672 673 if (qc) 673 - ata_qc_complete(qc, AC_ERR_OTHER); 674 + ata_qc_complete(qc, err_mask); 674 675 } 675 676 676 677 return 1;
+29 -35
drivers/scsi/libata-core.c
··· 1263 1263 } 1264 1264 1265 1265 /* ATAPI-specific feature tests */ 1266 - else { 1266 + else if (dev->class == ATA_DEV_ATAPI) { 1267 1267 if (ata_id_is_ata(dev->id)) /* sanity check */ 1268 1268 goto err_out_nosup; 1269 1269 ··· 2399 2399 if (qc->flags & ATA_QCFLAG_SINGLE) 2400 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 2404 /* if we padded the buffer out to 32-bit bound, and data 2405 2405 * xfer direction is from-device, we must copy from the ··· 2409 2409 pad_buf = ap->pad + (qc->tag * ATA_DMA_PAD_SZ); 2410 2410 2411 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 2414 /* restore last sg */ 2414 2415 sg[qc->orig_n_elem - 1].length += qc->pad_len; 2415 2416 if (pad_buf) { ··· 2420 2419 kunmap_atomic(psg->page, KM_IRQ0); 2421 2420 } 2422 2421 } else { 2423 - dma_unmap_single(ap->host_set->dev, sg_dma_address(&sg[0]), 2424 - sg_dma_len(&sg[0]), dir); 2422 + if (sg_dma_len(&sg[0]) > 0) 2423 + dma_unmap_single(ap->host_set->dev, 2424 + sg_dma_address(&sg[0]), sg_dma_len(&sg[0]), 2425 + dir); 2425 2426 /* restore sg */ 2426 2427 sg->length += qc->pad_len; 2427 2428 if (pad_buf) ··· 2622 2619 sg->length, qc->pad_len); 2623 2620 } 2624 2621 2622 + if (!sg->length) { 2623 + sg_dma_address(sg) = 0; 2624 + goto skip_map; 2625 + } 2626 + 2625 2627 dma_address = dma_map_single(ap->host_set->dev, qc->buf_virt, 2626 2628 sg->length, dir); 2627 2629 if (dma_mapping_error(dma_address)) { ··· 2636 2628 } 2637 2629 2638 2630 sg_dma_address(sg) = dma_address; 2631 + skip_map: 2639 2632 sg_dma_len(sg) = sg->length; 2640 2633 2641 2634 DPRINTK("mapped buffer of %d bytes for %s\n", sg_dma_len(sg), ··· 2664 2655 struct ata_port *ap = qc->ap; 2665 2656 struct scatterlist *sg = qc->__sg; 2666 2657 struct scatterlist *lsg = &sg[qc->n_elem - 1]; 2667 - int n_elem, dir; 2658 + int n_elem, pre_n_elem, dir, trim_sg = 0; 2668 2659 2669 2660 VPRINTK("ENTER, ata%u\n", ap->id); 2670 2661 assert(qc->flags & ATA_QCFLAG_SG); ··· 2698 2689 sg_dma_len(psg) = ATA_DMA_PAD_SZ; 2699 2690 /* trim last sg */ 2700 2691 lsg->length -= qc->pad_len; 2692 + if (lsg->length == 0) 2693 + trim_sg = 1; 2701 2694 2702 2695 DPRINTK("padding done, sg[%d].length=%u pad_len=%u\n", 2703 2696 qc->n_elem - 1, lsg->length, qc->pad_len); 2704 2697 } 2705 2698 2699 + pre_n_elem = qc->n_elem; 2700 + if (trim_sg && pre_n_elem) 2701 + pre_n_elem--; 2702 + 2703 + if (!pre_n_elem) { 2704 + n_elem = 0; 2705 + goto skip_map; 2706 + } 2707 + 2706 2708 dir = qc->dma_dir; 2707 - n_elem = dma_map_sg(ap->host_set->dev, sg, qc->n_elem, dir); 2709 + n_elem = dma_map_sg(ap->host_set->dev, sg, pre_n_elem, dir); 2708 2710 if (n_elem < 1) { 2709 2711 /* restore last sg */ 2710 2712 lsg->length += qc->pad_len; ··· 2724 2704 2725 2705 DPRINTK("%d sg elements mapped\n", n_elem); 2726 2706 2707 + skip_map: 2727 2708 qc->n_elem = n_elem; 2728 2709 2729 2710 return 0; ··· 3284 3263 { 3285 3264 struct ata_port *ap = qc->ap; 3286 3265 struct ata_host_set *host_set = ap->host_set; 3287 - struct ata_device *dev = qc->dev; 3288 3266 u8 host_stat = 0, drv_stat; 3289 3267 unsigned long flags; 3290 3268 3291 3269 DPRINTK("ENTER\n"); 3292 - 3293 - /* FIXME: doesn't this conflict with timeout handling? */ 3294 - if (qc->dev->class == ATA_DEV_ATAPI && qc->scsicmd) { 3295 - struct scsi_cmnd *cmd = qc->scsicmd; 3296 - 3297 - if (!(cmd->eh_eflags & SCSI_EH_CANCEL_CMD)) { 3298 - 3299 - /* finish completing original command */ 3300 - spin_lock_irqsave(&host_set->lock, flags); 3301 - __ata_qc_complete(qc); 3302 - spin_unlock_irqrestore(&host_set->lock, flags); 3303 - 3304 - atapi_request_sense(ap, dev, cmd); 3305 - 3306 - cmd->result = (CHECK_CONDITION << 1) | (DID_OK << 16); 3307 - scsi_finish_command(cmd); 3308 - 3309 - goto out; 3310 - } 3311 - } 3312 3270 3313 3271 spin_lock_irqsave(&host_set->lock, flags); 3314 3272 ··· 3327 3327 3328 3328 spin_unlock_irqrestore(&host_set->lock, flags); 3329 3329 3330 - out: 3331 3330 DPRINTK("EXIT\n"); 3332 3331 } 3333 3332 ··· 3410 3411 3411 3412 qc = ata_qc_new(ap); 3412 3413 if (qc) { 3413 - qc->__sg = NULL; 3414 - qc->flags = 0; 3415 3414 qc->scsicmd = NULL; 3416 3415 qc->ap = ap; 3417 3416 qc->dev = dev; 3418 - qc->cursect = qc->cursg = qc->cursg_ofs = 0; 3419 - qc->nsect = 0; 3420 - qc->nbytes = qc->curbytes = 0; 3421 3417 3422 - ata_tf_init(ap, &qc->tf, dev->devno); 3418 + ata_qc_reinit(qc); 3423 3419 } 3424 3420 3425 3421 return qc;
+43 -34
drivers/scsi/libata-scsi.c
··· 1955 1955 done(cmd); 1956 1956 } 1957 1957 1958 - void atapi_request_sense(struct ata_port *ap, struct ata_device *dev, 1959 - struct scsi_cmnd *cmd) 1958 + static int atapi_sense_complete(struct ata_queued_cmd *qc,unsigned int err_mask) 1960 1959 { 1961 - DECLARE_COMPLETION(wait); 1962 - struct ata_queued_cmd *qc; 1963 - unsigned long flags; 1964 - int rc; 1960 + if (err_mask && ((err_mask & AC_ERR_DEV) == 0)) 1961 + /* FIXME: not quite right; we don't want the 1962 + * translation of taskfile registers into 1963 + * a sense descriptors, since that's only 1964 + * correct for ATA, not ATAPI 1965 + */ 1966 + ata_gen_ata_desc_sense(qc); 1967 + 1968 + qc->scsidone(qc->scsicmd); 1969 + return 0; 1970 + } 1971 + 1972 + /* is it pointless to prefer PIO for "safety reasons"? */ 1973 + static inline int ata_pio_use_silly(struct ata_port *ap) 1974 + { 1975 + return (ap->flags & ATA_FLAG_PIO_DMA); 1976 + } 1977 + 1978 + static void atapi_request_sense(struct ata_queued_cmd *qc) 1979 + { 1980 + struct ata_port *ap = qc->ap; 1981 + struct scsi_cmnd *cmd = qc->scsicmd; 1965 1982 1966 1983 DPRINTK("ATAPI request sense\n"); 1967 1984 1968 - qc = ata_qc_new_init(ap, dev); 1969 - BUG_ON(qc == NULL); 1970 - 1971 1985 /* FIXME: is this needed? */ 1972 1986 memset(cmd->sense_buffer, 0, sizeof(cmd->sense_buffer)); 1987 + 1988 + ap->ops->tf_read(ap, &qc->tf); 1989 + 1990 + /* fill these in, for the case where they are -not- overwritten */ 1991 + cmd->sense_buffer[0] = 0x70; 1992 + cmd->sense_buffer[2] = qc->tf.feature >> 4; 1993 + 1994 + ata_qc_reinit(qc); 1973 1995 1974 1996 ata_sg_init_one(qc, cmd->sense_buffer, sizeof(cmd->sense_buffer)); 1975 1997 qc->dma_dir = DMA_FROM_DEVICE; ··· 2003 1981 qc->tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; 2004 1982 qc->tf.command = ATA_CMD_PACKET; 2005 1983 2006 - qc->tf.protocol = ATA_PROT_ATAPI; 2007 - qc->tf.lbam = (8 * 1024) & 0xff; 2008 - qc->tf.lbah = (8 * 1024) >> 8; 1984 + if (ata_pio_use_silly(ap)) { 1985 + qc->tf.protocol = ATA_PROT_ATAPI_DMA; 1986 + qc->tf.feature |= ATAPI_PKT_DMA; 1987 + } else { 1988 + qc->tf.protocol = ATA_PROT_ATAPI; 1989 + qc->tf.lbam = (8 * 1024) & 0xff; 1990 + qc->tf.lbah = (8 * 1024) >> 8; 1991 + } 2009 1992 qc->nbytes = SCSI_SENSE_BUFFERSIZE; 2010 1993 2011 - qc->waiting = &wait; 2012 - qc->complete_fn = ata_qc_complete_noop; 1994 + qc->complete_fn = atapi_sense_complete; 2013 1995 2014 - spin_lock_irqsave(&ap->host_set->lock, flags); 2015 - rc = ata_qc_issue(qc); 2016 - spin_unlock_irqrestore(&ap->host_set->lock, flags); 2017 - 2018 - if (rc) 2019 - ata_port_disable(ap); 2020 - else 2021 - wait_for_completion(&wait); 1996 + if (ata_qc_issue(qc)) 1997 + ata_qc_complete(qc, AC_ERR_OTHER); 2022 1998 2023 1999 DPRINTK("EXIT\n"); 2024 2000 } ··· 2028 2008 VPRINTK("ENTER, err_mask 0x%X\n", err_mask); 2029 2009 2030 2010 if (unlikely(err_mask & AC_ERR_DEV)) { 2031 - DPRINTK("request check condition\n"); 2032 - 2033 - /* FIXME: command completion with check condition 2034 - * but no sense causes the error handler to run, 2035 - * which then issues REQUEST SENSE, fills in the sense 2036 - * buffer, and completes the command (for the second 2037 - * time). We need to issue REQUEST SENSE some other 2038 - * way, to avoid completing the command twice. 2039 - */ 2040 2011 cmd->result = SAM_STAT_CHECK_CONDITION; 2041 - 2042 - qc->scsidone(cmd); 2043 - 2012 + atapi_request_sense(qc); 2044 2013 return 1; 2045 2014 } 2046 2015
-2
drivers/scsi/libata.h
··· 54 54 55 55 56 56 /* libata-scsi.c */ 57 - extern void atapi_request_sense(struct ata_port *ap, struct ata_device *dev, 58 - struct scsi_cmnd *cmd); 59 57 extern void ata_scsi_scan_host(struct ata_port *ap); 60 58 extern int ata_scsi_error(struct Scsi_Host *host); 61 59 extern unsigned int ata_scsiop_inq_std(struct ata_scsi_args *args, u8 *rbuf,
+14
include/linux/libata.h
··· 59 59 #define VPRINTK(fmt, args...) 60 60 #endif /* ATA_DEBUG */ 61 61 62 + #define BPRINTK(fmt, args...) if (ap->flags & ATA_FLAG_DEBUGMSG) printk(KERN_ERR "%s: " fmt, __FUNCTION__, ## args) 63 + 62 64 #ifdef ATA_NDEBUG 63 65 #define assert(expr) 64 66 #else ··· 121 119 ATA_FLAG_PIO_DMA = (1 << 8), /* PIO cmds via DMA */ 122 120 ATA_FLAG_NOINTR = (1 << 9), /* FIXME: Remove this once 123 121 * proper HSM is in place. */ 122 + ATA_FLAG_DEBUGMSG = (1 << 10), 124 123 125 124 ATA_QCFLAG_ACTIVE = (1 << 1), /* cmd not yet ack'd to scsi lyer */ 126 125 ATA_QCFLAG_SG = (1 << 3), /* have s/g table? */ ··· 660 657 tf->device = ATA_DEVICE_OBS; 661 658 else 662 659 tf->device = ATA_DEVICE_OBS | ATA_DEV1; 660 + } 661 + 662 + static inline void ata_qc_reinit(struct ata_queued_cmd *qc) 663 + { 664 + qc->__sg = NULL; 665 + qc->flags = 0; 666 + qc->cursect = qc->cursg = qc->cursg_ofs = 0; 667 + qc->nsect = 0; 668 + qc->nbytes = qc->curbytes = 0; 669 + 670 + ata_tf_init(qc->ap, &qc->tf, qc->dev->devno); 663 671 } 664 672 665 673