Fix residual handling in two SCSI LLDs
Subsystems (4)
Bart Van Assche
maintainerv2 cover Fix residual handling in two SCSI LLDs
Hi Martin,
This patch series fixes the documentation of scsi_set_resid() and also fixes residual handling in two SCSI LLDs. Please consider this patch series for the next merge window.
Thanks,
Bart.
Changes compared to v1:
- Left out a patch that has already been queued.
- Left out the device conformance checks.
Bart Van Assche (2):
scsi: ufs: Fix residual handling
RDMA/srp: Fix residual handling
drivers/infiniband/ulp/srp/ib_srp.c | 4 ---- drivers/ufs/core/ufshcd.c | 12 ++++++++++-- include/ufs/ufs.h | 6 ++++++ 3 files changed, 16 insertions(+), 6 deletions(-)
Bart Van Assche
maintainerPATCH v2 1/2 scsi: ufs: Fix residual handling
Only call scsi_set_resid() in case of an underflow. Do not call scsi_set_resid() in case of an overflow.
--- drivers/ufs/core/ufshcd.c | 12 ++++++++++-- include/ufs/ufs.h | 6 ++++++ 2 files changed, 16 insertions(+), 2 deletions(-)
drivers/ufs/core/ufshcd.c +10 -2
@@ -5222,9 +5222,17 @@ ufshcd_transfer_rsp_status(struct ufs_hba *hba, struct ufshcd_lrb *lrbp,int result =0 ;int scsi_status;enum utp_ocs ocs; +u8 upiu_flags; +u32 resid; -scsi_set_resid (lrbp->cmd, -be32_to_cpu (lrbp->ucd_rsp_ptr->sr.residual_transfer_count)); + upiu_flags =be32_to_cpu (lrbp->ucd_rsp_ptr->header.dword_0) >>16 ; + resid =be32_to_cpu (lrbp->ucd_rsp_ptr->sr.residual_transfer_count); +/* +* Test !overflow instead of underflow to support UFS devices that do +* not set either flag. +*/ +if (resid && !(upiu_flags &UPIU_RSP_FLAG_OVERFLOW )) +scsi_set_resid (lrbp->cmd, resid);/* overall command status of utrd */ ocs =ufshcd_get_tr_ocs (lrbp, cqe);
include/ufs/ufs.h +6 -0
@@ -104,6 +104,12 @@ enum { UPIU_CMD_FLAGS_READ = 0x40, }; +/* UPIU response flags */ +enum { +UPIU_RSP_FLAG_UNDERFLOW =0x20 , +UPIU_RSP_FLAG_OVERFLOW =0x40 , +}; +/* UPIU Task Attributes */ enum {UPIU_TASK_ATTR_SIMPLE =0x00 ,
RE: [PATCH v2 1/2] scsi: ufs: Fix residual handling
Quoted 8 lines
Only call
scsi_set_resid()in case of an underflow. Do not callscsi_set_resid()in case of an overflow.Cc Avri Altman <[email protected]>Cc Adrian Hunter <[email protected]>Fixes cb38845d90fc ("scsi: ufs: core: Set the residual byte count")Signed-off-by Bart Van Assche <[email protected]>
Re: [PATCH v2 1/2] scsi: ufs: Fix residual handling
In reply to Bart Van AsscheQuoted 7 lines · Bart Van Assche
Only call
scsi_set_resid()in case of an underflow. Do not callscsi_set_resid()in case of an overflow.Cc Avri Altman <[email protected]>Cc Adrian Hunter <[email protected]>Fixes cb38845d90fc ("scsi: ufs: core: Set the residual byte count")Signed-off-by Bart Van Assche <[email protected]>
Quoted 46 lines
--- drivers/ufs/core/ufshcd.c | 12 ++++++++++-- include/ufs/ufs.h | 6 ++++++ 2 files changed, 16 insertions(+), 2 deletions(-)drivers/ufs/core/ufshcd.c +10
-2@@ -5222,9 +5222,17 @@ ufshcd_transfer_rsp_status(struct ufs_hba *hba, struct ufshcd_lrb *lrbp,int result =0 ;int scsi_status;enum utp_ocs ocs; +u8 upiu_flags; +u32 resid; -scsi_set_resid (lrbp->cmd, -be32_to_cpu (lrbp->ucd_rsp_ptr->sr.residual_transfer_count)); + upiu_flags =be32_to_cpu (lrbp->ucd_rsp_ptr->header.dword_0) >>16 ; + resid =be32_to_cpu (lrbp->ucd_rsp_ptr->sr.residual_transfer_count); +/* +* Test !overflow instead of underflow to support UFS devices that do +* not set either flag. +*/ +if (resid && !(upiu_flags &UPIU_RSP_FLAG_OVERFLOW )) +scsi_set_resid (lrbp->cmd, resid);/* overall command status of utrd */ ocs =ufshcd_get_tr_ocs (lrbp, cqe);include/ufs/ufs.h +6
-0@@ -104,6 +104,12 @@ enum { UPIU_CMD_FLAGS_READ = 0x40, }; +/* UPIU response flags */ +enum { +UPIU_RSP_FLAG_UNDERFLOW =0x20 , +UPIU_RSP_FLAG_OVERFLOW =0x40 , +}; +/* UPIU Task Attributes */ enum {UPIU_TASK_ATTR_SIMPLE =0x00 ,
Bart Van Assche
maintainerPATCH v2 2/2 RDMA/srp: Fix residual handling
In reply to Bart Van AsscheAlthough the code for residual handling in the SRP initiator follows the SCSI documentation, that documentation has never been correct. Because scsi_finish_command() starts from the data buffer length and subtracts the residual, scsi_set_resid() must not be called if a residual overflow occurs. Hence remove the scsi_set_resid() calls from the SRP initiator if a residual overflow occurrs.
--- drivers/infiniband/ulp/srp/ib_srp.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/infiniband/ulp/srp/ib_srp.c +0 -4
@@ -1979,12 +1979,8 @@ static void srp_process_rsp(struct srp_rdma_ch *ch, struct srp_rsp *rsp)if (unlikely (rsp->flags &SRP_RSP_FLAG_DIUNDER ))scsi_set_resid (scmnd,be32_to_cpu (rsp->data_in_res_cnt)); -else if (unlikely (rsp->flags &SRP_RSP_FLAG_DIOVER )) -scsi_set_resid (scmnd, -be32_to_cpu (rsp->data_in_res_cnt));else if (unlikely (rsp->flags &SRP_RSP_FLAG_DOUNDER ))scsi_set_resid (scmnd,be32_to_cpu (rsp->data_out_res_cnt)); -else if (unlikely (rsp->flags &SRP_RSP_FLAG_DOOVER )) -scsi_set_resid (scmnd, -be32_to_cpu (rsp->data_out_res_cnt));srp_free_req (ch, req, scmnd,be32_to_cpu (rsp->req_lim_delta));
Re: [PATCH v2 2/2] RDMA/srp: Fix residual handling
Quoted 7 lines · Bart Van Assche
Although the code for residual handling in the SRP initiator follows the SCSI documentation, that documentation has never been correct. Because
scsi_finish_command()starts from the data buffer length and subtracts the residual,scsi_set_resid()must not be called if a residual overflow occurs. Hence remove thescsi_set_resid()calls from the SRP initiator if a residual overflow occurrs.
Quoted 9 lines
Cc Leon Romanovsky <[email protected]>Cc Jason Gunthorpe <[email protected]>Fixes 9237f04e12cc ("scsi: core: Fix scsi_get/set_resid() interface")Fixes e714531a349f ("IB/srp: Fix residual handling")Signed-off-by Bart Van Assche <[email protected]>--- drivers/infiniband/ulp/srp/ib_srp.c | 4 ---- 1 file changed, 4 deletions(-)
Thanks,
Martin K. Petersen
AppliedBart,
Quoted 3 lines
This patch series fixes the documentation of
scsi_set_resid()and also fixes residual handling in two SCSI LLDs. Please consider this patch series for the next merge window.
Applied to 6.6/scsi-staging, thanks!
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Martin K. Petersen
AppliedQuoted 9 lines · Bart Van Assche
This patch series fixes the documentation of
scsi_set_resid()and also fixes residual handling in two SCSI LLDs. Please consider this patch series for the next merge window.Thanks,
Bart.
[...]
Applied to 6.6/scsi-queue, thanks!
[1/2] scsi: ufs: Fix residual handling
https://git.kernel.org/mkp/scsi/c/2903265e27bf [2/2] RDMA/srp: Fix residual handling https://git.kernel.org/mkp/scsi/c/89e637c19b24
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering