ufs.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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. QUERY_FLAG_IDN_BKOPS_EN = 0x04,
  99. };
  100. /* Attribute idn for Query requests */
  101. enum attr_idn {
  102. QUERY_ATTR_IDN_BKOPS_STATUS = 0x05,
  103. QUERY_ATTR_IDN_EE_CONTROL = 0x0D,
  104. QUERY_ATTR_IDN_EE_STATUS = 0x0E,
  105. };
  106. /* Exception event mask values */
  107. enum {
  108. MASK_EE_STATUS = 0xFFFF,
  109. MASK_EE_URGENT_BKOPS = (1 << 2),
  110. };
  111. /* Background operation status */
  112. enum {
  113. BKOPS_STATUS_NO_OP = 0x0,
  114. BKOPS_STATUS_NON_CRITICAL = 0x1,
  115. BKOPS_STATUS_PERF_IMPACT = 0x2,
  116. BKOPS_STATUS_CRITICAL = 0x3,
  117. };
  118. /* UTP QUERY Transaction Specific Fields OpCode */
  119. enum query_opcode {
  120. UPIU_QUERY_OPCODE_NOP = 0x0,
  121. UPIU_QUERY_OPCODE_READ_DESC = 0x1,
  122. UPIU_QUERY_OPCODE_WRITE_DESC = 0x2,
  123. UPIU_QUERY_OPCODE_READ_ATTR = 0x3,
  124. UPIU_QUERY_OPCODE_WRITE_ATTR = 0x4,
  125. UPIU_QUERY_OPCODE_READ_FLAG = 0x5,
  126. UPIU_QUERY_OPCODE_SET_FLAG = 0x6,
  127. UPIU_QUERY_OPCODE_CLEAR_FLAG = 0x7,
  128. UPIU_QUERY_OPCODE_TOGGLE_FLAG = 0x8,
  129. };
  130. /* Query response result code */
  131. enum {
  132. QUERY_RESULT_SUCCESS = 0x00,
  133. QUERY_RESULT_NOT_READABLE = 0xF6,
  134. QUERY_RESULT_NOT_WRITEABLE = 0xF7,
  135. QUERY_RESULT_ALREADY_WRITTEN = 0xF8,
  136. QUERY_RESULT_INVALID_LENGTH = 0xF9,
  137. QUERY_RESULT_INVALID_VALUE = 0xFA,
  138. QUERY_RESULT_INVALID_SELECTOR = 0xFB,
  139. QUERY_RESULT_INVALID_INDEX = 0xFC,
  140. QUERY_RESULT_INVALID_IDN = 0xFD,
  141. QUERY_RESULT_INVALID_OPCODE = 0xFE,
  142. QUERY_RESULT_GENERAL_FAILURE = 0xFF,
  143. };
  144. /* UTP Transfer Request Command Type (CT) */
  145. enum {
  146. UPIU_COMMAND_SET_TYPE_SCSI = 0x0,
  147. UPIU_COMMAND_SET_TYPE_UFS = 0x1,
  148. UPIU_COMMAND_SET_TYPE_QUERY = 0x2,
  149. };
  150. /* UTP Transfer Request Command Offset */
  151. #define UPIU_COMMAND_TYPE_OFFSET 28
  152. /* Offset of the response code in the UPIU header */
  153. #define UPIU_RSP_CODE_OFFSET 8
  154. enum {
  155. MASK_SCSI_STATUS = 0xFF,
  156. MASK_TASK_RESPONSE = 0xFF00,
  157. MASK_RSP_UPIU_RESULT = 0xFFFF,
  158. MASK_QUERY_DATA_SEG_LEN = 0xFFFF,
  159. MASK_RSP_UPIU_DATA_SEG_LEN = 0xFFFF,
  160. MASK_RSP_EXCEPTION_EVENT = 0x10000,
  161. };
  162. /* Task management service response */
  163. enum {
  164. UPIU_TASK_MANAGEMENT_FUNC_COMPL = 0x00,
  165. UPIU_TASK_MANAGEMENT_FUNC_NOT_SUPPORTED = 0x04,
  166. UPIU_TASK_MANAGEMENT_FUNC_SUCCEEDED = 0x08,
  167. UPIU_TASK_MANAGEMENT_FUNC_FAILED = 0x05,
  168. UPIU_INCORRECT_LOGICAL_UNIT_NO = 0x09,
  169. };
  170. /**
  171. * struct utp_upiu_header - UPIU header structure
  172. * @dword_0: UPIU header DW-0
  173. * @dword_1: UPIU header DW-1
  174. * @dword_2: UPIU header DW-2
  175. */
  176. struct utp_upiu_header {
  177. u32 dword_0;
  178. u32 dword_1;
  179. u32 dword_2;
  180. };
  181. /**
  182. * struct utp_upiu_cmd - Command UPIU structure
  183. * @data_transfer_len: Data Transfer Length DW-3
  184. * @cdb: Command Descriptor Block CDB DW-4 to DW-7
  185. */
  186. struct utp_upiu_cmd {
  187. u32 exp_data_transfer_len;
  188. u8 cdb[MAX_CDB_SIZE];
  189. };
  190. /**
  191. * struct utp_upiu_query - upiu request buffer structure for
  192. * query request.
  193. * @opcode: command to perform B-0
  194. * @idn: a value that indicates the particular type of data B-1
  195. * @index: Index to further identify data B-2
  196. * @selector: Index to further identify data B-3
  197. * @reserved_osf: spec reserved field B-4,5
  198. * @length: number of descriptor bytes to read/write B-6,7
  199. * @value: Attribute value to be written DW-5
  200. * @reserved: spec reserved DW-6,7
  201. */
  202. struct utp_upiu_query {
  203. u8 opcode;
  204. u8 idn;
  205. u8 index;
  206. u8 selector;
  207. u16 reserved_osf;
  208. u16 length;
  209. u32 value;
  210. u32 reserved[2];
  211. };
  212. /**
  213. * struct utp_upiu_req - general upiu request structure
  214. * @header:UPIU header structure DW-0 to DW-2
  215. * @sc: fields structure for scsi command DW-3 to DW-7
  216. * @qr: fields structure for query request DW-3 to DW-7
  217. */
  218. struct utp_upiu_req {
  219. struct utp_upiu_header header;
  220. union {
  221. struct utp_upiu_cmd sc;
  222. struct utp_upiu_query qr;
  223. };
  224. };
  225. /**
  226. * struct utp_cmd_rsp - Response UPIU structure
  227. * @residual_transfer_count: Residual transfer count DW-3
  228. * @reserved: Reserved double words DW-4 to DW-7
  229. * @sense_data_len: Sense data length DW-8 U16
  230. * @sense_data: Sense data field DW-8 to DW-12
  231. */
  232. struct utp_cmd_rsp {
  233. u32 residual_transfer_count;
  234. u32 reserved[4];
  235. u16 sense_data_len;
  236. u8 sense_data[18];
  237. };
  238. /**
  239. * struct utp_upiu_rsp - general upiu response structure
  240. * @header: UPIU header structure DW-0 to DW-2
  241. * @sr: fields structure for scsi command DW-3 to DW-12
  242. * @qr: fields structure for query request DW-3 to DW-7
  243. */
  244. struct utp_upiu_rsp {
  245. struct utp_upiu_header header;
  246. union {
  247. struct utp_cmd_rsp sr;
  248. struct utp_upiu_query qr;
  249. };
  250. };
  251. /**
  252. * struct utp_upiu_task_req - Task request UPIU structure
  253. * @header - UPIU header structure DW0 to DW-2
  254. * @input_param1: Input parameter 1 DW-3
  255. * @input_param2: Input parameter 2 DW-4
  256. * @input_param3: Input parameter 3 DW-5
  257. * @reserved: Reserved double words DW-6 to DW-7
  258. */
  259. struct utp_upiu_task_req {
  260. struct utp_upiu_header header;
  261. u32 input_param1;
  262. u32 input_param2;
  263. u32 input_param3;
  264. u32 reserved[2];
  265. };
  266. /**
  267. * struct utp_upiu_task_rsp - Task Management Response UPIU structure
  268. * @header: UPIU header structure DW0-DW-2
  269. * @output_param1: Ouput parameter 1 DW3
  270. * @output_param2: Output parameter 2 DW4
  271. * @reserved: Reserved double words DW-5 to DW-7
  272. */
  273. struct utp_upiu_task_rsp {
  274. struct utp_upiu_header header;
  275. u32 output_param1;
  276. u32 output_param2;
  277. u32 reserved[3];
  278. };
  279. /**
  280. * struct ufs_query_req - parameters for building a query request
  281. * @query_func: UPIU header query function
  282. * @upiu_req: the query request data
  283. */
  284. struct ufs_query_req {
  285. u8 query_func;
  286. struct utp_upiu_query upiu_req;
  287. };
  288. /**
  289. * struct ufs_query_resp - UPIU QUERY
  290. * @response: device response code
  291. * @upiu_res: query response data
  292. */
  293. struct ufs_query_res {
  294. u8 response;
  295. struct utp_upiu_query upiu_res;
  296. };
  297. #endif /* End of Header */