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 struct scic_sds_port;
152 struct scic_sds_controller;
155 * This enumeration provides a named phy type for the state machine
159 enum scic_sds_phy_protocol {
161 * This is an unknown phy type since there is either nothing on the other
162 * end or we have not detected the phy type as yet.
164 SCIC_SDS_PHY_PROTOCOL_UNKNOWN,
169 SCIC_SDS_PHY_PROTOCOL_SAS,
174 SCIC_SDS_PHY_PROTOCOL_SATA,
176 SCIC_SDS_MAX_PHY_PROTOCOLS
180 * struct scic_sds_phy - This structure contains or references all of the data
181 * necessary to represent the core phy object and SCU harware protocol
186 struct scic_sds_phy {
187 struct sci_base_phy parent;
190 * This field specifies the port object that owns/contains this phy.
192 struct scic_sds_port *owning_port;
195 * This field indicates whether the phy supports 1.5 Gb/s, 3.0 Gb/s,
196 * or 6.0 Gb/s operation.
198 enum sci_sas_link_rate max_negotiated_speed;
201 * This member specifies the protocol being utilized on this phy. This
202 * field contains a legitamite value once the PHY has link trained with
205 enum scic_sds_phy_protocol protocol;
208 * This field specifies the index with which this phy is associated (0-3).
213 * This member indicates if this particular PHY has received a BCN while
214 * it had no port assignement. This BCN will be reported once the phy is
215 * assigned to a port.
217 bool bcn_received_while_port_unassigned;
220 * This field indicates if this PHY is currently in the process of
221 * link training (i.e. it has started OOB, but has yet to perform
222 * IAF exchange/Signature FIS reception).
224 bool is_in_link_training;
228 struct sci_sas_identify_address_frame identify_address_frame_buffer;
233 struct sata_fis_reg_d2h signature_fis_buffer;
240 * This field contains a reference to the timer utilized in detecting
241 * when a signature FIS timeout has occurred. The signature FIS is the
242 * first FIS sent by an attached SATA device after OOB/SN.
244 void *sata_timeout_timer;
246 const struct scic_sds_phy_state_handler *state_handlers;
248 struct sci_base_state_machine starting_substate_machine;
251 * This field is the pointer to the transport layer register for the SCU
254 struct scu_transport_layer_registers __iomem *transport_layer_registers;
257 * This field points to the link layer register set within the SCU.
259 struct scu_link_layer_registers __iomem *link_layer_registers;
264 typedef enum sci_status (*scic_sds_phy_event_handler_t)(struct scic_sds_phy *, u32);
265 typedef enum sci_status (*scic_sds_phy_frame_handler_t)(struct scic_sds_phy *, u32);
266 typedef enum sci_status (*scic_sds_phy_power_handler_t)(struct scic_sds_phy *);
269 * struct scic_sds_phy_state_handler -
273 struct scic_sds_phy_state_handler {
275 * This is the struct sci_base_phy object state handlers.
277 struct sci_base_phy_state_handler parent;
280 * The state handler for unsolicited frames received from the SCU hardware.
282 scic_sds_phy_frame_handler_t frame_handler;
285 * The state handler for events received from the SCU hardware.
287 scic_sds_phy_event_handler_t event_handler;
290 * The state handler for staggered spinup.
292 scic_sds_phy_power_handler_t consume_power_handler;
297 * scic_sds_phy_get_index() -
299 * This macro returns the phy index for the specified phy
301 #define scic_sds_phy_get_index(phy) \
305 * scic_sds_phy_get_controller() - This macro returns the controller for this
310 #define scic_sds_phy_get_controller(phy) \
311 (scic_sds_port_get_controller((phy)->owning_port))
314 * scic_sds_phy_set_state_handlers() - This macro sets the state handlers for
319 #define scic_sds_phy_set_state_handlers(phy, handlers) \
320 ((phy)->state_handlers = (handlers))
323 * scic_sds_phy_set_base_state_handlers() -
325 * This macro set the base state handlers for the phy object.
327 #define scic_sds_phy_set_base_state_handlers(phy, state_id) \
328 scic_sds_phy_set_state_handlers(\
330 &scic_sds_phy_state_handler_table[(state_id)] \
333 void scic_sds_phy_construct(
334 struct scic_sds_phy *this_phy,
335 struct scic_sds_port *owning_port,
338 struct scic_sds_port *scic_sds_phy_get_port(
339 struct scic_sds_phy *this_phy);
341 void scic_sds_phy_set_port(
342 struct scic_sds_phy *this_phy,
343 struct scic_sds_port *owning_port);
345 enum sci_status scic_sds_phy_initialize(
346 struct scic_sds_phy *this_phy,
347 struct scu_transport_layer_registers __iomem *transport_layer_registers,
348 struct scu_link_layer_registers __iomem *link_layer_registers);
350 enum sci_status scic_sds_phy_start(
351 struct scic_sds_phy *this_phy);
353 enum sci_status scic_sds_phy_stop(
354 struct scic_sds_phy *this_phy);
356 enum sci_status scic_sds_phy_reset(
357 struct scic_sds_phy *this_phy);
359 void scic_sds_phy_resume(
360 struct scic_sds_phy *this_phy);
362 void scic_sds_phy_setup_transport(
363 struct scic_sds_phy *this_phy,
366 enum sci_status scic_sds_phy_event_handler(
367 struct scic_sds_phy *this_phy,
370 enum sci_status scic_sds_phy_frame_handler(
371 struct scic_sds_phy *this_phy,
374 enum sci_status scic_sds_phy_consume_power_handler(
375 struct scic_sds_phy *this_phy);
377 void scic_sds_phy_get_sas_address(
378 struct scic_sds_phy *this_phy,
379 struct sci_sas_address *sas_address);
381 void scic_sds_phy_get_attached_sas_address(
382 struct scic_sds_phy *this_phy,
383 struct sci_sas_address *sas_address);
385 void scic_sds_phy_get_protocols(
386 struct scic_sds_phy *this_phy,
387 struct sci_sas_identify_address_frame_protocols *protocols);
389 void scic_sds_phy_get_attached_phy_protocols(
390 struct scic_sds_phy *this_phy,
391 struct sci_sas_identify_address_frame_protocols *protocols);
393 #endif /* _SCIC_SDS_PHY_H_ */