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_phy_registers.h"
64 #include "scic_sds_port.h"
65 #include "scic_sds_remote_node_context.h"
66 #include "sci_environment.h"
68 #include "scu_event_codes.h"
70 #define SCIC_SDS_PHY_MIN_TIMER_COUNT (SCI_MAX_PHYS)
71 #define SCIC_SDS_PHY_MAX_TIMER_COUNT (SCI_MAX_PHYS)
73 /* Maximum arbitration wait time in micro-seconds */
74 #define SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME (700)
76 enum sas_linkrate
sci_phy_linkrate(struct scic_sds_phy
*sci_phy
)
78 return sci_phy
->max_negotiated_speed
;
82 * *****************************************************************************
83 * * SCIC SDS PHY Internal Methods
84 * ***************************************************************************** */
87 * This method will initialize the phy transport layer registers
89 * @transport_layer_registers
93 static enum sci_status
scic_sds_phy_transport_layer_initialization(
94 struct scic_sds_phy
*this_phy
,
95 struct scu_transport_layer_registers __iomem
*transport_layer_registers
)
99 this_phy
->transport_layer_registers
= transport_layer_registers
;
101 SCU_STPTLDARNI_WRITE(this_phy
, SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
);
103 /* Hardware team recommends that we enable the STP prefetch for all transports */
104 tl_control
= SCU_TLCR_READ(this_phy
);
105 tl_control
|= SCU_TLCR_GEN_BIT(STP_WRITE_DATA_PREFETCH
);
106 SCU_TLCR_WRITE(this_phy
, tl_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 SCU_SAS_TIID_WRITE(sci_phy
, (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
)));
144 /* Write the device SAS Address */
145 SCU_SAS_TIDNH_WRITE(sci_phy
, 0xFEDCBA98);
146 SCU_SAS_TIDNL_WRITE(sci_phy
, phy_idx
);
148 /* Write the source SAS Address */
149 SCU_SAS_TISSAH_WRITE(sci_phy
, phy_oem
->sas_address
.high
);
150 SCU_SAS_TISSAL_WRITE(sci_phy
, phy_oem
->sas_address
.low
);
152 /* Clear and Set the PHY Identifier */
153 SCU_SAS_TIPID_WRITE(sci_phy
, 0x00000000);
154 SCU_SAS_TIPID_WRITE(sci_phy
, SCU_SAS_TIPID_GEN_VALUE(ID
, phy_idx
));
156 /* Change the initial state of the phy configuration register */
157 phy_configuration
= SCU_SAS_PCFG_READ(sci_phy
);
159 /* Hold OOB state machine in reset */
160 phy_configuration
|= SCU_SAS_PCFG_GEN_BIT(OOB_RESET
);
161 SCU_SAS_PCFG_WRITE(sci_phy
, phy_configuration
);
163 /* Configure the SNW capabilities */
164 phy_capabilities
.u
.all
= 0;
165 phy_capabilities
.u
.bits
.start
= 1;
166 phy_capabilities
.u
.bits
.gen3_without_ssc_supported
= 1;
167 phy_capabilities
.u
.bits
.gen2_without_ssc_supported
= 1;
168 phy_capabilities
.u
.bits
.gen1_without_ssc_supported
= 1;
169 if (scic
->oem_parameters
.sds1
.controller
.do_enable_ssc
== true) {
170 phy_capabilities
.u
.bits
.gen3_with_ssc_supported
= 1;
171 phy_capabilities
.u
.bits
.gen2_with_ssc_supported
= 1;
172 phy_capabilities
.u
.bits
.gen1_with_ssc_supported
= 1;
176 * The SAS specification indicates that the phy_capabilities that
177 * are transmitted shall have an even parity. Calculate the parity. */
178 parity_check
= phy_capabilities
.u
.all
;
179 while (parity_check
!= 0) {
180 if (parity_check
& 0x1)
186 * If parity indicates there are an odd number of bits set, then
187 * set the parity bit to 1 in the phy capabilities. */
188 if ((parity_count
% 2) != 0)
189 phy_capabilities
.u
.bits
.parity
= 1;
191 SCU_SAS_PHYCAP_WRITE(sci_phy
, phy_capabilities
.u
.all
);
193 /* Set the enable spinup period but disable the ability to send
194 * notify enable spinup
196 SCU_SAS_ENSPINUP_WRITE(sci_phy
, SCU_ENSPINUP_GEN_VAL(COUNT
,
197 phy_user
->notify_enable_spin_up_insertion_frequency
));
199 /* Write the ALIGN Insertion Ferequency for connected phy and
200 * inpendent of connected state
202 clksm_value
= SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(CONNECTED
,
203 phy_user
->in_connection_align_insertion_frequency
);
205 clksm_value
|= SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(GENERAL
,
206 phy_user
->align_insertion_frequency
);
208 SCU_SAS_CLKSM_WRITE(sci_phy
, clksm_value
);
210 /* @todo Provide a way to write this register correctly */
211 scu_link_layer_register_write(sci_phy
, afe_lookup_table_control
, 0x02108421);
213 llctl
= SCU_SAS_LLCTL_GEN_VAL(NO_OUTBOUND_TASK_TIMEOUT
,
214 (u8
)scic
->user_parameters
.sds1
.no_outbound_task_timeout
);
216 switch(phy_user
->max_speed_generation
) {
217 case SCIC_SDS_PARM_GEN3_SPEED
:
218 link_rate
= SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN3
;
220 case SCIC_SDS_PARM_GEN2_SPEED
:
221 link_rate
= SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN2
;
224 link_rate
= SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN1
;
227 llctl
|= SCU_SAS_LLCTL_GEN_VAL(MAX_LINK_RATE
, link_rate
);
229 scu_link_layer_register_write(sci_phy
, link_layer_control
, llctl
);
231 if (is_a0() || is_a2()) {
232 /* Program the max ARB time for the PHY to 700us so we inter-operate with
233 * the PMC expander which shuts down PHYs if the expander PHY generates too
234 * many breaks. This time value will guarantee that the initiator PHY will
235 * generate the break.
237 scu_link_layer_register_write(sci_phy
,
238 maximum_arbitration_wait_timer_timeout
,
239 SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME
);
243 * Set the link layer hang detection to 500ms (0x1F4) from its default
244 * value of 128ms. Max value is 511 ms. */
245 scu_link_layer_register_write(sci_phy
, link_layer_hang_detection_timeout
,
248 /* We can exit the initial state to the stopped state */
249 sci_base_state_machine_change_state(&sci_phy
->parent
.state_machine
,
250 SCI_BASE_PHY_STATE_STOPPED
);
256 * This function will handle the sata SIGNATURE FIS timeout condition. It will
257 * restart the starting substate machine since we dont know what has actually
260 static void scic_sds_phy_sata_timeout(void *phy
)
262 struct scic_sds_phy
*sci_phy
= phy
;
264 dev_dbg(sciphy_to_dev(sci_phy
),
265 "%s: SCIC SDS Phy 0x%p did not receive signature fis before "
270 sci_base_state_machine_stop(&sci_phy
->starting_substate_machine
);
272 sci_base_state_machine_change_state(&sci_phy
->parent
.state_machine
,
273 SCI_BASE_PHY_STATE_STARTING
);
277 * This method returns the port currently containing this phy. If the phy is
278 * currently contained by the dummy port, then the phy is considered to not
280 * @this_phy: This parameter specifies the phy for which to retrieve the
283 * This method returns a handle to a port that contains the supplied phy.
284 * NULL This value is returned if the phy is not part of a real
285 * port (i.e. it's contained in the dummy port). !NULL All other
286 * values indicate a handle/pointer to the port containing the phy.
288 struct scic_sds_port
*scic_sds_phy_get_port(
289 struct scic_sds_phy
*this_phy
)
291 if (scic_sds_port_get_index(this_phy
->owning_port
) == SCIC_SDS_DUMMY_PORT
)
294 return this_phy
->owning_port
;
298 * This method will assign a port to the phy object.
299 * @out]: this_phy This parameter specifies the phy for which to assign a port
304 void scic_sds_phy_set_port(
305 struct scic_sds_phy
*this_phy
,
306 struct scic_sds_port
*the_port
)
308 this_phy
->owning_port
= the_port
;
310 if (this_phy
->bcn_received_while_port_unassigned
) {
311 this_phy
->bcn_received_while_port_unassigned
= false;
312 scic_sds_port_broadcast_change_received(this_phy
->owning_port
, this_phy
);
317 * This method will initialize the constructed phy
319 * @link_layer_registers:
323 enum sci_status
scic_sds_phy_initialize(
324 struct scic_sds_phy
*sci_phy
,
325 struct scu_transport_layer_registers __iomem
*transport_layer_registers
,
326 struct scu_link_layer_registers __iomem
*link_layer_registers
)
328 struct scic_sds_controller
*scic
= scic_sds_phy_get_controller(sci_phy
);
329 struct isci_host
*ihost
= sci_object_get_association(scic
);
331 /* Create the SIGNATURE FIS Timeout timer for this phy */
332 sci_phy
->sata_timeout_timer
=
336 scic_sds_phy_sata_timeout
);
338 /* Perfrom the initialization of the TL hardware */
339 scic_sds_phy_transport_layer_initialization(
341 transport_layer_registers
);
343 /* Perofrm the initialization of the PE hardware */
344 scic_sds_phy_link_layer_initialization(sci_phy
, link_layer_registers
);
347 * There is nothing that needs to be done in this state just
348 * transition to the stopped state. */
349 sci_base_state_machine_change_state(&sci_phy
->parent
.state_machine
,
350 SCI_BASE_PHY_STATE_STOPPED
);
356 * This method assigns the direct attached device ID for this phy.
358 * @this_phy The phy for which the direct attached device id is to
360 * @device_id The direct attached device ID to assign to the phy.
361 * This will either be the RNi for the device or an invalid RNi if there
362 * is no current device assigned to the phy.
364 void scic_sds_phy_setup_transport(
365 struct scic_sds_phy
*this_phy
,
370 SCU_STPTLDARNI_WRITE(this_phy
, device_id
);
373 * The read should guarantee that the first write gets posted
374 * before the next write
376 tl_control
= SCU_TLCR_READ(this_phy
);
377 tl_control
|= SCU_TLCR_GEN_BIT(CLEAR_TCI_NCQ_MAPPING_TABLE
);
378 SCU_TLCR_WRITE(this_phy
, tl_control
);
383 * @this_phy: The phy object to be suspended.
385 * This function will perform the register reads/writes to suspend the SCU
386 * hardware protocol engine. none
388 static void scic_sds_phy_suspend(
389 struct scic_sds_phy
*this_phy
)
391 u32 scu_sas_pcfg_value
;
393 scu_sas_pcfg_value
= SCU_SAS_PCFG_READ(this_phy
);
394 scu_sas_pcfg_value
|= SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE
);
395 SCU_SAS_PCFG_WRITE(this_phy
, scu_sas_pcfg_value
);
396 scic_sds_phy_setup_transport(this_phy
, SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
);
401 * @this_phy: The phy object to resume.
403 * This function will perform the register reads/writes required to resume the
404 * SCU hardware protocol engine. none
406 void scic_sds_phy_resume(
407 struct scic_sds_phy
*this_phy
)
409 u32 scu_sas_pcfg_value
;
411 scu_sas_pcfg_value
= SCU_SAS_PCFG_READ(this_phy
);
413 scu_sas_pcfg_value
&= ~SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE
);
415 SCU_SAS_PCFG_WRITE(this_phy
, scu_sas_pcfg_value
);
419 * This method returns the local sas address assigned to this phy.
420 * @this_phy: This parameter specifies the phy for which to retrieve the local
422 * @sas_address: This parameter specifies the location into which to copy the
426 void scic_sds_phy_get_sas_address(
427 struct scic_sds_phy
*this_phy
,
428 struct sci_sas_address
*sas_address
)
430 sas_address
->high
= SCU_SAS_TISSAH_READ(this_phy
);
431 sas_address
->low
= SCU_SAS_TISSAL_READ(this_phy
);
435 * This method returns the remote end-point (i.e. attached) sas address
436 * assigned to this phy.
437 * @this_phy: This parameter specifies the phy for which to retrieve the remote
438 * end-point SAS address.
439 * @sas_address: This parameter specifies the location into which to copy the
440 * remote end-point SAS address.
443 void scic_sds_phy_get_attached_sas_address(
444 struct scic_sds_phy
*this_phy
,
445 struct sci_sas_address
*sas_address
)
448 = this_phy
->phy_type
.sas
.identify_address_frame_buffer
.sas_address
.high
;
450 = this_phy
->phy_type
.sas
.identify_address_frame_buffer
.sas_address
.low
;
454 * This method returns the supported protocols assigned to this phy
459 void scic_sds_phy_get_protocols(
460 struct scic_sds_phy
*this_phy
,
461 struct sci_sas_identify_address_frame_protocols
*protocols
)
463 protocols
->u
.all
= (u16
)(SCU_SAS_TIID_READ(this_phy
) & 0x0000FFFF);
468 * @this_phy: The parameter is the phy object for which the attached phy
469 * protcols are to be returned.
471 * This method returns the supported protocols for the attached phy. If this
472 * is a SAS phy the protocols are returned from the identify address frame. If
473 * this is a SATA phy then protocols are made up and the target phy is an STP
474 * target phy. The caller will get the entire set of bits for the protocol
477 void scic_sds_phy_get_attached_phy_protocols(
478 struct scic_sds_phy
*this_phy
,
479 struct sci_sas_identify_address_frame_protocols
*protocols
)
481 protocols
->u
.all
= 0;
483 if (this_phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SAS
) {
485 this_phy
->phy_type
.sas
.identify_address_frame_buffer
.protocols
.u
.all
;
486 } else if (this_phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SATA
) {
487 protocols
->u
.bits
.stp_target
= 1;
492 * *****************************************************************************
493 * * SCIC SDS PHY Handler Redirects
494 * ***************************************************************************** */
497 * This method will attempt to start the phy object. This request is only valid
498 * when the phy is in the stopped state
503 enum sci_status
scic_sds_phy_start(struct scic_sds_phy
*sci_phy
)
505 return sci_phy
->state_handlers
->parent
.start_handler(&sci_phy
->parent
);
509 * This method will attempt to stop the phy object.
512 * enum sci_status SCI_SUCCESS if the phy is going to stop SCI_INVALID_STATE
513 * if the phy is not in a valid state to stop
515 enum sci_status
scic_sds_phy_stop(struct scic_sds_phy
*sci_phy
)
517 return sci_phy
->state_handlers
->parent
.stop_handler(&sci_phy
->parent
);
521 * This method will attempt to reset the phy. This request is only valid when
522 * the phy is in an ready state
527 enum sci_status
scic_sds_phy_reset(
528 struct scic_sds_phy
*this_phy
)
530 return this_phy
->state_handlers
->parent
.reset_handler(
536 * This method will process the event code received.
542 enum sci_status
scic_sds_phy_event_handler(
543 struct scic_sds_phy
*this_phy
,
546 return this_phy
->state_handlers
->event_handler(this_phy
, event_code
);
550 * This method will process the frame index received.
556 enum sci_status
scic_sds_phy_frame_handler(
557 struct scic_sds_phy
*this_phy
,
560 return this_phy
->state_handlers
->frame_handler(this_phy
, frame_index
);
564 * This method will give the phy permission to consume power
569 enum sci_status
scic_sds_phy_consume_power_handler(
570 struct scic_sds_phy
*this_phy
)
572 return this_phy
->state_handlers
->consume_power_handler(this_phy
);
576 * *****************************************************************************
577 * * SCIC PHY Public Methods
578 * ***************************************************************************** */
581 enum sci_status
scic_sas_phy_get_properties(
582 struct scic_sds_phy
*sci_phy
,
583 struct scic_sas_phy_properties
*properties
)
585 if (sci_phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SAS
) {
587 &properties
->received_iaf
,
588 &sci_phy
->phy_type
.sas
.identify_address_frame_buffer
,
589 sizeof(struct sci_sas_identify_address_frame
)
592 properties
->received_capabilities
.u
.all
593 = SCU_SAS_RECPHYCAP_READ(sci_phy
);
602 enum sci_status
scic_sata_phy_get_properties(
603 struct scic_sds_phy
*sci_phy
,
604 struct scic_sata_phy_properties
*properties
)
606 if (sci_phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SATA
) {
608 &properties
->signature_fis
,
609 &sci_phy
->phy_type
.sata
.signature_fis_buffer
,
610 sizeof(struct sata_fis_reg_d2h
)
613 /* / @todo add support for port selectors. */
614 properties
->is_port_selector_present
= false;
623 * *****************************************************************************
624 * * SCIC SDS PHY HELPER FUNCTIONS
625 * ***************************************************************************** */
630 * @this_phy: The phy object that received SAS PHY DETECTED.
632 * This method continues the link training for the phy as if it were a SAS PHY
633 * instead of a SATA PHY. This is done because the completion queue had a SAS
634 * PHY DETECTED event when the state machine was expecting a SATA PHY event.
637 static void scic_sds_phy_start_sas_link_training(
638 struct scic_sds_phy
*this_phy
)
642 phy_control
= SCU_SAS_PCFG_READ(this_phy
);
643 phy_control
|= SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD
);
644 SCU_SAS_PCFG_WRITE(this_phy
, phy_control
);
646 sci_base_state_machine_change_state(
647 &this_phy
->starting_substate_machine
,
648 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
651 this_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_SAS
;
656 * @this_phy: The phy object that received a SATA SPINUP HOLD event
658 * This method continues the link training for the phy as if it were a SATA PHY
659 * instead of a SAS PHY. This is done because the completion queue had a SATA
660 * SPINUP HOLD event when the state machine was expecting a SAS PHY event. none
662 static void scic_sds_phy_start_sata_link_training(
663 struct scic_sds_phy
*this_phy
)
665 sci_base_state_machine_change_state(
666 &this_phy
->starting_substate_machine
,
667 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
670 this_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_SATA
;
674 * scic_sds_phy_complete_link_training - perform processing common to
675 * all protocols upon completion of link training.
676 * @sci_phy: This parameter specifies the phy object for which link training
678 * @max_link_rate: This parameter specifies the maximum link rate to be
679 * associated with this phy.
680 * @next_state: This parameter specifies the next state for the phy's starting
684 static void scic_sds_phy_complete_link_training(
685 struct scic_sds_phy
*sci_phy
,
686 enum sci_sas_link_rate max_link_rate
,
689 sci_phy
->max_negotiated_speed
= max_link_rate
;
691 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
695 static void scic_sds_phy_restart_starting_state(
696 struct scic_sds_phy
*sci_phy
)
698 /* Stop the current substate machine */
699 sci_base_state_machine_stop(&sci_phy
->starting_substate_machine
);
701 /* Re-enter the base state machine starting state */
702 sci_base_state_machine_change_state(&sci_phy
->parent
.state_machine
,
703 SCI_BASE_PHY_STATE_STARTING
);
706 /* ****************************************************************************
707 * SCIC SDS PHY general handlers
708 ************************************************************************** */
709 static enum sci_status
scic_sds_phy_starting_substate_general_stop_handler(
710 struct sci_base_phy
*phy
)
712 struct scic_sds_phy
*this_phy
;
713 this_phy
= (struct scic_sds_phy
*)phy
;
715 sci_base_state_machine_stop(&this_phy
->starting_substate_machine
);
717 sci_base_state_machine_change_state(&phy
->state_machine
,
718 SCI_BASE_PHY_STATE_STOPPED
);
724 * *****************************************************************************
725 * * SCIC SDS PHY EVENT_HANDLERS
726 * ***************************************************************************** */
730 * @phy: This struct scic_sds_phy object which has received an event.
731 * @event_code: This is the event code which the phy object is to decode.
733 * This method is called when an event notification is received for the phy
734 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. -
735 * decode the event - sas phy detected causes a state transition to the wait
736 * for speed event notification. - any other events log a warning message and
737 * set a failure status enum sci_status SCI_SUCCESS on any valid event notification
738 * SCI_FAILURE on any unexpected event notifation
740 static enum sci_status
scic_sds_phy_starting_substate_await_ossp_event_handler(
741 struct scic_sds_phy
*this_phy
,
744 u32 result
= SCI_SUCCESS
;
746 switch (scu_get_event_code(event_code
)) {
747 case SCU_EVENT_SAS_PHY_DETECTED
:
748 scic_sds_phy_start_sas_link_training(this_phy
);
749 this_phy
->is_in_link_training
= true;
752 case SCU_EVENT_SATA_SPINUP_HOLD
:
753 scic_sds_phy_start_sata_link_training(this_phy
);
754 this_phy
->is_in_link_training
= true;
758 dev_dbg(sciphy_to_dev(this_phy
),
759 "%s: PHY starting substate machine received "
760 "unexpected event_code %x\n",
764 result
= SCI_FAILURE
;
773 * @phy: This struct scic_sds_phy object which has received an event.
774 * @event_code: This is the event code which the phy object is to decode.
776 * This method is called when an event notification is received for the phy
777 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. -
778 * decode the event - sas phy detected returns us back to this state. - speed
779 * event detected causes a state transition to the wait for iaf. - identify
780 * timeout is an un-expected event and the state machine is restarted. - link
781 * failure events restart the starting state machine - any other events log a
782 * warning message and set a failure status enum sci_status SCI_SUCCESS on any valid
783 * event notification SCI_FAILURE on any unexpected event notifation
785 static enum sci_status
scic_sds_phy_starting_substate_await_sas_phy_speed_event_handler(
786 struct scic_sds_phy
*this_phy
,
789 u32 result
= SCI_SUCCESS
;
791 switch (scu_get_event_code(event_code
)) {
792 case SCU_EVENT_SAS_PHY_DETECTED
:
794 * Why is this being reported again by the controller?
795 * We would re-enter this state so just stay here */
798 case SCU_EVENT_SAS_15
:
799 case SCU_EVENT_SAS_15_SSC
:
800 scic_sds_phy_complete_link_training(
801 this_phy
, SCI_SAS_150_GB
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
805 case SCU_EVENT_SAS_30
:
806 case SCU_EVENT_SAS_30_SSC
:
807 scic_sds_phy_complete_link_training(
808 this_phy
, SCI_SAS_300_GB
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
812 case SCU_EVENT_SAS_60
:
813 case SCU_EVENT_SAS_60_SSC
:
814 scic_sds_phy_complete_link_training(
815 this_phy
, SCI_SAS_600_GB
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
819 case SCU_EVENT_SATA_SPINUP_HOLD
:
821 * We were doing SAS PHY link training and received a SATA PHY event
822 * continue OOB/SN as if this were a SATA PHY */
823 scic_sds_phy_start_sata_link_training(this_phy
);
826 case SCU_EVENT_LINK_FAILURE
:
827 /* Link failure change state back to the starting state */
828 scic_sds_phy_restart_starting_state(this_phy
);
832 dev_warn(sciphy_to_dev(this_phy
),
833 "%s: PHY starting substate machine received "
834 "unexpected event_code %x\n",
838 result
= SCI_FAILURE
;
847 * @phy: This struct scic_sds_phy object which has received an event.
848 * @event_code: This is the event code which the phy object is to decode.
850 * This method is called when an event notification is received for the phy
851 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. -
852 * decode the event - sas phy detected event backs up the state machine to the
853 * await speed notification. - identify timeout is an un-expected event and the
854 * state machine is restarted. - link failure events restart the starting state
855 * machine - any other events log a warning message and set a failure status
856 * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any
857 * unexpected event notifation
859 static enum sci_status
scic_sds_phy_starting_substate_await_iaf_uf_event_handler(
860 struct scic_sds_phy
*this_phy
,
863 u32 result
= SCI_SUCCESS
;
865 switch (scu_get_event_code(event_code
)) {
866 case SCU_EVENT_SAS_PHY_DETECTED
:
867 /* Backup the state machine */
868 scic_sds_phy_start_sas_link_training(this_phy
);
871 case SCU_EVENT_SATA_SPINUP_HOLD
:
873 * We were doing SAS PHY link training and received a SATA PHY event
874 * continue OOB/SN as if this were a SATA PHY */
875 scic_sds_phy_start_sata_link_training(this_phy
);
878 case SCU_EVENT_RECEIVED_IDENTIFY_TIMEOUT
:
879 case SCU_EVENT_LINK_FAILURE
:
880 case SCU_EVENT_HARD_RESET_RECEIVED
:
881 /* Start the oob/sn state machine over again */
882 scic_sds_phy_restart_starting_state(this_phy
);
886 dev_warn(sciphy_to_dev(this_phy
),
887 "%s: PHY starting substate machine received "
888 "unexpected event_code %x\n",
892 result
= SCI_FAILURE
;
901 * @phy: This struct scic_sds_phy object which has received an event.
902 * @event_code: This is the event code which the phy object is to decode.
904 * This method is called when an event notification is received for the phy
905 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_POWER. -
906 * decode the event - link failure events restart the starting state machine -
907 * any other events log a warning message and set a failure status enum sci_status
908 * SCI_SUCCESS on a link failure event SCI_FAILURE on any unexpected event
911 static enum sci_status
scic_sds_phy_starting_substate_await_sas_power_event_handler(
912 struct scic_sds_phy
*this_phy
,
915 u32 result
= SCI_SUCCESS
;
917 switch (scu_get_event_code(event_code
)) {
918 case SCU_EVENT_LINK_FAILURE
:
919 /* Link failure change state back to the starting state */
920 scic_sds_phy_restart_starting_state(this_phy
);
924 dev_warn(sciphy_to_dev(this_phy
),
925 "%s: PHY starting substate machine received unexpected "
930 result
= SCI_FAILURE
;
939 * @phy: This struct scic_sds_phy object which has received an event.
940 * @event_code: This is the event code which the phy object is to decode.
942 * This method is called when an event notification is received for the phy
943 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. -
944 * decode the event - link failure events restart the starting state machine -
945 * sata spinup hold events are ignored since they are expected - any other
946 * events log a warning message and set a failure status enum sci_status SCI_SUCCESS
947 * on a link failure event SCI_FAILURE on any unexpected event notifation
949 static enum sci_status
scic_sds_phy_starting_substate_await_sata_power_event_handler(
950 struct scic_sds_phy
*this_phy
,
953 u32 result
= SCI_SUCCESS
;
955 switch (scu_get_event_code(event_code
)) {
956 case SCU_EVENT_LINK_FAILURE
:
957 /* Link failure change state back to the starting state */
958 scic_sds_phy_restart_starting_state(this_phy
);
961 case SCU_EVENT_SATA_SPINUP_HOLD
:
962 /* These events are received every 10ms and are expected while in this state */
965 case SCU_EVENT_SAS_PHY_DETECTED
:
967 * There has been a change in the phy type before OOB/SN for the
968 * SATA finished start down the SAS link traning path. */
969 scic_sds_phy_start_sas_link_training(this_phy
);
973 dev_warn(sciphy_to_dev(this_phy
),
974 "%s: PHY starting substate machine received "
975 "unexpected event_code %x\n",
979 result
= SCI_FAILURE
;
987 * scic_sds_phy_starting_substate_await_sata_phy_event_handler -
988 * @phy: This struct scic_sds_phy object which has received an event.
989 * @event_code: This is the event code which the phy object is to decode.
991 * This method is called when an event notification is received for the phy
992 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. -
993 * decode the event - link failure events restart the starting state machine -
994 * sata spinup hold events are ignored since they are expected - sata phy
995 * detected event change to the wait speed event - any other events log a
996 * warning message and set a failure status enum sci_status SCI_SUCCESS on a link
997 * failure event SCI_FAILURE on any unexpected event notifation
999 static enum sci_status
scic_sds_phy_starting_substate_await_sata_phy_event_handler(
1000 struct scic_sds_phy
*sci_phy
, u32 event_code
)
1002 u32 result
= SCI_SUCCESS
;
1004 switch (scu_get_event_code(event_code
)) {
1005 case SCU_EVENT_LINK_FAILURE
:
1006 /* Link failure change state back to the starting state */
1007 scic_sds_phy_restart_starting_state(sci_phy
);
1010 case SCU_EVENT_SATA_SPINUP_HOLD
:
1011 /* These events might be received since we dont know how many may be in
1012 * the completion queue while waiting for power
1016 case SCU_EVENT_SATA_PHY_DETECTED
:
1017 sci_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_SATA
;
1019 /* We have received the SATA PHY notification change state */
1020 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1021 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
);
1024 case SCU_EVENT_SAS_PHY_DETECTED
:
1025 /* There has been a change in the phy type before OOB/SN for the
1026 * SATA finished start down the SAS link traning path.
1028 scic_sds_phy_start_sas_link_training(sci_phy
);
1032 dev_warn(sciphy_to_dev(sci_phy
),
1033 "%s: PHY starting substate machine received "
1034 "unexpected event_code %x\n",
1038 result
= SCI_FAILURE
;
1047 * @phy: This struct scic_sds_phy object which has received an event.
1048 * @event_code: This is the event code which the phy object is to decode.
1050 * This method is called when an event notification is received for the phy
1051 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN.
1052 * - decode the event - sata phy detected returns us back to this state. -
1053 * speed event detected causes a state transition to the wait for signature. -
1054 * link failure events restart the starting state machine - any other events
1055 * log a warning message and set a failure status enum sci_status SCI_SUCCESS on any
1056 * valid event notification SCI_FAILURE on any unexpected event notifation
1058 static enum sci_status
scic_sds_phy_starting_substate_await_sata_speed_event_handler(
1059 struct scic_sds_phy
*this_phy
,
1062 u32 result
= SCI_SUCCESS
;
1064 switch (scu_get_event_code(event_code
)) {
1065 case SCU_EVENT_SATA_PHY_DETECTED
:
1067 * The hardware reports multiple SATA PHY detected events
1068 * ignore the extras */
1071 case SCU_EVENT_SATA_15
:
1072 case SCU_EVENT_SATA_15_SSC
:
1073 scic_sds_phy_complete_link_training(
1076 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
1080 case SCU_EVENT_SATA_30
:
1081 case SCU_EVENT_SATA_30_SSC
:
1082 scic_sds_phy_complete_link_training(
1085 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
1089 case SCU_EVENT_SATA_60
:
1090 case SCU_EVENT_SATA_60_SSC
:
1091 scic_sds_phy_complete_link_training(
1094 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
1098 case SCU_EVENT_LINK_FAILURE
:
1099 /* Link failure change state back to the starting state */
1100 scic_sds_phy_restart_starting_state(this_phy
);
1103 case SCU_EVENT_SAS_PHY_DETECTED
:
1105 * There has been a change in the phy type before OOB/SN for the
1106 * SATA finished start down the SAS link traning path. */
1107 scic_sds_phy_start_sas_link_training(this_phy
);
1111 dev_warn(sciphy_to_dev(this_phy
),
1112 "%s: PHY starting substate machine received "
1113 "unexpected event_code %x\n",
1117 result
= SCI_FAILURE
;
1125 * scic_sds_phy_starting_substate_await_sig_fis_event_handler -
1126 * @phy: This struct scic_sds_phy object which has received an event.
1127 * @event_code: This is the event code which the phy object is to decode.
1129 * This method is called when an event notification is received for the phy
1130 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. -
1131 * decode the event - sas phy detected event backs up the state machine to the
1132 * await speed notification. - identify timeout is an un-expected event and the
1133 * state machine is restarted. - link failure events restart the starting state
1134 * machine - any other events log a warning message and set a failure status
1135 * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any
1136 * unexpected event notifation
1138 static enum sci_status
scic_sds_phy_starting_substate_await_sig_fis_event_handler(
1139 struct scic_sds_phy
*sci_phy
, u32 event_code
)
1141 u32 result
= SCI_SUCCESS
;
1143 switch (scu_get_event_code(event_code
)) {
1144 case SCU_EVENT_SATA_PHY_DETECTED
:
1145 /* Backup the state machine */
1146 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1147 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
);
1150 case SCU_EVENT_LINK_FAILURE
:
1151 /* Link failure change state back to the starting state */
1152 scic_sds_phy_restart_starting_state(sci_phy
);
1156 dev_warn(sciphy_to_dev(sci_phy
),
1157 "%s: PHY starting substate machine received "
1158 "unexpected event_code %x\n",
1162 result
= SCI_FAILURE
;
1171 * *****************************************************************************
1172 * * SCIC SDS PHY FRAME_HANDLERS
1173 * ***************************************************************************** */
1177 * @phy: This is struct scic_sds_phy object which is being requested to decode the
1179 * @frame_index: This is the index of the unsolicited frame which was received
1182 * This method decodes the unsolicited frame when the struct scic_sds_phy is in the
1183 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - Get the UF Header - If the UF
1184 * is an IAF - Copy IAF data to local phy object IAF data buffer. - Change
1185 * starting substate to wait power. - else - log warning message of unexpected
1186 * unsolicted frame - release frame buffer enum sci_status SCI_SUCCESS
1188 static enum sci_status
scic_sds_phy_starting_substate_await_iaf_uf_frame_handler(
1189 struct scic_sds_phy
*sci_phy
, u32 frame_index
)
1191 enum sci_status result
;
1193 struct sci_sas_identify_address_frame
*identify_frame
;
1195 result
= scic_sds_unsolicited_frame_control_get_header(
1196 &(scic_sds_phy_get_controller(sci_phy
)->uf_control
),
1198 (void **)&frame_words
);
1200 if (result
!= SCI_SUCCESS
) {
1204 frame_words
[0] = SCIC_SWAP_DWORD(frame_words
[0]);
1205 identify_frame
= (struct sci_sas_identify_address_frame
*)frame_words
;
1207 if (identify_frame
->address_frame_type
== 0) {
1210 /* Byte swap the rest of the frame so we can make
1211 * a copy of the buffer
1213 frame_words
[1] = SCIC_SWAP_DWORD(frame_words
[1]);
1214 frame_words
[2] = SCIC_SWAP_DWORD(frame_words
[2]);
1215 frame_words
[3] = SCIC_SWAP_DWORD(frame_words
[3]);
1216 frame_words
[4] = SCIC_SWAP_DWORD(frame_words
[4]);
1217 frame_words
[5] = SCIC_SWAP_DWORD(frame_words
[5]);
1219 memcpy(&sci_phy
->phy_type
.sas
.identify_address_frame_buffer
,
1221 sizeof(struct sci_sas_identify_address_frame
));
1223 if (identify_frame
->protocols
.u
.bits
.smp_target
) {
1224 /* We got the IAF for an expander PHY go to the final state since
1225 * there are no power requirements for expander phys.
1227 state
= SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
;
1229 /* We got the IAF we can now go to the await spinup semaphore state */
1230 state
= SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
;
1232 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1234 result
= SCI_SUCCESS
;
1236 dev_warn(sciphy_to_dev(sci_phy
),
1237 "%s: PHY starting substate machine received "
1238 "unexpected frame id %x\n",
1242 /* Regardless of the result release this frame since we are done with it */
1243 scic_sds_controller_release_frame(scic_sds_phy_get_controller(sci_phy
),
1251 * @phy: This is struct scic_sds_phy object which is being requested to decode the
1253 * @frame_index: This is the index of the unsolicited frame which was received
1256 * This method decodes the unsolicited frame when the struct scic_sds_phy is in the
1257 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Get the UF Header - If
1258 * the UF is an SIGNATURE FIS - Copy IAF data to local phy object SIGNATURE FIS
1259 * data buffer. - else - log warning message of unexpected unsolicted frame -
1260 * release frame buffer enum sci_status SCI_SUCCESS Must decode the SIGNATURE FIS
1263 static enum sci_status
scic_sds_phy_starting_substate_await_sig_fis_frame_handler(
1264 struct scic_sds_phy
*sci_phy
,
1267 enum sci_status result
;
1269 struct sata_fis_header
*fis_frame_header
;
1270 u32
*fis_frame_data
;
1272 result
= scic_sds_unsolicited_frame_control_get_header(
1273 &(scic_sds_phy_get_controller(sci_phy
)->uf_control
),
1275 (void **)&frame_words
);
1277 if (result
!= SCI_SUCCESS
) {
1281 fis_frame_header
= (struct sata_fis_header
*)frame_words
;
1283 if ((fis_frame_header
->fis_type
== SATA_FIS_TYPE_REGD2H
) &&
1284 !(fis_frame_header
->status
& ATA_STATUS_REG_BSY_BIT
)) {
1285 scic_sds_unsolicited_frame_control_get_buffer(
1286 &(scic_sds_phy_get_controller(sci_phy
)->uf_control
),
1288 (void **)&fis_frame_data
);
1290 scic_sds_controller_copy_sata_response(
1291 &sci_phy
->phy_type
.sata
.signature_fis_buffer
,
1295 /* We got the IAF we can now go to the await spinup semaphore state */
1296 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1297 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
);
1299 result
= SCI_SUCCESS
;
1301 dev_warn(sciphy_to_dev(sci_phy
),
1302 "%s: PHY starting substate machine received "
1303 "unexpected frame id %x\n",
1307 /* Regardless of the result release this frame since we are done with it */
1308 scic_sds_controller_release_frame(scic_sds_phy_get_controller(sci_phy
),
1315 * *****************************************************************************
1316 * * SCIC SDS PHY POWER_HANDLERS
1317 * ***************************************************************************** */
1320 * scic_sds_phy_starting_substate_await_sas_power_consume_power_handler -
1321 * @phy: This is the struct sci_base_phy object which is cast into a struct scic_sds_phy
1324 * This method is called by the struct scic_sds_controller when the phy object is
1325 * granted power. - The notify enable spinups are turned on for this phy object
1326 * - The phy state machine is transitioned to the
1327 * SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. enum sci_status SCI_SUCCESS
1329 static enum sci_status
scic_sds_phy_starting_substate_await_sas_power_consume_power_handler(
1330 struct scic_sds_phy
*sci_phy
)
1334 enable_spinup
= SCU_SAS_ENSPINUP_READ(sci_phy
);
1335 enable_spinup
|= SCU_ENSPINUP_GEN_BIT(ENABLE
);
1336 SCU_SAS_ENSPINUP_WRITE(sci_phy
, enable_spinup
);
1338 /* Change state to the final state this substate machine has run to completion */
1339 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1340 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
);
1347 * @phy: This is the struct sci_base_phy object which is cast into a struct scic_sds_phy
1350 * This method is called by the struct scic_sds_controller when the phy object is
1351 * granted power. - The phy state machine is transitioned to the
1352 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. enum sci_status SCI_SUCCESS
1354 static enum sci_status
scic_sds_phy_starting_substate_await_sata_power_consume_power_handler(
1355 struct scic_sds_phy
*sci_phy
)
1357 u32 scu_sas_pcfg_value
;
1359 /* Release the spinup hold state and reset the OOB state machine */
1360 scu_sas_pcfg_value
= SCU_SAS_PCFG_READ(sci_phy
);
1361 scu_sas_pcfg_value
&=
1362 ~(SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD
) | SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE
));
1363 scu_sas_pcfg_value
|= SCU_SAS_PCFG_GEN_BIT(OOB_RESET
);
1364 SCU_SAS_PCFG_WRITE(sci_phy
, scu_sas_pcfg_value
);
1366 /* Now restart the OOB operation */
1367 scu_sas_pcfg_value
&= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET
);
1368 scu_sas_pcfg_value
|= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE
);
1369 SCU_SAS_PCFG_WRITE(sci_phy
, scu_sas_pcfg_value
);
1371 /* Change state to the final state this substate machine has run to completion */
1372 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1373 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN
);
1378 static enum sci_status
default_phy_handler(struct sci_base_phy
*base_phy
, const char *func
)
1380 struct scic_sds_phy
*sci_phy
;
1382 sci_phy
= container_of(base_phy
, typeof(*sci_phy
), parent
);
1383 dev_dbg(sciphy_to_dev(sci_phy
),
1384 "%s: in wrong state: %d\n", func
,
1385 sci_base_state_machine_get_state(&base_phy
->state_machine
));
1386 return SCI_FAILURE_INVALID_STATE
;
1389 static enum sci_status
scic_sds_phy_default_start_handler(struct sci_base_phy
*base_phy
)
1391 return default_phy_handler(base_phy
, __func__
);
1394 static enum sci_status
scic_sds_phy_default_stop_handler(struct sci_base_phy
*base_phy
)
1396 return default_phy_handler(base_phy
, __func__
);
1399 static enum sci_status
scic_sds_phy_default_reset_handler(struct sci_base_phy
*base_phy
)
1401 return default_phy_handler(base_phy
, __func__
);
1404 static enum sci_status
scic_sds_phy_default_destroy_handler(struct sci_base_phy
*base_phy
)
1406 return default_phy_handler(base_phy
, __func__
);
1409 static enum sci_status
scic_sds_phy_default_frame_handler(struct scic_sds_phy
*sci_phy
,
1412 struct scic_sds_controller
*scic
= scic_sds_phy_get_controller(sci_phy
);
1414 default_phy_handler(&sci_phy
->parent
, __func__
);
1415 scic_sds_controller_release_frame(scic
, frame_index
);
1417 return SCI_FAILURE_INVALID_STATE
;
1420 static enum sci_status
scic_sds_phy_default_event_handler(struct scic_sds_phy
*sci_phy
,
1423 return default_phy_handler(&sci_phy
->parent
, __func__
);
1426 static enum sci_status
scic_sds_phy_default_consume_power_handler(struct scic_sds_phy
*sci_phy
)
1428 return default_phy_handler(&sci_phy
->parent
, __func__
);
1433 static const struct scic_sds_phy_state_handler scic_sds_phy_starting_substate_handler_table
[] = {
1434 [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL
] = {
1435 .parent
.start_handler
= scic_sds_phy_default_start_handler
,
1436 .parent
.stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1437 .parent
.reset_handler
= scic_sds_phy_default_reset_handler
,
1438 .parent
.destruct_handler
= scic_sds_phy_default_destroy_handler
,
1439 .frame_handler
= scic_sds_phy_default_frame_handler
,
1440 .event_handler
= scic_sds_phy_default_event_handler
,
1441 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1443 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
] = {
1444 .parent
.start_handler
= scic_sds_phy_default_start_handler
,
1445 .parent
.stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1446 .parent
.reset_handler
= scic_sds_phy_default_reset_handler
,
1447 .parent
.destruct_handler
= scic_sds_phy_default_destroy_handler
,
1448 .frame_handler
= scic_sds_phy_default_frame_handler
,
1449 .event_handler
= scic_sds_phy_starting_substate_await_ossp_event_handler
,
1450 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1452 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
] = {
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_starting_substate_await_sas_phy_speed_event_handler
,
1459 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1461 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
] = {
1462 .parent
.start_handler
= scic_sds_phy_default_start_handler
,
1463 .parent
.stop_handler
= scic_sds_phy_default_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_starting_substate_await_iaf_uf_frame_handler
,
1467 .event_handler
= scic_sds_phy_starting_substate_await_iaf_uf_event_handler
,
1468 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1470 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
] = {
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_power_event_handler
,
1477 .consume_power_handler
= scic_sds_phy_starting_substate_await_sas_power_consume_power_handler
1479 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
] = {
1480 .parent
.start_handler
= scic_sds_phy_default_start_handler
,
1481 .parent
.stop_handler
= scic_sds_phy_starting_substate_general_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_default_frame_handler
,
1485 .event_handler
= scic_sds_phy_starting_substate_await_sata_power_event_handler
,
1486 .consume_power_handler
= scic_sds_phy_starting_substate_await_sata_power_consume_power_handler
1488 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN
] = {
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_sata_phy_event_handler
,
1495 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1497 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
] = {
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_speed_event_handler
,
1504 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1506 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
] = {
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_starting_substate_await_sig_fis_frame_handler
,
1512 .event_handler
= scic_sds_phy_starting_substate_await_sig_fis_event_handler
,
1513 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1515 [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
] = {
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_default_event_handler
,
1522 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1527 * scic_sds_phy_set_starting_substate_handlers() -
1529 * This macro sets the starting substate handlers by state_id
1531 #define scic_sds_phy_set_starting_substate_handlers(phy, state_id) \
1532 scic_sds_phy_set_state_handlers(\
1534 &scic_sds_phy_starting_substate_handler_table[(state_id)] \
1538 * ****************************************************************************
1539 * * PHY STARTING SUBSTATE METHODS
1540 * **************************************************************************** */
1543 * scic_sds_phy_starting_initial_substate_enter -
1544 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
1546 * This method will perform the actions required by the struct scic_sds_phy on
1547 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL. - The initial state
1548 * handlers are put in place for the struct scic_sds_phy object. - The state is
1549 * changed to the wait phy type event notification. none
1551 static void scic_sds_phy_starting_initial_substate_enter(struct sci_base_object
*object
)
1553 struct scic_sds_phy
*sci_phy
;
1555 sci_phy
= (struct scic_sds_phy
*)object
;
1557 scic_sds_phy_set_starting_substate_handlers(
1558 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL
);
1560 /* This is just an temporary state go off to the starting state */
1561 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1562 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
);
1567 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
1569 * This method will perform the actions required by the struct scic_sds_phy on
1570 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_PHY_TYPE_EN. - Set the
1571 * struct scic_sds_phy object state handlers for this state. none
1573 static void scic_sds_phy_starting_await_ossp_en_substate_enter(
1574 struct sci_base_object
*object
)
1576 struct scic_sds_phy
*this_phy
;
1578 this_phy
= (struct scic_sds_phy
*)object
;
1580 scic_sds_phy_set_starting_substate_handlers(
1581 this_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
1587 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
1589 * This method will perform the actions required by the struct scic_sds_phy on
1590 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. - Set the
1591 * struct scic_sds_phy object state handlers for this state. none
1593 static void scic_sds_phy_starting_await_sas_speed_en_substate_enter(
1594 struct sci_base_object
*object
)
1596 struct scic_sds_phy
*this_phy
;
1598 this_phy
= (struct scic_sds_phy
*)object
;
1600 scic_sds_phy_set_starting_substate_handlers(
1601 this_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
1607 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
1609 * This method will perform the actions required by the struct scic_sds_phy on
1610 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - Set the
1611 * struct scic_sds_phy object state handlers for this state. none
1613 static void scic_sds_phy_starting_await_iaf_uf_substate_enter(
1614 struct sci_base_object
*object
)
1616 struct scic_sds_phy
*this_phy
;
1618 this_phy
= (struct scic_sds_phy
*)object
;
1620 scic_sds_phy_set_starting_substate_handlers(
1621 this_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
1627 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
1629 * This method will perform the actions required by the struct scic_sds_phy on
1630 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Set the
1631 * struct scic_sds_phy object state handlers for this state. - Add this phy object to
1632 * the power control queue none
1634 static void scic_sds_phy_starting_await_sas_power_substate_enter(
1635 struct sci_base_object
*object
)
1637 struct scic_sds_phy
*this_phy
;
1639 this_phy
= (struct scic_sds_phy
*)object
;
1641 scic_sds_phy_set_starting_substate_handlers(
1642 this_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
1645 scic_sds_controller_power_control_queue_insert(
1646 scic_sds_phy_get_controller(this_phy
),
1653 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
1655 * This method will perform the actions required by the struct scic_sds_phy on exiting
1656 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Remove the
1657 * struct scic_sds_phy object from the power control queue. none
1659 static void scic_sds_phy_starting_await_sas_power_substate_exit(
1660 struct sci_base_object
*object
)
1662 struct scic_sds_phy
*this_phy
;
1664 this_phy
= (struct scic_sds_phy
*)object
;
1666 scic_sds_controller_power_control_queue_remove(
1667 scic_sds_phy_get_controller(this_phy
), this_phy
1673 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
1675 * This method will perform the actions required by the struct scic_sds_phy on
1676 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Set the
1677 * struct scic_sds_phy object state handlers for this state. - Add this phy object to
1678 * the power control queue none
1680 static void scic_sds_phy_starting_await_sata_power_substate_enter(
1681 struct sci_base_object
*object
)
1683 struct scic_sds_phy
*this_phy
;
1685 this_phy
= (struct scic_sds_phy
*)object
;
1687 scic_sds_phy_set_starting_substate_handlers(
1688 this_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
1691 scic_sds_controller_power_control_queue_insert(
1692 scic_sds_phy_get_controller(this_phy
),
1699 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
1701 * This method will perform the actions required by the struct scic_sds_phy on exiting
1702 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Remove the
1703 * struct scic_sds_phy object from the power control queue. none
1705 static void scic_sds_phy_starting_await_sata_power_substate_exit(
1706 struct sci_base_object
*object
)
1708 struct scic_sds_phy
*this_phy
;
1710 this_phy
= (struct scic_sds_phy
*)object
;
1712 scic_sds_controller_power_control_queue_remove(
1713 scic_sds_phy_get_controller(this_phy
),
1720 * @object: This is the struct sci_base_object which is cast to a
1721 * struct scic_sds_phy object.
1723 * This function will perform the actions required by the struct scic_sds_phy on
1724 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. - Set the
1725 * struct scic_sds_phy object state handlers for this state. none
1727 static void scic_sds_phy_starting_await_sata_phy_substate_enter(
1728 struct sci_base_object
*object
)
1730 struct scic_sds_phy
*sci_phy
= (struct scic_sds_phy
*)object
;
1732 scic_sds_phy_set_starting_substate_handlers(
1734 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN
);
1736 isci_timer_start(sci_phy
->sata_timeout_timer
,
1737 SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT
);
1742 * @object: This is the struct sci_base_object which is cast to a
1743 * struct scic_sds_phy object.
1745 * This method will perform the actions required by the struct scic_sds_phy
1747 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
1748 * that was started on entry to await sata phy event notification none
1750 static inline void scic_sds_phy_starting_await_sata_phy_substate_exit(
1751 struct sci_base_object
*object
)
1753 struct scic_sds_phy
*sci_phy
= (struct scic_sds_phy
*)object
;
1755 isci_timer_stop(sci_phy
->sata_timeout_timer
);
1760 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
1762 * This method will perform the actions required by the struct scic_sds_phy on
1763 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - Set the
1764 * struct scic_sds_phy object state handlers for this state. none
1766 static void scic_sds_phy_starting_await_sata_speed_substate_enter(
1767 struct sci_base_object
*object
)
1769 struct scic_sds_phy
*sci_phy
= (struct scic_sds_phy
*)object
;
1771 scic_sds_phy_set_starting_substate_handlers(
1773 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
);
1775 isci_timer_start(sci_phy
->sata_timeout_timer
,
1776 SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT
);
1781 * @object: This is the struct sci_base_object which is cast to a
1782 * struct scic_sds_phy object.
1784 * This function will perform the actions required by the
1785 * struct scic_sds_phy on exiting
1786 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
1787 * that was started on entry to await sata phy event notification none
1789 static inline void scic_sds_phy_starting_await_sata_speed_substate_exit(
1790 struct sci_base_object
*object
)
1792 struct scic_sds_phy
*sci_phy
= (struct scic_sds_phy
*)object
;
1794 isci_timer_stop(sci_phy
->sata_timeout_timer
);
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 struct scic_sds_phy on
1803 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Set the
1804 * struct scic_sds_phy object state handlers for this state.
1805 * - Start the SIGNATURE FIS
1806 * timeout timer none
1808 static void scic_sds_phy_starting_await_sig_fis_uf_substate_enter(
1809 struct sci_base_object
*object
)
1811 bool continue_to_ready_state
;
1812 struct scic_sds_phy
*sci_phy
= (struct scic_sds_phy
*)object
;
1814 scic_sds_phy_set_starting_substate_handlers(
1816 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
);
1818 continue_to_ready_state
= scic_sds_port_link_detected(
1819 sci_phy
->owning_port
,
1822 if (continue_to_ready_state
) {
1824 * Clear the PE suspend condition so we can actually
1826 * The hardware will not respond to the XRDY until the PE
1827 * suspend condition is cleared.
1829 scic_sds_phy_resume(sci_phy
);
1831 isci_timer_start(sci_phy
->sata_timeout_timer
,
1832 SCIC_SDS_SIGNATURE_FIS_TIMEOUT
);
1834 sci_phy
->is_in_link_training
= false;
1839 * @object: This is the struct sci_base_object which is cast to a
1840 * struct scic_sds_phy object.
1842 * This function will perform the actions required by the
1843 * struct scic_sds_phy on exiting
1844 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Stop the SIGNATURE
1845 * FIS timeout timer. none
1847 static inline void scic_sds_phy_starting_await_sig_fis_uf_substate_exit(
1848 struct sci_base_object
*object
)
1850 struct scic_sds_phy
*sci_phy
;
1852 sci_phy
= (struct scic_sds_phy
*)object
;
1854 isci_timer_stop(sci_phy
->sata_timeout_timer
);
1859 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
1861 * This method will perform the actions required by the struct scic_sds_phy on
1862 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. - Set the struct scic_sds_phy
1863 * object state handlers for this state. - Change base state machine to the
1866 static void scic_sds_phy_starting_final_substate_enter(struct sci_base_object
*object
)
1868 struct scic_sds_phy
*sci_phy
;
1870 sci_phy
= container_of(object
, typeof(*sci_phy
), parent
.parent
);
1872 scic_sds_phy_set_starting_substate_handlers(sci_phy
,
1873 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
);
1875 /* State machine has run to completion so exit out and change
1876 * the base state machine to the ready state
1878 sci_base_state_machine_change_state(&sci_phy
->parent
.state_machine
,
1879 SCI_BASE_PHY_STATE_READY
);
1882 /* --------------------------------------------------------------------------- */
1884 static const struct sci_base_state scic_sds_phy_starting_substates
[] = {
1885 [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL
] = {
1886 .enter_state
= scic_sds_phy_starting_initial_substate_enter
,
1888 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
] = {
1889 .enter_state
= scic_sds_phy_starting_await_ossp_en_substate_enter
,
1891 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
] = {
1892 .enter_state
= scic_sds_phy_starting_await_sas_speed_en_substate_enter
,
1894 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
] = {
1895 .enter_state
= scic_sds_phy_starting_await_iaf_uf_substate_enter
,
1897 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
] = {
1898 .enter_state
= scic_sds_phy_starting_await_sas_power_substate_enter
,
1899 .exit_state
= scic_sds_phy_starting_await_sas_power_substate_exit
,
1901 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
] = {
1902 .enter_state
= scic_sds_phy_starting_await_sata_power_substate_enter
,
1903 .exit_state
= scic_sds_phy_starting_await_sata_power_substate_exit
1905 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN
] = {
1906 .enter_state
= scic_sds_phy_starting_await_sata_phy_substate_enter
,
1907 .exit_state
= scic_sds_phy_starting_await_sata_phy_substate_exit
1909 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
] = {
1910 .enter_state
= scic_sds_phy_starting_await_sata_speed_substate_enter
,
1911 .exit_state
= scic_sds_phy_starting_await_sata_speed_substate_exit
1913 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
] = {
1914 .enter_state
= scic_sds_phy_starting_await_sig_fis_uf_substate_enter
,
1915 .exit_state
= scic_sds_phy_starting_await_sig_fis_uf_substate_exit
1917 [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
] = {
1918 .enter_state
= scic_sds_phy_starting_final_substate_enter
,
1924 * @phy: This is the struct sci_base_phy object which is cast into a
1925 * struct scic_sds_phy object.
1927 * This method takes the struct scic_sds_phy from a stopped state and
1928 * attempts to start it. - The phy state machine is transitioned to the
1929 * SCI_BASE_PHY_STATE_STARTING. enum sci_status SCI_SUCCESS
1931 static enum sci_status
scic_sds_phy_stopped_state_start_handler(struct sci_base_phy
*base_phy
)
1933 struct isci_host
*ihost
;
1934 struct scic_sds_phy
*sci_phy
;
1935 struct scic_sds_controller
*scic
;
1937 sci_phy
= container_of(base_phy
, typeof(*sci_phy
), parent
);
1938 scic
= scic_sds_phy_get_controller(sci_phy
),
1939 ihost
= sci_object_get_association(scic
);
1941 /* Create the SIGNATURE FIS Timeout timer for this phy */
1942 sci_phy
->sata_timeout_timer
= isci_timer_create(ihost
, sci_phy
,
1943 scic_sds_phy_sata_timeout
);
1945 if (sci_phy
->sata_timeout_timer
)
1946 sci_base_state_machine_change_state(&sci_phy
->parent
.state_machine
,
1947 SCI_BASE_PHY_STATE_STARTING
);
1952 static enum sci_status
scic_sds_phy_stopped_state_destroy_handler(struct sci_base_phy
*base_phy
)
1957 static enum sci_status
scic_sds_phy_ready_state_stop_handler(struct sci_base_phy
*base_phy
)
1959 sci_base_state_machine_change_state(&base_phy
->state_machine
,
1960 SCI_BASE_PHY_STATE_STOPPED
);
1965 static enum sci_status
scic_sds_phy_ready_state_reset_handler(struct sci_base_phy
*base_phy
)
1967 sci_base_state_machine_change_state(&base_phy
->state_machine
,
1968 SCI_BASE_PHY_STATE_RESETTING
);
1974 * scic_sds_phy_ready_state_event_handler -
1975 * @phy: This is the struct scic_sds_phy object which has received the event.
1977 * This method request the struct scic_sds_phy handle the received event. The only
1978 * event that we are interested in while in the ready state is the link failure
1979 * event. - decoded event is a link failure - transition the struct scic_sds_phy back
1980 * to the SCI_BASE_PHY_STATE_STARTING state. - any other event received will
1981 * report a warning message enum sci_status SCI_SUCCESS if the event received is a
1982 * link failure SCI_FAILURE_INVALID_STATE for any other event received.
1984 static enum sci_status
scic_sds_phy_ready_state_event_handler(struct scic_sds_phy
*sci_phy
,
1987 enum sci_status result
= SCI_FAILURE
;
1989 switch (scu_get_event_code(event_code
)) {
1990 case SCU_EVENT_LINK_FAILURE
:
1991 /* Link failure change state back to the starting state */
1992 sci_base_state_machine_change_state(&sci_phy
->parent
.state_machine
,
1993 SCI_BASE_PHY_STATE_STARTING
);
1994 result
= SCI_SUCCESS
;
1997 case SCU_EVENT_BROADCAST_CHANGE
:
1998 /* Broadcast change received. Notify the port. */
1999 if (scic_sds_phy_get_port(sci_phy
) != NULL
)
2000 scic_sds_port_broadcast_change_received(sci_phy
->owning_port
, sci_phy
);
2002 sci_phy
->bcn_received_while_port_unassigned
= true;
2006 dev_warn(sciphy_to_dev(sci_phy
),
2007 "%sP SCIC PHY 0x%p ready state machine received "
2008 "unexpected event_code %x\n",
2009 __func__
, sci_phy
, event_code
);
2011 result
= SCI_FAILURE_INVALID_STATE
;
2018 static enum sci_status
scic_sds_phy_resetting_state_event_handler(struct scic_sds_phy
*sci_phy
,
2021 enum sci_status result
= SCI_FAILURE
;
2023 switch (scu_get_event_code(event_code
)) {
2024 case SCU_EVENT_HARD_RESET_TRANSMITTED
:
2025 /* Link failure change state back to the starting state */
2026 sci_base_state_machine_change_state(&sci_phy
->parent
.state_machine
,
2027 SCI_BASE_PHY_STATE_STARTING
);
2028 result
= SCI_SUCCESS
;
2032 dev_warn(sciphy_to_dev(sci_phy
),
2033 "%s: SCIC PHY 0x%p resetting state machine received "
2034 "unexpected event_code %x\n",
2035 __func__
, sci_phy
, event_code
);
2037 result
= SCI_FAILURE_INVALID_STATE
;
2044 /* --------------------------------------------------------------------------- */
2046 static const struct scic_sds_phy_state_handler scic_sds_phy_state_handler_table
[] = {
2047 [SCI_BASE_PHY_STATE_INITIAL
] = {
2048 .parent
.start_handler
= scic_sds_phy_default_start_handler
,
2049 .parent
.stop_handler
= scic_sds_phy_default_stop_handler
,
2050 .parent
.reset_handler
= scic_sds_phy_default_reset_handler
,
2051 .parent
.destruct_handler
= scic_sds_phy_default_destroy_handler
,
2052 .frame_handler
= scic_sds_phy_default_frame_handler
,
2053 .event_handler
= scic_sds_phy_default_event_handler
,
2054 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
2056 [SCI_BASE_PHY_STATE_STOPPED
] = {
2057 .parent
.start_handler
= scic_sds_phy_stopped_state_start_handler
,
2058 .parent
.stop_handler
= scic_sds_phy_default_stop_handler
,
2059 .parent
.reset_handler
= scic_sds_phy_default_reset_handler
,
2060 .parent
.destruct_handler
= scic_sds_phy_stopped_state_destroy_handler
,
2061 .frame_handler
= scic_sds_phy_default_frame_handler
,
2062 .event_handler
= scic_sds_phy_default_event_handler
,
2063 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
2065 [SCI_BASE_PHY_STATE_STARTING
] = {
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_READY
] = {
2075 .parent
.start_handler
= scic_sds_phy_default_start_handler
,
2076 .parent
.stop_handler
= scic_sds_phy_ready_state_stop_handler
,
2077 .parent
.reset_handler
= scic_sds_phy_ready_state_reset_handler
,
2078 .parent
.destruct_handler
= scic_sds_phy_default_destroy_handler
,
2079 .frame_handler
= scic_sds_phy_default_frame_handler
,
2080 .event_handler
= scic_sds_phy_ready_state_event_handler
,
2081 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
2083 [SCI_BASE_PHY_STATE_RESETTING
] = {
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_resetting_state_event_handler
,
2090 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
2092 [SCI_BASE_PHY_STATE_FINAL
] = {
2093 .parent
.start_handler
= scic_sds_phy_default_start_handler
,
2094 .parent
.stop_handler
= scic_sds_phy_default_stop_handler
,
2095 .parent
.reset_handler
= scic_sds_phy_default_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_default_event_handler
,
2099 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
2104 * ****************************************************************************
2105 * * PHY STATE PRIVATE METHODS
2106 * **************************************************************************** */
2110 * @this_phy: This is the struct scic_sds_phy object to stop.
2112 * This method will stop the struct scic_sds_phy object. This does not reset the
2113 * protocol engine it just suspends it and places it in a state where it will
2114 * not cause the end device to power up. none
2116 static void scu_link_layer_stop_protocol_engine(
2117 struct scic_sds_phy
*this_phy
)
2119 u32 scu_sas_pcfg_value
;
2120 u32 enable_spinup_value
;
2122 /* Suspend the protocol engine and place it in a sata spinup hold state */
2123 scu_sas_pcfg_value
= SCU_SAS_PCFG_READ(this_phy
);
2124 scu_sas_pcfg_value
|= (
2125 SCU_SAS_PCFG_GEN_BIT(OOB_RESET
)
2126 | SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE
)
2127 | SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD
)
2129 SCU_SAS_PCFG_WRITE(this_phy
, scu_sas_pcfg_value
);
2131 /* Disable the notify enable spinup primitives */
2132 enable_spinup_value
= SCU_SAS_ENSPINUP_READ(this_phy
);
2133 enable_spinup_value
&= ~SCU_ENSPINUP_GEN_BIT(ENABLE
);
2134 SCU_SAS_ENSPINUP_WRITE(this_phy
, enable_spinup_value
);
2140 * This method will start the OOB/SN state machine for this struct scic_sds_phy object.
2142 static void scu_link_layer_start_oob(
2143 struct scic_sds_phy
*this_phy
)
2145 u32 scu_sas_pcfg_value
;
2147 scu_sas_pcfg_value
= SCU_SAS_PCFG_READ(this_phy
);
2148 scu_sas_pcfg_value
|= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE
);
2149 scu_sas_pcfg_value
&=
2150 ~(SCU_SAS_PCFG_GEN_BIT(OOB_RESET
) | SCU_SAS_PCFG_GEN_BIT(HARD_RESET
));
2152 SCU_SAS_PCFG_WRITE(this_phy
, scu_sas_pcfg_value
);
2158 * This method will transmit a hard reset request on the specified phy. The SCU
2159 * hardware requires that we reset the OOB state machine and set the hard reset
2160 * bit in the phy configuration register. We then must start OOB over with the
2161 * hard reset bit set.
2163 static void scu_link_layer_tx_hard_reset(
2164 struct scic_sds_phy
*this_phy
)
2166 u32 phy_configuration_value
;
2169 * SAS Phys must wait for the HARD_RESET_TX event notification to transition
2170 * to the starting state. */
2171 phy_configuration_value
= SCU_SAS_PCFG_READ(this_phy
);
2172 phy_configuration_value
|=
2173 (SCU_SAS_PCFG_GEN_BIT(HARD_RESET
) | SCU_SAS_PCFG_GEN_BIT(OOB_RESET
));
2174 SCU_SAS_PCFG_WRITE(this_phy
, phy_configuration_value
);
2176 /* Now take the OOB state machine out of reset */
2177 phy_configuration_value
|= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE
);
2178 phy_configuration_value
&= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET
);
2179 SCU_SAS_PCFG_WRITE(this_phy
, phy_configuration_value
);
2183 * ****************************************************************************
2184 * * PHY BASE STATE METHODS
2185 * **************************************************************************** */
2189 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
2191 * This method will perform the actions required by the struct scic_sds_phy on
2192 * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
2193 * handlers for the phy object base state machine initial state. none
2195 static void scic_sds_phy_initial_state_enter(
2196 struct sci_base_object
*object
)
2198 struct scic_sds_phy
*this_phy
;
2200 this_phy
= (struct scic_sds_phy
*)object
;
2202 scic_sds_phy_set_base_state_handlers(this_phy
, SCI_BASE_PHY_STATE_INITIAL
);
2207 * @object: This is the struct sci_base_object which is cast to a
2208 * struct scic_sds_phy object.
2210 * This function will perform the actions required by the struct scic_sds_phy on
2211 * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
2212 * handlers for the phy object base state machine initial state. - The SCU
2213 * hardware is requested to stop the protocol engine. none
2215 static void scic_sds_phy_stopped_state_enter(struct sci_base_object
*object
)
2217 struct scic_sds_phy
*sci_phy
= (struct scic_sds_phy
*)object
;
2218 struct scic_sds_controller
*scic
= scic_sds_phy_get_controller(sci_phy
);
2219 struct isci_host
*ihost
= sci_object_get_association(scic
);
2221 sci_phy
= (struct scic_sds_phy
*)object
;
2224 * @todo We need to get to the controller to place this PE in a
2228 scic_sds_phy_set_base_state_handlers(sci_phy
,
2229 SCI_BASE_PHY_STATE_STOPPED
);
2231 if (sci_phy
->sata_timeout_timer
!= NULL
) {
2232 isci_del_timer(ihost
, sci_phy
->sata_timeout_timer
);
2234 sci_phy
->sata_timeout_timer
= NULL
;
2237 scu_link_layer_stop_protocol_engine(sci_phy
);
2239 if (sci_phy
->parent
.state_machine
.previous_state_id
!=
2240 SCI_BASE_PHY_STATE_INITIAL
)
2241 scic_sds_controller_link_down(
2242 scic_sds_phy_get_controller(sci_phy
),
2243 scic_sds_phy_get_port(sci_phy
),
2249 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
2251 * This method will perform the actions required by the struct scic_sds_phy on
2252 * entering the SCI_BASE_PHY_STATE_STARTING. - This function sets the state
2253 * handlers for the phy object base state machine starting state. - The SCU
2254 * hardware is requested to start OOB/SN on this protocl engine. - The phy
2255 * starting substate machine is started. - If the previous state was the ready
2256 * state then the struct scic_sds_controller is informed that the phy has gone link
2259 static void scic_sds_phy_starting_state_enter(
2260 struct sci_base_object
*object
)
2262 struct scic_sds_phy
*this_phy
;
2264 this_phy
= (struct scic_sds_phy
*)object
;
2266 scic_sds_phy_set_base_state_handlers(this_phy
, SCI_BASE_PHY_STATE_STARTING
);
2268 scu_link_layer_stop_protocol_engine(this_phy
);
2269 scu_link_layer_start_oob(this_phy
);
2271 /* We don't know what kind of phy we are going to be just yet */
2272 this_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_UNKNOWN
;
2273 this_phy
->bcn_received_while_port_unassigned
= false;
2275 /* Change over to the starting substate machine to continue */
2276 sci_base_state_machine_start(&this_phy
->starting_substate_machine
);
2278 if (this_phy
->parent
.state_machine
.previous_state_id
2279 == SCI_BASE_PHY_STATE_READY
) {
2280 scic_sds_controller_link_down(
2281 scic_sds_phy_get_controller(this_phy
),
2282 scic_sds_phy_get_port(this_phy
),
2290 * @object: This is the struct sci_base_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
2293 * entering the SCI_BASE_PHY_STATE_READY. - This function sets the state
2294 * handlers for the phy object base state machine ready state. - The SCU
2295 * hardware protocol engine is resumed. - The struct scic_sds_controller is informed
2296 * that the phy object has gone link up. none
2298 static void scic_sds_phy_ready_state_enter(
2299 struct sci_base_object
*object
)
2301 struct scic_sds_phy
*this_phy
;
2303 this_phy
= (struct scic_sds_phy
*)object
;
2305 scic_sds_phy_set_base_state_handlers(this_phy
, SCI_BASE_PHY_STATE_READY
);
2307 scic_sds_controller_link_up(
2308 scic_sds_phy_get_controller(this_phy
),
2309 scic_sds_phy_get_port(this_phy
),
2316 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
2318 * This method will perform the actions required by the struct scic_sds_phy on exiting
2319 * the SCI_BASE_PHY_STATE_INITIAL. This function suspends the SCU hardware
2320 * protocol engine represented by this struct scic_sds_phy object. none
2322 static void scic_sds_phy_ready_state_exit(
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_suspend(this_phy
);
2334 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
2336 * This method will perform the actions required by the struct scic_sds_phy on
2337 * entering the SCI_BASE_PHY_STATE_RESETTING. - This function sets the state
2338 * handlers for the phy object base state machine resetting state. none
2340 static void scic_sds_phy_resetting_state_enter(
2341 struct sci_base_object
*object
)
2343 struct scic_sds_phy
*this_phy
;
2345 this_phy
= (struct scic_sds_phy
*)object
;
2347 scic_sds_phy_set_base_state_handlers(this_phy
, SCI_BASE_PHY_STATE_RESETTING
);
2350 * The phy is being reset, therefore deactivate it from the port.
2351 * In the resetting state we don't notify the user regarding
2352 * link up and link down notifications. */
2353 scic_sds_port_deactivate_phy(this_phy
->owning_port
, this_phy
, false);
2355 if (this_phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SAS
) {
2356 scu_link_layer_tx_hard_reset(this_phy
);
2359 * The SCU does not need to have a descrete reset state so just go back to
2360 * the starting state. */
2361 sci_base_state_machine_change_state(
2362 &this_phy
->parent
.state_machine
,
2363 SCI_BASE_PHY_STATE_STARTING
2370 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
2372 * This method will perform the actions required by the struct scic_sds_phy on
2373 * entering the SCI_BASE_PHY_STATE_FINAL. - This function sets the state
2374 * handlers for the phy object base state machine final state. none
2376 static void scic_sds_phy_final_state_enter(
2377 struct sci_base_object
*object
)
2379 struct scic_sds_phy
*this_phy
;
2381 this_phy
= (struct scic_sds_phy
*)object
;
2383 scic_sds_phy_set_base_state_handlers(this_phy
, SCI_BASE_PHY_STATE_FINAL
);
2385 /* Nothing to do here */
2388 /* --------------------------------------------------------------------------- */
2390 static const struct sci_base_state scic_sds_phy_state_table
[] = {
2391 [SCI_BASE_PHY_STATE_INITIAL
] = {
2392 .enter_state
= scic_sds_phy_initial_state_enter
,
2394 [SCI_BASE_PHY_STATE_STOPPED
] = {
2395 .enter_state
= scic_sds_phy_stopped_state_enter
,
2397 [SCI_BASE_PHY_STATE_STARTING
] = {
2398 .enter_state
= scic_sds_phy_starting_state_enter
,
2400 [SCI_BASE_PHY_STATE_READY
] = {
2401 .enter_state
= scic_sds_phy_ready_state_enter
,
2402 .exit_state
= scic_sds_phy_ready_state_exit
,
2404 [SCI_BASE_PHY_STATE_RESETTING
] = {
2405 .enter_state
= scic_sds_phy_resetting_state_enter
,
2407 [SCI_BASE_PHY_STATE_FINAL
] = {
2408 .enter_state
= scic_sds_phy_final_state_enter
,
2412 void scic_sds_phy_construct(struct scic_sds_phy
*sci_phy
,
2413 struct scic_sds_port
*owning_port
, u8 phy_index
)
2416 * Call the base constructor first
2418 sci_base_phy_construct(&sci_phy
->parent
, scic_sds_phy_state_table
);
2420 /* Copy the rest of the input data to our locals */
2421 sci_phy
->owning_port
= owning_port
;
2422 sci_phy
->phy_index
= phy_index
;
2423 sci_phy
->bcn_received_while_port_unassigned
= false;
2424 sci_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_UNKNOWN
;
2425 sci_phy
->link_layer_registers
= NULL
;
2426 sci_phy
->max_negotiated_speed
= SCI_SAS_NO_LINK_RATE
;
2427 sci_phy
->sata_timeout_timer
= NULL
;
2429 /* Clear out the identification buffer data */
2430 memset(&sci_phy
->phy_type
, 0, sizeof(sci_phy
->phy_type
));
2432 /* Initialize the the substate machines */
2433 sci_base_state_machine_construct(&sci_phy
->starting_substate_machine
,
2434 &sci_phy
->parent
.parent
,
2435 scic_sds_phy_starting_substates
,
2436 SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL
);