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 "scic_sds_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
*this_phy
,
94 struct scu_transport_layer_registers __iomem
*transport_layer_registers
)
98 this_phy
->transport_layer_registers
= transport_layer_registers
;
100 writel(SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
,
101 &this_phy
->transport_layer_registers
->stp_rni
);
103 /* Hardware team recommends that we enable the STP prefetch for all transports */
104 tl_control
= readl(&this_phy
->transport_layer_registers
->control
);
105 tl_control
|= SCU_TLCR_GEN_BIT(STP_WRITE_DATA_PREFETCH
);
106 writel(tl_control
, &this_phy
->transport_layer_registers
->control
);
112 * This method will initialize the phy link layer registers
114 * @link_layer_registers:
118 static enum sci_status
119 scic_sds_phy_link_layer_initialization(struct scic_sds_phy
*sci_phy
,
120 struct scu_link_layer_registers __iomem
*link_layer_registers
)
122 struct scic_sds_controller
*scic
= sci_phy
->owning_port
->owning_controller
;
123 int phy_idx
= sci_phy
->phy_index
;
124 struct sci_phy_user_params
*phy_user
= &scic
->user_parameters
.sds1
.phys
[phy_idx
];
125 struct sci_phy_oem_params
*phy_oem
= &scic
->oem_parameters
.sds1
.phys
[phy_idx
];
126 u32 phy_configuration
;
127 struct sas_capabilities phy_capabilities
;
128 u32 parity_check
= 0;
129 u32 parity_count
= 0;
130 u32 llctl
, link_rate
;
133 sci_phy
->link_layer_registers
= link_layer_registers
;
135 /* Set our IDENTIFY frame data */
136 #define SCI_END_DEVICE 0x01
138 writel(SCU_SAS_TIID_GEN_BIT(SMP_INITIATOR
) |
139 SCU_SAS_TIID_GEN_BIT(SSP_INITIATOR
) |
140 SCU_SAS_TIID_GEN_BIT(STP_INITIATOR
) |
141 SCU_SAS_TIID_GEN_BIT(DA_SATA_HOST
) |
142 SCU_SAS_TIID_GEN_VAL(DEVICE_TYPE
, SCI_END_DEVICE
),
143 &sci_phy
->link_layer_registers
->transmit_identification
);
145 /* Write the device SAS Address */
146 writel(0xFEDCBA98, &sci_phy
->link_layer_registers
->sas_device_name_high
);
147 writel(phy_idx
, &sci_phy
->link_layer_registers
->sas_device_name_low
);
149 /* Write the source SAS Address */
150 writel(phy_oem
->sas_address
.high
,
151 &sci_phy
->link_layer_registers
->source_sas_address_high
);
152 writel(phy_oem
->sas_address
.low
,
153 &sci_phy
->link_layer_registers
->source_sas_address_low
);
155 /* Clear and Set the PHY Identifier */
156 writel(0, &sci_phy
->link_layer_registers
->identify_frame_phy_id
);
157 writel(SCU_SAS_TIPID_GEN_VALUE(ID
, phy_idx
),
158 &sci_phy
->link_layer_registers
->identify_frame_phy_id
);
160 /* Change the initial state of the phy configuration register */
162 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
164 /* Hold OOB state machine in reset */
165 phy_configuration
|= SCU_SAS_PCFG_GEN_BIT(OOB_RESET
);
166 writel(phy_configuration
,
167 &sci_phy
->link_layer_registers
->phy_configuration
);
169 /* Configure the SNW capabilities */
170 phy_capabilities
.u
.all
= 0;
171 phy_capabilities
.u
.bits
.start
= 1;
172 phy_capabilities
.u
.bits
.gen3_without_ssc_supported
= 1;
173 phy_capabilities
.u
.bits
.gen2_without_ssc_supported
= 1;
174 phy_capabilities
.u
.bits
.gen1_without_ssc_supported
= 1;
175 if (scic
->oem_parameters
.sds1
.controller
.do_enable_ssc
== true) {
176 phy_capabilities
.u
.bits
.gen3_with_ssc_supported
= 1;
177 phy_capabilities
.u
.bits
.gen2_with_ssc_supported
= 1;
178 phy_capabilities
.u
.bits
.gen1_with_ssc_supported
= 1;
182 * The SAS specification indicates that the phy_capabilities that
183 * are transmitted shall have an even parity. Calculate the parity. */
184 parity_check
= phy_capabilities
.u
.all
;
185 while (parity_check
!= 0) {
186 if (parity_check
& 0x1)
192 * If parity indicates there are an odd number of bits set, then
193 * set the parity bit to 1 in the phy capabilities. */
194 if ((parity_count
% 2) != 0)
195 phy_capabilities
.u
.bits
.parity
= 1;
197 writel(phy_capabilities
.u
.all
,
198 &sci_phy
->link_layer_registers
->phy_capabilities
);
200 /* Set the enable spinup period but disable the ability to send
201 * notify enable spinup
203 writel(SCU_ENSPINUP_GEN_VAL(COUNT
,
204 phy_user
->notify_enable_spin_up_insertion_frequency
),
205 &sci_phy
->link_layer_registers
->notify_enable_spinup_control
);
207 /* Write the ALIGN Insertion Ferequency for connected phy and
208 * inpendent of connected state
210 clksm_value
= SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(CONNECTED
,
211 phy_user
->in_connection_align_insertion_frequency
);
213 clksm_value
|= SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(GENERAL
,
214 phy_user
->align_insertion_frequency
);
216 writel(clksm_value
, &sci_phy
->link_layer_registers
->clock_skew_management
);
218 /* @todo Provide a way to write this register correctly */
220 &sci_phy
->link_layer_registers
->afe_lookup_table_control
);
222 llctl
= SCU_SAS_LLCTL_GEN_VAL(NO_OUTBOUND_TASK_TIMEOUT
,
223 (u8
)scic
->user_parameters
.sds1
.no_outbound_task_timeout
);
225 switch(phy_user
->max_speed_generation
) {
226 case SCIC_SDS_PARM_GEN3_SPEED
:
227 link_rate
= SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN3
;
229 case SCIC_SDS_PARM_GEN2_SPEED
:
230 link_rate
= SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN2
;
233 link_rate
= SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN1
;
236 llctl
|= SCU_SAS_LLCTL_GEN_VAL(MAX_LINK_RATE
, link_rate
);
237 writel(llctl
, &sci_phy
->link_layer_registers
->link_layer_control
);
239 if (is_a0() || is_a2()) {
240 /* Program the max ARB time for the PHY to 700us so we inter-operate with
241 * the PMC expander which shuts down PHYs if the expander PHY generates too
242 * many breaks. This time value will guarantee that the initiator PHY will
243 * generate the break.
245 writel(SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME
,
246 &sci_phy
->link_layer_registers
->maximum_arbitration_wait_timer_timeout
);
250 * Set the link layer hang detection to 500ms (0x1F4) from its default
251 * value of 128ms. Max value is 511 ms.
253 writel(0x1F4, &sci_phy
->link_layer_registers
->link_layer_hang_detection_timeout
);
255 /* We can exit the initial state to the stopped state */
256 sci_base_state_machine_change_state(&sci_phy
->parent
.state_machine
,
257 SCI_BASE_PHY_STATE_STOPPED
);
263 * This function will handle the sata SIGNATURE FIS timeout condition. It will
264 * restart the starting substate machine since we dont know what has actually
267 static void scic_sds_phy_sata_timeout(void *phy
)
269 struct scic_sds_phy
*sci_phy
= phy
;
271 dev_dbg(sciphy_to_dev(sci_phy
),
272 "%s: SCIC SDS Phy 0x%p did not receive signature fis before "
277 sci_base_state_machine_stop(&sci_phy
->starting_substate_machine
);
279 sci_base_state_machine_change_state(&sci_phy
->parent
.state_machine
,
280 SCI_BASE_PHY_STATE_STARTING
);
284 * This method returns the port currently containing this phy. If the phy is
285 * currently contained by the dummy port, then the phy is considered to not
287 * @this_phy: This parameter specifies the phy for which to retrieve the
290 * This method returns a handle to a port that contains the supplied phy.
291 * NULL This value is returned if the phy is not part of a real
292 * port (i.e. it's contained in the dummy port). !NULL All other
293 * values indicate a handle/pointer to the port containing the phy.
295 struct scic_sds_port
*scic_sds_phy_get_port(
296 struct scic_sds_phy
*this_phy
)
298 if (scic_sds_port_get_index(this_phy
->owning_port
) == SCIC_SDS_DUMMY_PORT
)
301 return this_phy
->owning_port
;
305 * This method will assign a port to the phy object.
306 * @out]: this_phy This parameter specifies the phy for which to assign a port
311 void scic_sds_phy_set_port(
312 struct scic_sds_phy
*this_phy
,
313 struct scic_sds_port
*the_port
)
315 this_phy
->owning_port
= the_port
;
317 if (this_phy
->bcn_received_while_port_unassigned
) {
318 this_phy
->bcn_received_while_port_unassigned
= false;
319 scic_sds_port_broadcast_change_received(this_phy
->owning_port
, this_phy
);
324 * This method will initialize the constructed phy
326 * @link_layer_registers:
330 enum sci_status
scic_sds_phy_initialize(
331 struct scic_sds_phy
*sci_phy
,
332 struct scu_transport_layer_registers __iomem
*transport_layer_registers
,
333 struct scu_link_layer_registers __iomem
*link_layer_registers
)
335 struct scic_sds_controller
*scic
= scic_sds_phy_get_controller(sci_phy
);
336 struct isci_host
*ihost
= sci_object_get_association(scic
);
338 /* Create the SIGNATURE FIS Timeout timer for this phy */
339 sci_phy
->sata_timeout_timer
=
343 scic_sds_phy_sata_timeout
);
345 /* Perfrom the initialization of the TL hardware */
346 scic_sds_phy_transport_layer_initialization(
348 transport_layer_registers
);
350 /* Perofrm the initialization of the PE hardware */
351 scic_sds_phy_link_layer_initialization(sci_phy
, link_layer_registers
);
354 * There is nothing that needs to be done in this state just
355 * transition to the stopped state. */
356 sci_base_state_machine_change_state(&sci_phy
->parent
.state_machine
,
357 SCI_BASE_PHY_STATE_STOPPED
);
363 * This method assigns the direct attached device ID for this phy.
365 * @this_phy The phy for which the direct attached device id is to
367 * @device_id The direct attached device ID to assign to the phy.
368 * This will either be the RNi for the device or an invalid RNi if there
369 * is no current device assigned to the phy.
371 void scic_sds_phy_setup_transport(
372 struct scic_sds_phy
*this_phy
,
377 writel(device_id
, &this_phy
->transport_layer_registers
->stp_rni
);
380 * The read should guarantee that the first write gets posted
381 * before the next write
383 tl_control
= readl(&this_phy
->transport_layer_registers
->control
);
384 tl_control
|= SCU_TLCR_GEN_BIT(CLEAR_TCI_NCQ_MAPPING_TABLE
);
385 writel(tl_control
, &this_phy
->transport_layer_registers
->control
);
390 * @this_phy: The phy object to be suspended.
392 * This function will perform the register reads/writes to suspend the SCU
393 * hardware protocol engine. none
395 static void scic_sds_phy_suspend(
396 struct scic_sds_phy
*this_phy
)
398 u32 scu_sas_pcfg_value
;
401 readl(&this_phy
->link_layer_registers
->phy_configuration
);
402 scu_sas_pcfg_value
|= SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE
);
403 writel(scu_sas_pcfg_value
,
404 &this_phy
->link_layer_registers
->phy_configuration
);
406 scic_sds_phy_setup_transport(this_phy
, SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
);
411 * @this_phy: The phy object to resume.
413 * This function will perform the register reads/writes required to resume the
414 * SCU hardware protocol engine. none
416 void scic_sds_phy_resume(
417 struct scic_sds_phy
*this_phy
)
419 u32 scu_sas_pcfg_value
;
422 readl(&this_phy
->link_layer_registers
->phy_configuration
);
423 scu_sas_pcfg_value
&= ~SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE
);
424 writel(scu_sas_pcfg_value
,
425 &this_phy
->link_layer_registers
->phy_configuration
);
429 * This method returns the local sas address assigned to this phy.
430 * @this_phy: This parameter specifies the phy for which to retrieve the local
432 * @sas_address: This parameter specifies the location into which to copy the
436 void scic_sds_phy_get_sas_address(
437 struct scic_sds_phy
*this_phy
,
438 struct sci_sas_address
*sas_address
)
440 sas_address
->high
= readl(&this_phy
->link_layer_registers
->source_sas_address_high
);
441 sas_address
->low
= readl(&this_phy
->link_layer_registers
->source_sas_address_low
);
445 * This method returns the remote end-point (i.e. attached) sas address
446 * assigned to this phy.
447 * @this_phy: This parameter specifies the phy for which to retrieve the remote
448 * end-point SAS address.
449 * @sas_address: This parameter specifies the location into which to copy the
450 * remote end-point SAS address.
453 void scic_sds_phy_get_attached_sas_address(
454 struct scic_sds_phy
*this_phy
,
455 struct sci_sas_address
*sas_address
)
458 = this_phy
->phy_type
.sas
.identify_address_frame_buffer
.sas_address
.high
;
460 = this_phy
->phy_type
.sas
.identify_address_frame_buffer
.sas_address
.low
;
464 * This method returns the supported protocols assigned to this phy
469 void scic_sds_phy_get_protocols(
470 struct scic_sds_phy
*this_phy
,
471 struct sci_sas_identify_address_frame_protocols
*protocols
)
474 (u16
)(readl(&this_phy
->
475 link_layer_registers
->transmit_identification
) &
481 * @this_phy: The parameter is the phy object for which the attached phy
482 * protcols are to be returned.
484 * This method returns the supported protocols for the attached phy. If this
485 * is a SAS phy the protocols are returned from the identify address frame. If
486 * this is a SATA phy then protocols are made up and the target phy is an STP
487 * target phy. The caller will get the entire set of bits for the protocol
490 void scic_sds_phy_get_attached_phy_protocols(
491 struct scic_sds_phy
*this_phy
,
492 struct sci_sas_identify_address_frame_protocols
*protocols
)
494 protocols
->u
.all
= 0;
496 if (this_phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SAS
) {
498 this_phy
->phy_type
.sas
.identify_address_frame_buffer
.protocols
.u
.all
;
499 } else if (this_phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SATA
) {
500 protocols
->u
.bits
.stp_target
= 1;
505 * *****************************************************************************
506 * * SCIC SDS PHY Handler Redirects
507 * ***************************************************************************** */
510 * This method will attempt to start the phy object. This request is only valid
511 * when the phy is in the stopped state
516 enum sci_status
scic_sds_phy_start(struct scic_sds_phy
*sci_phy
)
518 return sci_phy
->state_handlers
->parent
.start_handler(&sci_phy
->parent
);
522 * This method will attempt to stop the phy object.
525 * enum sci_status SCI_SUCCESS if the phy is going to stop SCI_INVALID_STATE
526 * if the phy is not in a valid state to stop
528 enum sci_status
scic_sds_phy_stop(struct scic_sds_phy
*sci_phy
)
530 return sci_phy
->state_handlers
->parent
.stop_handler(&sci_phy
->parent
);
534 * This method will attempt to reset the phy. This request is only valid when
535 * the phy is in an ready state
540 enum sci_status
scic_sds_phy_reset(
541 struct scic_sds_phy
*this_phy
)
543 return this_phy
->state_handlers
->parent
.reset_handler(
549 * This method will process the event code received.
555 enum sci_status
scic_sds_phy_event_handler(
556 struct scic_sds_phy
*this_phy
,
559 return this_phy
->state_handlers
->event_handler(this_phy
, event_code
);
563 * This method will process the frame index received.
569 enum sci_status
scic_sds_phy_frame_handler(
570 struct scic_sds_phy
*this_phy
,
573 return this_phy
->state_handlers
->frame_handler(this_phy
, frame_index
);
577 * This method will give the phy permission to consume power
582 enum sci_status
scic_sds_phy_consume_power_handler(
583 struct scic_sds_phy
*this_phy
)
585 return this_phy
->state_handlers
->consume_power_handler(this_phy
);
589 * *****************************************************************************
590 * * SCIC PHY Public Methods
591 * ***************************************************************************** */
594 enum sci_status
scic_sas_phy_get_properties(
595 struct scic_sds_phy
*sci_phy
,
596 struct scic_sas_phy_properties
*properties
)
598 if (sci_phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SAS
) {
600 &properties
->received_iaf
,
601 &sci_phy
->phy_type
.sas
.identify_address_frame_buffer
,
602 sizeof(struct sci_sas_identify_address_frame
)
605 properties
->received_capabilities
.u
.all
=
606 readl(&sci_phy
->link_layer_registers
->receive_phycap
);
615 enum sci_status
scic_sata_phy_get_properties(
616 struct scic_sds_phy
*sci_phy
,
617 struct scic_sata_phy_properties
*properties
)
619 if (sci_phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SATA
) {
621 &properties
->signature_fis
,
622 &sci_phy
->phy_type
.sata
.signature_fis_buffer
,
623 sizeof(struct sata_fis_reg_d2h
)
626 /* / @todo add support for port selectors. */
627 properties
->is_port_selector_present
= false;
636 * *****************************************************************************
637 * * SCIC SDS PHY HELPER FUNCTIONS
638 * ***************************************************************************** */
643 * @this_phy: The phy object that received SAS PHY DETECTED.
645 * This method continues the link training for the phy as if it were a SAS PHY
646 * instead of a SATA PHY. This is done because the completion queue had a SAS
647 * PHY DETECTED event when the state machine was expecting a SATA PHY event.
650 static void scic_sds_phy_start_sas_link_training(
651 struct scic_sds_phy
*this_phy
)
656 readl(&this_phy
->link_layer_registers
->phy_configuration
);
657 phy_control
|= SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD
);
659 &this_phy
->link_layer_registers
->phy_configuration
);
661 sci_base_state_machine_change_state(
662 &this_phy
->starting_substate_machine
,
663 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
666 this_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_SAS
;
671 * @this_phy: The phy object that received a SATA SPINUP HOLD event
673 * This method continues the link training for the phy as if it were a SATA PHY
674 * instead of a SAS PHY. This is done because the completion queue had a SATA
675 * SPINUP HOLD event when the state machine was expecting a SAS PHY event. none
677 static void scic_sds_phy_start_sata_link_training(
678 struct scic_sds_phy
*this_phy
)
680 sci_base_state_machine_change_state(
681 &this_phy
->starting_substate_machine
,
682 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
685 this_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_SATA
;
689 * scic_sds_phy_complete_link_training - perform processing common to
690 * all protocols upon completion of link training.
691 * @sci_phy: This parameter specifies the phy object for which link training
693 * @max_link_rate: This parameter specifies the maximum link rate to be
694 * associated with this phy.
695 * @next_state: This parameter specifies the next state for the phy's starting
699 static void scic_sds_phy_complete_link_training(
700 struct scic_sds_phy
*sci_phy
,
701 enum sci_sas_link_rate max_link_rate
,
704 sci_phy
->max_negotiated_speed
= max_link_rate
;
706 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
710 static void scic_sds_phy_restart_starting_state(
711 struct scic_sds_phy
*sci_phy
)
713 /* Stop the current substate machine */
714 sci_base_state_machine_stop(&sci_phy
->starting_substate_machine
);
716 /* Re-enter the base state machine starting state */
717 sci_base_state_machine_change_state(&sci_phy
->parent
.state_machine
,
718 SCI_BASE_PHY_STATE_STARTING
);
721 /* ****************************************************************************
722 * SCIC SDS PHY general handlers
723 ************************************************************************** */
724 static enum sci_status
scic_sds_phy_starting_substate_general_stop_handler(
725 struct sci_base_phy
*phy
)
727 struct scic_sds_phy
*this_phy
;
728 this_phy
= (struct scic_sds_phy
*)phy
;
730 sci_base_state_machine_stop(&this_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
*this_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(this_phy
);
764 this_phy
->is_in_link_training
= true;
767 case SCU_EVENT_SATA_SPINUP_HOLD
:
768 scic_sds_phy_start_sata_link_training(this_phy
);
769 this_phy
->is_in_link_training
= true;
773 dev_dbg(sciphy_to_dev(this_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
*this_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(
816 this_phy
, SCI_SAS_150_GB
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
820 case SCU_EVENT_SAS_30
:
821 case SCU_EVENT_SAS_30_SSC
:
822 scic_sds_phy_complete_link_training(
823 this_phy
, SCI_SAS_300_GB
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
827 case SCU_EVENT_SAS_60
:
828 case SCU_EVENT_SAS_60_SSC
:
829 scic_sds_phy_complete_link_training(
830 this_phy
, SCI_SAS_600_GB
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
834 case SCU_EVENT_SATA_SPINUP_HOLD
:
836 * We were doing SAS PHY link training and received a SATA PHY event
837 * continue OOB/SN as if this were a SATA PHY */
838 scic_sds_phy_start_sata_link_training(this_phy
);
841 case SCU_EVENT_LINK_FAILURE
:
842 /* Link failure change state back to the starting state */
843 scic_sds_phy_restart_starting_state(this_phy
);
847 dev_warn(sciphy_to_dev(this_phy
),
848 "%s: PHY starting substate machine received "
849 "unexpected event_code %x\n",
853 result
= SCI_FAILURE
;
862 * @phy: This struct scic_sds_phy object which has received an event.
863 * @event_code: This is the event code which the phy object is to decode.
865 * This method is called when an event notification is received for the phy
866 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. -
867 * decode the event - sas phy detected event backs up the state machine to the
868 * await speed notification. - identify timeout is an un-expected event and the
869 * state machine is restarted. - link failure events restart the starting state
870 * machine - any other events log a warning message and set a failure status
871 * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any
872 * unexpected event notifation
874 static enum sci_status
scic_sds_phy_starting_substate_await_iaf_uf_event_handler(
875 struct scic_sds_phy
*this_phy
,
878 u32 result
= SCI_SUCCESS
;
880 switch (scu_get_event_code(event_code
)) {
881 case SCU_EVENT_SAS_PHY_DETECTED
:
882 /* Backup the state machine */
883 scic_sds_phy_start_sas_link_training(this_phy
);
886 case SCU_EVENT_SATA_SPINUP_HOLD
:
888 * We were doing SAS PHY link training and received a SATA PHY event
889 * continue OOB/SN as if this were a SATA PHY */
890 scic_sds_phy_start_sata_link_training(this_phy
);
893 case SCU_EVENT_RECEIVED_IDENTIFY_TIMEOUT
:
894 case SCU_EVENT_LINK_FAILURE
:
895 case SCU_EVENT_HARD_RESET_RECEIVED
:
896 /* Start the oob/sn state machine over again */
897 scic_sds_phy_restart_starting_state(this_phy
);
901 dev_warn(sciphy_to_dev(this_phy
),
902 "%s: PHY starting substate machine received "
903 "unexpected event_code %x\n",
907 result
= SCI_FAILURE
;
916 * @phy: This struct scic_sds_phy object which has received an event.
917 * @event_code: This is the event code which the phy object is to decode.
919 * This method is called when an event notification is received for the phy
920 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_POWER. -
921 * decode the event - link failure events restart the starting state machine -
922 * any other events log a warning message and set a failure status enum sci_status
923 * SCI_SUCCESS on a link failure event SCI_FAILURE on any unexpected event
926 static enum sci_status
scic_sds_phy_starting_substate_await_sas_power_event_handler(
927 struct scic_sds_phy
*this_phy
,
930 u32 result
= SCI_SUCCESS
;
932 switch (scu_get_event_code(event_code
)) {
933 case SCU_EVENT_LINK_FAILURE
:
934 /* Link failure change state back to the starting state */
935 scic_sds_phy_restart_starting_state(this_phy
);
939 dev_warn(sciphy_to_dev(this_phy
),
940 "%s: PHY starting substate machine received unexpected "
945 result
= SCI_FAILURE
;
954 * @phy: This struct scic_sds_phy object which has received an event.
955 * @event_code: This is the event code which the phy object is to decode.
957 * This method is called when an event notification is received for the phy
958 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. -
959 * decode the event - link failure events restart the starting state machine -
960 * sata spinup hold events are ignored since they are expected - any other
961 * events log a warning message and set a failure status enum sci_status SCI_SUCCESS
962 * on a link failure event SCI_FAILURE on any unexpected event notifation
964 static enum sci_status
scic_sds_phy_starting_substate_await_sata_power_event_handler(
965 struct scic_sds_phy
*this_phy
,
968 u32 result
= SCI_SUCCESS
;
970 switch (scu_get_event_code(event_code
)) {
971 case SCU_EVENT_LINK_FAILURE
:
972 /* Link failure change state back to the starting state */
973 scic_sds_phy_restart_starting_state(this_phy
);
976 case SCU_EVENT_SATA_SPINUP_HOLD
:
977 /* These events are received every 10ms and are expected while in this state */
980 case SCU_EVENT_SAS_PHY_DETECTED
:
982 * There has been a change in the phy type before OOB/SN for the
983 * SATA finished start down the SAS link traning path. */
984 scic_sds_phy_start_sas_link_training(this_phy
);
988 dev_warn(sciphy_to_dev(this_phy
),
989 "%s: PHY starting substate machine received "
990 "unexpected event_code %x\n",
994 result
= SCI_FAILURE
;
1002 * scic_sds_phy_starting_substate_await_sata_phy_event_handler -
1003 * @phy: This struct scic_sds_phy object which has received an event.
1004 * @event_code: This is the event code which the phy object is to decode.
1006 * This method is called when an event notification is received for the phy
1007 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. -
1008 * decode the event - link failure events restart the starting state machine -
1009 * sata spinup hold events are ignored since they are expected - sata phy
1010 * detected event change to the wait speed event - any other events log a
1011 * warning message and set a failure status enum sci_status SCI_SUCCESS on a link
1012 * failure event SCI_FAILURE on any unexpected event notifation
1014 static enum sci_status
scic_sds_phy_starting_substate_await_sata_phy_event_handler(
1015 struct scic_sds_phy
*sci_phy
, u32 event_code
)
1017 u32 result
= SCI_SUCCESS
;
1019 switch (scu_get_event_code(event_code
)) {
1020 case SCU_EVENT_LINK_FAILURE
:
1021 /* Link failure change state back to the starting state */
1022 scic_sds_phy_restart_starting_state(sci_phy
);
1025 case SCU_EVENT_SATA_SPINUP_HOLD
:
1026 /* These events might be received since we dont know how many may be in
1027 * the completion queue while waiting for power
1031 case SCU_EVENT_SATA_PHY_DETECTED
:
1032 sci_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_SATA
;
1034 /* We have received the SATA PHY notification change state */
1035 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1036 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
);
1039 case SCU_EVENT_SAS_PHY_DETECTED
:
1040 /* There has been a change in the phy type before OOB/SN for the
1041 * SATA finished start down the SAS link traning path.
1043 scic_sds_phy_start_sas_link_training(sci_phy
);
1047 dev_warn(sciphy_to_dev(sci_phy
),
1048 "%s: PHY starting substate machine received "
1049 "unexpected event_code %x\n",
1053 result
= SCI_FAILURE
;
1062 * @phy: This struct scic_sds_phy object which has received an event.
1063 * @event_code: This is the event code which the phy object is to decode.
1065 * This method is called when an event notification is received for the phy
1066 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN.
1067 * - decode the event - sata phy detected returns us back to this state. -
1068 * speed event detected causes a state transition to the wait for signature. -
1069 * link failure events restart the starting state machine - any other events
1070 * log a warning message and set a failure status enum sci_status SCI_SUCCESS on any
1071 * valid event notification SCI_FAILURE on any unexpected event notifation
1073 static enum sci_status
scic_sds_phy_starting_substate_await_sata_speed_event_handler(
1074 struct scic_sds_phy
*this_phy
,
1077 u32 result
= SCI_SUCCESS
;
1079 switch (scu_get_event_code(event_code
)) {
1080 case SCU_EVENT_SATA_PHY_DETECTED
:
1082 * The hardware reports multiple SATA PHY detected events
1083 * ignore the extras */
1086 case SCU_EVENT_SATA_15
:
1087 case SCU_EVENT_SATA_15_SSC
:
1088 scic_sds_phy_complete_link_training(
1091 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
1095 case SCU_EVENT_SATA_30
:
1096 case SCU_EVENT_SATA_30_SSC
:
1097 scic_sds_phy_complete_link_training(
1100 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
1104 case SCU_EVENT_SATA_60
:
1105 case SCU_EVENT_SATA_60_SSC
:
1106 scic_sds_phy_complete_link_training(
1109 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(this_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(this_phy
);
1126 dev_warn(sciphy_to_dev(this_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 * scic_sds_phy_starting_substate_await_sas_power_consume_power_handler -
1336 * @phy: This is the struct sci_base_phy object which is cast into a struct scic_sds_phy
1339 * This method is called by the struct scic_sds_controller when the phy object is
1340 * granted power. - The notify enable spinups are turned on for this phy object
1341 * - The phy state machine is transitioned to the
1342 * SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. enum sci_status SCI_SUCCESS
1344 static enum sci_status
scic_sds_phy_starting_substate_await_sas_power_consume_power_handler(
1345 struct scic_sds_phy
*sci_phy
)
1349 enable_spinup
= readl(&sci_phy
->link_layer_registers
->notify_enable_spinup_control
);
1350 enable_spinup
|= SCU_ENSPINUP_GEN_BIT(ENABLE
);
1351 writel(enable_spinup
, &sci_phy
->link_layer_registers
->notify_enable_spinup_control
);
1353 /* Change state to the final state this substate machine has run to completion */
1354 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1355 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
);
1362 * @phy: This is the struct sci_base_phy object which is cast into a struct scic_sds_phy
1365 * This method is called by the struct scic_sds_controller when the phy object is
1366 * granted power. - The phy state machine is transitioned to the
1367 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. enum sci_status SCI_SUCCESS
1369 static enum sci_status
scic_sds_phy_starting_substate_await_sata_power_consume_power_handler(
1370 struct scic_sds_phy
*sci_phy
)
1372 u32 scu_sas_pcfg_value
;
1374 /* Release the spinup hold state and reset the OOB state machine */
1375 scu_sas_pcfg_value
=
1376 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
1377 scu_sas_pcfg_value
&=
1378 ~(SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD
) | SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE
));
1379 scu_sas_pcfg_value
|= SCU_SAS_PCFG_GEN_BIT(OOB_RESET
);
1380 writel(scu_sas_pcfg_value
,
1381 &sci_phy
->link_layer_registers
->phy_configuration
);
1383 /* Now restart the OOB operation */
1384 scu_sas_pcfg_value
&= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET
);
1385 scu_sas_pcfg_value
|= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE
);
1386 writel(scu_sas_pcfg_value
,
1387 &sci_phy
->link_layer_registers
->phy_configuration
);
1389 /* Change state to the final state this substate machine has run to completion */
1390 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1391 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN
);
1396 static enum sci_status
default_phy_handler(struct sci_base_phy
*base_phy
, const char *func
)
1398 struct scic_sds_phy
*sci_phy
;
1400 sci_phy
= container_of(base_phy
, typeof(*sci_phy
), parent
);
1401 dev_dbg(sciphy_to_dev(sci_phy
),
1402 "%s: in wrong state: %d\n", func
,
1403 sci_base_state_machine_get_state(&base_phy
->state_machine
));
1404 return SCI_FAILURE_INVALID_STATE
;
1407 static enum sci_status
scic_sds_phy_default_start_handler(struct sci_base_phy
*base_phy
)
1409 return default_phy_handler(base_phy
, __func__
);
1412 static enum sci_status
scic_sds_phy_default_stop_handler(struct sci_base_phy
*base_phy
)
1414 return default_phy_handler(base_phy
, __func__
);
1417 static enum sci_status
scic_sds_phy_default_reset_handler(struct sci_base_phy
*base_phy
)
1419 return default_phy_handler(base_phy
, __func__
);
1422 static enum sci_status
scic_sds_phy_default_destroy_handler(struct sci_base_phy
*base_phy
)
1424 return default_phy_handler(base_phy
, __func__
);
1427 static enum sci_status
scic_sds_phy_default_frame_handler(struct scic_sds_phy
*sci_phy
,
1430 struct scic_sds_controller
*scic
= scic_sds_phy_get_controller(sci_phy
);
1432 default_phy_handler(&sci_phy
->parent
, __func__
);
1433 scic_sds_controller_release_frame(scic
, frame_index
);
1435 return SCI_FAILURE_INVALID_STATE
;
1438 static enum sci_status
scic_sds_phy_default_event_handler(struct scic_sds_phy
*sci_phy
,
1441 return default_phy_handler(&sci_phy
->parent
, __func__
);
1444 static enum sci_status
scic_sds_phy_default_consume_power_handler(struct scic_sds_phy
*sci_phy
)
1446 return default_phy_handler(&sci_phy
->parent
, __func__
);
1451 static const struct scic_sds_phy_state_handler scic_sds_phy_starting_substate_handler_table
[] = {
1452 [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL
] = {
1453 .parent
.start_handler
= scic_sds_phy_default_start_handler
,
1454 .parent
.stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1455 .parent
.reset_handler
= scic_sds_phy_default_reset_handler
,
1456 .parent
.destruct_handler
= scic_sds_phy_default_destroy_handler
,
1457 .frame_handler
= scic_sds_phy_default_frame_handler
,
1458 .event_handler
= scic_sds_phy_default_event_handler
,
1459 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1461 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
] = {
1462 .parent
.start_handler
= scic_sds_phy_default_start_handler
,
1463 .parent
.stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1464 .parent
.reset_handler
= scic_sds_phy_default_reset_handler
,
1465 .parent
.destruct_handler
= scic_sds_phy_default_destroy_handler
,
1466 .frame_handler
= scic_sds_phy_default_frame_handler
,
1467 .event_handler
= scic_sds_phy_starting_substate_await_ossp_event_handler
,
1468 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1470 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
] = {
1471 .parent
.start_handler
= scic_sds_phy_default_start_handler
,
1472 .parent
.stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1473 .parent
.reset_handler
= scic_sds_phy_default_reset_handler
,
1474 .parent
.destruct_handler
= scic_sds_phy_default_destroy_handler
,
1475 .frame_handler
= scic_sds_phy_default_frame_handler
,
1476 .event_handler
= scic_sds_phy_starting_substate_await_sas_phy_speed_event_handler
,
1477 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1479 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
] = {
1480 .parent
.start_handler
= scic_sds_phy_default_start_handler
,
1481 .parent
.stop_handler
= scic_sds_phy_default_stop_handler
,
1482 .parent
.reset_handler
= scic_sds_phy_default_reset_handler
,
1483 .parent
.destruct_handler
= scic_sds_phy_default_destroy_handler
,
1484 .frame_handler
= scic_sds_phy_starting_substate_await_iaf_uf_frame_handler
,
1485 .event_handler
= scic_sds_phy_starting_substate_await_iaf_uf_event_handler
,
1486 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1488 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
] = {
1489 .parent
.start_handler
= scic_sds_phy_default_start_handler
,
1490 .parent
.stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1491 .parent
.reset_handler
= scic_sds_phy_default_reset_handler
,
1492 .parent
.destruct_handler
= scic_sds_phy_default_destroy_handler
,
1493 .frame_handler
= scic_sds_phy_default_frame_handler
,
1494 .event_handler
= scic_sds_phy_starting_substate_await_sas_power_event_handler
,
1495 .consume_power_handler
= scic_sds_phy_starting_substate_await_sas_power_consume_power_handler
1497 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
] = {
1498 .parent
.start_handler
= scic_sds_phy_default_start_handler
,
1499 .parent
.stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1500 .parent
.reset_handler
= scic_sds_phy_default_reset_handler
,
1501 .parent
.destruct_handler
= scic_sds_phy_default_destroy_handler
,
1502 .frame_handler
= scic_sds_phy_default_frame_handler
,
1503 .event_handler
= scic_sds_phy_starting_substate_await_sata_power_event_handler
,
1504 .consume_power_handler
= scic_sds_phy_starting_substate_await_sata_power_consume_power_handler
1506 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN
] = {
1507 .parent
.start_handler
= scic_sds_phy_default_start_handler
,
1508 .parent
.stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1509 .parent
.reset_handler
= scic_sds_phy_default_reset_handler
,
1510 .parent
.destruct_handler
= scic_sds_phy_default_destroy_handler
,
1511 .frame_handler
= scic_sds_phy_default_frame_handler
,
1512 .event_handler
= scic_sds_phy_starting_substate_await_sata_phy_event_handler
,
1513 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1515 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
] = {
1516 .parent
.start_handler
= scic_sds_phy_default_start_handler
,
1517 .parent
.stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1518 .parent
.reset_handler
= scic_sds_phy_default_reset_handler
,
1519 .parent
.destruct_handler
= scic_sds_phy_default_destroy_handler
,
1520 .frame_handler
= scic_sds_phy_default_frame_handler
,
1521 .event_handler
= scic_sds_phy_starting_substate_await_sata_speed_event_handler
,
1522 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1524 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
] = {
1525 .parent
.start_handler
= scic_sds_phy_default_start_handler
,
1526 .parent
.stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1527 .parent
.reset_handler
= scic_sds_phy_default_reset_handler
,
1528 .parent
.destruct_handler
= scic_sds_phy_default_destroy_handler
,
1529 .frame_handler
= scic_sds_phy_starting_substate_await_sig_fis_frame_handler
,
1530 .event_handler
= scic_sds_phy_starting_substate_await_sig_fis_event_handler
,
1531 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1533 [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
] = {
1534 .parent
.start_handler
= scic_sds_phy_default_start_handler
,
1535 .parent
.stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1536 .parent
.reset_handler
= scic_sds_phy_default_reset_handler
,
1537 .parent
.destruct_handler
= scic_sds_phy_default_destroy_handler
,
1538 .frame_handler
= scic_sds_phy_default_frame_handler
,
1539 .event_handler
= scic_sds_phy_default_event_handler
,
1540 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1545 * scic_sds_phy_set_starting_substate_handlers() -
1547 * This macro sets the starting substate handlers by state_id
1549 #define scic_sds_phy_set_starting_substate_handlers(phy, state_id) \
1550 scic_sds_phy_set_state_handlers(\
1552 &scic_sds_phy_starting_substate_handler_table[(state_id)] \
1556 * ****************************************************************************
1557 * * PHY STARTING SUBSTATE METHODS
1558 * **************************************************************************** */
1561 * scic_sds_phy_starting_initial_substate_enter -
1562 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
1564 * This method will perform the actions required by the struct scic_sds_phy on
1565 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL. - The initial state
1566 * handlers are put in place for the struct scic_sds_phy object. - The state is
1567 * changed to the wait phy type event notification. none
1569 static void scic_sds_phy_starting_initial_substate_enter(struct sci_base_object
*object
)
1571 struct scic_sds_phy
*sci_phy
;
1573 sci_phy
= (struct scic_sds_phy
*)object
;
1575 scic_sds_phy_set_starting_substate_handlers(
1576 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL
);
1578 /* This is just an temporary state go off to the starting state */
1579 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1580 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
);
1585 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
1587 * This method will perform the actions required by the struct scic_sds_phy on
1588 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_PHY_TYPE_EN. - Set the
1589 * struct scic_sds_phy object state handlers for this state. none
1591 static void scic_sds_phy_starting_await_ossp_en_substate_enter(
1592 struct sci_base_object
*object
)
1594 struct scic_sds_phy
*this_phy
;
1596 this_phy
= (struct scic_sds_phy
*)object
;
1598 scic_sds_phy_set_starting_substate_handlers(
1599 this_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
1605 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
1607 * This method will perform the actions required by the struct scic_sds_phy on
1608 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. - Set the
1609 * struct scic_sds_phy object state handlers for this state. none
1611 static void scic_sds_phy_starting_await_sas_speed_en_substate_enter(
1612 struct sci_base_object
*object
)
1614 struct scic_sds_phy
*this_phy
;
1616 this_phy
= (struct scic_sds_phy
*)object
;
1618 scic_sds_phy_set_starting_substate_handlers(
1619 this_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
1625 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
1627 * This method will perform the actions required by the struct scic_sds_phy on
1628 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - Set the
1629 * struct scic_sds_phy object state handlers for this state. none
1631 static void scic_sds_phy_starting_await_iaf_uf_substate_enter(
1632 struct sci_base_object
*object
)
1634 struct scic_sds_phy
*this_phy
;
1636 this_phy
= (struct scic_sds_phy
*)object
;
1638 scic_sds_phy_set_starting_substate_handlers(
1639 this_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
1645 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
1647 * This method will perform the actions required by the struct scic_sds_phy on
1648 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Set the
1649 * struct scic_sds_phy object state handlers for this state. - Add this phy object to
1650 * the power control queue none
1652 static void scic_sds_phy_starting_await_sas_power_substate_enter(
1653 struct sci_base_object
*object
)
1655 struct scic_sds_phy
*this_phy
;
1657 this_phy
= (struct scic_sds_phy
*)object
;
1659 scic_sds_phy_set_starting_substate_handlers(
1660 this_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
1663 scic_sds_controller_power_control_queue_insert(
1664 scic_sds_phy_get_controller(this_phy
),
1671 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
1673 * This method will perform the actions required by the struct scic_sds_phy on exiting
1674 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Remove the
1675 * struct scic_sds_phy object from the power control queue. none
1677 static void scic_sds_phy_starting_await_sas_power_substate_exit(
1678 struct sci_base_object
*object
)
1680 struct scic_sds_phy
*this_phy
;
1682 this_phy
= (struct scic_sds_phy
*)object
;
1684 scic_sds_controller_power_control_queue_remove(
1685 scic_sds_phy_get_controller(this_phy
), this_phy
1691 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
1693 * This method will perform the actions required by the struct scic_sds_phy on
1694 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Set the
1695 * struct scic_sds_phy object state handlers for this state. - Add this phy object to
1696 * the power control queue none
1698 static void scic_sds_phy_starting_await_sata_power_substate_enter(
1699 struct sci_base_object
*object
)
1701 struct scic_sds_phy
*this_phy
;
1703 this_phy
= (struct scic_sds_phy
*)object
;
1705 scic_sds_phy_set_starting_substate_handlers(
1706 this_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
1709 scic_sds_controller_power_control_queue_insert(
1710 scic_sds_phy_get_controller(this_phy
),
1717 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
1719 * This method will perform the actions required by the struct scic_sds_phy on exiting
1720 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Remove the
1721 * struct scic_sds_phy object from the power control queue. none
1723 static void scic_sds_phy_starting_await_sata_power_substate_exit(
1724 struct sci_base_object
*object
)
1726 struct scic_sds_phy
*this_phy
;
1728 this_phy
= (struct scic_sds_phy
*)object
;
1730 scic_sds_controller_power_control_queue_remove(
1731 scic_sds_phy_get_controller(this_phy
),
1738 * @object: This is the struct sci_base_object which is cast to a
1739 * struct scic_sds_phy object.
1741 * This function will perform the actions required by the struct scic_sds_phy on
1742 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. - Set the
1743 * struct scic_sds_phy object state handlers for this state. none
1745 static void scic_sds_phy_starting_await_sata_phy_substate_enter(
1746 struct sci_base_object
*object
)
1748 struct scic_sds_phy
*sci_phy
= (struct scic_sds_phy
*)object
;
1750 scic_sds_phy_set_starting_substate_handlers(
1752 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN
);
1754 isci_timer_start(sci_phy
->sata_timeout_timer
,
1755 SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT
);
1760 * @object: This is the struct sci_base_object which is cast to a
1761 * struct scic_sds_phy object.
1763 * This method will perform the actions required by the struct scic_sds_phy
1765 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
1766 * that was started on entry to await sata phy event notification none
1768 static inline void scic_sds_phy_starting_await_sata_phy_substate_exit(
1769 struct sci_base_object
*object
)
1771 struct scic_sds_phy
*sci_phy
= (struct scic_sds_phy
*)object
;
1773 isci_timer_stop(sci_phy
->sata_timeout_timer
);
1778 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
1780 * This method will perform the actions required by the struct scic_sds_phy on
1781 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - Set the
1782 * struct scic_sds_phy object state handlers for this state. none
1784 static void scic_sds_phy_starting_await_sata_speed_substate_enter(
1785 struct sci_base_object
*object
)
1787 struct scic_sds_phy
*sci_phy
= (struct scic_sds_phy
*)object
;
1789 scic_sds_phy_set_starting_substate_handlers(
1791 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
);
1793 isci_timer_start(sci_phy
->sata_timeout_timer
,
1794 SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT
);
1799 * @object: This is the struct sci_base_object which is cast to a
1800 * struct scic_sds_phy object.
1802 * This function will perform the actions required by the
1803 * struct scic_sds_phy on exiting
1804 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
1805 * that was started on entry to await sata phy event notification none
1807 static inline void scic_sds_phy_starting_await_sata_speed_substate_exit(
1808 struct sci_base_object
*object
)
1810 struct scic_sds_phy
*sci_phy
= (struct scic_sds_phy
*)object
;
1812 isci_timer_stop(sci_phy
->sata_timeout_timer
);
1817 * @object: This is the struct sci_base_object which is cast to a
1818 * struct scic_sds_phy object.
1820 * This function will perform the actions required by the struct scic_sds_phy on
1821 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Set the
1822 * struct scic_sds_phy object state handlers for this state.
1823 * - Start the SIGNATURE FIS
1824 * timeout timer none
1826 static void scic_sds_phy_starting_await_sig_fis_uf_substate_enter(
1827 struct sci_base_object
*object
)
1829 bool continue_to_ready_state
;
1830 struct scic_sds_phy
*sci_phy
= (struct scic_sds_phy
*)object
;
1832 scic_sds_phy_set_starting_substate_handlers(
1834 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
);
1836 continue_to_ready_state
= scic_sds_port_link_detected(
1837 sci_phy
->owning_port
,
1840 if (continue_to_ready_state
) {
1842 * Clear the PE suspend condition so we can actually
1844 * The hardware will not respond to the XRDY until the PE
1845 * suspend condition is cleared.
1847 scic_sds_phy_resume(sci_phy
);
1849 isci_timer_start(sci_phy
->sata_timeout_timer
,
1850 SCIC_SDS_SIGNATURE_FIS_TIMEOUT
);
1852 sci_phy
->is_in_link_training
= false;
1857 * @object: This is the struct sci_base_object which is cast to a
1858 * struct scic_sds_phy object.
1860 * This function will perform the actions required by the
1861 * struct scic_sds_phy on exiting
1862 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Stop the SIGNATURE
1863 * FIS timeout timer. none
1865 static inline void scic_sds_phy_starting_await_sig_fis_uf_substate_exit(
1866 struct sci_base_object
*object
)
1868 struct scic_sds_phy
*sci_phy
;
1870 sci_phy
= (struct scic_sds_phy
*)object
;
1872 isci_timer_stop(sci_phy
->sata_timeout_timer
);
1877 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
1879 * This method will perform the actions required by the struct scic_sds_phy on
1880 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. - Set the struct scic_sds_phy
1881 * object state handlers for this state. - Change base state machine to the
1884 static void scic_sds_phy_starting_final_substate_enter(struct sci_base_object
*object
)
1886 struct scic_sds_phy
*sci_phy
;
1888 sci_phy
= container_of(object
, typeof(*sci_phy
), parent
.parent
);
1890 scic_sds_phy_set_starting_substate_handlers(sci_phy
,
1891 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
);
1893 /* State machine has run to completion so exit out and change
1894 * the base state machine to the ready state
1896 sci_base_state_machine_change_state(&sci_phy
->parent
.state_machine
,
1897 SCI_BASE_PHY_STATE_READY
);
1900 /* --------------------------------------------------------------------------- */
1902 static const struct sci_base_state scic_sds_phy_starting_substates
[] = {
1903 [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL
] = {
1904 .enter_state
= scic_sds_phy_starting_initial_substate_enter
,
1906 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
] = {
1907 .enter_state
= scic_sds_phy_starting_await_ossp_en_substate_enter
,
1909 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
] = {
1910 .enter_state
= scic_sds_phy_starting_await_sas_speed_en_substate_enter
,
1912 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
] = {
1913 .enter_state
= scic_sds_phy_starting_await_iaf_uf_substate_enter
,
1915 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
] = {
1916 .enter_state
= scic_sds_phy_starting_await_sas_power_substate_enter
,
1917 .exit_state
= scic_sds_phy_starting_await_sas_power_substate_exit
,
1919 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
] = {
1920 .enter_state
= scic_sds_phy_starting_await_sata_power_substate_enter
,
1921 .exit_state
= scic_sds_phy_starting_await_sata_power_substate_exit
1923 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN
] = {
1924 .enter_state
= scic_sds_phy_starting_await_sata_phy_substate_enter
,
1925 .exit_state
= scic_sds_phy_starting_await_sata_phy_substate_exit
1927 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
] = {
1928 .enter_state
= scic_sds_phy_starting_await_sata_speed_substate_enter
,
1929 .exit_state
= scic_sds_phy_starting_await_sata_speed_substate_exit
1931 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
] = {
1932 .enter_state
= scic_sds_phy_starting_await_sig_fis_uf_substate_enter
,
1933 .exit_state
= scic_sds_phy_starting_await_sig_fis_uf_substate_exit
1935 [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
] = {
1936 .enter_state
= scic_sds_phy_starting_final_substate_enter
,
1942 * @phy: This is the struct sci_base_phy object which is cast into a
1943 * struct scic_sds_phy object.
1945 * This method takes the struct scic_sds_phy from a stopped state and
1946 * attempts to start it. - The phy state machine is transitioned to the
1947 * SCI_BASE_PHY_STATE_STARTING. enum sci_status SCI_SUCCESS
1949 static enum sci_status
scic_sds_phy_stopped_state_start_handler(struct sci_base_phy
*base_phy
)
1951 struct isci_host
*ihost
;
1952 struct scic_sds_phy
*sci_phy
;
1953 struct scic_sds_controller
*scic
;
1955 sci_phy
= container_of(base_phy
, typeof(*sci_phy
), parent
);
1956 scic
= scic_sds_phy_get_controller(sci_phy
),
1957 ihost
= sci_object_get_association(scic
);
1959 /* Create the SIGNATURE FIS Timeout timer for this phy */
1960 sci_phy
->sata_timeout_timer
= isci_timer_create(ihost
, sci_phy
,
1961 scic_sds_phy_sata_timeout
);
1963 if (sci_phy
->sata_timeout_timer
)
1964 sci_base_state_machine_change_state(&sci_phy
->parent
.state_machine
,
1965 SCI_BASE_PHY_STATE_STARTING
);
1970 static enum sci_status
scic_sds_phy_stopped_state_destroy_handler(struct sci_base_phy
*base_phy
)
1975 static enum sci_status
scic_sds_phy_ready_state_stop_handler(struct sci_base_phy
*base_phy
)
1977 sci_base_state_machine_change_state(&base_phy
->state_machine
,
1978 SCI_BASE_PHY_STATE_STOPPED
);
1983 static enum sci_status
scic_sds_phy_ready_state_reset_handler(struct sci_base_phy
*base_phy
)
1985 sci_base_state_machine_change_state(&base_phy
->state_machine
,
1986 SCI_BASE_PHY_STATE_RESETTING
);
1992 * scic_sds_phy_ready_state_event_handler -
1993 * @phy: This is the struct scic_sds_phy object which has received the event.
1995 * This method request the struct scic_sds_phy handle the received event. The only
1996 * event that we are interested in while in the ready state is the link failure
1997 * event. - decoded event is a link failure - transition the struct scic_sds_phy back
1998 * to the SCI_BASE_PHY_STATE_STARTING state. - any other event received will
1999 * report a warning message enum sci_status SCI_SUCCESS if the event received is a
2000 * link failure SCI_FAILURE_INVALID_STATE for any other event received.
2002 static enum sci_status
scic_sds_phy_ready_state_event_handler(struct scic_sds_phy
*sci_phy
,
2005 enum sci_status result
= SCI_FAILURE
;
2007 switch (scu_get_event_code(event_code
)) {
2008 case SCU_EVENT_LINK_FAILURE
:
2009 /* Link failure change state back to the starting state */
2010 sci_base_state_machine_change_state(&sci_phy
->parent
.state_machine
,
2011 SCI_BASE_PHY_STATE_STARTING
);
2012 result
= SCI_SUCCESS
;
2015 case SCU_EVENT_BROADCAST_CHANGE
:
2016 /* Broadcast change received. Notify the port. */
2017 if (scic_sds_phy_get_port(sci_phy
) != NULL
)
2018 scic_sds_port_broadcast_change_received(sci_phy
->owning_port
, sci_phy
);
2020 sci_phy
->bcn_received_while_port_unassigned
= true;
2024 dev_warn(sciphy_to_dev(sci_phy
),
2025 "%sP SCIC PHY 0x%p ready state machine received "
2026 "unexpected event_code %x\n",
2027 __func__
, sci_phy
, event_code
);
2029 result
= SCI_FAILURE_INVALID_STATE
;
2036 static enum sci_status
scic_sds_phy_resetting_state_event_handler(struct scic_sds_phy
*sci_phy
,
2039 enum sci_status result
= SCI_FAILURE
;
2041 switch (scu_get_event_code(event_code
)) {
2042 case SCU_EVENT_HARD_RESET_TRANSMITTED
:
2043 /* Link failure change state back to the starting state */
2044 sci_base_state_machine_change_state(&sci_phy
->parent
.state_machine
,
2045 SCI_BASE_PHY_STATE_STARTING
);
2046 result
= SCI_SUCCESS
;
2050 dev_warn(sciphy_to_dev(sci_phy
),
2051 "%s: SCIC PHY 0x%p resetting state machine received "
2052 "unexpected event_code %x\n",
2053 __func__
, sci_phy
, event_code
);
2055 result
= SCI_FAILURE_INVALID_STATE
;
2062 /* --------------------------------------------------------------------------- */
2064 static const struct scic_sds_phy_state_handler scic_sds_phy_state_handler_table
[] = {
2065 [SCI_BASE_PHY_STATE_INITIAL
] = {
2066 .parent
.start_handler
= scic_sds_phy_default_start_handler
,
2067 .parent
.stop_handler
= scic_sds_phy_default_stop_handler
,
2068 .parent
.reset_handler
= scic_sds_phy_default_reset_handler
,
2069 .parent
.destruct_handler
= scic_sds_phy_default_destroy_handler
,
2070 .frame_handler
= scic_sds_phy_default_frame_handler
,
2071 .event_handler
= scic_sds_phy_default_event_handler
,
2072 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
2074 [SCI_BASE_PHY_STATE_STOPPED
] = {
2075 .parent
.start_handler
= scic_sds_phy_stopped_state_start_handler
,
2076 .parent
.stop_handler
= scic_sds_phy_default_stop_handler
,
2077 .parent
.reset_handler
= scic_sds_phy_default_reset_handler
,
2078 .parent
.destruct_handler
= scic_sds_phy_stopped_state_destroy_handler
,
2079 .frame_handler
= scic_sds_phy_default_frame_handler
,
2080 .event_handler
= scic_sds_phy_default_event_handler
,
2081 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
2083 [SCI_BASE_PHY_STATE_STARTING
] = {
2084 .parent
.start_handler
= scic_sds_phy_default_start_handler
,
2085 .parent
.stop_handler
= scic_sds_phy_default_stop_handler
,
2086 .parent
.reset_handler
= scic_sds_phy_default_reset_handler
,
2087 .parent
.destruct_handler
= scic_sds_phy_default_destroy_handler
,
2088 .frame_handler
= scic_sds_phy_default_frame_handler
,
2089 .event_handler
= scic_sds_phy_default_event_handler
,
2090 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
2092 [SCI_BASE_PHY_STATE_READY
] = {
2093 .parent
.start_handler
= scic_sds_phy_default_start_handler
,
2094 .parent
.stop_handler
= scic_sds_phy_ready_state_stop_handler
,
2095 .parent
.reset_handler
= scic_sds_phy_ready_state_reset_handler
,
2096 .parent
.destruct_handler
= scic_sds_phy_default_destroy_handler
,
2097 .frame_handler
= scic_sds_phy_default_frame_handler
,
2098 .event_handler
= scic_sds_phy_ready_state_event_handler
,
2099 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
2101 [SCI_BASE_PHY_STATE_RESETTING
] = {
2102 .parent
.start_handler
= scic_sds_phy_default_start_handler
,
2103 .parent
.stop_handler
= scic_sds_phy_default_stop_handler
,
2104 .parent
.reset_handler
= scic_sds_phy_default_reset_handler
,
2105 .parent
.destruct_handler
= scic_sds_phy_default_destroy_handler
,
2106 .frame_handler
= scic_sds_phy_default_frame_handler
,
2107 .event_handler
= scic_sds_phy_resetting_state_event_handler
,
2108 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
2110 [SCI_BASE_PHY_STATE_FINAL
] = {
2111 .parent
.start_handler
= scic_sds_phy_default_start_handler
,
2112 .parent
.stop_handler
= scic_sds_phy_default_stop_handler
,
2113 .parent
.reset_handler
= scic_sds_phy_default_reset_handler
,
2114 .parent
.destruct_handler
= scic_sds_phy_default_destroy_handler
,
2115 .frame_handler
= scic_sds_phy_default_frame_handler
,
2116 .event_handler
= scic_sds_phy_default_event_handler
,
2117 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
2122 * ****************************************************************************
2123 * * PHY STATE PRIVATE METHODS
2124 * **************************************************************************** */
2128 * @this_phy: This is the struct scic_sds_phy object to stop.
2130 * This method will stop the struct scic_sds_phy object. This does not reset the
2131 * protocol engine it just suspends it and places it in a state where it will
2132 * not cause the end device to power up. none
2134 static void scu_link_layer_stop_protocol_engine(
2135 struct scic_sds_phy
*this_phy
)
2137 u32 scu_sas_pcfg_value
;
2138 u32 enable_spinup_value
;
2140 /* Suspend the protocol engine and place it in a sata spinup hold state */
2141 scu_sas_pcfg_value
=
2142 readl(&this_phy
->link_layer_registers
->phy_configuration
);
2143 scu_sas_pcfg_value
|= (
2144 SCU_SAS_PCFG_GEN_BIT(OOB_RESET
)
2145 | SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE
)
2146 | SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD
)
2148 writel(scu_sas_pcfg_value
,
2149 &this_phy
->link_layer_registers
->phy_configuration
);
2151 /* Disable the notify enable spinup primitives */
2152 enable_spinup_value
= readl(&this_phy
->link_layer_registers
->notify_enable_spinup_control
);
2153 enable_spinup_value
&= ~SCU_ENSPINUP_GEN_BIT(ENABLE
);
2154 writel(enable_spinup_value
, &this_phy
->link_layer_registers
->notify_enable_spinup_control
);
2160 * This method will start the OOB/SN state machine for this struct scic_sds_phy object.
2162 static void scu_link_layer_start_oob(
2163 struct scic_sds_phy
*this_phy
)
2165 u32 scu_sas_pcfg_value
;
2167 scu_sas_pcfg_value
=
2168 readl(&this_phy
->link_layer_registers
->phy_configuration
);
2169 scu_sas_pcfg_value
|= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE
);
2170 scu_sas_pcfg_value
&=
2171 ~(SCU_SAS_PCFG_GEN_BIT(OOB_RESET
) | SCU_SAS_PCFG_GEN_BIT(HARD_RESET
));
2172 writel(scu_sas_pcfg_value
,
2173 &this_phy
->link_layer_registers
->phy_configuration
);
2179 * This method will transmit a hard reset request on the specified phy. The SCU
2180 * hardware requires that we reset the OOB state machine and set the hard reset
2181 * bit in the phy configuration register. We then must start OOB over with the
2182 * hard reset bit set.
2184 static void scu_link_layer_tx_hard_reset(
2185 struct scic_sds_phy
*this_phy
)
2187 u32 phy_configuration_value
;
2190 * SAS Phys must wait for the HARD_RESET_TX event notification to transition
2191 * to the starting state. */
2192 phy_configuration_value
=
2193 readl(&this_phy
->link_layer_registers
->phy_configuration
);
2194 phy_configuration_value
|=
2195 (SCU_SAS_PCFG_GEN_BIT(HARD_RESET
) | SCU_SAS_PCFG_GEN_BIT(OOB_RESET
));
2196 writel(phy_configuration_value
,
2197 &this_phy
->link_layer_registers
->phy_configuration
);
2199 /* Now take the OOB state machine out of reset */
2200 phy_configuration_value
|= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE
);
2201 phy_configuration_value
&= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET
);
2202 writel(phy_configuration_value
,
2203 &this_phy
->link_layer_registers
->phy_configuration
);
2207 * ****************************************************************************
2208 * * PHY BASE STATE METHODS
2209 * **************************************************************************** */
2213 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
2215 * This method will perform the actions required by the struct scic_sds_phy on
2216 * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
2217 * handlers for the phy object base state machine initial state. none
2219 static void scic_sds_phy_initial_state_enter(
2220 struct sci_base_object
*object
)
2222 struct scic_sds_phy
*this_phy
;
2224 this_phy
= (struct scic_sds_phy
*)object
;
2226 scic_sds_phy_set_base_state_handlers(this_phy
, SCI_BASE_PHY_STATE_INITIAL
);
2231 * @object: This is the struct sci_base_object which is cast to a
2232 * struct scic_sds_phy object.
2234 * This function will perform the actions required by the struct scic_sds_phy on
2235 * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
2236 * handlers for the phy object base state machine initial state. - The SCU
2237 * hardware is requested to stop the protocol engine. none
2239 static void scic_sds_phy_stopped_state_enter(struct sci_base_object
*object
)
2241 struct scic_sds_phy
*sci_phy
= (struct scic_sds_phy
*)object
;
2242 struct scic_sds_controller
*scic
= scic_sds_phy_get_controller(sci_phy
);
2243 struct isci_host
*ihost
= sci_object_get_association(scic
);
2245 sci_phy
= (struct scic_sds_phy
*)object
;
2248 * @todo We need to get to the controller to place this PE in a
2252 scic_sds_phy_set_base_state_handlers(sci_phy
,
2253 SCI_BASE_PHY_STATE_STOPPED
);
2255 if (sci_phy
->sata_timeout_timer
!= NULL
) {
2256 isci_del_timer(ihost
, sci_phy
->sata_timeout_timer
);
2258 sci_phy
->sata_timeout_timer
= NULL
;
2261 scu_link_layer_stop_protocol_engine(sci_phy
);
2263 if (sci_phy
->parent
.state_machine
.previous_state_id
!=
2264 SCI_BASE_PHY_STATE_INITIAL
)
2265 scic_sds_controller_link_down(
2266 scic_sds_phy_get_controller(sci_phy
),
2267 scic_sds_phy_get_port(sci_phy
),
2273 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
2275 * This method will perform the actions required by the struct scic_sds_phy on
2276 * entering the SCI_BASE_PHY_STATE_STARTING. - This function sets the state
2277 * handlers for the phy object base state machine starting state. - The SCU
2278 * hardware is requested to start OOB/SN on this protocl engine. - The phy
2279 * starting substate machine is started. - If the previous state was the ready
2280 * state then the struct scic_sds_controller is informed that the phy has gone link
2283 static void scic_sds_phy_starting_state_enter(
2284 struct sci_base_object
*object
)
2286 struct scic_sds_phy
*this_phy
;
2288 this_phy
= (struct scic_sds_phy
*)object
;
2290 scic_sds_phy_set_base_state_handlers(this_phy
, SCI_BASE_PHY_STATE_STARTING
);
2292 scu_link_layer_stop_protocol_engine(this_phy
);
2293 scu_link_layer_start_oob(this_phy
);
2295 /* We don't know what kind of phy we are going to be just yet */
2296 this_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_UNKNOWN
;
2297 this_phy
->bcn_received_while_port_unassigned
= false;
2299 /* Change over to the starting substate machine to continue */
2300 sci_base_state_machine_start(&this_phy
->starting_substate_machine
);
2302 if (this_phy
->parent
.state_machine
.previous_state_id
2303 == SCI_BASE_PHY_STATE_READY
) {
2304 scic_sds_controller_link_down(
2305 scic_sds_phy_get_controller(this_phy
),
2306 scic_sds_phy_get_port(this_phy
),
2314 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
2316 * This method will perform the actions required by the struct scic_sds_phy on
2317 * entering the SCI_BASE_PHY_STATE_READY. - This function sets the state
2318 * handlers for the phy object base state machine ready state. - The SCU
2319 * hardware protocol engine is resumed. - The struct scic_sds_controller is informed
2320 * that the phy object has gone link up. none
2322 static void scic_sds_phy_ready_state_enter(
2323 struct sci_base_object
*object
)
2325 struct scic_sds_phy
*this_phy
;
2327 this_phy
= (struct scic_sds_phy
*)object
;
2329 scic_sds_phy_set_base_state_handlers(this_phy
, SCI_BASE_PHY_STATE_READY
);
2331 scic_sds_controller_link_up(
2332 scic_sds_phy_get_controller(this_phy
),
2333 scic_sds_phy_get_port(this_phy
),
2340 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
2342 * This method will perform the actions required by the struct scic_sds_phy on exiting
2343 * the SCI_BASE_PHY_STATE_INITIAL. This function suspends the SCU hardware
2344 * protocol engine represented by this struct scic_sds_phy object. none
2346 static void scic_sds_phy_ready_state_exit(
2347 struct sci_base_object
*object
)
2349 struct scic_sds_phy
*this_phy
;
2351 this_phy
= (struct scic_sds_phy
*)object
;
2353 scic_sds_phy_suspend(this_phy
);
2358 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
2360 * This method will perform the actions required by the struct scic_sds_phy on
2361 * entering the SCI_BASE_PHY_STATE_RESETTING. - This function sets the state
2362 * handlers for the phy object base state machine resetting state. none
2364 static void scic_sds_phy_resetting_state_enter(
2365 struct sci_base_object
*object
)
2367 struct scic_sds_phy
*this_phy
;
2369 this_phy
= (struct scic_sds_phy
*)object
;
2371 scic_sds_phy_set_base_state_handlers(this_phy
, SCI_BASE_PHY_STATE_RESETTING
);
2374 * The phy is being reset, therefore deactivate it from the port.
2375 * In the resetting state we don't notify the user regarding
2376 * link up and link down notifications. */
2377 scic_sds_port_deactivate_phy(this_phy
->owning_port
, this_phy
, false);
2379 if (this_phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SAS
) {
2380 scu_link_layer_tx_hard_reset(this_phy
);
2383 * The SCU does not need to have a descrete reset state so just go back to
2384 * the starting state. */
2385 sci_base_state_machine_change_state(
2386 &this_phy
->parent
.state_machine
,
2387 SCI_BASE_PHY_STATE_STARTING
2394 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
2396 * This method will perform the actions required by the struct scic_sds_phy on
2397 * entering the SCI_BASE_PHY_STATE_FINAL. - This function sets the state
2398 * handlers for the phy object base state machine final state. none
2400 static void scic_sds_phy_final_state_enter(
2401 struct sci_base_object
*object
)
2403 struct scic_sds_phy
*this_phy
;
2405 this_phy
= (struct scic_sds_phy
*)object
;
2407 scic_sds_phy_set_base_state_handlers(this_phy
, SCI_BASE_PHY_STATE_FINAL
);
2409 /* Nothing to do here */
2412 /* --------------------------------------------------------------------------- */
2414 static const struct sci_base_state scic_sds_phy_state_table
[] = {
2415 [SCI_BASE_PHY_STATE_INITIAL
] = {
2416 .enter_state
= scic_sds_phy_initial_state_enter
,
2418 [SCI_BASE_PHY_STATE_STOPPED
] = {
2419 .enter_state
= scic_sds_phy_stopped_state_enter
,
2421 [SCI_BASE_PHY_STATE_STARTING
] = {
2422 .enter_state
= scic_sds_phy_starting_state_enter
,
2424 [SCI_BASE_PHY_STATE_READY
] = {
2425 .enter_state
= scic_sds_phy_ready_state_enter
,
2426 .exit_state
= scic_sds_phy_ready_state_exit
,
2428 [SCI_BASE_PHY_STATE_RESETTING
] = {
2429 .enter_state
= scic_sds_phy_resetting_state_enter
,
2431 [SCI_BASE_PHY_STATE_FINAL
] = {
2432 .enter_state
= scic_sds_phy_final_state_enter
,
2436 void scic_sds_phy_construct(struct scic_sds_phy
*sci_phy
,
2437 struct scic_sds_port
*owning_port
, u8 phy_index
)
2440 * Call the base constructor first
2442 sci_base_phy_construct(&sci_phy
->parent
, scic_sds_phy_state_table
);
2444 /* Copy the rest of the input data to our locals */
2445 sci_phy
->owning_port
= owning_port
;
2446 sci_phy
->phy_index
= phy_index
;
2447 sci_phy
->bcn_received_while_port_unassigned
= false;
2448 sci_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_UNKNOWN
;
2449 sci_phy
->link_layer_registers
= NULL
;
2450 sci_phy
->max_negotiated_speed
= SCI_SAS_NO_LINK_RATE
;
2451 sci_phy
->sata_timeout_timer
= NULL
;
2453 /* Clear out the identification buffer data */
2454 memset(&sci_phy
->phy_type
, 0, sizeof(sci_phy
->phy_type
));
2456 /* Initialize the the substate machines */
2457 sci_base_state_machine_construct(&sci_phy
->starting_substate_machine
,
2458 &sci_phy
->parent
.parent
,
2459 scic_sds_phy_starting_substates
,
2460 SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL
);