aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/scsi/libata-core.c594
-rw-r--r--drivers/scsi/pdc_adma.c8
-rw-r--r--drivers/scsi/sata_mv.c7
-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.c6
-rw-r--r--include/linux/ata.h11
-rw-r--r--include/linux/libata.h27
10 files changed, 485 insertions, 196 deletions
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index 61cba39a6834..5ab220e9907c 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -70,6 +70,7 @@ static int fgb(u32 bitmap);
70static int ata_choose_xfer_mode(const struct ata_port *ap, 70static int ata_choose_xfer_mode(const struct ata_port *ap,
71 u8 *xfer_mode_out, 71 u8 *xfer_mode_out,
72 unsigned int *xfer_shift_out); 72 unsigned int *xfer_shift_out);
73static void ata_pio_error(struct ata_port *ap);
73 74
74static unsigned int ata_unique_id = 1; 75static unsigned int ata_unique_id = 1;
75static struct workqueue_struct *ata_wq; 76static struct workqueue_struct *ata_wq;
@@ -213,7 +214,7 @@ int ata_rwcmd_protocol(struct ata_queued_cmd *qc)
213 } else if (lba48 && (qc->ap->flags & ATA_FLAG_PIO_LBA48)) { 214 } else if (lba48 && (qc->ap->flags & ATA_FLAG_PIO_LBA48)) {
214 /* Unable to use DMA due to host limitation */ 215 /* Unable to use DMA due to host limitation */
215 tf->protocol = ATA_PROT_PIO; 216 tf->protocol = ATA_PROT_PIO;
216 index = dev->multi_count ? 0 : 4; 217 index = dev->multi_count ? 0 : 8;
217 } else { 218 } else {
218 tf->protocol = ATA_PROT_DMA; 219 tf->protocol = ATA_PROT_DMA;
219 index = 16; 220 index = 16;
@@ -718,13 +719,6 @@ static unsigned int ata_pio_modes(const struct ata_device *adev)
718} 719}
719 720
720static inline void 721static inline void
721ata_queue_packet_task(struct ata_port *ap)
722{
723 if (!(ap->flags & ATA_FLAG_FLUSH_PIO_TASK))
724 queue_work(ata_wq, &ap->packet_task);
725}
726
727static inline void
728ata_queue_pio_task(struct ata_port *ap) 722ata_queue_pio_task(struct ata_port *ap)
729{ 723{
730 if (!(ap->flags & ATA_FLAG_FLUSH_PIO_TASK)) 724 if (!(ap->flags & ATA_FLAG_FLUSH_PIO_TASK))
@@ -739,10 +733,10 @@ ata_queue_delayed_pio_task(struct ata_port *ap, unsigned long delay)
739} 733}
740 734
741/** 735/**
742 * ata_flush_pio_tasks - Flush pio_task and packet_task 736 * ata_flush_pio_tasks - Flush pio_task
743 * @ap: the target ata_port 737 * @ap: the target ata_port
744 * 738 *
745 * After this function completes, pio_task and packet_task are 739 * After this function completes, pio_task is
746 * guranteed not to be running or scheduled. 740 * guranteed not to be running or scheduled.
747 * 741 *
748 * LOCKING: 742 * LOCKING:
@@ -769,7 +763,6 @@ static void ata_flush_pio_tasks(struct ata_port *ap)
769 * Cancel and flush. 763 * Cancel and flush.
770 */ 764 */
771 tmp |= cancel_delayed_work(&ap->pio_task); 765 tmp |= cancel_delayed_work(&ap->pio_task);
772 tmp |= cancel_delayed_work(&ap->packet_task);
773 if (!tmp) { 766 if (!tmp) {
774 DPRINTK("flush #2\n"); 767 DPRINTK("flush #2\n");
775 flush_workqueue(ata_wq); 768 flush_workqueue(ata_wq);
@@ -1087,7 +1080,12 @@ retry:
1087 1080
1088 } 1081 }
1089 1082
1090 dev->cdb_len = 16; 1083 if (dev->id[59] & 0x100) {
1084 dev->multi_count = dev->id[59] & 0xff;
1085 DPRINTK("ata%u: dev %u multi count %u\n",
1086 ap->id, device, dev->multi_count);
1087 }
1088
1091 } 1089 }
1092 1090
1093 /* ATAPI-specific feature tests */ 1091 /* ATAPI-specific feature tests */
@@ -1102,6 +1100,9 @@ retry:
1102 } 1100 }
1103 dev->cdb_len = (unsigned int) rc; 1101 dev->cdb_len = (unsigned int) rc;
1104 1102
1103 if (ata_id_cdb_intr(dev->id))
1104 dev->flags |= ATA_DFLAG_CDB_INTR;
1105
1105 /* print device info to dmesg */ 1106 /* print device info to dmesg */
1106 printk(KERN_INFO "ata%u: dev %u ATAPI, max %s\n", 1107 printk(KERN_INFO "ata%u: dev %u ATAPI, max %s\n",
1107 ap->id, device, 1108 ap->id, device,
@@ -2931,7 +2932,6 @@ void ata_poll_qc_complete(struct ata_queued_cmd *qc)
2931 unsigned long flags; 2932 unsigned long flags;
2932 2933
2933 spin_lock_irqsave(&ap->host_set->lock, flags); 2934 spin_lock_irqsave(&ap->host_set->lock, flags);
2934 ap->flags &= ~ATA_FLAG_NOINTR;
2935 ata_irq_on(ap); 2935 ata_irq_on(ap);
2936 ata_qc_complete(qc); 2936 ata_qc_complete(qc);
2937 spin_unlock_irqrestore(&ap->host_set->lock, flags); 2937 spin_unlock_irqrestore(&ap->host_set->lock, flags);
@@ -2997,7 +2997,8 @@ static unsigned long ata_pio_poll(struct ata_port *ap)
2997 * None. (executing in kernel thread context) 2997 * None. (executing in kernel thread context)
2998 * 2998 *
2999 * RETURNS: 2999 * RETURNS:
3000 * Non-zero if qc completed, zero otherwise. 3000 * Zero if qc completed.
3001 * Non-zero if has next.
3001 */ 3002 */
3002 3003
3003static int ata_pio_complete (struct ata_port *ap) 3004static int ata_pio_complete (struct ata_port *ap)
@@ -3010,7 +3011,7 @@ static int ata_pio_complete (struct ata_port *ap)
3010 * we enter, BSY will be cleared in a chk-status or two. If not, 3011 * we enter, BSY will be cleared in a chk-status or two. If not,
3011 * the drive is probably seeking or something. Snooze for a couple 3012 * the drive is probably seeking or something. Snooze for a couple
3012 * msecs, then chk-status again. If still busy, fall back to 3013 * msecs, then chk-status again. If still busy, fall back to
3013 * HSM_ST_POLL state. 3014 * HSM_ST_LAST_POLL state.
3014 */ 3015 */
3015 drv_stat = ata_busy_wait(ap, ATA_BUSY, 10); 3016 drv_stat = ata_busy_wait(ap, ATA_BUSY, 10);
3016 if (drv_stat & ATA_BUSY) { 3017 if (drv_stat & ATA_BUSY) {
@@ -3019,7 +3020,7 @@ static int ata_pio_complete (struct ata_port *ap)
3019 if (drv_stat & ATA_BUSY) { 3020 if (drv_stat & ATA_BUSY) {
3020 ap->hsm_task_state = HSM_ST_LAST_POLL; 3021 ap->hsm_task_state = HSM_ST_LAST_POLL;
3021 ap->pio_task_timeout = jiffies + ATA_TMOUT_PIO; 3022 ap->pio_task_timeout = jiffies + ATA_TMOUT_PIO;
3022 return 0; 3023 return 1;
3023 } 3024 }
3024 } 3025 }
3025 3026
@@ -3030,7 +3031,7 @@ static int ata_pio_complete (struct ata_port *ap)
3030 if (!ata_ok(drv_stat)) { 3031 if (!ata_ok(drv_stat)) {
3031 qc->err_mask |= __ac_err_mask(drv_stat); 3032 qc->err_mask |= __ac_err_mask(drv_stat);
3032 ap->hsm_task_state = HSM_ST_ERR; 3033 ap->hsm_task_state = HSM_ST_ERR;
3033 return 0; 3034 return 1;
3034 } 3035 }
3035 3036
3036 ap->hsm_task_state = HSM_ST_IDLE; 3037 ap->hsm_task_state = HSM_ST_IDLE;
@@ -3040,7 +3041,7 @@ static int ata_pio_complete (struct ata_port *ap)
3040 3041
3041 /* another command may start at this point */ 3042 /* another command may start at this point */
3042 3043
3043 return 1; 3044 return 0;
3044} 3045}
3045 3046
3046 3047
@@ -3212,7 +3213,23 @@ static void ata_pio_sector(struct ata_queued_cmd *qc)
3212 page = nth_page(page, (offset >> PAGE_SHIFT)); 3213 page = nth_page(page, (offset >> PAGE_SHIFT));
3213 offset %= PAGE_SIZE; 3214 offset %= PAGE_SIZE;
3214 3215
3215 buf = kmap(page) + offset; 3216 DPRINTK("data %s\n", qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read");
3217
3218 if (PageHighMem(page)) {
3219 unsigned long flags;
3220
3221 local_irq_save(flags);
3222 buf = kmap_atomic(page, KM_IRQ0);
3223
3224 /* do the actual data transfer */
3225 ata_data_xfer(ap, buf + offset, ATA_SECT_SIZE, do_write);
3226
3227 kunmap_atomic(buf, KM_IRQ0);
3228 local_irq_restore(flags);
3229 } else {
3230 buf = page_address(page);
3231 ata_data_xfer(ap, buf + offset, ATA_SECT_SIZE, do_write);
3232 }
3216 3233
3217 qc->cursect++; 3234 qc->cursect++;
3218 qc->cursg_ofs++; 3235 qc->cursg_ofs++;
@@ -3221,14 +3238,153 @@ static void ata_pio_sector(struct ata_queued_cmd *qc)
3221 qc->cursg++; 3238 qc->cursg++;
3222 qc->cursg_ofs = 0; 3239 qc->cursg_ofs = 0;
3223 } 3240 }
3241}
3224 3242
3225 DPRINTK("data %s\n", qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read"); 3243/**
3244 * ata_pio_sectors - Transfer one or many 512-byte sectors.
3245 * @qc: Command on going
3246 *
3247 * Transfer one or many ATA_SECT_SIZE of data from/to the
3248 * ATA device for the DRQ request.
3249 *
3250 * LOCKING:
3251 * Inherited from caller.
3252 */
3253
3254static void ata_pio_sectors(struct ata_queued_cmd *qc)
3255{
3256 if (is_multi_taskfile(&qc->tf)) {
3257 /* READ/WRITE MULTIPLE */
3258 unsigned int nsect;
3259
3260 WARN_ON(qc->dev->multi_count == 0);
3226 3261
3227 /* do the actual data transfer */ 3262 nsect = min(qc->nsect - qc->cursect, qc->dev->multi_count);
3228 do_write = (qc->tf.flags & ATA_TFLAG_WRITE); 3263 while (nsect--)
3229 ata_data_xfer(ap, buf, ATA_SECT_SIZE, do_write); 3264 ata_pio_sector(qc);
3265 } else
3266 ata_pio_sector(qc);
3267}
3230 3268
3231 kunmap(page); 3269/**
3270 * atapi_send_cdb - Write CDB bytes to hardware
3271 * @ap: Port to which ATAPI device is attached.
3272 * @qc: Taskfile currently active
3273 *
3274 * When device has indicated its readiness to accept
3275 * a CDB, this function is called. Send the CDB.
3276 *
3277 * LOCKING:
3278 * caller.
3279 */
3280
3281static void atapi_send_cdb(struct ata_port *ap, struct ata_queued_cmd *qc)
3282{
3283 /* send SCSI cdb */
3284 DPRINTK("send cdb\n");
3285 WARN_ON(ap->cdb_len < 12);
3286
3287 ata_data_xfer(ap, qc->cdb, ap->cdb_len, 1);
3288 ata_altstatus(ap); /* flush */
3289
3290 switch (qc->tf.protocol) {
3291 case ATA_PROT_ATAPI:
3292 ap->hsm_task_state = HSM_ST;
3293 break;
3294 case ATA_PROT_ATAPI_NODATA:
3295 ap->hsm_task_state = HSM_ST_LAST;
3296 break;
3297 case ATA_PROT_ATAPI_DMA:
3298 ap->hsm_task_state = HSM_ST_LAST;
3299 /* initiate bmdma */
3300 ap->ops->bmdma_start(qc);
3301 break;
3302 }
3303}
3304
3305/**
3306 * ata_pio_first_block - Write first data block to hardware
3307 * @ap: Port to which ATA/ATAPI device is attached.
3308 *
3309 * When device has indicated its readiness to accept
3310 * the data, this function sends out the CDB or
3311 * the first data block by PIO.
3312 * After this,
3313 * - If polling, ata_pio_task() handles the rest.
3314 * - Otherwise, interrupt handler takes over.
3315 *
3316 * LOCKING:
3317 * Kernel thread context (may sleep)
3318 *
3319 * RETURNS:
3320 * Zero if irq handler takes over
3321 * Non-zero if has next (polling).
3322 */
3323
3324static int ata_pio_first_block(struct ata_port *ap)
3325{
3326 struct ata_queued_cmd *qc;
3327 u8 status;
3328 unsigned long flags;
3329 int has_next;
3330
3331 qc = ata_qc_from_tag(ap, ap->active_tag);
3332 WARN_ON(qc == NULL);
3333 WARN_ON((qc->flags & ATA_QCFLAG_ACTIVE) == 0);
3334
3335 /* if polling, we will stay in the work queue after sending the data.
3336 * otherwise, interrupt handler takes over after sending the data.
3337 */
3338 has_next = (qc->tf.flags & ATA_TFLAG_POLLING);
3339
3340 /* sleep-wait for BSY to clear */
3341 DPRINTK("busy wait\n");
3342 if (ata_busy_sleep(ap, ATA_TMOUT_DATAOUT_QUICK, ATA_TMOUT_DATAOUT)) {
3343 qc->err_mask |= AC_ERR_TIMEOUT;
3344 ap->hsm_task_state = HSM_ST_TMOUT;
3345 goto err_out;
3346 }
3347
3348 /* make sure DRQ is set */
3349 status = ata_chk_status(ap);
3350 if ((status & (ATA_BUSY | ATA_DRQ)) != ATA_DRQ) {
3351 /* device status error */
3352 qc->err_mask |= AC_ERR_HSM;
3353 ap->hsm_task_state = HSM_ST_ERR;
3354 goto err_out;
3355 }
3356
3357 /* Send the CDB (atapi) or the first data block (ata pio out).
3358 * During the state transition, interrupt handler shouldn't
3359 * be invoked before the data transfer is complete and
3360 * hsm_task_state is changed. Hence, the following locking.
3361 */
3362 spin_lock_irqsave(&ap->host_set->lock, flags);
3363
3364 if (qc->tf.protocol == ATA_PROT_PIO) {
3365 /* PIO data out protocol.
3366 * send first data block.
3367 */
3368
3369 /* ata_pio_sectors() might change the state to HSM_ST_LAST.
3370 * so, the state is changed here before ata_pio_sectors().
3371 */
3372 ap->hsm_task_state = HSM_ST;
3373 ata_pio_sectors(qc);
3374 ata_altstatus(ap); /* flush */
3375 } else
3376 /* send CDB */
3377 atapi_send_cdb(ap, qc);
3378
3379 spin_unlock_irqrestore(&ap->host_set->lock, flags);
3380
3381 /* if polling, ata_pio_task() handles the rest.
3382 * otherwise, interrupt handler takes over from here.
3383 */
3384 return has_next;
3385
3386err_out:
3387 return 1; /* has next */
3232} 3388}
3233 3389
3234/** 3390/**
@@ -3294,7 +3450,23 @@ next_sg:
3294 /* don't cross page boundaries */ 3450 /* don't cross page boundaries */
3295 count = min(count, (unsigned int)PAGE_SIZE - offset); 3451 count = min(count, (unsigned int)PAGE_SIZE - offset);
3296 3452
3297 buf = kmap(page) + offset; 3453 DPRINTK("data %s\n", qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read");
3454
3455 if (PageHighMem(page)) {
3456 unsigned long flags;
3457
3458 local_irq_save(flags);
3459 buf = kmap_atomic(page, KM_IRQ0);
3460
3461 /* do the actual data transfer */
3462 ata_data_xfer(ap, buf + offset, count, do_write);
3463
3464 kunmap_atomic(buf, KM_IRQ0);
3465 local_irq_restore(flags);
3466 } else {
3467 buf = page_address(page);
3468 ata_data_xfer(ap, buf + offset, count, do_write);
3469 }
3298 3470
3299 bytes -= count; 3471 bytes -= count;
3300 qc->curbytes += count; 3472 qc->curbytes += count;
@@ -3305,13 +3477,6 @@ next_sg:
3305 qc->cursg_ofs = 0; 3477 qc->cursg_ofs = 0;
3306 } 3478 }
3307 3479
3308 DPRINTK("data %s\n", qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read");
3309
3310 /* do the actual data transfer */
3311 ata_data_xfer(ap, buf, count, do_write);
3312
3313 kunmap(page);
3314
3315 if (bytes) 3480 if (bytes)
3316 goto next_sg; 3481 goto next_sg;
3317} 3482}
@@ -3348,6 +3513,8 @@ static void atapi_pio_bytes(struct ata_queued_cmd *qc)
3348 if (do_write != i_write) 3513 if (do_write != i_write)
3349 goto err_out; 3514 goto err_out;
3350 3515
3516 VPRINTK("ata%u: xfering %d bytes\n", ap->id, bytes);
3517
3351 __atapi_pio_bytes(qc, bytes); 3518 __atapi_pio_bytes(qc, bytes);
3352 3519
3353 return; 3520 return;
@@ -3418,19 +3585,22 @@ static void ata_pio_block(struct ata_port *ap)
3418 return; 3585 return;
3419 } 3586 }
3420 3587
3421 ata_pio_sector(qc); 3588 ata_pio_sectors(qc);
3422 } 3589 }
3590
3591 ata_altstatus(ap); /* flush */
3423} 3592}
3424 3593
3425static void ata_pio_error(struct ata_port *ap) 3594static void ata_pio_error(struct ata_port *ap)
3426{ 3595{
3427 struct ata_queued_cmd *qc; 3596 struct ata_queued_cmd *qc;
3428 3597
3429 printk(KERN_WARNING "ata%u: PIO error\n", ap->id);
3430
3431 qc = ata_qc_from_tag(ap, ap->active_tag); 3598 qc = ata_qc_from_tag(ap, ap->active_tag);
3432 WARN_ON(qc == NULL); 3599 WARN_ON(qc == NULL);
3433 3600
3601 if (qc->tf.command != ATA_CMD_PACKET)
3602 printk(KERN_WARNING "ata%u: PIO error\n", ap->id);
3603
3434 /* make sure qc->err_mask is available to 3604 /* make sure qc->err_mask is available to
3435 * know what's wrong and recover 3605 * know what's wrong and recover
3436 */ 3606 */
@@ -3445,22 +3615,23 @@ static void ata_pio_task(void *_data)
3445{ 3615{
3446 struct ata_port *ap = _data; 3616 struct ata_port *ap = _data;
3447 unsigned long timeout; 3617 unsigned long timeout;
3448 int qc_completed; 3618 int has_next;
3449 3619
3450fsm_start: 3620fsm_start:
3451 timeout = 0; 3621 timeout = 0;
3452 qc_completed = 0; 3622 has_next = 1;
3453 3623
3454 switch (ap->hsm_task_state) { 3624 switch (ap->hsm_task_state) {
3455 case HSM_ST_IDLE: 3625 case HSM_ST_FIRST:
3456 return; 3626 has_next = ata_pio_first_block(ap);
3627 break;
3457 3628
3458 case HSM_ST: 3629 case HSM_ST:
3459 ata_pio_block(ap); 3630 ata_pio_block(ap);
3460 break; 3631 break;
3461 3632
3462 case HSM_ST_LAST: 3633 case HSM_ST_LAST:
3463 qc_completed = ata_pio_complete(ap); 3634 has_next = ata_pio_complete(ap);
3464 break; 3635 break;
3465 3636
3466 case HSM_ST_POLL: 3637 case HSM_ST_POLL:
@@ -3472,11 +3643,15 @@ fsm_start:
3472 case HSM_ST_ERR: 3643 case HSM_ST_ERR:
3473 ata_pio_error(ap); 3644 ata_pio_error(ap);
3474 return; 3645 return;
3646
3647 default:
3648 BUG();
3649 return;
3475 } 3650 }
3476 3651
3477 if (timeout) 3652 if (timeout)
3478 ata_queue_delayed_pio_task(ap, timeout); 3653 ata_queue_delayed_pio_task(ap, timeout);
3479 else if (!qc_completed) 3654 else if (has_next)
3480 goto fsm_start; 3655 goto fsm_start;
3481} 3656}
3482 3657
@@ -3534,8 +3709,10 @@ static void ata_qc_timeout(struct ata_queued_cmd *qc)
3534 printk(KERN_ERR "ata%u: command 0x%x timeout, stat 0x%x host_stat 0x%x\n", 3709 printk(KERN_ERR "ata%u: command 0x%x timeout, stat 0x%x host_stat 0x%x\n",
3535 ap->id, qc->tf.command, drv_stat, host_stat); 3710 ap->id, qc->tf.command, drv_stat, host_stat);
3536 3711
3712 ap->hsm_task_state = HSM_ST_IDLE;
3713
3537 /* complete taskfile transaction */ 3714 /* complete taskfile transaction */
3538 qc->err_mask |= ac_err_mask(drv_stat); 3715 qc->err_mask |= AC_ERR_TIMEOUT;
3539 break; 3716 break;
3540 } 3717 }
3541 3718
@@ -3762,43 +3939,104 @@ unsigned int ata_qc_issue_prot(struct ata_queued_cmd *qc)
3762{ 3939{
3763 struct ata_port *ap = qc->ap; 3940 struct ata_port *ap = qc->ap;
3764 3941
3942 /* Use polling pio if the LLD doesn't handle
3943 * interrupt driven pio and atapi CDB interrupt.
3944 */
3945 if (ap->flags & ATA_FLAG_PIO_POLLING) {
3946 switch (qc->tf.protocol) {
3947 case ATA_PROT_PIO:
3948 case ATA_PROT_ATAPI:
3949 case ATA_PROT_ATAPI_NODATA:
3950 qc->tf.flags |= ATA_TFLAG_POLLING;
3951 break;
3952 case ATA_PROT_ATAPI_DMA:
3953 if (qc->dev->flags & ATA_DFLAG_CDB_INTR)
3954 BUG();
3955 break;
3956 default:
3957 break;
3958 }
3959 }
3960
3961 /* select the device */
3765 ata_dev_select(ap, qc->dev->devno, 1, 0); 3962 ata_dev_select(ap, qc->dev->devno, 1, 0);
3766 3963
3964 /* start the command */
3767 switch (qc->tf.protocol) { 3965 switch (qc->tf.protocol) {
3768 case ATA_PROT_NODATA: 3966 case ATA_PROT_NODATA:
3967 if (qc->tf.flags & ATA_TFLAG_POLLING)
3968 ata_qc_set_polling(qc);
3969
3769 ata_tf_to_host(ap, &qc->tf); 3970 ata_tf_to_host(ap, &qc->tf);
3971 ap->hsm_task_state = HSM_ST_LAST;
3972
3973 if (qc->tf.flags & ATA_TFLAG_POLLING)
3974 ata_queue_pio_task(ap);
3975
3770 break; 3976 break;
3771 3977
3772 case ATA_PROT_DMA: 3978 case ATA_PROT_DMA:
3979 WARN_ON(qc->tf.flags & ATA_TFLAG_POLLING);
3980
3773 ap->ops->tf_load(ap, &qc->tf); /* load tf registers */ 3981 ap->ops->tf_load(ap, &qc->tf); /* load tf registers */
3774 ap->ops->bmdma_setup(qc); /* set up bmdma */ 3982 ap->ops->bmdma_setup(qc); /* set up bmdma */
3775 ap->ops->bmdma_start(qc); /* initiate bmdma */ 3983 ap->ops->bmdma_start(qc); /* initiate bmdma */
3984 ap->hsm_task_state = HSM_ST_LAST;
3776 break; 3985 break;
3777 3986
3778 case ATA_PROT_PIO: /* load tf registers, initiate polling pio */ 3987 case ATA_PROT_PIO:
3779 ata_qc_set_polling(qc); 3988 if (qc->tf.flags & ATA_TFLAG_POLLING)
3780 ata_tf_to_host(ap, &qc->tf); 3989 ata_qc_set_polling(qc);
3781 ap->hsm_task_state = HSM_ST;
3782 ata_queue_pio_task(ap);
3783 break;
3784 3990
3785 case ATA_PROT_ATAPI:
3786 ata_qc_set_polling(qc);
3787 ata_tf_to_host(ap, &qc->tf); 3991 ata_tf_to_host(ap, &qc->tf);
3788 ata_queue_packet_task(ap); 3992
3993 if (qc->tf.flags & ATA_TFLAG_WRITE) {
3994 /* PIO data out protocol */
3995 ap->hsm_task_state = HSM_ST_FIRST;
3996 ata_queue_pio_task(ap);
3997
3998 /* always send first data block using
3999 * the ata_pio_task() codepath.
4000 */
4001 } else {
4002 /* PIO data in protocol */
4003 ap->hsm_task_state = HSM_ST;
4004
4005 if (qc->tf.flags & ATA_TFLAG_POLLING)
4006 ata_queue_pio_task(ap);
4007
4008 /* if polling, ata_pio_task() handles the rest.
4009 * otherwise, interrupt handler takes over from here.
4010 */
4011 }
4012
3789 break; 4013 break;
3790 4014
4015 case ATA_PROT_ATAPI:
3791 case ATA_PROT_ATAPI_NODATA: 4016 case ATA_PROT_ATAPI_NODATA:
3792 ap->flags |= ATA_FLAG_NOINTR; 4017 if (qc->tf.flags & ATA_TFLAG_POLLING)
4018 ata_qc_set_polling(qc);
4019
3793 ata_tf_to_host(ap, &qc->tf); 4020 ata_tf_to_host(ap, &qc->tf);
3794 ata_queue_packet_task(ap); 4021
4022 ap->hsm_task_state = HSM_ST_FIRST;
4023
4024 /* send cdb by polling if no cdb interrupt */
4025 if ((!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) ||
4026 (qc->tf.flags & ATA_TFLAG_POLLING))
4027 ata_queue_pio_task(ap);
3795 break; 4028 break;
3796 4029
3797 case ATA_PROT_ATAPI_DMA: 4030 case ATA_PROT_ATAPI_DMA:
3798 ap->flags |= ATA_FLAG_NOINTR; 4031 WARN_ON(qc->tf.flags & ATA_TFLAG_POLLING);
4032
3799 ap->ops->tf_load(ap, &qc->tf); /* load tf registers */ 4033 ap->ops->tf_load(ap, &qc->tf); /* load tf registers */
3800 ap->ops->bmdma_setup(qc); /* set up bmdma */ 4034 ap->ops->bmdma_setup(qc); /* set up bmdma */
3801 ata_queue_packet_task(ap); 4035 ap->hsm_task_state = HSM_ST_FIRST;
4036
4037 /* send cdb by polling if no cdb interrupt */
4038 if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR))
4039 ata_queue_pio_task(ap);
3802 break; 4040 break;
3803 4041
3804 default: 4042 default:
@@ -4059,48 +4297,160 @@ void ata_bmdma_stop(struct ata_queued_cmd *qc)
4059inline unsigned int ata_host_intr (struct ata_port *ap, 4297inline unsigned int ata_host_intr (struct ata_port *ap,
4060 struct ata_queued_cmd *qc) 4298 struct ata_queued_cmd *qc)
4061{ 4299{
4062 u8 status, host_stat; 4300 u8 status, host_stat = 0;
4063 4301
4064 switch (qc->tf.protocol) { 4302 VPRINTK("ata%u: protocol %d task_state %d\n",
4303 ap->id, qc->tf.protocol, ap->hsm_task_state);
4065 4304
4066 case ATA_PROT_DMA: 4305 /* Check whether we are expecting interrupt in this state */
4067 case ATA_PROT_ATAPI_DMA: 4306 switch (ap->hsm_task_state) {
4068 case ATA_PROT_ATAPI: 4307 case HSM_ST_FIRST:
4069 /* check status of DMA engine */ 4308 /* Check the ATA_DFLAG_CDB_INTR flag is enough here.
4070 host_stat = ap->ops->bmdma_status(ap); 4309 * The flag was turned on only for atapi devices.
4071 VPRINTK("ata%u: host_stat 0x%X\n", ap->id, host_stat); 4310 * No need to check is_atapi_taskfile(&qc->tf) again.
4072 4311 */
4073 /* if it's not our irq... */ 4312 if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR))
4074 if (!(host_stat & ATA_DMA_INTR))
4075 goto idle_irq; 4313 goto idle_irq;
4314 break;
4315 case HSM_ST_LAST:
4316 if (qc->tf.protocol == ATA_PROT_DMA ||
4317 qc->tf.protocol == ATA_PROT_ATAPI_DMA) {
4318 /* check status of DMA engine */
4319 host_stat = ap->ops->bmdma_status(ap);
4320 VPRINTK("ata%u: host_stat 0x%X\n", ap->id, host_stat);
4321
4322 /* if it's not our irq... */
4323 if (!(host_stat & ATA_DMA_INTR))
4324 goto idle_irq;
4325
4326 /* before we do anything else, clear DMA-Start bit */
4327 ap->ops->bmdma_stop(qc);
4328
4329 if (unlikely(host_stat & ATA_DMA_ERR)) {
4330 /* error when transfering data to/from memory */
4331 qc->err_mask |= AC_ERR_HOST_BUS;
4332 ap->hsm_task_state = HSM_ST_ERR;
4333 }
4334 }
4335 break;
4336 case HSM_ST:
4337 break;
4338 default:
4339 goto idle_irq;
4340 }
4076 4341
4077 /* before we do anything else, clear DMA-Start bit */ 4342 /* check altstatus */
4078 ap->ops->bmdma_stop(qc); 4343 status = ata_altstatus(ap);
4344 if (status & ATA_BUSY)
4345 goto idle_irq;
4079 4346
4080 /* fall through */ 4347 /* check main status, clearing INTRQ */
4348 status = ata_chk_status(ap);
4349 if (unlikely(status & ATA_BUSY))
4350 goto idle_irq;
4081 4351
4082 case ATA_PROT_ATAPI_NODATA: 4352 DPRINTK("ata%u: protocol %d task_state %d (dev_stat 0x%X)\n",
4083 case ATA_PROT_NODATA: 4353 ap->id, qc->tf.protocol, ap->hsm_task_state, status);
4084 /* check altstatus */
4085 status = ata_altstatus(ap);
4086 if (status & ATA_BUSY)
4087 goto idle_irq;
4088 4354
4089 /* check main status, clearing INTRQ */ 4355 /* ack bmdma irq events */
4090 status = ata_chk_status(ap); 4356 ap->ops->irq_clear(ap);
4091 if (unlikely(status & ATA_BUSY))
4092 goto idle_irq;
4093 DPRINTK("ata%u: protocol %d (dev_stat 0x%X)\n",
4094 ap->id, qc->tf.protocol, status);
4095 4357
4096 /* ack bmdma irq events */ 4358 /* check error */
4097 ap->ops->irq_clear(ap); 4359 if (unlikely(status & (ATA_ERR | ATA_DF))) {
4360 qc->err_mask |= AC_ERR_DEV;
4361 ap->hsm_task_state = HSM_ST_ERR;
4362 }
4363
4364fsm_start:
4365 switch (ap->hsm_task_state) {
4366 case HSM_ST_FIRST:
4367 /* Some pre-ATAPI-4 devices assert INTRQ
4368 * at this state when ready to receive CDB.
4369 */
4370
4371 /* check device status */
4372 if (unlikely((status & (ATA_BUSY | ATA_DRQ)) != ATA_DRQ)) {
4373 /* Wrong status. Let EH handle this */
4374 qc->err_mask |= AC_ERR_HSM;
4375 ap->hsm_task_state = HSM_ST_ERR;
4376 goto fsm_start;
4377 }
4378
4379 atapi_send_cdb(ap, qc);
4380
4381 break;
4382
4383 case HSM_ST:
4384 /* complete command or read/write the data register */
4385 if (qc->tf.protocol == ATA_PROT_ATAPI) {
4386 /* ATAPI PIO protocol */
4387 if ((status & ATA_DRQ) == 0) {
4388 /* no more data to transfer */
4389 ap->hsm_task_state = HSM_ST_LAST;
4390 goto fsm_start;
4391 }
4392
4393 atapi_pio_bytes(qc);
4394
4395 if (unlikely(ap->hsm_task_state == HSM_ST_ERR))
4396 /* bad ireason reported by device */
4397 goto fsm_start;
4398
4399 } else {
4400 /* ATA PIO protocol */
4401 if (unlikely((status & ATA_DRQ) == 0)) {
4402 /* handle BSY=0, DRQ=0 as error */
4403 qc->err_mask |= AC_ERR_HSM;
4404 ap->hsm_task_state = HSM_ST_ERR;
4405 goto fsm_start;
4406 }
4407
4408 ata_pio_sectors(qc);
4409
4410 if (ap->hsm_task_state == HSM_ST_LAST &&
4411 (!(qc->tf.flags & ATA_TFLAG_WRITE))) {
4412 /* all data read */
4413 ata_altstatus(ap);
4414 status = ata_chk_status(ap);
4415 goto fsm_start;
4416 }
4417 }
4418
4419 ata_altstatus(ap); /* flush */
4420 break;
4421
4422 case HSM_ST_LAST:
4423 if (unlikely(status & ATA_DRQ)) {
4424 /* handle DRQ=1 as error */
4425 qc->err_mask |= AC_ERR_HSM;
4426 ap->hsm_task_state = HSM_ST_ERR;
4427 goto fsm_start;
4428 }
4429
4430 /* no more data to transfer */
4431 DPRINTK("ata%u: command complete, drv_stat 0x%x\n",
4432 ap->id, status);
4433
4434 ap->hsm_task_state = HSM_ST_IDLE;
4098 4435
4099 /* complete taskfile transaction */ 4436 /* complete taskfile transaction */
4100 qc->err_mask |= ac_err_mask(status); 4437 qc->err_mask |= ac_err_mask(status);
4101 ata_qc_complete(qc); 4438 ata_qc_complete(qc);
4102 break; 4439 break;
4103 4440
4441 case HSM_ST_ERR:
4442 if (qc->tf.command != ATA_CMD_PACKET)
4443 printk(KERN_ERR "ata%u: command error, drv_stat 0x%x host_stat 0x%x\n",
4444 ap->id, status, host_stat);
4445
4446 /* make sure qc->err_mask is available to
4447 * know what's wrong and recover
4448 */
4449 WARN_ON(qc->err_mask == 0);
4450
4451 ap->hsm_task_state = HSM_ST_IDLE;
4452 ata_qc_complete(qc);
4453 break;
4104 default: 4454 default:
4105 goto idle_irq; 4455 goto idle_irq;
4106 } 4456 }
@@ -4151,11 +4501,11 @@ irqreturn_t ata_interrupt (int irq, void *dev_instance, struct pt_regs *regs)
4151 4501
4152 ap = host_set->ports[i]; 4502 ap = host_set->ports[i];
4153 if (ap && 4503 if (ap &&
4154 !(ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR))) { 4504 !(ap->flags & ATA_FLAG_PORT_DISABLED)) {
4155 struct ata_queued_cmd *qc; 4505 struct ata_queued_cmd *qc;
4156 4506
4157 qc = ata_qc_from_tag(ap, ap->active_tag); 4507 qc = ata_qc_from_tag(ap, ap->active_tag);
4158 if (qc && (!(qc->tf.ctl & ATA_NIEN)) && 4508 if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)) &&
4159 (qc->flags & ATA_QCFLAG_ACTIVE)) 4509 (qc->flags & ATA_QCFLAG_ACTIVE))
4160 handled |= ata_host_intr(ap, qc); 4510 handled |= ata_host_intr(ap, qc);
4161 } 4511 }
@@ -4166,79 +4516,6 @@ irqreturn_t ata_interrupt (int irq, void *dev_instance, struct pt_regs *regs)
4166 return IRQ_RETVAL(handled); 4516 return IRQ_RETVAL(handled);
4167} 4517}
4168 4518
4169/**
4170 * atapi_packet_task - Write CDB bytes to hardware
4171 * @_data: Port to which ATAPI device is attached.
4172 *
4173 * When device has indicated its readiness to accept
4174 * a CDB, this function is called. Send the CDB.
4175 * If DMA is to be performed, exit immediately.
4176 * Otherwise, we are in polling mode, so poll
4177 * status under operation succeeds or fails.
4178 *
4179 * LOCKING:
4180 * Kernel thread context (may sleep)
4181 */
4182
4183static void atapi_packet_task(void *_data)
4184{
4185 struct ata_port *ap = _data;
4186 struct ata_queued_cmd *qc;
4187 u8 status;
4188
4189 qc = ata_qc_from_tag(ap, ap->active_tag);
4190 WARN_ON(qc == NULL);
4191 WARN_ON(!(qc->flags & ATA_QCFLAG_ACTIVE));
4192
4193 /* sleep-wait for BSY to clear */
4194 DPRINTK("busy wait\n");
4195 if (ata_busy_sleep(ap, ATA_TMOUT_CDB_QUICK, ATA_TMOUT_CDB)) {
4196 qc->err_mask |= AC_ERR_TIMEOUT;
4197 goto err_out;
4198 }
4199
4200 /* make sure DRQ is set */
4201 status = ata_chk_status(ap);
4202 if ((status & (ATA_BUSY | ATA_DRQ)) != ATA_DRQ) {
4203 qc->err_mask |= AC_ERR_HSM;
4204 goto err_out;
4205 }
4206
4207 /* send SCSI cdb */
4208 DPRINTK("send cdb\n");
4209 WARN_ON(qc->dev->cdb_len < 12);
4210
4211 if (qc->tf.protocol == ATA_PROT_ATAPI_DMA ||
4212 qc->tf.protocol == ATA_PROT_ATAPI_NODATA) {
4213 unsigned long flags;
4214
4215 /* Once we're done issuing command and kicking bmdma,
4216 * irq handler takes over. To not lose irq, we need
4217 * to clear NOINTR flag before sending cdb, but
4218 * interrupt handler shouldn't be invoked before we're
4219 * finished. Hence, the following locking.
4220 */
4221 spin_lock_irqsave(&ap->host_set->lock, flags);
4222 ap->flags &= ~ATA_FLAG_NOINTR;
4223 ata_data_xfer(ap, qc->cdb, qc->dev->cdb_len, 1);
4224 if (qc->tf.protocol == ATA_PROT_ATAPI_DMA)
4225 ap->ops->bmdma_start(qc); /* initiate bmdma */
4226 spin_unlock_irqrestore(&ap->host_set->lock, flags);
4227 } else {
4228 ata_data_xfer(ap, qc->cdb, qc->dev->cdb_len, 1);
4229
4230 /* PIO commands are handled by polling */
4231 ap->hsm_task_state = HSM_ST;
4232 ata_queue_pio_task(ap);
4233 }
4234
4235 return;
4236
4237err_out:
4238 ata_poll_qc_complete(qc);
4239}
4240
4241
4242/* 4519/*
4243 * Execute a 'simple' command, that only consists of the opcode 'cmd' itself, 4520 * Execute a 'simple' command, that only consists of the opcode 'cmd' itself,
4244 * without filling any other registers 4521 * without filling any other registers
@@ -4458,7 +4735,6 @@ static void ata_host_init(struct ata_port *ap, struct Scsi_Host *host,
4458 ap->active_tag = ATA_TAG_POISON; 4735 ap->active_tag = ATA_TAG_POISON;
4459 ap->last_ctl = 0xFF; 4736 ap->last_ctl = 0xFF;
4460 4737
4461 INIT_WORK(&ap->packet_task, atapi_packet_task, ap);
4462 INIT_WORK(&ap->pio_task, ata_pio_task, ap); 4738 INIT_WORK(&ap->pio_task, ata_pio_task, ap);
4463 INIT_LIST_HEAD(&ap->eh_done_q); 4739 INIT_LIST_HEAD(&ap->eh_done_q);
4464 4740
diff --git a/drivers/scsi/pdc_adma.c b/drivers/scsi/pdc_adma.c
index 5f33cc932e70..f32af5dc58c4 100644
--- a/drivers/scsi/pdc_adma.c
+++ b/drivers/scsi/pdc_adma.c
@@ -457,13 +457,13 @@ static inline unsigned int adma_intr_pkt(struct ata_host_set *host_set)
457 continue; 457 continue;
458 handled = 1; 458 handled = 1;
459 adma_enter_reg_mode(ap); 459 adma_enter_reg_mode(ap);
460 if (ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR)) 460 if (ap->flags & ATA_FLAG_PORT_DISABLED)
461 continue; 461 continue;
462 pp = ap->private_data; 462 pp = ap->private_data;
463 if (!pp || pp->state != adma_state_pkt) 463 if (!pp || pp->state != adma_state_pkt)
464 continue; 464 continue;
465 qc = ata_qc_from_tag(ap, ap->active_tag); 465 qc = ata_qc_from_tag(ap, ap->active_tag);
466 if (qc && (!(qc->tf.ctl & ATA_NIEN))) { 466 if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING))) {
467 if ((status & (aPERR | aPSD | aUIRQ))) 467 if ((status & (aPERR | aPSD | aUIRQ)))
468 qc->err_mask |= AC_ERR_OTHER; 468 qc->err_mask |= AC_ERR_OTHER;
469 else if (pp->pkt[0] != cDONE) 469 else if (pp->pkt[0] != cDONE)
@@ -482,13 +482,13 @@ static inline unsigned int adma_intr_mmio(struct ata_host_set *host_set)
482 for (port_no = 0; port_no < host_set->n_ports; ++port_no) { 482 for (port_no = 0; port_no < host_set->n_ports; ++port_no) {
483 struct ata_port *ap; 483 struct ata_port *ap;
484 ap = host_set->ports[port_no]; 484 ap = host_set->ports[port_no];
485 if (ap && (!(ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR)))) { 485 if (ap && (!(ap->flags & ATA_FLAG_PORT_DISABLED))) {
486 struct ata_queued_cmd *qc; 486 struct ata_queued_cmd *qc;
487 struct adma_port_priv *pp = ap->private_data; 487 struct adma_port_priv *pp = ap->private_data;
488 if (!pp || pp->state != adma_state_mmio) 488 if (!pp || pp->state != adma_state_mmio)
489 continue; 489 continue;
490 qc = ata_qc_from_tag(ap, ap->active_tag); 490 qc = ata_qc_from_tag(ap, ap->active_tag);
491 if (qc && (!(qc->tf.ctl & ATA_NIEN))) { 491 if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING))) {
492 492
493 /* check main status, clearing INTRQ */ 493 /* check main status, clearing INTRQ */
494 u8 status = ata_check_status(ap); 494 u8 status = ata_check_status(ap);
diff --git a/drivers/scsi/sata_mv.c b/drivers/scsi/sata_mv.c
index c158de2e757d..e05751e7aad4 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),
@@ -1387,8 +1387,7 @@ static void mv_host_intr(struct ata_host_set *host_set, u32 relevant,
1387 handled++; 1387 handled++;
1388 } 1388 }
1389 1389
1390 if (ap && 1390 if (ap && (ap->flags & ATA_FLAG_PORT_DISABLED))
1391 (ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR)))
1392 continue; 1391 continue;
1393 1392
1394 err_mask = ac_err_mask(ata_status); 1393 err_mask = ac_err_mask(ata_status);
@@ -1409,7 +1408,7 @@ static void mv_host_intr(struct ata_host_set *host_set, u32 relevant,
1409 VPRINTK("port %u IRQ found for qc, " 1408 VPRINTK("port %u IRQ found for qc, "
1410 "ata_status 0x%x\n", port,ata_status); 1409 "ata_status 0x%x\n", port,ata_status);
1411 /* mark qc status appropriately */ 1410 /* mark qc status appropriately */
1412 if (!(qc->tf.ctl & ATA_NIEN)) { 1411 if (!(qc->tf.flags & ATA_TFLAG_POLLING)) {
1413 qc->err_mask |= err_mask; 1412 qc->err_mask |= err_mask;
1414 ata_qc_complete(qc); 1413 ata_qc_complete(qc);
1415 } 1414 }
diff --git a/drivers/scsi/sata_nv.c b/drivers/scsi/sata_nv.c
index caffadc2e0ae..5168db981dde 100644
--- a/drivers/scsi/sata_nv.c
+++ b/drivers/scsi/sata_nv.c
@@ -309,11 +309,11 @@ static irqreturn_t nv_interrupt (int irq, void *dev_instance,
309 309
310 ap = host_set->ports[i]; 310 ap = host_set->ports[i];
311 if (ap && 311 if (ap &&
312 !(ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR))) { 312 !(ap->flags & ATA_FLAG_PORT_DISABLED)) {
313 struct ata_queued_cmd *qc; 313 struct ata_queued_cmd *qc;
314 314
315 qc = ata_qc_from_tag(ap, ap->active_tag); 315 qc = ata_qc_from_tag(ap, ap->active_tag);
316 if (qc && (!(qc->tf.ctl & ATA_NIEN))) 316 if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)))
317 handled += ata_host_intr(ap, qc); 317 handled += ata_host_intr(ap, qc);
318 else 318 else
319 // No request pending? Clear interrupt status 319 // No request pending? Clear interrupt status
diff --git a/drivers/scsi/sata_promise.c b/drivers/scsi/sata_promise.c
index ba2b7a0983db..7fa807d7d9e1 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
@@ -533,11 +534,11 @@ static irqreturn_t pdc_interrupt (int irq, void *dev_instance, struct pt_regs *r
533 ap = host_set->ports[i]; 534 ap = host_set->ports[i];
534 tmp = mask & (1 << (i + 1)); 535 tmp = mask & (1 << (i + 1));
535 if (tmp && ap && 536 if (tmp && ap &&
536 !(ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR))) { 537 !(ap->flags & ATA_FLAG_PORT_DISABLED)) {
537 struct ata_queued_cmd *qc; 538 struct ata_queued_cmd *qc;
538 539
539 qc = ata_qc_from_tag(ap, ap->active_tag); 540 qc = ata_qc_from_tag(ap, ap->active_tag);
540 if (qc && (!(qc->tf.ctl & ATA_NIEN))) 541 if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)))
541 handled += pdc_host_intr(ap, qc); 542 handled += pdc_host_intr(ap, qc);
542 } 543 }
543 } 544 }
diff --git a/drivers/scsi/sata_qstor.c b/drivers/scsi/sata_qstor.c
index 286482630be3..bfc1dc8e7779 100644
--- a/drivers/scsi/sata_qstor.c
+++ b/drivers/scsi/sata_qstor.c
@@ -177,7 +177,7 @@ static const struct ata_port_info qs_port_info[] = {
177 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 177 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
178 ATA_FLAG_SATA_RESET | 178 ATA_FLAG_SATA_RESET |
179 //FIXME ATA_FLAG_SRST | 179 //FIXME ATA_FLAG_SRST |
180 ATA_FLAG_MMIO, 180 ATA_FLAG_MMIO | ATA_FLAG_PIO_POLLING,
181 .pio_mask = 0x10, /* pio4 */ 181 .pio_mask = 0x10, /* pio4 */
182 .udma_mask = 0x7f, /* udma0-6 */ 182 .udma_mask = 0x7f, /* udma0-6 */
183 .port_ops = &qs_ata_ops, 183 .port_ops = &qs_ata_ops,
@@ -396,14 +396,13 @@ static inline unsigned int qs_intr_pkt(struct ata_host_set *host_set)
396 DPRINTK("SFF=%08x%08x: sCHAN=%u sHST=%d sDST=%02x\n", 396 DPRINTK("SFF=%08x%08x: sCHAN=%u sHST=%d sDST=%02x\n",
397 sff1, sff0, port_no, sHST, sDST); 397 sff1, sff0, port_no, sHST, sDST);
398 handled = 1; 398 handled = 1;
399 if (ap && !(ap->flags & 399 if (ap && !(ap->flags & ATA_FLAG_PORT_DISABLED)) {
400 (ATA_FLAG_PORT_DISABLED|ATA_FLAG_NOINTR))) {
401 struct ata_queued_cmd *qc; 400 struct ata_queued_cmd *qc;
402 struct qs_port_priv *pp = ap->private_data; 401 struct qs_port_priv *pp = ap->private_data;
403 if (!pp || pp->state != qs_state_pkt) 402 if (!pp || pp->state != qs_state_pkt)
404 continue; 403 continue;
405 qc = ata_qc_from_tag(ap, ap->active_tag); 404 qc = ata_qc_from_tag(ap, ap->active_tag);
406 if (qc && (!(qc->tf.ctl & ATA_NIEN))) { 405 if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING))) {
407 switch (sHST) { 406 switch (sHST) {
408 case 0: /* successful CPB */ 407 case 0: /* successful CPB */
409 case 3: /* device error */ 408 case 3: /* device error */
@@ -430,13 +429,13 @@ static inline unsigned int qs_intr_mmio(struct ata_host_set *host_set)
430 struct ata_port *ap; 429 struct ata_port *ap;
431 ap = host_set->ports[port_no]; 430 ap = host_set->ports[port_no];
432 if (ap && 431 if (ap &&
433 !(ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR))) { 432 !(ap->flags & ATA_FLAG_PORT_DISABLED)) {
434 struct ata_queued_cmd *qc; 433 struct ata_queued_cmd *qc;
435 struct qs_port_priv *pp = ap->private_data; 434 struct qs_port_priv *pp = ap->private_data;
436 if (!pp || pp->state != qs_state_mmio) 435 if (!pp || pp->state != qs_state_mmio)
437 continue; 436 continue;
438 qc = ata_qc_from_tag(ap, ap->active_tag); 437 qc = ata_qc_from_tag(ap, ap->active_tag);
439 if (qc && (!(qc->tf.ctl & ATA_NIEN))) { 438 if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING))) {
440 439
441 /* check main status, clearing INTRQ */ 440 /* check main status, clearing INTRQ */
442 u8 status = ata_check_status(ap); 441 u8 status = ata_check_status(ap);
diff --git a/drivers/scsi/sata_sx4.c b/drivers/scsi/sata_sx4.c
index 9f8a76815402..60ebe5ce32c4 100644
--- a/drivers/scsi/sata_sx4.c
+++ b/drivers/scsi/sata_sx4.c
@@ -220,7 +220,7 @@ static const struct ata_port_info pdc_port_info[] = {
220 .sht = &pdc_sata_sht, 220 .sht = &pdc_sata_sht,
221 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 221 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
222 ATA_FLAG_SRST | ATA_FLAG_MMIO | 222 ATA_FLAG_SRST | ATA_FLAG_MMIO |
223 ATA_FLAG_NO_ATAPI, 223 ATA_FLAG_PIO_POLLING,
224 .pio_mask = 0x1f, /* pio0-4 */ 224 .pio_mask = 0x1f, /* pio0-4 */
225 .mwdma_mask = 0x07, /* mwdma0-2 */ 225 .mwdma_mask = 0x07, /* mwdma0-2 */
226 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 226 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
@@ -835,11 +835,11 @@ static irqreturn_t pdc20621_interrupt (int irq, void *dev_instance, struct pt_re
835 tmp = mask & (1 << i); 835 tmp = mask & (1 << i);
836 VPRINTK("seq %u, port_no %u, ap %p, tmp %x\n", i, port_no, ap, tmp); 836 VPRINTK("seq %u, port_no %u, ap %p, tmp %x\n", i, port_no, ap, tmp);
837 if (tmp && ap && 837 if (tmp && ap &&
838 !(ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR))) { 838 !(ap->flags & ATA_FLAG_PORT_DISABLED)) {
839 struct ata_queued_cmd *qc; 839 struct ata_queued_cmd *qc;
840 840
841 qc = ata_qc_from_tag(ap, ap->active_tag); 841 qc = ata_qc_from_tag(ap, ap->active_tag);
842 if (qc && (!(qc->tf.ctl & ATA_NIEN))) 842 if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)))
843 handled += pdc20621_host_intr(ap, qc, (i > 4), 843 handled += pdc20621_host_intr(ap, qc, (i > 4),
844 mmio_base); 844 mmio_base);
845 } 845 }
diff --git a/drivers/scsi/sata_vsc.c b/drivers/scsi/sata_vsc.c
index e124db8e8284..976a6b124af9 100644
--- a/drivers/scsi/sata_vsc.c
+++ b/drivers/scsi/sata_vsc.c
@@ -201,12 +201,12 @@ static irqreturn_t vsc_sata_interrupt (int irq, void *dev_instance,
201 struct ata_port *ap; 201 struct ata_port *ap;
202 202
203 ap = host_set->ports[i]; 203 ap = host_set->ports[i];
204 if (ap && !(ap->flags & 204 if (ap &&
205 (ATA_FLAG_PORT_DISABLED|ATA_FLAG_NOINTR))) { 205 !(ap->flags & ATA_FLAG_PORT_DISABLED)) {
206 struct ata_queued_cmd *qc; 206 struct ata_queued_cmd *qc;
207 207
208 qc = ata_qc_from_tag(ap, ap->active_tag); 208 qc = ata_qc_from_tag(ap, ap->active_tag);
209 if (qc && (!(qc->tf.ctl & ATA_NIEN))) 209 if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)))
210 handled += ata_host_intr(ap, qc); 210 handled += ata_host_intr(ap, qc);
211 } 211 }
212 } 212 }
diff --git a/include/linux/ata.h b/include/linux/ata.h
index b02a16c435e7..469952366ed4 100644
--- a/include/linux/ata.h
+++ b/include/linux/ata.h
@@ -197,6 +197,7 @@ enum {
197 ATA_TFLAG_WRITE = (1 << 3), /* data dir: host->dev==1 (write) */ 197 ATA_TFLAG_WRITE = (1 << 3), /* data dir: host->dev==1 (write) */
198 ATA_TFLAG_LBA = (1 << 4), /* enable LBA */ 198 ATA_TFLAG_LBA = (1 << 4), /* enable LBA */
199 ATA_TFLAG_FUA = (1 << 5), /* enable FUA */ 199 ATA_TFLAG_FUA = (1 << 5), /* enable FUA */
200 ATA_TFLAG_POLLING = (1 << 6), /* set nIEN to 1 and use polling */
200}; 201};
201 202
202enum ata_tf_protocols { 203enum ata_tf_protocols {
@@ -267,6 +268,8 @@ struct ata_taskfile {
267 ((u64) (id)[(n) + 1] << 16) | \ 268 ((u64) (id)[(n) + 1] << 16) | \
268 ((u64) (id)[(n) + 0]) ) 269 ((u64) (id)[(n) + 0]) )
269 270
271#define ata_id_cdb_intr(id) (((id)[0] & 0x60) == 0x20)
272
270static inline unsigned int ata_id_major_version(const u16 *id) 273static inline unsigned int ata_id_major_version(const u16 *id)
271{ 274{
272 unsigned int mver; 275 unsigned int mver;
@@ -306,6 +309,14 @@ static inline int is_atapi_taskfile(const struct ata_taskfile *tf)
306 (tf->protocol == ATA_PROT_ATAPI_DMA); 309 (tf->protocol == ATA_PROT_ATAPI_DMA);
307} 310}
308 311
312static inline int is_multi_taskfile(struct ata_taskfile *tf)
313{
314 return (tf->command == ATA_CMD_READ_MULTI) ||
315 (tf->command == ATA_CMD_WRITE_MULTI) ||
316 (tf->command == ATA_CMD_READ_MULTI_EXT) ||
317 (tf->command == ATA_CMD_WRITE_MULTI_EXT);
318}
319
309static inline int ata_ok(u8 status) 320static inline int ata_ok(u8 status)
310{ 321{
311 return ((status & (ATA_BUSY | ATA_DRDY | ATA_DF | ATA_DRQ | ATA_ERR)) 322 return ((status & (ATA_BUSY | ATA_DRDY | ATA_DF | ATA_DRQ | ATA_ERR))
diff --git a/include/linux/libata.h b/include/linux/libata.h
index afe46457124e..67d07c44b2e7 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -123,6 +123,7 @@ enum {
123 ATA_DFLAG_LBA48 = (1 << 0), /* device supports LBA48 */ 123 ATA_DFLAG_LBA48 = (1 << 0), /* device supports LBA48 */
124 ATA_DFLAG_PIO = (1 << 1), /* device currently in PIO mode */ 124 ATA_DFLAG_PIO = (1 << 1), /* device currently in PIO mode */
125 ATA_DFLAG_LBA = (1 << 2), /* device supports LBA */ 125 ATA_DFLAG_LBA = (1 << 2), /* device supports LBA */
126 ATA_DFLAG_CDB_INTR = (1 << 3), /* device asserts INTRQ when ready for CDB */
126 127
127 ATA_DEV_UNKNOWN = 0, /* unknown device */ 128 ATA_DEV_UNKNOWN = 0, /* unknown device */
128 ATA_DEV_ATA = 1, /* ATA device */ 129 ATA_DEV_ATA = 1, /* ATA device */
@@ -141,8 +142,8 @@ enum {
141 ATA_FLAG_MMIO = (1 << 6), /* use MMIO, not PIO */ 142 ATA_FLAG_MMIO = (1 << 6), /* use MMIO, not PIO */
142 ATA_FLAG_SATA_RESET = (1 << 7), /* (obsolete) use COMRESET */ 143 ATA_FLAG_SATA_RESET = (1 << 7), /* (obsolete) use COMRESET */
143 ATA_FLAG_PIO_DMA = (1 << 8), /* PIO cmds via DMA */ 144 ATA_FLAG_PIO_DMA = (1 << 8), /* PIO cmds via DMA */
144 ATA_FLAG_NOINTR = (1 << 9), /* FIXME: Remove this once 145 ATA_FLAG_PIO_POLLING = (1 << 9), /* use polling PIO if LLD
145 * proper HSM is in place. */ 146 * doesn't handle PIO interrupts */
146 ATA_FLAG_DEBUGMSG = (1 << 10), 147 ATA_FLAG_DEBUGMSG = (1 << 10),
147 ATA_FLAG_NO_ATAPI = (1 << 11), /* No ATAPI support */ 148 ATA_FLAG_NO_ATAPI = (1 << 11), /* No ATAPI support */
148 149
@@ -165,6 +166,8 @@ enum {
165 ATA_TMOUT_PIO = 30 * HZ, 166 ATA_TMOUT_PIO = 30 * HZ,
166 ATA_TMOUT_BOOT = 30 * HZ, /* heuristic */ 167 ATA_TMOUT_BOOT = 30 * HZ, /* heuristic */
167 ATA_TMOUT_BOOT_QUICK = 7 * HZ, /* heuristic */ 168 ATA_TMOUT_BOOT_QUICK = 7 * HZ, /* heuristic */
169 ATA_TMOUT_DATAOUT = 30 * HZ,
170 ATA_TMOUT_DATAOUT_QUICK = 5 * HZ,
168 ATA_TMOUT_CDB = 30 * HZ, 171 ATA_TMOUT_CDB = 30 * HZ,
169 ATA_TMOUT_CDB_QUICK = 5 * HZ, 172 ATA_TMOUT_CDB_QUICK = 5 * HZ,
170 ATA_TMOUT_INTERNAL = 30 * HZ, 173 ATA_TMOUT_INTERNAL = 30 * HZ,
@@ -204,14 +207,16 @@ enum {
204}; 207};
205 208
206enum hsm_task_states { 209enum hsm_task_states {
207 HSM_ST_UNKNOWN, 210 HSM_ST_UNKNOWN, /* state unknown */
208 HSM_ST_IDLE, 211 HSM_ST_IDLE, /* no command on going */
209 HSM_ST_POLL, 212 HSM_ST_POLL, /* same as HSM_ST, waits longer */
210 HSM_ST_TMOUT, 213 HSM_ST_TMOUT, /* timeout */
211 HSM_ST, 214 HSM_ST, /* (waiting the device to) transfer data */
212 HSM_ST_LAST, 215 HSM_ST_LAST, /* (waiting the device to) complete command */
213 HSM_ST_LAST_POLL, 216 HSM_ST_LAST_POLL, /* same as HSM_ST_LAST, waits longer */
214 HSM_ST_ERR, 217 HSM_ST_ERR, /* error */
218 HSM_ST_FIRST, /* (waiting the device to)
219 write CDB or first data block */
215}; 220};
216 221
217enum ata_completion_errors { 222enum ata_completion_errors {
@@ -388,8 +393,6 @@ struct ata_port {
388 struct ata_host_stats stats; 393 struct ata_host_stats stats;
389 struct ata_host_set *host_set; 394 struct ata_host_set *host_set;
390 395
391 struct work_struct packet_task;
392
393 struct work_struct pio_task; 396 struct work_struct pio_task;
394 unsigned int hsm_task_state; 397 unsigned int hsm_task_state;
395 unsigned long pio_task_timeout; 398 unsigned long pio_task_timeout;