Skip to contentSkip to conversation

RDMA/srpt: Report the SCSI residual to the initiator

PATCH In review Bart Van Assche 2 participants 3 messages Oct 29, 2019 – Nov 4, 2019

Subsystems (2)
lore
Share & tools
lore

Bart Van Assche

author maintainer
#0 lore raw

PATCH 1/1 RDMA/srpt: Report the SCSI residual to the initiator

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 -f sg_raw -r 1k /dev/sdb 12 00 00 00 60 00 -o inquiry.bin |&
grep resid=

Cc Honggang LI <[email protected]>
Cc Laurence Oberman <[email protected]>
Fixes a42d985bd5b2 ("ib_srpt: Initial SRP Target merge for v3.3-rc1")
---
 drivers/infiniband/ulp/srpt/ib_srpt.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
drivers/infiniband/ulp/srpt/ib_srpt.c +24 -0
index a278e76b9e02..c9972b686c27 100644
@@ -1362,9 +1362,11 @@ static int srpt_build_cmd_rsp(struct srpt_rdma_ch *ch,
 			      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;
+	int resid = cmd->residual_count;
 
 	/*
 	 * The lowest bit of all SAM-3 status codes is zero (see also
@@ -1386,6 +1388,28 @@ static int srpt_build_cmd_rsp(struct srpt_rdma_ch *ch,
 	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);
Signature · 1 line
2.24.0.rc0.303.g954a862665-goog
#1 lore raw
Quoted 20 lines · Bart Van Assche

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 -f sg_raw -r 1k /dev/sdb 12 00 00 00 60 00 -o inquiry.bin |&
grep resid=

Cc Honggang LI <[email protected]>
Cc Laurence Oberman <[email protected]>
Fixes a42d985bd5b2 ("ib_srpt: Initial SRP Target merge for v3.3-rc1")
---
 drivers/infiniband/ulp/srpt/ib_srpt.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
drivers/infiniband/ulp/srpt/ib_srpt.c +0 -0
index a278e76b9e02..c9972b686c27 100644

drivers/infiniband/ulp/srpt/ib_srpt.c static int srpt_build_cmd_rsp(struct srpt_rdma_ch *ch, · line 1369

Quoted 8 lines
drivers/infiniband/ulp/srpt/ib_srpt.c +2 -0
@@ -1362,9 +1362,11 @@ static int srpt_build_cmd_rsp(struct srpt_rdma_ch *ch,
 			      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;
+	int resid = cmd->residual_count;
        ^^^

Should be u32?

author maintainer
#2 lore raw
Quoted 30 lines · Honggang LI
Quoted 20 lines · Bart Van Assche

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 -f sg_raw -r 1k /dev/sdb 12 00 00 00 60 00 -o inquiry.bin |&
grep resid=

Cc Honggang LI <[email protected]>
Cc Laurence Oberman <[email protected]>
Fixes a42d985bd5b2 ("ib_srpt: Initial SRP Target merge for v3.3-rc1")
---
  drivers/infiniband/ulp/srpt/ib_srpt.c | 24 ++++++++++++++++++++++++
  1 file changed, 24 insertions(+)
drivers/infiniband/ulp/srpt/ib_srpt.c +0 -0
index a278e76b9e02..c9972b686c27 100644

drivers/infiniband/ulp/srpt/ib_srpt.c static int srpt_build_cmd_rsp(struct srpt_rdma_ch *ch, · line 1369

Quoted 8 lines
drivers/infiniband/ulp/srpt/ib_srpt.c +2 -0
@@ -1362,9 +1362,11 @@ static int srpt_build_cmd_rsp(struct srpt_rdma_ch *ch,
  			      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;
+	int resid = cmd->residual_count;
         ^^^
Quoted 1 line

Should be u32?

Since se_cmd.residual_count has been declared as u32 it's probably better to declare this variable as u32 too. I will make that change and post a v2.

Thanks,

Bart.