remote_device.c 52 KB

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