diff mbox series

[v2,2/4] scsi: ufs: Re-use exec_dev_cmd

Message ID 20240305210051.10847-3-avri.altman@wdc.com (mailing list archive)
State Superseded
Headers show
Series Re-use device management code fragments | expand

Commit Message

Avri Altman March 5, 2024, 9 p.m. UTC
Move out the actual command issue from exec_dev_cmd so it can be used
elsewhere.  While at it, remove a redundant "lrbp->cmd = NULL"
assignment.  Also, as a free bonus, call the upiu trace if it doesn't.

Signed-off-by: Avri Altman <avri.altman@wdc.com>
---
 drivers/ufs/core/ufshcd.c | 53 ++++++++++++++++++---------------------
 1 file changed, 24 insertions(+), 29 deletions(-)

Comments

Bean Huo March 6, 2024, 10:05 p.m. UTC | #1
On Tue, 2024-03-05 at 23:00 +0200, Avri Altman wrote:
> Move out the actual command issue from exec_dev_cmd so it can be used
> elsewhere.  While at it, remove a redundant "lrbp->cmd = NULL"
> assignment.  Also, as a free bonus, call the upiu trace if it
> doesn't.


This statement is a bit strange, what it is "if it doesn't"?

from the change, the patch refactors command issue for broader usage
and enhance UPIU tracing, isolate the command issuance logic from
`ufshcd_exec_dev_cmd` to allow reuse across different contexts.
Avri Altman March 7, 2024, 7:28 p.m. UTC | #2
> 
> On Tue, 2024-03-05 at 23:00 +0200, Avri Altman wrote:
> > Move out the actual command issue from exec_dev_cmd so it can be used
> > elsewhere.  While at it, remove a redundant "lrbp->cmd = NULL"
> > assignment.  Also, as a free bonus, call the upiu trace if it doesn't.
> 
> 
> This statement is a bit strange, what it is "if it doesn't"?
> 
> from the change, the patch refactors command issue for broader usage
> and enhance UPIU tracing, isolate the command issuance logic from
> `ufshcd_exec_dev_cmd` to allow reuse across different contexts.
What I meant is, that I see no downside for including the bsg path in the upiu trace event.
Do you object to that?

Thanks,
Avri
Bean Huo March 8, 2024, 7:29 p.m. UTC | #3
On Thu, 2024-03-07 at 19:28 +0000, Avri Altman wrote:
> > On Tue, 2024-03-05 at 23:00 +0200, Avri Altman wrote:
> > > Move out the actual command issue from exec_dev_cmd so it can be
> > > used
> > > elsewhere.  While at it, remove a redundant "lrbp->cmd = NULL"
> > > assignment.  Also, as a free bonus, call the upiu trace if it
> > > doesn't.
> > 
> > 
> > This statement is a bit strange, what it is "if it doesn't"?
> > 
> > from the change, the patch refactors command issue for broader
> > usage
> > and enhance UPIU tracing, isolate the command issuance logic from
> > `ufshcd_exec_dev_cmd` to allow reuse across different contexts.
> What I meant is, that I see no downside for including the bsg path in
> the upiu trace event.
> Do you object to that?

Avri, 

no, I meant your commit message is not clearer. and then understood
after reading your patch.

Kind regards,
Bean
Avri Altman March 8, 2024, 7:42 p.m. UTC | #4
> On Thu, 2024-03-07 at 19:28 +0000, Avri Altman wrote:
> > > On Tue, 2024-03-05 at 23:00 +0200, Avri Altman wrote:
> > > > Move out the actual command issue from exec_dev_cmd so it can be
> > > > used elsewhere.  While at it, remove a redundant "lrbp->cmd =
> > > > NULL"
> > > > assignment.  Also, as a free bonus, call the upiu trace if it
> > > > doesn't.
> > >
> > >
> > > This statement is a bit strange, what it is "if it doesn't"?
> > >
> > > from the change, the patch refactors command issue for broader usage
> > > and enhance UPIU tracing, isolate the command issuance logic from
> > > `ufshcd_exec_dev_cmd` to allow reuse across different contexts.
> > What I meant is, that I see no downside for including the bsg path in
> > the upiu trace event.
> > Do you object to that?
> 
> Avri,
> 
> no, I meant your commit message is not clearer. and then understood after
> reading your patch.
Will reword the commit log.

Thanks,
Avri

> 
> Kind regards,
> Bean
diff mbox series

Patch

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 983b7b8e3c7c..3f62ad7b4062 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -3286,6 +3286,25 @@  static void ufshcd_dev_man_unlock(struct ufs_hba *hba)
 	ufshcd_release(hba);
 }
 
