UFS core patches
Subsystems (4)
Bart Van Assche
reviewercover UFS core patches
Hi Martin,
Please consider these UFS core patches for the next merge window.
Thanks,
Bart.
Bart Van Assche (4):
scsi: ufs: Return in case of an invalid tag
scsi: ufs: Move the 4K alignment code into the Exynos driver
scsi: ufs: Simplify ufshcd_comp_scsi_upiu()
scsi: ufs: Set the Command Priority (CP) flag for RT requests
drivers/ufs/core/ufshcd.c | 42 +++++++++++++++++++---------------- drivers/ufs/host/ufs-exynos.c | 9 ++++++-- include/ufs/ufs.h | 3 ++- include/ufs/ufshcd.h | 7 ++---- 4 files changed, 34 insertions(+), 27 deletions(-)
Bart Van Assche
reviewerPATCH 1/4 scsi: ufs: Return in case of an invalid tag
If a tag is invalid, instead of only issuing a kernel warning, also return. This patch suppresses Coverity warnings about left shifts with a negative right hand operand.
--- drivers/ufs/core/ufshcd.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
drivers/ufs/core/ufshcd.c +11 -5
@@ -2822,7 +2822,8 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)int err =0 ;struct ufs_hw_queue *hwq =NULL ; -WARN_ONCE (tag <0 || tag >= hba->nutrs,"Invalid tag %d\n" , tag); +if (WARN_ONCE (tag <0 || tag >= hba->nutrs,"Invalid tag %d\n" , tag)) +return 0 ;switch (hba->ufshcd_state) {case UFSHCD_STATE_OPERATIONAL :
@@ -6923,8 +6924,11 @@ static int __ufshcd_issue_tm_cmd(struct ufs_hba *hba,spin_lock_irqsave (host->host_lock, flags); task_tag = req->tag; -WARN_ONCE (task_tag <0 || task_tag >= hba->nutmrs,"Invalid tag %d\n" , - task_tag); +if (WARN_ONCE (task_tag <0 || task_tag >= hba->nutmrs, +"Invalid tag %d\n" , task_tag)) { + err = -EINVAL ; + goto unlock; + } hba->tmf_rqs[req->tag] = req; treq->upiu_req.req_header.task_tag = task_tag;
@@ -6963,6 +6967,7 @@ static int __ufshcd_issue_tm_cmd(struct ufs_hba *hba,spin_lock_irqsave (hba->host->host_lock, flags); hba->tmf_rqs[req->tag] =NULL ;__clear_bit (task_tag, &hba->outstanding_tasks); +unlock:spin_unlock_irqrestore (hba->host->host_lock, flags);ufshcd_release (hba);
@@ -7485,7 +7490,7 @@ int ufshcd_try_to_abort_task(struct ufs_hba *hba, int tag)* ufshcd_abort - scsi host template eh_abort_handler callback * @cmd: SCSI command pointer * -* Return: SUCCESS or FAILED. +* Return: SUCCESS, FAILED or FAST_IO_FAIL. */ static int ufshcd_abort (struct scsi_cmnd *cmd) {
@@ -7498,7 +7503,8 @@ static int ufshcd_abort(struct scsi_cmnd *cmd)bool outstanding;u32 reg; -WARN_ONCE (tag <0 ,"Invalid tag %d\n" , tag); +if (WARN_ONCE (tag <0 ,"Invalid tag %d\n" , tag)) +return FAST_IO_FAIL ;ufshcd_hold (hba);
RE: [PATCH 1/4] scsi: ufs: Return in case of an invalid tag
Hi Bart,
Quoted 14 lines
If a tag is invalid, instead of only issuing a kernel warning, also return. This patch suppresses Coverity warnings about left shifts with a negative right hand operand.
Signed-off-by Bart Van Assche <[email protected]>--- drivers/ufs/core/ufshcd.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)drivers/ufs/core/ufshcd.c +0
-0
drivers/ufs/core/ufshcd.c static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) · line 2826
Quoted 6 lines
drivers/ufs/core/ufshcd.c +2
-1@@ -2822,7 +2822,8 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) int err = 0; struct ufs_hw_queue *hwq = NULL; - WARN_ONCE(tag < 0 || tag >= hba->nutrs, "Invalid tag %d\n", tag); + if (WARN_ONCE(tag < 0 || tag >= hba->nutrs, "Invalid tag %d\n", tag)) + return 0;
As far as I know, a return 0 from a queuecommand means that the request was accepted by LLD.
Thanks,
Daejun
Bart Van Assche
reviewerRe: [PATCH 1/4] scsi: ufs: Return in case of an invalid tag
Quoted 9 lines · Daejun Park
Quoted 8 lines · Bart Van Assche
drivers/ufs/core/ufshcd.c +0
-0@@ -2822,7 +2822,8 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) int err = 0; struct ufs_hw_queue *hwq = NULL;
Quoted 5 lines
drivers/ufs/core/ufshcd.c static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) · line 2826
Quoted 3 lines
drivers/ufs/core/ufshcd.c +2
-1- WARN_ONCE(tag < 0 || tag >= hba->nutrs, "Invalid tag %d\n", tag); + if (WARN_ONCE(tag < 0 || tag >= hba->nutrs, "Invalid tag %d\n", tag)) + return 0;As far as I know, a return 0 from a queuecommand means that the request was accepted by LLD.
This is on purpose. I think that it is better to issue a warning and to cause command processing to hang rather than to return a code that causes the SCSI core to resubmit a command with an invalid tag and to cause an infinite loop.
Thanks,
Bart.
Re: [PATCH 1/4] scsi: ufs: Return in case of an invalid tag
Quoted 10 lines · Bart Van Assche
drivers/ufs/core/ufshcd.c static int ufshcd_queuecommand(struct Scsi_Host · line 2825
Quoted 10 lines
drivers/ufs/core/ufshcd.c +0
-1@@ -2822,7 +2822,8 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) int err = 0; struct ufs_hw_queue *hwq = NULL; - WARN_ONCE(tag < 0 || tag >= hba->nutrs, "Invalid tag %d\n", tag);
How is tag < 0 even possible? Indeed, I doubt the tag >= hba->nutrs check also, since shost->can_queue is set to hba->nutrs - UFSHCD_NUM_RESERVED AFAICS
John
Quoted 5 lines
drivers/ufs/core/ufshcd.c static int ufshcd_queuecommand(struct Scsi_Host · line 2828
Quoted 3 lines
drivers/ufs/core/ufshcd.c +2
-0+ if (WARN_ONCE(tag < 0 || tag >= hba->nutrs, "Invalid tag %d\n", tag)) + return 0;As far as I know, a return 0 from a queuecommand means that the request was accepted by LLD.
Bart Van Assche
reviewerRe: [PATCH 1/4] scsi: ufs: Return in case of an invalid tag
Quoted 13 lines · John Garry
Quoted 10 lines · Bart Van Assche
drivers/ufs/core/ufshcd.c static int ufshcd_queuecommand(struct Scsi_Host · line 2825
Quoted 10 lines
drivers/ufs/core/ufshcd.c +0
-1@@ -2822,7 +2822,8 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) int err = 0; struct ufs_hw_queue *hwq = NULL; - WARN_ONCE(tag < 0 || tag >= hba->nutrs, "Invalid tag %d\n", tag);How is tag < 0 even possible? Indeed, I doubt the tag >=
hba->nutrscheck also, sinceshost->can_queueis set tohba->nutrs-UFSHCD_NUM_RESERVEDAFAICS
Hi John,
In my opinion neither tag < 0 nor tag >= hba->nutrs can happen. Hence, another possibility is to remove the above warning statement.
Thanks,
Bart.
Bart Van Assche
reviewerPATCH 2/4 scsi: ufs: Move the 4K alignment code into the Exynos driver
In reply to Bart Van AsscheThe DMA alignment for the Exynos controller follows directly from the PRDT segment size configured in ufs-exynos.c. Hence, move the DMA alignment code into the Exynos driver source code.
--- drivers/ufs/core/ufshcd.c | 6 ++++-- drivers/ufs/host/ufs-exynos.c | 9 +++++++-- include/ufs/ufshcd.h | 7 ++----- 3 files changed, 13 insertions(+), 9 deletions(-)
drivers/ufs/core/ufshcd.c +4 -2
@@ -5098,8 +5098,7 @@ static int ufshcd_slave_configure(struct scsi_device *sdev)struct request_queue *q = sdev->request_queue;blk_queue_update_dma_pad (q,PRDT_DATA_BYTE_COUNT_PAD -1 ); -if (hba->quirks &UFSHCD_QUIRK_4KB_DMA_ALIGNMENT ) -blk_queue_update_dma_alignment (q,SZ_4K -1 ); +/* * Block runtime-pm until all consumers are added. * Refer ufshcd_setup_links().
@@ -5115,6 +5114,9 @@ static int ufshcd_slave_configure(struct scsi_device *sdev)*/ sdev->silence_suspend =1 ; +if (hba->vops && hba->vops->config_scsi_dev) + hba->vops->config_scsi_dev (sdev); +ufshcd_crypto_register (hba, q);return 0 ;
drivers/ufs/host/ufs-exynos.c +7 -2
@@ -1511,6 +1511,11 @@ static int fsd_ufs_pre_link(struct exynos_ufs *ufs)return 0 ; } +static void exynos_ufs_config_scsi_dev (struct scsi_device *sdev) +{ +blk_queue_update_dma_alignment (sdev->request_queue,SZ_4K -1 ); +} +static int fsd_ufs_post_link (struct exynos_ufs *ufs) {int i;
@@ -1579,6 +1584,7 @@ static const struct ufs_hba_variant_ops ufs_hba_exynos_ops = { .hibern8_notify = exynos_ufs_hibern8_notify, .suspend = exynos_ufs_suspend, .resume = exynos_ufs_resume, + .config_scsi_dev = exynos_ufs_config_scsi_dev, };static struct ufs_hba_variant_ops ufs_hba_exynosauto_vh_ops = {
@@ -1680,8 +1686,7 @@ static const struct exynos_ufs_drv_data exynos_ufs_drvs = {UFSHCI_QUIRK_SKIP_RESET_INTR_AGGR |UFSHCD_QUIRK_BROKEN_OCS_FATAL_ERROR |UFSHCI_QUIRK_SKIP_MANUAL_WB_FLUSH_CTRL | -UFSHCD_QUIRK_SKIP_DEF_UNIPRO_TIMEOUT_SETTING | - UFSHCD_QUIRK_4KB_DMA_ALIGNMENT, + UFSHCD_QUIRK_SKIP_DEF_UNIPRO_TIMEOUT_SETTING, .opts =EXYNOS_UFS_OPT_HAS_APB_CLK_CTRL |EXYNOS_UFS_OPT_BROKEN_AUTO_CLK_CTRL | EXYNOS_UFS_OPT_BROKEN_RX_SEL_IDX |
include/ufs/ufshcd.h +2 -5
@@ -28,6 +28,7 @@#define UFSHCD "ufshcd" +struct scsi_device ;struct ufs_hba ;enum dev_cmd_type {
@@ -371,6 +372,7 @@ struct ufs_hba_variant_ops {int (*get_outstanding_cqs)(struct ufs_hba *hba,unsigned long *ocqs);int (*config_esi)(struct ufs_hba *hba); +void (*config_scsi_dev)(struct scsi_device *sdev); };/* clock gating state */
@@ -596,11 +598,6 @@ enum ufshcd_quirks {*/ UFSHCD_QUIRK_SKIP_DEF_UNIPRO_TIMEOUT_SETTING = 1 << 13, -/* -* Align DMA SG entries on a 4 KiB boundary. -*/ - UFSHCD_QUIRK_4KB_DMA_ALIGNMENT = 1 << 14, -/* * This quirk needs to be enabled if the host controller does not * support UIC command
Bart Van Assche
reviewerPATCH 3/4 scsi: ufs: Simplify ufshcd_comp_scsi_upiu()
In reply to Bart Van Asscheufshcd_comp_scsi_upiu() has one caller and that caller ensures that lrbp->cmd != NULL. Hence leave out the lrbp->cmd check from ufshcd_comp_scsi_upiu().
--- drivers/ufs/core/ufshcd.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
drivers/ufs/core/ufshcd.c +4 -12
@@ -2714,27 +2714,19 @@ static int ufshcd_compose_devman_upiu(struct ufs_hba *hba,* for SCSI Purposes * @hba: per adapter instance * @lrbp: pointer to local reference block -* -* Return: 0 upon success; < 0 upon failure. */ -static int ufshcd_comp_scsi_upiu (struct ufs_hba *hba,struct ufshcd_lrb *lrbp) +static void ufshcd_comp_scsi_upiu (struct ufs_hba *hba,struct ufshcd_lrb *lrbp) {u8 upiu_flags; -int ret =0 ;if (hba->ufs_version <=ufshci_version (1 ,1 )) lrbp->command_type =UTP_CMD_TYPE_SCSI ;else lrbp->command_type =UTP_CMD_TYPE_UFS_STORAGE ; -if (likely (lrbp->cmd)) { -ufshcd_prepare_req_desc_hdr (lrbp, &upiu_flags, lrbp->cmd->sc_data_direction,0 ); -ufshcd_prepare_utp_scsi_cmd_upiu (lrbp, upiu_flags); - }else { - ret = -EINVAL ; - } - -return ret; +ufshcd_prepare_req_desc_hdr (lrbp, &upiu_flags, + lrbp->cmd->sc_data_direction,0 ); +ufshcd_prepare_utp_scsi_cmd_upiu (lrbp, upiu_flags); }/**
Bart Van Assche
reviewerPATCH 4/4 scsi: ufs: Set the Command Priority (CP) flag for RT requests
In reply to Bart Van AsscheMake the UFS device execute realtime (RT) requests before other requests. This will be used in Android to reduce the I/O latency of the foreground app.
--- drivers/ufs/core/ufshcd.c | 4 ++++ include/ufs/ufs.h | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-)
drivers/ufs/core/ufshcd.c +4 -0
@@ -2717,6 +2717,8 @@ static int ufshcd_compose_devman_upiu(struct ufs_hba *hba,*/ static void ufshcd_comp_scsi_upiu (struct ufs_hba *hba,struct ufshcd_lrb *lrbp) { +struct request *rq =scsi_cmd_to_rq (lrbp->cmd); +unsigned int ioprio_class =IOPRIO_PRIO_CLASS (req_get_ioprio (rq));u8 upiu_flags;if (hba->ufs_version <=ufshci_version (1 ,1 ))
@@ -2726,6 +2728,8 @@ static void ufshcd_comp_scsi_upiu(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)ufshcd_prepare_req_desc_hdr (lrbp, &upiu_flags, lrbp->cmd->sc_data_direction,0 ); +if (ioprio_class ==IOPRIO_CLASS_RT ) + upiu_flags |=UPIU_CMD_FLAGS_CP ;ufshcd_prepare_utp_scsi_cmd_upiu (lrbp, upiu_flags); }
include/ufs/ufs.h +2 -1
@@ -98,9 +98,10 @@ enum upiu_response_transaction { UPIU_TRANSACTION_REJECT_UPIU = 0x3F, }; -/* UPIU Read/Write flags */ +/* UPIU Read/Write flags. See also table "UPIU Flags" in the UFS standard. */ enum {UPIU_CMD_FLAGS_NONE =0x00 , +UPIU_CMD_FLAGS_CP =0x04 ,UPIU_CMD_FLAGS_WRITE =0x20 ,UPIU_CMD_FLAGS_READ =0x40 , };
Avri Altman
reviewerRE: [PATCH 4/4] scsi: ufs: Set the Command Priority (CP) flag for RT requests
Quoted 4 lines
Make the UFS device execute realtime (RT) requests before other requests. This will be used in Android to reduce the I/O latency of the foreground app.
Maybe one more sentence, explaining that ufs CP is agnostic to scsi CDL, And can be implemented regardless.
Thanks,
Avri
Quoted 49 lines
Signed-off-by Bart Van Assche <[email protected]>--- drivers/ufs/core/ufshcd.c | 4 ++++ include/ufs/ufs.h | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-)drivers/ufs/core/ufshcd.c +2
-0@@ -2717,6 +2717,8 @@ static int ufshcd_compose_devman_upiu(structufs_hba *hba, */ static void ufshcd_comp_scsi_upiu (struct ufs_hba *hba,struct ufshcd_lrb *lrbp) { +struct request *rq =scsi_cmd_to_rq (lrbp->cmd); +unsigned int ioprio_class =IOPRIO_PRIO_CLASS (req_get_ioprio (rq));u8 upiu_flags;if (hba->ufs_version <= ufshci_version(1, 1))drivers/ufs/core/ufshcd.c +2
-0@@ -2726,6 +2728,8 @@ static void ufshcd_comp_scsi_upiu(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)ufshcd_prepare_req_desc_hdr (lrbp, &upiu_flags, lrbp->cmd->sc_data_direction,0 ); +if (ioprio_class ==IOPRIO_CLASS_RT ) + upiu_flags |=UPIU_CMD_FLAGS_CP ;ufshcd_prepare_utp_scsi_cmd_upiu (lrbp, upiu_flags); }include/ufs/ufs.h +2
-1@@ -98,9 +98,10 @@ enum upiu_response_transaction { UPIU_TRANSACTION_REJECT_UPIU = 0x3F, }; -/* UPIU Read/Write flags */ +/* UPIU Read/Write flags. See also table "UPIU Flags" in the UFS standard. */ enum {UPIU_CMD_FLAGS_NONE =0x00 , +UPIU_CMD_FLAGS_CP =0x04 ,UPIU_CMD_FLAGS_WRITE =0x20 ,UPIU_CMD_FLAGS_READ =0x40 ,};
Bart Van Assche
reviewerRe: [PATCH 4/4] scsi: ufs: Set the Command Priority (CP) flag for RT requests
Quoted 7 lines · Avri Altman
Quoted 3 lines · Bart Van Assche
Make the UFS device execute realtime (RT) requests before other requests. This will be used in Android to reduce the I/O latency of the foreground app.
Maybe one more sentence, explaining that ufs CP is agnostic to scsi CDL, And can be implemented regardless.
Hmm ... is it really necessary to add a reference to CDL in the patch
description? I'm not aware of any UFS devices that support CDL.
Additionally, if CDL will ever be supported then I think thatufshcd_comp_scsi_upiu() should be modified such that it selects a duration limit instead of setting the CP bit.
Thanks,
Bart.