aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/scsi/libata-core.c553
-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.c19
-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, 466 insertions, 186 deletions
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index 9ea102587914..4fd98fceee51 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -74,6 +74,7 @@ static int ata_choose_xfer_mode(const struct ata_port *ap,
74 u8 *xfer_mode_out, 74 u8 *xfer_mode_out,
75 unsigned int *xfer_shift_out); 75 unsigned int *xfer_shift_out);
76static void __ata_qc_complete(struct ata_queued_cmd *qc); 76static void __ata_qc_complete(struct ata_queued_cmd *qc);
77static void ata_pio_error(struct ata_port *ap);
77 78
78static unsigned int ata_unique_id = 1; 79static unsigned int ata_unique_id = 1;
79static struct workqueue_struct *ata_wq; 80static struct workqueue_struct *ata_wq;
@@ -1339,6 +1340,12 @@ retry:
1339 1340
1340 } 1341 }
1341 1342
1343 if (dev->id[59] & 0x100) {
1344 dev->multi_count = dev->id[59] & 0xff;
1345 DPRINTK("ata%u: dev %u multi count %u\n",
1346 ap->id, device, dev->multi_count);
1347 }
1348
1342 ap->host->max_cmd_len = 16; 1349 ap->host->max_cmd_len = 16;
1343 } 1350 }
1344 1351
@@ -1355,6 +1362,9 @@ retry:
1355 ap->cdb_len = (unsigned int) rc; 1362 ap->cdb_len = (unsigned int) rc;
1356 ap->host->max_cmd_len = (unsigned char) ap->cdb_len; 1363 ap->host->max_cmd_len = (unsigned char) ap->cdb_len;
1357 1364
1365 if (ata_id_cdb_intr(dev->id))
1366 dev->flags |= ATA_DFLAG_CDB_INTR;
1367
1358 /* print device info to dmesg */ 1368 /* print device info to dmesg */
1359 printk(KERN_INFO "ata%u: dev %u ATAPI, max %s\n", 1369 printk(KERN_INFO "ata%u: dev %u ATAPI, max %s\n",
1360 ap->id, device, 1370 ap->id, device,
@@ -2802,7 +2812,6 @@ void ata_poll_qc_complete(struct ata_queued_cmd *qc)
2802 unsigned long flags; 2812 unsigned long flags;
2803 2813
2804 spin_lock_irqsave(&ap->host_set->lock, flags); 2814 spin_lock_irqsave(&ap->host_set->lock, flags);
2805 ap->flags &= ~ATA_FLAG_NOINTR;
2806 ata_irq_on(ap); 2815 ata_irq_on(ap);
2807 ata_qc_complete(qc); 2816 ata_qc_complete(qc);
2808 spin_unlock_irqrestore(&ap->host_set->lock, flags); 2817 spin_unlock_irqrestore(&ap->host_set->lock, flags);
@@ -2868,7 +2877,8 @@ static unsigned long ata_pio_poll(struct ata_port *ap)
2868 * None. (executing in kernel thread context) 2877 * None. (executing in kernel thread context)
2869 * 2878 *
2870 * RETURNS: 2879 * RETURNS:
2871 * Non-zero if qc completed, zero otherwise. 2880 * Zero if qc completed.
2881 * Non-zero if has next.
2872 */ 2882 */
2873 2883
2874static int ata_pio_complete (struct ata_port *ap) 2884static int ata_pio_complete (struct ata_port *ap)
@@ -2881,7 +2891,7 @@ static int ata_pio_complete (struct ata_port *ap)
2881 * we enter, BSY will be cleared in a chk-status or two. If not, 2891 * we enter, BSY will be cleared in a chk-status or two. If not,
2882 * the drive is probably seeking or something. Snooze for a couple 2892 * the drive is probably seeking or something. Snooze for a couple
2883 * msecs, then chk-status again. If still busy, fall back to 2893 * msecs, then chk-status again. If still busy, fall back to
2884 * HSM_ST_POLL state. 2894 * HSM_ST_LAST_POLL state.
2885 */ 2895 */
2886 drv_stat = ata_busy_wait(ap, ATA_BUSY, 10); 2896 drv_stat = ata_busy_wait(ap, ATA_BUSY, 10);
2887 if (drv_stat & ATA_BUSY) { 2897 if (drv_stat & ATA_BUSY) {
@@ -2890,7 +2900,7 @@ static int ata_pio_complete (struct ata_port *ap)
2890 if (drv_stat & ATA_BUSY) { 2900 if (drv_stat & ATA_BUSY) {
2891 ap->hsm_task_state = HSM_ST_LAST_POLL; 2901 ap->hsm_task_state = HSM_ST_LAST_POLL;
2892 ap->pio_task_timeout = jiffies + ATA_TMOUT_PIO; 2902 ap->pio_task_timeout = jiffies + ATA_TMOUT_PIO;
2893 return 0; 2903 return 1;
2894 } 2904 }
2895 } 2905 }
2896 2906
@@ -2901,7 +2911,7 @@ static int ata_pio_complete (struct ata_port *ap)
2901 if (!ata_ok(drv_stat)) { 2911 if (!ata_ok(drv_stat)) {
2902 qc->err_mask |= __ac_err_mask(drv_stat); 2912 qc->err_mask |= __ac_err_mask(drv_stat);
2903 ap->hsm_task_state = HSM_ST_ERR; 2913 ap->hsm_task_state = HSM_ST_ERR;
2904 return 0; 2914 return 1;
2905 } 2915 }
2906 2916
2907 ap->hsm_task_state = HSM_ST_IDLE; 2917 ap->hsm_task_state = HSM_ST_IDLE;
@@ -2911,7 +2921,7 @@ static int ata_pio_complete (struct ata_port *ap)
2911 2921
2912 /* another command may start at this point */ 2922 /* another command may start at this point */
2913 2923
2914 return 1; 2924 return 0;
2915} 2925}
2916 2926
2917 2927
@@ -3072,7 +3082,23 @@ static void ata_pio_sector(struct ata_queued_cmd *qc)
3072 page = nth_page(page, (offset >> PAGE_SHIFT)); 3082 page = nth_page(page, (offset >> PAGE_SHIFT));
3073 offset %= PAGE_SIZE; 3083 offset %= PAGE_SIZE;
3074 3084
3075 buf = kmap(page) + offset; 3085 DPRINTK("data %s\n", qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read");
3086
3087 if (PageHighMem(page)) {
3088 unsigned long flags;
3089
3090 local_irq_save(flags);
3091 buf = kmap_atomic(page, KM_IRQ0);
3092
3093 /* do the actual data transfer */
3094 ata_data_xfer(ap, buf + offset, ATA_SECT_SIZE, do_write);
3095
3096 kunmap_atomic(buf, KM_IRQ0);
3097 local_irq_restore(flags);
3098 } else {
3099 buf = page_address(page);
3100 ata_data_xfer(ap, buf + offset, ATA_SECT_SIZE, do_write);
3101 }
3076 3102
3077 qc->cursect++; 3103 qc->cursect++;
3078 qc->cursg_ofs++; 3104 qc->cursg_ofs++;
@@ -3081,14 +3107,151 @@ static void ata_pio_sector(struct ata_queued_cmd *qc)
3081 qc->cursg++; 3107 qc->cursg++;
3082 qc->cursg_ofs = 0; 3108 qc->cursg_ofs = 0;
3083 } 3109 }
3110}
3084 3111
3085 DPRINTK("data %s\n", qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read"); 3112/**
3113 * ata_pio_sectors - Transfer one or many 512-byte sectors.
3114 * @qc: Command on going
3115 *
3116 * Transfer one or many ATA_SECT_SIZE of data from/to the
3117 * ATA device for the DRQ request.
3118 *
3119 * LOCKING:
3120 * Inherited from caller.
3121 */
3122
3123static void ata_pio_sectors(struct ata_queued_cmd *qc)
3124{
3125 if (is_multi_taskfile(&qc->tf)) {
3126 /* READ/WRITE MULTIPLE */
3127 unsigned int nsect;
3128
3129 assert(qc->dev->multi_count);
3130
3131 nsect = min(qc->nsect - qc->cursect, qc->dev->multi_count);
3132 while (nsect--)
3133 ata_pio_sector(qc);
3134 } else
3135 ata_pio_sector(qc);
3136}
3137
3138/**
3139 * atapi_send_cdb - Write CDB bytes to hardware
3140 * @ap: Port to which ATAPI device is attached.
3141 * @qc: Taskfile currently active
3142 *
3143 * When device has indicated its readiness to accept
3144 * a CDB, this function is called. Send the CDB.
3145 *
3146 * LOCKING:
3147 * caller.
3148 */
3149
3150static void atapi_send_cdb(struct ata_port *ap, struct ata_queued_cmd *qc)
3151{
3152 /* send SCSI cdb */
3153 DPRINTK("send cdb\n");
3154 assert(ap->cdb_len >= 12);
3155
3156 ata_data_xfer(ap, qc->cdb, ap->cdb_len, 1);
3157 ata_altstatus(ap); /* flush */
3158
3159 switch (qc->tf.protocol) {
3160 case ATA_PROT_ATAPI:
3161 ap->hsm_task_state = HSM_ST;
3162 break;
3163 case ATA_PROT_ATAPI_NODATA:
3164 ap->hsm_task_state = HSM_ST_LAST;
3165 break;
3166 case ATA_PROT_ATAPI_DMA:
3167 ap->hsm_task_state = HSM_ST_LAST;
3168 /* initiate bmdma */
3169 ap->ops->bmdma_start(qc);
3170 break;
3171 }
3172}
3173
3174/**
3175 * ata_pio_first_block - Write first data block to hardware
3176 * @ap: Port to which ATA/ATAPI device is attached.
3177 *
3178 * When device has indicated its readiness to accept
3179 * the data, this function sends out the CDB or
3180 * the first data block by PIO.
3181 * After this,
3182 * - If polling, ata_pio_task() handles the rest.
3183 * - Otherwise, interrupt handler takes over.
3184 *
3185 * LOCKING:
3186 * Kernel thread context (may sleep)
3187 *
3188 * RETURNS:
3189 * Zero if irq handler takes over
3190 * Non-zero if has next (polling).
3191 */
3192
3193static int ata_pio_first_block(struct ata_port *ap)
3194{
3195 struct ata_queued_cmd *qc;
3196 u8 status;
3197 unsigned long flags;
3198 int has_next;
3199
3200 qc = ata_qc_from_tag(ap, ap->active_tag);
3201 assert(qc != NULL);
3202 assert(qc->flags & ATA_QCFLAG_ACTIVE);
3203
3204 /* if polling, we will stay in the work queue after sending the data.
3205 * otherwise, interrupt handler takes over after sending the data.
3206 */
3207 has_next = (qc->tf.flags & ATA_TFLAG_POLLING);
3208
3209 /* sleep-wait for BSY to clear */
3210 DPRINTK("busy wait\n");
3211 if (ata_busy_sleep(ap, ATA_TMOUT_DATAOUT_QUICK, ATA_TMOUT_DATAOUT)) {
3212 ap->hsm_task_state = HSM_ST_TMOUT;
3213 goto err_out;
3214 }
3215
3216 /* make sure DRQ is set */
3217 status = ata_chk_status(ap);
3218 if ((status & (ATA_BUSY | ATA_DRQ)) != ATA_DRQ) {
3219 /* device status error */
3220 ap->hsm_task_state = HSM_ST_ERR;
3221 goto err_out;
3222 }
3223
3224 /* Send the CDB (atapi) or the first data block (ata pio out).
3225 * During the state transition, interrupt handler shouldn't
3226 * be invoked before the data transfer is complete and
3227 * hsm_task_state is changed. Hence, the following locking.
3228 */
3229 spin_lock_irqsave(&ap->host_set->lock, flags);
3230
3231 if (qc->tf.protocol == ATA_PROT_PIO) {
3232 /* PIO data out protocol.
3233 * send first data block.
3234 */
3235
3236 /* ata_pio_sectors() might change the state to HSM_ST_LAST.
3237 * so, the state is changed here before ata_pio_sectors().
3238 */
3239 ap->hsm_task_state = HSM_ST;
3240 ata_pio_sectors(qc);
3241 ata_altstatus(ap); /* flush */
3242 } else
3243 /* send CDB */
3244 atapi_send_cdb(ap, qc);
3245
3246 spin_unlock_irqrestore(&ap->host_set->lock, flags);
3086 3247
3087 /* do the actual data transfer */ 3248 /* if polling, ata_pio_task() handles the rest.
3088 do_write = (qc->tf.flags & ATA_TFLAG_WRITE); 3249 * otherwise, interrupt handler takes over from here.
3089 ata_data_xfer(ap, buf, ATA_SECT_SIZE, do_write); 3250 */
3251 return has_next;
3090 3252
3091 kunmap(page); 3253err_out:
3254 return 1; /* has next */
3092} 3255}
3093 3256
3094/** 3257/**
@@ -3154,7 +3317,23 @@ next_sg:
3154 /* don't cross page boundaries */ 3317 /* don't cross page boundaries */
3155 count = min(count, (unsigned int)PAGE_SIZE - offset); 3318 count = min(count, (unsigned int)PAGE_SIZE - offset);
3156 3319
3157 buf = kmap(page) + offset; 3320 DPRINTK("data %s\n", qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read");
3321
3322 if (PageHighMem(page)) {
3323 unsigned long flags;
3324
3325 local_irq_save(flags);
3326 buf = kmap_atomic(page, KM_IRQ0);
3327
3328 /* do the actual data transfer */
3329 ata_data_xfer(ap, buf + offset, count, do_write);
3330
3331 kunmap_atomic(buf, KM_IRQ0);
3332 local_irq_restore(flags);
3333 } else {
3334 buf = page_address(page);
3335 ata_data_xfer(ap, buf + offset, count, do_write);
3336 }
3158 3337
3159 bytes -= count; 3338 bytes -= count;
3160 qc->curbytes += count; 3339 qc->curbytes += count;
@@ -3165,13 +3344,6 @@ next_sg:
3165 qc->cursg_ofs = 0; 3344 qc->cursg_ofs = 0;
3166 } 3345 }
3167 3346
3168 DPRINTK("data %s\n", qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read");
3169
3170 /* do the actual data transfer */
3171 ata_data_xfer(ap, buf, count, do_write);
3172
3173 kunmap(page);
3174
3175 if (bytes) 3347 if (bytes)
3176 goto next_sg; 3348 goto next_sg;
3177} 3349}
@@ -3208,6 +3380,8 @@ static void atapi_pio_bytes(struct ata_queued_cmd *qc)
3208 if (do_write != i_write) 3380 if (do_write != i_write)
3209 goto err_out; 3381 goto err_out;
3210 3382
3383 VPRINTK("ata%u: xfering %d bytes\n", ap->id, bytes);
3384
3211 __atapi_pio_bytes(qc, bytes); 3385 __atapi_pio_bytes(qc, bytes);
3212 3386
3213 return; 3387 return;
@@ -3278,8 +3452,10 @@ static void ata_pio_block(struct ata_port *ap)
3278 return; 3452 return;
3279 } 3453 }
3280 3454
3281 ata_pio_sector(qc); 3455 ata_pio_sectors(qc);
3282 } 3456 }
3457
3458 ata_altstatus(ap); /* flush */
3283} 3459}
3284 3460
3285static void ata_pio_error(struct ata_port *ap) 3461static void ata_pio_error(struct ata_port *ap)
@@ -3305,22 +3481,23 @@ static void ata_pio_task(void *_data)
3305{ 3481{
3306 struct ata_port *ap = _data; 3482 struct ata_port *ap = _data;
3307 unsigned long timeout; 3483 unsigned long timeout;
3308 int qc_completed; 3484 int has_next;
3309 3485
3310fsm_start: 3486fsm_start:
3311 timeout = 0; 3487 timeout = 0;
3312 qc_completed = 0; 3488 has_next = 1;
3313 3489
3314 switch (ap->hsm_task_state) { 3490 switch (ap->hsm_task_state) {
3315 case HSM_ST_IDLE: 3491 case HSM_ST_FIRST:
3316 return; 3492 has_next = ata_pio_first_block(ap);
3493 break;
3317 3494
3318 case HSM_ST: 3495 case HSM_ST:
3319 ata_pio_block(ap); 3496 ata_pio_block(ap);
3320 break; 3497 break;
3321 3498
3322 case HSM_ST_LAST: 3499 case HSM_ST_LAST:
3323 qc_completed = ata_pio_complete(ap); 3500 has_next = ata_pio_complete(ap);
3324 break; 3501 break;
3325 3502
3326 case HSM_ST_POLL: 3503 case HSM_ST_POLL:
@@ -3332,11 +3509,15 @@ fsm_start:
3332 case HSM_ST_ERR: 3509 case HSM_ST_ERR:
3333 ata_pio_error(ap); 3510 ata_pio_error(ap);
3334 return; 3511 return;
3512
3513 default:
3514 BUG();
3515 return;
3335 } 3516 }
3336 3517
3337 if (timeout) 3518 if (timeout)
3338 queue_delayed_work(ata_wq, &ap->pio_task, timeout); 3519 queue_delayed_work(ata_wq, &ap->pio_task, timeout);
3339 else if (!qc_completed) 3520 else if (has_next)
3340 goto fsm_start; 3521 goto fsm_start;
3341} 3522}
3342 3523
@@ -3399,6 +3580,8 @@ static void ata_qc_timeout(struct ata_queued_cmd *qc)
3399 printk(KERN_ERR "ata%u: command 0x%x timeout, stat 0x%x host_stat 0x%x\n", 3580 printk(KERN_ERR "ata%u: command 0x%x timeout, stat 0x%x host_stat 0x%x\n",
3400 ap->id, qc->tf.command, drv_stat, host_stat); 3581 ap->id, qc->tf.command, drv_stat, host_stat);
3401 3582
3583 ap->hsm_task_state = HSM_ST_IDLE;
3584
3402 /* complete taskfile transaction */ 3585 /* complete taskfile transaction */
3403 qc->err_mask |= ac_err_mask(drv_stat); 3586 qc->err_mask |= ac_err_mask(drv_stat);
3404 ata_qc_complete(qc); 3587 ata_qc_complete(qc);
@@ -3664,43 +3847,103 @@ int ata_qc_issue_prot(struct ata_queued_cmd *qc)
3664{ 3847{
3665 struct ata_port *ap = qc->ap; 3848 struct ata_port *ap = qc->ap;
3666 3849
3850 /* Use polling pio if the LLD doesn't handle
3851 * interrupt driven pio and atapi CDB interrupt.
3852 */
3853 if (ap->flags & ATA_FLAG_PIO_POLLING) {
3854 switch (qc->tf.protocol) {
3855 case ATA_PROT_PIO:
3856 case ATA_PROT_ATAPI:
3857 case ATA_PROT_ATAPI_NODATA:
3858 qc->tf.flags |= ATA_TFLAG_POLLING;
3859 break;
3860 case ATA_PROT_ATAPI_DMA:
3861 if (qc->dev->flags & ATA_DFLAG_CDB_INTR)
3862 BUG();
3863 break;
3864 default:
3865 break;
3866 }
3867 }
3868
3869 /* select the device */
3667 ata_dev_select(ap, qc->dev->devno, 1, 0); 3870 ata_dev_select(ap, qc->dev->devno, 1, 0);
3668 3871
3872 /* start the command */
3669 switch (qc->tf.protocol) { 3873 switch (qc->tf.protocol) {
3670 case ATA_PROT_NODATA: 3874 case ATA_PROT_NODATA:
3875 if (qc->tf.flags & ATA_TFLAG_POLLING)
3876 ata_qc_set_polling(qc);
3877
3671 ata_tf_to_host(ap, &qc->tf); 3878 ata_tf_to_host(ap, &qc->tf);
3879 ap->hsm_task_state = HSM_ST_LAST;
3880
3881 if (qc->tf.flags & ATA_TFLAG_POLLING)
3882 queue_work(ata_wq, &ap->pio_task);
3883
3672 break; 3884 break;
3673 3885
3674 case ATA_PROT_DMA: 3886 case ATA_PROT_DMA:
3887 assert(!(qc->tf.flags & ATA_TFLAG_POLLING));
3888
3675 ap->ops->tf_load(ap, &qc->tf); /* load tf registers */ 3889 ap->ops->tf_load(ap, &qc->tf); /* load tf registers */
3676 ap->ops->bmdma_setup(qc); /* set up bmdma */ 3890 ap->ops->bmdma_setup(qc); /* set up bmdma */
3677 ap->ops->bmdma_start(qc); /* initiate bmdma */ 3891 ap->ops->bmdma_start(qc); /* initiate bmdma */
3892 ap->hsm_task_state = HSM_ST_LAST;
3678 break; 3893 break;
3679 3894
3680 case ATA_PROT_PIO: /* load tf registers, initiate polling pio */ 3895 case ATA_PROT_PIO:
3681 ata_qc_set_polling(qc); 3896 if (qc->tf.flags & ATA_TFLAG_POLLING)
3682 ata_tf_to_host(ap, &qc->tf); 3897 ata_qc_set_polling(qc);
3683 ap->hsm_task_state = HSM_ST;
3684 queue_work(ata_wq, &ap->pio_task);
3685 break;
3686 3898
3687 case ATA_PROT_ATAPI:
3688 ata_qc_set_polling(qc);
3689 ata_tf_to_host(ap, &qc->tf); 3899 ata_tf_to_host(ap, &qc->tf);
3690 queue_work(ata_wq, &ap->packet_task); 3900
3901 if (qc->tf.flags & ATA_TFLAG_WRITE) {
3902 /* PIO data out protocol */
3903 ap->hsm_task_state = HSM_ST_FIRST;
3904 queue_work(ata_wq, &ap->pio_task);
3905
3906 /* always send first data block using
3907 * the ata_pio_task() codepath.
3908 */
3909 } else {
3910 /* PIO data in protocol */
3911 ap->hsm_task_state = HSM_ST;
3912
3913 if (qc->tf.flags & ATA_TFLAG_POLLING)
3914 queue_work(ata_wq, &ap->pio_task);
3915
3916 /* if polling, ata_pio_task() handles the rest.
3917 * otherwise, interrupt handler takes over from here.
3918 */
3919 }
3920
3691 break; 3921 break;
3692 3922
3923 case ATA_PROT_ATAPI:
3693 case ATA_PROT_ATAPI_NODATA: 3924 case ATA_PROT_ATAPI_NODATA:
3694 ap->flags |= ATA_FLAG_NOINTR; 3925 if (qc->tf.flags & ATA_TFLAG_POLLING)
3926 ata_qc_set_polling(qc);
3927
3695 ata_tf_to_host(ap, &qc->tf); 3928 ata_tf_to_host(ap, &qc->tf);
3696 queue_work(ata_wq, &ap->packet_task); 3929 ap->hsm_task_state = HSM_ST_FIRST;
3930
3931 /* send cdb by polling if no cdb interrupt */
3932 if ((!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) ||
3933 (qc->tf.flags & ATA_TFLAG_POLLING))
3934 queue_work(ata_wq, &ap->pio_task);
3697 break; 3935 break;
3698 3936
3699 case ATA_PROT_ATAPI_DMA: 3937 case ATA_PROT_ATAPI_DMA:
3700 ap->flags |= ATA_FLAG_NOINTR; 3938 assert(!(qc->tf.flags & ATA_TFLAG_POLLING));
3939
3701 ap->ops->tf_load(ap, &qc->tf); /* load tf registers */ 3940 ap->ops->tf_load(ap, &qc->tf); /* load tf registers */
3702 ap->ops->bmdma_setup(qc); /* set up bmdma */ 3941 ap->ops->bmdma_setup(qc); /* set up bmdma */
3703 queue_work(ata_wq, &ap->packet_task); 3942 ap->hsm_task_state = HSM_ST_FIRST;
3943
3944 /* send cdb by polling if no cdb interrupt */
3945 if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR))
3946 queue_work(ata_wq, &ap->pio_task);
3704 break; 3947 break;
3705 3948
3706 default: 3949 default:
@@ -3961,48 +4204,144 @@ void ata_bmdma_stop(struct ata_queued_cmd *qc)
3961inline unsigned int ata_host_intr (struct ata_port *ap, 4204inline unsigned int ata_host_intr (struct ata_port *ap,
3962 struct ata_queued_cmd *qc) 4205 struct ata_queued_cmd *qc)
3963{ 4206{
3964 u8 status, host_stat; 4207 u8 status, host_stat = 0;
3965 4208
3966 switch (qc->tf.protocol) { 4209 VPRINTK("ata%u: protocol %d task_state %d\n",
4210 ap->id, qc->tf.protocol, ap->hsm_task_state);
3967 4211
3968 case ATA_PROT_DMA: 4212 /* Check whether we are expecting interrupt in this state */
3969 case ATA_PROT_ATAPI_DMA: 4213 switch (ap->hsm_task_state) {
3970 case ATA_PROT_ATAPI: 4214 case HSM_ST_FIRST:
3971 /* check status of DMA engine */ 4215 /* Check the ATA_DFLAG_CDB_INTR flag is enough here.
3972 host_stat = ap->ops->bmdma_status(ap); 4216 * The flag was turned on only for atapi devices.
3973 VPRINTK("ata%u: host_stat 0x%X\n", ap->id, host_stat); 4217 * No need to check is_atapi_taskfile(&qc->tf) again.
3974 4218 */
3975 /* if it's not our irq... */ 4219 if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR))
3976 if (!(host_stat & ATA_DMA_INTR))
3977 goto idle_irq; 4220 goto idle_irq;
4221 break;
4222 case HSM_ST_LAST:
4223 if (qc->tf.protocol == ATA_PROT_DMA ||
4224 qc->tf.protocol == ATA_PROT_ATAPI_DMA) {
4225 /* check status of DMA engine */
4226 host_stat = ap->ops->bmdma_status(ap);
4227 VPRINTK("ata%u: host_stat 0x%X\n", ap->id, host_stat);
4228
4229 /* if it's not our irq... */
4230 if (!(host_stat & ATA_DMA_INTR))
4231 goto idle_irq;
4232
4233 /* before we do anything else, clear DMA-Start bit */
4234 ap->ops->bmdma_stop(qc);
4235 }
4236 break;
4237 case HSM_ST:
4238 break;
4239 default:
4240 goto idle_irq;
4241 }
3978 4242
3979 /* before we do anything else, clear DMA-Start bit */ 4243 /* check altstatus */
3980 ap->ops->bmdma_stop(qc); 4244 status = ata_altstatus(ap);
4245 if (status & ATA_BUSY)
4246 goto idle_irq;
3981 4247
3982 /* fall through */ 4248 /* check main status, clearing INTRQ */
4249 status = ata_chk_status(ap);
4250 if (unlikely(status & ATA_BUSY))
4251 goto idle_irq;
3983 4252
3984 case ATA_PROT_ATAPI_NODATA: 4253 DPRINTK("ata%u: protocol %d task_state %d (dev_stat 0x%X)\n",
3985 case ATA_PROT_NODATA: 4254 ap->id, qc->tf.protocol, ap->hsm_task_state, status);
3986 /* check altstatus */
3987 status = ata_altstatus(ap);
3988 if (status & ATA_BUSY)
3989 goto idle_irq;
3990 4255
3991 /* check main status, clearing INTRQ */ 4256 /* ack bmdma irq events */
3992 status = ata_chk_status(ap); 4257 ap->ops->irq_clear(ap);
3993 if (unlikely(status & ATA_BUSY))
3994 goto idle_irq;
3995 DPRINTK("ata%u: protocol %d (dev_stat 0x%X)\n",
3996 ap->id, qc->tf.protocol, status);
3997 4258
3998 /* ack bmdma irq events */ 4259 /* check error */
3999 ap->ops->irq_clear(ap); 4260 if (unlikely((status & ATA_ERR) || (host_stat & ATA_DMA_ERR)))
4261 ap->hsm_task_state = HSM_ST_ERR;
4262
4263fsm_start:
4264 switch (ap->hsm_task_state) {
4265 case HSM_ST_FIRST:
4266 /* Some pre-ATAPI-4 devices assert INTRQ
4267 * at this state when ready to receive CDB.
4268 */
4269
4270 /* check device status */
4271 if (unlikely((status & (ATA_BUSY | ATA_DRQ)) != ATA_DRQ)) {
4272 /* Wrong status. Let EH handle this */
4273 ap->hsm_task_state = HSM_ST_ERR;
4274 goto fsm_start;
4275 }
4276
4277 atapi_send_cdb(ap, qc);
4278
4279 break;
4280
4281 case HSM_ST:
4282 /* complete command or read/write the data register */
4283 if (qc->tf.protocol == ATA_PROT_ATAPI) {
4284 /* ATAPI PIO protocol */
4285 if ((status & ATA_DRQ) == 0) {
4286 /* no more data to transfer */
4287 ap->hsm_task_state = HSM_ST_LAST;
4288 goto fsm_start;
4289 }
4290
4291 atapi_pio_bytes(qc);
4292
4293 if (unlikely(ap->hsm_task_state == HSM_ST_ERR))
4294 /* bad ireason reported by device */
4295 goto fsm_start;
4296
4297 } else {
4298 /* ATA PIO protocol */
4299 if (unlikely((status & ATA_DRQ) == 0)) {
4300 /* handle BSY=0, DRQ=0 as error */
4301 ap->hsm_task_state = HSM_ST_ERR;
4302 goto fsm_start;
4303 }
4304
4305 ata_pio_sectors(qc);
4306
4307 if (ap->hsm_task_state == HSM_ST_LAST &&
4308 (!(qc->tf.flags & ATA_TFLAG_WRITE))) {
4309 /* all data read */
4310 ata_altstatus(ap);
4311 status = ata_chk_status(ap);
4312 goto fsm_start;
4313 }
4314 }
4315
4316 ata_altstatus(ap); /* flush */
4317 break;
4318
4319 case HSM_ST_LAST:
4320 if (unlikely(status & ATA_DRQ)) {
4321 /* handle DRQ=1 as error */
4322 ap->hsm_task_state = HSM_ST_ERR;
4323 goto fsm_start;
4324 }
4325
4326 /* no more data to transfer */
4327 DPRINTK("ata%u: command complete, drv_stat 0x%x\n",
4328 ap->id, status);
4329
4330 ap->hsm_task_state = HSM_ST_IDLE;
4000 4331
4001 /* complete taskfile transaction */ 4332 /* complete taskfile transaction */
4002 qc->err_mask |= ac_err_mask(status); 4333 qc->err_mask |= ac_err_mask(status);
4003 ata_qc_complete(qc); 4334 ata_qc_complete(qc);
4004 break; 4335 break;
4005 4336
4337 case HSM_ST_ERR:
4338 printk(KERN_ERR "ata%u: command error, drv_stat 0x%x host_stat 0x%x\n",
4339 ap->id, status, host_stat);
4340
4341 ap->hsm_task_state = HSM_ST_IDLE;
4342 qc->err_mask |= __ac_err_mask(status);
4343 ata_qc_complete(qc);
4344 break;
4006 default: 4345 default:
4007 goto idle_irq; 4346 goto idle_irq;
4008 } 4347 }
@@ -4053,11 +4392,11 @@ irqreturn_t ata_interrupt (int irq, void *dev_instance, struct pt_regs *regs)
4053 4392
4054 ap = host_set->ports[i]; 4393 ap = host_set->ports[i];
4055 if (ap && 4394 if (ap &&
4056 !(ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR))) { 4395 !(ap->flags & ATA_FLAG_PORT_DISABLED)) {
4057 struct ata_queued_cmd *qc; 4396 struct ata_queued_cmd *qc;
4058 4397
4059 qc = ata_qc_from_tag(ap, ap->active_tag); 4398 qc = ata_qc_from_tag(ap, ap->active_tag);
4060 if (qc && (!(qc->tf.ctl & ATA_NIEN)) && 4399 if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)) &&
4061 (qc->flags & ATA_QCFLAG_ACTIVE)) 4400 (qc->flags & ATA_QCFLAG_ACTIVE))
4062 handled |= ata_host_intr(ap, qc); 4401 handled |= ata_host_intr(ap, qc);
4063 } 4402 }
@@ -4069,79 +4408,6 @@ irqreturn_t ata_interrupt (int irq, void *dev_instance, struct pt_regs *regs)
4069} 4408}
4070 4409
4071/** 4410/**
4072 * atapi_packet_task - Write CDB bytes to hardware
4073 * @_data: Port to which ATAPI device is attached.
4074 *
4075 * When device has indicated its readiness to accept
4076 * a CDB, this function is called. Send the CDB.
4077 * If DMA is to be performed, exit immediately.
4078 * Otherwise, we are in polling mode, so poll
4079 * status under operation succeeds or fails.
4080 *
4081 * LOCKING:
4082 * Kernel thread context (may sleep)
4083 */
4084
4085static void atapi_packet_task(void *_data)
4086{
4087 struct ata_port *ap = _data;
4088 struct ata_queued_cmd *qc;
4089 u8 status;
4090
4091 qc = ata_qc_from_tag(ap, ap->active_tag);
4092 assert(qc != NULL);
4093 assert(qc->flags & ATA_QCFLAG_ACTIVE);
4094
4095 /* sleep-wait for BSY to clear */
4096 DPRINTK("busy wait\n");
4097 if (ata_busy_sleep(ap, ATA_TMOUT_CDB_QUICK, ATA_TMOUT_CDB)) {
4098 qc->err_mask |= AC_ERR_ATA_BUS;
4099 goto err_out;
4100 }
4101
4102 /* make sure DRQ is set */
4103 status = ata_chk_status(ap);
4104 if ((status & (ATA_BUSY | ATA_DRQ)) != ATA_DRQ) {
4105 qc->err_mask |= AC_ERR_ATA_BUS;
4106 goto err_out;
4107 }
4108
4109 /* send SCSI cdb */
4110 DPRINTK("send cdb\n");
4111 assert(ap->cdb_len >= 12);
4112
4113 if (qc->tf.protocol == ATA_PROT_ATAPI_DMA ||
4114 qc->tf.protocol == ATA_PROT_ATAPI_NODATA) {
4115 unsigned long flags;
4116
4117 /* Once we're done issuing command and kicking bmdma,
4118 * irq handler takes over. To not lose irq, we need
4119 * to clear NOINTR flag before sending cdb, but
4120 * interrupt handler shouldn't be invoked before we're
4121 * finished. Hence, the following locking.
4122 */
4123 spin_lock_irqsave(&ap->host_set->lock, flags);
4124 ap->flags &= ~ATA_FLAG_NOINTR;
4125 ata_data_xfer(ap, qc->cdb, ap->cdb_len, 1);
4126 if (qc->tf.protocol == ATA_PROT_ATAPI_DMA)
4127 ap->ops->bmdma_start(qc); /* initiate bmdma */
4128 spin_unlock_irqrestore(&ap->host_set->lock, flags);
4129 } else {
4130 ata_data_xfer(ap, qc->cdb, ap->cdb_len, 1);
4131
4132 /* PIO commands are handled by polling */
4133 ap->hsm_task_state = HSM_ST;
4134 queue_work(ata_wq, &ap->pio_task);
4135 }
4136
4137 return;
4138
4139err_out:
4140 ata_poll_qc_complete(qc);
4141}
4142
4143
4144/**
4145 * ata_port_start - Set port up for dma. 4411 * ata_port_start - Set port up for dma.
4146 * @ap: Port to initialize 4412 * @ap: Port to initialize
4147 * 4413 *
@@ -4267,7 +4533,6 @@ static void ata_host_init(struct ata_port *ap, struct Scsi_Host *host,
4267 ap->active_tag = ATA_TAG_POISON; 4533 ap->active_tag = ATA_TAG_POISON;
4268 ap->last_ctl = 0xFF; 4534 ap->last_ctl = 0xFF;
4269 4535
4270 INIT_WORK(&ap->packet_task, atapi_packet_task, ap);
4271 INIT_WORK(&ap->pio_task, ata_pio_task, ap); 4536 INIT_WORK(&ap->pio_task, ata_pio_task, ap);
4272 4537
4273 for (i = 0; i < ATA_MAX_DEVICES; i++) 4538 for (i = 0; i < ATA_MAX_DEVICES; i++)
diff --git a/drivers/scsi/pdc_adma.c b/drivers/scsi/pdc_adma.c
index e8df0c9ec1e6..4daede86f00a 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 b2bf16a9bf4b..17044168ebfe 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),
@@ -1221,8 +1221,7 @@ static void mv_host_intr(struct ata_host_set *host_set, u32 relevant,
1221 handled++; 1221 handled++;
1222 } 1222 }
1223 1223
1224 if (ap && 1224 if (ap && (ap->flags & ATA_FLAG_PORT_DISABLED))
1225 (ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR)))
1226 continue; 1225 continue;
1227 1226
1228 err_mask = ac_err_mask(ata_status); 1227 err_mask = ac_err_mask(ata_status);
@@ -1243,7 +1242,7 @@ static void mv_host_intr(struct ata_host_set *host_set, u32 relevant,
1243 VPRINTK("port %u IRQ found for qc, " 1242 VPRINTK("port %u IRQ found for qc, "
1244 "ata_status 0x%x\n", port,ata_status); 1243 "ata_status 0x%x\n", port,ata_status);
1245 /* mark qc status appropriately */ 1244 /* mark qc status appropriately */
1246 if (!(qc->tf.ctl & ATA_NIEN)) { 1245 if (!(qc->tf.flags & ATA_TFLAG_POLLING)) {
1247 qc->err_mask |= err_mask; 1246 qc->err_mask |= err_mask;
1248 ata_qc_complete(qc); 1247 ata_qc_complete(qc);
1249 } 1248 }
diff --git a/drivers/scsi/sata_nv.c b/drivers/scsi/sata_nv.c
index 4954896dfdb9..8fdb2336f6f3 100644
--- a/drivers/scsi/sata_nv.c
+++ b/drivers/scsi/sata_nv.c
@@ -304,11 +304,11 @@ static irqreturn_t nv_interrupt (int irq, void *dev_instance,
304 304
305 ap = host_set->ports[i]; 305 ap = host_set->ports[i];
306 if (ap && 306 if (ap &&
307 !(ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR))) { 307 !(ap->flags & ATA_FLAG_PORT_DISABLED)) {
308 struct ata_queued_cmd *qc; 308 struct ata_queued_cmd *qc;
309 309
310 qc = ata_qc_from_tag(ap, ap->active_tag); 310 qc = ata_qc_from_tag(ap, ap->active_tag);
311 if (qc && (!(qc->tf.ctl & ATA_NIEN))) 311 if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)))
312 handled += ata_host_intr(ap, qc); 312 handled += ata_host_intr(ap, qc);
313 } 313 }
314 314
diff --git a/drivers/scsi/sata_promise.c b/drivers/scsi/sata_promise.c
index da7fa04b8a73..b4cbc9d6be1b 100644
--- a/drivers/scsi/sata_promise.c
+++ b/drivers/scsi/sata_promise.c
@@ -70,9 +70,6 @@ enum {
70 PDC_HAS_PATA = (1 << 1), /* PDC20375 has PATA */ 70 PDC_HAS_PATA = (1 << 1), /* PDC20375 has PATA */
71 71
72 PDC_RESET = (1 << 11), /* HDMA reset */ 72 PDC_RESET = (1 << 11), /* HDMA reset */
73
74 PDC_COMMON_FLAGS = ATA_FLAG_NO_LEGACY | ATA_FLAG_SRST |
75 ATA_FLAG_MMIO | ATA_FLAG_NO_ATAPI,
76}; 73};
77 74
78 75
@@ -165,7 +162,9 @@ static const struct ata_port_info pdc_port_info[] = {
165 /* board_2037x */ 162 /* board_2037x */
166 { 163 {
167 .sht = &pdc_ata_sht, 164 .sht = &pdc_ata_sht,
168 .host_flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA, 165 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
166 ATA_FLAG_SRST | ATA_FLAG_MMIO |
167 ATA_FLAG_PIO_POLLING,
169 .pio_mask = 0x1f, /* pio0-4 */ 168 .pio_mask = 0x1f, /* pio0-4 */
170 .mwdma_mask = 0x07, /* mwdma0-2 */ 169 .mwdma_mask = 0x07, /* mwdma0-2 */
171 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 170 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
@@ -175,7 +174,9 @@ static const struct ata_port_info pdc_port_info[] = {
175 /* board_20319 */ 174 /* board_20319 */
176 { 175 {
177 .sht = &pdc_ata_sht, 176 .sht = &pdc_ata_sht,
178 .host_flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA, 177 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
178 ATA_FLAG_SRST | ATA_FLAG_MMIO |
179 ATA_FLAG_PIO_POLLING,
179 .pio_mask = 0x1f, /* pio0-4 */ 180 .pio_mask = 0x1f, /* pio0-4 */
180 .mwdma_mask = 0x07, /* mwdma0-2 */ 181 .mwdma_mask = 0x07, /* mwdma0-2 */
181 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 182 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
@@ -185,7 +186,9 @@ static const struct ata_port_info pdc_port_info[] = {
185 /* board_20619 */ 186 /* board_20619 */
186 { 187 {
187 .sht = &pdc_ata_sht, 188 .sht = &pdc_ata_sht,
188 .host_flags = PDC_COMMON_FLAGS | ATA_FLAG_SLAVE_POSS, 189 .host_flags = ATA_FLAG_NO_LEGACY | ATA_FLAG_SRST |
190 ATA_FLAG_MMIO | ATA_FLAG_SLAVE_POSS |
191 ATA_FLAG_PIO_POLLING,
189 .pio_mask = 0x1f, /* pio0-4 */ 192 .pio_mask = 0x1f, /* pio0-4 */
190 .mwdma_mask = 0x07, /* mwdma0-2 */ 193 .mwdma_mask = 0x07, /* mwdma0-2 */
191 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 194 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
@@ -498,11 +501,11 @@ static irqreturn_t pdc_interrupt (int irq, void *dev_instance, struct pt_regs *r
498 ap = host_set->ports[i]; 501 ap = host_set->ports[i];
499 tmp = mask & (1 << (i + 1)); 502 tmp = mask & (1 << (i + 1));
500 if (tmp && ap && 503 if (tmp && ap &&
501 !(ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR))) { 504 !(ap->flags & ATA_FLAG_PORT_DISABLED)) {
502 struct ata_queued_cmd *qc; 505 struct ata_queued_cmd *qc;
503 506
504 qc = ata_qc_from_tag(ap, ap->active_tag); 507 qc = ata_qc_from_tag(ap, ap->active_tag);
505 if (qc && (!(qc->tf.ctl & ATA_NIEN))) 508 if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)))
506 handled += pdc_host_intr(ap, qc); 509 handled += pdc_host_intr(ap, qc);
507 } 510 }
508 } 511 }
diff --git a/drivers/scsi/sata_qstor.c b/drivers/scsi/sata_qstor.c
index de05e2883f9c..6367966941d6 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 94b253b80da8..a33862d2b630 100644
--- a/drivers/scsi/sata_sx4.c
+++ b/drivers/scsi/sata_sx4.c
@@ -221,7 +221,7 @@ static const struct ata_port_info pdc_port_info[] = {
221 .sht = &pdc_sata_sht, 221 .sht = &pdc_sata_sht,
222 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 222 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
223 ATA_FLAG_SRST | ATA_FLAG_MMIO | 223 ATA_FLAG_SRST | ATA_FLAG_MMIO |
224 ATA_FLAG_NO_ATAPI, 224 ATA_FLAG_PIO_POLLING,
225 .pio_mask = 0x1f, /* pio0-4 */ 225 .pio_mask = 0x1f, /* pio0-4 */
226 .mwdma_mask = 0x07, /* mwdma0-2 */ 226 .mwdma_mask = 0x07, /* mwdma0-2 */
227 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 227 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
@@ -836,11 +836,11 @@ static irqreturn_t pdc20621_interrupt (int irq, void *dev_instance, struct pt_re
836 tmp = mask & (1 << i); 836 tmp = mask & (1 << i);
837 VPRINTK("seq %u, port_no %u, ap %p, tmp %x\n", i, port_no, ap, tmp); 837 VPRINTK("seq %u, port_no %u, ap %p, tmp %x\n", i, port_no, ap, tmp);
838 if (tmp && ap && 838 if (tmp && ap &&
839 !(ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR))) { 839 !(ap->flags & ATA_FLAG_PORT_DISABLED)) {
840 struct ata_queued_cmd *qc; 840 struct ata_queued_cmd *qc;
841 841
842 qc = ata_qc_from_tag(ap, ap->active_tag); 842 qc = ata_qc_from_tag(ap, ap->active_tag);
843 if (qc && (!(qc->tf.ctl & ATA_NIEN))) 843 if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)))
844 handled += pdc20621_host_intr(ap, qc, (i > 4), 844 handled += pdc20621_host_intr(ap, qc, (i > 4),
845 mmio_base); 845 mmio_base);
846 } 846 }
diff --git a/drivers/scsi/sata_vsc.c b/drivers/scsi/sata_vsc.c
index fcfa486965b4..f566e17246f0 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 d2873b732bb1..f512104a1a3f 100644
--- a/include/linux/ata.h
+++ b/include/linux/ata.h
@@ -192,6 +192,7 @@ enum {
192 ATA_TFLAG_DEVICE = (1 << 2), /* enable r/w to device reg */ 192 ATA_TFLAG_DEVICE = (1 << 2), /* enable r/w to device reg */
193 ATA_TFLAG_WRITE = (1 << 3), /* data dir: host->dev==1 (write) */ 193 ATA_TFLAG_WRITE = (1 << 3), /* data dir: host->dev==1 (write) */
194 ATA_TFLAG_LBA = (1 << 4), /* enable LBA */ 194 ATA_TFLAG_LBA = (1 << 4), /* enable LBA */
195 ATA_TFLAG_POLLING = (1 << 5), /* set nIEN to 1 and use polling */
195}; 196};
196 197
197enum ata_tf_protocols { 198enum ata_tf_protocols {
@@ -261,6 +262,8 @@ struct ata_taskfile {
261 ((u64) (id)[(n) + 1] << 16) | \ 262 ((u64) (id)[(n) + 1] << 16) | \
262 ((u64) (id)[(n) + 0]) ) 263 ((u64) (id)[(n) + 0]) )
263 264
265#define ata_id_cdb_intr(id) (((id)[0] & 0x60) == 0x20)
266
264static inline int ata_id_current_chs_valid(const u16 *id) 267static inline int ata_id_current_chs_valid(const u16 *id)
265{ 268{
266 /* For ATA-1 devices, if the INITIALIZE DEVICE PARAMETERS command 269 /* For ATA-1 devices, if the INITIALIZE DEVICE PARAMETERS command
@@ -290,6 +293,14 @@ static inline int is_atapi_taskfile(const struct ata_taskfile *tf)
290 (tf->protocol == ATA_PROT_ATAPI_DMA); 293 (tf->protocol == ATA_PROT_ATAPI_DMA);
291} 294}
292 295
296static inline int is_multi_taskfile(struct ata_taskfile *tf)
297{
298 return (tf->command == ATA_CMD_READ_MULTI) ||
299 (tf->command == ATA_CMD_WRITE_MULTI) ||
300 (tf->command == ATA_CMD_READ_MULTI_EXT) ||
301 (tf->command == ATA_CMD_WRITE_MULTI_EXT);
302}
303
293static inline int ata_ok(u8 status) 304static inline int ata_ok(u8 status)
294{ 305{
295 return ((status & (ATA_BUSY | ATA_DRDY | ATA_DF | ATA_DRQ | ATA_ERR)) 306 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 e828e172ccbf..596858e37cc1 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -101,6 +101,7 @@ enum {
101 ATA_DFLAG_PIO = (1 << 1), /* device currently in PIO mode */ 101 ATA_DFLAG_PIO = (1 << 1), /* device currently in PIO mode */
102 ATA_DFLAG_LOCK_SECTORS = (1 << 2), /* don't adjust max_sectors */ 102 ATA_DFLAG_LOCK_SECTORS = (1 << 2), /* don't adjust max_sectors */
103 ATA_DFLAG_LBA = (1 << 3), /* device supports LBA */ 103 ATA_DFLAG_LBA = (1 << 3), /* device supports LBA */
104 ATA_DFLAG_CDB_INTR = (1 << 4), /* device asserts INTRQ when ready for CDB */
104 105
105 ATA_DEV_UNKNOWN = 0, /* unknown device */ 106 ATA_DEV_UNKNOWN = 0, /* unknown device */
106 ATA_DEV_ATA = 1, /* ATA device */ 107 ATA_DEV_ATA = 1, /* ATA device */
@@ -119,8 +120,8 @@ enum {
119 ATA_FLAG_MMIO = (1 << 6), /* use MMIO, not PIO */ 120 ATA_FLAG_MMIO = (1 << 6), /* use MMIO, not PIO */
120 ATA_FLAG_SATA_RESET = (1 << 7), /* use COMRESET */ 121 ATA_FLAG_SATA_RESET = (1 << 7), /* use COMRESET */
121 ATA_FLAG_PIO_DMA = (1 << 8), /* PIO cmds via DMA */ 122 ATA_FLAG_PIO_DMA = (1 << 8), /* PIO cmds via DMA */
122 ATA_FLAG_NOINTR = (1 << 9), /* FIXME: Remove this once 123 ATA_FLAG_PIO_POLLING = (1 << 9), /* use polling PIO if LLD
123 * proper HSM is in place. */ 124 * doesn't handle PIO interrupts */
124 ATA_FLAG_DEBUGMSG = (1 << 10), 125 ATA_FLAG_DEBUGMSG = (1 << 10),
125 ATA_FLAG_NO_ATAPI = (1 << 11), /* No ATAPI support */ 126 ATA_FLAG_NO_ATAPI = (1 << 11), /* No ATAPI support */
126 127
@@ -134,6 +135,8 @@ enum {
134 ATA_TMOUT_PIO = 30 * HZ, 135 ATA_TMOUT_PIO = 30 * HZ,
135 ATA_TMOUT_BOOT = 30 * HZ, /* hueristic */ 136 ATA_TMOUT_BOOT = 30 * HZ, /* hueristic */
136 ATA_TMOUT_BOOT_QUICK = 7 * HZ, /* hueristic */ 137 ATA_TMOUT_BOOT_QUICK = 7 * HZ, /* hueristic */
138 ATA_TMOUT_DATAOUT = 30 * HZ,
139 ATA_TMOUT_DATAOUT_QUICK = 5 * HZ,
137 ATA_TMOUT_CDB = 30 * HZ, 140 ATA_TMOUT_CDB = 30 * HZ,
138 ATA_TMOUT_CDB_QUICK = 5 * HZ, 141 ATA_TMOUT_CDB_QUICK = 5 * HZ,
139 ATA_TMOUT_INTERNAL = 30 * HZ, 142 ATA_TMOUT_INTERNAL = 30 * HZ,
@@ -173,14 +176,16 @@ enum {
173}; 176};
174 177
175enum hsm_task_states { 178enum hsm_task_states {
176 HSM_ST_UNKNOWN, 179 HSM_ST_UNKNOWN, /* state unknown */
177 HSM_ST_IDLE, 180 HSM_ST_IDLE, /* no command on going */
178 HSM_ST_POLL, 181 HSM_ST_POLL, /* same as HSM_ST, waits longer */
179 HSM_ST_TMOUT, 182 HSM_ST_TMOUT, /* timeout */
180 HSM_ST, 183 HSM_ST, /* (waiting the device to) transfer data */
181 HSM_ST_LAST, 184 HSM_ST_LAST, /* (waiting the device to) complete command */
182 HSM_ST_LAST_POLL, 185 HSM_ST_LAST_POLL, /* same as HSM_ST_LAST, waits longer */
183 HSM_ST_ERR, 186 HSM_ST_ERR, /* error */
187 HSM_ST_FIRST, /* (waiting the device to)
188 write CDB or first data block */
184}; 189};
185 190
186enum ata_completion_errors { 191enum ata_completion_errors {
@@ -348,8 +353,6 @@ struct ata_port {
348 struct ata_host_stats stats; 353 struct ata_host_stats stats;
349 struct ata_host_set *host_set; 354 struct ata_host_set *host_set;
350 355
351 struct work_struct packet_task;
352
353 struct work_struct pio_task; 356 struct work_struct pio_task;
354 unsigned int hsm_task_state; 357 unsigned int hsm_task_state;
355 unsigned long pio_task_timeout; 358 unsigned long pio_task_timeout;