isci: Remove SCIC_SWAP_DWORD()
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / scsi / isci / core / scic_sds_phy.c
blob18dc14a8f0ba8c28039ce10b84d4c267fa84480d
1 /*
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.
5 * GPL LICENSE SUMMARY
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.
24 * BSD LICENSE
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
31 * are met:
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
38 * distribution.
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 <scsi/sas.h>
57 #include "sas.h"
58 #include "sci_base_state.h"
59 #include "sci_base_state_machine.h"
60 #include "scic_phy.h"
61 #include "scic_sds_controller.h"
62 #include "scic_sds_phy.h"
63 #include "scic_sds_port.h"
64 #include "remote_node_context.h"
65 #include "sci_environment.h"
66 #include "sci_util.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 * ***************************************************************************** */
85 /**
86 * This method will initialize the phy transport layer registers
87 * @sci_phy:
88 * @transport_layer_registers
90 * enum sci_status
92 static enum sci_status scic_sds_phy_transport_layer_initialization(
93 struct scic_sds_phy *sci_phy,
94 struct scu_transport_layer_registers __iomem *transport_layer_registers)
96 u32 tl_control;
98 sci_phy->transport_layer_registers = transport_layer_registers;
100 writel(SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX,
101 &sci_phy->transport_layer_registers->stp_rni);
104 * Hardware team recommends that we enable the STP prefetch for all
105 * transports
107 tl_control = readl(&sci_phy->transport_layer_registers->control);
108 tl_control |= SCU_TLCR_GEN_BIT(STP_WRITE_DATA_PREFETCH);
109 writel(tl_control, &sci_phy->transport_layer_registers->control);
111 return SCI_SUCCESS;
115 * This method will initialize the phy link layer registers
116 * @sci_phy:
117 * @link_layer_registers:
119 * enum sci_status
121 static enum sci_status
122 scic_sds_phy_link_layer_initialization(struct scic_sds_phy *sci_phy,
123 struct scu_link_layer_registers __iomem *link_layer_registers)
125 struct scic_sds_controller *scic =
126 sci_phy->owning_port->owning_controller;
127 int phy_idx = sci_phy->phy_index;
128 struct sci_phy_user_params *phy_user =
129 &scic->user_parameters.sds1.phys[phy_idx];
130 struct sci_phy_oem_params *phy_oem =
131 &scic->oem_parameters.sds1.phys[phy_idx];
132 u32 phy_configuration;
133 struct scic_phy_cap phy_cap;
134 u32 parity_check = 0;
135 u32 parity_count = 0;
136 u32 llctl, link_rate;
137 u32 clksm_value = 0;
139 sci_phy->link_layer_registers = link_layer_registers;
141 /* Set our IDENTIFY frame data */
142 #define SCI_END_DEVICE 0x01
144 writel(SCU_SAS_TIID_GEN_BIT(SMP_INITIATOR) |
145 SCU_SAS_TIID_GEN_BIT(SSP_INITIATOR) |
146 SCU_SAS_TIID_GEN_BIT(STP_INITIATOR) |
147 SCU_SAS_TIID_GEN_BIT(DA_SATA_HOST) |
148 SCU_SAS_TIID_GEN_VAL(DEVICE_TYPE, SCI_END_DEVICE),
149 &sci_phy->link_layer_registers->transmit_identification);
151 /* Write the device SAS Address */
152 writel(0xFEDCBA98,
153 &sci_phy->link_layer_registers->sas_device_name_high);
154 writel(phy_idx, &sci_phy->link_layer_registers->sas_device_name_low);
156 /* Write the source SAS Address */
157 writel(phy_oem->sas_address.high,
158 &sci_phy->link_layer_registers->source_sas_address_high);
159 writel(phy_oem->sas_address.low,
160 &sci_phy->link_layer_registers->source_sas_address_low);
162 /* Clear and Set the PHY Identifier */
163 writel(0, &sci_phy->link_layer_registers->identify_frame_phy_id);
164 writel(SCU_SAS_TIPID_GEN_VALUE(ID, phy_idx),
165 &sci_phy->link_layer_registers->identify_frame_phy_id);
167 /* Change the initial state of the phy configuration register */
168 phy_configuration =
169 readl(&sci_phy->link_layer_registers->phy_configuration);
171 /* Hold OOB state machine in reset */
172 phy_configuration |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
173 writel(phy_configuration,
174 &sci_phy->link_layer_registers->phy_configuration);
176 /* Configure the SNW capabilities */
177 phy_cap.all = 0;
178 phy_cap.start = 1;
179 phy_cap.gen3_no_ssc = 1;
180 phy_cap.gen2_no_ssc = 1;
181 phy_cap.gen1_no_ssc = 1;
182 if (scic->oem_parameters.sds1.controller.do_enable_ssc == true) {
183 phy_cap.gen3_ssc = 1;
184 phy_cap.gen2_ssc = 1;
185 phy_cap.gen1_ssc = 1;
189 * The SAS specification indicates that the phy_capabilities that
190 * are transmitted shall have an even parity. Calculate the parity. */
191 parity_check = phy_cap.all;
192 while (parity_check != 0) {
193 if (parity_check & 0x1)
194 parity_count++;
195 parity_check >>= 1;
199 * If parity indicates there are an odd number of bits set, then
200 * set the parity bit to 1 in the phy capabilities. */
201 if ((parity_count % 2) != 0)
202 phy_cap.parity = 1;
204 writel(phy_cap.all, &sci_phy->link_layer_registers->phy_capabilities);
206 /* Set the enable spinup period but disable the ability to send
207 * notify enable spinup
209 writel(SCU_ENSPINUP_GEN_VAL(COUNT,
210 phy_user->notify_enable_spin_up_insertion_frequency),
211 &sci_phy->link_layer_registers->notify_enable_spinup_control);
213 /* Write the ALIGN Insertion Ferequency for connected phy and
214 * inpendent of connected state
216 clksm_value = SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(CONNECTED,
217 phy_user->in_connection_align_insertion_frequency);
219 clksm_value |= SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(GENERAL,
220 phy_user->align_insertion_frequency);
222 writel(clksm_value, &sci_phy->link_layer_registers->clock_skew_management);
224 /* @todo Provide a way to write this register correctly */
225 writel(0x02108421,
226 &sci_phy->link_layer_registers->afe_lookup_table_control);
228 llctl = SCU_SAS_LLCTL_GEN_VAL(NO_OUTBOUND_TASK_TIMEOUT,
229 (u8)scic->user_parameters.sds1.no_outbound_task_timeout);
231 switch(phy_user->max_speed_generation) {
232 case SCIC_SDS_PARM_GEN3_SPEED:
233 link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN3;
234 break;
235 case SCIC_SDS_PARM_GEN2_SPEED:
236 link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN2;
237 break;
238 default:
239 link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN1;
240 break;
242 llctl |= SCU_SAS_LLCTL_GEN_VAL(MAX_LINK_RATE, link_rate);
243 writel(llctl, &sci_phy->link_layer_registers->link_layer_control);
245 if (is_a0() || is_a2()) {
246 /* Program the max ARB time for the PHY to 700us so we inter-operate with
247 * the PMC expander which shuts down PHYs if the expander PHY generates too
248 * many breaks. This time value will guarantee that the initiator PHY will
249 * generate the break.
251 writel(SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME,
252 &sci_phy->link_layer_registers->maximum_arbitration_wait_timer_timeout);
256 * Set the link layer hang detection to 500ms (0x1F4) from its default
257 * value of 128ms. Max value is 511 ms.
259 writel(0x1F4, &sci_phy->link_layer_registers->link_layer_hang_detection_timeout);
261 /* We can exit the initial state to the stopped state */
262 sci_base_state_machine_change_state(&sci_phy->state_machine,
263 SCI_BASE_PHY_STATE_STOPPED);
265 return SCI_SUCCESS;
269 * This function will handle the sata SIGNATURE FIS timeout condition. It will
270 * restart the starting substate machine since we dont know what has actually
271 * happening.
273 static void scic_sds_phy_sata_timeout(void *phy)
275 struct scic_sds_phy *sci_phy = phy;
277 dev_dbg(sciphy_to_dev(sci_phy),
278 "%s: SCIC SDS Phy 0x%p did not receive signature fis before "
279 "timeout.\n",
280 __func__,
281 sci_phy);
283 sci_base_state_machine_stop(&sci_phy->starting_substate_machine);
285 sci_base_state_machine_change_state(&sci_phy->state_machine,
286 SCI_BASE_PHY_STATE_STARTING);
290 * This method returns the port currently containing this phy. If the phy is
291 * currently contained by the dummy port, then the phy is considered to not
292 * be part of a port.
293 * @sci_phy: This parameter specifies the phy for which to retrieve the
294 * containing port.
296 * This method returns a handle to a port that contains the supplied phy.
297 * NULL This value is returned if the phy is not part of a real
298 * port (i.e. it's contained in the dummy port). !NULL All other
299 * values indicate a handle/pointer to the port containing the phy.
301 struct scic_sds_port *scic_sds_phy_get_port(
302 struct scic_sds_phy *sci_phy)
304 if (scic_sds_port_get_index(sci_phy->owning_port) == SCIC_SDS_DUMMY_PORT)
305 return NULL;
307 return sci_phy->owning_port;
311 * This method will assign a port to the phy object.
312 * @out]: sci_phy This parameter specifies the phy for which to assign a port
313 * object.
317 void scic_sds_phy_set_port(
318 struct scic_sds_phy *sci_phy,
319 struct scic_sds_port *sci_port)
321 sci_phy->owning_port = sci_port;
323 if (sci_phy->bcn_received_while_port_unassigned) {
324 sci_phy->bcn_received_while_port_unassigned = false;
325 scic_sds_port_broadcast_change_received(sci_phy->owning_port, sci_phy);
330 * This method will initialize the constructed phy
331 * @sci_phy:
332 * @link_layer_registers:
334 * enum sci_status
336 enum sci_status scic_sds_phy_initialize(
337 struct scic_sds_phy *sci_phy,
338 struct scu_transport_layer_registers __iomem *transport_layer_registers,
339 struct scu_link_layer_registers __iomem *link_layer_registers)
341 struct scic_sds_controller *scic = scic_sds_phy_get_controller(sci_phy);
342 struct isci_host *ihost = scic->ihost;
344 /* Create the SIGNATURE FIS Timeout timer for this phy */
345 sci_phy->sata_timeout_timer =
346 isci_timer_create(
347 ihost,
348 sci_phy,
349 scic_sds_phy_sata_timeout);
351 /* Perfrom the initialization of the TL hardware */
352 scic_sds_phy_transport_layer_initialization(
353 sci_phy,
354 transport_layer_registers);
356 /* Perofrm the initialization of the PE hardware */
357 scic_sds_phy_link_layer_initialization(sci_phy, link_layer_registers);
360 * There is nothing that needs to be done in this state just
361 * transition to the stopped state. */
362 sci_base_state_machine_change_state(&sci_phy->state_machine,
363 SCI_BASE_PHY_STATE_STOPPED);
365 return SCI_SUCCESS;
369 * This method assigns the direct attached device ID for this phy.
371 * @sci_phy The phy for which the direct attached device id is to
372 * be assigned.
373 * @device_id The direct attached device ID to assign to the phy.
374 * This will either be the RNi for the device or an invalid RNi if there
375 * is no current device assigned to the phy.
377 void scic_sds_phy_setup_transport(
378 struct scic_sds_phy *sci_phy,
379 u32 device_id)
381 u32 tl_control;
383 writel(device_id, &sci_phy->transport_layer_registers->stp_rni);
386 * The read should guarantee that the first write gets posted
387 * before the next write
389 tl_control = readl(&sci_phy->transport_layer_registers->control);
390 tl_control |= SCU_TLCR_GEN_BIT(CLEAR_TCI_NCQ_MAPPING_TABLE);
391 writel(tl_control, &sci_phy->transport_layer_registers->control);
396 * @sci_phy: The phy object to be suspended.
398 * This function will perform the register reads/writes to suspend the SCU
399 * hardware protocol engine. none
401 static void scic_sds_phy_suspend(
402 struct scic_sds_phy *sci_phy)
404 u32 scu_sas_pcfg_value;
406 scu_sas_pcfg_value =
407 readl(&sci_phy->link_layer_registers->phy_configuration);
408 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE);
409 writel(scu_sas_pcfg_value,
410 &sci_phy->link_layer_registers->phy_configuration);
412 scic_sds_phy_setup_transport(
413 sci_phy,
414 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX);
417 void scic_sds_phy_resume(struct scic_sds_phy *sci_phy)
419 u32 scu_sas_pcfg_value;
421 scu_sas_pcfg_value =
422 readl(&sci_phy->link_layer_registers->phy_configuration);
423 scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE);
424 writel(scu_sas_pcfg_value,
425 &sci_phy->link_layer_registers->phy_configuration);
428 void scic_sds_phy_get_sas_address(struct scic_sds_phy *sci_phy,
429 struct sci_sas_address *sas_address)
431 sas_address->high = readl(&sci_phy->link_layer_registers->source_sas_address_high);
432 sas_address->low = readl(&sci_phy->link_layer_registers->source_sas_address_low);
435 void scic_sds_phy_get_attached_sas_address(struct scic_sds_phy *sci_phy,
436 struct sci_sas_address *sas_address)
438 struct sas_identify_frame *iaf;
439 struct isci_phy *iphy = sci_phy->iphy;
441 iaf = &iphy->frame_rcvd.iaf;
442 memcpy(sas_address, iaf->sas_addr, SAS_ADDR_SIZE);
445 void scic_sds_phy_get_protocols(struct scic_sds_phy *sci_phy,
446 struct scic_phy_proto *protocols)
448 protocols->all =
449 (u16)(readl(&sci_phy->
450 link_layer_registers->transmit_identification) &
451 0x0000FFFF);
455 * This method will attempt to start the phy object. This request is only valid
456 * when the phy is in the stopped state
457 * @sci_phy:
459 * enum sci_status
461 enum sci_status scic_sds_phy_start(struct scic_sds_phy *sci_phy)
463 return sci_phy->state_handlers->start_handler(sci_phy);
467 * This method will attempt to stop the phy object.
468 * @sci_phy:
470 * enum sci_status SCI_SUCCESS if the phy is going to stop SCI_INVALID_STATE
471 * if the phy is not in a valid state to stop
473 enum sci_status scic_sds_phy_stop(struct scic_sds_phy *sci_phy)
475 return sci_phy->state_handlers->stop_handler(sci_phy);
479 * This method will attempt to reset the phy. This request is only valid when
480 * the phy is in an ready state
481 * @sci_phy:
483 * enum sci_status
485 enum sci_status scic_sds_phy_reset(
486 struct scic_sds_phy *sci_phy)
488 return sci_phy->state_handlers->reset_handler(sci_phy);
492 * This method will process the event code received.
493 * @sci_phy:
494 * @event_code:
496 * enum sci_status
498 enum sci_status scic_sds_phy_event_handler(
499 struct scic_sds_phy *sci_phy,
500 u32 event_code)
502 return sci_phy->state_handlers->event_handler(sci_phy, event_code);
506 * This method will process the frame index received.
507 * @sci_phy:
508 * @frame_index:
510 * enum sci_status
512 enum sci_status scic_sds_phy_frame_handler(
513 struct scic_sds_phy *sci_phy,
514 u32 frame_index)
516 return sci_phy->state_handlers->frame_handler(sci_phy, frame_index);
520 * This method will give the phy permission to consume power
521 * @sci_phy:
523 * enum sci_status
525 enum sci_status scic_sds_phy_consume_power_handler(
526 struct scic_sds_phy *sci_phy)
528 return sci_phy->state_handlers->consume_power_handler(sci_phy);
532 * *****************************************************************************
533 * * SCIC SDS PHY HELPER FUNCTIONS
534 * ***************************************************************************** */
539 * @sci_phy: The phy object that received SAS PHY DETECTED.
541 * This method continues the link training for the phy as if it were a SAS PHY
542 * instead of a SATA PHY. This is done because the completion queue had a SAS
543 * PHY DETECTED event when the state machine was expecting a SATA PHY event.
544 * none
546 static void scic_sds_phy_start_sas_link_training(
547 struct scic_sds_phy *sci_phy)
549 u32 phy_control;
551 phy_control =
552 readl(&sci_phy->link_layer_registers->phy_configuration);
553 phy_control |= SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD);
554 writel(phy_control,
555 &sci_phy->link_layer_registers->phy_configuration);
557 sci_base_state_machine_change_state(
558 &sci_phy->starting_substate_machine,
559 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
562 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SAS;
567 * @sci_phy: The phy object that received a SATA SPINUP HOLD event
569 * This method continues the link training for the phy as if it were a SATA PHY
570 * instead of a SAS PHY. This is done because the completion queue had a SATA
571 * SPINUP HOLD event when the state machine was expecting a SAS PHY event. none
573 static void scic_sds_phy_start_sata_link_training(
574 struct scic_sds_phy *sci_phy)
576 sci_base_state_machine_change_state(
577 &sci_phy->starting_substate_machine,
578 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
581 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
585 * scic_sds_phy_complete_link_training - perform processing common to
586 * all protocols upon completion of link training.
587 * @sci_phy: This parameter specifies the phy object for which link training
588 * has completed.
589 * @max_link_rate: This parameter specifies the maximum link rate to be
590 * associated with this phy.
591 * @next_state: This parameter specifies the next state for the phy's starting
592 * sub-state machine.
595 static void scic_sds_phy_complete_link_training(
596 struct scic_sds_phy *sci_phy,
597 enum sas_linkrate max_link_rate,
598 u32 next_state)
600 sci_phy->max_negotiated_speed = max_link_rate;
602 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
603 next_state);
606 static void scic_sds_phy_restart_starting_state(
607 struct scic_sds_phy *sci_phy)
609 /* Stop the current substate machine */
610 sci_base_state_machine_stop(&sci_phy->starting_substate_machine);
612 /* Re-enter the base state machine starting state */
613 sci_base_state_machine_change_state(&sci_phy->state_machine,
614 SCI_BASE_PHY_STATE_STARTING);
617 /* ****************************************************************************
618 * SCIC SDS PHY general handlers
619 ************************************************************************** */
620 static enum sci_status scic_sds_phy_starting_substate_general_stop_handler(
621 struct scic_sds_phy *phy)
623 sci_base_state_machine_stop(&phy->starting_substate_machine);
625 sci_base_state_machine_change_state(&phy->state_machine,
626 SCI_BASE_PHY_STATE_STOPPED);
628 return SCI_SUCCESS;
632 * *****************************************************************************
633 * * SCIC SDS PHY EVENT_HANDLERS
634 * ***************************************************************************** */
638 * @phy: This struct scic_sds_phy object which has received an event.
639 * @event_code: This is the event code which the phy object is to decode.
641 * This method is called when an event notification is received for the phy
642 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. -
643 * decode the event - sas phy detected causes a state transition to the wait
644 * for speed event notification. - any other events log a warning message and
645 * set a failure status enum sci_status SCI_SUCCESS on any valid event notification
646 * SCI_FAILURE on any unexpected event notifation
648 static enum sci_status scic_sds_phy_starting_substate_await_ossp_event_handler(
649 struct scic_sds_phy *sci_phy,
650 u32 event_code)
652 u32 result = SCI_SUCCESS;
654 switch (scu_get_event_code(event_code)) {
655 case SCU_EVENT_SAS_PHY_DETECTED:
656 scic_sds_phy_start_sas_link_training(sci_phy);
657 sci_phy->is_in_link_training = true;
658 break;
660 case SCU_EVENT_SATA_SPINUP_HOLD:
661 scic_sds_phy_start_sata_link_training(sci_phy);
662 sci_phy->is_in_link_training = true;
663 break;
665 default:
666 dev_dbg(sciphy_to_dev(sci_phy),
667 "%s: PHY starting substate machine received "
668 "unexpected event_code %x\n",
669 __func__,
670 event_code);
672 result = SCI_FAILURE;
673 break;
676 return result;
681 * @phy: This struct scic_sds_phy object which has received an event.
682 * @event_code: This is the event code which the phy object is to decode.
684 * This method is called when an event notification is received for the phy
685 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. -
686 * decode the event - sas phy detected returns us back to this state. - speed
687 * event detected causes a state transition to the wait for iaf. - identify
688 * timeout is an un-expected event and the state machine is restarted. - link
689 * failure events restart the starting state machine - any other events log a
690 * warning message and set a failure status enum sci_status SCI_SUCCESS on any valid
691 * event notification SCI_FAILURE on any unexpected event notifation
693 static enum sci_status scic_sds_phy_starting_substate_await_sas_phy_speed_event_handler(
694 struct scic_sds_phy *sci_phy,
695 u32 event_code)
697 u32 result = SCI_SUCCESS;
699 switch (scu_get_event_code(event_code)) {
700 case SCU_EVENT_SAS_PHY_DETECTED:
702 * Why is this being reported again by the controller?
703 * We would re-enter this state so just stay here */
704 break;
706 case SCU_EVENT_SAS_15:
707 case SCU_EVENT_SAS_15_SSC:
708 scic_sds_phy_complete_link_training(
709 sci_phy,
710 SAS_LINK_RATE_1_5_GBPS,
711 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF);
712 break;
714 case SCU_EVENT_SAS_30:
715 case SCU_EVENT_SAS_30_SSC:
716 scic_sds_phy_complete_link_training(
717 sci_phy,
718 SAS_LINK_RATE_3_0_GBPS,
719 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF);
720 break;
722 case SCU_EVENT_SAS_60:
723 case SCU_EVENT_SAS_60_SSC:
724 scic_sds_phy_complete_link_training(
725 sci_phy,
726 SAS_LINK_RATE_6_0_GBPS,
727 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF);
728 break;
730 case SCU_EVENT_SATA_SPINUP_HOLD:
732 * We were doing SAS PHY link training and received a SATA PHY event
733 * continue OOB/SN as if this were a SATA PHY */
734 scic_sds_phy_start_sata_link_training(sci_phy);
735 break;
737 case SCU_EVENT_LINK_FAILURE:
738 /* Link failure change state back to the starting state */
739 scic_sds_phy_restart_starting_state(sci_phy);
740 break;
742 default:
743 dev_warn(sciphy_to_dev(sci_phy),
744 "%s: PHY starting substate machine received "
745 "unexpected event_code %x\n",
746 __func__,
747 event_code);
749 result = SCI_FAILURE;
750 break;
753 return result;
758 * @phy: This struct scic_sds_phy object which has received an event.
759 * @event_code: This is the event code which the phy object is to decode.
761 * This method is called when an event notification is received for the phy
762 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. -
763 * decode the event - sas phy detected event backs up the state machine to the
764 * await speed notification. - identify timeout is an un-expected event and the
765 * state machine is restarted. - link failure events restart the starting state
766 * machine - any other events log a warning message and set a failure status
767 * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any
768 * unexpected event notifation
770 static enum sci_status scic_sds_phy_starting_substate_await_iaf_uf_event_handler(
771 struct scic_sds_phy *sci_phy,
772 u32 event_code)
774 u32 result = SCI_SUCCESS;
776 switch (scu_get_event_code(event_code)) {
777 case SCU_EVENT_SAS_PHY_DETECTED:
778 /* Backup the state machine */
779 scic_sds_phy_start_sas_link_training(sci_phy);
780 break;
782 case SCU_EVENT_SATA_SPINUP_HOLD:
784 * We were doing SAS PHY link training and received a SATA PHY event
785 * continue OOB/SN as if this were a SATA PHY */
786 scic_sds_phy_start_sata_link_training(sci_phy);
787 break;
789 case SCU_EVENT_RECEIVED_IDENTIFY_TIMEOUT:
790 case SCU_EVENT_LINK_FAILURE:
791 case SCU_EVENT_HARD_RESET_RECEIVED:
792 /* Start the oob/sn state machine over again */
793 scic_sds_phy_restart_starting_state(sci_phy);
794 break;
796 default:
797 dev_warn(sciphy_to_dev(sci_phy),
798 "%s: PHY starting substate machine received "
799 "unexpected event_code %x\n",
800 __func__,
801 event_code);
803 result = SCI_FAILURE;
804 break;
807 return result;
812 * @phy: This struct scic_sds_phy object which has received an event.
813 * @event_code: This is the event code which the phy object is to decode.
815 * This method is called when an event notification is received for the phy
816 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_POWER. -
817 * decode the event - link failure events restart the starting state machine -
818 * any other events log a warning message and set a failure status enum sci_status
819 * SCI_SUCCESS on a link failure event SCI_FAILURE on any unexpected event
820 * notifation
822 static enum sci_status scic_sds_phy_starting_substate_await_sas_power_event_handler(
823 struct scic_sds_phy *sci_phy,
824 u32 event_code)
826 u32 result = SCI_SUCCESS;
828 switch (scu_get_event_code(event_code)) {
829 case SCU_EVENT_LINK_FAILURE:
830 /* Link failure change state back to the starting state */
831 scic_sds_phy_restart_starting_state(sci_phy);
832 break;
834 default:
835 dev_warn(sciphy_to_dev(sci_phy),
836 "%s: PHY starting substate machine received unexpected "
837 "event_code %x\n",
838 __func__,
839 event_code);
841 result = SCI_FAILURE;
842 break;
845 return result;
850 * @phy: This struct scic_sds_phy object which has received an event.
851 * @event_code: This is the event code which the phy object is to decode.
853 * This method is called when an event notification is received for the phy
854 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. -
855 * decode the event - link failure events restart the starting state machine -
856 * sata spinup hold events are ignored since they are expected - any other
857 * events log a warning message and set a failure status enum sci_status SCI_SUCCESS
858 * on a link failure event SCI_FAILURE on any unexpected event notifation
860 static enum sci_status scic_sds_phy_starting_substate_await_sata_power_event_handler(
861 struct scic_sds_phy *sci_phy,
862 u32 event_code)
864 u32 result = SCI_SUCCESS;
866 switch (scu_get_event_code(event_code)) {
867 case SCU_EVENT_LINK_FAILURE:
868 /* Link failure change state back to the starting state */
869 scic_sds_phy_restart_starting_state(sci_phy);
870 break;
872 case SCU_EVENT_SATA_SPINUP_HOLD:
873 /* These events are received every 10ms and are expected while in this state */
874 break;
876 case SCU_EVENT_SAS_PHY_DETECTED:
878 * There has been a change in the phy type before OOB/SN for the
879 * SATA finished start down the SAS link traning path. */
880 scic_sds_phy_start_sas_link_training(sci_phy);
881 break;
883 default:
884 dev_warn(sciphy_to_dev(sci_phy),
885 "%s: PHY starting substate machine received "
886 "unexpected event_code %x\n",
887 __func__,
888 event_code);
890 result = SCI_FAILURE;
891 break;
894 return result;
898 * scic_sds_phy_starting_substate_await_sata_phy_event_handler -
899 * @phy: This struct scic_sds_phy object which has received an event.
900 * @event_code: This is the event code which the phy object is to decode.
902 * This method is called when an event notification is received for the phy
903 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. -
904 * decode the event - link failure events restart the starting state machine -
905 * sata spinup hold events are ignored since they are expected - sata phy
906 * detected event change to the wait speed event - any other events log a
907 * warning message and set a failure status enum sci_status SCI_SUCCESS on a link
908 * failure event SCI_FAILURE on any unexpected event notifation
910 static enum sci_status scic_sds_phy_starting_substate_await_sata_phy_event_handler(
911 struct scic_sds_phy *sci_phy, u32 event_code)
913 u32 result = SCI_SUCCESS;
915 switch (scu_get_event_code(event_code)) {
916 case SCU_EVENT_LINK_FAILURE:
917 /* Link failure change state back to the starting state */
918 scic_sds_phy_restart_starting_state(sci_phy);
919 break;
921 case SCU_EVENT_SATA_SPINUP_HOLD:
922 /* These events might be received since we dont know how many may be in
923 * the completion queue while waiting for power
925 break;
927 case SCU_EVENT_SATA_PHY_DETECTED:
928 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
930 /* We have received the SATA PHY notification change state */
931 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
932 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN);
933 break;
935 case SCU_EVENT_SAS_PHY_DETECTED:
936 /* There has been a change in the phy type before OOB/SN for the
937 * SATA finished start down the SAS link traning path.
939 scic_sds_phy_start_sas_link_training(sci_phy);
940 break;
942 default:
943 dev_warn(sciphy_to_dev(sci_phy),
944 "%s: PHY starting substate machine received "
945 "unexpected event_code %x\n",
946 __func__,
947 event_code);
949 result = SCI_FAILURE;
950 break;
953 return result;
958 * @phy: This struct scic_sds_phy object which has received an event.
959 * @event_code: This is the event code which the phy object is to decode.
961 * This method is called when an event notification is received for the phy
962 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN.
963 * - decode the event - sata phy detected returns us back to this state. -
964 * speed event detected causes a state transition to the wait for signature. -
965 * link failure events restart the starting state machine - any other events
966 * log a warning message and set a failure status enum sci_status SCI_SUCCESS on any
967 * valid event notification SCI_FAILURE on any unexpected event notifation
969 static enum sci_status scic_sds_phy_starting_substate_await_sata_speed_event_handler(
970 struct scic_sds_phy *sci_phy,
971 u32 event_code)
973 u32 result = SCI_SUCCESS;
975 switch (scu_get_event_code(event_code)) {
976 case SCU_EVENT_SATA_PHY_DETECTED:
978 * The hardware reports multiple SATA PHY detected events
979 * ignore the extras */
980 break;
982 case SCU_EVENT_SATA_15:
983 case SCU_EVENT_SATA_15_SSC:
984 scic_sds_phy_complete_link_training(
985 sci_phy,
986 SAS_LINK_RATE_1_5_GBPS,
987 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
988 break;
990 case SCU_EVENT_SATA_30:
991 case SCU_EVENT_SATA_30_SSC:
992 scic_sds_phy_complete_link_training(
993 sci_phy,
994 SAS_LINK_RATE_3_0_GBPS,
995 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
996 break;
998 case SCU_EVENT_SATA_60:
999 case SCU_EVENT_SATA_60_SSC:
1000 scic_sds_phy_complete_link_training(
1001 sci_phy,
1002 SAS_LINK_RATE_6_0_GBPS,
1003 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
1004 break;
1006 case SCU_EVENT_LINK_FAILURE:
1007 /* Link failure change state back to the starting state */
1008 scic_sds_phy_restart_starting_state(sci_phy);
1009 break;
1011 case SCU_EVENT_SAS_PHY_DETECTED:
1013 * There has been a change in the phy type before OOB/SN for the
1014 * SATA finished start down the SAS link traning path. */
1015 scic_sds_phy_start_sas_link_training(sci_phy);
1016 break;
1018 default:
1019 dev_warn(sciphy_to_dev(sci_phy),
1020 "%s: PHY starting substate machine received "
1021 "unexpected event_code %x\n",
1022 __func__,
1023 event_code);
1025 result = SCI_FAILURE;
1026 break;
1029 return result;
1033 * scic_sds_phy_starting_substate_await_sig_fis_event_handler -
1034 * @phy: This struct scic_sds_phy object which has received an event.
1035 * @event_code: This is the event code which the phy object is to decode.
1037 * This method is called when an event notification is received for the phy
1038 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. -
1039 * decode the event - sas phy detected event backs up the state machine to the
1040 * await speed notification. - identify timeout is an un-expected event and the
1041 * state machine is restarted. - link failure events restart the starting state
1042 * machine - any other events log a warning message and set a failure status
1043 * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any
1044 * unexpected event notifation
1046 static enum sci_status scic_sds_phy_starting_substate_await_sig_fis_event_handler(
1047 struct scic_sds_phy *sci_phy, u32 event_code)
1049 u32 result = SCI_SUCCESS;
1051 switch (scu_get_event_code(event_code)) {
1052 case SCU_EVENT_SATA_PHY_DETECTED:
1053 /* Backup the state machine */
1054 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
1055 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN);
1056 break;
1058 case SCU_EVENT_LINK_FAILURE:
1059 /* Link failure change state back to the starting state */
1060 scic_sds_phy_restart_starting_state(sci_phy);
1061 break;
1063 default:
1064 dev_warn(sciphy_to_dev(sci_phy),
1065 "%s: PHY starting substate machine received "
1066 "unexpected event_code %x\n",
1067 __func__,
1068 event_code);
1070 result = SCI_FAILURE;
1071 break;
1074 return result;
1079 * *****************************************************************************
1080 * * SCIC SDS PHY FRAME_HANDLERS
1081 * ***************************************************************************** */
1085 * @phy: This is struct scic_sds_phy object which is being requested to decode the
1086 * frame data.
1087 * @frame_index: This is the index of the unsolicited frame which was received
1088 * for this phy.
1090 * This method decodes the unsolicited frame when the struct scic_sds_phy is in the
1091 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - Get the UF Header - If the UF
1092 * is an IAF - Copy IAF data to local phy object IAF data buffer. - Change
1093 * starting substate to wait power. - else - log warning message of unexpected
1094 * unsolicted frame - release frame buffer enum sci_status SCI_SUCCESS
1096 static enum sci_status scic_sds_phy_starting_substate_await_iaf_uf_frame_handler(
1097 struct scic_sds_phy *sci_phy, u32 frame_index)
1099 enum sci_status result;
1100 u32 *frame_words;
1101 struct sas_identify_frame iaf;
1102 struct isci_phy *iphy = sci_phy->iphy;
1104 result = scic_sds_unsolicited_frame_control_get_header(
1105 &(scic_sds_phy_get_controller(sci_phy)->uf_control),
1106 frame_index,
1107 (void **)&frame_words);
1109 if (result != SCI_SUCCESS)
1110 return result;
1112 sci_swab32_cpy(&iaf, frame_words, sizeof(iaf) / sizeof(u32));
1113 if (iaf.frame_type == 0) {
1114 u32 state;
1116 memcpy(&iphy->frame_rcvd.iaf, &iaf, sizeof(iaf));
1117 if (iaf.smp_tport) {
1118 /* We got the IAF for an expander PHY go to the final
1119 * state since there are no power requirements for
1120 * expander phys.
1122 state = SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL;
1123 } else {
1124 /* We got the IAF we can now go to the await spinup
1125 * semaphore state
1127 state = SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER;
1129 sci_base_state_machine_change_state(
1130 &sci_phy->starting_substate_machine,
1131 state);
1132 result = SCI_SUCCESS;
1133 } else
1134 dev_warn(sciphy_to_dev(sci_phy),
1135 "%s: PHY starting substate machine received "
1136 "unexpected frame id %x\n",
1137 __func__,
1138 frame_index);
1140 scic_sds_controller_release_frame(scic_sds_phy_get_controller(sci_phy),
1141 frame_index);
1143 return result;
1148 * @phy: This is struct scic_sds_phy object which is being requested to decode the
1149 * frame data.
1150 * @frame_index: This is the index of the unsolicited frame which was received
1151 * for this phy.
1153 * This method decodes the unsolicited frame when the struct scic_sds_phy is in the
1154 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Get the UF Header - If
1155 * the UF is an SIGNATURE FIS - Copy IAF data to local phy object SIGNATURE FIS
1156 * data buffer. - else - log warning message of unexpected unsolicted frame -
1157 * release frame buffer enum sci_status SCI_SUCCESS Must decode the SIGNATURE FIS
1158 * data
1160 static enum sci_status scic_sds_phy_starting_substate_await_sig_fis_frame_handler(
1161 struct scic_sds_phy *sci_phy,
1162 u32 frame_index)
1164 enum sci_status result;
1165 struct dev_to_host_fis *frame_header;
1166 u32 *fis_frame_data;
1167 struct isci_phy *iphy = sci_phy->iphy;
1169 result = scic_sds_unsolicited_frame_control_get_header(
1170 &(scic_sds_phy_get_controller(sci_phy)->uf_control),
1171 frame_index,
1172 (void **)&frame_header);
1174 if (result != SCI_SUCCESS)
1175 return result;
1177 if ((frame_header->fis_type == FIS_REGD2H) &&
1178 !(frame_header->status & ATA_BUSY)) {
1179 scic_sds_unsolicited_frame_control_get_buffer(
1180 &(scic_sds_phy_get_controller(sci_phy)->uf_control),
1181 frame_index,
1182 (void **)&fis_frame_data);
1184 scic_sds_controller_copy_sata_response(&iphy->frame_rcvd.fis,
1185 frame_header,
1186 fis_frame_data);
1188 /* got IAF we can now go to the await spinup semaphore state */
1189 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
1190 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL);
1192 result = SCI_SUCCESS;
1193 } else
1194 dev_warn(sciphy_to_dev(sci_phy),
1195 "%s: PHY starting substate machine received "
1196 "unexpected frame id %x\n",
1197 __func__,
1198 frame_index);
1200 /* Regardless of the result we are done with this frame with it */
1201 scic_sds_controller_release_frame(scic_sds_phy_get_controller(sci_phy),
1202 frame_index);
1204 return result;
1208 * *****************************************************************************
1209 * * SCIC SDS PHY POWER_HANDLERS
1210 * ***************************************************************************** */
1213 * This method is called by the struct scic_sds_controller when the phy object is
1214 * granted power. - The notify enable spinups are turned on for this phy object
1215 * - The phy state machine is transitioned to the
1216 * SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. enum sci_status SCI_SUCCESS
1218 static enum sci_status scic_sds_phy_starting_substate_await_sas_power_consume_power_handler(
1219 struct scic_sds_phy *sci_phy)
1221 u32 enable_spinup;
1223 enable_spinup = readl(&sci_phy->link_layer_registers->notify_enable_spinup_control);
1224 enable_spinup |= SCU_ENSPINUP_GEN_BIT(ENABLE);
1225 writel(enable_spinup, &sci_phy->link_layer_registers->notify_enable_spinup_control);
1227 /* Change state to the final state this substate machine has run to completion */
1228 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
1229 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL);
1231 return SCI_SUCCESS;
1235 * This method is called by the struct scic_sds_controller when the phy object is
1236 * granted power. - The phy state machine is transitioned to the
1237 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. enum sci_status SCI_SUCCESS
1239 static enum sci_status scic_sds_phy_starting_substate_await_sata_power_consume_power_handler(
1240 struct scic_sds_phy *sci_phy)
1242 u32 scu_sas_pcfg_value;
1244 /* Release the spinup hold state and reset the OOB state machine */
1245 scu_sas_pcfg_value =
1246 readl(&sci_phy->link_layer_registers->phy_configuration);
1247 scu_sas_pcfg_value &=
1248 ~(SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD) | SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE));
1249 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
1250 writel(scu_sas_pcfg_value,
1251 &sci_phy->link_layer_registers->phy_configuration);
1253 /* Now restart the OOB operation */
1254 scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
1255 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
1256 writel(scu_sas_pcfg_value,
1257 &sci_phy->link_layer_registers->phy_configuration);
1259 /* Change state to the final state this substate machine has run to completion */
1260 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
1261 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN);
1263 return SCI_SUCCESS;
1266 static enum sci_status default_phy_handler(struct scic_sds_phy *sci_phy,
1267 const char *func)
1269 dev_dbg(sciphy_to_dev(sci_phy),
1270 "%s: in wrong state: %d\n", func,
1271 sci_base_state_machine_get_state(&sci_phy->state_machine));
1272 return SCI_FAILURE_INVALID_STATE;
1275 static enum sci_status
1276 scic_sds_phy_default_start_handler(struct scic_sds_phy *sci_phy)
1278 return default_phy_handler(sci_phy, __func__);
1281 static enum sci_status
1282 scic_sds_phy_default_stop_handler(struct scic_sds_phy *sci_phy)
1284 return default_phy_handler(sci_phy, __func__);
1287 static enum sci_status
1288 scic_sds_phy_default_reset_handler(struct scic_sds_phy *sci_phy)
1290 return default_phy_handler(sci_phy, __func__);
1293 static enum sci_status
1294 scic_sds_phy_default_destroy_handler(struct scic_sds_phy *sci_phy)
1296 return default_phy_handler(sci_phy, __func__);
1299 static enum sci_status
1300 scic_sds_phy_default_frame_handler(struct scic_sds_phy *sci_phy,
1301 u32 frame_index)
1303 struct scic_sds_controller *scic = scic_sds_phy_get_controller(sci_phy);
1305 default_phy_handler(sci_phy, __func__);
1306 scic_sds_controller_release_frame(scic, frame_index);
1308 return SCI_FAILURE_INVALID_STATE;
1311 static enum sci_status
1312 scic_sds_phy_default_event_handler(struct scic_sds_phy *sci_phy,
1313 u32 event_code)
1315 return default_phy_handler(sci_phy, __func__);
1318 static enum sci_status
1319 scic_sds_phy_default_consume_power_handler(struct scic_sds_phy *sci_phy)
1321 return default_phy_handler(sci_phy, __func__);
1326 static const struct scic_sds_phy_state_handler scic_sds_phy_starting_substate_handler_table[] = {
1327 [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL] = {
1328 .start_handler = scic_sds_phy_default_start_handler,
1329 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1330 .reset_handler = scic_sds_phy_default_reset_handler,
1331 .destruct_handler = scic_sds_phy_default_destroy_handler,
1332 .frame_handler = scic_sds_phy_default_frame_handler,
1333 .event_handler = scic_sds_phy_default_event_handler,
1334 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1336 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN] = {
1337 .start_handler = scic_sds_phy_default_start_handler,
1338 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1339 .reset_handler = scic_sds_phy_default_reset_handler,
1340 .destruct_handler = scic_sds_phy_default_destroy_handler,
1341 .frame_handler = scic_sds_phy_default_frame_handler,
1342 .event_handler = scic_sds_phy_starting_substate_await_ossp_event_handler,
1343 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1345 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN] = {
1346 .start_handler = scic_sds_phy_default_start_handler,
1347 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1348 .reset_handler = scic_sds_phy_default_reset_handler,
1349 .destruct_handler = scic_sds_phy_default_destroy_handler,
1350 .frame_handler = scic_sds_phy_default_frame_handler,
1351 .event_handler = scic_sds_phy_starting_substate_await_sas_phy_speed_event_handler,
1352 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1354 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF] = {
1355 .start_handler = scic_sds_phy_default_start_handler,
1356 .stop_handler = scic_sds_phy_default_stop_handler,
1357 .reset_handler = scic_sds_phy_default_reset_handler,
1358 .destruct_handler = scic_sds_phy_default_destroy_handler,
1359 .frame_handler = scic_sds_phy_starting_substate_await_iaf_uf_frame_handler,
1360 .event_handler = scic_sds_phy_starting_substate_await_iaf_uf_event_handler,
1361 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1363 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER] = {
1364 .start_handler = scic_sds_phy_default_start_handler,
1365 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1366 .reset_handler = scic_sds_phy_default_reset_handler,
1367 .destruct_handler = scic_sds_phy_default_destroy_handler,
1368 .frame_handler = scic_sds_phy_default_frame_handler,
1369 .event_handler = scic_sds_phy_starting_substate_await_sas_power_event_handler,
1370 .consume_power_handler = scic_sds_phy_starting_substate_await_sas_power_consume_power_handler
1372 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER] = {
1373 .start_handler = scic_sds_phy_default_start_handler,
1374 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1375 .reset_handler = scic_sds_phy_default_reset_handler,
1376 .destruct_handler = scic_sds_phy_default_destroy_handler,
1377 .frame_handler = scic_sds_phy_default_frame_handler,
1378 .event_handler = scic_sds_phy_starting_substate_await_sata_power_event_handler,
1379 .consume_power_handler = scic_sds_phy_starting_substate_await_sata_power_consume_power_handler
1381 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN] = {
1382 .start_handler = scic_sds_phy_default_start_handler,
1383 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1384 .reset_handler = scic_sds_phy_default_reset_handler,
1385 .destruct_handler = scic_sds_phy_default_destroy_handler,
1386 .frame_handler = scic_sds_phy_default_frame_handler,
1387 .event_handler = scic_sds_phy_starting_substate_await_sata_phy_event_handler,
1388 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1390 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN] = {
1391 .start_handler = scic_sds_phy_default_start_handler,
1392 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1393 .reset_handler = scic_sds_phy_default_reset_handler,
1394 .destruct_handler = scic_sds_phy_default_destroy_handler,
1395 .frame_handler = scic_sds_phy_default_frame_handler,
1396 .event_handler = scic_sds_phy_starting_substate_await_sata_speed_event_handler,
1397 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1399 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF] = {
1400 .start_handler = scic_sds_phy_default_start_handler,
1401 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1402 .reset_handler = scic_sds_phy_default_reset_handler,
1403 .destruct_handler = scic_sds_phy_default_destroy_handler,
1404 .frame_handler = scic_sds_phy_starting_substate_await_sig_fis_frame_handler,
1405 .event_handler = scic_sds_phy_starting_substate_await_sig_fis_event_handler,
1406 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1408 [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL] = {
1409 .start_handler = scic_sds_phy_default_start_handler,
1410 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1411 .reset_handler = scic_sds_phy_default_reset_handler,
1412 .destruct_handler = scic_sds_phy_default_destroy_handler,
1413 .frame_handler = scic_sds_phy_default_frame_handler,
1414 .event_handler = scic_sds_phy_default_event_handler,
1415 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1420 * scic_sds_phy_set_starting_substate_handlers() -
1422 * This macro sets the starting substate handlers by state_id
1424 #define scic_sds_phy_set_starting_substate_handlers(phy, state_id) \
1425 scic_sds_phy_set_state_handlers(\
1426 (phy), \
1427 &scic_sds_phy_starting_substate_handler_table[(state_id)] \
1431 * ****************************************************************************
1432 * * PHY STARTING SUBSTATE METHODS
1433 * **************************************************************************** */
1436 * scic_sds_phy_starting_initial_substate_enter -
1437 * @object: This is the object which is cast to a struct scic_sds_phy object.
1439 * This method will perform the actions required by the struct scic_sds_phy on
1440 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL. - The initial state
1441 * handlers are put in place for the struct scic_sds_phy object. - The state is
1442 * changed to the wait phy type event notification. none
1444 static void scic_sds_phy_starting_initial_substate_enter(void *object)
1446 struct scic_sds_phy *sci_phy = object;
1448 scic_sds_phy_set_starting_substate_handlers(
1449 sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL);
1451 /* This is just an temporary state go off to the starting state */
1452 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
1453 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN);
1458 * @object: This is the object which is cast to a struct scic_sds_phy object.
1460 * This method will perform the actions required by the struct scic_sds_phy on
1461 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_PHY_TYPE_EN. - Set the
1462 * struct scic_sds_phy object state handlers for this state. none
1464 static void scic_sds_phy_starting_await_ossp_en_substate_enter(void *object)
1466 struct scic_sds_phy *sci_phy = object;
1468 scic_sds_phy_set_starting_substate_handlers(
1469 sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
1475 * @object: This is the object which is cast to a struct scic_sds_phy object.
1477 * This method will perform the actions required by the struct scic_sds_phy on
1478 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. - Set the
1479 * struct scic_sds_phy object state handlers for this state. none
1481 static void scic_sds_phy_starting_await_sas_speed_en_substate_enter(
1482 void *object)
1484 struct scic_sds_phy *sci_phy = object;
1486 scic_sds_phy_set_starting_substate_handlers(
1487 sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
1493 * @object: This is the object which is cast to a struct scic_sds_phy object.
1495 * This method will perform the actions required by the struct scic_sds_phy on
1496 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - Set the
1497 * struct scic_sds_phy object state handlers for this state. none
1499 static void scic_sds_phy_starting_await_iaf_uf_substate_enter(void *object)
1501 struct scic_sds_phy *sci_phy = object;
1503 scic_sds_phy_set_starting_substate_handlers(
1504 sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
1510 * @object: This is the object which is cast to a struct scic_sds_phy object.
1512 * This method will perform the actions required by the struct scic_sds_phy on
1513 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Set the
1514 * struct scic_sds_phy object state handlers for this state. - Add this phy object to
1515 * the power control queue none
1517 static void scic_sds_phy_starting_await_sas_power_substate_enter(void *object)
1519 struct scic_sds_phy *sci_phy = object;
1521 scic_sds_phy_set_starting_substate_handlers(
1522 sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
1525 scic_sds_controller_power_control_queue_insert(
1526 scic_sds_phy_get_controller(sci_phy),
1527 sci_phy
1533 * @object: This is the object which is cast to a struct scic_sds_phy object.
1535 * This method will perform the actions required by the struct scic_sds_phy on exiting
1536 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Remove the
1537 * struct scic_sds_phy object from the power control queue. none
1539 static void scic_sds_phy_starting_await_sas_power_substate_exit(void *object)
1541 struct scic_sds_phy *sci_phy = object;
1543 scic_sds_controller_power_control_queue_remove(
1544 scic_sds_phy_get_controller(sci_phy), sci_phy
1550 * @object: This is the object which is cast to a struct scic_sds_phy object.
1552 * This method will perform the actions required by the struct scic_sds_phy on
1553 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Set the
1554 * struct scic_sds_phy object state handlers for this state. - Add this phy object to
1555 * the power control queue none
1557 static void scic_sds_phy_starting_await_sata_power_substate_enter(void *object)
1559 struct scic_sds_phy *sci_phy = object;
1561 scic_sds_phy_set_starting_substate_handlers(
1562 sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
1565 scic_sds_controller_power_control_queue_insert(
1566 scic_sds_phy_get_controller(sci_phy),
1567 sci_phy
1573 * @object: This is the object which is cast to a struct scic_sds_phy object.
1575 * This method will perform the actions required by the struct scic_sds_phy on exiting
1576 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Remove the
1577 * struct scic_sds_phy object from the power control queue. none
1579 static void scic_sds_phy_starting_await_sata_power_substate_exit(void *object)
1581 struct scic_sds_phy *sci_phy = object;
1583 scic_sds_controller_power_control_queue_remove(
1584 scic_sds_phy_get_controller(sci_phy),
1585 sci_phy
1591 * @object: This is the object which is cast to a struct scic_sds_phy object.
1593 * This function will perform the actions required by the struct scic_sds_phy on
1594 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. - Set the
1595 * struct scic_sds_phy object state handlers for this state. none
1597 static void scic_sds_phy_starting_await_sata_phy_substate_enter(void *object)
1599 struct scic_sds_phy *sci_phy = object;
1601 scic_sds_phy_set_starting_substate_handlers(
1602 sci_phy,
1603 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN);
1605 isci_timer_start(sci_phy->sata_timeout_timer,
1606 SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
1611 * @object: This is the object which is cast to a struct scic_sds_phy object.
1613 * This method will perform the actions required by the struct scic_sds_phy
1614 * on exiting
1615 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
1616 * that was started on entry to await sata phy event notification none
1618 static inline void scic_sds_phy_starting_await_sata_phy_substate_exit(
1619 void *object)
1621 struct scic_sds_phy *sci_phy = object;
1623 isci_timer_stop(sci_phy->sata_timeout_timer);
1628 * @object: This is the object which is cast to a struct scic_sds_phy object.
1630 * This method will perform the actions required by the struct scic_sds_phy on
1631 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - Set the
1632 * struct scic_sds_phy object state handlers for this state. none
1634 static void scic_sds_phy_starting_await_sata_speed_substate_enter(void *object)
1636 struct scic_sds_phy *sci_phy = object;
1638 scic_sds_phy_set_starting_substate_handlers(
1639 sci_phy,
1640 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN);
1642 isci_timer_start(sci_phy->sata_timeout_timer,
1643 SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
1648 * @object: This is the object which is cast to a struct scic_sds_phy object.
1650 * This function will perform the actions required by the
1651 * struct scic_sds_phy on exiting
1652 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
1653 * that was started on entry to await sata phy event notification none
1655 static inline void scic_sds_phy_starting_await_sata_speed_substate_exit(
1656 void *object)
1658 struct scic_sds_phy *sci_phy = object;
1660 isci_timer_stop(sci_phy->sata_timeout_timer);
1665 * @object: This is the object which is cast to a struct scic_sds_phy object.
1667 * This function will perform the actions required by the struct scic_sds_phy on
1668 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Set the
1669 * struct scic_sds_phy object state handlers for this state.
1670 * - Start the SIGNATURE FIS
1671 * timeout timer none
1673 static void scic_sds_phy_starting_await_sig_fis_uf_substate_enter(void *object)
1675 bool continue_to_ready_state;
1676 struct scic_sds_phy *sci_phy = object;
1678 scic_sds_phy_set_starting_substate_handlers(
1679 sci_phy,
1680 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
1682 continue_to_ready_state = scic_sds_port_link_detected(
1683 sci_phy->owning_port,
1684 sci_phy);
1686 if (continue_to_ready_state) {
1688 * Clear the PE suspend condition so we can actually
1689 * receive SIG FIS
1690 * The hardware will not respond to the XRDY until the PE
1691 * suspend condition is cleared.
1693 scic_sds_phy_resume(sci_phy);
1695 isci_timer_start(sci_phy->sata_timeout_timer,
1696 SCIC_SDS_SIGNATURE_FIS_TIMEOUT);
1697 } else
1698 sci_phy->is_in_link_training = false;
1703 * @object: This is the object which is cast to a struct scic_sds_phy object.
1705 * This function will perform the actions required by the
1706 * struct scic_sds_phy on exiting
1707 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Stop the SIGNATURE
1708 * FIS timeout timer. none
1710 static inline void scic_sds_phy_starting_await_sig_fis_uf_substate_exit(
1711 void *object)
1713 struct scic_sds_phy *sci_phy = object;
1715 isci_timer_stop(sci_phy->sata_timeout_timer);
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
1723 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. - Set the struct scic_sds_phy
1724 * object state handlers for this state. - Change base state machine to the
1725 * ready state. none
1727 static void scic_sds_phy_starting_final_substate_enter(void *object)
1729 struct scic_sds_phy *sci_phy = object;
1731 scic_sds_phy_set_starting_substate_handlers(sci_phy,
1732 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL);
1734 /* State machine has run to completion so exit out and change
1735 * the base state machine to the ready state
1737 sci_base_state_machine_change_state(&sci_phy->state_machine,
1738 SCI_BASE_PHY_STATE_READY);
1741 /* --------------------------------------------------------------------------- */
1743 static const struct sci_base_state scic_sds_phy_starting_substates[] = {
1744 [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL] = {
1745 .enter_state = scic_sds_phy_starting_initial_substate_enter,
1747 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN] = {
1748 .enter_state = scic_sds_phy_starting_await_ossp_en_substate_enter,
1750 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN] = {
1751 .enter_state = scic_sds_phy_starting_await_sas_speed_en_substate_enter,
1753 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF] = {
1754 .enter_state = scic_sds_phy_starting_await_iaf_uf_substate_enter,
1756 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER] = {
1757 .enter_state = scic_sds_phy_starting_await_sas_power_substate_enter,
1758 .exit_state = scic_sds_phy_starting_await_sas_power_substate_exit,
1760 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER] = {
1761 .enter_state = scic_sds_phy_starting_await_sata_power_substate_enter,
1762 .exit_state = scic_sds_phy_starting_await_sata_power_substate_exit
1764 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN] = {
1765 .enter_state = scic_sds_phy_starting_await_sata_phy_substate_enter,
1766 .exit_state = scic_sds_phy_starting_await_sata_phy_substate_exit
1768 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN] = {
1769 .enter_state = scic_sds_phy_starting_await_sata_speed_substate_enter,
1770 .exit_state = scic_sds_phy_starting_await_sata_speed_substate_exit
1772 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF] = {
1773 .enter_state = scic_sds_phy_starting_await_sig_fis_uf_substate_enter,
1774 .exit_state = scic_sds_phy_starting_await_sig_fis_uf_substate_exit
1776 [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL] = {
1777 .enter_state = scic_sds_phy_starting_final_substate_enter,
1782 * This method takes the struct scic_sds_phy from a stopped state and
1783 * attempts to start it. - The phy state machine is transitioned to the
1784 * SCI_BASE_PHY_STATE_STARTING. enum sci_status SCI_SUCCESS
1786 static enum sci_status
1787 scic_sds_phy_stopped_state_start_handler(struct scic_sds_phy *sci_phy)
1789 struct isci_host *ihost;
1790 struct scic_sds_controller *scic;
1792 scic = scic_sds_phy_get_controller(sci_phy),
1793 ihost = scic->ihost;
1795 /* Create the SIGNATURE FIS Timeout timer for this phy */
1796 sci_phy->sata_timeout_timer = isci_timer_create(ihost, sci_phy,
1797 scic_sds_phy_sata_timeout);
1799 if (sci_phy->sata_timeout_timer)
1800 sci_base_state_machine_change_state(&sci_phy->state_machine,
1801 SCI_BASE_PHY_STATE_STARTING);
1803 return SCI_SUCCESS;
1806 static enum sci_status
1807 scic_sds_phy_stopped_state_destroy_handler(struct scic_sds_phy *sci_phy)
1809 return SCI_SUCCESS;
1812 static enum sci_status
1813 scic_sds_phy_ready_state_stop_handler(struct scic_sds_phy *sci_phy)
1815 sci_base_state_machine_change_state(&sci_phy->state_machine,
1816 SCI_BASE_PHY_STATE_STOPPED);
1818 return SCI_SUCCESS;
1821 static enum sci_status
1822 scic_sds_phy_ready_state_reset_handler(struct scic_sds_phy *sci_phy)
1824 sci_base_state_machine_change_state(&sci_phy->state_machine,
1825 SCI_BASE_PHY_STATE_RESETTING);
1827 return SCI_SUCCESS;
1831 * scic_sds_phy_ready_state_event_handler -
1832 * @phy: This is the struct scic_sds_phy object which has received the event.
1834 * This method request the struct scic_sds_phy handle the received event. The only
1835 * event that we are interested in while in the ready state is the link failure
1836 * event. - decoded event is a link failure - transition the struct scic_sds_phy back
1837 * to the SCI_BASE_PHY_STATE_STARTING state. - any other event received will
1838 * report a warning message enum sci_status SCI_SUCCESS if the event received is a
1839 * link failure SCI_FAILURE_INVALID_STATE for any other event received.
1841 static enum sci_status scic_sds_phy_ready_state_event_handler(struct scic_sds_phy *sci_phy,
1842 u32 event_code)
1844 enum sci_status result = SCI_FAILURE;
1846 switch (scu_get_event_code(event_code)) {
1847 case SCU_EVENT_LINK_FAILURE:
1848 /* Link failure change state back to the starting state */
1849 sci_base_state_machine_change_state(&sci_phy->state_machine,
1850 SCI_BASE_PHY_STATE_STARTING);
1851 result = SCI_SUCCESS;
1852 break;
1854 case SCU_EVENT_BROADCAST_CHANGE:
1855 /* Broadcast change received. Notify the port. */
1856 if (scic_sds_phy_get_port(sci_phy) != NULL)
1857 scic_sds_port_broadcast_change_received(sci_phy->owning_port, sci_phy);
1858 else
1859 sci_phy->bcn_received_while_port_unassigned = true;
1860 break;
1862 default:
1863 dev_warn(sciphy_to_dev(sci_phy),
1864 "%sP SCIC PHY 0x%p ready state machine received "
1865 "unexpected event_code %x\n",
1866 __func__, sci_phy, event_code);
1868 result = SCI_FAILURE_INVALID_STATE;
1869 break;
1872 return result;
1875 static enum sci_status scic_sds_phy_resetting_state_event_handler(struct scic_sds_phy *sci_phy,
1876 u32 event_code)
1878 enum sci_status result = SCI_FAILURE;
1880 switch (scu_get_event_code(event_code)) {
1881 case SCU_EVENT_HARD_RESET_TRANSMITTED:
1882 /* Link failure change state back to the starting state */
1883 sci_base_state_machine_change_state(&sci_phy->state_machine,
1884 SCI_BASE_PHY_STATE_STARTING);
1885 result = SCI_SUCCESS;
1886 break;
1888 default:
1889 dev_warn(sciphy_to_dev(sci_phy),
1890 "%s: SCIC PHY 0x%p resetting state machine received "
1891 "unexpected event_code %x\n",
1892 __func__, sci_phy, event_code);
1894 result = SCI_FAILURE_INVALID_STATE;
1895 break;
1898 return result;
1901 /* --------------------------------------------------------------------------- */
1903 static const struct scic_sds_phy_state_handler scic_sds_phy_state_handler_table[] = {
1904 [SCI_BASE_PHY_STATE_INITIAL] = {
1905 .start_handler = scic_sds_phy_default_start_handler,
1906 .stop_handler = scic_sds_phy_default_stop_handler,
1907 .reset_handler = scic_sds_phy_default_reset_handler,
1908 .destruct_handler = scic_sds_phy_default_destroy_handler,
1909 .frame_handler = scic_sds_phy_default_frame_handler,
1910 .event_handler = scic_sds_phy_default_event_handler,
1911 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1913 [SCI_BASE_PHY_STATE_STOPPED] = {
1914 .start_handler = scic_sds_phy_stopped_state_start_handler,
1915 .stop_handler = scic_sds_phy_default_stop_handler,
1916 .reset_handler = scic_sds_phy_default_reset_handler,
1917 .destruct_handler = scic_sds_phy_stopped_state_destroy_handler,
1918 .frame_handler = scic_sds_phy_default_frame_handler,
1919 .event_handler = scic_sds_phy_default_event_handler,
1920 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1922 [SCI_BASE_PHY_STATE_STARTING] = {
1923 .start_handler = scic_sds_phy_default_start_handler,
1924 .stop_handler = scic_sds_phy_default_stop_handler,
1925 .reset_handler = scic_sds_phy_default_reset_handler,
1926 .destruct_handler = scic_sds_phy_default_destroy_handler,
1927 .frame_handler = scic_sds_phy_default_frame_handler,
1928 .event_handler = scic_sds_phy_default_event_handler,
1929 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1931 [SCI_BASE_PHY_STATE_READY] = {
1932 .start_handler = scic_sds_phy_default_start_handler,
1933 .stop_handler = scic_sds_phy_ready_state_stop_handler,
1934 .reset_handler = scic_sds_phy_ready_state_reset_handler,
1935 .destruct_handler = scic_sds_phy_default_destroy_handler,
1936 .frame_handler = scic_sds_phy_default_frame_handler,
1937 .event_handler = scic_sds_phy_ready_state_event_handler,
1938 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1940 [SCI_BASE_PHY_STATE_RESETTING] = {
1941 .start_handler = scic_sds_phy_default_start_handler,
1942 .stop_handler = scic_sds_phy_default_stop_handler,
1943 .reset_handler = scic_sds_phy_default_reset_handler,
1944 .destruct_handler = scic_sds_phy_default_destroy_handler,
1945 .frame_handler = scic_sds_phy_default_frame_handler,
1946 .event_handler = scic_sds_phy_resetting_state_event_handler,
1947 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1949 [SCI_BASE_PHY_STATE_FINAL] = {
1950 .start_handler = scic_sds_phy_default_start_handler,
1951 .stop_handler = scic_sds_phy_default_stop_handler,
1952 .reset_handler = scic_sds_phy_default_reset_handler,
1953 .destruct_handler = scic_sds_phy_default_destroy_handler,
1954 .frame_handler = scic_sds_phy_default_frame_handler,
1955 .event_handler = scic_sds_phy_default_event_handler,
1956 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1961 * ****************************************************************************
1962 * * PHY STATE PRIVATE METHODS
1963 * **************************************************************************** */
1967 * @sci_phy: This is the struct scic_sds_phy object to stop.
1969 * This method will stop the struct scic_sds_phy object. This does not reset the
1970 * protocol engine it just suspends it and places it in a state where it will
1971 * not cause the end device to power up. none
1973 static void scu_link_layer_stop_protocol_engine(
1974 struct scic_sds_phy *sci_phy)
1976 u32 scu_sas_pcfg_value;
1977 u32 enable_spinup_value;
1979 /* Suspend the protocol engine and place it in a sata spinup hold state */
1980 scu_sas_pcfg_value =
1981 readl(&sci_phy->link_layer_registers->phy_configuration);
1982 scu_sas_pcfg_value |=
1983 (SCU_SAS_PCFG_GEN_BIT(OOB_RESET) |
1984 SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE) |
1985 SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD));
1986 writel(scu_sas_pcfg_value,
1987 &sci_phy->link_layer_registers->phy_configuration);
1989 /* Disable the notify enable spinup primitives */
1990 enable_spinup_value = readl(&sci_phy->link_layer_registers->notify_enable_spinup_control);
1991 enable_spinup_value &= ~SCU_ENSPINUP_GEN_BIT(ENABLE);
1992 writel(enable_spinup_value, &sci_phy->link_layer_registers->notify_enable_spinup_control);
1998 * This method will start the OOB/SN state machine for this struct scic_sds_phy object.
2000 static void scu_link_layer_start_oob(
2001 struct scic_sds_phy *sci_phy)
2003 u32 scu_sas_pcfg_value;
2005 scu_sas_pcfg_value =
2006 readl(&sci_phy->link_layer_registers->phy_configuration);
2007 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
2008 scu_sas_pcfg_value &=
2009 ~(SCU_SAS_PCFG_GEN_BIT(OOB_RESET) |
2010 SCU_SAS_PCFG_GEN_BIT(HARD_RESET));
2011 writel(scu_sas_pcfg_value,
2012 &sci_phy->link_layer_registers->phy_configuration);
2018 * This method will transmit a hard reset request on the specified phy. The SCU
2019 * hardware requires that we reset the OOB state machine and set the hard reset
2020 * bit in the phy configuration register. We then must start OOB over with the
2021 * hard reset bit set.
2023 static void scu_link_layer_tx_hard_reset(
2024 struct scic_sds_phy *sci_phy)
2026 u32 phy_configuration_value;
2029 * SAS Phys must wait for the HARD_RESET_TX event notification to transition
2030 * to the starting state. */
2031 phy_configuration_value =
2032 readl(&sci_phy->link_layer_registers->phy_configuration);
2033 phy_configuration_value |=
2034 (SCU_SAS_PCFG_GEN_BIT(HARD_RESET) |
2035 SCU_SAS_PCFG_GEN_BIT(OOB_RESET));
2036 writel(phy_configuration_value,
2037 &sci_phy->link_layer_registers->phy_configuration);
2039 /* Now take the OOB state machine out of reset */
2040 phy_configuration_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
2041 phy_configuration_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
2042 writel(phy_configuration_value,
2043 &sci_phy->link_layer_registers->phy_configuration);
2047 * ****************************************************************************
2048 * * PHY BASE STATE METHODS
2049 * **************************************************************************** */
2053 * @object: This is the object which is cast to a struct scic_sds_phy object.
2055 * This method will perform the actions required by the struct scic_sds_phy on
2056 * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
2057 * handlers for the phy object base state machine initial state. none
2059 static void scic_sds_phy_initial_state_enter(void *object)
2061 struct scic_sds_phy *sci_phy = object;
2063 scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_INITIAL);
2068 * @object: This is the object which is cast to a struct scic_sds_phy object.
2070 * This function will perform the actions required by the struct scic_sds_phy on
2071 * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
2072 * handlers for the phy object base state machine initial state. - The SCU
2073 * hardware is requested to stop the protocol engine. none
2075 static void scic_sds_phy_stopped_state_enter(void *object)
2077 struct scic_sds_phy *sci_phy = object;
2078 struct scic_sds_controller *scic = scic_sds_phy_get_controller(sci_phy);
2079 struct isci_host *ihost = scic->ihost;
2082 * @todo We need to get to the controller to place this PE in a
2083 * reset state
2086 scic_sds_phy_set_base_state_handlers(sci_phy,
2087 SCI_BASE_PHY_STATE_STOPPED);
2089 if (sci_phy->sata_timeout_timer != NULL) {
2090 isci_del_timer(ihost, sci_phy->sata_timeout_timer);
2092 sci_phy->sata_timeout_timer = NULL;
2095 scu_link_layer_stop_protocol_engine(sci_phy);
2097 if (sci_phy->state_machine.previous_state_id !=
2098 SCI_BASE_PHY_STATE_INITIAL)
2099 scic_sds_controller_link_down(
2100 scic_sds_phy_get_controller(sci_phy),
2101 scic_sds_phy_get_port(sci_phy),
2102 sci_phy);
2107 * @object: This is the object which is cast to a struct scic_sds_phy object.
2109 * This method will perform the actions required by the struct scic_sds_phy on
2110 * entering the SCI_BASE_PHY_STATE_STARTING. - This function sets the state
2111 * handlers for the phy object base state machine starting state. - The SCU
2112 * hardware is requested to start OOB/SN on this protocl engine. - The phy
2113 * starting substate machine is started. - If the previous state was the ready
2114 * state then the struct scic_sds_controller is informed that the phy has gone link
2115 * down. none
2117 static void scic_sds_phy_starting_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_STARTING);
2123 scu_link_layer_stop_protocol_engine(sci_phy);
2124 scu_link_layer_start_oob(sci_phy);
2126 /* We don't know what kind of phy we are going to be just yet */
2127 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
2128 sci_phy->bcn_received_while_port_unassigned = false;
2130 /* Change over to the starting substate machine to continue */
2131 sci_base_state_machine_start(&sci_phy->starting_substate_machine);
2133 if (sci_phy->state_machine.previous_state_id
2134 == SCI_BASE_PHY_STATE_READY) {
2135 scic_sds_controller_link_down(
2136 scic_sds_phy_get_controller(sci_phy),
2137 scic_sds_phy_get_port(sci_phy),
2138 sci_phy
2145 * @object: This is the object which is cast to a struct scic_sds_phy object.
2147 * This method will perform the actions required by the struct scic_sds_phy on
2148 * entering the SCI_BASE_PHY_STATE_READY. - This function sets the state
2149 * handlers for the phy object base state machine ready state. - The SCU
2150 * hardware protocol engine is resumed. - The struct scic_sds_controller is informed
2151 * that the phy object has gone link up. none
2153 static void scic_sds_phy_ready_state_enter(void *object)
2155 struct scic_sds_phy *sci_phy = object;
2157 scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_READY);
2159 scic_sds_controller_link_up(
2160 scic_sds_phy_get_controller(sci_phy),
2161 scic_sds_phy_get_port(sci_phy),
2162 sci_phy
2168 * @object: This is the object which is cast to a struct scic_sds_phy object.
2170 * This method will perform the actions required by the struct scic_sds_phy on exiting
2171 * the SCI_BASE_PHY_STATE_INITIAL. This function suspends the SCU hardware
2172 * protocol engine represented by this struct scic_sds_phy object. none
2174 static void scic_sds_phy_ready_state_exit(void *object)
2176 struct scic_sds_phy *sci_phy = object;
2178 scic_sds_phy_suspend(sci_phy);
2183 * @object: This is the object which is cast to a struct scic_sds_phy object.
2185 * This method will perform the actions required by the struct scic_sds_phy on
2186 * entering the SCI_BASE_PHY_STATE_RESETTING. - This function sets the state
2187 * handlers for the phy object base state machine resetting state. none
2189 static void scic_sds_phy_resetting_state_enter(void *object)
2191 struct scic_sds_phy *sci_phy = object;
2193 scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_RESETTING);
2196 * The phy is being reset, therefore deactivate it from the port.
2197 * In the resetting state we don't notify the user regarding
2198 * link up and link down notifications. */
2199 scic_sds_port_deactivate_phy(sci_phy->owning_port, sci_phy, false);
2201 if (sci_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
2202 scu_link_layer_tx_hard_reset(sci_phy);
2203 } else {
2205 * The SCU does not need to have a discrete reset state so
2206 * just go back to the starting state.
2208 sci_base_state_machine_change_state(
2209 &sci_phy->state_machine,
2210 SCI_BASE_PHY_STATE_STARTING);
2216 * @object: This is the object which is cast to a struct scic_sds_phy object.
2218 * This method will perform the actions required by the struct scic_sds_phy on
2219 * entering the SCI_BASE_PHY_STATE_FINAL. - This function sets the state
2220 * handlers for the phy object base state machine final state. none
2222 static void scic_sds_phy_final_state_enter(void *object)
2224 struct scic_sds_phy *sci_phy = object;
2226 scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_FINAL);
2228 /* Nothing to do here */
2231 /* --------------------------------------------------------------------------- */
2233 static const struct sci_base_state scic_sds_phy_state_table[] = {
2234 [SCI_BASE_PHY_STATE_INITIAL] = {
2235 .enter_state = scic_sds_phy_initial_state_enter,
2237 [SCI_BASE_PHY_STATE_STOPPED] = {
2238 .enter_state = scic_sds_phy_stopped_state_enter,
2240 [SCI_BASE_PHY_STATE_STARTING] = {
2241 .enter_state = scic_sds_phy_starting_state_enter,
2243 [SCI_BASE_PHY_STATE_READY] = {
2244 .enter_state = scic_sds_phy_ready_state_enter,
2245 .exit_state = scic_sds_phy_ready_state_exit,
2247 [SCI_BASE_PHY_STATE_RESETTING] = {
2248 .enter_state = scic_sds_phy_resetting_state_enter,
2250 [SCI_BASE_PHY_STATE_FINAL] = {
2251 .enter_state = scic_sds_phy_final_state_enter,
2255 void scic_sds_phy_construct(struct scic_sds_phy *sci_phy,
2256 struct scic_sds_port *owning_port, u8 phy_index)
2258 sci_base_state_machine_construct(&sci_phy->state_machine,
2259 sci_phy,
2260 scic_sds_phy_state_table,
2261 SCI_BASE_PHY_STATE_INITIAL);
2263 sci_base_state_machine_start(&sci_phy->state_machine);
2265 /* Copy the rest of the input data to our locals */
2266 sci_phy->owning_port = owning_port;
2267 sci_phy->phy_index = phy_index;
2268 sci_phy->bcn_received_while_port_unassigned = false;
2269 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
2270 sci_phy->link_layer_registers = NULL;
2271 sci_phy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
2272 sci_phy->sata_timeout_timer = NULL;
2274 /* Initialize the the substate machines */
2275 sci_base_state_machine_construct(&sci_phy->starting_substate_machine,
2276 sci_phy,
2277 scic_sds_phy_starting_substates,
2278 SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL);