Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1 | /* |
| 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 Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 56 | #include "isci.h" |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 57 | #include "port.h" |
| 58 | #include "request.h" |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 59 | |
| 60 | #define SCIC_SDS_PORT_HARD_RESET_TIMEOUT (1000) |
| 61 | #define SCU_DUMMY_INDEX (0xFFFF) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 62 | |
Dan Williams | c132f69 | 2012-01-03 23:26:08 -0800 | [diff] [blame] | 63 | static struct device *sciport_to_dev(struct isci_port *iport) |
| 64 | { |
| 65 | int i = iport->physical_port_index; |
| 66 | struct isci_port *table; |
| 67 | struct isci_host *ihost; |
| 68 | |
| 69 | if (i == SCIC_SDS_DUMMY_PORT) |
| 70 | i = SCI_MAX_PORTS+1; |
| 71 | |
| 72 | table = iport - i; |
| 73 | ihost = container_of(table, typeof(*ihost), ports[0]); |
| 74 | |
| 75 | return &ihost->pdev->dev; |
| 76 | } |
| 77 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 78 | static void sci_port_get_protocols(struct isci_port *iport, struct sci_phy_proto *proto) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 79 | { |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 80 | u8 index; |
| 81 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 82 | proto->all = 0; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 83 | for (index = 0; index < SCI_MAX_PHYS; index++) { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 84 | struct isci_phy *iphy = iport->phy_table[index]; |
| 85 | |
| 86 | if (!iphy) |
| 87 | continue; |
| 88 | sci_phy_get_protocols(iphy, proto); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 89 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 92 | static u32 sci_port_get_phys(struct isci_port *iport) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 93 | { |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 94 | u32 index; |
| 95 | u32 mask; |
| 96 | |
| 97 | mask = 0; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 98 | for (index = 0; index < SCI_MAX_PHYS; index++) |
| 99 | if (iport->phy_table[index]) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 100 | mask |= (1 << index); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 101 | |
| 102 | return mask; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 105 | /** |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 106 | * sci_port_get_properties() - This method simply returns the properties |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 107 | * regarding the port, such as: physical index, protocols, sas address, etc. |
| 108 | * @port: this parameter specifies the port for which to retrieve the physical |
| 109 | * index. |
| 110 | * @properties: This parameter specifies the properties structure into which to |
| 111 | * copy the requested information. |
| 112 | * |
| 113 | * Indicate if the user specified a valid port. SCI_SUCCESS This value is |
| 114 | * returned if the specified port was valid. SCI_FAILURE_INVALID_PORT This |
| 115 | * value is returned if the specified port is not valid. When this value is |
| 116 | * returned, no data is copied to the properties output parameter. |
| 117 | */ |
Bartek Nowakowski | 7e62984 | 2012-01-04 01:33:20 -0800 | [diff] [blame] | 118 | enum sci_status sci_port_get_properties(struct isci_port *iport, |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 119 | struct sci_port_properties *prop) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 120 | { |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 121 | if (!iport || iport->logical_port_index == SCIC_SDS_DUMMY_PORT) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 122 | return SCI_FAILURE_INVALID_PORT; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 123 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 124 | prop->index = iport->logical_port_index; |
| 125 | prop->phy_mask = sci_port_get_phys(iport); |
| 126 | sci_port_get_sas_address(iport, &prop->local.sas_address); |
| 127 | sci_port_get_protocols(iport, &prop->local.protocols); |
| 128 | sci_port_get_attached_sas_address(iport, &prop->remote.sas_address); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 129 | |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 130 | return SCI_SUCCESS; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 133 | static void sci_port_bcn_enable(struct isci_port *iport) |
Jeff Skirvin | 61aaff4 | 2011-06-21 12:16:33 -0700 | [diff] [blame] | 134 | { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 135 | struct isci_phy *iphy; |
Jeff Skirvin | 61aaff4 | 2011-06-21 12:16:33 -0700 | [diff] [blame] | 136 | u32 val; |
| 137 | int i; |
| 138 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 139 | for (i = 0; i < ARRAY_SIZE(iport->phy_table); i++) { |
| 140 | iphy = iport->phy_table[i]; |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 141 | if (!iphy) |
Jeff Skirvin | 61aaff4 | 2011-06-21 12:16:33 -0700 | [diff] [blame] | 142 | continue; |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 143 | val = readl(&iphy->link_layer_registers->link_layer_control); |
Jeff Skirvin | 61aaff4 | 2011-06-21 12:16:33 -0700 | [diff] [blame] | 144 | /* clear the bit by writing 1. */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 145 | writel(val, &iphy->link_layer_registers->link_layer_control); |
Jeff Skirvin | 61aaff4 | 2011-06-21 12:16:33 -0700 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 149 | static void isci_port_bc_change_received(struct isci_host *ihost, |
| 150 | struct isci_port *iport, |
| 151 | struct isci_phy *iphy) |
Jeff Skirvin | 61aaff4 | 2011-06-21 12:16:33 -0700 | [diff] [blame] | 152 | { |
Dan Williams | 52d7463 | 2011-10-27 15:05:37 -0700 | [diff] [blame] | 153 | dev_dbg(&ihost->pdev->dev, |
| 154 | "%s: isci_phy = %p, sas_phy = %p\n", |
| 155 | __func__, iphy, &iphy->sas_phy); |
Jeff Skirvin | 61aaff4 | 2011-06-21 12:16:33 -0700 | [diff] [blame] | 156 | |
Dan Williams | 52d7463 | 2011-10-27 15:05:37 -0700 | [diff] [blame] | 157 | ihost->sas_ha.notify_port_event(&iphy->sas_phy, PORTE_BROADCAST_RCVD); |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 158 | sci_port_bcn_enable(iport); |
Jeff Skirvin | 61aaff4 | 2011-06-21 12:16:33 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 161 | static void isci_port_link_up(struct isci_host *isci_host, |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 162 | struct isci_port *iport, |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 163 | struct isci_phy *iphy) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 164 | { |
| 165 | unsigned long flags; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 166 | struct sci_port_properties properties; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 167 | unsigned long success = true; |
| 168 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 169 | dev_dbg(&isci_host->pdev->dev, |
| 170 | "%s: isci_port = %p\n", |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 171 | __func__, iport); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 172 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 173 | spin_lock_irqsave(&iphy->sas_phy.frame_rcvd_lock, flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 174 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 175 | sci_port_get_properties(iport, &properties); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 176 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 177 | if (iphy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) { |
Dan Williams | 150fc6f | 2011-02-25 10:25:21 -0800 | [diff] [blame] | 178 | u64 attached_sas_address; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 179 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 180 | iphy->sas_phy.oob_mode = SATA_OOB_MODE; |
| 181 | iphy->sas_phy.frame_rcvd_size = sizeof(struct dev_to_host_fis); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 182 | |
| 183 | /* |
| 184 | * For direct-attached SATA devices, the SCI core will |
| 185 | * automagically assign a SAS address to the end device |
| 186 | * for the purpose of creating a port. This SAS address |
| 187 | * will not be the same as assigned to the PHY and needs |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 188 | * to be obtained from struct sci_port_properties properties. |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 189 | */ |
Dan Williams | 150fc6f | 2011-02-25 10:25:21 -0800 | [diff] [blame] | 190 | attached_sas_address = properties.remote.sas_address.high; |
| 191 | attached_sas_address <<= 32; |
| 192 | attached_sas_address |= properties.remote.sas_address.low; |
| 193 | swab64s(&attached_sas_address); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 194 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 195 | memcpy(&iphy->sas_phy.attached_sas_addr, |
Dan Williams | 150fc6f | 2011-02-25 10:25:21 -0800 | [diff] [blame] | 196 | &attached_sas_address, sizeof(attached_sas_address)); |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 197 | } else if (iphy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) { |
| 198 | iphy->sas_phy.oob_mode = SAS_OOB_MODE; |
| 199 | iphy->sas_phy.frame_rcvd_size = sizeof(struct sas_identify_frame); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 200 | |
| 201 | /* Copy the attached SAS address from the IAF */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 202 | memcpy(iphy->sas_phy.attached_sas_addr, |
| 203 | iphy->frame_rcvd.iaf.sas_addr, SAS_ADDR_SIZE); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 204 | } else { |
| 205 | dev_err(&isci_host->pdev->dev, "%s: unkown target\n", __func__); |
| 206 | success = false; |
| 207 | } |
| 208 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 209 | iphy->sas_phy.phy->negotiated_linkrate = sci_phy_linkrate(iphy); |
Dan Williams | 83e5143 | 2011-02-18 09:25:13 -0800 | [diff] [blame] | 210 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 211 | spin_unlock_irqrestore(&iphy->sas_phy.frame_rcvd_lock, flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 212 | |
| 213 | /* Notify libsas that we have an address frame, if indeed |
| 214 | * we've found an SSP, SMP, or STP target */ |
| 215 | if (success) |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 216 | isci_host->sas_ha.notify_port_event(&iphy->sas_phy, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 217 | PORTE_BYTES_DMAED); |
| 218 | } |
| 219 | |
| 220 | |
| 221 | /** |
| 222 | * isci_port_link_down() - This function is called by the sci core when a link |
| 223 | * becomes inactive. |
| 224 | * @isci_host: This parameter specifies the isci host object. |
| 225 | * @phy: This parameter specifies the isci phy with the active link. |
| 226 | * @port: This parameter specifies the isci port with the active link. |
| 227 | * |
| 228 | */ |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 229 | static void isci_port_link_down(struct isci_host *isci_host, |
| 230 | struct isci_phy *isci_phy, |
| 231 | struct isci_port *isci_port) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 232 | { |
| 233 | struct isci_remote_device *isci_device; |
| 234 | |
| 235 | dev_dbg(&isci_host->pdev->dev, |
| 236 | "%s: isci_port = %p\n", __func__, isci_port); |
| 237 | |
| 238 | if (isci_port) { |
| 239 | |
| 240 | /* check to see if this is the last phy on this port. */ |
Jeff Skirvin | 61aaff4 | 2011-06-21 12:16:33 -0700 | [diff] [blame] | 241 | if (isci_phy->sas_phy.port && |
| 242 | isci_phy->sas_phy.port->num_phys == 1) { |
Jeff Skirvin | 61aaff4 | 2011-06-21 12:16:33 -0700 | [diff] [blame] | 243 | /* change the state for all devices on this port. The |
| 244 | * next task sent to this device will be returned as |
| 245 | * SAS_TASK_UNDELIVERED, and the scsi mid layer will |
| 246 | * remove the target |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 247 | */ |
| 248 | list_for_each_entry(isci_device, |
| 249 | &isci_port->remote_dev_list, |
| 250 | node) { |
| 251 | dev_dbg(&isci_host->pdev->dev, |
| 252 | "%s: isci_device = %p\n", |
| 253 | __func__, isci_device); |
Dan Williams | 209fae1 | 2011-06-13 17:39:44 -0700 | [diff] [blame] | 254 | set_bit(IDEV_GONE, &isci_device->flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 255 | } |
| 256 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | /* Notify libsas of the borken link, this will trigger calls to our |
| 260 | * isci_port_deformed and isci_dev_gone functions. |
| 261 | */ |
| 262 | sas_phy_disconnected(&isci_phy->sas_phy); |
| 263 | isci_host->sas_ha.notify_phy_event(&isci_phy->sas_phy, |
| 264 | PHYE_LOSS_OF_SIGNAL); |
| 265 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 266 | dev_dbg(&isci_host->pdev->dev, |
| 267 | "%s: isci_port = %p - Done\n", __func__, isci_port); |
| 268 | } |
| 269 | |
Jeff Skirvin | 8e35a13 | 2011-10-27 15:05:32 -0700 | [diff] [blame] | 270 | static bool is_port_ready_state(enum sci_port_states state) |
| 271 | { |
| 272 | switch (state) { |
| 273 | case SCI_PORT_READY: |
| 274 | case SCI_PORT_SUB_WAITING: |
| 275 | case SCI_PORT_SUB_OPERATIONAL: |
| 276 | case SCI_PORT_SUB_CONFIGURING: |
| 277 | return true; |
| 278 | default: |
| 279 | return false; |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | /* flag dummy rnc hanling when exiting a ready state */ |
| 284 | static void port_state_machine_change(struct isci_port *iport, |
| 285 | enum sci_port_states state) |
| 286 | { |
| 287 | struct sci_base_state_machine *sm = &iport->sm; |
| 288 | enum sci_port_states old_state = sm->current_state_id; |
| 289 | |
| 290 | if (is_port_ready_state(old_state) && !is_port_ready_state(state)) |
| 291 | iport->ready_exit = true; |
| 292 | |
| 293 | sci_change_state(sm, state); |
| 294 | iport->ready_exit = false; |
| 295 | } |
| 296 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 297 | /** |
| 298 | * isci_port_hard_reset_complete() - This function is called by the sci core |
| 299 | * when the hard reset complete notification has been received. |
| 300 | * @port: This parameter specifies the sci port with the active link. |
| 301 | * @completion_status: This parameter specifies the core status for the reset |
| 302 | * process. |
| 303 | * |
| 304 | */ |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 305 | static void isci_port_hard_reset_complete(struct isci_port *isci_port, |
| 306 | enum sci_status completion_status) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 307 | { |
Dan Williams | 9277699 | 2011-11-30 11:57:34 -0800 | [diff] [blame] | 308 | struct isci_host *ihost = isci_port->owning_controller; |
| 309 | |
| 310 | dev_dbg(&ihost->pdev->dev, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 311 | "%s: isci_port = %p, completion_status=%x\n", |
| 312 | __func__, isci_port, completion_status); |
| 313 | |
| 314 | /* Save the status of the hard reset from the port. */ |
| 315 | isci_port->hard_reset_status = completion_status; |
| 316 | |
Jeff Skirvin | 8e35a13 | 2011-10-27 15:05:32 -0700 | [diff] [blame] | 317 | if (completion_status != SCI_SUCCESS) { |
| 318 | |
| 319 | /* The reset failed. The port state is now SCI_PORT_FAILED. */ |
| 320 | if (isci_port->active_phy_mask == 0) { |
Dan Williams | 9277699 | 2011-11-30 11:57:34 -0800 | [diff] [blame] | 321 | int phy_idx = isci_port->last_active_phy; |
| 322 | struct isci_phy *iphy = &ihost->phys[phy_idx]; |
Jeff Skirvin | 8e35a13 | 2011-10-27 15:05:32 -0700 | [diff] [blame] | 323 | |
| 324 | /* Generate the link down now to the host, since it |
| 325 | * was intercepted by the hard reset state machine when |
| 326 | * it really happened. |
| 327 | */ |
Dan Williams | 9277699 | 2011-11-30 11:57:34 -0800 | [diff] [blame] | 328 | isci_port_link_down(ihost, iphy, isci_port); |
Jeff Skirvin | 8e35a13 | 2011-10-27 15:05:32 -0700 | [diff] [blame] | 329 | } |
| 330 | /* Advance the port state so that link state changes will be |
Dan Williams | 9277699 | 2011-11-30 11:57:34 -0800 | [diff] [blame] | 331 | * noticed. |
| 332 | */ |
Jeff Skirvin | 8e35a13 | 2011-10-27 15:05:32 -0700 | [diff] [blame] | 333 | port_state_machine_change(isci_port, SCI_PORT_SUB_WAITING); |
| 334 | |
| 335 | } |
Dan Williams | 9277699 | 2011-11-30 11:57:34 -0800 | [diff] [blame] | 336 | clear_bit(IPORT_RESET_PENDING, &isci_port->state); |
| 337 | wake_up(&ihost->eventq); |
| 338 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 339 | } |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 340 | |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 341 | /* This method will return a true value if the specified phy can be assigned to |
| 342 | * this port The following is a list of phys for each port that are allowed: - |
| 343 | * Port 0 - 3 2 1 0 - Port 1 - 1 - Port 2 - 3 2 - Port 3 - 3 This method |
| 344 | * doesn't preclude all configurations. It merely ensures that a phy is part |
| 345 | * of the allowable set of phy identifiers for that port. For example, one |
| 346 | * could assign phy 3 to port 0 and no other phys. Please refer to |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 347 | * sci_port_is_phy_mask_valid() for information regarding whether the |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 348 | * phy_mask for a port can be supported. bool true if this is a valid phy |
| 349 | * assignment for the port false if this is not a valid phy assignment for the |
| 350 | * port |
| 351 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 352 | bool sci_port_is_valid_phy_assignment(struct isci_port *iport, u32 phy_index) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 353 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 354 | struct isci_host *ihost = iport->owning_controller; |
| 355 | struct sci_user_parameters *user = &ihost->user_parameters; |
| 356 | |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 357 | /* Initialize to invalid value. */ |
| 358 | u32 existing_phy_index = SCI_MAX_PHYS; |
| 359 | u32 index; |
| 360 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 361 | if ((iport->physical_port_index == 1) && (phy_index != 1)) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 362 | return false; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 363 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 364 | if (iport->physical_port_index == 3 && phy_index != 3) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 365 | return false; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 366 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 367 | if (iport->physical_port_index == 2 && |
| 368 | (phy_index == 0 || phy_index == 1)) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 369 | return false; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 370 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 371 | for (index = 0; index < SCI_MAX_PHYS; index++) |
| 372 | if (iport->phy_table[index] && index != phy_index) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 373 | existing_phy_index = index; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 374 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 375 | /* Ensure that all of the phys in the port are capable of |
| 376 | * operating at the same maximum link rate. |
| 377 | */ |
| 378 | if (existing_phy_index < SCI_MAX_PHYS && |
| 379 | user->phys[phy_index].max_speed_generation != |
| 380 | user->phys[existing_phy_index].max_speed_generation) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 381 | return false; |
| 382 | |
| 383 | return true; |
| 384 | } |
| 385 | |
| 386 | /** |
| 387 | * |
| 388 | * @sci_port: This is the port object for which to determine if the phy mask |
| 389 | * can be supported. |
| 390 | * |
| 391 | * This method will return a true value if the port's phy mask can be supported |
| 392 | * by the SCU. The following is a list of valid PHY mask configurations for |
| 393 | * each port: - Port 0 - [[3 2] 1] 0 - Port 1 - [1] - Port 2 - [[3] 2] |
| 394 | * - Port 3 - [3] This method returns a boolean indication specifying if the |
| 395 | * phy mask can be supported. true if this is a valid phy assignment for the |
| 396 | * port false if this is not a valid phy assignment for the port |
| 397 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 398 | static bool sci_port_is_phy_mask_valid( |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 399 | struct isci_port *iport, |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 400 | u32 phy_mask) |
| 401 | { |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 402 | if (iport->physical_port_index == 0) { |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 403 | if (((phy_mask & 0x0F) == 0x0F) |
| 404 | || ((phy_mask & 0x03) == 0x03) |
| 405 | || ((phy_mask & 0x01) == 0x01) |
| 406 | || (phy_mask == 0)) |
| 407 | return true; |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 408 | } else if (iport->physical_port_index == 1) { |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 409 | if (((phy_mask & 0x02) == 0x02) |
| 410 | || (phy_mask == 0)) |
| 411 | return true; |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 412 | } else if (iport->physical_port_index == 2) { |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 413 | if (((phy_mask & 0x0C) == 0x0C) |
| 414 | || ((phy_mask & 0x04) == 0x04) |
| 415 | || (phy_mask == 0)) |
| 416 | return true; |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 417 | } else if (iport->physical_port_index == 3) { |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 418 | if (((phy_mask & 0x08) == 0x08) |
| 419 | || (phy_mask == 0)) |
| 420 | return true; |
| 421 | } |
| 422 | |
| 423 | return false; |
| 424 | } |
| 425 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 426 | /* |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 427 | * This method retrieves a currently active (i.e. connected) phy contained in |
| 428 | * the port. Currently, the lowest order phy that is connected is returned. |
| 429 | * This method returns a pointer to a SCIS_SDS_PHY object. NULL This value is |
| 430 | * returned if there are no currently active (i.e. connected to a remote end |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 431 | * point) phys contained in the port. All other values specify a struct sci_phy |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 432 | * object that is active in the port. |
| 433 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 434 | static struct isci_phy *sci_port_get_a_connected_phy(struct isci_port *iport) |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 435 | { |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 436 | u32 index; |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 437 | struct isci_phy *iphy; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 438 | |
| 439 | for (index = 0; index < SCI_MAX_PHYS; index++) { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 440 | /* Ensure that the phy is both part of the port and currently |
| 441 | * connected to the remote end-point. |
| 442 | */ |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 443 | iphy = iport->phy_table[index]; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 444 | if (iphy && sci_port_active_phy(iport, iphy)) |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 445 | return iphy; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | return NULL; |
| 449 | } |
| 450 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 451 | static enum sci_status sci_port_set_phy(struct isci_port *iport, struct isci_phy *iphy) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 452 | { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 453 | /* Check to see if we can add this phy to a port |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 454 | * that means that the phy is not part of a port and that the port does |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 455 | * not already have a phy assinged to the phy index. |
| 456 | */ |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 457 | if (!iport->phy_table[iphy->phy_index] && |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 458 | !phy_get_non_dummy_port(iphy) && |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 459 | sci_port_is_valid_phy_assignment(iport, iphy->phy_index)) { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 460 | /* Phy is being added in the stopped state so we are in MPC mode |
| 461 | * make logical port index = physical port index |
| 462 | */ |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 463 | iport->logical_port_index = iport->physical_port_index; |
| 464 | iport->phy_table[iphy->phy_index] = iphy; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 465 | sci_phy_set_port(iphy, iport); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 466 | |
| 467 | return SCI_SUCCESS; |
| 468 | } |
| 469 | |
| 470 | return SCI_FAILURE; |
| 471 | } |
| 472 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 473 | static enum sci_status sci_port_clear_phy(struct isci_port *iport, struct isci_phy *iphy) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 474 | { |
| 475 | /* Make sure that this phy is part of this port */ |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 476 | if (iport->phy_table[iphy->phy_index] == iphy && |
| 477 | phy_get_non_dummy_port(iphy) == iport) { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 478 | struct isci_host *ihost = iport->owning_controller; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 479 | |
| 480 | /* Yep it is assigned to this port so remove it */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 481 | sci_phy_set_port(iphy, &ihost->ports[SCI_MAX_PORTS]); |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 482 | iport->phy_table[iphy->phy_index] = NULL; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 483 | return SCI_SUCCESS; |
| 484 | } |
| 485 | |
| 486 | return SCI_FAILURE; |
| 487 | } |
| 488 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 489 | void sci_port_get_sas_address(struct isci_port *iport, struct sci_sas_address *sas) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 490 | { |
| 491 | u32 index; |
| 492 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 493 | sas->high = 0; |
| 494 | sas->low = 0; |
| 495 | for (index = 0; index < SCI_MAX_PHYS; index++) |
| 496 | if (iport->phy_table[index]) |
| 497 | sci_phy_get_sas_address(iport->phy_table[index], sas); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 498 | } |
| 499 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 500 | void sci_port_get_attached_sas_address(struct isci_port *iport, struct sci_sas_address *sas) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 501 | { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 502 | struct isci_phy *iphy; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 503 | |
| 504 | /* |
| 505 | * Ensure that the phy is both part of the port and currently |
| 506 | * connected to the remote end-point. |
| 507 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 508 | iphy = sci_port_get_a_connected_phy(iport); |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 509 | if (iphy) { |
| 510 | if (iphy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA) { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 511 | sci_phy_get_attached_sas_address(iphy, sas); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 512 | } else { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 513 | sci_phy_get_sas_address(iphy, sas); |
| 514 | sas->low += iphy->phy_index; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 515 | } |
| 516 | } else { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 517 | sas->high = 0; |
| 518 | sas->low = 0; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 519 | } |
| 520 | } |
| 521 | |
| 522 | /** |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 523 | * sci_port_construct_dummy_rnc() - create dummy rnc for si workaround |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 524 | * |
| 525 | * @sci_port: logical port on which we need to create the remote node context |
| 526 | * @rni: remote node index for this remote node context. |
| 527 | * |
| 528 | * This routine will construct a dummy remote node context data structure |
| 529 | * This structure will be posted to the hardware to work around a scheduler |
| 530 | * error in the hardware. |
| 531 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 532 | static void sci_port_construct_dummy_rnc(struct isci_port *iport, u16 rni) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 533 | { |
| 534 | union scu_remote_node_context *rnc; |
| 535 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 536 | rnc = &iport->owning_controller->remote_node_context_table[rni]; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 537 | |
| 538 | memset(rnc, 0, sizeof(union scu_remote_node_context)); |
| 539 | |
| 540 | rnc->ssp.remote_sas_address_hi = 0; |
| 541 | rnc->ssp.remote_sas_address_lo = 0; |
| 542 | |
| 543 | rnc->ssp.remote_node_index = rni; |
| 544 | rnc->ssp.remote_node_port_width = 1; |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 545 | rnc->ssp.logical_port_index = iport->physical_port_index; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 546 | |
| 547 | rnc->ssp.nexus_loss_timer_enable = false; |
| 548 | rnc->ssp.check_bit = false; |
| 549 | rnc->ssp.is_valid = true; |
| 550 | rnc->ssp.is_remote_node_context = true; |
| 551 | rnc->ssp.function_number = 0; |
| 552 | rnc->ssp.arbitration_wait_time = 0; |
| 553 | } |
| 554 | |
Dan Williams | dd047c8 | 2011-06-09 11:06:58 -0700 | [diff] [blame] | 555 | /* |
| 556 | * construct a dummy task context data structure. This |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 557 | * structure will be posted to the hardwre to work around a scheduler error |
| 558 | * in the hardware. |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 559 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 560 | static void sci_port_construct_dummy_task(struct isci_port *iport, u16 tag) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 561 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 562 | struct isci_host *ihost = iport->owning_controller; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 563 | struct scu_task_context *task_context; |
| 564 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 565 | task_context = &ihost->task_context_table[ISCI_TAG_TCI(tag)]; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 566 | memset(task_context, 0, sizeof(struct scu_task_context)); |
| 567 | |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 568 | task_context->initiator_request = 1; |
| 569 | task_context->connection_rate = 1; |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 570 | task_context->logical_port_index = iport->physical_port_index; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 571 | task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SSP; |
Dan Williams | dd047c8 | 2011-06-09 11:06:58 -0700 | [diff] [blame] | 572 | task_context->task_index = ISCI_TAG_TCI(tag); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 573 | task_context->valid = SCU_TASK_CONTEXT_VALID; |
| 574 | task_context->context_type = SCU_TASK_CONTEXT_TYPE; |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 575 | task_context->remote_node_index = iport->reserved_rni; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 576 | task_context->do_not_dma_ssp_good_response = 1; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 577 | task_context->task_phase = 0x01; |
| 578 | } |
| 579 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 580 | static void sci_port_destroy_dummy_resources(struct isci_port *iport) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 581 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 582 | struct isci_host *ihost = iport->owning_controller; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 583 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 584 | if (iport->reserved_tag != SCI_CONTROLLER_INVALID_IO_TAG) |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 585 | isci_free_tag(ihost, iport->reserved_tag); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 586 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 587 | if (iport->reserved_rni != SCU_DUMMY_INDEX) |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 588 | sci_remote_node_table_release_remote_node_index(&ihost->available_remote_nodes, |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 589 | 1, iport->reserved_rni); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 590 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 591 | iport->reserved_rni = SCU_DUMMY_INDEX; |
| 592 | iport->reserved_tag = SCI_CONTROLLER_INVALID_IO_TAG; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 593 | } |
| 594 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 595 | void sci_port_setup_transports(struct isci_port *iport, u32 device_id) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 596 | { |
| 597 | u8 index; |
| 598 | |
| 599 | for (index = 0; index < SCI_MAX_PHYS; index++) { |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 600 | if (iport->active_phy_mask & (1 << index)) |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 601 | sci_phy_setup_transport(iport->phy_table[index], device_id); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 602 | } |
| 603 | } |
| 604 | |
Marcin Tomczak | 05b080f | 2012-01-04 01:33:41 -0800 | [diff] [blame] | 605 | static void sci_port_resume_phy(struct isci_port *iport, struct isci_phy *iphy) |
| 606 | { |
| 607 | sci_phy_resume(iphy); |
| 608 | iport->enabled_phy_mask |= 1 << iphy->phy_index; |
| 609 | } |
| 610 | |
| 611 | static void sci_port_activate_phy(struct isci_port *iport, |
| 612 | struct isci_phy *iphy, |
| 613 | u8 flags) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 614 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 615 | struct isci_host *ihost = iport->owning_controller; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 616 | |
Marcin Tomczak | 05b080f | 2012-01-04 01:33:41 -0800 | [diff] [blame] | 617 | if (iphy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA && (flags & PF_RESUME)) |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 618 | sci_phy_resume(iphy); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 619 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 620 | iport->active_phy_mask |= 1 << iphy->phy_index; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 621 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 622 | sci_controller_clear_invalid_phy(ihost, iphy); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 623 | |
Marcin Tomczak | 05b080f | 2012-01-04 01:33:41 -0800 | [diff] [blame] | 624 | if (flags & PF_NOTIFY) |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 625 | isci_port_link_up(ihost, iport, iphy); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 626 | } |
| 627 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 628 | void sci_port_deactivate_phy(struct isci_port *iport, struct isci_phy *iphy, |
| 629 | bool do_notify_user) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 630 | { |
Dan Williams | 34a9915 | 2011-07-01 02:25:15 -0700 | [diff] [blame] | 631 | struct isci_host *ihost = iport->owning_controller; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 632 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 633 | iport->active_phy_mask &= ~(1 << iphy->phy_index); |
Marcin Tomczak | 05b080f | 2012-01-04 01:33:41 -0800 | [diff] [blame] | 634 | iport->enabled_phy_mask &= ~(1 << iphy->phy_index); |
Jeff Skirvin | 8e35a13 | 2011-10-27 15:05:32 -0700 | [diff] [blame] | 635 | if (!iport->active_phy_mask) |
| 636 | iport->last_active_phy = iphy->phy_index; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 637 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 638 | iphy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 639 | |
Marcin Tomczak | d4ec1cf | 2012-01-04 01:33:15 -0800 | [diff] [blame] | 640 | /* Re-assign the phy back to the LP as if it were a narrow port for APC |
| 641 | * mode. For MPC mode, the phy will remain in the port. |
| 642 | */ |
| 643 | if (iport->owning_controller->oem_parameters.controller.mode_type == |
| 644 | SCIC_PORT_AUTOMATIC_CONFIGURATION_MODE) |
| 645 | writel(iphy->phy_index, |
| 646 | &iport->port_pe_configuration_register[iphy->phy_index]); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 647 | |
| 648 | if (do_notify_user == true) |
| 649 | isci_port_link_down(ihost, iphy, iport); |
| 650 | } |
| 651 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 652 | static void sci_port_invalid_link_up(struct isci_port *iport, struct isci_phy *iphy) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 653 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 654 | struct isci_host *ihost = iport->owning_controller; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 655 | |
| 656 | /* |
| 657 | * Check to see if we have alreay reported this link as bad and if |
| 658 | * not go ahead and tell the SCI_USER that we have discovered an |
| 659 | * invalid link. |
| 660 | */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 661 | if ((ihost->invalid_phy_mask & (1 << iphy->phy_index)) == 0) { |
Dan Williams | 34a9915 | 2011-07-01 02:25:15 -0700 | [diff] [blame] | 662 | ihost->invalid_phy_mask |= 1 << iphy->phy_index; |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 663 | dev_warn(&ihost->pdev->dev, "Invalid link up!\n"); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 664 | } |
| 665 | } |
| 666 | |
| 667 | /** |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 668 | * sci_port_general_link_up_handler - phy can be assigned to port? |
| 669 | * @sci_port: sci_port object for which has a phy that has gone link up. |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 670 | * @sci_phy: This is the struct isci_phy object that has gone link up. |
Marcin Tomczak | 05b080f | 2012-01-04 01:33:41 -0800 | [diff] [blame] | 671 | * @flags: PF_RESUME, PF_NOTIFY to sci_port_activate_phy |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 672 | * |
Marcin Tomczak | 05b080f | 2012-01-04 01:33:41 -0800 | [diff] [blame] | 673 | * Determine if this phy can be assigned to this port . If the phy is |
| 674 | * not a valid PHY for this port then the function will notify the user. |
| 675 | * A PHY can only be part of a port if it's attached SAS ADDRESS is the |
| 676 | * same as all other PHYs in the same port. |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 677 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 678 | static void sci_port_general_link_up_handler(struct isci_port *iport, |
Marcin Tomczak | 05b080f | 2012-01-04 01:33:41 -0800 | [diff] [blame] | 679 | struct isci_phy *iphy, |
| 680 | u8 flags) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 681 | { |
| 682 | struct sci_sas_address port_sas_address; |
| 683 | struct sci_sas_address phy_sas_address; |
| 684 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 685 | sci_port_get_attached_sas_address(iport, &port_sas_address); |
| 686 | sci_phy_get_attached_sas_address(iphy, &phy_sas_address); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 687 | |
| 688 | /* If the SAS address of the new phy matches the SAS address of |
| 689 | * other phys in the port OR this is the first phy in the port, |
| 690 | * then activate the phy and allow it to be used for operations |
| 691 | * in this port. |
| 692 | */ |
| 693 | if ((phy_sas_address.high == port_sas_address.high && |
| 694 | phy_sas_address.low == port_sas_address.low) || |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 695 | iport->active_phy_mask == 0) { |
| 696 | struct sci_base_state_machine *sm = &iport->sm; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 697 | |
Marcin Tomczak | 05b080f | 2012-01-04 01:33:41 -0800 | [diff] [blame] | 698 | sci_port_activate_phy(iport, iphy, flags); |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 699 | if (sm->current_state_id == SCI_PORT_RESETTING) |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 700 | port_state_machine_change(iport, SCI_PORT_READY); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 701 | } else |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 702 | sci_port_invalid_link_up(iport, iphy); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | |
| 706 | |
| 707 | /** |
| 708 | * This method returns false if the port only has a single phy object assigned. |
| 709 | * If there are no phys or more than one phy then the method will return |
| 710 | * true. |
| 711 | * @sci_port: The port for which the wide port condition is to be checked. |
| 712 | * |
| 713 | * bool true Is returned if this is a wide ported port. false Is returned if |
| 714 | * this is a narrow port. |
| 715 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 716 | static bool sci_port_is_wide(struct isci_port *iport) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 717 | { |
| 718 | u32 index; |
| 719 | u32 phy_count = 0; |
| 720 | |
| 721 | for (index = 0; index < SCI_MAX_PHYS; index++) { |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 722 | if (iport->phy_table[index] != NULL) { |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 723 | phy_count++; |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | return phy_count != 1; |
| 728 | } |
| 729 | |
| 730 | /** |
| 731 | * This method is called by the PHY object when the link is detected. if the |
| 732 | * port wants the PHY to continue on to the link up state then the port |
| 733 | * layer must return true. If the port object returns false the phy object |
| 734 | * must halt its attempt to go link up. |
| 735 | * @sci_port: The port associated with the phy object. |
| 736 | * @sci_phy: The phy object that is trying to go link up. |
| 737 | * |
| 738 | * true if the phy object can continue to the link up condition. true Is |
| 739 | * returned if this phy can continue to the ready state. false Is returned if |
| 740 | * can not continue on to the ready state. This notification is in place for |
| 741 | * wide ports and direct attached phys. Since there are no wide ported SATA |
| 742 | * devices this could become an invalid port configuration. |
| 743 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 744 | bool sci_port_link_detected( |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 745 | struct isci_port *iport, |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 746 | struct isci_phy *iphy) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 747 | { |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 748 | if ((iport->logical_port_index != SCIC_SDS_DUMMY_PORT) && |
Marcin Tomczak | 05b080f | 2012-01-04 01:33:41 -0800 | [diff] [blame] | 749 | (iphy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA)) { |
| 750 | if (sci_port_is_wide(iport)) { |
| 751 | sci_port_invalid_link_up(iport, iphy); |
| 752 | return false; |
| 753 | } else { |
| 754 | struct isci_host *ihost = iport->owning_controller; |
| 755 | struct isci_port *dst_port = &(ihost->ports[iphy->phy_index]); |
| 756 | writel(iphy->phy_index, |
| 757 | &dst_port->port_pe_configuration_register[iphy->phy_index]); |
| 758 | } |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | return true; |
| 762 | } |
| 763 | |
Edmund Nadolski | 5553ba2 | 2011-05-19 11:59:10 +0000 | [diff] [blame] | 764 | static void port_timeout(unsigned long data) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 765 | { |
Edmund Nadolski | 5553ba2 | 2011-05-19 11:59:10 +0000 | [diff] [blame] | 766 | struct sci_timer *tmr = (struct sci_timer *)data; |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 767 | struct isci_port *iport = container_of(tmr, typeof(*iport), timer); |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 768 | struct isci_host *ihost = iport->owning_controller; |
Edmund Nadolski | 5553ba2 | 2011-05-19 11:59:10 +0000 | [diff] [blame] | 769 | unsigned long flags; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 770 | u32 current_state; |
| 771 | |
Edmund Nadolski | 5553ba2 | 2011-05-19 11:59:10 +0000 | [diff] [blame] | 772 | spin_lock_irqsave(&ihost->scic_lock, flags); |
| 773 | |
| 774 | if (tmr->cancel) |
| 775 | goto done; |
| 776 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 777 | current_state = iport->sm.current_state_id; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 778 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 779 | if (current_state == SCI_PORT_RESETTING) { |
Piotr Sawicki | e91f41e | 2011-05-11 23:52:21 +0000 | [diff] [blame] | 780 | /* if the port is still in the resetting state then the timeout |
| 781 | * fired before the reset completed. |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 782 | */ |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 783 | port_state_machine_change(iport, SCI_PORT_FAILED); |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 784 | } else if (current_state == SCI_PORT_STOPPED) { |
Piotr Sawicki | e91f41e | 2011-05-11 23:52:21 +0000 | [diff] [blame] | 785 | /* if the port is stopped then the start request failed In this |
| 786 | * case stay in the stopped state. |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 787 | */ |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 788 | dev_err(sciport_to_dev(iport), |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 789 | "%s: SCIC Port 0x%p failed to stop before tiemout.\n", |
| 790 | __func__, |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 791 | iport); |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 792 | } else if (current_state == SCI_PORT_STOPPING) { |
Dan Williams | fca4ecb | 2012-01-03 23:26:15 -0800 | [diff] [blame] | 793 | dev_dbg(sciport_to_dev(iport), |
| 794 | "%s: port%d: stop complete timeout\n", |
| 795 | __func__, iport->physical_port_index); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 796 | } else { |
Piotr Sawicki | e91f41e | 2011-05-11 23:52:21 +0000 | [diff] [blame] | 797 | /* The port is in the ready state and we have a timer |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 798 | * reporting a timeout this should not happen. |
| 799 | */ |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 800 | dev_err(sciport_to_dev(iport), |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 801 | "%s: SCIC Port 0x%p is processing a timeout operation " |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 802 | "in state %d.\n", __func__, iport, current_state); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 803 | } |
Edmund Nadolski | 5553ba2 | 2011-05-19 11:59:10 +0000 | [diff] [blame] | 804 | |
| 805 | done: |
| 806 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | /* --------------------------------------------------------------------------- */ |
| 810 | |
| 811 | /** |
| 812 | * This function updates the hardwares VIIT entry for this port. |
| 813 | * |
| 814 | * |
| 815 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 816 | static void sci_port_update_viit_entry(struct isci_port *iport) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 817 | { |
| 818 | struct sci_sas_address sas_address; |
| 819 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 820 | sci_port_get_sas_address(iport, &sas_address); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 821 | |
| 822 | writel(sas_address.high, |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 823 | &iport->viit_registers->initiator_sas_address_hi); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 824 | writel(sas_address.low, |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 825 | &iport->viit_registers->initiator_sas_address_lo); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 826 | |
| 827 | /* This value get cleared just in case its not already cleared */ |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 828 | writel(0, &iport->viit_registers->reserved); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 829 | |
| 830 | /* We are required to update the status register last */ |
| 831 | writel(SCU_VIIT_ENTRY_ID_VIIT | |
| 832 | SCU_VIIT_IPPT_INITIATOR | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 833 | ((1 << iport->physical_port_index) << SCU_VIIT_ENTRY_LPVIE_SHIFT) | |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 834 | SCU_VIIT_STATUS_ALL_VALID, |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 835 | &iport->viit_registers->status); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 836 | } |
| 837 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 838 | enum sas_linkrate sci_port_get_max_allowed_speed(struct isci_port *iport) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 839 | { |
| 840 | u16 index; |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 841 | struct isci_phy *iphy; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 842 | enum sas_linkrate max_allowed_speed = SAS_LINK_RATE_6_0_GBPS; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 843 | |
| 844 | /* |
| 845 | * Loop through all of the phys in this port and find the phy with the |
| 846 | * lowest maximum link rate. */ |
| 847 | for (index = 0; index < SCI_MAX_PHYS; index++) { |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 848 | iphy = iport->phy_table[index]; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 849 | if (iphy && sci_port_active_phy(iport, iphy) && |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 850 | iphy->max_negotiated_speed < max_allowed_speed) |
| 851 | max_allowed_speed = iphy->max_negotiated_speed; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | return max_allowed_speed; |
| 855 | } |
| 856 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 857 | static void sci_port_suspend_port_task_scheduler(struct isci_port *iport) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 858 | { |
| 859 | u32 pts_control_value; |
| 860 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 861 | pts_control_value = readl(&iport->port_task_scheduler_registers->control); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 862 | pts_control_value |= SCU_PTSxCR_GEN_BIT(SUSPEND); |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 863 | writel(pts_control_value, &iport->port_task_scheduler_registers->control); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | /** |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 867 | * sci_port_post_dummy_request() - post dummy/workaround request |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 868 | * @sci_port: port to post task |
| 869 | * |
| 870 | * Prevent the hardware scheduler from posting new requests to the front |
| 871 | * of the scheduler queue causing a starvation problem for currently |
| 872 | * ongoing requests. |
| 873 | * |
| 874 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 875 | static void sci_port_post_dummy_request(struct isci_port *iport) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 876 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 877 | struct isci_host *ihost = iport->owning_controller; |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 878 | u16 tag = iport->reserved_tag; |
Dan Williams | 312e0c2 | 2011-06-28 13:47:09 -0700 | [diff] [blame] | 879 | struct scu_task_context *tc; |
| 880 | u32 command; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 881 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 882 | tc = &ihost->task_context_table[ISCI_TAG_TCI(tag)]; |
Dan Williams | 312e0c2 | 2011-06-28 13:47:09 -0700 | [diff] [blame] | 883 | tc->abort = 0; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 884 | |
| 885 | command = SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 886 | iport->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | |
Dan Williams | 312e0c2 | 2011-06-28 13:47:09 -0700 | [diff] [blame] | 887 | ISCI_TAG_TCI(tag); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 888 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 889 | sci_controller_post_request(ihost, command); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 890 | } |
| 891 | |
| 892 | /** |
| 893 | * This routine will abort the dummy request. This will alow the hardware to |
| 894 | * power down parts of the silicon to save power. |
| 895 | * |
| 896 | * @sci_port: The port on which the task must be aborted. |
| 897 | * |
| 898 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 899 | static void sci_port_abort_dummy_request(struct isci_port *iport) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 900 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 901 | struct isci_host *ihost = iport->owning_controller; |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 902 | u16 tag = iport->reserved_tag; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 903 | struct scu_task_context *tc; |
| 904 | u32 command; |
| 905 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 906 | tc = &ihost->task_context_table[ISCI_TAG_TCI(tag)]; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 907 | tc->abort = 1; |
| 908 | |
| 909 | command = SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 910 | iport->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | |
Dan Williams | 312e0c2 | 2011-06-28 13:47:09 -0700 | [diff] [blame] | 911 | ISCI_TAG_TCI(tag); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 912 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 913 | sci_controller_post_request(ihost, command); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | /** |
| 917 | * |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 918 | * @sci_port: This is the struct isci_port object to resume. |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 919 | * |
| 920 | * This method will resume the port task scheduler for this port object. none |
| 921 | */ |
| 922 | static void |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 923 | sci_port_resume_port_task_scheduler(struct isci_port *iport) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 924 | { |
| 925 | u32 pts_control_value; |
| 926 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 927 | pts_control_value = readl(&iport->port_task_scheduler_registers->control); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 928 | pts_control_value &= ~SCU_PTSxCR_GEN_BIT(SUSPEND); |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 929 | writel(pts_control_value, &iport->port_task_scheduler_registers->control); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 930 | } |
| 931 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 932 | static void sci_port_ready_substate_waiting_enter(struct sci_base_state_machine *sm) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 933 | { |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 934 | struct isci_port *iport = container_of(sm, typeof(*iport), sm); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 935 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 936 | sci_port_suspend_port_task_scheduler(iport); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 937 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 938 | iport->not_ready_reason = SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 939 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 940 | if (iport->active_phy_mask != 0) { |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 941 | /* At least one of the phys on the port is ready */ |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 942 | port_state_machine_change(iport, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 943 | SCI_PORT_SUB_OPERATIONAL); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 944 | } |
| 945 | } |
| 946 | |
Marcin Tomczak | 05b080f | 2012-01-04 01:33:41 -0800 | [diff] [blame] | 947 | static void scic_sds_port_ready_substate_waiting_exit( |
| 948 | struct sci_base_state_machine *sm) |
| 949 | { |
| 950 | struct isci_port *iport = container_of(sm, typeof(*iport), sm); |
| 951 | sci_port_resume_port_task_scheduler(iport); |
| 952 | } |
| 953 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 954 | static void sci_port_ready_substate_operational_enter(struct sci_base_state_machine *sm) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 955 | { |
| 956 | u32 index; |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 957 | struct isci_port *iport = container_of(sm, typeof(*iport), sm); |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 958 | struct isci_host *ihost = iport->owning_controller; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 959 | |
Dan Williams | fca4ecb | 2012-01-03 23:26:15 -0800 | [diff] [blame] | 960 | dev_dbg(&ihost->pdev->dev, "%s: port%d ready\n", |
| 961 | __func__, iport->physical_port_index); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 962 | |
| 963 | for (index = 0; index < SCI_MAX_PHYS; index++) { |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 964 | if (iport->phy_table[index]) { |
| 965 | writel(iport->physical_port_index, |
| 966 | &iport->port_pe_configuration_register[ |
| 967 | iport->phy_table[index]->phy_index]); |
Marcin Tomczak | 05b080f | 2012-01-04 01:33:41 -0800 | [diff] [blame] | 968 | if (((iport->active_phy_mask^iport->enabled_phy_mask) & (1 << index)) != 0) |
| 969 | sci_port_resume_phy(iport, iport->phy_table[index]); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 970 | } |
| 971 | } |
| 972 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 973 | sci_port_update_viit_entry(iport); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 974 | |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 975 | /* |
| 976 | * Post the dummy task for the port so the hardware can schedule |
| 977 | * io correctly |
| 978 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 979 | sci_port_post_dummy_request(iport); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 980 | } |
| 981 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 982 | static void sci_port_invalidate_dummy_remote_node(struct isci_port *iport) |
Piotr Sawicki | e91f41e | 2011-05-11 23:52:21 +0000 | [diff] [blame] | 983 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 984 | struct isci_host *ihost = iport->owning_controller; |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 985 | u8 phys_index = iport->physical_port_index; |
Piotr Sawicki | e91f41e | 2011-05-11 23:52:21 +0000 | [diff] [blame] | 986 | union scu_remote_node_context *rnc; |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 987 | u16 rni = iport->reserved_rni; |
Piotr Sawicki | e91f41e | 2011-05-11 23:52:21 +0000 | [diff] [blame] | 988 | u32 command; |
| 989 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 990 | rnc = &ihost->remote_node_context_table[rni]; |
Piotr Sawicki | e91f41e | 2011-05-11 23:52:21 +0000 | [diff] [blame] | 991 | |
| 992 | rnc->ssp.is_valid = false; |
| 993 | |
| 994 | /* ensure the preceding tc abort request has reached the |
| 995 | * controller and give it ample time to act before posting the rnc |
| 996 | * invalidate |
| 997 | */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 998 | readl(&ihost->smu_registers->interrupt_status); /* flush */ |
Piotr Sawicki | e91f41e | 2011-05-11 23:52:21 +0000 | [diff] [blame] | 999 | udelay(10); |
| 1000 | |
| 1001 | command = SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE | |
| 1002 | phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni; |
| 1003 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1004 | sci_controller_post_request(ihost, command); |
Piotr Sawicki | e91f41e | 2011-05-11 23:52:21 +0000 | [diff] [blame] | 1005 | } |
| 1006 | |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1007 | /** |
| 1008 | * |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1009 | * @object: This is the object which is cast to a struct isci_port object. |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1010 | * |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1011 | * This method will perform the actions required by the struct isci_port on |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1012 | * exiting the SCI_PORT_SUB_OPERATIONAL. This function reports |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1013 | * the port not ready and suspends the port task scheduler. none |
| 1014 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1015 | static void sci_port_ready_substate_operational_exit(struct sci_base_state_machine *sm) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1016 | { |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1017 | struct isci_port *iport = container_of(sm, typeof(*iport), sm); |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1018 | struct isci_host *ihost = iport->owning_controller; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1019 | |
| 1020 | /* |
| 1021 | * Kill the dummy task for this port if it has not yet posted |
| 1022 | * the hardware will treat this as a NOP and just return abort |
| 1023 | * complete. |
| 1024 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1025 | sci_port_abort_dummy_request(iport); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1026 | |
Dan Williams | fca4ecb | 2012-01-03 23:26:15 -0800 | [diff] [blame] | 1027 | dev_dbg(&ihost->pdev->dev, "%s: port%d !ready\n", |
| 1028 | __func__, iport->physical_port_index); |
Piotr Sawicki | e91f41e | 2011-05-11 23:52:21 +0000 | [diff] [blame] | 1029 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1030 | if (iport->ready_exit) |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1031 | sci_port_invalidate_dummy_remote_node(iport); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1032 | } |
| 1033 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1034 | static void sci_port_ready_substate_configuring_enter(struct sci_base_state_machine *sm) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1035 | { |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1036 | struct isci_port *iport = container_of(sm, typeof(*iport), sm); |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1037 | struct isci_host *ihost = iport->owning_controller; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1038 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1039 | if (iport->active_phy_mask == 0) { |
Dan Williams | fca4ecb | 2012-01-03 23:26:15 -0800 | [diff] [blame] | 1040 | dev_dbg(&ihost->pdev->dev, "%s: port%d !ready\n", |
| 1041 | __func__, iport->physical_port_index); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1042 | |
Marcin Tomczak | 05b080f | 2012-01-04 01:33:41 -0800 | [diff] [blame] | 1043 | port_state_machine_change(iport, SCI_PORT_SUB_WAITING); |
| 1044 | } else |
| 1045 | port_state_machine_change(iport, SCI_PORT_SUB_OPERATIONAL); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1048 | enum sci_status sci_port_start(struct isci_port *iport) |
Piotr Sawicki | d76f71d | 2011-05-11 23:52:26 +0000 | [diff] [blame] | 1049 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1050 | struct isci_host *ihost = iport->owning_controller; |
Piotr Sawicki | d76f71d | 2011-05-11 23:52:26 +0000 | [diff] [blame] | 1051 | enum sci_status status = SCI_SUCCESS; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1052 | enum sci_port_states state; |
Piotr Sawicki | d76f71d | 2011-05-11 23:52:26 +0000 | [diff] [blame] | 1053 | u32 phy_mask; |
| 1054 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1055 | state = iport->sm.current_state_id; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1056 | if (state != SCI_PORT_STOPPED) { |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1057 | dev_warn(sciport_to_dev(iport), |
Piotr Sawicki | d76f71d | 2011-05-11 23:52:26 +0000 | [diff] [blame] | 1058 | "%s: in wrong state: %d\n", __func__, state); |
| 1059 | return SCI_FAILURE_INVALID_STATE; |
| 1060 | } |
| 1061 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1062 | if (iport->assigned_device_count > 0) { |
Piotr Sawicki | d76f71d | 2011-05-11 23:52:26 +0000 | [diff] [blame] | 1063 | /* TODO This is a start failure operation because |
| 1064 | * there are still devices assigned to this port. |
| 1065 | * There must be no devices assigned to a port on a |
| 1066 | * start operation. |
| 1067 | */ |
| 1068 | return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION; |
| 1069 | } |
| 1070 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1071 | if (iport->reserved_rni == SCU_DUMMY_INDEX) { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1072 | u16 rni = sci_remote_node_table_allocate_remote_node( |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1073 | &ihost->available_remote_nodes, 1); |
Piotr Sawicki | d76f71d | 2011-05-11 23:52:26 +0000 | [diff] [blame] | 1074 | |
| 1075 | if (rni != SCU_DUMMY_INDEX) |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1076 | sci_port_construct_dummy_rnc(iport, rni); |
Piotr Sawicki | d76f71d | 2011-05-11 23:52:26 +0000 | [diff] [blame] | 1077 | else |
| 1078 | status = SCI_FAILURE_INSUFFICIENT_RESOURCES; |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1079 | iport->reserved_rni = rni; |
Piotr Sawicki | d76f71d | 2011-05-11 23:52:26 +0000 | [diff] [blame] | 1080 | } |
| 1081 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1082 | if (iport->reserved_tag == SCI_CONTROLLER_INVALID_IO_TAG) { |
Dan Williams | 312e0c2 | 2011-06-28 13:47:09 -0700 | [diff] [blame] | 1083 | u16 tag; |
Piotr Sawicki | d76f71d | 2011-05-11 23:52:26 +0000 | [diff] [blame] | 1084 | |
Dan Williams | 312e0c2 | 2011-06-28 13:47:09 -0700 | [diff] [blame] | 1085 | tag = isci_alloc_tag(ihost); |
| 1086 | if (tag == SCI_CONTROLLER_INVALID_IO_TAG) |
Piotr Sawicki | d76f71d | 2011-05-11 23:52:26 +0000 | [diff] [blame] | 1087 | status = SCI_FAILURE_INSUFFICIENT_RESOURCES; |
Dan Williams | 312e0c2 | 2011-06-28 13:47:09 -0700 | [diff] [blame] | 1088 | else |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1089 | sci_port_construct_dummy_task(iport, tag); |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1090 | iport->reserved_tag = tag; |
Piotr Sawicki | d76f71d | 2011-05-11 23:52:26 +0000 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | if (status == SCI_SUCCESS) { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1094 | phy_mask = sci_port_get_phys(iport); |
Piotr Sawicki | d76f71d | 2011-05-11 23:52:26 +0000 | [diff] [blame] | 1095 | |
| 1096 | /* |
| 1097 | * There are one or more phys assigned to this port. Make sure |
| 1098 | * the port's phy mask is in fact legal and supported by the |
| 1099 | * silicon. |
| 1100 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1101 | if (sci_port_is_phy_mask_valid(iport, phy_mask) == true) { |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1102 | port_state_machine_change(iport, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1103 | SCI_PORT_READY); |
Piotr Sawicki | d76f71d | 2011-05-11 23:52:26 +0000 | [diff] [blame] | 1104 | |
| 1105 | return SCI_SUCCESS; |
| 1106 | } |
| 1107 | status = SCI_FAILURE; |
| 1108 | } |
| 1109 | |
| 1110 | if (status != SCI_SUCCESS) |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1111 | sci_port_destroy_dummy_resources(iport); |
Piotr Sawicki | d76f71d | 2011-05-11 23:52:26 +0000 | [diff] [blame] | 1112 | |
| 1113 | return status; |
| 1114 | } |
| 1115 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1116 | enum sci_status sci_port_stop(struct isci_port *iport) |
Piotr Sawicki | 8bc80d3 | 2011-05-11 23:52:31 +0000 | [diff] [blame] | 1117 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1118 | enum sci_port_states state; |
Piotr Sawicki | 8bc80d3 | 2011-05-11 23:52:31 +0000 | [diff] [blame] | 1119 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1120 | state = iport->sm.current_state_id; |
Piotr Sawicki | 8bc80d3 | 2011-05-11 23:52:31 +0000 | [diff] [blame] | 1121 | switch (state) { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1122 | case SCI_PORT_STOPPED: |
Piotr Sawicki | 8bc80d3 | 2011-05-11 23:52:31 +0000 | [diff] [blame] | 1123 | return SCI_SUCCESS; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1124 | case SCI_PORT_SUB_WAITING: |
| 1125 | case SCI_PORT_SUB_OPERATIONAL: |
| 1126 | case SCI_PORT_SUB_CONFIGURING: |
| 1127 | case SCI_PORT_RESETTING: |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1128 | port_state_machine_change(iport, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1129 | SCI_PORT_STOPPING); |
Piotr Sawicki | 8bc80d3 | 2011-05-11 23:52:31 +0000 | [diff] [blame] | 1130 | return SCI_SUCCESS; |
| 1131 | default: |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1132 | dev_warn(sciport_to_dev(iport), |
Piotr Sawicki | 8bc80d3 | 2011-05-11 23:52:31 +0000 | [diff] [blame] | 1133 | "%s: in wrong state: %d\n", __func__, state); |
| 1134 | return SCI_FAILURE_INVALID_STATE; |
| 1135 | } |
| 1136 | } |
| 1137 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1138 | static enum sci_status sci_port_hard_reset(struct isci_port *iport, u32 timeout) |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1139 | { |
| 1140 | enum sci_status status = SCI_FAILURE_INVALID_PHY; |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1141 | struct isci_phy *iphy = NULL; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1142 | enum sci_port_states state; |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1143 | u32 phy_index; |
| 1144 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1145 | state = iport->sm.current_state_id; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1146 | if (state != SCI_PORT_SUB_OPERATIONAL) { |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1147 | dev_warn(sciport_to_dev(iport), |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1148 | "%s: in wrong state: %d\n", __func__, state); |
| 1149 | return SCI_FAILURE_INVALID_STATE; |
| 1150 | } |
| 1151 | |
| 1152 | /* Select a phy on which we can send the hard reset request. */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1153 | for (phy_index = 0; phy_index < SCI_MAX_PHYS && !iphy; phy_index++) { |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1154 | iphy = iport->phy_table[phy_index]; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1155 | if (iphy && !sci_port_active_phy(iport, iphy)) { |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1156 | /* |
| 1157 | * We found a phy but it is not ready select |
| 1158 | * different phy |
| 1159 | */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1160 | iphy = NULL; |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1161 | } |
| 1162 | } |
| 1163 | |
| 1164 | /* If we have a phy then go ahead and start the reset procedure */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1165 | if (!iphy) |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1166 | return status; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1167 | status = sci_phy_reset(iphy); |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1168 | |
| 1169 | if (status != SCI_SUCCESS) |
| 1170 | return status; |
| 1171 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1172 | sci_mod_timer(&iport->timer, timeout); |
| 1173 | iport->not_ready_reason = SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED; |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1174 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1175 | port_state_machine_change(iport, SCI_PORT_RESETTING); |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1176 | return SCI_SUCCESS; |
| 1177 | } |
| 1178 | |
| 1179 | /** |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1180 | * sci_port_add_phy() - |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1181 | * @sci_port: This parameter specifies the port in which the phy will be added. |
| 1182 | * @sci_phy: This parameter is the phy which is to be added to the port. |
| 1183 | * |
| 1184 | * This method will add a PHY to the selected port. This method returns an |
| 1185 | * enum sci_status. SCI_SUCCESS the phy has been added to the port. Any other |
| 1186 | * status is a failure to add the phy to the port. |
| 1187 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1188 | enum sci_status sci_port_add_phy(struct isci_port *iport, |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1189 | struct isci_phy *iphy) |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1190 | { |
| 1191 | enum sci_status status; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1192 | enum sci_port_states state; |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1193 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1194 | state = iport->sm.current_state_id; |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1195 | switch (state) { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1196 | case SCI_PORT_STOPPED: { |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1197 | struct sci_sas_address port_sas_address; |
| 1198 | |
| 1199 | /* Read the port assigned SAS Address if there is one */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1200 | sci_port_get_sas_address(iport, &port_sas_address); |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1201 | |
| 1202 | if (port_sas_address.high != 0 && port_sas_address.low != 0) { |
| 1203 | struct sci_sas_address phy_sas_address; |
| 1204 | |
| 1205 | /* Make sure that the PHY SAS Address matches the SAS Address |
| 1206 | * for this port |
| 1207 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1208 | sci_phy_get_sas_address(iphy, &phy_sas_address); |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1209 | |
| 1210 | if (port_sas_address.high != phy_sas_address.high || |
| 1211 | port_sas_address.low != phy_sas_address.low) |
| 1212 | return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION; |
| 1213 | } |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1214 | return sci_port_set_phy(iport, iphy); |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1215 | } |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1216 | case SCI_PORT_SUB_WAITING: |
| 1217 | case SCI_PORT_SUB_OPERATIONAL: |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1218 | status = sci_port_set_phy(iport, iphy); |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1219 | |
| 1220 | if (status != SCI_SUCCESS) |
| 1221 | return status; |
| 1222 | |
Marcin Tomczak | 05b080f | 2012-01-04 01:33:41 -0800 | [diff] [blame] | 1223 | sci_port_general_link_up_handler(iport, iphy, PF_NOTIFY|PF_RESUME); |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1224 | iport->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING; |
| 1225 | port_state_machine_change(iport, SCI_PORT_SUB_CONFIGURING); |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1226 | |
| 1227 | return status; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1228 | case SCI_PORT_SUB_CONFIGURING: |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1229 | status = sci_port_set_phy(iport, iphy); |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1230 | |
| 1231 | if (status != SCI_SUCCESS) |
| 1232 | return status; |
Marcin Tomczak | 05b080f | 2012-01-04 01:33:41 -0800 | [diff] [blame] | 1233 | sci_port_general_link_up_handler(iport, iphy, PF_NOTIFY); |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1234 | |
| 1235 | /* Re-enter the configuring state since this may be the last phy in |
| 1236 | * the port. |
| 1237 | */ |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1238 | port_state_machine_change(iport, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1239 | SCI_PORT_SUB_CONFIGURING); |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1240 | return SCI_SUCCESS; |
| 1241 | default: |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1242 | dev_warn(sciport_to_dev(iport), |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1243 | "%s: in wrong state: %d\n", __func__, state); |
| 1244 | return SCI_FAILURE_INVALID_STATE; |
| 1245 | } |
| 1246 | } |
| 1247 | |
| 1248 | /** |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1249 | * sci_port_remove_phy() - |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1250 | * @sci_port: This parameter specifies the port in which the phy will be added. |
| 1251 | * @sci_phy: This parameter is the phy which is to be added to the port. |
| 1252 | * |
| 1253 | * This method will remove the PHY from the selected PORT. This method returns |
| 1254 | * an enum sci_status. SCI_SUCCESS the phy has been removed from the port. Any |
| 1255 | * other status is a failure to add the phy to the port. |
| 1256 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1257 | enum sci_status sci_port_remove_phy(struct isci_port *iport, |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1258 | struct isci_phy *iphy) |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1259 | { |
| 1260 | enum sci_status status; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1261 | enum sci_port_states state; |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1262 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1263 | state = iport->sm.current_state_id; |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1264 | |
| 1265 | switch (state) { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1266 | case SCI_PORT_STOPPED: |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1267 | return sci_port_clear_phy(iport, iphy); |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1268 | case SCI_PORT_SUB_OPERATIONAL: |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1269 | status = sci_port_clear_phy(iport, iphy); |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1270 | if (status != SCI_SUCCESS) |
| 1271 | return status; |
| 1272 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1273 | sci_port_deactivate_phy(iport, iphy, true); |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1274 | iport->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING; |
| 1275 | port_state_machine_change(iport, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1276 | SCI_PORT_SUB_CONFIGURING); |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1277 | return SCI_SUCCESS; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1278 | case SCI_PORT_SUB_CONFIGURING: |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1279 | status = sci_port_clear_phy(iport, iphy); |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1280 | |
| 1281 | if (status != SCI_SUCCESS) |
| 1282 | return status; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1283 | sci_port_deactivate_phy(iport, iphy, true); |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1284 | |
| 1285 | /* Re-enter the configuring state since this may be the last phy in |
| 1286 | * the port |
| 1287 | */ |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1288 | port_state_machine_change(iport, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1289 | SCI_PORT_SUB_CONFIGURING); |
Piotr Sawicki | 051266c | 2011-05-12 19:10:14 +0000 | [diff] [blame] | 1290 | return SCI_SUCCESS; |
| 1291 | default: |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1292 | dev_warn(sciport_to_dev(iport), |
Piotr Sawicki | 051266c | 2011-05-12 19:10:14 +0000 | [diff] [blame] | 1293 | "%s: in wrong state: %d\n", __func__, state); |
| 1294 | return SCI_FAILURE_INVALID_STATE; |
| 1295 | } |
| 1296 | } |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1297 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1298 | enum sci_status sci_port_link_up(struct isci_port *iport, |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1299 | struct isci_phy *iphy) |
Piotr Sawicki | 051266c | 2011-05-12 19:10:14 +0000 | [diff] [blame] | 1300 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1301 | enum sci_port_states state; |
Piotr Sawicki | 051266c | 2011-05-12 19:10:14 +0000 | [diff] [blame] | 1302 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1303 | state = iport->sm.current_state_id; |
Piotr Sawicki | 051266c | 2011-05-12 19:10:14 +0000 | [diff] [blame] | 1304 | switch (state) { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1305 | case SCI_PORT_SUB_WAITING: |
Piotr Sawicki | 051266c | 2011-05-12 19:10:14 +0000 | [diff] [blame] | 1306 | /* Since this is the first phy going link up for the port we |
| 1307 | * can just enable it and continue |
| 1308 | */ |
Marcin Tomczak | 05b080f | 2012-01-04 01:33:41 -0800 | [diff] [blame] | 1309 | sci_port_activate_phy(iport, iphy, PF_NOTIFY|PF_RESUME); |
Piotr Sawicki | 051266c | 2011-05-12 19:10:14 +0000 | [diff] [blame] | 1310 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1311 | port_state_machine_change(iport, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1312 | SCI_PORT_SUB_OPERATIONAL); |
Piotr Sawicki | 051266c | 2011-05-12 19:10:14 +0000 | [diff] [blame] | 1313 | return SCI_SUCCESS; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1314 | case SCI_PORT_SUB_OPERATIONAL: |
Marcin Tomczak | 05b080f | 2012-01-04 01:33:41 -0800 | [diff] [blame] | 1315 | sci_port_general_link_up_handler(iport, iphy, PF_NOTIFY|PF_RESUME); |
Piotr Sawicki | 051266c | 2011-05-12 19:10:14 +0000 | [diff] [blame] | 1316 | return SCI_SUCCESS; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1317 | case SCI_PORT_RESETTING: |
Piotr Sawicki | 051266c | 2011-05-12 19:10:14 +0000 | [diff] [blame] | 1318 | /* TODO We should make sure that the phy that has gone |
| 1319 | * link up is the same one on which we sent the reset. It is |
| 1320 | * possible that the phy on which we sent the reset is not the |
| 1321 | * one that has gone link up and we want to make sure that |
| 1322 | * phy being reset comes back. Consider the case where a |
| 1323 | * reset is sent but before the hardware processes the reset it |
| 1324 | * get a link up on the port because of a hot plug event. |
| 1325 | * because of the reset request this phy will go link down |
| 1326 | * almost immediately. |
| 1327 | */ |
| 1328 | |
| 1329 | /* In the resetting state we don't notify the user regarding |
| 1330 | * link up and link down notifications. |
| 1331 | */ |
Marcin Tomczak | 05b080f | 2012-01-04 01:33:41 -0800 | [diff] [blame] | 1332 | sci_port_general_link_up_handler(iport, iphy, PF_RESUME); |
Piotr Sawicki | 051266c | 2011-05-12 19:10:14 +0000 | [diff] [blame] | 1333 | return SCI_SUCCESS; |
| 1334 | default: |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1335 | dev_warn(sciport_to_dev(iport), |
Piotr Sawicki | 051266c | 2011-05-12 19:10:14 +0000 | [diff] [blame] | 1336 | "%s: in wrong state: %d\n", __func__, state); |
| 1337 | return SCI_FAILURE_INVALID_STATE; |
| 1338 | } |
| 1339 | } |
| 1340 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1341 | enum sci_status sci_port_link_down(struct isci_port *iport, |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1342 | struct isci_phy *iphy) |
Piotr Sawicki | 051266c | 2011-05-12 19:10:14 +0000 | [diff] [blame] | 1343 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1344 | enum sci_port_states state; |
Piotr Sawicki | 051266c | 2011-05-12 19:10:14 +0000 | [diff] [blame] | 1345 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1346 | state = iport->sm.current_state_id; |
Piotr Sawicki | 051266c | 2011-05-12 19:10:14 +0000 | [diff] [blame] | 1347 | switch (state) { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1348 | case SCI_PORT_SUB_OPERATIONAL: |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1349 | sci_port_deactivate_phy(iport, iphy, true); |
Piotr Sawicki | 051266c | 2011-05-12 19:10:14 +0000 | [diff] [blame] | 1350 | |
| 1351 | /* If there are no active phys left in the port, then |
| 1352 | * transition the port to the WAITING state until such time |
| 1353 | * as a phy goes link up |
| 1354 | */ |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1355 | if (iport->active_phy_mask == 0) |
| 1356 | port_state_machine_change(iport, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1357 | SCI_PORT_SUB_WAITING); |
Piotr Sawicki | 051266c | 2011-05-12 19:10:14 +0000 | [diff] [blame] | 1358 | return SCI_SUCCESS; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1359 | case SCI_PORT_RESETTING: |
Piotr Sawicki | 051266c | 2011-05-12 19:10:14 +0000 | [diff] [blame] | 1360 | /* In the resetting state we don't notify the user regarding |
| 1361 | * link up and link down notifications. */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1362 | sci_port_deactivate_phy(iport, iphy, false); |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1363 | return SCI_SUCCESS; |
| 1364 | default: |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1365 | dev_warn(sciport_to_dev(iport), |
Piotr Sawicki | bd6713b | 2011-05-12 19:10:03 +0000 | [diff] [blame] | 1366 | "%s: in wrong state: %d\n", __func__, state); |
| 1367 | return SCI_FAILURE_INVALID_STATE; |
| 1368 | } |
| 1369 | } |
| 1370 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1371 | enum sci_status sci_port_start_io(struct isci_port *iport, |
| 1372 | struct isci_remote_device *idev, |
| 1373 | struct isci_request *ireq) |
Dan Williams | 6813820 | 2011-05-12 07:16:06 -0700 | [diff] [blame] | 1374 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1375 | enum sci_port_states state; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1376 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1377 | state = iport->sm.current_state_id; |
Dan Williams | 6813820 | 2011-05-12 07:16:06 -0700 | [diff] [blame] | 1378 | switch (state) { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1379 | case SCI_PORT_SUB_WAITING: |
Dan Williams | 6813820 | 2011-05-12 07:16:06 -0700 | [diff] [blame] | 1380 | return SCI_FAILURE_INVALID_STATE; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1381 | case SCI_PORT_SUB_OPERATIONAL: |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1382 | iport->started_request_count++; |
Dan Williams | 6813820 | 2011-05-12 07:16:06 -0700 | [diff] [blame] | 1383 | return SCI_SUCCESS; |
| 1384 | default: |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1385 | dev_warn(sciport_to_dev(iport), |
Dan Williams | 6813820 | 2011-05-12 07:16:06 -0700 | [diff] [blame] | 1386 | "%s: in wrong state: %d\n", __func__, state); |
| 1387 | return SCI_FAILURE_INVALID_STATE; |
| 1388 | } |
| 1389 | } |
| 1390 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1391 | enum sci_status sci_port_complete_io(struct isci_port *iport, |
| 1392 | struct isci_remote_device *idev, |
| 1393 | struct isci_request *ireq) |
Dan Williams | 6813820 | 2011-05-12 07:16:06 -0700 | [diff] [blame] | 1394 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1395 | enum sci_port_states state; |
Dan Williams | 6813820 | 2011-05-12 07:16:06 -0700 | [diff] [blame] | 1396 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1397 | state = iport->sm.current_state_id; |
Dan Williams | 6813820 | 2011-05-12 07:16:06 -0700 | [diff] [blame] | 1398 | switch (state) { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1399 | case SCI_PORT_STOPPED: |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1400 | dev_warn(sciport_to_dev(iport), |
Dan Williams | 6813820 | 2011-05-12 07:16:06 -0700 | [diff] [blame] | 1401 | "%s: in wrong state: %d\n", __func__, state); |
| 1402 | return SCI_FAILURE_INVALID_STATE; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1403 | case SCI_PORT_STOPPING: |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1404 | sci_port_decrement_request_count(iport); |
Dan Williams | 6813820 | 2011-05-12 07:16:06 -0700 | [diff] [blame] | 1405 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1406 | if (iport->started_request_count == 0) |
| 1407 | port_state_machine_change(iport, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1408 | SCI_PORT_STOPPED); |
Dan Williams | 6813820 | 2011-05-12 07:16:06 -0700 | [diff] [blame] | 1409 | break; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1410 | case SCI_PORT_READY: |
| 1411 | case SCI_PORT_RESETTING: |
| 1412 | case SCI_PORT_FAILED: |
| 1413 | case SCI_PORT_SUB_WAITING: |
| 1414 | case SCI_PORT_SUB_OPERATIONAL: |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1415 | sci_port_decrement_request_count(iport); |
Dan Williams | 6813820 | 2011-05-12 07:16:06 -0700 | [diff] [blame] | 1416 | break; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1417 | case SCI_PORT_SUB_CONFIGURING: |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1418 | sci_port_decrement_request_count(iport); |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1419 | if (iport->started_request_count == 0) { |
| 1420 | port_state_machine_change(iport, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1421 | SCI_PORT_SUB_OPERATIONAL); |
Dan Williams | 6813820 | 2011-05-12 07:16:06 -0700 | [diff] [blame] | 1422 | } |
| 1423 | break; |
| 1424 | } |
| 1425 | return SCI_SUCCESS; |
| 1426 | } |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1427 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1428 | static void sci_port_enable_port_task_scheduler(struct isci_port *iport) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1429 | { |
| 1430 | u32 pts_control_value; |
| 1431 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1432 | /* enable the port task scheduler in a suspended state */ |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1433 | pts_control_value = readl(&iport->port_task_scheduler_registers->control); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1434 | pts_control_value |= SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND); |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1435 | writel(pts_control_value, &iport->port_task_scheduler_registers->control); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1436 | } |
| 1437 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1438 | static void sci_port_disable_port_task_scheduler(struct isci_port *iport) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1439 | { |
| 1440 | u32 pts_control_value; |
| 1441 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1442 | pts_control_value = readl(&iport->port_task_scheduler_registers->control); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1443 | pts_control_value &= |
| 1444 | ~(SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND)); |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1445 | writel(pts_control_value, &iport->port_task_scheduler_registers->control); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1446 | } |
| 1447 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1448 | static void sci_port_post_dummy_remote_node(struct isci_port *iport) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1449 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1450 | struct isci_host *ihost = iport->owning_controller; |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1451 | u8 phys_index = iport->physical_port_index; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1452 | union scu_remote_node_context *rnc; |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1453 | u16 rni = iport->reserved_rni; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1454 | u32 command; |
| 1455 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1456 | rnc = &ihost->remote_node_context_table[rni]; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1457 | rnc->ssp.is_valid = true; |
| 1458 | |
| 1459 | command = SCU_CONTEXT_COMMAND_POST_RNC_32 | |
| 1460 | phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni; |
| 1461 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1462 | sci_controller_post_request(ihost, command); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1463 | |
| 1464 | /* ensure hardware has seen the post rnc command and give it |
| 1465 | * ample time to act before sending the suspend |
| 1466 | */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1467 | readl(&ihost->smu_registers->interrupt_status); /* flush */ |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1468 | udelay(10); |
| 1469 | |
| 1470 | command = SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX | |
| 1471 | phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni; |
| 1472 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1473 | sci_controller_post_request(ihost, command); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1474 | } |
| 1475 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1476 | static void sci_port_stopped_state_enter(struct sci_base_state_machine *sm) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1477 | { |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1478 | struct isci_port *iport = container_of(sm, typeof(*iport), sm); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1479 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1480 | if (iport->sm.previous_state_id == SCI_PORT_STOPPING) { |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1481 | /* |
| 1482 | * If we enter this state becasuse of a request to stop |
| 1483 | * the port then we want to disable the hardwares port |
| 1484 | * task scheduler. */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1485 | sci_port_disable_port_task_scheduler(iport); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1486 | } |
| 1487 | } |
| 1488 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1489 | static void sci_port_stopped_state_exit(struct sci_base_state_machine *sm) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1490 | { |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1491 | struct isci_port *iport = container_of(sm, typeof(*iport), sm); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1492 | |
| 1493 | /* Enable and suspend the port task scheduler */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1494 | sci_port_enable_port_task_scheduler(iport); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1495 | } |
| 1496 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1497 | static void sci_port_ready_state_enter(struct sci_base_state_machine *sm) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1498 | { |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1499 | struct isci_port *iport = container_of(sm, typeof(*iport), sm); |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1500 | struct isci_host *ihost = iport->owning_controller; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1501 | u32 prev_state; |
| 1502 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1503 | prev_state = iport->sm.previous_state_id; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1504 | if (prev_state == SCI_PORT_RESETTING) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1505 | isci_port_hard_reset_complete(iport, SCI_SUCCESS); |
| 1506 | else |
Dan Williams | fca4ecb | 2012-01-03 23:26:15 -0800 | [diff] [blame] | 1507 | dev_dbg(&ihost->pdev->dev, "%s: port%d !ready\n", |
| 1508 | __func__, iport->physical_port_index); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1509 | |
| 1510 | /* Post and suspend the dummy remote node context for this port. */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1511 | sci_port_post_dummy_remote_node(iport); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1512 | |
| 1513 | /* Start the ready substate machine */ |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1514 | port_state_machine_change(iport, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1515 | SCI_PORT_SUB_WAITING); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1516 | } |
| 1517 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1518 | static void sci_port_resetting_state_exit(struct sci_base_state_machine *sm) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1519 | { |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1520 | struct isci_port *iport = container_of(sm, typeof(*iport), sm); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1521 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1522 | sci_del_timer(&iport->timer); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1523 | } |
| 1524 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1525 | static void sci_port_stopping_state_exit(struct sci_base_state_machine *sm) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1526 | { |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1527 | struct isci_port *iport = container_of(sm, typeof(*iport), sm); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1528 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1529 | sci_del_timer(&iport->timer); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1530 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1531 | sci_port_destroy_dummy_resources(iport); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1532 | } |
| 1533 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1534 | static void sci_port_failed_state_enter(struct sci_base_state_machine *sm) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1535 | { |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1536 | struct isci_port *iport = container_of(sm, typeof(*iport), sm); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1537 | |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1538 | isci_port_hard_reset_complete(iport, SCI_FAILURE_TIMEOUT); |
| 1539 | } |
| 1540 | |
| 1541 | /* --------------------------------------------------------------------------- */ |
| 1542 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1543 | static const struct sci_base_state sci_port_state_table[] = { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1544 | [SCI_PORT_STOPPED] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1545 | .enter_state = sci_port_stopped_state_enter, |
| 1546 | .exit_state = sci_port_stopped_state_exit |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1547 | }, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1548 | [SCI_PORT_STOPPING] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1549 | .exit_state = sci_port_stopping_state_exit |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1550 | }, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1551 | [SCI_PORT_READY] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1552 | .enter_state = sci_port_ready_state_enter, |
Piotr Sawicki | e91f41e | 2011-05-11 23:52:21 +0000 | [diff] [blame] | 1553 | }, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1554 | [SCI_PORT_SUB_WAITING] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1555 | .enter_state = sci_port_ready_substate_waiting_enter, |
Marcin Tomczak | 05b080f | 2012-01-04 01:33:41 -0800 | [diff] [blame] | 1556 | .exit_state = scic_sds_port_ready_substate_waiting_exit, |
Piotr Sawicki | e91f41e | 2011-05-11 23:52:21 +0000 | [diff] [blame] | 1557 | }, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1558 | [SCI_PORT_SUB_OPERATIONAL] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1559 | .enter_state = sci_port_ready_substate_operational_enter, |
| 1560 | .exit_state = sci_port_ready_substate_operational_exit |
Piotr Sawicki | e91f41e | 2011-05-11 23:52:21 +0000 | [diff] [blame] | 1561 | }, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1562 | [SCI_PORT_SUB_CONFIGURING] = { |
Marcin Tomczak | 05b080f | 2012-01-04 01:33:41 -0800 | [diff] [blame] | 1563 | .enter_state = sci_port_ready_substate_configuring_enter |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1564 | }, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1565 | [SCI_PORT_RESETTING] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1566 | .exit_state = sci_port_resetting_state_exit |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1567 | }, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1568 | [SCI_PORT_FAILED] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1569 | .enter_state = sci_port_failed_state_enter, |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1570 | } |
| 1571 | }; |
| 1572 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1573 | void sci_port_construct(struct isci_port *iport, u8 index, |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1574 | struct isci_host *ihost) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1575 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1576 | sci_init_sm(&iport->sm, sci_port_state_table, SCI_PORT_STOPPED); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1577 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1578 | iport->logical_port_index = SCIC_SDS_DUMMY_PORT; |
| 1579 | iport->physical_port_index = index; |
| 1580 | iport->active_phy_mask = 0; |
Marcin Tomczak | 05b080f | 2012-01-04 01:33:41 -0800 | [diff] [blame] | 1581 | iport->enabled_phy_mask = 0; |
Jeff Skirvin | 8e35a13 | 2011-10-27 15:05:32 -0700 | [diff] [blame] | 1582 | iport->last_active_phy = 0; |
| 1583 | iport->ready_exit = false; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1584 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1585 | iport->owning_controller = ihost; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1586 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1587 | iport->started_request_count = 0; |
| 1588 | iport->assigned_device_count = 0; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1589 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1590 | iport->reserved_rni = SCU_DUMMY_INDEX; |
| 1591 | iport->reserved_tag = SCI_CONTROLLER_INVALID_IO_TAG; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1592 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1593 | sci_init_timer(&iport->timer, port_timeout); |
Edmund Nadolski | 5553ba2 | 2011-05-19 11:59:10 +0000 | [diff] [blame] | 1594 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1595 | iport->port_task_scheduler_registers = NULL; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1596 | |
| 1597 | for (index = 0; index < SCI_MAX_PHYS; index++) |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1598 | iport->phy_table[index] = NULL; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1599 | } |
| 1600 | |
| 1601 | void isci_port_init(struct isci_port *iport, struct isci_host *ihost, int index) |
| 1602 | { |
| 1603 | INIT_LIST_HEAD(&iport->remote_dev_list); |
| 1604 | INIT_LIST_HEAD(&iport->domain_dev_list); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1605 | iport->isci_host = ihost; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1606 | } |
| 1607 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1608 | void sci_port_broadcast_change_received(struct isci_port *iport, struct isci_phy *iphy) |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1609 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1610 | struct isci_host *ihost = iport->owning_controller; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1611 | |
| 1612 | /* notify the user. */ |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1613 | isci_port_bc_change_received(ihost, iport, iphy); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1614 | } |
| 1615 | |
Dan Williams | 9277699 | 2011-11-30 11:57:34 -0800 | [diff] [blame] | 1616 | static void wait_port_reset(struct isci_host *ihost, struct isci_port *iport) |
| 1617 | { |
| 1618 | wait_event(ihost->eventq, !test_bit(IPORT_RESET_PENDING, &iport->state)); |
| 1619 | } |
| 1620 | |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1621 | int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *iport, |
| 1622 | struct isci_phy *iphy) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1623 | { |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1624 | unsigned long flags; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1625 | enum sci_status status; |
Jeff Skirvin | 8e35a13 | 2011-10-27 15:05:32 -0700 | [diff] [blame] | 1626 | int ret = TMF_RESP_FUNC_COMPLETE; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1627 | |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1628 | dev_dbg(&ihost->pdev->dev, "%s: iport = %p\n", |
| 1629 | __func__, iport); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1630 | |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1631 | spin_lock_irqsave(&ihost->scic_lock, flags); |
Dan Williams | 9277699 | 2011-11-30 11:57:34 -0800 | [diff] [blame] | 1632 | set_bit(IPORT_RESET_PENDING, &iport->state); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1633 | |
| 1634 | #define ISCI_PORT_RESET_TIMEOUT SCIC_SDS_SIGNATURE_FIS_TIMEOUT |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1635 | status = sci_port_hard_reset(iport, ISCI_PORT_RESET_TIMEOUT); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1636 | |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1637 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1638 | |
| 1639 | if (status == SCI_SUCCESS) { |
Dan Williams | 9277699 | 2011-11-30 11:57:34 -0800 | [diff] [blame] | 1640 | wait_port_reset(ihost, iport); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1641 | |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1642 | dev_dbg(&ihost->pdev->dev, |
| 1643 | "%s: iport = %p; hard reset completion\n", |
| 1644 | __func__, iport); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1645 | |
Jeff Skirvin | 8e35a13 | 2011-10-27 15:05:32 -0700 | [diff] [blame] | 1646 | if (iport->hard_reset_status != SCI_SUCCESS) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1647 | ret = TMF_RESP_FUNC_FAILED; |
Jeff Skirvin | 8e35a13 | 2011-10-27 15:05:32 -0700 | [diff] [blame] | 1648 | |
| 1649 | dev_err(&ihost->pdev->dev, |
| 1650 | "%s: iport = %p; hard reset failed (0x%x)\n", |
| 1651 | __func__, iport, iport->hard_reset_status); |
| 1652 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1653 | } else { |
Dan Williams | 9277699 | 2011-11-30 11:57:34 -0800 | [diff] [blame] | 1654 | clear_bit(IPORT_RESET_PENDING, &iport->state); |
| 1655 | wake_up(&ihost->eventq); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1656 | ret = TMF_RESP_FUNC_FAILED; |
| 1657 | |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1658 | dev_err(&ihost->pdev->dev, |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1659 | "%s: iport = %p; sci_port_hard_reset call" |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1660 | " failed 0x%x\n", |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1661 | __func__, iport, status); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1662 | |
| 1663 | } |
| 1664 | |
| 1665 | /* If the hard reset for the port has failed, consider this |
| 1666 | * the same as link failures on all phys in the port. |
| 1667 | */ |
| 1668 | if (ret != TMF_RESP_FUNC_COMPLETE) { |
Jeff Skirvin | fd0527a | 2011-06-20 14:09:26 -0700 | [diff] [blame] | 1669 | |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1670 | dev_err(&ihost->pdev->dev, |
| 1671 | "%s: iport = %p; hard reset failed " |
Jeff Skirvin | fd0527a | 2011-06-20 14:09:26 -0700 | [diff] [blame] | 1672 | "(0x%x) - driving explicit link fail for all phys\n", |
| 1673 | __func__, iport, iport->hard_reset_status); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1674 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1675 | return ret; |
| 1676 | } |
Dave Jiang | 09d7da1 | 2011-03-26 16:11:51 -0700 | [diff] [blame] | 1677 | |
Dan Williams | 687833a | 2011-11-17 18:01:38 -0800 | [diff] [blame] | 1678 | int isci_ata_check_ready(struct domain_device *dev) |
| 1679 | { |
| 1680 | struct isci_port *iport = dev->port->lldd_port; |
| 1681 | struct isci_host *ihost = dev_to_ihost(dev); |
| 1682 | struct isci_remote_device *idev; |
| 1683 | unsigned long flags; |
| 1684 | int rc = 0; |
| 1685 | |
| 1686 | spin_lock_irqsave(&ihost->scic_lock, flags); |
| 1687 | idev = isci_lookup_device(dev); |
| 1688 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
| 1689 | |
| 1690 | if (!idev) |
| 1691 | goto out; |
| 1692 | |
| 1693 | if (test_bit(IPORT_RESET_PENDING, &iport->state)) |
| 1694 | goto out; |
| 1695 | |
| 1696 | rc = !!iport->active_phy_mask; |
| 1697 | out: |
| 1698 | isci_put_device(idev); |
| 1699 | |
| 1700 | return rc; |
| 1701 | } |
| 1702 | |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1703 | void isci_port_deformed(struct asd_sas_phy *phy) |
Dave Jiang | 09d7da1 | 2011-03-26 16:11:51 -0700 | [diff] [blame] | 1704 | { |
Dan Williams | c132f69 | 2012-01-03 23:26:08 -0800 | [diff] [blame] | 1705 | struct isci_host *ihost = phy->ha->lldd_ha; |
| 1706 | struct isci_port *iport = phy->port->lldd_port; |
| 1707 | unsigned long flags; |
| 1708 | int i; |
| 1709 | |
| 1710 | /* we got a port notification on a port that was subsequently |
| 1711 | * torn down and libsas is just now catching up |
| 1712 | */ |
| 1713 | if (!iport) |
| 1714 | return; |
| 1715 | |
| 1716 | spin_lock_irqsave(&ihost->scic_lock, flags); |
| 1717 | for (i = 0; i < SCI_MAX_PHYS; i++) { |
| 1718 | if (iport->active_phy_mask & 1 << i) |
| 1719 | break; |
| 1720 | } |
| 1721 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
| 1722 | |
| 1723 | if (i >= SCI_MAX_PHYS) |
| 1724 | dev_dbg(&ihost->pdev->dev, "%s: port: %ld\n", |
| 1725 | __func__, (long) (iport - &ihost->ports[0])); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1726 | } |
| 1727 | |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 1728 | void isci_port_formed(struct asd_sas_phy *phy) |
| 1729 | { |
Dan Williams | c132f69 | 2012-01-03 23:26:08 -0800 | [diff] [blame] | 1730 | struct isci_host *ihost = phy->ha->lldd_ha; |
| 1731 | struct isci_phy *iphy = to_iphy(phy); |
| 1732 | struct asd_sas_port *port = phy->port; |
| 1733 | struct isci_port *iport; |
| 1734 | unsigned long flags; |
| 1735 | int i; |
| 1736 | |
| 1737 | /* initial ports are formed as the driver is still initializing, |
| 1738 | * wait for that process to complete |
| 1739 | */ |
| 1740 | wait_for_start(ihost); |
| 1741 | |
| 1742 | spin_lock_irqsave(&ihost->scic_lock, flags); |
| 1743 | for (i = 0; i < SCI_MAX_PORTS; i++) { |
| 1744 | iport = &ihost->ports[i]; |
| 1745 | if (iport->active_phy_mask & 1 << iphy->phy_index) |
| 1746 | break; |
| 1747 | } |
| 1748 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
| 1749 | |
| 1750 | if (i >= SCI_MAX_PORTS) |
| 1751 | iport = NULL; |
| 1752 | |
| 1753 | port->lldd_port = iport; |
Dave Jiang | 09d7da1 | 2011-03-26 16:11:51 -0700 | [diff] [blame] | 1754 | } |