diff options
Diffstat (limited to 'drivers/ide/ide-cd.c')
| -rw-r--r-- | drivers/ide/ide-cd.c | 585 |
1 files changed, 293 insertions, 292 deletions
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c index 1afd95ad4653..ad984322da94 100644 --- a/drivers/ide/ide-cd.c +++ b/drivers/ide/ide-cd.c | |||
| @@ -39,12 +39,13 @@ | |||
| 39 | #include <linux/mutex.h> | 39 | #include <linux/mutex.h> |
| 40 | #include <linux/bcd.h> | 40 | #include <linux/bcd.h> |
| 41 | 41 | ||
| 42 | #include <scsi/scsi.h> /* For SCSI -> ATAPI command conversion */ | 42 | /* For SCSI -> ATAPI command conversion */ |
| 43 | #include <scsi/scsi.h> | ||
| 43 | 44 | ||
| 44 | #include <asm/irq.h> | 45 | #include <linux/irq.h> |
| 45 | #include <asm/io.h> | 46 | #include <linux/io.h> |
| 46 | #include <asm/byteorder.h> | 47 | #include <asm/byteorder.h> |
| 47 | #include <asm/uaccess.h> | 48 | #include <linux/uaccess.h> |
| 48 | #include <asm/unaligned.h> | 49 | #include <asm/unaligned.h> |
| 49 | 50 | ||
| 50 | #include "ide-cd.h" | 51 | #include "ide-cd.h" |
| @@ -77,12 +78,11 @@ static void ide_cd_put(struct cdrom_info *cd) | |||
| 77 | mutex_unlock(&idecd_ref_mutex); | 78 | mutex_unlock(&idecd_ref_mutex); |
| 78 | } | 79 | } |
| 79 | 80 | ||
| 80 | /**************************************************************************** | 81 | /* |
| 81 | * Generic packet command support and error handling routines. | 82 | * Generic packet command support and error handling routines. |
| 82 | */ | 83 | */ |
| 83 | 84 | ||
| 84 | /* Mark that we've seen a media change, and invalidate our internal | 85 | /* Mark that we've seen a media change and invalidate our internal buffers. */ |
| 85 | buffers. */ | ||
| 86 | static void cdrom_saw_media_change(ide_drive_t *drive) | 86 | static void cdrom_saw_media_change(ide_drive_t *drive) |
| 87 | { | 87 | { |
| 88 | struct cdrom_info *cd = drive->driver_data; | 88 | struct cdrom_info *cd = drive->driver_data; |
| @@ -105,9 +105,8 @@ static int cdrom_log_sense(ide_drive_t *drive, struct request *rq, | |||
| 105 | break; | 105 | break; |
| 106 | case NOT_READY: | 106 | case NOT_READY: |
| 107 | /* | 107 | /* |
| 108 | * don't care about tray state messages for | 108 | * don't care about tray state messages for e.g. capacity |
| 109 | * e.g. capacity commands or in-progress or | 109 | * commands or in-progress or becoming ready |
| 110 | * becoming ready | ||
| 111 | */ | 110 | */ |
| 112 | if (sense->asc == 0x3a || sense->asc == 0x04) | 111 | if (sense->asc == 0x3a || sense->asc == 0x04) |
| 113 | break; | 112 | break; |
| @@ -115,8 +114,8 @@ static int cdrom_log_sense(ide_drive_t *drive, struct request *rq, | |||
| 115 | break; | 114 | break; |
| 116 | case ILLEGAL_REQUEST: | 115 | case ILLEGAL_REQUEST: |
| 117 | /* | 116 | /* |
| 118 | * don't log START_STOP unit with LoEj set, since | 117 | * don't log START_STOP unit with LoEj set, since we cannot |
| 119 | * we cannot reliably check if drive can auto-close | 118 | * reliably check if drive can auto-close |
| 120 | */ | 119 | */ |
| 121 | if (rq->cmd[0] == GPCMD_START_STOP_UNIT && sense->asc == 0x24) | 120 | if (rq->cmd[0] == GPCMD_START_STOP_UNIT && sense->asc == 0x24) |
| 122 | break; | 121 | break; |
| @@ -124,9 +123,9 @@ static int cdrom_log_sense(ide_drive_t *drive, struct request *rq, | |||
| 124 | break; | 123 | break; |
| 125 | case UNIT_ATTENTION: | 124 | case UNIT_ATTENTION: |
| 126 | /* | 125 | /* |
| 127 | * Make good and sure we've seen this potential media | 126 | * Make good and sure we've seen this potential media change. |
| 128 | * change. Some drives (i.e. Creative) fail to present | 127 | * Some drives (i.e. Creative) fail to present the correct sense |
| 129 | * the correct sense key in the error register. | 128 | * key in the error register. |
| 130 | */ | 129 | */ |
| 131 | cdrom_saw_media_change(drive); | 130 | cdrom_saw_media_change(drive); |
| 132 | break; | 131 | break; |
| @@ -137,8 +136,7 @@ static int cdrom_log_sense(ide_drive_t *drive, struct request *rq, | |||
| 137 | return log; | 136 | return log; |
| 138 | } | 137 | } |
| 139 | 138 | ||
| 140 | static | 139 | static void cdrom_analyze_sense_data(ide_drive_t *drive, |
| 141 | void cdrom_analyze_sense_data(ide_drive_t *drive, | ||
| 142 | struct request *failed_command, | 140 | struct request *failed_command, |
| 143 | struct request_sense *sense) | 141 | struct request_sense *sense) |
| 144 | { | 142 | { |
| @@ -151,15 +149,16 @@ void cdrom_analyze_sense_data(ide_drive_t *drive, | |||
| 151 | return; | 149 | return; |
| 152 | 150 | ||
| 153 | /* | 151 | /* |
| 154 | * If a read toc is executed for a CD-R or CD-RW medium where | 152 | * If a read toc is executed for a CD-R or CD-RW medium where the first |
| 155 | * the first toc has not been recorded yet, it will fail with | 153 | * toc has not been recorded yet, it will fail with 05/24/00 (which is a |
| 156 | * 05/24/00 (which is a confusing error) | 154 | * confusing error) |
| 157 | */ | 155 | */ |
| 158 | if (failed_command && failed_command->cmd[0] == GPCMD_READ_TOC_PMA_ATIP) | 156 | if (failed_command && failed_command->cmd[0] == GPCMD_READ_TOC_PMA_ATIP) |
| 159 | if (sense->sense_key == 0x05 && sense->asc == 0x24) | 157 | if (sense->sense_key == 0x05 && sense->asc == 0x24) |
| 160 | return; | 158 | return; |
| 161 | 159 | ||
| 162 | if (sense->error_code == 0x70) { /* Current Error */ | 160 | /* current error */ |
| 161 | if (sense->error_code == 0x70) { | ||
| 163 | switch (sense->sense_key) { | 162 | switch (sense->sense_key) { |
| 164 | case MEDIUM_ERROR: | 163 | case MEDIUM_ERROR: |
| 165 | case VOLUME_OVERFLOW: | 164 | case VOLUME_OVERFLOW: |
| @@ -178,25 +177,23 @@ void cdrom_analyze_sense_data(ide_drive_t *drive, | |||
| 178 | if (bio_sectors < 4) | 177 | if (bio_sectors < 4) |
| 179 | bio_sectors = 4; | 178 | bio_sectors = 4; |
| 180 | if (drive->queue->hardsect_size == 2048) | 179 | if (drive->queue->hardsect_size == 2048) |
| 181 | sector <<= 2; /* Device sector size is 2K */ | 180 | /* device sector size is 2K */ |
| 181 | sector <<= 2; | ||
| 182 | sector &= ~(bio_sectors - 1); | 182 | sector &= ~(bio_sectors - 1); |
| 183 | valid = (sector - failed_command->sector) << 9; | 183 | valid = (sector - failed_command->sector) << 9; |
| 184 | 184 | ||
| 185 | if (valid < 0) | 185 | if (valid < 0) |
| 186 | valid = 0; | 186 | valid = 0; |
| 187 | if (sector < get_capacity(info->disk) && | 187 | if (sector < get_capacity(info->disk) && |
| 188 | drive->probed_capacity - sector < 4 * 75) { | 188 | drive->probed_capacity - sector < 4 * 75) |
| 189 | set_capacity(info->disk, sector); | 189 | set_capacity(info->disk, sector); |
| 190 | } | ||
| 191 | } | 190 | } |
| 192 | } | 191 | } |
| 193 | 192 | ||
| 194 | ide_cd_log_error(drive->name, failed_command, sense); | 193 | ide_cd_log_error(drive->name, failed_command, sense); |
| 195 | } | 194 | } |
| 196 | 195 | ||
| 197 | /* | 196 | /* Initialize a ide-cd packet command request */ |
| 198 | * Initialize a ide-cd packet command request | ||
| 199 | */ | ||
| 200 | void ide_cd_init_rq(ide_drive_t *drive, struct request *rq) | 197 | void ide_cd_init_rq(ide_drive_t *drive, struct request *rq) |
| 201 | { | 198 | { |
| 202 | struct cdrom_info *cd = drive->driver_data; | 199 | struct cdrom_info *cd = drive->driver_data; |
| @@ -220,7 +217,8 @@ static void cdrom_queue_request_sense(ide_drive_t *drive, void *sense, | |||
| 220 | 217 | ||
| 221 | rq->data = sense; | 218 | rq->data = sense; |
| 222 | rq->cmd[0] = GPCMD_REQUEST_SENSE; | 219 | rq->cmd[0] = GPCMD_REQUEST_SENSE; |
| 223 | rq->cmd[4] = rq->data_len = 18; | 220 | rq->cmd[4] = 18; |
| 221 | rq->data_len = 18; | ||
| 224 | 222 | ||
| 225 | rq->cmd_type = REQ_TYPE_SENSE; | 223 | rq->cmd_type = REQ_TYPE_SENSE; |
| 226 | 224 | ||
| @@ -252,7 +250,7 @@ static void cdrom_end_request(ide_drive_t *drive, int uptodate) | |||
| 252 | } | 250 | } |
| 253 | cdrom_analyze_sense_data(drive, failed, sense); | 251 | cdrom_analyze_sense_data(drive, failed, sense); |
| 254 | /* | 252 | /* |
| 255 | * now end failed request | 253 | * now end the failed request |
| 256 | */ | 254 | */ |
| 257 | if (blk_fs_request(failed)) { | 255 | if (blk_fs_request(failed)) { |
| 258 | if (ide_end_dequeued_request(drive, failed, 0, | 256 | if (ide_end_dequeued_request(drive, failed, 0, |
| @@ -280,21 +278,24 @@ static void cdrom_end_request(ide_drive_t *drive, int uptodate) | |||
| 280 | ide_end_request(drive, uptodate, nsectors); | 278 | ide_end_request(drive, uptodate, nsectors); |
| 281 | } | 279 | } |
| 282 | 280 | ||
| 283 | static void ide_dump_status_no_sense(ide_drive_t *drive, const char *msg, u8 stat) | 281 | static void ide_dump_status_no_sense(ide_drive_t *drive, const char *msg, u8 st) |
| 284 | { | 282 | { |
| 285 | if (stat & 0x80) | 283 | if (st & 0x80) |
| 286 | return; | 284 | return; |
| 287 | ide_dump_status(drive, msg, stat); | 285 | ide_dump_status(drive, msg, st); |
| 288 | } | 286 | } |
| 289 | 287 | ||
| 290 | /* Returns 0 if the request should be continued. | 288 | /* |
| 291 | Returns 1 if the request was ended. */ | 289 | * Returns: |
| 290 | * 0: if the request should be continued. | ||
| 291 | * 1: if the request was ended. | ||
| 292 | */ | ||
| 292 | static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret) | 293 | static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret) |
| 293 | { | 294 | { |
| 294 | struct request *rq = HWGROUP(drive)->rq; | 295 | struct request *rq = HWGROUP(drive)->rq; |
| 295 | int stat, err, sense_key; | 296 | int stat, err, sense_key; |
| 296 | 297 | ||
| 297 | /* Check for errors. */ | 298 | /* check for errors */ |
| 298 | stat = ide_read_status(drive); | 299 | stat = ide_read_status(drive); |
| 299 | 300 | ||
| 300 | if (stat_ret) | 301 | if (stat_ret) |
| @@ -303,20 +304,22 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret) | |||
| 303 | if (OK_STAT(stat, good_stat, BAD_R_STAT)) | 304 | if (OK_STAT(stat, good_stat, BAD_R_STAT)) |
| 304 | return 0; | 305 | return 0; |
| 305 | 306 | ||
| 306 | /* Get the IDE error register. */ | 307 | /* get the IDE error register */ |
| 307 | err = ide_read_error(drive); | 308 | err = ide_read_error(drive); |
| 308 | sense_key = err >> 4; | 309 | sense_key = err >> 4; |
| 309 | 310 | ||
| 310 | if (rq == NULL) { | 311 | if (rq == NULL) { |
| 311 | printk("%s: missing rq in cdrom_decode_status\n", drive->name); | 312 | printk(KERN_ERR "%s: missing rq in %s\n", |
| 313 | drive->name, __func__); | ||
| 312 | return 1; | 314 | return 1; |
| 313 | } | 315 | } |
| 314 | 316 | ||
| 315 | if (blk_sense_request(rq)) { | 317 | if (blk_sense_request(rq)) { |
| 316 | /* We got an error trying to get sense info | 318 | /* |
| 317 | from the drive (probably while trying | 319 | * We got an error trying to get sense info from the drive |
| 318 | to recover from a former error). Just give up. */ | 320 | * (probably while trying to recover from a former error). |
| 319 | 321 | * Just give up. | |
| 322 | */ | ||
| 320 | rq->cmd_flags |= REQ_FAILED; | 323 | rq->cmd_flags |= REQ_FAILED; |
| 321 | cdrom_end_request(drive, 0); | 324 | cdrom_end_request(drive, 0); |
| 322 | ide_error(drive, "request sense failure", stat); | 325 | ide_error(drive, "request sense failure", stat); |
| @@ -332,13 +335,12 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret) | |||
| 332 | if (blk_pc_request(rq) && !rq->errors) | 335 | if (blk_pc_request(rq) && !rq->errors) |
| 333 | rq->errors = SAM_STAT_CHECK_CONDITION; | 336 | rq->errors = SAM_STAT_CHECK_CONDITION; |
| 334 | 337 | ||
| 335 | /* Check for tray open. */ | 338 | /* check for tray open */ |
| 336 | if (sense_key == NOT_READY) { | 339 | if (sense_key == NOT_READY) { |
| 337 | cdrom_saw_media_change(drive); | 340 | cdrom_saw_media_change(drive); |
| 338 | } else if (sense_key == UNIT_ATTENTION) { | 341 | } else if (sense_key == UNIT_ATTENTION) { |
| 339 | /* Check for media change. */ | 342 | /* check for media change */ |
| 340 | cdrom_saw_media_change(drive); | 343 | cdrom_saw_media_change(drive); |
| 341 | /*printk("%s: media changed\n",drive->name);*/ | ||
| 342 | return 0; | 344 | return 0; |
| 343 | } else if (sense_key == ILLEGAL_REQUEST && | 345 | } else if (sense_key == ILLEGAL_REQUEST && |
| 344 | rq->cmd[0] == GPCMD_START_STOP_UNIT) { | 346 | rq->cmd[0] == GPCMD_START_STOP_UNIT) { |
| @@ -350,7 +352,7 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret) | |||
| 350 | * cdrom_log_sense() knows this! | 352 | * cdrom_log_sense() knows this! |
| 351 | */ | 353 | */ |
| 352 | } else if (!(rq->cmd_flags & REQ_QUIET)) { | 354 | } else if (!(rq->cmd_flags & REQ_QUIET)) { |
| 353 | /* Otherwise, print an error. */ | 355 | /* otherwise, print an error */ |
| 354 | ide_dump_status(drive, "packet command error", stat); | 356 | ide_dump_status(drive, "packet command error", stat); |
| 355 | } | 357 | } |
| 356 | 358 | ||
| @@ -366,27 +368,30 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret) | |||
| 366 | } else if (blk_fs_request(rq)) { | 368 | } else if (blk_fs_request(rq)) { |
| 367 | int do_end_request = 0; | 369 | int do_end_request = 0; |
| 368 | 370 | ||
| 369 | /* Handle errors from READ and WRITE requests. */ | 371 | /* handle errors from READ and WRITE requests */ |
| 370 | 372 | ||
| 371 | if (blk_noretry_request(rq)) | 373 | if (blk_noretry_request(rq)) |
| 372 | do_end_request = 1; | 374 | do_end_request = 1; |
| 373 | 375 | ||
| 374 | if (sense_key == NOT_READY) { | 376 | if (sense_key == NOT_READY) { |
| 375 | /* Tray open. */ | 377 | /* tray open */ |
| 376 | if (rq_data_dir(rq) == READ) { | 378 | if (rq_data_dir(rq) == READ) { |
| 377 | cdrom_saw_media_change(drive); | 379 | cdrom_saw_media_change(drive); |
| 378 | 380 | ||
| 379 | /* Fail the request. */ | 381 | /* fail the request */ |
| 380 | printk("%s: tray open\n", drive->name); | 382 | printk(KERN_ERR "%s: tray open\n", drive->name); |
| 381 | do_end_request = 1; | 383 | do_end_request = 1; |
| 382 | } else { | 384 | } else { |
| 383 | struct cdrom_info *info = drive->driver_data; | 385 | struct cdrom_info *info = drive->driver_data; |
| 384 | 386 | ||
| 385 | /* allow the drive 5 seconds to recover, some | 387 | /* |
| 388 | * Allow the drive 5 seconds to recover, some | ||
| 386 | * devices will return this error while flushing | 389 | * devices will return this error while flushing |
| 387 | * data from cache */ | 390 | * data from cache. |
| 391 | */ | ||
| 388 | if (!rq->errors) | 392 | if (!rq->errors) |
| 389 | info->write_timeout = jiffies + ATAPI_WAIT_WRITE_BUSY; | 393 | info->write_timeout = jiffies + |
| 394 | ATAPI_WAIT_WRITE_BUSY; | ||
| 390 | rq->errors = 1; | 395 | rq->errors = 1; |
| 391 | if (time_after(jiffies, info->write_timeout)) | 396 | if (time_after(jiffies, info->write_timeout)) |
| 392 | do_end_request = 1; | 397 | do_end_request = 1; |
| @@ -394,65 +399,68 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret) | |||
| 394 | unsigned long flags; | 399 | unsigned long flags; |
| 395 | 400 | ||
| 396 | /* | 401 | /* |
| 397 | * take a breather relying on the | 402 | * take a breather relying on the unplug |
| 398 | * unplug timer to kick us again | 403 | * timer to kick us again |
| 399 | */ | 404 | */ |
| 400 | spin_lock_irqsave(&ide_lock, flags); | 405 | spin_lock_irqsave(&ide_lock, flags); |
| 401 | blk_plug_device(drive->queue); | 406 | blk_plug_device(drive->queue); |
| 402 | spin_unlock_irqrestore(&ide_lock, flags); | 407 | spin_unlock_irqrestore(&ide_lock, |
| 408 | flags); | ||
| 403 | return 1; | 409 | return 1; |
| 404 | } | 410 | } |
| 405 | } | 411 | } |
| 406 | } else if (sense_key == UNIT_ATTENTION) { | 412 | } else if (sense_key == UNIT_ATTENTION) { |
| 407 | /* Media change. */ | 413 | /* media change */ |
| 408 | cdrom_saw_media_change (drive); | 414 | cdrom_saw_media_change(drive); |
| 409 | 415 | ||
| 410 | /* | 416 | /* |
| 411 | * Arrange to retry the request. | 417 | * Arrange to retry the request but be sure to give up |
| 412 | * But be sure to give up if we've retried | 418 | * if we've retried too many times. |
| 413 | * too many times. | ||
| 414 | */ | 419 | */ |
| 415 | if (++rq->errors > ERROR_MAX) | 420 | if (++rq->errors > ERROR_MAX) |
| 416 | do_end_request = 1; | 421 | do_end_request = 1; |
| 417 | } else if (sense_key == ILLEGAL_REQUEST || | 422 | } else if (sense_key == ILLEGAL_REQUEST || |
| 418 | sense_key == DATA_PROTECT) { | 423 | sense_key == DATA_PROTECT) { |
| 419 | /* | 424 | /* |
| 420 | * No point in retrying after an illegal | 425 | * No point in retrying after an illegal request or data |
| 421 | * request or data protect error. | 426 | * protect error. |
| 422 | */ | 427 | */ |
| 423 | ide_dump_status_no_sense(drive, "command error", stat); | 428 | ide_dump_status_no_sense(drive, "command error", stat); |
| 424 | do_end_request = 1; | 429 | do_end_request = 1; |
| 425 | } else if (sense_key == MEDIUM_ERROR) { | 430 | } else if (sense_key == MEDIUM_ERROR) { |
| 426 | /* | 431 | /* |
| 427 | * No point in re-trying a zillion times on a bad | 432 | * No point in re-trying a zillion times on a bad |
| 428 | * sector... If we got here the error is not correctable | 433 | * sector. If we got here the error is not correctable. |
| 429 | */ | 434 | */ |
| 430 | ide_dump_status_no_sense(drive, "media error (bad sector)", stat); | 435 | ide_dump_status_no_sense(drive, |
| 436 | "media error (bad sector)", | ||
| 437 | stat); | ||
| 431 | do_end_request = 1; | 438 | do_end_request = 1; |
| 432 | } else if (sense_key == BLANK_CHECK) { | 439 | } else if (sense_key == BLANK_CHECK) { |
| 433 | /* Disk appears blank ?? */ | 440 | /* disk appears blank ?? */ |
| 434 | ide_dump_status_no_sense(drive, "media error (blank)", stat); | 441 | ide_dump_status_no_sense(drive, "media error (blank)", |
| 442 | stat); | ||
| 435 | do_end_request = 1; | 443 | do_end_request = 1; |
| 436 | } else if ((err & ~ABRT_ERR) != 0) { | 444 | } else if ((err & ~ABRT_ERR) != 0) { |
| 437 | /* Go to the default handler | 445 | /* go to the default handler for other errors */ |
| 438 | for other errors. */ | ||
| 439 | ide_error(drive, "cdrom_decode_status", stat); | 446 | ide_error(drive, "cdrom_decode_status", stat); |
| 440 | return 1; | 447 | return 1; |
| 441 | } else if ((++rq->errors > ERROR_MAX)) { | 448 | } else if ((++rq->errors > ERROR_MAX)) { |
| 442 | /* We've racked up too many retries. Abort. */ | 449 | /* we've racked up too many retries, abort */ |
| 443 | do_end_request = 1; | 450 | do_end_request = 1; |
| 444 | } | 451 | } |
| 445 | 452 | ||
| 446 | /* End a request through request sense analysis when we have | 453 | /* |
| 447 | sense data. We need this in order to perform end of media | 454 | * End a request through request sense analysis when we have |
| 448 | processing */ | 455 | * sense data. We need this in order to perform end of media |
| 449 | 456 | * processing. | |
| 457 | */ | ||
| 450 | if (do_end_request) | 458 | if (do_end_request) |
| 451 | goto end_request; | 459 | goto end_request; |
| 452 | 460 | ||
| 453 | /* | 461 | /* |
| 454 | * If we got a CHECK_CONDITION status, | 462 | * If we got a CHECK_CONDITION status, queue |
| 455 | * queue a request sense command. | 463 | * a request sense command. |
| 456 | */ | 464 | */ |
| 457 | if (stat & ERR_STAT) | 465 | if (stat & ERR_STAT) |
| 458 | cdrom_queue_request_sense(drive, NULL, NULL); | 466 | cdrom_queue_request_sense(drive, NULL, NULL); |
| @@ -461,7 +469,7 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret) | |||
| 461 | cdrom_end_request(drive, 0); | 469 | cdrom_end_request(drive, 0); |
| 462 | } | 470 | } |
| 463 | 471 | ||
| 464 | /* Retry, or handle the next request. */ | 472 | /* retry, or handle the next request */ |
| 465 | return 1; | 473 | return 1; |
| 466 | 474 | ||
| 467 | end_request: | 475 | end_request: |
| @@ -486,10 +494,10 @@ static int cdrom_timer_expiry(ide_drive_t *drive) | |||
| 486 | unsigned long wait = 0; | 494 | unsigned long wait = 0; |
| 487 | 495 | ||
| 488 | /* | 496 | /* |
| 489 | * Some commands are *slow* and normally take a long time to | 497 | * Some commands are *slow* and normally take a long time to complete. |
| 490 | * complete. Usually we can use the ATAPI "disconnect" to bypass | 498 | * Usually we can use the ATAPI "disconnect" to bypass this, but not all |
| 491 | * this, but not all commands/drives support that. Let | 499 | * commands/drives support that. Let ide_timer_expiry keep polling us |
| 492 | * ide_timer_expiry keep polling us for these. | 500 | * for these. |
| 493 | */ | 501 | */ |
| 494 | switch (rq->cmd[0]) { | 502 | switch (rq->cmd[0]) { |
| 495 | case GPCMD_BLANK: | 503 | case GPCMD_BLANK: |
| @@ -501,20 +509,22 @@ static int cdrom_timer_expiry(ide_drive_t *drive) | |||
| 501 | break; | 509 | break; |
| 502 | default: | 510 | default: |
| 503 | if (!(rq->cmd_flags & REQ_QUIET)) | 511 | if (!(rq->cmd_flags & REQ_QUIET)) |
| 504 | printk(KERN_INFO "ide-cd: cmd 0x%x timed out\n", rq->cmd[0]); | 512 | printk(KERN_INFO "ide-cd: cmd 0x%x timed out\n", |
| 513 | rq->cmd[0]); | ||
| 505 | wait = 0; | 514 | wait = 0; |
| 506 | break; | 515 | break; |
| 507 | } | 516 | } |
| 508 | return wait; | 517 | return wait; |
| 509 | } | 518 | } |
| 510 | 519 | ||
| 511 | /* Set up the device registers for transferring a packet command on DEV, | 520 | /* |
| 512 | expecting to later transfer XFERLEN bytes. HANDLER is the routine | 521 | * Set up the device registers for transferring a packet command on DEV, |
| 513 | which actually transfers the command to the drive. If this is a | 522 | * expecting to later transfer XFERLEN bytes. HANDLER is the routine |
| 514 | drq_interrupt device, this routine will arrange for HANDLER to be | 523 | * which actually transfers the command to the drive. If this is a |
| 515 | called when the interrupt from the drive arrives. Otherwise, HANDLER | 524 | * drq_interrupt device, this routine will arrange for HANDLER to be |
| 516 | will be called immediately after the drive is prepared for the transfer. */ | 525 | * called when the interrupt from the drive arrives. Otherwise, HANDLER |
| 517 | 526 | * will be called immediately after the drive is prepared for the transfer. | |
| 527 | */ | ||
| 518 | static ide_startstop_t cdrom_start_packet_command(ide_drive_t *drive, | 528 | static ide_startstop_t cdrom_start_packet_command(ide_drive_t *drive, |
| 519 | int xferlen, | 529 | int xferlen, |
| 520 | ide_handler_t *handler) | 530 | ide_handler_t *handler) |
| @@ -523,15 +533,15 @@ static ide_startstop_t cdrom_start_packet_command(ide_drive_t *drive, | |||
| 523 | struct cdrom_info *info = drive->driver_data; | 533 | struct cdrom_info *info = drive->driver_data; |
| 524 | ide_hwif_t *hwif = drive->hwif; | 534 | ide_hwif_t *hwif = drive->hwif; |
| 525 | 535 | ||
| 526 | /* Wait for the controller to be idle. */ | 536 | /* wait for the controller to be idle */ |
| 527 | if (ide_wait_stat(&startstop, drive, 0, BUSY_STAT, WAIT_READY)) | 537 | if (ide_wait_stat(&startstop, drive, 0, BUSY_STAT, WAIT_READY)) |
| 528 | return startstop; | 538 | return startstop; |
| 529 | 539 | ||
| 530 | /* FIXME: for Virtual DMA we must check harder */ | 540 | /* FIXME: for Virtual DMA we must check harder */ |
| 531 | if (info->dma) | 541 | if (info->dma) |
| 532 | info->dma = !hwif->dma_setup(drive); | 542 | info->dma = !hwif->dma_ops->dma_setup(drive); |
| 533 | 543 | ||
| 534 | /* Set up the controller registers. */ | 544 | /* set up the controller registers */ |
| 535 | ide_pktcmd_tf_load(drive, IDE_TFLAG_OUT_NSECT | IDE_TFLAG_OUT_LBAL | | 545 | ide_pktcmd_tf_load(drive, IDE_TFLAG_OUT_NSECT | IDE_TFLAG_OUT_LBAL | |
| 536 | IDE_TFLAG_NO_SELECT_MASK, xferlen, info->dma); | 546 | IDE_TFLAG_NO_SELECT_MASK, xferlen, info->dma); |
| 537 | 547 | ||
| @@ -541,7 +551,8 @@ static ide_startstop_t cdrom_start_packet_command(ide_drive_t *drive, | |||
| 541 | drive->waiting_for_dma = 0; | 551 | drive->waiting_for_dma = 0; |
| 542 | 552 | ||
| 543 | /* packet command */ | 553 | /* packet command */ |
| 544 | ide_execute_command(drive, WIN_PACKETCMD, handler, ATAPI_WAIT_PC, cdrom_timer_expiry); | 554 | ide_execute_command(drive, WIN_PACKETCMD, handler, |
| 555 | ATAPI_WAIT_PC, cdrom_timer_expiry); | ||
| 545 | return ide_started; | 556 | return ide_started; |
| 546 | } else { | 557 | } else { |
| 547 | unsigned long flags; | 558 | unsigned long flags; |
| @@ -557,11 +568,12 @@ static ide_startstop_t cdrom_start_packet_command(ide_drive_t *drive, | |||
| 557 | } | 568 | } |
| 558 | } | 569 | } |
| 559 | 570 | ||
| 560 | /* Send a packet command to DRIVE described by CMD_BUF and CMD_LEN. | 571 | /* |
| 561 | The device registers must have already been prepared | 572 | * Send a packet command to DRIVE described by CMD_BUF and CMD_LEN. The device |
| 562 | by cdrom_start_packet_command. | 573 | * registers must have already been prepared by cdrom_start_packet_command. |
| 563 | HANDLER is the interrupt handler to call when the command completes | 574 | * HANDLER is the interrupt handler to call when the command completes or |
| 564 | or there's data ready. */ | 575 | * there's data ready. |
| 576 | */ | ||
| 565 | #define ATAPI_MIN_CDB_BYTES 12 | 577 | #define ATAPI_MIN_CDB_BYTES 12 |
| 566 | static ide_startstop_t cdrom_transfer_packet_command(ide_drive_t *drive, | 578 | static ide_startstop_t cdrom_transfer_packet_command(ide_drive_t *drive, |
| 567 | struct request *rq, | 579 | struct request *rq, |
| @@ -573,24 +585,26 @@ static ide_startstop_t cdrom_transfer_packet_command(ide_drive_t *drive, | |||
| 573 | ide_startstop_t startstop; | 585 | ide_startstop_t startstop; |
| 574 | 586 | ||
| 575 | if (info->cd_flags & IDE_CD_FLAG_DRQ_INTERRUPT) { | 587 | if (info->cd_flags & IDE_CD_FLAG_DRQ_INTERRUPT) { |
| 576 | /* Here we should have been called after receiving an interrupt | 588 | /* |
| 577 | from the device. DRQ should how be set. */ | 589 | * Here we should have been called after receiving an interrupt |
| 590 | * from the device. DRQ should how be set. | ||
| 591 | */ | ||
| 578 | 592 | ||
| 579 | /* Check for errors. */ | 593 | /* check for errors */ |
| 580 | if (cdrom_decode_status(drive, DRQ_STAT, NULL)) | 594 | if (cdrom_decode_status(drive, DRQ_STAT, NULL)) |
| 581 | return ide_stopped; | 595 | return ide_stopped; |
| 582 | 596 | ||
| 583 | /* Ok, next interrupt will be DMA interrupt. */ | 597 | /* ok, next interrupt will be DMA interrupt */ |
| 584 | if (info->dma) | 598 | if (info->dma) |
| 585 | drive->waiting_for_dma = 1; | 599 | drive->waiting_for_dma = 1; |
| 586 | } else { | 600 | } else { |
| 587 | /* Otherwise, we must wait for DRQ to get set. */ | 601 | /* otherwise, we must wait for DRQ to get set */ |
| 588 | if (ide_wait_stat(&startstop, drive, DRQ_STAT, | 602 | if (ide_wait_stat(&startstop, drive, DRQ_STAT, |
| 589 | BUSY_STAT, WAIT_READY)) | 603 | BUSY_STAT, WAIT_READY)) |
| 590 | return startstop; | 604 | return startstop; |
| 591 | } | 605 | } |
| 592 | 606 | ||
| 593 | /* Arm the interrupt handler. */ | 607 | /* arm the interrupt handler */ |
| 594 | ide_set_handler(drive, handler, rq->timeout, cdrom_timer_expiry); | 608 | ide_set_handler(drive, handler, rq->timeout, cdrom_timer_expiry); |
| 595 | 609 | ||
| 596 | /* ATAPI commands get padded out to 12 bytes minimum */ | 610 | /* ATAPI commands get padded out to 12 bytes minimum */ |
| @@ -598,20 +612,19 @@ static ide_startstop_t cdrom_transfer_packet_command(ide_drive_t *drive, | |||
| 598 | if (cmd_len < ATAPI_MIN_CDB_BYTES) | 612 | if (cmd_len < ATAPI_MIN_CDB_BYTES) |
| 599 | cmd_len = ATAPI_MIN_CDB_BYTES; | 613 | cmd_len = ATAPI_MIN_CDB_BYTES; |
| 600 | 614 | ||
| 601 | /* Send the command to the device. */ | 615 | /* send the command to the device */ |
| 602 | HWIF(drive)->atapi_output_bytes(drive, rq->cmd, cmd_len); | 616 | HWIF(drive)->atapi_output_bytes(drive, rq->cmd, cmd_len); |
| 603 | 617 | ||
| 604 | /* Start the DMA if need be */ | 618 | /* start the DMA if need be */ |
| 605 | if (info->dma) | 619 | if (info->dma) |
| 606 | hwif->dma_start(drive); | 620 | hwif->dma_ops->dma_start(drive); |
| 607 | 621 | ||
| 608 | return ide_started; | 622 | return ide_started; |
| 609 | } | 623 | } |
| 610 | 624 | ||
| 611 | /**************************************************************************** | 625 | /* |
| 612 | * Block read functions. | 626 | * Block read functions. |
| 613 | */ | 627 | */ |
| 614 | |||
| 615 | static void ide_cd_pad_transfer(ide_drive_t *drive, xfer_func_t *xf, int len) | 628 | static void ide_cd_pad_transfer(ide_drive_t *drive, xfer_func_t *xf, int len) |
| 616 | { | 629 | { |
| 617 | while (len > 0) { | 630 | while (len > 0) { |
| @@ -649,20 +662,21 @@ static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq, | |||
| 649 | ide_hwif_t *hwif = drive->hwif; | 662 | ide_hwif_t *hwif = drive->hwif; |
| 650 | xfer_func_t *xf; | 663 | xfer_func_t *xf; |
| 651 | 664 | ||
| 652 | /* Whoops... */ | 665 | /* whoops... */ |
| 653 | printk(KERN_ERR "%s: %s: wrong transfer direction!\n", | 666 | printk(KERN_ERR "%s: %s: wrong transfer direction!\n", |
| 654 | drive->name, __func__); | 667 | drive->name, __func__); |
| 655 | 668 | ||
| 656 | xf = rw ? hwif->atapi_output_bytes : hwif->atapi_input_bytes; | 669 | xf = rw ? hwif->atapi_output_bytes : hwif->atapi_input_bytes; |
| 657 | ide_cd_pad_transfer(drive, xf, len); | 670 | ide_cd_pad_transfer(drive, xf, len); |
| 658 | } else if (rw == 0 && ireason == 1) { | 671 | } else if (rw == 0 && ireason == 1) { |
| 659 | /* Some drives (ASUS) seem to tell us that status | 672 | /* |
| 660 | * info is available. just get it and ignore. | 673 | * Some drives (ASUS) seem to tell us that status info is |
| 674 | * available. Just get it and ignore. | ||
| 661 | */ | 675 | */ |
| 662 | (void)ide_read_status(drive); | 676 | (void)ide_read_status(drive); |
| 663 | return 0; | 677 | return 0; |
| 664 | } else { | 678 | } else { |
| 665 | /* Drive wants a command packet, or invalid ireason... */ | 679 | /* drive wants a command packet, or invalid ireason... */ |
| 666 | printk(KERN_ERR "%s: %s: bad interrupt reason 0x%02x\n", | 680 | printk(KERN_ERR "%s: %s: bad interrupt reason 0x%02x\n", |
| 667 | drive->name, __func__, ireason); | 681 | drive->name, __func__, ireason); |
| 668 | } | 682 | } |
| @@ -702,10 +716,10 @@ static int ide_cd_check_transfer_size(ide_drive_t *drive, int len) | |||
| 702 | static ide_startstop_t cdrom_newpc_intr(ide_drive_t *); | 716 | static ide_startstop_t cdrom_newpc_intr(ide_drive_t *); |
| 703 | 717 | ||
| 704 | /* | 718 | /* |
| 705 | * Routine to send a read/write packet command to the drive. | 719 | * Routine to send a read/write packet command to the drive. This is usually |
| 706 | * This is usually called directly from cdrom_start_{read,write}(). | 720 | * called directly from cdrom_start_{read,write}(). However, for drq_interrupt |
| 707 | * However, for drq_interrupt devices, it is called from an interrupt | 721 | * devices, it is called from an interrupt when the drive is ready to accept |
| 708 | * when the drive is ready to accept the command. | 722 | * the command. |
| 709 | */ | 723 | */ |
| 710 | static ide_startstop_t cdrom_start_rw_cont(ide_drive_t *drive) | 724 | static ide_startstop_t cdrom_start_rw_cont(ide_drive_t *drive) |
| 711 | { | 725 | { |
| @@ -727,7 +741,7 @@ static ide_startstop_t cdrom_start_rw_cont(ide_drive_t *drive) | |||
| 727 | * is larger than the buffer size. | 741 | * is larger than the buffer size. |
| 728 | */ | 742 | */ |
| 729 | if (nskip > 0) { | 743 | if (nskip > 0) { |
| 730 | /* Sanity check... */ | 744 | /* sanity check... */ |
| 731 | if (rq->current_nr_sectors != | 745 | if (rq->current_nr_sectors != |
| 732 | bio_cur_sectors(rq->bio)) { | 746 | bio_cur_sectors(rq->bio)) { |
| 733 | printk(KERN_ERR "%s: %s: buffer botch (%u)\n", | 747 | printk(KERN_ERR "%s: %s: buffer botch (%u)\n", |
| @@ -744,10 +758,10 @@ static ide_startstop_t cdrom_start_rw_cont(ide_drive_t *drive) | |||
| 744 | /* the immediate bit */ | 758 | /* the immediate bit */ |
| 745 | rq->cmd[1] = 1 << 3; | 759 | rq->cmd[1] = 1 << 3; |
| 746 | #endif | 760 | #endif |
| 747 | /* Set up the command */ | 761 | /* set up the command */ |
| 748 | rq->timeout = ATAPI_WAIT_PC; | 762 | rq->timeout = ATAPI_WAIT_PC; |
| 749 | 763 | ||
| 750 | /* Send the command to the drive and return. */ | 764 | /* send the command to the drive and return */ |
| 751 | return cdrom_transfer_packet_command(drive, rq, cdrom_newpc_intr); | 765 | return cdrom_transfer_packet_command(drive, rq, cdrom_newpc_intr); |
| 752 | } | 766 | } |
| 753 | 767 | ||
| @@ -767,14 +781,8 @@ static ide_startstop_t cdrom_seek_intr(ide_drive_t *drive) | |||
| 767 | info->cd_flags |= IDE_CD_FLAG_SEEKING; | 781 | info->cd_flags |= IDE_CD_FLAG_SEEKING; |
| 768 | 782 | ||
| 769 | if (retry && time_after(jiffies, info->start_seek + IDECD_SEEK_TIMER)) { | 783 | if (retry && time_after(jiffies, info->start_seek + IDECD_SEEK_TIMER)) { |
| 770 | if (--retry == 0) { | 784 | if (--retry == 0) |
| 771 | /* | ||
| 772 | * this condition is far too common, to bother | ||
| 773 | * users about it | ||
| 774 | */ | ||
| 775 | /* printk("%s: disabled DSC seek overlap\n", drive->name);*/ | ||
| 776 | drive->dsc_overlap = 0; | 785 | drive->dsc_overlap = 0; |
| 777 | } | ||
| 778 | } | 786 | } |
| 779 | return ide_stopped; | 787 | return ide_stopped; |
| 780 | } | 788 | } |
| @@ -800,32 +808,34 @@ static ide_startstop_t cdrom_start_seek(ide_drive_t *drive, unsigned int block) | |||
| 800 | 808 | ||
| 801 | info->dma = 0; | 809 | info->dma = 0; |
| 802 | info->start_seek = jiffies; | 810 | info->start_seek = jiffies; |
| 803 | return cdrom_start_packet_command(drive, 0, cdrom_start_seek_continuation); | 811 | return cdrom_start_packet_command(drive, 0, |
| 812 | cdrom_start_seek_continuation); | ||
| 804 | } | 813 | } |
| 805 | 814 | ||
| 806 | /* | 815 | /* |
| 807 | * Fix up a possibly partially-processed request so that we can | 816 | * Fix up a possibly partially-processed request so that we can start it over |
| 808 | * start it over entirely, or even put it back on the request queue. | 817 | * entirely, or even put it back on the request queue. |
| 809 | */ | 818 | */ |
| 810 | static void restore_request(struct request *rq) | 819 | static void restore_request(struct request *rq) |
| 811 | { | 820 | { |
| 812 | if (rq->buffer != bio_data(rq->bio)) { | 821 | if (rq->buffer != bio_data(rq->bio)) { |
| 813 | sector_t n = (rq->buffer - (char *) bio_data(rq->bio)) / SECTOR_SIZE; | 822 | sector_t n = |
| 823 | (rq->buffer - (char *)bio_data(rq->bio)) / SECTOR_SIZE; | ||
| 814 | 824 | ||
| 815 | rq->buffer = bio_data(rq->bio); | 825 | rq->buffer = bio_data(rq->bio); |
| 816 | rq->nr_sectors += n; | 826 | rq->nr_sectors += n; |
| 817 | rq->sector -= n; | 827 | rq->sector -= n; |
| 818 | } | 828 | } |
| 819 | rq->hard_cur_sectors = rq->current_nr_sectors = bio_cur_sectors(rq->bio); | 829 | rq->current_nr_sectors = bio_cur_sectors(rq->bio); |
| 830 | rq->hard_cur_sectors = rq->current_nr_sectors; | ||
| 820 | rq->hard_nr_sectors = rq->nr_sectors; | 831 | rq->hard_nr_sectors = rq->nr_sectors; |
| 821 | rq->hard_sector = rq->sector; | 832 | rq->hard_sector = rq->sector; |
| 822 | rq->q->prep_rq_fn(rq->q, rq); | 833 | rq->q->prep_rq_fn(rq->q, rq); |
| 823 | } | 834 | } |
| 824 | 835 | ||
| 825 | /**************************************************************************** | 836 | /* |
| 826 | * Execute all other packet commands. | 837 | * All other packet commands. |
| 827 | */ | 838 | */ |
| 828 | |||
| 829 | static void ide_cd_request_sense_fixup(struct request *rq) | 839 | static void ide_cd_request_sense_fixup(struct request *rq) |
| 830 | { | 840 | { |
| 831 | /* | 841 | /* |
| @@ -849,7 +859,7 @@ int ide_cd_queue_pc(ide_drive_t *drive, struct request *rq) | |||
| 849 | if (rq->sense == NULL) | 859 | if (rq->sense == NULL) |
| 850 | rq->sense = &sense; | 860 | rq->sense = &sense; |
| 851 | 861 | ||
| 852 | /* Start of retry loop. */ | 862 | /* start of retry loop */ |
| 853 | do { | 863 | do { |
| 854 | int error; | 864 | int error; |
| 855 | unsigned long time = jiffies; | 865 | unsigned long time = jiffies; |
| @@ -858,41 +868,45 @@ int ide_cd_queue_pc(ide_drive_t *drive, struct request *rq) | |||
| 858 | error = ide_do_drive_cmd(drive, rq, ide_wait); | 868 | error = ide_do_drive_cmd(drive, rq, ide_wait); |
| 859 | time = jiffies - time; | 869 | time = jiffies - time; |
| 860 | 870 | ||
| 861 | /* FIXME: we should probably abort/retry or something | 871 | /* |
| 862 | * in case of failure */ | 872 | * FIXME: we should probably abort/retry or something in case of |
| 873 | * failure. | ||
| 874 | */ | ||
| 863 | if (rq->cmd_flags & REQ_FAILED) { | 875 | if (rq->cmd_flags & REQ_FAILED) { |
| 864 | /* The request failed. Retry if it was due to a unit | 876 | /* |
| 865 | attention status | 877 | * The request failed. Retry if it was due to a unit |
| 866 | (usually means media was changed). */ | 878 | * attention status (usually means media was changed). |
| 879 | */ | ||
| 867 | struct request_sense *reqbuf = rq->sense; | 880 | struct request_sense *reqbuf = rq->sense; |
| 868 | 881 | ||
| 869 | if (reqbuf->sense_key == UNIT_ATTENTION) | 882 | if (reqbuf->sense_key == UNIT_ATTENTION) |
| 870 | cdrom_saw_media_change(drive); | 883 | cdrom_saw_media_change(drive); |
| 871 | else if (reqbuf->sense_key == NOT_READY && | 884 | else if (reqbuf->sense_key == NOT_READY && |
| 872 | reqbuf->asc == 4 && reqbuf->ascq != 4) { | 885 | reqbuf->asc == 4 && reqbuf->ascq != 4) { |
| 873 | /* The drive is in the process of loading | 886 | /* |
| 874 | a disk. Retry, but wait a little to give | 887 | * The drive is in the process of loading |
| 875 | the drive time to complete the load. */ | 888 | * a disk. Retry, but wait a little to give |
| 889 | * the drive time to complete the load. | ||
| 890 | */ | ||
| 876 | ssleep(2); | 891 | ssleep(2); |
| 877 | } else { | 892 | } else { |
| 878 | /* Otherwise, don't retry. */ | 893 | /* otherwise, don't retry */ |
| 879 | retries = 0; | 894 | retries = 0; |
| 880 | } | 895 | } |
| 881 | --retries; | 896 | --retries; |
| 882 | } | 897 | } |
| 883 | 898 | ||
| 884 | /* End of retry loop. */ | 899 | /* end of retry loop */ |
| 885 | } while ((rq->cmd_flags & REQ_FAILED) && retries >= 0); | 900 | } while ((rq->cmd_flags & REQ_FAILED) && retries >= 0); |
| 886 | 901 | ||
| 887 | /* Return an error if the command failed. */ | 902 | /* return an error if the command failed */ |
| 888 | return (rq->cmd_flags & REQ_FAILED) ? -EIO : 0; | 903 | return (rq->cmd_flags & REQ_FAILED) ? -EIO : 0; |
| 889 | } | 904 | } |
| 890 | 905 | ||
| 891 | /* | 906 | /* |
| 892 | * Called from blk_end_request_callback() after the data of the request | 907 | * Called from blk_end_request_callback() after the data of the request is |
| 893 | * is completed and before the request is completed. | 908 | * completed and before the request itself is completed. By returning value '1', |
| 894 | * By returning value '1', blk_end_request_callback() returns immediately | 909 | * blk_end_request_callback() returns immediately without completing it. |
| 895 | * without completing the request. | ||
| 896 | */ | 910 | */ |
| 897 | static int cdrom_newpc_intr_dummy_cb(struct request *rq) | 911 | static int cdrom_newpc_intr_dummy_cb(struct request *rq) |
| 898 | { | 912 | { |
| @@ -911,11 +925,11 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive) | |||
| 911 | unsigned int timeout; | 925 | unsigned int timeout; |
| 912 | u8 lowcyl, highcyl; | 926 | u8 lowcyl, highcyl; |
| 913 | 927 | ||
| 914 | /* Check for errors. */ | 928 | /* check for errors */ |
| 915 | dma = info->dma; | 929 | dma = info->dma; |
| 916 | if (dma) { | 930 | if (dma) { |
| 917 | info->dma = 0; | 931 | info->dma = 0; |
| 918 | dma_error = HWIF(drive)->ide_dma_end(drive); | 932 | dma_error = hwif->dma_ops->dma_end(drive); |
| 919 | if (dma_error) { | 933 | if (dma_error) { |
| 920 | printk(KERN_ERR "%s: DMA %s error\n", drive->name, | 934 | printk(KERN_ERR "%s: DMA %s error\n", drive->name, |
| 921 | write ? "write" : "read"); | 935 | write ? "write" : "read"); |
| @@ -926,9 +940,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive) | |||
| 926 | if (cdrom_decode_status(drive, 0, &stat)) | 940 | if (cdrom_decode_status(drive, 0, &stat)) |
| 927 | return ide_stopped; | 941 | return ide_stopped; |
| 928 | 942 | ||
| 929 | /* | 943 | /* using dma, transfer is complete now */ |
| 930 | * using dma, transfer is complete now | ||
| 931 | */ | ||
| 932 | if (dma) { | 944 | if (dma) { |
| 933 | if (dma_error) | 945 | if (dma_error) |
| 934 | return ide_error(drive, "dma error", stat); | 946 | return ide_error(drive, "dma error", stat); |
| @@ -939,9 +951,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive) | |||
| 939 | goto end_request; | 951 | goto end_request; |
| 940 | } | 952 | } |
| 941 | 953 | ||
| 942 | /* | 954 | /* ok we fall to pio :/ */ |
| 943 | * ok we fall to pio :/ | ||
| 944 | */ | ||
| 945 | ireason = hwif->INB(hwif->io_ports[IDE_IREASON_OFFSET]) & 0x3; | 955 | ireason = hwif->INB(hwif->io_ports[IDE_IREASON_OFFSET]) & 0x3; |
| 946 | lowcyl = hwif->INB(hwif->io_ports[IDE_BCOUNTL_OFFSET]); | 956 | lowcyl = hwif->INB(hwif->io_ports[IDE_BCOUNTL_OFFSET]); |
| 947 | highcyl = hwif->INB(hwif->io_ports[IDE_BCOUNTH_OFFSET]); | 957 | highcyl = hwif->INB(hwif->io_ports[IDE_BCOUNTH_OFFSET]); |
| @@ -952,9 +962,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive) | |||
| 952 | if (thislen > len) | 962 | if (thislen > len) |
| 953 | thislen = len; | 963 | thislen = len; |
| 954 | 964 | ||
| 955 | /* | 965 | /* If DRQ is clear, the command has completed. */ |
| 956 | * If DRQ is clear, the command has completed. | ||
| 957 | */ | ||
| 958 | if ((stat & DRQ_STAT) == 0) { | 966 | if ((stat & DRQ_STAT) == 0) { |
| 959 | if (blk_fs_request(rq)) { | 967 | if (blk_fs_request(rq)) { |
| 960 | /* | 968 | /* |
| @@ -975,15 +983,13 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive) | |||
| 975 | return ide_stopped; | 983 | return ide_stopped; |
| 976 | } else if (!blk_pc_request(rq)) { | 984 | } else if (!blk_pc_request(rq)) { |
| 977 | ide_cd_request_sense_fixup(rq); | 985 | ide_cd_request_sense_fixup(rq); |
| 978 | /* Complain if we still have data left to transfer. */ | 986 | /* complain if we still have data left to transfer */ |
| 979 | uptodate = rq->data_len ? 0 : 1; | 987 | uptodate = rq->data_len ? 0 : 1; |
| 980 | } | 988 | } |
| 981 | goto end_request; | 989 | goto end_request; |
| 982 | } | 990 | } |
| 983 | 991 | ||
| 984 | /* | 992 | /* check which way to transfer data */ |
| 985 | * check which way to transfer data | ||
| 986 | */ | ||
| 987 | if (ide_cd_check_ireason(drive, rq, len, ireason, write)) | 993 | if (ide_cd_check_ireason(drive, rq, len, ireason, write)) |
| 988 | return ide_stopped; | 994 | return ide_stopped; |
| 989 | 995 | ||
| @@ -1019,16 +1025,12 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive) | |||
| 1019 | xferfunc = HWIF(drive)->atapi_input_bytes; | 1025 | xferfunc = HWIF(drive)->atapi_input_bytes; |
| 1020 | } | 1026 | } |
| 1021 | 1027 | ||
| 1022 | /* | 1028 | /* transfer data */ |
| 1023 | * transfer data | ||
| 1024 | */ | ||
| 1025 | while (thislen > 0) { | 1029 | while (thislen > 0) { |
| 1026 | u8 *ptr = blk_fs_request(rq) ? NULL : rq->data; | 1030 | u8 *ptr = blk_fs_request(rq) ? NULL : rq->data; |
| 1027 | int blen = rq->data_len; | 1031 | int blen = rq->data_len; |
| 1028 | 1032 | ||
| 1029 | /* | 1033 | /* bio backed? */ |
| 1030 | * bio backed? | ||
| 1031 | */ | ||
| 1032 | if (rq->bio) { | 1034 | if (rq->bio) { |
| 1033 | if (blk_fs_request(rq)) { | 1035 | if (blk_fs_request(rq)) { |
| 1034 | ptr = rq->buffer; | 1036 | ptr = rq->buffer; |
| @@ -1043,7 +1045,8 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive) | |||
| 1043 | if (blk_fs_request(rq) && !write) | 1045 | if (blk_fs_request(rq) && !write) |
| 1044 | /* | 1046 | /* |
| 1045 | * If the buffers are full, pipe the rest into | 1047 | * If the buffers are full, pipe the rest into |
| 1046 | * oblivion. */ | 1048 | * oblivion. |
| 1049 | */ | ||
| 1047 | ide_cd_drain_data(drive, thislen >> 9); | 1050 | ide_cd_drain_data(drive, thislen >> 9); |
| 1048 | else { | 1051 | else { |
| 1049 | printk(KERN_ERR "%s: confused, missing data\n", | 1052 | printk(KERN_ERR "%s: confused, missing data\n", |
| @@ -1090,9 +1093,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive) | |||
| 1090 | rq->sense_len += blen; | 1093 | rq->sense_len += blen; |
| 1091 | } | 1094 | } |
| 1092 | 1095 | ||
| 1093 | /* | 1096 | /* pad, if necessary */ |
| 1094 | * pad, if necessary | ||
| 1095 | */ | ||
| 1096 | if (!blk_fs_request(rq) && len > 0) | 1097 | if (!blk_fs_request(rq) && len > 0) |
| 1097 | ide_cd_pad_transfer(drive, xferfunc, len); | 1098 | ide_cd_pad_transfer(drive, xferfunc, len); |
| 1098 | 1099 | ||
| @@ -1136,9 +1137,7 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq) | |||
| 1136 | queue_hardsect_size(drive->queue) >> SECTOR_BITS; | 1137 | queue_hardsect_size(drive->queue) >> SECTOR_BITS; |
| 1137 | 1138 | ||
| 1138 | if (write) { | 1139 | if (write) { |
| 1139 | /* | 1140 | /* disk has become write protected */ |
| 1140 | * disk has become write protected | ||
| 1141 | */ | ||
| 1142 | if (cd->disk->policy) { | 1141 | if (cd->disk->policy) { |
| 1143 | cdrom_end_request(drive, 0); | 1142 | cdrom_end_request(drive, 0); |
| 1144 | return ide_stopped; | 1143 | return ide_stopped; |
| @@ -1151,9 +1150,7 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq) | |||
| 1151 | restore_request(rq); | 1150 | restore_request(rq); |
| 1152 | } | 1151 | } |
| 1153 | 1152 | ||
| 1154 | /* | 1153 | /* use DMA, if possible / writes *must* be hardware frame aligned */ |
| 1155 | * use DMA, if possible / writes *must* be hardware frame aligned | ||
| 1156 | */ | ||
| 1157 | if ((rq->nr_sectors & (sectors_per_frame - 1)) || | 1154 | if ((rq->nr_sectors & (sectors_per_frame - 1)) || |
| 1158 | (rq->sector & (sectors_per_frame - 1))) { | 1155 | (rq->sector & (sectors_per_frame - 1))) { |
| 1159 | if (write) { | 1156 | if (write) { |
| @@ -1167,7 +1164,7 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq) | |||
| 1167 | if (write) | 1164 | if (write) |
| 1168 | cd->devinfo.media_written = 1; | 1165 | cd->devinfo.media_written = 1; |
| 1169 | 1166 | ||
| 1170 | /* Start sending the read/write request to the drive. */ | 1167 | /* start sending the read/write request to the drive */ |
| 1171 | return cdrom_start_packet_command(drive, 32768, cdrom_start_rw_cont); | 1168 | return cdrom_start_packet_command(drive, 32768, cdrom_start_rw_cont); |
| 1172 | } | 1169 | } |
| 1173 | 1170 | ||
| @@ -1192,12 +1189,11 @@ static ide_startstop_t cdrom_do_block_pc(ide_drive_t *drive, struct request *rq) | |||
| 1192 | 1189 | ||
| 1193 | info->dma = 0; | 1190 | info->dma = 0; |
| 1194 | 1191 | ||
| 1195 | /* | 1192 | /* sg request */ |
| 1196 | * sg request | ||
| 1197 | */ | ||
| 1198 | if (rq->bio) { | 1193 | if (rq->bio) { |
| 1199 | int mask = drive->queue->dma_alignment; | 1194 | int mask = drive->queue->dma_alignment; |
| 1200 | unsigned long addr = (unsigned long) page_address(bio_page(rq->bio)); | 1195 | unsigned long addr = |
| 1196 | (unsigned long)page_address(bio_page(rq->bio)); | ||
| 1201 | 1197 | ||
| 1202 | info->dma = drive->using_dma; | 1198 | info->dma = drive->using_dma; |
| 1203 | 1199 | ||
| @@ -1211,15 +1207,16 @@ static ide_startstop_t cdrom_do_block_pc(ide_drive_t *drive, struct request *rq) | |||
| 1211 | info->dma = 0; | 1207 | info->dma = 0; |
| 1212 | } | 1208 | } |
| 1213 | 1209 | ||
| 1214 | /* Start sending the command to the drive. */ | 1210 | /* start sending the command to the drive */ |
| 1215 | return cdrom_start_packet_command(drive, rq->data_len, cdrom_do_newpc_cont); | 1211 | return cdrom_start_packet_command(drive, rq->data_len, |
| 1212 | cdrom_do_newpc_cont); | ||
| 1216 | } | 1213 | } |
| 1217 | 1214 | ||
| 1218 | /**************************************************************************** | 1215 | /* |
| 1219 | * cdrom driver request routine. | 1216 | * cdrom driver request routine. |
| 1220 | */ | 1217 | */ |
| 1221 | static ide_startstop_t | 1218 | static ide_startstop_t ide_do_rw_cdrom(ide_drive_t *drive, struct request *rq, |
| 1222 | ide_do_rw_cdrom(ide_drive_t *drive, struct request *rq, sector_t block) | 1219 | sector_t block) |
| 1223 | { | 1220 | { |
| 1224 | ide_startstop_t action; | 1221 | ide_startstop_t action; |
| 1225 | struct cdrom_info *info = drive->driver_data; | 1222 | struct cdrom_info *info = drive->driver_data; |
| @@ -1231,14 +1228,19 @@ ide_do_rw_cdrom(ide_drive_t *drive, struct request *rq, sector_t block) | |||
| 1231 | 1228 | ||
| 1232 | if ((stat & SEEK_STAT) != SEEK_STAT) { | 1229 | if ((stat & SEEK_STAT) != SEEK_STAT) { |
| 1233 | if (elapsed < IDECD_SEEK_TIMEOUT) { | 1230 | if (elapsed < IDECD_SEEK_TIMEOUT) { |
| 1234 | ide_stall_queue(drive, IDECD_SEEK_TIMER); | 1231 | ide_stall_queue(drive, |
| 1232 | IDECD_SEEK_TIMER); | ||
| 1235 | return ide_stopped; | 1233 | return ide_stopped; |
| 1236 | } | 1234 | } |
| 1237 | printk(KERN_ERR "%s: DSC timeout\n", drive->name); | 1235 | printk(KERN_ERR "%s: DSC timeout\n", |
| 1236 | drive->name); | ||
| 1238 | } | 1237 | } |
| 1239 | info->cd_flags &= ~IDE_CD_FLAG_SEEKING; | 1238 | info->cd_flags &= ~IDE_CD_FLAG_SEEKING; |
| 1240 | } | 1239 | } |
| 1241 | if ((rq_data_dir(rq) == READ) && IDE_LARGE_SEEK(info->last_block, block, IDECD_SEEK_THRESHOLD) && drive->dsc_overlap) | 1240 | if (rq_data_dir(rq) == READ && |
| 1241 | IDE_LARGE_SEEK(info->last_block, block, | ||
| 1242 | IDECD_SEEK_THRESHOLD) && | ||
| 1243 | drive->dsc_overlap) | ||
| 1242 | action = cdrom_start_seek(drive, block); | 1244 | action = cdrom_start_seek(drive, block); |
| 1243 | else | 1245 | else |
| 1244 | action = cdrom_start_rw(drive, rq); | 1246 | action = cdrom_start_rw(drive, rq); |
| @@ -1248,9 +1250,7 @@ ide_do_rw_cdrom(ide_drive_t *drive, struct request *rq, sector_t block) | |||
| 1248 | rq->cmd_type == REQ_TYPE_ATA_PC) { | 1250 | rq->cmd_type == REQ_TYPE_ATA_PC) { |
| 1249 | return cdrom_do_block_pc(drive, rq); | 1251 | return cdrom_do_block_pc(drive, rq); |
| 1250 | } else if (blk_special_request(rq)) { | 1252 | } else if (blk_special_request(rq)) { |
| 1251 | /* | 1253 | /* right now this can only be a reset... */ |
| 1252 | * right now this can only be a reset... | ||
| 1253 | */ | ||
| 1254 | cdrom_end_request(drive, 1); | 1254 | cdrom_end_request(drive, 1); |
| 1255 | return ide_stopped; | 1255 | return ide_stopped; |
| 1256 | } | 1256 | } |
| @@ -1262,18 +1262,16 @@ ide_do_rw_cdrom(ide_drive_t *drive, struct request *rq, sector_t block) | |||
| 1262 | 1262 | ||
| 1263 | 1263 | ||
| 1264 | 1264 | ||
| 1265 | /**************************************************************************** | 1265 | /* |
| 1266 | * Ioctl handling. | 1266 | * Ioctl handling. |
| 1267 | * | 1267 | * |
| 1268 | * Routines which queue packet commands take as a final argument a pointer | 1268 | * Routines which queue packet commands take as a final argument a pointer to a |
| 1269 | * to a request_sense struct. If execution of the command results | 1269 | * request_sense struct. If execution of the command results in an error with a |
| 1270 | * in an error with a CHECK CONDITION status, this structure will be filled | 1270 | * CHECK CONDITION status, this structure will be filled with the results of the |
| 1271 | * with the results of the subsequent request sense command. The pointer | 1271 | * subsequent request sense command. The pointer can also be NULL, in which case |
| 1272 | * can also be NULL, in which case no sense information is returned. | 1272 | * no sense information is returned. |
| 1273 | */ | 1273 | */ |
| 1274 | 1274 | static void msf_from_bcd(struct atapi_msf *msf) | |
| 1275 | static | ||
| 1276 | void msf_from_bcd(struct atapi_msf *msf) | ||
| 1277 | { | 1275 | { |
| 1278 | msf->minute = BCD2BIN(msf->minute); | 1276 | msf->minute = BCD2BIN(msf->minute); |
| 1279 | msf->second = BCD2BIN(msf->second); | 1277 | msf->second = BCD2BIN(msf->second); |
| @@ -1293,8 +1291,8 @@ int cdrom_check_status(ide_drive_t *drive, struct request_sense *sense) | |||
| 1293 | req.cmd_flags |= REQ_QUIET; | 1291 | req.cmd_flags |= REQ_QUIET; |
| 1294 | 1292 | ||
| 1295 | /* | 1293 | /* |
| 1296 | * Sanyo 3 CD changer uses byte 7 of TEST_UNIT_READY to | 1294 | * Sanyo 3 CD changer uses byte 7 of TEST_UNIT_READY to switch CDs |
| 1297 | * switch CDs instead of supporting the LOAD_UNLOAD opcode. | 1295 | * instead of supporting the LOAD_UNLOAD opcode. |
| 1298 | */ | 1296 | */ |
| 1299 | req.cmd[7] = cdi->sanyo_slot % 3; | 1297 | req.cmd[7] = cdi->sanyo_slot % 3; |
| 1300 | 1298 | ||
| @@ -1370,36 +1368,39 @@ int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense) | |||
| 1370 | unsigned long sectors_per_frame = SECTORS_PER_FRAME; | 1368 | unsigned long sectors_per_frame = SECTORS_PER_FRAME; |
| 1371 | 1369 | ||
| 1372 | if (toc == NULL) { | 1370 | if (toc == NULL) { |
| 1373 | /* Try to allocate space. */ | 1371 | /* try to allocate space */ |
| 1374 | toc = kmalloc(sizeof(struct atapi_toc), GFP_KERNEL); | 1372 | toc = kmalloc(sizeof(struct atapi_toc), GFP_KERNEL); |
| 1375 | if (toc == NULL) { | 1373 | if (toc == NULL) { |
| 1376 | printk(KERN_ERR "%s: No cdrom TOC buffer!\n", drive->name); | 1374 | printk(KERN_ERR "%s: No cdrom TOC buffer!\n", |
| 1375 | drive->name); | ||
| 1377 | return -ENOMEM; | 1376 | return -ENOMEM; |
| 1378 | } | 1377 | } |
| 1379 | info->toc = toc; | 1378 | info->toc = toc; |
| 1380 | } | 1379 | } |
| 1381 | 1380 | ||
| 1382 | /* Check to see if the existing data is still valid. | 1381 | /* |
| 1383 | If it is, just return. */ | 1382 | * Check to see if the existing data is still valid. If it is, |
| 1383 | * just return. | ||
| 1384 | */ | ||
| 1384 | (void) cdrom_check_status(drive, sense); | 1385 | (void) cdrom_check_status(drive, sense); |
| 1385 | 1386 | ||
| 1386 | if (info->cd_flags & IDE_CD_FLAG_TOC_VALID) | 1387 | if (info->cd_flags & IDE_CD_FLAG_TOC_VALID) |
| 1387 | return 0; | 1388 | return 0; |
| 1388 | 1389 | ||
| 1389 | /* Try to get the total cdrom capacity and sector size. */ | 1390 | /* try to get the total cdrom capacity and sector size */ |
| 1390 | stat = cdrom_read_capacity(drive, &toc->capacity, §ors_per_frame, | 1391 | stat = cdrom_read_capacity(drive, &toc->capacity, §ors_per_frame, |
| 1391 | sense); | 1392 | sense); |
| 1392 | if (stat) | 1393 | if (stat) |
| 1393 | toc->capacity = 0x1fffff; | 1394 | toc->capacity = 0x1fffff; |
| 1394 | 1395 | ||
| 1395 | set_capacity(info->disk, toc->capacity * sectors_per_frame); | 1396 | set_capacity(info->disk, toc->capacity * sectors_per_frame); |
| 1396 | /* Save a private copy of te TOC capacity for error handling */ | 1397 | /* save a private copy of the TOC capacity for error handling */ |
| 1397 | drive->probed_capacity = toc->capacity * sectors_per_frame; | 1398 | drive->probed_capacity = toc->capacity * sectors_per_frame; |
| 1398 | 1399 | ||
| 1399 | blk_queue_hardsect_size(drive->queue, | 1400 | blk_queue_hardsect_size(drive->queue, |
| 1400 | sectors_per_frame << SECTOR_BITS); | 1401 | sectors_per_frame << SECTOR_BITS); |
| 1401 | 1402 | ||
| 1402 | /* First read just the header, so we know how long the TOC is. */ | 1403 | /* first read just the header, so we know how long the TOC is */ |
| 1403 | stat = cdrom_read_tocentry(drive, 0, 1, 0, (char *) &toc->hdr, | 1404 | stat = cdrom_read_tocentry(drive, 0, 1, 0, (char *) &toc->hdr, |
| 1404 | sizeof(struct atapi_toc_header), sense); | 1405 | sizeof(struct atapi_toc_header), sense); |
| 1405 | if (stat) | 1406 | if (stat) |
| @@ -1416,7 +1417,7 @@ int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense) | |||
| 1416 | if (ntracks > MAX_TRACKS) | 1417 | if (ntracks > MAX_TRACKS) |
| 1417 | ntracks = MAX_TRACKS; | 1418 | ntracks = MAX_TRACKS; |
| 1418 | 1419 | ||
| 1419 | /* Now read the whole schmeer. */ | 1420 | /* now read the whole schmeer */ |
| 1420 | stat = cdrom_read_tocentry(drive, toc->hdr.first_track, 1, 0, | 1421 | stat = cdrom_read_tocentry(drive, toc->hdr.first_track, 1, 0, |
| 1421 | (char *)&toc->hdr, | 1422 | (char *)&toc->hdr, |
| 1422 | sizeof(struct atapi_toc_header) + | 1423 | sizeof(struct atapi_toc_header) + |
| @@ -1424,15 +1425,18 @@ int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense) | |||
| 1424 | sizeof(struct atapi_toc_entry), sense); | 1425 | sizeof(struct atapi_toc_entry), sense); |
| 1425 | 1426 | ||
| 1426 | if (stat && toc->hdr.first_track > 1) { | 1427 | if (stat && toc->hdr.first_track > 1) { |
| 1427 | /* Cds with CDI tracks only don't have any TOC entries, | 1428 | /* |
| 1428 | despite of this the returned values are | 1429 | * Cds with CDI tracks only don't have any TOC entries, despite |
| 1429 | first_track == last_track = number of CDI tracks + 1, | 1430 | * of this the returned values are |
| 1430 | so that this case is indistinguishable from the same | 1431 | * first_track == last_track = number of CDI tracks + 1, |
| 1431 | layout plus an additional audio track. | 1432 | * so that this case is indistinguishable from the same layout |
| 1432 | If we get an error for the regular case, we assume | 1433 | * plus an additional audio track. If we get an error for the |
| 1433 | a CDI without additional audio tracks. In this case | 1434 | * regular case, we assume a CDI without additional audio |
| 1434 | the readable TOC is empty (CDI tracks are not included) | 1435 | * tracks. In this case the readable TOC is empty (CDI tracks |
| 1435 | and only holds the Leadout entry. Heiko Eißfeldt */ | 1436 | * are not included) and only holds the Leadout entry. |
| 1437 | * | ||
| 1438 | * Heiko Eißfeldt. | ||
| 1439 | */ | ||
| 1436 | ntracks = 0; | 1440 | ntracks = 0; |
| 1437 | stat = cdrom_read_tocentry(drive, CDROM_LEADOUT, 1, 0, | 1441 | stat = cdrom_read_tocentry(drive, CDROM_LEADOUT, 1, 0, |
| 1438 | (char *)&toc->hdr, | 1442 | (char *)&toc->hdr, |
| @@ -1473,9 +1477,8 @@ int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense) | |||
| 1473 | toc->ent[i].addr.msf.frame); | 1477 | toc->ent[i].addr.msf.frame); |
| 1474 | } | 1478 | } |
| 1475 | 1479 | ||
| 1476 | /* Read the multisession information. */ | ||
| 1477 | if (toc->hdr.first_track != CDROM_LEADOUT) { | 1480 | if (toc->hdr.first_track != CDROM_LEADOUT) { |
| 1478 | /* Read the multisession information. */ | 1481 | /* read the multisession information */ |
| 1479 | stat = cdrom_read_tocentry(drive, 0, 0, 1, (char *)&ms_tmp, | 1482 | stat = cdrom_read_tocentry(drive, 0, 0, 1, (char *)&ms_tmp, |
| 1480 | sizeof(ms_tmp), sense); | 1483 | sizeof(ms_tmp), sense); |
| 1481 | if (stat) | 1484 | if (stat) |
| @@ -1483,12 +1486,13 @@ int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense) | |||
| 1483 | 1486 | ||
| 1484 | toc->last_session_lba = be32_to_cpu(ms_tmp.ent.addr.lba); | 1487 | toc->last_session_lba = be32_to_cpu(ms_tmp.ent.addr.lba); |
| 1485 | } else { | 1488 | } else { |
| 1486 | ms_tmp.hdr.first_track = ms_tmp.hdr.last_track = CDROM_LEADOUT; | 1489 | ms_tmp.hdr.last_track = CDROM_LEADOUT; |
| 1490 | ms_tmp.hdr.first_track = ms_tmp.hdr.last_track; | ||
| 1487 | toc->last_session_lba = msf_to_lba(0, 2, 0); /* 0m 2s 0f */ | 1491 | toc->last_session_lba = msf_to_lba(0, 2, 0); /* 0m 2s 0f */ |
| 1488 | } | 1492 | } |
| 1489 | 1493 | ||
| 1490 | if (info->cd_flags & IDE_CD_FLAG_TOCADDR_AS_BCD) { | 1494 | if (info->cd_flags & IDE_CD_FLAG_TOCADDR_AS_BCD) { |
| 1491 | /* Re-read multisession information using MSF format */ | 1495 | /* re-read multisession information using MSF format */ |
| 1492 | stat = cdrom_read_tocentry(drive, 0, 1, 1, (char *)&ms_tmp, | 1496 | stat = cdrom_read_tocentry(drive, 0, 1, 1, (char *)&ms_tmp, |
| 1493 | sizeof(ms_tmp), sense); | 1497 | sizeof(ms_tmp), sense); |
| 1494 | if (stat) | 1498 | if (stat) |
| @@ -1502,7 +1506,7 @@ int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense) | |||
| 1502 | 1506 | ||
| 1503 | toc->xa_flag = (ms_tmp.hdr.first_track != ms_tmp.hdr.last_track); | 1507 | toc->xa_flag = (ms_tmp.hdr.first_track != ms_tmp.hdr.last_track); |
| 1504 | 1508 | ||
| 1505 | /* Now try to get the total cdrom capacity. */ | 1509 | /* now try to get the total cdrom capacity */ |
| 1506 | stat = cdrom_get_last_written(cdi, &last_written); | 1510 | stat = cdrom_get_last_written(cdi, &last_written); |
| 1507 | if (!stat && (last_written > toc->capacity)) { | 1511 | if (!stat && (last_written > toc->capacity)) { |
| 1508 | toc->capacity = last_written; | 1512 | toc->capacity = last_written; |
| @@ -1527,7 +1531,8 @@ int ide_cdrom_get_capabilities(ide_drive_t *drive, u8 *buf) | |||
| 1527 | size -= ATAPI_CAPABILITIES_PAGE_PAD_SIZE; | 1531 | size -= ATAPI_CAPABILITIES_PAGE_PAD_SIZE; |
| 1528 | 1532 | ||
| 1529 | init_cdrom_command(&cgc, buf, size, CGC_DATA_UNKNOWN); | 1533 | init_cdrom_command(&cgc, buf, size, CGC_DATA_UNKNOWN); |
| 1530 | do { /* we seem to get stat=0x01,err=0x00 the first time (??) */ | 1534 | do { |
| 1535 | /* we seem to get stat=0x01,err=0x00 the first time (??) */ | ||
| 1531 | stat = cdrom_mode_sense(cdi, &cgc, GPMODE_CAPABILITIES_PAGE, 0); | 1536 | stat = cdrom_mode_sense(cdi, &cgc, GPMODE_CAPABILITIES_PAGE, 0); |
| 1532 | if (!stat) | 1537 | if (!stat) |
| 1533 | break; | 1538 | break; |
| @@ -1596,8 +1601,7 @@ static int ide_cdrom_register(ide_drive_t *drive, int nslots) | |||
| 1596 | return register_cdrom(devinfo); | 1601 | return register_cdrom(devinfo); |
| 1597 | } | 1602 | } |
| 1598 | 1603 | ||
| 1599 | static | 1604 | static int ide_cdrom_probe_capabilities(ide_drive_t *drive) |
| 1600 | int ide_cdrom_probe_capabilities(ide_drive_t *drive) | ||
| 1601 | { | 1605 | { |
| 1602 | struct cdrom_info *cd = drive->driver_data; | 1606 | struct cdrom_info *cd = drive->driver_data; |
| 1603 | struct cdrom_device_info *cdi = &cd->devinfo; | 1607 | struct cdrom_device_info *cdi = &cd->devinfo; |
| @@ -1611,7 +1615,8 @@ int ide_cdrom_probe_capabilities(ide_drive_t *drive) | |||
| 1611 | 1615 | ||
| 1612 | if (drive->media == ide_optical) { | 1616 | if (drive->media == ide_optical) { |
| 1613 | cdi->mask &= ~(CDC_MO_DRIVE | CDC_RAM); | 1617 | cdi->mask &= ~(CDC_MO_DRIVE | CDC_RAM); |
| 1614 | printk(KERN_ERR "%s: ATAPI magneto-optical drive\n", drive->name); | 1618 | printk(KERN_ERR "%s: ATAPI magneto-optical drive\n", |
| 1619 | drive->name); | ||
| 1615 | return nslots; | 1620 | return nslots; |
| 1616 | } | 1621 | } |
| 1617 | 1622 | ||
| @@ -1622,11 +1627,10 @@ int ide_cdrom_probe_capabilities(ide_drive_t *drive) | |||
| 1622 | } | 1627 | } |
| 1623 | 1628 | ||
| 1624 | /* | 1629 | /* |
| 1625 | * we have to cheat a little here. the packet will eventually | 1630 | * We have to cheat a little here. the packet will eventually be queued |
| 1626 | * be queued with ide_cdrom_packet(), which extracts the | 1631 | * with ide_cdrom_packet(), which extracts the drive from cdi->handle. |
| 1627 | * drive from cdi->handle. Since this device hasn't been | 1632 | * Since this device hasn't been registered with the Uniform layer yet, |
| 1628 | * registered with the Uniform layer yet, it can't do this. | 1633 | * it can't do this. Same goes for cdi->ops. |
| 1629 | * Same goes for cdi->ops. | ||
| 1630 | */ | 1634 | */ |
| 1631 | cdi->handle = drive; | 1635 | cdi->handle = drive; |
| 1632 | cdi->ops = &ide_cdrom_dops; | 1636 | cdi->ops = &ide_cdrom_dops; |
| @@ -1695,18 +1699,7 @@ int ide_cdrom_probe_capabilities(ide_drive_t *drive) | |||
| 1695 | return nslots; | 1699 | return nslots; |
| 1696 | } | 1700 | } |
| 1697 | 1701 | ||
| 1698 | #ifdef CONFIG_IDE_PROC_FS | 1702 | /* standard prep_rq_fn that builds 10 byte cmds */ |
| 1699 | static void ide_cdrom_add_settings(ide_drive_t *drive) | ||
| 1700 | { | ||
| 1701 | ide_add_setting(drive, "dsc_overlap", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1, &drive->dsc_overlap, NULL); | ||
| 1702 | } | ||
| 1703 | #else | ||
| 1704 | static inline void ide_cdrom_add_settings(ide_drive_t *drive) { ; } | ||
| 1705 | #endif | ||
| 1706 | |||
| 1707 | /* | ||
| 1708 | * standard prep_rq_fn that builds 10 byte cmds | ||
| 1709 | */ | ||
| 1710 | static int ide_cdrom_prep_fs(struct request_queue *q, struct request *rq) | 1703 | static int ide_cdrom_prep_fs(struct request_queue *q, struct request *rq) |
| 1711 | { | 1704 | { |
| 1712 | int hard_sect = queue_hardsect_size(q); | 1705 | int hard_sect = queue_hardsect_size(q); |
| @@ -1745,9 +1738,7 @@ static int ide_cdrom_prep_pc(struct request *rq) | |||
| 1745 | { | 1738 | { |
| 1746 | u8 *c = rq->cmd; | 1739 | u8 *c = rq->cmd; |
| 1747 | 1740 | ||
| 1748 | /* | 1741 | /* transform 6-byte read/write commands to the 10-byte version */ |
| 1749 | * Transform 6-byte read/write commands to the 10-byte version | ||
| 1750 | */ | ||
| 1751 | if (c[0] == READ_6 || c[0] == WRITE_6) { | 1742 | if (c[0] == READ_6 || c[0] == WRITE_6) { |
| 1752 | c[8] = c[4]; | 1743 | c[8] = c[4]; |
| 1753 | c[5] = c[3]; | 1744 | c[5] = c[3]; |
| @@ -1789,6 +1780,41 @@ struct cd_list_entry { | |||
| 1789 | unsigned int cd_flags; | 1780 | unsigned int cd_flags; |
| 1790 | }; | 1781 | }; |
| 1791 | 1782 | ||
| 1783 | #ifdef CONFIG_IDE_PROC_FS | ||
| 1784 | static sector_t ide_cdrom_capacity(ide_drive_t *drive) | ||
| 1785 | { | ||
| 1786 | unsigned long capacity, sectors_per_frame; | ||
| 1787 | |||
| 1788 | if (cdrom_read_capacity(drive, &capacity, §ors_per_frame, NULL)) | ||
| 1789 | return 0; | ||
| 1790 | |||
| 1791 | return capacity * sectors_per_frame; | ||
| 1792 | } | ||
| 1793 | |||
| 1794 | static int proc_idecd_read_capacity(char *page, char **start, off_t off, | ||
| 1795 | int count, int *eof, void *data) | ||
| 1796 | { | ||
| 1797 | ide_drive_t *drive = data; | ||
| 1798 | int len; | ||
| 1799 | |||
| 1800 | len = sprintf(page, "%llu\n", (long long)ide_cdrom_capacity(drive)); | ||
| 1801 | PROC_IDE_READ_RETURN(page, start, off, count, eof, len); | ||
| 1802 | } | ||
| 1803 | |||
| 1804 | static ide_proc_entry_t idecd_proc[] = { | ||
| 1805 | { "capacity", S_IFREG|S_IRUGO, proc_idecd_read_capacity, NULL }, | ||
| 1806 | { NULL, 0, NULL, NULL } | ||
| 1807 | }; | ||
| 1808 | |||
| 1809 | static void ide_cdrom_add_settings(ide_drive_t *drive) | ||
| 1810 | { | ||
| 1811 | ide_add_setting(drive, "dsc_overlap", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1, | ||
| 1812 | &drive->dsc_overlap, NULL); | ||
| 1813 | } | ||
| 1814 | #else | ||
| 1815 | static inline void ide_cdrom_add_settings(ide_drive_t *drive) { ; } | ||
| 1816 | #endif | ||
| 1817 | |||
| 1792 | static const struct cd_list_entry ide_cd_quirks_list[] = { | 1818 | static const struct cd_list_entry ide_cd_quirks_list[] = { |
| 1793 | /* Limit transfer size per interrupt. */ | 1819 | /* Limit transfer size per interrupt. */ |
| 1794 | { "SAMSUNG CD-ROM SCR-2430", NULL, IDE_CD_FLAG_LIMIT_NFRAMES }, | 1820 | { "SAMSUNG CD-ROM SCR-2430", NULL, IDE_CD_FLAG_LIMIT_NFRAMES }, |
| @@ -1846,8 +1872,7 @@ static unsigned int ide_cd_flags(struct hd_driveid *id) | |||
| 1846 | return 0; | 1872 | return 0; |
| 1847 | } | 1873 | } |
| 1848 | 1874 | ||
| 1849 | static | 1875 | static int ide_cdrom_setup(ide_drive_t *drive) |
| 1850 | int ide_cdrom_setup(ide_drive_t *drive) | ||
| 1851 | { | 1876 | { |
| 1852 | struct cdrom_info *cd = drive->driver_data; | 1877 | struct cdrom_info *cd = drive->driver_data; |
| 1853 | struct cdrom_device_info *cdi = &cd->devinfo; | 1878 | struct cdrom_device_info *cdi = &cd->devinfo; |
| @@ -1876,13 +1901,12 @@ int ide_cdrom_setup(ide_drive_t *drive) | |||
| 1876 | id->fw_rev[4] == '1' && id->fw_rev[6] <= '2') | 1901 | id->fw_rev[4] == '1' && id->fw_rev[6] <= '2') |
| 1877 | cd->cd_flags |= IDE_CD_FLAG_TOCTRACKS_AS_BCD; | 1902 | cd->cd_flags |= IDE_CD_FLAG_TOCTRACKS_AS_BCD; |
| 1878 | else if (cd->cd_flags & IDE_CD_FLAG_SANYO_3CD) | 1903 | else if (cd->cd_flags & IDE_CD_FLAG_SANYO_3CD) |
| 1879 | cdi->sanyo_slot = 3; /* 3 => use CD in slot 0 */ | 1904 | /* 3 => use CD in slot 0 */ |
| 1905 | cdi->sanyo_slot = 3; | ||
| 1880 | 1906 | ||
| 1881 | nslots = ide_cdrom_probe_capabilities(drive); | 1907 | nslots = ide_cdrom_probe_capabilities(drive); |
| 1882 | 1908 | ||
| 1883 | /* | 1909 | /* set correct block size */ |
| 1884 | * set correct block size | ||
| 1885 | */ | ||
| 1886 | blk_queue_hardsect_size(drive->queue, CD_FRAMESIZE); | 1910 | blk_queue_hardsect_size(drive->queue, CD_FRAMESIZE); |
| 1887 | 1911 | ||
| 1888 | if (drive->autotune == IDE_TUNE_DEFAULT || | 1912 | if (drive->autotune == IDE_TUNE_DEFAULT || |
| @@ -1890,7 +1914,8 @@ int ide_cdrom_setup(ide_drive_t *drive) | |||
| 1890 | drive->dsc_overlap = (drive->next != drive); | 1914 | drive->dsc_overlap = (drive->next != drive); |
| 1891 | 1915 | ||
| 1892 | if (ide_cdrom_register(drive, nslots)) { | 1916 | if (ide_cdrom_register(drive, nslots)) { |
| 1893 | printk(KERN_ERR "%s: ide_cdrom_setup failed to register device with the cdrom driver.\n", drive->name); | 1917 | printk(KERN_ERR "%s: %s failed to register device with the" |
| 1918 | " cdrom driver.\n", drive->name, __func__); | ||
| 1894 | cd->devinfo.handle = NULL; | 1919 | cd->devinfo.handle = NULL; |
| 1895 | return 1; | 1920 | return 1; |
| 1896 | } | 1921 | } |
| @@ -1929,33 +1954,6 @@ static void ide_cd_release(struct kref *kref) | |||
| 1929 | 1954 | ||
| 1930 | static int ide_cd_probe(ide_drive_t *); | 1955 | static int ide_cd_probe(ide_drive_t *); |
| 1931 | 1956 | ||
| 1932 | #ifdef CONFIG_IDE_PROC_FS | ||
| 1933 | static sector_t ide_cdrom_capacity(ide_drive_t *drive) | ||
| 1934 | { | ||
| 1935 | unsigned long capacity, sectors_per_frame; | ||
| 1936 | |||
| 1937 | if (cdrom_read_capacity(drive, &capacity, §ors_per_frame, NULL)) | ||
| 1938 | return 0; | ||
| 1939 | |||
| 1940 | return capacity * sectors_per_frame; | ||
| 1941 | } | ||
| 1942 | |||
| 1943 | static int proc_idecd_read_capacity | ||
| 1944 | (char *page, char **start, off_t off, int count, int *eof, void *data) | ||
| 1945 | { | ||
| 1946 | ide_drive_t *drive = data; | ||
| 1947 | int len; | ||
| 1948 | |||
| 1949 | len = sprintf(page, "%llu\n", (long long)ide_cdrom_capacity(drive)); | ||
| 1950 | PROC_IDE_READ_RETURN(page, start, off, count, eof, len); | ||
| 1951 | } | ||
| 1952 | |||
| 1953 | static ide_proc_entry_t idecd_proc[] = { | ||
| 1954 | { "capacity", S_IFREG|S_IRUGO, proc_idecd_read_capacity, NULL }, | ||
| 1955 | { NULL, 0, NULL, NULL } | ||
| 1956 | }; | ||
| 1957 | #endif | ||
| 1958 | |||
| 1959 | static ide_driver_t ide_cdrom_driver = { | 1957 | static ide_driver_t ide_cdrom_driver = { |
| 1960 | .gen_driver = { | 1958 | .gen_driver = { |
| 1961 | .owner = THIS_MODULE, | 1959 | .owner = THIS_MODULE, |
| @@ -2093,7 +2091,7 @@ static struct block_device_operations idecd_ops = { | |||
| 2093 | .revalidate_disk = idecd_revalidate_disk | 2091 | .revalidate_disk = idecd_revalidate_disk |
| 2094 | }; | 2092 | }; |
| 2095 | 2093 | ||
| 2096 | /* options */ | 2094 | /* module options */ |
| 2097 | static char *ignore; | 2095 | static char *ignore; |
| 2098 | 2096 | ||
| 2099 | module_param(ignore, charp, 0400); | 2097 | module_param(ignore, charp, 0400); |
| @@ -2114,17 +2112,20 @@ static int ide_cd_probe(ide_drive_t *drive) | |||
| 2114 | /* skip drives that we were told to ignore */ | 2112 | /* skip drives that we were told to ignore */ |
| 2115 | if (ignore != NULL) { | 2113 | if (ignore != NULL) { |
| 2116 | if (strstr(ignore, drive->name)) { | 2114 | if (strstr(ignore, drive->name)) { |
| 2117 | printk(KERN_INFO "ide-cd: ignoring drive %s\n", drive->name); | 2115 | printk(KERN_INFO "ide-cd: ignoring drive %s\n", |
| 2116 | drive->name); | ||
| 2118 | goto failed; | 2117 | goto failed; |
| 2119 | } | 2118 | } |
| 2120 | } | 2119 | } |
| 2121 | if (drive->scsi) { | 2120 | if (drive->scsi) { |
| 2122 | printk(KERN_INFO "ide-cd: passing drive %s to ide-scsi emulation.\n", drive->name); | 2121 | printk(KERN_INFO "ide-cd: passing drive %s to ide-scsi " |
| 2122 | "emulation.\n", drive->name); | ||
| 2123 | goto failed; | 2123 | goto failed; |
| 2124 | } | 2124 | } |
| 2125 | info = kzalloc(sizeof(struct cdrom_info), GFP_KERNEL); | 2125 | info = kzalloc(sizeof(struct cdrom_info), GFP_KERNEL); |
| 2126 | if (info == NULL) { | 2126 | if (info == NULL) { |
| 2127 | printk(KERN_ERR "%s: Can't allocate a cdrom structure\n", drive->name); | 2127 | printk(KERN_ERR "%s: Can't allocate a cdrom structure\n", |
| 2128 | drive->name); | ||
| 2128 | goto failed; | 2129 | goto failed; |
| 2129 | } | 2130 | } |
| 2130 | 2131 | ||
