isci: merge smp request substates into primary state machine
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / scsi / isci / phy.c
blob0f64605200ffee987ae75c3eaa0952e14a660e36
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 "isci.h"
57 #include "host.h"
58 #include "phy.h"
59 #include "scu_event_codes.h"
60 #include "timers.h"
61 #include "probe_roms.h"
63 /* Maximum arbitration wait time in micro-seconds */
64 #define SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME (700)
66 enum sas_linkrate sci_phy_linkrate(struct scic_sds_phy *sci_phy)
68 return sci_phy->max_negotiated_speed;
72 * *****************************************************************************
73 * * SCIC SDS PHY Internal Methods
74 * ***************************************************************************** */
76 /**
77 * This method will initialize the phy transport layer registers
78 * @sci_phy:
79 * @transport_layer_registers
81 * enum sci_status
83 static enum sci_status scic_sds_phy_transport_layer_initialization(
84 struct scic_sds_phy *sci_phy,
85 struct scu_transport_layer_registers __iomem *transport_layer_registers)
87 u32 tl_control;
89 sci_phy->transport_layer_registers = transport_layer_registers;
91 writel(SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX,
92 &sci_phy->transport_layer_registers->stp_rni);
95 * Hardware team recommends that we enable the STP prefetch for all
96 * transports
98 tl_control = readl(&sci_phy->transport_layer_registers->control);
99 tl_control |= SCU_TLCR_GEN_BIT(STP_WRITE_DATA_PREFETCH);
100 writel(tl_control, &sci_phy->transport_layer_registers->control);
102 return SCI_SUCCESS;
106 * This method will initialize the phy link layer registers
107 * @sci_phy:
108 * @link_layer_registers:
110 * enum sci_status
112 static enum sci_status
113 scic_sds_phy_link_layer_initialization(struct scic_sds_phy *sci_phy,
114 struct scu_link_layer_registers __iomem *link_layer_registers)
116 struct scic_sds_controller *scic =
117 sci_phy->owning_port->owning_controller;
118 int phy_idx = sci_phy->phy_index;
119 struct sci_phy_user_params *phy_user =
120 &scic->user_parameters.sds1.phys[phy_idx];
121 struct sci_phy_oem_params *phy_oem =
122 &scic->oem_parameters.sds1.phys[phy_idx];
123 u32 phy_configuration;
124 struct scic_phy_cap phy_cap;
125 u32 parity_check = 0;
126 u32 parity_count = 0;
127 u32 llctl, link_rate;
128 u32 clksm_value = 0;
130 sci_phy->link_layer_registers = link_layer_registers;
132 /* Set our IDENTIFY frame data */
133 #define SCI_END_DEVICE 0x01
135 writel(SCU_SAS_TIID_GEN_BIT(SMP_INITIATOR) |
136 SCU_SAS_TIID_GEN_BIT(SSP_INITIATOR) |
137 SCU_SAS_TIID_GEN_BIT(STP_INITIATOR) |
138 SCU_SAS_TIID_GEN_BIT(DA_SATA_HOST) |
139 SCU_SAS_TIID_GEN_VAL(DEVICE_TYPE, SCI_END_DEVICE),
140 &sci_phy->link_layer_registers->transmit_identification);
142 /* Write the device SAS Address */
143 writel(0xFEDCBA98,
144 &sci_phy->link_layer_registers->sas_device_name_high);
145 writel(phy_idx, &sci_phy->link_layer_registers->sas_device_name_low);
147 /* Write the source SAS Address */
148 writel(phy_oem->sas_address.high,
149 &sci_phy->link_layer_registers->source_sas_address_high);
150 writel(phy_oem->sas_address.low,
151 &sci_phy->link_layer_registers->source_sas_address_low);
153 /* Clear and Set the PHY Identifier */
154 writel(0, &sci_phy->link_layer_registers->identify_frame_phy_id);
155 writel(SCU_SAS_TIPID_GEN_VALUE(ID, phy_idx),
156 &sci_phy->link_layer_registers->identify_frame_phy_id);
158 /* Change the initial state of the phy configuration register */
159 phy_configuration =
160 readl(&sci_phy->link_layer_registers->phy_configuration);
162 /* Hold OOB state machine in reset */
163 phy_configuration |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
164 writel(phy_configuration,
165 &sci_phy->link_layer_registers->phy_configuration);
167 /* Configure the SNW capabilities */
168 phy_cap.all = 0;
169 phy_cap.start = 1;
170 phy_cap.gen3_no_ssc = 1;
171 phy_cap.gen2_no_ssc = 1;
172 phy_cap.gen1_no_ssc = 1;
173 if (scic->oem_parameters.sds1.controller.do_enable_ssc == true) {
174 phy_cap.gen3_ssc = 1;
175 phy_cap.gen2_ssc = 1;
176 phy_cap.gen1_ssc = 1;
180 * The SAS specification indicates that the phy_capabilities that
181 * are transmitted shall have an even parity. Calculate the parity. */
182 parity_check = phy_cap.all;
183 while (parity_check != 0) {
184 if (parity_check & 0x1)
185 parity_count++;
186 parity_check >>= 1;
190 * If parity indicates there are an odd number of bits set, then
191 * set the parity bit to 1 in the phy capabilities. */
192 if ((parity_count % 2) != 0)
193 phy_cap.parity = 1;
195 writel(phy_cap.all, &sci_phy->link_layer_registers->phy_capabilities);
197 /* Set the enable spinup period but disable the ability to send
198 * notify enable spinup
200 writel(SCU_ENSPINUP_GEN_VAL(COUNT,
201 phy_user->notify_enable_spin_up_insertion_frequency),
202 &sci_phy->link_layer_registers->notify_enable_spinup_control);
204 /* Write the ALIGN Insertion Ferequency for connected phy and
205 * inpendent of connected state
207 clksm_value = SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(CONNECTED,
208 phy_user->in_connection_align_insertion_frequency);
210 clksm_value |= SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(GENERAL,
211 phy_user->align_insertion_frequency);
213 writel(clksm_value, &sci_phy->link_layer_registers->clock_skew_management);
215 /* @todo Provide a way to write this register correctly */
216 writel(0x02108421,
217 &sci_phy->link_layer_registers->afe_lookup_table_control);
219 llctl = SCU_SAS_LLCTL_GEN_VAL(NO_OUTBOUND_TASK_TIMEOUT,
220 (u8)scic->user_parameters.sds1.no_outbound_task_timeout);
222 switch(phy_user->max_speed_generation) {
223 case SCIC_SDS_PARM_GEN3_SPEED:
224 link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN3;
225 break;
226 case SCIC_SDS_PARM_GEN2_SPEED:
227 link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN2;
228 break;
229 default:
230 link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN1;
231 break;
233 llctl |= SCU_SAS_LLCTL_GEN_VAL(MAX_LINK_RATE, link_rate);
234 writel(llctl, &sci_phy->link_layer_registers->link_layer_control);
236 if (is_a0() || is_a2()) {
237 /* Program the max ARB time for the PHY to 700us so we inter-operate with
238 * the PMC expander which shuts down PHYs if the expander PHY generates too
239 * many breaks. This time value will guarantee that the initiator PHY will
240 * generate the break.
242 writel(SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME,
243 &sci_phy->link_layer_registers->maximum_arbitration_wait_timer_timeout);
247 * Set the link layer hang detection to 500ms (0x1F4) from its default
248 * value of 128ms. Max value is 511 ms.
250 writel(0x1F4, &sci_phy->link_layer_registers->link_layer_hang_detection_timeout);
252 /* We can exit the initial state to the stopped state */
253 sci_base_state_machine_change_state(&sci_phy->state_machine,
254 SCI_BASE_PHY_STATE_STOPPED);
256 return SCI_SUCCESS;
260 * This function will handle the sata SIGNATURE FIS timeout condition. It will
261 * restart the starting substate machine since we dont know what has actually
262 * happening.
264 static void scic_sds_phy_sata_timeout(void *phy)
266 struct scic_sds_phy *sci_phy = phy;
268 dev_dbg(sciphy_to_dev(sci_phy),
269 "%s: SCIC SDS Phy 0x%p did not receive signature fis before "
270 "timeout.\n",
271 __func__,
272 sci_phy);
274 sci_base_state_machine_stop(&sci_phy->starting_substate_machine);
276 sci_base_state_machine_change_state(&sci_phy->state_machine,
277 SCI_BASE_PHY_STATE_STARTING);
281 * This method returns the port currently containing this phy. If the phy is
282 * currently contained by the dummy port, then the phy is considered to not
283 * be part of a port.
284 * @sci_phy: This parameter specifies the phy for which to retrieve the
285 * containing port.
287 * This method returns a handle to a port that contains the supplied phy.
288 * NULL This value is returned if the phy is not part of a real
289 * port (i.e. it's contained in the dummy port). !NULL All other
290 * values indicate a handle/pointer to the port containing the phy.
292 struct scic_sds_port *scic_sds_phy_get_port(
293 struct scic_sds_phy *sci_phy)
295 if (scic_sds_port_get_index(sci_phy->owning_port) == SCIC_SDS_DUMMY_PORT)
296 return NULL;
298 return sci_phy->owning_port;
302 * This method will assign a port to the phy object.
303 * @out]: sci_phy This parameter specifies the phy for which to assign a port
304 * object.
308 void scic_sds_phy_set_port(
309 struct scic_sds_phy *sci_phy,
310 struct scic_sds_port *sci_port)
312 sci_phy->owning_port = sci_port;
314 if (sci_phy->bcn_received_while_port_unassigned) {
315 sci_phy->bcn_received_while_port_unassigned = false;
316 scic_sds_port_broadcast_change_received(sci_phy->owning_port, sci_phy);
321 * This method will initialize the constructed phy
322 * @sci_phy:
323 * @link_layer_registers:
325 * enum sci_status
327 enum sci_status scic_sds_phy_initialize(
328 struct scic_sds_phy *sci_phy,
329 struct scu_transport_layer_registers __iomem *transport_layer_registers,
330 struct scu_link_layer_registers __iomem *link_layer_registers)
332 struct scic_sds_controller *scic = scic_sds_phy_get_controller(sci_phy);
333 struct isci_host *ihost = scic_to_ihost(scic);
335 /* Create the SIGNATURE FIS Timeout timer for this phy */
336 sci_phy->sata_timeout_timer =
337 isci_timer_create(
338 ihost,
339 sci_phy,
340 scic_sds_phy_sata_timeout);
342 /* Perfrom the initialization of the TL hardware */
343 scic_sds_phy_transport_layer_initialization(
344 sci_phy,
345 transport_layer_registers);
347 /* Perofrm the initialization of the PE hardware */
348 scic_sds_phy_link_layer_initialization(sci_phy, link_layer_registers);
351 * There is nothing that needs to be done in this state just
352 * transition to the stopped state. */
353 sci_base_state_machine_change_state(&sci_phy->state_machine,
354 SCI_BASE_PHY_STATE_STOPPED);
356 return SCI_SUCCESS;
360 * This method assigns the direct attached device ID for this phy.
362 * @sci_phy The phy for which the direct attached device id is to
363 * be assigned.
364 * @device_id The direct attached device ID to assign to the phy.
365 * This will either be the RNi for the device or an invalid RNi if there
366 * is no current device assigned to the phy.
368 void scic_sds_phy_setup_transport(
369 struct scic_sds_phy *sci_phy,
370 u32 device_id)
372 u32 tl_control;
374 writel(device_id, &sci_phy->transport_layer_registers->stp_rni);
377 * The read should guarantee that the first write gets posted
378 * before the next write
380 tl_control = readl(&sci_phy->transport_layer_registers->control);
381 tl_control |= SCU_TLCR_GEN_BIT(CLEAR_TCI_NCQ_MAPPING_TABLE);
382 writel(tl_control, &sci_phy->transport_layer_registers->control);
387 * @sci_phy: The phy object to be suspended.
389 * This function will perform the register reads/writes to suspend the SCU
390 * hardware protocol engine. none
392 static void scic_sds_phy_suspend(
393 struct scic_sds_phy *sci_phy)
395 u32 scu_sas_pcfg_value;
397 scu_sas_pcfg_value =
398 readl(&sci_phy->link_layer_registers->phy_configuration);
399 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE);
400 writel(scu_sas_pcfg_value,
401 &sci_phy->link_layer_registers->phy_configuration);
403 scic_sds_phy_setup_transport(
404 sci_phy,
405 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX);
408 void scic_sds_phy_resume(struct scic_sds_phy *sci_phy)
410 u32 scu_sas_pcfg_value;
412 scu_sas_pcfg_value =
413 readl(&sci_phy->link_layer_registers->phy_configuration);
414 scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE);
415 writel(scu_sas_pcfg_value,
416 &sci_phy->link_layer_registers->phy_configuration);
419 void scic_sds_phy_get_sas_address(struct scic_sds_phy *sci_phy,
420 struct sci_sas_address *sas_address)
422 sas_address->high = readl(&sci_phy->link_layer_registers->source_sas_address_high);
423 sas_address->low = readl(&sci_phy->link_layer_registers->source_sas_address_low);
426 void scic_sds_phy_get_attached_sas_address(struct scic_sds_phy *sci_phy,
427 struct sci_sas_address *sas_address)
429 struct sas_identify_frame *iaf;
430 struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
432 iaf = &iphy->frame_rcvd.iaf;
433 memcpy(sas_address, iaf->sas_addr, SAS_ADDR_SIZE);
436 void scic_sds_phy_get_protocols(struct scic_sds_phy *sci_phy,
437 struct scic_phy_proto *protocols)
439 protocols->all =
440 (u16)(readl(&sci_phy->
441 link_layer_registers->transmit_identification) &
442 0x0000FFFF);
446 * This method will attempt to start the phy object. This request is only valid
447 * when the phy is in the stopped state
448 * @sci_phy:
450 * enum sci_status
452 enum sci_status scic_sds_phy_start(struct scic_sds_phy *sci_phy)
454 return sci_phy->state_handlers->start_handler(sci_phy);
458 * This method will attempt to stop the phy object.
459 * @sci_phy:
461 * enum sci_status SCI_SUCCESS if the phy is going to stop SCI_INVALID_STATE
462 * if the phy is not in a valid state to stop
464 enum sci_status scic_sds_phy_stop(struct scic_sds_phy *sci_phy)
466 return sci_phy->state_handlers->stop_handler(sci_phy);
470 * This method will attempt to reset the phy. This request is only valid when
471 * the phy is in an ready state
472 * @sci_phy:
474 * enum sci_status
476 enum sci_status scic_sds_phy_reset(
477 struct scic_sds_phy *sci_phy)
479 return sci_phy->state_handlers->reset_handler(sci_phy);
483 * This method will process the event code received.
484 * @sci_phy:
485 * @event_code:
487 * enum sci_status
489 enum sci_status scic_sds_phy_event_handler(
490 struct scic_sds_phy *sci_phy,
491 u32 event_code)
493 return sci_phy->state_handlers->event_handler(sci_phy, event_code);
497 * This method will process the frame index received.
498 * @sci_phy:
499 * @frame_index:
501 * enum sci_status
503 enum sci_status scic_sds_phy_frame_handler(
504 struct scic_sds_phy *sci_phy,
505 u32 frame_index)
507 return sci_phy->state_handlers->frame_handler(sci_phy, frame_index);
511 * This method will give the phy permission to consume power
512 * @sci_phy:
514 * enum sci_status
516 enum sci_status scic_sds_phy_consume_power_handler(
517 struct scic_sds_phy *sci_phy)
519 return sci_phy->state_handlers->consume_power_handler(sci_phy);
523 * *****************************************************************************
524 * * SCIC SDS PHY HELPER FUNCTIONS
525 * ***************************************************************************** */
530 * @sci_phy: The phy object that received SAS PHY DETECTED.
532 * This method continues the link training for the phy as if it were a SAS PHY
533 * instead of a SATA PHY. This is done because the completion queue had a SAS
534 * PHY DETECTED event when the state machine was expecting a SATA PHY event.
535 * none
537 static void scic_sds_phy_start_sas_link_training(
538 struct scic_sds_phy *sci_phy)
540 u32 phy_control;
542 phy_control =
543 readl(&sci_phy->link_layer_registers->phy_configuration);
544 phy_control |= SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD);
545 writel(phy_control,
546 &sci_phy->link_layer_registers->phy_configuration);
548 sci_base_state_machine_change_state(
549 &sci_phy->starting_substate_machine,
550 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
553 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SAS;
558 * @sci_phy: The phy object that received a SATA SPINUP HOLD event
560 * This method continues the link training for the phy as if it were a SATA PHY
561 * instead of a SAS PHY. This is done because the completion queue had a SATA
562 * SPINUP HOLD event when the state machine was expecting a SAS PHY event. none
564 static void scic_sds_phy_start_sata_link_training(
565 struct scic_sds_phy *sci_phy)
567 sci_base_state_machine_change_state(
568 &sci_phy->starting_substate_machine,
569 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
572 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
576 * scic_sds_phy_complete_link_training - perform processing common to
577 * all protocols upon completion of link training.
578 * @sci_phy: This parameter specifies the phy object for which link training
579 * has completed.
580 * @max_link_rate: This parameter specifies the maximum link rate to be
581 * associated with this phy.
582 * @next_state: This parameter specifies the next state for the phy's starting
583 * sub-state machine.
586 static void scic_sds_phy_complete_link_training(
587 struct scic_sds_phy *sci_phy,
588 enum sas_linkrate max_link_rate,
589 u32 next_state)
591 sci_phy->max_negotiated_speed = max_link_rate;
593 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
594 next_state);
597 static void scic_sds_phy_restart_starting_state(
598 struct scic_sds_phy *sci_phy)
600 /* Stop the current substate machine */
601 sci_base_state_machine_stop(&sci_phy->starting_substate_machine);
603 /* Re-enter the base state machine starting state */
604 sci_base_state_machine_change_state(&sci_phy->state_machine,
605 SCI_BASE_PHY_STATE_STARTING);
608 /* ****************************************************************************
609 * SCIC SDS PHY general handlers
610 ************************************************************************** */
611 static enum sci_status scic_sds_phy_starting_substate_general_stop_handler(
612 struct scic_sds_phy *phy)
614 sci_base_state_machine_stop(&phy->starting_substate_machine);
616 sci_base_state_machine_change_state(&phy->state_machine,
617 SCI_BASE_PHY_STATE_STOPPED);
619 return SCI_SUCCESS;
623 * *****************************************************************************
624 * * SCIC SDS PHY EVENT_HANDLERS
625 * ***************************************************************************** */
629 * @phy: This struct scic_sds_phy object which has received an event.
630 * @event_code: This is the event code which the phy object is to decode.
632 * This method is called when an event notification is received for the phy
633 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. -
634 * decode the event - sas phy detected causes a state transition to the wait
635 * for speed event notification. - any other events log a warning message and
636 * set a failure status enum sci_status SCI_SUCCESS on any valid event notification
637 * SCI_FAILURE on any unexpected event notifation
639 static enum sci_status scic_sds_phy_starting_substate_await_ossp_event_handler(
640 struct scic_sds_phy *sci_phy,
641 u32 event_code)
643 u32 result = SCI_SUCCESS;
645 switch (scu_get_event_code(event_code)) {
646 case SCU_EVENT_SAS_PHY_DETECTED:
647 scic_sds_phy_start_sas_link_training(sci_phy);
648 sci_phy->is_in_link_training = true;
649 break;
651 case SCU_EVENT_SATA_SPINUP_HOLD:
652 scic_sds_phy_start_sata_link_training(sci_phy);
653 sci_phy->is_in_link_training = true;
654 break;
656 default:
657 dev_dbg(sciphy_to_dev(sci_phy),
658 "%s: PHY starting substate machine received "
659 "unexpected event_code %x\n",
660 __func__,
661 event_code);
663 result = SCI_FAILURE;
664 break;
667 return result;
672 * @phy: This struct scic_sds_phy object which has received an event.
673 * @event_code: This is the event code which the phy object is to decode.
675 * This method is called when an event notification is received for the phy
676 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. -
677 * decode the event - sas phy detected returns us back to this state. - speed
678 * event detected causes a state transition to the wait for iaf. - identify
679 * timeout is an un-expected event and the state machine is restarted. - link
680 * failure events restart the starting state machine - any other events log a
681 * warning message and set a failure status enum sci_status SCI_SUCCESS on any valid
682 * event notification SCI_FAILURE on any unexpected event notifation
684 static enum sci_status scic_sds_phy_starting_substate_await_sas_phy_speed_event_handler(
685 struct scic_sds_phy *sci_phy,
686 u32 event_code)
688 u32 result = SCI_SUCCESS;
690 switch (scu_get_event_code(event_code)) {
691 case SCU_EVENT_SAS_PHY_DETECTED:
693 * Why is this being reported again by the controller?
694 * We would re-enter this state so just stay here */
695 break;
697 case SCU_EVENT_SAS_15:
698 case SCU_EVENT_SAS_15_SSC:
699 scic_sds_phy_complete_link_training(
700 sci_phy,
701 SAS_LINK_RATE_1_5_GBPS,
702 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF);
703 break;
705 case SCU_EVENT_SAS_30:
706 case SCU_EVENT_SAS_30_SSC:
707 scic_sds_phy_complete_link_training(
708 sci_phy,
709 SAS_LINK_RATE_3_0_GBPS,
710 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF);
711 break;
713 case SCU_EVENT_SAS_60:
714 case SCU_EVENT_SAS_60_SSC:
715 scic_sds_phy_complete_link_training(
716 sci_phy,
717 SAS_LINK_RATE_6_0_GBPS,
718 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF);
719 break;
721 case SCU_EVENT_SATA_SPINUP_HOLD:
723 * We were doing SAS PHY link training and received a SATA PHY event
724 * continue OOB/SN as if this were a SATA PHY */
725 scic_sds_phy_start_sata_link_training(sci_phy);
726 break;
728 case SCU_EVENT_LINK_FAILURE:
729 /* Link failure change state back to the starting state */
730 scic_sds_phy_restart_starting_state(sci_phy);
731 break;
733 default:
734 dev_warn(sciphy_to_dev(sci_phy),
735 "%s: PHY starting substate machine received "
736 "unexpected event_code %x\n",
737 __func__,
738 event_code);
740 result = SCI_FAILURE;
741 break;
744 return result;
749 * @phy: This struct scic_sds_phy object which has received an event.
750 * @event_code: This is the event code which the phy object is to decode.
752 * This method is called when an event notification is received for the phy
753 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. -
754 * decode the event - sas phy detected event backs up the state machine to the
755 * await speed notification. - identify timeout is an un-expected event and the
756 * state machine is restarted. - link failure events restart the starting state
757 * machine - any other events log a warning message and set a failure status
758 * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any
759 * unexpected event notifation
761 static enum sci_status scic_sds_phy_starting_substate_await_iaf_uf_event_handler(
762 struct scic_sds_phy *sci_phy,
763 u32 event_code)
765 u32 result = SCI_SUCCESS;
767 switch (scu_get_event_code(event_code)) {
768 case SCU_EVENT_SAS_PHY_DETECTED:
769 /* Backup the state machine */
770 scic_sds_phy_start_sas_link_training(sci_phy);
771 break;
773 case SCU_EVENT_SATA_SPINUP_HOLD:
775 * We were doing SAS PHY link training and received a SATA PHY event
776 * continue OOB/SN as if this were a SATA PHY */
777 scic_sds_phy_start_sata_link_training(sci_phy);
778 break;
780 case SCU_EVENT_RECEIVED_IDENTIFY_TIMEOUT:
781 case SCU_EVENT_LINK_FAILURE:
782 case SCU_EVENT_HARD_RESET_RECEIVED:
783 /* Start the oob/sn state machine over again */
784 scic_sds_phy_restart_starting_state(sci_phy);
785 break;
787 default:
788 dev_warn(sciphy_to_dev(sci_phy),
789 "%s: PHY starting substate machine received "
790 "unexpected event_code %x\n",
791 __func__,
792 event_code);
794 result = SCI_FAILURE;
795 break;
798 return result;
803 * @phy: This struct scic_sds_phy object which has received an event.
804 * @event_code: This is the event code which the phy object is to decode.
806 * This method is called when an event notification is received for the phy
807 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_POWER. -
808 * decode the event - link failure events restart the starting state machine -
809 * any other events log a warning message and set a failure status enum sci_status
810 * SCI_SUCCESS on a link failure event SCI_FAILURE on any unexpected event
811 * notifation
813 static enum sci_status scic_sds_phy_starting_substate_await_sas_power_event_handler(
814 struct scic_sds_phy *sci_phy,
815 u32 event_code)
817 u32 result = SCI_SUCCESS;
819 switch (scu_get_event_code(event_code)) {
820 case SCU_EVENT_LINK_FAILURE:
821 /* Link failure change state back to the starting state */
822 scic_sds_phy_restart_starting_state(sci_phy);
823 break;
825 default:
826 dev_warn(sciphy_to_dev(sci_phy),
827 "%s: PHY starting substate machine received unexpected "
828 "event_code %x\n",
829 __func__,
830 event_code);
832 result = SCI_FAILURE;
833 break;
836 return result;
841 * @phy: This struct scic_sds_phy object which has received an event.
842 * @event_code: This is the event code which the phy object is to decode.
844 * This method is called when an event notification is received for the phy
845 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. -
846 * decode the event - link failure events restart the starting state machine -
847 * sata spinup hold events are ignored since they are expected - any other
848 * events log a warning message and set a failure status enum sci_status SCI_SUCCESS
849 * on a link failure event SCI_FAILURE on any unexpected event notifation
851 static enum sci_status scic_sds_phy_starting_substate_await_sata_power_event_handler(
852 struct scic_sds_phy *sci_phy,
853 u32 event_code)
855 u32 result = SCI_SUCCESS;
857 switch (scu_get_event_code(event_code)) {
858 case SCU_EVENT_LINK_FAILURE:
859 /* Link failure change state back to the starting state */
860 scic_sds_phy_restart_starting_state(sci_phy);
861 break;
863 case SCU_EVENT_SATA_SPINUP_HOLD:
864 /* These events are received every 10ms and are expected while in this state */
865 break;
867 case SCU_EVENT_SAS_PHY_DETECTED:
869 * There has been a change in the phy type before OOB/SN for the
870 * SATA finished start down the SAS link traning path. */
871 scic_sds_phy_start_sas_link_training(sci_phy);
872 break;
874 default:
875 dev_warn(sciphy_to_dev(sci_phy),
876 "%s: PHY starting substate machine received "
877 "unexpected event_code %x\n",
878 __func__,
879 event_code);
881 result = SCI_FAILURE;
882 break;
885 return result;
889 * scic_sds_phy_starting_substate_await_sata_phy_event_handler -
890 * @phy: This struct scic_sds_phy object which has received an event.
891 * @event_code: This is the event code which the phy object is to decode.
893 * This method is called when an event notification is received for the phy
894 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. -
895 * decode the event - link failure events restart the starting state machine -
896 * sata spinup hold events are ignored since they are expected - sata phy
897 * detected event change to the wait speed event - any other events log a
898 * warning message and set a failure status enum sci_status SCI_SUCCESS on a link
899 * failure event SCI_FAILURE on any unexpected event notifation
901 static enum sci_status scic_sds_phy_starting_substate_await_sata_phy_event_handler(
902 struct scic_sds_phy *sci_phy, u32 event_code)
904 u32 result = SCI_SUCCESS;
906 switch (scu_get_event_code(event_code)) {
907 case SCU_EVENT_LINK_FAILURE:
908 /* Link failure change state back to the starting state */
909 scic_sds_phy_restart_starting_state(sci_phy);
910 break;
912 case SCU_EVENT_SATA_SPINUP_HOLD:
913 /* These events might be received since we dont know how many may be in
914 * the completion queue while waiting for power
916 break;
918 case SCU_EVENT_SATA_PHY_DETECTED:
919 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
921 /* We have received the SATA PHY notification change state */
922 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
923 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN);
924 break;
926 case SCU_EVENT_SAS_PHY_DETECTED:
927 /* There has been a change in the phy type before OOB/SN for the
928 * SATA finished start down the SAS link traning path.
930 scic_sds_phy_start_sas_link_training(sci_phy);
931 break;
933 default:
934 dev_warn(sciphy_to_dev(sci_phy),
935 "%s: PHY starting substate machine received "
936 "unexpected event_code %x\n",
937 __func__,
938 event_code);
940 result = SCI_FAILURE;
941 break;
944 return result;
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_SPEED_EN.
954 * - decode the event - sata phy detected returns us back to this state. -
955 * speed event detected causes a state transition to the wait for signature. -
956 * link failure events restart the starting state machine - any other events
957 * log a warning message and set a failure status enum sci_status SCI_SUCCESS on any
958 * valid event notification SCI_FAILURE on any unexpected event notifation
960 static enum sci_status scic_sds_phy_starting_substate_await_sata_speed_event_handler(
961 struct scic_sds_phy *sci_phy,
962 u32 event_code)
964 u32 result = SCI_SUCCESS;
966 switch (scu_get_event_code(event_code)) {
967 case SCU_EVENT_SATA_PHY_DETECTED:
969 * The hardware reports multiple SATA PHY detected events
970 * ignore the extras */
971 break;
973 case SCU_EVENT_SATA_15:
974 case SCU_EVENT_SATA_15_SSC:
975 scic_sds_phy_complete_link_training(
976 sci_phy,
977 SAS_LINK_RATE_1_5_GBPS,
978 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
979 break;
981 case SCU_EVENT_SATA_30:
982 case SCU_EVENT_SATA_30_SSC:
983 scic_sds_phy_complete_link_training(
984 sci_phy,
985 SAS_LINK_RATE_3_0_GBPS,
986 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
987 break;
989 case SCU_EVENT_SATA_60:
990 case SCU_EVENT_SATA_60_SSC:
991 scic_sds_phy_complete_link_training(
992 sci_phy,
993 SAS_LINK_RATE_6_0_GBPS,
994 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
995 break;
997 case SCU_EVENT_LINK_FAILURE:
998 /* Link failure change state back to the starting state */
999 scic_sds_phy_restart_starting_state(sci_phy);
1000 break;
1002 case SCU_EVENT_SAS_PHY_DETECTED:
1004 * There has been a change in the phy type before OOB/SN for the
1005 * SATA finished start down the SAS link traning path. */
1006 scic_sds_phy_start_sas_link_training(sci_phy);
1007 break;
1009 default:
1010 dev_warn(sciphy_to_dev(sci_phy),
1011 "%s: PHY starting substate machine received "
1012 "unexpected event_code %x\n",
1013 __func__,
1014 event_code);
1016 result = SCI_FAILURE;
1017 break;
1020 return result;
1024 * scic_sds_phy_starting_substate_await_sig_fis_event_handler -
1025 * @phy: This struct scic_sds_phy object which has received an event.
1026 * @event_code: This is the event code which the phy object is to decode.
1028 * This method is called when an event notification is received for the phy
1029 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. -
1030 * decode the event - sas phy detected event backs up the state machine to the
1031 * await speed notification. - identify timeout is an un-expected event and the
1032 * state machine is restarted. - link failure events restart the starting state
1033 * machine - any other events log a warning message and set a failure status
1034 * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any
1035 * unexpected event notifation
1037 static enum sci_status scic_sds_phy_starting_substate_await_sig_fis_event_handler(
1038 struct scic_sds_phy *sci_phy, u32 event_code)
1040 u32 result = SCI_SUCCESS;
1042 switch (scu_get_event_code(event_code)) {
1043 case SCU_EVENT_SATA_PHY_DETECTED:
1044 /* Backup the state machine */
1045 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
1046 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN);
1047 break;
1049 case SCU_EVENT_LINK_FAILURE:
1050 /* Link failure change state back to the starting state */
1051 scic_sds_phy_restart_starting_state(sci_phy);
1052 break;
1054 default:
1055 dev_warn(sciphy_to_dev(sci_phy),
1056 "%s: PHY starting substate machine received "
1057 "unexpected event_code %x\n",
1058 __func__,
1059 event_code);
1061 result = SCI_FAILURE;
1062 break;
1065 return result;
1070 * *****************************************************************************
1071 * * SCIC SDS PHY FRAME_HANDLERS
1072 * ***************************************************************************** */
1076 * @phy: This is struct scic_sds_phy object which is being requested to decode the
1077 * frame data.
1078 * @frame_index: This is the index of the unsolicited frame which was received
1079 * for this phy.
1081 * This method decodes the unsolicited frame when the struct scic_sds_phy is in the
1082 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - Get the UF Header - If the UF
1083 * is an IAF - Copy IAF data to local phy object IAF data buffer. - Change
1084 * starting substate to wait power. - else - log warning message of unexpected
1085 * unsolicted frame - release frame buffer enum sci_status SCI_SUCCESS
1087 static enum sci_status scic_sds_phy_starting_substate_await_iaf_uf_frame_handler(
1088 struct scic_sds_phy *sci_phy, u32 frame_index)
1090 enum sci_status result;
1091 u32 *frame_words;
1092 struct sas_identify_frame iaf;
1093 struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
1095 result = scic_sds_unsolicited_frame_control_get_header(
1096 &(scic_sds_phy_get_controller(sci_phy)->uf_control),
1097 frame_index,
1098 (void **)&frame_words);
1100 if (result != SCI_SUCCESS)
1101 return result;
1103 sci_swab32_cpy(&iaf, frame_words, sizeof(iaf) / sizeof(u32));
1104 if (iaf.frame_type == 0) {
1105 u32 state;
1107 memcpy(&iphy->frame_rcvd.iaf, &iaf, sizeof(iaf));
1108 if (iaf.smp_tport) {
1109 /* We got the IAF for an expander PHY go to the final
1110 * state since there are no power requirements for
1111 * expander phys.
1113 state = SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL;
1114 } else {
1115 /* We got the IAF we can now go to the await spinup
1116 * semaphore state
1118 state = SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER;
1120 sci_base_state_machine_change_state(
1121 &sci_phy->starting_substate_machine,
1122 state);
1123 result = SCI_SUCCESS;
1124 } else
1125 dev_warn(sciphy_to_dev(sci_phy),
1126 "%s: PHY starting substate machine received "
1127 "unexpected frame id %x\n",
1128 __func__,
1129 frame_index);
1131 scic_sds_controller_release_frame(scic_sds_phy_get_controller(sci_phy),
1132 frame_index);
1134 return result;
1139 * @phy: This is struct scic_sds_phy object which is being requested to decode the
1140 * frame data.
1141 * @frame_index: This is the index of the unsolicited frame which was received
1142 * for this phy.
1144 * This method decodes the unsolicited frame when the struct scic_sds_phy is in the
1145 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Get the UF Header - If
1146 * the UF is an SIGNATURE FIS - Copy IAF data to local phy object SIGNATURE FIS
1147 * data buffer. - else - log warning message of unexpected unsolicted frame -
1148 * release frame buffer enum sci_status SCI_SUCCESS Must decode the SIGNATURE FIS
1149 * data
1151 static enum sci_status scic_sds_phy_starting_substate_await_sig_fis_frame_handler(
1152 struct scic_sds_phy *sci_phy,
1153 u32 frame_index)
1155 enum sci_status result;
1156 struct dev_to_host_fis *frame_header;
1157 u32 *fis_frame_data;
1158 struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
1160 result = scic_sds_unsolicited_frame_control_get_header(
1161 &(scic_sds_phy_get_controller(sci_phy)->uf_control),
1162 frame_index,
1163 (void **)&frame_header);
1165 if (result != SCI_SUCCESS)
1166 return result;
1168 if ((frame_header->fis_type == FIS_REGD2H) &&
1169 !(frame_header->status & ATA_BUSY)) {
1170 scic_sds_unsolicited_frame_control_get_buffer(
1171 &(scic_sds_phy_get_controller(sci_phy)->uf_control),
1172 frame_index,
1173 (void **)&fis_frame_data);
1175 scic_sds_controller_copy_sata_response(&iphy->frame_rcvd.fis,
1176 frame_header,
1177 fis_frame_data);
1179 /* got IAF we can now go to the await spinup semaphore state */
1180 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
1181 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL);
1183 result = SCI_SUCCESS;
1184 } else
1185 dev_warn(sciphy_to_dev(sci_phy),
1186 "%s: PHY starting substate machine received "
1187 "unexpected frame id %x\n",
1188 __func__,
1189 frame_index);
1191 /* Regardless of the result we are done with this frame with it */
1192 scic_sds_controller_release_frame(scic_sds_phy_get_controller(sci_phy),
1193 frame_index);
1195 return result;
1199 * *****************************************************************************
1200 * * SCIC SDS PHY POWER_HANDLERS
1201 * ***************************************************************************** */
1204 * This method is called by the struct scic_sds_controller when the phy object is
1205 * granted power. - The notify enable spinups are turned on for this phy object
1206 * - The phy state machine is transitioned to the
1207 * SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. enum sci_status SCI_SUCCESS
1209 static enum sci_status scic_sds_phy_starting_substate_await_sas_power_consume_power_handler(
1210 struct scic_sds_phy *sci_phy)
1212 u32 enable_spinup;
1214 enable_spinup = readl(&sci_phy->link_layer_registers->notify_enable_spinup_control);
1215 enable_spinup |= SCU_ENSPINUP_GEN_BIT(ENABLE);
1216 writel(enable_spinup, &sci_phy->link_layer_registers->notify_enable_spinup_control);
1218 /* Change state to the final state this substate machine has run to completion */
1219 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
1220 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL);
1222 return SCI_SUCCESS;
1226 * This method is called by the struct scic_sds_controller when the phy object is
1227 * granted power. - The phy state machine is transitioned to the
1228 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. enum sci_status SCI_SUCCESS
1230 static enum sci_status scic_sds_phy_starting_substate_await_sata_power_consume_power_handler(
1231 struct scic_sds_phy *sci_phy)
1233 u32 scu_sas_pcfg_value;
1235 /* Release the spinup hold state and reset the OOB state machine */
1236 scu_sas_pcfg_value =
1237 readl(&sci_phy->link_layer_registers->phy_configuration);
1238 scu_sas_pcfg_value &=
1239 ~(SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD) | SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE));
1240 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
1241 writel(scu_sas_pcfg_value,
1242 &sci_phy->link_layer_registers->phy_configuration);
1244 /* Now restart the OOB operation */
1245 scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
1246 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
1247 writel(scu_sas_pcfg_value,
1248 &sci_phy->link_layer_registers->phy_configuration);
1250 /* Change state to the final state this substate machine has run to completion */
1251 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
1252 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN);
1254 return SCI_SUCCESS;
1257 static enum sci_status default_phy_handler(struct scic_sds_phy *sci_phy,
1258 const char *func)
1260 dev_dbg(sciphy_to_dev(sci_phy),
1261 "%s: in wrong state: %d\n", func,
1262 sci_base_state_machine_get_state(&sci_phy->state_machine));
1263 return SCI_FAILURE_INVALID_STATE;
1266 static enum sci_status
1267 scic_sds_phy_default_start_handler(struct scic_sds_phy *sci_phy)
1269 return default_phy_handler(sci_phy, __func__);
1272 static enum sci_status
1273 scic_sds_phy_default_stop_handler(struct scic_sds_phy *sci_phy)
1275 return default_phy_handler(sci_phy, __func__);
1278 static enum sci_status
1279 scic_sds_phy_default_reset_handler(struct scic_sds_phy *sci_phy)
1281 return default_phy_handler(sci_phy, __func__);
1284 static enum sci_status
1285 scic_sds_phy_default_destroy_handler(struct scic_sds_phy *sci_phy)
1287 return default_phy_handler(sci_phy, __func__);
1290 static enum sci_status
1291 scic_sds_phy_default_frame_handler(struct scic_sds_phy *sci_phy,
1292 u32 frame_index)
1294 struct scic_sds_controller *scic = scic_sds_phy_get_controller(sci_phy);
1296 default_phy_handler(sci_phy, __func__);
1297 scic_sds_controller_release_frame(scic, frame_index);
1299 return SCI_FAILURE_INVALID_STATE;
1302 static enum sci_status
1303 scic_sds_phy_default_event_handler(struct scic_sds_phy *sci_phy,
1304 u32 event_code)
1306 return default_phy_handler(sci_phy, __func__);
1309 static enum sci_status
1310 scic_sds_phy_default_consume_power_handler(struct scic_sds_phy *sci_phy)
1312 return default_phy_handler(sci_phy, __func__);
1317 static const struct scic_sds_phy_state_handler scic_sds_phy_starting_substate_handler_table[] = {
1318 [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL] = {
1319 .start_handler = scic_sds_phy_default_start_handler,
1320 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1321 .reset_handler = scic_sds_phy_default_reset_handler,
1322 .destruct_handler = scic_sds_phy_default_destroy_handler,
1323 .frame_handler = scic_sds_phy_default_frame_handler,
1324 .event_handler = scic_sds_phy_default_event_handler,
1325 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1327 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN] = {
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_starting_substate_await_ossp_event_handler,
1334 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1336 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_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_sas_phy_speed_event_handler,
1343 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1345 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF] = {
1346 .start_handler = scic_sds_phy_default_start_handler,
1347 .stop_handler = scic_sds_phy_default_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_starting_substate_await_iaf_uf_frame_handler,
1351 .event_handler = scic_sds_phy_starting_substate_await_iaf_uf_event_handler,
1352 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1354 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER] = {
1355 .start_handler = scic_sds_phy_default_start_handler,
1356 .stop_handler = scic_sds_phy_starting_substate_general_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_default_frame_handler,
1360 .event_handler = scic_sds_phy_starting_substate_await_sas_power_event_handler,
1361 .consume_power_handler = scic_sds_phy_starting_substate_await_sas_power_consume_power_handler
1363 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_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_sata_power_event_handler,
1370 .consume_power_handler = scic_sds_phy_starting_substate_await_sata_power_consume_power_handler
1372 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN] = {
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_phy_event_handler,
1379 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1381 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_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_speed_event_handler,
1388 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1390 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF] = {
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_starting_substate_await_sig_fis_frame_handler,
1396 .event_handler = scic_sds_phy_starting_substate_await_sig_fis_event_handler,
1397 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1399 [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL] = {
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_default_frame_handler,
1405 .event_handler = scic_sds_phy_default_event_handler,
1406 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1411 * scic_sds_phy_set_starting_substate_handlers() -
1413 * This macro sets the starting substate handlers by state_id
1415 #define scic_sds_phy_set_starting_substate_handlers(phy, state_id) \
1416 scic_sds_phy_set_state_handlers(\
1417 (phy), \
1418 &scic_sds_phy_starting_substate_handler_table[(state_id)] \
1422 * ****************************************************************************
1423 * * PHY STARTING SUBSTATE METHODS
1424 * **************************************************************************** */
1427 * scic_sds_phy_starting_initial_substate_enter -
1428 * @object: This is the object which is cast to a struct scic_sds_phy object.
1430 * This method will perform the actions required by the struct scic_sds_phy on
1431 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL. - The initial state
1432 * handlers are put in place for the struct scic_sds_phy object. - The state is
1433 * changed to the wait phy type event notification. none
1435 static void scic_sds_phy_starting_initial_substate_enter(void *object)
1437 struct scic_sds_phy *sci_phy = object;
1439 scic_sds_phy_set_starting_substate_handlers(
1440 sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL);
1442 /* This is just an temporary state go off to the starting state */
1443 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
1444 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN);
1449 * @object: This is the object which is cast to a struct scic_sds_phy object.
1451 * This method will perform the actions required by the struct scic_sds_phy on
1452 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_PHY_TYPE_EN. - Set the
1453 * struct scic_sds_phy object state handlers for this state. none
1455 static void scic_sds_phy_starting_await_ossp_en_substate_enter(void *object)
1457 struct scic_sds_phy *sci_phy = object;
1459 scic_sds_phy_set_starting_substate_handlers(
1460 sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
1466 * @object: This is the object which is cast to a struct scic_sds_phy object.
1468 * This method will perform the actions required by the struct scic_sds_phy on
1469 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. - Set the
1470 * struct scic_sds_phy object state handlers for this state. none
1472 static void scic_sds_phy_starting_await_sas_speed_en_substate_enter(
1473 void *object)
1475 struct scic_sds_phy *sci_phy = object;
1477 scic_sds_phy_set_starting_substate_handlers(
1478 sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
1484 * @object: This is the object which is cast to a struct scic_sds_phy object.
1486 * This method will perform the actions required by the struct scic_sds_phy on
1487 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - Set the
1488 * struct scic_sds_phy object state handlers for this state. none
1490 static void scic_sds_phy_starting_await_iaf_uf_substate_enter(void *object)
1492 struct scic_sds_phy *sci_phy = object;
1494 scic_sds_phy_set_starting_substate_handlers(
1495 sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
1501 * @object: This is the object which is cast to a struct scic_sds_phy object.
1503 * This method will perform the actions required by the struct scic_sds_phy on
1504 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Set the
1505 * struct scic_sds_phy object state handlers for this state. - Add this phy object to
1506 * the power control queue none
1508 static void scic_sds_phy_starting_await_sas_power_substate_enter(void *object)
1510 struct scic_sds_phy *sci_phy = object;
1512 scic_sds_phy_set_starting_substate_handlers(
1513 sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
1516 scic_sds_controller_power_control_queue_insert(
1517 scic_sds_phy_get_controller(sci_phy),
1518 sci_phy
1524 * @object: This is the object which is cast to a struct scic_sds_phy object.
1526 * This method will perform the actions required by the struct scic_sds_phy on exiting
1527 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Remove the
1528 * struct scic_sds_phy object from the power control queue. none
1530 static void scic_sds_phy_starting_await_sas_power_substate_exit(void *object)
1532 struct scic_sds_phy *sci_phy = object;
1534 scic_sds_controller_power_control_queue_remove(
1535 scic_sds_phy_get_controller(sci_phy), sci_phy
1541 * @object: This is the object which is cast to a struct scic_sds_phy object.
1543 * This method will perform the actions required by the struct scic_sds_phy on
1544 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Set the
1545 * struct scic_sds_phy object state handlers for this state. - Add this phy object to
1546 * the power control queue none
1548 static void scic_sds_phy_starting_await_sata_power_substate_enter(void *object)
1550 struct scic_sds_phy *sci_phy = object;
1552 scic_sds_phy_set_starting_substate_handlers(
1553 sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
1556 scic_sds_controller_power_control_queue_insert(
1557 scic_sds_phy_get_controller(sci_phy),
1558 sci_phy
1564 * @object: This is the object which is cast to a struct scic_sds_phy object.
1566 * This method will perform the actions required by the struct scic_sds_phy on exiting
1567 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Remove the
1568 * struct scic_sds_phy object from the power control queue. none
1570 static void scic_sds_phy_starting_await_sata_power_substate_exit(void *object)
1572 struct scic_sds_phy *sci_phy = object;
1574 scic_sds_controller_power_control_queue_remove(
1575 scic_sds_phy_get_controller(sci_phy),
1576 sci_phy
1582 * @object: This is the object which is cast to a struct scic_sds_phy object.
1584 * This function will perform the actions required by the struct scic_sds_phy on
1585 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. - Set the
1586 * struct scic_sds_phy object state handlers for this state. none
1588 static void scic_sds_phy_starting_await_sata_phy_substate_enter(void *object)
1590 struct scic_sds_phy *sci_phy = object;
1592 scic_sds_phy_set_starting_substate_handlers(
1593 sci_phy,
1594 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN);
1596 isci_timer_start(sci_phy->sata_timeout_timer,
1597 SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
1602 * @object: This is the object which is cast to a struct scic_sds_phy object.
1604 * This method will perform the actions required by the struct scic_sds_phy
1605 * on exiting
1606 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
1607 * that was started on entry to await sata phy event notification none
1609 static inline void scic_sds_phy_starting_await_sata_phy_substate_exit(
1610 void *object)
1612 struct scic_sds_phy *sci_phy = object;
1614 isci_timer_stop(sci_phy->sata_timeout_timer);
1619 * @object: This is the object which is cast to a struct scic_sds_phy object.
1621 * This method will perform the actions required by the struct scic_sds_phy on
1622 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - Set the
1623 * struct scic_sds_phy object state handlers for this state. none
1625 static void scic_sds_phy_starting_await_sata_speed_substate_enter(void *object)
1627 struct scic_sds_phy *sci_phy = object;
1629 scic_sds_phy_set_starting_substate_handlers(
1630 sci_phy,
1631 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN);
1633 isci_timer_start(sci_phy->sata_timeout_timer,
1634 SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
1639 * @object: This is the object which is cast to a struct scic_sds_phy object.
1641 * This function will perform the actions required by the
1642 * struct scic_sds_phy on exiting
1643 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
1644 * that was started on entry to await sata phy event notification none
1646 static inline void scic_sds_phy_starting_await_sata_speed_substate_exit(
1647 void *object)
1649 struct scic_sds_phy *sci_phy = object;
1651 isci_timer_stop(sci_phy->sata_timeout_timer);
1656 * @object: This is the object which is cast to a struct scic_sds_phy object.
1658 * This function will perform the actions required by the struct scic_sds_phy on
1659 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Set the
1660 * struct scic_sds_phy object state handlers for this state.
1661 * - Start the SIGNATURE FIS
1662 * timeout timer none
1664 static void scic_sds_phy_starting_await_sig_fis_uf_substate_enter(void *object)
1666 bool continue_to_ready_state;
1667 struct scic_sds_phy *sci_phy = object;
1669 scic_sds_phy_set_starting_substate_handlers(
1670 sci_phy,
1671 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
1673 continue_to_ready_state = scic_sds_port_link_detected(
1674 sci_phy->owning_port,
1675 sci_phy);
1677 if (continue_to_ready_state) {
1679 * Clear the PE suspend condition so we can actually
1680 * receive SIG FIS
1681 * The hardware will not respond to the XRDY until the PE
1682 * suspend condition is cleared.
1684 scic_sds_phy_resume(sci_phy);
1686 isci_timer_start(sci_phy->sata_timeout_timer,
1687 SCIC_SDS_SIGNATURE_FIS_TIMEOUT);
1688 } else
1689 sci_phy->is_in_link_training = false;
1694 * @object: This is the object which is cast to a struct scic_sds_phy object.
1696 * This function will perform the actions required by the
1697 * struct scic_sds_phy on exiting
1698 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Stop the SIGNATURE
1699 * FIS timeout timer. none
1701 static inline void scic_sds_phy_starting_await_sig_fis_uf_substate_exit(
1702 void *object)
1704 struct scic_sds_phy *sci_phy = object;
1706 isci_timer_stop(sci_phy->sata_timeout_timer);
1711 * @object: This is the object which is cast to a struct scic_sds_phy object.
1713 * This method will perform the actions required by the struct scic_sds_phy on
1714 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. - Set the struct scic_sds_phy
1715 * object state handlers for this state. - Change base state machine to the
1716 * ready state. none
1718 static void scic_sds_phy_starting_final_substate_enter(void *object)
1720 struct scic_sds_phy *sci_phy = object;
1722 scic_sds_phy_set_starting_substate_handlers(sci_phy,
1723 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL);
1725 /* State machine has run to completion so exit out and change
1726 * the base state machine to the ready state
1728 sci_base_state_machine_change_state(&sci_phy->state_machine,
1729 SCI_BASE_PHY_STATE_READY);
1732 /* --------------------------------------------------------------------------- */
1734 static const struct sci_base_state scic_sds_phy_starting_substates[] = {
1735 [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL] = {
1736 .enter_state = scic_sds_phy_starting_initial_substate_enter,
1738 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN] = {
1739 .enter_state = scic_sds_phy_starting_await_ossp_en_substate_enter,
1741 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN] = {
1742 .enter_state = scic_sds_phy_starting_await_sas_speed_en_substate_enter,
1744 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF] = {
1745 .enter_state = scic_sds_phy_starting_await_iaf_uf_substate_enter,
1747 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER] = {
1748 .enter_state = scic_sds_phy_starting_await_sas_power_substate_enter,
1749 .exit_state = scic_sds_phy_starting_await_sas_power_substate_exit,
1751 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER] = {
1752 .enter_state = scic_sds_phy_starting_await_sata_power_substate_enter,
1753 .exit_state = scic_sds_phy_starting_await_sata_power_substate_exit
1755 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN] = {
1756 .enter_state = scic_sds_phy_starting_await_sata_phy_substate_enter,
1757 .exit_state = scic_sds_phy_starting_await_sata_phy_substate_exit
1759 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN] = {
1760 .enter_state = scic_sds_phy_starting_await_sata_speed_substate_enter,
1761 .exit_state = scic_sds_phy_starting_await_sata_speed_substate_exit
1763 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF] = {
1764 .enter_state = scic_sds_phy_starting_await_sig_fis_uf_substate_enter,
1765 .exit_state = scic_sds_phy_starting_await_sig_fis_uf_substate_exit
1767 [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL] = {
1768 .enter_state = scic_sds_phy_starting_final_substate_enter,
1773 * This method takes the struct scic_sds_phy from a stopped state and
1774 * attempts to start it. - The phy state machine is transitioned to the
1775 * SCI_BASE_PHY_STATE_STARTING. enum sci_status SCI_SUCCESS
1777 static enum sci_status
1778 scic_sds_phy_stopped_state_start_handler(struct scic_sds_phy *sci_phy)
1780 struct isci_host *ihost;
1781 struct scic_sds_controller *scic;
1783 scic = scic_sds_phy_get_controller(sci_phy),
1784 ihost = scic_to_ihost(scic);
1786 /* Create the SIGNATURE FIS Timeout timer for this phy */
1787 sci_phy->sata_timeout_timer = isci_timer_create(ihost, sci_phy,
1788 scic_sds_phy_sata_timeout);
1790 if (sci_phy->sata_timeout_timer)
1791 sci_base_state_machine_change_state(&sci_phy->state_machine,
1792 SCI_BASE_PHY_STATE_STARTING);
1794 return SCI_SUCCESS;
1797 static enum sci_status
1798 scic_sds_phy_stopped_state_destroy_handler(struct scic_sds_phy *sci_phy)
1800 return SCI_SUCCESS;
1803 static enum sci_status
1804 scic_sds_phy_ready_state_stop_handler(struct scic_sds_phy *sci_phy)
1806 sci_base_state_machine_change_state(&sci_phy->state_machine,
1807 SCI_BASE_PHY_STATE_STOPPED);
1809 return SCI_SUCCESS;
1812 static enum sci_status
1813 scic_sds_phy_ready_state_reset_handler(struct scic_sds_phy *sci_phy)
1815 sci_base_state_machine_change_state(&sci_phy->state_machine,
1816 SCI_BASE_PHY_STATE_RESETTING);
1818 return SCI_SUCCESS;
1822 * scic_sds_phy_ready_state_event_handler -
1823 * @phy: This is the struct scic_sds_phy object which has received the event.
1825 * This method request the struct scic_sds_phy handle the received event. The only
1826 * event that we are interested in while in the ready state is the link failure
1827 * event. - decoded event is a link failure - transition the struct scic_sds_phy back
1828 * to the SCI_BASE_PHY_STATE_STARTING state. - any other event received will
1829 * report a warning message enum sci_status SCI_SUCCESS if the event received is a
1830 * link failure SCI_FAILURE_INVALID_STATE for any other event received.
1832 static enum sci_status scic_sds_phy_ready_state_event_handler(struct scic_sds_phy *sci_phy,
1833 u32 event_code)
1835 enum sci_status result = SCI_FAILURE;
1837 switch (scu_get_event_code(event_code)) {
1838 case SCU_EVENT_LINK_FAILURE:
1839 /* Link failure change state back to the starting state */
1840 sci_base_state_machine_change_state(&sci_phy->state_machine,
1841 SCI_BASE_PHY_STATE_STARTING);
1842 result = SCI_SUCCESS;
1843 break;
1845 case SCU_EVENT_BROADCAST_CHANGE:
1846 /* Broadcast change received. Notify the port. */
1847 if (scic_sds_phy_get_port(sci_phy) != NULL)
1848 scic_sds_port_broadcast_change_received(sci_phy->owning_port, sci_phy);
1849 else
1850 sci_phy->bcn_received_while_port_unassigned = true;
1851 break;
1853 default:
1854 dev_warn(sciphy_to_dev(sci_phy),
1855 "%sP SCIC PHY 0x%p ready state machine received "
1856 "unexpected event_code %x\n",
1857 __func__, sci_phy, event_code);
1859 result = SCI_FAILURE_INVALID_STATE;
1860 break;
1863 return result;
1866 static enum sci_status scic_sds_phy_resetting_state_event_handler(struct scic_sds_phy *sci_phy,
1867 u32 event_code)
1869 enum sci_status result = SCI_FAILURE;
1871 switch (scu_get_event_code(event_code)) {
1872 case SCU_EVENT_HARD_RESET_TRANSMITTED:
1873 /* Link failure change state back to the starting state */
1874 sci_base_state_machine_change_state(&sci_phy->state_machine,
1875 SCI_BASE_PHY_STATE_STARTING);
1876 result = SCI_SUCCESS;
1877 break;
1879 default:
1880 dev_warn(sciphy_to_dev(sci_phy),
1881 "%s: SCIC PHY 0x%p resetting state machine received "
1882 "unexpected event_code %x\n",
1883 __func__, sci_phy, event_code);
1885 result = SCI_FAILURE_INVALID_STATE;
1886 break;
1889 return result;
1892 /* --------------------------------------------------------------------------- */
1894 static const struct scic_sds_phy_state_handler scic_sds_phy_state_handler_table[] = {
1895 [SCI_BASE_PHY_STATE_INITIAL] = {
1896 .start_handler = scic_sds_phy_default_start_handler,
1897 .stop_handler = scic_sds_phy_default_stop_handler,
1898 .reset_handler = scic_sds_phy_default_reset_handler,
1899 .destruct_handler = scic_sds_phy_default_destroy_handler,
1900 .frame_handler = scic_sds_phy_default_frame_handler,
1901 .event_handler = scic_sds_phy_default_event_handler,
1902 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1904 [SCI_BASE_PHY_STATE_STOPPED] = {
1905 .start_handler = scic_sds_phy_stopped_state_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_stopped_state_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_STARTING] = {
1914 .start_handler = scic_sds_phy_default_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_default_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_READY] = {
1923 .start_handler = scic_sds_phy_default_start_handler,
1924 .stop_handler = scic_sds_phy_ready_state_stop_handler,
1925 .reset_handler = scic_sds_phy_ready_state_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_ready_state_event_handler,
1929 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1931 [SCI_BASE_PHY_STATE_RESETTING] = {
1932 .start_handler = scic_sds_phy_default_start_handler,
1933 .stop_handler = scic_sds_phy_default_stop_handler,
1934 .reset_handler = scic_sds_phy_default_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_resetting_state_event_handler,
1938 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1940 [SCI_BASE_PHY_STATE_FINAL] = {
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_default_event_handler,
1947 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1952 * ****************************************************************************
1953 * * PHY STATE PRIVATE METHODS
1954 * **************************************************************************** */
1958 * @sci_phy: This is the struct scic_sds_phy object to stop.
1960 * This method will stop the struct scic_sds_phy object. This does not reset the
1961 * protocol engine it just suspends it and places it in a state where it will
1962 * not cause the end device to power up. none
1964 static void scu_link_layer_stop_protocol_engine(
1965 struct scic_sds_phy *sci_phy)
1967 u32 scu_sas_pcfg_value;
1968 u32 enable_spinup_value;
1970 /* Suspend the protocol engine and place it in a sata spinup hold state */
1971 scu_sas_pcfg_value =
1972 readl(&sci_phy->link_layer_registers->phy_configuration);
1973 scu_sas_pcfg_value |=
1974 (SCU_SAS_PCFG_GEN_BIT(OOB_RESET) |
1975 SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE) |
1976 SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD));
1977 writel(scu_sas_pcfg_value,
1978 &sci_phy->link_layer_registers->phy_configuration);
1980 /* Disable the notify enable spinup primitives */
1981 enable_spinup_value = readl(&sci_phy->link_layer_registers->notify_enable_spinup_control);
1982 enable_spinup_value &= ~SCU_ENSPINUP_GEN_BIT(ENABLE);
1983 writel(enable_spinup_value, &sci_phy->link_layer_registers->notify_enable_spinup_control);
1989 * This method will start the OOB/SN state machine for this struct scic_sds_phy object.
1991 static void scu_link_layer_start_oob(
1992 struct scic_sds_phy *sci_phy)
1994 u32 scu_sas_pcfg_value;
1996 scu_sas_pcfg_value =
1997 readl(&sci_phy->link_layer_registers->phy_configuration);
1998 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
1999 scu_sas_pcfg_value &=
2000 ~(SCU_SAS_PCFG_GEN_BIT(OOB_RESET) |
2001 SCU_SAS_PCFG_GEN_BIT(HARD_RESET));
2002 writel(scu_sas_pcfg_value,
2003 &sci_phy->link_layer_registers->phy_configuration);
2009 * This method will transmit a hard reset request on the specified phy. The SCU
2010 * hardware requires that we reset the OOB state machine and set the hard reset
2011 * bit in the phy configuration register. We then must start OOB over with the
2012 * hard reset bit set.
2014 static void scu_link_layer_tx_hard_reset(
2015 struct scic_sds_phy *sci_phy)
2017 u32 phy_configuration_value;
2020 * SAS Phys must wait for the HARD_RESET_TX event notification to transition
2021 * to the starting state. */
2022 phy_configuration_value =
2023 readl(&sci_phy->link_layer_registers->phy_configuration);
2024 phy_configuration_value |=
2025 (SCU_SAS_PCFG_GEN_BIT(HARD_RESET) |
2026 SCU_SAS_PCFG_GEN_BIT(OOB_RESET));
2027 writel(phy_configuration_value,
2028 &sci_phy->link_layer_registers->phy_configuration);
2030 /* Now take the OOB state machine out of reset */
2031 phy_configuration_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
2032 phy_configuration_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
2033 writel(phy_configuration_value,
2034 &sci_phy->link_layer_registers->phy_configuration);
2038 * ****************************************************************************
2039 * * PHY BASE STATE METHODS
2040 * **************************************************************************** */
2044 * @object: This is the object which is cast to a struct scic_sds_phy object.
2046 * This method will perform the actions required by the struct scic_sds_phy on
2047 * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
2048 * handlers for the phy object base state machine initial state. none
2050 static void scic_sds_phy_initial_state_enter(void *object)
2052 struct scic_sds_phy *sci_phy = object;
2054 scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_INITIAL);
2059 * @object: This is the object which is cast to a struct scic_sds_phy object.
2061 * This function will perform the actions required by the struct scic_sds_phy on
2062 * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
2063 * handlers for the phy object base state machine initial state. - The SCU
2064 * hardware is requested to stop the protocol engine. none
2066 static void scic_sds_phy_stopped_state_enter(void *object)
2068 struct scic_sds_phy *sci_phy = object;
2069 struct scic_sds_controller *scic = scic_sds_phy_get_controller(sci_phy);
2070 struct isci_host *ihost = scic_to_ihost(scic);
2073 * @todo We need to get to the controller to place this PE in a
2074 * reset state
2077 scic_sds_phy_set_base_state_handlers(sci_phy,
2078 SCI_BASE_PHY_STATE_STOPPED);
2080 if (sci_phy->sata_timeout_timer != NULL) {
2081 isci_del_timer(ihost, sci_phy->sata_timeout_timer);
2083 sci_phy->sata_timeout_timer = NULL;
2086 scu_link_layer_stop_protocol_engine(sci_phy);
2088 if (sci_phy->state_machine.previous_state_id !=
2089 SCI_BASE_PHY_STATE_INITIAL)
2090 scic_sds_controller_link_down(
2091 scic_sds_phy_get_controller(sci_phy),
2092 scic_sds_phy_get_port(sci_phy),
2093 sci_phy);
2098 * @object: This is the object which is cast to a struct scic_sds_phy object.
2100 * This method will perform the actions required by the struct scic_sds_phy on
2101 * entering the SCI_BASE_PHY_STATE_STARTING. - This function sets the state
2102 * handlers for the phy object base state machine starting state. - The SCU
2103 * hardware is requested to start OOB/SN on this protocl engine. - The phy
2104 * starting substate machine is started. - If the previous state was the ready
2105 * state then the struct scic_sds_controller is informed that the phy has gone link
2106 * down. none
2108 static void scic_sds_phy_starting_state_enter(void *object)
2110 struct scic_sds_phy *sci_phy = object;
2112 scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_STARTING);
2114 scu_link_layer_stop_protocol_engine(sci_phy);
2115 scu_link_layer_start_oob(sci_phy);
2117 /* We don't know what kind of phy we are going to be just yet */
2118 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
2119 sci_phy->bcn_received_while_port_unassigned = false;
2121 /* Change over to the starting substate machine to continue */
2122 sci_base_state_machine_start(&sci_phy->starting_substate_machine);
2124 if (sci_phy->state_machine.previous_state_id
2125 == SCI_BASE_PHY_STATE_READY) {
2126 scic_sds_controller_link_down(
2127 scic_sds_phy_get_controller(sci_phy),
2128 scic_sds_phy_get_port(sci_phy),
2129 sci_phy
2136 * @object: This is the object which is cast to a struct scic_sds_phy object.
2138 * This method will perform the actions required by the struct scic_sds_phy on
2139 * entering the SCI_BASE_PHY_STATE_READY. - This function sets the state
2140 * handlers for the phy object base state machine ready state. - The SCU
2141 * hardware protocol engine is resumed. - The struct scic_sds_controller is informed
2142 * that the phy object has gone link up. none
2144 static void scic_sds_phy_ready_state_enter(void *object)
2146 struct scic_sds_phy *sci_phy = object;
2148 scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_READY);
2150 scic_sds_controller_link_up(
2151 scic_sds_phy_get_controller(sci_phy),
2152 scic_sds_phy_get_port(sci_phy),
2153 sci_phy
2159 * @object: This is the object which is cast to a struct scic_sds_phy object.
2161 * This method will perform the actions required by the struct scic_sds_phy on exiting
2162 * the SCI_BASE_PHY_STATE_INITIAL. This function suspends the SCU hardware
2163 * protocol engine represented by this struct scic_sds_phy object. none
2165 static void scic_sds_phy_ready_state_exit(void *object)
2167 struct scic_sds_phy *sci_phy = object;
2169 scic_sds_phy_suspend(sci_phy);
2174 * @object: This is the object which is cast to a struct scic_sds_phy object.
2176 * This method will perform the actions required by the struct scic_sds_phy on
2177 * entering the SCI_BASE_PHY_STATE_RESETTING. - This function sets the state
2178 * handlers for the phy object base state machine resetting state. none
2180 static void scic_sds_phy_resetting_state_enter(void *object)
2182 struct scic_sds_phy *sci_phy = object;
2184 scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_RESETTING);
2187 * The phy is being reset, therefore deactivate it from the port.
2188 * In the resetting state we don't notify the user regarding
2189 * link up and link down notifications. */
2190 scic_sds_port_deactivate_phy(sci_phy->owning_port, sci_phy, false);
2192 if (sci_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
2193 scu_link_layer_tx_hard_reset(sci_phy);
2194 } else {
2196 * The SCU does not need to have a discrete reset state so
2197 * just go back to the starting state.
2199 sci_base_state_machine_change_state(
2200 &sci_phy->state_machine,
2201 SCI_BASE_PHY_STATE_STARTING);
2207 * @object: This is the object which is cast to a struct scic_sds_phy object.
2209 * This method will perform the actions required by the struct scic_sds_phy on
2210 * entering the SCI_BASE_PHY_STATE_FINAL. - This function sets the state
2211 * handlers for the phy object base state machine final state. none
2213 static void scic_sds_phy_final_state_enter(void *object)
2215 struct scic_sds_phy *sci_phy = object;
2217 scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_FINAL);
2219 /* Nothing to do here */
2222 /* --------------------------------------------------------------------------- */
2224 static const struct sci_base_state scic_sds_phy_state_table[] = {
2225 [SCI_BASE_PHY_STATE_INITIAL] = {
2226 .enter_state = scic_sds_phy_initial_state_enter,
2228 [SCI_BASE_PHY_STATE_STOPPED] = {
2229 .enter_state = scic_sds_phy_stopped_state_enter,
2231 [SCI_BASE_PHY_STATE_STARTING] = {
2232 .enter_state = scic_sds_phy_starting_state_enter,
2234 [SCI_BASE_PHY_STATE_READY] = {
2235 .enter_state = scic_sds_phy_ready_state_enter,
2236 .exit_state = scic_sds_phy_ready_state_exit,
2238 [SCI_BASE_PHY_STATE_RESETTING] = {
2239 .enter_state = scic_sds_phy_resetting_state_enter,
2241 [SCI_BASE_PHY_STATE_FINAL] = {
2242 .enter_state = scic_sds_phy_final_state_enter,
2246 void scic_sds_phy_construct(struct scic_sds_phy *sci_phy,
2247 struct scic_sds_port *owning_port, u8 phy_index)
2249 sci_base_state_machine_construct(&sci_phy->state_machine,
2250 sci_phy,
2251 scic_sds_phy_state_table,
2252 SCI_BASE_PHY_STATE_INITIAL);
2254 sci_base_state_machine_start(&sci_phy->state_machine);
2256 /* Copy the rest of the input data to our locals */
2257 sci_phy->owning_port = owning_port;
2258 sci_phy->phy_index = phy_index;
2259 sci_phy->bcn_received_while_port_unassigned = false;
2260 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
2261 sci_phy->link_layer_registers = NULL;
2262 sci_phy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
2263 sci_phy->sata_timeout_timer = NULL;
2265 /* Initialize the the substate machines */
2266 sci_base_state_machine_construct(&sci_phy->starting_substate_machine,
2267 sci_phy,
2268 scic_sds_phy_starting_substates,
2269 SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL);
2272 void isci_phy_init(struct isci_phy *iphy, struct isci_host *ihost, int index)
2274 union scic_oem_parameters oem;
2275 u64 sci_sas_addr;
2276 __be64 sas_addr;
2278 scic_oem_parameters_get(&ihost->sci, &oem);
2279 sci_sas_addr = oem.sds1.phys[index].sas_address.high;
2280 sci_sas_addr <<= 32;
2281 sci_sas_addr |= oem.sds1.phys[index].sas_address.low;
2282 sas_addr = cpu_to_be64(sci_sas_addr);
2283 memcpy(iphy->sas_addr, &sas_addr, sizeof(sas_addr));
2285 iphy->isci_port = NULL;
2286 iphy->sas_phy.enabled = 0;
2287 iphy->sas_phy.id = index;
2288 iphy->sas_phy.sas_addr = &iphy->sas_addr[0];
2289 iphy->sas_phy.frame_rcvd = (u8 *)&iphy->frame_rcvd;
2290 iphy->sas_phy.ha = &ihost->sas_ha;
2291 iphy->sas_phy.lldd_phy = iphy;
2292 iphy->sas_phy.enabled = 1;
2293 iphy->sas_phy.class = SAS;
2294 iphy->sas_phy.iproto = SAS_PROTOCOL_ALL;
2295 iphy->sas_phy.tproto = 0;
2296 iphy->sas_phy.type = PHY_TYPE_PHYSICAL;
2297 iphy->sas_phy.role = PHY_ROLE_INITIATOR;
2298 iphy->sas_phy.oob_mode = OOB_NOT_CONNECTED;
2299 iphy->sas_phy.linkrate = SAS_LINK_RATE_UNKNOWN;
2300 memset(&iphy->frame_rcvd, 0, sizeof(iphy->frame_rcvd));
2305 * isci_phy_control() - This function is one of the SAS Domain Template
2306 * functions. This is a phy management function.
2307 * @phy: This parameter specifies the sphy being controlled.
2308 * @func: This parameter specifies the phy control function being invoked.
2309 * @buf: This parameter is specific to the phy function being invoked.
2311 * status, zero indicates success.
2313 int isci_phy_control(struct asd_sas_phy *sas_phy,
2314 enum phy_func func,
2315 void *buf)
2317 int ret = 0;
2318 struct isci_phy *iphy = sas_phy->lldd_phy;
2319 struct isci_port *iport = iphy->isci_port;
2320 struct isci_host *ihost = sas_phy->ha->lldd_ha;
2321 unsigned long flags;
2323 dev_dbg(&ihost->pdev->dev,
2324 "%s: phy %p; func %d; buf %p; isci phy %p, port %p\n",
2325 __func__, sas_phy, func, buf, iphy, iport);
2327 switch (func) {
2328 case PHY_FUNC_DISABLE:
2329 spin_lock_irqsave(&ihost->scic_lock, flags);
2330 scic_sds_phy_stop(&iphy->sci);
2331 spin_unlock_irqrestore(&ihost->scic_lock, flags);
2332 break;
2334 case PHY_FUNC_LINK_RESET:
2335 spin_lock_irqsave(&ihost->scic_lock, flags);
2336 scic_sds_phy_stop(&iphy->sci);
2337 scic_sds_phy_start(&iphy->sci);
2338 spin_unlock_irqrestore(&ihost->scic_lock, flags);
2339 break;
2341 case PHY_FUNC_HARD_RESET:
2342 if (!iport)
2343 return -ENODEV;
2345 /* Perform the port reset. */
2346 ret = isci_port_perform_hard_reset(ihost, iport, iphy);
2348 break;
2350 default:
2351 dev_dbg(&ihost->pdev->dev,
2352 "%s: phy %p; func %d NOT IMPLEMENTED!\n",
2353 __func__, sas_phy, func);
2354 ret = -ENOSYS;
2355 break;
2357 return ret;