Lines Matching full:cd

147 	struct scsi_cd *cd = dev_get_drvdata(dev);  in sr_runtime_suspend()  local
149 if (!cd) /* E.g.: runtime suspend following sr_remove() */ in sr_runtime_suspend()
152 if (cd->media_present) in sr_runtime_suspend()
208 struct scsi_cd *cd = cdi->handle; in sr_check_events() local
218 events = sr_get_events(cd->device); in sr_check_events()
219 cd->get_event_changed |= events & DISK_EVENT_MEDIA_CHANGE; in sr_check_events()
227 if (cd->ignore_get_event) { in sr_check_events()
237 if (cd->device->changed) { in sr_check_events()
239 cd->device->changed = 0; in sr_check_events()
240 cd->tur_changed = true; in sr_check_events()
247 last_present = cd->media_present; in sr_check_events()
248 ret = scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr); in sr_check_events()
255 cd->media_present = scsi_status_is_good(ret) || in sr_check_events()
258 if (last_present != cd->media_present) in sr_check_events()
259 cd->device->changed = 1; in sr_check_events()
261 if (cd->device->changed) { in sr_check_events()
263 cd->device->changed = 0; in sr_check_events()
264 cd->tur_changed = true; in sr_check_events()
267 if (cd->ignore_get_event) in sr_check_events()
271 if (!cd->tur_changed) { in sr_check_events()
272 if (cd->get_event_changed) { in sr_check_events()
273 if (cd->tur_mismatch++ > 8) { in sr_check_events()
274 sr_printk(KERN_WARNING, cd, in sr_check_events()
276 cd->ignore_get_event = true; in sr_check_events()
279 cd->tur_mismatch = 0; in sr_check_events()
282 cd->tur_changed = false; in sr_check_events()
283 cd->get_event_changed = false; in sr_check_events()
302 struct scsi_cd *cd = scsi_cd(rq->q->disk); in sr_done() local
328 if (cd->device->sector_size == 2048) in sr_done()
342 if (error_sector < get_capacity(cd->disk) && in sr_done()
343 cd->capacity - error_sector < 4 * 75) in sr_done()
344 set_capacity(cd->disk, error_sector); in sr_done()
362 struct scsi_cd *cd; in sr_init_command() local
369 cd = scsi_cd(rq->q->disk); in sr_init_command()
374 if (!cd->device || !scsi_device_online(cd->device)) { in sr_init_command()
382 if (cd->device->changed) { in sr_init_command()
390 s_size = cd->device->sector_size; in sr_init_command()
398 if (!cd->writeable) in sr_init_command()
401 cd->cdi.media_written = 1; in sr_init_command()
462 SCpnt->transfersize = cd->device->sector_size; in sr_init_command()
476 static int sr_revalidate_disk(struct scsi_cd *cd) in sr_revalidate_disk() argument
481 if (scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr)) in sr_revalidate_disk()
483 sr_cd_check(&cd->cdi); in sr_revalidate_disk()
484 return get_sectorsize(cd); in sr_revalidate_disk()
489 struct scsi_cd *cd = scsi_cd(disk); in sr_block_open() local
490 struct scsi_device *sdev = cd->device; in sr_block_open()
493 if (scsi_device_get(cd->device)) in sr_block_open()
498 ret = sr_revalidate_disk(cd); in sr_block_open()
503 mutex_lock(&cd->lock); in sr_block_open()
504 ret = cdrom_open(&cd->cdi, mode); in sr_block_open()
505 mutex_unlock(&cd->lock); in sr_block_open()
509 scsi_device_put(cd->device); in sr_block_open()
515 struct scsi_cd *cd = scsi_cd(disk); in sr_block_release() local
517 mutex_lock(&cd->lock); in sr_block_release()
518 cdrom_release(&cd->cdi); in sr_block_release()
519 mutex_unlock(&cd->lock); in sr_block_release()
521 scsi_device_put(cd->device); in sr_block_release()
527 struct scsi_cd *cd = scsi_cd(bdev->bd_disk); in sr_block_ioctl() local
528 struct scsi_device *sdev = cd->device; in sr_block_ioctl()
535 mutex_lock(&cd->lock); in sr_block_ioctl()
545 ret = cdrom_ioctl(&cd->cdi, bdev, cmd, arg); in sr_block_ioctl()
554 mutex_unlock(&cd->lock); in sr_block_ioctl()
561 struct scsi_cd *cd = disk->private_data; in sr_block_check_events() local
563 if (atomic_read(&cd->device->disk_events_disable_depth)) in sr_block_check_events()
565 return cdrom_check_events(&cd->cdi, clearing); in sr_block_check_events()
570 struct scsi_cd *cd = disk->private_data; in sr_free_disk() local
576 unregister_cdrom(&cd->cdi); in sr_free_disk()
577 mutex_destroy(&cd->lock); in sr_free_disk()
578 kfree(cd); in sr_free_disk()
594 struct scsi_cd *cd = cdi->handle; in sr_open() local
595 struct scsi_device *sdev = cd->device; in sr_open()
615 struct scsi_cd *cd; in sr_probe() local
624 cd = kzalloc(sizeof(*cd), GFP_KERNEL); in sr_probe()
625 if (!cd) in sr_probe()
632 mutex_init(&cd->lock); in sr_probe()
656 cd->device = sdev; in sr_probe()
657 cd->disk = disk; in sr_probe()
658 cd->capacity = 0x1fffff; in sr_probe()
659 cd->device->changed = 1; /* force recheck CD type */ in sr_probe()
660 cd->media_present = 1; in sr_probe()
661 cd->use = 1; in sr_probe()
662 cd->readcd_known = 0; in sr_probe()
663 cd->readcd_cdda = 0; in sr_probe()
665 cd->cdi.ops = &sr_dops; in sr_probe()
666 cd->cdi.handle = cd; in sr_probe()
667 cd->cdi.mask = 0; in sr_probe()
668 cd->cdi.capacity = 1; in sr_probe()
669 sprintf(cd->cdi.name, "sr%d", minor); in sr_probe()
674 if (get_capabilities(cd)) in sr_probe()
676 sr_vendor_init(cd); in sr_probe()
678 set_capacity(disk, cd->capacity); in sr_probe()
679 disk->private_data = cd; in sr_probe()
681 if (register_cdrom(disk, &cd->cdi)) in sr_probe()
690 dev_set_drvdata(dev, cd); in sr_probe()
691 error = sr_revalidate_disk(cd); in sr_probe()
700 "Attached scsi CD-ROM %s\n", cd->cdi.name); in sr_probe()
701 scsi_autopm_put_device(cd->device); in sr_probe()
706 unregister_cdrom(&cd->cdi); in sr_probe()
713 mutex_destroy(&cd->lock); in sr_probe()
715 kfree(cd); in sr_probe()
722 static int get_sectorsize(struct scsi_cd *cd) in get_sectorsize() argument
724 struct request_queue *q = cd->device->request_queue; in get_sectorsize()
745 err = scsi_execute_cmd(cd->device, cmd, REQ_OP_DRV_IN, buffer, in get_sectorsize()
749 cd->capacity = 0x1fffff; in get_sectorsize()
754 cd->capacity = 1 + get_unaligned_be32(&buffer[0]); in get_sectorsize()
762 if (!cdrom_get_last_written(&cd->cdi, &last_written)) in get_sectorsize()
763 cd->capacity = max_t(long, cd->capacity, last_written); in get_sectorsize()
768 * HP 4020i CD-Recorder reports 2340 byte sectors in get_sectorsize()
769 * Philips CD-Writers report 2352 byte sectors in get_sectorsize()
779 cd->capacity *= 4; in get_sectorsize()
784 sr_printk(KERN_INFO, cd, in get_sectorsize()
786 cd->capacity = 0; in get_sectorsize()
789 cd->device->sector_size = sector_size; in get_sectorsize()
795 set_capacity(cd->disk, cd->capacity); in get_sectorsize()
806 static int get_capabilities(struct scsi_cd *cd) in get_capabilities() argument
830 sr_printk(KERN_ERR, cd, "out of memory.\n"); in get_capabilities()
835 scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr); in get_capabilities()
838 rc = scsi_mode_sense(cd->device, 0, 0x2a, 0, buffer, ms_len, in get_capabilities()
844 cd->cdi.speed = 1; in get_capabilities()
845 cd->cdi.mask |= (CDC_CD_R | CDC_CD_RW | CDC_DVD_R | in get_capabilities()
850 sr_printk(KERN_INFO, cd, "scsi-1 drive"); in get_capabilities()
855 cd->cdi.speed = get_unaligned_be16(&buffer[n + 8]) / 176; in get_capabilities()
856 cd->readcd_known = 1; in get_capabilities()
857 cd->readcd_cdda = buffer[n + 5] & 0x01; in get_capabilities()
859 sr_printk(KERN_INFO, cd, in get_capabilities()
862 cd->cdi.speed, in get_capabilities()
863 buffer[n + 3] & 0x01 ? "writer " : "", /* CD Writer */ in get_capabilities()
865 buffer[n + 2] & 0x02 ? "cd/rw " : "", /* can read rewriteable */ in get_capabilities()
871 cd->cdi.mask |= CDC_CLOSE_TRAY; in get_capabilities()
874 cd->cdi.mask |= CDC_DVD; in get_capabilities()
877 cd->cdi.mask |= CDC_DVD_RAM; in get_capabilities()
880 cd->cdi.mask |= CDC_DVD_R; in get_capabilities()
882 /* can't write CD-RW media */ in get_capabilities()
883 cd->cdi.mask |= CDC_CD_RW; in get_capabilities()
885 /* can't write CD-R media */ in get_capabilities()
886 cd->cdi.mask |= CDC_CD_R; in get_capabilities()
889 cd->cdi.mask |= CDC_OPEN_TRAY; in get_capabilities()
893 cd->cdi.capacity = in get_capabilities()
894 cdrom_number_of_slots(&cd->cdi); in get_capabilities()
895 if (cd->cdi.capacity <= 1) in get_capabilities()
897 cd->cdi.mask |= CDC_SELECT_DISC; in get_capabilities()
899 cd->cdi.mask |= CDC_CLOSE_TRAY; */ in get_capabilities()
902 * if DVD-RAM, MRW-W or CD-RW, we are randomly writable in get_capabilities()
904 if ((cd->cdi.mask & (CDC_DVD_RAM | CDC_MRW_W | CDC_RAM | CDC_CD_RW)) != in get_capabilities()
906 cd->writeable = 1; in get_capabilities()
915 * by the Uniform CD-ROM layer.
920 struct scsi_cd *cd = cdi->handle; in sr_packet() local
921 struct scsi_device *sdev = cd->device; in sr_packet()
929 sr_do_ioctl(cd, cgc); in sr_packet()
986 struct scsi_cd *cd = dev_get_drvdata(dev); in sr_remove() local
988 scsi_autopm_get_device(cd->device); in sr_remove()
990 del_gendisk(cd->disk); in sr_remove()
991 put_disk(cd->disk); in sr_remove()