isci: renaming sas_capabilities to scic_phy_cap
[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
DJ
438 struct sas_identify_frame *iaf;
439
1dea554f 440 iaf = &sci_phy->phy_type.sas_id_frame;
4b7ebd05 441 memcpy(sas_address, iaf->sas_addr, SAS_ADDR_SIZE);
6f231dda
DW
442}
443
6f231dda 444void scic_sds_phy_get_protocols(
e2023b87 445 struct scic_sds_phy *sci_phy,
6f231dda
DW
446 struct sci_sas_identify_address_frame_protocols *protocols)
447{
bc99aa47 448 protocols->u.all =
e2023b87 449 (u16)(readl(&sci_phy->
bc99aa47
CH
450 link_layer_registers->transmit_identification) &
451 0x0000FFFF);
6f231dda
DW
452}
453
6f231dda 454void scic_sds_phy_get_attached_phy_protocols(
e2023b87 455 struct scic_sds_phy *sci_phy,
6f231dda
DW
456 struct sci_sas_identify_address_frame_protocols *protocols)
457{
458 protocols->u.all = 0;
459
e2023b87 460 if (sci_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
4b7ebd05
DJ
461 struct sas_identify_frame *iaf;
462
1dea554f 463 iaf = &sci_phy->phy_type.sas_id_frame;
4b7ebd05 464 memcpy(&protocols->u.all, &iaf->initiator_bits, 2);
e2023b87 465 } else if (sci_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) {
6f231dda
DW
466 protocols->u.bits.stp_target = 1;
467 }
468}
469
470/*
471 * *****************************************************************************
472 * * SCIC SDS PHY Handler Redirects
473 * ***************************************************************************** */
474
475/**
476 * This method will attempt to start the phy object. This request is only valid
477 * when the phy is in the stopped state
4d07f7f3 478 * @sci_phy:
6f231dda
DW
479 *
480 * enum sci_status
481 */
4d07f7f3 482enum sci_status scic_sds_phy_start(struct scic_sds_phy *sci_phy)
6f231dda 483{
d857d9a0 484 return sci_phy->state_handlers->start_handler(sci_phy);
6f231dda
DW
485}
486
487/**
488 * This method will attempt to stop the phy object.
4d07f7f3 489 * @sci_phy:
6f231dda 490 *
4d07f7f3
DJ
491 * enum sci_status SCI_SUCCESS if the phy is going to stop SCI_INVALID_STATE
492 * if the phy is not in a valid state to stop
6f231dda 493 */
4d07f7f3 494enum sci_status scic_sds_phy_stop(struct scic_sds_phy *sci_phy)
6f231dda 495{
d857d9a0 496 return sci_phy->state_handlers->stop_handler(sci_phy);
6f231dda
DW
497}
498
499/**
500 * This method will attempt to reset the phy. This request is only valid when
501 * the phy is in an ready state
e2023b87 502 * @sci_phy:
6f231dda
DW
503 *
504 * enum sci_status
505 */
506enum sci_status scic_sds_phy_reset(
e2023b87 507 struct scic_sds_phy *sci_phy)
6f231dda 508{
e2023b87 509 return sci_phy->state_handlers->reset_handler(sci_phy);
6f231dda
DW
510}
511
512/**
513 * This method will process the event code received.
e2023b87 514 * @sci_phy:
6f231dda
DW
515 * @event_code:
516 *
517 * enum sci_status
518 */
519enum sci_status scic_sds_phy_event_handler(
e2023b87 520 struct scic_sds_phy *sci_phy,
6f231dda
DW
521 u32 event_code)
522{
e2023b87 523 return sci_phy->state_handlers->event_handler(sci_phy, event_code);
6f231dda
DW
524}
525
526/**
527 * This method will process the frame index received.
e2023b87 528 * @sci_phy:
6f231dda
DW
529 * @frame_index:
530 *
531 * enum sci_status
532 */
533enum sci_status scic_sds_phy_frame_handler(
e2023b87 534 struct scic_sds_phy *sci_phy,
6f231dda
DW
535 u32 frame_index)
536{
e2023b87 537 return sci_phy->state_handlers->frame_handler(sci_phy, frame_index);
6f231dda
DW
538}
539
540/**
541 * This method will give the phy permission to consume power
e2023b87 542 * @sci_phy:
6f231dda
DW
543 *
544 * enum sci_status
545 */
546enum sci_status scic_sds_phy_consume_power_handler(
e2023b87 547 struct scic_sds_phy *sci_phy)
6f231dda 548{
e2023b87 549 return sci_phy->state_handlers->consume_power_handler(sci_phy);
6f231dda
DW
550}
551
552/*
553 * *****************************************************************************
554 * * SCIC PHY Public Methods
555 * ***************************************************************************** */
556
557
558enum sci_status scic_sas_phy_get_properties(
559 struct scic_sds_phy *sci_phy,
560 struct scic_sas_phy_properties *properties)
561{
562 if (sci_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
4b7ebd05 563 memcpy(&properties->rcvd_iaf,
1dea554f 564 &sci_phy->phy_type.sas_id_frame,
4b7ebd05 565 sizeof(struct sas_identify_frame));
6f231dda 566
ed0e2483 567 properties->rcvd_cap.all =
bc99aa47 568 readl(&sci_phy->link_layer_registers->receive_phycap);
6f231dda
DW
569
570 return SCI_SUCCESS;
571 }
572
573 return SCI_FAILURE;
574}
575
576
577enum sci_status scic_sata_phy_get_properties(
578 struct scic_sds_phy *sci_phy,
579 struct scic_sata_phy_properties *properties)
580{
581 if (sci_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) {
f2f30080 582 memcpy(&properties->signature_fis,
1dea554f 583 &sci_phy->phy_type.sata_sig_fis,
f2f30080 584 sizeof(struct dev_to_host_fis));
6f231dda
DW
585
586 /* / @todo add support for port selectors. */
587 properties->is_port_selector_present = false;
588
589 return SCI_SUCCESS;
590 }
591
592 return SCI_FAILURE;
593}
594
595/*
596 * *****************************************************************************
597 * * SCIC SDS PHY HELPER FUNCTIONS
598 * ***************************************************************************** */
599
600
601/**
602 *
e2023b87 603 * @sci_phy: The phy object that received SAS PHY DETECTED.
6f231dda
DW
604 *
605 * This method continues the link training for the phy as if it were a SAS PHY
606 * instead of a SATA PHY. This is done because the completion queue had a SAS
607 * PHY DETECTED event when the state machine was expecting a SATA PHY event.
608 * none
609 */
610static void scic_sds_phy_start_sas_link_training(
e2023b87 611 struct scic_sds_phy *sci_phy)
6f231dda
DW
612{
613 u32 phy_control;
614
bc99aa47 615 phy_control =
e2023b87 616 readl(&sci_phy->link_layer_registers->phy_configuration);
6f231dda 617 phy_control |= SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD);
bc99aa47 618 writel(phy_control,
e2023b87 619 &sci_phy->link_layer_registers->phy_configuration);
6f231dda
DW
620
621 sci_base_state_machine_change_state(
e2023b87 622 &sci_phy->starting_substate_machine,
6f231dda
DW
623 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
624 );
625
e2023b87 626 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SAS;
6f231dda
DW
627}
628
629/**
630 *
e2023b87 631 * @sci_phy: The phy object that received a SATA SPINUP HOLD event
6f231dda
DW
632 *
633 * This method continues the link training for the phy as if it were a SATA PHY
634 * instead of a SAS PHY. This is done because the completion queue had a SATA
635 * SPINUP HOLD event when the state machine was expecting a SAS PHY event. none
636 */
637static void scic_sds_phy_start_sata_link_training(
e2023b87 638 struct scic_sds_phy *sci_phy)
6f231dda
DW
639{
640 sci_base_state_machine_change_state(
e2023b87 641 &sci_phy->starting_substate_machine,
6f231dda
DW
642 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
643 );
644
e2023b87 645 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
6f231dda
DW
646}
647
648/**
068b2c03
DW
649 * scic_sds_phy_complete_link_training - perform processing common to
650 * all protocols upon completion of link training.
651 * @sci_phy: This parameter specifies the phy object for which link training
6f231dda
DW
652 * has completed.
653 * @max_link_rate: This parameter specifies the maximum link rate to be
654 * associated with this phy.
655 * @next_state: This parameter specifies the next state for the phy's starting
656 * sub-state machine.
657 *
658 */
659static void scic_sds_phy_complete_link_training(
068b2c03 660 struct scic_sds_phy *sci_phy,
26bace34 661 enum sas_linkrate max_link_rate,
6f231dda
DW
662 u32 next_state)
663{
068b2c03 664 sci_phy->max_negotiated_speed = max_link_rate;
6f231dda 665
068b2c03
DW
666 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
667 next_state);
6f231dda
DW
668}
669
6f231dda 670static void scic_sds_phy_restart_starting_state(
068b2c03 671 struct scic_sds_phy *sci_phy)
6f231dda
DW
672{
673 /* Stop the current substate machine */
068b2c03 674 sci_base_state_machine_stop(&sci_phy->starting_substate_machine);
6f231dda
DW
675
676 /* Re-enter the base state machine starting state */
d857d9a0 677 sci_base_state_machine_change_state(&sci_phy->state_machine,
068b2c03 678 SCI_BASE_PHY_STATE_STARTING);
6f231dda
DW
679}
680
c658b109
PM
681/* ****************************************************************************
682 * SCIC SDS PHY general handlers
683 ************************************************************************** */
684static enum sci_status scic_sds_phy_starting_substate_general_stop_handler(
d857d9a0 685 struct scic_sds_phy *phy)
c658b109 686{
d857d9a0 687 sci_base_state_machine_stop(&phy->starting_substate_machine);
c658b109
PM
688
689 sci_base_state_machine_change_state(&phy->state_machine,
690 SCI_BASE_PHY_STATE_STOPPED);
691
692 return SCI_SUCCESS;
693}
694
6f231dda
DW
695/*
696 * *****************************************************************************
697 * * SCIC SDS PHY EVENT_HANDLERS
698 * ***************************************************************************** */
699
700/**
701 *
702 * @phy: This struct scic_sds_phy object which has received an event.
703 * @event_code: This is the event code which the phy object is to decode.
704 *
705 * This method is called when an event notification is received for the phy
706 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. -
707 * decode the event - sas phy detected causes a state transition to the wait
708 * for speed event notification. - any other events log a warning message and
709 * set a failure status enum sci_status SCI_SUCCESS on any valid event notification
710 * SCI_FAILURE on any unexpected event notifation
711 */
712static enum sci_status scic_sds_phy_starting_substate_await_ossp_event_handler(
e2023b87 713 struct scic_sds_phy *sci_phy,
6f231dda
DW
714 u32 event_code)
715{
716 u32 result = SCI_SUCCESS;
717
718 switch (scu_get_event_code(event_code)) {
719 case SCU_EVENT_SAS_PHY_DETECTED:
e2023b87
DJ
720 scic_sds_phy_start_sas_link_training(sci_phy);
721 sci_phy->is_in_link_training = true;
6f231dda
DW
722 break;
723
724 case SCU_EVENT_SATA_SPINUP_HOLD:
e2023b87
DJ
725 scic_sds_phy_start_sata_link_training(sci_phy);
726 sci_phy->is_in_link_training = true;
6f231dda
DW
727 break;
728
729 default:
e2023b87 730 dev_dbg(sciphy_to_dev(sci_phy),
d7628d05
DJ
731 "%s: PHY starting substate machine received "
732 "unexpected event_code %x\n",
733 __func__,
734 event_code);
6f231dda
DW
735
736 result = SCI_FAILURE;
737 break;
738 }
739
740 return result;
741}
742
743/**
744 *
745 * @phy: This struct scic_sds_phy object which has received an event.
746 * @event_code: This is the event code which the phy object is to decode.
747 *
748 * This method is called when an event notification is received for the phy
749 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. -
750 * decode the event - sas phy detected returns us back to this state. - speed
751 * event detected causes a state transition to the wait for iaf. - identify
752 * timeout is an un-expected event and the state machine is restarted. - link
753 * failure events restart the starting state machine - any other events log a
754 * warning message and set a failure status enum sci_status SCI_SUCCESS on any valid
755 * event notification SCI_FAILURE on any unexpected event notifation
756 */
757static enum sci_status scic_sds_phy_starting_substate_await_sas_phy_speed_event_handler(
e2023b87 758 struct scic_sds_phy *sci_phy,
6f231dda
DW
759 u32 event_code)
760{
761 u32 result = SCI_SUCCESS;
762
763 switch (scu_get_event_code(event_code)) {
764 case SCU_EVENT_SAS_PHY_DETECTED:
765 /*
766 * Why is this being reported again by the controller?
767 * We would re-enter this state so just stay here */
768 break;
769
770 case SCU_EVENT_SAS_15:
771 case SCU_EVENT_SAS_15_SSC:
772 scic_sds_phy_complete_link_training(
e2023b87
DJ
773 sci_phy,
774 SAS_LINK_RATE_1_5_GBPS,
775 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF);
6f231dda
DW
776 break;
777
778 case SCU_EVENT_SAS_30:
779 case SCU_EVENT_SAS_30_SSC:
780 scic_sds_phy_complete_link_training(
e2023b87
DJ
781 sci_phy,
782 SAS_LINK_RATE_3_0_GBPS,
783 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF);
6f231dda
DW
784 break;
785
786 case SCU_EVENT_SAS_60:
787 case SCU_EVENT_SAS_60_SSC:
788 scic_sds_phy_complete_link_training(
e2023b87
DJ
789 sci_phy,
790 SAS_LINK_RATE_6_0_GBPS,
791 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF);
6f231dda
DW
792 break;
793
794 case SCU_EVENT_SATA_SPINUP_HOLD:
795 /*
796 * We were doing SAS PHY link training and received a SATA PHY event
797 * continue OOB/SN as if this were a SATA PHY */
e2023b87 798 scic_sds_phy_start_sata_link_training(sci_phy);
6f231dda
DW
799 break;
800
801 case SCU_EVENT_LINK_FAILURE:
802 /* Link failure change state back to the starting state */
e2023b87 803 scic_sds_phy_restart_starting_state(sci_phy);
6f231dda
DW
804 break;
805
806 default:
e2023b87 807 dev_warn(sciphy_to_dev(sci_phy),
6f231dda
DW
808 "%s: PHY starting substate machine received "
809 "unexpected event_code %x\n",
810 __func__,
811 event_code);
812
813 result = SCI_FAILURE;
814 break;
815 }
816
817 return result;
818}
819
820/**
821 *
822 * @phy: This struct scic_sds_phy object which has received an event.
823 * @event_code: This is the event code which the phy object is to decode.
824 *
825 * This method is called when an event notification is received for the phy
826 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. -
827 * decode the event - sas phy detected event backs up the state machine to the
828 * await speed notification. - identify timeout is an un-expected event and the
829 * state machine is restarted. - link failure events restart the starting state
830 * machine - any other events log a warning message and set a failure status
831 * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any
832 * unexpected event notifation
833 */
834static enum sci_status scic_sds_phy_starting_substate_await_iaf_uf_event_handler(
e2023b87 835 struct scic_sds_phy *sci_phy,
6f231dda
DW
836 u32 event_code)
837{
838 u32 result = SCI_SUCCESS;
839
840 switch (scu_get_event_code(event_code)) {
841 case SCU_EVENT_SAS_PHY_DETECTED:
842 /* Backup the state machine */
e2023b87 843 scic_sds_phy_start_sas_link_training(sci_phy);
6f231dda
DW
844 break;
845
846 case SCU_EVENT_SATA_SPINUP_HOLD:
847 /*
848 * We were doing SAS PHY link training and received a SATA PHY event
849 * continue OOB/SN as if this were a SATA PHY */
e2023b87 850 scic_sds_phy_start_sata_link_training(sci_phy);
6f231dda
DW
851 break;
852
853 case SCU_EVENT_RECEIVED_IDENTIFY_TIMEOUT:
854 case SCU_EVENT_LINK_FAILURE:
855 case SCU_EVENT_HARD_RESET_RECEIVED:
856 /* Start the oob/sn state machine over again */
e2023b87 857 scic_sds_phy_restart_starting_state(sci_phy);
6f231dda
DW
858 break;
859
860 default:
e2023b87 861 dev_warn(sciphy_to_dev(sci_phy),
6f231dda
DW
862 "%s: PHY starting substate machine received "
863 "unexpected event_code %x\n",
864 __func__,
865 event_code);
866
867 result = SCI_FAILURE;
868 break;
869 }
870
871 return result;
872}
873
874/**
875 *
876 * @phy: This struct scic_sds_phy object which has received an event.
877 * @event_code: This is the event code which the phy object is to decode.
878 *
879 * This method is called when an event notification is received for the phy
880 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_POWER. -
881 * decode the event - link failure events restart the starting state machine -
882 * any other events log a warning message and set a failure status enum sci_status
883 * SCI_SUCCESS on a link failure event SCI_FAILURE on any unexpected event
884 * notifation
885 */
886static enum sci_status scic_sds_phy_starting_substate_await_sas_power_event_handler(
e2023b87 887 struct scic_sds_phy *sci_phy,
6f231dda
DW
888 u32 event_code)
889{
890 u32 result = SCI_SUCCESS;
891
892 switch (scu_get_event_code(event_code)) {
893 case SCU_EVENT_LINK_FAILURE:
894 /* Link failure change state back to the starting state */
e2023b87 895 scic_sds_phy_restart_starting_state(sci_phy);
6f231dda
DW
896 break;
897
898 default:
e2023b87 899 dev_warn(sciphy_to_dev(sci_phy),
6f231dda
DW
900 "%s: PHY starting substate machine received unexpected "
901 "event_code %x\n",
902 __func__,
903 event_code);
904
905 result = SCI_FAILURE;
906 break;
907 }
908
909 return result;
910}
911
912/**
913 *
914 * @phy: This struct scic_sds_phy object which has received an event.
915 * @event_code: This is the event code which the phy object is to decode.
916 *
917 * This method is called when an event notification is received for the phy
918 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. -
919 * decode the event - link failure events restart the starting state machine -
920 * sata spinup hold events are ignored since they are expected - any other
921 * events log a warning message and set a failure status enum sci_status SCI_SUCCESS
922 * on a link failure event SCI_FAILURE on any unexpected event notifation
923 */
924static enum sci_status scic_sds_phy_starting_substate_await_sata_power_event_handler(
e2023b87 925 struct scic_sds_phy *sci_phy,
6f231dda
DW
926 u32 event_code)
927{
928 u32 result = SCI_SUCCESS;
929
930 switch (scu_get_event_code(event_code)) {
931 case SCU_EVENT_LINK_FAILURE:
932 /* Link failure change state back to the starting state */
e2023b87 933 scic_sds_phy_restart_starting_state(sci_phy);
6f231dda
DW
934 break;
935
936 case SCU_EVENT_SATA_SPINUP_HOLD:
937 /* These events are received every 10ms and are expected while in this state */
938 break;
939
940 case SCU_EVENT_SAS_PHY_DETECTED:
941 /*
942 * There has been a change in the phy type before OOB/SN for the
943 * SATA finished start down the SAS link traning path. */
e2023b87 944 scic_sds_phy_start_sas_link_training(sci_phy);
6f231dda
DW
945 break;
946
947 default:
e2023b87 948 dev_warn(sciphy_to_dev(sci_phy),
6f231dda
DW
949 "%s: PHY starting substate machine received "
950 "unexpected event_code %x\n",
951 __func__,
952 event_code);
953
954 result = SCI_FAILURE;
955 break;
956 }
957
958 return result;
959}
960
961/**
068b2c03 962 * scic_sds_phy_starting_substate_await_sata_phy_event_handler -
6f231dda
DW
963 * @phy: This struct scic_sds_phy object which has received an event.
964 * @event_code: This is the event code which the phy object is to decode.
965 *
966 * This method is called when an event notification is received for the phy
967 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. -
968 * decode the event - link failure events restart the starting state machine -
969 * sata spinup hold events are ignored since they are expected - sata phy
970 * detected event change to the wait speed event - any other events log a
971 * warning message and set a failure status enum sci_status SCI_SUCCESS on a link
972 * failure event SCI_FAILURE on any unexpected event notifation
973 */
974static enum sci_status scic_sds_phy_starting_substate_await_sata_phy_event_handler(
068b2c03 975 struct scic_sds_phy *sci_phy, u32 event_code)
6f231dda
DW
976{
977 u32 result = SCI_SUCCESS;
978
979 switch (scu_get_event_code(event_code)) {
980 case SCU_EVENT_LINK_FAILURE:
981 /* Link failure change state back to the starting state */
068b2c03 982 scic_sds_phy_restart_starting_state(sci_phy);
6f231dda
DW
983 break;
984
985 case SCU_EVENT_SATA_SPINUP_HOLD:
068b2c03
DW
986 /* These events might be received since we dont know how many may be in
987 * the completion queue while waiting for power
988 */
6f231dda
DW
989 break;
990
991 case SCU_EVENT_SATA_PHY_DETECTED:
068b2c03 992 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
6f231dda
DW
993
994 /* We have received the SATA PHY notification change state */
068b2c03
DW
995 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
996 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN);
6f231dda
DW
997 break;
998
999 case SCU_EVENT_SAS_PHY_DETECTED:
068b2c03
DW
1000 /* There has been a change in the phy type before OOB/SN for the
1001 * SATA finished start down the SAS link traning path.
1002 */
1003 scic_sds_phy_start_sas_link_training(sci_phy);
6f231dda
DW
1004 break;
1005
1006 default:
068b2c03 1007 dev_warn(sciphy_to_dev(sci_phy),
6f231dda
DW
1008 "%s: PHY starting substate machine received "
1009 "unexpected event_code %x\n",
1010 __func__,
1011 event_code);
1012
1013 result = SCI_FAILURE;
1014 break;
1015 }
1016
1017 return result;
1018}
1019
1020/**
1021 *
1022 * @phy: This struct scic_sds_phy object which has received an event.
1023 * @event_code: This is the event code which the phy object is to decode.
1024 *
1025 * This method is called when an event notification is received for the phy
1026 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN.
1027 * - decode the event - sata phy detected returns us back to this state. -
1028 * speed event detected causes a state transition to the wait for signature. -
1029 * link failure events restart the starting state machine - any other events
1030 * log a warning message and set a failure status enum sci_status SCI_SUCCESS on any
1031 * valid event notification SCI_FAILURE on any unexpected event notifation
1032 */
1033static enum sci_status scic_sds_phy_starting_substate_await_sata_speed_event_handler(
e2023b87 1034 struct scic_sds_phy *sci_phy,
6f231dda
DW
1035 u32 event_code)
1036{
1037 u32 result = SCI_SUCCESS;
1038
1039 switch (scu_get_event_code(event_code)) {
1040 case SCU_EVENT_SATA_PHY_DETECTED:
1041 /*
1042 * The hardware reports multiple SATA PHY detected events
1043 * ignore the extras */
1044 break;
1045
1046 case SCU_EVENT_SATA_15:
1047 case SCU_EVENT_SATA_15_SSC:
1048 scic_sds_phy_complete_link_training(
e2023b87 1049 sci_phy,
26bace34 1050 SAS_LINK_RATE_1_5_GBPS,
e2023b87 1051 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
6f231dda
DW
1052 break;
1053
1054 case SCU_EVENT_SATA_30:
1055 case SCU_EVENT_SATA_30_SSC:
1056 scic_sds_phy_complete_link_training(
e2023b87 1057 sci_phy,
26bace34 1058 SAS_LINK_RATE_3_0_GBPS,
e2023b87 1059 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
6f231dda
DW
1060 break;
1061
1062 case SCU_EVENT_SATA_60:
1063 case SCU_EVENT_SATA_60_SSC:
1064 scic_sds_phy_complete_link_training(
e2023b87 1065 sci_phy,
26bace34 1066 SAS_LINK_RATE_6_0_GBPS,
e2023b87 1067 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
6f231dda
DW
1068 break;
1069
1070 case SCU_EVENT_LINK_FAILURE:
1071 /* Link failure change state back to the starting state */
e2023b87 1072 scic_sds_phy_restart_starting_state(sci_phy);
6f231dda
DW
1073 break;
1074
1075 case SCU_EVENT_SAS_PHY_DETECTED:
1076 /*
1077 * There has been a change in the phy type before OOB/SN for the
1078 * SATA finished start down the SAS link traning path. */
e2023b87 1079 scic_sds_phy_start_sas_link_training(sci_phy);
6f231dda
DW
1080 break;
1081
1082 default:
e2023b87 1083 dev_warn(sciphy_to_dev(sci_phy),
6f231dda
DW
1084 "%s: PHY starting substate machine received "
1085 "unexpected event_code %x\n",
1086 __func__,
1087 event_code);
1088
1089 result = SCI_FAILURE;
1090 break;
1091 }
1092
1093 return result;
1094}
1095
1096/**
068b2c03 1097 * scic_sds_phy_starting_substate_await_sig_fis_event_handler -
6f231dda
DW
1098 * @phy: This struct scic_sds_phy object which has received an event.
1099 * @event_code: This is the event code which the phy object is to decode.
1100 *
1101 * This method is called when an event notification is received for the phy
1102 * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. -
1103 * decode the event - sas phy detected event backs up the state machine to the
1104 * await speed notification. - identify timeout is an un-expected event and the
1105 * state machine is restarted. - link failure events restart the starting state
1106 * machine - any other events log a warning message and set a failure status
1107 * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any
1108 * unexpected event notifation
1109 */
1110static enum sci_status scic_sds_phy_starting_substate_await_sig_fis_event_handler(
068b2c03 1111 struct scic_sds_phy *sci_phy, u32 event_code)
6f231dda
DW
1112{
1113 u32 result = SCI_SUCCESS;
1114
1115 switch (scu_get_event_code(event_code)) {
1116 case SCU_EVENT_SATA_PHY_DETECTED:
1117 /* Backup the state machine */
068b2c03
DW
1118 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
1119 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN);
6f231dda
DW
1120 break;
1121
1122 case SCU_EVENT_LINK_FAILURE:
1123 /* Link failure change state back to the starting state */
068b2c03 1124 scic_sds_phy_restart_starting_state(sci_phy);
6f231dda
DW
1125 break;
1126
1127 default:
068b2c03 1128 dev_warn(sciphy_to_dev(sci_phy),
6f231dda
DW
1129 "%s: PHY starting substate machine received "
1130 "unexpected event_code %x\n",
1131 __func__,
1132 event_code);
1133
1134 result = SCI_FAILURE;
1135 break;
1136 }
1137
1138 return result;
1139}
1140
1141
1142/*
1143 * *****************************************************************************
1144 * * SCIC SDS PHY FRAME_HANDLERS
1145 * ***************************************************************************** */
1146
1147/**
1148 *
1149 * @phy: This is struct scic_sds_phy object which is being requested to decode the
1150 * frame data.
1151 * @frame_index: This is the index of the unsolicited frame which was received
1152 * for this phy.
1153 *
1154 * This method decodes the unsolicited frame when the struct scic_sds_phy is in the
1155 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - Get the UF Header - If the UF
1156 * is an IAF - Copy IAF data to local phy object IAF data buffer. - Change
1157 * starting substate to wait power. - else - log warning message of unexpected
1158 * unsolicted frame - release frame buffer enum sci_status SCI_SUCCESS
1159 */
1160static enum sci_status scic_sds_phy_starting_substate_await_iaf_uf_frame_handler(
068b2c03 1161 struct scic_sds_phy *sci_phy, u32 frame_index)
6f231dda
DW
1162{
1163 enum sci_status result;
1164 u32 *frame_words;
4b7ebd05 1165 struct sas_identify_frame *identify_frame;
6f231dda
DW
1166
1167 result = scic_sds_unsolicited_frame_control_get_header(
068b2c03 1168 &(scic_sds_phy_get_controller(sci_phy)->uf_control),
6f231dda
DW
1169 frame_index,
1170 (void **)&frame_words);
1171
1172 if (result != SCI_SUCCESS) {
1173 return result;
1174 }
1175
1176 frame_words[0] = SCIC_SWAP_DWORD(frame_words[0]);
4b7ebd05 1177 identify_frame = (struct sas_identify_frame *)frame_words;
6f231dda 1178
4b7ebd05 1179 if (identify_frame->frame_type == 0) {
068b2c03
DW
1180 u32 state;
1181
1182 /* Byte swap the rest of the frame so we can make
1183 * a copy of the buffer
1184 */
6f231dda
DW
1185 frame_words[1] = SCIC_SWAP_DWORD(frame_words[1]);
1186 frame_words[2] = SCIC_SWAP_DWORD(frame_words[2]);
1187 frame_words[3] = SCIC_SWAP_DWORD(frame_words[3]);
1188 frame_words[4] = SCIC_SWAP_DWORD(frame_words[4]);
1189 frame_words[5] = SCIC_SWAP_DWORD(frame_words[5]);
1190
1dea554f 1191 memcpy(&sci_phy->phy_type.sas_id_frame,
6f231dda 1192 identify_frame,
4b7ebd05 1193 sizeof(struct sas_identify_frame));
6f231dda 1194
4b7ebd05 1195 if (identify_frame->smp_tport) {
068b2c03
DW
1196 /* We got the IAF for an expander PHY go to the final state since
1197 * there are no power requirements for expander phys.
1198 */
1199 state = SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL;
6f231dda
DW
1200 } else {
1201 /* We got the IAF we can now go to the await spinup semaphore state */
068b2c03 1202 state = SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER;
6f231dda 1203 }
068b2c03
DW
1204 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
1205 state);
6f231dda
DW
1206 result = SCI_SUCCESS;
1207 } else
068b2c03 1208 dev_warn(sciphy_to_dev(sci_phy),
6f231dda
DW
1209 "%s: PHY starting substate machine received "
1210 "unexpected frame id %x\n",
1211 __func__,
1212 frame_index);
1213
1214 /* Regardless of the result release this frame since we are done with it */
068b2c03
DW
1215 scic_sds_controller_release_frame(scic_sds_phy_get_controller(sci_phy),
1216 frame_index);
6f231dda
DW
1217
1218 return result;
1219}
1220
1221/**
1222 *
1223 * @phy: This is struct scic_sds_phy object which is being requested to decode the
1224 * frame data.
1225 * @frame_index: This is the index of the unsolicited frame which was received
1226 * for this phy.
1227 *
1228 * This method decodes the unsolicited frame when the struct scic_sds_phy is in the
1229 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Get the UF Header - If
1230 * the UF is an SIGNATURE FIS - Copy IAF data to local phy object SIGNATURE FIS
1231 * data buffer. - else - log warning message of unexpected unsolicted frame -
1232 * release frame buffer enum sci_status SCI_SUCCESS Must decode the SIGNATURE FIS
1233 * data
1234 */
1235static enum sci_status scic_sds_phy_starting_substate_await_sig_fis_frame_handler(
068b2c03 1236 struct scic_sds_phy *sci_phy,
6f231dda
DW
1237 u32 frame_index)
1238{
1239 enum sci_status result;
e76d6180 1240 struct dev_to_host_fis *frame_header;
6f231dda
DW
1241 u32 *fis_frame_data;
1242
1243 result = scic_sds_unsolicited_frame_control_get_header(
068b2c03 1244 &(scic_sds_phy_get_controller(sci_phy)->uf_control),
6f231dda 1245 frame_index,
e76d6180 1246 (void **)&frame_header);
6f231dda 1247
e76d6180 1248 if (result != SCI_SUCCESS)
6f231dda 1249 return result;
6f231dda 1250
e76d6180
DJ
1251 if ((frame_header->fis_type == FIS_REGD2H) &&
1252 !(frame_header->status & ATA_BUSY)) {
6f231dda 1253 scic_sds_unsolicited_frame_control_get_buffer(
068b2c03 1254 &(scic_sds_phy_get_controller(sci_phy)->uf_control),
6f231dda 1255 frame_index,
068b2c03 1256 (void **)&fis_frame_data);
6f231dda
DW
1257
1258 scic_sds_controller_copy_sata_response(
1dea554f 1259 &sci_phy->phy_type.sata_sig_fis,
e76d6180 1260 frame_header,
068b2c03 1261 fis_frame_data);
6f231dda 1262
e76d6180 1263 /* got IAF we can now go to the await spinup semaphore state */
068b2c03
DW
1264 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
1265 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL);
6f231dda
DW
1266
1267 result = SCI_SUCCESS;
1268 } else
068b2c03 1269 dev_warn(sciphy_to_dev(sci_phy),
6f231dda
DW
1270 "%s: PHY starting substate machine received "
1271 "unexpected frame id %x\n",
1272 __func__,
1273 frame_index);
1274
e76d6180 1275 /* Regardless of the result we are done with this frame with it */
068b2c03
DW
1276 scic_sds_controller_release_frame(scic_sds_phy_get_controller(sci_phy),
1277 frame_index);
6f231dda
DW
1278
1279 return result;
1280}
1281
1282/*
1283 * *****************************************************************************
1284 * * SCIC SDS PHY POWER_HANDLERS
1285 * ***************************************************************************** */
1286
d857d9a0 1287/*
6f231dda
DW
1288 * This method is called by the struct scic_sds_controller when the phy object is
1289 * granted power. - The notify enable spinups are turned on for this phy object
1290 * - The phy state machine is transitioned to the
1291 * SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. enum sci_status SCI_SUCCESS
1292 */
1293static enum sci_status scic_sds_phy_starting_substate_await_sas_power_consume_power_handler(
068b2c03 1294 struct scic_sds_phy *sci_phy)
6f231dda
DW
1295{
1296 u32 enable_spinup;
1297
bc99aa47 1298 enable_spinup = readl(&sci_phy->link_layer_registers->notify_enable_spinup_control);
6f231dda 1299 enable_spinup |= SCU_ENSPINUP_GEN_BIT(ENABLE);
bc99aa47 1300 writel(enable_spinup, &sci_phy->link_layer_registers->notify_enable_spinup_control);
6f231dda
DW
1301
1302 /* Change state to the final state this substate machine has run to completion */
068b2c03
DW
1303 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
1304 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL);
6f231dda
DW
1305
1306 return SCI_SUCCESS;
1307}
1308
d857d9a0 1309/*
6f231dda
DW
1310 * This method is called by the struct scic_sds_controller when the phy object is
1311 * granted power. - The phy state machine is transitioned to the
1312 * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. enum sci_status SCI_SUCCESS
1313 */
1314static enum sci_status scic_sds_phy_starting_substate_await_sata_power_consume_power_handler(
068b2c03 1315 struct scic_sds_phy *sci_phy)
6f231dda
DW
1316{
1317 u32 scu_sas_pcfg_value;
1318
1319 /* Release the spinup hold state and reset the OOB state machine */
bc99aa47
CH
1320 scu_sas_pcfg_value =
1321 readl(&sci_phy->link_layer_registers->phy_configuration);
6f231dda
DW
1322 scu_sas_pcfg_value &=
1323 ~(SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD) | SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE));
1324 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
bc99aa47
CH
1325 writel(scu_sas_pcfg_value,
1326 &sci_phy->link_layer_registers->phy_configuration);
6f231dda
DW
1327
1328 /* Now restart the OOB operation */
1329 scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
1330 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
bc99aa47
CH
1331 writel(scu_sas_pcfg_value,
1332 &sci_phy->link_layer_registers->phy_configuration);
6f231dda
DW
1333
1334 /* Change state to the final state this substate machine has run to completion */
068b2c03
DW
1335 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
1336 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN);
6f231dda
DW
1337
1338 return SCI_SUCCESS;
1339}
1340
d857d9a0
MT
1341static enum sci_status default_phy_handler(struct scic_sds_phy *sci_phy,
1342 const char *func)
35173d57 1343{
35173d57
DW
1344 dev_dbg(sciphy_to_dev(sci_phy),
1345 "%s: in wrong state: %d\n", func,
d857d9a0 1346 sci_base_state_machine_get_state(&sci_phy->state_machine));
35173d57
DW
1347 return SCI_FAILURE_INVALID_STATE;
1348}
1349
d857d9a0
MT
1350static enum sci_status
1351scic_sds_phy_default_start_handler(struct scic_sds_phy *sci_phy)
35173d57 1352{
d857d9a0 1353 return default_phy_handler(sci_phy, __func__);
35173d57
DW
1354}
1355
d857d9a0
MT
1356static enum sci_status
1357scic_sds_phy_default_stop_handler(struct scic_sds_phy *sci_phy)
35173d57 1358{
d857d9a0 1359 return default_phy_handler(sci_phy, __func__);
35173d57
DW
1360}
1361
d857d9a0
MT
1362static enum sci_status
1363scic_sds_phy_default_reset_handler(struct scic_sds_phy *sci_phy)
35173d57 1364{
d857d9a0 1365 return default_phy_handler(sci_phy, __func__);
35173d57
DW
1366}
1367
d857d9a0
MT
1368static enum sci_status
1369scic_sds_phy_default_destroy_handler(struct scic_sds_phy *sci_phy)
35173d57 1370{
d857d9a0 1371 return default_phy_handler(sci_phy, __func__);
35173d57
DW
1372}
1373
d857d9a0
MT
1374static enum sci_status
1375scic_sds_phy_default_frame_handler(struct scic_sds_phy *sci_phy,
1376 u32 frame_index)
35173d57
DW
1377{
1378 struct scic_sds_controller *scic = scic_sds_phy_get_controller(sci_phy);
1379
d857d9a0 1380 default_phy_handler(sci_phy, __func__);
35173d57
DW
1381 scic_sds_controller_release_frame(scic, frame_index);
1382
1383 return SCI_FAILURE_INVALID_STATE;
1384}
1385
d857d9a0
MT
1386static enum sci_status
1387scic_sds_phy_default_event_handler(struct scic_sds_phy *sci_phy,
1388 u32 event_code)
35173d57 1389{
d857d9a0 1390 return default_phy_handler(sci_phy, __func__);
35173d57
DW
1391}
1392
d857d9a0
MT
1393static enum sci_status
1394scic_sds_phy_default_consume_power_handler(struct scic_sds_phy *sci_phy)
35173d57 1395{
d857d9a0 1396 return default_phy_handler(sci_phy, __func__);
35173d57
DW
1397}
1398
1399
1400
1401static const struct scic_sds_phy_state_handler scic_sds_phy_starting_substate_handler_table[] = {
8f31550c 1402 [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL] = {
d857d9a0
MT
1403 .start_handler = scic_sds_phy_default_start_handler,
1404 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1405 .reset_handler = scic_sds_phy_default_reset_handler,
1406 .destruct_handler = scic_sds_phy_default_destroy_handler,
1407 .frame_handler = scic_sds_phy_default_frame_handler,
1408 .event_handler = scic_sds_phy_default_event_handler,
1409 .consume_power_handler = scic_sds_phy_default_consume_power_handler
6f231dda 1410 },
8f31550c 1411 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN] = {
d857d9a0
MT
1412 .start_handler = scic_sds_phy_default_start_handler,
1413 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1414 .reset_handler = scic_sds_phy_default_reset_handler,
1415 .destruct_handler = scic_sds_phy_default_destroy_handler,
1416 .frame_handler = scic_sds_phy_default_frame_handler,
1417 .event_handler = scic_sds_phy_starting_substate_await_ossp_event_handler,
1418 .consume_power_handler = scic_sds_phy_default_consume_power_handler
6f231dda 1419 },
8f31550c 1420 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN] = {
d857d9a0
MT
1421 .start_handler = scic_sds_phy_default_start_handler,
1422 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1423 .reset_handler = scic_sds_phy_default_reset_handler,
1424 .destruct_handler = scic_sds_phy_default_destroy_handler,
1425 .frame_handler = scic_sds_phy_default_frame_handler,
1426 .event_handler = scic_sds_phy_starting_substate_await_sas_phy_speed_event_handler,
1427 .consume_power_handler = scic_sds_phy_default_consume_power_handler
6f231dda 1428 },
8f31550c 1429 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF] = {
d857d9a0
MT
1430 .start_handler = scic_sds_phy_default_start_handler,
1431 .stop_handler = scic_sds_phy_default_stop_handler,
1432 .reset_handler = scic_sds_phy_default_reset_handler,
1433 .destruct_handler = scic_sds_phy_default_destroy_handler,
1434 .frame_handler = scic_sds_phy_starting_substate_await_iaf_uf_frame_handler,
1435 .event_handler = scic_sds_phy_starting_substate_await_iaf_uf_event_handler,
1436 .consume_power_handler = scic_sds_phy_default_consume_power_handler
6f231dda 1437 },
8f31550c 1438 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER] = {
d857d9a0
MT
1439 .start_handler = scic_sds_phy_default_start_handler,
1440 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1441 .reset_handler = scic_sds_phy_default_reset_handler,
1442 .destruct_handler = scic_sds_phy_default_destroy_handler,
1443 .frame_handler = scic_sds_phy_default_frame_handler,
1444 .event_handler = scic_sds_phy_starting_substate_await_sas_power_event_handler,
1445 .consume_power_handler = scic_sds_phy_starting_substate_await_sas_power_consume_power_handler
6f231dda 1446 },
8f31550c 1447 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER] = {
d857d9a0
MT
1448 .start_handler = scic_sds_phy_default_start_handler,
1449 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1450 .reset_handler = scic_sds_phy_default_reset_handler,
1451 .destruct_handler = scic_sds_phy_default_destroy_handler,
1452 .frame_handler = scic_sds_phy_default_frame_handler,
1453 .event_handler = scic_sds_phy_starting_substate_await_sata_power_event_handler,
1454 .consume_power_handler = scic_sds_phy_starting_substate_await_sata_power_consume_power_handler
6f231dda 1455 },
8f31550c 1456 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN] = {
d857d9a0
MT
1457 .start_handler = scic_sds_phy_default_start_handler,
1458 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1459 .reset_handler = scic_sds_phy_default_reset_handler,
1460 .destruct_handler = scic_sds_phy_default_destroy_handler,
1461 .frame_handler = scic_sds_phy_default_frame_handler,
1462 .event_handler = scic_sds_phy_starting_substate_await_sata_phy_event_handler,
1463 .consume_power_handler = scic_sds_phy_default_consume_power_handler
6f231dda 1464 },
8f31550c 1465 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN] = {
d857d9a0
MT
1466 .start_handler = scic_sds_phy_default_start_handler,
1467 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1468 .reset_handler = scic_sds_phy_default_reset_handler,
1469 .destruct_handler = scic_sds_phy_default_destroy_handler,
1470 .frame_handler = scic_sds_phy_default_frame_handler,
1471 .event_handler = scic_sds_phy_starting_substate_await_sata_speed_event_handler,
1472 .consume_power_handler = scic_sds_phy_default_consume_power_handler
6f231dda 1473 },
8f31550c 1474 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF] = {
d857d9a0
MT
1475 .start_handler = scic_sds_phy_default_start_handler,
1476 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1477 .reset_handler = scic_sds_phy_default_reset_handler,
1478 .destruct_handler = scic_sds_phy_default_destroy_handler,
1479 .frame_handler = scic_sds_phy_starting_substate_await_sig_fis_frame_handler,
1480 .event_handler = scic_sds_phy_starting_substate_await_sig_fis_event_handler,
1481 .consume_power_handler = scic_sds_phy_default_consume_power_handler
6f231dda 1482 },
8f31550c 1483 [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL] = {
d857d9a0
MT
1484 .start_handler = scic_sds_phy_default_start_handler,
1485 .stop_handler = scic_sds_phy_starting_substate_general_stop_handler,
1486 .reset_handler = scic_sds_phy_default_reset_handler,
1487 .destruct_handler = scic_sds_phy_default_destroy_handler,
8f31550c
DW
1488 .frame_handler = scic_sds_phy_default_frame_handler,
1489 .event_handler = scic_sds_phy_default_event_handler,
1490 .consume_power_handler = scic_sds_phy_default_consume_power_handler
6f231dda
DW
1491 }
1492};
1493
1494/**
1495 * scic_sds_phy_set_starting_substate_handlers() -
1496 *
1497 * This macro sets the starting substate handlers by state_id
1498 */
1499#define scic_sds_phy_set_starting_substate_handlers(phy, state_id) \
1500 scic_sds_phy_set_state_handlers(\
1501 (phy), \
1502 &scic_sds_phy_starting_substate_handler_table[(state_id)] \
1503 )
1504
1505/*
1506 * ****************************************************************************
1507 * * PHY STARTING SUBSTATE METHODS
1508 * **************************************************************************** */
1509
1510/**
068b2c03 1511 * scic_sds_phy_starting_initial_substate_enter -
9a0fff7b 1512 * @object: This is the object which is cast to a struct scic_sds_phy object.
6f231dda
DW
1513 *
1514 * This method will perform the actions required by the struct scic_sds_phy on
1515 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL. - The initial state
1516 * handlers are put in place for the struct scic_sds_phy object. - The state is
1517 * changed to the wait phy type event notification. none
1518 */
9a0fff7b 1519static void scic_sds_phy_starting_initial_substate_enter(void *object)
6f231dda 1520{
e1e72a00 1521 struct scic_sds_phy *sci_phy = object;
6f231dda
DW
1522
1523 scic_sds_phy_set_starting_substate_handlers(
068b2c03 1524 sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL);
6f231dda
DW
1525
1526 /* This is just an temporary state go off to the starting state */
068b2c03
DW
1527 sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
1528 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN);
6f231dda
DW
1529}
1530
1531/**
1532 *
9a0fff7b 1533 * @object: This is the object which is cast to a struct scic_sds_phy object.
6f231dda
DW
1534 *
1535 * This method will perform the actions required by the struct scic_sds_phy on
1536 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_PHY_TYPE_EN. - Set the
1537 * struct scic_sds_phy object state handlers for this state. none
1538 */
9a0fff7b 1539static void scic_sds_phy_starting_await_ossp_en_substate_enter(void *object)
6f231dda 1540{
e1e72a00 1541 struct scic_sds_phy *sci_phy = object;
6f231dda
DW
1542
1543 scic_sds_phy_set_starting_substate_handlers(
e2023b87 1544 sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
6f231dda
DW
1545 );
1546}
1547
1548/**
1549 *
9a0fff7b 1550 * @object: This is the object which is cast to a struct scic_sds_phy object.
6f231dda
DW
1551 *
1552 * This method will perform the actions required by the struct scic_sds_phy on
1553 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. - Set the
1554 * struct scic_sds_phy object state handlers for this state. none
1555 */
1556static void scic_sds_phy_starting_await_sas_speed_en_substate_enter(
9a0fff7b 1557 void *object)
6f231dda 1558{
e1e72a00 1559 struct scic_sds_phy *sci_phy = object;
6f231dda
DW
1560
1561 scic_sds_phy_set_starting_substate_handlers(
e2023b87 1562 sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
6f231dda
DW
1563 );
1564}
1565
1566/**
1567 *
9a0fff7b 1568 * @object: This is the object which is cast to a struct scic_sds_phy object.
6f231dda
DW
1569 *
1570 * This method will perform the actions required by the struct scic_sds_phy on
1571 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - Set the
1572 * struct scic_sds_phy object state handlers for this state. none
1573 */
9a0fff7b 1574static void scic_sds_phy_starting_await_iaf_uf_substate_enter(void *object)
6f231dda 1575{
e1e72a00 1576 struct scic_sds_phy *sci_phy = object;
6f231dda
DW
1577
1578 scic_sds_phy_set_starting_substate_handlers(
e2023b87 1579 sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
6f231dda
DW
1580 );
1581}
1582
1583/**
1584 *
9a0fff7b 1585 * @object: This is the object which is cast to a struct scic_sds_phy object.
6f231dda
DW
1586 *
1587 * This method will perform the actions required by the struct scic_sds_phy on
1588 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Set the
1589 * struct scic_sds_phy object state handlers for this state. - Add this phy object to
1590 * the power control queue none
1591 */
9a0fff7b 1592static void scic_sds_phy_starting_await_sas_power_substate_enter(void *object)
6f231dda 1593{
e1e72a00 1594 struct scic_sds_phy *sci_phy = object;
6f231dda
DW
1595
1596 scic_sds_phy_set_starting_substate_handlers(
e2023b87 1597 sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
6f231dda
DW
1598 );
1599
1600 scic_sds_controller_power_control_queue_insert(
e2023b87
DJ
1601 scic_sds_phy_get_controller(sci_phy),
1602 sci_phy
6f231dda
DW
1603 );
1604}
1605
1606/**
1607 *
9a0fff7b 1608 * @object: This is the object which is cast to a struct scic_sds_phy object.
6f231dda
DW
1609 *
1610 * This method will perform the actions required by the struct scic_sds_phy on exiting
1611 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Remove the
1612 * struct scic_sds_phy object from the power control queue. none
1613 */
9a0fff7b 1614static void scic_sds_phy_starting_await_sas_power_substate_exit(void *object)
6f231dda 1615{
e1e72a00 1616 struct scic_sds_phy *sci_phy = object;
6f231dda
DW
1617
1618 scic_sds_controller_power_control_queue_remove(
e2023b87 1619 scic_sds_phy_get_controller(sci_phy), sci_phy
6f231dda
DW
1620 );
1621}
1622
1623/**
1624 *
9a0fff7b 1625 * @object: This is the object which is cast to a struct scic_sds_phy object.
6f231dda
DW
1626 *
1627 * This method will perform the actions required by the struct scic_sds_phy on
1628 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Set the
1629 * struct scic_sds_phy object state handlers for this state. - Add this phy object to
1630 * the power control queue none
1631 */
9a0fff7b 1632static void scic_sds_phy_starting_await_sata_power_substate_enter(void *object)
6f231dda 1633{
e1e72a00 1634 struct scic_sds_phy *sci_phy = object;
6f231dda
DW
1635
1636 scic_sds_phy_set_starting_substate_handlers(
e2023b87 1637 sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
6f231dda
DW
1638 );
1639
1640 scic_sds_controller_power_control_queue_insert(
e2023b87
DJ
1641 scic_sds_phy_get_controller(sci_phy),
1642 sci_phy
6f231dda
DW
1643 );
1644}
1645
1646/**
1647 *
9a0fff7b 1648 * @object: This is the object which is cast to a struct scic_sds_phy object.
6f231dda
DW
1649 *
1650 * This method will perform the actions required by the struct scic_sds_phy on exiting
1651 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Remove the
1652 * struct scic_sds_phy object from the power control queue. none
1653 */
9a0fff7b 1654static void scic_sds_phy_starting_await_sata_power_substate_exit(void *object)
6f231dda 1655{
e1e72a00 1656 struct scic_sds_phy *sci_phy = object;
6f231dda
DW
1657
1658 scic_sds_controller_power_control_queue_remove(
e2023b87
DJ
1659 scic_sds_phy_get_controller(sci_phy),
1660 sci_phy
6f231dda
DW
1661 );
1662}
1663
1664/**
1665 *
9a0fff7b 1666 * @object: This is the object which is cast to a struct scic_sds_phy object.
6f231dda 1667 *
09d7da13 1668 * This function will perform the actions required by the struct scic_sds_phy on
6f231dda
DW
1669 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. - Set the
1670 * struct scic_sds_phy object state handlers for this state. none
1671 */
9a0fff7b 1672static void scic_sds_phy_starting_await_sata_phy_substate_enter(void *object)
6f231dda 1673{
e1e72a00 1674 struct scic_sds_phy *sci_phy = object;
6f231dda
DW
1675
1676 scic_sds_phy_set_starting_substate_handlers(
09d7da13
DJ
1677 sci_phy,
1678 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN);
6f231dda 1679
09d7da13
DJ
1680 isci_timer_start(sci_phy->sata_timeout_timer,
1681 SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
6f231dda
DW
1682}
1683
1684/**
1685 *
9a0fff7b 1686 * @object: This is the object which is cast to a struct scic_sds_phy object.
6f231dda 1687 *
09d7da13
DJ
1688 * This method will perform the actions required by the struct scic_sds_phy
1689 * on exiting
6f231dda
DW
1690 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
1691 * that was started on entry to await sata phy event notification none
1692 */
09d7da13 1693static inline void scic_sds_phy_starting_await_sata_phy_substate_exit(
9a0fff7b 1694 void *object)
6f231dda 1695{
e1e72a00 1696 struct scic_sds_phy *sci_phy = object;
6f231dda 1697
09d7da13 1698 isci_timer_stop(sci_phy->sata_timeout_timer);
6f231dda
DW
1699}
1700
1701/**
1702 *
9a0fff7b 1703 * @object: This is the object which is cast to a struct scic_sds_phy object.
6f231dda
DW
1704 *
1705 * This method will perform the actions required by the struct scic_sds_phy on
1706 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - Set the
1707 * struct scic_sds_phy object state handlers for this state. none
1708 */
9a0fff7b 1709static void scic_sds_phy_starting_await_sata_speed_substate_enter(void *object)
6f231dda 1710{
e1e72a00 1711 struct scic_sds_phy *sci_phy = object;
6f231dda
DW
1712
1713 scic_sds_phy_set_starting_substate_handlers(
09d7da13
DJ
1714 sci_phy,
1715 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN);
6f231dda 1716
09d7da13
DJ
1717 isci_timer_start(sci_phy->sata_timeout_timer,
1718 SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
6f231dda
DW
1719}
1720
1721/**
1722 *
9a0fff7b 1723 * @object: This is the object which is cast to a struct scic_sds_phy object.
6f231dda 1724 *
09d7da13
DJ
1725 * This function will perform the actions required by the
1726 * struct scic_sds_phy on exiting
6f231dda
DW
1727 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
1728 * that was started on entry to await sata phy event notification none
1729 */
09d7da13 1730static inline void scic_sds_phy_starting_await_sata_speed_substate_exit(
9a0fff7b 1731 void *object)
6f231dda 1732{
e1e72a00 1733 struct scic_sds_phy *sci_phy = object;
6f231dda 1734
09d7da13 1735 isci_timer_stop(sci_phy->sata_timeout_timer);
6f231dda
DW
1736}
1737
1738/**
1739 *
9a0fff7b 1740 * @object: This is the object which is cast to a struct scic_sds_phy object.
6f231dda 1741 *
09d7da13 1742 * This function will perform the actions required by the struct scic_sds_phy on
6f231dda 1743 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Set the
09d7da13
DJ
1744 * struct scic_sds_phy object state handlers for this state.
1745 * - Start the SIGNATURE FIS
6f231dda
DW
1746 * timeout timer none
1747 */
9a0fff7b 1748static void scic_sds_phy_starting_await_sig_fis_uf_substate_enter(void *object)
6f231dda
DW
1749{
1750 bool continue_to_ready_state;
e1e72a00 1751 struct scic_sds_phy *sci_phy = object;
6f231dda
DW
1752
1753 scic_sds_phy_set_starting_substate_handlers(
09d7da13
DJ
1754 sci_phy,
1755 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
6f231dda
DW
1756
1757 continue_to_ready_state = scic_sds_port_link_detected(
09d7da13
DJ
1758 sci_phy->owning_port,
1759 sci_phy);
6f231dda
DW
1760
1761 if (continue_to_ready_state) {
1762 /*
09d7da13
DJ
1763 * Clear the PE suspend condition so we can actually
1764 * receive SIG FIS
1765 * The hardware will not respond to the XRDY until the PE
1766 * suspend condition is cleared.
1767 */
1768 scic_sds_phy_resume(sci_phy);
1769
1770 isci_timer_start(sci_phy->sata_timeout_timer,
1771 SCIC_SDS_SIGNATURE_FIS_TIMEOUT);
1772 } else
1773 sci_phy->is_in_link_training = false;
6f231dda
DW
1774}
1775
1776/**
1777 *
9a0fff7b 1778 * @object: This is the object which is cast to a struct scic_sds_phy object.
6f231dda 1779 *
09d7da13
DJ
1780 * This function will perform the actions required by the
1781 * struct scic_sds_phy on exiting
6f231dda
DW
1782 * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Stop the SIGNATURE
1783 * FIS timeout timer. none
1784 */
09d7da13 1785static inline void scic_sds_phy_starting_await_sig_fis_uf_substate_exit(
9a0fff7b 1786 void *object)
6f231dda 1787{
e1e72a00 1788 struct scic_sds_phy *sci_phy = object;
6f231dda 1789
09d7da13 1790 isci_timer_stop(sci_phy->sata_timeout_timer);
6f231dda
DW
1791}
1792
1793/**
1794 *
9a0fff7b 1795 * @object: This is the object which is cast to a struct scic_sds_phy object.
6f231dda
DW
1796 *
1797 * This method will perform the actions required by the struct scic_sds_phy on
1798 * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. - Set the struct scic_sds_phy
1799 * object state handlers for this state. - Change base state machine to the
1800 * ready state. none
1801 */
9a0fff7b 1802static void scic_sds_phy_starting_final_substate_enter(void *object)
6f231dda 1803{
e1e72a00 1804 struct scic_sds_phy *sci_phy = object;
6f231dda 1805
068b2c03
DW
1806 scic_sds_phy_set_starting_substate_handlers(sci_phy,
1807 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL);
6f231dda 1808
068b2c03
DW
1809 /* State machine has run to completion so exit out and change
1810 * the base state machine to the ready state
1811 */
d857d9a0 1812 sci_base_state_machine_change_state(&sci_phy->state_machine,
068b2c03 1813 SCI_BASE_PHY_STATE_READY);
6f231dda
DW
1814}
1815
1816/* --------------------------------------------------------------------------- */
1817
35173d57 1818static const struct sci_base_state scic_sds_phy_starting_substates[] = {
6f231dda
DW
1819 [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL] = {
1820 .enter_state = scic_sds_phy_starting_initial_substate_enter,
1821 },
1822 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN] = {
1823 .enter_state = scic_sds_phy_starting_await_ossp_en_substate_enter,
1824 },
1825 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN] = {
1826 .enter_state = scic_sds_phy_starting_await_sas_speed_en_substate_enter,
1827 },
1828 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF] = {
1829 .enter_state = scic_sds_phy_starting_await_iaf_uf_substate_enter,
1830 },
1831 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER] = {
1832 .enter_state = scic_sds_phy_starting_await_sas_power_substate_enter,
1833 .exit_state = scic_sds_phy_starting_await_sas_power_substate_exit,
1834 },
1835 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER] = {
1836 .enter_state = scic_sds_phy_starting_await_sata_power_substate_enter,
1837 .exit_state = scic_sds_phy_starting_await_sata_power_substate_exit
1838 },
1839 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN] = {
1840 .enter_state = scic_sds_phy_starting_await_sata_phy_substate_enter,
1841 .exit_state = scic_sds_phy_starting_await_sata_phy_substate_exit
1842 },
1843 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN] = {
1844 .enter_state = scic_sds_phy_starting_await_sata_speed_substate_enter,
1845 .exit_state = scic_sds_phy_starting_await_sata_speed_substate_exit
1846 },
1847 [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF] = {
1848 .enter_state = scic_sds_phy_starting_await_sig_fis_uf_substate_enter,
1849 .exit_state = scic_sds_phy_starting_await_sig_fis_uf_substate_exit
1850 },
1851 [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL] = {
1852 .enter_state = scic_sds_phy_starting_final_substate_enter,
1853 }
1854};
1855
d857d9a0 1856/*
09d7da13
DJ
1857 * This method takes the struct scic_sds_phy from a stopped state and
1858 * attempts to start it. - The phy state machine is transitioned to the
6f231dda
DW
1859 * SCI_BASE_PHY_STATE_STARTING. enum sci_status SCI_SUCCESS
1860 */
d857d9a0
MT
1861static enum sci_status
1862scic_sds_phy_stopped_state_start_handler(struct scic_sds_phy *sci_phy)
6f231dda 1863{
068b2c03 1864 struct isci_host *ihost;
068b2c03
DW
1865 struct scic_sds_controller *scic;
1866
068b2c03 1867 scic = scic_sds_phy_get_controller(sci_phy),
d3757c3a 1868 ihost = scic->ihost;
6f231dda 1869
c658b109 1870 /* Create the SIGNATURE FIS Timeout timer for this phy */
068b2c03
DW
1871 sci_phy->sata_timeout_timer = isci_timer_create(ihost, sci_phy,
1872 scic_sds_phy_sata_timeout);
1873
1874 if (sci_phy->sata_timeout_timer)
d857d9a0 1875 sci_base_state_machine_change_state(&sci_phy->state_machine,
068b2c03 1876 SCI_BASE_PHY_STATE_STARTING);
6f231dda
DW
1877
1878 return SCI_SUCCESS;
1879}
1880
d857d9a0
MT
1881static enum sci_status
1882scic_sds_phy_stopped_state_destroy_handler(struct scic_sds_phy *sci_phy)
6f231dda 1883{
6f231dda
DW
1884 return SCI_SUCCESS;
1885}
1886
d857d9a0
MT
1887static enum sci_status
1888scic_sds_phy_ready_state_stop_handler(struct scic_sds_phy *sci_phy)
6f231dda 1889{
d857d9a0 1890 sci_base_state_machine_change_state(&sci_phy->state_machine,
068b2c03 1891 SCI_BASE_PHY_STATE_STOPPED);
6f231dda
DW
1892
1893 return SCI_SUCCESS;
1894}
1895
d857d9a0
MT
1896static enum sci_status
1897scic_sds_phy_ready_state_reset_handler(struct scic_sds_phy *sci_phy)
6f231dda 1898{
d857d9a0 1899 sci_base_state_machine_change_state(&sci_phy->state_machine,
068b2c03 1900 SCI_BASE_PHY_STATE_RESETTING);
6f231dda
DW
1901
1902 return SCI_SUCCESS;
1903}
1904
1905/**
068b2c03 1906 * scic_sds_phy_ready_state_event_handler -
6f231dda
DW
1907 * @phy: This is the struct scic_sds_phy object which has received the event.
1908 *
1909 * This method request the struct scic_sds_phy handle the received event. The only
1910 * event that we are interested in while in the ready state is the link failure
1911 * event. - decoded event is a link failure - transition the struct scic_sds_phy back
068b2c03 1912 * to the SCI_BASE_PHY_STATE_STARTING state. - any other event received will
6f231dda
DW
1913 * report a warning message enum sci_status SCI_SUCCESS if the event received is a
1914 * link failure SCI_FAILURE_INVALID_STATE for any other event received.
1915 */
068b2c03
DW
1916static enum sci_status scic_sds_phy_ready_state_event_handler(struct scic_sds_phy *sci_phy,
1917 u32 event_code)
6f231dda
DW
1918{
1919 enum sci_status result = SCI_FAILURE;
1920
1921 switch (scu_get_event_code(event_code)) {
1922 case SCU_EVENT_LINK_FAILURE:
1923 /* Link failure change state back to the starting state */
d857d9a0 1924 sci_base_state_machine_change_state(&sci_phy->state_machine,
068b2c03 1925 SCI_BASE_PHY_STATE_STARTING);
6f231dda
DW
1926 result = SCI_SUCCESS;
1927 break;
1928
1929 case SCU_EVENT_BROADCAST_CHANGE:
1930 /* Broadcast change received. Notify the port. */
068b2c03
DW
1931 if (scic_sds_phy_get_port(sci_phy) != NULL)
1932 scic_sds_port_broadcast_change_received(sci_phy->owning_port, sci_phy);
6f231dda 1933 else
068b2c03 1934 sci_phy->bcn_received_while_port_unassigned = true;
6f231dda
DW
1935 break;
1936
1937 default:
068b2c03 1938 dev_warn(sciphy_to_dev(sci_phy),
6f231dda
DW
1939 "%sP SCIC PHY 0x%p ready state machine received "
1940 "unexpected event_code %x\n",
068b2c03 1941 __func__, sci_phy, event_code);
6f231dda
DW
1942
1943 result = SCI_FAILURE_INVALID_STATE;
1944 break;
1945 }
1946
1947 return result;
1948}
1949
068b2c03
DW
1950static enum sci_status scic_sds_phy_resetting_state_event_handler(struct scic_sds_phy *sci_phy,
1951 u32 event_code)
6f231dda
DW
1952{
1953 enum sci_status result = SCI_FAILURE;
1954
1955 switch (scu_get_event_code(event_code)) {
1956 case SCU_EVENT_HARD_RESET_TRANSMITTED:
1957 /* Link failure change state back to the starting state */
d857d9a0 1958 sci_base_state_machine_change_state(&sci_phy->state_machine,
068b2c03 1959 SCI_BASE_PHY_STATE_STARTING);
6f231dda
DW
1960 result = SCI_SUCCESS;
1961 break;
1962
1963 default:
068b2c03 1964 dev_warn(sciphy_to_dev(sci_phy),
6f231dda
DW
1965 "%s: SCIC PHY 0x%p resetting state machine received "
1966 "unexpected event_code %x\n",
068b2c03 1967 __func__, sci_phy, event_code);
6f231dda
DW
1968
1969 result = SCI_FAILURE_INVALID_STATE;
1970 break;
1971 }
1972
1973 return result;
1974}
1975
1976/* --------------------------------------------------------------------------- */
1977
35173d57 1978static const struct scic_sds_phy_state_handler scic_sds_phy_state_handler_table[] = {
8f31550c 1979 [SCI_BASE_PHY_STATE_INITIAL] = {
d857d9a0
MT
1980 .start_handler = scic_sds_phy_default_start_handler,
1981 .stop_handler = scic_sds_phy_default_stop_handler,
1982 .reset_handler = scic_sds_phy_default_reset_handler,
1983 .destruct_handler = scic_sds_phy_default_destroy_handler,
8f31550c
DW
1984 .frame_handler = scic_sds_phy_default_frame_handler,
1985 .event_handler = scic_sds_phy_default_event_handler,
1986 .consume_power_handler = scic_sds_phy_default_consume_power_handler
6f231dda 1987 },
8f31550c 1988 [SCI_BASE_PHY_STATE_STOPPED] = {
d857d9a0
MT
1989 .start_handler = scic_sds_phy_stopped_state_start_handler,
1990 .stop_handler = scic_sds_phy_default_stop_handler,
1991 .reset_handler = scic_sds_phy_default_reset_handler,
1992 .destruct_handler = scic_sds_phy_stopped_state_destroy_handler,
8f31550c
DW
1993 .frame_handler = scic_sds_phy_default_frame_handler,
1994 .event_handler = scic_sds_phy_default_event_handler,
1995 .consume_power_handler = scic_sds_phy_default_consume_power_handler
6f231dda 1996 },
8f31550c 1997 [SCI_BASE_PHY_STATE_STARTING] = {
d857d9a0
MT
1998 .start_handler = scic_sds_phy_default_start_handler,
1999 .stop_handler = scic_sds_phy_default_stop_handler,
2000 .reset_handler = scic_sds_phy_default_reset_handler,
2001 .destruct_handler = scic_sds_phy_default_destroy_handler,
8f31550c
DW
2002 .frame_handler = scic_sds_phy_default_frame_handler,
2003 .event_handler = scic_sds_phy_default_event_handler,
2004 .consume_power_handler = scic_sds_phy_default_consume_power_handler
6f231dda 2005 },
8f31550c 2006 [SCI_BASE_PHY_STATE_READY] = {
d857d9a0
MT
2007 .start_handler = scic_sds_phy_default_start_handler,
2008 .stop_handler = scic_sds_phy_ready_state_stop_handler,
2009 .reset_handler = scic_sds_phy_ready_state_reset_handler,
2010 .destruct_handler = scic_sds_phy_default_destroy_handler,
8f31550c
DW
2011 .frame_handler = scic_sds_phy_default_frame_handler,
2012 .event_handler = scic_sds_phy_ready_state_event_handler,
2013 .consume_power_handler = scic_sds_phy_default_consume_power_handler
6f231dda 2014 },
8f31550c 2015 [SCI_BASE_PHY_STATE_RESETTING] = {
d857d9a0
MT
2016 .start_handler = scic_sds_phy_default_start_handler,
2017 .stop_handler = scic_sds_phy_default_stop_handler,
2018 .reset_handler = scic_sds_phy_default_reset_handler,
2019 .destruct_handler = scic_sds_phy_default_destroy_handler,
8f31550c
DW
2020 .frame_handler = scic_sds_phy_default_frame_handler,
2021 .event_handler = scic_sds_phy_resetting_state_event_handler,
2022 .consume_power_handler = scic_sds_phy_default_consume_power_handler
6f231dda 2023 },
8f31550c 2024 [SCI_BASE_PHY_STATE_FINAL] = {
d857d9a0
MT
2025 .start_handler = scic_sds_phy_default_start_handler,
2026 .stop_handler = scic_sds_phy_default_stop_handler,
2027 .reset_handler = scic_sds_phy_default_reset_handler,
2028 .destruct_handler = scic_sds_phy_default_destroy_handler,
8f31550c
DW
2029 .frame_handler = scic_sds_phy_default_frame_handler,
2030 .event_handler = scic_sds_phy_default_event_handler,
2031 .consume_power_handler = scic_sds_phy_default_consume_power_handler
6f231dda
DW
2032 }
2033};
2034
2035/*
2036 * ****************************************************************************
2037 * * PHY STATE PRIVATE METHODS
2038 * **************************************************************************** */
2039
2040/**
2041 *
e2023b87 2042 * @sci_phy: This is the struct scic_sds_phy object to stop.
6f231dda
DW
2043 *
2044 * This method will stop the struct scic_sds_phy object. This does not reset the
2045 * protocol engine it just suspends it and places it in a state where it will
2046 * not cause the end device to power up. none
2047 */
2048static void scu_link_layer_stop_protocol_engine(
e2023b87 2049 struct scic_sds_phy *sci_phy)
6f231dda
DW
2050{
2051 u32 scu_sas_pcfg_value;
2052 u32 enable_spinup_value;
2053
2054 /* Suspend the protocol engine and place it in a sata spinup hold state */
bc99aa47 2055 scu_sas_pcfg_value =
e2023b87
DJ
2056 readl(&sci_phy->link_layer_registers->phy_configuration);
2057 scu_sas_pcfg_value |=
2058 (SCU_SAS_PCFG_GEN_BIT(OOB_RESET) |
2059 SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE) |
2060 SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD));
bc99aa47 2061 writel(scu_sas_pcfg_value,
e2023b87 2062 &sci_phy->link_layer_registers->phy_configuration);
6f231dda
DW
2063
2064 /* Disable the notify enable spinup primitives */
e2023b87 2065 enable_spinup_value = readl(&sci_phy->link_layer_registers->notify_enable_spinup_control);
6f231dda 2066 enable_spinup_value &= ~SCU_ENSPINUP_GEN_BIT(ENABLE);
e2023b87 2067 writel(enable_spinup_value, &sci_phy->link_layer_registers->notify_enable_spinup_control);
6f231dda
DW
2068}
2069
2070/**
2071 *
2072 *
2073 * This method will start the OOB/SN state machine for this struct scic_sds_phy object.
2074 */
2075static void scu_link_layer_start_oob(
e2023b87 2076 struct scic_sds_phy *sci_phy)
6f231dda
DW
2077{
2078 u32 scu_sas_pcfg_value;
2079
bc99aa47 2080 scu_sas_pcfg_value =
e2023b87 2081 readl(&sci_phy->link_layer_registers->phy_configuration);
6f231dda
DW
2082 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
2083 scu_sas_pcfg_value &=
e2023b87
DJ
2084 ~(SCU_SAS_PCFG_GEN_BIT(OOB_RESET) |
2085 SCU_SAS_PCFG_GEN_BIT(HARD_RESET));
bc99aa47 2086 writel(scu_sas_pcfg_value,
e2023b87 2087 &sci_phy->link_layer_registers->phy_configuration);
6f231dda
DW
2088}
2089
2090/**
2091 *
2092 *
2093 * This method will transmit a hard reset request on the specified phy. The SCU
2094 * hardware requires that we reset the OOB state machine and set the hard reset
2095 * bit in the phy configuration register. We then must start OOB over with the
2096 * hard reset bit set.
2097 */
2098static void scu_link_layer_tx_hard_reset(
e2023b87 2099 struct scic_sds_phy *sci_phy)
6f231dda
DW
2100{
2101 u32 phy_configuration_value;
2102
2103 /*
2104 * SAS Phys must wait for the HARD_RESET_TX event notification to transition
2105 * to the starting state. */
bc99aa47 2106 phy_configuration_value =
e2023b87 2107 readl(&sci_phy->link_layer_registers->phy_configuration);
6f231dda 2108 phy_configuration_value |=
e2023b87
DJ
2109 (SCU_SAS_PCFG_GEN_BIT(HARD_RESET) |
2110 SCU_SAS_PCFG_GEN_BIT(OOB_RESET));
bc99aa47 2111 writel(phy_configuration_value,
e2023b87 2112 &sci_phy->link_layer_registers->phy_configuration);
6f231dda
DW
2113
2114 /* Now take the OOB state machine out of reset */
2115 phy_configuration_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
2116 phy_configuration_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
bc99aa47 2117 writel(phy_configuration_value,
e2023b87 2118 &sci_phy->link_layer_registers->phy_configuration);
6f231dda
DW
2119}
2120
2121/*
2122 * ****************************************************************************
2123 * * PHY BASE STATE METHODS
2124 * **************************************************************************** */
2125
2126/**
2127 *
9a0fff7b 2128 * @object: This is the object which is cast to a struct scic_sds_phy object.
6f231dda
DW
2129 *
2130 * This method will perform the actions required by the struct scic_sds_phy on
2131 * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
2132 * handlers for the phy object base state machine initial state. none
2133 */
9a0fff7b 2134static void scic_sds_phy_initial_state_enter(void *object)
6f231dda 2135{
e1e72a00 2136 struct scic_sds_phy *sci_phy = object;
6f231dda 2137
e2023b87 2138 scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_INITIAL);
6f231dda
DW
2139}
2140
2141/**
2142 *
9a0fff7b 2143 * @object: This is the object which is cast to a struct scic_sds_phy object.
6f231dda 2144 *
09d7da13 2145 * This function will perform the actions required by the struct scic_sds_phy on
6f231dda
DW
2146 * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
2147 * handlers for the phy object base state machine initial state. - The SCU
2148 * hardware is requested to stop the protocol engine. none
2149 */
9a0fff7b 2150static void scic_sds_phy_stopped_state_enter(void *object)
6f231dda 2151{
e1e72a00 2152 struct scic_sds_phy *sci_phy = object;
09d7da13 2153 struct scic_sds_controller *scic = scic_sds_phy_get_controller(sci_phy);
d3757c3a 2154 struct isci_host *ihost = scic->ihost;
6f231dda 2155
4d07f7f3
DJ
2156 /*
2157 * @todo We need to get to the controller to place this PE in a
2158 * reset state
2159 */
6f231dda 2160
09d7da13
DJ
2161 scic_sds_phy_set_base_state_handlers(sci_phy,
2162 SCI_BASE_PHY_STATE_STOPPED);
c658b109
PM
2163
2164 if (sci_phy->sata_timeout_timer != NULL) {
09d7da13 2165 isci_del_timer(ihost, sci_phy->sata_timeout_timer);
c658b109
PM
2166
2167 sci_phy->sata_timeout_timer = NULL;
2168 }
6f231dda 2169
c658b109 2170 scu_link_layer_stop_protocol_engine(sci_phy);
4d07f7f3 2171
d857d9a0 2172 if (sci_phy->state_machine.previous_state_id !=
4d07f7f3 2173 SCI_BASE_PHY_STATE_INITIAL)
09d7da13
DJ
2174 scic_sds_controller_link_down(
2175 scic_sds_phy_get_controller(sci_phy),
2176 scic_sds_phy_get_port(sci_phy),
2177 sci_phy);
6f231dda
DW
2178}
2179
2180/**
2181 *
9a0fff7b 2182 * @object: This is the object which is cast to a struct scic_sds_phy object.
6f231dda
DW
2183 *
2184 * This method will perform the actions required by the struct scic_sds_phy on
2185 * entering the SCI_BASE_PHY_STATE_STARTING. - This function sets the state
2186 * handlers for the phy object base state machine starting state. - The SCU
2187 * hardware is requested to start OOB/SN on this protocl engine. - The phy
2188 * starting substate machine is started. - If the previous state was the ready
2189 * state then the struct scic_sds_controller is informed that the phy has gone link
2190 * down. none
2191 */
9a0fff7b 2192static void scic_sds_phy_starting_state_enter(void *object)
6f231dda 2193{
e1e72a00 2194 struct scic_sds_phy *sci_phy = object;
6f231dda 2195
e2023b87 2196 scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_STARTING);
6f231dda 2197
e2023b87
DJ
2198 scu_link_layer_stop_protocol_engine(sci_phy);
2199 scu_link_layer_start_oob(sci_phy);
6f231dda
DW
2200
2201 /* We don't know what kind of phy we are going to be just yet */
e2023b87
DJ
2202 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
2203 sci_phy->bcn_received_while_port_unassigned = false;
6f231dda
DW
2204
2205 /* Change over to the starting substate machine to continue */
e2023b87 2206 sci_base_state_machine_start(&sci_phy->starting_substate_machine);
6f231dda 2207
e2023b87 2208 if (sci_phy->state_machine.previous_state_id
6f231dda
DW
2209 == SCI_BASE_PHY_STATE_READY) {
2210 scic_sds_controller_link_down(
e2023b87
DJ
2211 scic_sds_phy_get_controller(sci_phy),
2212 scic_sds_phy_get_port(sci_phy),
2213 sci_phy
6f231dda
DW
2214 );
2215 }
2216}
2217
2218/**
2219 *
9a0fff7b 2220 * @object: This is the object which is cast to a struct scic_sds_phy object.
6f231dda
DW
2221 *
2222 * This method will perform the actions required by the struct scic_sds_phy on
2223 * entering the SCI_BASE_PHY_STATE_READY. - This function sets the state
2224 * handlers for the phy object base state machine ready state. - The SCU
2225 * hardware protocol engine is resumed. - The struct scic_sds_controller is informed
2226 * that the phy object has gone link up. none
2227 */
9a0fff7b 2228static void scic_sds_phy_ready_state_enter(void *object)
6f231dda 2229{
e1e72a00 2230 struct scic_sds_phy *sci_phy = object;
6f231dda 2231
e2023b87 2232 scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_READY);
6f231dda
DW
2233
2234 scic_sds_controller_link_up(
e2023b87
DJ
2235 scic_sds_phy_get_controller(sci_phy),
2236 scic_sds_phy_get_port(sci_phy),
2237 sci_phy
6f231dda
DW
2238 );
2239}
2240
2241/**
2242 *
9a0fff7b 2243 * @object: This is the object which is cast to a struct scic_sds_phy object.
6f231dda
DW
2244 *
2245 * This method will perform the actions required by the struct scic_sds_phy on exiting
2246 * the SCI_BASE_PHY_STATE_INITIAL. This function suspends the SCU hardware
2247 * protocol engine represented by this struct scic_sds_phy object. none
2248 */
9a0fff7b 2249static void scic_sds_phy_ready_state_exit(void *object)
6f231dda 2250{
e1e72a00 2251 struct scic_sds_phy *sci_phy = object;
6f231dda 2252
e2023b87 2253 scic_sds_phy_suspend(sci_phy);
6f231dda
DW
2254}
2255
2256/**
2257 *
9a0fff7b 2258 * @object: This is the object which is cast to a struct scic_sds_phy object.
6f231dda
DW
2259 *
2260 * This method will perform the actions required by the struct scic_sds_phy on
2261 * entering the SCI_BASE_PHY_STATE_RESETTING. - This function sets the state
2262 * handlers for the phy object base state machine resetting state. none
2263 */
9a0fff7b 2264static void scic_sds_phy_resetting_state_enter(void *object)
6f231dda 2265{
e1e72a00 2266 struct scic_sds_phy *sci_phy = object;
6f231dda 2267
e2023b87 2268 scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_RESETTING);
6f231dda
DW
2269
2270 /*
2271 * The phy is being reset, therefore deactivate it from the port.
2272 * In the resetting state we don't notify the user regarding
2273 * link up and link down notifications. */
e2023b87 2274 scic_sds_port_deactivate_phy(sci_phy->owning_port, sci_phy, false);
6f231dda 2275
e2023b87
DJ
2276 if (sci_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
2277 scu_link_layer_tx_hard_reset(sci_phy);
6f231dda
DW
2278 } else {
2279 /*
e2023b87
DJ
2280 * The SCU does not need to have a discrete reset state so
2281 * just go back to the starting state.
2282 */
2283 sci_base_state_machine_change_state(
2284 &sci_phy->state_machine,
2285 SCI_BASE_PHY_STATE_STARTING);
6f231dda
DW
2286 }
2287}
2288
2289/**
2290 *
9a0fff7b 2291 * @object: This is the object which is cast to a struct scic_sds_phy object.
6f231dda
DW
2292 *
2293 * This method will perform the actions required by the struct scic_sds_phy on
2294 * entering the SCI_BASE_PHY_STATE_FINAL. - This function sets the state
2295 * handlers for the phy object base state machine final state. none
2296 */
9a0fff7b 2297static void scic_sds_phy_final_state_enter(void *object)
6f231dda 2298{
e1e72a00 2299 struct scic_sds_phy *sci_phy = object;
6f231dda 2300
e2023b87 2301 scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_FINAL);
6f231dda
DW
2302
2303 /* Nothing to do here */
2304}
2305
2306/* --------------------------------------------------------------------------- */
2307
35173d57 2308static const struct sci_base_state scic_sds_phy_state_table[] = {
6f231dda
DW
2309 [SCI_BASE_PHY_STATE_INITIAL] = {
2310 .enter_state = scic_sds_phy_initial_state_enter,
2311 },
2312 [SCI_BASE_PHY_STATE_STOPPED] = {
2313 .enter_state = scic_sds_phy_stopped_state_enter,
2314 },
2315 [SCI_BASE_PHY_STATE_STARTING] = {
2316 .enter_state = scic_sds_phy_starting_state_enter,
2317 },
2318 [SCI_BASE_PHY_STATE_READY] = {
2319 .enter_state = scic_sds_phy_ready_state_enter,
2320 .exit_state = scic_sds_phy_ready_state_exit,
2321 },
2322 [SCI_BASE_PHY_STATE_RESETTING] = {
2323 .enter_state = scic_sds_phy_resetting_state_enter,
2324 },
2325 [SCI_BASE_PHY_STATE_FINAL] = {
2326 .enter_state = scic_sds_phy_final_state_enter,
2327 },
2328};
2329
35173d57
DW
2330void scic_sds_phy_construct(struct scic_sds_phy *sci_phy,
2331 struct scic_sds_port *owning_port, u8 phy_index)
2332{
d857d9a0 2333
d857d9a0 2334 sci_base_state_machine_construct(&sci_phy->state_machine,
e1e72a00 2335 sci_phy,
d857d9a0
MT
2336 scic_sds_phy_state_table,
2337 SCI_BASE_PHY_STATE_INITIAL);
2338
2339 sci_base_state_machine_start(&sci_phy->state_machine);
35173d57
DW
2340
2341 /* Copy the rest of the input data to our locals */
2342 sci_phy->owning_port = owning_port;
2343 sci_phy->phy_index = phy_index;
2344 sci_phy->bcn_received_while_port_unassigned = false;
2345 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
2346 sci_phy->link_layer_registers = NULL;
26bace34 2347 sci_phy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
35173d57
DW
2348 sci_phy->sata_timeout_timer = NULL;
2349
2350 /* Clear out the identification buffer data */
2351 memset(&sci_phy->phy_type, 0, sizeof(sci_phy->phy_type));
2352
2353 /* Initialize the the substate machines */
2354 sci_base_state_machine_construct(&sci_phy->starting_substate_machine,
e1e72a00 2355 sci_phy,
35173d57
DW
2356 scic_sds_phy_starting_substates,
2357 SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL);
2358}
This page took 0.16143 seconds and 5 git commands to generate.