scsi_bsg_ufs.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 <linux/types.h>
  11. /*
  12. * This file intended to be included by both kernel and user space
  13. */
  14. #define UFS_CDB_SIZE 16
  15. /* uic commands are 4DW long, per UFSHCI V2.1 paragraph 5.6.1 */
  16. #define UIC_CMD_SIZE (sizeof(__u32) * 4)
  17. enum ufs_bsg_msg_code {
  18. UPIU_TRANSACTION_UIC_CMD = 0x1F,
  19. UPIU_TRANSACTION_ARPMB_CMD,
  20. };
  21. /* UFS RPMB Request Message Types */
  22. enum ufs_rpmb_op_type {
  23. UFS_RPMB_WRITE_KEY = 0x01,
  24. UFS_RPMB_READ_CNT = 0x02,
  25. UFS_RPMB_WRITE = 0x03,
  26. UFS_RPMB_READ = 0x04,
  27. UFS_RPMB_READ_RESP = 0x05,
  28. UFS_RPMB_SEC_CONF_WRITE = 0x06,
  29. UFS_RPMB_SEC_CONF_READ = 0x07,
  30. UFS_RPMB_PURGE_ENABLE = 0x08,
  31. UFS_RPMB_PURGE_STATUS_READ = 0x09,
  32. };
  33. /**
  34. * struct utp_upiu_header - UPIU header structure
  35. * @dword_0: UPIU header DW-0
  36. * @dword_1: UPIU header DW-1
  37. * @dword_2: UPIU header DW-2
  38. */
  39. struct utp_upiu_header {
  40. __be32 dword_0;
  41. __be32 dword_1;
  42. __be32 dword_2;
  43. };
  44. /**
  45. * struct utp_upiu_query - upiu request buffer structure for
  46. * query request.
  47. * @opcode: command to perform B-0
  48. * @idn: a value that indicates the particular type of data B-1
  49. * @index: Index to further identify data B-2
  50. * @selector: Index to further identify data B-3
  51. * @reserved_osf: spec reserved field B-4,5
  52. * @length: number of descriptor bytes to read/write B-6,7
  53. * @value: Attribute value to be written DW-5
  54. * @reserved: spec reserved DW-6,7
  55. */
  56. struct utp_upiu_query {
  57. __u8 opcode;
  58. __u8 idn;
  59. __u8 index;
  60. __u8 selector;
  61. __be16 reserved_osf;
  62. __be16 length;
  63. __be32 value;
  64. __be32 reserved[2];
  65. };
  66. /**
  67. * struct utp_upiu_query_v4_0 - upiu request buffer structure for
  68. * query request >= UFS 4.0 spec.
  69. * @opcode: command to perform B-0
  70. * @idn: a value that indicates the particular type of data B-1
  71. * @index: Index to further identify data B-2
  72. * @selector: Index to further identify data B-3
  73. * @osf4: spec field B-5
  74. * @osf5: spec field B 6,7
  75. * @osf6: spec field DW 8,9
  76. * @osf7: spec field DW 10,11
  77. */
  78. struct utp_upiu_query_v4_0 {
  79. __u8 opcode;
  80. __u8 idn;
  81. __u8 index;
  82. __u8 selector;
  83. __u8 osf3;
  84. __u8 osf4;
  85. __be16 osf5;
  86. __be32 osf6;
  87. __be32 osf7;
  88. __be32 reserved;
  89. };
  90. /**
  91. * struct utp_upiu_cmd - Command UPIU structure
  92. * @data_transfer_len: Data Transfer Length DW-3
  93. * @cdb: Command Descriptor Block CDB DW-4 to DW-7
  94. */
  95. struct utp_upiu_cmd {
  96. __be32 exp_data_transfer_len;
  97. __u8 cdb[UFS_CDB_SIZE];
  98. };
  99. /**
  100. * struct utp_upiu_req - general upiu request structure
  101. * @header:UPIU header structure DW-0 to DW-2
  102. * @sc: fields structure for scsi command DW-3 to DW-7
  103. * @qr: fields structure for query request DW-3 to DW-7
  104. * @uc: use utp_upiu_query to host the 4 dwords of uic command
  105. */
  106. struct utp_upiu_req {
  107. struct utp_upiu_header header;
  108. union {
  109. struct utp_upiu_cmd sc;
  110. struct utp_upiu_query qr;
  111. struct utp_upiu_query uc;
  112. };
  113. };
  114. struct ufs_arpmb_meta {
  115. __be16 req_resp_type;
  116. __u8 nonce[16];
  117. __be32 write_counter;
  118. __be16 addr_lun;
  119. __be16 block_count;
  120. __be16 result;
  121. } __attribute__((__packed__));
  122. struct ufs_ehs {
  123. __u8 length;
  124. __u8 ehs_type;
  125. __be16 ehssub_type;
  126. struct ufs_arpmb_meta meta;
  127. __u8 mac_key[32];
  128. } __attribute__((__packed__));
  129. /* request (CDB) structure of the sg_io_v4 */
  130. struct ufs_bsg_request {
  131. __u32 msgcode;
  132. struct utp_upiu_req upiu_req;
  133. };
  134. /* response (request sense data) structure of the sg_io_v4 */
  135. struct ufs_bsg_reply {
  136. /*
  137. * The completion result. Result exists in two forms:
  138. * if negative, it is an -Exxx system errno value. There will
  139. * be no further reply information supplied.
  140. * else, it's the 4-byte scsi error result, with driver, host,
  141. * msg and status fields. The per-msgcode reply structure
  142. * will contain valid data.
  143. */
  144. int result;
  145. /* If there was reply_payload, how much was received? */
  146. __u32 reply_payload_rcv_len;
  147. struct utp_upiu_req upiu_rsp;
  148. };
  149. struct ufs_rpmb_request {
  150. struct ufs_bsg_request bsg_request;
  151. struct ufs_ehs ehs_req;
  152. };
  153. struct ufs_rpmb_reply {
  154. struct ufs_bsg_reply bsg_reply;
  155. struct ufs_ehs ehs_rsp;
  156. };
  157. #endif /* UFS_BSG_H */