UFS core patches
Subsystems (4)
Bart Van Assche
reviewerv2 cover UFS core patches
Hi Martin,
Please consider these UFS core patches for the next merge window.
Thanks,
Bart.
Changes compared to v1:
- In patch 1/4, instead of preserving the WARN_ONCE() statements, remove these.
- Added a reference to CDL in the description of patch 4/4.
Bart Van Assche (4):
scsi: ufs: Remove request tag range checks
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 | 32 ++++++++++++-------------------- drivers/ufs/host/ufs-exynos.c | 9 +++++++-- include/ufs/ufs.h | 3 ++- include/ufs/ufshcd.h | 7 ++----- 4 files changed, 23 insertions(+), 28 deletions(-)
Bart Van Assche
reviewerPATCH v2 1/4 scsi: ufs: Remove request tag range checks
The block layer core guarantees that tag numbers are in the expected range. Hence remove the statements that check this. This patch suppresses Coverity warnings about left shifts with a negative right hand operand. The following commit originally introduced request tag range checks:14497328b6a6 ("scsi: ufs: verify command tag validity").
--- drivers/ufs/core/ufshcd.c | 6 ------ 1 file changed, 6 deletions(-)
drivers/ufs/core/ufshcd.c +0 -6
@@ -2822,8 +2822,6 @@ 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); -switch (hba->ufshcd_state) {case UFSHCD_STATE_OPERATIONAL :break ;
@@ -6923,8 +6921,6 @@ 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); hba->tmf_rqs[req->tag] = req; treq->upiu_req.req_header.task_tag = task_tag;
@@ -7498,8 +7494,6 @@ static int ufshcd_abort(struct scsi_cmnd *cmd)bool outstanding;u32 reg; -WARN_ONCE (tag <0 ,"Invalid tag %d\n" , tag); -ufshcd_hold (hba);if (!is_mcq_enabled (hba)) {
Re: [PATCH v2 1/4] scsi: ufs: Remove request tag range checks
Quoted 9 lines · Bart Van Assche
The block layer core guarantees that tag numbers are in the expected range. Hence remove the statements that check this. This patch suppresses Coverity warnings about left shifts with a negative right hand operand. The following commit originally introduced request tag range checks:
14497328b6a6("scsi: ufs: verify command tag validity").Cc John Garry<[email protected]>Signed-off-by Bart Van Assche<[email protected]>
Feel free to add:
Bart Van Assche
reviewerPATCH v2 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
@@ -5095,8 +5095,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().
@@ -5112,6 +5111,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
RE: [PATCH v2 2/4] scsi: ufs: Move the 4K alignment code into the Exynos driver
Hi Bart
Quoted 18 lines
-----Original Message-----
From: Bart Van Assche <[email protected]>
Sent: Friday, September 22, 2023 12:53 AM
To: Martin K . Petersen <[email protected]>
Cc: [email protected]; Bart Van Assche <[email protected]>; Alim Akhtar <[email protected]>; James E.J. Bottomley <[email protected]>; Krzysztof Kozlowski <[email protected]>; Stanley Chu <[email protected]>; Can Guo <[email protected]>; Manivannan Sadhasivam <[email protected]>; Asutosh Das <[email protected]>; Bean Huo <[email protected]>; Bao D. Nguyen <[email protected]>; Arthur Simchaev <[email protected]>; Po-Wen Kao <[email protected]>; Eric Biggers <[email protected]>; Keoseong Park <[email protected]>
Subject: [PATCH v2 2/4] scsi: ufs: Move the 4K alignment code into the Exynos driver
Quoted 7 lines
The 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.Cc Alim Akhtar <[email protected]>Signed-off-by Bart Van Assche <[email protected]>---
Tested on exynos7 platform, able to use ufs with this change, so
Quoted 105 lines
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 index renamed from drivers/ufs/core/ufshcd.c +0
-0
f48a65fa3bf7..379229d51f04100644drivers/ufs/core/ufshcd.c +1
-2@@ -5095,8 +5095,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 ); +/* drivers/ufs/core/ufshcd.c +3
-0* Block runtime-pm until all consumers are added. * Refer ufshcd_setup_links(). @@ -5112,6 +5111,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);drivers/ufs/core/ufshcd.c +0
-0return 0 ;drivers/ufs/host/ufs-exynos.c +4
-0@@ -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_opsufs_hba_exynosauto_vh_ops= { @@ -
1680,8 +1686,7 @@ static const structexynos_ufs_drv_dataexynos_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|drivers/ufs/host/ufs-exynos.c +1
-1- 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|drivers/ufs/host/ufs-exynos.c +0
-0EXYNOS_UFS_OPT_BROKEN_RX_SEL_IDX |include/ufs/ufshcd.h index renamed from include/ufs/ufshcd.h +0
-0
7d07b256e906..e0d6590d163d100644include/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 v2 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); }/**
RE: [PATCH v2 3/4] scsi: ufs: Simplify ufshcd_comp_scsi_upiu()
Quoted 5 lines
ufshcd_comp_scsi_upiu()has one caller and that caller ensures thatlrbp->cmd!= NULL. Hence leave out thelrbp->cmdcheck fromufshcd_comp_scsi_upiu().Signed-off-by Bart Van Assche <[email protected]>
Quoted 44 lines
--- drivers/ufs/core/ufshcd.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)drivers/ufs/core/ufshcd.c index renamed from drivers/ufs/core/ufshcd.c +0
-0
379229d51f04..8561383076e8100644drivers/ufs/core/ufshcd.c +5
-12@@ -2714,27 +2714,19 @@ static int ufshcd_compose_devman_upiu(structufs_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 v2 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.
Note: UFS devices do not support CDL so using CDL is not a viable alternative.
--- 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 , };
RE: [PATCH v2 4/4] scsi: ufs: Set the Command Priority (CP) flag for RT requests
Quoted 8 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.
Note: UFS devices do not support CDL so using CDL is not a viable alternative.
Signed-off-by Bart Van Assche <[email protected]>
Quoted 46 lines
--- drivers/ufs/core/ufshcd.c | 4 ++++ include/ufs/ufs.h | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-)drivers/ufs/core/ufshcd.c index renamed from drivers/ufs/core/ufshcd.c +0
-0
8561383076e8..c614619f06bd100644drivers/ufs/core/ufshcd.c +3
-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)) @@ -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);drivers/ufs/core/ufshcd.c +2
-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 index renamed from include/ufs/ufs.h +0
-0
0cced88f4531..e77ab1786856100644include/ufs/ufs.h +3
-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 , };
Martin K. Petersen
AppliedBart,
Quoted 1 line
Please consider these UFS core patches for the next merge window.
Applied to 6.7/scsi-staging, thanks!
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Martin K. Petersen
AppliedQuoted 11 lines · Bart Van Assche
Please consider these UFS core patches for the next merge window.
Thanks,
Bart.
Changes compared to v1:
- In patch 1/4, instead of preserving theWARN_ONCE()statements, remove these.
- Added a reference to CDL in the description of patch 4/4.[...]
Applied to 6.7/scsi-queue, thanks!
[1/4] scsi: ufs: Remove request tag range checks
https://git.kernel.org/mkp/scsi/c/cdaaff61d3bf [2/4] scsi: ufs: Move the 4K alignment code into the Exynos driver https://git.kernel.org/mkp/scsi/c/858231bdb223 [3/4] scsi: ufs: Simplify ufshcd_comp_scsi_upiu() https://git.kernel.org/mkp/scsi/c/c788cf8a21cd [4/4] scsi: ufs: Set the Command Priority (CP) flag for RT requests https://git.kernel.org/mkp/scsi/c/00d2fa28da0a
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering