isci: replace this_* and the_* variables with more meaningful names
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / scsi / isci / core / scic_sds_remote_device.c
blobfa7828d4d97535e7c888faab23a514f0f4435750
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.
5 * GPL LICENSE SUMMARY
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
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.
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.
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.
24 * BSD LICENSE
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
31 * are met:
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.
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.
56 #include "intel_sas.h"
57 #include "scic_controller.h"
58 #include "scic_phy.h"
59 #include "scic_port.h"
60 #include "scic_remote_device.h"
61 #include "scic_sds_controller.h"
62 #include "scic_sds_phy.h"
63 #include "scic_sds_port.h"
64 #include "scic_sds_remote_device.h"
65 #include "scic_sds_remote_node_context.h"
66 #include "scic_sds_request.h"
67 #include "sci_environment.h"
68 #include "sci_util.h"
69 #include "scu_event_codes.h"
72 #define SCIC_SDS_REMOTE_DEVICE_RESET_TIMEOUT (1000)
75 * *****************************************************************************
76 * * CORE REMOTE DEVICE PRIVATE METHODS
77 * ***************************************************************************** */
80 * *****************************************************************************
81 * * CORE REMOTE DEVICE PUBLIC METHODS
82 * ***************************************************************************** */
84 u32 scic_remote_device_get_object_size(void)
86 return sizeof(struct scic_sds_remote_device)
87 + sizeof(struct scic_sds_remote_node_context);
90 enum sci_status scic_remote_device_da_construct(
91 struct scic_sds_remote_device *sci_dev)
93 enum sci_status status;
94 u16 remote_node_index;
95 struct sci_sas_identify_address_frame_protocols protocols;
98 * This information is request to determine how many remote node context
99 * entries will be needed to store the remote node.
101 scic_sds_port_get_attached_protocols(sci_dev->owning_port, &protocols);
102 sci_dev->target_protocols.u.all = protocols.u.all;
103 sci_dev->is_direct_attached = true;
104 #if !defined(DISABLE_ATAPI)
105 sci_dev->is_atapi = scic_sds_remote_device_is_atapi(sci_dev);
106 #endif
108 status = scic_sds_controller_allocate_remote_node_context(
109 sci_dev->owning_port->owning_controller,
110 sci_dev,
111 &remote_node_index);
113 if (status == SCI_SUCCESS) {
114 sci_dev->rnc->remote_node_index = remote_node_index;
116 scic_sds_port_get_attached_sas_address(
117 sci_dev->owning_port, &sci_dev->device_address);
119 if (sci_dev->target_protocols.u.bits.attached_ssp_target) {
120 sci_dev->has_ready_substate_machine = false;
121 } else if (sci_dev->target_protocols.u.bits.attached_stp_target) {
122 sci_dev->has_ready_substate_machine = true;
124 sci_base_state_machine_construct(
125 &sci_dev->ready_substate_machine,
126 &sci_dev->parent,
127 scic_sds_stp_remote_device_ready_substate_table,
128 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
129 } else if (sci_dev->target_protocols.u.bits.attached_smp_target) {
130 sci_dev->has_ready_substate_machine = true;
132 /* add the SMP ready substate machine construction here */
133 sci_base_state_machine_construct(
134 &sci_dev->ready_substate_machine,
135 &sci_dev->parent,
136 scic_sds_smp_remote_device_ready_substate_table,
137 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
140 sci_dev->connection_rate = scic_sds_port_get_max_allowed_speed(
141 sci_dev->owning_port);
143 /* / @todo Should I assign the port width by reading all of the phys on the port? */
144 sci_dev->device_port_width = 1;
147 return status;
151 static void scic_sds_remote_device_get_info_from_smp_discover_response(
152 struct scic_sds_remote_device *sci_dev,
153 struct smp_response_discover *discover_response)
155 /* decode discover_response to set sas_address to sci_dev. */
156 sci_dev->device_address.high =
157 discover_response->attached_sas_address.high;
159 sci_dev->device_address.low =
160 discover_response->attached_sas_address.low;
162 sci_dev->target_protocols.u.all = discover_response->protocols.u.all;
166 enum sci_status scic_remote_device_ea_construct(
167 struct scic_sds_remote_device *sci_dev,
168 struct smp_response_discover *discover_response)
170 enum sci_status status;
171 struct scic_sds_controller *scic;
173 scic = scic_sds_port_get_controller(sci_dev->owning_port);
175 scic_sds_remote_device_get_info_from_smp_discover_response(
176 sci_dev, discover_response);
178 status = scic_sds_controller_allocate_remote_node_context(
179 scic, sci_dev, &sci_dev->rnc->remote_node_index);
181 if (status == SCI_SUCCESS) {
182 if (sci_dev->target_protocols.u.bits.attached_ssp_target) {
183 sci_dev->has_ready_substate_machine = false;
184 } else if (sci_dev->target_protocols.u.bits.attached_smp_target) {
185 sci_dev->has_ready_substate_machine = true;
187 /* add the SMP ready substate machine construction here */
188 sci_base_state_machine_construct(
189 &sci_dev->ready_substate_machine,
190 &sci_dev->parent,
191 scic_sds_smp_remote_device_ready_substate_table,
192 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
193 } else if (sci_dev->target_protocols.u.bits.attached_stp_target) {
194 sci_dev->has_ready_substate_machine = true;
196 sci_base_state_machine_construct(
197 &sci_dev->ready_substate_machine,
198 &sci_dev->parent,
199 scic_sds_stp_remote_device_ready_substate_table,
200 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
204 * For SAS-2 the physical link rate is actually a logical link
205 * rate that incorporates multiplexing. The SCU doesn't
206 * incorporate multiplexing and for the purposes of the
207 * connection the logical link rate is that same as the
208 * physical. Furthermore, the SAS-2 and SAS-1.1 fields overlay
209 * one another, so this code works for both situations. */
210 sci_dev->connection_rate = min_t(u16,
211 scic_sds_port_get_max_allowed_speed(sci_dev->owning_port),
212 discover_response->u2.sas1_1.negotiated_physical_link_rate
215 /* / @todo Should I assign the port width by reading all of the phys on the port? */
216 sci_dev->device_port_width = 1;
219 return status;
222 enum sci_status scic_remote_device_destruct(
223 struct scic_sds_remote_device *sci_dev)
225 return sci_dev->state_handlers->destruct_handler(sci_dev);
229 enum sci_status scic_remote_device_start(
230 struct scic_sds_remote_device *sci_dev,
231 u32 timeout)
233 return sci_dev->state_handlers->start_handler(sci_dev);
237 enum sci_status scic_remote_device_stop(
238 struct scic_sds_remote_device *sci_dev,
239 u32 timeout)
241 return sci_dev->state_handlers->stop_handler(sci_dev);
245 enum sci_status scic_remote_device_reset(
246 struct scic_sds_remote_device *sci_dev)
248 return sci_dev->state_handlers->reset_handler(sci_dev);
252 enum sci_status scic_remote_device_reset_complete(
253 struct scic_sds_remote_device *sci_dev)
255 return sci_dev->state_handlers->reset_complete_handler(sci_dev);
259 enum sas_linkrate scic_remote_device_get_connection_rate(
260 struct scic_sds_remote_device *sci_dev)
262 return sci_dev->connection_rate;
266 void scic_remote_device_get_protocols(
267 struct scic_sds_remote_device *sci_dev,
268 struct smp_discover_response_protocols *pr)
270 pr->u.all = sci_dev->target_protocols.u.all;
273 #if !defined(DISABLE_ATAPI)
274 bool scic_remote_device_is_atapi(struct scic_sds_remote_device *sci_dev)
276 return sci_dev->is_atapi;
278 #endif
282 * *****************************************************************************
283 * * SCU DRIVER STANDARD (SDS) REMOTE DEVICE IMPLEMENTATIONS
284 * ***************************************************************************** */
289 * Remote device timer requirements
291 #define SCIC_SDS_REMOTE_DEVICE_MINIMUM_TIMER_COUNT (0)
292 #define SCIC_SDS_REMOTE_DEVICE_MAXIMUM_TIMER_COUNT (SCI_MAX_REMOTE_DEVICES)
297 * @sci_dev: The remote device for which the suspend is being requested.
299 * This method invokes the remote device suspend state handler. enum sci_status
301 enum sci_status scic_sds_remote_device_suspend(
302 struct scic_sds_remote_device *sci_dev,
303 u32 suspend_type)
305 return sci_dev->state_handlers->suspend_handler(sci_dev, suspend_type);
310 * @sci_dev: The remote device for which the resume is being requested.
312 * This method invokes the remote device resume state handler. enum sci_status
314 enum sci_status scic_sds_remote_device_resume(
315 struct scic_sds_remote_device *sci_dev)
317 return sci_dev->state_handlers->resume_handler(sci_dev);
322 * @sci_dev: The remote device for which the event handling is being
323 * requested.
324 * @frame_index: This is the frame index that is being processed.
326 * This method invokes the frame handler for the remote device state machine
327 * enum sci_status
329 enum sci_status scic_sds_remote_device_frame_handler(
330 struct scic_sds_remote_device *sci_dev,
331 u32 frame_index)
333 return sci_dev->state_handlers->frame_handler(sci_dev, frame_index);
338 * @sci_dev: The remote device for which the event handling is being
339 * requested.
340 * @event_code: This is the event code that is to be processed.
342 * This method invokes the remote device event handler. enum sci_status
344 enum sci_status scic_sds_remote_device_event_handler(
345 struct scic_sds_remote_device *sci_dev,
346 u32 event_code)
348 return sci_dev->state_handlers->event_handler(sci_dev, event_code);
353 * @controller: The controller that is starting the io request.
354 * @sci_dev: The remote device for which the start io handling is being
355 * requested.
356 * @io_request: The io request that is being started.
358 * This method invokes the remote device start io handler. enum sci_status
360 enum sci_status scic_sds_remote_device_start_io(
361 struct scic_sds_controller *controller,
362 struct scic_sds_remote_device *sci_dev,
363 struct scic_sds_request *io_request)
365 return sci_dev->state_handlers->start_io_handler(
366 sci_dev, io_request);
371 * @controller: The controller that is completing the io request.
372 * @sci_dev: The remote device for which the complete io handling is being
373 * requested.
374 * @io_request: The io request that is being completed.
376 * This method invokes the remote device complete io handler. enum sci_status
378 enum sci_status scic_sds_remote_device_complete_io(
379 struct scic_sds_controller *controller,
380 struct scic_sds_remote_device *sci_dev,
381 struct scic_sds_request *io_request)
383 return sci_dev->state_handlers->complete_io_handler(
384 sci_dev, io_request);
389 * @controller: The controller that is starting the task request.
390 * @sci_dev: The remote device for which the start task handling is being
391 * requested.
392 * @io_request: The task request that is being started.
394 * This method invokes the remote device start task handler. enum sci_status
396 enum sci_status scic_sds_remote_device_start_task(
397 struct scic_sds_controller *controller,
398 struct scic_sds_remote_device *sci_dev,
399 struct scic_sds_request *io_request)
401 return sci_dev->state_handlers->start_task_handler(
402 sci_dev, io_request);
407 * @controller: The controller that is completing the task request.
408 * @sci_dev: The remote device for which the complete task handling is
409 * being requested.
410 * @io_request: The task request that is being completed.
412 * This method invokes the remote device complete task handler. enum sci_status
417 * @sci_dev:
418 * @request:
420 * This method takes the request and bulids an appropriate SCU context for the
421 * request and then requests the controller to post the request. none
423 void scic_sds_remote_device_post_request(
424 struct scic_sds_remote_device *sci_dev,
425 u32 request)
427 u32 context;
429 context = scic_sds_remote_device_build_command_context(sci_dev, request);
431 scic_sds_controller_post_request(
432 scic_sds_remote_device_get_controller(sci_dev),
433 context
437 #if !defined(DISABLE_ATAPI)
440 * @sci_dev: The device to be checked.
442 * This method check the signature fis of a stp device to decide whether a
443 * device is atapi or not. true if a device is atapi device. False if a device
444 * is not atapi.
446 bool scic_sds_remote_device_is_atapi(
447 struct scic_sds_remote_device *sci_dev)
449 if (!sci_dev->target_protocols.u.bits.attached_stp_target)
450 return false;
451 else if (sci_dev->is_direct_attached) {
452 struct scic_sds_phy *phy;
453 struct scic_sata_phy_properties properties;
454 struct sata_fis_reg_d2h *signature_fis;
455 phy = scic_sds_port_get_a_connected_phy(sci_dev->owning_port);
456 scic_sata_phy_get_properties(phy, &properties);
458 /* decode the signature fis. */
459 signature_fis = &(properties.signature_fis);
461 if ((signature_fis->sector_count == 0x01)
462 && (signature_fis->lba_low == 0x01)
463 && (signature_fis->lba_mid == 0x14)
464 && (signature_fis->lba_high == 0xEB)
465 && ((signature_fis->device & 0x5F) == 0x00)
467 /* An ATA device supporting the PACKET command set. */
468 return true;
469 } else
470 return false;
471 } else {
472 /* Expander supported ATAPI device is not currently supported. */
473 return false;
476 #endif
480 * @user_parameter: This is cast to a remote device object.
482 * This method is called once the remote node context is ready to be freed.
483 * The remote device can now report that its stop operation is complete. none
485 static void scic_sds_cb_remote_device_rnc_destruct_complete(
486 void *user_parameter)
488 struct scic_sds_remote_device *sci_dev;
490 sci_dev = (struct scic_sds_remote_device *)user_parameter;
492 BUG_ON(sci_dev->started_request_count != 0);
494 sci_base_state_machine_change_state(&sci_dev->state_machine,
495 SCI_BASE_REMOTE_DEVICE_STATE_STOPPED);
500 * @user_parameter: This is cast to a remote device object.
502 * This method is called once the remote node context has transisitioned to a
503 * ready state. This is the indication that the remote device object can also
504 * transition to ready. none
506 static void scic_sds_remote_device_resume_complete_handler(
507 void *user_parameter)
509 struct scic_sds_remote_device *sci_dev;
511 sci_dev = (struct scic_sds_remote_device *)user_parameter;
513 if (
514 sci_base_state_machine_get_state(&sci_dev->state_machine)
515 != SCI_BASE_REMOTE_DEVICE_STATE_READY
517 sci_base_state_machine_change_state(
518 &sci_dev->state_machine,
519 SCI_BASE_REMOTE_DEVICE_STATE_READY
526 * @device: This parameter specifies the device for which the request is being
527 * started.
528 * @request: This parameter specifies the request being started.
529 * @status: This parameter specifies the current start operation status.
531 * This method will perform the STP request start processing common to IO
532 * requests and task requests of all types. none
534 void scic_sds_remote_device_start_request(
535 struct scic_sds_remote_device *sci_dev,
536 struct scic_sds_request *sci_req,
537 enum sci_status status)
539 /* We still have a fault in starting the io complete it on the port */
540 if (status == SCI_SUCCESS)
541 scic_sds_remote_device_increment_request_count(sci_dev);
542 else{
543 sci_dev->owning_port->state_handlers->complete_io_handler(
544 sci_dev->owning_port, sci_dev, sci_req
552 * @request: This parameter specifies the request being continued.
554 * This method will continue to post tc for a STP request. This method usually
555 * serves as a callback when RNC gets resumed during a task management
556 * sequence. none
558 void scic_sds_remote_device_continue_request(void *dev)
560 struct scic_sds_remote_device *sci_dev = dev;
562 /* we need to check if this request is still valid to continue. */
563 if (sci_dev->working_request)
564 scic_controller_continue_io(sci_dev->working_request);
569 * @user_parameter: This is cast to a remote device object.
571 * This method is called once the remote node context has reached a suspended
572 * state. The remote device can now report that its suspend operation is
573 * complete. none
577 * This method will terminate all of the IO requests in the controllers IO
578 * request table that were targeted for this device.
579 * @sci_dev: This parameter specifies the remote device for which to
580 * attempt to terminate all requests.
582 * This method returns an indication as to whether all requests were
583 * successfully terminated. If a single request fails to be terminated, then
584 * this method will return the failure.
586 static enum sci_status scic_sds_remote_device_terminate_requests(
587 struct scic_sds_remote_device *sci_dev)
589 enum sci_status status = SCI_SUCCESS;
590 enum sci_status terminate_status = SCI_SUCCESS;
591 struct scic_sds_request *sci_req;
592 u32 index;
593 u32 request_count = sci_dev->started_request_count;
595 for (index = 0;
596 (index < SCI_MAX_IO_REQUESTS) && (request_count > 0);
597 index++) {
598 sci_req = sci_dev->owning_port->owning_controller->io_request_table[index];
600 if ((sci_req != NULL) && (sci_req->target_device == sci_dev)) {
601 terminate_status = scic_controller_terminate_request(
602 sci_dev->owning_port->owning_controller,
603 sci_dev,
604 sci_req
607 if (terminate_status != SCI_SUCCESS)
608 status = terminate_status;
610 request_count--;
614 return status;
617 static enum sci_status
618 default_device_handler(struct scic_sds_remote_device *sci_dev,
619 const char *func)
621 dev_warn(scirdev_to_dev(sci_dev),
622 "%s: in wrong state: %d\n", func,
623 sci_base_state_machine_get_state(&sci_dev->state_machine));
624 return SCI_FAILURE_INVALID_STATE;
627 enum sci_status scic_sds_remote_device_default_start_handler(
628 struct scic_sds_remote_device *sci_dev)
630 return default_device_handler(sci_dev, __func__);
633 static enum sci_status scic_sds_remote_device_default_stop_handler(
634 struct scic_sds_remote_device *sci_dev)
636 return default_device_handler(sci_dev, __func__);
639 enum sci_status scic_sds_remote_device_default_fail_handler(
640 struct scic_sds_remote_device *sci_dev)
642 return default_device_handler(sci_dev, __func__);
645 enum sci_status scic_sds_remote_device_default_destruct_handler(
646 struct scic_sds_remote_device *sci_dev)
648 return default_device_handler(sci_dev, __func__);
651 enum sci_status scic_sds_remote_device_default_reset_handler(
652 struct scic_sds_remote_device *sci_dev)
654 return default_device_handler(sci_dev, __func__);
657 enum sci_status scic_sds_remote_device_default_reset_complete_handler(
658 struct scic_sds_remote_device *sci_dev)
660 return default_device_handler(sci_dev, __func__);
663 enum sci_status scic_sds_remote_device_default_suspend_handler(
664 struct scic_sds_remote_device *sci_dev, u32 suspend_type)
666 return default_device_handler(sci_dev, __func__);
669 enum sci_status scic_sds_remote_device_default_resume_handler(
670 struct scic_sds_remote_device *sci_dev)
672 return default_device_handler(sci_dev, __func__);
677 * @device: The struct scic_sds_remote_device which is then cast into a
678 * struct scic_sds_remote_device.
679 * @event_code: The event code that the struct scic_sds_controller wants the device
680 * object to process.
682 * This method is the default event handler. It will call the RNC state
683 * machine handler for any RNC events otherwise it will log a warning and
684 * returns a failure. enum sci_status SCI_FAILURE_INVALID_STATE
686 static enum sci_status scic_sds_remote_device_core_event_handler(
687 struct scic_sds_remote_device *sci_dev,
688 u32 event_code,
689 bool is_ready_state)
691 enum sci_status status;
693 switch (scu_get_event_type(event_code)) {
694 case SCU_EVENT_TYPE_RNC_OPS_MISC:
695 case SCU_EVENT_TYPE_RNC_SUSPEND_TX:
696 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX:
697 status = scic_sds_remote_node_context_event_handler(sci_dev->rnc, event_code);
698 break;
699 case SCU_EVENT_TYPE_PTX_SCHEDULE_EVENT:
701 if (scu_get_event_code(event_code) == SCU_EVENT_IT_NEXUS_TIMEOUT) {
702 status = SCI_SUCCESS;
704 /* Suspend the associated RNC */
705 scic_sds_remote_node_context_suspend(sci_dev->rnc,
706 SCI_SOFTWARE_SUSPENSION,
707 NULL, NULL);
709 dev_dbg(scirdev_to_dev(sci_dev),
710 "%s: device: %p event code: %x: %s\n",
711 __func__, sci_dev, event_code,
712 (is_ready_state)
713 ? "I_T_Nexus_Timeout event"
714 : "I_T_Nexus_Timeout event in wrong state");
716 break;
718 /* Else, fall through and treat as unhandled... */
720 default:
721 dev_dbg(scirdev_to_dev(sci_dev),
722 "%s: device: %p event code: %x: %s\n",
723 __func__, sci_dev, event_code,
724 (is_ready_state)
725 ? "unexpected event"
726 : "unexpected event in wrong state");
727 status = SCI_FAILURE_INVALID_STATE;
728 break;
731 return status;
735 * @device: The struct scic_sds_remote_device which is then cast into a
736 * struct scic_sds_remote_device.
737 * @event_code: The event code that the struct scic_sds_controller wants the device
738 * object to process.
740 * This method is the default event handler. It will call the RNC state
741 * machine handler for any RNC events otherwise it will log a warning and
742 * returns a failure. enum sci_status SCI_FAILURE_INVALID_STATE
744 static enum sci_status scic_sds_remote_device_default_event_handler(
745 struct scic_sds_remote_device *sci_dev,
746 u32 event_code)
748 return scic_sds_remote_device_core_event_handler(sci_dev,
749 event_code,
750 false);
755 * @device: The struct scic_sds_remote_device which is then cast into a
756 * struct scic_sds_remote_device.
757 * @frame_index: The frame index for which the struct scic_sds_controller wants this
758 * device object to process.
760 * This method is the default unsolicited frame handler. It logs a warning,
761 * releases the frame and returns a failure. enum sci_status
762 * SCI_FAILURE_INVALID_STATE
764 enum sci_status scic_sds_remote_device_default_frame_handler(
765 struct scic_sds_remote_device *sci_dev,
766 u32 frame_index)
768 dev_warn(scirdev_to_dev(sci_dev),
769 "%s: SCIC Remote Device requested to handle frame %x "
770 "while in wrong state %d\n",
771 __func__,
772 frame_index,
773 sci_base_state_machine_get_state(
774 &sci_dev->state_machine));
776 /* Return the frame back to the controller */
777 scic_sds_controller_release_frame(
778 scic_sds_remote_device_get_controller(sci_dev), frame_index
781 return SCI_FAILURE_INVALID_STATE;
784 enum sci_status scic_sds_remote_device_default_start_request_handler(
785 struct scic_sds_remote_device *sci_dev,
786 struct scic_sds_request *request)
788 return default_device_handler(sci_dev, __func__);
791 enum sci_status scic_sds_remote_device_default_complete_request_handler(
792 struct scic_sds_remote_device *sci_dev,
793 struct scic_sds_request *request)
795 return default_device_handler(sci_dev, __func__);
798 enum sci_status scic_sds_remote_device_default_continue_request_handler(
799 struct scic_sds_remote_device *sci_dev,
800 struct scic_sds_request *request)
802 return default_device_handler(sci_dev, __func__);
807 * @device: The struct scic_sds_remote_device which is then cast into a
808 * struct scic_sds_remote_device.
809 * @frame_index: The frame index for which the struct scic_sds_controller wants this
810 * device object to process.
812 * This method is a general ssp frame handler. In most cases the device object
813 * needs to route the unsolicited frame processing to the io request object.
814 * This method decodes the tag for the io request object and routes the
815 * unsolicited frame to that object. enum sci_status SCI_FAILURE_INVALID_STATE
817 enum sci_status scic_sds_remote_device_general_frame_handler(
818 struct scic_sds_remote_device *sci_dev,
819 u32 frame_index)
821 enum sci_status result;
822 struct sci_ssp_frame_header *frame_header;
823 struct scic_sds_request *io_request;
825 result = scic_sds_unsolicited_frame_control_get_header(
826 &(scic_sds_remote_device_get_controller(sci_dev)->uf_control),
827 frame_index,
828 (void **)&frame_header
831 if (SCI_SUCCESS == result) {
832 io_request = scic_sds_controller_get_io_request_from_tag(
833 scic_sds_remote_device_get_controller(sci_dev), frame_header->tag);
835 if ((io_request == NULL)
836 || (io_request->target_device != sci_dev)) {
838 * We could not map this tag to a valid IO request
839 * Just toss the frame and continue */
840 scic_sds_controller_release_frame(
841 scic_sds_remote_device_get_controller(sci_dev), frame_index
843 } else {
844 /* The IO request is now in charge of releasing the frame */
845 result = io_request->state_handlers->frame_handler(
846 io_request, frame_index);
850 return result;
855 * @[in]: sci_dev This is the device object that is receiving the event.
856 * @[in]: event_code The event code to process.
858 * This is a common method for handling events reported to the remote device
859 * from the controller object. enum sci_status
861 enum sci_status scic_sds_remote_device_general_event_handler(
862 struct scic_sds_remote_device *sci_dev,
863 u32 event_code)
865 return scic_sds_remote_device_core_event_handler(sci_dev,
866 event_code,
867 true);
871 * *****************************************************************************
872 * * STOPPED STATE HANDLERS
873 * ***************************************************************************** */
877 * @device:
879 * This method takes the struct scic_sds_remote_device from a stopped state and
880 * attempts to start it. The RNC buffer for the device is constructed and the
881 * device state machine is transitioned to the
882 * SCIC_BASE_REMOTE_DEVICE_STATE_STARTING. enum sci_status SCI_SUCCESS if there is
883 * an RNC buffer available to construct the remote device.
884 * SCI_FAILURE_INSUFFICIENT_RESOURCES if there is no RNC buffer available in
885 * which to construct the remote device.
887 static enum sci_status scic_sds_remote_device_stopped_state_start_handler(
888 struct scic_sds_remote_device *sci_dev)
890 enum sci_status status;
892 status = scic_sds_remote_node_context_resume(sci_dev->rnc,
893 scic_sds_remote_device_resume_complete_handler, sci_dev);
895 if (status == SCI_SUCCESS)
896 sci_base_state_machine_change_state(&sci_dev->state_machine,
897 SCI_BASE_REMOTE_DEVICE_STATE_STARTING);
899 return status;
902 static enum sci_status scic_sds_remote_device_stopped_state_stop_handler(
903 struct scic_sds_remote_device *sci_dev)
905 return SCI_SUCCESS;
910 * @sci_dev: The struct scic_sds_remote_device which is cast into a
911 * struct scic_sds_remote_device.
913 * This method will destruct a struct scic_sds_remote_device that is in a stopped
914 * state. This is the only state from which a destruct request will succeed.
915 * The RNi for this struct scic_sds_remote_device is returned to the free pool and the
916 * device object transitions to the SCI_BASE_REMOTE_DEVICE_STATE_FINAL.
917 * enum sci_status SCI_SUCCESS
919 static enum sci_status scic_sds_remote_device_stopped_state_destruct_handler(
920 struct scic_sds_remote_device *sci_dev)
922 struct scic_sds_controller *scic;
924 scic = scic_sds_remote_device_get_controller(sci_dev);
925 scic_sds_controller_free_remote_node_context(scic, sci_dev,
926 sci_dev->rnc->remote_node_index);
927 sci_dev->rnc->remote_node_index = SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX;
929 sci_base_state_machine_change_state(&sci_dev->state_machine,
930 SCI_BASE_REMOTE_DEVICE_STATE_FINAL);
932 return SCI_SUCCESS;
936 * *****************************************************************************
937 * * STARTING STATE HANDLERS
938 * ***************************************************************************** */
940 static enum sci_status scic_sds_remote_device_starting_state_stop_handler(
941 struct scic_sds_remote_device *sci_dev)
944 * This device has not yet started so there had better be no IO requests
946 BUG_ON(sci_dev->started_request_count != 0);
949 * Destroy the remote node context
951 scic_sds_remote_node_context_destruct(sci_dev->rnc,
952 scic_sds_cb_remote_device_rnc_destruct_complete, sci_dev);
955 * Transition to the stopping state and wait for the remote node to
956 * complete being posted and invalidated.
958 sci_base_state_machine_change_state(&sci_dev->state_machine,
959 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING);
961 return SCI_SUCCESS;
964 enum sci_status scic_sds_remote_device_ready_state_stop_handler(
965 struct scic_sds_remote_device *sci_dev)
967 enum sci_status status = SCI_SUCCESS;
969 /* Request the parent state machine to transition to the stopping state */
970 sci_base_state_machine_change_state(&sci_dev->state_machine,
971 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING);
973 if (sci_dev->started_request_count == 0) {
974 scic_sds_remote_node_context_destruct(sci_dev->rnc,
975 scic_sds_cb_remote_device_rnc_destruct_complete,
976 sci_dev);
977 } else
978 status = scic_sds_remote_device_terminate_requests(sci_dev);
980 return status;
985 * @device: The struct scic_sds_remote_device object which is cast to a
986 * struct scic_sds_remote_device object.
988 * This is the ready state device reset handler enum sci_status
990 enum sci_status scic_sds_remote_device_ready_state_reset_handler(
991 struct scic_sds_remote_device *sci_dev)
993 /* Request the parent state machine to transition to the stopping state */
994 sci_base_state_machine_change_state(&sci_dev->state_machine,
995 SCI_BASE_REMOTE_DEVICE_STATE_RESETTING);
997 return SCI_SUCCESS;
1001 * This method will attempt to start a task request for this device object. The
1002 * remote device object will issue the start request for the task and if
1003 * successful it will start the request for the port object then increment its
1004 * own requet count. enum sci_status SCI_SUCCESS if the task request is started for
1005 * this device object. SCI_FAILURE_INSUFFICIENT_RESOURCES if the io request
1006 * object could not get the resources to start.
1008 static enum sci_status scic_sds_remote_device_ready_state_start_task_handler(
1009 struct scic_sds_remote_device *sci_dev,
1010 struct scic_sds_request *request)
1012 enum sci_status result;
1014 /* See if the port is in a state where we can start the IO request */
1015 result = scic_sds_port_start_io(
1016 scic_sds_remote_device_get_port(sci_dev), sci_dev, request);
1018 if (result == SCI_SUCCESS) {
1019 result = scic_sds_remote_node_context_start_task(
1020 sci_dev->rnc, request);
1021 if (result == SCI_SUCCESS)
1022 result = scic_sds_request_start(request);
1024 scic_sds_remote_device_start_request(sci_dev, request, result);
1027 return result;
1031 * This method will attempt to start an io request for this device object. The
1032 * remote device object will issue the start request for the io and if
1033 * successful it will start the request for the port object then increment its
1034 * own requet count. enum sci_status SCI_SUCCESS if the io request is started for
1035 * this device object. SCI_FAILURE_INSUFFICIENT_RESOURCES if the io request
1036 * object could not get the resources to start.
1038 static enum sci_status scic_sds_remote_device_ready_state_start_io_handler(
1039 struct scic_sds_remote_device *sci_dev,
1040 struct scic_sds_request *request)
1042 enum sci_status result;
1044 /* See if the port is in a state where we can start the IO request */
1045 result = scic_sds_port_start_io(
1046 scic_sds_remote_device_get_port(sci_dev), sci_dev, request);
1048 if (result == SCI_SUCCESS) {
1049 result = scic_sds_remote_node_context_start_io(
1050 sci_dev->rnc, request);
1051 if (result == SCI_SUCCESS)
1052 result = scic_sds_request_start(request);
1054 scic_sds_remote_device_start_request(sci_dev, request, result);
1057 return result;
1061 * This method will complete the request for the remote device object. The
1062 * method will call the completion handler for the request object and if
1063 * successful it will complete the request on the port object then decrement
1064 * its own started_request_count. enum sci_status
1066 static enum sci_status scic_sds_remote_device_ready_state_complete_request_handler(
1067 struct scic_sds_remote_device *sci_dev,
1068 struct scic_sds_request *request)
1070 enum sci_status result;
1072 result = scic_sds_request_complete(request);
1074 if (result != SCI_SUCCESS)
1075 return result;
1077 /* See if the port is in a state
1078 * where we can start the IO request */
1079 result = scic_sds_port_complete_io(
1080 scic_sds_remote_device_get_port(sci_dev),
1081 sci_dev, request);
1083 if (result == SCI_SUCCESS)
1084 scic_sds_remote_device_decrement_request_count(sci_dev);
1086 return result;
1090 * *****************************************************************************
1091 * * STOPPING STATE HANDLERS
1092 * ***************************************************************************** */
1096 * @sci_dev: The struct scic_sds_remote_device which is cast into a
1097 * struct scic_sds_remote_device.
1099 * This method will stop a struct scic_sds_remote_device that is already in the
1100 * SCI_BASE_REMOTE_DEVICE_STATE_STOPPING state. This is not considered an error
1101 * since we allow a stop request on a device that is alreay stopping or
1102 * stopped. enum sci_status SCI_SUCCESS
1104 static enum sci_status scic_sds_remote_device_stopping_state_stop_handler(
1105 struct scic_sds_remote_device *device)
1108 * All requests should have been terminated, but if there is an
1109 * attempt to stop a device already in the stopping state, then
1110 * try again to terminate. */
1111 return scic_sds_remote_device_terminate_requests(device);
1117 * @device: The device object for which the request is completing.
1118 * @request: The task request that is being completed.
1120 * This method completes requests for this struct scic_sds_remote_device while it is
1121 * in the SCI_BASE_REMOTE_DEVICE_STATE_STOPPING state. This method calls the
1122 * complete method for the request object and if that is successful the port
1123 * object is called to complete the task request. Then the device object itself
1124 * completes the task request. If struct scic_sds_remote_device started_request_count
1125 * goes to 0 and the invalidate RNC request has completed the device object can
1126 * transition to the SCI_BASE_REMOTE_DEVICE_STATE_STOPPED. enum sci_status
1128 static enum sci_status scic_sds_remote_device_stopping_state_complete_request_handler(
1129 struct scic_sds_remote_device *sci_dev,
1130 struct scic_sds_request *request)
1132 enum sci_status status = SCI_SUCCESS;
1134 status = scic_sds_request_complete(request);
1136 if (status != SCI_SUCCESS)
1137 return status;
1139 status = scic_sds_port_complete_io(scic_sds_remote_device_get_port(sci_dev),
1140 sci_dev, request);
1141 if (status != SCI_SUCCESS)
1142 return status;
1144 scic_sds_remote_device_decrement_request_count(sci_dev);
1146 if (scic_sds_remote_device_get_request_count(sci_dev) == 0)
1147 scic_sds_remote_node_context_destruct(sci_dev->rnc,
1148 scic_sds_cb_remote_device_rnc_destruct_complete,
1149 sci_dev);
1150 return SCI_SUCCESS;
1155 * @device: The struct scic_sds_remote_device which is to be cast into a
1156 * struct scic_sds_remote_device object.
1158 * This method will complete the reset operation when the device is in the
1159 * resetting state. enum sci_status
1161 static enum sci_status scic_sds_remote_device_resetting_state_reset_complete_handler(
1162 struct scic_sds_remote_device *sci_dev)
1165 sci_base_state_machine_change_state(
1166 &sci_dev->state_machine,
1167 SCI_BASE_REMOTE_DEVICE_STATE_READY
1170 return SCI_SUCCESS;
1175 * @device: The struct scic_sds_remote_device which is to be cast into a
1176 * struct scic_sds_remote_device object.
1178 * This method will stop the remote device while in the resetting state.
1179 * enum sci_status
1181 static enum sci_status scic_sds_remote_device_resetting_state_stop_handler(
1182 struct scic_sds_remote_device *sci_dev)
1184 sci_base_state_machine_change_state(
1185 &sci_dev->state_machine,
1186 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
1189 return SCI_SUCCESS;
1193 * This method completes requests for this struct scic_sds_remote_device while it is
1194 * in the SCI_BASE_REMOTE_DEVICE_STATE_RESETTING state. This method calls the
1195 * complete method for the request object and if that is successful the port
1196 * object is called to complete the task request. Then the device object itself
1197 * completes the task request. enum sci_status
1199 static enum sci_status scic_sds_remote_device_resetting_state_complete_request_handler(
1200 struct scic_sds_remote_device *sci_dev,
1201 struct scic_sds_request *request)
1203 enum sci_status status = SCI_SUCCESS;
1205 status = scic_sds_request_complete(request);
1207 if (status == SCI_SUCCESS) {
1208 status = scic_sds_port_complete_io(
1209 scic_sds_remote_device_get_port(sci_dev),
1210 sci_dev, request);
1212 if (status == SCI_SUCCESS) {
1213 scic_sds_remote_device_decrement_request_count(sci_dev);
1217 return status;
1221 * *****************************************************************************
1222 * * FAILED STATE HANDLERS
1223 * ***************************************************************************** */
1227 * @device: The struct scic_sds_remote_device which is to be cast into a
1228 * struct scic_sds_remote_device object.
1230 * This method handles the remove request for a failed struct scic_sds_remote_device
1231 * object. The method will transition the device object to the
1232 * SCIC_BASE_REMOTE_DEVICE_STATE_STOPPING. enum sci_status SCI_SUCCESS
1235 /* --------------------------------------------------------------------------- */
1237 static const struct scic_sds_remote_device_state_handler scic_sds_remote_device_state_handler_table[] = {
1238 [SCI_BASE_REMOTE_DEVICE_STATE_INITIAL] = {
1239 .start_handler = scic_sds_remote_device_default_start_handler,
1240 .stop_handler = scic_sds_remote_device_default_stop_handler,
1241 .fail_handler = scic_sds_remote_device_default_fail_handler,
1242 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1243 .reset_handler = scic_sds_remote_device_default_reset_handler,
1244 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1245 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1246 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1247 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1248 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1249 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1250 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1251 .resume_handler = scic_sds_remote_device_default_resume_handler,
1252 .event_handler = scic_sds_remote_device_default_event_handler,
1253 .frame_handler = scic_sds_remote_device_default_frame_handler
1255 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPED] = {
1256 .start_handler = scic_sds_remote_device_stopped_state_start_handler,
1257 .stop_handler = scic_sds_remote_device_stopped_state_stop_handler,
1258 .fail_handler = scic_sds_remote_device_default_fail_handler,
1259 .destruct_handler = scic_sds_remote_device_stopped_state_destruct_handler,
1260 .reset_handler = scic_sds_remote_device_default_reset_handler,
1261 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1262 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1263 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1264 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1265 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1266 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1267 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1268 .resume_handler = scic_sds_remote_device_default_resume_handler,
1269 .event_handler = scic_sds_remote_device_default_event_handler,
1270 .frame_handler = scic_sds_remote_device_default_frame_handler
1272 [SCI_BASE_REMOTE_DEVICE_STATE_STARTING] = {
1273 .start_handler = scic_sds_remote_device_default_start_handler,
1274 .stop_handler = scic_sds_remote_device_starting_state_stop_handler,
1275 .fail_handler = scic_sds_remote_device_default_fail_handler,
1276 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1277 .reset_handler = scic_sds_remote_device_default_reset_handler,
1278 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1279 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1280 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1281 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1282 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1283 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1284 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1285 .resume_handler = scic_sds_remote_device_default_resume_handler,
1286 .event_handler = scic_sds_remote_device_general_event_handler,
1287 .frame_handler = scic_sds_remote_device_default_frame_handler
1289 [SCI_BASE_REMOTE_DEVICE_STATE_READY] = {
1290 .start_handler = scic_sds_remote_device_default_start_handler,
1291 .stop_handler = scic_sds_remote_device_ready_state_stop_handler,
1292 .fail_handler = scic_sds_remote_device_default_fail_handler,
1293 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1294 .reset_handler = scic_sds_remote_device_ready_state_reset_handler,
1295 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1296 .start_io_handler = scic_sds_remote_device_ready_state_start_io_handler,
1297 .complete_io_handler = scic_sds_remote_device_ready_state_complete_request_handler,
1298 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1299 .start_task_handler = scic_sds_remote_device_ready_state_start_task_handler,
1300 .complete_task_handler = scic_sds_remote_device_ready_state_complete_request_handler,
1301 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1302 .resume_handler = scic_sds_remote_device_default_resume_handler,
1303 .event_handler = scic_sds_remote_device_general_event_handler,
1304 .frame_handler = scic_sds_remote_device_general_frame_handler,
1306 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPING] = {
1307 .start_handler = scic_sds_remote_device_default_start_handler,
1308 .stop_handler = scic_sds_remote_device_stopping_state_stop_handler,
1309 .fail_handler = scic_sds_remote_device_default_fail_handler,
1310 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1311 .reset_handler = scic_sds_remote_device_default_reset_handler,
1312 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1313 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1314 .complete_io_handler = scic_sds_remote_device_stopping_state_complete_request_handler,
1315 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1316 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1317 .complete_task_handler = scic_sds_remote_device_stopping_state_complete_request_handler,
1318 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1319 .resume_handler = scic_sds_remote_device_default_resume_handler,
1320 .event_handler = scic_sds_remote_device_general_event_handler,
1321 .frame_handler = scic_sds_remote_device_general_frame_handler
1323 [SCI_BASE_REMOTE_DEVICE_STATE_FAILED] = {
1324 .start_handler = scic_sds_remote_device_default_start_handler,
1325 .stop_handler = scic_sds_remote_device_default_stop_handler,
1326 .fail_handler = scic_sds_remote_device_default_fail_handler,
1327 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1328 .reset_handler = scic_sds_remote_device_default_reset_handler,
1329 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1330 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1331 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1332 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1333 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1334 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1335 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1336 .resume_handler = scic_sds_remote_device_default_resume_handler,
1337 .event_handler = scic_sds_remote_device_default_event_handler,
1338 .frame_handler = scic_sds_remote_device_general_frame_handler
1340 [SCI_BASE_REMOTE_DEVICE_STATE_RESETTING] = {
1341 .start_handler = scic_sds_remote_device_default_start_handler,
1342 .stop_handler = scic_sds_remote_device_resetting_state_stop_handler,
1343 .fail_handler = scic_sds_remote_device_default_fail_handler,
1344 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1345 .reset_handler = scic_sds_remote_device_default_reset_handler,
1346 .reset_complete_handler = scic_sds_remote_device_resetting_state_reset_complete_handler,
1347 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1348 .complete_io_handler = scic_sds_remote_device_resetting_state_complete_request_handler,
1349 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1350 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1351 .complete_task_handler = scic_sds_remote_device_resetting_state_complete_request_handler,
1352 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1353 .resume_handler = scic_sds_remote_device_default_resume_handler,
1354 .event_handler = scic_sds_remote_device_default_event_handler,
1355 .frame_handler = scic_sds_remote_device_general_frame_handler
1357 [SCI_BASE_REMOTE_DEVICE_STATE_FINAL] = {
1358 .start_handler = scic_sds_remote_device_default_start_handler,
1359 .stop_handler = scic_sds_remote_device_default_stop_handler,
1360 .fail_handler = scic_sds_remote_device_default_fail_handler,
1361 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1362 .reset_handler = scic_sds_remote_device_default_reset_handler,
1363 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1364 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1365 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1366 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1367 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1368 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1369 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1370 .resume_handler = scic_sds_remote_device_default_resume_handler,
1371 .event_handler = scic_sds_remote_device_default_event_handler,
1372 .frame_handler = scic_sds_remote_device_default_frame_handler
1378 * @object: This is the struct sci_base_object that is cast into a
1379 * struct scic_sds_remote_device.
1381 * This is the enter method for the SCI_BASE_REMOTE_DEVICE_STATE_INITIAL it
1382 * immediatly transitions the remote device object to the stopped state. none
1384 static void scic_sds_remote_device_initial_state_enter(
1385 struct sci_base_object *object)
1387 struct scic_sds_remote_device *sci_dev = (struct scic_sds_remote_device *)object;
1389 sci_dev = container_of(object, typeof(*sci_dev), parent);
1390 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
1391 SCI_BASE_REMOTE_DEVICE_STATE_INITIAL);
1393 /* Initial state is a transitional state to the stopped state */
1394 sci_base_state_machine_change_state(&sci_dev->state_machine,
1395 SCI_BASE_REMOTE_DEVICE_STATE_STOPPED);
1400 * @object: This is the struct sci_base_object that is cast into a
1401 * struct scic_sds_remote_device.
1403 * This is the enter function for the SCI_BASE_REMOTE_DEVICE_STATE_INITIAL it
1404 * sets the stopped state handlers and if this state is entered from the
1405 * SCI_BASE_REMOTE_DEVICE_STATE_STOPPING then the SCI User is informed that the
1406 * device stop is complete. none
1408 static void scic_sds_remote_device_stopped_state_enter(
1409 struct sci_base_object *object)
1411 struct scic_sds_remote_device *sci_dev;
1412 struct scic_sds_controller *scic;
1413 struct isci_remote_device *idev;
1414 struct isci_host *ihost;
1415 u32 prev_state;
1417 sci_dev = container_of(object, typeof(*sci_dev), parent);
1418 scic = scic_sds_remote_device_get_controller(sci_dev);
1419 ihost = sci_object_get_association(scic);
1420 idev = sci_object_get_association(sci_dev);
1422 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
1423 SCI_BASE_REMOTE_DEVICE_STATE_STOPPED);
1425 /* If we are entering from the stopping state let the SCI User know that
1426 * the stop operation has completed.
1428 prev_state = sci_dev->state_machine.previous_state_id;
1429 if (prev_state == SCI_BASE_REMOTE_DEVICE_STATE_STOPPING)
1430 isci_remote_device_stop_complete(ihost, idev, SCI_SUCCESS);
1432 scic_sds_controller_remote_device_stopped(scic, sci_dev);
1437 * @object: This is the struct sci_base_object that is cast into a
1438 * struct scic_sds_remote_device.
1440 * This is the enter function for the SCI_BASE_REMOTE_DEVICE_STATE_STARTING it
1441 * sets the starting state handlers, sets the device not ready, and posts the
1442 * remote node context to the hardware. none
1444 static void scic_sds_remote_device_starting_state_enter(struct sci_base_object *object)
1446 struct scic_sds_remote_device *sci_dev = container_of(object, typeof(*sci_dev),
1447 parent);
1448 struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev);
1449 struct isci_host *ihost = sci_object_get_association(scic);
1450 struct isci_remote_device *idev = sci_object_get_association(sci_dev);
1452 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
1453 SCI_BASE_REMOTE_DEVICE_STATE_STARTING);
1455 isci_remote_device_not_ready(ihost, idev,
1456 SCIC_REMOTE_DEVICE_NOT_READY_START_REQUESTED);
1459 static void scic_sds_remote_device_starting_state_exit(struct sci_base_object *object)
1461 struct scic_sds_remote_device *sci_dev = container_of(object, typeof(*sci_dev),
1462 parent);
1463 struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev);
1464 struct isci_host *ihost = sci_object_get_association(scic);
1465 struct isci_remote_device *idev = sci_object_get_association(sci_dev);
1468 * @todo Check the device object for the proper return code for this
1469 * callback
1471 isci_remote_device_start_complete(ihost, idev, SCI_SUCCESS);
1476 * @object: This is the struct sci_base_object that is cast into a
1477 * struct scic_sds_remote_device.
1479 * This is the enter function for the SCI_BASE_REMOTE_DEVICE_STATE_READY it sets
1480 * the ready state handlers, and starts the ready substate machine. none
1482 static void scic_sds_remote_device_ready_state_enter(struct sci_base_object *object)
1484 struct scic_sds_remote_device *sci_dev = container_of(object, typeof(*sci_dev),
1485 parent);
1486 struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev);
1487 struct isci_host *ihost = sci_object_get_association(scic);
1488 struct isci_remote_device *idev = sci_object_get_association(sci_dev);
1490 SET_STATE_HANDLER(sci_dev,
1491 scic_sds_remote_device_state_handler_table,
1492 SCI_BASE_REMOTE_DEVICE_STATE_READY);
1494 scic->remote_device_sequence[sci_dev->rnc->remote_node_index]++;
1496 if (sci_dev->has_ready_substate_machine)
1497 sci_base_state_machine_start(&sci_dev->ready_substate_machine);
1498 else
1499 isci_remote_device_ready(ihost, idev);
1504 * @object: This is the struct sci_base_object that is cast into a
1505 * struct scic_sds_remote_device.
1507 * This is the exit function for the SCI_BASE_REMOTE_DEVICE_STATE_READY it does
1508 * nothing. none
1510 static void scic_sds_remote_device_ready_state_exit(
1511 struct sci_base_object *object)
1513 struct scic_sds_remote_device *sci_dev = container_of(object, typeof(*sci_dev),
1514 parent);
1515 if (sci_dev->has_ready_substate_machine)
1516 sci_base_state_machine_stop(&sci_dev->ready_substate_machine);
1517 else {
1518 struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev);
1519 struct isci_host *ihost = sci_object_get_association(scic);
1520 struct isci_remote_device *idev = sci_object_get_association(sci_dev);
1522 isci_remote_device_not_ready(ihost, idev,
1523 SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED);
1529 * @object: This is the struct sci_base_object that is cast into a
1530 * struct scic_sds_remote_device.
1532 * This is the enter method for the SCI_BASE_REMOTE_DEVICE_STATE_STOPPING it
1533 * sets the stopping state handlers and posts an RNC invalidate request to the
1534 * SCU hardware. none
1536 static void scic_sds_remote_device_stopping_state_enter(
1537 struct sci_base_object *object)
1539 struct scic_sds_remote_device *sci_dev = (struct scic_sds_remote_device *)object;
1541 SET_STATE_HANDLER(
1542 sci_dev,
1543 scic_sds_remote_device_state_handler_table,
1544 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
1550 * @object: This is the struct sci_base_object that is cast into a
1551 * struct scic_sds_remote_device.
1553 * This is the enter method for the SCI_BASE_REMOTE_DEVICE_STATE_FAILED it sets
1554 * the stopping state handlers. none
1556 static void scic_sds_remote_device_failed_state_enter(
1557 struct sci_base_object *object)
1559 struct scic_sds_remote_device *sci_dev = (struct scic_sds_remote_device *)object;
1561 SET_STATE_HANDLER(
1562 sci_dev,
1563 scic_sds_remote_device_state_handler_table,
1564 SCI_BASE_REMOTE_DEVICE_STATE_FAILED
1570 * @object: This is the struct sci_base_object that is cast into a
1571 * struct scic_sds_remote_device.
1573 * This is the enter method for the SCI_BASE_REMOTE_DEVICE_STATE_RESETTING it
1574 * sets the resetting state handlers. none
1576 static void scic_sds_remote_device_resetting_state_enter(
1577 struct sci_base_object *object)
1579 struct scic_sds_remote_device *sci_dev = (struct scic_sds_remote_device *)object;
1581 SET_STATE_HANDLER(
1582 sci_dev,
1583 scic_sds_remote_device_state_handler_table,
1584 SCI_BASE_REMOTE_DEVICE_STATE_RESETTING
1587 scic_sds_remote_node_context_suspend(
1588 sci_dev->rnc, SCI_SOFTWARE_SUSPENSION, NULL, NULL);
1593 * @object: This is the struct sci_base_object that is cast into a
1594 * struct scic_sds_remote_device.
1596 * This is the exit method for the SCI_BASE_REMOTE_DEVICE_STATE_RESETTING it
1597 * does nothing. none
1599 static void scic_sds_remote_device_resetting_state_exit(
1600 struct sci_base_object *object)
1602 struct scic_sds_remote_device *sci_dev = (struct scic_sds_remote_device *)object;
1604 scic_sds_remote_node_context_resume(sci_dev->rnc, NULL, NULL);
1609 * @object: This is the struct sci_base_object that is cast into a
1610 * struct scic_sds_remote_device.
1612 * This is the enter method for the SCI_BASE_REMOTE_DEVICE_STATE_FINAL it sets
1613 * the final state handlers. none
1615 static void scic_sds_remote_device_final_state_enter(
1616 struct sci_base_object *object)
1618 struct scic_sds_remote_device *sci_dev = (struct scic_sds_remote_device *)object;
1620 SET_STATE_HANDLER(
1621 sci_dev,
1622 scic_sds_remote_device_state_handler_table,
1623 SCI_BASE_REMOTE_DEVICE_STATE_FINAL
1627 /* --------------------------------------------------------------------------- */
1629 static const struct sci_base_state scic_sds_remote_device_state_table[] = {
1630 [SCI_BASE_REMOTE_DEVICE_STATE_INITIAL] = {
1631 .enter_state = scic_sds_remote_device_initial_state_enter,
1633 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPED] = {
1634 .enter_state = scic_sds_remote_device_stopped_state_enter,
1636 [SCI_BASE_REMOTE_DEVICE_STATE_STARTING] = {
1637 .enter_state = scic_sds_remote_device_starting_state_enter,
1638 .exit_state = scic_sds_remote_device_starting_state_exit
1640 [SCI_BASE_REMOTE_DEVICE_STATE_READY] = {
1641 .enter_state = scic_sds_remote_device_ready_state_enter,
1642 .exit_state = scic_sds_remote_device_ready_state_exit
1644 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPING] = {
1645 .enter_state = scic_sds_remote_device_stopping_state_enter,
1647 [SCI_BASE_REMOTE_DEVICE_STATE_FAILED] = {
1648 .enter_state = scic_sds_remote_device_failed_state_enter,
1650 [SCI_BASE_REMOTE_DEVICE_STATE_RESETTING] = {
1651 .enter_state = scic_sds_remote_device_resetting_state_enter,
1652 .exit_state = scic_sds_remote_device_resetting_state_exit
1654 [SCI_BASE_REMOTE_DEVICE_STATE_FINAL] = {
1655 .enter_state = scic_sds_remote_device_final_state_enter,
1659 void scic_remote_device_construct(struct scic_sds_port *sci_port,
1660 struct scic_sds_remote_device *sci_dev)
1662 sci_dev->owning_port = sci_port;
1663 sci_dev->started_request_count = 0;
1664 sci_dev->rnc = (struct scic_sds_remote_node_context *) &sci_dev[1];
1665 sci_dev->parent.private = NULL;
1667 sci_base_state_machine_construct(
1668 &sci_dev->state_machine,
1669 &sci_dev->parent,
1670 scic_sds_remote_device_state_table,
1671 SCI_BASE_REMOTE_DEVICE_STATE_INITIAL
1674 sci_base_state_machine_start(
1675 &sci_dev->state_machine
1678 scic_sds_remote_node_context_construct(
1679 sci_dev,
1680 sci_dev->rnc,
1681 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
1684 sci_object_set_association(sci_dev->rnc, sci_dev);