diff mbox series

[v2,4/4] scsi: ufs: Set the Command Priority (CP) flag for RT requests

Message ID 20230921192335.676924-5-bvanassche@acm.org (mailing list archive)
State Accepted
Headers show
Series UFS core patches | expand

Commit Message

Bart Van Assche Sept. 21, 2023, 7:22 p.m. UTC
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 <bvanassche@acm.org>
---
 drivers/ufs/core/ufshcd.c | 4 ++++
 include/ufs/ufs.h         | 3 ++-
 2 files changed, 6 insertions(+), 1 deletion(-)

Comments

Avri Altman Sept. 22, 2023, 5:15 a.m. UTC | #1
> 
> 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 <bvanassche@acm.org>
Reviewed-by: Avri Altman <avri.altman@wdc.com>

> ---
>  drivers/ufs/core/ufshcd.c | 4 ++++
>  include/ufs/ufs.h         | 3 ++-
>  2 files changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index
> 8561383076e8..c614619f06bd 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -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);  }
> 
> diff --git a/include/ufs/ufs.h b/include/ufs/ufs.h index
> 0cced88f4531..e77ab1786856 100644
> --- a/include/ufs/ufs.h
> +++ b/include/ufs/ufs.h
> @@ -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,
>  };
diff mbox series

Patch

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 8561383076e8..c614619f06bd 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -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);
 }
 
diff --git a/include/ufs/ufs.h b/include/ufs/ufs.h
index 0cced88f4531..e77ab1786856 100644
--- a/include/ufs/ufs.h
+++ b/include/ufs/ufs.h
@@ -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,
 };