Add advanced RPMB support in ufs_bsg: 1. According to the UFS specification, only one RPMB operation can be performed at any time. We can ensure this by using reserved slot and its dev_cmd sync operation protection mechanism. 2. For Advanced RPMB, RPMB metadata is packaged in an EHS (Extra Header Segment) of a command UPIU, and the corresponding reply EHS (from the device) should also be returned to the user space. bsg_job->request and bsg_job->reply allow us to pass and return EHS from/back to userspace. Compared to normal/legacy RPMB, the advantages of advanced RPMB are: 1. The data length in the Advanced RPMB data read/write command can be larger than 4KB. For the legacy RPMB, the data length in a single RPMB data transfer is 256 bytes. 2. All of the advanced RPMB operations will be a single command. For legacy RPMB, take the read write-counter value as an example, you need two commands (first SECURITY PROTOCOL OUT, then second SECURITY PROTOCOL IN).
Showing the changes to include/uapi (1 of 6 files). Show all
Unified · Split
| @@ -14,10 +14,27 @@ · 13 unmodified lines | |||
| 14 | */ | 14 | */ |
| 15 | 15 | ||
| 16 | #define UFS_CDB_SIZE 16 | 16 | #define UFS_CDB_SIZE 16 |
| 17 | #define UPIU_TRANSACTION_UIC_CMD 0x1F | ||
| 18 | /* uic commands are 4DW long, per UFSHCI V2.1 paragraph 5.6.1 */ | 17 | /* uic commands are 4DW long, per UFSHCI V2.1 paragraph 5.6.1 */ |
| 19 | #define UIC_CMD_SIZE (sizeof(__u32) * 4) | 18 | #define UIC_CMD_SIZE (sizeof(__u32) * 4) |
| 20 | 19 | ||
| 20 | enum ufs_bsg_msg_code { | ||
| 21 | UPIU_TRANSACTION_UIC_CMD = 0x1F, | ||
| 22 | UPIU_TRANSACTION_ARPMB_CMD, | ||
| 23 | }; | ||
| 24 | |||
| 25 | /* UFS RPMB Request Message Types */ | ||
| 26 | enum ufs_rpmb_op_type { | ||
| 27 | UFS_RPMB_WRITE_KEY = 0x01, | ||
| 28 | UFS_RPMB_READ_CNT = 0x02, | ||
| 29 | UFS_RPMB_WRITE = 0x03, | ||
| 30 | UFS_RPMB_READ = 0x04, | ||
| 31 | UFS_RPMB_READ_RESP = 0x05, | ||
| 32 | UFS_RPMB_SEC_CONF_WRITE = 0x06, | ||
| 33 | UFS_RPMB_SEC_CONF_READ = 0x07, | ||
| 34 | UFS_RPMB_PURGE_ENABLE = 0x08, | ||
| 35 | UFS_RPMB_PURGE_STATUS_READ = 0x09, | ||
| 36 | }; | ||
| 37 | |||
| 21 | /** | 38 | /** |
| 22 | * struct utp_upiu_header - UPIU header structure | 39 | * struct utp_upiu_header - UPIU header structure |
| 23 | * @dword_0: UPIU header DW-0 | 40 | * @dword_0: UPIU header DW-0 |
| @@ -79,6 +96,23 @@ struct utp_upiu_req { · 55 unmodified lines | |||
| 79 | }; | 96 | }; |
| 80 | }; | 97 | }; |
| 81 | 98 | ||
| 99 | struct ufs_arpmb_meta { | ||
| 100 | __u16 req_resp_type; | ||
| 101 | __u8 nonce[16]; | ||
| 102 | __u32 write_counter; | ||
| 103 | __u16 addr_lun; | ||
| 104 | __u16 block_count; | ||
| 105 | __u16 result; | ||
| 106 | } __attribute__((__packed__)); | ||
| 107 | |||
| 108 | struct ufs_ehs { | ||
| 109 | __u8 length; | ||
| 110 | __u8 ehs_type; | ||
| 111 | __u16 ehssub_type; | ||
| 112 | struct ufs_arpmb_meta meta; | ||
| 113 | __u8 mac_key[32]; | ||
| 114 | } __attribute__((__packed__)); | ||
| 115 | |||
| 82 | /* request (CDB) structure of the sg_io_v4 */ | 116 | /* request (CDB) structure of the sg_io_v4 */ |
| 83 | struct ufs_bsg_request { | 117 | struct ufs_bsg_request { |
| 84 | __u32 msgcode; | 118 | __u32 msgcode; |
| @@ -102,4 +136,14 @@ struct ufs_bsg_reply { · 17 unmodified lines | |||
| 102 | 136 | ||
| 103 | struct utp_upiu_req upiu_rsp; | 137 | struct utp_upiu_req upiu_rsp; |
| 104 | }; | 138 | }; |
| 139 | |||
| 140 | struct ufs_rpmb_request { | ||
| 141 | struct ufs_bsg_request bsg_request; | ||
| 142 | struct ufs_ehs ehs_req; | ||
| 143 | }; | ||
| 144 | |||
| 145 | struct ufs_rpmb_reply { | ||
| 146 | struct ufs_bsg_reply bsg_reply; | ||
| 147 | struct ufs_ehs ehs_rsp; | ||
| 148 | }; | ||
| 105 | #endif /* UFS_BSG_H */ | 149 | #endif /* UFS_BSG_H */ |