scsi_bsg_ufs.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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_cmd - Command UPIU structure
  68. * @data_transfer_len: Data Transfer Length DW-3
  69. * @cdb: Command Descriptor Block CDB DW-4 to DW-7
  70. */
  71. struct utp_upiu_cmd {
  72. __be32 exp_data_transfer_len;
  73. __u8 cdb[UFS_CDB_SIZE];
  74. };
  75. /**
  76. * struct utp_upiu_req - general upiu request structure
  77. * @header:UPIU header structure DW-0 to DW-2
  78. * @sc: fields structure for scsi command DW-3 to DW-7
  79. * @qr: fields structure for query request DW-3 to DW-7
  80. * @uc: use utp_upiu_query to host the 4 dwords of uic command
  81. */
  82. struct utp_upiu_req {
  83. struct utp_upiu_header header;
  84. union {
  85. struct utp_upiu_cmd sc;
  86. struct utp_upiu_query qr;
  87. struct utp_upiu_query uc;
  88. };
  89. };
  90. struct ufs_arpmb_meta {
  91. __be16 req_resp_type;
  92. __u8 nonce[16];
  93. __be32 write_counter;
  94. __be16 addr_lun;
  95. __be16 block_count;
  96. __be16 result;
  97. } __attribute__((__packed__));
  98. struct ufs_ehs {
  99. __u8 length;
  100. __u8 ehs_type;
  101. __be16 ehssub_type;
  102. struct ufs_arpmb_meta meta;
  103. __u8 mac_key[32];
  104. } __attribute__((__packed__));
  105. /* request (CDB) structure of the sg_io_v4 */
  106. struct ufs_bsg_request {
  107. __u32 msgcode;
  108. struct utp_upiu_req upiu_req;
  109. };
  110. /* response (request sense data) structure of the sg_io_v4 */
  111. struct ufs_bsg_reply {
  112. /*
  113. * The completion result. Result exists in two forms:
  114. * if negative, it is an -Exxx system errno value. There will
  115. * be no further reply information supplied.
  116. * else, it's the 4-byte scsi error result, with driver, host,
  117. * msg and status fields. The per-msgcode reply structure
  118. * will contain valid data.
  119. */
  120. int result;
  121. /* If there was reply_payload, how much was received? */
  122. __u32 reply_payload_rcv_len;
  123. struct utp_upiu_req upiu_rsp;
  124. };
  125. struct ufs_rpmb_request {
  126. struct ufs_bsg_request bsg_request;
  127. struct ufs_ehs ehs_req;
  128. };
  129. struct ufs_rpmb_reply {
  130. struct ufs_bsg_reply bsg_reply;
  131. struct ufs_ehs ehs_rsp;
  132. };
  133. #endif /* UFS_BSG_H */