Commit | Line | Data |
---|---|---|
6f231dda DW |
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 | ||
6f231dda DW |
56 | #include "scic_controller.h" |
57 | #include "scic_phy.h" | |
58 | #include "scic_port.h" | |
59 | #include "scic_sds_controller.h" | |
60 | #include "scic_sds_phy.h" | |
6f231dda | 61 | #include "scic_sds_port.h" |
88f3b62a DW |
62 | #include "remote_device.h" |
63 | #include "remote_node_context.h" | |
6f231dda | 64 | #include "scic_sds_request.h" |
6f231dda | 65 | #include "sci_environment.h" |
bc99aa47 | 66 | #include "scu_registers.h" |
6f231dda | 67 | |
6f231dda DW |
68 | #define SCIC_SDS_PORT_MIN_TIMER_COUNT (SCI_MAX_PORTS) |
69 | #define SCIC_SDS_PORT_MAX_TIMER_COUNT (SCI_MAX_PORTS) | |
70 | ||
71 | #define SCIC_SDS_PORT_HARD_RESET_TIMEOUT (1000) | |
a8d4b9fe | 72 | #define SCU_DUMMY_INDEX (0xFFFF) |
6f231dda | 73 | |
6f231dda DW |
74 | |
75 | /** | |
76 | * | |
e2023b87 | 77 | * @sci_port: This is the port object to which the phy is being assigned. |
6f231dda DW |
78 | * @phy_index: This is the phy index that is being assigned to the port. |
79 | * | |
80 | * This method will return a true value if the specified phy can be assigned to | |
81 | * this port The following is a list of phys for each port that are allowed: - | |
82 | * Port 0 - 3 2 1 0 - Port 1 - 1 - Port 2 - 3 2 - Port 3 - 3 This method | |
83 | * doesn't preclude all configurations. It merely ensures that a phy is part | |
84 | * of the allowable set of phy identifiers for that port. For example, one | |
85 | * could assign phy 3 to port 0 and no other phys. Please refer to | |
86 | * scic_sds_port_is_phy_mask_valid() for information regarding whether the | |
87 | * phy_mask for a port can be supported. bool true if this is a valid phy | |
88 | * assignment for the port false if this is not a valid phy assignment for the | |
89 | * port | |
90 | */ | |
91 | bool scic_sds_port_is_valid_phy_assignment( | |
e2023b87 | 92 | struct scic_sds_port *sci_port, |
6f231dda DW |
93 | u32 phy_index) |
94 | { | |
95 | /* Initialize to invalid value. */ | |
96 | u32 existing_phy_index = SCI_MAX_PHYS; | |
97 | u32 index; | |
98 | ||
e2023b87 | 99 | if ((sci_port->physical_port_index == 1) && (phy_index != 1)) { |
6f231dda DW |
100 | return false; |
101 | } | |
102 | ||
e2023b87 | 103 | if (sci_port->physical_port_index == 3 && phy_index != 3) { |
6f231dda DW |
104 | return false; |
105 | } | |
106 | ||
107 | if ( | |
e2023b87 | 108 | (sci_port->physical_port_index == 2) |
6f231dda DW |
109 | && ((phy_index == 0) || (phy_index == 1)) |
110 | ) { | |
111 | return false; | |
112 | } | |
113 | ||
114 | for (index = 0; index < SCI_MAX_PHYS; index++) { | |
e2023b87 | 115 | if ((sci_port->phy_table[index] != NULL) |
6f231dda DW |
116 | && (index != phy_index)) { |
117 | existing_phy_index = index; | |
118 | } | |
119 | } | |
120 | ||
121 | /* | |
122 | * Ensure that all of the phys in the port are capable of | |
123 | * operating at the same maximum link rate. */ | |
124 | if ( | |
125 | (existing_phy_index < SCI_MAX_PHYS) | |
e2023b87 | 126 | && (sci_port->owning_controller->user_parameters.sds1.phys[ |
6f231dda | 127 | phy_index].max_speed_generation != |
e2023b87 | 128 | sci_port->owning_controller->user_parameters.sds1.phys[ |
6f231dda DW |
129 | existing_phy_index].max_speed_generation) |
130 | ) | |
131 | return false; | |
132 | ||
133 | return true; | |
134 | } | |
135 | ||
136 | /** | |
137 | * This method requests a list (mask) of the phys contained in the supplied SAS | |
138 | * port. | |
e2023b87 | 139 | * @sci_port: a handle corresponding to the SAS port for which to return the |
6f231dda DW |
140 | * phy mask. |
141 | * | |
142 | * Return a bit mask indicating which phys are a part of this port. Each bit | |
143 | * corresponds to a phy identifier (e.g. bit 0 = phy id 0). | |
144 | */ | |
e2023b87 | 145 | static u32 scic_sds_port_get_phys(struct scic_sds_port *sci_port) |
6f231dda DW |
146 | { |
147 | u32 index; | |
148 | u32 mask; | |
149 | ||
150 | mask = 0; | |
151 | ||
152 | for (index = 0; index < SCI_MAX_PHYS; index++) { | |
e2023b87 | 153 | if (sci_port->phy_table[index] != NULL) { |
6f231dda DW |
154 | mask |= (1 << index); |
155 | } | |
156 | } | |
157 | ||
158 | return mask; | |
159 | } | |
160 | ||
161 | /** | |
162 | * | |
e2023b87 | 163 | * @sci_port: This is the port object for which to determine if the phy mask |
6f231dda DW |
164 | * can be supported. |
165 | * | |
166 | * This method will return a true value if the port's phy mask can be supported | |
167 | * by the SCU. The following is a list of valid PHY mask configurations for | |
168 | * each port: - Port 0 - [[3 2] 1] 0 - Port 1 - [1] - Port 2 - [[3] 2] | |
169 | * - Port 3 - [3] This method returns a boolean indication specifying if the | |
170 | * phy mask can be supported. true if this is a valid phy assignment for the | |
171 | * port false if this is not a valid phy assignment for the port | |
172 | */ | |
35173d57 | 173 | static bool scic_sds_port_is_phy_mask_valid( |
e2023b87 | 174 | struct scic_sds_port *sci_port, |
6f231dda DW |
175 | u32 phy_mask) |
176 | { | |
e2023b87 | 177 | if (sci_port->physical_port_index == 0) { |
6f231dda DW |
178 | if (((phy_mask & 0x0F) == 0x0F) |
179 | || ((phy_mask & 0x03) == 0x03) | |
180 | || ((phy_mask & 0x01) == 0x01) | |
181 | || (phy_mask == 0)) | |
182 | return true; | |
e2023b87 | 183 | } else if (sci_port->physical_port_index == 1) { |
6f231dda DW |
184 | if (((phy_mask & 0x02) == 0x02) |
185 | || (phy_mask == 0)) | |
186 | return true; | |
e2023b87 | 187 | } else if (sci_port->physical_port_index == 2) { |
6f231dda DW |
188 | if (((phy_mask & 0x0C) == 0x0C) |
189 | || ((phy_mask & 0x04) == 0x04) | |
190 | || (phy_mask == 0)) | |
191 | return true; | |
e2023b87 | 192 | } else if (sci_port->physical_port_index == 3) { |
6f231dda DW |
193 | if (((phy_mask & 0x08) == 0x08) |
194 | || (phy_mask == 0)) | |
195 | return true; | |
196 | } | |
197 | ||
198 | return false; | |
199 | } | |
200 | ||
201 | /** | |
202 | * | |
e2023b87 | 203 | * @sci_port: This parameter specifies the port from which to return a |
6f231dda DW |
204 | * connected phy. |
205 | * | |
206 | * This method retrieves a currently active (i.e. connected) phy contained in | |
207 | * the port. Currently, the lowest order phy that is connected is returned. | |
208 | * This method returns a pointer to a SCIS_SDS_PHY object. NULL This value is | |
209 | * returned if there are no currently active (i.e. connected to a remote end | |
210 | * point) phys contained in the port. All other values specify a struct scic_sds_phy | |
211 | * object that is active in the port. | |
212 | */ | |
213 | static struct scic_sds_phy *scic_sds_port_get_a_connected_phy( | |
e2023b87 | 214 | struct scic_sds_port *sci_port |
6f231dda DW |
215 | ) { |
216 | u32 index; | |
217 | struct scic_sds_phy *phy; | |
218 | ||
219 | for (index = 0; index < SCI_MAX_PHYS; index++) { | |
220 | /* | |
221 | * Ensure that the phy is both part of the port and currently | |
222 | * connected to the remote end-point. */ | |
e2023b87 | 223 | phy = sci_port->phy_table[index]; |
6f231dda DW |
224 | if ( |
225 | (phy != NULL) | |
e2023b87 | 226 | && scic_sds_port_active_phy(sci_port, phy) |
6f231dda DW |
227 | ) { |
228 | return phy; | |
229 | } | |
230 | } | |
231 | ||
232 | return NULL; | |
233 | } | |
234 | ||
235 | /** | |
236 | * scic_sds_port_set_phy() - | |
237 | * @out]: port The port object to which the phy assignement is being made. | |
238 | * @out]: phy The phy which is being assigned to the port. | |
239 | * | |
240 | * This method attempts to make the assignment of the phy to the port. If | |
241 | * successful the phy is assigned to the ports phy table. bool true if the phy | |
242 | * assignment can be made. false if the phy assignement can not be made. This | |
243 | * is a functional test that only fails if the phy is currently assigned to a | |
244 | * different port. | |
245 | */ | |
35173d57 | 246 | static enum sci_status scic_sds_port_set_phy( |
6f231dda DW |
247 | struct scic_sds_port *port, |
248 | struct scic_sds_phy *phy) | |
249 | { | |
250 | /* | |
251 | * Check to see if we can add this phy to a port | |
252 | * that means that the phy is not part of a port and that the port does | |
253 | * not already have a phy assinged to the phy index. */ | |
254 | if ( | |
a7e536c7 EN |
255 | (port->phy_table[phy->phy_index] == NULL) |
256 | && (scic_sds_phy_get_port(phy) == NULL) | |
6f231dda DW |
257 | && scic_sds_port_is_valid_phy_assignment(port, phy->phy_index) |
258 | ) { | |
259 | /* | |
260 | * Phy is being added in the stopped state so we are in MPC mode | |
261 | * make logical port index = physical port index */ | |
262 | port->logical_port_index = port->physical_port_index; | |
263 | port->phy_table[phy->phy_index] = phy; | |
264 | scic_sds_phy_set_port(phy, port); | |
265 | ||
266 | return SCI_SUCCESS; | |
267 | } | |
268 | ||
269 | return SCI_FAILURE; | |
270 | } | |
271 | ||
272 | /** | |
273 | * scic_sds_port_clear_phy() - | |
274 | * @out]: port The port from which the phy is being cleared. | |
275 | * @out]: phy The phy being cleared from the port. | |
276 | * | |
277 | * This method will clear the phy assigned to this port. This method fails if | |
278 | * this phy is not currently assinged to this port. bool true if the phy is | |
279 | * removed from the port. false if this phy is not assined to this port. | |
280 | */ | |
35173d57 | 281 | static enum sci_status scic_sds_port_clear_phy( |
6f231dda DW |
282 | struct scic_sds_port *port, |
283 | struct scic_sds_phy *phy) | |
284 | { | |
285 | /* Make sure that this phy is part of this port */ | |
e531381e DW |
286 | if (port->phy_table[phy->phy_index] == phy && |
287 | scic_sds_phy_get_port(phy) == port) { | |
288 | struct scic_sds_controller *scic = port->owning_controller; | |
289 | struct isci_host *ihost = scic_to_ihost(scic); | |
6f231dda | 290 | |
e531381e DW |
291 | /* Yep it is assigned to this port so remove it */ |
292 | scic_sds_phy_set_port(phy, &ihost->ports[SCI_MAX_PORTS].sci); | |
a7e536c7 | 293 | port->phy_table[phy->phy_index] = NULL; |
6f231dda DW |
294 | return SCI_SUCCESS; |
295 | } | |
296 | ||
297 | return SCI_FAILURE; | |
298 | } | |
299 | ||
300 | /** | |
301 | * scic_sds_port_add_phy() - | |
e2023b87 DJ |
302 | * @sci_port: This parameter specifies the port in which the phy will be added. |
303 | * @sci_phy: This parameter is the phy which is to be added to the port. | |
6f231dda DW |
304 | * |
305 | * This method will add a PHY to the selected port. This method returns an | |
306 | * enum sci_status. SCI_SUCCESS the phy has been added to the port. Any other status | |
307 | * is failre to add the phy to the port. | |
308 | */ | |
309 | enum sci_status scic_sds_port_add_phy( | |
e2023b87 DJ |
310 | struct scic_sds_port *sci_port, |
311 | struct scic_sds_phy *sci_phy) | |
6f231dda | 312 | { |
e2023b87 DJ |
313 | return sci_port->state_handlers->add_phy_handler( |
314 | sci_port, sci_phy); | |
6f231dda DW |
315 | } |
316 | ||
317 | ||
318 | /** | |
319 | * scic_sds_port_remove_phy() - | |
e2023b87 DJ |
320 | * @sci_port: This parameter specifies the port in which the phy will be added. |
321 | * @sci_phy: This parameter is the phy which is to be added to the port. | |
6f231dda DW |
322 | * |
323 | * This method will remove the PHY from the selected PORT. This method returns | |
324 | * an enum sci_status. SCI_SUCCESS the phy has been removed from the port. Any other | |
325 | * status is failre to add the phy to the port. | |
326 | */ | |
327 | enum sci_status scic_sds_port_remove_phy( | |
e2023b87 DJ |
328 | struct scic_sds_port *sci_port, |
329 | struct scic_sds_phy *sci_phy) | |
6f231dda | 330 | { |
e2023b87 DJ |
331 | return sci_port->state_handlers->remove_phy_handler( |
332 | sci_port, sci_phy); | |
6f231dda DW |
333 | } |
334 | ||
335 | /** | |
336 | * This method requests the SAS address for the supplied SAS port from the SCI | |
337 | * implementation. | |
e2023b87 | 338 | * @sci_port: a handle corresponding to the SAS port for which to return the |
6f231dda DW |
339 | * SAS address. |
340 | * @sas_address: This parameter specifies a pointer to a SAS address structure | |
341 | * into which the core will copy the SAS address for the port. | |
342 | * | |
343 | */ | |
344 | void scic_sds_port_get_sas_address( | |
e2023b87 | 345 | struct scic_sds_port *sci_port, |
6f231dda DW |
346 | struct sci_sas_address *sas_address) |
347 | { | |
348 | u32 index; | |
349 | ||
350 | sas_address->high = 0; | |
351 | sas_address->low = 0; | |
352 | ||
353 | for (index = 0; index < SCI_MAX_PHYS; index++) { | |
e2023b87 DJ |
354 | if (sci_port->phy_table[index] != NULL) { |
355 | scic_sds_phy_get_sas_address(sci_port->phy_table[index], sas_address); | |
6f231dda DW |
356 | } |
357 | } | |
358 | } | |
359 | ||
d7b90fc3 DJ |
360 | /* |
361 | * This function will indicate which protocols are supported by this port. | |
e2023b87 | 362 | * @sci_port: a handle corresponding to the SAS port for which to return the |
6f231dda | 363 | * supported protocols. |
d7b90fc3 DJ |
364 | * @protocols: This parameter specifies a pointer to a data structure |
365 | * which the core will copy the protocol values for the port from the | |
366 | * transmit_identification register. | |
6f231dda | 367 | */ |
d7b90fc3 DJ |
368 | static void |
369 | scic_sds_port_get_protocols(struct scic_sds_port *sci_port, | |
370 | struct scic_phy_proto *protocols) | |
6f231dda DW |
371 | { |
372 | u8 index; | |
373 | ||
d7b90fc3 | 374 | protocols->all = 0; |
6f231dda DW |
375 | |
376 | for (index = 0; index < SCI_MAX_PHYS; index++) { | |
e2023b87 | 377 | if (sci_port->phy_table[index] != NULL) { |
d7b90fc3 DJ |
378 | scic_sds_phy_get_protocols(sci_port->phy_table[index], |
379 | protocols); | |
6f231dda DW |
380 | } |
381 | } | |
382 | } | |
383 | ||
d7b90fc3 DJ |
384 | /* |
385 | * This function requests the SAS address for the device directly attached to | |
6f231dda | 386 | * this SAS port. |
e2023b87 | 387 | * @sci_port: a handle corresponding to the SAS port for which to return the |
6f231dda DW |
388 | * SAS address. |
389 | * @sas_address: This parameter specifies a pointer to a SAS address structure | |
390 | * into which the core will copy the SAS address for the device directly | |
391 | * attached to the port. | |
392 | * | |
393 | */ | |
394 | void scic_sds_port_get_attached_sas_address( | |
e2023b87 | 395 | struct scic_sds_port *sci_port, |
6f231dda DW |
396 | struct sci_sas_address *sas_address) |
397 | { | |
d7b90fc3 | 398 | struct scic_sds_phy *sci_phy; |
6f231dda DW |
399 | |
400 | /* | |
401 | * Ensure that the phy is both part of the port and currently | |
d7b90fc3 DJ |
402 | * connected to the remote end-point. |
403 | */ | |
404 | sci_phy = scic_sds_port_get_a_connected_phy(sci_port); | |
405 | if (sci_phy) { | |
406 | if (sci_phy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA) { | |
407 | scic_sds_phy_get_attached_sas_address(sci_phy, | |
408 | sas_address); | |
6f231dda | 409 | } else { |
d7b90fc3 DJ |
410 | scic_sds_phy_get_sas_address(sci_phy, sas_address); |
411 | sas_address->low += sci_phy->phy_index; | |
6f231dda DW |
412 | } |
413 | } else { | |
414 | sas_address->high = 0; | |
415 | sas_address->low = 0; | |
416 | } | |
417 | } | |
418 | ||
6f231dda | 419 | /** |
a8d4b9fe | 420 | * scic_sds_port_construct_dummy_rnc() - create dummy rnc for si workaround |
6f231dda | 421 | * |
a8d4b9fe TC |
422 | * @sci_port: logical port on which we need to create the remote node context |
423 | * @rni: remote node index for this remote node context. | |
6f231dda | 424 | * |
a8d4b9fe TC |
425 | * This routine will construct a dummy remote node context data structure |
426 | * This structure will be posted to the hardware to work around a scheduler | |
427 | * error in the hardware. | |
6f231dda | 428 | */ |
35173d57 | 429 | static void scic_sds_port_construct_dummy_rnc(struct scic_sds_port *sci_port, u16 rni) |
a8d4b9fe TC |
430 | { |
431 | union scu_remote_node_context *rnc; | |
6f231dda | 432 | |
a8d4b9fe TC |
433 | rnc = &sci_port->owning_controller->remote_node_context_table[rni]; |
434 | ||
435 | memset(rnc, 0, sizeof(union scu_remote_node_context)); | |
436 | ||
437 | rnc->ssp.remote_sas_address_hi = 0; | |
438 | rnc->ssp.remote_sas_address_lo = 0; | |
439 | ||
440 | rnc->ssp.remote_node_index = rni; | |
441 | rnc->ssp.remote_node_port_width = 1; | |
442 | rnc->ssp.logical_port_index = sci_port->physical_port_index; | |
443 | ||
444 | rnc->ssp.nexus_loss_timer_enable = false; | |
445 | rnc->ssp.check_bit = false; | |
446 | rnc->ssp.is_valid = true; | |
447 | rnc->ssp.is_remote_node_context = true; | |
448 | rnc->ssp.function_number = 0; | |
449 | rnc->ssp.arbitration_wait_time = 0; | |
450 | } | |
6f231dda DW |
451 | |
452 | /** | |
a8d4b9fe TC |
453 | * scic_sds_port_construct_dummy_task() - create dummy task for si workaround |
454 | * @sci_port The logical port on which we need to create the | |
455 | * remote node context. | |
456 | * context. | |
457 | * @tci The remote node index for this remote node context. | |
6f231dda | 458 | * |
a8d4b9fe TC |
459 | * This routine will construct a dummy task context data structure. This |
460 | * structure will be posted to the hardwre to work around a scheduler error | |
461 | * in the hardware. | |
6f231dda DW |
462 | * |
463 | */ | |
35173d57 | 464 | static void scic_sds_port_construct_dummy_task(struct scic_sds_port *sci_port, u16 tci) |
a8d4b9fe TC |
465 | { |
466 | struct scu_task_context *task_context; | |
467 | ||
468 | task_context = scic_sds_controller_get_task_context_buffer(sci_port->owning_controller, tci); | |
469 | ||
470 | memset(task_context, 0, sizeof(struct scu_task_context)); | |
471 | ||
472 | task_context->abort = 0; | |
473 | task_context->priority = 0; | |
474 | task_context->initiator_request = 1; | |
475 | task_context->connection_rate = 1; | |
476 | task_context->protocol_engine_index = 0; | |
477 | task_context->logical_port_index = sci_port->physical_port_index; | |
478 | task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SSP; | |
479 | task_context->task_index = scic_sds_io_tag_get_index(tci); | |
480 | task_context->valid = SCU_TASK_CONTEXT_VALID; | |
481 | task_context->context_type = SCU_TASK_CONTEXT_TYPE; | |
482 | ||
483 | task_context->remote_node_index = sci_port->reserved_rni; | |
484 | task_context->command_code = 0; | |
485 | ||
486 | task_context->link_layer_control = 0; | |
487 | task_context->do_not_dma_ssp_good_response = 1; | |
488 | task_context->strict_ordering = 0; | |
489 | task_context->control_frame = 0; | |
490 | task_context->timeout_enable = 0; | |
491 | task_context->block_guard_enable = 0; | |
492 | ||
493 | task_context->address_modifier = 0; | |
494 | ||
495 | task_context->task_phase = 0x01; | |
496 | } | |
497 | ||
35173d57 | 498 | static void scic_sds_port_destroy_dummy_resources(struct scic_sds_port *sci_port) |
a8d4b9fe TC |
499 | { |
500 | struct scic_sds_controller *scic = sci_port->owning_controller; | |
501 | ||
502 | if (sci_port->reserved_tci != SCU_DUMMY_INDEX) | |
503 | scic_controller_free_io_tag(scic, sci_port->reserved_tci); | |
504 | ||
505 | if (sci_port->reserved_rni != SCU_DUMMY_INDEX) | |
506 | scic_sds_remote_node_table_release_remote_node_index(&scic->available_remote_nodes, | |
507 | 1, sci_port->reserved_rni); | |
508 | ||
509 | sci_port->reserved_rni = SCU_DUMMY_INDEX; | |
510 | sci_port->reserved_tci = SCU_DUMMY_INDEX; | |
511 | } | |
512 | ||
6f231dda DW |
513 | /** |
514 | * This method performs initialization of the supplied port. Initialization | |
515 | * includes: - state machine initialization - member variable initialization | |
516 | * - configuring the phy_mask | |
e2023b87 | 517 | * @sci_port: |
6f231dda DW |
518 | * @transport_layer_registers: |
519 | * @port_task_scheduler_registers: | |
520 | * @port_configuration_regsiter: | |
521 | * | |
522 | * enum sci_status SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION This value is returned | |
523 | * if the phy being added to the port | |
524 | */ | |
525 | enum sci_status scic_sds_port_initialize( | |
e2023b87 | 526 | struct scic_sds_port *sci_port, |
24621466 HD |
527 | void __iomem *port_task_scheduler_registers, |
528 | void __iomem *port_configuration_regsiter, | |
529 | void __iomem *viit_registers) | |
6f231dda | 530 | { |
e2023b87 DJ |
531 | sci_port->port_task_scheduler_registers = port_task_scheduler_registers; |
532 | sci_port->port_pe_configuration_register = port_configuration_regsiter; | |
533 | sci_port->viit_registers = viit_registers; | |
6f231dda | 534 | |
6f231dda DW |
535 | return SCI_SUCCESS; |
536 | } | |
537 | ||
538 | /** | |
35173d57 DW |
539 | * scic_port_get_properties() - This method simply returns the properties |
540 | * regarding the port, such as: physical index, protocols, sas address, etc. | |
541 | * @port: this parameter specifies the port for which to retrieve the physical | |
542 | * index. | |
543 | * @properties: This parameter specifies the properties structure into which to | |
544 | * copy the requested information. | |
6f231dda | 545 | * |
35173d57 DW |
546 | * Indicate if the user specified a valid port. SCI_SUCCESS This value is |
547 | * returned if the specified port was valid. SCI_FAILURE_INVALID_PORT This | |
548 | * value is returned if the specified port is not valid. When this value is | |
549 | * returned, no data is copied to the properties output parameter. | |
6f231dda | 550 | */ |
6f231dda DW |
551 | enum sci_status scic_port_get_properties( |
552 | struct scic_sds_port *port, | |
553 | struct scic_port_properties *prop) | |
554 | { | |
a7e536c7 | 555 | if ((port == NULL) || |
6f231dda DW |
556 | (port->logical_port_index == SCIC_SDS_DUMMY_PORT)) |
557 | return SCI_FAILURE_INVALID_PORT; | |
558 | ||
559 | prop->index = port->logical_port_index; | |
560 | prop->phy_mask = scic_sds_port_get_phys(port); | |
561 | scic_sds_port_get_sas_address(port, &prop->local.sas_address); | |
562 | scic_sds_port_get_protocols(port, &prop->local.protocols); | |
563 | scic_sds_port_get_attached_sas_address(port, &prop->remote.sas_address); | |
6f231dda DW |
564 | |
565 | return SCI_SUCCESS; | |
566 | } | |
567 | ||
35173d57 | 568 | /** |
de728b7d | 569 | * scic_port_hard_reset() - perform port hard reset |
35173d57 DW |
570 | * @port: a handle corresponding to the SAS port to be hard reset. |
571 | * @reset_timeout: This parameter specifies the number of milliseconds in which | |
572 | * the port reset operation should complete. | |
573 | * | |
de728b7d | 574 | * The SCI User callback in scic_user_callbacks_t will only be called once for |
35173d57 DW |
575 | * each phy in the SAS Port at completion of the hard reset sequence. Return a |
576 | * status indicating whether the hard reset started successfully. SCI_SUCCESS | |
577 | * This value is returned if the hard reset operation started successfully. | |
578 | */ | |
6f231dda DW |
579 | enum sci_status scic_port_hard_reset( |
580 | struct scic_sds_port *port, | |
581 | u32 reset_timeout) | |
582 | { | |
41e2b905 MT |
583 | return port->state_handlers->reset_handler( |
584 | port, reset_timeout); | |
6f231dda DW |
585 | } |
586 | ||
587 | /** | |
6f231dda | 588 | * This method assigns the direct attached device ID for this port. |
24621466 | 589 | * |
e2023b87 | 590 | * @param[in] sci_port The port for which the direct attached device id is to |
24621466 HD |
591 | * be assigned. |
592 | * @param[in] device_id The direct attached device ID to assign to the port. | |
593 | * This will be the RNi for the device | |
6f231dda | 594 | */ |
24621466 | 595 | void scic_sds_port_setup_transports( |
e2023b87 | 596 | struct scic_sds_port *sci_port, |
6f231dda DW |
597 | u32 device_id) |
598 | { | |
24621466 | 599 | u8 index; |
6f231dda | 600 | |
24621466 | 601 | for (index = 0; index < SCI_MAX_PHYS; index++) { |
e2023b87 DJ |
602 | if (sci_port->active_phy_mask & (1 << index)) |
603 | scic_sds_phy_setup_transport(sci_port->phy_table[index], device_id); | |
24621466 | 604 | } |
6f231dda DW |
605 | } |
606 | ||
6f231dda DW |
607 | /** |
608 | * | |
e2023b87 DJ |
609 | * @sci_port: This is the port on which the phy should be enabled. |
610 | * @sci_phy: This is the specific phy which to enable. | |
6f231dda DW |
611 | * @do_notify_user: This parameter specifies whether to inform the user (via |
612 | * scic_cb_port_link_up()) as to the fact that a new phy as become ready. | |
613 | * | |
09d7da13 DJ |
614 | * This function will activate the phy in the port. |
615 | * Activation includes: - adding | |
6f231dda DW |
616 | * the phy to the port - enabling the Protocol Engine in the silicon. - |
617 | * notifying the user that the link is up. none | |
618 | */ | |
35173d57 DW |
619 | static void scic_sds_port_activate_phy(struct scic_sds_port *sci_port, |
620 | struct scic_sds_phy *sci_phy, | |
621 | bool do_notify_user) | |
6f231dda | 622 | { |
d7b90fc3 | 623 | struct scic_sds_controller *scic = sci_port->owning_controller; |
cc3dbd0a | 624 | struct isci_host *ihost = scic_to_ihost(scic); |
6f231dda | 625 | |
d7b90fc3 | 626 | if (sci_phy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA) |
09d7da13 | 627 | scic_sds_phy_resume(sci_phy); |
6f231dda | 628 | |
09d7da13 | 629 | sci_port->active_phy_mask |= 1 << sci_phy->phy_index; |
6f231dda | 630 | |
09d7da13 | 631 | scic_sds_controller_clear_invalid_phy(scic, sci_phy); |
6f231dda DW |
632 | |
633 | if (do_notify_user == true) | |
09d7da13 | 634 | isci_port_link_up(ihost, sci_port, sci_phy); |
6f231dda DW |
635 | } |
636 | ||
09d7da13 DJ |
637 | void scic_sds_port_deactivate_phy(struct scic_sds_port *sci_port, |
638 | struct scic_sds_phy *sci_phy, | |
639 | bool do_notify_user) | |
6f231dda | 640 | { |
35173d57 | 641 | struct scic_sds_controller *scic = scic_sds_port_get_controller(sci_port); |
e531381e | 642 | struct isci_port *iport = sci_port_to_iport(sci_port); |
cc3dbd0a | 643 | struct isci_host *ihost = scic_to_ihost(scic); |
4b33981a | 644 | struct isci_phy *iphy = sci_phy_to_iphy(sci_phy); |
09d7da13 DJ |
645 | |
646 | sci_port->active_phy_mask &= ~(1 << sci_phy->phy_index); | |
6f231dda | 647 | |
26bace34 | 648 | sci_phy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN; |
6f231dda DW |
649 | |
650 | /* Re-assign the phy back to the LP as if it were a narrow port */ | |
bc99aa47 CH |
651 | writel(sci_phy->phy_index, |
652 | &sci_port->port_pe_configuration_register[sci_phy->phy_index]); | |
6f231dda DW |
653 | |
654 | if (do_notify_user == true) | |
09d7da13 | 655 | isci_port_link_down(ihost, iphy, iport); |
6f231dda DW |
656 | } |
657 | ||
658 | /** | |
659 | * | |
e2023b87 DJ |
660 | * @sci_port: This is the port on which the phy should be disabled. |
661 | * @sci_phy: This is the specific phy which to disabled. | |
6f231dda | 662 | * |
09d7da13 | 663 | * This function will disable the phy and report that the phy is not valid for |
6f231dda DW |
664 | * this port object. None |
665 | */ | |
cc3dbd0a AW |
666 | static void scic_sds_port_invalid_link_up(struct scic_sds_port *sci_port, |
667 | struct scic_sds_phy *sci_phy) | |
6f231dda | 668 | { |
cc3dbd0a | 669 | struct scic_sds_controller *scic = sci_port->owning_controller; |
6f231dda DW |
670 | |
671 | /* | |
09d7da13 DJ |
672 | * Check to see if we have alreay reported this link as bad and if |
673 | * not go ahead and tell the SCI_USER that we have discovered an | |
674 | * invalid link. | |
675 | */ | |
676 | if ((scic->invalid_phy_mask & (1 << sci_phy->phy_index)) == 0) { | |
677 | scic_sds_controller_set_invalid_phy(scic, sci_phy); | |
cc3dbd0a | 678 | dev_warn(&scic_to_ihost(scic)->pdev->dev, "Invalid link up!\n"); |
6f231dda DW |
679 | } |
680 | } | |
681 | ||
35173d57 DW |
682 | /** |
683 | * scic_sds_port_general_link_up_handler - phy can be assigned to port? | |
684 | * @sci_port: scic_sds_port object for which has a phy that has gone link up. | |
685 | * @sci_phy: This is the struct scic_sds_phy object that has gone link up. | |
686 | * @do_notify_user: This parameter specifies whether to inform the user (via | |
687 | * scic_cb_port_link_up()) as to the fact that a new phy as become ready. | |
688 | * | |
689 | * Determine if this phy can be assigned to this | |
690 | * port . If the phy is not a valid PHY for | |
691 | * this port then the function will notify the user. A PHY can only be | |
692 | * part of a port if it's attached SAS ADDRESS is the same as all other PHYs in | |
693 | * the same port. none | |
694 | */ | |
695 | static void scic_sds_port_general_link_up_handler(struct scic_sds_port *sci_port, | |
696 | struct scic_sds_phy *sci_phy, | |
697 | bool do_notify_user) | |
698 | { | |
699 | struct sci_sas_address port_sas_address; | |
700 | struct sci_sas_address phy_sas_address; | |
701 | ||
702 | scic_sds_port_get_attached_sas_address(sci_port, &port_sas_address); | |
703 | scic_sds_phy_get_attached_sas_address(sci_phy, &phy_sas_address); | |
704 | ||
705 | /* If the SAS address of the new phy matches the SAS address of | |
706 | * other phys in the port OR this is the first phy in the port, | |
707 | * then activate the phy and allow it to be used for operations | |
708 | * in this port. | |
709 | */ | |
710 | if ((phy_sas_address.high == port_sas_address.high && | |
711 | phy_sas_address.low == port_sas_address.low) || | |
712 | sci_port->active_phy_mask == 0) { | |
41e2b905 | 713 | struct sci_base_state_machine *sm = &sci_port->state_machine; |
35173d57 DW |
714 | |
715 | scic_sds_port_activate_phy(sci_port, sci_phy, do_notify_user); | |
716 | if (sm->current_state_id == SCI_BASE_PORT_STATE_RESETTING) | |
717 | sci_base_state_machine_change_state(sm, SCI_BASE_PORT_STATE_READY); | |
718 | } else | |
719 | scic_sds_port_invalid_link_up(sci_port, sci_phy); | |
720 | } | |
721 | ||
722 | ||
723 | ||
6f231dda DW |
724 | /** |
725 | * This method returns false if the port only has a single phy object assigned. | |
726 | * If there are no phys or more than one phy then the method will return | |
727 | * true. | |
e2023b87 | 728 | * @sci_port: The port for which the wide port condition is to be checked. |
6f231dda DW |
729 | * |
730 | * bool true Is returned if this is a wide ported port. false Is returned if | |
731 | * this is a narrow port. | |
732 | */ | |
e2023b87 | 733 | static bool scic_sds_port_is_wide(struct scic_sds_port *sci_port) |
6f231dda DW |
734 | { |
735 | u32 index; | |
736 | u32 phy_count = 0; | |
737 | ||
738 | for (index = 0; index < SCI_MAX_PHYS; index++) { | |
e2023b87 | 739 | if (sci_port->phy_table[index] != NULL) { |
6f231dda DW |
740 | phy_count++; |
741 | } | |
742 | } | |
743 | ||
744 | return phy_count != 1; | |
745 | } | |
746 | ||
747 | /** | |
748 | * This method is called by the PHY object when the link is detected. if the | |
749 | * port wants the PHY to continue on to the link up state then the port | |
750 | * layer must return true. If the port object returns false the phy object | |
751 | * must halt its attempt to go link up. | |
e2023b87 DJ |
752 | * @sci_port: The port associated with the phy object. |
753 | * @sci_phy: The phy object that is trying to go link up. | |
6f231dda DW |
754 | * |
755 | * true if the phy object can continue to the link up condition. true Is | |
756 | * returned if this phy can continue to the ready state. false Is returned if | |
757 | * can not continue on to the ready state. This notification is in place for | |
758 | * wide ports and direct attached phys. Since there are no wide ported SATA | |
759 | * devices this could become an invalid port configuration. | |
760 | */ | |
761 | bool scic_sds_port_link_detected( | |
e2023b87 DJ |
762 | struct scic_sds_port *sci_port, |
763 | struct scic_sds_phy *sci_phy) | |
6f231dda | 764 | { |
d7b90fc3 DJ |
765 | if ((sci_port->logical_port_index != SCIC_SDS_DUMMY_PORT) && |
766 | (sci_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) && | |
767 | scic_sds_port_is_wide(sci_port)) { | |
e2023b87 | 768 | scic_sds_port_invalid_link_up(sci_port, sci_phy); |
6f231dda DW |
769 | |
770 | return false; | |
771 | } | |
772 | ||
773 | return true; | |
774 | } | |
775 | ||
776 | /** | |
777 | * This method is the entry point for the phy to inform the port that it is now | |
778 | * in a ready state | |
e2023b87 | 779 | * @sci_port: |
6f231dda DW |
780 | * |
781 | * | |
782 | */ | |
783 | void scic_sds_port_link_up( | |
e2023b87 DJ |
784 | struct scic_sds_port *sci_port, |
785 | struct scic_sds_phy *sci_phy) | |
6f231dda | 786 | { |
e2023b87 | 787 | sci_phy->is_in_link_training = false; |
6f231dda | 788 | |
e2023b87 | 789 | sci_port->state_handlers->link_up_handler(sci_port, sci_phy); |
6f231dda DW |
790 | } |
791 | ||
792 | /** | |
793 | * This method is the entry point for the phy to inform the port that it is no | |
794 | * longer in a ready state | |
e2023b87 | 795 | * @sci_port: |
6f231dda DW |
796 | * |
797 | * | |
798 | */ | |
799 | void scic_sds_port_link_down( | |
e2023b87 DJ |
800 | struct scic_sds_port *sci_port, |
801 | struct scic_sds_phy *sci_phy) | |
6f231dda | 802 | { |
e2023b87 | 803 | sci_port->state_handlers->link_down_handler(sci_port, sci_phy); |
6f231dda DW |
804 | } |
805 | ||
806 | /** | |
807 | * This method is called to start an IO request on this port. | |
e2023b87 DJ |
808 | * @sci_port: |
809 | * @sci_dev: | |
810 | * @sci_req: | |
6f231dda DW |
811 | * |
812 | * enum sci_status | |
813 | */ | |
814 | enum sci_status scic_sds_port_start_io( | |
e2023b87 DJ |
815 | struct scic_sds_port *sci_port, |
816 | struct scic_sds_remote_device *sci_dev, | |
817 | struct scic_sds_request *sci_req) | |
6f231dda | 818 | { |
e2023b87 DJ |
819 | return sci_port->state_handlers->start_io_handler( |
820 | sci_port, sci_dev, sci_req); | |
6f231dda DW |
821 | } |
822 | ||
823 | /** | |
824 | * This method is called to complete an IO request to the port. | |
e2023b87 DJ |
825 | * @sci_port: |
826 | * @sci_dev: | |
827 | * @sci_req: | |
6f231dda DW |
828 | * |
829 | * enum sci_status | |
830 | */ | |
831 | enum sci_status scic_sds_port_complete_io( | |
e2023b87 DJ |
832 | struct scic_sds_port *sci_port, |
833 | struct scic_sds_remote_device *sci_dev, | |
834 | struct scic_sds_request *sci_req) | |
6f231dda | 835 | { |
e2023b87 DJ |
836 | return sci_port->state_handlers->complete_io_handler( |
837 | sci_port, sci_dev, sci_req); | |
6f231dda DW |
838 | } |
839 | ||
840 | /** | |
841 | * This method is provided to timeout requests for port operations. Mostly its | |
842 | * for the port reset operation. | |
843 | * | |
844 | * | |
845 | */ | |
846 | static void scic_sds_port_timeout_handler(void *port) | |
847 | { | |
09d7da13 | 848 | struct scic_sds_port *sci_port = port; |
6f231dda DW |
849 | u32 current_state; |
850 | ||
851 | current_state = sci_base_state_machine_get_state( | |
41e2b905 | 852 | &sci_port->state_machine); |
6f231dda DW |
853 | |
854 | if (current_state == SCI_BASE_PORT_STATE_RESETTING) { | |
855 | /* | |
09d7da13 DJ |
856 | * if the port is still in the resetting state then the |
857 | * timeout fired before the reset completed. | |
858 | */ | |
6f231dda | 859 | sci_base_state_machine_change_state( |
41e2b905 | 860 | &sci_port->state_machine, |
09d7da13 | 861 | SCI_BASE_PORT_STATE_FAILED); |
6f231dda DW |
862 | } else if (current_state == SCI_BASE_PORT_STATE_STOPPED) { |
863 | /* | |
864 | * if the port is stopped then the start request failed | |
09d7da13 DJ |
865 | * In this case stay in the stopped state. |
866 | */ | |
867 | dev_err(sciport_to_dev(sci_port), | |
6f231dda DW |
868 | "%s: SCIC Port 0x%p failed to stop before tiemout.\n", |
869 | __func__, | |
09d7da13 | 870 | sci_port); |
6f231dda | 871 | } else if (current_state == SCI_BASE_PORT_STATE_STOPPING) { |
09d7da13 DJ |
872 | /* |
873 | * if the port is still stopping then the stop has not | |
874 | * completed | |
875 | */ | |
876 | isci_port_stop_complete( | |
877 | scic_sds_port_get_controller(sci_port), | |
878 | sci_port, | |
879 | SCI_FAILURE_TIMEOUT); | |
6f231dda DW |
880 | } else { |
881 | /* | |
09d7da13 DJ |
882 | * The port is in the ready state and we have a timer |
883 | * reporting a timeout this should not happen. | |
884 | */ | |
885 | dev_err(sciport_to_dev(sci_port), | |
6f231dda DW |
886 | "%s: SCIC Port 0x%p is processing a timeout operation " |
887 | "in state %d.\n", | |
888 | __func__, | |
09d7da13 | 889 | sci_port, |
6f231dda DW |
890 | current_state); |
891 | } | |
892 | } | |
893 | ||
894 | /* --------------------------------------------------------------------------- */ | |
895 | ||
6f231dda DW |
896 | /** |
897 | * This function updates the hardwares VIIT entry for this port. | |
898 | * | |
899 | * | |
900 | */ | |
e2023b87 | 901 | static void scic_sds_port_update_viit_entry(struct scic_sds_port *sci_port) |
6f231dda DW |
902 | { |
903 | struct sci_sas_address sas_address; | |
904 | ||
e2023b87 | 905 | scic_sds_port_get_sas_address(sci_port, &sas_address); |
6f231dda | 906 | |
bc99aa47 | 907 | writel(sas_address.high, |
e2023b87 | 908 | &sci_port->viit_registers->initiator_sas_address_hi); |
bc99aa47 | 909 | writel(sas_address.low, |
e2023b87 | 910 | &sci_port->viit_registers->initiator_sas_address_lo); |
6f231dda DW |
911 | |
912 | /* This value get cleared just in case its not already cleared */ | |
e2023b87 | 913 | writel(0, &sci_port->viit_registers->reserved); |
6f231dda DW |
914 | |
915 | /* We are required to update the status register last */ | |
bc99aa47 CH |
916 | writel(SCU_VIIT_ENTRY_ID_VIIT | |
917 | SCU_VIIT_IPPT_INITIATOR | | |
e2023b87 | 918 | ((1 << sci_port->physical_port_index) << SCU_VIIT_ENTRY_LPVIE_SHIFT) | |
bc99aa47 | 919 | SCU_VIIT_STATUS_ALL_VALID, |
e2023b87 | 920 | &sci_port->viit_registers->status); |
6f231dda DW |
921 | } |
922 | ||
923 | /** | |
924 | * This method returns the maximum allowed speed for data transfers on this | |
925 | * port. This maximum allowed speed evaluates to the maximum speed of the | |
926 | * slowest phy in the port. | |
e2023b87 | 927 | * @sci_port: This parameter specifies the port for which to retrieve the |
6f231dda DW |
928 | * maximum allowed speed. |
929 | * | |
930 | * This method returns the maximum negotiated speed of the slowest phy in the | |
931 | * port. | |
932 | */ | |
26bace34 | 933 | enum sas_linkrate scic_sds_port_get_max_allowed_speed( |
e2023b87 | 934 | struct scic_sds_port *sci_port) |
6f231dda | 935 | { |
26bace34 DW |
936 | u16 index; |
937 | enum sas_linkrate max_allowed_speed = SAS_LINK_RATE_6_0_GBPS; | |
938 | struct scic_sds_phy *phy = NULL; | |
6f231dda DW |
939 | |
940 | /* | |
941 | * Loop through all of the phys in this port and find the phy with the | |
942 | * lowest maximum link rate. */ | |
943 | for (index = 0; index < SCI_MAX_PHYS; index++) { | |
e2023b87 | 944 | phy = sci_port->phy_table[index]; |
6f231dda DW |
945 | if ( |
946 | (phy != NULL) | |
e2023b87 | 947 | && (scic_sds_port_active_phy(sci_port, phy) == true) |
6f231dda DW |
948 | && (phy->max_negotiated_speed < max_allowed_speed) |
949 | ) | |
950 | max_allowed_speed = phy->max_negotiated_speed; | |
951 | } | |
952 | ||
953 | return max_allowed_speed; | |
954 | } | |
955 | ||
956 | ||
957 | /** | |
958 | * This method passes the event to core user. | |
e2023b87 DJ |
959 | * @sci_port: The port that a BCN happens. |
960 | * @sci_phy: The phy that receives BCN. | |
6f231dda DW |
961 | * |
962 | */ | |
963 | void scic_sds_port_broadcast_change_received( | |
09d7da13 DJ |
964 | struct scic_sds_port *sci_port, |
965 | struct scic_sds_phy *sci_phy) | |
6f231dda | 966 | { |
09d7da13 | 967 | struct scic_sds_controller *scic = sci_port->owning_controller; |
cc3dbd0a | 968 | struct isci_host *ihost = scic_to_ihost(scic); |
09d7da13 | 969 | |
6f231dda | 970 | /* notify the user. */ |
09d7da13 | 971 | isci_port_bc_change_received(ihost, sci_port, sci_phy); |
6f231dda DW |
972 | } |
973 | ||
974 | ||
975 | /** | |
976 | * This API methhod enables the broadcast change notification from underneath | |
977 | * hardware. | |
e2023b87 | 978 | * @sci_port: The port that a BCN had been disabled from. |
6f231dda DW |
979 | * |
980 | */ | |
981 | void scic_port_enable_broadcast_change_notification( | |
982 | struct scic_sds_port *port) | |
983 | { | |
984 | struct scic_sds_phy *phy; | |
985 | u32 register_value; | |
986 | u8 index; | |
987 | ||
988 | /* Loop through all of the phys to enable BCN. */ | |
989 | for (index = 0; index < SCI_MAX_PHYS; index++) { | |
990 | phy = port->phy_table[index]; | |
991 | if (phy != NULL) { | |
bc99aa47 CH |
992 | register_value = |
993 | readl(&phy->link_layer_registers->link_layer_control); | |
6f231dda DW |
994 | |
995 | /* clear the bit by writing 1. */ | |
bc99aa47 CH |
996 | writel(register_value, |
997 | &phy->link_layer_registers->link_layer_control); | |
6f231dda DW |
998 | } |
999 | } | |
1000 | } | |
1001 | ||
1002 | /* | |
1003 | * **************************************************************************** | |
1004 | * * READY SUBSTATE HANDLERS | |
1005 | * **************************************************************************** */ | |
1006 | ||
41e2b905 | 1007 | /* |
6f231dda DW |
1008 | * This method is the general ready state stop handler for the struct scic_sds_port |
1009 | * object. This function will transition the ready substate machine to its | |
1010 | * final state. enum sci_status SCI_SUCCESS | |
1011 | */ | |
1012 | static enum sci_status scic_sds_port_ready_substate_stop_handler( | |
41e2b905 | 1013 | struct scic_sds_port *port) |
6f231dda | 1014 | { |
6f231dda | 1015 | sci_base_state_machine_change_state( |
41e2b905 | 1016 | &port->state_machine, |
6f231dda DW |
1017 | SCI_BASE_PORT_STATE_STOPPING |
1018 | ); | |
1019 | ||
1020 | return SCI_SUCCESS; | |
1021 | } | |
1022 | ||
38aa74eb | 1023 | /* |
6f231dda DW |
1024 | * This method is the general ready substate complete io handler for the |
1025 | * struct scic_sds_port object. This function decrments the outstanding request count | |
1026 | * for this port object. enum sci_status SCI_SUCCESS | |
1027 | */ | |
1028 | static enum sci_status scic_sds_port_ready_substate_complete_io_handler( | |
1029 | struct scic_sds_port *port, | |
1030 | struct scic_sds_remote_device *device, | |
1031 | struct scic_sds_request *io_request) | |
1032 | { | |
41e2b905 | 1033 | scic_sds_port_decrement_request_count(port); |
6f231dda DW |
1034 | |
1035 | return SCI_SUCCESS; | |
1036 | } | |
1037 | ||
1038 | static enum sci_status scic_sds_port_ready_substate_add_phy_handler( | |
41e2b905 | 1039 | struct scic_sds_port *port, |
d857d9a0 | 1040 | struct scic_sds_phy *phy) |
6f231dda | 1041 | { |
6f231dda DW |
1042 | enum sci_status status; |
1043 | ||
d857d9a0 | 1044 | status = scic_sds_port_set_phy(port, phy); |
6f231dda DW |
1045 | |
1046 | if (status == SCI_SUCCESS) { | |
d857d9a0 | 1047 | scic_sds_port_general_link_up_handler(port, phy, true); |
6f231dda | 1048 | |
41e2b905 | 1049 | port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING; |
6f231dda DW |
1050 | |
1051 | sci_base_state_machine_change_state( | |
41e2b905 | 1052 | &port->ready_substate_machine, |
6f231dda DW |
1053 | SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING |
1054 | ); | |
1055 | } | |
1056 | ||
1057 | return status; | |
1058 | } | |
1059 | ||
1060 | ||
1061 | static enum sci_status scic_sds_port_ready_substate_remove_phy_handler( | |
41e2b905 | 1062 | struct scic_sds_port *port, |
d857d9a0 | 1063 | struct scic_sds_phy *phy) |
6f231dda | 1064 | { |
6f231dda DW |
1065 | enum sci_status status; |
1066 | ||
d857d9a0 | 1067 | status = scic_sds_port_clear_phy(port, phy); |
6f231dda DW |
1068 | |
1069 | if (status == SCI_SUCCESS) { | |
d857d9a0 | 1070 | scic_sds_port_deactivate_phy(port, phy, true); |
6f231dda | 1071 | |
41e2b905 | 1072 | port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING; |
6f231dda DW |
1073 | |
1074 | sci_base_state_machine_change_state( | |
41e2b905 | 1075 | &port->ready_substate_machine, |
6f231dda DW |
1076 | SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING |
1077 | ); | |
1078 | } | |
1079 | ||
1080 | return status; | |
1081 | } | |
1082 | ||
1083 | /* | |
1084 | * **************************************************************************** | |
1085 | * * READY SUBSTATE WAITING HANDLERS | |
1086 | * **************************************************************************** */ | |
1087 | ||
1088 | /** | |
1089 | * | |
e2023b87 | 1090 | * @sci_port: This is the struct scic_sds_port object that which has a phy that has |
6f231dda | 1091 | * gone link up. |
e2023b87 | 1092 | * @sci_phy: This is the struct scic_sds_phy object that has gone link up. |
6f231dda DW |
1093 | * |
1094 | * This method is the ready waiting substate link up handler for the | |
1095 | * struct scic_sds_port object. This methos will report the link up condition for | |
1096 | * this port and will transition to the ready operational substate. none | |
1097 | */ | |
1098 | static void scic_sds_port_ready_waiting_substate_link_up_handler( | |
e2023b87 DJ |
1099 | struct scic_sds_port *sci_port, |
1100 | struct scic_sds_phy *sci_phy) | |
6f231dda DW |
1101 | { |
1102 | /* | |
1103 | * Since this is the first phy going link up for the port we can just enable | |
1104 | * it and continue. */ | |
e2023b87 | 1105 | scic_sds_port_activate_phy(sci_port, sci_phy, true); |
6f231dda DW |
1106 | |
1107 | sci_base_state_machine_change_state( | |
e2023b87 | 1108 | &sci_port->ready_substate_machine, |
6f231dda DW |
1109 | SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL |
1110 | ); | |
1111 | } | |
1112 | ||
38aa74eb | 1113 | /* |
6f231dda DW |
1114 | * This method is the ready waiting substate start io handler for the |
1115 | * struct scic_sds_port object. The port object can not accept new requests so the | |
1116 | * request is failed. enum sci_status SCI_FAILURE_INVALID_STATE | |
1117 | */ | |
1118 | static enum sci_status scic_sds_port_ready_waiting_substate_start_io_handler( | |
1119 | struct scic_sds_port *port, | |
1120 | struct scic_sds_remote_device *device, | |
1121 | struct scic_sds_request *io_request) | |
1122 | { | |
1123 | return SCI_FAILURE_INVALID_STATE; | |
1124 | } | |
1125 | ||
1126 | /* | |
1127 | * **************************************************************************** | |
1128 | * * READY SUBSTATE OPERATIONAL HANDLERS | |
1129 | * **************************************************************************** */ | |
1130 | ||
41e2b905 | 1131 | /* |
6f231dda DW |
1132 | * This method will casue the port to reset. enum sci_status SCI_SUCCESS |
1133 | */ | |
09d7da13 DJ |
1134 | static enum |
1135 | sci_status scic_sds_port_ready_operational_substate_reset_handler( | |
41e2b905 | 1136 | struct scic_sds_port *port, |
09d7da13 | 1137 | u32 timeout) |
6f231dda DW |
1138 | { |
1139 | enum sci_status status = SCI_FAILURE_INVALID_PHY; | |
1140 | u32 phy_index; | |
a7e536c7 | 1141 | struct scic_sds_phy *selected_phy = NULL; |
6f231dda DW |
1142 | |
1143 | ||
1144 | /* Select a phy on which we can send the hard reset request. */ | |
09d7da13 DJ |
1145 | for (phy_index = 0; |
1146 | (phy_index < SCI_MAX_PHYS) && (selected_phy == NULL); | |
1147 | phy_index++) { | |
41e2b905 | 1148 | selected_phy = port->phy_table[phy_index]; |
09d7da13 DJ |
1149 | |
1150 | if ((selected_phy != NULL) && | |
41e2b905 | 1151 | !scic_sds_port_active_phy(port, selected_phy)) { |
09d7da13 DJ |
1152 | /* |
1153 | * We found a phy but it is not ready select | |
1154 | * different phy | |
1155 | */ | |
a7e536c7 | 1156 | selected_phy = NULL; |
6f231dda DW |
1157 | } |
1158 | } | |
1159 | ||
1160 | /* If we have a phy then go ahead and start the reset procedure */ | |
a7e536c7 | 1161 | if (selected_phy != NULL) { |
6f231dda DW |
1162 | status = scic_sds_phy_reset(selected_phy); |
1163 | ||
1164 | if (status == SCI_SUCCESS) { | |
41e2b905 MT |
1165 | isci_timer_start(port->timer_handle, timeout); |
1166 | port->not_ready_reason = | |
09d7da13 | 1167 | SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED; |
6f231dda DW |
1168 | |
1169 | sci_base_state_machine_change_state( | |
41e2b905 | 1170 | &port->state_machine, |
09d7da13 | 1171 | SCI_BASE_PORT_STATE_RESETTING); |
6f231dda DW |
1172 | } |
1173 | } | |
1174 | ||
1175 | return status; | |
1176 | } | |
1177 | ||
1178 | /** | |
1179 | * scic_sds_port_ready_operational_substate_link_up_handler() - | |
e2023b87 | 1180 | * @sci_port: This is the struct scic_sds_port object that which has a phy that has |
6f231dda | 1181 | * gone link up. |
e2023b87 | 1182 | * @sci_phy: This is the struct scic_sds_phy object that has gone link up. |
6f231dda DW |
1183 | * |
1184 | * This method is the ready operational substate link up handler for the | |
1185 | * struct scic_sds_port object. This function notifies the SCI User that the phy has | |
1186 | * gone link up. none | |
1187 | */ | |
1188 | static void scic_sds_port_ready_operational_substate_link_up_handler( | |
e2023b87 DJ |
1189 | struct scic_sds_port *sci_port, |
1190 | struct scic_sds_phy *sci_phy) | |
6f231dda | 1191 | { |
e2023b87 | 1192 | scic_sds_port_general_link_up_handler(sci_port, sci_phy, true); |
6f231dda DW |
1193 | } |
1194 | ||
1195 | /** | |
1196 | * scic_sds_port_ready_operational_substate_link_down_handler() - | |
068b2c03 | 1197 | * @sci_port: This is the struct scic_sds_port object that which has a phy that has |
6f231dda | 1198 | * gone link down. |
068b2c03 | 1199 | * @sci_phy: This is the struct scic_sds_phy object that has gone link down. |
6f231dda DW |
1200 | * |
1201 | * This method is the ready operational substate link down handler for the | |
1202 | * struct scic_sds_port object. This function notifies the SCI User that the phy has | |
1203 | * gone link down and if this is the last phy in the port the port will change | |
1204 | * state to the ready waiting substate. none | |
1205 | */ | |
1206 | static void scic_sds_port_ready_operational_substate_link_down_handler( | |
068b2c03 DW |
1207 | struct scic_sds_port *sci_port, |
1208 | struct scic_sds_phy *sci_phy) | |
6f231dda | 1209 | { |
068b2c03 | 1210 | scic_sds_port_deactivate_phy(sci_port, sci_phy, true); |
6f231dda DW |
1211 | |
1212 | /* | |
1213 | * If there are no active phys left in the port, then transition | |
1214 | * the port to the WAITING state until such time as a phy goes | |
1215 | * link up. */ | |
068b2c03 DW |
1216 | if (sci_port->active_phy_mask == 0) |
1217 | sci_base_state_machine_change_state(&sci_port->ready_substate_machine, | |
1218 | SCIC_SDS_PORT_READY_SUBSTATE_WAITING); | |
6f231dda DW |
1219 | } |
1220 | ||
38aa74eb | 1221 | /* |
6f231dda DW |
1222 | * This method is the ready operational substate start io handler for the |
1223 | * struct scic_sds_port object. This function incremetns the outstanding request | |
1224 | * count for this port object. enum sci_status SCI_SUCCESS | |
1225 | */ | |
1226 | static enum sci_status scic_sds_port_ready_operational_substate_start_io_handler( | |
1227 | struct scic_sds_port *port, | |
1228 | struct scic_sds_remote_device *device, | |
1229 | struct scic_sds_request *io_request) | |
1230 | { | |
b9988b8e | 1231 | port->started_request_count++; |
6f231dda DW |
1232 | return SCI_SUCCESS; |
1233 | } | |
1234 | ||
1235 | /* | |
1236 | * **************************************************************************** | |
1237 | * * READY SUBSTATE OPERATIONAL HANDLERS | |
1238 | * **************************************************************************** */ | |
1239 | ||
41e2b905 | 1240 | /* |
6f231dda DW |
1241 | * This is the default method for a port add phy request. It will report a |
1242 | * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE | |
1243 | */ | |
1244 | static enum sci_status scic_sds_port_ready_configuring_substate_add_phy_handler( | |
41e2b905 | 1245 | struct scic_sds_port *port, |
d857d9a0 | 1246 | struct scic_sds_phy *phy) |
6f231dda | 1247 | { |
6f231dda DW |
1248 | enum sci_status status; |
1249 | ||
d857d9a0 | 1250 | status = scic_sds_port_set_phy(port, phy); |
6f231dda DW |
1251 | |
1252 | if (status == SCI_SUCCESS) { | |
d857d9a0 | 1253 | scic_sds_port_general_link_up_handler(port, phy, true); |
6f231dda DW |
1254 | |
1255 | /* | |
1256 | * Re-enter the configuring state since this may be the last phy in | |
1257 | * the port. */ | |
1258 | sci_base_state_machine_change_state( | |
41e2b905 | 1259 | &port->ready_substate_machine, |
6f231dda DW |
1260 | SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING |
1261 | ); | |
1262 | } | |
1263 | ||
1264 | return status; | |
1265 | } | |
1266 | ||
41e2b905 | 1267 | /* |
6f231dda DW |
1268 | * This is the default method for a port remove phy request. It will report a |
1269 | * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE | |
1270 | */ | |
1271 | static enum sci_status scic_sds_port_ready_configuring_substate_remove_phy_handler( | |
41e2b905 | 1272 | struct scic_sds_port *port, |
d857d9a0 | 1273 | struct scic_sds_phy *phy) |
6f231dda | 1274 | { |
6f231dda DW |
1275 | enum sci_status status; |
1276 | ||
d857d9a0 | 1277 | status = scic_sds_port_clear_phy(port, phy); |
6f231dda DW |
1278 | |
1279 | if (status == SCI_SUCCESS) { | |
d857d9a0 | 1280 | scic_sds_port_deactivate_phy(port, phy, true); |
6f231dda DW |
1281 | |
1282 | /* | |
1283 | * Re-enter the configuring state since this may be the last phy in | |
1284 | * the port. */ | |
1285 | sci_base_state_machine_change_state( | |
41e2b905 | 1286 | &port->ready_substate_machine, |
6f231dda DW |
1287 | SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING |
1288 | ); | |
1289 | } | |
1290 | ||
1291 | return status; | |
1292 | } | |
1293 | ||
1294 | /** | |
1295 | * scic_sds_port_ready_configuring_substate_complete_io_handler() - | |
1296 | * @port: This is the port that is being requested to complete the io request. | |
1297 | * @device: This is the device on which the io is completing. | |
1298 | * | |
1299 | * This method will decrement the outstanding request count for this port. If | |
1300 | * the request count goes to 0 then the port can be reprogrammed with its new | |
1301 | * phy data. | |
1302 | */ | |
41e2b905 MT |
1303 | static enum sci_status |
1304 | scic_sds_port_ready_configuring_substate_complete_io_handler( | |
6f231dda DW |
1305 | struct scic_sds_port *port, |
1306 | struct scic_sds_remote_device *device, | |
1307 | struct scic_sds_request *io_request) | |
1308 | { | |
1309 | scic_sds_port_decrement_request_count(port); | |
1310 | ||
1311 | if (port->started_request_count == 0) { | |
1312 | sci_base_state_machine_change_state( | |
1313 | &port->ready_substate_machine, | |
1314 | SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL | |
1315 | ); | |
1316 | } | |
1317 | ||
1318 | return SCI_SUCCESS; | |
1319 | } | |
1320 | ||
41e2b905 MT |
1321 | static enum sci_status default_port_handler(struct scic_sds_port *sci_port, |
1322 | const char *func) | |
35173d57 | 1323 | { |
35173d57 DW |
1324 | dev_warn(sciport_to_dev(sci_port), |
1325 | "%s: in wrong state: %d\n", func, | |
41e2b905 | 1326 | sci_base_state_machine_get_state(&sci_port->state_machine)); |
35173d57 DW |
1327 | return SCI_FAILURE_INVALID_STATE; |
1328 | } | |
1329 | ||
41e2b905 MT |
1330 | static enum sci_status |
1331 | scic_sds_port_default_start_handler(struct scic_sds_port *sci_port) | |
35173d57 | 1332 | { |
41e2b905 | 1333 | return default_port_handler(sci_port, __func__); |
35173d57 DW |
1334 | } |
1335 | ||
41e2b905 MT |
1336 | static enum sci_status |
1337 | scic_sds_port_default_stop_handler(struct scic_sds_port *sci_port) | |
35173d57 | 1338 | { |
41e2b905 | 1339 | return default_port_handler(sci_port, __func__); |
35173d57 DW |
1340 | } |
1341 | ||
41e2b905 MT |
1342 | static enum sci_status |
1343 | scic_sds_port_default_destruct_handler(struct scic_sds_port *sci_port) | |
35173d57 | 1344 | { |
41e2b905 | 1345 | return default_port_handler(sci_port, __func__); |
35173d57 DW |
1346 | } |
1347 | ||
41e2b905 MT |
1348 | static enum sci_status |
1349 | scic_sds_port_default_reset_handler(struct scic_sds_port *sci_port, | |
1350 | u32 timeout) | |
35173d57 | 1351 | { |
41e2b905 | 1352 | return default_port_handler(sci_port, __func__); |
35173d57 DW |
1353 | } |
1354 | ||
41e2b905 MT |
1355 | static enum sci_status |
1356 | scic_sds_port_default_add_phy_handler(struct scic_sds_port *sci_port, | |
d857d9a0 | 1357 | struct scic_sds_phy *base_phy) |
35173d57 | 1358 | { |
41e2b905 | 1359 | return default_port_handler(sci_port, __func__); |
35173d57 DW |
1360 | } |
1361 | ||
41e2b905 MT |
1362 | static enum sci_status |
1363 | scic_sds_port_default_remove_phy_handler(struct scic_sds_port *sci_port, | |
d857d9a0 | 1364 | struct scic_sds_phy *base_phy) |
35173d57 | 1365 | { |
41e2b905 | 1366 | return default_port_handler(sci_port, __func__); |
35173d57 DW |
1367 | } |
1368 | ||
41e2b905 | 1369 | /* |
35173d57 DW |
1370 | * This is the default method for a port unsolicited frame request. It will |
1371 | * report a warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE Is it even | |
1372 | * possible to receive an unsolicited frame directed to a port object? It | |
1373 | * seems possible if we implementing virtual functions but until then? | |
1374 | */ | |
41e2b905 MT |
1375 | static enum sci_status |
1376 | scic_sds_port_default_frame_handler(struct scic_sds_port *sci_port, | |
1377 | u32 frame_index) | |
35173d57 DW |
1378 | { |
1379 | struct scic_sds_controller *scic = scic_sds_port_get_controller(sci_port); | |
1380 | ||
41e2b905 | 1381 | default_port_handler(sci_port, __func__); |
35173d57 DW |
1382 | scic_sds_controller_release_frame(scic, frame_index); |
1383 | ||
1384 | return SCI_FAILURE_INVALID_STATE; | |
1385 | } | |
1386 | ||
1387 | static enum sci_status scic_sds_port_default_event_handler(struct scic_sds_port *sci_port, | |
1388 | u32 event_code) | |
1389 | { | |
41e2b905 | 1390 | return default_port_handler(sci_port, __func__); |
35173d57 DW |
1391 | } |
1392 | ||
1393 | static void scic_sds_port_default_link_up_handler(struct scic_sds_port *sci_port, | |
1394 | struct scic_sds_phy *sci_phy) | |
1395 | { | |
41e2b905 | 1396 | default_port_handler(sci_port, __func__); |
35173d57 DW |
1397 | } |
1398 | ||
1399 | static void scic_sds_port_default_link_down_handler(struct scic_sds_port *sci_port, | |
1400 | struct scic_sds_phy *sci_phy) | |
1401 | { | |
41e2b905 | 1402 | default_port_handler(sci_port, __func__); |
35173d57 | 1403 | } |
6f231dda | 1404 | |
35173d57 DW |
1405 | static enum sci_status scic_sds_port_default_start_io_handler(struct scic_sds_port *sci_port, |
1406 | struct scic_sds_remote_device *sci_dev, | |
1407 | struct scic_sds_request *sci_req) | |
1408 | { | |
41e2b905 | 1409 | return default_port_handler(sci_port, __func__); |
35173d57 DW |
1410 | } |
1411 | ||
1412 | static enum sci_status scic_sds_port_default_complete_io_handler(struct scic_sds_port *sci_port, | |
1413 | struct scic_sds_remote_device *sci_dev, | |
1414 | struct scic_sds_request *sci_req) | |
1415 | { | |
41e2b905 | 1416 | return default_port_handler(sci_port, __func__); |
35173d57 DW |
1417 | } |
1418 | ||
1419 | ||
1420 | ||
1421 | static struct scic_sds_port_state_handler | |
41e2b905 | 1422 | scic_sds_port_ready_substate_handler_table[SCIC_SDS_PORT_READY_MAX_SUBSTATES] = { |
6f231dda | 1423 | { |
41e2b905 MT |
1424 | /* SCIC_SDS_PORT_READY_SUBSTATE_WAITING */ |
1425 | scic_sds_port_default_start_handler, | |
1426 | scic_sds_port_ready_substate_stop_handler, | |
1427 | scic_sds_port_default_destruct_handler, | |
1428 | scic_sds_port_default_reset_handler, | |
1429 | scic_sds_port_ready_substate_add_phy_handler, | |
1430 | scic_sds_port_default_remove_phy_handler, | |
6f231dda DW |
1431 | scic_sds_port_default_frame_handler, |
1432 | scic_sds_port_default_event_handler, | |
1433 | scic_sds_port_ready_waiting_substate_link_up_handler, | |
1434 | scic_sds_port_default_link_down_handler, | |
1435 | scic_sds_port_ready_waiting_substate_start_io_handler, | |
1436 | scic_sds_port_ready_substate_complete_io_handler, | |
1437 | }, | |
41e2b905 | 1438 | |
6f231dda | 1439 | { |
41e2b905 MT |
1440 | /* SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL */ |
1441 | scic_sds_port_default_start_handler, | |
1442 | scic_sds_port_ready_substate_stop_handler, | |
1443 | scic_sds_port_default_destruct_handler, | |
1444 | scic_sds_port_ready_operational_substate_reset_handler, | |
1445 | scic_sds_port_ready_substate_add_phy_handler, | |
1446 | scic_sds_port_ready_substate_remove_phy_handler, | |
6f231dda DW |
1447 | scic_sds_port_default_frame_handler, |
1448 | scic_sds_port_default_event_handler, | |
1449 | scic_sds_port_ready_operational_substate_link_up_handler, | |
1450 | scic_sds_port_ready_operational_substate_link_down_handler, | |
1451 | scic_sds_port_ready_operational_substate_start_io_handler, | |
41e2b905 | 1452 | scic_sds_port_ready_substate_complete_io_handler, |
6f231dda | 1453 | }, |
41e2b905 | 1454 | |
6f231dda | 1455 | { |
41e2b905 MT |
1456 | /* SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING */ |
1457 | scic_sds_port_default_start_handler, | |
1458 | scic_sds_port_ready_substate_stop_handler, | |
1459 | scic_sds_port_default_destruct_handler, | |
1460 | scic_sds_port_default_reset_handler, | |
1461 | scic_sds_port_ready_configuring_substate_add_phy_handler, | |
1462 | scic_sds_port_ready_configuring_substate_remove_phy_handler, | |
6f231dda DW |
1463 | scic_sds_port_default_frame_handler, |
1464 | scic_sds_port_default_event_handler, | |
1465 | scic_sds_port_default_link_up_handler, | |
1466 | scic_sds_port_default_link_down_handler, | |
1467 | scic_sds_port_default_start_io_handler, | |
1468 | scic_sds_port_ready_configuring_substate_complete_io_handler | |
1469 | } | |
1470 | }; | |
1471 | ||
6f231dda DW |
1472 | /** |
1473 | * scic_sds_port_set_ready_state_handlers() - | |
1474 | * | |
1475 | * This macro sets the port ready substate handlers. | |
1476 | */ | |
1477 | #define scic_sds_port_set_ready_state_handlers(port, state_id) \ | |
1478 | scic_sds_port_set_state_handlers(\ | |
1479 | port, &scic_sds_port_ready_substate_handler_table[(state_id)] \ | |
1480 | ) | |
1481 | ||
1482 | /* | |
1483 | * ****************************************************************************** | |
1484 | * * PORT STATE PRIVATE METHODS | |
1485 | * ****************************************************************************** */ | |
1486 | ||
1487 | /** | |
1488 | * | |
e2023b87 | 1489 | * @sci_port: This is the struct scic_sds_port object to suspend. |
6f231dda DW |
1490 | * |
1491 | * This method will susped the port task scheduler for this port object. none | |
1492 | */ | |
bc99aa47 CH |
1493 | static void |
1494 | scic_sds_port_suspend_port_task_scheduler(struct scic_sds_port *port) | |
6f231dda DW |
1495 | { |
1496 | u32 pts_control_value; | |
6f231dda | 1497 | |
bc99aa47 | 1498 | pts_control_value = readl(&port->port_task_scheduler_registers->control); |
6f231dda | 1499 | pts_control_value |= SCU_PTSxCR_GEN_BIT(SUSPEND); |
bc99aa47 | 1500 | writel(pts_control_value, &port->port_task_scheduler_registers->control); |
6f231dda DW |
1501 | } |
1502 | ||
a8d4b9fe TC |
1503 | /** |
1504 | * scic_sds_port_post_dummy_request() - post dummy/workaround request | |
1505 | * @sci_port: port to post task | |
1506 | * | |
1507 | * Prevent the hardware scheduler from posting new requests to the front | |
1508 | * of the scheduler queue causing a starvation problem for currently | |
1509 | * ongoing requests. | |
1510 | * | |
1511 | */ | |
35173d57 | 1512 | static void scic_sds_port_post_dummy_request(struct scic_sds_port *sci_port) |
a8d4b9fe TC |
1513 | { |
1514 | u32 command; | |
1515 | struct scu_task_context *task_context; | |
1516 | struct scic_sds_controller *scic = sci_port->owning_controller; | |
1517 | u16 tci = sci_port->reserved_tci; | |
1518 | ||
1519 | task_context = scic_sds_controller_get_task_context_buffer(scic, tci); | |
1520 | ||
1521 | task_context->abort = 0; | |
1522 | ||
1523 | command = SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC | | |
1524 | sci_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | | |
1525 | tci; | |
1526 | ||
1527 | scic_sds_controller_post_request(scic, command); | |
1528 | } | |
1529 | ||
1530 | /** | |
1531 | * This routine will abort the dummy request. This will alow the hardware to | |
1532 | * power down parts of the silicon to save power. | |
1533 | * | |
1534 | * @sci_port: The port on which the task must be aborted. | |
1535 | * | |
1536 | */ | |
35173d57 | 1537 | static void scic_sds_port_abort_dummy_request(struct scic_sds_port *sci_port) |
a8d4b9fe TC |
1538 | { |
1539 | struct scic_sds_controller *scic = sci_port->owning_controller; | |
1540 | u16 tci = sci_port->reserved_tci; | |
1541 | struct scu_task_context *tc; | |
1542 | u32 command; | |
1543 | ||
1544 | tc = scic_sds_controller_get_task_context_buffer(scic, tci); | |
1545 | ||
1546 | tc->abort = 1; | |
1547 | ||
1548 | command = SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT | | |
1549 | sci_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | | |
1550 | tci; | |
1551 | ||
1552 | scic_sds_controller_post_request(scic, command); | |
1553 | } | |
1554 | ||
6f231dda DW |
1555 | /** |
1556 | * | |
e2023b87 | 1557 | * @sci_port: This is the struct scic_sds_port object to resume. |
6f231dda DW |
1558 | * |
1559 | * This method will resume the port task scheduler for this port object. none | |
1560 | */ | |
bc99aa47 CH |
1561 | static void |
1562 | scic_sds_port_resume_port_task_scheduler(struct scic_sds_port *port) | |
6f231dda DW |
1563 | { |
1564 | u32 pts_control_value; | |
1565 | ||
bc99aa47 | 1566 | pts_control_value = readl(&port->port_task_scheduler_registers->control); |
6f231dda | 1567 | pts_control_value &= ~SCU_PTSxCR_GEN_BIT(SUSPEND); |
bc99aa47 | 1568 | writel(pts_control_value, &port->port_task_scheduler_registers->control); |
6f231dda DW |
1569 | } |
1570 | ||
1571 | /* | |
1572 | * ****************************************************************************** | |
1573 | * * PORT READY SUBSTATE METHODS | |
1574 | * ****************************************************************************** */ | |
1575 | ||
1576 | /** | |
1577 | * | |
9a0fff7b | 1578 | * @object: This is the object which is cast to a struct scic_sds_port object. |
6f231dda DW |
1579 | * |
1580 | * This method will perform the actions required by the struct scic_sds_port on | |
1581 | * entering the SCIC_SDS_PORT_READY_SUBSTATE_WAITING. This function checks the | |
1582 | * port for any ready phys. If there is at least one phy in a ready state then | |
1583 | * the port transitions to the ready operational substate. none | |
1584 | */ | |
9a0fff7b | 1585 | static void scic_sds_port_ready_substate_waiting_enter(void *object) |
6f231dda | 1586 | { |
115bd1f9 | 1587 | struct scic_sds_port *sci_port = object; |
6f231dda DW |
1588 | |
1589 | scic_sds_port_set_ready_state_handlers( | |
e2023b87 | 1590 | sci_port, SCIC_SDS_PORT_READY_SUBSTATE_WAITING |
6f231dda DW |
1591 | ); |
1592 | ||
e2023b87 | 1593 | scic_sds_port_suspend_port_task_scheduler(sci_port); |
6f231dda | 1594 | |
e2023b87 | 1595 | sci_port->not_ready_reason = SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS; |
6f231dda | 1596 | |
e2023b87 | 1597 | if (sci_port->active_phy_mask != 0) { |
6f231dda DW |
1598 | /* At least one of the phys on the port is ready */ |
1599 | sci_base_state_machine_change_state( | |
e2023b87 | 1600 | &sci_port->ready_substate_machine, |
6f231dda DW |
1601 | SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL |
1602 | ); | |
1603 | } | |
1604 | } | |
1605 | ||
1606 | /** | |
1607 | * | |
9a0fff7b | 1608 | * @object: This is the object which is cast to a struct scic_sds_port object. |
6f231dda | 1609 | * |
09d7da13 DJ |
1610 | * This function will perform the actions required by the struct scic_sds_port |
1611 | * on entering the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function sets | |
6f231dda DW |
1612 | * the state handlers for the port object, notifies the SCI User that the port |
1613 | * is ready, and resumes port operations. none | |
1614 | */ | |
9a0fff7b | 1615 | static void scic_sds_port_ready_substate_operational_enter(void *object) |
6f231dda DW |
1616 | { |
1617 | u32 index; | |
115bd1f9 | 1618 | struct scic_sds_port *sci_port = object; |
e531381e | 1619 | struct scic_sds_controller *scic = sci_port->owning_controller; |
cc3dbd0a | 1620 | struct isci_host *ihost = scic_to_ihost(scic); |
e531381e | 1621 | struct isci_port *iport = sci_port_to_iport(sci_port); |
6f231dda DW |
1622 | |
1623 | scic_sds_port_set_ready_state_handlers( | |
09d7da13 DJ |
1624 | sci_port, |
1625 | SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL); | |
6f231dda | 1626 | |
09d7da13 | 1627 | isci_port_ready(ihost, iport); |
6f231dda DW |
1628 | |
1629 | for (index = 0; index < SCI_MAX_PHYS; index++) { | |
bc99aa47 CH |
1630 | if (sci_port->phy_table[index]) { |
1631 | writel(sci_port->physical_port_index, | |
1632 | &sci_port->port_pe_configuration_register[ | |
1633 | sci_port->phy_table[index]->phy_index]); | |
1634 | } | |
6f231dda DW |
1635 | } |
1636 | ||
09d7da13 | 1637 | scic_sds_port_update_viit_entry(sci_port); |
6f231dda | 1638 | |
09d7da13 | 1639 | scic_sds_port_resume_port_task_scheduler(sci_port); |
a8d4b9fe | 1640 | |
09d7da13 DJ |
1641 | /* |
1642 | * Post the dummy task for the port so the hardware can schedule | |
a8d4b9fe TC |
1643 | * io correctly |
1644 | */ | |
09d7da13 | 1645 | scic_sds_port_post_dummy_request(sci_port); |
6f231dda DW |
1646 | } |
1647 | ||
1648 | /** | |
1649 | * | |
9a0fff7b | 1650 | * @object: This is the object which is cast to a struct scic_sds_port object. |
6f231dda DW |
1651 | * |
1652 | * This method will perform the actions required by the struct scic_sds_port on | |
1653 | * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports | |
1654 | * the port not ready and suspends the port task scheduler. none | |
1655 | */ | |
9a0fff7b | 1656 | static void scic_sds_port_ready_substate_operational_exit(void *object) |
6f231dda | 1657 | { |
115bd1f9 | 1658 | struct scic_sds_port *sci_port = object; |
e531381e | 1659 | struct scic_sds_controller *scic = sci_port->owning_controller; |
cc3dbd0a | 1660 | struct isci_host *ihost = scic_to_ihost(scic); |
e531381e | 1661 | struct isci_port *iport = sci_port_to_iport(sci_port); |
6f231dda | 1662 | |
09d7da13 DJ |
1663 | /* |
1664 | * Kill the dummy task for this port if it has not yet posted | |
1665 | * the hardware will treat this as a NOP and just return abort | |
1666 | * complete. | |
1667 | */ | |
1668 | scic_sds_port_abort_dummy_request(sci_port); | |
27ce51df | 1669 | |
09d7da13 | 1670 | isci_port_not_ready(ihost, iport); |
6f231dda DW |
1671 | } |
1672 | ||
1673 | /* | |
1674 | * ****************************************************************************** | |
1675 | * * PORT READY CONFIGURING METHODS | |
1676 | * ****************************************************************************** */ | |
1677 | ||
1678 | /** | |
1679 | * scic_sds_port_ready_substate_configuring_enter() - | |
9a0fff7b | 1680 | * @object: This is the object which is cast to a struct scic_sds_port object. |
6f231dda DW |
1681 | * |
1682 | * This method will perform the actions required by the struct scic_sds_port on | |
1683 | * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports | |
1684 | * the port not ready and suspends the port task scheduler. none | |
1685 | */ | |
9a0fff7b | 1686 | static void scic_sds_port_ready_substate_configuring_enter(void *object) |
6f231dda | 1687 | { |
115bd1f9 | 1688 | struct scic_sds_port *sci_port = object; |
e531381e | 1689 | struct scic_sds_controller *scic = sci_port->owning_controller; |
cc3dbd0a | 1690 | struct isci_host *ihost = scic_to_ihost(scic); |
e531381e | 1691 | struct isci_port *iport = sci_port_to_iport(sci_port); |
6f231dda DW |
1692 | |
1693 | scic_sds_port_set_ready_state_handlers( | |
09d7da13 DJ |
1694 | sci_port, |
1695 | SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING); | |
6f231dda | 1696 | |
09d7da13 DJ |
1697 | if (sci_port->active_phy_mask == 0) { |
1698 | isci_port_not_ready(ihost, iport); | |
6f231dda DW |
1699 | |
1700 | sci_base_state_machine_change_state( | |
09d7da13 DJ |
1701 | &sci_port->ready_substate_machine, |
1702 | SCIC_SDS_PORT_READY_SUBSTATE_WAITING); | |
1703 | } else if (sci_port->started_request_count == 0) | |
6f231dda | 1704 | sci_base_state_machine_change_state( |
09d7da13 DJ |
1705 | &sci_port->ready_substate_machine, |
1706 | SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL); | |
6f231dda DW |
1707 | } |
1708 | ||
9a0fff7b | 1709 | static void scic_sds_port_ready_substate_configuring_exit(void *object) |
6f231dda | 1710 | { |
115bd1f9 | 1711 | struct scic_sds_port *sci_port = object; |
6f231dda | 1712 | |
e2023b87 | 1713 | scic_sds_port_suspend_port_task_scheduler(sci_port); |
6f231dda DW |
1714 | } |
1715 | ||
1716 | /* --------------------------------------------------------------------------- */ | |
1717 | ||
35173d57 | 1718 | static const struct sci_base_state scic_sds_port_ready_substate_table[] = { |
6f231dda DW |
1719 | [SCIC_SDS_PORT_READY_SUBSTATE_WAITING] = { |
1720 | .enter_state = scic_sds_port_ready_substate_waiting_enter, | |
1721 | }, | |
1722 | [SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL] = { | |
1723 | .enter_state = scic_sds_port_ready_substate_operational_enter, | |
1724 | .exit_state = scic_sds_port_ready_substate_operational_exit | |
1725 | }, | |
1726 | [SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING] = { | |
1727 | .enter_state = scic_sds_port_ready_substate_configuring_enter, | |
1728 | .exit_state = scic_sds_port_ready_substate_configuring_exit | |
1729 | }, | |
1730 | }; | |
1731 | ||
6f231dda DW |
1732 | /** |
1733 | * | |
1734 | * @port: This is the struct scic_sds_port object on which the io request count will | |
1735 | * be decremented. | |
1736 | * @device: This is the struct scic_sds_remote_device object to which the io request | |
1737 | * is being directed. This parameter is not required to complete this | |
1738 | * operation. | |
1739 | * @io_request: This is the request that is being completed on this port | |
1740 | * object. This parameter is not required to complete this operation. | |
1741 | * | |
1742 | * This is a general complete io request handler for the struct scic_sds_port object. | |
1743 | * enum sci_status SCI_SUCCESS | |
1744 | */ | |
1745 | static enum sci_status scic_sds_port_general_complete_io_handler( | |
1746 | struct scic_sds_port *port, | |
1747 | struct scic_sds_remote_device *device, | |
1748 | struct scic_sds_request *io_request) | |
1749 | { | |
41e2b905 | 1750 | scic_sds_port_decrement_request_count(port); |
6f231dda DW |
1751 | |
1752 | return SCI_SUCCESS; | |
1753 | } | |
1754 | ||
6f231dda | 1755 | /** |
a8d4b9fe | 1756 | * scic_sds_port_stopped_state_start_handler() - stop a port from "started" |
6f231dda | 1757 | * |
41e2b905 | 1758 | * @port: This is the struct scic_sds_port object which is cast into a |
09d7da13 | 1759 | * struct scic_sds_port object. |
6f231dda | 1760 | * |
09d7da13 DJ |
1761 | * This function takes the struct scic_sds_port from a stopped state and |
1762 | * attempts to start it. To start a port it must have no assiged devices and | |
1763 | * it must have at least one phy assigned to it. If those conditions are | |
1764 | * met then the port can transition to the ready state. | |
1765 | * enum sci_status | |
1766 | * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION | |
1767 | * This struct scic_sds_port object could not be started because the port | |
1768 | * configuration is not valid. | |
1769 | * SCI_SUCCESS | |
1770 | * the start request is successful and the struct scic_sds_port object | |
1771 | * has transitioned to the SCI_BASE_PORT_STATE_READY. | |
6f231dda | 1772 | */ |
09d7da13 | 1773 | static enum sci_status |
41e2b905 | 1774 | scic_sds_port_stopped_state_start_handler(struct scic_sds_port *sci_port) |
6f231dda | 1775 | { |
a8d4b9fe | 1776 | struct scic_sds_controller *scic = sci_port->owning_controller; |
cc3dbd0a | 1777 | struct isci_host *ihost = scic_to_ihost(scic); |
a8d4b9fe | 1778 | enum sci_status status = SCI_SUCCESS; |
6f231dda | 1779 | u32 phy_mask; |
6f231dda | 1780 | |
a8d4b9fe | 1781 | if (sci_port->assigned_device_count > 0) { |
6f231dda | 1782 | /* |
09d7da13 DJ |
1783 | * @todo This is a start failure operation because |
1784 | * there are still devices assigned to this port. | |
1785 | * There must be no devices assigned to a port on a | |
1786 | * start operation. | |
1787 | */ | |
6f231dda DW |
1788 | return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION; |
1789 | } | |
1790 | ||
09d7da13 DJ |
1791 | sci_port->timer_handle = |
1792 | isci_timer_create(ihost, | |
1793 | sci_port, | |
1794 | scic_sds_port_timeout_handler); | |
6f231dda | 1795 | |
a8d4b9fe TC |
1796 | if (!sci_port->timer_handle) |
1797 | return SCI_FAILURE_INSUFFICIENT_RESOURCES; | |
6f231dda | 1798 | |
a8d4b9fe | 1799 | if (sci_port->reserved_rni == SCU_DUMMY_INDEX) { |
09d7da13 DJ |
1800 | u16 rni = scic_sds_remote_node_table_allocate_remote_node( |
1801 | &scic->available_remote_nodes, 1); | |
a8d4b9fe TC |
1802 | |
1803 | if (rni != SCU_DUMMY_INDEX) | |
1804 | scic_sds_port_construct_dummy_rnc(sci_port, rni); | |
1805 | else | |
1806 | status = SCI_FAILURE_INSUFFICIENT_RESOURCES; | |
1807 | sci_port->reserved_rni = rni; | |
1808 | } | |
1809 | ||
1810 | if (sci_port->reserved_tci == SCU_DUMMY_INDEX) { | |
1811 | /* Allocate a TCI and remove the sequence nibble */ | |
1812 | u16 tci = scic_controller_allocate_io_tag(scic); | |
1813 | ||
1814 | if (tci != SCU_DUMMY_INDEX) | |
1815 | scic_sds_port_construct_dummy_task(sci_port, tci); | |
1816 | else | |
1817 | status = SCI_FAILURE_INSUFFICIENT_RESOURCES; | |
1818 | sci_port->reserved_tci = tci; | |
1819 | } | |
1820 | ||
1821 | if (status == SCI_SUCCESS) { | |
1822 | phy_mask = scic_sds_port_get_phys(sci_port); | |
1823 | ||
1824 | /* | |
1825 | * There are one or more phys assigned to this port. Make sure | |
1826 | * the port's phy mask is in fact legal and supported by the | |
1827 | * silicon. | |
1828 | */ | |
1829 | if (scic_sds_port_is_phy_mask_valid(sci_port, phy_mask) == true) { | |
41e2b905 MT |
1830 | sci_base_state_machine_change_state( |
1831 | &sci_port->state_machine, | |
1832 | SCI_BASE_PORT_STATE_READY); | |
a8d4b9fe TC |
1833 | |
1834 | return SCI_SUCCESS; | |
1835 | } else | |
1836 | status = SCI_FAILURE; | |
6f231dda DW |
1837 | } |
1838 | ||
a8d4b9fe TC |
1839 | if (status != SCI_SUCCESS) |
1840 | scic_sds_port_destroy_dummy_resources(sci_port); | |
1841 | ||
1842 | return status; | |
6f231dda DW |
1843 | } |
1844 | ||
41e2b905 | 1845 | /* |
6f231dda DW |
1846 | * This method takes the struct scic_sds_port that is in a stopped state and handles a |
1847 | * stop request. This function takes no action. enum sci_status SCI_SUCCESS the | |
1848 | * stop request is successful as the struct scic_sds_port object is already stopped. | |
1849 | */ | |
1850 | static enum sci_status scic_sds_port_stopped_state_stop_handler( | |
41e2b905 | 1851 | struct scic_sds_port *port) |
6f231dda DW |
1852 | { |
1853 | /* We are already stopped so there is nothing to do here */ | |
1854 | return SCI_SUCCESS; | |
1855 | } | |
1856 | ||
41e2b905 | 1857 | /* |
6f231dda DW |
1858 | * This method takes the struct scic_sds_port that is in a stopped state and handles |
1859 | * the destruct request. The stopped state is the only state in which the | |
1860 | * struct scic_sds_port can be destroyed. This function causes the port object to | |
1861 | * transition to the SCI_BASE_PORT_STATE_FINAL. enum sci_status SCI_SUCCESS | |
1862 | */ | |
1863 | static enum sci_status scic_sds_port_stopped_state_destruct_handler( | |
41e2b905 | 1864 | struct scic_sds_port *port) |
6f231dda | 1865 | { |
41e2b905 | 1866 | sci_base_state_machine_stop(&port->state_machine); |
6f231dda DW |
1867 | |
1868 | return SCI_SUCCESS; | |
1869 | } | |
1870 | ||
41e2b905 | 1871 | /* |
6f231dda DW |
1872 | * This method takes the struct scic_sds_port that is in a stopped state and handles |
1873 | * the add phy request. In MPC mode the only time a phy can be added to a port | |
1874 | * is in the SCI_BASE_PORT_STATE_STOPPED. enum sci_status | |
1875 | * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION is returned when the phy can not | |
1876 | * be added to the port. SCI_SUCCESS if the phy is added to the port. | |
1877 | */ | |
1878 | static enum sci_status scic_sds_port_stopped_state_add_phy_handler( | |
41e2b905 | 1879 | struct scic_sds_port *port, |
d857d9a0 | 1880 | struct scic_sds_phy *phy) |
6f231dda | 1881 | { |
6f231dda DW |
1882 | struct sci_sas_address port_sas_address; |
1883 | ||
1884 | /* Read the port assigned SAS Address if there is one */ | |
41e2b905 | 1885 | scic_sds_port_get_sas_address(port, &port_sas_address); |
6f231dda DW |
1886 | |
1887 | if (port_sas_address.high != 0 && port_sas_address.low != 0) { | |
1888 | struct sci_sas_address phy_sas_address; | |
1889 | ||
1890 | /* | |
1891 | * Make sure that the PHY SAS Address matches the SAS Address | |
1892 | * for this port. */ | |
d857d9a0 | 1893 | scic_sds_phy_get_sas_address(phy, &phy_sas_address); |
6f231dda DW |
1894 | |
1895 | if ( | |
1896 | (port_sas_address.high != phy_sas_address.high) | |
1897 | || (port_sas_address.low != phy_sas_address.low) | |
1898 | ) { | |
1899 | return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION; | |
1900 | } | |
1901 | } | |
1902 | ||
d857d9a0 | 1903 | return scic_sds_port_set_phy(port, phy); |
6f231dda DW |
1904 | } |
1905 | ||
41e2b905 | 1906 | /* |
6f231dda DW |
1907 | * This method takes the struct scic_sds_port that is in a stopped state and handles |
1908 | * the remove phy request. In MPC mode the only time a phy can be removed from | |
1909 | * a port is in the SCI_BASE_PORT_STATE_STOPPED. enum sci_status | |
1910 | * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION is returned when the phy can not | |
1911 | * be added to the port. SCI_SUCCESS if the phy is added to the port. | |
1912 | */ | |
1913 | static enum sci_status scic_sds_port_stopped_state_remove_phy_handler( | |
41e2b905 | 1914 | struct scic_sds_port *port, |
d857d9a0 | 1915 | struct scic_sds_phy *phy) |
6f231dda | 1916 | { |
d857d9a0 | 1917 | return scic_sds_port_clear_phy(port, phy); |
6f231dda DW |
1918 | } |
1919 | ||
1920 | /* | |
1921 | * **************************************************************************** | |
1922 | * * READY STATE HANDLERS | |
1923 | * **************************************************************************** */ | |
1924 | ||
1925 | /* | |
1926 | * **************************************************************************** | |
1927 | * * RESETTING STATE HANDLERS | |
1928 | * **************************************************************************** */ | |
1929 | ||
1930 | /* | |
1931 | * **************************************************************************** | |
1932 | * * STOPPING STATE HANDLERS | |
1933 | * **************************************************************************** */ | |
1934 | ||
41e2b905 | 1935 | /* |
6f231dda DW |
1936 | * This method takes the struct scic_sds_port that is in a stopping state and handles |
1937 | * the complete io request. Should the request count reach 0 then the port | |
1938 | * object will transition to the stopped state. enum sci_status SCI_SUCCESS | |
1939 | */ | |
1940 | static enum sci_status scic_sds_port_stopping_state_complete_io_handler( | |
068b2c03 | 1941 | struct scic_sds_port *sci_port, |
6f231dda DW |
1942 | struct scic_sds_remote_device *device, |
1943 | struct scic_sds_request *io_request) | |
1944 | { | |
068b2c03 | 1945 | scic_sds_port_decrement_request_count(sci_port); |
6f231dda | 1946 | |
068b2c03 | 1947 | if (sci_port->started_request_count == 0) { |
41e2b905 | 1948 | sci_base_state_machine_change_state(&sci_port->state_machine, |
068b2c03 | 1949 | SCI_BASE_PORT_STATE_STOPPED); |
6f231dda DW |
1950 | } |
1951 | ||
1952 | return SCI_SUCCESS; | |
1953 | } | |
1954 | ||
1955 | /* | |
1956 | * **************************************************************************** | |
1957 | * * RESETTING STATE HANDLERS | |
1958 | * **************************************************************************** */ | |
1959 | ||
1960 | /** | |
1961 | * | |
1962 | * @port: This is the port object which is being requested to stop. | |
1963 | * | |
1964 | * This method will stop a failed port. This causes a transition to the | |
1965 | * stopping state. enum sci_status SCI_SUCCESS | |
1966 | */ | |
1967 | static enum sci_status scic_sds_port_reset_state_stop_handler( | |
41e2b905 | 1968 | struct scic_sds_port *port) |
6f231dda | 1969 | { |
6f231dda | 1970 | sci_base_state_machine_change_state( |
41e2b905 | 1971 | &port->state_machine, |
6f231dda DW |
1972 | SCI_BASE_PORT_STATE_STOPPING |
1973 | ); | |
1974 | ||
1975 | return SCI_SUCCESS; | |
1976 | } | |
1977 | ||
41e2b905 | 1978 | /* |
6f231dda DW |
1979 | * This method will transition a failed port to its ready state. The port |
1980 | * failed because a hard reset request timed out but at some time later one or | |
1981 | * more phys in the port became ready. enum sci_status SCI_SUCCESS | |
1982 | */ | |
1983 | static void scic_sds_port_reset_state_link_up_handler( | |
41e2b905 | 1984 | struct scic_sds_port *port, |
6f231dda DW |
1985 | struct scic_sds_phy *phy) |
1986 | { | |
1987 | /* | |
1988 | * / @todo We should make sure that the phy that has gone link up is the same | |
1989 | * / one on which we sent the reset. It is possible that the phy on | |
1990 | * / which we sent the reset is not the one that has gone link up and we | |
1991 | * / want to make sure that phy being reset comes back. Consider the | |
1992 | * / case where a reset is sent but before the hardware processes the | |
1993 | * / reset it get a link up on the port because of a hot plug event. | |
1994 | * / because of the reset request this phy will go link down almost | |
1995 | * / immediately. */ | |
1996 | ||
1997 | /* | |
1998 | * In the resetting state we don't notify the user regarding | |
1999 | * link up and link down notifications. */ | |
41e2b905 | 2000 | scic_sds_port_general_link_up_handler(port, phy, false); |
6f231dda DW |
2001 | } |
2002 | ||
41e2b905 | 2003 | /* |
6f231dda DW |
2004 | * This method process link down notifications that occur during a port reset |
2005 | * operation. Link downs can occur during the reset operation. enum sci_status | |
2006 | * SCI_SUCCESS | |
2007 | */ | |
2008 | static void scic_sds_port_reset_state_link_down_handler( | |
41e2b905 | 2009 | struct scic_sds_port *port, |
6f231dda DW |
2010 | struct scic_sds_phy *phy) |
2011 | { | |
2012 | /* | |
2013 | * In the resetting state we don't notify the user regarding | |
2014 | * link up and link down notifications. */ | |
41e2b905 | 2015 | scic_sds_port_deactivate_phy(port, phy, false); |
6f231dda DW |
2016 | } |
2017 | ||
35173d57 | 2018 | static struct scic_sds_port_state_handler |
6f231dda DW |
2019 | scic_sds_port_state_handler_table[SCI_BASE_PORT_MAX_STATES] = |
2020 | { | |
2021 | /* SCI_BASE_PORT_STATE_STOPPED */ | |
2022 | { | |
41e2b905 MT |
2023 | scic_sds_port_stopped_state_start_handler, |
2024 | scic_sds_port_stopped_state_stop_handler, | |
2025 | scic_sds_port_stopped_state_destruct_handler, | |
2026 | scic_sds_port_default_reset_handler, | |
2027 | scic_sds_port_stopped_state_add_phy_handler, | |
2028 | scic_sds_port_stopped_state_remove_phy_handler, | |
6f231dda DW |
2029 | scic_sds_port_default_frame_handler, |
2030 | scic_sds_port_default_event_handler, | |
2031 | scic_sds_port_default_link_up_handler, | |
2032 | scic_sds_port_default_link_down_handler, | |
2033 | scic_sds_port_default_start_io_handler, | |
2034 | scic_sds_port_default_complete_io_handler | |
2035 | }, | |
2036 | /* SCI_BASE_PORT_STATE_STOPPING */ | |
2037 | { | |
41e2b905 MT |
2038 | scic_sds_port_default_start_handler, |
2039 | scic_sds_port_default_stop_handler, | |
2040 | scic_sds_port_default_destruct_handler, | |
2041 | scic_sds_port_default_reset_handler, | |
2042 | scic_sds_port_default_add_phy_handler, | |
2043 | scic_sds_port_default_remove_phy_handler, | |
6f231dda DW |
2044 | scic_sds_port_default_frame_handler, |
2045 | scic_sds_port_default_event_handler, | |
2046 | scic_sds_port_default_link_up_handler, | |
2047 | scic_sds_port_default_link_down_handler, | |
2048 | scic_sds_port_default_start_io_handler, | |
2049 | scic_sds_port_stopping_state_complete_io_handler | |
2050 | }, | |
2051 | /* SCI_BASE_PORT_STATE_READY */ | |
2052 | { | |
41e2b905 MT |
2053 | scic_sds_port_default_start_handler, |
2054 | scic_sds_port_default_stop_handler, | |
2055 | scic_sds_port_default_destruct_handler, | |
2056 | scic_sds_port_default_reset_handler, | |
2057 | scic_sds_port_default_add_phy_handler, | |
2058 | scic_sds_port_default_remove_phy_handler, | |
6f231dda DW |
2059 | scic_sds_port_default_frame_handler, |
2060 | scic_sds_port_default_event_handler, | |
2061 | scic_sds_port_default_link_up_handler, | |
2062 | scic_sds_port_default_link_down_handler, | |
2063 | scic_sds_port_default_start_io_handler, | |
2064 | scic_sds_port_general_complete_io_handler | |
2065 | }, | |
2066 | /* SCI_BASE_PORT_STATE_RESETTING */ | |
2067 | { | |
41e2b905 MT |
2068 | scic_sds_port_default_start_handler, |
2069 | scic_sds_port_reset_state_stop_handler, | |
2070 | scic_sds_port_default_destruct_handler, | |
2071 | scic_sds_port_default_reset_handler, | |
2072 | scic_sds_port_default_add_phy_handler, | |
2073 | scic_sds_port_default_remove_phy_handler, | |
6f231dda DW |
2074 | scic_sds_port_default_frame_handler, |
2075 | scic_sds_port_default_event_handler, | |
2076 | scic_sds_port_reset_state_link_up_handler, | |
2077 | scic_sds_port_reset_state_link_down_handler, | |
2078 | scic_sds_port_default_start_io_handler, | |
2079 | scic_sds_port_general_complete_io_handler | |
2080 | }, | |
2081 | /* SCI_BASE_PORT_STATE_FAILED */ | |
2082 | { | |
41e2b905 MT |
2083 | scic_sds_port_default_start_handler, |
2084 | scic_sds_port_default_stop_handler, | |
2085 | scic_sds_port_default_destruct_handler, | |
2086 | scic_sds_port_default_reset_handler, | |
2087 | scic_sds_port_default_add_phy_handler, | |
2088 | scic_sds_port_default_remove_phy_handler, | |
6f231dda DW |
2089 | scic_sds_port_default_frame_handler, |
2090 | scic_sds_port_default_event_handler, | |
2091 | scic_sds_port_default_link_up_handler, | |
2092 | scic_sds_port_default_link_down_handler, | |
2093 | scic_sds_port_default_start_io_handler, | |
2094 | scic_sds_port_general_complete_io_handler | |
2095 | } | |
2096 | }; | |
2097 | ||
2098 | /* | |
2099 | * ****************************************************************************** | |
2100 | * * PORT STATE PRIVATE METHODS | |
2101 | * ****************************************************************************** */ | |
2102 | ||
2103 | /** | |
2104 | * | |
e2023b87 | 2105 | * @sci_port: This is the port object which to suspend. |
6f231dda DW |
2106 | * |
2107 | * This method will enable the SCU Port Task Scheduler for this port object but | |
2108 | * will leave the port task scheduler in a suspended state. none | |
2109 | */ | |
bc99aa47 CH |
2110 | static void |
2111 | scic_sds_port_enable_port_task_scheduler(struct scic_sds_port *port) | |
6f231dda DW |
2112 | { |
2113 | u32 pts_control_value; | |
2114 | ||
bc99aa47 | 2115 | pts_control_value = readl(&port->port_task_scheduler_registers->control); |
6f231dda | 2116 | pts_control_value |= SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND); |
bc99aa47 | 2117 | writel(pts_control_value, &port->port_task_scheduler_registers->control); |
6f231dda DW |
2118 | } |
2119 | ||
2120 | /** | |
2121 | * | |
e2023b87 | 2122 | * @sci_port: This is the port object which to resume. |
6f231dda DW |
2123 | * |
2124 | * This method will disable the SCU port task scheduler for this port object. | |
2125 | * none | |
2126 | */ | |
bc99aa47 CH |
2127 | static void |
2128 | scic_sds_port_disable_port_task_scheduler(struct scic_sds_port *port) | |
6f231dda DW |
2129 | { |
2130 | u32 pts_control_value; | |
2131 | ||
bc99aa47 CH |
2132 | pts_control_value = readl(&port->port_task_scheduler_registers->control); |
2133 | pts_control_value &= | |
2134 | ~(SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND)); | |
2135 | writel(pts_control_value, &port->port_task_scheduler_registers->control); | |
6f231dda DW |
2136 | } |
2137 | ||
35173d57 | 2138 | static void scic_sds_port_post_dummy_remote_node(struct scic_sds_port *sci_port) |
a8d4b9fe TC |
2139 | { |
2140 | struct scic_sds_controller *scic = sci_port->owning_controller; | |
2141 | u8 phys_index = sci_port->physical_port_index; | |
2142 | union scu_remote_node_context *rnc; | |
2143 | u16 rni = sci_port->reserved_rni; | |
2144 | u32 command; | |
2145 | ||
2146 | rnc = &scic->remote_node_context_table[rni]; | |
2147 | rnc->ssp.is_valid = true; | |
2148 | ||
2149 | command = SCU_CONTEXT_COMMAND_POST_RNC_32 | | |
2150 | phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni; | |
2151 | ||
2152 | scic_sds_controller_post_request(scic, command); | |
2153 | ||
2154 | /* ensure hardware has seen the post rnc command and give it | |
2155 | * ample time to act before sending the suspend | |
2156 | */ | |
bc99aa47 | 2157 | readl(&scic->smu_registers->interrupt_status); /* flush */ |
a8d4b9fe TC |
2158 | udelay(10); |
2159 | ||
2160 | command = SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX | | |
2161 | phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni; | |
2162 | ||
2163 | scic_sds_controller_post_request(scic, command); | |
2164 | } | |
2165 | ||
35173d57 | 2166 | static void scic_sds_port_invalidate_dummy_remote_node(struct scic_sds_port *sci_port) |
a8d4b9fe TC |
2167 | { |
2168 | struct scic_sds_controller *scic = sci_port->owning_controller; | |
2169 | u8 phys_index = sci_port->physical_port_index; | |
2170 | union scu_remote_node_context *rnc; | |
2171 | u16 rni = sci_port->reserved_rni; | |
2172 | u32 command; | |
2173 | ||
2174 | rnc = &scic->remote_node_context_table[rni]; | |
2175 | ||
2176 | rnc->ssp.is_valid = false; | |
2177 | ||
27ce51df DW |
2178 | /* ensure the preceding tc abort request has reached the |
2179 | * controller and give it ample time to act before posting the rnc | |
2180 | * invalidate | |
2181 | */ | |
bc99aa47 | 2182 | readl(&scic->smu_registers->interrupt_status); /* flush */ |
27ce51df DW |
2183 | udelay(10); |
2184 | ||
a8d4b9fe TC |
2185 | command = SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE | |
2186 | phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni; | |
2187 | ||
2188 | scic_sds_controller_post_request(scic, command); | |
2189 | } | |
2190 | ||
6f231dda DW |
2191 | /* |
2192 | * ****************************************************************************** | |
2193 | * * PORT STATE METHODS | |
2194 | * ****************************************************************************** */ | |
2195 | ||
2196 | /** | |
2197 | * | |
9a0fff7b | 2198 | * @object: This is the object which is cast to a struct scic_sds_port object. |
6f231dda DW |
2199 | * |
2200 | * This method will perform the actions required by the struct scic_sds_port on | |
2201 | * entering the SCI_BASE_PORT_STATE_STOPPED. This function sets the stopped | |
2202 | * state handlers for the struct scic_sds_port object and disables the port task | |
2203 | * scheduler in the hardware. none | |
2204 | */ | |
9a0fff7b | 2205 | static void scic_sds_port_stopped_state_enter(void *object) |
6f231dda | 2206 | { |
115bd1f9 | 2207 | struct scic_sds_port *sci_port = object; |
6f231dda DW |
2208 | |
2209 | scic_sds_port_set_base_state_handlers( | |
e2023b87 | 2210 | sci_port, SCI_BASE_PORT_STATE_STOPPED |
6f231dda DW |
2211 | ); |
2212 | ||
2213 | if ( | |
2214 | SCI_BASE_PORT_STATE_STOPPING | |
e2023b87 | 2215 | == sci_port->state_machine.previous_state_id |
6f231dda DW |
2216 | ) { |
2217 | /* | |
2218 | * If we enter this state becasuse of a request to stop | |
2219 | * the port then we want to disable the hardwares port | |
2220 | * task scheduler. */ | |
e2023b87 | 2221 | scic_sds_port_disable_port_task_scheduler(sci_port); |
6f231dda DW |
2222 | } |
2223 | } | |
2224 | ||
2225 | /** | |
2226 | * | |
9a0fff7b | 2227 | * @object: This is the object which is cast to a struct scic_sds_port object. |
6f231dda DW |
2228 | * |
2229 | * This method will perform the actions required by the struct scic_sds_port on | |
2230 | * exiting the SCI_BASE_STATE_STOPPED. This function enables the SCU hardware | |
2231 | * port task scheduler. none | |
2232 | */ | |
9a0fff7b | 2233 | static void scic_sds_port_stopped_state_exit(void *object) |
6f231dda | 2234 | { |
115bd1f9 | 2235 | struct scic_sds_port *sci_port = object; |
6f231dda DW |
2236 | |
2237 | /* Enable and suspend the port task scheduler */ | |
e2023b87 | 2238 | scic_sds_port_enable_port_task_scheduler(sci_port); |
6f231dda DW |
2239 | } |
2240 | ||
2241 | /** | |
068b2c03 | 2242 | * scic_sds_port_ready_state_enter - |
9a0fff7b | 2243 | * @object: This is the object which is cast to a struct scic_sds_port object. |
6f231dda DW |
2244 | * |
2245 | * This method will perform the actions required by the struct scic_sds_port on | |
2246 | * entering the SCI_BASE_PORT_STATE_READY. This function sets the ready state | |
09d7da13 DJ |
2247 | * handlers for the struct scic_sds_port object, reports the port object as |
2248 | * not ready and starts the ready substate machine. none | |
6f231dda | 2249 | */ |
9a0fff7b | 2250 | static void scic_sds_port_ready_state_enter(void *object) |
6f231dda | 2251 | { |
115bd1f9 | 2252 | struct scic_sds_port *sci_port = object; |
cc3dbd0a AW |
2253 | struct scic_sds_controller *scic = sci_port->owning_controller; |
2254 | struct isci_host *ihost = scic_to_ihost(scic); | |
e531381e | 2255 | struct isci_port *iport = sci_port_to_iport(sci_port); |
068b2c03 | 2256 | u32 prev_state; |
6f231dda | 2257 | |
068b2c03 DW |
2258 | /* Put the ready state handlers in place though they will not be there long */ |
2259 | scic_sds_port_set_base_state_handlers(sci_port, SCI_BASE_PORT_STATE_READY); | |
2260 | ||
41e2b905 | 2261 | prev_state = sci_port->state_machine.previous_state_id; |
068b2c03 | 2262 | if (prev_state == SCI_BASE_PORT_STATE_RESETTING) |
09d7da13 | 2263 | isci_port_hard_reset_complete(iport, SCI_SUCCESS); |
068b2c03 | 2264 | else |
09d7da13 | 2265 | isci_port_not_ready(ihost, iport); |
6f231dda | 2266 | |
a8d4b9fe | 2267 | /* Post and suspend the dummy remote node context for this port. */ |
09d7da13 | 2268 | scic_sds_port_post_dummy_remote_node(sci_port); |
a8d4b9fe | 2269 | |
6f231dda | 2270 | /* Start the ready substate machine */ |
068b2c03 | 2271 | sci_base_state_machine_start(&sci_port->ready_substate_machine); |
6f231dda DW |
2272 | } |
2273 | ||
9a0fff7b | 2274 | static void scic_sds_port_ready_state_exit(void *object) |
6f231dda | 2275 | { |
115bd1f9 | 2276 | struct scic_sds_port *sci_port = object; |
a8d4b9fe | 2277 | |
068b2c03 DW |
2278 | sci_base_state_machine_stop(&sci_port->ready_substate_machine); |
2279 | scic_sds_port_invalidate_dummy_remote_node(sci_port); | |
6f231dda DW |
2280 | } |
2281 | ||
2282 | /** | |
2283 | * | |
9a0fff7b | 2284 | * @object: This is the object which is cast to a struct scic_sds_port object. |
6f231dda DW |
2285 | * |
2286 | * This method will perform the actions required by the struct scic_sds_port on | |
2287 | * entering the SCI_BASE_PORT_STATE_RESETTING. This function sets the resetting | |
2288 | * state handlers for the struct scic_sds_port object. none | |
2289 | */ | |
9a0fff7b | 2290 | static void scic_sds_port_resetting_state_enter(void *object) |
6f231dda | 2291 | { |
115bd1f9 | 2292 | struct scic_sds_port *sci_port = object; |
6f231dda DW |
2293 | |
2294 | scic_sds_port_set_base_state_handlers( | |
e2023b87 | 2295 | sci_port, SCI_BASE_PORT_STATE_RESETTING |
6f231dda | 2296 | ); |
6f231dda DW |
2297 | } |
2298 | ||
2299 | /** | |
2300 | * | |
9a0fff7b | 2301 | * @object: This is the object which is cast to a struct scic_sds_port object. |
6f231dda | 2302 | * |
09d7da13 DJ |
2303 | * This function will perform the actions required by the |
2304 | * struct scic_sds_port on | |
6f231dda DW |
2305 | * exiting the SCI_BASE_STATE_RESETTING. This function does nothing. none |
2306 | */ | |
9a0fff7b | 2307 | static inline void scic_sds_port_resetting_state_exit(void *object) |
6f231dda | 2308 | { |
115bd1f9 | 2309 | struct scic_sds_port *sci_port = object; |
6f231dda | 2310 | |
09d7da13 | 2311 | isci_timer_stop(sci_port->timer_handle); |
6f231dda DW |
2312 | } |
2313 | ||
2314 | /** | |
2315 | * | |
9a0fff7b MP |
2316 | * @object: This is the void object which is cast to a |
2317 | * struct scic_sds_port object. | |
6f231dda DW |
2318 | * |
2319 | * This method will perform the actions required by the struct scic_sds_port on | |
2320 | * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping | |
2321 | * state handlers for the struct scic_sds_port object. none | |
2322 | */ | |
9a0fff7b | 2323 | static void scic_sds_port_stopping_state_enter(void *object) |
6f231dda | 2324 | { |
115bd1f9 | 2325 | struct scic_sds_port *sci_port = object; |
6f231dda DW |
2326 | |
2327 | scic_sds_port_set_base_state_handlers( | |
e2023b87 | 2328 | sci_port, SCI_BASE_PORT_STATE_STOPPING |
6f231dda DW |
2329 | ); |
2330 | } | |
2331 | ||
2332 | /** | |
2333 | * | |
9a0fff7b | 2334 | * @object: This is the object which is cast to a struct scic_sds_port object. |
6f231dda | 2335 | * |
09d7da13 DJ |
2336 | * This function will perform the actions required by the |
2337 | * struct scic_sds_port on | |
6f231dda DW |
2338 | * exiting the SCI_BASE_STATE_STOPPING. This function does nothing. none |
2339 | */ | |
09d7da13 | 2340 | static inline void |
9a0fff7b | 2341 | scic_sds_port_stopping_state_exit(void *object) |
6f231dda | 2342 | { |
115bd1f9 | 2343 | struct scic_sds_port *sci_port = object; |
6f231dda | 2344 | |
09d7da13 | 2345 | isci_timer_stop(sci_port->timer_handle); |
a8d4b9fe | 2346 | |
09d7da13 | 2347 | scic_sds_port_destroy_dummy_resources(sci_port); |
6f231dda DW |
2348 | } |
2349 | ||
2350 | /** | |
2351 | * | |
9a0fff7b | 2352 | * @object: This is the object which is cast to a struct scic_sds_port object. |
6f231dda | 2353 | * |
09d7da13 DJ |
2354 | * This function will perform the actions required by the |
2355 | * struct scic_sds_port on | |
6f231dda DW |
2356 | * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping |
2357 | * state handlers for the struct scic_sds_port object. none | |
2358 | */ | |
9a0fff7b | 2359 | static void scic_sds_port_failed_state_enter(void *object) |
6f231dda | 2360 | { |
115bd1f9 | 2361 | struct scic_sds_port *sci_port = object; |
e531381e | 2362 | struct isci_port *iport = sci_port_to_iport(sci_port); |
6f231dda | 2363 | |
09d7da13 DJ |
2364 | scic_sds_port_set_base_state_handlers(sci_port, |
2365 | SCI_BASE_PORT_STATE_FAILED); | |
6f231dda | 2366 | |
09d7da13 | 2367 | isci_port_hard_reset_complete(iport, SCI_FAILURE_TIMEOUT); |
6f231dda DW |
2368 | } |
2369 | ||
2370 | /* --------------------------------------------------------------------------- */ | |
2371 | ||
35173d57 | 2372 | static const struct sci_base_state scic_sds_port_state_table[] = { |
6f231dda DW |
2373 | [SCI_BASE_PORT_STATE_STOPPED] = { |
2374 | .enter_state = scic_sds_port_stopped_state_enter, | |
2375 | .exit_state = scic_sds_port_stopped_state_exit | |
2376 | }, | |
2377 | [SCI_BASE_PORT_STATE_STOPPING] = { | |
2378 | .enter_state = scic_sds_port_stopping_state_enter, | |
2379 | .exit_state = scic_sds_port_stopping_state_exit | |
2380 | }, | |
2381 | [SCI_BASE_PORT_STATE_READY] = { | |
2382 | .enter_state = scic_sds_port_ready_state_enter, | |
2383 | .exit_state = scic_sds_port_ready_state_exit | |
2384 | }, | |
2385 | [SCI_BASE_PORT_STATE_RESETTING] = { | |
2386 | .enter_state = scic_sds_port_resetting_state_enter, | |
2387 | .exit_state = scic_sds_port_resetting_state_exit | |
2388 | }, | |
2389 | [SCI_BASE_PORT_STATE_FAILED] = { | |
2390 | .enter_state = scic_sds_port_failed_state_enter, | |
2391 | } | |
2392 | }; | |
2393 | ||
e531381e | 2394 | void scic_sds_port_construct(struct scic_sds_port *sci_port, u8 index, |
35173d57 DW |
2395 | struct scic_sds_controller *scic) |
2396 | { | |
41e2b905 | 2397 | sci_base_state_machine_construct(&sci_port->state_machine, |
115bd1f9 | 2398 | sci_port, |
41e2b905 MT |
2399 | scic_sds_port_state_table, |
2400 | SCI_BASE_PORT_STATE_STOPPED); | |
2401 | ||
2402 | sci_base_state_machine_start(&sci_port->state_machine); | |
35173d57 DW |
2403 | |
2404 | sci_base_state_machine_construct(&sci_port->ready_substate_machine, | |
115bd1f9 | 2405 | sci_port, |
35173d57 DW |
2406 | scic_sds_port_ready_substate_table, |
2407 | SCIC_SDS_PORT_READY_SUBSTATE_WAITING); | |
2408 | ||
2409 | sci_port->logical_port_index = SCIC_SDS_DUMMY_PORT; | |
e531381e | 2410 | sci_port->physical_port_index = index; |
35173d57 DW |
2411 | sci_port->active_phy_mask = 0; |
2412 | ||
2413 | sci_port->owning_controller = scic; | |
2414 | ||
2415 | sci_port->started_request_count = 0; | |
2416 | sci_port->assigned_device_count = 0; | |
2417 | ||
2418 | sci_port->reserved_rni = SCU_DUMMY_INDEX; | |
2419 | sci_port->reserved_tci = SCU_DUMMY_INDEX; | |
2420 | ||
2421 | sci_port->timer_handle = NULL; | |
35173d57 DW |
2422 | sci_port->port_task_scheduler_registers = NULL; |
2423 | ||
2424 | for (index = 0; index < SCI_MAX_PHYS; index++) | |
2425 | sci_port->phy_table[index] = NULL; | |
2426 | } |