Lines Matching +full:sense +full:- +full:mode

2  * ATAPI CD-ROM driver.
4 * Copyright (C) 1994-1996 Scott Snyder <snyder@fnald0.fnal.gov>
5 * Copyright (C) 1996-1998 Erik Andersen <andersee@debian.org>
6 * Copyright (C) 1998-2000 Jens Axboe <axboe@suse.de>
7 * Copyright (C) 2005, 2007-2009 Bartlomiej Zolnierkiewicz
12 * See Documentation/cdrom/ide-cd.rst for usage information.
14 * Suggestions are welcome. Patches that work are more welcome though. ;-)
17 * Mt. Fuji (SFF8090 version 4) and ATAPI (SFF-8020i rev 2.6) standards.
20 * Documentation/ide/ChangeLog.ide-cd.1994-2004
23 #define DRV_NAME "ide-cd"
45 /* For SCSI -> ATAPI command conversion */
53 #include "ide-cd.h"
67 if (ide_device_get(cd->drive)) in ide_cd_get()
70 get_device(&cd->dev); in ide_cd_get()
79 ide_drive_t *drive = cd->drive; in ide_cd_put()
82 put_device(&cd->dev); in ide_cd_put()
94 drive->dev_flags |= IDE_DFLAG_MEDIA_CHANGED; in cdrom_saw_media_change()
95 drive->atapi_flags &= ~IDE_AFLAG_TOC_VALID; in cdrom_saw_media_change()
100 struct request_sense *sense = &drive->sense_data; in cdrom_log_sense() local
103 if (!sense || !rq || (rq->rq_flags & RQF_QUIET)) in cdrom_log_sense()
106 ide_debug_log(IDE_DBG_SENSE, "sense_key: 0x%x", sense->sense_key); in cdrom_log_sense()
108 switch (sense->sense_key) { in cdrom_log_sense()
115 * commands or in-progress or becoming ready in cdrom_log_sense()
117 if (sense->asc == 0x3a || sense->asc == 0x04) in cdrom_log_sense()
124 * reliably check if drive can auto-close in cdrom_log_sense()
126 if (scsi_req(rq)->cmd[0] == GPCMD_START_STOP_UNIT && sense->asc == 0x24) in cdrom_log_sense()
133 * Some drives (i.e. Creative) fail to present the correct sense in cdrom_log_sense()
148 struct request_sense *sense = &drive->sense_data; in cdrom_analyze_sense_data() local
149 struct cdrom_info *info = drive->driver_data; in cdrom_analyze_sense_data()
154 sense->error_code, sense->sense_key); in cdrom_analyze_sense_data()
158 failed_command->cmd[0]); in cdrom_analyze_sense_data()
164 * If a read toc is executed for a CD-R or CD-RW medium where the first in cdrom_analyze_sense_data()
168 if (failed_command && scsi_req(failed_command)->cmd[0] == GPCMD_READ_TOC_PMA_ATIP) in cdrom_analyze_sense_data()
169 if (sense->sense_key == 0x05 && sense->asc == 0x24) in cdrom_analyze_sense_data()
173 if (sense->error_code == 0x70) { in cdrom_analyze_sense_data()
174 switch (sense->sense_key) { in cdrom_analyze_sense_data()
178 if (!sense->valid) in cdrom_analyze_sense_data()
183 sector = (sense->information[0] << 24) | in cdrom_analyze_sense_data()
184 (sense->information[1] << 16) | in cdrom_analyze_sense_data()
185 (sense->information[2] << 8) | in cdrom_analyze_sense_data()
186 (sense->information[3]); in cdrom_analyze_sense_data()
188 if (queue_logical_block_size(drive->queue) == 2048) in cdrom_analyze_sense_data()
192 bio_sectors = max(bio_sectors(failed_command->bio), 4U); in cdrom_analyze_sense_data()
193 sector &= ~(bio_sectors - 1); in cdrom_analyze_sense_data()
203 if (sector < get_capacity(info->disk) && in cdrom_analyze_sense_data()
204 drive->probed_capacity - sector < 4 * 75) in cdrom_analyze_sense_data()
205 set_capacity(info->disk, sector); in cdrom_analyze_sense_data()
209 ide_cd_log_error(drive->name, failed_command, sense); in cdrom_analyze_sense_data()
215 * For ATA_PRIV_SENSE, "ide_req(rq)->special" points to the original in ide_cd_complete_failed_rq()
216 * failed request. Also, the sense data should be read in ide_cd_complete_failed_rq()
218 * sense buffer if it got copied during mapping. in ide_cd_complete_failed_rq()
220 struct request *failed = ide_req(rq)->special; in ide_cd_complete_failed_rq()
221 void *sense = bio_data(rq->bio); in ide_cd_complete_failed_rq() local
225 * Sense is always read into drive->sense_data, copy back to the in ide_cd_complete_failed_rq()
228 memcpy(scsi_req(failed)->sense, sense, 18); in ide_cd_complete_failed_rq()
229 scsi_req(failed)->sense_len = scsi_req(rq)->sense_len; in ide_cd_complete_failed_rq()
249 struct cdrom_info *info = drive->driver_data; in ide_cd_breathe()
251 if (!scsi_req(rq)->result) in ide_cd_breathe()
252 info->write_timeout = jiffies + ATAPI_WAIT_WRITE_BUSY; in ide_cd_breathe()
254 scsi_req(rq)->result = 1; in ide_cd_breathe()
256 if (time_after(jiffies, info->write_timeout)) in ide_cd_breathe()
263 blk_mq_delay_kick_requeue_list(drive->queue, 1); in ide_cd_breathe()
270 if (!drive->sense_rq) in ide_cd_free_sense()
273 blk_mq_free_request(drive->sense_rq); in ide_cd_free_sense()
274 drive->sense_rq = NULL; in ide_cd_free_sense()
275 drive->sense_rq_armed = false; in ide_cd_free_sense()
286 ide_hwif_t *hwif = drive->hwif; in cdrom_decode_status()
287 struct request *rq = hwif->rq; in cdrom_decode_status()
294 ide_debug_log(IDE_DBG_RQ, "cmd: 0x%x, rq->cmd_type: 0x%x, err: 0x%x, " in cdrom_decode_status()
296 rq->cmd[0], rq->cmd_type, err, stat); in cdrom_decode_status()
300 * We got an error trying to get sense info from the drive in cdrom_decode_status()
304 rq->rq_flags |= RQF_FAILED; in cdrom_decode_status()
309 if (blk_rq_is_scsi(rq) && !scsi_req(rq)->result) in cdrom_decode_status()
310 scsi_req(rq)->result = SAM_STAT_CHECK_CONDITION; in cdrom_decode_status()
324 !(rq->rq_flags & RQF_QUIET)) in cdrom_decode_status()
326 drive->name); in cdrom_decode_status()
340 if (++scsi_req(rq)->result > ERROR_MAX) in cdrom_decode_status()
345 * Don't print error message for this condition -- SFF8090i in cdrom_decode_status()
351 if (scsi_req(rq)->cmd[0] == GPCMD_START_STOP_UNIT) in cdrom_decode_status()
359 if (!(rq->rq_flags & RQF_QUIET)) in cdrom_decode_status()
365 * No point in re-trying a zillion times on a bad sector. in cdrom_decode_status()
368 if (!(rq->rq_flags & RQF_QUIET)) in cdrom_decode_status()
375 if (!(rq->rq_flags & RQF_QUIET)) in cdrom_decode_status()
387 } else if (++scsi_req(rq)->result > ERROR_MAX) in cdrom_decode_status()
393 rq->rq_flags |= RQF_FAILED; in cdrom_decode_status()
398 * End a request through request sense analysis when we have sense data. in cdrom_decode_status()
404 /* if we got a CHECK_CONDITION status, queue a request sense command */ in cdrom_decode_status()
411 hwif->rq = NULL; in cdrom_decode_status()
419 struct request *rq = cmd->rq; in ide_cd_request_sense_fixup()
421 ide_debug_log(IDE_DBG_FUNC, "rq->cmd[0]: 0x%x", rq->cmd[0]); in ide_cd_request_sense_fixup()
424 * Some of the trailing request sense fields are optional, in ide_cd_request_sense_fixup()
427 if (scsi_req(rq)->cmd[0] == GPCMD_REQUEST_SENSE && in ide_cd_request_sense_fixup()
428 cmd->nleft > 0 && cmd->nleft <= 5) in ide_cd_request_sense_fixup()
429 cmd->nleft = 0; in ide_cd_request_sense_fixup()
437 struct cdrom_info *info = drive->driver_data; in ide_cd_queue_pc()
455 rq = blk_get_request(drive->queue, in ide_cd_queue_pc()
457 memcpy(scsi_req(rq)->cmd, cmd, BLK_MAX_CDB); in ide_cd_queue_pc()
458 ide_req(rq)->type = ATA_PRIV_PC; in ide_cd_queue_pc()
459 rq->rq_flags |= rq_flags; in ide_cd_queue_pc()
460 rq->timeout = timeout; in ide_cd_queue_pc()
462 error = blk_rq_map_kern(drive->queue, rq, buffer, in ide_cd_queue_pc()
470 blk_execute_rq(drive->queue, info->disk, rq, 0); in ide_cd_queue_pc()
471 error = scsi_req(rq)->result ? -EIO : 0; in ide_cd_queue_pc()
474 *bufflen = scsi_req(rq)->resid_len; in ide_cd_queue_pc()
475 scsi_normalize_sense(scsi_req(rq)->sense, in ide_cd_queue_pc()
476 scsi_req(rq)->sense_len, sshdr); in ide_cd_queue_pc()
482 failed = (rq->rq_flags & RQF_FAILED) != 0; in ide_cd_queue_pc()
488 if (sshdr->sense_key == UNIT_ATTENTION) in ide_cd_queue_pc()
490 else if (sshdr->sense_key == NOT_READY && in ide_cd_queue_pc()
491 sshdr->asc == 4 && sshdr->ascq != 4) { in ide_cd_queue_pc()
502 --retries; in ide_cd_queue_pc()
510 return failed ? -EIO : 0; in ide_cd_queue_pc()
518 unsigned int nr_bytes = cmd->nbytes - cmd->nleft; in ide_cd_error_cmd()
520 if (cmd->tf_flags & IDE_TFLAG_WRITE) in ide_cd_error_cmd()
521 nr_bytes -= cmd->last_xfer_len; in ide_cd_error_cmd()
540 req->cmd[0] = GPCMD_READ_10; in ide_cdrom_prep_fs()
542 req->cmd[0] = GPCMD_WRITE_10; in ide_cdrom_prep_fs()
547 req->cmd[2] = (block >> 24) & 0xff; in ide_cdrom_prep_fs()
548 req->cmd[3] = (block >> 16) & 0xff; in ide_cdrom_prep_fs()
549 req->cmd[4] = (block >> 8) & 0xff; in ide_cdrom_prep_fs()
550 req->cmd[5] = block & 0xff; in ide_cdrom_prep_fs()
555 req->cmd[7] = (blocks >> 8) & 0xff; in ide_cdrom_prep_fs()
556 req->cmd[8] = blocks & 0xff; in ide_cdrom_prep_fs()
557 req->cmd_len = 10; in ide_cdrom_prep_fs()
567 u8 *c = scsi_req(rq)->cmd; in ide_cdrom_prep_pc()
569 /* transform 6-byte read/write commands to the 10-byte version */ in ide_cdrom_prep_pc()
577 c[0] += (READ_10 - READ_6); in ide_cdrom_prep_pc()
578 scsi_req(rq)->cmd_len = 10; in ide_cdrom_prep_pc()
583 * it's silly to pretend we understand 6-byte sense commands, just in ide_cdrom_prep_pc()
588 scsi_req(rq)->result = ILLEGAL_REQUEST; in ide_cdrom_prep_pc()
600 return ide_cdrom_prep_fs(drive->queue, rq); in ide_cdrom_prep_rq()
609 ide_hwif_t *hwif = drive->hwif; in cdrom_newpc_intr()
610 struct ide_cmd *cmd = &hwif->cmd; in cdrom_newpc_intr()
611 struct request *rq = hwif->rq; in cdrom_newpc_intr()
615 int sense = ata_sense_request(rq); in cdrom_newpc_intr() local
620 ide_debug_log(IDE_DBG_PC, "cmd: 0x%x, write: 0x%x", rq->cmd[0], write); in cdrom_newpc_intr()
623 dma = drive->dma; in cdrom_newpc_intr()
625 drive->dma = 0; in cdrom_newpc_intr()
626 drive->waiting_for_dma = 0; in cdrom_newpc_intr()
627 dma_error = hwif->dma_ops->dma_end(drive); in cdrom_newpc_intr()
630 printk(KERN_ERR PFX "%s: DMA %s error\n", drive->name, in cdrom_newpc_intr()
637 stat = hwif->tp_ops->read_status(hwif); in cdrom_newpc_intr()
658 thislen = !blk_rq_is_passthrough(rq) ? len : cmd->nleft; in cdrom_newpc_intr()
674 if (cmd->nleft > 0) { in cdrom_newpc_intr()
676 "(%u bytes)\n", drive->name, __func__, in cdrom_newpc_intr()
677 cmd->nleft); in cdrom_newpc_intr()
679 rq->rq_flags |= RQF_FAILED; in cdrom_newpc_intr()
687 uptodate = cmd->nleft ? 0 : 1; in cdrom_newpc_intr()
695 uptodate = cmd->nleft ? 0 : 1; in cdrom_newpc_intr()
699 rq->rq_flags |= RQF_FAILED; in cdrom_newpc_intr()
711 cmd->last_xfer_len = 0; in cdrom_newpc_intr()
713 ide_debug_log(IDE_DBG_PC, "data transfer, rq->cmd_type: 0x%x, " in cdrom_newpc_intr()
715 rq->cmd_type, ireason); in cdrom_newpc_intr()
719 int blen = min_t(int, thislen, cmd->nleft); in cdrom_newpc_intr()
721 if (cmd->nleft == 0) in cdrom_newpc_intr()
725 cmd->last_xfer_len += blen; in cdrom_newpc_intr()
727 thislen -= blen; in cdrom_newpc_intr()
728 len -= blen; in cdrom_newpc_intr()
730 if (sense && write == 0) in cdrom_newpc_intr()
731 scsi_req(rq)->sense_len += blen; in cdrom_newpc_intr()
740 drive->name); in cdrom_newpc_intr()
748 timeout = rq->timeout; in cdrom_newpc_intr()
759 hwif->expiry = expiry; in cdrom_newpc_intr()
765 scsi_req(rq)->resid_len = 0; in cdrom_newpc_intr()
767 hwif->rq = NULL; in cdrom_newpc_intr()
769 if (sense && uptodate) in cdrom_newpc_intr()
773 if (cmd->nleft == 0) in cdrom_newpc_intr()
776 if (uptodate <= 0 && scsi_req(rq)->result == 0) in cdrom_newpc_intr()
777 scsi_req(rq)->result = -EIO; in cdrom_newpc_intr()
780 if (uptodate == 0 && rq->bio) in cdrom_newpc_intr()
786 scsi_req(rq)->resid_len -= cmd->nbytes - cmd->nleft; in cdrom_newpc_intr()
787 if (uptodate == 0 && (cmd->tf_flags & IDE_TFLAG_WRITE)) in cdrom_newpc_intr()
788 scsi_req(rq)->resid_len += cmd->last_xfer_len; in cdrom_newpc_intr()
793 if (sense && rc == 2) in cdrom_newpc_intr()
794 ide_error(drive, "request sense failure", stat); in cdrom_newpc_intr()
803 struct cdrom_info *cd = drive->driver_data; in cdrom_start_rw()
804 struct request_queue *q = drive->queue; in cdrom_start_rw()
809 ide_debug_log(IDE_DBG_RQ, "rq->cmd[0]: 0x%x, rq->cmd_flags: 0x%x, " in cdrom_start_rw()
811 rq->cmd[0], rq->cmd_flags, sectors_per_frame); in cdrom_start_rw()
815 if (get_disk_ro(cd->disk)) in cdrom_start_rw()
826 if ((blk_rq_sectors(rq) & (sectors_per_frame - 1)) || in cdrom_start_rw()
827 (blk_rq_pos(rq) & (sectors_per_frame - 1))) in cdrom_start_rw()
831 drive->dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA); in cdrom_start_rw()
834 cd->devinfo.media_written = 1; in cdrom_start_rw()
836 rq->timeout = ATAPI_WAIT_PC; in cdrom_start_rw()
844 ide_debug_log(IDE_DBG_PC, "rq->cmd[0]: 0x%x, rq->cmd_type: 0x%x", in cdrom_do_block_pc()
845 rq->cmd[0], rq->cmd_type); in cdrom_do_block_pc()
848 rq->rq_flags |= RQF_QUIET; in cdrom_do_block_pc()
850 rq->rq_flags &= ~RQF_FAILED; in cdrom_do_block_pc()
852 drive->dma = 0; in cdrom_do_block_pc()
855 if (rq->bio) { in cdrom_do_block_pc()
856 struct request_queue *q = drive->queue; in cdrom_do_block_pc()
857 char *buf = bio_data(rq->bio); in cdrom_do_block_pc()
860 drive->dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA); in cdrom_do_block_pc()
868 alignment = queue_dma_alignment(q) | q->dma_pad_mask; in cdrom_do_block_pc()
870 || blk_rq_bytes(rq) & q->dma_pad_mask in cdrom_do_block_pc()
872 drive->dma = 0; in cdrom_do_block_pc()
884 rq->cmd[0], (unsigned long long)block); in ide_cd_do_request()
886 if (drive->debug_mask & IDE_DBG_RQ) in ide_cd_do_request()
897 if (!rq->timeout) in ide_cd_do_request()
898 rq->timeout = ATAPI_WAIT_PC; in ide_cd_do_request()
903 switch (ide_req(rq)->type) { in ide_cd_do_request()
916 /* prepare sense request for this command */ in ide_cd_do_request()
949 * subsequent request sense command. The pointer can also be NULL, in which case
950 * no sense information is returned.
954 msf->minute = bcd2bin(msf->minute); in msf_from_bcd()
955 msf->second = bcd2bin(msf->second); in msf_from_bcd()
956 msf->frame = bcd2bin(msf->frame); in msf_from_bcd()
961 struct cdrom_info *info = drive->driver_data; in cdrom_check_status()
968 return -EIO; in cdrom_check_status()
970 cdi = &info->devinfo; in cdrom_check_status()
979 cmd[7] = cdi->sanyo_slot % 3; in cdrom_check_status()
1023 drive->name, blocklen); in cdrom_read_capacity()
1062 struct cdrom_info *info = drive->driver_data; in ide_cd_read_toc()
1063 struct cdrom_device_info *cdi = &info->devinfo; in ide_cd_read_toc()
1064 struct atapi_toc *toc = info->toc; in ide_cd_read_toc()
1079 drive->name); in ide_cd_read_toc()
1080 return -ENOMEM; in ide_cd_read_toc()
1082 info->toc = toc; in ide_cd_read_toc()
1091 if (drive->atapi_flags & IDE_AFLAG_TOC_VALID) in ide_cd_read_toc()
1095 stat = cdrom_read_capacity(drive, &toc->capacity, &sectors_per_frame); in ide_cd_read_toc()
1097 toc->capacity = 0x1fffff; in ide_cd_read_toc()
1099 set_capacity(info->disk, toc->capacity * sectors_per_frame); in ide_cd_read_toc()
1101 drive->probed_capacity = toc->capacity * sectors_per_frame; in ide_cd_read_toc()
1103 blk_queue_logical_block_size(drive->queue, in ide_cd_read_toc()
1107 stat = ide_cdrom_read_tocentry(drive, 0, 1, 0, (char *) &toc->hdr, in ide_cd_read_toc()
1112 if (drive->atapi_flags & IDE_AFLAG_TOCTRACKS_AS_BCD) { in ide_cd_read_toc()
1113 toc->hdr.first_track = bcd2bin(toc->hdr.first_track); in ide_cd_read_toc()
1114 toc->hdr.last_track = bcd2bin(toc->hdr.last_track); in ide_cd_read_toc()
1117 ntracks = toc->hdr.last_track - toc->hdr.first_track + 1; in ide_cd_read_toc()
1119 return -EIO; in ide_cd_read_toc()
1124 stat = ide_cdrom_read_tocentry(drive, toc->hdr.first_track, 1, 0, in ide_cd_read_toc()
1125 (char *)&toc->hdr, in ide_cd_read_toc()
1130 if (stat && toc->hdr.first_track > 1) { in ide_cd_read_toc()
1145 (char *)&toc->hdr, in ide_cd_read_toc()
1152 if (drive->atapi_flags & IDE_AFLAG_TOCTRACKS_AS_BCD) { in ide_cd_read_toc()
1153 toc->hdr.first_track = (u8)bin2bcd(CDROM_LEADOUT); in ide_cd_read_toc()
1154 toc->hdr.last_track = (u8)bin2bcd(CDROM_LEADOUT); in ide_cd_read_toc()
1156 toc->hdr.first_track = CDROM_LEADOUT; in ide_cd_read_toc()
1157 toc->hdr.last_track = CDROM_LEADOUT; in ide_cd_read_toc()
1164 toc->hdr.toc_length = be16_to_cpu(toc->hdr.toc_length); in ide_cd_read_toc()
1166 if (drive->atapi_flags & IDE_AFLAG_TOCTRACKS_AS_BCD) { in ide_cd_read_toc()
1167 toc->hdr.first_track = bcd2bin(toc->hdr.first_track); in ide_cd_read_toc()
1168 toc->hdr.last_track = bcd2bin(toc->hdr.last_track); in ide_cd_read_toc()
1172 if (drive->atapi_flags & IDE_AFLAG_TOCADDR_AS_BCD) { in ide_cd_read_toc()
1173 if (drive->atapi_flags & IDE_AFLAG_TOCTRACKS_AS_BCD) in ide_cd_read_toc()
1174 toc->ent[i].track = bcd2bin(toc->ent[i].track); in ide_cd_read_toc()
1175 msf_from_bcd(&toc->ent[i].addr.msf); in ide_cd_read_toc()
1177 toc->ent[i].addr.lba = msf_to_lba(toc->ent[i].addr.msf.minute, in ide_cd_read_toc()
1178 toc->ent[i].addr.msf.second, in ide_cd_read_toc()
1179 toc->ent[i].addr.msf.frame); in ide_cd_read_toc()
1182 if (toc->hdr.first_track != CDROM_LEADOUT) { in ide_cd_read_toc()
1189 toc->last_session_lba = be32_to_cpu(ms_tmp.ent.addr.lba); in ide_cd_read_toc()
1193 toc->last_session_lba = msf_to_lba(0, 2, 0); /* 0m 2s 0f */ in ide_cd_read_toc()
1196 if (drive->atapi_flags & IDE_AFLAG_TOCADDR_AS_BCD) { in ide_cd_read_toc()
1197 /* re-read multisession information using MSF format */ in ide_cd_read_toc()
1204 toc->last_session_lba = msf_to_lba(ms_tmp.ent.addr.msf.minute, in ide_cd_read_toc()
1209 toc->xa_flag = (ms_tmp.hdr.first_track != ms_tmp.hdr.last_track); in ide_cd_read_toc()
1213 if (!stat && (last_written > toc->capacity)) { in ide_cd_read_toc()
1214 toc->capacity = last_written; in ide_cd_read_toc()
1215 set_capacity(info->disk, toc->capacity * sectors_per_frame); in ide_cd_read_toc()
1216 drive->probed_capacity = toc->capacity * sectors_per_frame; in ide_cd_read_toc()
1220 drive->atapi_flags |= IDE_AFLAG_TOC_VALID; in ide_cd_read_toc()
1227 struct cdrom_info *info = drive->driver_data; in ide_cdrom_get_capabilities()
1228 struct cdrom_device_info *cdi = &info->devinfo; in ide_cdrom_get_capabilities()
1234 if ((drive->atapi_flags & IDE_AFLAG_FULL_CAPS_PAGE) == 0) in ide_cdrom_get_capabilities()
1235 size -= ATAPI_CAPABILITIES_PAGE_PAD_SIZE; in ide_cdrom_get_capabilities()
1243 } while (--attempts); in ide_cdrom_get_capabilities()
1249 struct cdrom_info *cd = drive->driver_data; in ide_cdrom_update_speed()
1254 if (drive->atapi_flags & IDE_AFLAG_LE_SPEED_FIELDS) { in ide_cdrom_update_speed()
1265 cd->current_speed = DIV_ROUND_CLOSEST(curspeed, 176); in ide_cdrom_update_speed()
1266 cd->max_speed = DIV_ROUND_CLOSEST(maxspeed, 176); in ide_cdrom_update_speed()
1294 struct cdrom_info *info = drive->driver_data; in ide_cdrom_register()
1295 struct cdrom_device_info *devinfo = &info->devinfo; in ide_cdrom_register()
1299 devinfo->ops = &ide_cdrom_dops; in ide_cdrom_register()
1300 devinfo->speed = info->current_speed; in ide_cdrom_register()
1301 devinfo->capacity = nslots; in ide_cdrom_register()
1302 devinfo->handle = drive; in ide_cdrom_register()
1303 strcpy(devinfo->name, drive->name); in ide_cdrom_register()
1305 if (drive->atapi_flags & IDE_AFLAG_NO_SPEED_SELECT) in ide_cdrom_register()
1306 devinfo->mask |= CDC_SELECT_SPEED; in ide_cdrom_register()
1308 return register_cdrom(info->disk, devinfo); in ide_cdrom_register()
1313 struct cdrom_info *cd = drive->driver_data; in ide_cdrom_probe_capabilities()
1314 struct cdrom_device_info *cdi = &cd->devinfo; in ide_cdrom_probe_capabilities()
1320 drive->media, drive->atapi_flags); in ide_cdrom_probe_capabilities()
1322 cdi->mask = (CDC_CD_R | CDC_CD_RW | CDC_DVD | CDC_DVD_R | in ide_cdrom_probe_capabilities()
1326 if (drive->media == ide_optical) { in ide_cdrom_probe_capabilities()
1327 cdi->mask &= ~(CDC_MO_DRIVE | CDC_RAM); in ide_cdrom_probe_capabilities()
1328 printk(KERN_ERR PFX "%s: ATAPI magneto-optical drive\n", in ide_cdrom_probe_capabilities()
1329 drive->name); in ide_cdrom_probe_capabilities()
1333 if (drive->atapi_flags & IDE_AFLAG_PRE_ATAPI12) { in ide_cdrom_probe_capabilities()
1334 drive->atapi_flags &= ~IDE_AFLAG_NO_EJECT; in ide_cdrom_probe_capabilities()
1335 cdi->mask &= ~CDC_PLAY_AUDIO; in ide_cdrom_probe_capabilities()
1341 * with ide_cdrom_packet(), which extracts the drive from cdi->handle. in ide_cdrom_probe_capabilities()
1343 * it can't do this. Same goes for cdi->ops. in ide_cdrom_probe_capabilities()
1345 cdi->handle = drive; in ide_cdrom_probe_capabilities()
1346 cdi->ops = &ide_cdrom_dops; in ide_cdrom_probe_capabilities()
1352 drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING; in ide_cdrom_probe_capabilities()
1354 drive->atapi_flags &= ~IDE_AFLAG_NO_EJECT; in ide_cdrom_probe_capabilities()
1356 cdi->mask &= ~CDC_CD_R; in ide_cdrom_probe_capabilities()
1358 cdi->mask &= ~(CDC_CD_RW | CDC_RAM); in ide_cdrom_probe_capabilities()
1360 cdi->mask &= ~CDC_DVD; in ide_cdrom_probe_capabilities()
1362 cdi->mask &= ~(CDC_DVD_RAM | CDC_RAM); in ide_cdrom_probe_capabilities()
1364 cdi->mask &= ~CDC_DVD_R; in ide_cdrom_probe_capabilities()
1365 if ((buf[8 + 4] & 0x01) || (drive->atapi_flags & IDE_AFLAG_PLAY_AUDIO_OK)) in ide_cdrom_probe_capabilities()
1366 cdi->mask &= ~CDC_PLAY_AUDIO; in ide_cdrom_probe_capabilities()
1371 (drive->atapi_flags & IDE_AFLAG_NO_AUTOCLOSE)) in ide_cdrom_probe_capabilities()
1372 cdi->mask |= CDC_CLOSE_TRAY; in ide_cdrom_probe_capabilities()
1374 if (cdi->sanyo_slot > 0) { in ide_cdrom_probe_capabilities()
1375 cdi->mask &= ~CDC_SELECT_DISC; in ide_cdrom_probe_capabilities()
1381 cdi->mask &= ~CDC_SELECT_DISC; in ide_cdrom_probe_capabilities()
1386 printk(KERN_INFO PFX "%s: ATAPI", drive->name); in ide_cdrom_probe_capabilities()
1389 if (cd->max_speed) in ide_cdrom_probe_capabilities()
1390 printk(KERN_CONT " %dX", cd->max_speed); in ide_cdrom_probe_capabilities()
1392 printk(KERN_CONT " %s", (cdi->mask & CDC_DVD) ? "CD-ROM" : "DVD-ROM"); in ide_cdrom_probe_capabilities()
1394 if ((cdi->mask & CDC_DVD_R) == 0 || (cdi->mask & CDC_DVD_RAM) == 0) in ide_cdrom_probe_capabilities()
1396 (cdi->mask & CDC_DVD_R) ? "" : "-R", in ide_cdrom_probe_capabilities()
1397 (cdi->mask & CDC_DVD_RAM) ? "" : "/RAM"); in ide_cdrom_probe_capabilities()
1399 if ((cdi->mask & CDC_CD_R) == 0 || (cdi->mask & CDC_CD_RW) == 0) in ide_cdrom_probe_capabilities()
1401 (cdi->mask & CDC_CD_R) ? "" : "-R", in ide_cdrom_probe_capabilities()
1402 (cdi->mask & CDC_CD_RW) ? "" : "/RW"); in ide_cdrom_probe_capabilities()
1404 if ((cdi->mask & CDC_SELECT_DISC) == 0) in ide_cdrom_probe_capabilities()
1434 ide_drive_t *drive = m->private; in idecd_capacity_proc_show()
1457 /* SCR-3231 doesn't support the SET_CD_SPEED command. */
1458 { "SAMSUNG CD-ROM SCR-3231", NULL, IDE_AFLAG_NO_SPEED_SELECT },
1460 { "NEC CD-ROM DRIVE:260", "1.01", IDE_AFLAG_TOCADDR_AS_BCD |
1467 * Sanyo 3 CD changer uses a non-standard command for CD changing
1470 { "CD-ROM CDR-C3 G", NULL, IDE_AFLAG_SANYO_3CD },
1471 { "CD-ROM CDR-C3G", NULL, IDE_AFLAG_SANYO_3CD },
1472 { "CD-ROM CDR_C36", NULL, IDE_AFLAG_SANYO_3CD },
1473 /* Stingray 8X CD-ROM. */
1474 { "STINGRAY 8422 IDE 8X CD-ROM 7-27-95", NULL, IDE_AFLAG_PRE_ATAPI12 },
1476 * ACER 50X CD-ROM and WPI 32X CD-ROM require the full spec length
1477 * mode sense page capabilities size, but older drives break.
1480 { "WPI CDS-32X", NULL, IDE_AFLAG_FULL_CAPS_PAGE },
1481 /* ACER/AOpen 24X CD-ROM has the speed fields byte-swapped. */
1487 { "MATSHITADVD-ROM SR-8187", NULL, IDE_AFLAG_PLAY_AUDIO_OK },
1488 { "MATSHITADVD-ROM SR-8186", NULL, IDE_AFLAG_PLAY_AUDIO_OK },
1489 { "MATSHITADVD-ROM SR-8176", NULL, IDE_AFLAG_PLAY_AUDIO_OK },
1490 { "MATSHITADVD-ROM SR-8174", NULL, IDE_AFLAG_PLAY_AUDIO_OK },
1491 { "Optiarc DVD RW AD-5200A", NULL, IDE_AFLAG_PLAY_AUDIO_OK },
1492 { "Optiarc DVD RW AD-7200A", NULL, IDE_AFLAG_PLAY_AUDIO_OK },
1493 { "Optiarc DVD RW AD-7543A", NULL, IDE_AFLAG_NO_AUTOCLOSE },
1494 { "TEAC CD-ROM CD-224E", NULL, IDE_AFLAG_NO_AUTOCLOSE },
1502 while (cle->id_model) { in ide_cd_flags()
1503 if (strcmp(cle->id_model, (char *)&id[ATA_ID_PROD]) == 0 && in ide_cd_flags()
1504 (cle->id_firmware == NULL || in ide_cd_flags()
1505 strstr((char *)&id[ATA_ID_FW_REV], cle->id_firmware))) in ide_cd_flags()
1506 return cle->cd_flags; in ide_cd_flags()
1515 struct cdrom_info *cd = drive->driver_data; in ide_cdrom_setup()
1516 struct cdrom_device_info *cdi = &cd->devinfo; in ide_cdrom_setup()
1517 struct request_queue *q = drive->queue; in ide_cdrom_setup()
1518 u16 *id = drive->id; in ide_cdrom_setup()
1524 drive->prep_rq = ide_cdrom_prep_rq; in ide_cdrom_setup()
1528 drive->dev_flags |= IDE_DFLAG_MEDIA_CHANGED; in ide_cdrom_setup()
1529 drive->atapi_flags = IDE_AFLAG_NO_EJECT | ide_cd_flags(id); in ide_cdrom_setup()
1531 if ((drive->atapi_flags & IDE_AFLAG_VERTOS_300_SSD) && in ide_cdrom_setup()
1533 drive->atapi_flags |= (IDE_AFLAG_TOCTRACKS_AS_BCD | in ide_cdrom_setup()
1535 else if ((drive->atapi_flags & IDE_AFLAG_VERTOS_600_ESD) && in ide_cdrom_setup()
1537 drive->atapi_flags |= IDE_AFLAG_TOCTRACKS_AS_BCD; in ide_cdrom_setup()
1538 else if (drive->atapi_flags & IDE_AFLAG_SANYO_3CD) in ide_cdrom_setup()
1540 cdi->sanyo_slot = 3; in ide_cdrom_setup()
1548 " cdrom driver.\n", drive->name, __func__); in ide_cdrom_setup()
1549 cd->devinfo.handle = NULL; in ide_cdrom_setup()
1553 ide_proc_register_driver(drive, cd->driver); in ide_cdrom_setup()
1559 struct cdrom_info *info = drive->driver_data; in ide_cd_remove()
1563 ide_proc_unregister_driver(drive, info->driver); in ide_cd_remove()
1564 device_del(&info->dev); in ide_cd_remove()
1565 del_gendisk(info->disk); in ide_cd_remove()
1568 put_device(&info->dev); in ide_cd_remove()
1575 struct cdrom_device_info *devinfo = &info->devinfo; in ide_cd_release()
1576 ide_drive_t *drive = info->drive; in ide_cd_release()
1577 struct gendisk *g = info->disk; in ide_cd_release()
1581 kfree(info->toc); in ide_cd_release()
1582 if (devinfo->handle == drive) in ide_cd_release()
1584 drive->driver_data = NULL; in ide_cd_release()
1585 drive->prep_rq = NULL; in ide_cd_release()
1586 g->private_data = NULL; in ide_cd_release()
1596 .name = "ide-cdrom",
1609 static int idecd_open(struct block_device *bdev, fmode_t mode) in idecd_open() argument
1612 int rc = -ENXIO; in idecd_open()
1615 info = ide_drv_g(bdev->bd_disk, cdrom_info); in idecd_open()
1617 ide_cd_read_toc(info->drive); in idecd_open()
1621 info = ide_cd_get(bdev->bd_disk); in idecd_open()
1625 rc = cdrom_open(&info->devinfo, bdev, mode); in idecd_open()
1633 static void idecd_release(struct gendisk *disk, fmode_t mode) in idecd_release() argument
1638 cdrom_release(&info->devinfo, mode); in idecd_release()
1652 return -EFAULT; in idecd_set_spindown()
1679 return -EFAULT; in idecd_get_spindown()
1683 static int idecd_locked_ioctl(struct block_device *bdev, fmode_t mode, in idecd_locked_ioctl() argument
1686 struct cdrom_info *info = ide_drv_g(bdev->bd_disk, cdrom_info); in idecd_locked_ioctl()
1691 return idecd_set_spindown(&info->devinfo, arg); in idecd_locked_ioctl()
1693 return idecd_get_spindown(&info->devinfo, arg); in idecd_locked_ioctl()
1698 err = generic_ide_ioctl(info->drive, bdev, cmd, arg); in idecd_locked_ioctl()
1699 if (err == -EINVAL) in idecd_locked_ioctl()
1700 err = cdrom_ioctl(&info->devinfo, bdev, mode, cmd, arg); in idecd_locked_ioctl()
1705 static int idecd_ioctl(struct block_device *bdev, fmode_t mode, in idecd_ioctl() argument
1711 ret = idecd_locked_ioctl(bdev, mode, cmd, arg); in idecd_ioctl()
1717 static int idecd_locked_compat_ioctl(struct block_device *bdev, fmode_t mode, in idecd_locked_compat_ioctl() argument
1720 struct cdrom_info *info = ide_drv_g(bdev->bd_disk, cdrom_info); in idecd_locked_compat_ioctl()
1726 return idecd_set_spindown(&info->devinfo, (unsigned long)argp); in idecd_locked_compat_ioctl()
1728 return idecd_get_spindown(&info->devinfo, (unsigned long)argp); in idecd_locked_compat_ioctl()
1733 err = generic_ide_ioctl(info->drive, bdev, cmd, arg); in idecd_locked_compat_ioctl()
1734 if (err == -EINVAL) in idecd_locked_compat_ioctl()
1735 err = cdrom_ioctl(&info->devinfo, bdev, mode, cmd, in idecd_locked_compat_ioctl()
1741 static int idecd_compat_ioctl(struct block_device *bdev, fmode_t mode, in idecd_compat_ioctl() argument
1747 ret = idecd_locked_compat_ioctl(bdev, mode, cmd, arg); in idecd_compat_ioctl()
1757 return cdrom_check_events(&info->devinfo, clearing); in idecd_check_events()
1774 MODULE_DESCRIPTION("ATAPI CD-ROM Driver");
1782 drive->driver_req, drive->media); in ide_cd_probe()
1784 if (!strstr("ide-cdrom", drive->driver_req)) in ide_cd_probe()
1787 if (drive->media != ide_cdrom && drive->media != ide_optical) in ide_cd_probe()
1790 drive->debug_mask = debug_mask; in ide_cd_probe()
1791 drive->irq_handler = cdrom_newpc_intr; in ide_cd_probe()
1796 drive->name); in ide_cd_probe()
1806 info->dev.parent = &drive->gendev; in ide_cd_probe()
1807 info->dev.release = ide_cd_release; in ide_cd_probe()
1808 dev_set_name(&info->dev, "%s", dev_name(&drive->gendev)); in ide_cd_probe()
1810 if (device_register(&info->dev)) in ide_cd_probe()
1813 info->drive = drive; in ide_cd_probe()
1814 info->driver = &ide_cdrom_driver; in ide_cd_probe()
1815 info->disk = g; in ide_cd_probe()
1817 g->private_data = &info->driver; in ide_cd_probe()
1819 drive->driver_data = info; in ide_cd_probe()
1821 g->minors = 1; in ide_cd_probe()
1822 g->flags = GENHD_FL_CD | GENHD_FL_REMOVABLE; in ide_cd_probe()
1824 put_device(&info->dev); in ide_cd_probe()
1829 g->fops = &idecd_ops; in ide_cd_probe()
1830 g->flags |= GENHD_FL_REMOVABLE | GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE; in ide_cd_probe()
1831 g->events = DISK_EVENT_MEDIA_CHANGE; in ide_cd_probe()
1832 device_add_disk(&drive->gendev, g, NULL); in ide_cd_probe()
1840 return -ENODEV; in ide_cd_probe()
1854 MODULE_ALIAS("ide:*m-cdrom*");
1855 MODULE_ALIAS("ide-cd");