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 | |
| 56 | #include "isci.h" |
Dan Williams | ce2b326 | 2011-05-08 15:49:15 -0700 | [diff] [blame] | 57 | #include "host.h" |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 58 | #include "phy.h" |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 59 | #include "scu_event_codes.h" |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 60 | #include "probe_roms.h" |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 61 | |
Dan Williams | d7a0ccd | 2012-02-10 01:18:44 -0800 | [diff] [blame] | 62 | #undef C |
| 63 | #define C(a) (#a) |
| 64 | static const char *phy_state_name(enum sci_phy_states state) |
| 65 | { |
| 66 | static const char * const strings[] = PHY_STATES; |
| 67 | |
| 68 | return strings[state]; |
| 69 | } |
| 70 | #undef C |
| 71 | |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 72 | /* Maximum arbitration wait time in micro-seconds */ |
| 73 | #define SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME (700) |
| 74 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 75 | enum sas_linkrate sci_phy_linkrate(struct isci_phy *iphy) |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 76 | { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 77 | return iphy->max_negotiated_speed; |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Dan Williams | e462116 | 2012-02-10 01:18:49 -0800 | [diff] [blame] | 80 | static struct isci_host *phy_to_host(struct isci_phy *iphy) |
Dan Williams | c132f69 | 2012-01-03 23:26:08 -0800 | [diff] [blame] | 81 | { |
| 82 | struct isci_phy *table = iphy - iphy->phy_index; |
| 83 | struct isci_host *ihost = container_of(table, typeof(*ihost), phys[0]); |
| 84 | |
Dan Williams | e462116 | 2012-02-10 01:18:49 -0800 | [diff] [blame] | 85 | return ihost; |
| 86 | } |
| 87 | |
| 88 | static struct device *sciphy_to_dev(struct isci_phy *iphy) |
| 89 | { |
| 90 | return &phy_to_host(iphy)->pdev->dev; |
Dan Williams | c132f69 | 2012-01-03 23:26:08 -0800 | [diff] [blame] | 91 | } |
| 92 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 93 | static enum sci_status |
| 94 | sci_phy_transport_layer_initialization(struct isci_phy *iphy, |
| 95 | struct scu_transport_layer_registers __iomem *reg) |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 96 | { |
| 97 | u32 tl_control; |
| 98 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 99 | iphy->transport_layer_registers = reg; |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 100 | |
| 101 | writel(SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX, |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 102 | &iphy->transport_layer_registers->stp_rni); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 103 | |
| 104 | /* |
| 105 | * Hardware team recommends that we enable the STP prefetch for all |
| 106 | * transports |
| 107 | */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 108 | tl_control = readl(&iphy->transport_layer_registers->control); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 109 | tl_control |= SCU_TLCR_GEN_BIT(STP_WRITE_DATA_PREFETCH); |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 110 | writel(tl_control, &iphy->transport_layer_registers->control); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 111 | |
| 112 | return SCI_SUCCESS; |
| 113 | } |
| 114 | |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 115 | static enum sci_status |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 116 | sci_phy_link_layer_initialization(struct isci_phy *iphy, |
Dan Williams | 2e5da88 | 2012-01-04 01:32:34 -0800 | [diff] [blame] | 117 | struct scu_link_layer_registers __iomem *llr) |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 118 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 119 | struct isci_host *ihost = iphy->owning_port->owning_controller; |
Dan Williams | 2e5da88 | 2012-01-04 01:32:34 -0800 | [diff] [blame] | 120 | struct sci_phy_user_params *phy_user; |
| 121 | struct sci_phy_oem_params *phy_oem; |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 122 | int phy_idx = iphy->phy_index; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 123 | struct sci_phy_cap phy_cap; |
Dan Williams | 2e5da88 | 2012-01-04 01:32:34 -0800 | [diff] [blame] | 124 | u32 phy_configuration; |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 125 | u32 parity_check = 0; |
| 126 | u32 parity_count = 0; |
| 127 | u32 llctl, link_rate; |
| 128 | u32 clksm_value = 0; |
Marcin Tomczak | 985af6f | 2011-07-29 17:16:50 -0700 | [diff] [blame] | 129 | u32 sp_timeouts = 0; |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 130 | |
Dan Williams | 2e5da88 | 2012-01-04 01:32:34 -0800 | [diff] [blame] | 131 | phy_user = &ihost->user_parameters.phys[phy_idx]; |
| 132 | phy_oem = &ihost->oem_parameters.phys[phy_idx]; |
| 133 | iphy->link_layer_registers = llr; |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 134 | |
| 135 | /* Set our IDENTIFY frame data */ |
| 136 | #define SCI_END_DEVICE 0x01 |
| 137 | |
| 138 | writel(SCU_SAS_TIID_GEN_BIT(SMP_INITIATOR) | |
| 139 | SCU_SAS_TIID_GEN_BIT(SSP_INITIATOR) | |
| 140 | SCU_SAS_TIID_GEN_BIT(STP_INITIATOR) | |
| 141 | SCU_SAS_TIID_GEN_BIT(DA_SATA_HOST) | |
| 142 | SCU_SAS_TIID_GEN_VAL(DEVICE_TYPE, SCI_END_DEVICE), |
Dan Williams | 2e5da88 | 2012-01-04 01:32:34 -0800 | [diff] [blame] | 143 | &llr->transmit_identification); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 144 | |
| 145 | /* Write the device SAS Address */ |
Dan Williams | 2e5da88 | 2012-01-04 01:32:34 -0800 | [diff] [blame] | 146 | writel(0xFEDCBA98, &llr->sas_device_name_high); |
| 147 | writel(phy_idx, &llr->sas_device_name_low); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 148 | |
| 149 | /* Write the source SAS Address */ |
Dan Williams | 2e5da88 | 2012-01-04 01:32:34 -0800 | [diff] [blame] | 150 | writel(phy_oem->sas_address.high, &llr->source_sas_address_high); |
| 151 | writel(phy_oem->sas_address.low, &llr->source_sas_address_low); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 152 | |
| 153 | /* Clear and Set the PHY Identifier */ |
Dan Williams | 2e5da88 | 2012-01-04 01:32:34 -0800 | [diff] [blame] | 154 | writel(0, &llr->identify_frame_phy_id); |
| 155 | writel(SCU_SAS_TIPID_GEN_VALUE(ID, phy_idx), &llr->identify_frame_phy_id); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 156 | |
| 157 | /* Change the initial state of the phy configuration register */ |
Dan Williams | 2e5da88 | 2012-01-04 01:32:34 -0800 | [diff] [blame] | 158 | phy_configuration = readl(&llr->phy_configuration); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 159 | |
| 160 | /* Hold OOB state machine in reset */ |
| 161 | phy_configuration |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET); |
Dan Williams | 2e5da88 | 2012-01-04 01:32:34 -0800 | [diff] [blame] | 162 | writel(phy_configuration, &llr->phy_configuration); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 163 | |
| 164 | /* Configure the SNW capabilities */ |
| 165 | phy_cap.all = 0; |
| 166 | phy_cap.start = 1; |
| 167 | phy_cap.gen3_no_ssc = 1; |
| 168 | phy_cap.gen2_no_ssc = 1; |
| 169 | phy_cap.gen1_no_ssc = 1; |
Dave Jiang | 594e566 | 2012-01-04 01:32:44 -0800 | [diff] [blame] | 170 | if (ihost->oem_parameters.controller.do_enable_ssc) { |
| 171 | struct scu_afe_registers __iomem *afe = &ihost->scu_registers->afe; |
| 172 | struct scu_afe_transceiver *xcvr = &afe->scu_afe_xcvr[phy_idx]; |
| 173 | struct isci_pci_info *pci_info = to_pci_info(ihost->pdev); |
| 174 | bool en_sas = false; |
| 175 | bool en_sata = false; |
| 176 | u32 sas_type = 0; |
| 177 | u32 sata_spread = 0x2; |
| 178 | u32 sas_spread = 0x2; |
| 179 | |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 180 | phy_cap.gen3_ssc = 1; |
| 181 | phy_cap.gen2_ssc = 1; |
| 182 | phy_cap.gen1_ssc = 1; |
Dave Jiang | 594e566 | 2012-01-04 01:32:44 -0800 | [diff] [blame] | 183 | |
| 184 | if (pci_info->orom->hdr.version < ISCI_ROM_VER_1_1) |
| 185 | en_sas = en_sata = true; |
| 186 | else { |
| 187 | sata_spread = ihost->oem_parameters.controller.ssc_sata_tx_spread_level; |
| 188 | sas_spread = ihost->oem_parameters.controller.ssc_sas_tx_spread_level; |
| 189 | |
| 190 | if (sata_spread) |
| 191 | en_sata = true; |
| 192 | |
| 193 | if (sas_spread) { |
| 194 | en_sas = true; |
| 195 | sas_type = ihost->oem_parameters.controller.ssc_sas_tx_type; |
| 196 | } |
| 197 | |
| 198 | } |
| 199 | |
| 200 | if (en_sas) { |
| 201 | u32 reg; |
| 202 | |
| 203 | reg = readl(&xcvr->afe_xcvr_control0); |
| 204 | reg |= (0x00100000 | (sas_type << 19)); |
| 205 | writel(reg, &xcvr->afe_xcvr_control0); |
| 206 | |
| 207 | reg = readl(&xcvr->afe_tx_ssc_control); |
| 208 | reg |= sas_spread << 8; |
| 209 | writel(reg, &xcvr->afe_tx_ssc_control); |
| 210 | } |
| 211 | |
| 212 | if (en_sata) { |
| 213 | u32 reg; |
| 214 | |
| 215 | reg = readl(&xcvr->afe_tx_ssc_control); |
| 216 | reg |= sata_spread; |
| 217 | writel(reg, &xcvr->afe_tx_ssc_control); |
| 218 | |
| 219 | reg = readl(&llr->stp_control); |
| 220 | reg |= 1 << 12; |
| 221 | writel(reg, &llr->stp_control); |
| 222 | } |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 223 | } |
| 224 | |
Dan Williams | 2e5da88 | 2012-01-04 01:32:34 -0800 | [diff] [blame] | 225 | /* The SAS specification indicates that the phy_capabilities that |
| 226 | * are transmitted shall have an even parity. Calculate the parity. |
| 227 | */ |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 228 | parity_check = phy_cap.all; |
| 229 | while (parity_check != 0) { |
| 230 | if (parity_check & 0x1) |
| 231 | parity_count++; |
| 232 | parity_check >>= 1; |
| 233 | } |
| 234 | |
Dan Williams | 2e5da88 | 2012-01-04 01:32:34 -0800 | [diff] [blame] | 235 | /* If parity indicates there are an odd number of bits set, then |
| 236 | * set the parity bit to 1 in the phy capabilities. |
| 237 | */ |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 238 | if ((parity_count % 2) != 0) |
| 239 | phy_cap.parity = 1; |
| 240 | |
Dan Williams | 2e5da88 | 2012-01-04 01:32:34 -0800 | [diff] [blame] | 241 | writel(phy_cap.all, &llr->phy_capabilities); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 242 | |
| 243 | /* Set the enable spinup period but disable the ability to send |
| 244 | * notify enable spinup |
| 245 | */ |
| 246 | writel(SCU_ENSPINUP_GEN_VAL(COUNT, |
| 247 | phy_user->notify_enable_spin_up_insertion_frequency), |
Dan Williams | 2e5da88 | 2012-01-04 01:32:34 -0800 | [diff] [blame] | 248 | &llr->notify_enable_spinup_control); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 249 | |
| 250 | /* Write the ALIGN Insertion Ferequency for connected phy and |
| 251 | * inpendent of connected state |
| 252 | */ |
| 253 | clksm_value = SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(CONNECTED, |
| 254 | phy_user->in_connection_align_insertion_frequency); |
| 255 | |
| 256 | clksm_value |= SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(GENERAL, |
| 257 | phy_user->align_insertion_frequency); |
| 258 | |
Dan Williams | 2e5da88 | 2012-01-04 01:32:34 -0800 | [diff] [blame] | 259 | writel(clksm_value, &llr->clock_skew_management); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 260 | |
Jeff Skirvin | afd13a1 | 2012-01-04 01:32:39 -0800 | [diff] [blame] | 261 | if (is_c0(ihost->pdev) || is_c1(ihost->pdev)) { |
| 262 | writel(0x04210400, &llr->afe_lookup_table_control); |
| 263 | writel(0x020A7C05, &llr->sas_primitive_timeout); |
| 264 | } else |
| 265 | writel(0x02108421, &llr->afe_lookup_table_control); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 266 | |
| 267 | llctl = SCU_SAS_LLCTL_GEN_VAL(NO_OUTBOUND_TASK_TIMEOUT, |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 268 | (u8)ihost->user_parameters.no_outbound_task_timeout); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 269 | |
James Bottomley | a5ec7f86 | 2011-07-03 14:14:45 -0500 | [diff] [blame] | 270 | switch (phy_user->max_speed_generation) { |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 271 | case SCIC_SDS_PARM_GEN3_SPEED: |
| 272 | link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN3; |
| 273 | break; |
| 274 | case SCIC_SDS_PARM_GEN2_SPEED: |
| 275 | link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN2; |
| 276 | break; |
| 277 | default: |
| 278 | link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN1; |
| 279 | break; |
| 280 | } |
| 281 | llctl |= SCU_SAS_LLCTL_GEN_VAL(MAX_LINK_RATE, link_rate); |
Dan Williams | 2e5da88 | 2012-01-04 01:32:34 -0800 | [diff] [blame] | 282 | writel(llctl, &llr->link_layer_control); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 283 | |
Dan Williams | 2e5da88 | 2012-01-04 01:32:34 -0800 | [diff] [blame] | 284 | sp_timeouts = readl(&llr->sas_phy_timeouts); |
Marcin Tomczak | 985af6f | 2011-07-29 17:16:50 -0700 | [diff] [blame] | 285 | |
| 286 | /* Clear the default 0x36 (54us) RATE_CHANGE timeout value. */ |
| 287 | sp_timeouts &= ~SCU_SAS_PHYTOV_GEN_VAL(RATE_CHANGE, 0xFF); |
| 288 | |
| 289 | /* Set RATE_CHANGE timeout value to 0x3B (59us). This ensures SCU can |
| 290 | * lock with 3Gb drive when SCU max rate is set to 1.5Gb. |
| 291 | */ |
| 292 | sp_timeouts |= SCU_SAS_PHYTOV_GEN_VAL(RATE_CHANGE, 0x3B); |
| 293 | |
Dan Williams | 2e5da88 | 2012-01-04 01:32:34 -0800 | [diff] [blame] | 294 | writel(sp_timeouts, &llr->sas_phy_timeouts); |
Marcin Tomczak | 985af6f | 2011-07-29 17:16:50 -0700 | [diff] [blame] | 295 | |
Marcin Tomczak | 0b06f35 | 2011-07-29 17:16:50 -0700 | [diff] [blame] | 296 | sp_timeouts = readl(&iphy->link_layer_registers->sas_phy_timeouts); |
| 297 | |
| 298 | /* Clear the default 0x36 (54us) RATE_CHANGE timeout value. */ |
| 299 | sp_timeouts &= ~SCU_SAS_PHYTOV_GEN_VAL(RATE_CHANGE, 0xFF); |
| 300 | |
| 301 | /* Set RATE_CHANGE timeout value to 0x3B (59us). This ensures SCU can |
| 302 | * lock with 3Gb drive when SCU max rate is set to 1.5Gb. |
| 303 | */ |
| 304 | sp_timeouts |= SCU_SAS_PHYTOV_GEN_VAL(RATE_CHANGE, 0x3B); |
| 305 | |
| 306 | writel(sp_timeouts, &iphy->link_layer_registers->sas_phy_timeouts); |
| 307 | |
Dan Williams | dc00c8b | 2011-07-01 11:41:21 -0700 | [diff] [blame] | 308 | if (is_a2(ihost->pdev)) { |
Dan Williams | 2e5da88 | 2012-01-04 01:32:34 -0800 | [diff] [blame] | 309 | /* Program the max ARB time for the PHY to 700us so we |
| 310 | * inter-operate with the PMC expander which shuts down |
| 311 | * PHYs if the expander PHY generates too many breaks. |
| 312 | * This time value will guarantee that the initiator PHY |
| 313 | * will generate the break. |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 314 | */ |
| 315 | writel(SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME, |
Dan Williams | 2e5da88 | 2012-01-04 01:32:34 -0800 | [diff] [blame] | 316 | &llr->maximum_arbitration_wait_timer_timeout); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Dan Williams | 2e5da88 | 2012-01-04 01:32:34 -0800 | [diff] [blame] | 319 | /* Disable link layer hang detection, rely on the OS timeout for |
| 320 | * I/O timeouts. |
| 321 | */ |
| 322 | writel(0, &llr->link_layer_hang_detection_timeout); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 323 | |
| 324 | /* We can exit the initial state to the stopped state */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 325 | sci_change_state(&iphy->sm, SCI_PHY_STOPPED); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 326 | |
| 327 | return SCI_SUCCESS; |
| 328 | } |
| 329 | |
Edmund Nadolski | a628d47 | 2011-05-19 11:59:36 +0000 | [diff] [blame] | 330 | static void phy_sata_timeout(unsigned long data) |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 331 | { |
Edmund Nadolski | a628d47 | 2011-05-19 11:59:36 +0000 | [diff] [blame] | 332 | struct sci_timer *tmr = (struct sci_timer *)data; |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 333 | struct isci_phy *iphy = container_of(tmr, typeof(*iphy), sata_timer); |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 334 | struct isci_host *ihost = iphy->owning_port->owning_controller; |
Edmund Nadolski | a628d47 | 2011-05-19 11:59:36 +0000 | [diff] [blame] | 335 | unsigned long flags; |
| 336 | |
| 337 | spin_lock_irqsave(&ihost->scic_lock, flags); |
| 338 | |
| 339 | if (tmr->cancel) |
| 340 | goto done; |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 341 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 342 | dev_dbg(sciphy_to_dev(iphy), |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 343 | "%s: SCIC SDS Phy 0x%p did not receive signature fis before " |
| 344 | "timeout.\n", |
| 345 | __func__, |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 346 | iphy); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 347 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 348 | sci_change_state(&iphy->sm, SCI_PHY_STARTING); |
Edmund Nadolski | a628d47 | 2011-05-19 11:59:36 +0000 | [diff] [blame] | 349 | done: |
| 350 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | /** |
| 354 | * This method returns the port currently containing this phy. If the phy is |
| 355 | * currently contained by the dummy port, then the phy is considered to not |
| 356 | * be part of a port. |
| 357 | * @sci_phy: This parameter specifies the phy for which to retrieve the |
| 358 | * containing port. |
| 359 | * |
| 360 | * This method returns a handle to a port that contains the supplied phy. |
| 361 | * NULL This value is returned if the phy is not part of a real |
| 362 | * port (i.e. it's contained in the dummy port). !NULL All other |
| 363 | * values indicate a handle/pointer to the port containing the phy. |
| 364 | */ |
Dan Williams | 34a9915 | 2011-07-01 02:25:15 -0700 | [diff] [blame] | 365 | struct isci_port *phy_get_non_dummy_port(struct isci_phy *iphy) |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 366 | { |
Dan Williams | 34a9915 | 2011-07-01 02:25:15 -0700 | [diff] [blame] | 367 | struct isci_port *iport = iphy->owning_port; |
| 368 | |
| 369 | if (iport->physical_port_index == SCIC_SDS_DUMMY_PORT) |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 370 | return NULL; |
| 371 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 372 | return iphy->owning_port; |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | /** |
| 376 | * This method will assign a port to the phy object. |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 377 | * @out]: iphy This parameter specifies the phy for which to assign a port |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 378 | * object. |
| 379 | * |
| 380 | * |
| 381 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 382 | void sci_phy_set_port( |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 383 | struct isci_phy *iphy, |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 384 | struct isci_port *iport) |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 385 | { |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 386 | iphy->owning_port = iport; |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 387 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 388 | if (iphy->bcn_received_while_port_unassigned) { |
| 389 | iphy->bcn_received_while_port_unassigned = false; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 390 | sci_port_broadcast_change_received(iphy->owning_port, iphy); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 391 | } |
| 392 | } |
| 393 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 394 | enum sci_status sci_phy_initialize(struct isci_phy *iphy, |
| 395 | struct scu_transport_layer_registers __iomem *tl, |
| 396 | struct scu_link_layer_registers __iomem *ll) |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 397 | { |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 398 | /* Perfrom the initialization of the TL hardware */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 399 | sci_phy_transport_layer_initialization(iphy, tl); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 400 | |
| 401 | /* Perofrm the initialization of the PE hardware */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 402 | sci_phy_link_layer_initialization(iphy, ll); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 403 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 404 | /* There is nothing that needs to be done in this state just |
| 405 | * transition to the stopped state |
| 406 | */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 407 | sci_change_state(&iphy->sm, SCI_PHY_STOPPED); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 408 | |
| 409 | return SCI_SUCCESS; |
| 410 | } |
| 411 | |
| 412 | /** |
| 413 | * This method assigns the direct attached device ID for this phy. |
| 414 | * |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 415 | * @iphy The phy for which the direct attached device id is to |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 416 | * be assigned. |
| 417 | * @device_id The direct attached device ID to assign to the phy. |
| 418 | * This will either be the RNi for the device or an invalid RNi if there |
| 419 | * is no current device assigned to the phy. |
| 420 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 421 | void sci_phy_setup_transport(struct isci_phy *iphy, u32 device_id) |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 422 | { |
| 423 | u32 tl_control; |
| 424 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 425 | writel(device_id, &iphy->transport_layer_registers->stp_rni); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 426 | |
| 427 | /* |
| 428 | * The read should guarantee that the first write gets posted |
| 429 | * before the next write |
| 430 | */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 431 | tl_control = readl(&iphy->transport_layer_registers->control); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 432 | tl_control |= SCU_TLCR_GEN_BIT(CLEAR_TCI_NCQ_MAPPING_TABLE); |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 433 | writel(tl_control, &iphy->transport_layer_registers->control); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 434 | } |
| 435 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 436 | static void sci_phy_suspend(struct isci_phy *iphy) |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 437 | { |
| 438 | u32 scu_sas_pcfg_value; |
| 439 | |
| 440 | scu_sas_pcfg_value = |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 441 | readl(&iphy->link_layer_registers->phy_configuration); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 442 | scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE); |
| 443 | writel(scu_sas_pcfg_value, |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 444 | &iphy->link_layer_registers->phy_configuration); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 445 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 446 | sci_phy_setup_transport(iphy, SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 449 | void sci_phy_resume(struct isci_phy *iphy) |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 450 | { |
| 451 | u32 scu_sas_pcfg_value; |
| 452 | |
| 453 | scu_sas_pcfg_value = |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 454 | readl(&iphy->link_layer_registers->phy_configuration); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 455 | scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE); |
| 456 | writel(scu_sas_pcfg_value, |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 457 | &iphy->link_layer_registers->phy_configuration); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 458 | } |
| 459 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 460 | void sci_phy_get_sas_address(struct isci_phy *iphy, struct sci_sas_address *sas) |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 461 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 462 | sas->high = readl(&iphy->link_layer_registers->source_sas_address_high); |
| 463 | sas->low = readl(&iphy->link_layer_registers->source_sas_address_low); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 464 | } |
| 465 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 466 | void sci_phy_get_attached_sas_address(struct isci_phy *iphy, struct sci_sas_address *sas) |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 467 | { |
| 468 | struct sas_identify_frame *iaf; |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 469 | |
| 470 | iaf = &iphy->frame_rcvd.iaf; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 471 | memcpy(sas, iaf->sas_addr, SAS_ADDR_SIZE); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 474 | void sci_phy_get_protocols(struct isci_phy *iphy, struct sci_phy_proto *proto) |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 475 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 476 | proto->all = readl(&iphy->link_layer_registers->transmit_identification); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 477 | } |
| 478 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 479 | enum sci_status sci_phy_start(struct isci_phy *iphy) |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 480 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 481 | enum sci_phy_states state = iphy->sm.current_state_id; |
Dan Williams | 966699b | 2011-05-12 03:44:24 -0700 | [diff] [blame] | 482 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 483 | if (state != SCI_PHY_STOPPED) { |
Dan Williams | d7a0ccd | 2012-02-10 01:18:44 -0800 | [diff] [blame] | 484 | dev_dbg(sciphy_to_dev(iphy), "%s: in wrong state: %s\n", |
| 485 | __func__, phy_state_name(state)); |
Dan Williams | 966699b | 2011-05-12 03:44:24 -0700 | [diff] [blame] | 486 | return SCI_FAILURE_INVALID_STATE; |
| 487 | } |
| 488 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 489 | sci_change_state(&iphy->sm, SCI_PHY_STARTING); |
Dan Williams | 966699b | 2011-05-12 03:44:24 -0700 | [diff] [blame] | 490 | return SCI_SUCCESS; |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 491 | } |
| 492 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 493 | enum sci_status sci_phy_stop(struct isci_phy *iphy) |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 494 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 495 | enum sci_phy_states state = iphy->sm.current_state_id; |
Dan Williams | 9315323 | 2011-05-12 04:01:03 -0700 | [diff] [blame] | 496 | |
| 497 | switch (state) { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 498 | case SCI_PHY_SUB_INITIAL: |
| 499 | case SCI_PHY_SUB_AWAIT_OSSP_EN: |
| 500 | case SCI_PHY_SUB_AWAIT_SAS_SPEED_EN: |
| 501 | case SCI_PHY_SUB_AWAIT_SAS_POWER: |
| 502 | case SCI_PHY_SUB_AWAIT_SATA_POWER: |
| 503 | case SCI_PHY_SUB_AWAIT_SATA_PHY_EN: |
| 504 | case SCI_PHY_SUB_AWAIT_SATA_SPEED_EN: |
| 505 | case SCI_PHY_SUB_AWAIT_SIG_FIS_UF: |
| 506 | case SCI_PHY_SUB_FINAL: |
| 507 | case SCI_PHY_READY: |
Dan Williams | 9315323 | 2011-05-12 04:01:03 -0700 | [diff] [blame] | 508 | break; |
| 509 | default: |
Dan Williams | d7a0ccd | 2012-02-10 01:18:44 -0800 | [diff] [blame] | 510 | dev_dbg(sciphy_to_dev(iphy), "%s: in wrong state: %s\n", |
| 511 | __func__, phy_state_name(state)); |
Dan Williams | 9315323 | 2011-05-12 04:01:03 -0700 | [diff] [blame] | 512 | return SCI_FAILURE_INVALID_STATE; |
| 513 | } |
| 514 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 515 | sci_change_state(&iphy->sm, SCI_PHY_STOPPED); |
Dan Williams | 9315323 | 2011-05-12 04:01:03 -0700 | [diff] [blame] | 516 | return SCI_SUCCESS; |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 517 | } |
| 518 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 519 | enum sci_status sci_phy_reset(struct isci_phy *iphy) |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 520 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 521 | enum sci_phy_states state = iphy->sm.current_state_id; |
Dan Williams | 0cf36fa | 2011-05-12 04:02:07 -0700 | [diff] [blame] | 522 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 523 | if (state != SCI_PHY_READY) { |
Dan Williams | d7a0ccd | 2012-02-10 01:18:44 -0800 | [diff] [blame] | 524 | dev_dbg(sciphy_to_dev(iphy), "%s: in wrong state: %s\n", |
| 525 | __func__, phy_state_name(state)); |
Dan Williams | 0cf36fa | 2011-05-12 04:02:07 -0700 | [diff] [blame] | 526 | return SCI_FAILURE_INVALID_STATE; |
| 527 | } |
| 528 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 529 | sci_change_state(&iphy->sm, SCI_PHY_RESETTING); |
Dan Williams | 0cf36fa | 2011-05-12 04:02:07 -0700 | [diff] [blame] | 530 | return SCI_SUCCESS; |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 531 | } |
| 532 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 533 | enum sci_status sci_phy_consume_power_handler(struct isci_phy *iphy) |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 534 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 535 | enum sci_phy_states state = iphy->sm.current_state_id; |
Dan Williams | 5b1d4af | 2011-05-12 04:51:41 -0700 | [diff] [blame] | 536 | |
| 537 | switch (state) { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 538 | case SCI_PHY_SUB_AWAIT_SAS_POWER: { |
Dan Williams | 5b1d4af | 2011-05-12 04:51:41 -0700 | [diff] [blame] | 539 | u32 enable_spinup; |
| 540 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 541 | enable_spinup = readl(&iphy->link_layer_registers->notify_enable_spinup_control); |
Dan Williams | 5b1d4af | 2011-05-12 04:51:41 -0700 | [diff] [blame] | 542 | enable_spinup |= SCU_ENSPINUP_GEN_BIT(ENABLE); |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 543 | writel(enable_spinup, &iphy->link_layer_registers->notify_enable_spinup_control); |
Dan Williams | 5b1d4af | 2011-05-12 04:51:41 -0700 | [diff] [blame] | 544 | |
| 545 | /* Change state to the final state this substate machine has run to completion */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 546 | sci_change_state(&iphy->sm, SCI_PHY_SUB_FINAL); |
Dan Williams | 5b1d4af | 2011-05-12 04:51:41 -0700 | [diff] [blame] | 547 | |
| 548 | return SCI_SUCCESS; |
| 549 | } |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 550 | case SCI_PHY_SUB_AWAIT_SATA_POWER: { |
Dan Williams | 5b1d4af | 2011-05-12 04:51:41 -0700 | [diff] [blame] | 551 | u32 scu_sas_pcfg_value; |
| 552 | |
| 553 | /* Release the spinup hold state and reset the OOB state machine */ |
| 554 | scu_sas_pcfg_value = |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 555 | readl(&iphy->link_layer_registers->phy_configuration); |
Dan Williams | 5b1d4af | 2011-05-12 04:51:41 -0700 | [diff] [blame] | 556 | scu_sas_pcfg_value &= |
| 557 | ~(SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD) | SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE)); |
| 558 | scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET); |
| 559 | writel(scu_sas_pcfg_value, |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 560 | &iphy->link_layer_registers->phy_configuration); |
Dan Williams | 5b1d4af | 2011-05-12 04:51:41 -0700 | [diff] [blame] | 561 | |
| 562 | /* Now restart the OOB operation */ |
| 563 | scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET); |
| 564 | scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE); |
| 565 | writel(scu_sas_pcfg_value, |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 566 | &iphy->link_layer_registers->phy_configuration); |
Dan Williams | 5b1d4af | 2011-05-12 04:51:41 -0700 | [diff] [blame] | 567 | |
| 568 | /* Change state to the final state this substate machine has run to completion */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 569 | sci_change_state(&iphy->sm, SCI_PHY_SUB_AWAIT_SATA_PHY_EN); |
Dan Williams | 5b1d4af | 2011-05-12 04:51:41 -0700 | [diff] [blame] | 570 | |
| 571 | return SCI_SUCCESS; |
| 572 | } |
| 573 | default: |
Dan Williams | d7a0ccd | 2012-02-10 01:18:44 -0800 | [diff] [blame] | 574 | dev_dbg(sciphy_to_dev(iphy), "%s: in wrong state: %s\n", |
| 575 | __func__, phy_state_name(state)); |
Dan Williams | 5b1d4af | 2011-05-12 04:51:41 -0700 | [diff] [blame] | 576 | return SCI_FAILURE_INVALID_STATE; |
| 577 | } |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 578 | } |
| 579 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 580 | static void sci_phy_start_sas_link_training(struct isci_phy *iphy) |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 581 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 582 | /* continue the link training for the phy as if it were a SAS PHY |
| 583 | * instead of a SATA PHY. This is done because the completion queue had a SAS |
| 584 | * PHY DETECTED event when the state machine was expecting a SATA PHY event. |
| 585 | */ |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 586 | u32 phy_control; |
| 587 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 588 | phy_control = readl(&iphy->link_layer_registers->phy_configuration); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 589 | phy_control |= SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD); |
| 590 | writel(phy_control, |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 591 | &iphy->link_layer_registers->phy_configuration); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 592 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 593 | sci_change_state(&iphy->sm, SCI_PHY_SUB_AWAIT_SAS_SPEED_EN); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 594 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 595 | iphy->protocol = SCIC_SDS_PHY_PROTOCOL_SAS; |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 596 | } |
| 597 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 598 | static void sci_phy_start_sata_link_training(struct isci_phy *iphy) |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 599 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 600 | /* This method continues the link training for the phy as if it were a SATA PHY |
| 601 | * instead of a SAS PHY. This is done because the completion queue had a SATA |
| 602 | * SPINUP HOLD event when the state machine was expecting a SAS PHY event. none |
| 603 | */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 604 | sci_change_state(&iphy->sm, SCI_PHY_SUB_AWAIT_SATA_POWER); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 605 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 606 | iphy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA; |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | /** |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 610 | * sci_phy_complete_link_training - perform processing common to |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 611 | * all protocols upon completion of link training. |
| 612 | * @sci_phy: This parameter specifies the phy object for which link training |
| 613 | * has completed. |
| 614 | * @max_link_rate: This parameter specifies the maximum link rate to be |
| 615 | * associated with this phy. |
| 616 | * @next_state: This parameter specifies the next state for the phy's starting |
| 617 | * sub-state machine. |
| 618 | * |
| 619 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 620 | static void sci_phy_complete_link_training(struct isci_phy *iphy, |
| 621 | enum sas_linkrate max_link_rate, |
| 622 | u32 next_state) |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 623 | { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 624 | iphy->max_negotiated_speed = max_link_rate; |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 625 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 626 | sci_change_state(&iphy->sm, next_state); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 627 | } |
| 628 | |
Dan Williams | e462116 | 2012-02-10 01:18:49 -0800 | [diff] [blame] | 629 | static const char *phy_event_name(u32 event_code) |
| 630 | { |
| 631 | switch (scu_get_event_code(event_code)) { |
| 632 | case SCU_EVENT_PORT_SELECTOR_DETECTED: |
| 633 | return "port selector"; |
| 634 | case SCU_EVENT_SENT_PORT_SELECTION: |
| 635 | return "port selection"; |
| 636 | case SCU_EVENT_HARD_RESET_TRANSMITTED: |
| 637 | return "tx hard reset"; |
| 638 | case SCU_EVENT_HARD_RESET_RECEIVED: |
| 639 | return "rx hard reset"; |
| 640 | case SCU_EVENT_RECEIVED_IDENTIFY_TIMEOUT: |
| 641 | return "identify timeout"; |
| 642 | case SCU_EVENT_LINK_FAILURE: |
| 643 | return "link fail"; |
| 644 | case SCU_EVENT_SATA_SPINUP_HOLD: |
| 645 | return "sata spinup hold"; |
| 646 | case SCU_EVENT_SAS_15_SSC: |
| 647 | case SCU_EVENT_SAS_15: |
| 648 | return "sas 1.5"; |
| 649 | case SCU_EVENT_SAS_30_SSC: |
| 650 | case SCU_EVENT_SAS_30: |
| 651 | return "sas 3.0"; |
| 652 | case SCU_EVENT_SAS_60_SSC: |
| 653 | case SCU_EVENT_SAS_60: |
| 654 | return "sas 6.0"; |
| 655 | case SCU_EVENT_SATA_15_SSC: |
| 656 | case SCU_EVENT_SATA_15: |
| 657 | return "sata 1.5"; |
| 658 | case SCU_EVENT_SATA_30_SSC: |
| 659 | case SCU_EVENT_SATA_30: |
| 660 | return "sata 3.0"; |
| 661 | case SCU_EVENT_SATA_60_SSC: |
| 662 | case SCU_EVENT_SATA_60: |
| 663 | return "sata 6.0"; |
| 664 | case SCU_EVENT_SAS_PHY_DETECTED: |
| 665 | return "sas detect"; |
| 666 | case SCU_EVENT_SATA_PHY_DETECTED: |
| 667 | return "sata detect"; |
| 668 | default: |
| 669 | return "unknown"; |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | #define phy_event_dbg(iphy, state, code) \ |
| 674 | dev_dbg(sciphy_to_dev(iphy), "phy-%d:%d: %s event: %s (%x)\n", \ |
| 675 | phy_to_host(iphy)->id, iphy->phy_index, \ |
| 676 | phy_state_name(state), phy_event_name(code), code) |
| 677 | |
| 678 | #define phy_event_warn(iphy, state, code) \ |
| 679 | dev_warn(sciphy_to_dev(iphy), "phy-%d:%d: %s event: %s (%x)\n", \ |
| 680 | phy_to_host(iphy)->id, iphy->phy_index, \ |
| 681 | phy_state_name(state), phy_event_name(code), code) |
| 682 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 683 | enum sci_status sci_phy_event_handler(struct isci_phy *iphy, u32 event_code) |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 684 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 685 | enum sci_phy_states state = iphy->sm.current_state_id; |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 686 | |
| 687 | switch (state) { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 688 | case SCI_PHY_SUB_AWAIT_OSSP_EN: |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 689 | switch (scu_get_event_code(event_code)) { |
| 690 | case SCU_EVENT_SAS_PHY_DETECTED: |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 691 | sci_phy_start_sas_link_training(iphy); |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 692 | iphy->is_in_link_training = true; |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 693 | break; |
| 694 | case SCU_EVENT_SATA_SPINUP_HOLD: |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 695 | sci_phy_start_sata_link_training(iphy); |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 696 | iphy->is_in_link_training = true; |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 697 | break; |
| 698 | default: |
Dan Williams | e462116 | 2012-02-10 01:18:49 -0800 | [diff] [blame] | 699 | phy_event_dbg(iphy, state, event_code); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 700 | return SCI_FAILURE; |
| 701 | } |
| 702 | return SCI_SUCCESS; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 703 | case SCI_PHY_SUB_AWAIT_SAS_SPEED_EN: |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 704 | switch (scu_get_event_code(event_code)) { |
| 705 | case SCU_EVENT_SAS_PHY_DETECTED: |
| 706 | /* |
| 707 | * Why is this being reported again by the controller? |
| 708 | * We would re-enter this state so just stay here */ |
| 709 | break; |
| 710 | case SCU_EVENT_SAS_15: |
| 711 | case SCU_EVENT_SAS_15_SSC: |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 712 | sci_phy_complete_link_training(iphy, SAS_LINK_RATE_1_5_GBPS, |
| 713 | SCI_PHY_SUB_AWAIT_IAF_UF); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 714 | break; |
| 715 | case SCU_EVENT_SAS_30: |
| 716 | case SCU_EVENT_SAS_30_SSC: |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 717 | sci_phy_complete_link_training(iphy, SAS_LINK_RATE_3_0_GBPS, |
| 718 | SCI_PHY_SUB_AWAIT_IAF_UF); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 719 | break; |
| 720 | case SCU_EVENT_SAS_60: |
| 721 | case SCU_EVENT_SAS_60_SSC: |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 722 | sci_phy_complete_link_training(iphy, SAS_LINK_RATE_6_0_GBPS, |
| 723 | SCI_PHY_SUB_AWAIT_IAF_UF); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 724 | break; |
| 725 | case SCU_EVENT_SATA_SPINUP_HOLD: |
| 726 | /* |
| 727 | * We were doing SAS PHY link training and received a SATA PHY event |
| 728 | * continue OOB/SN as if this were a SATA PHY */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 729 | sci_phy_start_sata_link_training(iphy); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 730 | break; |
| 731 | case SCU_EVENT_LINK_FAILURE: |
| 732 | /* Link failure change state back to the starting state */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 733 | sci_change_state(&iphy->sm, SCI_PHY_STARTING); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 734 | break; |
| 735 | default: |
Dan Williams | e462116 | 2012-02-10 01:18:49 -0800 | [diff] [blame] | 736 | phy_event_warn(iphy, state, event_code); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 737 | return SCI_FAILURE; |
| 738 | break; |
| 739 | } |
| 740 | return SCI_SUCCESS; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 741 | case SCI_PHY_SUB_AWAIT_IAF_UF: |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 742 | switch (scu_get_event_code(event_code)) { |
| 743 | case SCU_EVENT_SAS_PHY_DETECTED: |
| 744 | /* Backup the state machine */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 745 | sci_phy_start_sas_link_training(iphy); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 746 | break; |
| 747 | case SCU_EVENT_SATA_SPINUP_HOLD: |
| 748 | /* We were doing SAS PHY link training and received a |
| 749 | * SATA PHY event continue OOB/SN as if this were a |
| 750 | * SATA PHY |
| 751 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 752 | sci_phy_start_sata_link_training(iphy); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 753 | break; |
| 754 | case SCU_EVENT_RECEIVED_IDENTIFY_TIMEOUT: |
| 755 | case SCU_EVENT_LINK_FAILURE: |
| 756 | case SCU_EVENT_HARD_RESET_RECEIVED: |
| 757 | /* Start the oob/sn state machine over again */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 758 | sci_change_state(&iphy->sm, SCI_PHY_STARTING); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 759 | break; |
| 760 | default: |
Dan Williams | e462116 | 2012-02-10 01:18:49 -0800 | [diff] [blame] | 761 | phy_event_warn(iphy, state, event_code); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 762 | return SCI_FAILURE; |
| 763 | } |
| 764 | return SCI_SUCCESS; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 765 | case SCI_PHY_SUB_AWAIT_SAS_POWER: |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 766 | switch (scu_get_event_code(event_code)) { |
| 767 | case SCU_EVENT_LINK_FAILURE: |
| 768 | /* Link failure change state back to the starting state */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 769 | sci_change_state(&iphy->sm, SCI_PHY_STARTING); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 770 | break; |
| 771 | default: |
Dan Williams | e462116 | 2012-02-10 01:18:49 -0800 | [diff] [blame] | 772 | phy_event_warn(iphy, state, event_code); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 773 | return SCI_FAILURE; |
| 774 | } |
| 775 | return SCI_SUCCESS; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 776 | case SCI_PHY_SUB_AWAIT_SATA_POWER: |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 777 | switch (scu_get_event_code(event_code)) { |
| 778 | case SCU_EVENT_LINK_FAILURE: |
| 779 | /* Link failure change state back to the starting state */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 780 | sci_change_state(&iphy->sm, SCI_PHY_STARTING); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 781 | break; |
| 782 | case SCU_EVENT_SATA_SPINUP_HOLD: |
| 783 | /* These events are received every 10ms and are |
| 784 | * expected while in this state |
| 785 | */ |
| 786 | break; |
| 787 | |
| 788 | case SCU_EVENT_SAS_PHY_DETECTED: |
| 789 | /* There has been a change in the phy type before OOB/SN for the |
| 790 | * SATA finished start down the SAS link traning path. |
| 791 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 792 | sci_phy_start_sas_link_training(iphy); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 793 | break; |
| 794 | |
| 795 | default: |
Dan Williams | e462116 | 2012-02-10 01:18:49 -0800 | [diff] [blame] | 796 | phy_event_warn(iphy, state, event_code); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 797 | return SCI_FAILURE; |
| 798 | } |
| 799 | return SCI_SUCCESS; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 800 | case SCI_PHY_SUB_AWAIT_SATA_PHY_EN: |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 801 | switch (scu_get_event_code(event_code)) { |
| 802 | case SCU_EVENT_LINK_FAILURE: |
| 803 | /* Link failure change state back to the starting state */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 804 | sci_change_state(&iphy->sm, SCI_PHY_STARTING); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 805 | break; |
| 806 | case SCU_EVENT_SATA_SPINUP_HOLD: |
| 807 | /* These events might be received since we dont know how many may be in |
| 808 | * the completion queue while waiting for power |
| 809 | */ |
| 810 | break; |
| 811 | case SCU_EVENT_SATA_PHY_DETECTED: |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 812 | iphy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA; |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 813 | |
| 814 | /* We have received the SATA PHY notification change state */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 815 | sci_change_state(&iphy->sm, SCI_PHY_SUB_AWAIT_SATA_SPEED_EN); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 816 | break; |
| 817 | case SCU_EVENT_SAS_PHY_DETECTED: |
| 818 | /* There has been a change in the phy type before OOB/SN for the |
| 819 | * SATA finished start down the SAS link traning path. |
| 820 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 821 | sci_phy_start_sas_link_training(iphy); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 822 | break; |
| 823 | default: |
Dan Williams | e462116 | 2012-02-10 01:18:49 -0800 | [diff] [blame] | 824 | phy_event_warn(iphy, state, event_code); |
Justin P. Mattock | 6993248 | 2011-07-26 23:06:29 -0700 | [diff] [blame] | 825 | return SCI_FAILURE; |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 826 | } |
| 827 | return SCI_SUCCESS; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 828 | case SCI_PHY_SUB_AWAIT_SATA_SPEED_EN: |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 829 | switch (scu_get_event_code(event_code)) { |
| 830 | case SCU_EVENT_SATA_PHY_DETECTED: |
| 831 | /* |
| 832 | * The hardware reports multiple SATA PHY detected events |
| 833 | * ignore the extras */ |
| 834 | break; |
| 835 | case SCU_EVENT_SATA_15: |
| 836 | case SCU_EVENT_SATA_15_SSC: |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 837 | sci_phy_complete_link_training(iphy, SAS_LINK_RATE_1_5_GBPS, |
| 838 | SCI_PHY_SUB_AWAIT_SIG_FIS_UF); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 839 | break; |
| 840 | case SCU_EVENT_SATA_30: |
| 841 | case SCU_EVENT_SATA_30_SSC: |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 842 | sci_phy_complete_link_training(iphy, SAS_LINK_RATE_3_0_GBPS, |
| 843 | SCI_PHY_SUB_AWAIT_SIG_FIS_UF); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 844 | break; |
| 845 | case SCU_EVENT_SATA_60: |
| 846 | case SCU_EVENT_SATA_60_SSC: |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 847 | sci_phy_complete_link_training(iphy, SAS_LINK_RATE_6_0_GBPS, |
| 848 | SCI_PHY_SUB_AWAIT_SIG_FIS_UF); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 849 | break; |
| 850 | case SCU_EVENT_LINK_FAILURE: |
| 851 | /* Link failure change state back to the starting state */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 852 | sci_change_state(&iphy->sm, SCI_PHY_STARTING); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 853 | break; |
| 854 | case SCU_EVENT_SAS_PHY_DETECTED: |
| 855 | /* |
| 856 | * There has been a change in the phy type before OOB/SN for the |
| 857 | * SATA finished start down the SAS link traning path. */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 858 | sci_phy_start_sas_link_training(iphy); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 859 | break; |
| 860 | default: |
Dan Williams | e462116 | 2012-02-10 01:18:49 -0800 | [diff] [blame] | 861 | phy_event_warn(iphy, state, event_code); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 862 | return SCI_FAILURE; |
| 863 | } |
| 864 | |
| 865 | return SCI_SUCCESS; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 866 | case SCI_PHY_SUB_AWAIT_SIG_FIS_UF: |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 867 | switch (scu_get_event_code(event_code)) { |
| 868 | case SCU_EVENT_SATA_PHY_DETECTED: |
| 869 | /* Backup the state machine */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 870 | sci_change_state(&iphy->sm, SCI_PHY_SUB_AWAIT_SATA_SPEED_EN); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 871 | break; |
| 872 | |
| 873 | case SCU_EVENT_LINK_FAILURE: |
| 874 | /* Link failure change state back to the starting state */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 875 | sci_change_state(&iphy->sm, SCI_PHY_STARTING); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 876 | break; |
| 877 | |
| 878 | default: |
Dan Williams | e462116 | 2012-02-10 01:18:49 -0800 | [diff] [blame] | 879 | phy_event_warn(iphy, state, event_code); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 880 | return SCI_FAILURE; |
| 881 | } |
| 882 | return SCI_SUCCESS; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 883 | case SCI_PHY_READY: |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 884 | switch (scu_get_event_code(event_code)) { |
| 885 | case SCU_EVENT_LINK_FAILURE: |
| 886 | /* Link failure change state back to the starting state */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 887 | sci_change_state(&iphy->sm, SCI_PHY_STARTING); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 888 | break; |
| 889 | case SCU_EVENT_BROADCAST_CHANGE: |
| 890 | /* Broadcast change received. Notify the port. */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 891 | if (phy_get_non_dummy_port(iphy) != NULL) |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 892 | sci_port_broadcast_change_received(iphy->owning_port, iphy); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 893 | else |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 894 | iphy->bcn_received_while_port_unassigned = true; |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 895 | break; |
| 896 | default: |
Dan Williams | e462116 | 2012-02-10 01:18:49 -0800 | [diff] [blame] | 897 | phy_event_warn(iphy, state, event_code); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 898 | return SCI_FAILURE_INVALID_STATE; |
| 899 | } |
| 900 | return SCI_SUCCESS; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 901 | case SCI_PHY_RESETTING: |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 902 | switch (scu_get_event_code(event_code)) { |
| 903 | case SCU_EVENT_HARD_RESET_TRANSMITTED: |
| 904 | /* Link failure change state back to the starting state */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 905 | sci_change_state(&iphy->sm, SCI_PHY_STARTING); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 906 | break; |
| 907 | default: |
Dan Williams | e462116 | 2012-02-10 01:18:49 -0800 | [diff] [blame] | 908 | phy_event_warn(iphy, state, event_code); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 909 | return SCI_FAILURE_INVALID_STATE; |
| 910 | break; |
| 911 | } |
| 912 | return SCI_SUCCESS; |
| 913 | default: |
Dan Williams | d7a0ccd | 2012-02-10 01:18:44 -0800 | [diff] [blame] | 914 | dev_dbg(sciphy_to_dev(iphy), "%s: in wrong state: %s\n", |
| 915 | __func__, phy_state_name(state)); |
Dan Williams | 23506a6 | 2011-05-12 04:27:29 -0700 | [diff] [blame] | 916 | return SCI_FAILURE_INVALID_STATE; |
| 917 | } |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 918 | } |
| 919 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 920 | enum sci_status sci_phy_frame_handler(struct isci_phy *iphy, u32 frame_index) |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 921 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 922 | enum sci_phy_states state = iphy->sm.current_state_id; |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 923 | struct isci_host *ihost = iphy->owning_port->owning_controller; |
Dan Williams | c4441ab | 2011-05-12 04:17:51 -0700 | [diff] [blame] | 924 | enum sci_status result; |
Dan Williams | 4cffe13 | 2011-06-23 23:44:52 -0700 | [diff] [blame] | 925 | unsigned long flags; |
Dan Williams | c4441ab | 2011-05-12 04:17:51 -0700 | [diff] [blame] | 926 | |
| 927 | switch (state) { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 928 | case SCI_PHY_SUB_AWAIT_IAF_UF: { |
Dan Williams | c4441ab | 2011-05-12 04:17:51 -0700 | [diff] [blame] | 929 | u32 *frame_words; |
| 930 | struct sas_identify_frame iaf; |
Dan Williams | c4441ab | 2011-05-12 04:17:51 -0700 | [diff] [blame] | 931 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 932 | result = sci_unsolicited_frame_control_get_header(&ihost->uf_control, |
| 933 | frame_index, |
| 934 | (void **)&frame_words); |
Dan Williams | c4441ab | 2011-05-12 04:17:51 -0700 | [diff] [blame] | 935 | |
| 936 | if (result != SCI_SUCCESS) |
| 937 | return result; |
| 938 | |
| 939 | sci_swab32_cpy(&iaf, frame_words, sizeof(iaf) / sizeof(u32)); |
| 940 | if (iaf.frame_type == 0) { |
| 941 | u32 state; |
| 942 | |
Dan Williams | 4cffe13 | 2011-06-23 23:44:52 -0700 | [diff] [blame] | 943 | spin_lock_irqsave(&iphy->sas_phy.frame_rcvd_lock, flags); |
Dan Williams | c4441ab | 2011-05-12 04:17:51 -0700 | [diff] [blame] | 944 | memcpy(&iphy->frame_rcvd.iaf, &iaf, sizeof(iaf)); |
Dan Williams | 4cffe13 | 2011-06-23 23:44:52 -0700 | [diff] [blame] | 945 | spin_unlock_irqrestore(&iphy->sas_phy.frame_rcvd_lock, flags); |
Dan Williams | c4441ab | 2011-05-12 04:17:51 -0700 | [diff] [blame] | 946 | if (iaf.smp_tport) { |
| 947 | /* We got the IAF for an expander PHY go to the final |
| 948 | * state since there are no power requirements for |
| 949 | * expander phys. |
| 950 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 951 | state = SCI_PHY_SUB_FINAL; |
Dan Williams | c4441ab | 2011-05-12 04:17:51 -0700 | [diff] [blame] | 952 | } else { |
| 953 | /* We got the IAF we can now go to the await spinup |
| 954 | * semaphore state |
| 955 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 956 | state = SCI_PHY_SUB_AWAIT_SAS_POWER; |
Dan Williams | c4441ab | 2011-05-12 04:17:51 -0700 | [diff] [blame] | 957 | } |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 958 | sci_change_state(&iphy->sm, state); |
Dan Williams | c4441ab | 2011-05-12 04:17:51 -0700 | [diff] [blame] | 959 | result = SCI_SUCCESS; |
| 960 | } else |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 961 | dev_warn(sciphy_to_dev(iphy), |
Dan Williams | c4441ab | 2011-05-12 04:17:51 -0700 | [diff] [blame] | 962 | "%s: PHY starting substate machine received " |
| 963 | "unexpected frame id %x\n", |
| 964 | __func__, frame_index); |
| 965 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 966 | sci_controller_release_frame(ihost, frame_index); |
Dan Williams | c4441ab | 2011-05-12 04:17:51 -0700 | [diff] [blame] | 967 | return result; |
| 968 | } |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 969 | case SCI_PHY_SUB_AWAIT_SIG_FIS_UF: { |
Dan Williams | c4441ab | 2011-05-12 04:17:51 -0700 | [diff] [blame] | 970 | struct dev_to_host_fis *frame_header; |
| 971 | u32 *fis_frame_data; |
Dan Williams | c4441ab | 2011-05-12 04:17:51 -0700 | [diff] [blame] | 972 | |
Dan Williams | 34a9915 | 2011-07-01 02:25:15 -0700 | [diff] [blame] | 973 | result = sci_unsolicited_frame_control_get_header(&ihost->uf_control, |
| 974 | frame_index, |
| 975 | (void **)&frame_header); |
Dan Williams | c4441ab | 2011-05-12 04:17:51 -0700 | [diff] [blame] | 976 | |
| 977 | if (result != SCI_SUCCESS) |
| 978 | return result; |
| 979 | |
| 980 | if ((frame_header->fis_type == FIS_REGD2H) && |
| 981 | !(frame_header->status & ATA_BUSY)) { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 982 | sci_unsolicited_frame_control_get_buffer(&ihost->uf_control, |
| 983 | frame_index, |
| 984 | (void **)&fis_frame_data); |
Dan Williams | c4441ab | 2011-05-12 04:17:51 -0700 | [diff] [blame] | 985 | |
Dan Williams | 4cffe13 | 2011-06-23 23:44:52 -0700 | [diff] [blame] | 986 | spin_lock_irqsave(&iphy->sas_phy.frame_rcvd_lock, flags); |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 987 | sci_controller_copy_sata_response(&iphy->frame_rcvd.fis, |
| 988 | frame_header, |
| 989 | fis_frame_data); |
Dan Williams | 4cffe13 | 2011-06-23 23:44:52 -0700 | [diff] [blame] | 990 | spin_unlock_irqrestore(&iphy->sas_phy.frame_rcvd_lock, flags); |
Dan Williams | c4441ab | 2011-05-12 04:17:51 -0700 | [diff] [blame] | 991 | |
| 992 | /* got IAF we can now go to the await spinup semaphore state */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 993 | sci_change_state(&iphy->sm, SCI_PHY_SUB_FINAL); |
Dan Williams | c4441ab | 2011-05-12 04:17:51 -0700 | [diff] [blame] | 994 | |
| 995 | result = SCI_SUCCESS; |
| 996 | } else |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 997 | dev_warn(sciphy_to_dev(iphy), |
Dan Williams | c4441ab | 2011-05-12 04:17:51 -0700 | [diff] [blame] | 998 | "%s: PHY starting substate machine received " |
| 999 | "unexpected frame id %x\n", |
| 1000 | __func__, frame_index); |
| 1001 | |
| 1002 | /* Regardless of the result we are done with this frame with it */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1003 | sci_controller_release_frame(ihost, frame_index); |
Dan Williams | c4441ab | 2011-05-12 04:17:51 -0700 | [diff] [blame] | 1004 | |
| 1005 | return result; |
| 1006 | } |
| 1007 | default: |
Dan Williams | d7a0ccd | 2012-02-10 01:18:44 -0800 | [diff] [blame] | 1008 | dev_dbg(sciphy_to_dev(iphy), "%s: in wrong state: %s\n", |
| 1009 | __func__, phy_state_name(state)); |
Dan Williams | c4441ab | 2011-05-12 04:17:51 -0700 | [diff] [blame] | 1010 | return SCI_FAILURE_INVALID_STATE; |
| 1011 | } |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame] | 1012 | |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1013 | } |
| 1014 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1015 | static void sci_phy_starting_initial_substate_enter(struct sci_base_state_machine *sm) |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1016 | { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1017 | struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm); |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1018 | |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1019 | /* This is just an temporary state go off to the starting state */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1020 | sci_change_state(&iphy->sm, SCI_PHY_SUB_AWAIT_OSSP_EN); |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1021 | } |
| 1022 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1023 | static void sci_phy_starting_await_sas_power_substate_enter(struct sci_base_state_machine *sm) |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1024 | { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1025 | struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm); |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1026 | struct isci_host *ihost = iphy->owning_port->owning_controller; |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1027 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1028 | sci_controller_power_control_queue_insert(ihost, iphy); |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1029 | } |
| 1030 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1031 | static void sci_phy_starting_await_sas_power_substate_exit(struct sci_base_state_machine *sm) |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1032 | { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1033 | struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm); |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1034 | struct isci_host *ihost = iphy->owning_port->owning_controller; |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1035 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1036 | sci_controller_power_control_queue_remove(ihost, iphy); |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1037 | } |
| 1038 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1039 | static void sci_phy_starting_await_sata_power_substate_enter(struct sci_base_state_machine *sm) |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1040 | { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1041 | struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm); |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1042 | struct isci_host *ihost = iphy->owning_port->owning_controller; |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1043 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1044 | sci_controller_power_control_queue_insert(ihost, iphy); |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1045 | } |
| 1046 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1047 | static void sci_phy_starting_await_sata_power_substate_exit(struct sci_base_state_machine *sm) |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1048 | { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1049 | struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm); |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1050 | struct isci_host *ihost = iphy->owning_port->owning_controller; |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1051 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1052 | sci_controller_power_control_queue_remove(ihost, iphy); |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1055 | static void sci_phy_starting_await_sata_phy_substate_enter(struct sci_base_state_machine *sm) |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1056 | { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1057 | struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm); |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1058 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1059 | sci_mod_timer(&iphy->sata_timer, SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT); |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1060 | } |
| 1061 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1062 | static void sci_phy_starting_await_sata_phy_substate_exit(struct sci_base_state_machine *sm) |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1063 | { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1064 | struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm); |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1065 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1066 | sci_del_timer(&iphy->sata_timer); |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1067 | } |
| 1068 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1069 | static void sci_phy_starting_await_sata_speed_substate_enter(struct sci_base_state_machine *sm) |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1070 | { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1071 | struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm); |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1072 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1073 | sci_mod_timer(&iphy->sata_timer, SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT); |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1074 | } |
| 1075 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1076 | static void sci_phy_starting_await_sata_speed_substate_exit(struct sci_base_state_machine *sm) |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1077 | { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1078 | struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm); |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1079 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1080 | sci_del_timer(&iphy->sata_timer); |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1081 | } |
| 1082 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1083 | static void sci_phy_starting_await_sig_fis_uf_substate_enter(struct sci_base_state_machine *sm) |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1084 | { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1085 | struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm); |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1086 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1087 | if (sci_port_link_detected(iphy->owning_port, iphy)) { |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1088 | |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1089 | /* |
| 1090 | * Clear the PE suspend condition so we can actually |
| 1091 | * receive SIG FIS |
| 1092 | * The hardware will not respond to the XRDY until the PE |
| 1093 | * suspend condition is cleared. |
| 1094 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1095 | sci_phy_resume(iphy); |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1096 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1097 | sci_mod_timer(&iphy->sata_timer, |
Edmund Nadolski | a628d47 | 2011-05-19 11:59:36 +0000 | [diff] [blame] | 1098 | SCIC_SDS_SIGNATURE_FIS_TIMEOUT); |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1099 | } else |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1100 | iphy->is_in_link_training = false; |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1101 | } |
| 1102 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1103 | static void sci_phy_starting_await_sig_fis_uf_substate_exit(struct sci_base_state_machine *sm) |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1104 | { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1105 | struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm); |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1106 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1107 | sci_del_timer(&iphy->sata_timer); |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1108 | } |
| 1109 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1110 | static void sci_phy_starting_final_substate_enter(struct sci_base_state_machine *sm) |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1111 | { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1112 | struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm); |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1113 | |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1114 | /* State machine has run to completion so exit out and change |
| 1115 | * the base state machine to the ready state |
| 1116 | */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1117 | sci_change_state(&iphy->sm, SCI_PHY_READY); |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1118 | } |
| 1119 | |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1120 | /** |
| 1121 | * |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1122 | * @sci_phy: This is the struct isci_phy object to stop. |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1123 | * |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1124 | * This method will stop the struct isci_phy object. This does not reset the |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1125 | * protocol engine it just suspends it and places it in a state where it will |
| 1126 | * not cause the end device to power up. none |
| 1127 | */ |
| 1128 | static void scu_link_layer_stop_protocol_engine( |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1129 | struct isci_phy *iphy) |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1130 | { |
| 1131 | u32 scu_sas_pcfg_value; |
| 1132 | u32 enable_spinup_value; |
| 1133 | |
| 1134 | /* Suspend the protocol engine and place it in a sata spinup hold state */ |
| 1135 | scu_sas_pcfg_value = |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1136 | readl(&iphy->link_layer_registers->phy_configuration); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1137 | scu_sas_pcfg_value |= |
| 1138 | (SCU_SAS_PCFG_GEN_BIT(OOB_RESET) | |
| 1139 | SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE) | |
| 1140 | SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD)); |
| 1141 | writel(scu_sas_pcfg_value, |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1142 | &iphy->link_layer_registers->phy_configuration); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1143 | |
| 1144 | /* Disable the notify enable spinup primitives */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1145 | enable_spinup_value = readl(&iphy->link_layer_registers->notify_enable_spinup_control); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1146 | enable_spinup_value &= ~SCU_ENSPINUP_GEN_BIT(ENABLE); |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1147 | writel(enable_spinup_value, &iphy->link_layer_registers->notify_enable_spinup_control); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1148 | } |
| 1149 | |
Marcin Tomczak | 0953dbe | 2012-01-04 01:33:36 -0800 | [diff] [blame] | 1150 | static void scu_link_layer_start_oob(struct isci_phy *iphy) |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1151 | { |
Marcin Tomczak | 0953dbe | 2012-01-04 01:33:36 -0800 | [diff] [blame] | 1152 | struct scu_link_layer_registers __iomem *ll = iphy->link_layer_registers; |
| 1153 | u32 val; |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1154 | |
Marcin Tomczak | 0953dbe | 2012-01-04 01:33:36 -0800 | [diff] [blame] | 1155 | /** Reset OOB sequence - start */ |
| 1156 | val = readl(&ll->phy_configuration); |
| 1157 | val &= ~(SCU_SAS_PCFG_GEN_BIT(OOB_RESET) | |
| 1158 | SCU_SAS_PCFG_GEN_BIT(HARD_RESET)); |
| 1159 | writel(val, &ll->phy_configuration); |
| 1160 | readl(&ll->phy_configuration); /* flush */ |
| 1161 | /** Reset OOB sequence - end */ |
| 1162 | |
| 1163 | /** Start OOB sequence - start */ |
| 1164 | val = readl(&ll->phy_configuration); |
| 1165 | val |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE); |
| 1166 | writel(val, &ll->phy_configuration); |
| 1167 | readl(&ll->phy_configuration); /* flush */ |
| 1168 | /** Start OOB sequence - end */ |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1169 | } |
| 1170 | |
| 1171 | /** |
| 1172 | * |
| 1173 | * |
| 1174 | * This method will transmit a hard reset request on the specified phy. The SCU |
| 1175 | * hardware requires that we reset the OOB state machine and set the hard reset |
| 1176 | * bit in the phy configuration register. We then must start OOB over with the |
| 1177 | * hard reset bit set. |
| 1178 | */ |
| 1179 | static void scu_link_layer_tx_hard_reset( |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1180 | struct isci_phy *iphy) |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1181 | { |
| 1182 | u32 phy_configuration_value; |
| 1183 | |
| 1184 | /* |
| 1185 | * SAS Phys must wait for the HARD_RESET_TX event notification to transition |
| 1186 | * to the starting state. */ |
| 1187 | phy_configuration_value = |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1188 | readl(&iphy->link_layer_registers->phy_configuration); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1189 | phy_configuration_value |= |
| 1190 | (SCU_SAS_PCFG_GEN_BIT(HARD_RESET) | |
| 1191 | SCU_SAS_PCFG_GEN_BIT(OOB_RESET)); |
| 1192 | writel(phy_configuration_value, |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1193 | &iphy->link_layer_registers->phy_configuration); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1194 | |
| 1195 | /* Now take the OOB state machine out of reset */ |
| 1196 | phy_configuration_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE); |
| 1197 | phy_configuration_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET); |
| 1198 | writel(phy_configuration_value, |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1199 | &iphy->link_layer_registers->phy_configuration); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1200 | } |
| 1201 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1202 | static void sci_phy_stopped_state_enter(struct sci_base_state_machine *sm) |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1203 | { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1204 | struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm); |
Dan Williams | 34a9915 | 2011-07-01 02:25:15 -0700 | [diff] [blame] | 1205 | struct isci_port *iport = iphy->owning_port; |
| 1206 | struct isci_host *ihost = iport->owning_controller; |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1207 | |
| 1208 | /* |
| 1209 | * @todo We need to get to the controller to place this PE in a |
| 1210 | * reset state |
| 1211 | */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1212 | sci_del_timer(&iphy->sata_timer); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1213 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1214 | scu_link_layer_stop_protocol_engine(iphy); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1215 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1216 | if (iphy->sm.previous_state_id != SCI_PHY_INITIAL) |
Dan Williams | 34a9915 | 2011-07-01 02:25:15 -0700 | [diff] [blame] | 1217 | sci_controller_link_down(ihost, phy_get_non_dummy_port(iphy), iphy); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1218 | } |
| 1219 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1220 | static void sci_phy_starting_state_enter(struct sci_base_state_machine *sm) |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1221 | { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1222 | struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm); |
Dan Williams | 34a9915 | 2011-07-01 02:25:15 -0700 | [diff] [blame] | 1223 | struct isci_port *iport = iphy->owning_port; |
| 1224 | struct isci_host *ihost = iport->owning_controller; |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1225 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1226 | scu_link_layer_stop_protocol_engine(iphy); |
| 1227 | scu_link_layer_start_oob(iphy); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1228 | |
| 1229 | /* We don't know what kind of phy we are going to be just yet */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1230 | iphy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN; |
| 1231 | iphy->bcn_received_while_port_unassigned = false; |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1232 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1233 | if (iphy->sm.previous_state_id == SCI_PHY_READY) |
Dan Williams | 34a9915 | 2011-07-01 02:25:15 -0700 | [diff] [blame] | 1234 | sci_controller_link_down(ihost, phy_get_non_dummy_port(iphy), iphy); |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1235 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1236 | sci_change_state(&iphy->sm, SCI_PHY_SUB_INITIAL); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1237 | } |
| 1238 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1239 | static void sci_phy_ready_state_enter(struct sci_base_state_machine *sm) |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1240 | { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1241 | struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm); |
Dan Williams | 34a9915 | 2011-07-01 02:25:15 -0700 | [diff] [blame] | 1242 | struct isci_port *iport = iphy->owning_port; |
| 1243 | struct isci_host *ihost = iport->owning_controller; |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1244 | |
Dan Williams | 34a9915 | 2011-07-01 02:25:15 -0700 | [diff] [blame] | 1245 | sci_controller_link_up(ihost, phy_get_non_dummy_port(iphy), iphy); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1246 | } |
| 1247 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1248 | static void sci_phy_ready_state_exit(struct sci_base_state_machine *sm) |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1249 | { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1250 | struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1251 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1252 | sci_phy_suspend(iphy); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1253 | } |
| 1254 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1255 | static void sci_phy_resetting_state_enter(struct sci_base_state_machine *sm) |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1256 | { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1257 | struct isci_phy *iphy = container_of(sm, typeof(*iphy), sm); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1258 | |
Dan Williams | 5b1d4af | 2011-05-12 04:51:41 -0700 | [diff] [blame] | 1259 | /* The phy is being reset, therefore deactivate it from the port. In |
| 1260 | * the resetting state we don't notify the user regarding link up and |
| 1261 | * link down notifications |
| 1262 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1263 | sci_port_deactivate_phy(iphy->owning_port, iphy, false); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1264 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1265 | if (iphy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) { |
| 1266 | scu_link_layer_tx_hard_reset(iphy); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1267 | } else { |
Dan Williams | 5b1d4af | 2011-05-12 04:51:41 -0700 | [diff] [blame] | 1268 | /* The SCU does not need to have a discrete reset state so |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1269 | * just go back to the starting state. |
| 1270 | */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1271 | sci_change_state(&iphy->sm, SCI_PHY_STARTING); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1272 | } |
| 1273 | } |
| 1274 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1275 | static const struct sci_base_state sci_phy_state_table[] = { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1276 | [SCI_PHY_INITIAL] = { }, |
| 1277 | [SCI_PHY_STOPPED] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1278 | .enter_state = sci_phy_stopped_state_enter, |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1279 | }, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1280 | [SCI_PHY_STARTING] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1281 | .enter_state = sci_phy_starting_state_enter, |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1282 | }, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1283 | [SCI_PHY_SUB_INITIAL] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1284 | .enter_state = sci_phy_starting_initial_substate_enter, |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1285 | }, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1286 | [SCI_PHY_SUB_AWAIT_OSSP_EN] = { }, |
| 1287 | [SCI_PHY_SUB_AWAIT_SAS_SPEED_EN] = { }, |
| 1288 | [SCI_PHY_SUB_AWAIT_IAF_UF] = { }, |
| 1289 | [SCI_PHY_SUB_AWAIT_SAS_POWER] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1290 | .enter_state = sci_phy_starting_await_sas_power_substate_enter, |
| 1291 | .exit_state = sci_phy_starting_await_sas_power_substate_exit, |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1292 | }, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1293 | [SCI_PHY_SUB_AWAIT_SATA_POWER] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1294 | .enter_state = sci_phy_starting_await_sata_power_substate_enter, |
| 1295 | .exit_state = sci_phy_starting_await_sata_power_substate_exit |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1296 | }, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1297 | [SCI_PHY_SUB_AWAIT_SATA_PHY_EN] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1298 | .enter_state = sci_phy_starting_await_sata_phy_substate_enter, |
| 1299 | .exit_state = sci_phy_starting_await_sata_phy_substate_exit |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1300 | }, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1301 | [SCI_PHY_SUB_AWAIT_SATA_SPEED_EN] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1302 | .enter_state = sci_phy_starting_await_sata_speed_substate_enter, |
| 1303 | .exit_state = sci_phy_starting_await_sata_speed_substate_exit |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1304 | }, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1305 | [SCI_PHY_SUB_AWAIT_SIG_FIS_UF] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1306 | .enter_state = sci_phy_starting_await_sig_fis_uf_substate_enter, |
| 1307 | .exit_state = sci_phy_starting_await_sig_fis_uf_substate_exit |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1308 | }, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1309 | [SCI_PHY_SUB_FINAL] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1310 | .enter_state = sci_phy_starting_final_substate_enter, |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 1311 | }, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1312 | [SCI_PHY_READY] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1313 | .enter_state = sci_phy_ready_state_enter, |
| 1314 | .exit_state = sci_phy_ready_state_exit, |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1315 | }, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1316 | [SCI_PHY_RESETTING] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1317 | .enter_state = sci_phy_resetting_state_enter, |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1318 | }, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1319 | [SCI_PHY_FINAL] = { }, |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1320 | }; |
| 1321 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1322 | void sci_phy_construct(struct isci_phy *iphy, |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1323 | struct isci_port *iport, u8 phy_index) |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1324 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1325 | sci_init_sm(&iphy->sm, sci_phy_state_table, SCI_PHY_INITIAL); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1326 | |
| 1327 | /* Copy the rest of the input data to our locals */ |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1328 | iphy->owning_port = iport; |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1329 | iphy->phy_index = phy_index; |
| 1330 | iphy->bcn_received_while_port_unassigned = false; |
| 1331 | iphy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN; |
| 1332 | iphy->link_layer_registers = NULL; |
| 1333 | iphy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN; |
Edmund Nadolski | a628d47 | 2011-05-19 11:59:36 +0000 | [diff] [blame] | 1334 | |
| 1335 | /* Create the SIGNATURE FIS Timeout timer for this phy */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1336 | sci_init_timer(&iphy->sata_timer, phy_sata_timeout); |
Dan Williams | d35bc1b | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 1337 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1338 | |
Dan Williams | 4b33981 | 2011-05-06 17:36:38 -0700 | [diff] [blame] | 1339 | void isci_phy_init(struct isci_phy *iphy, struct isci_host *ihost, int index) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1340 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1341 | struct sci_oem_params *oem = &ihost->oem_parameters; |
Dan Williams | 4b33981 | 2011-05-06 17:36:38 -0700 | [diff] [blame] | 1342 | u64 sci_sas_addr; |
| 1343 | __be64 sas_addr; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1344 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1345 | sci_sas_addr = oem->phys[index].sas_address.high; |
Dan Williams | 4b33981 | 2011-05-06 17:36:38 -0700 | [diff] [blame] | 1346 | sci_sas_addr <<= 32; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1347 | sci_sas_addr |= oem->phys[index].sas_address.low; |
Dan Williams | 4b33981 | 2011-05-06 17:36:38 -0700 | [diff] [blame] | 1348 | sas_addr = cpu_to_be64(sci_sas_addr); |
| 1349 | memcpy(iphy->sas_addr, &sas_addr, sizeof(sas_addr)); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1350 | |
Dan Williams | 4b33981 | 2011-05-06 17:36:38 -0700 | [diff] [blame] | 1351 | iphy->sas_phy.enabled = 0; |
| 1352 | iphy->sas_phy.id = index; |
| 1353 | iphy->sas_phy.sas_addr = &iphy->sas_addr[0]; |
| 1354 | iphy->sas_phy.frame_rcvd = (u8 *)&iphy->frame_rcvd; |
| 1355 | iphy->sas_phy.ha = &ihost->sas_ha; |
| 1356 | iphy->sas_phy.lldd_phy = iphy; |
| 1357 | iphy->sas_phy.enabled = 1; |
| 1358 | iphy->sas_phy.class = SAS; |
| 1359 | iphy->sas_phy.iproto = SAS_PROTOCOL_ALL; |
| 1360 | iphy->sas_phy.tproto = 0; |
| 1361 | iphy->sas_phy.type = PHY_TYPE_PHYSICAL; |
| 1362 | iphy->sas_phy.role = PHY_ROLE_INITIATOR; |
| 1363 | iphy->sas_phy.oob_mode = OOB_NOT_CONNECTED; |
| 1364 | iphy->sas_phy.linkrate = SAS_LINK_RATE_UNKNOWN; |
| 1365 | memset(&iphy->frame_rcvd, 0, sizeof(iphy->frame_rcvd)); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1366 | } |
| 1367 | |
| 1368 | |
| 1369 | /** |
| 1370 | * isci_phy_control() - This function is one of the SAS Domain Template |
| 1371 | * functions. This is a phy management function. |
| 1372 | * @phy: This parameter specifies the sphy being controlled. |
| 1373 | * @func: This parameter specifies the phy control function being invoked. |
| 1374 | * @buf: This parameter is specific to the phy function being invoked. |
| 1375 | * |
| 1376 | * status, zero indicates success. |
| 1377 | */ |
Dave Jiang | 4d07f7f | 2011-03-02 12:31:24 -0800 | [diff] [blame] | 1378 | int isci_phy_control(struct asd_sas_phy *sas_phy, |
| 1379 | enum phy_func func, |
| 1380 | void *buf) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1381 | { |
Dave Jiang | 4d07f7f | 2011-03-02 12:31:24 -0800 | [diff] [blame] | 1382 | int ret = 0; |
| 1383 | struct isci_phy *iphy = sas_phy->lldd_phy; |
Dan Williams | c132f69 | 2012-01-03 23:26:08 -0800 | [diff] [blame] | 1384 | struct asd_sas_port *port = sas_phy->port; |
Dave Jiang | 4d07f7f | 2011-03-02 12:31:24 -0800 | [diff] [blame] | 1385 | struct isci_host *ihost = sas_phy->ha->lldd_ha; |
| 1386 | unsigned long flags; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1387 | |
Dave Jiang | 4d07f7f | 2011-03-02 12:31:24 -0800 | [diff] [blame] | 1388 | dev_dbg(&ihost->pdev->dev, |
| 1389 | "%s: phy %p; func %d; buf %p; isci phy %p, port %p\n", |
Dan Williams | c132f69 | 2012-01-03 23:26:08 -0800 | [diff] [blame] | 1390 | __func__, sas_phy, func, buf, iphy, port); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1391 | |
| 1392 | switch (func) { |
Dave Jiang | 4d07f7f | 2011-03-02 12:31:24 -0800 | [diff] [blame] | 1393 | case PHY_FUNC_DISABLE: |
| 1394 | spin_lock_irqsave(&ihost->scic_lock, flags); |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1395 | sci_phy_stop(iphy); |
Dave Jiang | 4d07f7f | 2011-03-02 12:31:24 -0800 | [diff] [blame] | 1396 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
| 1397 | break; |
| 1398 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1399 | case PHY_FUNC_LINK_RESET: |
Dave Jiang | 4d07f7f | 2011-03-02 12:31:24 -0800 | [diff] [blame] | 1400 | spin_lock_irqsave(&ihost->scic_lock, flags); |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1401 | sci_phy_stop(iphy); |
| 1402 | sci_phy_start(iphy); |
Dave Jiang | 4d07f7f | 2011-03-02 12:31:24 -0800 | [diff] [blame] | 1403 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
| 1404 | break; |
| 1405 | |
| 1406 | case PHY_FUNC_HARD_RESET: |
Dan Williams | c132f69 | 2012-01-03 23:26:08 -0800 | [diff] [blame] | 1407 | if (!port) |
Dave Jiang | 4d07f7f | 2011-03-02 12:31:24 -0800 | [diff] [blame] | 1408 | return -ENODEV; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1409 | |
Dan Williams | c132f69 | 2012-01-03 23:26:08 -0800 | [diff] [blame] | 1410 | ret = isci_port_perform_hard_reset(ihost, port->lldd_port, iphy); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1411 | |
| 1412 | break; |
Dan Williams | ac013ed | 2011-09-28 18:48:02 -0700 | [diff] [blame] | 1413 | case PHY_FUNC_GET_EVENTS: { |
| 1414 | struct scu_link_layer_registers __iomem *r; |
| 1415 | struct sas_phy *phy = sas_phy->phy; |
| 1416 | |
| 1417 | r = iphy->link_layer_registers; |
| 1418 | phy->running_disparity_error_count = readl(&r->running_disparity_error_count); |
| 1419 | phy->loss_of_dword_sync_count = readl(&r->loss_of_sync_error_count); |
| 1420 | phy->phy_reset_problem_count = readl(&r->phy_reset_problem_count); |
| 1421 | phy->invalid_dword_count = readl(&r->invalid_dword_counter); |
| 1422 | break; |
| 1423 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1424 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1425 | default: |
Dave Jiang | 4d07f7f | 2011-03-02 12:31:24 -0800 | [diff] [blame] | 1426 | dev_dbg(&ihost->pdev->dev, |
| 1427 | "%s: phy %p; func %d NOT IMPLEMENTED!\n", |
| 1428 | __func__, sas_phy, func); |
| 1429 | ret = -ENOSYS; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1430 | break; |
| 1431 | } |
| 1432 | return ret; |
| 1433 | } |