diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 6656c98c7cd2..c2b862f81d2b 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -2665,7 +2665,7 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) (hba->clk_gating.state != CLKS_ON)); lrbp = &hba->lrb[tag]; - if (unlikely(test_bit(tag, &hba->outstanding_reqs))) { + if (unlikely(lrbp->in_use)) { if (hba->pm_op_in_progress) set_host_byte(cmd, DID_BAD_TARGET); else @@ -2925,7 +2925,7 @@ static int ufshcd_exec_dev_cmd(struct ufs_hba *hba, init_completion(&wait); lrbp = &hba->lrb[tag]; - if (unlikely(test_bit(tag, &hba->outstanding_reqs))) { + if (unlikely(lrbp->in_use)) { err = -EBUSY; goto out; } @@ -5134,9 +5134,8 @@ static void __ufshcd_transfer_req_compl(struct ufs_hba *hba, bool update_scaling = false; for_each_set_bit(index, &completed_reqs, hba->nutrs) { - if (!test_and_clear_bit(index, &hba->outstanding_reqs)) - continue; lrbp = &hba->lrb[index]; + lrbp->in_use = false; lrbp->compl_time_stamp = ktime_get(); cmd = lrbp->cmd; if (cmd) { @@ -5168,6 +5167,9 @@ static void __ufshcd_transfer_req_compl(struct ufs_hba *hba, hba->clk_scaling.active_reqs--; } + /* clear corresponding bits of completed commands */ + hba->outstanding_reqs ^= completed_reqs; + ufshcd_clk_scaling_update_busy(hba); } @@ -6601,11 +6603,11 @@ static int ufshcd_issue_devman_upiu_cmd(struct ufs_hba *hba, WARN_ON_ONCE(!ufshcd_valid_tag(hba, tag)); init_completion(&wait); - if (unlikely(test_bit(tag, &hba->outstanding_reqs))) { + lrbp = &hba->lrb[tag]; + if (unlikely(lrbp->in_use)) { err = -EBUSY; goto out; } - lrbp = &hba->lrb[tag]; WARN_ON(lrbp->cmd); lrbp->cmd = NULL; @@ -6974,6 +6976,7 @@ static int ufshcd_abort(struct scsi_cmnd *cmd) if (lrbp->cmd) { __ufshcd_transfer_req_compl(hba, (1UL << tag)); __set_bit(tag, &hba->outstanding_reqs); + lrbp->in_use = true; hba->force_reset = true; ufshcd_schedule_eh_work(hba); } diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index 0c70f8a8c158..9ce98969446c 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -188,6 +188,7 @@ struct ufs_pm_lvl_states { * @crypto_key_slot: the key slot to use for inline crypto (-1 if none) * @data_unit_num: the data unit number for the first block for inline crypto * @req_abort_skip: skip request abort task flag + * @in_use: indicates that this lrb is still in use */ struct ufshcd_lrb { struct utp_transfer_req_desc *utr_descriptor_ptr; @@ -217,6 +218,7 @@ struct ufshcd_lrb { #endif bool req_abort_skip; + bool in_use; }; /**