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