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_
59 #include "intel_sata.h"
60 #include "intel_sas.h"
61 #include "scu_registers.h"
62 #include "sci_base_state_machine.h"
63 #include <scsi/libsas.h>
69 * This is the timeout value for the SATA phy to wait for a SIGNATURE FIS
70 * before restarting the starting state machine. Technically, the old parallel
71 * ATA specification required up to 30 seconds for a device to issue its
72 * signature FIS as a result of a soft reset. Now we see that devices respond
73 * generally within 15 seconds, but we'll use 25 for now.
75 #define SCIC_SDS_SIGNATURE_FIS_TIMEOUT 25000
80 * This is the timeout for the SATA OOB/SN because the hardware does not
81 * recognize a hot plug after OOB signal but before the SN signals. We need to
82 * make sure after a hotplug timeout if we have not received the speed event
83 * notification from the hardware that we restart the hardware OOB state
86 #define SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT 250
88 enum scic_sds_phy_states
{
90 * Simply the initial state for the base domain state machine.
92 SCI_BASE_PHY_STATE_INITIAL
,
95 * This state indicates that the phy has successfully been stopped.
96 * In this state no new IO operations are permitted on this phy.
97 * This state is entered from the INITIAL state.
98 * This state is entered from the STARTING state.
99 * This state is entered from the READY state.
100 * This state is entered from the RESETTING state.
102 SCI_BASE_PHY_STATE_STOPPED
,
105 * This state indicates that the phy is in the process of becomming
106 * ready. In this state no new IO operations are permitted on this phy.
107 * This state is entered from the STOPPED state.
108 * This state is entered from the READY state.
109 * This state is entered from the RESETTING state.
111 SCI_BASE_PHY_STATE_STARTING
,
114 * This state indicates the the phy is now ready. Thus, the user
115 * is able to perform IO operations utilizing this phy as long as it
116 * is currently part of a valid port.
117 * This state is entered from the STARTING state.
119 SCI_BASE_PHY_STATE_READY
,
122 * This state indicates that the phy is in the process of being reset.
123 * In this state no new IO operations are permitted on this phy.
124 * This state is entered from the READY state.
126 SCI_BASE_PHY_STATE_RESETTING
,
129 * Simply the final state for the base phy state machine.
131 SCI_BASE_PHY_STATE_FINAL
,
136 * enum scic_sds_phy_starting_substates -
140 enum scic_sds_phy_starting_substates
{
144 SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL
,
147 * Wait state for the hardware OSSP event type notification
149 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
,
152 * Wait state for the PHY speed notification
154 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
,
157 * Wait state for the IAF Unsolicited frame notification
159 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
,
162 * Wait state for the request to consume power
164 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
,
167 * Wait state for request to consume power
169 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
,
172 * Wait state for the SATA PHY notification
174 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN
,
177 * Wait for the SATA PHY speed notification
179 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
,
182 * Wait state for the SIGNATURE FIS unsolicited frame notification
184 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
,
187 * Exit state for this state machine
189 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
,
192 struct scic_sds_port
;
193 struct scic_sds_controller
;
196 * This enumeration provides a named phy type for the state machine
200 enum scic_sds_phy_protocol
{
202 * This is an unknown phy type since there is either nothing on the other
203 * end or we have not detected the phy type as yet.
205 SCIC_SDS_PHY_PROTOCOL_UNKNOWN
,
210 SCIC_SDS_PHY_PROTOCOL_SAS
,
215 SCIC_SDS_PHY_PROTOCOL_SATA
,
217 SCIC_SDS_MAX_PHY_PROTOCOLS
222 * struct scic_sds_phy - This structure contains or references all of the data
223 * necessary to represent the core phy object and SCU harware protocol
228 struct scic_sds_phy
{
230 * This field depicts the peer object for the phy.
232 struct isci_phy
*iphy
;
235 * This field contains the information for the base phy state machine.
237 struct sci_base_state_machine state_machine
;
240 * This field specifies the port object that owns/contains this phy.
242 struct scic_sds_port
*owning_port
;
245 * This field indicates whether the phy supports 1.5 Gb/s, 3.0 Gb/s,
246 * or 6.0 Gb/s operation.
248 enum sas_linkrate max_negotiated_speed
;
251 * This member specifies the protocol being utilized on this phy. This
252 * field contains a legitamite value once the PHY has link trained with
255 enum scic_sds_phy_protocol protocol
;
258 * This field specifies the index with which this phy is associated (0-3).
263 * This member indicates if this particular PHY has received a BCN while
264 * it had no port assignement. This BCN will be reported once the phy is
265 * assigned to a port.
267 bool bcn_received_while_port_unassigned
;
270 * This field indicates if this PHY is currently in the process of
271 * link training (i.e. it has started OOB, but has yet to perform
272 * IAF exchange/Signature FIS reception).
274 bool is_in_link_training
;
278 struct sci_sas_identify_address_frame identify_address_frame_buffer
;
283 struct dev_to_host_fis signature_fis_buffer
;
290 * This field contains a reference to the timer utilized in detecting
291 * when a signature FIS timeout has occurred. The signature FIS is the
292 * first FIS sent by an attached SATA device after OOB/SN.
294 void *sata_timeout_timer
;
296 const struct scic_sds_phy_state_handler
*state_handlers
;
298 struct sci_base_state_machine starting_substate_machine
;
301 * This field is the pointer to the transport layer register for the SCU
304 struct scu_transport_layer_registers __iomem
*transport_layer_registers
;
307 * This field points to the link layer register set within the SCU.
309 struct scu_link_layer_registers __iomem
*link_layer_registers
;
313 typedef enum sci_status (*scic_sds_phy_handler_t
)(struct scic_sds_phy
*);
314 typedef enum sci_status (*scic_sds_phy_event_handler_t
)(struct scic_sds_phy
*, u32
);
315 typedef enum sci_status (*scic_sds_phy_frame_handler_t
)(struct scic_sds_phy
*, u32
);
316 typedef enum sci_status (*scic_sds_phy_power_handler_t
)(struct scic_sds_phy
*);
319 * struct scic_sds_phy_state_handler -
323 struct scic_sds_phy_state_handler
{
325 * The start_handler specifies the method invoked when there is an
326 * attempt to start a phy.
328 scic_sds_phy_handler_t start_handler
;
331 * The stop_handler specifies the method invoked when there is an
332 * attempt to stop a phy.
334 scic_sds_phy_handler_t stop_handler
;
337 * The reset_handler specifies the method invoked when there is an
338 * attempt to reset a phy.
340 scic_sds_phy_handler_t reset_handler
;
343 * The destruct_handler specifies the method invoked when attempting to
346 scic_sds_phy_handler_t destruct_handler
;
349 * The state handler for unsolicited frames received from the SCU hardware.
351 scic_sds_phy_frame_handler_t frame_handler
;
354 * The state handler for events received from the SCU hardware.
356 scic_sds_phy_event_handler_t event_handler
;
359 * The state handler for staggered spinup.
361 scic_sds_phy_power_handler_t consume_power_handler
;
366 * scic_sds_phy_get_index() -
368 * This macro returns the phy index for the specified phy
370 #define scic_sds_phy_get_index(phy) \
374 * scic_sds_phy_get_controller() - This macro returns the controller for this
379 #define scic_sds_phy_get_controller(phy) \
380 (scic_sds_port_get_controller((phy)->owning_port))
383 * scic_sds_phy_set_state_handlers() - This macro sets the state handlers for
388 #define scic_sds_phy_set_state_handlers(phy, handlers) \
389 ((phy)->state_handlers = (handlers))
392 * scic_sds_phy_set_base_state_handlers() -
394 * This macro set the base state handlers for the phy object.
396 #define scic_sds_phy_set_base_state_handlers(phy, state_id) \
397 scic_sds_phy_set_state_handlers(\
399 &scic_sds_phy_state_handler_table[(state_id)] \
402 void scic_sds_phy_construct(
403 struct scic_sds_phy
*this_phy
,
404 struct scic_sds_port
*owning_port
,
407 struct scic_sds_port
*scic_sds_phy_get_port(
408 struct scic_sds_phy
*this_phy
);
410 void scic_sds_phy_set_port(
411 struct scic_sds_phy
*this_phy
,
412 struct scic_sds_port
*owning_port
);
414 enum sci_status
scic_sds_phy_initialize(
415 struct scic_sds_phy
*this_phy
,
416 struct scu_transport_layer_registers __iomem
*transport_layer_registers
,
417 struct scu_link_layer_registers __iomem
*link_layer_registers
);
419 enum sci_status
scic_sds_phy_start(
420 struct scic_sds_phy
*this_phy
);
422 enum sci_status
scic_sds_phy_stop(
423 struct scic_sds_phy
*this_phy
);
425 enum sci_status
scic_sds_phy_reset(
426 struct scic_sds_phy
*this_phy
);
428 void scic_sds_phy_resume(
429 struct scic_sds_phy
*this_phy
);
431 void scic_sds_phy_setup_transport(
432 struct scic_sds_phy
*this_phy
,
435 enum sci_status
scic_sds_phy_event_handler(
436 struct scic_sds_phy
*this_phy
,
439 enum sci_status
scic_sds_phy_frame_handler(
440 struct scic_sds_phy
*this_phy
,
443 enum sci_status
scic_sds_phy_consume_power_handler(
444 struct scic_sds_phy
*this_phy
);
446 void scic_sds_phy_get_sas_address(
447 struct scic_sds_phy
*this_phy
,
448 struct sci_sas_address
*sas_address
);
450 void scic_sds_phy_get_attached_sas_address(
451 struct scic_sds_phy
*this_phy
,
452 struct sci_sas_address
*sas_address
);
454 void scic_sds_phy_get_protocols(
455 struct scic_sds_phy
*this_phy
,
456 struct sci_sas_identify_address_frame_protocols
*protocols
);
458 void scic_sds_phy_get_attached_phy_protocols(
459 struct scic_sds_phy
*this_phy
,
460 struct sci_sas_identify_address_frame_protocols
*protocols
);
462 #endif /* _SCIC_SDS_PHY_H_ */