All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] scsi: ufs: Introduce ufshcd_abort_all()
@ 2022-10-31 18:34 Bart Van Assche
  2022-10-31 18:51 ` Adrian Hunter
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Bart Van Assche @ 2022-10-31 18:34 UTC (permalink / raw)
  To: Martin K . Petersen
  Cc: Jaegeuk Kim, linux-scsi, Adrian Hunter, Bart Van Assche,
	James E.J. Bottomley, Bean Huo, Avri Altman, Jinyoung Choi

Move the code for aborting all SCSI commands and TMFs into a new function.
This patch makes the ufshcd_err_handler() easier to read. Except for adding
more logging, this patch does not change any functionality.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---

Changes compared to v1:
- changed type of 'tag' and 'ret' from 'unsigned int' into 'int'.

 drivers/ufs/core/ufshcd.c | 62 +++++++++++++++++++++------------------
 1 file changed, 34 insertions(+), 28 deletions(-)

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index b81a218f5644..d91e1f31c66f 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -6159,6 +6159,38 @@ static bool ufshcd_is_pwr_mode_restore_needed(struct ufs_hba *hba)
 	return false;
 }
 
+static bool ufshcd_abort_all(struct ufs_hba *hba)
+{
+	bool needs_reset = false;
+	int tag, ret;
+
+	/* Clear pending transfer requests */
+	for_each_set_bit(tag, &hba->outstanding_reqs, hba->nutrs) {
+		ret = ufshcd_try_to_abort_task(hba, tag);
+		dev_err(hba->dev, "Aborting tag %d / CDB %#02x %s\n", tag,
+			hba->lrb[tag].cmd ? hba->lrb[tag].cmd->cmnd[0] : -1,
+			ret ? "failed" : "succeeded");
+		if (ret) {
+			needs_reset = true;
+			goto out;
+		}
+	}
+
+	/* Clear pending task management requests */
+	for_each_set_bit(tag, &hba->outstanding_tasks, hba->nutmrs) {
+		if (ufshcd_clear_tm_cmd(hba, tag)) {
+			needs_reset = true;
+			goto out;
+		}
+	}
+
+out:
+	/* Complete the requests that are cleared by s/w */
+	ufshcd_complete_requests(hba);
+
+	return needs_reset;
+}
+
 /**
  * ufshcd_err_handler - handle UFS errors that require s/w attention
  * @work: pointer to work structure
@@ -6170,10 +6202,7 @@ static void ufshcd_err_handler(struct work_struct *work)
 	unsigned long flags;
 	bool needs_restore;
 	bool needs_reset;
-	bool err_xfer;
-	bool err_tm;
 	int pmc_err;
-	int tag;
 
 	hba = container_of(work, struct ufs_hba, eh_work);
 
@@ -6202,8 +6231,6 @@ static void ufshcd_err_handler(struct work_struct *work)
 again:
 	needs_restore = false;
 	needs_reset = false;
-	err_xfer = false;
-	err_tm = false;
 
 	if (hba->ufshcd_state != UFSHCD_STATE_ERROR)
 		hba->ufshcd_state = UFSHCD_STATE_RESET;
@@ -6272,34 +6299,13 @@ static void ufshcd_err_handler(struct work_struct *work)
 	hba->silence_err_logs = true;
 	/* release lock as clear command might sleep */
 	spin_unlock_irqrestore(hba->host->host_lock, flags);
-	/* Clear pending transfer requests */
-	for_each_set_bit(tag, &hba->outstanding_reqs, hba->nutrs) {
-		if (ufshcd_try_to_abort_task(hba, tag)) {
-			err_xfer = true;
-			goto lock_skip_pending_xfer_clear;
-		}
-		dev_err(hba->dev, "Aborted tag %d / CDB %#02x\n", tag,
-			hba->lrb[tag].cmd ? hba->lrb[tag].cmd->cmnd[0] : -1);
-	}
 
-	/* Clear pending task management requests */
-	for_each_set_bit(tag, &hba->outstanding_tasks, hba->nutmrs) {
-		if (ufshcd_clear_tm_cmd(hba, tag)) {
-			err_tm = true;
-			goto lock_skip_pending_xfer_clear;
-		}
-	}
-
-lock_skip_pending_xfer_clear:
-	/* Complete the requests that are cleared by s/w */
-	ufshcd_complete_requests(hba);
+	needs_reset = ufshcd_abort_all(hba);
 
 	spin_lock_irqsave(hba->host->host_lock, flags);
 	hba->silence_err_logs = false;
-	if (err_xfer || err_tm) {
-		needs_reset = true;
+	if (needs_reset)
 		goto do_reset;
-	}
 
 	/*
 	 * After all reqs and tasks are cleared from doorbell,

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] scsi: ufs: Introduce ufshcd_abort_all()
  2022-10-31 18:34 [PATCH v2] scsi: ufs: Introduce ufshcd_abort_all() Bart Van Assche
@ 2022-10-31 18:51 ` Adrian Hunter
  2022-11-08  3:03 ` Martin K. Petersen
  2022-11-17 18:29 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Adrian Hunter @ 2022-10-31 18:51 UTC (permalink / raw)
  To: Bart Van Assche, Martin K . Petersen
  Cc: Jaegeuk Kim, linux-scsi, James E.J. Bottomley, Bean Huo,
	Avri Altman, Jinyoung Choi

On 31/10/22 20:34, Bart Van Assche wrote:
> Move the code for aborting all SCSI commands and TMFs into a new function.
> This patch makes the ufshcd_err_handler() easier to read. Except for adding
> more logging, this patch does not change any functionality.
> 
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>

Reviewed-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
> 
> Changes compared to v1:
> - changed type of 'tag' and 'ret' from 'unsigned int' into 'int'.
> 
>  drivers/ufs/core/ufshcd.c | 62 +++++++++++++++++++++------------------
>  1 file changed, 34 insertions(+), 28 deletions(-)
> 
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index b81a218f5644..d91e1f31c66f 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -6159,6 +6159,38 @@ static bool ufshcd_is_pwr_mode_restore_needed(struct ufs_hba *hba)
>  	return false;
>  }
>  
> +static bool ufshcd_abort_all(struct ufs_hba *hba)
> +{
> +	bool needs_reset = false;
> +	int tag, ret;
> +
> +	/* Clear pending transfer requests */
> +	for_each_set_bit(tag, &hba->outstanding_reqs, hba->nutrs) {
> +		ret = ufshcd_try_to_abort_task(hba, tag);
> +		dev_err(hba->dev, "Aborting tag %d / CDB %#02x %s\n", tag,
> +			hba->lrb[tag].cmd ? hba->lrb[tag].cmd->cmnd[0] : -1,
> +			ret ? "failed" : "succeeded");
> +		if (ret) {
> +			needs_reset = true;
> +			goto out;
> +		}
> +	}
> +
> +	/* Clear pending task management requests */
> +	for_each_set_bit(tag, &hba->outstanding_tasks, hba->nutmrs) {
> +		if (ufshcd_clear_tm_cmd(hba, tag)) {
> +			needs_reset = true;
> +			goto out;
> +		}
> +	}
> +
> +out:
> +	/* Complete the requests that are cleared by s/w */
> +	ufshcd_complete_requests(hba);
> +
> +	return needs_reset;
> +}
> +
>  /**
>   * ufshcd_err_handler - handle UFS errors that require s/w attention
>   * @work: pointer to work structure
> @@ -6170,10 +6202,7 @@ static void ufshcd_err_handler(struct work_struct *work)
>  	unsigned long flags;
>  	bool needs_restore;
>  	bool needs_reset;
> -	bool err_xfer;
> -	bool err_tm;
>  	int pmc_err;
> -	int tag;
>  
>  	hba = container_of(work, struct ufs_hba, eh_work);
>  
> @@ -6202,8 +6231,6 @@ static void ufshcd_err_handler(struct work_struct *work)
>  again:
>  	needs_restore = false;
>  	needs_reset = false;
> -	err_xfer = false;
> -	err_tm = false;
>  
>  	if (hba->ufshcd_state != UFSHCD_STATE_ERROR)
>  		hba->ufshcd_state = UFSHCD_STATE_RESET;
> @@ -6272,34 +6299,13 @@ static void ufshcd_err_handler(struct work_struct *work)
>  	hba->silence_err_logs = true;
>  	/* release lock as clear command might sleep */
>  	spin_unlock_irqrestore(hba->host->host_lock, flags);
> -	/* Clear pending transfer requests */
> -	for_each_set_bit(tag, &hba->outstanding_reqs, hba->nutrs) {
> -		if (ufshcd_try_to_abort_task(hba, tag)) {
> -			err_xfer = true;
> -			goto lock_skip_pending_xfer_clear;
> -		}
> -		dev_err(hba->dev, "Aborted tag %d / CDB %#02x\n", tag,
> -			hba->lrb[tag].cmd ? hba->lrb[tag].cmd->cmnd[0] : -1);
> -	}
>  
> -	/* Clear pending task management requests */
> -	for_each_set_bit(tag, &hba->outstanding_tasks, hba->nutmrs) {
> -		if (ufshcd_clear_tm_cmd(hba, tag)) {
> -			err_tm = true;
> -			goto lock_skip_pending_xfer_clear;
> -		}
> -	}
> -
> -lock_skip_pending_xfer_clear:
> -	/* Complete the requests that are cleared by s/w */
> -	ufshcd_complete_requests(hba);
> +	needs_reset = ufshcd_abort_all(hba);
>  
>  	spin_lock_irqsave(hba->host->host_lock, flags);
>  	hba->silence_err_logs = false;
> -	if (err_xfer || err_tm) {
> -		needs_reset = true;
> +	if (needs_reset)
>  		goto do_reset;
> -	}
>  
>  	/*
>  	 * After all reqs and tasks are cleared from doorbell,


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] scsi: ufs: Introduce ufshcd_abort_all()
  2022-10-31 18:34 [PATCH v2] scsi: ufs: Introduce ufshcd_abort_all() Bart Van Assche
  2022-10-31 18:51 ` Adrian Hunter
