ufshcd.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * Universal Flash Storage Host controller driver
  3. *
  4. * This code is based on drivers/scsi/ufs/ufshcd.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 _UFSHCD_H
  36. #define _UFSHCD_H
  37. #include <linux/module.h>
  38. #include <linux/kernel.h>
  39. #include <linux/init.h>
  40. #include <linux/interrupt.h>
  41. #include <linux/io.h>
  42. #include <linux/delay.h>
  43. #include <linux/slab.h>
  44. #include <linux/spinlock.h>
  45. #include <linux/workqueue.h>
  46. #include <linux/errno.h>
  47. #include <linux/types.h>
  48. #include <linux/wait.h>
  49. #include <linux/bitops.h>
  50. #include <linux/pm_runtime.h>
  51. #include <linux/clk.h>
  52. #include <asm/irq.h>
  53. #include <asm/byteorder.h>
  54. #include <scsi/scsi.h>
  55. #include <scsi/scsi_cmnd.h>
  56. #include <scsi/scsi_host.h>
  57. #include <scsi/scsi_tcq.h>
  58. #include <scsi/scsi_dbg.h>
  59. #include <scsi/scsi_eh.h>
  60. #include "ufs.h"
  61. #include "ufshci.h"
  62. #define UFSHCD "ufshcd"
  63. #define UFSHCD_DRIVER_VERSION "0.2"
  64. /**
  65. * struct uic_command - UIC command structure
  66. * @command: UIC command
  67. * @argument1: UIC command argument 1
  68. * @argument2: UIC command argument 2
  69. * @argument3: UIC command argument 3
  70. * @cmd_active: Indicate if UIC command is outstanding
  71. * @result: UIC command result
  72. */
  73. struct uic_command {
  74. u32 command;
  75. u32 argument1;
  76. u32 argument2;
  77. u32 argument3;
  78. int cmd_active;
  79. int result;
  80. };
  81. /**
  82. * struct ufshcd_lrb - local reference block
  83. * @utr_descriptor_ptr: UTRD address of the command
  84. * @ucd_cmd_ptr: UCD address of the command
  85. * @ucd_rsp_ptr: Response UPIU address for this command
  86. * @ucd_prdt_ptr: PRDT address of the command
  87. * @cmd: pointer to SCSI command
  88. * @sense_buffer: pointer to sense buffer address of the SCSI command
  89. * @sense_bufflen: Length of the sense buffer
  90. * @scsi_status: SCSI status of the command
  91. * @command_type: SCSI, UFS, Query.
  92. * @task_tag: Task tag of the command
  93. * @lun: LUN of the command
  94. */
  95. struct ufshcd_lrb {
  96. struct utp_transfer_req_desc *utr_descriptor_ptr;
  97. struct utp_upiu_cmd *ucd_cmd_ptr;
  98. struct utp_upiu_rsp *ucd_rsp_ptr;
  99. struct ufshcd_sg_entry *ucd_prdt_ptr;
  100. struct scsi_cmnd *cmd;
  101. u8 *sense_buffer;
  102. unsigned int sense_bufflen;
  103. int scsi_status;
  104. int command_type;
  105. int task_tag;
  106. unsigned int lun;
  107. };
  108. /**
  109. * struct ufs_hba - per adapter private structure
  110. * @mmio_base: UFSHCI base register address
  111. * @ucdl_base_addr: UFS Command Descriptor base address
  112. * @utrdl_base_addr: UTP Transfer Request Descriptor base address
  113. * @utmrdl_base_addr: UTP Task Management Descriptor base address
  114. * @ucdl_dma_addr: UFS Command Descriptor DMA address
  115. * @utrdl_dma_addr: UTRDL DMA address
  116. * @utmrdl_dma_addr: UTMRDL DMA address
  117. * @host: Scsi_Host instance of the driver
  118. * @dev: device handle
  119. * @lrb: local reference block
  120. * @outstanding_tasks: Bits representing outstanding task requests
  121. * @outstanding_reqs: Bits representing outstanding transfer requests
  122. * @capabilities: UFS Controller Capabilities
  123. * @nutrs: Transfer Request Queue depth supported by controller
  124. * @nutmrs: Task Management Queue depth supported by controller
  125. * @ufs_version: UFS Version to which controller complies
  126. * @irq: Irq number of the controller
  127. * @active_uic_cmd: handle of active UIC command
  128. * @ufshcd_tm_wait_queue: wait queue for task management
  129. * @tm_condition: condition variable for task management
  130. * @ufshcd_state: UFSHCD states
  131. * @int_enable_mask: Interrupt Mask Bits
  132. * @uic_workq: Work queue for UIC completion handling
  133. * @feh_workq: Work queue for fatal controller error handling
  134. * @errors: HBA errors
  135. */
  136. struct ufs_hba {
  137. void __iomem *mmio_base;
  138. /* Virtual memory reference */
  139. struct utp_transfer_cmd_desc *ucdl_base_addr;
  140. struct utp_transfer_req_desc *utrdl_base_addr;
  141. struct utp_task_req_desc *utmrdl_base_addr;
  142. /* DMA memory reference */
  143. dma_addr_t ucdl_dma_addr;
  144. dma_addr_t utrdl_dma_addr;
  145. dma_addr_t utmrdl_dma_addr;
  146. struct Scsi_Host *host;
  147. struct device *dev;
  148. struct ufshcd_lrb *lrb;
  149. unsigned long outstanding_tasks;
  150. unsigned long outstanding_reqs;
  151. u32 capabilities;
  152. int nutrs;
  153. int nutmrs;
  154. u32 ufs_version;
  155. unsigned int irq;
  156. struct uic_command active_uic_cmd;
  157. wait_queue_head_t ufshcd_tm_wait_queue;
  158. unsigned long tm_condition;
  159. u32 ufshcd_state;
  160. u32 int_enable_mask;
  161. /* Work Queues */
  162. struct work_struct uic_workq;
  163. struct work_struct feh_workq;
  164. /* HBA Errors */
  165. u32 errors;
  166. };
  167. int ufshcd_init(struct device *, struct ufs_hba ** , void __iomem * ,
  168. unsigned int);
  169. void ufshcd_remove(struct ufs_hba *);
  170. /**
  171. * ufshcd_hba_stop - Send controller to reset state
  172. * @hba: per adapter instance
  173. */
  174. static inline void ufshcd_hba_stop(struct ufs_hba *hba)
  175. {
  176. writel(CONTROLLER_DISABLE, (hba->mmio_base + REG_CONTROLLER_ENABLE));
  177. }
  178. #endif /* End of Header */