blob: fd0e9734e5d0ffbd7c355eafd62f9729021fed30 [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
Dan Williams85280952011-06-28 15:05:53 -070065enum sas_linkrate sci_phy_linkrate(struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -070066{
Dan Williams85280952011-06-28 15:05:53 -070067 return iphy->max_negotiated_speed;
Dan Williamsd35bc1b2011-05-10 02:28:45 -070068}
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(
Dan Williams85280952011-06-28 15:05:53 -070083 struct isci_phy *iphy,
Dan Williamsd35bc1b2011-05-10 02:28:45 -070084 struct scu_transport_layer_registers __iomem *transport_layer_registers)
85{
86 u32 tl_control;
87
Dan Williams85280952011-06-28 15:05:53 -070088 iphy->transport_layer_registers = transport_layer_registers;
Dan Williamsd35bc1b2011-05-10 02:28:45 -070089
90 writel(SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX,
Dan Williams85280952011-06-28 15:05:53 -070091 &iphy->transport_layer_registers->stp_rni);
Dan Williamsd35bc1b2011-05-10 02:28:45 -070092
93 /*
94 * Hardware team recommends that we enable the STP prefetch for all
95 * transports
96 */
Dan Williams85280952011-06-28 15:05:53 -070097 tl_control = readl(&iphy->transport_layer_registers->control);
Dan Williamsd35bc1b2011-05-10 02:28:45 -070098 tl_control |= SCU_TLCR_GEN_BIT(STP_WRITE_DATA_PREFETCH);
Dan Williams85280952011-06-28 15:05:53 -070099 writel(tl_control, &iphy->transport_layer_registers->control);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700100
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
Dan Williams85280952011-06-28 15:05:53 -0700112scic_sds_phy_link_layer_initialization(struct isci_phy *iphy,
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700113 struct scu_link_layer_registers __iomem *link_layer_registers)
114{
115 struct scic_sds_controller *scic =
Dan Williams85280952011-06-28 15:05:53 -0700116 iphy->owning_port->owning_controller;
117 int phy_idx = iphy->phy_index;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700118 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
Dan Williams85280952011-06-28 15:05:53 -0700129 iphy->link_layer_registers = link_layer_registers;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700130
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),
Dan Williams85280952011-06-28 15:05:53 -0700139 &iphy->link_layer_registers->transmit_identification);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700140
141 /* Write the device SAS Address */
142 writel(0xFEDCBA98,
Dan Williams85280952011-06-28 15:05:53 -0700143 &iphy->link_layer_registers->sas_device_name_high);
144 writel(phy_idx, &iphy->link_layer_registers->sas_device_name_low);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700145
146 /* Write the source SAS Address */
147 writel(phy_oem->sas_address.high,
Dan Williams85280952011-06-28 15:05:53 -0700148 &iphy->link_layer_registers->source_sas_address_high);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700149 writel(phy_oem->sas_address.low,
Dan Williams85280952011-06-28 15:05:53 -0700150 &iphy->link_layer_registers->source_sas_address_low);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700151
152 /* Clear and Set the PHY Identifier */
Dan Williams85280952011-06-28 15:05:53 -0700153 writel(0, &iphy->link_layer_registers->identify_frame_phy_id);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700154 writel(SCU_SAS_TIPID_GEN_VALUE(ID, phy_idx),
Dan Williams85280952011-06-28 15:05:53 -0700155 &iphy->link_layer_registers->identify_frame_phy_id);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700156
157 /* Change the initial state of the phy configuration register */
158 phy_configuration =
Dan Williams85280952011-06-28 15:05:53 -0700159 readl(&iphy->link_layer_registers->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700160
161 /* Hold OOB state machine in reset */
162 phy_configuration |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
163 writel(phy_configuration,
Dan Williams85280952011-06-28 15:05:53 -0700164 &iphy->link_layer_registers->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700165
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
Dan Williams85280952011-06-28 15:05:53 -0700194 writel(phy_cap.all, &iphy->link_layer_registers->phy_capabilities);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700195
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),
Dan Williams85280952011-06-28 15:05:53 -0700201 &iphy->link_layer_registers->notify_enable_spinup_control);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700202
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
Dan Williams85280952011-06-28 15:05:53 -0700212 writel(clksm_value, &iphy->link_layer_registers->clock_skew_management);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700213
214 /* @todo Provide a way to write this register correctly */
215 writel(0x02108421,
Dan Williams85280952011-06-28 15:05:53 -0700216 &iphy->link_layer_registers->afe_lookup_table_control);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700217
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);
Dan Williams85280952011-06-28 15:05:53 -0700233 writel(llctl, &iphy->link_layer_registers->link_layer_control);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700234
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,
Dan Williams85280952011-06-28 15:05:53 -0700242 &iphy->link_layer_registers->maximum_arbitration_wait_timer_timeout);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700243 }
244
Jeff Skirvin9b917982011-06-20 14:09:31 -0700245 /* Disable link layer hang detection, rely on the OS timeout for I/O timeouts. */
Dan Williams85280952011-06-28 15:05:53 -0700246 writel(0, &iphy->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 */
Dan Williams85280952011-06-28 15:05:53 -0700249 sci_change_state(&iphy->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;
Dan Williams85280952011-06-28 15:05:53 -0700257 struct isci_phy *iphy = container_of(tmr, typeof(*iphy), sata_timer);
258 struct isci_host *ihost = scic_to_ihost(iphy->owning_port->owning_controller);
Edmund Nadolskia628d472011-05-19 11:59:36 +0000259 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
Dan Williams85280952011-06-28 15:05:53 -0700266 dev_dbg(sciphy_to_dev(iphy),
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700267 "%s: SCIC SDS Phy 0x%p did not receive signature fis before "
268 "timeout.\n",
269 __func__,
Dan Williams85280952011-06-28 15:05:53 -0700270 iphy);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700271
Dan Williams85280952011-06-28 15:05:53 -0700272 sci_change_state(&iphy->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 Williamsffe191c2011-06-29 13:09:25 -0700289struct isci_port *phy_get_non_dummy_port(
Dan Williams85280952011-06-28 15:05:53 -0700290 struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700291{
Dan Williams85280952011-06-28 15:05:53 -0700292 if (scic_sds_port_get_index(iphy->owning_port) == SCIC_SDS_DUMMY_PORT)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700293 return NULL;
294
Dan Williams85280952011-06-28 15:05:53 -0700295 return iphy->owning_port;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700296}
297
298/**
299 * This method will assign a port to the phy object.
Dan Williams85280952011-06-28 15:05:53 -0700300 * @out]: iphy This parameter specifies the phy for which to assign a port
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700301 * object.
302 *
303 *
304 */
305void scic_sds_phy_set_port(
Dan Williams85280952011-06-28 15:05:53 -0700306 struct isci_phy *iphy,
Dan Williamsffe191c2011-06-29 13:09:25 -0700307 struct isci_port *iport)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700308{
Dan Williamsffe191c2011-06-29 13:09:25 -0700309 iphy->owning_port = iport;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700310
Dan Williams85280952011-06-28 15:05:53 -0700311 if (iphy->bcn_received_while_port_unassigned) {
312 iphy->bcn_received_while_port_unassigned = false;
313 scic_sds_port_broadcast_change_received(iphy->owning_port, iphy);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700314 }
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(
Dan Williams85280952011-06-28 15:05:53 -0700325 struct isci_phy *iphy,
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700326 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(
Dan Williams85280952011-06-28 15:05:53 -0700331 iphy,
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700332 transport_layer_registers);
333
334 /* Perofrm the initialization of the PE hardware */
Dan Williams85280952011-06-28 15:05:53 -0700335 scic_sds_phy_link_layer_initialization(iphy, link_layer_registers);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700336
337 /*
338 * There is nothing that needs to be done in this state just
339 * transition to the stopped state. */
Dan Williams85280952011-06-28 15:05:53 -0700340 sci_change_state(&iphy->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 *
Dan Williams85280952011-06-28 15:05:53 -0700348 * @iphy The phy for which the direct attached device id is to
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700349 * 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(
Dan Williams85280952011-06-28 15:05:53 -0700355 struct isci_phy *iphy,
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700356 u32 device_id)
357{
358 u32 tl_control;
359
Dan Williams85280952011-06-28 15:05:53 -0700360 writel(device_id, &iphy->transport_layer_registers->stp_rni);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700361
362 /*
363 * The read should guarantee that the first write gets posted
364 * before the next write
365 */
Dan Williams85280952011-06-28 15:05:53 -0700366 tl_control = readl(&iphy->transport_layer_registers->control);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700367 tl_control |= SCU_TLCR_GEN_BIT(CLEAR_TCI_NCQ_MAPPING_TABLE);
Dan Williams85280952011-06-28 15:05:53 -0700368 writel(tl_control, &iphy->transport_layer_registers->control);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700369}
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(
Dan Williams85280952011-06-28 15:05:53 -0700379 struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700380{
381 u32 scu_sas_pcfg_value;
382
383 scu_sas_pcfg_value =
Dan Williams85280952011-06-28 15:05:53 -0700384 readl(&iphy->link_layer_registers->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700385 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE);
386 writel(scu_sas_pcfg_value,
Dan Williams85280952011-06-28 15:05:53 -0700387 &iphy->link_layer_registers->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700388
389 scic_sds_phy_setup_transport(
Dan Williams85280952011-06-28 15:05:53 -0700390 iphy,
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700391 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX);
392}
393
Dan Williams85280952011-06-28 15:05:53 -0700394void scic_sds_phy_resume(struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700395{
396 u32 scu_sas_pcfg_value;
397
398 scu_sas_pcfg_value =
Dan Williams85280952011-06-28 15:05:53 -0700399 readl(&iphy->link_layer_registers->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700400 scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE);
401 writel(scu_sas_pcfg_value,
Dan Williams85280952011-06-28 15:05:53 -0700402 &iphy->link_layer_registers->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700403}
404
Dan Williams85280952011-06-28 15:05:53 -0700405void scic_sds_phy_get_sas_address(struct isci_phy *iphy,
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700406 struct sci_sas_address *sas_address)
407{
Dan Williams85280952011-06-28 15:05:53 -0700408 sas_address->high = readl(&iphy->link_layer_registers->source_sas_address_high);
409 sas_address->low = readl(&iphy->link_layer_registers->source_sas_address_low);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700410}
411
Dan Williams85280952011-06-28 15:05:53 -0700412void scic_sds_phy_get_attached_sas_address(struct isci_phy *iphy,
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700413 struct sci_sas_address *sas_address)
414{
415 struct sas_identify_frame *iaf;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700416
417 iaf = &iphy->frame_rcvd.iaf;
418 memcpy(sas_address, iaf->sas_addr, SAS_ADDR_SIZE);
419}
420
Dan Williams85280952011-06-28 15:05:53 -0700421void scic_sds_phy_get_protocols(struct isci_phy *iphy,
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700422 struct scic_phy_proto *protocols)
423{
424 protocols->all =
Dan Williams85280952011-06-28 15:05:53 -0700425 (u16)(readl(&iphy->
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700426 link_layer_registers->transmit_identification) &
427 0x0000FFFF);
428}
429
Dan Williams85280952011-06-28 15:05:53 -0700430enum sci_status scic_sds_phy_start(struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700431{
Dan Williams85280952011-06-28 15:05:53 -0700432 enum scic_sds_phy_states state = iphy->sm.current_state_id;
Dan Williams966699b2011-05-12 03:44:24 -0700433
Edmund Nadolskie3013702011-06-02 00:10:43 +0000434 if (state != SCI_PHY_STOPPED) {
Dan Williams85280952011-06-28 15:05:53 -0700435 dev_dbg(sciphy_to_dev(iphy),
Dan Williams966699b2011-05-12 03:44:24 -0700436 "%s: in wrong state: %d\n", __func__, state);
437 return SCI_FAILURE_INVALID_STATE;
438 }
439
Dan Williams85280952011-06-28 15:05:53 -0700440 sci_change_state(&iphy->sm, SCI_PHY_STARTING);
Dan Williams966699b2011-05-12 03:44:24 -0700441 return SCI_SUCCESS;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700442}
443
Dan Williams85280952011-06-28 15:05:53 -0700444enum sci_status scic_sds_phy_stop(struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700445{
Dan Williams85280952011-06-28 15:05:53 -0700446 enum scic_sds_phy_states state = iphy->sm.current_state_id;
Dan Williams93153232011-05-12 04:01:03 -0700447
448 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +0000449 case SCI_PHY_SUB_INITIAL:
450 case SCI_PHY_SUB_AWAIT_OSSP_EN:
451 case SCI_PHY_SUB_AWAIT_SAS_SPEED_EN:
452 case SCI_PHY_SUB_AWAIT_SAS_POWER:
453 case SCI_PHY_SUB_AWAIT_SATA_POWER:
454 case SCI_PHY_SUB_AWAIT_SATA_PHY_EN:
455 case SCI_PHY_SUB_AWAIT_SATA_SPEED_EN:
456 case SCI_PHY_SUB_AWAIT_SIG_FIS_UF:
457 case SCI_PHY_SUB_FINAL:
458 case SCI_PHY_READY:
Dan Williams93153232011-05-12 04:01:03 -0700459 break;
460 default:
Dan Williams85280952011-06-28 15:05:53 -0700461 dev_dbg(sciphy_to_dev(iphy),
Dan Williams93153232011-05-12 04:01:03 -0700462 "%s: in wrong state: %d\n", __func__, state);
463 return SCI_FAILURE_INVALID_STATE;
464 }
465
Dan Williams85280952011-06-28 15:05:53 -0700466 sci_change_state(&iphy->sm, SCI_PHY_STOPPED);
Dan Williams93153232011-05-12 04:01:03 -0700467 return SCI_SUCCESS;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700468}
469
Dan Williams85280952011-06-28 15:05:53 -0700470enum sci_status scic_sds_phy_reset(struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700471{
Dan Williams85280952011-06-28 15:05:53 -0700472 enum scic_sds_phy_states state = iphy->sm.current_state_id;
Dan Williams0cf36fa2011-05-12 04:02:07 -0700473
Edmund Nadolskie3013702011-06-02 00:10:43 +0000474 if (state != SCI_PHY_READY) {
Dan Williams85280952011-06-28 15:05:53 -0700475 dev_dbg(sciphy_to_dev(iphy),
Dan Williams0cf36fa2011-05-12 04:02:07 -0700476 "%s: in wrong state: %d\n", __func__, state);
477 return SCI_FAILURE_INVALID_STATE;
478 }
479
Dan Williams85280952011-06-28 15:05:53 -0700480 sci_change_state(&iphy->sm, SCI_PHY_RESETTING);
Dan Williams0cf36fa2011-05-12 04:02:07 -0700481 return SCI_SUCCESS;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700482}
483
Dan Williams85280952011-06-28 15:05:53 -0700484enum sci_status scic_sds_phy_consume_power_handler(struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700485{
Dan Williams85280952011-06-28 15:05:53 -0700486 enum scic_sds_phy_states state = iphy->sm.current_state_id;
Dan Williams5b1d4af2011-05-12 04:51:41 -0700487
488 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +0000489 case SCI_PHY_SUB_AWAIT_SAS_POWER: {
Dan Williams5b1d4af2011-05-12 04:51:41 -0700490 u32 enable_spinup;
491
Dan Williams85280952011-06-28 15:05:53 -0700492 enable_spinup = readl(&iphy->link_layer_registers->notify_enable_spinup_control);
Dan Williams5b1d4af2011-05-12 04:51:41 -0700493 enable_spinup |= SCU_ENSPINUP_GEN_BIT(ENABLE);
Dan Williams85280952011-06-28 15:05:53 -0700494 writel(enable_spinup, &iphy->link_layer_registers->notify_enable_spinup_control);
Dan Williams5b1d4af2011-05-12 04:51:41 -0700495
496 /* Change state to the final state this substate machine has run to completion */
Dan Williams85280952011-06-28 15:05:53 -0700497 sci_change_state(&iphy->sm, SCI_PHY_SUB_FINAL);
Dan Williams5b1d4af2011-05-12 04:51:41 -0700498
499 return SCI_SUCCESS;
500 }
Edmund Nadolskie3013702011-06-02 00:10:43 +0000501 case SCI_PHY_SUB_AWAIT_SATA_POWER: {
Dan Williams5b1d4af2011-05-12 04:51:41 -0700502 u32 scu_sas_pcfg_value;
503
504 /* Release the spinup hold state and reset the OOB state machine */
505 scu_sas_pcfg_value =
Dan Williams85280952011-06-28 15:05:53 -0700506 readl(&iphy->link_layer_registers->phy_configuration);
Dan Williams5b1d4af2011-05-12 04:51:41 -0700507 scu_sas_pcfg_value &=
508 ~(SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD) | SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE));
509 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
510 writel(scu_sas_pcfg_value,
Dan Williams85280952011-06-28 15:05:53 -0700511 &iphy->link_layer_registers->phy_configuration);
Dan Williams5b1d4af2011-05-12 04:51:41 -0700512
513 /* Now restart the OOB operation */
514 scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
515 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
516 writel(scu_sas_pcfg_value,
Dan Williams85280952011-06-28 15:05:53 -0700517 &iphy->link_layer_registers->phy_configuration);
Dan Williams5b1d4af2011-05-12 04:51:41 -0700518
519 /* Change state to the final state this substate machine has run to completion */
Dan Williams85280952011-06-28 15:05:53 -0700520 sci_change_state(&iphy->sm, SCI_PHY_SUB_AWAIT_SATA_PHY_EN);
Dan Williams5b1d4af2011-05-12 04:51:41 -0700521
522 return SCI_SUCCESS;
523 }
524 default:
Dan Williams85280952011-06-28 15:05:53 -0700525 dev_dbg(sciphy_to_dev(iphy),
Dan Williams5b1d4af2011-05-12 04:51:41 -0700526 "%s: in wrong state: %d\n", __func__, state);
527 return SCI_FAILURE_INVALID_STATE;
528 }
Dan Williams23506a62011-05-12 04:27:29 -0700529}
530
531/*
532 * *****************************************************************************
533 * * SCIC SDS PHY HELPER FUNCTIONS
534 * ***************************************************************************** */
535
536
537/**
538 *
539 * @sci_phy: The phy object that received SAS PHY DETECTED.
540 *
541 * This method continues the link training for the phy as if it were a SAS PHY
542 * instead of a SATA PHY. This is done because the completion queue had a SAS
543 * PHY DETECTED event when the state machine was expecting a SATA PHY event.
544 * none
545 */
546static void scic_sds_phy_start_sas_link_training(
Dan Williams85280952011-06-28 15:05:53 -0700547 struct isci_phy *iphy)
Dan Williams23506a62011-05-12 04:27:29 -0700548{
549 u32 phy_control;
550
551 phy_control =
Dan Williams85280952011-06-28 15:05:53 -0700552 readl(&iphy->link_layer_registers->phy_configuration);
Dan Williams23506a62011-05-12 04:27:29 -0700553 phy_control |= SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD);
554 writel(phy_control,
Dan Williams85280952011-06-28 15:05:53 -0700555 &iphy->link_layer_registers->phy_configuration);
Dan Williams23506a62011-05-12 04:27:29 -0700556
Dan Williams85280952011-06-28 15:05:53 -0700557 sci_change_state(&iphy->sm, SCI_PHY_SUB_AWAIT_SAS_SPEED_EN);
Dan Williams23506a62011-05-12 04:27:29 -0700558
Dan Williams85280952011-06-28 15:05:53 -0700559 iphy->protocol = SCIC_SDS_PHY_PROTOCOL_SAS;
Dan Williams23506a62011-05-12 04:27:29 -0700560}
561
562/**
563 *
564 * @sci_phy: The phy object that received a SATA SPINUP HOLD event
565 *
566 * This method continues the link training for the phy as if it were a SATA PHY
567 * instead of a SAS PHY. This is done because the completion queue had a SATA
568 * SPINUP HOLD event when the state machine was expecting a SAS PHY event. none
569 */
570static void scic_sds_phy_start_sata_link_training(
Dan Williams85280952011-06-28 15:05:53 -0700571 struct isci_phy *iphy)
Dan Williams23506a62011-05-12 04:27:29 -0700572{
Dan Williams85280952011-06-28 15:05:53 -0700573 sci_change_state(&iphy->sm, SCI_PHY_SUB_AWAIT_SATA_POWER);
Dan Williams23506a62011-05-12 04:27:29 -0700574
Dan Williams85280952011-06-28 15:05:53 -0700575 iphy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
Dan Williams23506a62011-05-12 04:27:29 -0700576}
577
578/**
579 * scic_sds_phy_complete_link_training - perform processing common to
580 * all protocols upon completion of link training.
581 * @sci_phy: This parameter specifies the phy object for which link training
582 * has completed.
583 * @max_link_rate: This parameter specifies the maximum link rate to be
584 * associated with this phy.
585 * @next_state: This parameter specifies the next state for the phy's starting
586 * sub-state machine.
587 *
588 */
589static void scic_sds_phy_complete_link_training(
Dan Williams85280952011-06-28 15:05:53 -0700590 struct isci_phy *iphy,
Dan Williams23506a62011-05-12 04:27:29 -0700591 enum sas_linkrate max_link_rate,
592 u32 next_state)
593{
Dan Williams85280952011-06-28 15:05:53 -0700594 iphy->max_negotiated_speed = max_link_rate;
Dan Williams23506a62011-05-12 04:27:29 -0700595
Dan Williams85280952011-06-28 15:05:53 -0700596 sci_change_state(&iphy->sm, next_state);
Dan Williams23506a62011-05-12 04:27:29 -0700597}
598
Dan Williams85280952011-06-28 15:05:53 -0700599enum sci_status scic_sds_phy_event_handler(struct isci_phy *iphy,
Dan Williams23506a62011-05-12 04:27:29 -0700600 u32 event_code)
601{
Dan Williams85280952011-06-28 15:05:53 -0700602 enum scic_sds_phy_states state = iphy->sm.current_state_id;
Dan Williams23506a62011-05-12 04:27:29 -0700603
604 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +0000605 case SCI_PHY_SUB_AWAIT_OSSP_EN:
Dan Williams23506a62011-05-12 04:27:29 -0700606 switch (scu_get_event_code(event_code)) {
607 case SCU_EVENT_SAS_PHY_DETECTED:
Dan Williams85280952011-06-28 15:05:53 -0700608 scic_sds_phy_start_sas_link_training(iphy);
609 iphy->is_in_link_training = true;
Dan Williams23506a62011-05-12 04:27:29 -0700610 break;
611 case SCU_EVENT_SATA_SPINUP_HOLD:
Dan Williams85280952011-06-28 15:05:53 -0700612 scic_sds_phy_start_sata_link_training(iphy);
613 iphy->is_in_link_training = true;
Dan Williams23506a62011-05-12 04:27:29 -0700614 break;
615 default:
Dan Williams85280952011-06-28 15:05:53 -0700616 dev_dbg(sciphy_to_dev(iphy),
Dan Williams23506a62011-05-12 04:27:29 -0700617 "%s: PHY starting substate machine received "
618 "unexpected event_code %x\n",
619 __func__,
620 event_code);
621 return SCI_FAILURE;
622 }
623 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000624 case SCI_PHY_SUB_AWAIT_SAS_SPEED_EN:
Dan Williams23506a62011-05-12 04:27:29 -0700625 switch (scu_get_event_code(event_code)) {
626 case SCU_EVENT_SAS_PHY_DETECTED:
627 /*
628 * Why is this being reported again by the controller?
629 * We would re-enter this state so just stay here */
630 break;
631 case SCU_EVENT_SAS_15:
632 case SCU_EVENT_SAS_15_SSC:
633 scic_sds_phy_complete_link_training(
Dan Williams85280952011-06-28 15:05:53 -0700634 iphy,
Dan Williams23506a62011-05-12 04:27:29 -0700635 SAS_LINK_RATE_1_5_GBPS,
Edmund Nadolskie3013702011-06-02 00:10:43 +0000636 SCI_PHY_SUB_AWAIT_IAF_UF);
Dan Williams23506a62011-05-12 04:27:29 -0700637 break;
638 case SCU_EVENT_SAS_30:
639 case SCU_EVENT_SAS_30_SSC:
640 scic_sds_phy_complete_link_training(
Dan Williams85280952011-06-28 15:05:53 -0700641 iphy,
Dan Williams23506a62011-05-12 04:27:29 -0700642 SAS_LINK_RATE_3_0_GBPS,
Edmund Nadolskie3013702011-06-02 00:10:43 +0000643 SCI_PHY_SUB_AWAIT_IAF_UF);
Dan Williams23506a62011-05-12 04:27:29 -0700644 break;
645 case SCU_EVENT_SAS_60:
646 case SCU_EVENT_SAS_60_SSC:
647 scic_sds_phy_complete_link_training(
Dan Williams85280952011-06-28 15:05:53 -0700648 iphy,
Dan Williams23506a62011-05-12 04:27:29 -0700649 SAS_LINK_RATE_6_0_GBPS,
Edmund Nadolskie3013702011-06-02 00:10:43 +0000650 SCI_PHY_SUB_AWAIT_IAF_UF);
Dan Williams23506a62011-05-12 04:27:29 -0700651 break;
652 case SCU_EVENT_SATA_SPINUP_HOLD:
653 /*
654 * We were doing SAS PHY link training and received a SATA PHY event
655 * continue OOB/SN as if this were a SATA PHY */
Dan Williams85280952011-06-28 15:05:53 -0700656 scic_sds_phy_start_sata_link_training(iphy);
Dan Williams23506a62011-05-12 04:27:29 -0700657 break;
658 case SCU_EVENT_LINK_FAILURE:
659 /* Link failure change state back to the starting state */
Dan Williams85280952011-06-28 15:05:53 -0700660 sci_change_state(&iphy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700661 break;
662 default:
Dan Williams85280952011-06-28 15:05:53 -0700663 dev_warn(sciphy_to_dev(iphy),
Dan Williams23506a62011-05-12 04:27:29 -0700664 "%s: PHY starting substate machine received "
665 "unexpected event_code %x\n",
666 __func__, event_code);
667
668 return SCI_FAILURE;
669 break;
670 }
671 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000672 case SCI_PHY_SUB_AWAIT_IAF_UF:
Dan Williams23506a62011-05-12 04:27:29 -0700673 switch (scu_get_event_code(event_code)) {
674 case SCU_EVENT_SAS_PHY_DETECTED:
675 /* Backup the state machine */
Dan Williams85280952011-06-28 15:05:53 -0700676 scic_sds_phy_start_sas_link_training(iphy);
Dan Williams23506a62011-05-12 04:27:29 -0700677 break;
678 case SCU_EVENT_SATA_SPINUP_HOLD:
679 /* We were doing SAS PHY link training and received a
680 * SATA PHY event continue OOB/SN as if this were a
681 * SATA PHY
682 */
Dan Williams85280952011-06-28 15:05:53 -0700683 scic_sds_phy_start_sata_link_training(iphy);
Dan Williams23506a62011-05-12 04:27:29 -0700684 break;
685 case SCU_EVENT_RECEIVED_IDENTIFY_TIMEOUT:
686 case SCU_EVENT_LINK_FAILURE:
687 case SCU_EVENT_HARD_RESET_RECEIVED:
688 /* Start the oob/sn state machine over again */
Dan Williams85280952011-06-28 15:05:53 -0700689 sci_change_state(&iphy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700690 break;
691 default:
Dan Williams85280952011-06-28 15:05:53 -0700692 dev_warn(sciphy_to_dev(iphy),
Dan Williams23506a62011-05-12 04:27:29 -0700693 "%s: PHY starting substate machine received "
694 "unexpected event_code %x\n",
695 __func__, event_code);
696 return SCI_FAILURE;
697 }
698 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000699 case SCI_PHY_SUB_AWAIT_SAS_POWER:
Dan Williams23506a62011-05-12 04:27:29 -0700700 switch (scu_get_event_code(event_code)) {
701 case SCU_EVENT_LINK_FAILURE:
702 /* Link failure change state back to the starting state */
Dan Williams85280952011-06-28 15:05:53 -0700703 sci_change_state(&iphy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700704 break;
705 default:
Dan Williams85280952011-06-28 15:05:53 -0700706 dev_warn(sciphy_to_dev(iphy),
Dan Williams23506a62011-05-12 04:27:29 -0700707 "%s: PHY starting substate machine received unexpected "
708 "event_code %x\n",
709 __func__,
710 event_code);
711 return SCI_FAILURE;
712 }
713 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000714 case SCI_PHY_SUB_AWAIT_SATA_POWER:
Dan Williams23506a62011-05-12 04:27:29 -0700715 switch (scu_get_event_code(event_code)) {
716 case SCU_EVENT_LINK_FAILURE:
717 /* Link failure change state back to the starting state */
Dan Williams85280952011-06-28 15:05:53 -0700718 sci_change_state(&iphy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700719 break;
720 case SCU_EVENT_SATA_SPINUP_HOLD:
721 /* These events are received every 10ms and are
722 * expected while in this state
723 */
724 break;
725
726 case SCU_EVENT_SAS_PHY_DETECTED:
727 /* There has been a change in the phy type before OOB/SN for the
728 * SATA finished start down the SAS link traning path.
729 */
Dan Williams85280952011-06-28 15:05:53 -0700730 scic_sds_phy_start_sas_link_training(iphy);
Dan Williams23506a62011-05-12 04:27:29 -0700731 break;
732
733 default:
Dan Williams85280952011-06-28 15:05:53 -0700734 dev_warn(sciphy_to_dev(iphy),
Dan Williams23506a62011-05-12 04:27:29 -0700735 "%s: PHY starting substate machine received "
736 "unexpected event_code %x\n",
737 __func__, event_code);
738
739 return SCI_FAILURE;
740 }
741 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000742 case SCI_PHY_SUB_AWAIT_SATA_PHY_EN:
Dan Williams23506a62011-05-12 04:27:29 -0700743 switch (scu_get_event_code(event_code)) {
744 case SCU_EVENT_LINK_FAILURE:
745 /* Link failure change state back to the starting state */
Dan Williams85280952011-06-28 15:05:53 -0700746 sci_change_state(&iphy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700747 break;
748 case SCU_EVENT_SATA_SPINUP_HOLD:
749 /* These events might be received since we dont know how many may be in
750 * the completion queue while waiting for power
751 */
752 break;
753 case SCU_EVENT_SATA_PHY_DETECTED:
Dan Williams85280952011-06-28 15:05:53 -0700754 iphy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
Dan Williams23506a62011-05-12 04:27:29 -0700755
756 /* We have received the SATA PHY notification change state */
Dan Williams85280952011-06-28 15:05:53 -0700757 sci_change_state(&iphy->sm, SCI_PHY_SUB_AWAIT_SATA_SPEED_EN);
Dan Williams23506a62011-05-12 04:27:29 -0700758 break;
759 case SCU_EVENT_SAS_PHY_DETECTED:
760 /* There has been a change in the phy type before OOB/SN for the
761 * SATA finished start down the SAS link traning path.
762 */
Dan Williams85280952011-06-28 15:05:53 -0700763 scic_sds_phy_start_sas_link_training(iphy);
Dan Williams23506a62011-05-12 04:27:29 -0700764 break;
765 default:
Dan Williams85280952011-06-28 15:05:53 -0700766 dev_warn(sciphy_to_dev(iphy),
Dan Williams23506a62011-05-12 04:27:29 -0700767 "%s: PHY starting substate machine received "
768 "unexpected event_code %x\n",
769 __func__,
770 event_code);
771
772 return SCI_FAILURE;;
773 }
774 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000775 case SCI_PHY_SUB_AWAIT_SATA_SPEED_EN:
Dan Williams23506a62011-05-12 04:27:29 -0700776 switch (scu_get_event_code(event_code)) {
777 case SCU_EVENT_SATA_PHY_DETECTED:
778 /*
779 * The hardware reports multiple SATA PHY detected events
780 * ignore the extras */
781 break;
782 case SCU_EVENT_SATA_15:
783 case SCU_EVENT_SATA_15_SSC:
784 scic_sds_phy_complete_link_training(
Dan Williams85280952011-06-28 15:05:53 -0700785 iphy,
Dan Williams23506a62011-05-12 04:27:29 -0700786 SAS_LINK_RATE_1_5_GBPS,
Edmund Nadolskie3013702011-06-02 00:10:43 +0000787 SCI_PHY_SUB_AWAIT_SIG_FIS_UF);
Dan Williams23506a62011-05-12 04:27:29 -0700788 break;
789 case SCU_EVENT_SATA_30:
790 case SCU_EVENT_SATA_30_SSC:
791 scic_sds_phy_complete_link_training(
Dan Williams85280952011-06-28 15:05:53 -0700792 iphy,
Dan Williams23506a62011-05-12 04:27:29 -0700793 SAS_LINK_RATE_3_0_GBPS,
Edmund Nadolskie3013702011-06-02 00:10:43 +0000794 SCI_PHY_SUB_AWAIT_SIG_FIS_UF);
Dan Williams23506a62011-05-12 04:27:29 -0700795 break;
796 case SCU_EVENT_SATA_60:
797 case SCU_EVENT_SATA_60_SSC:
798 scic_sds_phy_complete_link_training(
Dan Williams85280952011-06-28 15:05:53 -0700799 iphy,
Dan Williams23506a62011-05-12 04:27:29 -0700800 SAS_LINK_RATE_6_0_GBPS,
Edmund Nadolskie3013702011-06-02 00:10:43 +0000801 SCI_PHY_SUB_AWAIT_SIG_FIS_UF);
Dan Williams23506a62011-05-12 04:27:29 -0700802 break;
803 case SCU_EVENT_LINK_FAILURE:
804 /* Link failure change state back to the starting state */
Dan Williams85280952011-06-28 15:05:53 -0700805 sci_change_state(&iphy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700806 break;
807 case SCU_EVENT_SAS_PHY_DETECTED:
808 /*
809 * There has been a change in the phy type before OOB/SN for the
810 * SATA finished start down the SAS link traning path. */
Dan Williams85280952011-06-28 15:05:53 -0700811 scic_sds_phy_start_sas_link_training(iphy);
Dan Williams23506a62011-05-12 04:27:29 -0700812 break;
813 default:
Dan Williams85280952011-06-28 15:05:53 -0700814 dev_warn(sciphy_to_dev(iphy),
Dan Williams23506a62011-05-12 04:27:29 -0700815 "%s: PHY starting substate machine received "
816 "unexpected event_code %x\n",
817 __func__, event_code);
818
819 return SCI_FAILURE;
820 }
821
822 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000823 case SCI_PHY_SUB_AWAIT_SIG_FIS_UF:
Dan Williams23506a62011-05-12 04:27:29 -0700824 switch (scu_get_event_code(event_code)) {
825 case SCU_EVENT_SATA_PHY_DETECTED:
826 /* Backup the state machine */
Dan Williams85280952011-06-28 15:05:53 -0700827 sci_change_state(&iphy->sm, SCI_PHY_SUB_AWAIT_SATA_SPEED_EN);
Dan Williams23506a62011-05-12 04:27:29 -0700828 break;
829
830 case SCU_EVENT_LINK_FAILURE:
831 /* Link failure change state back to the starting state */
Dan Williams85280952011-06-28 15:05:53 -0700832 sci_change_state(&iphy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700833 break;
834
835 default:
Dan Williams85280952011-06-28 15:05:53 -0700836 dev_warn(sciphy_to_dev(iphy),
Dan Williams23506a62011-05-12 04:27:29 -0700837 "%s: PHY starting substate machine received "
838 "unexpected event_code %x\n",
839 __func__,
840 event_code);
841
842 return SCI_FAILURE;
843 }
844 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000845 case SCI_PHY_READY:
Dan Williams23506a62011-05-12 04:27:29 -0700846 switch (scu_get_event_code(event_code)) {
847 case SCU_EVENT_LINK_FAILURE:
848 /* Link failure change state back to the starting state */
Dan Williams85280952011-06-28 15:05:53 -0700849 sci_change_state(&iphy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700850 break;
851 case SCU_EVENT_BROADCAST_CHANGE:
852 /* Broadcast change received. Notify the port. */
Dan Williams85280952011-06-28 15:05:53 -0700853 if (phy_get_non_dummy_port(iphy) != NULL)
854 scic_sds_port_broadcast_change_received(iphy->owning_port, iphy);
Dan Williams23506a62011-05-12 04:27:29 -0700855 else
Dan Williams85280952011-06-28 15:05:53 -0700856 iphy->bcn_received_while_port_unassigned = true;
Dan Williams23506a62011-05-12 04:27:29 -0700857 break;
858 default:
Dan Williams85280952011-06-28 15:05:53 -0700859 dev_warn(sciphy_to_dev(iphy),
Dan Williams23506a62011-05-12 04:27:29 -0700860 "%sP SCIC PHY 0x%p ready state machine received "
861 "unexpected event_code %x\n",
Dan Williams85280952011-06-28 15:05:53 -0700862 __func__, iphy, event_code);
Dan Williams23506a62011-05-12 04:27:29 -0700863 return SCI_FAILURE_INVALID_STATE;
864 }
865 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000866 case SCI_PHY_RESETTING:
Dan Williams23506a62011-05-12 04:27:29 -0700867 switch (scu_get_event_code(event_code)) {
868 case SCU_EVENT_HARD_RESET_TRANSMITTED:
869 /* Link failure change state back to the starting state */
Dan Williams85280952011-06-28 15:05:53 -0700870 sci_change_state(&iphy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700871 break;
872 default:
Dan Williams85280952011-06-28 15:05:53 -0700873 dev_warn(sciphy_to_dev(iphy),
Dan Williams23506a62011-05-12 04:27:29 -0700874 "%s: SCIC PHY 0x%p resetting state machine received "
875 "unexpected event_code %x\n",
Dan Williams85280952011-06-28 15:05:53 -0700876 __func__, iphy, event_code);
Dan Williams23506a62011-05-12 04:27:29 -0700877
878 return SCI_FAILURE_INVALID_STATE;
879 break;
880 }
881 return SCI_SUCCESS;
882 default:
Dan Williams85280952011-06-28 15:05:53 -0700883 dev_dbg(sciphy_to_dev(iphy),
Dan Williams23506a62011-05-12 04:27:29 -0700884 "%s: in wrong state: %d\n", __func__, state);
885 return SCI_FAILURE_INVALID_STATE;
886 }
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700887}
888
Dan Williams85280952011-06-28 15:05:53 -0700889enum sci_status scic_sds_phy_frame_handler(struct isci_phy *iphy,
Dan Williamsc4441ab2011-05-12 04:17:51 -0700890 u32 frame_index)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700891{
Dan Williams85280952011-06-28 15:05:53 -0700892 enum scic_sds_phy_states state = iphy->sm.current_state_id;
893 struct scic_sds_controller *scic = iphy->owning_port->owning_controller;
Dan Williamsc4441ab2011-05-12 04:17:51 -0700894 enum sci_status result;
Dan Williams4cffe132011-06-23 23:44:52 -0700895 unsigned long flags;
Dan Williamsc4441ab2011-05-12 04:17:51 -0700896
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;
Dan Williamsc4441ab2011-05-12 04:17:51 -0700901
902 result = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
903 frame_index,
904 (void **)&frame_words);
905
906 if (result != SCI_SUCCESS)
907 return result;
908
909 sci_swab32_cpy(&iaf, frame_words, sizeof(iaf) / sizeof(u32));
910 if (iaf.frame_type == 0) {
911 u32 state;
912
Dan Williams4cffe132011-06-23 23:44:52 -0700913 spin_lock_irqsave(&iphy->sas_phy.frame_rcvd_lock, flags);
Dan Williamsc4441ab2011-05-12 04:17:51 -0700914 memcpy(&iphy->frame_rcvd.iaf, &iaf, sizeof(iaf));
Dan Williams4cffe132011-06-23 23:44:52 -0700915 spin_unlock_irqrestore(&iphy->sas_phy.frame_rcvd_lock, flags);
Dan Williamsc4441ab2011-05-12 04:17:51 -0700916 if (iaf.smp_tport) {
917 /* We got the IAF for an expander PHY go to the final
918 * state since there are no power requirements for
919 * expander phys.
920 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000921 state = SCI_PHY_SUB_FINAL;
Dan Williamsc4441ab2011-05-12 04:17:51 -0700922 } else {
923 /* We got the IAF we can now go to the await spinup
924 * semaphore state
925 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000926 state = SCI_PHY_SUB_AWAIT_SAS_POWER;
Dan Williamsc4441ab2011-05-12 04:17:51 -0700927 }
Dan Williams85280952011-06-28 15:05:53 -0700928 sci_change_state(&iphy->sm, state);
Dan Williamsc4441ab2011-05-12 04:17:51 -0700929 result = SCI_SUCCESS;
930 } else
Dan Williams85280952011-06-28 15:05:53 -0700931 dev_warn(sciphy_to_dev(iphy),
Dan Williamsc4441ab2011-05-12 04:17:51 -0700932 "%s: PHY starting substate machine received "
933 "unexpected frame id %x\n",
934 __func__, frame_index);
935
936 scic_sds_controller_release_frame(scic, frame_index);
937 return result;
938 }
Edmund Nadolskie3013702011-06-02 00:10:43 +0000939 case SCI_PHY_SUB_AWAIT_SIG_FIS_UF: {
Dan Williamsc4441ab2011-05-12 04:17:51 -0700940 struct dev_to_host_fis *frame_header;
941 u32 *fis_frame_data;
Dan Williamsc4441ab2011-05-12 04:17:51 -0700942
943 result = scic_sds_unsolicited_frame_control_get_header(
Dan Williams85280952011-06-28 15:05:53 -0700944 &(scic_sds_phy_get_controller(iphy)->uf_control),
Dan Williamsc4441ab2011-05-12 04:17:51 -0700945 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
Dan Williams4cffe132011-06-23 23:44:52 -0700957 spin_lock_irqsave(&iphy->sas_phy.frame_rcvd_lock, flags);
Dan Williamsc4441ab2011-05-12 04:17:51 -0700958 scic_sds_controller_copy_sata_response(&iphy->frame_rcvd.fis,
959 frame_header,
960 fis_frame_data);
Dan Williams4cffe132011-06-23 23:44:52 -0700961 spin_unlock_irqrestore(&iphy->sas_phy.frame_rcvd_lock, flags);
Dan Williamsc4441ab2011-05-12 04:17:51 -0700962
963 /* got IAF we can now go to the await spinup semaphore state */
Dan Williams85280952011-06-28 15:05:53 -0700964 sci_change_state(&iphy->sm, SCI_PHY_SUB_FINAL);
Dan Williamsc4441ab2011-05-12 04:17:51 -0700965
966 result = SCI_SUCCESS;
967 } else
Dan Williams85280952011-06-28 15:05:53 -0700968 dev_warn(sciphy_to_dev(iphy),
Dan Williamsc4441ab2011-05-12 04:17:51 -0700969 "%s: PHY starting substate machine received "
970 "unexpected frame id %x\n",
971 __func__, frame_index);
972
973 /* Regardless of the result we are done with this frame with it */
974 scic_sds_controller_release_frame(scic, frame_index);
975
976 return result;
977 }
978 default:
Dan Williams85280952011-06-28 15:05:53 -0700979 dev_dbg(sciphy_to_dev(iphy),
Dan Williamsc4441ab2011-05-12 04:17:51 -0700980 "%s: in wrong state: %d\n", __func__, state);
981 return SCI_FAILURE_INVALID_STATE;
982 }
Dan Williams5076a1a2011-06-27 14:57:03 -0700983
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700984}
985
Dan Williams9269e0e2011-05-12 07:42:17 -0700986static void scic_sds_phy_starting_initial_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +0000987{
Dan Williams85280952011-06-28 15:05:53 -0700988 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +0000989
Adam Gruchala4a33c522011-05-10 23:54:23 +0000990 /* This is just an temporary state go off to the starting state */
Dan Williams85280952011-06-28 15:05:53 -0700991 sci_change_state(&iphy->sm, SCI_PHY_SUB_AWAIT_OSSP_EN);
Adam Gruchala4a33c522011-05-10 23:54:23 +0000992}
993
Dan Williams9269e0e2011-05-12 07:42:17 -0700994static void scic_sds_phy_starting_await_sas_power_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +0000995{
Dan Williams85280952011-06-28 15:05:53 -0700996 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
997 struct scic_sds_controller *scic = iphy->owning_port->owning_controller;
Adam Gruchala4a33c522011-05-10 23:54:23 +0000998
Dan Williams85280952011-06-28 15:05:53 -0700999 scic_sds_controller_power_control_queue_insert(scic, iphy);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001000}
1001
Dan Williams9269e0e2011-05-12 07:42:17 -07001002static void scic_sds_phy_starting_await_sas_power_substate_exit(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001003{
Dan Williams85280952011-06-28 15:05:53 -07001004 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
1005 struct scic_sds_controller *scic = iphy->owning_port->owning_controller;
Adam Gruchala4a33c522011-05-10 23:54:23 +00001006
Dan Williams85280952011-06-28 15:05:53 -07001007 scic_sds_controller_power_control_queue_remove(scic, iphy);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001008}
1009
Dan Williams9269e0e2011-05-12 07:42:17 -07001010static void scic_sds_phy_starting_await_sata_power_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001011{
Dan Williams85280952011-06-28 15:05:53 -07001012 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
1013 struct scic_sds_controller *scic = iphy->owning_port->owning_controller;
Adam Gruchala4a33c522011-05-10 23:54:23 +00001014
Dan Williams85280952011-06-28 15:05:53 -07001015 scic_sds_controller_power_control_queue_insert(scic, iphy);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001016}
1017
Dan Williams9269e0e2011-05-12 07:42:17 -07001018static void scic_sds_phy_starting_await_sata_power_substate_exit(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001019{
Dan Williams85280952011-06-28 15:05:53 -07001020 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
1021 struct scic_sds_controller *scic = iphy->owning_port->owning_controller;
Adam Gruchala4a33c522011-05-10 23:54:23 +00001022
Dan Williams85280952011-06-28 15:05:53 -07001023 scic_sds_controller_power_control_queue_remove(scic, iphy);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001024}
1025
Dan Williams9269e0e2011-05-12 07:42:17 -07001026static void scic_sds_phy_starting_await_sata_phy_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001027{
Dan Williams85280952011-06-28 15:05:53 -07001028 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001029
Dan Williams85280952011-06-28 15:05:53 -07001030 sci_mod_timer(&iphy->sata_timer, SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001031}
1032
Dan Williams9269e0e2011-05-12 07:42:17 -07001033static void scic_sds_phy_starting_await_sata_phy_substate_exit(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001034{
Dan Williams85280952011-06-28 15:05:53 -07001035 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001036
Dan Williams85280952011-06-28 15:05:53 -07001037 sci_del_timer(&iphy->sata_timer);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001038}
1039
Dan Williams9269e0e2011-05-12 07:42:17 -07001040static void scic_sds_phy_starting_await_sata_speed_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001041{
Dan Williams85280952011-06-28 15:05:53 -07001042 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001043
Dan Williams85280952011-06-28 15:05:53 -07001044 sci_mod_timer(&iphy->sata_timer, SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001045}
1046
Dan Williams9269e0e2011-05-12 07:42:17 -07001047static void scic_sds_phy_starting_await_sata_speed_substate_exit(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001048{
Dan Williams85280952011-06-28 15:05:53 -07001049 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001050
Dan Williams85280952011-06-28 15:05:53 -07001051 sci_del_timer(&iphy->sata_timer);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001052}
1053
Dan Williams9269e0e2011-05-12 07:42:17 -07001054static void scic_sds_phy_starting_await_sig_fis_uf_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001055{
Dan Williams85280952011-06-28 15:05:53 -07001056 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001057
Dan Williams85280952011-06-28 15:05:53 -07001058 if (scic_sds_port_link_detected(iphy->owning_port, iphy)) {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001059
Adam Gruchala4a33c522011-05-10 23:54:23 +00001060 /*
1061 * Clear the PE suspend condition so we can actually
1062 * receive SIG FIS
1063 * The hardware will not respond to the XRDY until the PE
1064 * suspend condition is cleared.
1065 */
Dan Williams85280952011-06-28 15:05:53 -07001066 scic_sds_phy_resume(iphy);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001067
Dan Williams85280952011-06-28 15:05:53 -07001068 sci_mod_timer(&iphy->sata_timer,
Edmund Nadolskia628d472011-05-19 11:59:36 +00001069 SCIC_SDS_SIGNATURE_FIS_TIMEOUT);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001070 } else
Dan Williams85280952011-06-28 15:05:53 -07001071 iphy->is_in_link_training = false;
Adam Gruchala4a33c522011-05-10 23:54:23 +00001072}
1073
Dan Williams9269e0e2011-05-12 07:42:17 -07001074static void scic_sds_phy_starting_await_sig_fis_uf_substate_exit(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001075{
Dan Williams85280952011-06-28 15:05:53 -07001076 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001077
Dan Williams85280952011-06-28 15:05:53 -07001078 sci_del_timer(&iphy->sata_timer);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001079}
1080
Dan Williams9269e0e2011-05-12 07:42:17 -07001081static void scic_sds_phy_starting_final_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001082{
Dan Williams85280952011-06-28 15:05:53 -07001083 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001084
Adam Gruchala4a33c522011-05-10 23:54:23 +00001085 /* State machine has run to completion so exit out and change
1086 * the base state machine to the ready state
1087 */
Dan Williams85280952011-06-28 15:05:53 -07001088 sci_change_state(&iphy->sm, SCI_PHY_READY);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001089}
1090
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001091/**
1092 *
Dan Williams85280952011-06-28 15:05:53 -07001093 * @sci_phy: This is the struct isci_phy object to stop.
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001094 *
Dan Williams85280952011-06-28 15:05:53 -07001095 * This method will stop the struct isci_phy object. This does not reset the
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001096 * protocol engine it just suspends it and places it in a state where it will
1097 * not cause the end device to power up. none
1098 */
1099static void scu_link_layer_stop_protocol_engine(
Dan Williams85280952011-06-28 15:05:53 -07001100 struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001101{
1102 u32 scu_sas_pcfg_value;
1103 u32 enable_spinup_value;
1104
1105 /* Suspend the protocol engine and place it in a sata spinup hold state */
1106 scu_sas_pcfg_value =
Dan Williams85280952011-06-28 15:05:53 -07001107 readl(&iphy->link_layer_registers->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001108 scu_sas_pcfg_value |=
1109 (SCU_SAS_PCFG_GEN_BIT(OOB_RESET) |
1110 SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE) |
1111 SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD));
1112 writel(scu_sas_pcfg_value,
Dan Williams85280952011-06-28 15:05:53 -07001113 &iphy->link_layer_registers->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001114
1115 /* Disable the notify enable spinup primitives */
Dan Williams85280952011-06-28 15:05:53 -07001116 enable_spinup_value = readl(&iphy->link_layer_registers->notify_enable_spinup_control);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001117 enable_spinup_value &= ~SCU_ENSPINUP_GEN_BIT(ENABLE);
Dan Williams85280952011-06-28 15:05:53 -07001118 writel(enable_spinup_value, &iphy->link_layer_registers->notify_enable_spinup_control);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001119}
1120
1121/**
1122 *
1123 *
Dan Williams85280952011-06-28 15:05:53 -07001124 * This method will start the OOB/SN state machine for this struct isci_phy object.
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001125 */
1126static void scu_link_layer_start_oob(
Dan Williams85280952011-06-28 15:05:53 -07001127 struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001128{
1129 u32 scu_sas_pcfg_value;
1130
1131 scu_sas_pcfg_value =
Dan Williams85280952011-06-28 15:05:53 -07001132 readl(&iphy->link_layer_registers->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001133 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
1134 scu_sas_pcfg_value &=
1135 ~(SCU_SAS_PCFG_GEN_BIT(OOB_RESET) |
1136 SCU_SAS_PCFG_GEN_BIT(HARD_RESET));
1137 writel(scu_sas_pcfg_value,
Dan Williams85280952011-06-28 15:05:53 -07001138 &iphy->link_layer_registers->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001139}
1140
1141/**
1142 *
1143 *
1144 * This method will transmit a hard reset request on the specified phy. The SCU
1145 * hardware requires that we reset the OOB state machine and set the hard reset
1146 * bit in the phy configuration register. We then must start OOB over with the
1147 * hard reset bit set.
1148 */
1149static void scu_link_layer_tx_hard_reset(
Dan Williams85280952011-06-28 15:05:53 -07001150 struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001151{
1152 u32 phy_configuration_value;
1153
1154 /*
1155 * SAS Phys must wait for the HARD_RESET_TX event notification to transition
1156 * to the starting state. */
1157 phy_configuration_value =
Dan Williams85280952011-06-28 15:05:53 -07001158 readl(&iphy->link_layer_registers->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001159 phy_configuration_value |=
1160 (SCU_SAS_PCFG_GEN_BIT(HARD_RESET) |
1161 SCU_SAS_PCFG_GEN_BIT(OOB_RESET));
1162 writel(phy_configuration_value,
Dan Williams85280952011-06-28 15:05:53 -07001163 &iphy->link_layer_registers->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001164
1165 /* Now take the OOB state machine out of reset */
1166 phy_configuration_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
1167 phy_configuration_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
1168 writel(phy_configuration_value,
Dan Williams85280952011-06-28 15:05:53 -07001169 &iphy->link_layer_registers->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001170}
1171
Dan Williams9269e0e2011-05-12 07:42:17 -07001172static void scic_sds_phy_stopped_state_enter(struct sci_base_state_machine *sm)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001173{
Dan Williams85280952011-06-28 15:05:53 -07001174 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001175
1176 /*
1177 * @todo We need to get to the controller to place this PE in a
1178 * reset state
1179 */
Dan Williams85280952011-06-28 15:05:53 -07001180 sci_del_timer(&iphy->sata_timer);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001181
Dan Williams85280952011-06-28 15:05:53 -07001182 scu_link_layer_stop_protocol_engine(iphy);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001183
Dan Williams85280952011-06-28 15:05:53 -07001184 if (iphy->sm.previous_state_id != SCI_PHY_INITIAL)
1185 scic_sds_controller_link_down(scic_sds_phy_get_controller(iphy),
1186 phy_get_non_dummy_port(iphy),
1187 iphy);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001188}
1189
Dan Williams9269e0e2011-05-12 07:42:17 -07001190static void scic_sds_phy_starting_state_enter(struct sci_base_state_machine *sm)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001191{
Dan Williams85280952011-06-28 15:05:53 -07001192 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001193
Dan Williams85280952011-06-28 15:05:53 -07001194 scu_link_layer_stop_protocol_engine(iphy);
1195 scu_link_layer_start_oob(iphy);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001196
1197 /* We don't know what kind of phy we are going to be just yet */
Dan Williams85280952011-06-28 15:05:53 -07001198 iphy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
1199 iphy->bcn_received_while_port_unassigned = false;
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001200
Dan Williams85280952011-06-28 15:05:53 -07001201 if (iphy->sm.previous_state_id == SCI_PHY_READY)
1202 scic_sds_controller_link_down(scic_sds_phy_get_controller(iphy),
1203 phy_get_non_dummy_port(iphy),
1204 iphy);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001205
Dan Williams85280952011-06-28 15:05:53 -07001206 sci_change_state(&iphy->sm, SCI_PHY_SUB_INITIAL);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001207}
1208
Dan Williams9269e0e2011-05-12 07:42:17 -07001209static void scic_sds_phy_ready_state_enter(struct sci_base_state_machine *sm)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001210{
Dan Williams85280952011-06-28 15:05:53 -07001211 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001212
Dan Williams85280952011-06-28 15:05:53 -07001213 scic_sds_controller_link_up(scic_sds_phy_get_controller(iphy),
1214 phy_get_non_dummy_port(iphy),
1215 iphy);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001216
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001217}
1218
Dan Williams9269e0e2011-05-12 07:42:17 -07001219static void scic_sds_phy_ready_state_exit(struct sci_base_state_machine *sm)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001220{
Dan Williams85280952011-06-28 15:05:53 -07001221 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001222
Dan Williams85280952011-06-28 15:05:53 -07001223 scic_sds_phy_suspend(iphy);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001224}
1225
Dan Williams9269e0e2011-05-12 07:42:17 -07001226static void scic_sds_phy_resetting_state_enter(struct sci_base_state_machine *sm)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001227{
Dan Williams85280952011-06-28 15:05:53 -07001228 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001229
Dan Williams5b1d4af2011-05-12 04:51:41 -07001230 /* The phy is being reset, therefore deactivate it from the port. In
1231 * the resetting state we don't notify the user regarding link up and
1232 * link down notifications
1233 */
Dan Williams85280952011-06-28 15:05:53 -07001234 scic_sds_port_deactivate_phy(iphy->owning_port, iphy, false);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001235
Dan Williams85280952011-06-28 15:05:53 -07001236 if (iphy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
1237 scu_link_layer_tx_hard_reset(iphy);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001238 } else {
Dan Williams5b1d4af2011-05-12 04:51:41 -07001239 /* The SCU does not need to have a discrete reset state so
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001240 * just go back to the starting state.
1241 */
Dan Williams85280952011-06-28 15:05:53 -07001242 sci_change_state(&iphy->sm, SCI_PHY_STARTING);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001243 }
1244}
1245
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001246static const struct sci_base_state scic_sds_phy_state_table[] = {
Edmund Nadolskie3013702011-06-02 00:10:43 +00001247 [SCI_PHY_INITIAL] = { },
1248 [SCI_PHY_STOPPED] = {
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001249 .enter_state = scic_sds_phy_stopped_state_enter,
1250 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001251 [SCI_PHY_STARTING] = {
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001252 .enter_state = scic_sds_phy_starting_state_enter,
1253 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001254 [SCI_PHY_SUB_INITIAL] = {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001255 .enter_state = scic_sds_phy_starting_initial_substate_enter,
1256 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001257 [SCI_PHY_SUB_AWAIT_OSSP_EN] = { },
1258 [SCI_PHY_SUB_AWAIT_SAS_SPEED_EN] = { },
1259 [SCI_PHY_SUB_AWAIT_IAF_UF] = { },
1260 [SCI_PHY_SUB_AWAIT_SAS_POWER] = {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001261 .enter_state = scic_sds_phy_starting_await_sas_power_substate_enter,
1262 .exit_state = scic_sds_phy_starting_await_sas_power_substate_exit,
1263 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001264 [SCI_PHY_SUB_AWAIT_SATA_POWER] = {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001265 .enter_state = scic_sds_phy_starting_await_sata_power_substate_enter,
1266 .exit_state = scic_sds_phy_starting_await_sata_power_substate_exit
1267 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001268 [SCI_PHY_SUB_AWAIT_SATA_PHY_EN] = {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001269 .enter_state = scic_sds_phy_starting_await_sata_phy_substate_enter,
1270 .exit_state = scic_sds_phy_starting_await_sata_phy_substate_exit
1271 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001272 [SCI_PHY_SUB_AWAIT_SATA_SPEED_EN] = {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001273 .enter_state = scic_sds_phy_starting_await_sata_speed_substate_enter,
1274 .exit_state = scic_sds_phy_starting_await_sata_speed_substate_exit
1275 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001276 [SCI_PHY_SUB_AWAIT_SIG_FIS_UF] = {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001277 .enter_state = scic_sds_phy_starting_await_sig_fis_uf_substate_enter,
1278 .exit_state = scic_sds_phy_starting_await_sig_fis_uf_substate_exit
1279 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001280 [SCI_PHY_SUB_FINAL] = {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001281 .enter_state = scic_sds_phy_starting_final_substate_enter,
1282 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001283 [SCI_PHY_READY] = {
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001284 .enter_state = scic_sds_phy_ready_state_enter,
1285 .exit_state = scic_sds_phy_ready_state_exit,
1286 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001287 [SCI_PHY_RESETTING] = {
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001288 .enter_state = scic_sds_phy_resetting_state_enter,
1289 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001290 [SCI_PHY_FINAL] = { },
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001291};
1292
Dan Williams85280952011-06-28 15:05:53 -07001293void scic_sds_phy_construct(struct isci_phy *iphy,
Dan Williamsffe191c2011-06-29 13:09:25 -07001294 struct isci_port *iport, u8 phy_index)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001295{
Dan Williams85280952011-06-28 15:05:53 -07001296 sci_init_sm(&iphy->sm, scic_sds_phy_state_table, SCI_PHY_INITIAL);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001297
1298 /* Copy the rest of the input data to our locals */
Dan Williamsffe191c2011-06-29 13:09:25 -07001299 iphy->owning_port = iport;
Dan Williams85280952011-06-28 15:05:53 -07001300 iphy->phy_index = phy_index;
1301 iphy->bcn_received_while_port_unassigned = false;
1302 iphy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
1303 iphy->link_layer_registers = NULL;
1304 iphy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
Edmund Nadolskia628d472011-05-19 11:59:36 +00001305
1306 /* Create the SIGNATURE FIS Timeout timer for this phy */
Dan Williams85280952011-06-28 15:05:53 -07001307 sci_init_timer(&iphy->sata_timer, phy_sata_timeout);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001308}
Dan Williams6f231dd2011-07-02 22:56:22 -07001309
Dan Williams4b339812011-05-06 17:36:38 -07001310void isci_phy_init(struct isci_phy *iphy, struct isci_host *ihost, int index)
Dan Williams6f231dd2011-07-02 22:56:22 -07001311{
Dan Williams150fc6f2011-02-25 10:25:21 -08001312 union scic_oem_parameters oem;
Dan Williams4b339812011-05-06 17:36:38 -07001313 u64 sci_sas_addr;
1314 __be64 sas_addr;
Dan Williams6f231dd2011-07-02 22:56:22 -07001315
Dan Williams4b339812011-05-06 17:36:38 -07001316 scic_oem_parameters_get(&ihost->sci, &oem);
1317 sci_sas_addr = oem.sds1.phys[index].sas_address.high;
1318 sci_sas_addr <<= 32;
1319 sci_sas_addr |= oem.sds1.phys[index].sas_address.low;
1320 sas_addr = cpu_to_be64(sci_sas_addr);
1321 memcpy(iphy->sas_addr, &sas_addr, sizeof(sas_addr));
Dan Williams6f231dd2011-07-02 22:56:22 -07001322
Dan Williams4b339812011-05-06 17:36:38 -07001323 iphy->isci_port = NULL;
1324 iphy->sas_phy.enabled = 0;
1325 iphy->sas_phy.id = index;
1326 iphy->sas_phy.sas_addr = &iphy->sas_addr[0];
1327 iphy->sas_phy.frame_rcvd = (u8 *)&iphy->frame_rcvd;
1328 iphy->sas_phy.ha = &ihost->sas_ha;
1329 iphy->sas_phy.lldd_phy = iphy;
1330 iphy->sas_phy.enabled = 1;
1331 iphy->sas_phy.class = SAS;
1332 iphy->sas_phy.iproto = SAS_PROTOCOL_ALL;
1333 iphy->sas_phy.tproto = 0;
1334 iphy->sas_phy.type = PHY_TYPE_PHYSICAL;
1335 iphy->sas_phy.role = PHY_ROLE_INITIATOR;
1336 iphy->sas_phy.oob_mode = OOB_NOT_CONNECTED;
1337 iphy->sas_phy.linkrate = SAS_LINK_RATE_UNKNOWN;
1338 memset(&iphy->frame_rcvd, 0, sizeof(iphy->frame_rcvd));
Dan Williams6f231dd2011-07-02 22:56:22 -07001339}
1340
1341
1342/**
1343 * isci_phy_control() - This function is one of the SAS Domain Template
1344 * functions. This is a phy management function.
1345 * @phy: This parameter specifies the sphy being controlled.
1346 * @func: This parameter specifies the phy control function being invoked.
1347 * @buf: This parameter is specific to the phy function being invoked.
1348 *
1349 * status, zero indicates success.
1350 */
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001351int isci_phy_control(struct asd_sas_phy *sas_phy,
1352 enum phy_func func,
1353 void *buf)
Dan Williams6f231dd2011-07-02 22:56:22 -07001354{
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001355 int ret = 0;
1356 struct isci_phy *iphy = sas_phy->lldd_phy;
1357 struct isci_port *iport = iphy->isci_port;
1358 struct isci_host *ihost = sas_phy->ha->lldd_ha;
1359 unsigned long flags;
Dan Williams6f231dd2011-07-02 22:56:22 -07001360
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001361 dev_dbg(&ihost->pdev->dev,
1362 "%s: phy %p; func %d; buf %p; isci phy %p, port %p\n",
1363 __func__, sas_phy, func, buf, iphy, iport);
Dan Williams6f231dd2011-07-02 22:56:22 -07001364
1365 switch (func) {
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001366 case PHY_FUNC_DISABLE:
1367 spin_lock_irqsave(&ihost->scic_lock, flags);
Dan Williams85280952011-06-28 15:05:53 -07001368 scic_sds_phy_stop(iphy);
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001369 spin_unlock_irqrestore(&ihost->scic_lock, flags);
1370 break;
1371
Dan Williams6f231dd2011-07-02 22:56:22 -07001372 case PHY_FUNC_LINK_RESET:
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001373 spin_lock_irqsave(&ihost->scic_lock, flags);
Dan Williams85280952011-06-28 15:05:53 -07001374 scic_sds_phy_stop(iphy);
1375 scic_sds_phy_start(iphy);
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001376 spin_unlock_irqrestore(&ihost->scic_lock, flags);
1377 break;
1378
1379 case PHY_FUNC_HARD_RESET:
1380 if (!iport)
1381 return -ENODEV;
Dan Williams6f231dd2011-07-02 22:56:22 -07001382
1383 /* Perform the port reset. */
Dan Williams4393aa42011-03-31 13:10:44 -07001384 ret = isci_port_perform_hard_reset(ihost, iport, iphy);
Dan Williams6f231dd2011-07-02 22:56:22 -07001385
1386 break;
1387
Dan Williams6f231dd2011-07-02 22:56:22 -07001388 default:
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001389 dev_dbg(&ihost->pdev->dev,
1390 "%s: phy %p; func %d NOT IMPLEMENTED!\n",
1391 __func__, sas_phy, func);
1392 ret = -ENOSYS;
Dan Williams6f231dd2011-07-02 22:56:22 -07001393 break;
1394 }
1395 return ret;
1396}