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