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.
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.
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
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
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.
55 #include "intel_sas.h"
58 #include "remote_device.h"
60 #include "scic_controller.h"
61 #include "scic_io_request.h"
63 #include "scic_port.h"
64 #include "scic_sds_controller.h"
65 #include "scic_sds_phy.h"
66 #include "scic_sds_port.h"
67 #include "remote_node_context.h"
68 #include "scic_sds_request.h"
69 #include "sci_environment.h"
71 #include "scu_event_codes.h"
74 enum sci_status
scic_remote_device_stop(
75 struct scic_sds_remote_device
*sci_dev
,
78 return sci_dev
->state_handlers
->stop_handler(sci_dev
);
82 enum sci_status
scic_remote_device_reset(
83 struct scic_sds_remote_device
*sci_dev
)
85 return sci_dev
->state_handlers
->reset_handler(sci_dev
);
89 enum sci_status
scic_remote_device_reset_complete(
90 struct scic_sds_remote_device
*sci_dev
)
92 return sci_dev
->state_handlers
->reset_complete_handler(sci_dev
);
96 enum sas_linkrate
scic_remote_device_get_connection_rate(
97 struct scic_sds_remote_device
*sci_dev
)
99 return sci_dev
->connection_rate
;
103 void scic_remote_device_get_protocols(
104 struct scic_sds_remote_device
*sci_dev
,
105 struct smp_discover_response_protocols
*pr
)
107 pr
->u
.all
= sci_dev
->target_protocols
.u
.all
;
110 #if !defined(DISABLE_ATAPI)
111 bool scic_remote_device_is_atapi(struct scic_sds_remote_device
*sci_dev
)
113 return sci_dev
->is_atapi
;
121 * Remote device timer requirements
123 #define SCIC_SDS_REMOTE_DEVICE_MINIMUM_TIMER_COUNT (0)
124 #define SCIC_SDS_REMOTE_DEVICE_MAXIMUM_TIMER_COUNT (SCI_MAX_REMOTE_DEVICES)
129 * @sci_dev: The remote device for which the suspend is being requested.
131 * This method invokes the remote device suspend state handler. enum sci_status
133 enum sci_status
scic_sds_remote_device_suspend(
134 struct scic_sds_remote_device
*sci_dev
,
137 return sci_dev
->state_handlers
->suspend_handler(sci_dev
, suspend_type
);
142 * @sci_dev: The remote device for which the event handling is being
144 * @frame_index: This is the frame index that is being processed.
146 * This method invokes the frame handler for the remote device state machine
149 enum sci_status
scic_sds_remote_device_frame_handler(
150 struct scic_sds_remote_device
*sci_dev
,
153 return sci_dev
->state_handlers
->frame_handler(sci_dev
, frame_index
);
158 * @sci_dev: The remote device for which the event handling is being
160 * @event_code: This is the event code that is to be processed.
162 * This method invokes the remote device event handler. enum sci_status
164 enum sci_status
scic_sds_remote_device_event_handler(
165 struct scic_sds_remote_device
*sci_dev
,
168 return sci_dev
->state_handlers
->event_handler(sci_dev
, event_code
);
173 * @controller: The controller that is starting the io request.
174 * @sci_dev: The remote device for which the start io handling is being
176 * @io_request: The io request that is being started.
178 * This method invokes the remote device start io handler. enum sci_status
180 enum sci_status
scic_sds_remote_device_start_io(
181 struct scic_sds_controller
*controller
,
182 struct scic_sds_remote_device
*sci_dev
,
183 struct scic_sds_request
*io_request
)
185 return sci_dev
->state_handlers
->start_io_handler(
186 sci_dev
, io_request
);
191 * @controller: The controller that is completing the io request.
192 * @sci_dev: The remote device for which the complete io handling is being
194 * @io_request: The io request that is being completed.
196 * This method invokes the remote device complete io handler. enum sci_status
198 enum sci_status
scic_sds_remote_device_complete_io(
199 struct scic_sds_controller
*controller
,
200 struct scic_sds_remote_device
*sci_dev
,
201 struct scic_sds_request
*io_request
)
203 return sci_dev
->state_handlers
->complete_io_handler(
204 sci_dev
, io_request
);
209 * @controller: The controller that is starting the task request.
210 * @sci_dev: The remote device for which the start task handling is being
212 * @io_request: The task request that is being started.
214 * This method invokes the remote device start task handler. enum sci_status
216 enum sci_status
scic_sds_remote_device_start_task(
217 struct scic_sds_controller
*controller
,
218 struct scic_sds_remote_device
*sci_dev
,
219 struct scic_sds_request
*io_request
)
221 return sci_dev
->state_handlers
->start_task_handler(
222 sci_dev
, io_request
);
227 * @controller: The controller that is completing the task request.
228 * @sci_dev: The remote device for which the complete task handling is
230 * @io_request: The task request that is being completed.
232 * This method invokes the remote device complete task handler. enum sci_status
240 * This method takes the request and bulids an appropriate SCU context for the
241 * request and then requests the controller to post the request. none
243 void scic_sds_remote_device_post_request(
244 struct scic_sds_remote_device
*sci_dev
,
249 context
= scic_sds_remote_device_build_command_context(sci_dev
, request
);
251 scic_sds_controller_post_request(
252 scic_sds_remote_device_get_controller(sci_dev
),
257 #if !defined(DISABLE_ATAPI)
260 * @sci_dev: The device to be checked.
262 * This method check the signature fis of a stp device to decide whether a
263 * device is atapi or not. true if a device is atapi device. False if a device
266 bool scic_sds_remote_device_is_atapi(
267 struct scic_sds_remote_device
*sci_dev
)
269 if (!sci_dev
->target_protocols
.u
.bits
.attached_stp_target
)
271 else if (sci_dev
->is_direct_attached
) {
272 struct scic_sds_phy
*phy
;
273 struct scic_sata_phy_properties properties
;
274 struct sata_fis_reg_d2h
*signature_fis
;
275 phy
= scic_sds_port_get_a_connected_phy(sci_dev
->owning_port
);
276 scic_sata_phy_get_properties(phy
, &properties
);
278 /* decode the signature fis. */
279 signature_fis
= &(properties
.signature_fis
);
281 if ((signature_fis
->sector_count
== 0x01)
282 && (signature_fis
->lba_low
== 0x01)
283 && (signature_fis
->lba_mid
== 0x14)
284 && (signature_fis
->lba_high
== 0xEB)
285 && ((signature_fis
->device
& 0x5F) == 0x00)
287 /* An ATA device supporting the PACKET command set. */
292 /* Expander supported ATAPI device is not currently supported. */
300 * @user_parameter: This is cast to a remote device object.
302 * This method is called once the remote node context is ready to be freed.
303 * The remote device can now report that its stop operation is complete. none
305 static void scic_sds_cb_remote_device_rnc_destruct_complete(
306 void *user_parameter
)
308 struct scic_sds_remote_device
*sci_dev
;
310 sci_dev
= (struct scic_sds_remote_device
*)user_parameter
;
312 BUG_ON(sci_dev
->started_request_count
!= 0);
314 sci_base_state_machine_change_state(&sci_dev
->state_machine
,
315 SCI_BASE_REMOTE_DEVICE_STATE_STOPPED
);
320 * @user_parameter: This is cast to a remote device object.
322 * This method is called once the remote node context has transisitioned to a
323 * ready state. This is the indication that the remote device object can also
324 * transition to ready. none
326 static void scic_sds_remote_device_resume_complete_handler(
327 void *user_parameter
)
329 struct scic_sds_remote_device
*sci_dev
;
331 sci_dev
= (struct scic_sds_remote_device
*)user_parameter
;
334 sci_base_state_machine_get_state(&sci_dev
->state_machine
)
335 != SCI_BASE_REMOTE_DEVICE_STATE_READY
337 sci_base_state_machine_change_state(
338 &sci_dev
->state_machine
,
339 SCI_BASE_REMOTE_DEVICE_STATE_READY
346 * @device: This parameter specifies the device for which the request is being
348 * @request: This parameter specifies the request being started.
349 * @status: This parameter specifies the current start operation status.
351 * This method will perform the STP request start processing common to IO
352 * requests and task requests of all types. none
354 void scic_sds_remote_device_start_request(
355 struct scic_sds_remote_device
*sci_dev
,
356 struct scic_sds_request
*sci_req
,
357 enum sci_status status
)
359 /* We still have a fault in starting the io complete it on the port */
360 if (status
== SCI_SUCCESS
)
361 scic_sds_remote_device_increment_request_count(sci_dev
);
363 sci_dev
->owning_port
->state_handlers
->complete_io_handler(
364 sci_dev
->owning_port
, sci_dev
, sci_req
372 * @request: This parameter specifies the request being continued.
374 * This method will continue to post tc for a STP request. This method usually
375 * serves as a callback when RNC gets resumed during a task management
378 void scic_sds_remote_device_continue_request(void *dev
)
380 struct scic_sds_remote_device
*sci_dev
= dev
;
382 /* we need to check if this request is still valid to continue. */
383 if (sci_dev
->working_request
)
384 scic_controller_continue_io(sci_dev
->working_request
);
388 * This method will terminate all of the IO requests in the controllers IO
389 * request table that were targeted for this device.
390 * @sci_dev: This parameter specifies the remote device for which to
391 * attempt to terminate all requests.
393 * This method returns an indication as to whether all requests were
394 * successfully terminated. If a single request fails to be terminated, then
395 * this method will return the failure.
397 static enum sci_status
scic_sds_remote_device_terminate_requests(
398 struct scic_sds_remote_device
*sci_dev
)
400 enum sci_status status
= SCI_SUCCESS
;
401 enum sci_status terminate_status
= SCI_SUCCESS
;
402 struct scic_sds_request
*sci_req
;
404 u32 request_count
= sci_dev
->started_request_count
;
407 (index
< SCI_MAX_IO_REQUESTS
) && (request_count
> 0);
409 sci_req
= sci_dev
->owning_port
->owning_controller
->io_request_table
[index
];
411 if ((sci_req
!= NULL
) && (sci_req
->target_device
== sci_dev
)) {
412 terminate_status
= scic_controller_terminate_request(
413 sci_dev
->owning_port
->owning_controller
,
418 if (terminate_status
!= SCI_SUCCESS
)
419 status
= terminate_status
;
428 static enum sci_status
429 default_device_handler(struct scic_sds_remote_device
*sci_dev
,
432 dev_warn(scirdev_to_dev(sci_dev
),
433 "%s: in wrong state: %d\n", func
,
434 sci_base_state_machine_get_state(&sci_dev
->state_machine
));
435 return SCI_FAILURE_INVALID_STATE
;
438 enum sci_status
scic_sds_remote_device_default_start_handler(
439 struct scic_sds_remote_device
*sci_dev
)
441 return default_device_handler(sci_dev
, __func__
);
444 static enum sci_status
scic_sds_remote_device_default_stop_handler(
445 struct scic_sds_remote_device
*sci_dev
)
447 return default_device_handler(sci_dev
, __func__
);
450 enum sci_status
scic_sds_remote_device_default_fail_handler(
451 struct scic_sds_remote_device
*sci_dev
)
453 return default_device_handler(sci_dev
, __func__
);
456 enum sci_status
scic_sds_remote_device_default_destruct_handler(
457 struct scic_sds_remote_device
*sci_dev
)
459 return default_device_handler(sci_dev
, __func__
);
462 enum sci_status
scic_sds_remote_device_default_reset_handler(
463 struct scic_sds_remote_device
*sci_dev
)
465 return default_device_handler(sci_dev
, __func__
);
468 enum sci_status
scic_sds_remote_device_default_reset_complete_handler(
469 struct scic_sds_remote_device
*sci_dev
)
471 return default_device_handler(sci_dev
, __func__
);
474 enum sci_status
scic_sds_remote_device_default_suspend_handler(
475 struct scic_sds_remote_device
*sci_dev
, u32 suspend_type
)
477 return default_device_handler(sci_dev
, __func__
);
480 enum sci_status
scic_sds_remote_device_default_resume_handler(
481 struct scic_sds_remote_device
*sci_dev
)
483 return default_device_handler(sci_dev
, __func__
);
488 * @device: The struct scic_sds_remote_device which is then cast into a
489 * struct scic_sds_remote_device.
490 * @event_code: The event code that the struct scic_sds_controller wants the device
493 * This method is the default event handler. It will call the RNC state
494 * machine handler for any RNC events otherwise it will log a warning and
495 * returns a failure. enum sci_status SCI_FAILURE_INVALID_STATE
497 static enum sci_status
scic_sds_remote_device_core_event_handler(
498 struct scic_sds_remote_device
*sci_dev
,
502 enum sci_status status
;
504 switch (scu_get_event_type(event_code
)) {
505 case SCU_EVENT_TYPE_RNC_OPS_MISC
:
506 case SCU_EVENT_TYPE_RNC_SUSPEND_TX
:
507 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX
:
508 status
= scic_sds_remote_node_context_event_handler(&sci_dev
->rnc
, event_code
);
510 case SCU_EVENT_TYPE_PTX_SCHEDULE_EVENT
:
512 if (scu_get_event_code(event_code
) == SCU_EVENT_IT_NEXUS_TIMEOUT
) {
513 status
= SCI_SUCCESS
;
515 /* Suspend the associated RNC */
516 scic_sds_remote_node_context_suspend(&sci_dev
->rnc
,
517 SCI_SOFTWARE_SUSPENSION
,
520 dev_dbg(scirdev_to_dev(sci_dev
),
521 "%s: device: %p event code: %x: %s\n",
522 __func__
, sci_dev
, event_code
,
524 ? "I_T_Nexus_Timeout event"
525 : "I_T_Nexus_Timeout event in wrong state");
529 /* Else, fall through and treat as unhandled... */
532 dev_dbg(scirdev_to_dev(sci_dev
),
533 "%s: device: %p event code: %x: %s\n",
534 __func__
, sci_dev
, event_code
,
537 : "unexpected event in wrong state");
538 status
= SCI_FAILURE_INVALID_STATE
;
546 * @device: The struct scic_sds_remote_device which is then cast into a
547 * struct scic_sds_remote_device.
548 * @event_code: The event code that the struct scic_sds_controller wants the device
551 * This method is the default event handler. It will call the RNC state
552 * machine handler for any RNC events otherwise it will log a warning and
553 * returns a failure. enum sci_status SCI_FAILURE_INVALID_STATE
555 static enum sci_status
scic_sds_remote_device_default_event_handler(
556 struct scic_sds_remote_device
*sci_dev
,
559 return scic_sds_remote_device_core_event_handler(sci_dev
,
566 * @device: The struct scic_sds_remote_device which is then cast into a
567 * struct scic_sds_remote_device.
568 * @frame_index: The frame index for which the struct scic_sds_controller wants this
569 * device object to process.
571 * This method is the default unsolicited frame handler. It logs a warning,
572 * releases the frame and returns a failure. enum sci_status
573 * SCI_FAILURE_INVALID_STATE
575 enum sci_status
scic_sds_remote_device_default_frame_handler(
576 struct scic_sds_remote_device
*sci_dev
,
579 dev_warn(scirdev_to_dev(sci_dev
),
580 "%s: SCIC Remote Device requested to handle frame %x "
581 "while in wrong state %d\n",
584 sci_base_state_machine_get_state(
585 &sci_dev
->state_machine
));
587 /* Return the frame back to the controller */
588 scic_sds_controller_release_frame(
589 scic_sds_remote_device_get_controller(sci_dev
), frame_index
592 return SCI_FAILURE_INVALID_STATE
;
595 enum sci_status
scic_sds_remote_device_default_start_request_handler(
596 struct scic_sds_remote_device
*sci_dev
,
597 struct scic_sds_request
*request
)
599 return default_device_handler(sci_dev
, __func__
);
602 enum sci_status
scic_sds_remote_device_default_complete_request_handler(
603 struct scic_sds_remote_device
*sci_dev
,
604 struct scic_sds_request
*request
)
606 return default_device_handler(sci_dev
, __func__
);
609 enum sci_status
scic_sds_remote_device_default_continue_request_handler(
610 struct scic_sds_remote_device
*sci_dev
,
611 struct scic_sds_request
*request
)
613 return default_device_handler(sci_dev
, __func__
);
618 * @device: The struct scic_sds_remote_device which is then cast into a
619 * struct scic_sds_remote_device.
620 * @frame_index: The frame index for which the struct scic_sds_controller wants this
621 * device object to process.
623 * This method is a general ssp frame handler. In most cases the device object
624 * needs to route the unsolicited frame processing to the io request object.
625 * This method decodes the tag for the io request object and routes the
626 * unsolicited frame to that object. enum sci_status SCI_FAILURE_INVALID_STATE
628 enum sci_status
scic_sds_remote_device_general_frame_handler(
629 struct scic_sds_remote_device
*sci_dev
,
632 enum sci_status result
;
633 struct sci_ssp_frame_header
*frame_header
;
634 struct scic_sds_request
*io_request
;
636 result
= scic_sds_unsolicited_frame_control_get_header(
637 &(scic_sds_remote_device_get_controller(sci_dev
)->uf_control
),
639 (void **)&frame_header
642 if (SCI_SUCCESS
== result
) {
643 io_request
= scic_sds_controller_get_io_request_from_tag(
644 scic_sds_remote_device_get_controller(sci_dev
), frame_header
->tag
);
646 if ((io_request
== NULL
)
647 || (io_request
->target_device
!= sci_dev
)) {
649 * We could not map this tag to a valid IO request
650 * Just toss the frame and continue */
651 scic_sds_controller_release_frame(
652 scic_sds_remote_device_get_controller(sci_dev
), frame_index
655 /* The IO request is now in charge of releasing the frame */
656 result
= io_request
->state_handlers
->frame_handler(
657 io_request
, frame_index
);
666 * @[in]: sci_dev This is the device object that is receiving the event.
667 * @[in]: event_code The event code to process.
669 * This is a common method for handling events reported to the remote device
670 * from the controller object. enum sci_status
672 enum sci_status
scic_sds_remote_device_general_event_handler(
673 struct scic_sds_remote_device
*sci_dev
,
676 return scic_sds_remote_device_core_event_handler(sci_dev
,
682 * *****************************************************************************
683 * * STOPPED STATE HANDLERS
684 * ***************************************************************************** */
690 * This method takes the struct scic_sds_remote_device from a stopped state and
691 * attempts to start it. The RNC buffer for the device is constructed and the
692 * device state machine is transitioned to the
693 * SCIC_BASE_REMOTE_DEVICE_STATE_STARTING. enum sci_status SCI_SUCCESS if there is
694 * an RNC buffer available to construct the remote device.
695 * SCI_FAILURE_INSUFFICIENT_RESOURCES if there is no RNC buffer available in
696 * which to construct the remote device.
698 static enum sci_status
scic_sds_remote_device_stopped_state_start_handler(
699 struct scic_sds_remote_device
*sci_dev
)
701 enum sci_status status
;
703 status
= scic_sds_remote_node_context_resume(&sci_dev
->rnc
,
704 scic_sds_remote_device_resume_complete_handler
, sci_dev
);
706 if (status
== SCI_SUCCESS
)
707 sci_base_state_machine_change_state(&sci_dev
->state_machine
,
708 SCI_BASE_REMOTE_DEVICE_STATE_STARTING
);
713 static enum sci_status
scic_sds_remote_device_stopped_state_stop_handler(
714 struct scic_sds_remote_device
*sci_dev
)
721 * @sci_dev: The struct scic_sds_remote_device which is cast into a
722 * struct scic_sds_remote_device.
724 * This method will destruct a struct scic_sds_remote_device that is in a stopped
725 * state. This is the only state from which a destruct request will succeed.
726 * The RNi for this struct scic_sds_remote_device is returned to the free pool and the
727 * device object transitions to the SCI_BASE_REMOTE_DEVICE_STATE_FINAL.
728 * enum sci_status SCI_SUCCESS
730 static enum sci_status
scic_sds_remote_device_stopped_state_destruct_handler(
731 struct scic_sds_remote_device
*sci_dev
)
733 struct scic_sds_controller
*scic
;
735 scic
= scic_sds_remote_device_get_controller(sci_dev
);
736 scic_sds_controller_free_remote_node_context(scic
, sci_dev
,
737 sci_dev
->rnc
.remote_node_index
);
738 sci_dev
->rnc
.remote_node_index
= SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
;
740 sci_base_state_machine_change_state(&sci_dev
->state_machine
,
741 SCI_BASE_REMOTE_DEVICE_STATE_FINAL
);
747 * *****************************************************************************
748 * * STARTING STATE HANDLERS
749 * ***************************************************************************** */
751 static enum sci_status
scic_sds_remote_device_starting_state_stop_handler(
752 struct scic_sds_remote_device
*sci_dev
)
755 * This device has not yet started so there had better be no IO requests
757 BUG_ON(sci_dev
->started_request_count
!= 0);
760 * Destroy the remote node context
762 scic_sds_remote_node_context_destruct(&sci_dev
->rnc
,
763 scic_sds_cb_remote_device_rnc_destruct_complete
, sci_dev
);
766 * Transition to the stopping state and wait for the remote node to
767 * complete being posted and invalidated.
769 sci_base_state_machine_change_state(&sci_dev
->state_machine
,
770 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
);
775 enum sci_status
scic_sds_remote_device_ready_state_stop_handler(
776 struct scic_sds_remote_device
*sci_dev
)
778 enum sci_status status
= SCI_SUCCESS
;
780 /* Request the parent state machine to transition to the stopping state */
781 sci_base_state_machine_change_state(&sci_dev
->state_machine
,
782 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
);
784 if (sci_dev
->started_request_count
== 0) {
785 scic_sds_remote_node_context_destruct(&sci_dev
->rnc
,
786 scic_sds_cb_remote_device_rnc_destruct_complete
,
789 status
= scic_sds_remote_device_terminate_requests(sci_dev
);
796 * @device: The struct scic_sds_remote_device object which is cast to a
797 * struct scic_sds_remote_device object.
799 * This is the ready state device reset handler enum sci_status
801 enum sci_status
scic_sds_remote_device_ready_state_reset_handler(
802 struct scic_sds_remote_device
*sci_dev
)
804 /* Request the parent state machine to transition to the stopping state */
805 sci_base_state_machine_change_state(&sci_dev
->state_machine
,
806 SCI_BASE_REMOTE_DEVICE_STATE_RESETTING
);
812 * This method will attempt to start a task request for this device object. The
813 * remote device object will issue the start request for the task and if
814 * successful it will start the request for the port object then increment its
815 * own requet count. enum sci_status SCI_SUCCESS if the task request is started for
816 * this device object. SCI_FAILURE_INSUFFICIENT_RESOURCES if the io request
817 * object could not get the resources to start.
819 static enum sci_status
scic_sds_remote_device_ready_state_start_task_handler(
820 struct scic_sds_remote_device
*sci_dev
,
821 struct scic_sds_request
*request
)
823 enum sci_status result
;
825 /* See if the port is in a state where we can start the IO request */
826 result
= scic_sds_port_start_io(
827 scic_sds_remote_device_get_port(sci_dev
), sci_dev
, request
);
829 if (result
== SCI_SUCCESS
) {
830 result
= scic_sds_remote_node_context_start_task(&sci_dev
->rnc
,
832 if (result
== SCI_SUCCESS
)
833 result
= scic_sds_request_start(request
);
835 scic_sds_remote_device_start_request(sci_dev
, request
, result
);
842 * This method will attempt to start an io request for this device object. The
843 * remote device object will issue the start request for the io and if
844 * successful it will start the request for the port object then increment its
845 * own requet count. enum sci_status SCI_SUCCESS if the io request is started for
846 * this device object. SCI_FAILURE_INSUFFICIENT_RESOURCES if the io request
847 * object could not get the resources to start.
849 static enum sci_status
scic_sds_remote_device_ready_state_start_io_handler(
850 struct scic_sds_remote_device
*sci_dev
,
851 struct scic_sds_request
*request
)
853 enum sci_status result
;
855 /* See if the port is in a state where we can start the IO request */
856 result
= scic_sds_port_start_io(
857 scic_sds_remote_device_get_port(sci_dev
), sci_dev
, request
);
859 if (result
== SCI_SUCCESS
) {
860 result
= scic_sds_remote_node_context_start_io(&sci_dev
->rnc
, request
);
861 if (result
== SCI_SUCCESS
)
862 result
= scic_sds_request_start(request
);
864 scic_sds_remote_device_start_request(sci_dev
, request
, result
);
871 * This method will complete the request for the remote device object. The
872 * method will call the completion handler for the request object and if
873 * successful it will complete the request on the port object then decrement
874 * its own started_request_count. enum sci_status
876 static enum sci_status
scic_sds_remote_device_ready_state_complete_request_handler(
877 struct scic_sds_remote_device
*sci_dev
,
878 struct scic_sds_request
*request
)
880 enum sci_status result
;
882 result
= scic_sds_request_complete(request
);
884 if (result
!= SCI_SUCCESS
)
887 /* See if the port is in a state
888 * where we can start the IO request */
889 result
= scic_sds_port_complete_io(
890 scic_sds_remote_device_get_port(sci_dev
),
893 if (result
== SCI_SUCCESS
)
894 scic_sds_remote_device_decrement_request_count(sci_dev
);
900 * *****************************************************************************
901 * * STOPPING STATE HANDLERS
902 * ***************************************************************************** */
906 * @sci_dev: The struct scic_sds_remote_device which is cast into a
907 * struct scic_sds_remote_device.
909 * This method will stop a struct scic_sds_remote_device that is already in the
910 * SCI_BASE_REMOTE_DEVICE_STATE_STOPPING state. This is not considered an error
911 * since we allow a stop request on a device that is alreay stopping or
912 * stopped. enum sci_status SCI_SUCCESS
914 static enum sci_status
scic_sds_remote_device_stopping_state_stop_handler(
915 struct scic_sds_remote_device
*device
)
918 * All requests should have been terminated, but if there is an
919 * attempt to stop a device already in the stopping state, then
920 * try again to terminate. */
921 return scic_sds_remote_device_terminate_requests(device
);
927 * @device: The device object for which the request is completing.
928 * @request: The task request that is being completed.
930 * This method completes requests for this struct scic_sds_remote_device while it is
931 * in the SCI_BASE_REMOTE_DEVICE_STATE_STOPPING state. This method calls the
932 * complete method for the request object and if that is successful the port
933 * object is called to complete the task request. Then the device object itself
934 * completes the task request. If struct scic_sds_remote_device started_request_count
935 * goes to 0 and the invalidate RNC request has completed the device object can
936 * transition to the SCI_BASE_REMOTE_DEVICE_STATE_STOPPED. enum sci_status
938 static enum sci_status
scic_sds_remote_device_stopping_state_complete_request_handler(
939 struct scic_sds_remote_device
*sci_dev
,
940 struct scic_sds_request
*request
)
942 enum sci_status status
= SCI_SUCCESS
;
944 status
= scic_sds_request_complete(request
);
946 if (status
!= SCI_SUCCESS
)
949 status
= scic_sds_port_complete_io(scic_sds_remote_device_get_port(sci_dev
),
951 if (status
!= SCI_SUCCESS
)
954 scic_sds_remote_device_decrement_request_count(sci_dev
);
956 if (scic_sds_remote_device_get_request_count(sci_dev
) == 0)
957 scic_sds_remote_node_context_destruct(&sci_dev
->rnc
,
958 scic_sds_cb_remote_device_rnc_destruct_complete
,
965 * @device: The struct scic_sds_remote_device which is to be cast into a
966 * struct scic_sds_remote_device object.
968 * This method will complete the reset operation when the device is in the
969 * resetting state. enum sci_status
971 static enum sci_status
scic_sds_remote_device_resetting_state_reset_complete_handler(
972 struct scic_sds_remote_device
*sci_dev
)
975 sci_base_state_machine_change_state(
976 &sci_dev
->state_machine
,
977 SCI_BASE_REMOTE_DEVICE_STATE_READY
985 * @device: The struct scic_sds_remote_device which is to be cast into a
986 * struct scic_sds_remote_device object.
988 * This method will stop the remote device while in the resetting state.
991 static enum sci_status
scic_sds_remote_device_resetting_state_stop_handler(
992 struct scic_sds_remote_device
*sci_dev
)
994 sci_base_state_machine_change_state(
995 &sci_dev
->state_machine
,
996 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
1003 * This method completes requests for this struct scic_sds_remote_device while it is
1004 * in the SCI_BASE_REMOTE_DEVICE_STATE_RESETTING state. This method calls the
1005 * complete method for the request object and if that is successful the port
1006 * object is called to complete the task request. Then the device object itself
1007 * completes the task request. enum sci_status
1009 static enum sci_status
scic_sds_remote_device_resetting_state_complete_request_handler(
1010 struct scic_sds_remote_device
*sci_dev
,
1011 struct scic_sds_request
*request
)
1013 enum sci_status status
= SCI_SUCCESS
;
1015 status
= scic_sds_request_complete(request
);
1017 if (status
== SCI_SUCCESS
) {
1018 status
= scic_sds_port_complete_io(
1019 scic_sds_remote_device_get_port(sci_dev
),
1022 if (status
== SCI_SUCCESS
) {
1023 scic_sds_remote_device_decrement_request_count(sci_dev
);
1030 static const struct scic_sds_remote_device_state_handler scic_sds_remote_device_state_handler_table
[] = {
1031 [SCI_BASE_REMOTE_DEVICE_STATE_INITIAL
] = {
1032 .start_handler
= scic_sds_remote_device_default_start_handler
,
1033 .stop_handler
= scic_sds_remote_device_default_stop_handler
,
1034 .fail_handler
= scic_sds_remote_device_default_fail_handler
,
1035 .destruct_handler
= scic_sds_remote_device_default_destruct_handler
,
1036 .reset_handler
= scic_sds_remote_device_default_reset_handler
,
1037 .reset_complete_handler
= scic_sds_remote_device_default_reset_complete_handler
,
1038 .start_io_handler
= scic_sds_remote_device_default_start_request_handler
,
1039 .complete_io_handler
= scic_sds_remote_device_default_complete_request_handler
,
1040 .continue_io_handler
= scic_sds_remote_device_default_continue_request_handler
,
1041 .start_task_handler
= scic_sds_remote_device_default_start_request_handler
,
1042 .complete_task_handler
= scic_sds_remote_device_default_complete_request_handler
,
1043 .suspend_handler
= scic_sds_remote_device_default_suspend_handler
,
1044 .resume_handler
= scic_sds_remote_device_default_resume_handler
,
1045 .event_handler
= scic_sds_remote_device_default_event_handler
,
1046 .frame_handler
= scic_sds_remote_device_default_frame_handler
1048 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPED
] = {
1049 .start_handler
= scic_sds_remote_device_stopped_state_start_handler
,
1050 .stop_handler
= scic_sds_remote_device_stopped_state_stop_handler
,
1051 .fail_handler
= scic_sds_remote_device_default_fail_handler
,
1052 .destruct_handler
= scic_sds_remote_device_stopped_state_destruct_handler
,
1053 .reset_handler
= scic_sds_remote_device_default_reset_handler
,
1054 .reset_complete_handler
= scic_sds_remote_device_default_reset_complete_handler
,
1055 .start_io_handler
= scic_sds_remote_device_default_start_request_handler
,
1056 .complete_io_handler
= scic_sds_remote_device_default_complete_request_handler
,
1057 .continue_io_handler
= scic_sds_remote_device_default_continue_request_handler
,
1058 .start_task_handler
= scic_sds_remote_device_default_start_request_handler
,
1059 .complete_task_handler
= scic_sds_remote_device_default_complete_request_handler
,
1060 .suspend_handler
= scic_sds_remote_device_default_suspend_handler
,
1061 .resume_handler
= scic_sds_remote_device_default_resume_handler
,
1062 .event_handler
= scic_sds_remote_device_default_event_handler
,
1063 .frame_handler
= scic_sds_remote_device_default_frame_handler
1065 [SCI_BASE_REMOTE_DEVICE_STATE_STARTING
] = {
1066 .start_handler
= scic_sds_remote_device_default_start_handler
,
1067 .stop_handler
= scic_sds_remote_device_starting_state_stop_handler
,
1068 .fail_handler
= scic_sds_remote_device_default_fail_handler
,
1069 .destruct_handler
= scic_sds_remote_device_default_destruct_handler
,
1070 .reset_handler
= scic_sds_remote_device_default_reset_handler
,
1071 .reset_complete_handler
= scic_sds_remote_device_default_reset_complete_handler
,
1072 .start_io_handler
= scic_sds_remote_device_default_start_request_handler
,
1073 .complete_io_handler
= scic_sds_remote_device_default_complete_request_handler
,
1074 .continue_io_handler
= scic_sds_remote_device_default_continue_request_handler
,
1075 .start_task_handler
= scic_sds_remote_device_default_start_request_handler
,
1076 .complete_task_handler
= scic_sds_remote_device_default_complete_request_handler
,
1077 .suspend_handler
= scic_sds_remote_device_default_suspend_handler
,
1078 .resume_handler
= scic_sds_remote_device_default_resume_handler
,
1079 .event_handler
= scic_sds_remote_device_general_event_handler
,
1080 .frame_handler
= scic_sds_remote_device_default_frame_handler
1082 [SCI_BASE_REMOTE_DEVICE_STATE_READY
] = {
1083 .start_handler
= scic_sds_remote_device_default_start_handler
,
1084 .stop_handler
= scic_sds_remote_device_ready_state_stop_handler
,
1085 .fail_handler
= scic_sds_remote_device_default_fail_handler
,
1086 .destruct_handler
= scic_sds_remote_device_default_destruct_handler
,
1087 .reset_handler
= scic_sds_remote_device_ready_state_reset_handler
,
1088 .reset_complete_handler
= scic_sds_remote_device_default_reset_complete_handler
,
1089 .start_io_handler
= scic_sds_remote_device_ready_state_start_io_handler
,
1090 .complete_io_handler
= scic_sds_remote_device_ready_state_complete_request_handler
,
1091 .continue_io_handler
= scic_sds_remote_device_default_continue_request_handler
,
1092 .start_task_handler
= scic_sds_remote_device_ready_state_start_task_handler
,
1093 .complete_task_handler
= scic_sds_remote_device_ready_state_complete_request_handler
,
1094 .suspend_handler
= scic_sds_remote_device_default_suspend_handler
,
1095 .resume_handler
= scic_sds_remote_device_default_resume_handler
,
1096 .event_handler
= scic_sds_remote_device_general_event_handler
,
1097 .frame_handler
= scic_sds_remote_device_general_frame_handler
,
1099 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
] = {
1100 .start_handler
= scic_sds_remote_device_default_start_handler
,
1101 .stop_handler
= scic_sds_remote_device_stopping_state_stop_handler
,
1102 .fail_handler
= scic_sds_remote_device_default_fail_handler
,
1103 .destruct_handler
= scic_sds_remote_device_default_destruct_handler
,
1104 .reset_handler
= scic_sds_remote_device_default_reset_handler
,
1105 .reset_complete_handler
= scic_sds_remote_device_default_reset_complete_handler
,
1106 .start_io_handler
= scic_sds_remote_device_default_start_request_handler
,
1107 .complete_io_handler
= scic_sds_remote_device_stopping_state_complete_request_handler
,
1108 .continue_io_handler
= scic_sds_remote_device_default_continue_request_handler
,
1109 .start_task_handler
= scic_sds_remote_device_default_start_request_handler
,
1110 .complete_task_handler
= scic_sds_remote_device_stopping_state_complete_request_handler
,
1111 .suspend_handler
= scic_sds_remote_device_default_suspend_handler
,
1112 .resume_handler
= scic_sds_remote_device_default_resume_handler
,
1113 .event_handler
= scic_sds_remote_device_general_event_handler
,
1114 .frame_handler
= scic_sds_remote_device_general_frame_handler
1116 [SCI_BASE_REMOTE_DEVICE_STATE_FAILED
] = {
1117 .start_handler
= scic_sds_remote_device_default_start_handler
,
1118 .stop_handler
= scic_sds_remote_device_default_stop_handler
,
1119 .fail_handler
= scic_sds_remote_device_default_fail_handler
,
1120 .destruct_handler
= scic_sds_remote_device_default_destruct_handler
,
1121 .reset_handler
= scic_sds_remote_device_default_reset_handler
,
1122 .reset_complete_handler
= scic_sds_remote_device_default_reset_complete_handler
,
1123 .start_io_handler
= scic_sds_remote_device_default_start_request_handler
,
1124 .complete_io_handler
= scic_sds_remote_device_default_complete_request_handler
,
1125 .continue_io_handler
= scic_sds_remote_device_default_continue_request_handler
,
1126 .start_task_handler
= scic_sds_remote_device_default_start_request_handler
,
1127 .complete_task_handler
= scic_sds_remote_device_default_complete_request_handler
,
1128 .suspend_handler
= scic_sds_remote_device_default_suspend_handler
,
1129 .resume_handler
= scic_sds_remote_device_default_resume_handler
,
1130 .event_handler
= scic_sds_remote_device_default_event_handler
,
1131 .frame_handler
= scic_sds_remote_device_general_frame_handler
1133 [SCI_BASE_REMOTE_DEVICE_STATE_RESETTING
] = {
1134 .start_handler
= scic_sds_remote_device_default_start_handler
,
1135 .stop_handler
= scic_sds_remote_device_resetting_state_stop_handler
,
1136 .fail_handler
= scic_sds_remote_device_default_fail_handler
,
1137 .destruct_handler
= scic_sds_remote_device_default_destruct_handler
,
1138 .reset_handler
= scic_sds_remote_device_default_reset_handler
,
1139 .reset_complete_handler
= scic_sds_remote_device_resetting_state_reset_complete_handler
,
1140 .start_io_handler
= scic_sds_remote_device_default_start_request_handler
,
1141 .complete_io_handler
= scic_sds_remote_device_resetting_state_complete_request_handler
,
1142 .continue_io_handler
= scic_sds_remote_device_default_continue_request_handler
,
1143 .start_task_handler
= scic_sds_remote_device_default_start_request_handler
,
1144 .complete_task_handler
= scic_sds_remote_device_resetting_state_complete_request_handler
,
1145 .suspend_handler
= scic_sds_remote_device_default_suspend_handler
,
1146 .resume_handler
= scic_sds_remote_device_default_resume_handler
,
1147 .event_handler
= scic_sds_remote_device_default_event_handler
,
1148 .frame_handler
= scic_sds_remote_device_general_frame_handler
1150 [SCI_BASE_REMOTE_DEVICE_STATE_FINAL
] = {
1151 .start_handler
= scic_sds_remote_device_default_start_handler
,
1152 .stop_handler
= scic_sds_remote_device_default_stop_handler
,
1153 .fail_handler
= scic_sds_remote_device_default_fail_handler
,
1154 .destruct_handler
= scic_sds_remote_device_default_destruct_handler
,
1155 .reset_handler
= scic_sds_remote_device_default_reset_handler
,
1156 .reset_complete_handler
= scic_sds_remote_device_default_reset_complete_handler
,
1157 .start_io_handler
= scic_sds_remote_device_default_start_request_handler
,
1158 .complete_io_handler
= scic_sds_remote_device_default_complete_request_handler
,
1159 .continue_io_handler
= scic_sds_remote_device_default_continue_request_handler
,
1160 .start_task_handler
= scic_sds_remote_device_default_start_request_handler
,
1161 .complete_task_handler
= scic_sds_remote_device_default_complete_request_handler
,
1162 .suspend_handler
= scic_sds_remote_device_default_suspend_handler
,
1163 .resume_handler
= scic_sds_remote_device_default_resume_handler
,
1164 .event_handler
= scic_sds_remote_device_default_event_handler
,
1165 .frame_handler
= scic_sds_remote_device_default_frame_handler
1169 static void scic_sds_remote_device_initial_state_enter(
1170 struct sci_base_object
*object
)
1172 struct scic_sds_remote_device
*sci_dev
= (struct scic_sds_remote_device
*)object
;
1174 sci_dev
= container_of(object
, typeof(*sci_dev
), parent
);
1175 SET_STATE_HANDLER(sci_dev
, scic_sds_remote_device_state_handler_table
,
1176 SCI_BASE_REMOTE_DEVICE_STATE_INITIAL
);
1178 /* Initial state is a transitional state to the stopped state */
1179 sci_base_state_machine_change_state(&sci_dev
->state_machine
,
1180 SCI_BASE_REMOTE_DEVICE_STATE_STOPPED
);
1184 * isci_remote_device_change_state() - This function gets the status of the
1185 * remote_device object.
1186 * @isci_device: This parameter points to the isci_remote_device object
1188 * status of the object as a isci_status enum.
1190 void isci_remote_device_change_state(
1191 struct isci_remote_device
*isci_device
,
1192 enum isci_status status
)
1194 unsigned long flags
;
1196 spin_lock_irqsave(&isci_device
->state_lock
, flags
);
1197 isci_device
->status
= status
;
1198 spin_unlock_irqrestore(&isci_device
->state_lock
, flags
);
1202 * scic_remote_device_destruct() - free remote node context and destruct
1203 * @remote_device: This parameter specifies the remote device to be destructed.
1205 * Remote device objects are a limited resource. As such, they must be
1206 * protected. Thus calls to construct and destruct are mutually exclusive and
1207 * non-reentrant. The return value shall indicate if the device was
1208 * successfully destructed or if some failure occurred. enum sci_status This value
1209 * is returned if the device is successfully destructed.
1210 * SCI_FAILURE_INVALID_REMOTE_DEVICE This value is returned if the supplied
1211 * device isn't valid (e.g. it's already been destoryed, the handle isn't
1214 static enum sci_status
scic_remote_device_destruct(struct scic_sds_remote_device
*sci_dev
)
1216 return sci_dev
->state_handlers
->destruct_handler(sci_dev
);
1220 * isci_remote_device_deconstruct() - This function frees an isci_remote_device.
1221 * @ihost: This parameter specifies the isci host object.
1222 * @idev: This parameter specifies the remote device to be freed.
1225 static void isci_remote_device_deconstruct(struct isci_host
*ihost
, struct isci_remote_device
*idev
)
1227 dev_dbg(&ihost
->pdev
->dev
,
1228 "%s: isci_device = %p\n", __func__
, idev
);
1230 /* There should not be any outstanding io's. All paths to
1231 * here should go through isci_remote_device_nuke_requests.
1232 * If we hit this condition, we will need a way to complete
1233 * io requests in process */
1234 while (!list_empty(&idev
->reqs_in_process
)) {
1236 dev_err(&ihost
->pdev
->dev
,
1237 "%s: ** request list not empty! **\n", __func__
);
1241 scic_remote_device_destruct(&idev
->sci
);
1242 idev
->domain_dev
->lldd_dev
= NULL
;
1243 idev
->domain_dev
= NULL
;
1244 idev
->isci_port
= NULL
;
1245 list_del_init(&idev
->node
);
1247 clear_bit(IDEV_START_PENDING
, &idev
->flags
);
1248 clear_bit(IDEV_STOP_PENDING
, &idev
->flags
);
1249 wake_up(&ihost
->eventq
);
1253 * isci_remote_device_stop_complete() - This function is called by the scic
1254 * when the remote device stop has completed. We mark the isci device as not
1255 * ready and remove the isci remote device.
1256 * @ihost: This parameter specifies the isci host object.
1257 * @idev: This parameter specifies the remote device.
1258 * @status: This parameter specifies status of the completion.
1261 static void isci_remote_device_stop_complete(struct isci_host
*ihost
,
1262 struct isci_remote_device
*idev
)
1264 dev_dbg(&ihost
->pdev
->dev
, "%s: complete idev = %p\n", __func__
, idev
);
1266 isci_remote_device_change_state(idev
, isci_stopped
);
1268 /* after stop, we can tear down resources. */
1269 isci_remote_device_deconstruct(ihost
, idev
);
1272 static void scic_sds_remote_device_stopped_state_enter(
1273 struct sci_base_object
*object
)
1275 struct scic_sds_remote_device
*sci_dev
;
1276 struct scic_sds_controller
*scic
;
1277 struct isci_remote_device
*idev
;
1278 struct isci_host
*ihost
;
1281 sci_dev
= container_of(object
, typeof(*sci_dev
), parent
);
1282 scic
= scic_sds_remote_device_get_controller(sci_dev
);
1283 ihost
= sci_object_get_association(scic
);
1284 idev
= sci_object_get_association(sci_dev
);
1286 SET_STATE_HANDLER(sci_dev
, scic_sds_remote_device_state_handler_table
,
1287 SCI_BASE_REMOTE_DEVICE_STATE_STOPPED
);
1289 /* If we are entering from the stopping state let the SCI User know that
1290 * the stop operation has completed.
1292 prev_state
= sci_dev
->state_machine
.previous_state_id
;
1293 if (prev_state
== SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
)
1294 isci_remote_device_stop_complete(ihost
, idev
);
1296 scic_sds_controller_remote_device_stopped(scic
, sci_dev
);
1299 static void scic_sds_remote_device_starting_state_enter(struct sci_base_object
*object
)
1301 struct scic_sds_remote_device
*sci_dev
= container_of(object
, typeof(*sci_dev
),
1303 struct scic_sds_controller
*scic
= scic_sds_remote_device_get_controller(sci_dev
);
1304 struct isci_host
*ihost
= sci_object_get_association(scic
);
1305 struct isci_remote_device
*idev
= sci_object_get_association(sci_dev
);
1307 SET_STATE_HANDLER(sci_dev
, scic_sds_remote_device_state_handler_table
,
1308 SCI_BASE_REMOTE_DEVICE_STATE_STARTING
);
1310 isci_remote_device_not_ready(ihost
, idev
,
1311 SCIC_REMOTE_DEVICE_NOT_READY_START_REQUESTED
);
1314 static void scic_sds_remote_device_ready_state_enter(struct sci_base_object
*object
)
1316 struct scic_sds_remote_device
*sci_dev
= container_of(object
, typeof(*sci_dev
),
1318 struct scic_sds_controller
*scic
= scic_sds_remote_device_get_controller(sci_dev
);
1319 struct isci_host
*ihost
= sci_object_get_association(scic
);
1320 struct isci_remote_device
*idev
= sci_object_get_association(sci_dev
);
1322 SET_STATE_HANDLER(sci_dev
,
1323 scic_sds_remote_device_state_handler_table
,
1324 SCI_BASE_REMOTE_DEVICE_STATE_READY
);
1326 scic
->remote_device_sequence
[sci_dev
->rnc
.remote_node_index
]++;
1328 if (sci_dev
->has_ready_substate_machine
)
1329 sci_base_state_machine_start(&sci_dev
->ready_substate_machine
);
1331 isci_remote_device_ready(ihost
, idev
);
1334 static void scic_sds_remote_device_ready_state_exit(
1335 struct sci_base_object
*object
)
1337 struct scic_sds_remote_device
*sci_dev
= container_of(object
, typeof(*sci_dev
),
1339 if (sci_dev
->has_ready_substate_machine
)
1340 sci_base_state_machine_stop(&sci_dev
->ready_substate_machine
);
1342 struct scic_sds_controller
*scic
= scic_sds_remote_device_get_controller(sci_dev
);
1343 struct isci_host
*ihost
= sci_object_get_association(scic
);
1344 struct isci_remote_device
*idev
= sci_object_get_association(sci_dev
);
1346 isci_remote_device_not_ready(ihost
, idev
,
1347 SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED
);
1351 static void scic_sds_remote_device_stopping_state_enter(
1352 struct sci_base_object
*object
)
1354 struct scic_sds_remote_device
*sci_dev
= (struct scic_sds_remote_device
*)object
;
1358 scic_sds_remote_device_state_handler_table
,
1359 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
1363 static void scic_sds_remote_device_failed_state_enter(
1364 struct sci_base_object
*object
)
1366 struct scic_sds_remote_device
*sci_dev
= (struct scic_sds_remote_device
*)object
;
1370 scic_sds_remote_device_state_handler_table
,
1371 SCI_BASE_REMOTE_DEVICE_STATE_FAILED
1375 static void scic_sds_remote_device_resetting_state_enter(
1376 struct sci_base_object
*object
)
1378 struct scic_sds_remote_device
*sci_dev
= (struct scic_sds_remote_device
*)object
;
1382 scic_sds_remote_device_state_handler_table
,
1383 SCI_BASE_REMOTE_DEVICE_STATE_RESETTING
1386 scic_sds_remote_node_context_suspend(
1387 &sci_dev
->rnc
, SCI_SOFTWARE_SUSPENSION
, NULL
, NULL
);
1390 static void scic_sds_remote_device_resetting_state_exit(
1391 struct sci_base_object
*object
)
1393 struct scic_sds_remote_device
*sci_dev
= (struct scic_sds_remote_device
*)object
;
1395 scic_sds_remote_node_context_resume(&sci_dev
->rnc
, NULL
, NULL
);
1398 static void scic_sds_remote_device_final_state_enter(
1399 struct sci_base_object
*object
)
1401 struct scic_sds_remote_device
*sci_dev
= (struct scic_sds_remote_device
*)object
;
1405 scic_sds_remote_device_state_handler_table
,
1406 SCI_BASE_REMOTE_DEVICE_STATE_FINAL
1411 static const struct sci_base_state scic_sds_remote_device_state_table
[] = {
1412 [SCI_BASE_REMOTE_DEVICE_STATE_INITIAL
] = {
1413 .enter_state
= scic_sds_remote_device_initial_state_enter
,
1415 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPED
] = {
1416 .enter_state
= scic_sds_remote_device_stopped_state_enter
,
1418 [SCI_BASE_REMOTE_DEVICE_STATE_STARTING
] = {
1419 .enter_state
= scic_sds_remote_device_starting_state_enter
,
1421 [SCI_BASE_REMOTE_DEVICE_STATE_READY
] = {
1422 .enter_state
= scic_sds_remote_device_ready_state_enter
,
1423 .exit_state
= scic_sds_remote_device_ready_state_exit
1425 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
] = {
1426 .enter_state
= scic_sds_remote_device_stopping_state_enter
,
1428 [SCI_BASE_REMOTE_DEVICE_STATE_FAILED
] = {
1429 .enter_state
= scic_sds_remote_device_failed_state_enter
,
1431 [SCI_BASE_REMOTE_DEVICE_STATE_RESETTING
] = {
1432 .enter_state
= scic_sds_remote_device_resetting_state_enter
,
1433 .exit_state
= scic_sds_remote_device_resetting_state_exit
1435 [SCI_BASE_REMOTE_DEVICE_STATE_FINAL
] = {
1436 .enter_state
= scic_sds_remote_device_final_state_enter
,
1441 * scic_remote_device_construct() - common construction
1442 * @sci_port: SAS/SATA port through which this device is accessed.
1443 * @sci_dev: remote device to construct
1445 * This routine just performs benign initialization and does not
1446 * allocate the remote_node_context which is left to
1447 * scic_remote_device_[de]a_construct(). scic_remote_device_destruct()
1448 * frees the remote_node_context(s) for the device.
1450 static void scic_remote_device_construct(struct scic_sds_port
*sci_port
,
1451 struct scic_sds_remote_device
*sci_dev
)
1453 sci_dev
->owning_port
= sci_port
;
1454 sci_dev
->started_request_count
= 0;
1455 sci_dev
->parent
.private = NULL
;
1457 sci_base_state_machine_construct(
1458 &sci_dev
->state_machine
,
1460 scic_sds_remote_device_state_table
,
1461 SCI_BASE_REMOTE_DEVICE_STATE_INITIAL
1464 sci_base_state_machine_start(
1465 &sci_dev
->state_machine
1468 scic_sds_remote_node_context_construct(&sci_dev
->rnc
,
1469 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
);
1471 sci_object_set_association(&sci_dev
->rnc
, sci_dev
);
1475 * scic_remote_device_da_construct() - construct direct attached device.
1477 * The information (e.g. IAF, Signature FIS, etc.) necessary to build
1478 * the device is known to the SCI Core since it is contained in the
1479 * scic_phy object. Remote node context(s) is/are a global resource
1480 * allocated by this routine, freed by scic_remote_device_destruct().
1483 * SCI_FAILURE_DEVICE_EXISTS - device has already been constructed.
1484 * SCI_FAILURE_UNSUPPORTED_PROTOCOL - e.g. sas device attached to
1485 * sata-only controller instance.
1486 * SCI_FAILURE_INSUFFICIENT_RESOURCES - remote node contexts exhausted.
1488 static enum sci_status
scic_remote_device_da_construct(struct scic_sds_port
*sci_port
,
1489 struct scic_sds_remote_device
*sci_dev
)
1491 enum sci_status status
;
1492 u16 remote_node_index
;
1493 struct sci_sas_identify_address_frame_protocols protocols
;
1495 scic_remote_device_construct(sci_port
, sci_dev
);
1498 * This information is request to determine how many remote node context
1499 * entries will be needed to store the remote node.
1501 scic_sds_port_get_attached_protocols(sci_dev
->owning_port
, &protocols
);
1502 sci_dev
->target_protocols
.u
.all
= protocols
.u
.all
;
1503 sci_dev
->is_direct_attached
= true;
1504 #if !defined(DISABLE_ATAPI)
1505 sci_dev
->is_atapi
= scic_sds_remote_device_is_atapi(sci_dev
);
1508 status
= scic_sds_controller_allocate_remote_node_context(
1509 sci_dev
->owning_port
->owning_controller
,
1511 &remote_node_index
);
1513 if (status
== SCI_SUCCESS
) {
1514 sci_dev
->rnc
.remote_node_index
= remote_node_index
;
1516 scic_sds_port_get_attached_sas_address(
1517 sci_dev
->owning_port
, &sci_dev
->device_address
);
1519 if (sci_dev
->target_protocols
.u
.bits
.attached_ssp_target
) {
1520 sci_dev
->has_ready_substate_machine
= false;
1521 } else if (sci_dev
->target_protocols
.u
.bits
.attached_stp_target
) {
1522 sci_dev
->has_ready_substate_machine
= true;
1524 sci_base_state_machine_construct(
1525 &sci_dev
->ready_substate_machine
,
1527 scic_sds_stp_remote_device_ready_substate_table
,
1528 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE
);
1529 } else if (sci_dev
->target_protocols
.u
.bits
.attached_smp_target
) {
1530 sci_dev
->has_ready_substate_machine
= true;
1532 /* add the SMP ready substate machine construction here */
1533 sci_base_state_machine_construct(
1534 &sci_dev
->ready_substate_machine
,
1536 scic_sds_smp_remote_device_ready_substate_table
,
1537 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE
);
1540 sci_dev
->connection_rate
= scic_sds_port_get_max_allowed_speed(
1541 sci_dev
->owning_port
);
1543 /* / @todo Should I assign the port width by reading all of the phys on the port? */
1544 sci_dev
->device_port_width
= 1;
1550 static void scic_sds_remote_device_get_info_from_smp_discover_response(
1551 struct scic_sds_remote_device
*sci_dev
,
1552 struct smp_response_discover
*discover_response
)
1554 /* decode discover_response to set sas_address to sci_dev. */
1555 sci_dev
->device_address
.high
=
1556 discover_response
->attached_sas_address
.high
;
1558 sci_dev
->device_address
.low
=
1559 discover_response
->attached_sas_address
.low
;
1561 sci_dev
->target_protocols
.u
.all
= discover_response
->protocols
.u
.all
;
1565 * scic_remote_device_ea_construct() - construct expander attached device
1566 * @discover_response: data to build remote device
1568 * Remote node context(s) is/are a global resource allocated by this
1569 * routine, freed by scic_remote_device_destruct().
1572 * SCI_FAILURE_DEVICE_EXISTS - device has already been constructed.
1573 * SCI_FAILURE_UNSUPPORTED_PROTOCOL - e.g. sas device attached to
1574 * sata-only controller instance.
1575 * SCI_FAILURE_INSUFFICIENT_RESOURCES - remote node contexts exhausted.
1577 static enum sci_status
scic_remote_device_ea_construct(struct scic_sds_port
*sci_port
,
1578 struct scic_sds_remote_device
*sci_dev
,
1579 struct smp_response_discover
*discover_response
)
1581 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1582 enum sci_status status
;
1584 scic_remote_device_construct(sci_port
, sci_dev
);
1586 scic_sds_remote_device_get_info_from_smp_discover_response(
1587 sci_dev
, discover_response
);
1589 status
= scic_sds_controller_allocate_remote_node_context(
1590 scic
, sci_dev
, &sci_dev
->rnc
.remote_node_index
);
1592 if (status
== SCI_SUCCESS
) {
1593 if (sci_dev
->target_protocols
.u
.bits
.attached_ssp_target
) {
1594 sci_dev
->has_ready_substate_machine
= false;
1595 } else if (sci_dev
->target_protocols
.u
.bits
.attached_smp_target
) {
1596 sci_dev
->has_ready_substate_machine
= true;
1598 /* add the SMP ready substate machine construction here */
1599 sci_base_state_machine_construct(
1600 &sci_dev
->ready_substate_machine
,
1602 scic_sds_smp_remote_device_ready_substate_table
,
1603 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE
);
1604 } else if (sci_dev
->target_protocols
.u
.bits
.attached_stp_target
) {
1605 sci_dev
->has_ready_substate_machine
= true;
1607 sci_base_state_machine_construct(
1608 &sci_dev
->ready_substate_machine
,
1610 scic_sds_stp_remote_device_ready_substate_table
,
1611 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE
);
1615 * For SAS-2 the physical link rate is actually a logical link
1616 * rate that incorporates multiplexing. The SCU doesn't
1617 * incorporate multiplexing and for the purposes of the
1618 * connection the logical link rate is that same as the
1619 * physical. Furthermore, the SAS-2 and SAS-1.1 fields overlay
1620 * one another, so this code works for both situations. */
1621 sci_dev
->connection_rate
= min_t(u16
,
1622 scic_sds_port_get_max_allowed_speed(sci_port
),
1623 discover_response
->u2
.sas1_1
.negotiated_physical_link_rate
);
1625 /* / @todo Should I assign the port width by reading all of the phys on the port? */
1626 sci_dev
->device_port_width
= 1;
1633 * scic_remote_device_start() - This method will start the supplied remote
1634 * device. This method enables normal IO requests to flow through to the
1636 * @remote_device: This parameter specifies the device to be started.
1637 * @timeout: This parameter specifies the number of milliseconds in which the
1638 * start operation should complete.
1640 * An indication of whether the device was successfully started. SCI_SUCCESS
1641 * This value is returned if the device was successfully started.
1642 * SCI_FAILURE_INVALID_PHY This value is returned if the user attempts to start
1643 * the device when there have been no phys added to it.
1645 static enum sci_status
scic_remote_device_start(struct scic_sds_remote_device
*sci_dev
,
1648 return sci_dev
->state_handlers
->start_handler(sci_dev
);
1652 * isci_remote_device_construct() - This function calls the scic remote device
1653 * construct and start functions, it waits on the remote device start
1655 * @port: This parameter specifies the isci port with the remote device.
1656 * @isci_device: This parameter specifies the isci remote device
1658 * status from the scic calls, the caller to this function should clean up
1659 * resources as appropriate.
1661 static enum sci_status
isci_remote_device_construct(
1662 struct isci_port
*port
,
1663 struct isci_remote_device
*isci_device
)
1665 enum sci_status status
= SCI_SUCCESS
;
1667 if (isci_device
->domain_dev
->parent
&&
1668 (isci_device
->domain_dev
->parent
->dev_type
== EDGE_DEV
)) {
1671 /* struct smp_response_discover discover_response; */
1672 struct discover_resp discover_response
;
1673 struct domain_device
*parent
=
1674 isci_device
->domain_dev
->parent
;
1676 struct expander_device
*parent_ex
= &parent
->ex_dev
;
1678 for (i
= 0; i
< parent_ex
->num_phys
; i
++) {
1680 struct ex_phy
*phy
= &parent_ex
->ex_phy
[i
];
1682 if ((phy
->phy_state
== PHY_VACANT
) ||
1683 (phy
->phy_state
== PHY_NOT_PRESENT
))
1686 if (SAS_ADDR(phy
->attached_sas_addr
)
1687 == SAS_ADDR(isci_device
->domain_dev
->sas_addr
)) {
1689 discover_response
.attached_dev_type
1690 = phy
->attached_dev_type
;
1691 discover_response
.linkrate
1693 discover_response
.attached_sata_host
1694 = phy
->attached_sata_host
;
1695 discover_response
.attached_sata_dev
1696 = phy
->attached_sata_dev
;
1697 discover_response
.attached_sata_ps
1698 = phy
->attached_sata_ps
;
1699 discover_response
.iproto
1700 = phy
->attached_iproto
>> 1;
1701 discover_response
.tproto
1702 = phy
->attached_tproto
>> 1;
1704 discover_response
.attached_sas_addr
,
1705 phy
->attached_sas_addr
,
1708 discover_response
.attached_phy_id
1709 = phy
->attached_phy_id
;
1710 discover_response
.change_count
1711 = phy
->phy_change_count
;
1712 discover_response
.routing_attr
1713 = phy
->routing_attr
;
1714 discover_response
.hmin_linkrate
1715 = phy
->phy
->minimum_linkrate_hw
;
1716 discover_response
.hmax_linkrate
1717 = phy
->phy
->maximum_linkrate_hw
;
1718 discover_response
.pmin_linkrate
1719 = phy
->phy
->minimum_linkrate
;
1720 discover_response
.pmax_linkrate
1721 = phy
->phy
->maximum_linkrate
;
1726 dev_dbg(&port
->isci_host
->pdev
->dev
,
1727 "%s: parent->dev_type = EDGE_DEV\n",
1730 status
= scic_remote_device_ea_construct(port
->sci_port_handle
,
1732 (struct smp_response_discover
*)&discover_response
);
1735 status
= scic_remote_device_da_construct(port
->sci_port_handle
,
1739 if (status
!= SCI_SUCCESS
) {
1740 dev_dbg(&port
->isci_host
->pdev
->dev
,
1741 "%s: scic_remote_device_da_construct failed - "
1742 "isci_device = %p\n",
1749 /* XXX will be killed with sci_base_object removal */
1750 sci_object_set_association(&isci_device
->sci
, isci_device
);
1752 /* start the device. */
1753 status
= scic_remote_device_start(&isci_device
->sci
,
1754 ISCI_REMOTE_DEVICE_START_TIMEOUT
);
1756 if (status
!= SCI_SUCCESS
) {
1757 dev_warn(&port
->isci_host
->pdev
->dev
,
1758 "%s: scic_remote_device_start failed\n",
1766 void isci_remote_device_nuke_requests(struct isci_host
*ihost
, struct isci_remote_device
*idev
)
1768 DECLARE_COMPLETION_ONSTACK(aborted_task_completion
);
1770 dev_dbg(&ihost
->pdev
->dev
,
1771 "%s: idev = %p\n", __func__
, idev
);
1773 /* Cleanup all requests pending for this device. */
1774 isci_terminate_pending_requests(ihost
, idev
, terminating
);
1776 dev_dbg(&ihost
->pdev
->dev
,
1777 "%s: idev = %p, done\n", __func__
, idev
);
1781 * This function builds the isci_remote_device when a libsas dev_found message
1783 * @isci_host: This parameter specifies the isci host object.
1784 * @port: This parameter specifies the isci_port conected to this device.
1786 * pointer to new isci_remote_device.
1788 static struct isci_remote_device
*
1789 isci_remote_device_alloc(struct isci_host
*ihost
, struct isci_port
*iport
)
1791 struct isci_remote_device
*idev
;
1794 for (i
= 0; i
< SCI_MAX_REMOTE_DEVICES
; i
++) {
1795 idev
= &ihost
->devices
[i
];
1796 if (!test_and_set_bit(IDEV_ALLOCATED
, &idev
->flags
))
1800 if (i
>= SCI_MAX_REMOTE_DEVICES
) {
1801 dev_warn(&ihost
->pdev
->dev
, "%s: failed\n", __func__
);
1805 if (WARN_ONCE(!list_empty(&idev
->reqs_in_process
), "found requests in process\n"))
1808 if (WARN_ONCE(!list_empty(&idev
->node
), "found non-idle remote device\n"))
1811 isci_remote_device_change_state(idev
, isci_freed
);
1817 * isci_remote_device_ready() - This function is called by the scic when the
1818 * remote device is ready. We mark the isci device as ready and signal the
1820 * @ihost: our valid isci_host
1821 * @idev: remote device
1824 void isci_remote_device_ready(struct isci_host
*ihost
, struct isci_remote_device
*idev
)
1826 dev_dbg(&ihost
->pdev
->dev
,
1827 "%s: idev = %p\n", __func__
, idev
);
1829 isci_remote_device_change_state(idev
, isci_ready_for_io
);
1830 if (test_and_clear_bit(IDEV_START_PENDING
, &idev
->flags
))
1831 wake_up(&ihost
->eventq
);
1835 * isci_remote_device_not_ready() - This function is called by the scic when
1836 * the remote device is not ready. We mark the isci device as ready (not
1837 * "ready_for_io") and signal the waiting proccess.
1838 * @isci_host: This parameter specifies the isci host object.
1839 * @isci_device: This parameter specifies the remote device
1842 void isci_remote_device_not_ready(struct isci_host
*ihost
,
1843 struct isci_remote_device
*idev
, u32 reason
)
1845 dev_dbg(&ihost
->pdev
->dev
,
1846 "%s: isci_device = %p\n", __func__
, idev
);
1848 if (reason
== SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED
)
1849 isci_remote_device_change_state(idev
, isci_stopping
);
1851 /* device ready is actually a "not ready for io" state. */
1852 isci_remote_device_change_state(idev
, isci_ready
);
1856 * isci_remote_device_stop() - This function is called internally to stop the
1858 * @isci_host: This parameter specifies the isci host object.
1859 * @isci_device: This parameter specifies the remote device.
1861 * The status of the scic request to stop.
1863 enum sci_status
isci_remote_device_stop(struct isci_host
*ihost
, struct isci_remote_device
*idev
)
1865 enum sci_status status
;
1866 unsigned long flags
;
1868 dev_dbg(&ihost
->pdev
->dev
,
1869 "%s: isci_device = %p\n", __func__
, idev
);
1871 isci_remote_device_change_state(idev
, isci_stopping
);
1873 /* Kill all outstanding requests. */
1874 isci_remote_device_nuke_requests(ihost
, idev
);
1876 set_bit(IDEV_STOP_PENDING
, &idev
->flags
);
1878 spin_lock_irqsave(&ihost
->scic_lock
, flags
);
1879 status
= scic_remote_device_stop(&idev
->sci
, 50);
1880 spin_unlock_irqrestore(&ihost
->scic_lock
, flags
);
1882 /* Wait for the stop complete callback. */
1883 if (status
== SCI_SUCCESS
) {
1884 wait_for_device_stop(ihost
, idev
);
1885 clear_bit(IDEV_ALLOCATED
, &idev
->flags
);
1888 dev_dbg(&ihost
->pdev
->dev
,
1889 "%s: idev = %p - after completion wait\n",
1896 * isci_remote_device_gone() - This function is called by libsas when a domain
1897 * device is removed.
1898 * @domain_device: This parameter specifies the libsas domain device.
1901 void isci_remote_device_gone(struct domain_device
*dev
)
1903 struct isci_host
*ihost
= dev_to_ihost(dev
);
1904 struct isci_remote_device
*idev
= dev
->lldd_dev
;
1906 dev_dbg(&ihost
->pdev
->dev
,
1907 "%s: domain_device = %p, isci_device = %p, isci_port = %p\n",
1908 __func__
, dev
, idev
, idev
->isci_port
);
1910 isci_remote_device_stop(ihost
, idev
);
1915 * isci_remote_device_found() - This function is called by libsas when a remote
1916 * device is discovered. A remote device object is created and started. the
1917 * function then sleeps until the sci core device started message is
1919 * @domain_device: This parameter specifies the libsas domain device.
1921 * status, zero indicates success.
1923 int isci_remote_device_found(struct domain_device
*domain_dev
)
1925 struct isci_host
*isci_host
= dev_to_ihost(domain_dev
);
1926 struct isci_port
*isci_port
;
1927 struct isci_phy
*isci_phy
;
1928 struct asd_sas_port
*sas_port
;
1929 struct asd_sas_phy
*sas_phy
;
1930 struct isci_remote_device
*isci_device
;
1931 enum sci_status status
;
1933 dev_dbg(&isci_host
->pdev
->dev
,
1934 "%s: domain_device = %p\n", __func__
, domain_dev
);
1936 wait_for_start(isci_host
);
1938 sas_port
= domain_dev
->port
;
1939 sas_phy
= list_first_entry(&sas_port
->phy_list
, struct asd_sas_phy
,
1941 isci_phy
= to_isci_phy(sas_phy
);
1942 isci_port
= isci_phy
->isci_port
;
1944 /* we are being called for a device on this port,
1945 * so it has to come up eventually
1947 wait_for_completion(&isci_port
->start_complete
);
1949 if ((isci_stopping
== isci_port_get_state(isci_port
)) ||
1950 (isci_stopped
== isci_port_get_state(isci_port
)))
1953 isci_device
= isci_remote_device_alloc(isci_host
, isci_port
);
1957 INIT_LIST_HEAD(&isci_device
->node
);
1958 domain_dev
->lldd_dev
= isci_device
;
1959 isci_device
->domain_dev
= domain_dev
;
1960 isci_device
->isci_port
= isci_port
;
1961 isci_remote_device_change_state(isci_device
, isci_starting
);
1964 spin_lock_irq(&isci_host
->scic_lock
);
1965 list_add_tail(&isci_device
->node
, &isci_port
->remote_dev_list
);
1967 set_bit(IDEV_START_PENDING
, &isci_device
->flags
);
1968 status
= isci_remote_device_construct(isci_port
, isci_device
);
1969 spin_unlock_irq(&isci_host
->scic_lock
);
1971 dev_dbg(&isci_host
->pdev
->dev
,
1972 "%s: isci_device = %p\n",
1973 __func__
, isci_device
);
1975 if (status
!= SCI_SUCCESS
) {
1977 spin_lock_irq(&isci_host
->scic_lock
);
1978 isci_remote_device_deconstruct(
1982 spin_unlock_irq(&isci_host
->scic_lock
);
1986 /* wait for the device ready callback. */
1987 wait_for_device_start(isci_host
, isci_device
);
1992 * isci_device_is_reset_pending() - This function will check if there is any
1993 * pending reset condition on the device.
1994 * @request: This parameter is the isci_device object.
1996 * true if there is a reset pending for the device.
1998 bool isci_device_is_reset_pending(
1999 struct isci_host
*isci_host
,
2000 struct isci_remote_device
*isci_device
)
2002 struct isci_request
*isci_request
;
2003 struct isci_request
*tmp_req
;
2004 bool reset_is_pending
= false;
2005 unsigned long flags
;
2007 dev_dbg(&isci_host
->pdev
->dev
,
2008 "%s: isci_device = %p\n", __func__
, isci_device
);
2010 spin_lock_irqsave(&isci_host
->scic_lock
, flags
);
2012 /* Check for reset on all pending requests. */
2013 list_for_each_entry_safe(isci_request
, tmp_req
,
2014 &isci_device
->reqs_in_process
, dev_node
) {
2015 dev_dbg(&isci_host
->pdev
->dev
,
2016 "%s: isci_device = %p request = %p\n",
2017 __func__
, isci_device
, isci_request
);
2019 if (isci_request
->ttype
== io_task
) {
2020 struct sas_task
*task
= isci_request_access_task(
2023 spin_lock(&task
->task_state_lock
);
2024 if (task
->task_state_flags
& SAS_TASK_NEED_DEV_RESET
)
2025 reset_is_pending
= true;
2026 spin_unlock(&task
->task_state_lock
);
2030 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
2032 dev_dbg(&isci_host
->pdev
->dev
,
2033 "%s: isci_device = %p reset_is_pending = %d\n",
2034 __func__
, isci_device
, reset_is_pending
);
2036 return reset_is_pending
;
2040 * isci_device_clear_reset_pending() - This function will clear if any pending
2041 * reset condition flags on the device.
2042 * @request: This parameter is the isci_device object.
2044 * true if there is a reset pending for the device.
2046 void isci_device_clear_reset_pending(struct isci_host
*ihost
, struct isci_remote_device
*idev
)
2048 struct isci_request
*isci_request
;
2049 struct isci_request
*tmp_req
;
2050 unsigned long flags
= 0;
2052 dev_dbg(&ihost
->pdev
->dev
, "%s: idev=%p, ihost=%p\n",
2053 __func__
, idev
, ihost
);
2055 spin_lock_irqsave(&ihost
->scic_lock
, flags
);
2057 /* Clear reset pending on all pending requests. */
2058 list_for_each_entry_safe(isci_request
, tmp_req
,
2059 &idev
->reqs_in_process
, dev_node
) {
2060 dev_dbg(&ihost
->pdev
->dev
, "%s: idev = %p request = %p\n",
2061 __func__
, idev
, isci_request
);
2063 if (isci_request
->ttype
== io_task
) {
2065 unsigned long flags2
;
2066 struct sas_task
*task
= isci_request_access_task(
2069 spin_lock_irqsave(&task
->task_state_lock
, flags2
);
2070 task
->task_state_flags
&= ~SAS_TASK_NEED_DEV_RESET
;
2071 spin_unlock_irqrestore(&task
->task_state_lock
, flags2
);
2074 spin_unlock_irqrestore(&ihost
->scic_lock
, flags
);