aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/scsi/libata-core.c883
-rw-r--r--drivers/scsi/pdc_adma.c8
-rw-r--r--drivers/scsi/sata_mv.c6
-rw-r--r--drivers/scsi/sata_nv.c4
-rw-r--r--drivers/scsi/sata_promise.c7
-rw-r--r--drivers/scsi/sata_qstor.c11
-rw-r--r--drivers/scsi/sata_sx4.c6
-rw-r--r--drivers/scsi/sata_vsc.c15
8 files changed, 616 insertions, 324 deletions
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index 8beba3cd9a56..9de48dd4234a 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -1305,11 +1305,19 @@ static int ata_dev_configure(struct ata_port *ap, struct ata_device *dev,
1305 dev->cylinders, dev->heads, dev->sectors); 1305 dev->cylinders, dev->heads, dev->sectors);
1306 } 1306 }
1307 1307
1308 if (dev->id[59] & 0x100) {
1309 dev->multi_count = dev->id[59] & 0xff;
1310 DPRINTK("ata%u: dev %u multi count %u\n",
1311 ap->id, dev->devno, dev->multi_count);
1312 }
1313
1308 dev->cdb_len = 16; 1314 dev->cdb_len = 16;
1309 } 1315 }
1310 1316
1311 /* ATAPI-specific feature tests */ 1317 /* ATAPI-specific feature tests */
1312 else if (dev->class == ATA_DEV_ATAPI) { 1318 else if (dev->class == ATA_DEV_ATAPI) {
1319 char *cdb_intr_string = "";
1320
1313 rc = atapi_cdb_len(id); 1321 rc = atapi_cdb_len(id);
1314 if ((rc < 12) || (rc > ATAPI_CDB_LEN)) { 1322 if ((rc < 12) || (rc > ATAPI_CDB_LEN)) {
1315 printk(KERN_WARNING "ata%u: unsupported CDB len\n", ap->id); 1323 printk(KERN_WARNING "ata%u: unsupported CDB len\n", ap->id);
@@ -1318,10 +1326,16 @@ static int ata_dev_configure(struct ata_port *ap, struct ata_device *dev,
1318 } 1326 }
1319 dev->cdb_len = (unsigned int) rc; 1327 dev->cdb_len = (unsigned int) rc;
1320 1328
1329 if (ata_id_cdb_intr(dev->id)) {
1330 dev->flags |= ATA_DFLAG_CDB_INTR;
1331 cdb_intr_string = ", CDB intr";
1332 }
1333
1321 /* print device info to dmesg */ 1334 /* print device info to dmesg */
1322 if (print_info) 1335 if (print_info)
1323 printk(KERN_INFO "ata%u: dev %u ATAPI, max %s\n", 1336 printk(KERN_INFO "ata%u: dev %u ATAPI, max %s%s\n",
1324 ap->id, dev->devno, ata_mode_string(xfer_mask)); 1337 ap->id, dev->devno, ata_mode_string(xfer_mask),
1338 cdb_intr_string);
1325 } 1339 }
1326 1340
1327 ap->host->max_cmd_len = 0; 1341 ap->host->max_cmd_len = 0;
@@ -3164,6 +3178,15 @@ int ata_check_atapi_dma(struct ata_queued_cmd *qc)
3164 if (ap->ops->check_atapi_dma) 3178 if (ap->ops->check_atapi_dma)
3165 rc = ap->ops->check_atapi_dma(qc); 3179 rc = ap->ops->check_atapi_dma(qc);
3166 3180
3181 /* We don't support polling DMA.
3182 * Use PIO if the LLDD handles only interrupts in
3183 * the HSM_ST_LAST state and the ATAPI device
3184 * generates CDB interrupts.
3185 */
3186 if ((ap->flags & ATA_FLAG_PIO_POLLING) &&
3187 (qc->dev->flags & ATA_DFLAG_CDB_INTR))
3188 rc = 1;
3189
3167 return rc; 3190 return rc;
3168} 3191}
3169/** 3192/**
@@ -3406,112 +3429,12 @@ void ata_poll_qc_complete(struct ata_queued_cmd *qc)
3406 unsigned long flags; 3429 unsigned long flags;
3407 3430
3408 spin_lock_irqsave(&ap->host_set->lock, flags); 3431 spin_lock_irqsave(&ap->host_set->lock, flags);
3409 ap->flags &= ~ATA_FLAG_NOINTR;
3410 ata_irq_on(ap); 3432 ata_irq_on(ap);
3411 ata_qc_complete(qc); 3433 ata_qc_complete(qc);
3412 spin_unlock_irqrestore(&ap->host_set->lock, flags); 3434 spin_unlock_irqrestore(&ap->host_set->lock, flags);
3413} 3435}
3414 3436
3415/** 3437/**
3416 * ata_pio_poll - poll using PIO, depending on current state
3417 * @qc: qc in progress
3418 *
3419 * LOCKING:
3420 * None. (executing in kernel thread context)
3421 *
3422 * RETURNS:
3423 * timeout value to use
3424 */
3425static unsigned long ata_pio_poll(struct ata_queued_cmd *qc)
3426{
3427 struct ata_port *ap = qc->ap;
3428 u8 status;
3429 unsigned int poll_state = HSM_ST_UNKNOWN;
3430 unsigned int reg_state = HSM_ST_UNKNOWN;
3431
3432 switch (ap->hsm_task_state) {
3433 case HSM_ST:
3434 case HSM_ST_POLL:
3435 poll_state = HSM_ST_POLL;
3436 reg_state = HSM_ST;
3437 break;
3438 case HSM_ST_LAST:
3439 case HSM_ST_LAST_POLL:
3440 poll_state = HSM_ST_LAST_POLL;
3441 reg_state = HSM_ST_LAST;
3442 break;
3443 default:
3444 BUG();
3445 break;
3446 }
3447
3448 status = ata_chk_status(ap);
3449 if (status & ATA_BUSY) {
3450 if (time_after(jiffies, ap->pio_task_timeout)) {
3451 qc->err_mask |= AC_ERR_TIMEOUT;
3452 ap->hsm_task_state = HSM_ST_TMOUT;
3453 return 0;
3454 }
3455 ap->hsm_task_state = poll_state;
3456 return ATA_SHORT_PAUSE;
3457 }
3458
3459 ap->hsm_task_state = reg_state;
3460 return 0;
3461}
3462
3463/**
3464 * ata_pio_complete - check if drive is busy or idle
3465 * @qc: qc to complete
3466 *
3467 * LOCKING:
3468 * None. (executing in kernel thread context)
3469 *
3470 * RETURNS:
3471 * Non-zero if qc completed, zero otherwise.
3472 */
3473static int ata_pio_complete(struct ata_queued_cmd *qc)
3474{
3475 struct ata_port *ap = qc->ap;
3476 u8 drv_stat;
3477
3478 /*
3479 * This is purely heuristic. This is a fast path. Sometimes when
3480 * we enter, BSY will be cleared in a chk-status or two. If not,
3481 * the drive is probably seeking or something. Snooze for a couple
3482 * msecs, then chk-status again. If still busy, fall back to
3483 * HSM_ST_POLL state.
3484 */
3485 drv_stat = ata_busy_wait(ap, ATA_BUSY, 10);
3486 if (drv_stat & ATA_BUSY) {
3487 msleep(2);
3488 drv_stat = ata_busy_wait(ap, ATA_BUSY, 10);
3489 if (drv_stat & ATA_BUSY) {
3490 ap->hsm_task_state = HSM_ST_LAST_POLL;
3491 ap->pio_task_timeout = jiffies + ATA_TMOUT_PIO;
3492 return 0;
3493 }
3494 }
3495
3496 drv_stat = ata_wait_idle(ap);
3497 if (!ata_ok(drv_stat)) {
3498 qc->err_mask |= __ac_err_mask(drv_stat);
3499 ap->hsm_task_state = HSM_ST_ERR;
3500 return 0;
3501 }
3502
3503 ap->hsm_task_state = HSM_ST_IDLE;
3504
3505 WARN_ON(qc->err_mask);
3506 ata_poll_qc_complete(qc);
3507
3508 /* another command may start at this point */
3509
3510 return 1;
3511}
3512
3513
3514/**
3515 * swap_buf_le16 - swap halves of 16-bit words in place 3438 * swap_buf_le16 - swap halves of 16-bit words in place
3516 * @buf: Buffer to swap 3439 * @buf: Buffer to swap
3517 * @buf_words: Number of 16-bit words in buffer. 3440 * @buf_words: Number of 16-bit words in buffer.
@@ -3679,7 +3602,23 @@ static void ata_pio_sector(struct ata_queued_cmd *qc)
3679 page = nth_page(page, (offset >> PAGE_SHIFT)); 3602 page = nth_page(page, (offset >> PAGE_SHIFT));
3680 offset %= PAGE_SIZE; 3603 offset %= PAGE_SIZE;
3681 3604
3682 buf = kmap(page) + offset; 3605 DPRINTK("data %s\n", qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read");
3606
3607 if (PageHighMem(page)) {
3608 unsigned long flags;
3609
3610 local_irq_save(flags);
3611 buf = kmap_atomic(page, KM_IRQ0);
3612
3613 /* do the actual data transfer */
3614 ata_data_xfer(ap, buf + offset, ATA_SECT_SIZE, do_write);
3615
3616 kunmap_atomic(buf, KM_IRQ0);
3617 local_irq_restore(flags);
3618 } else {
3619 buf = page_address(page);
3620 ata_data_xfer(ap, buf + offset, ATA_SECT_SIZE, do_write);
3621 }
3683 3622
3684 qc->cursect++; 3623 qc->cursect++;
3685 qc->cursg_ofs++; 3624 qc->cursg_ofs++;
@@ -3688,14 +3627,68 @@ static void ata_pio_sector(struct ata_queued_cmd *qc)
3688 qc->cursg++; 3627 qc->cursg++;
3689 qc->cursg_ofs = 0; 3628 qc->cursg_ofs = 0;
3690 } 3629 }
3630}
3691 3631
3692 DPRINTK("data %s\n", qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read"); 3632/**
3633 * ata_pio_sectors - Transfer one or many 512-byte sectors.
3634 * @qc: Command on going
3635 *
3636 * Transfer one or many ATA_SECT_SIZE of data from/to the
3637 * ATA device for the DRQ request.
3638 *
3639 * LOCKING:
3640 * Inherited from caller.
3641 */
3642
3643static void ata_pio_sectors(struct ata_queued_cmd *qc)
3644{
3645 if (is_multi_taskfile(&qc->tf)) {
3646 /* READ/WRITE MULTIPLE */
3647 unsigned int nsect;
3648
3649 WARN_ON(qc->dev->multi_count == 0);
3650
3651 nsect = min(qc->nsect - qc->cursect, qc->dev->multi_count);
3652 while (nsect--)
3653 ata_pio_sector(qc);
3654 } else
3655 ata_pio_sector(qc);
3656}
3657
3658/**
3659 * atapi_send_cdb - Write CDB bytes to hardware
3660 * @ap: Port to which ATAPI device is attached.
3661 * @qc: Taskfile currently active
3662 *
3663 * When device has indicated its readiness to accept
3664 * a CDB, this function is called. Send the CDB.
3665 *
3666 * LOCKING:
3667 * caller.
3668 */
3669
3670static void atapi_send_cdb(struct ata_port *ap, struct ata_queued_cmd *qc)
3671{
3672 /* send SCSI cdb */
3673 DPRINTK("send cdb\n");
3674 WARN_ON(qc->dev->cdb_len < 12);
3693 3675
3694 /* do the actual data transfer */ 3676 ata_data_xfer(ap, qc->cdb, qc->dev->cdb_len, 1);
3695 do_write = (qc->tf.flags & ATA_TFLAG_WRITE); 3677 ata_altstatus(ap); /* flush */
3696 ata_data_xfer(ap, buf, ATA_SECT_SIZE, do_write);
3697 3678
3698 kunmap(page); 3679 switch (qc->tf.protocol) {
3680 case ATA_PROT_ATAPI:
3681 ap->hsm_task_state = HSM_ST;
3682 break;
3683 case ATA_PROT_ATAPI_NODATA:
3684 ap->hsm_task_state = HSM_ST_LAST;
3685 break;
3686 case ATA_PROT_ATAPI_DMA:
3687 ap->hsm_task_state = HSM_ST_LAST;
3688 /* initiate bmdma */
3689 ap->ops->bmdma_start(qc);
3690 break;
3691 }
3699} 3692}
3700 3693
3701/** 3694/**
@@ -3761,7 +3754,23 @@ next_sg:
3761 /* don't cross page boundaries */ 3754 /* don't cross page boundaries */
3762 count = min(count, (unsigned int)PAGE_SIZE - offset); 3755 count = min(count, (unsigned int)PAGE_SIZE - offset);
3763 3756
3764 buf = kmap(page) + offset; 3757 DPRINTK("data %s\n", qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read");
3758
3759 if (PageHighMem(page)) {
3760 unsigned long flags;
3761
3762 local_irq_save(flags);
3763 buf = kmap_atomic(page, KM_IRQ0);
3764
3765 /* do the actual data transfer */
3766 ata_data_xfer(ap, buf + offset, count, do_write);
3767
3768 kunmap_atomic(buf, KM_IRQ0);
3769 local_irq_restore(flags);
3770 } else {
3771 buf = page_address(page);
3772 ata_data_xfer(ap, buf + offset, count, do_write);
3773 }
3765 3774
3766 bytes -= count; 3775 bytes -= count;
3767 qc->curbytes += count; 3776 qc->curbytes += count;
@@ -3772,13 +3781,6 @@ next_sg:
3772 qc->cursg_ofs = 0; 3781 qc->cursg_ofs = 0;
3773 } 3782 }
3774 3783
3775 DPRINTK("data %s\n", qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read");
3776
3777 /* do the actual data transfer */
3778 ata_data_xfer(ap, buf, count, do_write);
3779
3780 kunmap(page);
3781
3782 if (bytes) 3784 if (bytes)
3783 goto next_sg; 3785 goto next_sg;
3784} 3786}
@@ -3815,6 +3817,8 @@ static void atapi_pio_bytes(struct ata_queued_cmd *qc)
3815 if (do_write != i_write) 3817 if (do_write != i_write)
3816 goto err_out; 3818 goto err_out;
3817 3819
3820 VPRINTK("ata%u: xfering %d bytes\n", ap->id, bytes);
3821
3818 __atapi_pio_bytes(qc, bytes); 3822 __atapi_pio_bytes(qc, bytes);
3819 3823
3820 return; 3824 return;
@@ -3827,187 +3831,392 @@ err_out:
3827} 3831}
3828 3832
3829/** 3833/**
3830 * ata_pio_block - start PIO on a block 3834 * ata_hsm_ok_in_wq - Check if the qc can be handled in the workqueue.
3831 * @qc: qc to transfer block for 3835 * @ap: the target ata_port
3836 * @qc: qc on going
3832 * 3837 *
3833 * LOCKING: 3838 * RETURNS:
3834 * None. (executing in kernel thread context) 3839 * 1 if ok in workqueue, 0 otherwise.
3835 */ 3840 */
3836static void ata_pio_block(struct ata_queued_cmd *qc) 3841
3842static inline int ata_hsm_ok_in_wq(struct ata_port *ap, struct ata_queued_cmd *qc)
3837{ 3843{
3838 struct ata_port *ap = qc->ap; 3844 if (qc->tf.flags & ATA_TFLAG_POLLING)
3839 u8 status; 3845 return 1;
3840 3846
3841 /* 3847 if (ap->hsm_task_state == HSM_ST_FIRST) {
3842 * This is purely heuristic. This is a fast path. 3848 if (qc->tf.protocol == ATA_PROT_PIO &&
3843 * Sometimes when we enter, BSY will be cleared in 3849 (qc->tf.flags & ATA_TFLAG_WRITE))
3844 * a chk-status or two. If not, the drive is probably seeking 3850 return 1;
3845 * or something. Snooze for a couple msecs, then
3846 * chk-status again. If still busy, fall back to
3847 * HSM_ST_POLL state.
3848 */
3849 status = ata_busy_wait(ap, ATA_BUSY, 5);
3850 if (status & ATA_BUSY) {
3851 msleep(2);
3852 status = ata_busy_wait(ap, ATA_BUSY, 10);
3853 if (status & ATA_BUSY) {
3854 ap->hsm_task_state = HSM_ST_POLL;
3855 ap->pio_task_timeout = jiffies + ATA_TMOUT_PIO;
3856 return;
3857 }
3858 }
3859 3851
3860 /* check error */ 3852 if (is_atapi_taskfile(&qc->tf) &&
3861 if (status & (ATA_ERR | ATA_DF)) { 3853 !(qc->dev->flags & ATA_DFLAG_CDB_INTR))
3862 qc->err_mask |= AC_ERR_DEV; 3854 return 1;
3863 ap->hsm_task_state = HSM_ST_ERR;
3864 return;
3865 } 3855 }
3866 3856
3867 /* transfer data if any */ 3857 return 0;
3868 if (is_atapi_taskfile(&qc->tf)) { 3858}
3869 /* DRQ=0 means no more data to transfer */
3870 if ((status & ATA_DRQ) == 0) {
3871 ap->hsm_task_state = HSM_ST_LAST;
3872 return;
3873 }
3874 3859
3875 atapi_pio_bytes(qc); 3860/**
3876 } else { 3861 * ata_hsm_move - move the HSM to the next state.
3877 /* handle BSY=0, DRQ=0 as error */ 3862 * @ap: the target ata_port
3878 if ((status & ATA_DRQ) == 0) { 3863 * @qc: qc on going
3864 * @status: current device status
3865 * @in_wq: 1 if called from workqueue, 0 otherwise
3866 *
3867 * RETURNS:
3868 * 1 when poll next status needed, 0 otherwise.
3869 */
3870
3871static int ata_hsm_move(struct ata_port *ap, struct ata_queued_cmd *qc,
3872 u8 status, int in_wq)
3873{
3874 unsigned long flags = 0;
3875 int poll_next;
3876
3877 WARN_ON((qc->flags & ATA_QCFLAG_ACTIVE) == 0);
3878
3879 /* Make sure ata_qc_issue_prot() does not throw things
3880 * like DMA polling into the workqueue. Notice that
3881 * in_wq is not equivalent to (qc->tf.flags & ATA_TFLAG_POLLING).
3882 */
3883 WARN_ON(in_wq != ata_hsm_ok_in_wq(ap, qc));
3884
3885fsm_start:
3886 DPRINTK("ata%u: protocol %d task_state %d (dev_stat 0x%X)\n",
3887 ap->id, qc->tf.protocol, ap->hsm_task_state, status);
3888
3889 switch (ap->hsm_task_state) {
3890 case HSM_ST_FIRST:
3891 /* Send first data block or PACKET CDB */
3892
3893 /* If polling, we will stay in the work queue after
3894 * sending the data. Otherwise, interrupt handler
3895 * takes over after sending the data.
3896 */
3897 poll_next = (qc->tf.flags & ATA_TFLAG_POLLING);
3898
3899 /* check device status */
3900 if (unlikely((status & (ATA_BUSY | ATA_DRQ)) != ATA_DRQ)) {
3901 /* Wrong status. Let EH handle this */
3879 qc->err_mask |= AC_ERR_HSM; 3902 qc->err_mask |= AC_ERR_HSM;
3880 ap->hsm_task_state = HSM_ST_ERR; 3903 ap->hsm_task_state = HSM_ST_ERR;
3881 return; 3904 goto fsm_start;
3882 } 3905 }
3883 3906
3884 ata_pio_sector(qc); 3907 /* Device should not ask for data transfer (DRQ=1)
3885 } 3908 * when it finds something wrong.
3886} 3909 * We ignore DRQ here and stop the HSM by
3910 * changing hsm_task_state to HSM_ST_ERR and
3911 * let the EH abort the command or reset the device.
3912 */
3913 if (unlikely(status & (ATA_ERR | ATA_DF))) {
3914 printk(KERN_WARNING "ata%d: DRQ=1 with device error, dev_stat 0x%X\n",
3915 ap->id, status);
3916 qc->err_mask |= AC_ERR_DEV;
3917 ap->hsm_task_state = HSM_ST_ERR;
3918 goto fsm_start;
3919 }
3887 3920
3888static void ata_pio_error(struct ata_queued_cmd *qc) 3921 /* Send the CDB (atapi) or the first data block (ata pio out).
3889{ 3922 * During the state transition, interrupt handler shouldn't
3890 struct ata_port *ap = qc->ap; 3923 * be invoked before the data transfer is complete and
3924 * hsm_task_state is changed. Hence, the following locking.
3925 */
3926 if (in_wq)
3927 spin_lock_irqsave(&ap->host_set->lock, flags);
3891 3928
3892 if (qc->tf.command != ATA_CMD_PACKET) 3929 if (qc->tf.protocol == ATA_PROT_PIO) {
3893 printk(KERN_WARNING "ata%u: dev %u PIO error\n", 3930 /* PIO data out protocol.
3894 ap->id, qc->dev->devno); 3931 * send first data block.
3932 */
3895 3933
3896 /* make sure qc->err_mask is available to 3934 /* ata_pio_sectors() might change the state
3897 * know what's wrong and recover 3935 * to HSM_ST_LAST. so, the state is changed here
3898 */ 3936 * before ata_pio_sectors().
3899 WARN_ON(qc->err_mask == 0); 3937 */
3938 ap->hsm_task_state = HSM_ST;
3939 ata_pio_sectors(qc);
3940 ata_altstatus(ap); /* flush */
3941 } else
3942 /* send CDB */
3943 atapi_send_cdb(ap, qc);
3944
3945 if (in_wq)
3946 spin_unlock_irqrestore(&ap->host_set->lock, flags);
3947
3948 /* if polling, ata_pio_task() handles the rest.
3949 * otherwise, interrupt handler takes over from here.
3950 */
3951 break;
3900 3952
3901 ap->hsm_task_state = HSM_ST_IDLE; 3953 case HSM_ST:
3954 /* complete command or read/write the data register */
3955 if (qc->tf.protocol == ATA_PROT_ATAPI) {
3956 /* ATAPI PIO protocol */
3957 if ((status & ATA_DRQ) == 0) {
3958 /* no more data to transfer */
3959 ap->hsm_task_state = HSM_ST_LAST;
3960 goto fsm_start;
3961 }
3902 3962
3903 ata_poll_qc_complete(qc); 3963 /* Device should not ask for data transfer (DRQ=1)
3904} 3964 * when it finds something wrong.
3965 * We ignore DRQ here and stop the HSM by
3966 * changing hsm_task_state to HSM_ST_ERR and
3967 * let the EH abort the command or reset the device.
3968 */
3969 if (unlikely(status & (ATA_ERR | ATA_DF))) {
3970 printk(KERN_WARNING "ata%d: DRQ=1 with device error, dev_stat 0x%X\n",
3971 ap->id, status);
3972 qc->err_mask |= AC_ERR_DEV;
3973 ap->hsm_task_state = HSM_ST_ERR;
3974 goto fsm_start;
3975 }
3905 3976
3906static void ata_pio_task(void *_data) 3977 atapi_pio_bytes(qc);
3907{
3908 struct ata_queued_cmd *qc = _data;
3909 struct ata_port *ap = qc->ap;
3910 unsigned long timeout;
3911 int qc_completed;
3912 3978
3913fsm_start: 3979 if (unlikely(ap->hsm_task_state == HSM_ST_ERR))
3914 timeout = 0; 3980 /* bad ireason reported by device */
3915 qc_completed = 0; 3981 goto fsm_start;
3916 3982
3917 switch (ap->hsm_task_state) { 3983 } else {
3918 case HSM_ST_IDLE: 3984 /* ATA PIO protocol */
3919 return; 3985 if (unlikely((status & ATA_DRQ) == 0)) {
3986 /* handle BSY=0, DRQ=0 as error */
3987 qc->err_mask |= AC_ERR_HSM;
3988 ap->hsm_task_state = HSM_ST_ERR;
3989 goto fsm_start;
3990 }
3920 3991
3921 case HSM_ST: 3992 /* For PIO reads, some devices may ask for
3922 ata_pio_block(qc); 3993 * data transfer (DRQ=1) alone with ERR=1.
3994 * We respect DRQ here and transfer one
3995 * block of junk data before changing the
3996 * hsm_task_state to HSM_ST_ERR.
3997 *
3998 * For PIO writes, ERR=1 DRQ=1 doesn't make
3999 * sense since the data block has been
4000 * transferred to the device.
4001 */
4002 if (unlikely(status & (ATA_ERR | ATA_DF))) {
4003 /* data might be corrputed */
4004 qc->err_mask |= AC_ERR_DEV;
4005
4006 if (!(qc->tf.flags & ATA_TFLAG_WRITE)) {
4007 ata_pio_sectors(qc);
4008 ata_altstatus(ap);
4009 status = ata_wait_idle(ap);
4010 }
4011
4012 /* ata_pio_sectors() might change the
4013 * state to HSM_ST_LAST. so, the state
4014 * is changed after ata_pio_sectors().
4015 */
4016 ap->hsm_task_state = HSM_ST_ERR;
4017 goto fsm_start;
4018 }
4019
4020 ata_pio_sectors(qc);
4021
4022 if (ap->hsm_task_state == HSM_ST_LAST &&
4023 (!(qc->tf.flags & ATA_TFLAG_WRITE))) {
4024 /* all data read */
4025 ata_altstatus(ap);
4026 status = ata_wait_idle(ap);
4027 goto fsm_start;
4028 }
4029 }
4030
4031 ata_altstatus(ap); /* flush */
4032 poll_next = 1;
3923 break; 4033 break;
3924 4034
3925 case HSM_ST_LAST: 4035 case HSM_ST_LAST:
3926 qc_completed = ata_pio_complete(qc); 4036 if (unlikely(!ata_ok(status))) {
3927 break; 4037 qc->err_mask |= __ac_err_mask(status);
4038 ap->hsm_task_state = HSM_ST_ERR;
4039 goto fsm_start;
4040 }
4041
4042 /* no more data to transfer */
4043 DPRINTK("ata%u: command complete, drv_stat 0x%x\n",
4044 ap->id, status);
4045
4046 WARN_ON(qc->err_mask);
3928 4047
3929 case HSM_ST_POLL: 4048 ap->hsm_task_state = HSM_ST_IDLE;
3930 case HSM_ST_LAST_POLL: 4049
3931 timeout = ata_pio_poll(qc); 4050 /* complete taskfile transaction */
4051 if (in_wq)
4052 ata_poll_qc_complete(qc);
4053 else
4054 ata_qc_complete(qc);
4055
4056 poll_next = 0;
3932 break; 4057 break;
3933 4058
3934 case HSM_ST_TMOUT:
3935 case HSM_ST_ERR: 4059 case HSM_ST_ERR:
3936 ata_pio_error(qc); 4060 if (qc->tf.command != ATA_CMD_PACKET)
3937 return; 4061 printk(KERN_ERR "ata%u: command error, drv_stat 0x%x\n",
4062 ap->id, status);
4063
4064 /* make sure qc->err_mask is available to
4065 * know what's wrong and recover
4066 */
4067 WARN_ON(qc->err_mask == 0);
4068
4069 ap->hsm_task_state = HSM_ST_IDLE;
4070
4071 /* complete taskfile transaction */
4072 if (in_wq)
4073 ata_poll_qc_complete(qc);
4074 else
4075 ata_qc_complete(qc);
4076
4077 poll_next = 0;
4078 break;
4079 default:
4080 poll_next = 0;
4081 BUG();
4082 }
4083
4084 return poll_next;
4085}
4086
4087static void ata_pio_task(void *_data)
4088{
4089 struct ata_queued_cmd *qc = _data;
4090 struct ata_port *ap = qc->ap;
4091 u8 status;
4092 int poll_next;
4093
4094fsm_start:
4095 WARN_ON(ap->hsm_task_state == HSM_ST_IDLE);
4096
4097 qc = ata_qc_from_tag(ap, ap->active_tag);
4098 WARN_ON(qc == NULL);
4099
4100 /*
4101 * This is purely heuristic. This is a fast path.
4102 * Sometimes when we enter, BSY will be cleared in
4103 * a chk-status or two. If not, the drive is probably seeking
4104 * or something. Snooze for a couple msecs, then
4105 * chk-status again. If still busy, queue delayed work.
4106 */
4107 status = ata_busy_wait(ap, ATA_BUSY, 5);
4108 if (status & ATA_BUSY) {
4109 msleep(2);
4110 status = ata_busy_wait(ap, ATA_BUSY, 10);
4111 if (status & ATA_BUSY) {
4112 ata_port_queue_task(ap, ata_pio_task, ap, ATA_SHORT_PAUSE);
4113 return;
4114 }
3938 } 4115 }
3939 4116
3940 if (timeout) 4117 /* move the HSM */
3941 ata_port_queue_task(ap, ata_pio_task, qc, timeout); 4118 poll_next = ata_hsm_move(ap, qc, status, 1);
3942 else if (!qc_completed) 4119
4120 /* another command or interrupt handler
4121 * may be running at this point.
4122 */
4123 if (poll_next)
3943 goto fsm_start; 4124 goto fsm_start;
3944} 4125}
3945 4126
3946/** 4127/**
3947 * atapi_packet_task - Write CDB bytes to hardware 4128 * ata_qc_timeout - Handle timeout of queued command
3948 * @_data: qc in progress 4129 * @qc: Command that timed out
3949 * 4130 *
3950 * When device has indicated its readiness to accept 4131 * Some part of the kernel (currently, only the SCSI layer)
3951 * a CDB, this function is called. Send the CDB. 4132 * has noticed that the active command on port @ap has not
3952 * If DMA is to be performed, exit immediately. 4133 * completed after a specified length of time. Handle this
3953 * Otherwise, we are in polling mode, so poll 4134 * condition by disabling DMA (if necessary) and completing
3954 * status under operation succeeds or fails. 4135 * transactions, with error if necessary.
4136 *
4137 * This also handles the case of the "lost interrupt", where
4138 * for some reason (possibly hardware bug, possibly driver bug)
4139 * an interrupt was not delivered to the driver, even though the
4140 * transaction completed successfully.
3955 * 4141 *
3956 * LOCKING: 4142 * LOCKING:
3957 * Kernel thread context (may sleep) 4143 * Inherited from SCSI layer (none, can sleep)
3958 */ 4144 */
3959static void atapi_packet_task(void *_data) 4145
4146static void ata_qc_timeout(struct ata_queued_cmd *qc)
3960{ 4147{
3961 struct ata_queued_cmd *qc = _data;
3962 struct ata_port *ap = qc->ap; 4148 struct ata_port *ap = qc->ap;
3963 u8 status; 4149 struct ata_host_set *host_set = ap->host_set;
4150 u8 host_stat = 0, drv_stat;
4151 unsigned long flags;
4152
4153 DPRINTK("ENTER\n");
4154
4155 ap->hsm_task_state = HSM_ST_IDLE;
4156
4157 spin_lock_irqsave(&host_set->lock, flags);
3964 4158
3965 /* sleep-wait for BSY to clear */ 4159 switch (qc->tf.protocol) {
3966 DPRINTK("busy wait\n"); 4160
3967 if (ata_busy_sleep(ap, ATA_TMOUT_CDB_QUICK, ATA_TMOUT_CDB)) { 4161 case ATA_PROT_DMA:
4162 case ATA_PROT_ATAPI_DMA:
4163 host_stat = ap->ops->bmdma_status(ap);
4164
4165 /* before we do anything else, clear DMA-Start bit */
4166 ap->ops->bmdma_stop(qc);
4167
4168 /* fall through */
4169
4170 default:
4171 ata_altstatus(ap);
4172 drv_stat = ata_chk_status(ap);
4173
4174 /* ack bmdma irq events */
4175 ap->ops->irq_clear(ap);
4176
4177 printk(KERN_ERR "ata%u: command 0x%x timeout, stat 0x%x host_stat 0x%x\n",
4178 ap->id, qc->tf.command, drv_stat, host_stat);
4179
4180 ap->hsm_task_state = HSM_ST_IDLE;
4181
4182 /* complete taskfile transaction */
3968 qc->err_mask |= AC_ERR_TIMEOUT; 4183 qc->err_mask |= AC_ERR_TIMEOUT;
3969 goto err_out; 4184 break;
3970 } 4185 }
3971 4186
3972 /* make sure DRQ is set */ 4187 spin_unlock_irqrestore(&host_set->lock, flags);
3973 status = ata_chk_status(ap);
3974 if ((status & (ATA_BUSY | ATA_DRQ)) != ATA_DRQ) {
3975 qc->err_mask |= AC_ERR_HSM;
3976 goto err_out;
3977 }
3978 4188
3979 /* send SCSI cdb */ 4189 ata_eh_qc_complete(qc);
3980 DPRINTK("send cdb\n");
3981 WARN_ON(qc->dev->cdb_len < 12);
3982 4190
3983 if (qc->tf.protocol == ATA_PROT_ATAPI_DMA || 4191 DPRINTK("EXIT\n");
3984 qc->tf.protocol == ATA_PROT_ATAPI_NODATA) { 4192}
3985 unsigned long flags;
3986 4193
3987 /* Once we're done issuing command and kicking bmdma, 4194/**
3988 * irq handler takes over. To not lose irq, we need 4195 * ata_eng_timeout - Handle timeout of queued command
3989 * to clear NOINTR flag before sending cdb, but 4196 * @ap: Port on which timed-out command is active
3990 * interrupt handler shouldn't be invoked before we're 4197 *
3991 * finished. Hence, the following locking. 4198 * Some part of the kernel (currently, only the SCSI layer)
3992 */ 4199 * has noticed that the active command on port @ap has not
3993 spin_lock_irqsave(&ap->host_set->lock, flags); 4200 * completed after a specified length of time. Handle this
3994 ap->flags &= ~ATA_FLAG_NOINTR; 4201 * condition by disabling DMA (if necessary) and completing
3995 ata_data_xfer(ap, qc->cdb, qc->dev->cdb_len, 1); 4202 * transactions, with error if necessary.
3996 if (qc->tf.protocol == ATA_PROT_ATAPI_DMA) 4203 *
3997 ap->ops->bmdma_start(qc); /* initiate bmdma */ 4204 * This also handles the case of the "lost interrupt", where
3998 spin_unlock_irqrestore(&ap->host_set->lock, flags); 4205 * for some reason (possibly hardware bug, possibly driver bug)
3999 } else { 4206 * an interrupt was not delivered to the driver, even though the
4000 ata_data_xfer(ap, qc->cdb, qc->dev->cdb_len, 1); 4207 * transaction completed successfully.
4208 *
4209 * LOCKING:
4210 * Inherited from SCSI layer (none, can sleep)
4211 */
4001 4212
4002 /* PIO commands are handled by polling */ 4213void ata_eng_timeout(struct ata_port *ap)
4003 ap->hsm_task_state = HSM_ST; 4214{
4004 ata_port_queue_task(ap, ata_pio_task, qc, 0); 4215 DPRINTK("ENTER\n");
4005 }
4006 4216
4007 return; 4217 ata_qc_timeout(ata_qc_from_tag(ap, ap->active_tag));
4008 4218
4009err_out: 4219 DPRINTK("EXIT\n");
4010 ata_poll_qc_complete(qc);
4011} 4220}
4012 4221
4013/** 4222/**
@@ -4197,43 +4406,105 @@ unsigned int ata_qc_issue_prot(struct ata_queued_cmd *qc)
4197{ 4406{
4198 struct ata_port *ap = qc->ap; 4407 struct ata_port *ap = qc->ap;
4199 4408
4409 /* Use polling pio if the LLD doesn't handle
4410 * interrupt driven pio and atapi CDB interrupt.
4411 */
4412 if (ap->flags & ATA_FLAG_PIO_POLLING) {
4413 switch (qc->tf.protocol) {
4414 case ATA_PROT_PIO:
4415 case ATA_PROT_ATAPI:
4416 case ATA_PROT_ATAPI_NODATA:
4417 qc->tf.flags |= ATA_TFLAG_POLLING;
4418 break;
4419 case ATA_PROT_ATAPI_DMA:
4420 if (qc->dev->flags & ATA_DFLAG_CDB_INTR)
4421 /* see ata_check_atapi_dma() */
4422 BUG();
4423 break;
4424 default:
4425 break;
4426 }
4427 }
4428
4429 /* select the device */
4200 ata_dev_select(ap, qc->dev->devno, 1, 0); 4430 ata_dev_select(ap, qc->dev->devno, 1, 0);
4201 4431
4432 /* start the command */
4202 switch (qc->tf.protocol) { 4433 switch (qc->tf.protocol) {
4203 case ATA_PROT_NODATA: 4434 case ATA_PROT_NODATA:
4435 if (qc->tf.flags & ATA_TFLAG_POLLING)
4436 ata_qc_set_polling(qc);
4437
4204 ata_tf_to_host(ap, &qc->tf); 4438 ata_tf_to_host(ap, &qc->tf);
4439 ap->hsm_task_state = HSM_ST_LAST;
4440
4441 if (qc->tf.flags & ATA_TFLAG_POLLING)
4442 ata_port_queue_task(ap, ata_pio_task, ap, 0);
4443
4205 break; 4444 break;
4206 4445
4207 case ATA_PROT_DMA: 4446 case ATA_PROT_DMA:
4447 WARN_ON(qc->tf.flags & ATA_TFLAG_POLLING);
4448
4208 ap->ops->tf_load(ap, &qc->tf); /* load tf registers */ 4449 ap->ops->tf_load(ap, &qc->tf); /* load tf registers */
4209 ap->ops->bmdma_setup(qc); /* set up bmdma */ 4450 ap->ops->bmdma_setup(qc); /* set up bmdma */
4210 ap->ops->bmdma_start(qc); /* initiate bmdma */ 4451 ap->ops->bmdma_start(qc); /* initiate bmdma */
4452 ap->hsm_task_state = HSM_ST_LAST;
4211 break; 4453 break;
4212 4454
4213 case ATA_PROT_PIO: /* load tf registers, initiate polling pio */ 4455 case ATA_PROT_PIO:
4214 ata_qc_set_polling(qc); 4456 if (qc->tf.flags & ATA_TFLAG_POLLING)
4215 ata_tf_to_host(ap, &qc->tf); 4457 ata_qc_set_polling(qc);
4216 ap->hsm_task_state = HSM_ST;
4217 ata_port_queue_task(ap, ata_pio_task, qc, 0);
4218 break;
4219 4458
4220 case ATA_PROT_ATAPI:
4221 ata_qc_set_polling(qc);
4222 ata_tf_to_host(ap, &qc->tf); 4459 ata_tf_to_host(ap, &qc->tf);
4223 ata_port_queue_task(ap, atapi_packet_task, qc, 0); 4460
4461 if (qc->tf.flags & ATA_TFLAG_WRITE) {
4462 /* PIO data out protocol */
4463 ap->hsm_task_state = HSM_ST_FIRST;
4464 ata_port_queue_task(ap, ata_pio_task, ap, 0);
4465
4466 /* always send first data block using
4467 * the ata_pio_task() codepath.
4468 */
4469 } else {
4470 /* PIO data in protocol */
4471 ap->hsm_task_state = HSM_ST;
4472
4473 if (qc->tf.flags & ATA_TFLAG_POLLING)
4474 ata_port_queue_task(ap, ata_pio_task, ap, 0);
4475
4476 /* if polling, ata_pio_task() handles the rest.
4477 * otherwise, interrupt handler takes over from here.
4478 */
4479 }
4480
4224 break; 4481 break;
4225 4482
4483 case ATA_PROT_ATAPI:
4226 case ATA_PROT_ATAPI_NODATA: 4484 case ATA_PROT_ATAPI_NODATA:
4227 ap->flags |= ATA_FLAG_NOINTR; 4485 if (qc->tf.flags & ATA_TFLAG_POLLING)
4486 ata_qc_set_polling(qc);
4487
4228 ata_tf_to_host(ap, &qc->tf); 4488 ata_tf_to_host(ap, &qc->tf);
4229 ata_port_queue_task(ap, atapi_packet_task, qc, 0); 4489
4490 ap->hsm_task_state = HSM_ST_FIRST;
4491
4492 /* send cdb by polling if no cdb interrupt */
4493 if ((!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) ||
4494 (qc->tf.flags & ATA_TFLAG_POLLING))
4495 ata_port_queue_task(ap, ata_pio_task, ap, 0);
4230 break; 4496 break;
4231 4497
4232 case ATA_PROT_ATAPI_DMA: 4498 case ATA_PROT_ATAPI_DMA:
4233 ap->flags |= ATA_FLAG_NOINTR; 4499 WARN_ON(qc->tf.flags & ATA_TFLAG_POLLING);
4500
4234 ap->ops->tf_load(ap, &qc->tf); /* load tf registers */ 4501 ap->ops->tf_load(ap, &qc->tf); /* load tf registers */
4235 ap->ops->bmdma_setup(qc); /* set up bmdma */ 4502 ap->ops->bmdma_setup(qc); /* set up bmdma */
4236 ata_port_queue_task(ap, atapi_packet_task, qc, 0); 4503 ap->hsm_task_state = HSM_ST_FIRST;
4504
4505 /* send cdb by polling if no cdb interrupt */
4506 if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR))
4507 ata_port_queue_task(ap, ata_pio_task, ap, 0);
4237 break; 4508 break;
4238 4509
4239 default: 4510 default:
@@ -4263,52 +4534,66 @@ unsigned int ata_qc_issue_prot(struct ata_queued_cmd *qc)
4263inline unsigned int ata_host_intr (struct ata_port *ap, 4534inline unsigned int ata_host_intr (struct ata_port *ap,
4264 struct ata_queued_cmd *qc) 4535 struct ata_queued_cmd *qc)
4265{ 4536{
4266 u8 status, host_stat; 4537 u8 status, host_stat = 0;
4267 4538
4268 switch (qc->tf.protocol) { 4539 VPRINTK("ata%u: protocol %d task_state %d\n",
4540 ap->id, qc->tf.protocol, ap->hsm_task_state);
4269 4541
4270 case ATA_PROT_DMA: 4542 /* Check whether we are expecting interrupt in this state */
4271 case ATA_PROT_ATAPI_DMA: 4543 switch (ap->hsm_task_state) {
4272 case ATA_PROT_ATAPI: 4544 case HSM_ST_FIRST:
4273 /* check status of DMA engine */ 4545 /* Some pre-ATAPI-4 devices assert INTRQ
4274 host_stat = ap->ops->bmdma_status(ap); 4546 * at this state when ready to receive CDB.
4275 VPRINTK("ata%u: host_stat 0x%X\n", ap->id, host_stat); 4547 */
4276
4277 /* if it's not our irq... */
4278 if (!(host_stat & ATA_DMA_INTR))
4279 goto idle_irq;
4280
4281 /* before we do anything else, clear DMA-Start bit */
4282 ap->ops->bmdma_stop(qc);
4283
4284 /* fall through */
4285
4286 case ATA_PROT_ATAPI_NODATA:
4287 case ATA_PROT_NODATA:
4288 /* check altstatus */
4289 status = ata_altstatus(ap);
4290 if (status & ATA_BUSY)
4291 goto idle_irq;
4292 4548
4293 /* check main status, clearing INTRQ */ 4549 /* Check the ATA_DFLAG_CDB_INTR flag is enough here.
4294 status = ata_chk_status(ap); 4550 * The flag was turned on only for atapi devices.
4295 if (unlikely(status & ATA_BUSY)) 4551 * No need to check is_atapi_taskfile(&qc->tf) again.
4552 */
4553 if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR))
4296 goto idle_irq; 4554 goto idle_irq;
4297 DPRINTK("ata%u: protocol %d (dev_stat 0x%X)\n",
4298 ap->id, qc->tf.protocol, status);
4299
4300 /* ack bmdma irq events */
4301 ap->ops->irq_clear(ap);
4302
4303 /* complete taskfile transaction */
4304 qc->err_mask |= ac_err_mask(status);
4305 ata_qc_complete(qc);
4306 break; 4555 break;
4307 4556 case HSM_ST_LAST:
4557 if (qc->tf.protocol == ATA_PROT_DMA ||
4558 qc->tf.protocol == ATA_PROT_ATAPI_DMA) {
4559 /* check status of DMA engine */
4560 host_stat = ap->ops->bmdma_status(ap);
4561 VPRINTK("ata%u: host_stat 0x%X\n", ap->id, host_stat);
4562
4563 /* if it's not our irq... */
4564 if (!(host_stat & ATA_DMA_INTR))
4565 goto idle_irq;
4566
4567 /* before we do anything else, clear DMA-Start bit */
4568 ap->ops->bmdma_stop(qc);
4569
4570 if (unlikely(host_stat & ATA_DMA_ERR)) {
4571 /* error when transfering data to/from memory */
4572 qc->err_mask |= AC_ERR_HOST_BUS;
4573 ap->hsm_task_state = HSM_ST_ERR;
4574 }
4575 }
4576 break;
4577 case HSM_ST:
4578 break;
4308 default: 4579 default:
4309 goto idle_irq; 4580 goto idle_irq;
4310 } 4581 }
4311 4582
4583 /* check altstatus */
4584 status = ata_altstatus(ap);
4585 if (status & ATA_BUSY)
4586 goto idle_irq;
4587
4588 /* check main status, clearing INTRQ */
4589 status = ata_chk_status(ap);
4590 if (unlikely(status & ATA_BUSY))
4591 goto idle_irq;
4592
4593 /* ack bmdma irq events */
4594 ap->ops->irq_clear(ap);
4595
4596 ata_hsm_move(ap, qc, status, 0);
4312 return 1; /* irq handled */ 4597 return 1; /* irq handled */
4313 4598
4314idle_irq: 4599idle_irq:
@@ -4355,11 +4640,11 @@ irqreturn_t ata_interrupt (int irq, void *dev_instance, struct pt_regs *regs)
4355 4640
4356 ap = host_set->ports[i]; 4641 ap = host_set->ports[i];
4357 if (ap && 4642 if (ap &&
4358 !(ap->flags & (ATA_FLAG_DISABLED | ATA_FLAG_NOINTR))) { 4643 !(ap->flags & ATA_FLAG_DISABLED)) {
4359 struct ata_queued_cmd *qc; 4644 struct ata_queued_cmd *qc;
4360 4645
4361 qc = ata_qc_from_tag(ap, ap->active_tag); 4646 qc = ata_qc_from_tag(ap, ap->active_tag);
4362 if (qc && (!(qc->tf.ctl & ATA_NIEN)) && 4647 if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)) &&
4363 (qc->flags & ATA_QCFLAG_ACTIVE)) 4648 (qc->flags & ATA_QCFLAG_ACTIVE))
4364 handled |= ata_host_intr(ap, qc); 4649 handled |= ata_host_intr(ap, qc);
4365 } 4650 }
diff --git a/drivers/scsi/pdc_adma.c b/drivers/scsi/pdc_adma.c
index d64073dd028f..a4dcb4352206 100644
--- a/drivers/scsi/pdc_adma.c
+++ b/drivers/scsi/pdc_adma.c
@@ -456,13 +456,13 @@ static inline unsigned int adma_intr_pkt(struct ata_host_set *host_set)
456 continue; 456 continue;
457 handled = 1; 457 handled = 1;
458 adma_enter_reg_mode(ap); 458 adma_enter_reg_mode(ap);
459 if (ap->flags & (ATA_FLAG_DISABLED | ATA_FLAG_NOINTR)) 459 if (ap->flags & ATA_FLAG_DISABLED)
460 continue; 460 continue;
461 pp = ap->private_data; 461 pp = ap->private_data;
462 if (!pp || pp->state != adma_state_pkt) 462 if (!pp || pp->state != adma_state_pkt)
463 continue; 463 continue;
464 qc = ata_qc_from_tag(ap, ap->active_tag); 464 qc = ata_qc_from_tag(ap, ap->active_tag);
465 if (qc && (!(qc->tf.ctl & ATA_NIEN))) { 465 if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING))) {
466 if ((status & (aPERR | aPSD | aUIRQ))) 466 if ((status & (aPERR | aPSD | aUIRQ)))
467 qc->err_mask |= AC_ERR_OTHER; 467 qc->err_mask |= AC_ERR_OTHER;
468 else if (pp->pkt[0] != cDONE) 468 else if (pp->pkt[0] != cDONE)
@@ -481,13 +481,13 @@ static inline unsigned int adma_intr_mmio(struct ata_host_set *host_set)
481 for (port_no = 0; port_no < host_set->n_ports; ++port_no) { 481 for (port_no = 0; port_no < host_set->n_ports; ++port_no) {
482 struct ata_port *ap; 482 struct ata_port *ap;
483 ap = host_set->ports[port_no]; 483 ap = host_set->ports[port_no];
484 if (ap && (!(ap->flags & (ATA_FLAG_DISABLED | ATA_FLAG_NOINTR)))) { 484 if (ap && (!(ap->flags & ATA_FLAG_DISABLED))) {
485 struct ata_queued_cmd *qc; 485 struct ata_queued_cmd *qc;
486 struct adma_port_priv *pp = ap->private_data; 486 struct adma_port_priv *pp = ap->private_data;
487 if (!pp || pp->state != adma_state_mmio) 487 if (!pp || pp->state != adma_state_mmio)
488 continue; 488 continue;
489 qc = ata_qc_from_tag(ap, ap->active_tag); 489 qc = ata_qc_from_tag(ap, ap->active_tag);
490 if (qc && (!(qc->tf.ctl & ATA_NIEN))) { 490 if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING))) {
491 491
492 /* check main status, clearing INTRQ */ 492 /* check main status, clearing INTRQ */
493 u8 status = ata_check_status(ap); 493 u8 status = ata_check_status(ap);
diff --git a/drivers/scsi/sata_mv.c b/drivers/scsi/sata_mv.c
index e9152f850003..fd9f2173f062 100644
--- a/drivers/scsi/sata_mv.c
+++ b/drivers/scsi/sata_mv.c
@@ -87,7 +87,7 @@ enum {
87 MV_FLAG_IRQ_COALESCE = (1 << 29), /* IRQ coalescing capability */ 87 MV_FLAG_IRQ_COALESCE = (1 << 29), /* IRQ coalescing capability */
88 MV_COMMON_FLAGS = (ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 88 MV_COMMON_FLAGS = (ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
89 ATA_FLAG_SATA_RESET | ATA_FLAG_MMIO | 89 ATA_FLAG_SATA_RESET | ATA_FLAG_MMIO |
90 ATA_FLAG_NO_ATAPI), 90 ATA_FLAG_PIO_POLLING),
91 MV_6XXX_FLAGS = MV_FLAG_IRQ_COALESCE, 91 MV_6XXX_FLAGS = MV_FLAG_IRQ_COALESCE,
92 92
93 CRQB_FLAG_READ = (1 << 0), 93 CRQB_FLAG_READ = (1 << 0),
@@ -1397,7 +1397,7 @@ static void mv_host_intr(struct ata_host_set *host_set, u32 relevant,
1397 } 1397 }
1398 } 1398 }
1399 1399
1400 if (ap->flags & (ATA_FLAG_DISABLED | ATA_FLAG_NOINTR)) 1400 if (ap && (ap->flags & ATA_FLAG_DISABLED))
1401 continue; 1401 continue;
1402 1402
1403 err_mask = ac_err_mask(ata_status); 1403 err_mask = ac_err_mask(ata_status);
@@ -1418,7 +1418,7 @@ static void mv_host_intr(struct ata_host_set *host_set, u32 relevant,
1418 VPRINTK("port %u IRQ found for qc, " 1418 VPRINTK("port %u IRQ found for qc, "
1419 "ata_status 0x%x\n", port,ata_status); 1419 "ata_status 0x%x\n", port,ata_status);
1420 /* mark qc status appropriately */ 1420 /* mark qc status appropriately */
1421 if (!(qc->tf.ctl & ATA_NIEN)) { 1421 if (!(qc->tf.flags & ATA_TFLAG_POLLING)) {
1422 qc->err_mask |= err_mask; 1422 qc->err_mask |= err_mask;
1423 ata_qc_complete(qc); 1423 ata_qc_complete(qc);
1424 } 1424 }
diff --git a/drivers/scsi/sata_nv.c b/drivers/scsi/sata_nv.c
index 72721ac482d8..be38f328a479 100644
--- a/drivers/scsi/sata_nv.c
+++ b/drivers/scsi/sata_nv.c
@@ -280,11 +280,11 @@ static irqreturn_t nv_interrupt (int irq, void *dev_instance,
280 280
281 ap = host_set->ports[i]; 281 ap = host_set->ports[i];
282 if (ap && 282 if (ap &&
283 !(ap->flags & (ATA_FLAG_DISABLED | ATA_FLAG_NOINTR))) { 283 !(ap->flags & ATA_FLAG_DISABLED)) {
284 struct ata_queued_cmd *qc; 284 struct ata_queued_cmd *qc;
285 285
286 qc = ata_qc_from_tag(ap, ap->active_tag); 286 qc = ata_qc_from_tag(ap, ap->active_tag);
287 if (qc && (!(qc->tf.ctl & ATA_NIEN))) 287 if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)))
288 handled += ata_host_intr(ap, qc); 288 handled += ata_host_intr(ap, qc);
289 else 289 else
290 // No request pending? Clear interrupt status 290 // No request pending? Clear interrupt status
diff --git a/drivers/scsi/sata_promise.c b/drivers/scsi/sata_promise.c
index 9557c7aa45e0..322525d84907 100644
--- a/drivers/scsi/sata_promise.c
+++ b/drivers/scsi/sata_promise.c
@@ -76,7 +76,8 @@ enum {
76 PDC_RESET = (1 << 11), /* HDMA reset */ 76 PDC_RESET = (1 << 11), /* HDMA reset */
77 77
78 PDC_COMMON_FLAGS = ATA_FLAG_NO_LEGACY | ATA_FLAG_SRST | 78 PDC_COMMON_FLAGS = ATA_FLAG_NO_LEGACY | ATA_FLAG_SRST |
79 ATA_FLAG_MMIO | ATA_FLAG_NO_ATAPI, 79 ATA_FLAG_MMIO | ATA_FLAG_NO_ATAPI |
80 ATA_FLAG_PIO_POLLING,
80}; 81};
81 82
82 83
@@ -534,11 +535,11 @@ static irqreturn_t pdc_interrupt (int irq, void *dev_instance, struct pt_regs *r
534 ap = host_set->ports[i]; 535 ap = host_set->ports[i];
535 tmp = mask & (1 << (i + 1)); 536 tmp = mask & (1 << (i + 1));
536 if (tmp && ap && 537 if (tmp && ap &&
537 !(ap->flags & (ATA_FLAG_DISABLED | ATA_FLAG_NOINTR))) { 538 !(ap->flags & ATA_FLAG_DISABLED)) {
538 struct ata_queued_cmd *qc; 539 struct ata_queued_cmd *qc;
539 540
540 qc = ata_qc_from_tag(ap, ap->active_tag); 541 qc = ata_qc_from_tag(ap, ap->active_tag);
541 if (qc && (!(qc->tf.ctl & ATA_NIEN))) 542 if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)))
542 handled += pdc_host_intr(ap, qc); 543 handled += pdc_host_intr(ap, qc);
543 } 544 }
544 } 545 }
diff --git a/drivers/scsi/sata_qstor.c b/drivers/scsi/sata_qstor.c
index 8ef042a09448..f86858962fbe 100644
--- a/drivers/scsi/sata_qstor.c
+++ b/drivers/scsi/sata_qstor.c
@@ -176,7 +176,7 @@ static const struct ata_port_info qs_port_info[] = {
176 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 176 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
177 ATA_FLAG_SATA_RESET | 177 ATA_FLAG_SATA_RESET |
178 //FIXME ATA_FLAG_SRST | 178 //FIXME ATA_FLAG_SRST |
179 ATA_FLAG_MMIO, 179 ATA_FLAG_MMIO | ATA_FLAG_PIO_POLLING,
180 .pio_mask = 0x10, /* pio4 */ 180 .pio_mask = 0x10, /* pio4 */
181 .udma_mask = 0x7f, /* udma0-6 */ 181 .udma_mask = 0x7f, /* udma0-6 */
182 .port_ops = &qs_ata_ops, 182 .port_ops = &qs_ata_ops,
@@ -395,14 +395,13 @@ static inline unsigned int qs_intr_pkt(struct ata_host_set *host_set)
395 DPRINTK("SFF=%08x%08x: sCHAN=%u sHST=%d sDST=%02x\n", 395 DPRINTK("SFF=%08x%08x: sCHAN=%u sHST=%d sDST=%02x\n",
396 sff1, sff0, port_no, sHST, sDST); 396 sff1, sff0, port_no, sHST, sDST);
397 handled = 1; 397 handled = 1;
398 if (ap && !(ap->flags & 398 if (ap && !(ap->flags & ATA_FLAG_DISABLED)) {
399 (ATA_FLAG_DISABLED|ATA_FLAG_NOINTR))) {
400 struct ata_queued_cmd *qc; 399 struct ata_queued_cmd *qc;
401 struct qs_port_priv *pp = ap->private_data; 400 struct qs_port_priv *pp = ap->private_data;
402 if (!pp || pp->state != qs_state_pkt) 401 if (!pp || pp->state != qs_state_pkt)
403 continue; 402 continue;
404 qc = ata_qc_from_tag(ap, ap->active_tag); 403 qc = ata_qc_from_tag(ap, ap->active_tag);
405 if (qc && (!(qc->tf.ctl & ATA_NIEN))) { 404 if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING))) {
406 switch (sHST) { 405 switch (sHST) {
407 case 0: /* successful CPB */ 406 case 0: /* successful CPB */
408 case 3: /* device error */ 407 case 3: /* device error */
@@ -429,13 +428,13 @@ static inline unsigned int qs_intr_mmio(struct ata_host_set *host_set)
429 struct ata_port *ap; 428 struct ata_port *ap;
430 ap = host_set->ports[port_no]; 429 ap = host_set->ports[port_no];
431 if (ap && 430 if (ap &&
432 !(ap->flags & (ATA_FLAG_DISABLED | ATA_FLAG_NOINTR))) { 431 !(ap->flags & ATA_FLAG_DISABLED)) {
433 struct ata_queued_cmd *qc; 432 struct ata_queued_cmd *qc;
434 struct qs_port_priv *pp = ap->private_data; 433 struct qs_port_priv *pp = ap->private_data;
435 if (!pp || pp->state != qs_state_mmio) 434 if (!pp || pp->state != qs_state_mmio)
436 continue; 435 continue;
437 qc = ata_qc_from_tag(ap, ap->active_tag); 436 qc = ata_qc_from_tag(ap, ap->active_tag);
438 if (qc && (!(qc->tf.ctl & ATA_NIEN))) { 437 if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING))) {
439 438
440 /* check main status, clearing INTRQ */ 439 /* check main status, clearing INTRQ */
441 u8 status = ata_check_status(ap); 440 u8 status = ata_check_status(ap);
diff --git a/drivers/scsi/sata_sx4.c b/drivers/scsi/sata_sx4.c
index 3af28ef76fd9..45c78c399bfd 100644
--- a/drivers/scsi/sata_sx4.c
+++ b/drivers/scsi/sata_sx4.c
@@ -219,7 +219,7 @@ static const struct ata_port_info pdc_port_info[] = {
219 .sht = &pdc_sata_sht, 219 .sht = &pdc_sata_sht,
220 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 220 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
221 ATA_FLAG_SRST | ATA_FLAG_MMIO | 221 ATA_FLAG_SRST | ATA_FLAG_MMIO |
222 ATA_FLAG_NO_ATAPI, 222 ATA_FLAG_PIO_POLLING,
223 .pio_mask = 0x1f, /* pio0-4 */ 223 .pio_mask = 0x1f, /* pio0-4 */
224 .mwdma_mask = 0x07, /* mwdma0-2 */ 224 .mwdma_mask = 0x07, /* mwdma0-2 */
225 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 225 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
@@ -834,11 +834,11 @@ static irqreturn_t pdc20621_interrupt (int irq, void *dev_instance, struct pt_re
834 tmp = mask & (1 << i); 834 tmp = mask & (1 << i);
835 VPRINTK("seq %u, port_no %u, ap %p, tmp %x\n", i, port_no, ap, tmp); 835 VPRINTK("seq %u, port_no %u, ap %p, tmp %x\n", i, port_no, ap, tmp);
836 if (tmp && ap && 836 if (tmp && ap &&
837 !(ap->flags & (ATA_FLAG_DISABLED | ATA_FLAG_NOINTR))) { 837 !(ap->flags & ATA_FLAG_DISABLED)) {
838 struct ata_queued_cmd *qc; 838 struct ata_queued_cmd *qc;
839 839
840 qc = ata_qc_from_tag(ap, ap->active_tag); 840 qc = ata_qc_from_tag(ap, ap->active_tag);
841 if (qc && (!(qc->tf.ctl & ATA_NIEN))) 841 if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)))
842 handled += pdc20621_host_intr(ap, qc, (i > 4), 842 handled += pdc20621_host_intr(ap, qc, (i > 4),
843 mmio_base); 843 mmio_base);
844 } 844 }
diff --git a/drivers/scsi/sata_vsc.c b/drivers/scsi/sata_vsc.c
index cecc1f76256b..b7d6a31628c2 100644
--- a/drivers/scsi/sata_vsc.c
+++ b/drivers/scsi/sata_vsc.c
@@ -221,14 +221,21 @@ static irqreturn_t vsc_sata_interrupt (int irq, void *dev_instance,
221 221
222 ap = host_set->ports[i]; 222 ap = host_set->ports[i];
223 223
224 if (ap && !(ap->flags & 224 if (is_vsc_sata_int_err(i, int_status)) {
225 (ATA_FLAG_DISABLED|ATA_FLAG_NOINTR))) { 225 u32 err_status;
226 printk(KERN_DEBUG "%s: ignoring interrupt(s)\n", __FUNCTION__);
227 err_status = ap ? vsc_sata_scr_read(ap, SCR_ERROR) : 0;
228 vsc_sata_scr_write(ap, SCR_ERROR, err_status);
229 handled++;
230 }
231
232 if (ap && !(ap->flags & ATA_FLAG_DISABLED)) {
226 struct ata_queued_cmd *qc; 233 struct ata_queued_cmd *qc;
227 234
228 qc = ata_qc_from_tag(ap, ap->active_tag); 235 qc = ata_qc_from_tag(ap, ap->active_tag);
229 if (qc && (!(qc->tf.ctl & ATA_NIEN))) { 236 if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)))
230 handled += ata_host_intr(ap, qc); 237 handled += ata_host_intr(ap, qc);
231 } else if (is_vsc_sata_int_err(i, int_status)) { 238 else if (is_vsc_sata_int_err(i, int_status)) {
232 /* 239 /*
233 * On some chips (i.e. Intel 31244), an error 240 * On some chips (i.e. Intel 31244), an error
234 * interrupt will sneak in at initialization 241 * interrupt will sneak in at initialization