diff options
Diffstat (limited to 'drivers/scsi/scsi_debug.c')
-rw-r--r-- | drivers/scsi/scsi_debug.c | 490 |
1 files changed, 460 insertions, 30 deletions
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index fb9af207d61..0b575c87100 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -44,12 +44,15 @@ #include <net/checksum.h> +#include <asm/unaligned.h> + #include <scsi/scsi.h> #include <scsi/scsi_cmnd.h> #include <scsi/scsi_device.h> #include <scsi/scsi_host.h> #include <scsi/scsicam.h> #include <scsi/scsi_eh.h> +#include <scsi/scsi_dbg.h> #include "sd.h" #include "scsi_logging.h" @@ -64,6 +67,7 @@ static const char * scsi_debug_version_date = "20070104"; #define PARAMETER_LIST_LENGTH_ERR 0x1a #define INVALID_OPCODE 0x20 #define ADDR_OUT_OF_RANGE 0x21 +#define INVALID_COMMAND_OPCODE 0x20 #define INVALID_FIELD_IN_CDB 0x24 #define INVALID_FIELD_IN_PARAM_LIST 0x26 #define POWERON_RESET 0x29 @@ -103,6 +107,10 @@ static const char * scsi_debug_version_date = "20070104"; #define DEF_ATO 1 #define DEF_PHYSBLK_EXP 0 #define DEF_LOWEST_ALIGNED 0 +#define DEF_UNMAP_MAX_BLOCKS 0 +#define DEF_UNMAP_MAX_DESC 0 +#define DEF_UNMAP_GRANULARITY 0 +#define DEF_UNMAP_ALIGNMENT 0 /* bit mask values for scsi_debug_opts */ #define SCSI_DEBUG_OPT_NOISE 1 @@ -160,6 +168,10 @@ static int scsi_debug_guard = DEF_GUARD; static int scsi_debug_ato = DEF_ATO; static int scsi_debug_physblk_exp = DEF_PHYSBLK_EXP; static int scsi_debug_lowest_aligned = DEF_LOWEST_ALIGNED; +static int scsi_debug_unmap_max_desc = DEF_UNMAP_MAX_DESC; +static int scsi_debug_unmap_max_blocks = DEF_UNMAP_MAX_BLOCKS; +static int scsi_debug_unmap_granularity = DEF_UNMAP_GRANULARITY; +static int scsi_debug_unmap_alignment = DEF_UNMAP_ALIGNMENT; static int scsi_debug_cmnd_count = 0; @@ -180,7 +192,7 @@ static int sdebug_sectors_per; /* sectors per cylinder */ #define SDEBUG_SENSE_LEN 32 #define SCSI_DEBUG_CANQUEUE 255 -#define SCSI_DEBUG_MAX_CMD_LEN 16 +#define SCSI_DEBUG_MAX_CMD_LEN 32 struct sdebug_dev_info { struct list_head dev_list; @@ -221,7 +233,9 @@ static struct sdebug_queued_cmd queued_arr[SCSI_DEBUG_CANQUEUE]; static unsigned char * fake_storep; /* ramdisk storage */ static unsigned char *dif_storep; /* protection info */ +static void *map_storep; /* provisioning map */ +static unsigned long map_size; static int num_aborts = 0; static int num_dev_resets = 0; static int num_bus_resets = 0; @@ -296,9 +310,26 @@ static void mk_sense_buffer(struct sdebug_dev_info *devip, int key, } static void get_data_transfer_info(unsigned char *cmd, - unsigned long long *lba, unsigned int *num) + unsigned long long *lba, unsigned int *num, + u32 *ei_lba) { + *ei_lba = 0; + switch (*cmd) { + case VARIABLE_LENGTH_CMD: + *lba = (u64)cmd[19] | (u64)cmd[18] << 8 | + (u64)cmd[17] << 16 | (u64)cmd[16] << 24 | + (u64)cmd[15] << 32 | (u64)cmd[14] << 40 | + (u64)cmd[13] << 48 | (u64)cmd[12] << 56; + + *ei_lba = (u32)cmd[23] | (u32)cmd[22] << 8 | + (u32)cmd[21] << 16 | (u32)cmd[20] << 24; + + *num = (u32)cmd[31] | (u32)cmd[30] << 8 | (u32)cmd[29] << 16 | + (u32)cmd[28] << 24; + break; + + case WRITE_SAME_16: case WRITE_16: case READ_16: *lba = (u64)cmd[9] | (u64)cmd[8] << 8 | @@ -317,6 +348,7 @@ static void get_data_transfer_info(unsigned char *cmd, *num = (u32)cmd[9] | (u32)cmd[8] << 8 | (u32)cmd[7] << 16 | (u32)cmd[6] << 24; break; + case WRITE_SAME: case WRITE_10: case READ_10: case XDWRITEREAD_10: @@ -653,10 +685,12 @@ static int inquiry_evpd_89(unsigned char * arr) } +/* Block limits VPD page (SBC-3) */ static unsigned char vpdb0_data[] = { - /* from 4th byte */ 0,0,0,4, - 0,0,0x4,0, - 0,0,0,64, + /* from 4th byte */ 0,0,0,4, 0,0,0x4,0, 0,0,0,64, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, }; static int inquiry_evpd_b0(unsigned char * arr) @@ -673,14 +707,40 @@ static int inquiry_evpd_b0(unsigned char * arr) arr[6] = (sdebug_store_sectors >> 8) & 0xff; arr[7] = sdebug_store_sectors & 0xff; } + + if (scsi_debug_unmap_max_desc) { + unsigned int blocks; + + if (scsi_debug_unmap_max_blocks) + blocks = scsi_debug_unmap_max_blocks; + else + blocks = 0xffffffff; + + put_unaligned_be32(blocks, &arr[16]); + put_unaligned_be32(scsi_debug_unmap_max_desc, &arr[20]); + } + + if (scsi_debug_unmap_alignment) { + put_unaligned_be32(scsi_debug_unmap_alignment, &arr[28]); + arr[28] |= 0x80; /* UGAVALID */ + } + + if (scsi_debug_unmap_granularity) { + put_unaligned_be32(scsi_debug_unmap_granularity, &arr[24]); + return 0x3c; /* Mandatory page length for thin provisioning */ + } + return sizeof(vpdb0_data); } +/* Block device characteristics VPD page (SBC-3) */ static int inquiry_evpd_b1(unsigned char *arr) { memset(arr, 0, 0x3c); arr[0] = 0; - arr[1] = 1; + arr[1] = 1; /* non rotating medium (e.g. solid state) */ + arr[2] = 0; + arr[3] = 5; /* less than 1.8" */ return 0x3c; } @@ -956,6 +1016,10 @@ static int resp_readcap16(struct scsi_cmnd * scp, arr[11] = scsi_debug_sector_size & 0xff; arr[13] = scsi_debug_physblk_exp & 0xf; arr[14] = (scsi_debug_lowest_aligned >> 8) & 0x3f; + + if (scsi_debug_unmap_granularity) + arr[14] |= 0x80; /* TPE */ + arr[15] = scsi_debug_lowest_aligned & 0xff; if (scsi_debug_dif) { @@ -1589,7 +1653,7 @@ static int do_device_access(struct scsi_cmnd *scmd, } static int prot_verify_read(struct scsi_cmnd *SCpnt, sector_t start_sec, - unsigned int sectors) + unsigned int sectors, u32 ei_lba) { unsigned int i, resid; struct scatterlist *psgl; @@ -1636,13 +1700,23 @@ static int prot_verify_read(struct scsi_cmnd *SCpnt, sector_t start_sec, return 0x01; } - if (scsi_debug_dif != SD_DIF_TYPE3_PROTECTION && + if (scsi_debug_dif == SD_DIF_TYPE1_PROTECTION && be32_to_cpu(sdt[i].ref_tag) != (sector & 0xffffffff)) { printk(KERN_ERR "%s: REF check failed on sector %lu\n", __func__, (unsigned long)sector); dif_errors++; return 0x03; } + + if (scsi_debug_dif == SD_DIF_TYPE2_PROTECTION && + be32_to_cpu(sdt[i].ref_tag) != ei_lba) { + printk(KERN_ERR "%s: REF check failed on sector %lu\n", + __func__, (unsigned long)sector); + dif_errors++; + return 0x03; + } + + ei_lba++; } resid = sectors * 8; /* Bytes of protection data to copy into sgl */ @@ -1670,7 +1744,8 @@ static int prot_verify_read(struct scsi_cmnd *SCpnt, sector_t start_sec, } static int resp_read(struct scsi_cmnd *SCpnt, unsigned long long lba, - unsigned int num, struct sdebug_dev_info *devip) + unsigned int num, struct sdebug_dev_info *devip, + u32 ei_lba) { unsigned long iflags; int ret; @@ -1699,7 +1774,7 @@ static int resp_read(struct scsi_cmnd *SCpnt, unsigned long long lba, /* DIX + T10 DIF */ if (scsi_debug_dix && scsi_prot_sg_count(SCpnt)) { - int prot_ret = prot_verify_read(SCpnt, lba, num); + int prot_ret = prot_verify_read(SCpnt, lba, num, ei_lba); if (prot_ret) { mk_sense_buffer(devip, ABORTED_COMMAND, 0x10, prot_ret); @@ -1735,7 +1810,7 @@ void dump_sector(unsigned char *buf, int len) } static int prot_verify_write(struct scsi_cmnd *SCpnt, sector_t start_sec, - unsigned int sectors) + unsigned int sectors, u32 ei_lba) { int i, j, ret; struct sd_dif_tuple *sdt; @@ -1749,11 +1824,6 @@ static int prot_verify_write(struct scsi_cmnd *SCpnt, sector_t start_sec, sector = do_div(tmp_sec, sdebug_store_sectors); - if (((SCpnt->cmnd[1] >> 5) & 7) != 1) { - printk(KERN_WARNING "scsi_debug: WRPROTECT != 1\n"); - return 0; - } - BUG_ON(scsi_sg_count(SCpnt) == 0); BUG_ON(scsi_prot_sg_count(SCpnt) == 0); @@ -1808,7 +1878,7 @@ static int prot_verify_write(struct scsi_cmnd *SCpnt, sector_t start_sec, goto out; } - if (scsi_debug_dif != SD_DIF_TYPE3_PROTECTION && + if (scsi_debug_dif == SD_DIF_TYPE1_PROTECTION && be32_to_cpu(sdt->ref_tag) != (start_sec & 0xffffffff)) { printk(KERN_ERR @@ -1819,6 +1889,16 @@ static int prot_verify_write(struct scsi_cmnd *SCpnt, sector_t start_sec, goto out; } + if (scsi_debug_dif == SD_DIF_TYPE2_PROTECTION && + be32_to_cpu(sdt->ref_tag) != ei_lba) { + printk(KERN_ERR + "%s: REF check failed on sector %lu\n", + __func__, (unsigned long)sector); + ret = 0x03; + dump_sector(daddr, scsi_debug_sector_size); + goto out; + } + /* Would be great to copy this in bigger * chunks. However, for the sake of * correctness we need to verify each sector @@ -1832,6 +1912,7 @@ static int prot_verify_write(struct scsi_cmnd *SCpnt, sector_t start_sec, sector = 0; /* Force wrap */ start_sec++; + ei_lba++; daddr += scsi_debug_sector_size; ppage_offset += sizeof(struct sd_dif_tuple); } @@ -1852,8 +1933,73 @@ out: return ret; } +static unsigned int map_state(sector_t lba, unsigned int *num) +{ + unsigned int granularity, alignment, mapped; + sector_t block, next, end; + + granularity = scsi_debug_unmap_granularity; + alignment = granularity - scsi_debug_unmap_alignment; + block = lba + alignment; + do_div(block, granularity); + + mapped = test_bit(block, map_storep); + + if (mapped) + next = find_next_zero_bit(map_storep, map_size, block); + else + next = find_next_bit(map_storep, map_size, block); + + end = next * granularity - scsi_debug_unmap_alignment; + *num = end - lba; + + return mapped; +} + +static void map_region(sector_t lba, unsigned int len) +{ + unsigned int granularity, alignment; + sector_t end = lba + len; + + granularity = scsi_debug_unmap_granularity; + alignment = granularity - scsi_debug_unmap_alignment; + + while (lba < end) { + sector_t block, rem; + + block = lba + alignment; + rem = do_div(block, granularity); + + set_bit(block, map_storep); + + lba += granularity - rem; + } +} + +static void unmap_region(sector_t lba, unsigned int len) +{ + unsigned int granularity, alignment; + sector_t end = lba + len; + + granularity = scsi_debug_unmap_granularity; + alignment = granularity - scsi_debug_unmap_alignment; + + while (lba < end) { + sector_t block, rem; + + block = lba + alignment; + rem = do_div(block, granularity); + + if (rem == 0 && lba + granularity <= end) + clear_bit(block, map_storep); + + lba += granularity - rem; + } +} + static int resp_write(struct scsi_cmnd *SCpnt, unsigned long long lba, - unsigned int num, struct sdebug_dev_info *devip) + unsigned int num, struct sdebug_dev_info *devip, + u32 ei_lba) { unsigned long iflags; int ret; @@ -1864,7 +2010,7 @@ static int resp_write(struct scsi_cmnd *SCpnt, unsigned long long lba, /* DIX + T10 DIF */ if (scsi_debug_dix && scsi_prot_sg_count(SCpnt)) { - int prot_ret = prot_verify_write(SCpnt, lba, num); + int prot_ret = prot_verify_write(SCpnt, lba, num, ei_lba); if (prot_ret) { mk_sense_buffer(devip, ILLEGAL_REQUEST, 0x10, prot_ret); @@ -1874,6 +2020,8 @@ static int resp_write(struct scsi_cmnd *SCpnt, unsigned long long lba, write_lock_irqsave(&atomic_rw, iflags); ret = do_device_access(SCpnt, devip, lba, num, 1); + if (scsi_debug_unmap_granularity) + map_region(lba, num); write_unlock_irqrestore(&atomic_rw, iflags); if (-1 == ret) return (DID_ERROR << 16); @@ -1881,9 +2029,143 @@ static int resp_write(struct scsi_cmnd *SCpnt, unsigned long long lba, (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)) printk(KERN_INFO "scsi_debug: write: cdb indicated=%u, " " IO sent=%d bytes\n", num * scsi_debug_sector_size, ret); + return 0; } +static int resp_write_same(struct scsi_cmnd *scmd, unsigned long long lba, + unsigned int num, struct sdebug_dev_info *devip, + u32 ei_lba, unsigned int unmap) +{ + unsigned long iflags; + unsigned long long i; + int ret; + + ret = check_device_access_params(devip, lba, num); + if (ret) + return ret; + + write_lock_irqsave(&atomic_rw, iflags); + + if (unmap && scsi_debug_unmap_granularity) { + unmap_region(lba, num); + goto out; + } + + /* Else fetch one logical block */ + ret = fetch_to_dev_buffer(scmd, + fake_storep + (lba * scsi_debug_sector_size), + scsi_debug_sector_size); + + if (-1 == ret) { + write_unlock_irqrestore(&atomic_rw, iflags); + return (DID_ERROR << 16); + } else if ((ret < (num * scsi_debug_sector_size)) && + (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)) + printk(KERN_INFO "scsi_debug: write same: cdb indicated=%u, " + " IO sent=%d bytes\n", num * scsi_debug_sector_size, ret); + + /* Copy first sector to remaining blocks */ + for (i = 1 ; i < num ; i++) + memcpy(fake_storep + ((lba + i) * scsi_debug_sector_size), + fake_storep + (lba * scsi_debug_sector_size), + scsi_debug_sector_size); + + if (scsi_debug_unmap_granularity) + map_region(lba, num); +out: + write_unlock_irqrestore(&atomic_rw, iflags); + + return 0; +} + +struct unmap_block_desc { + __be64 lba; + __be32 blocks; + __be32 __reserved; +}; + +static int resp_unmap(struct scsi_cmnd * scmd, struct sdebug_dev_info * devip) +{ + unsigned char *buf; + struct unmap_block_desc *desc; + unsigned int i, payload_len, descriptors; + int ret; + + ret = check_readiness(scmd, 1, devip); + if (ret) + return ret; + + payload_len = get_unaligned_be16(&scmd->cmnd[7]); + BUG_ON(scsi_bufflen(scmd) != payload_len); + + descriptors = (payload_len - 8) / 16; + + buf = kmalloc(scsi_bufflen(scmd), GFP_ATOMIC); + if (!buf) + return check_condition_result; + + scsi_sg_copy_to_buffer(scmd, buf, scsi_bufflen(scmd)); + + BUG_ON(get_unaligned_be16(&buf[0]) != payload_len - 2); + BUG_ON(get_unaligned_be16(&buf[2]) != descriptors * 16); + + desc = (void *)&buf[8]; + + for (i = 0 ; i < descriptors ; i++) { + unsigned long long lba = get_unaligned_be64(&desc[i].lba); + unsigned int num = get_unaligned_be32(&desc[i].blocks); + + ret = check_device_access_params(devip, lba, num); + if (ret) + goto out; + + unmap_region(lba, num); + } + + ret = 0; + +out: + kfree(buf); + + return ret; +} + +#define SDEBUG_GET_LBA_STATUS_LEN 32 + +static int resp_get_lba_status(struct scsi_cmnd * scmd, + struct sdebug_dev_info * devip) +{ + unsigned long long lba; + unsigned int alloc_len, mapped, num; + unsigned char arr[SDEBUG_GET_LBA_STATUS_LEN]; + int ret; + + ret = check_readiness(scmd, 1, devip); + if (ret) + return ret; + + lba = get_unaligned_be64(&scmd->cmnd[2]); + alloc_len = get_unaligned_be32(&scmd->cmnd[10]); + + if (alloc_len < 24) + return 0; + + ret = check_device_access_params(devip, lba, 1); + if (ret) + return ret; + + mapped = map_state(lba, &num); + + memset(arr, 0, SDEBUG_GET_LBA_STATUS_LEN); + put_unaligned_be32(16, &arr[0]); /* Parameter Data Length */ + put_unaligned_be64(lba, &arr[8]); /* LBA */ + put_unaligned_be32(num, &arr[16]); /* Number of blocks */ + arr[20] = !mapped; /* mapped = 0, unmapped = 1 */ + + return fill_from_dev_buffer(scmd, arr, SDEBUG_GET_LBA_STATUS_LEN); +} + #define SDEBUG_RLUN_ARR_SZ 256 static int resp_report_luns(struct scsi_cmnd * scp, @@ -2394,6 +2676,10 @@ module_param_named(guard, scsi_debug_guard, int, S_IRUGO); module_param_named(ato, scsi_debug_ato, int, S_IRUGO); module_param_named(physblk_exp, scsi_debug_physblk_exp, int, S_IRUGO); module_param_named(lowest_aligned, scsi_debug_lowest_aligned, int, S_IRUGO); +module_param_named(unmap_max_blocks, scsi_debug_unmap_max_blocks, int, S_IRUGO); +module_param_named(unmap_max_desc, scsi_debug_unmap_max_desc, int, S_IRUGO); +module_param_named(unmap_granularity, scsi_debug_unmap_granularity, int, S_IRUGO); +module_param_named(unmap_alignment, scsi_debug_unmap_alignment, int, S_IRUGO); MODULE_AUTHOR("Eric Youngdale + Douglas Gilbert"); MODULE_DESCRIPTION("SCSI debug adapter driver"); @@ -2422,6 +2708,10 @@ MODULE_PARM_DESC(dix, "data integrity extensions mask (def=0)"); MODULE_PARM_DESC(dif, "data integrity field type: 0-3 (def=0)"); MODULE_PARM_DESC(guard, "protection checksum: 0=crc, 1=ip (def=0)"); MODULE_PARM_DESC(ato, "application tag ownership: 0=disk 1=host (def=1)"); +MODULE_PARM_DESC(unmap_max_blocks, "max # of blocks can be unmapped in one cmd (def=0)"); +MODULE_PARM_DESC(unmap_max_desc, "max # of ranges that can be unmapped in one cmd (def=0)"); +MODULE_PARM_DESC(unmap_granularity, "thin provisioning granularity in blocks (def=0)"); +MODULE_PARM_DESC(unmap_alignment, "lowest aligned thin provisioning lba (def=0)"); static char sdebug_info[256]; @@ -2780,6 +3070,23 @@ static ssize_t sdebug_ato_show(struct device_driver *ddp, char *buf) } DRIVER_ATTR(ato, S_IRUGO, sdebug_ato_show, NULL); +static ssize_t sdebug_map_show(struct device_driver *ddp, char *buf) +{ + ssize_t count; + + if (scsi_debug_unmap_granularity == 0) + return scnprintf(buf, PAGE_SIZE, "0-%u\n", + sdebug_store_sectors); + + count = bitmap_scnlistprintf(buf, PAGE_SIZE, map_storep, map_size); + + buf[count++] = '\n'; + buf[count++] = 0; + + return count; +} +DRIVER_ATTR(map, S_IRUGO, sdebug_map_show, NULL); + /* Note: The following function creates attribute files in the /sys/bus/pseudo/drivers/scsi_debug directory. The advantage of these @@ -2811,11 +3118,13 @@ static int do_create_driverfs_files(void) ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_dif); ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_guard); ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_ato); + ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_map); return ret; } static void do_remove_driverfs_files(void) { + driver_remove_file(&sdebug_driverfs_driver, &driver_attr_map); driver_remove_file(&sdebug_driverfs_driver, &driver_attr_ato); driver_remove_file(&sdebug_driverfs_driver, &driver_attr_guard); driver_remove_file(&sdebug_driverfs_driver, &driver_attr_dif); @@ -2872,11 +3181,12 @@ static int __init scsi_debug_init(void) case SD_DIF_TYPE0_PROTECTION: case SD_DIF_TYPE1_PROTECTION: + case SD_DIF_TYPE2_PROTECTION: case SD_DIF_TYPE3_PROTECTION: break; default: - printk(KERN_ERR "scsi_debug_init: dif must be 0, 1 or 3\n"); + printk(KERN_ERR "scsi_debug_init: dif must be 0, 1, 2 or 3\n"); return -EINVAL; } @@ -2952,6 +3262,36 @@ static int __init scsi_debug_init(void) memset(dif_storep, 0xff, dif_size); } + if (scsi_debug_unmap_granularity) { + unsigned int map_bytes; + + if (scsi_debug_unmap_granularity < scsi_debug_unmap_alignment) { + printk(KERN_ERR + "%s: ERR: unmap_granularity < unmap_alignment\n", + __func__); + return -EINVAL; + } + + map_size = (sdebug_store_sectors / scsi_debug_unmap_granularity); + map_bytes = map_size >> 3; + map_storep = vmalloc(map_bytes); + + printk(KERN_INFO "scsi_debug_init: %lu provisioning blocks\n", + map_size); + + if (map_storep == NULL) { + printk(KERN_ERR "scsi_debug_init: out of mem. (MAP)\n"); + ret = -ENOMEM; + goto free_vm; + } + + memset(map_storep, 0x0, map_bytes); + + /* Map first 1KB for partition table */ + if (scsi_debug_num_parts) + map_region(0, 2); + } + ret = device_register(&pseudo_primary); if (ret < 0) { printk(KERN_WARNING "scsi_debug: device_register error: %d\n", @@ -3004,6 +3344,8 @@ bus_unreg: dev_unreg: device_unregister(&pseudo_primary); free_vm: + if (map_storep) + vfree(map_storep); if (dif_storep) vfree(dif_storep); vfree(fake_storep); @@ -3121,6 +3463,7 @@ int scsi_debug_queuecommand(struct scsi_cmnd *SCpnt, done_funct_t done) int len, k; unsigned int num; unsigned long long lba; + u32 ei_lba; int errsts = 0; int target = SCpnt->device->id; struct sdebug_dev_info *devip = NULL; @@ -3129,6 +3472,7 @@ int scsi_debug_queuecommand(struct scsi_cmnd *SCpnt, done_funct_t done) int inj_dif = 0; int inj_dix = 0; int delay_override = 0; + int unmap = 0; scsi_set_resid(SCpnt, 0); if ((SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) && cmd) { @@ -3234,13 +3578,21 @@ int scsi_debug_queuecommand(struct scsi_cmnd *SCpnt, done_funct_t done) errsts = resp_readcap(SCpnt, devip); break; case SERVICE_ACTION_IN: - if (SAI_READ_CAPACITY_16 != cmd[1]) { + if (cmd[1] == SAI_READ_CAPACITY_16) + errsts = resp_readcap16(SCpnt, devip); + else if (cmd[1] == SAI_GET_LBA_STATUS) { + + if (scsi_debug_unmap_max_desc == 0) { + mk_sense_buffer(devip, ILLEGAL_REQUEST, + INVALID_COMMAND_OPCODE, 0); + errsts = check_condition_result; + } else + errsts = resp_get_lba_status(SCpnt, devip); + } else { mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_OPCODE, 0); errsts = check_condition_result; - break; } - errsts = resp_readcap16(SCpnt, devip); break; case MAINTENANCE_IN: if (MI_REPORT_TARGET_PGS != cmd[1]) { @@ -3254,14 +3606,30 @@ int scsi_debug_queuecommand(struct scsi_cmnd *SCpnt, done_funct_t done) case READ_16: case READ_12: case READ_10: + /* READ{10,12,16} and DIF Type 2 are natural enemies */ + if (scsi_debug_dif == SD_DIF_TYPE2_PROTECTION && + cmd[1] & 0xe0) { + mk_sense_buffer(devip, ILLEGAL_REQUEST, + INVALID_COMMAND_OPCODE, 0); + errsts = check_condition_result; + break; + } + + if ((scsi_debug_dif == SD_DIF_TYPE1_PROTECTION || + scsi_debug_dif == SD_DIF_TYPE3_PROTECTION) && + (cmd[1] & 0xe0) == 0) + printk(KERN_ERR "Unprotected RD/WR to DIF device\n"); + + /* fall through */ case READ_6: +read: errsts = check_readiness(SCpnt, 0, devip); if (errsts) break; if (scsi_debug_fake_rw) break; - get_data_transfer_info(cmd, &lba, &num); - errsts = resp_read(SCpnt, lba, num, devip); + get_data_transfer_info(cmd, &lba, &num, &ei_lba); + errsts = resp_read(SCpnt, lba, num, devip, ei_lba); if (inj_recovered && (0 == errsts)) { mk_sense_buffer(devip, RECOVERED_ERROR, THRESHOLD_EXCEEDED, 0); @@ -3288,14 +3656,30 @@ int scsi_debug_queuecommand(struct scsi_cmnd *SCpnt, done_funct_t done) case WRITE_16: case WRITE_12: case WRITE_10: + /* WRITE{10,12,16} and DIF Type 2 are natural enemies */ + if (scsi_debug_dif == SD_DIF_TYPE2_PROTECTION && + cmd[1] & 0xe0) { + mk_sense_buffer(devip, ILLEGAL_REQUEST, + INVALID_COMMAND_OPCODE, 0); + errsts = check_condition_result; + break; + } + + if ((scsi_debug_dif == SD_DIF_TYPE1_PROTECTION || + scsi_debug_dif == SD_DIF_TYPE3_PROTECTION) && + (cmd[1] & 0xe0) == 0) + printk(KERN_ERR "Unprotected RD/WR to DIF device\n"); + + /* fall through */ case WRITE_6: +write: errsts = check_readiness(SCpnt, 0, devip); if (errsts) break; if (scsi_debug_fake_rw) break; - get_data_transfer_info(cmd, &lba, &num); - errsts = resp_write(SCpnt, lba, num, devip); + get_data_transfer_info(cmd, &lba, &num, &ei_lba); + errsts = resp_write(SCpnt, lba, num, devip, ei_lba); if (inj_recovered && (0 == errsts)) { mk_sense_buffer(devip, RECOVERED_ERROR, THRESHOLD_EXCEEDED, 0); @@ -3308,6 +3692,29 @@ int scsi_debug_queuecommand(struct scsi_cmnd *SCpnt, done_funct_t done) errsts = illegal_condition_result; } break; + case WRITE_SAME_16: + if (cmd[1] & 0x8) + unmap = 1; + /* fall through */ + case WRITE_SAME: + errsts = check_readiness(SCpnt, 0, devip); + if (errsts) + break; + get_data_transfer_info(cmd, &lba, &num, &ei_lba); + errsts = resp_write_same(SCpnt, lba, num, devip, ei_lba, unmap); + break; + case UNMAP: + errsts = check_readiness(SCpnt, 0, devip); + if (errsts) + break; + + if (scsi_debug_unmap_max_desc == 0) { + mk_sense_buffer(devip, ILLEGAL_REQUEST, + INVALID_COMMAND_OPCODE, 0); + errsts = check_condition_result; + } else + errsts = resp_unmap(SCpnt, devip); + break; case MODE_SENSE: case MODE_SENSE_10: errsts = resp_mode_sense(SCpnt, target, devip); @@ -3341,15 +3748,38 @@ int scsi_debug_queuecommand(struct scsi_cmnd *SCpnt, done_funct_t done) break; if (scsi_debug_fake_rw) break; - get_data_transfer_info(cmd, &lba, &num); - errsts = resp_read(SCpnt, lba, num, devip); + get_data_transfer_info(cmd, &lba, &num, &ei_lba); + errsts = resp_read(SCpnt, lba, num, devip, ei_lba); if (errsts) break; - errsts = resp_write(SCpnt, lba, num, devip); + errsts = resp_write(SCpnt, lba, num, devip, ei_lba); if (errsts) break; errsts = resp_xdwriteread(SCpnt, lba, num, devip); break; + case VARIABLE_LENGTH_CMD: + if (scsi_debug_dif == SD_DIF_TYPE2_PROTECTION) { + + if ((cmd[10] & 0xe0) == 0) + printk(KERN_ERR + "Unprotected RD/WR to DIF device\n"); + + if (cmd[9] == READ_32) { + BUG_ON(SCpnt->cmd_len < 32); + goto read; + } + + if (cmd[9] == WRITE_32) { + BUG_ON(SCpnt->cmd_len < 32); + goto write; + } + } + + mk_sense_buffer(devip, ILLEGAL_REQUEST, + INVALID_FIELD_IN_CDB, 0); + errsts = check_condition_result; + break; + default: if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) printk(KERN_INFO "scsi_debug: Opcode: 0x%x not " |