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