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
40 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
41 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
42 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
43 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
44 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 #ifndef _SCIC_SDS_REMOTE_DEVICE_H_
55 #define _SCIC_SDS_REMOTE_DEVICE_H_
60 * @brief This file contains the structures, constants, and prototypes for the
61 * SCIC_SDS_REMOTE_DEVICE object.
68 #include <dev/isci/scil/intel_sas.h>
69 #include <dev/isci/scil/sci_base_remote_device.h>
70 #include <dev/isci/scil/sci_base_request.h>
71 #include <dev/isci/scil/sci_base_state_machine_logger.h>
72 #include <dev/isci/scil/scu_remote_node_context.h>
73 #include <dev/isci/scil/scic_sds_remote_node_context.h>
75 struct SCIC_SDS_CONTROLLER;
77 struct SCIC_SDS_REQUEST;
78 struct SCIC_SDS_REMOTE_DEVICE_STATE_HANDLER;
81 * @enum SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATES
83 * This is the enumeration of the ready substates for the
84 * SCIC_SDS_REMOTE_DEVICE.
86 enum SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATES
89 * This is the initial state for the remote device ready substate.
91 SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATE_INITIAL,
94 * This is the ready operational substate for the remote device. This is the
95 * normal operational state for a remote device.
97 SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATE_OPERATIONAL,
100 * This is the suspended state for the remote device. This is the state that
101 * the device is placed in when a RNC suspend is received by the SCU hardware.
103 SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATE_SUSPENDED,
106 * This is the final state that the device is placed in before a change to the
107 * base state machine.
109 SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATE_FINAL,
111 SCIC_SDS_SSP_REMOTE_DEVICE_READY_MAX_SUBSTATES
115 * @enum SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATES
117 * This is the enumeration for the SCIC_SDS_REMOTE_DEVICE ready substates for
118 * the STP remote device.
120 enum SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATES
123 * This is the idle substate for the stp remote device. When there are no
124 * active IO for the device it is in this state.
126 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE,
129 * This is the command state for for the STP remote device. This state is
130 * entered when the device is processing a non-NCQ command. The device object
131 * will fail any new start IO requests until this command is complete.
133 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD,
136 * This is the NCQ state for the STP remote device. This state is entered
137 * when the device is processing an NCQ reuqest. It will remain in this state
138 * so long as there is one or more NCQ requests being processed.
140 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ,
143 * This is the NCQ error state for the STP remote device. This state is
144 * entered when an SDB error FIS is received by the device object while in the
145 * NCQ state. The device object will only accept a READ LOG command while in
148 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR,
150 #if !defined(DISABLE_ATAPI)
152 * This is the ATAPI error state for the STP ATAPI remote device. This state is
153 * entered when ATAPI device sends error status FIS without data while the device
154 * object is in CMD state. A suspension event is expected in this state. The device
155 * object will resume right away.
157 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_ATAPI_ERROR,
161 * This is the READY substate indicates the device is waiting for the RESET task
162 * coming to be recovered from certain hardware specific error.
164 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET,
166 SCIC_SDS_STP_REMOTE_DEVICE_READY_MAX_SUBSTATES
171 * @enum SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATES
173 * This is the enumeration of the ready substates for the SMP REMOTE DEVICE.
176 enum SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATES
179 * This is the ready operational substate for the remote device. This is the
180 * normal operational state for a remote device.
182 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE,
185 * This is the suspended state for the remote device. This is the state that
186 * the device is placed in when a RNC suspend is received by the SCU hardware.
188 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD,
190 SCIC_SDS_SMP_REMOTE_DEVICE_READY_MAX_SUBSTATES
197 * @struct SCIC_SDS_REMOTE_DEVICE
199 * @brief This structure contains the data for an SCU implementation of
200 * the SCU Core device data.
202 typedef struct SCIC_SDS_REMOTE_DEVICE
205 * This field is the common base for all remote device objects.
207 SCI_BASE_REMOTE_DEVICE_T parent;
210 * This field is the programmed device port width. This value is written to
211 * the RCN data structure to tell the SCU how many open connections this
214 U32 device_port_width;
217 * This field is the programmed connection rate for this remote device. It is
218 * used to program the TC with the maximum allowed connection rate.
220 SCI_SAS_LINK_RATE connection_rate;
223 * This field contains the allowed target protocols for this remote device.
225 SMP_DISCOVER_RESPONSE_PROTOCOLS_T target_protocols;
228 * This field contains the device SAS address.
230 SCI_SAS_ADDRESS_T device_address;
233 * This filed is assinged the value of TRUE if the device is directly attached
236 BOOL is_direct_attached;
238 #if !defined(DISABLE_ATAPI)
240 * This filed is assinged the value of TRUE if the device is an ATAPI device.
246 * This filed contains a pointer back to the port to which this device is
249 struct SCIC_SDS_PORT *owning_port;
252 * This field contains the SCU silicon remote node context specific
255 struct SCIC_SDS_REMOTE_NODE_CONTEXT * rnc;
258 * This field contains the stated request count for the remote device. The
259 * device can not reach the SCI_BASE_REMOTE_DEVICE_STATE_STOPPED until all
260 * requests are complete and the rnc_posted value is FALSE.
262 U32 started_request_count;
265 * This field contains a pointer to the working request object. It is only
266 * used only for SATA requests since the unsolicited frames we get from the
267 * hardware have no Tag value to look up the io request object.
269 struct SCIC_SDS_REQUEST * working_request;
272 * This field contains the reason for the remote device going not_ready. It is
273 * assigned in the state handlers and used in the state transition.
275 U32 not_ready_reason;
278 * This field is TRUE if this remote device has an initialzied ready substate
279 * machine. SSP devices do not have a ready substate machine and STP devices
280 * have a ready substate machine.
282 BOOL has_ready_substate_machine;
285 * This field contains the state machine for the ready substate machine for
286 * this SCIC_SDS_REMOTE_DEVICE object.
288 SCI_BASE_STATE_MACHINE_T ready_substate_machine;
291 * This field maintains the set of state handlers for the remote device
292 * object. These are changed each time the remote device enters a new state.
294 struct SCIC_SDS_REMOTE_DEVICE_STATE_HANDLER *state_handlers;
298 * This field conatins the ready substate machine logger. The logger will
299 * emit a message each time the ready substate machine changes state.
301 SCI_BASE_STATE_MACHINE_LOGGER_T ready_substate_machine_logger;
304 } SCIC_SDS_REMOTE_DEVICE_T;
307 typedef SCI_STATUS (*SCIC_SDS_REMOTE_DEVICE_HANDLER_T)(
308 SCIC_SDS_REMOTE_DEVICE_T *this_device);
310 typedef SCI_STATUS (*SCIC_SDS_REMOTE_DEVICE_SUSPEND_HANDLER_T)(
311 SCIC_SDS_REMOTE_DEVICE_T *this_device,
314 typedef SCI_STATUS (*SCIC_SDS_REMOTE_DEVICE_RESUME_HANDLER_T)(
315 SCIC_SDS_REMOTE_DEVICE_T *this_device);
317 typedef SCI_STATUS (*SCIC_SDS_REMOTE_DEVICE_FRAME_HANDLER_T)(
318 SCIC_SDS_REMOTE_DEVICE_T *this_device,
321 typedef SCI_STATUS (*SCIC_SDS_REMOTE_DEVICE_EVENT_HANDLER_T)(
322 SCIC_SDS_REMOTE_DEVICE_T *this_device,
325 typedef void (*SCIC_SDS_REMOTE_DEVICE_READY_NOT_READY_HANDLER_T)(
326 SCIC_SDS_REMOTE_DEVICE_T *this_device);
329 * @struct SCIC_SDS_REMOTE_DEVICE_STATE_HANDLER
330 * @brief This structure conains the state handlers that are needed to
331 * process requests for the SCU remote device objects.
333 typedef struct SCIC_SDS_REMOTE_DEVICE_STATE_HANDLER
335 SCI_BASE_REMOTE_DEVICE_STATE_HANDLER_T parent;
337 SCIC_SDS_REMOTE_DEVICE_SUSPEND_HANDLER_T suspend_handler;
338 SCIC_SDS_REMOTE_DEVICE_RESUME_HANDLER_T resume_handler;
340 SCIC_SDS_REMOTE_DEVICE_EVENT_HANDLER_T event_handler;
341 SCIC_SDS_REMOTE_DEVICE_FRAME_HANDLER_T frame_handler;
343 } SCIC_SDS_REMOTE_DEVICE_STATE_HANDLER_T;
346 extern SCI_BASE_STATE_T scic_sds_remote_device_state_table[];
347 extern SCI_BASE_STATE_T scic_sds_ssp_remote_device_ready_substate_table[];
348 extern SCI_BASE_STATE_T scic_sds_stp_remote_device_ready_substate_table[];
349 extern SCI_BASE_STATE_T scic_sds_smp_remote_device_ready_substate_table[];
351 extern SCIC_SDS_REMOTE_DEVICE_STATE_HANDLER_T
352 scic_sds_remote_device_state_handler_table[];
353 extern SCIC_SDS_REMOTE_DEVICE_STATE_HANDLER_T
354 scic_sds_ssp_remote_device_ready_substate_handler_table[];
355 extern SCIC_SDS_REMOTE_DEVICE_STATE_HANDLER_T
356 scic_sds_stp_remote_device_ready_substate_handler_table[];
357 extern SCIC_SDS_REMOTE_DEVICE_STATE_HANDLER_T
358 scic_sds_smp_remote_device_ready_substate_handler_table[];
361 * This macro incrments the request count for this device
363 #define scic_sds_remote_device_increment_request_count(this_device) \
364 ((this_device)->started_request_count++)
367 * This macro decrements the request count for this device. This count
368 * will never decrment past 0.
370 #define scic_sds_remote_device_decrement_request_count(this_device) \
371 ((this_device)->started_request_count > 0 ? \
372 (this_device)->started_request_count-- : 0)
375 * This is a helper macro to return the current device request count.
377 #define scic_sds_remote_device_get_request_count(this_device) \
378 ((this_device)->started_request_count)
381 * This macro returns the owning port of this remote device obejct.
383 #define scic_sds_remote_device_get_port(this_device) \
384 ((this_device)->owning_port)
387 * This macro returns the controller object that contains this device
390 #define scic_sds_remote_device_get_controller(this_device) \
391 scic_sds_port_get_controller(scic_sds_remote_device_get_port(this_device))
394 * This macro sets the remote device state handlers pointer and is set on
395 * entry to each device state.
397 #define scic_sds_remote_device_set_state_handlers(this_device, handlers) \
398 ((this_device)->state_handlers = (handlers))
401 * This macro returns the base sate machine object for the remote device.
403 #define scic_sds_remote_device_get_base_state_machine(this_device) \
404 (&(this_device)->parent.state_machine)
407 * This macro returns the remote device ready substate machine
409 #define scic_sds_remote_device_get_ready_substate_machine(this_device) \
410 (&(this_device)->ready_substate_machine)
413 * This macro returns the owning port of this device
415 #define scic_sds_remote_device_get_port(this_device) \
416 ((this_device)->owning_port)
419 * This macro returns the remote device sequence value
421 #define scic_sds_remote_device_get_sequence(this_device) \
423 scic_sds_remote_device_get_controller(this_device)->\
424 remote_device_sequence[(this_device)->rnc->remote_node_index] \
428 * This macro returns the controllers protocol engine group
430 #define scic_sds_remote_device_get_controller_peg(this_device) \
432 scic_sds_controller_get_protocol_engine_group( \
433 scic_sds_port_get_controller( \
434 scic_sds_remote_device_get_port(this_device) \
440 * This macro returns the port index for the devices owning port
442 #define scic_sds_remote_device_get_port_index(this_device) \
443 (scic_sds_port_get_index(scic_sds_remote_device_get_port(this_device)))
446 * This macro returns the remote node index for this device object
448 #define scic_sds_remote_device_get_index(this_device) \
449 ((this_device)->rnc->remote_node_index)
452 * This macro builds a remote device context for the SCU post request
455 #define scic_sds_remote_device_build_command_context(device, command) \
457 | ((U32)(scic_sds_remote_device_get_controller_peg((device))) << SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT)\
458 | ((U32)(scic_sds_remote_device_get_port_index((device))) << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) \
459 | (scic_sds_remote_device_get_index((device))) \
463 * This macro makes the working request assingment for the remote device
464 * object. To clear the working request use this macro with a NULL request
467 #define scic_sds_remote_device_set_working_request(device, request) \
468 ((device)->working_request = (request))
470 // ---------------------------------------------------------------------------
472 U32 scic_sds_remote_device_get_min_timer_count(void);
474 U32 scic_sds_remote_device_get_max_timer_count(void);
476 SCI_STATUS scic_sds_remote_device_frame_handler(
477 SCIC_SDS_REMOTE_DEVICE_T *this_device,
481 SCI_STATUS scic_sds_remote_device_event_handler(
482 SCIC_SDS_REMOTE_DEVICE_T *this_device,
486 SCI_STATUS scic_sds_remote_device_start_io(
487 struct SCIC_SDS_CONTROLLER *controller,
488 SCIC_SDS_REMOTE_DEVICE_T *this_device,
489 struct SCIC_SDS_REQUEST *io_request
492 SCI_STATUS scic_sds_remote_device_complete_io(
493 struct SCIC_SDS_CONTROLLER *controller,
494 SCIC_SDS_REMOTE_DEVICE_T *this_device,
495 struct SCIC_SDS_REQUEST *io_request
498 SCI_STATUS scic_sds_remote_device_resume(
499 SCIC_SDS_REMOTE_DEVICE_T *this_device
502 SCI_STATUS scic_sds_remote_device_suspend(
503 SCIC_SDS_REMOTE_DEVICE_T *this_device,
507 SCI_STATUS scic_sds_remote_device_start_task(
508 struct SCIC_SDS_CONTROLLER *controller,
509 SCIC_SDS_REMOTE_DEVICE_T *this_device,
510 struct SCIC_SDS_REQUEST *io_request
513 void scic_sds_remote_device_post_request(
514 SCIC_SDS_REMOTE_DEVICE_T * this_device,
518 #if !defined(DISABLE_ATAPI)
519 BOOL scic_sds_remote_device_is_atapi(
520 SCIC_SDS_REMOTE_DEVICE_T *this_device
522 #else // !defined(DISABLE_ATAPI)
523 #define scic_sds_remote_device_is_atapi(this_device) FALSE
524 #endif // !defined(DISABLE_ATAPI)
526 // ---------------------------------------------------------------------------
529 void scic_sds_remote_device_initialize_state_logging(
530 SCIC_SDS_REMOTE_DEVICE_T *this_device
533 void scic_sds_remote_device_deinitialize_state_logging(
534 SCIC_SDS_REMOTE_DEVICE_T *this_device
537 #define scic_sds_remote_device_initialize_state_logging(x)
538 #define scic_sds_remote_device_deinitialize_state_logging(x)
539 #endif // SCI_LOGGING
541 // ---------------------------------------------------------------------------
543 void scic_sds_remote_device_start_request(
544 SCIC_SDS_REMOTE_DEVICE_T * this_device,
545 struct SCIC_SDS_REQUEST * the_request,
549 void scic_sds_remote_device_continue_request(
550 SCIC_SDS_REMOTE_DEVICE_T * this_device
553 SCI_STATUS scic_sds_remote_device_default_start_handler(
554 SCI_BASE_REMOTE_DEVICE_T *this_device
557 SCI_STATUS scic_sds_remote_device_default_stop_handler(
558 SCI_BASE_REMOTE_DEVICE_T *this_device
561 SCI_STATUS scic_sds_remote_device_default_fail_handler(
562 SCI_BASE_REMOTE_DEVICE_T *this_device
565 SCI_STATUS scic_sds_remote_device_default_destruct_handler(
566 SCI_BASE_REMOTE_DEVICE_T *this_device
569 SCI_STATUS scic_sds_remote_device_default_reset_handler(
570 SCI_BASE_REMOTE_DEVICE_T *device
573 SCI_STATUS scic_sds_remote_device_default_reset_complete_handler(
574 SCI_BASE_REMOTE_DEVICE_T *device
577 SCI_STATUS scic_sds_remote_device_default_start_request_handler(
578 SCI_BASE_REMOTE_DEVICE_T *device,
579 SCI_BASE_REQUEST_T *request
582 SCI_STATUS scic_sds_remote_device_default_complete_request_handler(
583 SCI_BASE_REMOTE_DEVICE_T *device,
584 SCI_BASE_REQUEST_T *request
587 SCI_STATUS scic_sds_remote_device_default_continue_request_handler(
588 SCI_BASE_REMOTE_DEVICE_T *device,
589 SCI_BASE_REQUEST_T *request
592 SCI_STATUS scic_sds_remote_device_default_suspend_handler(
593 SCIC_SDS_REMOTE_DEVICE_T *this_device,
597 SCI_STATUS scic_sds_remote_device_default_resume_handler(
598 SCIC_SDS_REMOTE_DEVICE_T *this_device
601 SCI_STATUS scic_sds_remote_device_default_event_handler(
602 SCIC_SDS_REMOTE_DEVICE_T *this_device,
606 SCI_STATUS scic_sds_remote_device_default_frame_handler(
607 SCIC_SDS_REMOTE_DEVICE_T *this_device,
611 // ---------------------------------------------------------------------------
613 SCI_STATUS scic_sds_remote_device_ready_state_stop_handler(
614 SCI_BASE_REMOTE_DEVICE_T *device
617 SCI_STATUS scic_sds_remote_device_ready_state_reset_handler(
618 SCI_BASE_REMOTE_DEVICE_T *device
621 SCI_STATUS scic_sds_remote_device_general_frame_handler(
622 SCIC_SDS_REMOTE_DEVICE_T *this_device,
626 SCI_STATUS scic_sds_remote_device_general_event_handler(
627 SCIC_SDS_REMOTE_DEVICE_T *this_device,
631 SCI_STATUS scic_sds_ssp_remote_device_ready_suspended_substate_resume_handler(
632 SCIC_SDS_REMOTE_DEVICE_T *this_device
635 // ---------------------------------------------------------------------------
637 void scic_sds_remote_device_get_info_from_smp_discover_response(
638 SCIC_SDS_REMOTE_DEVICE_T * this_device,
639 SMP_RESPONSE_DISCOVER_T * discover_response
644 #endif // __cplusplus
646 #endif // _SCIC_SDS_REMOTE_DEVICE_H_