remote_device.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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. #ifndef _ISCI_REMOTE_DEVICE_H_
  56. #define _ISCI_REMOTE_DEVICE_H_
  57. #include <scsi/libsas.h>
  58. #include <linux/kref.h>
  59. #include "scu_remote_node_context.h"
  60. #include "remote_node_context.h"
  61. #include "port.h"
  62. enum sci_remote_device_not_ready_reason_code {
  63. SCIC_REMOTE_DEVICE_NOT_READY_START_REQUESTED,
  64. SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED,
  65. SCIC_REMOTE_DEVICE_NOT_READY_SATA_REQUEST_STARTED,
  66. SCIC_REMOTE_DEVICE_NOT_READY_SATA_SDB_ERROR_FIS_RECEIVED,
  67. SCIC_REMOTE_DEVICE_NOT_READY_SMP_REQUEST_STARTED,
  68. SCIC_REMOTE_DEVICE_NOT_READY_REASON_CODE_MAX
  69. };
  70. /**
  71. * isci_remote_device - isci representation of a sas expander / end point
  72. * @device_port_width: hw setting for number of simultaneous connections
  73. * @connection_rate: per-taskcontext connection rate for this device
  74. * @working_request: SATA requests have no tag we for unaccelerated
  75. * protocols we need a method to associate unsolicited
  76. * frames with a pending request
  77. */
  78. struct isci_remote_device {
  79. #define IDEV_START_PENDING 0
  80. #define IDEV_STOP_PENDING 1
  81. #define IDEV_ALLOCATED 2
  82. #define IDEV_GONE 3
  83. #define IDEV_IO_READY 4
  84. #define IDEV_IO_NCQERROR 5
  85. #define IDEV_RNC_LLHANG_ENABLED 6
  86. #define IDEV_ABORT_PATH_ACTIVE 7
  87. #define IDEV_ABORT_PATH_RESUME_PENDING 8
  88. unsigned long flags;
  89. struct kref kref;
  90. struct isci_port *isci_port;
  91. struct domain_device *domain_dev;
  92. struct list_head node;
  93. struct sci_base_state_machine sm;
  94. u32 device_port_width;
  95. enum sas_linkrate connection_rate;
  96. struct isci_port *owning_port;
  97. struct sci_remote_node_context rnc;
  98. /* XXX unify with device reference counting and delete */
  99. u32 started_request_count;
  100. struct isci_request *working_request;
  101. u32 not_ready_reason;
  102. scics_sds_remote_node_context_callback abort_resume_cb;
  103. void *abort_resume_cbparam;
  104. };
  105. #define ISCI_REMOTE_DEVICE_START_TIMEOUT 5000
  106. /* device reference routines must be called under sci_lock */
  107. static inline struct isci_remote_device *isci_get_device(
  108. struct isci_remote_device *idev)
  109. {
  110. if (idev)
  111. kref_get(&idev->kref);
  112. return idev;
  113. }
  114. static inline struct isci_remote_device *isci_lookup_device(struct domain_device *dev)
  115. {
  116. struct isci_remote_device *idev = dev->lldd_dev;
  117. if (idev && !test_bit(IDEV_GONE, &idev->flags)) {
  118. kref_get(&idev->kref);
  119. return idev;
  120. }
  121. return NULL;
  122. }
  123. void isci_remote_device_release(struct kref *kref);
  124. static inline void isci_put_device(struct isci_remote_device *idev)
  125. {
  126. if (idev)
  127. kref_put(&idev->kref, isci_remote_device_release);
  128. }
  129. enum sci_status isci_remote_device_stop(struct isci_host *ihost,
  130. struct isci_remote_device *idev);
  131. void isci_remote_device_nuke_requests(struct isci_host *ihost,
  132. struct isci_remote_device *idev);
  133. void isci_remote_device_gone(struct domain_device *domain_dev);
  134. int isci_remote_device_found(struct domain_device *domain_dev);
  135. /**
  136. * sci_remote_device_stop() - This method will stop both transmission and
  137. * reception of link activity for the supplied remote device. This method
  138. * disables normal IO requests from flowing through to the remote device.
  139. * @remote_device: This parameter specifies the device to be stopped.
  140. * @timeout: This parameter specifies the number of milliseconds in which the
  141. * stop operation should complete.
  142. *
  143. * An indication of whether the device was successfully stopped. SCI_SUCCESS
  144. * This value is returned if the transmission and reception for the device was
  145. * successfully stopped.
  146. */
  147. enum sci_status sci_remote_device_stop(
  148. struct isci_remote_device *idev,
  149. u32 timeout);
  150. /**
  151. * sci_remote_device_reset() - This method will reset the device making it
  152. * ready for operation. This method must be called anytime the device is
  153. * reset either through a SMP phy control or a port hard reset request.
  154. * @remote_device: This parameter specifies the device to be reset.
  155. *
  156. * This method does not actually cause the device hardware to be reset. This
  157. * method resets the software object so that it will be operational after a
  158. * device hardware reset completes. An indication of whether the device reset
  159. * was accepted. SCI_SUCCESS This value is returned if the device reset is
  160. * started.
  161. */
  162. enum sci_status sci_remote_device_reset(
  163. struct isci_remote_device *idev);
  164. /**
  165. * sci_remote_device_reset_complete() - This method informs the device object
  166. * that the reset operation is complete and the device can resume operation
  167. * again.
  168. * @remote_device: This parameter specifies the device which is to be informed
  169. * of the reset complete operation.
  170. *
  171. * An indication that the device is resuming operation. SCI_SUCCESS the device
  172. * is resuming operation.
  173. */
  174. enum sci_status sci_remote_device_reset_complete(
  175. struct isci_remote_device *idev);
  176. /**
  177. * enum sci_remote_device_states - This enumeration depicts all the states
  178. * for the common remote device state machine.
  179. * @SCI_DEV_INITIAL: Simply the initial state for the base remote device
  180. * state machine.
  181. *
  182. * @SCI_DEV_STOPPED: This state indicates that the remote device has
  183. * successfully been stopped. In this state no new IO operations are
  184. * permitted. This state is entered from the INITIAL state. This state
  185. * is entered from the STOPPING state.
  186. *
  187. * @SCI_DEV_STARTING: This state indicates the the remote device is in
  188. * the process of becoming ready (i.e. starting). In this state no new
  189. * IO operations are permitted. This state is entered from the STOPPED
  190. * state.
  191. *
  192. * @SCI_DEV_READY: This state indicates the remote device is now ready.
  193. * Thus, the user is able to perform IO operations on the remote device.
  194. * This state is entered from the STARTING state.
  195. *
  196. * @SCI_STP_DEV_IDLE: This is the idle substate for the stp remote
  197. * device. When there are no active IO for the device it is is in this
  198. * state.
  199. *
  200. * @SCI_STP_DEV_CMD: This is the command state for for the STP remote
  201. * device. This state is entered when the device is processing a
  202. * non-NCQ command. The device object will fail any new start IO
  203. * requests until this command is complete.
  204. *
  205. * @SCI_STP_DEV_NCQ: This is the NCQ state for the STP remote device.
  206. * This state is entered when the device is processing an NCQ reuqest.
  207. * It will remain in this state so long as there is one or more NCQ
  208. * requests being processed.
  209. *
  210. * @SCI_STP_DEV_NCQ_ERROR: This is the NCQ error state for the STP
  211. * remote device. This state is entered when an SDB error FIS is
  212. * received by the device object while in the NCQ state. The device
  213. * object will only accept a READ LOG command while in this state.
  214. *
  215. * @SCI_STP_DEV_ATAPI_ERROR: This is the ATAPI error state for the STP
  216. * ATAPI remote device. This state is entered when ATAPI device sends
  217. * error status FIS without data while the device object is in CMD
  218. * state. A suspension event is expected in this state. The device
  219. * object will resume right away.
  220. *
  221. * @SCI_STP_DEV_AWAIT_RESET: This is the READY substate indicates the
  222. * device is waiting for the RESET task coming to be recovered from
  223. * certain hardware specific error.
  224. *
  225. * @SCI_SMP_DEV_IDLE: This is the ready operational substate for the
  226. * remote device. This is the normal operational state for a remote
  227. * device.
  228. *
  229. * @SCI_SMP_DEV_CMD: This is the suspended state for the remote device.
  230. * This is the state that the device is placed in when a RNC suspend is
  231. * received by the SCU hardware.
  232. *
  233. * @SCI_DEV_STOPPING: This state indicates that the remote device is in
  234. * the process of stopping. In this state no new IO operations are
  235. * permitted, but existing IO operations are allowed to complete. This
  236. * state is entered from the READY state. This state is entered from
  237. * the FAILED state.
  238. *
  239. * @SCI_DEV_FAILED: This state indicates that the remote device has
  240. * failed. In this state no new IO operations are permitted. This
  241. * state is entered from the INITIALIZING state. This state is entered
  242. * from the READY state.
  243. *
  244. * @SCI_DEV_RESETTING: This state indicates the device is being reset.
  245. * In this state no new IO operations are permitted. This state is
  246. * entered from the READY state.
  247. *
  248. * @SCI_DEV_FINAL: Simply the final state for the base remote device
  249. * state machine.
  250. */
  251. #define REMOTE_DEV_STATES {\
  252. C(DEV_INITIAL),\
  253. C(DEV_STOPPED),\
  254. C(DEV_STARTING),\
  255. C(DEV_READY),\
  256. C(STP_DEV_IDLE),\
  257. C(STP_DEV_CMD),\
  258. C(STP_DEV_NCQ),\
  259. C(STP_DEV_NCQ_ERROR),\
  260. C(STP_DEV_ATAPI_ERROR),\
  261. C(STP_DEV_AWAIT_RESET),\
  262. C(SMP_DEV_IDLE),\
  263. C(SMP_DEV_CMD),\
  264. C(DEV_STOPPING),\
  265. C(DEV_FAILED),\
  266. C(DEV_RESETTING),\
  267. C(DEV_FINAL),\
  268. }
  269. #undef C
  270. #define C(a) SCI_##a
  271. enum sci_remote_device_states REMOTE_DEV_STATES;
  272. #undef C
  273. const char *dev_state_name(enum sci_remote_device_states state);
  274. static inline struct isci_remote_device *rnc_to_dev(struct sci_remote_node_context *rnc)
  275. {
  276. struct isci_remote_device *idev;
  277. idev = container_of(rnc, typeof(*idev), rnc);
  278. return idev;
  279. }
  280. static inline bool dev_is_expander(struct domain_device *dev)
  281. {
  282. return dev->dev_type == SAS_EDGE_EXPANDER_DEVICE || dev->dev_type == SAS_FANOUT_EXPANDER_DEVICE;
  283. }
  284. static inline void sci_remote_device_decrement_request_count(struct isci_remote_device *idev)
  285. {
  286. /* XXX delete this voodoo when converting to the top-level device
  287. * reference count
  288. */
  289. if (WARN_ONCE(idev->started_request_count == 0,
  290. "%s: tried to decrement started_request_count past 0!?",
  291. __func__))
  292. /* pass */;
  293. else
  294. idev->started_request_count--;
  295. }
  296. void isci_dev_set_hang_detection_timeout(struct isci_remote_device *idev, u32 timeout);
  297. enum sci_status sci_remote_device_frame_handler(
  298. struct isci_remote_device *idev,
  299. u32 frame_index);
  300. enum sci_status sci_remote_device_event_handler(
  301. struct isci_remote_device *idev,
  302. u32 event_code);
  303. enum sci_status sci_remote_device_start_io(
  304. struct isci_host *ihost,
  305. struct isci_remote_device *idev,
  306. struct isci_request *ireq);
  307. enum sci_status sci_remote_device_start_task(
  308. struct isci_host *ihost,
  309. struct isci_remote_device *idev,
  310. struct isci_request *ireq);
  311. enum sci_status sci_remote_device_complete_io(
  312. struct isci_host *ihost,
  313. struct isci_remote_device *idev,
  314. struct isci_request *ireq);
  315. void sci_remote_device_post_request(
  316. struct isci_remote_device *idev,
  317. u32 request);
  318. enum sci_status sci_remote_device_terminate_requests(
  319. struct isci_remote_device *idev);
  320. int isci_remote_device_is_safe_to_abort(
  321. struct isci_remote_device *idev);
  322. enum sci_status
  323. sci_remote_device_abort_requests_pending_abort(
  324. struct isci_remote_device *idev);
  325. enum sci_status isci_remote_device_suspend(
  326. struct isci_host *ihost,
  327. struct isci_remote_device *idev);
  328. enum sci_status sci_remote_device_resume(
  329. struct isci_remote_device *idev,
  330. scics_sds_remote_node_context_callback cb_fn,
  331. void *cb_p);
  332. enum sci_status isci_remote_device_resume_from_abort(
  333. struct isci_host *ihost,
  334. struct isci_remote_device *idev);
  335. enum sci_status isci_remote_device_reset(
  336. struct isci_host *ihost,
  337. struct isci_remote_device *idev);
  338. enum sci_status isci_remote_device_reset_complete(
  339. struct isci_host *ihost,
  340. struct isci_remote_device *idev);
  341. enum sci_status isci_remote_device_suspend_terminate(
  342. struct isci_host *ihost,
  343. struct isci_remote_device *idev,
  344. struct isci_request *ireq);
  345. enum sci_status isci_remote_device_terminate_requests(
  346. struct isci_host *ihost,
  347. struct isci_remote_device *idev,
  348. struct isci_request *ireq);
  349. enum sci_status sci_remote_device_suspend(struct isci_remote_device *idev,
  350. enum sci_remote_node_suspension_reasons reason);
  351. #endif /* !defined(_ISCI_REMOTE_DEVICE_H_) */