+static int ufshcd_issue_dev_cmd(struct ufs_hba *hba, struct ufshcd_lrb *lrbp,
+			  const u32 tag, int timeout)
+{
+	DECLARE_COMPLETION_ONSTACK(wait);
+	int err;
+
+	hba->dev_cmd.complete = &wait;
+
+	ufshcd_add_query_upiu_trace(hba, UFS_QUERY_SEND, lrbp->ucd_req_ptr);
+
+	ufshcd_send_command(hba, tag, hba->dev_cmd_queue);
+	err = ufshcd_wait_for_dev_cmd(hba, lrbp, timeout);
+
+	ufshcd_add_query_upiu_trace(hba, err ? UFS_QUERY_ERR : UFS_QUERY_COMP,
+				    (struct utp_upiu_req *)lrbp->ucd_rsp_ptr);
+
+	return err;
+}
+
 /**
  * ufshcd_exec_dev_cmd - API for sending device management requests
  * @hba: UFS hba
@@ -3300,31 +3319,18 @@  static void ufshcd_dev_man_unlock(struct ufs_hba *hba)
 static int ufshcd_exec_dev_cmd(struct ufs_hba *hba,
 		enum dev_cmd_type cmd_type, int timeout)
 {
-	DECLARE_COMPLETION_ONSTACK(wait);
 	const u32 tag = hba->reserved_slot;
-	struct ufshcd_lrb *lrbp;
+	struct ufshcd_lrb *lrbp = &hba->lrb[tag];
 	int err;
 
 	/* Protects use of hba->reserved_slot. */
 	lockdep_assert_held(&hba->dev_cmd.lock);
 
-	lrbp = &hba->lrb[tag];
-	lrbp->cmd = NULL;
 	err = ufshcd_compose_dev_cmd(hba, lrbp, cmd_type, tag);
 	if (unlikely(err))
-		goto out;
-
-	hba->dev_cmd.complete = &wait;
-
-	ufshcd_add_query_upiu_trace(hba, UFS_QUERY_SEND, lrbp->ucd_req_ptr);
-
-	ufshcd_send_command(hba, tag, hba->dev_cmd_queue);
-	err = ufshcd_wait_for_dev_cmd(hba, lrbp, timeout);
-	ufshcd_add_query_upiu_trace(hba, err ? UFS_QUERY_ERR : UFS_QUERY_COMP,
-				    (struct utp_upiu_req *)lrbp->ucd_rsp_ptr);
+		return err;
 
-out:
-	return err;
+	return ufshcd_issue_dev_cmd(hba, lrbp, tag, timeout);
 }
 
 /**
@@ -7206,7 +7212,6 @@  static int ufshcd_issue_devman_upiu_cmd(struct ufs_hba *hba,
 					enum dev_cmd_type cmd_type,
 					enum query_opcode desc_op)
 {
-	DECLARE_COMPLETION_ONSTACK(wait);
 	const u32 tag = hba->reserved_slot;
 	struct ufshcd_lrb *lrbp;
 	int err = 0;
@@ -7246,17 +7251,12 @@  static int ufshcd_issue_devman_upiu_cmd(struct ufs_hba *hba,
 
 	memset(lrbp->ucd_rsp_ptr, 0, sizeof(struct utp_upiu_rsp));
 
-	hba->dev_cmd.complete = &wait;
-
-	ufshcd_add_query_upiu_trace(hba, UFS_QUERY_SEND, lrbp->ucd_req_ptr);
-
-	ufshcd_send_command(hba, tag, hba->dev_cmd_queue);
 	/*
 	 * ignore the returning value here - ufshcd_check_query_response is
 	 * bound to fail since dev_cmd.query and dev_cmd.type were left empty.
 	 * read the response directly ignoring all errors.
 	 */
-	ufshcd_wait_for_dev_cmd(hba, lrbp, QUERY_REQ_TIMEOUT);
+	ufshcd_issue_dev_cmd(hba, lrbp, tag, QUERY_REQ_TIMEOUT);
 
 	/* just copy the upiu response as it is */
 	memcpy(rsp_upiu, lrbp->ucd_rsp_ptr, sizeof(*rsp_upiu));
@@ -7371,7 +7371,6 @@  int ufshcd_advanced_rpmb_req_handler(struct ufs_hba *hba, struct utp_upiu_req *r
 			 struct ufs_ehs *rsp_ehs, int sg_cnt, struct scatterlist *sg_list,
 			 enum dma_data_direction dir)
 {
-	DECLARE_COMPLETION_ONSTACK(wait);
 	const u32 tag = hba->reserved_slot;
 	struct ufshcd_lrb *lrbp;
 	int err = 0;
@@ -7418,11 +7417,7 @@  int ufshcd_advanced_rpmb_req_handler(struct ufs_hba *hba, struct utp_upiu_req *r
 
 	memset(lrbp->ucd_rsp_ptr, 0, sizeof(struct utp_upiu_rsp));
 
-	hba->dev_cmd.complete = &wait;
-
-	ufshcd_send_command(hba, tag, hba->dev_cmd_queue);
-
-	err = ufshcd_wait_for_dev_cmd(hba, lrbp, ADVANCED_RPMB_REQ_TIMEOUT);
+	err = ufshcd_issue_dev_cmd(hba, lrbp, tag, ADVANCED_RPMB_REQ_TIMEOUT);
 
 	if (!err) {
 		/* Just copy the upiu response as it is */