remote_device.c 53 KB

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