1
0
Fork 0

[SCSI] sr: fix test unit ready responses

Commit 210ba1d172 updated sr.c to use
the scsi_test_unit_ready() function.  Unfortunately, this has the
wrong characteristic of eating NOT_READY returns which sr.c relies on
for tray status.

Fix by rolling an internal sr_test_unit_ready() that doesn't do this.

Tested-by: Daniel Drake <dsd@gentoo.org>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
wifi-calibration
James Bottomley 2008-02-06 13:01:58 -06:00
parent d6a451dd4d
commit 38582a62ec
3 changed files with 29 additions and 24 deletions

View File

@ -163,6 +163,29 @@ static void scsi_cd_put(struct scsi_cd *cd)
mutex_unlock(&sr_ref_mutex); mutex_unlock(&sr_ref_mutex);
} }
/* identical to scsi_test_unit_ready except that it doesn't
* eat the NOT_READY returns for removable media */
int sr_test_unit_ready(struct scsi_device *sdev, struct scsi_sense_hdr *sshdr)
{
int retries = MAX_RETRIES;
int the_result;
u8 cmd[] = {TEST_UNIT_READY, 0, 0, 0, 0, 0 };
/* issue TEST_UNIT_READY until the initial startup UNIT_ATTENTION
* conditions are gone, or a timeout happens
*/
do {
the_result = scsi_execute_req(sdev, cmd, DMA_NONE, NULL,
0, sshdr, SR_TIMEOUT,
retries--);
} while (retries > 0 &&
(!scsi_status_is_good(the_result) ||
(scsi_sense_valid(sshdr) &&
sshdr->sense_key == UNIT_ATTENTION)));
return the_result;
}
/* /*
* This function checks to see if the media has been changed in the * This function checks to see if the media has been changed in the
* CDROM drive. It is possible that we have already sensed a change, * CDROM drive. It is possible that we have already sensed a change,
@ -185,8 +208,7 @@ static int sr_media_change(struct cdrom_device_info *cdi, int slot)
} }
sshdr = kzalloc(sizeof(*sshdr), GFP_KERNEL); sshdr = kzalloc(sizeof(*sshdr), GFP_KERNEL);
retval = scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, retval = sr_test_unit_ready(cd->device, sshdr);
sshdr);
if (retval || (scsi_sense_valid(sshdr) && if (retval || (scsi_sense_valid(sshdr) &&
/* 0x3a is medium not present */ /* 0x3a is medium not present */
sshdr->asc == 0x3a)) { sshdr->asc == 0x3a)) {
@ -733,10 +755,8 @@ static void get_capabilities(struct scsi_cd *cd)
{ {
unsigned char *buffer; unsigned char *buffer;
struct scsi_mode_data data; struct scsi_mode_data data;
unsigned char cmd[MAX_COMMAND_SIZE];
struct scsi_sense_hdr sshdr; struct scsi_sense_hdr sshdr;
unsigned int the_result; int rc, n;
int retries, rc, n;
static const char *loadmech[] = static const char *loadmech[] =
{ {
@ -758,23 +778,8 @@ static void get_capabilities(struct scsi_cd *cd)
return; return;
} }
/* issue TEST_UNIT_READY until the initial startup UNIT_ATTENTION /* eat unit attentions */
* conditions are gone, or a timeout happens sr_test_unit_ready(cd->device, &sshdr);
*/
retries = 0;
do {
memset((void *)cmd, 0, MAX_COMMAND_SIZE);
cmd[0] = TEST_UNIT_READY;
the_result = scsi_execute_req (cd->device, cmd, DMA_NONE, NULL,
0, &sshdr, SR_TIMEOUT,
MAX_RETRIES);
retries++;
} while (retries < 5 &&
(!scsi_status_is_good(the_result) ||
(scsi_sense_valid(&sshdr) &&
sshdr.sense_key == UNIT_ATTENTION)));
/* ask for mode page 0x2a */ /* ask for mode page 0x2a */
rc = scsi_mode_sense(cd->device, 0, 0x2a, buffer, 128, rc = scsi_mode_sense(cd->device, 0, 0x2a, buffer, 128,

View File

@ -61,6 +61,7 @@ int sr_select_speed(struct cdrom_device_info *cdi, int speed);
int sr_audio_ioctl(struct cdrom_device_info *, unsigned int, void *); int sr_audio_ioctl(struct cdrom_device_info *, unsigned int, void *);
int sr_is_xa(Scsi_CD *); int sr_is_xa(Scsi_CD *);
int sr_test_unit_ready(struct scsi_device *sdev, struct scsi_sense_hdr *sshdr);
/* sr_vendor.c */ /* sr_vendor.c */
void sr_vendor_init(Scsi_CD *); void sr_vendor_init(Scsi_CD *);

View File

@ -306,8 +306,7 @@ int sr_drive_status(struct cdrom_device_info *cdi, int slot)
/* we have no changer support */ /* we have no changer support */
return -EINVAL; return -EINVAL;
} }
if (0 == scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, if (0 == sr_test_unit_ready(cd->device, &sshdr))
&sshdr))
return CDS_DISC_OK; return CDS_DISC_OK;
if (!cdrom_get_media_event(cdi, &med)) { if (!cdrom_get_media_event(cdi, &med)) {