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 "scu_event_codes.h"
61 #include "probe_roms.h"
63 /* Maximum arbitration wait time in micro-seconds */
64 #define SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME (700)
66 enum sas_linkrate
sci_phy_linkrate(struct scic_sds_phy
*sci_phy
)
68 return sci_phy
->max_negotiated_speed
;
72 * *****************************************************************************
73 * * SCIC SDS PHY Internal Methods
74 * ***************************************************************************** */
77 * This method will initialize the phy transport layer registers
79 * @transport_layer_registers
83 static enum sci_status
scic_sds_phy_transport_layer_initialization(
84 struct scic_sds_phy
*sci_phy
,
85 struct scu_transport_layer_registers __iomem
*transport_layer_registers
)
89 sci_phy
->transport_layer_registers
= transport_layer_registers
;
91 writel(SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
,
92 &sci_phy
->transport_layer_registers
->stp_rni
);
95 * Hardware team recommends that we enable the STP prefetch for all
98 tl_control
= readl(&sci_phy
->transport_layer_registers
->control
);
99 tl_control
|= SCU_TLCR_GEN_BIT(STP_WRITE_DATA_PREFETCH
);
100 writel(tl_control
, &sci_phy
->transport_layer_registers
->control
);
106 * This method will initialize the phy link layer registers
108 * @link_layer_registers:
112 static enum sci_status
113 scic_sds_phy_link_layer_initialization(struct scic_sds_phy
*sci_phy
,
114 struct scu_link_layer_registers __iomem
*link_layer_registers
)
116 struct scic_sds_controller
*scic
=
117 sci_phy
->owning_port
->owning_controller
;
118 int phy_idx
= sci_phy
->phy_index
;
119 struct sci_phy_user_params
*phy_user
=
120 &scic
->user_parameters
.sds1
.phys
[phy_idx
];
121 struct sci_phy_oem_params
*phy_oem
=
122 &scic
->oem_parameters
.sds1
.phys
[phy_idx
];
123 u32 phy_configuration
;
124 struct scic_phy_cap phy_cap
;
125 u32 parity_check
= 0;
126 u32 parity_count
= 0;
127 u32 llctl
, link_rate
;
130 sci_phy
->link_layer_registers
= link_layer_registers
;
132 /* Set our IDENTIFY frame data */
133 #define SCI_END_DEVICE 0x01
135 writel(SCU_SAS_TIID_GEN_BIT(SMP_INITIATOR
) |
136 SCU_SAS_TIID_GEN_BIT(SSP_INITIATOR
) |
137 SCU_SAS_TIID_GEN_BIT(STP_INITIATOR
) |
138 SCU_SAS_TIID_GEN_BIT(DA_SATA_HOST
) |
139 SCU_SAS_TIID_GEN_VAL(DEVICE_TYPE
, SCI_END_DEVICE
),
140 &sci_phy
->link_layer_registers
->transmit_identification
);
142 /* Write the device SAS Address */
144 &sci_phy
->link_layer_registers
->sas_device_name_high
);
145 writel(phy_idx
, &sci_phy
->link_layer_registers
->sas_device_name_low
);
147 /* Write the source SAS Address */
148 writel(phy_oem
->sas_address
.high
,
149 &sci_phy
->link_layer_registers
->source_sas_address_high
);
150 writel(phy_oem
->sas_address
.low
,
151 &sci_phy
->link_layer_registers
->source_sas_address_low
);
153 /* Clear and Set the PHY Identifier */
154 writel(0, &sci_phy
->link_layer_registers
->identify_frame_phy_id
);
155 writel(SCU_SAS_TIPID_GEN_VALUE(ID
, phy_idx
),
156 &sci_phy
->link_layer_registers
->identify_frame_phy_id
);
158 /* Change the initial state of the phy configuration register */
160 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
162 /* Hold OOB state machine in reset */
163 phy_configuration
|= SCU_SAS_PCFG_GEN_BIT(OOB_RESET
);
164 writel(phy_configuration
,
165 &sci_phy
->link_layer_registers
->phy_configuration
);
167 /* Configure the SNW capabilities */
170 phy_cap
.gen3_no_ssc
= 1;
171 phy_cap
.gen2_no_ssc
= 1;
172 phy_cap
.gen1_no_ssc
= 1;
173 if (scic
->oem_parameters
.sds1
.controller
.do_enable_ssc
== true) {
174 phy_cap
.gen3_ssc
= 1;
175 phy_cap
.gen2_ssc
= 1;
176 phy_cap
.gen1_ssc
= 1;
180 * The SAS specification indicates that the phy_capabilities that
181 * are transmitted shall have an even parity. Calculate the parity. */
182 parity_check
= phy_cap
.all
;
183 while (parity_check
!= 0) {
184 if (parity_check
& 0x1)
190 * If parity indicates there are an odd number of bits set, then
191 * set the parity bit to 1 in the phy capabilities. */
192 if ((parity_count
% 2) != 0)
195 writel(phy_cap
.all
, &sci_phy
->link_layer_registers
->phy_capabilities
);
197 /* Set the enable spinup period but disable the ability to send
198 * notify enable spinup
200 writel(SCU_ENSPINUP_GEN_VAL(COUNT
,
201 phy_user
->notify_enable_spin_up_insertion_frequency
),
202 &sci_phy
->link_layer_registers
->notify_enable_spinup_control
);
204 /* Write the ALIGN Insertion Ferequency for connected phy and
205 * inpendent of connected state
207 clksm_value
= SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(CONNECTED
,
208 phy_user
->in_connection_align_insertion_frequency
);
210 clksm_value
|= SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(GENERAL
,
211 phy_user
->align_insertion_frequency
);
213 writel(clksm_value
, &sci_phy
->link_layer_registers
->clock_skew_management
);
215 /* @todo Provide a way to write this register correctly */
217 &sci_phy
->link_layer_registers
->afe_lookup_table_control
);
219 llctl
= SCU_SAS_LLCTL_GEN_VAL(NO_OUTBOUND_TASK_TIMEOUT
,
220 (u8
)scic
->user_parameters
.sds1
.no_outbound_task_timeout
);
222 switch(phy_user
->max_speed_generation
) {
223 case SCIC_SDS_PARM_GEN3_SPEED
:
224 link_rate
= SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN3
;
226 case SCIC_SDS_PARM_GEN2_SPEED
:
227 link_rate
= SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN2
;
230 link_rate
= SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN1
;
233 llctl
|= SCU_SAS_LLCTL_GEN_VAL(MAX_LINK_RATE
, link_rate
);
234 writel(llctl
, &sci_phy
->link_layer_registers
->link_layer_control
);
236 if (is_a0() || is_a2()) {
237 /* Program the max ARB time for the PHY to 700us so we inter-operate with
238 * the PMC expander which shuts down PHYs if the expander PHY generates too
239 * many breaks. This time value will guarantee that the initiator PHY will
240 * generate the break.
242 writel(SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME
,
243 &sci_phy
->link_layer_registers
->maximum_arbitration_wait_timer_timeout
);
247 * Set the link layer hang detection to 500ms (0x1F4) from its default
248 * value of 128ms. Max value is 511 ms.
250 writel(0x1F4, &sci_phy
->link_layer_registers
->link_layer_hang_detection_timeout
);
252 /* We can exit the initial state to the stopped state */
253 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
254 SCI_BASE_PHY_STATE_STOPPED
);
260 * This function will handle the sata SIGNATURE FIS timeout condition. It will
261 * restart the starting substate machine since we dont know what has actually
264 static void scic_sds_phy_sata_timeout(void *phy
)
266 struct scic_sds_phy
*sci_phy
= phy
;
268 dev_dbg(sciphy_to_dev(sci_phy
),
269 "%s: SCIC SDS Phy 0x%p did not receive signature fis before "
274 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
275 SCI_BASE_PHY_STATE_STARTING
);
279 * This method returns the port currently containing this phy. If the phy is
280 * currently contained by the dummy port, then the phy is considered to not
282 * @sci_phy: This parameter specifies the phy for which to retrieve the
285 * This method returns a handle to a port that contains the supplied phy.
286 * NULL This value is returned if the phy is not part of a real
287 * port (i.e. it's contained in the dummy port). !NULL All other
288 * values indicate a handle/pointer to the port containing the phy.
290 struct scic_sds_port
*scic_sds_phy_get_port(
291 struct scic_sds_phy
*sci_phy
)
293 if (scic_sds_port_get_index(sci_phy
->owning_port
) == SCIC_SDS_DUMMY_PORT
)
296 return sci_phy
->owning_port
;
300 * This method will assign a port to the phy object.
301 * @out]: sci_phy This parameter specifies the phy for which to assign a port
306 void scic_sds_phy_set_port(
307 struct scic_sds_phy
*sci_phy
,
308 struct scic_sds_port
*sci_port
)
310 sci_phy
->owning_port
= sci_port
;
312 if (sci_phy
->bcn_received_while_port_unassigned
) {
313 sci_phy
->bcn_received_while_port_unassigned
= false;
314 scic_sds_port_broadcast_change_received(sci_phy
->owning_port
, sci_phy
);
319 * This method will initialize the constructed phy
321 * @link_layer_registers:
325 enum sci_status
scic_sds_phy_initialize(
326 struct scic_sds_phy
*sci_phy
,
327 struct scu_transport_layer_registers __iomem
*transport_layer_registers
,
328 struct scu_link_layer_registers __iomem
*link_layer_registers
)
330 struct scic_sds_controller
*scic
= scic_sds_phy_get_controller(sci_phy
);
331 struct isci_host
*ihost
= scic_to_ihost(scic
);
333 /* Create the SIGNATURE FIS Timeout timer for this phy */
334 sci_phy
->sata_timeout_timer
=
338 scic_sds_phy_sata_timeout
);
340 /* Perfrom the initialization of the TL hardware */
341 scic_sds_phy_transport_layer_initialization(
343 transport_layer_registers
);
345 /* Perofrm the initialization of the PE hardware */
346 scic_sds_phy_link_layer_initialization(sci_phy
, link_layer_registers
);
349 * There is nothing that needs to be done in this state just
350 * transition to the stopped state. */
351 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
352 SCI_BASE_PHY_STATE_STOPPED
);
358 * This method assigns the direct attached device ID for this phy.
360 * @sci_phy The phy for which the direct attached device id is to
362 * @device_id The direct attached device ID to assign to the phy.
363 * This will either be the RNi for the device or an invalid RNi if there
364 * is no current device assigned to the phy.
366 void scic_sds_phy_setup_transport(
367 struct scic_sds_phy
*sci_phy
,
372 writel(device_id
, &sci_phy
->transport_layer_registers
->stp_rni
);
375 * The read should guarantee that the first write gets posted
376 * before the next write
378 tl_control
= readl(&sci_phy
->transport_layer_registers
->control
);
379 tl_control
|= SCU_TLCR_GEN_BIT(CLEAR_TCI_NCQ_MAPPING_TABLE
);
380 writel(tl_control
, &sci_phy
->transport_layer_registers
->control
);
385 * @sci_phy: The phy object to be suspended.
387 * This function will perform the register reads/writes to suspend the SCU
388 * hardware protocol engine. none
390 static void scic_sds_phy_suspend(
391 struct scic_sds_phy
*sci_phy
)
393 u32 scu_sas_pcfg_value
;
396 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
397 scu_sas_pcfg_value
|= SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE
);
398 writel(scu_sas_pcfg_value
,
399 &sci_phy
->link_layer_registers
->phy_configuration
);
401 scic_sds_phy_setup_transport(
403 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
);
406 void scic_sds_phy_resume(struct scic_sds_phy
*sci_phy
)
408 u32 scu_sas_pcfg_value
;
411 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
412 scu_sas_pcfg_value
&= ~SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE
);
413 writel(scu_sas_pcfg_value
,
414 &sci_phy
->link_layer_registers
->phy_configuration
);
417 void scic_sds_phy_get_sas_address(struct scic_sds_phy
*sci_phy
,
418 struct sci_sas_address
*sas_address
)
420 sas_address
->high
= readl(&sci_phy
->link_layer_registers
->source_sas_address_high
);
421 sas_address
->low
= readl(&sci_phy
->link_layer_registers
->source_sas_address_low
);
424 void scic_sds_phy_get_attached_sas_address(struct scic_sds_phy
*sci_phy
,
425 struct sci_sas_address
*sas_address
)
427 struct sas_identify_frame
*iaf
;
428 struct isci_phy
*iphy
= sci_phy_to_iphy(sci_phy
);
430 iaf
= &iphy
->frame_rcvd
.iaf
;
431 memcpy(sas_address
, iaf
->sas_addr
, SAS_ADDR_SIZE
);
434 void scic_sds_phy_get_protocols(struct scic_sds_phy
*sci_phy
,
435 struct scic_phy_proto
*protocols
)
438 (u16
)(readl(&sci_phy
->
439 link_layer_registers
->transmit_identification
) &
444 * This method will attempt to start the phy object. This request is only valid
445 * when the phy is in the stopped state
450 enum sci_status
scic_sds_phy_start(struct scic_sds_phy
*sci_phy
)
452 return sci_phy
->state_handlers
->start_handler(sci_phy
);
456 * This method will attempt to stop the phy object.
459 * enum sci_status SCI_SUCCESS if the phy is going to stop SCI_INVALID_STATE
460 * if the phy is not in a valid state to stop
462 enum sci_status
scic_sds_phy_stop(struct scic_sds_phy
*sci_phy
)
464 return sci_phy
->state_handlers
->stop_handler(sci_phy
);
468 * This method will attempt to reset the phy. This request is only valid when
469 * the phy is in an ready state
474 enum sci_status
scic_sds_phy_reset(
475 struct scic_sds_phy
*sci_phy
)
477 return sci_phy
->state_handlers
->reset_handler(sci_phy
);
481 * This method will process the event code received.
487 enum sci_status
scic_sds_phy_event_handler(
488 struct scic_sds_phy
*sci_phy
,
491 return sci_phy
->state_handlers
->event_handler(sci_phy
, event_code
);
495 * This method will process the frame index received.
501 enum sci_status
scic_sds_phy_frame_handler(
502 struct scic_sds_phy
*sci_phy
,
505 return sci_phy
->state_handlers
->frame_handler(sci_phy
, frame_index
);
509 * This method will give the phy permission to consume power
514 enum sci_status
scic_sds_phy_consume_power_handler(
515 struct scic_sds_phy
*sci_phy
)
517 return sci_phy
->state_handlers
->consume_power_handler(sci_phy
);
521 * *****************************************************************************
522 * * SCIC SDS PHY HELPER FUNCTIONS
523 * ***************************************************************************** */
528 * @sci_phy: The phy object that received SAS PHY DETECTED.
530 * This method continues the link training for the phy as if it were a SAS PHY
531 * instead of a SATA PHY. This is done because the completion queue had a SAS
532 * PHY DETECTED event when the state machine was expecting a SATA PHY event.
535 static void scic_sds_phy_start_sas_link_training(
536 struct scic_sds_phy
*sci_phy
)
541 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
542 phy_control
|= SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD
);
544 &sci_phy
->link_layer_registers
->phy_configuration
);
546 sci_base_state_machine_change_state(
547 &sci_phy
->state_machine
,
548 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
551 sci_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_SAS
;
556 * @sci_phy: The phy object that received a SATA SPINUP HOLD event
558 * This method continues the link training for the phy as if it were a SATA PHY
559 * instead of a SAS PHY. This is done because the completion queue had a SATA
560 * SPINUP HOLD event when the state machine was expecting a SAS PHY event. none
562 static void scic_sds_phy_start_sata_link_training(
563 struct scic_sds_phy
*sci_phy
)
565 sci_base_state_machine_change_state(
566 &sci_phy
->state_machine
,
567 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
570 sci_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_SATA
;
574 * scic_sds_phy_complete_link_training - perform processing common to
575 * all protocols upon completion of link training.
576 * @sci_phy: This parameter specifies the phy object for which link training
578 * @max_link_rate: This parameter specifies the maximum link rate to be
579 * associated with this phy.
580 * @next_state: This parameter specifies the next state for the phy's starting
584 static void scic_sds_phy_complete_link_training(
585 struct scic_sds_phy
*sci_phy
,
586 enum sas_linkrate max_link_rate
,
589 sci_phy
->max_negotiated_speed
= max_link_rate
;
591 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
595 static void scic_sds_phy_restart_starting_state(
596 struct scic_sds_phy
*sci_phy
)
598 /* Re-enter the base state machine starting state */
599 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
600 SCI_BASE_PHY_STATE_STARTING
);
603 /* ****************************************************************************
604 * SCIC SDS PHY general handlers
605 ************************************************************************** */
606 static enum sci_status
scic_sds_phy_starting_substate_general_stop_handler(
607 struct scic_sds_phy
*phy
)
609 sci_base_state_machine_change_state(&phy
->state_machine
,
610 SCI_BASE_PHY_STATE_STOPPED
);
616 * *****************************************************************************
617 * * SCIC SDS PHY EVENT_HANDLERS
618 * ***************************************************************************** */
622 * @phy: This struct scic_sds_phy object which has received an event.
623 * @event_code: This is the event code which the phy object is to decode.
625 * This method is called when an event notification is received for the phy
626 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. -
627 * decode the event - sas phy detected causes a state transition to the wait
628 * for speed event notification. - any other events log a warning message and
629 * set a failure status enum sci_status SCI_SUCCESS on any valid event notification
630 * SCI_FAILURE on any unexpected event notifation
632 static enum sci_status
scic_sds_phy_starting_substate_await_ossp_event_handler(
633 struct scic_sds_phy
*sci_phy
,
636 u32 result
= SCI_SUCCESS
;
638 switch (scu_get_event_code(event_code
)) {
639 case SCU_EVENT_SAS_PHY_DETECTED
:
640 scic_sds_phy_start_sas_link_training(sci_phy
);
641 sci_phy
->is_in_link_training
= true;
644 case SCU_EVENT_SATA_SPINUP_HOLD
:
645 scic_sds_phy_start_sata_link_training(sci_phy
);
646 sci_phy
->is_in_link_training
= true;
650 dev_dbg(sciphy_to_dev(sci_phy
),
651 "%s: PHY starting substate machine received "
652 "unexpected event_code %x\n",
656 result
= SCI_FAILURE
;
665 * @phy: This struct scic_sds_phy object which has received an event.
666 * @event_code: This is the event code which the phy object is to decode.
668 * This method is called when an event notification is received for the phy
669 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. -
670 * decode the event - sas phy detected returns us back to this state. - speed
671 * event detected causes a state transition to the wait for iaf. - identify
672 * timeout is an un-expected event and the state machine is restarted. - link
673 * failure events restart the starting state machine - any other events log a
674 * warning message and set a failure status enum sci_status SCI_SUCCESS on any valid
675 * event notification SCI_FAILURE on any unexpected event notifation
677 static enum sci_status
scic_sds_phy_starting_substate_await_sas_phy_speed_event_handler(
678 struct scic_sds_phy
*sci_phy
,
681 u32 result
= SCI_SUCCESS
;
683 switch (scu_get_event_code(event_code
)) {
684 case SCU_EVENT_SAS_PHY_DETECTED
:
686 * Why is this being reported again by the controller?
687 * We would re-enter this state so just stay here */
690 case SCU_EVENT_SAS_15
:
691 case SCU_EVENT_SAS_15_SSC
:
692 scic_sds_phy_complete_link_training(
694 SAS_LINK_RATE_1_5_GBPS
,
695 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
);
698 case SCU_EVENT_SAS_30
:
699 case SCU_EVENT_SAS_30_SSC
:
700 scic_sds_phy_complete_link_training(
702 SAS_LINK_RATE_3_0_GBPS
,
703 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
);
706 case SCU_EVENT_SAS_60
:
707 case SCU_EVENT_SAS_60_SSC
:
708 scic_sds_phy_complete_link_training(
710 SAS_LINK_RATE_6_0_GBPS
,
711 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
);
714 case SCU_EVENT_SATA_SPINUP_HOLD
:
716 * We were doing SAS PHY link training and received a SATA PHY event
717 * continue OOB/SN as if this were a SATA PHY */
718 scic_sds_phy_start_sata_link_training(sci_phy
);
721 case SCU_EVENT_LINK_FAILURE
:
722 /* Link failure change state back to the starting state */
723 scic_sds_phy_restart_starting_state(sci_phy
);
727 dev_warn(sciphy_to_dev(sci_phy
),
728 "%s: PHY starting substate machine received "
729 "unexpected event_code %x\n",
733 result
= SCI_FAILURE
;
742 * @phy: This struct scic_sds_phy object which has received an event.
743 * @event_code: This is the event code which the phy object is to decode.
745 * This method is called when an event notification is received for the phy
746 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. -
747 * decode the event - sas phy detected event backs up the state machine to the
748 * await speed notification. - identify timeout is an un-expected event and the
749 * state machine is restarted. - link failure events restart the starting state
750 * machine - any other events log a warning message and set a failure status
751 * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any
752 * unexpected event notifation
754 static enum sci_status
scic_sds_phy_starting_substate_await_iaf_uf_event_handler(
755 struct scic_sds_phy
*sci_phy
,
758 u32 result
= SCI_SUCCESS
;
760 switch (scu_get_event_code(event_code
)) {
761 case SCU_EVENT_SAS_PHY_DETECTED
:
762 /* Backup the state machine */
763 scic_sds_phy_start_sas_link_training(sci_phy
);
766 case SCU_EVENT_SATA_SPINUP_HOLD
:
768 * We were doing SAS PHY link training and received a SATA PHY event
769 * continue OOB/SN as if this were a SATA PHY */
770 scic_sds_phy_start_sata_link_training(sci_phy
);
773 case SCU_EVENT_RECEIVED_IDENTIFY_TIMEOUT
:
774 case SCU_EVENT_LINK_FAILURE
:
775 case SCU_EVENT_HARD_RESET_RECEIVED
:
776 /* Start the oob/sn state machine over again */
777 scic_sds_phy_restart_starting_state(sci_phy
);
781 dev_warn(sciphy_to_dev(sci_phy
),
782 "%s: PHY starting substate machine received "
783 "unexpected event_code %x\n",
787 result
= SCI_FAILURE
;
796 * @phy: This struct scic_sds_phy object which has received an event.
797 * @event_code: This is the event code which the phy object is to decode.
799 * This method is called when an event notification is received for the phy
800 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_POWER. -
801 * decode the event - link failure events restart the starting state machine -
802 * any other events log a warning message and set a failure status enum sci_status
803 * SCI_SUCCESS on a link failure event SCI_FAILURE on any unexpected event
806 static enum sci_status
scic_sds_phy_starting_substate_await_sas_power_event_handler(
807 struct scic_sds_phy
*sci_phy
,
810 u32 result
= SCI_SUCCESS
;
812 switch (scu_get_event_code(event_code
)) {
813 case SCU_EVENT_LINK_FAILURE
:
814 /* Link failure change state back to the starting state */
815 scic_sds_phy_restart_starting_state(sci_phy
);
819 dev_warn(sciphy_to_dev(sci_phy
),
820 "%s: PHY starting substate machine received unexpected "
825 result
= SCI_FAILURE
;
834 * @phy: This struct scic_sds_phy object which has received an event.
835 * @event_code: This is the event code which the phy object is to decode.
837 * This method is called when an event notification is received for the phy
838 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. -
839 * decode the event - link failure events restart the starting state machine -
840 * sata spinup hold events are ignored since they are expected - any other
841 * events log a warning message and set a failure status enum sci_status SCI_SUCCESS
842 * on a link failure event SCI_FAILURE on any unexpected event notifation
844 static enum sci_status
scic_sds_phy_starting_substate_await_sata_power_event_handler(
845 struct scic_sds_phy
*sci_phy
,
848 u32 result
= SCI_SUCCESS
;
850 switch (scu_get_event_code(event_code
)) {
851 case SCU_EVENT_LINK_FAILURE
:
852 /* Link failure change state back to the starting state */
853 scic_sds_phy_restart_starting_state(sci_phy
);
856 case SCU_EVENT_SATA_SPINUP_HOLD
:
857 /* These events are received every 10ms and are expected while in this state */
860 case SCU_EVENT_SAS_PHY_DETECTED
:
862 * There has been a change in the phy type before OOB/SN for the
863 * SATA finished start down the SAS link traning path. */
864 scic_sds_phy_start_sas_link_training(sci_phy
);
868 dev_warn(sciphy_to_dev(sci_phy
),
869 "%s: PHY starting substate machine received "
870 "unexpected event_code %x\n",
874 result
= SCI_FAILURE
;
882 * scic_sds_phy_starting_substate_await_sata_phy_event_handler -
883 * @phy: This struct scic_sds_phy object which has received an event.
884 * @event_code: This is the event code which the phy object is to decode.
886 * This method is called when an event notification is received for the phy
887 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. -
888 * decode the event - link failure events restart the starting state machine -
889 * sata spinup hold events are ignored since they are expected - sata phy
890 * detected event change to the wait speed event - any other events log a
891 * warning message and set a failure status enum sci_status SCI_SUCCESS on a link
892 * failure event SCI_FAILURE on any unexpected event notifation
894 static enum sci_status
scic_sds_phy_starting_substate_await_sata_phy_event_handler(
895 struct scic_sds_phy
*sci_phy
, u32 event_code
)
897 u32 result
= SCI_SUCCESS
;
899 switch (scu_get_event_code(event_code
)) {
900 case SCU_EVENT_LINK_FAILURE
:
901 /* Link failure change state back to the starting state */
902 scic_sds_phy_restart_starting_state(sci_phy
);
905 case SCU_EVENT_SATA_SPINUP_HOLD
:
906 /* These events might be received since we dont know how many may be in
907 * the completion queue while waiting for power
911 case SCU_EVENT_SATA_PHY_DETECTED
:
912 sci_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_SATA
;
914 /* We have received the SATA PHY notification change state */
915 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
916 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
);
919 case SCU_EVENT_SAS_PHY_DETECTED
:
920 /* There has been a change in the phy type before OOB/SN for the
921 * SATA finished start down the SAS link traning path.
923 scic_sds_phy_start_sas_link_training(sci_phy
);
927 dev_warn(sciphy_to_dev(sci_phy
),
928 "%s: PHY starting substate machine received "
929 "unexpected event_code %x\n",
933 result
= SCI_FAILURE
;
942 * @phy: This struct scic_sds_phy object which has received an event.
943 * @event_code: This is the event code which the phy object is to decode.
945 * This method is called when an event notification is received for the phy
946 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN.
947 * - decode the event - sata phy detected returns us back to this state. -
948 * speed event detected causes a state transition to the wait for signature. -
949 * link failure events restart the starting state machine - any other events
950 * log a warning message and set a failure status enum sci_status SCI_SUCCESS on any
951 * valid event notification SCI_FAILURE on any unexpected event notifation
953 static enum sci_status
scic_sds_phy_starting_substate_await_sata_speed_event_handler(
954 struct scic_sds_phy
*sci_phy
,
957 u32 result
= SCI_SUCCESS
;
959 switch (scu_get_event_code(event_code
)) {
960 case SCU_EVENT_SATA_PHY_DETECTED
:
962 * The hardware reports multiple SATA PHY detected events
963 * ignore the extras */
966 case SCU_EVENT_SATA_15
:
967 case SCU_EVENT_SATA_15_SSC
:
968 scic_sds_phy_complete_link_training(
970 SAS_LINK_RATE_1_5_GBPS
,
971 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
);
974 case SCU_EVENT_SATA_30
:
975 case SCU_EVENT_SATA_30_SSC
:
976 scic_sds_phy_complete_link_training(
978 SAS_LINK_RATE_3_0_GBPS
,
979 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
);
982 case SCU_EVENT_SATA_60
:
983 case SCU_EVENT_SATA_60_SSC
:
984 scic_sds_phy_complete_link_training(
986 SAS_LINK_RATE_6_0_GBPS
,
987 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
);
990 case SCU_EVENT_LINK_FAILURE
:
991 /* Link failure change state back to the starting state */
992 scic_sds_phy_restart_starting_state(sci_phy
);
995 case SCU_EVENT_SAS_PHY_DETECTED
:
997 * There has been a change in the phy type before OOB/SN for the
998 * SATA finished start down the SAS link traning path. */
999 scic_sds_phy_start_sas_link_training(sci_phy
);
1003 dev_warn(sciphy_to_dev(sci_phy
),
1004 "%s: PHY starting substate machine received "
1005 "unexpected event_code %x\n",
1009 result
= SCI_FAILURE
;
1017 * scic_sds_phy_starting_substate_await_sig_fis_event_handler -
1018 * @phy: This struct scic_sds_phy object which has received an event.
1019 * @event_code: This is the event code which the phy object is to decode.
1021 * This method is called when an event notification is received for the phy
1022 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. -
1023 * decode the event - sas phy detected event backs up the state machine to the
1024 * await speed notification. - identify timeout is an un-expected event and the
1025 * state machine is restarted. - link failure events restart the starting state
1026 * machine - any other events log a warning message and set a failure status
1027 * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any
1028 * unexpected event notifation
1030 static enum sci_status
scic_sds_phy_starting_substate_await_sig_fis_event_handler(
1031 struct scic_sds_phy
*sci_phy
, u32 event_code
)
1033 u32 result
= SCI_SUCCESS
;
1035 switch (scu_get_event_code(event_code
)) {
1036 case SCU_EVENT_SATA_PHY_DETECTED
:
1037 /* Backup the state machine */
1038 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1039 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
);
1042 case SCU_EVENT_LINK_FAILURE
:
1043 /* Link failure change state back to the starting state */
1044 scic_sds_phy_restart_starting_state(sci_phy
);
1048 dev_warn(sciphy_to_dev(sci_phy
),
1049 "%s: PHY starting substate machine received "
1050 "unexpected event_code %x\n",
1054 result
= SCI_FAILURE
;
1063 * *****************************************************************************
1064 * * SCIC SDS PHY FRAME_HANDLERS
1065 * ***************************************************************************** */
1069 * @phy: This is struct scic_sds_phy object which is being requested to decode the
1071 * @frame_index: This is the index of the unsolicited frame which was received
1074 * This method decodes the unsolicited frame when the struct scic_sds_phy is in the
1075 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - Get the UF Header - If the UF
1076 * is an IAF - Copy IAF data to local phy object IAF data buffer. - Change
1077 * starting substate to wait power. - else - log warning message of unexpected
1078 * unsolicted frame - release frame buffer enum sci_status SCI_SUCCESS
1080 static enum sci_status
scic_sds_phy_starting_substate_await_iaf_uf_frame_handler(
1081 struct scic_sds_phy
*sci_phy
, u32 frame_index
)
1083 enum sci_status result
;
1085 struct sas_identify_frame iaf
;
1086 struct isci_phy
*iphy
= sci_phy_to_iphy(sci_phy
);
1088 result
= scic_sds_unsolicited_frame_control_get_header(
1089 &(scic_sds_phy_get_controller(sci_phy
)->uf_control
),
1091 (void **)&frame_words
);
1093 if (result
!= SCI_SUCCESS
)
1096 sci_swab32_cpy(&iaf
, frame_words
, sizeof(iaf
) / sizeof(u32
));
1097 if (iaf
.frame_type
== 0) {
1100 memcpy(&iphy
->frame_rcvd
.iaf
, &iaf
, sizeof(iaf
));
1101 if (iaf
.smp_tport
) {
1102 /* We got the IAF for an expander PHY go to the final
1103 * state since there are no power requirements for
1106 state
= SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
;
1108 /* We got the IAF we can now go to the await spinup
1111 state
= SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
;
1113 sci_base_state_machine_change_state(
1114 &sci_phy
->state_machine
,
1116 result
= SCI_SUCCESS
;
1118 dev_warn(sciphy_to_dev(sci_phy
),
1119 "%s: PHY starting substate machine received "
1120 "unexpected frame id %x\n",
1124 scic_sds_controller_release_frame(scic_sds_phy_get_controller(sci_phy
),
1132 * @phy: This is struct scic_sds_phy object which is being requested to decode the
1134 * @frame_index: This is the index of the unsolicited frame which was received
1137 * This method decodes the unsolicited frame when the struct scic_sds_phy is in the
1138 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Get the UF Header - If
1139 * the UF is an SIGNATURE FIS - Copy IAF data to local phy object SIGNATURE FIS
1140 * data buffer. - else - log warning message of unexpected unsolicted frame -
1141 * release frame buffer enum sci_status SCI_SUCCESS Must decode the SIGNATURE FIS
1144 static enum sci_status
scic_sds_phy_starting_substate_await_sig_fis_frame_handler(
1145 struct scic_sds_phy
*sci_phy
,
1148 enum sci_status result
;
1149 struct dev_to_host_fis
*frame_header
;
1150 u32
*fis_frame_data
;
1151 struct isci_phy
*iphy
= sci_phy_to_iphy(sci_phy
);
1153 result
= scic_sds_unsolicited_frame_control_get_header(
1154 &(scic_sds_phy_get_controller(sci_phy
)->uf_control
),
1156 (void **)&frame_header
);
1158 if (result
!= SCI_SUCCESS
)
1161 if ((frame_header
->fis_type
== FIS_REGD2H
) &&
1162 !(frame_header
->status
& ATA_BUSY
)) {
1163 scic_sds_unsolicited_frame_control_get_buffer(
1164 &(scic_sds_phy_get_controller(sci_phy
)->uf_control
),
1166 (void **)&fis_frame_data
);
1168 scic_sds_controller_copy_sata_response(&iphy
->frame_rcvd
.fis
,
1172 /* got IAF we can now go to the await spinup semaphore state */
1173 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1174 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
);
1176 result
= SCI_SUCCESS
;
1178 dev_warn(sciphy_to_dev(sci_phy
),
1179 "%s: PHY starting substate machine received "
1180 "unexpected frame id %x\n",
1184 /* Regardless of the result we are done with this frame with it */
1185 scic_sds_controller_release_frame(scic_sds_phy_get_controller(sci_phy
),
1192 * *****************************************************************************
1193 * * SCIC SDS PHY POWER_HANDLERS
1194 * ***************************************************************************** */
1197 * This method is called by the struct scic_sds_controller when the phy object is
1198 * granted power. - The notify enable spinups are turned on for this phy object
1199 * - The phy state machine is transitioned to the
1200 * SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. enum sci_status SCI_SUCCESS
1202 static enum sci_status
scic_sds_phy_starting_substate_await_sas_power_consume_power_handler(
1203 struct scic_sds_phy
*sci_phy
)
1207 enable_spinup
= readl(&sci_phy
->link_layer_registers
->notify_enable_spinup_control
);
1208 enable_spinup
|= SCU_ENSPINUP_GEN_BIT(ENABLE
);
1209 writel(enable_spinup
, &sci_phy
->link_layer_registers
->notify_enable_spinup_control
);
1211 /* Change state to the final state this substate machine has run to completion */
1212 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1213 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
);
1219 * This method is called by the struct scic_sds_controller when the phy object is
1220 * granted power. - The phy state machine is transitioned to the
1221 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. enum sci_status SCI_SUCCESS
1223 static enum sci_status
scic_sds_phy_starting_substate_await_sata_power_consume_power_handler(
1224 struct scic_sds_phy
*sci_phy
)
1226 u32 scu_sas_pcfg_value
;
1228 /* Release the spinup hold state and reset the OOB state machine */
1229 scu_sas_pcfg_value
=
1230 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
1231 scu_sas_pcfg_value
&=
1232 ~(SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD
) | SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE
));
1233 scu_sas_pcfg_value
|= SCU_SAS_PCFG_GEN_BIT(OOB_RESET
);
1234 writel(scu_sas_pcfg_value
,
1235 &sci_phy
->link_layer_registers
->phy_configuration
);
1237 /* Now restart the OOB operation */
1238 scu_sas_pcfg_value
&= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET
);
1239 scu_sas_pcfg_value
|= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE
);
1240 writel(scu_sas_pcfg_value
,
1241 &sci_phy
->link_layer_registers
->phy_configuration
);
1243 /* Change state to the final state this substate machine has run to completion */
1244 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1245 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN
);
1250 static enum sci_status
default_phy_handler(struct scic_sds_phy
*sci_phy
,
1253 dev_dbg(sciphy_to_dev(sci_phy
),
1254 "%s: in wrong state: %d\n", func
,
1255 sci_base_state_machine_get_state(&sci_phy
->state_machine
));
1256 return SCI_FAILURE_INVALID_STATE
;
1259 static enum sci_status
1260 scic_sds_phy_default_start_handler(struct scic_sds_phy
*sci_phy
)
1262 return default_phy_handler(sci_phy
, __func__
);
1265 static enum sci_status
1266 scic_sds_phy_default_stop_handler(struct scic_sds_phy
*sci_phy
)
1268 return default_phy_handler(sci_phy
, __func__
);
1271 static enum sci_status
1272 scic_sds_phy_default_reset_handler(struct scic_sds_phy
*sci_phy
)
1274 return default_phy_handler(sci_phy
, __func__
);
1277 static enum sci_status
1278 scic_sds_phy_default_destroy_handler(struct scic_sds_phy
*sci_phy
)
1280 return default_phy_handler(sci_phy
, __func__
);
1283 static enum sci_status
1284 scic_sds_phy_default_frame_handler(struct scic_sds_phy
*sci_phy
,
1287 struct scic_sds_controller
*scic
= scic_sds_phy_get_controller(sci_phy
);
1289 default_phy_handler(sci_phy
, __func__
);
1290 scic_sds_controller_release_frame(scic
, frame_index
);
1292 return SCI_FAILURE_INVALID_STATE
;
1295 static enum sci_status
1296 scic_sds_phy_default_event_handler(struct scic_sds_phy
*sci_phy
,
1299 return default_phy_handler(sci_phy
, __func__
);
1302 static enum sci_status
1303 scic_sds_phy_default_consume_power_handler(struct scic_sds_phy
*sci_phy
)
1305 return default_phy_handler(sci_phy
, __func__
);
1309 * This method takes the struct scic_sds_phy from a stopped state and
1310 * attempts to start it. - The phy state machine is transitioned to the
1311 * SCI_BASE_PHY_STATE_STARTING. enum sci_status SCI_SUCCESS
1313 static enum sci_status
1314 scic_sds_phy_stopped_state_start_handler(struct scic_sds_phy
*sci_phy
)
1316 struct isci_host
*ihost
;
1317 struct scic_sds_controller
*scic
;
1319 scic
= scic_sds_phy_get_controller(sci_phy
),
1320 ihost
= scic_to_ihost(scic
);
1322 /* Create the SIGNATURE FIS Timeout timer for this phy */
1323 sci_phy
->sata_timeout_timer
= isci_timer_create(ihost
, sci_phy
,
1324 scic_sds_phy_sata_timeout
);
1326 if (sci_phy
->sata_timeout_timer
)
1327 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1328 SCI_BASE_PHY_STATE_STARTING
);
1333 static enum sci_status
1334 scic_sds_phy_stopped_state_destroy_handler(struct scic_sds_phy
*sci_phy
)
1339 static enum sci_status
1340 scic_sds_phy_ready_state_stop_handler(struct scic_sds_phy
*sci_phy
)
1342 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1343 SCI_BASE_PHY_STATE_STOPPED
);
1348 static enum sci_status
1349 scic_sds_phy_ready_state_reset_handler(struct scic_sds_phy
*sci_phy
)
1351 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1352 SCI_BASE_PHY_STATE_RESETTING
);
1358 * scic_sds_phy_ready_state_event_handler -
1359 * @phy: This is the struct scic_sds_phy object which has received the event.
1361 * This method request the struct scic_sds_phy handle the received event. The only
1362 * event that we are interested in while in the ready state is the link failure
1363 * event. - decoded event is a link failure - transition the struct scic_sds_phy back
1364 * to the SCI_BASE_PHY_STATE_STARTING state. - any other event received will
1365 * report a warning message enum sci_status SCI_SUCCESS if the event received is a
1366 * link failure SCI_FAILURE_INVALID_STATE for any other event received.
1368 static enum sci_status
scic_sds_phy_ready_state_event_handler(struct scic_sds_phy
*sci_phy
,
1371 enum sci_status result
= SCI_FAILURE
;
1373 switch (scu_get_event_code(event_code
)) {
1374 case SCU_EVENT_LINK_FAILURE
:
1375 /* Link failure change state back to the starting state */
1376 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1377 SCI_BASE_PHY_STATE_STARTING
);
1378 result
= SCI_SUCCESS
;
1381 case SCU_EVENT_BROADCAST_CHANGE
:
1382 /* Broadcast change received. Notify the port. */
1383 if (scic_sds_phy_get_port(sci_phy
) != NULL
)
1384 scic_sds_port_broadcast_change_received(sci_phy
->owning_port
, sci_phy
);
1386 sci_phy
->bcn_received_while_port_unassigned
= true;
1390 dev_warn(sciphy_to_dev(sci_phy
),
1391 "%sP SCIC PHY 0x%p ready state machine received "
1392 "unexpected event_code %x\n",
1393 __func__
, sci_phy
, event_code
);
1395 result
= SCI_FAILURE_INVALID_STATE
;
1402 static enum sci_status
scic_sds_phy_resetting_state_event_handler(struct scic_sds_phy
*sci_phy
,
1405 enum sci_status result
= SCI_FAILURE
;
1407 switch (scu_get_event_code(event_code
)) {
1408 case SCU_EVENT_HARD_RESET_TRANSMITTED
:
1409 /* Link failure change state back to the starting state */
1410 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1411 SCI_BASE_PHY_STATE_STARTING
);
1412 result
= SCI_SUCCESS
;
1416 dev_warn(sciphy_to_dev(sci_phy
),
1417 "%s: SCIC PHY 0x%p resetting state machine received "
1418 "unexpected event_code %x\n",
1419 __func__
, sci_phy
, event_code
);
1421 result
= SCI_FAILURE_INVALID_STATE
;
1428 /* --------------------------------------------------------------------------- */
1430 static const struct scic_sds_phy_state_handler scic_sds_phy_state_handler_table
[] = {
1431 [SCI_BASE_PHY_STATE_INITIAL
] = {
1432 .start_handler
= scic_sds_phy_default_start_handler
,
1433 .stop_handler
= scic_sds_phy_default_stop_handler
,
1434 .reset_handler
= scic_sds_phy_default_reset_handler
,
1435 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1436 .frame_handler
= scic_sds_phy_default_frame_handler
,
1437 .event_handler
= scic_sds_phy_default_event_handler
,
1438 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1440 [SCI_BASE_PHY_STATE_STOPPED
] = {
1441 .start_handler
= scic_sds_phy_stopped_state_start_handler
,
1442 .stop_handler
= scic_sds_phy_default_stop_handler
,
1443 .reset_handler
= scic_sds_phy_default_reset_handler
,
1444 .destruct_handler
= scic_sds_phy_stopped_state_destroy_handler
,
1445 .frame_handler
= scic_sds_phy_default_frame_handler
,
1446 .event_handler
= scic_sds_phy_default_event_handler
,
1447 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1449 [SCI_BASE_PHY_STATE_STARTING
] = {
1450 .start_handler
= scic_sds_phy_default_start_handler
,
1451 .stop_handler
= scic_sds_phy_default_stop_handler
,
1452 .reset_handler
= scic_sds_phy_default_reset_handler
,
1453 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1454 .frame_handler
= scic_sds_phy_default_frame_handler
,
1455 .event_handler
= scic_sds_phy_default_event_handler
,
1456 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1458 [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL
] = {
1459 .start_handler
= scic_sds_phy_default_start_handler
,
1460 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1461 .reset_handler
= scic_sds_phy_default_reset_handler
,
1462 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1463 .frame_handler
= scic_sds_phy_default_frame_handler
,
1464 .event_handler
= scic_sds_phy_default_event_handler
,
1465 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1467 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
] = {
1468 .start_handler
= scic_sds_phy_default_start_handler
,
1469 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1470 .reset_handler
= scic_sds_phy_default_reset_handler
,
1471 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1472 .frame_handler
= scic_sds_phy_default_frame_handler
,
1473 .event_handler
= scic_sds_phy_starting_substate_await_ossp_event_handler
,
1474 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1476 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
] = {
1477 .start_handler
= scic_sds_phy_default_start_handler
,
1478 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1479 .reset_handler
= scic_sds_phy_default_reset_handler
,
1480 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1481 .frame_handler
= scic_sds_phy_default_frame_handler
,
1482 .event_handler
= scic_sds_phy_starting_substate_await_sas_phy_speed_event_handler
,
1483 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1485 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
] = {
1486 .start_handler
= scic_sds_phy_default_start_handler
,
1487 .stop_handler
= scic_sds_phy_default_stop_handler
,
1488 .reset_handler
= scic_sds_phy_default_reset_handler
,
1489 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1490 .frame_handler
= scic_sds_phy_starting_substate_await_iaf_uf_frame_handler
,
1491 .event_handler
= scic_sds_phy_starting_substate_await_iaf_uf_event_handler
,
1492 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1494 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
] = {
1495 .start_handler
= scic_sds_phy_default_start_handler
,
1496 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1497 .reset_handler
= scic_sds_phy_default_reset_handler
,
1498 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1499 .frame_handler
= scic_sds_phy_default_frame_handler
,
1500 .event_handler
= scic_sds_phy_starting_substate_await_sas_power_event_handler
,
1501 .consume_power_handler
= scic_sds_phy_starting_substate_await_sas_power_consume_power_handler
1503 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
] = {
1504 .start_handler
= scic_sds_phy_default_start_handler
,
1505 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1506 .reset_handler
= scic_sds_phy_default_reset_handler
,
1507 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1508 .frame_handler
= scic_sds_phy_default_frame_handler
,
1509 .event_handler
= scic_sds_phy_starting_substate_await_sata_power_event_handler
,
1510 .consume_power_handler
= scic_sds_phy_starting_substate_await_sata_power_consume_power_handler
1512 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN
] = {
1513 .start_handler
= scic_sds_phy_default_start_handler
,
1514 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1515 .reset_handler
= scic_sds_phy_default_reset_handler
,
1516 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1517 .frame_handler
= scic_sds_phy_default_frame_handler
,
1518 .event_handler
= scic_sds_phy_starting_substate_await_sata_phy_event_handler
,
1519 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1521 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
] = {
1522 .start_handler
= scic_sds_phy_default_start_handler
,
1523 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1524 .reset_handler
= scic_sds_phy_default_reset_handler
,
1525 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1526 .frame_handler
= scic_sds_phy_default_frame_handler
,
1527 .event_handler
= scic_sds_phy_starting_substate_await_sata_speed_event_handler
,
1528 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1530 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
] = {
1531 .start_handler
= scic_sds_phy_default_start_handler
,
1532 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1533 .reset_handler
= scic_sds_phy_default_reset_handler
,
1534 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1535 .frame_handler
= scic_sds_phy_starting_substate_await_sig_fis_frame_handler
,
1536 .event_handler
= scic_sds_phy_starting_substate_await_sig_fis_event_handler
,
1537 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1539 [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
] = {
1540 .start_handler
= scic_sds_phy_default_start_handler
,
1541 .stop_handler
= scic_sds_phy_starting_substate_general_stop_handler
,
1542 .reset_handler
= scic_sds_phy_default_reset_handler
,
1543 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1544 .frame_handler
= scic_sds_phy_default_frame_handler
,
1545 .event_handler
= scic_sds_phy_default_event_handler
,
1546 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1548 [SCI_BASE_PHY_STATE_READY
] = {
1549 .start_handler
= scic_sds_phy_default_start_handler
,
1550 .stop_handler
= scic_sds_phy_ready_state_stop_handler
,
1551 .reset_handler
= scic_sds_phy_ready_state_reset_handler
,
1552 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1553 .frame_handler
= scic_sds_phy_default_frame_handler
,
1554 .event_handler
= scic_sds_phy_ready_state_event_handler
,
1555 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1557 [SCI_BASE_PHY_STATE_RESETTING
] = {
1558 .start_handler
= scic_sds_phy_default_start_handler
,
1559 .stop_handler
= scic_sds_phy_default_stop_handler
,
1560 .reset_handler
= scic_sds_phy_default_reset_handler
,
1561 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1562 .frame_handler
= scic_sds_phy_default_frame_handler
,
1563 .event_handler
= scic_sds_phy_resetting_state_event_handler
,
1564 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1566 [SCI_BASE_PHY_STATE_FINAL
] = {
1567 .start_handler
= scic_sds_phy_default_start_handler
,
1568 .stop_handler
= scic_sds_phy_default_stop_handler
,
1569 .reset_handler
= scic_sds_phy_default_reset_handler
,
1570 .destruct_handler
= scic_sds_phy_default_destroy_handler
,
1571 .frame_handler
= scic_sds_phy_default_frame_handler
,
1572 .event_handler
= scic_sds_phy_default_event_handler
,
1573 .consume_power_handler
= scic_sds_phy_default_consume_power_handler
1578 * ****************************************************************************
1579 * * PHY STARTING SUBSTATE METHODS
1580 * **************************************************************************** */
1583 * scic_sds_phy_starting_initial_substate_enter -
1584 * @object: This is the object which is cast to a struct scic_sds_phy object.
1586 * This method will perform the actions required by the struct scic_sds_phy on
1587 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL. - The initial state
1588 * handlers are put in place for the struct scic_sds_phy object. - The state is
1589 * changed to the wait phy type event notification. none
1591 static void scic_sds_phy_starting_initial_substate_enter(void *object
)
1593 struct scic_sds_phy
*sci_phy
= object
;
1595 scic_sds_phy_set_base_state_handlers(
1596 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL
);
1598 /* This is just an temporary state go off to the starting state */
1599 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1600 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
);
1605 * @object: This is the object which is cast to a struct scic_sds_phy object.
1607 * This method will perform the actions required by the struct scic_sds_phy on
1608 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_PHY_TYPE_EN. - Set the
1609 * struct scic_sds_phy object state handlers for this state. none
1611 static void scic_sds_phy_starting_await_ossp_en_substate_enter(void *object
)
1613 struct scic_sds_phy
*sci_phy
= object
;
1615 scic_sds_phy_set_base_state_handlers(
1616 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
1622 * @object: This is the object which is cast to a struct scic_sds_phy object.
1624 * This method will perform the actions required by the struct scic_sds_phy on
1625 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. - Set the
1626 * struct scic_sds_phy object state handlers for this state. none
1628 static void scic_sds_phy_starting_await_sas_speed_en_substate_enter(
1631 struct scic_sds_phy
*sci_phy
= object
;
1633 scic_sds_phy_set_base_state_handlers(
1634 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
1640 * @object: This is the object which is cast to a struct scic_sds_phy object.
1642 * This method will perform the actions required by the struct scic_sds_phy on
1643 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - Set the
1644 * struct scic_sds_phy object state handlers for this state. none
1646 static void scic_sds_phy_starting_await_iaf_uf_substate_enter(void *object
)
1648 struct scic_sds_phy
*sci_phy
= object
;
1650 scic_sds_phy_set_base_state_handlers(
1651 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
1657 * @object: This is the object which is cast to a struct scic_sds_phy object.
1659 * This method will perform the actions required by the struct scic_sds_phy on
1660 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Set the
1661 * struct scic_sds_phy object state handlers for this state. - Add this phy object to
1662 * the power control queue none
1664 static void scic_sds_phy_starting_await_sas_power_substate_enter(void *object
)
1666 struct scic_sds_phy
*sci_phy
= object
;
1668 scic_sds_phy_set_base_state_handlers(
1669 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
1672 scic_sds_controller_power_control_queue_insert(
1673 scic_sds_phy_get_controller(sci_phy
),
1680 * @object: This is the object which is cast to a struct scic_sds_phy object.
1682 * This method will perform the actions required by the struct scic_sds_phy on exiting
1683 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Remove the
1684 * struct scic_sds_phy object from the power control queue. none
1686 static void scic_sds_phy_starting_await_sas_power_substate_exit(void *object
)
1688 struct scic_sds_phy
*sci_phy
= object
;
1690 scic_sds_controller_power_control_queue_remove(
1691 scic_sds_phy_get_controller(sci_phy
), sci_phy
1697 * @object: This is the object which is cast to a struct scic_sds_phy object.
1699 * This method will perform the actions required by the struct scic_sds_phy on
1700 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Set the
1701 * struct scic_sds_phy object state handlers for this state. - Add this phy object to
1702 * the power control queue none
1704 static void scic_sds_phy_starting_await_sata_power_substate_enter(void *object
)
1706 struct scic_sds_phy
*sci_phy
= object
;
1708 scic_sds_phy_set_base_state_handlers(
1709 sci_phy
, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
1712 scic_sds_controller_power_control_queue_insert(
1713 scic_sds_phy_get_controller(sci_phy
),
1720 * @object: This is the object which is cast to a struct scic_sds_phy object.
1722 * This method will perform the actions required by the struct scic_sds_phy on exiting
1723 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Remove the
1724 * struct scic_sds_phy object from the power control queue. none
1726 static void scic_sds_phy_starting_await_sata_power_substate_exit(void *object
)
1728 struct scic_sds_phy
*sci_phy
= object
;
1730 scic_sds_controller_power_control_queue_remove(
1731 scic_sds_phy_get_controller(sci_phy
),
1738 * @object: This is the object which is cast to a struct scic_sds_phy object.
1740 * This function will perform the actions required by the struct scic_sds_phy on
1741 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. - Set the
1742 * struct scic_sds_phy object state handlers for this state. none
1744 static void scic_sds_phy_starting_await_sata_phy_substate_enter(void *object
)
1746 struct scic_sds_phy
*sci_phy
= object
;
1748 scic_sds_phy_set_base_state_handlers(
1750 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN
);
1752 isci_timer_start(sci_phy
->sata_timeout_timer
,
1753 SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT
);
1758 * @object: This is the object which is cast to a struct scic_sds_phy object.
1760 * This method will perform the actions required by the struct scic_sds_phy
1762 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
1763 * that was started on entry to await sata phy event notification none
1765 static inline void scic_sds_phy_starting_await_sata_phy_substate_exit(
1768 struct scic_sds_phy
*sci_phy
= object
;
1770 isci_timer_stop(sci_phy
->sata_timeout_timer
);
1775 * @object: This is the object which is cast to a struct scic_sds_phy object.
1777 * This method will perform the actions required by the struct scic_sds_phy on
1778 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - Set the
1779 * struct scic_sds_phy object state handlers for this state. none
1781 static void scic_sds_phy_starting_await_sata_speed_substate_enter(void *object
)
1783 struct scic_sds_phy
*sci_phy
= object
;
1785 scic_sds_phy_set_base_state_handlers(
1787 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
);
1789 isci_timer_start(sci_phy
->sata_timeout_timer
,
1790 SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT
);
1795 * @object: This is the object which is cast to a struct scic_sds_phy object.
1797 * This function will perform the actions required by the
1798 * struct scic_sds_phy on exiting
1799 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
1800 * that was started on entry to await sata phy event notification none
1802 static inline void scic_sds_phy_starting_await_sata_speed_substate_exit(
1805 struct scic_sds_phy
*sci_phy
= object
;
1807 isci_timer_stop(sci_phy
->sata_timeout_timer
);
1812 * @object: This is the object which is cast to a struct scic_sds_phy object.
1814 * This function will perform the actions required by the struct scic_sds_phy on
1815 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Set the
1816 * struct scic_sds_phy object state handlers for this state.
1817 * - Start the SIGNATURE FIS
1818 * timeout timer none
1820 static void scic_sds_phy_starting_await_sig_fis_uf_substate_enter(void *object
)
1822 bool continue_to_ready_state
;
1823 struct scic_sds_phy
*sci_phy
= object
;
1825 scic_sds_phy_set_base_state_handlers(
1827 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
);
1829 continue_to_ready_state
= scic_sds_port_link_detected(
1830 sci_phy
->owning_port
,
1833 if (continue_to_ready_state
) {
1835 * Clear the PE suspend condition so we can actually
1837 * The hardware will not respond to the XRDY until the PE
1838 * suspend condition is cleared.
1840 scic_sds_phy_resume(sci_phy
);
1842 isci_timer_start(sci_phy
->sata_timeout_timer
,
1843 SCIC_SDS_SIGNATURE_FIS_TIMEOUT
);
1845 sci_phy
->is_in_link_training
= false;
1850 * @object: This is the object which is cast to a struct scic_sds_phy object.
1852 * This function will perform the actions required by the
1853 * struct scic_sds_phy on exiting
1854 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Stop the SIGNATURE
1855 * FIS timeout timer. none
1857 static inline void scic_sds_phy_starting_await_sig_fis_uf_substate_exit(
1860 struct scic_sds_phy
*sci_phy
= object
;
1862 isci_timer_stop(sci_phy
->sata_timeout_timer
);
1867 * @object: This is the object which is cast to a struct scic_sds_phy object.
1869 * This method will perform the actions required by the struct scic_sds_phy on
1870 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. - Set the struct scic_sds_phy
1871 * object state handlers for this state. - Change base state machine to the
1874 static void scic_sds_phy_starting_final_substate_enter(void *object
)
1876 struct scic_sds_phy
*sci_phy
= object
;
1878 scic_sds_phy_set_base_state_handlers(sci_phy
,
1879 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
);
1881 /* State machine has run to completion so exit out and change
1882 * the base state machine to the ready state
1884 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
1885 SCI_BASE_PHY_STATE_READY
);
1889 * ****************************************************************************
1890 * * PHY STATE PRIVATE METHODS
1891 * **************************************************************************** */
1895 * @sci_phy: This is the struct scic_sds_phy object to stop.
1897 * This method will stop the struct scic_sds_phy object. This does not reset the
1898 * protocol engine it just suspends it and places it in a state where it will
1899 * not cause the end device to power up. none
1901 static void scu_link_layer_stop_protocol_engine(
1902 struct scic_sds_phy
*sci_phy
)
1904 u32 scu_sas_pcfg_value
;
1905 u32 enable_spinup_value
;
1907 /* Suspend the protocol engine and place it in a sata spinup hold state */
1908 scu_sas_pcfg_value
=
1909 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
1910 scu_sas_pcfg_value
|=
1911 (SCU_SAS_PCFG_GEN_BIT(OOB_RESET
) |
1912 SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE
) |
1913 SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD
));
1914 writel(scu_sas_pcfg_value
,
1915 &sci_phy
->link_layer_registers
->phy_configuration
);
1917 /* Disable the notify enable spinup primitives */
1918 enable_spinup_value
= readl(&sci_phy
->link_layer_registers
->notify_enable_spinup_control
);
1919 enable_spinup_value
&= ~SCU_ENSPINUP_GEN_BIT(ENABLE
);
1920 writel(enable_spinup_value
, &sci_phy
->link_layer_registers
->notify_enable_spinup_control
);
1926 * This method will start the OOB/SN state machine for this struct scic_sds_phy object.
1928 static void scu_link_layer_start_oob(
1929 struct scic_sds_phy
*sci_phy
)
1931 u32 scu_sas_pcfg_value
;
1933 scu_sas_pcfg_value
=
1934 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
1935 scu_sas_pcfg_value
|= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE
);
1936 scu_sas_pcfg_value
&=
1937 ~(SCU_SAS_PCFG_GEN_BIT(OOB_RESET
) |
1938 SCU_SAS_PCFG_GEN_BIT(HARD_RESET
));
1939 writel(scu_sas_pcfg_value
,
1940 &sci_phy
->link_layer_registers
->phy_configuration
);
1946 * This method will transmit a hard reset request on the specified phy. The SCU
1947 * hardware requires that we reset the OOB state machine and set the hard reset
1948 * bit in the phy configuration register. We then must start OOB over with the
1949 * hard reset bit set.
1951 static void scu_link_layer_tx_hard_reset(
1952 struct scic_sds_phy
*sci_phy
)
1954 u32 phy_configuration_value
;
1957 * SAS Phys must wait for the HARD_RESET_TX event notification to transition
1958 * to the starting state. */
1959 phy_configuration_value
=
1960 readl(&sci_phy
->link_layer_registers
->phy_configuration
);
1961 phy_configuration_value
|=
1962 (SCU_SAS_PCFG_GEN_BIT(HARD_RESET
) |
1963 SCU_SAS_PCFG_GEN_BIT(OOB_RESET
));
1964 writel(phy_configuration_value
,
1965 &sci_phy
->link_layer_registers
->phy_configuration
);
1967 /* Now take the OOB state machine out of reset */
1968 phy_configuration_value
|= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE
);
1969 phy_configuration_value
&= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET
);
1970 writel(phy_configuration_value
,
1971 &sci_phy
->link_layer_registers
->phy_configuration
);
1975 * ****************************************************************************
1976 * * PHY BASE STATE METHODS
1977 * **************************************************************************** */
1981 * @object: This is the object which is cast to a struct scic_sds_phy object.
1983 * This method will perform the actions required by the struct scic_sds_phy on
1984 * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
1985 * handlers for the phy object base state machine initial state. none
1987 static void scic_sds_phy_initial_state_enter(void *object
)
1989 struct scic_sds_phy
*sci_phy
= object
;
1991 scic_sds_phy_set_base_state_handlers(sci_phy
, SCI_BASE_PHY_STATE_INITIAL
);
1996 * @object: This is the object which is cast to a struct scic_sds_phy object.
1998 * This function will perform the actions required by the struct scic_sds_phy on
1999 * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
2000 * handlers for the phy object base state machine initial state. - The SCU
2001 * hardware is requested to stop the protocol engine. none
2003 static void scic_sds_phy_stopped_state_enter(void *object
)
2005 struct scic_sds_phy
*sci_phy
= object
;
2006 struct scic_sds_controller
*scic
= scic_sds_phy_get_controller(sci_phy
);
2007 struct isci_host
*ihost
= scic_to_ihost(scic
);
2010 * @todo We need to get to the controller to place this PE in a
2014 scic_sds_phy_set_base_state_handlers(sci_phy
,
2015 SCI_BASE_PHY_STATE_STOPPED
);
2017 if (sci_phy
->sata_timeout_timer
!= NULL
) {
2018 isci_del_timer(ihost
, sci_phy
->sata_timeout_timer
);
2020 sci_phy
->sata_timeout_timer
= NULL
;
2023 scu_link_layer_stop_protocol_engine(sci_phy
);
2025 if (sci_phy
->state_machine
.previous_state_id
!=
2026 SCI_BASE_PHY_STATE_INITIAL
)
2027 scic_sds_controller_link_down(
2028 scic_sds_phy_get_controller(sci_phy
),
2029 scic_sds_phy_get_port(sci_phy
),
2035 * @object: This is the object which is cast to a struct scic_sds_phy object.
2037 * This method will perform the actions required by the struct scic_sds_phy on
2038 * entering the SCI_BASE_PHY_STATE_STARTING. - This function sets the state
2039 * handlers for the phy object base state machine starting state. - The SCU
2040 * hardware is requested to start OOB/SN on this protocl engine. - The phy
2041 * starting substate machine is started. - If the previous state was the ready
2042 * state then the struct scic_sds_controller is informed that the phy has gone link
2045 static void scic_sds_phy_starting_state_enter(void *object
)
2047 struct scic_sds_phy
*sci_phy
= object
;
2049 scic_sds_phy_set_base_state_handlers(sci_phy
, SCI_BASE_PHY_STATE_STARTING
);
2051 scu_link_layer_stop_protocol_engine(sci_phy
);
2052 scu_link_layer_start_oob(sci_phy
);
2054 /* We don't know what kind of phy we are going to be just yet */
2055 sci_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_UNKNOWN
;
2056 sci_phy
->bcn_received_while_port_unassigned
= false;
2058 if (sci_phy
->state_machine
.previous_state_id
2059 == SCI_BASE_PHY_STATE_READY
) {
2060 scic_sds_controller_link_down(
2061 scic_sds_phy_get_controller(sci_phy
),
2062 scic_sds_phy_get_port(sci_phy
),
2067 sci_base_state_machine_change_state(&sci_phy
->state_machine
,
2068 SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL
);
2073 * @object: This is the object which is cast to a struct scic_sds_phy object.
2075 * This method will perform the actions required by the struct scic_sds_phy on
2076 * entering the SCI_BASE_PHY_STATE_READY. - This function sets the state
2077 * handlers for the phy object base state machine ready state. - The SCU
2078 * hardware protocol engine is resumed. - The struct scic_sds_controller is informed
2079 * that the phy object has gone link up. none
2081 static void scic_sds_phy_ready_state_enter(void *object
)
2083 struct scic_sds_phy
*sci_phy
= object
;
2085 scic_sds_phy_set_base_state_handlers(sci_phy
, SCI_BASE_PHY_STATE_READY
);
2087 scic_sds_controller_link_up(
2088 scic_sds_phy_get_controller(sci_phy
),
2089 scic_sds_phy_get_port(sci_phy
),
2096 * @object: This is the object which is cast to a struct scic_sds_phy object.
2098 * This method will perform the actions required by the struct scic_sds_phy on exiting
2099 * the SCI_BASE_PHY_STATE_INITIAL. This function suspends the SCU hardware
2100 * protocol engine represented by this struct scic_sds_phy object. none
2102 static void scic_sds_phy_ready_state_exit(void *object
)
2104 struct scic_sds_phy
*sci_phy
= object
;
2106 scic_sds_phy_suspend(sci_phy
);
2111 * @object: This is the object which is cast to a struct scic_sds_phy object.
2113 * This method will perform the actions required by the struct scic_sds_phy on
2114 * entering the SCI_BASE_PHY_STATE_RESETTING. - This function sets the state
2115 * handlers for the phy object base state machine resetting state. none
2117 static void scic_sds_phy_resetting_state_enter(void *object
)
2119 struct scic_sds_phy
*sci_phy
= object
;
2121 scic_sds_phy_set_base_state_handlers(sci_phy
, SCI_BASE_PHY_STATE_RESETTING
);
2124 * The phy is being reset, therefore deactivate it from the port.
2125 * In the resetting state we don't notify the user regarding
2126 * link up and link down notifications. */
2127 scic_sds_port_deactivate_phy(sci_phy
->owning_port
, sci_phy
, false);
2129 if (sci_phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SAS
) {
2130 scu_link_layer_tx_hard_reset(sci_phy
);
2133 * The SCU does not need to have a discrete reset state so
2134 * just go back to the starting state.
2136 sci_base_state_machine_change_state(
2137 &sci_phy
->state_machine
,
2138 SCI_BASE_PHY_STATE_STARTING
);
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_FINAL. - This function sets the state
2148 * handlers for the phy object base state machine final state. none
2150 static void scic_sds_phy_final_state_enter(void *object
)
2152 struct scic_sds_phy
*sci_phy
= object
;
2154 scic_sds_phy_set_base_state_handlers(sci_phy
, SCI_BASE_PHY_STATE_FINAL
);
2156 /* Nothing to do here */
2159 /* --------------------------------------------------------------------------- */
2161 static const struct sci_base_state scic_sds_phy_state_table
[] = {
2162 [SCI_BASE_PHY_STATE_INITIAL
] = {
2163 .enter_state
= scic_sds_phy_initial_state_enter
,
2165 [SCI_BASE_PHY_STATE_STOPPED
] = {
2166 .enter_state
= scic_sds_phy_stopped_state_enter
,
2168 [SCI_BASE_PHY_STATE_STARTING
] = {
2169 .enter_state
= scic_sds_phy_starting_state_enter
,
2171 [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL
] = {
2172 .enter_state
= scic_sds_phy_starting_initial_substate_enter
,
2174 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
] = {
2175 .enter_state
= scic_sds_phy_starting_await_ossp_en_substate_enter
,
2177 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
] = {
2178 .enter_state
= scic_sds_phy_starting_await_sas_speed_en_substate_enter
,
2180 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
] = {
2181 .enter_state
= scic_sds_phy_starting_await_iaf_uf_substate_enter
,
2183 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
] = {
2184 .enter_state
= scic_sds_phy_starting_await_sas_power_substate_enter
,
2185 .exit_state
= scic_sds_phy_starting_await_sas_power_substate_exit
,
2187 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
] = {
2188 .enter_state
= scic_sds_phy_starting_await_sata_power_substate_enter
,
2189 .exit_state
= scic_sds_phy_starting_await_sata_power_substate_exit
2191 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN
] = {
2192 .enter_state
= scic_sds_phy_starting_await_sata_phy_substate_enter
,
2193 .exit_state
= scic_sds_phy_starting_await_sata_phy_substate_exit
2195 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
] = {
2196 .enter_state
= scic_sds_phy_starting_await_sata_speed_substate_enter
,
2197 .exit_state
= scic_sds_phy_starting_await_sata_speed_substate_exit
2199 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
] = {
2200 .enter_state
= scic_sds_phy_starting_await_sig_fis_uf_substate_enter
,
2201 .exit_state
= scic_sds_phy_starting_await_sig_fis_uf_substate_exit
2203 [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
] = {
2204 .enter_state
= scic_sds_phy_starting_final_substate_enter
,
2206 [SCI_BASE_PHY_STATE_READY
] = {
2207 .enter_state
= scic_sds_phy_ready_state_enter
,
2208 .exit_state
= scic_sds_phy_ready_state_exit
,
2210 [SCI_BASE_PHY_STATE_RESETTING
] = {
2211 .enter_state
= scic_sds_phy_resetting_state_enter
,
2213 [SCI_BASE_PHY_STATE_FINAL
] = {
2214 .enter_state
= scic_sds_phy_final_state_enter
,
2218 void scic_sds_phy_construct(struct scic_sds_phy
*sci_phy
,
2219 struct scic_sds_port
*owning_port
, u8 phy_index
)
2221 sci_base_state_machine_construct(&sci_phy
->state_machine
,
2223 scic_sds_phy_state_table
,
2224 SCI_BASE_PHY_STATE_INITIAL
);
2226 sci_base_state_machine_start(&sci_phy
->state_machine
);
2228 /* Copy the rest of the input data to our locals */
2229 sci_phy
->owning_port
= owning_port
;
2230 sci_phy
->phy_index
= phy_index
;
2231 sci_phy
->bcn_received_while_port_unassigned
= false;
2232 sci_phy
->protocol
= SCIC_SDS_PHY_PROTOCOL_UNKNOWN
;
2233 sci_phy
->link_layer_registers
= NULL
;
2234 sci_phy
->max_negotiated_speed
= SAS_LINK_RATE_UNKNOWN
;
2235 sci_phy
->sata_timeout_timer
= NULL
;
2238 void isci_phy_init(struct isci_phy
*iphy
, struct isci_host
*ihost
, int index
)
2240 union scic_oem_parameters oem
;
2244 scic_oem_parameters_get(&ihost
->sci
, &oem
);
2245 sci_sas_addr
= oem
.sds1
.phys
[index
].sas_address
.high
;
2246 sci_sas_addr
<<= 32;
2247 sci_sas_addr
|= oem
.sds1
.phys
[index
].sas_address
.low
;
2248 sas_addr
= cpu_to_be64(sci_sas_addr
);
2249 memcpy(iphy
->sas_addr
, &sas_addr
, sizeof(sas_addr
));
2251 iphy
->isci_port
= NULL
;
2252 iphy
->sas_phy
.enabled
= 0;
2253 iphy
->sas_phy
.id
= index
;
2254 iphy
->sas_phy
.sas_addr
= &iphy
->sas_addr
[0];
2255 iphy
->sas_phy
.frame_rcvd
= (u8
*)&iphy
->frame_rcvd
;
2256 iphy
->sas_phy
.ha
= &ihost
->sas_ha
;
2257 iphy
->sas_phy
.lldd_phy
= iphy
;
2258 iphy
->sas_phy
.enabled
= 1;
2259 iphy
->sas_phy
.class = SAS
;
2260 iphy
->sas_phy
.iproto
= SAS_PROTOCOL_ALL
;
2261 iphy
->sas_phy
.tproto
= 0;
2262 iphy
->sas_phy
.type
= PHY_TYPE_PHYSICAL
;
2263 iphy
->sas_phy
.role
= PHY_ROLE_INITIATOR
;
2264 iphy
->sas_phy
.oob_mode
= OOB_NOT_CONNECTED
;
2265 iphy
->sas_phy
.linkrate
= SAS_LINK_RATE_UNKNOWN
;
2266 memset(&iphy
->frame_rcvd
, 0, sizeof(iphy
->frame_rcvd
));
2271 * isci_phy_control() - This function is one of the SAS Domain Template
2272 * functions. This is a phy management function.
2273 * @phy: This parameter specifies the sphy being controlled.
2274 * @func: This parameter specifies the phy control function being invoked.
2275 * @buf: This parameter is specific to the phy function being invoked.
2277 * status, zero indicates success.
2279 int isci_phy_control(struct asd_sas_phy
*sas_phy
,
2284 struct isci_phy
*iphy
= sas_phy
->lldd_phy
;
2285 struct isci_port
*iport
= iphy
->isci_port
;
2286 struct isci_host
*ihost
= sas_phy
->ha
->lldd_ha
;
2287 unsigned long flags
;
2289 dev_dbg(&ihost
->pdev
->dev
,
2290 "%s: phy %p; func %d; buf %p; isci phy %p, port %p\n",
2291 __func__
, sas_phy
, func
, buf
, iphy
, iport
);
2294 case PHY_FUNC_DISABLE
:
2295 spin_lock_irqsave(&ihost
->scic_lock
, flags
);
2296 scic_sds_phy_stop(&iphy
->sci
);
2297 spin_unlock_irqrestore(&ihost
->scic_lock
, flags
);
2300 case PHY_FUNC_LINK_RESET
:
2301 spin_lock_irqsave(&ihost
->scic_lock
, flags
);
2302 scic_sds_phy_stop(&iphy
->sci
);
2303 scic_sds_phy_start(&iphy
->sci
);
2304 spin_unlock_irqrestore(&ihost
->scic_lock
, flags
);
2307 case PHY_FUNC_HARD_RESET
:
2311 /* Perform the port reset. */
2312 ret
= isci_port_perform_hard_reset(ihost
, iport
, iphy
);
2317 dev_dbg(&ihost
->pdev
->dev
,
2318 "%s: phy %p; func %d NOT IMPLEMENTED!\n",
2319 __func__
, sas_phy
, func
);