mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3] scsi: ufs: core: Fix RPMB region size detection for UFS 2.2
@ 2026-02-09 15:17 Alexey Charkov
  2026-02-18  2:16 ` Martin K. Petersen
  2026-02-24 16:47 ` Martin K. Petersen
  0 siblings, 2 replies; 3+ messages in thread
From: Alexey Charkov @ 2026-02-09 15:17 UTC (permalink / raw)
  To: Alim Akhtar, Avri Altman, Bart Van Assche, James E.J. Bottomley,
	Martin K. Petersen, Bean Huo, Can Guo
  Cc: linux-scsi, linux-kernel, stable, Alexey Charkov

Older UFS spec devices (2.2 and earlier) do not expose per-region RPMB
sizes, as only one RPMB region is supported. In such cases, the size of
the single RPMB region can be deduced from the Logical Block Count and
Logical Block Size fields in the RPMB Unit Descriptor.

Add a fallback mechanism to calculate the RPMB region size from these
fields if the device implements an older spec, so that the RPMB driver
can work with such devices - otherwise it silently skips the whole RPMB.

        Section 14.1.4.6 (RPMB Unit Descriptor)

Link: https://www.jedec.org/system/files/docs/JESD220C-2_2.pdf
Cc: stable@vger.kernel.org
Fixes: b06b8c421485 ("scsi: ufs: core: Add OP-TEE based RPMB driver for UFS devices")
Reviewed-by: Bean Huo <beanhuo@micron.com>
Signed-off-by: Alexey Charkov <alchark@flipper.net>
---
Changes in v3:
- Fix comment style, add note about respective fields being always zero (thanks Bart)
- Link to v2: https://lore.kernel.org/r/20260205-ufs-rpmb-v2-1-5e1572ee52bf@flipper.net

Changes in v2:
- Comment on the expected size of the RPMB partition on UFS 2.2 (thanks Bean)
- Use a standard define for size instead of a magic number (thanks Bean)
- Link to v1: https://lore.kernel.org/r/20260129-ufs-rpmb-v1-1-691534ab723f@flipper.net
---
 drivers/ufs/core/ufshcd.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 847b55789bb8..0d7b31620ea4 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -24,6 +24,7 @@
 #include <linux/pm_opp.h>
 #include <linux/regulator/consumer.h>
 #include <linux/sched/clock.h>
+#include <linux/sizes.h>
 #include <linux/iopoll.h>
 #include <scsi/scsi_cmnd.h>
 #include <scsi/scsi_dbg.h>
@@ -5249,6 +5250,25 @@ static void ufshcd_lu_init(struct ufs_hba *hba, struct scsi_device *sdev)
 		hba->dev_info.rpmb_region_size[1] = desc_buf[RPMB_UNIT_DESC_PARAM_REGION1_SIZE];
 		hba->dev_info.rpmb_region_size[2] = desc_buf[RPMB_UNIT_DESC_PARAM_REGION2_SIZE];
 		hba->dev_info.rpmb_region_size[3] = desc_buf[RPMB_UNIT_DESC_PARAM_REGION3_SIZE];
+
+		if (hba->dev_info.wspecversion <= 0x0220) {
+			/*
+			 * These older spec chips have only one RPMB region,
+			 * sized between 128 kB minimum and 16 MB maximum.
+			 * No per region size fields are provided (respective
+			 * REGIONX_SIZE fields always contain zeros), so get
+			 * it from the logical block count and size fields for
+			 * compatibility
+			 *
+			 * (See JESD220C-2_2 Section 14.1.4.6
+			 * RPMB Unit Descriptor,* offset 13h, 4 bytes)
+			 */
+			hba->dev_info.rpmb_region_size[0] =
+				(get_unaligned_be64(desc_buf
+					+ RPMB_UNIT_DESC_PARAM_LOGICAL_BLK_COUNT)
+				<< desc_buf[RPMB_UNIT_DESC_PARAM_LOGICAL_BLK_SIZE])
+				/ SZ_128K;
+		}
 	}
 
 

---
base-commit: 9845cf73f7db6094c0d8419d6adb848028f4a921
change-id: 20260129-ufs-rpmb-d198a699a40d

Best regards,
-- 
Alexey Charkov <alchark@flipper.net>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] scsi: ufs: core: Fix RPMB region size detection for UFS 2.2
  2026-02-09 15:17 [PATCH v3] scsi: ufs: core: Fix RPMB region size detection for UFS 2.2 Alexey Charkov
@ 2026-02-18  2:16 ` Martin K. Petersen
  2026-02-24 16:47 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: Martin K. Petersen @ 2026-02-18  2:16 UTC (permalink / raw)
  To: Alexey Charkov
  Cc: Alim Akhtar, Avri Altman, Bart Van Assche, James E.J. Bottomley,
	Martin K. Petersen, Bean Huo, Can Guo, linux-scsi, linux-kernel,
	stable


Alexey,

> Older UFS spec devices (2.2 and earlier) do not expose per-region RPMB
> sizes, as only one RPMB region is supported. In such cases, the size
> of the single RPMB region can be deduced from the Logical Block Count
> and Logical Block Size fields in the RPMB Unit Descriptor.

Applied to 7.0/scsi-staging, thanks!

-- 
Martin K. Petersen

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] scsi: ufs: core: Fix RPMB region size detection for UFS 2.2
  2026-02-09 15:17 [PATCH v3] scsi: ufs: core: Fix RPMB region size detection for UFS 2.2 Alexey Charkov
  2026-02-18  2:16 ` Martin K. Petersen
@ 2026-02-24 16:47 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: Martin K. Petersen @ 2026-02-24 16:47 UTC (permalink / raw)
  To: Alim Akhtar, Avri Altman, Bart Van Assche, James E.J. Bottomley,
	Bean Huo, Can Guo, Alexey Charkov
  Cc: Martin K . Petersen, linux-scsi, linux-kernel, stable

On Mon, 09 Feb 2026 19:17:34 +0400, Alexey Charkov wrote:

> Older UFS spec devices (2.2 and earlier) do not expose per-region RPMB
> sizes, as only one RPMB region is supported. In such cases, the size of
> the single RPMB region can be deduced from the Logical Block Count and
> Logical Block Size fields in the RPMB Unit Descriptor.
> 
> Add a fallback mechanism to calculate the RPMB region size from these
> fields if the device implements an older spec, so that the RPMB driver
> can work with such devices - otherwise it silently skips the whole RPMB.
> 
> [...]

Applied to 7.0/scsi-fixes, thanks!

[1/1] scsi: ufs: core: Fix RPMB region size detection for UFS 2.2
      https://git.kernel.org/mkp/scsi/c/2e6b5cd6a4b3

-- 
Martin K. Petersen

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-02-24 16:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-09 15:17 [PATCH v3] scsi: ufs: core: Fix RPMB region size detection for UFS 2.2 Alexey Charkov
2026-02-18  2:16 ` Martin K. Petersen
2026-02-24 16:47 ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®