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"
69 #define SCIC_SDS_PHY_MIN_TIMER_COUNT (SCI_MAX_PHYS)
70 #define SCIC_SDS_PHY_MAX_TIMER_COUNT (SCI_MAX_PHYS)
72 /* Maximum arbitration wait time in micro-seconds */
73 #define SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME (700)
75 enum sas_linkrate
sci_phy_linkrate(struct scic_sds_phy
*sci_phy
)
77 return sci_phy
->max_negotiated_speed
;
81 * *****************************************************************************
82 * * SCIC SDS PHY Internal Methods
83 * ***************************************************************************** */
86 * This method will initialize the phy transport layer registers
88 * @transport_layer_registers
92 static enum sci_status
scic_sds_phy_transport_layer_initialization(
93 struct scic_sds_phy
*sci_phy
,
94 struct scu_transport_layer_registers __iomem
*transport_layer_registers
)
98 sci_phy
->transport_layer_registers
= transport_layer_registers
;
100 writel(SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
,
101 &sci_phy
->transport_layer_registers
->stp_rni
);
104 * Hardware team recommends that we enable the STP prefetch for all
107 tl_control
= readl(&sci_phy
->transport_layer_registers
->control
);
108 tl_control
|= SCU_TLCR_GEN_BIT(STP_WRITE_DATA_PREFETCH
);
109 writel(tl_control
, &sci_phy
->transport_layer_registers
->control
);
115 * This method will initialize the phy link layer registers
117 * @link_layer_registers:
121 static enum sci_status
122 scic_sds_phy_link_layer_initialization(struct scic_sds_phy
*sci_phy
,
123 struct scu_link_layer_registers __iomem
*link_layer_registers
)
125 struct scic_sds_controller
*scic
=
126 sci_phy
->owning_port
->owning_controller
;
127 int phy_idx
= sci_phy
->phy_index
;
128 struct sci_phy_user_params
*phy_user
=
129 &scic
->user_parameters
.sds1
.phys
[phy_idx
];
130 struct sci_phy_oem_params
*phy_oem
=
131 &scic
->oem_parameters
.sds1
.phys
[phy_idx
];
132 u32 phy_configuration
;
133 struct scic_phy_cap phy_cap
;
134 u32 parity_check
= 0;
135 u32 parity_count
= 0;
136 u32 llctl
, link_rate
;
139 sci_phy
->link_layer_registers
= link_layer_registers
;
141 /* Set our IDENTIFY frame data */
142 #define SCI_END_DEVICE 0x01
144 writel(SCU_SAS_TIID_GEN_BIT(SMP_INITIATOR
) |
145 SCU_SAS_TIID_GEN_BIT(SSP_INITIATOR
) |
146 SCU_SAS_TIID_GEN_BIT(STP_INITIATOR
) |
147 SCU_SAS_TIID_GEN_BIT(DA_SATA_HOST
) |
148 SCU_SAS_TIID_GEN_VAL(DEVICE_TYPE
, SCI_END_DEVICE
),
149 &sci_phy
->link_layer_registers
->transmit_identification
);
151 /* Write the device SAS Address */
153 &sci_phy
->link_layer_registers
->sas_device_name_high
);
154 writel(phy_idx
, &sci_phy
->link_layer_registers
->sas_device_name_low
);
156 /* Write the source SAS Address */
157 writel(phy_oem
->sas_address
.high
,
158 &sci_phy
->link_layer_registers
->source_sas_address_high
);
159 writel(phy_oem
->sas_address
.low
,
160 &sci_phy
->link_layer_registers
->source_sas_address_low
);
162 /* Clear and Set the PHY Identifier */
163 writel(0, &sci_phy
->link_layer_registers
->identify_frame_phy_id
);
164 writel(SCU_SAS_TIPID_GEN_VALUE(ID
, phy_idx
),
165 &sci_phy
->link_layer_registers
->identify_frame_phy_id
);
167 /* Change the initial state of the phy configuration register */
169 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
171 /* Hold OOB state machine in reset */
172 phy_configuration
|= SCU_SAS_PCFG_GEN_BIT(OOB_RESET
);
173 writel(phy_configuration
,
174 &sci_phy
->link_layer_registers
->phy_configuration
);
176 /* Configure the SNW capabilities */
179 phy_cap
.gen3_no_ssc
= 1;
180 phy_cap
.gen2_no_ssc
= 1;
181 phy_cap
.gen1_no_ssc
= 1;
182 if (scic
->oem_parameters
.sds1
.controller
.do_enable_ssc
== true) {
183 phy_cap
.gen3_ssc
= 1;
184 phy_cap
.gen2_ssc
= 1;
185 phy_cap
.gen1_ssc
= 1;
189 * The SAS specification indicates that the phy_capabilities that
190 * are transmitted shall have an even parity. Calculate the parity. */
191 parity_check
= phy_cap
.all
;
192 while (parity_check
!= 0) {
193 if (parity_check
& 0x1)
199 * If parity indicates there are an odd number of bits set, then
200 * set the parity bit to 1 in the phy capabilities. */
201 if ((parity_count
% 2) != 0)
204 writel(phy_cap
.all
, &sci_phy
->link_layer_registers
->phy_capabilities
);
206 /* Set the enable spinup period but disable the ability to send
207 * notify enable spinup
209 writel(SCU_ENSPINUP_GEN_VAL(COUNT
,
210 phy_user
->notify_enable_spin_up_insertion_frequency
),
211 &sci_phy
->link_layer_registers
->notify_enable_spinup_control
);
213 /* Write the ALIGN Insertion Ferequency for connected phy and
214 * inpendent of connected state
216 clksm_value
= SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(CONNECTED
,
217 phy_user
->in_connection_align_insertion_frequency
);
219 clksm_value
|= SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(GENERAL
,
220 phy_user
->align_insertion_frequency
);
222 writel(clksm_value
, &sci_phy
->link_layer_registers
->clock_skew_management
);
224 /* @todo Provide a way to write this register correctly */
226 &sci_phy
->link_layer_registers
->afe_lookup_table_control
);
228 llctl
= SCU_SAS_LLCTL_GEN_VAL(NO_OUTBOUND_TASK_TIMEOUT
,
229 (u8
)scic
->user_parameters
.sds1
.no_outbound_task_timeout
);
231 switch(phy_user
->max_speed_generation
) {
232 case SCIC_SDS_PARM_GEN3_SPEED
:
233 link_rate
= SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN3
;
235 case SCIC_SDS_PARM_GEN2_SPEED
:
236 link_rate
= SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN2
;
239 link_rate
= SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN1
;
242 llctl
|= SCU_SAS_LLCTL_GEN_VAL(MAX_LINK_RATE
, link_rate
);
243 writel(llctl
, &sci_phy
->link_layer_registers
->link_layer_control
);
245 if (is_a0() || is_a2()) {
246 /* Program the max ARB time for the PHY to 700us so we inter-operate with
247 * the PMC expander which shuts down PHYs if the expander PHY generates too
248 * many breaks. This time value will guarantee that the initiator PHY will
249 * generate the break.
251 writel(SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME
,
252 &sci_phy
->link_layer_registers
->maximum_arbitration_wait_timer_timeout
);
256 * Set the link layer hang detection to 500ms (0x1F4) from its default
257 * value of 128ms. Max value is 511 ms.
259 writel(0x1F4, &sci_phy
->link_layer_registers
->link_layer_hang_detection_timeout
);
261 /* We can exit the initial state to the stopped state */
262 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
263 SCI_BASE_PHY_STATE_STOPPED
);
269 * This function will handle the sata SIGNATURE FIS timeout condition. It will
270 * restart the starting substate machine since we dont know what has actually
273 static void scic_sds_phy_sata_timeout(void *phy
)
275 struct scic_sds_phy
*sci_phy
= phy
;
277 dev_dbg(sciphy_to_dev(sci_phy
),
278 "%s: SCIC SDS Phy 0x%p did not receive signature fis before "
283 sci_base_state_machine_stop(&sci_phy
->starting_substate_machine
);
285 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
286 SCI_BASE_PHY_STATE_STARTING
);
290 * This method returns the port currently containing this phy. If the phy is
291 * currently contained by the dummy port, then the phy is considered to not
293 * @sci_phy: This parameter specifies the phy for which to retrieve the
296 * This method returns a handle to a port that contains the supplied phy.
297 * NULL This value is returned if the phy is not part of a real
298 * port (i.e. it's contained in the dummy port). !NULL All other
299 * values indicate a handle/pointer to the port containing the phy.
301 struct scic_sds_port
*scic_sds_phy_get_port(
302 struct scic_sds_phy
*sci_phy
)
304 if (scic_sds_port_get_index(sci_phy
->owning_port
) == SCIC_SDS_DUMMY_PORT
)
307 return sci_phy
->owning_port
;
311 * This method will assign a port to the phy object.
312 * @out]: sci_phy This parameter specifies the phy for which to assign a port
317 void scic_sds_phy_set_port(
318 struct scic_sds_phy
*sci_phy
,
319 struct scic_sds_port
*sci_port
)
321 sci_phy
->owning_port
= sci_port
;
323 if (sci_phy
->bcn_received_while_port_unassigned
) {
324 sci_phy
->bcn_received_while_port_unassigned
= false;
325 scic_sds_port_broadcast_change_received(sci_phy
->owning_port
, sci_phy
);
330 * This method will initialize the constructed phy
332 * @link_layer_registers:
336 enum sci_status
scic_sds_phy_initialize(
337 struct scic_sds_phy
*sci_phy
,
338 struct scu_transport_layer_registers __iomem
*transport_layer_registers
,
339 struct scu_link_layer_registers __iomem
*link_layer_registers
)
341 struct scic_sds_controller
*scic
= scic_sds_phy_get_controller(sci_phy
);
342 struct isci_host
*ihost
= scic
->ihost
;
344 /* Create the SIGNATURE FIS Timeout timer for this phy */
345 sci_phy
->sata_timeout_timer
=
349 scic_sds_phy_sata_timeout
);
351 /* Perfrom the initialization of the TL hardware */
352 scic_sds_phy_transport_layer_initialization(
354 transport_layer_registers
);
356 /* Perofrm the initialization of the PE hardware */
357 scic_sds_phy_link_layer_initialization(sci_phy
, link_layer_registers
);
360 * There is nothing that needs to be done in this state just
361 * transition to the stopped state. */
362 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
363 SCI_BASE_PHY_STATE_STOPPED
);
369 * This method assigns the direct attached device ID for this phy.
371 * @sci_phy The phy for which the direct attached device id is to
373 * @device_id The direct attached device ID to assign to the phy.
374 * This will either be the RNi for the device or an invalid RNi if there
375 * is no current device assigned to the phy.
377 void scic_sds_phy_setup_transport(
378 struct scic_sds_phy
*sci_phy
,
383 writel(device_id
, &sci_phy
->transport_layer_registers
->stp_rni
);
386 * The read should guarantee that the first write gets posted
387 * before the next write
389 tl_control
= readl(&sci_phy
->transport_layer_registers
->control
);
390 tl_control
|= SCU_TLCR_GEN_BIT(CLEAR_TCI_NCQ_MAPPING_TABLE
);
391 writel(tl_control
, &sci_phy
->transport_layer_registers
->control
);
396 * @sci_phy: The phy object to be suspended.
398 * This function will perform the register reads/writes to suspend the SCU
399 * hardware protocol engine. none
401 static void scic_sds_phy_suspend(
402 struct scic_sds_phy
*sci_phy
)
404 u32 scu_sas_pcfg_value
;
407 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
408 scu_sas_pcfg_value
|= SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE
);
409 writel(scu_sas_pcfg_value
,
410 &sci_phy
->link_layer_registers
->phy_configuration
);
412 scic_sds_phy_setup_transport(
414 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
);
417 void scic_sds_phy_resume(struct scic_sds_phy
*sci_phy
)
419 u32 scu_sas_pcfg_value
;
422 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
423 scu_sas_pcfg_value
&= ~SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE
);
424 writel(scu_sas_pcfg_value
,
425 &sci_phy
->link_layer_registers
->phy_configuration
);
428 void scic_sds_phy_get_sas_address(struct scic_sds_phy
*sci_phy
,
429 struct sci_sas_address
*sas_address
)
431 sas_address
->high
= readl(&sci_phy
->link_layer_registers
->source_sas_address_high
);
432 sas_address
->low
= readl(&sci_phy
->link_layer_registers
->source_sas_address_low
);
435 void scic_sds_phy_get_attached_sas_address(struct scic_sds_phy
*sci_phy
,
436 struct sci_sas_address
*sas_address
)
438 struct sas_identify_frame
*iaf
;
440 iaf
= &sci_phy
->phy_type
.sas_id_frame
;
441 memcpy(sas_address
, iaf
->sas_addr
, SAS_ADDR_SIZE
);
444 void scic_sds_phy_get_protocols(
445 struct scic_sds_phy
*sci_phy
,
446 struct sci_sas_identify_address_frame_protocols
*protocols
)
449 (u16
)(readl(&sci_phy
->
450 link_layer_registers
->transmit_identification
) &
454 void scic_sds_phy_get_attached_phy_protocols(
455 struct scic_sds_phy
*sci_phy
,
456 struct sci_sas_identify_address_frame_protocols
*protocols
)
458 protocols
->u
.all
= 0;
460 if (sci_phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SAS
) {
461 struct sas_identify_frame
*iaf
;
463 iaf
= &sci_phy
->phy_type
.sas_id_frame
;
464 memcpy(&protocols
->u
.all
, &iaf
->initiator_bits
, 2);
465 } else if (sci_phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SATA
) {
466 protocols
->u
.bits
.stp_target
= 1;
471 * *****************************************************************************
472 * * SCIC SDS PHY Handler Redirects
473 * ***************************************************************************** */
476 * This method will attempt to start the phy object. This request is only valid
477 * when the phy is in the stopped state
482 enum sci_status
scic_sds_phy_start(struct scic_sds_phy
*sci_phy
)
484 return sci_phy
->state_handlers
->start_handler(sci_phy
);
488 * This method will attempt to stop the phy object.
491 * enum sci_status SCI_SUCCESS if the phy is going to stop SCI_INVALID_STATE
492 * if the phy is not in a valid state to stop
494 enum sci_status
scic_sds_phy_stop(struct scic_sds_phy
*sci_phy
)
496 return sci_phy
->state_handlers
->stop_handler(sci_phy
);
500 * This method will attempt to reset the phy. This request is only valid when
501 * the phy is in an ready state
506 enum sci_status
scic_sds_phy_reset(
507 struct scic_sds_phy
*sci_phy
)
509 return sci_phy
->state_handlers
->reset_handler(sci_phy
);
513 * This method will process the event code received.
519 enum sci_status
scic_sds_phy_event_handler(
520 struct scic_sds_phy
*sci_phy
,
523 return sci_phy
->state_handlers
->event_handler(sci_phy
, event_code
);
527 * This method will process the frame index received.
533 enum sci_status
scic_sds_phy_frame_handler(
534 struct scic_sds_phy
*sci_phy
,
537 return sci_phy
->state_handlers
->frame_handler(sci_phy
, frame_index
);
541 * This method will give the phy permission to consume power
546 enum sci_status
scic_sds_phy_consume_power_handler(
547 struct scic_sds_phy
*sci_phy
)
549 return sci_phy
->state_handlers
->consume_power_handler(sci_phy
);
553 * *****************************************************************************
554 * * SCIC PHY Public Methods
555 * ***************************************************************************** */
558 enum sci_status
scic_sas_phy_get_properties(
559 struct scic_sds_phy
*sci_phy
,
560 struct scic_sas_phy_properties
*properties
)
562 if (sci_phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SAS
) {
563 memcpy(&properties
->rcvd_iaf
,
564 &sci_phy
->phy_type
.sas_id_frame
,
565 sizeof(struct sas_identify_frame
));
567 properties
->rcvd_cap
.all
=
568 readl(&sci_phy
->link_layer_registers
->receive_phycap
);
577 enum sci_status
scic_sata_phy_get_properties(
578 struct scic_sds_phy
*sci_phy
,
579 struct scic_sata_phy_properties
*properties
)
581 if (sci_phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SATA
) {
582 memcpy(&properties
->signature_fis
,
583 &sci_phy
->phy_type
.sata_sig_fis
,
584 sizeof(struct dev_to_host_fis
));
586 /* / @todo add support for port selectors. */
587 properties
->is_port_selector_present
= false;
596 * *****************************************************************************
597 * * SCIC SDS PHY HELPER FUNCTIONS
598 * ***************************************************************************** */
603 * @sci_phy: The phy object that received SAS PHY DETECTED.
605 * This method continues the link training for the phy as if it were a SAS PHY
606 * instead of a SATA PHY. This is done because the completion queue had a SAS
607 * PHY DETECTED event when the state machine was expecting a SATA PHY event.
610 static void scic_sds_phy_start_sas_link_training(
611 struct scic_sds_phy
*sci_phy
)
616 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
617 phy_control
|= SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD
);
619 &sci_phy
->link_layer_registers
->phy_configuration
);
621 sci_base_state_machine_change_state(
622 &sci_phy
->starting_substate_machine
,
623 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
626 sci_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_SAS
;
631 * @sci_phy: The phy object that received a SATA SPINUP HOLD event
633 * This method continues the link training for the phy as if it were a SATA PHY
634 * instead of a SAS PHY. This is done because the completion queue had a SATA
635 * SPINUP HOLD event when the state machine was expecting a SAS PHY event. none
637 static void scic_sds_phy_start_sata_link_training(
638 struct scic_sds_phy
*sci_phy
)
640 sci_base_state_machine_change_state(
641 &sci_phy
->starting_substate_machine
,
642 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
645 sci_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_SATA
;
649 * scic_sds_phy_complete_link_training - perform processing common to
650 * all protocols upon completion of link training.
651 * @sci_phy: This parameter specifies the phy object for which link training
653 * @max_link_rate: This parameter specifies the maximum link rate to be
654 * associated with this phy.
655 * @next_state: This parameter specifies the next state for the phy's starting
659 static void scic_sds_phy_complete_link_training(
660 struct scic_sds_phy
*sci_phy
,
661 enum sas_linkrate max_link_rate
,
664 sci_phy
->max_negotiated_speed
= max_link_rate
;
666 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
670 static void scic_sds_phy_restart_starting_state(
671 struct scic_sds_phy
*sci_phy
)
673 /* Stop the current substate machine */
674 sci_base_state_machine_stop(&sci_phy
->starting_substate_machine
);
676 /* Re-enter the base state machine starting state */
677 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
678 SCI_BASE_PHY_STATE_STARTING
);
681 /* ****************************************************************************
682 * SCIC SDS PHY general handlers
683 ************************************************************************** */
684 static enum sci_status
scic_sds_phy_starting_substate_general_stop_handler(
685 struct scic_sds_phy
*phy
)
687 sci_base_state_machine_stop(&phy
->starting_substate_machine
);
689 sci_base_state_machine_change_state(&phy
->state_machine
,
690 SCI_BASE_PHY_STATE_STOPPED
);
696 * *****************************************************************************
697 * * SCIC SDS PHY EVENT_HANDLERS
698 * ***************************************************************************** */
702 * @phy: This struct scic_sds_phy object which has received an event.
703 * @event_code: This is the event code which the phy object is to decode.
705 * This method is called when an event notification is received for the phy
706 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. -
707 * decode the event - sas phy detected causes a state transition to the wait
708 * for speed event notification. - any other events log a warning message and
709 * set a failure status enum sci_status SCI_SUCCESS on any valid event notification
710 * SCI_FAILURE on any unexpected event notifation
712 static enum sci_status
scic_sds_phy_starting_substate_await_ossp_event_handler(
713 struct scic_sds_phy
*sci_phy
,
716 u32 result
= SCI_SUCCESS
;
718 switch (scu_get_event_code(event_code
)) {
719 case SCU_EVENT_SAS_PHY_DETECTED
:
720 scic_sds_phy_start_sas_link_training(sci_phy
);
721 sci_phy
->is_in_link_training
= true;
724 case SCU_EVENT_SATA_SPINUP_HOLD
:
725 scic_sds_phy_start_sata_link_training(sci_phy
);
726 sci_phy
->is_in_link_training
= true;
730 dev_dbg(sciphy_to_dev(sci_phy
),
731 "%s: PHY starting substate machine received "
732 "unexpected event_code %x\n",
736 result
= SCI_FAILURE
;
745 * @phy: This struct scic_sds_phy object which has received an event.
746 * @event_code: This is the event code which the phy object is to decode.
748 * This method is called when an event notification is received for the phy
749 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. -
750 * decode the event - sas phy detected returns us back to this state. - speed
751 * event detected causes a state transition to the wait for iaf. - identify
752 * timeout is an un-expected event and the state machine is restarted. - link
753 * failure events restart the starting state machine - any other events log a
754 * warning message and set a failure status enum sci_status SCI_SUCCESS on any valid
755 * event notification SCI_FAILURE on any unexpected event notifation
757 static enum sci_status
scic_sds_phy_starting_substate_await_sas_phy_speed_event_handler(
758 struct scic_sds_phy
*sci_phy
,
761 u32 result
= SCI_SUCCESS
;
763 switch (scu_get_event_code(event_code
)) {
764 case SCU_EVENT_SAS_PHY_DETECTED
:
766 * Why is this being reported again by the controller?
767 * We would re-enter this state so just stay here */
770 case SCU_EVENT_SAS_15
:
771 case SCU_EVENT_SAS_15_SSC
:
772 scic_sds_phy_complete_link_training(
774 SAS_LINK_RATE_1_5_GBPS
,
775 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
);
778 case SCU_EVENT_SAS_30
:
779 case SCU_EVENT_SAS_30_SSC
:
780 scic_sds_phy_complete_link_training(
782 SAS_LINK_RATE_3_0_GBPS
,
783 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
);
786 case SCU_EVENT_SAS_60
:
787 case SCU_EVENT_SAS_60_SSC
:
788 scic_sds_phy_complete_link_training(
790 SAS_LINK_RATE_6_0_GBPS
,
791 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
);
794 case SCU_EVENT_SATA_SPINUP_HOLD
:
796 * We were doing SAS PHY link training and received a SATA PHY event
797 * continue OOB/SN as if this were a SATA PHY */
798 scic_sds_phy_start_sata_link_training(sci_phy
);
801 case SCU_EVENT_LINK_FAILURE
:
802 /* Link failure change state back to the starting state */
803 scic_sds_phy_restart_starting_state(sci_phy
);
807 dev_warn(sciphy_to_dev(sci_phy
),
808 "%s: PHY starting substate machine received "
809 "unexpected event_code %x\n",
813 result
= SCI_FAILURE
;
822 * @phy: This struct scic_sds_phy object which has received an event.
823 * @event_code: This is the event code which the phy object is to decode.
825 * This method is called when an event notification is received for the phy
826 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. -
827 * decode the event - sas phy detected event backs up the state machine to the
828 * await speed notification. - identify timeout is an un-expected event and the
829 * state machine is restarted. - link failure events restart the starting state
830 * machine - any other events log a warning message and set a failure status
831 * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any
832 * unexpected event notifation
834 static enum sci_status
scic_sds_phy_starting_substate_await_iaf_uf_event_handler(
835 struct scic_sds_phy
*sci_phy
,
838 u32 result
= SCI_SUCCESS
;
840 switch (scu_get_event_code(event_code
)) {
841 case SCU_EVENT_SAS_PHY_DETECTED
:
842 /* Backup the state machine */
843 scic_sds_phy_start_sas_link_training(sci_phy
);
846 case SCU_EVENT_SATA_SPINUP_HOLD
:
848 * We were doing SAS PHY link training and received a SATA PHY event
849 * continue OOB/SN as if this were a SATA PHY */
850 scic_sds_phy_start_sata_link_training(sci_phy
);
853 case SCU_EVENT_RECEIVED_IDENTIFY_TIMEOUT
:
854 case SCU_EVENT_LINK_FAILURE
:
855 case SCU_EVENT_HARD_RESET_RECEIVED
:
856 /* Start the oob/sn state machine over again */
857 scic_sds_phy_restart_starting_state(sci_phy
);
861 dev_warn(sciphy_to_dev(sci_phy
),
862 "%s: PHY starting substate machine received "
863 "unexpected event_code %x\n",
867 result
= SCI_FAILURE
;
876 * @phy: This struct scic_sds_phy object which has received an event.
877 * @event_code: This is the event code which the phy object is to decode.
879 * This method is called when an event notification is received for the phy
880 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_POWER. -
881 * decode the event - link failure events restart the starting state machine -
882 * any other events log a warning message and set a failure status enum sci_status
883 * SCI_SUCCESS on a link failure event SCI_FAILURE on any unexpected event
886 static enum sci_status
scic_sds_phy_starting_substate_await_sas_power_event_handler(
887 struct scic_sds_phy
*sci_phy
,
890 u32 result
= SCI_SUCCESS
;
892 switch (scu_get_event_code(event_code
)) {
893 case SCU_EVENT_LINK_FAILURE
:
894 /* Link failure change state back to the starting state */
895 scic_sds_phy_restart_starting_state(sci_phy
);
899 dev_warn(sciphy_to_dev(sci_phy
),
900 "%s: PHY starting substate machine received unexpected "
905 result
= SCI_FAILURE
;
914 * @phy: This struct scic_sds_phy object which has received an event.
915 * @event_code: This is the event code which the phy object is to decode.
917 * This method is called when an event notification is received for the phy
918 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. -
919 * decode the event - link failure events restart the starting state machine -
920 * sata spinup hold events are ignored since they are expected - any other
921 * events log a warning message and set a failure status enum sci_status SCI_SUCCESS
922 * on a link failure event SCI_FAILURE on any unexpected event notifation
924 static enum sci_status
scic_sds_phy_starting_substate_await_sata_power_event_handler(
925 struct scic_sds_phy
*sci_phy
,
928 u32 result
= SCI_SUCCESS
;
930 switch (scu_get_event_code(event_code
)) {
931 case SCU_EVENT_LINK_FAILURE
:
932 /* Link failure change state back to the starting state */
933 scic_sds_phy_restart_starting_state(sci_phy
);
936 case SCU_EVENT_SATA_SPINUP_HOLD
:
937 /* These events are received every 10ms and are expected while in this state */
940 case SCU_EVENT_SAS_PHY_DETECTED
:
942 * There has been a change in the phy type before OOB/SN for the
943 * SATA finished start down the SAS link traning path. */
944 scic_sds_phy_start_sas_link_training(sci_phy
);
948 dev_warn(sciphy_to_dev(sci_phy
),
949 "%s: PHY starting substate machine received "
950 "unexpected event_code %x\n",
954 result
= SCI_FAILURE
;
962 * scic_sds_phy_starting_substate_await_sata_phy_event_handler -
963 * @phy: This struct scic_sds_phy object which has received an event.
964 * @event_code: This is the event code which the phy object is to decode.
966 * This method is called when an event notification is received for the phy
967 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. -
968 * decode the event - link failure events restart the starting state machine -
969 * sata spinup hold events are ignored since they are expected - sata phy
970 * detected event change to the wait speed event - any other events log a
971 * warning message and set a failure status enum sci_status SCI_SUCCESS on a link
972 * failure event SCI_FAILURE on any unexpected event notifation
974 static enum sci_status
scic_sds_phy_starting_substate_await_sata_phy_event_handler(
975 struct scic_sds_phy
*sci_phy
, u32 event_code
)
977 u32 result
= SCI_SUCCESS
;
979 switch (scu_get_event_code(event_code
)) {
980 case SCU_EVENT_LINK_FAILURE
:
981 /* Link failure change state back to the starting state */
982 scic_sds_phy_restart_starting_state(sci_phy
);
985 case SCU_EVENT_SATA_SPINUP_HOLD
:
986 /* These events might be received since we dont know how many may be in
987 * the completion queue while waiting for power
991 case SCU_EVENT_SATA_PHY_DETECTED
:
992 sci_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_SATA
;
994 /* We have received the SATA PHY notification change state */
995 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
996 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
);
999 case SCU_EVENT_SAS_PHY_DETECTED
:
1000 /* There has been a change in the phy type before OOB/SN for the
1001 * SATA finished start down the SAS link traning path.
1003 scic_sds_phy_start_sas_link_training(sci_phy
);
1007 dev_warn(sciphy_to_dev(sci_phy
),
1008 "%s: PHY starting substate machine received "
1009 "unexpected event_code %x\n",
1013 result
= SCI_FAILURE
;
1022 * @phy: This struct scic_sds_phy object which has received an event.
1023 * @event_code: This is the event code which the phy object is to decode.
1025 * This method is called when an event notification is received for the phy
1026 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN.
1027 * - decode the event - sata phy detected returns us back to this state. -
1028 * speed event detected causes a state transition to the wait for signature. -
1029 * link failure events restart the starting state machine - any other events
1030 * log a warning message and set a failure status enum sci_status SCI_SUCCESS on any
1031 * valid event notification SCI_FAILURE on any unexpected event notifation
1033 static enum sci_status
scic_sds_phy_starting_substate_await_sata_speed_event_handler(
1034 struct scic_sds_phy
*sci_phy
,
1037 u32 result
= SCI_SUCCESS
;
1039 switch (scu_get_event_code(event_code
)) {
1040 case SCU_EVENT_SATA_PHY_DETECTED
:
1042 * The hardware reports multiple SATA PHY detected events
1043 * ignore the extras */
1046 case SCU_EVENT_SATA_15
:
1047 case SCU_EVENT_SATA_15_SSC
:
1048 scic_sds_phy_complete_link_training(
1050 SAS_LINK_RATE_1_5_GBPS
,
1051 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
);
1054 case SCU_EVENT_SATA_30
:
1055 case SCU_EVENT_SATA_30_SSC
:
1056 scic_sds_phy_complete_link_training(
1058 SAS_LINK_RATE_3_0_GBPS
,
1059 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
);
1062 case SCU_EVENT_SATA_60
:
1063 case SCU_EVENT_SATA_60_SSC
:
1064 scic_sds_phy_complete_link_training(
1066 SAS_LINK_RATE_6_0_GBPS
,
1067 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
);
1070 case SCU_EVENT_LINK_FAILURE
:
1071 /* Link failure change state back to the starting state */
1072 scic_sds_phy_restart_starting_state(sci_phy
);
1075 case SCU_EVENT_SAS_PHY_DETECTED
:
1077 * There has been a change in the phy type before OOB/SN for the
1078 * SATA finished start down the SAS link traning path. */
1079 scic_sds_phy_start_sas_link_training(sci_phy
);
1083 dev_warn(sciphy_to_dev(sci_phy
),
1084 "%s: PHY starting substate machine received "
1085 "unexpected event_code %x\n",
1089 result
= SCI_FAILURE
;
1097 * scic_sds_phy_starting_substate_await_sig_fis_event_handler -
1098 * @phy: This struct scic_sds_phy object which has received an event.
1099 * @event_code: This is the event code which the phy object is to decode.
1101 * This method is called when an event notification is received for the phy
1102 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. -
1103 * decode the event - sas phy detected event backs up the state machine to the
1104 * await speed notification. - identify timeout is an un-expected event and the
1105 * state machine is restarted. - link failure events restart the starting state
1106 * machine - any other events log a warning message and set a failure status
1107 * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any
1108 * unexpected event notifation
1110 static enum sci_status
scic_sds_phy_starting_substate_await_sig_fis_event_handler(
1111 struct scic_sds_phy
*sci_phy
, u32 event_code
)
1113 u32 result
= SCI_SUCCESS
;
1115 switch (scu_get_event_code(event_code
)) {
1116 case SCU_EVENT_SATA_PHY_DETECTED
:
1117 /* Backup the state machine */
1118 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1119 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
);
1122 case SCU_EVENT_LINK_FAILURE
:
1123 /* Link failure change state back to the starting state */
1124 scic_sds_phy_restart_starting_state(sci_phy
);
1128 dev_warn(sciphy_to_dev(sci_phy
),
1129 "%s: PHY starting substate machine received "
1130 "unexpected event_code %x\n",
1134 result
= SCI_FAILURE
;
1143 * *****************************************************************************
1144 * * SCIC SDS PHY FRAME_HANDLERS
1145 * ***************************************************************************** */
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_IAF_UF. - Get the UF Header - If the UF
1156 * is an IAF - Copy IAF data to local phy object IAF data buffer. - Change
1157 * starting substate to wait power. - else - log warning message of unexpected
1158 * unsolicted frame - release frame buffer enum sci_status SCI_SUCCESS
1160 static enum sci_status
scic_sds_phy_starting_substate_await_iaf_uf_frame_handler(
1161 struct scic_sds_phy
*sci_phy
, u32 frame_index
)
1163 enum sci_status result
;
1165 struct sas_identify_frame
*identify_frame
;
1167 result
= scic_sds_unsolicited_frame_control_get_header(
1168 &(scic_sds_phy_get_controller(sci_phy
)->uf_control
),
1170 (void **)&frame_words
);
1172 if (result
!= SCI_SUCCESS
) {
1176 frame_words
[0] = SCIC_SWAP_DWORD(frame_words
[0]);
1177 identify_frame
= (struct sas_identify_frame
*)frame_words
;
1179 if (identify_frame
->frame_type
== 0) {
1182 /* Byte swap the rest of the frame so we can make
1183 * a copy of the buffer
1185 frame_words
[1] = SCIC_SWAP_DWORD(frame_words
[1]);
1186 frame_words
[2] = SCIC_SWAP_DWORD(frame_words
[2]);
1187 frame_words
[3] = SCIC_SWAP_DWORD(frame_words
[3]);
1188 frame_words
[4] = SCIC_SWAP_DWORD(frame_words
[4]);
1189 frame_words
[5] = SCIC_SWAP_DWORD(frame_words
[5]);
1191 memcpy(&sci_phy
->phy_type
.sas_id_frame
,
1193 sizeof(struct sas_identify_frame
));
1195 if (identify_frame
->smp_tport
) {
1196 /* We got the IAF for an expander PHY go to the final state since
1197 * there are no power requirements for expander phys.
1199 state
= SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
;
1201 /* We got the IAF we can now go to the await spinup semaphore state */
1202 state
= SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
;
1204 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1206 result
= SCI_SUCCESS
;
1208 dev_warn(sciphy_to_dev(sci_phy
),
1209 "%s: PHY starting substate machine received "
1210 "unexpected frame id %x\n",
1214 /* Regardless of the result release this frame since we are done with it */
1215 scic_sds_controller_release_frame(scic_sds_phy_get_controller(sci_phy
),
1223 * @phy: This is struct scic_sds_phy object which is being requested to decode the
1225 * @frame_index: This is the index of the unsolicited frame which was received
1228 * This method decodes the unsolicited frame when the struct scic_sds_phy is in the
1229 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Get the UF Header - If
1230 * the UF is an SIGNATURE FIS - Copy IAF data to local phy object SIGNATURE FIS
1231 * data buffer. - else - log warning message of unexpected unsolicted frame -
1232 * release frame buffer enum sci_status SCI_SUCCESS Must decode the SIGNATURE FIS
1235 static enum sci_status
scic_sds_phy_starting_substate_await_sig_fis_frame_handler(
1236 struct scic_sds_phy
*sci_phy
,
1239 enum sci_status result
;
1240 struct dev_to_host_fis
*frame_header
;
1241 u32
*fis_frame_data
;
1243 result
= scic_sds_unsolicited_frame_control_get_header(
1244 &(scic_sds_phy_get_controller(sci_phy
)->uf_control
),
1246 (void **)&frame_header
);
1248 if (result
!= SCI_SUCCESS
)
1251 if ((frame_header
->fis_type
== FIS_REGD2H
) &&
1252 !(frame_header
->status
& ATA_BUSY
)) {
1253 scic_sds_unsolicited_frame_control_get_buffer(
1254 &(scic_sds_phy_get_controller(sci_phy
)->uf_control
),
1256 (void **)&fis_frame_data
);
1258 scic_sds_controller_copy_sata_response(
1259 &sci_phy
->phy_type
.sata_sig_fis
,
1263 /* got IAF we can now go to the await spinup semaphore state */
1264 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1265 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
);
1267 result
= SCI_SUCCESS
;
1269 dev_warn(sciphy_to_dev(sci_phy
),
1270 "%s: PHY starting substate machine received "
1271 "unexpected frame id %x\n",
1275 /* Regardless of the result we are done with this frame with it */
1276 scic_sds_controller_release_frame(scic_sds_phy_get_controller(sci_phy
),
1283 * *****************************************************************************
1284 * * SCIC SDS PHY POWER_HANDLERS
1285 * ***************************************************************************** */
1288 * This method is called by the struct scic_sds_controller when the phy object is
1289 * granted power. - The notify enable spinups are turned on for this phy object
1290 * - The phy state machine is transitioned to the
1291 * SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. enum sci_status SCI_SUCCESS
1293 static enum sci_status
scic_sds_phy_starting_substate_await_sas_power_consume_power_handler(
1294 struct scic_sds_phy
*sci_phy
)
1298 enable_spinup
= readl(&sci_phy
->link_layer_registers
->notify_enable_spinup_control
);
1299 enable_spinup
|= SCU_ENSPINUP_GEN_BIT(ENABLE
);
1300 writel(enable_spinup
, &sci_phy
->link_layer_registers
->notify_enable_spinup_control
);
1302 /* Change state to the final state this substate machine has run to completion */
1303 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1304 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
);
1310 * This method is called by the struct scic_sds_controller when the phy object is
1311 * granted power. - The phy state machine is transitioned to the
1312 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. enum sci_status SCI_SUCCESS
1314 static enum sci_status
scic_sds_phy_starting_substate_await_sata_power_consume_power_handler(
1315 struct scic_sds_phy
*sci_phy
)
1317 u32 scu_sas_pcfg_value
;
1319 /* Release the spinup hold state and reset the OOB state machine */
1320 scu_sas_pcfg_value
=
1321 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
1322 scu_sas_pcfg_value
&=
1323 ~(SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD
) | SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE
));
1324 scu_sas_pcfg_value
|= SCU_SAS_PCFG_GEN_BIT(OOB_RESET
);
1325 writel(scu_sas_pcfg_value
,
1326 &sci_phy
->link_layer_registers
->phy_configuration
);
1328 /* Now restart the OOB operation */
1329 scu_sas_pcfg_value
&= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET
);
1330 scu_sas_pcfg_value
|= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE
);
1331 writel(scu_sas_pcfg_value
,
1332 &sci_phy
->link_layer_registers
->phy_configuration
);
1334 /* Change state to the final state this substate machine has run to completion */
1335 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1336 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN
);
1341 static enum sci_status
default_phy_handler(struct scic_sds_phy
*sci_phy
,
1344 dev_dbg(sciphy_to_dev(sci_phy
),
1345 "%s: in wrong state: %d\n", func
,
1346 sci_base_state_machine_get_state(&sci_phy
->state_machine
));
1347 return SCI_FAILURE_INVALID_STATE
;
1350 static enum sci_status
1351 scic_sds_phy_default_start_handler(struct scic_sds_phy
*sci_phy
)
1353 return default_phy_handler(sci_phy
, __func__
);
1356 static enum sci_status
1357 scic_sds_phy_default_stop_handler(struct scic_sds_phy
*sci_phy
)
1359 return default_phy_handler(sci_phy
, __func__
);
1362 static enum sci_status
1363 scic_sds_phy_default_reset_handler(struct scic_sds_phy
*sci_phy
)
1365 return default_phy_handler(sci_phy
, __func__
);
1368 static enum sci_status
1369 scic_sds_phy_default_destroy_handler(struct scic_sds_phy
*sci_phy
)
1371 return default_phy_handler(sci_phy
, __func__
);
1374 static enum sci_status
1375 scic_sds_phy_default_frame_handler(struct scic_sds_phy
*sci_phy
,
1378 struct scic_sds_controller
*scic
= scic_sds_phy_get_controller(sci_phy
);
1380 default_phy_handler(sci_phy
, __func__
);
1381 scic_sds_controller_release_frame(scic
, frame_index
);
1383 return SCI_FAILURE_INVALID_STATE
;
1386 static enum sci_status
1387 scic_sds_phy_default_event_handler(struct scic_sds_phy
*sci_phy
,
1390 return default_phy_handler(sci_phy
, __func__
);
1393 static enum sci_status
1394 scic_sds_phy_default_consume_power_handler(struct scic_sds_phy
*sci_phy
)
1396 return default_phy_handler(sci_phy
, __func__
);
1401 static const struct scic_sds_phy_state_handler scic_sds_phy_starting_substate_handler_table
[] = {
1402 [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL
] = {
1403 .start_handler
= scic_sds_phy_default_start_handler
,
1404 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1405 .reset_handler
= scic_sds_phy_default_reset_handler
,
1406 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1407 .frame_handler
= scic_sds_phy_default_frame_handler
,
1408 .event_handler
= scic_sds_phy_default_event_handler
,
1409 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1411 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
] = {
1412 .start_handler
= scic_sds_phy_default_start_handler
,
1413 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1414 .reset_handler
= scic_sds_phy_default_reset_handler
,
1415 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1416 .frame_handler
= scic_sds_phy_default_frame_handler
,
1417 .event_handler
= scic_sds_phy_starting_substate_await_ossp_event_handler
,
1418 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1420 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
] = {
1421 .start_handler
= scic_sds_phy_default_start_handler
,
1422 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1423 .reset_handler
= scic_sds_phy_default_reset_handler
,
1424 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1425 .frame_handler
= scic_sds_phy_default_frame_handler
,
1426 .event_handler
= scic_sds_phy_starting_substate_await_sas_phy_speed_event_handler
,
1427 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1429 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
] = {
1430 .start_handler
= scic_sds_phy_default_start_handler
,
1431 .stop_handler
= scic_sds_phy_default_stop_handler
,
1432 .reset_handler
= scic_sds_phy_default_reset_handler
,
1433 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1434 .frame_handler
= scic_sds_phy_starting_substate_await_iaf_uf_frame_handler
,
1435 .event_handler
= scic_sds_phy_starting_substate_await_iaf_uf_event_handler
,
1436 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1438 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
] = {
1439 .start_handler
= scic_sds_phy_default_start_handler
,
1440 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1441 .reset_handler
= scic_sds_phy_default_reset_handler
,
1442 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1443 .frame_handler
= scic_sds_phy_default_frame_handler
,
1444 .event_handler
= scic_sds_phy_starting_substate_await_sas_power_event_handler
,
1445 .consume_power_handler
= scic_sds_phy_starting_substate_await_sas_power_consume_power_handler
1447 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
] = {
1448 .start_handler
= scic_sds_phy_default_start_handler
,
1449 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1450 .reset_handler
= scic_sds_phy_default_reset_handler
,
1451 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1452 .frame_handler
= scic_sds_phy_default_frame_handler
,
1453 .event_handler
= scic_sds_phy_starting_substate_await_sata_power_event_handler
,
1454 .consume_power_handler
= scic_sds_phy_starting_substate_await_sata_power_consume_power_handler
1456 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN
] = {
1457 .start_handler
= scic_sds_phy_default_start_handler
,
1458 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1459 .reset_handler
= scic_sds_phy_default_reset_handler
,
1460 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1461 .frame_handler
= scic_sds_phy_default_frame_handler
,
1462 .event_handler
= scic_sds_phy_starting_substate_await_sata_phy_event_handler
,
1463 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1465 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
] = {
1466 .start_handler
= scic_sds_phy_default_start_handler
,
1467 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1468 .reset_handler
= scic_sds_phy_default_reset_handler
,
1469 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1470 .frame_handler
= scic_sds_phy_default_frame_handler
,
1471 .event_handler
= scic_sds_phy_starting_substate_await_sata_speed_event_handler
,
1472 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1474 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
] = {
1475 .start_handler
= scic_sds_phy_default_start_handler
,
1476 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1477 .reset_handler
= scic_sds_phy_default_reset_handler
,
1478 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1479 .frame_handler
= scic_sds_phy_starting_substate_await_sig_fis_frame_handler
,
1480 .event_handler
= scic_sds_phy_starting_substate_await_sig_fis_event_handler
,
1481 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1483 [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
] = {
1484 .start_handler
= scic_sds_phy_default_start_handler
,
1485 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1486 .reset_handler
= scic_sds_phy_default_reset_handler
,
1487 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1488 .frame_handler
= scic_sds_phy_default_frame_handler
,
1489 .event_handler
= scic_sds_phy_default_event_handler
,
1490 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1495 * scic_sds_phy_set_starting_substate_handlers() -
1497 * This macro sets the starting substate handlers by state_id
1499 #define scic_sds_phy_set_starting_substate_handlers(phy, state_id) \
1500 scic_sds_phy_set_state_handlers(\
1502 &scic_sds_phy_starting_substate_handler_table[(state_id)] \
1506 * ****************************************************************************
1507 * * PHY STARTING SUBSTATE METHODS
1508 * **************************************************************************** */
1511 * scic_sds_phy_starting_initial_substate_enter -
1512 * @object: This is the object which is cast to a struct scic_sds_phy object.
1514 * This method will perform the actions required by the struct scic_sds_phy on
1515 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL. - The initial state
1516 * handlers are put in place for the struct scic_sds_phy object. - The state is
1517 * changed to the wait phy type event notification. none
1519 static void scic_sds_phy_starting_initial_substate_enter(void *object
)
1521 struct scic_sds_phy
*sci_phy
= object
;
1523 scic_sds_phy_set_starting_substate_handlers(
1524 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL
);
1526 /* This is just an temporary state go off to the starting state */
1527 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1528 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
);
1533 * @object: This is the object which is cast to a struct scic_sds_phy object.
1535 * This method will perform the actions required by the struct scic_sds_phy on
1536 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_PHY_TYPE_EN. - Set the
1537 * struct scic_sds_phy object state handlers for this state. none
1539 static void scic_sds_phy_starting_await_ossp_en_substate_enter(void *object
)
1541 struct scic_sds_phy
*sci_phy
= object
;
1543 scic_sds_phy_set_starting_substate_handlers(
1544 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
1550 * @object: This is the object which is cast to a struct scic_sds_phy object.
1552 * This method will perform the actions required by the struct scic_sds_phy on
1553 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. - Set the
1554 * struct scic_sds_phy object state handlers for this state. none
1556 static void scic_sds_phy_starting_await_sas_speed_en_substate_enter(
1559 struct scic_sds_phy
*sci_phy
= object
;
1561 scic_sds_phy_set_starting_substate_handlers(
1562 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
1568 * @object: This is the object which is cast to a struct scic_sds_phy object.
1570 * This method will perform the actions required by the struct scic_sds_phy on
1571 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - Set the
1572 * struct scic_sds_phy object state handlers for this state. none
1574 static void scic_sds_phy_starting_await_iaf_uf_substate_enter(void *object
)
1576 struct scic_sds_phy
*sci_phy
= object
;
1578 scic_sds_phy_set_starting_substate_handlers(
1579 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
1585 * @object: This is the object which is cast to a struct scic_sds_phy object.
1587 * This method will perform the actions required by the struct scic_sds_phy on
1588 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Set the
1589 * struct scic_sds_phy object state handlers for this state. - Add this phy object to
1590 * the power control queue none
1592 static void scic_sds_phy_starting_await_sas_power_substate_enter(void *object
)
1594 struct scic_sds_phy
*sci_phy
= object
;
1596 scic_sds_phy_set_starting_substate_handlers(
1597 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
1600 scic_sds_controller_power_control_queue_insert(
1601 scic_sds_phy_get_controller(sci_phy
),
1608 * @object: This is the object which is cast to a struct scic_sds_phy object.
1610 * This method will perform the actions required by the struct scic_sds_phy on exiting
1611 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Remove the
1612 * struct scic_sds_phy object from the power control queue. none
1614 static void scic_sds_phy_starting_await_sas_power_substate_exit(void *object
)
1616 struct scic_sds_phy
*sci_phy
= object
;
1618 scic_sds_controller_power_control_queue_remove(
1619 scic_sds_phy_get_controller(sci_phy
), sci_phy
1625 * @object: This is the object which is cast to a struct scic_sds_phy object.
1627 * This method will perform the actions required by the struct scic_sds_phy on
1628 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Set the
1629 * struct scic_sds_phy object state handlers for this state. - Add this phy object to
1630 * the power control queue none
1632 static void scic_sds_phy_starting_await_sata_power_substate_enter(void *object
)
1634 struct scic_sds_phy
*sci_phy
= object
;
1636 scic_sds_phy_set_starting_substate_handlers(
1637 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
1640 scic_sds_controller_power_control_queue_insert(
1641 scic_sds_phy_get_controller(sci_phy
),
1648 * @object: This is the object which is cast to a struct scic_sds_phy object.
1650 * This method will perform the actions required by the struct scic_sds_phy on exiting
1651 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Remove the
1652 * struct scic_sds_phy object from the power control queue. none
1654 static void scic_sds_phy_starting_await_sata_power_substate_exit(void *object
)
1656 struct scic_sds_phy
*sci_phy
= object
;
1658 scic_sds_controller_power_control_queue_remove(
1659 scic_sds_phy_get_controller(sci_phy
),
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_SATA_PHY_EN. - Set the
1670 * struct scic_sds_phy object state handlers for this state. none
1672 static void scic_sds_phy_starting_await_sata_phy_substate_enter(void *object
)
1674 struct scic_sds_phy
*sci_phy
= object
;
1676 scic_sds_phy_set_starting_substate_handlers(
1678 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN
);
1680 isci_timer_start(sci_phy
->sata_timeout_timer
,
1681 SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT
);
1686 * @object: This is the object which is cast to a struct scic_sds_phy object.
1688 * This method will perform the actions required by the struct scic_sds_phy
1690 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
1691 * that was started on entry to await sata phy event notification none
1693 static inline void scic_sds_phy_starting_await_sata_phy_substate_exit(
1696 struct scic_sds_phy
*sci_phy
= object
;
1698 isci_timer_stop(sci_phy
->sata_timeout_timer
);
1703 * @object: This is the object which is cast to a struct scic_sds_phy object.
1705 * This method will perform the actions required by the struct scic_sds_phy on
1706 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - Set the
1707 * struct scic_sds_phy object state handlers for this state. none
1709 static void scic_sds_phy_starting_await_sata_speed_substate_enter(void *object
)
1711 struct scic_sds_phy
*sci_phy
= object
;
1713 scic_sds_phy_set_starting_substate_handlers(
1715 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
);
1717 isci_timer_start(sci_phy
->sata_timeout_timer
,
1718 SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT
);
1723 * @object: This is the object which is cast to a struct scic_sds_phy object.
1725 * This function will perform the actions required by the
1726 * struct scic_sds_phy on exiting
1727 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
1728 * that was started on entry to await sata phy event notification none
1730 static inline void scic_sds_phy_starting_await_sata_speed_substate_exit(
1733 struct scic_sds_phy
*sci_phy
= object
;
1735 isci_timer_stop(sci_phy
->sata_timeout_timer
);
1740 * @object: This is the object which is cast to a struct scic_sds_phy object.
1742 * This function will perform the actions required by the struct scic_sds_phy on
1743 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Set the
1744 * struct scic_sds_phy object state handlers for this state.
1745 * - Start the SIGNATURE FIS
1746 * timeout timer none
1748 static void scic_sds_phy_starting_await_sig_fis_uf_substate_enter(void *object
)
1750 bool continue_to_ready_state
;
1751 struct scic_sds_phy
*sci_phy
= object
;
1753 scic_sds_phy_set_starting_substate_handlers(
1755 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
);
1757 continue_to_ready_state
= scic_sds_port_link_detected(
1758 sci_phy
->owning_port
,
1761 if (continue_to_ready_state
) {
1763 * Clear the PE suspend condition so we can actually
1765 * The hardware will not respond to the XRDY until the PE
1766 * suspend condition is cleared.
1768 scic_sds_phy_resume(sci_phy
);
1770 isci_timer_start(sci_phy
->sata_timeout_timer
,
1771 SCIC_SDS_SIGNATURE_FIS_TIMEOUT
);
1773 sci_phy
->is_in_link_training
= false;
1778 * @object: This is the object which is cast to a struct scic_sds_phy object.
1780 * This function will perform the actions required by the
1781 * struct scic_sds_phy on exiting
1782 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Stop the SIGNATURE
1783 * FIS timeout timer. none
1785 static inline void scic_sds_phy_starting_await_sig_fis_uf_substate_exit(
1788 struct scic_sds_phy
*sci_phy
= object
;
1790 isci_timer_stop(sci_phy
->sata_timeout_timer
);
1795 * @object: This is the object which is cast to a struct scic_sds_phy object.
1797 * This method will perform the actions required by the struct scic_sds_phy on
1798 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. - Set the struct scic_sds_phy
1799 * object state handlers for this state. - Change base state machine to the
1802 static void scic_sds_phy_starting_final_substate_enter(void *object
)
1804 struct scic_sds_phy
*sci_phy
= object
;
1806 scic_sds_phy_set_starting_substate_handlers(sci_phy
,
1807 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
);
1809 /* State machine has run to completion so exit out and change
1810 * the base state machine to the ready state
1812 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1813 SCI_BASE_PHY_STATE_READY
);
1816 /* --------------------------------------------------------------------------- */
1818 static const struct sci_base_state scic_sds_phy_starting_substates
[] = {
1819 [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL
] = {
1820 .enter_state
= scic_sds_phy_starting_initial_substate_enter
,
1822 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
] = {
1823 .enter_state
= scic_sds_phy_starting_await_ossp_en_substate_enter
,
1825 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
] = {
1826 .enter_state
= scic_sds_phy_starting_await_sas_speed_en_substate_enter
,
1828 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
] = {
1829 .enter_state
= scic_sds_phy_starting_await_iaf_uf_substate_enter
,
1831 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
] = {
1832 .enter_state
= scic_sds_phy_starting_await_sas_power_substate_enter
,
1833 .exit_state
= scic_sds_phy_starting_await_sas_power_substate_exit
,
1835 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
] = {
1836 .enter_state
= scic_sds_phy_starting_await_sata_power_substate_enter
,
1837 .exit_state
= scic_sds_phy_starting_await_sata_power_substate_exit
1839 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN
] = {
1840 .enter_state
= scic_sds_phy_starting_await_sata_phy_substate_enter
,
1841 .exit_state
= scic_sds_phy_starting_await_sata_phy_substate_exit
1843 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
] = {
1844 .enter_state
= scic_sds_phy_starting_await_sata_speed_substate_enter
,
1845 .exit_state
= scic_sds_phy_starting_await_sata_speed_substate_exit
1847 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
] = {
1848 .enter_state
= scic_sds_phy_starting_await_sig_fis_uf_substate_enter
,
1849 .exit_state
= scic_sds_phy_starting_await_sig_fis_uf_substate_exit
1851 [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
] = {
1852 .enter_state
= scic_sds_phy_starting_final_substate_enter
,
1857 * This method takes the struct scic_sds_phy from a stopped state and
1858 * attempts to start it. - The phy state machine is transitioned to the
1859 * SCI_BASE_PHY_STATE_STARTING. enum sci_status SCI_SUCCESS
1861 static enum sci_status
1862 scic_sds_phy_stopped_state_start_handler(struct scic_sds_phy
*sci_phy
)
1864 struct isci_host
*ihost
;
1865 struct scic_sds_controller
*scic
;
1867 scic
= scic_sds_phy_get_controller(sci_phy
),
1868 ihost
= scic
->ihost
;
1870 /* Create the SIGNATURE FIS Timeout timer for this phy */
1871 sci_phy
->sata_timeout_timer
= isci_timer_create(ihost
, sci_phy
,
1872 scic_sds_phy_sata_timeout
);
1874 if (sci_phy
->sata_timeout_timer
)
1875 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1876 SCI_BASE_PHY_STATE_STARTING
);
1881 static enum sci_status
1882 scic_sds_phy_stopped_state_destroy_handler(struct scic_sds_phy
*sci_phy
)
1887 static enum sci_status
1888 scic_sds_phy_ready_state_stop_handler(struct scic_sds_phy
*sci_phy
)
1890 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1891 SCI_BASE_PHY_STATE_STOPPED
);
1896 static enum sci_status
1897 scic_sds_phy_ready_state_reset_handler(struct scic_sds_phy
*sci_phy
)
1899 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1900 SCI_BASE_PHY_STATE_RESETTING
);
1906 * scic_sds_phy_ready_state_event_handler -
1907 * @phy: This is the struct scic_sds_phy object which has received the event.
1909 * This method request the struct scic_sds_phy handle the received event. The only
1910 * event that we are interested in while in the ready state is the link failure
1911 * event. - decoded event is a link failure - transition the struct scic_sds_phy back
1912 * to the SCI_BASE_PHY_STATE_STARTING state. - any other event received will
1913 * report a warning message enum sci_status SCI_SUCCESS if the event received is a
1914 * link failure SCI_FAILURE_INVALID_STATE for any other event received.
1916 static enum sci_status
scic_sds_phy_ready_state_event_handler(struct scic_sds_phy
*sci_phy
,
1919 enum sci_status result
= SCI_FAILURE
;
1921 switch (scu_get_event_code(event_code
)) {
1922 case SCU_EVENT_LINK_FAILURE
:
1923 /* Link failure change state back to the starting state */
1924 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1925 SCI_BASE_PHY_STATE_STARTING
);
1926 result
= SCI_SUCCESS
;
1929 case SCU_EVENT_BROADCAST_CHANGE
:
1930 /* Broadcast change received. Notify the port. */
1931 if (scic_sds_phy_get_port(sci_phy
) != NULL
)
1932 scic_sds_port_broadcast_change_received(sci_phy
->owning_port
, sci_phy
);
1934 sci_phy
->bcn_received_while_port_unassigned
= true;
1938 dev_warn(sciphy_to_dev(sci_phy
),
1939 "%sP SCIC PHY 0x%p ready state machine received "
1940 "unexpected event_code %x\n",
1941 __func__
, sci_phy
, event_code
);
1943 result
= SCI_FAILURE_INVALID_STATE
;
1950 static enum sci_status
scic_sds_phy_resetting_state_event_handler(struct scic_sds_phy
*sci_phy
,
1953 enum sci_status result
= SCI_FAILURE
;
1955 switch (scu_get_event_code(event_code
)) {
1956 case SCU_EVENT_HARD_RESET_TRANSMITTED
:
1957 /* Link failure change state back to the starting state */
1958 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1959 SCI_BASE_PHY_STATE_STARTING
);
1960 result
= SCI_SUCCESS
;
1964 dev_warn(sciphy_to_dev(sci_phy
),
1965 "%s: SCIC PHY 0x%p resetting state machine received "
1966 "unexpected event_code %x\n",
1967 __func__
, sci_phy
, event_code
);
1969 result
= SCI_FAILURE_INVALID_STATE
;
1976 /* --------------------------------------------------------------------------- */
1978 static const struct scic_sds_phy_state_handler scic_sds_phy_state_handler_table
[] = {
1979 [SCI_BASE_PHY_STATE_INITIAL
] = {
1980 .start_handler
= scic_sds_phy_default_start_handler
,
1981 .stop_handler
= scic_sds_phy_default_stop_handler
,
1982 .reset_handler
= scic_sds_phy_default_reset_handler
,
1983 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1984 .frame_handler
= scic_sds_phy_default_frame_handler
,
1985 .event_handler
= scic_sds_phy_default_event_handler
,
1986 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1988 [SCI_BASE_PHY_STATE_STOPPED
] = {
1989 .start_handler
= scic_sds_phy_stopped_state_start_handler
,
1990 .stop_handler
= scic_sds_phy_default_stop_handler
,
1991 .reset_handler
= scic_sds_phy_default_reset_handler
,
1992 .destruct_handler
= scic_sds_phy_stopped_state_destroy_handler
,
1993 .frame_handler
= scic_sds_phy_default_frame_handler
,
1994 .event_handler
= scic_sds_phy_default_event_handler
,
1995 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1997 [SCI_BASE_PHY_STATE_STARTING
] = {
1998 .start_handler
= scic_sds_phy_default_start_handler
,
1999 .stop_handler
= scic_sds_phy_default_stop_handler
,
2000 .reset_handler
= scic_sds_phy_default_reset_handler
,
2001 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
2002 .frame_handler
= scic_sds_phy_default_frame_handler
,
2003 .event_handler
= scic_sds_phy_default_event_handler
,
2004 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
2006 [SCI_BASE_PHY_STATE_READY
] = {
2007 .start_handler
= scic_sds_phy_default_start_handler
,
2008 .stop_handler
= scic_sds_phy_ready_state_stop_handler
,
2009 .reset_handler
= scic_sds_phy_ready_state_reset_handler
,
2010 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
2011 .frame_handler
= scic_sds_phy_default_frame_handler
,
2012 .event_handler
= scic_sds_phy_ready_state_event_handler
,
2013 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
2015 [SCI_BASE_PHY_STATE_RESETTING
] = {
2016 .start_handler
= scic_sds_phy_default_start_handler
,
2017 .stop_handler
= scic_sds_phy_default_stop_handler
,
2018 .reset_handler
= scic_sds_phy_default_reset_handler
,
2019 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
2020 .frame_handler
= scic_sds_phy_default_frame_handler
,
2021 .event_handler
= scic_sds_phy_resetting_state_event_handler
,
2022 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
2024 [SCI_BASE_PHY_STATE_FINAL
] = {
2025 .start_handler
= scic_sds_phy_default_start_handler
,
2026 .stop_handler
= scic_sds_phy_default_stop_handler
,
2027 .reset_handler
= scic_sds_phy_default_reset_handler
,
2028 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
2029 .frame_handler
= scic_sds_phy_default_frame_handler
,
2030 .event_handler
= scic_sds_phy_default_event_handler
,
2031 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
2036 * ****************************************************************************
2037 * * PHY STATE PRIVATE METHODS
2038 * **************************************************************************** */
2042 * @sci_phy: This is the struct scic_sds_phy object to stop.
2044 * This method will stop the struct scic_sds_phy object. This does not reset the
2045 * protocol engine it just suspends it and places it in a state where it will
2046 * not cause the end device to power up. none
2048 static void scu_link_layer_stop_protocol_engine(
2049 struct scic_sds_phy
*sci_phy
)
2051 u32 scu_sas_pcfg_value
;
2052 u32 enable_spinup_value
;
2054 /* Suspend the protocol engine and place it in a sata spinup hold state */
2055 scu_sas_pcfg_value
=
2056 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
2057 scu_sas_pcfg_value
|=
2058 (SCU_SAS_PCFG_GEN_BIT(OOB_RESET
) |
2059 SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE
) |
2060 SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD
));
2061 writel(scu_sas_pcfg_value
,
2062 &sci_phy
->link_layer_registers
->phy_configuration
);
2064 /* Disable the notify enable spinup primitives */
2065 enable_spinup_value
= readl(&sci_phy
->link_layer_registers
->notify_enable_spinup_control
);
2066 enable_spinup_value
&= ~SCU_ENSPINUP_GEN_BIT(ENABLE
);
2067 writel(enable_spinup_value
, &sci_phy
->link_layer_registers
->notify_enable_spinup_control
);
2073 * This method will start the OOB/SN state machine for this struct scic_sds_phy object.
2075 static void scu_link_layer_start_oob(
2076 struct scic_sds_phy
*sci_phy
)
2078 u32 scu_sas_pcfg_value
;
2080 scu_sas_pcfg_value
=
2081 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
2082 scu_sas_pcfg_value
|= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE
);
2083 scu_sas_pcfg_value
&=
2084 ~(SCU_SAS_PCFG_GEN_BIT(OOB_RESET
) |
2085 SCU_SAS_PCFG_GEN_BIT(HARD_RESET
));
2086 writel(scu_sas_pcfg_value
,
2087 &sci_phy
->link_layer_registers
->phy_configuration
);
2093 * This method will transmit a hard reset request on the specified phy. The SCU
2094 * hardware requires that we reset the OOB state machine and set the hard reset
2095 * bit in the phy configuration register. We then must start OOB over with the
2096 * hard reset bit set.
2098 static void scu_link_layer_tx_hard_reset(
2099 struct scic_sds_phy
*sci_phy
)
2101 u32 phy_configuration_value
;
2104 * SAS Phys must wait for the HARD_RESET_TX event notification to transition
2105 * to the starting state. */
2106 phy_configuration_value
=
2107 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
2108 phy_configuration_value
|=
2109 (SCU_SAS_PCFG_GEN_BIT(HARD_RESET
) |
2110 SCU_SAS_PCFG_GEN_BIT(OOB_RESET
));
2111 writel(phy_configuration_value
,
2112 &sci_phy
->link_layer_registers
->phy_configuration
);
2114 /* Now take the OOB state machine out of reset */
2115 phy_configuration_value
|= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE
);
2116 phy_configuration_value
&= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET
);
2117 writel(phy_configuration_value
,
2118 &sci_phy
->link_layer_registers
->phy_configuration
);
2122 * ****************************************************************************
2123 * * PHY BASE STATE METHODS
2124 * **************************************************************************** */
2128 * @object: This is the object which is cast to a struct scic_sds_phy object.
2130 * This method will perform the actions required by the struct scic_sds_phy on
2131 * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
2132 * handlers for the phy object base state machine initial state. none
2134 static void scic_sds_phy_initial_state_enter(void *object
)
2136 struct scic_sds_phy
*sci_phy
= object
;
2138 scic_sds_phy_set_base_state_handlers(sci_phy
, SCI_BASE_PHY_STATE_INITIAL
);
2143 * @object: This is the object which is cast to a struct scic_sds_phy object.
2145 * This function will perform the actions required by the struct scic_sds_phy on
2146 * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
2147 * handlers for the phy object base state machine initial state. - The SCU
2148 * hardware is requested to stop the protocol engine. none
2150 static void scic_sds_phy_stopped_state_enter(void *object
)
2152 struct scic_sds_phy
*sci_phy
= object
;
2153 struct scic_sds_controller
*scic
= scic_sds_phy_get_controller(sci_phy
);
2154 struct isci_host
*ihost
= scic
->ihost
;
2157 * @todo We need to get to the controller to place this PE in a
2161 scic_sds_phy_set_base_state_handlers(sci_phy
,
2162 SCI_BASE_PHY_STATE_STOPPED
);
2164 if (sci_phy
->sata_timeout_timer
!= NULL
) {
2165 isci_del_timer(ihost
, sci_phy
->sata_timeout_timer
);
2167 sci_phy
->sata_timeout_timer
= NULL
;
2170 scu_link_layer_stop_protocol_engine(sci_phy
);
2172 if (sci_phy
->state_machine
.previous_state_id
!=
2173 SCI_BASE_PHY_STATE_INITIAL
)
2174 scic_sds_controller_link_down(
2175 scic_sds_phy_get_controller(sci_phy
),
2176 scic_sds_phy_get_port(sci_phy
),
2182 * @object: This is the object which is cast to a struct scic_sds_phy object.
2184 * This method will perform the actions required by the struct scic_sds_phy on
2185 * entering the SCI_BASE_PHY_STATE_STARTING. - This function sets the state
2186 * handlers for the phy object base state machine starting state. - The SCU
2187 * hardware is requested to start OOB/SN on this protocl engine. - The phy
2188 * starting substate machine is started. - If the previous state was the ready
2189 * state then the struct scic_sds_controller is informed that the phy has gone link
2192 static void scic_sds_phy_starting_state_enter(void *object
)
2194 struct scic_sds_phy
*sci_phy
= object
;
2196 scic_sds_phy_set_base_state_handlers(sci_phy
, SCI_BASE_PHY_STATE_STARTING
);
2198 scu_link_layer_stop_protocol_engine(sci_phy
);
2199 scu_link_layer_start_oob(sci_phy
);
2201 /* We don't know what kind of phy we are going to be just yet */
2202 sci_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_UNKNOWN
;
2203 sci_phy
->bcn_received_while_port_unassigned
= false;
2205 /* Change over to the starting substate machine to continue */
2206 sci_base_state_machine_start(&sci_phy
->starting_substate_machine
);
2208 if (sci_phy
->state_machine
.previous_state_id
2209 == SCI_BASE_PHY_STATE_READY
) {
2210 scic_sds_controller_link_down(
2211 scic_sds_phy_get_controller(sci_phy
),
2212 scic_sds_phy_get_port(sci_phy
),
2220 * @object: This is the object which is cast to a struct scic_sds_phy object.
2222 * This method will perform the actions required by the struct scic_sds_phy on
2223 * entering the SCI_BASE_PHY_STATE_READY. - This function sets the state
2224 * handlers for the phy object base state machine ready state. - The SCU
2225 * hardware protocol engine is resumed. - The struct scic_sds_controller is informed
2226 * that the phy object has gone link up. none
2228 static void scic_sds_phy_ready_state_enter(void *object
)
2230 struct scic_sds_phy
*sci_phy
= object
;
2232 scic_sds_phy_set_base_state_handlers(sci_phy
, SCI_BASE_PHY_STATE_READY
);
2234 scic_sds_controller_link_up(
2235 scic_sds_phy_get_controller(sci_phy
),
2236 scic_sds_phy_get_port(sci_phy
),
2243 * @object: This is the object which is cast to a struct scic_sds_phy object.
2245 * This method will perform the actions required by the struct scic_sds_phy on exiting
2246 * the SCI_BASE_PHY_STATE_INITIAL. This function suspends the SCU hardware
2247 * protocol engine represented by this struct scic_sds_phy object. none
2249 static void scic_sds_phy_ready_state_exit(void *object
)
2251 struct scic_sds_phy
*sci_phy
= object
;
2253 scic_sds_phy_suspend(sci_phy
);
2258 * @object: This is the object which is cast to a struct scic_sds_phy object.
2260 * This method will perform the actions required by the struct scic_sds_phy on
2261 * entering the SCI_BASE_PHY_STATE_RESETTING. - This function sets the state
2262 * handlers for the phy object base state machine resetting state. none
2264 static void scic_sds_phy_resetting_state_enter(void *object
)
2266 struct scic_sds_phy
*sci_phy
= object
;
2268 scic_sds_phy_set_base_state_handlers(sci_phy
, SCI_BASE_PHY_STATE_RESETTING
);
2271 * The phy is being reset, therefore deactivate it from the port.
2272 * In the resetting state we don't notify the user regarding
2273 * link up and link down notifications. */
2274 scic_sds_port_deactivate_phy(sci_phy
->owning_port
, sci_phy
, false);
2276 if (sci_phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SAS
) {
2277 scu_link_layer_tx_hard_reset(sci_phy
);
2280 * The SCU does not need to have a discrete reset state so
2281 * just go back to the starting state.
2283 sci_base_state_machine_change_state(
2284 &sci_phy
->state_machine
,
2285 SCI_BASE_PHY_STATE_STARTING
);
2291 * @object: This is the object which is cast to a struct scic_sds_phy object.
2293 * This method will perform the actions required by the struct scic_sds_phy on
2294 * entering the SCI_BASE_PHY_STATE_FINAL. - This function sets the state
2295 * handlers for the phy object base state machine final state. none
2297 static void scic_sds_phy_final_state_enter(void *object
)
2299 struct scic_sds_phy
*sci_phy
= object
;
2301 scic_sds_phy_set_base_state_handlers(sci_phy
, SCI_BASE_PHY_STATE_FINAL
);
2303 /* Nothing to do here */
2306 /* --------------------------------------------------------------------------- */
2308 static const struct sci_base_state scic_sds_phy_state_table
[] = {
2309 [SCI_BASE_PHY_STATE_INITIAL
] = {
2310 .enter_state
= scic_sds_phy_initial_state_enter
,
2312 [SCI_BASE_PHY_STATE_STOPPED
] = {
2313 .enter_state
= scic_sds_phy_stopped_state_enter
,
2315 [SCI_BASE_PHY_STATE_STARTING
] = {
2316 .enter_state
= scic_sds_phy_starting_state_enter
,
2318 [SCI_BASE_PHY_STATE_READY
] = {
2319 .enter_state
= scic_sds_phy_ready_state_enter
,
2320 .exit_state
= scic_sds_phy_ready_state_exit
,
2322 [SCI_BASE_PHY_STATE_RESETTING
] = {
2323 .enter_state
= scic_sds_phy_resetting_state_enter
,
2325 [SCI_BASE_PHY_STATE_FINAL
] = {
2326 .enter_state
= scic_sds_phy_final_state_enter
,
2330 void scic_sds_phy_construct(struct scic_sds_phy
*sci_phy
,
2331 struct scic_sds_port
*owning_port
, u8 phy_index
)
2334 sci_base_state_machine_construct(&sci_phy
->state_machine
,
2336 scic_sds_phy_state_table
,
2337 SCI_BASE_PHY_STATE_INITIAL
);
2339 sci_base_state_machine_start(&sci_phy
->state_machine
);
2341 /* Copy the rest of the input data to our locals */
2342 sci_phy
->owning_port
= owning_port
;
2343 sci_phy
->phy_index
= phy_index
;
2344 sci_phy
->bcn_received_while_port_unassigned
= false;
2345 sci_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_UNKNOWN
;
2346 sci_phy
->link_layer_registers
= NULL
;
2347 sci_phy
->max_negotiated_speed
= SAS_LINK_RATE_UNKNOWN
;
2348 sci_phy
->sata_timeout_timer
= NULL
;
2350 /* Clear out the identification buffer data */
2351 memset(&sci_phy
->phy_type
, 0, sizeof(sci_phy
->phy_type
));
2353 /* Initialize the the substate machines */
2354 sci_base_state_machine_construct(&sci_phy
->starting_substate_machine
,
2356 scic_sds_phy_starting_substates
,
2357 SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL
);