aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/sd.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/sd.c')
-rw-r--r--drivers/scsi/sd.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index de6c60320f6f..829cc37abc41 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1434,6 +1434,8 @@ static void read_capacity_error(struct scsi_disk *sdkp, struct scsi_device *sdp,
1434#error RC16_LEN must not be more than SD_BUF_SIZE 1434#error RC16_LEN must not be more than SD_BUF_SIZE
1435#endif 1435#endif
1436 1436
1437#define READ_CAPACITY_RETRIES_ON_RESET 10
1438
1437static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp, 1439static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp,
1438 unsigned char *buffer) 1440 unsigned char *buffer)
1439{ 1441{
@@ -1441,7 +1443,7 @@ static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp,
1441 struct scsi_sense_hdr sshdr; 1443 struct scsi_sense_hdr sshdr;
1442 int sense_valid = 0; 1444 int sense_valid = 0;
1443 int the_result; 1445 int the_result;
1444 int retries = 3; 1446 int retries = 3, reset_retries = READ_CAPACITY_RETRIES_ON_RESET;
1445 unsigned int alignment; 1447 unsigned int alignment;
1446 unsigned long long lba; 1448 unsigned long long lba;
1447 unsigned sector_size; 1449 unsigned sector_size;
@@ -1470,6 +1472,13 @@ static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp,
1470 * Invalid Field in CDB, just retry 1472 * Invalid Field in CDB, just retry
1471 * silently with RC10 */ 1473 * silently with RC10 */
1472 return -EINVAL; 1474 return -EINVAL;
1475 if (sense_valid &&
1476 sshdr.sense_key == UNIT_ATTENTION &&
1477 sshdr.asc == 0x29 && sshdr.ascq == 0x00)
1478 /* Device reset might occur several times,
1479 * give it one more chance */
1480 if (--reset_retries > 0)
1481 continue;
1473 } 1482 }
1474 retries--; 1483 retries--;
1475 1484
@@ -1528,7 +1537,7 @@ static int read_capacity_10(struct scsi_disk *sdkp, struct scsi_device *sdp,
1528 struct scsi_sense_hdr sshdr; 1537 struct scsi_sense_hdr sshdr;
1529 int sense_valid = 0; 1538 int sense_valid = 0;
1530 int the_result; 1539 int the_result;
1531 int retries = 3; 1540 int retries = 3, reset_retries = READ_CAPACITY_RETRIES_ON_RESET;
1532 sector_t lba; 1541 sector_t lba;
1533 unsigned sector_size; 1542 unsigned sector_size;
1534 1543
@@ -1544,8 +1553,16 @@ static int read_capacity_10(struct scsi_disk *sdkp, struct scsi_device *sdp,
1544 if (media_not_present(sdkp, &sshdr)) 1553 if (media_not_present(sdkp, &sshdr))
1545 return -ENODEV; 1554 return -ENODEV;
1546 1555
1547 if (the_result) 1556 if (the_result) {
1548 sense_valid = scsi_sense_valid(&sshdr); 1557 sense_valid = scsi_sense_valid(&sshdr);
1558 if (sense_valid &&
1559 sshdr.sense_key == UNIT_ATTENTION &&
1560 sshdr.asc == 0x29 && sshdr.ascq == 0x00)
1561 /* Device reset might occur several times,
1562 * give it one more chance */
1563 if (--reset_retries > 0)
1564 continue;
1565 }
1549 retries--; 1566 retries--;
1550 1567
1551 } while (the_result && retries); 1568 } while (the_result && retries);
@@ -1574,6 +1591,8 @@ static int read_capacity_10(struct scsi_disk *sdkp, struct scsi_device *sdp,
1574 1591
1575static int sd_try_rc16_first(struct scsi_device *sdp) 1592static int sd_try_rc16_first(struct scsi_device *sdp)
1576{ 1593{
1594 if (sdp->host->max_cmd_len < 16)
1595 return 0;
1577 if (sdp->scsi_level > SCSI_SPC_2) 1596 if (sdp->scsi_level > SCSI_SPC_2)
1578 return 1; 1597 return 1;
1579 if (scsi_device_protection(sdp)) 1598 if (scsi_device_protection(sdp))