Skip to contentSkip to conversation

Simplify ufshcd_execute_start_stop()

PATCH Applied Bart Van Assche 3 participants 6 messages Feb 10, 2023 – Feb 22, 2023

Subsystems (2)
lore
Share & tools
lore

Bart Van Assche

author reviewer
#0 lore raw

v3 cover Simplify ufshcd_execute_start_stop()

Hi Martin,

This patch series simplifies ufshcd_execute_start_stop() by using the new scsi_execute_cmd() function instead of open-coding it. Please consider this patch for the next merge window.

Thanks,

Bart.

Changes compared to v2:
- Changed the type of scsi_exec_args.scmd_flags from unsigned int into int.
- Left out a WARN_ON_ONCE() statement from patch 2/3 that was removed by patch 3/3 anyway.

Changes compared to v1:
- Addressed John's feedback that RQF_PM should always be set if BLK_MQ_REQ_PM is set.
- Added a third patch that makes RQF_PM to be set implicitly.

Bart Van Assche (3):
scsi: core: Extend struct scsi_exec_args
scsi: ufs: Rely on the block layer for setting RQF_PM
scsi: ufs: Simplify ufshcd_execute_start_stop()

 drivers/scsi/scsi_lib.c    |  1 +
 drivers/ufs/core/ufshcd.c  | 35 ++++++++---------------------------
 include/scsi/scsi_device.h |  1 +
 3 files changed, 10 insertions(+), 27 deletions(-)
author reviewer
#1 lore raw

PATCH v3 1/3 scsi: core: Extend struct scsi_exec_args

Allow SCSI LLDs to specify SCMD_* flags.

---
 drivers/scsi/scsi_lib.c    | 1 +
 include/scsi/scsi_device.h | 1 +
 2 files changed, 2 insertions(+)
