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