@@ -876,6 +876,30 @@ static blk_status_t sd_setup_unmap_cmnd(struct scsi_cmnd *cmd)
return scsi_alloc_sgtables(cmd);
}
+static void sd_config_atomic(struct scsi_disk *sdkp)
+{
+ unsigned int logical_block_size = sdkp->device->sector_size;
+ struct request_queue *q = sdkp->disk->queue;
+
+ if (sdkp->max_atomic) {
+ unsigned int physical_block_size_sectors =
+ sdkp->physical_block_size / sdkp->device->sector_size;
+ unsigned int max_atomic = max_t(unsigned int,
+ rounddown_pow_of_two(sdkp->max_atomic),
+ rounddown_pow_of_two(sdkp->max_atomic_with_boundary));
+ unsigned int unit_max = min_t(unsigned int, max_atomic,
+ rounddown_pow_of_two(sdkp->max_atomic_boundary));
+ unsigned int unit_min = sdkp->atomic_granularity ?
+ rounddown_pow_of_two(sdkp->atomic_granularity) :
+ physical_block_size_sectors;
+
+ blk_queue_atomic_write_max_bytes(q, max_atomic * logical_block_size);
+ blk_queue_atomic_write_unit_min(q, unit_min);
+ blk_queue_atomic_write_unit_max(q, unit_max);
+ blk_queue_atomic_write_boundary(q, 0);
+ }
+}
+
static blk_status_t sd_setup_write_same16_cmnd(struct scsi_cmnd *cmd,
bool unmap)
{
@@ -2922,7 +2946,7 @@ static void sd_read_block_limits(struct scsi_disk *sdkp)
sdkp->max_ws_blocks = (u32)get_unaligned_be64(&vpd->data[36]);
if (!sdkp->lbpme)
- goto out;
+ goto read_atomics;
lba_count = get_unaligned_be32(&vpd->data[20]);
desc_count = get_unaligned_be32(&vpd->data[24]);
@@ -2953,6 +2977,14 @@ static void sd_read_block_limits(struct scsi_disk *sdkp)
else
sd_config_discard(sdkp, SD_LBP_DISABLE);
}
+read_atomics:
+ sdkp->max_atomic = get_unaligned_be32(&vpd->data[44]);
+ sdkp->atomic_alignment = get_unaligned_be32(&vpd->data[48]);
+ sdkp->atomic_granularity = get_unaligned_be32(&vpd->data[52]);
+ sdkp->max_atomic_with_boundary = get_unaligned_be32(&vpd->data[56]);
+ sdkp->max_atomic_boundary = get_unaligned_be32(&vpd->data[60]);
+
+ sd_config_atomic(sdkp);
}
out:
@@ -121,6 +121,13 @@ struct scsi_disk {
u32 max_unmap_blocks;
u32 unmap_granularity;
u32 unmap_alignment;
+
+ u32 max_atomic;
+ u32 atomic_alignment;
+ u32 atomic_granularity;
+ u32 max_atomic_with_boundary;
+ u32 max_atomic_boundary;
+
u32 index;
unsigned int physical_block_size;
unsigned int max_medium_access_timeouts;
Also update block layer request queue sysfs properties. See sbc4r22 section 6.6.4 - Block limits VPD page. Signed-off-by: John Garry <john.g.garry@oracle.com> --- drivers/scsi/sd.c | 34 +++++++++++++++++++++++++++++++++- drivers/scsi/sd.h | 7 +++++++ 2 files changed, 40 insertions(+), 1 deletion(-)