remote_device.c 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713
  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 <linux/bitops.h>
  57. #include "isci.h"
  58. #include "port.h"
  59. #include "remote_device.h"
  60. #include "request.h"
  61. #include "remote_node_context.h"
  62. #include "scu_event_codes.h"
  63. #include "task.h"
  64. #undef C
  65. #define C(a) (#a)
  66. const char *dev_state_name(enum sci_remote_device_states state)
  67. {
  68. static const char * const strings[] = REMOTE_DEV_STATES;
  69. return strings[state];
  70. }
  71. #undef C
  72. enum sci_status sci_remote_device_suspend(struct isci_remote_device *idev,
  73. enum sci_remote_node_suspension_reasons reason)
  74. {
  75. return sci_remote_node_context_suspend(&idev->rnc, reason,
  76. SCI_SOFTWARE_SUSPEND_EXPECTED_EVENT);
  77. }
  78. /**
  79. * isci_remote_device_ready() - This function is called by the ihost when the
  80. * remote device is ready. We mark the isci device as ready and signal the
  81. * waiting proccess.
  82. * @ihost: our valid isci_host
  83. * @idev: remote device
  84. *
  85. */
  86. static void isci_remote_device_ready(struct isci_host *ihost, struct isci_remote_device *idev)
  87. {
  88. dev_dbg(&ihost->pdev->dev,
  89. "%s: idev = %p\n", __func__, idev);
  90. clear_bit(IDEV_IO_NCQERROR, &idev->flags);
  91. set_bit(IDEV_IO_READY, &idev->flags);
  92. if (test_and_clear_bit(IDEV_START_PENDING, &idev->flags))
  93. wake_up(&ihost->eventq);
  94. }
  95. static enum sci_status sci_remote_device_terminate_req(
  96. struct isci_host *ihost,
  97. struct isci_remote_device *idev,
  98. int check_abort,
  99. struct isci_request *ireq)
  100. {
  101. if (!test_bit(IREQ_ACTIVE, &ireq->flags) ||
  102. (ireq->target_device != idev) ||
  103. (check_abort && !test_bit(IREQ_PENDING_ABORT, &ireq->flags)))
  104. return SCI_SUCCESS;
  105. dev_dbg(&ihost->pdev->dev,
  106. "%s: idev=%p; flags=%lx; req=%p; req target=%p\n",
  107. __func__, idev, idev->flags, ireq, ireq->target_device);
  108. set_bit(IREQ_ABORT_PATH_ACTIVE, &ireq->flags);
  109. return sci_controller_terminate_request(ihost, idev, ireq);
  110. }
  111. static enum sci_status sci_remote_device_terminate_reqs_checkabort(
  112. struct isci_remote_device *idev,
  113. int chk)
  114. {
  115. struct isci_host *ihost = idev->owning_port->owning_controller;
  116. enum sci_status status = SCI_SUCCESS;
  117. u32 i;
  118. for (i = 0; i < SCI_MAX_IO_REQUESTS; i++) {
  119. struct isci_request *ireq = ihost->reqs[i];
  120. enum sci_status s;
  121. s = sci_remote_device_terminate_req(ihost, idev, chk, ireq);
  122. if (s != SCI_SUCCESS)
  123. status = s;
  124. }
  125. return status;
  126. }
  127. static bool isci_compare_suspendcount(
  128. struct isci_remote_device *idev,
  129. u32 localcount)
  130. {
  131. smp_rmb();
  132. /* Check for a change in the suspend count, or the RNC
  133. * being destroyed.
  134. */
  135. return (localcount != idev->rnc.suspend_count)
  136. || sci_remote_node_context_is_being_destroyed(&idev->rnc);
  137. }
  138. static bool isci_check_reqterm(
  139. struct isci_host *ihost,
  140. struct isci_remote_device *idev,
  141. struct isci_request *ireq,
  142. u32 localcount)
  143. {
  144. unsigned long flags;
  145. bool res;
  146. spin_lock_irqsave(&ihost->scic_lock, flags);
  147. res = isci_compare_suspendcount(idev, localcount)
  148. && !test_bit(IREQ_ABORT_PATH_ACTIVE, &ireq->flags);
  149. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  150. return res;
  151. }
  152. static bool isci_check_devempty(
  153. struct isci_host *ihost,
  154. struct isci_remote_device *idev,
  155. u32 localcount)
  156. {
  157. unsigned long flags;
  158. bool res;
  159. spin_lock_irqsave(&ihost->scic_lock, flags);
  160. res = isci_compare_suspendcount(idev, localcount)
  161. && idev->started_request_count == 0;
  162. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  163. return res;
  164. }
  165. enum sci_status isci_remote_device_terminate_requests(
  166. struct isci_host *ihost,
  167. struct isci_remote_device *idev,
  168. struct isci_request *ireq)
  169. {
  170. enum sci_status status = SCI_SUCCESS;
  171. unsigned long flags;
  172. u32 rnc_suspend_count;
  173. spin_lock_irqsave(&ihost->scic_lock, flags);
  174. if (isci_get_device(idev) == NULL) {
  175. dev_dbg(&ihost->pdev->dev, "%s: failed isci_get_device(idev=%p)\n",
  176. __func__, idev);
  177. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  178. status = SCI_FAILURE;
  179. } else {
  180. /* If already suspended, don't wait for another suspension. */
  181. smp_rmb();
  182. rnc_suspend_count
  183. = sci_remote_node_context_is_suspended(&idev->rnc)
  184. ? 0 : idev->rnc.suspend_count;
  185. dev_dbg(&ihost->pdev->dev,
  186. "%s: idev=%p, ireq=%p; started_request_count=%d, "
  187. "rnc_suspend_count=%d, rnc.suspend_count=%d"
  188. "about to wait\n",
  189. __func__, idev, ireq, idev->started_request_count,
  190. rnc_suspend_count, idev->rnc.suspend_count);
  191. #define MAX_SUSPEND_MSECS 10000
  192. if (ireq) {
  193. /* Terminate a specific TC. */
  194. set_bit(IREQ_NO_AUTO_FREE_TAG, &ireq->flags);
  195. sci_remote_device_terminate_req(ihost, idev, 0, ireq);
  196. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  197. if (!wait_event_timeout(ihost->eventq,
  198. isci_check_reqterm(ihost, idev, ireq,
  199. rnc_suspend_count),
  200. msecs_to_jiffies(MAX_SUSPEND_MSECS))) {
  201. dev_warn(&ihost->pdev->dev, "%s host%d timeout single\n",
  202. __func__, ihost->id);
  203. dev_dbg(&ihost->pdev->dev,
  204. "%s: ******* Timeout waiting for "
  205. "suspend; idev=%p, current state %s; "
  206. "started_request_count=%d, flags=%lx\n\t"
  207. "rnc_suspend_count=%d, rnc.suspend_count=%d "
  208. "RNC: current state %s, current "
  209. "suspend_type %x dest state %d;\n"
  210. "ireq=%p, ireq->flags = %lx\n",
  211. __func__, idev,
  212. dev_state_name(idev->sm.current_state_id),
  213. idev->started_request_count, idev->flags,
  214. rnc_suspend_count, idev->rnc.suspend_count,
  215. rnc_state_name(idev->rnc.sm.current_state_id),
  216. idev->rnc.suspend_type,
  217. idev->rnc.destination_state,
  218. ireq, ireq->flags);
  219. }
  220. spin_lock_irqsave(&ihost->scic_lock, flags);
  221. clear_bit(IREQ_NO_AUTO_FREE_TAG, &ireq->flags);
  222. if (!test_bit(IREQ_ABORT_PATH_ACTIVE, &ireq->flags))
  223. isci_free_tag(ihost, ireq->io_tag);
  224. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  225. } else {
  226. /* Terminate all TCs. */
  227. sci_remote_device_terminate_requests(idev);
  228. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  229. if (!wait_event_timeout(ihost->eventq,
  230. isci_check_devempty(ihost, idev,
  231. rnc_suspend_count),
  232. msecs_to_jiffies(MAX_SUSPEND_MSECS))) {
  233. dev_warn(&ihost->pdev->dev, "%s host%d timeout all\n",
  234. __func__, ihost->id);
  235. dev_dbg(&ihost->pdev->dev,
  236. "%s: ******* Timeout waiting for "
  237. "suspend; idev=%p, current state %s; "
  238. "started_request_count=%d, flags=%lx\n\t"
  239. "rnc_suspend_count=%d, "
  240. "RNC: current state %s, "
  241. "rnc.suspend_count=%d, current "
  242. "suspend_type %x dest state %d\n",
  243. __func__, idev,
  244. dev_state_name(idev->sm.current_state_id),
  245. idev->started_request_count, idev->flags,
  246. rnc_suspend_count,
  247. rnc_state_name(idev->rnc.sm.current_state_id),
  248. idev->rnc.suspend_count,
  249. idev->rnc.suspend_type,
  250. idev->rnc.destination_state);
  251. }
  252. }
  253. dev_dbg(&ihost->pdev->dev, "%s: idev=%p, wait done\n",
  254. __func__, idev);
  255. isci_put_device(idev);
  256. }
  257. return status;
  258. }
  259. /**
  260. * isci_remote_device_not_ready() - This function is called by the ihost when
  261. * the remote device is not ready. We mark the isci device as ready (not
  262. * "ready_for_io") and signal the waiting proccess.
  263. * @isci_host: This parameter specifies the isci host object.
  264. * @isci_device: This parameter specifies the remote device
  265. *
  266. * sci_lock is held on entrance to this function.
  267. */
  268. static void isci_remote_device_not_ready(struct isci_host *ihost,
  269. struct isci_remote_device *idev,
  270. u32 reason)
  271. {
  272. dev_dbg(&ihost->pdev->dev,
  273. "%s: isci_device = %p; reason = %d\n", __func__, idev, reason);
  274. switch (reason) {
  275. case SCIC_REMOTE_DEVICE_NOT_READY_SATA_SDB_ERROR_FIS_RECEIVED:
  276. set_bit(IDEV_IO_NCQERROR, &idev->flags);
  277. /* Suspend the remote device so the I/O can be terminated. */
  278. sci_remote_device_suspend(idev, SCI_SW_SUSPEND_NORMAL);
  279. /* Kill all outstanding requests for the device. */
  280. sci_remote_device_terminate_requests(idev);
  281. /* Fall through into the default case... */
  282. default:
  283. clear_bit(IDEV_IO_READY, &idev->flags);
  284. break;
  285. }
  286. }
  287. /* called once the remote node context is ready to be freed.
  288. * The remote device can now report that its stop operation is complete. none
  289. */
  290. static void rnc_destruct_done(void *_dev)
  291. {
  292. struct isci_remote_device *idev = _dev;
  293. BUG_ON(idev->started_request_count != 0);
  294. sci_change_state(&idev->sm, SCI_DEV_STOPPED);
  295. }
  296. enum sci_status sci_remote_device_terminate_requests(
  297. struct isci_remote_device *idev)
  298. {
  299. return sci_remote_device_terminate_reqs_checkabort(idev, 0);
  300. }
  301. enum sci_status sci_remote_device_stop(struct isci_remote_device *idev,
  302. u32 timeout)
  303. {
  304. struct sci_base_state_machine *sm = &idev->sm;
  305. enum sci_remote_device_states state = sm->current_state_id;
  306. switch (state) {
  307. case SCI_DEV_INITIAL:
  308. case SCI_DEV_FAILED:
  309. case SCI_DEV_FINAL:
  310. default:
  311. dev_warn(scirdev_to_dev(idev), "%s: in wrong state: %s\n",
  312. __func__, dev_state_name(state));
  313. return SCI_FAILURE_INVALID_STATE;
  314. case SCI_DEV_STOPPED:
  315. return SCI_SUCCESS;
  316. case SCI_DEV_STARTING:
  317. /* device not started so there had better be no requests */
  318. BUG_ON(idev->started_request_count != 0);
  319. sci_remote_node_context_destruct(&idev->rnc,
  320. rnc_destruct_done, idev);
  321. /* Transition to the stopping state and wait for the
  322. * remote node to complete being posted and invalidated.
  323. */
  324. sci_change_state(sm, SCI_DEV_STOPPING);
  325. return SCI_SUCCESS;
  326. case SCI_DEV_READY:
  327. case SCI_STP_DEV_IDLE:
  328. case SCI_STP_DEV_CMD:
  329. case SCI_STP_DEV_NCQ:
  330. case SCI_STP_DEV_NCQ_ERROR:
  331. case SCI_STP_DEV_AWAIT_RESET:
  332. case SCI_SMP_DEV_IDLE:
  333. case SCI_SMP_DEV_CMD:
  334. sci_change_state(sm, SCI_DEV_STOPPING);
  335. if (idev->started_request_count == 0)
  336. sci_remote_node_context_destruct(&idev->rnc,
  337. rnc_destruct_done,
  338. idev);
  339. else {
  340. sci_remote_device_suspend(
  341. idev, SCI_SW_SUSPEND_LINKHANG_DETECT);
  342. sci_remote_device_terminate_requests(idev);
  343. }
  344. return SCI_SUCCESS;
  345. case SCI_DEV_STOPPING:
  346. /* All requests should have been terminated, but if there is an
  347. * attempt to stop a device already in the stopping state, then
  348. * try again to terminate.
  349. */
  350. return sci_remote_device_terminate_requests(idev);
  351. case SCI_DEV_RESETTING:
  352. sci_change_state(sm, SCI_DEV_STOPPING);
  353. return SCI_SUCCESS;
  354. }
  355. }
  356. enum sci_status sci_remote_device_reset(struct isci_remote_device *idev)
  357. {
  358. struct sci_base_state_machine *sm = &idev->sm;
  359. enum sci_remote_device_states state = sm->current_state_id;
  360. switch (state) {
  361. case SCI_DEV_INITIAL:
  362. case SCI_DEV_STOPPED:
  363. case SCI_DEV_STARTING:
  364. case SCI_SMP_DEV_IDLE:
  365. case SCI_SMP_DEV_CMD:
  366. case SCI_DEV_STOPPING:
  367. case SCI_DEV_FAILED:
  368. case SCI_DEV_RESETTING:
  369. case SCI_DEV_FINAL:
  370. default:
  371. dev_warn(scirdev_to_dev(idev), "%s: in wrong state: %s\n",
  372. __func__, dev_state_name(state));
  373. return SCI_FAILURE_INVALID_STATE;
  374. case SCI_DEV_READY:
  375. case SCI_STP_DEV_IDLE:
  376. case SCI_STP_DEV_CMD:
  377. case SCI_STP_DEV_NCQ:
  378. case SCI_STP_DEV_NCQ_ERROR:
  379. case SCI_STP_DEV_AWAIT_RESET:
  380. sci_change_state(sm, SCI_DEV_RESETTING);
  381. return SCI_SUCCESS;
  382. }
  383. }
  384. enum sci_status sci_remote_device_reset_complete(struct isci_remote_device *idev)
  385. {
  386. struct sci_base_state_machine *sm = &idev->sm;
  387. enum sci_remote_device_states state = sm->current_state_id;
  388. if (state != SCI_DEV_RESETTING) {
  389. dev_warn(scirdev_to_dev(idev), "%s: in wrong state: %s\n",
  390. __func__, dev_state_name(state));
  391. return SCI_FAILURE_INVALID_STATE;
  392. }
  393. sci_change_state(sm, SCI_DEV_READY);
  394. return SCI_SUCCESS;
  395. }
  396. enum sci_status sci_remote_device_frame_handler(struct isci_remote_device *idev,
  397. u32 frame_index)
  398. {
  399. struct sci_base_state_machine *sm = &idev->sm;
  400. enum sci_remote_device_states state = sm->current_state_id;
  401. struct isci_host *ihost = idev->owning_port->owning_controller;
  402. enum sci_status status;
  403. switch (state) {
  404. case SCI_DEV_INITIAL:
  405. case SCI_DEV_STOPPED:
  406. case SCI_DEV_STARTING:
  407. case SCI_STP_DEV_IDLE:
  408. case SCI_SMP_DEV_IDLE:
  409. case SCI_DEV_FINAL:
  410. default:
  411. dev_warn(scirdev_to_dev(idev), "%s: in wrong state: %s\n",
  412. __func__, dev_state_name(state));
  413. /* Return the frame back to the controller */
  414. sci_controller_release_frame(ihost, frame_index);
  415. return SCI_FAILURE_INVALID_STATE;
  416. case SCI_DEV_READY:
  417. case SCI_STP_DEV_NCQ_ERROR:
  418. case SCI_STP_DEV_AWAIT_RESET:
  419. case SCI_DEV_STOPPING:
  420. case SCI_DEV_FAILED:
  421. case SCI_DEV_RESETTING: {
  422. struct isci_request *ireq;
  423. struct ssp_frame_hdr hdr;
  424. void *frame_header;
  425. ssize_t word_cnt;
  426. status = sci_unsolicited_frame_control_get_header(&ihost->uf_control,
  427. frame_index,
  428. &frame_header);
  429. if (status != SCI_SUCCESS)
  430. return status;
  431. word_cnt = sizeof(hdr) / sizeof(u32);
  432. sci_swab32_cpy(&hdr, frame_header, word_cnt);
  433. ireq = sci_request_by_tag(ihost, be16_to_cpu(hdr.tag));
  434. if (ireq && ireq->target_device == idev) {
  435. /* The IO request is now in charge of releasing the frame */
  436. status = sci_io_request_frame_handler(ireq, frame_index);
  437. } else {
  438. /* We could not map this tag to a valid IO
  439. * request Just toss the frame and continue
  440. */
  441. sci_controller_release_frame(ihost, frame_index);
  442. }
  443. break;
  444. }
  445. case SCI_STP_DEV_NCQ: {
  446. struct dev_to_host_fis *hdr;
  447. status = sci_unsolicited_frame_control_get_header(&ihost->uf_control,
  448. frame_index,
  449. (void **)&hdr);
  450. if (status != SCI_SUCCESS)
  451. return status;
  452. if (hdr->fis_type == FIS_SETDEVBITS &&
  453. (hdr->status & ATA_ERR)) {
  454. idev->not_ready_reason = SCIC_REMOTE_DEVICE_NOT_READY_SATA_SDB_ERROR_FIS_RECEIVED;
  455. /* TODO Check sactive and complete associated IO if any. */
  456. sci_change_state(sm, SCI_STP_DEV_NCQ_ERROR);
  457. } else if (hdr->fis_type == FIS_REGD2H &&
  458. (hdr->status & ATA_ERR)) {
  459. /*
  460. * Some devices return D2H FIS when an NCQ error is detected.
  461. * Treat this like an SDB error FIS ready reason.
  462. */
  463. idev->not_ready_reason = SCIC_REMOTE_DEVICE_NOT_READY_SATA_SDB_ERROR_FIS_RECEIVED;
  464. sci_change_state(&idev->sm, SCI_STP_DEV_NCQ_ERROR);
  465. } else
  466. status = SCI_FAILURE;
  467. sci_controller_release_frame(ihost, frame_index);
  468. break;
  469. }
  470. case SCI_STP_DEV_CMD:
  471. case SCI_SMP_DEV_CMD:
  472. /* The device does not process any UF received from the hardware while
  473. * in this state. All unsolicited frames are forwarded to the io request
  474. * object.
  475. */
  476. status = sci_io_request_frame_handler(idev->working_request, frame_index);
  477. break;
  478. }
  479. return status;
  480. }
  481. static bool is_remote_device_ready(struct isci_remote_device *idev)
  482. {
  483. struct sci_base_state_machine *sm = &idev->sm;
  484. enum sci_remote_device_states state = sm->current_state_id;
  485. switch (state) {
  486. case SCI_DEV_READY:
  487. case SCI_STP_DEV_IDLE:
  488. case SCI_STP_DEV_CMD:
  489. case SCI_STP_DEV_NCQ:
  490. case SCI_STP_DEV_NCQ_ERROR:
  491. case SCI_STP_DEV_AWAIT_RESET:
  492. case SCI_SMP_DEV_IDLE:
  493. case SCI_SMP_DEV_CMD:
  494. return true;
  495. default:
  496. return false;
  497. }
  498. }
  499. /*
  500. * called once the remote node context has transisitioned to a ready
  501. * state (after suspending RX and/or TX due to early D2H fis)
  502. */
  503. static void atapi_remote_device_resume_done(void *_dev)
  504. {
  505. struct isci_remote_device *idev = _dev;
  506. struct isci_request *ireq = idev->working_request;
  507. sci_change_state(&ireq->sm, SCI_REQ_COMPLETED);
  508. }
  509. enum sci_status sci_remote_device_event_handler(struct isci_remote_device *idev,
  510. u32 event_code)
  511. {
  512. enum sci_status status;
  513. struct sci_base_state_machine *sm = &idev->sm;
  514. enum sci_remote_device_states state = sm->current_state_id;
  515. switch (scu_get_event_type(event_code)) {
  516. case SCU_EVENT_TYPE_RNC_OPS_MISC:
  517. case SCU_EVENT_TYPE_RNC_SUSPEND_TX:
  518. case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX:
  519. status = sci_remote_node_context_event_handler(&idev->rnc, event_code);
  520. break;
  521. case SCU_EVENT_TYPE_PTX_SCHEDULE_EVENT:
  522. if (scu_get_event_code(event_code) == SCU_EVENT_IT_NEXUS_TIMEOUT) {
  523. status = SCI_SUCCESS;
  524. /* Suspend the associated RNC */
  525. sci_remote_device_suspend(idev, SCI_SW_SUSPEND_NORMAL);
  526. dev_dbg(scirdev_to_dev(idev),
  527. "%s: device: %p event code: %x: %s\n",
  528. __func__, idev, event_code,
  529. is_remote_device_ready(idev)
  530. ? "I_T_Nexus_Timeout event"
  531. : "I_T_Nexus_Timeout event in wrong state");
  532. break;
  533. }
  534. /* Else, fall through and treat as unhandled... */
  535. default:
  536. dev_dbg(scirdev_to_dev(idev),
  537. "%s: device: %p event code: %x: %s\n",
  538. __func__, idev, event_code,
  539. is_remote_device_ready(idev)
  540. ? "unexpected event"
  541. : "unexpected event in wrong state");
  542. status = SCI_FAILURE_INVALID_STATE;
  543. break;
  544. }
  545. if (status != SCI_SUCCESS)
  546. return status;
  547. /* Decode device-specific states that may require an RNC resume during
  548. * normal operation. When the abort path is active, these resumes are
  549. * managed when the abort path exits.
  550. */
  551. if (state == SCI_STP_DEV_ATAPI_ERROR) {
  552. /* For ATAPI error state resume the RNC right away. */
  553. if (scu_get_event_type(event_code) == SCU_EVENT_TYPE_RNC_SUSPEND_TX ||
  554. scu_get_event_type(event_code) == SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX) {
  555. return sci_remote_node_context_resume(&idev->rnc,
  556. atapi_remote_device_resume_done,
  557. idev);
  558. }
  559. }
  560. if (state == SCI_STP_DEV_IDLE) {
  561. /* We pick up suspension events to handle specifically to this
  562. * state. We resume the RNC right away.
  563. */
  564. if (scu_get_event_type(event_code) == SCU_EVENT_TYPE_RNC_SUSPEND_TX ||
  565. scu_get_event_type(event_code) == SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX)
  566. status = sci_remote_node_context_resume(&idev->rnc, NULL, NULL);
  567. }
  568. return status;
  569. }
  570. static void sci_remote_device_start_request(struct isci_remote_device *idev,
  571. struct isci_request *ireq,
  572. enum sci_status status)
  573. {
  574. struct isci_port *iport = idev->owning_port;
  575. /* cleanup requests that failed after starting on the port */
  576. if (status != SCI_SUCCESS)
  577. sci_port_complete_io(iport, idev, ireq);
  578. else {
  579. kref_get(&idev->kref);
  580. idev->started_request_count++;
  581. }
  582. }
  583. enum sci_status sci_remote_device_start_io(struct isci_host *ihost,
  584. struct isci_remote_device *idev,
  585. struct isci_request *ireq)
  586. {
  587. struct sci_base_state_machine *sm = &idev->sm;
  588. enum sci_remote_device_states state = sm->current_state_id;
  589. struct isci_port *iport = idev->owning_port;
  590. enum sci_status status;
  591. switch (state) {
  592. case SCI_DEV_INITIAL:
  593. case SCI_DEV_STOPPED:
  594. case SCI_DEV_STARTING:
  595. case SCI_STP_DEV_NCQ_ERROR:
  596. case SCI_DEV_STOPPING:
  597. case SCI_DEV_FAILED:
  598. case SCI_DEV_RESETTING:
  599. case SCI_DEV_FINAL:
  600. default:
  601. dev_warn(scirdev_to_dev(idev), "%s: in wrong state: %s\n",
  602. __func__, dev_state_name(state));
  603. return SCI_FAILURE_INVALID_STATE;
  604. case SCI_DEV_READY:
  605. /* attempt to start an io request for this device object. The remote
  606. * device object will issue the start request for the io and if
  607. * successful it will start the request for the port object then
  608. * increment its own request count.
  609. */
  610. status = sci_port_start_io(iport, idev, ireq);
  611. if (status != SCI_SUCCESS)
  612. return status;
  613. status = sci_remote_node_context_start_io(&idev->rnc, ireq);
  614. if (status != SCI_SUCCESS)
  615. break;
  616. status = sci_request_start(ireq);
  617. break;
  618. case SCI_STP_DEV_IDLE: {
  619. /* handle the start io operation for a sata device that is in
  620. * the command idle state. - Evalute the type of IO request to
  621. * be started - If its an NCQ request change to NCQ substate -
  622. * If its any other command change to the CMD substate
  623. *
  624. * If this is a softreset we may want to have a different
  625. * substate.
  626. */
  627. enum sci_remote_device_states new_state;
  628. struct sas_task *task = isci_request_access_task(ireq);
  629. status = sci_port_start_io(iport, idev, ireq);
  630. if (status != SCI_SUCCESS)
  631. return status;
  632. status = sci_remote_node_context_start_io(&idev->rnc, ireq);
  633. if (status != SCI_SUCCESS)
  634. break;
  635. status = sci_request_start(ireq);
  636. if (status != SCI_SUCCESS)
  637. break;
  638. if (task->ata_task.use_ncq)
  639. new_state = SCI_STP_DEV_NCQ;
  640. else {
  641. idev->working_request = ireq;
  642. new_state = SCI_STP_DEV_CMD;
  643. }
  644. sci_change_state(sm, new_state);
  645. break;
  646. }
  647. case SCI_STP_DEV_NCQ: {
  648. struct sas_task *task = isci_request_access_task(ireq);
  649. if (task->ata_task.use_ncq) {
  650. status = sci_port_start_io(iport, idev, ireq);
  651. if (status != SCI_SUCCESS)
  652. return status;
  653. status = sci_remote_node_context_start_io(&idev->rnc, ireq);
  654. if (status != SCI_SUCCESS)
  655. break;
  656. status = sci_request_start(ireq);
  657. } else
  658. return SCI_FAILURE_INVALID_STATE;
  659. break;
  660. }
  661. case SCI_STP_DEV_AWAIT_RESET:
  662. return SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED;
  663. case SCI_SMP_DEV_IDLE:
  664. status = sci_port_start_io(iport, idev, ireq);
  665. if (status != SCI_SUCCESS)
  666. return status;
  667. status = sci_remote_node_context_start_io(&idev->rnc, ireq);
  668. if (status != SCI_SUCCESS)
  669. break;
  670. status = sci_request_start(ireq);
  671. if (status != SCI_SUCCESS)
  672. break;
  673. idev->working_request = ireq;
  674. sci_change_state(&idev->sm, SCI_SMP_DEV_CMD);
  675. break;
  676. case SCI_STP_DEV_CMD:
  677. case SCI_SMP_DEV_CMD:
  678. /* device is already handling a command it can not accept new commands
  679. * until this one is complete.
  680. */
  681. return SCI_FAILURE_INVALID_STATE;
  682. }
  683. sci_remote_device_start_request(idev, ireq, status);
  684. return status;
  685. }
  686. static enum sci_status common_complete_io(struct isci_port *iport,
  687. struct isci_remote_device *idev,
  688. struct isci_request *ireq)
  689. {
  690. enum sci_status status;
  691. status = sci_request_complete(ireq);
  692. if (status != SCI_SUCCESS)
  693. return status;
  694. status = sci_port_complete_io(iport, idev, ireq);
  695. if (status != SCI_SUCCESS)
  696. return status;
  697. sci_remote_device_decrement_request_count(idev);
  698. return status;
  699. }
  700. enum sci_status sci_remote_device_complete_io(struct isci_host *ihost,
  701. struct isci_remote_device *idev,
  702. struct isci_request *ireq)
  703. {
  704. struct sci_base_state_machine *sm = &idev->sm;
  705. enum sci_remote_device_states state = sm->current_state_id;
  706. struct isci_port *iport = idev->owning_port;
  707. enum sci_status status;
  708. switch (state) {
  709. case SCI_DEV_INITIAL:
  710. case SCI_DEV_STOPPED:
  711. case SCI_DEV_STARTING:
  712. case SCI_STP_DEV_IDLE:
  713. case SCI_SMP_DEV_IDLE:
  714. case SCI_DEV_FAILED:
  715. case SCI_DEV_FINAL:
  716. default:
  717. dev_warn(scirdev_to_dev(idev), "%s: in wrong state: %s\n",
  718. __func__, dev_state_name(state));
  719. return SCI_FAILURE_INVALID_STATE;
  720. case SCI_DEV_READY:
  721. case SCI_STP_DEV_AWAIT_RESET:
  722. case SCI_DEV_RESETTING:
  723. status = common_complete_io(iport, idev, ireq);
  724. break;
  725. case SCI_STP_DEV_CMD:
  726. case SCI_STP_DEV_NCQ:
  727. case SCI_STP_DEV_NCQ_ERROR:
  728. case SCI_STP_DEV_ATAPI_ERROR:
  729. status = common_complete_io(iport, idev, ireq);
  730. if (status != SCI_SUCCESS)
  731. break;
  732. if (ireq->sci_status == SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) {
  733. /* This request causes hardware error, device needs to be Lun Reset.
  734. * So here we force the state machine to IDLE state so the rest IOs
  735. * can reach RNC state handler, these IOs will be completed by RNC with
  736. * status of "DEVICE_RESET_REQUIRED", instead of "INVALID STATE".
  737. */
  738. sci_change_state(sm, SCI_STP_DEV_AWAIT_RESET);
  739. } else if (idev->started_request_count == 0)
  740. sci_change_state(sm, SCI_STP_DEV_IDLE);
  741. break;
  742. case SCI_SMP_DEV_CMD:
  743. status = common_complete_io(iport, idev, ireq);
  744. if (status != SCI_SUCCESS)
  745. break;
  746. sci_change_state(sm, SCI_SMP_DEV_IDLE);
  747. break;
  748. case SCI_DEV_STOPPING:
  749. status = common_complete_io(iport, idev, ireq);
  750. if (status != SCI_SUCCESS)
  751. break;
  752. if (idev->started_request_count == 0)
  753. sci_remote_node_context_destruct(&idev->rnc,
  754. rnc_destruct_done,
  755. idev);
  756. break;
  757. }
  758. if (status != SCI_SUCCESS)
  759. dev_err(scirdev_to_dev(idev),
  760. "%s: Port:0x%p Device:0x%p Request:0x%p Status:0x%x "
  761. "could not complete\n", __func__, iport,
  762. idev, ireq, status);
  763. else
  764. isci_put_device(idev);
  765. return status;
  766. }
  767. static void sci_remote_device_continue_request(void *dev)
  768. {
  769. struct isci_remote_device *idev = dev;
  770. /* we need to check if this request is still valid to continue. */
  771. if (idev->working_request)
  772. sci_controller_continue_io(idev->working_request);
  773. }
  774. enum sci_status sci_remote_device_start_task(struct isci_host *ihost,
  775. struct isci_remote_device *idev,
  776. struct isci_request *ireq)
  777. {
  778. struct sci_base_state_machine *sm = &idev->sm;
  779. enum sci_remote_device_states state = sm->current_state_id;
  780. struct isci_port *iport = idev->owning_port;
  781. enum sci_status status;
  782. switch (state) {
  783. case SCI_DEV_INITIAL:
  784. case SCI_DEV_STOPPED:
  785. case SCI_DEV_STARTING:
  786. case SCI_SMP_DEV_IDLE:
  787. case SCI_SMP_DEV_CMD:
  788. case SCI_DEV_STOPPING:
  789. case SCI_DEV_FAILED:
  790. case SCI_DEV_RESETTING:
  791. case SCI_DEV_FINAL:
  792. default:
  793. dev_warn(scirdev_to_dev(idev), "%s: in wrong state: %s\n",
  794. __func__, dev_state_name(state));
  795. return SCI_FAILURE_INVALID_STATE;
  796. case SCI_STP_DEV_IDLE:
  797. case SCI_STP_DEV_CMD:
  798. case SCI_STP_DEV_NCQ:
  799. case SCI_STP_DEV_NCQ_ERROR:
  800. case SCI_STP_DEV_AWAIT_RESET:
  801. status = sci_port_start_io(iport, idev, ireq);
  802. if (status != SCI_SUCCESS)
  803. return status;
  804. status = sci_request_start(ireq);
  805. if (status != SCI_SUCCESS)
  806. goto out;
  807. /* Note: If the remote device state is not IDLE this will
  808. * replace the request that probably resulted in the task
  809. * management request.
  810. */
  811. idev->working_request = ireq;
  812. sci_change_state(sm, SCI_STP_DEV_CMD);
  813. /* The remote node context must cleanup the TCi to NCQ mapping
  814. * table. The only way to do this correctly is to either write
  815. * to the TLCR register or to invalidate and repost the RNC. In
  816. * either case the remote node context state machine will take
  817. * the correct action when the remote node context is suspended
  818. * and later resumed.
  819. */
  820. sci_remote_device_suspend(idev,
  821. SCI_SW_SUSPEND_LINKHANG_DETECT);
  822. status = sci_remote_node_context_start_task(&idev->rnc, ireq,
  823. sci_remote_device_continue_request, idev);
  824. out:
  825. sci_remote_device_start_request(idev, ireq, status);
  826. /* We need to let the controller start request handler know that
  827. * it can't post TC yet. We will provide a callback function to
  828. * post TC when RNC gets resumed.
  829. */
  830. return SCI_FAILURE_RESET_DEVICE_PARTIAL_SUCCESS;
  831. case SCI_DEV_READY:
  832. status = sci_port_start_io(iport, idev, ireq);
  833. if (status != SCI_SUCCESS)
  834. return status;
  835. /* Resume the RNC as needed: */
  836. status = sci_remote_node_context_start_task(&idev->rnc, ireq,
  837. NULL, NULL);
  838. if (status != SCI_SUCCESS)
  839. break;
  840. status = sci_request_start(ireq);
  841. break;
  842. }
  843. sci_remote_device_start_request(idev, ireq, status);
  844. return status;
  845. }
  846. void sci_remote_device_post_request(struct isci_remote_device *idev, u32 request)
  847. {
  848. struct isci_port *iport = idev->owning_port;
  849. u32 context;
  850. context = request |
  851. (ISCI_PEG << SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) |
  852. (iport->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) |
  853. idev->rnc.remote_node_index;
  854. sci_controller_post_request(iport->owning_controller, context);
  855. }
  856. /* called once the remote node context has transisitioned to a
  857. * ready state. This is the indication that the remote device object can also
  858. * transition to ready.
  859. */
  860. static void remote_device_resume_done(void *_dev)
  861. {
  862. struct isci_remote_device *idev = _dev;
  863. if (is_remote_device_ready(idev))
  864. return;
  865. /* go 'ready' if we are not already in a ready state */
  866. sci_change_state(&idev->sm, SCI_DEV_READY);
  867. }
  868. static void sci_stp_remote_device_ready_idle_substate_resume_complete_handler(void *_dev)
  869. {
  870. struct isci_remote_device *idev = _dev;
  871. struct isci_host *ihost = idev->owning_port->owning_controller;
  872. /* For NCQ operation we do not issue a isci_remote_device_not_ready().
  873. * As a result, avoid sending the ready notification.
  874. */
  875. if (idev->sm.previous_state_id != SCI_STP_DEV_NCQ)
  876. isci_remote_device_ready(ihost, idev);
  877. }
  878. static void sci_remote_device_initial_state_enter(struct sci_base_state_machine *sm)
  879. {
  880. struct isci_remote_device *idev = container_of(sm, typeof(*idev), sm);
  881. /* Initial state is a transitional state to the stopped state */
  882. sci_change_state(&idev->sm, SCI_DEV_STOPPED);
  883. }
  884. /**
  885. * sci_remote_device_destruct() - free remote node context and destruct
  886. * @remote_device: This parameter specifies the remote device to be destructed.
  887. *
  888. * Remote device objects are a limited resource. As such, they must be
  889. * protected. Thus calls to construct and destruct are mutually exclusive and
  890. * non-reentrant. The return value shall indicate if the device was
  891. * successfully destructed or if some failure occurred. enum sci_status This value
  892. * is returned if the device is successfully destructed.
  893. * SCI_FAILURE_INVALID_REMOTE_DEVICE This value is returned if the supplied
  894. * device isn't valid (e.g. it's already been destoryed, the handle isn't
  895. * valid, etc.).
  896. */
  897. static enum sci_status sci_remote_device_destruct(struct isci_remote_device *idev)
  898. {
  899. struct sci_base_state_machine *sm = &idev->sm;
  900. enum sci_remote_device_states state = sm->current_state_id;
  901. struct isci_host *ihost;
  902. if (state != SCI_DEV_STOPPED) {
  903. dev_warn(scirdev_to_dev(idev), "%s: in wrong state: %s\n",
  904. __func__, dev_state_name(state));
  905. return SCI_FAILURE_INVALID_STATE;
  906. }
  907. ihost = idev->owning_port->owning_controller;
  908. sci_controller_free_remote_node_context(ihost, idev,
  909. idev->rnc.remote_node_index);
  910. idev->rnc.remote_node_index = SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX;
  911. sci_change_state(sm, SCI_DEV_FINAL);
  912. return SCI_SUCCESS;
  913. }
  914. /**
  915. * isci_remote_device_deconstruct() - This function frees an isci_remote_device.
  916. * @ihost: This parameter specifies the isci host object.
  917. * @idev: This parameter specifies the remote device to be freed.
  918. *
  919. */
  920. static void isci_remote_device_deconstruct(struct isci_host *ihost, struct isci_remote_device *idev)
  921. {
  922. dev_dbg(&ihost->pdev->dev,
  923. "%s: isci_device = %p\n", __func__, idev);
  924. /* There should not be any outstanding io's. All paths to
  925. * here should go through isci_remote_device_nuke_requests.
  926. * If we hit this condition, we will need a way to complete
  927. * io requests in process */
  928. BUG_ON(idev->started_request_count > 0);
  929. sci_remote_device_destruct(idev);
  930. list_del_init(&idev->node);
  931. isci_put_device(idev);
  932. }
  933. static void sci_remote_device_stopped_state_enter(struct sci_base_state_machine *sm)
  934. {
  935. struct isci_remote_device *idev = container_of(sm, typeof(*idev), sm);
  936. struct isci_host *ihost = idev->owning_port->owning_controller;
  937. u32 prev_state;
  938. /* If we are entering from the stopping state let the SCI User know that
  939. * the stop operation has completed.
  940. */
  941. prev_state = idev->sm.previous_state_id;
  942. if (prev_state == SCI_DEV_STOPPING)
  943. isci_remote_device_deconstruct(ihost, idev);
  944. sci_controller_remote_device_stopped(ihost, idev);
  945. }
  946. static void sci_remote_device_starting_state_enter(struct sci_base_state_machine *sm)
  947. {
  948. struct isci_remote_device *idev = container_of(sm, typeof(*idev), sm);
  949. struct isci_host *ihost = idev->owning_port->owning_controller;
  950. isci_remote_device_not_ready(ihost, idev,
  951. SCIC_REMOTE_DEVICE_NOT_READY_START_REQUESTED);
  952. }
  953. static void sci_remote_device_ready_state_enter(struct sci_base_state_machine *sm)
  954. {
  955. struct isci_remote_device *idev = container_of(sm, typeof(*idev), sm);
  956. struct isci_host *ihost = idev->owning_port->owning_controller;
  957. struct domain_device *dev = idev->domain_dev;
  958. if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_SATA)) {
  959. sci_change_state(&idev->sm, SCI_STP_DEV_IDLE);
  960. } else if (dev_is_expander(dev)) {
  961. sci_change_state(&idev->sm, SCI_SMP_DEV_IDLE);
  962. } else
  963. isci_remote_device_ready(ihost, idev);
  964. }
  965. static void sci_remote_device_ready_state_exit(struct sci_base_state_machine *sm)
  966. {
  967. struct isci_remote_device *idev = container_of(sm, typeof(*idev), sm);
  968. struct domain_device *dev = idev->domain_dev;
  969. if (dev->dev_type == SAS_END_DEV) {
  970. struct isci_host *ihost = idev->owning_port->owning_controller;
  971. isci_remote_device_not_ready(ihost, idev,
  972. SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED);
  973. }
  974. }
  975. static void sci_remote_device_resetting_state_enter(struct sci_base_state_machine *sm)
  976. {
  977. struct isci_remote_device *idev = container_of(sm, typeof(*idev), sm);
  978. struct isci_host *ihost = idev->owning_port->owning_controller;
  979. dev_dbg(&ihost->pdev->dev,
  980. "%s: isci_device = %p\n", __func__, idev);
  981. sci_remote_device_suspend(idev, SCI_SW_SUSPEND_LINKHANG_DETECT);
  982. }
  983. static void sci_remote_device_resetting_state_exit(struct sci_base_state_machine *sm)
  984. {
  985. struct isci_remote_device *idev = container_of(sm, typeof(*idev), sm);
  986. struct isci_host *ihost = idev->owning_port->owning_controller;
  987. dev_dbg(&ihost->pdev->dev,
  988. "%s: isci_device = %p\n", __func__, idev);
  989. sci_remote_node_context_resume(&idev->rnc, NULL, NULL);
  990. }
  991. static void sci_stp_remote_device_ready_idle_substate_enter(struct sci_base_state_machine *sm)
  992. {
  993. struct isci_remote_device *idev = container_of(sm, typeof(*idev), sm);
  994. idev->working_request = NULL;
  995. if (sci_remote_node_context_is_ready(&idev->rnc)) {
  996. /*
  997. * Since the RNC is ready, it's alright to finish completion
  998. * processing (e.g. signal the remote device is ready). */
  999. sci_stp_remote_device_ready_idle_substate_resume_complete_handler(idev);
  1000. } else {
  1001. sci_remote_node_context_resume(&idev->rnc,
  1002. sci_stp_remote_device_ready_idle_substate_resume_complete_handler,
  1003. idev);
  1004. }
  1005. }
  1006. static void sci_stp_remote_device_ready_cmd_substate_enter(struct sci_base_state_machine *sm)
  1007. {
  1008. struct isci_remote_device *idev = container_of(sm, typeof(*idev), sm);
  1009. struct isci_host *ihost = idev->owning_port->owning_controller;
  1010. BUG_ON(idev->working_request == NULL);
  1011. isci_remote_device_not_ready(ihost, idev,
  1012. SCIC_REMOTE_DEVICE_NOT_READY_SATA_REQUEST_STARTED);
  1013. }
  1014. static void sci_stp_remote_device_ready_ncq_error_substate_enter(struct sci_base_state_machine *sm)
  1015. {
  1016. struct isci_remote_device *idev = container_of(sm, typeof(*idev), sm);
  1017. struct isci_host *ihost = idev->owning_port->owning_controller;
  1018. if (idev->not_ready_reason == SCIC_REMOTE_DEVICE_NOT_READY_SATA_SDB_ERROR_FIS_RECEIVED)
  1019. isci_remote_device_not_ready(ihost, idev,
  1020. idev->not_ready_reason);
  1021. }
  1022. static void sci_smp_remote_device_ready_idle_substate_enter(struct sci_base_state_machine *sm)
  1023. {
  1024. struct isci_remote_device *idev = container_of(sm, typeof(*idev), sm);
  1025. struct isci_host *ihost = idev->owning_port->owning_controller;
  1026. isci_remote_device_ready(ihost, idev);
  1027. }
  1028. static void sci_smp_remote_device_ready_cmd_substate_enter(struct sci_base_state_machine *sm)
  1029. {
  1030. struct isci_remote_device *idev = container_of(sm, typeof(*idev), sm);
  1031. struct isci_host *ihost = idev->owning_port->owning_controller;
  1032. BUG_ON(idev->working_request == NULL);
  1033. isci_remote_device_not_ready(ihost, idev,
  1034. SCIC_REMOTE_DEVICE_NOT_READY_SMP_REQUEST_STARTED);
  1035. }
  1036. static void sci_smp_remote_device_ready_cmd_substate_exit(struct sci_base_state_machine *sm)
  1037. {
  1038. struct isci_remote_device *idev = container_of(sm, typeof(*idev), sm);
  1039. idev->working_request = NULL;
  1040. }
  1041. static const struct sci_base_state sci_remote_device_state_table[] = {
  1042. [SCI_DEV_INITIAL] = {
  1043. .enter_state = sci_remote_device_initial_state_enter,
  1044. },
  1045. [SCI_DEV_STOPPED] = {
  1046. .enter_state = sci_remote_device_stopped_state_enter,
  1047. },
  1048. [SCI_DEV_STARTING] = {
  1049. .enter_state = sci_remote_device_starting_state_enter,
  1050. },
  1051. [SCI_DEV_READY] = {
  1052. .enter_state = sci_remote_device_ready_state_enter,
  1053. .exit_state = sci_remote_device_ready_state_exit
  1054. },
  1055. [SCI_STP_DEV_IDLE] = {
  1056. .enter_state = sci_stp_remote_device_ready_idle_substate_enter,
  1057. },
  1058. [SCI_STP_DEV_CMD] = {
  1059. .enter_state = sci_stp_remote_device_ready_cmd_substate_enter,
  1060. },
  1061. [SCI_STP_DEV_NCQ] = { },
  1062. [SCI_STP_DEV_NCQ_ERROR] = {
  1063. .enter_state = sci_stp_remote_device_ready_ncq_error_substate_enter,
  1064. },
  1065. [SCI_STP_DEV_ATAPI_ERROR] = { },
  1066. [SCI_STP_DEV_AWAIT_RESET] = { },
  1067. [SCI_SMP_DEV_IDLE] = {
  1068. .enter_state = sci_smp_remote_device_ready_idle_substate_enter,
  1069. },
  1070. [SCI_SMP_DEV_CMD] = {
  1071. .enter_state = sci_smp_remote_device_ready_cmd_substate_enter,
  1072. .exit_state = sci_smp_remote_device_ready_cmd_substate_exit,
  1073. },
  1074. [SCI_DEV_STOPPING] = { },
  1075. [SCI_DEV_FAILED] = { },
  1076. [SCI_DEV_RESETTING] = {
  1077. .enter_state = sci_remote_device_resetting_state_enter,
  1078. .exit_state = sci_remote_device_resetting_state_exit
  1079. },
  1080. [SCI_DEV_FINAL] = { },
  1081. };
  1082. /**
  1083. * sci_remote_device_construct() - common construction
  1084. * @sci_port: SAS/SATA port through which this device is accessed.
  1085. * @sci_dev: remote device to construct
  1086. *
  1087. * This routine just performs benign initialization and does not
  1088. * allocate the remote_node_context which is left to
  1089. * sci_remote_device_[de]a_construct(). sci_remote_device_destruct()
  1090. * frees the remote_node_context(s) for the device.
  1091. */
  1092. static void sci_remote_device_construct(struct isci_port *iport,
  1093. struct isci_remote_device *idev)
  1094. {
  1095. idev->owning_port = iport;
  1096. idev->started_request_count = 0;
  1097. sci_init_sm(&idev->sm, sci_remote_device_state_table, SCI_DEV_INITIAL);
  1098. sci_remote_node_context_construct(&idev->rnc,
  1099. SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX);
  1100. }
  1101. /**
  1102. * sci_remote_device_da_construct() - construct direct attached device.
  1103. *
  1104. * The information (e.g. IAF, Signature FIS, etc.) necessary to build
  1105. * the device is known to the SCI Core since it is contained in the
  1106. * sci_phy object. Remote node context(s) is/are a global resource
  1107. * allocated by this routine, freed by sci_remote_device_destruct().
  1108. *
  1109. * Returns:
  1110. * SCI_FAILURE_DEVICE_EXISTS - device has already been constructed.
  1111. * SCI_FAILURE_UNSUPPORTED_PROTOCOL - e.g. sas device attached to
  1112. * sata-only controller instance.
  1113. * SCI_FAILURE_INSUFFICIENT_RESOURCES - remote node contexts exhausted.
  1114. */
  1115. static enum sci_status sci_remote_device_da_construct(struct isci_port *iport,
  1116. struct isci_remote_device *idev)
  1117. {
  1118. enum sci_status status;
  1119. struct sci_port_properties properties;
  1120. sci_remote_device_construct(iport, idev);
  1121. sci_port_get_properties(iport, &properties);
  1122. /* Get accurate port width from port's phy mask for a DA device. */
  1123. idev->device_port_width = hweight32(properties.phy_mask);
  1124. status = sci_controller_allocate_remote_node_context(iport->owning_controller,
  1125. idev,
  1126. &idev->rnc.remote_node_index);
  1127. if (status != SCI_SUCCESS)
  1128. return status;
  1129. idev->connection_rate = sci_port_get_max_allowed_speed(iport);
  1130. return SCI_SUCCESS;
  1131. }
  1132. /**
  1133. * sci_remote_device_ea_construct() - construct expander attached device
  1134. *
  1135. * Remote node context(s) is/are a global resource allocated by this
  1136. * routine, freed by sci_remote_device_destruct().
  1137. *
  1138. * Returns:
  1139. * SCI_FAILURE_DEVICE_EXISTS - device has already been constructed.
  1140. * SCI_FAILURE_UNSUPPORTED_PROTOCOL - e.g. sas device attached to
  1141. * sata-only controller instance.
  1142. * SCI_FAILURE_INSUFFICIENT_RESOURCES - remote node contexts exhausted.
  1143. */
  1144. static enum sci_status sci_remote_device_ea_construct(struct isci_port *iport,
  1145. struct isci_remote_device *idev)
  1146. {
  1147. struct domain_device *dev = idev->domain_dev;
  1148. enum sci_status status;
  1149. sci_remote_device_construct(iport, idev);
  1150. status = sci_controller_allocate_remote_node_context(iport->owning_controller,
  1151. idev,
  1152. &idev->rnc.remote_node_index);
  1153. if (status != SCI_SUCCESS)
  1154. return status;
  1155. /* For SAS-2 the physical link rate is actually a logical link
  1156. * rate that incorporates multiplexing. The SCU doesn't
  1157. * incorporate multiplexing and for the purposes of the
  1158. * connection the logical link rate is that same as the
  1159. * physical. Furthermore, the SAS-2 and SAS-1.1 fields overlay
  1160. * one another, so this code works for both situations.
  1161. */
  1162. idev->connection_rate = min_t(u16, sci_port_get_max_allowed_speed(iport),
  1163. dev->linkrate);
  1164. /* / @todo Should I assign the port width by reading all of the phys on the port? */
  1165. idev->device_port_width = 1;
  1166. return SCI_SUCCESS;
  1167. }
  1168. enum sci_status sci_remote_device_resume(
  1169. struct isci_remote_device *idev,
  1170. scics_sds_remote_node_context_callback cb_fn,
  1171. void *cb_p)
  1172. {
  1173. enum sci_status status;
  1174. status = sci_remote_node_context_resume(&idev->rnc, cb_fn, cb_p);
  1175. if (status != SCI_SUCCESS)
  1176. dev_dbg(scirdev_to_dev(idev), "%s: failed to resume: %d\n",
  1177. __func__, status);
  1178. return status;
  1179. }
  1180. static void isci_remote_device_resume_from_abort_complete(void *cbparam)
  1181. {
  1182. struct isci_remote_device *idev = cbparam;
  1183. struct isci_host *ihost = idev->owning_port->owning_controller;
  1184. scics_sds_remote_node_context_callback abort_resume_cb =
  1185. idev->abort_resume_cb;
  1186. dev_dbg(scirdev_to_dev(idev), "%s: passing-along resume: %p\n",
  1187. __func__, abort_resume_cb);
  1188. if (abort_resume_cb != NULL) {
  1189. idev->abort_resume_cb = NULL;
  1190. abort_resume_cb(idev->abort_resume_cbparam);
  1191. }
  1192. clear_bit(IDEV_ABORT_PATH_RESUME_PENDING, &idev->flags);
  1193. wake_up(&ihost->eventq);
  1194. }
  1195. void isci_remote_device_wait_for_resume_from_abort(
  1196. struct isci_host *ihost,
  1197. struct isci_remote_device *idev)
  1198. {
  1199. dev_dbg(scirdev_to_dev(idev), "%s: starting resume wait: %p\n",
  1200. __func__, idev);
  1201. #define MAX_RESUME_MSECS 10000
  1202. if (!wait_event_timeout(ihost->eventq,
  1203. (!test_bit(IDEV_ABORT_PATH_RESUME_PENDING,
  1204. &idev->flags)
  1205. || test_bit(IDEV_STOP_PENDING, &idev->flags)),
  1206. msecs_to_jiffies(MAX_RESUME_MSECS))) {
  1207. dev_warn(scirdev_to_dev(idev), "%s: #### Timeout waiting for "
  1208. "resume: %p\n", __func__, idev);
  1209. }
  1210. clear_bit(IDEV_ABORT_PATH_RESUME_PENDING, &idev->flags);
  1211. dev_dbg(scirdev_to_dev(idev), "%s: resume wait done: %p\n",
  1212. __func__, idev);
  1213. }
  1214. enum sci_status isci_remote_device_resume_from_abort(
  1215. struct isci_host *ihost,
  1216. struct isci_remote_device *idev)
  1217. {
  1218. unsigned long flags;
  1219. enum sci_status status = SCI_SUCCESS;
  1220. int destroyed;
  1221. spin_lock_irqsave(&ihost->scic_lock, flags);
  1222. /* Preserve any current resume callbacks, for instance from other
  1223. * resumptions.
  1224. */
  1225. idev->abort_resume_cb = idev->rnc.user_callback;
  1226. idev->abort_resume_cbparam = idev->rnc.user_cookie;
  1227. set_bit(IDEV_ABORT_PATH_RESUME_PENDING, &idev->flags);
  1228. clear_bit(IDEV_ABORT_PATH_ACTIVE, &idev->flags);
  1229. destroyed = sci_remote_node_context_is_being_destroyed(&idev->rnc);
  1230. if (!destroyed)
  1231. status = sci_remote_device_resume(
  1232. idev, isci_remote_device_resume_from_abort_complete,
  1233. idev);
  1234. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  1235. if (!destroyed)
  1236. isci_remote_device_wait_for_resume_from_abort(ihost, idev);
  1237. else
  1238. clear_bit(IDEV_ABORT_PATH_RESUME_PENDING, &idev->flags);
  1239. return status;
  1240. }
  1241. /**
  1242. * sci_remote_device_start() - This method will start the supplied remote
  1243. * device. This method enables normal IO requests to flow through to the
  1244. * remote device.
  1245. * @remote_device: This parameter specifies the device to be started.
  1246. * @timeout: This parameter specifies the number of milliseconds in which the
  1247. * start operation should complete.
  1248. *
  1249. * An indication of whether the device was successfully started. SCI_SUCCESS
  1250. * This value is returned if the device was successfully started.
  1251. * SCI_FAILURE_INVALID_PHY This value is returned if the user attempts to start
  1252. * the device when there have been no phys added to it.
  1253. */
  1254. static enum sci_status sci_remote_device_start(struct isci_remote_device *idev,
  1255. u32 timeout)
  1256. {
  1257. struct sci_base_state_machine *sm = &idev->sm;
  1258. enum sci_remote_device_states state = sm->current_state_id;
  1259. enum sci_status status;
  1260. if (state != SCI_DEV_STOPPED) {
  1261. dev_warn(scirdev_to_dev(idev), "%s: in wrong state: %s\n",
  1262. __func__, dev_state_name(state));
  1263. return SCI_FAILURE_INVALID_STATE;
  1264. }
  1265. status = sci_remote_device_resume(idev, remote_device_resume_done,
  1266. idev);
  1267. if (status != SCI_SUCCESS)
  1268. return status;
  1269. sci_change_state(sm, SCI_DEV_STARTING);
  1270. return SCI_SUCCESS;
  1271. }
  1272. static enum sci_status isci_remote_device_construct(struct isci_port *iport,
  1273. struct isci_remote_device *idev)
  1274. {
  1275. struct isci_host *ihost = iport->isci_host;
  1276. struct domain_device *dev = idev->domain_dev;
  1277. enum sci_status status;
  1278. if (dev->parent && dev_is_expander(dev->parent))
  1279. status = sci_remote_device_ea_construct(iport, idev);
  1280. else
  1281. status = sci_remote_device_da_construct(iport, idev);
  1282. if (status != SCI_SUCCESS) {
  1283. dev_dbg(&ihost->pdev->dev, "%s: construct failed: %d\n",
  1284. __func__, status);
  1285. return status;
  1286. }
  1287. /* start the device. */
  1288. status = sci_remote_device_start(idev, ISCI_REMOTE_DEVICE_START_TIMEOUT);
  1289. if (status != SCI_SUCCESS)
  1290. dev_warn(&ihost->pdev->dev, "remote device start failed: %d\n",
  1291. status);
  1292. return status;
  1293. }
  1294. /**
  1295. * This function builds the isci_remote_device when a libsas dev_found message
  1296. * is received.
  1297. * @isci_host: This parameter specifies the isci host object.
  1298. * @port: This parameter specifies the isci_port conected to this device.
  1299. *
  1300. * pointer to new isci_remote_device.
  1301. */
  1302. static struct isci_remote_device *
  1303. isci_remote_device_alloc(struct isci_host *ihost, struct isci_port *iport)
  1304. {
  1305. struct isci_remote_device *idev;
  1306. int i;
  1307. for (i = 0; i < SCI_MAX_REMOTE_DEVICES; i++) {
  1308. idev = &ihost->devices[i];
  1309. if (!test_and_set_bit(IDEV_ALLOCATED, &idev->flags))
  1310. break;
  1311. }
  1312. if (i >= SCI_MAX_REMOTE_DEVICES) {
  1313. dev_warn(&ihost->pdev->dev, "%s: failed\n", __func__);
  1314. return NULL;
  1315. }
  1316. if (WARN_ONCE(!list_empty(&idev->node), "found non-idle remote device\n"))
  1317. return NULL;
  1318. return idev;
  1319. }
  1320. void isci_remote_device_release(struct kref *kref)
  1321. {
  1322. struct isci_remote_device *idev = container_of(kref, typeof(*idev), kref);
  1323. struct isci_host *ihost = idev->isci_port->isci_host;
  1324. idev->domain_dev = NULL;
  1325. idev->isci_port = NULL;
  1326. clear_bit(IDEV_START_PENDING, &idev->flags);
  1327. clear_bit(IDEV_STOP_PENDING, &idev->flags);
  1328. clear_bit(IDEV_IO_READY, &idev->flags);
  1329. clear_bit(IDEV_GONE, &idev->flags);
  1330. smp_mb__before_clear_bit();
  1331. clear_bit(IDEV_ALLOCATED, &idev->flags);
  1332. wake_up(&ihost->eventq);
  1333. }
  1334. /**
  1335. * isci_remote_device_stop() - This function is called internally to stop the
  1336. * remote device.
  1337. * @isci_host: This parameter specifies the isci host object.
  1338. * @isci_device: This parameter specifies the remote device.
  1339. *
  1340. * The status of the ihost request to stop.
  1341. */
  1342. enum sci_status isci_remote_device_stop(struct isci_host *ihost, struct isci_remote_device *idev)
  1343. {
  1344. enum sci_status status;
  1345. unsigned long flags;
  1346. dev_dbg(&ihost->pdev->dev,
  1347. "%s: isci_device = %p\n", __func__, idev);
  1348. spin_lock_irqsave(&ihost->scic_lock, flags);
  1349. idev->domain_dev->lldd_dev = NULL; /* disable new lookups */
  1350. set_bit(IDEV_GONE, &idev->flags);
  1351. set_bit(IDEV_STOP_PENDING, &idev->flags);
  1352. status = sci_remote_device_stop(idev, 50);
  1353. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  1354. /* Wait for the stop complete callback. */
  1355. if (WARN_ONCE(status != SCI_SUCCESS, "failed to stop device\n"))
  1356. /* nothing to wait for */;
  1357. else
  1358. wait_for_device_stop(ihost, idev);
  1359. dev_dbg(&ihost->pdev->dev,
  1360. "%s: isci_device = %p, waiting done.\n", __func__, idev);
  1361. return status;
  1362. }
  1363. /**
  1364. * isci_remote_device_gone() - This function is called by libsas when a domain
  1365. * device is removed.
  1366. * @domain_device: This parameter specifies the libsas domain device.
  1367. *
  1368. */
  1369. void isci_remote_device_gone(struct domain_device *dev)
  1370. {
  1371. struct isci_host *ihost = dev_to_ihost(dev);
  1372. struct isci_remote_device *idev = dev->lldd_dev;
  1373. dev_dbg(&ihost->pdev->dev,
  1374. "%s: domain_device = %p, isci_device = %p, isci_port = %p\n",
  1375. __func__, dev, idev, idev->isci_port);
  1376. isci_remote_device_stop(ihost, idev);
  1377. }
  1378. /**
  1379. * isci_remote_device_found() - This function is called by libsas when a remote
  1380. * device is discovered. A remote device object is created and started. the
  1381. * function then sleeps until the sci core device started message is
  1382. * received.
  1383. * @domain_device: This parameter specifies the libsas domain device.
  1384. *
  1385. * status, zero indicates success.
  1386. */
  1387. int isci_remote_device_found(struct domain_device *dev)
  1388. {
  1389. struct isci_host *isci_host = dev_to_ihost(dev);
  1390. struct isci_port *isci_port = dev->port->lldd_port;
  1391. struct isci_remote_device *isci_device;
  1392. enum sci_status status;
  1393. dev_dbg(&isci_host->pdev->dev,
  1394. "%s: domain_device = %p\n", __func__, dev);
  1395. if (!isci_port)
  1396. return -ENODEV;
  1397. isci_device = isci_remote_device_alloc(isci_host, isci_port);
  1398. if (!isci_device)
  1399. return -ENODEV;
  1400. kref_init(&isci_device->kref);
  1401. INIT_LIST_HEAD(&isci_device->node);
  1402. spin_lock_irq(&isci_host->scic_lock);
  1403. isci_device->domain_dev = dev;
  1404. isci_device->isci_port = isci_port;
  1405. list_add_tail(&isci_device->node, &isci_port->remote_dev_list);
  1406. set_bit(IDEV_START_PENDING, &isci_device->flags);
  1407. status = isci_remote_device_construct(isci_port, isci_device);
  1408. dev_dbg(&isci_host->pdev->dev,
  1409. "%s: isci_device = %p\n",
  1410. __func__, isci_device);
  1411. if (status == SCI_SUCCESS) {
  1412. /* device came up, advertise it to the world */
  1413. dev->lldd_dev = isci_device;
  1414. } else
  1415. isci_put_device(isci_device);
  1416. spin_unlock_irq(&isci_host->scic_lock);
  1417. /* wait for the device ready callback. */
  1418. wait_for_device_start(isci_host, isci_device);
  1419. return status == SCI_SUCCESS ? 0 : -ENODEV;
  1420. }
  1421. enum sci_status isci_remote_device_suspend_terminate(
  1422. struct isci_host *ihost,
  1423. struct isci_remote_device *idev,
  1424. struct isci_request *ireq)
  1425. {
  1426. unsigned long flags;
  1427. enum sci_status status;
  1428. /* Put the device into suspension. */
  1429. spin_lock_irqsave(&ihost->scic_lock, flags);
  1430. set_bit(IDEV_ABORT_PATH_ACTIVE, &idev->flags);
  1431. sci_remote_device_suspend(idev, SCI_SW_SUSPEND_LINKHANG_DETECT);
  1432. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  1433. /* Terminate and wait for the completions. */
  1434. status = isci_remote_device_terminate_requests(ihost, idev, ireq);
  1435. if (status != SCI_SUCCESS)
  1436. dev_dbg(&ihost->pdev->dev,
  1437. "%s: isci_remote_device_terminate_requests(%p) "
  1438. "returned %d!\n",
  1439. __func__, idev, status);
  1440. /* NOTE: RNC resumption is left to the caller! */
  1441. return status;
  1442. }
  1443. int isci_remote_device_is_safe_to_abort(
  1444. struct isci_remote_device *idev)
  1445. {
  1446. return sci_remote_node_context_is_safe_to_abort(&idev->rnc);
  1447. }
  1448. enum sci_status sci_remote_device_abort_requests_pending_abort(
  1449. struct isci_remote_device *idev)
  1450. {
  1451. return sci_remote_device_terminate_reqs_checkabort(idev, 1);
  1452. }
  1453. enum sci_status isci_remote_device_reset_complete(
  1454. struct isci_host *ihost,
  1455. struct isci_remote_device *idev)
  1456. {
  1457. unsigned long flags;
  1458. enum sci_status status;
  1459. spin_lock_irqsave(&ihost->scic_lock, flags);
  1460. status = sci_remote_device_reset_complete(idev);
  1461. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  1462. return status;
  1463. }
  1464. void isci_dev_set_hang_detection_timeout(
  1465. struct isci_remote_device *idev,
  1466. u32 timeout)
  1467. {
  1468. if (dev_is_sata(idev->domain_dev)) {
  1469. if (timeout) {
  1470. if (test_and_set_bit(IDEV_RNC_LLHANG_ENABLED,
  1471. &idev->flags))
  1472. return; /* Already enabled. */
  1473. } else if (!test_and_clear_bit(IDEV_RNC_LLHANG_ENABLED,
  1474. &idev->flags))
  1475. return; /* Not enabled. */
  1476. sci_port_set_hang_detection_timeout(idev->owning_port,
  1477. timeout);
  1478. }
  1479. }