blob: c434d5a0effa71bd3c3a18466f9940c02ef44f67 [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
Dan Williamsffe191c2011-06-29 13:09:25 -070086scic_sds_port_get_protocols(struct isci_port *iport,
Dan Williamse2f8db52011-05-10 02:28:46 -070087 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++) {
Dan Williamsffe191c2011-06-29 13:09:25 -070094 if (iport->phy_table[index] != NULL) {
95 scic_sds_phy_get_protocols(iport->phy_table[index],
Dan Williamse2f8db52011-05-10 02:28:46 -070096 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 Williamsffe191c2011-06-29 13:09:25 -0700110static u32 scic_sds_port_get_phys(struct isci_port *iport)
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++) {
Dan Williamsffe191c2011-06-29 13:09:25 -0700118 if (iport->phy_table[index] != NULL) {
Dan Williamse2f8db52011-05-10 02:28:46 -0700119 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 */
Dan Williamsffe191c2011-06-29 13:09:25 -0700139static enum sci_status scic_port_get_properties(struct isci_port *iport,
Dan Williamse2f8db52011-05-10 02:28:46 -0700140 struct scic_port_properties *prop)
Dan Williams6f231dd2011-07-02 22:56:22 -0700141{
Dan Williamsffe191c2011-06-29 13:09:25 -0700142 if (!iport || iport->logical_port_index == SCIC_SDS_DUMMY_PORT)
Dan Williamse2f8db52011-05-10 02:28:46 -0700143 return SCI_FAILURE_INVALID_PORT;
Dan Williams6f231dd2011-07-02 22:56:22 -0700144
Dan Williamsffe191c2011-06-29 13:09:25 -0700145 prop->index = iport->logical_port_index;
146 prop->phy_mask = scic_sds_port_get_phys(iport);
147 scic_sds_port_get_sas_address(iport, &prop->local.sas_address);
148 scic_sds_port_get_protocols(iport, &prop->local.protocols);
149 scic_sds_port_get_attached_sas_address(iport, &prop->remote.sas_address);
Dan Williams6f231dd2011-07-02 22:56:22 -0700150
Dan Williamse2f8db52011-05-10 02:28:46 -0700151 return SCI_SUCCESS;
Dan Williams6f231dd2011-07-02 22:56:22 -0700152}
153
Dan Williamsffe191c2011-06-29 13:09:25 -0700154static void scic_port_bcn_enable(struct isci_port *iport)
Jeff Skirvin61aaff42011-06-21 12:16:33 -0700155{
Dan Williams85280952011-06-28 15:05:53 -0700156 struct isci_phy *iphy;
Jeff Skirvin61aaff42011-06-21 12:16:33 -0700157 u32 val;
158 int i;
159
Dan Williamsffe191c2011-06-29 13:09:25 -0700160 for (i = 0; i < ARRAY_SIZE(iport->phy_table); i++) {
161 iphy = iport->phy_table[i];
Dan Williams85280952011-06-28 15:05:53 -0700162 if (!iphy)
Jeff Skirvin61aaff42011-06-21 12:16:33 -0700163 continue;
Dan Williams85280952011-06-28 15:05:53 -0700164 val = readl(&iphy->link_layer_registers->link_layer_control);
Jeff Skirvin61aaff42011-06-21 12:16:33 -0700165 /* clear the bit by writing 1. */
Dan Williams85280952011-06-28 15:05:53 -0700166 writel(val, &iphy->link_layer_registers->link_layer_control);
Jeff Skirvin61aaff42011-06-21 12:16:33 -0700167 }
168}
169
170/* called under scic_lock to stabilize phy:port associations */
171void isci_port_bcn_enable(struct isci_host *ihost, struct isci_port *iport)
172{
173 int i;
174
175 clear_bit(IPORT_BCN_BLOCKED, &iport->flags);
176 wake_up(&ihost->eventq);
177
178 if (!test_and_clear_bit(IPORT_BCN_PENDING, &iport->flags))
179 return;
180
Dan Williamsffe191c2011-06-29 13:09:25 -0700181 for (i = 0; i < ARRAY_SIZE(iport->phy_table); i++) {
182 struct isci_phy *iphy = iport->phy_table[i];
Jeff Skirvin61aaff42011-06-21 12:16:33 -0700183
Dan Williams85280952011-06-28 15:05:53 -0700184 if (!iphy)
Jeff Skirvin61aaff42011-06-21 12:16:33 -0700185 continue;
186
187 ihost->sas_ha.notify_port_event(&iphy->sas_phy,
188 PORTE_BROADCAST_RCVD);
189 break;
190 }
191}
192
Dan Williamsffe191c2011-06-29 13:09:25 -0700193static void isci_port_bc_change_received(struct isci_host *ihost,
194 struct isci_port *iport,
195 struct isci_phy *iphy)
Jeff Skirvin61aaff42011-06-21 12:16:33 -0700196{
Jeff Skirvin61aaff42011-06-21 12:16:33 -0700197 if (iport && test_bit(IPORT_BCN_BLOCKED, &iport->flags)) {
198 dev_dbg(&ihost->pdev->dev,
199 "%s: disabled BCN; isci_phy = %p, sas_phy = %p\n",
200 __func__, iphy, &iphy->sas_phy);
201 set_bit(IPORT_BCN_PENDING, &iport->flags);
202 atomic_inc(&iport->event);
203 wake_up(&ihost->eventq);
204 } else {
205 dev_dbg(&ihost->pdev->dev,
206 "%s: isci_phy = %p, sas_phy = %p\n",
207 __func__, iphy, &iphy->sas_phy);
208
209 ihost->sas_ha.notify_port_event(&iphy->sas_phy,
210 PORTE_BROADCAST_RCVD);
211 }
Dan Williamsffe191c2011-06-29 13:09:25 -0700212 scic_port_bcn_enable(iport);
Jeff Skirvin61aaff42011-06-21 12:16:33 -0700213}
214
Dan Williamse2f8db52011-05-10 02:28:46 -0700215static void isci_port_link_up(struct isci_host *isci_host,
Dan Williamsffe191c2011-06-29 13:09:25 -0700216 struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -0700217 struct isci_phy *iphy)
Dan Williams6f231dd2011-07-02 22:56:22 -0700218{
219 unsigned long flags;
220 struct scic_port_properties properties;
Dan Williams6f231dd2011-07-02 22:56:22 -0700221 unsigned long success = true;
222
Dan Williams85280952011-06-28 15:05:53 -0700223 BUG_ON(iphy->isci_port != NULL);
Bartosz Barcinski6cb4d6b2011-04-12 17:28:43 -0700224
Dan Williamsffe191c2011-06-29 13:09:25 -0700225 iphy->isci_port = iport;
Dan Williams6f231dd2011-07-02 22:56:22 -0700226
227 dev_dbg(&isci_host->pdev->dev,
228 "%s: isci_port = %p\n",
Dan Williamsffe191c2011-06-29 13:09:25 -0700229 __func__, iport);
Dan Williams6f231dd2011-07-02 22:56:22 -0700230
Dan Williams85280952011-06-28 15:05:53 -0700231 spin_lock_irqsave(&iphy->sas_phy.frame_rcvd_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700232
Dan Williams85280952011-06-28 15:05:53 -0700233 isci_port_change_state(iphy->isci_port, isci_starting);
Dan Williams6f231dd2011-07-02 22:56:22 -0700234
Dan Williamsffe191c2011-06-29 13:09:25 -0700235 scic_port_get_properties(iport, &properties);
Dan Williams6f231dd2011-07-02 22:56:22 -0700236
Dan Williams85280952011-06-28 15:05:53 -0700237 if (iphy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) {
Dan Williams150fc6f2011-02-25 10:25:21 -0800238 u64 attached_sas_address;
Dan Williams6f231dd2011-07-02 22:56:22 -0700239
Dan Williams85280952011-06-28 15:05:53 -0700240 iphy->sas_phy.oob_mode = SATA_OOB_MODE;
241 iphy->sas_phy.frame_rcvd_size = sizeof(struct dev_to_host_fis);
Dan Williams6f231dd2011-07-02 22:56:22 -0700242
243 /*
244 * For direct-attached SATA devices, the SCI core will
245 * automagically assign a SAS address to the end device
246 * for the purpose of creating a port. This SAS address
247 * will not be the same as assigned to the PHY and needs
248 * to be obtained from struct scic_port_properties properties.
249 */
Dan Williams150fc6f2011-02-25 10:25:21 -0800250 attached_sas_address = properties.remote.sas_address.high;
251 attached_sas_address <<= 32;
252 attached_sas_address |= properties.remote.sas_address.low;
253 swab64s(&attached_sas_address);
Dan Williams6f231dd2011-07-02 22:56:22 -0700254
Dan Williams85280952011-06-28 15:05:53 -0700255 memcpy(&iphy->sas_phy.attached_sas_addr,
Dan Williams150fc6f2011-02-25 10:25:21 -0800256 &attached_sas_address, sizeof(attached_sas_address));
Dan Williams85280952011-06-28 15:05:53 -0700257 } else if (iphy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
258 iphy->sas_phy.oob_mode = SAS_OOB_MODE;
259 iphy->sas_phy.frame_rcvd_size = sizeof(struct sas_identify_frame);
Dan Williams6f231dd2011-07-02 22:56:22 -0700260
261 /* Copy the attached SAS address from the IAF */
Dan Williams85280952011-06-28 15:05:53 -0700262 memcpy(iphy->sas_phy.attached_sas_addr,
263 iphy->frame_rcvd.iaf.sas_addr, SAS_ADDR_SIZE);
Dan Williams6f231dd2011-07-02 22:56:22 -0700264 } else {
265 dev_err(&isci_host->pdev->dev, "%s: unkown target\n", __func__);
266 success = false;
267 }
268
Dan Williams85280952011-06-28 15:05:53 -0700269 iphy->sas_phy.phy->negotiated_linkrate = sci_phy_linkrate(iphy);
Dan Williams83e51432011-02-18 09:25:13 -0800270
Dan Williams85280952011-06-28 15:05:53 -0700271 spin_unlock_irqrestore(&iphy->sas_phy.frame_rcvd_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700272
273 /* Notify libsas that we have an address frame, if indeed
274 * we've found an SSP, SMP, or STP target */
275 if (success)
Dan Williams85280952011-06-28 15:05:53 -0700276 isci_host->sas_ha.notify_port_event(&iphy->sas_phy,
Dan Williams6f231dd2011-07-02 22:56:22 -0700277 PORTE_BYTES_DMAED);
278}
279
280
281/**
282 * isci_port_link_down() - This function is called by the sci core when a link
283 * becomes inactive.
284 * @isci_host: This parameter specifies the isci host object.
285 * @phy: This parameter specifies the isci phy with the active link.
286 * @port: This parameter specifies the isci port with the active link.
287 *
288 */
Dan Williamse2f8db52011-05-10 02:28:46 -0700289static void isci_port_link_down(struct isci_host *isci_host,
290 struct isci_phy *isci_phy,
291 struct isci_port *isci_port)
Dan Williams6f231dd2011-07-02 22:56:22 -0700292{
293 struct isci_remote_device *isci_device;
294
295 dev_dbg(&isci_host->pdev->dev,
296 "%s: isci_port = %p\n", __func__, isci_port);
297
298 if (isci_port) {
299
300 /* check to see if this is the last phy on this port. */
Jeff Skirvin61aaff42011-06-21 12:16:33 -0700301 if (isci_phy->sas_phy.port &&
302 isci_phy->sas_phy.port->num_phys == 1) {
303 atomic_inc(&isci_port->event);
304 isci_port_bcn_enable(isci_host, isci_port);
Dan Williams6f231dd2011-07-02 22:56:22 -0700305
Jeff Skirvin61aaff42011-06-21 12:16:33 -0700306 /* change the state for all devices on this port. The
307 * next task sent to this device will be returned as
308 * SAS_TASK_UNDELIVERED, and the scsi mid layer will
309 * remove the target
Dan Williams6f231dd2011-07-02 22:56:22 -0700310 */
311 list_for_each_entry(isci_device,
312 &isci_port->remote_dev_list,
313 node) {
314 dev_dbg(&isci_host->pdev->dev,
315 "%s: isci_device = %p\n",
316 __func__, isci_device);
Dan Williams209fae12011-06-13 17:39:44 -0700317 set_bit(IDEV_GONE, &isci_device->flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700318 }
319 }
320 isci_port_change_state(isci_port, isci_stopping);
321 }
322
323 /* Notify libsas of the borken link, this will trigger calls to our
324 * isci_port_deformed and isci_dev_gone functions.
325 */
326 sas_phy_disconnected(&isci_phy->sas_phy);
327 isci_host->sas_ha.notify_phy_event(&isci_phy->sas_phy,
328 PHYE_LOSS_OF_SIGNAL);
329
330 isci_phy->isci_port = NULL;
331
332 dev_dbg(&isci_host->pdev->dev,
333 "%s: isci_port = %p - Done\n", __func__, isci_port);
334}
335
336
337/**
Dan Williams6f231dd2011-07-02 22:56:22 -0700338 * isci_port_ready() - This function is called by the sci core when a link
339 * becomes ready.
340 * @isci_host: This parameter specifies the isci host object.
341 * @port: This parameter specifies the sci port with the active link.
342 *
343 */
Dan Williamse2f8db52011-05-10 02:28:46 -0700344static void isci_port_ready(struct isci_host *isci_host, struct isci_port *isci_port)
Dan Williams6f231dd2011-07-02 22:56:22 -0700345{
346 dev_dbg(&isci_host->pdev->dev,
347 "%s: isci_port = %p\n", __func__, isci_port);
348
349 complete_all(&isci_port->start_complete);
350 isci_port_change_state(isci_port, isci_ready);
351 return;
352}
353
354/**
355 * isci_port_not_ready() - This function is called by the sci core when a link
356 * is not ready. All remote devices on this link will be removed if they are
357 * in the stopping state.
358 * @isci_host: This parameter specifies the isci host object.
359 * @port: This parameter specifies the sci port with the active link.
360 *
361 */
Dan Williamse2f8db52011-05-10 02:28:46 -0700362static void isci_port_not_ready(struct isci_host *isci_host, struct isci_port *isci_port)
Dan Williams6f231dd2011-07-02 22:56:22 -0700363{
364 dev_dbg(&isci_host->pdev->dev,
365 "%s: isci_port = %p\n", __func__, isci_port);
366}
367
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700368static void isci_port_stop_complete(struct isci_host *ihost,
Dan Williamsffe191c2011-06-29 13:09:25 -0700369 struct isci_port *iport,
Dan Williamse2f8db52011-05-10 02:28:46 -0700370 enum sci_status completion_status)
371{
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700372 dev_dbg(&ihost->pdev->dev, "Port stop complete\n");
Dan Williamse2f8db52011-05-10 02:28:46 -0700373}
374
Dan Williams6f231dd2011-07-02 22:56:22 -0700375/**
376 * isci_port_hard_reset_complete() - This function is called by the sci core
377 * when the hard reset complete notification has been received.
378 * @port: This parameter specifies the sci port with the active link.
379 * @completion_status: This parameter specifies the core status for the reset
380 * process.
381 *
382 */
Dan Williamse2f8db52011-05-10 02:28:46 -0700383static void isci_port_hard_reset_complete(struct isci_port *isci_port,
384 enum sci_status completion_status)
Dan Williams6f231dd2011-07-02 22:56:22 -0700385{
386 dev_dbg(&isci_port->isci_host->pdev->dev,
387 "%s: isci_port = %p, completion_status=%x\n",
388 __func__, isci_port, completion_status);
389
390 /* Save the status of the hard reset from the port. */
391 isci_port->hard_reset_status = completion_status;
392
393 complete_all(&isci_port->hard_reset_complete);
394}
Dan Williams4393aa42011-03-31 13:10:44 -0700395
Dan Williamse2f8db52011-05-10 02:28:46 -0700396/* This method will return a true value if the specified phy can be assigned to
397 * this port The following is a list of phys for each port that are allowed: -
398 * Port 0 - 3 2 1 0 - Port 1 - 1 - Port 2 - 3 2 - Port 3 - 3 This method
399 * doesn't preclude all configurations. It merely ensures that a phy is part
400 * of the allowable set of phy identifiers for that port. For example, one
401 * could assign phy 3 to port 0 and no other phys. Please refer to
402 * scic_sds_port_is_phy_mask_valid() for information regarding whether the
403 * phy_mask for a port can be supported. bool true if this is a valid phy
404 * assignment for the port false if this is not a valid phy assignment for the
405 * port
406 */
Dan Williamsffe191c2011-06-29 13:09:25 -0700407bool scic_sds_port_is_valid_phy_assignment(struct isci_port *iport,
Dan Williamse2f8db52011-05-10 02:28:46 -0700408 u32 phy_index)
409{
410 /* Initialize to invalid value. */
411 u32 existing_phy_index = SCI_MAX_PHYS;
412 u32 index;
413
Dan Williamsffe191c2011-06-29 13:09:25 -0700414 if ((iport->physical_port_index == 1) && (phy_index != 1)) {
Dan Williamse2f8db52011-05-10 02:28:46 -0700415 return false;
416 }
417
Dan Williamsffe191c2011-06-29 13:09:25 -0700418 if (iport->physical_port_index == 3 && phy_index != 3) {
Dan Williamse2f8db52011-05-10 02:28:46 -0700419 return false;
420 }
421
422 if (
Dan Williamsffe191c2011-06-29 13:09:25 -0700423 (iport->physical_port_index == 2)
Dan Williamse2f8db52011-05-10 02:28:46 -0700424 && ((phy_index == 0) || (phy_index == 1))
425 ) {
426 return false;
427 }
428
429 for (index = 0; index < SCI_MAX_PHYS; index++) {
Dan Williamsffe191c2011-06-29 13:09:25 -0700430 if ((iport->phy_table[index] != NULL)
Dan Williamse2f8db52011-05-10 02:28:46 -0700431 && (index != phy_index)) {
432 existing_phy_index = index;
433 }
434 }
435
436 /*
437 * Ensure that all of the phys in the port are capable of
438 * operating at the same maximum link rate. */
439 if (
440 (existing_phy_index < SCI_MAX_PHYS)
Dan Williamsffe191c2011-06-29 13:09:25 -0700441 && (iport->owning_controller->user_parameters.sds1.phys[
Dan Williamse2f8db52011-05-10 02:28:46 -0700442 phy_index].max_speed_generation !=
Dan Williamsffe191c2011-06-29 13:09:25 -0700443 iport->owning_controller->user_parameters.sds1.phys[
Dan Williamse2f8db52011-05-10 02:28:46 -0700444 existing_phy_index].max_speed_generation)
445 )
446 return false;
447
448 return true;
449}
450
451/**
452 *
453 * @sci_port: This is the port object for which to determine if the phy mask
454 * can be supported.
455 *
456 * This method will return a true value if the port's phy mask can be supported
457 * by the SCU. The following is a list of valid PHY mask configurations for
458 * each port: - Port 0 - [[3 2] 1] 0 - Port 1 - [1] - Port 2 - [[3] 2]
459 * - Port 3 - [3] This method returns a boolean indication specifying if the
460 * phy mask can be supported. true if this is a valid phy assignment for the
461 * port false if this is not a valid phy assignment for the port
462 */
463static bool scic_sds_port_is_phy_mask_valid(
Dan Williamsffe191c2011-06-29 13:09:25 -0700464 struct isci_port *iport,
Dan Williamse2f8db52011-05-10 02:28:46 -0700465 u32 phy_mask)
466{
Dan Williamsffe191c2011-06-29 13:09:25 -0700467 if (iport->physical_port_index == 0) {
Dan Williamse2f8db52011-05-10 02:28:46 -0700468 if (((phy_mask & 0x0F) == 0x0F)
469 || ((phy_mask & 0x03) == 0x03)
470 || ((phy_mask & 0x01) == 0x01)
471 || (phy_mask == 0))
472 return true;
Dan Williamsffe191c2011-06-29 13:09:25 -0700473 } else if (iport->physical_port_index == 1) {
Dan Williamse2f8db52011-05-10 02:28:46 -0700474 if (((phy_mask & 0x02) == 0x02)
475 || (phy_mask == 0))
476 return true;
Dan Williamsffe191c2011-06-29 13:09:25 -0700477 } else if (iport->physical_port_index == 2) {
Dan Williamse2f8db52011-05-10 02:28:46 -0700478 if (((phy_mask & 0x0C) == 0x0C)
479 || ((phy_mask & 0x04) == 0x04)
480 || (phy_mask == 0))
481 return true;
Dan Williamsffe191c2011-06-29 13:09:25 -0700482 } else if (iport->physical_port_index == 3) {
Dan Williamse2f8db52011-05-10 02:28:46 -0700483 if (((phy_mask & 0x08) == 0x08)
484 || (phy_mask == 0))
485 return true;
486 }
487
488 return false;
489}
490
Dan Williams85280952011-06-28 15:05:53 -0700491/*
Dan Williamse2f8db52011-05-10 02:28:46 -0700492 * This method retrieves a currently active (i.e. connected) phy contained in
493 * the port. Currently, the lowest order phy that is connected is returned.
494 * This method returns a pointer to a SCIS_SDS_PHY object. NULL This value is
495 * returned if there are no currently active (i.e. connected to a remote end
496 * point) phys contained in the port. All other values specify a struct scic_sds_phy
497 * object that is active in the port.
498 */
Dan Williamsffe191c2011-06-29 13:09:25 -0700499static struct isci_phy *scic_sds_port_get_a_connected_phy(struct isci_port *iport)
Dan Williams85280952011-06-28 15:05:53 -0700500{
Dan Williamse2f8db52011-05-10 02:28:46 -0700501 u32 index;
Dan Williams85280952011-06-28 15:05:53 -0700502 struct isci_phy *iphy;
Dan Williamse2f8db52011-05-10 02:28:46 -0700503
504 for (index = 0; index < SCI_MAX_PHYS; index++) {
Dan Williams85280952011-06-28 15:05:53 -0700505 /* Ensure that the phy is both part of the port and currently
506 * connected to the remote end-point.
507 */
Dan Williamsffe191c2011-06-29 13:09:25 -0700508 iphy = iport->phy_table[index];
509 if (iphy && scic_sds_port_active_phy(iport, iphy))
Dan Williams85280952011-06-28 15:05:53 -0700510 return iphy;
Dan Williamse2f8db52011-05-10 02:28:46 -0700511 }
512
513 return NULL;
514}
515
Dan Williamsffe191c2011-06-29 13:09:25 -0700516static enum sci_status scic_sds_port_set_phy(struct isci_port *iport, struct isci_phy *iphy)
Dan Williamse2f8db52011-05-10 02:28:46 -0700517{
Dan Williams85280952011-06-28 15:05:53 -0700518 /* Check to see if we can add this phy to a port
Dan Williamse2f8db52011-05-10 02:28:46 -0700519 * that means that the phy is not part of a port and that the port does
Dan Williams85280952011-06-28 15:05:53 -0700520 * not already have a phy assinged to the phy index.
521 */
Dan Williamsffe191c2011-06-29 13:09:25 -0700522 if (!iport->phy_table[iphy->phy_index] &&
Dan Williams85280952011-06-28 15:05:53 -0700523 !phy_get_non_dummy_port(iphy) &&
Dan Williamsffe191c2011-06-29 13:09:25 -0700524 scic_sds_port_is_valid_phy_assignment(iport, iphy->phy_index)) {
Dan Williams85280952011-06-28 15:05:53 -0700525 /* Phy is being added in the stopped state so we are in MPC mode
526 * make logical port index = physical port index
527 */
Dan Williamsffe191c2011-06-29 13:09:25 -0700528 iport->logical_port_index = iport->physical_port_index;
529 iport->phy_table[iphy->phy_index] = iphy;
530 scic_sds_phy_set_port(iphy, iport);
Dan Williamse2f8db52011-05-10 02:28:46 -0700531
532 return SCI_SUCCESS;
533 }
534
535 return SCI_FAILURE;
536}
537
Dan Williamsffe191c2011-06-29 13:09:25 -0700538static enum sci_status scic_sds_port_clear_phy(struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -0700539 struct isci_phy *iphy)
Dan Williamse2f8db52011-05-10 02:28:46 -0700540{
541 /* Make sure that this phy is part of this port */
Dan Williamsffe191c2011-06-29 13:09:25 -0700542 if (iport->phy_table[iphy->phy_index] == iphy &&
543 phy_get_non_dummy_port(iphy) == iport) {
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700544 struct isci_host *ihost = iport->owning_controller;
Dan Williamse2f8db52011-05-10 02:28:46 -0700545
546 /* Yep it is assigned to this port so remove it */
Dan Williamsffe191c2011-06-29 13:09:25 -0700547 scic_sds_phy_set_port(iphy, &ihost->ports[SCI_MAX_PORTS]);
548 iport->phy_table[iphy->phy_index] = NULL;
Dan Williamse2f8db52011-05-10 02:28:46 -0700549 return SCI_SUCCESS;
550 }
551
552 return SCI_FAILURE;
553}
554
Dan Williamse2f8db52011-05-10 02:28:46 -0700555
556/**
557 * This method requests the SAS address for the supplied SAS port from the SCI
558 * implementation.
559 * @sci_port: a handle corresponding to the SAS port for which to return the
560 * SAS address.
561 * @sas_address: This parameter specifies a pointer to a SAS address structure
562 * into which the core will copy the SAS address for the port.
563 *
564 */
565void scic_sds_port_get_sas_address(
Dan Williamsffe191c2011-06-29 13:09:25 -0700566 struct isci_port *iport,
Dan Williamse2f8db52011-05-10 02:28:46 -0700567 struct sci_sas_address *sas_address)
568{
569 u32 index;
570
571 sas_address->high = 0;
572 sas_address->low = 0;
573
574 for (index = 0; index < SCI_MAX_PHYS; index++) {
Dan Williamsffe191c2011-06-29 13:09:25 -0700575 if (iport->phy_table[index] != NULL) {
576 scic_sds_phy_get_sas_address(iport->phy_table[index], sas_address);
Dan Williamse2f8db52011-05-10 02:28:46 -0700577 }
578 }
579}
580
581/*
582 * This function requests the SAS address for the device directly attached to
583 * this SAS port.
584 * @sci_port: a handle corresponding to the SAS port for which to return the
585 * SAS address.
586 * @sas_address: This parameter specifies a pointer to a SAS address structure
587 * into which the core will copy the SAS address for the device directly
588 * attached to the port.
589 *
590 */
591void scic_sds_port_get_attached_sas_address(
Dan Williamsffe191c2011-06-29 13:09:25 -0700592 struct isci_port *iport,
Dan Williamse2f8db52011-05-10 02:28:46 -0700593 struct sci_sas_address *sas_address)
594{
Dan Williams85280952011-06-28 15:05:53 -0700595 struct isci_phy *iphy;
Dan Williamse2f8db52011-05-10 02:28:46 -0700596
597 /*
598 * Ensure that the phy is both part of the port and currently
599 * connected to the remote end-point.
600 */
Dan Williamsffe191c2011-06-29 13:09:25 -0700601 iphy = scic_sds_port_get_a_connected_phy(iport);
Dan Williams85280952011-06-28 15:05:53 -0700602 if (iphy) {
603 if (iphy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA) {
604 scic_sds_phy_get_attached_sas_address(iphy,
Dan Williamse2f8db52011-05-10 02:28:46 -0700605 sas_address);
606 } else {
Dan Williams85280952011-06-28 15:05:53 -0700607 scic_sds_phy_get_sas_address(iphy, sas_address);
608 sas_address->low += iphy->phy_index;
Dan Williamse2f8db52011-05-10 02:28:46 -0700609 }
610 } else {
611 sas_address->high = 0;
612 sas_address->low = 0;
613 }
614}
615
616/**
617 * scic_sds_port_construct_dummy_rnc() - create dummy rnc for si workaround
618 *
619 * @sci_port: logical port on which we need to create the remote node context
620 * @rni: remote node index for this remote node context.
621 *
622 * This routine will construct a dummy remote node context data structure
623 * This structure will be posted to the hardware to work around a scheduler
624 * error in the hardware.
625 */
Dan Williamsffe191c2011-06-29 13:09:25 -0700626static void scic_sds_port_construct_dummy_rnc(struct isci_port *iport, u16 rni)
Dan Williamse2f8db52011-05-10 02:28:46 -0700627{
628 union scu_remote_node_context *rnc;
629
Dan Williamsffe191c2011-06-29 13:09:25 -0700630 rnc = &iport->owning_controller->remote_node_context_table[rni];
Dan Williamse2f8db52011-05-10 02:28:46 -0700631
632 memset(rnc, 0, sizeof(union scu_remote_node_context));
633
634 rnc->ssp.remote_sas_address_hi = 0;
635 rnc->ssp.remote_sas_address_lo = 0;
636
637 rnc->ssp.remote_node_index = rni;
638 rnc->ssp.remote_node_port_width = 1;
Dan Williamsffe191c2011-06-29 13:09:25 -0700639 rnc->ssp.logical_port_index = iport->physical_port_index;
Dan Williamse2f8db52011-05-10 02:28:46 -0700640
641 rnc->ssp.nexus_loss_timer_enable = false;
642 rnc->ssp.check_bit = false;
643 rnc->ssp.is_valid = true;
644 rnc->ssp.is_remote_node_context = true;
645 rnc->ssp.function_number = 0;
646 rnc->ssp.arbitration_wait_time = 0;
647}
648
Dan Williamsdd047c82011-06-09 11:06:58 -0700649/*
650 * construct a dummy task context data structure. This
Dan Williamse2f8db52011-05-10 02:28:46 -0700651 * structure will be posted to the hardwre to work around a scheduler error
652 * in the hardware.
Dan Williamse2f8db52011-05-10 02:28:46 -0700653 */
Dan Williamsffe191c2011-06-29 13:09:25 -0700654static void scic_sds_port_construct_dummy_task(struct isci_port *iport, u16 tag)
Dan Williamse2f8db52011-05-10 02:28:46 -0700655{
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700656 struct isci_host *ihost = iport->owning_controller;
Dan Williamse2f8db52011-05-10 02:28:46 -0700657 struct scu_task_context *task_context;
658
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700659 task_context = &ihost->task_context_table[ISCI_TAG_TCI(tag)];
Dan Williamse2f8db52011-05-10 02:28:46 -0700660 memset(task_context, 0, sizeof(struct scu_task_context));
661
Dan Williamse2f8db52011-05-10 02:28:46 -0700662 task_context->initiator_request = 1;
663 task_context->connection_rate = 1;
Dan Williamsffe191c2011-06-29 13:09:25 -0700664 task_context->logical_port_index = iport->physical_port_index;
Dan Williamse2f8db52011-05-10 02:28:46 -0700665 task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SSP;
Dan Williamsdd047c82011-06-09 11:06:58 -0700666 task_context->task_index = ISCI_TAG_TCI(tag);
Dan Williamse2f8db52011-05-10 02:28:46 -0700667 task_context->valid = SCU_TASK_CONTEXT_VALID;
668 task_context->context_type = SCU_TASK_CONTEXT_TYPE;
Dan Williamsffe191c2011-06-29 13:09:25 -0700669 task_context->remote_node_index = iport->reserved_rni;
Dan Williamse2f8db52011-05-10 02:28:46 -0700670 task_context->do_not_dma_ssp_good_response = 1;
Dan Williamse2f8db52011-05-10 02:28:46 -0700671 task_context->task_phase = 0x01;
672}
673
Dan Williamsffe191c2011-06-29 13:09:25 -0700674static void scic_sds_port_destroy_dummy_resources(struct isci_port *iport)
Dan Williamse2f8db52011-05-10 02:28:46 -0700675{
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700676 struct isci_host *ihost = iport->owning_controller;
Dan Williamse2f8db52011-05-10 02:28:46 -0700677
Dan Williamsffe191c2011-06-29 13:09:25 -0700678 if (iport->reserved_tag != SCI_CONTROLLER_INVALID_IO_TAG)
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700679 isci_free_tag(ihost, iport->reserved_tag);
Dan Williamse2f8db52011-05-10 02:28:46 -0700680
Dan Williamsffe191c2011-06-29 13:09:25 -0700681 if (iport->reserved_rni != SCU_DUMMY_INDEX)
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700682 scic_sds_remote_node_table_release_remote_node_index(&ihost->available_remote_nodes,
Dan Williamsffe191c2011-06-29 13:09:25 -0700683 1, iport->reserved_rni);
Dan Williamse2f8db52011-05-10 02:28:46 -0700684
Dan Williamsffe191c2011-06-29 13:09:25 -0700685 iport->reserved_rni = SCU_DUMMY_INDEX;
686 iport->reserved_tag = SCI_CONTROLLER_INVALID_IO_TAG;
Dan Williamse2f8db52011-05-10 02:28:46 -0700687}
688
689/**
690 * This method performs initialization of the supplied port. Initialization
691 * includes: - state machine initialization - member variable initialization
692 * - configuring the phy_mask
693 * @sci_port:
694 * @transport_layer_registers:
695 * @port_task_scheduler_registers:
696 * @port_configuration_regsiter:
697 *
698 * enum sci_status SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION This value is returned
699 * if the phy being added to the port
700 */
701enum sci_status scic_sds_port_initialize(
Dan Williamsffe191c2011-06-29 13:09:25 -0700702 struct isci_port *iport,
Dan Williamse2f8db52011-05-10 02:28:46 -0700703 void __iomem *port_task_scheduler_registers,
704 void __iomem *port_configuration_regsiter,
705 void __iomem *viit_registers)
706{
Dan Williamsffe191c2011-06-29 13:09:25 -0700707 iport->port_task_scheduler_registers = port_task_scheduler_registers;
708 iport->port_pe_configuration_register = port_configuration_regsiter;
709 iport->viit_registers = viit_registers;
Dan Williamse2f8db52011-05-10 02:28:46 -0700710
711 return SCI_SUCCESS;
712}
713
Dan Williamse2f8db52011-05-10 02:28:46 -0700714
715/**
716 * This method assigns the direct attached device ID for this port.
717 *
Dan Williamsffe191c2011-06-29 13:09:25 -0700718 * @param[in] iport The port for which the direct attached device id is to
Dan Williamse2f8db52011-05-10 02:28:46 -0700719 * be assigned.
720 * @param[in] device_id The direct attached device ID to assign to the port.
721 * This will be the RNi for the device
722 */
723void scic_sds_port_setup_transports(
Dan Williamsffe191c2011-06-29 13:09:25 -0700724 struct isci_port *iport,
Dan Williamse2f8db52011-05-10 02:28:46 -0700725 u32 device_id)
726{
727 u8 index;
728
729 for (index = 0; index < SCI_MAX_PHYS; index++) {
Dan Williamsffe191c2011-06-29 13:09:25 -0700730 if (iport->active_phy_mask & (1 << index))
731 scic_sds_phy_setup_transport(iport->phy_table[index], device_id);
Dan Williamse2f8db52011-05-10 02:28:46 -0700732 }
733}
734
735/**
736 *
737 * @sci_port: This is the port on which the phy should be enabled.
738 * @sci_phy: This is the specific phy which to enable.
739 * @do_notify_user: This parameter specifies whether to inform the user (via
740 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
741 *
742 * This function will activate the phy in the port.
743 * Activation includes: - adding
744 * the phy to the port - enabling the Protocol Engine in the silicon. -
745 * notifying the user that the link is up. none
746 */
Dan Williamsffe191c2011-06-29 13:09:25 -0700747static void scic_sds_port_activate_phy(struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -0700748 struct isci_phy *iphy,
Dan Williamse2f8db52011-05-10 02:28:46 -0700749 bool do_notify_user)
750{
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700751 struct isci_host *ihost = iport->owning_controller;
Dan Williamse2f8db52011-05-10 02:28:46 -0700752
Dan Williams85280952011-06-28 15:05:53 -0700753 if (iphy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA)
754 scic_sds_phy_resume(iphy);
Dan Williamse2f8db52011-05-10 02:28:46 -0700755
Dan Williamsffe191c2011-06-29 13:09:25 -0700756 iport->active_phy_mask |= 1 << iphy->phy_index;
Dan Williamse2f8db52011-05-10 02:28:46 -0700757
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700758 scic_sds_controller_clear_invalid_phy(ihost, iphy);
Dan Williamse2f8db52011-05-10 02:28:46 -0700759
760 if (do_notify_user == true)
Dan Williamsffe191c2011-06-29 13:09:25 -0700761 isci_port_link_up(ihost, iport, iphy);
Dan Williamse2f8db52011-05-10 02:28:46 -0700762}
763
Dan Williamsffe191c2011-06-29 13:09:25 -0700764void scic_sds_port_deactivate_phy(struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -0700765 struct isci_phy *iphy,
Dan Williamse2f8db52011-05-10 02:28:46 -0700766 bool do_notify_user)
767{
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700768 struct isci_host *ihost = scic_sds_port_get_controller(iport);
Dan Williamse2f8db52011-05-10 02:28:46 -0700769
Dan Williamsffe191c2011-06-29 13:09:25 -0700770 iport->active_phy_mask &= ~(1 << iphy->phy_index);
Dan Williamse2f8db52011-05-10 02:28:46 -0700771
Dan Williams85280952011-06-28 15:05:53 -0700772 iphy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
Dan Williamse2f8db52011-05-10 02:28:46 -0700773
774 /* Re-assign the phy back to the LP as if it were a narrow port */
Dan Williams85280952011-06-28 15:05:53 -0700775 writel(iphy->phy_index,
Dan Williamsffe191c2011-06-29 13:09:25 -0700776 &iport->port_pe_configuration_register[iphy->phy_index]);
Dan Williamse2f8db52011-05-10 02:28:46 -0700777
778 if (do_notify_user == true)
779 isci_port_link_down(ihost, iphy, iport);
780}
781
782/**
783 *
784 * @sci_port: This is the port on which the phy should be disabled.
785 * @sci_phy: This is the specific phy which to disabled.
786 *
787 * This function will disable the phy and report that the phy is not valid for
788 * this port object. None
789 */
Dan Williamsffe191c2011-06-29 13:09:25 -0700790static void scic_sds_port_invalid_link_up(struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -0700791 struct isci_phy *iphy)
Dan Williamse2f8db52011-05-10 02:28:46 -0700792{
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700793 struct isci_host *ihost = iport->owning_controller;
Dan Williamse2f8db52011-05-10 02:28:46 -0700794
795 /*
796 * Check to see if we have alreay reported this link as bad and if
797 * not go ahead and tell the SCI_USER that we have discovered an
798 * invalid link.
799 */
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700800 if ((ihost->invalid_phy_mask & (1 << iphy->phy_index)) == 0) {
801 scic_sds_controller_set_invalid_phy(ihost, iphy);
802 dev_warn(&ihost->pdev->dev, "Invalid link up!\n");
Dan Williamse2f8db52011-05-10 02:28:46 -0700803 }
804}
805
Piotr Sawickie91f41e2011-05-11 23:52:21 +0000806static bool is_port_ready_state(enum scic_sds_port_states state)
807{
808 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +0000809 case SCI_PORT_READY:
810 case SCI_PORT_SUB_WAITING:
811 case SCI_PORT_SUB_OPERATIONAL:
812 case SCI_PORT_SUB_CONFIGURING:
Piotr Sawickie91f41e2011-05-11 23:52:21 +0000813 return true;
814 default:
815 return false;
816 }
817}
818
819/* flag dummy rnc hanling when exiting a ready state */
Dan Williamsffe191c2011-06-29 13:09:25 -0700820static void port_state_machine_change(struct isci_port *iport,
Piotr Sawickie91f41e2011-05-11 23:52:21 +0000821 enum scic_sds_port_states state)
822{
Dan Williamsffe191c2011-06-29 13:09:25 -0700823 struct sci_base_state_machine *sm = &iport->sm;
Piotr Sawickie91f41e2011-05-11 23:52:21 +0000824 enum scic_sds_port_states old_state = sm->current_state_id;
825
826 if (is_port_ready_state(old_state) && !is_port_ready_state(state))
Dan Williamsffe191c2011-06-29 13:09:25 -0700827 iport->ready_exit = true;
Piotr Sawickie91f41e2011-05-11 23:52:21 +0000828
Edmund Nadolskie3013702011-06-02 00:10:43 +0000829 sci_change_state(sm, state);
Dan Williamsffe191c2011-06-29 13:09:25 -0700830 iport->ready_exit = false;
Piotr Sawickie91f41e2011-05-11 23:52:21 +0000831}
832
Dan Williamse2f8db52011-05-10 02:28:46 -0700833/**
834 * scic_sds_port_general_link_up_handler - phy can be assigned to port?
835 * @sci_port: scic_sds_port object for which has a phy that has gone link up.
Dan Williams85280952011-06-28 15:05:53 -0700836 * @sci_phy: This is the struct isci_phy object that has gone link up.
Dan Williamse2f8db52011-05-10 02:28:46 -0700837 * @do_notify_user: This parameter specifies whether to inform the user (via
838 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
839 *
840 * Determine if this phy can be assigned to this
841 * port . If the phy is not a valid PHY for
842 * this port then the function will notify the user. A PHY can only be
843 * part of a port if it's attached SAS ADDRESS is the same as all other PHYs in
844 * the same port. none
845 */
Dan Williamsffe191c2011-06-29 13:09:25 -0700846static void scic_sds_port_general_link_up_handler(struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -0700847 struct isci_phy *iphy,
Dan Williamse2f8db52011-05-10 02:28:46 -0700848 bool do_notify_user)
849{
850 struct sci_sas_address port_sas_address;
851 struct sci_sas_address phy_sas_address;
852
Dan Williamsffe191c2011-06-29 13:09:25 -0700853 scic_sds_port_get_attached_sas_address(iport, &port_sas_address);
Dan Williams85280952011-06-28 15:05:53 -0700854 scic_sds_phy_get_attached_sas_address(iphy, &phy_sas_address);
Dan Williamse2f8db52011-05-10 02:28:46 -0700855
856 /* If the SAS address of the new phy matches the SAS address of
857 * other phys in the port OR this is the first phy in the port,
858 * then activate the phy and allow it to be used for operations
859 * in this port.
860 */
861 if ((phy_sas_address.high == port_sas_address.high &&
862 phy_sas_address.low == port_sas_address.low) ||
Dan Williamsffe191c2011-06-29 13:09:25 -0700863 iport->active_phy_mask == 0) {
864 struct sci_base_state_machine *sm = &iport->sm;
Dan Williamse2f8db52011-05-10 02:28:46 -0700865
Dan Williamsffe191c2011-06-29 13:09:25 -0700866 scic_sds_port_activate_phy(iport, iphy, do_notify_user);
Edmund Nadolskie3013702011-06-02 00:10:43 +0000867 if (sm->current_state_id == SCI_PORT_RESETTING)
Dan Williamsffe191c2011-06-29 13:09:25 -0700868 port_state_machine_change(iport, SCI_PORT_READY);
Dan Williamse2f8db52011-05-10 02:28:46 -0700869 } else
Dan Williamsffe191c2011-06-29 13:09:25 -0700870 scic_sds_port_invalid_link_up(iport, iphy);
Dan Williamse2f8db52011-05-10 02:28:46 -0700871}
872
873
874
875/**
876 * This method returns false if the port only has a single phy object assigned.
877 * If there are no phys or more than one phy then the method will return
878 * true.
879 * @sci_port: The port for which the wide port condition is to be checked.
880 *
881 * bool true Is returned if this is a wide ported port. false Is returned if
882 * this is a narrow port.
883 */
Dan Williamsffe191c2011-06-29 13:09:25 -0700884static bool scic_sds_port_is_wide(struct isci_port *iport)
Dan Williamse2f8db52011-05-10 02:28:46 -0700885{
886 u32 index;
887 u32 phy_count = 0;
888
889 for (index = 0; index < SCI_MAX_PHYS; index++) {
Dan Williamsffe191c2011-06-29 13:09:25 -0700890 if (iport->phy_table[index] != NULL) {
Dan Williamse2f8db52011-05-10 02:28:46 -0700891 phy_count++;
892 }
893 }
894
895 return phy_count != 1;
896}
897
898/**
899 * This method is called by the PHY object when the link is detected. if the
900 * port wants the PHY to continue on to the link up state then the port
901 * layer must return true. If the port object returns false the phy object
902 * must halt its attempt to go link up.
903 * @sci_port: The port associated with the phy object.
904 * @sci_phy: The phy object that is trying to go link up.
905 *
906 * true if the phy object can continue to the link up condition. true Is
907 * returned if this phy can continue to the ready state. false Is returned if
908 * can not continue on to the ready state. This notification is in place for
909 * wide ports and direct attached phys. Since there are no wide ported SATA
910 * devices this could become an invalid port configuration.
911 */
912bool scic_sds_port_link_detected(
Dan Williamsffe191c2011-06-29 13:09:25 -0700913 struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -0700914 struct isci_phy *iphy)
Dan Williamse2f8db52011-05-10 02:28:46 -0700915{
Dan Williamsffe191c2011-06-29 13:09:25 -0700916 if ((iport->logical_port_index != SCIC_SDS_DUMMY_PORT) &&
Dan Williams85280952011-06-28 15:05:53 -0700917 (iphy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) &&
Dan Williamsffe191c2011-06-29 13:09:25 -0700918 scic_sds_port_is_wide(iport)) {
919 scic_sds_port_invalid_link_up(iport, iphy);
Dan Williamse2f8db52011-05-10 02:28:46 -0700920
921 return false;
922 }
923
924 return true;
925}
926
Edmund Nadolski5553ba22011-05-19 11:59:10 +0000927static void port_timeout(unsigned long data)
Dan Williamse2f8db52011-05-10 02:28:46 -0700928{
Edmund Nadolski5553ba22011-05-19 11:59:10 +0000929 struct sci_timer *tmr = (struct sci_timer *)data;
Dan Williamsffe191c2011-06-29 13:09:25 -0700930 struct isci_port *iport = container_of(tmr, typeof(*iport), timer);
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700931 struct isci_host *ihost = iport->owning_controller;
Edmund Nadolski5553ba22011-05-19 11:59:10 +0000932 unsigned long flags;
Dan Williamse2f8db52011-05-10 02:28:46 -0700933 u32 current_state;
934
Edmund Nadolski5553ba22011-05-19 11:59:10 +0000935 spin_lock_irqsave(&ihost->scic_lock, flags);
936
937 if (tmr->cancel)
938 goto done;
939
Dan Williamsffe191c2011-06-29 13:09:25 -0700940 current_state = iport->sm.current_state_id;
Dan Williamse2f8db52011-05-10 02:28:46 -0700941
Edmund Nadolskie3013702011-06-02 00:10:43 +0000942 if (current_state == SCI_PORT_RESETTING) {
Piotr Sawickie91f41e2011-05-11 23:52:21 +0000943 /* if the port is still in the resetting state then the timeout
944 * fired before the reset completed.
Dan Williamse2f8db52011-05-10 02:28:46 -0700945 */
Dan Williamsffe191c2011-06-29 13:09:25 -0700946 port_state_machine_change(iport, SCI_PORT_FAILED);
Edmund Nadolskie3013702011-06-02 00:10:43 +0000947 } else if (current_state == SCI_PORT_STOPPED) {
Piotr Sawickie91f41e2011-05-11 23:52:21 +0000948 /* if the port is stopped then the start request failed In this
949 * case stay in the stopped state.
Dan Williamse2f8db52011-05-10 02:28:46 -0700950 */
Dan Williamsffe191c2011-06-29 13:09:25 -0700951 dev_err(sciport_to_dev(iport),
Dan Williamse2f8db52011-05-10 02:28:46 -0700952 "%s: SCIC Port 0x%p failed to stop before tiemout.\n",
953 __func__,
Dan Williamsffe191c2011-06-29 13:09:25 -0700954 iport);
Edmund Nadolskie3013702011-06-02 00:10:43 +0000955 } else if (current_state == SCI_PORT_STOPPING) {
Piotr Sawickie91f41e2011-05-11 23:52:21 +0000956 /* if the port is still stopping then the stop has not completed */
Dan Williamsffe191c2011-06-29 13:09:25 -0700957 isci_port_stop_complete(iport->owning_controller,
958 iport,
Piotr Sawickie91f41e2011-05-11 23:52:21 +0000959 SCI_FAILURE_TIMEOUT);
Dan Williamse2f8db52011-05-10 02:28:46 -0700960 } else {
Piotr Sawickie91f41e2011-05-11 23:52:21 +0000961 /* The port is in the ready state and we have a timer
Dan Williamse2f8db52011-05-10 02:28:46 -0700962 * reporting a timeout this should not happen.
963 */
Dan Williamsffe191c2011-06-29 13:09:25 -0700964 dev_err(sciport_to_dev(iport),
Dan Williamse2f8db52011-05-10 02:28:46 -0700965 "%s: SCIC Port 0x%p is processing a timeout operation "
Dan Williamsffe191c2011-06-29 13:09:25 -0700966 "in state %d.\n", __func__, iport, current_state);
Dan Williamse2f8db52011-05-10 02:28:46 -0700967 }
Edmund Nadolski5553ba22011-05-19 11:59:10 +0000968
969done:
970 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williamse2f8db52011-05-10 02:28:46 -0700971}
972
973/* --------------------------------------------------------------------------- */
974
975/**
976 * This function updates the hardwares VIIT entry for this port.
977 *
978 *
979 */
Dan Williamsffe191c2011-06-29 13:09:25 -0700980static void scic_sds_port_update_viit_entry(struct isci_port *iport)
Dan Williamse2f8db52011-05-10 02:28:46 -0700981{
982 struct sci_sas_address sas_address;
983
Dan Williamsffe191c2011-06-29 13:09:25 -0700984 scic_sds_port_get_sas_address(iport, &sas_address);
Dan Williamse2f8db52011-05-10 02:28:46 -0700985
986 writel(sas_address.high,
Dan Williamsffe191c2011-06-29 13:09:25 -0700987 &iport->viit_registers->initiator_sas_address_hi);
Dan Williamse2f8db52011-05-10 02:28:46 -0700988 writel(sas_address.low,
Dan Williamsffe191c2011-06-29 13:09:25 -0700989 &iport->viit_registers->initiator_sas_address_lo);
Dan Williamse2f8db52011-05-10 02:28:46 -0700990
991 /* This value get cleared just in case its not already cleared */
Dan Williamsffe191c2011-06-29 13:09:25 -0700992 writel(0, &iport->viit_registers->reserved);
Dan Williamse2f8db52011-05-10 02:28:46 -0700993
994 /* We are required to update the status register last */
995 writel(SCU_VIIT_ENTRY_ID_VIIT |
996 SCU_VIIT_IPPT_INITIATOR |
Dan Williamsffe191c2011-06-29 13:09:25 -0700997 ((1 << iport->physical_port_index) << SCU_VIIT_ENTRY_LPVIE_SHIFT) |
Dan Williamse2f8db52011-05-10 02:28:46 -0700998 SCU_VIIT_STATUS_ALL_VALID,
Dan Williamsffe191c2011-06-29 13:09:25 -0700999 &iport->viit_registers->status);
Dan Williamse2f8db52011-05-10 02:28:46 -07001000}
1001
Dan Williamsffe191c2011-06-29 13:09:25 -07001002enum sas_linkrate scic_sds_port_get_max_allowed_speed(struct isci_port *iport)
Dan Williamse2f8db52011-05-10 02:28:46 -07001003{
1004 u16 index;
Dan Williams85280952011-06-28 15:05:53 -07001005 struct isci_phy *iphy;
Dan Williamse2f8db52011-05-10 02:28:46 -07001006 enum sas_linkrate max_allowed_speed = SAS_LINK_RATE_6_0_GBPS;
Dan Williamse2f8db52011-05-10 02:28:46 -07001007
1008 /*
1009 * Loop through all of the phys in this port and find the phy with the
1010 * lowest maximum link rate. */
1011 for (index = 0; index < SCI_MAX_PHYS; index++) {
Dan Williamsffe191c2011-06-29 13:09:25 -07001012 iphy = iport->phy_table[index];
1013 if (iphy && scic_sds_port_active_phy(iport, iphy) &&
Dan Williams85280952011-06-28 15:05:53 -07001014 iphy->max_negotiated_speed < max_allowed_speed)
1015 max_allowed_speed = iphy->max_negotiated_speed;
Dan Williamse2f8db52011-05-10 02:28:46 -07001016 }
1017
1018 return max_allowed_speed;
1019}
1020
Dan Williamsffe191c2011-06-29 13:09:25 -07001021static void scic_sds_port_suspend_port_task_scheduler(struct isci_port *iport)
Dan Williamse2f8db52011-05-10 02:28:46 -07001022{
1023 u32 pts_control_value;
1024
Dan Williamsffe191c2011-06-29 13:09:25 -07001025 pts_control_value = readl(&iport->port_task_scheduler_registers->control);
Dan Williamse2f8db52011-05-10 02:28:46 -07001026 pts_control_value |= SCU_PTSxCR_GEN_BIT(SUSPEND);
Dan Williamsffe191c2011-06-29 13:09:25 -07001027 writel(pts_control_value, &iport->port_task_scheduler_registers->control);
Dan Williamse2f8db52011-05-10 02:28:46 -07001028}
1029
1030/**
1031 * scic_sds_port_post_dummy_request() - post dummy/workaround request
1032 * @sci_port: port to post task
1033 *
1034 * Prevent the hardware scheduler from posting new requests to the front
1035 * of the scheduler queue causing a starvation problem for currently
1036 * ongoing requests.
1037 *
1038 */
Dan Williamsffe191c2011-06-29 13:09:25 -07001039static void scic_sds_port_post_dummy_request(struct isci_port *iport)
Dan Williamse2f8db52011-05-10 02:28:46 -07001040{
Dan Williamsd9dcb4b2011-06-30 17:38:32 -07001041 struct isci_host *ihost = iport->owning_controller;
Dan Williamsffe191c2011-06-29 13:09:25 -07001042 u16 tag = iport->reserved_tag;
Dan Williams312e0c22011-06-28 13:47:09 -07001043 struct scu_task_context *tc;
1044 u32 command;
Dan Williamse2f8db52011-05-10 02:28:46 -07001045
Dan Williamsd9dcb4b2011-06-30 17:38:32 -07001046 tc = &ihost->task_context_table[ISCI_TAG_TCI(tag)];
Dan Williams312e0c22011-06-28 13:47:09 -07001047 tc->abort = 0;
Dan Williamse2f8db52011-05-10 02:28:46 -07001048
1049 command = SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
Dan Williamsffe191c2011-06-29 13:09:25 -07001050 iport->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
Dan Williams312e0c22011-06-28 13:47:09 -07001051 ISCI_TAG_TCI(tag);
Dan Williamse2f8db52011-05-10 02:28:46 -07001052
Dan Williamsd9dcb4b2011-06-30 17:38:32 -07001053 scic_sds_controller_post_request(ihost, command);
Dan Williamse2f8db52011-05-10 02:28:46 -07001054}
1055
1056/**
1057 * This routine will abort the dummy request. This will alow the hardware to
1058 * power down parts of the silicon to save power.
1059 *
1060 * @sci_port: The port on which the task must be aborted.
1061 *
1062 */
Dan Williamsffe191c2011-06-29 13:09:25 -07001063static void scic_sds_port_abort_dummy_request(struct isci_port *iport)
Dan Williamse2f8db52011-05-10 02:28:46 -07001064{
Dan Williamsd9dcb4b2011-06-30 17:38:32 -07001065 struct isci_host *ihost = iport->owning_controller;
Dan Williamsffe191c2011-06-29 13:09:25 -07001066 u16 tag = iport->reserved_tag;
Dan Williamse2f8db52011-05-10 02:28:46 -07001067 struct scu_task_context *tc;
1068 u32 command;
1069
Dan Williamsd9dcb4b2011-06-30 17:38:32 -07001070 tc = &ihost->task_context_table[ISCI_TAG_TCI(tag)];
Dan Williamse2f8db52011-05-10 02:28:46 -07001071 tc->abort = 1;
1072
1073 command = SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT |
Dan Williamsffe191c2011-06-29 13:09:25 -07001074 iport->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
Dan Williams312e0c22011-06-28 13:47:09 -07001075 ISCI_TAG_TCI(tag);
Dan Williamse2f8db52011-05-10 02:28:46 -07001076
Dan Williamsd9dcb4b2011-06-30 17:38:32 -07001077 scic_sds_controller_post_request(ihost, command);
Dan Williamse2f8db52011-05-10 02:28:46 -07001078}
1079
1080/**
1081 *
Dan Williamsffe191c2011-06-29 13:09:25 -07001082 * @sci_port: This is the struct isci_port object to resume.
Dan Williamse2f8db52011-05-10 02:28:46 -07001083 *
1084 * This method will resume the port task scheduler for this port object. none
1085 */
1086static void
Dan Williamsffe191c2011-06-29 13:09:25 -07001087scic_sds_port_resume_port_task_scheduler(struct isci_port *iport)
Dan Williamse2f8db52011-05-10 02:28:46 -07001088{
1089 u32 pts_control_value;
1090
Dan Williamsffe191c2011-06-29 13:09:25 -07001091 pts_control_value = readl(&iport->port_task_scheduler_registers->control);
Dan Williamse2f8db52011-05-10 02:28:46 -07001092 pts_control_value &= ~SCU_PTSxCR_GEN_BIT(SUSPEND);
Dan Williamsffe191c2011-06-29 13:09:25 -07001093 writel(pts_control_value, &iport->port_task_scheduler_registers->control);
Dan Williamse2f8db52011-05-10 02:28:46 -07001094}
1095
Dan Williams9269e0e2011-05-12 07:42:17 -07001096static void scic_sds_port_ready_substate_waiting_enter(struct sci_base_state_machine *sm)
Dan Williamse2f8db52011-05-10 02:28:46 -07001097{
Dan Williamsffe191c2011-06-29 13:09:25 -07001098 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
Dan Williamse2f8db52011-05-10 02:28:46 -07001099
Dan Williamsffe191c2011-06-29 13:09:25 -07001100 scic_sds_port_suspend_port_task_scheduler(iport);
Dan Williamse2f8db52011-05-10 02:28:46 -07001101
Dan Williamsffe191c2011-06-29 13:09:25 -07001102 iport->not_ready_reason = SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS;
Dan Williamse2f8db52011-05-10 02:28:46 -07001103
Dan Williamsffe191c2011-06-29 13:09:25 -07001104 if (iport->active_phy_mask != 0) {
Dan Williamse2f8db52011-05-10 02:28:46 -07001105 /* At least one of the phys on the port is ready */
Dan Williamsffe191c2011-06-29 13:09:25 -07001106 port_state_machine_change(iport,
Edmund Nadolskie3013702011-06-02 00:10:43 +00001107 SCI_PORT_SUB_OPERATIONAL);
Dan Williamse2f8db52011-05-10 02:28:46 -07001108 }
1109}
1110
Dan Williams9269e0e2011-05-12 07:42:17 -07001111static void scic_sds_port_ready_substate_operational_enter(struct sci_base_state_machine *sm)
Dan Williamse2f8db52011-05-10 02:28:46 -07001112{
1113 u32 index;
Dan Williamsffe191c2011-06-29 13:09:25 -07001114 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
Dan Williamsd9dcb4b2011-06-30 17:38:32 -07001115 struct isci_host *ihost = iport->owning_controller;
Dan Williamse2f8db52011-05-10 02:28:46 -07001116
Dan Williamse2f8db52011-05-10 02:28:46 -07001117 isci_port_ready(ihost, iport);
1118
1119 for (index = 0; index < SCI_MAX_PHYS; index++) {
Dan Williamsffe191c2011-06-29 13:09:25 -07001120 if (iport->phy_table[index]) {
1121 writel(iport->physical_port_index,
1122 &iport->port_pe_configuration_register[
1123 iport->phy_table[index]->phy_index]);
Dan Williamse2f8db52011-05-10 02:28:46 -07001124 }
1125 }
1126
Dan Williamsffe191c2011-06-29 13:09:25 -07001127 scic_sds_port_update_viit_entry(iport);
Dan Williamse2f8db52011-05-10 02:28:46 -07001128
Dan Williamsffe191c2011-06-29 13:09:25 -07001129 scic_sds_port_resume_port_task_scheduler(iport);
Dan Williamse2f8db52011-05-10 02:28:46 -07001130
1131 /*
1132 * Post the dummy task for the port so the hardware can schedule
1133 * io correctly
1134 */
Dan Williamsffe191c2011-06-29 13:09:25 -07001135 scic_sds_port_post_dummy_request(iport);
Dan Williamse2f8db52011-05-10 02:28:46 -07001136}
1137
Dan Williamsffe191c2011-06-29 13:09:25 -07001138static void scic_sds_port_invalidate_dummy_remote_node(struct isci_port *iport)
Piotr Sawickie91f41e2011-05-11 23:52:21 +00001139{
Dan Williamsd9dcb4b2011-06-30 17:38:32 -07001140 struct isci_host *ihost = iport->owning_controller;
Dan Williamsffe191c2011-06-29 13:09:25 -07001141 u8 phys_index = iport->physical_port_index;
Piotr Sawickie91f41e2011-05-11 23:52:21 +00001142 union scu_remote_node_context *rnc;
Dan Williamsffe191c2011-06-29 13:09:25 -07001143 u16 rni = iport->reserved_rni;
Piotr Sawickie91f41e2011-05-11 23:52:21 +00001144 u32 command;
1145
Dan Williamsd9dcb4b2011-06-30 17:38:32 -07001146 rnc = &ihost->remote_node_context_table[rni];
Piotr Sawickie91f41e2011-05-11 23:52:21 +00001147
1148 rnc->ssp.is_valid = false;
1149
1150 /* ensure the preceding tc abort request has reached the
1151 * controller and give it ample time to act before posting the rnc
1152 * invalidate
1153 */
Dan Williamsd9dcb4b2011-06-30 17:38:32 -07001154 readl(&ihost->smu_registers->interrupt_status); /* flush */
Piotr Sawickie91f41e2011-05-11 23:52:21 +00001155 udelay(10);
1156
1157 command = SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE |
1158 phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
1159
Dan Williamsd9dcb4b2011-06-30 17:38:32 -07001160 scic_sds_controller_post_request(ihost, command);
Piotr Sawickie91f41e2011-05-11 23:52:21 +00001161}
1162
Dan Williamse2f8db52011-05-10 02:28:46 -07001163/**
1164 *
Dan Williamsffe191c2011-06-29 13:09:25 -07001165 * @object: This is the object which is cast to a struct isci_port object.
Dan Williamse2f8db52011-05-10 02:28:46 -07001166 *
Dan Williamsffe191c2011-06-29 13:09:25 -07001167 * This method will perform the actions required by the struct isci_port on
Edmund Nadolskie3013702011-06-02 00:10:43 +00001168 * exiting the SCI_PORT_SUB_OPERATIONAL. This function reports
Dan Williamse2f8db52011-05-10 02:28:46 -07001169 * the port not ready and suspends the port task scheduler. none
1170 */
Dan Williams9269e0e2011-05-12 07:42:17 -07001171static void scic_sds_port_ready_substate_operational_exit(struct sci_base_state_machine *sm)
Dan Williamse2f8db52011-05-10 02:28:46 -07001172{
Dan Williamsffe191c2011-06-29 13:09:25 -07001173 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
Dan Williamsd9dcb4b2011-06-30 17:38:32 -07001174 struct isci_host *ihost = iport->owning_controller;
Dan Williamse2f8db52011-05-10 02:28:46 -07001175
1176 /*
1177 * Kill the dummy task for this port if it has not yet posted
1178 * the hardware will treat this as a NOP and just return abort
1179 * complete.
1180 */
Dan Williamsffe191c2011-06-29 13:09:25 -07001181 scic_sds_port_abort_dummy_request(iport);
Dan Williamse2f8db52011-05-10 02:28:46 -07001182
1183 isci_port_not_ready(ihost, iport);
Piotr Sawickie91f41e2011-05-11 23:52:21 +00001184
Dan Williamsffe191c2011-06-29 13:09:25 -07001185 if (iport->ready_exit)
1186 scic_sds_port_invalidate_dummy_remote_node(iport);
Dan Williamse2f8db52011-05-10 02:28:46 -07001187}
1188
Dan Williams9269e0e2011-05-12 07:42:17 -07001189static void scic_sds_port_ready_substate_configuring_enter(struct sci_base_state_machine *sm)
Dan Williamse2f8db52011-05-10 02:28:46 -07001190{
Dan Williamsffe191c2011-06-29 13:09:25 -07001191 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
Dan Williamsd9dcb4b2011-06-30 17:38:32 -07001192 struct isci_host *ihost = iport->owning_controller;
Dan Williamse2f8db52011-05-10 02:28:46 -07001193
Dan Williamsffe191c2011-06-29 13:09:25 -07001194 if (iport->active_phy_mask == 0) {
Dan Williamse2f8db52011-05-10 02:28:46 -07001195 isci_port_not_ready(ihost, iport);
1196
Dan Williamsffe191c2011-06-29 13:09:25 -07001197 port_state_machine_change(iport,
Edmund Nadolskie3013702011-06-02 00:10:43 +00001198 SCI_PORT_SUB_WAITING);
Dan Williamsffe191c2011-06-29 13:09:25 -07001199 } else if (iport->started_request_count == 0)
1200 port_state_machine_change(iport,
Edmund Nadolskie3013702011-06-02 00:10:43 +00001201 SCI_PORT_SUB_OPERATIONAL);
Dan Williamse2f8db52011-05-10 02:28:46 -07001202}
1203
Dan Williams9269e0e2011-05-12 07:42:17 -07001204static void scic_sds_port_ready_substate_configuring_exit(struct sci_base_state_machine *sm)
Dan Williamse2f8db52011-05-10 02:28:46 -07001205{
Dan Williamsffe191c2011-06-29 13:09:25 -07001206 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
Dan Williamse2f8db52011-05-10 02:28:46 -07001207
Dan Williamsffe191c2011-06-29 13:09:25 -07001208 scic_sds_port_suspend_port_task_scheduler(iport);
1209 if (iport->ready_exit)
1210 scic_sds_port_invalidate_dummy_remote_node(iport);
Dan Williamse2f8db52011-05-10 02:28:46 -07001211}
1212
Dan Williamsffe191c2011-06-29 13:09:25 -07001213enum sci_status scic_sds_port_start(struct isci_port *iport)
Piotr Sawickid76f71d2011-05-11 23:52:26 +00001214{
Dan Williamsd9dcb4b2011-06-30 17:38:32 -07001215 struct isci_host *ihost = iport->owning_controller;
Piotr Sawickid76f71d2011-05-11 23:52:26 +00001216 enum sci_status status = SCI_SUCCESS;
1217 enum scic_sds_port_states state;
1218 u32 phy_mask;
1219
Dan Williamsffe191c2011-06-29 13:09:25 -07001220 state = iport->sm.current_state_id;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001221 if (state != SCI_PORT_STOPPED) {
Dan Williamsffe191c2011-06-29 13:09:25 -07001222 dev_warn(sciport_to_dev(iport),
Piotr Sawickid76f71d2011-05-11 23:52:26 +00001223 "%s: in wrong state: %d\n", __func__, state);
1224 return SCI_FAILURE_INVALID_STATE;
1225 }
1226
Dan Williamsffe191c2011-06-29 13:09:25 -07001227 if (iport->assigned_device_count > 0) {
Piotr Sawickid76f71d2011-05-11 23:52:26 +00001228 /* TODO This is a start failure operation because
1229 * there are still devices assigned to this port.
1230 * There must be no devices assigned to a port on a
1231 * start operation.
1232 */
1233 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
1234 }
1235
Dan Williamsffe191c2011-06-29 13:09:25 -07001236 if (iport->reserved_rni == SCU_DUMMY_INDEX) {
Piotr Sawickid76f71d2011-05-11 23:52:26 +00001237 u16 rni = scic_sds_remote_node_table_allocate_remote_node(
Dan Williamsd9dcb4b2011-06-30 17:38:32 -07001238 &ihost->available_remote_nodes, 1);
Piotr Sawickid76f71d2011-05-11 23:52:26 +00001239
1240 if (rni != SCU_DUMMY_INDEX)
Dan Williamsffe191c2011-06-29 13:09:25 -07001241 scic_sds_port_construct_dummy_rnc(iport, rni);
Piotr Sawickid76f71d2011-05-11 23:52:26 +00001242 else
1243 status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
Dan Williamsffe191c2011-06-29 13:09:25 -07001244 iport->reserved_rni = rni;
Piotr Sawickid76f71d2011-05-11 23:52:26 +00001245 }
1246
Dan Williamsffe191c2011-06-29 13:09:25 -07001247 if (iport->reserved_tag == SCI_CONTROLLER_INVALID_IO_TAG) {
Dan Williams312e0c22011-06-28 13:47:09 -07001248 u16 tag;
Piotr Sawickid76f71d2011-05-11 23:52:26 +00001249
Dan Williams312e0c22011-06-28 13:47:09 -07001250 tag = isci_alloc_tag(ihost);
1251 if (tag == SCI_CONTROLLER_INVALID_IO_TAG)
Piotr Sawickid76f71d2011-05-11 23:52:26 +00001252 status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
Dan Williams312e0c22011-06-28 13:47:09 -07001253 else
Dan Williamsffe191c2011-06-29 13:09:25 -07001254 scic_sds_port_construct_dummy_task(iport, tag);
1255 iport->reserved_tag = tag;
Piotr Sawickid76f71d2011-05-11 23:52:26 +00001256 }
1257
1258 if (status == SCI_SUCCESS) {
Dan Williamsffe191c2011-06-29 13:09:25 -07001259 phy_mask = scic_sds_port_get_phys(iport);
Piotr Sawickid76f71d2011-05-11 23:52:26 +00001260
1261 /*
1262 * There are one or more phys assigned to this port. Make sure
1263 * the port's phy mask is in fact legal and supported by the
1264 * silicon.
1265 */
Dan Williamsffe191c2011-06-29 13:09:25 -07001266 if (scic_sds_port_is_phy_mask_valid(iport, phy_mask) == true) {
1267 port_state_machine_change(iport,
Edmund Nadolskie3013702011-06-02 00:10:43 +00001268 SCI_PORT_READY);
Piotr Sawickid76f71d2011-05-11 23:52:26 +00001269
1270 return SCI_SUCCESS;
1271 }
1272 status = SCI_FAILURE;
1273 }
1274
1275 if (status != SCI_SUCCESS)
Dan Williamsffe191c2011-06-29 13:09:25 -07001276 scic_sds_port_destroy_dummy_resources(iport);
Piotr Sawickid76f71d2011-05-11 23:52:26 +00001277
1278 return status;
1279}
1280
Dan Williamsffe191c2011-06-29 13:09:25 -07001281enum sci_status scic_sds_port_stop(struct isci_port *iport)
Piotr Sawicki8bc80d32011-05-11 23:52:31 +00001282{
1283 enum scic_sds_port_states state;
1284
Dan Williamsffe191c2011-06-29 13:09:25 -07001285 state = iport->sm.current_state_id;
Piotr Sawicki8bc80d32011-05-11 23:52:31 +00001286 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +00001287 case SCI_PORT_STOPPED:
Piotr Sawicki8bc80d32011-05-11 23:52:31 +00001288 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001289 case SCI_PORT_SUB_WAITING:
1290 case SCI_PORT_SUB_OPERATIONAL:
1291 case SCI_PORT_SUB_CONFIGURING:
1292 case SCI_PORT_RESETTING:
Dan Williamsffe191c2011-06-29 13:09:25 -07001293 port_state_machine_change(iport,
Edmund Nadolskie3013702011-06-02 00:10:43 +00001294 SCI_PORT_STOPPING);
Piotr Sawicki8bc80d32011-05-11 23:52:31 +00001295 return SCI_SUCCESS;
1296 default:
Dan Williamsffe191c2011-06-29 13:09:25 -07001297 dev_warn(sciport_to_dev(iport),
Piotr Sawicki8bc80d32011-05-11 23:52:31 +00001298 "%s: in wrong state: %d\n", __func__, state);
1299 return SCI_FAILURE_INVALID_STATE;
1300 }
1301}
1302
Dan Williamsffe191c2011-06-29 13:09:25 -07001303static enum sci_status scic_port_hard_reset(struct isci_port *iport, u32 timeout)
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001304{
1305 enum sci_status status = SCI_FAILURE_INVALID_PHY;
Dan Williams85280952011-06-28 15:05:53 -07001306 struct isci_phy *iphy = NULL;
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001307 enum scic_sds_port_states state;
1308 u32 phy_index;
1309
Dan Williamsffe191c2011-06-29 13:09:25 -07001310 state = iport->sm.current_state_id;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001311 if (state != SCI_PORT_SUB_OPERATIONAL) {
Dan Williamsffe191c2011-06-29 13:09:25 -07001312 dev_warn(sciport_to_dev(iport),
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001313 "%s: in wrong state: %d\n", __func__, state);
1314 return SCI_FAILURE_INVALID_STATE;
1315 }
1316
1317 /* Select a phy on which we can send the hard reset request. */
Dan Williams85280952011-06-28 15:05:53 -07001318 for (phy_index = 0; phy_index < SCI_MAX_PHYS && !iphy; phy_index++) {
Dan Williamsffe191c2011-06-29 13:09:25 -07001319 iphy = iport->phy_table[phy_index];
1320 if (iphy && !scic_sds_port_active_phy(iport, iphy)) {
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001321 /*
1322 * We found a phy but it is not ready select
1323 * different phy
1324 */
Dan Williams85280952011-06-28 15:05:53 -07001325 iphy = NULL;
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001326 }
1327 }
1328
1329 /* If we have a phy then go ahead and start the reset procedure */
Dan Williams85280952011-06-28 15:05:53 -07001330 if (!iphy)
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001331 return status;
Dan Williams85280952011-06-28 15:05:53 -07001332 status = scic_sds_phy_reset(iphy);
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001333
1334 if (status != SCI_SUCCESS)
1335 return status;
1336
Dan Williamsffe191c2011-06-29 13:09:25 -07001337 sci_mod_timer(&iport->timer, timeout);
1338 iport->not_ready_reason = SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED;
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001339
Dan Williamsffe191c2011-06-29 13:09:25 -07001340 port_state_machine_change(iport, SCI_PORT_RESETTING);
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001341 return SCI_SUCCESS;
1342}
1343
1344/**
1345 * scic_sds_port_add_phy() -
1346 * @sci_port: This parameter specifies the port in which the phy will be added.
1347 * @sci_phy: This parameter is the phy which is to be added to the port.
1348 *
1349 * This method will add a PHY to the selected port. This method returns an
1350 * enum sci_status. SCI_SUCCESS the phy has been added to the port. Any other
1351 * status is a failure to add the phy to the port.
1352 */
Dan Williamsffe191c2011-06-29 13:09:25 -07001353enum sci_status scic_sds_port_add_phy(struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -07001354 struct isci_phy *iphy)
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001355{
1356 enum sci_status status;
1357 enum scic_sds_port_states state;
1358
Dan Williamsffe191c2011-06-29 13:09:25 -07001359 state = iport->sm.current_state_id;
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001360 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +00001361 case SCI_PORT_STOPPED: {
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001362 struct sci_sas_address port_sas_address;
1363
1364 /* Read the port assigned SAS Address if there is one */
Dan Williamsffe191c2011-06-29 13:09:25 -07001365 scic_sds_port_get_sas_address(iport, &port_sas_address);
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001366
1367 if (port_sas_address.high != 0 && port_sas_address.low != 0) {
1368 struct sci_sas_address phy_sas_address;
1369
1370 /* Make sure that the PHY SAS Address matches the SAS Address
1371 * for this port
1372 */
Dan Williams85280952011-06-28 15:05:53 -07001373 scic_sds_phy_get_sas_address(iphy, &phy_sas_address);
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001374
1375 if (port_sas_address.high != phy_sas_address.high ||
1376 port_sas_address.low != phy_sas_address.low)
1377 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
1378 }
Dan Williamsffe191c2011-06-29 13:09:25 -07001379 return scic_sds_port_set_phy(iport, iphy);
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001380 }
Edmund Nadolskie3013702011-06-02 00:10:43 +00001381 case SCI_PORT_SUB_WAITING:
1382 case SCI_PORT_SUB_OPERATIONAL:
Dan Williamsffe191c2011-06-29 13:09:25 -07001383 status = scic_sds_port_set_phy(iport, iphy);
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001384
1385 if (status != SCI_SUCCESS)
1386 return status;
1387
Dan Williamsffe191c2011-06-29 13:09:25 -07001388 scic_sds_port_general_link_up_handler(iport, iphy, true);
1389 iport->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
1390 port_state_machine_change(iport, SCI_PORT_SUB_CONFIGURING);
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001391
1392 return status;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001393 case SCI_PORT_SUB_CONFIGURING:
Dan Williamsffe191c2011-06-29 13:09:25 -07001394 status = scic_sds_port_set_phy(iport, iphy);
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001395
1396 if (status != SCI_SUCCESS)
1397 return status;
Dan Williamsffe191c2011-06-29 13:09:25 -07001398 scic_sds_port_general_link_up_handler(iport, iphy, true);
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001399
1400 /* Re-enter the configuring state since this may be the last phy in
1401 * the port.
1402 */
Dan Williamsffe191c2011-06-29 13:09:25 -07001403 port_state_machine_change(iport,
Edmund Nadolskie3013702011-06-02 00:10:43 +00001404 SCI_PORT_SUB_CONFIGURING);
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001405 return SCI_SUCCESS;
1406 default:
Dan Williamsffe191c2011-06-29 13:09:25 -07001407 dev_warn(sciport_to_dev(iport),
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001408 "%s: in wrong state: %d\n", __func__, state);
1409 return SCI_FAILURE_INVALID_STATE;
1410 }
1411}
1412
1413/**
1414 * scic_sds_port_remove_phy() -
1415 * @sci_port: This parameter specifies the port in which the phy will be added.
1416 * @sci_phy: This parameter is the phy which is to be added to the port.
1417 *
1418 * This method will remove the PHY from the selected PORT. This method returns
1419 * an enum sci_status. SCI_SUCCESS the phy has been removed from the port. Any
1420 * other status is a failure to add the phy to the port.
1421 */
Dan Williamsffe191c2011-06-29 13:09:25 -07001422enum sci_status scic_sds_port_remove_phy(struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -07001423 struct isci_phy *iphy)
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001424{
1425 enum sci_status status;
1426 enum scic_sds_port_states state;
1427
Dan Williamsffe191c2011-06-29 13:09:25 -07001428 state = iport->sm.current_state_id;
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001429
1430 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +00001431 case SCI_PORT_STOPPED:
Dan Williamsffe191c2011-06-29 13:09:25 -07001432 return scic_sds_port_clear_phy(iport, iphy);
Edmund Nadolskie3013702011-06-02 00:10:43 +00001433 case SCI_PORT_SUB_OPERATIONAL:
Dan Williamsffe191c2011-06-29 13:09:25 -07001434 status = scic_sds_port_clear_phy(iport, iphy);
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001435 if (status != SCI_SUCCESS)
1436 return status;
1437
Dan Williamsffe191c2011-06-29 13:09:25 -07001438 scic_sds_port_deactivate_phy(iport, iphy, true);
1439 iport->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
1440 port_state_machine_change(iport,
Edmund Nadolskie3013702011-06-02 00:10:43 +00001441 SCI_PORT_SUB_CONFIGURING);
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001442 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001443 case SCI_PORT_SUB_CONFIGURING:
Dan Williamsffe191c2011-06-29 13:09:25 -07001444 status = scic_sds_port_clear_phy(iport, iphy);
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001445
1446 if (status != SCI_SUCCESS)
1447 return status;
Dan Williamsffe191c2011-06-29 13:09:25 -07001448 scic_sds_port_deactivate_phy(iport, iphy, true);
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001449
1450 /* Re-enter the configuring state since this may be the last phy in
1451 * the port
1452 */
Dan Williamsffe191c2011-06-29 13:09:25 -07001453 port_state_machine_change(iport,
Edmund Nadolskie3013702011-06-02 00:10:43 +00001454 SCI_PORT_SUB_CONFIGURING);
Piotr Sawicki051266c2011-05-12 19:10:14 +00001455 return SCI_SUCCESS;
1456 default:
Dan Williamsffe191c2011-06-29 13:09:25 -07001457 dev_warn(sciport_to_dev(iport),
Piotr Sawicki051266c2011-05-12 19:10:14 +00001458 "%s: in wrong state: %d\n", __func__, state);
1459 return SCI_FAILURE_INVALID_STATE;
1460 }
1461}
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001462
Dan Williamsffe191c2011-06-29 13:09:25 -07001463enum sci_status scic_sds_port_link_up(struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -07001464 struct isci_phy *iphy)
Piotr Sawicki051266c2011-05-12 19:10:14 +00001465{
1466 enum scic_sds_port_states state;
1467
Dan Williamsffe191c2011-06-29 13:09:25 -07001468 state = iport->sm.current_state_id;
Piotr Sawicki051266c2011-05-12 19:10:14 +00001469 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +00001470 case SCI_PORT_SUB_WAITING:
Piotr Sawicki051266c2011-05-12 19:10:14 +00001471 /* Since this is the first phy going link up for the port we
1472 * can just enable it and continue
1473 */
Dan Williamsffe191c2011-06-29 13:09:25 -07001474 scic_sds_port_activate_phy(iport, iphy, true);
Piotr Sawicki051266c2011-05-12 19:10:14 +00001475
Dan Williamsffe191c2011-06-29 13:09:25 -07001476 port_state_machine_change(iport,
Edmund Nadolskie3013702011-06-02 00:10:43 +00001477 SCI_PORT_SUB_OPERATIONAL);
Piotr Sawicki051266c2011-05-12 19:10:14 +00001478 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001479 case SCI_PORT_SUB_OPERATIONAL:
Dan Williamsffe191c2011-06-29 13:09:25 -07001480 scic_sds_port_general_link_up_handler(iport, iphy, true);
Piotr Sawicki051266c2011-05-12 19:10:14 +00001481 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001482 case SCI_PORT_RESETTING:
Piotr Sawicki051266c2011-05-12 19:10:14 +00001483 /* TODO We should make sure that the phy that has gone
1484 * link up is the same one on which we sent the reset. It is
1485 * possible that the phy on which we sent the reset is not the
1486 * one that has gone link up and we want to make sure that
1487 * phy being reset comes back. Consider the case where a
1488 * reset is sent but before the hardware processes the reset it
1489 * get a link up on the port because of a hot plug event.
1490 * because of the reset request this phy will go link down
1491 * almost immediately.
1492 */
1493
1494 /* In the resetting state we don't notify the user regarding
1495 * link up and link down notifications.
1496 */
Dan Williamsffe191c2011-06-29 13:09:25 -07001497 scic_sds_port_general_link_up_handler(iport, iphy, false);
Piotr Sawicki051266c2011-05-12 19:10:14 +00001498 return SCI_SUCCESS;
1499 default:
Dan Williamsffe191c2011-06-29 13:09:25 -07001500 dev_warn(sciport_to_dev(iport),
Piotr Sawicki051266c2011-05-12 19:10:14 +00001501 "%s: in wrong state: %d\n", __func__, state);
1502 return SCI_FAILURE_INVALID_STATE;
1503 }
1504}
1505
Dan Williamsffe191c2011-06-29 13:09:25 -07001506enum sci_status scic_sds_port_link_down(struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -07001507 struct isci_phy *iphy)
Piotr Sawicki051266c2011-05-12 19:10:14 +00001508{
1509 enum scic_sds_port_states state;
1510
Dan Williamsffe191c2011-06-29 13:09:25 -07001511 state = iport->sm.current_state_id;
Piotr Sawicki051266c2011-05-12 19:10:14 +00001512 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +00001513 case SCI_PORT_SUB_OPERATIONAL:
Dan Williamsffe191c2011-06-29 13:09:25 -07001514 scic_sds_port_deactivate_phy(iport, iphy, true);
Piotr Sawicki051266c2011-05-12 19:10:14 +00001515
1516 /* If there are no active phys left in the port, then
1517 * transition the port to the WAITING state until such time
1518 * as a phy goes link up
1519 */
Dan Williamsffe191c2011-06-29 13:09:25 -07001520 if (iport->active_phy_mask == 0)
1521 port_state_machine_change(iport,
Edmund Nadolskie3013702011-06-02 00:10:43 +00001522 SCI_PORT_SUB_WAITING);
Piotr Sawicki051266c2011-05-12 19:10:14 +00001523 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001524 case SCI_PORT_RESETTING:
Piotr Sawicki051266c2011-05-12 19:10:14 +00001525 /* In the resetting state we don't notify the user regarding
1526 * link up and link down notifications. */
Dan Williamsffe191c2011-06-29 13:09:25 -07001527 scic_sds_port_deactivate_phy(iport, iphy, false);
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001528 return SCI_SUCCESS;
1529 default:
Dan Williamsffe191c2011-06-29 13:09:25 -07001530 dev_warn(sciport_to_dev(iport),
Piotr Sawickibd6713b2011-05-12 19:10:03 +00001531 "%s: in wrong state: %d\n", __func__, state);
1532 return SCI_FAILURE_INVALID_STATE;
1533 }
1534}
1535
Dan Williamsffe191c2011-06-29 13:09:25 -07001536enum sci_status scic_sds_port_start_io(struct isci_port *iport,
Dan Williams78a6f062011-06-30 16:31:37 -07001537 struct isci_remote_device *idev,
Dan Williams5076a1a2011-06-27 14:57:03 -07001538 struct isci_request *ireq)
Dan Williams68138202011-05-12 07:16:06 -07001539{
1540 enum scic_sds_port_states state;
Dan Williamse2f8db52011-05-10 02:28:46 -07001541
Dan Williamsffe191c2011-06-29 13:09:25 -07001542 state = iport->sm.current_state_id;
Dan Williams68138202011-05-12 07:16:06 -07001543 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +00001544 case SCI_PORT_SUB_WAITING:
Dan Williams68138202011-05-12 07:16:06 -07001545 return SCI_FAILURE_INVALID_STATE;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001546 case SCI_PORT_SUB_OPERATIONAL:
Dan Williamsffe191c2011-06-29 13:09:25 -07001547 iport->started_request_count++;
Dan Williams68138202011-05-12 07:16:06 -07001548 return SCI_SUCCESS;
1549 default:
Dan Williamsffe191c2011-06-29 13:09:25 -07001550 dev_warn(sciport_to_dev(iport),
Dan Williams68138202011-05-12 07:16:06 -07001551 "%s: in wrong state: %d\n", __func__, state);
1552 return SCI_FAILURE_INVALID_STATE;
1553 }
1554}
1555
Dan Williamsffe191c2011-06-29 13:09:25 -07001556enum sci_status scic_sds_port_complete_io(struct isci_port *iport,
Dan Williams78a6f062011-06-30 16:31:37 -07001557 struct isci_remote_device *idev,
Dan Williams5076a1a2011-06-27 14:57:03 -07001558 struct isci_request *ireq)
Dan Williams68138202011-05-12 07:16:06 -07001559{
1560 enum scic_sds_port_states state;
1561
Dan Williamsffe191c2011-06-29 13:09:25 -07001562 state = iport->sm.current_state_id;
Dan Williams68138202011-05-12 07:16:06 -07001563 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +00001564 case SCI_PORT_STOPPED:
Dan Williamsffe191c2011-06-29 13:09:25 -07001565 dev_warn(sciport_to_dev(iport),
Dan Williams68138202011-05-12 07:16:06 -07001566 "%s: in wrong state: %d\n", __func__, state);
1567 return SCI_FAILURE_INVALID_STATE;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001568 case SCI_PORT_STOPPING:
Dan Williamsffe191c2011-06-29 13:09:25 -07001569 scic_sds_port_decrement_request_count(iport);
Dan Williams68138202011-05-12 07:16:06 -07001570
Dan Williamsffe191c2011-06-29 13:09:25 -07001571 if (iport->started_request_count == 0)
1572 port_state_machine_change(iport,
Edmund Nadolskie3013702011-06-02 00:10:43 +00001573 SCI_PORT_STOPPED);
Dan Williams68138202011-05-12 07:16:06 -07001574 break;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001575 case SCI_PORT_READY:
1576 case SCI_PORT_RESETTING:
1577 case SCI_PORT_FAILED:
1578 case SCI_PORT_SUB_WAITING:
1579 case SCI_PORT_SUB_OPERATIONAL:
Dan Williamsffe191c2011-06-29 13:09:25 -07001580 scic_sds_port_decrement_request_count(iport);
Dan Williams68138202011-05-12 07:16:06 -07001581 break;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001582 case SCI_PORT_SUB_CONFIGURING:
Dan Williamsffe191c2011-06-29 13:09:25 -07001583 scic_sds_port_decrement_request_count(iport);
1584 if (iport->started_request_count == 0) {
1585 port_state_machine_change(iport,
Edmund Nadolskie3013702011-06-02 00:10:43 +00001586 SCI_PORT_SUB_OPERATIONAL);
Dan Williams68138202011-05-12 07:16:06 -07001587 }
1588 break;
1589 }
1590 return SCI_SUCCESS;
1591}
Dan Williamse2f8db52011-05-10 02:28:46 -07001592
1593/**
1594 *
1595 * @sci_port: This is the port object which to suspend.
1596 *
1597 * This method will enable the SCU Port Task Scheduler for this port object but
1598 * will leave the port task scheduler in a suspended state. none
1599 */
1600static void
Dan Williamsffe191c2011-06-29 13:09:25 -07001601scic_sds_port_enable_port_task_scheduler(struct isci_port *iport)
Dan Williamse2f8db52011-05-10 02:28:46 -07001602{
1603 u32 pts_control_value;
1604
Dan Williamsffe191c2011-06-29 13:09:25 -07001605 pts_control_value = readl(&iport->port_task_scheduler_registers->control);
Dan Williamse2f8db52011-05-10 02:28:46 -07001606 pts_control_value |= SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND);
Dan Williamsffe191c2011-06-29 13:09:25 -07001607 writel(pts_control_value, &iport->port_task_scheduler_registers->control);
Dan Williamse2f8db52011-05-10 02:28:46 -07001608}
1609
1610/**
1611 *
1612 * @sci_port: This is the port object which to resume.
1613 *
1614 * This method will disable the SCU port task scheduler for this port object.
1615 * none
1616 */
1617static void
Dan Williamsffe191c2011-06-29 13:09:25 -07001618scic_sds_port_disable_port_task_scheduler(struct isci_port *iport)
Dan Williamse2f8db52011-05-10 02:28:46 -07001619{
1620 u32 pts_control_value;
1621
Dan Williamsffe191c2011-06-29 13:09:25 -07001622 pts_control_value = readl(&iport->port_task_scheduler_registers->control);
Dan Williamse2f8db52011-05-10 02:28:46 -07001623 pts_control_value &=
1624 ~(SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND));
Dan Williamsffe191c2011-06-29 13:09:25 -07001625 writel(pts_control_value, &iport->port_task_scheduler_registers->control);
Dan Williamse2f8db52011-05-10 02:28:46 -07001626}
1627
Dan Williamsffe191c2011-06-29 13:09:25 -07001628static void scic_sds_port_post_dummy_remote_node(struct isci_port *iport)
Dan Williamse2f8db52011-05-10 02:28:46 -07001629{
Dan Williamsd9dcb4b2011-06-30 17:38:32 -07001630 struct isci_host *ihost = iport->owning_controller;
Dan Williamsffe191c2011-06-29 13:09:25 -07001631 u8 phys_index = iport->physical_port_index;
Dan Williamse2f8db52011-05-10 02:28:46 -07001632 union scu_remote_node_context *rnc;
Dan Williamsffe191c2011-06-29 13:09:25 -07001633 u16 rni = iport->reserved_rni;
Dan Williamse2f8db52011-05-10 02:28:46 -07001634 u32 command;
1635
Dan Williamsd9dcb4b2011-06-30 17:38:32 -07001636 rnc = &ihost->remote_node_context_table[rni];
Dan Williamse2f8db52011-05-10 02:28:46 -07001637 rnc->ssp.is_valid = true;
1638
1639 command = SCU_CONTEXT_COMMAND_POST_RNC_32 |
1640 phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
1641
Dan Williamsd9dcb4b2011-06-30 17:38:32 -07001642 scic_sds_controller_post_request(ihost, command);
Dan Williamse2f8db52011-05-10 02:28:46 -07001643
1644 /* ensure hardware has seen the post rnc command and give it
1645 * ample time to act before sending the suspend
1646 */
Dan Williamsd9dcb4b2011-06-30 17:38:32 -07001647 readl(&ihost->smu_registers->interrupt_status); /* flush */
Dan Williamse2f8db52011-05-10 02:28:46 -07001648 udelay(10);
1649
1650 command = SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX |
1651 phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
1652
Dan Williamsd9dcb4b2011-06-30 17:38:32 -07001653 scic_sds_controller_post_request(ihost, command);
Dan Williamse2f8db52011-05-10 02:28:46 -07001654}
1655
Dan Williams9269e0e2011-05-12 07:42:17 -07001656static void scic_sds_port_stopped_state_enter(struct sci_base_state_machine *sm)
Dan Williamse2f8db52011-05-10 02:28:46 -07001657{
Dan Williamsffe191c2011-06-29 13:09:25 -07001658 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
Dan Williamse2f8db52011-05-10 02:28:46 -07001659
Dan Williamsffe191c2011-06-29 13:09:25 -07001660 if (iport->sm.previous_state_id == SCI_PORT_STOPPING) {
Dan Williamse2f8db52011-05-10 02:28:46 -07001661 /*
1662 * If we enter this state becasuse of a request to stop
1663 * the port then we want to disable the hardwares port
1664 * task scheduler. */
Dan Williamsffe191c2011-06-29 13:09:25 -07001665 scic_sds_port_disable_port_task_scheduler(iport);
Dan Williamse2f8db52011-05-10 02:28:46 -07001666 }
1667}
1668
Dan Williams9269e0e2011-05-12 07:42:17 -07001669static void scic_sds_port_stopped_state_exit(struct sci_base_state_machine *sm)
Dan Williamse2f8db52011-05-10 02:28:46 -07001670{
Dan Williamsffe191c2011-06-29 13:09:25 -07001671 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
Dan Williamse2f8db52011-05-10 02:28:46 -07001672
1673 /* Enable and suspend the port task scheduler */
Dan Williamsffe191c2011-06-29 13:09:25 -07001674 scic_sds_port_enable_port_task_scheduler(iport);
Dan Williamse2f8db52011-05-10 02:28:46 -07001675}
1676
Dan Williams9269e0e2011-05-12 07:42:17 -07001677static void scic_sds_port_ready_state_enter(struct sci_base_state_machine *sm)
Dan Williamse2f8db52011-05-10 02:28:46 -07001678{
Dan Williamsffe191c2011-06-29 13:09:25 -07001679 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
Dan Williamsd9dcb4b2011-06-30 17:38:32 -07001680 struct isci_host *ihost = iport->owning_controller;
Dan Williamse2f8db52011-05-10 02:28:46 -07001681 u32 prev_state;
1682
Dan Williamsffe191c2011-06-29 13:09:25 -07001683 prev_state = iport->sm.previous_state_id;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001684 if (prev_state == SCI_PORT_RESETTING)
Dan Williamse2f8db52011-05-10 02:28:46 -07001685 isci_port_hard_reset_complete(iport, SCI_SUCCESS);
1686 else
1687 isci_port_not_ready(ihost, iport);
1688
1689 /* Post and suspend the dummy remote node context for this port. */
Dan Williamsffe191c2011-06-29 13:09:25 -07001690 scic_sds_port_post_dummy_remote_node(iport);
Dan Williamse2f8db52011-05-10 02:28:46 -07001691
1692 /* Start the ready substate machine */
Dan Williamsffe191c2011-06-29 13:09:25 -07001693 port_state_machine_change(iport,
Edmund Nadolskie3013702011-06-02 00:10:43 +00001694 SCI_PORT_SUB_WAITING);
Dan Williamse2f8db52011-05-10 02:28:46 -07001695}
1696
Dan Williams9269e0e2011-05-12 07:42:17 -07001697static void scic_sds_port_resetting_state_exit(struct sci_base_state_machine *sm)
Dan Williamse2f8db52011-05-10 02:28:46 -07001698{
Dan Williamsffe191c2011-06-29 13:09:25 -07001699 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
Dan Williamse2f8db52011-05-10 02:28:46 -07001700
Dan Williamsffe191c2011-06-29 13:09:25 -07001701 sci_del_timer(&iport->timer);
Dan Williamse2f8db52011-05-10 02:28:46 -07001702}
1703
Dan Williams9269e0e2011-05-12 07:42:17 -07001704static void scic_sds_port_stopping_state_exit(struct sci_base_state_machine *sm)
Dan Williamse2f8db52011-05-10 02:28:46 -07001705{
Dan Williamsffe191c2011-06-29 13:09:25 -07001706 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
Dan Williamse2f8db52011-05-10 02:28:46 -07001707
Dan Williamsffe191c2011-06-29 13:09:25 -07001708 sci_del_timer(&iport->timer);
Dan Williamse2f8db52011-05-10 02:28:46 -07001709
Dan Williamsffe191c2011-06-29 13:09:25 -07001710 scic_sds_port_destroy_dummy_resources(iport);
Dan Williamse2f8db52011-05-10 02:28:46 -07001711}
1712
Dan Williams9269e0e2011-05-12 07:42:17 -07001713static void scic_sds_port_failed_state_enter(struct sci_base_state_machine *sm)
Dan Williamse2f8db52011-05-10 02:28:46 -07001714{
Dan Williamsffe191c2011-06-29 13:09:25 -07001715 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
Dan Williamse2f8db52011-05-10 02:28:46 -07001716
Dan Williamse2f8db52011-05-10 02:28:46 -07001717 isci_port_hard_reset_complete(iport, SCI_FAILURE_TIMEOUT);
1718}
1719
1720/* --------------------------------------------------------------------------- */
1721
1722static const struct sci_base_state scic_sds_port_state_table[] = {
Edmund Nadolskie3013702011-06-02 00:10:43 +00001723 [SCI_PORT_STOPPED] = {
Dan Williamse2f8db52011-05-10 02:28:46 -07001724 .enter_state = scic_sds_port_stopped_state_enter,
1725 .exit_state = scic_sds_port_stopped_state_exit
1726 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001727 [SCI_PORT_STOPPING] = {
Dan Williamse2f8db52011-05-10 02:28:46 -07001728 .exit_state = scic_sds_port_stopping_state_exit
1729 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001730 [SCI_PORT_READY] = {
Dan Williamse2f8db52011-05-10 02:28:46 -07001731 .enter_state = scic_sds_port_ready_state_enter,
Piotr Sawickie91f41e2011-05-11 23:52:21 +00001732 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001733 [SCI_PORT_SUB_WAITING] = {
Piotr Sawickie91f41e2011-05-11 23:52:21 +00001734 .enter_state = scic_sds_port_ready_substate_waiting_enter,
1735 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001736 [SCI_PORT_SUB_OPERATIONAL] = {
Piotr Sawickie91f41e2011-05-11 23:52:21 +00001737 .enter_state = scic_sds_port_ready_substate_operational_enter,
1738 .exit_state = scic_sds_port_ready_substate_operational_exit
1739 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001740 [SCI_PORT_SUB_CONFIGURING] = {
Piotr Sawickie91f41e2011-05-11 23:52:21 +00001741 .enter_state = scic_sds_port_ready_substate_configuring_enter,
1742 .exit_state = scic_sds_port_ready_substate_configuring_exit
Dan Williamse2f8db52011-05-10 02:28:46 -07001743 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001744 [SCI_PORT_RESETTING] = {
Dan Williamse2f8db52011-05-10 02:28:46 -07001745 .exit_state = scic_sds_port_resetting_state_exit
1746 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00001747 [SCI_PORT_FAILED] = {
Dan Williamse2f8db52011-05-10 02:28:46 -07001748 .enter_state = scic_sds_port_failed_state_enter,
1749 }
1750};
1751
Dan Williamsffe191c2011-06-29 13:09:25 -07001752void scic_sds_port_construct(struct isci_port *iport, u8 index,
Dan Williamsd9dcb4b2011-06-30 17:38:32 -07001753 struct isci_host *ihost)
Dan Williamse2f8db52011-05-10 02:28:46 -07001754{
Dan Williamsffe191c2011-06-29 13:09:25 -07001755 sci_init_sm(&iport->sm, scic_sds_port_state_table, SCI_PORT_STOPPED);
Dan Williamse2f8db52011-05-10 02:28:46 -07001756
Dan Williamsffe191c2011-06-29 13:09:25 -07001757 iport->logical_port_index = SCIC_SDS_DUMMY_PORT;
1758 iport->physical_port_index = index;
1759 iport->active_phy_mask = 0;
1760 iport->ready_exit = false;
Dan Williamse2f8db52011-05-10 02:28:46 -07001761
Dan Williamsd9dcb4b2011-06-30 17:38:32 -07001762 iport->owning_controller = ihost;
Dan Williamse2f8db52011-05-10 02:28:46 -07001763
Dan Williamsffe191c2011-06-29 13:09:25 -07001764 iport->started_request_count = 0;
1765 iport->assigned_device_count = 0;
Dan Williamse2f8db52011-05-10 02:28:46 -07001766
Dan Williamsffe191c2011-06-29 13:09:25 -07001767 iport->reserved_rni = SCU_DUMMY_INDEX;
1768 iport->reserved_tag = SCI_CONTROLLER_INVALID_IO_TAG;
Dan Williamse2f8db52011-05-10 02:28:46 -07001769
Dan Williamsffe191c2011-06-29 13:09:25 -07001770 sci_init_timer(&iport->timer, port_timeout);
Edmund Nadolski5553ba22011-05-19 11:59:10 +00001771
Dan Williamsffe191c2011-06-29 13:09:25 -07001772 iport->port_task_scheduler_registers = NULL;
Dan Williamse2f8db52011-05-10 02:28:46 -07001773
1774 for (index = 0; index < SCI_MAX_PHYS; index++)
Dan Williamsffe191c2011-06-29 13:09:25 -07001775 iport->phy_table[index] = NULL;
Dan Williamse2f8db52011-05-10 02:28:46 -07001776}
1777
1778void isci_port_init(struct isci_port *iport, struct isci_host *ihost, int index)
1779{
1780 INIT_LIST_HEAD(&iport->remote_dev_list);
1781 INIT_LIST_HEAD(&iport->domain_dev_list);
1782 spin_lock_init(&iport->state_lock);
1783 init_completion(&iport->start_complete);
1784 iport->isci_host = ihost;
1785 isci_port_change_state(iport, isci_freed);
Jeff Skirvin61aaff42011-06-21 12:16:33 -07001786 atomic_set(&iport->event, 0);
Dan Williamse2f8db52011-05-10 02:28:46 -07001787}
1788
1789/**
1790 * isci_port_get_state() - This function gets the status of the port object.
1791 * @isci_port: This parameter points to the isci_port object
1792 *
1793 * status of the object as a isci_status enum.
1794 */
1795enum isci_status isci_port_get_state(
1796 struct isci_port *isci_port)
1797{
1798 return isci_port->status;
1799}
1800
Dan Williamse2f8db52011-05-10 02:28:46 -07001801void scic_sds_port_broadcast_change_received(
Dan Williamsffe191c2011-06-29 13:09:25 -07001802 struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -07001803 struct isci_phy *iphy)
Dan Williamse2f8db52011-05-10 02:28:46 -07001804{
Dan Williamsd9dcb4b2011-06-30 17:38:32 -07001805 struct isci_host *ihost = iport->owning_controller;
Dan Williamse2f8db52011-05-10 02:28:46 -07001806
1807 /* notify the user. */
Dan Williamsffe191c2011-06-29 13:09:25 -07001808 isci_port_bc_change_received(ihost, iport, iphy);
Dan Williamse2f8db52011-05-10 02:28:46 -07001809}
1810
Dan Williams4393aa42011-03-31 13:10:44 -07001811int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *iport,
1812 struct isci_phy *iphy)
Dan Williams6f231dd2011-07-02 22:56:22 -07001813{
Dan Williams4393aa42011-03-31 13:10:44 -07001814 unsigned long flags;
Dan Williams6f231dd2011-07-02 22:56:22 -07001815 enum sci_status status;
Jeff Skirvinfd0527a2011-06-20 14:09:26 -07001816 int idx, ret = TMF_RESP_FUNC_COMPLETE;
Dan Williams6f231dd2011-07-02 22:56:22 -07001817
Dan Williams4393aa42011-03-31 13:10:44 -07001818 dev_dbg(&ihost->pdev->dev, "%s: iport = %p\n",
1819 __func__, iport);
Dan Williams6f231dd2011-07-02 22:56:22 -07001820
Dan Williams4393aa42011-03-31 13:10:44 -07001821 init_completion(&iport->hard_reset_complete);
Dan Williams6f231dd2011-07-02 22:56:22 -07001822
Dan Williams4393aa42011-03-31 13:10:44 -07001823 spin_lock_irqsave(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001824
1825 #define ISCI_PORT_RESET_TIMEOUT SCIC_SDS_SIGNATURE_FIS_TIMEOUT
Dan Williamsffe191c2011-06-29 13:09:25 -07001826 status = scic_port_hard_reset(iport, ISCI_PORT_RESET_TIMEOUT);
Dan Williams6f231dd2011-07-02 22:56:22 -07001827
Dan Williams4393aa42011-03-31 13:10:44 -07001828 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001829
1830 if (status == SCI_SUCCESS) {
Dan Williams4393aa42011-03-31 13:10:44 -07001831 wait_for_completion(&iport->hard_reset_complete);
Dan Williams6f231dd2011-07-02 22:56:22 -07001832
Dan Williams4393aa42011-03-31 13:10:44 -07001833 dev_dbg(&ihost->pdev->dev,
1834 "%s: iport = %p; hard reset completion\n",
1835 __func__, iport);
Dan Williams6f231dd2011-07-02 22:56:22 -07001836
Dan Williams4393aa42011-03-31 13:10:44 -07001837 if (iport->hard_reset_status != SCI_SUCCESS)
Dan Williams6f231dd2011-07-02 22:56:22 -07001838 ret = TMF_RESP_FUNC_FAILED;
1839 } else {
1840 ret = TMF_RESP_FUNC_FAILED;
1841
Dan Williams4393aa42011-03-31 13:10:44 -07001842 dev_err(&ihost->pdev->dev,
1843 "%s: iport = %p; scic_port_hard_reset call"
Dan Williams6f231dd2011-07-02 22:56:22 -07001844 " failed 0x%x\n",
Dan Williams4393aa42011-03-31 13:10:44 -07001845 __func__, iport, status);
Dan Williams6f231dd2011-07-02 22:56:22 -07001846
1847 }
1848
1849 /* If the hard reset for the port has failed, consider this
1850 * the same as link failures on all phys in the port.
1851 */
1852 if (ret != TMF_RESP_FUNC_COMPLETE) {
Jeff Skirvinfd0527a2011-06-20 14:09:26 -07001853
Dan Williams4393aa42011-03-31 13:10:44 -07001854 dev_err(&ihost->pdev->dev,
1855 "%s: iport = %p; hard reset failed "
Jeff Skirvinfd0527a2011-06-20 14:09:26 -07001856 "(0x%x) - driving explicit link fail for all phys\n",
1857 __func__, iport, iport->hard_reset_status);
Dan Williams6f231dd2011-07-02 22:56:22 -07001858
Jeff Skirvinfd0527a2011-06-20 14:09:26 -07001859 /* Down all phys in the port. */
1860 spin_lock_irqsave(&ihost->scic_lock, flags);
1861 for (idx = 0; idx < SCI_MAX_PHYS; ++idx) {
Dan Williamsffe191c2011-06-29 13:09:25 -07001862 struct isci_phy *iphy = iport->phy_table[idx];
Jeff Skirvinfd0527a2011-06-20 14:09:26 -07001863
Dan Williamsffe191c2011-06-29 13:09:25 -07001864 if (!iphy)
1865 continue;
1866 scic_sds_phy_stop(iphy);
1867 scic_sds_phy_start(iphy);
Jeff Skirvinfd0527a2011-06-20 14:09:26 -07001868 }
1869 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001870 }
Dan Williams6f231dd2011-07-02 22:56:22 -07001871 return ret;
1872}
Dave Jiang09d7da12011-03-26 16:11:51 -07001873
Dan Williamse2f8db52011-05-10 02:28:46 -07001874/**
1875 * isci_port_deformed() - This function is called by libsas when a port becomes
1876 * inactive.
1877 * @phy: This parameter specifies the libsas phy with the inactive port.
1878 *
1879 */
1880void isci_port_deformed(struct asd_sas_phy *phy)
Dave Jiang09d7da12011-03-26 16:11:51 -07001881{
Dan Williamse2f8db52011-05-10 02:28:46 -07001882 pr_debug("%s: sas_phy = %p\n", __func__, phy);
1883}
1884
1885/**
1886 * isci_port_formed() - This function is called by libsas when a port becomes
1887 * active.
1888 * @phy: This parameter specifies the libsas phy with the active port.
1889 *
1890 */
1891void isci_port_formed(struct asd_sas_phy *phy)
1892{
1893 pr_debug("%s: sas_phy = %p, sas_port = %p\n", __func__, phy, phy->port);
Dave Jiang09d7da12011-03-26 16:11:51 -07001894}