[SCSI] sr: fix test unit ready responses

Commit 210ba1d1724f5c4ed87a2ab1a21ca861a915f734 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>

+29 -24
+27 -22
drivers/scsi/sr.c
··· 163 163 mutex_unlock(&sr_ref_mutex); 164 164 } 165 165 166 + /* identical to scsi_test_unit_ready except that it doesn't 167 + * eat the NOT_READY returns for removable media */ 168 + int sr_test_unit_ready(struct scsi_device *sdev, struct scsi_sense_hdr *sshdr) 169 + { 170 + int retries = MAX_RETRIES; 171 + int the_result; 172 + u8 cmd[] = {TEST_UNIT_READY, 0, 0, 0, 0, 0 }; 173 + 174 + /* issue TEST_UNIT_READY until the initial startup UNIT_ATTENTION 175 + * conditions are gone, or a timeout happens 176 + */ 177 + do { 178 + the_result = scsi_execute_req(sdev, cmd, DMA_NONE, NULL, 179 + 0, sshdr, SR_TIMEOUT, 180 + retries--); 181 + 182 + } while (retries > 0 && 183 + (!scsi_status_is_good(the_result) || 184 + (scsi_sense_valid(sshdr) && 185 + sshdr->sense_key == UNIT_ATTENTION))); 186 + return the_result; 187 + } 188 + 166 189 /* 167 190 * This function checks to see if the media has been changed in the 168 191 * CDROM drive. It is possible that we have already sensed a change, ··· 208 185 } 209 186 210 187 sshdr = kzalloc(sizeof(*sshdr), GFP_KERNEL); 211 - retval = scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, 212 - sshdr); 188 + retval = sr_test_unit_ready(cd->device, sshdr); 213 189 if (retval || (scsi_sense_valid(sshdr) && 214 190 /* 0x3a is medium not present */ 215 191 sshdr->asc == 0x3a)) { ··· 755 733 { 756 734 unsigned char *buffer; 757 735 struct scsi_mode_data data; 758 - unsigned char cmd[MAX_COMMAND_SIZE]; 759 736 struct scsi_sense_hdr sshdr; 760 - unsigned int the_result; 761 - int retries, rc, n; 737 + int rc, n; 762 738 763 739 static const char *loadmech[] = 764 740 { ··· 778 758 return; 779 759 } 780 760 781 - /* issue TEST_UNIT_READY until the initial startup UNIT_ATTENTION 782 - * conditions are gone, or a timeout happens 783 - */ 784 - retries = 0; 785 - do { 786 - memset((void *)cmd, 0, MAX_COMMAND_SIZE); 787 - cmd[0] = TEST_UNIT_READY; 788 - 789 - the_result = scsi_execute_req (cd->device, cmd, DMA_NONE, NULL, 790 - 0, &sshdr, SR_TIMEOUT, 791 - MAX_RETRIES); 792 - 793 - retries++; 794 - } while (retries < 5 && 795 - (!scsi_status_is_good(the_result) || 796 - (scsi_sense_valid(&sshdr) && 797 - sshdr.sense_key == UNIT_ATTENTION))); 761 + /* eat unit attentions */ 762 + sr_test_unit_ready(cd->device, &sshdr); 798 763 799 764 /* ask for mode page 0x2a */ 800 765 rc = scsi_mode_sense(cd->device, 0, 0x2a, buffer, 128,
+1
drivers/scsi/sr.h
··· 61 61 int sr_audio_ioctl(struct cdrom_device_info *, unsigned int, void *); 62 62 63 63 int sr_is_xa(Scsi_CD *); 64 + int sr_test_unit_ready(struct scsi_device *sdev, struct scsi_sense_hdr *sshdr); 64 65 65 66 /* sr_vendor.c */ 66 67 void sr_vendor_init(Scsi_CD *);
+1 -2
drivers/scsi/sr_ioctl.c
··· 306 306 /* we have no changer support */ 307 307 return -EINVAL; 308 308 } 309 - if (0 == scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, 310 - &sshdr)) 309 + if (0 == sr_test_unit_ready(cd->device, &sshdr)) 311 310 return CDS_DISC_OK; 312 311 313 312 if (!cdrom_get_media_event(cdi, &med)) {