host.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /*
  2. * This file is provided under a dual BSD/GPLv2 license. When using or
  3. * redistributing this file, you may do so under either license.
  4. *
  5. * GPL LICENSE SUMMARY
  6. *
  7. * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of version 2 of the GNU General Public License as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called LICENSE.GPL.
  23. *
  24. * BSD LICENSE
  25. *
  26. * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
  27. * All rights reserved.
  28. *
  29. * Redistribution and use in source and binary forms, with or without
  30. * modification, are permitted provided that the following conditions
  31. * are met:
  32. *
  33. * * Redistributions of source code must retain the above copyright
  34. * notice, this list of conditions and the following disclaimer.
  35. * * Redistributions in binary form must reproduce the above copyright
  36. * notice, this list of conditions and the following disclaimer in
  37. * the documentation and/or other materials provided with the
  38. * distribution.
  39. * * Neither the name of Intel Corporation nor the names of its
  40. * contributors may be used to endorse or promote products derived
  41. * from this software without specific prior written permission.
  42. *
  43. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  44. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  45. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  46. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  47. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  48. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  49. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  50. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  51. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  52. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  53. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  54. */
  55. #if !defined(_SCI_HOST_H_)
  56. #define _SCI_HOST_H_
  57. #include "phy.h"
  58. /*#include "task.h"*/
  59. #include "timers.h"
  60. #include "remote_device.h"
  61. #include "scic_remote_device.h"
  62. #define DRV_NAME "isci"
  63. #define SCI_PCI_BAR_COUNT 2
  64. #define SCI_NUM_MSI_X_INT 2
  65. #define SCI_SMU_BAR 0
  66. #define SCI_SMU_BAR_SIZE (16*1024)
  67. #define SCI_SCU_BAR 1
  68. #define SCI_SCU_BAR_SIZE (4*1024*1024)
  69. #define SCI_IO_SPACE_BAR0 2
  70. #define SCI_IO_SPACE_BAR1 3
  71. #define ISCI_CAN_QUEUE_VAL 250 /* < SCI_MAX_IO_REQUESTS ? */
  72. #define SCIC_CONTROLLER_STOP_TIMEOUT 5000
  73. struct coherent_memory_info {
  74. struct list_head node;
  75. dma_addr_t dma_handle;
  76. void *vaddr;
  77. size_t size;
  78. struct sci_physical_memory_descriptor *mde;
  79. };
  80. struct isci_host {
  81. struct scic_sds_controller *core_controller;
  82. union scic_oem_parameters oem_parameters;
  83. int id; /* unique within a given pci device */
  84. struct list_head timers;
  85. void *core_ctrl_memory;
  86. struct dma_pool *dma_pool;
  87. unsigned int dma_pool_alloc_size;
  88. struct isci_phy phys[SCI_MAX_PHYS];
  89. /* isci_ports and sas_ports are implicitly parallel to the
  90. * ports maintained by the core
  91. */
  92. struct isci_port isci_ports[SCI_MAX_PORTS];
  93. struct asd_sas_port sas_ports[SCI_MAX_PORTS];
  94. struct sas_ha_struct sas_ha;
  95. int can_queue;
  96. spinlock_t queue_lock;
  97. spinlock_t state_lock;
  98. struct pci_dev *pdev;
  99. enum isci_status status;
  100. #define IHOST_START_PENDING 0
  101. #define IHOST_STOP_PENDING 1
  102. unsigned long flags;
  103. wait_queue_head_t eventq;
  104. struct Scsi_Host *shost;
  105. struct tasklet_struct completion_tasklet;
  106. struct list_head mdl_struct_list;
  107. struct list_head requests_to_complete;
  108. struct list_head requests_to_errorback;
  109. spinlock_t scic_lock;
  110. /* careful only access this via idev_by_id */
  111. struct isci_remote_device devices[0];
  112. };
  113. static inline struct isci_remote_device *idev_by_id(struct isci_host *ihost, int i)
  114. {
  115. void *p = ihost->devices;
  116. return p + i * (sizeof(struct isci_remote_device) +
  117. scic_remote_device_get_object_size());
  118. }
  119. /**
  120. * struct isci_pci_info - This class represents the pci function containing the
  121. * controllers. Depending on PCI SKU, there could be up to 2 controllers in
  122. * the PCI function.
  123. */
  124. #define SCI_MAX_MSIX_INT (SCI_NUM_MSI_X_INT*SCI_MAX_CONTROLLERS)
  125. struct isci_pci_info {
  126. struct msix_entry msix_entries[SCI_MAX_MSIX_INT];
  127. struct isci_host *hosts[SCI_MAX_CONTROLLERS];
  128. struct isci_orom *orom;
  129. };
  130. static inline struct isci_pci_info *to_pci_info(struct pci_dev *pdev)
  131. {
  132. return pci_get_drvdata(pdev);
  133. }
  134. #define for_each_isci_host(id, ihost, pdev) \
  135. for (id = 0, ihost = to_pci_info(pdev)->hosts[id]; \
  136. id < ARRAY_SIZE(to_pci_info(pdev)->hosts) && ihost; \
  137. ihost = to_pci_info(pdev)->hosts[++id])
  138. static inline
  139. enum isci_status isci_host_get_state(
  140. struct isci_host *isci_host)
  141. {
  142. return isci_host->status;
  143. }
  144. static inline void isci_host_change_state(
  145. struct isci_host *isci_host,
  146. enum isci_status status)
  147. {
  148. unsigned long flags;
  149. dev_dbg(&isci_host->pdev->dev,
  150. "%s: isci_host = %p, state = 0x%x",
  151. __func__,
  152. isci_host,
  153. status);
  154. spin_lock_irqsave(&isci_host->state_lock, flags);
  155. isci_host->status = status;
  156. spin_unlock_irqrestore(&isci_host->state_lock, flags);
  157. }
  158. static inline int isci_host_can_queue(
  159. struct isci_host *isci_host,
  160. int num)
  161. {
  162. int ret = 0;
  163. unsigned long flags;
  164. spin_lock_irqsave(&isci_host->queue_lock, flags);
  165. if ((isci_host->can_queue - num) < 0) {
  166. dev_dbg(&isci_host->pdev->dev,
  167. "%s: isci_host->can_queue = %d\n",
  168. __func__,
  169. isci_host->can_queue);
  170. ret = -SAS_QUEUE_FULL;
  171. } else
  172. isci_host->can_queue -= num;
  173. spin_unlock_irqrestore(&isci_host->queue_lock, flags);
  174. return ret;
  175. }
  176. static inline void isci_host_can_dequeue(
  177. struct isci_host *isci_host,
  178. int num)
  179. {
  180. unsigned long flags;
  181. spin_lock_irqsave(&isci_host->queue_lock, flags);
  182. isci_host->can_queue += num;
  183. spin_unlock_irqrestore(&isci_host->queue_lock, flags);
  184. }
  185. static inline void wait_for_start(struct isci_host *ihost)
  186. {
  187. wait_event(ihost->eventq, !test_bit(IHOST_START_PENDING, &ihost->flags));
  188. }
  189. static inline void wait_for_stop(struct isci_host *ihost)
  190. {
  191. wait_event(ihost->eventq, !test_bit(IHOST_STOP_PENDING, &ihost->flags));
  192. }
  193. static inline void wait_for_device_start(struct isci_host *ihost, struct isci_remote_device *idev)
  194. {
  195. wait_event(ihost->eventq, !test_bit(IDEV_START_PENDING, &idev->flags));
  196. }
  197. static inline void wait_for_device_stop(struct isci_host *ihost, struct isci_remote_device *idev)
  198. {
  199. wait_event(ihost->eventq, !test_bit(IDEV_STOP_PENDING, &idev->flags));
  200. }
  201. static inline struct isci_host *dev_to_ihost(struct domain_device *dev)
  202. {
  203. return dev->port->ha->lldd_ha;
  204. }
  205. /**
  206. * isci_host_scan_finished() -
  207. *
  208. * This function is one of the SCSI Host Template functions. The SCSI midlayer
  209. * calls this function during a target scan, approx. once every 10 millisecs.
  210. */
  211. int isci_host_scan_finished(
  212. struct Scsi_Host *,
  213. unsigned long);
  214. /**
  215. * isci_host_scan_start() -
  216. *
  217. * This function is one of the SCSI Host Template function, called by the SCSI
  218. * mid layer berfore a target scan begins. The core library controller start
  219. * routine is called from here.
  220. */
  221. void isci_host_scan_start(
  222. struct Scsi_Host *);
  223. /**
  224. * isci_host_start_complete() -
  225. *
  226. * This function is called by the core library, through the ISCI Module, to
  227. * indicate controller start status.
  228. */
  229. void isci_host_start_complete(
  230. struct isci_host *,
  231. enum sci_status);
  232. void isci_host_stop_complete(
  233. struct isci_host *isci_host,
  234. enum sci_status completion_status);
  235. int isci_host_init(struct isci_host *);
  236. void isci_host_init_controller_names(
  237. struct isci_host *isci_host,
  238. unsigned int controller_idx);
  239. void isci_host_deinit(
  240. struct isci_host *);
  241. void isci_host_port_link_up(
  242. struct isci_host *,
  243. struct scic_sds_port *,
  244. struct scic_sds_phy *);
  245. int isci_host_dev_found(struct domain_device *);
  246. void isci_host_remote_device_start_complete(
  247. struct isci_host *,
  248. struct isci_remote_device *,
  249. enum sci_status);
  250. #endif /* !defined(_SCI_HOST_H_) */