@ 2022-11-08  3:03 ` Martin K. Petersen
  2022-11-17 18:29 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2022-11-08  3:03 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Martin K . Petersen, Jaegeuk Kim, linux-scsi, Adrian Hunter,
	James E.J. Bottomley, Bean Huo, Avri Altman, Jinyoung Choi


Bart,

> Move the code for aborting all SCSI commands and TMFs into a new
> function.  This patch makes the ufshcd_err_handler() easier to
> read. Except for adding more logging, this patch does not change any
> functionality.

Applied to 6.2/scsi-staging, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] scsi: ufs: Introduce ufshcd_abort_all()
  2022-10-31 18:34 [PATCH v2] scsi: ufs: Introduce ufshcd_abort_all() Bart Van Assche
  2022-10-31 18:51 ` Adrian Hunter
  2022-11-08  3:03 ` Martin K. Petersen
@ 2022-11-17 18:29 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2022-11-17 18:29 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Martin K . Petersen, Bean Huo, Avri Altman, James E.J. Bottomley,
	Jaegeuk Kim, linux-scsi, Jinyoung Choi, Adrian Hunter

On Mon, 31 Oct 2022 11:34:21 -0700, Bart Van Assche wrote:

> Move the code for aborting all SCSI commands and TMFs into a new function.
> This patch makes the ufshcd_err_handler() easier to read. Except for adding
> more logging, this patch does not change any functionality.
> 
> 

Applied to 6.2/scsi-queue, thanks!

[1/1] scsi: ufs: Introduce ufshcd_abort_all()
      https://git.kernel.org/mkp/scsi/c/b817e6ffbad7

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-17 18:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-31 18:34 [PATCH v2] scsi: ufs: Introduce ufshcd_abort_all() Bart Van Assche
2022-10-31 18:51 ` Adrian Hunter
2022-11-08  3:03 ` Martin K. Petersen
2022-11-17 18:29 ` Martin K. Petersen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.