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 #include "intel_ata.h"
57 #include "intel_sata.h"
58 #include "sci_base_state.h"
59 #include "sci_base_state_machine.h"
61 #include "scic_sds_controller.h"
62 #include "scic_sds_phy.h"
63 #include "scic_sds_port.h"
64 #include "remote_node_context.h"
65 #include "sci_environment.h"
67 #include "scu_event_codes.h"
69 #define SCIC_SDS_PHY_MIN_TIMER_COUNT (SCI_MAX_PHYS)
70 #define SCIC_SDS_PHY_MAX_TIMER_COUNT (SCI_MAX_PHYS)
72 /* Maximum arbitration wait time in micro-seconds */
73 #define SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME (700)
75 enum sas_linkrate
sci_phy_linkrate(struct scic_sds_phy
*sci_phy
)
77 return sci_phy
->max_negotiated_speed
;
81 * *****************************************************************************
82 * * SCIC SDS PHY Internal Methods
83 * ***************************************************************************** */
86 * This method will initialize the phy transport layer registers
88 * @transport_layer_registers
92 static enum sci_status
scic_sds_phy_transport_layer_initialization(
93 struct scic_sds_phy
*sci_phy
,
94 struct scu_transport_layer_registers __iomem
*transport_layer_registers
)
98 sci_phy
->transport_layer_registers
= transport_layer_registers
;
100 writel(SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
,
101 &sci_phy
->transport_layer_registers
->stp_rni
);
104 * Hardware team recommends that we enable the STP prefetch for all
107 tl_control
= readl(&sci_phy
->transport_layer_registers
->control
);
108 tl_control
|= SCU_TLCR_GEN_BIT(STP_WRITE_DATA_PREFETCH
);
109 writel(tl_control
, &sci_phy
->transport_layer_registers
->control
);
115 * This method will initialize the phy link layer registers
117 * @link_layer_registers:
121 static enum sci_status
122 scic_sds_phy_link_layer_initialization(struct scic_sds_phy
*sci_phy
,
123 struct scu_link_layer_registers __iomem
*link_layer_registers
)
125 struct scic_sds_controller
*scic
= sci_phy
->owning_port
->owning_controller
;
126 int phy_idx
= sci_phy
->phy_index
;
127 struct sci_phy_user_params
*phy_user
= &scic
->user_parameters
.sds1
.phys
[phy_idx
];
128 struct sci_phy_oem_params
*phy_oem
= &scic
->oem_parameters
.sds1
.phys
[phy_idx
];
129 u32 phy_configuration
;
130 struct sas_capabilities phy_capabilities
;
131 u32 parity_check
= 0;
132 u32 parity_count
= 0;
133 u32 llctl
, link_rate
;
136 sci_phy
->link_layer_registers
= link_layer_registers
;
138 /* Set our IDENTIFY frame data */
139 #define SCI_END_DEVICE 0x01
141 writel(SCU_SAS_TIID_GEN_BIT(SMP_INITIATOR
) |
142 SCU_SAS_TIID_GEN_BIT(SSP_INITIATOR
) |
143 SCU_SAS_TIID_GEN_BIT(STP_INITIATOR
) |
144 SCU_SAS_TIID_GEN_BIT(DA_SATA_HOST
) |
145 SCU_SAS_TIID_GEN_VAL(DEVICE_TYPE
, SCI_END_DEVICE
),
146 &sci_phy
->link_layer_registers
->transmit_identification
);
148 /* Write the device SAS Address */
149 writel(0xFEDCBA98, &sci_phy
->link_layer_registers
->sas_device_name_high
);
150 writel(phy_idx
, &sci_phy
->link_layer_registers
->sas_device_name_low
);
152 /* Write the source SAS Address */
153 writel(phy_oem
->sas_address
.high
,
154 &sci_phy
->link_layer_registers
->source_sas_address_high
);
155 writel(phy_oem
->sas_address
.low
,
156 &sci_phy
->link_layer_registers
->source_sas_address_low
);
158 /* Clear and Set the PHY Identifier */
159 writel(0, &sci_phy
->link_layer_registers
->identify_frame_phy_id
);
160 writel(SCU_SAS_TIPID_GEN_VALUE(ID
, phy_idx
),
161 &sci_phy
->link_layer_registers
->identify_frame_phy_id
);
163 /* Change the initial state of the phy configuration register */
165 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
167 /* Hold OOB state machine in reset */
168 phy_configuration
|= SCU_SAS_PCFG_GEN_BIT(OOB_RESET
);
169 writel(phy_configuration
,
170 &sci_phy
->link_layer_registers
->phy_configuration
);
172 /* Configure the SNW capabilities */
173 phy_capabilities
.u
.all
= 0;
174 phy_capabilities
.u
.bits
.start
= 1;
175 phy_capabilities
.u
.bits
.gen3_without_ssc_supported
= 1;
176 phy_capabilities
.u
.bits
.gen2_without_ssc_supported
= 1;
177 phy_capabilities
.u
.bits
.gen1_without_ssc_supported
= 1;
178 if (scic
->oem_parameters
.sds1
.controller
.do_enable_ssc
== true) {
179 phy_capabilities
.u
.bits
.gen3_with_ssc_supported
= 1;
180 phy_capabilities
.u
.bits
.gen2_with_ssc_supported
= 1;
181 phy_capabilities
.u
.bits
.gen1_with_ssc_supported
= 1;
185 * The SAS specification indicates that the phy_capabilities that
186 * are transmitted shall have an even parity. Calculate the parity. */
187 parity_check
= phy_capabilities
.u
.all
;
188 while (parity_check
!= 0) {
189 if (parity_check
& 0x1)
195 * If parity indicates there are an odd number of bits set, then
196 * set the parity bit to 1 in the phy capabilities. */
197 if ((parity_count
% 2) != 0)
198 phy_capabilities
.u
.bits
.parity
= 1;
200 writel(phy_capabilities
.u
.all
,
201 &sci_phy
->link_layer_registers
->phy_capabilities
);
203 /* Set the enable spinup period but disable the ability to send
204 * notify enable spinup
206 writel(SCU_ENSPINUP_GEN_VAL(COUNT
,
207 phy_user
->notify_enable_spin_up_insertion_frequency
),
208 &sci_phy
->link_layer_registers
->notify_enable_spinup_control
);
210 /* Write the ALIGN Insertion Ferequency for connected phy and
211 * inpendent of connected state
213 clksm_value
= SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(CONNECTED
,
214 phy_user
->in_connection_align_insertion_frequency
);
216 clksm_value
|= SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(GENERAL
,
217 phy_user
->align_insertion_frequency
);
219 writel(clksm_value
, &sci_phy
->link_layer_registers
->clock_skew_management
);
221 /* @todo Provide a way to write this register correctly */
223 &sci_phy
->link_layer_registers
->afe_lookup_table_control
);
225 llctl
= SCU_SAS_LLCTL_GEN_VAL(NO_OUTBOUND_TASK_TIMEOUT
,
226 (u8
)scic
->user_parameters
.sds1
.no_outbound_task_timeout
);
228 switch(phy_user
->max_speed_generation
) {
229 case SCIC_SDS_PARM_GEN3_SPEED
:
230 link_rate
= SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN3
;
232 case SCIC_SDS_PARM_GEN2_SPEED
:
233 link_rate
= SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN2
;
236 link_rate
= SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN1
;
239 llctl
|= SCU_SAS_LLCTL_GEN_VAL(MAX_LINK_RATE
, link_rate
);
240 writel(llctl
, &sci_phy
->link_layer_registers
->link_layer_control
);
242 if (is_a0() || is_a2()) {
243 /* Program the max ARB time for the PHY to 700us so we inter-operate with
244 * the PMC expander which shuts down PHYs if the expander PHY generates too
245 * many breaks. This time value will guarantee that the initiator PHY will
246 * generate the break.
248 writel(SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME
,
249 &sci_phy
->link_layer_registers
->maximum_arbitration_wait_timer_timeout
);
253 * Set the link layer hang detection to 500ms (0x1F4) from its default
254 * value of 128ms. Max value is 511 ms.
256 writel(0x1F4, &sci_phy
->link_layer_registers
->link_layer_hang_detection_timeout
);
258 /* We can exit the initial state to the stopped state */
259 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
260 SCI_BASE_PHY_STATE_STOPPED
);
266 * This function will handle the sata SIGNATURE FIS timeout condition. It will
267 * restart the starting substate machine since we dont know what has actually
270 static void scic_sds_phy_sata_timeout(void *phy
)
272 struct scic_sds_phy
*sci_phy
= phy
;
274 dev_dbg(sciphy_to_dev(sci_phy
),
275 "%s: SCIC SDS Phy 0x%p did not receive signature fis before "
280 sci_base_state_machine_stop(&sci_phy
->starting_substate_machine
);
282 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
283 SCI_BASE_PHY_STATE_STARTING
);
287 * This method returns the port currently containing this phy. If the phy is
288 * currently contained by the dummy port, then the phy is considered to not
290 * @sci_phy: This parameter specifies the phy for which to retrieve the
293 * This method returns a handle to a port that contains the supplied phy.
294 * NULL This value is returned if the phy is not part of a real
295 * port (i.e. it's contained in the dummy port). !NULL All other
296 * values indicate a handle/pointer to the port containing the phy.
298 struct scic_sds_port
*scic_sds_phy_get_port(
299 struct scic_sds_phy
*sci_phy
)
301 if (scic_sds_port_get_index(sci_phy
->owning_port
) == SCIC_SDS_DUMMY_PORT
)
304 return sci_phy
->owning_port
;
308 * This method will assign a port to the phy object.
309 * @out]: sci_phy This parameter specifies the phy for which to assign a port
314 void scic_sds_phy_set_port(
315 struct scic_sds_phy
*sci_phy
,
316 struct scic_sds_port
*sci_port
)
318 sci_phy
->owning_port
= sci_port
;
320 if (sci_phy
->bcn_received_while_port_unassigned
) {
321 sci_phy
->bcn_received_while_port_unassigned
= false;
322 scic_sds_port_broadcast_change_received(sci_phy
->owning_port
, sci_phy
);
327 * This method will initialize the constructed phy
329 * @link_layer_registers:
333 enum sci_status
scic_sds_phy_initialize(
334 struct scic_sds_phy
*sci_phy
,
335 struct scu_transport_layer_registers __iomem
*transport_layer_registers
,
336 struct scu_link_layer_registers __iomem
*link_layer_registers
)
338 struct scic_sds_controller
*scic
= scic_sds_phy_get_controller(sci_phy
);
339 struct isci_host
*ihost
= scic
->ihost
;
341 /* Create the SIGNATURE FIS Timeout timer for this phy */
342 sci_phy
->sata_timeout_timer
=
346 scic_sds_phy_sata_timeout
);
348 /* Perfrom the initialization of the TL hardware */
349 scic_sds_phy_transport_layer_initialization(
351 transport_layer_registers
);
353 /* Perofrm the initialization of the PE hardware */
354 scic_sds_phy_link_layer_initialization(sci_phy
, link_layer_registers
);
357 * There is nothing that needs to be done in this state just
358 * transition to the stopped state. */
359 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
360 SCI_BASE_PHY_STATE_STOPPED
);
366 * This method assigns the direct attached device ID for this phy.
368 * @sci_phy The phy for which the direct attached device id is to
370 * @device_id The direct attached device ID to assign to the phy.
371 * This will either be the RNi for the device or an invalid RNi if there
372 * is no current device assigned to the phy.
374 void scic_sds_phy_setup_transport(
375 struct scic_sds_phy
*sci_phy
,
380 writel(device_id
, &sci_phy
->transport_layer_registers
->stp_rni
);
383 * The read should guarantee that the first write gets posted
384 * before the next write
386 tl_control
= readl(&sci_phy
->transport_layer_registers
->control
);
387 tl_control
|= SCU_TLCR_GEN_BIT(CLEAR_TCI_NCQ_MAPPING_TABLE
);
388 writel(tl_control
, &sci_phy
->transport_layer_registers
->control
);
393 * @sci_phy: The phy object to be suspended.
395 * This function will perform the register reads/writes to suspend the SCU
396 * hardware protocol engine. none
398 static void scic_sds_phy_suspend(
399 struct scic_sds_phy
*sci_phy
)
401 u32 scu_sas_pcfg_value
;
404 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
405 scu_sas_pcfg_value
|= SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE
);
406 writel(scu_sas_pcfg_value
,
407 &sci_phy
->link_layer_registers
->phy_configuration
);
409 scic_sds_phy_setup_transport(
411 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
);
416 * @sci_phy: The phy object to resume.
418 * This function will perform the register reads/writes required to resume the
419 * SCU hardware protocol engine. none
421 void scic_sds_phy_resume(
422 struct scic_sds_phy
*sci_phy
)
424 u32 scu_sas_pcfg_value
;
427 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
428 scu_sas_pcfg_value
&= ~SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE
);
429 writel(scu_sas_pcfg_value
,
430 &sci_phy
->link_layer_registers
->phy_configuration
);
434 * This method returns the local sas address assigned to this phy.
435 * @sci_phy: This parameter specifies the phy for which to retrieve the local
437 * @sas_address: This parameter specifies the location into which to copy the
441 void scic_sds_phy_get_sas_address(
442 struct scic_sds_phy
*sci_phy
,
443 struct sci_sas_address
*sas_address
)
445 sas_address
->high
= readl(&sci_phy
->link_layer_registers
->source_sas_address_high
);
446 sas_address
->low
= readl(&sci_phy
->link_layer_registers
->source_sas_address_low
);
450 * This method returns the remote end-point (i.e. attached) sas address
451 * assigned to this phy.
452 * @sci_phy: This parameter specifies the phy for which to retrieve the remote
453 * end-point SAS address.
454 * @sas_address: This parameter specifies the location into which to copy the
455 * remote end-point SAS address.
458 void scic_sds_phy_get_attached_sas_address(
459 struct scic_sds_phy
*sci_phy
,
460 struct sci_sas_address
*sas_address
)
463 = sci_phy
->phy_type
.sas
.identify_address_frame_buffer
.sas_address
.high
;
465 = sci_phy
->phy_type
.sas
.identify_address_frame_buffer
.sas_address
.low
;
469 * This method returns the supported protocols assigned to this phy
474 void scic_sds_phy_get_protocols(
475 struct scic_sds_phy
*sci_phy
,
476 struct sci_sas_identify_address_frame_protocols
*protocols
)
479 (u16
)(readl(&sci_phy
->
480 link_layer_registers
->transmit_identification
) &
486 * @sci_phy: The parameter is the phy object for which the attached phy
487 * protcols are to be returned.
489 * This method returns the supported protocols for the attached phy. If this
490 * is a SAS phy the protocols are returned from the identify address frame. If
491 * this is a SATA phy then protocols are made up and the target phy is an STP
492 * target phy. The caller will get the entire set of bits for the protocol
495 void scic_sds_phy_get_attached_phy_protocols(
496 struct scic_sds_phy
*sci_phy
,
497 struct sci_sas_identify_address_frame_protocols
*protocols
)
499 protocols
->u
.all
= 0;
501 if (sci_phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SAS
) {
503 sci_phy
->phy_type
.sas
.identify_address_frame_buffer
.protocols
.u
.all
;
504 } else if (sci_phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SATA
) {
505 protocols
->u
.bits
.stp_target
= 1;
510 * *****************************************************************************
511 * * SCIC SDS PHY Handler Redirects
512 * ***************************************************************************** */
515 * This method will attempt to start the phy object. This request is only valid
516 * when the phy is in the stopped state
521 enum sci_status
scic_sds_phy_start(struct scic_sds_phy
*sci_phy
)
523 return sci_phy
->state_handlers
->start_handler(sci_phy
);
527 * This method will attempt to stop the phy object.
530 * enum sci_status SCI_SUCCESS if the phy is going to stop SCI_INVALID_STATE
531 * if the phy is not in a valid state to stop
533 enum sci_status
scic_sds_phy_stop(struct scic_sds_phy
*sci_phy
)
535 return sci_phy
->state_handlers
->stop_handler(sci_phy
);
539 * This method will attempt to reset the phy. This request is only valid when
540 * the phy is in an ready state
545 enum sci_status
scic_sds_phy_reset(
546 struct scic_sds_phy
*sci_phy
)
548 return sci_phy
->state_handlers
->reset_handler(sci_phy
);
552 * This method will process the event code received.
558 enum sci_status
scic_sds_phy_event_handler(
559 struct scic_sds_phy
*sci_phy
,
562 return sci_phy
->state_handlers
->event_handler(sci_phy
, event_code
);
566 * This method will process the frame index received.
572 enum sci_status
scic_sds_phy_frame_handler(
573 struct scic_sds_phy
*sci_phy
,
576 return sci_phy
->state_handlers
->frame_handler(sci_phy
, frame_index
);
580 * This method will give the phy permission to consume power
585 enum sci_status
scic_sds_phy_consume_power_handler(
586 struct scic_sds_phy
*sci_phy
)
588 return sci_phy
->state_handlers
->consume_power_handler(sci_phy
);
592 * *****************************************************************************
593 * * SCIC PHY Public Methods
594 * ***************************************************************************** */
597 enum sci_status
scic_sas_phy_get_properties(
598 struct scic_sds_phy
*sci_phy
,
599 struct scic_sas_phy_properties
*properties
)
601 if (sci_phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SAS
) {
603 &properties
->received_iaf
,
604 &sci_phy
->phy_type
.sas
.identify_address_frame_buffer
,
605 sizeof(struct sci_sas_identify_address_frame
)
608 properties
->received_capabilities
.u
.all
=
609 readl(&sci_phy
->link_layer_registers
->receive_phycap
);
618 enum sci_status
scic_sata_phy_get_properties(
619 struct scic_sds_phy
*sci_phy
,
620 struct scic_sata_phy_properties
*properties
)
622 if (sci_phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SATA
) {
624 &properties
->signature_fis
,
625 &sci_phy
->phy_type
.sata
.signature_fis_buffer
,
626 sizeof(struct sata_fis_reg_d2h
)
629 /* / @todo add support for port selectors. */
630 properties
->is_port_selector_present
= false;
639 * *****************************************************************************
640 * * SCIC SDS PHY HELPER FUNCTIONS
641 * ***************************************************************************** */
646 * @sci_phy: The phy object that received SAS PHY DETECTED.
648 * This method continues the link training for the phy as if it were a SAS PHY
649 * instead of a SATA PHY. This is done because the completion queue had a SAS
650 * PHY DETECTED event when the state machine was expecting a SATA PHY event.
653 static void scic_sds_phy_start_sas_link_training(
654 struct scic_sds_phy
*sci_phy
)
659 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
660 phy_control
|= SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD
);
662 &sci_phy
->link_layer_registers
->phy_configuration
);
664 sci_base_state_machine_change_state(
665 &sci_phy
->starting_substate_machine
,
666 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
669 sci_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_SAS
;
674 * @sci_phy: The phy object that received a SATA SPINUP HOLD event
676 * This method continues the link training for the phy as if it were a SATA PHY
677 * instead of a SAS PHY. This is done because the completion queue had a SATA
678 * SPINUP HOLD event when the state machine was expecting a SAS PHY event. none
680 static void scic_sds_phy_start_sata_link_training(
681 struct scic_sds_phy
*sci_phy
)
683 sci_base_state_machine_change_state(
684 &sci_phy
->starting_substate_machine
,
685 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
688 sci_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_SATA
;
692 * scic_sds_phy_complete_link_training - perform processing common to
693 * all protocols upon completion of link training.
694 * @sci_phy: This parameter specifies the phy object for which link training
696 * @max_link_rate: This parameter specifies the maximum link rate to be
697 * associated with this phy.
698 * @next_state: This parameter specifies the next state for the phy's starting
702 static void scic_sds_phy_complete_link_training(
703 struct scic_sds_phy
*sci_phy
,
704 enum sas_linkrate max_link_rate
,
707 sci_phy
->max_negotiated_speed
= max_link_rate
;
709 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
713 static void scic_sds_phy_restart_starting_state(
714 struct scic_sds_phy
*sci_phy
)
716 /* Stop the current substate machine */
717 sci_base_state_machine_stop(&sci_phy
->starting_substate_machine
);
719 /* Re-enter the base state machine starting state */
720 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
721 SCI_BASE_PHY_STATE_STARTING
);
724 /* ****************************************************************************
725 * SCIC SDS PHY general handlers
726 ************************************************************************** */
727 static enum sci_status
scic_sds_phy_starting_substate_general_stop_handler(
728 struct scic_sds_phy
*phy
)
730 sci_base_state_machine_stop(&phy
->starting_substate_machine
);
732 sci_base_state_machine_change_state(&phy
->state_machine
,
733 SCI_BASE_PHY_STATE_STOPPED
);
739 * *****************************************************************************
740 * * SCIC SDS PHY EVENT_HANDLERS
741 * ***************************************************************************** */
745 * @phy: This struct scic_sds_phy object which has received an event.
746 * @event_code: This is the event code which the phy object is to decode.
748 * This method is called when an event notification is received for the phy
749 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. -
750 * decode the event - sas phy detected causes a state transition to the wait
751 * for speed event notification. - any other events log a warning message and
752 * set a failure status enum sci_status SCI_SUCCESS on any valid event notification
753 * SCI_FAILURE on any unexpected event notifation
755 static enum sci_status
scic_sds_phy_starting_substate_await_ossp_event_handler(
756 struct scic_sds_phy
*sci_phy
,
759 u32 result
= SCI_SUCCESS
;
761 switch (scu_get_event_code(event_code
)) {
762 case SCU_EVENT_SAS_PHY_DETECTED
:
763 scic_sds_phy_start_sas_link_training(sci_phy
);
764 sci_phy
->is_in_link_training
= true;
767 case SCU_EVENT_SATA_SPINUP_HOLD
:
768 scic_sds_phy_start_sata_link_training(sci_phy
);
769 sci_phy
->is_in_link_training
= true;
773 dev_dbg(sciphy_to_dev(sci_phy
),
774 "%s: PHY starting substate machine received "
775 "unexpected event_code %x\n",
779 result
= SCI_FAILURE
;
788 * @phy: This struct scic_sds_phy object which has received an event.
789 * @event_code: This is the event code which the phy object is to decode.
791 * This method is called when an event notification is received for the phy
792 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. -
793 * decode the event - sas phy detected returns us back to this state. - speed
794 * event detected causes a state transition to the wait for iaf. - identify
795 * timeout is an un-expected event and the state machine is restarted. - link
796 * failure events restart the starting state machine - any other events log a
797 * warning message and set a failure status enum sci_status SCI_SUCCESS on any valid
798 * event notification SCI_FAILURE on any unexpected event notifation
800 static enum sci_status
scic_sds_phy_starting_substate_await_sas_phy_speed_event_handler(
801 struct scic_sds_phy
*sci_phy
,
804 u32 result
= SCI_SUCCESS
;
806 switch (scu_get_event_code(event_code
)) {
807 case SCU_EVENT_SAS_PHY_DETECTED
:
809 * Why is this being reported again by the controller?
810 * We would re-enter this state so just stay here */
813 case SCU_EVENT_SAS_15
:
814 case SCU_EVENT_SAS_15_SSC
:
815 scic_sds_phy_complete_link_training(
817 SAS_LINK_RATE_1_5_GBPS
,
818 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
);
821 case SCU_EVENT_SAS_30
:
822 case SCU_EVENT_SAS_30_SSC
:
823 scic_sds_phy_complete_link_training(
825 SAS_LINK_RATE_3_0_GBPS
,
826 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
);
829 case SCU_EVENT_SAS_60
:
830 case SCU_EVENT_SAS_60_SSC
:
831 scic_sds_phy_complete_link_training(
833 SAS_LINK_RATE_6_0_GBPS
,
834 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
);
837 case SCU_EVENT_SATA_SPINUP_HOLD
:
839 * We were doing SAS PHY link training and received a SATA PHY event
840 * continue OOB/SN as if this were a SATA PHY */
841 scic_sds_phy_start_sata_link_training(sci_phy
);
844 case SCU_EVENT_LINK_FAILURE
:
845 /* Link failure change state back to the starting state */
846 scic_sds_phy_restart_starting_state(sci_phy
);
850 dev_warn(sciphy_to_dev(sci_phy
),
851 "%s: PHY starting substate machine received "
852 "unexpected event_code %x\n",
856 result
= SCI_FAILURE
;
865 * @phy: This struct scic_sds_phy object which has received an event.
866 * @event_code: This is the event code which the phy object is to decode.
868 * This method is called when an event notification is received for the phy
869 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. -
870 * decode the event - sas phy detected event backs up the state machine to the
871 * await speed notification. - identify timeout is an un-expected event and the
872 * state machine is restarted. - link failure events restart the starting state
873 * machine - any other events log a warning message and set a failure status
874 * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any
875 * unexpected event notifation
877 static enum sci_status
scic_sds_phy_starting_substate_await_iaf_uf_event_handler(
878 struct scic_sds_phy
*sci_phy
,
881 u32 result
= SCI_SUCCESS
;
883 switch (scu_get_event_code(event_code
)) {
884 case SCU_EVENT_SAS_PHY_DETECTED
:
885 /* Backup the state machine */
886 scic_sds_phy_start_sas_link_training(sci_phy
);
889 case SCU_EVENT_SATA_SPINUP_HOLD
:
891 * We were doing SAS PHY link training and received a SATA PHY event
892 * continue OOB/SN as if this were a SATA PHY */
893 scic_sds_phy_start_sata_link_training(sci_phy
);
896 case SCU_EVENT_RECEIVED_IDENTIFY_TIMEOUT
:
897 case SCU_EVENT_LINK_FAILURE
:
898 case SCU_EVENT_HARD_RESET_RECEIVED
:
899 /* Start the oob/sn state machine over again */
900 scic_sds_phy_restart_starting_state(sci_phy
);
904 dev_warn(sciphy_to_dev(sci_phy
),
905 "%s: PHY starting substate machine received "
906 "unexpected event_code %x\n",
910 result
= SCI_FAILURE
;
919 * @phy: This struct scic_sds_phy object which has received an event.
920 * @event_code: This is the event code which the phy object is to decode.
922 * This method is called when an event notification is received for the phy
923 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_POWER. -
924 * decode the event - link failure events restart the starting state machine -
925 * any other events log a warning message and set a failure status enum sci_status
926 * SCI_SUCCESS on a link failure event SCI_FAILURE on any unexpected event
929 static enum sci_status
scic_sds_phy_starting_substate_await_sas_power_event_handler(
930 struct scic_sds_phy
*sci_phy
,
933 u32 result
= SCI_SUCCESS
;
935 switch (scu_get_event_code(event_code
)) {
936 case SCU_EVENT_LINK_FAILURE
:
937 /* Link failure change state back to the starting state */
938 scic_sds_phy_restart_starting_state(sci_phy
);
942 dev_warn(sciphy_to_dev(sci_phy
),
943 "%s: PHY starting substate machine received unexpected "
948 result
= SCI_FAILURE
;
957 * @phy: This struct scic_sds_phy object which has received an event.
958 * @event_code: This is the event code which the phy object is to decode.
960 * This method is called when an event notification is received for the phy
961 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. -
962 * decode the event - link failure events restart the starting state machine -
963 * sata spinup hold events are ignored since they are expected - any other
964 * events log a warning message and set a failure status enum sci_status SCI_SUCCESS
965 * on a link failure event SCI_FAILURE on any unexpected event notifation
967 static enum sci_status
scic_sds_phy_starting_substate_await_sata_power_event_handler(
968 struct scic_sds_phy
*sci_phy
,
971 u32 result
= SCI_SUCCESS
;
973 switch (scu_get_event_code(event_code
)) {
974 case SCU_EVENT_LINK_FAILURE
:
975 /* Link failure change state back to the starting state */
976 scic_sds_phy_restart_starting_state(sci_phy
);
979 case SCU_EVENT_SATA_SPINUP_HOLD
:
980 /* These events are received every 10ms and are expected while in this state */
983 case SCU_EVENT_SAS_PHY_DETECTED
:
985 * There has been a change in the phy type before OOB/SN for the
986 * SATA finished start down the SAS link traning path. */
987 scic_sds_phy_start_sas_link_training(sci_phy
);
991 dev_warn(sciphy_to_dev(sci_phy
),
992 "%s: PHY starting substate machine received "
993 "unexpected event_code %x\n",
997 result
= SCI_FAILURE
;
1005 * scic_sds_phy_starting_substate_await_sata_phy_event_handler -
1006 * @phy: This struct scic_sds_phy object which has received an event.
1007 * @event_code: This is the event code which the phy object is to decode.
1009 * This method is called when an event notification is received for the phy
1010 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. -
1011 * decode the event - link failure events restart the starting state machine -
1012 * sata spinup hold events are ignored since they are expected - sata phy
1013 * detected event change to the wait speed event - any other events log a
1014 * warning message and set a failure status enum sci_status SCI_SUCCESS on a link
1015 * failure event SCI_FAILURE on any unexpected event notifation
1017 static enum sci_status
scic_sds_phy_starting_substate_await_sata_phy_event_handler(
1018 struct scic_sds_phy
*sci_phy
, u32 event_code
)
1020 u32 result
= SCI_SUCCESS
;
1022 switch (scu_get_event_code(event_code
)) {
1023 case SCU_EVENT_LINK_FAILURE
:
1024 /* Link failure change state back to the starting state */
1025 scic_sds_phy_restart_starting_state(sci_phy
);
1028 case SCU_EVENT_SATA_SPINUP_HOLD
:
1029 /* These events might be received since we dont know how many may be in
1030 * the completion queue while waiting for power
1034 case SCU_EVENT_SATA_PHY_DETECTED
:
1035 sci_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_SATA
;
1037 /* We have received the SATA PHY notification change state */
1038 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1039 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
);
1042 case SCU_EVENT_SAS_PHY_DETECTED
:
1043 /* There has been a change in the phy type before OOB/SN for the
1044 * SATA finished start down the SAS link traning path.
1046 scic_sds_phy_start_sas_link_training(sci_phy
);
1050 dev_warn(sciphy_to_dev(sci_phy
),
1051 "%s: PHY starting substate machine received "
1052 "unexpected event_code %x\n",
1056 result
= SCI_FAILURE
;
1065 * @phy: This struct scic_sds_phy object which has received an event.
1066 * @event_code: This is the event code which the phy object is to decode.
1068 * This method is called when an event notification is received for the phy
1069 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN.
1070 * - decode the event - sata phy detected returns us back to this state. -
1071 * speed event detected causes a state transition to the wait for signature. -
1072 * link failure events restart the starting state machine - any other events
1073 * log a warning message and set a failure status enum sci_status SCI_SUCCESS on any
1074 * valid event notification SCI_FAILURE on any unexpected event notifation
1076 static enum sci_status
scic_sds_phy_starting_substate_await_sata_speed_event_handler(
1077 struct scic_sds_phy
*sci_phy
,
1080 u32 result
= SCI_SUCCESS
;
1082 switch (scu_get_event_code(event_code
)) {
1083 case SCU_EVENT_SATA_PHY_DETECTED
:
1085 * The hardware reports multiple SATA PHY detected events
1086 * ignore the extras */
1089 case SCU_EVENT_SATA_15
:
1090 case SCU_EVENT_SATA_15_SSC
:
1091 scic_sds_phy_complete_link_training(
1093 SAS_LINK_RATE_1_5_GBPS
,
1094 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
);
1097 case SCU_EVENT_SATA_30
:
1098 case SCU_EVENT_SATA_30_SSC
:
1099 scic_sds_phy_complete_link_training(
1101 SAS_LINK_RATE_3_0_GBPS
,
1102 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
);
1105 case SCU_EVENT_SATA_60
:
1106 case SCU_EVENT_SATA_60_SSC
:
1107 scic_sds_phy_complete_link_training(
1109 SAS_LINK_RATE_6_0_GBPS
,
1110 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
);
1113 case SCU_EVENT_LINK_FAILURE
:
1114 /* Link failure change state back to the starting state */
1115 scic_sds_phy_restart_starting_state(sci_phy
);
1118 case SCU_EVENT_SAS_PHY_DETECTED
:
1120 * There has been a change in the phy type before OOB/SN for the
1121 * SATA finished start down the SAS link traning path. */
1122 scic_sds_phy_start_sas_link_training(sci_phy
);
1126 dev_warn(sciphy_to_dev(sci_phy
),
1127 "%s: PHY starting substate machine received "
1128 "unexpected event_code %x\n",
1132 result
= SCI_FAILURE
;
1140 * scic_sds_phy_starting_substate_await_sig_fis_event_handler -
1141 * @phy: This struct scic_sds_phy object which has received an event.
1142 * @event_code: This is the event code which the phy object is to decode.
1144 * This method is called when an event notification is received for the phy
1145 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. -
1146 * decode the event - sas phy detected event backs up the state machine to the
1147 * await speed notification. - identify timeout is an un-expected event and the
1148 * state machine is restarted. - link failure events restart the starting state
1149 * machine - any other events log a warning message and set a failure status
1150 * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any
1151 * unexpected event notifation
1153 static enum sci_status
scic_sds_phy_starting_substate_await_sig_fis_event_handler(
1154 struct scic_sds_phy
*sci_phy
, u32 event_code
)
1156 u32 result
= SCI_SUCCESS
;
1158 switch (scu_get_event_code(event_code
)) {
1159 case SCU_EVENT_SATA_PHY_DETECTED
:
1160 /* Backup the state machine */
1161 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1162 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
);
1165 case SCU_EVENT_LINK_FAILURE
:
1166 /* Link failure change state back to the starting state */
1167 scic_sds_phy_restart_starting_state(sci_phy
);
1171 dev_warn(sciphy_to_dev(sci_phy
),
1172 "%s: PHY starting substate machine received "
1173 "unexpected event_code %x\n",
1177 result
= SCI_FAILURE
;
1186 * *****************************************************************************
1187 * * SCIC SDS PHY FRAME_HANDLERS
1188 * ***************************************************************************** */
1192 * @phy: This is struct scic_sds_phy object which is being requested to decode the
1194 * @frame_index: This is the index of the unsolicited frame which was received
1197 * This method decodes the unsolicited frame when the struct scic_sds_phy is in the
1198 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - Get the UF Header - If the UF
1199 * is an IAF - Copy IAF data to local phy object IAF data buffer. - Change
1200 * starting substate to wait power. - else - log warning message of unexpected
1201 * unsolicted frame - release frame buffer enum sci_status SCI_SUCCESS
1203 static enum sci_status
scic_sds_phy_starting_substate_await_iaf_uf_frame_handler(
1204 struct scic_sds_phy
*sci_phy
, u32 frame_index
)
1206 enum sci_status result
;
1208 struct sci_sas_identify_address_frame
*identify_frame
;
1210 result
= scic_sds_unsolicited_frame_control_get_header(
1211 &(scic_sds_phy_get_controller(sci_phy
)->uf_control
),
1213 (void **)&frame_words
);
1215 if (result
!= SCI_SUCCESS
) {
1219 frame_words
[0] = SCIC_SWAP_DWORD(frame_words
[0]);
1220 identify_frame
= (struct sci_sas_identify_address_frame
*)frame_words
;
1222 if (identify_frame
->address_frame_type
== 0) {
1225 /* Byte swap the rest of the frame so we can make
1226 * a copy of the buffer
1228 frame_words
[1] = SCIC_SWAP_DWORD(frame_words
[1]);
1229 frame_words
[2] = SCIC_SWAP_DWORD(frame_words
[2]);
1230 frame_words
[3] = SCIC_SWAP_DWORD(frame_words
[3]);
1231 frame_words
[4] = SCIC_SWAP_DWORD(frame_words
[4]);
1232 frame_words
[5] = SCIC_SWAP_DWORD(frame_words
[5]);
1234 memcpy(&sci_phy
->phy_type
.sas
.identify_address_frame_buffer
,
1236 sizeof(struct sci_sas_identify_address_frame
));
1238 if (identify_frame
->protocols
.u
.bits
.smp_target
) {
1239 /* We got the IAF for an expander PHY go to the final state since
1240 * there are no power requirements for expander phys.
1242 state
= SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
;
1244 /* We got the IAF we can now go to the await spinup semaphore state */
1245 state
= SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
;
1247 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1249 result
= SCI_SUCCESS
;
1251 dev_warn(sciphy_to_dev(sci_phy
),
1252 "%s: PHY starting substate machine received "
1253 "unexpected frame id %x\n",
1257 /* Regardless of the result release this frame since we are done with it */
1258 scic_sds_controller_release_frame(scic_sds_phy_get_controller(sci_phy
),
1266 * @phy: This is struct scic_sds_phy object which is being requested to decode the
1268 * @frame_index: This is the index of the unsolicited frame which was received
1271 * This method decodes the unsolicited frame when the struct scic_sds_phy is in the
1272 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Get the UF Header - If
1273 * the UF is an SIGNATURE FIS - Copy IAF data to local phy object SIGNATURE FIS
1274 * data buffer. - else - log warning message of unexpected unsolicted frame -
1275 * release frame buffer enum sci_status SCI_SUCCESS Must decode the SIGNATURE FIS
1278 static enum sci_status
scic_sds_phy_starting_substate_await_sig_fis_frame_handler(
1279 struct scic_sds_phy
*sci_phy
,
1282 enum sci_status result
;
1284 struct sata_fis_header
*fis_frame_header
;
1285 u32
*fis_frame_data
;
1287 result
= scic_sds_unsolicited_frame_control_get_header(
1288 &(scic_sds_phy_get_controller(sci_phy
)->uf_control
),
1290 (void **)&frame_words
);
1292 if (result
!= SCI_SUCCESS
) {
1296 fis_frame_header
= (struct sata_fis_header
*)frame_words
;
1298 if ((fis_frame_header
->fis_type
== SATA_FIS_TYPE_REGD2H
) &&
1299 !(fis_frame_header
->status
& ATA_STATUS_REG_BSY_BIT
)) {
1300 scic_sds_unsolicited_frame_control_get_buffer(
1301 &(scic_sds_phy_get_controller(sci_phy
)->uf_control
),
1303 (void **)&fis_frame_data
);
1305 scic_sds_controller_copy_sata_response(
1306 &sci_phy
->phy_type
.sata
.signature_fis_buffer
,
1310 /* We got the IAF we can now go to the await spinup semaphore state */
1311 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1312 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
);
1314 result
= SCI_SUCCESS
;
1316 dev_warn(sciphy_to_dev(sci_phy
),
1317 "%s: PHY starting substate machine received "
1318 "unexpected frame id %x\n",
1322 /* Regardless of the result release this frame since we are done with it */
1323 scic_sds_controller_release_frame(scic_sds_phy_get_controller(sci_phy
),
1330 * *****************************************************************************
1331 * * SCIC SDS PHY POWER_HANDLERS
1332 * ***************************************************************************** */
1335 * This method is called by the struct scic_sds_controller when the phy object is
1336 * granted power. - The notify enable spinups are turned on for this phy object
1337 * - The phy state machine is transitioned to the
1338 * SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. enum sci_status SCI_SUCCESS
1340 static enum sci_status
scic_sds_phy_starting_substate_await_sas_power_consume_power_handler(
1341 struct scic_sds_phy
*sci_phy
)
1345 enable_spinup
= readl(&sci_phy
->link_layer_registers
->notify_enable_spinup_control
);
1346 enable_spinup
|= SCU_ENSPINUP_GEN_BIT(ENABLE
);
1347 writel(enable_spinup
, &sci_phy
->link_layer_registers
->notify_enable_spinup_control
);
1349 /* Change state to the final state this substate machine has run to completion */
1350 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1351 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
);
1357 * This method is called by the struct scic_sds_controller when the phy object is
1358 * granted power. - The phy state machine is transitioned to the
1359 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. enum sci_status SCI_SUCCESS
1361 static enum sci_status
scic_sds_phy_starting_substate_await_sata_power_consume_power_handler(
1362 struct scic_sds_phy
*sci_phy
)
1364 u32 scu_sas_pcfg_value
;
1366 /* Release the spinup hold state and reset the OOB state machine */
1367 scu_sas_pcfg_value
=
1368 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
1369 scu_sas_pcfg_value
&=
1370 ~(SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD
) | SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE
));
1371 scu_sas_pcfg_value
|= SCU_SAS_PCFG_GEN_BIT(OOB_RESET
);
1372 writel(scu_sas_pcfg_value
,
1373 &sci_phy
->link_layer_registers
->phy_configuration
);
1375 /* Now restart the OOB operation */
1376 scu_sas_pcfg_value
&= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET
);
1377 scu_sas_pcfg_value
|= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE
);
1378 writel(scu_sas_pcfg_value
,
1379 &sci_phy
->link_layer_registers
->phy_configuration
);
1381 /* Change state to the final state this substate machine has run to completion */
1382 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1383 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN
);
1388 static enum sci_status
default_phy_handler(struct scic_sds_phy
*sci_phy
,
1391 dev_dbg(sciphy_to_dev(sci_phy
),
1392 "%s: in wrong state: %d\n", func
,
1393 sci_base_state_machine_get_state(&sci_phy
->state_machine
));
1394 return SCI_FAILURE_INVALID_STATE
;
1397 static enum sci_status
1398 scic_sds_phy_default_start_handler(struct scic_sds_phy
*sci_phy
)
1400 return default_phy_handler(sci_phy
, __func__
);
1403 static enum sci_status
1404 scic_sds_phy_default_stop_handler(struct scic_sds_phy
*sci_phy
)
1406 return default_phy_handler(sci_phy
, __func__
);
1409 static enum sci_status
1410 scic_sds_phy_default_reset_handler(struct scic_sds_phy
*sci_phy
)
1412 return default_phy_handler(sci_phy
, __func__
);
1415 static enum sci_status
1416 scic_sds_phy_default_destroy_handler(struct scic_sds_phy
*sci_phy
)
1418 return default_phy_handler(sci_phy
, __func__
);
1421 static enum sci_status
1422 scic_sds_phy_default_frame_handler(struct scic_sds_phy
*sci_phy
,
1425 struct scic_sds_controller
*scic
= scic_sds_phy_get_controller(sci_phy
);
1427 default_phy_handler(sci_phy
, __func__
);
1428 scic_sds_controller_release_frame(scic
, frame_index
);
1430 return SCI_FAILURE_INVALID_STATE
;
1433 static enum sci_status
1434 scic_sds_phy_default_event_handler(struct scic_sds_phy
*sci_phy
,
1437 return default_phy_handler(sci_phy
, __func__
);
1440 static enum sci_status
1441 scic_sds_phy_default_consume_power_handler(struct scic_sds_phy
*sci_phy
)
1443 return default_phy_handler(sci_phy
, __func__
);
1448 static const struct scic_sds_phy_state_handler scic_sds_phy_starting_substate_handler_table
[] = {
1449 [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL
] = {
1450 .start_handler
= scic_sds_phy_default_start_handler
,
1451 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1452 .reset_handler
= scic_sds_phy_default_reset_handler
,
1453 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1454 .frame_handler
= scic_sds_phy_default_frame_handler
,
1455 .event_handler
= scic_sds_phy_default_event_handler
,
1456 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1458 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
] = {
1459 .start_handler
= scic_sds_phy_default_start_handler
,
1460 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1461 .reset_handler
= scic_sds_phy_default_reset_handler
,
1462 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1463 .frame_handler
= scic_sds_phy_default_frame_handler
,
1464 .event_handler
= scic_sds_phy_starting_substate_await_ossp_event_handler
,
1465 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1467 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
] = {
1468 .start_handler
= scic_sds_phy_default_start_handler
,
1469 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1470 .reset_handler
= scic_sds_phy_default_reset_handler
,
1471 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1472 .frame_handler
= scic_sds_phy_default_frame_handler
,
1473 .event_handler
= scic_sds_phy_starting_substate_await_sas_phy_speed_event_handler
,
1474 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1476 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
] = {
1477 .start_handler
= scic_sds_phy_default_start_handler
,
1478 .stop_handler
= scic_sds_phy_default_stop_handler
,
1479 .reset_handler
= scic_sds_phy_default_reset_handler
,
1480 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1481 .frame_handler
= scic_sds_phy_starting_substate_await_iaf_uf_frame_handler
,
1482 .event_handler
= scic_sds_phy_starting_substate_await_iaf_uf_event_handler
,
1483 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1485 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
] = {
1486 .start_handler
= scic_sds_phy_default_start_handler
,
1487 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1488 .reset_handler
= scic_sds_phy_default_reset_handler
,
1489 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1490 .frame_handler
= scic_sds_phy_default_frame_handler
,
1491 .event_handler
= scic_sds_phy_starting_substate_await_sas_power_event_handler
,
1492 .consume_power_handler
= scic_sds_phy_starting_substate_await_sas_power_consume_power_handler
1494 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
] = {
1495 .start_handler
= scic_sds_phy_default_start_handler
,
1496 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1497 .reset_handler
= scic_sds_phy_default_reset_handler
,
1498 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1499 .frame_handler
= scic_sds_phy_default_frame_handler
,
1500 .event_handler
= scic_sds_phy_starting_substate_await_sata_power_event_handler
,
1501 .consume_power_handler
= scic_sds_phy_starting_substate_await_sata_power_consume_power_handler
1503 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN
] = {
1504 .start_handler
= scic_sds_phy_default_start_handler
,
1505 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1506 .reset_handler
= scic_sds_phy_default_reset_handler
,
1507 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1508 .frame_handler
= scic_sds_phy_default_frame_handler
,
1509 .event_handler
= scic_sds_phy_starting_substate_await_sata_phy_event_handler
,
1510 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1512 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
] = {
1513 .start_handler
= scic_sds_phy_default_start_handler
,
1514 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1515 .reset_handler
= scic_sds_phy_default_reset_handler
,
1516 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1517 .frame_handler
= scic_sds_phy_default_frame_handler
,
1518 .event_handler
= scic_sds_phy_starting_substate_await_sata_speed_event_handler
,
1519 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1521 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
] = {
1522 .start_handler
= scic_sds_phy_default_start_handler
,
1523 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1524 .reset_handler
= scic_sds_phy_default_reset_handler
,
1525 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1526 .frame_handler
= scic_sds_phy_starting_substate_await_sig_fis_frame_handler
,
1527 .event_handler
= scic_sds_phy_starting_substate_await_sig_fis_event_handler
,
1528 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1530 [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
] = {
1531 .start_handler
= scic_sds_phy_default_start_handler
,
1532 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1533 .reset_handler
= scic_sds_phy_default_reset_handler
,
1534 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1535 .frame_handler
= scic_sds_phy_default_frame_handler
,
1536 .event_handler
= scic_sds_phy_default_event_handler
,
1537 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1542 * scic_sds_phy_set_starting_substate_handlers() -
1544 * This macro sets the starting substate handlers by state_id
1546 #define scic_sds_phy_set_starting_substate_handlers(phy, state_id) \
1547 scic_sds_phy_set_state_handlers(\
1549 &scic_sds_phy_starting_substate_handler_table[(state_id)] \
1553 * ****************************************************************************
1554 * * PHY STARTING SUBSTATE METHODS
1555 * **************************************************************************** */
1558 * scic_sds_phy_starting_initial_substate_enter -
1559 * @object: This is the object which is cast to a struct scic_sds_phy object.
1561 * This method will perform the actions required by the struct scic_sds_phy on
1562 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL. - The initial state
1563 * handlers are put in place for the struct scic_sds_phy object. - The state is
1564 * changed to the wait phy type event notification. none
1566 static void scic_sds_phy_starting_initial_substate_enter(void *object
)
1568 struct scic_sds_phy
*sci_phy
= object
;
1570 scic_sds_phy_set_starting_substate_handlers(
1571 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL
);
1573 /* This is just an temporary state go off to the starting state */
1574 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1575 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
);
1580 * @object: This is the object which is cast to a struct scic_sds_phy object.
1582 * This method will perform the actions required by the struct scic_sds_phy on
1583 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_PHY_TYPE_EN. - Set the
1584 * struct scic_sds_phy object state handlers for this state. none
1586 static void scic_sds_phy_starting_await_ossp_en_substate_enter(void *object
)
1588 struct scic_sds_phy
*sci_phy
= object
;
1590 scic_sds_phy_set_starting_substate_handlers(
1591 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
1597 * @object: This is the object which is cast to a struct scic_sds_phy object.
1599 * This method will perform the actions required by the struct scic_sds_phy on
1600 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. - Set the
1601 * struct scic_sds_phy object state handlers for this state. none
1603 static void scic_sds_phy_starting_await_sas_speed_en_substate_enter(
1606 struct scic_sds_phy
*sci_phy
= object
;
1608 scic_sds_phy_set_starting_substate_handlers(
1609 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
1615 * @object: This is the object which is cast to a struct scic_sds_phy object.
1617 * This method will perform the actions required by the struct scic_sds_phy on
1618 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - Set the
1619 * struct scic_sds_phy object state handlers for this state. none
1621 static void scic_sds_phy_starting_await_iaf_uf_substate_enter(void *object
)
1623 struct scic_sds_phy
*sci_phy
= object
;
1625 scic_sds_phy_set_starting_substate_handlers(
1626 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
1632 * @object: This is the object which is cast to a struct scic_sds_phy object.
1634 * This method will perform the actions required by the struct scic_sds_phy on
1635 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Set the
1636 * struct scic_sds_phy object state handlers for this state. - Add this phy object to
1637 * the power control queue none
1639 static void scic_sds_phy_starting_await_sas_power_substate_enter(void *object
)
1641 struct scic_sds_phy
*sci_phy
= object
;
1643 scic_sds_phy_set_starting_substate_handlers(
1644 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
1647 scic_sds_controller_power_control_queue_insert(
1648 scic_sds_phy_get_controller(sci_phy
),
1655 * @object: This is the object which is cast to a struct scic_sds_phy object.
1657 * This method will perform the actions required by the struct scic_sds_phy on exiting
1658 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Remove the
1659 * struct scic_sds_phy object from the power control queue. none
1661 static void scic_sds_phy_starting_await_sas_power_substate_exit(void *object
)
1663 struct scic_sds_phy
*sci_phy
= object
;
1665 scic_sds_controller_power_control_queue_remove(
1666 scic_sds_phy_get_controller(sci_phy
), sci_phy
1672 * @object: This is the object which is cast to a struct scic_sds_phy object.
1674 * This method will perform the actions required by the struct scic_sds_phy on
1675 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Set the
1676 * struct scic_sds_phy object state handlers for this state. - Add this phy object to
1677 * the power control queue none
1679 static void scic_sds_phy_starting_await_sata_power_substate_enter(void *object
)
1681 struct scic_sds_phy
*sci_phy
= object
;
1683 scic_sds_phy_set_starting_substate_handlers(
1684 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
1687 scic_sds_controller_power_control_queue_insert(
1688 scic_sds_phy_get_controller(sci_phy
),
1695 * @object: This is the object which is cast to a struct scic_sds_phy object.
1697 * This method will perform the actions required by the struct scic_sds_phy on exiting
1698 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Remove the
1699 * struct scic_sds_phy object from the power control queue. none
1701 static void scic_sds_phy_starting_await_sata_power_substate_exit(void *object
)
1703 struct scic_sds_phy
*sci_phy
= object
;
1705 scic_sds_controller_power_control_queue_remove(
1706 scic_sds_phy_get_controller(sci_phy
),
1713 * @object: This is the object which is cast to a struct scic_sds_phy object.
1715 * This function will perform the actions required by the struct scic_sds_phy on
1716 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. - Set the
1717 * struct scic_sds_phy object state handlers for this state. none
1719 static void scic_sds_phy_starting_await_sata_phy_substate_enter(void *object
)
1721 struct scic_sds_phy
*sci_phy
= object
;
1723 scic_sds_phy_set_starting_substate_handlers(
1725 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN
);
1727 isci_timer_start(sci_phy
->sata_timeout_timer
,
1728 SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT
);
1733 * @object: This is the object which is cast to a struct scic_sds_phy object.
1735 * This method will perform the actions required by the struct scic_sds_phy
1737 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
1738 * that was started on entry to await sata phy event notification none
1740 static inline void scic_sds_phy_starting_await_sata_phy_substate_exit(
1743 struct scic_sds_phy
*sci_phy
= object
;
1745 isci_timer_stop(sci_phy
->sata_timeout_timer
);
1750 * @object: This is the object which is cast to a struct scic_sds_phy object.
1752 * This method will perform the actions required by the struct scic_sds_phy on
1753 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - Set the
1754 * struct scic_sds_phy object state handlers for this state. none
1756 static void scic_sds_phy_starting_await_sata_speed_substate_enter(void *object
)
1758 struct scic_sds_phy
*sci_phy
= object
;
1760 scic_sds_phy_set_starting_substate_handlers(
1762 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
);
1764 isci_timer_start(sci_phy
->sata_timeout_timer
,
1765 SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT
);
1770 * @object: This is the object which is cast to a struct scic_sds_phy object.
1772 * This function will perform the actions required by the
1773 * struct scic_sds_phy on exiting
1774 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
1775 * that was started on entry to await sata phy event notification none
1777 static inline void scic_sds_phy_starting_await_sata_speed_substate_exit(
1780 struct scic_sds_phy
*sci_phy
= object
;
1782 isci_timer_stop(sci_phy
->sata_timeout_timer
);
1787 * @object: This is the object which is cast to a struct scic_sds_phy object.
1789 * This function will perform the actions required by the struct scic_sds_phy on
1790 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Set the
1791 * struct scic_sds_phy object state handlers for this state.
1792 * - Start the SIGNATURE FIS
1793 * timeout timer none
1795 static void scic_sds_phy_starting_await_sig_fis_uf_substate_enter(void *object
)
1797 bool continue_to_ready_state
;
1798 struct scic_sds_phy
*sci_phy
= object
;
1800 scic_sds_phy_set_starting_substate_handlers(
1802 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
);
1804 continue_to_ready_state
= scic_sds_port_link_detected(
1805 sci_phy
->owning_port
,
1808 if (continue_to_ready_state
) {
1810 * Clear the PE suspend condition so we can actually
1812 * The hardware will not respond to the XRDY until the PE
1813 * suspend condition is cleared.
1815 scic_sds_phy_resume(sci_phy
);
1817 isci_timer_start(sci_phy
->sata_timeout_timer
,
1818 SCIC_SDS_SIGNATURE_FIS_TIMEOUT
);
1820 sci_phy
->is_in_link_training
= false;
1825 * @object: This is the object which is cast to a struct scic_sds_phy object.
1827 * This function will perform the actions required by the
1828 * struct scic_sds_phy on exiting
1829 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Stop the SIGNATURE
1830 * FIS timeout timer. none
1832 static inline void scic_sds_phy_starting_await_sig_fis_uf_substate_exit(
1835 struct scic_sds_phy
*sci_phy
= object
;
1837 isci_timer_stop(sci_phy
->sata_timeout_timer
);
1842 * @object: This is the object which is cast to a struct scic_sds_phy object.
1844 * This method will perform the actions required by the struct scic_sds_phy on
1845 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. - Set the struct scic_sds_phy
1846 * object state handlers for this state. - Change base state machine to the
1849 static void scic_sds_phy_starting_final_substate_enter(void *object
)
1851 struct scic_sds_phy
*sci_phy
= object
;
1853 scic_sds_phy_set_starting_substate_handlers(sci_phy
,
1854 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
);
1856 /* State machine has run to completion so exit out and change
1857 * the base state machine to the ready state
1859 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1860 SCI_BASE_PHY_STATE_READY
);
1863 /* --------------------------------------------------------------------------- */
1865 static const struct sci_base_state scic_sds_phy_starting_substates
[] = {
1866 [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL
] = {
1867 .enter_state
= scic_sds_phy_starting_initial_substate_enter
,
1869 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
] = {
1870 .enter_state
= scic_sds_phy_starting_await_ossp_en_substate_enter
,
1872 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
] = {
1873 .enter_state
= scic_sds_phy_starting_await_sas_speed_en_substate_enter
,
1875 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
] = {
1876 .enter_state
= scic_sds_phy_starting_await_iaf_uf_substate_enter
,
1878 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
] = {
1879 .enter_state
= scic_sds_phy_starting_await_sas_power_substate_enter
,
1880 .exit_state
= scic_sds_phy_starting_await_sas_power_substate_exit
,
1882 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
] = {
1883 .enter_state
= scic_sds_phy_starting_await_sata_power_substate_enter
,
1884 .exit_state
= scic_sds_phy_starting_await_sata_power_substate_exit
1886 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN
] = {
1887 .enter_state
= scic_sds_phy_starting_await_sata_phy_substate_enter
,
1888 .exit_state
= scic_sds_phy_starting_await_sata_phy_substate_exit
1890 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
] = {
1891 .enter_state
= scic_sds_phy_starting_await_sata_speed_substate_enter
,
1892 .exit_state
= scic_sds_phy_starting_await_sata_speed_substate_exit
1894 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
] = {
1895 .enter_state
= scic_sds_phy_starting_await_sig_fis_uf_substate_enter
,
1896 .exit_state
= scic_sds_phy_starting_await_sig_fis_uf_substate_exit
1898 [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
] = {
1899 .enter_state
= scic_sds_phy_starting_final_substate_enter
,
1904 * This method takes the struct scic_sds_phy from a stopped state and
1905 * attempts to start it. - The phy state machine is transitioned to the
1906 * SCI_BASE_PHY_STATE_STARTING. enum sci_status SCI_SUCCESS
1908 static enum sci_status
1909 scic_sds_phy_stopped_state_start_handler(struct scic_sds_phy
*sci_phy
)
1911 struct isci_host
*ihost
;
1912 struct scic_sds_controller
*scic
;
1914 scic
= scic_sds_phy_get_controller(sci_phy
),
1915 ihost
= scic
->ihost
;
1917 /* Create the SIGNATURE FIS Timeout timer for this phy */
1918 sci_phy
->sata_timeout_timer
= isci_timer_create(ihost
, sci_phy
,
1919 scic_sds_phy_sata_timeout
);
1921 if (sci_phy
->sata_timeout_timer
)
1922 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1923 SCI_BASE_PHY_STATE_STARTING
);
1928 static enum sci_status
1929 scic_sds_phy_stopped_state_destroy_handler(struct scic_sds_phy
*sci_phy
)
1934 static enum sci_status
1935 scic_sds_phy_ready_state_stop_handler(struct scic_sds_phy
*sci_phy
)
1937 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1938 SCI_BASE_PHY_STATE_STOPPED
);
1943 static enum sci_status
1944 scic_sds_phy_ready_state_reset_handler(struct scic_sds_phy
*sci_phy
)
1946 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1947 SCI_BASE_PHY_STATE_RESETTING
);
1953 * scic_sds_phy_ready_state_event_handler -
1954 * @phy: This is the struct scic_sds_phy object which has received the event.
1956 * This method request the struct scic_sds_phy handle the received event. The only
1957 * event that we are interested in while in the ready state is the link failure
1958 * event. - decoded event is a link failure - transition the struct scic_sds_phy back
1959 * to the SCI_BASE_PHY_STATE_STARTING state. - any other event received will
1960 * report a warning message enum sci_status SCI_SUCCESS if the event received is a
1961 * link failure SCI_FAILURE_INVALID_STATE for any other event received.
1963 static enum sci_status
scic_sds_phy_ready_state_event_handler(struct scic_sds_phy
*sci_phy
,
1966 enum sci_status result
= SCI_FAILURE
;
1968 switch (scu_get_event_code(event_code
)) {
1969 case SCU_EVENT_LINK_FAILURE
:
1970 /* Link failure change state back to the starting state */
1971 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1972 SCI_BASE_PHY_STATE_STARTING
);
1973 result
= SCI_SUCCESS
;
1976 case SCU_EVENT_BROADCAST_CHANGE
:
1977 /* Broadcast change received. Notify the port. */
1978 if (scic_sds_phy_get_port(sci_phy
) != NULL
)
1979 scic_sds_port_broadcast_change_received(sci_phy
->owning_port
, sci_phy
);
1981 sci_phy
->bcn_received_while_port_unassigned
= true;
1985 dev_warn(sciphy_to_dev(sci_phy
),
1986 "%sP SCIC PHY 0x%p ready state machine received "
1987 "unexpected event_code %x\n",
1988 __func__
, sci_phy
, event_code
);
1990 result
= SCI_FAILURE_INVALID_STATE
;
1997 static enum sci_status
scic_sds_phy_resetting_state_event_handler(struct scic_sds_phy
*sci_phy
,
2000 enum sci_status result
= SCI_FAILURE
;
2002 switch (scu_get_event_code(event_code
)) {
2003 case SCU_EVENT_HARD_RESET_TRANSMITTED
:
2004 /* Link failure change state back to the starting state */
2005 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
2006 SCI_BASE_PHY_STATE_STARTING
);
2007 result
= SCI_SUCCESS
;
2011 dev_warn(sciphy_to_dev(sci_phy
),
2012 "%s: SCIC PHY 0x%p resetting state machine received "
2013 "unexpected event_code %x\n",
2014 __func__
, sci_phy
, event_code
);
2016 result
= SCI_FAILURE_INVALID_STATE
;
2023 /* --------------------------------------------------------------------------- */
2025 static const struct scic_sds_phy_state_handler scic_sds_phy_state_handler_table
[] = {
2026 [SCI_BASE_PHY_STATE_INITIAL
] = {
2027 .start_handler
= scic_sds_phy_default_start_handler
,
2028 .stop_handler
= scic_sds_phy_default_stop_handler
,
2029 .reset_handler
= scic_sds_phy_default_reset_handler
,
2030 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
2031 .frame_handler
= scic_sds_phy_default_frame_handler
,
2032 .event_handler
= scic_sds_phy_default_event_handler
,
2033 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
2035 [SCI_BASE_PHY_STATE_STOPPED
] = {
2036 .start_handler
= scic_sds_phy_stopped_state_start_handler
,
2037 .stop_handler
= scic_sds_phy_default_stop_handler
,
2038 .reset_handler
= scic_sds_phy_default_reset_handler
,
2039 .destruct_handler
= scic_sds_phy_stopped_state_destroy_handler
,
2040 .frame_handler
= scic_sds_phy_default_frame_handler
,
2041 .event_handler
= scic_sds_phy_default_event_handler
,
2042 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
2044 [SCI_BASE_PHY_STATE_STARTING
] = {
2045 .start_handler
= scic_sds_phy_default_start_handler
,
2046 .stop_handler
= scic_sds_phy_default_stop_handler
,
2047 .reset_handler
= scic_sds_phy_default_reset_handler
,
2048 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
2049 .frame_handler
= scic_sds_phy_default_frame_handler
,
2050 .event_handler
= scic_sds_phy_default_event_handler
,
2051 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
2053 [SCI_BASE_PHY_STATE_READY
] = {
2054 .start_handler
= scic_sds_phy_default_start_handler
,
2055 .stop_handler
= scic_sds_phy_ready_state_stop_handler
,
2056 .reset_handler
= scic_sds_phy_ready_state_reset_handler
,
2057 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
2058 .frame_handler
= scic_sds_phy_default_frame_handler
,
2059 .event_handler
= scic_sds_phy_ready_state_event_handler
,
2060 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
2062 [SCI_BASE_PHY_STATE_RESETTING
] = {
2063 .start_handler
= scic_sds_phy_default_start_handler
,
2064 .stop_handler
= scic_sds_phy_default_stop_handler
,
2065 .reset_handler
= scic_sds_phy_default_reset_handler
,
2066 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
2067 .frame_handler
= scic_sds_phy_default_frame_handler
,
2068 .event_handler
= scic_sds_phy_resetting_state_event_handler
,
2069 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
2071 [SCI_BASE_PHY_STATE_FINAL
] = {
2072 .start_handler
= scic_sds_phy_default_start_handler
,
2073 .stop_handler
= scic_sds_phy_default_stop_handler
,
2074 .reset_handler
= scic_sds_phy_default_reset_handler
,
2075 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
2076 .frame_handler
= scic_sds_phy_default_frame_handler
,
2077 .event_handler
= scic_sds_phy_default_event_handler
,
2078 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
2083 * ****************************************************************************
2084 * * PHY STATE PRIVATE METHODS
2085 * **************************************************************************** */
2089 * @sci_phy: This is the struct scic_sds_phy object to stop.
2091 * This method will stop the struct scic_sds_phy object. This does not reset the
2092 * protocol engine it just suspends it and places it in a state where it will
2093 * not cause the end device to power up. none
2095 static void scu_link_layer_stop_protocol_engine(
2096 struct scic_sds_phy
*sci_phy
)
2098 u32 scu_sas_pcfg_value
;
2099 u32 enable_spinup_value
;
2101 /* Suspend the protocol engine and place it in a sata spinup hold state */
2102 scu_sas_pcfg_value
=
2103 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
2104 scu_sas_pcfg_value
|=
2105 (SCU_SAS_PCFG_GEN_BIT(OOB_RESET
) |
2106 SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE
) |
2107 SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD
));
2108 writel(scu_sas_pcfg_value
,
2109 &sci_phy
->link_layer_registers
->phy_configuration
);
2111 /* Disable the notify enable spinup primitives */
2112 enable_spinup_value
= readl(&sci_phy
->link_layer_registers
->notify_enable_spinup_control
);
2113 enable_spinup_value
&= ~SCU_ENSPINUP_GEN_BIT(ENABLE
);
2114 writel(enable_spinup_value
, &sci_phy
->link_layer_registers
->notify_enable_spinup_control
);
2120 * This method will start the OOB/SN state machine for this struct scic_sds_phy object.
2122 static void scu_link_layer_start_oob(
2123 struct scic_sds_phy
*sci_phy
)
2125 u32 scu_sas_pcfg_value
;
2127 scu_sas_pcfg_value
=
2128 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
2129 scu_sas_pcfg_value
|= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE
);
2130 scu_sas_pcfg_value
&=
2131 ~(SCU_SAS_PCFG_GEN_BIT(OOB_RESET
) |
2132 SCU_SAS_PCFG_GEN_BIT(HARD_RESET
));
2133 writel(scu_sas_pcfg_value
,
2134 &sci_phy
->link_layer_registers
->phy_configuration
);
2140 * This method will transmit a hard reset request on the specified phy. The SCU
2141 * hardware requires that we reset the OOB state machine and set the hard reset
2142 * bit in the phy configuration register. We then must start OOB over with the
2143 * hard reset bit set.
2145 static void scu_link_layer_tx_hard_reset(
2146 struct scic_sds_phy
*sci_phy
)
2148 u32 phy_configuration_value
;
2151 * SAS Phys must wait for the HARD_RESET_TX event notification to transition
2152 * to the starting state. */
2153 phy_configuration_value
=
2154 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
2155 phy_configuration_value
|=
2156 (SCU_SAS_PCFG_GEN_BIT(HARD_RESET
) |
2157 SCU_SAS_PCFG_GEN_BIT(OOB_RESET
));
2158 writel(phy_configuration_value
,
2159 &sci_phy
->link_layer_registers
->phy_configuration
);
2161 /* Now take the OOB state machine out of reset */
2162 phy_configuration_value
|= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE
);
2163 phy_configuration_value
&= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET
);
2164 writel(phy_configuration_value
,
2165 &sci_phy
->link_layer_registers
->phy_configuration
);
2169 * ****************************************************************************
2170 * * PHY BASE STATE METHODS
2171 * **************************************************************************** */
2175 * @object: This is the object which is cast to a struct scic_sds_phy object.
2177 * This method will perform the actions required by the struct scic_sds_phy on
2178 * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
2179 * handlers for the phy object base state machine initial state. none
2181 static void scic_sds_phy_initial_state_enter(void *object
)
2183 struct scic_sds_phy
*sci_phy
= object
;
2185 scic_sds_phy_set_base_state_handlers(sci_phy
, SCI_BASE_PHY_STATE_INITIAL
);
2190 * @object: This is the object which is cast to a struct scic_sds_phy object.
2192 * This function will perform the actions required by the struct scic_sds_phy on
2193 * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
2194 * handlers for the phy object base state machine initial state. - The SCU
2195 * hardware is requested to stop the protocol engine. none
2197 static void scic_sds_phy_stopped_state_enter(void *object
)
2199 struct scic_sds_phy
*sci_phy
= object
;
2200 struct scic_sds_controller
*scic
= scic_sds_phy_get_controller(sci_phy
);
2201 struct isci_host
*ihost
= scic
->ihost
;
2204 * @todo We need to get to the controller to place this PE in a
2208 scic_sds_phy_set_base_state_handlers(sci_phy
,
2209 SCI_BASE_PHY_STATE_STOPPED
);
2211 if (sci_phy
->sata_timeout_timer
!= NULL
) {
2212 isci_del_timer(ihost
, sci_phy
->sata_timeout_timer
);
2214 sci_phy
->sata_timeout_timer
= NULL
;
2217 scu_link_layer_stop_protocol_engine(sci_phy
);
2219 if (sci_phy
->state_machine
.previous_state_id
!=
2220 SCI_BASE_PHY_STATE_INITIAL
)
2221 scic_sds_controller_link_down(
2222 scic_sds_phy_get_controller(sci_phy
),
2223 scic_sds_phy_get_port(sci_phy
),
2229 * @object: This is the object which is cast to a struct scic_sds_phy object.
2231 * This method will perform the actions required by the struct scic_sds_phy on
2232 * entering the SCI_BASE_PHY_STATE_STARTING. - This function sets the state
2233 * handlers for the phy object base state machine starting state. - The SCU
2234 * hardware is requested to start OOB/SN on this protocl engine. - The phy
2235 * starting substate machine is started. - If the previous state was the ready
2236 * state then the struct scic_sds_controller is informed that the phy has gone link
2239 static void scic_sds_phy_starting_state_enter(void *object
)
2241 struct scic_sds_phy
*sci_phy
= object
;
2243 scic_sds_phy_set_base_state_handlers(sci_phy
, SCI_BASE_PHY_STATE_STARTING
);
2245 scu_link_layer_stop_protocol_engine(sci_phy
);
2246 scu_link_layer_start_oob(sci_phy
);
2248 /* We don't know what kind of phy we are going to be just yet */
2249 sci_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_UNKNOWN
;
2250 sci_phy
->bcn_received_while_port_unassigned
= false;
2252 /* Change over to the starting substate machine to continue */
2253 sci_base_state_machine_start(&sci_phy
->starting_substate_machine
);
2255 if (sci_phy
->state_machine
.previous_state_id
2256 == SCI_BASE_PHY_STATE_READY
) {
2257 scic_sds_controller_link_down(
2258 scic_sds_phy_get_controller(sci_phy
),
2259 scic_sds_phy_get_port(sci_phy
),
2267 * @object: This is the object which is cast to a struct scic_sds_phy object.
2269 * This method will perform the actions required by the struct scic_sds_phy on
2270 * entering the SCI_BASE_PHY_STATE_READY. - This function sets the state
2271 * handlers for the phy object base state machine ready state. - The SCU
2272 * hardware protocol engine is resumed. - The struct scic_sds_controller is informed
2273 * that the phy object has gone link up. none
2275 static void scic_sds_phy_ready_state_enter(void *object
)
2277 struct scic_sds_phy
*sci_phy
= object
;
2279 scic_sds_phy_set_base_state_handlers(sci_phy
, SCI_BASE_PHY_STATE_READY
);
2281 scic_sds_controller_link_up(
2282 scic_sds_phy_get_controller(sci_phy
),
2283 scic_sds_phy_get_port(sci_phy
),
2290 * @object: This is the object which is cast to a struct scic_sds_phy object.
2292 * This method will perform the actions required by the struct scic_sds_phy on exiting
2293 * the SCI_BASE_PHY_STATE_INITIAL. This function suspends the SCU hardware
2294 * protocol engine represented by this struct scic_sds_phy object. none
2296 static void scic_sds_phy_ready_state_exit(void *object
)
2298 struct scic_sds_phy
*sci_phy
= object
;
2300 scic_sds_phy_suspend(sci_phy
);
2305 * @object: This is the object which is cast to a struct scic_sds_phy object.
2307 * This method will perform the actions required by the struct scic_sds_phy on
2308 * entering the SCI_BASE_PHY_STATE_RESETTING. - This function sets the state
2309 * handlers for the phy object base state machine resetting state. none
2311 static void scic_sds_phy_resetting_state_enter(void *object
)
2313 struct scic_sds_phy
*sci_phy
= object
;
2315 scic_sds_phy_set_base_state_handlers(sci_phy
, SCI_BASE_PHY_STATE_RESETTING
);
2318 * The phy is being reset, therefore deactivate it from the port.
2319 * In the resetting state we don't notify the user regarding
2320 * link up and link down notifications. */
2321 scic_sds_port_deactivate_phy(sci_phy
->owning_port
, sci_phy
, false);
2323 if (sci_phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SAS
) {
2324 scu_link_layer_tx_hard_reset(sci_phy
);
2327 * The SCU does not need to have a discrete reset state so
2328 * just go back to the starting state.
2330 sci_base_state_machine_change_state(
2331 &sci_phy
->state_machine
,
2332 SCI_BASE_PHY_STATE_STARTING
);
2338 * @object: This is the object which is cast to a struct scic_sds_phy object.
2340 * This method will perform the actions required by the struct scic_sds_phy on
2341 * entering the SCI_BASE_PHY_STATE_FINAL. - This function sets the state
2342 * handlers for the phy object base state machine final state. none
2344 static void scic_sds_phy_final_state_enter(void *object
)
2346 struct scic_sds_phy
*sci_phy
= object
;
2348 scic_sds_phy_set_base_state_handlers(sci_phy
, SCI_BASE_PHY_STATE_FINAL
);
2350 /* Nothing to do here */
2353 /* --------------------------------------------------------------------------- */
2355 static const struct sci_base_state scic_sds_phy_state_table
[] = {
2356 [SCI_BASE_PHY_STATE_INITIAL
] = {
2357 .enter_state
= scic_sds_phy_initial_state_enter
,
2359 [SCI_BASE_PHY_STATE_STOPPED
] = {
2360 .enter_state
= scic_sds_phy_stopped_state_enter
,
2362 [SCI_BASE_PHY_STATE_STARTING
] = {
2363 .enter_state
= scic_sds_phy_starting_state_enter
,
2365 [SCI_BASE_PHY_STATE_READY
] = {
2366 .enter_state
= scic_sds_phy_ready_state_enter
,
2367 .exit_state
= scic_sds_phy_ready_state_exit
,
2369 [SCI_BASE_PHY_STATE_RESETTING
] = {
2370 .enter_state
= scic_sds_phy_resetting_state_enter
,
2372 [SCI_BASE_PHY_STATE_FINAL
] = {
2373 .enter_state
= scic_sds_phy_final_state_enter
,
2377 void scic_sds_phy_construct(struct scic_sds_phy
*sci_phy
,
2378 struct scic_sds_port
*owning_port
, u8 phy_index
)
2381 sci_base_state_machine_construct(&sci_phy
->state_machine
,
2383 scic_sds_phy_state_table
,
2384 SCI_BASE_PHY_STATE_INITIAL
);
2386 sci_base_state_machine_start(&sci_phy
->state_machine
);
2388 /* Copy the rest of the input data to our locals */
2389 sci_phy
->owning_port
= owning_port
;
2390 sci_phy
->phy_index
= phy_index
;
2391 sci_phy
->bcn_received_while_port_unassigned
= false;
2392 sci_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_UNKNOWN
;
2393 sci_phy
->link_layer_registers
= NULL
;
2394 sci_phy
->max_negotiated_speed
= SAS_LINK_RATE_UNKNOWN
;
2395 sci_phy
->sata_timeout_timer
= NULL
;
2397 /* Clear out the identification buffer data */
2398 memset(&sci_phy
->phy_type
, 0, sizeof(sci_phy
->phy_type
));
2400 /* Initialize the the substate machines */
2401 sci_base_state_machine_construct(&sci_phy
->starting_substate_machine
,
2403 scic_sds_phy_starting_substates
,
2404 SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL
);