Commit | Line | Data |
---|---|---|
6f231dda DW |
1 | /* |
2 | * This file is provided under a dual BSD/GPLv2 license. When using or | |
3 | * redistributing this file, you may do so under either license. | |
4 | * | |
5 | * GPL LICENSE SUMMARY | |
6 | * | |
7 | * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of version 2 of the GNU General Public License as | |
11 | * published by the Free Software Foundation. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, but | |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | |
21 | * The full GNU General Public License is included in this distribution | |
22 | * in the file called LICENSE.GPL. | |
23 | * | |
24 | * BSD LICENSE | |
25 | * | |
26 | * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. | |
27 | * All rights reserved. | |
28 | * | |
29 | * Redistribution and use in source and binary forms, with or without | |
30 | * modification, are permitted provided that the following conditions | |
31 | * are met: | |
32 | * | |
33 | * * Redistributions of source code must retain the above copyright | |
34 | * notice, this list of conditions and the following disclaimer. | |
35 | * * Redistributions in binary form must reproduce the above copyright | |
36 | * notice, this list of conditions and the following disclaimer in | |
37 | * the documentation and/or other materials provided with the | |
38 | * distribution. | |
39 | * * Neither the name of Intel Corporation nor the names of its | |
40 | * contributors may be used to endorse or promote products derived | |
41 | * from this software without specific prior written permission. | |
42 | * | |
43 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
44 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
45 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
46 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
47 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
48 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
49 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
50 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
51 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
52 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
53 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
54 | */ | |
55 | ||
6f231dda | 56 | #include "isci.h" |
6f231dda DW |
57 | #include "port.h" |
58 | #include "request.h" | |
e2f8db50 DW |
59 | |
60 | #define SCIC_SDS_PORT_HARD_RESET_TIMEOUT (1000) | |
61 | #define SCU_DUMMY_INDEX (0xFFFF) | |
6f231dda | 62 | |
e531381e DW |
63 | static void isci_port_change_state(struct isci_port *iport, enum isci_status status) |
64 | { | |
65 | unsigned long flags; | |
6f231dda | 66 | |
e531381e DW |
67 | dev_dbg(&iport->isci_host->pdev->dev, |
68 | "%s: iport = %p, state = 0x%x\n", | |
69 | __func__, iport, status); | |
6f231dda | 70 | |
e531381e DW |
71 | /* XXX pointless lock */ |
72 | spin_lock_irqsave(&iport->state_lock, flags); | |
73 | iport->status = status; | |
74 | spin_unlock_irqrestore(&iport->state_lock, flags); | |
75 | } | |
6f231dda | 76 | |
e2f8db50 DW |
77 | /* |
78 | * This function will indicate which protocols are supported by this port. | |
79 | * @sci_port: a handle corresponding to the SAS port for which to return the | |
80 | * supported protocols. | |
81 | * @protocols: This parameter specifies a pointer to a data structure | |
82 | * which the core will copy the protocol values for the port from the | |
83 | * transmit_identification register. | |
84 | */ | |
85 | static void | |
86 | scic_sds_port_get_protocols(struct scic_sds_port *sci_port, | |
87 | struct scic_phy_proto *protocols) | |
6f231dda | 88 | { |
e2f8db50 DW |
89 | u8 index; |
90 | ||
91 | protocols->all = 0; | |
92 | ||
93 | for (index = 0; index < SCI_MAX_PHYS; index++) { | |
94 | if (sci_port->phy_table[index] != NULL) { | |
95 | scic_sds_phy_get_protocols(sci_port->phy_table[index], | |
96 | protocols); | |
97 | } | |
98 | } | |
6f231dda DW |
99 | } |
100 | ||
6f231dda | 101 | /** |
e2f8db50 DW |
102 | * This method requests a list (mask) of the phys contained in the supplied SAS |
103 | * port. | |
104 | * @sci_port: a handle corresponding to the SAS port for which to return the | |
105 | * phy mask. | |
6f231dda | 106 | * |
e2f8db50 DW |
107 | * Return a bit mask indicating which phys are a part of this port. Each bit |
108 | * corresponds to a phy identifier (e.g. bit 0 = phy id 0). | |
6f231dda | 109 | */ |
e2f8db50 | 110 | static u32 scic_sds_port_get_phys(struct scic_sds_port *sci_port) |
6f231dda | 111 | { |
e2f8db50 DW |
112 | u32 index; |
113 | u32 mask; | |
114 | ||
115 | mask = 0; | |
116 | ||
117 | for (index = 0; index < SCI_MAX_PHYS; index++) { | |
118 | if (sci_port->phy_table[index] != NULL) { | |
119 | mask |= (1 << index); | |
120 | } | |
121 | } | |
122 | ||
123 | return mask; | |
6f231dda DW |
124 | } |
125 | ||
e2f8db50 DW |
126 | /** |
127 | * scic_port_get_properties() - This method simply returns the properties | |
128 | * regarding the port, such as: physical index, protocols, sas address, etc. | |
129 | * @port: this parameter specifies the port for which to retrieve the physical | |
130 | * index. | |
131 | * @properties: This parameter specifies the properties structure into which to | |
132 | * copy the requested information. | |
133 | * | |
134 | * Indicate if the user specified a valid port. SCI_SUCCESS This value is | |
135 | * returned if the specified port was valid. SCI_FAILURE_INVALID_PORT This | |
136 | * value is returned if the specified port is not valid. When this value is | |
137 | * returned, no data is copied to the properties output parameter. | |
138 | */ | |
139 | static enum sci_status scic_port_get_properties(struct scic_sds_port *port, | |
140 | struct scic_port_properties *prop) | |
6f231dda | 141 | { |
e2f8db50 DW |
142 | if ((port == NULL) || |
143 | (port->logical_port_index == SCIC_SDS_DUMMY_PORT)) | |
144 | return SCI_FAILURE_INVALID_PORT; | |
6f231dda | 145 | |
e2f8db50 DW |
146 | prop->index = port->logical_port_index; |
147 | prop->phy_mask = scic_sds_port_get_phys(port); | |
148 | scic_sds_port_get_sas_address(port, &prop->local.sas_address); | |
149 | scic_sds_port_get_protocols(port, &prop->local.protocols); | |
150 | scic_sds_port_get_attached_sas_address(port, &prop->remote.sas_address); | |
6f231dda | 151 | |
e2f8db50 | 152 | return SCI_SUCCESS; |
6f231dda DW |
153 | } |
154 | ||
61aaff49 JS |
155 | static void scic_port_bcn_enable(struct scic_sds_port *sci_port) |
156 | { | |
157 | struct scic_sds_phy *sci_phy; | |
158 | u32 val; | |
159 | int i; | |
160 | ||
161 | for (i = 0; i < ARRAY_SIZE(sci_port->phy_table); i++) { | |
162 | sci_phy = sci_port->phy_table[i]; | |
163 | if (!sci_phy) | |
164 | continue; | |
165 | val = readl(&sci_phy->link_layer_registers->link_layer_control); | |
166 | /* clear the bit by writing 1. */ | |
167 | writel(val, &sci_phy->link_layer_registers->link_layer_control); | |
168 | } | |
169 | } | |
170 | ||
171 | /* called under scic_lock to stabilize phy:port associations */ | |
172 | void isci_port_bcn_enable(struct isci_host *ihost, struct isci_port *iport) | |
173 | { | |
174 | int i; | |
175 | ||
176 | clear_bit(IPORT_BCN_BLOCKED, &iport->flags); | |
177 | wake_up(&ihost->eventq); | |
178 | ||
179 | if (!test_and_clear_bit(IPORT_BCN_PENDING, &iport->flags)) | |
180 | return; | |
181 | ||
182 | for (i = 0; i < ARRAY_SIZE(iport->sci.phy_table); i++) { | |
183 | struct scic_sds_phy *sci_phy = iport->sci.phy_table[i]; | |
184 | struct isci_phy *iphy = sci_phy_to_iphy(sci_phy); | |
185 | ||
186 | if (!sci_phy) | |
187 | continue; | |
188 | ||
189 | ihost->sas_ha.notify_port_event(&iphy->sas_phy, | |
190 | PORTE_BROADCAST_RCVD); | |
191 | break; | |
192 | } | |
193 | } | |
194 | ||
195 | void isci_port_bc_change_received(struct isci_host *ihost, | |
196 | struct scic_sds_port *sci_port, | |
197 | struct scic_sds_phy *sci_phy) | |
198 | { | |
199 | struct isci_phy *iphy = sci_phy_to_iphy(sci_phy); | |
200 | struct isci_port *iport = iphy->isci_port; | |
201 | ||
202 | if (iport && test_bit(IPORT_BCN_BLOCKED, &iport->flags)) { | |
203 | dev_dbg(&ihost->pdev->dev, | |
204 | "%s: disabled BCN; isci_phy = %p, sas_phy = %p\n", | |
205 | __func__, iphy, &iphy->sas_phy); | |
206 | set_bit(IPORT_BCN_PENDING, &iport->flags); | |
207 | atomic_inc(&iport->event); | |
208 | wake_up(&ihost->eventq); | |
209 | } else { | |
210 | dev_dbg(&ihost->pdev->dev, | |
211 | "%s: isci_phy = %p, sas_phy = %p\n", | |
212 | __func__, iphy, &iphy->sas_phy); | |
213 | ||
214 | ihost->sas_ha.notify_port_event(&iphy->sas_phy, | |
215 | PORTE_BROADCAST_RCVD); | |
216 | } | |
217 | scic_port_bcn_enable(sci_port); | |
218 | } | |
219 | ||
e2f8db50 DW |
220 | static void isci_port_link_up(struct isci_host *isci_host, |
221 | struct scic_sds_port *port, | |
222 | struct scic_sds_phy *phy) | |
6f231dda DW |
223 | { |
224 | unsigned long flags; | |
225 | struct scic_port_properties properties; | |
4b33981a | 226 | struct isci_phy *isci_phy = sci_phy_to_iphy(phy); |
e531381e | 227 | struct isci_port *isci_port = sci_port_to_iport(port); |
6f231dda DW |
228 | unsigned long success = true; |
229 | ||
230 | BUG_ON(isci_phy->isci_port != NULL); | |
6cb4d6b3 | 231 | |
6f231dda DW |
232 | isci_phy->isci_port = isci_port; |
233 | ||
234 | dev_dbg(&isci_host->pdev->dev, | |
235 | "%s: isci_port = %p\n", | |
236 | __func__, isci_port); | |
237 | ||
238 | spin_lock_irqsave(&isci_phy->sas_phy.frame_rcvd_lock, flags); | |
239 | ||
240 | isci_port_change_state(isci_phy->isci_port, isci_starting); | |
241 | ||
242 | scic_port_get_properties(port, &properties); | |
243 | ||
d7b90fc3 | 244 | if (phy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) { |
150fc6fc | 245 | u64 attached_sas_address; |
6f231dda | 246 | |
6f231dda | 247 | isci_phy->sas_phy.oob_mode = SATA_OOB_MODE; |
f2f30080 | 248 | isci_phy->sas_phy.frame_rcvd_size = sizeof(struct dev_to_host_fis); |
6f231dda DW |
249 | |
250 | /* | |
251 | * For direct-attached SATA devices, the SCI core will | |
252 | * automagically assign a SAS address to the end device | |
253 | * for the purpose of creating a port. This SAS address | |
254 | * will not be the same as assigned to the PHY and needs | |
255 | * to be obtained from struct scic_port_properties properties. | |
256 | */ | |
150fc6fc DW |
257 | attached_sas_address = properties.remote.sas_address.high; |
258 | attached_sas_address <<= 32; | |
259 | attached_sas_address |= properties.remote.sas_address.low; | |
260 | swab64s(&attached_sas_address); | |
6f231dda | 261 | |
150fc6fc DW |
262 | memcpy(&isci_phy->sas_phy.attached_sas_addr, |
263 | &attached_sas_address, sizeof(attached_sas_address)); | |
d7b90fc3 | 264 | } else if (phy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) { |
6f231dda | 265 | isci_phy->sas_phy.oob_mode = SAS_OOB_MODE; |
4b7ebd05 | 266 | isci_phy->sas_phy.frame_rcvd_size = sizeof(struct sas_identify_frame); |
6f231dda DW |
267 | |
268 | /* Copy the attached SAS address from the IAF */ | |
269 | memcpy(isci_phy->sas_phy.attached_sas_addr, | |
4b7ebd05 | 270 | isci_phy->frame_rcvd.iaf.sas_addr, SAS_ADDR_SIZE); |
6f231dda DW |
271 | } else { |
272 | dev_err(&isci_host->pdev->dev, "%s: unkown target\n", __func__); | |
273 | success = false; | |
274 | } | |
275 | ||
83e51430 DW |
276 | isci_phy->sas_phy.phy->negotiated_linkrate = sci_phy_linkrate(phy); |
277 | ||
6f231dda DW |
278 | spin_unlock_irqrestore(&isci_phy->sas_phy.frame_rcvd_lock, flags); |
279 | ||
280 | /* Notify libsas that we have an address frame, if indeed | |
281 | * we've found an SSP, SMP, or STP target */ | |
282 | if (success) | |
283 | isci_host->sas_ha.notify_port_event(&isci_phy->sas_phy, | |
284 | PORTE_BYTES_DMAED); | |
285 | } | |
286 | ||
287 | ||
288 | /** | |
289 | * isci_port_link_down() - This function is called by the sci core when a link | |
290 | * becomes inactive. | |
291 | * @isci_host: This parameter specifies the isci host object. | |
292 | * @phy: This parameter specifies the isci phy with the active link. | |
293 | * @port: This parameter specifies the isci port with the active link. | |
294 | * | |
295 | */ | |
e2f8db50 DW |
296 | static void isci_port_link_down(struct isci_host *isci_host, |
297 | struct isci_phy *isci_phy, | |
298 | struct isci_port *isci_port) | |
6f231dda DW |
299 | { |
300 | struct isci_remote_device *isci_device; | |
301 | ||
302 | dev_dbg(&isci_host->pdev->dev, | |
303 | "%s: isci_port = %p\n", __func__, isci_port); | |
304 | ||
305 | if (isci_port) { | |
306 | ||
307 | /* check to see if this is the last phy on this port. */ | |
61aaff49 JS |
308 | if (isci_phy->sas_phy.port && |
309 | isci_phy->sas_phy.port->num_phys == 1) { | |
310 | atomic_inc(&isci_port->event); | |
311 | isci_port_bcn_enable(isci_host, isci_port); | |
312 | ||
313 | /* change the state for all devices on this port. The | |
314 | * next task sent to this device will be returned as | |
315 | * SAS_TASK_UNDELIVERED, and the scsi mid layer will | |
316 | * remove the target | |
6f231dda DW |
317 | */ |
318 | list_for_each_entry(isci_device, | |
319 | &isci_port->remote_dev_list, | |
320 | node) { | |
321 | dev_dbg(&isci_host->pdev->dev, | |
322 | "%s: isci_device = %p\n", | |
323 | __func__, isci_device); | |
324 | isci_remote_device_change_state(isci_device, | |
325 | isci_stopping); | |
326 | } | |
327 | } | |
328 | isci_port_change_state(isci_port, isci_stopping); | |
329 | } | |
330 | ||
331 | /* Notify libsas of the borken link, this will trigger calls to our | |
332 | * isci_port_deformed and isci_dev_gone functions. | |
333 | */ | |
334 | sas_phy_disconnected(&isci_phy->sas_phy); | |
335 | isci_host->sas_ha.notify_phy_event(&isci_phy->sas_phy, | |
336 | PHYE_LOSS_OF_SIGNAL); | |
337 | ||
338 | isci_phy->isci_port = NULL; | |
339 | ||
340 | dev_dbg(&isci_host->pdev->dev, | |
341 | "%s: isci_port = %p - Done\n", __func__, isci_port); | |
342 | } | |
343 | ||
344 | ||
6f231dda DW |
345 | /** |
346 | * isci_port_ready() - This function is called by the sci core when a link | |
347 | * becomes ready. | |
348 | * @isci_host: This parameter specifies the isci host object. | |
349 | * @port: This parameter specifies the sci port with the active link. | |
350 | * | |
351 | */ | |
e2f8db50 | 352 | static void isci_port_ready(struct isci_host *isci_host, struct isci_port *isci_port) |
6f231dda DW |
353 | { |
354 | dev_dbg(&isci_host->pdev->dev, | |
355 | "%s: isci_port = %p\n", __func__, isci_port); | |
356 | ||
357 | complete_all(&isci_port->start_complete); | |
358 | isci_port_change_state(isci_port, isci_ready); | |
359 | return; | |
360 | } | |
361 | ||
362 | /** | |
363 | * isci_port_not_ready() - This function is called by the sci core when a link | |
364 | * is not ready. All remote devices on this link will be removed if they are | |
365 | * in the stopping state. | |
366 | * @isci_host: This parameter specifies the isci host object. | |
367 | * @port: This parameter specifies the sci port with the active link. | |
368 | * | |
369 | */ | |
e2f8db50 | 370 | static void isci_port_not_ready(struct isci_host *isci_host, struct isci_port *isci_port) |
6f231dda DW |
371 | { |
372 | dev_dbg(&isci_host->pdev->dev, | |
373 | "%s: isci_port = %p\n", __func__, isci_port); | |
374 | } | |
375 | ||
e2f8db50 DW |
376 | static void isci_port_stop_complete(struct scic_sds_controller *scic, |
377 | struct scic_sds_port *sci_port, | |
378 | enum sci_status completion_status) | |
379 | { | |
380 | dev_dbg(&scic_to_ihost(scic)->pdev->dev, "Port stop complete\n"); | |
381 | } | |
382 | ||
6f231dda DW |
383 | /** |
384 | * isci_port_hard_reset_complete() - This function is called by the sci core | |
385 | * when the hard reset complete notification has been received. | |
386 | * @port: This parameter specifies the sci port with the active link. | |
387 | * @completion_status: This parameter specifies the core status for the reset | |
388 | * process. | |
389 | * | |
390 | */ | |
e2f8db50 DW |
391 | static void isci_port_hard_reset_complete(struct isci_port *isci_port, |
392 | enum sci_status completion_status) | |
6f231dda DW |
393 | { |
394 | dev_dbg(&isci_port->isci_host->pdev->dev, | |
395 | "%s: isci_port = %p, completion_status=%x\n", | |
396 | __func__, isci_port, completion_status); | |
397 | ||
398 | /* Save the status of the hard reset from the port. */ | |
399 | isci_port->hard_reset_status = completion_status; | |
400 | ||
401 | complete_all(&isci_port->hard_reset_complete); | |
402 | } | |
4393aa4e | 403 | |
e2f8db50 DW |
404 | /* This method will return a true value if the specified phy can be assigned to |
405 | * this port The following is a list of phys for each port that are allowed: - | |
406 | * Port 0 - 3 2 1 0 - Port 1 - 1 - Port 2 - 3 2 - Port 3 - 3 This method | |
407 | * doesn't preclude all configurations. It merely ensures that a phy is part | |
408 | * of the allowable set of phy identifiers for that port. For example, one | |
409 | * could assign phy 3 to port 0 and no other phys. Please refer to | |
410 | * scic_sds_port_is_phy_mask_valid() for information regarding whether the | |
411 | * phy_mask for a port can be supported. bool true if this is a valid phy | |
412 | * assignment for the port false if this is not a valid phy assignment for the | |
413 | * port | |
414 | */ | |
415 | bool scic_sds_port_is_valid_phy_assignment(struct scic_sds_port *sci_port, | |
416 | u32 phy_index) | |
6f231dda | 417 | { |
e2f8db50 DW |
418 | /* Initialize to invalid value. */ |
419 | u32 existing_phy_index = SCI_MAX_PHYS; | |
420 | u32 index; | |
6f231dda | 421 | |
e2f8db50 DW |
422 | if ((sci_port->physical_port_index == 1) && (phy_index != 1)) { |
423 | return false; | |
424 | } | |
6f231dda | 425 | |
e2f8db50 DW |
426 | if (sci_port->physical_port_index == 3 && phy_index != 3) { |
427 | return false; | |
428 | } | |
6f231dda | 429 | |
e2f8db50 DW |
430 | if ( |
431 | (sci_port->physical_port_index == 2) | |
432 | && ((phy_index == 0) || (phy_index == 1)) | |
433 | ) { | |
434 | return false; | |
435 | } | |
6f231dda | 436 | |
e2f8db50 DW |
437 | for (index = 0; index < SCI_MAX_PHYS; index++) { |
438 | if ((sci_port->phy_table[index] != NULL) | |
439 | && (index != phy_index)) { | |
440 | existing_phy_index = index; | |
441 | } | |
442 | } | |
6f231dda | 443 | |
e2f8db50 DW |
444 | /* |
445 | * Ensure that all of the phys in the port are capable of | |
446 | * operating at the same maximum link rate. */ | |
447 | if ( | |
448 | (existing_phy_index < SCI_MAX_PHYS) | |
449 | && (sci_port->owning_controller->user_parameters.sds1.phys[ | |
450 | phy_index].max_speed_generation != | |
451 | sci_port->owning_controller->user_parameters.sds1.phys[ | |
452 | existing_phy_index].max_speed_generation) | |
453 | ) | |
454 | return false; | |
6f231dda | 455 | |
e2f8db50 DW |
456 | return true; |
457 | } | |
6f231dda | 458 | |
e2f8db50 DW |
459 | /** |
460 | * | |
461 | * @sci_port: This is the port object for which to determine if the phy mask | |
462 | * can be supported. | |
463 | * | |
464 | * This method will return a true value if the port's phy mask can be supported | |
465 | * by the SCU. The following is a list of valid PHY mask configurations for | |
466 | * each port: - Port 0 - [[3 2] 1] 0 - Port 1 - [1] - Port 2 - [[3] 2] | |
467 | * - Port 3 - [3] This method returns a boolean indication specifying if the | |
468 | * phy mask can be supported. true if this is a valid phy assignment for the | |
469 | * port false if this is not a valid phy assignment for the port | |
470 | */ | |
471 | static bool scic_sds_port_is_phy_mask_valid( | |
472 | struct scic_sds_port *sci_port, | |
473 | u32 phy_mask) | |
474 | { | |
475 | if (sci_port->physical_port_index == 0) { | |
476 | if (((phy_mask & 0x0F) == 0x0F) | |
477 | || ((phy_mask & 0x03) == 0x03) | |
478 | || ((phy_mask & 0x01) == 0x01) | |
479 | || (phy_mask == 0)) | |
480 | return true; | |
481 | } else if (sci_port->physical_port_index == 1) { | |
482 | if (((phy_mask & 0x02) == 0x02) | |
483 | || (phy_mask == 0)) | |
484 | return true; | |
485 | } else if (sci_port->physical_port_index == 2) { | |
486 | if (((phy_mask & 0x0C) == 0x0C) | |
487 | || ((phy_mask & 0x04) == 0x04) | |
488 | || (phy_mask == 0)) | |
489 | return true; | |
490 | } else if (sci_port->physical_port_index == 3) { | |
491 | if (((phy_mask & 0x08) == 0x08) | |
492 | || (phy_mask == 0)) | |
493 | return true; | |
494 | } | |
6f231dda | 495 | |
e2f8db50 DW |
496 | return false; |
497 | } | |
6f231dda | 498 | |
e2f8db50 DW |
499 | /** |
500 | * | |
501 | * @sci_port: This parameter specifies the port from which to return a | |
502 | * connected phy. | |
503 | * | |
504 | * This method retrieves a currently active (i.e. connected) phy contained in | |
505 | * the port. Currently, the lowest order phy that is connected is returned. | |
506 | * This method returns a pointer to a SCIS_SDS_PHY object. NULL This value is | |
507 | * returned if there are no currently active (i.e. connected to a remote end | |
508 | * point) phys contained in the port. All other values specify a struct scic_sds_phy | |
509 | * object that is active in the port. | |
510 | */ | |
511 | static struct scic_sds_phy *scic_sds_port_get_a_connected_phy( | |
512 | struct scic_sds_port *sci_port | |
513 | ) { | |
514 | u32 index; | |
515 | struct scic_sds_phy *phy; | |
6f231dda | 516 | |
e2f8db50 DW |
517 | for (index = 0; index < SCI_MAX_PHYS; index++) { |
518 | /* | |
519 | * Ensure that the phy is both part of the port and currently | |
520 | * connected to the remote end-point. */ | |
521 | phy = sci_port->phy_table[index]; | |
522 | if ( | |
523 | (phy != NULL) | |
524 | && scic_sds_port_active_phy(sci_port, phy) | |
525 | ) { | |
526 | return phy; | |
527 | } | |
6f231dda DW |
528 | } |
529 | ||
e2f8db50 DW |
530 | return NULL; |
531 | } | |
532 | ||
533 | /** | |
534 | * scic_sds_port_set_phy() - | |
535 | * @out]: port The port object to which the phy assignement is being made. | |
536 | * @out]: phy The phy which is being assigned to the port. | |
537 | * | |
538 | * This method attempts to make the assignment of the phy to the port. If | |
539 | * successful the phy is assigned to the ports phy table. bool true if the phy | |
540 | * assignment can be made. false if the phy assignement can not be made. This | |
541 | * is a functional test that only fails if the phy is currently assigned to a | |
542 | * different port. | |
543 | */ | |
544 | static enum sci_status scic_sds_port_set_phy( | |
545 | struct scic_sds_port *port, | |
546 | struct scic_sds_phy *phy) | |
547 | { | |
548 | /* | |
549 | * Check to see if we can add this phy to a port | |
550 | * that means that the phy is not part of a port and that the port does | |
551 | * not already have a phy assinged to the phy index. */ | |
552 | if ( | |
553 | (port->phy_table[phy->phy_index] == NULL) | |
4f20ef4f | 554 | && (phy_get_non_dummy_port(phy) == NULL) |
e2f8db50 DW |
555 | && scic_sds_port_is_valid_phy_assignment(port, phy->phy_index) |
556 | ) { | |
557 | /* | |
558 | * Phy is being added in the stopped state so we are in MPC mode | |
559 | * make logical port index = physical port index */ | |
560 | port->logical_port_index = port->physical_port_index; | |
561 | port->phy_table[phy->phy_index] = phy; | |
562 | scic_sds_phy_set_port(phy, port); | |
563 | ||
564 | return SCI_SUCCESS; | |
565 | } | |
566 | ||
567 | return SCI_FAILURE; | |
568 | } | |
569 | ||
570 | /** | |
571 | * scic_sds_port_clear_phy() - | |
572 | * @out]: port The port from which the phy is being cleared. | |
573 | * @out]: phy The phy being cleared from the port. | |
574 | * | |
575 | * This method will clear the phy assigned to this port. This method fails if | |
576 | * this phy is not currently assinged to this port. bool true if the phy is | |
577 | * removed from the port. false if this phy is not assined to this port. | |
578 | */ | |
579 | static enum sci_status scic_sds_port_clear_phy( | |
580 | struct scic_sds_port *port, | |
581 | struct scic_sds_phy *phy) | |
582 | { | |
583 | /* Make sure that this phy is part of this port */ | |
584 | if (port->phy_table[phy->phy_index] == phy && | |
4f20ef4f | 585 | phy_get_non_dummy_port(phy) == port) { |
e2f8db50 DW |
586 | struct scic_sds_controller *scic = port->owning_controller; |
587 | struct isci_host *ihost = scic_to_ihost(scic); | |
588 | ||
589 | /* Yep it is assigned to this port so remove it */ | |
590 | scic_sds_phy_set_port(phy, &ihost->ports[SCI_MAX_PORTS].sci); | |
591 | port->phy_table[phy->phy_index] = NULL; | |
592 | return SCI_SUCCESS; | |
593 | } | |
594 | ||
595 | return SCI_FAILURE; | |
596 | } | |
597 | ||
e2f8db50 DW |
598 | |
599 | /** | |
600 | * This method requests the SAS address for the supplied SAS port from the SCI | |
601 | * implementation. | |
602 | * @sci_port: a handle corresponding to the SAS port for which to return the | |
603 | * SAS address. | |
604 | * @sas_address: This parameter specifies a pointer to a SAS address structure | |
605 | * into which the core will copy the SAS address for the port. | |
606 | * | |
607 | */ | |
608 | void scic_sds_port_get_sas_address( | |
609 | struct scic_sds_port *sci_port, | |
610 | struct sci_sas_address *sas_address) | |
611 | { | |
612 | u32 index; | |
613 | ||
614 | sas_address->high = 0; | |
615 | sas_address->low = 0; | |
616 | ||
617 | for (index = 0; index < SCI_MAX_PHYS; index++) { | |
618 | if (sci_port->phy_table[index] != NULL) { | |
619 | scic_sds_phy_get_sas_address(sci_port->phy_table[index], sas_address); | |
620 | } | |
621 | } | |
622 | } | |
623 | ||
624 | /* | |
625 | * This function requests the SAS address for the device directly attached to | |
626 | * this SAS port. | |
627 | * @sci_port: a handle corresponding to the SAS port for which to return the | |
628 | * SAS address. | |
629 | * @sas_address: This parameter specifies a pointer to a SAS address structure | |
630 | * into which the core will copy the SAS address for the device directly | |
631 | * attached to the port. | |
632 | * | |
633 | */ | |
634 | void scic_sds_port_get_attached_sas_address( | |
635 | struct scic_sds_port *sci_port, | |
636 | struct sci_sas_address *sas_address) | |
637 | { | |
638 | struct scic_sds_phy *sci_phy; | |
639 | ||
640 | /* | |
641 | * Ensure that the phy is both part of the port and currently | |
642 | * connected to the remote end-point. | |
6f231dda | 643 | */ |
e2f8db50 DW |
644 | sci_phy = scic_sds_port_get_a_connected_phy(sci_port); |
645 | if (sci_phy) { | |
646 | if (sci_phy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA) { | |
647 | scic_sds_phy_get_attached_sas_address(sci_phy, | |
648 | sas_address); | |
649 | } else { | |
650 | scic_sds_phy_get_sas_address(sci_phy, sas_address); | |
651 | sas_address->low += sci_phy->phy_index; | |
652 | } | |
653 | } else { | |
654 | sas_address->high = 0; | |
655 | sas_address->low = 0; | |
656 | } | |
657 | } | |
4393aa4e | 658 | |
e2f8db50 DW |
659 | /** |
660 | * scic_sds_port_construct_dummy_rnc() - create dummy rnc for si workaround | |
661 | * | |
662 | * @sci_port: logical port on which we need to create the remote node context | |
663 | * @rni: remote node index for this remote node context. | |
664 | * | |
665 | * This routine will construct a dummy remote node context data structure | |
666 | * This structure will be posted to the hardware to work around a scheduler | |
667 | * error in the hardware. | |
668 | */ | |
669 | static void scic_sds_port_construct_dummy_rnc(struct scic_sds_port *sci_port, u16 rni) | |
670 | { | |
671 | union scu_remote_node_context *rnc; | |
672 | ||
673 | rnc = &sci_port->owning_controller->remote_node_context_table[rni]; | |
674 | ||
675 | memset(rnc, 0, sizeof(union scu_remote_node_context)); | |
676 | ||
677 | rnc->ssp.remote_sas_address_hi = 0; | |
678 | rnc->ssp.remote_sas_address_lo = 0; | |
679 | ||
680 | rnc->ssp.remote_node_index = rni; | |
681 | rnc->ssp.remote_node_port_width = 1; | |
682 | rnc->ssp.logical_port_index = sci_port->physical_port_index; | |
683 | ||
684 | rnc->ssp.nexus_loss_timer_enable = false; | |
685 | rnc->ssp.check_bit = false; | |
686 | rnc->ssp.is_valid = true; | |
687 | rnc->ssp.is_remote_node_context = true; | |
688 | rnc->ssp.function_number = 0; | |
689 | rnc->ssp.arbitration_wait_time = 0; | |
690 | } | |
691 | ||
dd047c8e DW |
692 | /* |
693 | * construct a dummy task context data structure. This | |
e2f8db50 DW |
694 | * structure will be posted to the hardwre to work around a scheduler error |
695 | * in the hardware. | |
e2f8db50 | 696 | */ |
dd047c8e | 697 | static void scic_sds_port_construct_dummy_task(struct scic_sds_port *sci_port, u16 tag) |
e2f8db50 DW |
698 | { |
699 | struct scu_task_context *task_context; | |
700 | ||
dd047c8e | 701 | task_context = scic_sds_controller_get_task_context_buffer(sci_port->owning_controller, tag); |
e2f8db50 DW |
702 | |
703 | memset(task_context, 0, sizeof(struct scu_task_context)); | |
704 | ||
705 | task_context->abort = 0; | |
706 | task_context->priority = 0; | |
707 | task_context->initiator_request = 1; | |
708 | task_context->connection_rate = 1; | |
709 | task_context->protocol_engine_index = 0; | |
710 | task_context->logical_port_index = sci_port->physical_port_index; | |
711 | task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SSP; | |
dd047c8e | 712 | task_context->task_index = ISCI_TAG_TCI(tag); |
e2f8db50 DW |
713 | task_context->valid = SCU_TASK_CONTEXT_VALID; |
714 | task_context->context_type = SCU_TASK_CONTEXT_TYPE; | |
715 | ||
716 | task_context->remote_node_index = sci_port->reserved_rni; | |
717 | task_context->command_code = 0; | |
718 | ||
719 | task_context->link_layer_control = 0; | |
720 | task_context->do_not_dma_ssp_good_response = 1; | |
721 | task_context->strict_ordering = 0; | |
722 | task_context->control_frame = 0; | |
723 | task_context->timeout_enable = 0; | |
724 | task_context->block_guard_enable = 0; | |
725 | ||
726 | task_context->address_modifier = 0; | |
727 | ||
728 | task_context->task_phase = 0x01; | |
729 | } | |
730 | ||
731 | static void scic_sds_port_destroy_dummy_resources(struct scic_sds_port *sci_port) | |
732 | { | |
733 | struct scic_sds_controller *scic = sci_port->owning_controller; | |
734 | ||
735 | if (sci_port->reserved_tci != SCU_DUMMY_INDEX) | |
736 | scic_controller_free_io_tag(scic, sci_port->reserved_tci); | |
737 | ||
738 | if (sci_port->reserved_rni != SCU_DUMMY_INDEX) | |
739 | scic_sds_remote_node_table_release_remote_node_index(&scic->available_remote_nodes, | |
740 | 1, sci_port->reserved_rni); | |
741 | ||
742 | sci_port->reserved_rni = SCU_DUMMY_INDEX; | |
743 | sci_port->reserved_tci = SCU_DUMMY_INDEX; | |
744 | } | |
745 | ||
746 | /** | |
747 | * This method performs initialization of the supplied port. Initialization | |
748 | * includes: - state machine initialization - member variable initialization | |
749 | * - configuring the phy_mask | |
750 | * @sci_port: | |
751 | * @transport_layer_registers: | |
752 | * @port_task_scheduler_registers: | |
753 | * @port_configuration_regsiter: | |
754 | * | |
755 | * enum sci_status SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION This value is returned | |
756 | * if the phy being added to the port | |
757 | */ | |
758 | enum sci_status scic_sds_port_initialize( | |
759 | struct scic_sds_port *sci_port, | |
760 | void __iomem *port_task_scheduler_registers, | |
761 | void __iomem *port_configuration_regsiter, | |
762 | void __iomem *viit_registers) | |
763 | { | |
764 | sci_port->port_task_scheduler_registers = port_task_scheduler_registers; | |
765 | sci_port->port_pe_configuration_register = port_configuration_regsiter; | |
766 | sci_port->viit_registers = viit_registers; | |
767 | ||
768 | return SCI_SUCCESS; | |
769 | } | |
770 | ||
e2f8db50 DW |
771 | |
772 | /** | |
773 | * This method assigns the direct attached device ID for this port. | |
774 | * | |
775 | * @param[in] sci_port The port for which the direct attached device id is to | |
776 | * be assigned. | |
777 | * @param[in] device_id The direct attached device ID to assign to the port. | |
778 | * This will be the RNi for the device | |
779 | */ | |
780 | void scic_sds_port_setup_transports( | |
781 | struct scic_sds_port *sci_port, | |
782 | u32 device_id) | |
783 | { | |
784 | u8 index; | |
785 | ||
786 | for (index = 0; index < SCI_MAX_PHYS; index++) { | |
787 | if (sci_port->active_phy_mask & (1 << index)) | |
788 | scic_sds_phy_setup_transport(sci_port->phy_table[index], device_id); | |
6f231dda | 789 | } |
e2f8db50 | 790 | } |
6f231dda | 791 | |
e2f8db50 DW |
792 | /** |
793 | * | |
794 | * @sci_port: This is the port on which the phy should be enabled. | |
795 | * @sci_phy: This is the specific phy which to enable. | |
796 | * @do_notify_user: This parameter specifies whether to inform the user (via | |
797 | * scic_cb_port_link_up()) as to the fact that a new phy as become ready. | |
798 | * | |
799 | * This function will activate the phy in the port. | |
800 | * Activation includes: - adding | |
801 | * the phy to the port - enabling the Protocol Engine in the silicon. - | |
802 | * notifying the user that the link is up. none | |
803 | */ | |
804 | static void scic_sds_port_activate_phy(struct scic_sds_port *sci_port, | |
805 | struct scic_sds_phy *sci_phy, | |
806 | bool do_notify_user) | |
807 | { | |
808 | struct scic_sds_controller *scic = sci_port->owning_controller; | |
809 | struct isci_host *ihost = scic_to_ihost(scic); | |
810 | ||
811 | if (sci_phy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA) | |
812 | scic_sds_phy_resume(sci_phy); | |
813 | ||
814 | sci_port->active_phy_mask |= 1 << sci_phy->phy_index; | |
815 | ||
816 | scic_sds_controller_clear_invalid_phy(scic, sci_phy); | |
817 | ||
818 | if (do_notify_user == true) | |
819 | isci_port_link_up(ihost, sci_port, sci_phy); | |
6f231dda | 820 | } |
09d7da13 | 821 | |
e2f8db50 DW |
822 | void scic_sds_port_deactivate_phy(struct scic_sds_port *sci_port, |
823 | struct scic_sds_phy *sci_phy, | |
824 | bool do_notify_user) | |
09d7da13 | 825 | { |
e2f8db50 DW |
826 | struct scic_sds_controller *scic = scic_sds_port_get_controller(sci_port); |
827 | struct isci_port *iport = sci_port_to_iport(sci_port); | |
828 | struct isci_host *ihost = scic_to_ihost(scic); | |
829 | struct isci_phy *iphy = sci_phy_to_iphy(sci_phy); | |
830 | ||
831 | sci_port->active_phy_mask &= ~(1 << sci_phy->phy_index); | |
832 | ||
833 | sci_phy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN; | |
834 | ||
835 | /* Re-assign the phy back to the LP as if it were a narrow port */ | |
836 | writel(sci_phy->phy_index, | |
837 | &sci_port->port_pe_configuration_register[sci_phy->phy_index]); | |
838 | ||
839 | if (do_notify_user == true) | |
840 | isci_port_link_down(ihost, iphy, iport); | |
841 | } | |
842 | ||
843 | /** | |
844 | * | |
845 | * @sci_port: This is the port on which the phy should be disabled. | |
846 | * @sci_phy: This is the specific phy which to disabled. | |
847 | * | |
848 | * This function will disable the phy and report that the phy is not valid for | |
849 | * this port object. None | |
850 | */ | |
851 | static void scic_sds_port_invalid_link_up(struct scic_sds_port *sci_port, | |
852 | struct scic_sds_phy *sci_phy) | |
853 | { | |
854 | struct scic_sds_controller *scic = sci_port->owning_controller; | |
855 | ||
856 | /* | |
857 | * Check to see if we have alreay reported this link as bad and if | |
858 | * not go ahead and tell the SCI_USER that we have discovered an | |
859 | * invalid link. | |
860 | */ | |
861 | if ((scic->invalid_phy_mask & (1 << sci_phy->phy_index)) == 0) { | |
862 | scic_sds_controller_set_invalid_phy(scic, sci_phy); | |
863 | dev_warn(&scic_to_ihost(scic)->pdev->dev, "Invalid link up!\n"); | |
864 | } | |
865 | } | |
866 | ||
e91f41ef PS |
867 | static bool is_port_ready_state(enum scic_sds_port_states state) |
868 | { | |
869 | switch (state) { | |
e301370a EN |
870 | case SCI_PORT_READY: |
871 | case SCI_PORT_SUB_WAITING: | |
872 | case SCI_PORT_SUB_OPERATIONAL: | |
873 | case SCI_PORT_SUB_CONFIGURING: | |
e91f41ef PS |
874 | return true; |
875 | default: | |
876 | return false; | |
877 | } | |
878 | } | |
879 | ||
880 | /* flag dummy rnc hanling when exiting a ready state */ | |
881 | static void port_state_machine_change(struct scic_sds_port *sci_port, | |
882 | enum scic_sds_port_states state) | |
883 | { | |
e301370a | 884 | struct sci_base_state_machine *sm = &sci_port->sm; |
e91f41ef PS |
885 | enum scic_sds_port_states old_state = sm->current_state_id; |
886 | ||
887 | if (is_port_ready_state(old_state) && !is_port_ready_state(state)) | |
888 | sci_port->ready_exit = true; | |
889 | ||
e301370a | 890 | sci_change_state(sm, state); |
e91f41ef PS |
891 | sci_port->ready_exit = false; |
892 | } | |
893 | ||
e2f8db50 DW |
894 | /** |
895 | * scic_sds_port_general_link_up_handler - phy can be assigned to port? | |
896 | * @sci_port: scic_sds_port object for which has a phy that has gone link up. | |
897 | * @sci_phy: This is the struct scic_sds_phy object that has gone link up. | |
898 | * @do_notify_user: This parameter specifies whether to inform the user (via | |
899 | * scic_cb_port_link_up()) as to the fact that a new phy as become ready. | |
900 | * | |
901 | * Determine if this phy can be assigned to this | |
902 | * port . If the phy is not a valid PHY for | |
903 | * this port then the function will notify the user. A PHY can only be | |
904 | * part of a port if it's attached SAS ADDRESS is the same as all other PHYs in | |
905 | * the same port. none | |
906 | */ | |
907 | static void scic_sds_port_general_link_up_handler(struct scic_sds_port *sci_port, | |
908 | struct scic_sds_phy *sci_phy, | |
909 | bool do_notify_user) | |
910 | { | |
911 | struct sci_sas_address port_sas_address; | |
912 | struct sci_sas_address phy_sas_address; | |
913 | ||
914 | scic_sds_port_get_attached_sas_address(sci_port, &port_sas_address); | |
915 | scic_sds_phy_get_attached_sas_address(sci_phy, &phy_sas_address); | |
916 | ||
917 | /* If the SAS address of the new phy matches the SAS address of | |
918 | * other phys in the port OR this is the first phy in the port, | |
919 | * then activate the phy and allow it to be used for operations | |
920 | * in this port. | |
921 | */ | |
922 | if ((phy_sas_address.high == port_sas_address.high && | |
923 | phy_sas_address.low == port_sas_address.low) || | |
924 | sci_port->active_phy_mask == 0) { | |
e301370a | 925 | struct sci_base_state_machine *sm = &sci_port->sm; |
e2f8db50 DW |
926 | |
927 | scic_sds_port_activate_phy(sci_port, sci_phy, do_notify_user); | |
e301370a EN |
928 | if (sm->current_state_id == SCI_PORT_RESETTING) |
929 | port_state_machine_change(sci_port, SCI_PORT_READY); | |
e2f8db50 DW |
930 | } else |
931 | scic_sds_port_invalid_link_up(sci_port, sci_phy); | |
932 | } | |
933 | ||
934 | ||
935 | ||
936 | /** | |
937 | * This method returns false if the port only has a single phy object assigned. | |
938 | * If there are no phys or more than one phy then the method will return | |
939 | * true. | |
940 | * @sci_port: The port for which the wide port condition is to be checked. | |
941 | * | |
942 | * bool true Is returned if this is a wide ported port. false Is returned if | |
943 | * this is a narrow port. | |
944 | */ | |
945 | static bool scic_sds_port_is_wide(struct scic_sds_port *sci_port) | |
946 | { | |
947 | u32 index; | |
948 | u32 phy_count = 0; | |
949 | ||
950 | for (index = 0; index < SCI_MAX_PHYS; index++) { | |
951 | if (sci_port->phy_table[index] != NULL) { | |
952 | phy_count++; | |
953 | } | |
954 | } | |
955 | ||
956 | return phy_count != 1; | |
957 | } | |
958 | ||
959 | /** | |
960 | * This method is called by the PHY object when the link is detected. if the | |
961 | * port wants the PHY to continue on to the link up state then the port | |
962 | * layer must return true. If the port object returns false the phy object | |
963 | * must halt its attempt to go link up. | |
964 | * @sci_port: The port associated with the phy object. | |
965 | * @sci_phy: The phy object that is trying to go link up. | |
966 | * | |
967 | * true if the phy object can continue to the link up condition. true Is | |
968 | * returned if this phy can continue to the ready state. false Is returned if | |
969 | * can not continue on to the ready state. This notification is in place for | |
970 | * wide ports and direct attached phys. Since there are no wide ported SATA | |
971 | * devices this could become an invalid port configuration. | |
972 | */ | |
973 | bool scic_sds_port_link_detected( | |
974 | struct scic_sds_port *sci_port, | |
975 | struct scic_sds_phy *sci_phy) | |
976 | { | |
977 | if ((sci_port->logical_port_index != SCIC_SDS_DUMMY_PORT) && | |
978 | (sci_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) && | |
979 | scic_sds_port_is_wide(sci_port)) { | |
980 | scic_sds_port_invalid_link_up(sci_port, sci_phy); | |
981 | ||
982 | return false; | |
983 | } | |
984 | ||
985 | return true; | |
986 | } | |
987 | ||
5553ba2b | 988 | static void port_timeout(unsigned long data) |
e2f8db50 | 989 | { |
5553ba2b EN |
990 | struct sci_timer *tmr = (struct sci_timer *)data; |
991 | struct scic_sds_port *sci_port = container_of(tmr, typeof(*sci_port), timer); | |
992 | struct isci_host *ihost = scic_to_ihost(sci_port->owning_controller); | |
993 | unsigned long flags; | |
e2f8db50 DW |
994 | u32 current_state; |
995 | ||
5553ba2b EN |
996 | spin_lock_irqsave(&ihost->scic_lock, flags); |
997 | ||
998 | if (tmr->cancel) | |
999 | goto done; | |
1000 | ||
e301370a | 1001 | current_state = sci_port->sm.current_state_id; |
e2f8db50 | 1002 | |
e301370a | 1003 | if (current_state == SCI_PORT_RESETTING) { |
e91f41ef PS |
1004 | /* if the port is still in the resetting state then the timeout |
1005 | * fired before the reset completed. | |
e2f8db50 | 1006 | */ |
e301370a EN |
1007 | port_state_machine_change(sci_port, SCI_PORT_FAILED); |
1008 | } else if (current_state == SCI_PORT_STOPPED) { | |
e91f41ef PS |
1009 | /* if the port is stopped then the start request failed In this |
1010 | * case stay in the stopped state. | |
e2f8db50 DW |
1011 | */ |
1012 | dev_err(sciport_to_dev(sci_port), | |
1013 | "%s: SCIC Port 0x%p failed to stop before tiemout.\n", | |
1014 | __func__, | |
1015 | sci_port); | |
e301370a | 1016 | } else if (current_state == SCI_PORT_STOPPING) { |
e91f41ef PS |
1017 | /* if the port is still stopping then the stop has not completed */ |
1018 | isci_port_stop_complete(sci_port->owning_controller, | |
1019 | sci_port, | |
1020 | SCI_FAILURE_TIMEOUT); | |
e2f8db50 | 1021 | } else { |
e91f41ef | 1022 | /* The port is in the ready state and we have a timer |
e2f8db50 DW |
1023 | * reporting a timeout this should not happen. |
1024 | */ | |
1025 | dev_err(sciport_to_dev(sci_port), | |
1026 | "%s: SCIC Port 0x%p is processing a timeout operation " | |
e91f41ef | 1027 | "in state %d.\n", __func__, sci_port, current_state); |
e2f8db50 | 1028 | } |
5553ba2b EN |
1029 | |
1030 | done: | |
1031 | spin_unlock_irqrestore(&ihost->scic_lock, flags); | |
e2f8db50 DW |
1032 | } |
1033 | ||
1034 | /* --------------------------------------------------------------------------- */ | |
1035 | ||
1036 | /** | |
1037 | * This function updates the hardwares VIIT entry for this port. | |
1038 | * | |
1039 | * | |
1040 | */ | |
1041 | static void scic_sds_port_update_viit_entry(struct scic_sds_port *sci_port) | |
1042 | { | |
1043 | struct sci_sas_address sas_address; | |
1044 | ||
1045 | scic_sds_port_get_sas_address(sci_port, &sas_address); | |
1046 | ||
1047 | writel(sas_address.high, | |
1048 | &sci_port->viit_registers->initiator_sas_address_hi); | |
1049 | writel(sas_address.low, | |
1050 | &sci_port->viit_registers->initiator_sas_address_lo); | |
1051 | ||
1052 | /* This value get cleared just in case its not already cleared */ | |
1053 | writel(0, &sci_port->viit_registers->reserved); | |
1054 | ||
1055 | /* We are required to update the status register last */ | |
1056 | writel(SCU_VIIT_ENTRY_ID_VIIT | | |
1057 | SCU_VIIT_IPPT_INITIATOR | | |
1058 | ((1 << sci_port->physical_port_index) << SCU_VIIT_ENTRY_LPVIE_SHIFT) | | |
1059 | SCU_VIIT_STATUS_ALL_VALID, | |
1060 | &sci_port->viit_registers->status); | |
1061 | } | |
1062 | ||
1063 | /** | |
1064 | * This method returns the maximum allowed speed for data transfers on this | |
1065 | * port. This maximum allowed speed evaluates to the maximum speed of the | |
1066 | * slowest phy in the port. | |
1067 | * @sci_port: This parameter specifies the port for which to retrieve the | |
1068 | * maximum allowed speed. | |
1069 | * | |
1070 | * This method returns the maximum negotiated speed of the slowest phy in the | |
1071 | * port. | |
1072 | */ | |
1073 | enum sas_linkrate scic_sds_port_get_max_allowed_speed( | |
1074 | struct scic_sds_port *sci_port) | |
1075 | { | |
1076 | u16 index; | |
1077 | enum sas_linkrate max_allowed_speed = SAS_LINK_RATE_6_0_GBPS; | |
1078 | struct scic_sds_phy *phy = NULL; | |
1079 | ||
1080 | /* | |
1081 | * Loop through all of the phys in this port and find the phy with the | |
1082 | * lowest maximum link rate. */ | |
1083 | for (index = 0; index < SCI_MAX_PHYS; index++) { | |
1084 | phy = sci_port->phy_table[index]; | |
1085 | if ( | |
1086 | (phy != NULL) | |
1087 | && (scic_sds_port_active_phy(sci_port, phy) == true) | |
1088 | && (phy->max_negotiated_speed < max_allowed_speed) | |
1089 | ) | |
1090 | max_allowed_speed = phy->max_negotiated_speed; | |
1091 | } | |
1092 | ||
1093 | return max_allowed_speed; | |
1094 | } | |
1095 | ||
e2f8db50 DW |
1096 | /** |
1097 | * | |
1098 | * @sci_port: This is the struct scic_sds_port object to suspend. | |
1099 | * | |
1100 | * This method will susped the port task scheduler for this port object. none | |
1101 | */ | |
1102 | static void | |
1103 | scic_sds_port_suspend_port_task_scheduler(struct scic_sds_port *port) | |
1104 | { | |
1105 | u32 pts_control_value; | |
1106 | ||
1107 | pts_control_value = readl(&port->port_task_scheduler_registers->control); | |
1108 | pts_control_value |= SCU_PTSxCR_GEN_BIT(SUSPEND); | |
1109 | writel(pts_control_value, &port->port_task_scheduler_registers->control); | |
1110 | } | |
1111 | ||
1112 | /** | |
1113 | * scic_sds_port_post_dummy_request() - post dummy/workaround request | |
1114 | * @sci_port: port to post task | |
1115 | * | |
1116 | * Prevent the hardware scheduler from posting new requests to the front | |
1117 | * of the scheduler queue causing a starvation problem for currently | |
1118 | * ongoing requests. | |
1119 | * | |
1120 | */ | |
1121 | static void scic_sds_port_post_dummy_request(struct scic_sds_port *sci_port) | |
1122 | { | |
1123 | u32 command; | |
1124 | struct scu_task_context *task_context; | |
1125 | struct scic_sds_controller *scic = sci_port->owning_controller; | |
1126 | u16 tci = sci_port->reserved_tci; | |
1127 | ||
1128 | task_context = scic_sds_controller_get_task_context_buffer(scic, tci); | |
1129 | ||
1130 | task_context->abort = 0; | |
1131 | ||
1132 | command = SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC | | |
1133 | sci_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | | |
1134 | tci; | |
1135 | ||
1136 | scic_sds_controller_post_request(scic, command); | |
1137 | } | |
1138 | ||
1139 | /** | |
1140 | * This routine will abort the dummy request. This will alow the hardware to | |
1141 | * power down parts of the silicon to save power. | |
1142 | * | |
1143 | * @sci_port: The port on which the task must be aborted. | |
1144 | * | |
1145 | */ | |
1146 | static void scic_sds_port_abort_dummy_request(struct scic_sds_port *sci_port) | |
1147 | { | |
1148 | struct scic_sds_controller *scic = sci_port->owning_controller; | |
1149 | u16 tci = sci_port->reserved_tci; | |
1150 | struct scu_task_context *tc; | |
1151 | u32 command; | |
1152 | ||
1153 | tc = scic_sds_controller_get_task_context_buffer(scic, tci); | |
1154 | ||
1155 | tc->abort = 1; | |
1156 | ||
1157 | command = SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT | | |
1158 | sci_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | | |
1159 | tci; | |
1160 | ||
1161 | scic_sds_controller_post_request(scic, command); | |
1162 | } | |
1163 | ||
1164 | /** | |
1165 | * | |
1166 | * @sci_port: This is the struct scic_sds_port object to resume. | |
1167 | * | |
1168 | * This method will resume the port task scheduler for this port object. none | |
1169 | */ | |
1170 | static void | |
1171 | scic_sds_port_resume_port_task_scheduler(struct scic_sds_port *port) | |
1172 | { | |
1173 | u32 pts_control_value; | |
1174 | ||
1175 | pts_control_value = readl(&port->port_task_scheduler_registers->control); | |
1176 | pts_control_value &= ~SCU_PTSxCR_GEN_BIT(SUSPEND); | |
1177 | writel(pts_control_value, &port->port_task_scheduler_registers->control); | |
1178 | } | |
1179 | ||
9269e0e8 | 1180 | static void scic_sds_port_ready_substate_waiting_enter(struct sci_base_state_machine *sm) |
e2f8db50 | 1181 | { |
e301370a | 1182 | struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), sm); |
e2f8db50 | 1183 | |
e2f8db50 DW |
1184 | scic_sds_port_suspend_port_task_scheduler(sci_port); |
1185 | ||
1186 | sci_port->not_ready_reason = SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS; | |
1187 | ||
1188 | if (sci_port->active_phy_mask != 0) { | |
1189 | /* At least one of the phys on the port is ready */ | |
e91f41ef | 1190 | port_state_machine_change(sci_port, |
e301370a | 1191 | SCI_PORT_SUB_OPERATIONAL); |
e2f8db50 DW |
1192 | } |
1193 | } | |
1194 | ||
9269e0e8 | 1195 | static void scic_sds_port_ready_substate_operational_enter(struct sci_base_state_machine *sm) |
e2f8db50 DW |
1196 | { |
1197 | u32 index; | |
e301370a | 1198 | struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), sm); |
e2f8db50 DW |
1199 | struct scic_sds_controller *scic = sci_port->owning_controller; |
1200 | struct isci_host *ihost = scic_to_ihost(scic); | |
1201 | struct isci_port *iport = sci_port_to_iport(sci_port); | |
1202 | ||
e2f8db50 DW |
1203 | isci_port_ready(ihost, iport); |
1204 | ||
1205 | for (index = 0; index < SCI_MAX_PHYS; index++) { | |
1206 | if (sci_port->phy_table[index]) { | |
1207 | writel(sci_port->physical_port_index, | |
1208 | &sci_port->port_pe_configuration_register[ | |
1209 | sci_port->phy_table[index]->phy_index]); | |
1210 | } | |
1211 | } | |
1212 | ||
1213 | scic_sds_port_update_viit_entry(sci_port); | |
1214 | ||
1215 | scic_sds_port_resume_port_task_scheduler(sci_port); | |
1216 | ||
1217 | /* | |
1218 | * Post the dummy task for the port so the hardware can schedule | |
1219 | * io correctly | |
1220 | */ | |
1221 | scic_sds_port_post_dummy_request(sci_port); | |
1222 | } | |
1223 | ||
e91f41ef PS |
1224 | static void scic_sds_port_invalidate_dummy_remote_node(struct scic_sds_port *sci_port) |
1225 | { | |
1226 | struct scic_sds_controller *scic = sci_port->owning_controller; | |
1227 | u8 phys_index = sci_port->physical_port_index; | |
1228 | union scu_remote_node_context *rnc; | |
1229 | u16 rni = sci_port->reserved_rni; | |
1230 | u32 command; | |
1231 | ||
1232 | rnc = &scic->remote_node_context_table[rni]; | |
1233 | ||
1234 | rnc->ssp.is_valid = false; | |
1235 | ||
1236 | /* ensure the preceding tc abort request has reached the | |
1237 | * controller and give it ample time to act before posting the rnc | |
1238 | * invalidate | |
1239 | */ | |
1240 | readl(&scic->smu_registers->interrupt_status); /* flush */ | |
1241 | udelay(10); | |
1242 | ||
1243 | command = SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE | | |
1244 | phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni; | |
1245 | ||
1246 | scic_sds_controller_post_request(scic, command); | |
1247 | } | |
1248 | ||
e2f8db50 DW |
1249 | /** |
1250 | * | |
1251 | * @object: This is the object which is cast to a struct scic_sds_port object. | |
1252 | * | |
1253 | * This method will perform the actions required by the struct scic_sds_port on | |
e301370a | 1254 | * exiting the SCI_PORT_SUB_OPERATIONAL. This function reports |
e2f8db50 DW |
1255 | * the port not ready and suspends the port task scheduler. none |
1256 | */ | |
9269e0e8 | 1257 | static void scic_sds_port_ready_substate_operational_exit(struct sci_base_state_machine *sm) |
e2f8db50 | 1258 | { |
e301370a | 1259 | struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), sm); |
e2f8db50 DW |
1260 | struct scic_sds_controller *scic = sci_port->owning_controller; |
1261 | struct isci_host *ihost = scic_to_ihost(scic); | |
1262 | struct isci_port *iport = sci_port_to_iport(sci_port); | |
1263 | ||
1264 | /* | |
1265 | * Kill the dummy task for this port if it has not yet posted | |
1266 | * the hardware will treat this as a NOP and just return abort | |
1267 | * complete. | |
1268 | */ | |
1269 | scic_sds_port_abort_dummy_request(sci_port); | |
1270 | ||
1271 | isci_port_not_ready(ihost, iport); | |
e91f41ef PS |
1272 | |
1273 | if (sci_port->ready_exit) | |
1274 | scic_sds_port_invalidate_dummy_remote_node(sci_port); | |
e2f8db50 DW |
1275 | } |
1276 | ||
9269e0e8 | 1277 | static void scic_sds_port_ready_substate_configuring_enter(struct sci_base_state_machine *sm) |
e2f8db50 | 1278 | { |
e301370a | 1279 | struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), sm); |
e2f8db50 DW |
1280 | struct scic_sds_controller *scic = sci_port->owning_controller; |
1281 | struct isci_host *ihost = scic_to_ihost(scic); | |
1282 | struct isci_port *iport = sci_port_to_iport(sci_port); | |
1283 | ||
e2f8db50 DW |
1284 | if (sci_port->active_phy_mask == 0) { |
1285 | isci_port_not_ready(ihost, iport); | |
1286 | ||
e91f41ef | 1287 | port_state_machine_change(sci_port, |
e301370a | 1288 | SCI_PORT_SUB_WAITING); |
e2f8db50 | 1289 | } else if (sci_port->started_request_count == 0) |
e91f41ef | 1290 | port_state_machine_change(sci_port, |
e301370a | 1291 | SCI_PORT_SUB_OPERATIONAL); |
e2f8db50 DW |
1292 | } |
1293 | ||
9269e0e8 | 1294 | static void scic_sds_port_ready_substate_configuring_exit(struct sci_base_state_machine *sm) |
e2f8db50 | 1295 | { |
e301370a | 1296 | struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), sm); |
e2f8db50 DW |
1297 | |
1298 | scic_sds_port_suspend_port_task_scheduler(sci_port); | |
e91f41ef PS |
1299 | if (sci_port->ready_exit) |
1300 | scic_sds_port_invalidate_dummy_remote_node(sci_port); | |
e2f8db50 DW |
1301 | } |
1302 | ||
d76f71d9 PS |
1303 | enum sci_status scic_sds_port_start(struct scic_sds_port *sci_port) |
1304 | { | |
1305 | struct scic_sds_controller *scic = sci_port->owning_controller; | |
d76f71d9 PS |
1306 | enum sci_status status = SCI_SUCCESS; |
1307 | enum scic_sds_port_states state; | |
1308 | u32 phy_mask; | |
1309 | ||
e301370a EN |
1310 | state = sci_port->sm.current_state_id; |
1311 | if (state != SCI_PORT_STOPPED) { | |
d76f71d9 PS |
1312 | dev_warn(sciport_to_dev(sci_port), |
1313 | "%s: in wrong state: %d\n", __func__, state); | |
1314 | return SCI_FAILURE_INVALID_STATE; | |
1315 | } | |
1316 | ||
1317 | if (sci_port->assigned_device_count > 0) { | |
1318 | /* TODO This is a start failure operation because | |
1319 | * there are still devices assigned to this port. | |
1320 | * There must be no devices assigned to a port on a | |
1321 | * start operation. | |
1322 | */ | |
1323 | return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION; | |
1324 | } | |
1325 | ||
d76f71d9 PS |
1326 | if (sci_port->reserved_rni == SCU_DUMMY_INDEX) { |
1327 | u16 rni = scic_sds_remote_node_table_allocate_remote_node( | |
1328 | &scic->available_remote_nodes, 1); | |
1329 | ||
1330 | if (rni != SCU_DUMMY_INDEX) | |
1331 | scic_sds_port_construct_dummy_rnc(sci_port, rni); | |
1332 | else | |
1333 | status = SCI_FAILURE_INSUFFICIENT_RESOURCES; | |
1334 | sci_port->reserved_rni = rni; | |
1335 | } | |
1336 | ||
1337 | if (sci_port->reserved_tci == SCU_DUMMY_INDEX) { | |
1338 | /* Allocate a TCI and remove the sequence nibble */ | |
1339 | u16 tci = scic_controller_allocate_io_tag(scic); | |
1340 | ||
1341 | if (tci != SCU_DUMMY_INDEX) | |
1342 | scic_sds_port_construct_dummy_task(sci_port, tci); | |
1343 | else | |
1344 | status = SCI_FAILURE_INSUFFICIENT_RESOURCES; | |
1345 | sci_port->reserved_tci = tci; | |
1346 | } | |
1347 | ||
1348 | if (status == SCI_SUCCESS) { | |
1349 | phy_mask = scic_sds_port_get_phys(sci_port); | |
1350 | ||
1351 | /* | |
1352 | * There are one or more phys assigned to this port. Make sure | |
1353 | * the port's phy mask is in fact legal and supported by the | |
1354 | * silicon. | |
1355 | */ | |
1356 | if (scic_sds_port_is_phy_mask_valid(sci_port, phy_mask) == true) { | |
1357 | port_state_machine_change(sci_port, | |
e301370a | 1358 | SCI_PORT_READY); |
d76f71d9 PS |
1359 | |
1360 | return SCI_SUCCESS; | |
1361 | } | |
1362 | status = SCI_FAILURE; | |
1363 | } | |
1364 | ||
1365 | if (status != SCI_SUCCESS) | |
1366 | scic_sds_port_destroy_dummy_resources(sci_port); | |
1367 | ||
1368 | return status; | |
1369 | } | |
1370 | ||
8bc80d30 PS |
1371 | enum sci_status scic_sds_port_stop(struct scic_sds_port *sci_port) |
1372 | { | |
1373 | enum scic_sds_port_states state; | |
1374 | ||
e301370a | 1375 | state = sci_port->sm.current_state_id; |
8bc80d30 | 1376 | switch (state) { |
e301370a | 1377 | case SCI_PORT_STOPPED: |
8bc80d30 | 1378 | return SCI_SUCCESS; |
e301370a EN |
1379 | case SCI_PORT_SUB_WAITING: |
1380 | case SCI_PORT_SUB_OPERATIONAL: | |
1381 | case SCI_PORT_SUB_CONFIGURING: | |
1382 | case SCI_PORT_RESETTING: | |
8bc80d30 | 1383 | port_state_machine_change(sci_port, |
e301370a | 1384 | SCI_PORT_STOPPING); |
8bc80d30 PS |
1385 | return SCI_SUCCESS; |
1386 | default: | |
1387 | dev_warn(sciport_to_dev(sci_port), | |
1388 | "%s: in wrong state: %d\n", __func__, state); | |
1389 | return SCI_FAILURE_INVALID_STATE; | |
1390 | } | |
1391 | } | |
1392 | ||
bd6713b4 PS |
1393 | static enum sci_status scic_port_hard_reset(struct scic_sds_port *sci_port, u32 timeout) |
1394 | { | |
1395 | enum sci_status status = SCI_FAILURE_INVALID_PHY; | |
1396 | struct scic_sds_phy *selected_phy = NULL; | |
1397 | enum scic_sds_port_states state; | |
1398 | u32 phy_index; | |
1399 | ||
e301370a EN |
1400 | state = sci_port->sm.current_state_id; |
1401 | if (state != SCI_PORT_SUB_OPERATIONAL) { | |
bd6713b4 PS |
1402 | dev_warn(sciport_to_dev(sci_port), |
1403 | "%s: in wrong state: %d\n", __func__, state); | |
1404 | return SCI_FAILURE_INVALID_STATE; | |
1405 | } | |
1406 | ||
1407 | /* Select a phy on which we can send the hard reset request. */ | |
1408 | for (phy_index = 0; phy_index < SCI_MAX_PHYS && !selected_phy; phy_index++) { | |
1409 | selected_phy = sci_port->phy_table[phy_index]; | |
1410 | if (selected_phy && | |
1411 | !scic_sds_port_active_phy(sci_port, selected_phy)) { | |
1412 | /* | |
1413 | * We found a phy but it is not ready select | |
1414 | * different phy | |
1415 | */ | |
1416 | selected_phy = NULL; | |
1417 | } | |
1418 | } | |
1419 | ||
1420 | /* If we have a phy then go ahead and start the reset procedure */ | |
1421 | if (!selected_phy) | |
1422 | return status; | |
1423 | status = scic_sds_phy_reset(selected_phy); | |
1424 | ||
1425 | if (status != SCI_SUCCESS) | |
1426 | return status; | |
1427 | ||
5553ba2b | 1428 | sci_mod_timer(&sci_port->timer, timeout); |
bd6713b4 PS |
1429 | sci_port->not_ready_reason = SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED; |
1430 | ||
1431 | port_state_machine_change(sci_port, | |
e301370a | 1432 | SCI_PORT_RESETTING); |
bd6713b4 PS |
1433 | return SCI_SUCCESS; |
1434 | } | |
1435 | ||
1436 | /** | |
1437 | * scic_sds_port_add_phy() - | |
1438 | * @sci_port: This parameter specifies the port in which the phy will be added. | |
1439 | * @sci_phy: This parameter is the phy which is to be added to the port. | |
1440 | * | |
1441 | * This method will add a PHY to the selected port. This method returns an | |
1442 | * enum sci_status. SCI_SUCCESS the phy has been added to the port. Any other | |
1443 | * status is a failure to add the phy to the port. | |
1444 | */ | |
1445 | enum sci_status scic_sds_port_add_phy(struct scic_sds_port *sci_port, | |
1446 | struct scic_sds_phy *sci_phy) | |
1447 | { | |
1448 | enum sci_status status; | |
1449 | enum scic_sds_port_states state; | |
1450 | ||
e301370a | 1451 | state = sci_port->sm.current_state_id; |
bd6713b4 | 1452 | switch (state) { |
e301370a | 1453 | case SCI_PORT_STOPPED: { |
bd6713b4 PS |
1454 | struct sci_sas_address port_sas_address; |
1455 | ||
1456 | /* Read the port assigned SAS Address if there is one */ | |
1457 | scic_sds_port_get_sas_address(sci_port, &port_sas_address); | |
1458 | ||
1459 | if (port_sas_address.high != 0 && port_sas_address.low != 0) { | |
1460 | struct sci_sas_address phy_sas_address; | |
1461 | ||
1462 | /* Make sure that the PHY SAS Address matches the SAS Address | |
1463 | * for this port | |
1464 | */ | |
1465 | scic_sds_phy_get_sas_address(sci_phy, &phy_sas_address); | |
1466 | ||
1467 | if (port_sas_address.high != phy_sas_address.high || | |
1468 | port_sas_address.low != phy_sas_address.low) | |
1469 | return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION; | |
1470 | } | |
1471 | return scic_sds_port_set_phy(sci_port, sci_phy); | |
1472 | } | |
e301370a EN |
1473 | case SCI_PORT_SUB_WAITING: |
1474 | case SCI_PORT_SUB_OPERATIONAL: | |
bd6713b4 PS |
1475 | status = scic_sds_port_set_phy(sci_port, sci_phy); |
1476 | ||
1477 | if (status != SCI_SUCCESS) | |
1478 | return status; | |
1479 | ||
1480 | scic_sds_port_general_link_up_handler(sci_port, sci_phy, true); | |
1481 | sci_port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING; | |
e301370a | 1482 | port_state_machine_change(sci_port, SCI_PORT_SUB_CONFIGURING); |
bd6713b4 PS |
1483 | |
1484 | return status; | |
e301370a | 1485 | case SCI_PORT_SUB_CONFIGURING: |
bd6713b4 PS |
1486 | status = scic_sds_port_set_phy(sci_port, sci_phy); |
1487 | ||
1488 | if (status != SCI_SUCCESS) | |
1489 | return status; | |
1490 | scic_sds_port_general_link_up_handler(sci_port, sci_phy, true); | |
1491 | ||
1492 | /* Re-enter the configuring state since this may be the last phy in | |
1493 | * the port. | |
1494 | */ | |
1495 | port_state_machine_change(sci_port, | |
e301370a | 1496 | SCI_PORT_SUB_CONFIGURING); |
bd6713b4 PS |
1497 | return SCI_SUCCESS; |
1498 | default: | |
1499 | dev_warn(sciport_to_dev(sci_port), | |
1500 | "%s: in wrong state: %d\n", __func__, state); | |
1501 | return SCI_FAILURE_INVALID_STATE; | |
1502 | } | |
1503 | } | |
1504 | ||
1505 | /** | |
1506 | * scic_sds_port_remove_phy() - | |
1507 | * @sci_port: This parameter specifies the port in which the phy will be added. | |
1508 | * @sci_phy: This parameter is the phy which is to be added to the port. | |
1509 | * | |
1510 | * This method will remove the PHY from the selected PORT. This method returns | |
1511 | * an enum sci_status. SCI_SUCCESS the phy has been removed from the port. Any | |
1512 | * other status is a failure to add the phy to the port. | |
1513 | */ | |
1514 | enum sci_status scic_sds_port_remove_phy(struct scic_sds_port *sci_port, | |
1515 | struct scic_sds_phy *sci_phy) | |
1516 | { | |
1517 | enum sci_status status; | |
1518 | enum scic_sds_port_states state; | |
1519 | ||
e301370a | 1520 | state = sci_port->sm.current_state_id; |
bd6713b4 PS |
1521 | |
1522 | switch (state) { | |
e301370a | 1523 | case SCI_PORT_STOPPED: |
bd6713b4 | 1524 | return scic_sds_port_clear_phy(sci_port, sci_phy); |
e301370a | 1525 | case SCI_PORT_SUB_OPERATIONAL: |
bd6713b4 PS |
1526 | status = scic_sds_port_clear_phy(sci_port, sci_phy); |
1527 | if (status != SCI_SUCCESS) | |
1528 | return status; | |
1529 | ||
1530 | scic_sds_port_deactivate_phy(sci_port, sci_phy, true); | |
1531 | sci_port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING; | |
1532 | port_state_machine_change(sci_port, | |
e301370a | 1533 | SCI_PORT_SUB_CONFIGURING); |
bd6713b4 | 1534 | return SCI_SUCCESS; |
e301370a | 1535 | case SCI_PORT_SUB_CONFIGURING: |
bd6713b4 PS |
1536 | status = scic_sds_port_clear_phy(sci_port, sci_phy); |
1537 | ||
1538 | if (status != SCI_SUCCESS) | |
1539 | return status; | |
1540 | scic_sds_port_deactivate_phy(sci_port, sci_phy, true); | |
1541 | ||
1542 | /* Re-enter the configuring state since this may be the last phy in | |
1543 | * the port | |
1544 | */ | |
1545 | port_state_machine_change(sci_port, | |
e301370a | 1546 | SCI_PORT_SUB_CONFIGURING); |
051266ca PS |
1547 | return SCI_SUCCESS; |
1548 | default: | |
1549 | dev_warn(sciport_to_dev(sci_port), | |
1550 | "%s: in wrong state: %d\n", __func__, state); | |
1551 | return SCI_FAILURE_INVALID_STATE; | |
1552 | } | |
1553 | } | |
bd6713b4 | 1554 | |
051266ca PS |
1555 | enum sci_status scic_sds_port_link_up(struct scic_sds_port *sci_port, |
1556 | struct scic_sds_phy *sci_phy) | |
1557 | { | |
1558 | enum scic_sds_port_states state; | |
1559 | ||
e301370a | 1560 | state = sci_port->sm.current_state_id; |
051266ca | 1561 | switch (state) { |
e301370a | 1562 | case SCI_PORT_SUB_WAITING: |
051266ca PS |
1563 | /* Since this is the first phy going link up for the port we |
1564 | * can just enable it and continue | |
1565 | */ | |
1566 | scic_sds_port_activate_phy(sci_port, sci_phy, true); | |
1567 | ||
1568 | port_state_machine_change(sci_port, | |
e301370a | 1569 | SCI_PORT_SUB_OPERATIONAL); |
051266ca | 1570 | return SCI_SUCCESS; |
e301370a | 1571 | case SCI_PORT_SUB_OPERATIONAL: |
051266ca PS |
1572 | scic_sds_port_general_link_up_handler(sci_port, sci_phy, true); |
1573 | return SCI_SUCCESS; | |
e301370a | 1574 | case SCI_PORT_RESETTING: |
051266ca PS |
1575 | /* TODO We should make sure that the phy that has gone |
1576 | * link up is the same one on which we sent the reset. It is | |
1577 | * possible that the phy on which we sent the reset is not the | |
1578 | * one that has gone link up and we want to make sure that | |
1579 | * phy being reset comes back. Consider the case where a | |
1580 | * reset is sent but before the hardware processes the reset it | |
1581 | * get a link up on the port because of a hot plug event. | |
1582 | * because of the reset request this phy will go link down | |
1583 | * almost immediately. | |
1584 | */ | |
1585 | ||
1586 | /* In the resetting state we don't notify the user regarding | |
1587 | * link up and link down notifications. | |
1588 | */ | |
1589 | scic_sds_port_general_link_up_handler(sci_port, sci_phy, false); | |
1590 | return SCI_SUCCESS; | |
1591 | default: | |
1592 | dev_warn(sciport_to_dev(sci_port), | |
1593 | "%s: in wrong state: %d\n", __func__, state); | |
1594 | return SCI_FAILURE_INVALID_STATE; | |
1595 | } | |
1596 | } | |
1597 | ||
1598 | enum sci_status scic_sds_port_link_down(struct scic_sds_port *sci_port, | |
1599 | struct scic_sds_phy *sci_phy) | |
1600 | { | |
1601 | enum scic_sds_port_states state; | |
1602 | ||
e301370a | 1603 | state = sci_port->sm.current_state_id; |
051266ca | 1604 | switch (state) { |
e301370a | 1605 | case SCI_PORT_SUB_OPERATIONAL: |
051266ca PS |
1606 | scic_sds_port_deactivate_phy(sci_port, sci_phy, true); |
1607 | ||
1608 | /* If there are no active phys left in the port, then | |
1609 | * transition the port to the WAITING state until such time | |
1610 | * as a phy goes link up | |
1611 | */ | |
1612 | if (sci_port->active_phy_mask == 0) | |
1613 | port_state_machine_change(sci_port, | |
e301370a | 1614 | SCI_PORT_SUB_WAITING); |
051266ca | 1615 | return SCI_SUCCESS; |
e301370a | 1616 | case SCI_PORT_RESETTING: |
051266ca PS |
1617 | /* In the resetting state we don't notify the user regarding |
1618 | * link up and link down notifications. */ | |
1619 | scic_sds_port_deactivate_phy(sci_port, sci_phy, false); | |
bd6713b4 PS |
1620 | return SCI_SUCCESS; |
1621 | default: | |
1622 | dev_warn(sciport_to_dev(sci_port), | |
1623 | "%s: in wrong state: %d\n", __func__, state); | |
1624 | return SCI_FAILURE_INVALID_STATE; | |
1625 | } | |
1626 | } | |
1627 | ||
6813820c DW |
1628 | enum sci_status scic_sds_port_start_io(struct scic_sds_port *sci_port, |
1629 | struct scic_sds_remote_device *sci_dev, | |
1630 | struct scic_sds_request *sci_req) | |
1631 | { | |
1632 | enum scic_sds_port_states state; | |
1633 | ||
e301370a | 1634 | state = sci_port->sm.current_state_id; |
6813820c | 1635 | switch (state) { |
e301370a | 1636 | case SCI_PORT_SUB_WAITING: |
6813820c | 1637 | return SCI_FAILURE_INVALID_STATE; |
e301370a | 1638 | case SCI_PORT_SUB_OPERATIONAL: |
6813820c DW |
1639 | sci_port->started_request_count++; |
1640 | return SCI_SUCCESS; | |
1641 | default: | |
1642 | dev_warn(sciport_to_dev(sci_port), | |
1643 | "%s: in wrong state: %d\n", __func__, state); | |
1644 | return SCI_FAILURE_INVALID_STATE; | |
e2f8db50 | 1645 | } |
6813820c | 1646 | } |
e2f8db50 | 1647 | |
6813820c DW |
1648 | enum sci_status scic_sds_port_complete_io(struct scic_sds_port *sci_port, |
1649 | struct scic_sds_remote_device *sci_dev, | |
1650 | struct scic_sds_request *sci_req) | |
1651 | { | |
1652 | enum scic_sds_port_states state; | |
1653 | ||
e301370a | 1654 | state = sci_port->sm.current_state_id; |
6813820c | 1655 | switch (state) { |
e301370a | 1656 | case SCI_PORT_STOPPED: |
6813820c DW |
1657 | dev_warn(sciport_to_dev(sci_port), |
1658 | "%s: in wrong state: %d\n", __func__, state); | |
1659 | return SCI_FAILURE_INVALID_STATE; | |
e301370a | 1660 | case SCI_PORT_STOPPING: |
6813820c DW |
1661 | scic_sds_port_decrement_request_count(sci_port); |
1662 | ||
1663 | if (sci_port->started_request_count == 0) | |
1664 | port_state_machine_change(sci_port, | |
e301370a | 1665 | SCI_PORT_STOPPED); |
6813820c | 1666 | break; |
e301370a EN |
1667 | case SCI_PORT_READY: |
1668 | case SCI_PORT_RESETTING: | |
1669 | case SCI_PORT_FAILED: | |
1670 | case SCI_PORT_SUB_WAITING: | |
1671 | case SCI_PORT_SUB_OPERATIONAL: | |
6813820c DW |
1672 | scic_sds_port_decrement_request_count(sci_port); |
1673 | break; | |
e301370a | 1674 | case SCI_PORT_SUB_CONFIGURING: |
6813820c DW |
1675 | scic_sds_port_decrement_request_count(sci_port); |
1676 | if (sci_port->started_request_count == 0) { | |
1677 | port_state_machine_change(sci_port, | |
e301370a | 1678 | SCI_PORT_SUB_OPERATIONAL); |
6813820c DW |
1679 | } |
1680 | break; | |
1681 | } | |
1682 | return SCI_SUCCESS; | |
1683 | } | |
e2f8db50 DW |
1684 | |
1685 | /** | |
1686 | * | |
1687 | * @sci_port: This is the port object which to suspend. | |
1688 | * | |
1689 | * This method will enable the SCU Port Task Scheduler for this port object but | |
1690 | * will leave the port task scheduler in a suspended state. none | |
1691 | */ | |
1692 | static void | |
1693 | scic_sds_port_enable_port_task_scheduler(struct scic_sds_port *port) | |
1694 | { | |
1695 | u32 pts_control_value; | |
1696 | ||
1697 | pts_control_value = readl(&port->port_task_scheduler_registers->control); | |
1698 | pts_control_value |= SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND); | |
1699 | writel(pts_control_value, &port->port_task_scheduler_registers->control); | |
1700 | } | |
1701 | ||
1702 | /** | |
1703 | * | |
1704 | * @sci_port: This is the port object which to resume. | |
1705 | * | |
1706 | * This method will disable the SCU port task scheduler for this port object. | |
1707 | * none | |
1708 | */ | |
1709 | static void | |
1710 | scic_sds_port_disable_port_task_scheduler(struct scic_sds_port *port) | |
1711 | { | |
1712 | u32 pts_control_value; | |
1713 | ||
1714 | pts_control_value = readl(&port->port_task_scheduler_registers->control); | |
1715 | pts_control_value &= | |
1716 | ~(SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND)); | |
1717 | writel(pts_control_value, &port->port_task_scheduler_registers->control); | |
1718 | } | |
1719 | ||
1720 | static void scic_sds_port_post_dummy_remote_node(struct scic_sds_port *sci_port) | |
1721 | { | |
1722 | struct scic_sds_controller *scic = sci_port->owning_controller; | |
1723 | u8 phys_index = sci_port->physical_port_index; | |
1724 | union scu_remote_node_context *rnc; | |
1725 | u16 rni = sci_port->reserved_rni; | |
1726 | u32 command; | |
1727 | ||
1728 | rnc = &scic->remote_node_context_table[rni]; | |
1729 | rnc->ssp.is_valid = true; | |
1730 | ||
1731 | command = SCU_CONTEXT_COMMAND_POST_RNC_32 | | |
1732 | phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni; | |
1733 | ||
1734 | scic_sds_controller_post_request(scic, command); | |
1735 | ||
1736 | /* ensure hardware has seen the post rnc command and give it | |
1737 | * ample time to act before sending the suspend | |
1738 | */ | |
1739 | readl(&scic->smu_registers->interrupt_status); /* flush */ | |
1740 | udelay(10); | |
1741 | ||
1742 | command = SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX | | |
1743 | phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni; | |
1744 | ||
1745 | scic_sds_controller_post_request(scic, command); | |
1746 | } | |
1747 | ||
9269e0e8 | 1748 | static void scic_sds_port_stopped_state_enter(struct sci_base_state_machine *sm) |
e2f8db50 | 1749 | { |
e301370a | 1750 | struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), sm); |
e2f8db50 | 1751 | |
e301370a | 1752 | if (sci_port->sm.previous_state_id == SCI_PORT_STOPPING) { |
e2f8db50 DW |
1753 | /* |
1754 | * If we enter this state becasuse of a request to stop | |
1755 | * the port then we want to disable the hardwares port | |
1756 | * task scheduler. */ | |
1757 | scic_sds_port_disable_port_task_scheduler(sci_port); | |
1758 | } | |
1759 | } | |
1760 | ||
9269e0e8 | 1761 | static void scic_sds_port_stopped_state_exit(struct sci_base_state_machine *sm) |
e2f8db50 | 1762 | { |
e301370a | 1763 | struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), sm); |
e2f8db50 DW |
1764 | |
1765 | /* Enable and suspend the port task scheduler */ | |
1766 | scic_sds_port_enable_port_task_scheduler(sci_port); | |
1767 | } | |
1768 | ||
9269e0e8 | 1769 | static void scic_sds_port_ready_state_enter(struct sci_base_state_machine *sm) |
e2f8db50 | 1770 | { |
e301370a | 1771 | struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), sm); |
e2f8db50 DW |
1772 | struct scic_sds_controller *scic = sci_port->owning_controller; |
1773 | struct isci_host *ihost = scic_to_ihost(scic); | |
1774 | struct isci_port *iport = sci_port_to_iport(sci_port); | |
1775 | u32 prev_state; | |
1776 | ||
e301370a EN |
1777 | prev_state = sci_port->sm.previous_state_id; |
1778 | if (prev_state == SCI_PORT_RESETTING) | |
e2f8db50 DW |
1779 | isci_port_hard_reset_complete(iport, SCI_SUCCESS); |
1780 | else | |
1781 | isci_port_not_ready(ihost, iport); | |
1782 | ||
1783 | /* Post and suspend the dummy remote node context for this port. */ | |
1784 | scic_sds_port_post_dummy_remote_node(sci_port); | |
1785 | ||
1786 | /* Start the ready substate machine */ | |
e91f41ef | 1787 | port_state_machine_change(sci_port, |
e301370a | 1788 | SCI_PORT_SUB_WAITING); |
e2f8db50 DW |
1789 | } |
1790 | ||
9269e0e8 | 1791 | static void scic_sds_port_resetting_state_exit(struct sci_base_state_machine *sm) |
e2f8db50 | 1792 | { |
e301370a | 1793 | struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), sm); |
e2f8db50 | 1794 | |
5553ba2b | 1795 | sci_del_timer(&sci_port->timer); |
e2f8db50 DW |
1796 | } |
1797 | ||
9269e0e8 | 1798 | static void scic_sds_port_stopping_state_exit(struct sci_base_state_machine *sm) |
e2f8db50 | 1799 | { |
e301370a | 1800 | struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), sm); |
e2f8db50 | 1801 | |
5553ba2b | 1802 | sci_del_timer(&sci_port->timer); |
e2f8db50 DW |
1803 | |
1804 | scic_sds_port_destroy_dummy_resources(sci_port); | |
1805 | } | |
1806 | ||
9269e0e8 | 1807 | static void scic_sds_port_failed_state_enter(struct sci_base_state_machine *sm) |
e2f8db50 | 1808 | { |
e301370a | 1809 | struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), sm); |
e2f8db50 DW |
1810 | struct isci_port *iport = sci_port_to_iport(sci_port); |
1811 | ||
e2f8db50 DW |
1812 | isci_port_hard_reset_complete(iport, SCI_FAILURE_TIMEOUT); |
1813 | } | |
1814 | ||
1815 | /* --------------------------------------------------------------------------- */ | |
1816 | ||
1817 | static const struct sci_base_state scic_sds_port_state_table[] = { | |
e301370a | 1818 | [SCI_PORT_STOPPED] = { |
e2f8db50 DW |
1819 | .enter_state = scic_sds_port_stopped_state_enter, |
1820 | .exit_state = scic_sds_port_stopped_state_exit | |
1821 | }, | |
e301370a | 1822 | [SCI_PORT_STOPPING] = { |
e2f8db50 DW |
1823 | .exit_state = scic_sds_port_stopping_state_exit |
1824 | }, | |
e301370a | 1825 | [SCI_PORT_READY] = { |
e2f8db50 | 1826 | .enter_state = scic_sds_port_ready_state_enter, |
e91f41ef | 1827 | }, |
e301370a | 1828 | [SCI_PORT_SUB_WAITING] = { |
e91f41ef PS |
1829 | .enter_state = scic_sds_port_ready_substate_waiting_enter, |
1830 | }, | |
e301370a | 1831 | [SCI_PORT_SUB_OPERATIONAL] = { |
e91f41ef PS |
1832 | .enter_state = scic_sds_port_ready_substate_operational_enter, |
1833 | .exit_state = scic_sds_port_ready_substate_operational_exit | |
1834 | }, | |
e301370a | 1835 | [SCI_PORT_SUB_CONFIGURING] = { |
e91f41ef PS |
1836 | .enter_state = scic_sds_port_ready_substate_configuring_enter, |
1837 | .exit_state = scic_sds_port_ready_substate_configuring_exit | |
e2f8db50 | 1838 | }, |
e301370a | 1839 | [SCI_PORT_RESETTING] = { |
e2f8db50 DW |
1840 | .exit_state = scic_sds_port_resetting_state_exit |
1841 | }, | |
e301370a | 1842 | [SCI_PORT_FAILED] = { |
e2f8db50 DW |
1843 | .enter_state = scic_sds_port_failed_state_enter, |
1844 | } | |
1845 | }; | |
1846 | ||
1847 | void scic_sds_port_construct(struct scic_sds_port *sci_port, u8 index, | |
1848 | struct scic_sds_controller *scic) | |
1849 | { | |
12ef6544 | 1850 | sci_init_sm(&sci_port->sm, scic_sds_port_state_table, SCI_PORT_STOPPED); |
e2f8db50 | 1851 | |
e2f8db50 DW |
1852 | sci_port->logical_port_index = SCIC_SDS_DUMMY_PORT; |
1853 | sci_port->physical_port_index = index; | |
1854 | sci_port->active_phy_mask = 0; | |
e91f41ef | 1855 | sci_port->ready_exit = false; |
e2f8db50 DW |
1856 | |
1857 | sci_port->owning_controller = scic; | |
1858 | ||
1859 | sci_port->started_request_count = 0; | |
1860 | sci_port->assigned_device_count = 0; | |
1861 | ||
1862 | sci_port->reserved_rni = SCU_DUMMY_INDEX; | |
1863 | sci_port->reserved_tci = SCU_DUMMY_INDEX; | |
1864 | ||
5553ba2b EN |
1865 | sci_init_timer(&sci_port->timer, port_timeout); |
1866 | ||
e2f8db50 DW |
1867 | sci_port->port_task_scheduler_registers = NULL; |
1868 | ||
1869 | for (index = 0; index < SCI_MAX_PHYS; index++) | |
1870 | sci_port->phy_table[index] = NULL; | |
1871 | } | |
1872 | ||
1873 | void isci_port_init(struct isci_port *iport, struct isci_host *ihost, int index) | |
1874 | { | |
1875 | INIT_LIST_HEAD(&iport->remote_dev_list); | |
1876 | INIT_LIST_HEAD(&iport->domain_dev_list); | |
1877 | spin_lock_init(&iport->state_lock); | |
1878 | init_completion(&iport->start_complete); | |
1879 | iport->isci_host = ihost; | |
1880 | isci_port_change_state(iport, isci_freed); | |
61aaff49 | 1881 | atomic_set(&iport->event, 0); |
e2f8db50 DW |
1882 | } |
1883 | ||
1884 | /** | |
1885 | * isci_port_get_state() - This function gets the status of the port object. | |
1886 | * @isci_port: This parameter points to the isci_port object | |
1887 | * | |
1888 | * status of the object as a isci_status enum. | |
1889 | */ | |
1890 | enum isci_status isci_port_get_state( | |
1891 | struct isci_port *isci_port) | |
1892 | { | |
1893 | return isci_port->status; | |
1894 | } | |
1895 | ||
e2f8db50 DW |
1896 | void scic_sds_port_broadcast_change_received( |
1897 | struct scic_sds_port *sci_port, | |
1898 | struct scic_sds_phy *sci_phy) | |
1899 | { | |
1900 | struct scic_sds_controller *scic = sci_port->owning_controller; | |
1901 | struct isci_host *ihost = scic_to_ihost(scic); | |
1902 | ||
1903 | /* notify the user. */ | |
1904 | isci_port_bc_change_received(ihost, sci_port, sci_phy); | |
1905 | } | |
1906 | ||
1907 | int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *iport, | |
1908 | struct isci_phy *iphy) | |
1909 | { | |
1910 | unsigned long flags; | |
1911 | enum sci_status status; | |
fd0527ab | 1912 | int idx, ret = TMF_RESP_FUNC_COMPLETE; |
e2f8db50 DW |
1913 | |
1914 | dev_dbg(&ihost->pdev->dev, "%s: iport = %p\n", | |
1915 | __func__, iport); | |
1916 | ||
1917 | init_completion(&iport->hard_reset_complete); | |
1918 | ||
1919 | spin_lock_irqsave(&ihost->scic_lock, flags); | |
1920 | ||
1921 | #define ISCI_PORT_RESET_TIMEOUT SCIC_SDS_SIGNATURE_FIS_TIMEOUT | |
1922 | status = scic_port_hard_reset(&iport->sci, ISCI_PORT_RESET_TIMEOUT); | |
1923 | ||
1924 | spin_unlock_irqrestore(&ihost->scic_lock, flags); | |
1925 | ||
1926 | if (status == SCI_SUCCESS) { | |
1927 | wait_for_completion(&iport->hard_reset_complete); | |
1928 | ||
1929 | dev_dbg(&ihost->pdev->dev, | |
1930 | "%s: iport = %p; hard reset completion\n", | |
1931 | __func__, iport); | |
1932 | ||
1933 | if (iport->hard_reset_status != SCI_SUCCESS) | |
1934 | ret = TMF_RESP_FUNC_FAILED; | |
1935 | } else { | |
1936 | ret = TMF_RESP_FUNC_FAILED; | |
1937 | ||
1938 | dev_err(&ihost->pdev->dev, | |
1939 | "%s: iport = %p; scic_port_hard_reset call" | |
1940 | " failed 0x%x\n", | |
1941 | __func__, iport, status); | |
1942 | ||
1943 | } | |
1944 | ||
1945 | /* If the hard reset for the port has failed, consider this | |
1946 | * the same as link failures on all phys in the port. | |
1947 | */ | |
1948 | if (ret != TMF_RESP_FUNC_COMPLETE) { | |
fd0527ab | 1949 | |
e2f8db50 DW |
1950 | dev_err(&ihost->pdev->dev, |
1951 | "%s: iport = %p; hard reset failed " | |
fd0527ab JS |
1952 | "(0x%x) - driving explicit link fail for all phys\n", |
1953 | __func__, iport, iport->hard_reset_status); | |
e2f8db50 | 1954 | |
fd0527ab JS |
1955 | /* Down all phys in the port. */ |
1956 | spin_lock_irqsave(&ihost->scic_lock, flags); | |
1957 | for (idx = 0; idx < SCI_MAX_PHYS; ++idx) { | |
1958 | ||
1959 | if (iport->sci.phy_table[idx] != NULL) { | |
e2f8db50 | 1960 | |
fd0527ab JS |
1961 | scic_sds_phy_stop( |
1962 | iport->sci.phy_table[idx]); | |
1963 | scic_sds_phy_start( | |
1964 | iport->sci.phy_table[idx]); | |
1965 | } | |
1966 | } | |
1967 | spin_unlock_irqrestore(&ihost->scic_lock, flags); | |
1968 | } | |
e2f8db50 DW |
1969 | return ret; |
1970 | } | |
1971 | ||
1972 | /** | |
1973 | * isci_port_deformed() - This function is called by libsas when a port becomes | |
1974 | * inactive. | |
1975 | * @phy: This parameter specifies the libsas phy with the inactive port. | |
1976 | * | |
1977 | */ | |
1978 | void isci_port_deformed(struct asd_sas_phy *phy) | |
1979 | { | |
1980 | pr_debug("%s: sas_phy = %p\n", __func__, phy); | |
1981 | } | |
1982 | ||
1983 | /** | |
1984 | * isci_port_formed() - This function is called by libsas when a port becomes | |
1985 | * active. | |
1986 | * @phy: This parameter specifies the libsas phy with the active port. | |
1987 | * | |
1988 | */ | |
1989 | void isci_port_formed(struct asd_sas_phy *phy) | |
1990 | { | |
1991 | pr_debug("%s: sas_phy = %p, sas_port = %p\n", __func__, phy, phy->port); | |
09d7da13 | 1992 | } |