diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2010-10-22 20:34:15 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-10-22 20:34:15 -0400 |
commit | c70b5296e775cde46cfcb2d860ba160108a5ec7a (patch) | |
tree | 30419cb982acca44499236adcca65f2f87698c74 /drivers/scsi/sd.c | |
parent | 80c226fbef56576946c9655fcb2ab62e63404d12 (diff) | |
parent | 58ff4bd042adf8013c8f70fd03c2c0f8d022e387 (diff) |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6: (84 commits)
[SCSI] be2iscsi: SGE Len == 64K
[SCSI] be2iscsi: Remove premature free of cid
[SCSI] be2iscsi: More time for FW
[SCSI] libsas: fix bug for vacant phy
[SCSI] sd: Fix overflow with big physical blocks
[SCSI] st: add MTWEOFI to write filemarks without flushing drive buffer
[SCSI] libsas: Don't issue commands to devices that have been hot-removed
[SCSI] megaraid_sas: Add Online Controller Reset to MegaRAID SAS drive
[SCSI] lpfc 8.3.17: Update lpfc driver version to 8.3.17
[SCSI] lpfc 8.3.17: Replace function reset methodology
[SCSI] lpfc 8.3.17: SCSI fixes
[SCSI] lpfc 8.3.17: BSG fixes
[SCSI] lpfc 8.3.17: SLI Additions and Fixes
[SCSI] lpfc 8.3.17: Code Cleanup and Locking fixes
[SCSI] zfcp: Remove scsi_cmnd->serial_number from debug traces
[SCSI] ipr: fix array error logging
[SCSI] aha152x: enable PCMCIA on 64bit
[SCSI] scsi_dh_alua: Handle all states correctly
[SCSI] cxgb4i: connection and ddp setting update
[SCSI] cxgb3i: fixed connection over vlan
...
Diffstat (limited to 'drivers/scsi/sd.c')
-rw-r--r-- | drivers/scsi/sd.c | 78 |
1 files changed, 60 insertions, 18 deletions
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 20514c47a5aa..20295774bf70 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c | |||
@@ -477,7 +477,7 @@ static int scsi_setup_discard_cmnd(struct scsi_device *sdp, struct request *rq) | |||
477 | 477 | ||
478 | static int scsi_setup_flush_cmnd(struct scsi_device *sdp, struct request *rq) | 478 | static int scsi_setup_flush_cmnd(struct scsi_device *sdp, struct request *rq) |
479 | { | 479 | { |
480 | rq->timeout = SD_TIMEOUT; | 480 | rq->timeout = SD_FLUSH_TIMEOUT; |
481 | rq->retries = SD_MAX_RETRIES; | 481 | rq->retries = SD_MAX_RETRIES; |
482 | rq->cmd[0] = SYNCHRONIZE_CACHE; | 482 | rq->cmd[0] = SYNCHRONIZE_CACHE; |
483 | rq->cmd_len = 10; | 483 | rq->cmd_len = 10; |
@@ -1072,7 +1072,7 @@ static int sd_sync_cache(struct scsi_disk *sdkp) | |||
1072 | * flush everything. | 1072 | * flush everything. |
1073 | */ | 1073 | */ |
1074 | res = scsi_execute_req(sdp, cmd, DMA_NONE, NULL, 0, &sshdr, | 1074 | res = scsi_execute_req(sdp, cmd, DMA_NONE, NULL, 0, &sshdr, |
1075 | SD_TIMEOUT, SD_MAX_RETRIES, NULL); | 1075 | SD_FLUSH_TIMEOUT, SD_MAX_RETRIES, NULL); |
1076 | if (res == 0) | 1076 | if (res == 0) |
1077 | break; | 1077 | break; |
1078 | } | 1078 | } |
@@ -1554,7 +1554,7 @@ static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp, | |||
1554 | } | 1554 | } |
1555 | 1555 | ||
1556 | /* Logical blocks per physical block exponent */ | 1556 | /* Logical blocks per physical block exponent */ |
1557 | sdkp->hw_sector_size = (1 << (buffer[13] & 0xf)) * sector_size; | 1557 | sdkp->physical_block_size = (1 << (buffer[13] & 0xf)) * sector_size; |
1558 | 1558 | ||
1559 | /* Lowest aligned logical block */ | 1559 | /* Lowest aligned logical block */ |
1560 | alignment = ((buffer[14] & 0x3f) << 8 | buffer[15]) * sector_size; | 1560 | alignment = ((buffer[14] & 0x3f) << 8 | buffer[15]) * sector_size; |
@@ -1567,7 +1567,7 @@ static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp, | |||
1567 | struct request_queue *q = sdp->request_queue; | 1567 | struct request_queue *q = sdp->request_queue; |
1568 | 1568 | ||
1569 | sdkp->thin_provisioning = 1; | 1569 | sdkp->thin_provisioning = 1; |
1570 | q->limits.discard_granularity = sdkp->hw_sector_size; | 1570 | q->limits.discard_granularity = sdkp->physical_block_size; |
1571 | q->limits.max_discard_sectors = 0xffffffff; | 1571 | q->limits.max_discard_sectors = 0xffffffff; |
1572 | 1572 | ||
1573 | if (buffer[14] & 0x40) /* TPRZ */ | 1573 | if (buffer[14] & 0x40) /* TPRZ */ |
@@ -1635,7 +1635,7 @@ static int read_capacity_10(struct scsi_disk *sdkp, struct scsi_device *sdp, | |||
1635 | } | 1635 | } |
1636 | 1636 | ||
1637 | sdkp->capacity = lba + 1; | 1637 | sdkp->capacity = lba + 1; |
1638 | sdkp->hw_sector_size = sector_size; | 1638 | sdkp->physical_block_size = sector_size; |
1639 | return sector_size; | 1639 | return sector_size; |
1640 | } | 1640 | } |
1641 | 1641 | ||
@@ -1756,10 +1756,10 @@ got_data: | |||
1756 | (unsigned long long)sdkp->capacity, | 1756 | (unsigned long long)sdkp->capacity, |
1757 | sector_size, cap_str_10, cap_str_2); | 1757 | sector_size, cap_str_10, cap_str_2); |
1758 | 1758 | ||
1759 | if (sdkp->hw_sector_size != sector_size) | 1759 | if (sdkp->physical_block_size != sector_size) |
1760 | sd_printk(KERN_NOTICE, sdkp, | 1760 | sd_printk(KERN_NOTICE, sdkp, |
1761 | "%u-byte physical blocks\n", | 1761 | "%u-byte physical blocks\n", |
1762 | sdkp->hw_sector_size); | 1762 | sdkp->physical_block_size); |
1763 | } | 1763 | } |
1764 | } | 1764 | } |
1765 | 1765 | ||
@@ -1773,7 +1773,8 @@ got_data: | |||
1773 | else if (sector_size == 256) | 1773 | else if (sector_size == 256) |
1774 | sdkp->capacity >>= 1; | 1774 | sdkp->capacity >>= 1; |
1775 | 1775 | ||
1776 | blk_queue_physical_block_size(sdp->request_queue, sdkp->hw_sector_size); | 1776 | blk_queue_physical_block_size(sdp->request_queue, |
1777 | sdkp->physical_block_size); | ||
1777 | sdkp->device->sector_size = sector_size; | 1778 | sdkp->device->sector_size = sector_size; |
1778 | } | 1779 | } |
1779 | 1780 | ||
@@ -2039,14 +2040,24 @@ static void sd_read_block_limits(struct scsi_disk *sdkp) | |||
2039 | lba_count = get_unaligned_be32(&buffer[20]); | 2040 | lba_count = get_unaligned_be32(&buffer[20]); |
2040 | desc_count = get_unaligned_be32(&buffer[24]); | 2041 | desc_count = get_unaligned_be32(&buffer[24]); |
2041 | 2042 | ||
2042 | if (lba_count) { | 2043 | if (lba_count && desc_count) { |
2043 | q->limits.max_discard_sectors = | 2044 | if (sdkp->tpvpd && !sdkp->tpu) |
2044 | lba_count * sector_sz >> 9; | 2045 | sdkp->unmap = 0; |
2045 | 2046 | else | |
2046 | if (desc_count) | ||
2047 | sdkp->unmap = 1; | 2047 | sdkp->unmap = 1; |
2048 | } | 2048 | } |
2049 | 2049 | ||
2050 | if (sdkp->tpvpd && !sdkp->tpu && !sdkp->tpws) { | ||
2051 | sd_printk(KERN_ERR, sdkp, "Thin provisioning is " \ | ||
2052 | "enabled but neither TPU, nor TPWS are " \ | ||
2053 | "set. Disabling discard!\n"); | ||
2054 | goto out; | ||
2055 | } | ||
2056 | |||
2057 | if (lba_count) | ||
2058 | q->limits.max_discard_sectors = | ||
2059 | lba_count * sector_sz >> 9; | ||
2060 | |||
2050 | granularity = get_unaligned_be32(&buffer[28]); | 2061 | granularity = get_unaligned_be32(&buffer[28]); |
2051 | 2062 | ||
2052 | if (granularity) | 2063 | if (granularity) |
@@ -2087,6 +2098,31 @@ static void sd_read_block_characteristics(struct scsi_disk *sdkp) | |||
2087 | kfree(buffer); | 2098 | kfree(buffer); |
2088 | } | 2099 | } |
2089 | 2100 | ||
2101 | /** | ||
2102 | * sd_read_thin_provisioning - Query thin provisioning VPD page | ||
2103 | * @disk: disk to query | ||
2104 | */ | ||
2105 | static void sd_read_thin_provisioning(struct scsi_disk *sdkp) | ||
2106 | { | ||
2107 | unsigned char *buffer; | ||
2108 | const int vpd_len = 8; | ||
2109 | |||
2110 | if (sdkp->thin_provisioning == 0) | ||
2111 | return; | ||
2112 | |||
2113 | buffer = kmalloc(vpd_len, GFP_KERNEL); | ||
2114 | |||
2115 | if (!buffer || scsi_get_vpd_page(sdkp->device, 0xb2, buffer, vpd_len)) | ||
2116 | goto out; | ||
2117 | |||
2118 | sdkp->tpvpd = 1; | ||
2119 | sdkp->tpu = (buffer[5] >> 7) & 1; /* UNMAP */ | ||
2120 | sdkp->tpws = (buffer[5] >> 6) & 1; /* WRITE SAME(16) with UNMAP */ | ||
2121 | |||
2122 | out: | ||
2123 | kfree(buffer); | ||
2124 | } | ||
2125 | |||
2090 | static int sd_try_extended_inquiry(struct scsi_device *sdp) | 2126 | static int sd_try_extended_inquiry(struct scsi_device *sdp) |
2091 | { | 2127 | { |
2092 | /* | 2128 | /* |
@@ -2138,6 +2174,7 @@ static int sd_revalidate_disk(struct gendisk *disk) | |||
2138 | sd_read_capacity(sdkp, buffer); | 2174 | sd_read_capacity(sdkp, buffer); |
2139 | 2175 | ||
2140 | if (sd_try_extended_inquiry(sdp)) { | 2176 | if (sd_try_extended_inquiry(sdp)) { |
2177 | sd_read_thin_provisioning(sdkp); | ||
2141 | sd_read_block_limits(sdkp); | 2178 | sd_read_block_limits(sdkp); |
2142 | sd_read_block_characteristics(sdkp); | 2179 | sd_read_block_characteristics(sdkp); |
2143 | } | 2180 | } |
@@ -2250,11 +2287,10 @@ static void sd_probe_async(void *data, async_cookie_t cookie) | |||
2250 | index = sdkp->index; | 2287 | index = sdkp->index; |
2251 | dev = &sdp->sdev_gendev; | 2288 | dev = &sdp->sdev_gendev; |
2252 | 2289 | ||
2253 | if (index < SD_MAX_DISKS) { | 2290 | gd->major = sd_major((index & 0xf0) >> 4); |
2254 | gd->major = sd_major((index & 0xf0) >> 4); | 2291 | gd->first_minor = ((index & 0xf) << 4) | (index & 0xfff00); |
2255 | gd->first_minor = ((index & 0xf) << 4) | (index & 0xfff00); | 2292 | gd->minors = SD_MINORS; |
2256 | gd->minors = SD_MINORS; | 2293 | |
2257 | } | ||
2258 | gd->fops = &sd_fops; | 2294 | gd->fops = &sd_fops; |
2259 | gd->private_data = &sdkp->driver; | 2295 | gd->private_data = &sdkp->driver; |
2260 | gd->queue = sdkp->device->request_queue; | 2296 | gd->queue = sdkp->device->request_queue; |
@@ -2344,6 +2380,12 @@ static int sd_probe(struct device *dev) | |||
2344 | if (error) | 2380 | if (error) |
2345 | goto out_put; | 2381 | goto out_put; |
2346 | 2382 | ||
2383 | if (index >= SD_MAX_DISKS) { | ||
2384 | error = -ENODEV; | ||
2385 | sdev_printk(KERN_WARNING, sdp, "SCSI disk (sd) name space exhausted.\n"); | ||
2386 | goto out_free_index; | ||
2387 | } | ||
2388 | |||
2347 | error = sd_format_disk_name("sd", index, gd->disk_name, DISK_NAME_LEN); | 2389 | error = sd_format_disk_name("sd", index, gd->disk_name, DISK_NAME_LEN); |
2348 | if (error) | 2390 | if (error) |
2349 | goto out_free_index; | 2391 | goto out_free_index; |