Skip to content

Commit

Permalink
scsi: ufs: Retry aborted SCSI commands instead of completing these su…
Browse files Browse the repository at this point in the history
…ccessfully

[ Upstream commit 73dc3c4 ]

Neither SAM nor the UFS standard require that the UFS controller fills in
the completion status of commands that have been aborted (LUN RESET aborts
pending commands). Hence do not rely on the completion status provided by
the UFS controller for aborted commands but instead ask the SCSI core to
retry SCSI commands that have been aborted.

Link: https://lore.kernel.org/r/20210722033439.26550-18-bvanassche@acm.org
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Stanley Chu <stanley.chu@mediatek.com>
Cc: Can Guo <cang@codeaurora.org>
Cc: Asutosh Das <asutoshd@codeaurora.org>
Cc: Avri Altman <avri.altman@wdc.com>
Reviewed-by: Bean Huo <beanhuo@micron.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
bvanassche authored and gregkh committed Sep 30, 2021
1 parent 4368d7a commit 1d65bff
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions drivers/scsi/ufs/ufshcd.c
Expand Up @@ -5229,10 +5229,12 @@ static irqreturn_t ufshcd_uic_cmd_compl(struct ufs_hba *hba, u32 intr_status)
/**
* __ufshcd_transfer_req_compl - handle SCSI and query command completion
* @hba: per adapter instance
* @completed_reqs: requests to complete
* @completed_reqs: bitmask that indicates which requests to complete
* @retry_requests: whether to ask the SCSI core to retry completed requests
*/
static void __ufshcd_transfer_req_compl(struct ufs_hba *hba,
unsigned long completed_reqs)
unsigned long completed_reqs,
bool retry_requests)
{
struct ufshcd_lrb *lrbp;
struct scsi_cmnd *cmd;
Expand All @@ -5250,7 +5252,8 @@ static void __ufshcd_transfer_req_compl(struct ufs_hba *hba,
if (unlikely(ufshcd_should_inform_monitor(hba, lrbp)))
ufshcd_update_monitor(hba, lrbp);
ufshcd_add_command_trace(hba, index, UFS_CMD_COMP);
result = ufshcd_transfer_rsp_status(hba, lrbp);
result = retry_requests ? DID_BUS_BUSY << 16 :
ufshcd_transfer_rsp_status(hba, lrbp);
scsi_dma_unmap(cmd);
cmd->result = result;
/* Mark completed command as NULL in LRB */
Expand All @@ -5276,12 +5279,14 @@ static void __ufshcd_transfer_req_compl(struct ufs_hba *hba,
/**
* ufshcd_transfer_req_compl - handle SCSI and query command completion
* @hba: per adapter instance
* @retry_requests: whether or not to ask to retry requests
*
* Returns
* IRQ_HANDLED - If interrupt is valid
* IRQ_NONE - If invalid interrupt
*/
static irqreturn_t ufshcd_transfer_req_compl(struct ufs_hba *hba)
static irqreturn_t ufshcd_transfer_req_compl(struct ufs_hba *hba,
bool retry_requests)
{
unsigned long completed_reqs, flags;
u32 tr_doorbell;
Expand All @@ -5303,7 +5308,8 @@ static irqreturn_t ufshcd_transfer_req_compl(struct ufs_hba *hba)
spin_unlock_irqrestore(hba->host->host_lock, flags);

if (completed_reqs) {
__ufshcd_transfer_req_compl(hba, completed_reqs);
__ufshcd_transfer_req_compl(hba, completed_reqs,
retry_requests);
return IRQ_HANDLED;
} else {
return IRQ_NONE;
Expand Down Expand Up @@ -5782,7 +5788,13 @@ static void ufshcd_exception_event_handler(struct work_struct *work)
/* Complete requests that have door-bell cleared */
static void ufshcd_complete_requests(struct ufs_hba *hba)
{
ufshcd_transfer_req_compl(hba);
ufshcd_transfer_req_compl(hba, /*retry_requests=*/false);
ufshcd_tmc_handler(hba);
}

static void ufshcd_retry_aborted_requests(struct ufs_hba *hba)
{
ufshcd_transfer_req_compl(hba, /*retry_requests=*/true);
ufshcd_tmc_handler(hba);
}

Expand Down Expand Up @@ -6124,8 +6136,7 @@ static void ufshcd_err_handler(struct work_struct *work)
}

lock_skip_pending_xfer_clear:
/* Complete the requests that are cleared by s/w */
ufshcd_complete_requests(hba);
ufshcd_retry_aborted_requests(hba);

spin_lock_irqsave(hba->host->host_lock, flags);
hba->silence_err_logs = false;
Expand Down Expand Up @@ -6423,7 +6434,7 @@ static irqreturn_t ufshcd_sl_intr(struct ufs_hba *hba, u32 intr_status)
retval |= ufshcd_tmc_handler(hba);

if (intr_status & UTP_TRANSFER_REQ_COMPL)
retval |= ufshcd_transfer_req_compl(hba);
retval |= ufshcd_transfer_req_compl(hba, /*retry_requests=*/false);

return retval;
}
Expand Down Expand Up @@ -6847,7 +6858,7 @@ static int ufshcd_eh_device_reset_handler(struct scsi_cmnd *cmd)
err = ufshcd_clear_cmd(hba, pos);
if (err)
break;
__ufshcd_transfer_req_compl(hba, pos);
__ufshcd_transfer_req_compl(hba, pos, /*retry_requests=*/true);
}
}

Expand Down Expand Up @@ -7018,7 +7029,7 @@ static int ufshcd_abort(struct scsi_cmnd *cmd)
dev_err(hba->dev,
"%s: cmd was completed, but without a notifying intr, tag = %d",
__func__, tag);
__ufshcd_transfer_req_compl(hba, 1UL << tag);
__ufshcd_transfer_req_compl(hba, 1UL << tag, /*retry_requests=*/false);
goto release;
}

Expand Down Expand Up @@ -7083,7 +7094,7 @@ static int ufshcd_host_reset_and_restore(struct ufs_hba *hba)
*/
ufshcd_hba_stop(hba);
hba->silence_err_logs = true;
ufshcd_complete_requests(hba);
ufshcd_retry_aborted_requests(hba);
hba->silence_err_logs = false;

/* scale up clocks to max frequency before full reinitialization */
Expand Down

0 comments on commit 1d65bff

Please sign in to comment.