Skip to contentSkip to conversation

Changes for UFS advanced RPMB

PATCH Applied Bean Huo 3 participants 7 messages Aug 9, 2023 – Sep 5, 2023

Subsystems (2)
lore
Share & tools
lore

Bean Huo

author
#0 lore raw

cover Changes for UFS advanced RPMB

Bean Huo (2):
scsi: ufs: core: Add advanced RPMB support where UFSHCI 4.0 does not
support EHS length in UTRD
scsi: ufs: core: No need to update UPIU.header.flags and lun in
advanced RPMB handler

 drivers/ufs/core/ufs_bsg.c |  3 +--
 drivers/ufs/core/ufshcd.c  | 14 ++++++++++----
 2 files changed, 11 insertions(+), 6 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/2 scsi: ufs: core: Add advanced RPMB support where UFSHCI 4.0 does not support EHS length in UTRD

From: Bean Huo <[email protected]>

According to UFSHCI 4.0 specification:

5.2 Host Controller Capabilities Registers
5.2.1 Offset 00h: CAP – Controller Capabilities:

" EHS Length in UTRD Supported (EHSLUTRDS): Indicates whether the host
controller supports EHS Length field in UTRD.
0 – Host controller takes EHS length from CMD UPIU, and SW driver use EHS Length field in CMD UPIU. 1 – HW controller takes EHS length from UTRD, and SW driver use EHS Length field in UTRD. NOTE Recommend Host controllers move to taking EHS length from UTRD, and in UFS-5, it will be mandatory."

So, when UFSHCI 4.0 doesn't support EHS Length field in UTRD, we could use EHS Length field in CMD UPIU. This patch aims to remove the limitation that advanced RPMB only works when EHS length is supported in UTRD.

Fixes 6ff265fc5ef6 ("scsi: ufs: core: bsg: Add advanced RPMB support in ufs_bsg")
---
 drivers/ufs/core/ufs_bsg.c |  3 +--
 drivers/ufs/core/ufshcd.c  | 10 +++++++++-
 2 files changed, 10 insertions(+), 3 deletions(-)
drivers/ufs/core/ufs_bsg.c +1 -2
index 34e423924e06..374e5aae4e7e 100644
@@ -76,8 +76,7 @@ static int ufs_bsg_exec_advanced_rpmb_req(struct ufs_hba *hba, struct bsg_job *j
 	int ret;
 	int data_len;
 
-	if (hba->ufs_version < ufshci_version(4, 0) || !hba->dev_info.b_advanced_rpmb_en ||
-	    !(hba->capabilities & MASK_EHSLUTRD_SUPPORTED))
+	if (hba->ufs_version < ufshci_version(4, 0) || !hba->dev_info.b_advanced_rpmb_en)
 		return -EINVAL;
 
 	if (rpmb_request->ehs_req.length != 2 || rpmb_request->ehs_req.ehs_type != 1)
drivers/ufs/core/ufshcd.c +9 -1
index 8b5ee1a7d454..7f965ac18ee8 100644
@@ -7240,7 +7240,15 @@ int ufshcd_advanced_rpmb_req_handler(struct ufs_hba *hba, struct utp_upiu_req *r
 	/* Advanced RPMB starts from UFS 4.0, so its command type is UTP_CMD_TYPE_UFS_STORAGE */
 	lrbp->command_type = UTP_CMD_TYPE_UFS_STORAGE;
 
-	ufshcd_prepare_req_desc_hdr(lrbp, &upiu_flags, dir, 2);
+	/*
+	 * According to UFSHCI 4.0 specification page 24, if EHSLUTRDS is 0, host controller takes
+	 * EHS length from CMD UPIU, and SW driver use EHS Length field in CMD UPIU. if it is 1,
+	 * HW controller takes EHS length from UTRD.
+	 */
+	if (hba->capabilities & MASK_EHSLUTRD_SUPPORTED)
+		ufshcd_prepare_req_desc_hdr(lrbp, &upiu_flags, dir, 2);
+	else
+		ufshcd_prepare_req_desc_hdr(lrbp, &upiu_flags, dir, 0);
 
 	/* update the task tag and LUN in the request upiu */
 	req_upiu->header.flags = upiu_flags;
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH 2/2 scsi: ufs: core: No need to update UPIU.header.flags and lun in advanced RPMB handler

In reply to Bean Huo

From: Bean Huo <[email protected]>

For advanced RPMB requests, its UPIU package should be fully initialized in its ufs-bsg-based application, except for task tag. in ufshcd.c, we just copy UPIU (with CDB) request as-is.

---
 drivers/ufs/core/ufshcd.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/ufs/core/ufshcd.c +1 -3
index 7f965ac18ee8..446f949154c3 100644
@@ -7250,9 +7250,7 @@ int ufshcd_advanced_rpmb_req_handler(struct ufs_hba *hba, struct utp_upiu_req *r
 	else
 		ufshcd_prepare_req_desc_hdr(lrbp, &upiu_flags, dir, 0);
 
-	/* update the task tag and LUN in the request upiu */
-	req_upiu->header.flags = upiu_flags;
-	req_upiu->header.lun = UFS_UPIU_RPMB_WLUN;
+	/* update the task tag */
 	req_upiu->header.task_tag = tag;
 
 	/* copy the UPIU(contains CDB) request as it is */
Signature · 1 line
2.34.1
author
#3 lore raw
In reply to Bean Huo
Quoted 8 lines · Bean Huo

Bean Huo (2):
  scsi: ufs: core: Add advanced RPMB support where UFSHCI 4.0 does not
    support EHS length in UTRD
  scsi: ufs: core: No need to update UPIU.header.flags and lun in advanced RPMB handler

Quoted 4 lines

 drivers/ufs/core/ufs_bsg.c |  3 +--
 drivers/ufs/core/ufshcd.c  | 14 ++++++++++----

 2 files changed, 11 insertions(+), 6 deletions(-)

Hi Martin and Bart,

what's opinion of this series of patch??

Bean

reviewer Reviewed-by
#4 lore raw
Quoted 1 line · Bean Huo

what's opinion of this series of patch??

Hi Bean,

I had not yet reviewed these patches since my employer is not using advanced RPMB. Anyway, since both patches look good to me:

#5 lore raw
In reply to Bean Huo

Bean,

Quoted 5 lines

Bean Huo (2):
scsi: ufs: core: Add advanced RPMB support where UFSHCI 4.0 does not
support EHS length in UTRD
scsi: ufs: core: No need to update UPIU.header.flags and lun in
advanced RPMB handler

Applied to 6.6/scsi-staging, thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#6 lore raw
In reply to Bean Huo
Quoted 11 lines · Bean Huo

Bean Huo (2):
scsi: ufs: core: Add advanced RPMB support where UFSHCI 4.0 does not
support EHS length in UTRD
scsi: ufs: core: No need to update UPIU.header.flags and lun in
advanced RPMB handler

drivers/ufs/core/ufs_bsg.c | 3 +--

 drivers/ufs/core/ufshcd.c  | 14 ++++++++++----
 2 files changed, 11 insertions(+), 6 deletions(-)

[...]

Applied to 6.6/scsi-queue, thanks!

[1/2] scsi: ufs: core: Add advanced RPMB support where UFSHCI 4.0 does not support EHS length in UTRD

      https://git.kernel.org/mkp/scsi/c/c91e585cfb3d
[2/2] scsi: ufs: core: No need to update UPIU.header.flags and lun in advanced RPMB handler
      https://git.kernel.org/mkp/scsi/c/9f6fec656613
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering