remote_device.c 53 KB

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