Simplify ufshcd_execute_start_stop()
Subsystems (2)
Bart Van Assche
reviewerv2 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 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(-)
Bart Van Assche
reviewerPATCH v2 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
@@ -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
@@ -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 */ +unsigned int scmd_flags;/* SCMD flags */ int *resid;/* residual length */ };
Re: [PATCH v2 1/3] scsi: core: Extend struct scsi_exec_args
Quoted 5 lines · Bart Van Assche
Allow SCSI LLDs to specify SCMD_* flags.
Cc Mike Christie <[email protected]>Cc John Garry <[email protected]>Signed-off-by Bart Van Assche <[email protected]>
Just a couple of nits, below:
Quoted 10 lines
--- drivers/scsi/scsi_lib.c | 1 + include/scsi/scsi_device.h | 1 + 2 files changed, 2 insertions(+)drivers/scsi/scsi_lib.c +0
-0
drivers/scsi/scsi_lib.c int scsi_execute_cmd(struct scsi_device *sdev, const unsigned char *cmd, · line 232
Quoted 4 lines
drivers/scsi/scsi_lib.c +1
-0@@ -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;
nit: we zero the scsi_cmnd payload in scsi_alloc_request() -> scsi_initialize_rq(), so don't really need the bitwise OR. However it may be better to keep for change of scsi_initialize_rq() changing in terms of init.
include/scsi/scsi_device.h struct scsi_exec_args { · line 465
Quoted 12 lines
drivers/scsi/scsi_lib.c +0
-0req->timeout = timeout; req->rq_flags |=RQF_QUIET ;include/scsi/scsi_device.h +1
-0@@ -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 */ +unsigned int scmd_flags;/* SCMD flags */
nit: scsi_cmnd.flags is an int, so prob should keep the same type
Quoted 3 lines
include/scsi/scsi_device.h +0
-0int *resid;/* residual length */ };
Bart Van Assche
reviewerRe: [PATCH v2 1/3] scsi: core: Extend struct scsi_exec_args
Quoted 13 lines · John Garry
drivers/scsi/scsi_lib.c int scsi_execute_cmd(struct scsi_device *sdev, · line 233
Quoted 10 lines · Bart Van Assche
drivers/scsi/scsi_lib.c +1
-0@@ -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;nit: we zero the
scsi_cmndpayload inscsi_alloc_request()->scsi_initialize_rq(), so don't really need the bitwise OR. However it may be better to keep for change ofscsi_initialize_rq()changing in terms of init.
Hi John,
Thanks for the review.
If scmd->flags would be initialized to a non-zero value in the future then it would be non-trivial to remember that the above assignment would have to be changed into a logical or. So I'd like to keep the logical or.
Quoted 5 lines
Quoted 5 lines
drivers/scsi/scsi_lib.c +0
-0req->timeout = timeout; req->rq_flags |= RQF_QUIET;include/scsi/scsi_device.h +0
-1--- a/include/scsi/scsi_device.h
Quoted 8 lines
Quoted 6 lines
+++
b/include/scsi/scsi_device.hinclude/scsi/scsi_device.h +0
-0@@ -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_treq_flags; /*BLK_MQ_REQflags */ + unsigned int scmd_flags; /* SCMD flags */nit: scsi_cmnd.flags is an int, so prob should keep the same type
How about changing the type of scsi_cmnd.flags from 'int' into 'unsigned int'? I can't think of any reason to make a flags variable signed instead of unsigned.
Thanks,
Bart.
Re: [PATCH v2 1/3] scsi: core: Extend struct scsi_exec_args
Quoted 1 line · Bart Van Assche
If
scmd->flagswould be initialized to a non-zero value in the future then it would be non-trivial to remember that the above assignment would have to be changed into a logical or. So I'd like to keep the logical or.
ok
Quoted 15 lines
Quoted 14 lines
Quoted 8 lines
req->timeout= timeout;
req->rq_flags|=RQF_QUIET;include/scsi/scsi_device.h +0
-0@@ -462,6 +462,7 @@ struct scsi_exec_args {Quoted 4 lines
unsigned int sense_len; /* sense buffer len */ struct
scsi_sense_hdr*sshdr; /* decoded sense header */blk_mq_req_flags_treq_flags; /*BLK_MQ_REQflags */ + unsigned int scmd_flags; /* SCMD flags */nit: scsi_cmnd.flags is an int, so prob should keep the same type
Quoted 1 line
How about changing the type of scsi_cmnd.flags from 'int' into 'unsigned int'? I can't think of any reason to make a flags variable signed instead of unsigned.
Yeah, it is odd to have a signed flags, but it's not the only one in scsi_cmnd. You suggest a reasonable change, however scsi core structures have many odd member types already.. so I'll leave it to you to decide on the proposed change.
Thanks,
John
Bart Van Assche
reviewerPATCH v2 2/3 scsi: ufs: Rely on the block layer for setting RQF_PM
In reply to Bart Van AsscheDo 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 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/ufs/core/ufshcd.c +2 -1
@@ -9141,7 +9141,8 @@ 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 ; +WARN_ON_ONCE (!(req->rq_flags &RQF_PM ));blk_execute_rq (req,/*at_head=*/ true);
Re: [PATCH v2 2/3] scsi: ufs: Rely on the block layer for setting RQF_PM
Quoted 11 lines · Bart Van Assche
Do not set
RQF_PMexplicitly sincescsi_alloc_request()sets it indirectly ifBLK_MQ_REQ_PMis set. The call chain for the code that setsRQF_PMis 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;
Quoted 3 lines
Cc Mike Christie <[email protected]>Cc John Garry <[email protected]>Signed-off-by Bart Van Assche <[email protected]>
To me, this looks ok. JFYI, this is where I understood that Christoph mentioned that we are required to set both flags:
However, to me, we currently set RQF_PM after alloc the req, so I don't see why just using BLK_MQ_REQ_PM in the scsi_alloc_request() call won't suffice (since it would lead to RQF_PM being set).
Anyway, feel free to add:
Quoted 18 lines
--- drivers/ufs/core/ufshcd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/ufs/core/ufshcd.c +2
-1@@ -9141,7 +9141,8 @@ 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 ; +WARN_ON_ONCE (!(req->rq_flags &RQF_PM ));blk_execute_rq (req,/*at_head=*/ true);
Bart Van Assche
reviewerPATCH v2 3/3 scsi: ufs: Simplify ufshcd_execute_start_stop()
In reply to Bart Van AsscheUse scsi_execute_cmd() instead of open-coding it.
--- drivers/ufs/core/ufshcd.c | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-)
drivers/ufs/core/ufshcd.c +8 -28
@@ -9125,35 +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 ; -WARN_ON_ONCE (!(req->rq_flags &RQF_PM )); - -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); }/**
Re: [PATCH v2 3/3] scsi: ufs: Simplify ufshcd_execute_start_stop()
Quoted 5 lines · Bart Van Assche
Use
scsi_execute_cmd()instead of open-coding it.Cc Mike Christie<[email protected]>Cc John Garry<[email protected]>Signed-off-by Bart Van Assche<[email protected]>
Looks ok, so feel free to add: