ufshci.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. /*
  2. * Universal Flash Storage Host controller driver
  3. *
  4. * This code is based on drivers/scsi/ufs/ufshci.h
  5. * Copyright (C) 2011-2012 Samsung India Software Operations
  6. *
  7. * Santosh Yaraganavi <santosh.sy@samsung.com>
  8. * Vinayak Holikatti <h.vinayak@samsung.com>
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version 2
  13. * of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * NO WARRANTY
  21. * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
  22. * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
  23. * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
  24. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
  25. * solely responsible for determining the appropriateness of using and
  26. * distributing the Program and assumes all risks associated with its
  27. * exercise of rights under this Agreement, including but not limited to
  28. * the risks and costs of program errors, damage to or loss of data,
  29. * programs or equipment, and unavailability or interruption of operations.
  30. * DISCLAIMER OF LIABILITY
  31. * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
  32. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  33. * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
  34. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  35. * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  36. * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
  37. * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
  38. * You should have received a copy of the GNU General Public License
  39. * along with this program; if not, write to the Free Software
  40. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
  41. * USA.
  42. */
  43. #ifndef _UFSHCI_H
  44. #define _UFSHCI_H
  45. enum {
  46. TASK_REQ_UPIU_SIZE_DWORDS = 8,
  47. TASK_RSP_UPIU_SIZE_DWORDS = 8,
  48. ALIGNED_UPIU_SIZE = 128,
  49. };
  50. /* UFSHCI Registers */
  51. enum {
  52. REG_CONTROLLER_CAPABILITIES = 0x00,
  53. REG_UFS_VERSION = 0x08,
  54. REG_CONTROLLER_DEV_ID = 0x10,
  55. REG_CONTROLLER_PROD_ID = 0x14,
  56. REG_INTERRUPT_STATUS = 0x20,
  57. REG_INTERRUPT_ENABLE = 0x24,
  58. REG_CONTROLLER_STATUS = 0x30,
  59. REG_CONTROLLER_ENABLE = 0x34,
  60. REG_UIC_ERROR_CODE_PHY_ADAPTER_LAYER = 0x38,
  61. REG_UIC_ERROR_CODE_DATA_LINK_LAYER = 0x3C,
  62. REG_UIC_ERROR_CODE_NETWORK_LAYER = 0x40,
  63. REG_UIC_ERROR_CODE_TRANSPORT_LAYER = 0x44,
  64. REG_UIC_ERROR_CODE_DME = 0x48,
  65. REG_UTP_TRANSFER_REQ_INT_AGG_CONTROL = 0x4C,
  66. REG_UTP_TRANSFER_REQ_LIST_BASE_L = 0x50,
  67. REG_UTP_TRANSFER_REQ_LIST_BASE_H = 0x54,
  68. REG_UTP_TRANSFER_REQ_DOOR_BELL = 0x58,
  69. REG_UTP_TRANSFER_REQ_LIST_CLEAR = 0x5C,
  70. REG_UTP_TRANSFER_REQ_LIST_RUN_STOP = 0x60,
  71. REG_UTP_TASK_REQ_LIST_BASE_L = 0x70,
  72. REG_UTP_TASK_REQ_LIST_BASE_H = 0x74,
  73. REG_UTP_TASK_REQ_DOOR_BELL = 0x78,
  74. REG_UTP_TASK_REQ_LIST_CLEAR = 0x7C,
  75. REG_UTP_TASK_REQ_LIST_RUN_STOP = 0x80,
  76. REG_UIC_COMMAND = 0x90,
  77. REG_UIC_COMMAND_ARG_1 = 0x94,
  78. REG_UIC_COMMAND_ARG_2 = 0x98,
  79. REG_UIC_COMMAND_ARG_3 = 0x9C,
  80. };
  81. /* Controller capability masks */
  82. enum {
  83. MASK_TRANSFER_REQUESTS_SLOTS = 0x0000001F,
  84. MASK_TASK_MANAGEMENT_REQUEST_SLOTS = 0x00070000,
  85. MASK_64_ADDRESSING_SUPPORT = 0x01000000,
  86. MASK_OUT_OF_ORDER_DATA_DELIVERY_SUPPORT = 0x02000000,
  87. MASK_UIC_DME_TEST_MODE_SUPPORT = 0x04000000,
  88. };
  89. /* UFS Version 08h */
  90. #define MINOR_VERSION_NUM_MASK UFS_MASK(0xFFFF, 0)
  91. #define MAJOR_VERSION_NUM_MASK UFS_MASK(0xFFFF, 16)
  92. /* Controller UFSHCI version */
  93. enum {
  94. UFSHCI_VERSION_10 = 0x00010000,
  95. UFSHCI_VERSION_11 = 0x00010100,
  96. };
  97. /*
  98. * HCDDID - Host Controller Identification Descriptor
  99. * - Device ID and Device Class 10h
  100. */
  101. #define DEVICE_CLASS UFS_MASK(0xFFFF, 0)
  102. #define DEVICE_ID UFS_MASK(0xFF, 24)
  103. /*
  104. * HCPMID - Host Controller Identification Descriptor
  105. * - Product/Manufacturer ID 14h
  106. */
  107. #define MANUFACTURE_ID_MASK UFS_MASK(0xFFFF, 0)
  108. #define PRODUCT_ID_MASK UFS_MASK(0xFFFF, 16)
  109. #define UFS_BIT(x) (1L << (x))
  110. #define UTP_TRANSFER_REQ_COMPL UFS_BIT(0)
  111. #define UIC_DME_END_PT_RESET UFS_BIT(1)
  112. #define UIC_ERROR UFS_BIT(2)
  113. #define UIC_TEST_MODE UFS_BIT(3)
  114. #define UIC_POWER_MODE UFS_BIT(4)
  115. #define UIC_HIBERNATE_EXIT UFS_BIT(5)
  116. #define UIC_HIBERNATE_ENTER UFS_BIT(6)
  117. #define UIC_LINK_LOST UFS_BIT(7)
  118. #define UIC_LINK_STARTUP UFS_BIT(8)
  119. #define UTP_TASK_REQ_COMPL UFS_BIT(9)
  120. #define UIC_COMMAND_COMPL UFS_BIT(10)
  121. #define DEVICE_FATAL_ERROR UFS_BIT(11)
  122. #define CONTROLLER_FATAL_ERROR UFS_BIT(16)
  123. #define SYSTEM_BUS_FATAL_ERROR UFS_BIT(17)
  124. #define UFSHCD_ERROR_MASK (UIC_ERROR |\
  125. DEVICE_FATAL_ERROR |\
  126. CONTROLLER_FATAL_ERROR |\
  127. SYSTEM_BUS_FATAL_ERROR)
  128. #define INT_FATAL_ERRORS (DEVICE_FATAL_ERROR |\
  129. CONTROLLER_FATAL_ERROR |\
  130. SYSTEM_BUS_FATAL_ERROR)
  131. /* HCS - Host Controller Status 30h */
  132. #define DEVICE_PRESENT UFS_BIT(0)
  133. #define UTP_TRANSFER_REQ_LIST_READY UFS_BIT(1)
  134. #define UTP_TASK_REQ_LIST_READY UFS_BIT(2)
  135. #define UIC_COMMAND_READY UFS_BIT(3)
  136. #define HOST_ERROR_INDICATOR UFS_BIT(4)
  137. #define DEVICE_ERROR_INDICATOR UFS_BIT(5)
  138. #define UIC_POWER_MODE_CHANGE_REQ_STATUS_MASK UFS_MASK(0x7, 8)
  139. /* HCE - Host Controller Enable 34h */
  140. #define CONTROLLER_ENABLE UFS_BIT(0)
  141. #define CONTROLLER_DISABLE 0x0
  142. /* UECPA - Host UIC Error Code PHY Adapter Layer 38h */
  143. #define UIC_PHY_ADAPTER_LAYER_ERROR UFS_BIT(31)
  144. #define UIC_PHY_ADAPTER_LAYER_ERROR_CODE_MASK 0x1F
  145. /* UECDL - Host UIC Error Code Data Link Layer 3Ch */
  146. #define UIC_DATA_LINK_LAYER_ERROR UFS_BIT(31)
  147. #define UIC_DATA_LINK_LAYER_ERROR_CODE_MASK 0x7FFF
  148. #define UIC_DATA_LINK_LAYER_ERROR_PA_INIT 0x2000
  149. /* UECN - Host UIC Error Code Network Layer 40h */
  150. #define UIC_NETWORK_LAYER_ERROR UFS_BIT(31)
  151. #define UIC_NETWORK_LAYER_ERROR_CODE_MASK 0x7
  152. /* UECT - Host UIC Error Code Transport Layer 44h */
  153. #define UIC_TRANSPORT_LAYER_ERROR UFS_BIT(31)
  154. #define UIC_TRANSPORT_LAYER_ERROR_CODE_MASK 0x7F
  155. /* UECDME - Host UIC Error Code DME 48h */
  156. #define UIC_DME_ERROR UFS_BIT(31)
  157. #define UIC_DME_ERROR_CODE_MASK 0x1
  158. #define INT_AGGR_TIMEOUT_VAL_MASK 0xFF
  159. #define INT_AGGR_COUNTER_THRESHOLD_MASK UFS_MASK(0x1F, 8)
  160. #define INT_AGGR_COUNTER_AND_TIMER_RESET UFS_BIT(16)
  161. #define INT_AGGR_STATUS_BIT UFS_BIT(20)
  162. #define INT_AGGR_PARAM_WRITE UFS_BIT(24)
  163. #define INT_AGGR_ENABLE UFS_BIT(31)
  164. /* UTRLRSR - UTP Transfer Request Run-Stop Register 60h */
  165. #define UTP_TRANSFER_REQ_LIST_RUN_STOP_BIT UFS_BIT(0)
  166. /* UTMRLRSR - UTP Task Management Request Run-Stop Register 80h */
  167. #define UTP_TASK_REQ_LIST_RUN_STOP_BIT UFS_BIT(0)
  168. /* UICCMD - UIC Command */
  169. #define COMMAND_OPCODE_MASK 0xFF
  170. #define GEN_SELECTOR_INDEX_MASK 0xFFFF
  171. #define MIB_ATTRIBUTE_MASK UFS_MASK(0xFFFF, 16)
  172. #define RESET_LEVEL 0xFF
  173. #define ATTR_SET_TYPE_MASK UFS_MASK(0xFF, 16)
  174. #define CONFIG_RESULT_CODE_MASK 0xFF
  175. #define GENERIC_ERROR_CODE_MASK 0xFF
  176. /* UIC Commands */
  177. enum {
  178. UIC_CMD_DME_GET = 0x01,
  179. UIC_CMD_DME_SET = 0x02,
  180. UIC_CMD_DME_PEER_GET = 0x03,
  181. UIC_CMD_DME_PEER_SET = 0x04,
  182. UIC_CMD_DME_POWERON = 0x10,
  183. UIC_CMD_DME_POWEROFF = 0x11,
  184. UIC_CMD_DME_ENABLE = 0x12,
  185. UIC_CMD_DME_RESET = 0x14,
  186. UIC_CMD_DME_END_PT_RST = 0x15,
  187. UIC_CMD_DME_LINK_STARTUP = 0x16,
  188. UIC_CMD_DME_HIBER_ENTER = 0x17,
  189. UIC_CMD_DME_HIBER_EXIT = 0x18,
  190. UIC_CMD_DME_TEST_MODE = 0x1A,
  191. };
  192. /* UIC Config result code / Generic error code */
  193. enum {
  194. UIC_CMD_RESULT_SUCCESS = 0x00,
  195. UIC_CMD_RESULT_INVALID_ATTR = 0x01,
  196. UIC_CMD_RESULT_FAILURE = 0x01,
  197. UIC_CMD_RESULT_INVALID_ATTR_VALUE = 0x02,
  198. UIC_CMD_RESULT_READ_ONLY_ATTR = 0x03,
  199. UIC_CMD_RESULT_WRITE_ONLY_ATTR = 0x04,
  200. UIC_CMD_RESULT_BAD_INDEX = 0x05,
  201. UIC_CMD_RESULT_LOCKED_ATTR = 0x06,
  202. UIC_CMD_RESULT_BAD_TEST_FEATURE_INDEX = 0x07,
  203. UIC_CMD_RESULT_PEER_COMM_FAILURE = 0x08,
  204. UIC_CMD_RESULT_BUSY = 0x09,
  205. UIC_CMD_RESULT_DME_FAILURE = 0x0A,
  206. };
  207. #define MASK_UIC_COMMAND_RESULT 0xFF
  208. #define INT_AGGR_COUNTER_THRESHOLD_VALUE (0x1F << 8)
  209. #define INT_AGGR_TIMEOUT_VALUE (0x02)
  210. /* Interrupt disable masks */
  211. enum {
  212. /* Interrupt disable mask for UFSHCI v1.0 */
  213. INTERRUPT_DISABLE_MASK_10 = 0xFFFF,
  214. /* Interrupt disable mask for UFSHCI v1.1 */
  215. INTERRUPT_DISABLE_MASK_11 = 0x0,
  216. };
  217. /*
  218. * Request Descriptor Definitions
  219. */
  220. /* Transfer request command type */
  221. enum {
  222. UTP_CMD_TYPE_SCSI = 0x0,
  223. UTP_CMD_TYPE_UFS = 0x1,
  224. UTP_CMD_TYPE_DEV_MANAGE = 0x2,
  225. };
  226. enum {
  227. UTP_SCSI_COMMAND = 0x00000000,
  228. UTP_NATIVE_UFS_COMMAND = 0x10000000,
  229. UTP_DEVICE_MANAGEMENT_FUNCTION = 0x20000000,
  230. UTP_REQ_DESC_INT_CMD = 0x01000000,
  231. };
  232. /* UTP Transfer Request Data Direction (DD) */
  233. enum {
  234. UTP_NO_DATA_TRANSFER = 0x00000000,
  235. UTP_HOST_TO_DEVICE = 0x02000000,
  236. UTP_DEVICE_TO_HOST = 0x04000000,
  237. };
  238. /* Overall command status values */
  239. enum {
  240. OCS_SUCCESS = 0x0,
  241. OCS_INVALID_CMD_TABLE_ATTR = 0x1,
  242. OCS_INVALID_PRDT_ATTR = 0x2,
  243. OCS_MISMATCH_DATA_BUF_SIZE = 0x3,
  244. OCS_MISMATCH_RESP_UPIU_SIZE = 0x4,
  245. OCS_PEER_COMM_FAILURE = 0x5,
  246. OCS_ABORTED = 0x6,
  247. OCS_FATAL_ERROR = 0x7,
  248. OCS_INVALID_COMMAND_STATUS = 0x0F,
  249. MASK_OCS = 0x0F,
  250. };
  251. /**
  252. * struct ufshcd_sg_entry - UFSHCI PRD Entry
  253. * @base_addr: Lower 32bit physical address DW-0
  254. * @upper_addr: Upper 32bit physical address DW-1
  255. * @reserved: Reserved for future use DW-2
  256. * @size: size of physical segment DW-3
  257. */
  258. struct ufshcd_sg_entry {
  259. u32 base_addr;
  260. u32 upper_addr;
  261. u32 reserved;
  262. u32 size;
  263. };
  264. /**
  265. * struct utp_transfer_cmd_desc - UFS Command Descriptor structure
  266. * @command_upiu: Command UPIU Frame address
  267. * @response_upiu: Response UPIU Frame address
  268. * @prd_table: Physical Region Descriptor
  269. */
  270. struct utp_transfer_cmd_desc {
  271. u8 command_upiu[ALIGNED_UPIU_SIZE];
  272. u8 response_upiu[ALIGNED_UPIU_SIZE];
  273. struct ufshcd_sg_entry prd_table[SG_ALL];
  274. };
  275. /**
  276. * struct request_desc_header - Descriptor Header common to both UTRD and UTMRD
  277. * @dword0: Descriptor Header DW0
  278. * @dword1: Descriptor Header DW1
  279. * @dword2: Descriptor Header DW2
  280. * @dword3: Descriptor Header DW3
  281. */
  282. struct request_desc_header {
  283. u32 dword_0;
  284. u32 dword_1;
  285. u32 dword_2;
  286. u32 dword_3;
  287. };
  288. /**
  289. * struct utp_transfer_req_desc - UTRD structure
  290. * @header: UTRD header DW-0 to DW-3
  291. * @command_desc_base_addr_lo: UCD base address low DW-4
  292. * @command_desc_base_addr_hi: UCD base address high DW-5
  293. * @response_upiu_length: response UPIU length DW-6
  294. * @response_upiu_offset: response UPIU offset DW-6
  295. * @prd_table_length: Physical region descriptor length DW-7
  296. * @prd_table_offset: Physical region descriptor offset DW-7
  297. */
  298. struct utp_transfer_req_desc {
  299. /* DW 0-3 */
  300. struct request_desc_header header;
  301. /* DW 4-5*/
  302. u32 command_desc_base_addr_lo;
  303. u32 command_desc_base_addr_hi;
  304. /* DW 6 */
  305. u16 response_upiu_length;
  306. u16 response_upiu_offset;
  307. /* DW 7 */
  308. u16 prd_table_length;
  309. u16 prd_table_offset;
  310. };
  311. /**
  312. * struct utp_task_req_desc - UTMRD structure
  313. * @header: UTMRD header DW-0 to DW-3
  314. * @task_req_upiu: Pointer to task request UPIU DW-4 to DW-11
  315. * @task_rsp_upiu: Pointer to task response UPIU DW12 to DW-19
  316. */
  317. struct utp_task_req_desc {
  318. /* DW 0-3 */
  319. struct request_desc_header header;
  320. /* DW 4-11 */
  321. u32 task_req_upiu[TASK_REQ_UPIU_SIZE_DWORDS];
  322. /* DW 12-19 */
  323. u32 task_rsp_upiu[TASK_RSP_UPIU_SIZE_DWORDS];
  324. };
  325. #endif /* End of Header */