ufs: core: Optimize the UIC command implementation
Subsystems (2)
Bart Van Assche
reviewerv2 cover ufs: core: Optimize the UIC command implementation
Hi Martin,
This patch series reduces the number of readl() calls while processing UIC commands. Please consider this patch series for the next merge window.
Thanks,
Bart.
Changes compared to v1:
- Reduced the number of changes in patch 3/3.
Bart Van Assche (3):
ufs: core: Inline two functions related to UIC commands
ufs: core: Complain if UIC argument 2 is invalid
ufs: core: Optimize ufshcd_add_uic_command_trace()
drivers/ufs/core/ufshcd.c | 58 ++++++++++++--------------------------- 1 file changed, 17 insertions(+), 41 deletions(-)
Bart Van Assche
reviewerPATCH v2 1/3 ufs: core: Inline two functions related to UIC commands
The implementation of the two functions ufshcd_get_uic_cmd_result() and ufshcd_get_dme_attr_val() is very short. Additionally, both functions only have one caller. Inline both functions to make the code shorter.
--- drivers/ufs/core/ufshcd.c | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-)
drivers/ufs/core/ufshcd.c +8 -29
@@ -912,33 +912,6 @@ static inline int ufshcd_get_lists_status(u32 reg)return !((reg &UFSHCD_STATUS_READY ) ==UFSHCD_STATUS_READY ); } -/** -* ufshcd_get_uic_cmd_result - Get the UIC command result -* @hba: Pointer to adapter instance -* -* This function gets the result of UIC command completion -* -* Return: 0 on success; non-zero value on error. -*/ -static inline int ufshcd_get_uic_cmd_result (struct ufs_hba *hba) -{ -return ufshcd_readl (hba,REG_UIC_COMMAND_ARG_2 ) & -MASK_UIC_COMMAND_RESULT ; -} - -/** -* ufshcd_get_dme_attr_val - Get the value of attribute returned by UIC command -* @hba: Pointer to adapter instance -* -* This function gets UIC command argument3 -* -* Return: 0 on success; non-zero value on error. -*/ -static inline u32 ufshcd_get_dme_attr_val (struct ufs_hba *hba) -{ -return ufshcd_readl (hba,REG_UIC_COMMAND_ARG_3 ); -} -/** * ufshcd_get_req_rsp - returns the TR response transaction type * @ucd_rsp_ptr: pointer to response UPIU
@@ -5810,8 +5783,14 @@ static irqreturn_t ufshcd_uic_cmd_compl(struct ufs_hba *hba, u32 intr_status) hba->errors |= (UFSHCD_UIC_HIBERN8_MASK & intr_status);if (intr_status &UIC_COMMAND_COMPL ) { - cmd->argument2 |=ufshcd_get_uic_cmd_result (hba); - cmd->argument3 =ufshcd_get_dme_attr_val (hba); +/* +* Store the UIC command result in the lowest byte of +* cmd->argument2. +*/ + cmd->argument2 |=ufshcd_readl (hba,REG_UIC_COMMAND_ARG_2 ) & +MASK_UIC_COMMAND_RESULT ; +/* Store the DME attribute value in cmd->argument3. */ + cmd->argument3 =ufshcd_readl (hba,REG_UIC_COMMAND_ARG_3 );if (!hba->uic_async_done) cmd->cmd_active = false;complete (&cmd->done);
Bart Van Assche
reviewerPATCH v2 2/3 ufs: core: Complain if UIC argument 2 is invalid
In reply to Bart Van AsscheAccording to the UFSHCI standard, the lowest byte of UIC argument 2 is an output value. Additionally, ufshcd_uic_cmd_compl() is based on the assumption that the lowest byte of UIC argument 2 is zero. Hence, complain if the result byte is set when a UIC command is submitted.
--- drivers/ufs/core/ufshcd.c | 1 + 1 file changed, 1 insertion(+)
drivers/ufs/core/ufshcd.c +1 -0
@@ -2571,6 +2571,7 @@ ufshcd_dispatch_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd)lockdep_assert_held (&hba->uic_cmd_mutex);WARN_ON (hba->active_uic_cmd); +WARN_ON_ONCE (uic_cmd->argument2 &MASK_UIC_COMMAND_RESULT ); hba->active_uic_cmd = uic_cmd;
Bart Van Assche
reviewerPATCH v2 3/3 ufs: core: Optimize ufshcd_add_uic_command_trace()
In reply to Bart Van AsscheUse cached values in ufshcd_add_uic_command_trace() instead of calling readl() when tracing command submission (UFS_CMD_SEND).
--- drivers/ufs/core/ufshcd.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/ufs/core/ufshcd.c +11 -7
@@ -460,20 +460,24 @@ static void ufshcd_add_uic_command_trace(struct ufs_hba *hba,const struct uic_command *ucmd, enum ufs_trace_str_t str_t) { - u32 cmd; + u32 cmd, arg1, arg2, arg3;if (!trace_ufshcd_uic_command_enabled ())return ; -if (str_t ==UFS_CMD_SEND ) +if (str_t ==UFS_CMD_SEND ) { cmd = ucmd->command; -else + arg1 = ucmd->argument1; + arg2 = ucmd->argument2; + arg3 = ucmd->argument3; + }else { cmd =ufshcd_readl (hba,REG_UIC_COMMAND ); + arg1 =ufshcd_readl (hba,REG_UIC_COMMAND_ARG_1 ); + arg2 =ufshcd_readl (hba,REG_UIC_COMMAND_ARG_2 ); + arg3 =ufshcd_readl (hba,REG_UIC_COMMAND_ARG_3 ); + } -trace_ufshcd_uic_command (hba, str_t, cmd, -ufshcd_readl (hba,REG_UIC_COMMAND_ARG_1 ), -ufshcd_readl (hba,REG_UIC_COMMAND_ARG_2 ), -ufshcd_readl (hba,REG_UIC_COMMAND_ARG_3 )); +trace_ufshcd_uic_command (hba, str_t, cmd, arg1, arg2, arg3); } static void ufshcd_add_command_trace(struct ufs_hba *hba, struct scsi_cmnd *cmd,
Re: [PATCH v2 3/3] ufs: core: Optimize ufshcd_add_uic_command_trace()
Quoted 5 lines · Bart Van Assche
Use cached values in
ufshcd_add_uic_command_trace()instead of callingreadl()when tracing command submission (UFS_CMD_SEND).Signed-off-by Bart Van Assche <[email protected]>
Martin K. Petersen
AppliedBart,
Quoted 3 lines
This patch series reduces the number of
readl()calls while processing UIC commands. Please consider this patch series for the next merge window.
Applied to 7.2/scsi-staging, thanks!
Signature · 1 line
Martin K. Petersen
Martin K. Petersen
AppliedQuoted 8 lines · Bart Van Assche
This patch series reduces the number of
readl()calls while processing UIC commands. Please consider this patch series for the next merge window.Thanks,
Bart.
[...]
Applied to 7.2/scsi-queue, thanks!
[1/3] ufs: core: Inline two functions related to UIC commands
https://git.kernel.org/mkp/scsi/c/727e78887e62 [2/3] ufs: core: Complain if UIC argument 2 is invalid https://git.kernel.org/mkp/scsi/c/9fb4c793223b [3/3] ufs: core: Optimize ufshcd_add_uic_command_trace() https://git.kernel.org/mkp/scsi/c/f8380c57dcff
Signature · 1 line
Martin K. Petersen