2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* sr.c Copyright (C) 1992 David Giller
|
|
|
|
* Copyright (C) 1993, 1994, 1995, 1999 Eric Youngdale
|
|
|
|
*
|
|
|
|
* adapted from:
|
|
|
|
* sd.c Copyright (C) 1992 Drew Eckhardt
|
|
|
|
* Linux scsi disk driver by
|
|
|
|
* Drew Eckhardt <drew@colorado.edu>
|
|
|
|
*
|
|
|
|
* Modified by Eric Youngdale ericy@andante.org to
|
|
|
|
* add scatter-gather, multiple outstanding request, and other
|
|
|
|
* enhancements.
|
|
|
|
*
|
|
|
|
* Modified by Eric Youngdale eric@andante.org to support loadable
|
|
|
|
* low-level scsi drivers.
|
|
|
|
*
|
|
|
|
* Modified by Thomas Quinot thomas@melchior.cuivre.fdn.fr to
|
|
|
|
* provide auto-eject.
|
|
|
|
*
|
|
|
|
* Modified by Gerd Knorr <kraxel@cs.tu-berlin.de> to support the
|
|
|
|
* generic cdrom interface
|
|
|
|
*
|
|
|
|
* Modified by Jens Axboe <axboe@suse.de> - Uniform sr_packet()
|
|
|
|
* interface, capabilities probe additions, ioctl cleanups, etc.
|
|
|
|
*
|
|
|
|
* Modified by Richard Gooch <rgooch@atnf.csiro.au> to support devfs
|
|
|
|
*
|
|
|
|
* Modified by Jens Axboe <axboe@suse.de> - support DVD-RAM
|
|
|
|
* transparently and lose the GHOST hack
|
|
|
|
*
|
|
|
|
* Modified by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
|
|
|
|
* check resource allocation in sr_init and some cleanups
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/bio.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/cdrom.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/blkdev.h>
|
2006-01-11 15:16:10 +03:00
|
|
|
#include <linux/mutex.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
|
|
|
#include <linux/slab.h>
|
2013-01-23 11:09:31 +04:00
|
|
|
#include <linux/pm_runtime.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <asm/uaccess.h>
|
|
|
|
|
|
|
|
#include <scsi/scsi.h>
|
|
|
|
#include <scsi/scsi_dbg.h>
|
|
|
|
#include <scsi/scsi_device.h>
|
|
|
|
#include <scsi/scsi_driver.h>
|
2005-06-13 07:21:29 +04:00
|
|
|
#include <scsi/scsi_cmnd.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <scsi/scsi_eh.h>
|
|
|
|
#include <scsi/scsi_host.h>
|
|
|
|
#include <scsi/scsi_ioctl.h> /* For the door lock/unlock commands */
|
|
|
|
|
|
|
|
#include "scsi_logging.h"
|
|
|
|
#include "sr.h"
|
|
|
|
|
|
|
|
|
2006-03-08 11:14:20 +03:00
|
|
|
MODULE_DESCRIPTION("SCSI cdrom (sr) driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS_BLOCKDEV_MAJOR(SCSI_CDROM_MAJOR);
|
[SCSI] modalias for scsi devices
The following patch adds support for sysfs/uevent modalias
attribute for scsi devices (like disks, tapes, cdroms etc),
based on whatever current sd.c, sr.c, st.c and osst.c drivers
supports.
The modalias format is like this:
scsi:type-0x04
(for TYPE_WORM, handled by sr.c now).
Several comments.
o This hexadecimal type value is because all TYPE_XXX constants
in include/scsi/scsi.h are given in hex, but __stringify() will
not convert them to decimal (so it will NOT be scsi:type-4).
Since it does not really matter in which format it is, while
both modalias in module and modalias attribute match each other,
I descided to go for that 0x%02x format (and added a comment in
include/scsi/scsi.h to keep them that way), instead of changing
them all to decimal.
o There was no .uevent routine for SCSI bus. It might be a good
idea to add some more ueven environment variables in there.
o osst.c driver handles tapes too, like st.c, but only SOME tapes.
With this setup, hotplug scripts (or whatever is used by the
user) will try to load both st and osst modules for all SCSI
tapes found, because both modules have scsi:type-0x01 alias).
It is not harmful, but one extra module is no good either.
It is possible to solve this, by exporting more info in
modalias attribute, including vendor and device identification
strings, so that modalias becomes something like
scsi:type-0x12:vendor-Adaptec LTD:device-OnStream Tape Drive
and having that, match for all 3 attributes, not only device
type. But oh well, vendor and device strings may be large,
and they do contain spaces and whatnot.
So I left them for now, awaiting for comments first.
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
2006-10-27 16:02:37 +04:00
|
|
|
MODULE_ALIAS_SCSI_DEVICE(TYPE_ROM);
|
|
|
|
MODULE_ALIAS_SCSI_DEVICE(TYPE_WORM);
|
2006-03-08 11:14:20 +03:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
#define SR_DISKS 256
|
|
|
|
|
|
|
|
#define SR_CAPABILITIES \
|
|
|
|
(CDC_CLOSE_TRAY|CDC_OPEN_TRAY|CDC_LOCK|CDC_SELECT_SPEED| \
|
|
|
|
CDC_SELECT_DISC|CDC_MULTI_SESSION|CDC_MCN|CDC_MEDIA_CHANGED| \
|
2006-03-23 14:00:15 +03:00
|
|
|
CDC_PLAY_AUDIO|CDC_RESET|CDC_DRIVE_STATUS| \
|
2005-04-17 02:20:36 +04:00
|
|
|
CDC_CD_R|CDC_CD_RW|CDC_DVD|CDC_DVD_R|CDC_DVD_RAM|CDC_GENERIC_PACKET| \
|
|
|
|
CDC_MRW|CDC_MRW_W|CDC_RAM)
|
|
|
|
|
2010-06-02 16:28:52 +04:00
|
|
|
static DEFINE_MUTEX(sr_mutex);
|
2005-04-17 02:20:36 +04:00
|
|
|
static int sr_probe(struct device *);
|
|
|
|
static int sr_remove(struct device *);
|
Revert "scsi: revert "[SCSI] Get rid of scsi_cmnd->done""
This reverts commit ac40532ef0b8649e6f7f83859ea0de1c4ed08a19, which gets
us back the original cleanup of 6f5391c283d7fdcf24bf40786ea79061919d1e1d.
It turns out that the bug that was triggered by that commit was
apparently not actually triggered by that commit at all, and just the
testing conditions had changed enough to make it appear to be due to it.
The real problem seems to have been found by Peter Osterlund:
"pktcdvd sets it [block device size] when opening the /dev/pktcdvd
device, but when the drive is later opened as /dev/scd0, there is
nothing that sets it back. (Btw, 40944 is possible if the disk is a
CDRW that was formatted with "cdrwtool -m 10236".)
The problem is that pktcdvd opens the cd device in non-blocking mode
when pktsetup is run, and doesn't close it again until pktsetup -d is
run. The effect is that if you meanwhile open the cd device,
blkdev.c:do_open() doesn't call bd_set_size() because
bdev->bd_openers is non-zero."
In particular, to repeat the bug (regardless of whether commit
6f5391c283d7fdcf24bf40786ea79061919d1e1d is applied or not):
" 1. Start with an empty drive.
2. pktsetup 0 /dev/scd0
3. Insert a CD containing an isofs filesystem.
4. mount /dev/pktcdvd/0 /mnt/tmp
5. umount /mnt/tmp
6. Press the eject button.
7. Insert a DVD containing a non-writable filesystem.
8. mount /dev/scd0 /mnt/tmp
9. find /mnt/tmp -type f -print0 | xargs -0 sha1sum >/dev/null
10. If the DVD contains data beyond the physical size of a CD, you
get I/O errors in the terminal, and dmesg reports lots of
"attempt to access beyond end of device" errors."
which in turn is because the nested open after the media change won't
cause the size to be set properly (because the original open still holds
the block device, and we only do the bd_set_size() when we don't have
other people holding the device open).
The proper fix for that is probably to just do something like
bdev->bd_inode->i_size = (loff_t)get_capacity(disk)<<9;
in fs/block_dev.c:do_open() even for the cases where we're not the
original opener (but *not* call bd_set_size(), since that will also
change the block size of the device).
Cc: Peter Osterlund <petero2@telia.com>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: Matthew Wilcox <matthew@wil.cx>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-01-06 21:17:12 +03:00
|
|
|
static int sr_done(struct scsi_cmnd *);
|
2013-01-23 11:09:31 +04:00
|
|
|
static int sr_runtime_suspend(struct device *dev);
|
|
|
|
|
|
|
|
static struct dev_pm_ops sr_pm_ops = {
|
|
|
|
.runtime_suspend = sr_runtime_suspend,
|
|
|
|
};
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
static struct scsi_driver sr_template = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.gendrv = {
|
|
|
|
.name = "sr",
|
|
|
|
.probe = sr_probe,
|
|
|
|
.remove = sr_remove,
|
2013-01-23 11:09:31 +04:00
|
|
|
.pm = &sr_pm_ops,
|
2005-04-17 02:20:36 +04:00
|
|
|
},
|
Revert "scsi: revert "[SCSI] Get rid of scsi_cmnd->done""
This reverts commit ac40532ef0b8649e6f7f83859ea0de1c4ed08a19, which gets
us back the original cleanup of 6f5391c283d7fdcf24bf40786ea79061919d1e1d.
It turns out that the bug that was triggered by that commit was
apparently not actually triggered by that commit at all, and just the
testing conditions had changed enough to make it appear to be due to it.
The real problem seems to have been found by Peter Osterlund:
"pktcdvd sets it [block device size] when opening the /dev/pktcdvd
device, but when the drive is later opened as /dev/scd0, there is
nothing that sets it back. (Btw, 40944 is possible if the disk is a
CDRW that was formatted with "cdrwtool -m 10236".)
The problem is that pktcdvd opens the cd device in non-blocking mode
when pktsetup is run, and doesn't close it again until pktsetup -d is
run. The effect is that if you meanwhile open the cd device,
blkdev.c:do_open() doesn't call bd_set_size() because
bdev->bd_openers is non-zero."
In particular, to repeat the bug (regardless of whether commit
6f5391c283d7fdcf24bf40786ea79061919d1e1d is applied or not):
" 1. Start with an empty drive.
2. pktsetup 0 /dev/scd0
3. Insert a CD containing an isofs filesystem.
4. mount /dev/pktcdvd/0 /mnt/tmp
5. umount /mnt/tmp
6. Press the eject button.
7. Insert a DVD containing a non-writable filesystem.
8. mount /dev/scd0 /mnt/tmp
9. find /mnt/tmp -type f -print0 | xargs -0 sha1sum >/dev/null
10. If the DVD contains data beyond the physical size of a CD, you
get I/O errors in the terminal, and dmesg reports lots of
"attempt to access beyond end of device" errors."
which in turn is because the nested open after the media change won't
cause the size to be set properly (because the original open still holds
the block device, and we only do the bd_set_size() when we don't have
other people holding the device open).
The proper fix for that is probably to just do something like
bdev->bd_inode->i_size = (loff_t)get_capacity(disk)<<9;
in fs/block_dev.c:do_open() even for the cases where we're not the
original opener (but *not* call bd_set_size(), since that will also
change the block size of the device).
Cc: Peter Osterlund <petero2@telia.com>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: Matthew Wilcox <matthew@wil.cx>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-01-06 21:17:12 +03:00
|
|
|
.done = sr_done,
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static unsigned long sr_index_bits[SR_DISKS / BITS_PER_LONG];
|
|
|
|
static DEFINE_SPINLOCK(sr_index_lock);
|
|
|
|
|
|
|
|
/* This semaphore is used to mediate the 0->1 reference get in the
|
|
|
|
* face of object destruction (i.e. we can't allow a get on an
|
|
|
|
* object after last put) */
|
2006-01-11 15:16:10 +03:00
|
|
|
static DEFINE_MUTEX(sr_ref_mutex);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
static int sr_open(struct cdrom_device_info *, int);
|
|
|
|
static void sr_release(struct cdrom_device_info *);
|
|
|
|
|
|
|
|
static void get_sectorsize(struct scsi_cd *);
|
|
|
|
static void get_capabilities(struct scsi_cd *);
|
|
|
|
|
2010-12-16 19:52:17 +03:00
|
|
|
static unsigned int sr_check_events(struct cdrom_device_info *cdi,
|
|
|
|
unsigned int clearing, int slot);
|
2005-04-17 02:20:36 +04:00
|
|
|
static int sr_packet(struct cdrom_device_info *, struct packet_command *);
|
|
|
|
|
|
|
|
static struct cdrom_device_ops sr_dops = {
|
|
|
|
.open = sr_open,
|
|
|
|
.release = sr_release,
|
|
|
|
.drive_status = sr_drive_status,
|
2010-12-16 19:52:17 +03:00
|
|
|
.check_events = sr_check_events,
|
2005-04-17 02:20:36 +04:00
|
|
|
.tray_move = sr_tray_move,
|
|
|
|
.lock_door = sr_lock_door,
|
|
|
|
.select_speed = sr_select_speed,
|
|
|
|
.get_last_session = sr_get_last_session,
|
|
|
|
.get_mcn = sr_get_mcn,
|
|
|
|
.reset = sr_reset,
|
|
|
|
.audio_ioctl = sr_audio_ioctl,
|
|
|
|
.capability = SR_CAPABILITIES,
|
|
|
|
.generic_packet = sr_packet,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void sr_kref_release(struct kref *kref);
|
|
|
|
|
|
|
|
static inline struct scsi_cd *scsi_cd(struct gendisk *disk)
|
|
|
|
{
|
|
|
|
return container_of(disk->private_data, struct scsi_cd, driver);
|
|
|
|
}
|
|
|
|
|
2013-01-23 11:09:31 +04:00
|
|
|
static int sr_runtime_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct scsi_cd *cd = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
if (cd->media_present)
|
|
|
|
return -EBUSY;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* The get and put routines for the struct scsi_cd. Note this entity
|
|
|
|
* has a scsi_device pointer and owns a reference to this.
|
|
|
|
*/
|
|
|
|
static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk)
|
|
|
|
{
|
|
|
|
struct scsi_cd *cd = NULL;
|
|
|
|
|
2006-01-11 15:16:10 +03:00
|
|
|
mutex_lock(&sr_ref_mutex);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (disk->private_data == NULL)
|
|
|
|
goto out;
|
|
|
|
cd = scsi_cd(disk);
|
|
|
|
kref_get(&cd->kref);
|
|
|
|
if (scsi_device_get(cd->device))
|
|
|
|
goto out_put;
|
2013-01-23 11:09:31 +04:00
|
|
|
if (!scsi_autopm_get_device(cd->device))
|
|
|
|
goto out;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
out_put:
|
|
|
|
kref_put(&cd->kref, sr_kref_release);
|
|
|
|
cd = NULL;
|
|
|
|
out:
|
2006-01-11 15:16:10 +03:00
|
|
|
mutex_unlock(&sr_ref_mutex);
|
2005-04-17 02:20:36 +04:00
|
|
|
return cd;
|
|
|
|
}
|
|
|
|
|
2006-01-15 00:20:43 +03:00
|
|
|
static void scsi_cd_put(struct scsi_cd *cd)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct scsi_device *sdev = cd->device;
|
|
|
|
|
2006-01-11 15:16:10 +03:00
|
|
|
mutex_lock(&sr_ref_mutex);
|
2005-04-17 02:20:36 +04:00
|
|
|
kref_put(&cd->kref, sr_kref_release);
|
2013-01-23 11:09:31 +04:00
|
|
|
scsi_autopm_put_device(sdev);
|
2005-04-17 02:20:36 +04:00
|
|
|
scsi_device_put(sdev);
|
2006-01-11 15:16:10 +03:00
|
|
|
mutex_unlock(&sr_ref_mutex);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2010-12-16 19:52:17 +03:00
|
|
|
static unsigned int sr_get_events(struct scsi_device *sdev)
|
|
|
|
{
|
|
|
|
u8 buf[8];
|
|
|
|
u8 cmd[] = { GET_EVENT_STATUS_NOTIFICATION,
|
|
|
|
1, /* polled */
|
|
|
|
0, 0, /* reserved */
|
|
|
|
1 << 4, /* notification class: media */
|
|
|
|
0, 0, /* reserved */
|
|
|
|
0, sizeof(buf), /* allocation length */
|
|
|
|
0, /* control */
|
|
|
|
};
|
|
|
|
struct event_header *eh = (void *)buf;
|
|
|
|
struct media_event_desc *med = (void *)(buf + 4);
|
|
|
|
struct scsi_sense_hdr sshdr;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
result = scsi_execute_req(sdev, cmd, DMA_FROM_DEVICE, buf, sizeof(buf),
|
|
|
|
&sshdr, SR_TIMEOUT, MAX_RETRIES, NULL);
|
|
|
|
if (scsi_sense_valid(&sshdr) && sshdr.sense_key == UNIT_ATTENTION)
|
|
|
|
return DISK_EVENT_MEDIA_CHANGE;
|
|
|
|
|
|
|
|
if (result || be16_to_cpu(eh->data_len) < sizeof(*med))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (eh->nea || eh->notification_class != 0x4)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (med->media_event_code == 1)
|
|
|
|
return DISK_EVENT_EJECT_REQUEST;
|
|
|
|
else if (med->media_event_code == 2)
|
|
|
|
return DISK_EVENT_MEDIA_CHANGE;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
2010-12-16 19:52:17 +03:00
|
|
|
* This function checks to see if the media has been changed or eject
|
|
|
|
* button has been pressed. It is possible that we have already
|
|
|
|
* sensed a change, or the drive may have sensed one and not yet
|
|
|
|
* reported it. The past events are accumulated in sdev->changed and
|
|
|
|
* returned together with the current state.
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
2010-12-16 19:52:17 +03:00
|
|
|
static unsigned int sr_check_events(struct cdrom_device_info *cdi,
|
|
|
|
unsigned int clearing, int slot)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct scsi_cd *cd = cdi->handle;
|
2010-12-16 19:52:17 +03:00
|
|
|
bool last_present;
|
|
|
|
struct scsi_sense_hdr sshdr;
|
|
|
|
unsigned int events;
|
|
|
|
int ret;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-12-16 19:52:17 +03:00
|
|
|
/* no changer support */
|
|
|
|
if (CDSL_CURRENT != slot)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
events = sr_get_events(cd->device);
|
2011-06-30 17:03:48 +04:00
|
|
|
cd->get_event_changed |= events & DISK_EVENT_MEDIA_CHANGE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If earlier GET_EVENT_STATUS_NOTIFICATION and TUR did not agree
|
|
|
|
* for several times in a row. We rely on TUR only for this likely
|
|
|
|
* broken device, to prevent generating incorrect media changed
|
|
|
|
* events for every open().
|
|
|
|
*/
|
|
|
|
if (cd->ignore_get_event) {
|
|
|
|
events &= ~DISK_EVENT_MEDIA_CHANGE;
|
|
|
|
goto do_tur;
|
|
|
|
}
|
|
|
|
|
2010-12-16 19:52:17 +03:00
|
|
|
/*
|
|
|
|
* GET_EVENT_STATUS_NOTIFICATION is enough unless MEDIA_CHANGE
|
|
|
|
* is being cleared. Note that there are devices which hang
|
|
|
|
* if asked to execute TUR repeatedly.
|
|
|
|
*/
|
2011-06-30 17:03:48 +04:00
|
|
|
if (cd->device->changed) {
|
|
|
|
events |= DISK_EVENT_MEDIA_CHANGE;
|
|
|
|
cd->device->changed = 0;
|
|
|
|
cd->tur_changed = true;
|
|
|
|
}
|
2010-12-16 19:52:17 +03:00
|
|
|
|
2011-06-30 17:03:48 +04:00
|
|
|
if (!(clearing & DISK_EVENT_MEDIA_CHANGE))
|
|
|
|
return events;
|
|
|
|
do_tur:
|
2010-12-16 19:52:17 +03:00
|
|
|
/* let's see whether the media is there with TUR */
|
|
|
|
last_present = cd->media_present;
|
|
|
|
ret = scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-12-09 13:18:42 +03:00
|
|
|
/*
|
|
|
|
* Media is considered to be present if TUR succeeds or fails with
|
|
|
|
* sense data indicating something other than media-not-present
|
|
|
|
* (ASC 0x3a).
|
|
|
|
*/
|
2010-12-16 19:52:17 +03:00
|
|
|
cd->media_present = scsi_status_is_good(ret) ||
|
|
|
|
(scsi_sense_valid(&sshdr) && sshdr.asc != 0x3a);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-12-16 19:52:17 +03:00
|
|
|
if (last_present != cd->media_present)
|
2011-06-30 17:03:48 +04:00
|
|
|
cd->device->changed = 1;
|
|
|
|
|
2010-12-16 19:52:17 +03:00
|
|
|
if (cd->device->changed) {
|
|
|
|
events |= DISK_EVENT_MEDIA_CHANGE;
|
|
|
|
cd->device->changed = 0;
|
2011-06-30 17:03:48 +04:00
|
|
|
cd->tur_changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cd->ignore_get_event)
|
|
|
|
return events;
|
|
|
|
|
|
|
|
/* check whether GET_EVENT is reporting spurious MEDIA_CHANGE */
|
|
|
|
if (!cd->tur_changed) {
|
|
|
|
if (cd->get_event_changed) {
|
|
|
|
if (cd->tur_mismatch++ > 8) {
|
|
|
|
sdev_printk(KERN_WARNING, cd->device,
|
|
|
|
"GET_EVENT and TUR disagree continuously, suppress GET_EVENT events\n");
|
|
|
|
cd->ignore_get_event = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cd->tur_mismatch = 0;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2011-06-30 17:03:48 +04:00
|
|
|
cd->tur_changed = false;
|
|
|
|
cd->get_event_changed = false;
|
2007-08-14 16:10:39 +04:00
|
|
|
|
2010-12-16 19:52:17 +03:00
|
|
|
return events;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2010-12-16 19:52:17 +03:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
Revert "scsi: revert "[SCSI] Get rid of scsi_cmnd->done""
This reverts commit ac40532ef0b8649e6f7f83859ea0de1c4ed08a19, which gets
us back the original cleanup of 6f5391c283d7fdcf24bf40786ea79061919d1e1d.
It turns out that the bug that was triggered by that commit was
apparently not actually triggered by that commit at all, and just the
testing conditions had changed enough to make it appear to be due to it.
The real problem seems to have been found by Peter Osterlund:
"pktcdvd sets it [block device size] when opening the /dev/pktcdvd
device, but when the drive is later opened as /dev/scd0, there is
nothing that sets it back. (Btw, 40944 is possible if the disk is a
CDRW that was formatted with "cdrwtool -m 10236".)
The problem is that pktcdvd opens the cd device in non-blocking mode
when pktsetup is run, and doesn't close it again until pktsetup -d is
run. The effect is that if you meanwhile open the cd device,
blkdev.c:do_open() doesn't call bd_set_size() because
bdev->bd_openers is non-zero."
In particular, to repeat the bug (regardless of whether commit
6f5391c283d7fdcf24bf40786ea79061919d1e1d is applied or not):
" 1. Start with an empty drive.
2. pktsetup 0 /dev/scd0
3. Insert a CD containing an isofs filesystem.
4. mount /dev/pktcdvd/0 /mnt/tmp
5. umount /mnt/tmp
6. Press the eject button.
7. Insert a DVD containing a non-writable filesystem.
8. mount /dev/scd0 /mnt/tmp
9. find /mnt/tmp -type f -print0 | xargs -0 sha1sum >/dev/null
10. If the DVD contains data beyond the physical size of a CD, you
get I/O errors in the terminal, and dmesg reports lots of
"attempt to access beyond end of device" errors."
which in turn is because the nested open after the media change won't
cause the size to be set properly (because the original open still holds
the block device, and we only do the bd_set_size() when we don't have
other people holding the device open).
The proper fix for that is probably to just do something like
bdev->bd_inode->i_size = (loff_t)get_capacity(disk)<<9;
in fs/block_dev.c:do_open() even for the cases where we're not the
original opener (but *not* call bd_set_size(), since that will also
change the block size of the device).
Cc: Peter Osterlund <petero2@telia.com>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: Matthew Wilcox <matthew@wil.cx>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-01-06 21:17:12 +03:00
|
|
|
* sr_done is the interrupt routine for the device driver.
|
2005-04-17 02:20:36 +04:00
|
|
|
*
|
Revert "scsi: revert "[SCSI] Get rid of scsi_cmnd->done""
This reverts commit ac40532ef0b8649e6f7f83859ea0de1c4ed08a19, which gets
us back the original cleanup of 6f5391c283d7fdcf24bf40786ea79061919d1e1d.
It turns out that the bug that was triggered by that commit was
apparently not actually triggered by that commit at all, and just the
testing conditions had changed enough to make it appear to be due to it.
The real problem seems to have been found by Peter Osterlund:
"pktcdvd sets it [block device size] when opening the /dev/pktcdvd
device, but when the drive is later opened as /dev/scd0, there is
nothing that sets it back. (Btw, 40944 is possible if the disk is a
CDRW that was formatted with "cdrwtool -m 10236".)
The problem is that pktcdvd opens the cd device in non-blocking mode
when pktsetup is run, and doesn't close it again until pktsetup -d is
run. The effect is that if you meanwhile open the cd device,
blkdev.c:do_open() doesn't call bd_set_size() because
bdev->bd_openers is non-zero."
In particular, to repeat the bug (regardless of whether commit
6f5391c283d7fdcf24bf40786ea79061919d1e1d is applied or not):
" 1. Start with an empty drive.
2. pktsetup 0 /dev/scd0
3. Insert a CD containing an isofs filesystem.
4. mount /dev/pktcdvd/0 /mnt/tmp
5. umount /mnt/tmp
6. Press the eject button.
7. Insert a DVD containing a non-writable filesystem.
8. mount /dev/scd0 /mnt/tmp
9. find /mnt/tmp -type f -print0 | xargs -0 sha1sum >/dev/null
10. If the DVD contains data beyond the physical size of a CD, you
get I/O errors in the terminal, and dmesg reports lots of
"attempt to access beyond end of device" errors."
which in turn is because the nested open after the media change won't
cause the size to be set properly (because the original open still holds
the block device, and we only do the bd_set_size() when we don't have
other people holding the device open).
The proper fix for that is probably to just do something like
bdev->bd_inode->i_size = (loff_t)get_capacity(disk)<<9;
in fs/block_dev.c:do_open() even for the cases where we're not the
original opener (but *not* call bd_set_size(), since that will also
change the block size of the device).
Cc: Peter Osterlund <petero2@telia.com>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: Matthew Wilcox <matthew@wil.cx>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-01-06 21:17:12 +03:00
|
|
|
* It will be notified on the end of a SCSI read / write, and will take one
|
2005-04-17 02:20:36 +04:00
|
|
|
* of several actions based on success or failure.
|
|
|
|
*/
|
Revert "scsi: revert "[SCSI] Get rid of scsi_cmnd->done""
This reverts commit ac40532ef0b8649e6f7f83859ea0de1c4ed08a19, which gets
us back the original cleanup of 6f5391c283d7fdcf24bf40786ea79061919d1e1d.
It turns out that the bug that was triggered by that commit was
apparently not actually triggered by that commit at all, and just the
testing conditions had changed enough to make it appear to be due to it.
The real problem seems to have been found by Peter Osterlund:
"pktcdvd sets it [block device size] when opening the /dev/pktcdvd
device, but when the drive is later opened as /dev/scd0, there is
nothing that sets it back. (Btw, 40944 is possible if the disk is a
CDRW that was formatted with "cdrwtool -m 10236".)
The problem is that pktcdvd opens the cd device in non-blocking mode
when pktsetup is run, and doesn't close it again until pktsetup -d is
run. The effect is that if you meanwhile open the cd device,
blkdev.c:do_open() doesn't call bd_set_size() because
bdev->bd_openers is non-zero."
In particular, to repeat the bug (regardless of whether commit
6f5391c283d7fdcf24bf40786ea79061919d1e1d is applied or not):
" 1. Start with an empty drive.
2. pktsetup 0 /dev/scd0
3. Insert a CD containing an isofs filesystem.
4. mount /dev/pktcdvd/0 /mnt/tmp
5. umount /mnt/tmp
6. Press the eject button.
7. Insert a DVD containing a non-writable filesystem.
8. mount /dev/scd0 /mnt/tmp
9. find /mnt/tmp -type f -print0 | xargs -0 sha1sum >/dev/null
10. If the DVD contains data beyond the physical size of a CD, you
get I/O errors in the terminal, and dmesg reports lots of
"attempt to access beyond end of device" errors."
which in turn is because the nested open after the media change won't
cause the size to be set properly (because the original open still holds
the block device, and we only do the bd_set_size() when we don't have
other people holding the device open).
The proper fix for that is probably to just do something like
bdev->bd_inode->i_size = (loff_t)get_capacity(disk)<<9;
in fs/block_dev.c:do_open() even for the cases where we're not the
original opener (but *not* call bd_set_size(), since that will also
change the block size of the device).
Cc: Peter Osterlund <petero2@telia.com>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: Matthew Wilcox <matthew@wil.cx>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-01-06 21:17:12 +03:00
|
|
|
static int sr_done(struct scsi_cmnd *SCpnt)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
int result = SCpnt->result;
|
2007-12-13 14:47:40 +03:00
|
|
|
int this_count = scsi_bufflen(SCpnt);
|
2005-04-17 02:20:36 +04:00
|
|
|
int good_bytes = (result == 0 ? this_count : 0);
|
|
|
|
int block_sectors = 0;
|
|
|
|
long error_sector;
|
|
|
|
struct scsi_cd *cd = scsi_cd(SCpnt->request->rq_disk);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
printk("sr.c done: %x\n", result);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle MEDIUM ERRORs or VOLUME OVERFLOWs that indicate partial
|
|
|
|
* success. Since this is a relatively rare error condition, no
|
|
|
|
* care is taken to avoid unnecessary additional work such as
|
|
|
|
* memcpy's that could be avoided.
|
|
|
|
*/
|
|
|
|
if (driver_byte(result) != 0 && /* An error occurred */
|
|
|
|
(SCpnt->sense_buffer[0] & 0x7f) == 0x70) { /* Sense current */
|
|
|
|
switch (SCpnt->sense_buffer[2]) {
|
|
|
|
case MEDIUM_ERROR:
|
|
|
|
case VOLUME_OVERFLOW:
|
|
|
|
case ILLEGAL_REQUEST:
|
|
|
|
if (!(SCpnt->sense_buffer[0] & 0x90))
|
|
|
|
break;
|
|
|
|
error_sector = (SCpnt->sense_buffer[3] << 24) |
|
|
|
|
(SCpnt->sense_buffer[4] << 16) |
|
|
|
|
(SCpnt->sense_buffer[5] << 8) |
|
|
|
|
SCpnt->sense_buffer[6];
|
|
|
|
if (SCpnt->request->bio != NULL)
|
|
|
|
block_sectors =
|
|
|
|
bio_sectors(SCpnt->request->bio);
|
|
|
|
if (block_sectors < 4)
|
|
|
|
block_sectors = 4;
|
|
|
|
if (cd->device->sector_size == 2048)
|
|
|
|
error_sector <<= 2;
|
|
|
|
error_sector &= ~(block_sectors - 1);
|
2009-05-07 17:24:39 +04:00
|
|
|
good_bytes = (error_sector -
|
|
|
|
blk_rq_pos(SCpnt->request)) << 9;
|
2005-04-17 02:20:36 +04:00
|
|
|
if (good_bytes < 0 || good_bytes >= this_count)
|
|
|
|
good_bytes = 0;
|
|
|
|
/*
|
|
|
|
* The SCSI specification allows for the value
|
|
|
|
* returned by READ CAPACITY to be up to 75 2K
|
|
|
|
* sectors past the last readable block.
|
|
|
|
* Therefore, if we hit a medium error within the
|
|
|
|
* last 75 2K sectors, we decrease the saved size
|
|
|
|
* value.
|
|
|
|
*/
|
|
|
|
if (error_sector < get_capacity(cd->disk) &&
|
|
|
|
cd->capacity - error_sector < 4 * 75)
|
|
|
|
set_capacity(cd->disk, error_sector);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RECOVERED_ERROR:
|
|
|
|
good_bytes = this_count;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Revert "scsi: revert "[SCSI] Get rid of scsi_cmnd->done""
This reverts commit ac40532ef0b8649e6f7f83859ea0de1c4ed08a19, which gets
us back the original cleanup of 6f5391c283d7fdcf24bf40786ea79061919d1e1d.
It turns out that the bug that was triggered by that commit was
apparently not actually triggered by that commit at all, and just the
testing conditions had changed enough to make it appear to be due to it.
The real problem seems to have been found by Peter Osterlund:
"pktcdvd sets it [block device size] when opening the /dev/pktcdvd
device, but when the drive is later opened as /dev/scd0, there is
nothing that sets it back. (Btw, 40944 is possible if the disk is a
CDRW that was formatted with "cdrwtool -m 10236".)
The problem is that pktcdvd opens the cd device in non-blocking mode
when pktsetup is run, and doesn't close it again until pktsetup -d is
run. The effect is that if you meanwhile open the cd device,
blkdev.c:do_open() doesn't call bd_set_size() because
bdev->bd_openers is non-zero."
In particular, to repeat the bug (regardless of whether commit
6f5391c283d7fdcf24bf40786ea79061919d1e1d is applied or not):
" 1. Start with an empty drive.
2. pktsetup 0 /dev/scd0
3. Insert a CD containing an isofs filesystem.
4. mount /dev/pktcdvd/0 /mnt/tmp
5. umount /mnt/tmp
6. Press the eject button.
7. Insert a DVD containing a non-writable filesystem.
8. mount /dev/scd0 /mnt/tmp
9. find /mnt/tmp -type f -print0 | xargs -0 sha1sum >/dev/null
10. If the DVD contains data beyond the physical size of a CD, you
get I/O errors in the terminal, and dmesg reports lots of
"attempt to access beyond end of device" errors."
which in turn is because the nested open after the media change won't
cause the size to be set properly (because the original open still holds
the block device, and we only do the bd_set_size() when we don't have
other people holding the device open).
The proper fix for that is probably to just do something like
bdev->bd_inode->i_size = (loff_t)get_capacity(disk)<<9;
in fs/block_dev.c:do_open() even for the cases where we're not the
original opener (but *not* call bd_set_size(), since that will also
change the block size of the device).
Cc: Peter Osterlund <petero2@telia.com>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: Matthew Wilcox <matthew@wil.cx>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-01-06 21:17:12 +03:00
|
|
|
return good_bytes;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2007-08-04 19:06:25 +04:00
|
|
|
static int sr_prep_fn(struct request_queue *q, struct request *rq)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2008-09-14 16:55:09 +04:00
|
|
|
int block = 0, this_count, s_size;
|
2007-08-04 19:06:25 +04:00
|
|
|
struct scsi_cd *cd;
|
|
|
|
struct scsi_cmnd *SCpnt;
|
|
|
|
struct scsi_device *sdp = q->queuedata;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (rq->cmd_type == REQ_TYPE_BLOCK_PC) {
|
|
|
|
ret = scsi_setup_blk_pc_cmnd(sdp, rq);
|
|
|
|
goto out;
|
|
|
|
} else if (rq->cmd_type != REQ_TYPE_FS) {
|
|
|
|
ret = BLKPREP_KILL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
ret = scsi_setup_fs_cmnd(sdp, rq);
|
|
|
|
if (ret != BLKPREP_OK)
|
|
|
|
goto out;
|
|
|
|
SCpnt = rq->special;
|
|
|
|
cd = scsi_cd(rq->rq_disk);
|
|
|
|
|
|
|
|
/* from here on until we're complete, any goto out
|
|
|
|
* is used for a killable error condition */
|
|
|
|
ret = BLKPREP_KILL;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
SCSI_LOG_HLQUEUE(1, printk("Doing sr request, dev = %s, block = %d\n",
|
|
|
|
cd->disk->disk_name, block));
|
|
|
|
|
|
|
|
if (!cd->device || !scsi_device_online(cd->device)) {
|
2009-05-07 17:24:39 +04:00
|
|
|
SCSI_LOG_HLQUEUE(2, printk("Finishing %u sectors\n",
|
|
|
|
blk_rq_sectors(rq)));
|
2005-04-17 02:20:36 +04:00
|
|
|
SCSI_LOG_HLQUEUE(2, printk("Retry with 0x%p\n", SCpnt));
|
2007-08-04 19:06:25 +04:00
|
|
|
goto out;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cd->device->changed) {
|
|
|
|
/*
|
|
|
|
* quietly refuse to do anything to a changed disc until the
|
|
|
|
* changed bit has been reset
|
|
|
|
*/
|
2007-08-04 19:06:25 +04:00
|
|
|
goto out;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we do lazy blocksize switching (when reading XA sectors,
|
|
|
|
* see CDROMREADMODE2 ioctl)
|
|
|
|
*/
|
|
|
|
s_size = cd->device->sector_size;
|
|
|
|
if (s_size > 2048) {
|
|
|
|
if (!in_interrupt())
|
|
|
|
sr_set_blocklength(cd, 2048);
|
|
|
|
else
|
|
|
|
printk("sr: can't switch blocksize: in interrupt\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s_size != 512 && s_size != 1024 && s_size != 2048) {
|
2005-10-25 02:04:06 +04:00
|
|
|
scmd_printk(KERN_ERR, SCpnt, "bad sector size %d\n", s_size);
|
2007-08-04 19:06:25 +04:00
|
|
|
goto out;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2007-08-04 19:06:25 +04:00
|
|
|
if (rq_data_dir(rq) == WRITE) {
|
2005-04-17 02:20:36 +04:00
|
|
|
if (!cd->device->writeable)
|
2007-08-04 19:06:25 +04:00
|
|
|
goto out;
|
2005-04-17 02:20:36 +04:00
|
|
|
SCpnt->cmnd[0] = WRITE_10;
|
|
|
|
SCpnt->sc_data_direction = DMA_TO_DEVICE;
|
|
|
|
cd->cdi.media_written = 1;
|
2007-08-04 19:06:25 +04:00
|
|
|
} else if (rq_data_dir(rq) == READ) {
|
2005-04-17 02:20:36 +04:00
|
|
|
SCpnt->cmnd[0] = READ_10;
|
|
|
|
SCpnt->sc_data_direction = DMA_FROM_DEVICE;
|
|
|
|
} else {
|
2007-08-04 19:06:25 +04:00
|
|
|
blk_dump_rq_flags(rq, "Unknown sr command");
|
|
|
|
goto out;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2007-12-13 14:47:40 +03:00
|
|
|
struct scatterlist *sg;
|
|
|
|
int i, size = 0, sg_count = scsi_sg_count(SCpnt);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2007-12-13 14:47:40 +03:00
|
|
|
scsi_for_each_sg(SCpnt, sg, sg_count, i)
|
|
|
|
size += sg->length;
|
|
|
|
|
|
|
|
if (size != scsi_bufflen(SCpnt)) {
|
2005-10-25 02:04:06 +04:00
|
|
|
scmd_printk(KERN_ERR, SCpnt,
|
|
|
|
"mismatch count %d, bytes %d\n",
|
2007-12-13 14:47:40 +03:00
|
|
|
size, scsi_bufflen(SCpnt));
|
|
|
|
if (scsi_bufflen(SCpnt) > size)
|
|
|
|
SCpnt->sdb.length = size;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* request doesn't start on hw block boundary, add scatter pads
|
|
|
|
*/
|
2009-05-07 17:24:39 +04:00
|
|
|
if (((unsigned int)blk_rq_pos(rq) % (s_size >> 9)) ||
|
2007-12-13 14:47:40 +03:00
|
|
|
(scsi_bufflen(SCpnt) % s_size)) {
|
2005-10-25 02:04:06 +04:00
|
|
|
scmd_printk(KERN_NOTICE, SCpnt, "unaligned transfer\n");
|
2007-08-04 19:06:25 +04:00
|
|
|
goto out;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2007-12-13 14:47:40 +03:00
|
|
|
this_count = (scsi_bufflen(SCpnt) >> 9) / (s_size >> 9);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
|
2009-05-07 17:24:39 +04:00
|
|
|
SCSI_LOG_HLQUEUE(2, printk("%s : %s %d/%u 512 byte blocks.\n",
|
2005-04-17 02:20:36 +04:00
|
|
|
cd->cdi.name,
|
2007-08-04 19:06:25 +04:00
|
|
|
(rq_data_dir(rq) == WRITE) ?
|
2005-04-17 02:20:36 +04:00
|
|
|
"writing" : "reading",
|
2009-05-07 17:24:39 +04:00
|
|
|
this_count, blk_rq_sectors(rq)));
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
SCpnt->cmnd[1] = 0;
|
2009-05-07 17:24:39 +04:00
|
|
|
block = (unsigned int)blk_rq_pos(rq) / (s_size >> 9);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (this_count > 0xffff) {
|
|
|
|
this_count = 0xffff;
|
2007-12-13 14:47:40 +03:00
|
|
|
SCpnt->sdb.length = this_count * s_size;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
SCpnt->cmnd[2] = (unsigned char) (block >> 24) & 0xff;
|
|
|
|
SCpnt->cmnd[3] = (unsigned char) (block >> 16) & 0xff;
|
|
|
|
SCpnt->cmnd[4] = (unsigned char) (block >> 8) & 0xff;
|
|
|
|
SCpnt->cmnd[5] = (unsigned char) block & 0xff;
|
|
|
|
SCpnt->cmnd[6] = SCpnt->cmnd[9] = 0;
|
|
|
|
SCpnt->cmnd[7] = (unsigned char) (this_count >> 8) & 0xff;
|
|
|
|
SCpnt->cmnd[8] = (unsigned char) this_count & 0xff;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We shouldn't disconnect in the middle of a sector, so with a dumb
|
|
|
|
* host adapter, it's safe to assume that we can at least transfer
|
|
|
|
* this many bytes between each connect / disconnect.
|
|
|
|
*/
|
|
|
|
SCpnt->transfersize = cd->device->sector_size;
|
|
|
|
SCpnt->underflow = this_count << 9;
|
|
|
|
SCpnt->allowed = MAX_RETRIES;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This indicates that the command is ready from our end to be
|
|
|
|
* queued.
|
|
|
|
*/
|
2007-08-04 19:06:25 +04:00
|
|
|
ret = BLKPREP_OK;
|
|
|
|
out:
|
|
|
|
return scsi_prep_return(q, rq, ret);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2008-03-02 18:41:28 +03:00
|
|
|
static int sr_block_open(struct block_device *bdev, fmode_t mode)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2010-08-07 20:25:34 +04:00
|
|
|
struct scsi_cd *cd;
|
2008-03-02 18:41:28 +03:00
|
|
|
int ret = -ENXIO;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-06-02 16:28:52 +04:00
|
|
|
mutex_lock(&sr_mutex);
|
2010-08-07 20:25:34 +04:00
|
|
|
cd = scsi_cd_get(bdev->bd_disk);
|
2008-03-02 18:41:28 +03:00
|
|
|
if (cd) {
|
|
|
|
ret = cdrom_open(&cd->cdi, bdev, mode);
|
|
|
|
if (ret)
|
|
|
|
scsi_cd_put(cd);
|
|
|
|
}
|
2010-06-02 16:28:52 +04:00
|
|
|
mutex_unlock(&sr_mutex);
|
2005-04-17 02:20:36 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-03-02 18:41:28 +03:00
|
|
|
static int sr_block_release(struct gendisk *disk, fmode_t mode)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2008-03-02 18:41:28 +03:00
|
|
|
struct scsi_cd *cd = scsi_cd(disk);
|
2010-06-02 16:28:52 +04:00
|
|
|
mutex_lock(&sr_mutex);
|
2008-03-02 18:41:28 +03:00
|
|
|
cdrom_release(&cd->cdi, mode);
|
2005-04-17 02:20:36 +04:00
|
|
|
scsi_cd_put(cd);
|
2010-06-02 16:28:52 +04:00
|
|
|
mutex_unlock(&sr_mutex);
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-03-02 18:41:28 +03:00
|
|
|
static int sr_block_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned long arg)
|
|
|
|
{
|
2008-03-02 18:41:28 +03:00
|
|
|
struct scsi_cd *cd = scsi_cd(bdev->bd_disk);
|
2005-04-17 02:20:36 +04:00
|
|
|
struct scsi_device *sdev = cd->device;
|
2006-03-23 14:00:15 +03:00
|
|
|
void __user *argp = (void __user *)arg;
|
|
|
|
int ret;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2013-01-23 11:09:31 +04:00
|
|
|
scsi_autopm_get_device(cd->device);
|
|
|
|
|
2010-06-02 16:28:52 +04:00
|
|
|
mutex_lock(&sr_mutex);
|
2010-07-08 12:18:46 +04:00
|
|
|
|
2006-03-23 14:00:15 +03:00
|
|
|
/*
|
|
|
|
* Send SCSI addressing ioctls directly to mid level, send other
|
|
|
|
* ioctls to cdrom/block level.
|
|
|
|
*/
|
|
|
|
switch (cmd) {
|
|
|
|
case SCSI_IOCTL_GET_IDLUN:
|
|
|
|
case SCSI_IOCTL_GET_BUS_NUMBER:
|
2010-07-08 12:18:46 +04:00
|
|
|
ret = scsi_ioctl(sdev, cmd, argp);
|
|
|
|
goto out;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2006-03-23 14:00:15 +03:00
|
|
|
|
2008-03-02 18:41:28 +03:00
|
|
|
ret = cdrom_ioctl(&cd->cdi, bdev, mode, cmd, arg);
|
2007-01-02 11:41:04 +03:00
|
|
|
if (ret != -ENOSYS)
|
2010-07-08 12:18:46 +04:00
|
|
|
goto out;
|
2006-03-23 14:00:15 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ENODEV means that we didn't recognise the ioctl, or that we
|
|
|
|
* cannot execute it in the current device state. In either
|
|
|
|
* case fall through to scsi_ioctl, which will return ENDOEV again
|
|
|
|
* if it doesn't recognise the ioctl
|
|
|
|
*/
|
2008-03-02 16:15:49 +03:00
|
|
|
ret = scsi_nonblockable_ioctl(sdev, cmd, argp,
|
2008-11-05 16:58:42 +03:00
|
|
|
(mode & FMODE_NDELAY) != 0);
|
2006-03-23 14:00:15 +03:00
|
|
|
if (ret != -ENODEV)
|
2010-07-08 12:18:46 +04:00
|
|
|
goto out;
|
|
|
|
ret = scsi_ioctl(sdev, cmd, argp);
|
|
|
|
|
|
|
|
out:
|
2010-06-02 16:28:52 +04:00
|
|
|
mutex_unlock(&sr_mutex);
|
2013-01-23 11:09:31 +04:00
|
|
|
scsi_autopm_put_device(cd->device);
|
2010-07-08 12:18:46 +04:00
|
|
|
return ret;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2010-12-16 19:52:17 +03:00
|
|
|
static unsigned int sr_block_check_events(struct gendisk *disk,
|
|
|
|
unsigned int clearing)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct scsi_cd *cd = scsi_cd(disk);
|
2013-01-23 11:09:31 +04:00
|
|
|
unsigned int ret;
|
|
|
|
|
2013-01-23 11:09:32 +04:00
|
|
|
if (atomic_read(&cd->device->disk_events_disable_depth) == 0) {
|
|
|
|
scsi_autopm_get_device(cd->device);
|
|
|
|
ret = cdrom_check_events(&cd->cdi, clearing);
|
|
|
|
scsi_autopm_put_device(cd->device);
|
|
|
|
} else {
|
|
|
|
ret = 0;
|
|
|
|
}
|
2013-01-23 11:09:31 +04:00
|
|
|
|
|
|
|
return ret;
|
2010-12-16 19:52:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int sr_block_revalidate_disk(struct gendisk *disk)
|
|
|
|
{
|
|
|
|
struct scsi_cd *cd = scsi_cd(disk);
|
|
|
|
struct scsi_sense_hdr sshdr;
|
|
|
|
|
2013-01-23 11:09:31 +04:00
|
|
|
scsi_autopm_get_device(cd->device);
|
|
|
|
|
2010-12-16 19:52:17 +03:00
|
|
|
/* if the unit is not ready, nothing more to do */
|
|
|
|
if (scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr))
|
2013-01-23 11:09:31 +04:00
|
|
|
goto out;
|
2010-12-16 19:52:17 +03:00
|
|
|
|
|
|
|
sr_cd_check(&cd->cdi);
|
|
|
|
get_sectorsize(cd);
|
2013-01-23 11:09:31 +04:00
|
|
|
out:
|
|
|
|
scsi_autopm_put_device(cd->device);
|
2010-12-16 19:52:17 +03:00
|
|
|
return 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2009-09-22 04:01:13 +04:00
|
|
|
static const struct block_device_operations sr_bdops =
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
.owner = THIS_MODULE,
|
2008-03-02 18:41:28 +03:00
|
|
|
.open = sr_block_open,
|
|
|
|
.release = sr_block_release,
|
2010-07-08 12:18:46 +04:00
|
|
|
.ioctl = sr_block_ioctl,
|
2010-12-16 19:52:17 +03:00
|
|
|
.check_events = sr_block_check_events,
|
|
|
|
.revalidate_disk = sr_block_revalidate_disk,
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* No compat_ioctl for now because sr_block_ioctl never
|
2011-03-31 05:57:33 +04:00
|
|
|
* seems to pass arbitrary ioctls down to host drivers.
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
|
|
|
};
|
|
|
|
|
|
|
|
static int sr_open(struct cdrom_device_info *cdi, int purpose)
|
|
|
|
{
|
|
|
|
struct scsi_cd *cd = cdi->handle;
|
|
|
|
struct scsi_device *sdev = cd->device;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the device is in error recovery, wait until it is done.
|
|
|
|
* If the device is offline, then disallow any access to it.
|
|
|
|
*/
|
|
|
|
retval = -ENXIO;
|
|
|
|
if (!scsi_block_when_processing_errors(sdev))
|
|
|
|
goto error_out;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error_out:
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sr_release(struct cdrom_device_info *cdi)
|
|
|
|
{
|
|
|
|
struct scsi_cd *cd = cdi->handle;
|
|
|
|
|
|
|
|
if (cd->device->sector_size > 2048)
|
|
|
|
sr_set_blocklength(cd, 2048);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sr_probe(struct device *dev)
|
|
|
|
{
|
|
|
|
struct scsi_device *sdev = to_scsi_device(dev);
|
|
|
|
struct gendisk *disk;
|
|
|
|
struct scsi_cd *cd;
|
|
|
|
int minor, error;
|
|
|
|
|
|
|
|
error = -ENODEV;
|
|
|
|
if (sdev->type != TYPE_ROM && sdev->type != TYPE_WORM)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
error = -ENOMEM;
|
2006-01-16 18:31:18 +03:00
|
|
|
cd = kzalloc(sizeof(*cd), GFP_KERNEL);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (!cd)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
kref_init(&cd->kref);
|
|
|
|
|
|
|
|
disk = alloc_disk(1);
|
|
|
|
if (!disk)
|
|
|
|
goto fail_free;
|
|
|
|
|
|
|
|
spin_lock(&sr_index_lock);
|
|
|
|
minor = find_first_zero_bit(sr_index_bits, SR_DISKS);
|
|
|
|
if (minor == SR_DISKS) {
|
|
|
|
spin_unlock(&sr_index_lock);
|
|
|
|
error = -EBUSY;
|
|
|
|
goto fail_put;
|
|
|
|
}
|
|
|
|
__set_bit(minor, sr_index_bits);
|
|
|
|
spin_unlock(&sr_index_lock);
|
|
|
|
|
|
|
|
disk->major = SCSI_CDROM_MAJOR;
|
|
|
|
disk->first_minor = minor;
|
|
|
|
sprintf(disk->disk_name, "sr%d", minor);
|
|
|
|
disk->fops = &sr_bdops;
|
2011-04-21 22:54:46 +04:00
|
|
|
disk->flags = GENHD_FL_CD | GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE;
|
2010-12-16 19:52:17 +03:00
|
|
|
disk->events = DISK_EVENT_MEDIA_CHANGE | DISK_EVENT_EJECT_REQUEST;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2008-09-14 16:55:09 +04:00
|
|
|
blk_queue_rq_timeout(sdev->request_queue, SR_TIMEOUT);
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
cd->device = sdev;
|
|
|
|
cd->disk = disk;
|
|
|
|
cd->driver = &sr_template;
|
|
|
|
cd->disk = disk;
|
|
|
|
cd->capacity = 0x1fffff;
|
|
|
|
cd->device->changed = 1; /* force recheck CD type */
|
2010-12-16 19:52:17 +03:00
|
|
|
cd->media_present = 1;
|
2005-04-17 02:20:36 +04:00
|
|
|
cd->use = 1;
|
|
|
|
cd->readcd_known = 0;
|
|
|
|
cd->readcd_cdda = 0;
|
|
|
|
|
|
|
|
cd->cdi.ops = &sr_dops;
|
|
|
|
cd->cdi.handle = cd;
|
|
|
|
cd->cdi.mask = 0;
|
|
|
|
cd->cdi.capacity = 1;
|
|
|
|
sprintf(cd->cdi.name, "sr%d", minor);
|
|
|
|
|
|
|
|
sdev->sector_size = 2048; /* A guess, just in case */
|
|
|
|
|
|
|
|
/* FIXME: need to handle a get_capabilities failure properly ?? */
|
|
|
|
get_capabilities(cd);
|
2007-08-04 19:06:25 +04:00
|
|
|
blk_queue_prep_rq(sdev->request_queue, sr_prep_fn);
|
2005-04-17 02:20:36 +04:00
|
|
|
sr_vendor_init(cd);
|
|
|
|
|
|
|
|
disk->driverfs_dev = &sdev->sdev_gendev;
|
|
|
|
set_capacity(disk, cd->capacity);
|
|
|
|
disk->private_data = &cd->driver;
|
|
|
|
disk->queue = sdev->request_queue;
|
|
|
|
cd->cdi.disk = disk;
|
|
|
|
|
|
|
|
if (register_cdrom(&cd->cdi))
|
|
|
|
goto fail_put;
|
|
|
|
|
|
|
|
dev_set_drvdata(dev, cd);
|
|
|
|
disk->flags |= GENHD_FL_REMOVABLE;
|
|
|
|
add_disk(disk);
|
|
|
|
|
2005-10-02 20:45:08 +04:00
|
|
|
sdev_printk(KERN_DEBUG, sdev,
|
|
|
|
"Attached scsi CD-ROM %s\n", cd->cdi.name);
|
2013-01-23 11:09:31 +04:00
|
|
|
scsi_autopm_put_device(cd->device);
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail_put:
|
|
|
|
put_disk(disk);
|
|
|
|
fail_free:
|
|
|
|
kfree(cd);
|
|
|
|
fail:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void get_sectorsize(struct scsi_cd *cd)
|
|
|
|
{
|
|
|
|
unsigned char cmd[10];
|
2008-07-04 11:31:50 +04:00
|
|
|
unsigned char buffer[8];
|
2005-04-17 02:20:36 +04:00
|
|
|
int the_result, retries = 3;
|
|
|
|
int sector_size;
|
2007-07-24 11:28:11 +04:00
|
|
|
struct request_queue *queue;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
do {
|
|
|
|
cmd[0] = READ_CAPACITY;
|
|
|
|
memset((void *) &cmd[1], 0, 9);
|
2008-07-04 11:31:50 +04:00
|
|
|
memset(buffer, 0, sizeof(buffer));
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* Do the command and wait.. */
|
2005-06-13 07:21:29 +04:00
|
|
|
the_result = scsi_execute_req(cd->device, cmd, DMA_FROM_DEVICE,
|
2008-07-04 11:31:50 +04:00
|
|
|
buffer, sizeof(buffer), NULL,
|
2008-12-04 08:24:39 +03:00
|
|
|
SR_TIMEOUT, MAX_RETRIES, NULL);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
retries--;
|
|
|
|
|
|
|
|
} while (the_result && retries);
|
|
|
|
|
|
|
|
|
|
|
|
if (the_result) {
|
|
|
|
cd->capacity = 0x1fffff;
|
|
|
|
sector_size = 2048; /* A guess, just in case */
|
|
|
|
} else {
|
2009-09-04 06:38:02 +04:00
|
|
|
long last_written;
|
|
|
|
|
|
|
|
cd->capacity = 1 + ((buffer[0] << 24) | (buffer[1] << 16) |
|
|
|
|
(buffer[2] << 8) | buffer[3]);
|
|
|
|
/*
|
|
|
|
* READ_CAPACITY doesn't return the correct size on
|
|
|
|
* certain UDF media. If last_written is larger, use
|
|
|
|
* it instead.
|
|
|
|
*
|
|
|
|
* http://bugzilla.kernel.org/show_bug.cgi?id=9668
|
|
|
|
*/
|
|
|
|
if (!cdrom_get_last_written(&cd->cdi, &last_written))
|
|
|
|
cd->capacity = max_t(long, cd->capacity, last_written);
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
sector_size = (buffer[4] << 24) |
|
|
|
|
(buffer[5] << 16) | (buffer[6] << 8) | buffer[7];
|
|
|
|
switch (sector_size) {
|
|
|
|
/*
|
|
|
|
* HP 4020i CD-Recorder reports 2340 byte sectors
|
|
|
|
* Philips CD-Writers report 2352 byte sectors
|
|
|
|
*
|
|
|
|
* Use 2k sectors for them..
|
|
|
|
*/
|
|
|
|
case 0:
|
|
|
|
case 2340:
|
|
|
|
case 2352:
|
|
|
|
sector_size = 2048;
|
|
|
|
/* fall through */
|
|
|
|
case 2048:
|
|
|
|
cd->capacity *= 4;
|
|
|
|
/* fall through */
|
|
|
|
case 512:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printk("%s: unsupported sector size %d.\n",
|
|
|
|
cd->cdi.name, sector_size);
|
|
|
|
cd->capacity = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cd->device->sector_size = sector_size;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add this so that we have the ability to correctly gauge
|
|
|
|
* what the device is capable of.
|
|
|
|
*/
|
|
|
|
set_capacity(cd->disk, cd->capacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
queue = cd->device->request_queue;
|
2009-05-23 01:17:49 +04:00
|
|
|
blk_queue_logical_block_size(queue, sector_size);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2008-07-04 11:31:50 +04:00
|
|
|
return;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void get_capabilities(struct scsi_cd *cd)
|
|
|
|
{
|
|
|
|
unsigned char *buffer;
|
|
|
|
struct scsi_mode_data data;
|
2005-06-13 07:21:29 +04:00
|
|
|
struct scsi_sense_hdr sshdr;
|
2008-02-06 22:01:58 +03:00
|
|
|
int rc, n;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-11-28 18:22:25 +03:00
|
|
|
static const char *loadmech[] =
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
"caddy",
|
|
|
|
"tray",
|
|
|
|
"pop-up",
|
|
|
|
"",
|
|
|
|
"changer",
|
|
|
|
"cartridge changer",
|
|
|
|
"",
|
|
|
|
""
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* allocate transfer buffer */
|
|
|
|
buffer = kmalloc(512, GFP_KERNEL | GFP_DMA);
|
|
|
|
if (!buffer) {
|
|
|
|
printk(KERN_ERR "sr: out of memory.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-06 22:01:58 +03:00
|
|
|
/* eat unit attentions */
|
2010-12-08 22:57:40 +03:00
|
|
|
scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* ask for mode page 0x2a */
|
|
|
|
rc = scsi_mode_sense(cd->device, 0, 0x2a, buffer, 128,
|
2005-08-28 20:27:01 +04:00
|
|
|
SR_TIMEOUT, 3, &data, NULL);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (!scsi_status_is_good(rc)) {
|
|
|
|
/* failed, drive doesn't have capabilities mode page */
|
|
|
|
cd->cdi.speed = 1;
|
|
|
|
cd->cdi.mask |= (CDC_CD_R | CDC_CD_RW | CDC_DVD_R |
|
2006-01-12 07:58:40 +03:00
|
|
|
CDC_DVD | CDC_DVD_RAM |
|
|
|
|
CDC_SELECT_DISC | CDC_SELECT_SPEED |
|
|
|
|
CDC_MRW | CDC_MRW_W | CDC_RAM);
|
2005-04-17 02:20:36 +04:00
|
|
|
kfree(buffer);
|
|
|
|
printk("%s: scsi-1 drive\n", cd->cdi.name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
n = data.header_length + data.block_descriptor_length;
|
|
|
|
cd->cdi.speed = ((buffer[n + 8] << 8) + buffer[n + 9]) / 176;
|
|
|
|
cd->readcd_known = 1;
|
|
|
|
cd->readcd_cdda = buffer[n + 5] & 0x01;
|
|
|
|
/* print some capability bits */
|
|
|
|
printk("%s: scsi3-mmc drive: %dx/%dx %s%s%s%s%s%s\n", cd->cdi.name,
|
|
|
|
((buffer[n + 14] << 8) + buffer[n + 15]) / 176,
|
|
|
|
cd->cdi.speed,
|
|
|
|
buffer[n + 3] & 0x01 ? "writer " : "", /* CD Writer */
|
|
|
|
buffer[n + 3] & 0x20 ? "dvd-ram " : "",
|
|
|
|
buffer[n + 2] & 0x02 ? "cd/rw " : "", /* can read rewriteable */
|
|
|
|
buffer[n + 4] & 0x20 ? "xa/form2 " : "", /* can read xa/from2 */
|
|
|
|
buffer[n + 5] & 0x01 ? "cdda " : "", /* can read audio data */
|
|
|
|
loadmech[buffer[n + 6] >> 5]);
|
|
|
|
if ((buffer[n + 6] >> 5) == 0)
|
|
|
|
/* caddy drives can't close tray... */
|
|
|
|
cd->cdi.mask |= CDC_CLOSE_TRAY;
|
|
|
|
if ((buffer[n + 2] & 0x8) == 0)
|
|
|
|
/* not a DVD drive */
|
|
|
|
cd->cdi.mask |= CDC_DVD;
|
|
|
|
if ((buffer[n + 3] & 0x20) == 0)
|
|
|
|
/* can't write DVD-RAM media */
|
|
|
|
cd->cdi.mask |= CDC_DVD_RAM;
|
|
|
|
if ((buffer[n + 3] & 0x10) == 0)
|
|
|
|
/* can't write DVD-R media */
|
|
|
|
cd->cdi.mask |= CDC_DVD_R;
|
|
|
|
if ((buffer[n + 3] & 0x2) == 0)
|
|
|
|
/* can't write CD-RW media */
|
|
|
|
cd->cdi.mask |= CDC_CD_RW;
|
|
|
|
if ((buffer[n + 3] & 0x1) == 0)
|
|
|
|
/* can't write CD-R media */
|
|
|
|
cd->cdi.mask |= CDC_CD_R;
|
|
|
|
if ((buffer[n + 6] & 0x8) == 0)
|
|
|
|
/* can't eject */
|
|
|
|
cd->cdi.mask |= CDC_OPEN_TRAY;
|
|
|
|
|
|
|
|
if ((buffer[n + 6] >> 5) == mechtype_individual_changer ||
|
|
|
|
(buffer[n + 6] >> 5) == mechtype_cartridge_changer)
|
|
|
|
cd->cdi.capacity =
|
|
|
|
cdrom_number_of_slots(&cd->cdi);
|
|
|
|
if (cd->cdi.capacity <= 1)
|
|
|
|
/* not a changer */
|
|
|
|
cd->cdi.mask |= CDC_SELECT_DISC;
|
|
|
|
/*else I don't think it can close its tray
|
|
|
|
cd->cdi.mask |= CDC_CLOSE_TRAY; */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if DVD-RAM, MRW-W or CD-RW, we are randomly writable
|
|
|
|
*/
|
|
|
|
if ((cd->cdi.mask & (CDC_DVD_RAM | CDC_MRW_W | CDC_RAM | CDC_CD_RW)) !=
|
|
|
|
(CDC_DVD_RAM | CDC_MRW_W | CDC_RAM | CDC_CD_RW)) {
|
|
|
|
cd->device->writeable = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
kfree(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sr_packet() is the entry point for the generic commands generated
|
|
|
|
* by the Uniform CD-ROM layer.
|
|
|
|
*/
|
|
|
|
static int sr_packet(struct cdrom_device_info *cdi,
|
|
|
|
struct packet_command *cgc)
|
|
|
|
{
|
2010-10-02 01:20:08 +04:00
|
|
|
struct scsi_cd *cd = cdi->handle;
|
|
|
|
struct scsi_device *sdev = cd->device;
|
|
|
|
|
|
|
|
if (cgc->cmd[0] == GPCMD_READ_DISC_INFO && sdev->no_read_disc_info)
|
|
|
|
return -EDRIVE_CANT_DO_THIS;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
if (cgc->timeout <= 0)
|
|
|
|
cgc->timeout = IOCTL_TIMEOUT;
|
|
|
|
|
2010-10-02 01:20:08 +04:00
|
|
|
sr_do_ioctl(cd, cgc);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
return cgc->stat;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sr_kref_release - Called to free the scsi_cd structure
|
|
|
|
* @kref: pointer to embedded kref
|
|
|
|
*
|
2006-01-11 15:16:10 +03:00
|
|
|
* sr_ref_mutex must be held entering this routine. Because it is
|
2005-04-17 02:20:36 +04:00
|
|
|
* called on last put, you should always use the scsi_cd_get()
|
|
|
|
* scsi_cd_put() helpers which manipulate the semaphore directly
|
|
|
|
* and never do a direct kref_put().
|
|
|
|
**/
|
|
|
|
static void sr_kref_release(struct kref *kref)
|
|
|
|
{
|
|
|
|
struct scsi_cd *cd = container_of(kref, struct scsi_cd, kref);
|
|
|
|
struct gendisk *disk = cd->disk;
|
|
|
|
|
|
|
|
spin_lock(&sr_index_lock);
|
2008-09-03 11:01:48 +04:00
|
|
|
clear_bit(MINOR(disk_devt(disk)), sr_index_bits);
|
2005-04-17 02:20:36 +04:00
|
|
|
spin_unlock(&sr_index_lock);
|
|
|
|
|
|
|
|
unregister_cdrom(&cd->cdi);
|
|
|
|
|
|
|
|
disk->private_data = NULL;
|
|
|
|
|
|
|
|
put_disk(disk);
|
|
|
|
|
|
|
|
kfree(cd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sr_remove(struct device *dev)
|
|
|
|
{
|
|
|
|
struct scsi_cd *cd = dev_get_drvdata(dev);
|
|
|
|
|
2013-01-23 11:09:31 +04:00
|
|
|
scsi_autopm_get_device(cd->device);
|
|
|
|
|
2009-06-18 11:57:18 +04:00
|
|
|
blk_queue_prep_rq(cd->device->request_queue, scsi_prep_fn);
|
2005-04-17 02:20:36 +04:00
|
|
|
del_gendisk(cd->disk);
|
|
|
|
|
2006-01-11 15:16:10 +03:00
|
|
|
mutex_lock(&sr_ref_mutex);
|
2005-04-17 02:20:36 +04:00
|
|
|
kref_put(&cd->kref, sr_kref_release);
|
2006-01-11 15:16:10 +03:00
|
|
|
mutex_unlock(&sr_ref_mutex);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init init_sr(void)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = register_blkdev(SCSI_CDROM_MAJOR, "sr");
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
2007-06-25 19:39:33 +04:00
|
|
|
rc = scsi_register_driver(&sr_template.gendrv);
|
|
|
|
if (rc)
|
|
|
|
unregister_blkdev(SCSI_CDROM_MAJOR, "sr");
|
|
|
|
|
|
|
|
return rc;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit exit_sr(void)
|
|
|
|
{
|
|
|
|
scsi_unregister_driver(&sr_template.gendrv);
|
|
|
|
unregister_blkdev(SCSI_CDROM_MAJOR, "sr");
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(init_sr);
|
|
|
|
module_exit(exit_sr);
|
|
|
|
MODULE_LICENSE("GPL");
|