Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is provided under a dual BSD/GPLv2 license. When using or |
| 3 | * redistributing this file, you may do so under either license. |
| 4 | * |
| 5 | * GPL LICENSE SUMMARY |
| 6 | * |
| 7 | * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of version 2 of the GNU General Public License as |
| 11 | * published by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | * The full GNU General Public License is included in this distribution |
| 22 | * in the file called LICENSE.GPL. |
| 23 | * |
| 24 | * BSD LICENSE |
| 25 | * |
| 26 | * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. |
| 27 | * All rights reserved. |
| 28 | * |
| 29 | * Redistribution and use in source and binary forms, with or without |
| 30 | * modification, are permitted provided that the following conditions |
| 31 | * are met: |
| 32 | * |
| 33 | * * Redistributions of source code must retain the above copyright |
| 34 | * notice, this list of conditions and the following disclaimer. |
| 35 | * * Redistributions in binary form must reproduce the above copyright |
| 36 | * notice, this list of conditions and the following disclaimer in |
| 37 | * the documentation and/or other materials provided with the |
| 38 | * distribution. |
| 39 | * * Neither the name of Intel Corporation nor the names of its |
| 40 | * contributors may be used to endorse or promote products derived |
| 41 | * from this software without specific prior written permission. |
| 42 | * |
| 43 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 44 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 45 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 46 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 47 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 48 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 49 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 50 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 51 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 52 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 53 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 54 | */ |
| 55 | |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 56 | #include "host.h" |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 57 | |
| 58 | #define SCIC_SDS_MPC_RECONFIGURATION_TIMEOUT (10) |
| 59 | #define SCIC_SDS_APC_RECONFIGURATION_TIMEOUT (10) |
Dan Williams | 50a92d9 | 2012-02-29 01:07:56 -0800 | [diff] [blame] | 60 | #define SCIC_SDS_APC_WAIT_LINK_UP_NOTIFICATION (1000) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 61 | |
| 62 | enum SCIC_SDS_APC_ACTIVITY { |
| 63 | SCIC_SDS_APC_SKIP_PHY, |
| 64 | SCIC_SDS_APC_ADD_PHY, |
| 65 | SCIC_SDS_APC_START_TIMER, |
| 66 | |
| 67 | SCIC_SDS_APC_ACTIVITY_MAX |
| 68 | }; |
| 69 | |
| 70 | /* |
| 71 | * ****************************************************************************** |
| 72 | * General port configuration agent routines |
| 73 | * ****************************************************************************** */ |
| 74 | |
| 75 | /** |
| 76 | * |
| 77 | * @address_one: A SAS Address to be compared. |
| 78 | * @address_two: A SAS Address to be compared. |
| 79 | * |
| 80 | * Compare the two SAS Address and if SAS Address One is greater than SAS |
| 81 | * Address Two then return > 0 else if SAS Address One is less than SAS Address |
| 82 | * Two return < 0 Otherwise they are the same return 0 A signed value of x > 0 |
| 83 | * > y where x is returned for Address One > Address Two y is returned for |
| 84 | * Address One < Address Two 0 is returned ofr Address One = Address Two |
| 85 | */ |
| 86 | static s32 sci_sas_address_compare( |
| 87 | struct sci_sas_address address_one, |
| 88 | struct sci_sas_address address_two) |
| 89 | { |
| 90 | if (address_one.high > address_two.high) { |
| 91 | return 1; |
| 92 | } else if (address_one.high < address_two.high) { |
| 93 | return -1; |
| 94 | } else if (address_one.low > address_two.low) { |
| 95 | return 1; |
| 96 | } else if (address_one.low < address_two.low) { |
| 97 | return -1; |
| 98 | } |
| 99 | |
| 100 | /* The two SAS Address must be identical */ |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * |
| 106 | * @controller: The controller object used for the port search. |
| 107 | * @phy: The phy object to match. |
| 108 | * |
| 109 | * This routine will find a matching port for the phy. This means that the |
| 110 | * port and phy both have the same broadcast sas address and same received sas |
Edmund Nadolski | a7e536c | 2011-02-08 09:28:42 -0700 | [diff] [blame] | 111 | * address. The port address or the NULL if there is no matching |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 112 | * port. port address if the port can be found to match the phy. |
Edmund Nadolski | a7e536c | 2011-02-08 09:28:42 -0700 | [diff] [blame] | 113 | * NULL if there is no matching port for the phy. |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 114 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 115 | static struct isci_port *sci_port_configuration_agent_find_port( |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 116 | struct isci_host *ihost, |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 117 | struct isci_phy *iphy) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 118 | { |
Edmund Nadolski | ed30c27 | 2011-05-05 01:11:43 +0000 | [diff] [blame] | 119 | u8 i; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 120 | struct sci_sas_address port_sas_address; |
| 121 | struct sci_sas_address port_attached_device_address; |
| 122 | struct sci_sas_address phy_sas_address; |
| 123 | struct sci_sas_address phy_attached_device_address; |
| 124 | |
| 125 | /* |
| 126 | * Since this phy can be a member of a wide port check to see if one or |
| 127 | * more phys match the sent and received SAS address as this phy in which |
Edmund Nadolski | ed30c27 | 2011-05-05 01:11:43 +0000 | [diff] [blame] | 128 | * case it should participate in the same port. |
| 129 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 130 | sci_phy_get_sas_address(iphy, &phy_sas_address); |
| 131 | sci_phy_get_attached_sas_address(iphy, &phy_attached_device_address); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 132 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 133 | for (i = 0; i < ihost->logical_port_entries; i++) { |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 134 | struct isci_port *iport = &ihost->ports[i]; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 135 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 136 | sci_port_get_sas_address(iport, &port_sas_address); |
| 137 | sci_port_get_attached_sas_address(iport, &port_attached_device_address); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 138 | |
Dan Williams | e531381 | 2011-05-07 10:11:43 -0700 | [diff] [blame] | 139 | if (sci_sas_address_compare(port_sas_address, phy_sas_address) == 0 && |
| 140 | sci_sas_address_compare(port_attached_device_address, phy_attached_device_address) == 0) |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 141 | return iport; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Edmund Nadolski | a7e536c | 2011-02-08 09:28:42 -0700 | [diff] [blame] | 144 | return NULL; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | /** |
| 148 | * |
| 149 | * @controller: This is the controller object that contains the port agent |
| 150 | * @port_agent: This is the port configruation agent for the controller. |
| 151 | * |
| 152 | * This routine will validate the port configuration is correct for the SCU |
| 153 | * hardware. The SCU hardware allows for port configurations as follows. LP0 |
| 154 | * -> (PE0), (PE0, PE1), (PE0, PE1, PE2, PE3) LP1 -> (PE1) LP2 -> (PE2), (PE2, |
| 155 | * PE3) LP3 -> (PE3) enum sci_status SCI_SUCCESS the port configuration is valid for |
| 156 | * this port configuration agent. SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION |
| 157 | * the port configuration is not valid for this port configuration agent. |
| 158 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 159 | static enum sci_status sci_port_configuration_agent_validate_ports( |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 160 | struct isci_host *ihost, |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 161 | struct sci_port_configuration_agent *port_agent) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 162 | { |
| 163 | struct sci_sas_address first_address; |
| 164 | struct sci_sas_address second_address; |
| 165 | |
| 166 | /* |
| 167 | * Sanity check the max ranges for all the phys the max index |
| 168 | * is always equal to the port range index */ |
Dan Williams | 4b33981 | 2011-05-06 17:36:38 -0700 | [diff] [blame] | 169 | if (port_agent->phy_valid_port_range[0].max_index != 0 || |
| 170 | port_agent->phy_valid_port_range[1].max_index != 1 || |
| 171 | port_agent->phy_valid_port_range[2].max_index != 2 || |
| 172 | port_agent->phy_valid_port_range[3].max_index != 3) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 173 | return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 174 | |
| 175 | /* |
| 176 | * This is a request to configure a single x4 port or at least attempt |
| 177 | * to make all the phys into a single port */ |
Dan Williams | 4b33981 | 2011-05-06 17:36:38 -0700 | [diff] [blame] | 178 | if (port_agent->phy_valid_port_range[0].min_index == 0 && |
| 179 | port_agent->phy_valid_port_range[1].min_index == 0 && |
| 180 | port_agent->phy_valid_port_range[2].min_index == 0 && |
| 181 | port_agent->phy_valid_port_range[3].min_index == 0) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 182 | return SCI_SUCCESS; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 183 | |
| 184 | /* |
| 185 | * This is a degenerate case where phy 1 and phy 2 are assigned |
| 186 | * to the same port this is explicitly disallowed by the hardware |
| 187 | * unless they are part of the same x4 port and this condition was |
| 188 | * already checked above. */ |
| 189 | if (port_agent->phy_valid_port_range[2].min_index == 1) { |
| 190 | return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION; |
| 191 | } |
| 192 | |
| 193 | /* |
| 194 | * PE0 and PE3 can never have the same SAS Address unless they |
| 195 | * are part of the same x4 wide port and we have already checked |
| 196 | * for this condition. */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 197 | sci_phy_get_sas_address(&ihost->phys[0], &first_address); |
| 198 | sci_phy_get_sas_address(&ihost->phys[3], &second_address); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 199 | |
| 200 | if (sci_sas_address_compare(first_address, second_address) == 0) { |
| 201 | return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION; |
| 202 | } |
| 203 | |
| 204 | /* |
| 205 | * PE0 and PE1 are configured into a 2x1 ports make sure that the |
| 206 | * SAS Address for PE0 and PE2 are different since they can not be |
| 207 | * part of the same port. */ |
Dan Williams | 4b33981 | 2011-05-06 17:36:38 -0700 | [diff] [blame] | 208 | if (port_agent->phy_valid_port_range[0].min_index == 0 && |
| 209 | port_agent->phy_valid_port_range[1].min_index == 1) { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 210 | sci_phy_get_sas_address(&ihost->phys[0], &first_address); |
| 211 | sci_phy_get_sas_address(&ihost->phys[2], &second_address); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 212 | |
| 213 | if (sci_sas_address_compare(first_address, second_address) == 0) { |
| 214 | return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | /* |
| 219 | * PE2 and PE3 are configured into a 2x1 ports make sure that the |
| 220 | * SAS Address for PE1 and PE3 are different since they can not be |
| 221 | * part of the same port. */ |
Dan Williams | 4b33981 | 2011-05-06 17:36:38 -0700 | [diff] [blame] | 222 | if (port_agent->phy_valid_port_range[2].min_index == 2 && |
| 223 | port_agent->phy_valid_port_range[3].min_index == 3) { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 224 | sci_phy_get_sas_address(&ihost->phys[1], &first_address); |
| 225 | sci_phy_get_sas_address(&ihost->phys[3], &second_address); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 226 | |
| 227 | if (sci_sas_address_compare(first_address, second_address) == 0) { |
| 228 | return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION; |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | return SCI_SUCCESS; |
| 233 | } |
| 234 | |
| 235 | /* |
| 236 | * ****************************************************************************** |
| 237 | * Manual port configuration agent routines |
| 238 | * ****************************************************************************** */ |
| 239 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 240 | /* verify all of the phys in the same port are using the same SAS address */ |
| 241 | static enum sci_status |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 242 | sci_mpc_agent_validate_phy_configuration(struct isci_host *ihost, |
| 243 | struct sci_port_configuration_agent *port_agent) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 244 | { |
| 245 | u32 phy_mask; |
| 246 | u32 assigned_phy_mask; |
| 247 | struct sci_sas_address sas_address; |
| 248 | struct sci_sas_address phy_assigned_address; |
| 249 | u8 port_index; |
| 250 | u8 phy_index; |
| 251 | |
| 252 | assigned_phy_mask = 0; |
| 253 | sas_address.high = 0; |
| 254 | sas_address.low = 0; |
| 255 | |
| 256 | for (port_index = 0; port_index < SCI_MAX_PORTS; port_index++) { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 257 | phy_mask = ihost->oem_parameters.ports[port_index].phy_mask; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 258 | |
Dan Williams | 4b33981 | 2011-05-06 17:36:38 -0700 | [diff] [blame] | 259 | if (!phy_mask) |
| 260 | continue; |
| 261 | /* |
| 262 | * Make sure that one or more of the phys were not already assinged to |
| 263 | * a different port. */ |
| 264 | if ((phy_mask & ~assigned_phy_mask) == 0) { |
| 265 | return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION; |
| 266 | } |
| 267 | |
| 268 | /* Find the starting phy index for this round through the loop */ |
| 269 | for (phy_index = 0; phy_index < SCI_MAX_PHYS; phy_index++) { |
| 270 | if ((phy_mask & (1 << phy_index)) == 0) |
| 271 | continue; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 272 | sci_phy_get_sas_address(&ihost->phys[phy_index], |
Dan Williams | 4b33981 | 2011-05-06 17:36:38 -0700 | [diff] [blame] | 273 | &sas_address); |
| 274 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 275 | /* |
Dan Williams | 4b33981 | 2011-05-06 17:36:38 -0700 | [diff] [blame] | 276 | * The phy_index can be used as the starting point for the |
| 277 | * port range since the hardware starts all logical ports |
| 278 | * the same as the PE index. */ |
| 279 | port_agent->phy_valid_port_range[phy_index].min_index = port_index; |
| 280 | port_agent->phy_valid_port_range[phy_index].max_index = phy_index; |
| 281 | |
| 282 | if (phy_index != port_index) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 283 | return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION; |
| 284 | } |
| 285 | |
Dan Williams | 4b33981 | 2011-05-06 17:36:38 -0700 | [diff] [blame] | 286 | break; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 287 | } |
Dan Williams | 4b33981 | 2011-05-06 17:36:38 -0700 | [diff] [blame] | 288 | |
| 289 | /* |
| 290 | * See how many additional phys are being added to this logical port. |
| 291 | * Note: We have not moved the current phy_index so we will actually |
| 292 | * compare the startting phy with itself. |
| 293 | * This is expected and required to add the phy to the port. */ |
Colin Ian King | 4bc83b3 | 2018-04-20 10:57:16 +0100 | [diff] [blame] | 294 | for (; phy_index < SCI_MAX_PHYS; phy_index++) { |
Dan Williams | 4b33981 | 2011-05-06 17:36:38 -0700 | [diff] [blame] | 295 | if ((phy_mask & (1 << phy_index)) == 0) |
| 296 | continue; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 297 | sci_phy_get_sas_address(&ihost->phys[phy_index], |
Dan Williams | 4b33981 | 2011-05-06 17:36:38 -0700 | [diff] [blame] | 298 | &phy_assigned_address); |
| 299 | |
| 300 | if (sci_sas_address_compare(sas_address, phy_assigned_address) != 0) { |
| 301 | /* |
| 302 | * The phy mask specified that this phy is part of the same port |
| 303 | * as the starting phy and it is not so fail this configuration */ |
| 304 | return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION; |
| 305 | } |
| 306 | |
| 307 | port_agent->phy_valid_port_range[phy_index].min_index = port_index; |
| 308 | port_agent->phy_valid_port_range[phy_index].max_index = phy_index; |
| 309 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 310 | sci_port_add_phy(&ihost->ports[port_index], |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 311 | &ihost->phys[phy_index]); |
Dan Williams | 4b33981 | 2011-05-06 17:36:38 -0700 | [diff] [blame] | 312 | |
| 313 | assigned_phy_mask |= (1 << phy_index); |
| 314 | } |
| 315 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 318 | return sci_port_configuration_agent_validate_ports(ihost, port_agent); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Kees Cook | b0a2dc6 | 2017-09-01 23:21:24 -0700 | [diff] [blame] | 321 | static void mpc_agent_timeout(struct timer_list *t) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 322 | { |
| 323 | u8 index; |
Kees Cook | b0a2dc6 | 2017-09-01 23:21:24 -0700 | [diff] [blame] | 324 | struct sci_timer *tmr = from_timer(tmr, t, timer); |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 325 | struct sci_port_configuration_agent *port_agent; |
Edmund Nadolski | ac0eeb4 | 2011-05-19 20:00:51 -0700 | [diff] [blame] | 326 | struct isci_host *ihost; |
| 327 | unsigned long flags; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 328 | u16 configure_phy_mask; |
| 329 | |
Edmund Nadolski | ac0eeb4 | 2011-05-19 20:00:51 -0700 | [diff] [blame] | 330 | port_agent = container_of(tmr, typeof(*port_agent), timer); |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 331 | ihost = container_of(port_agent, typeof(*ihost), port_agent); |
Edmund Nadolski | ac0eeb4 | 2011-05-19 20:00:51 -0700 | [diff] [blame] | 332 | |
| 333 | spin_lock_irqsave(&ihost->scic_lock, flags); |
| 334 | |
| 335 | if (tmr->cancel) |
| 336 | goto done; |
| 337 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 338 | port_agent->timer_pending = false; |
| 339 | |
| 340 | /* Find the mask of phys that are reported read but as yet unconfigured into a port */ |
| 341 | configure_phy_mask = ~port_agent->phy_configured_mask & port_agent->phy_ready_mask; |
| 342 | |
| 343 | for (index = 0; index < SCI_MAX_PHYS; index++) { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 344 | struct isci_phy *iphy = &ihost->phys[index]; |
Dan Williams | 4b33981 | 2011-05-06 17:36:38 -0700 | [diff] [blame] | 345 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 346 | if (configure_phy_mask & (1 << index)) { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 347 | port_agent->link_up_handler(ihost, port_agent, |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 348 | phy_get_non_dummy_port(iphy), |
| 349 | iphy); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 350 | } |
| 351 | } |
Edmund Nadolski | ac0eeb4 | 2011-05-19 20:00:51 -0700 | [diff] [blame] | 352 | |
| 353 | done: |
| 354 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 355 | } |
| 356 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 357 | static void sci_mpc_agent_link_up(struct isci_host *ihost, |
| 358 | struct sci_port_configuration_agent *port_agent, |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 359 | struct isci_port *iport, |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 360 | struct isci_phy *iphy) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 361 | { |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 362 | /* If the port is NULL then the phy was not assigned to a port. |
| 363 | * This is because the phy was not given the same SAS Address as |
| 364 | * the other PHYs in the port. |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 365 | */ |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 366 | if (!iport) |
| 367 | return; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 368 | |
Dan Williams | 34a9915 | 2011-07-01 02:25:15 -0700 | [diff] [blame] | 369 | port_agent->phy_ready_mask |= (1 << iphy->phy_index); |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 370 | sci_port_link_up(iport, iphy); |
Dan Williams | 34a9915 | 2011-07-01 02:25:15 -0700 | [diff] [blame] | 371 | if ((iport->active_phy_mask & (1 << iphy->phy_index))) |
| 372 | port_agent->phy_configured_mask |= (1 << iphy->phy_index); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | /** |
| 376 | * |
| 377 | * @controller: This is the controller object that receives the link down |
| 378 | * notification. |
| 379 | * @port: This is the port object associated with the phy. If the is no |
Edmund Nadolski | a7e536c | 2011-02-08 09:28:42 -0700 | [diff] [blame] | 380 | * associated port this is an NULL. The port is an invalid |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 381 | * handle only if the phy was never port of this port. This happens when |
| 382 | * the phy is not broadcasting the same SAS address as the other phys in the |
| 383 | * assigned port. |
| 384 | * @phy: This is the phy object which has gone link down. |
| 385 | * |
Dave Jiang | 09d7da1 | 2011-03-26 16:11:51 -0700 | [diff] [blame] | 386 | * This function handles the manual port configuration link down notifications. |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 387 | * Since all ports and phys are associated at initialization time we just turn |
| 388 | * around and notifiy the port object of the link down event. If this PHY is |
| 389 | * not associated with a port there is no action taken. Is it possible to get a |
| 390 | * link down notification from a phy that has no assocoated port? |
| 391 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 392 | static void sci_mpc_agent_link_down( |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 393 | struct isci_host *ihost, |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 394 | struct sci_port_configuration_agent *port_agent, |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 395 | struct isci_port *iport, |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 396 | struct isci_phy *iphy) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 397 | { |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 398 | if (iport != NULL) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 399 | /* |
Dave Jiang | 09d7da1 | 2011-03-26 16:11:51 -0700 | [diff] [blame] | 400 | * If we can form a new port from the remainder of the phys |
| 401 | * then we want to start the timer to allow the SCI User to |
| 402 | * cleanup old devices and rediscover the port before |
| 403 | * rebuilding the port with the phys that remain in the ready |
| 404 | * state. |
| 405 | */ |
Dan Williams | 34a9915 | 2011-07-01 02:25:15 -0700 | [diff] [blame] | 406 | port_agent->phy_ready_mask &= ~(1 << iphy->phy_index); |
| 407 | port_agent->phy_configured_mask &= ~(1 << iphy->phy_index); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 408 | |
| 409 | /* |
Dave Jiang | 09d7da1 | 2011-03-26 16:11:51 -0700 | [diff] [blame] | 410 | * Check to see if there are more phys waiting to be |
| 411 | * configured into a port. If there are allow the SCI User |
| 412 | * to tear down this port, if necessary, and then reconstruct |
| 413 | * the port after the timeout. |
| 414 | */ |
| 415 | if ((port_agent->phy_configured_mask == 0x0000) && |
| 416 | (port_agent->phy_ready_mask != 0x0000) && |
| 417 | !port_agent->timer_pending) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 418 | port_agent->timer_pending = true; |
| 419 | |
Edmund Nadolski | ac0eeb4 | 2011-05-19 20:00:51 -0700 | [diff] [blame] | 420 | sci_mod_timer(&port_agent->timer, |
| 421 | SCIC_SDS_MPC_RECONFIGURATION_TIMEOUT); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 422 | } |
| 423 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 424 | sci_port_link_down(iport, iphy); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 425 | } |
| 426 | } |
| 427 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 428 | /* verify phys are assigned a valid SAS address for automatic port |
| 429 | * configuration mode. |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 430 | */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 431 | static enum sci_status |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 432 | sci_apc_agent_validate_phy_configuration(struct isci_host *ihost, |
| 433 | struct sci_port_configuration_agent *port_agent) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 434 | { |
| 435 | u8 phy_index; |
| 436 | u8 port_index; |
| 437 | struct sci_sas_address sas_address; |
| 438 | struct sci_sas_address phy_assigned_address; |
| 439 | |
| 440 | phy_index = 0; |
| 441 | |
| 442 | while (phy_index < SCI_MAX_PHYS) { |
| 443 | port_index = phy_index; |
| 444 | |
| 445 | /* Get the assigned SAS Address for the first PHY on the controller. */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 446 | sci_phy_get_sas_address(&ihost->phys[phy_index], |
Dan Williams | 4b33981 | 2011-05-06 17:36:38 -0700 | [diff] [blame] | 447 | &sas_address); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 448 | |
| 449 | while (++phy_index < SCI_MAX_PHYS) { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 450 | sci_phy_get_sas_address(&ihost->phys[phy_index], |
Dan Williams | 4b33981 | 2011-05-06 17:36:38 -0700 | [diff] [blame] | 451 | &phy_assigned_address); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 452 | |
| 453 | /* Verify each of the SAS address are all the same for every PHY */ |
| 454 | if (sci_sas_address_compare(sas_address, phy_assigned_address) == 0) { |
| 455 | port_agent->phy_valid_port_range[phy_index].min_index = port_index; |
| 456 | port_agent->phy_valid_port_range[phy_index].max_index = phy_index; |
| 457 | } else { |
| 458 | port_agent->phy_valid_port_range[phy_index].min_index = phy_index; |
| 459 | port_agent->phy_valid_port_range[phy_index].max_index = phy_index; |
| 460 | break; |
| 461 | } |
| 462 | } |
| 463 | } |
| 464 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 465 | return sci_port_configuration_agent_validate_ports(ihost, port_agent); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 466 | } |
| 467 | |
Marcin Tomczak | be77834 | 2012-01-04 01:33:31 -0800 | [diff] [blame] | 468 | /* |
| 469 | * This routine will restart the automatic port configuration timeout |
| 470 | * timer for the next time period. This could be caused by either a link |
| 471 | * down event or a link up event where we can not yet tell to which a phy |
| 472 | * belongs. |
| 473 | */ |
Dan Williams | 50a92d9 | 2012-02-29 01:07:56 -0800 | [diff] [blame] | 474 | static void sci_apc_agent_start_timer(struct sci_port_configuration_agent *port_agent, |
| 475 | u32 timeout) |
Marcin Tomczak | be77834 | 2012-01-04 01:33:31 -0800 | [diff] [blame] | 476 | { |
Marcin Tomczak | be77834 | 2012-01-04 01:33:31 -0800 | [diff] [blame] | 477 | port_agent->timer_pending = true; |
| 478 | sci_mod_timer(&port_agent->timer, timeout); |
| 479 | } |
| 480 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 481 | static void sci_apc_agent_configure_ports(struct isci_host *ihost, |
| 482 | struct sci_port_configuration_agent *port_agent, |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 483 | struct isci_phy *iphy, |
| 484 | bool start_timer) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 485 | { |
| 486 | u8 port_index; |
| 487 | enum sci_status status; |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 488 | struct isci_port *iport; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 489 | enum SCIC_SDS_APC_ACTIVITY apc_activity = SCIC_SDS_APC_SKIP_PHY; |
| 490 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 491 | iport = sci_port_configuration_agent_find_port(ihost, iphy); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 492 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 493 | if (iport) { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 494 | if (sci_port_is_valid_phy_assignment(iport, iphy->phy_index)) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 495 | apc_activity = SCIC_SDS_APC_ADD_PHY; |
| 496 | else |
| 497 | apc_activity = SCIC_SDS_APC_SKIP_PHY; |
| 498 | } else { |
| 499 | /* |
| 500 | * There is no matching Port for this PHY so lets search through the |
| 501 | * Ports and see if we can add the PHY to its own port or maybe start |
| 502 | * the timer and wait to see if a wider port can be made. |
| 503 | * |
| 504 | * Note the break when we reach the condition of the port id == phy id */ |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 505 | for (port_index = port_agent->phy_valid_port_range[iphy->phy_index].min_index; |
| 506 | port_index <= port_agent->phy_valid_port_range[iphy->phy_index].max_index; |
| 507 | port_index++) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 508 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 509 | iport = &ihost->ports[port_index]; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 510 | |
| 511 | /* First we must make sure that this PHY can be added to this Port. */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 512 | if (sci_port_is_valid_phy_assignment(iport, iphy->phy_index)) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 513 | /* |
| 514 | * Port contains a PHY with a greater PHY ID than the current |
| 515 | * PHY that has gone link up. This phy can not be part of any |
| 516 | * port so skip it and move on. */ |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 517 | if (iport->active_phy_mask > (1 << iphy->phy_index)) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 518 | apc_activity = SCIC_SDS_APC_SKIP_PHY; |
| 519 | break; |
| 520 | } |
| 521 | |
| 522 | /* |
| 523 | * We have reached the end of our Port list and have not found |
| 524 | * any reason why we should not either add the PHY to the port |
| 525 | * or wait for more phys to become active. */ |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 526 | if (iport->physical_port_index == iphy->phy_index) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 527 | /* |
| 528 | * The Port either has no active PHYs. |
| 529 | * Consider that if the port had any active PHYs we would have |
| 530 | * or active PHYs with |
| 531 | * a lower PHY Id than this PHY. */ |
| 532 | if (apc_activity != SCIC_SDS_APC_START_TIMER) { |
| 533 | apc_activity = SCIC_SDS_APC_ADD_PHY; |
| 534 | } |
| 535 | |
| 536 | break; |
| 537 | } |
| 538 | |
| 539 | /* |
| 540 | * The current Port has no active PHYs and this PHY could be part |
| 541 | * of this Port. Since we dont know as yet setup to start the |
| 542 | * timer and see if there is a better configuration. */ |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 543 | if (iport->active_phy_mask == 0) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 544 | apc_activity = SCIC_SDS_APC_START_TIMER; |
| 545 | } |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 546 | } else if (iport->active_phy_mask != 0) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 547 | /* |
| 548 | * The Port has an active phy and the current Phy can not |
| 549 | * participate in this port so skip the PHY and see if |
| 550 | * there is a better configuration. */ |
| 551 | apc_activity = SCIC_SDS_APC_SKIP_PHY; |
| 552 | } |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | /* |
| 557 | * Check to see if the start timer operations should instead map to an |
| 558 | * add phy operation. This is caused because we have been waiting to |
| 559 | * add a phy to a port but could not becuase the automatic port |
| 560 | * configuration engine had a choice of possible ports for the phy. |
| 561 | * Since we have gone through a timeout we are going to restrict the |
| 562 | * choice to the smallest possible port. */ |
| 563 | if ( |
| 564 | (start_timer == false) |
| 565 | && (apc_activity == SCIC_SDS_APC_START_TIMER) |
| 566 | ) { |
| 567 | apc_activity = SCIC_SDS_APC_ADD_PHY; |
| 568 | } |
| 569 | |
| 570 | switch (apc_activity) { |
| 571 | case SCIC_SDS_APC_ADD_PHY: |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 572 | status = sci_port_add_phy(iport, iphy); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 573 | |
| 574 | if (status == SCI_SUCCESS) { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 575 | port_agent->phy_configured_mask |= (1 << iphy->phy_index); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 576 | } |
| 577 | break; |
| 578 | |
| 579 | case SCIC_SDS_APC_START_TIMER: |
Marcin Tomczak | be77834 | 2012-01-04 01:33:31 -0800 | [diff] [blame] | 580 | sci_apc_agent_start_timer(port_agent, |
| 581 | SCIC_SDS_APC_WAIT_LINK_UP_NOTIFICATION); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 582 | break; |
| 583 | |
| 584 | case SCIC_SDS_APC_SKIP_PHY: |
| 585 | default: |
| 586 | /* do nothing the PHY can not be made part of a port at this time. */ |
| 587 | break; |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | /** |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 592 | * sci_apc_agent_link_up - handle apc link up events |
Piotr Sawicki | b382429 | 2011-02-23 00:09:14 -0800 | [diff] [blame] | 593 | * @scic: This is the controller object that receives the link up |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 594 | * notification. |
Piotr Sawicki | b382429 | 2011-02-23 00:09:14 -0800 | [diff] [blame] | 595 | * @sci_port: This is the port object associated with the phy. If the is no |
Edmund Nadolski | a7e536c | 2011-02-08 09:28:42 -0700 | [diff] [blame] | 596 | * associated port this is an NULL. |
Piotr Sawicki | b382429 | 2011-02-23 00:09:14 -0800 | [diff] [blame] | 597 | * @sci_phy: This is the phy object which has gone link up. |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 598 | * |
| 599 | * This method handles the automatic port configuration for link up |
| 600 | * notifications. Is it possible to get a link down notification from a phy |
| 601 | * that has no assocoated port? |
| 602 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 603 | static void sci_apc_agent_link_up(struct isci_host *ihost, |
| 604 | struct sci_port_configuration_agent *port_agent, |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 605 | struct isci_port *iport, |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 606 | struct isci_phy *iphy) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 607 | { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 608 | u8 phy_index = iphy->phy_index; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 609 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 610 | if (!iport) { |
Piotr Sawicki | b382429 | 2011-02-23 00:09:14 -0800 | [diff] [blame] | 611 | /* the phy is not the part of this port */ |
| 612 | port_agent->phy_ready_mask |= 1 << phy_index; |
Marcin Tomczak | be77834 | 2012-01-04 01:33:31 -0800 | [diff] [blame] | 613 | sci_apc_agent_start_timer(port_agent, |
| 614 | SCIC_SDS_APC_WAIT_LINK_UP_NOTIFICATION); |
Piotr Sawicki | b382429 | 2011-02-23 00:09:14 -0800 | [diff] [blame] | 615 | } else { |
| 616 | /* the phy is already the part of the port */ |
Piotr Sawicki | b382429 | 2011-02-23 00:09:14 -0800 | [diff] [blame] | 617 | port_agent->phy_ready_mask |= 1 << phy_index; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 618 | sci_port_link_up(iport, iphy); |
Piotr Sawicki | b382429 | 2011-02-23 00:09:14 -0800 | [diff] [blame] | 619 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | /** |
| 623 | * |
| 624 | * @controller: This is the controller object that receives the link down |
| 625 | * notification. |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 626 | * @iport: This is the port object associated with the phy. If the is no |
Edmund Nadolski | a7e536c | 2011-02-08 09:28:42 -0700 | [diff] [blame] | 627 | * associated port this is an NULL. |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 628 | * @iphy: This is the phy object which has gone link down. |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 629 | * |
| 630 | * This method handles the automatic port configuration link down |
| 631 | * notifications. not associated with a port there is no action taken. Is it |
| 632 | * possible to get a link down notification from a phy that has no assocoated |
| 633 | * port? |
| 634 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 635 | static void sci_apc_agent_link_down( |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 636 | struct isci_host *ihost, |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 637 | struct sci_port_configuration_agent *port_agent, |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 638 | struct isci_port *iport, |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 639 | struct isci_phy *iphy) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 640 | { |
Dan Williams | 34a9915 | 2011-07-01 02:25:15 -0700 | [diff] [blame] | 641 | port_agent->phy_ready_mask &= ~(1 << iphy->phy_index); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 642 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 643 | if (!iport) |
| 644 | return; |
| 645 | if (port_agent->phy_configured_mask & (1 << iphy->phy_index)) { |
| 646 | enum sci_status status; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 647 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 648 | status = sci_port_remove_phy(iport, iphy); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 649 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 650 | if (status == SCI_SUCCESS) |
| 651 | port_agent->phy_configured_mask &= ~(1 << iphy->phy_index); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 652 | } |
| 653 | } |
| 654 | |
Dan Williams | 4b33981 | 2011-05-06 17:36:38 -0700 | [diff] [blame] | 655 | /* configure the phys into ports when the timer fires */ |
Kees Cook | b0a2dc6 | 2017-09-01 23:21:24 -0700 | [diff] [blame] | 656 | static void apc_agent_timeout(struct timer_list *t) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 657 | { |
| 658 | u32 index; |
Kees Cook | b0a2dc6 | 2017-09-01 23:21:24 -0700 | [diff] [blame] | 659 | struct sci_timer *tmr = from_timer(tmr, t, timer); |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 660 | struct sci_port_configuration_agent *port_agent; |
Edmund Nadolski | ac0eeb4 | 2011-05-19 20:00:51 -0700 | [diff] [blame] | 661 | struct isci_host *ihost; |
| 662 | unsigned long flags; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 663 | u16 configure_phy_mask; |
| 664 | |
Edmund Nadolski | ac0eeb4 | 2011-05-19 20:00:51 -0700 | [diff] [blame] | 665 | port_agent = container_of(tmr, typeof(*port_agent), timer); |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 666 | ihost = container_of(port_agent, typeof(*ihost), port_agent); |
Edmund Nadolski | ac0eeb4 | 2011-05-19 20:00:51 -0700 | [diff] [blame] | 667 | |
| 668 | spin_lock_irqsave(&ihost->scic_lock, flags); |
| 669 | |
| 670 | if (tmr->cancel) |
| 671 | goto done; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 672 | |
| 673 | port_agent->timer_pending = false; |
| 674 | |
| 675 | configure_phy_mask = ~port_agent->phy_configured_mask & port_agent->phy_ready_mask; |
| 676 | |
Dan Williams | 4b33981 | 2011-05-06 17:36:38 -0700 | [diff] [blame] | 677 | if (!configure_phy_mask) |
Jeff Skirvin | 983d3fd | 2011-09-28 18:35:32 -0700 | [diff] [blame] | 678 | goto done; |
Dan Williams | 4b33981 | 2011-05-06 17:36:38 -0700 | [diff] [blame] | 679 | |
| 680 | for (index = 0; index < SCI_MAX_PHYS; index++) { |
| 681 | if ((configure_phy_mask & (1 << index)) == 0) |
| 682 | continue; |
| 683 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 684 | sci_apc_agent_configure_ports(ihost, port_agent, |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 685 | &ihost->phys[index], false); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 686 | } |
Edmund Nadolski | ac0eeb4 | 2011-05-19 20:00:51 -0700 | [diff] [blame] | 687 | |
Dan Williams | 50a92d9 | 2012-02-29 01:07:56 -0800 | [diff] [blame] | 688 | if (is_controller_start_complete(ihost)) |
| 689 | sci_controller_transition_to_ready(ihost, SCI_SUCCESS); |
| 690 | |
Edmund Nadolski | ac0eeb4 | 2011-05-19 20:00:51 -0700 | [diff] [blame] | 691 | done: |
| 692 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | /* |
| 696 | * ****************************************************************************** |
| 697 | * Public port configuration agent routines |
| 698 | * ****************************************************************************** */ |
| 699 | |
| 700 | /** |
| 701 | * |
| 702 | * |
| 703 | * This method will construct the port configuration agent for operation. This |
| 704 | * call is universal for both manual port configuration and automatic port |
| 705 | * configuration modes. |
| 706 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 707 | void sci_port_configuration_agent_construct( |
| 708 | struct sci_port_configuration_agent *port_agent) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 709 | { |
| 710 | u32 index; |
| 711 | |
| 712 | port_agent->phy_configured_mask = 0x00; |
| 713 | port_agent->phy_ready_mask = 0x00; |
| 714 | |
| 715 | port_agent->link_up_handler = NULL; |
| 716 | port_agent->link_down_handler = NULL; |
| 717 | |
| 718 | port_agent->timer_pending = false; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 719 | |
| 720 | for (index = 0; index < SCI_MAX_PORTS; index++) { |
| 721 | port_agent->phy_valid_port_range[index].min_index = 0; |
| 722 | port_agent->phy_valid_port_range[index].max_index = 0; |
| 723 | } |
| 724 | } |
| 725 | |
Dan Williams | 50a92d9 | 2012-02-29 01:07:56 -0800 | [diff] [blame] | 726 | bool is_port_config_apc(struct isci_host *ihost) |
| 727 | { |
| 728 | return ihost->port_agent.link_up_handler == sci_apc_agent_link_up; |
| 729 | } |
| 730 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 731 | enum sci_status sci_port_configuration_agent_initialize( |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 732 | struct isci_host *ihost, |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 733 | struct sci_port_configuration_agent *port_agent) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 734 | { |
Edmund Nadolski | ac0eeb4 | 2011-05-19 20:00:51 -0700 | [diff] [blame] | 735 | enum sci_status status; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 736 | enum sci_port_configuration_mode mode; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 737 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 738 | mode = ihost->oem_parameters.controller.mode_type; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 739 | |
| 740 | if (mode == SCIC_PORT_MANUAL_CONFIGURATION_MODE) { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 741 | status = sci_mpc_agent_validate_phy_configuration( |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 742 | ihost, port_agent); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 743 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 744 | port_agent->link_up_handler = sci_mpc_agent_link_up; |
| 745 | port_agent->link_down_handler = sci_mpc_agent_link_down; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 746 | |
Edmund Nadolski | ac0eeb4 | 2011-05-19 20:00:51 -0700 | [diff] [blame] | 747 | sci_init_timer(&port_agent->timer, mpc_agent_timeout); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 748 | } else { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 749 | status = sci_apc_agent_validate_phy_configuration( |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 750 | ihost, port_agent); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 751 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 752 | port_agent->link_up_handler = sci_apc_agent_link_up; |
| 753 | port_agent->link_down_handler = sci_apc_agent_link_down; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 754 | |
Edmund Nadolski | ac0eeb4 | 2011-05-19 20:00:51 -0700 | [diff] [blame] | 755 | sci_init_timer(&port_agent->timer, apc_agent_timeout); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | return status; |
| 759 | } |