blob: 5f4a4e3954dba0084abd14e34a59680550e0f51c [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
Dan Williams6f231dd2011-07-02 22:56:22 -070056#include "isci.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070057#include "port.h"
58#include "request.h"
Dan Williamse2f8db52011-05-10 02:28:46 -070059
60#define SCIC_SDS_PORT_HARD_RESET_TIMEOUT (1000)
61#define SCU_DUMMY_INDEX (0xFFFF)
Dan Williams6f231dd2011-07-02 22:56:22 -070062
Dan Williamse5313812011-05-07 10:11:43 -070063static void isci_port_change_state(struct isci_port *iport, enum isci_status status)
64{
65 unsigned long flags;
Dan Williams6f231dd2011-07-02 22:56:22 -070066
Dan Williamse5313812011-05-07 10:11:43 -070067 dev_dbg(&iport->isci_host->pdev->dev,
68 "%s: iport = %p, state = 0x%x\n",
69 __func__, iport, status);
Dan Williams6f231dd2011-07-02 22:56:22 -070070
Dan Williamse5313812011-05-07 10:11:43 -070071 /* XXX pointless lock */
72 spin_lock_irqsave(&iport->state_lock, flags);
73 iport->status = status;
74 spin_unlock_irqrestore(&iport->state_lock, flags);
75}
Dan Williams6f231dd2011-07-02 22:56:22 -070076
Dan Williamse2f8db52011-05-10 02:28:46 -070077/*
78 * This function will indicate which protocols are supported by this port.
79 * @sci_port: a handle corresponding to the SAS port for which to return the
80 * supported protocols.
81 * @protocols: This parameter specifies a pointer to a data structure
82 * which the core will copy the protocol values for the port from the
83 * transmit_identification register.
84 */
85static void
86scic_sds_port_get_protocols(struct scic_sds_port *sci_port,
87 struct scic_phy_proto *protocols)
Dan Williams6f231dd2011-07-02 22:56:22 -070088{
Dan Williamse2f8db52011-05-10 02:28:46 -070089 u8 index;
90
91 protocols->all = 0;
92
93 for (index = 0; index < SCI_MAX_PHYS; index++) {
94 if (sci_port->phy_table[index] != NULL) {
95 scic_sds_phy_get_protocols(sci_port->phy_table[index],
96 protocols);
97 }
98 }
Dan Williams6f231dd2011-07-02 22:56:22 -070099}
100
Dan Williams6f231dd2011-07-02 22:56:22 -0700101/**
Dan Williamse2f8db52011-05-10 02:28:46 -0700102 * This method requests a list (mask) of the phys contained in the supplied SAS
103 * port.
104 * @sci_port: a handle corresponding to the SAS port for which to return the
105 * phy mask.
Dan Williams6f231dd2011-07-02 22:56:22 -0700106 *
Dan Williamse2f8db52011-05-10 02:28:46 -0700107 * Return a bit mask indicating which phys are a part of this port. Each bit
108 * corresponds to a phy identifier (e.g. bit 0 = phy id 0).
Dan Williams6f231dd2011-07-02 22:56:22 -0700109 */
Dan Williamse2f8db52011-05-10 02:28:46 -0700110static u32 scic_sds_port_get_phys(struct scic_sds_port *sci_port)
Dan Williams6f231dd2011-07-02 22:56:22 -0700111{
Dan Williamse2f8db52011-05-10 02:28:46 -0700112 u32 index;
113 u32 mask;
114
115 mask = 0;
116
117 for (index = 0; index < SCI_MAX_PHYS; index++) {
118 if (sci_port->phy_table[index] != NULL) {
119 mask |= (1 << index);
120 }
121 }
122
123 return mask;
Dan Williams6f231dd2011-07-02 22:56:22 -0700124}
125
Dan Williamse2f8db52011-05-10 02:28:46 -0700126/**
127 * scic_port_get_properties() - This method simply returns the properties
128 * regarding the port, such as: physical index, protocols, sas address, etc.
129 * @port: this parameter specifies the port for which to retrieve the physical
130 * index.
131 * @properties: This parameter specifies the properties structure into which to
132 * copy the requested information.
133 *
134 * Indicate if the user specified a valid port. SCI_SUCCESS This value is
135 * returned if the specified port was valid. SCI_FAILURE_INVALID_PORT This
136 * value is returned if the specified port is not valid. When this value is
137 * returned, no data is copied to the properties output parameter.
138 */
139static enum sci_status scic_port_get_properties(struct scic_sds_port *port,
140 struct scic_port_properties *prop)
Dan Williams6f231dd2011-07-02 22:56:22 -0700141{
Dan Williamse2f8db52011-05-10 02:28:46 -0700142 if ((port == NULL) ||
143 (port->logical_port_index == SCIC_SDS_DUMMY_PORT))
144 return SCI_FAILURE_INVALID_PORT;
Dan Williams6f231dd2011-07-02 22:56:22 -0700145
Dan Williamse2f8db52011-05-10 02:28:46 -0700146 prop->index = port->logical_port_index;
147 prop->phy_mask = scic_sds_port_get_phys(port);
148 scic_sds_port_get_sas_address(port, &prop->local.sas_address);
149 scic_sds_port_get_protocols(port, &prop->local.protocols);
150 scic_sds_port_get_attached_sas_address(port, &prop->remote.sas_address);
Dan Williams6f231dd2011-07-02 22:56:22 -0700151
Dan Williamse2f8db52011-05-10 02:28:46 -0700152 return SCI_SUCCESS;
Dan Williams6f231dd2011-07-02 22:56:22 -0700153}
154
Jeff Skirvin61aaff42011-06-21 12:16:33 -0700155static void scic_port_bcn_enable(struct scic_sds_port *sci_port)
156{
157 struct scic_sds_phy *sci_phy;
158 u32 val;
159 int i;
160
161 for (i = 0; i < ARRAY_SIZE(sci_port->phy_table); i++) {
162 sci_phy = sci_port->phy_table[i];
163 if (!sci_phy)
164 continue;
165 val = readl(&sci_phy->link_layer_registers->link_layer_control);
166 /* clear the bit by writing 1. */
167 writel(val, &sci_phy->link_layer_registers->link_layer_control);
168 }
169}
170
171/* called under scic_lock to stabilize phy:port associations */
172void isci_port_bcn_enable(struct isci_host *ihost, struct isci_port *iport)
173{
174 int i;
175
176 clear_bit(IPORT_BCN_BLOCKED, &iport->flags);
177 wake_up(&ihost->eventq);
178
179 if (!test_and_clear_bit(IPORT_BCN_PENDING, &iport->flags))
180 return;
181
182 for (i = 0; i < ARRAY_SIZE(iport->sci.phy_table); i++) {
183 struct scic_sds_phy *sci_phy = iport->sci.phy_table[i];
184 struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
185
186 if (!sci_phy)
187 continue;
188
189 ihost->sas_ha.notify_port_event(&iphy->sas_phy,
190 PORTE_BROADCAST_RCVD);
191 break;
192 }
193}
194
195void isci_port_bc_change_received(struct isci_host *ihost,
196 struct scic_sds_port *sci_port,
197 struct scic_sds_phy *sci_phy)
198{
199 struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
200 struct isci_port *iport = iphy->isci_port;
201
202 if (iport && test_bit(IPORT_BCN_BLOCKED, &iport->flags)) {
203 dev_dbg(&ihost->pdev->dev,
204 "%s: disabled BCN; isci_phy = %p, sas_phy = %p\n",
205 __func__, iphy, &iphy->sas_phy);
206 set_bit(IPORT_BCN_PENDING, &iport->flags);
207 atomic_inc(&iport->event);
208 wake_up(&ihost->eventq);
209 } else {
210 dev_dbg(&ihost->pdev->dev,
211 "%s: isci_phy = %p, sas_phy = %p\n",
212 __func__, iphy, &iphy->sas_phy);
213
214 ihost->sas_ha.notify_port_event(&iphy->sas_phy,
215 PORTE_BROADCAST_RCVD);
216 }
217 scic_port_bcn_enable(sci_port);
218}
219
Dan Williamse2f8db52011-05-10 02:28:46 -0700220static void isci_port_link_up(struct isci_host *isci_host,
221 struct scic_sds_port *port,
222 struct scic_sds_phy *phy)
Dan Williams6f231dd2011-07-02 22:56:22 -0700223{
224 unsigned long flags;
225 struct scic_port_properties properties;
Dan Williams4b339812011-05-06 17:36:38 -0700226 struct isci_phy *isci_phy = sci_phy_to_iphy(phy);
Dan Williamse5313812011-05-07 10:11:43 -0700227 struct isci_port *isci_port = sci_port_to_iport(port);
Dan Williams6f231dd2011-07-02 22:56:22 -0700228 unsigned long success = true;
229
230 BUG_ON(isci_phy->isci_port != NULL);
Bartosz Barcinski6cb4d6b2011-04-12 17:28:43 -0700231
Dan Williams6f231dd2011-07-02 22:56:22 -0700232 isci_phy->isci_port = isci_port;
233
234 dev_dbg(&isci_host->pdev->dev,
235 "%s: isci_port = %p\n",
236 __func__, isci_port);
237
238 spin_lock_irqsave(&isci_phy->sas_phy.frame_rcvd_lock, flags);
239
240 isci_port_change_state(isci_phy->isci_port, isci_starting);
241
242 scic_port_get_properties(port, &properties);
243
Dave Jiangd7b90fc2011-05-04 18:22:33 -0700244 if (phy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) {
Dan Williams150fc6f2011-02-25 10:25:21 -0800245 u64 attached_sas_address;
Dan Williams6f231dd2011-07-02 22:56:22 -0700246
Dan Williams6f231dd2011-07-02 22:56:22 -0700247 isci_phy->sas_phy.oob_mode = SATA_OOB_MODE;
Dave Jiangf2f30082011-05-04 15:02:02 -0700248 isci_phy->sas_phy.frame_rcvd_size = sizeof(struct dev_to_host_fis);
Dan Williams6f231dd2011-07-02 22:56:22 -0700249
250 /*
251 * For direct-attached SATA devices, the SCI core will
252 * automagically assign a SAS address to the end device
253 * for the purpose of creating a port. This SAS address
254 * will not be the same as assigned to the PHY and needs
255 * to be obtained from struct scic_port_properties properties.
256 */
Dan Williams150fc6f2011-02-25 10:25:21 -0800257 attached_sas_address = properties.remote.sas_address.high;
258 attached_sas_address <<= 32;
259 attached_sas_address |= properties.remote.sas_address.low;
260 swab64s(&attached_sas_address);
Dan Williams6f231dd2011-07-02 22:56:22 -0700261
Dan Williams150fc6f2011-02-25 10:25:21 -0800262 memcpy(&isci_phy->sas_phy.attached_sas_addr,
263 &attached_sas_address, sizeof(attached_sas_address));
Dave Jiangd7b90fc2011-05-04 18:22:33 -0700264 } else if (phy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700265 isci_phy->sas_phy.oob_mode = SAS_OOB_MODE;
Dave Jiang4b7ebd02011-05-04 15:37:52 -0700266 isci_phy->sas_phy.frame_rcvd_size = sizeof(struct sas_identify_frame);
Dan Williams6f231dd2011-07-02 22:56:22 -0700267
268 /* Copy the attached SAS address from the IAF */
269 memcpy(isci_phy->sas_phy.attached_sas_addr,
Dave Jiang4b7ebd02011-05-04 15:37:52 -0700270 isci_phy->frame_rcvd.iaf.sas_addr, SAS_ADDR_SIZE);
Dan Williams6f231dd2011-07-02 22:56:22 -0700271 } else {
272 dev_err(&isci_host->pdev->dev, "%s: unkown target\n", __func__);
273 success = false;
274 }
275
Dan Williams83e51432011-02-18 09:25:13 -0800276 isci_phy->sas_phy.phy->negotiated_linkrate = sci_phy_linkrate(phy);
277
Dan Williams6f231dd2011-07-02 22:56:22 -0700278 spin_unlock_irqrestore(&isci_phy->sas_phy.frame_rcvd_lock, flags);
279
280 /* Notify libsas that we have an address frame, if indeed
281 * we've found an SSP, SMP, or STP target */
282 if (success)
283 isci_host->sas_ha.notify_port_event(&isci_phy->sas_phy,
284 PORTE_BYTES_DMAED);
285}
286
287
288/**
289 * isci_port_link_down() - This function is called by the sci core when a link
290 * becomes inactive.
291 * @isci_host: This parameter specifies the isci host object.
292 * @phy: This parameter specifies the isci phy with the active link.
293 * @port: This parameter specifies the isci port with the active link.
294 *
295 */
Dan Williamse2f8db52011-05-10 02:28:46 -0700296static void isci_port_link_down(struct isci_host *isci_host,
297 struct isci_phy *isci_phy,
298 struct isci_port *isci_port)
Dan Williams6f231dd2011-07-02 22:56:22 -0700299{
300 struct isci_remote_device *isci_device;
301
302 dev_dbg(&isci_host->pdev->dev,
303 "%s: isci_port = %p\n", __func__, isci_port);
304
305 if (isci_port) {
306
307 /* check to see if this is the last phy on this port. */
Jeff Skirvin61aaff42011-06-21 12:16:33 -0700308 if (isci_phy->sas_phy.port &&
309 isci_phy->sas_phy.port->num_phys == 1) {
310 atomic_inc(&isci_port->event);
311 isci_port_bcn_enable(isci_host, isci_port);
Dan Williams6f231dd2011-07-02 22:56:22 -0700312
Jeff Skirvin61aaff42011-06-21 12:16:33 -0700313 /* change the state for all devices on this port. The
314 * next task sent to this device will be returned as
315 * SAS_TASK_UNDELIVERED, and the scsi mid layer will
316 * remove the target
Dan Williams6f231dd2011-07-02 22:56:22 -0700317 */
318 list_for_each_entry(isci_device,
319 &isci_port->remote_dev_list,
320 node) {
321 dev_dbg(&isci_host->pdev->dev,
322 "%s: isci_device = %p\n",
323 __func__, isci_device);
Dan Williams209fae12011-06-13 17:39:44 -0700324 set_bit(IDEV_GONE, &isci_device->flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700325 }
326 }
327 isci_port_change_state(isci_port, isci_stopping);
328 }
329
330 /* Notify libsas of the borken link, this will trigger calls to our
331 * isci_port_deformed and isci_dev_gone functions.
332 */
333 sas_phy_disconnected(&isci_phy->sas_phy);
334 isci_host->sas_ha.notify_phy_event(&isci_phy->sas_phy,
335 PHYE_LOSS_OF_SIGNAL);
336
337 isci_phy->isci_port = NULL;
338
339 dev_dbg(&isci_host->pdev->dev,
340 "%s: isci_port = %p - Done\n", __func__, isci_port);
341}
342
343
344/**
Dan Williams6f231dd2011-07-02 22:56:22 -0700345 * isci_port_ready() - This function is called by the sci core when a link
346 * becomes ready.
347 * @isci_host: This parameter specifies the isci host object.
348 * @port: This parameter specifies the sci port with the active link.
349 *
350 */
Dan Williamse2f8db52011-05-10 02:28:46 -0700351static void isci_port_ready(struct isci_host *isci_host, struct isci_port *isci_port)
Dan Williams6f231dd2011-07-02 22:56:22 -0700352{
353 dev_dbg(&isci_host->pdev->dev,
354 "%s: isci_port = %p\n", __func__, isci_port);
355
356 complete_all(&isci_port->start_complete);
357 isci_port_change_state(isci_port, isci_ready);
358 return;
359}
360
361/**
362 * isci_port_not_ready() - This function is called by the sci core when a link
363 * is not ready. All remote devices on this link will be removed if they are
364 * in the stopping state.
365 * @isci_host: This parameter specifies the isci host object.
366 * @port: This parameter specifies the sci port with the active link.
367 *
368 */
Dan Williamse2f8db52011-05-10 02:28:46 -0700369static void isci_port_not_ready(struct isci_host *isci_host, struct isci_port *isci_port)
Dan Williams6f231dd2011-07-02 22:56:22 -0700370{
371 dev_dbg(&isci_host->pdev->dev,
372 "%s: isci_port = %p\n", __func__, isci_port);
373}
374
Dan Williamse2f8db52011-05-10 02:28:46 -0700375static void isci_port_stop_complete(struct scic_sds_controller *scic,
376 struct scic_sds_port *sci_port,
377 enum sci_status completion_status)
378{
379 dev_dbg(&scic_to_ihost(scic)->pdev->dev, "Port stop complete\n");
380}
381
Dan Williams6f231dd2011-07-02 22:56:22 -0700382/**
383 * isci_port_hard_reset_complete() - This function is called by the sci core
384 * when the hard reset complete notification has been received.
385 * @port: This parameter specifies the sci port with the active link.
386 * @completion_status: This parameter specifies the core status for the reset
387 * process.
388 *
389 */
Dan Williamse2f8db52011-05-10 02:28:46 -0700390static void isci_port_hard_reset_complete(struct isci_port *isci_port,
391 enum sci_status completion_status)
Dan Williams6f231dd2011-07-02 22:56:22 -0700392{
393 dev_dbg(&isci_port->isci_host->pdev->dev,
394 "%s: isci_port = %p, completion_status=%x\n",
395 __func__, isci_port, completion_status);
396
397 /* Save the status of the hard reset from the port. */
398 isci_port->hard_reset_status = completion_status;
399
400 complete_all(&isci_port->hard_reset_complete);
401}
Dan Williams4393aa42011-03-31 13:10:44 -0700402
Dan Williamse2f8db52011-05-10 02:28:46 -0700403/* This method will return a true value if the specified phy can be assigned to
404 * this port The following is a list of phys for each port that are allowed: -
405 * Port 0 - 3 2 1 0 - Port 1 - 1 - Port 2 - 3 2 - Port 3 - 3 This method
406 * doesn't preclude all configurations. It merely ensures that a phy is part
407 * of the allowable set of phy identifiers for that port. For example, one
408 * could assign phy 3 to port 0 and no other phys. Please refer to
409 * scic_sds_port_is_phy_mask_valid() for information regarding whether the
410 * phy_mask for a port can be supported. bool true if this is a valid phy
411 * assignment for the port false if this is not a valid phy assignment for the
412 * port
413 */
414bool scic_sds_port_is_valid_phy_assignment(struct scic_sds_port *sci_port,
415 u32 phy_index)
416{
417 /* Initialize to invalid value. */
418 u32 existing_phy_index = SCI_MAX_PHYS;
419 u32 index;
420
421 if ((sci_port->physical_port_index == 1) && (phy_index != 1)) {
422 return false;
423 }
424
425 if (sci_port->physical_port_index == 3 && phy_index != 3) {
426 return false;
427 }
428
429 if (
430 (sci_port->physical_port_index == 2)
431 && ((phy_index == 0) || (phy_index == 1))
432 ) {
433 return false;
434 }
435
436 for (index = 0; index < SCI_MAX_PHYS; index++) {
437 if ((sci_port->phy_table[index] != NULL)
438 && (index != phy_index)) {
439 existing_phy_index = index;
440 }
441 }
442
443 /*
444 * Ensure that all of the phys in the port are capable of
445 * operating at the same maximum link rate. */
446 if (
447 (existing_phy_index < SCI_MAX_PHYS)
448 && (sci_port->owning_controller->user_parameters.sds1.phys[
449 phy_index].max_speed_generation !=
450 sci_port->owning_controller->user_parameters.sds1.phys[
451 existing_phy_index].max_speed_generation)
452 )
453 return false;
454
455 return true;
456}
457
458/**
459 *
460 * @sci_port: This is the port object for which to determine if the phy mask
461 * can be supported.
462 *
463 * This method will return a true value if the port's phy mask can be supported
464 * by the SCU. The following is a list of valid PHY mask configurations for
465 * each port: - Port 0 - [[3 2] 1] 0 - Port 1 - [1] - Port 2 - [[3] 2]
466 * - Port 3 - [3] This method returns a boolean indication specifying if the
467 * phy mask can be supported. true if this is a valid phy assignment for the
468 * port false if this is not a valid phy assignment for the port
469 */
470static bool scic_sds_port_is_phy_mask_valid(
471 struct scic_sds_port *sci_port,
472 u32 phy_mask)
473{
474 if (sci_port->physical_port_index == 0) {
475 if (((phy_mask & 0x0F) == 0x0F)
476 || ((phy_mask & 0x03) == 0x03)
477 || ((phy_mask & 0x01) == 0x01)
478 || (phy_mask == 0))
479 return true;
480 } else if (sci_port->physical_port_index == 1) {
481 if (((phy_mask & 0x02) == 0x02)
482 || (phy_mask == 0))
483 return true;
484 } else if (sci_port->physical_port_index == 2) {
485 if (((phy_mask & 0x0C) == 0x0C)
486 || ((phy_mask & 0x04) == 0x04)
487 || (phy_mask == 0))
488 return true;
489 } else if (sci_port->physical_port_index == 3) {
490 if (((phy_mask & 0x08) == 0x08)
491 || (phy_mask == 0))
492 return true;
493 }
494
495 return false;
496}
497
498/**
499 *
500 * @sci_port: This parameter specifies the port from which to return a
501 * connected phy.
502 *
503 * This method retrieves a currently active (i.e. connected) phy contained in
504 * the port. Currently, the lowest order phy that is connected is returned.
505 * This method returns a pointer to a SCIS_SDS_PHY object. NULL This value is
506 * returned if there are no currently active (i.e. connected to a remote end
507 * point) phys contained in the port. All other values specify a struct scic_sds_phy
508 * object that is active in the port.
509 */
510static struct scic_sds_phy *scic_sds_port_get_a_connected_phy(
511 struct scic_sds_port *sci_port
512 ) {
513 u32 index;
514 struct scic_sds_phy *phy;
515
516 for (index = 0; index < SCI_MAX_PHYS; index++) {
517 /*
518 * Ensure that the phy is both part of the port and currently
519 * connected to the remote end-point. */
520 phy = sci_port->phy_table[index];
521 if (
522 (phy != NULL)
523 && scic_sds_port_active_phy(sci_port, phy)
524 ) {
525 return phy;
526 }
527 }
528
529 return NULL;
530}
531
532/**
533 * scic_sds_port_set_phy() -
534 * @out]: port The port object to which the phy assignement is being made.
535 * @out]: phy The phy which is being assigned to the port.
536 *
537 * This method attempts to make the assignment of the phy to the port. If
538 * successful the phy is assigned to the ports phy table. bool true if the phy
539 * assignment can be made. false if the phy assignement can not be made. This
540 * is a functional test that only fails if the phy is currently assigned to a
541 * different port.
542 */
543static enum sci_status scic_sds_port_set_phy(
544 struct scic_sds_port *port,
545 struct scic_sds_phy *phy)
546{
547 /*
548 * Check to see if we can add this phy to a port
549 * that means that the phy is not part of a port and that the port does
550 * not already have a phy assinged to the phy index. */
551 if (
552 (port->phy_table[phy->phy_index] == NULL)
Dan Williams4f20ef42011-05-12 06:00:31 -0700553 && (phy_get_non_dummy_port(phy) == NULL)
Dan Williamse2f8db52011-05-10 02:28:46 -0700554 && scic_sds_port_is_valid_phy_assignment(port, phy->phy_index)
555 ) {
556 /*
557 * Phy is being added in the stopped state so we are in MPC mode
558 * make logical port index = physical port index */
559 port->logical_port_index = port->physical_port_index;
560 port->phy_table[phy->phy_index] = phy;
561 scic_sds_phy_set_port(phy, port);
562
563 return SCI_SUCCESS;
564 }
565
566 return SCI_FAILURE;
567}
568
569/**
570 * scic_sds_port_clear_phy() -
571 * @out]: port The port from which the phy is being cleared.
572 * @out]: phy The phy being cleared from the port.
573 *
574 * This method will clear the phy assigned to this port. This method fails if
575 * this phy is not currently assinged to this port. bool true if the phy is
576 * removed from the port. false if this phy is not assined to this port.
577 */
578static enum sci_status scic_sds_port_clear_phy(
579 struct scic_sds_port *port,
580 struct scic_sds_phy *phy)
581{
582 /* Make sure that this phy is part of this port */
583 if (port->phy_table[phy->phy_index] == phy &&
Dan Williams4f20ef42011-05-12 06:00:31 -0700584 phy_get_non_dummy_port(phy) == port) {
Dan Williamse2f8db52011-05-10 02:28:46 -0700585 struct scic_sds_controller *scic = port->owning_controller;
586 struct isci_host *ihost = scic_to_ihost(scic);
587
588 /* Yep it is assigned to this port so remove it */
589 scic_sds_phy_set_port(phy, &ihost->ports[SCI_MAX_PORTS].sci);
590 port->phy_table[phy->phy_index] = NULL;
591 return SCI_SUCCESS;
592 }
593
594 return SCI_FAILURE;
595}
596
Dan Williamse2f8db52011-05-10 02:28:46 -0700597
598/**
599 * This method requests the SAS address for the supplied SAS port from the SCI
600 * implementation.
601 * @sci_port: a handle corresponding to the SAS port for which to return the
602 * SAS address.
603 * @sas_address: This parameter specifies a pointer to a SAS address structure
604 * into which the core will copy the SAS address for the port.
605 *
606 */
607void scic_sds_port_get_sas_address(
608 struct scic_sds_port *sci_port,
609 struct sci_sas_address *sas_address)
610{
611 u32 index;
612
613 sas_address->high = 0;
614 sas_address->low = 0;
615
616 for (index = 0; index < SCI_MAX_PHYS; index++) {
617 if (sci_port->phy_table[index] != NULL) {
618 scic_sds_phy_get_sas_address(sci_port->phy_table[index], sas_address);
619 }
620 }
621}
622
623/*
624 * This function requests the SAS address for the device directly attached to
625 * this SAS port.
626 * @sci_port: a handle corresponding to the SAS port for which to return the
627 * SAS address.
628 * @sas_address: This parameter specifies a pointer to a SAS address structure
629 * into which the core will copy the SAS address for the device directly
630 * attached to the port.
631 *
632 */
633void scic_sds_port_get_attached_sas_address(
634 struct scic_sds_port *sci_port,
635 struct sci_sas_address *sas_address)
636{
637 struct scic_sds_phy *sci_phy;
638
639 /*
640 * Ensure that the phy is both part of the port and currently
641 * connected to the remote end-point.
642 */
643 sci_phy = scic_sds_port_get_a_connected_phy(sci_port);
644 if (sci_phy) {
645 if (sci_phy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA) {
646 scic_sds_phy_get_attached_sas_address(sci_phy,
647 sas_address);
648 } else {
649 scic_sds_phy_get_sas_address(sci_phy, sas_address);
650 sas_address->low += sci_phy->phy_index;
651 }
652 } else {
653 sas_address->high = 0;
654 sas_address->low = 0;
655 }
656}
657
658/**
659 * scic_sds_port_construct_dummy_rnc() - create dummy rnc for si workaround
660 *
661 * @sci_port: logical port on which we need to create the remote node context
662 * @rni: remote node index for this remote node context.
663 *
664 * This routine will construct a dummy remote node context data structure
665 * This structure will be posted to the hardware to work around a scheduler
666 * error in the hardware.
667 */
668static void scic_sds_port_construct_dummy_rnc(struct scic_sds_port *sci_port, u16 rni)
669{
670 union scu_remote_node_context *rnc;
671
672 rnc = &sci_port->owning_controller->remote_node_context_table[rni];
673
674 memset(rnc, 0, sizeof(union scu_remote_node_context));
675
676 rnc->ssp.remote_sas_address_hi = 0;
677 rnc->ssp.remote_sas_address_lo = 0;
678
679 rnc->ssp.remote_node_index = rni;
680 rnc->ssp.remote_node_port_width = 1;
681 rnc->ssp.logical_port_index = sci_port->physical_port_index;
682
683 rnc->ssp.nexus_loss_timer_enable = false;
684 rnc->ssp.check_bit = false;
685 rnc->ssp.is_valid = true;
686 rnc->ssp.is_remote_node_context = true;
687 rnc->ssp.function_number = 0;
688 rnc->ssp.arbitration_wait_time = 0;
689}
690
Dan Williamsdd047c82011-06-09 11:06:58 -0700691/*
692 * construct a dummy task context data structure. This
Dan Williamse2f8db52011-05-10 02:28:46 -0700693 * structure will be posted to the hardwre to work around a scheduler error
694 * in the hardware.
Dan Williamse2f8db52011-05-10 02:28:46 -0700695 */
Dan Williamsdd047c82011-06-09 11:06:58 -0700696static void scic_sds_port_construct_dummy_task(struct scic_sds_port *sci_port, u16 tag)
Dan Williamse2f8db52011-05-10 02:28:46 -0700697{
698 struct scu_task_context *task_context;
699
Dan Williamsdd047c82011-06-09 11:06:58 -0700700 task_context = scic_sds_controller_get_task_context_buffer(sci_port->owning_controller, tag);
Dan Williamse2f8db52011-05-10 02:28:46 -0700701
702 memset(task_context, 0, sizeof(struct scu_task_context));
703
704 task_context->abort = 0;
705 task_context->priority = 0;
706 task_context->initiator_request = 1;
707 task_context->connection_rate = 1;
708 task_context->protocol_engine_index = 0;
709 task_context->logical_port_index = sci_port->physical_port_index;
710 task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SSP;
Dan Williamsdd047c82011-06-09 11:06:58 -0700711 task_context->task_index = ISCI_TAG_TCI(tag);
Dan Williamse2f8db52011-05-10 02:28:46 -0700712 task_context->valid = SCU_TASK_CONTEXT_VALID;
713 task_context->context_type = SCU_TASK_CONTEXT_TYPE;
714
715 task_context->remote_node_index = sci_port->reserved_rni;
716 task_context->command_code = 0;
717
718 task_context->link_layer_control = 0;
719 task_context->do_not_dma_ssp_good_response = 1;
720 task_context->strict_ordering = 0;
721 task_context->control_frame = 0;
722 task_context->timeout_enable = 0;
723 task_context->block_guard_enable = 0;
724
725 task_context->address_modifier = 0;
726
727 task_context->task_phase = 0x01;
728}
729
730static void scic_sds_port_destroy_dummy_resources(struct scic_sds_port *sci_port)
731{
732 struct scic_sds_controller *scic = sci_port->owning_controller;
733
734 if (sci_port->reserved_tci != SCU_DUMMY_INDEX)
735 scic_controller_free_io_tag(scic, sci_port->reserved_tci);
736
737 if (sci_port->reserved_rni != SCU_DUMMY_INDEX)
738 scic_sds_remote_node_table_release_remote_node_index(&scic->available_remote_nodes,
739 1, sci_port->reserved_rni);
740
741 sci_port->reserved_rni = SCU_DUMMY_INDEX;
742 sci_port->reserved_tci = SCU_DUMMY_INDEX;
743}
744
745/**
746 * This method performs initialization of the supplied port. Initialization
747 * includes: - state machine initialization - member variable initialization
748 * - configuring the phy_mask
749 * @sci_port:
750 * @transport_layer_registers:
751 * @port_task_scheduler_registers:
752 * @port_configuration_regsiter:
753 *
754 * enum sci_status SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION This value is returned
755 * if the phy being added to the port
756 */
757enum sci_status scic_sds_port_initialize(
758 struct scic_sds_port *sci_port,
759 void __iomem *port_task_scheduler_registers,
760 void __iomem *port_configuration_regsiter,
761 void __iomem *viit_registers)
762{
763 sci_port->port_task_scheduler_registers = port_task_scheduler_registers;
764 sci_port->port_pe_configuration_register = port_configuration_regsiter;
765 sci_port->viit_registers = viit_registers;
766
767 return SCI_SUCCESS;
768}
769
Dan Williamse2f8db52011-05-10 02:28:46 -0700770
771/**
772 * This method assigns the direct attached device ID for this port.
773 *
774 * @param[in] sci_port The port for which the direct attached device id is to
775 * be assigned.
776 * @param[in] device_id The direct attached device ID to assign to the port.
777 * This will be the RNi for the device
778 */
779void scic_sds_port_setup_transports(
780 struct scic_sds_port *sci_port,
781 u32 device_id)
782{
783 u8 index;
784
785 for (index = 0; index < SCI_MAX_PHYS; index++) {
786 if (sci_port->active_phy_mask & (1 << index))
787 scic_sds_phy_setup_transport(sci_port->phy_table[index], device_id);
788 }
789}
790
791/**
792 *
793 * @sci_port: This is the port on which the phy should be enabled.
794 * @sci_phy: This is the specific phy which to enable.
795 * @do_notify_user: This parameter specifies whether to inform the user (via
796 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
797 *
798 * This function will activate the phy in the port.
799 * Activation includes: - adding
800 * the phy to the port - enabling the Protocol Engine in the silicon. -
801 * notifying the user that the link is up. none
802 */
803static void scic_sds_port_activate_phy(struct scic_sds_port *sci_port,
804 struct scic_sds_phy *sci_phy,
805 bool do_notify_user)
806{
807 struct scic_sds_controller *scic = sci_port->owning_controller;
808 struct isci_host *ihost = scic_to_ihost(scic);
809
810 if (sci_phy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA)
811 scic_sds_phy_resume(sci_phy);
812
813 sci_port->active_phy_mask |= 1 << sci_phy->phy_index;
814
815 scic_sds_controller_clear_invalid_phy(scic, sci_phy);
816
817 if (do_notify_user == true)
818 isci_port_link_up(ihost, sci_port, sci_phy);
819}
820
821void scic_sds_port_deactivate_phy(struct scic_sds_port *sci_port,
822 struct scic_sds_phy *sci_phy,
823 bool do_notify_user)
824{
825 struct scic_sds_controller *scic = scic_sds_port_get_controller(sci_port);
826 struct isci_port *iport = sci_port_to_iport(sci_port);
827 struct isci_host *ihost = scic_to_ihost(scic);
828 struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
829
830 sci_port->active_phy_mask &= ~(1 << sci_phy->phy_index);
831
832 sci_phy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
833
834 /* Re-assign the phy back to the LP as if it were a narrow port */
835 writel(sci_phy->phy_index,
836 &sci_port->port_pe_configuration_register[sci_phy->phy_index]);
837
838 if (do_notify_user == true)
839 isci_port_link_down(ihost, iphy, iport);
840}
841
842/**
843 *
844 * @sci_port: This is the port on which the phy should be disabled.
845 * @sci_phy: This is the specific phy which to disabled.
846 *
847 * This function will disable the phy and report that the phy is not valid for
848 * this port object. None
849 */
850static void scic_sds_port_invalid_link_up(struct scic_sds_port *sci_port,
851 struct scic_sds_phy *sci_phy)
852{
853 struct scic_sds_controller *scic = sci_port->owning_controller;
854
855 /*
856 * Check to see if we have alreay reported this link as bad and if
857 * not go ahead and tell the SCI_USER that we have discovered an
858 * invalid link.
859 */
860 if ((scic->invalid_phy_mask & (1 << sci_phy->phy_index)) == 0) {
861 scic_sds_controller_set_invalid_phy(scic, sci_phy);
862 dev_warn(&scic_to_ihost(scic)->pdev->dev, "Invalid link up!\n");
863 }
864}
865
Piotr Sawickie91f41e2011-05-11 23:52:21 +0000866static bool is_port_ready_state(enum scic_sds_port_states state)
867{
868 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +0000869 case SCI_PORT_READY:
870 case SCI_PORT_SUB_WAITING:
871 case SCI_PORT_SUB_OPERATIONAL:
872 case SCI_PORT_SUB_CONFIGURING:
Piotr Sawickie91f41e2011-05-11 23:52:21 +0000873 return true;
874 default:
875 return false;
876 }
877}
878
879/* flag dummy rnc hanling when exiting a ready state */
880static void port_state_machine_change(struct scic_sds_port *sci_port,
881 enum scic_sds_port_states state)
882{
Edmund Nadolskie3013702011-06-02 00:10:43 +0000883 struct sci_base_state_machine *sm = &sci_port->sm;
Piotr Sawickie91f41e2011-05-11 23:52:21 +0000884 enum scic_sds_port_states old_state = sm->current_state_id;
885
886 if (is_port_ready_state(old_state) && !is_port_ready_state(state))
887 sci_port->ready_exit = true;
888
Edmund Nadolskie3013702011-06-02 00:10:43 +0000889 sci_change_state(sm, state);
Piotr Sawickie91f41e2011-05-11 23:52:21 +0000890 sci_port->ready_exit = false;
891}
892
Dan Williamse2f8db52011-05-10 02:28:46 -0700893/**
894 * scic_sds_port_general_link_up_handler - phy can be assigned to port?
895 * @sci_port: scic_sds_port object for which has a phy that has gone link up.
896 * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
897 * @do_notify_user: This parameter specifies whether to inform the user (via
898 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
899 *
900 * Determine if this phy can be assigned to this
901 * port . If the phy is not a valid PHY for
902 * this port then the function will notify the user. A PHY can only be
903 * part of a port if it's attached SAS ADDRESS is the same as all other PHYs in
904 * the same port. none
905 */
906static void scic_sds_port_general_link_up_handler(struct scic_sds_port *sci_port,
907 struct scic_sds_phy *sci_phy,
908 bool do_notify_user)
909{
910 struct sci_sas_address port_sas_address;
911 struct sci_sas_address phy_sas_address;
912
913 scic_sds_port_get_attached_sas_address(sci_port, &port_sas_address);
914 scic_sds_phy_get_attached_sas_address(sci_phy, &phy_sas_address);
915
916 /* If the SAS address of the new phy matches the SAS address of
917 * other phys in the port OR this is the first phy in the port,
918 * then activate the phy and allow it to be used for operations
919 * in this port.
920 */
921 if ((phy_sas_address.high == port_sas_address.high &&
922 phy_sas_address.low == port_sas_address.low) ||
923 sci_port->active_phy_mask == 0) {
Edmund Nadolskie3013702011-06-02 00:10:43 +0000924 struct sci_base_state_machine *sm = &sci_port->sm;
Dan Williamse2f8db52011-05-10 02:28:46 -0700925
926 scic_sds_port_activate_phy(sci_port, sci_phy, do_notify_user);
Edmund Nadolskie3013702011-06-02 00:10:43 +0000927 if (sm->current_state_id == SCI_PORT_RESETTING)
928 port_state_machine_change(sci_port, SCI_PORT_READY);
Dan Williamse2f8db52011-05-10 02:28:46 -0700929 } else
930 scic_sds_port_invalid_link_up(sci_port, sci_phy);
931}
932
933
934
935/**
936 * This method returns false if the port only has a single phy object assigned.
937 * If there are no phys or more than one phy then the method will return
938 * true.
939 * @sci_port: The port for which the wide port condition is to be checked.
940 *
941 * bool true Is returned if this is a wide ported port. false Is returned if
942 * this is a narrow port.
943 */
944static bool scic_sds_port_is_wide(struct scic_sds_port *sci_port)
945{
946 u32 index;
947 u32 phy_count = 0;
948
949 for (index = 0; index < SCI_MAX_PHYS; index++) {
950 if (sci_port->phy_table[index] != NULL) {
951 phy_count++;
952 }
953 }
954
955 return phy_count != 1;
956}
957
958/**
959 * This method is called by the PHY object when the link is detected. if the
960 * port wants the PHY to continue on to the link up state then the port
961 * layer must return true. If the port object returns false the phy object
962 * must halt its attempt to go link up.
963 * @sci_port: The port associated with the phy object.
964 * @sci_phy: The phy object that is trying to go link up.
965 *
966 * true if the phy object can continue to the link up condition. true Is
967 * returned if this phy can continue to the ready state. false Is returned if
968 * can not continue on to the ready state. This notification is in place for
969 * wide ports and direct attached phys. Since there are no wide ported SATA
970 * devices this could become an invalid port configuration.
971 */
972bool scic_sds_port_link_detected(
973 struct scic_sds_port *sci_port,
974 struct scic_sds_phy *sci_phy)
975{
976 if ((sci_port->logical_port_index != SCIC_SDS_DUMMY_PORT) &&
977 (sci_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) &&
978 scic_sds_port_is_wide(sci_port)) {
979 scic_sds_port_invalid_link_up(sci_port, sci_phy);
980
981 return false;
982 }
983
984 return true;
985}
986
Edmund Nadolski5553ba22011-05-19 11:59:10 +0000987static void port_timeout(unsigned long data)
Dan Williamse2f8db52011-05-10 02:28:46 -0700988{
Edmund Nadolski5553ba22011-05-19 11:59:10 +0000989 struct sci_timer *tmr = (struct sci_timer *)data;
990 struct scic_sds_port *sci_port = container_of(tmr, typeof(*sci_port), timer);
991 struct isci_host *ihost = scic_to_ihost(sci_port->owning_controller);
992 unsigned long flags;
Dan Williamse2f8db52011-05-10 02:28:46 -0700993 u32 current_state;
994
Edmund Nadolski5553ba22011-05-19 11:59:10 +0000995 spin_lock_irqsave(&ihost->scic_lock, flags);
996
997 if (tmr->cancel)
998 goto done;
999
Edmund Nadolskie3013702011-06-02 00:10:43 +00001000 current_state = sci_port->sm.current_state_id;
Dan Williamse2f8db52011-05-10 02:28:46 -07001001
Edmund Nadolskie3013702011-06-02 00:10:43 +00001002 if (current_state == SCI_PORT_RESETTING) {
Piotr Sawickie91f41e2011-05-11 23:52:21 +00001003 /* if the port is still in the resetting state then the timeout
1004 * fired before the reset completed.
Dan Williamse2f8db52011-05-10 02:28:46 -07001005 */
Edmund Nadolskie3013702011-06-02 00:10:43 +00001006 port_state_machine_change(sci_port, SCI_PORT_FAILED);
1007 } else if (current_state == SCI_PORT_STOPPED) {
Piotr Sawickie91f41e2011-05-11 23:52:21 +00001008 /* if the port is stopped then the start request failed In this
1009 * case stay in the stopped state.
Dan Williamse2f8db52011-05-10 02:28:46 -07001010 */
1011 dev_err(sciport_to_dev(sci_port),
1012 "%s: SCIC Port 0x%p failed to stop before tiemout.\n",
1013 __func__,
1014 sci_port);
Edmund Nadolskie3013702011-06-02 00:10:43 +00001015 } else if (current_state == SCI_PORT_STOPPING) {
Piotr Sawickie91f41e2011-05-11 23:52:21 +00001016 /* if the port is still stopping then the stop has not completed */
1017 isci_port_stop_complete(sci_port->owning_controller,
1018 sci_port,
1019 SCI_FAILURE_TIMEOUT);
Dan Williamse2f8db52011-05-10 02:28:46 -07001020 } else {
Piotr Sawickie91f41e2011-05-11 23:52:21 +00001021 /* The port is in the ready state and we have a timer
Dan Williamse2f8db52011-05-10 02:28:46 -07001022 * reporting a timeout this should not happen.
1023 */
1024 dev_err(sciport_to_dev(sci_port),
1025 "%s: SCIC Port 0x%p is processing a timeout operation "
Piotr Sawickie91f41e2011-05-11 23:52:21 +00001026 "in state %d.\n", __func__, sci_port, current_state);
Dan Williamse2f8db52011-05-10 02:28:46 -07001027 }
Edmund Nadolski5553ba22011-05-19 11:59:10 +00001028
1029done:
1030 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williamse2f8db52011-05-10 02:28:46 -07001031}
1032
1033/* --------------------------------------------------------------------------- */
1034
1035/**
1036 * This function updates the hardwares VIIT entry for this port.
1037 *
1038 *
1039 */
1040static void scic_sds_port_update_viit_entry(struct scic_sds_port *sci_port)
1041{
1042 struct sci_sas_address sas_address;
1043
1044 scic_sds_port_get_sas_address(sci_port, &sas_address);
1045
1046 writel(sas_address.high,
1047 &sci_port->viit_registers->initiator_sas_address_hi);
1048 writel(sas_address.low,
1049 &sci_port->viit_registers->initiator_sas_address_lo);
1050
1051 /* This value get cleared just in case its not already cleared */
1052 writel(0, &sci_port->viit_registers->reserved);
1053
1054 /* We are required to update the status register last */
1055 writel(SCU_VIIT_ENTRY_ID_VIIT |
1056 SCU_VIIT_IPPT_INITIATOR |
1057 ((1 << sci_port->physical_port_index) << SCU_VIIT_ENTRY_LPVIE_SHIFT) |
1058 SCU_VIIT_STATUS_ALL_VALID,
1059 &sci_port->viit_registers->status);
1060}
1061
1062/**
1063 * This method returns the maximum allowed speed for data transfers on this
1064 * port. This maximum allowed speed evaluates to the maximum speed of the
1065 * slowest phy in the port.
1066 * @sci_port: This parameter specifies the port for which to retrieve the
1067 * maximum allowed speed.
1068 *
1069 * This method returns the maximum negotiated speed of the slowest phy in the
1070 * port.
1071 */
1072enum sas_linkrate scic_sds_port_get_max_allowed_speed(
1073 struct scic_sds_port *sci_port)
1074{
1075 u16 index;
1076 enum sas_linkrate max_allowed_speed = SAS_LINK_RATE_6_0_GBPS;
1077 struct scic_sds_phy *phy = NULL;
1078
1079 /*
1080 * Loop through all of the phys in this port and find the phy with the
1081 * lowest maximum link rate. */
1082 for (index = 0; index < SCI_MAX_PHYS; index++) {
1083 phy = sci_port->phy_table[index];
1084 if (
1085 (phy != NULL)
1086 && (scic_sds_port_active_phy(sci_port, phy) == true)
1087 && (phy->max_negotiated_speed < max_allowed_speed)
1088 )
1089 max_allowed_speed = phy->max_negotiated_speed;
1090 }
1091
1092 return max_allowed_speed;
1093}
1094
Dan Williamse2f8db52011-05-10 02:28:46 -07001095/**
1096 *
1097 * @sci_port: This is the struct scic_sds_port object to suspend.
1098 *
1099 * This method will susped the port task scheduler for this port object. none
1100 */
1101static void
1102scic_sds_port_suspend_port_task_scheduler(struct scic_sds_port *port)
1103{
1104 u32 pts_control_value;
1105
1106 pts_control_value = readl(&port->port_task_scheduler_registers->control);
1107 pts_control_value |= SCU_PTSxCR_GEN_BIT(SUSPEND);
1108 writel(pts_control_value, &port->port_task_scheduler_registers->control);
1109}
1110
1111/**
1112 * scic_sds_port_post_dummy_request() - post dummy/workaround request
1113 * @sci_port: port to post task
1114 *
1115 * Prevent the hardware scheduler from posting new requests to the front
1116 * of the scheduler queue causing a starvation problem for currently
1117 * ongoing requests.
1118 *
1119 */
1120static void scic_sds_port_post_dummy_request(struct scic_sds_port *sci_port)
1121{
1122 u32 command;
1123 struct scu_task_context *task_context;
1124 struct scic_sds_controller *scic = sci_port->owning_controller;
1125 u16 tci = sci_port->reserved_tci;
1126
1127 task_context = scic_sds_controller_get_task_context_buffer(scic, tci);
1128
1129 task_context->abort = 0;
1130
1131 command = SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
1132 sci_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
1133 tci;
1134
1135 scic_sds_controller_post_request(scic, command);
1136}
1137
1138/**
1139 * This routine will abort the dummy request. This will alow the hardware to
1140 * power down parts of the silicon to save power.
1141 *
1142 * @sci_port: The port on which the task must be aborted.
1143 *
1144 */
1145static void scic_sds_port_abort_dummy_request(struct scic_sds_port *sci_port)
1146{
1147 struct scic_sds_controller *scic = sci_port->owning_controller;
1148 u16 tci = sci_port->reserved_tci;
1149 struct scu_task_context *tc;
1150 u32 command;
1151
1152 tc = scic_sds_controller_get_task_context_buffer(scic, tci);
1153
1154 tc->abort = 1;
1155
1156 command = SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT |
1157 sci_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
1158 tci;
1159
1160 scic_sds_controller_post_request(scic, command);
1161}
1162
1163/**
1164 *
1165 * @sci_port: This is the struct scic_sds_port object to resume.
1166 *
1167 * This method will resume the port task scheduler for this port object. none
1168 */
1169static void
1170scic_sds_port_resume_port_task_scheduler(struct scic_sds_port *port)
1171{
1172 u32 pts_control_value;
1173
1174 pts_control_value = readl(&port->port_task_scheduler_registers->control);
1175 pts_control_value &= ~SCU_PTSxCR_GEN_BIT(SUSPEND);
1176 writel(pts_control_value, &port->port_task_scheduler_registers->control);
1177}
1178
Dan Williams9269e0e2011-05-12 07:42:17 -07001179static void scic_sds_port_ready_substate_waiting_enter(struct sci_base_state_machine *sm)
Dan Williamse2f8db52011-05-10 02:28:46 -07001180{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001181 struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), sm);
Dan Williamse2f8db52011-05-10 02:28:46 -07001182
Dan Williamse2f8db52011-05-10 02:28:46 -07001183 scic_sds_port_suspend_port_task_scheduler(sci_port);
1184
1185 sci_port->not_ready_reason = SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS;
1186
1187 if (sci_port->active_phy_mask != 0) {
1188 /* At least one of the phys on the port is ready */
Piotr Sawickie91f41e2011-05-11 23:52:21 +00001189 port_state_machine_change(sci_port,
Edmund Nadolskie3013702011-06-02 00:10:43 +00001190 SCI_PORT_SUB_OPERATIONAL);
Dan Williamse2f8db52011-05-10 02:28:46 -07001191 }
1192}
1193
Dan Williams9269e0e2011-05-12 07:42:17 -07001194static void scic_sds_port_ready_substate_operational_enter(struct sci_base_state_machine *sm)
Dan Williamse2f8db52011-05-10 02:28:46 -07001195{
1196 u32 index;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001197 struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), sm);
Dan Williamse2f8db52011-05-10 02:28:46 -07001198 struct scic_sds_controller *scic = sci_port->owning_controller;
1199 struct isci_host *ihost = scic_to_ihost(scic);
1200 struct isci_port *iport = sci_port_to_iport(sci_port);
1201
Dan Williamse2f8db52011-05-10 02:28:46 -07001202 isci_port_ready(ihost, iport);
1203
1204 for (index = 0; index < SCI_MAX_PHYS; index++) {
1205 if (sci_port->phy_table[index]) {
1206 writel(sci_port->physical_port_index,
1207 &sci_port->port_pe_configuration_register[
1208 sci_port->phy_table[index]->phy_index]);
1209 }
1210 }
1211
1212 scic_sds_port_update_viit_entry(sci_port);
1213
1214 scic_sds_port_resume_port_task_scheduler(sci_port);
1215
1216 /*
1217 * Post the dummy task for the port so the hardware can schedule
1218 * io correctly
1219 */
1220 scic_sds_port_post_dummy_request(sci_port);
1221}
1222
Piotr Sawickie91f41e2011-05-11 23:52:21 +00001223static void scic_sds_port_invalidate_dummy_remote_node(struct scic_sds_port *sci_port)
1224{
1225 struct scic_sds_controller *scic = sci_port->owning_controller;
1226 u8 phys_index = sci_port->physical_port_index;
1227 union scu_remote_node_context *rnc;
1228 u16 rni = sci_port->reserved_rni;
1229 u32 command;
1230
1231 rnc = &scic->remote_node_context_table[rni];
1232
1233 rnc->ssp.is_valid = false;
1234
1235 /* ensure the preceding tc abort request has reached the
1236 * controller and give it ample time to act before posting the rnc
1237 * invalidate
1238 */
1239 readl(&scic->smu_registers->interrupt_status); /* flush */
1240 udelay(10);
1241
1242 command = SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE |
1243 phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
1244
1245 scic_sds_controller_post_request(scic, command);
1246}
1247
Dan Williamse2f8db52011-05-10 02:28:46 -07001248/**
1249 *
1250 * @object: This is the object which is cast to a struct scic_sds_port object.
1251 *
1252 * This method will perform the actions required by the struct scic_sds_port on
Edmund Nadolskie3013702011-06-02 00:10:43 +00001253 * exiting the SCI_PORT_SUB_OPERATIONAL. This function reports
Dan Williamse2f8db52011-05-10 02:28:46 -07001254 * the port not ready and suspends the port task scheduler. none
1255 */
Dan Williams9269e0e2011-05-12 07:42:17 -07001256static void scic_sds_port_ready_substate_operational_exit(struct sci_base_state_machine *sm)
Dan Williamse2f8db52011-05-10 02:28:46 -07001257{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001258 struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), sm);
Dan Williamse2f8db52011-05-10 02:28:46 -07001259 struct scic_sds_controller *scic = sci_port->owning_controller;
1260 struct isci_host *ihost = scic_to_ihost(scic);
1261 struct isci_port *iport = sci_port_to_iport(sci_port);
1262
1263 /*
1264 * Kill the dummy task for this port if it has not yet posted
1265 * the hardware will treat this as a NOP and just return abort
1266 * complete.
1267 */
1268 scic_sds_port_abort_dummy_request(sci_port);
1269
1270 isci_port_not_ready(ihost, iport);
Piotr Sawickie91f41e2011-05-11 23:52:21 +00001271
1272 if (sci_port->ready_exit)
1273 scic_sds_port_invalidate_dummy_remote_node(sci_port);
Dan Williamse2f8db52011-05-10 02:28:46 -07001274}
1275
Dan Williams9269e0e2011-05-12 07:42:17 -07001276static void scic_sds_port_ready_substate_configuring_enter(struct sci_base_state_machine *sm)
Dan Williamse2f8db52011-05-10 02:28:46 -07001277{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001278 struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), sm);
Dan Williamse2f8db52011-05-10 02:28:46 -07001279 struct scic_sds_controller *scic = sci_port->owning_controller;
1280 struct isci_host *ihost = scic_to_ihost(scic);
1281 struct isci_port *iport = sci_port_to_iport(sci_port);
1282
Dan Williamse2f8db52011-05-10 02:28:46 -07001283 if (sci_port->active_phy_mask == 0) {
1284 isci_port_not_ready(ihost, iport);
1285
Piotr Sawickie91f41e2011-05-11 23:52:21 +00001286 port_state_machine_change(sci_port,
Edmund Nadolskie3013702011-06-02 00:10:43 +00001287 SCI_PORT_SUB_WAITING);
Dan Williamse2f8db52011-05-10 02:28:46 -07001288 } else if (sci_port->started_request_count == 0)
Piotr Sawickie91f41e2011-05-11 23:52:21 +00001289 port_state_machine_change(sci_port,
Edmund Nadolskie3013702011-06-02 00:10:43 +00001290 SCI_PORT_SUB_OPERATIONAL);
Dan Williamse2f8db52011-05-10 02:28:46 -07001291}
1292
Dan Williams9269e0e2011-05-12 07:42:17 -07001293static void scic_sds_port_ready_substate_configuring_exit(struct sci_base_state_machine *sm)
Dan Williamse2f8db52011-05-10 02:28:46 -07001294{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001295 struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), sm);
Dan Williamse2f8db52011-05-10 02:28:46 -07001296
1297 scic_sds_port_suspend_port_task_scheduler(sci_port);
Piotr Sawickie91f41e2011-05-11 23:52:21 +00001298 if (sci_port->ready_exit)
1299 scic_sds_port_invalidate_dummy_remote_node(sci_port);
Dan Williamse2f8db52011-05-10 02:28:46 -07001300}
1301
Piotr Sawickid76f71d2011-05-11 23:52:26 +00001302enum sci_status scic_sds_port_start(struct scic_sds_port *sci_port)
1303{
1304 struct scic_sds_controller *scic = sci_port->owning_controller;
Piotr Sawickid76f71d2011-05-11 23:52:26 +00001305 enum sci_status status = SCI_SUCCESS;
1306 enum scic_sds_port_states state;
1307 u32 phy_mask;
1308
Edmund Nadolskie3013702011-06-02 00:10:43 +00001309 state = sci_port->sm.current_state_id;
1310 if (state != SCI_PORT_STOPPED) {
Piotr Sawickid76f71d2011-05-11 23:52:26 +00001311 dev_warn(sciport_to_dev(sci_port),
1312 "%s: in wrong state: %d\n", __func__, state);
1313 return SCI_FAILURE_INVALID_STATE;
1314 }
1315
1316 if (sci_port->assigned_device_count > 0) {
1317 /* TODO This is a start failure operation because
1318 * there are still devices assigned to this port.
1319 * There must be no devices assigned to a port on a
1320 * start operation.
1321 */
1322 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
1323 }
1324
Piotr Sawickid76f71d2011-05-11 23:52:26 +00001325 if (sci_port->reserved_rni == SCU_DUMMY_INDEX) {
1326 u16 rni = scic_sds_remote_node_table_allocate_remote_node(
1327 &scic->available_remote_nodes, 1);
1328
1329 if (rni != SCU_DUMMY_INDEX)
1330 scic_sds_port_construct_dummy_rnc(sci_port, rni);
1331 else
1332 status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
1333 sci_port->reserved_rni = rni;
1334 }
1335
1336 if (sci_port->reserved_tci == SCU_DUMMY_INDEX) {
1337 /* Allocate a TCI and remove the sequence nibble */
1338 u16 tci = scic_controller_allocate_io_tag(scic);
1339
1340 if (tci != SCU_DUMMY_INDEX)
1341 scic_sds_port_construct_dummy_task(sci_port, tci);
1342 else
1343 status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
1344 sci_port->reserved_tci = tci;
1345 }
1346
1347 if (status == SCI_SUCCESS) {
1348 phy_mask = scic_sds_port_get_phys(sci_port);
1349
1350 /*
1351 * There are one or more phys assigned to this port. Make sure
1352 * the port's phy mask is in fact legal and supported by the
1353 * silicon.
1354 */
1355 if (scic_sds_port_is_phy_mask_valid(sci_port, phy_mask) == true) {
1356 port_state_machine_change(sci_port,
Edmund Nadolskie3013702011-06-02 00:10:43 +00001357 SCI_PORT_READY);
Piotr Sawickid76f71d2011-05-11 23:52:26 +00001358
1359 return SCI_SUCCESS;
1360 }
1361 status = SCI_FAILURE;
1362 }
1363
1364 if (status != SCI_SUCCESS)
1365 scic_sds_port_destroy_dummy_resources(sci_port);
1366
1367 return status;
1368}
1369
Piotr Sawicki8bc80d32011-05-11 23:52:31 +00001370enum sci_status scic_sds_port_stop(struct scic_sds_port *sci_port)
1371{
1372 enum scic_sds_port_states state;
1373
Edmund Nadolskie3013702011-06-02 00:10:43 +00001374 state = sci_port->sm.current_state_id;
Piotr Sawicki8bc80d32011-05-11 23:52:31 +00001375 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +00001376 case SCI_PORT_STOPPED:
Piotr Sawicki8bc80d32011-05-11 23:52:31 +00001377 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001378 case SCI_PORT_SUB_WAITING:
1379 case SCI_PORT_SUB_OPERATIONAL:
1380 case SCI_PORT_SUB_CONFIGURING:
1381 case SCI_PORT_RESETTING:
Piotr Sawicki8bc80d32011-05-11 23:52:31 +00001382 port_state_machine_change(sci_port,
Edmund Nadolskie3013702011-06-02 00:10:43 +00001383 SCI_PORT_STOPPING);
Piotr Sawicki8bc80d32011-05-11 23:52:31 +00001384 return SCI_SUCCESS;
1385 default:
1386 dev_warn(sciport_to_dev(sci_port),
1387 "%s: in wrong state: %d\n", __func__, state);
1388 return SCI_FAILURE_INVALID_STATE;
1389 }
1390}
1391
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001392static enum sci_status scic_port_hard_reset(struct scic_sds_port *sci_port, u32 timeout)
1393{
1394 enum sci_status status = SCI_FAILURE_INVALID_PHY;
1395 struct scic_sds_phy *selected_phy = NULL;
1396 enum scic_sds_port_states state;
1397 u32 phy_index;
1398
Edmund Nadolskie3013702011-06-02 00:10:43 +00001399 state = sci_port->sm.current_state_id;
1400 if (state != SCI_PORT_SUB_OPERATIONAL) {
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001401 dev_warn(sciport_to_dev(sci_port),
1402 "%s: in wrong state: %d\n", __func__, state);
1403 return SCI_FAILURE_INVALID_STATE;
1404 }
1405
1406 /* Select a phy on which we can send the hard reset request. */
1407 for (phy_index = 0; phy_index < SCI_MAX_PHYS && !selected_phy; phy_index++) {
1408 selected_phy = sci_port->phy_table[phy_index];
1409 if (selected_phy &&
1410 !scic_sds_port_active_phy(sci_port, selected_phy)) {
1411 /*
1412 * We found a phy but it is not ready select
1413 * different phy
1414 */
1415 selected_phy = NULL;
1416 }
1417 }
1418
1419 /* If we have a phy then go ahead and start the reset procedure */
1420 if (!selected_phy)
1421 return status;
1422 status = scic_sds_phy_reset(selected_phy);
1423
1424 if (status != SCI_SUCCESS)
1425 return status;
1426
Edmund Nadolski5553ba22011-05-19 11:59:10 +00001427 sci_mod_timer(&sci_port->timer, timeout);
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001428 sci_port->not_ready_reason = SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED;
1429
1430 port_state_machine_change(sci_port,
Edmund Nadolskie3013702011-06-02 00:10:43 +00001431 SCI_PORT_RESETTING);
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001432 return SCI_SUCCESS;
1433}
1434
1435/**
1436 * scic_sds_port_add_phy() -
1437 * @sci_port: This parameter specifies the port in which the phy will be added.
1438 * @sci_phy: This parameter is the phy which is to be added to the port.
1439 *
1440 * This method will add a PHY to the selected port. This method returns an
1441 * enum sci_status. SCI_SUCCESS the phy has been added to the port. Any other
1442 * status is a failure to add the phy to the port.
1443 */
1444enum sci_status scic_sds_port_add_phy(struct scic_sds_port *sci_port,
1445 struct scic_sds_phy *sci_phy)
1446{
1447 enum sci_status status;
1448 enum scic_sds_port_states state;
1449
Edmund Nadolskie3013702011-06-02 00:10:43 +00001450 state = sci_port->sm.current_state_id;
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001451 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +00001452 case SCI_PORT_STOPPED: {
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001453 struct sci_sas_address port_sas_address;
1454
1455 /* Read the port assigned SAS Address if there is one */
1456 scic_sds_port_get_sas_address(sci_port, &port_sas_address);
1457
1458 if (port_sas_address.high != 0 && port_sas_address.low != 0) {
1459 struct sci_sas_address phy_sas_address;
1460
1461 /* Make sure that the PHY SAS Address matches the SAS Address
1462 * for this port
1463 */
1464 scic_sds_phy_get_sas_address(sci_phy, &phy_sas_address);
1465
1466 if (port_sas_address.high != phy_sas_address.high ||
1467 port_sas_address.low != phy_sas_address.low)
1468 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
1469 }
1470 return scic_sds_port_set_phy(sci_port, sci_phy);
1471 }
Edmund Nadolskie3013702011-06-02 00:10:43 +00001472 case SCI_PORT_SUB_WAITING:
1473 case SCI_PORT_SUB_OPERATIONAL:
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001474 status = scic_sds_port_set_phy(sci_port, sci_phy);
1475
1476 if (status != SCI_SUCCESS)
1477 return status;
1478
1479 scic_sds_port_general_link_up_handler(sci_port, sci_phy, true);
1480 sci_port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001481 port_state_machine_change(sci_port, SCI_PORT_SUB_CONFIGURING);
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001482
1483 return status;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001484 case SCI_PORT_SUB_CONFIGURING:
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001485 status = scic_sds_port_set_phy(sci_port, sci_phy);
1486
1487 if (status != SCI_SUCCESS)
1488 return status;
1489 scic_sds_port_general_link_up_handler(sci_port, sci_phy, true);
1490
1491 /* Re-enter the configuring state since this may be the last phy in
1492 * the port.
1493 */
1494 port_state_machine_change(sci_port,
Edmund Nadolskie3013702011-06-02 00:10:43 +00001495 SCI_PORT_SUB_CONFIGURING);
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001496 return SCI_SUCCESS;
1497 default:
1498 dev_warn(sciport_to_dev(sci_port),
1499 "%s: in wrong state: %d\n", __func__, state);
1500 return SCI_FAILURE_INVALID_STATE;
1501 }
1502}
1503
1504/**
1505 * scic_sds_port_remove_phy() -
1506 * @sci_port: This parameter specifies the port in which the phy will be added.
1507 * @sci_phy: This parameter is the phy which is to be added to the port.
1508 *
1509 * This method will remove the PHY from the selected PORT. This method returns
1510 * an enum sci_status. SCI_SUCCESS the phy has been removed from the port. Any
1511 * other status is a failure to add the phy to the port.
1512 */
1513enum sci_status scic_sds_port_remove_phy(struct scic_sds_port *sci_port,
1514 struct scic_sds_phy *sci_phy)
1515{
1516 enum sci_status status;
1517 enum scic_sds_port_states state;
1518
Edmund Nadolskie3013702011-06-02 00:10:43 +00001519 state = sci_port->sm.current_state_id;
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001520
1521 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +00001522 case SCI_PORT_STOPPED:
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001523 return scic_sds_port_clear_phy(sci_port, sci_phy);
Edmund Nadolskie3013702011-06-02 00:10:43 +00001524 case SCI_PORT_SUB_OPERATIONAL:
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001525 status = scic_sds_port_clear_phy(sci_port, sci_phy);
1526 if (status != SCI_SUCCESS)
1527 return status;
1528
1529 scic_sds_port_deactivate_phy(sci_port, sci_phy, true);
1530 sci_port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
1531 port_state_machine_change(sci_port,
Edmund Nadolskie3013702011-06-02 00:10:43 +00001532 SCI_PORT_SUB_CONFIGURING);
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001533 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001534 case SCI_PORT_SUB_CONFIGURING:
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001535 status = scic_sds_port_clear_phy(sci_port, sci_phy);
1536
1537 if (status != SCI_SUCCESS)
1538 return status;
1539 scic_sds_port_deactivate_phy(sci_port, sci_phy, true);
1540
1541 /* Re-enter the configuring state since this may be the last phy in
1542 * the port
1543 */
1544 port_state_machine_change(sci_port,
Edmund Nadolskie3013702011-06-02 00:10:43 +00001545 SCI_PORT_SUB_CONFIGURING);
Piotr Sawicki051266c2011-05-12 19:10:14 +00001546 return SCI_SUCCESS;
1547 default:
1548 dev_warn(sciport_to_dev(sci_port),
1549 "%s: in wrong state: %d\n", __func__, state);
1550 return SCI_FAILURE_INVALID_STATE;
1551 }
1552}
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001553
Piotr Sawicki051266c2011-05-12 19:10:14 +00001554enum sci_status scic_sds_port_link_up(struct scic_sds_port *sci_port,
1555 struct scic_sds_phy *sci_phy)
1556{
1557 enum scic_sds_port_states state;
1558
Edmund Nadolskie3013702011-06-02 00:10:43 +00001559 state = sci_port->sm.current_state_id;
Piotr Sawicki051266c2011-05-12 19:10:14 +00001560 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +00001561 case SCI_PORT_SUB_WAITING:
Piotr Sawicki051266c2011-05-12 19:10:14 +00001562 /* Since this is the first phy going link up for the port we
1563 * can just enable it and continue
1564 */
1565 scic_sds_port_activate_phy(sci_port, sci_phy, true);
1566
1567 port_state_machine_change(sci_port,
Edmund Nadolskie3013702011-06-02 00:10:43 +00001568 SCI_PORT_SUB_OPERATIONAL);
Piotr Sawicki051266c2011-05-12 19:10:14 +00001569 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001570 case SCI_PORT_SUB_OPERATIONAL:
Piotr Sawicki051266c2011-05-12 19:10:14 +00001571 scic_sds_port_general_link_up_handler(sci_port, sci_phy, true);
1572 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001573 case SCI_PORT_RESETTING:
Piotr Sawicki051266c2011-05-12 19:10:14 +00001574 /* TODO We should make sure that the phy that has gone
1575 * link up is the same one on which we sent the reset. It is
1576 * possible that the phy on which we sent the reset is not the
1577 * one that has gone link up and we want to make sure that
1578 * phy being reset comes back. Consider the case where a
1579 * reset is sent but before the hardware processes the reset it
1580 * get a link up on the port because of a hot plug event.
1581 * because of the reset request this phy will go link down
1582 * almost immediately.
1583 */
1584
1585 /* In the resetting state we don't notify the user regarding
1586 * link up and link down notifications.
1587 */
1588 scic_sds_port_general_link_up_handler(sci_port, sci_phy, false);
1589 return SCI_SUCCESS;
1590 default:
1591 dev_warn(sciport_to_dev(sci_port),
1592 "%s: in wrong state: %d\n", __func__, state);
1593 return SCI_FAILURE_INVALID_STATE;
1594 }
1595}
1596
1597enum sci_status scic_sds_port_link_down(struct scic_sds_port *sci_port,
1598 struct scic_sds_phy *sci_phy)
1599{
1600 enum scic_sds_port_states state;
1601
Edmund Nadolskie3013702011-06-02 00:10:43 +00001602 state = sci_port->sm.current_state_id;
Piotr Sawicki051266c2011-05-12 19:10:14 +00001603 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +00001604 case SCI_PORT_SUB_OPERATIONAL:
Piotr Sawicki051266c2011-05-12 19:10:14 +00001605 scic_sds_port_deactivate_phy(sci_port, sci_phy, true);
1606
1607 /* If there are no active phys left in the port, then
1608 * transition the port to the WAITING state until such time
1609 * as a phy goes link up
1610 */
1611 if (sci_port->active_phy_mask == 0)
1612 port_state_machine_change(sci_port,
Edmund Nadolskie3013702011-06-02 00:10:43 +00001613 SCI_PORT_SUB_WAITING);
Piotr Sawicki051266c2011-05-12 19:10:14 +00001614 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001615 case SCI_PORT_RESETTING:
Piotr Sawicki051266c2011-05-12 19:10:14 +00001616 /* In the resetting state we don't notify the user regarding
1617 * link up and link down notifications. */
1618 scic_sds_port_deactivate_phy(sci_port, sci_phy, false);
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001619 return SCI_SUCCESS;
1620 default:
1621 dev_warn(sciport_to_dev(sci_port),
1622 "%s: in wrong state: %d\n", __func__, state);
1623 return SCI_FAILURE_INVALID_STATE;
1624 }
1625}
1626
Dan Williams68138202011-05-12 07:16:06 -07001627enum sci_status scic_sds_port_start_io(struct scic_sds_port *sci_port,
1628 struct scic_sds_remote_device *sci_dev,
1629 struct scic_sds_request *sci_req)
1630{
1631 enum scic_sds_port_states state;
Dan Williamse2f8db52011-05-10 02:28:46 -07001632
Edmund Nadolskie3013702011-06-02 00:10:43 +00001633 state = sci_port->sm.current_state_id;
Dan Williams68138202011-05-12 07:16:06 -07001634 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +00001635 case SCI_PORT_SUB_WAITING:
Dan Williams68138202011-05-12 07:16:06 -07001636 return SCI_FAILURE_INVALID_STATE;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001637 case SCI_PORT_SUB_OPERATIONAL:
Dan Williams68138202011-05-12 07:16:06 -07001638 sci_port->started_request_count++;
1639 return SCI_SUCCESS;
1640 default:
1641 dev_warn(sciport_to_dev(sci_port),
1642 "%s: in wrong state: %d\n", __func__, state);
1643 return SCI_FAILURE_INVALID_STATE;
1644 }
1645}
1646
1647enum sci_status scic_sds_port_complete_io(struct scic_sds_port *sci_port,
1648 struct scic_sds_remote_device *sci_dev,
1649 struct scic_sds_request *sci_req)
1650{
1651 enum scic_sds_port_states state;
1652
Edmund Nadolskie3013702011-06-02 00:10:43 +00001653 state = sci_port->sm.current_state_id;
Dan Williams68138202011-05-12 07:16:06 -07001654 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +00001655 case SCI_PORT_STOPPED:
Dan Williams68138202011-05-12 07:16:06 -07001656 dev_warn(sciport_to_dev(sci_port),
1657 "%s: in wrong state: %d\n", __func__, state);
1658 return SCI_FAILURE_INVALID_STATE;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001659 case SCI_PORT_STOPPING:
Dan Williams68138202011-05-12 07:16:06 -07001660 scic_sds_port_decrement_request_count(sci_port);
1661
1662 if (sci_port->started_request_count == 0)
1663 port_state_machine_change(sci_port,
Edmund Nadolskie3013702011-06-02 00:10:43 +00001664 SCI_PORT_STOPPED);
Dan Williams68138202011-05-12 07:16:06 -07001665 break;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001666 case SCI_PORT_READY:
1667 case SCI_PORT_RESETTING:
1668 case SCI_PORT_FAILED:
1669 case SCI_PORT_SUB_WAITING:
1670 case SCI_PORT_SUB_OPERATIONAL:
Dan Williams68138202011-05-12 07:16:06 -07001671 scic_sds_port_decrement_request_count(sci_port);
1672 break;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001673 case SCI_PORT_SUB_CONFIGURING:
Dan Williams68138202011-05-12 07:16:06 -07001674 scic_sds_port_decrement_request_count(sci_port);
1675 if (sci_port->started_request_count == 0) {
1676 port_state_machine_change(sci_port,
Edmund Nadolskie3013702011-06-02 00:10:43 +00001677 SCI_PORT_SUB_OPERATIONAL);
Dan Williams68138202011-05-12 07:16:06 -07001678 }
1679 break;
1680 }
1681 return SCI_SUCCESS;
1682}
Dan Williamse2f8db52011-05-10 02:28:46 -07001683
1684/**
1685 *
1686 * @sci_port: This is the port object which to suspend.
1687 *
1688 * This method will enable the SCU Port Task Scheduler for this port object but
1689 * will leave the port task scheduler in a suspended state. none
1690 */
1691static void
1692scic_sds_port_enable_port_task_scheduler(struct scic_sds_port *port)
1693{
1694 u32 pts_control_value;
1695
1696 pts_control_value = readl(&port->port_task_scheduler_registers->control);
1697 pts_control_value |= SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND);
1698 writel(pts_control_value, &port->port_task_scheduler_registers->control);
1699}
1700
1701/**
1702 *
1703 * @sci_port: This is the port object which to resume.
1704 *
1705 * This method will disable the SCU port task scheduler for this port object.
1706 * none
1707 */
1708static void
1709scic_sds_port_disable_port_task_scheduler(struct scic_sds_port *port)
1710{
1711 u32 pts_control_value;
1712
1713 pts_control_value = readl(&port->port_task_scheduler_registers->control);
1714 pts_control_value &=
1715 ~(SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND));
1716 writel(pts_control_value, &port->port_task_scheduler_registers->control);
1717}
1718
1719static void scic_sds_port_post_dummy_remote_node(struct scic_sds_port *sci_port)
1720{
1721 struct scic_sds_controller *scic = sci_port->owning_controller;
1722 u8 phys_index = sci_port->physical_port_index;
1723 union scu_remote_node_context *rnc;
1724 u16 rni = sci_port->reserved_rni;
1725 u32 command;
1726
1727 rnc = &scic->remote_node_context_table[rni];
1728 rnc->ssp.is_valid = true;
1729
1730 command = SCU_CONTEXT_COMMAND_POST_RNC_32 |
1731 phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
1732
1733 scic_sds_controller_post_request(scic, command);
1734
1735 /* ensure hardware has seen the post rnc command and give it
1736 * ample time to act before sending the suspend
1737 */
1738 readl(&scic->smu_registers->interrupt_status); /* flush */
1739 udelay(10);
1740
1741 command = SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX |
1742 phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
1743
1744 scic_sds_controller_post_request(scic, command);
1745}
1746
Dan Williams9269e0e2011-05-12 07:42:17 -07001747static void scic_sds_port_stopped_state_enter(struct sci_base_state_machine *sm)
Dan Williamse2f8db52011-05-10 02:28:46 -07001748{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001749 struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), sm);
Dan Williamse2f8db52011-05-10 02:28:46 -07001750
Edmund Nadolskie3013702011-06-02 00:10:43 +00001751 if (sci_port->sm.previous_state_id == SCI_PORT_STOPPING) {
Dan Williamse2f8db52011-05-10 02:28:46 -07001752 /*
1753 * If we enter this state becasuse of a request to stop
1754 * the port then we want to disable the hardwares port
1755 * task scheduler. */
1756 scic_sds_port_disable_port_task_scheduler(sci_port);
1757 }
1758}
1759
Dan Williams9269e0e2011-05-12 07:42:17 -07001760static void scic_sds_port_stopped_state_exit(struct sci_base_state_machine *sm)
Dan Williamse2f8db52011-05-10 02:28:46 -07001761{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001762 struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), sm);
Dan Williamse2f8db52011-05-10 02:28:46 -07001763
1764 /* Enable and suspend the port task scheduler */
1765 scic_sds_port_enable_port_task_scheduler(sci_port);
1766}
1767
Dan Williams9269e0e2011-05-12 07:42:17 -07001768static void scic_sds_port_ready_state_enter(struct sci_base_state_machine *sm)
Dan Williamse2f8db52011-05-10 02:28:46 -07001769{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001770 struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), sm);
Dan Williamse2f8db52011-05-10 02:28:46 -07001771 struct scic_sds_controller *scic = sci_port->owning_controller;
1772 struct isci_host *ihost = scic_to_ihost(scic);
1773 struct isci_port *iport = sci_port_to_iport(sci_port);
1774 u32 prev_state;
1775
Edmund Nadolskie3013702011-06-02 00:10:43 +00001776 prev_state = sci_port->sm.previous_state_id;
1777 if (prev_state == SCI_PORT_RESETTING)
Dan Williamse2f8db52011-05-10 02:28:46 -07001778 isci_port_hard_reset_complete(iport, SCI_SUCCESS);
1779 else
1780 isci_port_not_ready(ihost, iport);
1781
1782 /* Post and suspend the dummy remote node context for this port. */
1783 scic_sds_port_post_dummy_remote_node(sci_port);
1784
1785 /* Start the ready substate machine */
Piotr Sawickie91f41e2011-05-11 23:52:21 +00001786 port_state_machine_change(sci_port,
Edmund Nadolskie3013702011-06-02 00:10:43 +00001787 SCI_PORT_SUB_WAITING);
Dan Williamse2f8db52011-05-10 02:28:46 -07001788}
1789
Dan Williams9269e0e2011-05-12 07:42:17 -07001790static void scic_sds_port_resetting_state_exit(struct sci_base_state_machine *sm)
Dan Williamse2f8db52011-05-10 02:28:46 -07001791{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001792 struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), sm);
Dan Williamse2f8db52011-05-10 02:28:46 -07001793
Edmund Nadolski5553ba22011-05-19 11:59:10 +00001794 sci_del_timer(&sci_port->timer);
Dan Williamse2f8db52011-05-10 02:28:46 -07001795}
1796
Dan Williams9269e0e2011-05-12 07:42:17 -07001797static void scic_sds_port_stopping_state_exit(struct sci_base_state_machine *sm)
Dan Williamse2f8db52011-05-10 02:28:46 -07001798{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001799 struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), sm);
Dan Williamse2f8db52011-05-10 02:28:46 -07001800
Edmund Nadolski5553ba22011-05-19 11:59:10 +00001801 sci_del_timer(&sci_port->timer);
Dan Williamse2f8db52011-05-10 02:28:46 -07001802
1803 scic_sds_port_destroy_dummy_resources(sci_port);
1804}
1805
Dan Williams9269e0e2011-05-12 07:42:17 -07001806static void scic_sds_port_failed_state_enter(struct sci_base_state_machine *sm)
Dan Williamse2f8db52011-05-10 02:28:46 -07001807{
Edmund Nadolskie3013702011-06-02 00:10:43 +00001808 struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), sm);
Dan Williamse2f8db52011-05-10 02:28:46 -07001809 struct isci_port *iport = sci_port_to_iport(sci_port);
1810
Dan Williamse2f8db52011-05-10 02:28:46 -07001811 isci_port_hard_reset_complete(iport, SCI_FAILURE_TIMEOUT);
1812}
1813
1814/* --------------------------------------------------------------------------- */
1815
1816static const struct sci_base_state scic_sds_port_state_table[] = {
Edmund Nadolskie3013702011-06-02 00:10:43 +00001817 [SCI_PORT_STOPPED] = {
Dan Williamse2f8db52011-05-10 02:28:46 -07001818 .enter_state = scic_sds_port_stopped_state_enter,
1819 .exit_state = scic_sds_port_stopped_state_exit
1820 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001821 [SCI_PORT_STOPPING] = {
Dan Williamse2f8db52011-05-10 02:28:46 -07001822 .exit_state = scic_sds_port_stopping_state_exit
1823 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001824 [SCI_PORT_READY] = {
Dan Williamse2f8db52011-05-10 02:28:46 -07001825 .enter_state = scic_sds_port_ready_state_enter,
Piotr Sawickie91f41e2011-05-11 23:52:21 +00001826 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001827 [SCI_PORT_SUB_WAITING] = {
Piotr Sawickie91f41e2011-05-11 23:52:21 +00001828 .enter_state = scic_sds_port_ready_substate_waiting_enter,
1829 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001830 [SCI_PORT_SUB_OPERATIONAL] = {
Piotr Sawickie91f41e2011-05-11 23:52:21 +00001831 .enter_state = scic_sds_port_ready_substate_operational_enter,
1832 .exit_state = scic_sds_port_ready_substate_operational_exit
1833 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001834 [SCI_PORT_SUB_CONFIGURING] = {
Piotr Sawickie91f41e2011-05-11 23:52:21 +00001835 .enter_state = scic_sds_port_ready_substate_configuring_enter,
1836 .exit_state = scic_sds_port_ready_substate_configuring_exit
Dan Williamse2f8db52011-05-10 02:28:46 -07001837 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001838 [SCI_PORT_RESETTING] = {
Dan Williamse2f8db52011-05-10 02:28:46 -07001839 .exit_state = scic_sds_port_resetting_state_exit
1840 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001841 [SCI_PORT_FAILED] = {
Dan Williamse2f8db52011-05-10 02:28:46 -07001842 .enter_state = scic_sds_port_failed_state_enter,
1843 }
1844};
1845
1846void scic_sds_port_construct(struct scic_sds_port *sci_port, u8 index,
1847 struct scic_sds_controller *scic)
1848{
Edmund Nadolski12ef6542011-06-02 00:10:50 +00001849 sci_init_sm(&sci_port->sm, scic_sds_port_state_table, SCI_PORT_STOPPED);
Dan Williamse2f8db52011-05-10 02:28:46 -07001850
Dan Williamse2f8db52011-05-10 02:28:46 -07001851 sci_port->logical_port_index = SCIC_SDS_DUMMY_PORT;
1852 sci_port->physical_port_index = index;
1853 sci_port->active_phy_mask = 0;
Piotr Sawickie91f41e2011-05-11 23:52:21 +00001854 sci_port->ready_exit = false;
Dan Williamse2f8db52011-05-10 02:28:46 -07001855
1856 sci_port->owning_controller = scic;
1857
1858 sci_port->started_request_count = 0;
1859 sci_port->assigned_device_count = 0;
1860
1861 sci_port->reserved_rni = SCU_DUMMY_INDEX;
1862 sci_port->reserved_tci = SCU_DUMMY_INDEX;
1863
Edmund Nadolski5553ba22011-05-19 11:59:10 +00001864 sci_init_timer(&sci_port->timer, port_timeout);
1865
Dan Williamse2f8db52011-05-10 02:28:46 -07001866 sci_port->port_task_scheduler_registers = NULL;
1867
1868 for (index = 0; index < SCI_MAX_PHYS; index++)
1869 sci_port->phy_table[index] = NULL;
1870}
1871
1872void isci_port_init(struct isci_port *iport, struct isci_host *ihost, int index)
1873{
1874 INIT_LIST_HEAD(&iport->remote_dev_list);
1875 INIT_LIST_HEAD(&iport->domain_dev_list);
1876 spin_lock_init(&iport->state_lock);
1877 init_completion(&iport->start_complete);
1878 iport->isci_host = ihost;
1879 isci_port_change_state(iport, isci_freed);
Jeff Skirvin61aaff42011-06-21 12:16:33 -07001880 atomic_set(&iport->event, 0);
Dan Williamse2f8db52011-05-10 02:28:46 -07001881}
1882
1883/**
1884 * isci_port_get_state() - This function gets the status of the port object.
1885 * @isci_port: This parameter points to the isci_port object
1886 *
1887 * status of the object as a isci_status enum.
1888 */
1889enum isci_status isci_port_get_state(
1890 struct isci_port *isci_port)
1891{
1892 return isci_port->status;
1893}
1894
Dan Williamse2f8db52011-05-10 02:28:46 -07001895void scic_sds_port_broadcast_change_received(
1896 struct scic_sds_port *sci_port,
1897 struct scic_sds_phy *sci_phy)
1898{
1899 struct scic_sds_controller *scic = sci_port->owning_controller;
1900 struct isci_host *ihost = scic_to_ihost(scic);
1901
1902 /* notify the user. */
1903 isci_port_bc_change_received(ihost, sci_port, sci_phy);
1904}
1905
Dan Williams4393aa42011-03-31 13:10:44 -07001906int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *iport,
1907 struct isci_phy *iphy)
Dan Williams6f231dd2011-07-02 22:56:22 -07001908{
Dan Williams4393aa42011-03-31 13:10:44 -07001909 unsigned long flags;
Dan Williams6f231dd2011-07-02 22:56:22 -07001910 enum sci_status status;
Jeff Skirvinfd0527a2011-06-20 14:09:26 -07001911 int idx, ret = TMF_RESP_FUNC_COMPLETE;
Dan Williams6f231dd2011-07-02 22:56:22 -07001912
Dan Williams4393aa42011-03-31 13:10:44 -07001913 dev_dbg(&ihost->pdev->dev, "%s: iport = %p\n",
1914 __func__, iport);
Dan Williams6f231dd2011-07-02 22:56:22 -07001915
Dan Williams4393aa42011-03-31 13:10:44 -07001916 init_completion(&iport->hard_reset_complete);
Dan Williams6f231dd2011-07-02 22:56:22 -07001917
Dan Williams4393aa42011-03-31 13:10:44 -07001918 spin_lock_irqsave(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001919
1920 #define ISCI_PORT_RESET_TIMEOUT SCIC_SDS_SIGNATURE_FIS_TIMEOUT
Dan Williamse5313812011-05-07 10:11:43 -07001921 status = scic_port_hard_reset(&iport->sci, ISCI_PORT_RESET_TIMEOUT);
Dan Williams6f231dd2011-07-02 22:56:22 -07001922
Dan Williams4393aa42011-03-31 13:10:44 -07001923 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001924
1925 if (status == SCI_SUCCESS) {
Dan Williams4393aa42011-03-31 13:10:44 -07001926 wait_for_completion(&iport->hard_reset_complete);
Dan Williams6f231dd2011-07-02 22:56:22 -07001927
Dan Williams4393aa42011-03-31 13:10:44 -07001928 dev_dbg(&ihost->pdev->dev,
1929 "%s: iport = %p; hard reset completion\n",
1930 __func__, iport);
Dan Williams6f231dd2011-07-02 22:56:22 -07001931
Dan Williams4393aa42011-03-31 13:10:44 -07001932 if (iport->hard_reset_status != SCI_SUCCESS)
Dan Williams6f231dd2011-07-02 22:56:22 -07001933 ret = TMF_RESP_FUNC_FAILED;
1934 } else {
1935 ret = TMF_RESP_FUNC_FAILED;
1936
Dan Williams4393aa42011-03-31 13:10:44 -07001937 dev_err(&ihost->pdev->dev,
1938 "%s: iport = %p; scic_port_hard_reset call"
Dan Williams6f231dd2011-07-02 22:56:22 -07001939 " failed 0x%x\n",
Dan Williams4393aa42011-03-31 13:10:44 -07001940 __func__, iport, status);
Dan Williams6f231dd2011-07-02 22:56:22 -07001941
1942 }
1943
1944 /* If the hard reset for the port has failed, consider this
1945 * the same as link failures on all phys in the port.
1946 */
1947 if (ret != TMF_RESP_FUNC_COMPLETE) {
Jeff Skirvinfd0527a2011-06-20 14:09:26 -07001948
Dan Williams4393aa42011-03-31 13:10:44 -07001949 dev_err(&ihost->pdev->dev,
1950 "%s: iport = %p; hard reset failed "
Jeff Skirvinfd0527a2011-06-20 14:09:26 -07001951 "(0x%x) - driving explicit link fail for all phys\n",
1952 __func__, iport, iport->hard_reset_status);
Dan Williams6f231dd2011-07-02 22:56:22 -07001953
Jeff Skirvinfd0527a2011-06-20 14:09:26 -07001954 /* Down all phys in the port. */
1955 spin_lock_irqsave(&ihost->scic_lock, flags);
1956 for (idx = 0; idx < SCI_MAX_PHYS; ++idx) {
1957
1958 if (iport->sci.phy_table[idx] != NULL) {
1959
1960 scic_sds_phy_stop(
1961 iport->sci.phy_table[idx]);
1962 scic_sds_phy_start(
1963 iport->sci.phy_table[idx]);
1964 }
1965 }
1966 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001967 }
Dan Williams6f231dd2011-07-02 22:56:22 -07001968 return ret;
1969}
Dave Jiang09d7da12011-03-26 16:11:51 -07001970
Dan Williamse2f8db52011-05-10 02:28:46 -07001971/**
1972 * isci_port_deformed() - This function is called by libsas when a port becomes
1973 * inactive.
1974 * @phy: This parameter specifies the libsas phy with the inactive port.
1975 *
1976 */
1977void isci_port_deformed(struct asd_sas_phy *phy)
Dave Jiang09d7da12011-03-26 16:11:51 -07001978{
Dan Williamse2f8db52011-05-10 02:28:46 -07001979 pr_debug("%s: sas_phy = %p\n", __func__, phy);
1980}
1981
1982/**
1983 * isci_port_formed() - This function is called by libsas when a port becomes
1984 * active.
1985 * @phy: This parameter specifies the libsas phy with the active port.
1986 *
1987 */
1988void isci_port_formed(struct asd_sas_phy *phy)
1989{
1990 pr_debug("%s: sas_phy = %p, sas_port = %p\n", __func__, phy, phy->port);
Dave Jiang09d7da12011-03-26 16:11:51 -07001991}