remote_node_context.c 20 KB

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