blob: 784c9a71333a3aa905bb1e5e68eaeaf0c072b4a1 [file] [log] [blame]
Dan Williams6f231dd2011-07-02 22:56:22 -07001/*
2 * This file is provided under a dual BSD/GPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
4 *
5 * GPL LICENSE SUMMARY
6 *
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
23 *
24 * BSD LICENSE
25 *
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
28 *
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
31 * are met:
32 *
33 * * Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * * Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in
37 * the documentation and/or other materials provided with the
38 * distribution.
39 * * Neither the name of Intel Corporation nor the names of its
40 * contributors may be used to endorse or promote products derived
41 * from this software without specific prior written permission.
42 *
43 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
44 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
45 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
46 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
47 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
50 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
51 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
53 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 */
55
56#include "isci.h"
Dan Williamsce2b3262011-05-08 15:49:15 -070057#include "host.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070058#include "phy.h"
Dan Williamsd35bc1b2011-05-10 02:28:45 -070059#include "scu_event_codes.h"
Dan Williamse2f8db52011-05-10 02:28:46 -070060#include "probe_roms.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070061
Dan Williamsd35bc1b2011-05-10 02:28:45 -070062/* Maximum arbitration wait time in micro-seconds */
63#define SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME (700)
64
65enum sas_linkrate sci_phy_linkrate(struct scic_sds_phy *sci_phy)
66{
67 return sci_phy->max_negotiated_speed;
68}
69
70/*
71 * *****************************************************************************
72 * * SCIC SDS PHY Internal Methods
73 * ***************************************************************************** */
74
75/**
76 * This method will initialize the phy transport layer registers
77 * @sci_phy:
78 * @transport_layer_registers
79 *
80 * enum sci_status
81 */
82static enum sci_status scic_sds_phy_transport_layer_initialization(
83 struct scic_sds_phy *sci_phy,
84 struct scu_transport_layer_registers __iomem *transport_layer_registers)
85{
86 u32 tl_control;
87
88 sci_phy->transport_layer_registers = transport_layer_registers;
89
90 writel(SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX,
91 &sci_phy->transport_layer_registers->stp_rni);
92
93 /*
94 * Hardware team recommends that we enable the STP prefetch for all
95 * transports
96 */
97 tl_control = readl(&sci_phy->transport_layer_registers->control);
98 tl_control |= SCU_TLCR_GEN_BIT(STP_WRITE_DATA_PREFETCH);
99 writel(tl_control, &sci_phy->transport_layer_registers->control);
100
101 return SCI_SUCCESS;
102}
103
104/**
105 * This method will initialize the phy link layer registers
106 * @sci_phy:
107 * @link_layer_registers:
108 *
109 * enum sci_status
110 */
111static enum sci_status
112scic_sds_phy_link_layer_initialization(struct scic_sds_phy *sci_phy,
113 struct scu_link_layer_registers __iomem *link_layer_registers)
114{
115 struct scic_sds_controller *scic =
116 sci_phy->owning_port->owning_controller;
117 int phy_idx = sci_phy->phy_index;
118 struct sci_phy_user_params *phy_user =
119 &scic->user_parameters.sds1.phys[phy_idx];
120 struct sci_phy_oem_params *phy_oem =
121 &scic->oem_parameters.sds1.phys[phy_idx];
122 u32 phy_configuration;
123 struct scic_phy_cap phy_cap;
124 u32 parity_check = 0;
125 u32 parity_count = 0;
126 u32 llctl, link_rate;
127 u32 clksm_value = 0;
128
129 sci_phy->link_layer_registers = link_layer_registers;
130
131 /* Set our IDENTIFY frame data */
132 #define SCI_END_DEVICE 0x01
133
134 writel(SCU_SAS_TIID_GEN_BIT(SMP_INITIATOR) |
135 SCU_SAS_TIID_GEN_BIT(SSP_INITIATOR) |
136 SCU_SAS_TIID_GEN_BIT(STP_INITIATOR) |
137 SCU_SAS_TIID_GEN_BIT(DA_SATA_HOST) |
138 SCU_SAS_TIID_GEN_VAL(DEVICE_TYPE, SCI_END_DEVICE),
139 &sci_phy->link_layer_registers->transmit_identification);
140
141 /* Write the device SAS Address */
142 writel(0xFEDCBA98,
143 &sci_phy->link_layer_registers->sas_device_name_high);
144 writel(phy_idx, &sci_phy->link_layer_registers->sas_device_name_low);
145
146 /* Write the source SAS Address */
147 writel(phy_oem->sas_address.high,
148 &sci_phy->link_layer_registers->source_sas_address_high);
149 writel(phy_oem->sas_address.low,
150 &sci_phy->link_layer_registers->source_sas_address_low);
151
152 /* Clear and Set the PHY Identifier */
153 writel(0, &sci_phy->link_layer_registers->identify_frame_phy_id);
154 writel(SCU_SAS_TIPID_GEN_VALUE(ID, phy_idx),
155 &sci_phy->link_layer_registers->identify_frame_phy_id);
156
157 /* Change the initial state of the phy configuration register */
158 phy_configuration =
159 readl(&sci_phy->link_layer_registers->phy_configuration);
160
161 /* Hold OOB state machine in reset */
162 phy_configuration |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
163 writel(phy_configuration,
164 &sci_phy->link_layer_registers->phy_configuration);
165
166 /* Configure the SNW capabilities */
167 phy_cap.all = 0;
168 phy_cap.start = 1;
169 phy_cap.gen3_no_ssc = 1;
170 phy_cap.gen2_no_ssc = 1;
171 phy_cap.gen1_no_ssc = 1;
172 if (scic->oem_parameters.sds1.controller.do_enable_ssc == true) {
173 phy_cap.gen3_ssc = 1;
174 phy_cap.gen2_ssc = 1;
175 phy_cap.gen1_ssc = 1;
176 }
177
178 /*
179 * The SAS specification indicates that the phy_capabilities that
180 * are transmitted shall have an even parity. Calculate the parity. */
181 parity_check = phy_cap.all;
182 while (parity_check != 0) {
183 if (parity_check & 0x1)
184 parity_count++;
185 parity_check >>= 1;
186 }
187
188 /*
189 * If parity indicates there are an odd number of bits set, then
190 * set the parity bit to 1 in the phy capabilities. */
191 if ((parity_count % 2) != 0)
192 phy_cap.parity = 1;
193
194 writel(phy_cap.all, &sci_phy->link_layer_registers->phy_capabilities);
195
196 /* Set the enable spinup period but disable the ability to send
197 * notify enable spinup
198 */
199 writel(SCU_ENSPINUP_GEN_VAL(COUNT,
200 phy_user->notify_enable_spin_up_insertion_frequency),
201 &sci_phy->link_layer_registers->notify_enable_spinup_control);
202
203 /* Write the ALIGN Insertion Ferequency for connected phy and
204 * inpendent of connected state
205 */
206 clksm_value = SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(CONNECTED,
207 phy_user->in_connection_align_insertion_frequency);
208
209 clksm_value |= SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(GENERAL,
210 phy_user->align_insertion_frequency);
211
212 writel(clksm_value, &sci_phy->link_layer_registers->clock_skew_management);
213
214 /* @todo Provide a way to write this register correctly */
215 writel(0x02108421,
216 &sci_phy->link_layer_registers->afe_lookup_table_control);
217
218 llctl = SCU_SAS_LLCTL_GEN_VAL(NO_OUTBOUND_TASK_TIMEOUT,
219 (u8)scic->user_parameters.sds1.no_outbound_task_timeout);
220
221 switch(phy_user->max_speed_generation) {
222 case SCIC_SDS_PARM_GEN3_SPEED:
223 link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN3;
224 break;
225 case SCIC_SDS_PARM_GEN2_SPEED:
226 link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN2;
227 break;
228 default:
229 link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN1;
230 break;
231 }
232 llctl |= SCU_SAS_LLCTL_GEN_VAL(MAX_LINK_RATE, link_rate);
233 writel(llctl, &sci_phy->link_layer_registers->link_layer_control);
234
235 if (is_a0() || is_a2()) {
236 /* Program the max ARB time for the PHY to 700us so we inter-operate with
237 * the PMC expander which shuts down PHYs if the expander PHY generates too
238 * many breaks. This time value will guarantee that the initiator PHY will
239 * generate the break.
240 */
241 writel(SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME,
242 &sci_phy->link_layer_registers->maximum_arbitration_wait_timer_timeout);
243 }
244
245 /*
246 * Set the link layer hang detection to 500ms (0x1F4) from its default
247 * value of 128ms. Max value is 511 ms.
248 */
249 writel(0x1F4, &sci_phy->link_layer_registers->link_layer_hang_detection_timeout);
250
251 /* We can exit the initial state to the stopped state */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000252 sci_change_state(&sci_phy->sm, SCI_PHY_STOPPED);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700253
254 return SCI_SUCCESS;
255}
256
Edmund Nadolskia628d472011-05-19 11:59:36 +0000257static void phy_sata_timeout(unsigned long data)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700258{
Edmund Nadolskia628d472011-05-19 11:59:36 +0000259 struct sci_timer *tmr = (struct sci_timer *)data;
260 struct scic_sds_phy *sci_phy = container_of(tmr, typeof(*sci_phy), sata_timer);
261 struct isci_host *ihost = scic_to_ihost(sci_phy->owning_port->owning_controller);
262 unsigned long flags;
263
264 spin_lock_irqsave(&ihost->scic_lock, flags);
265
266 if (tmr->cancel)
267 goto done;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700268
269 dev_dbg(sciphy_to_dev(sci_phy),
270 "%s: SCIC SDS Phy 0x%p did not receive signature fis before "
271 "timeout.\n",
272 __func__,
273 sci_phy);
274
Edmund Nadolskie3013702011-06-02 00:10:43 +0000275 sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
Edmund Nadolskia628d472011-05-19 11:59:36 +0000276done:
277 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700278}
279
280/**
281 * This method returns the port currently containing this phy. If the phy is
282 * currently contained by the dummy port, then the phy is considered to not
283 * be part of a port.
284 * @sci_phy: This parameter specifies the phy for which to retrieve the
285 * containing port.
286 *
287 * This method returns a handle to a port that contains the supplied phy.
288 * NULL This value is returned if the phy is not part of a real
289 * port (i.e. it's contained in the dummy port). !NULL All other
290 * values indicate a handle/pointer to the port containing the phy.
291 */
Dan Williams4f20ef42011-05-12 06:00:31 -0700292struct scic_sds_port *phy_get_non_dummy_port(
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700293 struct scic_sds_phy *sci_phy)
294{
295 if (scic_sds_port_get_index(sci_phy->owning_port) == SCIC_SDS_DUMMY_PORT)
296 return NULL;
297
298 return sci_phy->owning_port;
299}
300
301/**
302 * This method will assign a port to the phy object.
303 * @out]: sci_phy This parameter specifies the phy for which to assign a port
304 * object.
305 *
306 *
307 */
308void scic_sds_phy_set_port(
309 struct scic_sds_phy *sci_phy,
310 struct scic_sds_port *sci_port)
311{
312 sci_phy->owning_port = sci_port;
313
314 if (sci_phy->bcn_received_while_port_unassigned) {
315 sci_phy->bcn_received_while_port_unassigned = false;
316 scic_sds_port_broadcast_change_received(sci_phy->owning_port, sci_phy);
317 }
318}
319
320/**
321 * This method will initialize the constructed phy
322 * @sci_phy:
323 * @link_layer_registers:
324 *
325 * enum sci_status
326 */
327enum sci_status scic_sds_phy_initialize(
328 struct scic_sds_phy *sci_phy,
329 struct scu_transport_layer_registers __iomem *transport_layer_registers,
330 struct scu_link_layer_registers __iomem *link_layer_registers)
331{
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700332 /* Perfrom the initialization of the TL hardware */
333 scic_sds_phy_transport_layer_initialization(
334 sci_phy,
335 transport_layer_registers);
336
337 /* Perofrm the initialization of the PE hardware */
338 scic_sds_phy_link_layer_initialization(sci_phy, link_layer_registers);
339
340 /*
341 * There is nothing that needs to be done in this state just
342 * transition to the stopped state. */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000343 sci_change_state(&sci_phy->sm, SCI_PHY_STOPPED);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700344
345 return SCI_SUCCESS;
346}
347
348/**
349 * This method assigns the direct attached device ID for this phy.
350 *
351 * @sci_phy The phy for which the direct attached device id is to
352 * be assigned.
353 * @device_id The direct attached device ID to assign to the phy.
354 * This will either be the RNi for the device or an invalid RNi if there
355 * is no current device assigned to the phy.
356 */
357void scic_sds_phy_setup_transport(
358 struct scic_sds_phy *sci_phy,
359 u32 device_id)
360{
361 u32 tl_control;
362
363 writel(device_id, &sci_phy->transport_layer_registers->stp_rni);
364
365 /*
366 * The read should guarantee that the first write gets posted
367 * before the next write
368 */
369 tl_control = readl(&sci_phy->transport_layer_registers->control);
370 tl_control |= SCU_TLCR_GEN_BIT(CLEAR_TCI_NCQ_MAPPING_TABLE);
371 writel(tl_control, &sci_phy->transport_layer_registers->control);
372}
373
374/**
375 *
376 * @sci_phy: The phy object to be suspended.
377 *
378 * This function will perform the register reads/writes to suspend the SCU
379 * hardware protocol engine. none
380 */
381static void scic_sds_phy_suspend(
382 struct scic_sds_phy *sci_phy)
383{
384 u32 scu_sas_pcfg_value;
385
386 scu_sas_pcfg_value =
387 readl(&sci_phy->link_layer_registers->phy_configuration);
388 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE);
389 writel(scu_sas_pcfg_value,
390 &sci_phy->link_layer_registers->phy_configuration);
391
392 scic_sds_phy_setup_transport(
393 sci_phy,
394 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX);
395}
396
397void scic_sds_phy_resume(struct scic_sds_phy *sci_phy)
398{
399 u32 scu_sas_pcfg_value;
400
401 scu_sas_pcfg_value =
402 readl(&sci_phy->link_layer_registers->phy_configuration);
403 scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE);
404 writel(scu_sas_pcfg_value,
405 &sci_phy->link_layer_registers->phy_configuration);
406}
407
408void scic_sds_phy_get_sas_address(struct scic_sds_phy *sci_phy,
409 struct sci_sas_address *sas_address)
410{
411 sas_address->high = readl(&sci_phy->link_layer_registers->source_sas_address_high);
412 sas_address->low = readl(&sci_phy->link_layer_registers->source_sas_address_low);
413}
414
415void scic_sds_phy_get_attached_sas_address(struct scic_sds_phy *sci_phy,
416 struct sci_sas_address *sas_address)
417{
418 struct sas_identify_frame *iaf;
419 struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
420
421 iaf = &iphy->frame_rcvd.iaf;
422 memcpy(sas_address, iaf->sas_addr, SAS_ADDR_SIZE);
423}
424
425void scic_sds_phy_get_protocols(struct scic_sds_phy *sci_phy,
426 struct scic_phy_proto *protocols)
427{
428 protocols->all =
429 (u16)(readl(&sci_phy->
430 link_layer_registers->transmit_identification) &
431 0x0000FFFF);
432}
433
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700434enum sci_status scic_sds_phy_start(struct scic_sds_phy *sci_phy)
435{
Edmund Nadolskie3013702011-06-02 00:10:43 +0000436 enum scic_sds_phy_states state = sci_phy->sm.current_state_id;
Dan Williams966699b2011-05-12 03:44:24 -0700437
Edmund Nadolskie3013702011-06-02 00:10:43 +0000438 if (state != SCI_PHY_STOPPED) {
Dan Williams966699b2011-05-12 03:44:24 -0700439 dev_dbg(sciphy_to_dev(sci_phy),
440 "%s: in wrong state: %d\n", __func__, state);
441 return SCI_FAILURE_INVALID_STATE;
442 }
443
Edmund Nadolskie3013702011-06-02 00:10:43 +0000444 sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
Dan Williams966699b2011-05-12 03:44:24 -0700445 return SCI_SUCCESS;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700446}
447
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700448enum sci_status scic_sds_phy_stop(struct scic_sds_phy *sci_phy)
449{
Edmund Nadolskie3013702011-06-02 00:10:43 +0000450 enum scic_sds_phy_states state = sci_phy->sm.current_state_id;
Dan Williams93153232011-05-12 04:01:03 -0700451
452 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +0000453 case SCI_PHY_SUB_INITIAL:
454 case SCI_PHY_SUB_AWAIT_OSSP_EN:
455 case SCI_PHY_SUB_AWAIT_SAS_SPEED_EN:
456 case SCI_PHY_SUB_AWAIT_SAS_POWER:
457 case SCI_PHY_SUB_AWAIT_SATA_POWER:
458 case SCI_PHY_SUB_AWAIT_SATA_PHY_EN:
459 case SCI_PHY_SUB_AWAIT_SATA_SPEED_EN:
460 case SCI_PHY_SUB_AWAIT_SIG_FIS_UF:
461 case SCI_PHY_SUB_FINAL:
462 case SCI_PHY_READY:
Dan Williams93153232011-05-12 04:01:03 -0700463 break;
464 default:
465 dev_dbg(sciphy_to_dev(sci_phy),
466 "%s: in wrong state: %d\n", __func__, state);
467 return SCI_FAILURE_INVALID_STATE;
468 }
469
Edmund Nadolskie3013702011-06-02 00:10:43 +0000470 sci_change_state(&sci_phy->sm, SCI_PHY_STOPPED);
Dan Williams93153232011-05-12 04:01:03 -0700471 return SCI_SUCCESS;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700472}
473
Dan Williams0cf36fa2011-05-12 04:02:07 -0700474enum sci_status scic_sds_phy_reset(struct scic_sds_phy *sci_phy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700475{
Edmund Nadolskie3013702011-06-02 00:10:43 +0000476 enum scic_sds_phy_states state = sci_phy->sm.current_state_id;
Dan Williams0cf36fa2011-05-12 04:02:07 -0700477
Edmund Nadolskie3013702011-06-02 00:10:43 +0000478 if (state != SCI_PHY_READY) {
Dan Williams0cf36fa2011-05-12 04:02:07 -0700479 dev_dbg(sciphy_to_dev(sci_phy),
480 "%s: in wrong state: %d\n", __func__, state);
481 return SCI_FAILURE_INVALID_STATE;
482 }
483
Edmund Nadolskie3013702011-06-02 00:10:43 +0000484 sci_change_state(&sci_phy->sm, SCI_PHY_RESETTING);
Dan Williams0cf36fa2011-05-12 04:02:07 -0700485 return SCI_SUCCESS;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700486}
487
Dan Williams5b1d4af2011-05-12 04:51:41 -0700488enum sci_status scic_sds_phy_consume_power_handler(struct scic_sds_phy *sci_phy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700489{
Edmund Nadolskie3013702011-06-02 00:10:43 +0000490 enum scic_sds_phy_states state = sci_phy->sm.current_state_id;
Dan Williams5b1d4af2011-05-12 04:51:41 -0700491
492 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +0000493 case SCI_PHY_SUB_AWAIT_SAS_POWER: {
Dan Williams5b1d4af2011-05-12 04:51:41 -0700494 u32 enable_spinup;
495
496 enable_spinup = readl(&sci_phy->link_layer_registers->notify_enable_spinup_control);
497 enable_spinup |= SCU_ENSPINUP_GEN_BIT(ENABLE);
498 writel(enable_spinup, &sci_phy->link_layer_registers->notify_enable_spinup_control);
499
500 /* Change state to the final state this substate machine has run to completion */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000501 sci_change_state(&sci_phy->sm, SCI_PHY_SUB_FINAL);
Dan Williams5b1d4af2011-05-12 04:51:41 -0700502
503 return SCI_SUCCESS;
504 }
Edmund Nadolskie3013702011-06-02 00:10:43 +0000505 case SCI_PHY_SUB_AWAIT_SATA_POWER: {
Dan Williams5b1d4af2011-05-12 04:51:41 -0700506 u32 scu_sas_pcfg_value;
507
508 /* Release the spinup hold state and reset the OOB state machine */
509 scu_sas_pcfg_value =
510 readl(&sci_phy->link_layer_registers->phy_configuration);
511 scu_sas_pcfg_value &=
512 ~(SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD) | SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE));
513 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
514 writel(scu_sas_pcfg_value,
515 &sci_phy->link_layer_registers->phy_configuration);
516
517 /* Now restart the OOB operation */
518 scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
519 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
520 writel(scu_sas_pcfg_value,
521 &sci_phy->link_layer_registers->phy_configuration);
522
523 /* Change state to the final state this substate machine has run to completion */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000524 sci_change_state(&sci_phy->sm, SCI_PHY_SUB_AWAIT_SATA_PHY_EN);
Dan Williams5b1d4af2011-05-12 04:51:41 -0700525
526 return SCI_SUCCESS;
527 }
528 default:
529 dev_dbg(sciphy_to_dev(sci_phy),
530 "%s: in wrong state: %d\n", __func__, state);
531 return SCI_FAILURE_INVALID_STATE;
532 }
Dan Williams23506a62011-05-12 04:27:29 -0700533}
534
535/*
536 * *****************************************************************************
537 * * SCIC SDS PHY HELPER FUNCTIONS
538 * ***************************************************************************** */
539
540
541/**
542 *
543 * @sci_phy: The phy object that received SAS PHY DETECTED.
544 *
545 * This method continues the link training for the phy as if it were a SAS PHY
546 * instead of a SATA PHY. This is done because the completion queue had a SAS
547 * PHY DETECTED event when the state machine was expecting a SATA PHY event.
548 * none
549 */
550static void scic_sds_phy_start_sas_link_training(
551 struct scic_sds_phy *sci_phy)
552{
553 u32 phy_control;
554
555 phy_control =
556 readl(&sci_phy->link_layer_registers->phy_configuration);
557 phy_control |= SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD);
558 writel(phy_control,
559 &sci_phy->link_layer_registers->phy_configuration);
560
Edmund Nadolskie3013702011-06-02 00:10:43 +0000561 sci_change_state(&sci_phy->sm, SCI_PHY_SUB_AWAIT_SAS_SPEED_EN);
Dan Williams23506a62011-05-12 04:27:29 -0700562
563 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SAS;
564}
565
566/**
567 *
568 * @sci_phy: The phy object that received a SATA SPINUP HOLD event
569 *
570 * This method continues the link training for the phy as if it were a SATA PHY
571 * instead of a SAS PHY. This is done because the completion queue had a SATA
572 * SPINUP HOLD event when the state machine was expecting a SAS PHY event. none
573 */
574static void scic_sds_phy_start_sata_link_training(
575 struct scic_sds_phy *sci_phy)
576{
Edmund Nadolskie3013702011-06-02 00:10:43 +0000577 sci_change_state(&sci_phy->sm, SCI_PHY_SUB_AWAIT_SATA_POWER);
Dan Williams23506a62011-05-12 04:27:29 -0700578
579 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
580}
581
582/**
583 * scic_sds_phy_complete_link_training - perform processing common to
584 * all protocols upon completion of link training.
585 * @sci_phy: This parameter specifies the phy object for which link training
586 * has completed.
587 * @max_link_rate: This parameter specifies the maximum link rate to be
588 * associated with this phy.
589 * @next_state: This parameter specifies the next state for the phy's starting
590 * sub-state machine.
591 *
592 */
593static void scic_sds_phy_complete_link_training(
594 struct scic_sds_phy *sci_phy,
595 enum sas_linkrate max_link_rate,
596 u32 next_state)
597{
598 sci_phy->max_negotiated_speed = max_link_rate;
599
Edmund Nadolskie3013702011-06-02 00:10:43 +0000600 sci_change_state(&sci_phy->sm, next_state);
Dan Williams23506a62011-05-12 04:27:29 -0700601}
602
Dan Williams23506a62011-05-12 04:27:29 -0700603enum sci_status scic_sds_phy_event_handler(struct scic_sds_phy *sci_phy,
604 u32 event_code)
605{
Edmund Nadolskie3013702011-06-02 00:10:43 +0000606 enum scic_sds_phy_states state = sci_phy->sm.current_state_id;
Dan Williams23506a62011-05-12 04:27:29 -0700607
608 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +0000609 case SCI_PHY_SUB_AWAIT_OSSP_EN:
Dan Williams23506a62011-05-12 04:27:29 -0700610 switch (scu_get_event_code(event_code)) {
611 case SCU_EVENT_SAS_PHY_DETECTED:
612 scic_sds_phy_start_sas_link_training(sci_phy);
613 sci_phy->is_in_link_training = true;
614 break;
615 case SCU_EVENT_SATA_SPINUP_HOLD:
616 scic_sds_phy_start_sata_link_training(sci_phy);
617 sci_phy->is_in_link_training = true;
618 break;
619 default:
620 dev_dbg(sciphy_to_dev(sci_phy),
621 "%s: PHY starting substate machine received "
622 "unexpected event_code %x\n",
623 __func__,
624 event_code);
625 return SCI_FAILURE;
626 }
627 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000628 case SCI_PHY_SUB_AWAIT_SAS_SPEED_EN:
Dan Williams23506a62011-05-12 04:27:29 -0700629 switch (scu_get_event_code(event_code)) {
630 case SCU_EVENT_SAS_PHY_DETECTED:
631 /*
632 * Why is this being reported again by the controller?
633 * We would re-enter this state so just stay here */
634 break;
635 case SCU_EVENT_SAS_15:
636 case SCU_EVENT_SAS_15_SSC:
637 scic_sds_phy_complete_link_training(
638 sci_phy,
639 SAS_LINK_RATE_1_5_GBPS,
Edmund Nadolskie3013702011-06-02 00:10:43 +0000640 SCI_PHY_SUB_AWAIT_IAF_UF);
Dan Williams23506a62011-05-12 04:27:29 -0700641 break;
642 case SCU_EVENT_SAS_30:
643 case SCU_EVENT_SAS_30_SSC:
644 scic_sds_phy_complete_link_training(
645 sci_phy,
646 SAS_LINK_RATE_3_0_GBPS,
Edmund Nadolskie3013702011-06-02 00:10:43 +0000647 SCI_PHY_SUB_AWAIT_IAF_UF);
Dan Williams23506a62011-05-12 04:27:29 -0700648 break;
649 case SCU_EVENT_SAS_60:
650 case SCU_EVENT_SAS_60_SSC:
651 scic_sds_phy_complete_link_training(
652 sci_phy,
653 SAS_LINK_RATE_6_0_GBPS,
Edmund Nadolskie3013702011-06-02 00:10:43 +0000654 SCI_PHY_SUB_AWAIT_IAF_UF);
Dan Williams23506a62011-05-12 04:27:29 -0700655 break;
656 case SCU_EVENT_SATA_SPINUP_HOLD:
657 /*
658 * We were doing SAS PHY link training and received a SATA PHY event
659 * continue OOB/SN as if this were a SATA PHY */
660 scic_sds_phy_start_sata_link_training(sci_phy);
661 break;
662 case SCU_EVENT_LINK_FAILURE:
663 /* Link failure change state back to the starting state */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000664 sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700665 break;
666 default:
667 dev_warn(sciphy_to_dev(sci_phy),
668 "%s: PHY starting substate machine received "
669 "unexpected event_code %x\n",
670 __func__, event_code);
671
672 return SCI_FAILURE;
673 break;
674 }
675 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000676 case SCI_PHY_SUB_AWAIT_IAF_UF:
Dan Williams23506a62011-05-12 04:27:29 -0700677 switch (scu_get_event_code(event_code)) {
678 case SCU_EVENT_SAS_PHY_DETECTED:
679 /* Backup the state machine */
680 scic_sds_phy_start_sas_link_training(sci_phy);
681 break;
682 case SCU_EVENT_SATA_SPINUP_HOLD:
683 /* We were doing SAS PHY link training and received a
684 * SATA PHY event continue OOB/SN as if this were a
685 * SATA PHY
686 */
687 scic_sds_phy_start_sata_link_training(sci_phy);
688 break;
689 case SCU_EVENT_RECEIVED_IDENTIFY_TIMEOUT:
690 case SCU_EVENT_LINK_FAILURE:
691 case SCU_EVENT_HARD_RESET_RECEIVED:
692 /* Start the oob/sn state machine over again */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000693 sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700694 break;
695 default:
696 dev_warn(sciphy_to_dev(sci_phy),
697 "%s: PHY starting substate machine received "
698 "unexpected event_code %x\n",
699 __func__, event_code);
700 return SCI_FAILURE;
701 }
702 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000703 case SCI_PHY_SUB_AWAIT_SAS_POWER:
Dan Williams23506a62011-05-12 04:27:29 -0700704 switch (scu_get_event_code(event_code)) {
705 case SCU_EVENT_LINK_FAILURE:
706 /* Link failure change state back to the starting state */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000707 sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700708 break;
709 default:
710 dev_warn(sciphy_to_dev(sci_phy),
711 "%s: PHY starting substate machine received unexpected "
712 "event_code %x\n",
713 __func__,
714 event_code);
715 return SCI_FAILURE;
716 }
717 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000718 case SCI_PHY_SUB_AWAIT_SATA_POWER:
Dan Williams23506a62011-05-12 04:27:29 -0700719 switch (scu_get_event_code(event_code)) {
720 case SCU_EVENT_LINK_FAILURE:
721 /* Link failure change state back to the starting state */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000722 sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700723 break;
724 case SCU_EVENT_SATA_SPINUP_HOLD:
725 /* These events are received every 10ms and are
726 * expected while in this state
727 */
728 break;
729
730 case SCU_EVENT_SAS_PHY_DETECTED:
731 /* There has been a change in the phy type before OOB/SN for the
732 * SATA finished start down the SAS link traning path.
733 */
734 scic_sds_phy_start_sas_link_training(sci_phy);
735 break;
736
737 default:
738 dev_warn(sciphy_to_dev(sci_phy),
739 "%s: PHY starting substate machine received "
740 "unexpected event_code %x\n",
741 __func__, event_code);
742
743 return SCI_FAILURE;
744 }
745 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000746 case SCI_PHY_SUB_AWAIT_SATA_PHY_EN:
Dan Williams23506a62011-05-12 04:27:29 -0700747 switch (scu_get_event_code(event_code)) {
748 case SCU_EVENT_LINK_FAILURE:
749 /* Link failure change state back to the starting state */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000750 sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700751 break;
752 case SCU_EVENT_SATA_SPINUP_HOLD:
753 /* These events might be received since we dont know how many may be in
754 * the completion queue while waiting for power
755 */
756 break;
757 case SCU_EVENT_SATA_PHY_DETECTED:
758 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
759
760 /* We have received the SATA PHY notification change state */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000761 sci_change_state(&sci_phy->sm, SCI_PHY_SUB_AWAIT_SATA_SPEED_EN);
Dan Williams23506a62011-05-12 04:27:29 -0700762 break;
763 case SCU_EVENT_SAS_PHY_DETECTED:
764 /* There has been a change in the phy type before OOB/SN for the
765 * SATA finished start down the SAS link traning path.
766 */
767 scic_sds_phy_start_sas_link_training(sci_phy);
768 break;
769 default:
770 dev_warn(sciphy_to_dev(sci_phy),
771 "%s: PHY starting substate machine received "
772 "unexpected event_code %x\n",
773 __func__,
774 event_code);
775
776 return SCI_FAILURE;;
777 }
778 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000779 case SCI_PHY_SUB_AWAIT_SATA_SPEED_EN:
Dan Williams23506a62011-05-12 04:27:29 -0700780 switch (scu_get_event_code(event_code)) {
781 case SCU_EVENT_SATA_PHY_DETECTED:
782 /*
783 * The hardware reports multiple SATA PHY detected events
784 * ignore the extras */
785 break;
786 case SCU_EVENT_SATA_15:
787 case SCU_EVENT_SATA_15_SSC:
788 scic_sds_phy_complete_link_training(
789 sci_phy,
790 SAS_LINK_RATE_1_5_GBPS,
Edmund Nadolskie3013702011-06-02 00:10:43 +0000791 SCI_PHY_SUB_AWAIT_SIG_FIS_UF);
Dan Williams23506a62011-05-12 04:27:29 -0700792 break;
793 case SCU_EVENT_SATA_30:
794 case SCU_EVENT_SATA_30_SSC:
795 scic_sds_phy_complete_link_training(
796 sci_phy,
797 SAS_LINK_RATE_3_0_GBPS,
Edmund Nadolskie3013702011-06-02 00:10:43 +0000798 SCI_PHY_SUB_AWAIT_SIG_FIS_UF);
Dan Williams23506a62011-05-12 04:27:29 -0700799 break;
800 case SCU_EVENT_SATA_60:
801 case SCU_EVENT_SATA_60_SSC:
802 scic_sds_phy_complete_link_training(
803 sci_phy,
804 SAS_LINK_RATE_6_0_GBPS,
Edmund Nadolskie3013702011-06-02 00:10:43 +0000805 SCI_PHY_SUB_AWAIT_SIG_FIS_UF);
Dan Williams23506a62011-05-12 04:27:29 -0700806 break;
807 case SCU_EVENT_LINK_FAILURE:
808 /* Link failure change state back to the starting state */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000809 sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700810 break;
811 case SCU_EVENT_SAS_PHY_DETECTED:
812 /*
813 * There has been a change in the phy type before OOB/SN for the
814 * SATA finished start down the SAS link traning path. */
815 scic_sds_phy_start_sas_link_training(sci_phy);
816 break;
817 default:
818 dev_warn(sciphy_to_dev(sci_phy),
819 "%s: PHY starting substate machine received "
820 "unexpected event_code %x\n",
821 __func__, event_code);
822
823 return SCI_FAILURE;
824 }
825
826 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000827 case SCI_PHY_SUB_AWAIT_SIG_FIS_UF:
Dan Williams23506a62011-05-12 04:27:29 -0700828 switch (scu_get_event_code(event_code)) {
829 case SCU_EVENT_SATA_PHY_DETECTED:
830 /* Backup the state machine */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000831 sci_change_state(&sci_phy->sm, SCI_PHY_SUB_AWAIT_SATA_SPEED_EN);
Dan Williams23506a62011-05-12 04:27:29 -0700832 break;
833
834 case SCU_EVENT_LINK_FAILURE:
835 /* Link failure change state back to the starting state */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000836 sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700837 break;
838
839 default:
840 dev_warn(sciphy_to_dev(sci_phy),
841 "%s: PHY starting substate machine received "
842 "unexpected event_code %x\n",
843 __func__,
844 event_code);
845
846 return SCI_FAILURE;
847 }
848 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000849 case SCI_PHY_READY:
Dan Williams23506a62011-05-12 04:27:29 -0700850 switch (scu_get_event_code(event_code)) {
851 case SCU_EVENT_LINK_FAILURE:
852 /* Link failure change state back to the starting state */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000853 sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700854 break;
855 case SCU_EVENT_BROADCAST_CHANGE:
856 /* Broadcast change received. Notify the port. */
Dan Williams4f20ef42011-05-12 06:00:31 -0700857 if (phy_get_non_dummy_port(sci_phy) != NULL)
Dan Williams23506a62011-05-12 04:27:29 -0700858 scic_sds_port_broadcast_change_received(sci_phy->owning_port, sci_phy);
859 else
860 sci_phy->bcn_received_while_port_unassigned = true;
861 break;
862 default:
863 dev_warn(sciphy_to_dev(sci_phy),
864 "%sP SCIC PHY 0x%p ready state machine received "
865 "unexpected event_code %x\n",
866 __func__, sci_phy, event_code);
867 return SCI_FAILURE_INVALID_STATE;
868 }
869 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000870 case SCI_PHY_RESETTING:
Dan Williams23506a62011-05-12 04:27:29 -0700871 switch (scu_get_event_code(event_code)) {
872 case SCU_EVENT_HARD_RESET_TRANSMITTED:
873 /* Link failure change state back to the starting state */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000874 sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700875 break;
876 default:
877 dev_warn(sciphy_to_dev(sci_phy),
878 "%s: SCIC PHY 0x%p resetting state machine received "
879 "unexpected event_code %x\n",
880 __func__, sci_phy, event_code);
881
882 return SCI_FAILURE_INVALID_STATE;
883 break;
884 }
885 return SCI_SUCCESS;
886 default:
887 dev_dbg(sciphy_to_dev(sci_phy),
888 "%s: in wrong state: %d\n", __func__, state);
889 return SCI_FAILURE_INVALID_STATE;
890 }
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700891}
892
Dan Williamsc4441ab2011-05-12 04:17:51 -0700893enum sci_status scic_sds_phy_frame_handler(struct scic_sds_phy *sci_phy,
894 u32 frame_index)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700895{
Edmund Nadolskie3013702011-06-02 00:10:43 +0000896 enum scic_sds_phy_states state = sci_phy->sm.current_state_id;
Dan Williamsc4441ab2011-05-12 04:17:51 -0700897 struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller;
898 enum sci_status result;
899
900 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +0000901 case SCI_PHY_SUB_AWAIT_IAF_UF: {
Dan Williamsc4441ab2011-05-12 04:17:51 -0700902 u32 *frame_words;
903 struct sas_identify_frame iaf;
904 struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
905
906 result = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
907 frame_index,
908 (void **)&frame_words);
909
910 if (result != SCI_SUCCESS)
911 return result;
912
913 sci_swab32_cpy(&iaf, frame_words, sizeof(iaf) / sizeof(u32));
914 if (iaf.frame_type == 0) {
915 u32 state;
916
917 memcpy(&iphy->frame_rcvd.iaf, &iaf, sizeof(iaf));
918 if (iaf.smp_tport) {
919 /* We got the IAF for an expander PHY go to the final
920 * state since there are no power requirements for
921 * expander phys.
922 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000923 state = SCI_PHY_SUB_FINAL;
Dan Williamsc4441ab2011-05-12 04:17:51 -0700924 } else {
925 /* We got the IAF we can now go to the await spinup
926 * semaphore state
927 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000928 state = SCI_PHY_SUB_AWAIT_SAS_POWER;
Dan Williamsc4441ab2011-05-12 04:17:51 -0700929 }
Edmund Nadolskie3013702011-06-02 00:10:43 +0000930 sci_change_state(&sci_phy->sm, state);
Dan Williamsc4441ab2011-05-12 04:17:51 -0700931 result = SCI_SUCCESS;
932 } else
933 dev_warn(sciphy_to_dev(sci_phy),
934 "%s: PHY starting substate machine received "
935 "unexpected frame id %x\n",
936 __func__, frame_index);
937
938 scic_sds_controller_release_frame(scic, frame_index);
939 return result;
940 }
Edmund Nadolskie3013702011-06-02 00:10:43 +0000941 case SCI_PHY_SUB_AWAIT_SIG_FIS_UF: {
Dan Williamsc4441ab2011-05-12 04:17:51 -0700942 struct dev_to_host_fis *frame_header;
943 u32 *fis_frame_data;
944 struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
945
946 result = scic_sds_unsolicited_frame_control_get_header(
947 &(scic_sds_phy_get_controller(sci_phy)->uf_control),
948 frame_index,
949 (void **)&frame_header);
950
951 if (result != SCI_SUCCESS)
952 return result;
953
954 if ((frame_header->fis_type == FIS_REGD2H) &&
955 !(frame_header->status & ATA_BUSY)) {
956 scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
957 frame_index,
958 (void **)&fis_frame_data);
959
960 scic_sds_controller_copy_sata_response(&iphy->frame_rcvd.fis,
961 frame_header,
962 fis_frame_data);
963
964 /* got IAF we can now go to the await spinup semaphore state */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000965 sci_change_state(&sci_phy->sm, SCI_PHY_SUB_FINAL);
Dan Williamsc4441ab2011-05-12 04:17:51 -0700966
967 result = SCI_SUCCESS;
968 } else
969 dev_warn(sciphy_to_dev(sci_phy),
970 "%s: PHY starting substate machine received "
971 "unexpected frame id %x\n",
972 __func__, frame_index);
973
974 /* Regardless of the result we are done with this frame with it */
975 scic_sds_controller_release_frame(scic, frame_index);
976
977 return result;
978 }
979 default:
980 dev_dbg(sciphy_to_dev(sci_phy),
981 "%s: in wrong state: %d\n", __func__, state);
982 return SCI_FAILURE_INVALID_STATE;
983 }
984
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700985}
986
Dan Williams9269e0e2011-05-12 07:42:17 -0700987static void scic_sds_phy_starting_initial_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +0000988{
Edmund Nadolskie3013702011-06-02 00:10:43 +0000989 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +0000990
Adam Gruchala4a33c522011-05-10 23:54:23 +0000991 /* This is just an temporary state go off to the starting state */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000992 sci_change_state(&sci_phy->sm, SCI_PHY_SUB_AWAIT_OSSP_EN);
Adam Gruchala4a33c522011-05-10 23:54:23 +0000993}
994
Dan Williams9269e0e2011-05-12 07:42:17 -0700995static void scic_sds_phy_starting_await_sas_power_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +0000996{
Edmund Nadolskie3013702011-06-02 00:10:43 +0000997 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Dan Williams5b1d4af2011-05-12 04:51:41 -0700998 struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller;
Adam Gruchala4a33c522011-05-10 23:54:23 +0000999
Dan Williams5b1d4af2011-05-12 04:51:41 -07001000 scic_sds_controller_power_control_queue_insert(scic, sci_phy);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001001}
1002
Dan Williams9269e0e2011-05-12 07:42:17 -07001003static void scic_sds_phy_starting_await_sas_power_substate_exit(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001004{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001005 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Dan Williams5b1d4af2011-05-12 04:51:41 -07001006 struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller;
Adam Gruchala4a33c522011-05-10 23:54:23 +00001007
Dan Williams5b1d4af2011-05-12 04:51:41 -07001008 scic_sds_controller_power_control_queue_remove(scic, sci_phy);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001009}
1010
Dan Williams9269e0e2011-05-12 07:42:17 -07001011static void scic_sds_phy_starting_await_sata_power_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001012{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001013 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Dan Williams5b1d4af2011-05-12 04:51:41 -07001014 struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller;
Adam Gruchala4a33c522011-05-10 23:54:23 +00001015
Dan Williams5b1d4af2011-05-12 04:51:41 -07001016 scic_sds_controller_power_control_queue_insert(scic, sci_phy);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001017}
1018
Dan Williams9269e0e2011-05-12 07:42:17 -07001019static void scic_sds_phy_starting_await_sata_power_substate_exit(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001020{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001021 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Dan Williams5b1d4af2011-05-12 04:51:41 -07001022 struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller;
Adam Gruchala4a33c522011-05-10 23:54:23 +00001023
Dan Williams5b1d4af2011-05-12 04:51:41 -07001024 scic_sds_controller_power_control_queue_remove(scic, sci_phy);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001025}
1026
Dan Williams9269e0e2011-05-12 07:42:17 -07001027static void scic_sds_phy_starting_await_sata_phy_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001028{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001029 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001030
Edmund Nadolskia628d472011-05-19 11:59:36 +00001031 sci_mod_timer(&sci_phy->sata_timer, SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001032}
1033
Dan Williams9269e0e2011-05-12 07:42:17 -07001034static void scic_sds_phy_starting_await_sata_phy_substate_exit(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001035{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001036 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001037
Edmund Nadolskia628d472011-05-19 11:59:36 +00001038 sci_del_timer(&sci_phy->sata_timer);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001039}
1040
Dan Williams9269e0e2011-05-12 07:42:17 -07001041static void scic_sds_phy_starting_await_sata_speed_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001042{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001043 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001044
Edmund Nadolskia628d472011-05-19 11:59:36 +00001045 sci_mod_timer(&sci_phy->sata_timer, SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001046}
1047
Dan Williams9269e0e2011-05-12 07:42:17 -07001048static void scic_sds_phy_starting_await_sata_speed_substate_exit(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001049{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001050 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001051
Edmund Nadolskia628d472011-05-19 11:59:36 +00001052 sci_del_timer(&sci_phy->sata_timer);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001053}
1054
Dan Williams9269e0e2011-05-12 07:42:17 -07001055static void scic_sds_phy_starting_await_sig_fis_uf_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001056{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001057 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001058
Dan Williams5b1d4af2011-05-12 04:51:41 -07001059 if (scic_sds_port_link_detected(sci_phy->owning_port, sci_phy)) {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001060
Adam Gruchala4a33c522011-05-10 23:54:23 +00001061 /*
1062 * Clear the PE suspend condition so we can actually
1063 * receive SIG FIS
1064 * The hardware will not respond to the XRDY until the PE
1065 * suspend condition is cleared.
1066 */
1067 scic_sds_phy_resume(sci_phy);
1068
Edmund Nadolskia628d472011-05-19 11:59:36 +00001069 sci_mod_timer(&sci_phy->sata_timer,
1070 SCIC_SDS_SIGNATURE_FIS_TIMEOUT);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001071 } else
1072 sci_phy->is_in_link_training = false;
1073}
1074
Dan Williams9269e0e2011-05-12 07:42:17 -07001075static void scic_sds_phy_starting_await_sig_fis_uf_substate_exit(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001076{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001077 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001078
Edmund Nadolskia628d472011-05-19 11:59:36 +00001079 sci_del_timer(&sci_phy->sata_timer);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001080}
1081
Dan Williams9269e0e2011-05-12 07:42:17 -07001082static void scic_sds_phy_starting_final_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001083{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001084 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001085
Adam Gruchala4a33c522011-05-10 23:54:23 +00001086 /* State machine has run to completion so exit out and change
1087 * the base state machine to the ready state
1088 */
Edmund Nadolskie3013702011-06-02 00:10:43 +00001089 sci_change_state(&sci_phy->sm, SCI_PHY_READY);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001090}
1091
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001092/**
1093 *
1094 * @sci_phy: This is the struct scic_sds_phy object to stop.
1095 *
1096 * This method will stop the struct scic_sds_phy object. This does not reset the
1097 * protocol engine it just suspends it and places it in a state where it will
1098 * not cause the end device to power up. none
1099 */
1100static void scu_link_layer_stop_protocol_engine(
1101 struct scic_sds_phy *sci_phy)
1102{
1103 u32 scu_sas_pcfg_value;
1104 u32 enable_spinup_value;
1105
1106 /* Suspend the protocol engine and place it in a sata spinup hold state */
1107 scu_sas_pcfg_value =
1108 readl(&sci_phy->link_layer_registers->phy_configuration);
1109 scu_sas_pcfg_value |=
1110 (SCU_SAS_PCFG_GEN_BIT(OOB_RESET) |
1111 SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE) |
1112 SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD));
1113 writel(scu_sas_pcfg_value,
1114 &sci_phy->link_layer_registers->phy_configuration);
1115
1116 /* Disable the notify enable spinup primitives */
1117 enable_spinup_value = readl(&sci_phy->link_layer_registers->notify_enable_spinup_control);
1118 enable_spinup_value &= ~SCU_ENSPINUP_GEN_BIT(ENABLE);
1119 writel(enable_spinup_value, &sci_phy->link_layer_registers->notify_enable_spinup_control);
1120}
1121
1122/**
1123 *
1124 *
1125 * This method will start the OOB/SN state machine for this struct scic_sds_phy object.
1126 */
1127static void scu_link_layer_start_oob(
1128 struct scic_sds_phy *sci_phy)
1129{
1130 u32 scu_sas_pcfg_value;
1131
1132 scu_sas_pcfg_value =
1133 readl(&sci_phy->link_layer_registers->phy_configuration);
1134 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
1135 scu_sas_pcfg_value &=
1136 ~(SCU_SAS_PCFG_GEN_BIT(OOB_RESET) |
1137 SCU_SAS_PCFG_GEN_BIT(HARD_RESET));
1138 writel(scu_sas_pcfg_value,
1139 &sci_phy->link_layer_registers->phy_configuration);
1140}
1141
1142/**
1143 *
1144 *
1145 * This method will transmit a hard reset request on the specified phy. The SCU
1146 * hardware requires that we reset the OOB state machine and set the hard reset
1147 * bit in the phy configuration register. We then must start OOB over with the
1148 * hard reset bit set.
1149 */
1150static void scu_link_layer_tx_hard_reset(
1151 struct scic_sds_phy *sci_phy)
1152{
1153 u32 phy_configuration_value;
1154
1155 /*
1156 * SAS Phys must wait for the HARD_RESET_TX event notification to transition
1157 * to the starting state. */
1158 phy_configuration_value =
1159 readl(&sci_phy->link_layer_registers->phy_configuration);
1160 phy_configuration_value |=
1161 (SCU_SAS_PCFG_GEN_BIT(HARD_RESET) |
1162 SCU_SAS_PCFG_GEN_BIT(OOB_RESET));
1163 writel(phy_configuration_value,
1164 &sci_phy->link_layer_registers->phy_configuration);
1165
1166 /* Now take the OOB state machine out of reset */
1167 phy_configuration_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
1168 phy_configuration_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
1169 writel(phy_configuration_value,
1170 &sci_phy->link_layer_registers->phy_configuration);
1171}
1172
Dan Williams9269e0e2011-05-12 07:42:17 -07001173static void scic_sds_phy_stopped_state_enter(struct sci_base_state_machine *sm)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001174{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001175 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001176
1177 /*
1178 * @todo We need to get to the controller to place this PE in a
1179 * reset state
1180 */
Edmund Nadolskia628d472011-05-19 11:59:36 +00001181 sci_del_timer(&sci_phy->sata_timer);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001182
1183 scu_link_layer_stop_protocol_engine(sci_phy);
1184
Edmund Nadolskie3013702011-06-02 00:10:43 +00001185 if (sci_phy->sm.previous_state_id != SCI_PHY_INITIAL)
Dan Williams5b1d4af2011-05-12 04:51:41 -07001186 scic_sds_controller_link_down(scic_sds_phy_get_controller(sci_phy),
Dan Williams4f20ef42011-05-12 06:00:31 -07001187 phy_get_non_dummy_port(sci_phy),
Dan Williams5b1d4af2011-05-12 04:51:41 -07001188 sci_phy);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001189}
1190
Dan Williams9269e0e2011-05-12 07:42:17 -07001191static void scic_sds_phy_starting_state_enter(struct sci_base_state_machine *sm)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001192{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001193 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001194
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001195 scu_link_layer_stop_protocol_engine(sci_phy);
1196 scu_link_layer_start_oob(sci_phy);
1197
1198 /* We don't know what kind of phy we are going to be just yet */
1199 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
1200 sci_phy->bcn_received_while_port_unassigned = false;
1201
Edmund Nadolskie3013702011-06-02 00:10:43 +00001202 if (sci_phy->sm.previous_state_id == SCI_PHY_READY)
Dan Williams5b1d4af2011-05-12 04:51:41 -07001203 scic_sds_controller_link_down(scic_sds_phy_get_controller(sci_phy),
Dan Williams4f20ef42011-05-12 06:00:31 -07001204 phy_get_non_dummy_port(sci_phy),
Dan Williams5b1d4af2011-05-12 04:51:41 -07001205 sci_phy);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001206
Edmund Nadolskie3013702011-06-02 00:10:43 +00001207 sci_change_state(&sci_phy->sm, SCI_PHY_SUB_INITIAL);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001208}
1209
Dan Williams9269e0e2011-05-12 07:42:17 -07001210static void scic_sds_phy_ready_state_enter(struct sci_base_state_machine *sm)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001211{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001212 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001213
Dan Williams5b1d4af2011-05-12 04:51:41 -07001214 scic_sds_controller_link_up(scic_sds_phy_get_controller(sci_phy),
Dan Williams4f20ef42011-05-12 06:00:31 -07001215 phy_get_non_dummy_port(sci_phy),
Dan Williams5b1d4af2011-05-12 04:51:41 -07001216 sci_phy);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001217
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001218}
1219
Dan Williams9269e0e2011-05-12 07:42:17 -07001220static void scic_sds_phy_ready_state_exit(struct sci_base_state_machine *sm)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001221{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001222 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001223
1224 scic_sds_phy_suspend(sci_phy);
1225}
1226
Dan Williams9269e0e2011-05-12 07:42:17 -07001227static void scic_sds_phy_resetting_state_enter(struct sci_base_state_machine *sm)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001228{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001229 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001230
Dan Williams5b1d4af2011-05-12 04:51:41 -07001231 /* The phy is being reset, therefore deactivate it from the port. In
1232 * the resetting state we don't notify the user regarding link up and
1233 * link down notifications
1234 */
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001235 scic_sds_port_deactivate_phy(sci_phy->owning_port, sci_phy, false);
1236
1237 if (sci_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
1238 scu_link_layer_tx_hard_reset(sci_phy);
1239 } else {
Dan Williams5b1d4af2011-05-12 04:51:41 -07001240 /* The SCU does not need to have a discrete reset state so
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001241 * just go back to the starting state.
1242 */
Edmund Nadolskie3013702011-06-02 00:10:43 +00001243 sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001244 }
1245}
1246
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001247static const struct sci_base_state scic_sds_phy_state_table[] = {
Edmund Nadolskie3013702011-06-02 00:10:43 +00001248 [SCI_PHY_INITIAL] = { },
1249 [SCI_PHY_STOPPED] = {
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001250 .enter_state = scic_sds_phy_stopped_state_enter,
1251 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001252 [SCI_PHY_STARTING] = {
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001253 .enter_state = scic_sds_phy_starting_state_enter,
1254 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001255 [SCI_PHY_SUB_INITIAL] = {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001256 .enter_state = scic_sds_phy_starting_initial_substate_enter,
1257 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001258 [SCI_PHY_SUB_AWAIT_OSSP_EN] = { },
1259 [SCI_PHY_SUB_AWAIT_SAS_SPEED_EN] = { },
1260 [SCI_PHY_SUB_AWAIT_IAF_UF] = { },
1261 [SCI_PHY_SUB_AWAIT_SAS_POWER] = {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001262 .enter_state = scic_sds_phy_starting_await_sas_power_substate_enter,
1263 .exit_state = scic_sds_phy_starting_await_sas_power_substate_exit,
1264 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001265 [SCI_PHY_SUB_AWAIT_SATA_POWER] = {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001266 .enter_state = scic_sds_phy_starting_await_sata_power_substate_enter,
1267 .exit_state = scic_sds_phy_starting_await_sata_power_substate_exit
1268 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001269 [SCI_PHY_SUB_AWAIT_SATA_PHY_EN] = {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001270 .enter_state = scic_sds_phy_starting_await_sata_phy_substate_enter,
1271 .exit_state = scic_sds_phy_starting_await_sata_phy_substate_exit
1272 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001273 [SCI_PHY_SUB_AWAIT_SATA_SPEED_EN] = {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001274 .enter_state = scic_sds_phy_starting_await_sata_speed_substate_enter,
1275 .exit_state = scic_sds_phy_starting_await_sata_speed_substate_exit
1276 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001277 [SCI_PHY_SUB_AWAIT_SIG_FIS_UF] = {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001278 .enter_state = scic_sds_phy_starting_await_sig_fis_uf_substate_enter,
1279 .exit_state = scic_sds_phy_starting_await_sig_fis_uf_substate_exit
1280 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001281 [SCI_PHY_SUB_FINAL] = {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001282 .enter_state = scic_sds_phy_starting_final_substate_enter,
1283 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001284 [SCI_PHY_READY] = {
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001285 .enter_state = scic_sds_phy_ready_state_enter,
1286 .exit_state = scic_sds_phy_ready_state_exit,
1287 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001288 [SCI_PHY_RESETTING] = {
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001289 .enter_state = scic_sds_phy_resetting_state_enter,
1290 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001291 [SCI_PHY_FINAL] = { },
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001292};
1293
1294void scic_sds_phy_construct(struct scic_sds_phy *sci_phy,
1295 struct scic_sds_port *owning_port, u8 phy_index)
1296{
Edmund Nadolski12ef6542011-06-02 00:10:50 +00001297 sci_init_sm(&sci_phy->sm, scic_sds_phy_state_table, SCI_PHY_INITIAL);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001298
1299 /* Copy the rest of the input data to our locals */
1300 sci_phy->owning_port = owning_port;
1301 sci_phy->phy_index = phy_index;
1302 sci_phy->bcn_received_while_port_unassigned = false;
1303 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
1304 sci_phy->link_layer_registers = NULL;
1305 sci_phy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
Edmund Nadolskia628d472011-05-19 11:59:36 +00001306
1307 /* Create the SIGNATURE FIS Timeout timer for this phy */
1308 sci_init_timer(&sci_phy->sata_timer, phy_sata_timeout);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001309}
Dan Williams6f231dd2011-07-02 22:56:22 -07001310
Dan Williams4b339812011-05-06 17:36:38 -07001311void isci_phy_init(struct isci_phy *iphy, struct isci_host *ihost, int index)
Dan Williams6f231dd2011-07-02 22:56:22 -07001312{
Dan Williams150fc6f2011-02-25 10:25:21 -08001313 union scic_oem_parameters oem;
Dan Williams4b339812011-05-06 17:36:38 -07001314 u64 sci_sas_addr;
1315 __be64 sas_addr;
Dan Williams6f231dd2011-07-02 22:56:22 -07001316
Dan Williams4b339812011-05-06 17:36:38 -07001317 scic_oem_parameters_get(&ihost->sci, &oem);
1318 sci_sas_addr = oem.sds1.phys[index].sas_address.high;
1319 sci_sas_addr <<= 32;
1320 sci_sas_addr |= oem.sds1.phys[index].sas_address.low;
1321 sas_addr = cpu_to_be64(sci_sas_addr);
1322 memcpy(iphy->sas_addr, &sas_addr, sizeof(sas_addr));
Dan Williams6f231dd2011-07-02 22:56:22 -07001323
Dan Williams4b339812011-05-06 17:36:38 -07001324 iphy->isci_port = NULL;
1325 iphy->sas_phy.enabled = 0;
1326 iphy->sas_phy.id = index;
1327 iphy->sas_phy.sas_addr = &iphy->sas_addr[0];
1328 iphy->sas_phy.frame_rcvd = (u8 *)&iphy->frame_rcvd;
1329 iphy->sas_phy.ha = &ihost->sas_ha;
1330 iphy->sas_phy.lldd_phy = iphy;
1331 iphy->sas_phy.enabled = 1;
1332 iphy->sas_phy.class = SAS;
1333 iphy->sas_phy.iproto = SAS_PROTOCOL_ALL;
1334 iphy->sas_phy.tproto = 0;
1335 iphy->sas_phy.type = PHY_TYPE_PHYSICAL;
1336 iphy->sas_phy.role = PHY_ROLE_INITIATOR;
1337 iphy->sas_phy.oob_mode = OOB_NOT_CONNECTED;
1338 iphy->sas_phy.linkrate = SAS_LINK_RATE_UNKNOWN;
1339 memset(&iphy->frame_rcvd, 0, sizeof(iphy->frame_rcvd));
Dan Williams6f231dd2011-07-02 22:56:22 -07001340}
1341
1342
1343/**
1344 * isci_phy_control() - This function is one of the SAS Domain Template
1345 * functions. This is a phy management function.
1346 * @phy: This parameter specifies the sphy being controlled.
1347 * @func: This parameter specifies the phy control function being invoked.
1348 * @buf: This parameter is specific to the phy function being invoked.
1349 *
1350 * status, zero indicates success.
1351 */
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001352int isci_phy_control(struct asd_sas_phy *sas_phy,
1353 enum phy_func func,
1354 void *buf)
Dan Williams6f231dd2011-07-02 22:56:22 -07001355{
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001356 int ret = 0;
1357 struct isci_phy *iphy = sas_phy->lldd_phy;
1358 struct isci_port *iport = iphy->isci_port;
1359 struct isci_host *ihost = sas_phy->ha->lldd_ha;
1360 unsigned long flags;
Dan Williams6f231dd2011-07-02 22:56:22 -07001361
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001362 dev_dbg(&ihost->pdev->dev,
1363 "%s: phy %p; func %d; buf %p; isci phy %p, port %p\n",
1364 __func__, sas_phy, func, buf, iphy, iport);
Dan Williams6f231dd2011-07-02 22:56:22 -07001365
1366 switch (func) {
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001367 case PHY_FUNC_DISABLE:
1368 spin_lock_irqsave(&ihost->scic_lock, flags);
Dan Williams4b339812011-05-06 17:36:38 -07001369 scic_sds_phy_stop(&iphy->sci);
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001370 spin_unlock_irqrestore(&ihost->scic_lock, flags);
1371 break;
1372
Dan Williams6f231dd2011-07-02 22:56:22 -07001373 case PHY_FUNC_LINK_RESET:
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001374 spin_lock_irqsave(&ihost->scic_lock, flags);
Dan Williams4b339812011-05-06 17:36:38 -07001375 scic_sds_phy_stop(&iphy->sci);
1376 scic_sds_phy_start(&iphy->sci);
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001377 spin_unlock_irqrestore(&ihost->scic_lock, flags);
1378 break;
1379
1380 case PHY_FUNC_HARD_RESET:
1381 if (!iport)
1382 return -ENODEV;
Dan Williams6f231dd2011-07-02 22:56:22 -07001383
1384 /* Perform the port reset. */
Dan Williams4393aa42011-03-31 13:10:44 -07001385 ret = isci_port_perform_hard_reset(ihost, iport, iphy);
Dan Williams6f231dd2011-07-02 22:56:22 -07001386
1387 break;
1388
Dan Williams6f231dd2011-07-02 22:56:22 -07001389 default:
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001390 dev_dbg(&ihost->pdev->dev,
1391 "%s: phy %p; func %d NOT IMPLEMENTED!\n",
1392 __func__, sas_phy, func);
1393 ret = -ENOSYS;
Dan Williams6f231dd2011-07-02 22:56:22 -07001394 break;
1395 }
1396 return ret;
1397}