Skip to content

Commit 2e6b5cd

Browse files
alcharkmartinkpetersen
authored andcommitted
scsi: ufs: core: Fix RPMB region size detection for UFS 2.2
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: b06b8c4 ("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> Link: https://patch.msgid.link/20260209-ufs-rpmb-v3-1-b1804e71bd38@flipper.net Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 5729773 commit 2e6b5cd

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

drivers/ufs/core/ufshcd.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/pm_opp.h>
2424
#include <linux/regulator/consumer.h>
2525
#include <linux/sched/clock.h>
26+
#include <linux/sizes.h>
2627
#include <linux/iopoll.h>
2728
#include <scsi/scsi_cmnd.h>
2829
#include <scsi/scsi_dbg.h>
@@ -5248,6 +5249,25 @@ static void ufshcd_lu_init(struct ufs_hba *hba, struct scsi_device *sdev)
52485249
hba->dev_info.rpmb_region_size[1] = desc_buf[RPMB_UNIT_DESC_PARAM_REGION1_SIZE];
52495250
hba->dev_info.rpmb_region_size[2] = desc_buf[RPMB_UNIT_DESC_PARAM_REGION2_SIZE];
52505251
hba->dev_info.rpmb_region_size[3] = desc_buf[RPMB_UNIT_DESC_PARAM_REGION3_SIZE];
5252+
5253+
if (hba->dev_info.wspecversion <= 0x0220) {
5254+
/*
5255+
* These older spec chips have only one RPMB region,
5256+
* sized between 128 kB minimum and 16 MB maximum.
5257+
* No per region size fields are provided (respective
5258+
* REGIONX_SIZE fields always contain zeros), so get
5259+
* it from the logical block count and size fields for
5260+
* compatibility
5261+
*
5262+
* (See JESD220C-2_2 Section 14.1.4.6
5263+
* RPMB Unit Descriptor,* offset 13h, 4 bytes)
5264+
*/
5265+
hba->dev_info.rpmb_region_size[0] =
5266+
(get_unaligned_be64(desc_buf
5267+
+ RPMB_UNIT_DESC_PARAM_LOGICAL_BLK_COUNT)
5268+
<< desc_buf[RPMB_UNIT_DESC_PARAM_LOGICAL_BLK_SIZE])
5269+
/ SZ_128K;
5270+
}
52515271
}
52525272

52535273

0 commit comments

Comments
 (0)