remote_node_context.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  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 void sci_remote_node_context_await_suspend_state_exit(
  270. struct sci_base_state_machine *sm)
  271. {
  272. struct sci_remote_node_context *rnc
  273. = container_of(sm, typeof(*rnc), sm);
  274. isci_dev_set_hang_detection_timeout(rnc_to_dev(rnc), 0);
  275. }
  276. static const struct sci_base_state sci_remote_node_context_state_table[] = {
  277. [SCI_RNC_INITIAL] = {
  278. .enter_state = sci_remote_node_context_initial_state_enter,
  279. },
  280. [SCI_RNC_POSTING] = {
  281. .enter_state = sci_remote_node_context_posting_state_enter,
  282. },
  283. [SCI_RNC_INVALIDATING] = {
  284. .enter_state = sci_remote_node_context_invalidating_state_enter,
  285. },
  286. [SCI_RNC_RESUMING] = {
  287. .enter_state = sci_remote_node_context_resuming_state_enter,
  288. },
  289. [SCI_RNC_READY] = {
  290. .enter_state = sci_remote_node_context_ready_state_enter,
  291. },
  292. [SCI_RNC_TX_SUSPENDED] = {
  293. .enter_state = sci_remote_node_context_tx_suspended_state_enter,
  294. },
  295. [SCI_RNC_TX_RX_SUSPENDED] = {
  296. .enter_state = sci_remote_node_context_tx_rx_suspended_state_enter,
  297. },
  298. [SCI_RNC_AWAIT_SUSPENSION] = {
  299. .exit_state = sci_remote_node_context_await_suspend_state_exit,
  300. },
  301. };
  302. void sci_remote_node_context_construct(struct sci_remote_node_context *rnc,
  303. u16 remote_node_index)
  304. {
  305. memset(rnc, 0, sizeof(struct sci_remote_node_context));
  306. rnc->remote_node_index = remote_node_index;
  307. rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED;
  308. sci_init_sm(&rnc->sm, sci_remote_node_context_state_table, SCI_RNC_INITIAL);
  309. }
  310. enum sci_status sci_remote_node_context_event_handler(struct sci_remote_node_context *sci_rnc,
  311. u32 event_code)
  312. {
  313. enum scis_sds_remote_node_context_states state;
  314. state = sci_rnc->sm.current_state_id;
  315. switch (state) {
  316. case SCI_RNC_POSTING:
  317. switch (scu_get_event_code(event_code)) {
  318. case SCU_EVENT_POST_RNC_COMPLETE:
  319. sci_change_state(&sci_rnc->sm, SCI_RNC_READY);
  320. break;
  321. default:
  322. goto out;
  323. }
  324. break;
  325. case SCI_RNC_INVALIDATING:
  326. if (scu_get_event_code(event_code) == SCU_EVENT_POST_RNC_INVALIDATE_COMPLETE) {
  327. if (sci_rnc->destination_state == SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL)
  328. state = SCI_RNC_INITIAL;
  329. else
  330. state = SCI_RNC_POSTING;
  331. sci_change_state(&sci_rnc->sm, state);
  332. } else {
  333. switch (scu_get_event_type(event_code)) {
  334. case SCU_EVENT_TYPE_RNC_SUSPEND_TX:
  335. case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX:
  336. /* We really dont care if the hardware is going to suspend
  337. * the device since it's being invalidated anyway */
  338. dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  339. "%s: SCIC Remote Node Context 0x%p was "
  340. "suspeneded by hardware while being "
  341. "invalidated.\n", __func__, sci_rnc);
  342. break;
  343. default:
  344. goto out;
  345. }
  346. }
  347. break;
  348. case SCI_RNC_RESUMING:
  349. if (scu_get_event_code(event_code) == SCU_EVENT_POST_RCN_RELEASE) {
  350. sci_change_state(&sci_rnc->sm, SCI_RNC_READY);
  351. } else {
  352. switch (scu_get_event_type(event_code)) {
  353. case SCU_EVENT_TYPE_RNC_SUSPEND_TX:
  354. case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX:
  355. /* We really dont care if the hardware is going to suspend
  356. * the device since it's being resumed anyway */
  357. dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  358. "%s: SCIC Remote Node Context 0x%p was "
  359. "suspeneded by hardware while being resumed.\n",
  360. __func__, sci_rnc);
  361. break;
  362. default:
  363. goto out;
  364. }
  365. }
  366. break;
  367. case SCI_RNC_READY:
  368. switch (scu_get_event_type(event_code)) {
  369. case SCU_EVENT_TL_RNC_SUSPEND_TX:
  370. sci_change_state(&sci_rnc->sm, SCI_RNC_TX_SUSPENDED);
  371. sci_rnc->suspension_code = scu_get_event_specifier(event_code);
  372. break;
  373. case SCU_EVENT_TL_RNC_SUSPEND_TX_RX:
  374. sci_change_state(&sci_rnc->sm, SCI_RNC_TX_RX_SUSPENDED);
  375. sci_rnc->suspension_code = scu_get_event_specifier(event_code);
  376. break;
  377. default:
  378. goto out;
  379. }
  380. break;
  381. case SCI_RNC_AWAIT_SUSPENSION:
  382. switch (scu_get_event_type(event_code)) {
  383. case SCU_EVENT_TL_RNC_SUSPEND_TX:
  384. sci_change_state(&sci_rnc->sm, SCI_RNC_TX_SUSPENDED);
  385. sci_rnc->suspension_code = scu_get_event_specifier(event_code);
  386. break;
  387. case SCU_EVENT_TL_RNC_SUSPEND_TX_RX:
  388. sci_change_state(&sci_rnc->sm, SCI_RNC_TX_RX_SUSPENDED);
  389. sci_rnc->suspension_code = scu_get_event_specifier(event_code);
  390. break;
  391. default:
  392. goto out;
  393. }
  394. break;
  395. default:
  396. dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  397. "%s: invalid state: %s\n", __func__,
  398. rnc_state_name(state));
  399. return SCI_FAILURE_INVALID_STATE;
  400. }
  401. return SCI_SUCCESS;
  402. out:
  403. dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  404. "%s: code: %#x state: %s\n", __func__, event_code,
  405. rnc_state_name(state));
  406. return SCI_FAILURE;
  407. }
  408. enum sci_status sci_remote_node_context_destruct(struct sci_remote_node_context *sci_rnc,
  409. scics_sds_remote_node_context_callback cb_fn,
  410. void *cb_p)
  411. {
  412. enum scis_sds_remote_node_context_states state;
  413. state = sci_rnc->sm.current_state_id;
  414. switch (state) {
  415. case SCI_RNC_INVALIDATING:
  416. sci_remote_node_context_setup_to_destory(sci_rnc, cb_fn, cb_p);
  417. return SCI_SUCCESS;
  418. case SCI_RNC_POSTING:
  419. case SCI_RNC_RESUMING:
  420. case SCI_RNC_READY:
  421. case SCI_RNC_TX_SUSPENDED:
  422. case SCI_RNC_TX_RX_SUSPENDED:
  423. case SCI_RNC_AWAIT_SUSPENSION:
  424. sci_remote_node_context_setup_to_destory(sci_rnc, cb_fn, cb_p);
  425. sci_change_state(&sci_rnc->sm, SCI_RNC_INVALIDATING);
  426. return SCI_SUCCESS;
  427. case SCI_RNC_INITIAL:
  428. dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  429. "%s: invalid state: %s\n", __func__,
  430. rnc_state_name(state));
  431. /* We have decided that the destruct request on the remote node context
  432. * can not fail since it is either in the initial/destroyed state or is
  433. * can be destroyed.
  434. */
  435. return SCI_SUCCESS;
  436. default:
  437. dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  438. "%s: invalid state %s\n", __func__,
  439. rnc_state_name(state));
  440. return SCI_FAILURE_INVALID_STATE;
  441. }
  442. }
  443. enum sci_status sci_remote_node_context_suspend(struct sci_remote_node_context *sci_rnc,
  444. u32 suspend_type,
  445. scics_sds_remote_node_context_callback cb_fn,
  446. void *cb_p)
  447. {
  448. enum scis_sds_remote_node_context_states state;
  449. state = sci_rnc->sm.current_state_id;
  450. if (state != SCI_RNC_READY) {
  451. dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  452. "%s: invalid state %s\n", __func__,
  453. rnc_state_name(state));
  454. return SCI_FAILURE_INVALID_STATE;
  455. }
  456. sci_rnc->user_callback = cb_fn;
  457. sci_rnc->user_cookie = cb_p;
  458. sci_rnc->suspension_code = suspend_type;
  459. if (suspend_type == SCI_SOFTWARE_SUSPENSION) {
  460. sci_remote_device_post_request(rnc_to_dev(sci_rnc),
  461. SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX);
  462. isci_dev_set_hang_detection_timeout(rnc_to_dev(sci_rnc),
  463. 0x00000001);
  464. }
  465. sci_change_state(&sci_rnc->sm, SCI_RNC_AWAIT_SUSPENSION);
  466. return SCI_SUCCESS;
  467. }
  468. enum sci_status sci_remote_node_context_resume(struct sci_remote_node_context *sci_rnc,
  469. scics_sds_remote_node_context_callback cb_fn,
  470. void *cb_p)
  471. {
  472. enum scis_sds_remote_node_context_states state;
  473. state = sci_rnc->sm.current_state_id;
  474. switch (state) {
  475. case SCI_RNC_INITIAL:
  476. if (sci_rnc->remote_node_index == SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX)
  477. return SCI_FAILURE_INVALID_STATE;
  478. sci_remote_node_context_setup_to_resume(sci_rnc, cb_fn, cb_p);
  479. sci_remote_node_context_construct_buffer(sci_rnc);
  480. sci_change_state(&sci_rnc->sm, SCI_RNC_POSTING);
  481. return SCI_SUCCESS;
  482. case SCI_RNC_POSTING:
  483. case SCI_RNC_INVALIDATING:
  484. case SCI_RNC_RESUMING:
  485. if (sci_rnc->destination_state != SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_READY)
  486. return SCI_FAILURE_INVALID_STATE;
  487. sci_rnc->user_callback = cb_fn;
  488. sci_rnc->user_cookie = cb_p;
  489. return SCI_SUCCESS;
  490. case SCI_RNC_TX_SUSPENDED:
  491. case SCI_RNC_TX_RX_SUSPENDED: {
  492. struct isci_remote_device *idev = rnc_to_dev(sci_rnc);
  493. struct domain_device *dev = idev->domain_dev;
  494. /* If this is an expander attached SATA device we must
  495. * invalidate and repost the RNC since this is the only way
  496. * to clear the TCi to NCQ tag mapping table for the RNi.
  497. * All other device types we can just resume.
  498. */
  499. sci_remote_node_context_setup_to_resume(sci_rnc, cb_fn, cb_p);
  500. if (dev_is_sata(dev) && dev->parent)
  501. sci_change_state(&sci_rnc->sm, SCI_RNC_INVALIDATING);
  502. else
  503. sci_change_state(&sci_rnc->sm, SCI_RNC_RESUMING);
  504. return SCI_SUCCESS;
  505. }
  506. case SCI_RNC_AWAIT_SUSPENSION:
  507. sci_remote_node_context_setup_to_resume(sci_rnc, cb_fn, cb_p);
  508. return SCI_SUCCESS;
  509. default:
  510. dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  511. "%s: invalid state %s\n", __func__,
  512. rnc_state_name(state));
  513. return SCI_FAILURE_INVALID_STATE;
  514. }
  515. }
  516. enum sci_status sci_remote_node_context_start_io(struct sci_remote_node_context *sci_rnc,
  517. struct isci_request *ireq)
  518. {
  519. enum scis_sds_remote_node_context_states state;
  520. state = sci_rnc->sm.current_state_id;
  521. switch (state) {
  522. case SCI_RNC_READY:
  523. return SCI_SUCCESS;
  524. case SCI_RNC_TX_SUSPENDED:
  525. case SCI_RNC_TX_RX_SUSPENDED:
  526. case SCI_RNC_AWAIT_SUSPENSION:
  527. dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  528. "%s: invalid state %s\n", __func__,
  529. rnc_state_name(state));
  530. return SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED;
  531. default:
  532. dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  533. "%s: invalid state %s\n", __func__,
  534. rnc_state_name(state));
  535. return SCI_FAILURE_INVALID_STATE;
  536. }
  537. }
  538. enum sci_status sci_remote_node_context_start_task(struct sci_remote_node_context *sci_rnc,
  539. struct isci_request *ireq)
  540. {
  541. enum scis_sds_remote_node_context_states state;
  542. state = sci_rnc->sm.current_state_id;
  543. switch (state) {
  544. case SCI_RNC_RESUMING:
  545. case SCI_RNC_READY:
  546. case SCI_RNC_AWAIT_SUSPENSION:
  547. return SCI_SUCCESS;
  548. case SCI_RNC_TX_SUSPENDED:
  549. case SCI_RNC_TX_RX_SUSPENDED:
  550. sci_remote_node_context_resume(sci_rnc, NULL, NULL);
  551. return SCI_SUCCESS;
  552. default:
  553. dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  554. "%s: invalid state %s\n", __func__,
  555. rnc_state_name(state));
  556. return SCI_FAILURE_INVALID_STATE;
  557. }
  558. }