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.
56 #ifndef _SCIC_SDS_PHY_H_
57 #define _SCIC_SDS_PHY_H_
60 * This file contains the structures, constants and prototypes for the
61 * struct scic_sds_phy object.
66 #include "intel_sata.h"
67 #include "intel_sas.h"
68 #include "sci_base_phy.h"
69 #include "scu_registers.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 parallel
77 * ATA specification required up to 30 seconds for a device to issue its
78 * signature FIS as a result of a soft reset. Now we see that devices respond
79 * generally within 15 seconds, but we'll use 25 for now.
81 #define SCIC_SDS_SIGNATURE_FIS_TIMEOUT 25000
86 * This is the timeout for the SATA OOB/SN because the hardware does not
87 * recognize a hot plug after OOB signal but before the SN signals. We need to
88 * make sure after a hotplug timeout if we have not received the speed event
89 * notification from the hardware that we restart the hardware OOB state
92 #define SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT 250
95 * enum SCIC_SDS_PHY_STARTING_SUBSTATES -
99 enum SCIC_SDS_PHY_STARTING_SUBSTATES {
103 SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL,
106 * Wait state for the hardware OSSP event type notification
108 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN,
111 * Wait state for the PHY speed notification
113 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN,
116 * Wait state for the IAF Unsolicited frame notification
118 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF,
121 * Wait state for the request to consume power
123 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER,
126 * Wait state for request to consume power
128 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER,
131 * Wait state for the SATA PHY notification
133 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN,
136 * Wait for the SATA PHY speed notification
138 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN,
141 * Wait state for the SIGNATURE FIS unsolicited frame notification
143 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF,
146 * Exit state for this state machine
148 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL,
151 * Maximum number of substates for the STARTING state machine
153 SCIC_SDS_PHY_STARTING_MAX_SUBSTATES
156 struct scic_sds_port;
157 struct scic_sds_controller;
159 #ifdef SCIC_DEBUG_ENABLED
160 #define MAX_STATE_TRANSITION_RECORD (256)
165 * Debug code to record the state transitions for the phy object
167 struct scic_sds_phy_state_record {
168 struct sci_base_observer base_state_observer;
169 struct sci_base_observer starting_state_observer;
173 u32 state_transition_table[MAX_STATE_TRANSITION_RECORD];
176 #endif /* SCIC_DEBUG_ENABLED */
179 * This enumeration provides a named phy type for the state machine
183 enum SCIC_SDS_PHY_PROTOCOL {
185 * This is an unknown phy type since there is either nothing on the other
186 * end or we have not detected the phy type as yet.
188 SCIC_SDS_PHY_PROTOCOL_UNKNOWN,
193 SCIC_SDS_PHY_PROTOCOL_SAS,
198 SCIC_SDS_PHY_PROTOCOL_SATA,
200 SCIC_SDS_MAX_PHY_PROTOCOLS
204 * struct scic_sds_phy - This structure contains or references all of the data
205 * necessary to represent the core phy object and SCU harware protocol
210 struct scic_sds_phy {
211 struct sci_base_phy parent;
214 * This field specifies the port object that owns/contains this phy.
216 struct scic_sds_port *owning_port;
219 * This field indicates whether the phy supports 1.5 Gb/s, 3.0 Gb/s,
220 * or 6.0 Gb/s operation.
222 enum sci_sas_link_rate max_negotiated_speed;
225 * This member specifies the protocol being utilized on this phy. This
226 * field contains a legitamite value once the PHY has link trained with
229 enum SCIC_SDS_PHY_PROTOCOL protocol;
232 * This field specifies the index with which this phy is associated (0-3).
237 * This member indicates if this particular PHY has received a BCN while
238 * it had no port assignement. This BCN will be reported once the phy is
239 * assigned to a port.
241 bool bcn_received_while_port_unassigned;
244 * This field indicates if this PHY is currently in the process of
245 * link training (i.e. it has started OOB, but has yet to perform
246 * IAF exchange/Signature FIS reception).
248 bool is_in_link_training;
252 struct sci_sas_identify_address_frame identify_address_frame_buffer;
257 struct sata_fis_reg_d2h 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 struct sci_base_state_machine starting_substate_machine;
274 #ifdef SCIC_DEBUG_ENABLED
275 struct scic_sds_phy_state_record state_record;
276 #endif /* SCIC_DEBUG_ENABLED */
279 * This field points to the link layer register set within the SCU.
281 struct scu_link_layer_registers *link_layer_registers;
286 typedef enum sci_status (*SCIC_SDS_PHY_EVENT_HANDLER_T)(struct scic_sds_phy *, u32);
287 typedef enum sci_status (*SCIC_SDS_PHY_FRAME_HANDLER_T)(struct scic_sds_phy *, u32);
288 typedef enum sci_status (*SCIC_SDS_PHY_POWER_HANDLER_T)(struct scic_sds_phy *);
291 * struct scic_sds_phy_state_handler -
295 struct scic_sds_phy_state_handler {
297 * This is the struct sci_base_phy object state handlers.
299 struct sci_base_phy_state_handler parent;
302 * The state handler for unsolicited frames received from the SCU hardware.
304 SCIC_SDS_PHY_FRAME_HANDLER_T frame_handler;
307 * The state handler for events received from the SCU hardware.
309 SCIC_SDS_PHY_EVENT_HANDLER_T event_handler;
312 * The state handler for staggered spinup.
314 SCIC_SDS_PHY_POWER_HANDLER_T consume_power_handler;
318 extern struct scic_sds_phy_state_handler scic_sds_phy_state_handler_table[];
319 extern const struct sci_base_state scic_sds_phy_state_table[];
320 extern const struct sci_base_state scic_sds_phy_starting_substates[];
321 extern struct scic_sds_phy_state_handler
322 scic_sds_phy_starting_substate_handler_table[];
326 * scic_sds_phy_get_index() -
328 * This macro returns the phy index for the specified phy
330 #define scic_sds_phy_get_index(phy) \
334 * scic_sds_phy_get_controller() - This macro returns the controller for this
339 #define scic_sds_phy_get_controller(phy) \
340 (scic_sds_port_get_controller((phy)->owning_port))
343 * scic_sds_phy_get_base_state_machine() - This macro returns the state machine
348 #define scic_sds_phy_get_base_state_machine(phy) \
349 (&(phy)->parent.state_machine)
352 * scic_sds_phy_get_starting_substate_machine() - This macro returns the
353 * starting substate machine for this phy
357 #define scic_sds_phy_get_starting_substate_machine(phy) \
358 (&(phy)->starting_substate_machine)
361 * scic_sds_phy_set_state_handlers() - This macro sets the state handlers for
366 #define scic_sds_phy_set_state_handlers(phy, handlers) \
367 ((phy)->state_handlers = (handlers))
370 * scic_sds_phy_set_base_state_handlers() -
372 * This macro set the base state handlers for the phy object.
374 #define scic_sds_phy_set_base_state_handlers(phy, state_id) \
375 scic_sds_phy_set_state_handlers(\
377 &scic_sds_phy_state_handler_table[(state_id)] \
381 * scic_sds_phy_is_ready() -
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 /* --------------------------------------------------------------------------- */
399 /* --------------------------------------------------------------------------- */
401 void scic_sds_phy_construct(
402 struct scic_sds_phy *this_phy,
403 struct scic_sds_port *owning_port,
406 struct scic_sds_port *scic_sds_phy_get_port(
407 struct scic_sds_phy *this_phy);
409 void scic_sds_phy_set_port(
410 struct scic_sds_phy *this_phy,
411 struct scic_sds_port *owning_port);
413 enum sci_status scic_sds_phy_initialize(
414 struct scic_sds_phy *this_phy,
415 struct scu_link_layer_registers *link_layer_registers);
417 enum sci_status scic_sds_phy_start(
418 struct scic_sds_phy *this_phy);
420 enum sci_status scic_sds_phy_stop(
421 struct scic_sds_phy *this_phy);
423 enum sci_status scic_sds_phy_reset(
424 struct scic_sds_phy *this_phy);
426 /* --------------------------------------------------------------------------- */
428 void scic_sds_phy_suspend(
429 struct scic_sds_phy *this_phy);
431 void scic_sds_phy_resume(
432 struct scic_sds_phy *this_phy);
434 /* --------------------------------------------------------------------------- */
436 enum sci_status scic_sds_phy_event_handler(
437 struct scic_sds_phy *this_phy,
440 enum sci_status scic_sds_phy_frame_handler(
441 struct scic_sds_phy *this_phy,
444 enum sci_status scic_sds_phy_consume_power_handler(
445 struct scic_sds_phy *this_phy);
447 void scic_sds_phy_get_sas_address(
448 struct scic_sds_phy *this_phy,
449 struct sci_sas_address *sas_address);
451 void scic_sds_phy_get_attached_sas_address(
452 struct scic_sds_phy *this_phy,
453 struct sci_sas_address *sas_address);
455 void scic_sds_phy_get_protocols(
456 struct scic_sds_phy *this_phy,
457 struct sci_sas_identify_address_frame_protocols *protocols);
459 void scic_sds_phy_get_attached_phy_protocols(
460 struct scic_sds_phy *this_phy,
461 struct sci_sas_identify_address_frame_protocols *protocols);
464 * ****************************************************************************-
465 * * SCIC SDS PHY Handler Methods
466 * ****************************************************************************- */
468 enum sci_status scic_sds_phy_default_start_handler(
469 struct sci_base_phy *phy);
471 enum sci_status scic_sds_phy_default_stop_handler(
472 struct sci_base_phy *phy);
474 enum sci_status scic_sds_phy_default_reset_handler(
475 struct sci_base_phy *phy);
477 enum sci_status scic_sds_phy_default_destroy_handler(
478 struct sci_base_phy *phy);
480 enum sci_status scic_sds_phy_default_frame_handler(
481 struct scic_sds_phy *phy,
484 enum sci_status scic_sds_phy_default_event_handler(
485 struct scic_sds_phy *phy,
488 enum sci_status scic_sds_phy_default_consume_power_handler(
489 struct scic_sds_phy *phy);
491 #endif /* _SCIC_SDS_PHY_H_ */