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