From 6235bef6f990d31d8ace9c5af337c22b888b81e3 Mon Sep 17 00:00:00 2001 From: Yang Yingliang Date: Fri, 2 Apr 2021 17:25:17 +0800 Subject: scsi: target: iscsi: Switch to kmemdup_nul() Use kmemdup_nul() helper instead of open-coding to simplify the code. Link: https://lore.kernel.org/r/20210402092517.2445595-1-yangyingliang@huawei.com Reported-by: Hulk Robot Signed-off-by: Yang Yingliang Signed-off-by: Martin K. Petersen --- drivers/target/iscsi/iscsi_target_nego.c | 4 +--- drivers/target/iscsi/iscsi_target_parameters.c | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) (limited to 'drivers/target') diff --git a/drivers/target/iscsi/iscsi_target_nego.c b/drivers/target/iscsi/iscsi_target_nego.c index 151e2949bb75..9a4a632f631d 100644 --- a/drivers/target/iscsi/iscsi_target_nego.c +++ b/drivers/target/iscsi/iscsi_target_nego.c @@ -1082,14 +1082,12 @@ int iscsi_target_locate_portal( login_req = (struct iscsi_login_req *) login->req; payload_length = ntoh24(login_req->dlength); - tmpbuf = kzalloc(payload_length + 1, GFP_KERNEL); + tmpbuf = kmemdup_nul(login->req_buf, payload_length, GFP_KERNEL); if (!tmpbuf) { pr_err("Unable to allocate memory for tmpbuf.\n"); return -1; } - memcpy(tmpbuf, login->req_buf, payload_length); - tmpbuf[payload_length] = '\0'; start = tmpbuf; end = (start + payload_length); diff --git a/drivers/target/iscsi/iscsi_target_parameters.c b/drivers/target/iscsi/iscsi_target_parameters.c index 7a461fbb1566..6bc3aaf655fc 100644 --- a/drivers/target/iscsi/iscsi_target_parameters.c +++ b/drivers/target/iscsi/iscsi_target_parameters.c @@ -1357,14 +1357,12 @@ int iscsi_decode_text_input( struct iscsi_param_list *param_list = conn->param_list; char *tmpbuf, *start = NULL, *end = NULL; - tmpbuf = kzalloc(length + 1, GFP_KERNEL); + tmpbuf = kmemdup_nul(textbuf, length, GFP_KERNEL); if (!tmpbuf) { pr_err("Unable to allocate %u + 1 bytes for tmpbuf.\n", length); return -ENOMEM; } - memcpy(tmpbuf, textbuf, length); - tmpbuf[length] = '\0'; start = tmpbuf; end = (start + length); -- cgit v1.2.3 From 6ecdafaec79d4b3388a5b017245f23a0ff9d852d Mon Sep 17 00:00:00 2001 From: Varun Prakash Date: Wed, 14 Apr 2021 18:09:09 +0530 Subject: scsi: target: cxgbit: Unmap DMA buffer before calling target_execute_cmd() Instead of calling dma_unmap_sg() after completing WRITE I/O, call dma_unmap_sg() before calling target_execute_cmd() to sync the DMA buffer. Link: https://lore.kernel.org/r/1618403949-3443-1-git-send-email-varun@chelsio.com Cc: # 5.4+ Signed-off-by: Varun Prakash Signed-off-by: Martin K. Petersen --- drivers/target/iscsi/cxgbit/cxgbit_ddp.c | 19 ++++++++++--------- drivers/target/iscsi/cxgbit/cxgbit_target.c | 21 ++++++++++++++++++--- 2 files changed, 28 insertions(+), 12 deletions(-) (limited to 'drivers/target') diff --git a/drivers/target/iscsi/cxgbit/cxgbit_ddp.c b/drivers/target/iscsi/cxgbit/cxgbit_ddp.c index af35251232eb..b044999ad002 100644 --- a/drivers/target/iscsi/cxgbit/cxgbit_ddp.c +++ b/drivers/target/iscsi/cxgbit/cxgbit_ddp.c @@ -265,12 +265,13 @@ void cxgbit_unmap_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd) struct cxgbit_cmd *ccmd = iscsit_priv_cmd(cmd); if (ccmd->release) { - struct cxgbi_task_tag_info *ttinfo = &ccmd->ttinfo; - - if (ttinfo->sgl) { + if (cmd->se_cmd.se_cmd_flags & SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC) { + put_page(sg_page(&ccmd->sg)); + } else { struct cxgbit_sock *csk = conn->context; struct cxgbit_device *cdev = csk->com.cdev; struct cxgbi_ppm *ppm = cdev2ppm(cdev); + struct cxgbi_task_tag_info *ttinfo = &ccmd->ttinfo; /* Abort the TCP conn if DDP is not complete to * avoid any possibility of DDP after freeing @@ -280,14 +281,14 @@ void cxgbit_unmap_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd) cmd->se_cmd.data_length)) cxgbit_abort_conn(csk); + if (unlikely(ttinfo->sgl)) { + dma_unmap_sg(&ppm->pdev->dev, ttinfo->sgl, + ttinfo->nents, DMA_FROM_DEVICE); + ttinfo->nents = 0; + ttinfo->sgl = NULL; + } cxgbi_ppm_ppod_release(ppm, ttinfo->idx); - - dma_unmap_sg(&ppm->pdev->dev, ttinfo->sgl, - ttinfo->nents, DMA_FROM_DEVICE); - } else { - put_page(sg_page(&ccmd->sg)); } - ccmd->release = false; } } diff --git a/drivers/target/iscsi/cxgbit/cxgbit_target.c b/drivers/target/iscsi/cxgbit/cxgbit_target.c index b926e1d6c7b8..282297ffc404 100644 --- a/drivers/target/iscsi/cxgbit/cxgbit_target.c +++ b/drivers/target/iscsi/cxgbit/cxgbit_target.c @@ -997,17 +997,18 @@ static int cxgbit_handle_iscsi_dataout(struct cxgbit_sock *csk) struct scatterlist *sg_start; struct iscsi_conn *conn = csk->conn; struct iscsi_cmd *cmd = NULL; + struct cxgbit_cmd *ccmd; + struct cxgbi_task_tag_info *ttinfo; struct cxgbit_lro_pdu_cb *pdu_cb = cxgbit_rx_pdu_cb(csk->skb); struct iscsi_data *hdr = (struct iscsi_data *)pdu_cb->hdr; u32 data_offset = be32_to_cpu(hdr->offset); - u32 data_len = pdu_cb->dlen; + u32 data_len = ntoh24(hdr->dlength); int rc, sg_nents, sg_off; bool dcrc_err = false; if (pdu_cb->flags & PDUCBF_RX_DDP_CMP) { u32 offset = be32_to_cpu(hdr->offset); u32 ddp_data_len; - u32 payload_length = ntoh24(hdr->dlength); bool success = false; cmd = iscsit_find_cmd_from_itt_or_dump(conn, hdr->itt, 0); @@ -1022,7 +1023,7 @@ static int cxgbit_handle_iscsi_dataout(struct cxgbit_sock *csk) cmd->data_sn = be32_to_cpu(hdr->datasn); rc = __iscsit_check_dataout_hdr(conn, (unsigned char *)hdr, - cmd, payload_length, &success); + cmd, data_len, &success); if (rc < 0) return rc; else if (!success) @@ -1060,6 +1061,20 @@ static int cxgbit_handle_iscsi_dataout(struct cxgbit_sock *csk) cxgbit_skb_copy_to_sg(csk->skb, sg_start, sg_nents, skip); } + ccmd = iscsit_priv_cmd(cmd); + ttinfo = &ccmd->ttinfo; + + if (ccmd->release && ttinfo->sgl && + (cmd->se_cmd.data_length == (cmd->write_data_done + data_len))) { + struct cxgbit_device *cdev = csk->com.cdev; + struct cxgbi_ppm *ppm = cdev2ppm(cdev); + + dma_unmap_sg(&ppm->pdev->dev, ttinfo->sgl, ttinfo->nents, + DMA_FROM_DEVICE); + ttinfo->nents = 0; + ttinfo->sgl = NULL; + } + check_payload: rc = iscsit_check_dataout_payload(cmd, hdr, dcrc_err); -- cgit v1.2.3 From 998da772fd86bd4ba2ba8c0ac2c9bba4815a952d Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Sun, 9 May 2021 21:08:17 -0700 Subject: scsi: target: iscsi: Drop unnecessary container_of() The structure pointer passed to container_of() is never NULL; that was already checked. That means that the result of container_of() operations on it is also never NULL, even though se_node_acl is the first element of the structure embedding it. On top of that, it is misleading to perform a NULL check on the result of container_of() because the position of the contained element could change, which would make the test invalid. Remove the unnecessary NULL check. As it turns out, the container_of operation was only made for the purpose of the NULL check. If the container_of is actually needed, it is repeated later. Remove the container_of operation as well. The NULL check was identified and removed with the following Coccinelle script. @@ type t; identifier v; statement s; @@ <+... ( t v = container_of(...); | v = container_of(...); ) ... when != v - if (\( !v \| v == NULL \) ) s ...+> Link: https://lore.kernel.org/r/20210510040817.2050266-1-linux@roeck-us.net Cc: "Martin K. Petersen" Cc: Hou Pu Cc: Mike Christie Signed-off-by: Guenter Roeck Signed-off-by: Martin K. Petersen --- drivers/target/iscsi/iscsi_target_nego.c | 7 ------- 1 file changed, 7 deletions(-) (limited to 'drivers/target') diff --git a/drivers/target/iscsi/iscsi_target_nego.c b/drivers/target/iscsi/iscsi_target_nego.c index 9a4a632f631d..c0ed6f8e5c5b 100644 --- a/drivers/target/iscsi/iscsi_target_nego.c +++ b/drivers/target/iscsi/iscsi_target_nego.c @@ -118,13 +118,6 @@ static u32 iscsi_handle_authentication( " CHAP auth\n"); return -1; } - iscsi_nacl = container_of(se_nacl, struct iscsi_node_acl, - se_node_acl); - if (!iscsi_nacl) { - pr_err("Unable to locate struct iscsi_node_acl for" - " CHAP auth\n"); - return -1; - } if (se_nacl->dynamic_node_acl) { iscsi_tpg = container_of(se_nacl->se_tpg, -- cgit v1.2.3 From 3ac0fcb4b1a34d196da926d302635052fd90379e Mon Sep 17 00:00:00 2001 From: Bodo Stroesser Date: Wed, 12 May 2021 16:06:54 +0200 Subject: scsi: target: tcmu: Rename TCM_DEV_BIT_PLUGGED to TCMU_DEV_BIT_PLUGGED The bit definition TCM_DEV_BIT_PLUGGED should correctly be named TCMU_DEV_BIT_PLUGGED, since all other bits in the same bitfield have prefix TCMU_. Link: https://lore.kernel.org/r/20210512140654.31249-1-bostroesser@gmail.com Signed-off-by: Bodo Stroesser Signed-off-by: Martin K. Petersen --- drivers/target/target_core_user.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers/target') diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c index 198d25ae482a..9866d7b49ab8 100644 --- a/drivers/target/target_core_user.c +++ b/drivers/target/target_core_user.c @@ -121,7 +121,7 @@ struct tcmu_dev { #define TCMU_DEV_BIT_BROKEN 1 #define TCMU_DEV_BIT_BLOCKED 2 #define TCMU_DEV_BIT_TMR_NOTIFY 3 -#define TCM_DEV_BIT_PLUGGED 4 +#define TCMU_DEV_BIT_PLUGGED 4 unsigned long flags; struct uio_info uio_info; @@ -980,7 +980,7 @@ static void tcmu_unplug_device(struct se_dev_plug *se_plug) struct se_device *se_dev = se_plug->se_dev; struct tcmu_dev *udev = TCMU_DEV(se_dev); - clear_bit(TCM_DEV_BIT_PLUGGED, &udev->flags); + clear_bit(TCMU_DEV_BIT_PLUGGED, &udev->flags); uio_event_notify(&udev->uio_info); } @@ -988,7 +988,7 @@ static struct se_dev_plug *tcmu_plug_device(struct se_device *se_dev) { struct tcmu_dev *udev = TCMU_DEV(se_dev); - if (!test_and_set_bit(TCM_DEV_BIT_PLUGGED, &udev->flags)) + if (!test_and_set_bit(TCMU_DEV_BIT_PLUGGED, &udev->flags)) return &udev->se_plug; return NULL; @@ -1122,7 +1122,7 @@ static int queue_cmd_ring(struct tcmu_cmd *tcmu_cmd, sense_reason_t *scsi_err) list_add_tail(&tcmu_cmd->queue_entry, &udev->inflight_queue); - if (!test_bit(TCM_DEV_BIT_PLUGGED, &udev->flags)) + if (!test_bit(TCMU_DEV_BIT_PLUGGED, &udev->flags)) uio_event_notify(&udev->uio_info); return 0; -- cgit v1.2.3 From f8a78e9118ee6cee7c24113891a0e24b77486f5e Mon Sep 17 00:00:00 2001 From: Jiapeng Chong Date: Thu, 13 May 2021 18:49:37 +0800 Subject: scsi: target: sbp_target: Remove redundant assignment to pg_size Variable pg_size is set to '0x100 << pg_size', but this value is never read and it is not used later on. Hence it is a redundant assignment and can be removed. Clean up the following clang-analyzer warning: drivers/target/sbp/sbp_target.c:1264:3: warning: Value stored to 'pg_size' is never read [clang-analyzer-deadcode.DeadStores]. Link: https://lore.kernel.org/r/1620902977-57076-1-git-send-email-jiapeng.chong@linux.alibaba.com Reported-by: Abaci Robot Signed-off-by: Jiapeng Chong Signed-off-by: Martin K. Petersen --- drivers/target/sbp/sbp_target.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/target') diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c index ce84f93c183a..4d3ceee23622 100644 --- a/drivers/target/sbp/sbp_target.c +++ b/drivers/target/sbp/sbp_target.c @@ -1261,7 +1261,6 @@ static int sbp_rw_data(struct sbp_target_request *req) pg_size = CMDBLK_ORB_PG_SIZE(be32_to_cpu(req->orb.misc)); if (pg_size) { pr_err("sbp_run_transaction: page size ignored\n"); - pg_size = 0x100 << pg_size; } spin_lock_bh(&sess->lock); -- cgit v1.2.3 From 17f947b8b06f57615d31e4159dec1d5d7dda775f Mon Sep 17 00:00:00 2001 From: Sergey Samoylenko Date: Tue, 20 Apr 2021 21:59:19 +0300 Subject: scsi: target: core: Unify NAA identifier generation Both the INQUIRY handling and the XCOPY implementation provide functions to generate an NAA designator. In addition, these functions are poorly named: - spc_parse_naa_6h_vendor_specific() - target_xcopy_gen_naa_ieee() Introduce a common NAA 6 designator generation function, spc_gen_naa_6h_vendor_specific(). Link: https://lore.kernel.org/r/20210420185920.42431-2-s.samoylenko@yadro.com Signed-off-by: Sergey Samoylenko Signed-off-by: Roman Bolshakov Signed-off-by: Martin K. Petersen --- drivers/target/target_core_pr.h | 2 +- drivers/target/target_core_spc.c | 47 +++++++++++++++++++------------------- drivers/target/target_core_xcopy.c | 17 ++------------ 3 files changed, 26 insertions(+), 40 deletions(-) (limited to 'drivers/target') diff --git a/drivers/target/target_core_pr.h b/drivers/target/target_core_pr.h index a31c93e4e19c..b793c99637ab 100644 --- a/drivers/target/target_core_pr.h +++ b/drivers/target/target_core_pr.h @@ -52,7 +52,7 @@ /* * Function defined in target_core_spc.c */ -void spc_parse_naa_6h_vendor_specific(struct se_device *, unsigned char *); +void spc_gen_naa_6h_vendor_specific(struct se_device *, unsigned char *); extern struct kmem_cache *t10_pr_reg_cache; diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c index 70a661801cb9..b2d19493a994 100644 --- a/drivers/target/target_core_spc.c +++ b/drivers/target/target_core_spc.c @@ -129,13 +129,28 @@ spc_emulate_evpd_80(struct se_cmd *cmd, unsigned char *buf) return 0; } -void spc_parse_naa_6h_vendor_specific(struct se_device *dev, - unsigned char *buf) +/* + * Generate NAA IEEE Registered Extended designator + */ +void spc_gen_naa_6h_vendor_specific(struct se_device *dev, + unsigned char *buf) { unsigned char *p = &dev->t10_wwn.unit_serial[0]; - int cnt; + int cnt, off = 0; bool next = true; + /* + * Start NAA IEEE Registered Extended Identifier/Designator + */ + buf[off++] = 0x6 << 4; + + /* + * Use OpenFabrics IEEE Company ID: 00 14 05 + */ + buf[off++] = 0x01; + buf[off++] = 0x40; + buf[off] = (0x5 << 4); + /* * Generate up to 36 bits of VENDOR SPECIFIC IDENTIFIER starting on * byte 3 bit 3-0 for NAA IEEE Registered Extended DESIGNATOR field @@ -144,7 +159,7 @@ void spc_parse_naa_6h_vendor_specific(struct se_device *dev, * NUMBER set via vpd_unit_serial in target_core_configfs.c to ensure * per device uniqeness. */ - for (cnt = 0; *p && cnt < 13; p++) { + for (cnt = off + 13; *p && off < cnt; p++) { int val = hex_to_bin(*p); if (val < 0) @@ -152,10 +167,10 @@ void spc_parse_naa_6h_vendor_specific(struct se_device *dev, if (next) { next = false; - buf[cnt++] |= val; + buf[off++] |= val; } else { next = true; - buf[cnt] = val << 4; + buf[off] = val << 4; } } } @@ -203,24 +218,8 @@ spc_emulate_evpd_83(struct se_cmd *cmd, unsigned char *buf) /* Identifier/Designator length */ buf[off++] = 0x10; - /* - * Start NAA IEEE Registered Extended Identifier/Designator - */ - buf[off++] = (0x6 << 4); - - /* - * Use OpenFabrics IEEE Company ID: 00 14 05 - */ - buf[off++] = 0x01; - buf[off++] = 0x40; - buf[off] = (0x5 << 4); - - /* - * Return ConfigFS Unit Serial Number information for - * VENDOR_SPECIFIC_IDENTIFIER and - * VENDOR_SPECIFIC_IDENTIFIER_EXTENTION - */ - spc_parse_naa_6h_vendor_specific(dev, &buf[off]); + /* NAA IEEE Registered Extended designator */ + spc_gen_naa_6h_vendor_specific(dev, &buf[off]); len = 20; off = (len + 4); diff --git a/drivers/target/target_core_xcopy.c b/drivers/target/target_core_xcopy.c index d31ed071cb08..2e7ce661ef32 100644 --- a/drivers/target/target_core_xcopy.c +++ b/drivers/target/target_core_xcopy.c @@ -33,19 +33,6 @@ static struct workqueue_struct *xcopy_wq = NULL; static sense_reason_t target_parse_xcopy_cmd(struct xcopy_op *xop); -static int target_xcopy_gen_naa_ieee(struct se_device *dev, unsigned char *buf) -{ - int off = 0; - - buf[off++] = (0x6 << 4); - buf[off++] = 0x01; - buf[off++] = 0x40; - buf[off] = (0x5 << 4); - - spc_parse_naa_6h_vendor_specific(dev, &buf[off]); - return 0; -} - /** * target_xcopy_locate_se_dev_e4_iter - compare XCOPY NAA device identifiers * @@ -65,7 +52,7 @@ static int target_xcopy_locate_se_dev_e4_iter(struct se_device *se_dev, } memset(&tmp_dev_wwn[0], 0, XCOPY_NAA_IEEE_REGEX_LEN); - target_xcopy_gen_naa_ieee(se_dev, &tmp_dev_wwn[0]); + spc_gen_naa_6h_vendor_specific(se_dev, &tmp_dev_wwn[0]); rc = memcmp(&tmp_dev_wwn[0], dev_wwn, XCOPY_NAA_IEEE_REGEX_LEN); if (rc != 0) { @@ -241,7 +228,7 @@ static int target_xcopy_parse_target_descriptors(struct se_cmd *se_cmd, * se_device the XCOPY was received upon.. */ memset(&xop->local_dev_wwn[0], 0, XCOPY_NAA_IEEE_REGEX_LEN); - target_xcopy_gen_naa_ieee(local_dev, &xop->local_dev_wwn[0]); + spc_gen_naa_6h_vendor_specific(local_dev, &xop->local_dev_wwn[0]); while (start < tdll) { /* -- cgit v1.2.3 From 2469f1e0412cb053e37b7499ce5e48b6be4d7653 Mon Sep 17 00:00:00 2001 From: Sergey Samoylenko Date: Tue, 20 Apr 2021 21:59:20 +0300 Subject: scsi: target: core: Add configurable IEEE Company ID attribute Implement an attribute which provides a way to set a company specific WWN in configfs via: target/core/$backstore/$name/wwn/company_id The Open Fabrics Alliance ID 001405h remains the default. Link: https://lore.kernel.org/r/20210420185920.42431-3-s.samoylenko@yadro.com Signed-off-by: Sergey Samoylenko Signed-off-by: Roman Bolshakov Signed-off-by: Martin K. Petersen --- drivers/target/target_core_configfs.c | 50 +++++++++++++++++++++++++++++++++++ drivers/target/target_core_device.c | 5 ++++ drivers/target/target_core_spc.c | 14 +++++----- include/target/target_core_base.h | 1 + 4 files changed, 63 insertions(+), 7 deletions(-) (limited to 'drivers/target') diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c index 4b2e49341ad6..102ec644bc8a 100644 --- a/drivers/target/target_core_configfs.c +++ b/drivers/target/target_core_configfs.c @@ -1479,6 +1479,54 @@ static ssize_t target_wwn_revision_store(struct config_item *item, return count; } +static ssize_t +target_wwn_company_id_show(struct config_item *item, + char *page) +{ + return snprintf(page, PAGE_SIZE, "%#08x\n", + to_t10_wwn(item)->company_id); +} + +static ssize_t +target_wwn_company_id_store(struct config_item *item, + const char *page, size_t count) +{ + struct t10_wwn *t10_wwn = to_t10_wwn(item); + struct se_device *dev = t10_wwn->t10_dev; + u32 val; + int ret; + + /* + * The IEEE COMPANY_ID field should contain a 24-bit canonical + * form OUI assigned by the IEEE. + */ + ret = kstrtou32(page, 0, &val); + if (ret < 0) + return ret; + + if (val >= 0x1000000) + return -EOVERFLOW; + + /* + * Check to see if any active exports exist. If they do exist, fail + * here as changing this information on the fly (underneath the + * initiator side OS dependent multipath code) could cause negative + * effects. + */ + if (dev->export_count) { + pr_err("Unable to set Company ID while %u exports exist\n", + dev->export_count); + return -EINVAL; + } + + t10_wwn->company_id = val; + + pr_debug("Target_Core_ConfigFS: Set IEEE Company ID: %#08x\n", + t10_wwn->company_id); + + return count; +} + /* * VPD page 0x80 Unit serial */ @@ -1625,6 +1673,7 @@ DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_scsi_target_device, 0x20); CONFIGFS_ATTR(target_wwn_, vendor_id); CONFIGFS_ATTR(target_wwn_, product_id); CONFIGFS_ATTR(target_wwn_, revision); +CONFIGFS_ATTR(target_wwn_, company_id); CONFIGFS_ATTR(target_wwn_, vpd_unit_serial); CONFIGFS_ATTR_RO(target_wwn_, vpd_protocol_identifier); CONFIGFS_ATTR_RO(target_wwn_, vpd_assoc_logical_unit); @@ -1635,6 +1684,7 @@ static struct configfs_attribute *target_core_dev_wwn_attrs[] = { &target_wwn_attr_vendor_id, &target_wwn_attr_product_id, &target_wwn_attr_revision, + &target_wwn_attr_company_id, &target_wwn_attr_vpd_unit_serial, &target_wwn_attr_vpd_protocol_identifier, &target_wwn_attr_vpd_assoc_logical_unit, diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c index a8df9f0a82fa..8cb1fa0c0585 100644 --- a/drivers/target/target_core_device.c +++ b/drivers/target/target_core_device.c @@ -773,6 +773,11 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name) spin_lock_init(&dev->t10_alua.lba_map_lock); dev->t10_wwn.t10_dev = dev; + /* + * Use OpenFabrics IEEE Company ID: 00 14 05 + */ + dev->t10_wwn.company_id = 0x001405; + dev->t10_alua.t10_dev = dev; dev->dev_attrib.da_dev = dev; diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c index b2d19493a994..fe5d5ce4099c 100644 --- a/drivers/target/target_core_spc.c +++ b/drivers/target/target_core_spc.c @@ -136,20 +136,20 @@ void spc_gen_naa_6h_vendor_specific(struct se_device *dev, unsigned char *buf) { unsigned char *p = &dev->t10_wwn.unit_serial[0]; + u32 company_id = dev->t10_wwn.company_id; int cnt, off = 0; bool next = true; /* * Start NAA IEEE Registered Extended Identifier/Designator */ - buf[off++] = 0x6 << 4; + buf[off] = 0x6 << 4; - /* - * Use OpenFabrics IEEE Company ID: 00 14 05 - */ - buf[off++] = 0x01; - buf[off++] = 0x40; - buf[off] = (0x5 << 4); + /* IEEE COMPANY_ID */ + buf[off++] |= (company_id >> 20) & 0xf; + buf[off++] = (company_id >> 12) & 0xff; + buf[off++] = (company_id >> 4) & 0xff; + buf[off] = (company_id & 0xf) << 4; /* * Generate up to 36 bits of VENDOR SPECIFIC IDENTIFIER starting on diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h index d1f7d2a45354..85c16c266eac 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h @@ -326,6 +326,7 @@ struct t10_wwn { char model[INQUIRY_MODEL_LEN + 1]; char revision[INQUIRY_REVISION_LEN + 1]; char unit_serial[INQUIRY_VPD_SERIAL_LEN]; + u32 company_id; spinlock_t t10_vpd_lock; struct se_device *t10_dev; struct config_group t10_wwn_group; -- cgit v1.2.3 From 64ae33ef7486d01acb1f1d1ea601923973a3a462 Mon Sep 17 00:00:00 2001 From: Konstantin Shelekhin Date: Thu, 13 May 2021 22:28:03 +0300 Subject: scsi: target: core: Bump INQUIRY VERSION to SPC-4 Bump the SCSI primary command set standard to SPC-4. The upcoming version descriptors will report newer SCSI standards (like SBC-3) that are not defined in SPC-3. Link: https://lore.kernel.org/r/20210513192804.1252142-2-k.shelekhin@yadro.com Reviewed-by: Roman Bolshakov Signed-off-by: Konstantin Shelekhin Signed-off-by: Martin K. Petersen --- drivers/target/target_core_spc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/target') diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c index fe5d5ce4099c..0f30b71f0acc 100644 --- a/drivers/target/target_core_spc.c +++ b/drivers/target/target_core_spc.c @@ -58,7 +58,7 @@ spc_emulate_inquiry_std(struct se_cmd *cmd, unsigned char *buf) if (dev->transport->get_device_type(dev) == TYPE_TAPE) buf[1] = 0x80; - buf[2] = 0x05; /* SPC-3 */ + buf[2] = 0x06; /* SPC-4 */ /* * NORMACA and HISUP = 0, RESPONSE DATA FORMAT = 2 -- cgit v1.2.3 From b790a56d66eaac4a1ac6c558575fd0a694b06159 Mon Sep 17 00:00:00 2001 From: Konstantin Shelekhin Date: Thu, 13 May 2021 22:28:04 +0300 Subject: scsi: target: core: Add the VERSION DESCRIPTOR fields to the INQUIRY data Extend the standard INQUIRY data to 96 bytes and fill in the VERSION DESCRIPTOR fields. The layout follows SPC-4: - SCSI architecture standard - SCSI transport protocol standard - SCSI primary command set standard - SCSI device type command set standard All version descriptor values are defined as "no version claimed" because some initiators fail to recognize anything else. [mkp: whitespace] Link: https://lore.kernel.org/r/20210513192804.1252142-3-k.shelekhin@yadro.com Reviewed-by: Roman Bolshakov Signed-off-by: Konstantin Shelekhin Signed-off-by: Martin K. Petersen --- drivers/target/target_core_spc.c | 34 +++++++++++++++++++++++++++++++++- include/scsi/scsi_proto.h | 12 ++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) (limited to 'drivers/target') diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c index 0f30b71f0acc..2cb141ed68f5 100644 --- a/drivers/target/target_core_spc.c +++ b/drivers/target/target_core_spc.c @@ -47,10 +47,32 @@ static void spc_fill_alua_data(struct se_lun *lun, unsigned char *buf) spin_unlock(&lun->lun_tg_pt_gp_lock); } +static u16 +spc_find_scsi_transport_vd(int proto_id) +{ + switch (proto_id) { + case SCSI_PROTOCOL_FCP: + return SCSI_VERSION_DESCRIPTOR_FCP4; + case SCSI_PROTOCOL_ISCSI: + return SCSI_VERSION_DESCRIPTOR_ISCSI; + case SCSI_PROTOCOL_SAS: + return SCSI_VERSION_DESCRIPTOR_SAS3; + case SCSI_PROTOCOL_SBP: + return SCSI_VERSION_DESCRIPTOR_SBP3; + case SCSI_PROTOCOL_SRP: + return SCSI_VERSION_DESCRIPTOR_SRP; + default: + pr_warn("Cannot find VERSION DESCRIPTOR value for unknown SCSI" + " transport PROTOCOL IDENTIFIER %#x\n", proto_id); + return 0; + } +} + sense_reason_t spc_emulate_inquiry_std(struct se_cmd *cmd, unsigned char *buf) { struct se_lun *lun = cmd->se_lun; + struct se_portal_group *tpg = lun->lun_tpg; struct se_device *dev = cmd->se_dev; struct se_session *sess = cmd->se_sess; @@ -108,7 +130,17 @@ spc_emulate_inquiry_std(struct se_cmd *cmd, unsigned char *buf) strnlen(dev->t10_wwn.model, INQUIRY_MODEL_LEN)); memcpy(&buf[32], dev->t10_wwn.revision, strnlen(dev->t10_wwn.revision, INQUIRY_REVISION_LEN)); - buf[4] = 31; /* Set additional length to 31 */ + + /* + * Set the VERSION DESCRIPTOR fields + */ + put_unaligned_be16(SCSI_VERSION_DESCRIPTOR_SAM5, &buf[58]); + put_unaligned_be16(spc_find_scsi_transport_vd(tpg->proto_id), &buf[60]); + put_unaligned_be16(SCSI_VERSION_DESCRIPTOR_SPC4, &buf[62]); + if (cmd->se_dev->transport->get_device_type(dev) == TYPE_DISK) + put_unaligned_be16(SCSI_VERSION_DESCRIPTOR_SBC3, &buf[64]); + + buf[4] = 91; /* Set additional length to 91 */ return 0; } diff --git a/include/scsi/scsi_proto.h b/include/scsi/scsi_proto.h index c36860111932..5c106c4f249e 100644 --- a/include/scsi/scsi_proto.h +++ b/include/scsi/scsi_proto.h @@ -341,4 +341,16 @@ enum zbc_zone_cond { ZBC_ZONE_COND_OFFLINE = 0xf, }; +/* Version descriptor values for INQUIRY */ +enum scsi_version_descriptor { + SCSI_VERSION_DESCRIPTOR_FCP4 = 0x0a40, + SCSI_VERSION_DESCRIPTOR_ISCSI = 0x0960, + SCSI_VERSION_DESCRIPTOR_SAM5 = 0x00a0, + SCSI_VERSION_DESCRIPTOR_SAS3 = 0x0c60, + SCSI_VERSION_DESCRIPTOR_SBC3 = 0x04c0, + SCSI_VERSION_DESCRIPTOR_SBP3 = 0x0980, + SCSI_VERSION_DESCRIPTOR_SPC4 = 0x0460, + SCSI_VERSION_DESCRIPTOR_SRP = 0x0940 +}; + #endif /* _SCSI_PROTO_H_ */ -- cgit v1.2.3 From 824731258b65f58764786f8d776c2007b084e12c Mon Sep 17 00:00:00 2001 From: kernel test robot Date: Sun, 16 May 2021 07:03:58 +0800 Subject: scsi: target: tcmu: Fix boolreturn.cocci warnings drivers/target/target_core_user.c:1424:9-10: WARNING: return of 0/1 in function 'tcmu_handle_completions' with return type bool Return statements in functions returning bool should use true/false instead of 1/0. Generated by: scripts/coccinelle/misc/boolreturn.cocci Link: https://lore.kernel.org/r/20210515230358.GA97544@60d1edce16e0 Fixes: 9814b55cde05 ("scsi: target: tcmu: Return from tcmu_handle_completions() if cmd_id not found") CC: Bodo Stroesser Reported-by: kernel test robot Acked-by: Bodo Stroesser Signed-off-by: kernel test robot Signed-off-by: Martin K. Petersen --- drivers/target/target_core_user.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/target') diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c index 9866d7b49ab8..3bbe0a7a5465 100644 --- a/drivers/target/target_core_user.c +++ b/drivers/target/target_core_user.c @@ -1421,7 +1421,7 @@ static bool tcmu_handle_completions(struct tcmu_dev *udev) if (test_bit(TCMU_DEV_BIT_BROKEN, &udev->flags)) { pr_err("ring broken, not handling completions\n"); - return 0; + return false; } mb = udev->mb_addr; -- cgit v1.2.3 From 464a00c9e0ad45e3f42ff6ea705491a356df818e Mon Sep 17 00:00:00 2001 From: Hannes Reinecke Date: Tue, 27 Apr 2021 10:30:15 +0200 Subject: scsi: core: Kill DRIVER_SENSE Replace the check for DRIVER_SENSE with a check for scsi_status_is_check_condition(). Audit all callsites to ensure the SAM status is set correctly. For backwards compability move the DRIVER_SENSE definition to sg.h, and update sg, bsg, and scsi_ioctl to set the DRIVER_SENSE driver_status whenever SAM_STAT_CHECK_CONDITION is present. [mkp: fix zeroday srp warning] Link: https://lore.kernel.org/r/20210427083046.31620-10-hare@suse.de Signed-off-by: Hannes Reinecke Signed-off-by: Martin K. Petersen fix --- block/bsg.c | 2 ++ block/scsi_ioctl.c | 2 ++ drivers/ata/libata-scsi.c | 13 +++--------- drivers/scsi/NCR5380.c | 2 +- drivers/scsi/advansys.c | 2 -- drivers/scsi/aic7xxx/aic79xx_osm.c | 19 ++++++----------- drivers/scsi/aic7xxx/aic7xxx_osm.c | 1 - drivers/scsi/arcmsr/arcmsr_hba.c | 1 - drivers/scsi/ch.c | 2 +- drivers/scsi/cxlflash/superpipe.c | 3 +-- drivers/scsi/dc395x.c | 13 +++--------- drivers/scsi/esp_scsi.c | 4 +--- drivers/scsi/megaraid.c | 8 ++----- drivers/scsi/megaraid/megaraid_mbox.c | 7 ++---- drivers/scsi/megaraid/megaraid_sas_base.c | 2 -- drivers/scsi/megaraid/megaraid_sas_fusion.c | 1 - drivers/scsi/mvumi.c | 1 - drivers/scsi/scsi.c | 7 ------ drivers/scsi/scsi_debug.c | 4 ++-- drivers/scsi/scsi_ioctl.c | 3 +-- drivers/scsi/scsi_lib.c | 10 +++------ drivers/scsi/scsi_scan.c | 2 +- drivers/scsi/scsi_transport_spi.c | 2 +- drivers/scsi/sd.c | 33 +++++++++++++++-------------- drivers/scsi/sd_zbc.c | 3 +-- drivers/scsi/sg.c | 7 ++++-- drivers/scsi/stex.c | 4 ++-- drivers/scsi/sym53c8xx_2/sym_glue.c | 6 ++---- drivers/scsi/ufs/ufshcd.c | 2 +- drivers/scsi/virtio_scsi.c | 3 +-- drivers/scsi/vmw_pvscsi.c | 3 --- drivers/target/loopback/tcm_loop.c | 1 - drivers/usb/storage/cypress_atacb.c | 4 ++-- drivers/xen/xen-scsiback.c | 3 +-- include/scsi/sg.h | 11 ++++++++++ 35 files changed, 76 insertions(+), 115 deletions(-) (limited to 'drivers/target') diff --git a/block/bsg.c b/block/bsg.c index bd10922d5cbb..9e6ff0d71d25 100644 --- a/block/bsg.c +++ b/block/bsg.c @@ -97,6 +97,8 @@ static int bsg_scsi_complete_rq(struct request *rq, struct sg_io_v4 *hdr) hdr->device_status = sreq->result & 0xff; hdr->transport_status = host_byte(sreq->result); hdr->driver_status = driver_byte(sreq->result); + if (scsi_status_is_check_condition(sreq->result)) + hdr->driver_status = DRIVER_SENSE; hdr->info = 0; if (hdr->device_status || hdr->transport_status || hdr->driver_status) hdr->info |= SG_INFO_CHECK; diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c index 48bb4e1ea1e7..eb65bcde166f 100644 --- a/block/scsi_ioctl.c +++ b/block/scsi_ioctl.c @@ -257,6 +257,8 @@ static int blk_complete_sghdr_rq(struct request *rq, struct sg_io_hdr *hdr, hdr->msg_status = msg_byte(req->result); hdr->host_status = host_byte(req->result); hdr->driver_status = driver_byte(req->result); + if (scsi_status_is_check_condition(hdr->status)) + hdr->driver_status = DRIVER_SENSE; hdr->info = 0; if (hdr->masked_status || hdr->host_status || hdr->driver_status) hdr->info |= SG_INFO_CHECK; diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 61e15a2ce966..31b47ad073ad 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -411,13 +411,12 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg) rc = cmd_result; goto error; } - if (driver_byte(cmd_result) == DRIVER_SENSE) {/* sense data available */ + if (scsi_sense_valid(&sshdr)) {/* sense data available */ u8 *desc = sensebuf + 8; - cmd_result &= ~(0xFF<<24); /* DRIVER_SENSE is not an error */ /* If we set cc then ATA pass-through will cause a * check condition even if no error. Filter that. */ - if (cmd_result & SAM_STAT_CHECK_CONDITION) { + if (scsi_status_is_check_condition(cmd_result)) { if (sshdr.sense_key == RECOVERED_ERROR && sshdr.asc == 0 && sshdr.ascq == 0x1d) cmd_result &= ~SAM_STAT_CHECK_CONDITION; @@ -496,9 +495,8 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg) rc = cmd_result; goto error; } - if (driver_byte(cmd_result) == DRIVER_SENSE) {/* sense data available */ + if (scsi_sense_valid(&sshdr)) {/* sense data available */ u8 *desc = sensebuf + 8; - cmd_result &= ~(0xFF<<24); /* DRIVER_SENSE is not an error */ /* If we set cc then ATA pass-through will cause a * check condition even if no error. Filter that. */ @@ -864,8 +862,6 @@ static void ata_gen_passthru_sense(struct ata_queued_cmd *qc) memset(sb, 0, SCSI_SENSE_BUFFERSIZE); - cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; - /* * Use ata_to_sense_error() to map status register bits * onto sense key, asc & ascq. @@ -962,8 +958,6 @@ static void ata_gen_ata_sense(struct ata_queued_cmd *qc) memset(sb, 0, SCSI_SENSE_BUFFERSIZE); - cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; - if (ata_dev_disabled(dev)) { /* Device disabled after error recovery */ /* LOGICAL UNIT NOT READY, HARD RESET REQUIRED */ @@ -4201,7 +4195,6 @@ void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd) case REQUEST_SENSE: ata_scsi_set_sense(dev, cmd, 0, 0, 0); - cmd->result = (DRIVER_SENSE << 24); break; /* if we reach this, then writeback caching is disabled, diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c index 2ddbcaa667d1..d7594b794d3c 100644 --- a/drivers/scsi/NCR5380.c +++ b/drivers/scsi/NCR5380.c @@ -542,7 +542,7 @@ static void complete_cmd(struct Scsi_Host *instance, scsi_eh_restore_cmnd(cmd, &hostdata->ses); } else { scsi_eh_restore_cmnd(cmd, &hostdata->ses); - set_driver_byte(cmd, DRIVER_SENSE); + set_status_byte(cmd, SAM_STAT_CHECK_CONDITION); } hostdata->sensing = NULL; } diff --git a/drivers/scsi/advansys.c b/drivers/scsi/advansys.c index 800052f10699..379ff1bcfdbe 100644 --- a/drivers/scsi/advansys.c +++ b/drivers/scsi/advansys.c @@ -5964,7 +5964,6 @@ static void adv_isr_callback(ADV_DVC_VAR *adv_dvc_varp, ADV_SCSI_REQ_Q *scsiqp) ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n"); ASC_DBG_PRT_SENSE(2, scp->sense_buffer, SCSI_SENSE_BUFFERSIZE); - set_driver_byte(scp, DRIVER_SENSE); } break; @@ -6715,7 +6714,6 @@ static void asc_isr_callback(ASC_DVC_VAR *asc_dvc_varp, ASC_QDONE_INFO *qdonep) ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n"); ASC_DBG_PRT_SENSE(2, scp->sense_buffer, SCSI_SENSE_BUFFERSIZE); - set_driver_byte(scp, DRIVER_SENSE); } break; diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.c b/drivers/scsi/aic7xxx/aic79xx_osm.c index 4f7102f8eeb0..92ea24a075b8 100644 --- a/drivers/scsi/aic7xxx/aic79xx_osm.c +++ b/drivers/scsi/aic7xxx/aic79xx_osm.c @@ -1928,7 +1928,7 @@ ahd_linux_handle_scsi_status(struct ahd_softc *ahd, memcpy(cmd->sense_buffer, ahd_get_sense_buf(ahd, scb) + sense_offset, sense_size); - cmd->result |= (DRIVER_SENSE << 24); + set_status_byte(cmd, SAM_STAT_CHECK_CONDITION); #ifdef AHD_DEBUG if (ahd_debug & AHD_SHOW_SENSE) { @@ -2018,6 +2018,7 @@ ahd_linux_queue_cmd_complete(struct ahd_softc *ahd, struct scsi_cmnd *cmd) int new_status = DID_OK; int do_fallback = 0; int scsi_status; + struct scsi_sense_data *sense; /* * Map CAM error codes into Linux Error codes. We @@ -2041,18 +2042,12 @@ ahd_linux_queue_cmd_complete(struct ahd_softc *ahd, struct scsi_cmnd *cmd) switch(scsi_status) { case SAM_STAT_COMMAND_TERMINATED: case SAM_STAT_CHECK_CONDITION: - if ((cmd->result >> 24) != DRIVER_SENSE) { + sense = (struct scsi_sense_data *) + cmd->sense_buffer; + if (sense->extra_len >= 5 && + (sense->add_sense_code == 0x47 + || sense->add_sense_code == 0x48)) do_fallback = 1; - } else { - struct scsi_sense_data *sense; - - sense = (struct scsi_sense_data *) - cmd->sense_buffer; - if (sense->extra_len >= 5 && - (sense->add_sense_code == 0x47 - || sense->add_sense_code == 0x48)) - do_fallback = 1; - } break; default: break; diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm.c b/drivers/scsi/aic7xxx/aic7xxx_osm.c index d33f5a00bf0b..8b3d472aa3cc 100644 --- a/drivers/scsi/aic7xxx/aic7xxx_osm.c +++ b/drivers/scsi/aic7xxx/aic7xxx_osm.c @@ -1838,7 +1838,6 @@ ahc_linux_handle_scsi_status(struct ahc_softc *ahc, if (sense_size < SCSI_SENSE_BUFFERSIZE) memset(&cmd->sense_buffer[sense_size], 0, SCSI_SENSE_BUFFERSIZE - sense_size); - cmd->result |= (DRIVER_SENSE << 24); #ifdef AHC_DEBUG if (ahc_debug & AHC_SHOW_SENSE) { int i; diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c index 42e494a7106c..c01a5b2ff67a 100644 --- a/drivers/scsi/arcmsr/arcmsr_hba.c +++ b/drivers/scsi/arcmsr/arcmsr_hba.c @@ -1335,7 +1335,6 @@ static void arcmsr_report_sense_info(struct CommandControlBlock *ccb) memcpy(sensebuffer, ccb->arcmsr_cdb.SenseData, sense_data_length); sensebuffer->ErrorCode = SCSI_SENSE_CURRENT_ERRORS; sensebuffer->Valid = 1; - pcmd->result |= (DRIVER_SENSE << 24); } } diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c index d5990f6fb313..fc7197abfcdf 100644 --- a/drivers/scsi/ch.c +++ b/drivers/scsi/ch.c @@ -200,7 +200,7 @@ ch_do_scsi(scsi_changer *ch, unsigned char *cmd, int cmd_len, MAX_RETRIES, NULL); if (result < 0) return result; - if (driver_byte(result) == DRIVER_SENSE) { + if (scsi_sense_valid(&sshdr)) { if (debug) scsi_print_sense_hdr(ch->device, ch->name, &sshdr); errno = ch_find_errno(&sshdr); diff --git a/drivers/scsi/cxlflash/superpipe.c b/drivers/scsi/cxlflash/superpipe.c index caa7c5fd233d..df0ebabbf387 100644 --- a/drivers/scsi/cxlflash/superpipe.c +++ b/drivers/scsi/cxlflash/superpipe.c @@ -369,8 +369,7 @@ retry: goto out; } - if (result > 0 && driver_byte(result) == DRIVER_SENSE) { - result &= ~(0xFF<<24); /* DRIVER_SENSE is not an error */ + if (result > 0 && scsi_sense_valid(&sshdr)) { if (result & SAM_STAT_CHECK_CONDITION) { switch (sshdr.sense_key) { case NO_SENSE: diff --git a/drivers/scsi/dc395x.c b/drivers/scsi/dc395x.c index be87d5a7583d..a713fe605dda 100644 --- a/drivers/scsi/dc395x.c +++ b/drivers/scsi/dc395x.c @@ -3239,16 +3239,9 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb, } dprintkdbg(DBG_0, "srb_done: AUTO_REQSENSE2\n"); - if (srb->total_xfer_length - && srb->total_xfer_length >= cmd->underflow) - cmd->result = - MK_RES_LNX(DRIVER_SENSE, DID_OK, - srb->end_message, CHECK_CONDITION); - /*SET_RES_DID(cmd->result,DID_OK) */ - else - cmd->result = - MK_RES_LNX(DRIVER_SENSE, DID_OK, - srb->end_message, CHECK_CONDITION); + cmd->result = + MK_RES(0, DID_OK, + srb->end_message, SAM_STAT_CHECK_CONDITION); goto ckc_e; } diff --git a/drivers/scsi/esp_scsi.c b/drivers/scsi/esp_scsi.c index 342535ac0570..9a8c037a2f21 100644 --- a/drivers/scsi/esp_scsi.c +++ b/drivers/scsi/esp_scsi.c @@ -922,9 +922,7 @@ static void esp_cmd_is_done(struct esp *esp, struct esp_cmd_entry *ent, * saw originally. Also, report that we are providing * the sense data. */ - cmd->result = ((DRIVER_SENSE << 24) | - (DID_OK << 16) | - (SAM_STAT_CHECK_CONDITION << 0)); + cmd->result = SAM_STAT_CHECK_CONDITION; ent->flags &= ~ESP_CMD_FLAG_AUTOSENSE; if (esp_debug & ESP_DEBUG_AUTOSENSE) { diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c index ae3f32f89381..1880471c632a 100644 --- a/drivers/scsi/megaraid.c +++ b/drivers/scsi/megaraid.c @@ -1583,9 +1583,7 @@ mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status) memcpy(cmd->sense_buffer, pthru->reqsensearea, 14); - cmd->result = (DRIVER_SENSE << 24) | - (DID_OK << 16) | - (CHECK_CONDITION << 1); + cmd->result = SAM_STAT_CHECK_CONDITION; } else { if (mbox->m_out.cmd == MEGA_MBOXCMD_EXTPTHRU) { @@ -1593,9 +1591,7 @@ mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status) memcpy(cmd->sense_buffer, epthru->reqsensearea, 14); - cmd->result = (DRIVER_SENSE << 24) | - (DID_OK << 16) | - (CHECK_CONDITION << 1); + cmd->result = SAM_STAT_CHECK_CONDITION; } else scsi_build_sense(cmd, 0, ABORTED_COMMAND, 0, 0); diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c index 44154e13daa3..bb8b2fba4b3d 100644 --- a/drivers/scsi/megaraid/megaraid_mbox.c +++ b/drivers/scsi/megaraid/megaraid_mbox.c @@ -2299,8 +2299,7 @@ megaraid_mbox_dpc(unsigned long devp) memcpy(scp->sense_buffer, pthru->reqsensearea, 14); - scp->result = DRIVER_SENSE << 24 | - DID_OK << 16 | CHECK_CONDITION << 1; + scp->result = SAM_STAT_CHECK_CONDITION; } else { if (mbox->cmd == MBOXCMD_EXTPTHRU) { @@ -2308,9 +2307,7 @@ megaraid_mbox_dpc(unsigned long devp) memcpy(scp->sense_buffer, epthru->reqsensearea, 14); - scp->result = DRIVER_SENSE << 24 | - DID_OK << 16 | - CHECK_CONDITION << 1; + scp->result = SAM_STAT_CHECK_CONDITION; } else scsi_build_sense(scp, 0, ABORTED_COMMAND, 0, 0); diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c index 8ed347eebf07..181407888e58 100644 --- a/drivers/scsi/megaraid/megaraid_sas_base.c +++ b/drivers/scsi/megaraid/megaraid_sas_base.c @@ -3617,8 +3617,6 @@ megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd, SCSI_SENSE_BUFFERSIZE); memcpy(cmd->scmd->sense_buffer, cmd->sense, hdr->sense_len); - - cmd->scmd->result |= DRIVER_SENSE << 24; } break; diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c index 2221175ae051..1a4bd75229cf 100644 --- a/drivers/scsi/megaraid/megaraid_sas_fusion.c +++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c @@ -2051,7 +2051,6 @@ map_cmd_status(struct fusion_context *fusion, SCSI_SENSE_BUFFERSIZE); memcpy(scmd->sense_buffer, sense, SCSI_SENSE_BUFFERSIZE); - scmd->result |= DRIVER_SENSE << 24; } /* diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c index 94f706eeb561..f61250545025 100644 --- a/drivers/scsi/mvumi.c +++ b/drivers/scsi/mvumi.c @@ -1317,7 +1317,6 @@ static void mvumi_complete_cmd(struct mvumi_hba *mhba, struct mvumi_cmd *cmd, if (ob_frame->rsp_flag & CL_RSP_FLAG_SENSEDATA) { memcpy(cmd->scmd->sense_buffer, ob_frame->payload, sizeof(struct mvumi_sense_data)); - scmd->result |= (DRIVER_SENSE << 24); } break; default: diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index 1ce46e6e6483..d26025cf5de3 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -185,13 +185,6 @@ void scsi_finish_command(struct scsi_cmnd *cmd) if (atomic_read(&sdev->device_blocked)) atomic_set(&sdev->device_blocked, 0); - /* - * If we have valid sense information, then some kind of recovery - * must have taken place. Make a note of this. - */ - if (SCSI_SENSE_VALID(cmd)) - cmd->result |= (DRIVER_SENSE << 24); - SCSI_LOG_MLCOMPLETE(4, sdev_printk(KERN_INFO, sdev, "Notifying upper driver of completion " "(result %x)\n", cmd->result)); diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index a49fbd96a510..5b3a20a140f9 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -851,10 +851,10 @@ static struct device_driver sdebug_driverfs_driver = { }; static const int check_condition_result = - (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; + SAM_STAT_CHECK_CONDITION; static const int illegal_condition_result = - (DRIVER_SENSE << 24) | (DID_ABORT << 16) | SAM_STAT_CHECK_CONDITION; + (DID_ABORT << 16) | SAM_STAT_CHECK_CONDITION; static const int device_qfull_result = (DID_OK << 16) | SAM_STAT_TASK_SET_FULL; diff --git a/drivers/scsi/scsi_ioctl.c b/drivers/scsi/scsi_ioctl.c index d34e1b41dc71..0d13610cd6bf 100644 --- a/drivers/scsi/scsi_ioctl.c +++ b/drivers/scsi/scsi_ioctl.c @@ -103,8 +103,7 @@ static int ioctl_internal_command(struct scsi_device *sdev, char *cmd, if (result < 0) goto out; - if (driver_byte(result) == DRIVER_SENSE && - scsi_sense_valid(&sshdr)) { + if (scsi_sense_valid(&sshdr)) { switch (sshdr.sense_key) { case ILLEGAL_REQUEST: if (cmd[0] == ALLOW_MEDIUM_REMOVAL) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index d6b0cb2ab292..75d633ffdac0 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -593,8 +593,6 @@ static blk_status_t scsi_result_to_blk_status(struct scsi_cmnd *cmd, int result) case DID_OK: /* * Also check the other bytes than the status byte in result - * to handle the case when a SCSI LLD sets result to - * DRIVER_SENSE << 24 without setting SAM_STAT_CHECK_CONDITION. */ if (scsi_status_is_good(result) && (result & ~0xff) == 0) return BLK_STS_OK; @@ -790,7 +788,7 @@ static void scsi_io_completion_action(struct scsi_cmnd *cmd, int result) */ if (!level && __ratelimit(&_rs)) { scsi_print_result(cmd, NULL, FAILED); - if (driver_byte(result) == DRIVER_SENSE) + if (sense_valid) scsi_print_sense(cmd); scsi_print_command(cmd); } @@ -2152,8 +2150,7 @@ scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage, * ILLEGAL REQUEST if the code page isn't supported */ if (!scsi_status_is_good(result)) { - if (driver_byte(result) == DRIVER_SENSE && - scsi_sense_valid(sshdr)) { + if (scsi_sense_valid(sshdr)) { if ((sshdr->sense_key == ILLEGAL_REQUEST) && (sshdr->asc == 0x20) && (sshdr->ascq == 0)) { /* @@ -3236,7 +3233,6 @@ EXPORT_SYMBOL(scsi_vpd_tpg_id); void scsi_build_sense(struct scsi_cmnd *scmd, int desc, u8 key, u8 asc, u8 ascq) { scsi_build_sense_buffer(desc, scmd->sense_buffer, key, asc, ascq); - scmd->result = (DRIVER_SENSE << 24) | (DID_OK << 16) | - SAM_STAT_CHECK_CONDITION; + scmd->result = SAM_STAT_CHECK_CONDITION; } EXPORT_SYMBOL_GPL(scsi_build_sense); diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c index a0edcff7db1f..5ce45ef9808f 100644 --- a/drivers/scsi/scsi_scan.c +++ b/drivers/scsi/scsi_scan.c @@ -623,7 +623,7 @@ static int scsi_probe_lun(struct scsi_device *sdev, unsigned char *inq_result, * INQUIRY should not yield UNIT_ATTENTION * but many buggy devices do so anyway. */ - if (driver_byte(result) == DRIVER_SENSE && + if (scsi_status_is_check_condition(result) && scsi_sense_valid(&sshdr)) { if ((sshdr.sense_key == UNIT_ATTENTION) && ((sshdr.asc == 0x28) || diff --git a/drivers/scsi/scsi_transport_spi.c b/drivers/scsi/scsi_transport_spi.c index a9bb7ae2fafd..5af7a10e9514 100644 --- a/drivers/scsi/scsi_transport_spi.c +++ b/drivers/scsi/scsi_transport_spi.c @@ -127,7 +127,7 @@ static int spi_execute(struct scsi_device *sdev, const void *cmd, REQ_FAILFAST_TRANSPORT | REQ_FAILFAST_DRIVER, RQF_PM, NULL); - if (result < 0 || driver_byte(result) != DRIVER_SENSE || + if (result < 0 || !scsi_sense_valid(sshdr) || sshdr->sense_key != UNIT_ATTENTION) break; } diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 5733fbee2bae..66cb161667af 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -1722,16 +1722,17 @@ static int sd_sync_cache(struct scsi_disk *sdkp, struct scsi_sense_hdr *sshdr) if (res < 0) return res; - if (driver_byte(res) == DRIVER_SENSE) + if (scsi_status_is_check_condition(res) && + scsi_sense_valid(sshdr)) { sd_print_sense_hdr(sdkp, sshdr); - /* we need to evaluate the error return */ - if (scsi_sense_valid(sshdr) && - (sshdr->asc == 0x3a || /* medium not present */ - sshdr->asc == 0x20 || /* invalid command */ - (sshdr->asc == 0x74 && sshdr->ascq == 0x71))) /* drive is password locked */ + /* we need to evaluate the error return */ + if (sshdr->asc == 0x3a || /* medium not present */ + sshdr->asc == 0x20 || /* invalid command */ + (sshdr->asc == 0x74 && sshdr->ascq == 0x71)) /* drive is password locked */ /* this is no error here */ return 0; + } switch (host_byte(res)) { /* ignore errors due to racing a disconnection */ @@ -1828,7 +1829,7 @@ static int sd_pr_command(struct block_device *bdev, u8 sa, result = scsi_execute_req(sdev, cmd, DMA_TO_DEVICE, &data, sizeof(data), &sshdr, SD_TIMEOUT, sdkp->max_retries, NULL); - if (result > 0 && driver_byte(result) == DRIVER_SENSE && + if (scsi_status_is_check_condition(result) && scsi_sense_valid(&sshdr)) { sdev_printk(KERN_INFO, sdev, "PR command failed: %d\n", result); scsi_print_sense_hdr(sdev, NULL, &sshdr); @@ -2072,7 +2073,7 @@ static int sd_done(struct scsi_cmnd *SCpnt) } sdkp->medium_access_timed_out = 0; - if (driver_byte(result) != DRIVER_SENSE && + if (!scsi_status_is_check_condition(result) && (!sense_valid || sense_deferred)) goto out; @@ -2175,12 +2176,12 @@ sd_spinup_disk(struct scsi_disk *sdkp) if (the_result) sense_valid = scsi_sense_valid(&sshdr); retries++; - } while (retries < 3 && + } while (retries < 3 && (!scsi_status_is_good(the_result) || - ((driver_byte(the_result) == DRIVER_SENSE) && + (scsi_status_is_check_condition(the_result) && sense_valid && sshdr.sense_key == UNIT_ATTENTION))); - if (the_result < 0 || driver_byte(the_result) != DRIVER_SENSE) { + if (!scsi_status_is_check_condition(the_result)) { /* no sense, TUR either succeeded or failed * with a status error */ if(!spintime && !scsi_status_is_good(the_result)) { @@ -2308,7 +2309,7 @@ static void read_capacity_error(struct scsi_disk *sdkp, struct scsi_device *sdp, struct scsi_sense_hdr *sshdr, int sense_valid, int the_result) { - if (driver_byte(the_result) == DRIVER_SENSE) + if (sense_valid) sd_print_sense_hdr(sdkp, sshdr); else sd_printk(KERN_NOTICE, sdkp, "Sense not available.\n"); @@ -3594,12 +3595,12 @@ static int sd_start_stop_device(struct scsi_disk *sdkp, int start) SD_TIMEOUT, sdkp->max_retries, 0, RQF_PM, NULL); if (res) { sd_print_result(sdkp, "Start/Stop Unit failed", res); - if (res > 0 && driver_byte(res) == DRIVER_SENSE) + if (res > 0 && scsi_sense_valid(&sshdr)) { sd_print_sense_hdr(sdkp, &sshdr); - if (scsi_sense_valid(&sshdr) && /* 0x3a is medium not present */ - sshdr.asc == 0x3a) - res = 0; + if (sshdr.asc == 0x3a) + res = 0; + } } /* SCSI error codes must not go to the generic layer */ diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c index d4a79fdcfffe..186b5ff52c3a 100644 --- a/drivers/scsi/sd_zbc.c +++ b/drivers/scsi/sd_zbc.c @@ -116,8 +116,7 @@ static int sd_zbc_do_report_zones(struct scsi_disk *sdkp, unsigned char *buf, sd_printk(KERN_ERR, sdkp, "REPORT ZONES start lba %llu failed\n", lba); sd_print_result(sdkp, "REPORT ZONES", result); - if (result > 0 && driver_byte(result) == DRIVER_SENSE && - scsi_sense_valid(&sshdr)) + if (result > 0 && scsi_sense_valid(&sshdr)) sd_print_sense_hdr(sdkp, &sshdr); return -EIO; } diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index def7ec3bbaf9..faf7716c8851 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -498,9 +498,11 @@ sg_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos) old_hdr->host_status = hp->host_status; old_hdr->driver_status = hp->driver_status; if ((CHECK_CONDITION & hp->masked_status) || - (DRIVER_SENSE & hp->driver_status)) + (srp->sense_b[0] & 0x70) == 0x70) { + old_hdr->driver_status = DRIVER_SENSE; memcpy(old_hdr->sense_buffer, srp->sense_b, sizeof (old_hdr->sense_buffer)); + } switch (hp->host_status) { /* This setup of 'result' is for backward compatibility and is best ignored by the user who should use target, host + driver status */ @@ -574,7 +576,7 @@ sg_new_read(Sg_fd * sfp, char __user *buf, size_t count, Sg_request * srp) hp->sb_len_wr = 0; if ((hp->mx_sb_len > 0) && hp->sbp) { if ((CHECK_CONDITION & hp->masked_status) || - (DRIVER_SENSE & hp->driver_status)) { + (srp->sense_b[0] & 0x70) == 0x70) { int sb_len = SCSI_SENSE_BUFFERSIZE; sb_len = (hp->mx_sb_len > sb_len) ? sb_len : hp->mx_sb_len; len = 8 + (int) srp->sense_b[7]; /* Additional sense length field */ @@ -583,6 +585,7 @@ sg_new_read(Sg_fd * sfp, char __user *buf, size_t count, Sg_request * srp) err = -EFAULT; goto err_out; } + hp->driver_status = DRIVER_SENSE; hp->sb_len_wr = len; } } diff --git a/drivers/scsi/stex.c b/drivers/scsi/stex.c index 3af2a2d3bfa2..491b435273a6 100644 --- a/drivers/scsi/stex.c +++ b/drivers/scsi/stex.c @@ -737,7 +737,7 @@ static void stex_scsi_done(struct st_ccb *ccb) result |= DID_OK << 16; break; case SAM_STAT_CHECK_CONDITION: - result |= DRIVER_SENSE << 24; + result |= DID_OK << 16; break; case SAM_STAT_BUSY: result |= DID_BUS_BUSY << 16; @@ -748,7 +748,7 @@ static void stex_scsi_done(struct st_ccb *ccb) } } else if (ccb->srb_status & SRB_SEE_SENSE) - result = DRIVER_SENSE << 24 | SAM_STAT_CHECK_CONDITION; + result = SAM_STAT_CHECK_CONDITION; else switch (ccb->srb_status) { case SRB_STATUS_SELECTION_TIMEOUT: result = DID_NO_CONNECT << 16; diff --git a/drivers/scsi/sym53c8xx_2/sym_glue.c b/drivers/scsi/sym53c8xx_2/sym_glue.c index d9a045f9858c..16b65fc4405c 100644 --- a/drivers/scsi/sym53c8xx_2/sym_glue.c +++ b/drivers/scsi/sym53c8xx_2/sym_glue.c @@ -170,9 +170,8 @@ static int sym_xerr_cam_status(int cam_status, int x_status) void sym_set_cam_result_error(struct sym_hcb *np, struct sym_ccb *cp, int resid) { struct scsi_cmnd *cmd = cp->cmd; - u_int cam_status, scsi_status, drv_status; + u_int cam_status, scsi_status; - drv_status = 0; cam_status = DID_OK; scsi_status = cp->ssss_status; @@ -186,7 +185,6 @@ void sym_set_cam_result_error(struct sym_hcb *np, struct sym_ccb *cp, int resid) cp->xerr_status == 0) { cam_status = sym_xerr_cam_status(DID_OK, cp->sv_xerr_status); - drv_status = DRIVER_SENSE; /* * Bounce back the sense data to user. */ @@ -235,7 +233,7 @@ void sym_set_cam_result_error(struct sym_hcb *np, struct sym_ccb *cp, int resid) cam_status = sym_xerr_cam_status(DID_ERROR, cp->xerr_status); } scsi_set_resid(cmd, resid); - cmd->result = (drv_status << 24) | (cam_status << 16) | scsi_status; + cmd->result = (cam_status << 16) | scsi_status; } static int sym_scatter(struct sym_hcb *np, struct sym_ccb *cp, struct scsi_cmnd *cmd) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 9523e268c0e8..02267b090729 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -8604,7 +8604,7 @@ static int ufshcd_set_dev_pwr_mode(struct ufs_hba *hba, sdev_printk(KERN_WARNING, sdp, "START_STOP failed for power mode: %d, result %x\n", pwr_mode, ret); - if (ret > 0 && driver_byte(ret) == DRIVER_SENSE) + if (ret > 0 && scsi_sense_valid(&sshdr)) scsi_print_sense_hdr(sdp, NULL, &sshdr); } diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c index 1678b6f14af9..fd69a03d6137 100644 --- a/drivers/scsi/virtio_scsi.c +++ b/drivers/scsi/virtio_scsi.c @@ -161,8 +161,7 @@ static void virtscsi_complete_cmd(struct virtio_scsi *vscsi, void *buf) min_t(u32, virtio32_to_cpu(vscsi->vdev, resp->sense_len), VIRTIO_SCSI_SENSE_SIZE)); - if (resp->sense_len) - set_driver_byte(sc, DRIVER_SENSE); + set_status_byte(sc, SAM_STAT_CHECK_CONDITION); } sc->scsi_done(sc); diff --git a/drivers/scsi/vmw_pvscsi.c b/drivers/scsi/vmw_pvscsi.c index 8a79605d9652..f0707eaad9f7 100644 --- a/drivers/scsi/vmw_pvscsi.c +++ b/drivers/scsi/vmw_pvscsi.c @@ -576,9 +576,6 @@ static void pvscsi_complete_request(struct pvscsi_adapter *adapter, cmd->result = (DID_RESET << 16); } else { cmd->result = (DID_OK << 16) | sdstat; - if (sdstat == SAM_STAT_CHECK_CONDITION && - cmd->sense_buffer) - cmd->result |= (DRIVER_SENSE << 24); } } else switch (btstat) { diff --git a/drivers/target/loopback/tcm_loop.c b/drivers/target/loopback/tcm_loop.c index 2687fd7d45db..6d0b0e67e79e 100644 --- a/drivers/target/loopback/tcm_loop.c +++ b/drivers/target/loopback/tcm_loop.c @@ -566,7 +566,6 @@ static int tcm_loop_queue_data_or_status(const char *func, memcpy(sc->sense_buffer, se_cmd->sense_buffer, SCSI_SENSE_BUFFERSIZE); sc->result = SAM_STAT_CHECK_CONDITION; - set_driver_byte(sc, DRIVER_SENSE); } else sc->result = scsi_status; diff --git a/drivers/usb/storage/cypress_atacb.c b/drivers/usb/storage/cypress_atacb.c index a6f3267bbef6..2f7093ba5a2f 100644 --- a/drivers/usb/storage/cypress_atacb.c +++ b/drivers/usb/storage/cypress_atacb.c @@ -221,11 +221,11 @@ static void cypress_atacb_passthrough(struct scsi_cmnd *srb, struct us_data *us) desc[12] = regs[6]; /* device */ desc[13] = regs[7]; /* command */ - srb->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; + srb->result = SAM_STAT_CHECK_CONDITION; } goto end; invalid_fld: - srb->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; + srb->result = SAM_STAT_CHECK_CONDITION; memcpy(srb->sense_buffer, usb_stor_sense_invalidCDB, diff --git a/drivers/xen/xen-scsiback.c b/drivers/xen/xen-scsiback.c index 55a4763da05e..3ec038cd4332 100644 --- a/drivers/xen/xen-scsiback.c +++ b/drivers/xen/xen-scsiback.c @@ -1401,8 +1401,7 @@ static int scsiback_queue_status(struct se_cmd *se_cmd) if (se_cmd->sense_buffer && ((se_cmd->se_cmd_flags & SCF_TRANSPORT_TASK_SENSE) || (se_cmd->se_cmd_flags & SCF_EMULATED_TASK_SENSE))) - pending_req->result = (DRIVER_SENSE << 24) | - SAM_STAT_CHECK_CONDITION; + pending_req->result = SAM_STAT_CHECK_CONDITION; else pending_req->result = se_cmd->scsi_status; diff --git a/include/scsi/sg.h b/include/scsi/sg.h index e1a42c2409cc..d5c17775c3b4 100644 --- a/include/scsi/sg.h +++ b/include/scsi/sg.h @@ -131,6 +131,17 @@ struct compat_sg_io_hdr { #define SG_INFO_DIRECT_IO 0x2 /* direct IO requested and performed */ #define SG_INFO_MIXED_IO 0x4 /* part direct, part indirect IO */ +/* + * Obsolete DRIVER_SENSE driver byte + * + * Originally the SCSI midlayer would set the DRIVER_SENSE driver byte when + * a sense code was generated and a sense buffer was allocated. + * However, as nowadays every scsi command has a sense code allocated this + * distinction became moot as one could check the sense buffer directly. + * Consequently this byte is not set anymore from the midlayer, but SG will + * keep setting this byte to be compatible with previous releases. + */ +#define DRIVER_SENSE 0x08 typedef struct sg_scsi_id { /* used by SG_GET_SCSI_ID ioctl() */ int host_no; /* as in "scsi" where 'n' is one of 0, 1, 2 etc */ -- cgit v1.2.3 From 14b40c1e7ccc07e486719362f6f29ec5e3151331 Mon Sep 17 00:00:00 2001 From: Hannes Reinecke Date: Tue, 27 Apr 2021 10:30:45 +0200 Subject: scsi: target: Use standard SAM status types target_complete_cmd() and friends requires a SAM status type, so passing GOOD here is actually wrong. Link: https://lore.kernel.org/r/20210427083046.31620-40-hare@suse.de Reviewed-by: Bart Van Assche Signed-off-by: Hannes Reinecke Signed-off-by: Martin K. Petersen --- drivers/target/target_core_alua.c | 6 +++--- drivers/target/target_core_iblock.c | 2 +- drivers/target/target_core_pr.c | 8 ++++---- drivers/target/target_core_pscsi.c | 2 +- drivers/target/target_core_sbc.c | 10 +++++----- drivers/target/target_core_spc.c | 14 +++++++------- drivers/target/target_core_xcopy.c | 2 +- 7 files changed, 22 insertions(+), 22 deletions(-) (limited to 'drivers/target') diff --git a/drivers/target/target_core_alua.c b/drivers/target/target_core_alua.c index 5517c7dd5144..3bb921345bce 100644 --- a/drivers/target/target_core_alua.c +++ b/drivers/target/target_core_alua.c @@ -123,7 +123,7 @@ target_emulate_report_referrals(struct se_cmd *cmd) transport_kunmap_data_sg(cmd); - target_complete_cmd(cmd, GOOD); + target_complete_cmd(cmd, SAM_STAT_GOOD); return 0; } @@ -255,7 +255,7 @@ target_emulate_report_target_port_groups(struct se_cmd *cmd) } transport_kunmap_data_sg(cmd); - target_complete_cmd_with_length(cmd, GOOD, rd_len + 4); + target_complete_cmd_with_length(cmd, SAM_STAT_GOOD, rd_len + 4); return 0; } @@ -424,7 +424,7 @@ target_emulate_set_target_port_groups(struct se_cmd *cmd) out: transport_kunmap_data_sg(cmd); if (!rc) - target_complete_cmd(cmd, GOOD); + target_complete_cmd(cmd, SAM_STAT_GOOD); return rc; } diff --git a/drivers/target/target_core_iblock.c b/drivers/target/target_core_iblock.c index d6fdd1c61f90..deb2b8b64d20 100644 --- a/drivers/target/target_core_iblock.c +++ b/drivers/target/target_core_iblock.c @@ -474,7 +474,7 @@ iblock_execute_zero_out(struct block_device *bdev, struct se_cmd *cmd) if (ret) return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; - target_complete_cmd(cmd, GOOD); + target_complete_cmd(cmd, SAM_STAT_GOOD); return 0; } diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c index 6fd5fec95539..4b94b085625b 100644 --- a/drivers/target/target_core_pr.c +++ b/drivers/target/target_core_pr.c @@ -234,7 +234,7 @@ target_scsi2_reservation_release(struct se_cmd *cmd) out_unlock: spin_unlock(&dev->dev_reservation_lock); out: - target_complete_cmd(cmd, GOOD); + target_complete_cmd(cmd, SAM_STAT_GOOD); return 0; } @@ -297,7 +297,7 @@ out_unlock: spin_unlock(&dev->dev_reservation_lock); out: if (!ret) - target_complete_cmd(cmd, GOOD); + target_complete_cmd(cmd, SAM_STAT_GOOD); return ret; } @@ -3676,7 +3676,7 @@ target_scsi3_emulate_pr_out(struct se_cmd *cmd) } if (!ret) - target_complete_cmd(cmd, GOOD); + target_complete_cmd(cmd, SAM_STAT_GOOD); return ret; } @@ -4073,7 +4073,7 @@ target_scsi3_emulate_pr_in(struct se_cmd *cmd) } if (!ret) - target_complete_cmd(cmd, GOOD); + target_complete_cmd(cmd, SAM_STAT_GOOD); return ret; } diff --git a/drivers/target/target_core_pscsi.c b/drivers/target/target_core_pscsi.c index f2a11414366d..e2b97cba6679 100644 --- a/drivers/target/target_core_pscsi.c +++ b/drivers/target/target_core_pscsi.c @@ -1044,7 +1044,7 @@ static void pscsi_req_done(struct request *req, blk_status_t status) struct se_cmd *cmd = req->end_io_data; struct pscsi_plugin_task *pt = cmd->priv; int result = scsi_req(req)->result; - u8 scsi_status = status_byte(result) << 1; + u8 scsi_status = result & 0xff; if (scsi_status != SAM_STAT_GOOD) { pr_debug("PSCSI Status Byte exception at cmd: %p CDB:" diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c index 7b07e557dc8d..b32f4ee88e79 100644 --- a/drivers/target/target_core_sbc.c +++ b/drivers/target/target_core_sbc.c @@ -67,7 +67,7 @@ sbc_emulate_readcapacity(struct se_cmd *cmd) transport_kunmap_data_sg(cmd); } - target_complete_cmd_with_length(cmd, GOOD, 8); + target_complete_cmd_with_length(cmd, SAM_STAT_GOOD, 8); return 0; } @@ -130,7 +130,7 @@ sbc_emulate_readcapacity_16(struct se_cmd *cmd) transport_kunmap_data_sg(cmd); } - target_complete_cmd_with_length(cmd, GOOD, 32); + target_complete_cmd_with_length(cmd, SAM_STAT_GOOD, 32); return 0; } @@ -202,14 +202,14 @@ sbc_execute_write_same_unmap(struct se_cmd *cmd) return ret; } - target_complete_cmd(cmd, GOOD); + target_complete_cmd(cmd, SAM_STAT_GOOD); return 0; } static sense_reason_t sbc_emulate_noop(struct se_cmd *cmd) { - target_complete_cmd(cmd, GOOD); + target_complete_cmd(cmd, SAM_STAT_GOOD); return 0; } @@ -1245,7 +1245,7 @@ sbc_execute_unmap(struct se_cmd *cmd) err: transport_kunmap_data_sg(cmd); if (!ret) - target_complete_cmd(cmd, GOOD); + target_complete_cmd(cmd, SAM_STAT_GOOD); return ret; } diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c index 2cb141ed68f5..22703a0dbd07 100644 --- a/drivers/target/target_core_spc.c +++ b/drivers/target/target_core_spc.c @@ -781,7 +781,7 @@ out: kfree(buf); if (!ret) - target_complete_cmd_with_length(cmd, GOOD, len); + target_complete_cmd_with_length(cmd, SAM_STAT_GOOD, len); return ret; } @@ -1135,7 +1135,7 @@ set_length: transport_kunmap_data_sg(cmd); } - target_complete_cmd_with_length(cmd, GOOD, length); + target_complete_cmd_with_length(cmd, SAM_STAT_GOOD, length); return 0; } @@ -1153,7 +1153,7 @@ static sense_reason_t spc_emulate_modeselect(struct se_cmd *cmd) int i; if (!cmd->data_length) { - target_complete_cmd(cmd, GOOD); + target_complete_cmd(cmd, SAM_STAT_GOOD); return 0; } @@ -1196,7 +1196,7 @@ out: transport_kunmap_data_sg(cmd); if (!ret) - target_complete_cmd(cmd, GOOD); + target_complete_cmd(cmd, SAM_STAT_GOOD); return ret; } @@ -1229,7 +1229,7 @@ static sense_reason_t spc_emulate_request_sense(struct se_cmd *cmd) memcpy(rbuf, buf, min_t(u32, sizeof(buf), cmd->data_length)); transport_kunmap_data_sg(cmd); - target_complete_cmd(cmd, GOOD); + target_complete_cmd(cmd, SAM_STAT_GOOD); return 0; } @@ -1296,7 +1296,7 @@ done: transport_kunmap_data_sg(cmd); } - target_complete_cmd_with_length(cmd, GOOD, 8 + lun_count * 8); + target_complete_cmd_with_length(cmd, SAM_STAT_GOOD, 8 + lun_count * 8); return 0; } EXPORT_SYMBOL(spc_emulate_report_luns); @@ -1304,7 +1304,7 @@ EXPORT_SYMBOL(spc_emulate_report_luns); static sense_reason_t spc_emulate_testunitready(struct se_cmd *cmd) { - target_complete_cmd(cmd, GOOD); + target_complete_cmd(cmd, SAM_STAT_GOOD); return 0; } diff --git a/drivers/target/target_core_xcopy.c b/drivers/target/target_core_xcopy.c index 2e7ce661ef32..0f1319336f3e 100644 --- a/drivers/target/target_core_xcopy.c +++ b/drivers/target/target_core_xcopy.c @@ -998,7 +998,7 @@ static sense_reason_t target_rcr_operating_parameters(struct se_cmd *se_cmd) put_unaligned_be32(42, &p[0]); transport_kunmap_data_sg(se_cmd); - target_complete_cmd(se_cmd, GOOD); + target_complete_cmd(se_cmd, SAM_STAT_GOOD); return TCM_NO_SENSE; } -- cgit v1.2.3 From 149d0e489e807f1e6dc265f975a793cea11ecbea Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 23 May 2021 19:54:56 -0700 Subject: scsi: core: Introduce enums for the SAM and host status codes Make it possible for the compiler to verify whether SAM and host status codes are used correctly. [mkp: resolve conflicts with Hannes' SCSI result series] Link: https://lore.kernel.org/r/20210524025457.11299-3-bvanassche@acm.org Cc: Hannes Reinecke Reviewed-by: John Garry Reviewed-by: Himanshu Madhani Signed-off-by: Bart Van Assche Signed-off-by: Martin K. Petersen --- drivers/scsi/constants.c | 2 +- drivers/target/target_core_pscsi.c | 2 +- include/scsi/scsi.h | 67 ++-------------------------------- include/scsi/scsi_proto.h | 24 +++++++------ include/scsi/scsi_status.h | 74 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 91 insertions(+), 78 deletions(-) create mode 100644 include/scsi/scsi_status.h (limited to 'drivers/target') diff --git a/drivers/scsi/constants.c b/drivers/scsi/constants.c index 41bcfed08260..340785536998 100644 --- a/drivers/scsi/constants.c +++ b/drivers/scsi/constants.c @@ -408,8 +408,8 @@ static const char * const hostbyte_table[]={ const char *scsi_hostbyte_string(int result) { + enum scsi_host_status hb = host_byte(result); const char *hb_string = NULL; - int hb = host_byte(result); if (hb < ARRAY_SIZE(hostbyte_table)) hb_string = hostbyte_table[hb]; diff --git a/drivers/target/target_core_pscsi.c b/drivers/target/target_core_pscsi.c index e2b97cba6679..1646ba8eda11 100644 --- a/drivers/target/target_core_pscsi.c +++ b/drivers/target/target_core_pscsi.c @@ -1044,7 +1044,7 @@ static void pscsi_req_done(struct request *req, blk_status_t status) struct se_cmd *cmd = req->end_io_data; struct pscsi_plugin_task *pt = cmd->priv; int result = scsi_req(req)->result; - u8 scsi_status = result & 0xff; + enum sam_status scsi_status = result & 0xff; if (scsi_status != SAM_STAT_GOOD) { pr_debug("PSCSI Status Byte exception at cmd: %p CDB:" diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h index 358f969f368f..3e46859774c8 100644 --- a/include/scsi/scsi.h +++ b/include/scsi/scsi.h @@ -11,6 +11,7 @@ #include #include #include +#include struct scsi_cmnd; @@ -79,78 +80,14 @@ static inline int scsi_status_is_check_condition(int status) } /* - * MESSAGE CODES + * Extended message codes. */ - -#define COMMAND_COMPLETE 0x00 -#define EXTENDED_MESSAGE 0x01 #define EXTENDED_MODIFY_DATA_POINTER 0x00 #define EXTENDED_SDTR 0x01 #define EXTENDED_EXTENDED_IDENTIFY 0x02 /* SCSI-I only */ #define EXTENDED_WDTR 0x03 #define EXTENDED_PPR 0x04 #define EXTENDED_MODIFY_BIDI_DATA_PTR 0x05 -#define SAVE_POINTERS 0x02 -#define RESTORE_POINTERS 0x03 -#define DISCONNECT 0x04 -#define INITIATOR_ERROR 0x05 -#define ABORT_TASK_SET 0x06 -#define MESSAGE_REJECT 0x07 -#define NOP 0x08 -#define MSG_PARITY_ERROR 0x09 -#define LINKED_CMD_COMPLETE 0x0a -#define LINKED_FLG_CMD_COMPLETE 0x0b -#define TARGET_RESET 0x0c -#define ABORT_TASK 0x0d -#define CLEAR_TASK_SET 0x0e -#define INITIATE_RECOVERY 0x0f /* SCSI-II only */ -#define RELEASE_RECOVERY 0x10 /* SCSI-II only */ -#define TERMINATE_IO_PROC 0x11 /* SCSI-II only */ -#define CLEAR_ACA 0x16 -#define LOGICAL_UNIT_RESET 0x17 -#define SIMPLE_QUEUE_TAG 0x20 -#define HEAD_OF_QUEUE_TAG 0x21 -#define ORDERED_QUEUE_TAG 0x22 -#define IGNORE_WIDE_RESIDUE 0x23 -#define ACA 0x24 -#define QAS_REQUEST 0x55 - -/* Old SCSI2 names, don't use in new code */ -#define BUS_DEVICE_RESET TARGET_RESET -#define ABORT ABORT_TASK_SET - -/* - * Host byte codes - */ - -#define DID_OK 0x00 /* NO error */ -#define DID_NO_CONNECT 0x01 /* Couldn't connect before timeout period */ -#define DID_BUS_BUSY 0x02 /* BUS stayed busy through time out period */ -#define DID_TIME_OUT 0x03 /* TIMED OUT for other reason */ -#define DID_BAD_TARGET 0x04 /* BAD target. */ -#define DID_ABORT 0x05 /* Told to abort for some other reason */ -#define DID_PARITY 0x06 /* Parity error */ -#define DID_ERROR 0x07 /* Internal error */ -#define DID_RESET 0x08 /* Reset by somebody. */ -#define DID_BAD_INTR 0x09 /* Got an interrupt we weren't expecting. */ -#define DID_PASSTHROUGH 0x0a /* Force command past mid-layer */ -#define DID_SOFT_ERROR 0x0b /* The low level driver just wish a retry */ -#define DID_IMM_RETRY 0x0c /* Retry without decrementing retry count */ -#define DID_REQUEUE 0x0d /* Requeue command (no immediate retry) also - * without decrementing the retry count */ -#define DID_TRANSPORT_DISRUPTED 0x0e /* Transport error disrupted execution - * and the driver blocked the port to - * recover the link. Transport class will - * retry or fail IO */ -#define DID_TRANSPORT_FAILFAST 0x0f /* Transport class fastfailed the io */ -#define DID_TARGET_FAILURE 0x10 /* Permanent target failure, do not retry on - * other paths */ -#define DID_NEXUS_FAILURE 0x11 /* Permanent nexus failure, retry on other - * paths might yield different results */ -#define DID_ALLOC_FAILURE 0x12 /* Space allocation on the device failed */ -#define DID_MEDIUM_ERROR 0x13 /* Medium error */ -#define DID_TRANSPORT_MARGINAL 0x14 /* Transport marginal errors */ -#define DRIVER_OK 0x00 /* Driver status */ /* * Internal return values. diff --git a/include/scsi/scsi_proto.h b/include/scsi/scsi_proto.h index cb218a576bcf..f017843a8124 100644 --- a/include/scsi/scsi_proto.h +++ b/include/scsi/scsi_proto.h @@ -190,17 +190,19 @@ struct scsi_varlen_cdb_hdr { * SCSI Architecture Model (SAM) Status codes. Taken from SAM-3 draft * T10/1561-D Revision 4 Draft dated 7th November 2002. */ -#define SAM_STAT_GOOD 0x00 -#define SAM_STAT_CHECK_CONDITION 0x02 -#define SAM_STAT_CONDITION_MET 0x04 -#define SAM_STAT_BUSY 0x08 -#define SAM_STAT_INTERMEDIATE 0x10 -#define SAM_STAT_INTERMEDIATE_CONDITION_MET 0x14 -#define SAM_STAT_RESERVATION_CONFLICT 0x18 -#define SAM_STAT_COMMAND_TERMINATED 0x22 /* obsolete in SAM-3 */ -#define SAM_STAT_TASK_SET_FULL 0x28 -#define SAM_STAT_ACA_ACTIVE 0x30 -#define SAM_STAT_TASK_ABORTED 0x40 +enum sam_status { + SAM_STAT_GOOD = 0x00, + SAM_STAT_CHECK_CONDITION = 0x02, + SAM_STAT_CONDITION_MET = 0x04, + SAM_STAT_BUSY = 0x08, + SAM_STAT_INTERMEDIATE = 0x10, + SAM_STAT_INTERMEDIATE_CONDITION_MET = 0x14, + SAM_STAT_RESERVATION_CONFLICT = 0x18, + SAM_STAT_COMMAND_TERMINATED = 0x22, /* obsolete in SAM-3 */ + SAM_STAT_TASK_SET_FULL = 0x28, + SAM_STAT_ACA_ACTIVE = 0x30, + SAM_STAT_TASK_ABORTED = 0x40, +}; #define STATUS_MASK 0xfe /* diff --git a/include/scsi/scsi_status.h b/include/scsi/scsi_status.h new file mode 100644 index 000000000000..31d30cee1869 --- /dev/null +++ b/include/scsi/scsi_status.h @@ -0,0 +1,74 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _SCSI_SCSI_STATUS_H +#define _SCSI_SCSI_STATUS_H + +#include +#include + +/* Message codes. */ +enum scsi_msg_byte { + COMMAND_COMPLETE = 0x00, + EXTENDED_MESSAGE = 0x01, + SAVE_POINTERS = 0x02, + RESTORE_POINTERS = 0x03, + DISCONNECT = 0x04, + INITIATOR_ERROR = 0x05, + ABORT_TASK_SET = 0x06, + MESSAGE_REJECT = 0x07, + NOP = 0x08, + MSG_PARITY_ERROR = 0x09, + LINKED_CMD_COMPLETE = 0x0a, + LINKED_FLG_CMD_COMPLETE = 0x0b, + TARGET_RESET = 0x0c, + ABORT_TASK = 0x0d, + CLEAR_TASK_SET = 0x0e, + INITIATE_RECOVERY = 0x0f, /* SCSI-II only */ + RELEASE_RECOVERY = 0x10, /* SCSI-II only */ + TERMINATE_IO_PROC = 0x11, /* SCSI-II only */ + CLEAR_ACA = 0x16, + LOGICAL_UNIT_RESET = 0x17, + SIMPLE_QUEUE_TAG = 0x20, + HEAD_OF_QUEUE_TAG = 0x21, + ORDERED_QUEUE_TAG = 0x22, + IGNORE_WIDE_RESIDUE = 0x23, + ACA = 0x24, + QAS_REQUEST = 0x55, + + /* Old SCSI2 names, don't use in new code */ + BUS_DEVICE_RESET = TARGET_RESET, + ABORT = ABORT_TASK_SET, +}; + +/* Host byte codes. */ +enum scsi_host_status { + DID_OK = 0x00, /* NO error */ + DID_NO_CONNECT = 0x01, /* Couldn't connect before timeout period */ + DID_BUS_BUSY = 0x02, /* BUS stayed busy through time out period */ + DID_TIME_OUT = 0x03, /* TIMED OUT for other reason */ + DID_BAD_TARGET = 0x04, /* BAD target. */ + DID_ABORT = 0x05, /* Told to abort for some other reason */ + DID_PARITY = 0x06, /* Parity error */ + DID_ERROR = 0x07, /* Internal error */ + DID_RESET = 0x08, /* Reset by somebody. */ + DID_BAD_INTR = 0x09, /* Got an interrupt we weren't expecting. */ + DID_PASSTHROUGH = 0x0a, /* Force command past mid-layer */ + DID_SOFT_ERROR = 0x0b, /* The low level driver just wish a retry */ + DID_IMM_RETRY = 0x0c, /* Retry without decrementing retry count */ + DID_REQUEUE = 0x0d, /* Requeue command (no immediate retry) also + * without decrementing the retry count */ + DID_TRANSPORT_DISRUPTED = 0x0e, /* Transport error disrupted execution + * and the driver blocked the port to + * recover the link. Transport class will + * retry or fail IO */ + DID_TRANSPORT_FAILFAST = 0x0f, /* Transport class fastfailed the io */ + DID_TARGET_FAILURE = 0x10, /* Permanent target failure, do not retry on + * other paths */ + DID_NEXUS_FAILURE = 0x11, /* Permanent nexus failure, retry on other + * paths might yield different results */ + DID_ALLOC_FAILURE = 0x12, /* Space allocation on the device failed */ + DID_MEDIUM_ERROR = 0x13, /* Medium error */ + DID_TRANSPORT_MARGINAL = 0x14, /* Transport marginal errors */ +}; + +#endif /* _SCSI_SCSI_STATUS_H */ -- cgit v1.2.3 From 79366f0a8de24fc451017b710467deaa2811d6eb Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Thu, 17 Jun 2021 12:43:47 +0100 Subject: scsi: target: iscsi: Remove redundant continue statement The continue statement at the end of a loop has no effect, remove it. Link: https://lore.kernel.org/r/20210617114347.10247-1-colin.king@canonical.com Signed-off-by: Colin Ian King Signed-off-by: Martin K. Petersen Addresses-Coverity: ("Continue has no effect") --- drivers/target/iscsi/iscsi_target_erl1.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'drivers/target') diff --git a/drivers/target/iscsi/iscsi_target_erl1.c b/drivers/target/iscsi/iscsi_target_erl1.c index cd670cb9b8fb..0dd52f484fec 100644 --- a/drivers/target/iscsi/iscsi_target_erl1.c +++ b/drivers/target/iscsi/iscsi_target_erl1.c @@ -871,8 +871,6 @@ int iscsit_execute_ooo_cmdsns(struct iscsi_session *sess) if (iscsit_execute_cmd(cmd, 1) < 0) return -1; - - continue; } return ooo_count; -- cgit v1.2.3