ufshci.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. /*
  2. * Universal Flash Storage Host controller driver
  3. *
  4. * This code is based on drivers/scsi/ufs/ufshci.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 _UFSHCI_H
  36. #define _UFSHCI_H
  37. enum {
  38. TASK_REQ_UPIU_SIZE_DWORDS = 8,
  39. TASK_RSP_UPIU_SIZE_DWORDS = 8,
  40. ALIGNED_UPIU_SIZE = 128,
  41. };
  42. /* UFSHCI Registers */
  43. enum {
  44. REG_CONTROLLER_CAPABILITIES = 0x00,
  45. REG_UFS_VERSION = 0x08,
  46. REG_CONTROLLER_DEV_ID = 0x10,
  47. REG_CONTROLLER_PROD_ID = 0x14,
  48. REG_INTERRUPT_STATUS = 0x20,
  49. REG_INTERRUPT_ENABLE = 0x24,
  50. REG_CONTROLLER_STATUS = 0x30,
  51. REG_CONTROLLER_ENABLE = 0x34,
  52. REG_UIC_ERROR_CODE_PHY_ADAPTER_LAYER = 0x38,
  53. REG_UIC_ERROR_CODE_DATA_LINK_LAYER = 0x3C,
  54. REG_UIC_ERROR_CODE_NETWORK_LAYER = 0x40,
  55. REG_UIC_ERROR_CODE_TRANSPORT_LAYER = 0x44,
  56. REG_UIC_ERROR_CODE_DME = 0x48,
  57. REG_UTP_TRANSFER_REQ_INT_AGG_CONTROL = 0x4C,
  58. REG_UTP_TRANSFER_REQ_LIST_BASE_L = 0x50,
  59. REG_UTP_TRANSFER_REQ_LIST_BASE_H = 0x54,
  60. REG_UTP_TRANSFER_REQ_DOOR_BELL = 0x58,
  61. REG_UTP_TRANSFER_REQ_LIST_CLEAR = 0x5C,
  62. REG_UTP_TRANSFER_REQ_LIST_RUN_STOP = 0x60,
  63. REG_UTP_TASK_REQ_LIST_BASE_L = 0x70,
  64. REG_UTP_TASK_REQ_LIST_BASE_H = 0x74,
  65. REG_UTP_TASK_REQ_DOOR_BELL = 0x78,
  66. REG_UTP_TASK_REQ_LIST_CLEAR = 0x7C,
  67. REG_UTP_TASK_REQ_LIST_RUN_STOP = 0x80,
  68. REG_UIC_COMMAND = 0x90,
  69. REG_UIC_COMMAND_ARG_1 = 0x94,
  70. REG_UIC_COMMAND_ARG_2 = 0x98,
  71. REG_UIC_COMMAND_ARG_3 = 0x9C,
  72. };
  73. /* Controller capability masks */
  74. enum {
  75. MASK_TRANSFER_REQUESTS_SLOTS = 0x0000001F,
  76. MASK_TASK_MANAGEMENT_REQUEST_SLOTS = 0x00070000,
  77. MASK_64_ADDRESSING_SUPPORT = 0x01000000,
  78. MASK_OUT_OF_ORDER_DATA_DELIVERY_SUPPORT = 0x02000000,
  79. MASK_UIC_DME_TEST_MODE_SUPPORT = 0x04000000,
  80. };
  81. /* UFS Version 08h */
  82. #define MINOR_VERSION_NUM_MASK UFS_MASK(0xFFFF, 0)
  83. #define MAJOR_VERSION_NUM_MASK UFS_MASK(0xFFFF, 16)
  84. /* Controller UFSHCI version */
  85. enum {
  86. UFSHCI_VERSION_10 = 0x00010000,
  87. UFSHCI_VERSION_11 = 0x00010100,
  88. };
  89. /*
  90. * HCDDID - Host Controller Identification Descriptor
  91. * - Device ID and Device Class 10h
  92. */
  93. #define DEVICE_CLASS UFS_MASK(0xFFFF, 0)
  94. #define DEVICE_ID UFS_MASK(0xFF, 24)
  95. /*
  96. * HCPMID - Host Controller Identification Descriptor
  97. * - Product/Manufacturer ID 14h
  98. */
  99. #define MANUFACTURE_ID_MASK UFS_MASK(0xFFFF, 0)
  100. #define PRODUCT_ID_MASK UFS_MASK(0xFFFF, 16)
  101. #define UFS_BIT(x) (1L << (x))
  102. #define UTP_TRANSFER_REQ_COMPL UFS_BIT(0)
  103. #define UIC_DME_END_PT_RESET UFS_BIT(1)
  104. #define UIC_ERROR UFS_BIT(2)
  105. #define UIC_TEST_MODE UFS_BIT(3)
  106. #define UIC_POWER_MODE UFS_BIT(4)
  107. #define UIC_HIBERNATE_EXIT UFS_BIT(5)
  108. #define UIC_HIBERNATE_ENTER UFS_BIT(6)
  109. #define UIC_LINK_LOST UFS_BIT(7)
  110. #define UIC_LINK_STARTUP UFS_BIT(8)
  111. #define UTP_TASK_REQ_COMPL UFS_BIT(9)
  112. #define UIC_COMMAND_COMPL UFS_BIT(10)
  113. #define DEVICE_FATAL_ERROR UFS_BIT(11)
  114. #define CONTROLLER_FATAL_ERROR UFS_BIT(16)
  115. #define SYSTEM_BUS_FATAL_ERROR UFS_BIT(17)
  116. #define UFSHCD_ERROR_MASK (UIC_ERROR |\
  117. DEVICE_FATAL_ERROR |\
  118. CONTROLLER_FATAL_ERROR |\
  119. SYSTEM_BUS_FATAL_ERROR)
  120. #define INT_FATAL_ERRORS (DEVICE_FATAL_ERROR |\
  121. CONTROLLER_FATAL_ERROR |\
  122. SYSTEM_BUS_FATAL_ERROR)
  123. /* HCS - Host Controller Status 30h */
  124. #define DEVICE_PRESENT UFS_BIT(0)
  125. #define UTP_TRANSFER_REQ_LIST_READY UFS_BIT(1)
  126. #define UTP_TASK_REQ_LIST_READY UFS_BIT(2)
  127. #define UIC_COMMAND_READY UFS_BIT(3)
  128. #define HOST_ERROR_INDICATOR UFS_BIT(4)
  129. #define DEVICE_ERROR_INDICATOR UFS_BIT(5)
  130. #define UIC_POWER_MODE_CHANGE_REQ_STATUS_MASK UFS_MASK(0x7, 8)
  131. /* HCE - Host Controller Enable 34h */
  132. #define CONTROLLER_ENABLE UFS_BIT(0)
  133. #define CONTROLLER_DISABLE 0x0
  134. /* UECPA - Host UIC Error Code PHY Adapter Layer 38h */
  135. #define UIC_PHY_ADAPTER_LAYER_ERROR UFS_BIT(31)
  136. #define UIC_PHY_ADAPTER_LAYER_ERROR_CODE_MASK 0x1F
  137. /* UECDL - Host UIC Error Code Data Link Layer 3Ch */
  138. #define UIC_DATA_LINK_LAYER_ERROR UFS_BIT(31)
  139. #define UIC_DATA_LINK_LAYER_ERROR_CODE_MASK 0x7FFF
  140. #define UIC_DATA_LINK_LAYER_ERROR_PA_INIT 0x2000
  141. /* UECN - Host UIC Error Code Network Layer 40h */
  142. #define UIC_NETWORK_LAYER_ERROR UFS_BIT(31)
  143. #define UIC_NETWORK_LAYER_ERROR_CODE_MASK 0x7
  144. /* UECT - Host UIC Error Code Transport Layer 44h */
  145. #define UIC_TRANSPORT_LAYER_ERROR UFS_BIT(31)
  146. #define UIC_TRANSPORT_LAYER_ERROR_CODE_MASK 0x7F
  147. /* UECDME - Host UIC Error Code DME 48h */
  148. #define UIC_DME_ERROR UFS_BIT(31)
  149. #define UIC_DME_ERROR_CODE_MASK 0x1
  150. #define INT_AGGR_TIMEOUT_VAL_MASK 0xFF
  151. #define INT_AGGR_COUNTER_THRESHOLD_MASK UFS_MASK(0x1F, 8)
  152. #define INT_AGGR_COUNTER_AND_TIMER_RESET UFS_BIT(16)
  153. #define INT_AGGR_STATUS_BIT UFS_BIT(20)
  154. #define INT_AGGR_PARAM_WRITE UFS_BIT(24)
  155. #define INT_AGGR_ENABLE UFS_BIT(31)
  156. /* UTRLRSR - UTP Transfer Request Run-Stop Register 60h */
  157. #define UTP_TRANSFER_REQ_LIST_RUN_STOP_BIT UFS_BIT(0)
  158. /* UTMRLRSR - UTP Task Management Request Run-Stop Register 80h */
  159. #define UTP_TASK_REQ_LIST_RUN_STOP_BIT UFS_BIT(0)
  160. /* UICCMD - UIC Command */
  161. #define COMMAND_OPCODE_MASK 0xFF
  162. #define GEN_SELECTOR_INDEX_MASK 0xFFFF
  163. #define MIB_ATTRIBUTE_MASK UFS_MASK(0xFFFF, 16)
  164. #define RESET_LEVEL 0xFF
  165. #define ATTR_SET_TYPE_MASK UFS_MASK(0xFF, 16)
  166. #define CONFIG_RESULT_CODE_MASK 0xFF
  167. #define GENERIC_ERROR_CODE_MASK 0xFF
  168. /* UIC Commands */
  169. enum {
  170. UIC_CMD_DME_GET = 0x01,
  171. UIC_CMD_DME_SET = 0x02,
  172. UIC_CMD_DME_PEER_GET = 0x03,
  173. UIC_CMD_DME_PEER_SET = 0x04,
  174. UIC_CMD_DME_POWERON = 0x10,
  175. UIC_CMD_DME_POWEROFF = 0x11,
  176. UIC_CMD_DME_ENABLE = 0x12,
  177. UIC_CMD_DME_RESET = 0x14,
  178. UIC_CMD_DME_END_PT_RST = 0x15,
  179. UIC_CMD_DME_LINK_STARTUP = 0x16,
  180. UIC_CMD_DME_HIBER_ENTER = 0x17,
  181. UIC_CMD_DME_HIBER_EXIT = 0x18,
  182. UIC_CMD_DME_TEST_MODE = 0x1A,
  183. };
  184. /* UIC Config result code / Generic error code */
  185. enum {
  186. UIC_CMD_RESULT_SUCCESS = 0x00,
  187. UIC_CMD_RESULT_INVALID_ATTR = 0x01,
  188. UIC_CMD_RESULT_FAILURE = 0x01,
  189. UIC_CMD_RESULT_INVALID_ATTR_VALUE = 0x02,
  190. UIC_CMD_RESULT_READ_ONLY_ATTR = 0x03,
  191. UIC_CMD_RESULT_WRITE_ONLY_ATTR = 0x04,
  192. UIC_CMD_RESULT_BAD_INDEX = 0x05,
  193. UIC_CMD_RESULT_LOCKED_ATTR = 0x06,
  194. UIC_CMD_RESULT_BAD_TEST_FEATURE_INDEX = 0x07,
  195. UIC_CMD_RESULT_PEER_COMM_FAILURE = 0x08,
  196. UIC_CMD_RESULT_BUSY = 0x09,
  197. UIC_CMD_RESULT_DME_FAILURE = 0x0A,
  198. };
  199. #define MASK_UIC_COMMAND_RESULT 0xFF
  200. #define INT_AGGR_COUNTER_THRESHOLD_VALUE (0x1F << 8)
  201. #define INT_AGGR_TIMEOUT_VALUE (0x02)
  202. /* Interrupt disable masks */
  203. enum {
  204. /* Interrupt disable mask for UFSHCI v1.0 */
  205. INTERRUPT_MASK_ALL_VER_10 = 0x30FFF,
  206. INTERRUPT_MASK_RW_VER_10 = 0x30000,
  207. /* Interrupt disable mask for UFSHCI v1.1 */
  208. INTERRUPT_MASK_ALL_VER_11 = 0x31FFF,
  209. };
  210. /*
  211. * Request Descriptor Definitions
  212. */
  213. /* Transfer request command type */
  214. enum {
  215. UTP_CMD_TYPE_SCSI = 0x0,
  216. UTP_CMD_TYPE_UFS = 0x1,
  217. UTP_CMD_TYPE_DEV_MANAGE = 0x2,
  218. };
  219. enum {
  220. UTP_SCSI_COMMAND = 0x00000000,
  221. UTP_NATIVE_UFS_COMMAND = 0x10000000,
  222. UTP_DEVICE_MANAGEMENT_FUNCTION = 0x20000000,
  223. UTP_REQ_DESC_INT_CMD = 0x01000000,
  224. };
  225. /* UTP Transfer Request Data Direction (DD) */
  226. enum {
  227. UTP_NO_DATA_TRANSFER = 0x00000000,
  228. UTP_HOST_TO_DEVICE = 0x02000000,
  229. UTP_DEVICE_TO_HOST = 0x04000000,
  230. };
  231. /* Overall command status values */
  232. enum {
  233. OCS_SUCCESS = 0x0,
  234. OCS_INVALID_CMD_TABLE_ATTR = 0x1,
  235. OCS_INVALID_PRDT_ATTR = 0x2,
  236. OCS_MISMATCH_DATA_BUF_SIZE = 0x3,
  237. OCS_MISMATCH_RESP_UPIU_SIZE = 0x4,
  238. OCS_PEER_COMM_FAILURE = 0x5,
  239. OCS_ABORTED = 0x6,
  240. OCS_FATAL_ERROR = 0x7,
  241. OCS_INVALID_COMMAND_STATUS = 0x0F,
  242. MASK_OCS = 0x0F,
  243. };
  244. /**
  245. * struct ufshcd_sg_entry - UFSHCI PRD Entry
  246. * @base_addr: Lower 32bit physical address DW-0
  247. * @upper_addr: Upper 32bit physical address DW-1
  248. * @reserved: Reserved for future use DW-2
  249. * @size: size of physical segment DW-3
  250. */
  251. struct ufshcd_sg_entry {
  252. u32 base_addr;
  253. u32 upper_addr;
  254. u32 reserved;
  255. u32 size;
  256. };
  257. /**
  258. * struct utp_transfer_cmd_desc - UFS Command Descriptor structure
  259. * @command_upiu: Command UPIU Frame address
  260. * @response_upiu: Response UPIU Frame address
  261. * @prd_table: Physical Region Descriptor
  262. */
  263. struct utp_transfer_cmd_desc {
  264. u8 command_upiu[ALIGNED_UPIU_SIZE];
  265. u8 response_upiu[ALIGNED_UPIU_SIZE];
  266. struct ufshcd_sg_entry prd_table[SG_ALL];
  267. };
  268. /**
  269. * struct request_desc_header - Descriptor Header common to both UTRD and UTMRD
  270. * @dword0: Descriptor Header DW0
  271. * @dword1: Descriptor Header DW1
  272. * @dword2: Descriptor Header DW2
  273. * @dword3: Descriptor Header DW3
  274. */
  275. struct request_desc_header {
  276. u32 dword_0;
  277. u32 dword_1;
  278. u32 dword_2;
  279. u32 dword_3;
  280. };
  281. /**
  282. * struct utp_transfer_req_desc - UTRD structure
  283. * @header: UTRD header DW-0 to DW-3
  284. * @command_desc_base_addr_lo: UCD base address low DW-4
  285. * @command_desc_base_addr_hi: UCD base address high DW-5
  286. * @response_upiu_length: response UPIU length DW-6
  287. * @response_upiu_offset: response UPIU offset DW-6
  288. * @prd_table_length: Physical region descriptor length DW-7
  289. * @prd_table_offset: Physical region descriptor offset DW-7
  290. */
  291. struct utp_transfer_req_desc {
  292. /* DW 0-3 */
  293. struct request_desc_header header;
  294. /* DW 4-5*/
  295. u32 command_desc_base_addr_lo;
  296. u32 command_desc_base_addr_hi;
  297. /* DW 6 */
  298. u16 response_upiu_length;
  299. u16 response_upiu_offset;
  300. /* DW 7 */
  301. u16 prd_table_length;
  302. u16 prd_table_offset;
  303. };
  304. /**
  305. * struct utp_task_req_desc - UTMRD structure
  306. * @header: UTMRD header DW-0 to DW-3
  307. * @task_req_upiu: Pointer to task request UPIU DW-4 to DW-11
  308. * @task_rsp_upiu: Pointer to task response UPIU DW12 to DW-19
  309. */
  310. struct utp_task_req_desc {
  311. /* DW 0-3 */
  312. struct request_desc_header header;
  313. /* DW 4-11 */
  314. u32 task_req_upiu[TASK_REQ_UPIU_SIZE_DWORDS];
  315. /* DW 12-19 */
  316. u32 task_rsp_upiu[TASK_RSP_UPIU_SIZE_DWORDS];
  317. };
  318. #endif /* End of Header */