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