blob: 0ffb5d5a860ed405060131e88e30380712f0e180 [file] [log] [blame]
Dan Williams6f231dd2011-07-02 22:56:22 -07001/*
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 "isci.h"
Dan Williamsce2b3262011-05-08 15:49:15 -070057#include "host.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070058#include "phy.h"
Dan Williamsd35bc1b2011-05-10 02:28:45 -070059#include "scu_event_codes.h"
Dan Williamsd35bc1b2011-05-10 02:28:45 -070060#include "timers.h"
Dan Williamse2f8db52011-05-10 02:28:46 -070061#include "probe_roms.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070062
Dan Williamsd35bc1b2011-05-10 02:28:45 -070063/* Maximum arbitration wait time in micro-seconds */
64#define SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME (700)
65
66enum sas_linkrate sci_phy_linkrate(struct scic_sds_phy *sci_phy)
67{
68 return sci_phy->max_negotiated_speed;
69}
70
71/*
72 * *****************************************************************************
73 * * SCIC SDS PHY Internal Methods
74 * ***************************************************************************** */
75
76/**
77 * This method will initialize the phy transport layer registers
78 * @sci_phy:
79 * @transport_layer_registers
80 *
81 * enum sci_status
82 */
83static enum sci_status scic_sds_phy_transport_layer_initialization(
84 struct scic_sds_phy *sci_phy,
85 struct scu_transport_layer_registers __iomem *transport_layer_registers)
86{
87 u32 tl_control;
88
89 sci_phy->transport_layer_registers = transport_layer_registers;
90
91 writel(SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX,
92 &sci_phy->transport_layer_registers->stp_rni);
93
94 /*
95 * Hardware team recommends that we enable the STP prefetch for all
96 * transports
97 */
98 tl_control = readl(&sci_phy->transport_layer_registers->control);
99 tl_control |= SCU_TLCR_GEN_BIT(STP_WRITE_DATA_PREFETCH);
100 writel(tl_control, &sci_phy->transport_layer_registers->control);
101
102 return SCI_SUCCESS;
103}
104
105/**
106 * This method will initialize the phy link layer registers
107 * @sci_phy:
108 * @link_layer_registers:
109 *
110 * enum sci_status
111 */
112static enum sci_status
113scic_sds_phy_link_layer_initialization(struct scic_sds_phy *sci_phy,
114 struct scu_link_layer_registers __iomem *link_layer_registers)
115{
116 struct scic_sds_controller *scic =
117 sci_phy->owning_port->owning_controller;
118 int phy_idx = sci_phy->phy_index;
119 struct sci_phy_user_params *phy_user =
120 &scic->user_parameters.sds1.phys[phy_idx];
121 struct sci_phy_oem_params *phy_oem =
122 &scic->oem_parameters.sds1.phys[phy_idx];
123 u32 phy_configuration;
124 struct scic_phy_cap phy_cap;
125 u32 parity_check = 0;
126 u32 parity_count = 0;
127 u32 llctl, link_rate;
128 u32 clksm_value = 0;
129
130 sci_phy->link_layer_registers = link_layer_registers;
131
132 /* Set our IDENTIFY frame data */
133 #define SCI_END_DEVICE 0x01
134
135 writel(SCU_SAS_TIID_GEN_BIT(SMP_INITIATOR) |
136 SCU_SAS_TIID_GEN_BIT(SSP_INITIATOR) |
137 SCU_SAS_TIID_GEN_BIT(STP_INITIATOR) |
138 SCU_SAS_TIID_GEN_BIT(DA_SATA_HOST) |
139 SCU_SAS_TIID_GEN_VAL(DEVICE_TYPE, SCI_END_DEVICE),
140 &sci_phy->link_layer_registers->transmit_identification);
141
142 /* Write the device SAS Address */
143 writel(0xFEDCBA98,
144 &sci_phy->link_layer_registers->sas_device_name_high);
145 writel(phy_idx, &sci_phy->link_layer_registers->sas_device_name_low);
146
147 /* Write the source SAS Address */
148 writel(phy_oem->sas_address.high,
149 &sci_phy->link_layer_registers->source_sas_address_high);
150 writel(phy_oem->sas_address.low,
151 &sci_phy->link_layer_registers->source_sas_address_low);
152
153 /* Clear and Set the PHY Identifier */
154 writel(0, &sci_phy->link_layer_registers->identify_frame_phy_id);
155 writel(SCU_SAS_TIPID_GEN_VALUE(ID, phy_idx),
156 &sci_phy->link_layer_registers->identify_frame_phy_id);
157
158 /* Change the initial state of the phy configuration register */
159 phy_configuration =
160 readl(&sci_phy->link_layer_registers->phy_configuration);
161
162 /* Hold OOB state machine in reset */
163 phy_configuration |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
164 writel(phy_configuration,
165 &sci_phy->link_layer_registers->phy_configuration);
166
167 /* Configure the SNW capabilities */
168 phy_cap.all = 0;
169 phy_cap.start = 1;
170 phy_cap.gen3_no_ssc = 1;
171 phy_cap.gen2_no_ssc = 1;
172 phy_cap.gen1_no_ssc = 1;
173 if (scic->oem_parameters.sds1.controller.do_enable_ssc == true) {
174 phy_cap.gen3_ssc = 1;
175 phy_cap.gen2_ssc = 1;
176 phy_cap.gen1_ssc = 1;
177 }
178
179 /*
180 * The SAS specification indicates that the phy_capabilities that
181 * are transmitted shall have an even parity. Calculate the parity. */
182 parity_check = phy_cap.all;
183 while (parity_check != 0) {
184 if (parity_check & 0x1)
185 parity_count++;
186 parity_check >>= 1;
187 }
188
189 /*
190 * If parity indicates there are an odd number of bits set, then
191 * set the parity bit to 1 in the phy capabilities. */
192 if ((parity_count % 2) != 0)
193 phy_cap.parity = 1;
194
195 writel(phy_cap.all, &sci_phy->link_layer_registers->phy_capabilities);
196
197 /* Set the enable spinup period but disable the ability to send
198 * notify enable spinup
199 */
200 writel(SCU_ENSPINUP_GEN_VAL(COUNT,
201 phy_user->notify_enable_spin_up_insertion_frequency),
202 &sci_phy->link_layer_registers->notify_enable_spinup_control);
203
204 /* Write the ALIGN Insertion Ferequency for connected phy and
205 * inpendent of connected state
206 */
207 clksm_value = SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(CONNECTED,
208 phy_user->in_connection_align_insertion_frequency);
209
210 clksm_value |= SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(GENERAL,
211 phy_user->align_insertion_frequency);
212
213 writel(clksm_value, &sci_phy->link_layer_registers->clock_skew_management);
214
215 /* @todo Provide a way to write this register correctly */
216 writel(0x02108421,
217 &sci_phy->link_layer_registers->afe_lookup_table_control);
218
219 llctl = SCU_SAS_LLCTL_GEN_VAL(NO_OUTBOUND_TASK_TIMEOUT,
220 (u8)scic->user_parameters.sds1.no_outbound_task_timeout);
221
222 switch(phy_user->max_speed_generation) {
223 case SCIC_SDS_PARM_GEN3_SPEED:
224 link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN3;
225 break;
226 case SCIC_SDS_PARM_GEN2_SPEED:
227 link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN2;
228 break;
229 default:
230 link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN1;
231 break;
232 }
233 llctl |= SCU_SAS_LLCTL_GEN_VAL(MAX_LINK_RATE, link_rate);
234 writel(llctl, &sci_phy->link_layer_registers->link_layer_control);
235
236 if (is_a0() || is_a2()) {
237 /* Program the max ARB time for the PHY to 700us so we inter-operate with
238 * the PMC expander which shuts down PHYs if the expander PHY generates too
239 * many breaks. This time value will guarantee that the initiator PHY will
240 * generate the break.
241 */
242 writel(SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME,
243 &sci_phy->link_layer_registers->maximum_arbitration_wait_timer_timeout);
244 }
245
246 /*
247 * Set the link layer hang detection to 500ms (0x1F4) from its default
248 * value of 128ms. Max value is 511 ms.
249 */
250 writel(0x1F4, &sci_phy->link_layer_registers->link_layer_hang_detection_timeout);
251
252 /* We can exit the initial state to the stopped state */
253 sci_base_state_machine_change_state(&sci_phy->state_machine,
254 SCI_BASE_PHY_STATE_STOPPED);
255
256 return SCI_SUCCESS;
257}
258
259/**
260 * This function will handle the sata SIGNATURE FIS timeout condition. It will
261 * restart the starting substate machine since we dont know what has actually
262 * happening.
263 */
264static void scic_sds_phy_sata_timeout(void *phy)
265{
266 struct scic_sds_phy *sci_phy = phy;
267
268 dev_dbg(sciphy_to_dev(sci_phy),
269 "%s: SCIC SDS Phy 0x%p did not receive signature fis before "
270 "timeout.\n",
271 __func__,
272 sci_phy);
273
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700274 sci_base_state_machine_change_state(&sci_phy->state_machine,
275 SCI_BASE_PHY_STATE_STARTING);
276}
277
278/**
279 * This method returns the port currently containing this phy. If the phy is
280 * currently contained by the dummy port, then the phy is considered to not
281 * be part of a port.
282 * @sci_phy: This parameter specifies the phy for which to retrieve the
283 * containing port.
284 *
285 * This method returns a handle to a port that contains the supplied phy.
286 * NULL This value is returned if the phy is not part of a real
287 * port (i.e. it's contained in the dummy port). !NULL All other
288 * values indicate a handle/pointer to the port containing the phy.
289 */
290struct scic_sds_port *scic_sds_phy_get_port(
291 struct scic_sds_phy *sci_phy)
292{
293 if (scic_sds_port_get_index(sci_phy->owning_port) == SCIC_SDS_DUMMY_PORT)
294 return NULL;
295
296 return sci_phy->owning_port;
297}
298
299/**
300 * This method will assign a port to the phy object.
301 * @out]: sci_phy This parameter specifies the phy for which to assign a port
302 * object.
303 *
304 *
305 */
306void scic_sds_phy_set_port(
307 struct scic_sds_phy *sci_phy,
308 struct scic_sds_port *sci_port)
309{
310 sci_phy->owning_port = sci_port;
311
312 if (sci_phy->bcn_received_while_port_unassigned) {
313 sci_phy->bcn_received_while_port_unassigned = false;
314 scic_sds_port_broadcast_change_received(sci_phy->owning_port, sci_phy);
315 }
316}
317
318/**
319 * This method will initialize the constructed phy
320 * @sci_phy:
321 * @link_layer_registers:
322 *
323 * enum sci_status
324 */
325enum sci_status scic_sds_phy_initialize(
326 struct scic_sds_phy *sci_phy,
327 struct scu_transport_layer_registers __iomem *transport_layer_registers,
328 struct scu_link_layer_registers __iomem *link_layer_registers)
329{
330 struct scic_sds_controller *scic = scic_sds_phy_get_controller(sci_phy);
331 struct isci_host *ihost = scic_to_ihost(scic);
332
333 /* Create the SIGNATURE FIS Timeout timer for this phy */
334 sci_phy->sata_timeout_timer =
335 isci_timer_create(
336 ihost,
337 sci_phy,
338 scic_sds_phy_sata_timeout);
339
340 /* Perfrom the initialization of the TL hardware */
341 scic_sds_phy_transport_layer_initialization(
342 sci_phy,
343 transport_layer_registers);
344
345 /* Perofrm the initialization of the PE hardware */
346 scic_sds_phy_link_layer_initialization(sci_phy, link_layer_registers);
347
348 /*
349 * There is nothing that needs to be done in this state just
350 * transition to the stopped state. */
351 sci_base_state_machine_change_state(&sci_phy->state_machine,
352 SCI_BASE_PHY_STATE_STOPPED);
353
354 return SCI_SUCCESS;
355}
356
357/**
358 * This method assigns the direct attached device ID for this phy.
359 *
360 * @sci_phy The phy for which the direct attached device id is to
361 * be assigned.
362 * @device_id The direct attached device ID to assign to the phy.
363 * This will either be the RNi for the device or an invalid RNi if there
364 * is no current device assigned to the phy.
365 */
366void scic_sds_phy_setup_transport(
367 struct scic_sds_phy *sci_phy,
368 u32 device_id)
369{
370 u32 tl_control;
371
372 writel(device_id, &sci_phy->transport_layer_registers->stp_rni);
373
374 /*
375 * The read should guarantee that the first write gets posted
376 * before the next write
377 */
378 tl_control = readl(&sci_phy->transport_layer_registers->control);
379 tl_control |= SCU_TLCR_GEN_BIT(CLEAR_TCI_NCQ_MAPPING_TABLE);
380 writel(tl_control, &sci_phy->transport_layer_registers->control);
381}
382
383/**
384 *
385 * @sci_phy: The phy object to be suspended.
386 *
387 * This function will perform the register reads/writes to suspend the SCU
388 * hardware protocol engine. none
389 */
390static void scic_sds_phy_suspend(
391 struct scic_sds_phy *sci_phy)
392{
393 u32 scu_sas_pcfg_value;
394
395 scu_sas_pcfg_value =
396 readl(&sci_phy->link_layer_registers->phy_configuration);
397 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE);
398 writel(scu_sas_pcfg_value,
399 &sci_phy->link_layer_registers->phy_configuration);
400
401 scic_sds_phy_setup_transport(
402 sci_phy,
403 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX);
404}
405
406void scic_sds_phy_resume(struct scic_sds_phy *sci_phy)
407{
408 u32 scu_sas_pcfg_value;
409
410 scu_sas_pcfg_value =
411 readl(&sci_phy->link_layer_registers->phy_configuration);
412 scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE);
413 writel(scu_sas_pcfg_value,
414 &sci_phy->link_layer_registers->phy_configuration);
415}
416
417void scic_sds_phy_get_sas_address(struct scic_sds_phy *sci_phy,
418 struct sci_sas_address *sas_address)
419{
420 sas_address->high = readl(&sci_phy->link_layer_registers->source_sas_address_high);
421 sas_address->low = readl(&sci_phy->link_layer_registers->source_sas_address_low);
422}
423
424void scic_sds_phy_get_attached_sas_address(struct scic_sds_phy *sci_phy,
425 struct sci_sas_address *sas_address)
426{
427 struct sas_identify_frame *iaf;
428 struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
429
430 iaf = &iphy->frame_rcvd.iaf;
431 memcpy(sas_address, iaf->sas_addr, SAS_ADDR_SIZE);
432}
433
434void scic_sds_phy_get_protocols(struct scic_sds_phy *sci_phy,
435 struct scic_phy_proto *protocols)
436{
437 protocols->all =
438 (u16)(readl(&sci_phy->
439 link_layer_registers->transmit_identification) &
440 0x0000FFFF);
441}
442
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700443enum sci_status scic_sds_phy_start(struct scic_sds_phy *sci_phy)
444{
Dan Williams966699b2011-05-12 03:44:24 -0700445 struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller;
446 enum scic_sds_phy_states state = sci_phy->state_machine.current_state_id;
447 struct isci_host *ihost = scic_to_ihost(scic);
448
449 if (state != SCI_BASE_PHY_STATE_STOPPED) {
450 dev_dbg(sciphy_to_dev(sci_phy),
451 "%s: in wrong state: %d\n", __func__, state);
452 return SCI_FAILURE_INVALID_STATE;
453 }
454
455 /* Create the SIGNATURE FIS Timeout timer for this phy */
456 sci_phy->sata_timeout_timer = isci_timer_create(ihost, sci_phy,
457 scic_sds_phy_sata_timeout);
458
459 if (sci_phy->sata_timeout_timer)
460 sci_base_state_machine_change_state(&sci_phy->state_machine,
461 SCI_BASE_PHY_STATE_STARTING);
462
463 return SCI_SUCCESS;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700464}
465
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700466enum sci_status scic_sds_phy_stop(struct scic_sds_phy *sci_phy)
467{
Dan Williams93153232011-05-12 04:01:03 -0700468 enum scic_sds_phy_states state = sci_phy->state_machine.current_state_id;
469
470 switch (state) {
471 case SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL:
472 case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN:
473 case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN:
474 case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER:
475 case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER:
476 case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN:
477 case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN:
478 case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF:
479 case SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL:
480 case SCI_BASE_PHY_STATE_READY:
481 break;
482 default:
483 dev_dbg(sciphy_to_dev(sci_phy),
484 "%s: in wrong state: %d\n", __func__, state);
485 return SCI_FAILURE_INVALID_STATE;
486 }
487
488 sci_base_state_machine_change_state(&sci_phy->state_machine,
489 SCI_BASE_PHY_STATE_STOPPED);
490 return SCI_SUCCESS;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700491}
492
Dan Williams0cf36fa2011-05-12 04:02:07 -0700493enum sci_status scic_sds_phy_reset(struct scic_sds_phy *sci_phy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700494{
Dan Williams0cf36fa2011-05-12 04:02:07 -0700495 enum scic_sds_phy_states state = sci_phy->state_machine.current_state_id;
496
497 if (state != SCI_BASE_PHY_STATE_READY) {
498 dev_dbg(sciphy_to_dev(sci_phy),
499 "%s: in wrong state: %d\n", __func__, state);
500 return SCI_FAILURE_INVALID_STATE;
501 }
502
503 sci_base_state_machine_change_state(&sci_phy->state_machine,
504 SCI_BASE_PHY_STATE_RESETTING);
505 return SCI_SUCCESS;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700506}
507
508/**
Dan Williams23506a62011-05-12 04:27:29 -0700509 * This method will give the phy permission to consume power
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700510 * @sci_phy:
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700511 *
512 * enum sci_status
513 */
Dan Williams23506a62011-05-12 04:27:29 -0700514enum sci_status scic_sds_phy_consume_power_handler(
515 struct scic_sds_phy *sci_phy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700516{
Dan Williams23506a62011-05-12 04:27:29 -0700517 return sci_phy->state_handlers->consume_power_handler(sci_phy);
518}
519
520/*
521 * *****************************************************************************
522 * * SCIC SDS PHY HELPER FUNCTIONS
523 * ***************************************************************************** */
524
525
526/**
527 *
528 * @sci_phy: The phy object that received SAS PHY DETECTED.
529 *
530 * This method continues the link training for the phy as if it were a SAS PHY
531 * instead of a SATA PHY. This is done because the completion queue had a SAS
532 * PHY DETECTED event when the state machine was expecting a SATA PHY event.
533 * none
534 */
535static void scic_sds_phy_start_sas_link_training(
536 struct scic_sds_phy *sci_phy)
537{
538 u32 phy_control;
539
540 phy_control =
541 readl(&sci_phy->link_layer_registers->phy_configuration);
542 phy_control |= SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD);
543 writel(phy_control,
544 &sci_phy->link_layer_registers->phy_configuration);
545
546 sci_base_state_machine_change_state(
547 &sci_phy->state_machine,
548 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
549 );
550
551 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SAS;
552}
553
554/**
555 *
556 * @sci_phy: The phy object that received a SATA SPINUP HOLD event
557 *
558 * This method continues the link training for the phy as if it were a SATA PHY
559 * instead of a SAS PHY. This is done because the completion queue had a SATA
560 * SPINUP HOLD event when the state machine was expecting a SAS PHY event. none
561 */
562static void scic_sds_phy_start_sata_link_training(
563 struct scic_sds_phy *sci_phy)
564{
565 sci_base_state_machine_change_state(
566 &sci_phy->state_machine,
567 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
568 );
569
570 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
571}
572
573/**
574 * scic_sds_phy_complete_link_training - perform processing common to
575 * all protocols upon completion of link training.
576 * @sci_phy: This parameter specifies the phy object for which link training
577 * has completed.
578 * @max_link_rate: This parameter specifies the maximum link rate to be
579 * associated with this phy.
580 * @next_state: This parameter specifies the next state for the phy's starting
581 * sub-state machine.
582 *
583 */
584static void scic_sds_phy_complete_link_training(
585 struct scic_sds_phy *sci_phy,
586 enum sas_linkrate max_link_rate,
587 u32 next_state)
588{
589 sci_phy->max_negotiated_speed = max_link_rate;
590
591 sci_base_state_machine_change_state(&sci_phy->state_machine,
592 next_state);
593}
594
595/*
596 * This method is called by the struct scic_sds_controller when the phy object is
597 * granted power. - The notify enable spinups are turned on for this phy object
598 * - The phy state machine is transitioned to the
599 * SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. enum sci_status SCI_SUCCESS
600 */
601static enum sci_status scic_sds_phy_starting_substate_await_sas_power_consume_power_handler(
602 struct scic_sds_phy *sci_phy)
603{
604 u32 enable_spinup;
605
606 enable_spinup = readl(&sci_phy->link_layer_registers->notify_enable_spinup_control);
607 enable_spinup |= SCU_ENSPINUP_GEN_BIT(ENABLE);
608 writel(enable_spinup, &sci_phy->link_layer_registers->notify_enable_spinup_control);
609
610 /* Change state to the final state this substate machine has run to completion */
611 sci_base_state_machine_change_state(&sci_phy->state_machine,
612 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL);
613
614 return SCI_SUCCESS;
615}
616
617/*
618 * This method is called by the struct scic_sds_controller when the phy object is
619 * granted power. - The phy state machine is transitioned to the
620 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. enum sci_status SCI_SUCCESS
621 */
622static enum sci_status scic_sds_phy_starting_substate_await_sata_power_consume_power_handler(
623 struct scic_sds_phy *sci_phy)
624{
625 u32 scu_sas_pcfg_value;
626
627 /* Release the spinup hold state and reset the OOB state machine */
628 scu_sas_pcfg_value =
629 readl(&sci_phy->link_layer_registers->phy_configuration);
630 scu_sas_pcfg_value &=
631 ~(SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD) | SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE));
632 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
633 writel(scu_sas_pcfg_value,
634 &sci_phy->link_layer_registers->phy_configuration);
635
636 /* Now restart the OOB operation */
637 scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
638 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
639 writel(scu_sas_pcfg_value,
640 &sci_phy->link_layer_registers->phy_configuration);
641
642 /* Change state to the final state this substate machine has run to completion */
643 sci_base_state_machine_change_state(&sci_phy->state_machine,
644 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN);
645
646 return SCI_SUCCESS;
647}
648
649static enum sci_status default_phy_handler(struct scic_sds_phy *sci_phy,
650 const char *func)
651{
652 dev_dbg(sciphy_to_dev(sci_phy),
653 "%s: in wrong state: %d\n", func,
654 sci_base_state_machine_get_state(&sci_phy->state_machine));
655 return SCI_FAILURE_INVALID_STATE;
656}
657
658static enum sci_status
659scic_sds_phy_default_consume_power_handler(struct scic_sds_phy *sci_phy)
660{
661 return default_phy_handler(sci_phy, __func__);
662}
663
664
665enum sci_status scic_sds_phy_event_handler(struct scic_sds_phy *sci_phy,
666 u32 event_code)
667{
668 enum scic_sds_phy_states state = sci_phy->state_machine.current_state_id;
669
670 switch (state) {
671 case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN:
672 switch (scu_get_event_code(event_code)) {
673 case SCU_EVENT_SAS_PHY_DETECTED:
674 scic_sds_phy_start_sas_link_training(sci_phy);
675 sci_phy->is_in_link_training = true;
676 break;
677 case SCU_EVENT_SATA_SPINUP_HOLD:
678 scic_sds_phy_start_sata_link_training(sci_phy);
679 sci_phy->is_in_link_training = true;
680 break;
681 default:
682 dev_dbg(sciphy_to_dev(sci_phy),
683 "%s: PHY starting substate machine received "
684 "unexpected event_code %x\n",
685 __func__,
686 event_code);
687 return SCI_FAILURE;
688 }
689 return SCI_SUCCESS;
690 case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN:
691 switch (scu_get_event_code(event_code)) {
692 case SCU_EVENT_SAS_PHY_DETECTED:
693 /*
694 * Why is this being reported again by the controller?
695 * We would re-enter this state so just stay here */
696 break;
697 case SCU_EVENT_SAS_15:
698 case SCU_EVENT_SAS_15_SSC:
699 scic_sds_phy_complete_link_training(
700 sci_phy,
701 SAS_LINK_RATE_1_5_GBPS,
702 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF);
703 break;
704 case SCU_EVENT_SAS_30:
705 case SCU_EVENT_SAS_30_SSC:
706 scic_sds_phy_complete_link_training(
707 sci_phy,
708 SAS_LINK_RATE_3_0_GBPS,
709 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF);
710 break;
711 case SCU_EVENT_SAS_60:
712 case SCU_EVENT_SAS_60_SSC:
713 scic_sds_phy_complete_link_training(
714 sci_phy,
715 SAS_LINK_RATE_6_0_GBPS,
716 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF);
717 break;
718 case SCU_EVENT_SATA_SPINUP_HOLD:
719 /*
720 * We were doing SAS PHY link training and received a SATA PHY event
721 * continue OOB/SN as if this were a SATA PHY */
722 scic_sds_phy_start_sata_link_training(sci_phy);
723 break;
724 case SCU_EVENT_LINK_FAILURE:
725 /* Link failure change state back to the starting state */
726 sci_base_state_machine_change_state(&sci_phy->state_machine,
727 SCI_BASE_PHY_STATE_STARTING);
728 break;
729 default:
730 dev_warn(sciphy_to_dev(sci_phy),
731 "%s: PHY starting substate machine received "
732 "unexpected event_code %x\n",
733 __func__, event_code);
734
735 return SCI_FAILURE;
736 break;
737 }
738 return SCI_SUCCESS;
739 case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF:
740 switch (scu_get_event_code(event_code)) {
741 case SCU_EVENT_SAS_PHY_DETECTED:
742 /* Backup the state machine */
743 scic_sds_phy_start_sas_link_training(sci_phy);
744 break;
745 case SCU_EVENT_SATA_SPINUP_HOLD:
746 /* We were doing SAS PHY link training and received a
747 * SATA PHY event continue OOB/SN as if this were a
748 * SATA PHY
749 */
750 scic_sds_phy_start_sata_link_training(sci_phy);
751 break;
752 case SCU_EVENT_RECEIVED_IDENTIFY_TIMEOUT:
753 case SCU_EVENT_LINK_FAILURE:
754 case SCU_EVENT_HARD_RESET_RECEIVED:
755 /* Start the oob/sn state machine over again */
756 sci_base_state_machine_change_state(&sci_phy->state_machine,
757 SCI_BASE_PHY_STATE_STARTING);
758 break;
759 default:
760 dev_warn(sciphy_to_dev(sci_phy),
761 "%s: PHY starting substate machine received "
762 "unexpected event_code %x\n",
763 __func__, event_code);
764 return SCI_FAILURE;
765 }
766 return SCI_SUCCESS;
767 case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER:
768 switch (scu_get_event_code(event_code)) {
769 case SCU_EVENT_LINK_FAILURE:
770 /* Link failure change state back to the starting state */
771 sci_base_state_machine_change_state(&sci_phy->state_machine,
772 SCI_BASE_PHY_STATE_STARTING);
773 break;
774 default:
775 dev_warn(sciphy_to_dev(sci_phy),
776 "%s: PHY starting substate machine received unexpected "
777 "event_code %x\n",
778 __func__,
779 event_code);
780 return SCI_FAILURE;
781 }
782 return SCI_SUCCESS;
783 case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER:
784 switch (scu_get_event_code(event_code)) {
785 case SCU_EVENT_LINK_FAILURE:
786 /* Link failure change state back to the starting state */
787 sci_base_state_machine_change_state(&sci_phy->state_machine,
788 SCI_BASE_PHY_STATE_STARTING);
789 break;
790 case SCU_EVENT_SATA_SPINUP_HOLD:
791 /* These events are received every 10ms and are
792 * expected while in this state
793 */
794 break;
795
796 case SCU_EVENT_SAS_PHY_DETECTED:
797 /* There has been a change in the phy type before OOB/SN for the
798 * SATA finished start down the SAS link traning path.
799 */
800 scic_sds_phy_start_sas_link_training(sci_phy);
801 break;
802
803 default:
804 dev_warn(sciphy_to_dev(sci_phy),
805 "%s: PHY starting substate machine received "
806 "unexpected event_code %x\n",
807 __func__, event_code);
808
809 return SCI_FAILURE;
810 }
811 return SCI_SUCCESS;
812 case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN:
813 switch (scu_get_event_code(event_code)) {
814 case SCU_EVENT_LINK_FAILURE:
815 /* Link failure change state back to the starting state */
816 sci_base_state_machine_change_state(&sci_phy->state_machine,
817 SCI_BASE_PHY_STATE_STARTING);
818 break;
819 case SCU_EVENT_SATA_SPINUP_HOLD:
820 /* These events might be received since we dont know how many may be in
821 * the completion queue while waiting for power
822 */
823 break;
824 case SCU_EVENT_SATA_PHY_DETECTED:
825 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
826
827 /* We have received the SATA PHY notification change state */
828 sci_base_state_machine_change_state(&sci_phy->state_machine,
829 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN);
830 break;
831 case SCU_EVENT_SAS_PHY_DETECTED:
832 /* There has been a change in the phy type before OOB/SN for the
833 * SATA finished start down the SAS link traning path.
834 */
835 scic_sds_phy_start_sas_link_training(sci_phy);
836 break;
837 default:
838 dev_warn(sciphy_to_dev(sci_phy),
839 "%s: PHY starting substate machine received "
840 "unexpected event_code %x\n",
841 __func__,
842 event_code);
843
844 return SCI_FAILURE;;
845 }
846 return SCI_SUCCESS;
847 case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN:
848 switch (scu_get_event_code(event_code)) {
849 case SCU_EVENT_SATA_PHY_DETECTED:
850 /*
851 * The hardware reports multiple SATA PHY detected events
852 * ignore the extras */
853 break;
854 case SCU_EVENT_SATA_15:
855 case SCU_EVENT_SATA_15_SSC:
856 scic_sds_phy_complete_link_training(
857 sci_phy,
858 SAS_LINK_RATE_1_5_GBPS,
859 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
860 break;
861 case SCU_EVENT_SATA_30:
862 case SCU_EVENT_SATA_30_SSC:
863 scic_sds_phy_complete_link_training(
864 sci_phy,
865 SAS_LINK_RATE_3_0_GBPS,
866 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
867 break;
868 case SCU_EVENT_SATA_60:
869 case SCU_EVENT_SATA_60_SSC:
870 scic_sds_phy_complete_link_training(
871 sci_phy,
872 SAS_LINK_RATE_6_0_GBPS,
873 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
874 break;
875 case SCU_EVENT_LINK_FAILURE:
876 /* Link failure change state back to the starting state */
877 sci_base_state_machine_change_state(&sci_phy->state_machine,
878 SCI_BASE_PHY_STATE_STARTING);
879 break;
880 case SCU_EVENT_SAS_PHY_DETECTED:
881 /*
882 * There has been a change in the phy type before OOB/SN for the
883 * SATA finished start down the SAS link traning path. */
884 scic_sds_phy_start_sas_link_training(sci_phy);
885 break;
886 default:
887 dev_warn(sciphy_to_dev(sci_phy),
888 "%s: PHY starting substate machine received "
889 "unexpected event_code %x\n",
890 __func__, event_code);
891
892 return SCI_FAILURE;
893 }
894
895 return SCI_SUCCESS;
896 case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF:
897 switch (scu_get_event_code(event_code)) {
898 case SCU_EVENT_SATA_PHY_DETECTED:
899 /* Backup the state machine */
900 sci_base_state_machine_change_state(&sci_phy->state_machine,
901 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN);
902 break;
903
904 case SCU_EVENT_LINK_FAILURE:
905 /* Link failure change state back to the starting state */
906 sci_base_state_machine_change_state(&sci_phy->state_machine,
907 SCI_BASE_PHY_STATE_STARTING);
908 break;
909
910 default:
911 dev_warn(sciphy_to_dev(sci_phy),
912 "%s: PHY starting substate machine received "
913 "unexpected event_code %x\n",
914 __func__,
915 event_code);
916
917 return SCI_FAILURE;
918 }
919 return SCI_SUCCESS;
920 case SCI_BASE_PHY_STATE_READY:
921 switch (scu_get_event_code(event_code)) {
922 case SCU_EVENT_LINK_FAILURE:
923 /* Link failure change state back to the starting state */
924 sci_base_state_machine_change_state(&sci_phy->state_machine,
925 SCI_BASE_PHY_STATE_STARTING);
926 break;
927 case SCU_EVENT_BROADCAST_CHANGE:
928 /* Broadcast change received. Notify the port. */
929 if (scic_sds_phy_get_port(sci_phy) != NULL)
930 scic_sds_port_broadcast_change_received(sci_phy->owning_port, sci_phy);
931 else
932 sci_phy->bcn_received_while_port_unassigned = true;
933 break;
934 default:
935 dev_warn(sciphy_to_dev(sci_phy),
936 "%sP SCIC PHY 0x%p ready state machine received "
937 "unexpected event_code %x\n",
938 __func__, sci_phy, event_code);
939 return SCI_FAILURE_INVALID_STATE;
940 }
941 return SCI_SUCCESS;
942 case SCI_BASE_PHY_STATE_RESETTING:
943 switch (scu_get_event_code(event_code)) {
944 case SCU_EVENT_HARD_RESET_TRANSMITTED:
945 /* Link failure change state back to the starting state */
946 sci_base_state_machine_change_state(&sci_phy->state_machine,
947 SCI_BASE_PHY_STATE_STARTING);
948 break;
949 default:
950 dev_warn(sciphy_to_dev(sci_phy),
951 "%s: SCIC PHY 0x%p resetting state machine received "
952 "unexpected event_code %x\n",
953 __func__, sci_phy, event_code);
954
955 return SCI_FAILURE_INVALID_STATE;
956 break;
957 }
958 return SCI_SUCCESS;
959 default:
960 dev_dbg(sciphy_to_dev(sci_phy),
961 "%s: in wrong state: %d\n", __func__, state);
962 return SCI_FAILURE_INVALID_STATE;
963 }
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700964}
965
Dan Williamsc4441ab2011-05-12 04:17:51 -0700966enum sci_status scic_sds_phy_frame_handler(struct scic_sds_phy *sci_phy,
967 u32 frame_index)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700968{
Dan Williamsc4441ab2011-05-12 04:17:51 -0700969 enum scic_sds_phy_states state = sci_phy->state_machine.current_state_id;
970 struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller;
971 enum sci_status result;
972
973 switch (state) {
974 case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF: {
975 u32 *frame_words;
976 struct sas_identify_frame iaf;
977 struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
978
979 result = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
980 frame_index,
981 (void **)&frame_words);
982
983 if (result != SCI_SUCCESS)
984 return result;
985
986 sci_swab32_cpy(&iaf, frame_words, sizeof(iaf) / sizeof(u32));
987 if (iaf.frame_type == 0) {
988 u32 state;
989
990 memcpy(&iphy->frame_rcvd.iaf, &iaf, sizeof(iaf));
991 if (iaf.smp_tport) {
992 /* We got the IAF for an expander PHY go to the final
993 * state since there are no power requirements for
994 * expander phys.
995 */
996 state = SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL;
997 } else {
998 /* We got the IAF we can now go to the await spinup
999 * semaphore state
1000 */
1001 state = SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER;
1002 }
1003 sci_base_state_machine_change_state(&sci_phy->state_machine,
1004 state);
1005 result = SCI_SUCCESS;
1006 } else
1007 dev_warn(sciphy_to_dev(sci_phy),
1008 "%s: PHY starting substate machine received "
1009 "unexpected frame id %x\n",
1010 __func__, frame_index);
1011
1012 scic_sds_controller_release_frame(scic, frame_index);
1013 return result;
1014 }
1015 case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF: {
1016 struct dev_to_host_fis *frame_header;
1017 u32 *fis_frame_data;
1018 struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
1019
1020 result = scic_sds_unsolicited_frame_control_get_header(
1021 &(scic_sds_phy_get_controller(sci_phy)->uf_control),
1022 frame_index,
1023 (void **)&frame_header);
1024
1025 if (result != SCI_SUCCESS)
1026 return result;
1027
1028 if ((frame_header->fis_type == FIS_REGD2H) &&
1029 !(frame_header->status & ATA_BUSY)) {
1030 scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
1031 frame_index,
1032 (void **)&fis_frame_data);
1033
1034 scic_sds_controller_copy_sata_response(&iphy->frame_rcvd.fis,
1035 frame_header,
1036 fis_frame_data);
1037
1038 /* got IAF we can now go to the await spinup semaphore state */
1039 sci_base_state_machine_change_state(&sci_phy->state_machine,
1040 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL);
1041
1042 result = SCI_SUCCESS;
1043 } else
1044 dev_warn(sciphy_to_dev(sci_phy),
1045 "%s: PHY starting substate machine received "
1046 "unexpected frame id %x\n",
1047 __func__, frame_index);
1048
1049 /* Regardless of the result we are done with this frame with it */
1050 scic_sds_controller_release_frame(scic, frame_index);
1051
1052 return result;
1053 }
1054 default:
1055 dev_dbg(sciphy_to_dev(sci_phy),
1056 "%s: in wrong state: %d\n", __func__, state);
1057 return SCI_FAILURE_INVALID_STATE;
1058 }
1059
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001060}
1061
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001062
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001063
1064/* --------------------------------------------------------------------------- */
1065
1066static const struct scic_sds_phy_state_handler scic_sds_phy_state_handler_table[] = {
1067 [SCI_BASE_PHY_STATE_INITIAL] = {
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001068 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1069 },
1070 [SCI_BASE_PHY_STATE_STOPPED] = {
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001071 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1072 },
1073 [SCI_BASE_PHY_STATE_STARTING] = {
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001074 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1075 },
Adam Gruchala4a33c522011-05-10 23:54:23 +00001076 [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL] = {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001077 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1078 },
1079 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN] = {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001080 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1081 },
1082 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN] = {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001083 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1084 },
1085 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF] = {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001086 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1087 },
1088 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER] = {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001089 .consume_power_handler = scic_sds_phy_starting_substate_await_sas_power_consume_power_handler
1090 },
1091 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER] = {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001092 .consume_power_handler = scic_sds_phy_starting_substate_await_sata_power_consume_power_handler
1093 },
1094 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN] = {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001095 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1096 },
1097 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN] = {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001098 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1099 },
1100 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF] = {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001101 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1102 },
1103 [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL] = {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001104 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1105 },
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001106 [SCI_BASE_PHY_STATE_READY] = {
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001107 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1108 },
1109 [SCI_BASE_PHY_STATE_RESETTING] = {
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001110 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1111 },
1112 [SCI_BASE_PHY_STATE_FINAL] = {
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001113 .consume_power_handler = scic_sds_phy_default_consume_power_handler
1114 }
1115};
1116
1117/*
1118 * ****************************************************************************
Adam Gruchala4a33c522011-05-10 23:54:23 +00001119 * * PHY STARTING SUBSTATE METHODS
1120 * **************************************************************************** */
1121
1122/**
1123 * scic_sds_phy_starting_initial_substate_enter -
1124 * @object: This is the object which is cast to a struct scic_sds_phy object.
1125 *
1126 * This method will perform the actions required by the struct scic_sds_phy on
1127 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL. - The initial state
1128 * handlers are put in place for the struct scic_sds_phy object. - The state is
1129 * changed to the wait phy type event notification. none
1130 */
1131static void scic_sds_phy_starting_initial_substate_enter(void *object)
1132{
1133 struct scic_sds_phy *sci_phy = object;
1134
1135 scic_sds_phy_set_base_state_handlers(
1136 sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL);
1137
1138 /* This is just an temporary state go off to the starting state */
1139 sci_base_state_machine_change_state(&sci_phy->state_machine,
1140 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN);
1141}
1142
1143/**
1144 *
1145 * @object: This is the object which is cast to a struct scic_sds_phy object.
1146 *
1147 * This method will perform the actions required by the struct scic_sds_phy on
1148 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_PHY_TYPE_EN. - Set the
1149 * struct scic_sds_phy object state handlers for this state. none
1150 */
1151static void scic_sds_phy_starting_await_ossp_en_substate_enter(void *object)
1152{
1153 struct scic_sds_phy *sci_phy = object;
1154
1155 scic_sds_phy_set_base_state_handlers(
1156 sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
1157 );
1158}
1159
1160/**
1161 *
1162 * @object: This is the object which is cast to a struct scic_sds_phy object.
1163 *
1164 * This method will perform the actions required by the struct scic_sds_phy on
1165 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. - Set the
1166 * struct scic_sds_phy object state handlers for this state. none
1167 */
1168static void scic_sds_phy_starting_await_sas_speed_en_substate_enter(
1169 void *object)
1170{
1171 struct scic_sds_phy *sci_phy = object;
1172
1173 scic_sds_phy_set_base_state_handlers(
1174 sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
1175 );
1176}
1177
1178/**
1179 *
1180 * @object: This is the object which is cast to a struct scic_sds_phy object.
1181 *
1182 * This method will perform the actions required by the struct scic_sds_phy on
1183 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - Set the
1184 * struct scic_sds_phy object state handlers for this state. none
1185 */
1186static void scic_sds_phy_starting_await_iaf_uf_substate_enter(void *object)
1187{
1188 struct scic_sds_phy *sci_phy = object;
1189
1190 scic_sds_phy_set_base_state_handlers(
1191 sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
1192 );
1193}
1194
1195/**
1196 *
1197 * @object: This is the object which is cast to a struct scic_sds_phy object.
1198 *
1199 * This method will perform the actions required by the struct scic_sds_phy on
1200 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Set the
1201 * struct scic_sds_phy object state handlers for this state. - Add this phy object to
1202 * the power control queue none
1203 */
1204static void scic_sds_phy_starting_await_sas_power_substate_enter(void *object)
1205{
1206 struct scic_sds_phy *sci_phy = object;
1207
1208 scic_sds_phy_set_base_state_handlers(
1209 sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
1210 );
1211
1212 scic_sds_controller_power_control_queue_insert(
1213 scic_sds_phy_get_controller(sci_phy),
1214 sci_phy
1215 );
1216}
1217
1218/**
1219 *
1220 * @object: This is the object which is cast to a struct scic_sds_phy object.
1221 *
1222 * This method will perform the actions required by the struct scic_sds_phy on exiting
1223 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Remove the
1224 * struct scic_sds_phy object from the power control queue. none
1225 */
1226static void scic_sds_phy_starting_await_sas_power_substate_exit(void *object)
1227{
1228 struct scic_sds_phy *sci_phy = object;
1229
1230 scic_sds_controller_power_control_queue_remove(
1231 scic_sds_phy_get_controller(sci_phy), sci_phy
1232 );
1233}
1234
1235/**
1236 *
1237 * @object: This is the object which is cast to a struct scic_sds_phy object.
1238 *
1239 * This method will perform the actions required by the struct scic_sds_phy on
1240 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Set the
1241 * struct scic_sds_phy object state handlers for this state. - Add this phy object to
1242 * the power control queue none
1243 */
1244static void scic_sds_phy_starting_await_sata_power_substate_enter(void *object)
1245{
1246 struct scic_sds_phy *sci_phy = object;
1247
1248 scic_sds_phy_set_base_state_handlers(
1249 sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
1250 );
1251
1252 scic_sds_controller_power_control_queue_insert(
1253 scic_sds_phy_get_controller(sci_phy),
1254 sci_phy
1255 );
1256}
1257
1258/**
1259 *
1260 * @object: This is the object which is cast to a struct scic_sds_phy object.
1261 *
1262 * This method will perform the actions required by the struct scic_sds_phy on exiting
1263 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Remove the
1264 * struct scic_sds_phy object from the power control queue. none
1265 */
1266static void scic_sds_phy_starting_await_sata_power_substate_exit(void *object)
1267{
1268 struct scic_sds_phy *sci_phy = object;
1269
1270 scic_sds_controller_power_control_queue_remove(
1271 scic_sds_phy_get_controller(sci_phy),
1272 sci_phy
1273 );
1274}
1275
1276/**
1277 *
1278 * @object: This is the object which is cast to a struct scic_sds_phy object.
1279 *
1280 * This function will perform the actions required by the struct scic_sds_phy on
1281 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. - Set the
1282 * struct scic_sds_phy object state handlers for this state. none
1283 */
1284static void scic_sds_phy_starting_await_sata_phy_substate_enter(void *object)
1285{
1286 struct scic_sds_phy *sci_phy = object;
1287
1288 scic_sds_phy_set_base_state_handlers(
1289 sci_phy,
1290 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN);
1291
1292 isci_timer_start(sci_phy->sata_timeout_timer,
1293 SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
1294}
1295
1296/**
1297 *
1298 * @object: This is the object which is cast to a struct scic_sds_phy object.
1299 *
1300 * This method will perform the actions required by the struct scic_sds_phy
1301 * on exiting
1302 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
1303 * that was started on entry to await sata phy event notification none
1304 */
1305static inline void scic_sds_phy_starting_await_sata_phy_substate_exit(
1306 void *object)
1307{
1308 struct scic_sds_phy *sci_phy = object;
1309
1310 isci_timer_stop(sci_phy->sata_timeout_timer);
1311}
1312
1313/**
1314 *
1315 * @object: This is the object which is cast to a struct scic_sds_phy object.
1316 *
1317 * This method will perform the actions required by the struct scic_sds_phy on
1318 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - Set the
1319 * struct scic_sds_phy object state handlers for this state. none
1320 */
1321static void scic_sds_phy_starting_await_sata_speed_substate_enter(void *object)
1322{
1323 struct scic_sds_phy *sci_phy = object;
1324
1325 scic_sds_phy_set_base_state_handlers(
1326 sci_phy,
1327 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN);
1328
1329 isci_timer_start(sci_phy->sata_timeout_timer,
1330 SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
1331}
1332
1333/**
1334 *
1335 * @object: This is the object which is cast to a struct scic_sds_phy object.
1336 *
1337 * This function will perform the actions required by the
1338 * struct scic_sds_phy on exiting
1339 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
1340 * that was started on entry to await sata phy event notification none
1341 */
1342static inline void scic_sds_phy_starting_await_sata_speed_substate_exit(
1343 void *object)
1344{
1345 struct scic_sds_phy *sci_phy = object;
1346
1347 isci_timer_stop(sci_phy->sata_timeout_timer);
1348}
1349
1350/**
1351 *
1352 * @object: This is the object which is cast to a struct scic_sds_phy object.
1353 *
1354 * This function will perform the actions required by the struct scic_sds_phy on
1355 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Set the
1356 * struct scic_sds_phy object state handlers for this state.
1357 * - Start the SIGNATURE FIS
1358 * timeout timer none
1359 */
1360static void scic_sds_phy_starting_await_sig_fis_uf_substate_enter(void *object)
1361{
1362 bool continue_to_ready_state;
1363 struct scic_sds_phy *sci_phy = object;
1364
1365 scic_sds_phy_set_base_state_handlers(
1366 sci_phy,
1367 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
1368
1369 continue_to_ready_state = scic_sds_port_link_detected(
1370 sci_phy->owning_port,
1371 sci_phy);
1372
1373 if (continue_to_ready_state) {
1374 /*
1375 * Clear the PE suspend condition so we can actually
1376 * receive SIG FIS
1377 * The hardware will not respond to the XRDY until the PE
1378 * suspend condition is cleared.
1379 */
1380 scic_sds_phy_resume(sci_phy);
1381
1382 isci_timer_start(sci_phy->sata_timeout_timer,
1383 SCIC_SDS_SIGNATURE_FIS_TIMEOUT);
1384 } else
1385 sci_phy->is_in_link_training = false;
1386}
1387
1388/**
1389 *
1390 * @object: This is the object which is cast to a struct scic_sds_phy object.
1391 *
1392 * This function will perform the actions required by the
1393 * struct scic_sds_phy on exiting
1394 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Stop the SIGNATURE
1395 * FIS timeout timer. none
1396 */
1397static inline void scic_sds_phy_starting_await_sig_fis_uf_substate_exit(
1398 void *object)
1399{
1400 struct scic_sds_phy *sci_phy = object;
1401
1402 isci_timer_stop(sci_phy->sata_timeout_timer);
1403}
1404
1405/**
1406 *
1407 * @object: This is the object which is cast to a struct scic_sds_phy object.
1408 *
1409 * This method will perform the actions required by the struct scic_sds_phy on
1410 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. - Set the struct scic_sds_phy
1411 * object state handlers for this state. - Change base state machine to the
1412 * ready state. none
1413 */
1414static void scic_sds_phy_starting_final_substate_enter(void *object)
1415{
1416 struct scic_sds_phy *sci_phy = object;
1417
1418 scic_sds_phy_set_base_state_handlers(sci_phy,
1419 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL);
1420
1421 /* State machine has run to completion so exit out and change
1422 * the base state machine to the ready state
1423 */
1424 sci_base_state_machine_change_state(&sci_phy->state_machine,
1425 SCI_BASE_PHY_STATE_READY);
1426}
1427
1428/*
1429 * ****************************************************************************
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001430 * * PHY STATE PRIVATE METHODS
1431 * **************************************************************************** */
1432
1433/**
1434 *
1435 * @sci_phy: This is the struct scic_sds_phy object to stop.
1436 *
1437 * This method will stop the struct scic_sds_phy object. This does not reset the
1438 * protocol engine it just suspends it and places it in a state where it will
1439 * not cause the end device to power up. none
1440 */
1441static void scu_link_layer_stop_protocol_engine(
1442 struct scic_sds_phy *sci_phy)
1443{
1444 u32 scu_sas_pcfg_value;
1445 u32 enable_spinup_value;
1446
1447 /* Suspend the protocol engine and place it in a sata spinup hold state */
1448 scu_sas_pcfg_value =
1449 readl(&sci_phy->link_layer_registers->phy_configuration);
1450 scu_sas_pcfg_value |=
1451 (SCU_SAS_PCFG_GEN_BIT(OOB_RESET) |
1452 SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE) |
1453 SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD));
1454 writel(scu_sas_pcfg_value,
1455 &sci_phy->link_layer_registers->phy_configuration);
1456
1457 /* Disable the notify enable spinup primitives */
1458 enable_spinup_value = readl(&sci_phy->link_layer_registers->notify_enable_spinup_control);
1459 enable_spinup_value &= ~SCU_ENSPINUP_GEN_BIT(ENABLE);
1460 writel(enable_spinup_value, &sci_phy->link_layer_registers->notify_enable_spinup_control);
1461}
1462
1463/**
1464 *
1465 *
1466 * This method will start the OOB/SN state machine for this struct scic_sds_phy object.
1467 */
1468static void scu_link_layer_start_oob(
1469 struct scic_sds_phy *sci_phy)
1470{
1471 u32 scu_sas_pcfg_value;
1472
1473 scu_sas_pcfg_value =
1474 readl(&sci_phy->link_layer_registers->phy_configuration);
1475 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
1476 scu_sas_pcfg_value &=
1477 ~(SCU_SAS_PCFG_GEN_BIT(OOB_RESET) |
1478 SCU_SAS_PCFG_GEN_BIT(HARD_RESET));
1479 writel(scu_sas_pcfg_value,
1480 &sci_phy->link_layer_registers->phy_configuration);
1481}
1482
1483/**
1484 *
1485 *
1486 * This method will transmit a hard reset request on the specified phy. The SCU
1487 * hardware requires that we reset the OOB state machine and set the hard reset
1488 * bit in the phy configuration register. We then must start OOB over with the
1489 * hard reset bit set.
1490 */
1491static void scu_link_layer_tx_hard_reset(
1492 struct scic_sds_phy *sci_phy)
1493{
1494 u32 phy_configuration_value;
1495
1496 /*
1497 * SAS Phys must wait for the HARD_RESET_TX event notification to transition
1498 * to the starting state. */
1499 phy_configuration_value =
1500 readl(&sci_phy->link_layer_registers->phy_configuration);
1501 phy_configuration_value |=
1502 (SCU_SAS_PCFG_GEN_BIT(HARD_RESET) |
1503 SCU_SAS_PCFG_GEN_BIT(OOB_RESET));
1504 writel(phy_configuration_value,
1505 &sci_phy->link_layer_registers->phy_configuration);
1506
1507 /* Now take the OOB state machine out of reset */
1508 phy_configuration_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
1509 phy_configuration_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
1510 writel(phy_configuration_value,
1511 &sci_phy->link_layer_registers->phy_configuration);
1512}
1513
1514/*
1515 * ****************************************************************************
1516 * * PHY BASE STATE METHODS
1517 * **************************************************************************** */
1518
1519/**
1520 *
1521 * @object: This is the object which is cast to a struct scic_sds_phy object.
1522 *
1523 * This method will perform the actions required by the struct scic_sds_phy on
1524 * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
1525 * handlers for the phy object base state machine initial state. none
1526 */
1527static void scic_sds_phy_initial_state_enter(void *object)
1528{
1529 struct scic_sds_phy *sci_phy = object;
1530
1531 scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_INITIAL);
1532}
1533
1534/**
1535 *
1536 * @object: This is the object which is cast to a struct scic_sds_phy object.
1537 *
1538 * This function will perform the actions required by the struct scic_sds_phy on
1539 * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
1540 * handlers for the phy object base state machine initial state. - The SCU
1541 * hardware is requested to stop the protocol engine. none
1542 */
1543static void scic_sds_phy_stopped_state_enter(void *object)
1544{
1545 struct scic_sds_phy *sci_phy = object;
1546 struct scic_sds_controller *scic = scic_sds_phy_get_controller(sci_phy);
1547 struct isci_host *ihost = scic_to_ihost(scic);
1548
1549 /*
1550 * @todo We need to get to the controller to place this PE in a
1551 * reset state
1552 */
1553
1554 scic_sds_phy_set_base_state_handlers(sci_phy,
1555 SCI_BASE_PHY_STATE_STOPPED);
1556
1557 if (sci_phy->sata_timeout_timer != NULL) {
1558 isci_del_timer(ihost, sci_phy->sata_timeout_timer);
1559
1560 sci_phy->sata_timeout_timer = NULL;
1561 }
1562
1563 scu_link_layer_stop_protocol_engine(sci_phy);
1564
1565 if (sci_phy->state_machine.previous_state_id !=
1566 SCI_BASE_PHY_STATE_INITIAL)
1567 scic_sds_controller_link_down(
1568 scic_sds_phy_get_controller(sci_phy),
1569 scic_sds_phy_get_port(sci_phy),
1570 sci_phy);
1571}
1572
1573/**
1574 *
1575 * @object: This is the object which is cast to a struct scic_sds_phy object.
1576 *
1577 * This method will perform the actions required by the struct scic_sds_phy on
1578 * entering the SCI_BASE_PHY_STATE_STARTING. - This function sets the state
1579 * handlers for the phy object base state machine starting state. - The SCU
1580 * hardware is requested to start OOB/SN on this protocl engine. - The phy
1581 * starting substate machine is started. - If the previous state was the ready
1582 * state then the struct scic_sds_controller is informed that the phy has gone link
1583 * down. none
1584 */
1585static void scic_sds_phy_starting_state_enter(void *object)
1586{
1587 struct scic_sds_phy *sci_phy = object;
1588
1589 scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_STARTING);
1590
1591 scu_link_layer_stop_protocol_engine(sci_phy);
1592 scu_link_layer_start_oob(sci_phy);
1593
1594 /* We don't know what kind of phy we are going to be just yet */
1595 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
1596 sci_phy->bcn_received_while_port_unassigned = false;
1597
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001598 if (sci_phy->state_machine.previous_state_id
1599 == SCI_BASE_PHY_STATE_READY) {
1600 scic_sds_controller_link_down(
1601 scic_sds_phy_get_controller(sci_phy),
1602 scic_sds_phy_get_port(sci_phy),
1603 sci_phy
1604 );
1605 }
Adam Gruchala4a33c522011-05-10 23:54:23 +00001606
1607 sci_base_state_machine_change_state(&sci_phy->state_machine,
1608 SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001609}
1610
1611/**
1612 *
1613 * @object: This is the object which is cast to a struct scic_sds_phy object.
1614 *
1615 * This method will perform the actions required by the struct scic_sds_phy on
1616 * entering the SCI_BASE_PHY_STATE_READY. - This function sets the state
1617 * handlers for the phy object base state machine ready state. - The SCU
1618 * hardware protocol engine is resumed. - The struct scic_sds_controller is informed
1619 * that the phy object has gone link up. none
1620 */
1621static void scic_sds_phy_ready_state_enter(void *object)
1622{
1623 struct scic_sds_phy *sci_phy = object;
1624
1625 scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_READY);
1626
1627 scic_sds_controller_link_up(
1628 scic_sds_phy_get_controller(sci_phy),
1629 scic_sds_phy_get_port(sci_phy),
1630 sci_phy
1631 );
1632}
1633
1634/**
1635 *
1636 * @object: This is the object which is cast to a struct scic_sds_phy object.
1637 *
1638 * This method will perform the actions required by the struct scic_sds_phy on exiting
1639 * the SCI_BASE_PHY_STATE_INITIAL. This function suspends the SCU hardware
1640 * protocol engine represented by this struct scic_sds_phy object. none
1641 */
1642static void scic_sds_phy_ready_state_exit(void *object)
1643{
1644 struct scic_sds_phy *sci_phy = object;
1645
1646 scic_sds_phy_suspend(sci_phy);
1647}
1648
1649/**
1650 *
1651 * @object: This is the object which is cast to a struct scic_sds_phy object.
1652 *
1653 * This method will perform the actions required by the struct scic_sds_phy on
1654 * entering the SCI_BASE_PHY_STATE_RESETTING. - This function sets the state
1655 * handlers for the phy object base state machine resetting state. none
1656 */
1657static void scic_sds_phy_resetting_state_enter(void *object)
1658{
1659 struct scic_sds_phy *sci_phy = object;
1660
1661 scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_RESETTING);
1662
1663 /*
1664 * The phy is being reset, therefore deactivate it from the port.
1665 * In the resetting state we don't notify the user regarding
1666 * link up and link down notifications. */
1667 scic_sds_port_deactivate_phy(sci_phy->owning_port, sci_phy, false);
1668
1669 if (sci_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
1670 scu_link_layer_tx_hard_reset(sci_phy);
1671 } else {
1672 /*
1673 * The SCU does not need to have a discrete reset state so
1674 * just go back to the starting state.
1675 */
1676 sci_base_state_machine_change_state(
1677 &sci_phy->state_machine,
1678 SCI_BASE_PHY_STATE_STARTING);
1679 }
1680}
1681
1682/**
1683 *
1684 * @object: This is the object which is cast to a struct scic_sds_phy object.
1685 *
1686 * This method will perform the actions required by the struct scic_sds_phy on
1687 * entering the SCI_BASE_PHY_STATE_FINAL. - This function sets the state
1688 * handlers for the phy object base state machine final state. none
1689 */
1690static void scic_sds_phy_final_state_enter(void *object)
1691{
1692 struct scic_sds_phy *sci_phy = object;
1693
1694 scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_FINAL);
1695
1696 /* Nothing to do here */
1697}
1698
1699/* --------------------------------------------------------------------------- */
1700
1701static const struct sci_base_state scic_sds_phy_state_table[] = {
1702 [SCI_BASE_PHY_STATE_INITIAL] = {
1703 .enter_state = scic_sds_phy_initial_state_enter,
1704 },
1705 [SCI_BASE_PHY_STATE_STOPPED] = {
1706 .enter_state = scic_sds_phy_stopped_state_enter,
1707 },
1708 [SCI_BASE_PHY_STATE_STARTING] = {
1709 .enter_state = scic_sds_phy_starting_state_enter,
1710 },
Adam Gruchala4a33c522011-05-10 23:54:23 +00001711 [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL] = {
1712 .enter_state = scic_sds_phy_starting_initial_substate_enter,
1713 },
1714 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN] = {
1715 .enter_state = scic_sds_phy_starting_await_ossp_en_substate_enter,
1716 },
1717 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN] = {
1718 .enter_state = scic_sds_phy_starting_await_sas_speed_en_substate_enter,
1719 },
1720 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF] = {
1721 .enter_state = scic_sds_phy_starting_await_iaf_uf_substate_enter,
1722 },
1723 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER] = {
1724 .enter_state = scic_sds_phy_starting_await_sas_power_substate_enter,
1725 .exit_state = scic_sds_phy_starting_await_sas_power_substate_exit,
1726 },
1727 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER] = {
1728 .enter_state = scic_sds_phy_starting_await_sata_power_substate_enter,
1729 .exit_state = scic_sds_phy_starting_await_sata_power_substate_exit
1730 },
1731 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN] = {
1732 .enter_state = scic_sds_phy_starting_await_sata_phy_substate_enter,
1733 .exit_state = scic_sds_phy_starting_await_sata_phy_substate_exit
1734 },
1735 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN] = {
1736 .enter_state = scic_sds_phy_starting_await_sata_speed_substate_enter,
1737 .exit_state = scic_sds_phy_starting_await_sata_speed_substate_exit
1738 },
1739 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF] = {
1740 .enter_state = scic_sds_phy_starting_await_sig_fis_uf_substate_enter,
1741 .exit_state = scic_sds_phy_starting_await_sig_fis_uf_substate_exit
1742 },
1743 [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL] = {
1744 .enter_state = scic_sds_phy_starting_final_substate_enter,
1745 },
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001746 [SCI_BASE_PHY_STATE_READY] = {
1747 .enter_state = scic_sds_phy_ready_state_enter,
1748 .exit_state = scic_sds_phy_ready_state_exit,
1749 },
1750 [SCI_BASE_PHY_STATE_RESETTING] = {
1751 .enter_state = scic_sds_phy_resetting_state_enter,
1752 },
1753 [SCI_BASE_PHY_STATE_FINAL] = {
1754 .enter_state = scic_sds_phy_final_state_enter,
1755 },
1756};
1757
1758void scic_sds_phy_construct(struct scic_sds_phy *sci_phy,
1759 struct scic_sds_port *owning_port, u8 phy_index)
1760{
1761 sci_base_state_machine_construct(&sci_phy->state_machine,
1762 sci_phy,
1763 scic_sds_phy_state_table,
1764 SCI_BASE_PHY_STATE_INITIAL);
1765
1766 sci_base_state_machine_start(&sci_phy->state_machine);
1767
1768 /* Copy the rest of the input data to our locals */
1769 sci_phy->owning_port = owning_port;
1770 sci_phy->phy_index = phy_index;
1771 sci_phy->bcn_received_while_port_unassigned = false;
1772 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
1773 sci_phy->link_layer_registers = NULL;
1774 sci_phy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
1775 sci_phy->sata_timeout_timer = NULL;
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001776}
Dan Williams6f231dd2011-07-02 22:56:22 -07001777
Dan Williams4b339812011-05-06 17:36:38 -07001778void isci_phy_init(struct isci_phy *iphy, struct isci_host *ihost, int index)
Dan Williams6f231dd2011-07-02 22:56:22 -07001779{
Dan Williams150fc6f2011-02-25 10:25:21 -08001780 union scic_oem_parameters oem;
Dan Williams4b339812011-05-06 17:36:38 -07001781 u64 sci_sas_addr;
1782 __be64 sas_addr;
Dan Williams6f231dd2011-07-02 22:56:22 -07001783
Dan Williams4b339812011-05-06 17:36:38 -07001784 scic_oem_parameters_get(&ihost->sci, &oem);
1785 sci_sas_addr = oem.sds1.phys[index].sas_address.high;
1786 sci_sas_addr <<= 32;
1787 sci_sas_addr |= oem.sds1.phys[index].sas_address.low;
1788 sas_addr = cpu_to_be64(sci_sas_addr);
1789 memcpy(iphy->sas_addr, &sas_addr, sizeof(sas_addr));
Dan Williams6f231dd2011-07-02 22:56:22 -07001790
Dan Williams4b339812011-05-06 17:36:38 -07001791 iphy->isci_port = NULL;
1792 iphy->sas_phy.enabled = 0;
1793 iphy->sas_phy.id = index;
1794 iphy->sas_phy.sas_addr = &iphy->sas_addr[0];
1795 iphy->sas_phy.frame_rcvd = (u8 *)&iphy->frame_rcvd;
1796 iphy->sas_phy.ha = &ihost->sas_ha;
1797 iphy->sas_phy.lldd_phy = iphy;
1798 iphy->sas_phy.enabled = 1;
1799 iphy->sas_phy.class = SAS;
1800 iphy->sas_phy.iproto = SAS_PROTOCOL_ALL;
1801 iphy->sas_phy.tproto = 0;
1802 iphy->sas_phy.type = PHY_TYPE_PHYSICAL;
1803 iphy->sas_phy.role = PHY_ROLE_INITIATOR;
1804 iphy->sas_phy.oob_mode = OOB_NOT_CONNECTED;
1805 iphy->sas_phy.linkrate = SAS_LINK_RATE_UNKNOWN;
1806 memset(&iphy->frame_rcvd, 0, sizeof(iphy->frame_rcvd));
Dan Williams6f231dd2011-07-02 22:56:22 -07001807}
1808
1809
1810/**
1811 * isci_phy_control() - This function is one of the SAS Domain Template
1812 * functions. This is a phy management function.
1813 * @phy: This parameter specifies the sphy being controlled.
1814 * @func: This parameter specifies the phy control function being invoked.
1815 * @buf: This parameter is specific to the phy function being invoked.
1816 *
1817 * status, zero indicates success.
1818 */
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001819int isci_phy_control(struct asd_sas_phy *sas_phy,
1820 enum phy_func func,
1821 void *buf)
Dan Williams6f231dd2011-07-02 22:56:22 -07001822{
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001823 int ret = 0;
1824 struct isci_phy *iphy = sas_phy->lldd_phy;
1825 struct isci_port *iport = iphy->isci_port;
1826 struct isci_host *ihost = sas_phy->ha->lldd_ha;
1827 unsigned long flags;
Dan Williams6f231dd2011-07-02 22:56:22 -07001828
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001829 dev_dbg(&ihost->pdev->dev,
1830 "%s: phy %p; func %d; buf %p; isci phy %p, port %p\n",
1831 __func__, sas_phy, func, buf, iphy, iport);
Dan Williams6f231dd2011-07-02 22:56:22 -07001832
1833 switch (func) {
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001834 case PHY_FUNC_DISABLE:
1835 spin_lock_irqsave(&ihost->scic_lock, flags);
Dan Williams4b339812011-05-06 17:36:38 -07001836 scic_sds_phy_stop(&iphy->sci);
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001837 spin_unlock_irqrestore(&ihost->scic_lock, flags);
1838 break;
1839
Dan Williams6f231dd2011-07-02 22:56:22 -07001840 case PHY_FUNC_LINK_RESET:
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001841 spin_lock_irqsave(&ihost->scic_lock, flags);
Dan Williams4b339812011-05-06 17:36:38 -07001842 scic_sds_phy_stop(&iphy->sci);
1843 scic_sds_phy_start(&iphy->sci);
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001844 spin_unlock_irqrestore(&ihost->scic_lock, flags);
1845 break;
1846
1847 case PHY_FUNC_HARD_RESET:
1848 if (!iport)
1849 return -ENODEV;
Dan Williams6f231dd2011-07-02 22:56:22 -07001850
1851 /* Perform the port reset. */
Dan Williams4393aa42011-03-31 13:10:44 -07001852 ret = isci_port_perform_hard_reset(ihost, iport, iphy);
Dan Williams6f231dd2011-07-02 22:56:22 -07001853
1854 break;
1855
Dan Williams6f231dd2011-07-02 22:56:22 -07001856 default:
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001857 dev_dbg(&ihost->pdev->dev,
1858 "%s: phy %p; func %d NOT IMPLEMENTED!\n",
1859 __func__, sas_phy, func);
1860 ret = -ENOSYS;
Dan Williams6f231dd2011-07-02 22:56:22 -07001861 break;
1862 }
1863 return ret;
1864}