remote_device.c 53 KB

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