diff options
Diffstat (limited to 'drivers/scsi/libata-core.c')
-rw-r--r-- | drivers/scsi/libata-core.c | 324 |
1 files changed, 238 insertions, 86 deletions
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c index 73b1f72b7e43..dee4b12b0342 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> |
@@ -1304,12 +1314,12 @@ static inline u8 ata_dev_knobble(struct ata_port *ap) | |||
1304 | /** | 1314 | /** |
1305 | * ata_dev_config - Run device specific handlers and check for | 1315 | * ata_dev_config - Run device specific handlers and check for |
1306 | * SATA->PATA bridges | 1316 | * SATA->PATA bridges |
1307 | * @ap: Bus | 1317 | * @ap: Bus |
1308 | * @i: Device | 1318 | * @i: Device |
1309 | * | 1319 | * |
1310 | * LOCKING: | 1320 | * LOCKING: |
1311 | */ | 1321 | */ |
1312 | 1322 | ||
1313 | void ata_dev_config(struct ata_port *ap, unsigned int i) | 1323 | void ata_dev_config(struct ata_port *ap, unsigned int i) |
1314 | { | 1324 | { |
1315 | /* limit bridge transfers to udma5, 200 sectors */ | 1325 | /* limit bridge transfers to udma5, 200 sectors */ |
@@ -2268,19 +2278,6 @@ void ata_qc_prep(struct ata_queued_cmd *qc) | |||
2268 | * spin_lock_irqsave(host_set lock) | 2278 | * spin_lock_irqsave(host_set lock) |
2269 | */ | 2279 | */ |
2270 | 2280 | ||
2271 | |||
2272 | |||
2273 | /** | ||
2274 | * ata_sg_init_one - Prepare a one-entry scatter-gather list. | ||
2275 | * @qc: Queued command | ||
2276 | * @buf: transfer buffer | ||
2277 | * @buflen: length of buf | ||
2278 | * | ||
2279 | * Builds a single-entry scatter-gather list to initiate a | ||
2280 | * transfer utilizing the specified buffer. | ||
2281 | * | ||
2282 | * LOCKING: | ||
2283 | */ | ||
2284 | void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf, unsigned int buflen) | 2281 | void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf, unsigned int buflen) |
2285 | { | 2282 | { |
2286 | struct scatterlist *sg; | 2283 | struct scatterlist *sg; |
@@ -2312,18 +2309,6 @@ void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf, unsigned int buflen) | |||
2312 | * spin_lock_irqsave(host_set lock) | 2309 | * spin_lock_irqsave(host_set lock) |
2313 | */ | 2310 | */ |
2314 | 2311 | ||
2315 | |||
2316 | /** | ||
2317 | * ata_sg_init - Assign a scatter gather list to a queued command | ||
2318 | * @qc: Queued command | ||
2319 | * @sg: Scatter-gather list | ||
2320 | * @n_elem: length of sg list | ||
2321 | * | ||
2322 | * Attaches a scatter-gather list to a queued command. | ||
2323 | * | ||
2324 | * LOCKING: | ||
2325 | */ | ||
2326 | |||
2327 | void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg, | 2312 | void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg, |
2328 | unsigned int n_elem) | 2313 | unsigned int n_elem) |
2329 | { | 2314 | { |
@@ -2402,6 +2387,27 @@ static int ata_sg_setup(struct ata_queued_cmd *qc) | |||
2402 | } | 2387 | } |
2403 | 2388 | ||
2404 | /** | 2389 | /** |
2390 | * ata_poll_qc_complete - turn irq back on and finish qc | ||
2391 | * @qc: Command to complete | ||
2392 | * @drv_stat: ATA status register content | ||
2393 | * | ||
2394 | * LOCKING: | ||
2395 | * None. (grabs host lock) | ||
2396 | */ | ||
2397 | |||
2398 | void ata_poll_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat) | ||
2399 | { | ||
2400 | struct ata_port *ap = qc->ap; | ||
2401 | unsigned long flags; | ||
2402 | |||
2403 | spin_lock_irqsave(&ap->host_set->lock, flags); | ||
2404 | ap->flags &= ~ATA_FLAG_NOINTR; | ||
2405 | ata_irq_on(ap); | ||
2406 | ata_qc_complete(qc, drv_stat); | ||
2407 | spin_unlock_irqrestore(&ap->host_set->lock, flags); | ||
2408 | } | ||
2409 | |||
2410 | /** | ||
2405 | * ata_pio_poll - | 2411 | * ata_pio_poll - |
2406 | * @ap: | 2412 | * @ap: |
2407 | * | 2413 | * |
@@ -2463,11 +2469,10 @@ static void ata_pio_complete (struct ata_port *ap) | |||
2463 | u8 drv_stat; | 2469 | u8 drv_stat; |
2464 | 2470 | ||
2465 | /* | 2471 | /* |
2466 | * This is purely hueristic. This is a fast path. | 2472 | * This is purely heuristic. This is a fast path. Sometimes when |
2467 | * Sometimes when we enter, BSY will be cleared in | 2473 | * we enter, BSY will be cleared in a chk-status or two. If not, |
2468 | * a chk-status or two. If not, the drive is probably seeking | 2474 | * the drive is probably seeking or something. Snooze for a couple |
2469 | * or something. Snooze for a couple msecs, then | 2475 | * msecs, then chk-status again. If still busy, fall back to |
2470 | * chk-status again. If still busy, fall back to | ||
2471 | * PIO_ST_POLL state. | 2476 | * PIO_ST_POLL state. |
2472 | */ | 2477 | */ |
2473 | drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 10); | 2478 | drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 10); |
@@ -2492,9 +2497,7 @@ static void ata_pio_complete (struct ata_port *ap) | |||
2492 | 2497 | ||
2493 | ap->pio_task_state = PIO_ST_IDLE; | 2498 | ap->pio_task_state = PIO_ST_IDLE; |
2494 | 2499 | ||
2495 | ata_irq_on(ap); | 2500 | ata_poll_qc_complete(qc, drv_stat); |
2496 | |||
2497 | ata_qc_complete(qc, drv_stat); | ||
2498 | } | 2501 | } |
2499 | 2502 | ||
2500 | 2503 | ||
@@ -2519,6 +2522,20 @@ void swap_buf_le16(u16 *buf, unsigned int buf_words) | |||
2519 | #endif /* __BIG_ENDIAN */ | 2522 | #endif /* __BIG_ENDIAN */ |
2520 | } | 2523 | } |
2521 | 2524 | ||
2525 | /** | ||
2526 | * ata_mmio_data_xfer - Transfer data by MMIO | ||
2527 | * @ap: port to read/write | ||
2528 | * @buf: data buffer | ||
2529 | * @buflen: buffer length | ||
2530 | * @do_write: read/write | ||
2531 | * | ||
2532 | * Transfer data from/to the device data register by MMIO. | ||
2533 | * | ||
2534 | * LOCKING: | ||
2535 | * Inherited from caller. | ||
2536 | * | ||
2537 | */ | ||
2538 | |||
2522 | static void ata_mmio_data_xfer(struct ata_port *ap, unsigned char *buf, | 2539 | static void ata_mmio_data_xfer(struct ata_port *ap, unsigned char *buf, |
2523 | unsigned int buflen, int write_data) | 2540 | unsigned int buflen, int write_data) |
2524 | { | 2541 | { |
@@ -2527,6 +2544,7 @@ static void ata_mmio_data_xfer(struct ata_port *ap, unsigned char *buf, | |||
2527 | u16 *buf16 = (u16 *) buf; | 2544 | u16 *buf16 = (u16 *) buf; |
2528 | void __iomem *mmio = (void __iomem *)ap->ioaddr.data_addr; | 2545 | void __iomem *mmio = (void __iomem *)ap->ioaddr.data_addr; |
2529 | 2546 | ||
2547 | /* Transfer multiple of 2 bytes */ | ||
2530 | if (write_data) { | 2548 | if (write_data) { |
2531 | for (i = 0; i < words; i++) | 2549 | for (i = 0; i < words; i++) |
2532 | writew(le16_to_cpu(buf16[i]), mmio); | 2550 | writew(le16_to_cpu(buf16[i]), mmio); |
@@ -2534,19 +2552,76 @@ static void ata_mmio_data_xfer(struct ata_port *ap, unsigned char *buf, | |||
2534 | for (i = 0; i < words; i++) | 2552 | for (i = 0; i < words; i++) |
2535 | buf16[i] = cpu_to_le16(readw(mmio)); | 2553 | buf16[i] = cpu_to_le16(readw(mmio)); |
2536 | } | 2554 | } |
2555 | |||
2556 | /* Transfer trailing 1 byte, if any. */ | ||
2557 | if (unlikely(buflen & 0x01)) { | ||
2558 | u16 align_buf[1] = { 0 }; | ||
2559 | unsigned char *trailing_buf = buf + buflen - 1; | ||
2560 | |||
2561 | if (write_data) { | ||
2562 | memcpy(align_buf, trailing_buf, 1); | ||
2563 | writew(le16_to_cpu(align_buf[0]), mmio); | ||
2564 | } else { | ||
2565 | align_buf[0] = cpu_to_le16(readw(mmio)); | ||
2566 | memcpy(trailing_buf, align_buf, 1); | ||
2567 | } | ||
2568 | } | ||
2537 | } | 2569 | } |
2538 | 2570 | ||
2571 | /** | ||
2572 | * ata_pio_data_xfer - Transfer data by PIO | ||
2573 | * @ap: port to read/write | ||
2574 | * @buf: data buffer | ||
2575 | * @buflen: buffer length | ||
2576 | * @do_write: read/write | ||
2577 | * | ||
2578 | * Transfer data from/to the device data register by PIO. | ||
2579 | * | ||
2580 | * LOCKING: | ||
2581 | * Inherited from caller. | ||
2582 | * | ||
2583 | */ | ||
2584 | |||
2539 | static void ata_pio_data_xfer(struct ata_port *ap, unsigned char *buf, | 2585 | static void ata_pio_data_xfer(struct ata_port *ap, unsigned char *buf, |
2540 | unsigned int buflen, int write_data) | 2586 | unsigned int buflen, int write_data) |
2541 | { | 2587 | { |
2542 | unsigned int dwords = buflen >> 1; | 2588 | unsigned int words = buflen >> 1; |
2543 | 2589 | ||
2590 | /* Transfer multiple of 2 bytes */ | ||
2544 | if (write_data) | 2591 | if (write_data) |
2545 | outsw(ap->ioaddr.data_addr, buf, dwords); | 2592 | outsw(ap->ioaddr.data_addr, buf, words); |
2546 | else | 2593 | else |
2547 | insw(ap->ioaddr.data_addr, buf, dwords); | 2594 | insw(ap->ioaddr.data_addr, buf, words); |
2595 | |||
2596 | /* Transfer trailing 1 byte, if any. */ | ||
2597 | if (unlikely(buflen & 0x01)) { | ||
2598 | u16 align_buf[1] = { 0 }; | ||
2599 | unsigned char *trailing_buf = buf + buflen - 1; | ||
2600 | |||
2601 | if (write_data) { | ||
2602 | memcpy(align_buf, trailing_buf, 1); | ||
2603 | outw(le16_to_cpu(align_buf[0]), ap->ioaddr.data_addr); | ||
2604 | } else { | ||
2605 | align_buf[0] = cpu_to_le16(inw(ap->ioaddr.data_addr)); | ||
2606 | memcpy(trailing_buf, align_buf, 1); | ||
2607 | } | ||
2608 | } | ||
2548 | } | 2609 | } |
2549 | 2610 | ||
2611 | /** | ||
2612 | * ata_data_xfer - Transfer data from/to the data register. | ||
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. | ||
2619 | * | ||
2620 | * LOCKING: | ||
2621 | * Inherited from caller. | ||
2622 | * | ||
2623 | */ | ||
2624 | |||
2550 | static void ata_data_xfer(struct ata_port *ap, unsigned char *buf, | 2625 | static void ata_data_xfer(struct ata_port *ap, unsigned char *buf, |
2551 | unsigned int buflen, int do_write) | 2626 | unsigned int buflen, int do_write) |
2552 | { | 2627 | { |
@@ -2556,6 +2631,16 @@ static void ata_data_xfer(struct ata_port *ap, unsigned char *buf, | |||
2556 | ata_pio_data_xfer(ap, buf, buflen, do_write); | 2631 | ata_pio_data_xfer(ap, buf, buflen, do_write); |
2557 | } | 2632 | } |
2558 | 2633 | ||
2634 | /** | ||
2635 | * ata_pio_sector - Transfer ATA_SECT_SIZE (512 bytes) of data. | ||
2636 | * @qc: Command on going | ||
2637 | * | ||
2638 | * Transfer ATA_SECT_SIZE of data from/to the ATA device. | ||
2639 | * | ||
2640 | * LOCKING: | ||
2641 | * Inherited from caller. | ||
2642 | */ | ||
2643 | |||
2559 | static void ata_pio_sector(struct ata_queued_cmd *qc) | 2644 | static void ata_pio_sector(struct ata_queued_cmd *qc) |
2560 | { | 2645 | { |
2561 | int do_write = (qc->tf.flags & ATA_TFLAG_WRITE); | 2646 | int do_write = (qc->tf.flags & ATA_TFLAG_WRITE); |
@@ -2594,6 +2679,18 @@ static void ata_pio_sector(struct ata_queued_cmd *qc) | |||
2594 | kunmap(page); | 2679 | kunmap(page); |
2595 | } | 2680 | } |
2596 | 2681 | ||
2682 | /** | ||
2683 | * __atapi_pio_bytes - Transfer data from/to the ATAPI device. | ||
2684 | * @qc: Command on going | ||
2685 | * @bytes: number of bytes | ||
2686 | * | ||
2687 | * Transfer Transfer data from/to the ATAPI device. | ||
2688 | * | ||
2689 | * LOCKING: | ||
2690 | * Inherited from caller. | ||
2691 | * | ||
2692 | */ | ||
2693 | |||
2597 | static void __atapi_pio_bytes(struct ata_queued_cmd *qc, unsigned int bytes) | 2694 | static void __atapi_pio_bytes(struct ata_queued_cmd *qc, unsigned int bytes) |
2598 | { | 2695 | { |
2599 | int do_write = (qc->tf.flags & ATA_TFLAG_WRITE); | 2696 | int do_write = (qc->tf.flags & ATA_TFLAG_WRITE); |
@@ -2603,10 +2700,33 @@ static void __atapi_pio_bytes(struct ata_queued_cmd *qc, unsigned int bytes) | |||
2603 | unsigned char *buf; | 2700 | unsigned char *buf; |
2604 | unsigned int offset, count; | 2701 | unsigned int offset, count; |
2605 | 2702 | ||
2606 | if (qc->curbytes == qc->nbytes - bytes) | 2703 | if (qc->curbytes + bytes >= qc->nbytes) |
2607 | ap->pio_task_state = PIO_ST_LAST; | 2704 | ap->pio_task_state = PIO_ST_LAST; |
2608 | 2705 | ||
2609 | next_sg: | 2706 | next_sg: |
2707 | if (unlikely(qc->cursg >= qc->n_elem)) { | ||
2708 | /* | ||
2709 | * The end of qc->sg is reached and the device expects | ||
2710 | * more data to transfer. In order not to overrun qc->sg | ||
2711 | * and fulfill length specified in the byte count register, | ||
2712 | * - for read case, discard trailing data from the device | ||
2713 | * - for write case, padding zero data to the device | ||
2714 | */ | ||
2715 | u16 pad_buf[1] = { 0 }; | ||
2716 | unsigned int words = bytes >> 1; | ||
2717 | unsigned int i; | ||
2718 | |||
2719 | if (words) /* warning if bytes > 1 */ | ||
2720 | printk(KERN_WARNING "ata%u: %u bytes trailing data\n", | ||
2721 | ap->id, bytes); | ||
2722 | |||
2723 | for (i = 0; i < words; i++) | ||
2724 | ata_data_xfer(ap, (unsigned char*)pad_buf, 2, do_write); | ||
2725 | |||
2726 | ap->pio_task_state = PIO_ST_LAST; | ||
2727 | return; | ||
2728 | } | ||
2729 | |||
2610 | sg = &qc->sg[qc->cursg]; | 2730 | sg = &qc->sg[qc->cursg]; |
2611 | 2731 | ||
2612 | page = sg->page; | 2732 | page = sg->page; |
@@ -2640,11 +2760,21 @@ next_sg: | |||
2640 | 2760 | ||
2641 | kunmap(page); | 2761 | kunmap(page); |
2642 | 2762 | ||
2643 | if (bytes) { | 2763 | if (bytes) |
2644 | goto next_sg; | 2764 | goto next_sg; |
2645 | } | ||
2646 | } | 2765 | } |
2647 | 2766 | ||
2767 | /** | ||
2768 | * atapi_pio_bytes - Transfer data from/to the ATAPI device. | ||
2769 | * @qc: Command on going | ||
2770 | * | ||
2771 | * Transfer Transfer data from/to the ATAPI device. | ||
2772 | * | ||
2773 | * LOCKING: | ||
2774 | * Inherited from caller. | ||
2775 | * | ||
2776 | */ | ||
2777 | |||
2648 | static void atapi_pio_bytes(struct ata_queued_cmd *qc) | 2778 | static void atapi_pio_bytes(struct ata_queued_cmd *qc) |
2649 | { | 2779 | { |
2650 | struct ata_port *ap = qc->ap; | 2780 | struct ata_port *ap = qc->ap; |
@@ -2717,9 +2847,7 @@ static void ata_pio_block(struct ata_port *ap) | |||
2717 | if ((status & ATA_DRQ) == 0) { | 2847 | if ((status & ATA_DRQ) == 0) { |
2718 | ap->pio_task_state = PIO_ST_IDLE; | 2848 | ap->pio_task_state = PIO_ST_IDLE; |
2719 | 2849 | ||
2720 | ata_irq_on(ap); | 2850 | ata_poll_qc_complete(qc, status); |
2721 | |||
2722 | ata_qc_complete(qc, status); | ||
2723 | return; | 2851 | return; |
2724 | } | 2852 | } |
2725 | 2853 | ||
@@ -2749,9 +2877,7 @@ static void ata_pio_error(struct ata_port *ap) | |||
2749 | 2877 | ||
2750 | ap->pio_task_state = PIO_ST_IDLE; | 2878 | ap->pio_task_state = PIO_ST_IDLE; |
2751 | 2879 | ||
2752 | ata_irq_on(ap); | 2880 | ata_poll_qc_complete(qc, drv_stat | ATA_ERR); |
2753 | |||
2754 | ata_qc_complete(qc, drv_stat | ATA_ERR); | ||
2755 | } | 2881 | } |
2756 | 2882 | ||
2757 | static void ata_pio_task(void *_data) | 2883 | static void ata_pio_task(void *_data) |
@@ -2857,8 +2983,10 @@ static void atapi_request_sense(struct ata_port *ap, struct ata_device *dev, | |||
2857 | static void ata_qc_timeout(struct ata_queued_cmd *qc) | 2983 | static void ata_qc_timeout(struct ata_queued_cmd *qc) |
2858 | { | 2984 | { |
2859 | struct ata_port *ap = qc->ap; | 2985 | struct ata_port *ap = qc->ap; |
2986 | struct ata_host_set *host_set = ap->host_set; | ||
2860 | struct ata_device *dev = qc->dev; | 2987 | struct ata_device *dev = qc->dev; |
2861 | u8 host_stat = 0, drv_stat; | 2988 | u8 host_stat = 0, drv_stat; |
2989 | unsigned long flags; | ||
2862 | 2990 | ||
2863 | DPRINTK("ENTER\n"); | 2991 | DPRINTK("ENTER\n"); |
2864 | 2992 | ||
@@ -2869,7 +2997,9 @@ static void ata_qc_timeout(struct ata_queued_cmd *qc) | |||
2869 | if (!(cmd->eh_eflags & SCSI_EH_CANCEL_CMD)) { | 2997 | if (!(cmd->eh_eflags & SCSI_EH_CANCEL_CMD)) { |
2870 | 2998 | ||
2871 | /* finish completing original command */ | 2999 | /* finish completing original command */ |
3000 | spin_lock_irqsave(&host_set->lock, flags); | ||
2872 | __ata_qc_complete(qc); | 3001 | __ata_qc_complete(qc); |
3002 | spin_unlock_irqrestore(&host_set->lock, flags); | ||
2873 | 3003 | ||
2874 | atapi_request_sense(ap, dev, cmd); | 3004 | atapi_request_sense(ap, dev, cmd); |
2875 | 3005 | ||
@@ -2880,6 +3010,8 @@ static void ata_qc_timeout(struct ata_queued_cmd *qc) | |||
2880 | } | 3010 | } |
2881 | } | 3011 | } |
2882 | 3012 | ||
3013 | spin_lock_irqsave(&host_set->lock, flags); | ||
3014 | |||
2883 | /* hack alert! We cannot use the supplied completion | 3015 | /* hack alert! We cannot use the supplied completion |
2884 | * function from inside the ->eh_strategy_handler() thread. | 3016 | * function from inside the ->eh_strategy_handler() thread. |
2885 | * libata is the only user of ->eh_strategy_handler() in | 3017 | * libata is the only user of ->eh_strategy_handler() in |
@@ -2895,7 +3027,7 @@ static void ata_qc_timeout(struct ata_queued_cmd *qc) | |||
2895 | host_stat = ap->ops->bmdma_status(ap); | 3027 | host_stat = ap->ops->bmdma_status(ap); |
2896 | 3028 | ||
2897 | /* before we do anything else, clear DMA-Start bit */ | 3029 | /* before we do anything else, clear DMA-Start bit */ |
2898 | ap->ops->bmdma_stop(ap); | 3030 | ap->ops->bmdma_stop(qc); |
2899 | 3031 | ||
2900 | /* fall through */ | 3032 | /* fall through */ |
2901 | 3033 | ||
@@ -2913,6 +3045,9 @@ static void ata_qc_timeout(struct ata_queued_cmd *qc) | |||
2913 | ata_qc_complete(qc, drv_stat); | 3045 | ata_qc_complete(qc, drv_stat); |
2914 | break; | 3046 | break; |
2915 | } | 3047 | } |
3048 | |||
3049 | spin_unlock_irqrestore(&host_set->lock, flags); | ||
3050 | |||
2916 | out: | 3051 | out: |
2917 | DPRINTK("EXIT\n"); | 3052 | DPRINTK("EXIT\n"); |
2918 | } | 3053 | } |
@@ -3086,9 +3221,14 @@ void ata_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat) | |||
3086 | if (likely(qc->flags & ATA_QCFLAG_DMAMAP)) | 3221 | if (likely(qc->flags & ATA_QCFLAG_DMAMAP)) |
3087 | ata_sg_clean(qc); | 3222 | ata_sg_clean(qc); |
3088 | 3223 | ||
3224 | /* atapi: mark qc as inactive to prevent the interrupt handler | ||
3225 | * from completing the command twice later, before the error handler | ||
3226 | * is called. (when rc != 0 and atapi request sense is needed) | ||
3227 | */ | ||
3228 | qc->flags &= ~ATA_QCFLAG_ACTIVE; | ||
3229 | |||
3089 | /* call completion callback */ | 3230 | /* call completion callback */ |
3090 | rc = qc->complete_fn(qc, drv_stat); | 3231 | rc = qc->complete_fn(qc, drv_stat); |
3091 | qc->flags &= ~ATA_QCFLAG_ACTIVE; | ||
3092 | 3232 | ||
3093 | /* if callback indicates not to complete command (non-zero), | 3233 | /* if callback indicates not to complete command (non-zero), |
3094 | * return immediately | 3234 | * return immediately |
@@ -3218,11 +3358,13 @@ int ata_qc_issue_prot(struct ata_queued_cmd *qc) | |||
3218 | break; | 3358 | break; |
3219 | 3359 | ||
3220 | case ATA_PROT_ATAPI_NODATA: | 3360 | case ATA_PROT_ATAPI_NODATA: |
3361 | ap->flags |= ATA_FLAG_NOINTR; | ||
3221 | ata_tf_to_host_nolock(ap, &qc->tf); | 3362 | ata_tf_to_host_nolock(ap, &qc->tf); |
3222 | queue_work(ata_wq, &ap->packet_task); | 3363 | queue_work(ata_wq, &ap->packet_task); |
3223 | break; | 3364 | break; |
3224 | 3365 | ||
3225 | case ATA_PROT_ATAPI_DMA: | 3366 | case ATA_PROT_ATAPI_DMA: |
3367 | ap->flags |= ATA_FLAG_NOINTR; | ||
3226 | ap->ops->tf_load(ap, &qc->tf); /* load tf registers */ | 3368 | ap->ops->tf_load(ap, &qc->tf); /* load tf registers */ |
3227 | ap->ops->bmdma_setup(qc); /* set up bmdma */ | 3369 | ap->ops->bmdma_setup(qc); /* set up bmdma */ |
3228 | queue_work(ata_wq, &ap->packet_task); | 3370 | queue_work(ata_wq, &ap->packet_task); |
@@ -3267,7 +3409,7 @@ static void ata_bmdma_setup_mmio (struct ata_queued_cmd *qc) | |||
3267 | } | 3409 | } |
3268 | 3410 | ||
3269 | /** | 3411 | /** |
3270 | * ata_bmdma_start - Start a PCI IDE BMDMA transaction | 3412 | * ata_bmdma_start_mmio - Start a PCI IDE BMDMA transaction |
3271 | * @qc: Info associated with this ATA transaction. | 3413 | * @qc: Info associated with this ATA transaction. |
3272 | * | 3414 | * |
3273 | * LOCKING: | 3415 | * LOCKING: |
@@ -3438,7 +3580,7 @@ u8 ata_bmdma_status(struct ata_port *ap) | |||
3438 | 3580 | ||
3439 | /** | 3581 | /** |
3440 | * ata_bmdma_stop - Stop PCI IDE BMDMA transfer | 3582 | * ata_bmdma_stop - Stop PCI IDE BMDMA transfer |
3441 | * @ap: Port associated with this ATA transaction. | 3583 | * @qc: Command we are ending DMA for |
3442 | * | 3584 | * |
3443 | * Clears the ATA_DMA_START flag in the dma control register | 3585 | * Clears the ATA_DMA_START flag in the dma control register |
3444 | * | 3586 | * |
@@ -3448,8 +3590,9 @@ u8 ata_bmdma_status(struct ata_port *ap) | |||
3448 | * spin_lock_irqsave(host_set lock) | 3590 | * spin_lock_irqsave(host_set lock) |
3449 | */ | 3591 | */ |
3450 | 3592 | ||
3451 | void ata_bmdma_stop(struct ata_port *ap) | 3593 | void ata_bmdma_stop(struct ata_queued_cmd *qc) |
3452 | { | 3594 | { |
3595 | struct ata_port *ap = qc->ap; | ||
3453 | if (ap->flags & ATA_FLAG_MMIO) { | 3596 | if (ap->flags & ATA_FLAG_MMIO) { |
3454 | void __iomem *mmio = (void __iomem *) ap->ioaddr.bmdma_addr; | 3597 | void __iomem *mmio = (void __iomem *) ap->ioaddr.bmdma_addr; |
3455 | 3598 | ||
@@ -3501,7 +3644,7 @@ inline unsigned int ata_host_intr (struct ata_port *ap, | |||
3501 | goto idle_irq; | 3644 | goto idle_irq; |
3502 | 3645 | ||
3503 | /* before we do anything else, clear DMA-Start bit */ | 3646 | /* before we do anything else, clear DMA-Start bit */ |
3504 | ap->ops->bmdma_stop(ap); | 3647 | ap->ops->bmdma_stop(qc); |
3505 | 3648 | ||
3506 | /* fall through */ | 3649 | /* fall through */ |
3507 | 3650 | ||
@@ -3576,7 +3719,8 @@ irqreturn_t ata_interrupt (int irq, void *dev_instance, struct pt_regs *regs) | |||
3576 | struct ata_port *ap; | 3719 | struct ata_port *ap; |
3577 | 3720 | ||
3578 | ap = host_set->ports[i]; | 3721 | ap = host_set->ports[i]; |
3579 | if (ap && (!(ap->flags & ATA_FLAG_PORT_DISABLED))) { | 3722 | if (ap && |
3723 | !(ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR))) { | ||
3580 | struct ata_queued_cmd *qc; | 3724 | struct ata_queued_cmd *qc; |
3581 | 3725 | ||
3582 | qc = ata_qc_from_tag(ap, ap->active_tag); | 3726 | qc = ata_qc_from_tag(ap, ap->active_tag); |
@@ -3628,19 +3772,27 @@ static void atapi_packet_task(void *_data) | |||
3628 | /* send SCSI cdb */ | 3772 | /* send SCSI cdb */ |
3629 | DPRINTK("send cdb\n"); | 3773 | DPRINTK("send cdb\n"); |
3630 | assert(ap->cdb_len >= 12); | 3774 | assert(ap->cdb_len >= 12); |
3631 | ata_data_xfer(ap, qc->cdb, ap->cdb_len, 1); | ||
3632 | 3775 | ||
3633 | /* if we are DMA'ing, irq handler takes over from here */ | 3776 | if (qc->tf.protocol == ATA_PROT_ATAPI_DMA || |
3634 | if (qc->tf.protocol == ATA_PROT_ATAPI_DMA) | 3777 | qc->tf.protocol == ATA_PROT_ATAPI_NODATA) { |
3635 | ap->ops->bmdma_start(qc); /* initiate bmdma */ | 3778 | unsigned long flags; |
3636 | 3779 | ||
3637 | /* non-data commands are also handled via irq */ | 3780 | /* Once we're done issuing command and kicking bmdma, |
3638 | else if (qc->tf.protocol == ATA_PROT_ATAPI_NODATA) { | 3781 | * irq handler takes over. To not lose irq, we need |
3639 | /* do nothing */ | 3782 | * to clear NOINTR flag before sending cdb, but |
3640 | } | 3783 | * interrupt handler shouldn't be invoked before we're |
3784 | * finished. Hence, the following locking. | ||
3785 | */ | ||
3786 | spin_lock_irqsave(&ap->host_set->lock, flags); | ||
3787 | ap->flags &= ~ATA_FLAG_NOINTR; | ||
3788 | ata_data_xfer(ap, qc->cdb, ap->cdb_len, 1); | ||
3789 | if (qc->tf.protocol == ATA_PROT_ATAPI_DMA) | ||
3790 | ap->ops->bmdma_start(qc); /* initiate bmdma */ | ||
3791 | spin_unlock_irqrestore(&ap->host_set->lock, flags); | ||
3792 | } else { | ||
3793 | ata_data_xfer(ap, qc->cdb, ap->cdb_len, 1); | ||
3641 | 3794 | ||
3642 | /* PIO commands are handled by polling */ | 3795 | /* PIO commands are handled by polling */ |
3643 | else { | ||
3644 | ap->pio_task_state = PIO_ST; | 3796 | ap->pio_task_state = PIO_ST; |
3645 | queue_work(ata_wq, &ap->pio_task); | 3797 | queue_work(ata_wq, &ap->pio_task); |
3646 | } | 3798 | } |
@@ -3648,7 +3800,7 @@ static void atapi_packet_task(void *_data) | |||
3648 | return; | 3800 | return; |
3649 | 3801 | ||
3650 | err_out: | 3802 | err_out: |
3651 | ata_qc_complete(qc, ATA_ERR); | 3803 | ata_poll_qc_complete(qc, ATA_ERR); |
3652 | } | 3804 | } |
3653 | 3805 | ||
3654 | 3806 | ||