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.
59 #include "state_machine.h"
61 #include "scic_sds_phy.h"
62 #include "scic_sds_port.h"
63 #include "remote_node_context.h"
65 #include "scu_event_codes.h"
68 #define SCIC_SDS_PHY_MIN_TIMER_COUNT (SCI_MAX_PHYS)
69 #define SCIC_SDS_PHY_MAX_TIMER_COUNT (SCI_MAX_PHYS)
71 /* Maximum arbitration wait time in micro-seconds */
72 #define SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME (700)
74 enum sas_linkrate
sci_phy_linkrate(struct scic_sds_phy
*sci_phy
)
76 return sci_phy
->max_negotiated_speed
;
80 * *****************************************************************************
81 * * SCIC SDS PHY Internal Methods
82 * ***************************************************************************** */
85 * This method will initialize the phy transport layer registers
87 * @transport_layer_registers
91 static enum sci_status
scic_sds_phy_transport_layer_initialization(
92 struct scic_sds_phy
*sci_phy
,
93 struct scu_transport_layer_registers __iomem
*transport_layer_registers
)
97 sci_phy
->transport_layer_registers
= transport_layer_registers
;
99 writel(SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
,
100 &sci_phy
->transport_layer_registers
->stp_rni
);
103 * Hardware team recommends that we enable the STP prefetch for all
106 tl_control
= readl(&sci_phy
->transport_layer_registers
->control
);
107 tl_control
|= SCU_TLCR_GEN_BIT(STP_WRITE_DATA_PREFETCH
);
108 writel(tl_control
, &sci_phy
->transport_layer_registers
->control
);
114 * This method will initialize the phy link layer registers
116 * @link_layer_registers:
120 static enum sci_status
121 scic_sds_phy_link_layer_initialization(struct scic_sds_phy
*sci_phy
,
122 struct scu_link_layer_registers __iomem
*link_layer_registers
)
124 struct scic_sds_controller
*scic
=
125 sci_phy
->owning_port
->owning_controller
;
126 int phy_idx
= sci_phy
->phy_index
;
127 struct sci_phy_user_params
*phy_user
=
128 &scic
->user_parameters
.sds1
.phys
[phy_idx
];
129 struct sci_phy_oem_params
*phy_oem
=
130 &scic
->oem_parameters
.sds1
.phys
[phy_idx
];
131 u32 phy_configuration
;
132 struct scic_phy_cap phy_cap
;
133 u32 parity_check
= 0;
134 u32 parity_count
= 0;
135 u32 llctl
, link_rate
;
138 sci_phy
->link_layer_registers
= link_layer_registers
;
140 /* Set our IDENTIFY frame data */
141 #define SCI_END_DEVICE 0x01
143 writel(SCU_SAS_TIID_GEN_BIT(SMP_INITIATOR
) |
144 SCU_SAS_TIID_GEN_BIT(SSP_INITIATOR
) |
145 SCU_SAS_TIID_GEN_BIT(STP_INITIATOR
) |
146 SCU_SAS_TIID_GEN_BIT(DA_SATA_HOST
) |
147 SCU_SAS_TIID_GEN_VAL(DEVICE_TYPE
, SCI_END_DEVICE
),
148 &sci_phy
->link_layer_registers
->transmit_identification
);
150 /* Write the device SAS Address */
152 &sci_phy
->link_layer_registers
->sas_device_name_high
);
153 writel(phy_idx
, &sci_phy
->link_layer_registers
->sas_device_name_low
);
155 /* Write the source SAS Address */
156 writel(phy_oem
->sas_address
.high
,
157 &sci_phy
->link_layer_registers
->source_sas_address_high
);
158 writel(phy_oem
->sas_address
.low
,
159 &sci_phy
->link_layer_registers
->source_sas_address_low
);
161 /* Clear and Set the PHY Identifier */
162 writel(0, &sci_phy
->link_layer_registers
->identify_frame_phy_id
);
163 writel(SCU_SAS_TIPID_GEN_VALUE(ID
, phy_idx
),
164 &sci_phy
->link_layer_registers
->identify_frame_phy_id
);
166 /* Change the initial state of the phy configuration register */
168 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
170 /* Hold OOB state machine in reset */
171 phy_configuration
|= SCU_SAS_PCFG_GEN_BIT(OOB_RESET
);
172 writel(phy_configuration
,
173 &sci_phy
->link_layer_registers
->phy_configuration
);
175 /* Configure the SNW capabilities */
178 phy_cap
.gen3_no_ssc
= 1;
179 phy_cap
.gen2_no_ssc
= 1;
180 phy_cap
.gen1_no_ssc
= 1;
181 if (scic
->oem_parameters
.sds1
.controller
.do_enable_ssc
== true) {
182 phy_cap
.gen3_ssc
= 1;
183 phy_cap
.gen2_ssc
= 1;
184 phy_cap
.gen1_ssc
= 1;
188 * The SAS specification indicates that the phy_capabilities that
189 * are transmitted shall have an even parity. Calculate the parity. */
190 parity_check
= phy_cap
.all
;
191 while (parity_check
!= 0) {
192 if (parity_check
& 0x1)
198 * If parity indicates there are an odd number of bits set, then
199 * set the parity bit to 1 in the phy capabilities. */
200 if ((parity_count
% 2) != 0)
203 writel(phy_cap
.all
, &sci_phy
->link_layer_registers
->phy_capabilities
);
205 /* Set the enable spinup period but disable the ability to send
206 * notify enable spinup
208 writel(SCU_ENSPINUP_GEN_VAL(COUNT
,
209 phy_user
->notify_enable_spin_up_insertion_frequency
),
210 &sci_phy
->link_layer_registers
->notify_enable_spinup_control
);
212 /* Write the ALIGN Insertion Ferequency for connected phy and
213 * inpendent of connected state
215 clksm_value
= SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(CONNECTED
,
216 phy_user
->in_connection_align_insertion_frequency
);
218 clksm_value
|= SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(GENERAL
,
219 phy_user
->align_insertion_frequency
);
221 writel(clksm_value
, &sci_phy
->link_layer_registers
->clock_skew_management
);
223 /* @todo Provide a way to write this register correctly */
225 &sci_phy
->link_layer_registers
->afe_lookup_table_control
);
227 llctl
= SCU_SAS_LLCTL_GEN_VAL(NO_OUTBOUND_TASK_TIMEOUT
,
228 (u8
)scic
->user_parameters
.sds1
.no_outbound_task_timeout
);
230 switch(phy_user
->max_speed_generation
) {
231 case SCIC_SDS_PARM_GEN3_SPEED
:
232 link_rate
= SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN3
;
234 case SCIC_SDS_PARM_GEN2_SPEED
:
235 link_rate
= SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN2
;
238 link_rate
= SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN1
;
241 llctl
|= SCU_SAS_LLCTL_GEN_VAL(MAX_LINK_RATE
, link_rate
);
242 writel(llctl
, &sci_phy
->link_layer_registers
->link_layer_control
);
244 if (is_a0() || is_a2()) {
245 /* Program the max ARB time for the PHY to 700us so we inter-operate with
246 * the PMC expander which shuts down PHYs if the expander PHY generates too
247 * many breaks. This time value will guarantee that the initiator PHY will
248 * generate the break.
250 writel(SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME
,
251 &sci_phy
->link_layer_registers
->maximum_arbitration_wait_timer_timeout
);
255 * Set the link layer hang detection to 500ms (0x1F4) from its default
256 * value of 128ms. Max value is 511 ms.
258 writel(0x1F4, &sci_phy
->link_layer_registers
->link_layer_hang_detection_timeout
);
260 /* We can exit the initial state to the stopped state */
261 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
262 SCI_BASE_PHY_STATE_STOPPED
);
268 * This function will handle the sata SIGNATURE FIS timeout condition. It will
269 * restart the starting substate machine since we dont know what has actually
272 static void scic_sds_phy_sata_timeout(void *phy
)
274 struct scic_sds_phy
*sci_phy
= phy
;
276 dev_dbg(sciphy_to_dev(sci_phy
),
277 "%s: SCIC SDS Phy 0x%p did not receive signature fis before "
282 sci_base_state_machine_stop(&sci_phy
->starting_substate_machine
);
284 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
285 SCI_BASE_PHY_STATE_STARTING
);
289 * This method returns the port currently containing this phy. If the phy is
290 * currently contained by the dummy port, then the phy is considered to not
292 * @sci_phy: This parameter specifies the phy for which to retrieve the
295 * This method returns a handle to a port that contains the supplied phy.
296 * NULL This value is returned if the phy is not part of a real
297 * port (i.e. it's contained in the dummy port). !NULL All other
298 * values indicate a handle/pointer to the port containing the phy.
300 struct scic_sds_port
*scic_sds_phy_get_port(
301 struct scic_sds_phy
*sci_phy
)
303 if (scic_sds_port_get_index(sci_phy
->owning_port
) == SCIC_SDS_DUMMY_PORT
)
306 return sci_phy
->owning_port
;
310 * This method will assign a port to the phy object.
311 * @out]: sci_phy This parameter specifies the phy for which to assign a port
316 void scic_sds_phy_set_port(
317 struct scic_sds_phy
*sci_phy
,
318 struct scic_sds_port
*sci_port
)
320 sci_phy
->owning_port
= sci_port
;
322 if (sci_phy
->bcn_received_while_port_unassigned
) {
323 sci_phy
->bcn_received_while_port_unassigned
= false;
324 scic_sds_port_broadcast_change_received(sci_phy
->owning_port
, sci_phy
);
329 * This method will initialize the constructed phy
331 * @link_layer_registers:
335 enum sci_status
scic_sds_phy_initialize(
336 struct scic_sds_phy
*sci_phy
,
337 struct scu_transport_layer_registers __iomem
*transport_layer_registers
,
338 struct scu_link_layer_registers __iomem
*link_layer_registers
)
340 struct scic_sds_controller
*scic
= scic_sds_phy_get_controller(sci_phy
);
341 struct isci_host
*ihost
= scic_to_ihost(scic
);
343 /* Create the SIGNATURE FIS Timeout timer for this phy */
344 sci_phy
->sata_timeout_timer
=
348 scic_sds_phy_sata_timeout
);
350 /* Perfrom the initialization of the TL hardware */
351 scic_sds_phy_transport_layer_initialization(
353 transport_layer_registers
);
355 /* Perofrm the initialization of the PE hardware */
356 scic_sds_phy_link_layer_initialization(sci_phy
, link_layer_registers
);
359 * There is nothing that needs to be done in this state just
360 * transition to the stopped state. */
361 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
362 SCI_BASE_PHY_STATE_STOPPED
);
368 * This method assigns the direct attached device ID for this phy.
370 * @sci_phy The phy for which the direct attached device id is to
372 * @device_id The direct attached device ID to assign to the phy.
373 * This will either be the RNi for the device or an invalid RNi if there
374 * is no current device assigned to the phy.
376 void scic_sds_phy_setup_transport(
377 struct scic_sds_phy
*sci_phy
,
382 writel(device_id
, &sci_phy
->transport_layer_registers
->stp_rni
);
385 * The read should guarantee that the first write gets posted
386 * before the next write
388 tl_control
= readl(&sci_phy
->transport_layer_registers
->control
);
389 tl_control
|= SCU_TLCR_GEN_BIT(CLEAR_TCI_NCQ_MAPPING_TABLE
);
390 writel(tl_control
, &sci_phy
->transport_layer_registers
->control
);
395 * @sci_phy: The phy object to be suspended.
397 * This function will perform the register reads/writes to suspend the SCU
398 * hardware protocol engine. none
400 static void scic_sds_phy_suspend(
401 struct scic_sds_phy
*sci_phy
)
403 u32 scu_sas_pcfg_value
;
406 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
407 scu_sas_pcfg_value
|= SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE
);
408 writel(scu_sas_pcfg_value
,
409 &sci_phy
->link_layer_registers
->phy_configuration
);
411 scic_sds_phy_setup_transport(
413 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
);
416 void scic_sds_phy_resume(struct scic_sds_phy
*sci_phy
)
418 u32 scu_sas_pcfg_value
;
421 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
422 scu_sas_pcfg_value
&= ~SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE
);
423 writel(scu_sas_pcfg_value
,
424 &sci_phy
->link_layer_registers
->phy_configuration
);
427 void scic_sds_phy_get_sas_address(struct scic_sds_phy
*sci_phy
,
428 struct sci_sas_address
*sas_address
)
430 sas_address
->high
= readl(&sci_phy
->link_layer_registers
->source_sas_address_high
);
431 sas_address
->low
= readl(&sci_phy
->link_layer_registers
->source_sas_address_low
);
434 void scic_sds_phy_get_attached_sas_address(struct scic_sds_phy
*sci_phy
,
435 struct sci_sas_address
*sas_address
)
437 struct sas_identify_frame
*iaf
;
438 struct isci_phy
*iphy
= sci_phy_to_iphy(sci_phy
);
440 iaf
= &iphy
->frame_rcvd
.iaf
;
441 memcpy(sas_address
, iaf
->sas_addr
, SAS_ADDR_SIZE
);
444 void scic_sds_phy_get_protocols(struct scic_sds_phy
*sci_phy
,
445 struct scic_phy_proto
*protocols
)
448 (u16
)(readl(&sci_phy
->
449 link_layer_registers
->transmit_identification
) &
454 * This method will attempt to start the phy object. This request is only valid
455 * when the phy is in the stopped state
460 enum sci_status
scic_sds_phy_start(struct scic_sds_phy
*sci_phy
)
462 return sci_phy
->state_handlers
->start_handler(sci_phy
);
466 * This method will attempt to stop the phy object.
469 * enum sci_status SCI_SUCCESS if the phy is going to stop SCI_INVALID_STATE
470 * if the phy is not in a valid state to stop
472 enum sci_status
scic_sds_phy_stop(struct scic_sds_phy
*sci_phy
)
474 return sci_phy
->state_handlers
->stop_handler(sci_phy
);
478 * This method will attempt to reset the phy. This request is only valid when
479 * the phy is in an ready state
484 enum sci_status
scic_sds_phy_reset(
485 struct scic_sds_phy
*sci_phy
)
487 return sci_phy
->state_handlers
->reset_handler(sci_phy
);
491 * This method will process the event code received.
497 enum sci_status
scic_sds_phy_event_handler(
498 struct scic_sds_phy
*sci_phy
,
501 return sci_phy
->state_handlers
->event_handler(sci_phy
, event_code
);
505 * This method will process the frame index received.
511 enum sci_status
scic_sds_phy_frame_handler(
512 struct scic_sds_phy
*sci_phy
,
515 return sci_phy
->state_handlers
->frame_handler(sci_phy
, frame_index
);
519 * This method will give the phy permission to consume power
524 enum sci_status
scic_sds_phy_consume_power_handler(
525 struct scic_sds_phy
*sci_phy
)
527 return sci_phy
->state_handlers
->consume_power_handler(sci_phy
);
531 * *****************************************************************************
532 * * SCIC SDS PHY HELPER FUNCTIONS
533 * ***************************************************************************** */
538 * @sci_phy: The phy object that received SAS PHY DETECTED.
540 * This method continues the link training for the phy as if it were a SAS PHY
541 * instead of a SATA PHY. This is done because the completion queue had a SAS
542 * PHY DETECTED event when the state machine was expecting a SATA PHY event.
545 static void scic_sds_phy_start_sas_link_training(
546 struct scic_sds_phy
*sci_phy
)
551 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
552 phy_control
|= SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD
);
554 &sci_phy
->link_layer_registers
->phy_configuration
);
556 sci_base_state_machine_change_state(
557 &sci_phy
->starting_substate_machine
,
558 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
561 sci_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_SAS
;
566 * @sci_phy: The phy object that received a SATA SPINUP HOLD event
568 * This method continues the link training for the phy as if it were a SATA PHY
569 * instead of a SAS PHY. This is done because the completion queue had a SATA
570 * SPINUP HOLD event when the state machine was expecting a SAS PHY event. none
572 static void scic_sds_phy_start_sata_link_training(
573 struct scic_sds_phy
*sci_phy
)
575 sci_base_state_machine_change_state(
576 &sci_phy
->starting_substate_machine
,
577 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
580 sci_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_SATA
;
584 * scic_sds_phy_complete_link_training - perform processing common to
585 * all protocols upon completion of link training.
586 * @sci_phy: This parameter specifies the phy object for which link training
588 * @max_link_rate: This parameter specifies the maximum link rate to be
589 * associated with this phy.
590 * @next_state: This parameter specifies the next state for the phy's starting
594 static void scic_sds_phy_complete_link_training(
595 struct scic_sds_phy
*sci_phy
,
596 enum sas_linkrate max_link_rate
,
599 sci_phy
->max_negotiated_speed
= max_link_rate
;
601 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
605 static void scic_sds_phy_restart_starting_state(
606 struct scic_sds_phy
*sci_phy
)
608 /* Stop the current substate machine */
609 sci_base_state_machine_stop(&sci_phy
->starting_substate_machine
);
611 /* Re-enter the base state machine starting state */
612 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
613 SCI_BASE_PHY_STATE_STARTING
);
616 /* ****************************************************************************
617 * SCIC SDS PHY general handlers
618 ************************************************************************** */
619 static enum sci_status
scic_sds_phy_starting_substate_general_stop_handler(
620 struct scic_sds_phy
*phy
)
622 sci_base_state_machine_stop(&phy
->starting_substate_machine
);
624 sci_base_state_machine_change_state(&phy
->state_machine
,
625 SCI_BASE_PHY_STATE_STOPPED
);
631 * *****************************************************************************
632 * * SCIC SDS PHY EVENT_HANDLERS
633 * ***************************************************************************** */
637 * @phy: This struct scic_sds_phy object which has received an event.
638 * @event_code: This is the event code which the phy object is to decode.
640 * This method is called when an event notification is received for the phy
641 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. -
642 * decode the event - sas phy detected causes a state transition to the wait
643 * for speed event notification. - any other events log a warning message and
644 * set a failure status enum sci_status SCI_SUCCESS on any valid event notification
645 * SCI_FAILURE on any unexpected event notifation
647 static enum sci_status
scic_sds_phy_starting_substate_await_ossp_event_handler(
648 struct scic_sds_phy
*sci_phy
,
651 u32 result
= SCI_SUCCESS
;
653 switch (scu_get_event_code(event_code
)) {
654 case SCU_EVENT_SAS_PHY_DETECTED
:
655 scic_sds_phy_start_sas_link_training(sci_phy
);
656 sci_phy
->is_in_link_training
= true;
659 case SCU_EVENT_SATA_SPINUP_HOLD
:
660 scic_sds_phy_start_sata_link_training(sci_phy
);
661 sci_phy
->is_in_link_training
= true;
665 dev_dbg(sciphy_to_dev(sci_phy
),
666 "%s: PHY starting substate machine received "
667 "unexpected event_code %x\n",
671 result
= SCI_FAILURE
;
680 * @phy: This struct scic_sds_phy object which has received an event.
681 * @event_code: This is the event code which the phy object is to decode.
683 * This method is called when an event notification is received for the phy
684 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. -
685 * decode the event - sas phy detected returns us back to this state. - speed
686 * event detected causes a state transition to the wait for iaf. - identify
687 * timeout is an un-expected event and the state machine is restarted. - link
688 * failure events restart the starting state machine - any other events log a
689 * warning message and set a failure status enum sci_status SCI_SUCCESS on any valid
690 * event notification SCI_FAILURE on any unexpected event notifation
692 static enum sci_status
scic_sds_phy_starting_substate_await_sas_phy_speed_event_handler(
693 struct scic_sds_phy
*sci_phy
,
696 u32 result
= SCI_SUCCESS
;
698 switch (scu_get_event_code(event_code
)) {
699 case SCU_EVENT_SAS_PHY_DETECTED
:
701 * Why is this being reported again by the controller?
702 * We would re-enter this state so just stay here */
705 case SCU_EVENT_SAS_15
:
706 case SCU_EVENT_SAS_15_SSC
:
707 scic_sds_phy_complete_link_training(
709 SAS_LINK_RATE_1_5_GBPS
,
710 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
);
713 case SCU_EVENT_SAS_30
:
714 case SCU_EVENT_SAS_30_SSC
:
715 scic_sds_phy_complete_link_training(
717 SAS_LINK_RATE_3_0_GBPS
,
718 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
);
721 case SCU_EVENT_SAS_60
:
722 case SCU_EVENT_SAS_60_SSC
:
723 scic_sds_phy_complete_link_training(
725 SAS_LINK_RATE_6_0_GBPS
,
726 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
);
729 case SCU_EVENT_SATA_SPINUP_HOLD
:
731 * We were doing SAS PHY link training and received a SATA PHY event
732 * continue OOB/SN as if this were a SATA PHY */
733 scic_sds_phy_start_sata_link_training(sci_phy
);
736 case SCU_EVENT_LINK_FAILURE
:
737 /* Link failure change state back to the starting state */
738 scic_sds_phy_restart_starting_state(sci_phy
);
742 dev_warn(sciphy_to_dev(sci_phy
),
743 "%s: PHY starting substate machine received "
744 "unexpected event_code %x\n",
748 result
= SCI_FAILURE
;
757 * @phy: This struct scic_sds_phy object which has received an event.
758 * @event_code: This is the event code which the phy object is to decode.
760 * This method is called when an event notification is received for the phy
761 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. -
762 * decode the event - sas phy detected event backs up the state machine to the
763 * await speed notification. - identify timeout is an un-expected event and the
764 * state machine is restarted. - link failure events restart the starting state
765 * machine - any other events log a warning message and set a failure status
766 * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any
767 * unexpected event notifation
769 static enum sci_status
scic_sds_phy_starting_substate_await_iaf_uf_event_handler(
770 struct scic_sds_phy
*sci_phy
,
773 u32 result
= SCI_SUCCESS
;
775 switch (scu_get_event_code(event_code
)) {
776 case SCU_EVENT_SAS_PHY_DETECTED
:
777 /* Backup the state machine */
778 scic_sds_phy_start_sas_link_training(sci_phy
);
781 case SCU_EVENT_SATA_SPINUP_HOLD
:
783 * We were doing SAS PHY link training and received a SATA PHY event
784 * continue OOB/SN as if this were a SATA PHY */
785 scic_sds_phy_start_sata_link_training(sci_phy
);
788 case SCU_EVENT_RECEIVED_IDENTIFY_TIMEOUT
:
789 case SCU_EVENT_LINK_FAILURE
:
790 case SCU_EVENT_HARD_RESET_RECEIVED
:
791 /* Start the oob/sn state machine over again */
792 scic_sds_phy_restart_starting_state(sci_phy
);
796 dev_warn(sciphy_to_dev(sci_phy
),
797 "%s: PHY starting substate machine received "
798 "unexpected event_code %x\n",
802 result
= SCI_FAILURE
;
811 * @phy: This struct scic_sds_phy object which has received an event.
812 * @event_code: This is the event code which the phy object is to decode.
814 * This method is called when an event notification is received for the phy
815 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_POWER. -
816 * decode the event - link failure events restart the starting state machine -
817 * any other events log a warning message and set a failure status enum sci_status
818 * SCI_SUCCESS on a link failure event SCI_FAILURE on any unexpected event
821 static enum sci_status
scic_sds_phy_starting_substate_await_sas_power_event_handler(
822 struct scic_sds_phy
*sci_phy
,
825 u32 result
= SCI_SUCCESS
;
827 switch (scu_get_event_code(event_code
)) {
828 case SCU_EVENT_LINK_FAILURE
:
829 /* Link failure change state back to the starting state */
830 scic_sds_phy_restart_starting_state(sci_phy
);
834 dev_warn(sciphy_to_dev(sci_phy
),
835 "%s: PHY starting substate machine received unexpected "
840 result
= SCI_FAILURE
;
849 * @phy: This struct scic_sds_phy object which has received an event.
850 * @event_code: This is the event code which the phy object is to decode.
852 * This method is called when an event notification is received for the phy
853 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. -
854 * decode the event - link failure events restart the starting state machine -
855 * sata spinup hold events are ignored since they are expected - any other
856 * events log a warning message and set a failure status enum sci_status SCI_SUCCESS
857 * on a link failure event SCI_FAILURE on any unexpected event notifation
859 static enum sci_status
scic_sds_phy_starting_substate_await_sata_power_event_handler(
860 struct scic_sds_phy
*sci_phy
,
863 u32 result
= SCI_SUCCESS
;
865 switch (scu_get_event_code(event_code
)) {
866 case SCU_EVENT_LINK_FAILURE
:
867 /* Link failure change state back to the starting state */
868 scic_sds_phy_restart_starting_state(sci_phy
);
871 case SCU_EVENT_SATA_SPINUP_HOLD
:
872 /* These events are received every 10ms and are expected while in this state */
875 case SCU_EVENT_SAS_PHY_DETECTED
:
877 * There has been a change in the phy type before OOB/SN for the
878 * SATA finished start down the SAS link traning path. */
879 scic_sds_phy_start_sas_link_training(sci_phy
);
883 dev_warn(sciphy_to_dev(sci_phy
),
884 "%s: PHY starting substate machine received "
885 "unexpected event_code %x\n",
889 result
= SCI_FAILURE
;
897 * scic_sds_phy_starting_substate_await_sata_phy_event_handler -
898 * @phy: This struct scic_sds_phy object which has received an event.
899 * @event_code: This is the event code which the phy object is to decode.
901 * This method is called when an event notification is received for the phy
902 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. -
903 * decode the event - link failure events restart the starting state machine -
904 * sata spinup hold events are ignored since they are expected - sata phy
905 * detected event change to the wait speed event - any other events log a
906 * warning message and set a failure status enum sci_status SCI_SUCCESS on a link
907 * failure event SCI_FAILURE on any unexpected event notifation
909 static enum sci_status
scic_sds_phy_starting_substate_await_sata_phy_event_handler(
910 struct scic_sds_phy
*sci_phy
, u32 event_code
)
912 u32 result
= SCI_SUCCESS
;
914 switch (scu_get_event_code(event_code
)) {
915 case SCU_EVENT_LINK_FAILURE
:
916 /* Link failure change state back to the starting state */
917 scic_sds_phy_restart_starting_state(sci_phy
);
920 case SCU_EVENT_SATA_SPINUP_HOLD
:
921 /* These events might be received since we dont know how many may be in
922 * the completion queue while waiting for power
926 case SCU_EVENT_SATA_PHY_DETECTED
:
927 sci_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_SATA
;
929 /* We have received the SATA PHY notification change state */
930 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
931 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
);
934 case SCU_EVENT_SAS_PHY_DETECTED
:
935 /* There has been a change in the phy type before OOB/SN for the
936 * SATA finished start down the SAS link traning path.
938 scic_sds_phy_start_sas_link_training(sci_phy
);
942 dev_warn(sciphy_to_dev(sci_phy
),
943 "%s: PHY starting substate machine received "
944 "unexpected event_code %x\n",
948 result
= SCI_FAILURE
;
957 * @phy: This struct scic_sds_phy object which has received an event.
958 * @event_code: This is the event code which the phy object is to decode.
960 * This method is called when an event notification is received for the phy
961 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN.
962 * - decode the event - sata phy detected returns us back to this state. -
963 * speed event detected causes a state transition to the wait for signature. -
964 * link failure events restart the starting state machine - any other events
965 * log a warning message and set a failure status enum sci_status SCI_SUCCESS on any
966 * valid event notification SCI_FAILURE on any unexpected event notifation
968 static enum sci_status
scic_sds_phy_starting_substate_await_sata_speed_event_handler(
969 struct scic_sds_phy
*sci_phy
,
972 u32 result
= SCI_SUCCESS
;
974 switch (scu_get_event_code(event_code
)) {
975 case SCU_EVENT_SATA_PHY_DETECTED
:
977 * The hardware reports multiple SATA PHY detected events
978 * ignore the extras */
981 case SCU_EVENT_SATA_15
:
982 case SCU_EVENT_SATA_15_SSC
:
983 scic_sds_phy_complete_link_training(
985 SAS_LINK_RATE_1_5_GBPS
,
986 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
);
989 case SCU_EVENT_SATA_30
:
990 case SCU_EVENT_SATA_30_SSC
:
991 scic_sds_phy_complete_link_training(
993 SAS_LINK_RATE_3_0_GBPS
,
994 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
);
997 case SCU_EVENT_SATA_60
:
998 case SCU_EVENT_SATA_60_SSC
:
999 scic_sds_phy_complete_link_training(
1001 SAS_LINK_RATE_6_0_GBPS
,
1002 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
);
1005 case SCU_EVENT_LINK_FAILURE
:
1006 /* Link failure change state back to the starting state */
1007 scic_sds_phy_restart_starting_state(sci_phy
);
1010 case SCU_EVENT_SAS_PHY_DETECTED
:
1012 * There has been a change in the phy type before OOB/SN for the
1013 * SATA finished start down the SAS link traning path. */
1014 scic_sds_phy_start_sas_link_training(sci_phy
);
1018 dev_warn(sciphy_to_dev(sci_phy
),
1019 "%s: PHY starting substate machine received "
1020 "unexpected event_code %x\n",
1024 result
= SCI_FAILURE
;
1032 * scic_sds_phy_starting_substate_await_sig_fis_event_handler -
1033 * @phy: This struct scic_sds_phy object which has received an event.
1034 * @event_code: This is the event code which the phy object is to decode.
1036 * This method is called when an event notification is received for the phy
1037 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. -
1038 * decode the event - sas phy detected event backs up the state machine to the
1039 * await speed notification. - identify timeout is an un-expected event and the
1040 * state machine is restarted. - link failure events restart the starting state
1041 * machine - any other events log a warning message and set a failure status
1042 * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any
1043 * unexpected event notifation
1045 static enum sci_status
scic_sds_phy_starting_substate_await_sig_fis_event_handler(
1046 struct scic_sds_phy
*sci_phy
, u32 event_code
)
1048 u32 result
= SCI_SUCCESS
;
1050 switch (scu_get_event_code(event_code
)) {
1051 case SCU_EVENT_SATA_PHY_DETECTED
:
1052 /* Backup the state machine */
1053 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1054 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
);
1057 case SCU_EVENT_LINK_FAILURE
:
1058 /* Link failure change state back to the starting state */
1059 scic_sds_phy_restart_starting_state(sci_phy
);
1063 dev_warn(sciphy_to_dev(sci_phy
),
1064 "%s: PHY starting substate machine received "
1065 "unexpected event_code %x\n",
1069 result
= SCI_FAILURE
;
1078 * *****************************************************************************
1079 * * SCIC SDS PHY FRAME_HANDLERS
1080 * ***************************************************************************** */
1084 * @phy: This is struct scic_sds_phy object which is being requested to decode the
1086 * @frame_index: This is the index of the unsolicited frame which was received
1089 * This method decodes the unsolicited frame when the struct scic_sds_phy is in the
1090 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - Get the UF Header - If the UF
1091 * is an IAF - Copy IAF data to local phy object IAF data buffer. - Change
1092 * starting substate to wait power. - else - log warning message of unexpected
1093 * unsolicted frame - release frame buffer enum sci_status SCI_SUCCESS
1095 static enum sci_status
scic_sds_phy_starting_substate_await_iaf_uf_frame_handler(
1096 struct scic_sds_phy
*sci_phy
, u32 frame_index
)
1098 enum sci_status result
;
1100 struct sas_identify_frame iaf
;
1101 struct isci_phy
*iphy
= sci_phy_to_iphy(sci_phy
);
1103 result
= scic_sds_unsolicited_frame_control_get_header(
1104 &(scic_sds_phy_get_controller(sci_phy
)->uf_control
),
1106 (void **)&frame_words
);
1108 if (result
!= SCI_SUCCESS
)
1111 sci_swab32_cpy(&iaf
, frame_words
, sizeof(iaf
) / sizeof(u32
));
1112 if (iaf
.frame_type
== 0) {
1115 memcpy(&iphy
->frame_rcvd
.iaf
, &iaf
, sizeof(iaf
));
1116 if (iaf
.smp_tport
) {
1117 /* We got the IAF for an expander PHY go to the final
1118 * state since there are no power requirements for
1121 state
= SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
;
1123 /* We got the IAF we can now go to the await spinup
1126 state
= SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
;
1128 sci_base_state_machine_change_state(
1129 &sci_phy
->starting_substate_machine
,
1131 result
= SCI_SUCCESS
;
1133 dev_warn(sciphy_to_dev(sci_phy
),
1134 "%s: PHY starting substate machine received "
1135 "unexpected frame id %x\n",
1139 scic_sds_controller_release_frame(scic_sds_phy_get_controller(sci_phy
),
1147 * @phy: This is struct scic_sds_phy object which is being requested to decode the
1149 * @frame_index: This is the index of the unsolicited frame which was received
1152 * This method decodes the unsolicited frame when the struct scic_sds_phy is in the
1153 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Get the UF Header - If
1154 * the UF is an SIGNATURE FIS - Copy IAF data to local phy object SIGNATURE FIS
1155 * data buffer. - else - log warning message of unexpected unsolicted frame -
1156 * release frame buffer enum sci_status SCI_SUCCESS Must decode the SIGNATURE FIS
1159 static enum sci_status
scic_sds_phy_starting_substate_await_sig_fis_frame_handler(
1160 struct scic_sds_phy
*sci_phy
,
1163 enum sci_status result
;
1164 struct dev_to_host_fis
*frame_header
;
1165 u32
*fis_frame_data
;
1166 struct isci_phy
*iphy
= sci_phy_to_iphy(sci_phy
);
1168 result
= scic_sds_unsolicited_frame_control_get_header(
1169 &(scic_sds_phy_get_controller(sci_phy
)->uf_control
),
1171 (void **)&frame_header
);
1173 if (result
!= SCI_SUCCESS
)
1176 if ((frame_header
->fis_type
== FIS_REGD2H
) &&
1177 !(frame_header
->status
& ATA_BUSY
)) {
1178 scic_sds_unsolicited_frame_control_get_buffer(
1179 &(scic_sds_phy_get_controller(sci_phy
)->uf_control
),
1181 (void **)&fis_frame_data
);
1183 scic_sds_controller_copy_sata_response(&iphy
->frame_rcvd
.fis
,
1187 /* got IAF we can now go to the await spinup semaphore state */
1188 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1189 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
);
1191 result
= SCI_SUCCESS
;
1193 dev_warn(sciphy_to_dev(sci_phy
),
1194 "%s: PHY starting substate machine received "
1195 "unexpected frame id %x\n",
1199 /* Regardless of the result we are done with this frame with it */
1200 scic_sds_controller_release_frame(scic_sds_phy_get_controller(sci_phy
),
1207 * *****************************************************************************
1208 * * SCIC SDS PHY POWER_HANDLERS
1209 * ***************************************************************************** */
1212 * This method is called by the struct scic_sds_controller when the phy object is
1213 * granted power. - The notify enable spinups are turned on for this phy object
1214 * - The phy state machine is transitioned to the
1215 * SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. enum sci_status SCI_SUCCESS
1217 static enum sci_status
scic_sds_phy_starting_substate_await_sas_power_consume_power_handler(
1218 struct scic_sds_phy
*sci_phy
)
1222 enable_spinup
= readl(&sci_phy
->link_layer_registers
->notify_enable_spinup_control
);
1223 enable_spinup
|= SCU_ENSPINUP_GEN_BIT(ENABLE
);
1224 writel(enable_spinup
, &sci_phy
->link_layer_registers
->notify_enable_spinup_control
);
1226 /* Change state to the final state this substate machine has run to completion */
1227 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1228 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
);
1234 * This method is called by the struct scic_sds_controller when the phy object is
1235 * granted power. - The phy state machine is transitioned to the
1236 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. enum sci_status SCI_SUCCESS
1238 static enum sci_status
scic_sds_phy_starting_substate_await_sata_power_consume_power_handler(
1239 struct scic_sds_phy
*sci_phy
)
1241 u32 scu_sas_pcfg_value
;
1243 /* Release the spinup hold state and reset the OOB state machine */
1244 scu_sas_pcfg_value
=
1245 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
1246 scu_sas_pcfg_value
&=
1247 ~(SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD
) | SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE
));
1248 scu_sas_pcfg_value
|= SCU_SAS_PCFG_GEN_BIT(OOB_RESET
);
1249 writel(scu_sas_pcfg_value
,
1250 &sci_phy
->link_layer_registers
->phy_configuration
);
1252 /* Now restart the OOB operation */
1253 scu_sas_pcfg_value
&= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET
);
1254 scu_sas_pcfg_value
|= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE
);
1255 writel(scu_sas_pcfg_value
,
1256 &sci_phy
->link_layer_registers
->phy_configuration
);
1258 /* Change state to the final state this substate machine has run to completion */
1259 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1260 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN
);
1265 static enum sci_status
default_phy_handler(struct scic_sds_phy
*sci_phy
,
1268 dev_dbg(sciphy_to_dev(sci_phy
),
1269 "%s: in wrong state: %d\n", func
,
1270 sci_base_state_machine_get_state(&sci_phy
->state_machine
));
1271 return SCI_FAILURE_INVALID_STATE
;
1274 static enum sci_status
1275 scic_sds_phy_default_start_handler(struct scic_sds_phy
*sci_phy
)
1277 return default_phy_handler(sci_phy
, __func__
);
1280 static enum sci_status
1281 scic_sds_phy_default_stop_handler(struct scic_sds_phy
*sci_phy
)
1283 return default_phy_handler(sci_phy
, __func__
);
1286 static enum sci_status
1287 scic_sds_phy_default_reset_handler(struct scic_sds_phy
*sci_phy
)
1289 return default_phy_handler(sci_phy
, __func__
);
1292 static enum sci_status
1293 scic_sds_phy_default_destroy_handler(struct scic_sds_phy
*sci_phy
)
1295 return default_phy_handler(sci_phy
, __func__
);
1298 static enum sci_status
1299 scic_sds_phy_default_frame_handler(struct scic_sds_phy
*sci_phy
,
1302 struct scic_sds_controller
*scic
= scic_sds_phy_get_controller(sci_phy
);
1304 default_phy_handler(sci_phy
, __func__
);
1305 scic_sds_controller_release_frame(scic
, frame_index
);
1307 return SCI_FAILURE_INVALID_STATE
;
1310 static enum sci_status
1311 scic_sds_phy_default_event_handler(struct scic_sds_phy
*sci_phy
,
1314 return default_phy_handler(sci_phy
, __func__
);
1317 static enum sci_status
1318 scic_sds_phy_default_consume_power_handler(struct scic_sds_phy
*sci_phy
)
1320 return default_phy_handler(sci_phy
, __func__
);
1325 static const struct scic_sds_phy_state_handler scic_sds_phy_starting_substate_handler_table
[] = {
1326 [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL
] = {
1327 .start_handler
= scic_sds_phy_default_start_handler
,
1328 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1329 .reset_handler
= scic_sds_phy_default_reset_handler
,
1330 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1331 .frame_handler
= scic_sds_phy_default_frame_handler
,
1332 .event_handler
= scic_sds_phy_default_event_handler
,
1333 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1335 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
] = {
1336 .start_handler
= scic_sds_phy_default_start_handler
,
1337 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1338 .reset_handler
= scic_sds_phy_default_reset_handler
,
1339 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1340 .frame_handler
= scic_sds_phy_default_frame_handler
,
1341 .event_handler
= scic_sds_phy_starting_substate_await_ossp_event_handler
,
1342 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1344 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
] = {
1345 .start_handler
= scic_sds_phy_default_start_handler
,
1346 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1347 .reset_handler
= scic_sds_phy_default_reset_handler
,
1348 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1349 .frame_handler
= scic_sds_phy_default_frame_handler
,
1350 .event_handler
= scic_sds_phy_starting_substate_await_sas_phy_speed_event_handler
,
1351 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1353 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
] = {
1354 .start_handler
= scic_sds_phy_default_start_handler
,
1355 .stop_handler
= scic_sds_phy_default_stop_handler
,
1356 .reset_handler
= scic_sds_phy_default_reset_handler
,
1357 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1358 .frame_handler
= scic_sds_phy_starting_substate_await_iaf_uf_frame_handler
,
1359 .event_handler
= scic_sds_phy_starting_substate_await_iaf_uf_event_handler
,
1360 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1362 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
] = {
1363 .start_handler
= scic_sds_phy_default_start_handler
,
1364 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1365 .reset_handler
= scic_sds_phy_default_reset_handler
,
1366 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1367 .frame_handler
= scic_sds_phy_default_frame_handler
,
1368 .event_handler
= scic_sds_phy_starting_substate_await_sas_power_event_handler
,
1369 .consume_power_handler
= scic_sds_phy_starting_substate_await_sas_power_consume_power_handler
1371 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
] = {
1372 .start_handler
= scic_sds_phy_default_start_handler
,
1373 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1374 .reset_handler
= scic_sds_phy_default_reset_handler
,
1375 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1376 .frame_handler
= scic_sds_phy_default_frame_handler
,
1377 .event_handler
= scic_sds_phy_starting_substate_await_sata_power_event_handler
,
1378 .consume_power_handler
= scic_sds_phy_starting_substate_await_sata_power_consume_power_handler
1380 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN
] = {
1381 .start_handler
= scic_sds_phy_default_start_handler
,
1382 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1383 .reset_handler
= scic_sds_phy_default_reset_handler
,
1384 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1385 .frame_handler
= scic_sds_phy_default_frame_handler
,
1386 .event_handler
= scic_sds_phy_starting_substate_await_sata_phy_event_handler
,
1387 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1389 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
] = {
1390 .start_handler
= scic_sds_phy_default_start_handler
,
1391 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1392 .reset_handler
= scic_sds_phy_default_reset_handler
,
1393 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1394 .frame_handler
= scic_sds_phy_default_frame_handler
,
1395 .event_handler
= scic_sds_phy_starting_substate_await_sata_speed_event_handler
,
1396 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1398 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
] = {
1399 .start_handler
= scic_sds_phy_default_start_handler
,
1400 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1401 .reset_handler
= scic_sds_phy_default_reset_handler
,
1402 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1403 .frame_handler
= scic_sds_phy_starting_substate_await_sig_fis_frame_handler
,
1404 .event_handler
= scic_sds_phy_starting_substate_await_sig_fis_event_handler
,
1405 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1407 [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
] = {
1408 .start_handler
= scic_sds_phy_default_start_handler
,
1409 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1410 .reset_handler
= scic_sds_phy_default_reset_handler
,
1411 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1412 .frame_handler
= scic_sds_phy_default_frame_handler
,
1413 .event_handler
= scic_sds_phy_default_event_handler
,
1414 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1419 * scic_sds_phy_set_starting_substate_handlers() -
1421 * This macro sets the starting substate handlers by state_id
1423 #define scic_sds_phy_set_starting_substate_handlers(phy, state_id) \
1424 scic_sds_phy_set_state_handlers(\
1426 &scic_sds_phy_starting_substate_handler_table[(state_id)] \
1430 * ****************************************************************************
1431 * * PHY STARTING SUBSTATE METHODS
1432 * **************************************************************************** */
1435 * scic_sds_phy_starting_initial_substate_enter -
1436 * @object: This is the object which is cast to a struct scic_sds_phy object.
1438 * This method will perform the actions required by the struct scic_sds_phy on
1439 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL. - The initial state
1440 * handlers are put in place for the struct scic_sds_phy object. - The state is
1441 * changed to the wait phy type event notification. none
1443 static void scic_sds_phy_starting_initial_substate_enter(void *object
)
1445 struct scic_sds_phy
*sci_phy
= object
;
1447 scic_sds_phy_set_starting_substate_handlers(
1448 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL
);
1450 /* This is just an temporary state go off to the starting state */
1451 sci_base_state_machine_change_state(&sci_phy
->starting_substate_machine
,
1452 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
);
1457 * @object: This is the object which is cast to a struct scic_sds_phy object.
1459 * This method will perform the actions required by the struct scic_sds_phy on
1460 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_PHY_TYPE_EN. - Set the
1461 * struct scic_sds_phy object state handlers for this state. none
1463 static void scic_sds_phy_starting_await_ossp_en_substate_enter(void *object
)
1465 struct scic_sds_phy
*sci_phy
= object
;
1467 scic_sds_phy_set_starting_substate_handlers(
1468 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
1474 * @object: This is the object which is cast to a struct scic_sds_phy object.
1476 * This method will perform the actions required by the struct scic_sds_phy on
1477 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. - Set the
1478 * struct scic_sds_phy object state handlers for this state. none
1480 static void scic_sds_phy_starting_await_sas_speed_en_substate_enter(
1483 struct scic_sds_phy
*sci_phy
= object
;
1485 scic_sds_phy_set_starting_substate_handlers(
1486 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
1492 * @object: This is the object which is cast to a struct scic_sds_phy object.
1494 * This method will perform the actions required by the struct scic_sds_phy on
1495 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - Set the
1496 * struct scic_sds_phy object state handlers for this state. none
1498 static void scic_sds_phy_starting_await_iaf_uf_substate_enter(void *object
)
1500 struct scic_sds_phy
*sci_phy
= object
;
1502 scic_sds_phy_set_starting_substate_handlers(
1503 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
1509 * @object: This is the object which is cast to a struct scic_sds_phy object.
1511 * This method will perform the actions required by the struct scic_sds_phy on
1512 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Set the
1513 * struct scic_sds_phy object state handlers for this state. - Add this phy object to
1514 * the power control queue none
1516 static void scic_sds_phy_starting_await_sas_power_substate_enter(void *object
)
1518 struct scic_sds_phy
*sci_phy
= object
;
1520 scic_sds_phy_set_starting_substate_handlers(
1521 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
1524 scic_sds_controller_power_control_queue_insert(
1525 scic_sds_phy_get_controller(sci_phy
),
1532 * @object: This is the object which is cast to a struct scic_sds_phy object.
1534 * This method will perform the actions required by the struct scic_sds_phy on exiting
1535 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Remove the
1536 * struct scic_sds_phy object from the power control queue. none
1538 static void scic_sds_phy_starting_await_sas_power_substate_exit(void *object
)
1540 struct scic_sds_phy
*sci_phy
= object
;
1542 scic_sds_controller_power_control_queue_remove(
1543 scic_sds_phy_get_controller(sci_phy
), sci_phy
1549 * @object: This is the object which is cast to a struct scic_sds_phy object.
1551 * This method will perform the actions required by the struct scic_sds_phy on
1552 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Set the
1553 * struct scic_sds_phy object state handlers for this state. - Add this phy object to
1554 * the power control queue none
1556 static void scic_sds_phy_starting_await_sata_power_substate_enter(void *object
)
1558 struct scic_sds_phy
*sci_phy
= object
;
1560 scic_sds_phy_set_starting_substate_handlers(
1561 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
1564 scic_sds_controller_power_control_queue_insert(
1565 scic_sds_phy_get_controller(sci_phy
),
1572 * @object: This is the object which is cast to a struct scic_sds_phy object.
1574 * This method will perform the actions required by the struct scic_sds_phy on exiting
1575 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Remove the
1576 * struct scic_sds_phy object from the power control queue. none
1578 static void scic_sds_phy_starting_await_sata_power_substate_exit(void *object
)
1580 struct scic_sds_phy
*sci_phy
= object
;
1582 scic_sds_controller_power_control_queue_remove(
1583 scic_sds_phy_get_controller(sci_phy
),
1590 * @object: This is the object which is cast to a struct scic_sds_phy object.
1592 * This function will perform the actions required by the struct scic_sds_phy on
1593 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. - Set the
1594 * struct scic_sds_phy object state handlers for this state. none
1596 static void scic_sds_phy_starting_await_sata_phy_substate_enter(void *object
)
1598 struct scic_sds_phy
*sci_phy
= object
;
1600 scic_sds_phy_set_starting_substate_handlers(
1602 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN
);
1604 isci_timer_start(sci_phy
->sata_timeout_timer
,
1605 SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT
);
1610 * @object: This is the object which is cast to a struct scic_sds_phy object.
1612 * This method will perform the actions required by the struct scic_sds_phy
1614 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
1615 * that was started on entry to await sata phy event notification none
1617 static inline void scic_sds_phy_starting_await_sata_phy_substate_exit(
1620 struct scic_sds_phy
*sci_phy
= object
;
1622 isci_timer_stop(sci_phy
->sata_timeout_timer
);
1627 * @object: This is the object which is cast to a struct scic_sds_phy object.
1629 * This method will perform the actions required by the struct scic_sds_phy on
1630 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - Set the
1631 * struct scic_sds_phy object state handlers for this state. none
1633 static void scic_sds_phy_starting_await_sata_speed_substate_enter(void *object
)
1635 struct scic_sds_phy
*sci_phy
= object
;
1637 scic_sds_phy_set_starting_substate_handlers(
1639 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
);
1641 isci_timer_start(sci_phy
->sata_timeout_timer
,
1642 SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT
);
1647 * @object: This is the object which is cast to a struct scic_sds_phy object.
1649 * This function will perform the actions required by the
1650 * struct scic_sds_phy on exiting
1651 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
1652 * that was started on entry to await sata phy event notification none
1654 static inline void scic_sds_phy_starting_await_sata_speed_substate_exit(
1657 struct scic_sds_phy
*sci_phy
= object
;
1659 isci_timer_stop(sci_phy
->sata_timeout_timer
);
1664 * @object: This is the object which is cast to a struct scic_sds_phy object.
1666 * This function will perform the actions required by the struct scic_sds_phy on
1667 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Set the
1668 * struct scic_sds_phy object state handlers for this state.
1669 * - Start the SIGNATURE FIS
1670 * timeout timer none
1672 static void scic_sds_phy_starting_await_sig_fis_uf_substate_enter(void *object
)
1674 bool continue_to_ready_state
;
1675 struct scic_sds_phy
*sci_phy
= object
;
1677 scic_sds_phy_set_starting_substate_handlers(
1679 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
);
1681 continue_to_ready_state
= scic_sds_port_link_detected(
1682 sci_phy
->owning_port
,
1685 if (continue_to_ready_state
) {
1687 * Clear the PE suspend condition so we can actually
1689 * The hardware will not respond to the XRDY until the PE
1690 * suspend condition is cleared.
1692 scic_sds_phy_resume(sci_phy
);
1694 isci_timer_start(sci_phy
->sata_timeout_timer
,
1695 SCIC_SDS_SIGNATURE_FIS_TIMEOUT
);
1697 sci_phy
->is_in_link_training
= false;
1702 * @object: This is the object which is cast to a struct scic_sds_phy object.
1704 * This function will perform the actions required by the
1705 * struct scic_sds_phy on exiting
1706 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Stop the SIGNATURE
1707 * FIS timeout timer. none
1709 static inline void scic_sds_phy_starting_await_sig_fis_uf_substate_exit(
1712 struct scic_sds_phy
*sci_phy
= object
;
1714 isci_timer_stop(sci_phy
->sata_timeout_timer
);
1719 * @object: This is the object which is cast to a struct scic_sds_phy object.
1721 * This method will perform the actions required by the struct scic_sds_phy on
1722 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. - Set the struct scic_sds_phy
1723 * object state handlers for this state. - Change base state machine to the
1726 static void scic_sds_phy_starting_final_substate_enter(void *object
)
1728 struct scic_sds_phy
*sci_phy
= object
;
1730 scic_sds_phy_set_starting_substate_handlers(sci_phy
,
1731 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
);
1733 /* State machine has run to completion so exit out and change
1734 * the base state machine to the ready state
1736 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1737 SCI_BASE_PHY_STATE_READY
);
1740 /* --------------------------------------------------------------------------- */
1742 static const struct sci_base_state scic_sds_phy_starting_substates
[] = {
1743 [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL
] = {
1744 .enter_state
= scic_sds_phy_starting_initial_substate_enter
,
1746 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
] = {
1747 .enter_state
= scic_sds_phy_starting_await_ossp_en_substate_enter
,
1749 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
] = {
1750 .enter_state
= scic_sds_phy_starting_await_sas_speed_en_substate_enter
,
1752 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
] = {
1753 .enter_state
= scic_sds_phy_starting_await_iaf_uf_substate_enter
,
1755 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
] = {
1756 .enter_state
= scic_sds_phy_starting_await_sas_power_substate_enter
,
1757 .exit_state
= scic_sds_phy_starting_await_sas_power_substate_exit
,
1759 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
] = {
1760 .enter_state
= scic_sds_phy_starting_await_sata_power_substate_enter
,
1761 .exit_state
= scic_sds_phy_starting_await_sata_power_substate_exit
1763 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN
] = {
1764 .enter_state
= scic_sds_phy_starting_await_sata_phy_substate_enter
,
1765 .exit_state
= scic_sds_phy_starting_await_sata_phy_substate_exit
1767 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
] = {
1768 .enter_state
= scic_sds_phy_starting_await_sata_speed_substate_enter
,
1769 .exit_state
= scic_sds_phy_starting_await_sata_speed_substate_exit
1771 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
] = {
1772 .enter_state
= scic_sds_phy_starting_await_sig_fis_uf_substate_enter
,
1773 .exit_state
= scic_sds_phy_starting_await_sig_fis_uf_substate_exit
1775 [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
] = {
1776 .enter_state
= scic_sds_phy_starting_final_substate_enter
,
1781 * This method takes the struct scic_sds_phy from a stopped state and
1782 * attempts to start it. - The phy state machine is transitioned to the
1783 * SCI_BASE_PHY_STATE_STARTING. enum sci_status SCI_SUCCESS
1785 static enum sci_status
1786 scic_sds_phy_stopped_state_start_handler(struct scic_sds_phy
*sci_phy
)
1788 struct isci_host
*ihost
;
1789 struct scic_sds_controller
*scic
;
1791 scic
= scic_sds_phy_get_controller(sci_phy
),
1792 ihost
= scic_to_ihost(scic
);
1794 /* Create the SIGNATURE FIS Timeout timer for this phy */
1795 sci_phy
->sata_timeout_timer
= isci_timer_create(ihost
, sci_phy
,
1796 scic_sds_phy_sata_timeout
);
1798 if (sci_phy
->sata_timeout_timer
)
1799 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1800 SCI_BASE_PHY_STATE_STARTING
);
1805 static enum sci_status
1806 scic_sds_phy_stopped_state_destroy_handler(struct scic_sds_phy
*sci_phy
)
1811 static enum sci_status
1812 scic_sds_phy_ready_state_stop_handler(struct scic_sds_phy
*sci_phy
)
1814 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1815 SCI_BASE_PHY_STATE_STOPPED
);
1820 static enum sci_status
1821 scic_sds_phy_ready_state_reset_handler(struct scic_sds_phy
*sci_phy
)
1823 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1824 SCI_BASE_PHY_STATE_RESETTING
);
1830 * scic_sds_phy_ready_state_event_handler -
1831 * @phy: This is the struct scic_sds_phy object which has received the event.
1833 * This method request the struct scic_sds_phy handle the received event. The only
1834 * event that we are interested in while in the ready state is the link failure
1835 * event. - decoded event is a link failure - transition the struct scic_sds_phy back
1836 * to the SCI_BASE_PHY_STATE_STARTING state. - any other event received will
1837 * report a warning message enum sci_status SCI_SUCCESS if the event received is a
1838 * link failure SCI_FAILURE_INVALID_STATE for any other event received.
1840 static enum sci_status
scic_sds_phy_ready_state_event_handler(struct scic_sds_phy
*sci_phy
,
1843 enum sci_status result
= SCI_FAILURE
;
1845 switch (scu_get_event_code(event_code
)) {
1846 case SCU_EVENT_LINK_FAILURE
:
1847 /* Link failure change state back to the starting state */
1848 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1849 SCI_BASE_PHY_STATE_STARTING
);
1850 result
= SCI_SUCCESS
;
1853 case SCU_EVENT_BROADCAST_CHANGE
:
1854 /* Broadcast change received. Notify the port. */
1855 if (scic_sds_phy_get_port(sci_phy
) != NULL
)
1856 scic_sds_port_broadcast_change_received(sci_phy
->owning_port
, sci_phy
);
1858 sci_phy
->bcn_received_while_port_unassigned
= true;
1862 dev_warn(sciphy_to_dev(sci_phy
),
1863 "%sP SCIC PHY 0x%p ready state machine received "
1864 "unexpected event_code %x\n",
1865 __func__
, sci_phy
, event_code
);
1867 result
= SCI_FAILURE_INVALID_STATE
;
1874 static enum sci_status
scic_sds_phy_resetting_state_event_handler(struct scic_sds_phy
*sci_phy
,
1877 enum sci_status result
= SCI_FAILURE
;
1879 switch (scu_get_event_code(event_code
)) {
1880 case SCU_EVENT_HARD_RESET_TRANSMITTED
:
1881 /* Link failure change state back to the starting state */
1882 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1883 SCI_BASE_PHY_STATE_STARTING
);
1884 result
= SCI_SUCCESS
;
1888 dev_warn(sciphy_to_dev(sci_phy
),
1889 "%s: SCIC PHY 0x%p resetting state machine received "
1890 "unexpected event_code %x\n",
1891 __func__
, sci_phy
, event_code
);
1893 result
= SCI_FAILURE_INVALID_STATE
;
1900 /* --------------------------------------------------------------------------- */
1902 static const struct scic_sds_phy_state_handler scic_sds_phy_state_handler_table
[] = {
1903 [SCI_BASE_PHY_STATE_INITIAL
] = {
1904 .start_handler
= scic_sds_phy_default_start_handler
,
1905 .stop_handler
= scic_sds_phy_default_stop_handler
,
1906 .reset_handler
= scic_sds_phy_default_reset_handler
,
1907 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1908 .frame_handler
= scic_sds_phy_default_frame_handler
,
1909 .event_handler
= scic_sds_phy_default_event_handler
,
1910 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1912 [SCI_BASE_PHY_STATE_STOPPED
] = {
1913 .start_handler
= scic_sds_phy_stopped_state_start_handler
,
1914 .stop_handler
= scic_sds_phy_default_stop_handler
,
1915 .reset_handler
= scic_sds_phy_default_reset_handler
,
1916 .destruct_handler
= scic_sds_phy_stopped_state_destroy_handler
,
1917 .frame_handler
= scic_sds_phy_default_frame_handler
,
1918 .event_handler
= scic_sds_phy_default_event_handler
,
1919 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1921 [SCI_BASE_PHY_STATE_STARTING
] = {
1922 .start_handler
= scic_sds_phy_default_start_handler
,
1923 .stop_handler
= scic_sds_phy_default_stop_handler
,
1924 .reset_handler
= scic_sds_phy_default_reset_handler
,
1925 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1926 .frame_handler
= scic_sds_phy_default_frame_handler
,
1927 .event_handler
= scic_sds_phy_default_event_handler
,
1928 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1930 [SCI_BASE_PHY_STATE_READY
] = {
1931 .start_handler
= scic_sds_phy_default_start_handler
,
1932 .stop_handler
= scic_sds_phy_ready_state_stop_handler
,
1933 .reset_handler
= scic_sds_phy_ready_state_reset_handler
,
1934 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1935 .frame_handler
= scic_sds_phy_default_frame_handler
,
1936 .event_handler
= scic_sds_phy_ready_state_event_handler
,
1937 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1939 [SCI_BASE_PHY_STATE_RESETTING
] = {
1940 .start_handler
= scic_sds_phy_default_start_handler
,
1941 .stop_handler
= scic_sds_phy_default_stop_handler
,
1942 .reset_handler
= scic_sds_phy_default_reset_handler
,
1943 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1944 .frame_handler
= scic_sds_phy_default_frame_handler
,
1945 .event_handler
= scic_sds_phy_resetting_state_event_handler
,
1946 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1948 [SCI_BASE_PHY_STATE_FINAL
] = {
1949 .start_handler
= scic_sds_phy_default_start_handler
,
1950 .stop_handler
= scic_sds_phy_default_stop_handler
,
1951 .reset_handler
= scic_sds_phy_default_reset_handler
,
1952 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1953 .frame_handler
= scic_sds_phy_default_frame_handler
,
1954 .event_handler
= scic_sds_phy_default_event_handler
,
1955 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1960 * ****************************************************************************
1961 * * PHY STATE PRIVATE METHODS
1962 * **************************************************************************** */
1966 * @sci_phy: This is the struct scic_sds_phy object to stop.
1968 * This method will stop the struct scic_sds_phy object. This does not reset the
1969 * protocol engine it just suspends it and places it in a state where it will
1970 * not cause the end device to power up. none
1972 static void scu_link_layer_stop_protocol_engine(
1973 struct scic_sds_phy
*sci_phy
)
1975 u32 scu_sas_pcfg_value
;
1976 u32 enable_spinup_value
;
1978 /* Suspend the protocol engine and place it in a sata spinup hold state */
1979 scu_sas_pcfg_value
=
1980 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
1981 scu_sas_pcfg_value
|=
1982 (SCU_SAS_PCFG_GEN_BIT(OOB_RESET
) |
1983 SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE
) |
1984 SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD
));
1985 writel(scu_sas_pcfg_value
,
1986 &sci_phy
->link_layer_registers
->phy_configuration
);
1988 /* Disable the notify enable spinup primitives */
1989 enable_spinup_value
= readl(&sci_phy
->link_layer_registers
->notify_enable_spinup_control
);
1990 enable_spinup_value
&= ~SCU_ENSPINUP_GEN_BIT(ENABLE
);
1991 writel(enable_spinup_value
, &sci_phy
->link_layer_registers
->notify_enable_spinup_control
);
1997 * This method will start the OOB/SN state machine for this struct scic_sds_phy object.
1999 static void scu_link_layer_start_oob(
2000 struct scic_sds_phy
*sci_phy
)
2002 u32 scu_sas_pcfg_value
;
2004 scu_sas_pcfg_value
=
2005 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
2006 scu_sas_pcfg_value
|= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE
);
2007 scu_sas_pcfg_value
&=
2008 ~(SCU_SAS_PCFG_GEN_BIT(OOB_RESET
) |
2009 SCU_SAS_PCFG_GEN_BIT(HARD_RESET
));
2010 writel(scu_sas_pcfg_value
,
2011 &sci_phy
->link_layer_registers
->phy_configuration
);
2017 * This method will transmit a hard reset request on the specified phy. The SCU
2018 * hardware requires that we reset the OOB state machine and set the hard reset
2019 * bit in the phy configuration register. We then must start OOB over with the
2020 * hard reset bit set.
2022 static void scu_link_layer_tx_hard_reset(
2023 struct scic_sds_phy
*sci_phy
)
2025 u32 phy_configuration_value
;
2028 * SAS Phys must wait for the HARD_RESET_TX event notification to transition
2029 * to the starting state. */
2030 phy_configuration_value
=
2031 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
2032 phy_configuration_value
|=
2033 (SCU_SAS_PCFG_GEN_BIT(HARD_RESET
) |
2034 SCU_SAS_PCFG_GEN_BIT(OOB_RESET
));
2035 writel(phy_configuration_value
,
2036 &sci_phy
->link_layer_registers
->phy_configuration
);
2038 /* Now take the OOB state machine out of reset */
2039 phy_configuration_value
|= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE
);
2040 phy_configuration_value
&= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET
);
2041 writel(phy_configuration_value
,
2042 &sci_phy
->link_layer_registers
->phy_configuration
);
2046 * ****************************************************************************
2047 * * PHY BASE STATE METHODS
2048 * **************************************************************************** */
2052 * @object: This is the object which is cast to a struct scic_sds_phy object.
2054 * This method will perform the actions required by the struct scic_sds_phy on
2055 * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
2056 * handlers for the phy object base state machine initial state. none
2058 static void scic_sds_phy_initial_state_enter(void *object
)
2060 struct scic_sds_phy
*sci_phy
= object
;
2062 scic_sds_phy_set_base_state_handlers(sci_phy
, SCI_BASE_PHY_STATE_INITIAL
);
2067 * @object: This is the object which is cast to a struct scic_sds_phy object.
2069 * This function will perform the actions required by the struct scic_sds_phy on
2070 * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
2071 * handlers for the phy object base state machine initial state. - The SCU
2072 * hardware is requested to stop the protocol engine. none
2074 static void scic_sds_phy_stopped_state_enter(void *object
)
2076 struct scic_sds_phy
*sci_phy
= object
;
2077 struct scic_sds_controller
*scic
= scic_sds_phy_get_controller(sci_phy
);
2078 struct isci_host
*ihost
= scic_to_ihost(scic
);
2081 * @todo We need to get to the controller to place this PE in a
2085 scic_sds_phy_set_base_state_handlers(sci_phy
,
2086 SCI_BASE_PHY_STATE_STOPPED
);
2088 if (sci_phy
->sata_timeout_timer
!= NULL
) {
2089 isci_del_timer(ihost
, sci_phy
->sata_timeout_timer
);
2091 sci_phy
->sata_timeout_timer
= NULL
;
2094 scu_link_layer_stop_protocol_engine(sci_phy
);
2096 if (sci_phy
->state_machine
.previous_state_id
!=
2097 SCI_BASE_PHY_STATE_INITIAL
)
2098 scic_sds_controller_link_down(
2099 scic_sds_phy_get_controller(sci_phy
),
2100 scic_sds_phy_get_port(sci_phy
),
2106 * @object: This is the object which is cast to a struct scic_sds_phy object.
2108 * This method will perform the actions required by the struct scic_sds_phy on
2109 * entering the SCI_BASE_PHY_STATE_STARTING. - This function sets the state
2110 * handlers for the phy object base state machine starting state. - The SCU
2111 * hardware is requested to start OOB/SN on this protocl engine. - The phy
2112 * starting substate machine is started. - If the previous state was the ready
2113 * state then the struct scic_sds_controller is informed that the phy has gone link
2116 static void scic_sds_phy_starting_state_enter(void *object
)
2118 struct scic_sds_phy
*sci_phy
= object
;
2120 scic_sds_phy_set_base_state_handlers(sci_phy
, SCI_BASE_PHY_STATE_STARTING
);
2122 scu_link_layer_stop_protocol_engine(sci_phy
);
2123 scu_link_layer_start_oob(sci_phy
);
2125 /* We don't know what kind of phy we are going to be just yet */
2126 sci_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_UNKNOWN
;
2127 sci_phy
->bcn_received_while_port_unassigned
= false;
2129 /* Change over to the starting substate machine to continue */
2130 sci_base_state_machine_start(&sci_phy
->starting_substate_machine
);
2132 if (sci_phy
->state_machine
.previous_state_id
2133 == SCI_BASE_PHY_STATE_READY
) {
2134 scic_sds_controller_link_down(
2135 scic_sds_phy_get_controller(sci_phy
),
2136 scic_sds_phy_get_port(sci_phy
),
2144 * @object: This is the object which is cast to a struct scic_sds_phy object.
2146 * This method will perform the actions required by the struct scic_sds_phy on
2147 * entering the SCI_BASE_PHY_STATE_READY. - This function sets the state
2148 * handlers for the phy object base state machine ready state. - The SCU
2149 * hardware protocol engine is resumed. - The struct scic_sds_controller is informed
2150 * that the phy object has gone link up. none
2152 static void scic_sds_phy_ready_state_enter(void *object
)
2154 struct scic_sds_phy
*sci_phy
= object
;
2156 scic_sds_phy_set_base_state_handlers(sci_phy
, SCI_BASE_PHY_STATE_READY
);
2158 scic_sds_controller_link_up(
2159 scic_sds_phy_get_controller(sci_phy
),
2160 scic_sds_phy_get_port(sci_phy
),
2167 * @object: This is the object which is cast to a struct scic_sds_phy object.
2169 * This method will perform the actions required by the struct scic_sds_phy on exiting
2170 * the SCI_BASE_PHY_STATE_INITIAL. This function suspends the SCU hardware
2171 * protocol engine represented by this struct scic_sds_phy object. none
2173 static void scic_sds_phy_ready_state_exit(void *object
)
2175 struct scic_sds_phy
*sci_phy
= object
;
2177 scic_sds_phy_suspend(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_RESETTING. - This function sets the state
2186 * handlers for the phy object base state machine resetting state. none
2188 static void scic_sds_phy_resetting_state_enter(void *object
)
2190 struct scic_sds_phy
*sci_phy
= object
;
2192 scic_sds_phy_set_base_state_handlers(sci_phy
, SCI_BASE_PHY_STATE_RESETTING
);
2195 * The phy is being reset, therefore deactivate it from the port.
2196 * In the resetting state we don't notify the user regarding
2197 * link up and link down notifications. */
2198 scic_sds_port_deactivate_phy(sci_phy
->owning_port
, sci_phy
, false);
2200 if (sci_phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SAS
) {
2201 scu_link_layer_tx_hard_reset(sci_phy
);
2204 * The SCU does not need to have a discrete reset state so
2205 * just go back to the starting state.
2207 sci_base_state_machine_change_state(
2208 &sci_phy
->state_machine
,
2209 SCI_BASE_PHY_STATE_STARTING
);
2215 * @object: This is the object which is cast to a struct scic_sds_phy object.
2217 * This method will perform the actions required by the struct scic_sds_phy on
2218 * entering the SCI_BASE_PHY_STATE_FINAL. - This function sets the state
2219 * handlers for the phy object base state machine final state. none
2221 static void scic_sds_phy_final_state_enter(void *object
)
2223 struct scic_sds_phy
*sci_phy
= object
;
2225 scic_sds_phy_set_base_state_handlers(sci_phy
, SCI_BASE_PHY_STATE_FINAL
);
2227 /* Nothing to do here */
2230 /* --------------------------------------------------------------------------- */
2232 static const struct sci_base_state scic_sds_phy_state_table
[] = {
2233 [SCI_BASE_PHY_STATE_INITIAL
] = {
2234 .enter_state
= scic_sds_phy_initial_state_enter
,
2236 [SCI_BASE_PHY_STATE_STOPPED
] = {
2237 .enter_state
= scic_sds_phy_stopped_state_enter
,
2239 [SCI_BASE_PHY_STATE_STARTING
] = {
2240 .enter_state
= scic_sds_phy_starting_state_enter
,
2242 [SCI_BASE_PHY_STATE_READY
] = {
2243 .enter_state
= scic_sds_phy_ready_state_enter
,
2244 .exit_state
= scic_sds_phy_ready_state_exit
,
2246 [SCI_BASE_PHY_STATE_RESETTING
] = {
2247 .enter_state
= scic_sds_phy_resetting_state_enter
,
2249 [SCI_BASE_PHY_STATE_FINAL
] = {
2250 .enter_state
= scic_sds_phy_final_state_enter
,
2254 void scic_sds_phy_construct(struct scic_sds_phy
*sci_phy
,
2255 struct scic_sds_port
*owning_port
, u8 phy_index
)
2257 sci_base_state_machine_construct(&sci_phy
->state_machine
,
2259 scic_sds_phy_state_table
,
2260 SCI_BASE_PHY_STATE_INITIAL
);
2262 sci_base_state_machine_start(&sci_phy
->state_machine
);
2264 /* Copy the rest of the input data to our locals */
2265 sci_phy
->owning_port
= owning_port
;
2266 sci_phy
->phy_index
= phy_index
;
2267 sci_phy
->bcn_received_while_port_unassigned
= false;
2268 sci_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_UNKNOWN
;
2269 sci_phy
->link_layer_registers
= NULL
;
2270 sci_phy
->max_negotiated_speed
= SAS_LINK_RATE_UNKNOWN
;
2271 sci_phy
->sata_timeout_timer
= NULL
;
2273 /* Initialize the the substate machines */
2274 sci_base_state_machine_construct(&sci_phy
->starting_substate_machine
,
2276 scic_sds_phy_starting_substates
,
2277 SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL
);