diff options
Diffstat (limited to 'drivers/ide/ide-cd.c')
-rw-r--r-- | drivers/ide/ide-cd.c | 412 |
1 files changed, 152 insertions, 260 deletions
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c index fe5aefbf8339..1afd95ad4653 100644 --- a/drivers/ide/ide-cd.c +++ b/drivers/ide/ide-cd.c | |||
@@ -13,8 +13,8 @@ | |||
13 | * | 13 | * |
14 | * Suggestions are welcome. Patches that work are more welcome though. ;-) | 14 | * Suggestions are welcome. Patches that work are more welcome though. ;-) |
15 | * For those wishing to work on this driver, please be sure you download | 15 | * For those wishing to work on this driver, please be sure you download |
16 | * and comply with the latest Mt. Fuji (SFF8090 version 4) and ATAPI | 16 | * and comply with the latest Mt. Fuji (SFF8090 version 4) and ATAPI |
17 | * (SFF-8020i rev 2.6) standards. These documents can be obtained by | 17 | * (SFF-8020i rev 2.6) standards. These documents can be obtained by |
18 | * anonymous ftp from: | 18 | * anonymous ftp from: |
19 | * ftp://fission.dt.wdc.com/pub/standards/SFF_atapi/spec/SFF8020-r2.6/PS/8020r26.ps | 19 | * ftp://fission.dt.wdc.com/pub/standards/SFF_atapi/spec/SFF8020-r2.6/PS/8020r26.ps |
20 | * ftp://ftp.avc-pioneer.com/Mtfuji4/Spec/Fuji4r10.pdf | 20 | * ftp://ftp.avc-pioneer.com/Mtfuji4/Spec/Fuji4r10.pdf |
@@ -51,7 +51,7 @@ | |||
51 | 51 | ||
52 | static DEFINE_MUTEX(idecd_ref_mutex); | 52 | static DEFINE_MUTEX(idecd_ref_mutex); |
53 | 53 | ||
54 | #define to_ide_cd(obj) container_of(obj, struct cdrom_info, kref) | 54 | #define to_ide_cd(obj) container_of(obj, struct cdrom_info, kref) |
55 | 55 | ||
56 | #define ide_cd_g(disk) \ | 56 | #define ide_cd_g(disk) \ |
57 | container_of((disk)->private_data, struct cdrom_info, driver) | 57 | container_of((disk)->private_data, struct cdrom_info, driver) |
@@ -83,13 +83,12 @@ static void ide_cd_put(struct cdrom_info *cd) | |||
83 | 83 | ||
84 | /* Mark that we've seen a media change, and invalidate our internal | 84 | /* Mark that we've seen a media change, and invalidate our internal |
85 | 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; |
89 | 89 | ||
90 | cd->cd_flags |= IDE_CD_FLAG_MEDIA_CHANGED; | 90 | cd->cd_flags |= IDE_CD_FLAG_MEDIA_CHANGED; |
91 | cd->cd_flags &= ~IDE_CD_FLAG_TOC_VALID; | 91 | cd->cd_flags &= ~IDE_CD_FLAG_TOC_VALID; |
92 | cd->nsectors_buffered = 0; | ||
93 | } | 92 | } |
94 | 93 | ||
95 | static int cdrom_log_sense(ide_drive_t *drive, struct request *rq, | 94 | static int cdrom_log_sense(ide_drive_t *drive, struct request *rq, |
@@ -101,38 +100,39 @@ static int cdrom_log_sense(ide_drive_t *drive, struct request *rq, | |||
101 | return 0; | 100 | return 0; |
102 | 101 | ||
103 | switch (sense->sense_key) { | 102 | switch (sense->sense_key) { |
104 | case NO_SENSE: case RECOVERED_ERROR: | 103 | case NO_SENSE: |
105 | break; | 104 | case RECOVERED_ERROR: |
106 | case NOT_READY: | 105 | break; |
107 | /* | 106 | case NOT_READY: |
108 | * don't care about tray state messages for | 107 | /* |
109 | * e.g. capacity commands or in-progress or | 108 | * don't care about tray state messages for |
110 | * becoming ready | 109 | * e.g. capacity commands or in-progress or |
111 | */ | 110 | * becoming ready |
112 | if (sense->asc == 0x3a || sense->asc == 0x04) | 111 | */ |
113 | break; | 112 | if (sense->asc == 0x3a || sense->asc == 0x04) |
114 | log = 1; | ||
115 | break; | ||
116 | case ILLEGAL_REQUEST: | ||
117 | /* | ||
118 | * don't log START_STOP unit with LoEj set, since | ||
119 | * we cannot reliably check if drive can auto-close | ||
120 | */ | ||
121 | if (rq->cmd[0] == GPCMD_START_STOP_UNIT && sense->asc == 0x24) | ||
122 | break; | ||
123 | log = 1; | ||
124 | break; | ||
125 | case UNIT_ATTENTION: | ||
126 | /* | ||
127 | * Make good and sure we've seen this potential media | ||
128 | * change. Some drives (i.e. Creative) fail to present | ||
129 | * the correct sense key in the error register. | ||
130 | */ | ||
131 | cdrom_saw_media_change(drive); | ||
132 | break; | 113 | break; |
133 | default: | 114 | log = 1; |
134 | log = 1; | 115 | break; |
116 | case ILLEGAL_REQUEST: | ||
117 | /* | ||
118 | * don't log START_STOP unit with LoEj set, since | ||
119 | * we cannot reliably check if drive can auto-close | ||
120 | */ | ||
121 | if (rq->cmd[0] == GPCMD_START_STOP_UNIT && sense->asc == 0x24) | ||
135 | break; | 122 | break; |
123 | log = 1; | ||
124 | break; | ||
125 | case UNIT_ATTENTION: | ||
126 | /* | ||
127 | * Make good and sure we've seen this potential media | ||
128 | * change. Some drives (i.e. Creative) fail to present | ||
129 | * the correct sense key in the error register. | ||
130 | */ | ||
131 | cdrom_saw_media_change(drive); | ||
132 | break; | ||
133 | default: | ||
134 | log = 1; | ||
135 | break; | ||
136 | } | 136 | } |
137 | return log; | 137 | return log; |
138 | } | 138 | } |
@@ -159,8 +159,8 @@ void cdrom_analyze_sense_data(ide_drive_t *drive, | |||
159 | if (sense->sense_key == 0x05 && sense->asc == 0x24) | 159 | if (sense->sense_key == 0x05 && sense->asc == 0x24) |
160 | return; | 160 | return; |
161 | 161 | ||
162 | if (sense->error_code == 0x70) { /* Current Error */ | 162 | if (sense->error_code == 0x70) { /* Current Error */ |
163 | switch(sense->sense_key) { | 163 | switch (sense->sense_key) { |
164 | case MEDIUM_ERROR: | 164 | case MEDIUM_ERROR: |
165 | case VOLUME_OVERFLOW: | 165 | case VOLUME_OVERFLOW: |
166 | case ILLEGAL_REQUEST: | 166 | case ILLEGAL_REQUEST: |
@@ -179,7 +179,7 @@ void cdrom_analyze_sense_data(ide_drive_t *drive, | |||
179 | bio_sectors = 4; | 179 | bio_sectors = 4; |
180 | if (drive->queue->hardsect_size == 2048) | 180 | if (drive->queue->hardsect_size == 2048) |
181 | sector <<= 2; /* Device sector size is 2K */ | 181 | sector <<= 2; /* Device sector size is 2K */ |
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) |
@@ -188,8 +188,8 @@ void cdrom_analyze_sense_data(ide_drive_t *drive, | |||
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 | } | 190 | } |
191 | } | 191 | } |
192 | } | 192 | } |
193 | 193 | ||
194 | ide_cd_log_error(drive->name, failed_command, sense); | 194 | ide_cd_log_error(drive->name, failed_command, sense); |
195 | } | 195 | } |
@@ -230,7 +230,7 @@ static void cdrom_queue_request_sense(ide_drive_t *drive, void *sense, | |||
230 | (void) ide_do_drive_cmd(drive, rq, ide_preempt); | 230 | (void) ide_do_drive_cmd(drive, rq, ide_preempt); |
231 | } | 231 | } |
232 | 232 | ||
233 | static void cdrom_end_request (ide_drive_t *drive, int uptodate) | 233 | static void cdrom_end_request(ide_drive_t *drive, int uptodate) |
234 | { | 234 | { |
235 | struct request *rq = HWGROUP(drive)->rq; | 235 | struct request *rq = HWGROUP(drive)->rq; |
236 | int nsectors = rq->hard_cur_sectors; | 236 | int nsectors = rq->hard_cur_sectors; |
@@ -293,7 +293,7 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret) | |||
293 | { | 293 | { |
294 | struct request *rq = HWGROUP(drive)->rq; | 294 | struct request *rq = HWGROUP(drive)->rq; |
295 | int stat, err, sense_key; | 295 | int stat, err, sense_key; |
296 | 296 | ||
297 | /* Check for errors. */ | 297 | /* Check for errors. */ |
298 | stat = ide_read_status(drive); | 298 | stat = ide_read_status(drive); |
299 | 299 | ||
@@ -334,26 +334,26 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret) | |||
334 | 334 | ||
335 | /* Check for tray open. */ | 335 | /* Check for tray open. */ |
336 | if (sense_key == NOT_READY) { | 336 | if (sense_key == NOT_READY) { |
337 | cdrom_saw_media_change (drive); | 337 | cdrom_saw_media_change(drive); |
338 | } else if (sense_key == UNIT_ATTENTION) { | 338 | } else if (sense_key == UNIT_ATTENTION) { |
339 | /* Check for media change. */ | 339 | /* Check for media change. */ |
340 | cdrom_saw_media_change (drive); | 340 | cdrom_saw_media_change(drive); |
341 | /*printk("%s: media changed\n",drive->name);*/ | 341 | /*printk("%s: media changed\n",drive->name);*/ |
342 | return 0; | 342 | return 0; |
343 | } else if ((sense_key == ILLEGAL_REQUEST) && | 343 | } else if (sense_key == ILLEGAL_REQUEST && |
344 | (rq->cmd[0] == GPCMD_START_STOP_UNIT)) { | 344 | rq->cmd[0] == GPCMD_START_STOP_UNIT) { |
345 | /* | 345 | /* |
346 | * Don't print error message for this condition-- | 346 | * Don't print error message for this condition-- |
347 | * SFF8090i indicates that 5/24/00 is the correct | 347 | * SFF8090i indicates that 5/24/00 is the correct |
348 | * response to a request to close the tray if the | 348 | * response to a request to close the tray if the |
349 | * drive doesn't have that capability. | 349 | * drive doesn't have that capability. |
350 | * cdrom_log_sense() knows this! | 350 | * cdrom_log_sense() knows this! |
351 | */ | 351 | */ |
352 | } else if (!(rq->cmd_flags & REQ_QUIET)) { | 352 | } else if (!(rq->cmd_flags & REQ_QUIET)) { |
353 | /* Otherwise, print an error. */ | 353 | /* Otherwise, print an error. */ |
354 | ide_dump_status(drive, "packet command error", stat); | 354 | ide_dump_status(drive, "packet command error", stat); |
355 | } | 355 | } |
356 | 356 | ||
357 | rq->cmd_flags |= REQ_FAILED; | 357 | rq->cmd_flags |= REQ_FAILED; |
358 | 358 | ||
359 | /* | 359 | /* |
@@ -374,10 +374,10 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret) | |||
374 | if (sense_key == NOT_READY) { | 374 | if (sense_key == NOT_READY) { |
375 | /* Tray open. */ | 375 | /* Tray open. */ |
376 | if (rq_data_dir(rq) == READ) { | 376 | if (rq_data_dir(rq) == READ) { |
377 | cdrom_saw_media_change (drive); | 377 | cdrom_saw_media_change(drive); |
378 | 378 | ||
379 | /* Fail the request. */ | 379 | /* Fail the request. */ |
380 | printk ("%s: tray open\n", drive->name); | 380 | printk("%s: tray open\n", drive->name); |
381 | do_end_request = 1; | 381 | do_end_request = 1; |
382 | } else { | 382 | } else { |
383 | struct cdrom_info *info = drive->driver_data; | 383 | struct cdrom_info *info = drive->driver_data; |
@@ -399,7 +399,7 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret) | |||
399 | */ | 399 | */ |
400 | spin_lock_irqsave(&ide_lock, flags); | 400 | spin_lock_irqsave(&ide_lock, flags); |
401 | blk_plug_device(drive->queue); | 401 | blk_plug_device(drive->queue); |
402 | spin_unlock_irqrestore(&ide_lock,flags); | 402 | spin_unlock_irqrestore(&ide_lock, flags); |
403 | return 1; | 403 | return 1; |
404 | } | 404 | } |
405 | } | 405 | } |
@@ -407,25 +407,31 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret) | |||
407 | /* Media change. */ | 407 | /* Media change. */ |
408 | cdrom_saw_media_change (drive); | 408 | cdrom_saw_media_change (drive); |
409 | 409 | ||
410 | /* Arrange to retry the request. | 410 | /* |
411 | But be sure to give up if we've retried | 411 | * Arrange to retry the request. |
412 | too many times. */ | 412 | * But be sure to give up if we've retried |
413 | * too many times. | ||
414 | */ | ||
413 | if (++rq->errors > ERROR_MAX) | 415 | if (++rq->errors > ERROR_MAX) |
414 | do_end_request = 1; | 416 | do_end_request = 1; |
415 | } else if (sense_key == ILLEGAL_REQUEST || | 417 | } else if (sense_key == ILLEGAL_REQUEST || |
416 | sense_key == DATA_PROTECT) { | 418 | sense_key == DATA_PROTECT) { |
417 | /* No point in retrying after an illegal | 419 | /* |
418 | request or data protect error.*/ | 420 | * No point in retrying after an illegal |
419 | ide_dump_status_no_sense (drive, "command error", stat); | 421 | * request or data protect error. |
422 | */ | ||
423 | ide_dump_status_no_sense(drive, "command error", stat); | ||
420 | do_end_request = 1; | 424 | do_end_request = 1; |
421 | } else if (sense_key == MEDIUM_ERROR) { | 425 | } else if (sense_key == MEDIUM_ERROR) { |
422 | /* No point in re-trying a zillion times on a bad | 426 | /* |
423 | * sector... If we got here the error is not correctable */ | 427 | * No point in re-trying a zillion times on a bad |
424 | ide_dump_status_no_sense (drive, "media error (bad sector)", stat); | 428 | * sector... If we got here the error is not correctable |
429 | */ | ||
430 | ide_dump_status_no_sense(drive, "media error (bad sector)", stat); | ||
425 | do_end_request = 1; | 431 | do_end_request = 1; |
426 | } else if (sense_key == BLANK_CHECK) { | 432 | } else if (sense_key == BLANK_CHECK) { |
427 | /* Disk appears blank ?? */ | 433 | /* Disk appears blank ?? */ |
428 | ide_dump_status_no_sense (drive, "media error (blank)", stat); | 434 | ide_dump_status_no_sense(drive, "media error (blank)", stat); |
429 | do_end_request = 1; | 435 | do_end_request = 1; |
430 | } else if ((err & ~ABRT_ERR) != 0) { | 436 | } else if ((err & ~ABRT_ERR) != 0) { |
431 | /* Go to the default handler | 437 | /* Go to the default handler |
@@ -486,18 +492,18 @@ static int cdrom_timer_expiry(ide_drive_t *drive) | |||
486 | * ide_timer_expiry keep polling us for these. | 492 | * ide_timer_expiry keep polling us for these. |
487 | */ | 493 | */ |
488 | switch (rq->cmd[0]) { | 494 | switch (rq->cmd[0]) { |
489 | case GPCMD_BLANK: | 495 | case GPCMD_BLANK: |
490 | case GPCMD_FORMAT_UNIT: | 496 | case GPCMD_FORMAT_UNIT: |
491 | case GPCMD_RESERVE_RZONE_TRACK: | 497 | case GPCMD_RESERVE_RZONE_TRACK: |
492 | case GPCMD_CLOSE_TRACK: | 498 | case GPCMD_CLOSE_TRACK: |
493 | case GPCMD_FLUSH_CACHE: | 499 | case GPCMD_FLUSH_CACHE: |
494 | wait = ATAPI_WAIT_PC; | 500 | wait = ATAPI_WAIT_PC; |
495 | break; | 501 | break; |
496 | default: | 502 | default: |
497 | if (!(rq->cmd_flags & REQ_QUIET)) | 503 | if (!(rq->cmd_flags & REQ_QUIET)) |
498 | printk(KERN_INFO "ide-cd: cmd 0x%x timed out\n", rq->cmd[0]); | 504 | printk(KERN_INFO "ide-cd: cmd 0x%x timed out\n", rq->cmd[0]); |
499 | wait = 0; | 505 | wait = 0; |
500 | break; | 506 | break; |
501 | } | 507 | } |
502 | return wait; | 508 | return wait; |
503 | } | 509 | } |
@@ -557,7 +563,7 @@ static ide_startstop_t cdrom_start_packet_command(ide_drive_t *drive, | |||
557 | HANDLER is the interrupt handler to call when the command completes | 563 | HANDLER is the interrupt handler to call when the command completes |
558 | or there's data ready. */ | 564 | or there's data ready. */ |
559 | #define ATAPI_MIN_CDB_BYTES 12 | 565 | #define ATAPI_MIN_CDB_BYTES 12 |
560 | static ide_startstop_t cdrom_transfer_packet_command (ide_drive_t *drive, | 566 | static ide_startstop_t cdrom_transfer_packet_command(ide_drive_t *drive, |
561 | struct request *rq, | 567 | struct request *rq, |
562 | ide_handler_t *handler) | 568 | ide_handler_t *handler) |
563 | { | 569 | { |
@@ -626,47 +632,6 @@ static void ide_cd_drain_data(ide_drive_t *drive, int nsects) | |||
626 | } | 632 | } |
627 | 633 | ||
628 | /* | 634 | /* |
629 | * Buffer up to SECTORS_TO_TRANSFER sectors from the drive in our sector | ||
630 | * buffer. Once the first sector is added, any subsequent sectors are | ||
631 | * assumed to be continuous (until the buffer is cleared). For the first | ||
632 | * sector added, SECTOR is its sector number. (SECTOR is then ignored until | ||
633 | * the buffer is cleared.) | ||
634 | */ | ||
635 | static void cdrom_buffer_sectors (ide_drive_t *drive, unsigned long sector, | ||
636 | int sectors_to_transfer) | ||
637 | { | ||
638 | struct cdrom_info *info = drive->driver_data; | ||
639 | |||
640 | /* Number of sectors to read into the buffer. */ | ||
641 | int sectors_to_buffer = min_t(int, sectors_to_transfer, | ||
642 | (SECTOR_BUFFER_SIZE >> SECTOR_BITS) - | ||
643 | info->nsectors_buffered); | ||
644 | |||
645 | char *dest; | ||
646 | |||
647 | /* If we couldn't get a buffer, don't try to buffer anything... */ | ||
648 | if (info->buffer == NULL) | ||
649 | sectors_to_buffer = 0; | ||
650 | |||
651 | /* If this is the first sector in the buffer, remember its number. */ | ||
652 | if (info->nsectors_buffered == 0) | ||
653 | info->sector_buffered = sector; | ||
654 | |||
655 | /* Read the data into the buffer. */ | ||
656 | dest = info->buffer + info->nsectors_buffered * SECTOR_SIZE; | ||
657 | while (sectors_to_buffer > 0) { | ||
658 | HWIF(drive)->atapi_input_bytes(drive, dest, SECTOR_SIZE); | ||
659 | --sectors_to_buffer; | ||
660 | --sectors_to_transfer; | ||
661 | ++info->nsectors_buffered; | ||
662 | dest += SECTOR_SIZE; | ||
663 | } | ||
664 | |||
665 | /* Throw away any remaining data. */ | ||
666 | ide_cd_drain_data(drive, sectors_to_transfer); | ||
667 | } | ||
668 | |||
669 | /* | ||
670 | * Check the contents of the interrupt reason register from the cdrom | 635 | * Check the contents of the interrupt reason register from the cdrom |
671 | * and attempt to recover if there are problems. Returns 0 if everything's | 636 | * and attempt to recover if there are problems. Returns 0 if everything's |
672 | * ok; nonzero if the request has been terminated. | 637 | * ok; nonzero if the request has been terminated. |
@@ -686,7 +651,7 @@ static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq, | |||
686 | 651 | ||
687 | /* Whoops... */ | 652 | /* Whoops... */ |
688 | printk(KERN_ERR "%s: %s: wrong transfer direction!\n", | 653 | printk(KERN_ERR "%s: %s: wrong transfer direction!\n", |
689 | drive->name, __FUNCTION__); | 654 | drive->name, __func__); |
690 | 655 | ||
691 | xf = rw ? hwif->atapi_output_bytes : hwif->atapi_input_bytes; | 656 | xf = rw ? hwif->atapi_output_bytes : hwif->atapi_input_bytes; |
692 | ide_cd_pad_transfer(drive, xf, len); | 657 | ide_cd_pad_transfer(drive, xf, len); |
@@ -699,7 +664,7 @@ static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq, | |||
699 | } else { | 664 | } else { |
700 | /* Drive wants a command packet, or invalid ireason... */ | 665 | /* Drive wants a command packet, or invalid ireason... */ |
701 | printk(KERN_ERR "%s: %s: bad interrupt reason 0x%02x\n", | 666 | printk(KERN_ERR "%s: %s: bad interrupt reason 0x%02x\n", |
702 | drive->name, __FUNCTION__, ireason); | 667 | drive->name, __func__, ireason); |
703 | } | 668 | } |
704 | 669 | ||
705 | if (rq->cmd_type == REQ_TYPE_ATA_PC) | 670 | if (rq->cmd_type == REQ_TYPE_ATA_PC) |
@@ -721,7 +686,7 @@ static int ide_cd_check_transfer_size(ide_drive_t *drive, int len) | |||
721 | return 0; | 686 | return 0; |
722 | 687 | ||
723 | printk(KERN_ERR "%s: %s: Bad transfer size %d\n", | 688 | printk(KERN_ERR "%s: %s: Bad transfer size %d\n", |
724 | drive->name, __FUNCTION__, len); | 689 | drive->name, __func__, len); |
725 | 690 | ||
726 | if (cd->cd_flags & IDE_CD_FLAG_LIMIT_NFRAMES) | 691 | if (cd->cd_flags & IDE_CD_FLAG_LIMIT_NFRAMES) |
727 | printk(KERN_ERR " This drive is not supported by " | 692 | printk(KERN_ERR " This drive is not supported by " |
@@ -734,65 +699,6 @@ static int ide_cd_check_transfer_size(ide_drive_t *drive, int len) | |||
734 | return 1; | 699 | return 1; |
735 | } | 700 | } |
736 | 701 | ||
737 | /* | ||
738 | * Try to satisfy some of the current read request from our cached data. | ||
739 | * Returns nonzero if the request has been completed, zero otherwise. | ||
740 | */ | ||
741 | static int cdrom_read_from_buffer (ide_drive_t *drive) | ||
742 | { | ||
743 | struct cdrom_info *info = drive->driver_data; | ||
744 | struct request *rq = HWGROUP(drive)->rq; | ||
745 | unsigned short sectors_per_frame; | ||
746 | |||
747 | sectors_per_frame = queue_hardsect_size(drive->queue) >> SECTOR_BITS; | ||
748 | |||
749 | /* Can't do anything if there's no buffer. */ | ||
750 | if (info->buffer == NULL) return 0; | ||
751 | |||
752 | /* Loop while this request needs data and the next block is present | ||
753 | in our cache. */ | ||
754 | while (rq->nr_sectors > 0 && | ||
755 | rq->sector >= info->sector_buffered && | ||
756 | rq->sector < info->sector_buffered + info->nsectors_buffered) { | ||
757 | if (rq->current_nr_sectors == 0) | ||
758 | cdrom_end_request(drive, 1); | ||
759 | |||
760 | memcpy (rq->buffer, | ||
761 | info->buffer + | ||
762 | (rq->sector - info->sector_buffered) * SECTOR_SIZE, | ||
763 | SECTOR_SIZE); | ||
764 | rq->buffer += SECTOR_SIZE; | ||
765 | --rq->current_nr_sectors; | ||
766 | --rq->nr_sectors; | ||
767 | ++rq->sector; | ||
768 | } | ||
769 | |||
770 | /* If we've satisfied the current request, | ||
771 | terminate it successfully. */ | ||
772 | if (rq->nr_sectors == 0) { | ||
773 | cdrom_end_request(drive, 1); | ||
774 | return -1; | ||
775 | } | ||
776 | |||
777 | /* Move on to the next buffer if needed. */ | ||
778 | if (rq->current_nr_sectors == 0) | ||
779 | cdrom_end_request(drive, 1); | ||
780 | |||
781 | /* If this condition does not hold, then the kluge i use to | ||
782 | represent the number of sectors to skip at the start of a transfer | ||
783 | will fail. I think that this will never happen, but let's be | ||
784 | paranoid and check. */ | ||
785 | if (rq->current_nr_sectors < bio_cur_sectors(rq->bio) && | ||
786 | (rq->sector & (sectors_per_frame - 1))) { | ||
787 | printk(KERN_ERR "%s: cdrom_read_from_buffer: buffer botch (%ld)\n", | ||
788 | drive->name, (long)rq->sector); | ||
789 | cdrom_end_request(drive, 0); | ||
790 | return -1; | ||
791 | } | ||
792 | |||
793 | return 0; | ||
794 | } | ||
795 | |||
796 | static ide_startstop_t cdrom_newpc_intr(ide_drive_t *); | 702 | static ide_startstop_t cdrom_newpc_intr(ide_drive_t *); |
797 | 703 | ||
798 | /* | 704 | /* |
@@ -825,7 +731,7 @@ static ide_startstop_t cdrom_start_rw_cont(ide_drive_t *drive) | |||
825 | if (rq->current_nr_sectors != | 731 | if (rq->current_nr_sectors != |
826 | bio_cur_sectors(rq->bio)) { | 732 | bio_cur_sectors(rq->bio)) { |
827 | printk(KERN_ERR "%s: %s: buffer botch (%u)\n", | 733 | printk(KERN_ERR "%s: %s: buffer botch (%u)\n", |
828 | drive->name, __FUNCTION__, | 734 | drive->name, __func__, |
829 | rq->current_nr_sectors); | 735 | rq->current_nr_sectors); |
830 | cdrom_end_request(drive, 0); | 736 | cdrom_end_request(drive, 0); |
831 | return ide_stopped; | 737 | return ide_stopped; |
@@ -849,7 +755,7 @@ static ide_startstop_t cdrom_start_rw_cont(ide_drive_t *drive) | |||
849 | #define IDECD_SEEK_TIMER (5 * WAIT_MIN_SLEEP) /* 100 ms */ | 755 | #define IDECD_SEEK_TIMER (5 * WAIT_MIN_SLEEP) /* 100 ms */ |
850 | #define IDECD_SEEK_TIMEOUT (2 * WAIT_CMD) /* 20 sec */ | 756 | #define IDECD_SEEK_TIMEOUT (2 * WAIT_CMD) /* 20 sec */ |
851 | 757 | ||
852 | static ide_startstop_t cdrom_seek_intr (ide_drive_t *drive) | 758 | static ide_startstop_t cdrom_seek_intr(ide_drive_t *drive) |
853 | { | 759 | { |
854 | struct cdrom_info *info = drive->driver_data; | 760 | struct cdrom_info *info = drive->driver_data; |
855 | int stat; | 761 | int stat; |
@@ -866,14 +772,14 @@ static ide_startstop_t cdrom_seek_intr (ide_drive_t *drive) | |||
866 | * this condition is far too common, to bother | 772 | * this condition is far too common, to bother |
867 | * users about it | 773 | * users about it |
868 | */ | 774 | */ |
869 | /* printk("%s: disabled DSC seek overlap\n", drive->name);*/ | 775 | /* printk("%s: disabled DSC seek overlap\n", drive->name);*/ |
870 | drive->dsc_overlap = 0; | 776 | drive->dsc_overlap = 0; |
871 | } | 777 | } |
872 | } | 778 | } |
873 | return ide_stopped; | 779 | return ide_stopped; |
874 | } | 780 | } |
875 | 781 | ||
876 | static ide_startstop_t cdrom_start_seek_continuation (ide_drive_t *drive) | 782 | static ide_startstop_t cdrom_start_seek_continuation(ide_drive_t *drive) |
877 | { | 783 | { |
878 | struct request *rq = HWGROUP(drive)->rq; | 784 | struct request *rq = HWGROUP(drive)->rq; |
879 | sector_t frame = rq->sector; | 785 | sector_t frame = rq->sector; |
@@ -888,7 +794,7 @@ static ide_startstop_t cdrom_start_seek_continuation (ide_drive_t *drive) | |||
888 | return cdrom_transfer_packet_command(drive, rq, &cdrom_seek_intr); | 794 | return cdrom_transfer_packet_command(drive, rq, &cdrom_seek_intr); |
889 | } | 795 | } |
890 | 796 | ||
891 | static ide_startstop_t cdrom_start_seek (ide_drive_t *drive, unsigned int block) | 797 | static ide_startstop_t cdrom_start_seek(ide_drive_t *drive, unsigned int block) |
892 | { | 798 | { |
893 | struct cdrom_info *info = drive->driver_data; | 799 | struct cdrom_info *info = drive->driver_data; |
894 | 800 | ||
@@ -897,9 +803,11 @@ static ide_startstop_t cdrom_start_seek (ide_drive_t *drive, unsigned int block) | |||
897 | return cdrom_start_packet_command(drive, 0, cdrom_start_seek_continuation); | 803 | return cdrom_start_packet_command(drive, 0, cdrom_start_seek_continuation); |
898 | } | 804 | } |
899 | 805 | ||
900 | /* Fix up a possibly partially-processed request so that we can | 806 | /* |
901 | start it over entirely, or even put it back on the request queue. */ | 807 | * Fix up a possibly partially-processed request so that we can |
902 | static void restore_request (struct request *rq) | 808 | * start it over entirely, or even put it back on the request queue. |
809 | */ | ||
810 | static void restore_request(struct request *rq) | ||
903 | { | 811 | { |
904 | if (rq->buffer != bio_data(rq->bio)) { | 812 | if (rq->buffer != bio_data(rq->bio)) { |
905 | sector_t n = (rq->buffer - (char *) bio_data(rq->bio)) / SECTOR_SIZE; | 813 | sector_t n = (rq->buffer - (char *) bio_data(rq->bio)) / SECTOR_SIZE; |
@@ -950,7 +858,7 @@ int ide_cd_queue_pc(ide_drive_t *drive, struct request *rq) | |||
950 | error = ide_do_drive_cmd(drive, rq, ide_wait); | 858 | error = ide_do_drive_cmd(drive, rq, ide_wait); |
951 | time = jiffies - time; | 859 | time = jiffies - time; |
952 | 860 | ||
953 | /* FIXME: we should probably abort/retry or something | 861 | /* FIXME: we should probably abort/retry or something |
954 | * in case of failure */ | 862 | * in case of failure */ |
955 | if (rq->cmd_flags & REQ_FAILED) { | 863 | if (rq->cmd_flags & REQ_FAILED) { |
956 | /* The request failed. Retry if it was due to a unit | 864 | /* The request failed. Retry if it was due to a unit |
@@ -1057,7 +965,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive) | |||
1057 | if (rq->current_nr_sectors > 0) { | 965 | if (rq->current_nr_sectors > 0) { |
1058 | printk(KERN_ERR "%s: %s: data underrun " | 966 | printk(KERN_ERR "%s: %s: data underrun " |
1059 | "(%d blocks)\n", | 967 | "(%d blocks)\n", |
1060 | drive->name, __FUNCTION__, | 968 | drive->name, __func__, |
1061 | rq->current_nr_sectors); | 969 | rq->current_nr_sectors); |
1062 | if (!write) | 970 | if (!write) |
1063 | rq->cmd_flags |= REQ_FAILED; | 971 | rq->cmd_flags |= REQ_FAILED; |
@@ -1134,11 +1042,9 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive) | |||
1134 | if (!ptr) { | 1042 | if (!ptr) { |
1135 | if (blk_fs_request(rq) && !write) | 1043 | if (blk_fs_request(rq) && !write) |
1136 | /* | 1044 | /* |
1137 | * If the buffers are full, cache the rest | 1045 | * If the buffers are full, pipe the rest into |
1138 | * of the data in our internal buffer. | 1046 | * oblivion. */ |
1139 | */ | 1047 | ide_cd_drain_data(drive, thislen >> 9); |
1140 | cdrom_buffer_sectors(drive, rq->sector, | ||
1141 | thislen >> 9); | ||
1142 | else { | 1048 | else { |
1143 | printk(KERN_ERR "%s: confused, missing data\n", | 1049 | printk(KERN_ERR "%s: confused, missing data\n", |
1144 | drive->name); | 1050 | drive->name); |
@@ -1243,10 +1149,6 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq) | |||
1243 | * weirdness which might be present in the request packet. | 1149 | * weirdness which might be present in the request packet. |
1244 | */ | 1150 | */ |
1245 | restore_request(rq); | 1151 | restore_request(rq); |
1246 | |||
1247 | /* Satisfy whatever we can of this request from our cache. */ | ||
1248 | if (cdrom_read_from_buffer(drive)) | ||
1249 | return ide_stopped; | ||
1250 | } | 1152 | } |
1251 | 1153 | ||
1252 | /* | 1154 | /* |
@@ -1262,9 +1164,6 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq) | |||
1262 | } else | 1164 | } else |
1263 | cd->dma = drive->using_dma; | 1165 | cd->dma = drive->using_dma; |
1264 | 1166 | ||
1265 | /* Clear the local sector buffer. */ | ||
1266 | cd->nsectors_buffered = 0; | ||
1267 | |||
1268 | if (write) | 1167 | if (write) |
1269 | cd->devinfo.media_written = 1; | 1168 | cd->devinfo.media_written = 1; |
1270 | 1169 | ||
@@ -1320,7 +1219,7 @@ static ide_startstop_t cdrom_do_block_pc(ide_drive_t *drive, struct request *rq) | |||
1320 | * cdrom driver request routine. | 1219 | * cdrom driver request routine. |
1321 | */ | 1220 | */ |
1322 | static ide_startstop_t | 1221 | static ide_startstop_t |
1323 | ide_do_rw_cdrom (ide_drive_t *drive, struct request *rq, sector_t block) | 1222 | ide_do_rw_cdrom(ide_drive_t *drive, struct request *rq, sector_t block) |
1324 | { | 1223 | { |
1325 | ide_startstop_t action; | 1224 | ide_startstop_t action; |
1326 | struct cdrom_info *info = drive->driver_data; | 1225 | struct cdrom_info *info = drive->driver_data; |
@@ -1335,13 +1234,13 @@ ide_do_rw_cdrom (ide_drive_t *drive, struct request *rq, sector_t block) | |||
1335 | ide_stall_queue(drive, IDECD_SEEK_TIMER); | 1234 | ide_stall_queue(drive, IDECD_SEEK_TIMER); |
1336 | return ide_stopped; | 1235 | return ide_stopped; |
1337 | } | 1236 | } |
1338 | printk (KERN_ERR "%s: DSC timeout\n", drive->name); | 1237 | printk(KERN_ERR "%s: DSC timeout\n", drive->name); |
1339 | } | 1238 | } |
1340 | info->cd_flags &= ~IDE_CD_FLAG_SEEKING; | 1239 | info->cd_flags &= ~IDE_CD_FLAG_SEEKING; |
1341 | } | 1240 | } |
1342 | if ((rq_data_dir(rq) == READ) && IDE_LARGE_SEEK(info->last_block, block, IDECD_SEEK_THRESHOLD) && drive->dsc_overlap) { | 1241 | if ((rq_data_dir(rq) == READ) && IDE_LARGE_SEEK(info->last_block, block, IDECD_SEEK_THRESHOLD) && drive->dsc_overlap) |
1343 | action = cdrom_start_seek(drive, block); | 1242 | action = cdrom_start_seek(drive, block); |
1344 | } else | 1243 | else |
1345 | action = cdrom_start_rw(drive, rq); | 1244 | action = cdrom_start_rw(drive, rq); |
1346 | info->last_block = block; | 1245 | info->last_block = block; |
1347 | return action; | 1246 | return action; |
@@ -1374,7 +1273,7 @@ ide_do_rw_cdrom (ide_drive_t *drive, struct request *rq, sector_t block) | |||
1374 | */ | 1273 | */ |
1375 | 1274 | ||
1376 | static | 1275 | static |
1377 | void msf_from_bcd (struct atapi_msf *msf) | 1276 | void msf_from_bcd(struct atapi_msf *msf) |
1378 | { | 1277 | { |
1379 | msf->minute = BCD2BIN(msf->minute); | 1278 | msf->minute = BCD2BIN(msf->minute); |
1380 | msf->second = BCD2BIN(msf->second); | 1279 | msf->second = BCD2BIN(msf->second); |
@@ -1474,7 +1373,7 @@ int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense) | |||
1474 | /* Try to allocate space. */ | 1373 | /* Try to allocate space. */ |
1475 | toc = kmalloc(sizeof(struct atapi_toc), GFP_KERNEL); | 1374 | toc = kmalloc(sizeof(struct atapi_toc), GFP_KERNEL); |
1476 | if (toc == NULL) { | 1375 | if (toc == NULL) { |
1477 | printk (KERN_ERR "%s: No cdrom TOC buffer!\n", drive->name); | 1376 | printk(KERN_ERR "%s: No cdrom TOC buffer!\n", drive->name); |
1478 | return -ENOMEM; | 1377 | return -ENOMEM; |
1479 | } | 1378 | } |
1480 | info->toc = toc; | 1379 | info->toc = toc; |
@@ -1569,9 +1468,9 @@ int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense) | |||
1569 | toc->ent[i].track = BCD2BIN(toc->ent[i].track); | 1468 | toc->ent[i].track = BCD2BIN(toc->ent[i].track); |
1570 | msf_from_bcd(&toc->ent[i].addr.msf); | 1469 | msf_from_bcd(&toc->ent[i].addr.msf); |
1571 | } | 1470 | } |
1572 | toc->ent[i].addr.lba = msf_to_lba (toc->ent[i].addr.msf.minute, | 1471 | toc->ent[i].addr.lba = msf_to_lba(toc->ent[i].addr.msf.minute, |
1573 | toc->ent[i].addr.msf.second, | 1472 | toc->ent[i].addr.msf.second, |
1574 | toc->ent[i].addr.msf.frame); | 1473 | toc->ent[i].addr.msf.frame); |
1575 | } | 1474 | } |
1576 | 1475 | ||
1577 | /* Read the multisession information. */ | 1476 | /* Read the multisession information. */ |
@@ -1595,9 +1494,9 @@ int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense) | |||
1595 | if (stat) | 1494 | if (stat) |
1596 | return stat; | 1495 | return stat; |
1597 | 1496 | ||
1598 | msf_from_bcd (&ms_tmp.ent.addr.msf); | 1497 | msf_from_bcd(&ms_tmp.ent.addr.msf); |
1599 | toc->last_session_lba = msf_to_lba(ms_tmp.ent.addr.msf.minute, | 1498 | toc->last_session_lba = msf_to_lba(ms_tmp.ent.addr.msf.minute, |
1600 | ms_tmp.ent.addr.msf.second, | 1499 | ms_tmp.ent.addr.msf.second, |
1601 | ms_tmp.ent.addr.msf.frame); | 1500 | ms_tmp.ent.addr.msf.frame); |
1602 | } | 1501 | } |
1603 | 1502 | ||
@@ -1679,7 +1578,7 @@ static struct cdrom_device_ops ide_cdrom_dops = { | |||
1679 | .generic_packet = ide_cdrom_packet, | 1578 | .generic_packet = ide_cdrom_packet, |
1680 | }; | 1579 | }; |
1681 | 1580 | ||
1682 | static int ide_cdrom_register (ide_drive_t *drive, int nslots) | 1581 | static int ide_cdrom_register(ide_drive_t *drive, int nslots) |
1683 | { | 1582 | { |
1684 | struct cdrom_info *info = drive->driver_data; | 1583 | struct cdrom_info *info = drive->driver_data; |
1685 | struct cdrom_device_info *devinfo = &info->devinfo; | 1584 | struct cdrom_device_info *devinfo = &info->devinfo; |
@@ -1698,7 +1597,7 @@ static int ide_cdrom_register (ide_drive_t *drive, int nslots) | |||
1698 | } | 1597 | } |
1699 | 1598 | ||
1700 | static | 1599 | static |
1701 | int ide_cdrom_probe_capabilities (ide_drive_t *drive) | 1600 | int ide_cdrom_probe_capabilities(ide_drive_t *drive) |
1702 | { | 1601 | { |
1703 | struct cdrom_info *cd = drive->driver_data; | 1602 | struct cdrom_info *cd = drive->driver_data; |
1704 | struct cdrom_device_info *cdi = &cd->devinfo; | 1603 | struct cdrom_device_info *cdi = &cd->devinfo; |
@@ -1870,7 +1769,7 @@ static int ide_cdrom_prep_pc(struct request *rq) | |||
1870 | rq->errors = ILLEGAL_REQUEST; | 1769 | rq->errors = ILLEGAL_REQUEST; |
1871 | return BLKPREP_KILL; | 1770 | return BLKPREP_KILL; |
1872 | } | 1771 | } |
1873 | 1772 | ||
1874 | return BLKPREP_OK; | 1773 | return BLKPREP_OK; |
1875 | } | 1774 | } |
1876 | 1775 | ||
@@ -1948,7 +1847,7 @@ static unsigned int ide_cd_flags(struct hd_driveid *id) | |||
1948 | } | 1847 | } |
1949 | 1848 | ||
1950 | static | 1849 | static |
1951 | int ide_cdrom_setup (ide_drive_t *drive) | 1850 | int ide_cdrom_setup(ide_drive_t *drive) |
1952 | { | 1851 | { |
1953 | struct cdrom_info *cd = drive->driver_data; | 1852 | struct cdrom_info *cd = drive->driver_data; |
1954 | struct cdrom_device_info *cdi = &cd->devinfo; | 1853 | struct cdrom_device_info *cdi = &cd->devinfo; |
@@ -1979,7 +1878,7 @@ int ide_cdrom_setup (ide_drive_t *drive) | |||
1979 | else if (cd->cd_flags & IDE_CD_FLAG_SANYO_3CD) | 1878 | else if (cd->cd_flags & IDE_CD_FLAG_SANYO_3CD) |
1980 | cdi->sanyo_slot = 3; /* 3 => use CD in slot 0 */ | 1879 | cdi->sanyo_slot = 3; /* 3 => use CD in slot 0 */ |
1981 | 1880 | ||
1982 | nslots = ide_cdrom_probe_capabilities (drive); | 1881 | nslots = ide_cdrom_probe_capabilities(drive); |
1983 | 1882 | ||
1984 | /* | 1883 | /* |
1985 | * set correct block size | 1884 | * set correct block size |
@@ -1991,7 +1890,7 @@ int ide_cdrom_setup (ide_drive_t *drive) | |||
1991 | drive->dsc_overlap = (drive->next != drive); | 1890 | drive->dsc_overlap = (drive->next != drive); |
1992 | 1891 | ||
1993 | if (ide_cdrom_register(drive, nslots)) { | 1892 | if (ide_cdrom_register(drive, nslots)) { |
1994 | printk (KERN_ERR "%s: ide_cdrom_setup failed to register device with the cdrom driver.\n", drive->name); | 1893 | printk(KERN_ERR "%s: ide_cdrom_setup failed to register device with the cdrom driver.\n", drive->name); |
1995 | cd->devinfo.handle = NULL; | 1894 | cd->devinfo.handle = NULL; |
1996 | return 1; | 1895 | return 1; |
1997 | } | 1896 | } |
@@ -1999,19 +1898,6 @@ int ide_cdrom_setup (ide_drive_t *drive) | |||
1999 | return 0; | 1898 | return 0; |
2000 | } | 1899 | } |
2001 | 1900 | ||
2002 | #ifdef CONFIG_IDE_PROC_FS | ||
2003 | static | ||
2004 | sector_t ide_cdrom_capacity (ide_drive_t *drive) | ||
2005 | { | ||
2006 | unsigned long capacity, sectors_per_frame; | ||
2007 | |||
2008 | if (cdrom_read_capacity(drive, &capacity, §ors_per_frame, NULL)) | ||
2009 | return 0; | ||
2010 | |||
2011 | return capacity * sectors_per_frame; | ||
2012 | } | ||
2013 | #endif | ||
2014 | |||
2015 | static void ide_cd_remove(ide_drive_t *drive) | 1901 | static void ide_cd_remove(ide_drive_t *drive) |
2016 | { | 1902 | { |
2017 | struct cdrom_info *info = drive->driver_data; | 1903 | struct cdrom_info *info = drive->driver_data; |
@@ -2030,7 +1916,6 @@ static void ide_cd_release(struct kref *kref) | |||
2030 | ide_drive_t *drive = info->drive; | 1916 | ide_drive_t *drive = info->drive; |
2031 | struct gendisk *g = info->disk; | 1917 | struct gendisk *g = info->disk; |
2032 | 1918 | ||
2033 | kfree(info->buffer); | ||
2034 | kfree(info->toc); | 1919 | kfree(info->toc); |
2035 | if (devinfo->handle == drive) | 1920 | if (devinfo->handle == drive) |
2036 | unregister_cdrom(devinfo); | 1921 | unregister_cdrom(devinfo); |
@@ -2045,14 +1930,24 @@ static void ide_cd_release(struct kref *kref) | |||
2045 | static int ide_cd_probe(ide_drive_t *); | 1930 | static int ide_cd_probe(ide_drive_t *); |
2046 | 1931 | ||
2047 | #ifdef CONFIG_IDE_PROC_FS | 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 | |||
2048 | static int proc_idecd_read_capacity | 1943 | static int proc_idecd_read_capacity |
2049 | (char *page, char **start, off_t off, int count, int *eof, void *data) | 1944 | (char *page, char **start, off_t off, int count, int *eof, void *data) |
2050 | { | 1945 | { |
2051 | ide_drive_t *drive = data; | 1946 | ide_drive_t *drive = data; |
2052 | int len; | 1947 | int len; |
2053 | 1948 | ||
2054 | len = sprintf(page,"%llu\n", (long long)ide_cdrom_capacity(drive)); | 1949 | len = sprintf(page, "%llu\n", (long long)ide_cdrom_capacity(drive)); |
2055 | PROC_IDE_READ_RETURN(page,start,off,count,eof,len); | 1950 | PROC_IDE_READ_RETURN(page, start, off, count, eof, len); |
2056 | } | 1951 | } |
2057 | 1952 | ||
2058 | static ide_proc_entry_t idecd_proc[] = { | 1953 | static ide_proc_entry_t idecd_proc[] = { |
@@ -2081,20 +1976,17 @@ static ide_driver_t ide_cdrom_driver = { | |||
2081 | #endif | 1976 | #endif |
2082 | }; | 1977 | }; |
2083 | 1978 | ||
2084 | static int idecd_open(struct inode * inode, struct file * file) | 1979 | static int idecd_open(struct inode *inode, struct file *file) |
2085 | { | 1980 | { |
2086 | struct gendisk *disk = inode->i_bdev->bd_disk; | 1981 | struct gendisk *disk = inode->i_bdev->bd_disk; |
2087 | struct cdrom_info *info; | 1982 | struct cdrom_info *info; |
2088 | int rc = -ENOMEM; | 1983 | int rc = -ENOMEM; |
2089 | 1984 | ||
2090 | if (!(info = ide_cd_get(disk))) | 1985 | info = ide_cd_get(disk); |
1986 | if (!info) | ||
2091 | return -ENXIO; | 1987 | return -ENXIO; |
2092 | 1988 | ||
2093 | if (!info->buffer) | 1989 | rc = cdrom_open(&info->devinfo, inode, file); |
2094 | info->buffer = kmalloc(SECTOR_BUFFER_SIZE, GFP_KERNEL|__GFP_REPEAT); | ||
2095 | |||
2096 | if (info->buffer) | ||
2097 | rc = cdrom_open(&info->devinfo, inode, file); | ||
2098 | 1990 | ||
2099 | if (rc < 0) | 1991 | if (rc < 0) |
2100 | ide_cd_put(info); | 1992 | ide_cd_put(info); |
@@ -2102,12 +1994,12 @@ static int idecd_open(struct inode * inode, struct file * file) | |||
2102 | return rc; | 1994 | return rc; |
2103 | } | 1995 | } |
2104 | 1996 | ||
2105 | static int idecd_release(struct inode * inode, struct file * file) | 1997 | static int idecd_release(struct inode *inode, struct file *file) |
2106 | { | 1998 | { |
2107 | struct gendisk *disk = inode->i_bdev->bd_disk; | 1999 | struct gendisk *disk = inode->i_bdev->bd_disk; |
2108 | struct cdrom_info *info = ide_cd_g(disk); | 2000 | struct cdrom_info *info = ide_cd_g(disk); |
2109 | 2001 | ||
2110 | cdrom_release (&info->devinfo, file); | 2002 | cdrom_release(&info->devinfo, file); |
2111 | 2003 | ||
2112 | ide_cd_put(info); | 2004 | ide_cd_put(info); |
2113 | 2005 | ||
@@ -2139,7 +2031,7 @@ static int idecd_get_spindown(struct cdrom_device_info *cdi, unsigned long arg) | |||
2139 | struct packet_command cgc; | 2031 | struct packet_command cgc; |
2140 | char buffer[16]; | 2032 | char buffer[16]; |
2141 | int stat; | 2033 | int stat; |
2142 | char spindown; | 2034 | char spindown; |
2143 | 2035 | ||
2144 | init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_UNKNOWN); | 2036 | init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_UNKNOWN); |
2145 | 2037 | ||
@@ -2148,12 +2040,12 @@ static int idecd_get_spindown(struct cdrom_device_info *cdi, unsigned long arg) | |||
2148 | return stat; | 2040 | return stat; |
2149 | 2041 | ||
2150 | spindown = buffer[11] & 0x0f; | 2042 | spindown = buffer[11] & 0x0f; |
2151 | if (copy_to_user((void __user *)arg, &spindown, sizeof (char))) | 2043 | if (copy_to_user((void __user *)arg, &spindown, sizeof(char))) |
2152 | return -EFAULT; | 2044 | return -EFAULT; |
2153 | return 0; | 2045 | return 0; |
2154 | } | 2046 | } |
2155 | 2047 | ||
2156 | static int idecd_ioctl (struct inode *inode, struct file *file, | 2048 | static int idecd_ioctl(struct inode *inode, struct file *file, |
2157 | unsigned int cmd, unsigned long arg) | 2049 | unsigned int cmd, unsigned long arg) |
2158 | { | 2050 | { |
2159 | struct block_device *bdev = inode->i_bdev; | 2051 | struct block_device *bdev = inode->i_bdev; |
@@ -2161,13 +2053,13 @@ static int idecd_ioctl (struct inode *inode, struct file *file, | |||
2161 | int err; | 2053 | int err; |
2162 | 2054 | ||
2163 | switch (cmd) { | 2055 | switch (cmd) { |
2164 | case CDROMSETSPINDOWN: | 2056 | case CDROMSETSPINDOWN: |
2165 | return idecd_set_spindown(&info->devinfo, arg); | 2057 | return idecd_set_spindown(&info->devinfo, arg); |
2166 | case CDROMGETSPINDOWN: | 2058 | case CDROMGETSPINDOWN: |
2167 | return idecd_get_spindown(&info->devinfo, arg); | 2059 | return idecd_get_spindown(&info->devinfo, arg); |
2168 | default: | 2060 | default: |
2169 | break; | 2061 | break; |
2170 | } | 2062 | } |
2171 | 2063 | ||
2172 | err = generic_ide_ioctl(info->drive, file, bdev, cmd, arg); | 2064 | err = generic_ide_ioctl(info->drive, file, bdev, cmd, arg); |
2173 | if (err == -EINVAL) | 2065 | if (err == -EINVAL) |
@@ -2193,16 +2085,16 @@ static int idecd_revalidate_disk(struct gendisk *disk) | |||
2193 | } | 2085 | } |
2194 | 2086 | ||
2195 | static struct block_device_operations idecd_ops = { | 2087 | static struct block_device_operations idecd_ops = { |
2196 | .owner = THIS_MODULE, | 2088 | .owner = THIS_MODULE, |
2197 | .open = idecd_open, | 2089 | .open = idecd_open, |
2198 | .release = idecd_release, | 2090 | .release = idecd_release, |
2199 | .ioctl = idecd_ioctl, | 2091 | .ioctl = idecd_ioctl, |
2200 | .media_changed = idecd_media_changed, | 2092 | .media_changed = idecd_media_changed, |
2201 | .revalidate_disk= idecd_revalidate_disk | 2093 | .revalidate_disk = idecd_revalidate_disk |
2202 | }; | 2094 | }; |
2203 | 2095 | ||
2204 | /* options */ | 2096 | /* options */ |
2205 | static char *ignore = NULL; | 2097 | static char *ignore; |
2206 | 2098 | ||
2207 | module_param(ignore, charp, 0400); | 2099 | module_param(ignore, charp, 0400); |
2208 | MODULE_DESCRIPTION("ATAPI CD-ROM Driver"); | 2100 | MODULE_DESCRIPTION("ATAPI CD-ROM Driver"); |