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