aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/scsi/sd.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 7955bc226125..015a597a852e 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1433,6 +1433,8 @@ static void read_capacity_error(struct scsi_disk *sdkp, struct scsi_device *sdp,
1433#error RC16_LEN must not be more than SD_BUF_SIZE 1433#error RC16_LEN must not be more than SD_BUF_SIZE
1434#endif 1434#endif
1435 1435
1436#define READ_CAPACITY_RETRIES_ON_RESET 10
1437
1436static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp, 1438static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp,
1437 unsigned char *buffer) 1439 unsigned char *buffer)
1438{ 1440{
@@ -1440,7 +1442,7 @@ static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp,
1440 struct scsi_sense_hdr sshdr; 1442 struct scsi_sense_hdr sshdr;
1441 int sense_valid = 0; 1443 int sense_valid = 0;
1442 int the_result; 1444 int the_result;
1443 int retries = 3; 1445 int retries = 3, reset_retries = READ_CAPACITY_RETRIES_ON_RESET;
1444 unsigned int alignment; 1446 unsigned int alignment;
1445 unsigned long long lba; 1447 unsigned long long lba;
1446 unsigned sector_size; 1448 unsigned sector_size;
@@ -1469,6 +1471,13 @@ static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp,
1469 * Invalid Field in CDB, just retry 1471 * Invalid Field in CDB, just retry
1470 * silently with RC10 */ 1472 * silently with RC10 */
1471 return -EINVAL; 1473 return -EINVAL;
1474 if (sense_valid &&
1475 sshdr.sense_key == UNIT_ATTENTION &&
1476 sshdr.asc == 0x29 && sshdr.ascq == 0x00)
1477 /* Device reset might occur several times,
1478 * give it one more chance */
1479 if (--reset_retries > 0)
1480 continue;
1472 } 1481 }
1473 retries--; 1482 retries--;
1474 1483
@@ -1527,7 +1536,7 @@ static int read_capacity_10(struct scsi_disk *sdkp, struct scsi_device *sdp,
1527 struct scsi_sense_hdr sshdr; 1536 struct scsi_sense_hdr sshdr;
1528 int sense_valid = 0; 1537 int sense_valid = 0;
1529 int the_result; 1538 int the_result;
1530 int retries = 3; 1539 int retries = 3, reset_retries = READ_CAPACITY_RETRIES_ON_RESET;
1531 sector_t lba; 1540 sector_t lba;
1532 unsigned sector_size; 1541 unsigned sector_size;
1533 1542
@@ -1543,8 +1552,16 @@ static int read_capacity_10(struct scsi_disk *sdkp, struct scsi_device *sdp,
1543 if (media_not_present(sdkp, &sshdr)) 1552 if (media_not_present(sdkp, &sshdr))
1544 return -ENODEV; 1553 return -ENODEV;
1545 1554
1546 if (the_result) 1555 if (the_result) {
1547 sense_valid = scsi_sense_valid(&sshdr); 1556 sense_valid = scsi_sense_valid(&sshdr);
1557 if (sense_valid &&
1558 sshdr.sense_key == UNIT_ATTENTION &&
1559 sshdr.asc == 0x29 && sshdr.ascq == 0x00)
1560 /* Device reset might occur several times,
1561 * give it one more chance */
1562 if (--reset_retries > 0)
1563 continue;
1564 }
1548 retries--; 1565 retries--;
1549 1566
1550 } while (the_result && retries); 1567 } while (the_result && retries);