ufs.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /*
  2. * Universal Flash Storage Host controller driver
  3. *
  4. * This code is based on drivers/scsi/ufs/ufs.h
  5. * Copyright (C) 2011-2013 Samsung India Software Operations
  6. *
  7. * Authors:
  8. * Santosh Yaraganavi <santosh.sy@samsung.com>
  9. * Vinayak Holikatti <h.vinayak@samsung.com>
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version 2
  14. * of the License, or (at your option) any later version.
  15. * See the COPYING file in the top-level directory or visit
  16. * <http://www.gnu.org/licenses/gpl-2.0.html>
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * This program is provided "AS IS" and "WITH ALL FAULTS" and
  24. * without warranty of any kind. You are solely responsible for
  25. * determining the appropriateness of using and distributing
  26. * the program and assume all risks associated with your exercise
  27. * of rights with respect to the program, including but not limited
  28. * to infringement of third party rights, the risks and costs of
  29. * program errors, damage to or loss of data, programs or equipment,
  30. * and unavailability or interruption of operations. Under no
  31. * circumstances will the contributor of this Program be liable for
  32. * any damages of any kind arising from your use or distribution of
  33. * this program.
  34. */
  35. #ifndef _UFS_H
  36. #define _UFS_H
  37. #include <linux/mutex.h>
  38. #include <linux/types.h>
  39. #define MAX_CDB_SIZE 16
  40. #define GENERAL_UPIU_REQUEST_SIZE 32
  41. #define QUERY_DESC_MAX_SIZE 256
  42. #define QUERY_OSF_SIZE (GENERAL_UPIU_REQUEST_SIZE - \
  43. (sizeof(struct utp_upiu_header)))
  44. #define UPIU_HEADER_DWORD(byte3, byte2, byte1, byte0)\
  45. cpu_to_be32((byte3 << 24) | (byte2 << 16) |\
  46. (byte1 << 8) | (byte0))
  47. /*
  48. * UFS Protocol Information Unit related definitions
  49. */
  50. /* Task management functions */
  51. enum {
  52. UFS_ABORT_TASK = 0x01,
  53. UFS_ABORT_TASK_SET = 0x02,
  54. UFS_CLEAR_TASK_SET = 0x04,
  55. UFS_LOGICAL_RESET = 0x08,
  56. UFS_QUERY_TASK = 0x80,
  57. UFS_QUERY_TASK_SET = 0x81,
  58. };
  59. /* UTP UPIU Transaction Codes Initiator to Target */
  60. enum {
  61. UPIU_TRANSACTION_NOP_OUT = 0x00,
  62. UPIU_TRANSACTION_COMMAND = 0x01,
  63. UPIU_TRANSACTION_DATA_OUT = 0x02,
  64. UPIU_TRANSACTION_TASK_REQ = 0x04,
  65. UPIU_TRANSACTION_QUERY_REQ = 0x16,
  66. };
  67. /* UTP UPIU Transaction Codes Target to Initiator */
  68. enum {
  69. UPIU_TRANSACTION_NOP_IN = 0x20,
  70. UPIU_TRANSACTION_RESPONSE = 0x21,
  71. UPIU_TRANSACTION_DATA_IN = 0x22,
  72. UPIU_TRANSACTION_TASK_RSP = 0x24,
  73. UPIU_TRANSACTION_READY_XFER = 0x31,
  74. UPIU_TRANSACTION_QUERY_RSP = 0x36,
  75. UPIU_TRANSACTION_REJECT_UPIU = 0x3F,
  76. };
  77. /* UPIU Read/Write flags */
  78. enum {
  79. UPIU_CMD_FLAGS_NONE = 0x00,
  80. UPIU_CMD_FLAGS_WRITE = 0x20,
  81. UPIU_CMD_FLAGS_READ = 0x40,
  82. };
  83. /* UPIU Task Attributes */
  84. enum {
  85. UPIU_TASK_ATTR_SIMPLE = 0x00,
  86. UPIU_TASK_ATTR_ORDERED = 0x01,
  87. UPIU_TASK_ATTR_HEADQ = 0x02,
  88. UPIU_TASK_ATTR_ACA = 0x03,
  89. };
  90. /* UPIU Query request function */
  91. enum {
  92. UPIU_QUERY_FUNC_STANDARD_READ_REQUEST = 0x01,
  93. UPIU_QUERY_FUNC_STANDARD_WRITE_REQUEST = 0x81,
  94. };
  95. /* Flag idn for Query Requests*/
  96. enum flag_idn {
  97. QUERY_FLAG_IDN_FDEVICEINIT = 0x01,
  98. };
  99. /* UTP QUERY Transaction Specific Fields OpCode */
  100. enum query_opcode {
  101. UPIU_QUERY_OPCODE_NOP = 0x0,
  102. UPIU_QUERY_OPCODE_READ_DESC = 0x1,
  103. UPIU_QUERY_OPCODE_WRITE_DESC = 0x2,
  104. UPIU_QUERY_OPCODE_READ_ATTR = 0x3,
  105. UPIU_QUERY_OPCODE_WRITE_ATTR = 0x4,
  106. UPIU_QUERY_OPCODE_READ_FLAG = 0x5,
  107. UPIU_QUERY_OPCODE_SET_FLAG = 0x6,
  108. UPIU_QUERY_OPCODE_CLEAR_FLAG = 0x7,
  109. UPIU_QUERY_OPCODE_TOGGLE_FLAG = 0x8,
  110. };
  111. /* Query response result code */
  112. enum {
  113. QUERY_RESULT_SUCCESS = 0x00,
  114. QUERY_RESULT_NOT_READABLE = 0xF6,
  115. QUERY_RESULT_NOT_WRITEABLE = 0xF7,
  116. QUERY_RESULT_ALREADY_WRITTEN = 0xF8,
  117. QUERY_RESULT_INVALID_LENGTH = 0xF9,
  118. QUERY_RESULT_INVALID_VALUE = 0xFA,
  119. QUERY_RESULT_INVALID_SELECTOR = 0xFB,
  120. QUERY_RESULT_INVALID_INDEX = 0xFC,
  121. QUERY_RESULT_INVALID_IDN = 0xFD,
  122. QUERY_RESULT_INVALID_OPCODE = 0xFE,
  123. QUERY_RESULT_GENERAL_FAILURE = 0xFF,
  124. };
  125. /* UTP Transfer Request Command Type (CT) */
  126. enum {
  127. UPIU_COMMAND_SET_TYPE_SCSI = 0x0,
  128. UPIU_COMMAND_SET_TYPE_UFS = 0x1,
  129. UPIU_COMMAND_SET_TYPE_QUERY = 0x2,
  130. };
  131. /* UTP Transfer Request Command Offset */
  132. #define UPIU_COMMAND_TYPE_OFFSET 28
  133. /* Offset of the response code in the UPIU header */
  134. #define UPIU_RSP_CODE_OFFSET 8
  135. enum {
  136. MASK_SCSI_STATUS = 0xFF,
  137. MASK_TASK_RESPONSE = 0xFF00,
  138. MASK_RSP_UPIU_RESULT = 0xFFFF,
  139. MASK_QUERY_DATA_SEG_LEN = 0xFFFF,
  140. };
  141. /* Task management service response */
  142. enum {
  143. UPIU_TASK_MANAGEMENT_FUNC_COMPL = 0x00,
  144. UPIU_TASK_MANAGEMENT_FUNC_NOT_SUPPORTED = 0x04,
  145. UPIU_TASK_MANAGEMENT_FUNC_SUCCEEDED = 0x08,
  146. UPIU_TASK_MANAGEMENT_FUNC_FAILED = 0x05,
  147. UPIU_INCORRECT_LOGICAL_UNIT_NO = 0x09,
  148. };
  149. /**
  150. * struct utp_upiu_header - UPIU header structure
  151. * @dword_0: UPIU header DW-0
  152. * @dword_1: UPIU header DW-1
  153. * @dword_2: UPIU header DW-2
  154. */
  155. struct utp_upiu_header {
  156. u32 dword_0;
  157. u32 dword_1;
  158. u32 dword_2;
  159. };
  160. /**
  161. * struct utp_upiu_cmd - Command UPIU structure
  162. * @data_transfer_len: Data Transfer Length DW-3
  163. * @cdb: Command Descriptor Block CDB DW-4 to DW-7
  164. */
  165. struct utp_upiu_cmd {
  166. u32 exp_data_transfer_len;
  167. u8 cdb[MAX_CDB_SIZE];
  168. };
  169. /**
  170. * struct utp_upiu_query - upiu request buffer structure for
  171. * query request.
  172. * @opcode: command to perform B-0
  173. * @idn: a value that indicates the particular type of data B-1
  174. * @index: Index to further identify data B-2
  175. * @selector: Index to further identify data B-3
  176. * @reserved_osf: spec reserved field B-4,5
  177. * @length: number of descriptor bytes to read/write B-6,7
  178. * @value: Attribute value to be written DW-5
  179. * @reserved: spec reserved DW-6,7
  180. */
  181. struct utp_upiu_query {
  182. u8 opcode;
  183. u8 idn;
  184. u8 index;
  185. u8 selector;
  186. u16 reserved_osf;
  187. u16 length;
  188. u32 value;
  189. u32 reserved[2];
  190. };
  191. /**
  192. * struct utp_upiu_req - general upiu request structure
  193. * @header:UPIU header structure DW-0 to DW-2
  194. * @sc: fields structure for scsi command DW-3 to DW-7
  195. * @qr: fields structure for query request DW-3 to DW-7
  196. */
  197. struct utp_upiu_req {
  198. struct utp_upiu_header header;
  199. union {
  200. struct utp_upiu_cmd sc;
  201. struct utp_upiu_query qr;
  202. };
  203. };
  204. /**
  205. * struct utp_cmd_rsp - Response UPIU structure
  206. * @residual_transfer_count: Residual transfer count DW-3
  207. * @reserved: Reserved double words DW-4 to DW-7
  208. * @sense_data_len: Sense data length DW-8 U16
  209. * @sense_data: Sense data field DW-8 to DW-12
  210. */
  211. struct utp_cmd_rsp {
  212. u32 residual_transfer_count;
  213. u32 reserved[4];
  214. u16 sense_data_len;
  215. u8 sense_data[18];
  216. };
  217. /**
  218. * struct utp_upiu_rsp - general upiu response structure
  219. * @header: UPIU header structure DW-0 to DW-2
  220. * @sr: fields structure for scsi command DW-3 to DW-12
  221. * @qr: fields structure for query request DW-3 to DW-7
  222. */
  223. struct utp_upiu_rsp {
  224. struct utp_upiu_header header;
  225. union {
  226. struct utp_cmd_rsp sr;
  227. struct utp_upiu_query qr;
  228. };
  229. };
  230. /**
  231. * struct utp_upiu_task_req - Task request UPIU structure
  232. * @header - UPIU header structure DW0 to DW-2
  233. * @input_param1: Input parameter 1 DW-3
  234. * @input_param2: Input parameter 2 DW-4
  235. * @input_param3: Input parameter 3 DW-5
  236. * @reserved: Reserved double words DW-6 to DW-7
  237. */
  238. struct utp_upiu_task_req {
  239. struct utp_upiu_header header;
  240. u32 input_param1;
  241. u32 input_param2;
  242. u32 input_param3;
  243. u32 reserved[2];
  244. };
  245. /**
  246. * struct utp_upiu_task_rsp - Task Management Response UPIU structure
  247. * @header: UPIU header structure DW0-DW-2
  248. * @output_param1: Ouput parameter 1 DW3
  249. * @output_param2: Output parameter 2 DW4
  250. * @reserved: Reserved double words DW-5 to DW-7
  251. */
  252. struct utp_upiu_task_rsp {
  253. struct utp_upiu_header header;
  254. u32 output_param1;
  255. u32 output_param2;
  256. u32 reserved[3];
  257. };
  258. /**
  259. * struct ufs_query_req - parameters for building a query request
  260. * @query_func: UPIU header query function
  261. * @upiu_req: the query request data
  262. */
  263. struct ufs_query_req {
  264. u8 query_func;
  265. struct utp_upiu_query upiu_req;
  266. };
  267. /**
  268. * struct ufs_query_resp - UPIU QUERY
  269. * @response: device response code
  270. * @upiu_res: query response data
  271. */
  272. struct ufs_query_res {
  273. u8 response;
  274. struct utp_upiu_query upiu_res;
  275. };
  276. #endif /* End of Header */