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