From: Bean Huo <beanhuo@micron.com>
Move struct rpmb_frame and RPMB operation constants from MMC block
driver to include/linux/rpmb.h for reuse across different RPMB
implementations (UFS, NVMe, etc.).
Signed-off-by: Bean Huo <beanhuo@micron.com>
---
drivers/mmc/core/block.c | 42 --------------------------------------
include/linux/rpmb.h | 44 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+), 42 deletions(-)
diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
index b32eefcca4b7..bd5f6fcb03af 100644
--- a/drivers/mmc/core/block.c
+++ b/drivers/mmc/core/block.c
@@ -79,48 +79,6 @@ MODULE_ALIAS("mmc:block");
#define MMC_EXTRACT_INDEX_FROM_ARG(x) ((x & 0x00FF0000) >> 16)
#define MMC_EXTRACT_VALUE_FROM_ARG(x) ((x & 0x0000FF00) >> 8)
-/**
- * struct rpmb_frame - rpmb frame as defined by eMMC 5.1 (JESD84-B51)
- *
- * @stuff : stuff bytes
- * @key_mac : The authentication key or the message authentication
- * code (MAC) depending on the request/response type.
- * The MAC will be delivered in the last (or the only)
- * block of data.
- * @data : Data to be written or read by signed access.
- * @nonce : Random number generated by the host for the requests
- * and copied to the response by the RPMB engine.
- * @write_counter: Counter value for the total amount of the successful
- * authenticated data write requests made by the host.
- * @addr : Address of the data to be programmed to or read
- * from the RPMB. Address is the serial number of
- * the accessed block (half sector 256B).
- * @block_count : Number of blocks (half sectors, 256B) requested to be
- * read/programmed.
- * @result : Includes information about the status of the write counter
- * (valid, expired) and result of the access made to the RPMB.
- * @req_resp : Defines the type of request and response to/from the memory.
- *
- * The stuff bytes and big-endian properties are modeled to fit to the spec.
- */
-struct rpmb_frame {
- u8 stuff[196];
- u8 key_mac[32];
- u8 data[256];
- u8 nonce[16];
- __be32 write_counter;
- __be16 addr;
- __be16 block_count;
- __be16 result;
- __be16 req_resp;
-} __packed;
-
-#define RPMB_PROGRAM_KEY 0x1 /* Program RPMB Authentication Key */
-#define RPMB_GET_WRITE_COUNTER 0x2 /* Read RPMB write counter */
-#define RPMB_WRITE_DATA 0x3 /* Write data to RPMB partition */
-#define RPMB_READ_DATA 0x4 /* Read data from RPMB partition */
-#define RPMB_RESULT_READ 0x5 /* Read result request (Internal) */
-
#define RPMB_FRAME_SIZE sizeof(struct rpmb_frame)
#define CHECK_SIZE_NEQ(val) ((val) != sizeof(struct rpmb_frame))
#define CHECK_SIZE_ALIGNED(val) IS_ALIGNED((val), sizeof(struct rpmb_frame))
diff --git a/include/linux/rpmb.h b/include/linux/rpmb.h
index cccda73eea4d..ed3f8e431eff 100644
--- a/include/linux/rpmb.h
+++ b/include/linux/rpmb.h
@@ -61,6 +61,50 @@ struct rpmb_dev {
#define to_rpmb_dev(x) container_of((x), struct rpmb_dev, dev)
+/**
+ * struct rpmb_frame - RPMB frame structure for authenticated access
+ *
+ * @stuff : stuff bytes, a padding/reserved area of 196 bytes at the
+ * beginning of the RPMB frame. They don’t carry meaningful
+ * data but are required to make the frame exactly 512 bytes.
+ * @key_mac : The authentication key or the message authentication
+ * code (MAC) depending on the request/response type.
+ * The MAC will be delivered in the last (or the only)
+ * block of data.
+ * @data : Data to be written or read by signed access.
+ * @nonce : Random number generated by the host for the requests
+ * and copied to the response by the RPMB engine.
+ * @write_counter: Counter value for the total amount of the successful
+ * authenticated data write requests made by the host.
+ * @addr : Address of the data to be programmed to or read
+ * from the RPMB. Address is the serial number of
+ * the accessed block (half sector 256B).
+ * @block_count : Number of blocks (half sectors, 256B) requested to be
+ * read/programmed.
+ * @result : Includes information about the status of the write counter
+ * (valid, expired) and result of the access made to the RPMB.
+ * @req_resp : Defines the type of request and response to/from the memory.
+ *
+ * The stuff bytes and big-endian properties are modeled to fit to the spec.
+ */
+struct rpmb_frame {
+ u8 stuff[196];
+ u8 key_mac[32];
+ u8 data[256];
+ u8 nonce[16];
+ __be32 write_counter;
+ __be16 addr;
+ __be16 block_count;
+ __be16 result;
+ __be16 req_resp;
+};
+
+#define RPMB_PROGRAM_KEY 0x1 /* Program RPMB Authentication Key */
+#define RPMB_GET_WRITE_COUNTER 0x2 /* Read RPMB write counter */
+#define RPMB_WRITE_DATA 0x3 /* Write data to RPMB partition */
+#define RPMB_READ_DATA 0x4 /* Read data from RPMB partition */
+#define RPMB_RESULT_READ 0x5 /* Read result request (Internal) */
+
#if IS_ENABLED(CONFIG_RPMB)
struct rpmb_dev *rpmb_dev_get(struct rpmb_dev *rdev);
void rpmb_dev_put(struct rpmb_dev *rdev);
--
2.34.1
On Wed, 1 Oct 2025 at 08:08, Bean Huo <beanhuo@iokpp.de> wrote:
>
> From: Bean Huo <beanhuo@micron.com>
>
> Move struct rpmb_frame and RPMB operation constants from MMC block
> driver to include/linux/rpmb.h for reuse across different RPMB
> implementations (UFS, NVMe, etc.).
>
> Signed-off-by: Bean Huo <beanhuo@micron.com>
I have queued this up via my mmc tree and plan to send a late
pull-request to Linus to get this included for 6.18-rc1.
That should help to land the remaining pieces for ufs in the second
step without having to care about the mmc parts.
Kind regards
Uffe
> ---
> drivers/mmc/core/block.c | 42 --------------------------------------
> include/linux/rpmb.h | 44 ++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 44 insertions(+), 42 deletions(-)
>
> diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
> index b32eefcca4b7..bd5f6fcb03af 100644
> --- a/drivers/mmc/core/block.c
> +++ b/drivers/mmc/core/block.c
> @@ -79,48 +79,6 @@ MODULE_ALIAS("mmc:block");
> #define MMC_EXTRACT_INDEX_FROM_ARG(x) ((x & 0x00FF0000) >> 16)
> #define MMC_EXTRACT_VALUE_FROM_ARG(x) ((x & 0x0000FF00) >> 8)
>
> -/**
> - * struct rpmb_frame - rpmb frame as defined by eMMC 5.1 (JESD84-B51)
> - *
> - * @stuff : stuff bytes
> - * @key_mac : The authentication key or the message authentication
> - * code (MAC) depending on the request/response type.
> - * The MAC will be delivered in the last (or the only)
> - * block of data.
> - * @data : Data to be written or read by signed access.
> - * @nonce : Random number generated by the host for the requests
> - * and copied to the response by the RPMB engine.
> - * @write_counter: Counter value for the total amount of the successful
> - * authenticated data write requests made by the host.
> - * @addr : Address of the data to be programmed to or read
> - * from the RPMB. Address is the serial number of
> - * the accessed block (half sector 256B).
> - * @block_count : Number of blocks (half sectors, 256B) requested to be
> - * read/programmed.
> - * @result : Includes information about the status of the write counter
> - * (valid, expired) and result of the access made to the RPMB.
> - * @req_resp : Defines the type of request and response to/from the memory.
> - *
> - * The stuff bytes and big-endian properties are modeled to fit to the spec.
> - */
> -struct rpmb_frame {
> - u8 stuff[196];
> - u8 key_mac[32];
> - u8 data[256];
> - u8 nonce[16];
> - __be32 write_counter;
> - __be16 addr;
> - __be16 block_count;
> - __be16 result;
> - __be16 req_resp;
> -} __packed;
> -
> -#define RPMB_PROGRAM_KEY 0x1 /* Program RPMB Authentication Key */
> -#define RPMB_GET_WRITE_COUNTER 0x2 /* Read RPMB write counter */
> -#define RPMB_WRITE_DATA 0x3 /* Write data to RPMB partition */
> -#define RPMB_READ_DATA 0x4 /* Read data from RPMB partition */
> -#define RPMB_RESULT_READ 0x5 /* Read result request (Internal) */
> -
> #define RPMB_FRAME_SIZE sizeof(struct rpmb_frame)
> #define CHECK_SIZE_NEQ(val) ((val) != sizeof(struct rpmb_frame))
> #define CHECK_SIZE_ALIGNED(val) IS_ALIGNED((val), sizeof(struct rpmb_frame))
> diff --git a/include/linux/rpmb.h b/include/linux/rpmb.h
> index cccda73eea4d..ed3f8e431eff 100644
> --- a/include/linux/rpmb.h
> +++ b/include/linux/rpmb.h
> @@ -61,6 +61,50 @@ struct rpmb_dev {
>
> #define to_rpmb_dev(x) container_of((x), struct rpmb_dev, dev)
>
> +/**
> + * struct rpmb_frame - RPMB frame structure for authenticated access
> + *
> + * @stuff : stuff bytes, a padding/reserved area of 196 bytes at the
> + * beginning of the RPMB frame. They don’t carry meaningful
> + * data but are required to make the frame exactly 512 bytes.
> + * @key_mac : The authentication key or the message authentication
> + * code (MAC) depending on the request/response type.
> + * The MAC will be delivered in the last (or the only)
> + * block of data.
> + * @data : Data to be written or read by signed access.
> + * @nonce : Random number generated by the host for the requests
> + * and copied to the response by the RPMB engine.
> + * @write_counter: Counter value for the total amount of the successful
> + * authenticated data write requests made by the host.
> + * @addr : Address of the data to be programmed to or read
> + * from the RPMB. Address is the serial number of
> + * the accessed block (half sector 256B).
> + * @block_count : Number of blocks (half sectors, 256B) requested to be
> + * read/programmed.
> + * @result : Includes information about the status of the write counter
> + * (valid, expired) and result of the access made to the RPMB.
> + * @req_resp : Defines the type of request and response to/from the memory.
> + *
> + * The stuff bytes and big-endian properties are modeled to fit to the spec.
> + */
> +struct rpmb_frame {
> + u8 stuff[196];
> + u8 key_mac[32];
> + u8 data[256];
> + u8 nonce[16];
> + __be32 write_counter;
> + __be16 addr;
> + __be16 block_count;
> + __be16 result;
> + __be16 req_resp;
> +};
> +
> +#define RPMB_PROGRAM_KEY 0x1 /* Program RPMB Authentication Key */
> +#define RPMB_GET_WRITE_COUNTER 0x2 /* Read RPMB write counter */
> +#define RPMB_WRITE_DATA 0x3 /* Write data to RPMB partition */
> +#define RPMB_READ_DATA 0x4 /* Read data from RPMB partition */
> +#define RPMB_RESULT_READ 0x5 /* Read result request (Internal) */
> +
> #if IS_ENABLED(CONFIG_RPMB)
> struct rpmb_dev *rpmb_dev_get(struct rpmb_dev *rdev);
> void rpmb_dev_put(struct rpmb_dev *rdev);
> --
> 2.34.1
>
On Mon, 2025-10-06 at 12:21 +0200, Ulf Hansson wrote: > > Signed-off-by: Bean Huo <beanhuo@micron.com> > > I have queued this up via my mmc tree and plan to send a late > pull-request to Linus to get this included for 6.18-rc1. > > That should help to land the remaining pieces for ufs in the second > step without having to care about the mmc parts. > > Kind regards > Uffe thanks Uffe, Kind regards, Bean
On Wed, Oct 1, 2025 at 8:08 AM Bean Huo <beanhuo@iokpp.de> wrote: > > From: Bean Huo <beanhuo@micron.com> > > Move struct rpmb_frame and RPMB operation constants from MMC block > driver to include/linux/rpmb.h for reuse across different RPMB > implementations (UFS, NVMe, etc.). > > Signed-off-by: Bean Huo <beanhuo@micron.com> > --- > drivers/mmc/core/block.c | 42 -------------------------------------- > include/linux/rpmb.h | 44 ++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 44 insertions(+), 42 deletions(-) Acked-by: Jens Wiklander <jens.wiklander@linaro.org> Thanks, Jens
On 9/30/25 11:08 PM, Bean Huo wrote: > Move struct rpmb_frame and RPMB operation constants from MMC block > driver to include/linux/rpmb.h for reuse across different RPMB > implementations (UFS, NVMe, etc.). Reviewed-by: Bart Van Assche <bvanassche@acm.org>
© 2016 - 2026 Red Hat, Inc.