blob: 93a401dfbd30e0e064e59475e2e52951f2397ef8 [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
Jeff Skirvin9b917982011-06-20 14:09:31 -0700245 /* Disable link layer hang detection, rely on the OS timeout for I/O timeouts. */
246 writel(0, &sci_phy->link_layer_registers->link_layer_hang_detection_timeout);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700247
248 /* We can exit the initial state to the stopped state */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000249 sci_change_state(&sci_phy->sm, SCI_PHY_STOPPED);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700250
251 return SCI_SUCCESS;
252}
253
Edmund Nadolskia628d472011-05-19 11:59:36 +0000254static void phy_sata_timeout(unsigned long data)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700255{
Edmund Nadolskia628d472011-05-19 11:59:36 +0000256 struct sci_timer *tmr = (struct sci_timer *)data;
257 struct scic_sds_phy *sci_phy = container_of(tmr, typeof(*sci_phy), sata_timer);
258 struct isci_host *ihost = scic_to_ihost(sci_phy->owning_port->owning_controller);
259 unsigned long flags;
260
261 spin_lock_irqsave(&ihost->scic_lock, flags);
262
263 if (tmr->cancel)
264 goto done;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700265
266 dev_dbg(sciphy_to_dev(sci_phy),
267 "%s: SCIC SDS Phy 0x%p did not receive signature fis before "
268 "timeout.\n",
269 __func__,
270 sci_phy);
271
Edmund Nadolskie3013702011-06-02 00:10:43 +0000272 sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
Edmund Nadolskia628d472011-05-19 11:59:36 +0000273done:
274 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700275}
276
277/**
278 * This method returns the port currently containing this phy. If the phy is
279 * currently contained by the dummy port, then the phy is considered to not
280 * be part of a port.
281 * @sci_phy: This parameter specifies the phy for which to retrieve the
282 * containing port.
283 *
284 * This method returns a handle to a port that contains the supplied phy.
285 * NULL This value is returned if the phy is not part of a real
286 * port (i.e. it's contained in the dummy port). !NULL All other
287 * values indicate a handle/pointer to the port containing the phy.
288 */
Dan Williams4f20ef42011-05-12 06:00:31 -0700289struct scic_sds_port *phy_get_non_dummy_port(
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700290 struct scic_sds_phy *sci_phy)
291{
292 if (scic_sds_port_get_index(sci_phy->owning_port) == SCIC_SDS_DUMMY_PORT)
293 return NULL;
294
295 return sci_phy->owning_port;
296}
297
298/**
299 * This method will assign a port to the phy object.
300 * @out]: sci_phy This parameter specifies the phy for which to assign a port
301 * object.
302 *
303 *
304 */
305void scic_sds_phy_set_port(
306 struct scic_sds_phy *sci_phy,
307 struct scic_sds_port *sci_port)
308{
309 sci_phy->owning_port = sci_port;
310
311 if (sci_phy->bcn_received_while_port_unassigned) {
312 sci_phy->bcn_received_while_port_unassigned = false;
313 scic_sds_port_broadcast_change_received(sci_phy->owning_port, sci_phy);
314 }
315}
316
317/**
318 * This method will initialize the constructed phy
319 * @sci_phy:
320 * @link_layer_registers:
321 *
322 * enum sci_status
323 */
324enum sci_status scic_sds_phy_initialize(
325 struct scic_sds_phy *sci_phy,
326 struct scu_transport_layer_registers __iomem *transport_layer_registers,
327 struct scu_link_layer_registers __iomem *link_layer_registers)
328{
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700329 /* Perfrom the initialization of the TL hardware */
330 scic_sds_phy_transport_layer_initialization(
331 sci_phy,
332 transport_layer_registers);
333
334 /* Perofrm the initialization of the PE hardware */
335 scic_sds_phy_link_layer_initialization(sci_phy, link_layer_registers);
336
337 /*
338 * There is nothing that needs to be done in this state just
339 * transition to the stopped state. */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000340 sci_change_state(&sci_phy->sm, SCI_PHY_STOPPED);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700341
342 return SCI_SUCCESS;
343}
344
345/**
346 * This method assigns the direct attached device ID for this phy.
347 *
348 * @sci_phy The phy for which the direct attached device id is to
349 * be assigned.
350 * @device_id The direct attached device ID to assign to the phy.
351 * This will either be the RNi for the device or an invalid RNi if there
352 * is no current device assigned to the phy.
353 */
354void scic_sds_phy_setup_transport(
355 struct scic_sds_phy *sci_phy,
356 u32 device_id)
357{
358 u32 tl_control;
359
360 writel(device_id, &sci_phy->transport_layer_registers->stp_rni);
361
362 /*
363 * The read should guarantee that the first write gets posted
364 * before the next write
365 */
366 tl_control = readl(&sci_phy->transport_layer_registers->control);
367 tl_control |= SCU_TLCR_GEN_BIT(CLEAR_TCI_NCQ_MAPPING_TABLE);
368 writel(tl_control, &sci_phy->transport_layer_registers->control);
369}
370
371/**
372 *
373 * @sci_phy: The phy object to be suspended.
374 *
375 * This function will perform the register reads/writes to suspend the SCU
376 * hardware protocol engine. none
377 */
378static void scic_sds_phy_suspend(
379 struct scic_sds_phy *sci_phy)
380{
381 u32 scu_sas_pcfg_value;
382
383 scu_sas_pcfg_value =
384 readl(&sci_phy->link_layer_registers->phy_configuration);
385 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE);
386 writel(scu_sas_pcfg_value,
387 &sci_phy->link_layer_registers->phy_configuration);
388
389 scic_sds_phy_setup_transport(
390 sci_phy,
391 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX);
392}
393
394void scic_sds_phy_resume(struct scic_sds_phy *sci_phy)
395{
396 u32 scu_sas_pcfg_value;
397
398 scu_sas_pcfg_value =
399 readl(&sci_phy->link_layer_registers->phy_configuration);
400 scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE);
401 writel(scu_sas_pcfg_value,
402 &sci_phy->link_layer_registers->phy_configuration);
403}
404
405void scic_sds_phy_get_sas_address(struct scic_sds_phy *sci_phy,
406 struct sci_sas_address *sas_address)
407{
408 sas_address->high = readl(&sci_phy->link_layer_registers->source_sas_address_high);
409 sas_address->low = readl(&sci_phy->link_layer_registers->source_sas_address_low);
410}
411
412void scic_sds_phy_get_attached_sas_address(struct scic_sds_phy *sci_phy,
413 struct sci_sas_address *sas_address)
414{
415 struct sas_identify_frame *iaf;
416 struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
417
418 iaf = &iphy->frame_rcvd.iaf;
419 memcpy(sas_address, iaf->sas_addr, SAS_ADDR_SIZE);
420}
421
422void scic_sds_phy_get_protocols(struct scic_sds_phy *sci_phy,
423 struct scic_phy_proto *protocols)
424{
425 protocols->all =
426 (u16)(readl(&sci_phy->
427 link_layer_registers->transmit_identification) &
428 0x0000FFFF);
429}
430
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700431enum sci_status scic_sds_phy_start(struct scic_sds_phy *sci_phy)
432{
Edmund Nadolskie3013702011-06-02 00:10:43 +0000433 enum scic_sds_phy_states state = sci_phy->sm.current_state_id;
Dan Williams966699b2011-05-12 03:44:24 -0700434
Edmund Nadolskie3013702011-06-02 00:10:43 +0000435 if (state != SCI_PHY_STOPPED) {
Dan Williams966699b2011-05-12 03:44:24 -0700436 dev_dbg(sciphy_to_dev(sci_phy),
437 "%s: in wrong state: %d\n", __func__, state);
438 return SCI_FAILURE_INVALID_STATE;
439 }
440
Edmund Nadolskie3013702011-06-02 00:10:43 +0000441 sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
Dan Williams966699b2011-05-12 03:44:24 -0700442 return SCI_SUCCESS;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700443}
444
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700445enum sci_status scic_sds_phy_stop(struct scic_sds_phy *sci_phy)
446{
Edmund Nadolskie3013702011-06-02 00:10:43 +0000447 enum scic_sds_phy_states state = sci_phy->sm.current_state_id;
Dan Williams93153232011-05-12 04:01:03 -0700448
449 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +0000450 case SCI_PHY_SUB_INITIAL:
451 case SCI_PHY_SUB_AWAIT_OSSP_EN:
452 case SCI_PHY_SUB_AWAIT_SAS_SPEED_EN:
453 case SCI_PHY_SUB_AWAIT_SAS_POWER:
454 case SCI_PHY_SUB_AWAIT_SATA_POWER:
455 case SCI_PHY_SUB_AWAIT_SATA_PHY_EN:
456 case SCI_PHY_SUB_AWAIT_SATA_SPEED_EN:
457 case SCI_PHY_SUB_AWAIT_SIG_FIS_UF:
458 case SCI_PHY_SUB_FINAL:
459 case SCI_PHY_READY:
Dan Williams93153232011-05-12 04:01:03 -0700460 break;
461 default:
462 dev_dbg(sciphy_to_dev(sci_phy),
463 "%s: in wrong state: %d\n", __func__, state);
464 return SCI_FAILURE_INVALID_STATE;
465 }
466
Edmund Nadolskie3013702011-06-02 00:10:43 +0000467 sci_change_state(&sci_phy->sm, SCI_PHY_STOPPED);
Dan Williams93153232011-05-12 04:01:03 -0700468 return SCI_SUCCESS;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700469}
470
Dan Williams0cf36fa2011-05-12 04:02:07 -0700471enum sci_status scic_sds_phy_reset(struct scic_sds_phy *sci_phy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700472{
Edmund Nadolskie3013702011-06-02 00:10:43 +0000473 enum scic_sds_phy_states state = sci_phy->sm.current_state_id;
Dan Williams0cf36fa2011-05-12 04:02:07 -0700474
Edmund Nadolskie3013702011-06-02 00:10:43 +0000475 if (state != SCI_PHY_READY) {
Dan Williams0cf36fa2011-05-12 04:02:07 -0700476 dev_dbg(sciphy_to_dev(sci_phy),
477 "%s: in wrong state: %d\n", __func__, state);
478 return SCI_FAILURE_INVALID_STATE;
479 }
480
Edmund Nadolskie3013702011-06-02 00:10:43 +0000481 sci_change_state(&sci_phy->sm, SCI_PHY_RESETTING);
Dan Williams0cf36fa2011-05-12 04:02:07 -0700482 return SCI_SUCCESS;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700483}
484
Dan Williams5b1d4af2011-05-12 04:51:41 -0700485enum sci_status scic_sds_phy_consume_power_handler(struct scic_sds_phy *sci_phy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700486{
Edmund Nadolskie3013702011-06-02 00:10:43 +0000487 enum scic_sds_phy_states state = sci_phy->sm.current_state_id;
Dan Williams5b1d4af2011-05-12 04:51:41 -0700488
489 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +0000490 case SCI_PHY_SUB_AWAIT_SAS_POWER: {
Dan Williams5b1d4af2011-05-12 04:51:41 -0700491 u32 enable_spinup;
492
493 enable_spinup = readl(&sci_phy->link_layer_registers->notify_enable_spinup_control);
494 enable_spinup |= SCU_ENSPINUP_GEN_BIT(ENABLE);
495 writel(enable_spinup, &sci_phy->link_layer_registers->notify_enable_spinup_control);
496
497 /* Change state to the final state this substate machine has run to completion */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000498 sci_change_state(&sci_phy->sm, SCI_PHY_SUB_FINAL);
Dan Williams5b1d4af2011-05-12 04:51:41 -0700499
500 return SCI_SUCCESS;
501 }
Edmund Nadolskie3013702011-06-02 00:10:43 +0000502 case SCI_PHY_SUB_AWAIT_SATA_POWER: {
Dan Williams5b1d4af2011-05-12 04:51:41 -0700503 u32 scu_sas_pcfg_value;
504
505 /* Release the spinup hold state and reset the OOB state machine */
506 scu_sas_pcfg_value =
507 readl(&sci_phy->link_layer_registers->phy_configuration);
508 scu_sas_pcfg_value &=
509 ~(SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD) | SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE));
510 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
511 writel(scu_sas_pcfg_value,
512 &sci_phy->link_layer_registers->phy_configuration);
513
514 /* Now restart the OOB operation */
515 scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
516 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
517 writel(scu_sas_pcfg_value,
518 &sci_phy->link_layer_registers->phy_configuration);
519
520 /* Change state to the final state this substate machine has run to completion */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000521 sci_change_state(&sci_phy->sm, SCI_PHY_SUB_AWAIT_SATA_PHY_EN);
Dan Williams5b1d4af2011-05-12 04:51:41 -0700522
523 return SCI_SUCCESS;
524 }
525 default:
526 dev_dbg(sciphy_to_dev(sci_phy),
527 "%s: in wrong state: %d\n", __func__, state);
528 return SCI_FAILURE_INVALID_STATE;
529 }
Dan Williams23506a62011-05-12 04:27:29 -0700530}
531
532/*
533 * *****************************************************************************
534 * * SCIC SDS PHY HELPER FUNCTIONS
535 * ***************************************************************************** */
536
537
538/**
539 *
540 * @sci_phy: The phy object that received SAS PHY DETECTED.
541 *
542 * This method continues the link training for the phy as if it were a SAS PHY
543 * instead of a SATA PHY. This is done because the completion queue had a SAS
544 * PHY DETECTED event when the state machine was expecting a SATA PHY event.
545 * none
546 */
547static void scic_sds_phy_start_sas_link_training(
548 struct scic_sds_phy *sci_phy)
549{
550 u32 phy_control;
551
552 phy_control =
553 readl(&sci_phy->link_layer_registers->phy_configuration);
554 phy_control |= SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD);
555 writel(phy_control,
556 &sci_phy->link_layer_registers->phy_configuration);
557
Edmund Nadolskie3013702011-06-02 00:10:43 +0000558 sci_change_state(&sci_phy->sm, SCI_PHY_SUB_AWAIT_SAS_SPEED_EN);
Dan Williams23506a62011-05-12 04:27:29 -0700559
560 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SAS;
561}
562
563/**
564 *
565 * @sci_phy: The phy object that received a SATA SPINUP HOLD event
566 *
567 * This method continues the link training for the phy as if it were a SATA PHY
568 * instead of a SAS PHY. This is done because the completion queue had a SATA
569 * SPINUP HOLD event when the state machine was expecting a SAS PHY event. none
570 */
571static void scic_sds_phy_start_sata_link_training(
572 struct scic_sds_phy *sci_phy)
573{
Edmund Nadolskie3013702011-06-02 00:10:43 +0000574 sci_change_state(&sci_phy->sm, SCI_PHY_SUB_AWAIT_SATA_POWER);
Dan Williams23506a62011-05-12 04:27:29 -0700575
576 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
577}
578
579/**
580 * scic_sds_phy_complete_link_training - perform processing common to
581 * all protocols upon completion of link training.
582 * @sci_phy: This parameter specifies the phy object for which link training
583 * has completed.
584 * @max_link_rate: This parameter specifies the maximum link rate to be
585 * associated with this phy.
586 * @next_state: This parameter specifies the next state for the phy's starting
587 * sub-state machine.
588 *
589 */
590static void scic_sds_phy_complete_link_training(
591 struct scic_sds_phy *sci_phy,
592 enum sas_linkrate max_link_rate,
593 u32 next_state)
594{
595 sci_phy->max_negotiated_speed = max_link_rate;
596
Edmund Nadolskie3013702011-06-02 00:10:43 +0000597 sci_change_state(&sci_phy->sm, next_state);
Dan Williams23506a62011-05-12 04:27:29 -0700598}
599
Dan Williams23506a62011-05-12 04:27:29 -0700600enum sci_status scic_sds_phy_event_handler(struct scic_sds_phy *sci_phy,
601 u32 event_code)
602{
Edmund Nadolskie3013702011-06-02 00:10:43 +0000603 enum scic_sds_phy_states state = sci_phy->sm.current_state_id;
Dan Williams23506a62011-05-12 04:27:29 -0700604
605 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +0000606 case SCI_PHY_SUB_AWAIT_OSSP_EN:
Dan Williams23506a62011-05-12 04:27:29 -0700607 switch (scu_get_event_code(event_code)) {
608 case SCU_EVENT_SAS_PHY_DETECTED:
609 scic_sds_phy_start_sas_link_training(sci_phy);
610 sci_phy->is_in_link_training = true;
611 break;
612 case SCU_EVENT_SATA_SPINUP_HOLD:
613 scic_sds_phy_start_sata_link_training(sci_phy);
614 sci_phy->is_in_link_training = true;
615 break;
616 default:
617 dev_dbg(sciphy_to_dev(sci_phy),
618 "%s: PHY starting substate machine received "
619 "unexpected event_code %x\n",
620 __func__,
621 event_code);
622 return SCI_FAILURE;
623 }
624 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000625 case SCI_PHY_SUB_AWAIT_SAS_SPEED_EN:
Dan Williams23506a62011-05-12 04:27:29 -0700626 switch (scu_get_event_code(event_code)) {
627 case SCU_EVENT_SAS_PHY_DETECTED:
628 /*
629 * Why is this being reported again by the controller?
630 * We would re-enter this state so just stay here */
631 break;
632 case SCU_EVENT_SAS_15:
633 case SCU_EVENT_SAS_15_SSC:
634 scic_sds_phy_complete_link_training(
635 sci_phy,
636 SAS_LINK_RATE_1_5_GBPS,
Edmund Nadolskie3013702011-06-02 00:10:43 +0000637 SCI_PHY_SUB_AWAIT_IAF_UF);
Dan Williams23506a62011-05-12 04:27:29 -0700638 break;
639 case SCU_EVENT_SAS_30:
640 case SCU_EVENT_SAS_30_SSC:
641 scic_sds_phy_complete_link_training(
642 sci_phy,
643 SAS_LINK_RATE_3_0_GBPS,
Edmund Nadolskie3013702011-06-02 00:10:43 +0000644 SCI_PHY_SUB_AWAIT_IAF_UF);
Dan Williams23506a62011-05-12 04:27:29 -0700645 break;
646 case SCU_EVENT_SAS_60:
647 case SCU_EVENT_SAS_60_SSC:
648 scic_sds_phy_complete_link_training(
649 sci_phy,
650 SAS_LINK_RATE_6_0_GBPS,
Edmund Nadolskie3013702011-06-02 00:10:43 +0000651 SCI_PHY_SUB_AWAIT_IAF_UF);
Dan Williams23506a62011-05-12 04:27:29 -0700652 break;
653 case SCU_EVENT_SATA_SPINUP_HOLD:
654 /*
655 * We were doing SAS PHY link training and received a SATA PHY event
656 * continue OOB/SN as if this were a SATA PHY */
657 scic_sds_phy_start_sata_link_training(sci_phy);
658 break;
659 case SCU_EVENT_LINK_FAILURE:
660 /* Link failure change state back to the starting state */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000661 sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700662 break;
663 default:
664 dev_warn(sciphy_to_dev(sci_phy),
665 "%s: PHY starting substate machine received "
666 "unexpected event_code %x\n",
667 __func__, event_code);
668
669 return SCI_FAILURE;
670 break;
671 }
672 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000673 case SCI_PHY_SUB_AWAIT_IAF_UF:
Dan Williams23506a62011-05-12 04:27:29 -0700674 switch (scu_get_event_code(event_code)) {
675 case SCU_EVENT_SAS_PHY_DETECTED:
676 /* Backup the state machine */
677 scic_sds_phy_start_sas_link_training(sci_phy);
678 break;
679 case SCU_EVENT_SATA_SPINUP_HOLD:
680 /* We were doing SAS PHY link training and received a
681 * SATA PHY event continue OOB/SN as if this were a
682 * SATA PHY
683 */
684 scic_sds_phy_start_sata_link_training(sci_phy);
685 break;
686 case SCU_EVENT_RECEIVED_IDENTIFY_TIMEOUT:
687 case SCU_EVENT_LINK_FAILURE:
688 case SCU_EVENT_HARD_RESET_RECEIVED:
689 /* Start the oob/sn state machine over again */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000690 sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700691 break;
692 default:
693 dev_warn(sciphy_to_dev(sci_phy),
694 "%s: PHY starting substate machine received "
695 "unexpected event_code %x\n",
696 __func__, event_code);
697 return SCI_FAILURE;
698 }
699 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000700 case SCI_PHY_SUB_AWAIT_SAS_POWER:
Dan Williams23506a62011-05-12 04:27:29 -0700701 switch (scu_get_event_code(event_code)) {
702 case SCU_EVENT_LINK_FAILURE:
703 /* Link failure change state back to the starting state */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000704 sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700705 break;
706 default:
707 dev_warn(sciphy_to_dev(sci_phy),
708 "%s: PHY starting substate machine received unexpected "
709 "event_code %x\n",
710 __func__,
711 event_code);
712 return SCI_FAILURE;
713 }
714 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000715 case SCI_PHY_SUB_AWAIT_SATA_POWER:
Dan Williams23506a62011-05-12 04:27:29 -0700716 switch (scu_get_event_code(event_code)) {
717 case SCU_EVENT_LINK_FAILURE:
718 /* Link failure change state back to the starting state */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000719 sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700720 break;
721 case SCU_EVENT_SATA_SPINUP_HOLD:
722 /* These events are received every 10ms and are
723 * expected while in this state
724 */
725 break;
726
727 case SCU_EVENT_SAS_PHY_DETECTED:
728 /* There has been a change in the phy type before OOB/SN for the
729 * SATA finished start down the SAS link traning path.
730 */
731 scic_sds_phy_start_sas_link_training(sci_phy);
732 break;
733
734 default:
735 dev_warn(sciphy_to_dev(sci_phy),
736 "%s: PHY starting substate machine received "
737 "unexpected event_code %x\n",
738 __func__, event_code);
739
740 return SCI_FAILURE;
741 }
742 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000743 case SCI_PHY_SUB_AWAIT_SATA_PHY_EN:
Dan Williams23506a62011-05-12 04:27:29 -0700744 switch (scu_get_event_code(event_code)) {
745 case SCU_EVENT_LINK_FAILURE:
746 /* Link failure change state back to the starting state */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000747 sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700748 break;
749 case SCU_EVENT_SATA_SPINUP_HOLD:
750 /* These events might be received since we dont know how many may be in
751 * the completion queue while waiting for power
752 */
753 break;
754 case SCU_EVENT_SATA_PHY_DETECTED:
755 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
756
757 /* We have received the SATA PHY notification change state */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000758 sci_change_state(&sci_phy->sm, SCI_PHY_SUB_AWAIT_SATA_SPEED_EN);
Dan Williams23506a62011-05-12 04:27:29 -0700759 break;
760 case SCU_EVENT_SAS_PHY_DETECTED:
761 /* There has been a change in the phy type before OOB/SN for the
762 * SATA finished start down the SAS link traning path.
763 */
764 scic_sds_phy_start_sas_link_training(sci_phy);
765 break;
766 default:
767 dev_warn(sciphy_to_dev(sci_phy),
768 "%s: PHY starting substate machine received "
769 "unexpected event_code %x\n",
770 __func__,
771 event_code);
772
773 return SCI_FAILURE;;
774 }
775 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000776 case SCI_PHY_SUB_AWAIT_SATA_SPEED_EN:
Dan Williams23506a62011-05-12 04:27:29 -0700777 switch (scu_get_event_code(event_code)) {
778 case SCU_EVENT_SATA_PHY_DETECTED:
779 /*
780 * The hardware reports multiple SATA PHY detected events
781 * ignore the extras */
782 break;
783 case SCU_EVENT_SATA_15:
784 case SCU_EVENT_SATA_15_SSC:
785 scic_sds_phy_complete_link_training(
786 sci_phy,
787 SAS_LINK_RATE_1_5_GBPS,
Edmund Nadolskie3013702011-06-02 00:10:43 +0000788 SCI_PHY_SUB_AWAIT_SIG_FIS_UF);
Dan Williams23506a62011-05-12 04:27:29 -0700789 break;
790 case SCU_EVENT_SATA_30:
791 case SCU_EVENT_SATA_30_SSC:
792 scic_sds_phy_complete_link_training(
793 sci_phy,
794 SAS_LINK_RATE_3_0_GBPS,
Edmund Nadolskie3013702011-06-02 00:10:43 +0000795 SCI_PHY_SUB_AWAIT_SIG_FIS_UF);
Dan Williams23506a62011-05-12 04:27:29 -0700796 break;
797 case SCU_EVENT_SATA_60:
798 case SCU_EVENT_SATA_60_SSC:
799 scic_sds_phy_complete_link_training(
800 sci_phy,
801 SAS_LINK_RATE_6_0_GBPS,
Edmund Nadolskie3013702011-06-02 00:10:43 +0000802 SCI_PHY_SUB_AWAIT_SIG_FIS_UF);
Dan Williams23506a62011-05-12 04:27:29 -0700803 break;
804 case SCU_EVENT_LINK_FAILURE:
805 /* Link failure change state back to the starting state */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000806 sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700807 break;
808 case SCU_EVENT_SAS_PHY_DETECTED:
809 /*
810 * There has been a change in the phy type before OOB/SN for the
811 * SATA finished start down the SAS link traning path. */
812 scic_sds_phy_start_sas_link_training(sci_phy);
813 break;
814 default:
815 dev_warn(sciphy_to_dev(sci_phy),
816 "%s: PHY starting substate machine received "
817 "unexpected event_code %x\n",
818 __func__, event_code);
819
820 return SCI_FAILURE;
821 }
822
823 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000824 case SCI_PHY_SUB_AWAIT_SIG_FIS_UF:
Dan Williams23506a62011-05-12 04:27:29 -0700825 switch (scu_get_event_code(event_code)) {
826 case SCU_EVENT_SATA_PHY_DETECTED:
827 /* Backup the state machine */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000828 sci_change_state(&sci_phy->sm, SCI_PHY_SUB_AWAIT_SATA_SPEED_EN);
Dan Williams23506a62011-05-12 04:27:29 -0700829 break;
830
831 case SCU_EVENT_LINK_FAILURE:
832 /* Link failure change state back to the starting state */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000833 sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700834 break;
835
836 default:
837 dev_warn(sciphy_to_dev(sci_phy),
838 "%s: PHY starting substate machine received "
839 "unexpected event_code %x\n",
840 __func__,
841 event_code);
842
843 return SCI_FAILURE;
844 }
845 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000846 case SCI_PHY_READY:
Dan Williams23506a62011-05-12 04:27:29 -0700847 switch (scu_get_event_code(event_code)) {
848 case SCU_EVENT_LINK_FAILURE:
849 /* Link failure change state back to the starting state */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000850 sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700851 break;
852 case SCU_EVENT_BROADCAST_CHANGE:
853 /* Broadcast change received. Notify the port. */
Dan Williams4f20ef42011-05-12 06:00:31 -0700854 if (phy_get_non_dummy_port(sci_phy) != NULL)
Dan Williams23506a62011-05-12 04:27:29 -0700855 scic_sds_port_broadcast_change_received(sci_phy->owning_port, sci_phy);
856 else
857 sci_phy->bcn_received_while_port_unassigned = true;
858 break;
859 default:
860 dev_warn(sciphy_to_dev(sci_phy),
861 "%sP SCIC PHY 0x%p ready state machine received "
862 "unexpected event_code %x\n",
863 __func__, sci_phy, event_code);
864 return SCI_FAILURE_INVALID_STATE;
865 }
866 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000867 case SCI_PHY_RESETTING:
Dan Williams23506a62011-05-12 04:27:29 -0700868 switch (scu_get_event_code(event_code)) {
869 case SCU_EVENT_HARD_RESET_TRANSMITTED:
870 /* Link failure change state back to the starting state */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000871 sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700872 break;
873 default:
874 dev_warn(sciphy_to_dev(sci_phy),
875 "%s: SCIC PHY 0x%p resetting state machine received "
876 "unexpected event_code %x\n",
877 __func__, sci_phy, event_code);
878
879 return SCI_FAILURE_INVALID_STATE;
880 break;
881 }
882 return SCI_SUCCESS;
883 default:
884 dev_dbg(sciphy_to_dev(sci_phy),
885 "%s: in wrong state: %d\n", __func__, state);
886 return SCI_FAILURE_INVALID_STATE;
887 }
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700888}
889
Dan Williamsc4441ab2011-05-12 04:17:51 -0700890enum sci_status scic_sds_phy_frame_handler(struct scic_sds_phy *sci_phy,
891 u32 frame_index)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700892{
Edmund Nadolskie3013702011-06-02 00:10:43 +0000893 enum scic_sds_phy_states state = sci_phy->sm.current_state_id;
Dan Williamsc4441ab2011-05-12 04:17:51 -0700894 struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller;
895 enum sci_status result;
896
897 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +0000898 case SCI_PHY_SUB_AWAIT_IAF_UF: {
Dan Williamsc4441ab2011-05-12 04:17:51 -0700899 u32 *frame_words;
900 struct sas_identify_frame iaf;
901 struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
902
903 result = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
904 frame_index,
905 (void **)&frame_words);
906
907 if (result != SCI_SUCCESS)
908 return result;
909
910 sci_swab32_cpy(&iaf, frame_words, sizeof(iaf) / sizeof(u32));
911 if (iaf.frame_type == 0) {
912 u32 state;
913
914 memcpy(&iphy->frame_rcvd.iaf, &iaf, sizeof(iaf));
915 if (iaf.smp_tport) {
916 /* We got the IAF for an expander PHY go to the final
917 * state since there are no power requirements for
918 * expander phys.
919 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000920 state = SCI_PHY_SUB_FINAL;
Dan Williamsc4441ab2011-05-12 04:17:51 -0700921 } else {
922 /* We got the IAF we can now go to the await spinup
923 * semaphore state
924 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000925 state = SCI_PHY_SUB_AWAIT_SAS_POWER;
Dan Williamsc4441ab2011-05-12 04:17:51 -0700926 }
Edmund Nadolskie3013702011-06-02 00:10:43 +0000927 sci_change_state(&sci_phy->sm, state);
Dan Williamsc4441ab2011-05-12 04:17:51 -0700928 result = SCI_SUCCESS;
929 } else
930 dev_warn(sciphy_to_dev(sci_phy),
931 "%s: PHY starting substate machine received "
932 "unexpected frame id %x\n",
933 __func__, frame_index);
934
935 scic_sds_controller_release_frame(scic, frame_index);
936 return result;
937 }
Edmund Nadolskie3013702011-06-02 00:10:43 +0000938 case SCI_PHY_SUB_AWAIT_SIG_FIS_UF: {
Dan Williamsc4441ab2011-05-12 04:17:51 -0700939 struct dev_to_host_fis *frame_header;
940 u32 *fis_frame_data;
941 struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
942
943 result = scic_sds_unsolicited_frame_control_get_header(
944 &(scic_sds_phy_get_controller(sci_phy)->uf_control),
945 frame_index,
946 (void **)&frame_header);
947
948 if (result != SCI_SUCCESS)
949 return result;
950
951 if ((frame_header->fis_type == FIS_REGD2H) &&
952 !(frame_header->status & ATA_BUSY)) {
953 scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
954 frame_index,
955 (void **)&fis_frame_data);
956
957 scic_sds_controller_copy_sata_response(&iphy->frame_rcvd.fis,
958 frame_header,
959 fis_frame_data);
960
961 /* got IAF we can now go to the await spinup semaphore state */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000962 sci_change_state(&sci_phy->sm, SCI_PHY_SUB_FINAL);
Dan Williamsc4441ab2011-05-12 04:17:51 -0700963
964 result = SCI_SUCCESS;
965 } else
966 dev_warn(sciphy_to_dev(sci_phy),
967 "%s: PHY starting substate machine received "
968 "unexpected frame id %x\n",
969 __func__, frame_index);
970
971 /* Regardless of the result we are done with this frame with it */
972 scic_sds_controller_release_frame(scic, frame_index);
973
974 return result;
975 }
976 default:
977 dev_dbg(sciphy_to_dev(sci_phy),
978 "%s: in wrong state: %d\n", __func__, state);
979 return SCI_FAILURE_INVALID_STATE;
980 }
981
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700982}
983
Dan Williams9269e0e2011-05-12 07:42:17 -0700984static void scic_sds_phy_starting_initial_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +0000985{
Edmund Nadolskie3013702011-06-02 00:10:43 +0000986 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +0000987
Adam Gruchala4a33c522011-05-10 23:54:23 +0000988 /* This is just an temporary state go off to the starting state */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000989 sci_change_state(&sci_phy->sm, SCI_PHY_SUB_AWAIT_OSSP_EN);
Adam Gruchala4a33c522011-05-10 23:54:23 +0000990}
991
Dan Williams9269e0e2011-05-12 07:42:17 -0700992static void scic_sds_phy_starting_await_sas_power_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +0000993{
Edmund Nadolskie3013702011-06-02 00:10:43 +0000994 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Dan Williams5b1d4af2011-05-12 04:51:41 -0700995 struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller;
Adam Gruchala4a33c522011-05-10 23:54:23 +0000996
Dan Williams5b1d4af2011-05-12 04:51:41 -0700997 scic_sds_controller_power_control_queue_insert(scic, sci_phy);
Adam Gruchala4a33c522011-05-10 23:54:23 +0000998}
999
Dan Williams9269e0e2011-05-12 07:42:17 -07001000static void scic_sds_phy_starting_await_sas_power_substate_exit(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001001{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001002 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Dan Williams5b1d4af2011-05-12 04:51:41 -07001003 struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller;
Adam Gruchala4a33c522011-05-10 23:54:23 +00001004
Dan Williams5b1d4af2011-05-12 04:51:41 -07001005 scic_sds_controller_power_control_queue_remove(scic, sci_phy);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001006}
1007
Dan Williams9269e0e2011-05-12 07:42:17 -07001008static void scic_sds_phy_starting_await_sata_power_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001009{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001010 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Dan Williams5b1d4af2011-05-12 04:51:41 -07001011 struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller;
Adam Gruchala4a33c522011-05-10 23:54:23 +00001012
Dan Williams5b1d4af2011-05-12 04:51:41 -07001013 scic_sds_controller_power_control_queue_insert(scic, sci_phy);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001014}
1015
Dan Williams9269e0e2011-05-12 07:42:17 -07001016static void scic_sds_phy_starting_await_sata_power_substate_exit(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001017{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001018 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Dan Williams5b1d4af2011-05-12 04:51:41 -07001019 struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller;
Adam Gruchala4a33c522011-05-10 23:54:23 +00001020
Dan Williams5b1d4af2011-05-12 04:51:41 -07001021 scic_sds_controller_power_control_queue_remove(scic, sci_phy);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001022}
1023
Dan Williams9269e0e2011-05-12 07:42:17 -07001024static void scic_sds_phy_starting_await_sata_phy_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001025{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001026 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001027
Edmund Nadolskia628d472011-05-19 11:59:36 +00001028 sci_mod_timer(&sci_phy->sata_timer, SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001029}
1030
Dan Williams9269e0e2011-05-12 07:42:17 -07001031static void scic_sds_phy_starting_await_sata_phy_substate_exit(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001032{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001033 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001034
Edmund Nadolskia628d472011-05-19 11:59:36 +00001035 sci_del_timer(&sci_phy->sata_timer);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001036}
1037
Dan Williams9269e0e2011-05-12 07:42:17 -07001038static void scic_sds_phy_starting_await_sata_speed_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001039{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001040 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001041
Edmund Nadolskia628d472011-05-19 11:59:36 +00001042 sci_mod_timer(&sci_phy->sata_timer, SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001043}
1044
Dan Williams9269e0e2011-05-12 07:42:17 -07001045static void scic_sds_phy_starting_await_sata_speed_substate_exit(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001046{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001047 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001048
Edmund Nadolskia628d472011-05-19 11:59:36 +00001049 sci_del_timer(&sci_phy->sata_timer);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001050}
1051
Dan Williams9269e0e2011-05-12 07:42:17 -07001052static void scic_sds_phy_starting_await_sig_fis_uf_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001053{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001054 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001055
Dan Williams5b1d4af2011-05-12 04:51:41 -07001056 if (scic_sds_port_link_detected(sci_phy->owning_port, sci_phy)) {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001057
Adam Gruchala4a33c522011-05-10 23:54:23 +00001058 /*
1059 * Clear the PE suspend condition so we can actually
1060 * receive SIG FIS
1061 * The hardware will not respond to the XRDY until the PE
1062 * suspend condition is cleared.
1063 */
1064 scic_sds_phy_resume(sci_phy);
1065
Edmund Nadolskia628d472011-05-19 11:59:36 +00001066 sci_mod_timer(&sci_phy->sata_timer,
1067 SCIC_SDS_SIGNATURE_FIS_TIMEOUT);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001068 } else
1069 sci_phy->is_in_link_training = false;
1070}
1071
Dan Williams9269e0e2011-05-12 07:42:17 -07001072static void scic_sds_phy_starting_await_sig_fis_uf_substate_exit(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001073{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001074 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001075
Edmund Nadolskia628d472011-05-19 11:59:36 +00001076 sci_del_timer(&sci_phy->sata_timer);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001077}
1078
Dan Williams9269e0e2011-05-12 07:42:17 -07001079static void scic_sds_phy_starting_final_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001080{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001081 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001082
Adam Gruchala4a33c522011-05-10 23:54:23 +00001083 /* State machine has run to completion so exit out and change
1084 * the base state machine to the ready state
1085 */
Edmund Nadolskie3013702011-06-02 00:10:43 +00001086 sci_change_state(&sci_phy->sm, SCI_PHY_READY);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001087}
1088
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001089/**
1090 *
1091 * @sci_phy: This is the struct scic_sds_phy object to stop.
1092 *
1093 * This method will stop the struct scic_sds_phy object. This does not reset the
1094 * protocol engine it just suspends it and places it in a state where it will
1095 * not cause the end device to power up. none
1096 */
1097static void scu_link_layer_stop_protocol_engine(
1098 struct scic_sds_phy *sci_phy)
1099{
1100 u32 scu_sas_pcfg_value;
1101 u32 enable_spinup_value;
1102
1103 /* Suspend the protocol engine and place it in a sata spinup hold state */
1104 scu_sas_pcfg_value =
1105 readl(&sci_phy->link_layer_registers->phy_configuration);
1106 scu_sas_pcfg_value |=
1107 (SCU_SAS_PCFG_GEN_BIT(OOB_RESET) |
1108 SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE) |
1109 SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD));
1110 writel(scu_sas_pcfg_value,
1111 &sci_phy->link_layer_registers->phy_configuration);
1112
1113 /* Disable the notify enable spinup primitives */
1114 enable_spinup_value = readl(&sci_phy->link_layer_registers->notify_enable_spinup_control);
1115 enable_spinup_value &= ~SCU_ENSPINUP_GEN_BIT(ENABLE);
1116 writel(enable_spinup_value, &sci_phy->link_layer_registers->notify_enable_spinup_control);
1117}
1118
1119/**
1120 *
1121 *
1122 * This method will start the OOB/SN state machine for this struct scic_sds_phy object.
1123 */
1124static void scu_link_layer_start_oob(
1125 struct scic_sds_phy *sci_phy)
1126{
1127 u32 scu_sas_pcfg_value;
1128
1129 scu_sas_pcfg_value =
1130 readl(&sci_phy->link_layer_registers->phy_configuration);
1131 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
1132 scu_sas_pcfg_value &=
1133 ~(SCU_SAS_PCFG_GEN_BIT(OOB_RESET) |
1134 SCU_SAS_PCFG_GEN_BIT(HARD_RESET));
1135 writel(scu_sas_pcfg_value,
1136 &sci_phy->link_layer_registers->phy_configuration);
1137}
1138
1139/**
1140 *
1141 *
1142 * This method will transmit a hard reset request on the specified phy. The SCU
1143 * hardware requires that we reset the OOB state machine and set the hard reset
1144 * bit in the phy configuration register. We then must start OOB over with the
1145 * hard reset bit set.
1146 */
1147static void scu_link_layer_tx_hard_reset(
1148 struct scic_sds_phy *sci_phy)
1149{
1150 u32 phy_configuration_value;
1151
1152 /*
1153 * SAS Phys must wait for the HARD_RESET_TX event notification to transition
1154 * to the starting state. */
1155 phy_configuration_value =
1156 readl(&sci_phy->link_layer_registers->phy_configuration);
1157 phy_configuration_value |=
1158 (SCU_SAS_PCFG_GEN_BIT(HARD_RESET) |
1159 SCU_SAS_PCFG_GEN_BIT(OOB_RESET));
1160 writel(phy_configuration_value,
1161 &sci_phy->link_layer_registers->phy_configuration);
1162
1163 /* Now take the OOB state machine out of reset */
1164 phy_configuration_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
1165 phy_configuration_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
1166 writel(phy_configuration_value,
1167 &sci_phy->link_layer_registers->phy_configuration);
1168}
1169
Dan Williams9269e0e2011-05-12 07:42:17 -07001170static void scic_sds_phy_stopped_state_enter(struct sci_base_state_machine *sm)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001171{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001172 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001173
1174 /*
1175 * @todo We need to get to the controller to place this PE in a
1176 * reset state
1177 */
Edmund Nadolskia628d472011-05-19 11:59:36 +00001178 sci_del_timer(&sci_phy->sata_timer);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001179
1180 scu_link_layer_stop_protocol_engine(sci_phy);
1181
Edmund Nadolskie3013702011-06-02 00:10:43 +00001182 if (sci_phy->sm.previous_state_id != SCI_PHY_INITIAL)
Dan Williams5b1d4af2011-05-12 04:51:41 -07001183 scic_sds_controller_link_down(scic_sds_phy_get_controller(sci_phy),
Dan Williams4f20ef42011-05-12 06:00:31 -07001184 phy_get_non_dummy_port(sci_phy),
Dan Williams5b1d4af2011-05-12 04:51:41 -07001185 sci_phy);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001186}
1187
Dan Williams9269e0e2011-05-12 07:42:17 -07001188static void scic_sds_phy_starting_state_enter(struct sci_base_state_machine *sm)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001189{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001190 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001191
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001192 scu_link_layer_stop_protocol_engine(sci_phy);
1193 scu_link_layer_start_oob(sci_phy);
1194
1195 /* We don't know what kind of phy we are going to be just yet */
1196 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
1197 sci_phy->bcn_received_while_port_unassigned = false;
1198
Edmund Nadolskie3013702011-06-02 00:10:43 +00001199 if (sci_phy->sm.previous_state_id == SCI_PHY_READY)
Dan Williams5b1d4af2011-05-12 04:51:41 -07001200 scic_sds_controller_link_down(scic_sds_phy_get_controller(sci_phy),
Dan Williams4f20ef42011-05-12 06:00:31 -07001201 phy_get_non_dummy_port(sci_phy),
Dan Williams5b1d4af2011-05-12 04:51:41 -07001202 sci_phy);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001203
Edmund Nadolskie3013702011-06-02 00:10:43 +00001204 sci_change_state(&sci_phy->sm, SCI_PHY_SUB_INITIAL);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001205}
1206
Dan Williams9269e0e2011-05-12 07:42:17 -07001207static void scic_sds_phy_ready_state_enter(struct sci_base_state_machine *sm)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001208{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001209 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001210
Dan Williams5b1d4af2011-05-12 04:51:41 -07001211 scic_sds_controller_link_up(scic_sds_phy_get_controller(sci_phy),
Dan Williams4f20ef42011-05-12 06:00:31 -07001212 phy_get_non_dummy_port(sci_phy),
Dan Williams5b1d4af2011-05-12 04:51:41 -07001213 sci_phy);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001214
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001215}
1216
Dan Williams9269e0e2011-05-12 07:42:17 -07001217static void scic_sds_phy_ready_state_exit(struct sci_base_state_machine *sm)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001218{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001219 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001220
1221 scic_sds_phy_suspend(sci_phy);
1222}
1223
Dan Williams9269e0e2011-05-12 07:42:17 -07001224static void scic_sds_phy_resetting_state_enter(struct sci_base_state_machine *sm)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001225{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001226 struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001227
Dan Williams5b1d4af2011-05-12 04:51:41 -07001228 /* The phy is being reset, therefore deactivate it from the port. In
1229 * the resetting state we don't notify the user regarding link up and
1230 * link down notifications
1231 */
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001232 scic_sds_port_deactivate_phy(sci_phy->owning_port, sci_phy, false);
1233
1234 if (sci_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
1235 scu_link_layer_tx_hard_reset(sci_phy);
1236 } else {
Dan Williams5b1d4af2011-05-12 04:51:41 -07001237 /* The SCU does not need to have a discrete reset state so
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001238 * just go back to the starting state.
1239 */
Edmund Nadolskie3013702011-06-02 00:10:43 +00001240 sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001241 }
1242}
1243
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001244static const struct sci_base_state scic_sds_phy_state_table[] = {
Edmund Nadolskie3013702011-06-02 00:10:43 +00001245 [SCI_PHY_INITIAL] = { },
1246 [SCI_PHY_STOPPED] = {
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001247 .enter_state = scic_sds_phy_stopped_state_enter,
1248 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001249 [SCI_PHY_STARTING] = {
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001250 .enter_state = scic_sds_phy_starting_state_enter,
1251 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001252 [SCI_PHY_SUB_INITIAL] = {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001253 .enter_state = scic_sds_phy_starting_initial_substate_enter,
1254 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001255 [SCI_PHY_SUB_AWAIT_OSSP_EN] = { },
1256 [SCI_PHY_SUB_AWAIT_SAS_SPEED_EN] = { },
1257 [SCI_PHY_SUB_AWAIT_IAF_UF] = { },
1258 [SCI_PHY_SUB_AWAIT_SAS_POWER] = {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001259 .enter_state = scic_sds_phy_starting_await_sas_power_substate_enter,
1260 .exit_state = scic_sds_phy_starting_await_sas_power_substate_exit,
1261 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001262 [SCI_PHY_SUB_AWAIT_SATA_POWER] = {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001263 .enter_state = scic_sds_phy_starting_await_sata_power_substate_enter,
1264 .exit_state = scic_sds_phy_starting_await_sata_power_substate_exit
1265 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001266 [SCI_PHY_SUB_AWAIT_SATA_PHY_EN] = {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001267 .enter_state = scic_sds_phy_starting_await_sata_phy_substate_enter,
1268 .exit_state = scic_sds_phy_starting_await_sata_phy_substate_exit
1269 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001270 [SCI_PHY_SUB_AWAIT_SATA_SPEED_EN] = {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001271 .enter_state = scic_sds_phy_starting_await_sata_speed_substate_enter,
1272 .exit_state = scic_sds_phy_starting_await_sata_speed_substate_exit
1273 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001274 [SCI_PHY_SUB_AWAIT_SIG_FIS_UF] = {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001275 .enter_state = scic_sds_phy_starting_await_sig_fis_uf_substate_enter,
1276 .exit_state = scic_sds_phy_starting_await_sig_fis_uf_substate_exit
1277 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001278 [SCI_PHY_SUB_FINAL] = {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001279 .enter_state = scic_sds_phy_starting_final_substate_enter,
1280 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001281 [SCI_PHY_READY] = {
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001282 .enter_state = scic_sds_phy_ready_state_enter,
1283 .exit_state = scic_sds_phy_ready_state_exit,
1284 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001285 [SCI_PHY_RESETTING] = {
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001286 .enter_state = scic_sds_phy_resetting_state_enter,
1287 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001288 [SCI_PHY_FINAL] = { },
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001289};
1290
1291void scic_sds_phy_construct(struct scic_sds_phy *sci_phy,
1292 struct scic_sds_port *owning_port, u8 phy_index)
1293{
Edmund Nadolski12ef6542011-06-02 00:10:50 +00001294 sci_init_sm(&sci_phy->sm, scic_sds_phy_state_table, SCI_PHY_INITIAL);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001295
1296 /* Copy the rest of the input data to our locals */
1297 sci_phy->owning_port = owning_port;
1298 sci_phy->phy_index = phy_index;
1299 sci_phy->bcn_received_while_port_unassigned = false;
1300 sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
1301 sci_phy->link_layer_registers = NULL;
1302 sci_phy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
Edmund Nadolskia628d472011-05-19 11:59:36 +00001303
1304 /* Create the SIGNATURE FIS Timeout timer for this phy */
1305 sci_init_timer(&sci_phy->sata_timer, phy_sata_timeout);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001306}
Dan Williams6f231dd2011-07-02 22:56:22 -07001307
Dan Williams4b339812011-05-06 17:36:38 -07001308void isci_phy_init(struct isci_phy *iphy, struct isci_host *ihost, int index)
Dan Williams6f231dd2011-07-02 22:56:22 -07001309{
Dan Williams150fc6f2011-02-25 10:25:21 -08001310 union scic_oem_parameters oem;
Dan Williams4b339812011-05-06 17:36:38 -07001311 u64 sci_sas_addr;
1312 __be64 sas_addr;
Dan Williams6f231dd2011-07-02 22:56:22 -07001313
Dan Williams4b339812011-05-06 17:36:38 -07001314 scic_oem_parameters_get(&ihost->sci, &oem);
1315 sci_sas_addr = oem.sds1.phys[index].sas_address.high;
1316 sci_sas_addr <<= 32;
1317 sci_sas_addr |= oem.sds1.phys[index].sas_address.low;
1318 sas_addr = cpu_to_be64(sci_sas_addr);
1319 memcpy(iphy->sas_addr, &sas_addr, sizeof(sas_addr));
Dan Williams6f231dd2011-07-02 22:56:22 -07001320
Dan Williams4b339812011-05-06 17:36:38 -07001321 iphy->isci_port = NULL;
1322 iphy->sas_phy.enabled = 0;
1323 iphy->sas_phy.id = index;
1324 iphy->sas_phy.sas_addr = &iphy->sas_addr[0];
1325 iphy->sas_phy.frame_rcvd = (u8 *)&iphy->frame_rcvd;
1326 iphy->sas_phy.ha = &ihost->sas_ha;
1327 iphy->sas_phy.lldd_phy = iphy;
1328 iphy->sas_phy.enabled = 1;
1329 iphy->sas_phy.class = SAS;
1330 iphy->sas_phy.iproto = SAS_PROTOCOL_ALL;
1331 iphy->sas_phy.tproto = 0;
1332 iphy->sas_phy.type = PHY_TYPE_PHYSICAL;
1333 iphy->sas_phy.role = PHY_ROLE_INITIATOR;
1334 iphy->sas_phy.oob_mode = OOB_NOT_CONNECTED;
1335 iphy->sas_phy.linkrate = SAS_LINK_RATE_UNKNOWN;
1336 memset(&iphy->frame_rcvd, 0, sizeof(iphy->frame_rcvd));
Dan Williams6f231dd2011-07-02 22:56:22 -07001337}
1338
1339
1340/**
1341 * isci_phy_control() - This function is one of the SAS Domain Template
1342 * functions. This is a phy management function.
1343 * @phy: This parameter specifies the sphy being controlled.
1344 * @func: This parameter specifies the phy control function being invoked.
1345 * @buf: This parameter is specific to the phy function being invoked.
1346 *
1347 * status, zero indicates success.
1348 */
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001349int isci_phy_control(struct asd_sas_phy *sas_phy,
1350 enum phy_func func,
1351 void *buf)
Dan Williams6f231dd2011-07-02 22:56:22 -07001352{
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001353 int ret = 0;
1354 struct isci_phy *iphy = sas_phy->lldd_phy;
1355 struct isci_port *iport = iphy->isci_port;
1356 struct isci_host *ihost = sas_phy->ha->lldd_ha;
1357 unsigned long flags;
Dan Williams6f231dd2011-07-02 22:56:22 -07001358
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001359 dev_dbg(&ihost->pdev->dev,
1360 "%s: phy %p; func %d; buf %p; isci phy %p, port %p\n",
1361 __func__, sas_phy, func, buf, iphy, iport);
Dan Williams6f231dd2011-07-02 22:56:22 -07001362
1363 switch (func) {
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001364 case PHY_FUNC_DISABLE:
1365 spin_lock_irqsave(&ihost->scic_lock, flags);
Dan Williams4b339812011-05-06 17:36:38 -07001366 scic_sds_phy_stop(&iphy->sci);
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001367 spin_unlock_irqrestore(&ihost->scic_lock, flags);
1368 break;
1369
Dan Williams6f231dd2011-07-02 22:56:22 -07001370 case PHY_FUNC_LINK_RESET:
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001371 spin_lock_irqsave(&ihost->scic_lock, flags);
Dan Williams4b339812011-05-06 17:36:38 -07001372 scic_sds_phy_stop(&iphy->sci);
1373 scic_sds_phy_start(&iphy->sci);
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001374 spin_unlock_irqrestore(&ihost->scic_lock, flags);
1375 break;
1376
1377 case PHY_FUNC_HARD_RESET:
1378 if (!iport)
1379 return -ENODEV;
Dan Williams6f231dd2011-07-02 22:56:22 -07001380
1381 /* Perform the port reset. */
Dan Williams4393aa42011-03-31 13:10:44 -07001382 ret = isci_port_perform_hard_reset(ihost, iport, iphy);
Dan Williams6f231dd2011-07-02 22:56:22 -07001383
1384 break;
1385
Dan Williams6f231dd2011-07-02 22:56:22 -07001386 default:
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001387 dev_dbg(&ihost->pdev->dev,
1388 "%s: phy %p; func %d NOT IMPLEMENTED!\n",
1389 __func__, sas_phy, func);
1390 ret = -ENOSYS;
Dan Williams6f231dd2011-07-02 22:56:22 -07001391 break;
1392 }
1393 return ret;
1394}