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.
58 #include "sci_base_state.h"
59 #include "sci_base_state_machine.h"
61 #include "scic_sds_controller.h"
62 #include "scic_sds_phy.h"
63 #include "scic_sds_port.h"
64 #include "remote_node_context.h"
65 #include "sci_environment.h"
67 #include "scu_event_codes.h"
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
*sci_phy
,
95 struct scu_transport_layer_registers __iomem
*transport_layer_registers
)
99 sci_phy
->transport_layer_registers
= transport_layer_registers
;
101 writel(SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
,
102 &sci_phy
->transport_layer_registers
->stp_rni
);
105 * Hardware team recommends that we enable the STP prefetch for all
108 tl_control
= readl(&sci_phy
->transport_layer_registers
->control
);
109 tl_control
|= SCU_TLCR_GEN_BIT(STP_WRITE_DATA_PREFETCH
);
110 writel(tl_control
, &sci_phy
->transport_layer_registers
->control
);
116 * This method will initialize the phy link layer registers
118 * @link_layer_registers:
122 static enum sci_status
123 scic_sds_phy_link_layer_initialization(struct scic_sds_phy
*sci_phy
,
124 struct scu_link_layer_registers __iomem
*link_layer_registers
)
126 struct scic_sds_controller
*scic
=
127 sci_phy
->owning_port
->owning_controller
;
128 int phy_idx
= sci_phy
->phy_index
;
129 struct sci_phy_user_params
*phy_user
=
130 &scic
->user_parameters
.sds1
.phys
[phy_idx
];
131 struct sci_phy_oem_params
*phy_oem
=
132 &scic
->oem_parameters
.sds1
.phys
[phy_idx
];
133 u32 phy_configuration
;
134 struct scic_phy_cap phy_cap
;
135 u32 parity_check
= 0;
136 u32 parity_count
= 0;
137 u32 llctl
, link_rate
;
140 sci_phy
->link_layer_registers
= link_layer_registers
;
142 /* Set our IDENTIFY frame data */
143 #define SCI_END_DEVICE 0x01
145 writel(SCU_SAS_TIID_GEN_BIT(SMP_INITIATOR
) |
146 SCU_SAS_TIID_GEN_BIT(SSP_INITIATOR
) |
147 SCU_SAS_TIID_GEN_BIT(STP_INITIATOR
) |
148 SCU_SAS_TIID_GEN_BIT(DA_SATA_HOST
) |
149 SCU_SAS_TIID_GEN_VAL(DEVICE_TYPE
, SCI_END_DEVICE
),
150 &sci_phy
->link_layer_registers
->transmit_identification
);
152 /* Write the device SAS Address */
154 &sci_phy
->link_layer_registers
->sas_device_name_high
);
155 writel(phy_idx
, &sci_phy
->link_layer_registers
->sas_device_name_low
);
157 /* Write the source SAS Address */
158 writel(phy_oem
->sas_address
.high
,
159 &sci_phy
->link_layer_registers
->source_sas_address_high
);
160 writel(phy_oem
->sas_address
.low
,
161 &sci_phy
->link_layer_registers
->source_sas_address_low
);
163 /* Clear and Set the PHY Identifier */
164 writel(0, &sci_phy
->link_layer_registers
->identify_frame_phy_id
);
165 writel(SCU_SAS_TIPID_GEN_VALUE(ID
, phy_idx
),
166 &sci_phy
->link_layer_registers
->identify_frame_phy_id
);
168 /* Change the initial state of the phy configuration register */
170 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
172 /* Hold OOB state machine in reset */
173 phy_configuration
|= SCU_SAS_PCFG_GEN_BIT(OOB_RESET
);
174 writel(phy_configuration
,
175 &sci_phy
->link_layer_registers
->phy_configuration
);
177 /* Configure the SNW capabilities */
180 phy_cap
.gen3_no_ssc
= 1;
181 phy_cap
.gen2_no_ssc
= 1;
182 phy_cap
.gen1_no_ssc
= 1;
183 if (scic
->oem_parameters
.sds1
.controller
.do_enable_ssc
== true) {
184 phy_cap
.gen3_ssc
= 1;
185 phy_cap
.gen2_ssc
= 1;
186 phy_cap
.gen1_ssc
= 1;
190 * The SAS specification indicates that the phy_capabilities that
191 * are transmitted shall have an even parity. Calculate the parity. */
192 parity_check
= phy_cap
.all
;
193 while (parity_check
!= 0) {
194 if (parity_check
& 0x1)
200 * If parity indicates there are an odd number of bits set, then
201 * set the parity bit to 1 in the phy capabilities. */
202 if ((parity_count
% 2) != 0)
205 writel(phy_cap
.all
, &sci_phy
->link_layer_registers
->phy_capabilities
);
207 /* Set the enable spinup period but disable the ability to send
208 * notify enable spinup
210 writel(SCU_ENSPINUP_GEN_VAL(COUNT
,
211 phy_user
->notify_enable_spin_up_insertion_frequency
),
212 &sci_phy
->link_layer_registers
->notify_enable_spinup_control
);
214 /* Write the ALIGN Insertion Ferequency for connected phy and
215 * inpendent of connected state
217 clksm_value
= SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(CONNECTED
,
218 phy_user
->in_connection_align_insertion_frequency
);
220 clksm_value
|= SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(GENERAL
,
221 phy_user
->align_insertion_frequency
);
223 writel(clksm_value
, &sci_phy
->link_layer_registers
->clock_skew_management
);
225 /* @todo Provide a way to write this register correctly */
227 &sci_phy
->link_layer_registers
->afe_lookup_table_control
);
229 llctl
= SCU_SAS_LLCTL_GEN_VAL(NO_OUTBOUND_TASK_TIMEOUT
,
230 (u8
)scic
->user_parameters
.sds1
.no_outbound_task_timeout
);
232 switch(phy_user
->max_speed_generation
) {
233 case SCIC_SDS_PARM_GEN3_SPEED
:
234 link_rate
= SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN3
;
236 case SCIC_SDS_PARM_GEN2_SPEED
:
237 link_rate
= SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN2
;
240 link_rate
= SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN1
;
243 llctl
|= SCU_SAS_LLCTL_GEN_VAL(MAX_LINK_RATE
, link_rate
);
244 writel(llctl
, &sci_phy
->link_layer_registers
->link_layer_control
);
246 if (is_a0() || is_a2()) {
247 /* Program the max ARB time for the PHY to 700us so we inter-operate with
248 * the PMC expander which shuts down PHYs if the expander PHY generates too
249 * many breaks. This time value will guarantee that the initiator PHY will
250 * generate the break.
252 writel(SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME
,
253 &sci_phy
->link_layer_registers
->maximum_arbitration_wait_timer_timeout
);
257 * Set the link layer hang detection to 500ms (0x1F4) from its default
258 * value of 128ms. Max value is 511 ms.
260 writel(0x1F4, &sci_phy
->link_layer_registers
->link_layer_hang_detection_timeout
);
262 /* We can exit the initial state to the stopped state */
263 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
264 SCI_BASE_PHY_STATE_STOPPED
);
270 * This function will handle the sata SIGNATURE FIS timeout condition. It will
271 * restart the starting substate machine since we dont know what has actually
274 static void scic_sds_phy_sata_timeout(void *phy
)
276 struct scic_sds_phy
*sci_phy
= phy
;
278 dev_dbg(sciphy_to_dev(sci_phy
),
279 "%s: SCIC SDS Phy 0x%p did not receive signature fis before "
284 sci_base_state_machine_stop(&sci_phy
->starting_substate_machine
);
286 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
287 SCI_BASE_PHY_STATE_STARTING
);
291 * This method returns the port currently containing this phy. If the phy is
292 * currently contained by the dummy port, then the phy is considered to not
294 * @sci_phy: This parameter specifies the phy for which to retrieve the
297 * This method returns a handle to a port that contains the supplied phy.
298 * NULL This value is returned if the phy is not part of a real
299 * port (i.e. it's contained in the dummy port). !NULL All other
300 * values indicate a handle/pointer to the port containing the phy.
302 struct scic_sds_port
*scic_sds_phy_get_port(
303 struct scic_sds_phy
*sci_phy
)
305 if (scic_sds_port_get_index(sci_phy
->owning_port
) == SCIC_SDS_DUMMY_PORT
)
308 return sci_phy
->owning_port
;
312 * This method will assign a port to the phy object.
313 * @out]: sci_phy This parameter specifies the phy for which to assign a port
318 void scic_sds_phy_set_port(
319 struct scic_sds_phy
*sci_phy
,
320 struct scic_sds_port
*sci_port
)
322 sci_phy
->owning_port
= sci_port
;
324 if (sci_phy
->bcn_received_while_port_unassigned
) {
325 sci_phy
->bcn_received_while_port_unassigned
= false;
326 scic_sds_port_broadcast_change_received(sci_phy
->owning_port
, sci_phy
);
331 * This method will initialize the constructed phy
333 * @link_layer_registers:
337 enum sci_status
scic_sds_phy_initialize(
338 struct scic_sds_phy
*sci_phy
,
339 struct scu_transport_layer_registers __iomem
*transport_layer_registers
,
340 struct scu_link_layer_registers __iomem
*link_layer_registers
)
342 struct scic_sds_controller
*scic
= scic_sds_phy_get_controller(sci_phy
);
343 struct isci_host
*ihost
= scic_to_ihost(scic
);
345 /* Create the SIGNATURE FIS Timeout timer for this phy */
346 sci_phy
->sata_timeout_timer
=
350 scic_sds_phy_sata_timeout
);
352 /* Perfrom the initialization of the TL hardware */
353 scic_sds_phy_transport_layer_initialization(
355 transport_layer_registers
);
357 /* Perofrm the initialization of the PE hardware */
358 scic_sds_phy_link_layer_initialization(sci_phy
, link_layer_registers
);
361 * There is nothing that needs to be done in this state just
362 * transition to the stopped state. */
363 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
364 SCI_BASE_PHY_STATE_STOPPED
);
370 * This method assigns the direct attached device ID for this phy.
372 * @sci_phy The phy for which the direct attached device id is to
374 * @device_id The direct attached device ID to assign to the phy.
375 * This will either be the RNi for the device or an invalid RNi if there
376 * is no current device assigned to the phy.
378 void scic_sds_phy_setup_transport(
379 struct scic_sds_phy
*sci_phy
,
384 writel(device_id
, &sci_phy
->transport_layer_registers
->stp_rni
);
387 * The read should guarantee that the first write gets posted
388 * before the next write
390 tl_control
= readl(&sci_phy
->transport_layer_registers
->control
);
391 tl_control
|= SCU_TLCR_GEN_BIT(CLEAR_TCI_NCQ_MAPPING_TABLE
);
392 writel(tl_control
, &sci_phy
->transport_layer_registers
->control
);
397 * @sci_phy: The phy object to be suspended.
399 * This function will perform the register reads/writes to suspend the SCU
400 * hardware protocol engine. none
402 static void scic_sds_phy_suspend(
403 struct scic_sds_phy
*sci_phy
)
405 u32 scu_sas_pcfg_value
;
408 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
409 scu_sas_pcfg_value
|= SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE
);
410 writel(scu_sas_pcfg_value
,
411 &sci_phy
->link_layer_registers
->phy_configuration
);
413 scic_sds_phy_setup_transport(
415 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
);
418 void scic_sds_phy_resume(struct scic_sds_phy
*sci_phy
)
420 u32 scu_sas_pcfg_value
;
423 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
424 scu_sas_pcfg_value
&= ~SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE
);
425 writel(scu_sas_pcfg_value
,
426 &sci_phy
->link_layer_registers
->phy_configuration
);
429 void scic_sds_phy_get_sas_address(struct scic_sds_phy
*sci_phy
,
430 struct sci_sas_address
*sas_address
)
432 sas_address
->high
= readl(&sci_phy
->link_layer_registers
->source_sas_address_high
);
433 sas_address
->low
= readl(&sci_phy
->link_layer_registers
->source_sas_address_low
);
436 void scic_sds_phy_get_attached_sas_address(struct scic_sds_phy
*sci_phy
,
437 struct sci_sas_address
*sas_address
)
439 struct sas_identify_frame
*iaf
;
440 struct isci_phy
*iphy
= sci_phy_to_iphy(sci_phy
);
442 iaf
= &iphy
->frame_rcvd
.iaf
;
443 memcpy(sas_address
, iaf
->sas_addr
, SAS_ADDR_SIZE
);
446 void scic_sds_phy_get_protocols(struct scic_sds_phy
*sci_phy
,
447 struct scic_phy_proto
*protocols
)
450 (u16
)(readl(&sci_phy
->
451 link_layer_registers
->transmit_identification
) &
456 * This method will attempt to start the phy object. This request is only valid
457 * when the phy is in the stopped state
462 enum sci_status
scic_sds_phy_start(struct scic_sds_phy
*sci_phy
)
464 return sci_phy
->state_handlers
->start_handler(sci_phy
);
468 * This method will attempt to stop the phy object.
471 * enum sci_status SCI_SUCCESS if the phy is going to stop SCI_INVALID_STATE
472 * if the phy is not in a valid state to stop
474 enum sci_status
scic_sds_phy_stop(struct scic_sds_phy
*sci_phy
)
476 return sci_phy
->state_handlers
->stop_handler(sci_phy
);
480 * This method will attempt to reset the phy. This request is only valid when
481 * the phy is in an ready state
486 enum sci_status
scic_sds_phy_reset(
487 struct scic_sds_phy
*sci_phy
)
489 return sci_phy
->state_handlers
->reset_handler(sci_phy
);
493 * This method will process the event code received.
499 enum sci_status
scic_sds_phy_event_handler(
500 struct scic_sds_phy
*sci_phy
,
503 return sci_phy
->state_handlers
->event_handler(sci_phy
, event_code
);
507 * This method will process the frame index received.
513 enum sci_status
scic_sds_phy_frame_handler(
514 struct scic_sds_phy
*sci_phy
,
517 return sci_phy
->state_handlers
->frame_handler(sci_phy
, frame_index
);
521 * This method will give the phy permission to consume power
526 enum sci_status
scic_sds_phy_consume_power_handler(
527 struct scic_sds_phy
*sci_phy
)
529 return sci_phy
->state_handlers
->consume_power_handler(sci_phy
);
533 * *****************************************************************************
534 * * SCIC SDS PHY HELPER FUNCTIONS
535 * ***************************************************************************** */
540 * @sci_phy: The phy object that received SAS PHY DETECTED.
542 * This method continues the link training for the phy as if it were a SAS PHY
543 * instead of a SATA PHY. This is done because the completion queue had a SAS
544 * PHY DETECTED event when the state machine was expecting a SATA PHY event.
547 static void scic_sds_phy_start_sas_link_training(
548 struct scic_sds_phy
*sci_phy
)
553 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
554 phy_control
|= SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD
);
556 &sci_phy
->link_layer_registers
->phy_configuration
);
558 sci_base_state_machine_change_state(
559 &sci_phy
->starting_substate_machine
,
560 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
563 sci_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_SAS
;
568 * @sci_phy: The phy object that received a SATA SPINUP HOLD event
570 * This method continues the link training for the phy as if it were a SATA PHY
571 * instead of a SAS PHY. This is done because the completion queue had a SATA
572 * SPINUP HOLD event when the state machine was expecting a SAS PHY event. none
574 static void scic_sds_phy_start_sata_link_training(
575 struct scic_sds_phy
*sci_phy
)
577 sci_base_state_machine_change_state(
578 &sci_phy
->starting_substate_machine
,
579 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
582 sci_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_SATA
;
586 * scic_sds_phy_complete_link_training - perform processing common to
587 * all protocols upon completion of link training.
588 * @sci_phy: This parameter specifies the phy object for which link training
590 * @max_link_rate: This parameter specifies the maximum link rate to be
591 * associated with this phy.
592 * @next_state: This parameter specifies the next state for the phy's starting
596 static void scic_sds_phy_complete_link_training(
597 struct scic_sds_phy
*sci_phy
,
598 enum sas_linkrate max_link_rate
,
601 sci_phy
->max_negotiated_speed
= max_link_rate
;
603 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
607 static void scic_sds_phy_restart_starting_state(
608 struct scic_sds_phy
*sci_phy
)
610 /* Stop the current substate machine */
611 sci_base_state_machine_stop(&sci_phy
->starting_substate_machine
);
613 /* Re-enter the base state machine starting state */
614 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
615 SCI_BASE_PHY_STATE_STARTING
);
618 /* ****************************************************************************
619 * SCIC SDS PHY general handlers
620 ************************************************************************** */
621 static enum sci_status
scic_sds_phy_starting_substate_general_stop_handler(
622 struct scic_sds_phy
*phy
)
624 sci_base_state_machine_stop(&phy
->starting_substate_machine
);
626 sci_base_state_machine_change_state(&phy
->state_machine
,
627 SCI_BASE_PHY_STATE_STOPPED
);
633 * *****************************************************************************
634 * * SCIC SDS PHY EVENT_HANDLERS
635 * ***************************************************************************** */
639 * @phy: This struct scic_sds_phy object which has received an event.
640 * @event_code: This is the event code which the phy object is to decode.
642 * This method is called when an event notification is received for the phy
643 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. -
644 * decode the event - sas phy detected causes a state transition to the wait
645 * for speed event notification. - any other events log a warning message and
646 * set a failure status enum sci_status SCI_SUCCESS on any valid event notification
647 * SCI_FAILURE on any unexpected event notifation
649 static enum sci_status
scic_sds_phy_starting_substate_await_ossp_event_handler(
650 struct scic_sds_phy
*sci_phy
,
653 u32 result
= SCI_SUCCESS
;
655 switch (scu_get_event_code(event_code
)) {
656 case SCU_EVENT_SAS_PHY_DETECTED
:
657 scic_sds_phy_start_sas_link_training(sci_phy
);
658 sci_phy
->is_in_link_training
= true;
661 case SCU_EVENT_SATA_SPINUP_HOLD
:
662 scic_sds_phy_start_sata_link_training(sci_phy
);
663 sci_phy
->is_in_link_training
= true;
667 dev_dbg(sciphy_to_dev(sci_phy
),
668 "%s: PHY starting substate machine received "
669 "unexpected event_code %x\n",
673 result
= SCI_FAILURE
;
682 * @phy: This struct scic_sds_phy object which has received an event.
683 * @event_code: This is the event code which the phy object is to decode.
685 * This method is called when an event notification is received for the phy
686 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. -
687 * decode the event - sas phy detected returns us back to this state. - speed
688 * event detected causes a state transition to the wait for iaf. - identify
689 * timeout is an un-expected event and the state machine is restarted. - link
690 * failure events restart the starting state machine - any other events log a
691 * warning message and set a failure status enum sci_status SCI_SUCCESS on any valid
692 * event notification SCI_FAILURE on any unexpected event notifation
694 static enum sci_status
scic_sds_phy_starting_substate_await_sas_phy_speed_event_handler(
695 struct scic_sds_phy
*sci_phy
,
698 u32 result
= SCI_SUCCESS
;
700 switch (scu_get_event_code(event_code
)) {
701 case SCU_EVENT_SAS_PHY_DETECTED
:
703 * Why is this being reported again by the controller?
704 * We would re-enter this state so just stay here */
707 case SCU_EVENT_SAS_15
:
708 case SCU_EVENT_SAS_15_SSC
:
709 scic_sds_phy_complete_link_training(
711 SAS_LINK_RATE_1_5_GBPS
,
712 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
);
715 case SCU_EVENT_SAS_30
:
716 case SCU_EVENT_SAS_30_SSC
:
717 scic_sds_phy_complete_link_training(
719 SAS_LINK_RATE_3_0_GBPS
,
720 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
);
723 case SCU_EVENT_SAS_60
:
724 case SCU_EVENT_SAS_60_SSC
:
725 scic_sds_phy_complete_link_training(
727 SAS_LINK_RATE_6_0_GBPS
,
728 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
);
731 case SCU_EVENT_SATA_SPINUP_HOLD
:
733 * We were doing SAS PHY link training and received a SATA PHY event
734 * continue OOB/SN as if this were a SATA PHY */
735 scic_sds_phy_start_sata_link_training(sci_phy
);
738 case SCU_EVENT_LINK_FAILURE
:
739 /* Link failure change state back to the starting state */
740 scic_sds_phy_restart_starting_state(sci_phy
);
744 dev_warn(sciphy_to_dev(sci_phy
),
745 "%s: PHY starting substate machine received "
746 "unexpected event_code %x\n",
750 result
= SCI_FAILURE
;
759 * @phy: This struct scic_sds_phy object which has received an event.
760 * @event_code: This is the event code which the phy object is to decode.
762 * This method is called when an event notification is received for the phy
763 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. -
764 * decode the event - sas phy detected event backs up the state machine to the
765 * await speed notification. - identify timeout is an un-expected event and the
766 * state machine is restarted. - link failure events restart the starting state
767 * machine - any other events log a warning message and set a failure status
768 * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any
769 * unexpected event notifation
771 static enum sci_status
scic_sds_phy_starting_substate_await_iaf_uf_event_handler(
772 struct scic_sds_phy
*sci_phy
,
775 u32 result
= SCI_SUCCESS
;
777 switch (scu_get_event_code(event_code
)) {
778 case SCU_EVENT_SAS_PHY_DETECTED
:
779 /* Backup the state machine */
780 scic_sds_phy_start_sas_link_training(sci_phy
);
783 case SCU_EVENT_SATA_SPINUP_HOLD
:
785 * We were doing SAS PHY link training and received a SATA PHY event
786 * continue OOB/SN as if this were a SATA PHY */
787 scic_sds_phy_start_sata_link_training(sci_phy
);
790 case SCU_EVENT_RECEIVED_IDENTIFY_TIMEOUT
:
791 case SCU_EVENT_LINK_FAILURE
:
792 case SCU_EVENT_HARD_RESET_RECEIVED
:
793 /* Start the oob/sn state machine over again */
794 scic_sds_phy_restart_starting_state(sci_phy
);
798 dev_warn(sciphy_to_dev(sci_phy
),
799 "%s: PHY starting substate machine received "
800 "unexpected event_code %x\n",
804 result
= SCI_FAILURE
;
813 * @phy: This struct scic_sds_phy object which has received an event.
814 * @event_code: This is the event code which the phy object is to decode.
816 * This method is called when an event notification is received for the phy
817 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_POWER. -
818 * decode the event - link failure events restart the starting state machine -
819 * any other events log a warning message and set a failure status enum sci_status
820 * SCI_SUCCESS on a link failure event SCI_FAILURE on any unexpected event
823 static enum sci_status
scic_sds_phy_starting_substate_await_sas_power_event_handler(
824 struct scic_sds_phy
*sci_phy
,
827 u32 result
= SCI_SUCCESS
;
829 switch (scu_get_event_code(event_code
)) {
830 case SCU_EVENT_LINK_FAILURE
:
831 /* Link failure change state back to the starting state */
832 scic_sds_phy_restart_starting_state(sci_phy
);
836 dev_warn(sciphy_to_dev(sci_phy
),
837 "%s: PHY starting substate machine received unexpected "
842 result
= SCI_FAILURE
;
851 * @phy: This struct scic_sds_phy object which has received an event.
852 * @event_code: This is the event code which the phy object is to decode.
854 * This method is called when an event notification is received for the phy
855 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. -
856 * decode the event - link failure events restart the starting state machine -
857 * sata spinup hold events are ignored since they are expected - any other
858 * events log a warning message and set a failure status enum sci_status SCI_SUCCESS
859 * on a link failure event SCI_FAILURE on any unexpected event notifation
861 static enum sci_status
scic_sds_phy_starting_substate_await_sata_power_event_handler(
862 struct scic_sds_phy
*sci_phy
,
865 u32 result
= SCI_SUCCESS
;
867 switch (scu_get_event_code(event_code
)) {
868 case SCU_EVENT_LINK_FAILURE
:
869 /* Link failure change state back to the starting state */
870 scic_sds_phy_restart_starting_state(sci_phy
);
873 case SCU_EVENT_SATA_SPINUP_HOLD
:
874 /* These events are received every 10ms and are expected while in this state */
877 case SCU_EVENT_SAS_PHY_DETECTED
:
879 * There has been a change in the phy type before OOB/SN for the
880 * SATA finished start down the SAS link traning path. */
881 scic_sds_phy_start_sas_link_training(sci_phy
);
885 dev_warn(sciphy_to_dev(sci_phy
),
886 "%s: PHY starting substate machine received "
887 "unexpected event_code %x\n",
891 result
= SCI_FAILURE
;
899 * scic_sds_phy_starting_substate_await_sata_phy_event_handler -
900 * @phy: This struct scic_sds_phy object which has received an event.
901 * @event_code: This is the event code which the phy object is to decode.
903 * This method is called when an event notification is received for the phy
904 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. -
905 * decode the event - link failure events restart the starting state machine -
906 * sata spinup hold events are ignored since they are expected - sata phy
907 * detected event change to the wait speed event - any other events log a
908 * warning message and set a failure status enum sci_status SCI_SUCCESS on a link
909 * failure event SCI_FAILURE on any unexpected event notifation
911 static enum sci_status
scic_sds_phy_starting_substate_await_sata_phy_event_handler(
912 struct scic_sds_phy
*sci_phy
, u32 event_code
)
914 u32 result
= SCI_SUCCESS
;
916 switch (scu_get_event_code(event_code
)) {
917 case SCU_EVENT_LINK_FAILURE
:
918 /* Link failure change state back to the starting state */
919 scic_sds_phy_restart_starting_state(sci_phy
);
922 case SCU_EVENT_SATA_SPINUP_HOLD
:
923 /* These events might be received since we dont know how many may be in
924 * the completion queue while waiting for power
928 case SCU_EVENT_SATA_PHY_DETECTED
:
929 sci_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_SATA
;
931 /* We have received the SATA PHY notification change state */
932 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
933 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
);
936 case SCU_EVENT_SAS_PHY_DETECTED
:
937 /* There has been a change in the phy type before OOB/SN for the
938 * SATA finished start down the SAS link traning path.
940 scic_sds_phy_start_sas_link_training(sci_phy
);
944 dev_warn(sciphy_to_dev(sci_phy
),
945 "%s: PHY starting substate machine received "
946 "unexpected event_code %x\n",
950 result
= SCI_FAILURE
;
959 * @phy: This struct scic_sds_phy object which has received an event.
960 * @event_code: This is the event code which the phy object is to decode.
962 * This method is called when an event notification is received for the phy
963 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN.
964 * - decode the event - sata phy detected returns us back to this state. -
965 * speed event detected causes a state transition to the wait for signature. -
966 * link failure events restart the starting state machine - any other events
967 * log a warning message and set a failure status enum sci_status SCI_SUCCESS on any
968 * valid event notification SCI_FAILURE on any unexpected event notifation
970 static enum sci_status
scic_sds_phy_starting_substate_await_sata_speed_event_handler(
971 struct scic_sds_phy
*sci_phy
,
974 u32 result
= SCI_SUCCESS
;
976 switch (scu_get_event_code(event_code
)) {
977 case SCU_EVENT_SATA_PHY_DETECTED
:
979 * The hardware reports multiple SATA PHY detected events
980 * ignore the extras */
983 case SCU_EVENT_SATA_15
:
984 case SCU_EVENT_SATA_15_SSC
:
985 scic_sds_phy_complete_link_training(
987 SAS_LINK_RATE_1_5_GBPS
,
988 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
);
991 case SCU_EVENT_SATA_30
:
992 case SCU_EVENT_SATA_30_SSC
:
993 scic_sds_phy_complete_link_training(
995 SAS_LINK_RATE_3_0_GBPS
,
996 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
);
999 case SCU_EVENT_SATA_60
:
1000 case SCU_EVENT_SATA_60_SSC
:
1001 scic_sds_phy_complete_link_training(
1003 SAS_LINK_RATE_6_0_GBPS
,
1004 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
);
1007 case SCU_EVENT_LINK_FAILURE
:
1008 /* Link failure change state back to the starting state */
1009 scic_sds_phy_restart_starting_state(sci_phy
);
1012 case SCU_EVENT_SAS_PHY_DETECTED
:
1014 * There has been a change in the phy type before OOB/SN for the
1015 * SATA finished start down the SAS link traning path. */
1016 scic_sds_phy_start_sas_link_training(sci_phy
);
1020 dev_warn(sciphy_to_dev(sci_phy
),
1021 "%s: PHY starting substate machine received "
1022 "unexpected event_code %x\n",
1026 result
= SCI_FAILURE
;
1034 * scic_sds_phy_starting_substate_await_sig_fis_event_handler -
1035 * @phy: This struct scic_sds_phy object which has received an event.
1036 * @event_code: This is the event code which the phy object is to decode.
1038 * This method is called when an event notification is received for the phy
1039 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. -
1040 * decode the event - sas phy detected event backs up the state machine to the
1041 * await speed notification. - identify timeout is an un-expected event and the
1042 * state machine is restarted. - link failure events restart the starting state
1043 * machine - any other events log a warning message and set a failure status
1044 * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any
1045 * unexpected event notifation
1047 static enum sci_status
scic_sds_phy_starting_substate_await_sig_fis_event_handler(
1048 struct scic_sds_phy
*sci_phy
, u32 event_code
)
1050 u32 result
= SCI_SUCCESS
;
1052 switch (scu_get_event_code(event_code
)) {
1053 case SCU_EVENT_SATA_PHY_DETECTED
:
1054 /* Backup the state machine */
1055 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1056 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
);
1059 case SCU_EVENT_LINK_FAILURE
:
1060 /* Link failure change state back to the starting state */
1061 scic_sds_phy_restart_starting_state(sci_phy
);
1065 dev_warn(sciphy_to_dev(sci_phy
),
1066 "%s: PHY starting substate machine received "
1067 "unexpected event_code %x\n",
1071 result
= SCI_FAILURE
;
1080 * *****************************************************************************
1081 * * SCIC SDS PHY FRAME_HANDLERS
1082 * ***************************************************************************** */
1086 * @phy: This is struct scic_sds_phy object which is being requested to decode the
1088 * @frame_index: This is the index of the unsolicited frame which was received
1091 * This method decodes the unsolicited frame when the struct scic_sds_phy is in the
1092 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - Get the UF Header - If the UF
1093 * is an IAF - Copy IAF data to local phy object IAF data buffer. - Change
1094 * starting substate to wait power. - else - log warning message of unexpected
1095 * unsolicted frame - release frame buffer enum sci_status SCI_SUCCESS
1097 static enum sci_status
scic_sds_phy_starting_substate_await_iaf_uf_frame_handler(
1098 struct scic_sds_phy
*sci_phy
, u32 frame_index
)
1100 enum sci_status result
;
1102 struct sas_identify_frame iaf
;
1103 struct isci_phy
*iphy
= sci_phy_to_iphy(sci_phy
);
1105 result
= scic_sds_unsolicited_frame_control_get_header(
1106 &(scic_sds_phy_get_controller(sci_phy
)->uf_control
),
1108 (void **)&frame_words
);
1110 if (result
!= SCI_SUCCESS
)
1113 sci_swab32_cpy(&iaf
, frame_words
, sizeof(iaf
) / sizeof(u32
));
1114 if (iaf
.frame_type
== 0) {
1117 memcpy(&iphy
->frame_rcvd
.iaf
, &iaf
, sizeof(iaf
));
1118 if (iaf
.smp_tport
) {
1119 /* We got the IAF for an expander PHY go to the final
1120 * state since there are no power requirements for
1123 state
= SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
;
1125 /* We got the IAF we can now go to the await spinup
1128 state
= SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
;
1130 sci_base_state_machine_change_state(
1131 &sci_phy
->starting_substate_machine
,
1133 result
= SCI_SUCCESS
;
1135 dev_warn(sciphy_to_dev(sci_phy
),
1136 "%s: PHY starting substate machine received "
1137 "unexpected frame id %x\n",
1141 scic_sds_controller_release_frame(scic_sds_phy_get_controller(sci_phy
),
1149 * @phy: This is struct scic_sds_phy object which is being requested to decode the
1151 * @frame_index: This is the index of the unsolicited frame which was received
1154 * This method decodes the unsolicited frame when the struct scic_sds_phy is in the
1155 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Get the UF Header - If
1156 * the UF is an SIGNATURE FIS - Copy IAF data to local phy object SIGNATURE FIS
1157 * data buffer. - else - log warning message of unexpected unsolicted frame -
1158 * release frame buffer enum sci_status SCI_SUCCESS Must decode the SIGNATURE FIS
1161 static enum sci_status
scic_sds_phy_starting_substate_await_sig_fis_frame_handler(
1162 struct scic_sds_phy
*sci_phy
,
1165 enum sci_status result
;
1166 struct dev_to_host_fis
*frame_header
;
1167 u32
*fis_frame_data
;
1168 struct isci_phy
*iphy
= sci_phy_to_iphy(sci_phy
);
1170 result
= scic_sds_unsolicited_frame_control_get_header(
1171 &(scic_sds_phy_get_controller(sci_phy
)->uf_control
),
1173 (void **)&frame_header
);
1175 if (result
!= SCI_SUCCESS
)
1178 if ((frame_header
->fis_type
== FIS_REGD2H
) &&
1179 !(frame_header
->status
& ATA_BUSY
)) {
1180 scic_sds_unsolicited_frame_control_get_buffer(
1181 &(scic_sds_phy_get_controller(sci_phy
)->uf_control
),
1183 (void **)&fis_frame_data
);
1185 scic_sds_controller_copy_sata_response(&iphy
->frame_rcvd
.fis
,
1189 /* got IAF we can now go to the await spinup semaphore state */
1190 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1191 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
);
1193 result
= SCI_SUCCESS
;
1195 dev_warn(sciphy_to_dev(sci_phy
),
1196 "%s: PHY starting substate machine received "
1197 "unexpected frame id %x\n",
1201 /* Regardless of the result we are done with this frame with it */
1202 scic_sds_controller_release_frame(scic_sds_phy_get_controller(sci_phy
),
1209 * *****************************************************************************
1210 * * SCIC SDS PHY POWER_HANDLERS
1211 * ***************************************************************************** */
1214 * This method is called by the struct scic_sds_controller when the phy object is
1215 * granted power. - The notify enable spinups are turned on for this phy object
1216 * - The phy state machine is transitioned to the
1217 * SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. enum sci_status SCI_SUCCESS
1219 static enum sci_status
scic_sds_phy_starting_substate_await_sas_power_consume_power_handler(
1220 struct scic_sds_phy
*sci_phy
)
1224 enable_spinup
= readl(&sci_phy
->link_layer_registers
->notify_enable_spinup_control
);
1225 enable_spinup
|= SCU_ENSPINUP_GEN_BIT(ENABLE
);
1226 writel(enable_spinup
, &sci_phy
->link_layer_registers
->notify_enable_spinup_control
);
1228 /* Change state to the final state this substate machine has run to completion */
1229 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1230 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
);
1236 * This method is called by the struct scic_sds_controller when the phy object is
1237 * granted power. - The phy state machine is transitioned to the
1238 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. enum sci_status SCI_SUCCESS
1240 static enum sci_status
scic_sds_phy_starting_substate_await_sata_power_consume_power_handler(
1241 struct scic_sds_phy
*sci_phy
)
1243 u32 scu_sas_pcfg_value
;
1245 /* Release the spinup hold state and reset the OOB state machine */
1246 scu_sas_pcfg_value
=
1247 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
1248 scu_sas_pcfg_value
&=
1249 ~(SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD
) | SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE
));
1250 scu_sas_pcfg_value
|= SCU_SAS_PCFG_GEN_BIT(OOB_RESET
);
1251 writel(scu_sas_pcfg_value
,
1252 &sci_phy
->link_layer_registers
->phy_configuration
);
1254 /* Now restart the OOB operation */
1255 scu_sas_pcfg_value
&= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET
);
1256 scu_sas_pcfg_value
|= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE
);
1257 writel(scu_sas_pcfg_value
,
1258 &sci_phy
->link_layer_registers
->phy_configuration
);
1260 /* Change state to the final state this substate machine has run to completion */
1261 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1262 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN
);
1267 static enum sci_status
default_phy_handler(struct scic_sds_phy
*sci_phy
,
1270 dev_dbg(sciphy_to_dev(sci_phy
),
1271 "%s: in wrong state: %d\n", func
,
1272 sci_base_state_machine_get_state(&sci_phy
->state_machine
));
1273 return SCI_FAILURE_INVALID_STATE
;
1276 static enum sci_status
1277 scic_sds_phy_default_start_handler(struct scic_sds_phy
*sci_phy
)
1279 return default_phy_handler(sci_phy
, __func__
);
1282 static enum sci_status
1283 scic_sds_phy_default_stop_handler(struct scic_sds_phy
*sci_phy
)
1285 return default_phy_handler(sci_phy
, __func__
);
1288 static enum sci_status
1289 scic_sds_phy_default_reset_handler(struct scic_sds_phy
*sci_phy
)
1291 return default_phy_handler(sci_phy
, __func__
);
1294 static enum sci_status
1295 scic_sds_phy_default_destroy_handler(struct scic_sds_phy
*sci_phy
)
1297 return default_phy_handler(sci_phy
, __func__
);
1300 static enum sci_status
1301 scic_sds_phy_default_frame_handler(struct scic_sds_phy
*sci_phy
,
1304 struct scic_sds_controller
*scic
= scic_sds_phy_get_controller(sci_phy
);
1306 default_phy_handler(sci_phy
, __func__
);
1307 scic_sds_controller_release_frame(scic
, frame_index
);
1309 return SCI_FAILURE_INVALID_STATE
;
1312 static enum sci_status
1313 scic_sds_phy_default_event_handler(struct scic_sds_phy
*sci_phy
,
1316 return default_phy_handler(sci_phy
, __func__
);
1319 static enum sci_status
1320 scic_sds_phy_default_consume_power_handler(struct scic_sds_phy
*sci_phy
)
1322 return default_phy_handler(sci_phy
, __func__
);
1327 static const struct scic_sds_phy_state_handler scic_sds_phy_starting_substate_handler_table
[] = {
1328 [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL
] = {
1329 .start_handler
= scic_sds_phy_default_start_handler
,
1330 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1331 .reset_handler
= scic_sds_phy_default_reset_handler
,
1332 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1333 .frame_handler
= scic_sds_phy_default_frame_handler
,
1334 .event_handler
= scic_sds_phy_default_event_handler
,
1335 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1337 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
] = {
1338 .start_handler
= scic_sds_phy_default_start_handler
,
1339 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1340 .reset_handler
= scic_sds_phy_default_reset_handler
,
1341 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1342 .frame_handler
= scic_sds_phy_default_frame_handler
,
1343 .event_handler
= scic_sds_phy_starting_substate_await_ossp_event_handler
,
1344 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1346 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
] = {
1347 .start_handler
= scic_sds_phy_default_start_handler
,
1348 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1349 .reset_handler
= scic_sds_phy_default_reset_handler
,
1350 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1351 .frame_handler
= scic_sds_phy_default_frame_handler
,
1352 .event_handler
= scic_sds_phy_starting_substate_await_sas_phy_speed_event_handler
,
1353 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1355 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
] = {
1356 .start_handler
= scic_sds_phy_default_start_handler
,
1357 .stop_handler
= scic_sds_phy_default_stop_handler
,
1358 .reset_handler
= scic_sds_phy_default_reset_handler
,
1359 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1360 .frame_handler
= scic_sds_phy_starting_substate_await_iaf_uf_frame_handler
,
1361 .event_handler
= scic_sds_phy_starting_substate_await_iaf_uf_event_handler
,
1362 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1364 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
] = {
1365 .start_handler
= scic_sds_phy_default_start_handler
,
1366 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1367 .reset_handler
= scic_sds_phy_default_reset_handler
,
1368 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1369 .frame_handler
= scic_sds_phy_default_frame_handler
,
1370 .event_handler
= scic_sds_phy_starting_substate_await_sas_power_event_handler
,
1371 .consume_power_handler
= scic_sds_phy_starting_substate_await_sas_power_consume_power_handler
1373 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
] = {
1374 .start_handler
= scic_sds_phy_default_start_handler
,
1375 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1376 .reset_handler
= scic_sds_phy_default_reset_handler
,
1377 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1378 .frame_handler
= scic_sds_phy_default_frame_handler
,
1379 .event_handler
= scic_sds_phy_starting_substate_await_sata_power_event_handler
,
1380 .consume_power_handler
= scic_sds_phy_starting_substate_await_sata_power_consume_power_handler
1382 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN
] = {
1383 .start_handler
= scic_sds_phy_default_start_handler
,
1384 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1385 .reset_handler
= scic_sds_phy_default_reset_handler
,
1386 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1387 .frame_handler
= scic_sds_phy_default_frame_handler
,
1388 .event_handler
= scic_sds_phy_starting_substate_await_sata_phy_event_handler
,
1389 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1391 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
] = {
1392 .start_handler
= scic_sds_phy_default_start_handler
,
1393 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1394 .reset_handler
= scic_sds_phy_default_reset_handler
,
1395 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1396 .frame_handler
= scic_sds_phy_default_frame_handler
,
1397 .event_handler
= scic_sds_phy_starting_substate_await_sata_speed_event_handler
,
1398 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1400 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
] = {
1401 .start_handler
= scic_sds_phy_default_start_handler
,
1402 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1403 .reset_handler
= scic_sds_phy_default_reset_handler
,
1404 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1405 .frame_handler
= scic_sds_phy_starting_substate_await_sig_fis_frame_handler
,
1406 .event_handler
= scic_sds_phy_starting_substate_await_sig_fis_event_handler
,
1407 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1409 [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
] = {
1410 .start_handler
= scic_sds_phy_default_start_handler
,
1411 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1412 .reset_handler
= scic_sds_phy_default_reset_handler
,
1413 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1414 .frame_handler
= scic_sds_phy_default_frame_handler
,
1415 .event_handler
= scic_sds_phy_default_event_handler
,
1416 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1421 * scic_sds_phy_set_starting_substate_handlers() -
1423 * This macro sets the starting substate handlers by state_id
1425 #define scic_sds_phy_set_starting_substate_handlers(phy, state_id) \
1426 scic_sds_phy_set_state_handlers(\
1428 &scic_sds_phy_starting_substate_handler_table[(state_id)] \
1432 * ****************************************************************************
1433 * * PHY STARTING SUBSTATE METHODS
1434 * **************************************************************************** */
1437 * scic_sds_phy_starting_initial_substate_enter -
1438 * @object: This is the object which is cast to a struct scic_sds_phy object.
1440 * This method will perform the actions required by the struct scic_sds_phy on
1441 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL. - The initial state
1442 * handlers are put in place for the struct scic_sds_phy object. - The state is
1443 * changed to the wait phy type event notification. none
1445 static void scic_sds_phy_starting_initial_substate_enter(void *object
)
1447 struct scic_sds_phy
*sci_phy
= object
;
1449 scic_sds_phy_set_starting_substate_handlers(
1450 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL
);
1452 /* This is just an temporary state go off to the starting state */
1453 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1454 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
);
1459 * @object: This is the object which is cast to a struct scic_sds_phy object.
1461 * This method will perform the actions required by the struct scic_sds_phy on
1462 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_PHY_TYPE_EN. - Set the
1463 * struct scic_sds_phy object state handlers for this state. none
1465 static void scic_sds_phy_starting_await_ossp_en_substate_enter(void *object
)
1467 struct scic_sds_phy
*sci_phy
= object
;
1469 scic_sds_phy_set_starting_substate_handlers(
1470 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
1476 * @object: This is the object which is cast to a struct scic_sds_phy object.
1478 * This method will perform the actions required by the struct scic_sds_phy on
1479 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. - Set the
1480 * struct scic_sds_phy object state handlers for this state. none
1482 static void scic_sds_phy_starting_await_sas_speed_en_substate_enter(
1485 struct scic_sds_phy
*sci_phy
= object
;
1487 scic_sds_phy_set_starting_substate_handlers(
1488 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
1494 * @object: This is the object which is cast to a struct scic_sds_phy object.
1496 * This method will perform the actions required by the struct scic_sds_phy on
1497 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - Set the
1498 * struct scic_sds_phy object state handlers for this state. none
1500 static void scic_sds_phy_starting_await_iaf_uf_substate_enter(void *object
)
1502 struct scic_sds_phy
*sci_phy
= object
;
1504 scic_sds_phy_set_starting_substate_handlers(
1505 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
1511 * @object: This is the object which is cast to a struct scic_sds_phy object.
1513 * This method will perform the actions required by the struct scic_sds_phy on
1514 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Set the
1515 * struct scic_sds_phy object state handlers for this state. - Add this phy object to
1516 * the power control queue none
1518 static void scic_sds_phy_starting_await_sas_power_substate_enter(void *object
)
1520 struct scic_sds_phy
*sci_phy
= object
;
1522 scic_sds_phy_set_starting_substate_handlers(
1523 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
1526 scic_sds_controller_power_control_queue_insert(
1527 scic_sds_phy_get_controller(sci_phy
),
1534 * @object: This is the object which is cast to a struct scic_sds_phy object.
1536 * This method will perform the actions required by the struct scic_sds_phy on exiting
1537 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Remove the
1538 * struct scic_sds_phy object from the power control queue. none
1540 static void scic_sds_phy_starting_await_sas_power_substate_exit(void *object
)
1542 struct scic_sds_phy
*sci_phy
= object
;
1544 scic_sds_controller_power_control_queue_remove(
1545 scic_sds_phy_get_controller(sci_phy
), sci_phy
1551 * @object: This is the object which is cast to a struct scic_sds_phy object.
1553 * This method will perform the actions required by the struct scic_sds_phy on
1554 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Set the
1555 * struct scic_sds_phy object state handlers for this state. - Add this phy object to
1556 * the power control queue none
1558 static void scic_sds_phy_starting_await_sata_power_substate_enter(void *object
)
1560 struct scic_sds_phy
*sci_phy
= object
;
1562 scic_sds_phy_set_starting_substate_handlers(
1563 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
1566 scic_sds_controller_power_control_queue_insert(
1567 scic_sds_phy_get_controller(sci_phy
),
1574 * @object: This is the object which is cast to a struct scic_sds_phy object.
1576 * This method will perform the actions required by the struct scic_sds_phy on exiting
1577 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Remove the
1578 * struct scic_sds_phy object from the power control queue. none
1580 static void scic_sds_phy_starting_await_sata_power_substate_exit(void *object
)
1582 struct scic_sds_phy
*sci_phy
= object
;
1584 scic_sds_controller_power_control_queue_remove(
1585 scic_sds_phy_get_controller(sci_phy
),
1592 * @object: This is the object which is cast to a struct scic_sds_phy object.
1594 * This function will perform the actions required by the struct scic_sds_phy on
1595 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. - Set the
1596 * struct scic_sds_phy object state handlers for this state. none
1598 static void scic_sds_phy_starting_await_sata_phy_substate_enter(void *object
)
1600 struct scic_sds_phy
*sci_phy
= object
;
1602 scic_sds_phy_set_starting_substate_handlers(
1604 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN
);
1606 isci_timer_start(sci_phy
->sata_timeout_timer
,
1607 SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT
);
1612 * @object: This is the object which is cast to a struct scic_sds_phy object.
1614 * This method will perform the actions required by the struct scic_sds_phy
1616 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
1617 * that was started on entry to await sata phy event notification none
1619 static inline void scic_sds_phy_starting_await_sata_phy_substate_exit(
1622 struct scic_sds_phy
*sci_phy
= object
;
1624 isci_timer_stop(sci_phy
->sata_timeout_timer
);
1629 * @object: This is the object which is cast to a struct scic_sds_phy object.
1631 * This method will perform the actions required by the struct scic_sds_phy on
1632 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - Set the
1633 * struct scic_sds_phy object state handlers for this state. none
1635 static void scic_sds_phy_starting_await_sata_speed_substate_enter(void *object
)
1637 struct scic_sds_phy
*sci_phy
= object
;
1639 scic_sds_phy_set_starting_substate_handlers(
1641 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
);
1643 isci_timer_start(sci_phy
->sata_timeout_timer
,
1644 SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT
);
1649 * @object: This is the object which is cast to a struct scic_sds_phy object.
1651 * This function will perform the actions required by the
1652 * struct scic_sds_phy on exiting
1653 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
1654 * that was started on entry to await sata phy event notification none
1656 static inline void scic_sds_phy_starting_await_sata_speed_substate_exit(
1659 struct scic_sds_phy
*sci_phy
= object
;
1661 isci_timer_stop(sci_phy
->sata_timeout_timer
);
1666 * @object: This is the object which is cast to a struct scic_sds_phy object.
1668 * This function will perform the actions required by the struct scic_sds_phy on
1669 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Set the
1670 * struct scic_sds_phy object state handlers for this state.
1671 * - Start the SIGNATURE FIS
1672 * timeout timer none
1674 static void scic_sds_phy_starting_await_sig_fis_uf_substate_enter(void *object
)
1676 bool continue_to_ready_state
;
1677 struct scic_sds_phy
*sci_phy
= object
;
1679 scic_sds_phy_set_starting_substate_handlers(
1681 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
);
1683 continue_to_ready_state
= scic_sds_port_link_detected(
1684 sci_phy
->owning_port
,
1687 if (continue_to_ready_state
) {
1689 * Clear the PE suspend condition so we can actually
1691 * The hardware will not respond to the XRDY until the PE
1692 * suspend condition is cleared.
1694 scic_sds_phy_resume(sci_phy
);
1696 isci_timer_start(sci_phy
->sata_timeout_timer
,
1697 SCIC_SDS_SIGNATURE_FIS_TIMEOUT
);
1699 sci_phy
->is_in_link_training
= false;
1704 * @object: This is the object which is cast to a struct scic_sds_phy object.
1706 * This function will perform the actions required by the
1707 * struct scic_sds_phy on exiting
1708 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Stop the SIGNATURE
1709 * FIS timeout timer. none
1711 static inline void scic_sds_phy_starting_await_sig_fis_uf_substate_exit(
1714 struct scic_sds_phy
*sci_phy
= object
;
1716 isci_timer_stop(sci_phy
->sata_timeout_timer
);
1721 * @object: This is the object which is cast to a struct scic_sds_phy object.
1723 * This method will perform the actions required by the struct scic_sds_phy on
1724 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. - Set the struct scic_sds_phy
1725 * object state handlers for this state. - Change base state machine to the
1728 static void scic_sds_phy_starting_final_substate_enter(void *object
)
1730 struct scic_sds_phy
*sci_phy
= object
;
1732 scic_sds_phy_set_starting_substate_handlers(sci_phy
,
1733 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
);
1735 /* State machine has run to completion so exit out and change
1736 * the base state machine to the ready state
1738 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1739 SCI_BASE_PHY_STATE_READY
);
1742 /* --------------------------------------------------------------------------- */
1744 static const struct sci_base_state scic_sds_phy_starting_substates
[] = {
1745 [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL
] = {
1746 .enter_state
= scic_sds_phy_starting_initial_substate_enter
,
1748 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
] = {
1749 .enter_state
= scic_sds_phy_starting_await_ossp_en_substate_enter
,
1751 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
] = {
1752 .enter_state
= scic_sds_phy_starting_await_sas_speed_en_substate_enter
,
1754 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
] = {
1755 .enter_state
= scic_sds_phy_starting_await_iaf_uf_substate_enter
,
1757 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
] = {
1758 .enter_state
= scic_sds_phy_starting_await_sas_power_substate_enter
,
1759 .exit_state
= scic_sds_phy_starting_await_sas_power_substate_exit
,
1761 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
] = {
1762 .enter_state
= scic_sds_phy_starting_await_sata_power_substate_enter
,
1763 .exit_state
= scic_sds_phy_starting_await_sata_power_substate_exit
1765 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN
] = {
1766 .enter_state
= scic_sds_phy_starting_await_sata_phy_substate_enter
,
1767 .exit_state
= scic_sds_phy_starting_await_sata_phy_substate_exit
1769 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
] = {
1770 .enter_state
= scic_sds_phy_starting_await_sata_speed_substate_enter
,
1771 .exit_state
= scic_sds_phy_starting_await_sata_speed_substate_exit
1773 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
] = {
1774 .enter_state
= scic_sds_phy_starting_await_sig_fis_uf_substate_enter
,
1775 .exit_state
= scic_sds_phy_starting_await_sig_fis_uf_substate_exit
1777 [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
] = {
1778 .enter_state
= scic_sds_phy_starting_final_substate_enter
,
1783 * This method takes the struct scic_sds_phy from a stopped state and
1784 * attempts to start it. - The phy state machine is transitioned to the
1785 * SCI_BASE_PHY_STATE_STARTING. enum sci_status SCI_SUCCESS
1787 static enum sci_status
1788 scic_sds_phy_stopped_state_start_handler(struct scic_sds_phy
*sci_phy
)
1790 struct isci_host
*ihost
;
1791 struct scic_sds_controller
*scic
;
1793 scic
= scic_sds_phy_get_controller(sci_phy
),
1794 ihost
= scic_to_ihost(scic
);
1796 /* Create the SIGNATURE FIS Timeout timer for this phy */
1797 sci_phy
->sata_timeout_timer
= isci_timer_create(ihost
, sci_phy
,
1798 scic_sds_phy_sata_timeout
);
1800 if (sci_phy
->sata_timeout_timer
)
1801 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1802 SCI_BASE_PHY_STATE_STARTING
);
1807 static enum sci_status
1808 scic_sds_phy_stopped_state_destroy_handler(struct scic_sds_phy
*sci_phy
)
1813 static enum sci_status
1814 scic_sds_phy_ready_state_stop_handler(struct scic_sds_phy
*sci_phy
)
1816 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1817 SCI_BASE_PHY_STATE_STOPPED
);
1822 static enum sci_status
1823 scic_sds_phy_ready_state_reset_handler(struct scic_sds_phy
*sci_phy
)
1825 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1826 SCI_BASE_PHY_STATE_RESETTING
);
1832 * scic_sds_phy_ready_state_event_handler -
1833 * @phy: This is the struct scic_sds_phy object which has received the event.
1835 * This method request the struct scic_sds_phy handle the received event. The only
1836 * event that we are interested in while in the ready state is the link failure
1837 * event. - decoded event is a link failure - transition the struct scic_sds_phy back
1838 * to the SCI_BASE_PHY_STATE_STARTING state. - any other event received will
1839 * report a warning message enum sci_status SCI_SUCCESS if the event received is a
1840 * link failure SCI_FAILURE_INVALID_STATE for any other event received.
1842 static enum sci_status
scic_sds_phy_ready_state_event_handler(struct scic_sds_phy
*sci_phy
,
1845 enum sci_status result
= SCI_FAILURE
;
1847 switch (scu_get_event_code(event_code
)) {
1848 case SCU_EVENT_LINK_FAILURE
:
1849 /* Link failure change state back to the starting state */
1850 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1851 SCI_BASE_PHY_STATE_STARTING
);
1852 result
= SCI_SUCCESS
;
1855 case SCU_EVENT_BROADCAST_CHANGE
:
1856 /* Broadcast change received. Notify the port. */
1857 if (scic_sds_phy_get_port(sci_phy
) != NULL
)
1858 scic_sds_port_broadcast_change_received(sci_phy
->owning_port
, sci_phy
);
1860 sci_phy
->bcn_received_while_port_unassigned
= true;
1864 dev_warn(sciphy_to_dev(sci_phy
),
1865 "%sP SCIC PHY 0x%p ready state machine received "
1866 "unexpected event_code %x\n",
1867 __func__
, sci_phy
, event_code
);
1869 result
= SCI_FAILURE_INVALID_STATE
;
1876 static enum sci_status
scic_sds_phy_resetting_state_event_handler(struct scic_sds_phy
*sci_phy
,
1879 enum sci_status result
= SCI_FAILURE
;
1881 switch (scu_get_event_code(event_code
)) {
1882 case SCU_EVENT_HARD_RESET_TRANSMITTED
:
1883 /* Link failure change state back to the starting state */
1884 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1885 SCI_BASE_PHY_STATE_STARTING
);
1886 result
= SCI_SUCCESS
;
1890 dev_warn(sciphy_to_dev(sci_phy
),
1891 "%s: SCIC PHY 0x%p resetting state machine received "
1892 "unexpected event_code %x\n",
1893 __func__
, sci_phy
, event_code
);
1895 result
= SCI_FAILURE_INVALID_STATE
;
1902 /* --------------------------------------------------------------------------- */
1904 static const struct scic_sds_phy_state_handler scic_sds_phy_state_handler_table
[] = {
1905 [SCI_BASE_PHY_STATE_INITIAL
] = {
1906 .start_handler
= scic_sds_phy_default_start_handler
,
1907 .stop_handler
= scic_sds_phy_default_stop_handler
,
1908 .reset_handler
= scic_sds_phy_default_reset_handler
,
1909 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1910 .frame_handler
= scic_sds_phy_default_frame_handler
,
1911 .event_handler
= scic_sds_phy_default_event_handler
,
1912 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1914 [SCI_BASE_PHY_STATE_STOPPED
] = {
1915 .start_handler
= scic_sds_phy_stopped_state_start_handler
,
1916 .stop_handler
= scic_sds_phy_default_stop_handler
,
1917 .reset_handler
= scic_sds_phy_default_reset_handler
,
1918 .destruct_handler
= scic_sds_phy_stopped_state_destroy_handler
,
1919 .frame_handler
= scic_sds_phy_default_frame_handler
,
1920 .event_handler
= scic_sds_phy_default_event_handler
,
1921 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1923 [SCI_BASE_PHY_STATE_STARTING
] = {
1924 .start_handler
= scic_sds_phy_default_start_handler
,
1925 .stop_handler
= scic_sds_phy_default_stop_handler
,
1926 .reset_handler
= scic_sds_phy_default_reset_handler
,
1927 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1928 .frame_handler
= scic_sds_phy_default_frame_handler
,
1929 .event_handler
= scic_sds_phy_default_event_handler
,
1930 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1932 [SCI_BASE_PHY_STATE_READY
] = {
1933 .start_handler
= scic_sds_phy_default_start_handler
,
1934 .stop_handler
= scic_sds_phy_ready_state_stop_handler
,
1935 .reset_handler
= scic_sds_phy_ready_state_reset_handler
,
1936 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1937 .frame_handler
= scic_sds_phy_default_frame_handler
,
1938 .event_handler
= scic_sds_phy_ready_state_event_handler
,
1939 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1941 [SCI_BASE_PHY_STATE_RESETTING
] = {
1942 .start_handler
= scic_sds_phy_default_start_handler
,
1943 .stop_handler
= scic_sds_phy_default_stop_handler
,
1944 .reset_handler
= scic_sds_phy_default_reset_handler
,
1945 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1946 .frame_handler
= scic_sds_phy_default_frame_handler
,
1947 .event_handler
= scic_sds_phy_resetting_state_event_handler
,
1948 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1950 [SCI_BASE_PHY_STATE_FINAL
] = {
1951 .start_handler
= scic_sds_phy_default_start_handler
,
1952 .stop_handler
= scic_sds_phy_default_stop_handler
,
1953 .reset_handler
= scic_sds_phy_default_reset_handler
,
1954 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1955 .frame_handler
= scic_sds_phy_default_frame_handler
,
1956 .event_handler
= scic_sds_phy_default_event_handler
,
1957 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1962 * ****************************************************************************
1963 * * PHY STATE PRIVATE METHODS
1964 * **************************************************************************** */
1968 * @sci_phy: This is the struct scic_sds_phy object to stop.
1970 * This method will stop the struct scic_sds_phy object. This does not reset the
1971 * protocol engine it just suspends it and places it in a state where it will
1972 * not cause the end device to power up. none
1974 static void scu_link_layer_stop_protocol_engine(
1975 struct scic_sds_phy
*sci_phy
)
1977 u32 scu_sas_pcfg_value
;
1978 u32 enable_spinup_value
;
1980 /* Suspend the protocol engine and place it in a sata spinup hold state */
1981 scu_sas_pcfg_value
=
1982 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
1983 scu_sas_pcfg_value
|=
1984 (SCU_SAS_PCFG_GEN_BIT(OOB_RESET
) |
1985 SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE
) |
1986 SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD
));
1987 writel(scu_sas_pcfg_value
,
1988 &sci_phy
->link_layer_registers
->phy_configuration
);
1990 /* Disable the notify enable spinup primitives */
1991 enable_spinup_value
= readl(&sci_phy
->link_layer_registers
->notify_enable_spinup_control
);
1992 enable_spinup_value
&= ~SCU_ENSPINUP_GEN_BIT(ENABLE
);
1993 writel(enable_spinup_value
, &sci_phy
->link_layer_registers
->notify_enable_spinup_control
);
1999 * This method will start the OOB/SN state machine for this struct scic_sds_phy object.
2001 static void scu_link_layer_start_oob(
2002 struct scic_sds_phy
*sci_phy
)
2004 u32 scu_sas_pcfg_value
;
2006 scu_sas_pcfg_value
=
2007 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
2008 scu_sas_pcfg_value
|= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE
);
2009 scu_sas_pcfg_value
&=
2010 ~(SCU_SAS_PCFG_GEN_BIT(OOB_RESET
) |
2011 SCU_SAS_PCFG_GEN_BIT(HARD_RESET
));
2012 writel(scu_sas_pcfg_value
,
2013 &sci_phy
->link_layer_registers
->phy_configuration
);
2019 * This method will transmit a hard reset request on the specified phy. The SCU
2020 * hardware requires that we reset the OOB state machine and set the hard reset
2021 * bit in the phy configuration register. We then must start OOB over with the
2022 * hard reset bit set.
2024 static void scu_link_layer_tx_hard_reset(
2025 struct scic_sds_phy
*sci_phy
)
2027 u32 phy_configuration_value
;
2030 * SAS Phys must wait for the HARD_RESET_TX event notification to transition
2031 * to the starting state. */
2032 phy_configuration_value
=
2033 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
2034 phy_configuration_value
|=
2035 (SCU_SAS_PCFG_GEN_BIT(HARD_RESET
) |
2036 SCU_SAS_PCFG_GEN_BIT(OOB_RESET
));
2037 writel(phy_configuration_value
,
2038 &sci_phy
->link_layer_registers
->phy_configuration
);
2040 /* Now take the OOB state machine out of reset */
2041 phy_configuration_value
|= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE
);
2042 phy_configuration_value
&= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET
);
2043 writel(phy_configuration_value
,
2044 &sci_phy
->link_layer_registers
->phy_configuration
);
2048 * ****************************************************************************
2049 * * PHY BASE STATE METHODS
2050 * **************************************************************************** */
2054 * @object: This is the object which is cast to a struct scic_sds_phy object.
2056 * This method will perform the actions required by the struct scic_sds_phy on
2057 * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
2058 * handlers for the phy object base state machine initial state. none
2060 static void scic_sds_phy_initial_state_enter(void *object
)
2062 struct scic_sds_phy
*sci_phy
= object
;
2064 scic_sds_phy_set_base_state_handlers(sci_phy
, SCI_BASE_PHY_STATE_INITIAL
);
2069 * @object: This is the object which is cast to a struct scic_sds_phy object.
2071 * This function will perform the actions required by the struct scic_sds_phy on
2072 * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
2073 * handlers for the phy object base state machine initial state. - The SCU
2074 * hardware is requested to stop the protocol engine. none
2076 static void scic_sds_phy_stopped_state_enter(void *object
)
2078 struct scic_sds_phy
*sci_phy
= object
;
2079 struct scic_sds_controller
*scic
= scic_sds_phy_get_controller(sci_phy
);
2080 struct isci_host
*ihost
= scic_to_ihost(scic
);
2083 * @todo We need to get to the controller to place this PE in a
2087 scic_sds_phy_set_base_state_handlers(sci_phy
,
2088 SCI_BASE_PHY_STATE_STOPPED
);
2090 if (sci_phy
->sata_timeout_timer
!= NULL
) {
2091 isci_del_timer(ihost
, sci_phy
->sata_timeout_timer
);
2093 sci_phy
->sata_timeout_timer
= NULL
;
2096 scu_link_layer_stop_protocol_engine(sci_phy
);
2098 if (sci_phy
->state_machine
.previous_state_id
!=
2099 SCI_BASE_PHY_STATE_INITIAL
)
2100 scic_sds_controller_link_down(
2101 scic_sds_phy_get_controller(sci_phy
),
2102 scic_sds_phy_get_port(sci_phy
),
2108 * @object: This is the object which is cast to a struct scic_sds_phy object.
2110 * This method will perform the actions required by the struct scic_sds_phy on
2111 * entering the SCI_BASE_PHY_STATE_STARTING. - This function sets the state
2112 * handlers for the phy object base state machine starting state. - The SCU
2113 * hardware is requested to start OOB/SN on this protocl engine. - The phy
2114 * starting substate machine is started. - If the previous state was the ready
2115 * state then the struct scic_sds_controller is informed that the phy has gone link
2118 static void scic_sds_phy_starting_state_enter(void *object
)
2120 struct scic_sds_phy
*sci_phy
= object
;
2122 scic_sds_phy_set_base_state_handlers(sci_phy
, SCI_BASE_PHY_STATE_STARTING
);
2124 scu_link_layer_stop_protocol_engine(sci_phy
);
2125 scu_link_layer_start_oob(sci_phy
);
2127 /* We don't know what kind of phy we are going to be just yet */
2128 sci_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_UNKNOWN
;
2129 sci_phy
->bcn_received_while_port_unassigned
= false;
2131 /* Change over to the starting substate machine to continue */
2132 sci_base_state_machine_start(&sci_phy
->starting_substate_machine
);
2134 if (sci_phy
->state_machine
.previous_state_id
2135 == SCI_BASE_PHY_STATE_READY
) {
2136 scic_sds_controller_link_down(
2137 scic_sds_phy_get_controller(sci_phy
),
2138 scic_sds_phy_get_port(sci_phy
),
2146 * @object: This is the object which is cast to a struct scic_sds_phy object.
2148 * This method will perform the actions required by the struct scic_sds_phy on
2149 * entering the SCI_BASE_PHY_STATE_READY. - This function sets the state
2150 * handlers for the phy object base state machine ready state. - The SCU
2151 * hardware protocol engine is resumed. - The struct scic_sds_controller is informed
2152 * that the phy object has gone link up. none
2154 static void scic_sds_phy_ready_state_enter(void *object
)
2156 struct scic_sds_phy
*sci_phy
= object
;
2158 scic_sds_phy_set_base_state_handlers(sci_phy
, SCI_BASE_PHY_STATE_READY
);
2160 scic_sds_controller_link_up(
2161 scic_sds_phy_get_controller(sci_phy
),
2162 scic_sds_phy_get_port(sci_phy
),
2169 * @object: This is the object which is cast to a struct scic_sds_phy object.
2171 * This method will perform the actions required by the struct scic_sds_phy on exiting
2172 * the SCI_BASE_PHY_STATE_INITIAL. This function suspends the SCU hardware
2173 * protocol engine represented by this struct scic_sds_phy object. none
2175 static void scic_sds_phy_ready_state_exit(void *object
)
2177 struct scic_sds_phy
*sci_phy
= object
;
2179 scic_sds_phy_suspend(sci_phy
);
2184 * @object: This is the object which is cast to a struct scic_sds_phy object.
2186 * This method will perform the actions required by the struct scic_sds_phy on
2187 * entering the SCI_BASE_PHY_STATE_RESETTING. - This function sets the state
2188 * handlers for the phy object base state machine resetting state. none
2190 static void scic_sds_phy_resetting_state_enter(void *object
)
2192 struct scic_sds_phy
*sci_phy
= object
;
2194 scic_sds_phy_set_base_state_handlers(sci_phy
, SCI_BASE_PHY_STATE_RESETTING
);
2197 * The phy is being reset, therefore deactivate it from the port.
2198 * In the resetting state we don't notify the user regarding
2199 * link up and link down notifications. */
2200 scic_sds_port_deactivate_phy(sci_phy
->owning_port
, sci_phy
, false);
2202 if (sci_phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SAS
) {
2203 scu_link_layer_tx_hard_reset(sci_phy
);
2206 * The SCU does not need to have a discrete reset state so
2207 * just go back to the starting state.
2209 sci_base_state_machine_change_state(
2210 &sci_phy
->state_machine
,
2211 SCI_BASE_PHY_STATE_STARTING
);
2217 * @object: This is the object which is cast to a struct scic_sds_phy object.
2219 * This method will perform the actions required by the struct scic_sds_phy on
2220 * entering the SCI_BASE_PHY_STATE_FINAL. - This function sets the state
2221 * handlers for the phy object base state machine final state. none
2223 static void scic_sds_phy_final_state_enter(void *object
)
2225 struct scic_sds_phy
*sci_phy
= object
;
2227 scic_sds_phy_set_base_state_handlers(sci_phy
, SCI_BASE_PHY_STATE_FINAL
);
2229 /* Nothing to do here */
2232 /* --------------------------------------------------------------------------- */
2234 static const struct sci_base_state scic_sds_phy_state_table
[] = {
2235 [SCI_BASE_PHY_STATE_INITIAL
] = {
2236 .enter_state
= scic_sds_phy_initial_state_enter
,
2238 [SCI_BASE_PHY_STATE_STOPPED
] = {
2239 .enter_state
= scic_sds_phy_stopped_state_enter
,
2241 [SCI_BASE_PHY_STATE_STARTING
] = {
2242 .enter_state
= scic_sds_phy_starting_state_enter
,
2244 [SCI_BASE_PHY_STATE_READY
] = {
2245 .enter_state
= scic_sds_phy_ready_state_enter
,
2246 .exit_state
= scic_sds_phy_ready_state_exit
,
2248 [SCI_BASE_PHY_STATE_RESETTING
] = {
2249 .enter_state
= scic_sds_phy_resetting_state_enter
,
2251 [SCI_BASE_PHY_STATE_FINAL
] = {
2252 .enter_state
= scic_sds_phy_final_state_enter
,
2256 void scic_sds_phy_construct(struct scic_sds_phy
*sci_phy
,
2257 struct scic_sds_port
*owning_port
, u8 phy_index
)
2259 sci_base_state_machine_construct(&sci_phy
->state_machine
,
2261 scic_sds_phy_state_table
,
2262 SCI_BASE_PHY_STATE_INITIAL
);
2264 sci_base_state_machine_start(&sci_phy
->state_machine
);
2266 /* Copy the rest of the input data to our locals */
2267 sci_phy
->owning_port
= owning_port
;
2268 sci_phy
->phy_index
= phy_index
;
2269 sci_phy
->bcn_received_while_port_unassigned
= false;
2270 sci_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_UNKNOWN
;
2271 sci_phy
->link_layer_registers
= NULL
;
2272 sci_phy
->max_negotiated_speed
= SAS_LINK_RATE_UNKNOWN
;
2273 sci_phy
->sata_timeout_timer
= NULL
;
2275 /* Initialize the the substate machines */
2276 sci_base_state_machine_construct(&sci_phy
->starting_substate_machine
,
2278 scic_sds_phy_starting_substates
,
2279 SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL
);