smp_remote_device.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. #include "scic_sds_controller.h"
  56. #include "scic_sds_port.h"
  57. #include "remote_device.h"
  58. #include "scic_sds_request.h"
  59. #include "sci_environment.h"
  60. #include "sci_util.h"
  61. #include "scu_event_codes.h"
  62. #include "scu_task_context.h"
  63. /*
  64. * *****************************************************************************
  65. * * SMP REMOTE DEVICE READY IDLE SUBSTATE HANDLERS
  66. * ***************************************************************************** */
  67. /**
  68. *
  69. * @[in]: device The device the io is sent to.
  70. * @[in]: request The io to start.
  71. *
  72. * This method will handle the start io operation for a SMP device that is in
  73. * the idle state. enum sci_status
  74. */
  75. static enum sci_status scic_sds_smp_remote_device_ready_idle_substate_start_io_handler(
  76. struct scic_sds_remote_device *device,
  77. struct scic_sds_request *request)
  78. {
  79. enum sci_status status;
  80. /* Will the port allow the io request to start? */
  81. status = device->owning_port->state_handlers->start_io_handler(
  82. device->owning_port, device, request);
  83. if (status == SCI_SUCCESS) {
  84. status = scic_sds_remote_node_context_start_io(&device->rnc, request);
  85. if (status == SCI_SUCCESS)
  86. status = scic_sds_request_start(request);
  87. if (status == SCI_SUCCESS) {
  88. device->working_request = request;
  89. sci_base_state_machine_change_state(
  90. &device->ready_substate_machine,
  91. SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD
  92. );
  93. }
  94. scic_sds_remote_device_start_request(device, request, status);
  95. }
  96. return status;
  97. }
  98. /*
  99. * ******************************************************************************
  100. * * SMP REMOTE DEVICE READY SUBSTATE CMD HANDLERS
  101. * ****************************************************************************** */
  102. /**
  103. *
  104. * @device: This is the device object that is receiving the IO.
  105. * @request: The io to start.
  106. *
  107. * This device is already handling a command it can not accept new commands
  108. * until this one is complete. enum sci_status
  109. */
  110. static enum sci_status scic_sds_smp_remote_device_ready_cmd_substate_start_io_handler(
  111. struct scic_sds_remote_device *device,
  112. struct scic_sds_request *request)
  113. {
  114. return SCI_FAILURE_INVALID_STATE;
  115. }
  116. /**
  117. * this is the complete_io_handler for smp device at ready cmd substate.
  118. * @device: This is the device object that is receiving the IO.
  119. * @request: The io to start.
  120. *
  121. * enum sci_status
  122. */
  123. static enum sci_status
  124. scic_sds_smp_remote_device_ready_cmd_substate_complete_io_handler(
  125. struct scic_sds_remote_device *device,
  126. struct scic_sds_request *request)
  127. {
  128. enum sci_status status;
  129. struct scic_sds_request *sci_req;
  130. sci_req = (struct scic_sds_request *)request;
  131. status = scic_sds_io_request_complete(sci_req);
  132. if (status == SCI_SUCCESS) {
  133. status = scic_sds_port_complete_io(
  134. device->owning_port, device, sci_req);
  135. if (status == SCI_SUCCESS) {
  136. scic_sds_remote_device_decrement_request_count(device);
  137. sci_base_state_machine_change_state(
  138. &device->ready_substate_machine,
  139. SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE
  140. );
  141. } else
  142. dev_err(scirdev_to_dev(device),
  143. "%s: SCIC SDS Remote Device 0x%p io request "
  144. "0x%p could not be completd on the port 0x%p "
  145. "failed with status %d.\n",
  146. __func__,
  147. device,
  148. sci_req,
  149. device->owning_port,
  150. status);
  151. }
  152. return status;
  153. }
  154. /**
  155. * This is frame handler for smp device ready cmd substate.
  156. * @sci_dev: This is the device object that is receiving the frame.
  157. * @frame_index: The index for the frame received.
  158. *
  159. * enum sci_status
  160. */
  161. static enum sci_status scic_sds_smp_remote_device_ready_cmd_substate_frame_handler(
  162. struct scic_sds_remote_device *sci_dev,
  163. u32 frame_index)
  164. {
  165. enum sci_status status;
  166. /*
  167. * / The device does not process any UF received from the hardware while
  168. * / in this state. All unsolicited frames are forwarded to the io request
  169. * / object. */
  170. status = scic_sds_io_request_frame_handler(
  171. sci_dev->working_request,
  172. frame_index
  173. );
  174. return status;
  175. }
  176. /* --------------------------------------------------------------------------- */
  177. static const struct scic_sds_remote_device_state_handler scic_sds_smp_remote_device_ready_substate_handler_table[] = {
  178. [SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE] = {
  179. .start_handler = scic_sds_remote_device_default_start_handler,
  180. .stop_handler = scic_sds_remote_device_ready_state_stop_handler,
  181. .fail_handler = scic_sds_remote_device_default_fail_handler,
  182. .destruct_handler = scic_sds_remote_device_default_destruct_handler,
  183. .reset_handler = scic_sds_remote_device_default_reset_handler,
  184. .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
  185. .start_io_handler = scic_sds_smp_remote_device_ready_idle_substate_start_io_handler,
  186. .complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
  187. .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
  188. .start_task_handler = scic_sds_remote_device_default_start_request_handler,
  189. .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
  190. .suspend_handler = scic_sds_remote_device_default_suspend_handler,
  191. .resume_handler = scic_sds_remote_device_default_resume_handler,
  192. .event_handler = scic_sds_remote_device_general_event_handler,
  193. .frame_handler = scic_sds_remote_device_default_frame_handler
  194. },
  195. [SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD] = {
  196. .start_handler = scic_sds_remote_device_default_start_handler,
  197. .stop_handler = scic_sds_remote_device_ready_state_stop_handler,
  198. .fail_handler = scic_sds_remote_device_default_fail_handler,
  199. .destruct_handler = scic_sds_remote_device_default_destruct_handler,
  200. .reset_handler = scic_sds_remote_device_default_reset_handler,
  201. .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
  202. .start_io_handler = scic_sds_smp_remote_device_ready_cmd_substate_start_io_handler,
  203. .complete_io_handler = scic_sds_smp_remote_device_ready_cmd_substate_complete_io_handler,
  204. .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
  205. .start_task_handler = scic_sds_remote_device_default_start_request_handler,
  206. .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
  207. .suspend_handler = scic_sds_remote_device_default_suspend_handler,
  208. .resume_handler = scic_sds_remote_device_default_resume_handler,
  209. .event_handler = scic_sds_remote_device_general_event_handler,
  210. .frame_handler = scic_sds_smp_remote_device_ready_cmd_substate_frame_handler
  211. }
  212. };
  213. /**
  214. *
  215. * @object: This is the object which is cast into a
  216. * struct scic_sds_remote_device.
  217. *
  218. * This is the SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE enter method.
  219. * This function sets the ready cmd substate handlers and reports the device as
  220. * ready. none
  221. */
  222. static void scic_sds_smp_remote_device_ready_idle_substate_enter(void *object)
  223. {
  224. struct scic_sds_remote_device *sci_dev = object;
  225. struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev);
  226. struct isci_host *ihost = scic->ihost;
  227. struct isci_remote_device *idev = sci_dev_to_idev(sci_dev);
  228. SET_STATE_HANDLER(sci_dev,
  229. scic_sds_smp_remote_device_ready_substate_handler_table,
  230. SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
  231. isci_remote_device_ready(ihost, idev);
  232. }
  233. /**
  234. *
  235. * @object: This is the object which is cast into a
  236. * struct scic_sds_remote_device.
  237. *
  238. * This is the SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD enter method. This
  239. * function sets the remote device objects ready cmd substate handlers, and
  240. * notify core user that the device is not ready. none
  241. */
  242. static void scic_sds_smp_remote_device_ready_cmd_substate_enter(void *object)
  243. {
  244. struct scic_sds_remote_device *sci_dev = object;
  245. struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev);
  246. struct isci_host *ihost = scic->ihost;
  247. struct isci_remote_device *idev = sci_dev_to_idev(sci_dev);
  248. BUG_ON(sci_dev->working_request == NULL);
  249. SET_STATE_HANDLER(sci_dev,
  250. scic_sds_smp_remote_device_ready_substate_handler_table,
  251. SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD);
  252. isci_remote_device_not_ready(ihost, idev,
  253. SCIC_REMOTE_DEVICE_NOT_READY_SMP_REQUEST_STARTED);
  254. }
  255. /**
  256. *
  257. * @object: This is the object which is cast into a
  258. * struct scic_sds_remote_device.
  259. *
  260. * This is the SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATE_CMD exit method. none
  261. */
  262. static void scic_sds_smp_remote_device_ready_cmd_substate_exit(void *object)
  263. {
  264. struct scic_sds_remote_device *sci_dev = object;
  265. sci_dev->working_request = NULL;
  266. }
  267. /* --------------------------------------------------------------------------- */
  268. const struct sci_base_state scic_sds_smp_remote_device_ready_substate_table[] = {
  269. [SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE] = {
  270. .enter_state = scic_sds_smp_remote_device_ready_idle_substate_enter,
  271. },
  272. [SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD] = {
  273. .enter_state = scic_sds_smp_remote_device_ready_cmd_substate_enter,
  274. .exit_state = scic_sds_smp_remote_device_ready_cmd_substate_exit,
  275. },
  276. };