2 * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
9 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
23 * The full GNU General Public License is included in this distribution
24 * in the file called LICENSE.GPL.
28 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
29 * All rights reserved.
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
35 * * Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * * Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in
39 * the documentation and/or other materials provided with the
42 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
45 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
46 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
48 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
49 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
50 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
52 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56 #ifndef _SCIC_SDS_REMOTE_DEVICE_H_
57 #define _SCIC_SDS_REMOTE_DEVICE_H_
62 * @brief This file contains the structures, constants, and prototypes for the
63 * SCIC_SDS_REMOTE_DEVICE object.
70 #include <dev/isci/scil/intel_sas.h>
71 #include <dev/isci/scil/sci_base_remote_device.h>
72 #include <dev/isci/scil/sci_base_request.h>
73 #include <dev/isci/scil/sci_base_state_machine_logger.h>
74 #include <dev/isci/scil/scu_remote_node_context.h>
75 #include <dev/isci/scil/scic_sds_remote_node_context.h>
77 struct SCIC_SDS_CONTROLLER;
79 struct SCIC_SDS_REQUEST;
80 struct SCIC_SDS_REMOTE_DEVICE_STATE_HANDLER;
83 * @enum SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATES
85 * This is the enumeration of the ready substates for the
86 * SCIC_SDS_REMOTE_DEVICE.
88 enum SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATES
91 * This is the initial state for the remote device ready substate.
93 SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATE_INITIAL,
96 * This is the ready operational substate for the remote device. This is the
97 * normal operational state for a remote device.
99 SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATE_OPERATIONAL,
102 * This is the suspended state for the remote device. This is the state that
103 * the device is placed in when a RNC suspend is received by the SCU hardware.
105 SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATE_SUSPENDED,
108 * This is the final state that the device is placed in before a change to the
109 * base state machine.
111 SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATE_FINAL,
113 SCIC_SDS_SSP_REMOTE_DEVICE_READY_MAX_SUBSTATES
117 * @enum SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATES
119 * This is the enumeration for the SCIC_SDS_REMOTE_DEVICE ready substates for
120 * the STP remote device.
122 enum SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATES
125 * This is the idle substate for the stp remote device. When there are no
126 * active IO for the device it is in this state.
128 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE,
131 * This is the command state for for the STP remote device. This state is
132 * entered when the device is processing a non-NCQ command. The device object
133 * will fail any new start IO requests until this command is complete.
135 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD,
138 * This is the NCQ state for the STP remote device. This state is entered
139 * when the device is processing an NCQ reuqest. It will remain in this state
140 * so long as there is one or more NCQ requests being processed.
142 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ,
145 * This is the NCQ error state for the STP remote device. This state is
146 * entered when an SDB error FIS is received by the device object while in the
147 * NCQ state. The device object will only accept a READ LOG command while in
150 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR,
152 #if !defined(DISABLE_ATAPI)
154 * This is the ATAPI error state for the STP ATAPI remote device. This state is
155 * entered when ATAPI device sends error status FIS without data while the device
156 * object is in CMD state. A suspension event is expected in this state. The device
157 * object will resume right away.
159 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_ATAPI_ERROR,
163 * This is the READY substate indicates the device is waiting for the RESET task
164 * coming to be recovered from certain hardware specific error.
166 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET,
168 SCIC_SDS_STP_REMOTE_DEVICE_READY_MAX_SUBSTATES
173 * @enum SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATES
175 * This is the enumeration of the ready substates for the SMP REMOTE DEVICE.
178 enum SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATES
181 * This is the ready operational substate for the remote device. This is the
182 * normal operational state for a remote device.
184 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE,
187 * This is the suspended state for the remote device. This is the state that
188 * the device is placed in when a RNC suspend is received by the SCU hardware.
190 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD,
192 SCIC_SDS_SMP_REMOTE_DEVICE_READY_MAX_SUBSTATES
199 * @struct SCIC_SDS_REMOTE_DEVICE
201 * @brief This structure contains the data for an SCU implementation of
202 * the SCU Core device data.
204 typedef struct SCIC_SDS_REMOTE_DEVICE
207 * This field is the common base for all remote device objects.
209 SCI_BASE_REMOTE_DEVICE_T parent;
212 * This field is the programmed device port width. This value is written to
213 * the RCN data structure to tell the SCU how many open connections this
216 U32 device_port_width;
219 * This field is the programmed connection rate for this remote device. It is
220 * used to program the TC with the maximum allowed connection rate.
222 SCI_SAS_LINK_RATE connection_rate;
225 * This field contains the allowed target protocols for this remote device.
227 SMP_DISCOVER_RESPONSE_PROTOCOLS_T target_protocols;
230 * This field contains the device SAS address.
232 SCI_SAS_ADDRESS_T device_address;
235 * This filed is assinged the value of TRUE if the device is directly attached
238 BOOL is_direct_attached;
240 #if !defined(DISABLE_ATAPI)
242 * This filed is assinged the value of TRUE if the device is an ATAPI device.
248 * This filed contains a pointer back to the port to which this device is
251 struct SCIC_SDS_PORT *owning_port;
254 * This field contains the SCU silicon remote node context specific
257 struct SCIC_SDS_REMOTE_NODE_CONTEXT * rnc;
260 * This field contains the stated request count for the remote device. The
261 * device can not reach the SCI_BASE_REMOTE_DEVICE_STATE_STOPPED until all
262 * requests are complete and the rnc_posted value is FALSE.
264 U32 started_request_count;
267 * This field contains a pointer to the working request object. It is only
268 * used only for SATA requests since the unsolicited frames we get from the
269 * hardware have no Tag value to look up the io request object.
271 struct SCIC_SDS_REQUEST * working_request;
274 * This field contains the reason for the remote device going not_ready. It is
275 * assigned in the state handlers and used in the state transition.
277 U32 not_ready_reason;
280 * This field is TRUE if this remote device has an initialzied ready substate
281 * machine. SSP devices do not have a ready substate machine and STP devices
282 * have a ready substate machine.
284 BOOL has_ready_substate_machine;
287 * This field contains the state machine for the ready substate machine for
288 * this SCIC_SDS_REMOTE_DEVICE object.
290 SCI_BASE_STATE_MACHINE_T ready_substate_machine;
293 * This field maintains the set of state handlers for the remote device
294 * object. These are changed each time the remote device enters a new state.
296 struct SCIC_SDS_REMOTE_DEVICE_STATE_HANDLER *state_handlers;
300 * This field conatins the ready substate machine logger. The logger will
301 * emit a message each time the ready substate machine changes state.
303 SCI_BASE_STATE_MACHINE_LOGGER_T ready_substate_machine_logger;
306 } SCIC_SDS_REMOTE_DEVICE_T;
309 typedef SCI_STATUS (*SCIC_SDS_REMOTE_DEVICE_HANDLER_T)(
310 SCIC_SDS_REMOTE_DEVICE_T *this_device);
312 typedef SCI_STATUS (*SCIC_SDS_REMOTE_DEVICE_SUSPEND_HANDLER_T)(
313 SCIC_SDS_REMOTE_DEVICE_T *this_device,
316 typedef SCI_STATUS (*SCIC_SDS_REMOTE_DEVICE_RESUME_HANDLER_T)(
317 SCIC_SDS_REMOTE_DEVICE_T *this_device);
319 typedef SCI_STATUS (*SCIC_SDS_REMOTE_DEVICE_FRAME_HANDLER_T)(
320 SCIC_SDS_REMOTE_DEVICE_T *this_device,
323 typedef SCI_STATUS (*SCIC_SDS_REMOTE_DEVICE_EVENT_HANDLER_T)(
324 SCIC_SDS_REMOTE_DEVICE_T *this_device,
327 typedef void (*SCIC_SDS_REMOTE_DEVICE_READY_NOT_READY_HANDLER_T)(
328 SCIC_SDS_REMOTE_DEVICE_T *this_device);
331 * @struct SCIC_SDS_REMOTE_DEVICE_STATE_HANDLER
332 * @brief This structure conains the state handlers that are needed to
333 * process requests for the SCU remote device objects.
335 typedef struct SCIC_SDS_REMOTE_DEVICE_STATE_HANDLER
337 SCI_BASE_REMOTE_DEVICE_STATE_HANDLER_T parent;
339 SCIC_SDS_REMOTE_DEVICE_SUSPEND_HANDLER_T suspend_handler;
340 SCIC_SDS_REMOTE_DEVICE_RESUME_HANDLER_T resume_handler;
342 SCIC_SDS_REMOTE_DEVICE_EVENT_HANDLER_T event_handler;
343 SCIC_SDS_REMOTE_DEVICE_FRAME_HANDLER_T frame_handler;
345 } SCIC_SDS_REMOTE_DEVICE_STATE_HANDLER_T;
348 extern SCI_BASE_STATE_T scic_sds_remote_device_state_table[];
349 extern SCI_BASE_STATE_T scic_sds_ssp_remote_device_ready_substate_table[];
350 extern SCI_BASE_STATE_T scic_sds_stp_remote_device_ready_substate_table[];
351 extern SCI_BASE_STATE_T scic_sds_smp_remote_device_ready_substate_table[];
353 extern SCIC_SDS_REMOTE_DEVICE_STATE_HANDLER_T
354 scic_sds_remote_device_state_handler_table[];
355 extern SCIC_SDS_REMOTE_DEVICE_STATE_HANDLER_T
356 scic_sds_ssp_remote_device_ready_substate_handler_table[];
357 extern SCIC_SDS_REMOTE_DEVICE_STATE_HANDLER_T
358 scic_sds_stp_remote_device_ready_substate_handler_table[];
359 extern SCIC_SDS_REMOTE_DEVICE_STATE_HANDLER_T
360 scic_sds_smp_remote_device_ready_substate_handler_table[];
363 * This macro incrments the request count for this device
365 #define scic_sds_remote_device_increment_request_count(this_device) \
366 ((this_device)->started_request_count++)
369 * This macro decrements the request count for this device. This count
370 * will never decrment past 0.
372 #define scic_sds_remote_device_decrement_request_count(this_device) \
373 ((this_device)->started_request_count > 0 ? \
374 (this_device)->started_request_count-- : 0)
377 * This is a helper macro to return the current device request count.
379 #define scic_sds_remote_device_get_request_count(this_device) \
380 ((this_device)->started_request_count)
383 * This macro returns the owning port of this remote device obejct.
385 #define scic_sds_remote_device_get_port(this_device) \
386 ((this_device)->owning_port)
389 * This macro returns the controller object that contains this device
392 #define scic_sds_remote_device_get_controller(this_device) \
393 scic_sds_port_get_controller(scic_sds_remote_device_get_port(this_device))
396 * This macro sets the remote device state handlers pointer and is set on
397 * entry to each device state.
399 #define scic_sds_remote_device_set_state_handlers(this_device, handlers) \
400 ((this_device)->state_handlers = (handlers))
403 * This macro returns the base sate machine object for the remote device.
405 #define scic_sds_remote_device_get_base_state_machine(this_device) \
406 (&(this_device)->parent.state_machine)
409 * This macro returns the remote device ready substate machine
411 #define scic_sds_remote_device_get_ready_substate_machine(this_device) \
412 (&(this_device)->ready_substate_machine)
415 * This macro returns the owning port of this device
417 #define scic_sds_remote_device_get_port(this_device) \
418 ((this_device)->owning_port)
421 * This macro returns the remote device sequence value
423 #define scic_sds_remote_device_get_sequence(this_device) \
425 scic_sds_remote_device_get_controller(this_device)->\
426 remote_device_sequence[(this_device)->rnc->remote_node_index] \
430 * This macro returns the controllers protocol engine group
432 #define scic_sds_remote_device_get_controller_peg(this_device) \
434 scic_sds_controller_get_protocol_engine_group( \
435 scic_sds_port_get_controller( \
436 scic_sds_remote_device_get_port(this_device) \
442 * This macro returns the port index for the devices owning port
444 #define scic_sds_remote_device_get_port_index(this_device) \
445 (scic_sds_port_get_index(scic_sds_remote_device_get_port(this_device)))
448 * This macro returns the remote node index for this device object
450 #define scic_sds_remote_device_get_index(this_device) \
451 ((this_device)->rnc->remote_node_index)
454 * This macro builds a remote device context for the SCU post request
457 #define scic_sds_remote_device_build_command_context(device, command) \
459 | ((U32)(scic_sds_remote_device_get_controller_peg((device))) << SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT)\
460 | ((U32)(scic_sds_remote_device_get_port_index((device))) << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) \
461 | (scic_sds_remote_device_get_index((device))) \
465 * This macro makes the working request assingment for the remote device
466 * object. To clear the working request use this macro with a NULL request
469 #define scic_sds_remote_device_set_working_request(device, request) \
470 ((device)->working_request = (request))
472 // ---------------------------------------------------------------------------
474 U32 scic_sds_remote_device_get_min_timer_count(void);
476 U32 scic_sds_remote_device_get_max_timer_count(void);
478 SCI_STATUS scic_sds_remote_device_frame_handler(
479 SCIC_SDS_REMOTE_DEVICE_T *this_device,
483 SCI_STATUS scic_sds_remote_device_event_handler(
484 SCIC_SDS_REMOTE_DEVICE_T *this_device,
488 SCI_STATUS scic_sds_remote_device_start_io(
489 struct SCIC_SDS_CONTROLLER *controller,
490 SCIC_SDS_REMOTE_DEVICE_T *this_device,
491 struct SCIC_SDS_REQUEST *io_request
494 SCI_STATUS scic_sds_remote_device_complete_io(
495 struct SCIC_SDS_CONTROLLER *controller,
496 SCIC_SDS_REMOTE_DEVICE_T *this_device,
497 struct SCIC_SDS_REQUEST *io_request
500 SCI_STATUS scic_sds_remote_device_resume(
501 SCIC_SDS_REMOTE_DEVICE_T *this_device
504 SCI_STATUS scic_sds_remote_device_suspend(
505 SCIC_SDS_REMOTE_DEVICE_T *this_device,
509 SCI_STATUS scic_sds_remote_device_start_task(
510 struct SCIC_SDS_CONTROLLER *controller,
511 SCIC_SDS_REMOTE_DEVICE_T *this_device,
512 struct SCIC_SDS_REQUEST *io_request
515 void scic_sds_remote_device_post_request(
516 SCIC_SDS_REMOTE_DEVICE_T * this_device,
520 #if !defined(DISABLE_ATAPI)
521 BOOL scic_sds_remote_device_is_atapi(
522 SCIC_SDS_REMOTE_DEVICE_T *this_device
524 #else // !defined(DISABLE_ATAPI)
525 #define scic_sds_remote_device_is_atapi(this_device) FALSE
526 #endif // !defined(DISABLE_ATAPI)
528 // ---------------------------------------------------------------------------
531 void scic_sds_remote_device_initialize_state_logging(
532 SCIC_SDS_REMOTE_DEVICE_T *this_device
535 void scic_sds_remote_device_deinitialize_state_logging(
536 SCIC_SDS_REMOTE_DEVICE_T *this_device
539 #define scic_sds_remote_device_initialize_state_logging(x)
540 #define scic_sds_remote_device_deinitialize_state_logging(x)
541 #endif // SCI_LOGGING
543 // ---------------------------------------------------------------------------
545 void scic_sds_remote_device_start_request(
546 SCIC_SDS_REMOTE_DEVICE_T * this_device,
547 struct SCIC_SDS_REQUEST * the_request,
551 void scic_sds_remote_device_continue_request(
552 SCIC_SDS_REMOTE_DEVICE_T * this_device
555 SCI_STATUS scic_sds_remote_device_default_start_handler(
556 SCI_BASE_REMOTE_DEVICE_T *this_device
559 SCI_STATUS scic_sds_remote_device_default_stop_handler(
560 SCI_BASE_REMOTE_DEVICE_T *this_device
563 SCI_STATUS scic_sds_remote_device_default_fail_handler(
564 SCI_BASE_REMOTE_DEVICE_T *this_device
567 SCI_STATUS scic_sds_remote_device_default_destruct_handler(
568 SCI_BASE_REMOTE_DEVICE_T *this_device
571 SCI_STATUS scic_sds_remote_device_default_reset_handler(
572 SCI_BASE_REMOTE_DEVICE_T *device
575 SCI_STATUS scic_sds_remote_device_default_reset_complete_handler(
576 SCI_BASE_REMOTE_DEVICE_T *device
579 SCI_STATUS scic_sds_remote_device_default_start_request_handler(
580 SCI_BASE_REMOTE_DEVICE_T *device,
581 SCI_BASE_REQUEST_T *request
584 SCI_STATUS scic_sds_remote_device_default_complete_request_handler(
585 SCI_BASE_REMOTE_DEVICE_T *device,
586 SCI_BASE_REQUEST_T *request
589 SCI_STATUS scic_sds_remote_device_default_continue_request_handler(
590 SCI_BASE_REMOTE_DEVICE_T *device,
591 SCI_BASE_REQUEST_T *request
594 SCI_STATUS scic_sds_remote_device_default_suspend_handler(
595 SCIC_SDS_REMOTE_DEVICE_T *this_device,
599 SCI_STATUS scic_sds_remote_device_default_resume_handler(
600 SCIC_SDS_REMOTE_DEVICE_T *this_device
603 SCI_STATUS scic_sds_remote_device_default_event_handler(
604 SCIC_SDS_REMOTE_DEVICE_T *this_device,
608 SCI_STATUS scic_sds_remote_device_default_frame_handler(
609 SCIC_SDS_REMOTE_DEVICE_T *this_device,
613 // ---------------------------------------------------------------------------
615 SCI_STATUS scic_sds_remote_device_ready_state_stop_handler(
616 SCI_BASE_REMOTE_DEVICE_T *device
619 SCI_STATUS scic_sds_remote_device_ready_state_reset_handler(
620 SCI_BASE_REMOTE_DEVICE_T *device
623 SCI_STATUS scic_sds_remote_device_general_frame_handler(
624 SCIC_SDS_REMOTE_DEVICE_T *this_device,
628 SCI_STATUS scic_sds_remote_device_general_event_handler(
629 SCIC_SDS_REMOTE_DEVICE_T *this_device,
633 SCI_STATUS scic_sds_ssp_remote_device_ready_suspended_substate_resume_handler(
634 SCIC_SDS_REMOTE_DEVICE_T *this_device
637 // ---------------------------------------------------------------------------
639 void scic_sds_remote_device_get_info_from_smp_discover_response(
640 SCIC_SDS_REMOTE_DEVICE_T * this_device,
641 SMP_RESPONSE_DISCOVER_T * discover_response
646 #endif // __cplusplus
648 #endif // _SCIC_SDS_REMOTE_DEVICE_H_