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