blob: 87064f13f8fab7e1e24568e0f0cad05a02fe8aca [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 Williamsd7a0ccd2012-02-10 01:18:44 -080062#undef C
63#define C(a) (#a)
64static const char *phy_state_name(enum sci_phy_states state)
65{
66 static const char * const strings[] = PHY_STATES;
67
68 return strings[state];
69}
70#undef C
71
Dan Williamsd35bc1b2011-05-10 02:28:45 -070072/* Maximum arbitration wait time in micro-seconds */
73#define SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME (700)
74
Dan Williams85280952011-06-28 15:05:53 -070075enum sas_linkrate sci_phy_linkrate(struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -070076{
Dan Williams85280952011-06-28 15:05:53 -070077 return iphy->max_negotiated_speed;
Dan Williamsd35bc1b2011-05-10 02:28:45 -070078}
79
Dan Williamsc132f692012-01-03 23:26:08 -080080static struct device *sciphy_to_dev(struct isci_phy *iphy)
81{
82 struct isci_phy *table = iphy - iphy->phy_index;
83 struct isci_host *ihost = container_of(table, typeof(*ihost), phys[0]);
84
85 return &ihost->pdev->dev;
86}
87
Dan Williams89a73012011-06-30 19:14:33 -070088static enum sci_status
89sci_phy_transport_layer_initialization(struct isci_phy *iphy,
90 struct scu_transport_layer_registers __iomem *reg)
Dan Williamsd35bc1b2011-05-10 02:28:45 -070091{
92 u32 tl_control;
93
Dan Williams89a73012011-06-30 19:14:33 -070094 iphy->transport_layer_registers = reg;
Dan Williamsd35bc1b2011-05-10 02:28:45 -070095
96 writel(SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX,
Dan Williams85280952011-06-28 15:05:53 -070097 &iphy->transport_layer_registers->stp_rni);
Dan Williamsd35bc1b2011-05-10 02:28:45 -070098
99 /*
100 * Hardware team recommends that we enable the STP prefetch for all
101 * transports
102 */
Dan Williams85280952011-06-28 15:05:53 -0700103 tl_control = readl(&iphy->transport_layer_registers->control);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700104 tl_control |= SCU_TLCR_GEN_BIT(STP_WRITE_DATA_PREFETCH);
Dan Williams85280952011-06-28 15:05:53 -0700105 writel(tl_control, &iphy->transport_layer_registers->control);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700106
107 return SCI_SUCCESS;
108}
109
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700110static enum sci_status
Dan Williams89a73012011-06-30 19:14:33 -0700111sci_phy_link_layer_initialization(struct isci_phy *iphy,
Dan Williams2e5da882012-01-04 01:32:34 -0800112 struct scu_link_layer_registers __iomem *llr)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700113{
Dan Williams89a73012011-06-30 19:14:33 -0700114 struct isci_host *ihost = iphy->owning_port->owning_controller;
Dan Williams2e5da882012-01-04 01:32:34 -0800115 struct sci_phy_user_params *phy_user;
116 struct sci_phy_oem_params *phy_oem;
Dan Williams85280952011-06-28 15:05:53 -0700117 int phy_idx = iphy->phy_index;
Dan Williams89a73012011-06-30 19:14:33 -0700118 struct sci_phy_cap phy_cap;
Dan Williams2e5da882012-01-04 01:32:34 -0800119 u32 phy_configuration;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700120 u32 parity_check = 0;
121 u32 parity_count = 0;
122 u32 llctl, link_rate;
123 u32 clksm_value = 0;
Marcin Tomczak985af6f2011-07-29 17:16:50 -0700124 u32 sp_timeouts = 0;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700125
Dan Williams2e5da882012-01-04 01:32:34 -0800126 phy_user = &ihost->user_parameters.phys[phy_idx];
127 phy_oem = &ihost->oem_parameters.phys[phy_idx];
128 iphy->link_layer_registers = llr;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700129
130 /* Set our IDENTIFY frame data */
131 #define SCI_END_DEVICE 0x01
132
133 writel(SCU_SAS_TIID_GEN_BIT(SMP_INITIATOR) |
134 SCU_SAS_TIID_GEN_BIT(SSP_INITIATOR) |
135 SCU_SAS_TIID_GEN_BIT(STP_INITIATOR) |
136 SCU_SAS_TIID_GEN_BIT(DA_SATA_HOST) |
137 SCU_SAS_TIID_GEN_VAL(DEVICE_TYPE, SCI_END_DEVICE),
Dan Williams2e5da882012-01-04 01:32:34 -0800138 &llr->transmit_identification);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700139
140 /* Write the device SAS Address */
Dan Williams2e5da882012-01-04 01:32:34 -0800141 writel(0xFEDCBA98, &llr->sas_device_name_high);
142 writel(phy_idx, &llr->sas_device_name_low);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700143
144 /* Write the source SAS Address */
Dan Williams2e5da882012-01-04 01:32:34 -0800145 writel(phy_oem->sas_address.high, &llr->source_sas_address_high);
146 writel(phy_oem->sas_address.low, &llr->source_sas_address_low);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700147
148 /* Clear and Set the PHY Identifier */
Dan Williams2e5da882012-01-04 01:32:34 -0800149 writel(0, &llr->identify_frame_phy_id);
150 writel(SCU_SAS_TIPID_GEN_VALUE(ID, phy_idx), &llr->identify_frame_phy_id);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700151
152 /* Change the initial state of the phy configuration register */
Dan Williams2e5da882012-01-04 01:32:34 -0800153 phy_configuration = readl(&llr->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700154
155 /* Hold OOB state machine in reset */
156 phy_configuration |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
Dan Williams2e5da882012-01-04 01:32:34 -0800157 writel(phy_configuration, &llr->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700158
159 /* Configure the SNW capabilities */
160 phy_cap.all = 0;
161 phy_cap.start = 1;
162 phy_cap.gen3_no_ssc = 1;
163 phy_cap.gen2_no_ssc = 1;
164 phy_cap.gen1_no_ssc = 1;
Dave Jiang594e5662012-01-04 01:32:44 -0800165 if (ihost->oem_parameters.controller.do_enable_ssc) {
166 struct scu_afe_registers __iomem *afe = &ihost->scu_registers->afe;
167 struct scu_afe_transceiver *xcvr = &afe->scu_afe_xcvr[phy_idx];
168 struct isci_pci_info *pci_info = to_pci_info(ihost->pdev);
169 bool en_sas = false;
170 bool en_sata = false;
171 u32 sas_type = 0;
172 u32 sata_spread = 0x2;
173 u32 sas_spread = 0x2;
174
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700175 phy_cap.gen3_ssc = 1;
176 phy_cap.gen2_ssc = 1;
177 phy_cap.gen1_ssc = 1;
Dave Jiang594e5662012-01-04 01:32:44 -0800178
179 if (pci_info->orom->hdr.version < ISCI_ROM_VER_1_1)
180 en_sas = en_sata = true;
181 else {
182 sata_spread = ihost->oem_parameters.controller.ssc_sata_tx_spread_level;
183 sas_spread = ihost->oem_parameters.controller.ssc_sas_tx_spread_level;
184
185 if (sata_spread)
186 en_sata = true;
187
188 if (sas_spread) {
189 en_sas = true;
190 sas_type = ihost->oem_parameters.controller.ssc_sas_tx_type;
191 }
192
193 }
194
195 if (en_sas) {
196 u32 reg;
197
198 reg = readl(&xcvr->afe_xcvr_control0);
199 reg |= (0x00100000 | (sas_type << 19));
200 writel(reg, &xcvr->afe_xcvr_control0);
201
202 reg = readl(&xcvr->afe_tx_ssc_control);
203 reg |= sas_spread << 8;
204 writel(reg, &xcvr->afe_tx_ssc_control);
205 }
206
207 if (en_sata) {
208 u32 reg;
209
210 reg = readl(&xcvr->afe_tx_ssc_control);
211 reg |= sata_spread;
212 writel(reg, &xcvr->afe_tx_ssc_control);
213
214 reg = readl(&llr->stp_control);
215 reg |= 1 << 12;
216 writel(reg, &llr->stp_control);
217 }
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700218 }
219
Dan Williams2e5da882012-01-04 01:32:34 -0800220 /* The SAS specification indicates that the phy_capabilities that
221 * are transmitted shall have an even parity. Calculate the parity.
222 */
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700223 parity_check = phy_cap.all;
224 while (parity_check != 0) {
225 if (parity_check & 0x1)
226 parity_count++;
227 parity_check >>= 1;
228 }
229
Dan Williams2e5da882012-01-04 01:32:34 -0800230 /* If parity indicates there are an odd number of bits set, then
231 * set the parity bit to 1 in the phy capabilities.
232 */
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700233 if ((parity_count % 2) != 0)
234 phy_cap.parity = 1;
235
Dan Williams2e5da882012-01-04 01:32:34 -0800236 writel(phy_cap.all, &llr->phy_capabilities);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700237
238 /* Set the enable spinup period but disable the ability to send
239 * notify enable spinup
240 */
241 writel(SCU_ENSPINUP_GEN_VAL(COUNT,
242 phy_user->notify_enable_spin_up_insertion_frequency),
Dan Williams2e5da882012-01-04 01:32:34 -0800243 &llr->notify_enable_spinup_control);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700244
245 /* Write the ALIGN Insertion Ferequency for connected phy and
246 * inpendent of connected state
247 */
248 clksm_value = SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(CONNECTED,
249 phy_user->in_connection_align_insertion_frequency);
250
251 clksm_value |= SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(GENERAL,
252 phy_user->align_insertion_frequency);
253
Dan Williams2e5da882012-01-04 01:32:34 -0800254 writel(clksm_value, &llr->clock_skew_management);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700255
Jeff Skirvinafd13a12012-01-04 01:32:39 -0800256 if (is_c0(ihost->pdev) || is_c1(ihost->pdev)) {
257 writel(0x04210400, &llr->afe_lookup_table_control);
258 writel(0x020A7C05, &llr->sas_primitive_timeout);
259 } else
260 writel(0x02108421, &llr->afe_lookup_table_control);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700261
262 llctl = SCU_SAS_LLCTL_GEN_VAL(NO_OUTBOUND_TASK_TIMEOUT,
Dan Williams89a73012011-06-30 19:14:33 -0700263 (u8)ihost->user_parameters.no_outbound_task_timeout);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700264
James Bottomleya5ec7f862011-07-03 14:14:45 -0500265 switch (phy_user->max_speed_generation) {
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700266 case SCIC_SDS_PARM_GEN3_SPEED:
267 link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN3;
268 break;
269 case SCIC_SDS_PARM_GEN2_SPEED:
270 link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN2;
271 break;
272 default:
273 link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN1;
274 break;
275 }
276 llctl |= SCU_SAS_LLCTL_GEN_VAL(MAX_LINK_RATE, link_rate);
Dan Williams2e5da882012-01-04 01:32:34 -0800277 writel(llctl, &llr->link_layer_control);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700278
Dan Williams2e5da882012-01-04 01:32:34 -0800279 sp_timeouts = readl(&llr->sas_phy_timeouts);
Marcin Tomczak985af6f2011-07-29 17:16:50 -0700280
281 /* Clear the default 0x36 (54us) RATE_CHANGE timeout value. */
282 sp_timeouts &= ~SCU_SAS_PHYTOV_GEN_VAL(RATE_CHANGE, 0xFF);
283
284 /* Set RATE_CHANGE timeout value to 0x3B (59us). This ensures SCU can
285 * lock with 3Gb drive when SCU max rate is set to 1.5Gb.
286 */
287 sp_timeouts |= SCU_SAS_PHYTOV_GEN_VAL(RATE_CHANGE, 0x3B);
288
Dan Williams2e5da882012-01-04 01:32:34 -0800289 writel(sp_timeouts, &llr->sas_phy_timeouts);
Marcin Tomczak985af6f2011-07-29 17:16:50 -0700290
Dan Williamsdc00c8b2011-07-01 11:41:21 -0700291 if (is_a2(ihost->pdev)) {
Dan Williams2e5da882012-01-04 01:32:34 -0800292 /* Program the max ARB time for the PHY to 700us so we
293 * inter-operate with the PMC expander which shuts down
294 * PHYs if the expander PHY generates too many breaks.
295 * This time value will guarantee that the initiator PHY
296 * will generate the break.
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700297 */
298 writel(SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME,
Dan Williams2e5da882012-01-04 01:32:34 -0800299 &llr->maximum_arbitration_wait_timer_timeout);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700300 }
301
Dan Williams2e5da882012-01-04 01:32:34 -0800302 /* Disable link layer hang detection, rely on the OS timeout for
303 * I/O timeouts.
304 */
305 writel(0, &llr->link_layer_hang_detection_timeout);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700306
307 /* We can exit the initial state to the stopped state */
Dan Williams85280952011-06-28 15:05:53 -0700308 sci_change_state(&iphy->sm, SCI_PHY_STOPPED);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700309
310 return SCI_SUCCESS;
311}
312
Edmund Nadolskia628d472011-05-19 11:59:36 +0000313static void phy_sata_timeout(unsigned long data)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700314{
Edmund Nadolskia628d472011-05-19 11:59:36 +0000315 struct sci_timer *tmr = (struct sci_timer *)data;
Dan Williams85280952011-06-28 15:05:53 -0700316 struct isci_phy *iphy = container_of(tmr, typeof(*iphy), sata_timer);
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700317 struct isci_host *ihost = iphy->owning_port->owning_controller;
Edmund Nadolskia628d472011-05-19 11:59:36 +0000318 unsigned long flags;
319
320 spin_lock_irqsave(&ihost->scic_lock, flags);
321
322 if (tmr->cancel)
323 goto done;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700324
Dan Williams85280952011-06-28 15:05:53 -0700325 dev_dbg(sciphy_to_dev(iphy),
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700326 "%s: SCIC SDS Phy 0x%p did not receive signature fis before "
327 "timeout.\n",
328 __func__,
Dan Williams85280952011-06-28 15:05:53 -0700329 iphy);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700330
Dan Williams85280952011-06-28 15:05:53 -0700331 sci_change_state(&iphy->sm, SCI_PHY_STARTING);
Edmund Nadolskia628d472011-05-19 11:59:36 +0000332done:
333 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700334}
335
336/**
337 * This method returns the port currently containing this phy. If the phy is
338 * currently contained by the dummy port, then the phy is considered to not
339 * be part of a port.
340 * @sci_phy: This parameter specifies the phy for which to retrieve the
341 * containing port.
342 *
343 * This method returns a handle to a port that contains the supplied phy.
344 * NULL This value is returned if the phy is not part of a real
345 * port (i.e. it's contained in the dummy port). !NULL All other
346 * values indicate a handle/pointer to the port containing the phy.
347 */
Dan Williams34a99152011-07-01 02:25:15 -0700348struct isci_port *phy_get_non_dummy_port(struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700349{
Dan Williams34a99152011-07-01 02:25:15 -0700350 struct isci_port *iport = iphy->owning_port;
351
352 if (iport->physical_port_index == SCIC_SDS_DUMMY_PORT)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700353 return NULL;
354
Dan Williams85280952011-06-28 15:05:53 -0700355 return iphy->owning_port;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700356}
357
358/**
359 * This method will assign a port to the phy object.
Dan Williams85280952011-06-28 15:05:53 -0700360 * @out]: iphy This parameter specifies the phy for which to assign a port
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700361 * object.
362 *
363 *
364 */
Dan Williams89a73012011-06-30 19:14:33 -0700365void sci_phy_set_port(
Dan Williams85280952011-06-28 15:05:53 -0700366 struct isci_phy *iphy,
Dan Williamsffe191c2011-06-29 13:09:25 -0700367 struct isci_port *iport)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700368{
Dan Williamsffe191c2011-06-29 13:09:25 -0700369 iphy->owning_port = iport;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700370
Dan Williams85280952011-06-28 15:05:53 -0700371 if (iphy->bcn_received_while_port_unassigned) {
372 iphy->bcn_received_while_port_unassigned = false;
Dan Williams89a73012011-06-30 19:14:33 -0700373 sci_port_broadcast_change_received(iphy->owning_port, iphy);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700374 }
375}
376
Dan Williams89a73012011-06-30 19:14:33 -0700377enum sci_status sci_phy_initialize(struct isci_phy *iphy,
378 struct scu_transport_layer_registers __iomem *tl,
379 struct scu_link_layer_registers __iomem *ll)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700380{
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700381 /* Perfrom the initialization of the TL hardware */
Dan Williams89a73012011-06-30 19:14:33 -0700382 sci_phy_transport_layer_initialization(iphy, tl);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700383
384 /* Perofrm the initialization of the PE hardware */
Dan Williams89a73012011-06-30 19:14:33 -0700385 sci_phy_link_layer_initialization(iphy, ll);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700386
Dan Williams89a73012011-06-30 19:14:33 -0700387 /* There is nothing that needs to be done in this state just
388 * transition to the stopped state
389 */
Dan Williams85280952011-06-28 15:05:53 -0700390 sci_change_state(&iphy->sm, SCI_PHY_STOPPED);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700391
392 return SCI_SUCCESS;
393}
394
395/**
396 * This method assigns the direct attached device ID for this phy.
397 *
Dan Williams85280952011-06-28 15:05:53 -0700398 * @iphy The phy for which the direct attached device id is to
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700399 * be assigned.
400 * @device_id The direct attached device ID to assign to the phy.
401 * This will either be the RNi for the device or an invalid RNi if there
402 * is no current device assigned to the phy.
403 */
Dan Williams89a73012011-06-30 19:14:33 -0700404void sci_phy_setup_transport(struct isci_phy *iphy, u32 device_id)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700405{
406 u32 tl_control;
407
Dan Williams85280952011-06-28 15:05:53 -0700408 writel(device_id, &iphy->transport_layer_registers->stp_rni);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700409
410 /*
411 * The read should guarantee that the first write gets posted
412 * before the next write
413 */
Dan Williams85280952011-06-28 15:05:53 -0700414 tl_control = readl(&iphy->transport_layer_registers->control);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700415 tl_control |= SCU_TLCR_GEN_BIT(CLEAR_TCI_NCQ_MAPPING_TABLE);
Dan Williams85280952011-06-28 15:05:53 -0700416 writel(tl_control, &iphy->transport_layer_registers->control);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700417}
418
Dan Williams89a73012011-06-30 19:14:33 -0700419static void sci_phy_suspend(struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700420{
421 u32 scu_sas_pcfg_value;
422
423 scu_sas_pcfg_value =
Dan Williams85280952011-06-28 15:05:53 -0700424 readl(&iphy->link_layer_registers->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700425 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE);
426 writel(scu_sas_pcfg_value,
Dan Williams85280952011-06-28 15:05:53 -0700427 &iphy->link_layer_registers->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700428
Dan Williams89a73012011-06-30 19:14:33 -0700429 sci_phy_setup_transport(iphy, SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700430}
431
Dan Williams89a73012011-06-30 19:14:33 -0700432void sci_phy_resume(struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700433{
434 u32 scu_sas_pcfg_value;
435
436 scu_sas_pcfg_value =
Dan Williams85280952011-06-28 15:05:53 -0700437 readl(&iphy->link_layer_registers->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700438 scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE);
439 writel(scu_sas_pcfg_value,
Dan Williams85280952011-06-28 15:05:53 -0700440 &iphy->link_layer_registers->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700441}
442
Dan Williams89a73012011-06-30 19:14:33 -0700443void sci_phy_get_sas_address(struct isci_phy *iphy, struct sci_sas_address *sas)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700444{
Dan Williams89a73012011-06-30 19:14:33 -0700445 sas->high = readl(&iphy->link_layer_registers->source_sas_address_high);
446 sas->low = readl(&iphy->link_layer_registers->source_sas_address_low);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700447}
448
Dan Williams89a73012011-06-30 19:14:33 -0700449void sci_phy_get_attached_sas_address(struct isci_phy *iphy, struct sci_sas_address *sas)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700450{
451 struct sas_identify_frame *iaf;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700452
453 iaf = &iphy->frame_rcvd.iaf;
Dan Williams89a73012011-06-30 19:14:33 -0700454 memcpy(sas, iaf->sas_addr, SAS_ADDR_SIZE);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700455}
456
Dan Williams89a73012011-06-30 19:14:33 -0700457void sci_phy_get_protocols(struct isci_phy *iphy, struct sci_phy_proto *proto)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700458{
Dan Williams89a73012011-06-30 19:14:33 -0700459 proto->all = readl(&iphy->link_layer_registers->transmit_identification);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700460}
461
Dan Williams89a73012011-06-30 19:14:33 -0700462enum sci_status sci_phy_start(struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700463{
Dan Williams89a73012011-06-30 19:14:33 -0700464 enum sci_phy_states state = iphy->sm.current_state_id;
Dan Williams966699b2011-05-12 03:44:24 -0700465
Edmund Nadolskie3013702011-06-02 00:10:43 +0000466 if (state != SCI_PHY_STOPPED) {
Dan Williamsd7a0ccd2012-02-10 01:18:44 -0800467 dev_dbg(sciphy_to_dev(iphy), "%s: in wrong state: %s\n",
468 __func__, phy_state_name(state));
Dan Williams966699b2011-05-12 03:44:24 -0700469 return SCI_FAILURE_INVALID_STATE;
470 }
471
Dan Williams85280952011-06-28 15:05:53 -0700472 sci_change_state(&iphy->sm, SCI_PHY_STARTING);
Dan Williams966699b2011-05-12 03:44:24 -0700473 return SCI_SUCCESS;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700474}
475
Dan Williams89a73012011-06-30 19:14:33 -0700476enum sci_status sci_phy_stop(struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700477{
Dan Williams89a73012011-06-30 19:14:33 -0700478 enum sci_phy_states state = iphy->sm.current_state_id;
Dan Williams93153232011-05-12 04:01:03 -0700479
480 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +0000481 case SCI_PHY_SUB_INITIAL:
482 case SCI_PHY_SUB_AWAIT_OSSP_EN:
483 case SCI_PHY_SUB_AWAIT_SAS_SPEED_EN:
484 case SCI_PHY_SUB_AWAIT_SAS_POWER:
485 case SCI_PHY_SUB_AWAIT_SATA_POWER:
486 case SCI_PHY_SUB_AWAIT_SATA_PHY_EN:
487 case SCI_PHY_SUB_AWAIT_SATA_SPEED_EN:
488 case SCI_PHY_SUB_AWAIT_SIG_FIS_UF:
489 case SCI_PHY_SUB_FINAL:
490 case SCI_PHY_READY:
Dan Williams93153232011-05-12 04:01:03 -0700491 break;
492 default:
Dan Williamsd7a0ccd2012-02-10 01:18:44 -0800493 dev_dbg(sciphy_to_dev(iphy), "%s: in wrong state: %s\n",
494 __func__, phy_state_name(state));
Dan Williams93153232011-05-12 04:01:03 -0700495 return SCI_FAILURE_INVALID_STATE;
496 }
497
Dan Williams85280952011-06-28 15:05:53 -0700498 sci_change_state(&iphy->sm, SCI_PHY_STOPPED);
Dan Williams93153232011-05-12 04:01:03 -0700499 return SCI_SUCCESS;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700500}
501
Dan Williams89a73012011-06-30 19:14:33 -0700502enum sci_status sci_phy_reset(struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700503{
Dan Williams89a73012011-06-30 19:14:33 -0700504 enum sci_phy_states state = iphy->sm.current_state_id;
Dan Williams0cf36fa2011-05-12 04:02:07 -0700505
Edmund Nadolskie3013702011-06-02 00:10:43 +0000506 if (state != SCI_PHY_READY) {
Dan Williamsd7a0ccd2012-02-10 01:18:44 -0800507 dev_dbg(sciphy_to_dev(iphy), "%s: in wrong state: %s\n",
508 __func__, phy_state_name(state));
Dan Williams0cf36fa2011-05-12 04:02:07 -0700509 return SCI_FAILURE_INVALID_STATE;
510 }
511
Dan Williams85280952011-06-28 15:05:53 -0700512 sci_change_state(&iphy->sm, SCI_PHY_RESETTING);
Dan Williams0cf36fa2011-05-12 04:02:07 -0700513 return SCI_SUCCESS;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700514}
515
Dan Williams89a73012011-06-30 19:14:33 -0700516enum sci_status sci_phy_consume_power_handler(struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700517{
Dan Williams89a73012011-06-30 19:14:33 -0700518 enum sci_phy_states state = iphy->sm.current_state_id;
Dan Williams5b1d4af2011-05-12 04:51:41 -0700519
520 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +0000521 case SCI_PHY_SUB_AWAIT_SAS_POWER: {
Dan Williams5b1d4af2011-05-12 04:51:41 -0700522 u32 enable_spinup;
523
Dan Williams85280952011-06-28 15:05:53 -0700524 enable_spinup = readl(&iphy->link_layer_registers->notify_enable_spinup_control);
Dan Williams5b1d4af2011-05-12 04:51:41 -0700525 enable_spinup |= SCU_ENSPINUP_GEN_BIT(ENABLE);
Dan Williams85280952011-06-28 15:05:53 -0700526 writel(enable_spinup, &iphy->link_layer_registers->notify_enable_spinup_control);
Dan Williams5b1d4af2011-05-12 04:51:41 -0700527
528 /* Change state to the final state this substate machine has run to completion */
Dan Williams85280952011-06-28 15:05:53 -0700529 sci_change_state(&iphy->sm, SCI_PHY_SUB_FINAL);
Dan Williams5b1d4af2011-05-12 04:51:41 -0700530
531 return SCI_SUCCESS;
532 }
Edmund Nadolskie3013702011-06-02 00:10:43 +0000533 case SCI_PHY_SUB_AWAIT_SATA_POWER: {
Dan Williams5b1d4af2011-05-12 04:51:41 -0700534 u32 scu_sas_pcfg_value;
535
536 /* Release the spinup hold state and reset the OOB state machine */
537 scu_sas_pcfg_value =
Dan Williams85280952011-06-28 15:05:53 -0700538 readl(&iphy->link_layer_registers->phy_configuration);
Dan Williams5b1d4af2011-05-12 04:51:41 -0700539 scu_sas_pcfg_value &=
540 ~(SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD) | SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE));
541 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
542 writel(scu_sas_pcfg_value,
Dan Williams85280952011-06-28 15:05:53 -0700543 &iphy->link_layer_registers->phy_configuration);
Dan Williams5b1d4af2011-05-12 04:51:41 -0700544
545 /* Now restart the OOB operation */
546 scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
547 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
548 writel(scu_sas_pcfg_value,
Dan Williams85280952011-06-28 15:05:53 -0700549 &iphy->link_layer_registers->phy_configuration);
Dan Williams5b1d4af2011-05-12 04:51:41 -0700550
551 /* Change state to the final state this substate machine has run to completion */
Dan Williams85280952011-06-28 15:05:53 -0700552 sci_change_state(&iphy->sm, SCI_PHY_SUB_AWAIT_SATA_PHY_EN);
Dan Williams5b1d4af2011-05-12 04:51:41 -0700553
554 return SCI_SUCCESS;
555 }
556 default:
Dan Williamsd7a0ccd2012-02-10 01:18:44 -0800557 dev_dbg(sciphy_to_dev(iphy), "%s: in wrong state: %s\n",
558 __func__, phy_state_name(state));
Dan Williams5b1d4af2011-05-12 04:51:41 -0700559 return SCI_FAILURE_INVALID_STATE;
560 }
Dan Williams23506a62011-05-12 04:27:29 -0700561}
562
Dan Williams89a73012011-06-30 19:14:33 -0700563static void sci_phy_start_sas_link_training(struct isci_phy *iphy)
Dan Williams23506a62011-05-12 04:27:29 -0700564{
Dan Williams89a73012011-06-30 19:14:33 -0700565 /* continue the link training for the phy as if it were a SAS PHY
566 * instead of a SATA PHY. This is done because the completion queue had a SAS
567 * PHY DETECTED event when the state machine was expecting a SATA PHY event.
568 */
Dan Williams23506a62011-05-12 04:27:29 -0700569 u32 phy_control;
570
Dan Williams89a73012011-06-30 19:14:33 -0700571 phy_control = readl(&iphy->link_layer_registers->phy_configuration);
Dan Williams23506a62011-05-12 04:27:29 -0700572 phy_control |= SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD);
573 writel(phy_control,
Dan Williams89a73012011-06-30 19:14:33 -0700574 &iphy->link_layer_registers->phy_configuration);
Dan Williams23506a62011-05-12 04:27:29 -0700575
Dan Williams85280952011-06-28 15:05:53 -0700576 sci_change_state(&iphy->sm, SCI_PHY_SUB_AWAIT_SAS_SPEED_EN);
Dan Williams23506a62011-05-12 04:27:29 -0700577
Dan Williams85280952011-06-28 15:05:53 -0700578 iphy->protocol = SCIC_SDS_PHY_PROTOCOL_SAS;
Dan Williams23506a62011-05-12 04:27:29 -0700579}
580
Dan Williams89a73012011-06-30 19:14:33 -0700581static void sci_phy_start_sata_link_training(struct isci_phy *iphy)
Dan Williams23506a62011-05-12 04:27:29 -0700582{
Dan Williams89a73012011-06-30 19:14:33 -0700583 /* This method continues the link training for the phy as if it were a SATA PHY
584 * instead of a SAS PHY. This is done because the completion queue had a SATA
585 * SPINUP HOLD event when the state machine was expecting a SAS PHY event. none
586 */
Dan Williams85280952011-06-28 15:05:53 -0700587 sci_change_state(&iphy->sm, SCI_PHY_SUB_AWAIT_SATA_POWER);
Dan Williams23506a62011-05-12 04:27:29 -0700588
Dan Williams85280952011-06-28 15:05:53 -0700589 iphy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
Dan Williams23506a62011-05-12 04:27:29 -0700590}
591
592/**
Dan Williams89a73012011-06-30 19:14:33 -0700593 * sci_phy_complete_link_training - perform processing common to
Dan Williams23506a62011-05-12 04:27:29 -0700594 * all protocols upon completion of link training.
595 * @sci_phy: This parameter specifies the phy object for which link training
596 * has completed.
597 * @max_link_rate: This parameter specifies the maximum link rate to be
598 * associated with this phy.
599 * @next_state: This parameter specifies the next state for the phy's starting
600 * sub-state machine.
601 *
602 */
Dan Williams89a73012011-06-30 19:14:33 -0700603static void sci_phy_complete_link_training(struct isci_phy *iphy,
604 enum sas_linkrate max_link_rate,
605 u32 next_state)
Dan Williams23506a62011-05-12 04:27:29 -0700606{
Dan Williams85280952011-06-28 15:05:53 -0700607 iphy->max_negotiated_speed = max_link_rate;
Dan Williams23506a62011-05-12 04:27:29 -0700608
Dan Williams85280952011-06-28 15:05:53 -0700609 sci_change_state(&iphy->sm, next_state);
Dan Williams23506a62011-05-12 04:27:29 -0700610}
611
Dan Williams89a73012011-06-30 19:14:33 -0700612enum sci_status sci_phy_event_handler(struct isci_phy *iphy, u32 event_code)
Dan Williams23506a62011-05-12 04:27:29 -0700613{
Dan Williams89a73012011-06-30 19:14:33 -0700614 enum sci_phy_states state = iphy->sm.current_state_id;
Dan Williams23506a62011-05-12 04:27:29 -0700615
616 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +0000617 case SCI_PHY_SUB_AWAIT_OSSP_EN:
Dan Williams23506a62011-05-12 04:27:29 -0700618 switch (scu_get_event_code(event_code)) {
619 case SCU_EVENT_SAS_PHY_DETECTED:
Dan Williams89a73012011-06-30 19:14:33 -0700620 sci_phy_start_sas_link_training(iphy);
Dan Williams85280952011-06-28 15:05:53 -0700621 iphy->is_in_link_training = true;
Dan Williams23506a62011-05-12 04:27:29 -0700622 break;
623 case SCU_EVENT_SATA_SPINUP_HOLD:
Dan Williams89a73012011-06-30 19:14:33 -0700624 sci_phy_start_sata_link_training(iphy);
Dan Williams85280952011-06-28 15:05:53 -0700625 iphy->is_in_link_training = true;
Dan Williams23506a62011-05-12 04:27:29 -0700626 break;
627 default:
Dan Williams85280952011-06-28 15:05:53 -0700628 dev_dbg(sciphy_to_dev(iphy),
Dan Williams23506a62011-05-12 04:27:29 -0700629 "%s: PHY starting substate machine received "
630 "unexpected event_code %x\n",
631 __func__,
632 event_code);
633 return SCI_FAILURE;
634 }
635 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000636 case SCI_PHY_SUB_AWAIT_SAS_SPEED_EN:
Dan Williams23506a62011-05-12 04:27:29 -0700637 switch (scu_get_event_code(event_code)) {
638 case SCU_EVENT_SAS_PHY_DETECTED:
639 /*
640 * Why is this being reported again by the controller?
641 * We would re-enter this state so just stay here */
642 break;
643 case SCU_EVENT_SAS_15:
644 case SCU_EVENT_SAS_15_SSC:
Dan Williams89a73012011-06-30 19:14:33 -0700645 sci_phy_complete_link_training(iphy, SAS_LINK_RATE_1_5_GBPS,
646 SCI_PHY_SUB_AWAIT_IAF_UF);
Dan Williams23506a62011-05-12 04:27:29 -0700647 break;
648 case SCU_EVENT_SAS_30:
649 case SCU_EVENT_SAS_30_SSC:
Dan Williams89a73012011-06-30 19:14:33 -0700650 sci_phy_complete_link_training(iphy, SAS_LINK_RATE_3_0_GBPS,
651 SCI_PHY_SUB_AWAIT_IAF_UF);
Dan Williams23506a62011-05-12 04:27:29 -0700652 break;
653 case SCU_EVENT_SAS_60:
654 case SCU_EVENT_SAS_60_SSC:
Dan Williams89a73012011-06-30 19:14:33 -0700655 sci_phy_complete_link_training(iphy, SAS_LINK_RATE_6_0_GBPS,
656 SCI_PHY_SUB_AWAIT_IAF_UF);
Dan Williams23506a62011-05-12 04:27:29 -0700657 break;
658 case SCU_EVENT_SATA_SPINUP_HOLD:
659 /*
660 * We were doing SAS PHY link training and received a SATA PHY event
661 * continue OOB/SN as if this were a SATA PHY */
Dan Williams89a73012011-06-30 19:14:33 -0700662 sci_phy_start_sata_link_training(iphy);
Dan Williams23506a62011-05-12 04:27:29 -0700663 break;
664 case SCU_EVENT_LINK_FAILURE:
665 /* Link failure change state back to the starting state */
Dan Williams85280952011-06-28 15:05:53 -0700666 sci_change_state(&iphy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700667 break;
668 default:
Dan Williams85280952011-06-28 15:05:53 -0700669 dev_warn(sciphy_to_dev(iphy),
Dan Williams23506a62011-05-12 04:27:29 -0700670 "%s: PHY starting substate machine received "
671 "unexpected event_code %x\n",
672 __func__, event_code);
673
674 return SCI_FAILURE;
675 break;
676 }
677 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000678 case SCI_PHY_SUB_AWAIT_IAF_UF:
Dan Williams23506a62011-05-12 04:27:29 -0700679 switch (scu_get_event_code(event_code)) {
680 case SCU_EVENT_SAS_PHY_DETECTED:
681 /* Backup the state machine */
Dan Williams89a73012011-06-30 19:14:33 -0700682 sci_phy_start_sas_link_training(iphy);
Dan Williams23506a62011-05-12 04:27:29 -0700683 break;
684 case SCU_EVENT_SATA_SPINUP_HOLD:
685 /* We were doing SAS PHY link training and received a
686 * SATA PHY event continue OOB/SN as if this were a
687 * SATA PHY
688 */
Dan Williams89a73012011-06-30 19:14:33 -0700689 sci_phy_start_sata_link_training(iphy);
Dan Williams23506a62011-05-12 04:27:29 -0700690 break;
691 case SCU_EVENT_RECEIVED_IDENTIFY_TIMEOUT:
692 case SCU_EVENT_LINK_FAILURE:
693 case SCU_EVENT_HARD_RESET_RECEIVED:
694 /* Start the oob/sn state machine over again */
Dan Williams85280952011-06-28 15:05:53 -0700695 sci_change_state(&iphy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700696 break;
697 default:
Dan Williams85280952011-06-28 15:05:53 -0700698 dev_warn(sciphy_to_dev(iphy),
Dan Williams23506a62011-05-12 04:27:29 -0700699 "%s: PHY starting substate machine received "
700 "unexpected event_code %x\n",
701 __func__, event_code);
702 return SCI_FAILURE;
703 }
704 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000705 case SCI_PHY_SUB_AWAIT_SAS_POWER:
Dan Williams23506a62011-05-12 04:27:29 -0700706 switch (scu_get_event_code(event_code)) {
707 case SCU_EVENT_LINK_FAILURE:
708 /* Link failure change state back to the starting state */
Dan Williams85280952011-06-28 15:05:53 -0700709 sci_change_state(&iphy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700710 break;
711 default:
Dan Williams85280952011-06-28 15:05:53 -0700712 dev_warn(sciphy_to_dev(iphy),
Dan Williams23506a62011-05-12 04:27:29 -0700713 "%s: PHY starting substate machine received unexpected "
714 "event_code %x\n",
715 __func__,
716 event_code);
717 return SCI_FAILURE;
718 }
719 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000720 case SCI_PHY_SUB_AWAIT_SATA_POWER:
Dan Williams23506a62011-05-12 04:27:29 -0700721 switch (scu_get_event_code(event_code)) {
722 case SCU_EVENT_LINK_FAILURE:
723 /* Link failure change state back to the starting state */
Dan Williams85280952011-06-28 15:05:53 -0700724 sci_change_state(&iphy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700725 break;
726 case SCU_EVENT_SATA_SPINUP_HOLD:
727 /* These events are received every 10ms and are
728 * expected while in this state
729 */
730 break;
731
732 case SCU_EVENT_SAS_PHY_DETECTED:
733 /* There has been a change in the phy type before OOB/SN for the
734 * SATA finished start down the SAS link traning path.
735 */
Dan Williams89a73012011-06-30 19:14:33 -0700736 sci_phy_start_sas_link_training(iphy);
Dan Williams23506a62011-05-12 04:27:29 -0700737 break;
738
739 default:
Dan Williams85280952011-06-28 15:05:53 -0700740 dev_warn(sciphy_to_dev(iphy),
Dan Williams23506a62011-05-12 04:27:29 -0700741 "%s: PHY starting substate machine received "
742 "unexpected event_code %x\n",
743 __func__, event_code);
744
745 return SCI_FAILURE;
746 }
747 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000748 case SCI_PHY_SUB_AWAIT_SATA_PHY_EN:
Dan Williams23506a62011-05-12 04:27:29 -0700749 switch (scu_get_event_code(event_code)) {
750 case SCU_EVENT_LINK_FAILURE:
751 /* Link failure change state back to the starting state */
Dan Williams85280952011-06-28 15:05:53 -0700752 sci_change_state(&iphy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700753 break;
754 case SCU_EVENT_SATA_SPINUP_HOLD:
755 /* These events might be received since we dont know how many may be in
756 * the completion queue while waiting for power
757 */
758 break;
759 case SCU_EVENT_SATA_PHY_DETECTED:
Dan Williams85280952011-06-28 15:05:53 -0700760 iphy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
Dan Williams23506a62011-05-12 04:27:29 -0700761
762 /* We have received the SATA PHY notification change state */
Dan Williams85280952011-06-28 15:05:53 -0700763 sci_change_state(&iphy->sm, SCI_PHY_SUB_AWAIT_SATA_SPEED_EN);
Dan Williams23506a62011-05-12 04:27:29 -0700764 break;
765 case SCU_EVENT_SAS_PHY_DETECTED:
766 /* There has been a change in the phy type before OOB/SN for the
767 * SATA finished start down the SAS link traning path.
768 */
Dan Williams89a73012011-06-30 19:14:33 -0700769 sci_phy_start_sas_link_training(iphy);
Dan Williams23506a62011-05-12 04:27:29 -0700770 break;
771 default:
Dan Williams85280952011-06-28 15:05:53 -0700772 dev_warn(sciphy_to_dev(iphy),
Dan Williams23506a62011-05-12 04:27:29 -0700773 "%s: PHY starting substate machine received "
774 "unexpected event_code %x\n",
775 __func__,
776 event_code);
777
Justin P. Mattock69932482011-07-26 23:06:29 -0700778 return SCI_FAILURE;
Dan Williams23506a62011-05-12 04:27:29 -0700779 }
780 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000781 case SCI_PHY_SUB_AWAIT_SATA_SPEED_EN:
Dan Williams23506a62011-05-12 04:27:29 -0700782 switch (scu_get_event_code(event_code)) {
783 case SCU_EVENT_SATA_PHY_DETECTED:
784 /*
785 * The hardware reports multiple SATA PHY detected events
786 * ignore the extras */
787 break;
788 case SCU_EVENT_SATA_15:
789 case SCU_EVENT_SATA_15_SSC:
Dan Williams89a73012011-06-30 19:14:33 -0700790 sci_phy_complete_link_training(iphy, SAS_LINK_RATE_1_5_GBPS,
791 SCI_PHY_SUB_AWAIT_SIG_FIS_UF);
Dan Williams23506a62011-05-12 04:27:29 -0700792 break;
793 case SCU_EVENT_SATA_30:
794 case SCU_EVENT_SATA_30_SSC:
Dan Williams89a73012011-06-30 19:14:33 -0700795 sci_phy_complete_link_training(iphy, SAS_LINK_RATE_3_0_GBPS,
796 SCI_PHY_SUB_AWAIT_SIG_FIS_UF);
Dan Williams23506a62011-05-12 04:27:29 -0700797 break;
798 case SCU_EVENT_SATA_60:
799 case SCU_EVENT_SATA_60_SSC:
Dan Williams89a73012011-06-30 19:14:33 -0700800 sci_phy_complete_link_training(iphy, SAS_LINK_RATE_6_0_GBPS,
801 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 Williams89a73012011-06-30 19:14:33 -0700811 sci_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)
Dan Williams89a73012011-06-30 19:14:33 -0700854 sci_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 Williamsd7a0ccd2012-02-10 01:18:44 -0800883 dev_dbg(sciphy_to_dev(iphy), "%s: in wrong state: %s\n",
884 __func__, phy_state_name(state));
Dan Williams23506a62011-05-12 04:27:29 -0700885 return SCI_FAILURE_INVALID_STATE;
886 }
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700887}
888
Dan Williams89a73012011-06-30 19:14:33 -0700889enum sci_status sci_phy_frame_handler(struct isci_phy *iphy, u32 frame_index)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700890{
Dan Williams89a73012011-06-30 19:14:33 -0700891 enum sci_phy_states state = iphy->sm.current_state_id;
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700892 struct isci_host *ihost = iphy->owning_port->owning_controller;
Dan Williamsc4441ab2011-05-12 04:17:51 -0700893 enum sci_status result;
Dan Williams4cffe132011-06-23 23:44:52 -0700894 unsigned long flags;
Dan Williamsc4441ab2011-05-12 04:17:51 -0700895
896 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +0000897 case SCI_PHY_SUB_AWAIT_IAF_UF: {
Dan Williamsc4441ab2011-05-12 04:17:51 -0700898 u32 *frame_words;
899 struct sas_identify_frame iaf;
Dan Williamsc4441ab2011-05-12 04:17:51 -0700900
Dan Williams89a73012011-06-30 19:14:33 -0700901 result = sci_unsolicited_frame_control_get_header(&ihost->uf_control,
902 frame_index,
903 (void **)&frame_words);
Dan Williamsc4441ab2011-05-12 04:17:51 -0700904
905 if (result != SCI_SUCCESS)
906 return result;
907
908 sci_swab32_cpy(&iaf, frame_words, sizeof(iaf) / sizeof(u32));
909 if (iaf.frame_type == 0) {
910 u32 state;
911
Dan Williams4cffe132011-06-23 23:44:52 -0700912 spin_lock_irqsave(&iphy->sas_phy.frame_rcvd_lock, flags);
Dan Williamsc4441ab2011-05-12 04:17:51 -0700913 memcpy(&iphy->frame_rcvd.iaf, &iaf, sizeof(iaf));
Dan Williams4cffe132011-06-23 23:44:52 -0700914 spin_unlock_irqrestore(&iphy->sas_phy.frame_rcvd_lock, flags);
Dan Williamsc4441ab2011-05-12 04:17:51 -0700915 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 }
Dan Williams85280952011-06-28 15:05:53 -0700927 sci_change_state(&iphy->sm, state);
Dan Williamsc4441ab2011-05-12 04:17:51 -0700928 result = SCI_SUCCESS;
929 } else
Dan Williams85280952011-06-28 15:05:53 -0700930 dev_warn(sciphy_to_dev(iphy),
Dan Williamsc4441ab2011-05-12 04:17:51 -0700931 "%s: PHY starting substate machine received "
932 "unexpected frame id %x\n",
933 __func__, frame_index);
934
Dan Williams89a73012011-06-30 19:14:33 -0700935 sci_controller_release_frame(ihost, frame_index);
Dan Williamsc4441ab2011-05-12 04:17:51 -0700936 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;
Dan Williamsc4441ab2011-05-12 04:17:51 -0700941
Dan Williams34a99152011-07-01 02:25:15 -0700942 result = sci_unsolicited_frame_control_get_header(&ihost->uf_control,
943 frame_index,
944 (void **)&frame_header);
Dan Williamsc4441ab2011-05-12 04:17:51 -0700945
946 if (result != SCI_SUCCESS)
947 return result;
948
949 if ((frame_header->fis_type == FIS_REGD2H) &&
950 !(frame_header->status & ATA_BUSY)) {
Dan Williams89a73012011-06-30 19:14:33 -0700951 sci_unsolicited_frame_control_get_buffer(&ihost->uf_control,
952 frame_index,
953 (void **)&fis_frame_data);
Dan Williamsc4441ab2011-05-12 04:17:51 -0700954
Dan Williams4cffe132011-06-23 23:44:52 -0700955 spin_lock_irqsave(&iphy->sas_phy.frame_rcvd_lock, flags);
Dan Williams89a73012011-06-30 19:14:33 -0700956 sci_controller_copy_sata_response(&iphy->frame_rcvd.fis,
957 frame_header,
958 fis_frame_data);
Dan Williams4cffe132011-06-23 23:44:52 -0700959 spin_unlock_irqrestore(&iphy->sas_phy.frame_rcvd_lock, flags);
Dan Williamsc4441ab2011-05-12 04:17:51 -0700960
961 /* got IAF we can now go to the await spinup semaphore state */
Dan Williams85280952011-06-28 15:05:53 -0700962 sci_change_state(&iphy->sm, SCI_PHY_SUB_FINAL);
Dan Williamsc4441ab2011-05-12 04:17:51 -0700963
964 result = SCI_SUCCESS;
965 } else
Dan Williams85280952011-06-28 15:05:53 -0700966 dev_warn(sciphy_to_dev(iphy),
Dan Williamsc4441ab2011-05-12 04:17:51 -0700967 "%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 */
Dan Williams89a73012011-06-30 19:14:33 -0700972 sci_controller_release_frame(ihost, frame_index);
Dan Williamsc4441ab2011-05-12 04:17:51 -0700973
974 return result;
975 }
976 default:
Dan Williamsd7a0ccd2012-02-10 01:18:44 -0800977 dev_dbg(sciphy_to_dev(iphy), "%s: in wrong state: %s\n",
978 __func__, phy_state_name(state));
Dan Williamsc4441ab2011-05-12 04:17:51 -0700979 return SCI_FAILURE_INVALID_STATE;
980 }
Dan Williams5076a1a2011-06-27 14:57:03 -0700981
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700982}
983
Dan Williams89a73012011-06-30 19:14:33 -0700984static void sci_phy_starting_initial_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +0000985{
Dan Williams85280952011-06-28 15:05:53 -0700986 struct isci_phy *iphy = container_of(sm, typeof(*iphy), 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 */
Dan Williams85280952011-06-28 15:05:53 -0700989 sci_change_state(&iphy->sm, SCI_PHY_SUB_AWAIT_OSSP_EN);
Adam Gruchala4a33c522011-05-10 23:54:23 +0000990}
991
Dan Williams89a73012011-06-30 19:14:33 -0700992static void sci_phy_starting_await_sas_power_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +0000993{
Dan Williams85280952011-06-28 15:05:53 -0700994 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700995 struct isci_host *ihost = iphy->owning_port->owning_controller;
Adam Gruchala4a33c522011-05-10 23:54:23 +0000996
Dan Williams89a73012011-06-30 19:14:33 -0700997 sci_controller_power_control_queue_insert(ihost, iphy);
Adam Gruchala4a33c522011-05-10 23:54:23 +0000998}
999
Dan Williams89a73012011-06-30 19:14:33 -07001000static void sci_phy_starting_await_sas_power_substate_exit(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001001{
Dan Williams85280952011-06-28 15:05:53 -07001002 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Dan Williamsd9dcb4b2011-06-30 17:38:32 -07001003 struct isci_host *ihost = iphy->owning_port->owning_controller;
Adam Gruchala4a33c522011-05-10 23:54:23 +00001004
Dan Williams89a73012011-06-30 19:14:33 -07001005 sci_controller_power_control_queue_remove(ihost, iphy);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001006}
1007
Dan Williams89a73012011-06-30 19:14:33 -07001008static void sci_phy_starting_await_sata_power_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001009{
Dan Williams85280952011-06-28 15:05:53 -07001010 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Dan Williamsd9dcb4b2011-06-30 17:38:32 -07001011 struct isci_host *ihost = iphy->owning_port->owning_controller;
Adam Gruchala4a33c522011-05-10 23:54:23 +00001012
Dan Williams89a73012011-06-30 19:14:33 -07001013 sci_controller_power_control_queue_insert(ihost, iphy);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001014}
1015
Dan Williams89a73012011-06-30 19:14:33 -07001016static void sci_phy_starting_await_sata_power_substate_exit(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001017{
Dan Williams85280952011-06-28 15:05:53 -07001018 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Dan Williamsd9dcb4b2011-06-30 17:38:32 -07001019 struct isci_host *ihost = iphy->owning_port->owning_controller;
Adam Gruchala4a33c522011-05-10 23:54:23 +00001020
Dan Williams89a73012011-06-30 19:14:33 -07001021 sci_controller_power_control_queue_remove(ihost, iphy);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001022}
1023
Dan Williams89a73012011-06-30 19:14:33 -07001024static void sci_phy_starting_await_sata_phy_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001025{
Dan Williams85280952011-06-28 15:05:53 -07001026 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001027
Dan Williams85280952011-06-28 15:05:53 -07001028 sci_mod_timer(&iphy->sata_timer, SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001029}
1030
Dan Williams89a73012011-06-30 19:14:33 -07001031static void sci_phy_starting_await_sata_phy_substate_exit(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001032{
Dan Williams85280952011-06-28 15:05:53 -07001033 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001034
Dan Williams85280952011-06-28 15:05:53 -07001035 sci_del_timer(&iphy->sata_timer);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001036}
1037
Dan Williams89a73012011-06-30 19:14:33 -07001038static void sci_phy_starting_await_sata_speed_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001039{
Dan Williams85280952011-06-28 15:05:53 -07001040 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001041
Dan Williams85280952011-06-28 15:05:53 -07001042 sci_mod_timer(&iphy->sata_timer, SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001043}
1044
Dan Williams89a73012011-06-30 19:14:33 -07001045static void sci_phy_starting_await_sata_speed_substate_exit(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001046{
Dan Williams85280952011-06-28 15:05:53 -07001047 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001048
Dan Williams85280952011-06-28 15:05:53 -07001049 sci_del_timer(&iphy->sata_timer);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001050}
1051
Dan Williams89a73012011-06-30 19:14:33 -07001052static void sci_phy_starting_await_sig_fis_uf_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001053{
Dan Williams85280952011-06-28 15:05:53 -07001054 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001055
Dan Williams89a73012011-06-30 19:14:33 -07001056 if (sci_port_link_detected(iphy->owning_port, iphy)) {
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 */
Dan Williams89a73012011-06-30 19:14:33 -07001064 sci_phy_resume(iphy);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001065
Dan Williams85280952011-06-28 15:05:53 -07001066 sci_mod_timer(&iphy->sata_timer,
Edmund Nadolskia628d472011-05-19 11:59:36 +00001067 SCIC_SDS_SIGNATURE_FIS_TIMEOUT);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001068 } else
Dan Williams85280952011-06-28 15:05:53 -07001069 iphy->is_in_link_training = false;
Adam Gruchala4a33c522011-05-10 23:54:23 +00001070}
1071
Dan Williams89a73012011-06-30 19:14:33 -07001072static void sci_phy_starting_await_sig_fis_uf_substate_exit(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001073{
Dan Williams85280952011-06-28 15:05:53 -07001074 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001075
Dan Williams85280952011-06-28 15:05:53 -07001076 sci_del_timer(&iphy->sata_timer);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001077}
1078
Dan Williams89a73012011-06-30 19:14:33 -07001079static void sci_phy_starting_final_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001080{
Dan Williams85280952011-06-28 15:05:53 -07001081 struct isci_phy *iphy = container_of(sm, typeof(*iphy), 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 */
Dan Williams85280952011-06-28 15:05:53 -07001086 sci_change_state(&iphy->sm, SCI_PHY_READY);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001087}
1088
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001089/**
1090 *
Dan Williams85280952011-06-28 15:05:53 -07001091 * @sci_phy: This is the struct isci_phy object to stop.
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001092 *
Dan Williams85280952011-06-28 15:05:53 -07001093 * This method will stop the struct isci_phy object. This does not reset the
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001094 * 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(
Dan Williams85280952011-06-28 15:05:53 -07001098 struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001099{
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 =
Dan Williams85280952011-06-28 15:05:53 -07001105 readl(&iphy->link_layer_registers->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001106 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,
Dan Williams85280952011-06-28 15:05:53 -07001111 &iphy->link_layer_registers->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001112
1113 /* Disable the notify enable spinup primitives */
Dan Williams85280952011-06-28 15:05:53 -07001114 enable_spinup_value = readl(&iphy->link_layer_registers->notify_enable_spinup_control);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001115 enable_spinup_value &= ~SCU_ENSPINUP_GEN_BIT(ENABLE);
Dan Williams85280952011-06-28 15:05:53 -07001116 writel(enable_spinup_value, &iphy->link_layer_registers->notify_enable_spinup_control);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001117}
1118
Marcin Tomczak0953dbe2012-01-04 01:33:36 -08001119static void scu_link_layer_start_oob(struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001120{
Marcin Tomczak0953dbe2012-01-04 01:33:36 -08001121 struct scu_link_layer_registers __iomem *ll = iphy->link_layer_registers;
1122 u32 val;
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001123
Marcin Tomczak0953dbe2012-01-04 01:33:36 -08001124 /** Reset OOB sequence - start */
1125 val = readl(&ll->phy_configuration);
1126 val &= ~(SCU_SAS_PCFG_GEN_BIT(OOB_RESET) |
1127 SCU_SAS_PCFG_GEN_BIT(HARD_RESET));
1128 writel(val, &ll->phy_configuration);
1129 readl(&ll->phy_configuration); /* flush */
1130 /** Reset OOB sequence - end */
1131
1132 /** Start OOB sequence - start */
1133 val = readl(&ll->phy_configuration);
1134 val |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
1135 writel(val, &ll->phy_configuration);
1136 readl(&ll->phy_configuration); /* flush */
1137 /** Start OOB sequence - end */
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001138}
1139
1140/**
1141 *
1142 *
1143 * This method will transmit a hard reset request on the specified phy. The SCU
1144 * hardware requires that we reset the OOB state machine and set the hard reset
1145 * bit in the phy configuration register. We then must start OOB over with the
1146 * hard reset bit set.
1147 */
1148static void scu_link_layer_tx_hard_reset(
Dan Williams85280952011-06-28 15:05:53 -07001149 struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001150{
1151 u32 phy_configuration_value;
1152
1153 /*
1154 * SAS Phys must wait for the HARD_RESET_TX event notification to transition
1155 * to the starting state. */
1156 phy_configuration_value =
Dan Williams85280952011-06-28 15:05:53 -07001157 readl(&iphy->link_layer_registers->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001158 phy_configuration_value |=
1159 (SCU_SAS_PCFG_GEN_BIT(HARD_RESET) |
1160 SCU_SAS_PCFG_GEN_BIT(OOB_RESET));
1161 writel(phy_configuration_value,
Dan Williams85280952011-06-28 15:05:53 -07001162 &iphy->link_layer_registers->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001163
1164 /* Now take the OOB state machine out of reset */
1165 phy_configuration_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
1166 phy_configuration_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
1167 writel(phy_configuration_value,
Dan Williams85280952011-06-28 15:05:53 -07001168 &iphy->link_layer_registers->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001169}
1170
Dan Williams89a73012011-06-30 19:14:33 -07001171static void sci_phy_stopped_state_enter(struct sci_base_state_machine *sm)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001172{
Dan Williams85280952011-06-28 15:05:53 -07001173 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Dan Williams34a99152011-07-01 02:25:15 -07001174 struct isci_port *iport = iphy->owning_port;
1175 struct isci_host *ihost = iport->owning_controller;
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001176
1177 /*
1178 * @todo We need to get to the controller to place this PE in a
1179 * reset state
1180 */
Dan Williams85280952011-06-28 15:05:53 -07001181 sci_del_timer(&iphy->sata_timer);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001182
Dan Williams85280952011-06-28 15:05:53 -07001183 scu_link_layer_stop_protocol_engine(iphy);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001184
Dan Williams85280952011-06-28 15:05:53 -07001185 if (iphy->sm.previous_state_id != SCI_PHY_INITIAL)
Dan Williams34a99152011-07-01 02:25:15 -07001186 sci_controller_link_down(ihost, phy_get_non_dummy_port(iphy), iphy);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001187}
1188
Dan Williams89a73012011-06-30 19:14:33 -07001189static void sci_phy_starting_state_enter(struct sci_base_state_machine *sm)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001190{
Dan Williams85280952011-06-28 15:05:53 -07001191 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Dan Williams34a99152011-07-01 02:25:15 -07001192 struct isci_port *iport = iphy->owning_port;
1193 struct isci_host *ihost = iport->owning_controller;
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001194
Dan Williams85280952011-06-28 15:05:53 -07001195 scu_link_layer_stop_protocol_engine(iphy);
1196 scu_link_layer_start_oob(iphy);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001197
1198 /* We don't know what kind of phy we are going to be just yet */
Dan Williams85280952011-06-28 15:05:53 -07001199 iphy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
1200 iphy->bcn_received_while_port_unassigned = false;
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001201
Dan Williams85280952011-06-28 15:05:53 -07001202 if (iphy->sm.previous_state_id == SCI_PHY_READY)
Dan Williams34a99152011-07-01 02:25:15 -07001203 sci_controller_link_down(ihost, phy_get_non_dummy_port(iphy), iphy);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001204
Dan Williams85280952011-06-28 15:05:53 -07001205 sci_change_state(&iphy->sm, SCI_PHY_SUB_INITIAL);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001206}
1207
Dan Williams89a73012011-06-30 19:14:33 -07001208static void sci_phy_ready_state_enter(struct sci_base_state_machine *sm)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001209{
Dan Williams85280952011-06-28 15:05:53 -07001210 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Dan Williams34a99152011-07-01 02:25:15 -07001211 struct isci_port *iport = iphy->owning_port;
1212 struct isci_host *ihost = iport->owning_controller;
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001213
Dan Williams34a99152011-07-01 02:25:15 -07001214 sci_controller_link_up(ihost, phy_get_non_dummy_port(iphy), iphy);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001215}
1216
Dan Williams89a73012011-06-30 19:14:33 -07001217static void sci_phy_ready_state_exit(struct sci_base_state_machine *sm)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001218{
Dan Williams85280952011-06-28 15:05:53 -07001219 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001220
Dan Williams89a73012011-06-30 19:14:33 -07001221 sci_phy_suspend(iphy);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001222}
1223
Dan Williams89a73012011-06-30 19:14:33 -07001224static void sci_phy_resetting_state_enter(struct sci_base_state_machine *sm)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001225{
Dan Williams85280952011-06-28 15:05:53 -07001226 struct isci_phy *iphy = container_of(sm, typeof(*iphy), 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 Williams89a73012011-06-30 19:14:33 -07001232 sci_port_deactivate_phy(iphy->owning_port, iphy, false);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001233
Dan Williams85280952011-06-28 15:05:53 -07001234 if (iphy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
1235 scu_link_layer_tx_hard_reset(iphy);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001236 } 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 */
Dan Williams85280952011-06-28 15:05:53 -07001240 sci_change_state(&iphy->sm, SCI_PHY_STARTING);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001241 }
1242}
1243
Dan Williams89a73012011-06-30 19:14:33 -07001244static const struct sci_base_state sci_phy_state_table[] = {
Edmund Nadolskie3013702011-06-02 00:10:43 +00001245 [SCI_PHY_INITIAL] = { },
1246 [SCI_PHY_STOPPED] = {
Dan Williams89a73012011-06-30 19:14:33 -07001247 .enter_state = sci_phy_stopped_state_enter,
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001248 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001249 [SCI_PHY_STARTING] = {
Dan Williams89a73012011-06-30 19:14:33 -07001250 .enter_state = sci_phy_starting_state_enter,
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001251 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001252 [SCI_PHY_SUB_INITIAL] = {
Dan Williams89a73012011-06-30 19:14:33 -07001253 .enter_state = sci_phy_starting_initial_substate_enter,
Adam Gruchala4a33c522011-05-10 23:54:23 +00001254 },
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] = {
Dan Williams89a73012011-06-30 19:14:33 -07001259 .enter_state = sci_phy_starting_await_sas_power_substate_enter,
1260 .exit_state = sci_phy_starting_await_sas_power_substate_exit,
Adam Gruchala4a33c522011-05-10 23:54:23 +00001261 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001262 [SCI_PHY_SUB_AWAIT_SATA_POWER] = {
Dan Williams89a73012011-06-30 19:14:33 -07001263 .enter_state = sci_phy_starting_await_sata_power_substate_enter,
1264 .exit_state = sci_phy_starting_await_sata_power_substate_exit
Adam Gruchala4a33c522011-05-10 23:54:23 +00001265 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001266 [SCI_PHY_SUB_AWAIT_SATA_PHY_EN] = {
Dan Williams89a73012011-06-30 19:14:33 -07001267 .enter_state = sci_phy_starting_await_sata_phy_substate_enter,
1268 .exit_state = sci_phy_starting_await_sata_phy_substate_exit
Adam Gruchala4a33c522011-05-10 23:54:23 +00001269 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001270 [SCI_PHY_SUB_AWAIT_SATA_SPEED_EN] = {
Dan Williams89a73012011-06-30 19:14:33 -07001271 .enter_state = sci_phy_starting_await_sata_speed_substate_enter,
1272 .exit_state = sci_phy_starting_await_sata_speed_substate_exit
Adam Gruchala4a33c522011-05-10 23:54:23 +00001273 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001274 [SCI_PHY_SUB_AWAIT_SIG_FIS_UF] = {
Dan Williams89a73012011-06-30 19:14:33 -07001275 .enter_state = sci_phy_starting_await_sig_fis_uf_substate_enter,
1276 .exit_state = sci_phy_starting_await_sig_fis_uf_substate_exit
Adam Gruchala4a33c522011-05-10 23:54:23 +00001277 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001278 [SCI_PHY_SUB_FINAL] = {
Dan Williams89a73012011-06-30 19:14:33 -07001279 .enter_state = sci_phy_starting_final_substate_enter,
Adam Gruchala4a33c522011-05-10 23:54:23 +00001280 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001281 [SCI_PHY_READY] = {
Dan Williams89a73012011-06-30 19:14:33 -07001282 .enter_state = sci_phy_ready_state_enter,
1283 .exit_state = sci_phy_ready_state_exit,
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001284 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001285 [SCI_PHY_RESETTING] = {
Dan Williams89a73012011-06-30 19:14:33 -07001286 .enter_state = sci_phy_resetting_state_enter,
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001287 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001288 [SCI_PHY_FINAL] = { },
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001289};
1290
Dan Williams89a73012011-06-30 19:14:33 -07001291void sci_phy_construct(struct isci_phy *iphy,
Dan Williamsffe191c2011-06-29 13:09:25 -07001292 struct isci_port *iport, u8 phy_index)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001293{
Dan Williams89a73012011-06-30 19:14:33 -07001294 sci_init_sm(&iphy->sm, sci_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 */
Dan Williamsffe191c2011-06-29 13:09:25 -07001297 iphy->owning_port = iport;
Dan Williams85280952011-06-28 15:05:53 -07001298 iphy->phy_index = phy_index;
1299 iphy->bcn_received_while_port_unassigned = false;
1300 iphy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
1301 iphy->link_layer_registers = NULL;
1302 iphy->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 */
Dan Williams85280952011-06-28 15:05:53 -07001305 sci_init_timer(&iphy->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 Williams89a73012011-06-30 19:14:33 -07001310 struct sci_oem_params *oem = &ihost->oem_parameters;
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 Williams89a73012011-06-30 19:14:33 -07001314 sci_sas_addr = oem->phys[index].sas_address.high;
Dan Williams4b339812011-05-06 17:36:38 -07001315 sci_sas_addr <<= 32;
Dan Williams89a73012011-06-30 19:14:33 -07001316 sci_sas_addr |= oem->phys[index].sas_address.low;
Dan Williams4b339812011-05-06 17:36:38 -07001317 sas_addr = cpu_to_be64(sci_sas_addr);
1318 memcpy(iphy->sas_addr, &sas_addr, sizeof(sas_addr));
Dan Williams6f231dd2011-07-02 22:56:22 -07001319
Dan Williams4b339812011-05-06 17:36:38 -07001320 iphy->sas_phy.enabled = 0;
1321 iphy->sas_phy.id = index;
1322 iphy->sas_phy.sas_addr = &iphy->sas_addr[0];
1323 iphy->sas_phy.frame_rcvd = (u8 *)&iphy->frame_rcvd;
1324 iphy->sas_phy.ha = &ihost->sas_ha;
1325 iphy->sas_phy.lldd_phy = iphy;
1326 iphy->sas_phy.enabled = 1;
1327 iphy->sas_phy.class = SAS;
1328 iphy->sas_phy.iproto = SAS_PROTOCOL_ALL;
1329 iphy->sas_phy.tproto = 0;
1330 iphy->sas_phy.type = PHY_TYPE_PHYSICAL;
1331 iphy->sas_phy.role = PHY_ROLE_INITIATOR;
1332 iphy->sas_phy.oob_mode = OOB_NOT_CONNECTED;
1333 iphy->sas_phy.linkrate = SAS_LINK_RATE_UNKNOWN;
1334 memset(&iphy->frame_rcvd, 0, sizeof(iphy->frame_rcvd));
Dan Williams6f231dd2011-07-02 22:56:22 -07001335}
1336
1337
1338/**
1339 * isci_phy_control() - This function is one of the SAS Domain Template
1340 * functions. This is a phy management function.
1341 * @phy: This parameter specifies the sphy being controlled.
1342 * @func: This parameter specifies the phy control function being invoked.
1343 * @buf: This parameter is specific to the phy function being invoked.
1344 *
1345 * status, zero indicates success.
1346 */
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001347int isci_phy_control(struct asd_sas_phy *sas_phy,
1348 enum phy_func func,
1349 void *buf)
Dan Williams6f231dd2011-07-02 22:56:22 -07001350{
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001351 int ret = 0;
1352 struct isci_phy *iphy = sas_phy->lldd_phy;
Dan Williamsc132f692012-01-03 23:26:08 -08001353 struct asd_sas_port *port = sas_phy->port;
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001354 struct isci_host *ihost = sas_phy->ha->lldd_ha;
1355 unsigned long flags;
Dan Williams6f231dd2011-07-02 22:56:22 -07001356
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001357 dev_dbg(&ihost->pdev->dev,
1358 "%s: phy %p; func %d; buf %p; isci phy %p, port %p\n",
Dan Williamsc132f692012-01-03 23:26:08 -08001359 __func__, sas_phy, func, buf, iphy, port);
Dan Williams6f231dd2011-07-02 22:56:22 -07001360
1361 switch (func) {
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001362 case PHY_FUNC_DISABLE:
1363 spin_lock_irqsave(&ihost->scic_lock, flags);
Dan Williams89a73012011-06-30 19:14:33 -07001364 sci_phy_stop(iphy);
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001365 spin_unlock_irqrestore(&ihost->scic_lock, flags);
1366 break;
1367
Dan Williams6f231dd2011-07-02 22:56:22 -07001368 case PHY_FUNC_LINK_RESET:
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001369 spin_lock_irqsave(&ihost->scic_lock, flags);
Dan Williams89a73012011-06-30 19:14:33 -07001370 sci_phy_stop(iphy);
1371 sci_phy_start(iphy);
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001372 spin_unlock_irqrestore(&ihost->scic_lock, flags);
1373 break;
1374
1375 case PHY_FUNC_HARD_RESET:
Dan Williamsc132f692012-01-03 23:26:08 -08001376 if (!port)
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001377 return -ENODEV;
Dan Williams6f231dd2011-07-02 22:56:22 -07001378
Dan Williamsc132f692012-01-03 23:26:08 -08001379 ret = isci_port_perform_hard_reset(ihost, port->lldd_port, iphy);
Dan Williams6f231dd2011-07-02 22:56:22 -07001380
1381 break;
Dan Williamsac013ed2011-09-28 18:48:02 -07001382 case PHY_FUNC_GET_EVENTS: {
1383 struct scu_link_layer_registers __iomem *r;
1384 struct sas_phy *phy = sas_phy->phy;
1385
1386 r = iphy->link_layer_registers;
1387 phy->running_disparity_error_count = readl(&r->running_disparity_error_count);
1388 phy->loss_of_dword_sync_count = readl(&r->loss_of_sync_error_count);
1389 phy->phy_reset_problem_count = readl(&r->phy_reset_problem_count);
1390 phy->invalid_dword_count = readl(&r->invalid_dword_counter);
1391 break;
1392 }
Dan Williams6f231dd2011-07-02 22:56:22 -07001393
Dan Williams6f231dd2011-07-02 22:56:22 -07001394 default:
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001395 dev_dbg(&ihost->pdev->dev,
1396 "%s: phy %p; func %d NOT IMPLEMENTED!\n",
1397 __func__, sas_phy, func);
1398 ret = -ENOSYS;
Dan Williams6f231dd2011-07-02 22:56:22 -07001399 break;
1400 }
1401 return ret;
1402}