remote_device.c 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554
  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 <scsi/sas.h>
  56. #include "isci.h"
  57. #include "port.h"
  58. #include "remote_device.h"
  59. #include "request.h"
  60. #include "remote_node_context.h"
  61. #include "scu_event_codes.h"
  62. #include "task.h"
  63. /**
  64. * isci_remote_device_change_state() - This function gets the status of the
  65. * remote_device object.
  66. * @isci_device: This parameter points to the isci_remote_device object
  67. *
  68. * status of the object as a isci_status enum.
  69. */
  70. void isci_remote_device_change_state(
  71. struct isci_remote_device *isci_device,
  72. enum isci_status status)
  73. {
  74. unsigned long flags;
  75. spin_lock_irqsave(&isci_device->state_lock, flags);
  76. isci_device->status = status;
  77. spin_unlock_irqrestore(&isci_device->state_lock, flags);
  78. }
  79. /**
  80. * isci_remote_device_not_ready() - This function is called by the scic when
  81. * the remote device is not ready. We mark the isci device as ready (not
  82. * "ready_for_io") and signal the waiting proccess.
  83. * @isci_host: This parameter specifies the isci host object.
  84. * @isci_device: This parameter specifies the remote device
  85. *
  86. */
  87. static void isci_remote_device_not_ready(struct isci_host *ihost,
  88. struct isci_remote_device *idev, u32 reason)
  89. {
  90. dev_dbg(&ihost->pdev->dev,
  91. "%s: isci_device = %p\n", __func__, idev);
  92. if (reason == SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED)
  93. isci_remote_device_change_state(idev, isci_stopping);
  94. else
  95. /* device ready is actually a "not ready for io" state. */
  96. isci_remote_device_change_state(idev, isci_ready);
  97. }
  98. /**
  99. * isci_remote_device_ready() - This function is called by the scic when the
  100. * remote device is ready. We mark the isci device as ready and signal the
  101. * waiting proccess.
  102. * @ihost: our valid isci_host
  103. * @idev: remote device
  104. *
  105. */
  106. static void isci_remote_device_ready(struct isci_host *ihost, struct isci_remote_device *idev)
  107. {
  108. dev_dbg(&ihost->pdev->dev,
  109. "%s: idev = %p\n", __func__, idev);
  110. isci_remote_device_change_state(idev, isci_ready_for_io);
  111. if (test_and_clear_bit(IDEV_START_PENDING, &idev->flags))
  112. wake_up(&ihost->eventq);
  113. }
  114. /* called once the remote node context is ready to be freed.
  115. * The remote device can now report that its stop operation is complete. none
  116. */
  117. static void rnc_destruct_done(void *_dev)
  118. {
  119. struct scic_sds_remote_device *sci_dev = _dev;
  120. BUG_ON(sci_dev->started_request_count != 0);
  121. sci_base_state_machine_change_state(&sci_dev->state_machine,
  122. SCI_BASE_REMOTE_DEVICE_STATE_STOPPED);
  123. }
  124. static enum sci_status scic_sds_remote_device_terminate_requests(struct scic_sds_remote_device *sci_dev)
  125. {
  126. struct scic_sds_controller *scic = sci_dev->owning_port->owning_controller;
  127. u32 i, request_count = sci_dev->started_request_count;
  128. enum sci_status status = SCI_SUCCESS;
  129. for (i = 0; i < SCI_MAX_IO_REQUESTS && i < request_count; i++) {
  130. struct scic_sds_request *sci_req;
  131. enum sci_status s;
  132. sci_req = scic->io_request_table[i];
  133. if (!sci_req || sci_req->target_device != sci_dev)
  134. continue;
  135. s = scic_controller_terminate_request(scic, sci_dev, sci_req);
  136. if (s != SCI_SUCCESS)
  137. status = s;
  138. }
  139. return status;
  140. }
  141. enum sci_status scic_remote_device_stop(struct scic_sds_remote_device *sci_dev,
  142. u32 timeout)
  143. {
  144. struct sci_base_state_machine *sm = &sci_dev->state_machine;
  145. enum scic_sds_remote_device_states state = sm->current_state_id;
  146. switch (state) {
  147. case SCI_BASE_REMOTE_DEVICE_STATE_INITIAL:
  148. case SCI_BASE_REMOTE_DEVICE_STATE_FAILED:
  149. case SCI_BASE_REMOTE_DEVICE_STATE_FINAL:
  150. default:
  151. dev_warn(scirdev_to_dev(sci_dev), "%s: in wrong state: %d\n",
  152. __func__, state);
  153. return SCI_FAILURE_INVALID_STATE;
  154. case SCI_BASE_REMOTE_DEVICE_STATE_STOPPED:
  155. return SCI_SUCCESS;
  156. case SCI_BASE_REMOTE_DEVICE_STATE_STARTING:
  157. /* device not started so there had better be no requests */
  158. BUG_ON(sci_dev->started_request_count != 0);
  159. scic_sds_remote_node_context_destruct(&sci_dev->rnc,
  160. rnc_destruct_done, sci_dev);
  161. /* Transition to the stopping state and wait for the
  162. * remote node to complete being posted and invalidated.
  163. */
  164. sci_base_state_machine_change_state(sm, SCI_BASE_REMOTE_DEVICE_STATE_STOPPING);
  165. return SCI_SUCCESS;
  166. case SCI_BASE_REMOTE_DEVICE_STATE_READY:
  167. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE:
  168. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD:
  169. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ:
  170. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR:
  171. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET:
  172. case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE:
  173. case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD:
  174. sci_base_state_machine_change_state(sm, SCI_BASE_REMOTE_DEVICE_STATE_STOPPING);
  175. if (sci_dev->started_request_count == 0) {
  176. scic_sds_remote_node_context_destruct(&sci_dev->rnc,
  177. rnc_destruct_done, sci_dev);
  178. return SCI_SUCCESS;
  179. } else
  180. return scic_sds_remote_device_terminate_requests(sci_dev);
  181. break;
  182. case SCI_BASE_REMOTE_DEVICE_STATE_STOPPING:
  183. /* All requests should have been terminated, but if there is an
  184. * attempt to stop a device already in the stopping state, then
  185. * try again to terminate.
  186. */
  187. return scic_sds_remote_device_terminate_requests(sci_dev);
  188. case SCI_BASE_REMOTE_DEVICE_STATE_RESETTING:
  189. sci_base_state_machine_change_state(sm, SCI_BASE_REMOTE_DEVICE_STATE_STOPPING);
  190. return SCI_SUCCESS;
  191. }
  192. }
  193. enum sci_status scic_remote_device_reset(struct scic_sds_remote_device *sci_dev)
  194. {
  195. struct sci_base_state_machine *sm = &sci_dev->state_machine;
  196. enum scic_sds_remote_device_states state = sm->current_state_id;
  197. switch (state) {
  198. case SCI_BASE_REMOTE_DEVICE_STATE_INITIAL:
  199. case SCI_BASE_REMOTE_DEVICE_STATE_STOPPED:
  200. case SCI_BASE_REMOTE_DEVICE_STATE_STARTING:
  201. case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE:
  202. case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD:
  203. case SCI_BASE_REMOTE_DEVICE_STATE_STOPPING:
  204. case SCI_BASE_REMOTE_DEVICE_STATE_FAILED:
  205. case SCI_BASE_REMOTE_DEVICE_STATE_RESETTING:
  206. case SCI_BASE_REMOTE_DEVICE_STATE_FINAL:
  207. default:
  208. dev_warn(scirdev_to_dev(sci_dev), "%s: in wrong state: %d\n",
  209. __func__, state);
  210. return SCI_FAILURE_INVALID_STATE;
  211. case SCI_BASE_REMOTE_DEVICE_STATE_READY:
  212. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE:
  213. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD:
  214. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ:
  215. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR:
  216. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET:
  217. sci_base_state_machine_change_state(sm, SCI_BASE_REMOTE_DEVICE_STATE_RESETTING);
  218. return SCI_SUCCESS;
  219. }
  220. }
  221. enum sci_status scic_remote_device_reset_complete(struct scic_sds_remote_device *sci_dev)
  222. {
  223. struct sci_base_state_machine *sm = &sci_dev->state_machine;
  224. enum scic_sds_remote_device_states state = sm->current_state_id;
  225. if (state != SCI_BASE_REMOTE_DEVICE_STATE_RESETTING) {
  226. dev_warn(scirdev_to_dev(sci_dev), "%s: in wrong state: %d\n",
  227. __func__, state);
  228. return SCI_FAILURE_INVALID_STATE;
  229. }
  230. sci_base_state_machine_change_state(sm, SCI_BASE_REMOTE_DEVICE_STATE_READY);
  231. return SCI_SUCCESS;
  232. }
  233. enum sci_status scic_sds_remote_device_suspend(struct scic_sds_remote_device *sci_dev,
  234. u32 suspend_type)
  235. {
  236. struct sci_base_state_machine *sm = &sci_dev->state_machine;
  237. enum scic_sds_remote_device_states state = sm->current_state_id;
  238. if (state != SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD) {
  239. dev_warn(scirdev_to_dev(sci_dev), "%s: in wrong state: %d\n",
  240. __func__, state);
  241. return SCI_FAILURE_INVALID_STATE;
  242. }
  243. return scic_sds_remote_node_context_suspend(&sci_dev->rnc,
  244. suspend_type, NULL, NULL);
  245. }
  246. enum sci_status scic_sds_remote_device_frame_handler(struct scic_sds_remote_device *sci_dev,
  247. u32 frame_index)
  248. {
  249. struct sci_base_state_machine *sm = &sci_dev->state_machine;
  250. enum scic_sds_remote_device_states state = sm->current_state_id;
  251. struct scic_sds_controller *scic = sci_dev->owning_port->owning_controller;
  252. enum sci_status status;
  253. switch (state) {
  254. case SCI_BASE_REMOTE_DEVICE_STATE_INITIAL:
  255. case SCI_BASE_REMOTE_DEVICE_STATE_STOPPED:
  256. case SCI_BASE_REMOTE_DEVICE_STATE_STARTING:
  257. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE:
  258. case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE:
  259. case SCI_BASE_REMOTE_DEVICE_STATE_FINAL:
  260. default:
  261. dev_warn(scirdev_to_dev(sci_dev), "%s: in wrong state: %d\n",
  262. __func__, state);
  263. /* Return the frame back to the controller */
  264. scic_sds_controller_release_frame(scic, frame_index);
  265. return SCI_FAILURE_INVALID_STATE;
  266. case SCI_BASE_REMOTE_DEVICE_STATE_READY:
  267. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR:
  268. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET:
  269. case SCI_BASE_REMOTE_DEVICE_STATE_STOPPING:
  270. case SCI_BASE_REMOTE_DEVICE_STATE_FAILED:
  271. case SCI_BASE_REMOTE_DEVICE_STATE_RESETTING: {
  272. struct scic_sds_request *sci_req;
  273. struct ssp_frame_hdr hdr;
  274. void *frame_header;
  275. ssize_t word_cnt;
  276. status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
  277. frame_index,
  278. &frame_header);
  279. if (status != SCI_SUCCESS)
  280. return status;
  281. word_cnt = sizeof(hdr) / sizeof(u32);
  282. sci_swab32_cpy(&hdr, frame_header, word_cnt);
  283. sci_req = scic_request_by_tag(scic, be16_to_cpu(hdr.tag));
  284. if (sci_req && sci_req->target_device == sci_dev) {
  285. /* The IO request is now in charge of releasing the frame */
  286. status = sci_req->state_handlers->frame_handler(sci_req,
  287. frame_index);
  288. } else {
  289. /* We could not map this tag to a valid IO
  290. * request Just toss the frame and continue
  291. */
  292. scic_sds_controller_release_frame(scic, frame_index);
  293. }
  294. break;
  295. }
  296. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ: {
  297. struct dev_to_host_fis *hdr;
  298. status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
  299. frame_index,
  300. (void **)&hdr);
  301. if (status != SCI_SUCCESS)
  302. return status;
  303. if (hdr->fis_type == FIS_SETDEVBITS &&
  304. (hdr->status & ATA_ERR)) {
  305. sci_dev->not_ready_reason = SCIC_REMOTE_DEVICE_NOT_READY_SATA_SDB_ERROR_FIS_RECEIVED;
  306. /* TODO Check sactive and complete associated IO if any. */
  307. sci_base_state_machine_change_state(sm, SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR);
  308. } else if (hdr->fis_type == FIS_REGD2H &&
  309. (hdr->status & ATA_ERR)) {
  310. /*
  311. * Some devices return D2H FIS when an NCQ error is detected.
  312. * Treat this like an SDB error FIS ready reason.
  313. */
  314. sci_dev->not_ready_reason = SCIC_REMOTE_DEVICE_NOT_READY_SATA_SDB_ERROR_FIS_RECEIVED;
  315. sci_base_state_machine_change_state(&sci_dev->state_machine,
  316. SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR);
  317. } else
  318. status = SCI_FAILURE;
  319. scic_sds_controller_release_frame(scic, frame_index);
  320. break;
  321. }
  322. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD:
  323. case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD:
  324. /* The device does not process any UF received from the hardware while
  325. * in this state. All unsolicited frames are forwarded to the io request
  326. * object.
  327. */
  328. status = scic_sds_io_request_frame_handler(sci_dev->working_request, frame_index);
  329. break;
  330. }
  331. return status;
  332. }
  333. static bool is_remote_device_ready(struct scic_sds_remote_device *sci_dev)
  334. {
  335. struct sci_base_state_machine *sm = &sci_dev->state_machine;
  336. enum scic_sds_remote_device_states state = sm->current_state_id;
  337. switch (state) {
  338. case SCI_BASE_REMOTE_DEVICE_STATE_READY:
  339. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE:
  340. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD:
  341. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ:
  342. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR:
  343. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET:
  344. case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE:
  345. case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD:
  346. return true;
  347. default:
  348. return false;
  349. }
  350. }
  351. enum sci_status scic_sds_remote_device_event_handler(struct scic_sds_remote_device *sci_dev,
  352. u32 event_code)
  353. {
  354. struct sci_base_state_machine *sm = &sci_dev->state_machine;
  355. enum scic_sds_remote_device_states state = sm->current_state_id;
  356. enum sci_status status;
  357. switch (scu_get_event_type(event_code)) {
  358. case SCU_EVENT_TYPE_RNC_OPS_MISC:
  359. case SCU_EVENT_TYPE_RNC_SUSPEND_TX:
  360. case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX:
  361. status = scic_sds_remote_node_context_event_handler(&sci_dev->rnc, event_code);
  362. break;
  363. case SCU_EVENT_TYPE_PTX_SCHEDULE_EVENT:
  364. if (scu_get_event_code(event_code) == SCU_EVENT_IT_NEXUS_TIMEOUT) {
  365. status = SCI_SUCCESS;
  366. /* Suspend the associated RNC */
  367. scic_sds_remote_node_context_suspend(&sci_dev->rnc,
  368. SCI_SOFTWARE_SUSPENSION,
  369. NULL, NULL);
  370. dev_dbg(scirdev_to_dev(sci_dev),
  371. "%s: device: %p event code: %x: %s\n",
  372. __func__, sci_dev, event_code,
  373. is_remote_device_ready(sci_dev)
  374. ? "I_T_Nexus_Timeout event"
  375. : "I_T_Nexus_Timeout event in wrong state");
  376. break;
  377. }
  378. /* Else, fall through and treat as unhandled... */
  379. default:
  380. dev_dbg(scirdev_to_dev(sci_dev),
  381. "%s: device: %p event code: %x: %s\n",
  382. __func__, sci_dev, event_code,
  383. is_remote_device_ready(sci_dev)
  384. ? "unexpected event"
  385. : "unexpected event in wrong state");
  386. status = SCI_FAILURE_INVALID_STATE;
  387. break;
  388. }
  389. if (status != SCI_SUCCESS)
  390. return status;
  391. if (state == SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE) {
  392. /* We pick up suspension events to handle specifically to this
  393. * state. We resume the RNC right away.
  394. */
  395. if (scu_get_event_type(event_code) == SCU_EVENT_TYPE_RNC_SUSPEND_TX ||
  396. scu_get_event_type(event_code) == SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX)
  397. status = scic_sds_remote_node_context_resume(&sci_dev->rnc, NULL, NULL);
  398. }
  399. return status;
  400. }
  401. static void scic_sds_remote_device_start_request(struct scic_sds_remote_device *sci_dev,
  402. struct scic_sds_request *sci_req,
  403. enum sci_status status)
  404. {
  405. struct scic_sds_port *sci_port = sci_dev->owning_port;
  406. /* cleanup requests that failed after starting on the port */
  407. if (status != SCI_SUCCESS)
  408. scic_sds_port_complete_io(sci_port, sci_dev, sci_req);
  409. else
  410. scic_sds_remote_device_increment_request_count(sci_dev);
  411. }
  412. enum sci_status scic_sds_remote_device_start_io(struct scic_sds_controller *scic,
  413. struct scic_sds_remote_device *sci_dev,
  414. struct scic_sds_request *sci_req)
  415. {
  416. struct sci_base_state_machine *sm = &sci_dev->state_machine;
  417. enum scic_sds_remote_device_states state = sm->current_state_id;
  418. struct scic_sds_port *sci_port = sci_dev->owning_port;
  419. struct isci_request *ireq = sci_req_to_ireq(sci_req);
  420. enum sci_status status;
  421. switch (state) {
  422. case SCI_BASE_REMOTE_DEVICE_STATE_INITIAL:
  423. case SCI_BASE_REMOTE_DEVICE_STATE_STOPPED:
  424. case SCI_BASE_REMOTE_DEVICE_STATE_STARTING:
  425. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR:
  426. case SCI_BASE_REMOTE_DEVICE_STATE_STOPPING:
  427. case SCI_BASE_REMOTE_DEVICE_STATE_FAILED:
  428. case SCI_BASE_REMOTE_DEVICE_STATE_RESETTING:
  429. case SCI_BASE_REMOTE_DEVICE_STATE_FINAL:
  430. default:
  431. dev_warn(scirdev_to_dev(sci_dev), "%s: in wrong state: %d\n",
  432. __func__, state);
  433. return SCI_FAILURE_INVALID_STATE;
  434. case SCI_BASE_REMOTE_DEVICE_STATE_READY:
  435. /* attempt to start an io request for this device object. The remote
  436. * device object will issue the start request for the io and if
  437. * successful it will start the request for the port object then
  438. * increment its own request count.
  439. */
  440. status = scic_sds_port_start_io(sci_port, sci_dev, sci_req);
  441. if (status != SCI_SUCCESS)
  442. return status;
  443. status = scic_sds_remote_node_context_start_io(&sci_dev->rnc, sci_req);
  444. if (status != SCI_SUCCESS)
  445. break;
  446. status = scic_sds_request_start(sci_req);
  447. break;
  448. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE: {
  449. /* handle the start io operation for a sata device that is in
  450. * the command idle state. - Evalute the type of IO request to
  451. * be started - If its an NCQ request change to NCQ substate -
  452. * If its any other command change to the CMD substate
  453. *
  454. * If this is a softreset we may want to have a different
  455. * substate.
  456. */
  457. enum scic_sds_remote_device_states new_state;
  458. struct sas_task *task = isci_request_access_task(ireq);
  459. status = scic_sds_port_start_io(sci_port, sci_dev, sci_req);
  460. if (status != SCI_SUCCESS)
  461. return status;
  462. status = scic_sds_remote_node_context_start_io(&sci_dev->rnc, sci_req);
  463. if (status != SCI_SUCCESS)
  464. break;
  465. status = sci_req->state_handlers->start_handler(sci_req);
  466. if (status != SCI_SUCCESS)
  467. break;
  468. if (task->ata_task.use_ncq)
  469. new_state = SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ;
  470. else {
  471. sci_dev->working_request = sci_req;
  472. new_state = SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD;
  473. }
  474. sci_base_state_machine_change_state(sm, new_state);
  475. break;
  476. }
  477. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ: {
  478. struct sas_task *task = isci_request_access_task(ireq);
  479. if (task->ata_task.use_ncq) {
  480. status = scic_sds_port_start_io(sci_port, sci_dev, sci_req);
  481. if (status != SCI_SUCCESS)
  482. return status;
  483. status = scic_sds_remote_node_context_start_io(&sci_dev->rnc, sci_req);
  484. if (status != SCI_SUCCESS)
  485. break;
  486. status = sci_req->state_handlers->start_handler(sci_req);
  487. } else
  488. return SCI_FAILURE_INVALID_STATE;
  489. break;
  490. }
  491. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET:
  492. return SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED;
  493. case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE:
  494. status = scic_sds_port_start_io(sci_port, sci_dev, sci_req);
  495. if (status != SCI_SUCCESS)
  496. return status;
  497. status = scic_sds_remote_node_context_start_io(&sci_dev->rnc, sci_req);
  498. if (status != SCI_SUCCESS)
  499. break;
  500. status = scic_sds_request_start(sci_req);
  501. if (status != SCI_SUCCESS)
  502. break;
  503. sci_dev->working_request = sci_req;
  504. sci_base_state_machine_change_state(&sci_dev->state_machine,
  505. SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD);
  506. break;
  507. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD:
  508. case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD:
  509. /* device is already handling a command it can not accept new commands
  510. * until this one is complete.
  511. */
  512. return SCI_FAILURE_INVALID_STATE;
  513. }
  514. scic_sds_remote_device_start_request(sci_dev, sci_req, status);
  515. return status;
  516. }
  517. static enum sci_status common_complete_io(struct scic_sds_port *sci_port,
  518. struct scic_sds_remote_device *sci_dev,
  519. struct scic_sds_request *sci_req)
  520. {
  521. enum sci_status status;
  522. status = scic_sds_request_complete(sci_req);
  523. if (status != SCI_SUCCESS)
  524. return status;
  525. status = scic_sds_port_complete_io(sci_port, sci_dev, sci_req);
  526. if (status != SCI_SUCCESS)
  527. return status;
  528. scic_sds_remote_device_decrement_request_count(sci_dev);
  529. return status;
  530. }
  531. enum sci_status scic_sds_remote_device_complete_io(struct scic_sds_controller *scic,
  532. struct scic_sds_remote_device *sci_dev,
  533. struct scic_sds_request *sci_req)
  534. {
  535. struct sci_base_state_machine *sm = &sci_dev->state_machine;
  536. enum scic_sds_remote_device_states state = sm->current_state_id;
  537. struct scic_sds_port *sci_port = sci_dev->owning_port;
  538. enum sci_status status;
  539. switch (state) {
  540. case SCI_BASE_REMOTE_DEVICE_STATE_INITIAL:
  541. case SCI_BASE_REMOTE_DEVICE_STATE_STOPPED:
  542. case SCI_BASE_REMOTE_DEVICE_STATE_STARTING:
  543. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE:
  544. case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE:
  545. case SCI_BASE_REMOTE_DEVICE_STATE_FAILED:
  546. case SCI_BASE_REMOTE_DEVICE_STATE_FINAL:
  547. default:
  548. dev_warn(scirdev_to_dev(sci_dev), "%s: in wrong state: %d\n",
  549. __func__, state);
  550. return SCI_FAILURE_INVALID_STATE;
  551. case SCI_BASE_REMOTE_DEVICE_STATE_READY:
  552. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET:
  553. case SCI_BASE_REMOTE_DEVICE_STATE_RESETTING:
  554. status = common_complete_io(sci_port, sci_dev, sci_req);
  555. break;
  556. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD:
  557. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ:
  558. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR:
  559. status = common_complete_io(sci_port, sci_dev, sci_req);
  560. if (status != SCI_SUCCESS)
  561. break;
  562. if (sci_req->sci_status == SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) {
  563. /* This request causes hardware error, device needs to be Lun Reset.
  564. * So here we force the state machine to IDLE state so the rest IOs
  565. * can reach RNC state handler, these IOs will be completed by RNC with
  566. * status of "DEVICE_RESET_REQUIRED", instead of "INVALID STATE".
  567. */
  568. sci_base_state_machine_change_state(sm, SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET);
  569. } else if (scic_sds_remote_device_get_request_count(sci_dev) == 0)
  570. sci_base_state_machine_change_state(sm, SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
  571. break;
  572. case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD:
  573. status = common_complete_io(sci_port, sci_dev, sci_req);
  574. if (status != SCI_SUCCESS)
  575. break;
  576. sci_base_state_machine_change_state(sm, SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
  577. break;
  578. case SCI_BASE_REMOTE_DEVICE_STATE_STOPPING:
  579. status = common_complete_io(sci_port, sci_dev, sci_req);
  580. if (status != SCI_SUCCESS)
  581. break;
  582. if (scic_sds_remote_device_get_request_count(sci_dev) == 0)
  583. scic_sds_remote_node_context_destruct(&sci_dev->rnc,
  584. rnc_destruct_done,
  585. sci_dev);
  586. break;
  587. }
  588. if (status != SCI_SUCCESS)
  589. dev_err(scirdev_to_dev(sci_dev),
  590. "%s: Port:0x%p Device:0x%p Request:0x%p Status:0x%x "
  591. "could not complete\n", __func__, sci_port,
  592. sci_dev, sci_req, status);
  593. return status;
  594. }
  595. static void scic_sds_remote_device_continue_request(void *dev)
  596. {
  597. struct scic_sds_remote_device *sci_dev = dev;
  598. /* we need to check if this request is still valid to continue. */
  599. if (sci_dev->working_request)
  600. scic_controller_continue_io(sci_dev->working_request);
  601. }
  602. enum sci_status scic_sds_remote_device_start_task(struct scic_sds_controller *scic,
  603. struct scic_sds_remote_device *sci_dev,
  604. struct scic_sds_request *sci_req)
  605. {
  606. struct sci_base_state_machine *sm = &sci_dev->state_machine;
  607. enum scic_sds_remote_device_states state = sm->current_state_id;
  608. struct scic_sds_port *sci_port = sci_dev->owning_port;
  609. enum sci_status status;
  610. switch (state) {
  611. case SCI_BASE_REMOTE_DEVICE_STATE_INITIAL:
  612. case SCI_BASE_REMOTE_DEVICE_STATE_STOPPED:
  613. case SCI_BASE_REMOTE_DEVICE_STATE_STARTING:
  614. case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE:
  615. case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD:
  616. case SCI_BASE_REMOTE_DEVICE_STATE_STOPPING:
  617. case SCI_BASE_REMOTE_DEVICE_STATE_FAILED:
  618. case SCI_BASE_REMOTE_DEVICE_STATE_RESETTING:
  619. case SCI_BASE_REMOTE_DEVICE_STATE_FINAL:
  620. default:
  621. dev_warn(scirdev_to_dev(sci_dev), "%s: in wrong state: %d\n",
  622. __func__, state);
  623. return SCI_FAILURE_INVALID_STATE;
  624. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE:
  625. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD:
  626. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ:
  627. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR:
  628. case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET:
  629. status = scic_sds_port_start_io(sci_port, sci_dev, sci_req);
  630. if (status != SCI_SUCCESS)
  631. return status;
  632. status = scic_sds_remote_node_context_start_task(&sci_dev->rnc, sci_req);
  633. if (status != SCI_SUCCESS)
  634. goto out;
  635. status = sci_req->state_handlers->start_handler(sci_req);
  636. if (status != SCI_SUCCESS)
  637. goto out;
  638. /* Note: If the remote device state is not IDLE this will
  639. * replace the request that probably resulted in the task
  640. * management request.
  641. */
  642. sci_dev->working_request = sci_req;
  643. sci_base_state_machine_change_state(sm, SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD);
  644. /* The remote node context must cleanup the TCi to NCQ mapping
  645. * table. The only way to do this correctly is to either write
  646. * to the TLCR register or to invalidate and repost the RNC. In
  647. * either case the remote node context state machine will take
  648. * the correct action when the remote node context is suspended
  649. * and later resumed.
  650. */
  651. scic_sds_remote_node_context_suspend(&sci_dev->rnc,
  652. SCI_SOFTWARE_SUSPENSION, NULL, NULL);
  653. scic_sds_remote_node_context_resume(&sci_dev->rnc,
  654. scic_sds_remote_device_continue_request,
  655. sci_dev);
  656. out:
  657. scic_sds_remote_device_start_request(sci_dev, sci_req, status);
  658. /* We need to let the controller start request handler know that
  659. * it can't post TC yet. We will provide a callback function to
  660. * post TC when RNC gets resumed.
  661. */
  662. return SCI_FAILURE_RESET_DEVICE_PARTIAL_SUCCESS;
  663. case SCI_BASE_REMOTE_DEVICE_STATE_READY:
  664. status = scic_sds_port_start_io(sci_port, sci_dev, sci_req);
  665. if (status != SCI_SUCCESS)
  666. return status;
  667. status = scic_sds_remote_node_context_start_task(&sci_dev->rnc, sci_req);
  668. if (status != SCI_SUCCESS)
  669. break;
  670. status = scic_sds_request_start(sci_req);
  671. break;
  672. }
  673. scic_sds_remote_device_start_request(sci_dev, sci_req, status);
  674. return status;
  675. }
  676. /**
  677. *
  678. * @sci_dev:
  679. * @request:
  680. *
  681. * This method takes the request and bulids an appropriate SCU context for the
  682. * request and then requests the controller to post the request. none
  683. */
  684. void scic_sds_remote_device_post_request(
  685. struct scic_sds_remote_device *sci_dev,
  686. u32 request)
  687. {
  688. u32 context;
  689. context = scic_sds_remote_device_build_command_context(sci_dev, request);
  690. scic_sds_controller_post_request(
  691. scic_sds_remote_device_get_controller(sci_dev),
  692. context
  693. );
  694. }
  695. /* called once the remote node context has transisitioned to a
  696. * ready state. This is the indication that the remote device object can also
  697. * transition to ready.
  698. */
  699. static void remote_device_resume_done(void *_dev)
  700. {
  701. struct scic_sds_remote_device *sci_dev = _dev;
  702. if (is_remote_device_ready(sci_dev))
  703. return;
  704. /* go 'ready' if we are not already in a ready state */
  705. sci_base_state_machine_change_state(&sci_dev->state_machine,
  706. SCI_BASE_REMOTE_DEVICE_STATE_READY);
  707. }
  708. static void scic_sds_stp_remote_device_ready_idle_substate_resume_complete_handler(void *_dev)
  709. {
  710. struct scic_sds_remote_device *sci_dev = _dev;
  711. struct isci_remote_device *idev = sci_dev_to_idev(sci_dev);
  712. struct scic_sds_controller *scic = sci_dev->owning_port->owning_controller;
  713. /* For NCQ operation we do not issue a isci_remote_device_not_ready().
  714. * As a result, avoid sending the ready notification.
  715. */
  716. if (sci_dev->state_machine.previous_state_id != SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ)
  717. isci_remote_device_ready(scic_to_ihost(scic), idev);
  718. }
  719. static void scic_sds_remote_device_initial_state_enter(void *object)
  720. {
  721. struct scic_sds_remote_device *sci_dev = object;
  722. /* Initial state is a transitional state to the stopped state */
  723. sci_base_state_machine_change_state(&sci_dev->state_machine,
  724. SCI_BASE_REMOTE_DEVICE_STATE_STOPPED);
  725. }
  726. /**
  727. * scic_remote_device_destruct() - free remote node context and destruct
  728. * @remote_device: This parameter specifies the remote device to be destructed.
  729. *
  730. * Remote device objects are a limited resource. As such, they must be
  731. * protected. Thus calls to construct and destruct are mutually exclusive and
  732. * non-reentrant. The return value shall indicate if the device was
  733. * successfully destructed or if some failure occurred. enum sci_status This value
  734. * is returned if the device is successfully destructed.
  735. * SCI_FAILURE_INVALID_REMOTE_DEVICE This value is returned if the supplied
  736. * device isn't valid (e.g. it's already been destoryed, the handle isn't
  737. * valid, etc.).
  738. */
  739. static enum sci_status scic_remote_device_destruct(struct scic_sds_remote_device *sci_dev)
  740. {
  741. struct sci_base_state_machine *sm = &sci_dev->state_machine;
  742. enum scic_sds_remote_device_states state = sm->current_state_id;
  743. struct scic_sds_controller *scic;
  744. if (state != SCI_BASE_REMOTE_DEVICE_STATE_STOPPED) {
  745. dev_warn(scirdev_to_dev(sci_dev), "%s: in wrong state: %d\n",
  746. __func__, state);
  747. return SCI_FAILURE_INVALID_STATE;
  748. }
  749. scic = sci_dev->owning_port->owning_controller;
  750. scic_sds_controller_free_remote_node_context(scic, sci_dev,
  751. sci_dev->rnc.remote_node_index);
  752. sci_dev->rnc.remote_node_index = SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX;
  753. sci_base_state_machine_change_state(sm, SCI_BASE_REMOTE_DEVICE_STATE_FINAL);
  754. return SCI_SUCCESS;
  755. }
  756. /**
  757. * isci_remote_device_deconstruct() - This function frees an isci_remote_device.
  758. * @ihost: This parameter specifies the isci host object.
  759. * @idev: This parameter specifies the remote device to be freed.
  760. *
  761. */
  762. static void isci_remote_device_deconstruct(struct isci_host *ihost, struct isci_remote_device *idev)
  763. {
  764. dev_dbg(&ihost->pdev->dev,
  765. "%s: isci_device = %p\n", __func__, idev);
  766. /* There should not be any outstanding io's. All paths to
  767. * here should go through isci_remote_device_nuke_requests.
  768. * If we hit this condition, we will need a way to complete
  769. * io requests in process */
  770. while (!list_empty(&idev->reqs_in_process)) {
  771. dev_err(&ihost->pdev->dev,
  772. "%s: ** request list not empty! **\n", __func__);
  773. BUG();
  774. }
  775. scic_remote_device_destruct(&idev->sci);
  776. idev->domain_dev->lldd_dev = NULL;
  777. idev->domain_dev = NULL;
  778. idev->isci_port = NULL;
  779. list_del_init(&idev->node);
  780. clear_bit(IDEV_START_PENDING, &idev->flags);
  781. clear_bit(IDEV_STOP_PENDING, &idev->flags);
  782. clear_bit(IDEV_EH, &idev->flags);
  783. wake_up(&ihost->eventq);
  784. }
  785. /**
  786. * isci_remote_device_stop_complete() - This function is called by the scic
  787. * when the remote device stop has completed. We mark the isci device as not
  788. * ready and remove the isci remote device.
  789. * @ihost: This parameter specifies the isci host object.
  790. * @idev: This parameter specifies the remote device.
  791. * @status: This parameter specifies status of the completion.
  792. *
  793. */
  794. static void isci_remote_device_stop_complete(struct isci_host *ihost,
  795. struct isci_remote_device *idev)
  796. {
  797. dev_dbg(&ihost->pdev->dev, "%s: complete idev = %p\n", __func__, idev);
  798. isci_remote_device_change_state(idev, isci_stopped);
  799. /* after stop, we can tear down resources. */
  800. isci_remote_device_deconstruct(ihost, idev);
  801. }
  802. static void scic_sds_remote_device_stopped_state_enter(void *object)
  803. {
  804. struct scic_sds_remote_device *sci_dev = object;
  805. struct scic_sds_controller *scic = sci_dev->owning_port->owning_controller;
  806. struct isci_remote_device *idev = sci_dev_to_idev(sci_dev);
  807. u32 prev_state;
  808. /* If we are entering from the stopping state let the SCI User know that
  809. * the stop operation has completed.
  810. */
  811. prev_state = sci_dev->state_machine.previous_state_id;
  812. if (prev_state == SCI_BASE_REMOTE_DEVICE_STATE_STOPPING)
  813. isci_remote_device_stop_complete(scic_to_ihost(scic), idev);
  814. scic_sds_controller_remote_device_stopped(scic, sci_dev);
  815. }
  816. static void scic_sds_remote_device_starting_state_enter(void *object)
  817. {
  818. struct scic_sds_remote_device *sci_dev = object;
  819. struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev);
  820. struct isci_host *ihost = scic_to_ihost(scic);
  821. struct isci_remote_device *idev = sci_dev_to_idev(sci_dev);
  822. isci_remote_device_not_ready(ihost, idev,
  823. SCIC_REMOTE_DEVICE_NOT_READY_START_REQUESTED);
  824. }
  825. static void scic_sds_remote_device_ready_state_enter(void *object)
  826. {
  827. struct scic_sds_remote_device *sci_dev = object;
  828. struct scic_sds_controller *scic = sci_dev->owning_port->owning_controller;
  829. struct isci_remote_device *idev = sci_dev_to_idev(sci_dev);
  830. struct domain_device *dev = idev->domain_dev;
  831. scic->remote_device_sequence[sci_dev->rnc.remote_node_index]++;
  832. if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_SATA)) {
  833. sci_base_state_machine_change_state(&sci_dev->state_machine,
  834. SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
  835. } else if (dev_is_expander(dev)) {
  836. sci_base_state_machine_change_state(&sci_dev->state_machine,
  837. SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
  838. } else
  839. isci_remote_device_ready(scic_to_ihost(scic), idev);
  840. }
  841. static void scic_sds_remote_device_ready_state_exit(void *object)
  842. {
  843. struct scic_sds_remote_device *sci_dev = object;
  844. struct domain_device *dev = sci_dev_to_domain(sci_dev);
  845. if (dev->dev_type == SAS_END_DEV) {
  846. struct scic_sds_controller *scic = sci_dev->owning_port->owning_controller;
  847. struct isci_remote_device *idev = sci_dev_to_idev(sci_dev);
  848. isci_remote_device_not_ready(scic_to_ihost(scic), idev,
  849. SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED);
  850. }
  851. }
  852. static void scic_sds_remote_device_resetting_state_enter(void *object)
  853. {
  854. struct scic_sds_remote_device *sci_dev = object;
  855. scic_sds_remote_node_context_suspend(
  856. &sci_dev->rnc, SCI_SOFTWARE_SUSPENSION, NULL, NULL);
  857. }
  858. static void scic_sds_remote_device_resetting_state_exit(void *object)
  859. {
  860. struct scic_sds_remote_device *sci_dev = object;
  861. scic_sds_remote_node_context_resume(&sci_dev->rnc, NULL, NULL);
  862. }
  863. static void scic_sds_stp_remote_device_ready_idle_substate_enter(void *object)
  864. {
  865. struct scic_sds_remote_device *sci_dev = object;
  866. sci_dev->working_request = NULL;
  867. if (scic_sds_remote_node_context_is_ready(&sci_dev->rnc)) {
  868. /*
  869. * Since the RNC is ready, it's alright to finish completion
  870. * processing (e.g. signal the remote device is ready). */
  871. scic_sds_stp_remote_device_ready_idle_substate_resume_complete_handler(sci_dev);
  872. } else {
  873. scic_sds_remote_node_context_resume(&sci_dev->rnc,
  874. scic_sds_stp_remote_device_ready_idle_substate_resume_complete_handler,
  875. sci_dev);
  876. }
  877. }
  878. static void scic_sds_stp_remote_device_ready_cmd_substate_enter(void *object)
  879. {
  880. struct scic_sds_remote_device *sci_dev = object;
  881. struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev);
  882. BUG_ON(sci_dev->working_request == NULL);
  883. isci_remote_device_not_ready(scic_to_ihost(scic), sci_dev_to_idev(sci_dev),
  884. SCIC_REMOTE_DEVICE_NOT_READY_SATA_REQUEST_STARTED);
  885. }
  886. static void scic_sds_stp_remote_device_ready_ncq_error_substate_enter(void *object)
  887. {
  888. struct scic_sds_remote_device *sci_dev = object;
  889. struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev);
  890. struct isci_remote_device *idev = sci_dev_to_idev(sci_dev);
  891. if (sci_dev->not_ready_reason == SCIC_REMOTE_DEVICE_NOT_READY_SATA_SDB_ERROR_FIS_RECEIVED)
  892. isci_remote_device_not_ready(scic_to_ihost(scic), idev,
  893. sci_dev->not_ready_reason);
  894. }
  895. static void scic_sds_smp_remote_device_ready_idle_substate_enter(void *object)
  896. {
  897. struct scic_sds_remote_device *sci_dev = object;
  898. struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev);
  899. isci_remote_device_ready(scic_to_ihost(scic), sci_dev_to_idev(sci_dev));
  900. }
  901. static void scic_sds_smp_remote_device_ready_cmd_substate_enter(void *object)
  902. {
  903. struct scic_sds_remote_device *sci_dev = object;
  904. struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev);
  905. BUG_ON(sci_dev->working_request == NULL);
  906. isci_remote_device_not_ready(scic_to_ihost(scic), sci_dev_to_idev(sci_dev),
  907. SCIC_REMOTE_DEVICE_NOT_READY_SMP_REQUEST_STARTED);
  908. }
  909. static void scic_sds_smp_remote_device_ready_cmd_substate_exit(void *object)
  910. {
  911. struct scic_sds_remote_device *sci_dev = object;
  912. sci_dev->working_request = NULL;
  913. }
  914. static const struct sci_base_state scic_sds_remote_device_state_table[] = {
  915. [SCI_BASE_REMOTE_DEVICE_STATE_INITIAL] = {
  916. .enter_state = scic_sds_remote_device_initial_state_enter,
  917. },
  918. [SCI_BASE_REMOTE_DEVICE_STATE_STOPPED] = {
  919. .enter_state = scic_sds_remote_device_stopped_state_enter,
  920. },
  921. [SCI_BASE_REMOTE_DEVICE_STATE_STARTING] = {
  922. .enter_state = scic_sds_remote_device_starting_state_enter,
  923. },
  924. [SCI_BASE_REMOTE_DEVICE_STATE_READY] = {
  925. .enter_state = scic_sds_remote_device_ready_state_enter,
  926. .exit_state = scic_sds_remote_device_ready_state_exit
  927. },
  928. [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE] = {
  929. .enter_state = scic_sds_stp_remote_device_ready_idle_substate_enter,
  930. },
  931. [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD] = {
  932. .enter_state = scic_sds_stp_remote_device_ready_cmd_substate_enter,
  933. },
  934. [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ] = { },
  935. [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR] = {
  936. .enter_state = scic_sds_stp_remote_device_ready_ncq_error_substate_enter,
  937. },
  938. [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET] = { },
  939. [SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE] = {
  940. .enter_state = scic_sds_smp_remote_device_ready_idle_substate_enter,
  941. },
  942. [SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD] = {
  943. .enter_state = scic_sds_smp_remote_device_ready_cmd_substate_enter,
  944. .exit_state = scic_sds_smp_remote_device_ready_cmd_substate_exit,
  945. },
  946. [SCI_BASE_REMOTE_DEVICE_STATE_STOPPING] = { },
  947. [SCI_BASE_REMOTE_DEVICE_STATE_FAILED] = { },
  948. [SCI_BASE_REMOTE_DEVICE_STATE_RESETTING] = {
  949. .enter_state = scic_sds_remote_device_resetting_state_enter,
  950. .exit_state = scic_sds_remote_device_resetting_state_exit
  951. },
  952. [SCI_BASE_REMOTE_DEVICE_STATE_FINAL] = { },
  953. };
  954. /**
  955. * scic_remote_device_construct() - common construction
  956. * @sci_port: SAS/SATA port through which this device is accessed.
  957. * @sci_dev: remote device to construct
  958. *
  959. * This routine just performs benign initialization and does not
  960. * allocate the remote_node_context which is left to
  961. * scic_remote_device_[de]a_construct(). scic_remote_device_destruct()
  962. * frees the remote_node_context(s) for the device.
  963. */
  964. static void scic_remote_device_construct(struct scic_sds_port *sci_port,
  965. struct scic_sds_remote_device *sci_dev)
  966. {
  967. sci_dev->owning_port = sci_port;
  968. sci_dev->started_request_count = 0;
  969. sci_base_state_machine_construct(
  970. &sci_dev->state_machine,
  971. sci_dev,
  972. scic_sds_remote_device_state_table,
  973. SCI_BASE_REMOTE_DEVICE_STATE_INITIAL
  974. );
  975. sci_base_state_machine_start(
  976. &sci_dev->state_machine
  977. );
  978. scic_sds_remote_node_context_construct(&sci_dev->rnc,
  979. SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX);
  980. }
  981. /**
  982. * scic_remote_device_da_construct() - construct direct attached device.
  983. *
  984. * The information (e.g. IAF, Signature FIS, etc.) necessary to build
  985. * the device is known to the SCI Core since it is contained in the
  986. * scic_phy object. Remote node context(s) is/are a global resource
  987. * allocated by this routine, freed by scic_remote_device_destruct().
  988. *
  989. * Returns:
  990. * SCI_FAILURE_DEVICE_EXISTS - device has already been constructed.
  991. * SCI_FAILURE_UNSUPPORTED_PROTOCOL - e.g. sas device attached to
  992. * sata-only controller instance.
  993. * SCI_FAILURE_INSUFFICIENT_RESOURCES - remote node contexts exhausted.
  994. */
  995. static enum sci_status scic_remote_device_da_construct(struct scic_sds_port *sci_port,
  996. struct scic_sds_remote_device *sci_dev)
  997. {
  998. enum sci_status status;
  999. struct domain_device *dev = sci_dev_to_domain(sci_dev);
  1000. scic_remote_device_construct(sci_port, sci_dev);
  1001. /*
  1002. * This information is request to determine how many remote node context
  1003. * entries will be needed to store the remote node.
  1004. */
  1005. sci_dev->is_direct_attached = true;
  1006. status = scic_sds_controller_allocate_remote_node_context(sci_port->owning_controller,
  1007. sci_dev,
  1008. &sci_dev->rnc.remote_node_index);
  1009. if (status != SCI_SUCCESS)
  1010. return status;
  1011. if (dev->dev_type == SAS_END_DEV || dev->dev_type == SATA_DEV ||
  1012. (dev->tproto & SAS_PROTOCOL_STP) || dev_is_expander(dev))
  1013. /* pass */;
  1014. else
  1015. return SCI_FAILURE_UNSUPPORTED_PROTOCOL;
  1016. sci_dev->connection_rate = scic_sds_port_get_max_allowed_speed(sci_port);
  1017. /* / @todo Should I assign the port width by reading all of the phys on the port? */
  1018. sci_dev->device_port_width = 1;
  1019. return SCI_SUCCESS;
  1020. }
  1021. /**
  1022. * scic_remote_device_ea_construct() - construct expander attached device
  1023. *
  1024. * Remote node context(s) is/are a global resource allocated by this
  1025. * routine, freed by scic_remote_device_destruct().
  1026. *
  1027. * Returns:
  1028. * SCI_FAILURE_DEVICE_EXISTS - device has already been constructed.
  1029. * SCI_FAILURE_UNSUPPORTED_PROTOCOL - e.g. sas device attached to
  1030. * sata-only controller instance.
  1031. * SCI_FAILURE_INSUFFICIENT_RESOURCES - remote node contexts exhausted.
  1032. */
  1033. static enum sci_status scic_remote_device_ea_construct(struct scic_sds_port *sci_port,
  1034. struct scic_sds_remote_device *sci_dev)
  1035. {
  1036. struct domain_device *dev = sci_dev_to_domain(sci_dev);
  1037. enum sci_status status;
  1038. scic_remote_device_construct(sci_port, sci_dev);
  1039. status = scic_sds_controller_allocate_remote_node_context(sci_port->owning_controller,
  1040. sci_dev,
  1041. &sci_dev->rnc.remote_node_index);
  1042. if (status != SCI_SUCCESS)
  1043. return status;
  1044. if (dev->dev_type == SAS_END_DEV || dev->dev_type == SATA_DEV ||
  1045. (dev->tproto & SAS_PROTOCOL_STP) || dev_is_expander(dev))
  1046. /* pass */;
  1047. else
  1048. return SCI_FAILURE_UNSUPPORTED_PROTOCOL;
  1049. /*
  1050. * For SAS-2 the physical link rate is actually a logical link
  1051. * rate that incorporates multiplexing. The SCU doesn't
  1052. * incorporate multiplexing and for the purposes of the
  1053. * connection the logical link rate is that same as the
  1054. * physical. Furthermore, the SAS-2 and SAS-1.1 fields overlay
  1055. * one another, so this code works for both situations. */
  1056. sci_dev->connection_rate = min_t(u16, scic_sds_port_get_max_allowed_speed(sci_port),
  1057. dev->linkrate);
  1058. /* / @todo Should I assign the port width by reading all of the phys on the port? */
  1059. sci_dev->device_port_width = 1;
  1060. return SCI_SUCCESS;
  1061. }
  1062. /**
  1063. * scic_remote_device_start() - This method will start the supplied remote
  1064. * device. This method enables normal IO requests to flow through to the
  1065. * remote device.
  1066. * @remote_device: This parameter specifies the device to be started.
  1067. * @timeout: This parameter specifies the number of milliseconds in which the
  1068. * start operation should complete.
  1069. *
  1070. * An indication of whether the device was successfully started. SCI_SUCCESS
  1071. * This value is returned if the device was successfully started.
  1072. * SCI_FAILURE_INVALID_PHY This value is returned if the user attempts to start
  1073. * the device when there have been no phys added to it.
  1074. */
  1075. static enum sci_status scic_remote_device_start(struct scic_sds_remote_device *sci_dev,
  1076. u32 timeout)
  1077. {
  1078. struct sci_base_state_machine *sm = &sci_dev->state_machine;
  1079. enum scic_sds_remote_device_states state = sm->current_state_id;
  1080. enum sci_status status;
  1081. if (state != SCI_BASE_REMOTE_DEVICE_STATE_STOPPED) {
  1082. dev_warn(scirdev_to_dev(sci_dev), "%s: in wrong state: %d\n",
  1083. __func__, state);
  1084. return SCI_FAILURE_INVALID_STATE;
  1085. }
  1086. status = scic_sds_remote_node_context_resume(&sci_dev->rnc,
  1087. remote_device_resume_done,
  1088. sci_dev);
  1089. if (status != SCI_SUCCESS)
  1090. return status;
  1091. sci_base_state_machine_change_state(sm, SCI_BASE_REMOTE_DEVICE_STATE_STARTING);
  1092. return SCI_SUCCESS;
  1093. }
  1094. static enum sci_status isci_remote_device_construct(struct isci_port *iport,
  1095. struct isci_remote_device *idev)
  1096. {
  1097. struct scic_sds_port *sci_port = &iport->sci;
  1098. struct isci_host *ihost = iport->isci_host;
  1099. struct domain_device *dev = idev->domain_dev;
  1100. enum sci_status status;
  1101. if (dev->parent && dev_is_expander(dev->parent))
  1102. status = scic_remote_device_ea_construct(sci_port, &idev->sci);
  1103. else
  1104. status = scic_remote_device_da_construct(sci_port, &idev->sci);
  1105. if (status != SCI_SUCCESS) {
  1106. dev_dbg(&ihost->pdev->dev, "%s: construct failed: %d\n",
  1107. __func__, status);
  1108. return status;
  1109. }
  1110. /* start the device. */
  1111. status = scic_remote_device_start(&idev->sci, ISCI_REMOTE_DEVICE_START_TIMEOUT);
  1112. if (status != SCI_SUCCESS)
  1113. dev_warn(&ihost->pdev->dev, "remote device start failed: %d\n",
  1114. status);
  1115. return status;
  1116. }
  1117. void isci_remote_device_nuke_requests(struct isci_host *ihost, struct isci_remote_device *idev)
  1118. {
  1119. DECLARE_COMPLETION_ONSTACK(aborted_task_completion);
  1120. dev_dbg(&ihost->pdev->dev,
  1121. "%s: idev = %p\n", __func__, idev);
  1122. /* Cleanup all requests pending for this device. */
  1123. isci_terminate_pending_requests(ihost, idev, terminating);
  1124. dev_dbg(&ihost->pdev->dev,
  1125. "%s: idev = %p, done\n", __func__, idev);
  1126. }
  1127. /**
  1128. * This function builds the isci_remote_device when a libsas dev_found message
  1129. * is received.
  1130. * @isci_host: This parameter specifies the isci host object.
  1131. * @port: This parameter specifies the isci_port conected to this device.
  1132. *
  1133. * pointer to new isci_remote_device.
  1134. */
  1135. static struct isci_remote_device *
  1136. isci_remote_device_alloc(struct isci_host *ihost, struct isci_port *iport)
  1137. {
  1138. struct isci_remote_device *idev;
  1139. int i;
  1140. for (i = 0; i < SCI_MAX_REMOTE_DEVICES; i++) {
  1141. idev = &ihost->devices[i];
  1142. if (!test_and_set_bit(IDEV_ALLOCATED, &idev->flags))
  1143. break;
  1144. }
  1145. if (i >= SCI_MAX_REMOTE_DEVICES) {
  1146. dev_warn(&ihost->pdev->dev, "%s: failed\n", __func__);
  1147. return NULL;
  1148. }
  1149. if (WARN_ONCE(!list_empty(&idev->reqs_in_process), "found requests in process\n"))
  1150. return NULL;
  1151. if (WARN_ONCE(!list_empty(&idev->node), "found non-idle remote device\n"))
  1152. return NULL;
  1153. isci_remote_device_change_state(idev, isci_freed);
  1154. return idev;
  1155. }
  1156. /**
  1157. * isci_remote_device_stop() - This function is called internally to stop the
  1158. * remote device.
  1159. * @isci_host: This parameter specifies the isci host object.
  1160. * @isci_device: This parameter specifies the remote device.
  1161. *
  1162. * The status of the scic request to stop.
  1163. */
  1164. enum sci_status isci_remote_device_stop(struct isci_host *ihost, struct isci_remote_device *idev)
  1165. {
  1166. enum sci_status status;
  1167. unsigned long flags;
  1168. dev_dbg(&ihost->pdev->dev,
  1169. "%s: isci_device = %p\n", __func__, idev);
  1170. isci_remote_device_change_state(idev, isci_stopping);
  1171. /* Kill all outstanding requests. */
  1172. isci_remote_device_nuke_requests(ihost, idev);
  1173. set_bit(IDEV_STOP_PENDING, &idev->flags);
  1174. spin_lock_irqsave(&ihost->scic_lock, flags);
  1175. status = scic_remote_device_stop(&idev->sci, 50);
  1176. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  1177. /* Wait for the stop complete callback. */
  1178. if (status == SCI_SUCCESS) {
  1179. wait_for_device_stop(ihost, idev);
  1180. clear_bit(IDEV_ALLOCATED, &idev->flags);
  1181. }
  1182. dev_dbg(&ihost->pdev->dev,
  1183. "%s: idev = %p - after completion wait\n",
  1184. __func__, idev);
  1185. return status;
  1186. }
  1187. /**
  1188. * isci_remote_device_gone() - This function is called by libsas when a domain
  1189. * device is removed.
  1190. * @domain_device: This parameter specifies the libsas domain device.
  1191. *
  1192. */
  1193. void isci_remote_device_gone(struct domain_device *dev)
  1194. {
  1195. struct isci_host *ihost = dev_to_ihost(dev);
  1196. struct isci_remote_device *idev = dev->lldd_dev;
  1197. dev_dbg(&ihost->pdev->dev,
  1198. "%s: domain_device = %p, isci_device = %p, isci_port = %p\n",
  1199. __func__, dev, idev, idev->isci_port);
  1200. isci_remote_device_stop(ihost, idev);
  1201. }
  1202. /**
  1203. * isci_remote_device_found() - This function is called by libsas when a remote
  1204. * device is discovered. A remote device object is created and started. the
  1205. * function then sleeps until the sci core device started message is
  1206. * received.
  1207. * @domain_device: This parameter specifies the libsas domain device.
  1208. *
  1209. * status, zero indicates success.
  1210. */
  1211. int isci_remote_device_found(struct domain_device *domain_dev)
  1212. {
  1213. struct isci_host *isci_host = dev_to_ihost(domain_dev);
  1214. struct isci_port *isci_port;
  1215. struct isci_phy *isci_phy;
  1216. struct asd_sas_port *sas_port;
  1217. struct asd_sas_phy *sas_phy;
  1218. struct isci_remote_device *isci_device;
  1219. enum sci_status status;
  1220. dev_dbg(&isci_host->pdev->dev,
  1221. "%s: domain_device = %p\n", __func__, domain_dev);
  1222. wait_for_start(isci_host);
  1223. sas_port = domain_dev->port;
  1224. sas_phy = list_first_entry(&sas_port->phy_list, struct asd_sas_phy,
  1225. port_phy_el);
  1226. isci_phy = to_isci_phy(sas_phy);
  1227. isci_port = isci_phy->isci_port;
  1228. /* we are being called for a device on this port,
  1229. * so it has to come up eventually
  1230. */
  1231. wait_for_completion(&isci_port->start_complete);
  1232. if ((isci_stopping == isci_port_get_state(isci_port)) ||
  1233. (isci_stopped == isci_port_get_state(isci_port)))
  1234. return -ENODEV;
  1235. isci_device = isci_remote_device_alloc(isci_host, isci_port);
  1236. if (!isci_device)
  1237. return -ENODEV;
  1238. INIT_LIST_HEAD(&isci_device->node);
  1239. domain_dev->lldd_dev = isci_device;
  1240. isci_device->domain_dev = domain_dev;
  1241. isci_device->isci_port = isci_port;
  1242. isci_remote_device_change_state(isci_device, isci_starting);
  1243. spin_lock_irq(&isci_host->scic_lock);
  1244. list_add_tail(&isci_device->node, &isci_port->remote_dev_list);
  1245. set_bit(IDEV_START_PENDING, &isci_device->flags);
  1246. status = isci_remote_device_construct(isci_port, isci_device);
  1247. spin_unlock_irq(&isci_host->scic_lock);
  1248. dev_dbg(&isci_host->pdev->dev,
  1249. "%s: isci_device = %p\n",
  1250. __func__, isci_device);
  1251. if (status != SCI_SUCCESS) {
  1252. spin_lock_irq(&isci_host->scic_lock);
  1253. isci_remote_device_deconstruct(
  1254. isci_host,
  1255. isci_device
  1256. );
  1257. spin_unlock_irq(&isci_host->scic_lock);
  1258. return -ENODEV;
  1259. }
  1260. /* wait for the device ready callback. */
  1261. wait_for_device_start(isci_host, isci_device);
  1262. return 0;
  1263. }
  1264. /**
  1265. * isci_device_is_reset_pending() - This function will check if there is any
  1266. * pending reset condition on the device.
  1267. * @request: This parameter is the isci_device object.
  1268. *
  1269. * true if there is a reset pending for the device.
  1270. */
  1271. bool isci_device_is_reset_pending(
  1272. struct isci_host *isci_host,
  1273. struct isci_remote_device *isci_device)
  1274. {
  1275. struct isci_request *isci_request;
  1276. struct isci_request *tmp_req;
  1277. bool reset_is_pending = false;
  1278. unsigned long flags;
  1279. dev_dbg(&isci_host->pdev->dev,
  1280. "%s: isci_device = %p\n", __func__, isci_device);
  1281. spin_lock_irqsave(&isci_host->scic_lock, flags);
  1282. /* Check for reset on all pending requests. */
  1283. list_for_each_entry_safe(isci_request, tmp_req,
  1284. &isci_device->reqs_in_process, dev_node) {
  1285. dev_dbg(&isci_host->pdev->dev,
  1286. "%s: isci_device = %p request = %p\n",
  1287. __func__, isci_device, isci_request);
  1288. if (isci_request->ttype == io_task) {
  1289. struct sas_task *task = isci_request_access_task(
  1290. isci_request);
  1291. spin_lock(&task->task_state_lock);
  1292. if (task->task_state_flags & SAS_TASK_NEED_DEV_RESET)
  1293. reset_is_pending = true;
  1294. spin_unlock(&task->task_state_lock);
  1295. }
  1296. }
  1297. spin_unlock_irqrestore(&isci_host->scic_lock, flags);
  1298. dev_dbg(&isci_host->pdev->dev,
  1299. "%s: isci_device = %p reset_is_pending = %d\n",
  1300. __func__, isci_device, reset_is_pending);
  1301. return reset_is_pending;
  1302. }
  1303. /**
  1304. * isci_device_clear_reset_pending() - This function will clear if any pending
  1305. * reset condition flags on the device.
  1306. * @request: This parameter is the isci_device object.
  1307. *
  1308. * true if there is a reset pending for the device.
  1309. */
  1310. void isci_device_clear_reset_pending(struct isci_host *ihost, struct isci_remote_device *idev)
  1311. {
  1312. struct isci_request *isci_request;
  1313. struct isci_request *tmp_req;
  1314. unsigned long flags = 0;
  1315. dev_dbg(&ihost->pdev->dev, "%s: idev=%p, ihost=%p\n",
  1316. __func__, idev, ihost);
  1317. spin_lock_irqsave(&ihost->scic_lock, flags);
  1318. /* Clear reset pending on all pending requests. */
  1319. list_for_each_entry_safe(isci_request, tmp_req,
  1320. &idev->reqs_in_process, dev_node) {
  1321. dev_dbg(&ihost->pdev->dev, "%s: idev = %p request = %p\n",
  1322. __func__, idev, isci_request);
  1323. if (isci_request->ttype == io_task) {
  1324. unsigned long flags2;
  1325. struct sas_task *task = isci_request_access_task(
  1326. isci_request);
  1327. spin_lock_irqsave(&task->task_state_lock, flags2);
  1328. task->task_state_flags &= ~SAS_TASK_NEED_DEV_RESET;
  1329. spin_unlock_irqrestore(&task->task_state_lock, flags2);
  1330. }
  1331. }
  1332. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  1333. }