drivers/scsi/scsi_lib.c +1 -0
index abe93ec8b7d0..b7c569a42aa4 100644
@@ -229,6 +229,7 @@ int scsi_execute_cmd(struct scsi_device *sdev, const unsigned char *cmd,
 	scmd->cmd_len = COMMAND_SIZE(cmd[0]);
 	memcpy(scmd->cmnd, cmd, scmd->cmd_len);
 	scmd->allowed = retries;
+	scmd->flags |= args->scmd_flags;
 	req->timeout = timeout;
 	req->rq_flags |= RQF_QUIET;
 
include/scsi/scsi_device.h +1 -0
index 7e95ec45138f..de310f21406c 100644
@@ -462,6 +462,7 @@ struct scsi_exec_args {
 	unsigned int sense_len;		/* sense buffer len */
 	struct scsi_sense_hdr *sshdr;	/* decoded sense header */
 	blk_mq_req_flags_t req_flags;	/* BLK_MQ_REQ flags */
+	int scmd_flags;			/* SCMD flags */
 	int *resid;			/* residual length */
 };
 
author reviewer
#2 lore raw

PATCH v3 2/3 scsi: ufs: Rely on the block layer for setting RQF_PM

In reply to Bart Van Assche

Do not set RQF_PM explicitly since scsi_alloc_request() sets it indirectly if BLK_MQ_REQ_PM is set. The call chain for the code that sets RQF_PM is as follows:

    scsi_alloc_request()
      blk_mq_alloc_request()
        __blk_mq_alloc_requests()
          blk_mq_rq_ctx_init()
            if (data->flags & BLK_MQ_REQ_PM)
              data->rq_flags |= RQF_PM;
---
 drivers/ufs/core/ufshcd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ufs/core/ufshcd.c +1 -1
index 0cfe112ff8c3..293933806ffa 100644
@@ -9141,7 +9141,7 @@ static int ufshcd_execute_start_stop(struct scsi_device *sdev,
 	scmd->allowed = 0/*retries*/;
 	scmd->flags |= SCMD_FAIL_IF_RECOVERING;
 	req->timeout = 1 * HZ;
-	req->rq_flags |= RQF_PM | RQF_QUIET;
+	req->rq_flags |= RQF_QUIET;
 
 	blk_execute_rq(req, /*at_head=*/true);
 
author reviewer
#3 lore raw

PATCH v3 3/3 scsi: ufs: Simplify ufshcd_execute_start_stop()

In reply to Bart Van Assche

Use scsi_execute_cmd() instead of open-coding it.

---
 drivers/ufs/core/ufshcd.c | 35 ++++++++---------------------------
 1 file changed, 8 insertions(+), 27 deletions(-)
drivers/ufs/core/ufshcd.c +8 -27
index 293933806ffa..cb59f6b55cfd 100644
@@ -9125,34 +9125,15 @@ static int ufshcd_execute_start_stop(struct scsi_device *sdev,
 				     enum ufs_dev_pwr_mode pwr_mode,
 				     struct scsi_sense_hdr *sshdr)
 {
-	unsigned char cdb[6] = { START_STOP, 0, 0, 0, pwr_mode << 4, 0 };
-	struct request *req;
-	struct scsi_cmnd *scmd;
-	int ret;
-
-	req = scsi_alloc_request(sdev->request_queue, REQ_OP_DRV_IN,
-				 BLK_MQ_REQ_PM);
-	if (IS_ERR(req))
-		return PTR_ERR(req);
-
-	scmd = blk_mq_rq_to_pdu(req);
-	scmd->cmd_len = COMMAND_SIZE(cdb[0]);
-	memcpy(scmd->cmnd, cdb, scmd->cmd_len);
-	scmd->allowed = 0/*retries*/;
-	scmd->flags |= SCMD_FAIL_IF_RECOVERING;
-	req->timeout = 1 * HZ;
-	req->rq_flags |= RQF_QUIET;
-
-	blk_execute_rq(req, /*at_head=*/true);
-
-	if (sshdr)
-		scsi_normalize_sense(scmd->sense_buffer, scmd->sense_len,
-				     sshdr);
-	ret = scmd->result;
-
-	blk_mq_free_request(req);
+	const unsigned char cdb[6] = { START_STOP, 0, 0, 0, pwr_mode << 4, 0 };
+	const struct scsi_exec_args args = {
+		.sshdr = sshdr,
+		.req_flags = BLK_MQ_REQ_PM,
+		.scmd_flags = SCMD_FAIL_IF_RECOVERING,
+	};
 
-	return ret;
+	return scsi_execute_cmd(sdev, cdb, REQ_OP_DRV_IN, /*buffer=*/NULL,
+			/*bufflen=*/0, /*timeout=*/HZ, /*retries=*/0, &args);
 }
 
 /**
Reviewed-by on v3 3/3
#4 lore raw

Re: [PATCH v3 3/3] scsi: ufs: Simplify ufshcd_execute_start_stop()

Quoted 4 lines · Bart Van Assche

Use scsi_execute_cmd() instead of open-coding it.

Cc Mike Christie <[email protected]>
Cc John Garry <[email protected]>
Quoted 53 lines

---
drivers/ufs/core/ufshcd.c | 35 ++++++++---------------------------

1 file changed, 8 insertions(+), 27 deletions(-)
drivers/ufs/core/ufshcd.c +8 -27
index 293933806ffa..cb59f6b55cfd 100644
@@ -9125,34 +9125,15 @@ static int ufshcd_execute_start_stop(struct scsi_device *sdev,
 				     enum ufs_dev_pwr_mode pwr_mode,
 				     struct scsi_sense_hdr *sshdr)
 {
-	unsigned char cdb[6] = { START_STOP, 0, 0, 0, pwr_mode << 4, 0 };
-	struct request *req;
-	struct scsi_cmnd *scmd;
-	int ret;
-
-	req = scsi_alloc_request(sdev->request_queue, REQ_OP_DRV_IN,
-				 BLK_MQ_REQ_PM);
-	if (IS_ERR(req))
-		return PTR_ERR(req);
-
-	scmd = blk_mq_rq_to_pdu(req);
-	scmd->cmd_len = COMMAND_SIZE(cdb[0]);
-	memcpy(scmd->cmnd, cdb, scmd->cmd_len);
-	scmd->allowed = 0/*retries*/;
-	scmd->flags |= SCMD_FAIL_IF_RECOVERING;
-	req->timeout = 1 * HZ;
-	req->rq_flags |= RQF_QUIET;
-
-	blk_execute_rq(req, /*at_head=*/true);
-
-	if (sshdr)
-		scsi_normalize_sense(scmd->sense_buffer, scmd->sense_len,
-				     sshdr);
-	ret = scmd->result;
-
-	blk_mq_free_request(req);
+	const unsigned char cdb[6] = { START_STOP, 0, 0, 0, pwr_mode << 4, 0 };
+	const struct scsi_exec_args args = {
+		.sshdr = sshdr,
+		.req_flags = BLK_MQ_REQ_PM,
+		.scmd_flags = SCMD_FAIL_IF_RECOVERING,
+	};
 
-	return ret;
+	return scsi_execute_cmd(sdev, cdb, REQ_OP_DRV_IN, /*buffer=*/NULL,
+			/*bufflen=*/0, /*timeout=*/HZ, /*retries=*/0, &args);
 }
 
 /**
#5 lore raw
In reply to Bart Van Assche

Bart,

Quoted 3 lines

This patch series simplifies ufshcd_execute_start_stop() by using the new scsi_execute_cmd() function instead of open-coding it. Please consider this patch for the next merge window.

Applied to 6.3/scsi-staging, thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering