blob: 8d412ca689ade2683788ddd7df791a6b38b6cce7 [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
Dan Williamsc132f692012-01-03 23:26:08 -080070static struct device *sciphy_to_dev(struct isci_phy *iphy)
71{
72 struct isci_phy *table = iphy - iphy->phy_index;
73 struct isci_host *ihost = container_of(table, typeof(*ihost), phys[0]);
74
75 return &ihost->pdev->dev;
76}
77
Dan Williams89a73012011-06-30 19:14:33 -070078static enum sci_status
79sci_phy_transport_layer_initialization(struct isci_phy *iphy,
80 struct scu_transport_layer_registers __iomem *reg)
Dan Williamsd35bc1b2011-05-10 02:28:45 -070081{
82 u32 tl_control;
83
Dan Williams89a73012011-06-30 19:14:33 -070084 iphy->transport_layer_registers = reg;
Dan Williamsd35bc1b2011-05-10 02:28:45 -070085
86 writel(SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX,
Dan Williams85280952011-06-28 15:05:53 -070087 &iphy->transport_layer_registers->stp_rni);
Dan Williamsd35bc1b2011-05-10 02:28:45 -070088
89 /*
90 * Hardware team recommends that we enable the STP prefetch for all
91 * transports
92 */
Dan Williams85280952011-06-28 15:05:53 -070093 tl_control = readl(&iphy->transport_layer_registers->control);
Dan Williamsd35bc1b2011-05-10 02:28:45 -070094 tl_control |= SCU_TLCR_GEN_BIT(STP_WRITE_DATA_PREFETCH);
Dan Williams85280952011-06-28 15:05:53 -070095 writel(tl_control, &iphy->transport_layer_registers->control);
Dan Williamsd35bc1b2011-05-10 02:28:45 -070096
97 return SCI_SUCCESS;
98}
99
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700100static enum sci_status
Dan Williams89a73012011-06-30 19:14:33 -0700101sci_phy_link_layer_initialization(struct isci_phy *iphy,
Dan Williams2e5da882012-01-04 01:32:34 -0800102 struct scu_link_layer_registers __iomem *llr)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700103{
Dan Williams89a73012011-06-30 19:14:33 -0700104 struct isci_host *ihost = iphy->owning_port->owning_controller;
Dan Williams2e5da882012-01-04 01:32:34 -0800105 struct sci_phy_user_params *phy_user;
106 struct sci_phy_oem_params *phy_oem;
Dan Williams85280952011-06-28 15:05:53 -0700107 int phy_idx = iphy->phy_index;
Dan Williams89a73012011-06-30 19:14:33 -0700108 struct sci_phy_cap phy_cap;
Dan Williams2e5da882012-01-04 01:32:34 -0800109 u32 phy_configuration;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700110 u32 parity_check = 0;
111 u32 parity_count = 0;
112 u32 llctl, link_rate;
113 u32 clksm_value = 0;
Marcin Tomczak985af6f2011-07-29 17:16:50 -0700114 u32 sp_timeouts = 0;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700115
Dan Williams2e5da882012-01-04 01:32:34 -0800116 phy_user = &ihost->user_parameters.phys[phy_idx];
117 phy_oem = &ihost->oem_parameters.phys[phy_idx];
118 iphy->link_layer_registers = llr;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700119
120 /* Set our IDENTIFY frame data */
121 #define SCI_END_DEVICE 0x01
122
123 writel(SCU_SAS_TIID_GEN_BIT(SMP_INITIATOR) |
124 SCU_SAS_TIID_GEN_BIT(SSP_INITIATOR) |
125 SCU_SAS_TIID_GEN_BIT(STP_INITIATOR) |
126 SCU_SAS_TIID_GEN_BIT(DA_SATA_HOST) |
127 SCU_SAS_TIID_GEN_VAL(DEVICE_TYPE, SCI_END_DEVICE),
Dan Williams2e5da882012-01-04 01:32:34 -0800128 &llr->transmit_identification);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700129
130 /* Write the device SAS Address */
Dan Williams2e5da882012-01-04 01:32:34 -0800131 writel(0xFEDCBA98, &llr->sas_device_name_high);
132 writel(phy_idx, &llr->sas_device_name_low);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700133
134 /* Write the source SAS Address */
Dan Williams2e5da882012-01-04 01:32:34 -0800135 writel(phy_oem->sas_address.high, &llr->source_sas_address_high);
136 writel(phy_oem->sas_address.low, &llr->source_sas_address_low);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700137
138 /* Clear and Set the PHY Identifier */
Dan Williams2e5da882012-01-04 01:32:34 -0800139 writel(0, &llr->identify_frame_phy_id);
140 writel(SCU_SAS_TIPID_GEN_VALUE(ID, phy_idx), &llr->identify_frame_phy_id);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700141
142 /* Change the initial state of the phy configuration register */
Dan Williams2e5da882012-01-04 01:32:34 -0800143 phy_configuration = readl(&llr->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700144
145 /* Hold OOB state machine in reset */
146 phy_configuration |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
Dan Williams2e5da882012-01-04 01:32:34 -0800147 writel(phy_configuration, &llr->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700148
149 /* Configure the SNW capabilities */
150 phy_cap.all = 0;
151 phy_cap.start = 1;
152 phy_cap.gen3_no_ssc = 1;
153 phy_cap.gen2_no_ssc = 1;
154 phy_cap.gen1_no_ssc = 1;
Dave Jiang594e566a2012-01-04 01:32:44 -0800155 if (ihost->oem_parameters.controller.do_enable_ssc) {
156 struct scu_afe_registers __iomem *afe = &ihost->scu_registers->afe;
157 struct scu_afe_transceiver *xcvr = &afe->scu_afe_xcvr[phy_idx];
158 struct isci_pci_info *pci_info = to_pci_info(ihost->pdev);
159 bool en_sas = false;
160 bool en_sata = false;
161 u32 sas_type = 0;
162 u32 sata_spread = 0x2;
163 u32 sas_spread = 0x2;
164
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700165 phy_cap.gen3_ssc = 1;
166 phy_cap.gen2_ssc = 1;
167 phy_cap.gen1_ssc = 1;
Dave Jiang594e566a2012-01-04 01:32:44 -0800168
169 if (pci_info->orom->hdr.version < ISCI_ROM_VER_1_1)
170 en_sas = en_sata = true;
171 else {
172 sata_spread = ihost->oem_parameters.controller.ssc_sata_tx_spread_level;
173 sas_spread = ihost->oem_parameters.controller.ssc_sas_tx_spread_level;
174
175 if (sata_spread)
176 en_sata = true;
177
178 if (sas_spread) {
179 en_sas = true;
180 sas_type = ihost->oem_parameters.controller.ssc_sas_tx_type;
181 }
182
183 }
184
185 if (en_sas) {
186 u32 reg;
187
188 reg = readl(&xcvr->afe_xcvr_control0);
189 reg |= (0x00100000 | (sas_type << 19));
190 writel(reg, &xcvr->afe_xcvr_control0);
191
192 reg = readl(&xcvr->afe_tx_ssc_control);
193 reg |= sas_spread << 8;
194 writel(reg, &xcvr->afe_tx_ssc_control);
195 }
196
197 if (en_sata) {
198 u32 reg;
199
200 reg = readl(&xcvr->afe_tx_ssc_control);
201 reg |= sata_spread;
202 writel(reg, &xcvr->afe_tx_ssc_control);
203
204 reg = readl(&llr->stp_control);
205 reg |= 1 << 12;
206 writel(reg, &llr->stp_control);
207 }
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700208 }
209
Dan Williams2e5da882012-01-04 01:32:34 -0800210 /* The SAS specification indicates that the phy_capabilities that
211 * are transmitted shall have an even parity. Calculate the parity.
212 */
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700213 parity_check = phy_cap.all;
214 while (parity_check != 0) {
215 if (parity_check & 0x1)
216 parity_count++;
217 parity_check >>= 1;
218 }
219
Dan Williams2e5da882012-01-04 01:32:34 -0800220 /* If parity indicates there are an odd number of bits set, then
221 * set the parity bit to 1 in the phy capabilities.
222 */
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700223 if ((parity_count % 2) != 0)
224 phy_cap.parity = 1;
225
Dan Williams2e5da882012-01-04 01:32:34 -0800226 writel(phy_cap.all, &llr->phy_capabilities);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700227
228 /* Set the enable spinup period but disable the ability to send
229 * notify enable spinup
230 */
231 writel(SCU_ENSPINUP_GEN_VAL(COUNT,
232 phy_user->notify_enable_spin_up_insertion_frequency),
Dan Williams2e5da882012-01-04 01:32:34 -0800233 &llr->notify_enable_spinup_control);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700234
235 /* Write the ALIGN Insertion Ferequency for connected phy and
236 * inpendent of connected state
237 */
238 clksm_value = SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(CONNECTED,
239 phy_user->in_connection_align_insertion_frequency);
240
241 clksm_value |= SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(GENERAL,
242 phy_user->align_insertion_frequency);
243
Dan Williams2e5da882012-01-04 01:32:34 -0800244 writel(clksm_value, &llr->clock_skew_management);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700245
Jeff Skirvinafd13a12012-01-04 01:32:39 -0800246 if (is_c0(ihost->pdev) || is_c1(ihost->pdev)) {
247 writel(0x04210400, &llr->afe_lookup_table_control);
248 writel(0x020A7C05, &llr->sas_primitive_timeout);
249 } else
250 writel(0x02108421, &llr->afe_lookup_table_control);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700251
252 llctl = SCU_SAS_LLCTL_GEN_VAL(NO_OUTBOUND_TASK_TIMEOUT,
Dan Williams89a73012011-06-30 19:14:33 -0700253 (u8)ihost->user_parameters.no_outbound_task_timeout);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700254
James Bottomleya5ec7f862011-07-03 14:14:45 -0500255 switch (phy_user->max_speed_generation) {
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700256 case SCIC_SDS_PARM_GEN3_SPEED:
257 link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN3;
258 break;
259 case SCIC_SDS_PARM_GEN2_SPEED:
260 link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN2;
261 break;
262 default:
263 link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN1;
264 break;
265 }
266 llctl |= SCU_SAS_LLCTL_GEN_VAL(MAX_LINK_RATE, link_rate);
Dan Williams2e5da882012-01-04 01:32:34 -0800267 writel(llctl, &llr->link_layer_control);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700268
Dan Williams2e5da882012-01-04 01:32:34 -0800269 sp_timeouts = readl(&llr->sas_phy_timeouts);
Marcin Tomczak985af6f2011-07-29 17:16:50 -0700270
271 /* Clear the default 0x36 (54us) RATE_CHANGE timeout value. */
272 sp_timeouts &= ~SCU_SAS_PHYTOV_GEN_VAL(RATE_CHANGE, 0xFF);
273
274 /* Set RATE_CHANGE timeout value to 0x3B (59us). This ensures SCU can
275 * lock with 3Gb drive when SCU max rate is set to 1.5Gb.
276 */
277 sp_timeouts |= SCU_SAS_PHYTOV_GEN_VAL(RATE_CHANGE, 0x3B);
278
Dan Williams2e5da882012-01-04 01:32:34 -0800279 writel(sp_timeouts, &llr->sas_phy_timeouts);
Marcin Tomczak985af6f2011-07-29 17:16:50 -0700280
Dan Williamsdc00c8b2011-07-01 11:41:21 -0700281 if (is_a2(ihost->pdev)) {
Dan Williams2e5da882012-01-04 01:32:34 -0800282 /* Program the max ARB time for the PHY to 700us so we
283 * inter-operate with the PMC expander which shuts down
284 * PHYs if the expander PHY generates too many breaks.
285 * This time value will guarantee that the initiator PHY
286 * will generate the break.
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700287 */
288 writel(SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME,
Dan Williams2e5da882012-01-04 01:32:34 -0800289 &llr->maximum_arbitration_wait_timer_timeout);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700290 }
291
Dan Williams2e5da882012-01-04 01:32:34 -0800292 /* Disable link layer hang detection, rely on the OS timeout for
293 * I/O timeouts.
294 */
295 writel(0, &llr->link_layer_hang_detection_timeout);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700296
297 /* We can exit the initial state to the stopped state */
Dan Williams85280952011-06-28 15:05:53 -0700298 sci_change_state(&iphy->sm, SCI_PHY_STOPPED);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700299
300 return SCI_SUCCESS;
301}
302
Edmund Nadolskia628d472011-05-19 11:59:36 +0000303static void phy_sata_timeout(unsigned long data)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700304{
Edmund Nadolskia628d472011-05-19 11:59:36 +0000305 struct sci_timer *tmr = (struct sci_timer *)data;
Dan Williams85280952011-06-28 15:05:53 -0700306 struct isci_phy *iphy = container_of(tmr, typeof(*iphy), sata_timer);
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700307 struct isci_host *ihost = iphy->owning_port->owning_controller;
Edmund Nadolskia628d472011-05-19 11:59:36 +0000308 unsigned long flags;
309
310 spin_lock_irqsave(&ihost->scic_lock, flags);
311
312 if (tmr->cancel)
313 goto done;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700314
Dan Williams85280952011-06-28 15:05:53 -0700315 dev_dbg(sciphy_to_dev(iphy),
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700316 "%s: SCIC SDS Phy 0x%p did not receive signature fis before "
317 "timeout.\n",
318 __func__,
Dan Williams85280952011-06-28 15:05:53 -0700319 iphy);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700320
Dan Williams85280952011-06-28 15:05:53 -0700321 sci_change_state(&iphy->sm, SCI_PHY_STARTING);
Edmund Nadolskia628d472011-05-19 11:59:36 +0000322done:
323 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700324}
325
326/**
327 * This method returns the port currently containing this phy. If the phy is
328 * currently contained by the dummy port, then the phy is considered to not
329 * be part of a port.
330 * @sci_phy: This parameter specifies the phy for which to retrieve the
331 * containing port.
332 *
333 * This method returns a handle to a port that contains the supplied phy.
334 * NULL This value is returned if the phy is not part of a real
335 * port (i.e. it's contained in the dummy port). !NULL All other
336 * values indicate a handle/pointer to the port containing the phy.
337 */
Dan Williams34a99152011-07-01 02:25:15 -0700338struct isci_port *phy_get_non_dummy_port(struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700339{
Dan Williams34a99152011-07-01 02:25:15 -0700340 struct isci_port *iport = iphy->owning_port;
341
342 if (iport->physical_port_index == SCIC_SDS_DUMMY_PORT)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700343 return NULL;
344
Dan Williams85280952011-06-28 15:05:53 -0700345 return iphy->owning_port;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700346}
347
348/**
349 * This method will assign a port to the phy object.
Dan Williams85280952011-06-28 15:05:53 -0700350 * @out]: iphy This parameter specifies the phy for which to assign a port
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700351 * object.
352 *
353 *
354 */
Dan Williams89a73012011-06-30 19:14:33 -0700355void sci_phy_set_port(
Dan Williams85280952011-06-28 15:05:53 -0700356 struct isci_phy *iphy,
Dan Williamsffe191c2011-06-29 13:09:25 -0700357 struct isci_port *iport)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700358{
Dan Williamsffe191c2011-06-29 13:09:25 -0700359 iphy->owning_port = iport;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700360
Dan Williams85280952011-06-28 15:05:53 -0700361 if (iphy->bcn_received_while_port_unassigned) {
362 iphy->bcn_received_while_port_unassigned = false;
Dan Williams89a73012011-06-30 19:14:33 -0700363 sci_port_broadcast_change_received(iphy->owning_port, iphy);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700364 }
365}
366
Dan Williams89a73012011-06-30 19:14:33 -0700367enum sci_status sci_phy_initialize(struct isci_phy *iphy,
368 struct scu_transport_layer_registers __iomem *tl,
369 struct scu_link_layer_registers __iomem *ll)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700370{
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700371 /* Perfrom the initialization of the TL hardware */
Dan Williams89a73012011-06-30 19:14:33 -0700372 sci_phy_transport_layer_initialization(iphy, tl);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700373
374 /* Perofrm the initialization of the PE hardware */
Dan Williams89a73012011-06-30 19:14:33 -0700375 sci_phy_link_layer_initialization(iphy, ll);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700376
Dan Williams89a73012011-06-30 19:14:33 -0700377 /* There is nothing that needs to be done in this state just
378 * transition to the stopped state
379 */
Dan Williams85280952011-06-28 15:05:53 -0700380 sci_change_state(&iphy->sm, SCI_PHY_STOPPED);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700381
382 return SCI_SUCCESS;
383}
384
385/**
386 * This method assigns the direct attached device ID for this phy.
387 *
Dan Williams85280952011-06-28 15:05:53 -0700388 * @iphy The phy for which the direct attached device id is to
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700389 * be assigned.
390 * @device_id The direct attached device ID to assign to the phy.
391 * This will either be the RNi for the device or an invalid RNi if there
392 * is no current device assigned to the phy.
393 */
Dan Williams89a73012011-06-30 19:14:33 -0700394void sci_phy_setup_transport(struct isci_phy *iphy, u32 device_id)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700395{
396 u32 tl_control;
397
Dan Williams85280952011-06-28 15:05:53 -0700398 writel(device_id, &iphy->transport_layer_registers->stp_rni);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700399
400 /*
401 * The read should guarantee that the first write gets posted
402 * before the next write
403 */
Dan Williams85280952011-06-28 15:05:53 -0700404 tl_control = readl(&iphy->transport_layer_registers->control);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700405 tl_control |= SCU_TLCR_GEN_BIT(CLEAR_TCI_NCQ_MAPPING_TABLE);
Dan Williams85280952011-06-28 15:05:53 -0700406 writel(tl_control, &iphy->transport_layer_registers->control);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700407}
408
Dan Williams89a73012011-06-30 19:14:33 -0700409static void sci_phy_suspend(struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700410{
411 u32 scu_sas_pcfg_value;
412
413 scu_sas_pcfg_value =
Dan Williams85280952011-06-28 15:05:53 -0700414 readl(&iphy->link_layer_registers->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700415 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE);
416 writel(scu_sas_pcfg_value,
Dan Williams85280952011-06-28 15:05:53 -0700417 &iphy->link_layer_registers->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700418
Dan Williams89a73012011-06-30 19:14:33 -0700419 sci_phy_setup_transport(iphy, SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700420}
421
Dan Williams89a73012011-06-30 19:14:33 -0700422void sci_phy_resume(struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700423{
424 u32 scu_sas_pcfg_value;
425
426 scu_sas_pcfg_value =
Dan Williams85280952011-06-28 15:05:53 -0700427 readl(&iphy->link_layer_registers->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700428 scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE);
429 writel(scu_sas_pcfg_value,
Dan Williams85280952011-06-28 15:05:53 -0700430 &iphy->link_layer_registers->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700431}
432
Dan Williams89a73012011-06-30 19:14:33 -0700433void sci_phy_get_sas_address(struct isci_phy *iphy, struct sci_sas_address *sas)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700434{
Dan Williams89a73012011-06-30 19:14:33 -0700435 sas->high = readl(&iphy->link_layer_registers->source_sas_address_high);
436 sas->low = readl(&iphy->link_layer_registers->source_sas_address_low);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700437}
438
Dan Williams89a73012011-06-30 19:14:33 -0700439void sci_phy_get_attached_sas_address(struct isci_phy *iphy, struct sci_sas_address *sas)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700440{
441 struct sas_identify_frame *iaf;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700442
443 iaf = &iphy->frame_rcvd.iaf;
Dan Williams89a73012011-06-30 19:14:33 -0700444 memcpy(sas, iaf->sas_addr, SAS_ADDR_SIZE);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700445}
446
Dan Williams89a73012011-06-30 19:14:33 -0700447void sci_phy_get_protocols(struct isci_phy *iphy, struct sci_phy_proto *proto)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700448{
Dan Williams89a73012011-06-30 19:14:33 -0700449 proto->all = readl(&iphy->link_layer_registers->transmit_identification);
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700450}
451
Dan Williams89a73012011-06-30 19:14:33 -0700452enum sci_status sci_phy_start(struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700453{
Dan Williams89a73012011-06-30 19:14:33 -0700454 enum sci_phy_states state = iphy->sm.current_state_id;
Dan Williams966699b2011-05-12 03:44:24 -0700455
Edmund Nadolskie3013702011-06-02 00:10:43 +0000456 if (state != SCI_PHY_STOPPED) {
Dan Williams85280952011-06-28 15:05:53 -0700457 dev_dbg(sciphy_to_dev(iphy),
Dan Williams966699b2011-05-12 03:44:24 -0700458 "%s: in wrong state: %d\n", __func__, state);
459 return SCI_FAILURE_INVALID_STATE;
460 }
461
Dan Williams85280952011-06-28 15:05:53 -0700462 sci_change_state(&iphy->sm, SCI_PHY_STARTING);
Dan Williams966699b2011-05-12 03:44:24 -0700463 return SCI_SUCCESS;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700464}
465
Dan Williams89a73012011-06-30 19:14:33 -0700466enum sci_status sci_phy_stop(struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700467{
Dan Williams89a73012011-06-30 19:14:33 -0700468 enum sci_phy_states state = iphy->sm.current_state_id;
Dan Williams93153232011-05-12 04:01:03 -0700469
470 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +0000471 case SCI_PHY_SUB_INITIAL:
472 case SCI_PHY_SUB_AWAIT_OSSP_EN:
473 case SCI_PHY_SUB_AWAIT_SAS_SPEED_EN:
474 case SCI_PHY_SUB_AWAIT_SAS_POWER:
475 case SCI_PHY_SUB_AWAIT_SATA_POWER:
476 case SCI_PHY_SUB_AWAIT_SATA_PHY_EN:
477 case SCI_PHY_SUB_AWAIT_SATA_SPEED_EN:
478 case SCI_PHY_SUB_AWAIT_SIG_FIS_UF:
479 case SCI_PHY_SUB_FINAL:
480 case SCI_PHY_READY:
Dan Williams93153232011-05-12 04:01:03 -0700481 break;
482 default:
Dan Williams85280952011-06-28 15:05:53 -0700483 dev_dbg(sciphy_to_dev(iphy),
Dan Williams93153232011-05-12 04:01:03 -0700484 "%s: in wrong state: %d\n", __func__, state);
485 return SCI_FAILURE_INVALID_STATE;
486 }
487
Dan Williams85280952011-06-28 15:05:53 -0700488 sci_change_state(&iphy->sm, SCI_PHY_STOPPED);
Dan Williams93153232011-05-12 04:01:03 -0700489 return SCI_SUCCESS;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700490}
491
Dan Williams89a73012011-06-30 19:14:33 -0700492enum sci_status sci_phy_reset(struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700493{
Dan Williams89a73012011-06-30 19:14:33 -0700494 enum sci_phy_states state = iphy->sm.current_state_id;
Dan Williams0cf36fa2011-05-12 04:02:07 -0700495
Edmund Nadolskie3013702011-06-02 00:10:43 +0000496 if (state != SCI_PHY_READY) {
Dan Williams85280952011-06-28 15:05:53 -0700497 dev_dbg(sciphy_to_dev(iphy),
Dan Williams0cf36fa2011-05-12 04:02:07 -0700498 "%s: in wrong state: %d\n", __func__, state);
499 return SCI_FAILURE_INVALID_STATE;
500 }
501
Dan Williams85280952011-06-28 15:05:53 -0700502 sci_change_state(&iphy->sm, SCI_PHY_RESETTING);
Dan Williams0cf36fa2011-05-12 04:02:07 -0700503 return SCI_SUCCESS;
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700504}
505
Dan Williams89a73012011-06-30 19:14:33 -0700506enum sci_status sci_phy_consume_power_handler(struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700507{
Dan Williams89a73012011-06-30 19:14:33 -0700508 enum sci_phy_states state = iphy->sm.current_state_id;
Dan Williams5b1d4af2011-05-12 04:51:41 -0700509
510 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +0000511 case SCI_PHY_SUB_AWAIT_SAS_POWER: {
Dan Williams5b1d4af2011-05-12 04:51:41 -0700512 u32 enable_spinup;
513
Dan Williams85280952011-06-28 15:05:53 -0700514 enable_spinup = readl(&iphy->link_layer_registers->notify_enable_spinup_control);
Dan Williams5b1d4af2011-05-12 04:51:41 -0700515 enable_spinup |= SCU_ENSPINUP_GEN_BIT(ENABLE);
Dan Williams85280952011-06-28 15:05:53 -0700516 writel(enable_spinup, &iphy->link_layer_registers->notify_enable_spinup_control);
Dan Williams5b1d4af2011-05-12 04:51:41 -0700517
518 /* Change state to the final state this substate machine has run to completion */
Dan Williams85280952011-06-28 15:05:53 -0700519 sci_change_state(&iphy->sm, SCI_PHY_SUB_FINAL);
Dan Williams5b1d4af2011-05-12 04:51:41 -0700520
521 return SCI_SUCCESS;
522 }
Edmund Nadolskie3013702011-06-02 00:10:43 +0000523 case SCI_PHY_SUB_AWAIT_SATA_POWER: {
Dan Williams5b1d4af2011-05-12 04:51:41 -0700524 u32 scu_sas_pcfg_value;
525
526 /* Release the spinup hold state and reset the OOB state machine */
527 scu_sas_pcfg_value =
Dan Williams85280952011-06-28 15:05:53 -0700528 readl(&iphy->link_layer_registers->phy_configuration);
Dan Williams5b1d4af2011-05-12 04:51:41 -0700529 scu_sas_pcfg_value &=
530 ~(SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD) | SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE));
531 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
532 writel(scu_sas_pcfg_value,
Dan Williams85280952011-06-28 15:05:53 -0700533 &iphy->link_layer_registers->phy_configuration);
Dan Williams5b1d4af2011-05-12 04:51:41 -0700534
535 /* Now restart the OOB operation */
536 scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
537 scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
538 writel(scu_sas_pcfg_value,
Dan Williams85280952011-06-28 15:05:53 -0700539 &iphy->link_layer_registers->phy_configuration);
Dan Williams5b1d4af2011-05-12 04:51:41 -0700540
541 /* Change state to the final state this substate machine has run to completion */
Dan Williams85280952011-06-28 15:05:53 -0700542 sci_change_state(&iphy->sm, SCI_PHY_SUB_AWAIT_SATA_PHY_EN);
Dan Williams5b1d4af2011-05-12 04:51:41 -0700543
544 return SCI_SUCCESS;
545 }
546 default:
Dan Williams85280952011-06-28 15:05:53 -0700547 dev_dbg(sciphy_to_dev(iphy),
Dan Williams5b1d4af2011-05-12 04:51:41 -0700548 "%s: in wrong state: %d\n", __func__, state);
549 return SCI_FAILURE_INVALID_STATE;
550 }
Dan Williams23506a62011-05-12 04:27:29 -0700551}
552
Dan Williams89a73012011-06-30 19:14:33 -0700553static void sci_phy_start_sas_link_training(struct isci_phy *iphy)
Dan Williams23506a62011-05-12 04:27:29 -0700554{
Dan Williams89a73012011-06-30 19:14:33 -0700555 /* continue the link training for the phy as if it were a SAS PHY
556 * instead of a SATA PHY. This is done because the completion queue had a SAS
557 * PHY DETECTED event when the state machine was expecting a SATA PHY event.
558 */
Dan Williams23506a62011-05-12 04:27:29 -0700559 u32 phy_control;
560
Dan Williams89a73012011-06-30 19:14:33 -0700561 phy_control = readl(&iphy->link_layer_registers->phy_configuration);
Dan Williams23506a62011-05-12 04:27:29 -0700562 phy_control |= SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD);
563 writel(phy_control,
Dan Williams89a73012011-06-30 19:14:33 -0700564 &iphy->link_layer_registers->phy_configuration);
Dan Williams23506a62011-05-12 04:27:29 -0700565
Dan Williams85280952011-06-28 15:05:53 -0700566 sci_change_state(&iphy->sm, SCI_PHY_SUB_AWAIT_SAS_SPEED_EN);
Dan Williams23506a62011-05-12 04:27:29 -0700567
Dan Williams85280952011-06-28 15:05:53 -0700568 iphy->protocol = SCIC_SDS_PHY_PROTOCOL_SAS;
Dan Williams23506a62011-05-12 04:27:29 -0700569}
570
Dan Williams89a73012011-06-30 19:14:33 -0700571static void sci_phy_start_sata_link_training(struct isci_phy *iphy)
Dan Williams23506a62011-05-12 04:27:29 -0700572{
Dan Williams89a73012011-06-30 19:14:33 -0700573 /* This method continues the link training for the phy as if it were a SATA PHY
574 * instead of a SAS PHY. This is done because the completion queue had a SATA
575 * SPINUP HOLD event when the state machine was expecting a SAS PHY event. none
576 */
Dan Williams85280952011-06-28 15:05:53 -0700577 sci_change_state(&iphy->sm, SCI_PHY_SUB_AWAIT_SATA_POWER);
Dan Williams23506a62011-05-12 04:27:29 -0700578
Dan Williams85280952011-06-28 15:05:53 -0700579 iphy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
Dan Williams23506a62011-05-12 04:27:29 -0700580}
581
582/**
Dan Williams89a73012011-06-30 19:14:33 -0700583 * sci_phy_complete_link_training - perform processing common to
Dan Williams23506a62011-05-12 04:27:29 -0700584 * all protocols upon completion of link training.
585 * @sci_phy: This parameter specifies the phy object for which link training
586 * has completed.
587 * @max_link_rate: This parameter specifies the maximum link rate to be
588 * associated with this phy.
589 * @next_state: This parameter specifies the next state for the phy's starting
590 * sub-state machine.
591 *
592 */
Dan Williams89a73012011-06-30 19:14:33 -0700593static void sci_phy_complete_link_training(struct isci_phy *iphy,
594 enum sas_linkrate max_link_rate,
595 u32 next_state)
Dan Williams23506a62011-05-12 04:27:29 -0700596{
Dan Williams85280952011-06-28 15:05:53 -0700597 iphy->max_negotiated_speed = max_link_rate;
Dan Williams23506a62011-05-12 04:27:29 -0700598
Dan Williams85280952011-06-28 15:05:53 -0700599 sci_change_state(&iphy->sm, next_state);
Dan Williams23506a62011-05-12 04:27:29 -0700600}
601
Dan Williams89a73012011-06-30 19:14:33 -0700602enum sci_status sci_phy_event_handler(struct isci_phy *iphy, u32 event_code)
Dan Williams23506a62011-05-12 04:27:29 -0700603{
Dan Williams89a73012011-06-30 19:14:33 -0700604 enum sci_phy_states state = iphy->sm.current_state_id;
Dan Williams23506a62011-05-12 04:27:29 -0700605
606 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +0000607 case SCI_PHY_SUB_AWAIT_OSSP_EN:
Dan Williams23506a62011-05-12 04:27:29 -0700608 switch (scu_get_event_code(event_code)) {
609 case SCU_EVENT_SAS_PHY_DETECTED:
Dan Williams89a73012011-06-30 19:14:33 -0700610 sci_phy_start_sas_link_training(iphy);
Dan Williams85280952011-06-28 15:05:53 -0700611 iphy->is_in_link_training = true;
Dan Williams23506a62011-05-12 04:27:29 -0700612 break;
613 case SCU_EVENT_SATA_SPINUP_HOLD:
Dan Williams89a73012011-06-30 19:14:33 -0700614 sci_phy_start_sata_link_training(iphy);
Dan Williams85280952011-06-28 15:05:53 -0700615 iphy->is_in_link_training = true;
Dan Williams23506a62011-05-12 04:27:29 -0700616 break;
617 default:
Dan Williams85280952011-06-28 15:05:53 -0700618 dev_dbg(sciphy_to_dev(iphy),
Dan Williams23506a62011-05-12 04:27:29 -0700619 "%s: PHY starting substate machine received "
620 "unexpected event_code %x\n",
621 __func__,
622 event_code);
623 return SCI_FAILURE;
624 }
625 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000626 case SCI_PHY_SUB_AWAIT_SAS_SPEED_EN:
Dan Williams23506a62011-05-12 04:27:29 -0700627 switch (scu_get_event_code(event_code)) {
628 case SCU_EVENT_SAS_PHY_DETECTED:
629 /*
630 * Why is this being reported again by the controller?
631 * We would re-enter this state so just stay here */
632 break;
633 case SCU_EVENT_SAS_15:
634 case SCU_EVENT_SAS_15_SSC:
Dan Williams89a73012011-06-30 19:14:33 -0700635 sci_phy_complete_link_training(iphy, SAS_LINK_RATE_1_5_GBPS,
636 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:
Dan Williams89a73012011-06-30 19:14:33 -0700640 sci_phy_complete_link_training(iphy, SAS_LINK_RATE_3_0_GBPS,
641 SCI_PHY_SUB_AWAIT_IAF_UF);
Dan Williams23506a62011-05-12 04:27:29 -0700642 break;
643 case SCU_EVENT_SAS_60:
644 case SCU_EVENT_SAS_60_SSC:
Dan Williams89a73012011-06-30 19:14:33 -0700645 sci_phy_complete_link_training(iphy, SAS_LINK_RATE_6_0_GBPS,
646 SCI_PHY_SUB_AWAIT_IAF_UF);
Dan Williams23506a62011-05-12 04:27:29 -0700647 break;
648 case SCU_EVENT_SATA_SPINUP_HOLD:
649 /*
650 * We were doing SAS PHY link training and received a SATA PHY event
651 * continue OOB/SN as if this were a SATA PHY */
Dan Williams89a73012011-06-30 19:14:33 -0700652 sci_phy_start_sata_link_training(iphy);
Dan Williams23506a62011-05-12 04:27:29 -0700653 break;
654 case SCU_EVENT_LINK_FAILURE:
655 /* Link failure change state back to the starting state */
Dan Williams85280952011-06-28 15:05:53 -0700656 sci_change_state(&iphy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700657 break;
658 default:
Dan Williams85280952011-06-28 15:05:53 -0700659 dev_warn(sciphy_to_dev(iphy),
Dan Williams23506a62011-05-12 04:27:29 -0700660 "%s: PHY starting substate machine received "
661 "unexpected event_code %x\n",
662 __func__, event_code);
663
664 return SCI_FAILURE;
665 break;
666 }
667 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000668 case SCI_PHY_SUB_AWAIT_IAF_UF:
Dan Williams23506a62011-05-12 04:27:29 -0700669 switch (scu_get_event_code(event_code)) {
670 case SCU_EVENT_SAS_PHY_DETECTED:
671 /* Backup the state machine */
Dan Williams89a73012011-06-30 19:14:33 -0700672 sci_phy_start_sas_link_training(iphy);
Dan Williams23506a62011-05-12 04:27:29 -0700673 break;
674 case SCU_EVENT_SATA_SPINUP_HOLD:
675 /* We were doing SAS PHY link training and received a
676 * SATA PHY event continue OOB/SN as if this were a
677 * SATA PHY
678 */
Dan Williams89a73012011-06-30 19:14:33 -0700679 sci_phy_start_sata_link_training(iphy);
Dan Williams23506a62011-05-12 04:27:29 -0700680 break;
681 case SCU_EVENT_RECEIVED_IDENTIFY_TIMEOUT:
682 case SCU_EVENT_LINK_FAILURE:
683 case SCU_EVENT_HARD_RESET_RECEIVED:
684 /* Start the oob/sn state machine over again */
Dan Williams85280952011-06-28 15:05:53 -0700685 sci_change_state(&iphy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700686 break;
687 default:
Dan Williams85280952011-06-28 15:05:53 -0700688 dev_warn(sciphy_to_dev(iphy),
Dan Williams23506a62011-05-12 04:27:29 -0700689 "%s: PHY starting substate machine received "
690 "unexpected event_code %x\n",
691 __func__, event_code);
692 return SCI_FAILURE;
693 }
694 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000695 case SCI_PHY_SUB_AWAIT_SAS_POWER:
Dan Williams23506a62011-05-12 04:27:29 -0700696 switch (scu_get_event_code(event_code)) {
697 case SCU_EVENT_LINK_FAILURE:
698 /* Link failure change state back to the starting state */
Dan Williams85280952011-06-28 15:05:53 -0700699 sci_change_state(&iphy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700700 break;
701 default:
Dan Williams85280952011-06-28 15:05:53 -0700702 dev_warn(sciphy_to_dev(iphy),
Dan Williams23506a62011-05-12 04:27:29 -0700703 "%s: PHY starting substate machine received unexpected "
704 "event_code %x\n",
705 __func__,
706 event_code);
707 return SCI_FAILURE;
708 }
709 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000710 case SCI_PHY_SUB_AWAIT_SATA_POWER:
Dan Williams23506a62011-05-12 04:27:29 -0700711 switch (scu_get_event_code(event_code)) {
712 case SCU_EVENT_LINK_FAILURE:
713 /* Link failure change state back to the starting state */
Dan Williams85280952011-06-28 15:05:53 -0700714 sci_change_state(&iphy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700715 break;
716 case SCU_EVENT_SATA_SPINUP_HOLD:
717 /* These events are received every 10ms and are
718 * expected while in this state
719 */
720 break;
721
722 case SCU_EVENT_SAS_PHY_DETECTED:
723 /* There has been a change in the phy type before OOB/SN for the
724 * SATA finished start down the SAS link traning path.
725 */
Dan Williams89a73012011-06-30 19:14:33 -0700726 sci_phy_start_sas_link_training(iphy);
Dan Williams23506a62011-05-12 04:27:29 -0700727 break;
728
729 default:
Dan Williams85280952011-06-28 15:05:53 -0700730 dev_warn(sciphy_to_dev(iphy),
Dan Williams23506a62011-05-12 04:27:29 -0700731 "%s: PHY starting substate machine received "
732 "unexpected event_code %x\n",
733 __func__, event_code);
734
735 return SCI_FAILURE;
736 }
737 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000738 case SCI_PHY_SUB_AWAIT_SATA_PHY_EN:
Dan Williams23506a62011-05-12 04:27:29 -0700739 switch (scu_get_event_code(event_code)) {
740 case SCU_EVENT_LINK_FAILURE:
741 /* Link failure change state back to the starting state */
Dan Williams85280952011-06-28 15:05:53 -0700742 sci_change_state(&iphy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700743 break;
744 case SCU_EVENT_SATA_SPINUP_HOLD:
745 /* These events might be received since we dont know how many may be in
746 * the completion queue while waiting for power
747 */
748 break;
749 case SCU_EVENT_SATA_PHY_DETECTED:
Dan Williams85280952011-06-28 15:05:53 -0700750 iphy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
Dan Williams23506a62011-05-12 04:27:29 -0700751
752 /* We have received the SATA PHY notification change state */
Dan Williams85280952011-06-28 15:05:53 -0700753 sci_change_state(&iphy->sm, SCI_PHY_SUB_AWAIT_SATA_SPEED_EN);
Dan Williams23506a62011-05-12 04:27:29 -0700754 break;
755 case SCU_EVENT_SAS_PHY_DETECTED:
756 /* There has been a change in the phy type before OOB/SN for the
757 * SATA finished start down the SAS link traning path.
758 */
Dan Williams89a73012011-06-30 19:14:33 -0700759 sci_phy_start_sas_link_training(iphy);
Dan Williams23506a62011-05-12 04:27:29 -0700760 break;
761 default:
Dan Williams85280952011-06-28 15:05:53 -0700762 dev_warn(sciphy_to_dev(iphy),
Dan Williams23506a62011-05-12 04:27:29 -0700763 "%s: PHY starting substate machine received "
764 "unexpected event_code %x\n",
765 __func__,
766 event_code);
767
Justin P. Mattock69932482011-07-26 23:06:29 -0700768 return SCI_FAILURE;
Dan Williams23506a62011-05-12 04:27:29 -0700769 }
770 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000771 case SCI_PHY_SUB_AWAIT_SATA_SPEED_EN:
Dan Williams23506a62011-05-12 04:27:29 -0700772 switch (scu_get_event_code(event_code)) {
773 case SCU_EVENT_SATA_PHY_DETECTED:
774 /*
775 * The hardware reports multiple SATA PHY detected events
776 * ignore the extras */
777 break;
778 case SCU_EVENT_SATA_15:
779 case SCU_EVENT_SATA_15_SSC:
Dan Williams89a73012011-06-30 19:14:33 -0700780 sci_phy_complete_link_training(iphy, SAS_LINK_RATE_1_5_GBPS,
781 SCI_PHY_SUB_AWAIT_SIG_FIS_UF);
Dan Williams23506a62011-05-12 04:27:29 -0700782 break;
783 case SCU_EVENT_SATA_30:
784 case SCU_EVENT_SATA_30_SSC:
Dan Williams89a73012011-06-30 19:14:33 -0700785 sci_phy_complete_link_training(iphy, SAS_LINK_RATE_3_0_GBPS,
786 SCI_PHY_SUB_AWAIT_SIG_FIS_UF);
Dan Williams23506a62011-05-12 04:27:29 -0700787 break;
788 case SCU_EVENT_SATA_60:
789 case SCU_EVENT_SATA_60_SSC:
Dan Williams89a73012011-06-30 19:14:33 -0700790 sci_phy_complete_link_training(iphy, SAS_LINK_RATE_6_0_GBPS,
791 SCI_PHY_SUB_AWAIT_SIG_FIS_UF);
Dan Williams23506a62011-05-12 04:27:29 -0700792 break;
793 case SCU_EVENT_LINK_FAILURE:
794 /* Link failure change state back to the starting state */
Dan Williams85280952011-06-28 15:05:53 -0700795 sci_change_state(&iphy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700796 break;
797 case SCU_EVENT_SAS_PHY_DETECTED:
798 /*
799 * There has been a change in the phy type before OOB/SN for the
800 * SATA finished start down the SAS link traning path. */
Dan Williams89a73012011-06-30 19:14:33 -0700801 sci_phy_start_sas_link_training(iphy);
Dan Williams23506a62011-05-12 04:27:29 -0700802 break;
803 default:
Dan Williams85280952011-06-28 15:05:53 -0700804 dev_warn(sciphy_to_dev(iphy),
Dan Williams23506a62011-05-12 04:27:29 -0700805 "%s: PHY starting substate machine received "
806 "unexpected event_code %x\n",
807 __func__, event_code);
808
809 return SCI_FAILURE;
810 }
811
812 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000813 case SCI_PHY_SUB_AWAIT_SIG_FIS_UF:
Dan Williams23506a62011-05-12 04:27:29 -0700814 switch (scu_get_event_code(event_code)) {
815 case SCU_EVENT_SATA_PHY_DETECTED:
816 /* Backup the state machine */
Dan Williams85280952011-06-28 15:05:53 -0700817 sci_change_state(&iphy->sm, SCI_PHY_SUB_AWAIT_SATA_SPEED_EN);
Dan Williams23506a62011-05-12 04:27:29 -0700818 break;
819
820 case SCU_EVENT_LINK_FAILURE:
821 /* Link failure change state back to the starting state */
Dan Williams85280952011-06-28 15:05:53 -0700822 sci_change_state(&iphy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700823 break;
824
825 default:
Dan Williams85280952011-06-28 15:05:53 -0700826 dev_warn(sciphy_to_dev(iphy),
Dan Williams23506a62011-05-12 04:27:29 -0700827 "%s: PHY starting substate machine received "
828 "unexpected event_code %x\n",
829 __func__,
830 event_code);
831
832 return SCI_FAILURE;
833 }
834 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000835 case SCI_PHY_READY:
Dan Williams23506a62011-05-12 04:27:29 -0700836 switch (scu_get_event_code(event_code)) {
837 case SCU_EVENT_LINK_FAILURE:
838 /* Link failure change state back to the starting state */
Dan Williams85280952011-06-28 15:05:53 -0700839 sci_change_state(&iphy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700840 break;
841 case SCU_EVENT_BROADCAST_CHANGE:
842 /* Broadcast change received. Notify the port. */
Dan Williams85280952011-06-28 15:05:53 -0700843 if (phy_get_non_dummy_port(iphy) != NULL)
Dan Williams89a73012011-06-30 19:14:33 -0700844 sci_port_broadcast_change_received(iphy->owning_port, iphy);
Dan Williams23506a62011-05-12 04:27:29 -0700845 else
Dan Williams85280952011-06-28 15:05:53 -0700846 iphy->bcn_received_while_port_unassigned = true;
Dan Williams23506a62011-05-12 04:27:29 -0700847 break;
848 default:
Dan Williams85280952011-06-28 15:05:53 -0700849 dev_warn(sciphy_to_dev(iphy),
Dan Williams23506a62011-05-12 04:27:29 -0700850 "%sP SCIC PHY 0x%p ready state machine received "
851 "unexpected event_code %x\n",
Dan Williams85280952011-06-28 15:05:53 -0700852 __func__, iphy, event_code);
Dan Williams23506a62011-05-12 04:27:29 -0700853 return SCI_FAILURE_INVALID_STATE;
854 }
855 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000856 case SCI_PHY_RESETTING:
Dan Williams23506a62011-05-12 04:27:29 -0700857 switch (scu_get_event_code(event_code)) {
858 case SCU_EVENT_HARD_RESET_TRANSMITTED:
859 /* Link failure change state back to the starting state */
Dan Williams85280952011-06-28 15:05:53 -0700860 sci_change_state(&iphy->sm, SCI_PHY_STARTING);
Dan Williams23506a62011-05-12 04:27:29 -0700861 break;
862 default:
Dan Williams85280952011-06-28 15:05:53 -0700863 dev_warn(sciphy_to_dev(iphy),
Dan Williams23506a62011-05-12 04:27:29 -0700864 "%s: SCIC PHY 0x%p resetting state machine received "
865 "unexpected event_code %x\n",
Dan Williams85280952011-06-28 15:05:53 -0700866 __func__, iphy, event_code);
Dan Williams23506a62011-05-12 04:27:29 -0700867
868 return SCI_FAILURE_INVALID_STATE;
869 break;
870 }
871 return SCI_SUCCESS;
872 default:
Dan Williams85280952011-06-28 15:05:53 -0700873 dev_dbg(sciphy_to_dev(iphy),
Dan Williams23506a62011-05-12 04:27:29 -0700874 "%s: in wrong state: %d\n", __func__, state);
875 return SCI_FAILURE_INVALID_STATE;
876 }
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700877}
878
Dan Williams89a73012011-06-30 19:14:33 -0700879enum sci_status sci_phy_frame_handler(struct isci_phy *iphy, u32 frame_index)
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700880{
Dan Williams89a73012011-06-30 19:14:33 -0700881 enum sci_phy_states state = iphy->sm.current_state_id;
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700882 struct isci_host *ihost = iphy->owning_port->owning_controller;
Dan Williamsc4441ab2011-05-12 04:17:51 -0700883 enum sci_status result;
Dan Williams4cffe132011-06-23 23:44:52 -0700884 unsigned long flags;
Dan Williamsc4441ab2011-05-12 04:17:51 -0700885
886 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +0000887 case SCI_PHY_SUB_AWAIT_IAF_UF: {
Dan Williamsc4441ab2011-05-12 04:17:51 -0700888 u32 *frame_words;
889 struct sas_identify_frame iaf;
Dan Williamsc4441ab2011-05-12 04:17:51 -0700890
Dan Williams89a73012011-06-30 19:14:33 -0700891 result = sci_unsolicited_frame_control_get_header(&ihost->uf_control,
892 frame_index,
893 (void **)&frame_words);
Dan Williamsc4441ab2011-05-12 04:17:51 -0700894
895 if (result != SCI_SUCCESS)
896 return result;
897
898 sci_swab32_cpy(&iaf, frame_words, sizeof(iaf) / sizeof(u32));
899 if (iaf.frame_type == 0) {
900 u32 state;
901
Dan Williams4cffe132011-06-23 23:44:52 -0700902 spin_lock_irqsave(&iphy->sas_phy.frame_rcvd_lock, flags);
Dan Williamsc4441ab2011-05-12 04:17:51 -0700903 memcpy(&iphy->frame_rcvd.iaf, &iaf, sizeof(iaf));
Dan Williams4cffe132011-06-23 23:44:52 -0700904 spin_unlock_irqrestore(&iphy->sas_phy.frame_rcvd_lock, flags);
Dan Williamsc4441ab2011-05-12 04:17:51 -0700905 if (iaf.smp_tport) {
906 /* We got the IAF for an expander PHY go to the final
907 * state since there are no power requirements for
908 * expander phys.
909 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000910 state = SCI_PHY_SUB_FINAL;
Dan Williamsc4441ab2011-05-12 04:17:51 -0700911 } else {
912 /* We got the IAF we can now go to the await spinup
913 * semaphore state
914 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000915 state = SCI_PHY_SUB_AWAIT_SAS_POWER;
Dan Williamsc4441ab2011-05-12 04:17:51 -0700916 }
Dan Williams85280952011-06-28 15:05:53 -0700917 sci_change_state(&iphy->sm, state);
Dan Williamsc4441ab2011-05-12 04:17:51 -0700918 result = SCI_SUCCESS;
919 } else
Dan Williams85280952011-06-28 15:05:53 -0700920 dev_warn(sciphy_to_dev(iphy),
Dan Williamsc4441ab2011-05-12 04:17:51 -0700921 "%s: PHY starting substate machine received "
922 "unexpected frame id %x\n",
923 __func__, frame_index);
924
Dan Williams89a73012011-06-30 19:14:33 -0700925 sci_controller_release_frame(ihost, frame_index);
Dan Williamsc4441ab2011-05-12 04:17:51 -0700926 return result;
927 }
Edmund Nadolskie3013702011-06-02 00:10:43 +0000928 case SCI_PHY_SUB_AWAIT_SIG_FIS_UF: {
Dan Williamsc4441ab2011-05-12 04:17:51 -0700929 struct dev_to_host_fis *frame_header;
930 u32 *fis_frame_data;
Dan Williamsc4441ab2011-05-12 04:17:51 -0700931
Dan Williams34a99152011-07-01 02:25:15 -0700932 result = sci_unsolicited_frame_control_get_header(&ihost->uf_control,
933 frame_index,
934 (void **)&frame_header);
Dan Williamsc4441ab2011-05-12 04:17:51 -0700935
936 if (result != SCI_SUCCESS)
937 return result;
938
939 if ((frame_header->fis_type == FIS_REGD2H) &&
940 !(frame_header->status & ATA_BUSY)) {
Dan Williams89a73012011-06-30 19:14:33 -0700941 sci_unsolicited_frame_control_get_buffer(&ihost->uf_control,
942 frame_index,
943 (void **)&fis_frame_data);
Dan Williamsc4441ab2011-05-12 04:17:51 -0700944
Dan Williams4cffe132011-06-23 23:44:52 -0700945 spin_lock_irqsave(&iphy->sas_phy.frame_rcvd_lock, flags);
Dan Williams89a73012011-06-30 19:14:33 -0700946 sci_controller_copy_sata_response(&iphy->frame_rcvd.fis,
947 frame_header,
948 fis_frame_data);
Dan Williams4cffe132011-06-23 23:44:52 -0700949 spin_unlock_irqrestore(&iphy->sas_phy.frame_rcvd_lock, flags);
Dan Williamsc4441ab2011-05-12 04:17:51 -0700950
951 /* got IAF we can now go to the await spinup semaphore state */
Dan Williams85280952011-06-28 15:05:53 -0700952 sci_change_state(&iphy->sm, SCI_PHY_SUB_FINAL);
Dan Williamsc4441ab2011-05-12 04:17:51 -0700953
954 result = SCI_SUCCESS;
955 } else
Dan Williams85280952011-06-28 15:05:53 -0700956 dev_warn(sciphy_to_dev(iphy),
Dan Williamsc4441ab2011-05-12 04:17:51 -0700957 "%s: PHY starting substate machine received "
958 "unexpected frame id %x\n",
959 __func__, frame_index);
960
961 /* Regardless of the result we are done with this frame with it */
Dan Williams89a73012011-06-30 19:14:33 -0700962 sci_controller_release_frame(ihost, frame_index);
Dan Williamsc4441ab2011-05-12 04:17:51 -0700963
964 return result;
965 }
966 default:
Dan Williams85280952011-06-28 15:05:53 -0700967 dev_dbg(sciphy_to_dev(iphy),
Dan Williamsc4441ab2011-05-12 04:17:51 -0700968 "%s: in wrong state: %d\n", __func__, state);
969 return SCI_FAILURE_INVALID_STATE;
970 }
Dan Williams5076a1a2011-06-27 14:57:03 -0700971
Dan Williamsd35bc1b2011-05-10 02:28:45 -0700972}
973
Dan Williams89a73012011-06-30 19:14:33 -0700974static void sci_phy_starting_initial_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +0000975{
Dan Williams85280952011-06-28 15:05:53 -0700976 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +0000977
Adam Gruchala4a33c522011-05-10 23:54:23 +0000978 /* This is just an temporary state go off to the starting state */
Dan Williams85280952011-06-28 15:05:53 -0700979 sci_change_state(&iphy->sm, SCI_PHY_SUB_AWAIT_OSSP_EN);
Adam Gruchala4a33c522011-05-10 23:54:23 +0000980}
981
Dan Williams89a73012011-06-30 19:14:33 -0700982static void sci_phy_starting_await_sas_power_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +0000983{
Dan Williams85280952011-06-28 15:05:53 -0700984 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700985 struct isci_host *ihost = iphy->owning_port->owning_controller;
Adam Gruchala4a33c522011-05-10 23:54:23 +0000986
Dan Williams89a73012011-06-30 19:14:33 -0700987 sci_controller_power_control_queue_insert(ihost, iphy);
Adam Gruchala4a33c522011-05-10 23:54:23 +0000988}
989
Dan Williams89a73012011-06-30 19:14:33 -0700990static void sci_phy_starting_await_sas_power_substate_exit(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +0000991{
Dan Williams85280952011-06-28 15:05:53 -0700992 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700993 struct isci_host *ihost = iphy->owning_port->owning_controller;
Adam Gruchala4a33c522011-05-10 23:54:23 +0000994
Dan Williams89a73012011-06-30 19:14:33 -0700995 sci_controller_power_control_queue_remove(ihost, iphy);
Adam Gruchala4a33c522011-05-10 23:54:23 +0000996}
997
Dan Williams89a73012011-06-30 19:14:33 -0700998static void sci_phy_starting_await_sata_power_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +0000999{
Dan Williams85280952011-06-28 15:05:53 -07001000 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Dan Williamsd9dcb4b2011-06-30 17:38:32 -07001001 struct isci_host *ihost = iphy->owning_port->owning_controller;
Adam Gruchala4a33c522011-05-10 23:54:23 +00001002
Dan Williams89a73012011-06-30 19:14:33 -07001003 sci_controller_power_control_queue_insert(ihost, iphy);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001004}
1005
Dan Williams89a73012011-06-30 19:14:33 -07001006static void sci_phy_starting_await_sata_power_substate_exit(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001007{
Dan Williams85280952011-06-28 15:05:53 -07001008 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Dan Williamsd9dcb4b2011-06-30 17:38:32 -07001009 struct isci_host *ihost = iphy->owning_port->owning_controller;
Adam Gruchala4a33c522011-05-10 23:54:23 +00001010
Dan Williams89a73012011-06-30 19:14:33 -07001011 sci_controller_power_control_queue_remove(ihost, iphy);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001012}
1013
Dan Williams89a73012011-06-30 19:14:33 -07001014static void sci_phy_starting_await_sata_phy_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001015{
Dan Williams85280952011-06-28 15:05:53 -07001016 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001017
Dan Williams85280952011-06-28 15:05:53 -07001018 sci_mod_timer(&iphy->sata_timer, SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001019}
1020
Dan Williams89a73012011-06-30 19:14:33 -07001021static void sci_phy_starting_await_sata_phy_substate_exit(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001022{
Dan Williams85280952011-06-28 15:05:53 -07001023 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001024
Dan Williams85280952011-06-28 15:05:53 -07001025 sci_del_timer(&iphy->sata_timer);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001026}
1027
Dan Williams89a73012011-06-30 19:14:33 -07001028static void sci_phy_starting_await_sata_speed_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001029{
Dan Williams85280952011-06-28 15:05:53 -07001030 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001031
Dan Williams85280952011-06-28 15:05:53 -07001032 sci_mod_timer(&iphy->sata_timer, SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001033}
1034
Dan Williams89a73012011-06-30 19:14:33 -07001035static void sci_phy_starting_await_sata_speed_substate_exit(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001036{
Dan Williams85280952011-06-28 15:05:53 -07001037 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001038
Dan Williams85280952011-06-28 15:05:53 -07001039 sci_del_timer(&iphy->sata_timer);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001040}
1041
Dan Williams89a73012011-06-30 19:14:33 -07001042static void sci_phy_starting_await_sig_fis_uf_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001043{
Dan Williams85280952011-06-28 15:05:53 -07001044 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001045
Dan Williams89a73012011-06-30 19:14:33 -07001046 if (sci_port_link_detected(iphy->owning_port, iphy)) {
Adam Gruchala4a33c522011-05-10 23:54:23 +00001047
Adam Gruchala4a33c522011-05-10 23:54:23 +00001048 /*
1049 * Clear the PE suspend condition so we can actually
1050 * receive SIG FIS
1051 * The hardware will not respond to the XRDY until the PE
1052 * suspend condition is cleared.
1053 */
Dan Williams89a73012011-06-30 19:14:33 -07001054 sci_phy_resume(iphy);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001055
Dan Williams85280952011-06-28 15:05:53 -07001056 sci_mod_timer(&iphy->sata_timer,
Edmund Nadolskia628d472011-05-19 11:59:36 +00001057 SCIC_SDS_SIGNATURE_FIS_TIMEOUT);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001058 } else
Dan Williams85280952011-06-28 15:05:53 -07001059 iphy->is_in_link_training = false;
Adam Gruchala4a33c522011-05-10 23:54:23 +00001060}
1061
Dan Williams89a73012011-06-30 19:14:33 -07001062static void sci_phy_starting_await_sig_fis_uf_substate_exit(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001063{
Dan Williams85280952011-06-28 15:05:53 -07001064 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001065
Dan Williams85280952011-06-28 15:05:53 -07001066 sci_del_timer(&iphy->sata_timer);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001067}
1068
Dan Williams89a73012011-06-30 19:14:33 -07001069static void sci_phy_starting_final_substate_enter(struct sci_base_state_machine *sm)
Adam Gruchala4a33c522011-05-10 23:54:23 +00001070{
Dan Williams85280952011-06-28 15:05:53 -07001071 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001072
Adam Gruchala4a33c522011-05-10 23:54:23 +00001073 /* State machine has run to completion so exit out and change
1074 * the base state machine to the ready state
1075 */
Dan Williams85280952011-06-28 15:05:53 -07001076 sci_change_state(&iphy->sm, SCI_PHY_READY);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001077}
1078
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001079/**
1080 *
Dan Williams85280952011-06-28 15:05:53 -07001081 * @sci_phy: This is the struct isci_phy object to stop.
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001082 *
Dan Williams85280952011-06-28 15:05:53 -07001083 * This method will stop the struct isci_phy object. This does not reset the
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001084 * protocol engine it just suspends it and places it in a state where it will
1085 * not cause the end device to power up. none
1086 */
1087static void scu_link_layer_stop_protocol_engine(
Dan Williams85280952011-06-28 15:05:53 -07001088 struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001089{
1090 u32 scu_sas_pcfg_value;
1091 u32 enable_spinup_value;
1092
1093 /* Suspend the protocol engine and place it in a sata spinup hold state */
1094 scu_sas_pcfg_value =
Dan Williams85280952011-06-28 15:05:53 -07001095 readl(&iphy->link_layer_registers->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001096 scu_sas_pcfg_value |=
1097 (SCU_SAS_PCFG_GEN_BIT(OOB_RESET) |
1098 SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE) |
1099 SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD));
1100 writel(scu_sas_pcfg_value,
Dan Williams85280952011-06-28 15:05:53 -07001101 &iphy->link_layer_registers->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001102
1103 /* Disable the notify enable spinup primitives */
Dan Williams85280952011-06-28 15:05:53 -07001104 enable_spinup_value = readl(&iphy->link_layer_registers->notify_enable_spinup_control);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001105 enable_spinup_value &= ~SCU_ENSPINUP_GEN_BIT(ENABLE);
Dan Williams85280952011-06-28 15:05:53 -07001106 writel(enable_spinup_value, &iphy->link_layer_registers->notify_enable_spinup_control);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001107}
1108
Marcin Tomczak0953dbe2012-01-04 01:33:36 -08001109static void scu_link_layer_start_oob(struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001110{
Marcin Tomczak0953dbe2012-01-04 01:33:36 -08001111 struct scu_link_layer_registers __iomem *ll = iphy->link_layer_registers;
1112 u32 val;
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001113
Marcin Tomczak0953dbe2012-01-04 01:33:36 -08001114 /** Reset OOB sequence - start */
1115 val = readl(&ll->phy_configuration);
1116 val &= ~(SCU_SAS_PCFG_GEN_BIT(OOB_RESET) |
1117 SCU_SAS_PCFG_GEN_BIT(HARD_RESET));
1118 writel(val, &ll->phy_configuration);
1119 readl(&ll->phy_configuration); /* flush */
1120 /** Reset OOB sequence - end */
1121
1122 /** Start OOB sequence - start */
1123 val = readl(&ll->phy_configuration);
1124 val |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
1125 writel(val, &ll->phy_configuration);
1126 readl(&ll->phy_configuration); /* flush */
1127 /** Start OOB sequence - end */
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001128}
1129
1130/**
1131 *
1132 *
1133 * This method will transmit a hard reset request on the specified phy. The SCU
1134 * hardware requires that we reset the OOB state machine and set the hard reset
1135 * bit in the phy configuration register. We then must start OOB over with the
1136 * hard reset bit set.
1137 */
1138static void scu_link_layer_tx_hard_reset(
Dan Williams85280952011-06-28 15:05:53 -07001139 struct isci_phy *iphy)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001140{
1141 u32 phy_configuration_value;
1142
1143 /*
1144 * SAS Phys must wait for the HARD_RESET_TX event notification to transition
1145 * to the starting state. */
1146 phy_configuration_value =
Dan Williams85280952011-06-28 15:05:53 -07001147 readl(&iphy->link_layer_registers->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001148 phy_configuration_value |=
1149 (SCU_SAS_PCFG_GEN_BIT(HARD_RESET) |
1150 SCU_SAS_PCFG_GEN_BIT(OOB_RESET));
1151 writel(phy_configuration_value,
Dan Williams85280952011-06-28 15:05:53 -07001152 &iphy->link_layer_registers->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001153
1154 /* Now take the OOB state machine out of reset */
1155 phy_configuration_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
1156 phy_configuration_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
1157 writel(phy_configuration_value,
Dan Williams85280952011-06-28 15:05:53 -07001158 &iphy->link_layer_registers->phy_configuration);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001159}
1160
Dan Williams89a73012011-06-30 19:14:33 -07001161static void sci_phy_stopped_state_enter(struct sci_base_state_machine *sm)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001162{
Dan Williams85280952011-06-28 15:05:53 -07001163 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Dan Williams34a99152011-07-01 02:25:15 -07001164 struct isci_port *iport = iphy->owning_port;
1165 struct isci_host *ihost = iport->owning_controller;
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001166
1167 /*
1168 * @todo We need to get to the controller to place this PE in a
1169 * reset state
1170 */
Dan Williams85280952011-06-28 15:05:53 -07001171 sci_del_timer(&iphy->sata_timer);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001172
Dan Williams85280952011-06-28 15:05:53 -07001173 scu_link_layer_stop_protocol_engine(iphy);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001174
Dan Williams85280952011-06-28 15:05:53 -07001175 if (iphy->sm.previous_state_id != SCI_PHY_INITIAL)
Dan Williams34a99152011-07-01 02:25:15 -07001176 sci_controller_link_down(ihost, phy_get_non_dummy_port(iphy), iphy);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001177}
1178
Dan Williams89a73012011-06-30 19:14:33 -07001179static void sci_phy_starting_state_enter(struct sci_base_state_machine *sm)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001180{
Dan Williams85280952011-06-28 15:05:53 -07001181 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Dan Williams34a99152011-07-01 02:25:15 -07001182 struct isci_port *iport = iphy->owning_port;
1183 struct isci_host *ihost = iport->owning_controller;
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001184
Dan Williams85280952011-06-28 15:05:53 -07001185 scu_link_layer_stop_protocol_engine(iphy);
1186 scu_link_layer_start_oob(iphy);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001187
1188 /* We don't know what kind of phy we are going to be just yet */
Dan Williams85280952011-06-28 15:05:53 -07001189 iphy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
1190 iphy->bcn_received_while_port_unassigned = false;
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001191
Dan Williams85280952011-06-28 15:05:53 -07001192 if (iphy->sm.previous_state_id == SCI_PHY_READY)
Dan Williams34a99152011-07-01 02:25:15 -07001193 sci_controller_link_down(ihost, phy_get_non_dummy_port(iphy), iphy);
Adam Gruchala4a33c522011-05-10 23:54:23 +00001194
Dan Williams85280952011-06-28 15:05:53 -07001195 sci_change_state(&iphy->sm, SCI_PHY_SUB_INITIAL);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001196}
1197
Dan Williams89a73012011-06-30 19:14:33 -07001198static void sci_phy_ready_state_enter(struct sci_base_state_machine *sm)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001199{
Dan Williams85280952011-06-28 15:05:53 -07001200 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Dan Williams34a99152011-07-01 02:25:15 -07001201 struct isci_port *iport = iphy->owning_port;
1202 struct isci_host *ihost = iport->owning_controller;
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001203
Dan Williams34a99152011-07-01 02:25:15 -07001204 sci_controller_link_up(ihost, phy_get_non_dummy_port(iphy), iphy);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001205}
1206
Dan Williams89a73012011-06-30 19:14:33 -07001207static void sci_phy_ready_state_exit(struct sci_base_state_machine *sm)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001208{
Dan Williams85280952011-06-28 15:05:53 -07001209 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001210
Dan Williams89a73012011-06-30 19:14:33 -07001211 sci_phy_suspend(iphy);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001212}
1213
Dan Williams89a73012011-06-30 19:14:33 -07001214static void sci_phy_resetting_state_enter(struct sci_base_state_machine *sm)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001215{
Dan Williams85280952011-06-28 15:05:53 -07001216 struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001217
Dan Williams5b1d4af2011-05-12 04:51:41 -07001218 /* The phy is being reset, therefore deactivate it from the port. In
1219 * the resetting state we don't notify the user regarding link up and
1220 * link down notifications
1221 */
Dan Williams89a73012011-06-30 19:14:33 -07001222 sci_port_deactivate_phy(iphy->owning_port, iphy, false);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001223
Dan Williams85280952011-06-28 15:05:53 -07001224 if (iphy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
1225 scu_link_layer_tx_hard_reset(iphy);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001226 } else {
Dan Williams5b1d4af2011-05-12 04:51:41 -07001227 /* The SCU does not need to have a discrete reset state so
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001228 * just go back to the starting state.
1229 */
Dan Williams85280952011-06-28 15:05:53 -07001230 sci_change_state(&iphy->sm, SCI_PHY_STARTING);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001231 }
1232}
1233
Dan Williams89a73012011-06-30 19:14:33 -07001234static const struct sci_base_state sci_phy_state_table[] = {
Edmund Nadolskie3013702011-06-02 00:10:43 +00001235 [SCI_PHY_INITIAL] = { },
1236 [SCI_PHY_STOPPED] = {
Dan Williams89a73012011-06-30 19:14:33 -07001237 .enter_state = sci_phy_stopped_state_enter,
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001238 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001239 [SCI_PHY_STARTING] = {
Dan Williams89a73012011-06-30 19:14:33 -07001240 .enter_state = sci_phy_starting_state_enter,
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001241 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001242 [SCI_PHY_SUB_INITIAL] = {
Dan Williams89a73012011-06-30 19:14:33 -07001243 .enter_state = sci_phy_starting_initial_substate_enter,
Adam Gruchala4a33c522011-05-10 23:54:23 +00001244 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001245 [SCI_PHY_SUB_AWAIT_OSSP_EN] = { },
1246 [SCI_PHY_SUB_AWAIT_SAS_SPEED_EN] = { },
1247 [SCI_PHY_SUB_AWAIT_IAF_UF] = { },
1248 [SCI_PHY_SUB_AWAIT_SAS_POWER] = {
Dan Williams89a73012011-06-30 19:14:33 -07001249 .enter_state = sci_phy_starting_await_sas_power_substate_enter,
1250 .exit_state = sci_phy_starting_await_sas_power_substate_exit,
Adam Gruchala4a33c522011-05-10 23:54:23 +00001251 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001252 [SCI_PHY_SUB_AWAIT_SATA_POWER] = {
Dan Williams89a73012011-06-30 19:14:33 -07001253 .enter_state = sci_phy_starting_await_sata_power_substate_enter,
1254 .exit_state = sci_phy_starting_await_sata_power_substate_exit
Adam Gruchala4a33c522011-05-10 23:54:23 +00001255 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001256 [SCI_PHY_SUB_AWAIT_SATA_PHY_EN] = {
Dan Williams89a73012011-06-30 19:14:33 -07001257 .enter_state = sci_phy_starting_await_sata_phy_substate_enter,
1258 .exit_state = sci_phy_starting_await_sata_phy_substate_exit
Adam Gruchala4a33c522011-05-10 23:54:23 +00001259 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001260 [SCI_PHY_SUB_AWAIT_SATA_SPEED_EN] = {
Dan Williams89a73012011-06-30 19:14:33 -07001261 .enter_state = sci_phy_starting_await_sata_speed_substate_enter,
1262 .exit_state = sci_phy_starting_await_sata_speed_substate_exit
Adam Gruchala4a33c522011-05-10 23:54:23 +00001263 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001264 [SCI_PHY_SUB_AWAIT_SIG_FIS_UF] = {
Dan Williams89a73012011-06-30 19:14:33 -07001265 .enter_state = sci_phy_starting_await_sig_fis_uf_substate_enter,
1266 .exit_state = sci_phy_starting_await_sig_fis_uf_substate_exit
Adam Gruchala4a33c522011-05-10 23:54:23 +00001267 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001268 [SCI_PHY_SUB_FINAL] = {
Dan Williams89a73012011-06-30 19:14:33 -07001269 .enter_state = sci_phy_starting_final_substate_enter,
Adam Gruchala4a33c522011-05-10 23:54:23 +00001270 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001271 [SCI_PHY_READY] = {
Dan Williams89a73012011-06-30 19:14:33 -07001272 .enter_state = sci_phy_ready_state_enter,
1273 .exit_state = sci_phy_ready_state_exit,
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001274 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001275 [SCI_PHY_RESETTING] = {
Dan Williams89a73012011-06-30 19:14:33 -07001276 .enter_state = sci_phy_resetting_state_enter,
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001277 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001278 [SCI_PHY_FINAL] = { },
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001279};
1280
Dan Williams89a73012011-06-30 19:14:33 -07001281void sci_phy_construct(struct isci_phy *iphy,
Dan Williamsffe191c2011-06-29 13:09:25 -07001282 struct isci_port *iport, u8 phy_index)
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001283{
Dan Williams89a73012011-06-30 19:14:33 -07001284 sci_init_sm(&iphy->sm, sci_phy_state_table, SCI_PHY_INITIAL);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001285
1286 /* Copy the rest of the input data to our locals */
Dan Williamsffe191c2011-06-29 13:09:25 -07001287 iphy->owning_port = iport;
Dan Williams85280952011-06-28 15:05:53 -07001288 iphy->phy_index = phy_index;
1289 iphy->bcn_received_while_port_unassigned = false;
1290 iphy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
1291 iphy->link_layer_registers = NULL;
1292 iphy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
Edmund Nadolskia628d472011-05-19 11:59:36 +00001293
1294 /* Create the SIGNATURE FIS Timeout timer for this phy */
Dan Williams85280952011-06-28 15:05:53 -07001295 sci_init_timer(&iphy->sata_timer, phy_sata_timeout);
Dan Williamsd35bc1b2011-05-10 02:28:45 -07001296}
Dan Williams6f231dd2011-07-02 22:56:22 -07001297
Dan Williams4b339812011-05-06 17:36:38 -07001298void isci_phy_init(struct isci_phy *iphy, struct isci_host *ihost, int index)
Dan Williams6f231dd2011-07-02 22:56:22 -07001299{
Dan Williams89a73012011-06-30 19:14:33 -07001300 struct sci_oem_params *oem = &ihost->oem_parameters;
Dan Williams4b339812011-05-06 17:36:38 -07001301 u64 sci_sas_addr;
1302 __be64 sas_addr;
Dan Williams6f231dd2011-07-02 22:56:22 -07001303
Dan Williams89a73012011-06-30 19:14:33 -07001304 sci_sas_addr = oem->phys[index].sas_address.high;
Dan Williams4b339812011-05-06 17:36:38 -07001305 sci_sas_addr <<= 32;
Dan Williams89a73012011-06-30 19:14:33 -07001306 sci_sas_addr |= oem->phys[index].sas_address.low;
Dan Williams4b339812011-05-06 17:36:38 -07001307 sas_addr = cpu_to_be64(sci_sas_addr);
1308 memcpy(iphy->sas_addr, &sas_addr, sizeof(sas_addr));
Dan Williams6f231dd2011-07-02 22:56:22 -07001309
Dan Williams4b339812011-05-06 17:36:38 -07001310 iphy->sas_phy.enabled = 0;
1311 iphy->sas_phy.id = index;
1312 iphy->sas_phy.sas_addr = &iphy->sas_addr[0];
1313 iphy->sas_phy.frame_rcvd = (u8 *)&iphy->frame_rcvd;
1314 iphy->sas_phy.ha = &ihost->sas_ha;
1315 iphy->sas_phy.lldd_phy = iphy;
1316 iphy->sas_phy.enabled = 1;
1317 iphy->sas_phy.class = SAS;
1318 iphy->sas_phy.iproto = SAS_PROTOCOL_ALL;
1319 iphy->sas_phy.tproto = 0;
1320 iphy->sas_phy.type = PHY_TYPE_PHYSICAL;
1321 iphy->sas_phy.role = PHY_ROLE_INITIATOR;
1322 iphy->sas_phy.oob_mode = OOB_NOT_CONNECTED;
1323 iphy->sas_phy.linkrate = SAS_LINK_RATE_UNKNOWN;
1324 memset(&iphy->frame_rcvd, 0, sizeof(iphy->frame_rcvd));
Dan Williams6f231dd2011-07-02 22:56:22 -07001325}
1326
1327
1328/**
1329 * isci_phy_control() - This function is one of the SAS Domain Template
1330 * functions. This is a phy management function.
1331 * @phy: This parameter specifies the sphy being controlled.
1332 * @func: This parameter specifies the phy control function being invoked.
1333 * @buf: This parameter is specific to the phy function being invoked.
1334 *
1335 * status, zero indicates success.
1336 */
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001337int isci_phy_control(struct asd_sas_phy *sas_phy,
1338 enum phy_func func,
1339 void *buf)
Dan Williams6f231dd2011-07-02 22:56:22 -07001340{
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001341 int ret = 0;
1342 struct isci_phy *iphy = sas_phy->lldd_phy;
Dan Williamsc132f692012-01-03 23:26:08 -08001343 struct asd_sas_port *port = sas_phy->port;
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001344 struct isci_host *ihost = sas_phy->ha->lldd_ha;
1345 unsigned long flags;
Dan Williams6f231dd2011-07-02 22:56:22 -07001346
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001347 dev_dbg(&ihost->pdev->dev,
1348 "%s: phy %p; func %d; buf %p; isci phy %p, port %p\n",
Dan Williamsc132f692012-01-03 23:26:08 -08001349 __func__, sas_phy, func, buf, iphy, port);
Dan Williams6f231dd2011-07-02 22:56:22 -07001350
1351 switch (func) {
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001352 case PHY_FUNC_DISABLE:
1353 spin_lock_irqsave(&ihost->scic_lock, flags);
Dan Williams89a73012011-06-30 19:14:33 -07001354 sci_phy_stop(iphy);
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001355 spin_unlock_irqrestore(&ihost->scic_lock, flags);
1356 break;
1357
Dan Williams6f231dd2011-07-02 22:56:22 -07001358 case PHY_FUNC_LINK_RESET:
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001359 spin_lock_irqsave(&ihost->scic_lock, flags);
Dan Williams89a73012011-06-30 19:14:33 -07001360 sci_phy_stop(iphy);
1361 sci_phy_start(iphy);
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001362 spin_unlock_irqrestore(&ihost->scic_lock, flags);
1363 break;
1364
1365 case PHY_FUNC_HARD_RESET:
Dan Williamsc132f692012-01-03 23:26:08 -08001366 if (!port)
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001367 return -ENODEV;
Dan Williams6f231dd2011-07-02 22:56:22 -07001368
Dan Williamsc132f692012-01-03 23:26:08 -08001369 ret = isci_port_perform_hard_reset(ihost, port->lldd_port, iphy);
Dan Williams6f231dd2011-07-02 22:56:22 -07001370
1371 break;
Dan Williamsac013ed12011-09-28 18:48:02 -07001372 case PHY_FUNC_GET_EVENTS: {
1373 struct scu_link_layer_registers __iomem *r;
1374 struct sas_phy *phy = sas_phy->phy;
1375
1376 r = iphy->link_layer_registers;
1377 phy->running_disparity_error_count = readl(&r->running_disparity_error_count);
1378 phy->loss_of_dword_sync_count = readl(&r->loss_of_sync_error_count);
1379 phy->phy_reset_problem_count = readl(&r->phy_reset_problem_count);
1380 phy->invalid_dword_count = readl(&r->invalid_dword_counter);
1381 break;
1382 }
Dan Williams6f231dd2011-07-02 22:56:22 -07001383
Dan Williams6f231dd2011-07-02 22:56:22 -07001384 default:
Dave Jiang4d07f7f2011-03-02 12:31:24 -08001385 dev_dbg(&ihost->pdev->dev,
1386 "%s: phy %p; func %d NOT IMPLEMENTED!\n",
1387 __func__, sas_phy, func);
1388 ret = -ENOSYS;
Dan Williams6f231dd2011-07-02 22:56:22 -07001389 break;
1390 }
1391 return ret;
1392}