diff options
Diffstat (limited to 'drivers/scsi/sd.c')
-rw-r--r-- | drivers/scsi/sd.c | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 8b827f37b03e..829cc37abc41 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c | |||
@@ -1040,6 +1040,7 @@ static void sd_prepare_flush(struct request_queue *q, struct request *rq) | |||
1040 | { | 1040 | { |
1041 | rq->cmd_type = REQ_TYPE_BLOCK_PC; | 1041 | rq->cmd_type = REQ_TYPE_BLOCK_PC; |
1042 | rq->timeout = SD_TIMEOUT; | 1042 | rq->timeout = SD_TIMEOUT; |
1043 | rq->retries = SD_MAX_RETRIES; | ||
1043 | rq->cmd[0] = SYNCHRONIZE_CACHE; | 1044 | rq->cmd[0] = SYNCHRONIZE_CACHE; |
1044 | rq->cmd_len = 10; | 1045 | rq->cmd_len = 10; |
1045 | } | 1046 | } |
@@ -1433,6 +1434,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 | 1434 | #error RC16_LEN must not be more than SD_BUF_SIZE |
1434 | #endif | 1435 | #endif |
1435 | 1436 | ||
1437 | #define READ_CAPACITY_RETRIES_ON_RESET 10 | ||
1438 | |||
1436 | static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp, | 1439 | static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp, |
1437 | unsigned char *buffer) | 1440 | unsigned char *buffer) |
1438 | { | 1441 | { |
@@ -1440,7 +1443,7 @@ static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp, | |||
1440 | struct scsi_sense_hdr sshdr; | 1443 | struct scsi_sense_hdr sshdr; |
1441 | int sense_valid = 0; | 1444 | int sense_valid = 0; |
1442 | int the_result; | 1445 | int the_result; |
1443 | int retries = 3; | 1446 | int retries = 3, reset_retries = READ_CAPACITY_RETRIES_ON_RESET; |
1444 | unsigned int alignment; | 1447 | unsigned int alignment; |
1445 | unsigned long long lba; | 1448 | unsigned long long lba; |
1446 | unsigned sector_size; | 1449 | unsigned sector_size; |
@@ -1469,6 +1472,13 @@ static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp, | |||
1469 | * Invalid Field in CDB, just retry | 1472 | * Invalid Field in CDB, just retry |
1470 | * silently with RC10 */ | 1473 | * silently with RC10 */ |
1471 | 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; | ||
1472 | } | 1482 | } |
1473 | retries--; | 1483 | retries--; |
1474 | 1484 | ||
@@ -1527,7 +1537,7 @@ static int read_capacity_10(struct scsi_disk *sdkp, struct scsi_device *sdp, | |||
1527 | struct scsi_sense_hdr sshdr; | 1537 | struct scsi_sense_hdr sshdr; |
1528 | int sense_valid = 0; | 1538 | int sense_valid = 0; |
1529 | int the_result; | 1539 | int the_result; |
1530 | int retries = 3; | 1540 | int retries = 3, reset_retries = READ_CAPACITY_RETRIES_ON_RESET; |
1531 | sector_t lba; | 1541 | sector_t lba; |
1532 | unsigned sector_size; | 1542 | unsigned sector_size; |
1533 | 1543 | ||
@@ -1543,8 +1553,16 @@ static int read_capacity_10(struct scsi_disk *sdkp, struct scsi_device *sdp, | |||
1543 | if (media_not_present(sdkp, &sshdr)) | 1553 | if (media_not_present(sdkp, &sshdr)) |
1544 | return -ENODEV; | 1554 | return -ENODEV; |
1545 | 1555 | ||
1546 | if (the_result) | 1556 | if (the_result) { |
1547 | 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 | } | ||
1548 | retries--; | 1566 | retries--; |
1549 | 1567 | ||
1550 | } while (the_result && retries); | 1568 | } while (the_result && retries); |
@@ -1573,6 +1591,8 @@ static int read_capacity_10(struct scsi_disk *sdkp, struct scsi_device *sdp, | |||
1573 | 1591 | ||
1574 | static int sd_try_rc16_first(struct scsi_device *sdp) | 1592 | static int sd_try_rc16_first(struct scsi_device *sdp) |
1575 | { | 1593 | { |
1594 | if (sdp->host->max_cmd_len < 16) | ||
1595 | return 0; | ||
1576 | if (sdp->scsi_level > SCSI_SPC_2) | 1596 | if (sdp->scsi_level > SCSI_SPC_2) |
1577 | return 1; | 1597 | return 1; |
1578 | if (scsi_device_protection(sdp)) | 1598 | if (scsi_device_protection(sdp)) |