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