remote_device.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  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 scic_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. struct scic_sds_remote_device {
  71. /**
  72. * This field contains the information for the base remote device state
  73. * machine.
  74. */
  75. struct sci_base_state_machine sm;
  76. /**
  77. * This field is the programmed device port width. This value is
  78. * written to the RCN data structure to tell the SCU how many open
  79. * connections this device can have.
  80. */
  81. u32 device_port_width;
  82. /**
  83. * This field is the programmed connection rate for this remote device. It is
  84. * used to program the TC with the maximum allowed connection rate.
  85. */
  86. enum sas_linkrate connection_rate;
  87. /**
  88. * This filed is assinged the value of true if the device is directly
  89. * attached to the port.
  90. */
  91. bool is_direct_attached;
  92. /**
  93. * This filed contains a pointer back to the port to which this device
  94. * is assigned.
  95. */
  96. struct scic_sds_port *owning_port;
  97. /**
  98. * This field contains the SCU silicon remote node context specific
  99. * information.
  100. */
  101. struct scic_sds_remote_node_context rnc;
  102. /**
  103. * This field contains the stated request count for the remote device. The
  104. * device can not reach the SCI_DEV_STOPPED until all
  105. * requests are complete and the rnc_posted value is false.
  106. */
  107. u32 started_request_count;
  108. /**
  109. * This field contains a pointer to the working request object. It is only
  110. * used only for SATA requests since the unsolicited frames we get from the
  111. * hardware have no Tag value to look up the io request object.
  112. */
  113. struct scic_sds_request *working_request;
  114. /**
  115. * This field contains the reason for the remote device going not_ready. It is
  116. * assigned in the state handlers and used in the state transition.
  117. */
  118. u32 not_ready_reason;
  119. };
  120. struct isci_remote_device {
  121. enum isci_status status;
  122. #define IDEV_START_PENDING 0
  123. #define IDEV_STOP_PENDING 1
  124. #define IDEV_ALLOCATED 2
  125. #define IDEV_EH 3
  126. #define IDEV_GONE 4
  127. unsigned long flags;
  128. struct kref kref;
  129. struct isci_port *isci_port;
  130. struct domain_device *domain_dev;
  131. struct list_head node;
  132. struct list_head reqs_in_process;
  133. spinlock_t state_lock;
  134. struct scic_sds_remote_device sci;
  135. };
  136. #define ISCI_REMOTE_DEVICE_START_TIMEOUT 5000
  137. /* device reference routines must be called under scic_lock */
  138. static inline struct isci_remote_device *isci_lookup_device(struct domain_device *dev)
  139. {
  140. struct isci_remote_device *idev = dev->lldd_dev;
  141. if (idev && !test_bit(IDEV_GONE, &idev->flags)) {
  142. kref_get(&idev->kref);
  143. return idev;
  144. }
  145. return NULL;
  146. }
  147. void isci_remote_device_release(struct kref *kref);
  148. static inline void isci_put_device(struct isci_remote_device *idev)
  149. {
  150. if (idev)
  151. kref_put(&idev->kref, isci_remote_device_release);
  152. }
  153. enum sci_status isci_remote_device_stop(struct isci_host *ihost,
  154. struct isci_remote_device *idev);
  155. void isci_remote_device_nuke_requests(struct isci_host *ihost,
  156. struct isci_remote_device *idev);
  157. void isci_remote_device_gone(struct domain_device *domain_dev);
  158. int isci_remote_device_found(struct domain_device *domain_dev);
  159. bool isci_device_is_reset_pending(struct isci_host *ihost,
  160. struct isci_remote_device *idev);
  161. void isci_device_clear_reset_pending(struct isci_host *ihost,
  162. struct isci_remote_device *idev);
  163. void isci_remote_device_change_state(struct isci_remote_device *idev,
  164. enum isci_status status);
  165. /**
  166. * scic_remote_device_stop() - This method will stop both transmission and
  167. * reception of link activity for the supplied remote device. This method
  168. * disables normal IO requests from flowing through to the remote device.
  169. * @remote_device: This parameter specifies the device to be stopped.
  170. * @timeout: This parameter specifies the number of milliseconds in which the
  171. * stop operation should complete.
  172. *
  173. * An indication of whether the device was successfully stopped. SCI_SUCCESS
  174. * This value is returned if the transmission and reception for the device was
  175. * successfully stopped.
  176. */
  177. enum sci_status scic_remote_device_stop(
  178. struct scic_sds_remote_device *remote_device,
  179. u32 timeout);
  180. /**
  181. * scic_remote_device_reset() - This method will reset the device making it
  182. * ready for operation. This method must be called anytime the device is
  183. * reset either through a SMP phy control or a port hard reset request.
  184. * @remote_device: This parameter specifies the device to be reset.
  185. *
  186. * This method does not actually cause the device hardware to be reset. This
  187. * method resets the software object so that it will be operational after a
  188. * device hardware reset completes. An indication of whether the device reset
  189. * was accepted. SCI_SUCCESS This value is returned if the device reset is
  190. * started.
  191. */
  192. enum sci_status scic_remote_device_reset(
  193. struct scic_sds_remote_device *remote_device);
  194. /**
  195. * scic_remote_device_reset_complete() - This method informs the device object
  196. * that the reset operation is complete and the device can resume operation
  197. * again.
  198. * @remote_device: This parameter specifies the device which is to be informed
  199. * of the reset complete operation.
  200. *
  201. * An indication that the device is resuming operation. SCI_SUCCESS the device
  202. * is resuming operation.
  203. */
  204. enum sci_status scic_remote_device_reset_complete(
  205. struct scic_sds_remote_device *remote_device);
  206. #define scic_remote_device_is_atapi(device_handle) false
  207. /**
  208. * enum scic_sds_remote_device_states - This enumeration depicts all the states
  209. * for the common remote device state machine.
  210. *
  211. *
  212. */
  213. enum scic_sds_remote_device_states {
  214. /**
  215. * Simply the initial state for the base remote device state machine.
  216. */
  217. SCI_DEV_INITIAL,
  218. /**
  219. * This state indicates that the remote device has successfully been
  220. * stopped. In this state no new IO operations are permitted.
  221. * This state is entered from the INITIAL state.
  222. * This state is entered from the STOPPING state.
  223. */
  224. SCI_DEV_STOPPED,
  225. /**
  226. * This state indicates the the remote device is in the process of
  227. * becoming ready (i.e. starting). In this state no new IO operations
  228. * are permitted.
  229. * This state is entered from the STOPPED state.
  230. */
  231. SCI_DEV_STARTING,
  232. /**
  233. * This state indicates the remote device is now ready. Thus, the user
  234. * is able to perform IO operations on the remote device.
  235. * This state is entered from the STARTING state.
  236. */
  237. SCI_DEV_READY,
  238. /**
  239. * This is the idle substate for the stp remote device. When there are no
  240. * active IO for the device it is is in this state.
  241. */
  242. SCI_STP_DEV_IDLE,
  243. /**
  244. * This is the command state for for the STP remote device. This state is
  245. * entered when the device is processing a non-NCQ command. The device object
  246. * will fail any new start IO requests until this command is complete.
  247. */
  248. SCI_STP_DEV_CMD,
  249. /**
  250. * This is the NCQ state for the STP remote device. This state is entered
  251. * when the device is processing an NCQ reuqest. It will remain in this state
  252. * so long as there is one or more NCQ requests being processed.
  253. */
  254. SCI_STP_DEV_NCQ,
  255. /**
  256. * This is the NCQ error state for the STP remote device. This state is
  257. * entered when an SDB error FIS is received by the device object while in the
  258. * NCQ state. The device object will only accept a READ LOG command while in
  259. * this state.
  260. */
  261. SCI_STP_DEV_NCQ_ERROR,
  262. /**
  263. * This is the READY substate indicates the device is waiting for the RESET task
  264. * coming to be recovered from certain hardware specific error.
  265. */
  266. SCI_STP_DEV_AWAIT_RESET,
  267. /**
  268. * This is the ready operational substate for the remote device. This is the
  269. * normal operational state for a remote device.
  270. */
  271. SCI_SMP_DEV_IDLE,
  272. /**
  273. * This is the suspended state for the remote device. This is the state that
  274. * the device is placed in when a RNC suspend is received by the SCU hardware.
  275. */
  276. SCI_SMP_DEV_CMD,
  277. /**
  278. * This state indicates that the remote device is in the process of
  279. * stopping. In this state no new IO operations are permitted, but
  280. * existing IO operations are allowed to complete.
  281. * This state is entered from the READY state.
  282. * This state is entered from the FAILED state.
  283. */
  284. SCI_DEV_STOPPING,
  285. /**
  286. * This state indicates that the remote device has failed.
  287. * In this state no new IO operations are permitted.
  288. * This state is entered from the INITIALIZING state.
  289. * This state is entered from the READY state.
  290. */
  291. SCI_DEV_FAILED,
  292. /**
  293. * This state indicates the device is being reset.
  294. * In this state no new IO operations are permitted.
  295. * This state is entered from the READY state.
  296. */
  297. SCI_DEV_RESETTING,
  298. /**
  299. * Simply the final state for the base remote device state machine.
  300. */
  301. SCI_DEV_FINAL,
  302. };
  303. static inline struct scic_sds_remote_device *rnc_to_dev(struct scic_sds_remote_node_context *rnc)
  304. {
  305. struct scic_sds_remote_device *sci_dev;
  306. sci_dev = container_of(rnc, typeof(*sci_dev), rnc);
  307. return sci_dev;
  308. }
  309. static inline struct isci_remote_device *sci_dev_to_idev(struct scic_sds_remote_device *sci_dev)
  310. {
  311. struct isci_remote_device *idev = container_of(sci_dev, typeof(*idev), sci);
  312. return idev;
  313. }
  314. static inline struct domain_device *sci_dev_to_domain(struct scic_sds_remote_device *sci_dev)
  315. {
  316. return sci_dev_to_idev(sci_dev)->domain_dev;
  317. }
  318. static inline bool dev_is_expander(struct domain_device *dev)
  319. {
  320. return dev->dev_type == EDGE_DEV || dev->dev_type == FANOUT_DEV;
  321. }
  322. /**
  323. * scic_sds_remote_device_increment_request_count() -
  324. *
  325. * This macro incrments the request count for this device
  326. */
  327. #define scic_sds_remote_device_increment_request_count(sci_dev) \
  328. ((sci_dev)->started_request_count++)
  329. /**
  330. * scic_sds_remote_device_decrement_request_count() -
  331. *
  332. * This macro decrements the request count for this device. This count will
  333. * never decrment past 0.
  334. */
  335. #define scic_sds_remote_device_decrement_request_count(sci_dev) \
  336. ((sci_dev)->started_request_count > 0 ? \
  337. (sci_dev)->started_request_count-- : 0)
  338. /**
  339. * scic_sds_remote_device_get_request_count() -
  340. *
  341. * This is a helper macro to return the current device request count.
  342. */
  343. #define scic_sds_remote_device_get_request_count(sci_dev) \
  344. ((sci_dev)->started_request_count)
  345. /**
  346. * scic_sds_remote_device_get_port() -
  347. *
  348. * This macro returns the owning port of this remote device obejct.
  349. */
  350. #define scic_sds_remote_device_get_port(sci_dev) \
  351. ((sci_dev)->owning_port)
  352. /**
  353. * scic_sds_remote_device_get_controller() -
  354. *
  355. * This macro returns the controller object that contains this device object
  356. */
  357. #define scic_sds_remote_device_get_controller(sci_dev) \
  358. scic_sds_port_get_controller(scic_sds_remote_device_get_port(sci_dev))
  359. /**
  360. * scic_sds_remote_device_get_port() -
  361. *
  362. * This macro returns the owning port of this device
  363. */
  364. #define scic_sds_remote_device_get_port(sci_dev) \
  365. ((sci_dev)->owning_port)
  366. /**
  367. * scic_sds_remote_device_get_sequence() -
  368. *
  369. * This macro returns the remote device sequence value
  370. */
  371. #define scic_sds_remote_device_get_sequence(sci_dev) \
  372. (\
  373. scic_sds_remote_device_get_controller(sci_dev)-> \
  374. remote_device_sequence[(sci_dev)->rnc.remote_node_index] \
  375. )
  376. /**
  377. * scic_sds_remote_device_get_controller_peg() -
  378. *
  379. * This macro returns the controllers protocol engine group
  380. */
  381. #define scic_sds_remote_device_get_controller_peg(sci_dev) \
  382. (\
  383. scic_sds_controller_get_protocol_engine_group(\
  384. scic_sds_port_get_controller(\
  385. scic_sds_remote_device_get_port(sci_dev) \
  386. ) \
  387. ) \
  388. )
  389. /**
  390. * scic_sds_remote_device_get_index() -
  391. *
  392. * This macro returns the remote node index for this device object
  393. */
  394. #define scic_sds_remote_device_get_index(sci_dev) \
  395. ((sci_dev)->rnc.remote_node_index)
  396. /**
  397. * scic_sds_remote_device_build_command_context() -
  398. *
  399. * This macro builds a remote device context for the SCU post request operation
  400. */
  401. #define scic_sds_remote_device_build_command_context(device, command) \
  402. ((command) \
  403. | (scic_sds_remote_device_get_controller_peg((device)) << SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) \
  404. | ((device)->owning_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) \
  405. | (scic_sds_remote_device_get_index((device))) \
  406. )
  407. /**
  408. * scic_sds_remote_device_set_working_request() -
  409. *
  410. * This macro makes the working request assingment for the remote device
  411. * object. To clear the working request use this macro with a NULL request
  412. * object.
  413. */
  414. #define scic_sds_remote_device_set_working_request(device, request) \
  415. ((device)->working_request = (request))
  416. enum sci_status scic_sds_remote_device_frame_handler(
  417. struct scic_sds_remote_device *sci_dev,
  418. u32 frame_index);
  419. enum sci_status scic_sds_remote_device_event_handler(
  420. struct scic_sds_remote_device *sci_dev,
  421. u32 event_code);
  422. enum sci_status scic_sds_remote_device_start_io(
  423. struct scic_sds_controller *controller,
  424. struct scic_sds_remote_device *sci_dev,
  425. struct scic_sds_request *io_request);
  426. enum sci_status scic_sds_remote_device_start_task(
  427. struct scic_sds_controller *controller,
  428. struct scic_sds_remote_device *sci_dev,
  429. struct scic_sds_request *io_request);
  430. enum sci_status scic_sds_remote_device_complete_io(
  431. struct scic_sds_controller *controller,
  432. struct scic_sds_remote_device *sci_dev,
  433. struct scic_sds_request *io_request);
  434. enum sci_status scic_sds_remote_device_suspend(
  435. struct scic_sds_remote_device *sci_dev,
  436. u32 suspend_type);
  437. void scic_sds_remote_device_post_request(
  438. struct scic_sds_remote_device *sci_dev,
  439. u32 request);
  440. #define scic_sds_remote_device_is_atapi(sci_dev) false
  441. #endif /* !defined(_ISCI_REMOTE_DEVICE_H_) */