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