Commit dbdb2c5a authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Linus Torvalds

[PATCH] SCSI cdrom cleanup

This is one of the very early steps on cleaning up the SCSI cdrom
driver.  It gets rid of directly accessing the scsi_CDs array in favour
of using the handle we get from the generic cdrom layer.  Also uses
local vars instead of many grouped scsi_CDs accesses in other places.

The gain is to get rid of the global, static array of CDROMS
in the end.
parent a55b9112
This diff is collapsed.
......@@ -53,7 +53,7 @@ int sr_read_sector(int minor, int lba, int blksize, unsigned char *dest);
int sr_is_xa(int minor);
/* sr_vendor.c */
void sr_vendor_init(int minor);
void sr_vendor_init(Scsi_CD *);
int sr_cd_check(struct cdrom_device_info *);
int sr_set_blocklength(int minor, int blocklength);
......
......@@ -84,7 +84,7 @@ int sr_do_ioctl(int target, unsigned char *sr_cmd, void *buffer, unsigned buflen
char *bounce_buffer;
SDev = scsi_CDs[target].device;
SRpnt = scsi_allocate_request(scsi_CDs[target].device);
SRpnt = scsi_allocate_request(SDev);
if (!SRpnt) {
printk("Unable to allocate SCSI request in sr_do_ioctl");
return -ENOMEM;
......@@ -124,7 +124,7 @@ int sr_do_ioctl(int target, unsigned char *sr_cmd, void *buffer, unsigned buflen
if (driver_byte(result) != 0) {
switch (SRpnt->sr_sense_buffer[2] & 0xf) {
case UNIT_ATTENTION:
scsi_CDs[target].device->changed = 1;
SDev->changed = 1;
if (!quiet)
printk(KERN_INFO "sr%d: disc change detected.\n", target);
if (retries++ < 10)
......@@ -192,22 +192,25 @@ int sr_do_ioctl(int target, unsigned char *sr_cmd, void *buffer, unsigned buflen
static int test_unit_ready(int minor)
{
Scsi_CD *SCp;
u_char sr_cmd[10];
SCp = &scsi_CDs[minor];
sr_cmd[0] = GPCMD_TEST_UNIT_READY;
sr_cmd[1] = (scsi_CDs[minor].device->scsi_level <= SCSI_2) ?
((scsi_CDs[minor].device->lun) << 5) : 0;
sr_cmd[1] = (SCp->device->scsi_level <= SCSI_2) ?
((SCp->device->lun) << 5) : 0;
sr_cmd[2] = sr_cmd[3] = sr_cmd[4] = sr_cmd[5] = 0;
return sr_do_ioctl(minor, sr_cmd, NULL, 0, 1, SCSI_DATA_NONE, NULL);
}
int sr_tray_move(struct cdrom_device_info *cdi, int pos)
{
Scsi_CD *SCp = cdi->handle;
u_char sr_cmd[10];
sr_cmd[0] = GPCMD_START_STOP_UNIT;
sr_cmd[1] = (scsi_CDs[minor(cdi->dev)].device->scsi_level <= SCSI_2) ?
((scsi_CDs[minor(cdi->dev)].device->lun) << 5) : 0;
sr_cmd[1] = (SCp->device->scsi_level <= SCSI_2) ?
((SCp->device->lun) << 5) : 0;
sr_cmd[2] = sr_cmd[3] = sr_cmd[5] = 0;
sr_cmd[4] = (pos == 0) ? 0x03 /* close */ : 0x02 /* eject */ ;
......@@ -216,9 +219,10 @@ int sr_tray_move(struct cdrom_device_info *cdi, int pos)
int sr_lock_door(struct cdrom_device_info *cdi, int lock)
{
return scsi_ioctl(scsi_CDs[minor(cdi->dev)].device,
lock ? SCSI_IOCTL_DOORLOCK : SCSI_IOCTL_DOORUNLOCK,
0);
Scsi_CD *SCp = cdi->handle;
return scsi_ioctl(SCp->device, lock ? SCSI_IOCTL_DOORLOCK :
SCSI_IOCTL_DOORUNLOCK, 0);
}
int sr_drive_status(struct cdrom_device_info *cdi, int slot)
......@@ -235,6 +239,7 @@ int sr_drive_status(struct cdrom_device_info *cdi, int slot)
int sr_disk_status(struct cdrom_device_info *cdi)
{
Scsi_CD *SCp = cdi->handle;
struct cdrom_tochdr toc_h;
struct cdrom_tocentry toc_e;
int i, rc, have_datatracks = 0;
......@@ -256,7 +261,7 @@ int sr_disk_status(struct cdrom_device_info *cdi)
if (!have_datatracks)
return CDS_AUDIO;
if (scsi_CDs[minor(cdi->dev)].xa_flag)
if (SCp->xa_flag)
return CDS_XA_2_1;
else
return CDS_DATA_1;
......@@ -265,22 +270,24 @@ int sr_disk_status(struct cdrom_device_info *cdi)
int sr_get_last_session(struct cdrom_device_info *cdi,
struct cdrom_multisession *ms_info)
{
ms_info->addr.lba = scsi_CDs[minor(cdi->dev)].ms_offset;
ms_info->xa_flag = scsi_CDs[minor(cdi->dev)].xa_flag ||
(scsi_CDs[minor(cdi->dev)].ms_offset > 0);
Scsi_CD *SCp = cdi->handle;
ms_info->addr.lba = SCp->ms_offset;
ms_info->xa_flag = SCp->xa_flag || SCp->ms_offset > 0;
return 0;
}
int sr_get_mcn(struct cdrom_device_info *cdi, struct cdrom_mcn *mcn)
{
Scsi_CD *SCp = cdi->handle;
u_char sr_cmd[10];
char buffer[32];
int result;
sr_cmd[0] = GPCMD_READ_SUBCHANNEL;
sr_cmd[1] = (scsi_CDs[minor(cdi->dev)].device->scsi_level <= SCSI_2) ?
((scsi_CDs[minor(cdi->dev)].device->lun) << 5) : 0;
sr_cmd[1] = (SCp->device->scsi_level <= SCSI_2) ?
((SCp->device->lun) << 5) : 0;
sr_cmd[2] = 0x40; /* I do want the subchannel info */
sr_cmd[3] = 0x02; /* Give me medium catalog number info */
sr_cmd[4] = sr_cmd[5] = 0;
......@@ -305,6 +312,7 @@ int sr_reset(struct cdrom_device_info *cdi)
int sr_select_speed(struct cdrom_device_info *cdi, int speed)
{
Scsi_CD *SCp = cdi->handle;
u_char sr_cmd[MAX_COMMAND_SIZE];
if (speed == 0)
......@@ -314,8 +322,8 @@ int sr_select_speed(struct cdrom_device_info *cdi, int speed)
memset(sr_cmd, 0, MAX_COMMAND_SIZE);
sr_cmd[0] = GPCMD_SET_SPEED; /* SET CD SPEED */
sr_cmd[1] = (scsi_CDs[minor(cdi->dev)].device->scsi_level <= SCSI_2) ?
((scsi_CDs[minor(cdi->dev)].device->lun) << 5) : 0;
sr_cmd[1] = (SCp->device->scsi_level <= SCSI_2) ?
((SCp->device->lun) << 5) : 0;
sr_cmd[2] = (speed >> 8) & 0xff; /* MSB for speed (in kbytes/sec) */
sr_cmd[3] = speed & 0xff; /* LSB */
......@@ -332,6 +340,7 @@ int sr_select_speed(struct cdrom_device_info *cdi, int speed)
int sr_audio_ioctl(struct cdrom_device_info *cdi, unsigned int cmd, void *arg)
{
Scsi_CD *SCp = cdi->handle;
u_char sr_cmd[10];
int result, target = minor(cdi->dev);
unsigned char buffer[32];
......@@ -344,8 +353,8 @@ int sr_audio_ioctl(struct cdrom_device_info *cdi, unsigned int cmd, void *arg)
struct cdrom_tochdr *tochdr = (struct cdrom_tochdr *) arg;
sr_cmd[0] = GPCMD_READ_TOC_PMA_ATIP;
sr_cmd[1] = (scsi_CDs[target].device->scsi_level <= SCSI_2) ?
((scsi_CDs[target].device->lun) << 5) : 0;
sr_cmd[1] = (SCp->device->scsi_level <= SCSI_2) ?
((SCp->device->lun) << 5) : 0;
sr_cmd[2] = sr_cmd[3] = sr_cmd[4] = sr_cmd[5] = 0;
sr_cmd[8] = 12; /* LSB of length */
......@@ -362,8 +371,8 @@ int sr_audio_ioctl(struct cdrom_device_info *cdi, unsigned int cmd, void *arg)
struct cdrom_tocentry *tocentry = (struct cdrom_tocentry *) arg;
sr_cmd[0] = GPCMD_READ_TOC_PMA_ATIP;
sr_cmd[1] = (scsi_CDs[target].device->scsi_level <= SCSI_2) ?
((scsi_CDs[target].device->lun) << 5) : 0;
sr_cmd[1] = (SCp->device->scsi_level <= SCSI_2) ?
((SCp->device->lun) << 5) : 0;
sr_cmd[1] |= (tocentry->cdte_format == CDROM_MSF) ? 0x02 : 0;
sr_cmd[2] = sr_cmd[3] = sr_cmd[4] = sr_cmd[5] = 0;
sr_cmd[6] = tocentry->cdte_track;
......@@ -389,8 +398,8 @@ int sr_audio_ioctl(struct cdrom_device_info *cdi, unsigned int cmd, void *arg)
struct cdrom_ti* ti = (struct cdrom_ti*)arg;
sr_cmd[0] = GPCMD_PLAYAUDIO_TI;
sr_cmd[1] = (scsi_CDs[target].device->scsi_level <= SCSI_2) ?
(scsi_CDs[target].device->lun << 5) : 0;
sr_cmd[1] = (SCp->device->scsi_level <= SCSI_2) ?
(SCp->device->lun << 5) : 0;
sr_cmd[4] = ti->cdti_trk0;
sr_cmd[5] = ti->cdti_ind0;
sr_cmd[7] = ti->cdti_trk1;
......@@ -432,6 +441,7 @@ int sr_audio_ioctl(struct cdrom_device_info *cdi, unsigned int cmd, void *arg)
int sr_read_cd(int minor, unsigned char *dest, int lba, int format, int blksize)
{
unsigned char cmd[MAX_COMMAND_SIZE];
Scsi_CD *SCp = &scsi_CDs[minor];
#ifdef DEBUG
printk("sr%d: sr_read_cd lba=%d format=%d blksize=%d\n",
......@@ -440,8 +450,8 @@ int sr_read_cd(int minor, unsigned char *dest, int lba, int format, int blksize)
memset(cmd, 0, MAX_COMMAND_SIZE);
cmd[0] = GPCMD_READ_CD; /* READ_CD */
cmd[1] = (scsi_CDs[minor].device->scsi_level <= SCSI_2) ?
(scsi_CDs[minor].device->lun << 5) : 0;
cmd[1] = (SCp->device->scsi_level <= SCSI_2) ?
(SCp->device->lun << 5) : 0;
cmd[1] |= ((format & 7) << 2);
cmd[2] = (unsigned char) (lba >> 24) & 0xff;
cmd[3] = (unsigned char) (lba >> 16) & 0xff;
......@@ -472,19 +482,20 @@ int sr_read_cd(int minor, unsigned char *dest, int lba, int format, int blksize)
int sr_read_sector(int minor, int lba, int blksize, unsigned char *dest)
{
unsigned char cmd[MAX_COMMAND_SIZE]; /* the scsi-command */
Scsi_CD *SCp = &scsi_CDs[minor];
int rc;
/* we try the READ CD command first... */
if (scsi_CDs[minor].readcd_known) {
if (SCp->readcd_known) {
rc = sr_read_cd(minor, dest, lba, 0, blksize);
if (-EDRIVE_CANT_DO_THIS != rc)
return rc;
scsi_CDs[minor].readcd_known = 0;
SCp->readcd_known = 0;
printk("CDROM does'nt support READ CD (0xbe) command\n");
/* fall & retry the other way */
}
/* ... if this fails, we switch the blocksize using MODE SELECT */
if (blksize != scsi_CDs[minor].device->sector_size) {
if (blksize != SCp->device->sector_size) {
if (0 != (rc = sr_set_blocklength(minor, blksize)))
return rc;
}
......@@ -494,8 +505,8 @@ int sr_read_sector(int minor, int lba, int blksize, unsigned char *dest)
memset(cmd, 0, MAX_COMMAND_SIZE);
cmd[0] = GPCMD_READ_10;
cmd[1] = (scsi_CDs[minor].device->scsi_level <= SCSI_2) ?
(scsi_CDs[minor].device->lun << 5) : 0;
cmd[1] = (SCp->device->scsi_level <= SCSI_2) ?
(SCp->device->lun << 5) : 0;
cmd[2] = (unsigned char) (lba >> 24) & 0xff;
cmd[3] = (unsigned char) (lba >> 16) & 0xff;
cmd[4] = (unsigned char) (lba >> 8) & 0xff;
......@@ -514,6 +525,7 @@ int sr_read_sector(int minor, int lba, int blksize, unsigned char *dest)
int sr_is_xa(int minor)
{
unsigned char *raw_sector;
Scsi_CD *SCp = &scsi_CDs[minor];
int is_xa;
if (!xa_test)
......@@ -522,7 +534,7 @@ int sr_is_xa(int minor)
raw_sector = (unsigned char *) kmalloc(2048, GFP_DMA | GFP_KERNEL);
if (!raw_sector)
return -ENOMEM;
if (0 == sr_read_sector(minor, scsi_CDs[minor].ms_offset + 16,
if (0 == sr_read_sector(minor, SCp->ms_offset + 16,
CD_FRAMESIZE_RAW1, raw_sector)) {
is_xa = (raw_sector[3] == 0x02) ? 1 : 0;
} else {
......@@ -539,18 +551,16 @@ int sr_is_xa(int minor)
int sr_dev_ioctl(struct cdrom_device_info *cdi,
unsigned int cmd, unsigned long arg)
{
int target;
target = minor(cdi->dev);
Scsi_CD *SCp = cdi->handle;
switch (cmd) {
case BLKGETSIZE:
return put_user(scsi_CDs[target].capacity, (unsigned long *) arg);
return put_user(SCp->capacity, (unsigned long *) arg);
case BLKGETSIZE64:
return put_user((u64)scsi_CDs[target].capacity << 9, (u64 *)arg);
return put_user((u64)SCp->capacity << 9, (u64 *)arg);
default:
return scsi_ioctl(scsi_CDs[target].device, cmd, (void *) arg);
return scsi_ioctl(SCp->device, cmd, (void *)arg);
}
}
......
......@@ -58,27 +58,25 @@
#define VENDOR_TOSHIBA 3
#define VENDOR_WRITER 4 /* pre-scsi3 writers */
#define VENDOR_ID (scsi_CDs[minor].vendor)
void sr_vendor_init(int minor)
void sr_vendor_init(Scsi_CD *SCp)
{
#ifndef CONFIG_BLK_DEV_SR_VENDOR
VENDOR_ID = VENDOR_SCSI3;
SCp->vendor = VENDOR_SCSI3;
#else
char *vendor = scsi_CDs[minor].device->vendor;
char *model = scsi_CDs[minor].device->model;
char *vendor = SCp->device->vendor;
char *model = SCp->device->model;
/* default */
VENDOR_ID = VENDOR_SCSI3;
if (scsi_CDs[minor].readcd_known)
SCp->vendor = VENDOR_SCSI3;
if (SCp->readcd_known)
/* this is true for scsi3/mmc drives - no more checks */
return;
if (scsi_CDs[minor].device->type == TYPE_WORM) {
VENDOR_ID = VENDOR_WRITER;
if (SCp->device->type == TYPE_WORM) {
SCp->vendor = VENDOR_WRITER;
} else if (!strncmp(vendor, "NEC", 3)) {
VENDOR_ID = VENDOR_NEC;
SCp->vendor = VENDOR_NEC;
if (!strncmp(model, "CD-ROM DRIVE:25", 15) ||
!strncmp(model, "CD-ROM DRIVE:36", 15) ||
!strncmp(model, "CD-ROM DRIVE:83", 15) ||
......@@ -90,10 +88,10 @@ void sr_vendor_init(int minor)
#endif
)
/* these can't handle multisession, may hang */
scsi_CDs[minor].cdi.mask |= CDC_MULTI_SESSION;
SCp->cdi.mask |= CDC_MULTI_SESSION;
} else if (!strncmp(vendor, "TOSHIBA", 7)) {
VENDOR_ID = VENDOR_TOSHIBA;
SCp->vendor = VENDOR_TOSHIBA;
}
#endif
......@@ -108,10 +106,11 @@ int sr_set_blocklength(int minor, int blocklength)
unsigned char *buffer; /* the buffer for the ioctl */
unsigned char cmd[MAX_COMMAND_SIZE]; /* the scsi-command */
struct ccs_modesel_head *modesel;
Scsi_CD *SCp = &scsi_CDs[minor];
int rc, density = 0;
#ifdef CONFIG_BLK_DEV_SR_VENDOR
if (VENDOR_ID == VENDOR_TOSHIBA)
if (SCp->vendor == VENDOR_TOSHIBA)
density = (blocklength > 2048) ? 0x81 : 0x83;
#endif
......@@ -124,8 +123,8 @@ int sr_set_blocklength(int minor, int blocklength)
#endif
memset(cmd, 0, MAX_COMMAND_SIZE);
cmd[0] = MODE_SELECT;
cmd[1] = (scsi_CDs[minor].device->scsi_level <= SCSI_2) ?
(scsi_CDs[minor].device->lun << 5) : 0;
cmd[1] = (SCp->device->scsi_level <= SCSI_2) ?
(SCp->device->lun << 5) : 0;
cmd[1] |= (1 << 4);
cmd[4] = 12;
modesel = (struct ccs_modesel_head *) buffer;
......@@ -135,7 +134,7 @@ int sr_set_blocklength(int minor, int blocklength)
modesel->block_length_med = (blocklength >> 8) & 0xff;
modesel->block_length_lo = blocklength & 0xff;
if (0 == (rc = sr_do_ioctl(minor, cmd, buffer, sizeof(*modesel), 0, SCSI_DATA_WRITE, NULL))) {
scsi_CDs[minor].device->sector_size = blocklength;
SCp->device->sector_size = blocklength;
}
#ifdef DEBUG
else
......@@ -153,13 +152,14 @@ int sr_set_blocklength(int minor, int blocklength)
int sr_cd_check(struct cdrom_device_info *cdi)
{
Scsi_CD *SCp = cdi->handle;
unsigned long sector;
unsigned char *buffer; /* the buffer for the ioctl */
unsigned char cmd[MAX_COMMAND_SIZE]; /* the scsi-command */
int rc, no_multi, minor;
minor = minor(cdi->dev);
if (scsi_CDs[minor].cdi.mask & CDC_MULTI_SESSION)
if (SCp->cdi.mask & CDC_MULTI_SESSION)
return 0;
buffer = (unsigned char *) kmalloc(512, GFP_KERNEL | GFP_DMA);
......@@ -170,13 +170,13 @@ int sr_cd_check(struct cdrom_device_info *cdi)
no_multi = 0; /* flag: the drive can't handle multisession */
rc = 0;
switch (VENDOR_ID) {
switch (SCp->vendor) {
case VENDOR_SCSI3:
memset(cmd, 0, MAX_COMMAND_SIZE);
cmd[0] = READ_TOC;
cmd[1] = (scsi_CDs[minor].device->scsi_level <= SCSI_2) ?
(scsi_CDs[minor].device->lun << 5) : 0;
cmd[1] = (SCp->device->scsi_level <= SCSI_2) ?
(SCp->device->lun << 5) : 0;
cmd[8] = 12;
cmd[9] = 0x40;
rc = sr_do_ioctl(minor, cmd, buffer, 12, 1, SCSI_DATA_READ, NULL);
......@@ -201,8 +201,8 @@ int sr_cd_check(struct cdrom_device_info *cdi)
unsigned long min, sec, frame;
memset(cmd, 0, MAX_COMMAND_SIZE);
cmd[0] = 0xde;
cmd[1] = (scsi_CDs[minor].device->scsi_level <= SCSI_2) ?
(scsi_CDs[minor].device->lun << 5) : 0;
cmd[1] = (SCp->device->scsi_level <= SCSI_2) ?
(SCp->device->lun << 5) : 0;
cmd[1] |= 0x03;
cmd[2] = 0xb0;
rc = sr_do_ioctl(minor, cmd, buffer, 0x16, 1, SCSI_DATA_READ, NULL);
......@@ -228,8 +228,8 @@ int sr_cd_check(struct cdrom_device_info *cdi)
* where starts the last session ?) */
memset(cmd, 0, MAX_COMMAND_SIZE);
cmd[0] = 0xc7;
cmd[1] = (scsi_CDs[minor].device->scsi_level <= SCSI_2) ?
(scsi_CDs[minor].device->lun << 5) : 0;
cmd[1] = (SCp->device->scsi_level <= SCSI_2) ?
(SCp->device->lun << 5) : 0;
cmd[1] |= 0x03;
rc = sr_do_ioctl(minor, cmd, buffer, 4, 1, SCSI_DATA_READ, NULL);
if (rc == -EINVAL) {
......@@ -253,8 +253,8 @@ int sr_cd_check(struct cdrom_device_info *cdi)
case VENDOR_WRITER:
memset(cmd, 0, MAX_COMMAND_SIZE);
cmd[0] = READ_TOC;
cmd[1] = (scsi_CDs[minor].device->scsi_level <= SCSI_2) ?
(scsi_CDs[minor].device->lun << 5) : 0;
cmd[1] = (SCp->device->scsi_level <= SCSI_2) ?
(SCp->device->lun << 5) : 0;
cmd[8] = 0x04;
cmd[9] = 0x40;
rc = sr_do_ioctl(minor, cmd, buffer, 0x04, 1, SCSI_DATA_READ, NULL);
......@@ -267,8 +267,8 @@ int sr_cd_check(struct cdrom_device_info *cdi)
break;
}
cmd[0] = READ_TOC; /* Read TOC */
cmd[1] = (scsi_CDs[minor].device->scsi_level <= SCSI_2) ?
(scsi_CDs[minor].device->lun << 5) : 0;
cmd[1] = (SCp->device->scsi_level <= SCSI_2) ?
(SCp->device->lun << 5) : 0;
cmd[6] = rc & 0x7f; /* number of last session */
cmd[8] = 0x0c;
cmd[9] = 0x40;
......@@ -285,17 +285,17 @@ int sr_cd_check(struct cdrom_device_info *cdi)
/* should not happen */
printk(KERN_WARNING
"sr%d: unknown vendor code (%i), not initialized ?\n",
minor, VENDOR_ID);
minor, SCp->vendor);
sector = 0;
no_multi = 1;
break;
}
scsi_CDs[minor].ms_offset = sector;
scsi_CDs[minor].xa_flag = 0;
SCp->ms_offset = sector;
SCp->xa_flag = 0;
if (CDS_AUDIO != sr_disk_status(cdi) && 1 == sr_is_xa(minor))
scsi_CDs[minor].xa_flag = 1;
SCp->xa_flag = 1;
if (2048 != scsi_CDs[minor].device->sector_size) {
if (2048 != SCp->device->sector_size) {
sr_set_blocklength(minor, 2048);
}
if (no_multi)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment