remote_node_context.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  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 "host.h"
  56. #include "isci.h"
  57. #include "remote_device.h"
  58. #include "remote_node_context.h"
  59. #include "scu_event_codes.h"
  60. #include "scu_task_context.h"
  61. /**
  62. *
  63. * @sci_rnc: The RNC for which the is posted request is being made.
  64. *
  65. * This method will return true if the RNC is not in the initial state. In all
  66. * other states the RNC is considered active and this will return true. The
  67. * destroy request of the state machine drives the RNC back to the initial
  68. * state. If the state machine changes then this routine will also have to be
  69. * changed. bool true if the state machine is not in the initial state false if
  70. * the state machine is in the initial state
  71. */
  72. /**
  73. *
  74. * @sci_rnc: The state of the remote node context object to check.
  75. *
  76. * This method will return true if the remote node context is in a READY state
  77. * otherwise it will return false bool true if the remote node context is in
  78. * the ready state. false if the remote node context is not in the ready state.
  79. */
  80. bool sci_remote_node_context_is_ready(
  81. struct sci_remote_node_context *sci_rnc)
  82. {
  83. u32 current_state = sci_rnc->sm.current_state_id;
  84. if (current_state == SCI_RNC_READY) {
  85. return true;
  86. }
  87. return false;
  88. }
  89. static union scu_remote_node_context *sci_rnc_by_id(struct isci_host *ihost, u16 id)
  90. {
  91. if (id < ihost->remote_node_entries &&
  92. ihost->device_table[id])
  93. return &ihost->remote_node_context_table[id];
  94. return NULL;
  95. }
  96. static void sci_remote_node_context_construct_buffer(struct sci_remote_node_context *sci_rnc)
  97. {
  98. struct isci_remote_device *idev = rnc_to_dev(sci_rnc);
  99. struct domain_device *dev = idev->domain_dev;
  100. int rni = sci_rnc->remote_node_index;
  101. union scu_remote_node_context *rnc;
  102. struct isci_host *ihost;
  103. __le64 sas_addr;
  104. ihost = idev->owning_port->owning_controller;
  105. rnc = sci_rnc_by_id(ihost, rni);
  106. memset(rnc, 0, sizeof(union scu_remote_node_context)
  107. * sci_remote_device_node_count(idev));
  108. rnc->ssp.remote_node_index = rni;
  109. rnc->ssp.remote_node_port_width = idev->device_port_width;
  110. rnc->ssp.logical_port_index = idev->owning_port->physical_port_index;
  111. /* sas address is __be64, context ram format is __le64 */
  112. sas_addr = cpu_to_le64(SAS_ADDR(dev->sas_addr));
  113. rnc->ssp.remote_sas_address_hi = upper_32_bits(sas_addr);
  114. rnc->ssp.remote_sas_address_lo = lower_32_bits(sas_addr);
  115. rnc->ssp.nexus_loss_timer_enable = true;
  116. rnc->ssp.check_bit = false;
  117. rnc->ssp.is_valid = false;
  118. rnc->ssp.is_remote_node_context = true;
  119. rnc->ssp.function_number = 0;
  120. rnc->ssp.arbitration_wait_time = 0;
  121. if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) {
  122. rnc->ssp.connection_occupancy_timeout =
  123. ihost->user_parameters.stp_max_occupancy_timeout;
  124. rnc->ssp.connection_inactivity_timeout =
  125. ihost->user_parameters.stp_inactivity_timeout;
  126. } else {
  127. rnc->ssp.connection_occupancy_timeout =
  128. ihost->user_parameters.ssp_max_occupancy_timeout;
  129. rnc->ssp.connection_inactivity_timeout =
  130. ihost->user_parameters.ssp_inactivity_timeout;
  131. }
  132. rnc->ssp.initial_arbitration_wait_time = 0;
  133. /* Open Address Frame Parameters */
  134. rnc->ssp.oaf_connection_rate = idev->connection_rate;
  135. rnc->ssp.oaf_features = 0;
  136. rnc->ssp.oaf_source_zone_group = 0;
  137. rnc->ssp.oaf_more_compatibility_features = 0;
  138. }
  139. /**
  140. *
  141. * @sci_rnc:
  142. * @callback:
  143. * @callback_parameter:
  144. *
  145. * This method will setup the remote node context object so it will transition
  146. * to its ready state. If the remote node context is already setup to
  147. * transition to its final state then this function does nothing. none
  148. */
  149. static void sci_remote_node_context_setup_to_resume(
  150. struct sci_remote_node_context *sci_rnc,
  151. scics_sds_remote_node_context_callback callback,
  152. void *callback_parameter)
  153. {
  154. if (sci_rnc->destination_state != SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL) {
  155. sci_rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_READY;
  156. sci_rnc->user_callback = callback;
  157. sci_rnc->user_cookie = callback_parameter;
  158. }
  159. }
  160. static void sci_remote_node_context_setup_to_destory(
  161. struct sci_remote_node_context *sci_rnc,
  162. scics_sds_remote_node_context_callback callback,
  163. void *callback_parameter)
  164. {
  165. sci_rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL;
  166. sci_rnc->user_callback = callback;
  167. sci_rnc->user_cookie = callback_parameter;
  168. }
  169. /**
  170. *
  171. *
  172. * This method just calls the user callback function and then resets the
  173. * callback.
  174. */
  175. static void sci_remote_node_context_notify_user(
  176. struct sci_remote_node_context *rnc)
  177. {
  178. if (rnc->user_callback != NULL) {
  179. (*rnc->user_callback)(rnc->user_cookie);
  180. rnc->user_callback = NULL;
  181. rnc->user_cookie = NULL;
  182. }
  183. }
  184. static void sci_remote_node_context_continue_state_transitions(struct sci_remote_node_context *rnc)
  185. {
  186. if (rnc->destination_state == SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_READY)
  187. sci_remote_node_context_resume(rnc, rnc->user_callback,
  188. rnc->user_cookie);
  189. }
  190. static void sci_remote_node_context_validate_context_buffer(struct sci_remote_node_context *sci_rnc)
  191. {
  192. union scu_remote_node_context *rnc_buffer;
  193. struct isci_remote_device *idev = rnc_to_dev(sci_rnc);
  194. struct domain_device *dev = idev->domain_dev;
  195. struct isci_host *ihost = idev->owning_port->owning_controller;
  196. rnc_buffer = sci_rnc_by_id(ihost, sci_rnc->remote_node_index);
  197. rnc_buffer->ssp.is_valid = true;
  198. if (!idev->is_direct_attached &&
  199. (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP))) {
  200. sci_remote_device_post_request(idev, SCU_CONTEXT_COMMAND_POST_RNC_96);
  201. } else {
  202. sci_remote_device_post_request(idev, SCU_CONTEXT_COMMAND_POST_RNC_32);
  203. if (idev->is_direct_attached)
  204. sci_port_setup_transports(idev->owning_port,
  205. sci_rnc->remote_node_index);
  206. }
  207. }
  208. static void sci_remote_node_context_invalidate_context_buffer(struct sci_remote_node_context *sci_rnc)
  209. {
  210. union scu_remote_node_context *rnc_buffer;
  211. struct isci_remote_device *idev = rnc_to_dev(sci_rnc);
  212. struct isci_host *ihost = idev->owning_port->owning_controller;
  213. rnc_buffer = sci_rnc_by_id(ihost, sci_rnc->remote_node_index);
  214. rnc_buffer->ssp.is_valid = false;
  215. sci_remote_device_post_request(rnc_to_dev(sci_rnc),
  216. SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE);
  217. }
  218. static void sci_remote_node_context_initial_state_enter(struct sci_base_state_machine *sm)
  219. {
  220. struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm);
  221. /* Check to see if we have gotten back to the initial state because
  222. * someone requested to destroy the remote node context object.
  223. */
  224. if (sm->previous_state_id == SCI_RNC_INVALIDATING) {
  225. rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED;
  226. sci_remote_node_context_notify_user(rnc);
  227. }
  228. }
  229. static void sci_remote_node_context_posting_state_enter(struct sci_base_state_machine *sm)
  230. {
  231. struct sci_remote_node_context *sci_rnc = container_of(sm, typeof(*sci_rnc), sm);
  232. sci_remote_node_context_validate_context_buffer(sci_rnc);
  233. }
  234. static void sci_remote_node_context_invalidating_state_enter(struct sci_base_state_machine *sm)
  235. {
  236. struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm);
  237. sci_remote_node_context_invalidate_context_buffer(rnc);
  238. }
  239. static void sci_remote_node_context_resuming_state_enter(struct sci_base_state_machine *sm)
  240. {
  241. struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm);
  242. struct isci_remote_device *idev;
  243. struct domain_device *dev;
  244. idev = rnc_to_dev(rnc);
  245. dev = idev->domain_dev;
  246. /*
  247. * For direct attached SATA devices we need to clear the TLCR
  248. * NCQ to TCi tag mapping on the phy and in cases where we
  249. * resume because of a target reset we also need to update
  250. * the STPTLDARNI register with the RNi of the device
  251. */
  252. if ((dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) &&
  253. idev->is_direct_attached)
  254. sci_port_setup_transports(idev->owning_port,
  255. rnc->remote_node_index);
  256. sci_remote_device_post_request(idev, SCU_CONTEXT_COMMAND_POST_RNC_RESUME);
  257. }
  258. static void sci_remote_node_context_ready_state_enter(struct sci_base_state_machine *sm)
  259. {
  260. struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm);
  261. rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED;
  262. if (rnc->user_callback)
  263. sci_remote_node_context_notify_user(rnc);
  264. }
  265. static void sci_remote_node_context_tx_suspended_state_enter(struct sci_base_state_machine *sm)
  266. {
  267. struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm);
  268. sci_remote_node_context_continue_state_transitions(rnc);
  269. }
  270. static void sci_remote_node_context_tx_rx_suspended_state_enter(struct sci_base_state_machine *sm)
  271. {
  272. struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm);
  273. sci_remote_node_context_continue_state_transitions(rnc);
  274. }
  275. static const struct sci_base_state sci_remote_node_context_state_table[] = {
  276. [SCI_RNC_INITIAL] = {
  277. .enter_state = sci_remote_node_context_initial_state_enter,
  278. },
  279. [SCI_RNC_POSTING] = {
  280. .enter_state = sci_remote_node_context_posting_state_enter,
  281. },
  282. [SCI_RNC_INVALIDATING] = {
  283. .enter_state = sci_remote_node_context_invalidating_state_enter,
  284. },
  285. [SCI_RNC_RESUMING] = {
  286. .enter_state = sci_remote_node_context_resuming_state_enter,
  287. },
  288. [SCI_RNC_READY] = {
  289. .enter_state = sci_remote_node_context_ready_state_enter,
  290. },
  291. [SCI_RNC_TX_SUSPENDED] = {
  292. .enter_state = sci_remote_node_context_tx_suspended_state_enter,
  293. },
  294. [SCI_RNC_TX_RX_SUSPENDED] = {
  295. .enter_state = sci_remote_node_context_tx_rx_suspended_state_enter,
  296. },
  297. [SCI_RNC_AWAIT_SUSPENSION] = { },
  298. };
  299. void sci_remote_node_context_construct(struct sci_remote_node_context *rnc,
  300. u16 remote_node_index)
  301. {
  302. memset(rnc, 0, sizeof(struct sci_remote_node_context));
  303. rnc->remote_node_index = remote_node_index;
  304. rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED;
  305. sci_init_sm(&rnc->sm, sci_remote_node_context_state_table, SCI_RNC_INITIAL);
  306. }
  307. enum sci_status sci_remote_node_context_event_handler(struct sci_remote_node_context *sci_rnc,
  308. u32 event_code)
  309. {
  310. enum scis_sds_remote_node_context_states state;
  311. state = sci_rnc->sm.current_state_id;
  312. switch (state) {
  313. case SCI_RNC_POSTING:
  314. switch (scu_get_event_code(event_code)) {
  315. case SCU_EVENT_POST_RNC_COMPLETE:
  316. sci_change_state(&sci_rnc->sm, SCI_RNC_READY);
  317. break;
  318. default:
  319. goto out;
  320. }
  321. break;
  322. case SCI_RNC_INVALIDATING:
  323. if (scu_get_event_code(event_code) == SCU_EVENT_POST_RNC_INVALIDATE_COMPLETE) {
  324. if (sci_rnc->destination_state == SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL)
  325. state = SCI_RNC_INITIAL;
  326. else
  327. state = SCI_RNC_POSTING;
  328. sci_change_state(&sci_rnc->sm, state);
  329. } else {
  330. switch (scu_get_event_type(event_code)) {
  331. case SCU_EVENT_TYPE_RNC_SUSPEND_TX:
  332. case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX:
  333. /* We really dont care if the hardware is going to suspend
  334. * the device since it's being invalidated anyway */
  335. dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  336. "%s: SCIC Remote Node Context 0x%p was "
  337. "suspeneded by hardware while being "
  338. "invalidated.\n", __func__, sci_rnc);
  339. break;
  340. default:
  341. goto out;
  342. }
  343. }
  344. break;
  345. case SCI_RNC_RESUMING:
  346. if (scu_get_event_code(event_code) == SCU_EVENT_POST_RCN_RELEASE) {
  347. sci_change_state(&sci_rnc->sm, SCI_RNC_READY);
  348. } else {
  349. switch (scu_get_event_type(event_code)) {
  350. case SCU_EVENT_TYPE_RNC_SUSPEND_TX:
  351. case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX:
  352. /* We really dont care if the hardware is going to suspend
  353. * the device since it's being resumed anyway */
  354. dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  355. "%s: SCIC Remote Node Context 0x%p was "
  356. "suspeneded by hardware while being resumed.\n",
  357. __func__, sci_rnc);
  358. break;
  359. default:
  360. goto out;
  361. }
  362. }
  363. break;
  364. case SCI_RNC_READY:
  365. switch (scu_get_event_type(event_code)) {
  366. case SCU_EVENT_TL_RNC_SUSPEND_TX:
  367. sci_change_state(&sci_rnc->sm, SCI_RNC_TX_SUSPENDED);
  368. sci_rnc->suspension_code = scu_get_event_specifier(event_code);
  369. break;
  370. case SCU_EVENT_TL_RNC_SUSPEND_TX_RX:
  371. sci_change_state(&sci_rnc->sm, SCI_RNC_TX_RX_SUSPENDED);
  372. sci_rnc->suspension_code = scu_get_event_specifier(event_code);
  373. break;
  374. default:
  375. goto out;
  376. }
  377. break;
  378. case SCI_RNC_AWAIT_SUSPENSION:
  379. switch (scu_get_event_type(event_code)) {
  380. case SCU_EVENT_TL_RNC_SUSPEND_TX:
  381. sci_change_state(&sci_rnc->sm, SCI_RNC_TX_SUSPENDED);
  382. sci_rnc->suspension_code = scu_get_event_specifier(event_code);
  383. break;
  384. case SCU_EVENT_TL_RNC_SUSPEND_TX_RX:
  385. sci_change_state(&sci_rnc->sm, SCI_RNC_TX_RX_SUSPENDED);
  386. sci_rnc->suspension_code = scu_get_event_specifier(event_code);
  387. break;
  388. default:
  389. goto out;
  390. }
  391. break;
  392. default:
  393. dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  394. "%s: invalid state %d\n", __func__, state);
  395. return SCI_FAILURE_INVALID_STATE;
  396. }
  397. return SCI_SUCCESS;
  398. out:
  399. dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  400. "%s: code: %#x state: %d\n", __func__, event_code, state);
  401. return SCI_FAILURE;
  402. }
  403. enum sci_status sci_remote_node_context_destruct(struct sci_remote_node_context *sci_rnc,
  404. scics_sds_remote_node_context_callback cb_fn,
  405. void *cb_p)
  406. {
  407. enum scis_sds_remote_node_context_states state;
  408. state = sci_rnc->sm.current_state_id;
  409. switch (state) {
  410. case SCI_RNC_INVALIDATING:
  411. sci_remote_node_context_setup_to_destory(sci_rnc, cb_fn, cb_p);
  412. return SCI_SUCCESS;
  413. case SCI_RNC_POSTING:
  414. case SCI_RNC_RESUMING:
  415. case SCI_RNC_READY:
  416. case SCI_RNC_TX_SUSPENDED:
  417. case SCI_RNC_TX_RX_SUSPENDED:
  418. case SCI_RNC_AWAIT_SUSPENSION:
  419. sci_remote_node_context_setup_to_destory(sci_rnc, cb_fn, cb_p);
  420. sci_change_state(&sci_rnc->sm, SCI_RNC_INVALIDATING);
  421. return SCI_SUCCESS;
  422. case SCI_RNC_INITIAL:
  423. dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  424. "%s: invalid state %d\n", __func__, state);
  425. /* We have decided that the destruct request on the remote node context
  426. * can not fail since it is either in the initial/destroyed state or is
  427. * can be destroyed.
  428. */
  429. return SCI_SUCCESS;
  430. default:
  431. dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  432. "%s: invalid state %d\n", __func__, state);
  433. return SCI_FAILURE_INVALID_STATE;
  434. }
  435. }
  436. enum sci_status sci_remote_node_context_suspend(struct sci_remote_node_context *sci_rnc,
  437. u32 suspend_type,
  438. scics_sds_remote_node_context_callback cb_fn,
  439. void *cb_p)
  440. {
  441. enum scis_sds_remote_node_context_states state;
  442. state = sci_rnc->sm.current_state_id;
  443. if (state != SCI_RNC_READY) {
  444. dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  445. "%s: invalid state %d\n", __func__, state);
  446. return SCI_FAILURE_INVALID_STATE;
  447. }
  448. sci_rnc->user_callback = cb_fn;
  449. sci_rnc->user_cookie = cb_p;
  450. sci_rnc->suspension_code = suspend_type;
  451. if (suspend_type == SCI_SOFTWARE_SUSPENSION) {
  452. sci_remote_device_post_request(rnc_to_dev(sci_rnc),
  453. SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX);
  454. }
  455. sci_change_state(&sci_rnc->sm, SCI_RNC_AWAIT_SUSPENSION);
  456. return SCI_SUCCESS;
  457. }
  458. enum sci_status sci_remote_node_context_resume(struct sci_remote_node_context *sci_rnc,
  459. scics_sds_remote_node_context_callback cb_fn,
  460. void *cb_p)
  461. {
  462. enum scis_sds_remote_node_context_states state;
  463. state = sci_rnc->sm.current_state_id;
  464. switch (state) {
  465. case SCI_RNC_INITIAL:
  466. if (sci_rnc->remote_node_index == SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX)
  467. return SCI_FAILURE_INVALID_STATE;
  468. sci_remote_node_context_setup_to_resume(sci_rnc, cb_fn, cb_p);
  469. sci_remote_node_context_construct_buffer(sci_rnc);
  470. sci_change_state(&sci_rnc->sm, SCI_RNC_POSTING);
  471. return SCI_SUCCESS;
  472. case SCI_RNC_POSTING:
  473. case SCI_RNC_INVALIDATING:
  474. case SCI_RNC_RESUMING:
  475. if (sci_rnc->destination_state != SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_READY)
  476. return SCI_FAILURE_INVALID_STATE;
  477. sci_rnc->user_callback = cb_fn;
  478. sci_rnc->user_cookie = cb_p;
  479. return SCI_SUCCESS;
  480. case SCI_RNC_TX_SUSPENDED: {
  481. struct isci_remote_device *idev = rnc_to_dev(sci_rnc);
  482. struct domain_device *dev = idev->domain_dev;
  483. sci_remote_node_context_setup_to_resume(sci_rnc, cb_fn, cb_p);
  484. /* TODO: consider adding a resume action of NONE, INVALIDATE, WRITE_TLCR */
  485. if (dev->dev_type == SAS_END_DEV || dev_is_expander(dev))
  486. sci_change_state(&sci_rnc->sm, SCI_RNC_RESUMING);
  487. else if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) {
  488. if (idev->is_direct_attached) {
  489. /* @todo Fix this since I am being silly in writing to the STPTLDARNI register. */
  490. sci_change_state(&sci_rnc->sm, SCI_RNC_RESUMING);
  491. } else {
  492. sci_change_state(&sci_rnc->sm, SCI_RNC_INVALIDATING);
  493. }
  494. } else
  495. return SCI_FAILURE;
  496. return SCI_SUCCESS;
  497. }
  498. case SCI_RNC_TX_RX_SUSPENDED:
  499. sci_remote_node_context_setup_to_resume(sci_rnc, cb_fn, cb_p);
  500. sci_change_state(&sci_rnc->sm, SCI_RNC_RESUMING);
  501. return SCI_FAILURE_INVALID_STATE;
  502. case SCI_RNC_AWAIT_SUSPENSION:
  503. sci_remote_node_context_setup_to_resume(sci_rnc, cb_fn, cb_p);
  504. return SCI_SUCCESS;
  505. default:
  506. dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  507. "%s: invalid state %d\n", __func__, state);
  508. return SCI_FAILURE_INVALID_STATE;
  509. }
  510. }
  511. enum sci_status sci_remote_node_context_start_io(struct sci_remote_node_context *sci_rnc,
  512. struct isci_request *ireq)
  513. {
  514. enum scis_sds_remote_node_context_states state;
  515. state = sci_rnc->sm.current_state_id;
  516. switch (state) {
  517. case SCI_RNC_READY:
  518. return SCI_SUCCESS;
  519. case SCI_RNC_TX_SUSPENDED:
  520. case SCI_RNC_TX_RX_SUSPENDED:
  521. case SCI_RNC_AWAIT_SUSPENSION:
  522. dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  523. "%s: invalid state %d\n", __func__, state);
  524. return SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED;
  525. default:
  526. break;
  527. }
  528. dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  529. "%s: requested to start IO while still resuming, %d\n",
  530. __func__, state);
  531. return SCI_FAILURE_INVALID_STATE;
  532. }
  533. enum sci_status sci_remote_node_context_start_task(struct sci_remote_node_context *sci_rnc,
  534. struct isci_request *ireq)
  535. {
  536. enum scis_sds_remote_node_context_states state;
  537. state = sci_rnc->sm.current_state_id;
  538. switch (state) {
  539. case SCI_RNC_RESUMING:
  540. case SCI_RNC_READY:
  541. case SCI_RNC_AWAIT_SUSPENSION:
  542. return SCI_SUCCESS;
  543. case SCI_RNC_TX_SUSPENDED:
  544. case SCI_RNC_TX_RX_SUSPENDED:
  545. sci_remote_node_context_resume(sci_rnc, NULL, NULL);
  546. return SCI_SUCCESS;
  547. default:
  548. dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  549. "%s: invalid state %d\n", __func__, state);
  550. return SCI_FAILURE_INVALID_STATE;
  551. }
  552. }