2 * This file is provided under a dual BSD/GPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
33 * * Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * * Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in
37 * the documentation and/or other materials provided with the
39 * * Neither the name of Intel Corporation nor the names of its
40 * contributors may be used to endorse or promote products derived
41 * from this software without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
44 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
45 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
46 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
47 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
50 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
51 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
53 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56 #include "intel_ata.h"
57 #include "intel_sata.h"
58 #include "sci_base_state.h"
59 #include "sci_base_state_machine.h"
61 #include "scic_sds_controller.h"
62 #include "scic_sds_phy.h"
63 #include "scic_sds_port.h"
64 #include "scic_sds_remote_node_context.h"
65 #include "sci_environment.h"
67 #include "scu_event_codes.h"
69 #define SCIC_SDS_PHY_MIN_TIMER_COUNT (SCI_MAX_PHYS)
70 #define SCIC_SDS_PHY_MAX_TIMER_COUNT (SCI_MAX_PHYS)
72 /* Maximum arbitration wait time in micro-seconds */
73 #define SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME (700)
75 enum sas_linkrate sci_phy_linkrate(struct scic_sds_phy *sci_phy)
77 return sci_phy->max_negotiated_speed;
81 * *****************************************************************************
82 * * SCIC SDS PHY Internal Methods
83 * ***************************************************************************** */
86 * This method will initialize the phy transport layer registers
88 * @transport_layer_registers
92 static enum sci_status scic_sds_phy_transport_layer_initialization(
93 struct scic_sds_phy *this_phy,
94 struct scu_transport_layer_registers __iomem *transport_layer_registers)
98 this_phy->transport_layer_registers = transport_layer_registers;
100 writel(SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX,
101 &this_phy->transport_layer_registers->stp_rni);
103 /* Hardware team recommends that we enable the STP prefetch for all transports */
104 tl_control = readl(&this_phy->transport_layer_registers->control);
105 tl_control |= SCU_TLCR_GEN_BIT(STP_WRITE_DATA_PREFETCH);
106 writel(tl_control, &this_phy->transport_layer_registers->control);
112 * This method will initialize the phy link layer registers
114 * @link_layer_registers:
118 static enum sci_status
119 scic_sds_phy_link_layer_initialization(struct scic_sds_phy *sci_phy,
120 struct scu_link_layer_registers __iomem *link_layer_registers)
122 struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller;
123 int phy_idx = sci_phy->phy_index;
124 struct sci_phy_user_params *phy_user = &scic->user_parameters.sds1.phys[phy_idx];
125 struct sci_phy_oem_params *phy_oem = &scic->oem_parameters.sds1.phys[phy_idx];
126 u32 phy_configuration;
127 struct sas_capabilities phy_capabilities;
128 u32 parity_check = 0;
129 u32 parity_count = 0;
130 u32 llctl, link_rate;
133 sci_phy->link_layer_registers = link_layer_registers;
135 /* Set our IDENTIFY frame data */
136 #define SCI_END_DEVICE 0x01
138 writel(SCU_SAS_TIID_GEN_BIT(SMP_INITIATOR) |
139 SCU_SAS_TIID_GEN_BIT(SSP_INITIATOR) |
140 SCU_SAS_TIID_GEN_BIT(STP_INITIATOR) |
141 SCU_SAS_TIID_GEN_BIT(DA_SATA_HOST) |
142 SCU_SAS_TIID_GEN_VAL(DEVICE_TYPE, SCI_END_DEVICE),
143 &sci_phy->link_layer_registers->transmit_identification);
145 /* Write the device SAS Address */
146 writel(0xFEDCBA98, &sci_phy->link_layer_registers->sas_device_name_high);
147 writel(phy_idx, &sci_phy->link_layer_registers->sas_device_name_low);
149 /* Write the source SAS Address */
150 writel(phy_oem->sas_address.high,
151 &sci_phy->link_layer_registers->source_sas_address_high);
152 writel(phy_oem->sas_address.low,
153 &sci_phy->link_layer_registers->source_sas_address_low);
155 /* Clear and Set the PHY Identifier */
156 writel(0, &sci_phy->link_layer_registers->identify_frame_phy_id);
157 writel(SCU_SAS_TIPID_GEN_VALUE(ID, phy_idx),
158 &sci_phy->link_layer_registers->identify_frame_phy_id);
160 /* Change the initial state of the phy configuration register */
162 readl(&sci_phy->link_layer_registers->phy_configuration);
164 /* Hold OOB state machine in reset */
165 phy_configuration |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
166 writel(phy_configuration,
167 &sci_phy->link_layer_registers->phy_configuration);
169 /* Configure the SNW capabilities */
170 phy_capabilities.u.all = 0;
171 phy_capabilities.u.bits.start = 1;
172 phy_capabilities.u.bits.gen3_without_ssc_supported = 1;
173 phy_capabilities.u.bits.gen2_without_ssc_supported = 1;
174 phy_capabilities.u.bits.gen1_without_ssc_supported = 1;
175 if (scic->oem_parameters.sds1.controller.do_enable_ssc == true) {
176 phy_capabilities.u.bits.gen3_with_ssc_supported = 1;
177 phy_capabilities.u.bits.gen2_with_ssc_supported = 1;
178 phy_capabilities.u.bits.gen1_with_ssc_supported = 1;
182 * The SAS specification indicates that the phy_capabilities that
183 * are transmitted shall have an even parity. Calculate the parity. */
184 parity_check = phy_capabilities.u.all;
185 while (parity_check != 0) {
186 if (parity_check & 0x1)
192 * If parity indicates there are an odd number of bits set, then
193 * set the parity bit to 1 in the phy capabilities. */
194 if ((parity_count % 2) != 0)
195 phy_capabilities.u.bits.parity = 1;
197 writel(phy_capabilities.u.all,
198 &sci_phy->link_layer_registers->phy_capabilities);
200 /* Set the enable spinup period but disable the ability to send
201 * notify enable spinup
203 writel(SCU_ENSPINUP_GEN_VAL(COUNT,
204 phy_user->notify_enable_spin_up_insertion_frequency),
205 &sci_phy->link_layer_registers->notify_enable_spinup_control);
207 /* Write the ALIGN Insertion Ferequency for connected phy and
208 * inpendent of connected state
210 clksm_value = SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(CONNECTED,
211 phy_user->in_connection_align_insertion_frequency);
213 clksm_value |= SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(GENERAL,
214 phy_user->align_insertion_frequency);
216 writel(clksm_value, &sci_phy->link_layer_registers->clock_skew_management);
218 /* @todo Provide a way to write this register correctly */
220 &sci_phy->link_layer_registers->afe_lookup_table_control);
222 llctl = SCU_SAS_LLCTL_GEN_VAL(NO_OUTBOUND_TASK_TIMEOUT,
223 (u8)scic->user_parameters.sds1.no_outbound_task_timeout);
225 switch(phy_user->max_speed_generation) {
226 case SCIC_SDS_PARM_GEN3_SPEED:
227 link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN3;
229 case SCIC_SDS_PARM_GEN2_SPEED:
230 link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN2;
233 link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN1;
236 llctl |= SCU_SAS_LLCTL_GEN_VAL(MAX_LINK_RATE, link_rate);
237 writel(llctl, &sci_phy->link_layer_registers->link_layer_control);
239 if (is_a0() || is_a2()) {
240 /* Program the max ARB time for the PHY to 700us so we inter-operate with
241 * the PMC expander which shuts down PHYs if the expander PHY generates too
242 * many breaks. This time value will guarantee that the initiator PHY will
243 * generate the break.
245 writel(SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME,
246 &sci_phy->link_layer_registers->maximum_arbitration_wait_timer_timeout);
250 * Set the link layer hang detection to 500ms (0x1F4) from its default
251 * value of 128ms. Max value is 511 ms.
253 writel(0x1F4, &sci_phy->link_layer_registers->link_layer_hang_detection_timeout);
255 /* We can exit the initial state to the stopped state */
256 sci_base_state_machine_change_state(&sci_phy->state_machine,
257 SCI_BASE_PHY_STATE_STOPPED);
263 * This function will handle the sata SIGNATURE FIS timeout condition. It will
264 * restart the starting substate machine since we dont know what has actually
267 static void scic_sds_phy_sata_timeout(void *phy)
269 struct scic_sds_phy *sci_phy = phy;
271 dev_dbg(sciphy_to_dev(sci_phy),
272 "%s: SCIC SDS Phy 0x%p did not receive signature fis before "
277 sci_base_state_machine_stop(&sci_phy->starting_substate_machine);
279 sci_base_state_machine_change_state(&sci_phy->state_machine,
280 SCI_BASE_PHY_STATE_STARTING);
284 * This method returns the port currently containing this phy. If the phy is
285 * currently contained by the dummy port, then the phy is considered to not
287 * @this_phy: This parameter specifies the phy for which to retrieve the
290 * This method returns a handle to a port that contains the supplied phy.
291 * NULL This value is returned if the phy is not part of a real
292 * port (i.e. it's contained in the dummy port). !NULL All other
293 * values indicate a handle/pointer to the port containing the phy.
295 struct scic_sds_port *scic_sds_phy_get_port(
296 struct scic_sds_phy *this_phy)
298 if (scic_sds_port_get_index(this_phy->owning_port) == SCIC_SDS_DUMMY_PORT)
301 return this_phy->owning_port;
305 * This method will assign a port to the phy object.
306 * @out]: this_phy This parameter specifies the phy for which to assign a port
311 void scic_sds_phy_set_port(
312 struct scic_sds_phy *this_phy,
313 struct scic_sds_port *the_port)
315 this_phy->owning_port = the_port;
317 if (this_phy->bcn_received_while_port_unassigned) {
318 this_phy->bcn_received_while_port_unassigned = false;
319 scic_sds_port_broadcast_change_received(this_phy->owning_port, this_phy);
324 * This method will initialize the constructed phy
326 * @link_layer_registers:
330 enum sci_status scic_sds_phy_initialize(
331 struct scic_sds_phy *sci_phy,
332 struct scu_transport_layer_registers __iomem *transport_layer_registers,
333 struct scu_link_layer_registers __iomem *link_layer_registers)
335 struct scic_sds_controller *scic = scic_sds_phy_get_controller(sci_phy);
336 struct isci_host *ihost = sci_object_get_association(scic);
338 /* Create the SIGNATURE FIS Timeout timer for this phy */
339 sci_phy->sata_timeout_timer =
343 scic_sds_phy_sata_timeout);
345 /* Perfrom the initialization of the TL hardware */
346 scic_sds_phy_transport_layer_initialization(
348 transport_layer_registers);
350 /* Perofrm the initialization of the PE hardware */
351 scic_sds_phy_link_layer_initialization(sci_phy, link_layer_registers);
354 * There is nothing that needs to be done in this state just
355 * transition to the stopped state. */
356 sci_base_state_machine_change_state(&sci_phy->state_machine,
357 SCI_BASE_PHY_STATE_STOPPED);
363 * This method assigns the direct attached device ID for this phy.
365 * @this_phy The phy for which the direct attached device id is to
367 * @device_id The direct attached device ID to assign to the phy.
368 * This will either be the RNi for the device or an invalid RNi if there
369 * is no current device assigned to the phy.
371 void scic_sds_phy_setup_transport(
372 struct scic_sds_phy *this_phy,
377 writel(device_id, &this_phy->transport_layer_registers->stp_rni);
380 * The read should guarantee that the first write gets posted
381 * before the next write
383 tl_control = readl(&this_phy->transport_layer_registers->control);
384 tl_control |= SCU_TLCR_GEN_BIT(CLEAR_TCI_NCQ_MAPPING_TABLE);
385 writel(tl_control, &this_phy->transport_layer_registers->control);
390 * @this_phy: The phy object to be suspended.
392 * This function will perform the register reads/writes to suspend the SCU
393 * hardware protocol engine. none
395 static void scic_sds_phy_suspend(
396 struct scic_sds_phy *this_phy)
398 u32 scu_sas_pcfg_value;
401 readl(&this_phy->link_layer_registers->phy_configuration);
402 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE);
403 writel(scu_sas_pcfg_value,
404 &this_phy->link_layer_registers->phy_configuration);
406 scic_sds_phy_setup_transport(this_phy, SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX);
411 * @this_phy: The phy object to resume.
413 * This function will perform the register reads/writes required to resume the
414 * SCU hardware protocol engine. none
416 void scic_sds_phy_resume(
417 struct scic_sds_phy *this_phy)
419 u32 scu_sas_pcfg_value;
422 readl(&this_phy->link_layer_registers->phy_configuration);
423 scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE);
424 writel(scu_sas_pcfg_value,
425 &this_phy->link_layer_registers->phy_configuration);
429 * This method returns the local sas address assigned to this phy.
430 * @this_phy: This parameter specifies the phy for which to retrieve the local
432 * @sas_address: This parameter specifies the location into which to copy the
436 void scic_sds_phy_get_sas_address(
437 struct scic_sds_phy *this_phy,
438 struct sci_sas_address *sas_address)
440 sas_address->high = readl(&this_phy->link_layer_registers->source_sas_address_high);
441 sas_address->low = readl(&this_phy->link_layer_registers->source_sas_address_low);
445 * This method returns the remote end-point (i.e. attached) sas address
446 * assigned to this phy.
447 * @this_phy: This parameter specifies the phy for which to retrieve the remote
448 * end-point SAS address.
449 * @sas_address: This parameter specifies the location into which to copy the
450 * remote end-point SAS address.
453 void scic_sds_phy_get_attached_sas_address(
454 struct scic_sds_phy *this_phy,
455 struct sci_sas_address *sas_address)
458 = this_phy->phy_type.sas.identify_address_frame_buffer.sas_address.high;
460 = this_phy->phy_type.sas.identify_address_frame_buffer.sas_address.low;
464 * This method returns the supported protocols assigned to this phy
469 void scic_sds_phy_get_protocols(
470 struct scic_sds_phy *this_phy,
471 struct sci_sas_identify_address_frame_protocols *protocols)
474 (u16)(readl(&this_phy->
475 link_layer_registers->transmit_identification) &
481 * @this_phy: The parameter is the phy object for which the attached phy
482 * protcols are to be returned.
484 * This method returns the supported protocols for the attached phy. If this
485 * is a SAS phy the protocols are returned from the identify address frame. If
486 * this is a SATA phy then protocols are made up and the target phy is an STP
487 * target phy. The caller will get the entire set of bits for the protocol
490 void scic_sds_phy_get_attached_phy_protocols(
491 struct scic_sds_phy *this_phy,
492 struct sci_sas_identify_address_frame_protocols *protocols)
494 protocols->u.all = 0;
496 if (this_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
498 this_phy->phy_type.sas.identify_address_frame_buffer.protocols.u.all;
499 } else if (this_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) {
500 protocols->u.bits.stp_target = 1;
505 * *****************************************************************************
506 * * SCIC SDS PHY Handler Redirects
507 * ***************************************************************************** */
510 * This method will attempt to start the phy object. This request is only valid
511 * when the phy is in the stopped state
516 enum sci_status scic_sds_phy_start(struct scic_sds_phy *sci_phy)
518 return sci_phy->state_handlers->start_handler(sci_phy);
522 * This method will attempt to stop the phy object.
525 * enum sci_status SCI_SUCCESS if the phy is going to stop SCI_INVALID_STATE
526 * if the phy is not in a valid state to stop
528 enum sci_status scic_sds_phy_stop(struct scic_sds_phy *sci_phy)
530 return sci_phy->state_handlers->stop_handler(sci_phy);
534 * This method will attempt to reset the phy. This request is only valid when
535 * the phy is in an ready state
540 enum sci_status scic_sds_phy_reset(
541 struct scic_sds_phy *this_phy)
543 return this_phy->state_handlers->reset_handler(this_phy);
547 * This method will process the event code received.
553 enum sci_status scic_sds_phy_event_handler(
554 struct scic_sds_phy *this_phy,
557 return this_phy->state_handlers->event_handler(this_phy, event_code);
561 * This method will process the frame index received.
567 enum sci_status scic_sds_phy_frame_handler(
568 struct scic_sds_phy *this_phy,
571 return this_phy->state_handlers->frame_handler(this_phy, frame_index);
575 * This method will give the phy permission to consume power
580 enum sci_status scic_sds_phy_consume_power_handler(
581 struct scic_sds_phy *this_phy)
583 return this_phy->state_handlers->consume_power_handler(this_phy);
587 * *****************************************************************************
588 * * SCIC PHY Public Methods
589 * ***************************************************************************** */
592 enum sci_status scic_sas_phy_get_properties(
593 struct scic_sds_phy *sci_phy,
594 struct scic_sas_phy_properties *properties)
596 if (sci_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
598 &properties->received_iaf,
599 &sci_phy->phy_type.sas.identify_address_frame_buffer,
600 sizeof(struct sci_sas_identify_address_frame)
603 properties->received_capabilities.u.all =
604 readl(&sci_phy->link_layer_registers->receive_phycap);
613 enum sci_status scic_sata_phy_get_properties(
614 struct scic_sds_phy *sci_phy,
615 struct scic_sata_phy_properties *properties)
617 if (sci_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) {
619 &properties->signature_fis,
620 &sci_phy->phy_type.sata.signature_fis_buffer,
621 sizeof(struct sata_fis_reg_d2h)
624 /* / @todo add support for port selectors. */
625 properties->is_port_selector_present = false;
634 * *****************************************************************************
635 * * SCIC SDS PHY HELPER FUNCTIONS
636 * ***************************************************************************** */
641 * @this_phy: The phy object that received SAS PHY DETECTED.
643 * This method continues the link training for the phy as if it were a SAS PHY
644 * instead of a SATA PHY. This is done because the completion queue had a SAS
645 * PHY DETECTED event when the state machine was expecting a SATA PHY event.
648 static void scic_sds_phy_start_sas_link_training(
649 struct scic_sds_phy *this_phy)
654 readl(&this_phy->link_layer_registers->phy_configuration);
655 phy_control |= SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD);
657 &this_phy->link_layer_registers->phy_configuration);
659 sci_base_state_machine_change_state(
660 &this_phy->starting_substate_machine,
661 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
664 this_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SAS;
669 * @this_phy: The phy object that received a SATA SPINUP HOLD event
671 * This method continues the link training for the phy as if it were a SATA PHY
672 * instead of a SAS PHY. This is done because the completion queue had a SATA
673 * SPINUP HOLD event when the state machine was expecting a SAS PHY event. none
675 static void scic_sds_phy_start_sata_link_training(
676 struct scic_sds_phy *this_phy)
678 sci_base_state_machine_change_state(
679 &this_phy->starting_substate_machine,
680 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
683 this_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
687 * scic_sds_phy_complete_link_training - perform processing common to
688 * all protocols upon completion of link training.
689 * @sci_phy: This parameter specifies the phy object for which link training
691 * @max_link_rate: This parameter specifies the maximum link rate to be
692 * associated with this phy.
693 * @next_state: This parameter specifies the next state for the phy's starting
697 static void scic_sds_phy_complete_link_training(
698 struct scic_sds_phy *sci_phy,
699 enum sas_linkrate max_link_rate,
702 sci_phy->max_negotiated_speed = max_link_rate;
704 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
708 static void scic_sds_phy_restart_starting_state(
709 struct scic_sds_phy *sci_phy)
711 /* Stop the current substate machine */
712 sci_base_state_machine_stop(&sci_phy->starting_substate_machine);
714 /* Re-enter the base state machine starting state */
715 sci_base_state_machine_change_state(&sci_phy->state_machine,
716 SCI_BASE_PHY_STATE_STARTING);
719 /* ****************************************************************************
720 * SCIC SDS PHY general handlers
721 ************************************************************************** */
722 static enum sci_status scic_sds_phy_starting_substate_general_stop_handler(
723 struct scic_sds_phy *phy)
725 sci_base_state_machine_stop(&phy->starting_substate_machine);
727 sci_base_state_machine_change_state(&phy->state_machine,
728 SCI_BASE_PHY_STATE_STOPPED);
734 * *****************************************************************************
735 * * SCIC SDS PHY EVENT_HANDLERS
736 * ***************************************************************************** */
740 * @phy: This struct scic_sds_phy object which has received an event.
741 * @event_code: This is the event code which the phy object is to decode.
743 * This method is called when an event notification is received for the phy
744 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. -
745 * decode the event - sas phy detected causes a state transition to the wait
746 * for speed event notification. - any other events log a warning message and
747 * set a failure status enum sci_status SCI_SUCCESS on any valid event notification
748 * SCI_FAILURE on any unexpected event notifation
750 static enum sci_status scic_sds_phy_starting_substate_await_ossp_event_handler(
751 struct scic_sds_phy *this_phy,
754 u32 result = SCI_SUCCESS;
756 switch (scu_get_event_code(event_code)) {
757 case SCU_EVENT_SAS_PHY_DETECTED:
758 scic_sds_phy_start_sas_link_training(this_phy);
759 this_phy->is_in_link_training = true;
762 case SCU_EVENT_SATA_SPINUP_HOLD:
763 scic_sds_phy_start_sata_link_training(this_phy);
764 this_phy->is_in_link_training = true;
768 dev_dbg(sciphy_to_dev(this_phy),
769 "%s: PHY starting substate machine received "
770 "unexpected event_code %x\n",
774 result = SCI_FAILURE;
783 * @phy: This struct scic_sds_phy object which has received an event.
784 * @event_code: This is the event code which the phy object is to decode.
786 * This method is called when an event notification is received for the phy
787 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. -
788 * decode the event - sas phy detected returns us back to this state. - speed
789 * event detected causes a state transition to the wait for iaf. - identify
790 * timeout is an un-expected event and the state machine is restarted. - link
791 * failure events restart the starting state machine - any other events log a
792 * warning message and set a failure status enum sci_status SCI_SUCCESS on any valid
793 * event notification SCI_FAILURE on any unexpected event notifation
795 static enum sci_status scic_sds_phy_starting_substate_await_sas_phy_speed_event_handler(
796 struct scic_sds_phy *this_phy,
799 u32 result = SCI_SUCCESS;
801 switch (scu_get_event_code(event_code)) {
802 case SCU_EVENT_SAS_PHY_DETECTED:
804 * Why is this being reported again by the controller?
805 * We would re-enter this state so just stay here */
808 case SCU_EVENT_SAS_15:
809 case SCU_EVENT_SAS_15_SSC:
810 scic_sds_phy_complete_link_training(
811 this_phy, SAS_LINK_RATE_1_5_GBPS, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
815 case SCU_EVENT_SAS_30:
816 case SCU_EVENT_SAS_30_SSC:
817 scic_sds_phy_complete_link_training(
818 this_phy, SAS_LINK_RATE_3_0_GBPS, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
822 case SCU_EVENT_SAS_60:
823 case SCU_EVENT_SAS_60_SSC:
824 scic_sds_phy_complete_link_training(
825 this_phy, SAS_LINK_RATE_6_0_GBPS, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
829 case SCU_EVENT_SATA_SPINUP_HOLD:
831 * We were doing SAS PHY link training and received a SATA PHY event
832 * continue OOB/SN as if this were a SATA PHY */
833 scic_sds_phy_start_sata_link_training(this_phy);
836 case SCU_EVENT_LINK_FAILURE:
837 /* Link failure change state back to the starting state */
838 scic_sds_phy_restart_starting_state(this_phy);
842 dev_warn(sciphy_to_dev(this_phy),
843 "%s: PHY starting substate machine received "
844 "unexpected event_code %x\n",
848 result = SCI_FAILURE;
857 * @phy: This struct scic_sds_phy object which has received an event.
858 * @event_code: This is the event code which the phy object is to decode.
860 * This method is called when an event notification is received for the phy
861 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. -
862 * decode the event - sas phy detected event backs up the state machine to the
863 * await speed notification. - identify timeout is an un-expected event and the
864 * state machine is restarted. - link failure events restart the starting state
865 * machine - any other events log a warning message and set a failure status
866 * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any
867 * unexpected event notifation
869 static enum sci_status scic_sds_phy_starting_substate_await_iaf_uf_event_handler(
870 struct scic_sds_phy *this_phy,
873 u32 result = SCI_SUCCESS;
875 switch (scu_get_event_code(event_code)) {
876 case SCU_EVENT_SAS_PHY_DETECTED:
877 /* Backup the state machine */
878 scic_sds_phy_start_sas_link_training(this_phy);
881 case SCU_EVENT_SATA_SPINUP_HOLD:
883 * We were doing SAS PHY link training and received a SATA PHY event
884 * continue OOB/SN as if this were a SATA PHY */
885 scic_sds_phy_start_sata_link_training(this_phy);
888 case SCU_EVENT_RECEIVED_IDENTIFY_TIMEOUT:
889 case SCU_EVENT_LINK_FAILURE:
890 case SCU_EVENT_HARD_RESET_RECEIVED:
891 /* Start the oob/sn state machine over again */
892 scic_sds_phy_restart_starting_state(this_phy);
896 dev_warn(sciphy_to_dev(this_phy),
897 "%s: PHY starting substate machine received "
898 "unexpected event_code %x\n",
902 result = SCI_FAILURE;
911 * @phy: This struct scic_sds_phy object which has received an event.
912 * @event_code: This is the event code which the phy object is to decode.
914 * This method is called when an event notification is received for the phy
915 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_POWER. -
916 * decode the event - link failure events restart the starting state machine -
917 * any other events log a warning message and set a failure status enum sci_status
918 * SCI_SUCCESS on a link failure event SCI_FAILURE on any unexpected event
921 static enum sci_status scic_sds_phy_starting_substate_await_sas_power_event_handler(
922 struct scic_sds_phy *this_phy,
925 u32 result = SCI_SUCCESS;
927 switch (scu_get_event_code(event_code)) {
928 case SCU_EVENT_LINK_FAILURE:
929 /* Link failure change state back to the starting state */
930 scic_sds_phy_restart_starting_state(this_phy);
934 dev_warn(sciphy_to_dev(this_phy),
935 "%s: PHY starting substate machine received unexpected "
940 result = SCI_FAILURE;
949 * @phy: This struct scic_sds_phy object which has received an event.
950 * @event_code: This is the event code which the phy object is to decode.
952 * This method is called when an event notification is received for the phy
953 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. -
954 * decode the event - link failure events restart the starting state machine -
955 * sata spinup hold events are ignored since they are expected - any other
956 * events log a warning message and set a failure status enum sci_status SCI_SUCCESS
957 * on a link failure event SCI_FAILURE on any unexpected event notifation
959 static enum sci_status scic_sds_phy_starting_substate_await_sata_power_event_handler(
960 struct scic_sds_phy *this_phy,
963 u32 result = SCI_SUCCESS;
965 switch (scu_get_event_code(event_code)) {
966 case SCU_EVENT_LINK_FAILURE:
967 /* Link failure change state back to the starting state */
968 scic_sds_phy_restart_starting_state(this_phy);
971 case SCU_EVENT_SATA_SPINUP_HOLD:
972 /* These events are received every 10ms and are expected while in this state */
975 case SCU_EVENT_SAS_PHY_DETECTED:
977 * There has been a change in the phy type before OOB/SN for the
978 * SATA finished start down the SAS link traning path. */
979 scic_sds_phy_start_sas_link_training(this_phy);
983 dev_warn(sciphy_to_dev(this_phy),
984 "%s: PHY starting substate machine received "
985 "unexpected event_code %x\n",
989 result = SCI_FAILURE;
997 * scic_sds_phy_starting_substate_await_sata_phy_event_handler -
998 * @phy: This struct scic_sds_phy object which has received an event.
999 * @event_code: This is the event code which the phy object is to decode.
1001 * This method is called when an event notification is received for the phy
1002 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. -
1003 * decode the event - link failure events restart the starting state machine -
1004 * sata spinup hold events are ignored since they are expected - sata phy
1005 * detected event change to the wait speed event - any other events log a
1006 * warning message and set a failure status enum sci_status SCI_SUCCESS on a link
1007 * failure event SCI_FAILURE on any unexpected event notifation
1009 static enum sci_status scic_sds_phy_starting_substate_await_sata_phy_event_handler(
1010 struct scic_sds_phy *sci_phy, u32 event_code)
1012 u32 result = SCI_SUCCESS;
1014 switch (scu_get_event_code(event_code)) {
1015 case SCU_EVENT_LINK_FAILURE:
1016 /* Link failure change state back to the starting state */
1017 scic_sds_phy_restart_starting_state(sci_phy);
1020 case SCU_EVENT_SATA_SPINUP_HOLD:
1021 /* These events might be received since we dont know how many may be in
1022 * the completion queue while waiting for power
1026 case SCU_EVENT_SATA_PHY_DETECTED:
1027 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
1029 /* We have received the SATA PHY notification change state */
1030 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
1031 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN);
1034 case SCU_EVENT_SAS_PHY_DETECTED:
1035 /* There has been a change in the phy type before OOB/SN for the
1036 * SATA finished start down the SAS link traning path.
1038 scic_sds_phy_start_sas_link_training(sci_phy);
1042 dev_warn(sciphy_to_dev(sci_phy),
1043 "%s: PHY starting substate machine received "
1044 "unexpected event_code %x\n",
1048 result = SCI_FAILURE;
1057 * @phy: This struct scic_sds_phy object which has received an event.
1058 * @event_code: This is the event code which the phy object is to decode.
1060 * This method is called when an event notification is received for the phy
1061 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN.
1062 * - decode the event - sata phy detected returns us back to this state. -
1063 * speed event detected causes a state transition to the wait for signature. -
1064 * link failure events restart the starting state machine - any other events
1065 * log a warning message and set a failure status enum sci_status SCI_SUCCESS on any
1066 * valid event notification SCI_FAILURE on any unexpected event notifation
1068 static enum sci_status scic_sds_phy_starting_substate_await_sata_speed_event_handler(
1069 struct scic_sds_phy *this_phy,
1072 u32 result = SCI_SUCCESS;
1074 switch (scu_get_event_code(event_code)) {
1075 case SCU_EVENT_SATA_PHY_DETECTED:
1077 * The hardware reports multiple SATA PHY detected events
1078 * ignore the extras */
1081 case SCU_EVENT_SATA_15:
1082 case SCU_EVENT_SATA_15_SSC:
1083 scic_sds_phy_complete_link_training(
1085 SAS_LINK_RATE_1_5_GBPS,
1086 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
1090 case SCU_EVENT_SATA_30:
1091 case SCU_EVENT_SATA_30_SSC:
1092 scic_sds_phy_complete_link_training(
1094 SAS_LINK_RATE_3_0_GBPS,
1095 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
1099 case SCU_EVENT_SATA_60:
1100 case SCU_EVENT_SATA_60_SSC:
1101 scic_sds_phy_complete_link_training(
1103 SAS_LINK_RATE_6_0_GBPS,
1104 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF
1108 case SCU_EVENT_LINK_FAILURE:
1109 /* Link failure change state back to the starting state */
1110 scic_sds_phy_restart_starting_state(this_phy);
1113 case SCU_EVENT_SAS_PHY_DETECTED:
1115 * There has been a change in the phy type before OOB/SN for the
1116 * SATA finished start down the SAS link traning path. */
1117 scic_sds_phy_start_sas_link_training(this_phy);
1121 dev_warn(sciphy_to_dev(this_phy),
1122 "%s: PHY starting substate machine received "
1123 "unexpected event_code %x\n",
1127 result = SCI_FAILURE;
1135 * scic_sds_phy_starting_substate_await_sig_fis_event_handler -
1136 * @phy: This struct scic_sds_phy object which has received an event.
1137 * @event_code: This is the event code which the phy object is to decode.
1139 * This method is called when an event notification is received for the phy
1140 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. -
1141 * decode the event - sas phy detected event backs up the state machine to the
1142 * await speed notification. - identify timeout is an un-expected event and the
1143 * state machine is restarted. - link failure events restart the starting state
1144 * machine - any other events log a warning message and set a failure status
1145 * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any
1146 * unexpected event notifation
1148 static enum sci_status scic_sds_phy_starting_substate_await_sig_fis_event_handler(
1149 struct scic_sds_phy *sci_phy, u32 event_code)
1151 u32 result = SCI_SUCCESS;
1153 switch (scu_get_event_code(event_code)) {
1154 case SCU_EVENT_SATA_PHY_DETECTED:
1155 /* Backup the state machine */
1156 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
1157 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN);
1160 case SCU_EVENT_LINK_FAILURE:
1161 /* Link failure change state back to the starting state */
1162 scic_sds_phy_restart_starting_state(sci_phy);
1166 dev_warn(sciphy_to_dev(sci_phy),
1167 "%s: PHY starting substate machine received "
1168 "unexpected event_code %x\n",
1172 result = SCI_FAILURE;
1181 * *****************************************************************************
1182 * * SCIC SDS PHY FRAME_HANDLERS
1183 * ***************************************************************************** */
1187 * @phy: This is struct scic_sds_phy object which is being requested to decode the
1189 * @frame_index: This is the index of the unsolicited frame which was received
1192 * This method decodes the unsolicited frame when the struct scic_sds_phy is in the
1193 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - Get the UF Header - If the UF
1194 * is an IAF - Copy IAF data to local phy object IAF data buffer. - Change
1195 * starting substate to wait power. - else - log warning message of unexpected
1196 * unsolicted frame - release frame buffer enum sci_status SCI_SUCCESS
1198 static enum sci_status scic_sds_phy_starting_substate_await_iaf_uf_frame_handler(
1199 struct scic_sds_phy *sci_phy, u32 frame_index)
1201 enum sci_status result;
1203 struct sci_sas_identify_address_frame *identify_frame;
1205 result = scic_sds_unsolicited_frame_control_get_header(
1206 &(scic_sds_phy_get_controller(sci_phy)->uf_control),
1208 (void **)&frame_words);
1210 if (result != SCI_SUCCESS) {
1214 frame_words[0] = SCIC_SWAP_DWORD(frame_words[0]);
1215 identify_frame = (struct sci_sas_identify_address_frame *)frame_words;
1217 if (identify_frame->address_frame_type == 0) {
1220 /* Byte swap the rest of the frame so we can make
1221 * a copy of the buffer
1223 frame_words[1] = SCIC_SWAP_DWORD(frame_words[1]);
1224 frame_words[2] = SCIC_SWAP_DWORD(frame_words[2]);
1225 frame_words[3] = SCIC_SWAP_DWORD(frame_words[3]);
1226 frame_words[4] = SCIC_SWAP_DWORD(frame_words[4]);
1227 frame_words[5] = SCIC_SWAP_DWORD(frame_words[5]);
1229 memcpy(&sci_phy->phy_type.sas.identify_address_frame_buffer,
1231 sizeof(struct sci_sas_identify_address_frame));
1233 if (identify_frame->protocols.u.bits.smp_target) {
1234 /* We got the IAF for an expander PHY go to the final state since
1235 * there are no power requirements for expander phys.
1237 state = SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL;
1239 /* We got the IAF we can now go to the await spinup semaphore state */
1240 state = SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER;
1242 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
1244 result = SCI_SUCCESS;
1246 dev_warn(sciphy_to_dev(sci_phy),
1247 "%s: PHY starting substate machine received "
1248 "unexpected frame id %x\n",
1252 /* Regardless of the result release this frame since we are done with it */
1253 scic_sds_controller_release_frame(scic_sds_phy_get_controller(sci_phy),
1261 * @phy: This is struct scic_sds_phy object which is being requested to decode the
1263 * @frame_index: This is the index of the unsolicited frame which was received
1266 * This method decodes the unsolicited frame when the struct scic_sds_phy is in the
1267 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Get the UF Header - If
1268 * the UF is an SIGNATURE FIS - Copy IAF data to local phy object SIGNATURE FIS
1269 * data buffer. - else - log warning message of unexpected unsolicted frame -
1270 * release frame buffer enum sci_status SCI_SUCCESS Must decode the SIGNATURE FIS
1273 static enum sci_status scic_sds_phy_starting_substate_await_sig_fis_frame_handler(
1274 struct scic_sds_phy *sci_phy,
1277 enum sci_status result;
1279 struct sata_fis_header *fis_frame_header;
1280 u32 *fis_frame_data;
1282 result = scic_sds_unsolicited_frame_control_get_header(
1283 &(scic_sds_phy_get_controller(sci_phy)->uf_control),
1285 (void **)&frame_words);
1287 if (result != SCI_SUCCESS) {
1291 fis_frame_header = (struct sata_fis_header *)frame_words;
1293 if ((fis_frame_header->fis_type == SATA_FIS_TYPE_REGD2H) &&
1294 !(fis_frame_header->status & ATA_STATUS_REG_BSY_BIT)) {
1295 scic_sds_unsolicited_frame_control_get_buffer(
1296 &(scic_sds_phy_get_controller(sci_phy)->uf_control),
1298 (void **)&fis_frame_data);
1300 scic_sds_controller_copy_sata_response(
1301 &sci_phy->phy_type.sata.signature_fis_buffer,
1305 /* We got the IAF we can now go to the await spinup semaphore state */
1306 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
1307 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL);
1309 result = SCI_SUCCESS;
1311 dev_warn(sciphy_to_dev(sci_phy),
1312 "%s: PHY starting substate machine received "
1313 "unexpected frame id %x\n",
1317 /* Regardless of the result release this frame since we are done with it */
1318 scic_sds_controller_release_frame(scic_sds_phy_get_controller(sci_phy),
1325 * *****************************************************************************
1326 * * SCIC SDS PHY POWER_HANDLERS
1327 * ***************************************************************************** */
1330 * This method is called by the struct scic_sds_controller when the phy object is
1331 * granted power. - The notify enable spinups are turned on for this phy object
1332 * - The phy state machine is transitioned to the
1333 * SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. enum sci_status SCI_SUCCESS
1335 static enum sci_status scic_sds_phy_starting_substate_await_sas_power_consume_power_handler(
1336 struct scic_sds_phy *sci_phy)
1340 enable_spinup = readl(&sci_phy->link_layer_registers->notify_enable_spinup_control);
1341 enable_spinup |= SCU_ENSPINUP_GEN_BIT(ENABLE);
1342 writel(enable_spinup, &sci_phy->link_layer_registers->notify_enable_spinup_control);
1344 /* Change state to the final state this substate machine has run to completion */
1345 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
1346 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL);
1352 * This method is called by the struct scic_sds_controller when the phy object is
1353 * granted power. - The phy state machine is transitioned to the
1354 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. enum sci_status SCI_SUCCESS
1356 static enum sci_status scic_sds_phy_starting_substate_await_sata_power_consume_power_handler(
1357 struct scic_sds_phy *sci_phy)
1359 u32 scu_sas_pcfg_value;
1361 /* Release the spinup hold state and reset the OOB state machine */
1362 scu_sas_pcfg_value =
1363 readl(&sci_phy->link_layer_registers->phy_configuration);
1364 scu_sas_pcfg_value &=
1365 ~(SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD) | SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE));
1366 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
1367 writel(scu_sas_pcfg_value,
1368 &sci_phy->link_layer_registers->phy_configuration);
1370 /* Now restart the OOB operation */
1371 scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
1372 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
1373 writel(scu_sas_pcfg_value,
1374 &sci_phy->link_layer_registers->phy_configuration);
1376 /* Change state to the final state this substate machine has run to completion */
1377 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
1378 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN);
1383 static enum sci_status default_phy_handler(struct scic_sds_phy *sci_phy,
1386 dev_dbg(sciphy_to_dev(sci_phy),
1387 "%s: in wrong state: %d\n", func,
1388 sci_base_state_machine_get_state(&sci_phy->state_machine));
1389 return SCI_FAILURE_INVALID_STATE;
1392 static enum sci_status
1393 scic_sds_phy_default_start_handler(struct scic_sds_phy *sci_phy)
1395 return default_phy_handler(sci_phy, __func__);
1398 static enum sci_status
1399 scic_sds_phy_default_stop_handler(struct scic_sds_phy *sci_phy)
1401 return default_phy_handler(sci_phy, __func__);
1404 static enum sci_status
1405 scic_sds_phy_default_reset_handler(struct scic_sds_phy *sci_phy)
1407 return default_phy_handler(sci_phy, __func__);
1410 static enum sci_status
1411 scic_sds_phy_default_destroy_handler(struct scic_sds_phy *sci_phy)
1413 return default_phy_handler(sci_phy, __func__);
1416 static enum sci_status
1417 scic_sds_phy_default_frame_handler(struct scic_sds_phy *sci_phy,
1420 struct scic_sds_controller *scic = scic_sds_phy_get_controller(sci_phy);
1422 default_phy_handler(sci_phy, __func__);
1423 scic_sds_controller_release_frame(scic, frame_index);
1425 return SCI_FAILURE_INVALID_STATE;
1428 static enum sci_status
1429 scic_sds_phy_default_event_handler(struct scic_sds_phy *sci_phy,
1432 return default_phy_handler(sci_phy, __func__);
1435 static enum sci_status
1436 scic_sds_phy_default_consume_power_handler(struct scic_sds_phy *sci_phy)
1438 return default_phy_handler(sci_phy, __func__);
1443 static const struct scic_sds_phy_state_handler scic_sds_phy_starting_substate_handler_table[] = {
1444 [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL] = {
1445 .start_handler = scic_sds_phy_default_start_handler,
1446 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1447 .reset_handler = scic_sds_phy_default_reset_handler,
1448 .destruct_handler = scic_sds_phy_default_destroy_handler,
1449 .frame_handler = scic_sds_phy_default_frame_handler,
1450 .event_handler = scic_sds_phy_default_event_handler,
1451 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1453 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN] = {
1454 .start_handler = scic_sds_phy_default_start_handler,
1455 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1456 .reset_handler = scic_sds_phy_default_reset_handler,
1457 .destruct_handler = scic_sds_phy_default_destroy_handler,
1458 .frame_handler = scic_sds_phy_default_frame_handler,
1459 .event_handler = scic_sds_phy_starting_substate_await_ossp_event_handler,
1460 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1462 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN] = {
1463 .start_handler = scic_sds_phy_default_start_handler,
1464 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1465 .reset_handler = scic_sds_phy_default_reset_handler,
1466 .destruct_handler = scic_sds_phy_default_destroy_handler,
1467 .frame_handler = scic_sds_phy_default_frame_handler,
1468 .event_handler = scic_sds_phy_starting_substate_await_sas_phy_speed_event_handler,
1469 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1471 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF] = {
1472 .start_handler = scic_sds_phy_default_start_handler,
1473 .stop_handler = scic_sds_phy_default_stop_handler,
1474 .reset_handler = scic_sds_phy_default_reset_handler,
1475 .destruct_handler = scic_sds_phy_default_destroy_handler,
1476 .frame_handler = scic_sds_phy_starting_substate_await_iaf_uf_frame_handler,
1477 .event_handler = scic_sds_phy_starting_substate_await_iaf_uf_event_handler,
1478 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1480 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER] = {
1481 .start_handler = scic_sds_phy_default_start_handler,
1482 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1483 .reset_handler = scic_sds_phy_default_reset_handler,
1484 .destruct_handler = scic_sds_phy_default_destroy_handler,
1485 .frame_handler = scic_sds_phy_default_frame_handler,
1486 .event_handler = scic_sds_phy_starting_substate_await_sas_power_event_handler,
1487 .consume_power_handler = scic_sds_phy_starting_substate_await_sas_power_consume_power_handler
1489 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER] = {
1490 .start_handler = scic_sds_phy_default_start_handler,
1491 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1492 .reset_handler = scic_sds_phy_default_reset_handler,
1493 .destruct_handler = scic_sds_phy_default_destroy_handler,
1494 .frame_handler = scic_sds_phy_default_frame_handler,
1495 .event_handler = scic_sds_phy_starting_substate_await_sata_power_event_handler,
1496 .consume_power_handler = scic_sds_phy_starting_substate_await_sata_power_consume_power_handler
1498 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN] = {
1499 .start_handler = scic_sds_phy_default_start_handler,
1500 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1501 .reset_handler = scic_sds_phy_default_reset_handler,
1502 .destruct_handler = scic_sds_phy_default_destroy_handler,
1503 .frame_handler = scic_sds_phy_default_frame_handler,
1504 .event_handler = scic_sds_phy_starting_substate_await_sata_phy_event_handler,
1505 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1507 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN] = {
1508 .start_handler = scic_sds_phy_default_start_handler,
1509 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1510 .reset_handler = scic_sds_phy_default_reset_handler,
1511 .destruct_handler = scic_sds_phy_default_destroy_handler,
1512 .frame_handler = scic_sds_phy_default_frame_handler,
1513 .event_handler = scic_sds_phy_starting_substate_await_sata_speed_event_handler,
1514 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1516 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF] = {
1517 .start_handler = scic_sds_phy_default_start_handler,
1518 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1519 .reset_handler = scic_sds_phy_default_reset_handler,
1520 .destruct_handler = scic_sds_phy_default_destroy_handler,
1521 .frame_handler = scic_sds_phy_starting_substate_await_sig_fis_frame_handler,
1522 .event_handler = scic_sds_phy_starting_substate_await_sig_fis_event_handler,
1523 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1525 [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL] = {
1526 .start_handler = scic_sds_phy_default_start_handler,
1527 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1528 .reset_handler = scic_sds_phy_default_reset_handler,
1529 .destruct_handler = scic_sds_phy_default_destroy_handler,
1530 .frame_handler = scic_sds_phy_default_frame_handler,
1531 .event_handler = scic_sds_phy_default_event_handler,
1532 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1537 * scic_sds_phy_set_starting_substate_handlers() -
1539 * This macro sets the starting substate handlers by state_id
1541 #define scic_sds_phy_set_starting_substate_handlers(phy, state_id) \
1542 scic_sds_phy_set_state_handlers(\
1544 &scic_sds_phy_starting_substate_handler_table[(state_id)] \
1548 * ****************************************************************************
1549 * * PHY STARTING SUBSTATE METHODS
1550 * **************************************************************************** */
1553 * scic_sds_phy_starting_initial_substate_enter -
1554 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
1556 * This method will perform the actions required by the struct scic_sds_phy on
1557 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL. - The initial state
1558 * handlers are put in place for the struct scic_sds_phy object. - The state is
1559 * changed to the wait phy type event notification. none
1561 static void scic_sds_phy_starting_initial_substate_enter(struct sci_base_object *object)
1563 struct scic_sds_phy *sci_phy;
1565 sci_phy = (struct scic_sds_phy *)object;
1567 scic_sds_phy_set_starting_substate_handlers(
1568 sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL);
1570 /* This is just an temporary state go off to the starting state */
1571 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
1572 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN);
1577 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
1579 * This method will perform the actions required by the struct scic_sds_phy on
1580 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_PHY_TYPE_EN. - Set the
1581 * struct scic_sds_phy object state handlers for this state. none
1583 static void scic_sds_phy_starting_await_ossp_en_substate_enter(
1584 struct sci_base_object *object)
1586 struct scic_sds_phy *this_phy;
1588 this_phy = (struct scic_sds_phy *)object;
1590 scic_sds_phy_set_starting_substate_handlers(
1591 this_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
1597 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
1599 * This method will perform the actions required by the struct scic_sds_phy on
1600 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. - Set the
1601 * struct scic_sds_phy object state handlers for this state. none
1603 static void scic_sds_phy_starting_await_sas_speed_en_substate_enter(
1604 struct sci_base_object *object)
1606 struct scic_sds_phy *this_phy;
1608 this_phy = (struct scic_sds_phy *)object;
1610 scic_sds_phy_set_starting_substate_handlers(
1611 this_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
1617 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
1619 * This method will perform the actions required by the struct scic_sds_phy on
1620 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - Set the
1621 * struct scic_sds_phy object state handlers for this state. none
1623 static void scic_sds_phy_starting_await_iaf_uf_substate_enter(
1624 struct sci_base_object *object)
1626 struct scic_sds_phy *this_phy;
1628 this_phy = (struct scic_sds_phy *)object;
1630 scic_sds_phy_set_starting_substate_handlers(
1631 this_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
1637 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
1639 * This method will perform the actions required by the struct scic_sds_phy on
1640 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Set the
1641 * struct scic_sds_phy object state handlers for this state. - Add this phy object to
1642 * the power control queue none
1644 static void scic_sds_phy_starting_await_sas_power_substate_enter(
1645 struct sci_base_object *object)
1647 struct scic_sds_phy *this_phy;
1649 this_phy = (struct scic_sds_phy *)object;
1651 scic_sds_phy_set_starting_substate_handlers(
1652 this_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
1655 scic_sds_controller_power_control_queue_insert(
1656 scic_sds_phy_get_controller(this_phy),
1663 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
1665 * This method will perform the actions required by the struct scic_sds_phy on exiting
1666 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Remove the
1667 * struct scic_sds_phy object from the power control queue. none
1669 static void scic_sds_phy_starting_await_sas_power_substate_exit(
1670 struct sci_base_object *object)
1672 struct scic_sds_phy *this_phy;
1674 this_phy = (struct scic_sds_phy *)object;
1676 scic_sds_controller_power_control_queue_remove(
1677 scic_sds_phy_get_controller(this_phy), this_phy
1683 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
1685 * This method will perform the actions required by the struct scic_sds_phy on
1686 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Set the
1687 * struct scic_sds_phy object state handlers for this state. - Add this phy object to
1688 * the power control queue none
1690 static void scic_sds_phy_starting_await_sata_power_substate_enter(
1691 struct sci_base_object *object)
1693 struct scic_sds_phy *this_phy;
1695 this_phy = (struct scic_sds_phy *)object;
1697 scic_sds_phy_set_starting_substate_handlers(
1698 this_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
1701 scic_sds_controller_power_control_queue_insert(
1702 scic_sds_phy_get_controller(this_phy),
1709 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
1711 * This method will perform the actions required by the struct scic_sds_phy on exiting
1712 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Remove the
1713 * struct scic_sds_phy object from the power control queue. none
1715 static void scic_sds_phy_starting_await_sata_power_substate_exit(
1716 struct sci_base_object *object)
1718 struct scic_sds_phy *this_phy;
1720 this_phy = (struct scic_sds_phy *)object;
1722 scic_sds_controller_power_control_queue_remove(
1723 scic_sds_phy_get_controller(this_phy),
1730 * @object: This is the struct sci_base_object which is cast to a
1731 * struct scic_sds_phy object.
1733 * This function will perform the actions required by the struct scic_sds_phy on
1734 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. - Set the
1735 * struct scic_sds_phy object state handlers for this state. none
1737 static void scic_sds_phy_starting_await_sata_phy_substate_enter(
1738 struct sci_base_object *object)
1740 struct scic_sds_phy *sci_phy = (struct scic_sds_phy *)object;
1742 scic_sds_phy_set_starting_substate_handlers(
1744 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN);
1746 isci_timer_start(sci_phy->sata_timeout_timer,
1747 SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
1752 * @object: This is the struct sci_base_object which is cast to a
1753 * struct scic_sds_phy object.
1755 * This method will perform the actions required by the struct scic_sds_phy
1757 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
1758 * that was started on entry to await sata phy event notification none
1760 static inline void scic_sds_phy_starting_await_sata_phy_substate_exit(
1761 struct sci_base_object *object)
1763 struct scic_sds_phy *sci_phy = (struct scic_sds_phy *)object;
1765 isci_timer_stop(sci_phy->sata_timeout_timer);
1770 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
1772 * This method will perform the actions required by the struct scic_sds_phy on
1773 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - Set the
1774 * struct scic_sds_phy object state handlers for this state. none
1776 static void scic_sds_phy_starting_await_sata_speed_substate_enter(
1777 struct sci_base_object *object)
1779 struct scic_sds_phy *sci_phy = (struct scic_sds_phy *)object;
1781 scic_sds_phy_set_starting_substate_handlers(
1783 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN);
1785 isci_timer_start(sci_phy->sata_timeout_timer,
1786 SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
1791 * @object: This is the struct sci_base_object which is cast to a
1792 * struct scic_sds_phy object.
1794 * This function will perform the actions required by the
1795 * struct scic_sds_phy on exiting
1796 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
1797 * that was started on entry to await sata phy event notification none
1799 static inline void scic_sds_phy_starting_await_sata_speed_substate_exit(
1800 struct sci_base_object *object)
1802 struct scic_sds_phy *sci_phy = (struct scic_sds_phy *)object;
1804 isci_timer_stop(sci_phy->sata_timeout_timer);
1809 * @object: This is the struct sci_base_object which is cast to a
1810 * struct scic_sds_phy object.
1812 * This function will perform the actions required by the struct scic_sds_phy on
1813 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Set the
1814 * struct scic_sds_phy object state handlers for this state.
1815 * - Start the SIGNATURE FIS
1816 * timeout timer none
1818 static void scic_sds_phy_starting_await_sig_fis_uf_substate_enter(
1819 struct sci_base_object *object)
1821 bool continue_to_ready_state;
1822 struct scic_sds_phy *sci_phy = (struct scic_sds_phy *)object;
1824 scic_sds_phy_set_starting_substate_handlers(
1826 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
1828 continue_to_ready_state = scic_sds_port_link_detected(
1829 sci_phy->owning_port,
1832 if (continue_to_ready_state) {
1834 * Clear the PE suspend condition so we can actually
1836 * The hardware will not respond to the XRDY until the PE
1837 * suspend condition is cleared.
1839 scic_sds_phy_resume(sci_phy);
1841 isci_timer_start(sci_phy->sata_timeout_timer,
1842 SCIC_SDS_SIGNATURE_FIS_TIMEOUT);
1844 sci_phy->is_in_link_training = false;
1849 * @object: This is the struct sci_base_object which is cast to a
1850 * 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(
1858 struct sci_base_object *object)
1860 struct scic_sds_phy *sci_phy;
1862 sci_phy = (struct scic_sds_phy *)object;
1864 isci_timer_stop(sci_phy->sata_timeout_timer);
1869 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
1871 * This method will perform the actions required by the struct scic_sds_phy on
1872 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. - Set the struct scic_sds_phy
1873 * object state handlers for this state. - Change base state machine to the
1876 static void scic_sds_phy_starting_final_substate_enter(struct sci_base_object *object)
1878 struct scic_sds_phy *sci_phy;
1880 sci_phy = container_of(object, typeof(*sci_phy), parent);
1882 scic_sds_phy_set_starting_substate_handlers(sci_phy,
1883 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL);
1885 /* State machine has run to completion so exit out and change
1886 * the base state machine to the ready state
1888 sci_base_state_machine_change_state(&sci_phy->state_machine,
1889 SCI_BASE_PHY_STATE_READY);
1892 /* --------------------------------------------------------------------------- */
1894 static const struct sci_base_state scic_sds_phy_starting_substates[] = {
1895 [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL] = {
1896 .enter_state = scic_sds_phy_starting_initial_substate_enter,
1898 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN] = {
1899 .enter_state = scic_sds_phy_starting_await_ossp_en_substate_enter,
1901 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN] = {
1902 .enter_state = scic_sds_phy_starting_await_sas_speed_en_substate_enter,
1904 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF] = {
1905 .enter_state = scic_sds_phy_starting_await_iaf_uf_substate_enter,
1907 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER] = {
1908 .enter_state = scic_sds_phy_starting_await_sas_power_substate_enter,
1909 .exit_state = scic_sds_phy_starting_await_sas_power_substate_exit,
1911 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER] = {
1912 .enter_state = scic_sds_phy_starting_await_sata_power_substate_enter,
1913 .exit_state = scic_sds_phy_starting_await_sata_power_substate_exit
1915 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN] = {
1916 .enter_state = scic_sds_phy_starting_await_sata_phy_substate_enter,
1917 .exit_state = scic_sds_phy_starting_await_sata_phy_substate_exit
1919 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN] = {
1920 .enter_state = scic_sds_phy_starting_await_sata_speed_substate_enter,
1921 .exit_state = scic_sds_phy_starting_await_sata_speed_substate_exit
1923 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF] = {
1924 .enter_state = scic_sds_phy_starting_await_sig_fis_uf_substate_enter,
1925 .exit_state = scic_sds_phy_starting_await_sig_fis_uf_substate_exit
1927 [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL] = {
1928 .enter_state = scic_sds_phy_starting_final_substate_enter,
1933 * This method takes the struct scic_sds_phy from a stopped state and
1934 * attempts to start it. - The phy state machine is transitioned to the
1935 * SCI_BASE_PHY_STATE_STARTING. enum sci_status SCI_SUCCESS
1937 static enum sci_status
1938 scic_sds_phy_stopped_state_start_handler(struct scic_sds_phy *sci_phy)
1940 struct isci_host *ihost;
1941 struct scic_sds_controller *scic;
1943 scic = scic_sds_phy_get_controller(sci_phy),
1944 ihost = sci_object_get_association(scic);
1946 /* Create the SIGNATURE FIS Timeout timer for this phy */
1947 sci_phy->sata_timeout_timer = isci_timer_create(ihost, sci_phy,
1948 scic_sds_phy_sata_timeout);
1950 if (sci_phy->sata_timeout_timer)
1951 sci_base_state_machine_change_state(&sci_phy->state_machine,
1952 SCI_BASE_PHY_STATE_STARTING);
1957 static enum sci_status
1958 scic_sds_phy_stopped_state_destroy_handler(struct scic_sds_phy *sci_phy)
1963 static enum sci_status
1964 scic_sds_phy_ready_state_stop_handler(struct scic_sds_phy *sci_phy)
1966 sci_base_state_machine_change_state(&sci_phy->state_machine,
1967 SCI_BASE_PHY_STATE_STOPPED);
1972 static enum sci_status
1973 scic_sds_phy_ready_state_reset_handler(struct scic_sds_phy *sci_phy)
1975 sci_base_state_machine_change_state(&sci_phy->state_machine,
1976 SCI_BASE_PHY_STATE_RESETTING);
1982 * scic_sds_phy_ready_state_event_handler -
1983 * @phy: This is the struct scic_sds_phy object which has received the event.
1985 * This method request the struct scic_sds_phy handle the received event. The only
1986 * event that we are interested in while in the ready state is the link failure
1987 * event. - decoded event is a link failure - transition the struct scic_sds_phy back
1988 * to the SCI_BASE_PHY_STATE_STARTING state. - any other event received will
1989 * report a warning message enum sci_status SCI_SUCCESS if the event received is a
1990 * link failure SCI_FAILURE_INVALID_STATE for any other event received.
1992 static enum sci_status scic_sds_phy_ready_state_event_handler(struct scic_sds_phy *sci_phy,
1995 enum sci_status result = SCI_FAILURE;
1997 switch (scu_get_event_code(event_code)) {
1998 case SCU_EVENT_LINK_FAILURE:
1999 /* Link failure change state back to the starting state */
2000 sci_base_state_machine_change_state(&sci_phy->state_machine,
2001 SCI_BASE_PHY_STATE_STARTING);
2002 result = SCI_SUCCESS;
2005 case SCU_EVENT_BROADCAST_CHANGE:
2006 /* Broadcast change received. Notify the port. */
2007 if (scic_sds_phy_get_port(sci_phy) != NULL)
2008 scic_sds_port_broadcast_change_received(sci_phy->owning_port, sci_phy);
2010 sci_phy->bcn_received_while_port_unassigned = true;
2014 dev_warn(sciphy_to_dev(sci_phy),
2015 "%sP SCIC PHY 0x%p ready state machine received "
2016 "unexpected event_code %x\n",
2017 __func__, sci_phy, event_code);
2019 result = SCI_FAILURE_INVALID_STATE;
2026 static enum sci_status scic_sds_phy_resetting_state_event_handler(struct scic_sds_phy *sci_phy,
2029 enum sci_status result = SCI_FAILURE;
2031 switch (scu_get_event_code(event_code)) {
2032 case SCU_EVENT_HARD_RESET_TRANSMITTED:
2033 /* Link failure change state back to the starting state */
2034 sci_base_state_machine_change_state(&sci_phy->state_machine,
2035 SCI_BASE_PHY_STATE_STARTING);
2036 result = SCI_SUCCESS;
2040 dev_warn(sciphy_to_dev(sci_phy),
2041 "%s: SCIC PHY 0x%p resetting state machine received "
2042 "unexpected event_code %x\n",
2043 __func__, sci_phy, event_code);
2045 result = SCI_FAILURE_INVALID_STATE;
2052 /* --------------------------------------------------------------------------- */
2054 static const struct scic_sds_phy_state_handler scic_sds_phy_state_handler_table[] = {
2055 [SCI_BASE_PHY_STATE_INITIAL] = {
2056 .start_handler = scic_sds_phy_default_start_handler,
2057 .stop_handler = scic_sds_phy_default_stop_handler,
2058 .reset_handler = scic_sds_phy_default_reset_handler,
2059 .destruct_handler = scic_sds_phy_default_destroy_handler,
2060 .frame_handler = scic_sds_phy_default_frame_handler,
2061 .event_handler = scic_sds_phy_default_event_handler,
2062 .consume_power_handler = scic_sds_phy_default_consume_power_handler
2064 [SCI_BASE_PHY_STATE_STOPPED] = {
2065 .start_handler = scic_sds_phy_stopped_state_start_handler,
2066 .stop_handler = scic_sds_phy_default_stop_handler,
2067 .reset_handler = scic_sds_phy_default_reset_handler,
2068 .destruct_handler = scic_sds_phy_stopped_state_destroy_handler,
2069 .frame_handler = scic_sds_phy_default_frame_handler,
2070 .event_handler = scic_sds_phy_default_event_handler,
2071 .consume_power_handler = scic_sds_phy_default_consume_power_handler
2073 [SCI_BASE_PHY_STATE_STARTING] = {
2074 .start_handler = scic_sds_phy_default_start_handler,
2075 .stop_handler = scic_sds_phy_default_stop_handler,
2076 .reset_handler = scic_sds_phy_default_reset_handler,
2077 .destruct_handler = scic_sds_phy_default_destroy_handler,
2078 .frame_handler = scic_sds_phy_default_frame_handler,
2079 .event_handler = scic_sds_phy_default_event_handler,
2080 .consume_power_handler = scic_sds_phy_default_consume_power_handler
2082 [SCI_BASE_PHY_STATE_READY] = {
2083 .start_handler = scic_sds_phy_default_start_handler,
2084 .stop_handler = scic_sds_phy_ready_state_stop_handler,
2085 .reset_handler = scic_sds_phy_ready_state_reset_handler,
2086 .destruct_handler = scic_sds_phy_default_destroy_handler,
2087 .frame_handler = scic_sds_phy_default_frame_handler,
2088 .event_handler = scic_sds_phy_ready_state_event_handler,
2089 .consume_power_handler = scic_sds_phy_default_consume_power_handler
2091 [SCI_BASE_PHY_STATE_RESETTING] = {
2092 .start_handler = scic_sds_phy_default_start_handler,
2093 .stop_handler = scic_sds_phy_default_stop_handler,
2094 .reset_handler = scic_sds_phy_default_reset_handler,
2095 .destruct_handler = scic_sds_phy_default_destroy_handler,
2096 .frame_handler = scic_sds_phy_default_frame_handler,
2097 .event_handler = scic_sds_phy_resetting_state_event_handler,
2098 .consume_power_handler = scic_sds_phy_default_consume_power_handler
2100 [SCI_BASE_PHY_STATE_FINAL] = {
2101 .start_handler = scic_sds_phy_default_start_handler,
2102 .stop_handler = scic_sds_phy_default_stop_handler,
2103 .reset_handler = scic_sds_phy_default_reset_handler,
2104 .destruct_handler = scic_sds_phy_default_destroy_handler,
2105 .frame_handler = scic_sds_phy_default_frame_handler,
2106 .event_handler = scic_sds_phy_default_event_handler,
2107 .consume_power_handler = scic_sds_phy_default_consume_power_handler
2112 * ****************************************************************************
2113 * * PHY STATE PRIVATE METHODS
2114 * **************************************************************************** */
2118 * @this_phy: This is the struct scic_sds_phy object to stop.
2120 * This method will stop the struct scic_sds_phy object. This does not reset the
2121 * protocol engine it just suspends it and places it in a state where it will
2122 * not cause the end device to power up. none
2124 static void scu_link_layer_stop_protocol_engine(
2125 struct scic_sds_phy *this_phy)
2127 u32 scu_sas_pcfg_value;
2128 u32 enable_spinup_value;
2130 /* Suspend the protocol engine and place it in a sata spinup hold state */
2131 scu_sas_pcfg_value =
2132 readl(&this_phy->link_layer_registers->phy_configuration);
2133 scu_sas_pcfg_value |= (
2134 SCU_SAS_PCFG_GEN_BIT(OOB_RESET)
2135 | SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE)
2136 | SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD)
2138 writel(scu_sas_pcfg_value,
2139 &this_phy->link_layer_registers->phy_configuration);
2141 /* Disable the notify enable spinup primitives */
2142 enable_spinup_value = readl(&this_phy->link_layer_registers->notify_enable_spinup_control);
2143 enable_spinup_value &= ~SCU_ENSPINUP_GEN_BIT(ENABLE);
2144 writel(enable_spinup_value, &this_phy->link_layer_registers->notify_enable_spinup_control);
2150 * This method will start the OOB/SN state machine for this struct scic_sds_phy object.
2152 static void scu_link_layer_start_oob(
2153 struct scic_sds_phy *this_phy)
2155 u32 scu_sas_pcfg_value;
2157 scu_sas_pcfg_value =
2158 readl(&this_phy->link_layer_registers->phy_configuration);
2159 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
2160 scu_sas_pcfg_value &=
2161 ~(SCU_SAS_PCFG_GEN_BIT(OOB_RESET) | SCU_SAS_PCFG_GEN_BIT(HARD_RESET));
2162 writel(scu_sas_pcfg_value,
2163 &this_phy->link_layer_registers->phy_configuration);
2169 * This method will transmit a hard reset request on the specified phy. The SCU
2170 * hardware requires that we reset the OOB state machine and set the hard reset
2171 * bit in the phy configuration register. We then must start OOB over with the
2172 * hard reset bit set.
2174 static void scu_link_layer_tx_hard_reset(
2175 struct scic_sds_phy *this_phy)
2177 u32 phy_configuration_value;
2180 * SAS Phys must wait for the HARD_RESET_TX event notification to transition
2181 * to the starting state. */
2182 phy_configuration_value =
2183 readl(&this_phy->link_layer_registers->phy_configuration);
2184 phy_configuration_value |=
2185 (SCU_SAS_PCFG_GEN_BIT(HARD_RESET) | SCU_SAS_PCFG_GEN_BIT(OOB_RESET));
2186 writel(phy_configuration_value,
2187 &this_phy->link_layer_registers->phy_configuration);
2189 /* Now take the OOB state machine out of reset */
2190 phy_configuration_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
2191 phy_configuration_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
2192 writel(phy_configuration_value,
2193 &this_phy->link_layer_registers->phy_configuration);
2197 * ****************************************************************************
2198 * * PHY BASE STATE METHODS
2199 * **************************************************************************** */
2203 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
2205 * This method will perform the actions required by the struct scic_sds_phy on
2206 * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
2207 * handlers for the phy object base state machine initial state. none
2209 static void scic_sds_phy_initial_state_enter(
2210 struct sci_base_object *object)
2212 struct scic_sds_phy *this_phy;
2214 this_phy = (struct scic_sds_phy *)object;
2216 scic_sds_phy_set_base_state_handlers(this_phy, SCI_BASE_PHY_STATE_INITIAL);
2221 * @object: This is the struct sci_base_object which is cast to a
2222 * struct scic_sds_phy object.
2224 * This function will perform the actions required by the struct scic_sds_phy on
2225 * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
2226 * handlers for the phy object base state machine initial state. - The SCU
2227 * hardware is requested to stop the protocol engine. none
2229 static void scic_sds_phy_stopped_state_enter(struct sci_base_object *object)
2231 struct scic_sds_phy *sci_phy = (struct scic_sds_phy *)object;
2232 struct scic_sds_controller *scic = scic_sds_phy_get_controller(sci_phy);
2233 struct isci_host *ihost = sci_object_get_association(scic);
2235 sci_phy = (struct scic_sds_phy *)object;
2238 * @todo We need to get to the controller to place this PE in a
2242 scic_sds_phy_set_base_state_handlers(sci_phy,
2243 SCI_BASE_PHY_STATE_STOPPED);
2245 if (sci_phy->sata_timeout_timer != NULL) {
2246 isci_del_timer(ihost, sci_phy->sata_timeout_timer);
2248 sci_phy->sata_timeout_timer = NULL;
2251 scu_link_layer_stop_protocol_engine(sci_phy);
2253 if (sci_phy->state_machine.previous_state_id !=
2254 SCI_BASE_PHY_STATE_INITIAL)
2255 scic_sds_controller_link_down(
2256 scic_sds_phy_get_controller(sci_phy),
2257 scic_sds_phy_get_port(sci_phy),
2263 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
2265 * This method will perform the actions required by the struct scic_sds_phy on
2266 * entering the SCI_BASE_PHY_STATE_STARTING. - This function sets the state
2267 * handlers for the phy object base state machine starting state. - The SCU
2268 * hardware is requested to start OOB/SN on this protocl engine. - The phy
2269 * starting substate machine is started. - If the previous state was the ready
2270 * state then the struct scic_sds_controller is informed that the phy has gone link
2273 static void scic_sds_phy_starting_state_enter(
2274 struct sci_base_object *object)
2276 struct scic_sds_phy *this_phy;
2278 this_phy = (struct scic_sds_phy *)object;
2280 scic_sds_phy_set_base_state_handlers(this_phy, SCI_BASE_PHY_STATE_STARTING);
2282 scu_link_layer_stop_protocol_engine(this_phy);
2283 scu_link_layer_start_oob(this_phy);
2285 /* We don't know what kind of phy we are going to be just yet */
2286 this_phy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
2287 this_phy->bcn_received_while_port_unassigned = false;
2289 /* Change over to the starting substate machine to continue */
2290 sci_base_state_machine_start(&this_phy->starting_substate_machine);
2292 if (this_phy->state_machine.previous_state_id
2293 == SCI_BASE_PHY_STATE_READY) {
2294 scic_sds_controller_link_down(
2295 scic_sds_phy_get_controller(this_phy),
2296 scic_sds_phy_get_port(this_phy),
2304 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
2306 * This method will perform the actions required by the struct scic_sds_phy on
2307 * entering the SCI_BASE_PHY_STATE_READY. - This function sets the state
2308 * handlers for the phy object base state machine ready state. - The SCU
2309 * hardware protocol engine is resumed. - The struct scic_sds_controller is informed
2310 * that the phy object has gone link up. none
2312 static void scic_sds_phy_ready_state_enter(
2313 struct sci_base_object *object)
2315 struct scic_sds_phy *this_phy;
2317 this_phy = (struct scic_sds_phy *)object;
2319 scic_sds_phy_set_base_state_handlers(this_phy, SCI_BASE_PHY_STATE_READY);
2321 scic_sds_controller_link_up(
2322 scic_sds_phy_get_controller(this_phy),
2323 scic_sds_phy_get_port(this_phy),
2330 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
2332 * This method will perform the actions required by the struct scic_sds_phy on exiting
2333 * the SCI_BASE_PHY_STATE_INITIAL. This function suspends the SCU hardware
2334 * protocol engine represented by this struct scic_sds_phy object. none
2336 static void scic_sds_phy_ready_state_exit(
2337 struct sci_base_object *object)
2339 struct scic_sds_phy *this_phy;
2341 this_phy = (struct scic_sds_phy *)object;
2343 scic_sds_phy_suspend(this_phy);
2348 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
2350 * This method will perform the actions required by the struct scic_sds_phy on
2351 * entering the SCI_BASE_PHY_STATE_RESETTING. - This function sets the state
2352 * handlers for the phy object base state machine resetting state. none
2354 static void scic_sds_phy_resetting_state_enter(
2355 struct sci_base_object *object)
2357 struct scic_sds_phy *this_phy;
2359 this_phy = (struct scic_sds_phy *)object;
2361 scic_sds_phy_set_base_state_handlers(this_phy, SCI_BASE_PHY_STATE_RESETTING);
2364 * The phy is being reset, therefore deactivate it from the port.
2365 * In the resetting state we don't notify the user regarding
2366 * link up and link down notifications. */
2367 scic_sds_port_deactivate_phy(this_phy->owning_port, this_phy, false);
2369 if (this_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
2370 scu_link_layer_tx_hard_reset(this_phy);
2373 * The SCU does not need to have a discrete reset state so just go back to
2374 * the starting state. */
2375 sci_base_state_machine_change_state(&this_phy->state_machine,
2376 SCI_BASE_PHY_STATE_STARTING);
2382 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
2384 * This method will perform the actions required by the struct scic_sds_phy on
2385 * entering the SCI_BASE_PHY_STATE_FINAL. - This function sets the state
2386 * handlers for the phy object base state machine final state. none
2388 static void scic_sds_phy_final_state_enter(
2389 struct sci_base_object *object)
2391 struct scic_sds_phy *this_phy;
2393 this_phy = (struct scic_sds_phy *)object;
2395 scic_sds_phy_set_base_state_handlers(this_phy, SCI_BASE_PHY_STATE_FINAL);
2397 /* Nothing to do here */
2400 /* --------------------------------------------------------------------------- */
2402 static const struct sci_base_state scic_sds_phy_state_table[] = {
2403 [SCI_BASE_PHY_STATE_INITIAL] = {
2404 .enter_state = scic_sds_phy_initial_state_enter,
2406 [SCI_BASE_PHY_STATE_STOPPED] = {
2407 .enter_state = scic_sds_phy_stopped_state_enter,
2409 [SCI_BASE_PHY_STATE_STARTING] = {
2410 .enter_state = scic_sds_phy_starting_state_enter,
2412 [SCI_BASE_PHY_STATE_READY] = {
2413 .enter_state = scic_sds_phy_ready_state_enter,
2414 .exit_state = scic_sds_phy_ready_state_exit,
2416 [SCI_BASE_PHY_STATE_RESETTING] = {
2417 .enter_state = scic_sds_phy_resetting_state_enter,
2419 [SCI_BASE_PHY_STATE_FINAL] = {
2420 .enter_state = scic_sds_phy_final_state_enter,
2424 void scic_sds_phy_construct(struct scic_sds_phy *sci_phy,
2425 struct scic_sds_port *owning_port, u8 phy_index)
2428 sci_phy->parent.private = NULL;
2429 sci_base_state_machine_construct(&sci_phy->state_machine,
2431 scic_sds_phy_state_table,
2432 SCI_BASE_PHY_STATE_INITIAL);
2434 sci_base_state_machine_start(&sci_phy->state_machine);
2436 /* Copy the rest of the input data to our locals */
2437 sci_phy->owning_port = owning_port;
2438 sci_phy->phy_index = phy_index;
2439 sci_phy->bcn_received_while_port_unassigned = false;
2440 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
2441 sci_phy->link_layer_registers = NULL;
2442 sci_phy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
2443 sci_phy->sata_timeout_timer = NULL;
2445 /* Clear out the identification buffer data */
2446 memset(&sci_phy->phy_type, 0, sizeof(sci_phy->phy_type));
2448 /* Initialize the the substate machines */
2449 sci_base_state_machine_construct(&sci_phy->starting_substate_machine,
2451 scic_sds_phy_starting_substates,
2452 SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL);