UFS Multi-Circular Queue (MCQ)
Subsystems (4)
v3 cover UFS Multi-Circular Queue (MCQ)
UFS Multi-Circular Queue (MCQ) has been added in UFSHCI v4.0 to improve storage performance. This patch series is a RFC implementation of this.
This is the initial driver implementation and it has been verified by booting on an emulation platform. During testing, all low power modes were disabled and it was in HS-G1 mode.
Please take a look and let us know your thoughts.
v2 -> v3:
- Split the changes based on functionality
- Addressed queue configuration issues
- Faster SQE tail pointer increments
- Addressed comments from Bart and Manivannan
v1 -> v2:
- Enabled host_tagset
- Added queue num configuration support
- Added one more vops to allow vendor provide the wanted MAC
- Determine nutrs and can_queue by considering both MAC, bqueuedepth and EXT_IID support
- Postponed MCQ initialization and scsi_add_host() to async probe
- Used (EXT_IID, Task Tag) tuple to support up to 4096 tasks (theoretically)
Asutosh Das (2):
ufs: core: prepare ufs for multi circular queue support
ufs: core: mcq: Adds Multi-Circular Queue support
Can Guo (2):
ufs: core: Add Event Specific Interrupt configuration vendor specific
ops
ufs: host: qcom: Add MCQ support
drivers/ufs/core/Makefile | 2 +- drivers/ufs/core/ufs-mcq.c | 474 +++++++++++++++++++++++++++++++++++++++++ drivers/ufs/core/ufshcd-priv.h | 102 +++++++++ drivers/ufs/core/ufshcd.c | 370 +++++++++++++++++++++++++------- drivers/ufs/host/ufs-qcom.c | 134 ++++++++++++ drivers/ufs/host/ufs-qcom.h | 13 ++ include/ufs/ufs.h | 6 + include/ufs/ufshcd.h | 137 ++++++++++++ include/ufs/ufshci.h | 79 +++++++ 9 files changed, 1238 insertions(+), 79 deletions(-) create mode 100644 drivers/ufs/core/ufs-mcq.c
Signature · 1 line
2.7.4
RFC PATCH v3 1/4 ufs: core: prepare ufs for multi circular queue support
Preparatory changes for upcoming multi circular queue.
--- drivers/ufs/core/ufshcd.c | 99 +++++++++++++++++++++++++---------------------- 1 file changed, 53 insertions(+), 46 deletions(-)
drivers/ufs/core/ufshcd.c +53 -46
@@ -249,7 +249,7 @@ static int ufshcd_reset_and_restore(struct ufs_hba *hba);static int ufshcd_eh_host_reset_handler (struct scsi_cmnd *cmd);static int ufshcd_clear_tm_cmd (struct ufs_hba *hba,int tag);static void ufshcd_hba_exit (struct ufs_hba *hba); -static int ufshcd_probe_hba (struct ufs_hba *hba,bool init_dev_params); +static int ufshcd_probe_hba (struct ufs_hba *hba,bool initial_boot);static int ufshcd_setup_clocks (struct ufs_hba *hba,bool on);static inline void ufshcd_add_delay_before_dme_cmd (struct ufs_hba *hba);static int ufshcd_host_reset_and_restore (struct ufs_hba *hba);
@@ -310,10 +310,11 @@ static void ufshcd_scsi_block_requests(struct ufs_hba *hba)scsi_block_requests (hba->host); } -static void ufshcd_add_cmd_upiu_trace (struct ufs_hba *hba,unsigned int tag, +static void ufshcd_add_cmd_upiu_trace (struct ufs_hba *hba, +struct ufshcd_lrb *lrbp,enum ufs_trace_str_t str_t) { -struct utp_upiu_req *rq = hba->lrb[tag].ucd_req_ptr; +struct utp_upiu_req *rq = lrbp->ucd_req_ptr;struct utp_upiu_header *header;if (!trace_ufshcd_upiu_enabled ())
@@ -322,7 +323,7 @@ static void ufshcd_add_cmd_upiu_trace(struct ufs_hba *hba, unsigned int tag,if (str_t ==UFS_CMD_SEND ) header = &rq->header;else - header = &hba->lrb[tag].ucd_rsp_ptr->header; + header = &lrbp->ucd_rsp_ptr->header;trace_ufshcd_upiu (dev_name (hba->dev), str_t, header, &rq->sc.cdb,UFS_TSF_CDB );
@@ -379,13 +380,13 @@ static void ufshcd_add_uic_command_trace(struct ufs_hba *hba, ufshcd_readl(hba, REG_UIC_COMMAND_ARG_3)); } -static void ufshcd_add_command_trace (struct ufs_hba *hba,unsigned int tag, +static void ufshcd_add_command_trace (struct ufs_hba *hba, +struct ufshcd_lrb *lrbp,enum ufs_trace_str_t str_t) {u64 lba =0 ;u8 opcode =0 , group_id =0 ;u32 intr, doorbell; -struct ufshcd_lrb *lrbp = &hba->lrb[tag];struct scsi_cmnd *cmd = lrbp->cmd;struct request *rq =scsi_cmd_to_rq (cmd);int transfer_len =-1 ;
@@ -394,7 +395,7 @@ static void ufshcd_add_command_trace(struct ufs_hba *hba, unsigned int tag,return ;/* trace UPIU also */ -ufshcd_add_cmd_upiu_trace (hba, tag, str_t); +ufshcd_add_cmd_upiu_trace (hba, lrbp, str_t);if (!trace_ufshcd_command_enabled ())return ;
@@ -419,7 +420,7 @@ static void ufshcd_add_command_trace(struct ufs_hba *hba, unsigned int tag, intr =ufshcd_readl (hba,REG_INTERRUPT_STATUS ); doorbell =ufshcd_readl (hba,REG_UTP_TRANSFER_REQ_DOOR_BELL ); -trace_ufshcd_command (dev_name (hba->dev), str_t, tag, +trace_ufshcd_command (dev_name (hba->dev), str_t, lrbp->task_tag, doorbell, transfer_len, intr, lba, opcode, group_id); }
@@ -2134,14 +2135,14 @@ static void ufshcd_update_monitor(struct ufs_hba *hba, const struct ufshcd_lrb ** @task_tag: Task tag of the command */ static inline -void ufshcd_send_command (struct ufs_hba *hba,unsigned int task_tag) +void ufshcd_send_command (struct ufs_hba *hba,struct ufshcd_lrb *lrbp) { -struct ufshcd_lrb *lrbp = &hba->lrb[task_tag]; +int task_tag = lrbp->task_tag;unsigned long flags; lrbp->issue_time_stamp =ktime_get (); lrbp->compl_time_stamp =ktime_set (0 ,0 ); -ufshcd_add_command_trace (hba, task_tag,UFS_CMD_SEND ); +ufshcd_add_command_trace (hba, lrbp,UFS_CMD_SEND );ufshcd_clk_scaling_start_busy (hba);if (unlikely (ufshcd_should_inform_monitor (hba, lrbp)))ufshcd_start_monitor (hba, lrbp);
@@ -2553,9 +2554,10 @@ void ufshcd_prepare_utp_scsi_cmd_upiu(struct ufshcd_lrb *lrbp, u8 upiu_flags)/* command descriptor fields */ ucd_req_ptr->header.dword_0 =UPIU_HEADER_DWORD (UPIU_TRANSACTION_COMMAND , upiu_flags, - lrbp->lun, lrbp->task_tag); + lrbp->lun, lrbp->task_tag &0xff ); ucd_req_ptr->header.dword_1 =UPIU_HEADER_DWORD ( -UPIU_COMMAND_SET_TYPE_SCSI ,0 ,0 ,0 ); +UPIU_COMMAND_SET_TYPE_SCSI ,0 ,0 , + (lrbp->task_tag &0xf00 ) <<4 );/* Total EHS length and Data segment length will be zero */ ucd_req_ptr->header.dword_2 =0 ;
@@ -2845,7 +2847,7 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) goto out; } -ufshcd_send_command (hba, tag); +ufshcd_send_command (hba, lrbp); out:rcu_read_unlock ();
@@ -2971,7 +2973,7 @@ static int ufshcd_wait_for_dev_cmd(struct ufs_hba *hba,if (!time_left) { err = -ETIMEDOUT ; -dev_dbg (hba->dev,"%s: dev_cmd request timedout, tag %d\n" , +dev_err (hba->dev,"%s: dev_cmd request timedout, tag %d\n" , __func__, lrbp->task_tag);if (!ufshcd_clear_cmds (hba,1U << lrbp->task_tag))/* successfully cleared the command, retry if needed */
@@ -3021,7 +3023,7 @@ static int ufshcd_exec_dev_cmd(struct ufs_hba *hba,ufshcd_add_query_upiu_trace (hba,UFS_QUERY_SEND , lrbp->ucd_req_ptr); -ufshcd_send_command (hba, tag); +ufshcd_send_command (hba, lrbp); 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);
@@ -4513,6 +4515,7 @@ int ufshcd_make_hba_operational(struct ufs_hba *hba) REG_UTP_TRANSFER_REQ_LIST_BASE_L);ufshcd_writel (hba,upper_32_bits (hba->utrdl_dma_addr),REG_UTP_TRANSFER_REQ_LIST_BASE_H ); +ufshcd_writel (hba,lower_32_bits (hba->utmrdl_dma_addr),REG_UTP_TASK_REQ_LIST_BASE_L ); ufshcd_writel(hba, upper_32_bits(hba->utmrdl_dma_addr),
@@ -5320,6 +5323,32 @@ static void ufshcd_release_scsi_cmd(struct ufs_hba *hba,ufshcd_clk_scaling_update_busy (hba); } +void ufshcd_compl_one_cqe (struct ufs_hba *hba,int task_tag) +{ +struct ufshcd_lrb *lrbp; +struct scsi_cmnd *cmd; + + lrbp = &hba->lrb[task_tag]; + lrbp->compl_time_stamp =ktime_get (); + cmd = lrbp->cmd; +if (cmd) { +if (unlikely (ufshcd_should_inform_monitor (hba, lrbp))) +ufshcd_update_monitor (hba, lrbp); +ufshcd_add_command_trace (hba, lrbp,UFS_CMD_COMP ); + cmd->result =ufshcd_transfer_rsp_status (hba, lrbp); +ufshcd_release_scsi_cmd (hba, lrbp); +/* Do not touch lrbp after scsi done */ +scsi_done (cmd); + }else if (lrbp->command_type ==UTP_CMD_TYPE_DEV_MANAGE || + lrbp->command_type ==UTP_CMD_TYPE_UFS_STORAGE ) { +if (hba->dev_cmd.complete) { +ufshcd_add_command_trace (hba, lrbp,UFS_DEV_COMP ); +complete (hba->dev_cmd.complete); +ufshcd_clk_scaling_update_busy (hba); + } + } +} +/** * __ufshcd_transfer_req_compl - handle SCSI and query command completion * @hba: per adapter instance
@@ -5328,32 +5357,10 @@ static void ufshcd_release_scsi_cmd(struct ufs_hba *hba,static void __ufshcd_transfer_req_compl (struct ufs_hba *hba,unsigned long completed_reqs) { -struct ufshcd_lrb *lrbp; -struct scsi_cmnd *cmd; -int index; - -for_each_set_bit (index, &completed_reqs, hba->nutrs) { - lrbp = &hba->lrb[index]; - lrbp->compl_time_stamp =ktime_get (); - cmd = lrbp->cmd; -if (cmd) { -if (unlikely (ufshcd_should_inform_monitor (hba, lrbp))) -ufshcd_update_monitor (hba, lrbp); -ufshcd_add_command_trace (hba, index,UFS_CMD_COMP ); - cmd->result =ufshcd_transfer_rsp_status (hba, lrbp); -ufshcd_release_scsi_cmd (hba, lrbp); -/* Do not touch lrbp after scsi done */ -scsi_done (cmd); - }else if (lrbp->command_type ==UTP_CMD_TYPE_DEV_MANAGE || - lrbp->command_type ==UTP_CMD_TYPE_UFS_STORAGE ) { -if (hba->dev_cmd.complete) { -ufshcd_add_command_trace (hba, index, -UFS_DEV_COMP ); -complete (hba->dev_cmd.complete); -ufshcd_clk_scaling_update_busy (hba); - } - } - } +int tag; + +for_each_set_bit (tag, &completed_reqs, hba->nutrs) +ufshcd_compl_one_cqe (hba, tag); }/*
@@ -6869,7 +6876,7 @@ static int ufshcd_issue_devman_upiu_cmd(struct ufs_hba *hba,ufshcd_add_query_upiu_trace (hba,UFS_QUERY_SEND , lrbp->ucd_req_ptr); -ufshcd_send_command (hba, tag); +ufshcd_send_command (hba, lrbp);/* * ignore the returning value here - ufshcd_check_query_response is * bound to fail since dev_cmd.query and dev_cmd.type were left empty.
@@ -8138,11 +8145,11 @@ static int ufshcd_add_lus(struct ufs_hba *hba)/** * ufshcd_probe_hba - probe hba to detect device and initialize it * @hba: per-adapter instance -* @init_dev_params: whether or not to call ufshcd_device_params_init(). +* @initial_boot: Whether or not from initial bootup * * Execute link-startup and verify device initialization */ -static int ufshcd_probe_hba (struct ufs_hba *hba,bool init_dev_params) +static int ufshcd_probe_hba (struct ufs_hba *hba,bool initial_boot) {int ret;unsigned long flags;
@@ -8177,7 +8184,7 @@ static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params)* Initialize UFS device parameters used by driver, these * parameters are associated with UFS descriptors. */ -if (init_dev_params) { +if (initial_boot) { ret =ufshcd_device_params_init (hba);if (ret) goto out;
Signature · 1 line
2.7.4
Re: [RFC PATCH v3 1/4] ufs: core: prepare ufs for multi circular queue support
Asutosh,
Quoted 13 lines · Asutosh Das
Preparatory changes for upcoming multi circular queue.
Co-developed-by Can Guo <[email protected]>Signed-off-by Can Guo <[email protected]>Signed-off-by Asutosh Das <[email protected]>---
drivers/ufs/core/ufshcd.c | 99 +++++++++++++++++++++++++------------
----------1 file changed, 53 insertions(+), 46 deletions(-)(quoted diff) +0
-0@@ -2134,14 +2135,14 @@ static void ufshcd_update_monitor(struct
Quoted 3 lines
ufs_hba*hba, const structufshcd_lrb*
* @task_tag: Task tag of the command
*/
You didn't change parameter name in the function description.
Quoted 20 lines
static inline
(quoted diff) +1
-1-void ufshcd_send_command(struct ufs_hba *hba, unsigned int task_tag) +void ufshcd_send_command(struct ufs_hba *hba, struct ufshcd_lrb*lrbp)
{
- structufshcd_lrb*lrbp = &hba->lrb[task_tag]; + inttask_tag=lrbp->task_tag;
unsigned long flags;
lrbp->issue_time_stamp =ktime_get();lrbp->compl_time_stamp=ktime_set(0, 0);
- ufshcd_add_command_trace(hba,task_tag,UFS_CMD_SEND); + ufshcd_add_command_trace(hba, lrbp,UFS_CMD_SEND);ufshcd_clk_scaling_start_busy(hba);
if (unlikely(ufshcd_should_inform_monitor(hba, lrbp)))ufshcd_start_monitor(hba, lrbp);(quoted diff) +0
-0@@ -2553,9 +2554,10 @@ void ufshcd_prepare_utp_scsi_cmd_upiu(struct ufshcd_lrb *lrbp, u8 upiu_flags) /* command descriptor fields */ucd_req_ptr->header.dword_0 = UPIU_HEADER_DWORD(
Quoted 8 lines
UPIU_TRANSACTION_COMMAND,
upiu_flags, - lrbp->lun,lrbp->task_tag); + lrbp->lun,lrbp->task_tag&0xff);ucd_req_ptr->header.dword_1= UPIU_HEADER_DWORD(
- UPIU_COMMAND_SET_TYPE_SCSI, 0, 0, 0); + UPIU_COMMAND_SET_TYPE_SCSI, 0, 0, + (lrbp->task_tag &0xf00) << 4);
Are you sure here "(lrbp->task_tag & 0xf00) << 4" is correct?
this will overwrite other fields, see UPIU_HEADER_DWORD:
#define UPIU_HEADER_DWORD(byte3, byte2, byte1, byte0)\
cpu_to_be32((byte3 << 24) | (byte2 << 16) |\
(byte1 << 8) | (byte0))Quoted 22 lines
- ufshcd_send_command(hba, tag);
+ ufshcd_send_command(hba, lrbp);
err =ufshcd_wait_for_dev_cmd(hba, lrbp, timeout); ufshcd_add_query_upiu_trace(hba, err ?UFS_QUERY_ERR:UFS_QUERY_COMP,
(structutp_upiu_req*)lrbp-Quoted 1 line
ucd_rsp_ptr);drivers/ufs/core/ufshcd.c +1
-0@@ -4513,6 +4515,7 @@ int ufshcd_make_hba_operational(struct ufs_hba *hba) REG_UTP_TRANSFER_REQ_LIST_BASE_L); ufshcd_writel(hba, upper_32_bits(hba->utrdl_dma_addr), REG_UTP_TRANSFER_REQ_LIST_BASE_H); + ufshcd_writel(hba, lower_32_bits(hba->utmrdl_dma_addr), REG_UTP_TASK_REQ_LIST_BASE_L);ufshcd_writel(hba,
upper_32_bits(hba->utmrdl_dma_addr),drivers/ufs/core/ufshcd.c +0
-0@@ -5320,6 +5323,32 @@ static void ufshcd_release_scsi_cmd(structufs_hba *hba, ufshcd_clk_scaling_update_busy(hba); }
Quoted 2 lines
+voidufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag)
This function does only complete one task. What does cqe stand for?
Quoted 25 lines
drivers/ufs/core/ufshcd.c +9
-0+{ + struct ufshcd_lrb *lrbp; + struct scsi_cmnd *cmd; + + lrbp = &hba->lrb[task_tag]; + lrbp->compl_time_stamp = ktime_get(); + cmd = lrbp->cmd; + if (cmd) { + if (unlikely(ufshcd_should_inform_monitor(hba,lrbp)))
+ ufshcd_update_monitor(hba, lrbp); + ufshcd_add_command_trace(hba, lrbp,UFS_CMD_COMP); + cmd->result =ufshcd_transfer_rsp_status(hba, lrbp); + ufshcd_release_scsi_cmd(hba, lrbp);
+ /* Do not touch lrbp after scsi done */
+ scsi_done(cmd);
+ } else if (lrbp->command_type==UTP_CMD_TYPE_DEV_MANAGE|| +lrbp->command_type==UTP_CMD_TYPE_UFS_STORAGE) { + if (hba->dev_cmd.complete) {
+ ufshcd_add_command_trace(hba, lrbp,UFS_DEV_COMP);
+ complete(hba->dev_cmd.complete); + ufshcd_clk_scaling_update_busy(hba); + }
+ }
Review
Quoted 2 lines
(quoted diff) +2
-0+} +
Kind regards,
Bean
Re: [RFC PATCH v3 1/4] ufs: core: prepare ufs for multi circular queue support
Hello Bean
Thanks for your comments. Responses inline.
Quoted 3 lines · Bean Huo
Asutosh,
[...]
Quoted 23 lines
Quoted 23 lines
static inline
(quoted diff) +1
-1-void ufshcd_send_command(struct ufs_hba *hba, unsigned int task_tag) +void ufshcd_send_command(struct ufs_hba *hba, struct ufshcd_lrb*lrbp)
{
- structufshcd_lrb*lrbp = &hba->lrb[task_tag]; + inttask_tag=lrbp->task_tag;
unsigned long flags;lrbp->issue_time_stamp =
ktime_get();lrbp->compl_time_stamp=ktime_set(0, 0);
- ufshcd_add_command_trace(hba,task_tag,UFS_CMD_SEND); + ufshcd_add_command_trace(hba, lrbp,UFS_CMD_SEND);
ufshcd_clk_scaling_start_busy(hba);
if (unlikely(ufshcd_should_inform_monitor(hba, lrbp)))ufshcd_start_monitor(hba, lrbp);drivers/ufs/core/ufshcd.c +0
-1@@ -2553,9 +2554,10 @@ void ufshcd_prepare_utp_scsi_cmd_upiu(struct ufshcd_lrb *lrbp, u8 upiu_flags) /* command descriptor fields */ ucd_req_ptr->header.dword_0 = UPIU_HEADER_DWORD( UPIU_TRANSACTION_COMMAND, upiu_flags, - lrbp->lun, lrbp->task_tag);
Quoted 9 lines
drivers/ufs/core/ufshcd.c void ufshcd_prepare_utp_scsi_cmd_upiu(struct ufshcd_lrb *lrbp, u8 upiu_flags) · line 2561
Quoted 6 lines
drivers/ufs/core/ufshcd.c +3
-1+ lrbp->lun, lrbp->task_tag & 0xff); ucd_req_ptr->header.dword_1 = UPIU_HEADER_DWORD( - UPIU_COMMAND_SET_TYPE_SCSI, 0, 0, 0); + UPIU_COMMAND_SET_TYPE_SCSI, 0, 0, + (lrbp->task_tag & 0xf00) << 4);Are you sure here "(
lrbp->task_tag&0xf00) << 4" is correct?
EXT_IID is the higher nibble in DWORD1. So this looks correct to me.
COMMAND UPIU
0 1 2 3
xx000001b Flags LUN Task Tag
4 5 6 7
IID Command Set Type Reserved Reserved EXT_IID | Reserved
Quoted 32 lines
this will overwrite other fields, see
UPIU_HEADER_DWORD:#define UPIU_HEADER_DWORD(byte3, byte2, byte1, byte0)\ cpu_to_be32((byte3 << 24) | (byte2 << 16) |\ (byte1 << 8) | (byte0))Quoted 23 lines
(quoted diff) +1
-1- ufshcd_send_command(hba, tag); + ufshcd_send_command(hba, lrbp);err =
ufshcd_wait_for_dev_cmd(hba, lrbp, timeout); ufshcd_add_query_upiu_trace(hba, err ?UFS_QUERY_ERR:UFS_QUERY_COMP,
(structutp_upiu_req*)lrbp-Quoted 1 line
ucd_rsp_ptr);drivers/ufs/core/ufshcd.c +1
-0@@ -4513,6 +4515,7 @@ int ufshcd_make_hba_operational(struct ufs_hba *hba) REG_UTP_TRANSFER_REQ_LIST_BASE_L); ufshcd_writel(hba, upper_32_bits(hba->utrdl_dma_addr), REG_UTP_TRANSFER_REQ_LIST_BASE_H); + ufshcd_writel(hba, lower_32_bits(hba->utmrdl_dma_addr), REG_UTP_TASK_REQ_LIST_BASE_L);ufshcd_writel(hba,
upper_32_bits(hba->utmrdl_dma_addr),drivers/ufs/core/ufshcd.c +0
-0@@ -5320,6 +5323,32 @@ static void ufshcd_release_scsi_cmd(structufs_hba *hba, ufshcd_clk_scaling_update_busy(hba); }
Quoted 4 lines
drivers/ufs/core/ufshcd.c static void ufshcd_release_scsi_cmd(struct ufs_hba *hba, · line 5326
Quoted 1 line
drivers/ufs/core/ufshcd.c +1
-0+void ufshcd_compl_one_cqe (struct ufs_hba *hba,int task_tag)This function does only complete one task. What does cqe stand for?
CQE - Completion Queue Entry. The term 'task' is used for TM commands in scsi, hence there was a comment to change it to CQE.
Quoted 32 lines
Quoted 17 lines
drivers/ufs/core/ufshcd.c +16
-0+{ + struct ufshcd_lrb *lrbp; + struct scsi_cmnd *cmd; + + lrbp = &hba->lrb[task_tag]; + lrbp->compl_time_stamp = ktime_get(); + cmd = lrbp->cmd; + if (cmd) { + if (unlikely(ufshcd_should_inform_monitor(hba, lrbp))) + ufshcd_update_monitor(hba, lrbp); + ufshcd_add_command_trace(hba, lrbp, UFS_CMD_COMP); + cmd->result = ufshcd_transfer_rsp_status(hba, lrbp); + ufshcd_release_scsi_cmd(hba, lrbp); + /* Do not touch lrbp after scsi done */ + scsi_done(cmd); + } else if (lrbp->command_type == UTP_CMD_TYPE_DEV_MANAGE ||drivers/ufs/core/ufshcd.c static void ufshcd_release_scsi_cmd(struct ufs_hba *hba, · line 5351
Quoted 10 lines
drivers/ufs/core/ufshcd.c +9
-0+ lrbp->command_type == UTP_CMD_TYPE_UFS_STORAGE) { + if (hba->dev_cmd.complete) { + ufshcd_add_command_trace(hba, lrbp,UFS_DEV_COMP ); + complete(hba->dev_cmd.complete); + ufshcd_clk_scaling_update_busy(hba); + } + } +} +Kind regards,
Bean
Re: [RFC PATCH v3 1/4] ufs: core: prepare ufs for multi circular queue support
Quoted 17 lines · Asutosh Das (asd)
Quoted 15 lines
Quoted 6 lines
ufshcd_lrb*lrbp, u8upiu_flags)
/* command descriptor fields */ucd_req_ptr->header.dword_0= UPIU_HEADER_DWORD(UPIU_TRANSACTION_COMMAND,upiu_flags,
- lrbp->lun,lrbp->task_tag);Quoted 8 lines
+ lrbp->lun,
lrbp->task_tag&0xff);
ucd_req_ptr->header.dword_1 = UPIU_HEADER_DWORD( - UPIU_COMMAND_SET_TYPE_SCSI, 0, 0, 0);
+ UPIU_COMMAND_SET_TYPE_SCSI, 0, 0, + (lrbp->task_tag &0xf00) << 4);Quoted 2 lines
Are you sure here "(
lrbp->task_tag&0xf00) << 4" is correct?
Quoted 7 lines
EXT_IIDis the higher nibble in DWORD1. So this looks correct to me.COMMAND UPIU
0 1 2 3
xx000001b Flags LUN Task Tag
4 5 6 7
IID Command Set Type Reserved ReservedEXT_IID| Reserved
Hi Asutosh,
yes, [7:4] of byte 7 in UPIU header for host to device UPIUs EXT_IID, this is correct.
but I think byte7 should be (lrbp->task_tag & 0xf00) >> 4); rather than "<< 4"
or what I missundersood.
Kind regards,
Bean
Bart Van Assche
reviewerRe: [RFC PATCH v3 1/4] ufs: core: prepare ufs for multi circular queue support
In reply to Asutosh DasQuoted 1 line · Asutosh Das
Preparatory changes for upcoming multi circular queue.
One patch per change please and also describe each individual change. From https://www.kernel.org/doc/html/latest/process/submitting-patches.html#split-changes: "Separate each logical change into a separate patch".
Thanks,
Bart.
Re: [RFC PATCH v3 1/4] ufs: core: prepare ufs for multi circular queue support
Hello Bart,
Thanks for the comments.
Quoted 7 lines · Bart Van Assche
Quoted 1 line · Asutosh Das
Preparatory changes for upcoming multi circular queue.
One patch per change please and also describe each individual change.
From
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#split-changes: "Separate each logical change into a separate patch".
The intent of this change was to have all the non-mcq related changes to the ufshcd as a separate patch. I would add more details to the commit message of this change.
If there's anything specific in this patch that may need changes, please let me know.
Quoted 3 lines
Thanks,
Bart.
-asd
Bart Van Assche
reviewerRe: [RFC PATCH v3 1/4] ufs: core: prepare ufs for multi circular queue support
Quoted 4 lines · Asutosh Das (asd)
Hello Bart,
Thanks for the comments.On 9/8/2022 2:58 PM, Bart Van Assche wrote:
Quoted 8 lines
Quoted 5 lines · Asutosh Das
Quoted 1 line
Preparatory changes for upcoming multi circular queue.
One patch per change please and also describe each individual change. From https://www.kernel.org/doc/html/latest/process/submitting-patches.html#split-changes: "Separate each logical change into a separate patch".
The intent of this change was to have all the non-mcq related changes to the ufshcd as a separate patch. I would add more details to the commit message of this change.
If there's anything specific in this patch that may need changes, please let me know.
Please follow the "one change per patch" rule. This is a widely followed rule in the Linux kernel community. This rule exists because it is the responsibility of the developer(s) who post a patch series to make it easy for reviewers to review their work.
Thanks,
Bart.
Re: [RFC PATCH v3 1/4] ufs: core: prepare ufs for multi circular queue support
Quoted 8 lines · Bart Van Assche
Quoted 7 lines · Asutosh Das (asd)
Hello Bart,
Thanks for the comments.Quoted 3 lines · Bart Van Assche
Quoted 1 line · Asutosh Das
Preparatory changes for upcoming multi circular queue.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
One patch per change please and also describe each individual change. From https://www.kernel.org/doc/html/latest/process/submitting-patches.html#split-changes: "Separate each logical change into a separate patch".
The intent of this change was to have all the non-mcq related changes to the ufshcd as a separate patch. I would add more details to the commit message of this change.
If there's anything specific in this patch that may need changes, please let me know.Please follow the "one change per patch" rule. This is a widely followed rule in the Linux kernel community. This rule exists because it is the responsibility of the developer(s) who post a patch series to make it easy for reviewers to review their work.
Let me review and restructure the code and push it again. I would like to remove the RFC tag in the next version. Please let me know if that's _not_ OK.
Quoted 3 lines
Thanks,
Bart.
RFC PATCH v3 2/4 ufs: core: mcq: Adds Multi-Circular Queue support
In reply to Asutosh DasIn v4.0, UFSHCI specification has added Multi-Circular Queue support to enhance performance. It is backward compatible to the legacy Single Doorbell mode.
This patch adds the support for MCQ to ufshc driver. It uses shared tags across queues. It adds support for vendors to define the number of queues for different queue types. It also adds support ESI which is event specific interrupt mechanism for completion path.
--- drivers/ufs/core/Makefile | 2 +- drivers/ufs/core/ufs-mcq.c | 459 +++++++++++++++++++++++++++++++++++++++++ drivers/ufs/core/ufshcd-priv.h | 96 +++++++++ drivers/ufs/core/ufshcd.c | 281 +++++++++++++++++++++---- include/ufs/ufs.h | 6 + include/ufs/ufshcd.h | 130 ++++++++++++ include/ufs/ufshci.h | 79 +++++++ 7 files changed, 1012 insertions(+), 41 deletions(-) create mode 100644 drivers/ufs/core/ufs-mcq.c
drivers/ufs/core/Makefile +1 -1
@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_SCSI_UFSHCD) += ufshcd-core.o -ufshcd-core-y += ufshcd.o ufs-sysfs.o +ufshcd-core-y += ufshcd.o ufs-sysfs.o ufs-mcq.o ufshcd-core-$(CONFIG_DEBUG_FS) += ufs-debugfs.o ufshcd-core-$(CONFIG_SCSI_UFS_BSG) += ufs_bsg.o ufshcd-core-$(CONFIG_SCSI_UFS_CRYPTO) += ufshcd-crypto.o
drivers/ufs/core/ufs-mcq.c new file +459 -0
459 lines not on this page · raw message
drivers/ufs/core/ufshcd-priv.h +96 -0
114 lines not on this page · raw message
drivers/ufs/core/ufshcd.c +241 -40
484 lines not on this page · raw message
include/ufs/ufs.h +6 -0
@@ -165,6 +165,7 @@ enum attr_idn {QUERY_ATTR_IDN_AVAIL_WB_BUFF_SIZE =0x1D ,QUERY_ATTR_IDN_WB_BUFF_LIFE_TIME_EST =0x1E ,QUERY_ATTR_IDN_CURR_WB_BUFF_SIZE =0x1F , + QUERY_ATTR_IDN_EXT_IID_EN = 0x2A, };/* Descriptor idn for Query requests */
@@ -352,6 +353,7 @@ enum {UFS_DEV_EXT_TEMP_NOTIF =BIT (6 ),UFS_DEV_HPB_SUPPORT =BIT (7 ),UFS_DEV_WRITE_BOOSTER_SUP =BIT (8 ), + UFS_DEV_EXT_IID_SUP = BIT(16), };#define UFS_DEV_HPB_SUPPORT_VERSION 0x310
@@ -589,6 +591,8 @@ struct ufs_dev_info {u8 *model;u16 wspecversion;u32 clk_gating_wait_us; +/* Stores the depth of queue in UFS device */ +u8 bqueuedepth;/* UFS HPB related flag */ bool hpb_enabled;
@@ -601,6 +605,8 @@ struct ufs_dev_info {bool b_rpm_dev_flush_capable;u8 b_presrv_uspc_en; +/* UFS EXT_IID Enable */ +bool b_ext_iid_en; };/*
include/ufs/ufshcd.h +130 -0
186 lines not on this page · raw message
include/ufs/ufshci.h +79 -0
115 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [RFC PATCH v3 2/4] ufs: core: mcq: Adds Multi-Circular Queue support
Quoted 31 lines · Asutosh Das
drivers/ufs/core/ufs-mcq.c new file +30
-0+/** +* ufshcd_mcq_decide_queue_depth - decide the queue depth +* @hba - per adapter instance +* +* MAC - Max. Active Command of the Host Controller (HC) +* HC wouldn't send more than this commands to the device. +* The default MAC is 32, but the max. value may vary with +* vendor implementation. +* Calculates and adjusts the queue depth based on the depth +* supported by the HC, ufs device and if ext_iid is supported. +*/ +u32 ufshcd_mcq_decide_queue_depth(struct ufs_hba *hba) +{ + u32 qd, val; + int mac; + + mac = ufshcd_mcq_vops_get_hba_mac(hba); + if (mac < 0) { + val = ufshcd_readl(hba, REG_UFS_MCQ_CFG); + mac = (val & MCQ_CFG_MAC_MASK) >> MCQ_CFG_MAC_OFFSET; + } + + /* MAC is a 0 based value. */ + mac += 1; + qd = min_t(u32, mac, hba->dev_info.bqueuedepth); + if (!qd) + qd = mac; + + /* Adjust queue depth based on ext_iid support. */ + if (qd > 256 && (!hba->ext_iid_sup || !hba-Quoted 1 line
dev_info.b_ext_iid_en))
Quoted 5 lines
+ qd = 256;
+ else if (qd > 4096 &&hba->ext_iid_sup&& hba-Quoted 1 line
dev_info.b_ext_iid_en)
+ qd = 4096;
+
Astosh,
I don't understand here. How can qd be 4096? MAC in UFSHCI is 9 bits width, the maximum depth will be 512, and hba->dev_info.bqueuedepth is one byte width, maximum will be 256.
Kind regards,
Bean
Re: [RFC PATCH v3 2/4] ufs: core: mcq: Adds Multi-Circular Queue support
Hello Bean
Thanks for your comments. Responses inline.
Quoted 35 lines · Bean Huo
Quoted 34 lines · Asutosh Das
drivers/ufs/core/ufs-mcq.c new file +30
-0+/** +* ufshcd_mcq_decide_queue_depth - decide the queue depth +* @hba - per adapter instance +* +* MAC - Max. Active Command of the Host Controller (HC) +* HC wouldn't send more than this commands to the device. +* The default MAC is 32, but the max. value may vary with +* vendor implementation. +* Calculates and adjusts the queue depth based on the depth +* supported by the HC, ufs device and if ext_iid is supported. +*/ +u32 ufshcd_mcq_decide_queue_depth(struct ufs_hba *hba) +{ + u32 qd, val; + int mac; + + mac = ufshcd_mcq_vops_get_hba_mac(hba); + if (mac < 0) { + val = ufshcd_readl(hba, REG_UFS_MCQ_CFG); + mac = (val & MCQ_CFG_MAC_MASK) >> MCQ_CFG_MAC_OFFSET; + } + + /* MAC is a 0 based value. */ + mac += 1; + qd = min_t(u32, mac, hba->dev_info.bqueuedepth); + if (!qd) + qd = mac; + + /* Adjust queue depth based on ext_iid support. */ + if (qd > 256 && (!hba->ext_iid_sup || !hba-Quoted 1 line
dev_info.b_ext_iid_en))
+ qd = 256;
+ else if (qd > 4096 &&hba->ext_iid_sup&& hba-Quoted 1 line
dev_info.b_ext_iid_en)
Quoted 9 lines
Quoted 2 lines
+ qd = 4096;
+Astosh,
I don't understand here. How can qd be 4096? MAC in UFSHCI is 9 bits width, the maximum depth will be 512, and
hba->dev_info.bqueuedepthis one byte width, maximum will be 256.
Correct. The spec is fuzzy about it. Because ext_iid provides a provision to increase the Queue depth to 2^12. Even though the parameters that you referred to don't support it now.
Will remove this part in the next version.
Quoted 3 lines
Kind regards,
Bean
Re: [RFC PATCH v3 2/4] ufs: core: mcq: Adds Multi-Circular Queue support
In reply to Asutosh Dasdrivers/ufs/core/ufs-mcq.c line 128
Quoted 7 lines · Asutosh Das
drivers/ufs/core/ufs-mcq.c new file +7
-0+struct ufs_hw_queue *ufshcd_mcq_req_to_hwq (struct ufs_hba *hba, + struct request *req) +{ + u32 utag, hwq; + + utag = blk_mq_unique_tag(req); + hwq = blk_mq_unique_tag_to_hwq(utag);
I think you could directly get queue number from req->mq_hctx-
Quoted 1 line
queue_num.
Re: [RFC PATCH v3 2/4] ufs: core: mcq: Adds Multi-Circular Queue support
In reply to Asutosh DasQuoted 13 lines · Asutosh Das
drivers/ufs/core/ufs-mcq.c new file +12
-0+ +static void ufshcd_mcq_config_nr_queues (struct ufs_hba *hba) +{ + int i, rem; + u32 hbaq_cap, cmp; + struct Scsi_Host *host = hba->host; + + hbaq_cap = hba->mcq_capabilities & 0xff; + + rem = hbaq_cap - dev_cmd_queue; + /* min() compares variables of same type */ + hba->nr_queues[HCTX_TYPE_DEFAULT] = min(hbaq_cap -
Quoted 1 line
dev_cmd_queue,
hba->nr_queues[HCTX_TYPE_DEFAULT] = min(rem, num_possible_cpus());
Quoted 11 lines
+ num_possible_cpus()); + rem -= hba->nr_queues[HCTX_TYPE_DEFAULT];
+ if (rem <= 0)
+ goto out;
+ cmp = rem;
+ hba->nr_queues[HCTX_TYPE_POLL] =min(cmp, poll_queues); + rem -= hba->nr_queues[HCTX_TYPE_POLL];
+ if (rem <= 0)
+ goto out;
+ cmp = rem;
+ hba->nr_queues[HCTX_TYPE_READ] =min(cmp, read_queues);
static read_queues is not initialized.
Quoted 1 line
.....
drivers/ufs/core/ufshcd-priv.h static inline void ufshcd_vops_config_scaling_param(struct ufs_hba *hba, · line 265
Quoted 9 lines
drivers/ufs/core/ufshcd-priv.h +9
-0+static inline void ufshcd_inc_tp (struct ufs_hw_queue *q) +{ + u32 mask = q->max_entries - 1; + u32 val; + + q->sq_tp_slot = (q->sq_tp_slot + 1) & mask; + val = q->sq_tp_slot * sizeof(struct utp_transfer_req_desc); + writel(val, q->mcq_sq_tp); +}
This function just accesses the submission queue tail pointer. The function name should clearly explain this.
Re: [RFC PATCH v3 2/4] ufs: core: mcq: Adds Multi-Circular Queue support
Hello Bean
Thanks for your comments. Responses inline.
Quoted 18 lines · Bean Huo
Quoted 13 lines · Asutosh Das
drivers/ufs/core/ufs-mcq.c new file +12
-0+ +static void ufshcd_mcq_config_nr_queues (struct ufs_hba *hba) +{ + int i, rem; + u32 hbaq_cap, cmp; + struct Scsi_Host *host = hba->host; + + hbaq_cap = hba->mcq_capabilities & 0xff; + + rem = hbaq_cap - dev_cmd_queue; + /* min() compares variables of same type */ + hba->nr_queues[HCTX_TYPE_DEFAULT] = min(hbaq_cap -Quoted 1 line
dev_cmd_queue,hba->nr_queues[HCTX_TYPE_DEFAULT] = min(rem, num_possible_cpus());
min() compares variables of same type only.
Quoted 12 lines
Quoted 11 lines
+ num_possible_cpus()); + rem -= hba->nr_queues[HCTX_TYPE_DEFAULT];
+ if (rem <= 0)
+ goto out;
+ cmp = rem;
+ hba->nr_queues[HCTX_TYPE_POLL] =min(cmp, poll_queues); + rem -= hba->nr_queues[HCTX_TYPE_POLL];
+ if (rem <= 0)
+ goto out;
+ cmp = rem;
+ hba->nr_queues[HCTX_TYPE_READ] =min(cmp, read_queues);
Quoted 2 lines
static
read_queuesis not initialized.
It would be initialized to 0. But I think we should configure it as a module parameter which is missing. Let me add it in the next version.
Quoted 15 lines
Quoted 1 line
.....
drivers/ufs/core/ufshcd-priv.h static inline void ufshcd_vops_config_scaling_param(struct ufs_hba *hba, · line 265
Quoted 9 lines
drivers/ufs/core/ufshcd-priv.h +9
-0+static inline void ufshcd_inc_tp (struct ufs_hw_queue *q) +{ + u32 mask = q->max_entries - 1; + u32 val; + + q->sq_tp_slot = (q->sq_tp_slot + 1) & mask; + val = q->sq_tp_slot * sizeof(struct utp_transfer_req_desc); + writel(val, q->mcq_sq_tp); +}This function just accesses the submission queue tail pointer. The function name should clearly explain this.
The reason for this naming was that only SQ's tail pointer can be updated by SW. I can add a _sq_ to this function in the next version. Plmk if you prefer a better name.
Quoted 3 lines
Bart Van Assche
reviewerRe: [RFC PATCH v3 2/4] ufs: core: mcq: Adds Multi-Circular Queue support
In reply to Bean HuoQuoted 1 line · Bean Huo
static
read_queuesis not initialized.
Hi Bean,
The Linux kernel coding style guide does not allow to explicitly initialize static variables to zero. The C standard requires that static variables that are not initialized explicitly are initialized to zero. From https://en.wikipedia.org/wiki/.bss: "In C, statically allocated objects without an explicit initializer are initialized to zero (for arithmetic types) or a null pointer (for pointer types)."
Thanks,
Bart.
Bart Van Assche
reviewerRe: [RFC PATCH v3 2/4] ufs: core: mcq: Adds Multi-Circular Queue support
In reply to Asutosh DasQuoted 3 lines · Asutosh Das
In v4.0, UFSHCI specification has added Multi-Circular Queue support to enhance performance. It is backward compatible to the legacy Single Doorbell mode.
The above may be confusing for someone who is not familiar with the UFSHCI 4.0 specification. Consider changing the above text into the following: "The UFSHCI 4.0 register interface defines two modes: (1) a legacy mode that is compatible with UFSHCI 3.0 and (2) an MCQ mode in which multiple submission and completion queues are supported. A capability register indicates whether (1) and/or (2) are supported."
Quoted 12 lines
drivers/ufs/core/ufs-mcq.c new file +12
-0+static int rw_queue_count_set (const char *val,const struct kernel_param *kp) +{ +unsigned int n; +int ret; + + ret =kstrtouint (val,10 , &n); +if (ret) +return ret; +if (n >num_possible_cpus ()) +return -EINVAL ; +return param_set_uint (val, kp); +}
drivers/ufs/core/ufs-mcq.c line 54
Quoted 10 lines
drivers/ufs/core/ufs-mcq.c new file +10
-0+ +static const struct kernel_param_ops rw_queue_count_ops = { + .set = rw_queue_count_set, + .get = param_get_uint, +}; + +static unsigned int rw_queues =8 ; +module_param_cb (rw_queues, &rw_queue_count_ops, &rw_queues,0644 ); +MODULE_PARM_DESC (rw_queues, +"Number of interrupt driven I/O queues used for rw. Default value is 8" );
rw_queues should be >= 1 and <= 32. However, rw_queue_count_set() allows to set this variable to zero and also to values above 32. I think this needs to be improved.
drivers/ufs/core/ufs-mcq.c line 65
Quoted 10 lines
drivers/ufs/core/ufs-mcq.c new file +10
-0+/* resources */ +static const struct ufshcd_res_info_t ufshcd_res_info[RES_MAX ] = { + {"ufs_mem" ,NULL ,NULL }, + {"mcq" ,NULL ,NULL }, + {"mcq_sqd" ,NULL ,NULL }, + {"mcq_sqis" ,NULL ,NULL }, + {"mcq_cqd" ,NULL ,NULL }, + {"mcq_cqis" ,NULL ,NULL }, + {"mcq_vs" ,NULL ,NULL }, +};
Please make the above easier to verify by using designated initializers ([RES_MEM] = { .name = "ufs_mem" }, ...).
drivers/ufs/core/ufs-mcq.c line 72
Quoted 7 lines
drivers/ufs/core/ufs-mcq.c new file +7
-0+ +/** +* ufshcd_mcq_decide_queue_depth - decide the queue depth +* @hba - per adapter instance +* +* MAC - Max. Active Command of the Host Controller (HC) +* HC wouldn't send more than this commands to the device.
wouldn't -> won't
drivers/ufs/core/ufs-mcq.c line 93
Quoted 5 lines
drivers/ufs/core/ufs-mcq.c new file +5
-0+/* MAC is a 0 based value. */ + mac +=1 ; + qd =min_t (u32, mac, hba->dev_info.bqueuedepth); +if (!qd) + qd = mac;
Please use min_not_zero instead of open-coding it.
drivers/ufs/core/ufs-mcq.c line 106
Quoted 5 lines
drivers/ufs/core/ufs-mcq.c new file +5
-0+} + +/** +* ufshcd_mcq_config_mac - Set the #Max Activ Cmds. +* @hba - per adpater instance
adpater -> adapter
Quoted 3 lines
+ * @max_active_cmds - maximum # of active commands to the device at any time.
+ *
+ * The controller wouldn't send more than themax_active_cmdsto the device at
wouldn't -> won't
Quoted 1 line
+/* ROP - Runtime and operation registers configuration */
The above comment seems misleading to me. In the UFSHCI 4.0 specification the operation and runtime registers start with IS - Interrupt Status while the definitions below are for the MCQ submission and completion queue registers.
drivers/ufs/core/ufs-mcq.c line 167
Quoted 2 lines
drivers/ufs/core/ufs-mcq.c new file +2
-0+#define MCQ_CFG_n (r, i) \ + ((r) + MCQ_QCFG_SIZE * (i))
Please add a clear comment above this macro that explains its role and also the meaning of its arguments. I assume that 'i' is the queue index?
drivers/ufs/core/ufs-mcq.c line 169
Quoted 2 lines
drivers/ufs/core/ufs-mcq.c new file +2
-0+#define MCQ_ROP_OFFSET_n (p, i) \ + (hba->mcq_rop[(p)].offset + hba->mcq_rop[(p)].stride * (i))
Also for this macro, please explain its role. I assume that MCQ_CFG_n() is used to calculate offsets of registers defined in the UFSHCI 4.0 specification and that MCQ_ROP_OFFSET_n() is used to calculate offsets in the data structure with submission and completion queues?
drivers/ufs/core/ufs-mcq.c line 196
Quoted 1 line
drivers/ufs/core/ufs-mcq.c new file +1
-0+/* Sbmission Qqueue Doorbell Address Offset */
Sbmission -> Submission
Qqueue -> Queue
drivers/ufs/core/ufs-mcq.c line 216
Quoted 1 line
drivers/ufs/core/ufs-mcq.c new file +1
-0+/* Save the base addresses for quicker access */
base -> head and tail?
drivers/ufs/core/ufs-mcq.c line 234
Quoted 6 lines
drivers/ufs/core/ufs-mcq.c new file +6
-0+/* +* Submission Qeueue Enable|Size|Completion Queue ID to +* Submission Queue Attribute +*/ +ufsmcq_writel (hba, (1 <<31 ) | qsize | (i <<16 ), +MCQ_CFG_n (REG_SQATTR , i));
Qeueue -> Queue
drivers/ufs/core/ufs-mcq.c line 321
Quoted 9 lines
drivers/ufs/core/ufs-mcq.c new file +9
-0+static void ufshcd_mcq_config_nr_queues (struct ufs_hba *hba) +{ +int i, rem; +u32 hbaq_cap, cmp; +struct Scsi_Host *host = hba->host; + + hbaq_cap = hba->mcq_capabilities &0xff ; + + rem = hbaq_cap - dev_cmd_queue;
Please handle the case dev_cmd_queue > hbaq_cap (rem < 0) explicitly.
drivers/ufs/core/ufs-mcq.c line 322
Quoted 1 line
drivers/ufs/core/ufs-mcq.c new file +1
-0+/* min() compares variables of same type */
Please remove this comment. Every kernel developer should know this.
Quoted 8 lines
drivers/ufs/core/ufs-mcq.c new file +8
-0+ hba->nr_queues[HCTX_TYPE_DEFAULT ] =min (hbaq_cap - dev_cmd_queue, +num_possible_cpus ()); + rem -= hba->nr_queues[HCTX_TYPE_DEFAULT ]; +if (rem <=0 ) + goto out; + cmp = rem; + hba->nr_queues[HCTX_TYPE_POLL ] =min (cmp, poll_queues); + rem -= hba->nr_queues[HCTX_TYPE_POLL ];
drivers/ufs/core/ufs-mcq.c line 340
Quoted 10 lines
drivers/ufs/core/ufs-mcq.c new file +10
-0+if (rem <=0 ) + goto out; + cmp = rem; + hba->nr_queues[HCTX_TYPE_READ ] =min (cmp, read_queues); + +out: +for (i =0 ; i <HCTX_MAX_TYPES ; i++) + host->nr_hw_queues += hba->nr_queues[i]; + + hba->nr_hw_queues = host->nr_hw_queues + dev_cmd_queue;
I think there are code paths in this function that can result in host->nr_hw_queues becoming larger than the number of submission queues supported by the controller. Please fix.
drivers/ufs/core/ufs-mcq.c line 415
Quoted 9 lines
drivers/ufs/core/ufs-mcq.c new file +9
-0+static int ufshcd_mcq_get_tag (struct ufs_hba *hba, +struct ufs_hw_queue *hwq, +struct cq_entry *cqe) +{ +dma_addr_t dma_addr; + +/* Bits 31:7 UCD base address, 6:5 are reserved, 4:0 is SQ ID */ + dma_addr = ((u64 )le32_to_cpu (cqe->command_desc_base_addr_hi) <<32 ) | + (le32_to_cpu (cqe->command_desc_base_addr_lo) &CQE_UCD_BA );
The above code would become faster if command_desc_base_addr_hi and command_desc_base_addr_lo would be combined into a single __le64 member variable. Has this been considered?
drivers/ufs/core/ufshcd-priv.h static inline void ufshcd_vops_config_scaling_param(struct ufs_hba *hba, · line 265
Quoted 9 lines
drivers/ufs/core/ufshcd-priv.h +9
-0+static inline void ufshcd_inc_tp (struct ufs_hw_queue *q) +{ +u32 mask = q->max_entries -1 ; +u32 val; + + q->sq_tp_slot = (q->sq_tp_slot +1 ) & mask; + val = q->sq_tp_slot *sizeof (struct utp_transfer_req_desc ); +writel (val, q->mcq_sq_tp); +}
Please consider changing "tp" into "tail" or "tail_pointer" and "hp" into "head" or "head_pointer" to improve code readability.
Quoted 1 line
+EXPORT_SYMBOL_GPL(ufshcd_transfer_req_compl);
Why has this function been exported?
include/ufs/ufshcd.h struct ufs_hba_monitor { · line 746
Quoted 10 lines
include/ufs/ufshcd.h +10
-0+enum ufshcd_res { +RES_MEM , +RES_MCQ , +RES_MCQ_SQD , +RES_MCQ_SQIS , +RES_MCQ_CQD , +RES_MCQ_CQIS , +RES_MCQ_VS , +RES_MAX , +};
Please add a comment that explains the SQD, SQIS etc. acronyms.
include/ufs/ufshcd.h struct ufs_hba_monitor { · line 753
Quoted 6 lines
include/ufs/ufshcd.h +6
-0+/* MCQ Runtime Operation Pointer info structure */ +struct ufshcd_mcq_rop_info_t { +unsigned long offset; +unsigned long stride; +void __iomem *base; +};
Please document the role of the members of this data structure.
Thanks,
Bart.
RFC PATCH v3 3/4 ufs: core: Add Event Specific Interrupt configuration vendor specific ops
In reply to Asutosh DasFrom: Can Guo <[email protected]>
As Event Specific Interrupt message format is not defined in UFSHCI JEDEC specs, and the ESI handling highly depends on how the format is designed, hence add a vendor specific ops such that SoC vendors can configure their own ESI handlers. If ESI vops is not provided or returning error, go with the legacy (central) interrupt way.
Added APIs to enable ESI and config ESI base addresses.
--- drivers/ufs/core/ufs-mcq.c | 14 ++++++++++++++ drivers/ufs/core/ufshcd-priv.h | 8 ++++++++ drivers/ufs/core/ufshcd.c | 6 ++++++ include/ufs/ufshcd.h | 5 +++++ 4 files changed, 33 insertions(+)
drivers/ufs/core/ufs-mcq.c +14 -0
@@ -457,3 +457,17 @@ unsigned long ufshcd_mcq_poll_cqe_lock(struct ufs_hba *hba,return completed_reqs; } + +void ufshcd_mcq_enable_esi (struct ufs_hba *hba) +{ +ufshcd_writel (hba,ufshcd_readl (hba,REG_UFS_MEM_CFG ) |0x2 , +REG_UFS_MEM_CFG ); +} +EXPORT_SYMBOL_GPL (ufshcd_mcq_enable_esi); + +void ufshcd_mcq_config_esi (struct ufs_hba *hba,struct msi_msg *msg) +{ +ufshcd_writel (hba, msg->address_lo,REG_UFS_ESILBA ); +ufshcd_writel (hba, msg->address_hi,REG_UFS_ESIUBA ); +} +EXPORT_SYMBOL_GPL (ufshcd_mcq_config_esi);
drivers/ufs/core/ufshcd-priv.h +8 -0
@@ -254,6 +254,14 @@ static inline int ufshcd_mcq_vops_get_hba_mac(struct ufs_hba *hba)return -EOPNOTSUPP ; } +static inline int ufshcd_mcq_vops_config_esi (struct ufs_hba *hba) +{ +if (hba->vops && hba->vops->config_esi) +return hba->vops->config_esi (hba); + +return -EOPNOTSUPP ; +} +static inline void ufshcd_inc_tp (struct ufs_hw_queue *q) {u32 mask = q->max_entries -1 ;
drivers/ufs/core/ufshcd.c +6 -0
@@ -8306,6 +8306,12 @@ static int ufshcd_config_mcq(struct ufs_hba *hba) goto err; } + ret =ufshcd_mcq_vops_config_esi (hba); +if (ret) { +dev_info (hba->dev,"MCQ ESI not available %d\n" , ret); + ret =0 ; + } +ufshcd_enable_intr (hba,UFSHCD_ENABLE_MCQ_INTRS );ufshcd_mcq_make_queues_operational (hba);ufshcd_mcq_config_mac (hba, hba->nutrs);
include/ufs/ufshcd.h +5 -0
@@ -16,6 +16,7 @@#include <linux/blk-crypto-profile.h> #include <linux/blk-mq.h> #include <linux/devfreq.h> +#include <linux/msi.h> #include <linux/pm_runtime.h> #include <scsi/scsi_device.h> #include <ufs/unipro.h>
@@ -297,6 +298,7 @@ struct ufs_pwr_mode_info {* @get_outstanding_cqs: called to get outstanding completion queues * @config_queues: called to config Runtime Operation Pointers * @get_hba_mac: called to get vendor specific mac value +* @config_esi: called to config Event Specific Interrupt */ struct ufs_hba_variant_ops {const char *name;
@@ -339,6 +341,7 @@ struct ufs_hba_variant_ops { unsigned long *ocqs);int (*config_queues)(struct ufs_hba *hba);int (*get_hba_mac)(struct ufs_hba *hba); +int (*config_esi)(struct ufs_hba *hba); };/* clock gating state */
@@ -1230,6 +1233,8 @@ extern int ufshcd_dme_get_attr(struct ufs_hba *hba, u32 attr_sel,extern int ufshcd_config_pwr_mode (struct ufs_hba *hba,struct ufs_pa_layer_attr *desired_pwr_mode);extern int ufshcd_uic_change_pwr_mode (struct ufs_hba *hba,u8 mode); +extern void ufshcd_mcq_enable_esi (struct ufs_hba *hba); +extern void ufshcd_mcq_config_esi (struct ufs_hba *hba,struct msi_msg *msg);/* UIC command interfaces for DME primitives */ #define DME_LOCAL 0
Signature · 1 line
2.7.4
RFC PATCH v3 4/4 ufs: host: qcom: Add MCQ support
In reply to Asutosh DasFrom: Can Guo <[email protected]>
Use ESI and define Runtime and Operation definitions for MCQ.
--- drivers/ufs/core/ufs-mcq.c | 1 + drivers/ufs/core/ufshcd-priv.h | 2 - drivers/ufs/host/ufs-qcom.c | 134 +++++++++++++++++++++++++++++++++++++++++ drivers/ufs/host/ufs-qcom.h | 13 ++++ include/ufs/ufshcd.h | 2 + 5 files changed, 150 insertions(+), 2 deletions(-)
drivers/ufs/core/ufs-mcq.c +1 -0
@@ -445,6 +445,7 @@ unsigned long ufshcd_mcq_poll_cqe_nolock(struct ufs_hba *hba,return completed_reqs; } +EXPORT_SYMBOL_GPL (ufshcd_mcq_poll_cqe_nolock);unsigned long ufshcd_mcq_poll_cqe_lock (struct ufs_hba *hba,struct ufs_hw_queue *hwq)
drivers/ufs/core/ufshcd-priv.h +0 -2
@@ -56,8 +56,6 @@ int ufshcd_mcq_memory_alloc(struct ufs_hba *hba);void ufshcd_mcq_config_mac (struct ufs_hba *hba,u32 set);u32 ufshcd_mcq_read_cqis (struct ufs_hba *hba,int i);void ufshcd_mcq_write_cqis (struct ufs_hba *hba,u32 val,int i); -unsigned long ufshcd_mcq_poll_cqe_nolock (struct ufs_hba *hba, -struct ufs_hw_queue *hwq);unsigned long ufshcd_mcq_poll_cqe_lock (struct ufs_hba *hba,struct ufs_hw_queue *hwq);void ufshcd_mcq_make_queues_operational (struct ufs_hba *hba);
drivers/ufs/host/ufs-qcom.c +134 -0
152 lines not on this page · raw message
drivers/ufs/host/ufs-qcom.h +13 -0
@@ -53,6 +53,8 @@ enum {* added in HW Version 3.0.0 */ UFS_AH8_CFG =0xFC , + + REG_UFS_CFG3 = 0x271C, };/* QCOM UFS host controller vendor specific debug registers */
@@ -72,6 +74,15 @@ enum { UFS_UFS_DBG_RD_EDTL_RAM = 0x1900, }; +/* QCOM UFS MCQ vendor specific registers */ +enum { +UFS_MEM_MCQ_VS_CFG0 =0x0 , +UFS_MEM_SQIS_VS =0x4 , +UFS_MEM_CQIS_VS =0x8 , +UFS_MEM_IAGIS_VS =0xC , +UFS_MEM_IAGQTYPE_VS =0x10 , +}; +#define UFS_CNTLR_2_x_x_VEN_REGS_OFFSET (x) (0x000 + x)#define UFS_CNTLR_3_x_x_VEN_REGS_OFFSET (x) (0x400 + x)
@@ -221,6 +232,8 @@ struct ufs_qcom_host {struct reset_controller_dev rcdev;struct gpio_desc *device_reset; + +int esi_base; }; static inline u32
include/ufs/ufshcd.h +2 -0
@@ -1235,6 +1235,8 @@ extern int ufshcd_config_pwr_mode(struct ufs_hba *hba,extern int ufshcd_uic_change_pwr_mode (struct ufs_hba *hba,u8 mode);extern void ufshcd_mcq_enable_esi (struct ufs_hba *hba);extern void ufshcd_mcq_config_esi (struct ufs_hba *hba,struct msi_msg *msg); +extern unsigned long ufshcd_mcq_poll_cqe_nolock (struct ufs_hba *hba, +struct ufs_hw_queue *hwq);/* UIC command interfaces for DME primitives */ #define DME_LOCAL 0
Signature · 1 line
2.7.4
Bart Van Assche
reviewerRe: [RFC PATCH v3 4/4] ufs: host: qcom: Add MCQ support
drivers/ufs/host/ufs-qcom.c static void ufs_qcom_config_scaling_param(struct ufs_hba *hba, · line 1555
Quoted 4 lines · Asutosh Das
drivers/ufs/host/ufs-qcom.c +4
-0+static int ufs_qcom_get_hba_mac (struct ufs_hba *hba) +{ +return MAX_SUPP_MAC ; +}
The above implementation is not sufficient to convince me that the get_hba_mac vop is useful. Please remove this vop and use MAX_SUPP_MAC directly where ufshcd_mcq_vops_get_hba_mac() is called.
Thanks,
Bart.
Re: [RFC PATCH v3 4/4] ufs: host: qcom: Add MCQ support
Hello Bart,
Thanks for taking a look.
Quoted 8 lines · Bart Van Assche
drivers/ufs/host/ufs-qcom.c static void ufs_qcom_config_scaling_param(struct ufs_hba *hba, · line 1555
Quoted 4 lines · Asutosh Das
drivers/ufs/host/ufs-qcom.c +4
-0+static int ufs_qcom_get_hba_mac (struct ufs_hba *hba) +{ + return MAX_SUPP_MAC; +}The above implementation is not sufficient to convince me that the
get_hba_macvop is useful. Please remove this vop and useMAX_SUPP_MACdirectly whereufshcd_mcq_vops_get_hba_mac()is called.
The default value of MAC is 32 but it can have a max value of 256.
Here it has a value of 64.
So I think this vops would be helpful for other HC vendors as well who may have a different value than the default.
Quoted 3 lines
Thanks,
Bart.
-asd