diff options
author | Jeff Garzik <jgarzik@pobox.com> | 2005-08-29 19:24:43 -0400 |
---|---|---|
committer | Jeff Garzik <jgarzik@pobox.com> | 2005-08-29 19:24:43 -0400 |
commit | 76b2bf9b4dee2fb32ef17f5c84a99ce481a14be2 (patch) | |
tree | 49cd36d6e980044c2a88f2c14cdc9259e0f0f1b4 /drivers/scsi/libata-core.c | |
parent | 2fca877b68b2b4fc5b94277858a1bedd46017cde (diff) | |
parent | 8f3d17fb7bcb7c255197d11469fb5e9695c9d2f4 (diff) |
Merge libata branch 'chs-support' to latest upstream kernel.
Diffstat (limited to 'drivers/scsi/libata-core.c')
-rw-r--r-- | drivers/scsi/libata-core.c | 299 |
1 files changed, 238 insertions, 61 deletions
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c index 35b61d699f34..a872fad2326a 100644 --- a/drivers/scsi/libata-core.c +++ b/drivers/scsi/libata-core.c | |||
@@ -1,25 +1,35 @@ | |||
1 | /* | 1 | /* |
2 | libata-core.c - helper library for ATA | 2 | * libata-core.c - helper library for ATA |
3 | 3 | * | |
4 | Copyright 2003-2004 Red Hat, Inc. All rights reserved. | 4 | * Maintained by: Jeff Garzik <jgarzik@pobox.com> |
5 | Copyright 2003-2004 Jeff Garzik | 5 | * Please ALWAYS copy linux-ide@vger.kernel.org |
6 | 6 | * on emails. | |
7 | The contents of this file are subject to the Open | 7 | * |
8 | Software License version 1.1 that can be found at | 8 | * Copyright 2003-2004 Red Hat, Inc. All rights reserved. |
9 | http://www.opensource.org/licenses/osl-1.1.txt and is included herein | 9 | * Copyright 2003-2004 Jeff Garzik |
10 | by reference. | 10 | * |
11 | 11 | * | |
12 | Alternatively, the contents of this file may be used under the terms | 12 | * This program is free software; you can redistribute it and/or modify |
13 | of the GNU General Public License version 2 (the "GPL") as distributed | 13 | * it under the terms of the GNU General Public License as published by |
14 | in the kernel source COPYING file, in which case the provisions of | 14 | * the Free Software Foundation; either version 2, or (at your option) |
15 | the GPL are applicable instead of the above. If you wish to allow | 15 | * any later version. |
16 | the use of your version of this file only under the terms of the | 16 | * |
17 | GPL and not to allow others to use your version of this file under | 17 | * This program is distributed in the hope that it will be useful, |
18 | the OSL, indicate your decision by deleting the provisions above and | 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | replace them with the notice and other provisions required by the GPL. | 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20 | If you do not delete the provisions above, a recipient may use your | 20 | * GNU General Public License for more details. |
21 | version of this file under either the OSL or the GPL. | 21 | * |
22 | 22 | * You should have received a copy of the GNU General Public License | |
23 | * along with this program; see the file COPYING. If not, write to | ||
24 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | ||
25 | * | ||
26 | * | ||
27 | * libata documentation is available via 'make {ps|pdf}docs', | ||
28 | * as Documentation/DocBook/libata.* | ||
29 | * | ||
30 | * Hardware documentation available from http://www.t13.org/ and | ||
31 | * http://www.sata-io.org/ | ||
32 | * | ||
23 | */ | 33 | */ |
24 | 34 | ||
25 | #include <linux/config.h> | 35 | #include <linux/config.h> |
@@ -1342,12 +1352,12 @@ static inline u8 ata_dev_knobble(struct ata_port *ap) | |||
1342 | /** | 1352 | /** |
1343 | * ata_dev_config - Run device specific handlers and check for | 1353 | * ata_dev_config - Run device specific handlers and check for |
1344 | * SATA->PATA bridges | 1354 | * SATA->PATA bridges |
1345 | * @ap: Bus | 1355 | * @ap: Bus |
1346 | * @i: Device | 1356 | * @i: Device |
1347 | * | 1357 | * |
1348 | * LOCKING: | 1358 | * LOCKING: |
1349 | */ | 1359 | */ |
1350 | 1360 | ||
1351 | void ata_dev_config(struct ata_port *ap, unsigned int i) | 1361 | void ata_dev_config(struct ata_port *ap, unsigned int i) |
1352 | { | 1362 | { |
1353 | /* limit bridge transfers to udma5, 200 sectors */ | 1363 | /* limit bridge transfers to udma5, 200 sectors */ |
@@ -2463,6 +2473,27 @@ static int ata_sg_setup(struct ata_queued_cmd *qc) | |||
2463 | } | 2473 | } |
2464 | 2474 | ||
2465 | /** | 2475 | /** |
2476 | * ata_poll_qc_complete - turn irq back on and finish qc | ||
2477 | * @qc: Command to complete | ||
2478 | * @drv_stat: ATA status register content | ||
2479 | * | ||
2480 | * LOCKING: | ||
2481 | * None. (grabs host lock) | ||
2482 | */ | ||
2483 | |||
2484 | void ata_poll_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat) | ||
2485 | { | ||
2486 | struct ata_port *ap = qc->ap; | ||
2487 | unsigned long flags; | ||
2488 | |||
2489 | spin_lock_irqsave(&ap->host_set->lock, flags); | ||
2490 | ap->flags &= ~ATA_FLAG_NOINTR; | ||
2491 | ata_irq_on(ap); | ||
2492 | ata_qc_complete(qc, drv_stat); | ||
2493 | spin_unlock_irqrestore(&ap->host_set->lock, flags); | ||
2494 | } | ||
2495 | |||
2496 | /** | ||
2466 | * ata_pio_poll - | 2497 | * ata_pio_poll - |
2467 | * @ap: | 2498 | * @ap: |
2468 | * | 2499 | * |
@@ -2524,11 +2555,10 @@ static void ata_pio_complete (struct ata_port *ap) | |||
2524 | u8 drv_stat; | 2555 | u8 drv_stat; |
2525 | 2556 | ||
2526 | /* | 2557 | /* |
2527 | * This is purely hueristic. This is a fast path. | 2558 | * This is purely heuristic. This is a fast path. Sometimes when |
2528 | * Sometimes when we enter, BSY will be cleared in | 2559 | * we enter, BSY will be cleared in a chk-status or two. If not, |
2529 | * a chk-status or two. If not, the drive is probably seeking | 2560 | * the drive is probably seeking or something. Snooze for a couple |
2530 | * or something. Snooze for a couple msecs, then | 2561 | * msecs, then chk-status again. If still busy, fall back to |
2531 | * chk-status again. If still busy, fall back to | ||
2532 | * PIO_ST_POLL state. | 2562 | * PIO_ST_POLL state. |
2533 | */ | 2563 | */ |
2534 | drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 10); | 2564 | drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 10); |
@@ -2553,9 +2583,7 @@ static void ata_pio_complete (struct ata_port *ap) | |||
2553 | 2583 | ||
2554 | ap->pio_task_state = PIO_ST_IDLE; | 2584 | ap->pio_task_state = PIO_ST_IDLE; |
2555 | 2585 | ||
2556 | ata_irq_on(ap); | 2586 | ata_poll_qc_complete(qc, drv_stat); |
2557 | |||
2558 | ata_qc_complete(qc, drv_stat); | ||
2559 | } | 2587 | } |
2560 | 2588 | ||
2561 | 2589 | ||
@@ -2580,6 +2608,20 @@ void swap_buf_le16(u16 *buf, unsigned int buf_words) | |||
2580 | #endif /* __BIG_ENDIAN */ | 2608 | #endif /* __BIG_ENDIAN */ |
2581 | } | 2609 | } |
2582 | 2610 | ||
2611 | /** | ||
2612 | * ata_mmio_data_xfer - Transfer data by MMIO | ||
2613 | * @ap: port to read/write | ||
2614 | * @buf: data buffer | ||
2615 | * @buflen: buffer length | ||
2616 | * @do_write: read/write | ||
2617 | * | ||
2618 | * Transfer data from/to the device data register by MMIO. | ||
2619 | * | ||
2620 | * LOCKING: | ||
2621 | * Inherited from caller. | ||
2622 | * | ||
2623 | */ | ||
2624 | |||
2583 | static void ata_mmio_data_xfer(struct ata_port *ap, unsigned char *buf, | 2625 | static void ata_mmio_data_xfer(struct ata_port *ap, unsigned char *buf, |
2584 | unsigned int buflen, int write_data) | 2626 | unsigned int buflen, int write_data) |
2585 | { | 2627 | { |
@@ -2588,6 +2630,7 @@ static void ata_mmio_data_xfer(struct ata_port *ap, unsigned char *buf, | |||
2588 | u16 *buf16 = (u16 *) buf; | 2630 | u16 *buf16 = (u16 *) buf; |
2589 | void __iomem *mmio = (void __iomem *)ap->ioaddr.data_addr; | 2631 | void __iomem *mmio = (void __iomem *)ap->ioaddr.data_addr; |
2590 | 2632 | ||
2633 | /* Transfer multiple of 2 bytes */ | ||
2591 | if (write_data) { | 2634 | if (write_data) { |
2592 | for (i = 0; i < words; i++) | 2635 | for (i = 0; i < words; i++) |
2593 | writew(le16_to_cpu(buf16[i]), mmio); | 2636 | writew(le16_to_cpu(buf16[i]), mmio); |
@@ -2595,19 +2638,76 @@ static void ata_mmio_data_xfer(struct ata_port *ap, unsigned char *buf, | |||
2595 | for (i = 0; i < words; i++) | 2638 | for (i = 0; i < words; i++) |
2596 | buf16[i] = cpu_to_le16(readw(mmio)); | 2639 | buf16[i] = cpu_to_le16(readw(mmio)); |
2597 | } | 2640 | } |
2641 | |||
2642 | /* Transfer trailing 1 byte, if any. */ | ||
2643 | if (unlikely(buflen & 0x01)) { | ||
2644 | u16 align_buf[1] = { 0 }; | ||
2645 | unsigned char *trailing_buf = buf + buflen - 1; | ||
2646 | |||
2647 | if (write_data) { | ||
2648 | memcpy(align_buf, trailing_buf, 1); | ||
2649 | writew(le16_to_cpu(align_buf[0]), mmio); | ||
2650 | } else { | ||
2651 | align_buf[0] = cpu_to_le16(readw(mmio)); | ||
2652 | memcpy(trailing_buf, align_buf, 1); | ||
2653 | } | ||
2654 | } | ||
2598 | } | 2655 | } |
2599 | 2656 | ||
2657 | /** | ||
2658 | * ata_pio_data_xfer - Transfer data by PIO | ||
2659 | * @ap: port to read/write | ||
2660 | * @buf: data buffer | ||
2661 | * @buflen: buffer length | ||
2662 | * @do_write: read/write | ||
2663 | * | ||
2664 | * Transfer data from/to the device data register by PIO. | ||
2665 | * | ||
2666 | * LOCKING: | ||
2667 | * Inherited from caller. | ||
2668 | * | ||
2669 | */ | ||
2670 | |||
2600 | static void ata_pio_data_xfer(struct ata_port *ap, unsigned char *buf, | 2671 | static void ata_pio_data_xfer(struct ata_port *ap, unsigned char *buf, |
2601 | unsigned int buflen, int write_data) | 2672 | unsigned int buflen, int write_data) |
2602 | { | 2673 | { |
2603 | unsigned int dwords = buflen >> 1; | 2674 | unsigned int words = buflen >> 1; |
2604 | 2675 | ||
2676 | /* Transfer multiple of 2 bytes */ | ||
2605 | if (write_data) | 2677 | if (write_data) |
2606 | outsw(ap->ioaddr.data_addr, buf, dwords); | 2678 | outsw(ap->ioaddr.data_addr, buf, words); |
2607 | else | 2679 | else |
2608 | insw(ap->ioaddr.data_addr, buf, dwords); | 2680 | insw(ap->ioaddr.data_addr, buf, words); |
2681 | |||
2682 | /* Transfer trailing 1 byte, if any. */ | ||
2683 | if (unlikely(buflen & 0x01)) { | ||
2684 | u16 align_buf[1] = { 0 }; | ||
2685 | unsigned char *trailing_buf = buf + buflen - 1; | ||
2686 | |||
2687 | if (write_data) { | ||
2688 | memcpy(align_buf, trailing_buf, 1); | ||
2689 | outw(le16_to_cpu(align_buf[0]), ap->ioaddr.data_addr); | ||
2690 | } else { | ||
2691 | align_buf[0] = cpu_to_le16(inw(ap->ioaddr.data_addr)); | ||
2692 | memcpy(trailing_buf, align_buf, 1); | ||
2693 | } | ||
2694 | } | ||
2609 | } | 2695 | } |
2610 | 2696 | ||
2697 | /** | ||
2698 | * ata_data_xfer - Transfer data from/to the data register. | ||
2699 | * @ap: port to read/write | ||
2700 | * @buf: data buffer | ||
2701 | * @buflen: buffer length | ||
2702 | * @do_write: read/write | ||
2703 | * | ||
2704 | * Transfer data from/to the device data register. | ||
2705 | * | ||
2706 | * LOCKING: | ||
2707 | * Inherited from caller. | ||
2708 | * | ||
2709 | */ | ||
2710 | |||
2611 | static void ata_data_xfer(struct ata_port *ap, unsigned char *buf, | 2711 | static void ata_data_xfer(struct ata_port *ap, unsigned char *buf, |
2612 | unsigned int buflen, int do_write) | 2712 | unsigned int buflen, int do_write) |
2613 | { | 2713 | { |
@@ -2617,6 +2717,16 @@ static void ata_data_xfer(struct ata_port *ap, unsigned char *buf, | |||
2617 | ata_pio_data_xfer(ap, buf, buflen, do_write); | 2717 | ata_pio_data_xfer(ap, buf, buflen, do_write); |
2618 | } | 2718 | } |
2619 | 2719 | ||
2720 | /** | ||
2721 | * ata_pio_sector - Transfer ATA_SECT_SIZE (512 bytes) of data. | ||
2722 | * @qc: Command on going | ||
2723 | * | ||
2724 | * Transfer ATA_SECT_SIZE of data from/to the ATA device. | ||
2725 | * | ||
2726 | * LOCKING: | ||
2727 | * Inherited from caller. | ||
2728 | */ | ||
2729 | |||
2620 | static void ata_pio_sector(struct ata_queued_cmd *qc) | 2730 | static void ata_pio_sector(struct ata_queued_cmd *qc) |
2621 | { | 2731 | { |
2622 | int do_write = (qc->tf.flags & ATA_TFLAG_WRITE); | 2732 | int do_write = (qc->tf.flags & ATA_TFLAG_WRITE); |
@@ -2655,6 +2765,18 @@ static void ata_pio_sector(struct ata_queued_cmd *qc) | |||
2655 | kunmap(page); | 2765 | kunmap(page); |
2656 | } | 2766 | } |
2657 | 2767 | ||
2768 | /** | ||
2769 | * __atapi_pio_bytes - Transfer data from/to the ATAPI device. | ||
2770 | * @qc: Command on going | ||
2771 | * @bytes: number of bytes | ||
2772 | * | ||
2773 | * Transfer Transfer data from/to the ATAPI device. | ||
2774 | * | ||
2775 | * LOCKING: | ||
2776 | * Inherited from caller. | ||
2777 | * | ||
2778 | */ | ||
2779 | |||
2658 | static void __atapi_pio_bytes(struct ata_queued_cmd *qc, unsigned int bytes) | 2780 | static void __atapi_pio_bytes(struct ata_queued_cmd *qc, unsigned int bytes) |
2659 | { | 2781 | { |
2660 | int do_write = (qc->tf.flags & ATA_TFLAG_WRITE); | 2782 | int do_write = (qc->tf.flags & ATA_TFLAG_WRITE); |
@@ -2664,10 +2786,33 @@ static void __atapi_pio_bytes(struct ata_queued_cmd *qc, unsigned int bytes) | |||
2664 | unsigned char *buf; | 2786 | unsigned char *buf; |
2665 | unsigned int offset, count; | 2787 | unsigned int offset, count; |
2666 | 2788 | ||
2667 | if (qc->curbytes == qc->nbytes - bytes) | 2789 | if (qc->curbytes + bytes >= qc->nbytes) |
2668 | ap->pio_task_state = PIO_ST_LAST; | 2790 | ap->pio_task_state = PIO_ST_LAST; |
2669 | 2791 | ||
2670 | next_sg: | 2792 | next_sg: |
2793 | if (unlikely(qc->cursg >= qc->n_elem)) { | ||
2794 | /* | ||
2795 | * The end of qc->sg is reached and the device expects | ||
2796 | * more data to transfer. In order not to overrun qc->sg | ||
2797 | * and fulfill length specified in the byte count register, | ||
2798 | * - for read case, discard trailing data from the device | ||
2799 | * - for write case, padding zero data to the device | ||
2800 | */ | ||
2801 | u16 pad_buf[1] = { 0 }; | ||
2802 | unsigned int words = bytes >> 1; | ||
2803 | unsigned int i; | ||
2804 | |||
2805 | if (words) /* warning if bytes > 1 */ | ||
2806 | printk(KERN_WARNING "ata%u: %u bytes trailing data\n", | ||
2807 | ap->id, bytes); | ||
2808 | |||
2809 | for (i = 0; i < words; i++) | ||
2810 | ata_data_xfer(ap, (unsigned char*)pad_buf, 2, do_write); | ||
2811 | |||
2812 | ap->pio_task_state = PIO_ST_LAST; | ||
2813 | return; | ||
2814 | } | ||
2815 | |||
2671 | sg = &qc->sg[qc->cursg]; | 2816 | sg = &qc->sg[qc->cursg]; |
2672 | 2817 | ||
2673 | page = sg->page; | 2818 | page = sg->page; |
@@ -2701,11 +2846,21 @@ next_sg: | |||
2701 | 2846 | ||
2702 | kunmap(page); | 2847 | kunmap(page); |
2703 | 2848 | ||
2704 | if (bytes) { | 2849 | if (bytes) |
2705 | goto next_sg; | 2850 | goto next_sg; |
2706 | } | ||
2707 | } | 2851 | } |
2708 | 2852 | ||
2853 | /** | ||
2854 | * atapi_pio_bytes - Transfer data from/to the ATAPI device. | ||
2855 | * @qc: Command on going | ||
2856 | * | ||
2857 | * Transfer Transfer data from/to the ATAPI device. | ||
2858 | * | ||
2859 | * LOCKING: | ||
2860 | * Inherited from caller. | ||
2861 | * | ||
2862 | */ | ||
2863 | |||
2709 | static void atapi_pio_bytes(struct ata_queued_cmd *qc) | 2864 | static void atapi_pio_bytes(struct ata_queued_cmd *qc) |
2710 | { | 2865 | { |
2711 | struct ata_port *ap = qc->ap; | 2866 | struct ata_port *ap = qc->ap; |
@@ -2778,9 +2933,7 @@ static void ata_pio_block(struct ata_port *ap) | |||
2778 | if ((status & ATA_DRQ) == 0) { | 2933 | if ((status & ATA_DRQ) == 0) { |
2779 | ap->pio_task_state = PIO_ST_IDLE; | 2934 | ap->pio_task_state = PIO_ST_IDLE; |
2780 | 2935 | ||
2781 | ata_irq_on(ap); | 2936 | ata_poll_qc_complete(qc, status); |
2782 | |||
2783 | ata_qc_complete(qc, status); | ||
2784 | return; | 2937 | return; |
2785 | } | 2938 | } |
2786 | 2939 | ||
@@ -2810,9 +2963,7 @@ static void ata_pio_error(struct ata_port *ap) | |||
2810 | 2963 | ||
2811 | ap->pio_task_state = PIO_ST_IDLE; | 2964 | ap->pio_task_state = PIO_ST_IDLE; |
2812 | 2965 | ||
2813 | ata_irq_on(ap); | 2966 | ata_poll_qc_complete(qc, drv_stat | ATA_ERR); |
2814 | |||
2815 | ata_qc_complete(qc, drv_stat | ATA_ERR); | ||
2816 | } | 2967 | } |
2817 | 2968 | ||
2818 | static void ata_pio_task(void *_data) | 2969 | static void ata_pio_task(void *_data) |
@@ -2918,8 +3069,10 @@ static void atapi_request_sense(struct ata_port *ap, struct ata_device *dev, | |||
2918 | static void ata_qc_timeout(struct ata_queued_cmd *qc) | 3069 | static void ata_qc_timeout(struct ata_queued_cmd *qc) |
2919 | { | 3070 | { |
2920 | struct ata_port *ap = qc->ap; | 3071 | struct ata_port *ap = qc->ap; |
3072 | struct ata_host_set *host_set = ap->host_set; | ||
2921 | struct ata_device *dev = qc->dev; | 3073 | struct ata_device *dev = qc->dev; |
2922 | u8 host_stat = 0, drv_stat; | 3074 | u8 host_stat = 0, drv_stat; |
3075 | unsigned long flags; | ||
2923 | 3076 | ||
2924 | DPRINTK("ENTER\n"); | 3077 | DPRINTK("ENTER\n"); |
2925 | 3078 | ||
@@ -2930,7 +3083,9 @@ static void ata_qc_timeout(struct ata_queued_cmd *qc) | |||
2930 | if (!(cmd->eh_eflags & SCSI_EH_CANCEL_CMD)) { | 3083 | if (!(cmd->eh_eflags & SCSI_EH_CANCEL_CMD)) { |
2931 | 3084 | ||
2932 | /* finish completing original command */ | 3085 | /* finish completing original command */ |
3086 | spin_lock_irqsave(&host_set->lock, flags); | ||
2933 | __ata_qc_complete(qc); | 3087 | __ata_qc_complete(qc); |
3088 | spin_unlock_irqrestore(&host_set->lock, flags); | ||
2934 | 3089 | ||
2935 | atapi_request_sense(ap, dev, cmd); | 3090 | atapi_request_sense(ap, dev, cmd); |
2936 | 3091 | ||
@@ -2941,6 +3096,8 @@ static void ata_qc_timeout(struct ata_queued_cmd *qc) | |||
2941 | } | 3096 | } |
2942 | } | 3097 | } |
2943 | 3098 | ||
3099 | spin_lock_irqsave(&host_set->lock, flags); | ||
3100 | |||
2944 | /* hack alert! We cannot use the supplied completion | 3101 | /* hack alert! We cannot use the supplied completion |
2945 | * function from inside the ->eh_strategy_handler() thread. | 3102 | * function from inside the ->eh_strategy_handler() thread. |
2946 | * libata is the only user of ->eh_strategy_handler() in | 3103 | * libata is the only user of ->eh_strategy_handler() in |
@@ -2956,7 +3113,7 @@ static void ata_qc_timeout(struct ata_queued_cmd *qc) | |||
2956 | host_stat = ap->ops->bmdma_status(ap); | 3113 | host_stat = ap->ops->bmdma_status(ap); |
2957 | 3114 | ||
2958 | /* before we do anything else, clear DMA-Start bit */ | 3115 | /* before we do anything else, clear DMA-Start bit */ |
2959 | ap->ops->bmdma_stop(ap); | 3116 | ap->ops->bmdma_stop(qc); |
2960 | 3117 | ||
2961 | /* fall through */ | 3118 | /* fall through */ |
2962 | 3119 | ||
@@ -2974,6 +3131,9 @@ static void ata_qc_timeout(struct ata_queued_cmd *qc) | |||
2974 | ata_qc_complete(qc, drv_stat); | 3131 | ata_qc_complete(qc, drv_stat); |
2975 | break; | 3132 | break; |
2976 | } | 3133 | } |
3134 | |||
3135 | spin_unlock_irqrestore(&host_set->lock, flags); | ||
3136 | |||
2977 | out: | 3137 | out: |
2978 | DPRINTK("EXIT\n"); | 3138 | DPRINTK("EXIT\n"); |
2979 | } | 3139 | } |
@@ -3151,9 +3311,14 @@ void ata_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat) | |||
3151 | if (likely(qc->flags & ATA_QCFLAG_DMAMAP)) | 3311 | if (likely(qc->flags & ATA_QCFLAG_DMAMAP)) |
3152 | ata_sg_clean(qc); | 3312 | ata_sg_clean(qc); |
3153 | 3313 | ||
3314 | /* atapi: mark qc as inactive to prevent the interrupt handler | ||
3315 | * from completing the command twice later, before the error handler | ||
3316 | * is called. (when rc != 0 and atapi request sense is needed) | ||
3317 | */ | ||
3318 | qc->flags &= ~ATA_QCFLAG_ACTIVE; | ||
3319 | |||
3154 | /* call completion callback */ | 3320 | /* call completion callback */ |
3155 | rc = qc->complete_fn(qc, drv_stat); | 3321 | rc = qc->complete_fn(qc, drv_stat); |
3156 | qc->flags &= ~ATA_QCFLAG_ACTIVE; | ||
3157 | 3322 | ||
3158 | /* if callback indicates not to complete command (non-zero), | 3323 | /* if callback indicates not to complete command (non-zero), |
3159 | * return immediately | 3324 | * return immediately |
@@ -3283,11 +3448,13 @@ int ata_qc_issue_prot(struct ata_queued_cmd *qc) | |||
3283 | break; | 3448 | break; |
3284 | 3449 | ||
3285 | case ATA_PROT_ATAPI_NODATA: | 3450 | case ATA_PROT_ATAPI_NODATA: |
3451 | ap->flags |= ATA_FLAG_NOINTR; | ||
3286 | ata_tf_to_host_nolock(ap, &qc->tf); | 3452 | ata_tf_to_host_nolock(ap, &qc->tf); |
3287 | queue_work(ata_wq, &ap->packet_task); | 3453 | queue_work(ata_wq, &ap->packet_task); |
3288 | break; | 3454 | break; |
3289 | 3455 | ||
3290 | case ATA_PROT_ATAPI_DMA: | 3456 | case ATA_PROT_ATAPI_DMA: |
3457 | ap->flags |= ATA_FLAG_NOINTR; | ||
3291 | ap->ops->tf_load(ap, &qc->tf); /* load tf registers */ | 3458 | ap->ops->tf_load(ap, &qc->tf); /* load tf registers */ |
3292 | ap->ops->bmdma_setup(qc); /* set up bmdma */ | 3459 | ap->ops->bmdma_setup(qc); /* set up bmdma */ |
3293 | queue_work(ata_wq, &ap->packet_task); | 3460 | queue_work(ata_wq, &ap->packet_task); |
@@ -3332,7 +3499,7 @@ static void ata_bmdma_setup_mmio (struct ata_queued_cmd *qc) | |||
3332 | } | 3499 | } |
3333 | 3500 | ||
3334 | /** | 3501 | /** |
3335 | * ata_bmdma_start - Start a PCI IDE BMDMA transaction | 3502 | * ata_bmdma_start_mmio - Start a PCI IDE BMDMA transaction |
3336 | * @qc: Info associated with this ATA transaction. | 3503 | * @qc: Info associated with this ATA transaction. |
3337 | * | 3504 | * |
3338 | * LOCKING: | 3505 | * LOCKING: |
@@ -3503,7 +3670,7 @@ u8 ata_bmdma_status(struct ata_port *ap) | |||
3503 | 3670 | ||
3504 | /** | 3671 | /** |
3505 | * ata_bmdma_stop - Stop PCI IDE BMDMA transfer | 3672 | * ata_bmdma_stop - Stop PCI IDE BMDMA transfer |
3506 | * @ap: Port associated with this ATA transaction. | 3673 | * @qc: Command we are ending DMA for |
3507 | * | 3674 | * |
3508 | * Clears the ATA_DMA_START flag in the dma control register | 3675 | * Clears the ATA_DMA_START flag in the dma control register |
3509 | * | 3676 | * |
@@ -3513,8 +3680,9 @@ u8 ata_bmdma_status(struct ata_port *ap) | |||
3513 | * spin_lock_irqsave(host_set lock) | 3680 | * spin_lock_irqsave(host_set lock) |
3514 | */ | 3681 | */ |
3515 | 3682 | ||
3516 | void ata_bmdma_stop(struct ata_port *ap) | 3683 | void ata_bmdma_stop(struct ata_queued_cmd *qc) |
3517 | { | 3684 | { |
3685 | struct ata_port *ap = qc->ap; | ||
3518 | if (ap->flags & ATA_FLAG_MMIO) { | 3686 | if (ap->flags & ATA_FLAG_MMIO) { |
3519 | void __iomem *mmio = (void __iomem *) ap->ioaddr.bmdma_addr; | 3687 | void __iomem *mmio = (void __iomem *) ap->ioaddr.bmdma_addr; |
3520 | 3688 | ||
@@ -3566,7 +3734,7 @@ inline unsigned int ata_host_intr (struct ata_port *ap, | |||
3566 | goto idle_irq; | 3734 | goto idle_irq; |
3567 | 3735 | ||
3568 | /* before we do anything else, clear DMA-Start bit */ | 3736 | /* before we do anything else, clear DMA-Start bit */ |
3569 | ap->ops->bmdma_stop(ap); | 3737 | ap->ops->bmdma_stop(qc); |
3570 | 3738 | ||
3571 | /* fall through */ | 3739 | /* fall through */ |
3572 | 3740 | ||
@@ -3641,7 +3809,8 @@ irqreturn_t ata_interrupt (int irq, void *dev_instance, struct pt_regs *regs) | |||
3641 | struct ata_port *ap; | 3809 | struct ata_port *ap; |
3642 | 3810 | ||
3643 | ap = host_set->ports[i]; | 3811 | ap = host_set->ports[i]; |
3644 | if (ap && (!(ap->flags & ATA_FLAG_PORT_DISABLED))) { | 3812 | if (ap && |
3813 | !(ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR))) { | ||
3645 | struct ata_queued_cmd *qc; | 3814 | struct ata_queued_cmd *qc; |
3646 | 3815 | ||
3647 | qc = ata_qc_from_tag(ap, ap->active_tag); | 3816 | qc = ata_qc_from_tag(ap, ap->active_tag); |
@@ -3693,19 +3862,27 @@ static void atapi_packet_task(void *_data) | |||
3693 | /* send SCSI cdb */ | 3862 | /* send SCSI cdb */ |
3694 | DPRINTK("send cdb\n"); | 3863 | DPRINTK("send cdb\n"); |
3695 | assert(ap->cdb_len >= 12); | 3864 | assert(ap->cdb_len >= 12); |
3696 | ata_data_xfer(ap, qc->cdb, ap->cdb_len, 1); | ||
3697 | 3865 | ||
3698 | /* if we are DMA'ing, irq handler takes over from here */ | 3866 | if (qc->tf.protocol == ATA_PROT_ATAPI_DMA || |
3699 | if (qc->tf.protocol == ATA_PROT_ATAPI_DMA) | 3867 | qc->tf.protocol == ATA_PROT_ATAPI_NODATA) { |
3700 | ap->ops->bmdma_start(qc); /* initiate bmdma */ | 3868 | unsigned long flags; |
3701 | 3869 | ||
3702 | /* non-data commands are also handled via irq */ | 3870 | /* Once we're done issuing command and kicking bmdma, |
3703 | else if (qc->tf.protocol == ATA_PROT_ATAPI_NODATA) { | 3871 | * irq handler takes over. To not lose irq, we need |
3704 | /* do nothing */ | 3872 | * to clear NOINTR flag before sending cdb, but |
3705 | } | 3873 | * interrupt handler shouldn't be invoked before we're |
3874 | * finished. Hence, the following locking. | ||
3875 | */ | ||
3876 | spin_lock_irqsave(&ap->host_set->lock, flags); | ||
3877 | ap->flags &= ~ATA_FLAG_NOINTR; | ||
3878 | ata_data_xfer(ap, qc->cdb, ap->cdb_len, 1); | ||
3879 | if (qc->tf.protocol == ATA_PROT_ATAPI_DMA) | ||
3880 | ap->ops->bmdma_start(qc); /* initiate bmdma */ | ||
3881 | spin_unlock_irqrestore(&ap->host_set->lock, flags); | ||
3882 | } else { | ||
3883 | ata_data_xfer(ap, qc->cdb, ap->cdb_len, 1); | ||
3706 | 3884 | ||
3707 | /* PIO commands are handled by polling */ | 3885 | /* PIO commands are handled by polling */ |
3708 | else { | ||
3709 | ap->pio_task_state = PIO_ST; | 3886 | ap->pio_task_state = PIO_ST; |
3710 | queue_work(ata_wq, &ap->pio_task); | 3887 | queue_work(ata_wq, &ap->pio_task); |
3711 | } | 3888 | } |
@@ -3713,7 +3890,7 @@ static void atapi_packet_task(void *_data) | |||
3713 | return; | 3890 | return; |
3714 | 3891 | ||
3715 | err_out: | 3892 | err_out: |
3716 | ata_qc_complete(qc, ATA_ERR); | 3893 | ata_poll_qc_complete(qc, ATA_ERR); |
3717 | } | 3894 | } |
3718 | 3895 | ||
3719 | 3896 | ||