Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp8452548ybl; Thu, 16 Jan 2020 17:09:06 -0800 (PST) X-Google-Smtp-Source: APXvYqxv3wYKgvvXy194fLmdIi81y7dBqLsMn55wFDUO6dHc4HDN5pgd6M2uMn2MP9L7emNjTPvk X-Received: by 2002:aca:8d5:: with SMTP id 204mr1542176oii.141.1579223346439; Thu, 16 Jan 2020 17:09:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579223346; cv=none; d=google.com; s=arc-20160816; b=NDHg4ZilDQ6s9y2CDXEqmeb0v2emUfgMq8Pldahh2E5s+lPycPptvfxCDkF71pXh+o CID06S47YhJq84PuUDvhfLsYecvB7f5H3l5TEZ0HiocTHbqSAUXr+1Jzpk/paQ9ztn1H Pi7tnwIJjss/huSSEfIGQoibeqgWc444n9c0i3coxm4ICVGtvbaHt8y5pVzxDpHcUmv3 Jyl62D+StvsXPmmCSGIjiLmPx3UDJE1np4NNjvkUhgqo46LUi1tYnGxifhc4YK7Q1itv NQwXuMrMNroB1TYdfbXqeIzm8yq1v6azUTIXTIWxGSG28A9uyGobllfpUsYR/RSGEm5O OnNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3H2grSUB++rYrmlOhzHsIJYgH3h+ZM8TynFZlv/Ii1E=; b=GjLpBPp2l3uSbPg6zfwpQrDtknJSSyqYPqyYDIPgk7CqDoGjO/RFgdIqkf2BW2pnYF 22UJqMb/ChtA6B7AXVG+JMt9fuhP0bj03GoFcIkhL7eTtcypXRA9WZsgC7hOkweLPEjC 7HhX83oSsIOTFohkXzgyZ2Bkx4THQVo8RR3uxXU+KfNNNMl2TAyEF70WORYlbhwC1Vdy zd8tNosT+c1fXI4gsW1BQgbVV6DTvBKnk3+8+rPTWLulJlLasFiYHBXucDFm7KqY3DEW 0hyAB9E8qqZC6Hvn8z/5E9FFikZ1Aav0n1tZ3gl3Pv1NiCBx2n164Qdr4AkbbruPt+Iu xa0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=J+Aa1uEG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l7si14817638oth.11.2020.01.16.17.08.54; Thu, 16 Jan 2020 17:09:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=J+Aa1uEG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390904AbgAPXWM (ORCPT + 99 others); Thu, 16 Jan 2020 18:22:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:49810 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390894AbgAPXWF (ORCPT ); Thu, 16 Jan 2020 18:22:05 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CAB44206D9; Thu, 16 Jan 2020 23:22:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579216925; bh=V2J9YfWSVeAVG7GVUmiIj3FqxophZV4LyMA8bfFylx4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J+Aa1uEGVZw8IVKzPlNj40rXhZLgiHmicJaTFakGkpV5MTGw3AH3cI9pW5Nlzv0RN ZQ4wOwtMxjTSe0wwQstEqJQGnyK+rGrQyvgAEUi+vYM/8jlyvUj0yyF5Bh9mbWWvPC pNWp/kTrLKGbjLhx8cMFAkSje545PaiEMq9rMzTI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bart Van Assche , Honggang Li , Jason Gunthorpe Subject: [PATCH 5.4 076/203] RDMA/srpt: Report the SCSI residual to the initiator Date: Fri, 17 Jan 2020 00:16:33 +0100 Message-Id: <20200116231750.951965385@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200116231745.218684830@linuxfoundation.org> References: <20200116231745.218684830@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bart Van Assche commit e88982ad1bb12db699de96fbc07096359ef6176c upstream. The code added by this patch is similar to the code that already exists in ibmvscsis_determine_resid(). This patch has been tested by running the following command: strace sg_raw -r 1k /dev/sdb 12 00 00 00 60 00 -o inquiry.bin |& grep resid= Link: https://lore.kernel.org/r/20191105214632.183302-1-bvanassche@acm.org Fixes: a42d985bd5b2 ("ib_srpt: Initial SRP Target merge for v3.3-rc1") Signed-off-by: Bart Van Assche Acked-by: Honggang Li Signed-off-by: Jason Gunthorpe Signed-off-by: Greg Kroah-Hartman --- drivers/infiniband/ulp/srpt/ib_srpt.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) --- a/drivers/infiniband/ulp/srpt/ib_srpt.c +++ b/drivers/infiniband/ulp/srpt/ib_srpt.c @@ -1364,9 +1364,11 @@ static int srpt_build_cmd_rsp(struct srp struct srpt_send_ioctx *ioctx, u64 tag, int status) { + struct se_cmd *cmd = &ioctx->cmd; struct srp_rsp *srp_rsp; const u8 *sense_data; int sense_data_len, max_sense_len; + u32 resid = cmd->residual_count; /* * The lowest bit of all SAM-3 status codes is zero (see also @@ -1388,6 +1390,28 @@ static int srpt_build_cmd_rsp(struct srp srp_rsp->tag = tag; srp_rsp->status = status; + if (cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) { + if (cmd->data_direction == DMA_TO_DEVICE) { + /* residual data from an underflow write */ + srp_rsp->flags = SRP_RSP_FLAG_DOUNDER; + srp_rsp->data_out_res_cnt = cpu_to_be32(resid); + } else if (cmd->data_direction == DMA_FROM_DEVICE) { + /* residual data from an underflow read */ + srp_rsp->flags = SRP_RSP_FLAG_DIUNDER; + srp_rsp->data_in_res_cnt = cpu_to_be32(resid); + } + } else if (cmd->se_cmd_flags & SCF_OVERFLOW_BIT) { + if (cmd->data_direction == DMA_TO_DEVICE) { + /* residual data from an overflow write */ + srp_rsp->flags = SRP_RSP_FLAG_DOOVER; + srp_rsp->data_out_res_cnt = cpu_to_be32(resid); + } else if (cmd->data_direction == DMA_FROM_DEVICE) { + /* residual data from an overflow read */ + srp_rsp->flags = SRP_RSP_FLAG_DIOVER; + srp_rsp->data_in_res_cnt = cpu_to_be32(resid); + } + } + if (sense_data_len) { BUILD_BUG_ON(MIN_MAX_RSP_SIZE <= sizeof(*srp_rsp)); max_sense_len = ch->max_ti_iu_len - sizeof(*srp_rsp);