diff options
Diffstat (limited to 'drivers/ide/ide-atapi.c')
| -rw-r--r-- | drivers/ide/ide-atapi.c | 309 |
1 files changed, 198 insertions, 111 deletions
diff --git a/drivers/ide/ide-atapi.c b/drivers/ide/ide-atapi.c index 7201b176d75b..eb2181a6a11c 100644 --- a/drivers/ide/ide-atapi.c +++ b/drivers/ide/ide-atapi.c | |||
| @@ -10,6 +10,9 @@ | |||
| 10 | 10 | ||
| 11 | #include <scsi/scsi.h> | 11 | #include <scsi/scsi.h> |
| 12 | 12 | ||
| 13 | #define DRV_NAME "ide-atapi" | ||
| 14 | #define PFX DRV_NAME ": " | ||
| 15 | |||
| 13 | #ifdef DEBUG | 16 | #ifdef DEBUG |
| 14 | #define debug_log(fmt, args...) \ | 17 | #define debug_log(fmt, args...) \ |
| 15 | printk(KERN_INFO "ide: " fmt, ## args) | 18 | printk(KERN_INFO "ide: " fmt, ## args) |
| @@ -74,64 +77,36 @@ EXPORT_SYMBOL_GPL(ide_check_atapi_device); | |||
| 74 | void ide_init_pc(struct ide_atapi_pc *pc) | 77 | void ide_init_pc(struct ide_atapi_pc *pc) |
| 75 | { | 78 | { |
| 76 | memset(pc, 0, sizeof(*pc)); | 79 | memset(pc, 0, sizeof(*pc)); |
| 77 | pc->buf = pc->pc_buf; | ||
| 78 | pc->buf_size = IDE_PC_BUFFER_SIZE; | ||
| 79 | } | 80 | } |
| 80 | EXPORT_SYMBOL_GPL(ide_init_pc); | 81 | EXPORT_SYMBOL_GPL(ide_init_pc); |
| 81 | 82 | ||
| 82 | /* | 83 | /* |
| 83 | * Generate a new packet command request in front of the request queue, before | ||
| 84 | * the current request, so that it will be processed immediately, on the next | ||
| 85 | * pass through the driver. | ||
| 86 | */ | ||
| 87 | static void ide_queue_pc_head(ide_drive_t *drive, struct gendisk *disk, | ||
| 88 | struct ide_atapi_pc *pc, struct request *rq) | ||
| 89 | { | ||
| 90 | blk_rq_init(NULL, rq); | ||
| 91 | rq->cmd_type = REQ_TYPE_SPECIAL; | ||
| 92 | rq->cmd_flags |= REQ_PREEMPT; | ||
| 93 | rq->buffer = (char *)pc; | ||
| 94 | rq->rq_disk = disk; | ||
| 95 | |||
| 96 | if (pc->req_xfer) { | ||
| 97 | rq->data = pc->buf; | ||
| 98 | rq->data_len = pc->req_xfer; | ||
| 99 | } | ||
| 100 | |||
| 101 | memcpy(rq->cmd, pc->c, 12); | ||
| 102 | if (drive->media == ide_tape) | ||
| 103 | rq->cmd[13] = REQ_IDETAPE_PC1; | ||
| 104 | |||
| 105 | drive->hwif->rq = NULL; | ||
| 106 | |||
| 107 | elv_add_request(drive->queue, rq, ELEVATOR_INSERT_FRONT, 0); | ||
| 108 | } | ||
| 109 | |||
| 110 | /* | ||
| 111 | * Add a special packet command request to the tail of the request queue, | 84 | * Add a special packet command request to the tail of the request queue, |
| 112 | * and wait for it to be serviced. | 85 | * and wait for it to be serviced. |
| 113 | */ | 86 | */ |
| 114 | int ide_queue_pc_tail(ide_drive_t *drive, struct gendisk *disk, | 87 | int ide_queue_pc_tail(ide_drive_t *drive, struct gendisk *disk, |
| 115 | struct ide_atapi_pc *pc) | 88 | struct ide_atapi_pc *pc, void *buf, unsigned int bufflen) |
| 116 | { | 89 | { |
| 117 | struct request *rq; | 90 | struct request *rq; |
| 118 | int error; | 91 | int error; |
| 119 | 92 | ||
| 120 | rq = blk_get_request(drive->queue, READ, __GFP_WAIT); | 93 | rq = blk_get_request(drive->queue, READ, __GFP_WAIT); |
| 121 | rq->cmd_type = REQ_TYPE_SPECIAL; | 94 | rq->cmd_type = REQ_TYPE_SPECIAL; |
| 122 | rq->buffer = (char *)pc; | 95 | rq->special = (char *)pc; |
| 123 | 96 | ||
| 124 | if (pc->req_xfer) { | 97 | if (buf && bufflen) { |
| 125 | rq->data = pc->buf; | 98 | error = blk_rq_map_kern(drive->queue, rq, buf, bufflen, |
| 126 | rq->data_len = pc->req_xfer; | 99 | GFP_NOIO); |
| 100 | if (error) | ||
| 101 | goto put_req; | ||
| 127 | } | 102 | } |
| 128 | 103 | ||
| 129 | memcpy(rq->cmd, pc->c, 12); | 104 | memcpy(rq->cmd, pc->c, 12); |
| 130 | if (drive->media == ide_tape) | 105 | if (drive->media == ide_tape) |
| 131 | rq->cmd[13] = REQ_IDETAPE_PC1; | 106 | rq->cmd[13] = REQ_IDETAPE_PC1; |
| 132 | error = blk_execute_rq(drive->queue, disk, rq, 0); | 107 | error = blk_execute_rq(drive->queue, disk, rq, 0); |
| 108 | put_req: | ||
| 133 | blk_put_request(rq); | 109 | blk_put_request(rq); |
| 134 | |||
| 135 | return error; | 110 | return error; |
| 136 | } | 111 | } |
| 137 | EXPORT_SYMBOL_GPL(ide_queue_pc_tail); | 112 | EXPORT_SYMBOL_GPL(ide_queue_pc_tail); |
| @@ -143,7 +118,7 @@ int ide_do_test_unit_ready(ide_drive_t *drive, struct gendisk *disk) | |||
| 143 | ide_init_pc(&pc); | 118 | ide_init_pc(&pc); |
| 144 | pc.c[0] = TEST_UNIT_READY; | 119 | pc.c[0] = TEST_UNIT_READY; |
| 145 | 120 | ||
| 146 | return ide_queue_pc_tail(drive, disk, &pc); | 121 | return ide_queue_pc_tail(drive, disk, &pc, NULL, 0); |
| 147 | } | 122 | } |
| 148 | EXPORT_SYMBOL_GPL(ide_do_test_unit_ready); | 123 | EXPORT_SYMBOL_GPL(ide_do_test_unit_ready); |
| 149 | 124 | ||
| @@ -158,7 +133,7 @@ int ide_do_start_stop(ide_drive_t *drive, struct gendisk *disk, int start) | |||
| 158 | if (drive->media == ide_tape) | 133 | if (drive->media == ide_tape) |
| 159 | pc.flags |= PC_FLAG_WAIT_FOR_DSC; | 134 | pc.flags |= PC_FLAG_WAIT_FOR_DSC; |
| 160 | 135 | ||
| 161 | return ide_queue_pc_tail(drive, disk, &pc); | 136 | return ide_queue_pc_tail(drive, disk, &pc, NULL, 0); |
| 162 | } | 137 | } |
| 163 | EXPORT_SYMBOL_GPL(ide_do_start_stop); | 138 | EXPORT_SYMBOL_GPL(ide_do_start_stop); |
| 164 | 139 | ||
| @@ -173,7 +148,7 @@ int ide_set_media_lock(ide_drive_t *drive, struct gendisk *disk, int on) | |||
| 173 | pc.c[0] = ALLOW_MEDIUM_REMOVAL; | 148 | pc.c[0] = ALLOW_MEDIUM_REMOVAL; |
| 174 | pc.c[4] = on; | 149 | pc.c[4] = on; |
| 175 | 150 | ||
| 176 | return ide_queue_pc_tail(drive, disk, &pc); | 151 | return ide_queue_pc_tail(drive, disk, &pc, NULL, 0); |
| 177 | } | 152 | } |
| 178 | EXPORT_SYMBOL_GPL(ide_set_media_lock); | 153 | EXPORT_SYMBOL_GPL(ide_set_media_lock); |
| 179 | 154 | ||
| @@ -191,20 +166,109 @@ void ide_create_request_sense_cmd(ide_drive_t *drive, struct ide_atapi_pc *pc) | |||
| 191 | } | 166 | } |
| 192 | EXPORT_SYMBOL_GPL(ide_create_request_sense_cmd); | 167 | EXPORT_SYMBOL_GPL(ide_create_request_sense_cmd); |
| 193 | 168 | ||
| 169 | void ide_prep_sense(ide_drive_t *drive, struct request *rq) | ||
| 170 | { | ||
| 171 | struct request_sense *sense = &drive->sense_data; | ||
| 172 | struct request *sense_rq = &drive->sense_rq; | ||
| 173 | unsigned int cmd_len, sense_len; | ||
| 174 | int err; | ||
| 175 | |||
| 176 | switch (drive->media) { | ||
| 177 | case ide_floppy: | ||
| 178 | cmd_len = 255; | ||
| 179 | sense_len = 18; | ||
| 180 | break; | ||
| 181 | case ide_tape: | ||
| 182 | cmd_len = 20; | ||
| 183 | sense_len = 20; | ||
| 184 | break; | ||
| 185 | default: | ||
| 186 | cmd_len = 18; | ||
| 187 | sense_len = 18; | ||
| 188 | } | ||
| 189 | |||
| 190 | BUG_ON(sense_len > sizeof(*sense)); | ||
| 191 | |||
| 192 | if (blk_sense_request(rq) || drive->sense_rq_armed) | ||
| 193 | return; | ||
| 194 | |||
| 195 | memset(sense, 0, sizeof(*sense)); | ||
| 196 | |||
| 197 | blk_rq_init(rq->q, sense_rq); | ||
| 198 | |||
| 199 | err = blk_rq_map_kern(drive->queue, sense_rq, sense, sense_len, | ||
| 200 | GFP_NOIO); | ||
| 201 | if (unlikely(err)) { | ||
| 202 | if (printk_ratelimit()) | ||
| 203 | printk(KERN_WARNING PFX "%s: failed to map sense " | ||
| 204 | "buffer\n", drive->name); | ||
| 205 | return; | ||
| 206 | } | ||
| 207 | |||
| 208 | sense_rq->rq_disk = rq->rq_disk; | ||
| 209 | sense_rq->cmd[0] = GPCMD_REQUEST_SENSE; | ||
| 210 | sense_rq->cmd[4] = cmd_len; | ||
| 211 | sense_rq->cmd_type = REQ_TYPE_SENSE; | ||
| 212 | sense_rq->cmd_flags |= REQ_PREEMPT; | ||
| 213 | |||
| 214 | if (drive->media == ide_tape) | ||
| 215 | sense_rq->cmd[13] = REQ_IDETAPE_PC1; | ||
| 216 | |||
| 217 | drive->sense_rq_armed = true; | ||
| 218 | } | ||
| 219 | EXPORT_SYMBOL_GPL(ide_prep_sense); | ||
| 220 | |||
| 221 | int ide_queue_sense_rq(ide_drive_t *drive, void *special) | ||
| 222 | { | ||
| 223 | /* deferred failure from ide_prep_sense() */ | ||
| 224 | if (!drive->sense_rq_armed) { | ||
| 225 | printk(KERN_WARNING PFX "%s: error queuing a sense request\n", | ||
| 226 | drive->name); | ||
| 227 | return -ENOMEM; | ||
| 228 | } | ||
| 229 | |||
| 230 | drive->sense_rq.special = special; | ||
| 231 | drive->sense_rq_armed = false; | ||
| 232 | |||
| 233 | drive->hwif->rq = NULL; | ||
| 234 | |||
| 235 | elv_add_request(drive->queue, &drive->sense_rq, | ||
| 236 | ELEVATOR_INSERT_FRONT, 0); | ||
| 237 | return 0; | ||
| 238 | } | ||
| 239 | EXPORT_SYMBOL_GPL(ide_queue_sense_rq); | ||
| 240 | |||
| 194 | /* | 241 | /* |
| 195 | * Called when an error was detected during the last packet command. | 242 | * Called when an error was detected during the last packet command. |
| 196 | * We queue a request sense packet command in the head of the request list. | 243 | * We queue a request sense packet command at the head of the request |
| 244 | * queue. | ||
| 197 | */ | 245 | */ |
| 198 | void ide_retry_pc(ide_drive_t *drive, struct gendisk *disk) | 246 | void ide_retry_pc(ide_drive_t *drive) |
| 199 | { | 247 | { |
| 200 | struct request *rq = &drive->request_sense_rq; | 248 | struct request *failed_rq = drive->hwif->rq; |
| 249 | struct request *sense_rq = &drive->sense_rq; | ||
| 201 | struct ide_atapi_pc *pc = &drive->request_sense_pc; | 250 | struct ide_atapi_pc *pc = &drive->request_sense_pc; |
| 202 | 251 | ||
| 203 | (void)ide_read_error(drive); | 252 | (void)ide_read_error(drive); |
| 204 | ide_create_request_sense_cmd(drive, pc); | 253 | |
| 254 | /* init pc from sense_rq */ | ||
| 255 | ide_init_pc(pc); | ||
| 256 | memcpy(pc->c, sense_rq->cmd, 12); | ||
| 257 | |||
| 205 | if (drive->media == ide_tape) | 258 | if (drive->media == ide_tape) |
| 206 | set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags); | 259 | drive->atapi_flags |= IDE_AFLAG_IGNORE_DSC; |
| 207 | ide_queue_pc_head(drive, disk, pc, rq); | 260 | |
| 261 | /* | ||
| 262 | * Push back the failed request and put request sense on top | ||
| 263 | * of it. The failed command will be retried after sense data | ||
| 264 | * is acquired. | ||
| 265 | */ | ||
| 266 | blk_requeue_request(failed_rq->q, failed_rq); | ||
| 267 | drive->hwif->rq = NULL; | ||
| 268 | if (ide_queue_sense_rq(drive, pc)) { | ||
| 269 | blk_start_request(failed_rq); | ||
| 270 | ide_complete_rq(drive, -EIO, blk_rq_bytes(failed_rq)); | ||
| 271 | } | ||
| 208 | } | 272 | } |
| 209 | EXPORT_SYMBOL_GPL(ide_retry_pc); | 273 | EXPORT_SYMBOL_GPL(ide_retry_pc); |
| 210 | 274 | ||
| @@ -231,7 +295,7 @@ int ide_cd_expiry(ide_drive_t *drive) | |||
| 231 | break; | 295 | break; |
| 232 | default: | 296 | default: |
| 233 | if (!(rq->cmd_flags & REQ_QUIET)) | 297 | if (!(rq->cmd_flags & REQ_QUIET)) |
| 234 | printk(KERN_INFO "cmd 0x%x timed out\n", | 298 | printk(KERN_INFO PFX "cmd 0x%x timed out\n", |
| 235 | rq->cmd[0]); | 299 | rq->cmd[0]); |
| 236 | wait = 0; | 300 | wait = 0; |
| 237 | break; | 301 | break; |
| @@ -246,7 +310,7 @@ int ide_cd_get_xferlen(struct request *rq) | |||
| 246 | return 32768; | 310 | return 32768; |
| 247 | else if (blk_sense_request(rq) || blk_pc_request(rq) || | 311 | else if (blk_sense_request(rq) || blk_pc_request(rq) || |
| 248 | rq->cmd_type == REQ_TYPE_ATA_PC) | 312 | rq->cmd_type == REQ_TYPE_ATA_PC) |
| 249 | return rq->data_len; | 313 | return blk_rq_bytes(rq); |
| 250 | else | 314 | else |
| 251 | return 0; | 315 | return 0; |
| 252 | } | 316 | } |
| @@ -265,6 +329,55 @@ void ide_read_bcount_and_ireason(ide_drive_t *drive, u16 *bcount, u8 *ireason) | |||
| 265 | EXPORT_SYMBOL_GPL(ide_read_bcount_and_ireason); | 329 | EXPORT_SYMBOL_GPL(ide_read_bcount_and_ireason); |
| 266 | 330 | ||
| 267 | /* | 331 | /* |
| 332 | * Check the contents of the interrupt reason register and attempt to recover if | ||
| 333 | * there are problems. | ||
| 334 | * | ||
| 335 | * Returns: | ||
| 336 | * - 0 if everything's ok | ||
| 337 | * - 1 if the request has to be terminated. | ||
| 338 | */ | ||
| 339 | int ide_check_ireason(ide_drive_t *drive, struct request *rq, int len, | ||
| 340 | int ireason, int rw) | ||
| 341 | { | ||
| 342 | ide_hwif_t *hwif = drive->hwif; | ||
| 343 | |||
| 344 | debug_log("ireason: 0x%x, rw: 0x%x\n", ireason, rw); | ||
| 345 | |||
| 346 | if (ireason == (!rw << 1)) | ||
| 347 | return 0; | ||
| 348 | else if (ireason == (rw << 1)) { | ||
| 349 | printk(KERN_ERR PFX "%s: %s: wrong transfer direction!\n", | ||
| 350 | drive->name, __func__); | ||
| 351 | |||
| 352 | if (dev_is_idecd(drive)) | ||
| 353 | ide_pad_transfer(drive, rw, len); | ||
| 354 | } else if (!rw && ireason == ATAPI_COD) { | ||
| 355 | if (dev_is_idecd(drive)) { | ||
| 356 | /* | ||
| 357 | * Some drives (ASUS) seem to tell us that status info | ||
| 358 | * is available. Just get it and ignore. | ||
| 359 | */ | ||
| 360 | (void)hwif->tp_ops->read_status(hwif); | ||
| 361 | return 0; | ||
| 362 | } | ||
| 363 | } else { | ||
| 364 | if (ireason & ATAPI_COD) | ||
| 365 | printk(KERN_ERR PFX "%s: CoD != 0 in %s\n", drive->name, | ||
| 366 | __func__); | ||
| 367 | |||
| 368 | /* drive wants a command packet, or invalid ireason... */ | ||
| 369 | printk(KERN_ERR PFX "%s: %s: bad interrupt reason 0x%02x\n", | ||
| 370 | drive->name, __func__, ireason); | ||
| 371 | } | ||
| 372 | |||
| 373 | if (dev_is_idecd(drive) && rq->cmd_type == REQ_TYPE_ATA_PC) | ||
| 374 | rq->cmd_flags |= REQ_FAILED; | ||
| 375 | |||
| 376 | return 1; | ||
| 377 | } | ||
| 378 | EXPORT_SYMBOL_GPL(ide_check_ireason); | ||
| 379 | |||
| 380 | /* | ||
| 268 | * This is the usual interrupt handler which will be called during a packet | 381 | * This is the usual interrupt handler which will be called during a packet |
| 269 | * command. We will transfer some of the data (as requested by the drive) | 382 | * command. We will transfer some of the data (as requested by the drive) |
| 270 | * and will re-point interrupt handler to us. | 383 | * and will re-point interrupt handler to us. |
| @@ -276,7 +389,6 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive) | |||
| 276 | struct ide_cmd *cmd = &hwif->cmd; | 389 | struct ide_cmd *cmd = &hwif->cmd; |
| 277 | struct request *rq = hwif->rq; | 390 | struct request *rq = hwif->rq; |
| 278 | const struct ide_tp_ops *tp_ops = hwif->tp_ops; | 391 | const struct ide_tp_ops *tp_ops = hwif->tp_ops; |
| 279 | xfer_func_t *xferfunc; | ||
| 280 | unsigned int timeout, done; | 392 | unsigned int timeout, done; |
| 281 | u16 bcount; | 393 | u16 bcount; |
| 282 | u8 stat, ireason, dsc = 0; | 394 | u8 stat, ireason, dsc = 0; |
| @@ -299,25 +411,21 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive) | |||
| 299 | 411 | ||
| 300 | if (rc || (drive->media == ide_tape && (stat & ATA_ERR))) { | 412 | if (rc || (drive->media == ide_tape && (stat & ATA_ERR))) { |
| 301 | if (drive->media == ide_floppy) | 413 | if (drive->media == ide_floppy) |
| 302 | printk(KERN_ERR "%s: DMA %s error\n", | 414 | printk(KERN_ERR PFX "%s: DMA %s error\n", |
| 303 | drive->name, rq_data_dir(pc->rq) | 415 | drive->name, rq_data_dir(pc->rq) |
| 304 | ? "write" : "read"); | 416 | ? "write" : "read"); |
| 305 | pc->flags |= PC_FLAG_DMA_ERROR; | 417 | pc->flags |= PC_FLAG_DMA_ERROR; |
| 306 | } else { | 418 | } else |
| 307 | pc->xferred = pc->req_xfer; | 419 | rq->resid_len = 0; |
| 308 | if (drive->pc_update_buffers) | ||
| 309 | drive->pc_update_buffers(drive, pc); | ||
| 310 | } | ||
| 311 | debug_log("%s: DMA finished\n", drive->name); | 420 | debug_log("%s: DMA finished\n", drive->name); |
| 312 | } | 421 | } |
| 313 | 422 | ||
| 314 | /* No more interrupts */ | 423 | /* No more interrupts */ |
| 315 | if ((stat & ATA_DRQ) == 0) { | 424 | if ((stat & ATA_DRQ) == 0) { |
| 316 | int uptodate, error; | 425 | int uptodate, error; |
| 317 | unsigned int done; | ||
| 318 | 426 | ||
| 319 | debug_log("Packet command completed, %d bytes transferred\n", | 427 | debug_log("Packet command completed, %d bytes transferred\n", |
| 320 | pc->xferred); | 428 | blk_rq_bytes(rq)); |
| 321 | 429 | ||
| 322 | pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS; | 430 | pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS; |
| 323 | 431 | ||
| @@ -335,15 +443,15 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive) | |||
| 335 | pc->rq->errors++; | 443 | pc->rq->errors++; |
| 336 | 444 | ||
| 337 | if (rq->cmd[0] == REQUEST_SENSE) { | 445 | if (rq->cmd[0] == REQUEST_SENSE) { |
| 338 | printk(KERN_ERR "%s: I/O error in request sense" | 446 | printk(KERN_ERR PFX "%s: I/O error in request " |
| 339 | " command\n", drive->name); | 447 | "sense command\n", drive->name); |
| 340 | return ide_do_reset(drive); | 448 | return ide_do_reset(drive); |
| 341 | } | 449 | } |
| 342 | 450 | ||
| 343 | debug_log("[cmd %x]: check condition\n", rq->cmd[0]); | 451 | debug_log("[cmd %x]: check condition\n", rq->cmd[0]); |
| 344 | 452 | ||
| 345 | /* Retry operation */ | 453 | /* Retry operation */ |
| 346 | ide_retry_pc(drive, rq->rq_disk); | 454 | ide_retry_pc(drive); |
| 347 | 455 | ||
| 348 | /* queued, but not started */ | 456 | /* queued, but not started */ |
| 349 | return ide_stopped; | 457 | return ide_stopped; |
| @@ -353,6 +461,12 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive) | |||
| 353 | if ((pc->flags & PC_FLAG_WAIT_FOR_DSC) && (stat & ATA_DSC) == 0) | 461 | if ((pc->flags & PC_FLAG_WAIT_FOR_DSC) && (stat & ATA_DSC) == 0) |
| 354 | dsc = 1; | 462 | dsc = 1; |
| 355 | 463 | ||
| 464 | /* | ||
| 465 | * ->pc_callback() might change rq->data_len for | ||
| 466 | * residual count, cache total length. | ||
| 467 | */ | ||
| 468 | done = blk_rq_bytes(rq); | ||
| 469 | |||
| 356 | /* Command finished - Call the callback function */ | 470 | /* Command finished - Call the callback function */ |
| 357 | uptodate = drive->pc_callback(drive, dsc); | 471 | uptodate = drive->pc_callback(drive, dsc); |
| 358 | 472 | ||
| @@ -361,7 +475,6 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive) | |||
| 361 | 475 | ||
| 362 | if (blk_special_request(rq)) { | 476 | if (blk_special_request(rq)) { |
| 363 | rq->errors = 0; | 477 | rq->errors = 0; |
| 364 | done = blk_rq_bytes(rq); | ||
| 365 | error = 0; | 478 | error = 0; |
| 366 | } else { | 479 | } else { |
| 367 | 480 | ||
| @@ -370,22 +483,17 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive) | |||
| 370 | rq->errors = -EIO; | 483 | rq->errors = -EIO; |
| 371 | } | 484 | } |
| 372 | 485 | ||
| 373 | if (drive->media == ide_tape) | ||
| 374 | done = ide_rq_bytes(rq); /* FIXME */ | ||
| 375 | else | ||
| 376 | done = blk_rq_bytes(rq); | ||
| 377 | |||
| 378 | error = uptodate ? 0 : -EIO; | 486 | error = uptodate ? 0 : -EIO; |
| 379 | } | 487 | } |
| 380 | 488 | ||
| 381 | ide_complete_rq(drive, error, done); | 489 | ide_complete_rq(drive, error, blk_rq_bytes(rq)); |
| 382 | return ide_stopped; | 490 | return ide_stopped; |
| 383 | } | 491 | } |
| 384 | 492 | ||
| 385 | if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) { | 493 | if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) { |
| 386 | pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS; | 494 | pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS; |
| 387 | printk(KERN_ERR "%s: The device wants to issue more interrupts " | 495 | printk(KERN_ERR PFX "%s: The device wants to issue more " |
| 388 | "in DMA mode\n", drive->name); | 496 | "interrupts in DMA mode\n", drive->name); |
| 389 | ide_dma_off(drive); | 497 | ide_dma_off(drive); |
| 390 | return ide_do_reset(drive); | 498 | return ide_do_reset(drive); |
| 391 | } | 499 | } |
| @@ -393,43 +501,22 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive) | |||
| 393 | /* Get the number of bytes to transfer on this interrupt. */ | 501 | /* Get the number of bytes to transfer on this interrupt. */ |
| 394 | ide_read_bcount_and_ireason(drive, &bcount, &ireason); | 502 | ide_read_bcount_and_ireason(drive, &bcount, &ireason); |
| 395 | 503 | ||
| 396 | if (ireason & ATAPI_COD) { | 504 | if (ide_check_ireason(drive, rq, bcount, ireason, write)) |
| 397 | printk(KERN_ERR "%s: CoD != 0 in %s\n", drive->name, __func__); | ||
| 398 | return ide_do_reset(drive); | 505 | return ide_do_reset(drive); |
| 399 | } | ||
| 400 | 506 | ||
| 401 | if (((ireason & ATAPI_IO) == ATAPI_IO) == write) { | 507 | done = min_t(unsigned int, bcount, cmd->nleft); |
| 402 | /* Hopefully, we will never get here */ | 508 | ide_pio_bytes(drive, cmd, write, done); |
| 403 | printk(KERN_ERR "%s: We wanted to %s, but the device wants us " | ||
| 404 | "to %s!\n", drive->name, | ||
| 405 | (ireason & ATAPI_IO) ? "Write" : "Read", | ||
| 406 | (ireason & ATAPI_IO) ? "Read" : "Write"); | ||
| 407 | return ide_do_reset(drive); | ||
| 408 | } | ||
| 409 | |||
| 410 | xferfunc = write ? tp_ops->output_data : tp_ops->input_data; | ||
| 411 | |||
| 412 | if (drive->media == ide_floppy && pc->buf == NULL) { | ||
| 413 | done = min_t(unsigned int, bcount, cmd->nleft); | ||
| 414 | ide_pio_bytes(drive, cmd, write, done); | ||
| 415 | } else if (drive->media == ide_tape && pc->bh) { | ||
| 416 | done = drive->pc_io_buffers(drive, pc, bcount, write); | ||
| 417 | } else { | ||
| 418 | done = min_t(unsigned int, bcount, pc->req_xfer - pc->xferred); | ||
| 419 | xferfunc(drive, NULL, pc->cur_pos, done); | ||
| 420 | } | ||
| 421 | 509 | ||
| 422 | /* Update the current position */ | 510 | /* Update transferred byte count */ |
| 423 | pc->xferred += done; | 511 | rq->resid_len -= done; |
| 424 | pc->cur_pos += done; | ||
| 425 | 512 | ||
| 426 | bcount -= done; | 513 | bcount -= done; |
| 427 | 514 | ||
| 428 | if (bcount) | 515 | if (bcount) |
| 429 | ide_pad_transfer(drive, write, bcount); | 516 | ide_pad_transfer(drive, write, bcount); |
| 430 | 517 | ||
| 431 | debug_log("[cmd %x] transferred %d bytes, padded %d bytes\n", | 518 | debug_log("[cmd %x] transferred %d bytes, padded %d bytes, resid: %u\n", |
| 432 | rq->cmd[0], done, bcount); | 519 | rq->cmd[0], done, bcount, rq->resid_len); |
| 433 | 520 | ||
| 434 | /* And set the interrupt handler again */ | 521 | /* And set the interrupt handler again */ |
| 435 | ide_set_handler(drive, ide_pc_intr, timeout); | 522 | ide_set_handler(drive, ide_pc_intr, timeout); |
| @@ -463,13 +550,13 @@ static u8 ide_wait_ireason(ide_drive_t *drive, u8 ireason) | |||
| 463 | 550 | ||
| 464 | while (retries-- && ((ireason & ATAPI_COD) == 0 || | 551 | while (retries-- && ((ireason & ATAPI_COD) == 0 || |
| 465 | (ireason & ATAPI_IO))) { | 552 | (ireason & ATAPI_IO))) { |
| 466 | printk(KERN_ERR "%s: (IO,CoD != (0,1) while issuing " | 553 | printk(KERN_ERR PFX "%s: (IO,CoD != (0,1) while issuing " |
| 467 | "a packet command, retrying\n", drive->name); | 554 | "a packet command, retrying\n", drive->name); |
| 468 | udelay(100); | 555 | udelay(100); |
| 469 | ireason = ide_read_ireason(drive); | 556 | ireason = ide_read_ireason(drive); |
| 470 | if (retries == 0) { | 557 | if (retries == 0) { |
| 471 | printk(KERN_ERR "%s: (IO,CoD != (0,1) while issuing " | 558 | printk(KERN_ERR PFX "%s: (IO,CoD != (0,1) while issuing" |
| 472 | "a packet command, ignoring\n", | 559 | " a packet command, ignoring\n", |
| 473 | drive->name); | 560 | drive->name); |
| 474 | ireason |= ATAPI_COD; | 561 | ireason |= ATAPI_COD; |
| 475 | ireason &= ~ATAPI_IO; | 562 | ireason &= ~ATAPI_IO; |
| @@ -500,7 +587,7 @@ static ide_startstop_t ide_transfer_pc(ide_drive_t *drive) | |||
| 500 | u8 ireason; | 587 | u8 ireason; |
| 501 | 588 | ||
| 502 | if (ide_wait_stat(&startstop, drive, ATA_DRQ, ATA_BUSY, WAIT_READY)) { | 589 | if (ide_wait_stat(&startstop, drive, ATA_DRQ, ATA_BUSY, WAIT_READY)) { |
| 503 | printk(KERN_ERR "%s: Strange, packet command initiated yet " | 590 | printk(KERN_ERR PFX "%s: Strange, packet command initiated yet " |
| 504 | "DRQ isn't asserted\n", drive->name); | 591 | "DRQ isn't asserted\n", drive->name); |
| 505 | return startstop; | 592 | return startstop; |
| 506 | } | 593 | } |
| @@ -525,7 +612,7 @@ static ide_startstop_t ide_transfer_pc(ide_drive_t *drive) | |||
| 525 | 612 | ||
| 526 | /* | 613 | /* |
| 527 | * If necessary schedule the packet transfer to occur 'timeout' | 614 | * If necessary schedule the packet transfer to occur 'timeout' |
| 528 | * miliseconds later in ide_delayed_transfer_pc() after the | 615 | * milliseconds later in ide_delayed_transfer_pc() after the |
| 529 | * device says it's ready for a packet. | 616 | * device says it's ready for a packet. |
| 530 | */ | 617 | */ |
| 531 | if (drive->atapi_flags & IDE_AFLAG_ZIP_DRIVE) { | 618 | if (drive->atapi_flags & IDE_AFLAG_ZIP_DRIVE) { |
| @@ -542,8 +629,8 @@ static ide_startstop_t ide_transfer_pc(ide_drive_t *drive) | |||
| 542 | ireason = ide_wait_ireason(drive, ireason); | 629 | ireason = ide_wait_ireason(drive, ireason); |
| 543 | 630 | ||
| 544 | if ((ireason & ATAPI_COD) == 0 || (ireason & ATAPI_IO)) { | 631 | if ((ireason & ATAPI_COD) == 0 || (ireason & ATAPI_IO)) { |
| 545 | printk(KERN_ERR "%s: (IO,CoD) != (0,1) while issuing " | 632 | printk(KERN_ERR PFX "%s: (IO,CoD) != (0,1) while " |
| 546 | "a packet command\n", drive->name); | 633 | "issuing a packet command\n", drive->name); |
| 547 | 634 | ||
| 548 | return ide_do_reset(drive); | 635 | return ide_do_reset(drive); |
| 549 | } | 636 | } |
| @@ -581,7 +668,7 @@ ide_startstop_t ide_issue_pc(ide_drive_t *drive, struct ide_cmd *cmd) | |||
| 581 | ide_hwif_t *hwif = drive->hwif; | 668 | ide_hwif_t *hwif = drive->hwif; |
| 582 | ide_expiry_t *expiry = NULL; | 669 | ide_expiry_t *expiry = NULL; |
| 583 | struct request *rq = hwif->rq; | 670 | struct request *rq = hwif->rq; |
| 584 | unsigned int timeout; | 671 | unsigned int timeout, bytes; |
| 585 | u16 bcount; | 672 | u16 bcount; |
| 586 | u8 valid_tf; | 673 | u8 valid_tf; |
| 587 | u8 drq_int = !!(drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT); | 674 | u8 drq_int = !!(drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT); |
| @@ -597,14 +684,14 @@ ide_startstop_t ide_issue_pc(ide_drive_t *drive, struct ide_cmd *cmd) | |||
| 597 | } else { | 684 | } else { |
| 598 | pc = drive->pc; | 685 | pc = drive->pc; |
| 599 | 686 | ||
| 600 | /* We haven't transferred any data yet */ | ||
| 601 | pc->xferred = 0; | ||
| 602 | pc->cur_pos = pc->buf; | ||
| 603 | |||
| 604 | valid_tf = IDE_VALID_DEVICE; | 687 | valid_tf = IDE_VALID_DEVICE; |
| 605 | bcount = ((drive->media == ide_tape) ? | 688 | bytes = blk_rq_bytes(rq); |
| 606 | pc->req_xfer : | 689 | bcount = ((drive->media == ide_tape) ? bytes |
| 607 | min(pc->req_xfer, 63 * 1024)); | 690 | : min_t(unsigned int, |
| 691 | bytes, 63 * 1024)); | ||
| 692 | |||
| 693 | /* We haven't transferred any data yet */ | ||
| 694 | rq->resid_len = bcount; | ||
| 608 | 695 | ||
| 609 | if (pc->flags & PC_FLAG_DMA_ERROR) { | 696 | if (pc->flags & PC_FLAG_DMA_ERROR) { |
| 610 | pc->flags &= ~PC_FLAG_DMA_ERROR; | 697 | pc->flags &= ~PC_FLAG_DMA_ERROR; |
