scsi_bsg_ufs.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 - QUERY REQUEST UPIU structure.
  92. * @opcode: query function to perform B-0
  93. * @idn: descriptor or attribute identification number B-1
  94. * @index: Index that further identifies which data to access B-2
  95. * @selector: Index that further identifies which data to access B-3
  96. * @reserved_osf: spec reserved field B-4,5
  97. * @length: number of descriptor bytes to read or write B-6,7
  98. * @value: if @opcode == UPIU_QUERY_OPCODE_WRITE_ATTR, the value to be written B-6,7
  99. * @reserved: reserved for future use DW-6,7
  100. */
  101. struct utp_upiu_query {
  102. __u8 opcode;
  103. __u8 idn;
  104. __u8 index;
  105. __u8 selector;
  106. __be16 reserved_osf;
  107. __be16 length;
  108. __be32 value;
  109. __be32 reserved[2];
  110. };
  111. /**
  112. * struct utp_upiu_query_v4_0 - upiu request buffer structure for
  113. * query request >= UFS 4.0 spec.
  114. * @opcode: command to perform B-0
  115. * @idn: a value that indicates the particular type of data B-1
  116. * @index: Index to further identify data B-2
  117. * @selector: Index to further identify data B-3
  118. * @osf3: spec field B-4
  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. /* private: */
  135. __be32 reserved;
  136. };
  137. /**
  138. * struct utp_upiu_cmd - Command UPIU structure
  139. * @exp_data_transfer_len: Data Transfer Length DW-3
  140. * @cdb: Command Descriptor Block CDB DW-4 to DW-7
  141. */
  142. struct utp_upiu_cmd {
  143. __be32 exp_data_transfer_len;
  144. __u8 cdb[UFS_CDB_SIZE];
  145. };
  146. /**
  147. * struct utp_upiu_req - general upiu request structure
  148. * @header:UPIU header structure DW-0 to DW-2
  149. * @sc: fields structure for scsi command DW-3 to DW-7
  150. * @qr: fields structure for query request DW-3 to DW-7
  151. * @uc: use utp_upiu_query to host the 4 dwords of uic command
  152. */
  153. struct utp_upiu_req {
  154. struct utp_upiu_header header;
  155. union {
  156. struct utp_upiu_cmd sc;
  157. struct utp_upiu_query qr;
  158. struct utp_upiu_query uc;
  159. };
  160. };
  161. struct ufs_arpmb_meta {
  162. __be16 req_resp_type;
  163. __u8 nonce[16];
  164. __be32 write_counter;
  165. __be16 addr_lun;
  166. __be16 block_count;
  167. __be16 result;
  168. } __attribute__((__packed__));
  169. struct ufs_ehs {
  170. __u8 length;
  171. __u8 ehs_type;
  172. __be16 ehssub_type;
  173. struct ufs_arpmb_meta meta;
  174. __u8 mac_key[32];
  175. } __attribute__((__packed__));
  176. /* request (CDB) structure of the sg_io_v4 */
  177. struct ufs_bsg_request {
  178. __u32 msgcode;
  179. struct utp_upiu_req upiu_req;
  180. };
  181. /* response (request sense data) structure of the sg_io_v4 */
  182. struct ufs_bsg_reply {
  183. /*
  184. * The completion result. Result exists in two forms:
  185. * if negative, it is an -Exxx system errno value. There will
  186. * be no further reply information supplied.
  187. * else, it's the 4-byte scsi error result, with driver, host,
  188. * msg and status fields. The per-msgcode reply structure
  189. * will contain valid data.
  190. */
  191. int result;
  192. /* If there was reply_payload, how much was received? */
  193. __u32 reply_payload_rcv_len;
  194. struct utp_upiu_req upiu_rsp;
  195. };
  196. struct ufs_rpmb_request {
  197. struct ufs_bsg_request bsg_request;
  198. struct ufs_ehs ehs_req;
  199. };
  200. struct ufs_rpmb_reply {
  201. struct ufs_bsg_reply bsg_reply;
  202. struct ufs_ehs ehs_rsp;
  203. };
  204. #endif /* UFS_BSG_H */