scsi_bsg_ufs.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. /*
  3. * UFS Transport SGIO v4 BSG Message Support
  4. *
  5. * Copyright (C) 2011-2013 Samsung India Software Operations
  6. * Copyright (C) 2018 Western Digital Corporation
  7. */
  8. #ifndef SCSI_BSG_UFS_H
  9. #define SCSI_BSG_UFS_H
  10. #include <asm/byteorder.h>
  11. #include <linux/types.h>
  12. /*
  13. * This file intended to be included by both kernel and user space
  14. */
  15. #define UFS_CDB_SIZE 16
  16. /* uic commands are 4DW long, per UFSHCI V2.1 paragraph 5.6.1 */
  17. #define UIC_CMD_SIZE (sizeof(__u32) * 4)
  18. enum ufs_bsg_msg_code {
  19. UPIU_TRANSACTION_UIC_CMD = 0x1F,
  20. UPIU_TRANSACTION_ARPMB_CMD,
  21. };
  22. /* UFS RPMB Request Message Types */
  23. enum ufs_rpmb_op_type {
  24. UFS_RPMB_WRITE_KEY = 0x01,
  25. UFS_RPMB_READ_CNT = 0x02,
  26. UFS_RPMB_WRITE = 0x03,
  27. UFS_RPMB_READ = 0x04,
  28. UFS_RPMB_READ_RESP = 0x05,
  29. UFS_RPMB_SEC_CONF_WRITE = 0x06,
  30. UFS_RPMB_SEC_CONF_READ = 0x07,
  31. UFS_RPMB_PURGE_ENABLE = 0x08,
  32. UFS_RPMB_PURGE_STATUS_READ = 0x09,
  33. };
  34. /**
  35. * struct utp_upiu_header - UPIU header structure
  36. * @dword_0: UPIU header DW-0
  37. * @dword_1: UPIU header DW-1
  38. * @dword_2: UPIU header DW-2
  39. *
  40. * @transaction_code: Type of request or response. See also enum
  41. * upiu_request_transaction and enum upiu_response_transaction.
  42. * @flags: UPIU flags. The meaning of individual flags depends on the
  43. * transaction code.
  44. * @lun: Logical unit number.
  45. * @task_tag: Task tag.
  46. * @iid: Initiator ID.
  47. * @command_set_type: 0 for SCSI command set; 1 for UFS specific.
  48. * @tm_function: Task management function in case of a task management request
  49. * UPIU.
  50. * @query_function: Query function in case of a query request UPIU.
  51. * @response: 0 for success; 1 for failure.
  52. * @status: SCSI status if this is the header of a response to a SCSI command.
  53. * @ehs_length: EHS length in units of 32 bytes.
  54. * @device_information:
  55. * @data_segment_length: data segment length.
  56. */
  57. struct utp_upiu_header {
  58. union {
  59. struct {
  60. __be32 dword_0;
  61. __be32 dword_1;
  62. __be32 dword_2;
  63. };
  64. struct {
  65. __u8 transaction_code;
  66. __u8 flags;
  67. __u8 lun;
  68. __u8 task_tag;
  69. #if defined(__BIG_ENDIAN)
  70. __u8 iid: 4;
  71. __u8 command_set_type: 4;
  72. #elif defined(__LITTLE_ENDIAN)
  73. __u8 command_set_type: 4;
  74. __u8 iid: 4;
  75. #else
  76. #error
  77. #endif
  78. union {
  79. __u8 tm_function;
  80. __u8 query_function;
  81. } __attribute__((packed));
  82. __u8 response;
  83. __u8 status;
  84. __u8 ehs_length;
  85. __u8 device_information;
  86. __be16 data_segment_length;
  87. };
  88. };
  89. };
  90. /**
  91. * struct utp_upiu_query - upiu request buffer structure for
  92. * query request.
  93. * @opcode: command to perform B-0
  94. * @idn: a value that indicates the particular type of data B-1
  95. * @index: Index to further identify data B-2
  96. * @selector: Index to further identify data B-3
  97. * @reserved_osf: spec reserved field B-4,5
  98. * @length: number of descriptor bytes to read/write B-6,7
  99. * @value: Attribute value to be written DW-5
  100. * @reserved: spec reserved DW-6,7
  101. */
  102. struct utp_upiu_query {
  103. __u8 opcode;
  104. __u8 idn;
  105. __u8 index;
  106. __u8 selector;
  107. __be16 reserved_osf;
  108. __be16 length;
  109. __be32 value;
  110. __be32 reserved[2];
  111. };
  112. /**
  113. * struct utp_upiu_query_v4_0 - upiu request buffer structure for
  114. * query request >= UFS 4.0 spec.
  115. * @opcode: command to perform B-0
  116. * @idn: a value that indicates the particular type of data B-1
  117. * @index: Index to further identify data B-2
  118. * @selector: Index to further identify data B-3
  119. * @osf4: spec field B-5
  120. * @osf5: spec field B 6,7
  121. * @osf6: spec field DW 8,9
  122. * @osf7: spec field DW 10,11
  123. */
  124. struct utp_upiu_query_v4_0 {
  125. __u8 opcode;
  126. __u8 idn;
  127. __u8 index;
  128. __u8 selector;
  129. __u8 osf3;
  130. __u8 osf4;
  131. __be16 osf5;
  132. __be32 osf6;
  133. __be32 osf7;
  134. __be32 reserved;
  135. };
  136. /**
  137. * struct utp_upiu_cmd - Command UPIU structure
  138. * @data_transfer_len: Data Transfer Length DW-3
  139. * @cdb: Command Descriptor Block CDB DW-4 to DW-7
  140. */
  141. struct utp_upiu_cmd {
  142. __be32 exp_data_transfer_len;
  143. __u8 cdb[UFS_CDB_SIZE];
  144. };
  145. /**
  146. * struct utp_upiu_req - general upiu request structure
  147. * @header:UPIU header structure DW-0 to DW-2
  148. * @sc: fields structure for scsi command DW-3 to DW-7
  149. * @qr: fields structure for query request DW-3 to DW-7
  150. * @uc: use utp_upiu_query to host the 4 dwords of uic command
  151. */
  152. struct utp_upiu_req {
  153. struct utp_upiu_header header;
  154. union {
  155. struct utp_upiu_cmd sc;
  156. struct utp_upiu_query qr;
  157. struct utp_upiu_query uc;
  158. };
  159. };
  160. struct ufs_arpmb_meta {
  161. __be16 req_resp_type;
  162. __u8 nonce[16];
  163. __be32 write_counter;
  164. __be16 addr_lun;
  165. __be16 block_count;
  166. __be16 result;
  167. } __attribute__((__packed__));
  168. struct ufs_ehs {
  169. __u8 length;
  170. __u8 ehs_type;
  171. __be16 ehssub_type;
  172. struct ufs_arpmb_meta meta;
  173. __u8 mac_key[32];
  174. } __attribute__((__packed__));
  175. /* request (CDB) structure of the sg_io_v4 */
  176. struct ufs_bsg_request {
  177. __u32 msgcode;
  178. struct utp_upiu_req upiu_req;
  179. };
  180. /* response (request sense data) structure of the sg_io_v4 */
  181. struct ufs_bsg_reply {
  182. /*
  183. * The completion result. Result exists in two forms:
  184. * if negative, it is an -Exxx system errno value. There will
  185. * be no further reply information supplied.
  186. * else, it's the 4-byte scsi error result, with driver, host,
  187. * msg and status fields. The per-msgcode reply structure
  188. * will contain valid data.
  189. */
  190. int result;
  191. /* If there was reply_payload, how much was received? */
  192. __u32 reply_payload_rcv_len;
  193. struct utp_upiu_req upiu_rsp;
  194. };
  195. struct ufs_rpmb_request {
  196. struct ufs_bsg_request bsg_request;
  197. struct ufs_ehs ehs_req;
  198. };
  199. struct ufs_rpmb_reply {
  200. struct ufs_bsg_reply bsg_reply;
  201. struct ufs_ehs ehs_rsp;
  202. };
  203. #endif /* UFS_BSG_H */