Skip to content

Commit 2903265

Browse files
bvanasschemartinkpetersen
authored andcommitted
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. Cc: Avri Altman <avri.altman@wdc.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Fixes: cb38845 ("scsi: ufs: core: Set the residual byte count") Signed-off-by: Bart Van Assche <bvanassche@acm.org> Link: https://lore.kernel.org/r/20230724200843.3376570-2-bvanassche@acm.org Reviewed-by: Avri Altman <avri.altman@wdc.com> Reviewed-by: Adrian Hunter <adrian.hunter@intel.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 65aca38 commit 2903265

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

drivers/ufs/core/ufshcd.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5222,9 +5222,17 @@ ufshcd_transfer_rsp_status(struct ufs_hba *hba, struct ufshcd_lrb *lrbp,
52225222
int result = 0;
52235223
int scsi_status;
52245224
enum utp_ocs ocs;
5225+
u8 upiu_flags;
5226+
u32 resid;
52255227

5226-
scsi_set_resid(lrbp->cmd,
5227-
be32_to_cpu(lrbp->ucd_rsp_ptr->sr.residual_transfer_count));
5228+
upiu_flags = be32_to_cpu(lrbp->ucd_rsp_ptr->header.dword_0) >> 16;
5229+
resid = be32_to_cpu(lrbp->ucd_rsp_ptr->sr.residual_transfer_count);
5230+
/*
5231+
* Test !overflow instead of underflow to support UFS devices that do
5232+
* not set either flag.
5233+
*/
5234+
if (resid && !(upiu_flags & UPIU_RSP_FLAG_OVERFLOW))
5235+
scsi_set_resid(lrbp->cmd, resid);
52285236

52295237
/* overall command status of utrd */
52305238
ocs = ufshcd_get_tr_ocs(lrbp, cqe);

include/ufs/ufs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ enum {
104104
UPIU_CMD_FLAGS_READ = 0x40,
105105
};
106106

107+
/* UPIU response flags */
108+
enum {
109+
UPIU_RSP_FLAG_UNDERFLOW = 0x20,
110+
UPIU_RSP_FLAG_OVERFLOW = 0x40,
111+
};
112+
107113
/* UPIU Task Attributes */
108114
enum {
109115
UPIU_TASK_ATTR_SIMPLE = 0x00,

0 commit comments

Comments
 (0)