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