aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/isci/phy.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/isci/phy.c')
-rw-r--r--drivers/scsi/isci/phy.c2213
1 files changed, 2210 insertions, 3 deletions
diff --git a/drivers/scsi/isci/phy.c b/drivers/scsi/isci/phy.c
index 1134395c970e..b92d51f25481 100644
--- a/drivers/scsi/isci/phy.c
+++ b/drivers/scsi/isci/phy.c
@@ -56,12 +56,2219 @@
56#include "isci.h" 56#include "isci.h"
57#include "host.h" 57#include "host.h"
58#include "phy.h" 58#include "phy.h"
59#include "scu_event_codes.h"
59#include "scic_port.h" 60#include "scic_port.h"
60#include "scic_config_parameters.h" 61#include "scic_config_parameters.h"
62#include "timers.h"
61 63
62struct scic_sds_phy; 64/* Maximum arbitration wait time in micro-seconds */
63extern enum sci_status scic_sds_phy_start(struct scic_sds_phy *sci_phy); 65#define SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME (700)
64extern enum sci_status scic_sds_phy_stop(struct scic_sds_phy *sci_phy); 66
67enum sas_linkrate sci_phy_linkrate(struct scic_sds_phy *sci_phy)
68{
69 return sci_phy->max_negotiated_speed;
70}
71
72/*
73 * *****************************************************************************
74 * * SCIC SDS PHY Internal Methods
75 * ***************************************************************************** */
76
77/**
78 * This method will initialize the phy transport layer registers
79 * @sci_phy:
80 * @transport_layer_registers
81 *
82 * enum sci_status
83 */
84static enum sci_status scic_sds_phy_transport_layer_initialization(
85 struct scic_sds_phy *sci_phy,
86 struct scu_transport_layer_registers __iomem *transport_layer_registers)
87{
88 u32 tl_control;
89
90 sci_phy->transport_layer_registers = transport_layer_registers;
91
92 writel(SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX,
93 &sci_phy->transport_layer_registers->stp_rni);
94
95 /*
96 * Hardware team recommends that we enable the STP prefetch for all
97 * transports
98 */
99 tl_control = readl(&sci_phy->transport_layer_registers->control);
100 tl_control |= SCU_TLCR_GEN_BIT(STP_WRITE_DATA_PREFETCH);
101 writel(tl_control, &sci_phy->transport_layer_registers->control);
102
103 return SCI_SUCCESS;
104}
105
106/**
107 * This method will initialize the phy link layer registers
108 * @sci_phy:
109 * @link_layer_registers:
110 *
111 * enum sci_status
112 */
113static enum sci_status
114scic_sds_phy_link_layer_initialization(struct scic_sds_phy *sci_phy,
115 struct scu_link_layer_registers __iomem *link_layer_registers)
116{
117 struct scic_sds_controller *scic =
118 sci_phy->owning_port->owning_controller;
119 int phy_idx = sci_phy->phy_index;
120 struct sci_phy_user_params *phy_user =
121 &scic->user_parameters.sds1.phys[phy_idx];
122 struct sci_phy_oem_params *phy_oem =
123 &scic->oem_parameters.sds1.phys[phy_idx];
124 u32 phy_configuration;
125 struct scic_phy_cap phy_cap;
126 u32 parity_check = 0;
127 u32 parity_count = 0;
128 u32 llctl, link_rate;
129 u32 clksm_value = 0;
130
131 sci_phy->link_layer_registers = link_layer_registers;
132
133 /* Set our IDENTIFY frame data */
134 #define SCI_END_DEVICE 0x01
135
136 writel(SCU_SAS_TIID_GEN_BIT(SMP_INITIATOR) |
137 SCU_SAS_TIID_GEN_BIT(SSP_INITIATOR) |
138 SCU_SAS_TIID_GEN_BIT(STP_INITIATOR) |
139 SCU_SAS_TIID_GEN_BIT(DA_SATA_HOST) |
140 SCU_SAS_TIID_GEN_VAL(DEVICE_TYPE, SCI_END_DEVICE),
141 &sci_phy->link_layer_registers->transmit_identification);
142
143 /* Write the device SAS Address */
144 writel(0xFEDCBA98,
145 &sci_phy->link_layer_registers->sas_device_name_high);
146 writel(phy_idx, &sci_phy->link_layer_registers->sas_device_name_low);
147
148 /* Write the source SAS Address */
149 writel(phy_oem->sas_address.high,
150 &sci_phy->link_layer_registers->source_sas_address_high);
151 writel(phy_oem->sas_address.low,
152 &sci_phy->link_layer_registers->source_sas_address_low);
153
154 /* Clear and Set the PHY Identifier */
155 writel(0, &sci_phy->link_layer_registers->identify_frame_phy_id);
156 writel(SCU_SAS_TIPID_GEN_VALUE(ID, phy_idx),
157 &sci_phy->link_layer_registers->identify_frame_phy_id);
158
159 /* Change the initial state of the phy configuration register */
160 phy_configuration =
161 readl(&sci_phy->link_layer_registers->phy_configuration);
162
163 /* Hold OOB state machine in reset */
164 phy_configuration |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
165 writel(phy_configuration,
166 &sci_phy->link_layer_registers->phy_configuration);
167
168 /* Configure the SNW capabilities */
169 phy_cap.all = 0;
170 phy_cap.start = 1;
171 phy_cap.gen3_no_ssc = 1;
172 phy_cap.gen2_no_ssc = 1;
173 phy_cap.gen1_no_ssc = 1;
174 if (scic->oem_parameters.sds1.controller.do_enable_ssc == true) {
175 phy_cap.gen3_ssc = 1;
176 phy_cap.gen2_ssc = 1;
177 phy_cap.gen1_ssc = 1;
178 }
179
180 /*
181 * The SAS specification indicates that the phy_capabilities that
182 * are transmitted shall have an even parity. Calculate the parity. */
183 parity_check = phy_cap.all;
184 while (parity_check != 0) {
185 if (parity_check & 0x1)
186 parity_count++;
187 parity_check >>= 1;
188 }
189
190 /*
191 * If parity indicates there are an odd number of bits set, then
192 * set the parity bit to 1 in the phy capabilities. */
193 if ((parity_count % 2) != 0)
194 phy_cap.parity = 1;
195
196 writel(phy_cap.all, &sci_phy->link_layer_registers->phy_capabilities);
197
198 /* Set the enable spinup period but disable the ability to send
199 * notify enable spinup
200 */
201 writel(SCU_ENSPINUP_GEN_VAL(COUNT,
202 phy_user->notify_enable_spin_up_insertion_frequency),
203 &sci_phy->link_layer_registers->notify_enable_spinup_control);
204
205 /* Write the ALIGN Insertion Ferequency for connected phy and
206 * inpendent of connected state
207 */
208 clksm_value = SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(CONNECTED,
209 phy_user->in_connection_align_insertion_frequency);
210
211 clksm_value |= SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(GENERAL,
212 phy_user->align_insertion_frequency);
213
214 writel(clksm_value, &sci_phy->link_layer_registers->clock_skew_management);
215
216 /* @todo Provide a way to write this register correctly */
217 writel(0x02108421,
218 &sci_phy->link_layer_registers->afe_lookup_table_control);
219
220 llctl = SCU_SAS_LLCTL_GEN_VAL(NO_OUTBOUND_TASK_TIMEOUT,
221 (u8)scic->user_parameters.sds1.no_outbound_task_timeout);
222
223 switch(phy_user->max_speed_generation) {
224 case SCIC_SDS_PARM_GEN3_SPEED:
225 link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN3;
226 break;
227 case SCIC_SDS_PARM_GEN2_SPEED:
228 link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN2;
229 break;
230 default:
231 link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN1;
232 break;
233 }
234 llctl |= SCU_SAS_LLCTL_GEN_VAL(MAX_LINK_RATE, link_rate);
235 writel(llctl, &sci_phy->link_layer_registers->link_layer_control);
236
237 if (is_a0() || is_a2()) {
238 /* Program the max ARB time for the PHY to 700us so we inter-operate with
239 * the PMC expander which shuts down PHYs if the expander PHY generates too
240 * many breaks. This time value will guarantee that the initiator PHY will
241 * generate the break.
242 */
243 writel(SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME,
244 &sci_phy->link_layer_registers->maximum_arbitration_wait_timer_timeout);
245 }
246
247 /*
248 * Set the link layer hang detection to 500ms (0x1F4) from its default
249 * value of 128ms. Max value is 511 ms.
250 */
251 writel(0x1F4, &sci_phy->link_layer_registers->link_layer_hang_detection_timeout);
252
253 /* We can exit the initial state to the stopped state */
254 sci_base_state_machine_change_state(&sci_phy->state_machine,
255 SCI_BASE_PHY_STATE_STOPPED);
256
257 return SCI_SUCCESS;
258}
259
260/**
261 * This function will handle the sata SIGNATURE FIS timeout condition. It will
262 * restart the starting substate machine since we dont know what has actually
263 * happening.
264 */
265static void scic_sds_phy_sata_timeout(void *phy)
266{
267 struct scic_sds_phy *sci_phy = phy;
268
269 dev_dbg(sciphy_to_dev(sci_phy),
270 "%s: SCIC SDS Phy 0x%p did not receive signature fis before "
271 "timeout.\n",
272 __func__,
273 sci_phy);
274
275 sci_base_state_machine_stop(&sci_phy->starting_substate_machine);
276
277 sci_base_state_machine_change_state(&sci_phy->state_machine,
278 SCI_BASE_PHY_STATE_STARTING);
279}
280
281/**
282 * This method returns the port currently containing this phy. If the phy is
283 * currently contained by the dummy port, then the phy is considered to not
284 * be part of a port.
285 * @sci_phy: This parameter specifies the phy for which to retrieve the
286 * containing port.
287 *
288 * This method returns a handle to a port that contains the supplied phy.
289 * NULL This value is returned if the phy is not part of a real
290 * port (i.e. it's contained in the dummy port). !NULL All other
291 * values indicate a handle/pointer to the port containing the phy.
292 */
293struct scic_sds_port *scic_sds_phy_get_port(
294 struct scic_sds_phy *sci_phy)
295{
296 if (scic_sds_port_get_index(sci_phy->owning_port) == SCIC_SDS_DUMMY_PORT)
297 return NULL;
298
299 return sci_phy->owning_port;
300}
301
302/**
303 * This method will assign a port to the phy object.
304 * @out]: sci_phy This parameter specifies the phy for which to assign a port
305 * object.
306 *
307 *
308 */
309void scic_sds_phy_set_port(
310 struct scic_sds_phy *sci_phy,
311 struct scic_sds_port *sci_port)
312{
313 sci_phy->owning_port = sci_port;
314
315 if (sci_phy->bcn_received_while_port_unassigned) {
316 sci_phy->bcn_received_while_port_unassigned = false;
317 scic_sds_port_broadcast_change_received(sci_phy->owning_port, sci_phy);
318 }
319}
320
321/**
322 * This method will initialize the constructed phy
323 * @sci_phy:
324 * @link_layer_registers:
325 *
326 * enum sci_status
327 */
328enum sci_status scic_sds_phy_initialize(
329 struct scic_sds_phy *sci_phy,
330 struct scu_transport_layer_registers __iomem *transport_layer_registers,
331 struct scu_link_layer_registers __iomem *link_layer_registers)
332{
333 struct scic_sds_controller *scic = scic_sds_phy_get_controller(sci_phy);
334 struct isci_host *ihost = scic_to_ihost(scic);
335
336 /* Create the SIGNATURE FIS Timeout timer for this phy */
337 sci_phy->sata_timeout_timer =
338 isci_timer_create(
339 ihost,
340 sci_phy,
341 scic_sds_phy_sata_timeout);
342
343 /* Perfrom the initialization of the TL hardware */
344 scic_sds_phy_transport_layer_initialization(
345 sci_phy,
346 transport_layer_registers);
347
348 /* Perofrm the initialization of the PE hardware */
349 scic_sds_phy_link_layer_initialization(sci_phy, link_layer_registers);
350
351 /*
352 * There is nothing that needs to be done in this state just
353 * transition to the stopped state. */
354 sci_base_state_machine_change_state(&sci_phy->state_machine,
355 SCI_BASE_PHY_STATE_STOPPED);
356
357 return SCI_SUCCESS;
358}
359
360/**
361 * This method assigns the direct attached device ID for this phy.
362 *
363 * @sci_phy The phy for which the direct attached device id is to
364 * be assigned.
365 * @device_id The direct attached device ID to assign to the phy.
366 * This will either be the RNi for the device or an invalid RNi if there
367 * is no current device assigned to the phy.
368 */
369void scic_sds_phy_setup_transport(
370 struct scic_sds_phy *sci_phy,
371 u32 device_id)
372{
373 u32 tl_control;
374
375 writel(device_id, &sci_phy->transport_layer_registers->stp_rni);
376
377 /*
378 * The read should guarantee that the first write gets posted
379 * before the next write
380 */
381 tl_control = readl(&sci_phy->transport_layer_registers->control);
382 tl_control |= SCU_TLCR_GEN_BIT(CLEAR_TCI_NCQ_MAPPING_TABLE);
383 writel(tl_control, &sci_phy->transport_layer_registers->control);
384}
385
386/**
387 *
388 * @sci_phy: The phy object to be suspended.
389 *
390 * This function will perform the register reads/writes to suspend the SCU
391 * hardware protocol engine. none
392 */
393static void scic_sds_phy_suspend(
394 struct scic_sds_phy *sci_phy)
395{
396 u32 scu_sas_pcfg_value;
397
398 scu_sas_pcfg_value =
399 readl(&sci_phy->link_layer_registers->phy_configuration);
400 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE);
401 writel(scu_sas_pcfg_value,
402 &sci_phy->link_layer_registers->phy_configuration);
403
404 scic_sds_phy_setup_transport(
405 sci_phy,
406 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX);
407}
408
409void scic_sds_phy_resume(struct scic_sds_phy *sci_phy)
410{
411 u32 scu_sas_pcfg_value;
412
413 scu_sas_pcfg_value =
414 readl(&sci_phy->link_layer_registers->phy_configuration);
415 scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE);
416 writel(scu_sas_pcfg_value,
417 &sci_phy->link_layer_registers->phy_configuration);
418}
419
420void scic_sds_phy_get_sas_address(struct scic_sds_phy *sci_phy,
421 struct sci_sas_address *sas_address)
422{
423 sas_address->high = readl(&sci_phy->link_layer_registers->source_sas_address_high);
424 sas_address->low = readl(&sci_phy->link_layer_registers->source_sas_address_low);
425}
426
427void scic_sds_phy_get_attached_sas_address(struct scic_sds_phy *sci_phy,
428 struct sci_sas_address *sas_address)
429{
430 struct sas_identify_frame *iaf;
431 struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
432
433 iaf = &iphy->frame_rcvd.iaf;
434 memcpy(sas_address, iaf->sas_addr, SAS_ADDR_SIZE);
435}
436
437void scic_sds_phy_get_protocols(struct scic_sds_phy *sci_phy,
438 struct scic_phy_proto *protocols)
439{
440 protocols->all =
441 (u16)(readl(&sci_phy->
442 link_layer_registers->transmit_identification) &
443 0x0000FFFF);
444}
445
446/**
447 * This method will attempt to start the phy object. This request is only valid
448 * when the phy is in the stopped state
449 * @sci_phy:
450 *
451 * enum sci_status
452 */
453enum sci_status scic_sds_phy_start(struct scic_sds_phy *sci_phy)
454{
455 return sci_phy->state_handlers->start_handler(sci_phy);
456}
457
458/**
459 * This method will attempt to stop the phy object.
460 * @sci_phy:
461 *
462 * enum sci_status SCI_SUCCESS if the phy is going to stop SCI_INVALID_STATE
463 * if the phy is not in a valid state to stop
464 */
465enum sci_status scic_sds_phy_stop(struct scic_sds_phy *sci_phy)
466{
467 return sci_phy->state_handlers->stop_handler(sci_phy);
468}
469
470/**
471 * This method will attempt to reset the phy. This request is only valid when
472 * the phy is in an ready state
473 * @sci_phy:
474 *
475 * enum sci_status
476 */
477enum sci_status scic_sds_phy_reset(
478 struct scic_sds_phy *sci_phy)
479{
480 return sci_phy->state_handlers->reset_handler(sci_phy);
481}
482
483/**
484 * This method will process the event code received.
485 * @sci_phy:
486 * @event_code:
487 *
488 * enum sci_status
489 */
490enum sci_status scic_sds_phy_event_handler(
491 struct scic_sds_phy *sci_phy,
492 u32 event_code)
493{
494 return sci_phy->state_handlers->event_handler(sci_phy, event_code);
495}
496
497/**
498 * This method will process the frame index received.
499 * @sci_phy:
500 * @frame_index:
501 *
502 * enum sci_status
503 */
504enum sci_status scic_sds_phy_frame_handler(
505 struct scic_sds_phy *sci_phy,
506 u32 frame_index)
507{
508 return sci_phy->state_handlers->frame_handler(sci_phy, frame_index);
509}
510
511/**
512 * This method will give the phy permission to consume power
513 * @sci_phy:
514 *
515 * enum sci_status
516 */
517enum sci_status scic_sds_phy_consume_power_handler(
518 struct scic_sds_phy *sci_phy)
519{
520 return sci_phy->state_handlers->consume_power_handler(sci_phy);
521}
522
523/*
524 * *****************************************************************************
525 * * SCIC SDS PHY HELPER FUNCTIONS
526 * ***************************************************************************** */
527
528
529/**
530 *
531 * @sci_phy: The phy object that received SAS PHY DETECTED.
532 *
533 * This method continues the link training for the phy as if it were a SAS PHY
534 * instead of a SATA PHY. This is done because the completion queue had a SAS
535 * PHY DETECTED event when the state machine was expecting a SATA PHY event.
536 * none
537 */
538static void scic_sds_phy_start_sas_link_training(
539 struct scic_sds_phy *sci_phy)
540{
541 u32 phy_control;
542
543 phy_control =
544 readl(&sci_phy->link_layer_registers->phy_configuration);
545 phy_control |= SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD);
546 writel(phy_control,
547 &sci_phy->link_layer_registers->phy_configuration);
548
549 sci_base_state_machine_change_state(
550 &sci_phy->starting_substate_machine,
551 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
552 );
553
554 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SAS;
555}
556
557/**
558 *
559 * @sci_phy: The phy object that received a SATA SPINUP HOLD event
560 *
561 * This method continues the link training for the phy as if it were a SATA PHY
562 * instead of a SAS PHY. This is done because the completion queue had a SATA
563 * SPINUP HOLD event when the state machine was expecting a SAS PHY event. none
564 */
565static void scic_sds_phy_start_sata_link_training(
566 struct scic_sds_phy *sci_phy)
567{
568 sci_base_state_machine_change_state(
569 &sci_phy->starting_substate_machine,
570 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
571 );
572
573 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
574}
575
576/**
577 * scic_sds_phy_complete_link_training - perform processing common to
578 * all protocols upon completion of link training.
579 * @sci_phy: This parameter specifies the phy object for which link training
580 * has completed.
581 * @max_link_rate: This parameter specifies the maximum link rate to be
582 * associated with this phy.
583 * @next_state: This parameter specifies the next state for the phy's starting
584 * sub-state machine.
585 *
586 */
587static void scic_sds_phy_complete_link_training(
588 struct scic_sds_phy *sci_phy,
589 enum sas_linkrate max_link_rate,
590 u32 next_state)
591{
592 sci_phy->max_negotiated_speed = max_link_rate;
593
594 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
595 next_state);
596}
597
598static void scic_sds_phy_restart_starting_state(
599 struct scic_sds_phy *sci_phy)
600{
601 /* Stop the current substate machine */
602 sci_base_state_machine_stop(&sci_phy->starting_substate_machine);
603
604 /* Re-enter the base state machine starting state */
605 sci_base_state_machine_change_state(&sci_phy->state_machine,
606 SCI_BASE_PHY_STATE_STARTING);
607}
608
609/* ****************************************************************************
610 * SCIC SDS PHY general handlers
611 ************************************************************************** */
612static enum sci_status scic_sds_phy_starting_substate_general_stop_handler(
613 struct scic_sds_phy *phy)
614{
615 sci_base_state_machine_stop(&phy->starting_substate_machine);
616
617 sci_base_state_machine_change_state(&phy->state_machine,
618 SCI_BASE_PHY_STATE_STOPPED);
619
620 return SCI_SUCCESS;
621}
622
623/*
624 * *****************************************************************************
625 * * SCIC SDS PHY EVENT_HANDLERS
626 * ***************************************************************************** */
627
628/**
629 *
630 * @phy: This struct scic_sds_phy object which has received an event.
631 * @event_code: This is the event code which the phy object is to decode.
632 *
633 * This method is called when an event notification is received for the phy
634 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. -
635 * decode the event - sas phy detected causes a state transition to the wait
636 * for speed event notification. - any other events log a warning message and
637 * set a failure status enum sci_status SCI_SUCCESS on any valid event notification
638 * SCI_FAILURE on any unexpected event notifation
639 */
640static enum sci_status scic_sds_phy_starting_substate_await_ossp_event_handler(
641 struct scic_sds_phy *sci_phy,
642 u32 event_code)
643{
644 u32 result = SCI_SUCCESS;
645
646 switch (scu_get_event_code(event_code)) {
647 case SCU_EVENT_SAS_PHY_DETECTED:
648 scic_sds_phy_start_sas_link_training(sci_phy);
649 sci_phy->is_in_link_training = true;
650 break;
651
652 case SCU_EVENT_SATA_SPINUP_HOLD:
653 scic_sds_phy_start_sata_link_training(sci_phy);
654 sci_phy->is_in_link_training = true;
655 break;
656
657 default:
658 dev_dbg(sciphy_to_dev(sci_phy),
659 "%s: PHY starting substate machine received "
660 "unexpected event_code %x\n",
661 __func__,
662 event_code);
663
664 result = SCI_FAILURE;
665 break;
666 }
667
668 return result;
669}
670
671/**
672 *
673 * @phy: This struct scic_sds_phy object which has received an event.
674 * @event_code: This is the event code which the phy object is to decode.
675 *
676 * This method is called when an event notification is received for the phy
677 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. -
678 * decode the event - sas phy detected returns us back to this state. - speed
679 * event detected causes a state transition to the wait for iaf. - identify
680 * timeout is an un-expected event and the state machine is restarted. - link
681 * failure events restart the starting state machine - any other events log a
682 * warning message and set a failure status enum sci_status SCI_SUCCESS on any valid
683 * event notification SCI_FAILURE on any unexpected event notifation
684 */
685static enum sci_status scic_sds_phy_starting_substate_await_sas_phy_speed_event_handler(
686 struct scic_sds_phy *sci_phy,
687 u32 event_code)
688{
689 u32 result = SCI_SUCCESS;
690
691 switch (scu_get_event_code(event_code)) {
692 case SCU_EVENT_SAS_PHY_DETECTED:
693 /*
694 * Why is this being reported again by the controller?
695 * We would re-enter this state so just stay here */
696 break;
697
698 case SCU_EVENT_SAS_15:
699 case SCU_EVENT_SAS_15_SSC:
700 scic_sds_phy_complete_link_training(
701 sci_phy,
702 SAS_LINK_RATE_1_5_GBPS,
703 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF);
704 break;
705
706 case SCU_EVENT_SAS_30:
707 case SCU_EVENT_SAS_30_SSC:
708 scic_sds_phy_complete_link_training(
709 sci_phy,
710 SAS_LINK_RATE_3_0_GBPS,
711 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF);
712 break;
713
714 case SCU_EVENT_SAS_60:
715 case SCU_EVENT_SAS_60_SSC:
716 scic_sds_phy_complete_link_training(
717 sci_phy,
718 SAS_LINK_RATE_6_0_GBPS,
719 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF);
720 break;
721
722 case SCU_EVENT_SATA_SPINUP_HOLD:
723 /*
724 * We were doing SAS PHY link training and received a SATA PHY event
725 * continue OOB/SN as if this were a SATA PHY */
726 scic_sds_phy_start_sata_link_training(sci_phy);
727 break;
728
729 case SCU_EVENT_LINK_FAILURE:
730 /* Link failure change state back to the starting state */
731 scic_sds_phy_restart_starting_state(sci_phy);
732 break;
733
734 default:
735 dev_warn(sciphy_to_dev(sci_phy),
736 "%s: PHY starting substate machine received "
737 "unexpected event_code %x\n",
738 __func__,
739 event_code);
740
741 result = SCI_FAILURE;
742 break;
743 }
744
745 return result;
746}
747
748/**
749 *
750 * @phy: This struct scic_sds_phy object which has received an event.
751 * @event_code: This is the event code which the phy object is to decode.
752 *
753 * This method is called when an event notification is received for the phy
754 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. -
755 * decode the event - sas phy detected event backs up the state machine to the
756 * await speed notification. - identify timeout is an un-expected event and the
757 * state machine is restarted. - link failure events restart the starting state
758 * machine - any other events log a warning message and set a failure status
759 * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any
760 * unexpected event notifation
761 */
762static enum sci_status scic_sds_phy_starting_substate_await_iaf_uf_event_handler(
763 struct scic_sds_phy *sci_phy,
764 u32 event_code)
765{
766 u32 result = SCI_SUCCESS;
767
768 switch (scu_get_event_code(event_code)) {
769 case SCU_EVENT_SAS_PHY_DETECTED:
770 /* Backup the state machine */
771 scic_sds_phy_start_sas_link_training(sci_phy);
772 break;
773
774 case SCU_EVENT_SATA_SPINUP_HOLD:
775 /*
776 * We were doing SAS PHY link training and received a SATA PHY event
777 * continue OOB/SN as if this were a SATA PHY */
778 scic_sds_phy_start_sata_link_training(sci_phy);
779 break;
780
781 case SCU_EVENT_RECEIVED_IDENTIFY_TIMEOUT:
782 case SCU_EVENT_LINK_FAILURE:
783 case SCU_EVENT_HARD_RESET_RECEIVED:
784 /* Start the oob/sn state machine over again */
785 scic_sds_phy_restart_starting_state(sci_phy);
786 break;
787
788 default:
789 dev_warn(sciphy_to_dev(sci_phy),
790 "%s: PHY starting substate machine received "
791 "unexpected event_code %x\n",
792 __func__,
793 event_code);
794
795 result = SCI_FAILURE;
796 break;
797 }
798
799 return result;
800}
801
802/**
803 *
804 * @phy: This struct scic_sds_phy object which has received an event.
805 * @event_code: This is the event code which the phy object is to decode.
806 *
807 * This method is called when an event notification is received for the phy
808 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_POWER. -
809 * decode the event - link failure events restart the starting state machine -
810 * any other events log a warning message and set a failure status enum sci_status
811 * SCI_SUCCESS on a link failure event SCI_FAILURE on any unexpected event
812 * notifation
813 */
814static enum sci_status scic_sds_phy_starting_substate_await_sas_power_event_handler(
815 struct scic_sds_phy *sci_phy,
816 u32 event_code)
817{
818 u32 result = SCI_SUCCESS;
819
820 switch (scu_get_event_code(event_code)) {
821 case SCU_EVENT_LINK_FAILURE:
822 /* Link failure change state back to the starting state */
823 scic_sds_phy_restart_starting_state(sci_phy);
824 break;
825
826 default:
827 dev_warn(sciphy_to_dev(sci_phy),
828 "%s: PHY starting substate machine received unexpected "
829 "event_code %x\n",
830 __func__,
831 event_code);
832
833 result = SCI_FAILURE;
834 break;
835 }
836
837 return result;
838}
839
840/**
841 *
842 * @phy: This struct scic_sds_phy object which has received an event.
843 * @event_code: This is the event code which the phy object is to decode.
844 *
845 * This method is called when an event notification is received for the phy
846 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. -
847 * decode the event - link failure events restart the starting state machine -
848 * sata spinup hold events are ignored since they are expected - any other
849 * events log a warning message and set a failure status enum sci_status SCI_SUCCESS
850 * on a link failure event SCI_FAILURE on any unexpected event notifation
851 */
852static enum sci_status scic_sds_phy_starting_substate_await_sata_power_event_handler(
853 struct scic_sds_phy *sci_phy,
854 u32 event_code)
855{
856 u32 result = SCI_SUCCESS;
857
858 switch (scu_get_event_code(event_code)) {
859 case SCU_EVENT_LINK_FAILURE:
860 /* Link failure change state back to the starting state */
861 scic_sds_phy_restart_starting_state(sci_phy);
862 break;
863
864 case SCU_EVENT_SATA_SPINUP_HOLD:
865 /* These events are received every 10ms and are expected while in this state */
866 break;
867
868 case SCU_EVENT_SAS_PHY_DETECTED:
869 /*
870 * There has been a change in the phy type before OOB/SN for the
871 * SATA finished start down the SAS link traning path. */
872 scic_sds_phy_start_sas_link_training(sci_phy);
873 break;
874
875 default:
876 dev_warn(sciphy_to_dev(sci_phy),
877 "%s: PHY starting substate machine received "
878 "unexpected event_code %x\n",
879 __func__,
880 event_code);
881
882 result = SCI_FAILURE;
883 break;
884 }
885
886 return result;
887}
888
889/**
890 * scic_sds_phy_starting_substate_await_sata_phy_event_handler -
891 * @phy: This struct scic_sds_phy object which has received an event.
892 * @event_code: This is the event code which the phy object is to decode.
893 *
894 * This method is called when an event notification is received for the phy
895 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. -
896 * decode the event - link failure events restart the starting state machine -
897 * sata spinup hold events are ignored since they are expected - sata phy
898 * detected event change to the wait speed event - any other events log a
899 * warning message and set a failure status enum sci_status SCI_SUCCESS on a link
900 * failure event SCI_FAILURE on any unexpected event notifation
901 */
902static enum sci_status scic_sds_phy_starting_substate_await_sata_phy_event_handler(
903 struct scic_sds_phy *sci_phy, u32 event_code)
904{
905 u32 result = SCI_SUCCESS;
906
907 switch (scu_get_event_code(event_code)) {
908 case SCU_EVENT_LINK_FAILURE:
909 /* Link failure change state back to the starting state */
910 scic_sds_phy_restart_starting_state(sci_phy);
911 break;
912
913 case SCU_EVENT_SATA_SPINUP_HOLD:
914 /* These events might be received since we dont know how many may be in
915 * the completion queue while waiting for power
916 */
917 break;
918
919 case SCU_EVENT_SATA_PHY_DETECTED:
920 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
921
922 /* We have received the SATA PHY notification change state */
923 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
924 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN);
925 break;
926
927 case SCU_EVENT_SAS_PHY_DETECTED:
928 /* There has been a change in the phy type before OOB/SN for the
929 * SATA finished start down the SAS link traning path.
930 */
931 scic_sds_phy_start_sas_link_training(sci_phy);
932 break;
933
934 default:
935 dev_warn(sciphy_to_dev(sci_phy),
936 "%s: PHY starting substate machine received "
937 "unexpected event_code %x\n",
938 __func__,
939 event_code);
940
941 result = SCI_FAILURE;
942 break;
943 }
944
945 return result;
946}
947
948/**
949 *
950 * @phy: This struct scic_sds_phy object which has received an event.
951 * @event_code: This is the event code which the phy object is to decode.
952 *
953 * This method is called when an event notification is received for the phy
954 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN.
955 * - decode the event - sata phy detected returns us back to this state. -
956 * speed event detected causes a state transition to the wait for signature. -
957 * link failure events restart the starting state machine - any other events
958 * log a warning message and set a failure status enum sci_status SCI_SUCCESS on any
959 * valid event notification SCI_FAILURE on any unexpected event notifation
960 */
961static enum sci_status scic_sds_phy_starting_substate_await_sata_speed_event_handler(
962 struct scic_sds_phy *sci_phy,
963 u32 event_code)
964{
965 u32 result = SCI_SUCCESS;
966
967 switch (scu_get_event_code(event_code)) {
968 case SCU_EVENT_SATA_PHY_DETECTED:
969 /*
970 * The hardware reports multiple SATA PHY detected events
971 * ignore the extras */
972 break;
973
974 case SCU_EVENT_SATA_15:
975 case SCU_EVENT_SATA_15_SSC:
976 scic_sds_phy_complete_link_training(
977 sci_phy,
978 SAS_LINK_RATE_1_5_GBPS,
979 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
980 break;
981
982 case SCU_EVENT_SATA_30:
983 case SCU_EVENT_SATA_30_SSC:
984 scic_sds_phy_complete_link_training(
985 sci_phy,
986 SAS_LINK_RATE_3_0_GBPS,
987 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
988 break;
989
990 case SCU_EVENT_SATA_60:
991 case SCU_EVENT_SATA_60_SSC:
992 scic_sds_phy_complete_link_training(
993 sci_phy,
994 SAS_LINK_RATE_6_0_GBPS,
995 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
996 break;
997
998 case SCU_EVENT_LINK_FAILURE:
999 /* Link failure change state back to the starting state */
1000 scic_sds_phy_restart_starting_state(sci_phy);
1001 break;
1002
1003 case SCU_EVENT_SAS_PHY_DETECTED:
1004 /*
1005 * There has been a change in the phy type before OOB/SN for the
1006 * SATA finished start down the SAS link traning path. */
1007 scic_sds_phy_start_sas_link_training(sci_phy);
1008 break;
1009
1010 default:
1011 dev_warn(sciphy_to_dev(sci_phy),
1012 "%s: PHY starting substate machine received "
1013 "unexpected event_code %x\n",
1014 __func__,
1015 event_code);
1016
1017 result = SCI_FAILURE;
1018 break;
1019 }
1020
1021 return result;
1022}
1023
1024/**
1025 * scic_sds_phy_starting_substate_await_sig_fis_event_handler -
1026 * @phy: This struct scic_sds_phy object which has received an event.
1027 * @event_code: This is the event code which the phy object is to decode.
1028 *
1029 * This method is called when an event notification is received for the phy
1030 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. -
1031 * decode the event - sas phy detected event backs up the state machine to the
1032 * await speed notification. - identify timeout is an un-expected event and the
1033 * state machine is restarted. - link failure events restart the starting state
1034 * machine - any other events log a warning message and set a failure status
1035 * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any
1036 * unexpected event notifation
1037 */
1038static enum sci_status scic_sds_phy_starting_substate_await_sig_fis_event_handler(
1039 struct scic_sds_phy *sci_phy, u32 event_code)
1040{
1041 u32 result = SCI_SUCCESS;
1042
1043 switch (scu_get_event_code(event_code)) {
1044 case SCU_EVENT_SATA_PHY_DETECTED:
1045 /* Backup the state machine */
1046 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
1047 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN);
1048 break;
1049
1050 case SCU_EVENT_LINK_FAILURE:
1051 /* Link failure change state back to the starting state */
1052 scic_sds_phy_restart_starting_state(sci_phy);
1053 break;
1054
1055 default:
1056 dev_warn(sciphy_to_dev(sci_phy),
1057 "%s: PHY starting substate machine received "
1058 "unexpected event_code %x\n",
1059 __func__,
1060 event_code);
1061
1062 result = SCI_FAILURE;
1063 break;
1064 }
1065
1066 return result;
1067}
1068
1069
1070/*
1071 * *****************************************************************************
1072 * * SCIC SDS PHY FRAME_HANDLERS
1073 * ***************************************************************************** */
1074
1075/**
1076 *
1077 * @phy: This is struct scic_sds_phy object which is being requested to decode the
1078 * frame data.
1079 * @frame_index: This is the index of the unsolicited frame which was received
1080 * for this phy.
1081 *
1082 * This method decodes the unsolicited frame when the struct scic_sds_phy is in the
1083 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - Get the UF Header - If the UF
1084 * is an IAF - Copy IAF data to local phy object IAF data buffer. - Change
1085 * starting substate to wait power. - else - log warning message of unexpected
1086 * unsolicted frame - release frame buffer enum sci_status SCI_SUCCESS
1087 */
1088static enum sci_status scic_sds_phy_starting_substate_await_iaf_uf_frame_handler(
1089 struct scic_sds_phy *sci_phy, u32 frame_index)
1090{
1091 enum sci_status result;
1092 u32 *frame_words;
1093 struct sas_identify_frame iaf;
1094 struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
1095
1096 result = scic_sds_unsolicited_frame_control_get_header(
1097 &(scic_sds_phy_get_controller(sci_phy)->uf_control),
1098 frame_index,
1099 (void **)&frame_words);
1100
1101 if (result != SCI_SUCCESS)
1102 return result;
1103
1104 sci_swab32_cpy(&iaf, frame_words, sizeof(iaf) / sizeof(u32));
1105 if (iaf.frame_type == 0) {
1106 u32 state;
1107
1108 memcpy(&iphy->frame_rcvd.iaf, &iaf, sizeof(iaf));
1109 if (iaf.smp_tport) {
1110 /* We got the IAF for an expander PHY go to the final
1111 * state since there are no power requirements for
1112 * expander phys.
1113 */
1114 state = SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL;
1115 } else {
1116 /* We got the IAF we can now go to the await spinup
1117 * semaphore state
1118 */
1119 state = SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER;
1120 }
1121 sci_base_state_machine_change_state(
1122 &sci_phy->starting_substate_machine,
1123 state);
1124 result = SCI_SUCCESS;
1125 } else
1126 dev_warn(sciphy_to_dev(sci_phy),
1127 "%s: PHY starting substate machine received "
1128 "unexpected frame id %x\n",
1129 __func__,
1130 frame_index);
1131
1132 scic_sds_controller_release_frame(scic_sds_phy_get_controller(sci_phy),
1133 frame_index);
1134
1135 return result;
1136}
1137
1138/**
1139 *
1140 * @phy: This is struct scic_sds_phy object which is being requested to decode the
1141 * frame data.
1142 * @frame_index: This is the index of the unsolicited frame which was received
1143 * for this phy.
1144 *
1145 * This method decodes the unsolicited frame when the struct scic_sds_phy is in the
1146 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Get the UF Header - If
1147 * the UF is an SIGNATURE FIS - Copy IAF data to local phy object SIGNATURE FIS
1148 * data buffer. - else - log warning message of unexpected unsolicted frame -
1149 * release frame buffer enum sci_status SCI_SUCCESS Must decode the SIGNATURE FIS
1150 * data
1151 */
1152static enum sci_status scic_sds_phy_starting_substate_await_sig_fis_frame_handler(
1153 struct scic_sds_phy *sci_phy,
1154 u32 frame_index)
1155{
1156 enum sci_status result;
1157 struct dev_to_host_fis *frame_header;
1158 u32 *fis_frame_data;
1159 struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
1160
1161 result = scic_sds_unsolicited_frame_control_get_header(
1162 &(scic_sds_phy_get_controller(sci_phy)->uf_control),
1163 frame_index,
1164 (void **)&frame_header);
1165
1166 if (result != SCI_SUCCESS)
1167 return result;
1168
1169 if ((frame_header->fis_type == FIS_REGD2H) &&
1170 !(frame_header->status & ATA_BUSY)) {
1171 scic_sds_unsolicited_frame_control_get_buffer(
1172 &(scic_sds_phy_get_controller(sci_phy)->uf_control),
1173 frame_index,
1174 (void **)&fis_frame_data);
1175
1176 scic_sds_controller_copy_sata_response(&iphy->frame_rcvd.fis,
1177 frame_header,
1178 fis_frame_data);
1179
1180 /* got IAF we can now go to the await spinup semaphore state */
1181 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
1182 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL);
1183
1184 result = SCI_SUCCESS;
1185 } else
1186 dev_warn(sciphy_to_dev(sci_phy),
1187 "%s: PHY starting substate machine received "
1188 "unexpected frame id %x\n",
1189 __func__,
1190 frame_index);
1191
1192 /* Regardless of the result we are done with this frame with it */
1193 scic_sds_controller_release_frame(scic_sds_phy_get_controller(sci_phy),
1194 frame_index);
1195
1196 return result;
1197}
1198
1199/*
1200 * *****************************************************************************
1201 * * SCIC SDS PHY POWER_HANDLERS
1202 * ***************************************************************************** */
1203
1204/*
1205 * This method is called by the struct scic_sds_controller when the phy object is
1206 * granted power. - The notify enable spinups are turned on for this phy object
1207 * - The phy state machine is transitioned to the
1208 * SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. enum sci_status SCI_SUCCESS
1209 */
1210static enum sci_status scic_sds_phy_starting_substate_await_sas_power_consume_power_handler(
1211 struct scic_sds_phy *sci_phy)
1212{
1213 u32 enable_spinup;
1214
1215 enable_spinup = readl(&sci_phy->link_layer_registers->notify_enable_spinup_control);
1216 enable_spinup |= SCU_ENSPINUP_GEN_BIT(ENABLE);
1217 writel(enable_spinup, &sci_phy->link_layer_registers->notify_enable_spinup_control);
1218
1219 /* Change state to the final state this substate machine has run to completion */
1220 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
1221 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL);
1222
1223 return SCI_SUCCESS;
1224}
1225
1226/*
1227 * This method is called by the struct scic_sds_controller when the phy object is
1228 * granted power. - The phy state machine is transitioned to the
1229 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. enum sci_status SCI_SUCCESS
1230 */
1231static enum sci_status scic_sds_phy_starting_substate_await_sata_power_consume_power_handler(
1232 struct scic_sds_phy *sci_phy)
1233{
1234 u32 scu_sas_pcfg_value;
1235
1236 /* Release the spinup hold state and reset the OOB state machine */
1237 scu_sas_pcfg_value =
1238 readl(&sci_phy->link_layer_registers->phy_configuration);
1239 scu_sas_pcfg_value &=
1240 ~(SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD) | SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE));
1241 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
1242 writel(scu_sas_pcfg_value,
1243 &sci_phy->link_layer_registers->phy_configuration);
1244
1245 /* Now restart the OOB operation */
1246 scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
1247 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
1248 writel(scu_sas_pcfg_value,
1249 &sci_phy->link_layer_registers->phy_configuration);
1250
1251 /* Change state to the final state this substate machine has run to completion */
1252 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
1253 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN);
1254
1255 return SCI_SUCCESS;
1256}
1257
1258static enum sci_status default_phy_handler(struct scic_sds_phy *sci_phy,
1259 const char *func)
1260{
1261 dev_dbg(sciphy_to_dev(sci_phy),
1262 "%s: in wrong state: %d\n", func,
1263 sci_base_state_machine_get_state(&sci_phy->state_machine));
1264 return SCI_FAILURE_INVALID_STATE;
1265}
1266
1267static enum sci_status
1268scic_sds_phy_default_start_handler(struct scic_sds_phy *sci_phy)
1269{
1270 return default_phy_handler(sci_phy, __func__);
1271}
1272
1273static enum sci_status
1274scic_sds_phy_default_stop_handler(struct scic_sds_phy *sci_phy)
1275{
1276 return default_phy_handler(sci_phy, __func__);
1277}
1278
1279static enum sci_status
1280scic_sds_phy_default_reset_handler(struct scic_sds_phy *sci_phy)
1281{
1282 return default_phy_handler(sci_phy, __func__);
1283}
1284
1285static enum sci_status
1286scic_sds_phy_default_destroy_handler(struct scic_sds_phy *sci_phy)
1287{
1288 return default_phy_handler(sci_phy, __func__);
1289}
1290
1291static enum sci_status
1292scic_sds_phy_default_frame_handler(struct scic_sds_phy *sci_phy,
1293 u32 frame_index)
1294{
1295 struct scic_sds_controller *scic = scic_sds_phy_get_controller(sci_phy);
1296
1297 default_phy_handler(sci_phy, __func__);
1298 scic_sds_controller_release_frame(scic, frame_index);
1299
1300 return SCI_FAILURE_INVALID_STATE;
1301}
1302
1303static enum sci_status
1304scic_sds_phy_default_event_handler(struct scic_sds_phy *sci_phy,
1305 u32 event_code)
1306{
1307 return default_phy_handler(sci_phy, __func__);
1308}
1309
1310static enum sci_status
1311scic_sds_phy_default_consume_power_handler(struct scic_sds_phy *sci_phy)
1312{
1313 return default_phy_handler(sci_phy, __func__);
1314}
1315
1316
1317
1318static const struct scic_sds_phy_state_handler scic_sds_phy_starting_substate_handler_table[] = {
1319 [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL] = {
1320 .start_handler = scic_sds_phy_default_start_handler,
1321 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1322 .reset_handler = scic_sds_phy_default_reset_handler,
1323 .destruct_handler = scic_sds_phy_default_destroy_handler,
1324 .frame_handler = scic_sds_phy_default_frame_handler,
1325 .event_handler = scic_sds_phy_default_event_handler,
1326 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1327 },
1328 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN] = {
1329 .start_handler = scic_sds_phy_default_start_handler,
1330 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1331 .reset_handler = scic_sds_phy_default_reset_handler,
1332 .destruct_handler = scic_sds_phy_default_destroy_handler,
1333 .frame_handler = scic_sds_phy_default_frame_handler,
1334 .event_handler = scic_sds_phy_starting_substate_await_ossp_event_handler,
1335 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1336 },
1337 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN] = {
1338 .start_handler = scic_sds_phy_default_start_handler,
1339 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1340 .reset_handler = scic_sds_phy_default_reset_handler,
1341 .destruct_handler = scic_sds_phy_default_destroy_handler,
1342 .frame_handler = scic_sds_phy_default_frame_handler,
1343 .event_handler = scic_sds_phy_starting_substate_await_sas_phy_speed_event_handler,
1344 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1345 },
1346 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF] = {
1347 .start_handler = scic_sds_phy_default_start_handler,
1348 .stop_handler = scic_sds_phy_default_stop_handler,
1349 .reset_handler = scic_sds_phy_default_reset_handler,
1350 .destruct_handler = scic_sds_phy_default_destroy_handler,
1351 .frame_handler = scic_sds_phy_starting_substate_await_iaf_uf_frame_handler,
1352 .event_handler = scic_sds_phy_starting_substate_await_iaf_uf_event_handler,
1353 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1354 },
1355 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER] = {
1356 .start_handler = scic_sds_phy_default_start_handler,
1357 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1358 .reset_handler = scic_sds_phy_default_reset_handler,
1359 .destruct_handler = scic_sds_phy_default_destroy_handler,
1360 .frame_handler = scic_sds_phy_default_frame_handler,
1361 .event_handler = scic_sds_phy_starting_substate_await_sas_power_event_handler,
1362 .consume_power_handler = scic_sds_phy_starting_substate_await_sas_power_consume_power_handler
1363 },
1364 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER] = {
1365 .start_handler = scic_sds_phy_default_start_handler,
1366 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1367 .reset_handler = scic_sds_phy_default_reset_handler,
1368 .destruct_handler = scic_sds_phy_default_destroy_handler,
1369 .frame_handler = scic_sds_phy_default_frame_handler,
1370 .event_handler = scic_sds_phy_starting_substate_await_sata_power_event_handler,
1371 .consume_power_handler = scic_sds_phy_starting_substate_await_sata_power_consume_power_handler
1372 },
1373 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN] = {
1374 .start_handler = scic_sds_phy_default_start_handler,
1375 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1376 .reset_handler = scic_sds_phy_default_reset_handler,
1377 .destruct_handler = scic_sds_phy_default_destroy_handler,
1378 .frame_handler = scic_sds_phy_default_frame_handler,
1379 .event_handler = scic_sds_phy_starting_substate_await_sata_phy_event_handler,
1380 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1381 },
1382 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN] = {
1383 .start_handler = scic_sds_phy_default_start_handler,
1384 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1385 .reset_handler = scic_sds_phy_default_reset_handler,
1386 .destruct_handler = scic_sds_phy_default_destroy_handler,
1387 .frame_handler = scic_sds_phy_default_frame_handler,
1388 .event_handler = scic_sds_phy_starting_substate_await_sata_speed_event_handler,
1389 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1390 },
1391 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF] = {
1392 .start_handler = scic_sds_phy_default_start_handler,
1393 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1394 .reset_handler = scic_sds_phy_default_reset_handler,
1395 .destruct_handler = scic_sds_phy_default_destroy_handler,
1396 .frame_handler = scic_sds_phy_starting_substate_await_sig_fis_frame_handler,
1397 .event_handler = scic_sds_phy_starting_substate_await_sig_fis_event_handler,
1398 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1399 },
1400 [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL] = {
1401 .start_handler = scic_sds_phy_default_start_handler,
1402 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1403 .reset_handler = scic_sds_phy_default_reset_handler,
1404 .destruct_handler = scic_sds_phy_default_destroy_handler,
1405 .frame_handler = scic_sds_phy_default_frame_handler,
1406 .event_handler = scic_sds_phy_default_event_handler,
1407 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1408 }
1409};
1410
1411/**
1412 * scic_sds_phy_set_starting_substate_handlers() -
1413 *
1414 * This macro sets the starting substate handlers by state_id
1415 */
1416#define scic_sds_phy_set_starting_substate_handlers(phy, state_id) \
1417 scic_sds_phy_set_state_handlers(\
1418 (phy), \
1419 &scic_sds_phy_starting_substate_handler_table[(state_id)] \
1420 )
1421
1422/*
1423 * ****************************************************************************
1424 * * PHY STARTING SUBSTATE METHODS
1425 * **************************************************************************** */
1426
1427/**
1428 * scic_sds_phy_starting_initial_substate_enter -
1429 * @object: This is the object which is cast to a struct scic_sds_phy object.
1430 *
1431 * This method will perform the actions required by the struct scic_sds_phy on
1432 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL. - The initial state
1433 * handlers are put in place for the struct scic_sds_phy object. - The state is
1434 * changed to the wait phy type event notification. none
1435 */
1436static void scic_sds_phy_starting_initial_substate_enter(void *object)
1437{
1438 struct scic_sds_phy *sci_phy = object;
1439
1440 scic_sds_phy_set_starting_substate_handlers(
1441 sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL);
1442
1443 /* This is just an temporary state go off to the starting state */
1444 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
1445 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN);
1446}
1447
1448/**
1449 *
1450 * @object: This is the object which is cast to a struct scic_sds_phy object.
1451 *
1452 * This method will perform the actions required by the struct scic_sds_phy on
1453 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_PHY_TYPE_EN. - Set the
1454 * struct scic_sds_phy object state handlers for this state. none
1455 */
1456static void scic_sds_phy_starting_await_ossp_en_substate_enter(void *object)
1457{
1458 struct scic_sds_phy *sci_phy = object;
1459
1460 scic_sds_phy_set_starting_substate_handlers(
1461 sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
1462 );
1463}
1464
1465/**
1466 *
1467 * @object: This is the object which is cast to a struct scic_sds_phy object.
1468 *
1469 * This method will perform the actions required by the struct scic_sds_phy on
1470 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. - Set the
1471 * struct scic_sds_phy object state handlers for this state. none
1472 */
1473static void scic_sds_phy_starting_await_sas_speed_en_substate_enter(
1474 void *object)
1475{
1476 struct scic_sds_phy *sci_phy = object;
1477
1478 scic_sds_phy_set_starting_substate_handlers(
1479 sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
1480 );
1481}
1482
1483/**
1484 *
1485 * @object: This is the object which is cast to a struct scic_sds_phy object.
1486 *
1487 * This method will perform the actions required by the struct scic_sds_phy on
1488 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - Set the
1489 * struct scic_sds_phy object state handlers for this state. none
1490 */
1491static void scic_sds_phy_starting_await_iaf_uf_substate_enter(void *object)
1492{
1493 struct scic_sds_phy *sci_phy = object;
1494
1495 scic_sds_phy_set_starting_substate_handlers(
1496 sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
1497 );
1498}
1499
1500/**
1501 *
1502 * @object: This is the object which is cast to a struct scic_sds_phy object.
1503 *
1504 * This method will perform the actions required by the struct scic_sds_phy on
1505 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Set the
1506 * struct scic_sds_phy object state handlers for this state. - Add this phy object to
1507 * the power control queue none
1508 */
1509static void scic_sds_phy_starting_await_sas_power_substate_enter(void *object)
1510{
1511 struct scic_sds_phy *sci_phy = object;
1512
1513 scic_sds_phy_set_starting_substate_handlers(
1514 sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
1515 );
1516
1517 scic_sds_controller_power_control_queue_insert(
1518 scic_sds_phy_get_controller(sci_phy),
1519 sci_phy
1520 );
1521}
1522
1523/**
1524 *
1525 * @object: This is the object which is cast to a struct scic_sds_phy object.
1526 *
1527 * This method will perform the actions required by the struct scic_sds_phy on exiting
1528 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Remove the
1529 * struct scic_sds_phy object from the power control queue. none
1530 */
1531static void scic_sds_phy_starting_await_sas_power_substate_exit(void *object)
1532{
1533 struct scic_sds_phy *sci_phy = object;
1534
1535 scic_sds_controller_power_control_queue_remove(
1536 scic_sds_phy_get_controller(sci_phy), sci_phy
1537 );
1538}
1539
1540/**
1541 *
1542 * @object: This is the object which is cast to a struct scic_sds_phy object.
1543 *
1544 * This method will perform the actions required by the struct scic_sds_phy on
1545 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Set the
1546 * struct scic_sds_phy object state handlers for this state. - Add this phy object to
1547 * the power control queue none
1548 */
1549static void scic_sds_phy_starting_await_sata_power_substate_enter(void *object)
1550{
1551 struct scic_sds_phy *sci_phy = object;
1552
1553 scic_sds_phy_set_starting_substate_handlers(
1554 sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
1555 );
1556
1557 scic_sds_controller_power_control_queue_insert(
1558 scic_sds_phy_get_controller(sci_phy),
1559 sci_phy
1560 );
1561}
1562
1563/**
1564 *
1565 * @object: This is the object which is cast to a struct scic_sds_phy object.
1566 *
1567 * This method will perform the actions required by the struct scic_sds_phy on exiting
1568 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Remove the
1569 * struct scic_sds_phy object from the power control queue. none
1570 */
1571static void scic_sds_phy_starting_await_sata_power_substate_exit(void *object)
1572{
1573 struct scic_sds_phy *sci_phy = object;
1574
1575 scic_sds_controller_power_control_queue_remove(
1576 scic_sds_phy_get_controller(sci_phy),
1577 sci_phy
1578 );
1579}
1580
1581/**
1582 *
1583 * @object: This is the object which is cast to a struct scic_sds_phy object.
1584 *
1585 * This function will perform the actions required by the struct scic_sds_phy on
1586 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. - Set the
1587 * struct scic_sds_phy object state handlers for this state. none
1588 */
1589static void scic_sds_phy_starting_await_sata_phy_substate_enter(void *object)
1590{
1591 struct scic_sds_phy *sci_phy = object;
1592
1593 scic_sds_phy_set_starting_substate_handlers(
1594 sci_phy,
1595 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN);
1596
1597 isci_timer_start(sci_phy->sata_timeout_timer,
1598 SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
1599}
1600
1601/**
1602 *
1603 * @object: This is the object which is cast to a struct scic_sds_phy object.
1604 *
1605 * This method will perform the actions required by the struct scic_sds_phy
1606 * on exiting
1607 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
1608 * that was started on entry to await sata phy event notification none
1609 */
1610static inline void scic_sds_phy_starting_await_sata_phy_substate_exit(
1611 void *object)
1612{
1613 struct scic_sds_phy *sci_phy = object;
1614
1615 isci_timer_stop(sci_phy->sata_timeout_timer);
1616}
1617
1618/**
1619 *
1620 * @object: This is the object which is cast to a struct scic_sds_phy object.
1621 *
1622 * This method will perform the actions required by the struct scic_sds_phy on
1623 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - Set the
1624 * struct scic_sds_phy object state handlers for this state. none
1625 */
1626static void scic_sds_phy_starting_await_sata_speed_substate_enter(void *object)
1627{
1628 struct scic_sds_phy *sci_phy = object;
1629
1630 scic_sds_phy_set_starting_substate_handlers(
1631 sci_phy,
1632 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN);
1633
1634 isci_timer_start(sci_phy->sata_timeout_timer,
1635 SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
1636}
1637
1638/**
1639 *
1640 * @object: This is the object which is cast to a struct scic_sds_phy object.
1641 *
1642 * This function will perform the actions required by the
1643 * struct scic_sds_phy on exiting
1644 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
1645 * that was started on entry to await sata phy event notification none
1646 */
1647static inline void scic_sds_phy_starting_await_sata_speed_substate_exit(
1648 void *object)
1649{
1650 struct scic_sds_phy *sci_phy = object;
1651
1652 isci_timer_stop(sci_phy->sata_timeout_timer);
1653}
1654
1655/**
1656 *
1657 * @object: This is the object which is cast to a struct scic_sds_phy object.
1658 *
1659 * This function will perform the actions required by the struct scic_sds_phy on
1660 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Set the
1661 * struct scic_sds_phy object state handlers for this state.
1662 * - Start the SIGNATURE FIS
1663 * timeout timer none
1664 */
1665static void scic_sds_phy_starting_await_sig_fis_uf_substate_enter(void *object)
1666{
1667 bool continue_to_ready_state;
1668 struct scic_sds_phy *sci_phy = object;
1669
1670 scic_sds_phy_set_starting_substate_handlers(
1671 sci_phy,
1672 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
1673
1674 continue_to_ready_state = scic_sds_port_link_detected(
1675 sci_phy->owning_port,
1676 sci_phy);
1677
1678 if (continue_to_ready_state) {
1679 /*
1680 * Clear the PE suspend condition so we can actually
1681 * receive SIG FIS
1682 * The hardware will not respond to the XRDY until the PE
1683 * suspend condition is cleared.
1684 */
1685 scic_sds_phy_resume(sci_phy);
1686
1687 isci_timer_start(sci_phy->sata_timeout_timer,
1688 SCIC_SDS_SIGNATURE_FIS_TIMEOUT);
1689 } else
1690 sci_phy->is_in_link_training = false;
1691}
1692
1693/**
1694 *
1695 * @object: This is the object which is cast to a struct scic_sds_phy object.
1696 *
1697 * This function will perform the actions required by the
1698 * struct scic_sds_phy on exiting
1699 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Stop the SIGNATURE
1700 * FIS timeout timer. none
1701 */
1702static inline void scic_sds_phy_starting_await_sig_fis_uf_substate_exit(
1703 void *object)
1704{
1705 struct scic_sds_phy *sci_phy = object;
1706
1707 isci_timer_stop(sci_phy->sata_timeout_timer);
1708}
1709
1710/**
1711 *
1712 * @object: This is the object which is cast to a struct scic_sds_phy object.
1713 *
1714 * This method will perform the actions required by the struct scic_sds_phy on
1715 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. - Set the struct scic_sds_phy
1716 * object state handlers for this state. - Change base state machine to the
1717 * ready state. none
1718 */
1719static void scic_sds_phy_starting_final_substate_enter(void *object)
1720{
1721 struct scic_sds_phy *sci_phy = object;
1722
1723 scic_sds_phy_set_starting_substate_handlers(sci_phy,
1724 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL);
1725
1726 /* State machine has run to completion so exit out and change
1727 * the base state machine to the ready state
1728 */
1729 sci_base_state_machine_change_state(&sci_phy->state_machine,
1730 SCI_BASE_PHY_STATE_READY);
1731}
1732
1733/* --------------------------------------------------------------------------- */
1734
1735static const struct sci_base_state scic_sds_phy_starting_substates[] = {
1736 [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL] = {
1737 .enter_state = scic_sds_phy_starting_initial_substate_enter,
1738 },
1739 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN] = {
1740 .enter_state = scic_sds_phy_starting_await_ossp_en_substate_enter,
1741 },
1742 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN] = {
1743 .enter_state = scic_sds_phy_starting_await_sas_speed_en_substate_enter,
1744 },
1745 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF] = {
1746 .enter_state = scic_sds_phy_starting_await_iaf_uf_substate_enter,
1747 },
1748 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER] = {
1749 .enter_state = scic_sds_phy_starting_await_sas_power_substate_enter,
1750 .exit_state = scic_sds_phy_starting_await_sas_power_substate_exit,
1751 },
1752 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER] = {
1753 .enter_state = scic_sds_phy_starting_await_sata_power_substate_enter,
1754 .exit_state = scic_sds_phy_starting_await_sata_power_substate_exit
1755 },
1756 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN] = {
1757 .enter_state = scic_sds_phy_starting_await_sata_phy_substate_enter,
1758 .exit_state = scic_sds_phy_starting_await_sata_phy_substate_exit
1759 },
1760 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN] = {
1761 .enter_state = scic_sds_phy_starting_await_sata_speed_substate_enter,
1762 .exit_state = scic_sds_phy_starting_await_sata_speed_substate_exit
1763 },
1764 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF] = {
1765 .enter_state = scic_sds_phy_starting_await_sig_fis_uf_substate_enter,
1766 .exit_state = scic_sds_phy_starting_await_sig_fis_uf_substate_exit
1767 },
1768 [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL] = {
1769 .enter_state = scic_sds_phy_starting_final_substate_enter,
1770 }
1771};
1772
1773/*
1774 * This method takes the struct scic_sds_phy from a stopped state and
1775 * attempts to start it. - The phy state machine is transitioned to the
1776 * SCI_BASE_PHY_STATE_STARTING. enum sci_status SCI_SUCCESS
1777 */
1778static enum sci_status
1779scic_sds_phy_stopped_state_start_handler(struct scic_sds_phy *sci_phy)
1780{
1781 struct isci_host *ihost;
1782 struct scic_sds_controller *scic;
1783
1784 scic = scic_sds_phy_get_controller(sci_phy),
1785 ihost = scic_to_ihost(scic);
1786
1787 /* Create the SIGNATURE FIS Timeout timer for this phy */
1788 sci_phy->sata_timeout_timer = isci_timer_create(ihost, sci_phy,
1789 scic_sds_phy_sata_timeout);
1790
1791 if (sci_phy->sata_timeout_timer)
1792 sci_base_state_machine_change_state(&sci_phy->state_machine,
1793 SCI_BASE_PHY_STATE_STARTING);
1794
1795 return SCI_SUCCESS;
1796}
1797
1798static enum sci_status
1799scic_sds_phy_stopped_state_destroy_handler(struct scic_sds_phy *sci_phy)
1800{
1801 return SCI_SUCCESS;
1802}
1803
1804static enum sci_status
1805scic_sds_phy_ready_state_stop_handler(struct scic_sds_phy *sci_phy)
1806{
1807 sci_base_state_machine_change_state(&sci_phy->state_machine,
1808 SCI_BASE_PHY_STATE_STOPPED);
1809
1810 return SCI_SUCCESS;
1811}
1812
1813static enum sci_status
1814scic_sds_phy_ready_state_reset_handler(struct scic_sds_phy *sci_phy)
1815{
1816 sci_base_state_machine_change_state(&sci_phy->state_machine,
1817 SCI_BASE_PHY_STATE_RESETTING);
1818
1819 return SCI_SUCCESS;
1820}
1821
1822/**
1823 * scic_sds_phy_ready_state_event_handler -
1824 * @phy: This is the struct scic_sds_phy object which has received the event.
1825 *
1826 * This method request the struct scic_sds_phy handle the received event. The only
1827 * event that we are interested in while in the ready state is the link failure
1828 * event. - decoded event is a link failure - transition the struct scic_sds_phy back
1829 * to the SCI_BASE_PHY_STATE_STARTING state. - any other event received will
1830 * report a warning message enum sci_status SCI_SUCCESS if the event received is a
1831 * link failure SCI_FAILURE_INVALID_STATE for any other event received.
1832 */
1833static enum sci_status scic_sds_phy_ready_state_event_handler(struct scic_sds_phy *sci_phy,
1834 u32 event_code)
1835{
1836 enum sci_status result = SCI_FAILURE;
1837
1838 switch (scu_get_event_code(event_code)) {
1839 case SCU_EVENT_LINK_FAILURE:
1840 /* Link failure change state back to the starting state */
1841 sci_base_state_machine_change_state(&sci_phy->state_machine,
1842 SCI_BASE_PHY_STATE_STARTING);
1843 result = SCI_SUCCESS;
1844 break;
1845
1846 case SCU_EVENT_BROADCAST_CHANGE:
1847 /* Broadcast change received. Notify the port. */
1848 if (scic_sds_phy_get_port(sci_phy) != NULL)
1849 scic_sds_port_broadcast_change_received(sci_phy->owning_port, sci_phy);
1850 else
1851 sci_phy->bcn_received_while_port_unassigned = true;
1852 break;
1853
1854 default:
1855 dev_warn(sciphy_to_dev(sci_phy),
1856 "%sP SCIC PHY 0x%p ready state machine received "
1857 "unexpected event_code %x\n",
1858 __func__, sci_phy, event_code);
1859
1860 result = SCI_FAILURE_INVALID_STATE;
1861 break;
1862 }
1863
1864 return result;
1865}
1866
1867static enum sci_status scic_sds_phy_resetting_state_event_handler(struct scic_sds_phy *sci_phy,
1868 u32 event_code)
1869{
1870 enum sci_status result = SCI_FAILURE;
1871
1872 switch (scu_get_event_code(event_code)) {
1873 case SCU_EVENT_HARD_RESET_TRANSMITTED:
1874 /* Link failure change state back to the starting state */
1875 sci_base_state_machine_change_state(&sci_phy->state_machine,
1876 SCI_BASE_PHY_STATE_STARTING);
1877 result = SCI_SUCCESS;
1878 break;
1879
1880 default:
1881 dev_warn(sciphy_to_dev(sci_phy),
1882 "%s: SCIC PHY 0x%p resetting state machine received "
1883 "unexpected event_code %x\n",
1884 __func__, sci_phy, event_code);
1885
1886 result = SCI_FAILURE_INVALID_STATE;
1887 break;
1888 }
1889
1890 return result;
1891}
1892
1893/* --------------------------------------------------------------------------- */
1894
1895static const struct scic_sds_phy_state_handler scic_sds_phy_state_handler_table[] = {
1896 [SCI_BASE_PHY_STATE_INITIAL] = {
1897 .start_handler = scic_sds_phy_default_start_handler,
1898 .stop_handler = scic_sds_phy_default_stop_handler,
1899 .reset_handler = scic_sds_phy_default_reset_handler,
1900 .destruct_handler = scic_sds_phy_default_destroy_handler,
1901 .frame_handler = scic_sds_phy_default_frame_handler,
1902 .event_handler = scic_sds_phy_default_event_handler,
1903 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1904 },
1905 [SCI_BASE_PHY_STATE_STOPPED] = {
1906 .start_handler = scic_sds_phy_stopped_state_start_handler,
1907 .stop_handler = scic_sds_phy_default_stop_handler,
1908 .reset_handler = scic_sds_phy_default_reset_handler,
1909 .destruct_handler = scic_sds_phy_stopped_state_destroy_handler,
1910 .frame_handler = scic_sds_phy_default_frame_handler,
1911 .event_handler = scic_sds_phy_default_event_handler,
1912 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1913 },
1914 [SCI_BASE_PHY_STATE_STARTING] = {
1915 .start_handler = scic_sds_phy_default_start_handler,
1916 .stop_handler = scic_sds_phy_default_stop_handler,
1917 .reset_handler = scic_sds_phy_default_reset_handler,
1918 .destruct_handler = scic_sds_phy_default_destroy_handler,
1919 .frame_handler = scic_sds_phy_default_frame_handler,
1920 .event_handler = scic_sds_phy_default_event_handler,
1921 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1922 },
1923 [SCI_BASE_PHY_STATE_READY] = {
1924 .start_handler = scic_sds_phy_default_start_handler,
1925 .stop_handler = scic_sds_phy_ready_state_stop_handler,
1926 .reset_handler = scic_sds_phy_ready_state_reset_handler,
1927 .destruct_handler = scic_sds_phy_default_destroy_handler,
1928 .frame_handler = scic_sds_phy_default_frame_handler,
1929 .event_handler = scic_sds_phy_ready_state_event_handler,
1930 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1931 },
1932 [SCI_BASE_PHY_STATE_RESETTING] = {
1933 .start_handler = scic_sds_phy_default_start_handler,
1934 .stop_handler = scic_sds_phy_default_stop_handler,
1935 .reset_handler = scic_sds_phy_default_reset_handler,
1936 .destruct_handler = scic_sds_phy_default_destroy_handler,
1937 .frame_handler = scic_sds_phy_default_frame_handler,
1938 .event_handler = scic_sds_phy_resetting_state_event_handler,
1939 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1940 },
1941 [SCI_BASE_PHY_STATE_FINAL] = {
1942 .start_handler = scic_sds_phy_default_start_handler,
1943 .stop_handler = scic_sds_phy_default_stop_handler,
1944 .reset_handler = scic_sds_phy_default_reset_handler,
1945 .destruct_handler = scic_sds_phy_default_destroy_handler,
1946 .frame_handler = scic_sds_phy_default_frame_handler,
1947 .event_handler = scic_sds_phy_default_event_handler,
1948 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1949 }
1950};
1951
1952/*
1953 * ****************************************************************************
1954 * * PHY STATE PRIVATE METHODS
1955 * **************************************************************************** */
1956
1957/**
1958 *
1959 * @sci_phy: This is the struct scic_sds_phy object to stop.
1960 *
1961 * This method will stop the struct scic_sds_phy object. This does not reset the
1962 * protocol engine it just suspends it and places it in a state where it will
1963 * not cause the end device to power up. none
1964 */
1965static void scu_link_layer_stop_protocol_engine(
1966 struct scic_sds_phy *sci_phy)
1967{
1968 u32 scu_sas_pcfg_value;
1969 u32 enable_spinup_value;
1970
1971 /* Suspend the protocol engine and place it in a sata spinup hold state */
1972 scu_sas_pcfg_value =
1973 readl(&sci_phy->link_layer_registers->phy_configuration);
1974 scu_sas_pcfg_value |=
1975 (SCU_SAS_PCFG_GEN_BIT(OOB_RESET) |
1976 SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE) |
1977 SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD));
1978 writel(scu_sas_pcfg_value,
1979 &sci_phy->link_layer_registers->phy_configuration);
1980
1981 /* Disable the notify enable spinup primitives */
1982 enable_spinup_value = readl(&sci_phy->link_layer_registers->notify_enable_spinup_control);
1983 enable_spinup_value &= ~SCU_ENSPINUP_GEN_BIT(ENABLE);
1984 writel(enable_spinup_value, &sci_phy->link_layer_registers->notify_enable_spinup_control);
1985}
1986
1987/**
1988 *
1989 *
1990 * This method will start the OOB/SN state machine for this struct scic_sds_phy object.
1991 */
1992static void scu_link_layer_start_oob(
1993 struct scic_sds_phy *sci_phy)
1994{
1995 u32 scu_sas_pcfg_value;
1996
1997 scu_sas_pcfg_value =
1998 readl(&sci_phy->link_layer_registers->phy_configuration);
1999 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
2000 scu_sas_pcfg_value &=
2001 ~(SCU_SAS_PCFG_GEN_BIT(OOB_RESET) |
2002 SCU_SAS_PCFG_GEN_BIT(HARD_RESET));
2003 writel(scu_sas_pcfg_value,
2004 &sci_phy->link_layer_registers->phy_configuration);
2005}
2006
2007/**
2008 *
2009 *
2010 * This method will transmit a hard reset request on the specified phy. The SCU
2011 * hardware requires that we reset the OOB state machine and set the hard reset
2012 * bit in the phy configuration register. We then must start OOB over with the
2013 * hard reset bit set.
2014 */
2015static void scu_link_layer_tx_hard_reset(
2016 struct scic_sds_phy *sci_phy)
2017{
2018 u32 phy_configuration_value;
2019
2020 /*
2021 * SAS Phys must wait for the HARD_RESET_TX event notification to transition
2022 * to the starting state. */
2023 phy_configuration_value =
2024 readl(&sci_phy->link_layer_registers->phy_configuration);
2025 phy_configuration_value |=
2026 (SCU_SAS_PCFG_GEN_BIT(HARD_RESET) |
2027 SCU_SAS_PCFG_GEN_BIT(OOB_RESET));
2028 writel(phy_configuration_value,
2029 &sci_phy->link_layer_registers->phy_configuration);
2030
2031 /* Now take the OOB state machine out of reset */
2032 phy_configuration_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
2033 phy_configuration_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
2034 writel(phy_configuration_value,
2035 &sci_phy->link_layer_registers->phy_configuration);
2036}
2037
2038/*
2039 * ****************************************************************************
2040 * * PHY BASE STATE METHODS
2041 * **************************************************************************** */
2042
2043/**
2044 *
2045 * @object: This is the object which is cast to a struct scic_sds_phy object.
2046 *
2047 * This method will perform the actions required by the struct scic_sds_phy on
2048 * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
2049 * handlers for the phy object base state machine initial state. none
2050 */
2051static void scic_sds_phy_initial_state_enter(void *object)
2052{
2053 struct scic_sds_phy *sci_phy = object;
2054
2055 scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_INITIAL);
2056}
2057
2058/**
2059 *
2060 * @object: This is the object which is cast to a struct scic_sds_phy object.
2061 *
2062 * This function will perform the actions required by the struct scic_sds_phy on
2063 * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
2064 * handlers for the phy object base state machine initial state. - The SCU
2065 * hardware is requested to stop the protocol engine. none
2066 */
2067static void scic_sds_phy_stopped_state_enter(void *object)
2068{
2069 struct scic_sds_phy *sci_phy = object;
2070 struct scic_sds_controller *scic = scic_sds_phy_get_controller(sci_phy);
2071 struct isci_host *ihost = scic_to_ihost(scic);
2072
2073 /*
2074 * @todo We need to get to the controller to place this PE in a
2075 * reset state
2076 */
2077
2078 scic_sds_phy_set_base_state_handlers(sci_phy,
2079 SCI_BASE_PHY_STATE_STOPPED);
2080
2081 if (sci_phy->sata_timeout_timer != NULL) {
2082 isci_del_timer(ihost, sci_phy->sata_timeout_timer);
2083
2084 sci_phy->sata_timeout_timer = NULL;
2085 }
2086
2087 scu_link_layer_stop_protocol_engine(sci_phy);
2088
2089 if (sci_phy->state_machine.previous_state_id !=
2090 SCI_BASE_PHY_STATE_INITIAL)
2091 scic_sds_controller_link_down(
2092 scic_sds_phy_get_controller(sci_phy),
2093 scic_sds_phy_get_port(sci_phy),
2094 sci_phy);
2095}
2096
2097/**
2098 *
2099 * @object: This is the object which is cast to a struct scic_sds_phy object.
2100 *
2101 * This method will perform the actions required by the struct scic_sds_phy on
2102 * entering the SCI_BASE_PHY_STATE_STARTING. - This function sets the state
2103 * handlers for the phy object base state machine starting state. - The SCU
2104 * hardware is requested to start OOB/SN on this protocl engine. - The phy
2105 * starting substate machine is started. - If the previous state was the ready
2106 * state then the struct scic_sds_controller is informed that the phy has gone link
2107 * down. none
2108 */
2109static void scic_sds_phy_starting_state_enter(void *object)
2110{
2111 struct scic_sds_phy *sci_phy = object;
2112
2113 scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_STARTING);
2114
2115 scu_link_layer_stop_protocol_engine(sci_phy);
2116 scu_link_layer_start_oob(sci_phy);
2117
2118 /* We don't know what kind of phy we are going to be just yet */
2119 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
2120 sci_phy->bcn_received_while_port_unassigned = false;
2121
2122 /* Change over to the starting substate machine to continue */
2123 sci_base_state_machine_start(&sci_phy->starting_substate_machine);
2124
2125 if (sci_phy->state_machine.previous_state_id
2126 == SCI_BASE_PHY_STATE_READY) {
2127 scic_sds_controller_link_down(
2128 scic_sds_phy_get_controller(sci_phy),
2129 scic_sds_phy_get_port(sci_phy),
2130 sci_phy
2131 );
2132 }
2133}
2134
2135/**
2136 *
2137 * @object: This is the object which is cast to a struct scic_sds_phy object.
2138 *
2139 * This method will perform the actions required by the struct scic_sds_phy on
2140 * entering the SCI_BASE_PHY_STATE_READY. - This function sets the state
2141 * handlers for the phy object base state machine ready state. - The SCU
2142 * hardware protocol engine is resumed. - The struct scic_sds_controller is informed
2143 * that the phy object has gone link up. none
2144 */
2145static void scic_sds_phy_ready_state_enter(void *object)
2146{
2147 struct scic_sds_phy *sci_phy = object;
2148
2149 scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_READY);
2150
2151 scic_sds_controller_link_up(
2152 scic_sds_phy_get_controller(sci_phy),
2153 scic_sds_phy_get_port(sci_phy),
2154 sci_phy
2155 );
2156}
2157
2158/**
2159 *
2160 * @object: This is the object which is cast to a struct scic_sds_phy object.
2161 *
2162 * This method will perform the actions required by the struct scic_sds_phy on exiting
2163 * the SCI_BASE_PHY_STATE_INITIAL. This function suspends the SCU hardware
2164 * protocol engine represented by this struct scic_sds_phy object. none
2165 */
2166static void scic_sds_phy_ready_state_exit(void *object)
2167{
2168 struct scic_sds_phy *sci_phy = object;
2169
2170 scic_sds_phy_suspend(sci_phy);
2171}
2172
2173/**
2174 *
2175 * @object: This is the object which is cast to a struct scic_sds_phy object.
2176 *
2177 * This method will perform the actions required by the struct scic_sds_phy on
2178 * entering the SCI_BASE_PHY_STATE_RESETTING. - This function sets the state
2179 * handlers for the phy object base state machine resetting state. none
2180 */
2181static void scic_sds_phy_resetting_state_enter(void *object)
2182{
2183 struct scic_sds_phy *sci_phy = object;
2184
2185 scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_RESETTING);
2186
2187 /*
2188 * The phy is being reset, therefore deactivate it from the port.
2189 * In the resetting state we don't notify the user regarding
2190 * link up and link down notifications. */
2191 scic_sds_port_deactivate_phy(sci_phy->owning_port, sci_phy, false);
2192
2193 if (sci_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
2194 scu_link_layer_tx_hard_reset(sci_phy);
2195 } else {
2196 /*
2197 * The SCU does not need to have a discrete reset state so
2198 * just go back to the starting state.
2199 */
2200 sci_base_state_machine_change_state(
2201 &sci_phy->state_machine,
2202 SCI_BASE_PHY_STATE_STARTING);
2203 }
2204}
2205
2206/**
2207 *
2208 * @object: This is the object which is cast to a struct scic_sds_phy object.
2209 *
2210 * This method will perform the actions required by the struct scic_sds_phy on
2211 * entering the SCI_BASE_PHY_STATE_FINAL. - This function sets the state
2212 * handlers for the phy object base state machine final state. none
2213 */
2214static void scic_sds_phy_final_state_enter(void *object)
2215{
2216 struct scic_sds_phy *sci_phy = object;
2217
2218 scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_FINAL);
2219
2220 /* Nothing to do here */
2221}
2222
2223/* --------------------------------------------------------------------------- */
2224
2225static const struct sci_base_state scic_sds_phy_state_table[] = {
2226 [SCI_BASE_PHY_STATE_INITIAL] = {
2227 .enter_state = scic_sds_phy_initial_state_enter,
2228 },
2229 [SCI_BASE_PHY_STATE_STOPPED] = {
2230 .enter_state = scic_sds_phy_stopped_state_enter,
2231 },
2232 [SCI_BASE_PHY_STATE_STARTING] = {
2233 .enter_state = scic_sds_phy_starting_state_enter,
2234 },
2235 [SCI_BASE_PHY_STATE_READY] = {
2236 .enter_state = scic_sds_phy_ready_state_enter,
2237 .exit_state = scic_sds_phy_ready_state_exit,
2238 },
2239 [SCI_BASE_PHY_STATE_RESETTING] = {
2240 .enter_state = scic_sds_phy_resetting_state_enter,
2241 },
2242 [SCI_BASE_PHY_STATE_FINAL] = {
2243 .enter_state = scic_sds_phy_final_state_enter,
2244 },
2245};
2246
2247void scic_sds_phy_construct(struct scic_sds_phy *sci_phy,
2248 struct scic_sds_port *owning_port, u8 phy_index)
2249{
2250 sci_base_state_machine_construct(&sci_phy->state_machine,
2251 sci_phy,
2252 scic_sds_phy_state_table,
2253 SCI_BASE_PHY_STATE_INITIAL);
2254
2255 sci_base_state_machine_start(&sci_phy->state_machine);
2256
2257 /* Copy the rest of the input data to our locals */
2258 sci_phy->owning_port = owning_port;
2259 sci_phy->phy_index = phy_index;
2260 sci_phy->bcn_received_while_port_unassigned = false;
2261 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
2262 sci_phy->link_layer_registers = NULL;
2263 sci_phy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
2264 sci_phy->sata_timeout_timer = NULL;
2265
2266 /* Initialize the the substate machines */
2267 sci_base_state_machine_construct(&sci_phy->starting_substate_machine,
2268 sci_phy,
2269 scic_sds_phy_starting_substates,
2270 SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL);
2271}
65 2272
66void isci_phy_init(struct isci_phy *iphy, struct isci_host *ihost, int index) 2273void isci_phy_init(struct isci_phy *iphy, struct isci_host *ihost, int index)
67{ 2274{