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_PHY_H_
55 #define _SCIC_SDS_PHY_H_
60 * @brief This file contains the structures, constants and prototypes for the
61 * SCIC_SDS_PHY object.
68 #include <dev/isci/scil/intel_sata.h>
69 #include <dev/isci/scil/intel_sas.h>
70 #include <dev/isci/scil/sci_base_phy.h>
71 #include <dev/isci/scil/scu_registers.h>
72 #include <dev/isci/scil/scu_event_codes.h>
75 * This is the timeout value for the SATA phy to wait for a SIGNATURE FIS
76 * before restarting the starting state machine. Technically, the old
77 * parallel ATA specification required up to 30 seconds for a device to
78 * issue its signature FIS as a result of a soft reset. Now we see that
79 * devices respond generally within 15 seconds, but we'll use 25 for now.
81 #define SCIC_SDS_SIGNATURE_FIS_TIMEOUT 25000
84 * This is the timeout for the SATA OOB/SN because the hardware does not
85 * recognize a hot plug after OOB signal but before the SN signals. We
86 * need to make sure after a hotplug timeout if we have not received the
87 * speed event notification from the hardware that we restart the hardware
90 #define SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT 250
93 * @enum SCIC_SDS_PHY_STARTING_SUBSTATES
95 enum SCIC_SDS_PHY_STARTING_SUBSTATES
100 SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL,
103 * Wait state for the hardware OSSP event type notification
105 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN,
108 * Wait state for the PHY speed notification
110 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN,
113 * Wait state for the IAF Unsolicited frame notification
115 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF,
118 * Wait state for the request to consume power
120 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER,
123 * Wait state for request to consume power
125 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER,
128 * Wait state for the SATA PHY notification
130 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN,
133 * Wait for the SATA PHY speed notification
135 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN,
138 * Wait state for the SIGNATURE FIS unsolicited frame notification
140 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF,
143 * Exit state for this state machine
145 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL,
148 * Maximum number of substates for the STARTING state machine
150 SCIC_SDS_PHY_STARTING_MAX_SUBSTATES
153 struct SCIC_SDS_PORT;
154 struct SCIC_SDS_CONTROLLER;
156 #ifdef SCIC_DEBUG_ENABLED
157 #define MAX_STATE_TRANSITION_RECORD (256)
160 * Debug code to record the state transitions for the phy object
162 typedef struct SCIC_SDS_PHY_STATE_RECORD
164 SCI_BASE_OBSERVER_T base_state_observer;
165 SCI_BASE_OBSERVER_T starting_state_observer;
169 U32 state_transition_table[MAX_STATE_TRANSITION_RECORD];
171 } SCIC_SDS_PHY_STATE_RECORD_T;
172 #endif // SCIC_DEBUG_ENABLED
177 * @brief This enumeration provides a named phy type for the state machine
179 enum SCIC_SDS_PHY_PROTOCOL
182 * This is an unknown phy type since there is either nothing on the other
183 * end or we have not detected the phy type as yet.
185 SCIC_SDS_PHY_PROTOCOL_UNKNOWN,
190 SCIC_SDS_PHY_PROTOCOL_SAS,
195 SCIC_SDS_PHY_PROTOCOL_SATA,
197 SCIC_SDS_MAX_PHY_PROTOCOLS
201 * @struct SCIC_SDS_PHY
203 * @brief This structure contains or references all of the data necessary to
204 * represent the core phy object and SCU harware protocol engine.
206 typedef struct SCIC_SDS_PHY
208 SCI_BASE_PHY_T parent;
211 * This field specifies the port object that owns/contains this phy.
213 struct SCIC_SDS_PORT * owning_port;
216 * This field indicates whether the phy supports 1.5 Gb/s, 3.0 Gb/s,
217 * or 6.0 Gb/s operation.
219 SCI_SAS_LINK_RATE max_negotiated_speed;
222 * This member specifies the protocol being utilized on this phy. This
223 * field contains a legitamite value once the PHY has link trained with
226 enum SCIC_SDS_PHY_PROTOCOL protocol;
229 * This field specifies the index with which this phy is associated (0-3).
234 * This member indicates if this particular PHY has received a BCN while
235 * it had no port assignement. This BCN will be reported once the phy is
236 * assigned to a port.
238 BOOL bcn_received_while_port_unassigned;
241 * This field indicates if this PHY is currently in the process of
242 * link training (i.e. it has started OOB, but has yet to perform
243 * IAF exchange/Signature FIS reception).
245 BOOL is_in_link_training;
251 SCI_SAS_IDENTIFY_ADDRESS_FRAME_T identify_address_frame_buffer;
257 SATA_FIS_REG_D2H_T signature_fis_buffer;
264 * This field contains a reference to the timer utilized in detecting
265 * when a signature FIS timeout has occurred. The signature FIS is the
266 * first FIS sent by an attached SATA device after OOB/SN.
268 void * sata_timeout_timer;
270 struct SCIC_SDS_PHY_STATE_HANDLER *state_handlers;
272 SCI_BASE_STATE_MACHINE_T starting_substate_machine;
275 SCI_BASE_STATE_MACHINE_LOGGER_T starting_substate_machine_logger;
278 #ifdef SCIC_DEBUG_ENABLED
279 SCIC_SDS_PHY_STATE_RECORD_T state_record;
280 #endif // SCIC_DEBUG_ENABLED
283 * This field tracks how many errors of each type have been detected since
284 * the last controller reset or counter clear. Note that these are only
285 * for the error types that our driver needs to count manually. See
286 * SCU_ERR_CNT_* values defined in scu_event_codes.h.
288 U32 error_counter[SCU_ERR_CNT_MAX_INDEX];
291 * This field is the pointer to the transport layer register for the SCU
294 SCU_TRANSPORT_LAYER_REGISTERS_T *transport_layer_registers;
297 * This field points to the link layer register set within the SCU.
299 SCU_LINK_LAYER_REGISTERS_T *link_layer_registers;
304 typedef SCI_STATUS (*SCIC_SDS_PHY_EVENT_HANDLER_T)(SCIC_SDS_PHY_T *, U32);
305 typedef SCI_STATUS (*SCIC_SDS_PHY_FRAME_HANDLER_T)(SCIC_SDS_PHY_T *, U32);
306 typedef SCI_STATUS (*SCIC_SDS_PHY_POWER_HANDLER_T)(SCIC_SDS_PHY_T *);
309 * @struct SCIC_SDS_PHY_STATE_HANDLER
311 typedef struct SCIC_SDS_PHY_STATE_HANDLER
314 * This is the SCI_BASE_PHY object state handlers.
316 SCI_BASE_PHY_STATE_HANDLER_T parent;
319 * The state handler for unsolicited frames received from the SCU hardware.
321 SCIC_SDS_PHY_FRAME_HANDLER_T frame_handler;
324 * The state handler for events received from the SCU hardware.
326 SCIC_SDS_PHY_EVENT_HANDLER_T event_handler;
329 * The state handler for staggered spinup.
331 SCIC_SDS_PHY_POWER_HANDLER_T consume_power_handler;
333 } SCIC_SDS_PHY_STATE_HANDLER_T;
335 extern SCIC_SDS_PHY_STATE_HANDLER_T scic_sds_phy_state_handler_table[];
336 extern SCI_BASE_STATE_T scic_sds_phy_state_table[];
337 extern SCI_BASE_STATE_T scic_sds_phy_starting_substates[];
338 extern SCIC_SDS_PHY_STATE_HANDLER_T
339 scic_sds_phy_starting_substate_handler_table[];
343 * This macro returns the phy index for the specified phy
345 #define scic_sds_phy_get_index(phy) \
349 * @brief This macro returns the controller for this phy
351 #define scic_sds_phy_get_controller(phy) \
352 (scic_sds_port_get_controller((phy)->owning_port))
355 * @brief This macro returns the state machine for the base phy
357 #define scic_sds_phy_get_base_state_machine(phy) \
358 (&(phy)->parent.state_machine)
361 * @brief This macro returns the starting substate machine for
364 #define scic_sds_phy_get_starting_substate_machine(phy) \
365 (&(phy)->starting_substate_machine)
368 * @brief This macro sets the state handlers for this phy object
370 #define scic_sds_phy_set_state_handlers(phy, handlers) \
371 ((phy)->state_handlers = (handlers))
374 * This macro set the base state handlers for the phy object.
376 #define scic_sds_phy_set_base_state_handlers(phy, state_id) \
377 scic_sds_phy_set_state_handlers( \
379 &scic_sds_phy_state_handler_table[(state_id)] \
383 * This macro returns TRUE if the current base state for this phy is
384 * SCI_BASE_PHY_STATE_READY
386 #define scic_sds_phy_is_ready(phy) \
388 SCI_BASE_PHY_STATE_READY \
389 == sci_base_state_machine_get_state( \
390 scic_sds_phy_get_base_state_machine(phy) \
394 // ---------------------------------------------------------------------------
396 U32 scic_sds_phy_get_object_size(void);
398 U32 scic_sds_phy_get_min_timer_count(void);
400 U32 scic_sds_phy_get_max_timer_count(void);
402 // ---------------------------------------------------------------------------
404 void scic_sds_phy_construct(
405 struct SCIC_SDS_PHY *this_phy,
406 struct SCIC_SDS_PORT *owning_port,
410 SCI_PORT_HANDLE_T scic_sds_phy_get_port(
411 SCIC_SDS_PHY_T *this_phy
414 void scic_sds_phy_set_port(
415 struct SCIC_SDS_PHY *this_phy,
416 struct SCIC_SDS_PORT *owning_port
419 SCI_STATUS scic_sds_phy_initialize(
420 SCIC_SDS_PHY_T *this_phy,
421 void *transport_layer_registers,
422 SCU_LINK_LAYER_REGISTERS_T *link_layer_registers
425 SCI_STATUS scic_sds_phy_reset(
426 SCIC_SDS_PHY_T * this_phy
429 void scic_sds_phy_sata_timeout(
430 SCI_OBJECT_HANDLE_T cookie
433 // ---------------------------------------------------------------------------
435 void scic_sds_phy_suspend(
436 struct SCIC_SDS_PHY *this_phy
439 void scic_sds_phy_resume(
440 struct SCIC_SDS_PHY *this_phy
443 void scic_sds_phy_setup_transport(
444 struct SCIC_SDS_PHY * this_phy,
448 // ---------------------------------------------------------------------------
450 SCI_STATUS scic_sds_phy_event_handler(
451 SCIC_SDS_PHY_T *this_phy,
455 SCI_STATUS scic_sds_phy_frame_handler(
456 SCIC_SDS_PHY_T *this_phy,
460 SCI_STATUS scic_sds_phy_consume_power_handler(
461 SCIC_SDS_PHY_T *this_phy
464 void scic_sds_phy_get_sas_address(
465 SCIC_SDS_PHY_T *this_phy,
466 SCI_SAS_ADDRESS_T *sas_address
469 void scic_sds_phy_get_attached_sas_address(
470 SCIC_SDS_PHY_T *this_phy,
471 SCI_SAS_ADDRESS_T *sas_address
474 void scic_sds_phy_get_protocols(
475 SCIC_SDS_PHY_T *this_phy,
476 SCI_SAS_IDENTIFY_ADDRESS_FRAME_PROTOCOLS_T * protocols
479 void scic_sds_phy_get_attached_phy_protocols(
480 SCIC_SDS_PHY_T *this_phy,
481 SCI_SAS_IDENTIFY_ADDRESS_FRAME_PROTOCOLS_T * protocols
484 //****************************************************************************-
485 //* SCIC SDS PHY Handler Methods
486 //****************************************************************************-
488 SCI_STATUS scic_sds_phy_default_start_handler(
492 SCI_STATUS scic_sds_phy_default_stop_handler(
496 SCI_STATUS scic_sds_phy_default_reset_handler(
500 SCI_STATUS scic_sds_phy_default_destroy_handler(
504 SCI_STATUS scic_sds_phy_default_frame_handler(
509 SCI_STATUS scic_sds_phy_default_event_handler(
514 SCI_STATUS scic_sds_phy_default_consume_power_handler(
518 void scic_sds_phy_release_resource(
519 struct SCIC_SDS_CONTROLLER * controller,
520 struct SCIC_SDS_PHY * phy
523 void scic_sds_phy_restart_starting_state(
524 struct SCIC_SDS_PHY * this_phy
529 #endif // __cplusplus
531 #endif // _SCIC_SDS_PHY_H_