remote_node_context.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  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->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) {
  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 (!idev->is_direct_attached &&
  196. (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP))) {
  197. sci_remote_device_post_request(idev, SCU_CONTEXT_COMMAND_POST_RNC_96);
  198. } else {
  199. sci_remote_device_post_request(idev, SCU_CONTEXT_COMMAND_POST_RNC_32);
  200. if (idev->is_direct_attached)
  201. sci_port_setup_transports(idev->owning_port,
  202. sci_rnc->remote_node_index);
  203. }
  204. }
  205. static void sci_remote_node_context_invalidate_context_buffer(struct sci_remote_node_context *sci_rnc)
  206. {
  207. union scu_remote_node_context *rnc_buffer;
  208. struct isci_remote_device *idev = rnc_to_dev(sci_rnc);
  209. struct isci_host *ihost = idev->owning_port->owning_controller;
  210. rnc_buffer = sci_rnc_by_id(ihost, sci_rnc->remote_node_index);
  211. rnc_buffer->ssp.is_valid = false;
  212. sci_remote_device_post_request(rnc_to_dev(sci_rnc),
  213. SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE);
  214. }
  215. static void sci_remote_node_context_initial_state_enter(struct sci_base_state_machine *sm)
  216. {
  217. struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm);
  218. /* Check to see if we have gotten back to the initial state because
  219. * someone requested to destroy the remote node context object.
  220. */
  221. if (sm->previous_state_id == SCI_RNC_INVALIDATING) {
  222. rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED;
  223. sci_remote_node_context_notify_user(rnc);
  224. }
  225. }
  226. static void sci_remote_node_context_posting_state_enter(struct sci_base_state_machine *sm)
  227. {
  228. struct sci_remote_node_context *sci_rnc = container_of(sm, typeof(*sci_rnc), sm);
  229. sci_remote_node_context_validate_context_buffer(sci_rnc);
  230. }
  231. static void sci_remote_node_context_invalidating_state_enter(struct sci_base_state_machine *sm)
  232. {
  233. struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm);
  234. sci_remote_node_context_invalidate_context_buffer(rnc);
  235. }
  236. static void sci_remote_node_context_resuming_state_enter(struct sci_base_state_machine *sm)
  237. {
  238. struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm);
  239. struct isci_remote_device *idev;
  240. struct domain_device *dev;
  241. idev = rnc_to_dev(rnc);
  242. dev = idev->domain_dev;
  243. /*
  244. * For direct attached SATA devices we need to clear the TLCR
  245. * NCQ to TCi tag mapping on the phy and in cases where we
  246. * resume because of a target reset we also need to update
  247. * the STPTLDARNI register with the RNi of the device
  248. */
  249. if ((dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) &&
  250. idev->is_direct_attached)
  251. sci_port_setup_transports(idev->owning_port,
  252. rnc->remote_node_index);
  253. sci_remote_device_post_request(idev, SCU_CONTEXT_COMMAND_POST_RNC_RESUME);
  254. }
  255. static void sci_remote_node_context_ready_state_enter(struct sci_base_state_machine *sm)
  256. {
  257. struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm);
  258. rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED;
  259. if (rnc->user_callback)
  260. sci_remote_node_context_notify_user(rnc);
  261. }
  262. static void sci_remote_node_context_tx_suspended_state_enter(struct sci_base_state_machine *sm)
  263. {
  264. struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm);
  265. sci_remote_node_context_continue_state_transitions(rnc);
  266. }
  267. static void sci_remote_node_context_tx_rx_suspended_state_enter(struct sci_base_state_machine *sm)
  268. {
  269. struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm);
  270. sci_remote_node_context_continue_state_transitions(rnc);
  271. }
  272. static const struct sci_base_state sci_remote_node_context_state_table[] = {
  273. [SCI_RNC_INITIAL] = {
  274. .enter_state = sci_remote_node_context_initial_state_enter,
  275. },
  276. [SCI_RNC_POSTING] = {
  277. .enter_state = sci_remote_node_context_posting_state_enter,
  278. },
  279. [SCI_RNC_INVALIDATING] = {
  280. .enter_state = sci_remote_node_context_invalidating_state_enter,
  281. },
  282. [SCI_RNC_RESUMING] = {
  283. .enter_state = sci_remote_node_context_resuming_state_enter,
  284. },
  285. [SCI_RNC_READY] = {
  286. .enter_state = sci_remote_node_context_ready_state_enter,
  287. },
  288. [SCI_RNC_TX_SUSPENDED] = {
  289. .enter_state = sci_remote_node_context_tx_suspended_state_enter,
  290. },
  291. [SCI_RNC_TX_RX_SUSPENDED] = {
  292. .enter_state = sci_remote_node_context_tx_rx_suspended_state_enter,
  293. },
  294. [SCI_RNC_AWAIT_SUSPENSION] = { },
  295. };
  296. void sci_remote_node_context_construct(struct sci_remote_node_context *rnc,
  297. u16 remote_node_index)
  298. {
  299. memset(rnc, 0, sizeof(struct sci_remote_node_context));
  300. rnc->remote_node_index = remote_node_index;
  301. rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED;
  302. sci_init_sm(&rnc->sm, sci_remote_node_context_state_table, SCI_RNC_INITIAL);
  303. }
  304. enum sci_status sci_remote_node_context_event_handler(struct sci_remote_node_context *sci_rnc,
  305. u32 event_code)
  306. {
  307. enum scis_sds_remote_node_context_states state;
  308. state = sci_rnc->sm.current_state_id;
  309. switch (state) {
  310. case SCI_RNC_POSTING:
  311. switch (scu_get_event_code(event_code)) {
  312. case SCU_EVENT_POST_RNC_COMPLETE:
  313. sci_change_state(&sci_rnc->sm, SCI_RNC_READY);
  314. break;
  315. default:
  316. goto out;
  317. }
  318. break;
  319. case SCI_RNC_INVALIDATING:
  320. if (scu_get_event_code(event_code) == SCU_EVENT_POST_RNC_INVALIDATE_COMPLETE) {
  321. if (sci_rnc->destination_state == SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL)
  322. state = SCI_RNC_INITIAL;
  323. else
  324. state = SCI_RNC_POSTING;
  325. sci_change_state(&sci_rnc->sm, state);
  326. } else {
  327. switch (scu_get_event_type(event_code)) {
  328. case SCU_EVENT_TYPE_RNC_SUSPEND_TX:
  329. case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX:
  330. /* We really dont care if the hardware is going to suspend
  331. * the device since it's being invalidated anyway */
  332. dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  333. "%s: SCIC Remote Node Context 0x%p was "
  334. "suspeneded by hardware while being "
  335. "invalidated.\n", __func__, sci_rnc);
  336. break;
  337. default:
  338. goto out;
  339. }
  340. }
  341. break;
  342. case SCI_RNC_RESUMING:
  343. if (scu_get_event_code(event_code) == SCU_EVENT_POST_RCN_RELEASE) {
  344. sci_change_state(&sci_rnc->sm, SCI_RNC_READY);
  345. } else {
  346. switch (scu_get_event_type(event_code)) {
  347. case SCU_EVENT_TYPE_RNC_SUSPEND_TX:
  348. case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX:
  349. /* We really dont care if the hardware is going to suspend
  350. * the device since it's being resumed anyway */
  351. dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  352. "%s: SCIC Remote Node Context 0x%p was "
  353. "suspeneded by hardware while being resumed.\n",
  354. __func__, sci_rnc);
  355. break;
  356. default:
  357. goto out;
  358. }
  359. }
  360. break;
  361. case SCI_RNC_READY:
  362. switch (scu_get_event_type(event_code)) {
  363. case SCU_EVENT_TL_RNC_SUSPEND_TX:
  364. sci_change_state(&sci_rnc->sm, SCI_RNC_TX_SUSPENDED);
  365. sci_rnc->suspension_code = scu_get_event_specifier(event_code);
  366. break;
  367. case SCU_EVENT_TL_RNC_SUSPEND_TX_RX:
  368. sci_change_state(&sci_rnc->sm, SCI_RNC_TX_RX_SUSPENDED);
  369. sci_rnc->suspension_code = scu_get_event_specifier(event_code);
  370. break;
  371. default:
  372. goto out;
  373. }
  374. break;
  375. case SCI_RNC_AWAIT_SUSPENSION:
  376. switch (scu_get_event_type(event_code)) {
  377. case SCU_EVENT_TL_RNC_SUSPEND_TX:
  378. sci_change_state(&sci_rnc->sm, SCI_RNC_TX_SUSPENDED);
  379. sci_rnc->suspension_code = scu_get_event_specifier(event_code);
  380. break;
  381. case SCU_EVENT_TL_RNC_SUSPEND_TX_RX:
  382. sci_change_state(&sci_rnc->sm, SCI_RNC_TX_RX_SUSPENDED);
  383. sci_rnc->suspension_code = scu_get_event_specifier(event_code);
  384. break;
  385. default:
  386. goto out;
  387. }
  388. break;
  389. default:
  390. dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  391. "%s: invalid state %d\n", __func__, state);
  392. return SCI_FAILURE_INVALID_STATE;
  393. }
  394. return SCI_SUCCESS;
  395. out:
  396. dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  397. "%s: code: %#x state: %d\n", __func__, event_code, state);
  398. return SCI_FAILURE;
  399. }
  400. enum sci_status sci_remote_node_context_destruct(struct sci_remote_node_context *sci_rnc,
  401. scics_sds_remote_node_context_callback cb_fn,
  402. void *cb_p)
  403. {
  404. enum scis_sds_remote_node_context_states state;
  405. state = sci_rnc->sm.current_state_id;
  406. switch (state) {
  407. case SCI_RNC_INVALIDATING:
  408. sci_remote_node_context_setup_to_destory(sci_rnc, cb_fn, cb_p);
  409. return SCI_SUCCESS;
  410. case SCI_RNC_POSTING:
  411. case SCI_RNC_RESUMING:
  412. case SCI_RNC_READY:
  413. case SCI_RNC_TX_SUSPENDED:
  414. case SCI_RNC_TX_RX_SUSPENDED:
  415. case SCI_RNC_AWAIT_SUSPENSION:
  416. sci_remote_node_context_setup_to_destory(sci_rnc, cb_fn, cb_p);
  417. sci_change_state(&sci_rnc->sm, SCI_RNC_INVALIDATING);
  418. return SCI_SUCCESS;
  419. case SCI_RNC_INITIAL:
  420. dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  421. "%s: invalid state %d\n", __func__, 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 %d\n", __func__, state);
  430. return SCI_FAILURE_INVALID_STATE;
  431. }
  432. }
  433. enum sci_status sci_remote_node_context_suspend(struct sci_remote_node_context *sci_rnc,
  434. u32 suspend_type,
  435. scics_sds_remote_node_context_callback cb_fn,
  436. void *cb_p)
  437. {
  438. enum scis_sds_remote_node_context_states state;
  439. state = sci_rnc->sm.current_state_id;
  440. if (state != SCI_RNC_READY) {
  441. dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  442. "%s: invalid state %d\n", __func__, state);
  443. return SCI_FAILURE_INVALID_STATE;
  444. }
  445. sci_rnc->user_callback = cb_fn;
  446. sci_rnc->user_cookie = cb_p;
  447. sci_rnc->suspension_code = suspend_type;
  448. if (suspend_type == SCI_SOFTWARE_SUSPENSION) {
  449. sci_remote_device_post_request(rnc_to_dev(sci_rnc),
  450. SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX);
  451. }
  452. sci_change_state(&sci_rnc->sm, SCI_RNC_AWAIT_SUSPENSION);
  453. return SCI_SUCCESS;
  454. }
  455. enum sci_status sci_remote_node_context_resume(struct sci_remote_node_context *sci_rnc,
  456. scics_sds_remote_node_context_callback cb_fn,
  457. void *cb_p)
  458. {
  459. enum scis_sds_remote_node_context_states state;
  460. state = sci_rnc->sm.current_state_id;
  461. switch (state) {
  462. case SCI_RNC_INITIAL:
  463. if (sci_rnc->remote_node_index == SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX)
  464. return SCI_FAILURE_INVALID_STATE;
  465. sci_remote_node_context_setup_to_resume(sci_rnc, cb_fn, cb_p);
  466. sci_remote_node_context_construct_buffer(sci_rnc);
  467. sci_change_state(&sci_rnc->sm, SCI_RNC_POSTING);
  468. return SCI_SUCCESS;
  469. case SCI_RNC_POSTING:
  470. case SCI_RNC_INVALIDATING:
  471. case SCI_RNC_RESUMING:
  472. if (sci_rnc->destination_state != SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_READY)
  473. return SCI_FAILURE_INVALID_STATE;
  474. sci_rnc->user_callback = cb_fn;
  475. sci_rnc->user_cookie = cb_p;
  476. return SCI_SUCCESS;
  477. case SCI_RNC_TX_SUSPENDED: {
  478. struct isci_remote_device *idev = rnc_to_dev(sci_rnc);
  479. struct domain_device *dev = idev->domain_dev;
  480. sci_remote_node_context_setup_to_resume(sci_rnc, cb_fn, cb_p);
  481. /* TODO: consider adding a resume action of NONE, INVALIDATE, WRITE_TLCR */
  482. if (dev->dev_type == SAS_END_DEV || dev_is_expander(dev))
  483. sci_change_state(&sci_rnc->sm, SCI_RNC_RESUMING);
  484. else if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) {
  485. if (idev->is_direct_attached) {
  486. /* @todo Fix this since I am being silly in writing to the STPTLDARNI register. */
  487. sci_change_state(&sci_rnc->sm, SCI_RNC_RESUMING);
  488. } else {
  489. sci_change_state(&sci_rnc->sm, SCI_RNC_INVALIDATING);
  490. }
  491. } else
  492. return SCI_FAILURE;
  493. return SCI_SUCCESS;
  494. }
  495. case SCI_RNC_TX_RX_SUSPENDED:
  496. sci_remote_node_context_setup_to_resume(sci_rnc, cb_fn, cb_p);
  497. sci_change_state(&sci_rnc->sm, SCI_RNC_RESUMING);
  498. return SCI_FAILURE_INVALID_STATE;
  499. case SCI_RNC_AWAIT_SUSPENSION:
  500. sci_remote_node_context_setup_to_resume(sci_rnc, cb_fn, cb_p);
  501. return SCI_SUCCESS;
  502. default:
  503. dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  504. "%s: invalid state %d\n", __func__, state);
  505. return SCI_FAILURE_INVALID_STATE;
  506. }
  507. }
  508. enum sci_status sci_remote_node_context_start_io(struct sci_remote_node_context *sci_rnc,
  509. struct isci_request *ireq)
  510. {
  511. enum scis_sds_remote_node_context_states state;
  512. state = sci_rnc->sm.current_state_id;
  513. switch (state) {
  514. case SCI_RNC_READY:
  515. return SCI_SUCCESS;
  516. case SCI_RNC_TX_SUSPENDED:
  517. case SCI_RNC_TX_RX_SUSPENDED:
  518. case SCI_RNC_AWAIT_SUSPENSION:
  519. dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  520. "%s: invalid state %d\n", __func__, state);
  521. return SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED;
  522. default:
  523. break;
  524. }
  525. dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  526. "%s: requested to start IO while still resuming, %d\n",
  527. __func__, state);
  528. return SCI_FAILURE_INVALID_STATE;
  529. }
  530. enum sci_status sci_remote_node_context_start_task(struct sci_remote_node_context *sci_rnc,
  531. struct isci_request *ireq)
  532. {
  533. enum scis_sds_remote_node_context_states state;
  534. state = sci_rnc->sm.current_state_id;
  535. switch (state) {
  536. case SCI_RNC_RESUMING:
  537. case SCI_RNC_READY:
  538. case SCI_RNC_AWAIT_SUSPENSION:
  539. return SCI_SUCCESS;
  540. case SCI_RNC_TX_SUSPENDED:
  541. case SCI_RNC_TX_RX_SUSPENDED:
  542. sci_remote_node_context_resume(sci_rnc, NULL, NULL);
  543. return SCI_SUCCESS;
  544. default:
  545. dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
  546. "%s: invalid state %d\n", __func__, state);
  547. return SCI_FAILURE_INVALID_STATE;
  548. }
  549. }