From 48c3bee1ace64a23f42dc65b9aec3fa8389a2b6c Mon Sep 17 00:00:00 2001 From: mav Date: Mon, 6 Oct 2014 13:21:13 +0000 Subject: [PATCH] MFC r271839: Add support for "no Data-Out Buffer" (NDOB) flag of WRITE SAME (16) command. --- sys/cam/ctl/ctl.c | 11 ++++++++++- sys/cam/ctl/ctl_backend_block.c | 2 +- sys/cam/ctl/ctl_cmd_table.c | 2 +- sys/cam/scsi/scsi_all.h | 1 + 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/sys/cam/ctl/ctl.c b/sys/cam/ctl/ctl.c index 7690d0520a7f..84995321005e 100644 --- a/sys/cam/ctl/ctl.c +++ b/sys/cam/ctl/ctl.c @@ -5995,6 +5995,14 @@ ctl_write_same(struct ctl_scsiio *ctsio) break; /* NOTREACHED */ } + /* NDOB flag can be used only together with UNMAP */ + if ((byte2 & (SWS_NDOB | SWS_UNMAP)) == SWS_NDOB) { + ctl_set_invalid_field(ctsio, /*sks_valid*/ 1, + /*command*/ 1, /*field*/ 1, /*bit_valid*/ 1, /*bit*/ 0); + ctl_done((union ctl_io *)ctsio); + return (CTL_RETVAL_COMPLETE); + } + /* * The first check is to make sure we're in bounds, the second * check is to catch wrap-around problems. If the lba + num blocks @@ -6029,7 +6037,8 @@ ctl_write_same(struct ctl_scsiio *ctsio) * If we've got a kernel request that hasn't been malloced yet, * malloc it and tell the caller the data buffer is here. */ - if ((ctsio->io_hdr.flags & CTL_FLAG_ALLOCATED) == 0) { + if ((byte2 & SWS_NDOB) == 0 && + (ctsio->io_hdr.flags & CTL_FLAG_ALLOCATED) == 0) { ctsio->kern_data_ptr = malloc(len, M_CTL, M_WAITOK);; ctsio->kern_data_len = len; ctsio->kern_total_len = len; diff --git a/sys/cam/ctl/ctl_backend_block.c b/sys/cam/ctl/ctl_backend_block.c index 912f3484e6a1..086458e853fe 100644 --- a/sys/cam/ctl/ctl_backend_block.c +++ b/sys/cam/ctl/ctl_backend_block.c @@ -1045,7 +1045,7 @@ ctl_be_block_cw_dispatch_ws(struct ctl_be_block_lun *be_lun, softc = be_lun->softc; lbalen = ARGS(beio->io); - if (lbalen->flags & ~(SWS_LBDATA | SWS_UNMAP | SWS_ANCHOR) || + if (lbalen->flags & ~(SWS_LBDATA | SWS_UNMAP | SWS_ANCHOR | SWS_NDOB) || (lbalen->flags & (SWS_UNMAP | SWS_ANCHOR) && be_lun->unmap == NULL)) { ctl_free_beio(beio); ctl_set_invalid_field(&io->scsiio, diff --git a/sys/cam/ctl/ctl_cmd_table.c b/sys/cam/ctl/ctl_cmd_table.c index 6ad90dd36883..7d679a745e3e 100644 --- a/sys/cam/ctl/ctl_cmd_table.c +++ b/sys/cam/ctl/ctl_cmd_table.c @@ -1085,7 +1085,7 @@ const struct ctl_cmd_entry ctl_cmd_table[256] = {ctl_write_same, CTL_SERIDX_WRITE, CTL_CMD_FLAG_OK_ON_SLUN | CTL_FLAG_DATA_OUT, CTL_LUN_PAT_WRITE | CTL_LUN_PAT_RANGE, - 16, {0x1a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 16, {0x1b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0x07}}, /* 94 */ diff --git a/sys/cam/scsi/scsi_all.h b/sys/cam/scsi/scsi_all.h index bd66ab3228a3..db2ee801e961 100644 --- a/sys/cam/scsi/scsi_all.h +++ b/sys/cam/scsi/scsi_all.h @@ -1030,6 +1030,7 @@ struct scsi_write_same_16 { uint8_t opcode; uint8_t byte2; +#define SWS_NDOB 0x01 uint8_t addr[8]; uint8_t length[4]; uint8_t group;