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.
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
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.
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.
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.
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
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
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.
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.
60 #define SCIC_SDS_PORT_HARD_RESET_TIMEOUT (1000)
61 #define SCU_DUMMY_INDEX (0xFFFF)
63 static void isci_port_change_state(struct isci_port
*iport
, enum isci_status status
)
67 dev_dbg(&iport
->isci_host
->pdev
->dev
,
68 "%s: iport = %p, state = 0x%x\n",
69 __func__
, iport
, status
);
71 /* XXX pointless lock */
72 spin_lock_irqsave(&iport
->state_lock
, flags
);
73 iport
->status
= status
;
74 spin_unlock_irqrestore(&iport
->state_lock
, flags
);
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.
86 scic_sds_port_get_protocols(struct scic_sds_port
*sci_port
,
87 struct scic_phy_proto
*protocols
)
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
],
102 * This method requests a list (mask) of the phys contained in the supplied SAS
104 * @sci_port: a handle corresponding to the SAS port for which to return the
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).
110 static u32
scic_sds_port_get_phys(struct scic_sds_port
*sci_port
)
117 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
118 if (sci_port
->phy_table
[index
] != NULL
) {
119 mask
|= (1 << index
);
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
131 * @properties: This parameter specifies the properties structure into which to
132 * copy the requested information.
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.
139 static enum sci_status
scic_port_get_properties(struct scic_sds_port
*port
,
140 struct scic_port_properties
*prop
)
142 if ((port
== NULL
) ||
143 (port
->logical_port_index
== SCIC_SDS_DUMMY_PORT
))
144 return SCI_FAILURE_INVALID_PORT
;
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
);
155 static void scic_port_bcn_enable(struct scic_sds_port
*sci_port
)
157 struct isci_phy
*iphy
;
161 for (i
= 0; i
< ARRAY_SIZE(sci_port
->phy_table
); i
++) {
162 iphy
= sci_port
->phy_table
[i
];
165 val
= readl(&iphy
->link_layer_registers
->link_layer_control
);
166 /* clear the bit by writing 1. */
167 writel(val
, &iphy
->link_layer_registers
->link_layer_control
);
171 /* called under scic_lock to stabilize phy:port associations */
172 void isci_port_bcn_enable(struct isci_host
*ihost
, struct isci_port
*iport
)
176 clear_bit(IPORT_BCN_BLOCKED
, &iport
->flags
);
177 wake_up(&ihost
->eventq
);
179 if (!test_and_clear_bit(IPORT_BCN_PENDING
, &iport
->flags
))
182 for (i
= 0; i
< ARRAY_SIZE(iport
->sci
.phy_table
); i
++) {
183 struct isci_phy
*iphy
= iport
->sci
.phy_table
[i
];
188 ihost
->sas_ha
.notify_port_event(&iphy
->sas_phy
,
189 PORTE_BROADCAST_RCVD
);
194 void isci_port_bc_change_received(struct isci_host
*ihost
,
195 struct scic_sds_port
*sci_port
,
196 struct isci_phy
*iphy
)
198 struct isci_port
*iport
= iphy
->isci_port
;
200 if (iport
&& test_bit(IPORT_BCN_BLOCKED
, &iport
->flags
)) {
201 dev_dbg(&ihost
->pdev
->dev
,
202 "%s: disabled BCN; isci_phy = %p, sas_phy = %p\n",
203 __func__
, iphy
, &iphy
->sas_phy
);
204 set_bit(IPORT_BCN_PENDING
, &iport
->flags
);
205 atomic_inc(&iport
->event
);
206 wake_up(&ihost
->eventq
);
208 dev_dbg(&ihost
->pdev
->dev
,
209 "%s: isci_phy = %p, sas_phy = %p\n",
210 __func__
, iphy
, &iphy
->sas_phy
);
212 ihost
->sas_ha
.notify_port_event(&iphy
->sas_phy
,
213 PORTE_BROADCAST_RCVD
);
215 scic_port_bcn_enable(sci_port
);
218 static void isci_port_link_up(struct isci_host
*isci_host
,
219 struct scic_sds_port
*port
,
220 struct isci_phy
*iphy
)
223 struct scic_port_properties properties
;
224 struct isci_port
*isci_port
= sci_port_to_iport(port
);
225 unsigned long success
= true;
227 BUG_ON(iphy
->isci_port
!= NULL
);
229 iphy
->isci_port
= isci_port
;
231 dev_dbg(&isci_host
->pdev
->dev
,
232 "%s: isci_port = %p\n",
233 __func__
, isci_port
);
235 spin_lock_irqsave(&iphy
->sas_phy
.frame_rcvd_lock
, flags
);
237 isci_port_change_state(iphy
->isci_port
, isci_starting
);
239 scic_port_get_properties(port
, &properties
);
241 if (iphy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SATA
) {
242 u64 attached_sas_address
;
244 iphy
->sas_phy
.oob_mode
= SATA_OOB_MODE
;
245 iphy
->sas_phy
.frame_rcvd_size
= sizeof(struct dev_to_host_fis
);
248 * For direct-attached SATA devices, the SCI core will
249 * automagically assign a SAS address to the end device
250 * for the purpose of creating a port. This SAS address
251 * will not be the same as assigned to the PHY and needs
252 * to be obtained from struct scic_port_properties properties.
254 attached_sas_address
= properties
.remote
.sas_address
.high
;
255 attached_sas_address
<<= 32;
256 attached_sas_address
|= properties
.remote
.sas_address
.low
;
257 swab64s(&attached_sas_address
);
259 memcpy(&iphy
->sas_phy
.attached_sas_addr
,
260 &attached_sas_address
, sizeof(attached_sas_address
));
261 } else if (iphy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SAS
) {
262 iphy
->sas_phy
.oob_mode
= SAS_OOB_MODE
;
263 iphy
->sas_phy
.frame_rcvd_size
= sizeof(struct sas_identify_frame
);
265 /* Copy the attached SAS address from the IAF */
266 memcpy(iphy
->sas_phy
.attached_sas_addr
,
267 iphy
->frame_rcvd
.iaf
.sas_addr
, SAS_ADDR_SIZE
);
269 dev_err(&isci_host
->pdev
->dev
, "%s: unkown target\n", __func__
);
273 iphy
->sas_phy
.phy
->negotiated_linkrate
= sci_phy_linkrate(iphy
);
275 spin_unlock_irqrestore(&iphy
->sas_phy
.frame_rcvd_lock
, flags
);
277 /* Notify libsas that we have an address frame, if indeed
278 * we've found an SSP, SMP, or STP target */
280 isci_host
->sas_ha
.notify_port_event(&iphy
->sas_phy
,
286 * isci_port_link_down() - This function is called by the sci core when a link
288 * @isci_host: This parameter specifies the isci host object.
289 * @phy: This parameter specifies the isci phy with the active link.
290 * @port: This parameter specifies the isci port with the active link.
293 static void isci_port_link_down(struct isci_host
*isci_host
,
294 struct isci_phy
*isci_phy
,
295 struct isci_port
*isci_port
)
297 struct isci_remote_device
*isci_device
;
299 dev_dbg(&isci_host
->pdev
->dev
,
300 "%s: isci_port = %p\n", __func__
, isci_port
);
304 /* check to see if this is the last phy on this port. */
305 if (isci_phy
->sas_phy
.port
&&
306 isci_phy
->sas_phy
.port
->num_phys
== 1) {
307 atomic_inc(&isci_port
->event
);
308 isci_port_bcn_enable(isci_host
, isci_port
);
310 /* change the state for all devices on this port. The
311 * next task sent to this device will be returned as
312 * SAS_TASK_UNDELIVERED, and the scsi mid layer will
315 list_for_each_entry(isci_device
,
316 &isci_port
->remote_dev_list
,
318 dev_dbg(&isci_host
->pdev
->dev
,
319 "%s: isci_device = %p\n",
320 __func__
, isci_device
);
321 set_bit(IDEV_GONE
, &isci_device
->flags
);
324 isci_port_change_state(isci_port
, isci_stopping
);
327 /* Notify libsas of the borken link, this will trigger calls to our
328 * isci_port_deformed and isci_dev_gone functions.
330 sas_phy_disconnected(&isci_phy
->sas_phy
);
331 isci_host
->sas_ha
.notify_phy_event(&isci_phy
->sas_phy
,
332 PHYE_LOSS_OF_SIGNAL
);
334 isci_phy
->isci_port
= NULL
;
336 dev_dbg(&isci_host
->pdev
->dev
,
337 "%s: isci_port = %p - Done\n", __func__
, isci_port
);
342 * isci_port_ready() - This function is called by the sci core when a link
344 * @isci_host: This parameter specifies the isci host object.
345 * @port: This parameter specifies the sci port with the active link.
348 static void isci_port_ready(struct isci_host
*isci_host
, struct isci_port
*isci_port
)
350 dev_dbg(&isci_host
->pdev
->dev
,
351 "%s: isci_port = %p\n", __func__
, isci_port
);
353 complete_all(&isci_port
->start_complete
);
354 isci_port_change_state(isci_port
, isci_ready
);
359 * isci_port_not_ready() - This function is called by the sci core when a link
360 * is not ready. All remote devices on this link will be removed if they are
361 * in the stopping state.
362 * @isci_host: This parameter specifies the isci host object.
363 * @port: This parameter specifies the sci port with the active link.
366 static void isci_port_not_ready(struct isci_host
*isci_host
, struct isci_port
*isci_port
)
368 dev_dbg(&isci_host
->pdev
->dev
,
369 "%s: isci_port = %p\n", __func__
, isci_port
);
372 static void isci_port_stop_complete(struct scic_sds_controller
*scic
,
373 struct scic_sds_port
*sci_port
,
374 enum sci_status completion_status
)
376 dev_dbg(&scic_to_ihost(scic
)->pdev
->dev
, "Port stop complete\n");
380 * isci_port_hard_reset_complete() - This function is called by the sci core
381 * when the hard reset complete notification has been received.
382 * @port: This parameter specifies the sci port with the active link.
383 * @completion_status: This parameter specifies the core status for the reset
387 static void isci_port_hard_reset_complete(struct isci_port
*isci_port
,
388 enum sci_status completion_status
)
390 dev_dbg(&isci_port
->isci_host
->pdev
->dev
,
391 "%s: isci_port = %p, completion_status=%x\n",
392 __func__
, isci_port
, completion_status
);
394 /* Save the status of the hard reset from the port. */
395 isci_port
->hard_reset_status
= completion_status
;
397 complete_all(&isci_port
->hard_reset_complete
);
400 /* This method will return a true value if the specified phy can be assigned to
401 * this port The following is a list of phys for each port that are allowed: -
402 * Port 0 - 3 2 1 0 - Port 1 - 1 - Port 2 - 3 2 - Port 3 - 3 This method
403 * doesn't preclude all configurations. It merely ensures that a phy is part
404 * of the allowable set of phy identifiers for that port. For example, one
405 * could assign phy 3 to port 0 and no other phys. Please refer to
406 * scic_sds_port_is_phy_mask_valid() for information regarding whether the
407 * phy_mask for a port can be supported. bool true if this is a valid phy
408 * assignment for the port false if this is not a valid phy assignment for the
411 bool scic_sds_port_is_valid_phy_assignment(struct scic_sds_port
*sci_port
,
414 /* Initialize to invalid value. */
415 u32 existing_phy_index
= SCI_MAX_PHYS
;
418 if ((sci_port
->physical_port_index
== 1) && (phy_index
!= 1)) {
422 if (sci_port
->physical_port_index
== 3 && phy_index
!= 3) {
427 (sci_port
->physical_port_index
== 2)
428 && ((phy_index
== 0) || (phy_index
== 1))
433 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
434 if ((sci_port
->phy_table
[index
] != NULL
)
435 && (index
!= phy_index
)) {
436 existing_phy_index
= index
;
441 * Ensure that all of the phys in the port are capable of
442 * operating at the same maximum link rate. */
444 (existing_phy_index
< SCI_MAX_PHYS
)
445 && (sci_port
->owning_controller
->user_parameters
.sds1
.phys
[
446 phy_index
].max_speed_generation
!=
447 sci_port
->owning_controller
->user_parameters
.sds1
.phys
[
448 existing_phy_index
].max_speed_generation
)
457 * @sci_port: This is the port object for which to determine if the phy mask
460 * This method will return a true value if the port's phy mask can be supported
461 * by the SCU. The following is a list of valid PHY mask configurations for
462 * each port: - Port 0 - [[3 2] 1] 0 - Port 1 - [1] - Port 2 - [[3] 2]
463 * - Port 3 - [3] This method returns a boolean indication specifying if the
464 * phy mask can be supported. true if this is a valid phy assignment for the
465 * port false if this is not a valid phy assignment for the port
467 static bool scic_sds_port_is_phy_mask_valid(
468 struct scic_sds_port
*sci_port
,
471 if (sci_port
->physical_port_index
== 0) {
472 if (((phy_mask
& 0x0F) == 0x0F)
473 || ((phy_mask
& 0x03) == 0x03)
474 || ((phy_mask
& 0x01) == 0x01)
477 } else if (sci_port
->physical_port_index
== 1) {
478 if (((phy_mask
& 0x02) == 0x02)
481 } else if (sci_port
->physical_port_index
== 2) {
482 if (((phy_mask
& 0x0C) == 0x0C)
483 || ((phy_mask
& 0x04) == 0x04)
486 } else if (sci_port
->physical_port_index
== 3) {
487 if (((phy_mask
& 0x08) == 0x08)
496 * This method retrieves a currently active (i.e. connected) phy contained in
497 * the port. Currently, the lowest order phy that is connected is returned.
498 * This method returns a pointer to a SCIS_SDS_PHY object. NULL This value is
499 * returned if there are no currently active (i.e. connected to a remote end
500 * point) phys contained in the port. All other values specify a struct scic_sds_phy
501 * object that is active in the port.
503 static struct isci_phy
*scic_sds_port_get_a_connected_phy(struct scic_sds_port
*sci_port
)
506 struct isci_phy
*iphy
;
508 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
509 /* Ensure that the phy is both part of the port and currently
510 * connected to the remote end-point.
512 iphy
= sci_port
->phy_table
[index
];
513 if (iphy
&& scic_sds_port_active_phy(sci_port
, iphy
))
520 static enum sci_status
scic_sds_port_set_phy(struct scic_sds_port
*port
, struct isci_phy
*iphy
)
522 /* Check to see if we can add this phy to a port
523 * that means that the phy is not part of a port and that the port does
524 * not already have a phy assinged to the phy index.
526 if (!port
->phy_table
[iphy
->phy_index
] &&
527 !phy_get_non_dummy_port(iphy
) &&
528 scic_sds_port_is_valid_phy_assignment(port
, iphy
->phy_index
)) {
529 /* Phy is being added in the stopped state so we are in MPC mode
530 * make logical port index = physical port index
532 port
->logical_port_index
= port
->physical_port_index
;
533 port
->phy_table
[iphy
->phy_index
] = iphy
;
534 scic_sds_phy_set_port(iphy
, port
);
542 static enum sci_status
scic_sds_port_clear_phy(struct scic_sds_port
*port
,
543 struct isci_phy
*iphy
)
545 /* Make sure that this phy is part of this port */
546 if (port
->phy_table
[iphy
->phy_index
] == iphy
&&
547 phy_get_non_dummy_port(iphy
) == port
) {
548 struct scic_sds_controller
*scic
= port
->owning_controller
;
549 struct isci_host
*ihost
= scic_to_ihost(scic
);
551 /* Yep it is assigned to this port so remove it */
552 scic_sds_phy_set_port(iphy
, &ihost
->ports
[SCI_MAX_PORTS
].sci
);
553 port
->phy_table
[iphy
->phy_index
] = NULL
;
562 * This method requests the SAS address for the supplied SAS port from the SCI
564 * @sci_port: a handle corresponding to the SAS port for which to return the
566 * @sas_address: This parameter specifies a pointer to a SAS address structure
567 * into which the core will copy the SAS address for the port.
570 void scic_sds_port_get_sas_address(
571 struct scic_sds_port
*sci_port
,
572 struct sci_sas_address
*sas_address
)
576 sas_address
->high
= 0;
577 sas_address
->low
= 0;
579 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
580 if (sci_port
->phy_table
[index
] != NULL
) {
581 scic_sds_phy_get_sas_address(sci_port
->phy_table
[index
], sas_address
);
587 * This function requests the SAS address for the device directly attached to
589 * @sci_port: a handle corresponding to the SAS port for which to return the
591 * @sas_address: This parameter specifies a pointer to a SAS address structure
592 * into which the core will copy the SAS address for the device directly
593 * attached to the port.
596 void scic_sds_port_get_attached_sas_address(
597 struct scic_sds_port
*sci_port
,
598 struct sci_sas_address
*sas_address
)
600 struct isci_phy
*iphy
;
603 * Ensure that the phy is both part of the port and currently
604 * connected to the remote end-point.
606 iphy
= scic_sds_port_get_a_connected_phy(sci_port
);
608 if (iphy
->protocol
!= SCIC_SDS_PHY_PROTOCOL_SATA
) {
609 scic_sds_phy_get_attached_sas_address(iphy
,
612 scic_sds_phy_get_sas_address(iphy
, sas_address
);
613 sas_address
->low
+= iphy
->phy_index
;
616 sas_address
->high
= 0;
617 sas_address
->low
= 0;
622 * scic_sds_port_construct_dummy_rnc() - create dummy rnc for si workaround
624 * @sci_port: logical port on which we need to create the remote node context
625 * @rni: remote node index for this remote node context.
627 * This routine will construct a dummy remote node context data structure
628 * This structure will be posted to the hardware to work around a scheduler
629 * error in the hardware.
631 static void scic_sds_port_construct_dummy_rnc(struct scic_sds_port
*sci_port
, u16 rni
)
633 union scu_remote_node_context
*rnc
;
635 rnc
= &sci_port
->owning_controller
->remote_node_context_table
[rni
];
637 memset(rnc
, 0, sizeof(union scu_remote_node_context
));
639 rnc
->ssp
.remote_sas_address_hi
= 0;
640 rnc
->ssp
.remote_sas_address_lo
= 0;
642 rnc
->ssp
.remote_node_index
= rni
;
643 rnc
->ssp
.remote_node_port_width
= 1;
644 rnc
->ssp
.logical_port_index
= sci_port
->physical_port_index
;
646 rnc
->ssp
.nexus_loss_timer_enable
= false;
647 rnc
->ssp
.check_bit
= false;
648 rnc
->ssp
.is_valid
= true;
649 rnc
->ssp
.is_remote_node_context
= true;
650 rnc
->ssp
.function_number
= 0;
651 rnc
->ssp
.arbitration_wait_time
= 0;
655 * construct a dummy task context data structure. This
656 * structure will be posted to the hardwre to work around a scheduler error
659 static void scic_sds_port_construct_dummy_task(struct scic_sds_port
*sci_port
, u16 tag
)
661 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
662 struct scu_task_context
*task_context
;
664 task_context
= &scic
->task_context_table
[ISCI_TAG_TCI(tag
)];
665 memset(task_context
, 0, sizeof(struct scu_task_context
));
667 task_context
->initiator_request
= 1;
668 task_context
->connection_rate
= 1;
669 task_context
->logical_port_index
= sci_port
->physical_port_index
;
670 task_context
->protocol_type
= SCU_TASK_CONTEXT_PROTOCOL_SSP
;
671 task_context
->task_index
= ISCI_TAG_TCI(tag
);
672 task_context
->valid
= SCU_TASK_CONTEXT_VALID
;
673 task_context
->context_type
= SCU_TASK_CONTEXT_TYPE
;
674 task_context
->remote_node_index
= sci_port
->reserved_rni
;
675 task_context
->do_not_dma_ssp_good_response
= 1;
676 task_context
->task_phase
= 0x01;
679 static void scic_sds_port_destroy_dummy_resources(struct scic_sds_port
*sci_port
)
681 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
683 if (sci_port
->reserved_tag
!= SCI_CONTROLLER_INVALID_IO_TAG
)
684 isci_free_tag(scic_to_ihost(scic
), sci_port
->reserved_tag
);
686 if (sci_port
->reserved_rni
!= SCU_DUMMY_INDEX
)
687 scic_sds_remote_node_table_release_remote_node_index(&scic
->available_remote_nodes
,
688 1, sci_port
->reserved_rni
);
690 sci_port
->reserved_rni
= SCU_DUMMY_INDEX
;
691 sci_port
->reserved_tag
= SCI_CONTROLLER_INVALID_IO_TAG
;
695 * This method performs initialization of the supplied port. Initialization
696 * includes: - state machine initialization - member variable initialization
697 * - configuring the phy_mask
699 * @transport_layer_registers:
700 * @port_task_scheduler_registers:
701 * @port_configuration_regsiter:
703 * enum sci_status SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION This value is returned
704 * if the phy being added to the port
706 enum sci_status
scic_sds_port_initialize(
707 struct scic_sds_port
*sci_port
,
708 void __iomem
*port_task_scheduler_registers
,
709 void __iomem
*port_configuration_regsiter
,
710 void __iomem
*viit_registers
)
712 sci_port
->port_task_scheduler_registers
= port_task_scheduler_registers
;
713 sci_port
->port_pe_configuration_register
= port_configuration_regsiter
;
714 sci_port
->viit_registers
= viit_registers
;
721 * This method assigns the direct attached device ID for this port.
723 * @param[in] sci_port The port for which the direct attached device id is to
725 * @param[in] device_id The direct attached device ID to assign to the port.
726 * This will be the RNi for the device
728 void scic_sds_port_setup_transports(
729 struct scic_sds_port
*sci_port
,
734 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
735 if (sci_port
->active_phy_mask
& (1 << index
))
736 scic_sds_phy_setup_transport(sci_port
->phy_table
[index
], device_id
);
742 * @sci_port: This is the port on which the phy should be enabled.
743 * @sci_phy: This is the specific phy which to enable.
744 * @do_notify_user: This parameter specifies whether to inform the user (via
745 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
747 * This function will activate the phy in the port.
748 * Activation includes: - adding
749 * the phy to the port - enabling the Protocol Engine in the silicon. -
750 * notifying the user that the link is up. none
752 static void scic_sds_port_activate_phy(struct scic_sds_port
*sci_port
,
753 struct isci_phy
*iphy
,
756 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
757 struct isci_host
*ihost
= scic_to_ihost(scic
);
759 if (iphy
->protocol
!= SCIC_SDS_PHY_PROTOCOL_SATA
)
760 scic_sds_phy_resume(iphy
);
762 sci_port
->active_phy_mask
|= 1 << iphy
->phy_index
;
764 scic_sds_controller_clear_invalid_phy(scic
, iphy
);
766 if (do_notify_user
== true)
767 isci_port_link_up(ihost
, sci_port
, iphy
);
770 void scic_sds_port_deactivate_phy(struct scic_sds_port
*sci_port
,
771 struct isci_phy
*iphy
,
774 struct scic_sds_controller
*scic
= scic_sds_port_get_controller(sci_port
);
775 struct isci_port
*iport
= sci_port_to_iport(sci_port
);
776 struct isci_host
*ihost
= scic_to_ihost(scic
);
778 sci_port
->active_phy_mask
&= ~(1 << iphy
->phy_index
);
780 iphy
->max_negotiated_speed
= SAS_LINK_RATE_UNKNOWN
;
782 /* Re-assign the phy back to the LP as if it were a narrow port */
783 writel(iphy
->phy_index
,
784 &sci_port
->port_pe_configuration_register
[iphy
->phy_index
]);
786 if (do_notify_user
== true)
787 isci_port_link_down(ihost
, iphy
, iport
);
792 * @sci_port: This is the port on which the phy should be disabled.
793 * @sci_phy: This is the specific phy which to disabled.
795 * This function will disable the phy and report that the phy is not valid for
796 * this port object. None
798 static void scic_sds_port_invalid_link_up(struct scic_sds_port
*sci_port
,
799 struct isci_phy
*iphy
)
801 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
804 * Check to see if we have alreay reported this link as bad and if
805 * not go ahead and tell the SCI_USER that we have discovered an
808 if ((scic
->invalid_phy_mask
& (1 << iphy
->phy_index
)) == 0) {
809 scic_sds_controller_set_invalid_phy(scic
, iphy
);
810 dev_warn(&scic_to_ihost(scic
)->pdev
->dev
, "Invalid link up!\n");
814 static bool is_port_ready_state(enum scic_sds_port_states state
)
818 case SCI_PORT_SUB_WAITING
:
819 case SCI_PORT_SUB_OPERATIONAL
:
820 case SCI_PORT_SUB_CONFIGURING
:
827 /* flag dummy rnc hanling when exiting a ready state */
828 static void port_state_machine_change(struct scic_sds_port
*sci_port
,
829 enum scic_sds_port_states state
)
831 struct sci_base_state_machine
*sm
= &sci_port
->sm
;
832 enum scic_sds_port_states old_state
= sm
->current_state_id
;
834 if (is_port_ready_state(old_state
) && !is_port_ready_state(state
))
835 sci_port
->ready_exit
= true;
837 sci_change_state(sm
, state
);
838 sci_port
->ready_exit
= false;
842 * scic_sds_port_general_link_up_handler - phy can be assigned to port?
843 * @sci_port: scic_sds_port object for which has a phy that has gone link up.
844 * @sci_phy: This is the struct isci_phy object that has gone link up.
845 * @do_notify_user: This parameter specifies whether to inform the user (via
846 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
848 * Determine if this phy can be assigned to this
849 * port . If the phy is not a valid PHY for
850 * this port then the function will notify the user. A PHY can only be
851 * part of a port if it's attached SAS ADDRESS is the same as all other PHYs in
852 * the same port. none
854 static void scic_sds_port_general_link_up_handler(struct scic_sds_port
*sci_port
,
855 struct isci_phy
*iphy
,
858 struct sci_sas_address port_sas_address
;
859 struct sci_sas_address phy_sas_address
;
861 scic_sds_port_get_attached_sas_address(sci_port
, &port_sas_address
);
862 scic_sds_phy_get_attached_sas_address(iphy
, &phy_sas_address
);
864 /* If the SAS address of the new phy matches the SAS address of
865 * other phys in the port OR this is the first phy in the port,
866 * then activate the phy and allow it to be used for operations
869 if ((phy_sas_address
.high
== port_sas_address
.high
&&
870 phy_sas_address
.low
== port_sas_address
.low
) ||
871 sci_port
->active_phy_mask
== 0) {
872 struct sci_base_state_machine
*sm
= &sci_port
->sm
;
874 scic_sds_port_activate_phy(sci_port
, iphy
, do_notify_user
);
875 if (sm
->current_state_id
== SCI_PORT_RESETTING
)
876 port_state_machine_change(sci_port
, SCI_PORT_READY
);
878 scic_sds_port_invalid_link_up(sci_port
, iphy
);
884 * This method returns false if the port only has a single phy object assigned.
885 * If there are no phys or more than one phy then the method will return
887 * @sci_port: The port for which the wide port condition is to be checked.
889 * bool true Is returned if this is a wide ported port. false Is returned if
890 * this is a narrow port.
892 static bool scic_sds_port_is_wide(struct scic_sds_port
*sci_port
)
897 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
898 if (sci_port
->phy_table
[index
] != NULL
) {
903 return phy_count
!= 1;
907 * This method is called by the PHY object when the link is detected. if the
908 * port wants the PHY to continue on to the link up state then the port
909 * layer must return true. If the port object returns false the phy object
910 * must halt its attempt to go link up.
911 * @sci_port: The port associated with the phy object.
912 * @sci_phy: The phy object that is trying to go link up.
914 * true if the phy object can continue to the link up condition. true Is
915 * returned if this phy can continue to the ready state. false Is returned if
916 * can not continue on to the ready state. This notification is in place for
917 * wide ports and direct attached phys. Since there are no wide ported SATA
918 * devices this could become an invalid port configuration.
920 bool scic_sds_port_link_detected(
921 struct scic_sds_port
*sci_port
,
922 struct isci_phy
*iphy
)
924 if ((sci_port
->logical_port_index
!= SCIC_SDS_DUMMY_PORT
) &&
925 (iphy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SATA
) &&
926 scic_sds_port_is_wide(sci_port
)) {
927 scic_sds_port_invalid_link_up(sci_port
, iphy
);
935 static void port_timeout(unsigned long data
)
937 struct sci_timer
*tmr
= (struct sci_timer
*)data
;
938 struct scic_sds_port
*sci_port
= container_of(tmr
, typeof(*sci_port
), timer
);
939 struct isci_host
*ihost
= scic_to_ihost(sci_port
->owning_controller
);
943 spin_lock_irqsave(&ihost
->scic_lock
, flags
);
948 current_state
= sci_port
->sm
.current_state_id
;
950 if (current_state
== SCI_PORT_RESETTING
) {
951 /* if the port is still in the resetting state then the timeout
952 * fired before the reset completed.
954 port_state_machine_change(sci_port
, SCI_PORT_FAILED
);
955 } else if (current_state
== SCI_PORT_STOPPED
) {
956 /* if the port is stopped then the start request failed In this
957 * case stay in the stopped state.
959 dev_err(sciport_to_dev(sci_port
),
960 "%s: SCIC Port 0x%p failed to stop before tiemout.\n",
963 } else if (current_state
== SCI_PORT_STOPPING
) {
964 /* if the port is still stopping then the stop has not completed */
965 isci_port_stop_complete(sci_port
->owning_controller
,
967 SCI_FAILURE_TIMEOUT
);
969 /* The port is in the ready state and we have a timer
970 * reporting a timeout this should not happen.
972 dev_err(sciport_to_dev(sci_port
),
973 "%s: SCIC Port 0x%p is processing a timeout operation "
974 "in state %d.\n", __func__
, sci_port
, current_state
);
978 spin_unlock_irqrestore(&ihost
->scic_lock
, flags
);
981 /* --------------------------------------------------------------------------- */
984 * This function updates the hardwares VIIT entry for this port.
988 static void scic_sds_port_update_viit_entry(struct scic_sds_port
*sci_port
)
990 struct sci_sas_address sas_address
;
992 scic_sds_port_get_sas_address(sci_port
, &sas_address
);
994 writel(sas_address
.high
,
995 &sci_port
->viit_registers
->initiator_sas_address_hi
);
996 writel(sas_address
.low
,
997 &sci_port
->viit_registers
->initiator_sas_address_lo
);
999 /* This value get cleared just in case its not already cleared */
1000 writel(0, &sci_port
->viit_registers
->reserved
);
1002 /* We are required to update the status register last */
1003 writel(SCU_VIIT_ENTRY_ID_VIIT
|
1004 SCU_VIIT_IPPT_INITIATOR
|
1005 ((1 << sci_port
->physical_port_index
) << SCU_VIIT_ENTRY_LPVIE_SHIFT
) |
1006 SCU_VIIT_STATUS_ALL_VALID
,
1007 &sci_port
->viit_registers
->status
);
1010 enum sas_linkrate
scic_sds_port_get_max_allowed_speed(struct scic_sds_port
*sci_port
)
1013 struct isci_phy
*iphy
;
1014 enum sas_linkrate max_allowed_speed
= SAS_LINK_RATE_6_0_GBPS
;
1017 * Loop through all of the phys in this port and find the phy with the
1018 * lowest maximum link rate. */
1019 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
1020 iphy
= sci_port
->phy_table
[index
];
1021 if (iphy
&& scic_sds_port_active_phy(sci_port
, iphy
) &&
1022 iphy
->max_negotiated_speed
< max_allowed_speed
)
1023 max_allowed_speed
= iphy
->max_negotiated_speed
;
1026 return max_allowed_speed
;
1029 static void scic_sds_port_suspend_port_task_scheduler(struct scic_sds_port
*port
)
1031 u32 pts_control_value
;
1033 pts_control_value
= readl(&port
->port_task_scheduler_registers
->control
);
1034 pts_control_value
|= SCU_PTSxCR_GEN_BIT(SUSPEND
);
1035 writel(pts_control_value
, &port
->port_task_scheduler_registers
->control
);
1039 * scic_sds_port_post_dummy_request() - post dummy/workaround request
1040 * @sci_port: port to post task
1042 * Prevent the hardware scheduler from posting new requests to the front
1043 * of the scheduler queue causing a starvation problem for currently
1047 static void scic_sds_port_post_dummy_request(struct scic_sds_port
*sci_port
)
1049 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1050 u16 tag
= sci_port
->reserved_tag
;
1051 struct scu_task_context
*tc
;
1054 tc
= &scic
->task_context_table
[ISCI_TAG_TCI(tag
)];
1057 command
= SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC
|
1058 sci_port
->physical_port_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
|
1061 scic_sds_controller_post_request(scic
, command
);
1065 * This routine will abort the dummy request. This will alow the hardware to
1066 * power down parts of the silicon to save power.
1068 * @sci_port: The port on which the task must be aborted.
1071 static void scic_sds_port_abort_dummy_request(struct scic_sds_port
*sci_port
)
1073 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1074 u16 tag
= sci_port
->reserved_tag
;
1075 struct scu_task_context
*tc
;
1078 tc
= &scic
->task_context_table
[ISCI_TAG_TCI(tag
)];
1081 command
= SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT
|
1082 sci_port
->physical_port_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
|
1085 scic_sds_controller_post_request(scic
, command
);
1090 * @sci_port: This is the struct scic_sds_port object to resume.
1092 * This method will resume the port task scheduler for this port object. none
1095 scic_sds_port_resume_port_task_scheduler(struct scic_sds_port
*port
)
1097 u32 pts_control_value
;
1099 pts_control_value
= readl(&port
->port_task_scheduler_registers
->control
);
1100 pts_control_value
&= ~SCU_PTSxCR_GEN_BIT(SUSPEND
);
1101 writel(pts_control_value
, &port
->port_task_scheduler_registers
->control
);
1104 static void scic_sds_port_ready_substate_waiting_enter(struct sci_base_state_machine
*sm
)
1106 struct scic_sds_port
*sci_port
= container_of(sm
, typeof(*sci_port
), sm
);
1108 scic_sds_port_suspend_port_task_scheduler(sci_port
);
1110 sci_port
->not_ready_reason
= SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS
;
1112 if (sci_port
->active_phy_mask
!= 0) {
1113 /* At least one of the phys on the port is ready */
1114 port_state_machine_change(sci_port
,
1115 SCI_PORT_SUB_OPERATIONAL
);
1119 static void scic_sds_port_ready_substate_operational_enter(struct sci_base_state_machine
*sm
)
1122 struct scic_sds_port
*sci_port
= container_of(sm
, typeof(*sci_port
), sm
);
1123 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1124 struct isci_host
*ihost
= scic_to_ihost(scic
);
1125 struct isci_port
*iport
= sci_port_to_iport(sci_port
);
1127 isci_port_ready(ihost
, iport
);
1129 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
1130 if (sci_port
->phy_table
[index
]) {
1131 writel(sci_port
->physical_port_index
,
1132 &sci_port
->port_pe_configuration_register
[
1133 sci_port
->phy_table
[index
]->phy_index
]);
1137 scic_sds_port_update_viit_entry(sci_port
);
1139 scic_sds_port_resume_port_task_scheduler(sci_port
);
1142 * Post the dummy task for the port so the hardware can schedule
1145 scic_sds_port_post_dummy_request(sci_port
);
1148 static void scic_sds_port_invalidate_dummy_remote_node(struct scic_sds_port
*sci_port
)
1150 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1151 u8 phys_index
= sci_port
->physical_port_index
;
1152 union scu_remote_node_context
*rnc
;
1153 u16 rni
= sci_port
->reserved_rni
;
1156 rnc
= &scic
->remote_node_context_table
[rni
];
1158 rnc
->ssp
.is_valid
= false;
1160 /* ensure the preceding tc abort request has reached the
1161 * controller and give it ample time to act before posting the rnc
1164 readl(&scic
->smu_registers
->interrupt_status
); /* flush */
1167 command
= SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE
|
1168 phys_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
| rni
;
1170 scic_sds_controller_post_request(scic
, command
);
1175 * @object: This is the object which is cast to a struct scic_sds_port object.
1177 * This method will perform the actions required by the struct scic_sds_port on
1178 * exiting the SCI_PORT_SUB_OPERATIONAL. This function reports
1179 * the port not ready and suspends the port task scheduler. none
1181 static void scic_sds_port_ready_substate_operational_exit(struct sci_base_state_machine
*sm
)
1183 struct scic_sds_port
*sci_port
= container_of(sm
, typeof(*sci_port
), sm
);
1184 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1185 struct isci_host
*ihost
= scic_to_ihost(scic
);
1186 struct isci_port
*iport
= sci_port_to_iport(sci_port
);
1189 * Kill the dummy task for this port if it has not yet posted
1190 * the hardware will treat this as a NOP and just return abort
1193 scic_sds_port_abort_dummy_request(sci_port
);
1195 isci_port_not_ready(ihost
, iport
);
1197 if (sci_port
->ready_exit
)
1198 scic_sds_port_invalidate_dummy_remote_node(sci_port
);
1201 static void scic_sds_port_ready_substate_configuring_enter(struct sci_base_state_machine
*sm
)
1203 struct scic_sds_port
*sci_port
= container_of(sm
, typeof(*sci_port
), sm
);
1204 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1205 struct isci_host
*ihost
= scic_to_ihost(scic
);
1206 struct isci_port
*iport
= sci_port_to_iport(sci_port
);
1208 if (sci_port
->active_phy_mask
== 0) {
1209 isci_port_not_ready(ihost
, iport
);
1211 port_state_machine_change(sci_port
,
1212 SCI_PORT_SUB_WAITING
);
1213 } else if (sci_port
->started_request_count
== 0)
1214 port_state_machine_change(sci_port
,
1215 SCI_PORT_SUB_OPERATIONAL
);
1218 static void scic_sds_port_ready_substate_configuring_exit(struct sci_base_state_machine
*sm
)
1220 struct scic_sds_port
*sci_port
= container_of(sm
, typeof(*sci_port
), sm
);
1222 scic_sds_port_suspend_port_task_scheduler(sci_port
);
1223 if (sci_port
->ready_exit
)
1224 scic_sds_port_invalidate_dummy_remote_node(sci_port
);
1227 enum sci_status
scic_sds_port_start(struct scic_sds_port
*sci_port
)
1229 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1230 enum sci_status status
= SCI_SUCCESS
;
1231 enum scic_sds_port_states state
;
1234 state
= sci_port
->sm
.current_state_id
;
1235 if (state
!= SCI_PORT_STOPPED
) {
1236 dev_warn(sciport_to_dev(sci_port
),
1237 "%s: in wrong state: %d\n", __func__
, state
);
1238 return SCI_FAILURE_INVALID_STATE
;
1241 if (sci_port
->assigned_device_count
> 0) {
1242 /* TODO This is a start failure operation because
1243 * there are still devices assigned to this port.
1244 * There must be no devices assigned to a port on a
1247 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
;
1250 if (sci_port
->reserved_rni
== SCU_DUMMY_INDEX
) {
1251 u16 rni
= scic_sds_remote_node_table_allocate_remote_node(
1252 &scic
->available_remote_nodes
, 1);
1254 if (rni
!= SCU_DUMMY_INDEX
)
1255 scic_sds_port_construct_dummy_rnc(sci_port
, rni
);
1257 status
= SCI_FAILURE_INSUFFICIENT_RESOURCES
;
1258 sci_port
->reserved_rni
= rni
;
1261 if (sci_port
->reserved_tag
== SCI_CONTROLLER_INVALID_IO_TAG
) {
1262 struct isci_host
*ihost
= scic_to_ihost(scic
);
1265 tag
= isci_alloc_tag(ihost
);
1266 if (tag
== SCI_CONTROLLER_INVALID_IO_TAG
)
1267 status
= SCI_FAILURE_INSUFFICIENT_RESOURCES
;
1269 scic_sds_port_construct_dummy_task(sci_port
, tag
);
1270 sci_port
->reserved_tag
= tag
;
1273 if (status
== SCI_SUCCESS
) {
1274 phy_mask
= scic_sds_port_get_phys(sci_port
);
1277 * There are one or more phys assigned to this port. Make sure
1278 * the port's phy mask is in fact legal and supported by the
1281 if (scic_sds_port_is_phy_mask_valid(sci_port
, phy_mask
) == true) {
1282 port_state_machine_change(sci_port
,
1287 status
= SCI_FAILURE
;
1290 if (status
!= SCI_SUCCESS
)
1291 scic_sds_port_destroy_dummy_resources(sci_port
);
1296 enum sci_status
scic_sds_port_stop(struct scic_sds_port
*sci_port
)
1298 enum scic_sds_port_states state
;
1300 state
= sci_port
->sm
.current_state_id
;
1302 case SCI_PORT_STOPPED
:
1304 case SCI_PORT_SUB_WAITING
:
1305 case SCI_PORT_SUB_OPERATIONAL
:
1306 case SCI_PORT_SUB_CONFIGURING
:
1307 case SCI_PORT_RESETTING
:
1308 port_state_machine_change(sci_port
,
1312 dev_warn(sciport_to_dev(sci_port
),
1313 "%s: in wrong state: %d\n", __func__
, state
);
1314 return SCI_FAILURE_INVALID_STATE
;
1318 static enum sci_status
scic_port_hard_reset(struct scic_sds_port
*sci_port
, u32 timeout
)
1320 enum sci_status status
= SCI_FAILURE_INVALID_PHY
;
1321 struct isci_phy
*iphy
= NULL
;
1322 enum scic_sds_port_states state
;
1325 state
= sci_port
->sm
.current_state_id
;
1326 if (state
!= SCI_PORT_SUB_OPERATIONAL
) {
1327 dev_warn(sciport_to_dev(sci_port
),
1328 "%s: in wrong state: %d\n", __func__
, state
);
1329 return SCI_FAILURE_INVALID_STATE
;
1332 /* Select a phy on which we can send the hard reset request. */
1333 for (phy_index
= 0; phy_index
< SCI_MAX_PHYS
&& !iphy
; phy_index
++) {
1334 iphy
= sci_port
->phy_table
[phy_index
];
1335 if (iphy
&& !scic_sds_port_active_phy(sci_port
, iphy
)) {
1337 * We found a phy but it is not ready select
1344 /* If we have a phy then go ahead and start the reset procedure */
1347 status
= scic_sds_phy_reset(iphy
);
1349 if (status
!= SCI_SUCCESS
)
1352 sci_mod_timer(&sci_port
->timer
, timeout
);
1353 sci_port
->not_ready_reason
= SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED
;
1355 port_state_machine_change(sci_port
, SCI_PORT_RESETTING
);
1360 * scic_sds_port_add_phy() -
1361 * @sci_port: This parameter specifies the port in which the phy will be added.
1362 * @sci_phy: This parameter is the phy which is to be added to the port.
1364 * This method will add a PHY to the selected port. This method returns an
1365 * enum sci_status. SCI_SUCCESS the phy has been added to the port. Any other
1366 * status is a failure to add the phy to the port.
1368 enum sci_status
scic_sds_port_add_phy(struct scic_sds_port
*sci_port
,
1369 struct isci_phy
*iphy
)
1371 enum sci_status status
;
1372 enum scic_sds_port_states state
;
1374 state
= sci_port
->sm
.current_state_id
;
1376 case SCI_PORT_STOPPED
: {
1377 struct sci_sas_address port_sas_address
;
1379 /* Read the port assigned SAS Address if there is one */
1380 scic_sds_port_get_sas_address(sci_port
, &port_sas_address
);
1382 if (port_sas_address
.high
!= 0 && port_sas_address
.low
!= 0) {
1383 struct sci_sas_address phy_sas_address
;
1385 /* Make sure that the PHY SAS Address matches the SAS Address
1388 scic_sds_phy_get_sas_address(iphy
, &phy_sas_address
);
1390 if (port_sas_address
.high
!= phy_sas_address
.high
||
1391 port_sas_address
.low
!= phy_sas_address
.low
)
1392 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
;
1394 return scic_sds_port_set_phy(sci_port
, iphy
);
1396 case SCI_PORT_SUB_WAITING
:
1397 case SCI_PORT_SUB_OPERATIONAL
:
1398 status
= scic_sds_port_set_phy(sci_port
, iphy
);
1400 if (status
!= SCI_SUCCESS
)
1403 scic_sds_port_general_link_up_handler(sci_port
, iphy
, true);
1404 sci_port
->not_ready_reason
= SCIC_PORT_NOT_READY_RECONFIGURING
;
1405 port_state_machine_change(sci_port
, SCI_PORT_SUB_CONFIGURING
);
1408 case SCI_PORT_SUB_CONFIGURING
:
1409 status
= scic_sds_port_set_phy(sci_port
, iphy
);
1411 if (status
!= SCI_SUCCESS
)
1413 scic_sds_port_general_link_up_handler(sci_port
, iphy
, true);
1415 /* Re-enter the configuring state since this may be the last phy in
1418 port_state_machine_change(sci_port
,
1419 SCI_PORT_SUB_CONFIGURING
);
1422 dev_warn(sciport_to_dev(sci_port
),
1423 "%s: in wrong state: %d\n", __func__
, state
);
1424 return SCI_FAILURE_INVALID_STATE
;
1429 * scic_sds_port_remove_phy() -
1430 * @sci_port: This parameter specifies the port in which the phy will be added.
1431 * @sci_phy: This parameter is the phy which is to be added to the port.
1433 * This method will remove the PHY from the selected PORT. This method returns
1434 * an enum sci_status. SCI_SUCCESS the phy has been removed from the port. Any
1435 * other status is a failure to add the phy to the port.
1437 enum sci_status
scic_sds_port_remove_phy(struct scic_sds_port
*sci_port
,
1438 struct isci_phy
*iphy
)
1440 enum sci_status status
;
1441 enum scic_sds_port_states state
;
1443 state
= sci_port
->sm
.current_state_id
;
1446 case SCI_PORT_STOPPED
:
1447 return scic_sds_port_clear_phy(sci_port
, iphy
);
1448 case SCI_PORT_SUB_OPERATIONAL
:
1449 status
= scic_sds_port_clear_phy(sci_port
, iphy
);
1450 if (status
!= SCI_SUCCESS
)
1453 scic_sds_port_deactivate_phy(sci_port
, iphy
, true);
1454 sci_port
->not_ready_reason
= SCIC_PORT_NOT_READY_RECONFIGURING
;
1455 port_state_machine_change(sci_port
,
1456 SCI_PORT_SUB_CONFIGURING
);
1458 case SCI_PORT_SUB_CONFIGURING
:
1459 status
= scic_sds_port_clear_phy(sci_port
, iphy
);
1461 if (status
!= SCI_SUCCESS
)
1463 scic_sds_port_deactivate_phy(sci_port
, iphy
, true);
1465 /* Re-enter the configuring state since this may be the last phy in
1468 port_state_machine_change(sci_port
,
1469 SCI_PORT_SUB_CONFIGURING
);
1472 dev_warn(sciport_to_dev(sci_port
),
1473 "%s: in wrong state: %d\n", __func__
, state
);
1474 return SCI_FAILURE_INVALID_STATE
;
1478 enum sci_status
scic_sds_port_link_up(struct scic_sds_port
*sci_port
,
1479 struct isci_phy
*iphy
)
1481 enum scic_sds_port_states state
;
1483 state
= sci_port
->sm
.current_state_id
;
1485 case SCI_PORT_SUB_WAITING
:
1486 /* Since this is the first phy going link up for the port we
1487 * can just enable it and continue
1489 scic_sds_port_activate_phy(sci_port
, iphy
, true);
1491 port_state_machine_change(sci_port
,
1492 SCI_PORT_SUB_OPERATIONAL
);
1494 case SCI_PORT_SUB_OPERATIONAL
:
1495 scic_sds_port_general_link_up_handler(sci_port
, iphy
, true);
1497 case SCI_PORT_RESETTING
:
1498 /* TODO We should make sure that the phy that has gone
1499 * link up is the same one on which we sent the reset. It is
1500 * possible that the phy on which we sent the reset is not the
1501 * one that has gone link up and we want to make sure that
1502 * phy being reset comes back. Consider the case where a
1503 * reset is sent but before the hardware processes the reset it
1504 * get a link up on the port because of a hot plug event.
1505 * because of the reset request this phy will go link down
1506 * almost immediately.
1509 /* In the resetting state we don't notify the user regarding
1510 * link up and link down notifications.
1512 scic_sds_port_general_link_up_handler(sci_port
, iphy
, false);
1515 dev_warn(sciport_to_dev(sci_port
),
1516 "%s: in wrong state: %d\n", __func__
, state
);
1517 return SCI_FAILURE_INVALID_STATE
;
1521 enum sci_status
scic_sds_port_link_down(struct scic_sds_port
*sci_port
,
1522 struct isci_phy
*iphy
)
1524 enum scic_sds_port_states state
;
1526 state
= sci_port
->sm
.current_state_id
;
1528 case SCI_PORT_SUB_OPERATIONAL
:
1529 scic_sds_port_deactivate_phy(sci_port
, iphy
, true);
1531 /* If there are no active phys left in the port, then
1532 * transition the port to the WAITING state until such time
1533 * as a phy goes link up
1535 if (sci_port
->active_phy_mask
== 0)
1536 port_state_machine_change(sci_port
,
1537 SCI_PORT_SUB_WAITING
);
1539 case SCI_PORT_RESETTING
:
1540 /* In the resetting state we don't notify the user regarding
1541 * link up and link down notifications. */
1542 scic_sds_port_deactivate_phy(sci_port
, iphy
, false);
1545 dev_warn(sciport_to_dev(sci_port
),
1546 "%s: in wrong state: %d\n", __func__
, state
);
1547 return SCI_FAILURE_INVALID_STATE
;
1551 enum sci_status
scic_sds_port_start_io(struct scic_sds_port
*sci_port
,
1552 struct scic_sds_remote_device
*sci_dev
,
1553 struct isci_request
*ireq
)
1555 enum scic_sds_port_states state
;
1557 state
= sci_port
->sm
.current_state_id
;
1559 case SCI_PORT_SUB_WAITING
:
1560 return SCI_FAILURE_INVALID_STATE
;
1561 case SCI_PORT_SUB_OPERATIONAL
:
1562 sci_port
->started_request_count
++;
1565 dev_warn(sciport_to_dev(sci_port
),
1566 "%s: in wrong state: %d\n", __func__
, state
);
1567 return SCI_FAILURE_INVALID_STATE
;
1571 enum sci_status
scic_sds_port_complete_io(struct scic_sds_port
*sci_port
,
1572 struct scic_sds_remote_device
*sci_dev
,
1573 struct isci_request
*ireq
)
1575 enum scic_sds_port_states state
;
1577 state
= sci_port
->sm
.current_state_id
;
1579 case SCI_PORT_STOPPED
:
1580 dev_warn(sciport_to_dev(sci_port
),
1581 "%s: in wrong state: %d\n", __func__
, state
);
1582 return SCI_FAILURE_INVALID_STATE
;
1583 case SCI_PORT_STOPPING
:
1584 scic_sds_port_decrement_request_count(sci_port
);
1586 if (sci_port
->started_request_count
== 0)
1587 port_state_machine_change(sci_port
,
1590 case SCI_PORT_READY
:
1591 case SCI_PORT_RESETTING
:
1592 case SCI_PORT_FAILED
:
1593 case SCI_PORT_SUB_WAITING
:
1594 case SCI_PORT_SUB_OPERATIONAL
:
1595 scic_sds_port_decrement_request_count(sci_port
);
1597 case SCI_PORT_SUB_CONFIGURING
:
1598 scic_sds_port_decrement_request_count(sci_port
);
1599 if (sci_port
->started_request_count
== 0) {
1600 port_state_machine_change(sci_port
,
1601 SCI_PORT_SUB_OPERATIONAL
);
1610 * @sci_port: This is the port object which to suspend.
1612 * This method will enable the SCU Port Task Scheduler for this port object but
1613 * will leave the port task scheduler in a suspended state. none
1616 scic_sds_port_enable_port_task_scheduler(struct scic_sds_port
*port
)
1618 u32 pts_control_value
;
1620 pts_control_value
= readl(&port
->port_task_scheduler_registers
->control
);
1621 pts_control_value
|= SCU_PTSxCR_GEN_BIT(ENABLE
) | SCU_PTSxCR_GEN_BIT(SUSPEND
);
1622 writel(pts_control_value
, &port
->port_task_scheduler_registers
->control
);
1627 * @sci_port: This is the port object which to resume.
1629 * This method will disable the SCU port task scheduler for this port object.
1633 scic_sds_port_disable_port_task_scheduler(struct scic_sds_port
*port
)
1635 u32 pts_control_value
;
1637 pts_control_value
= readl(&port
->port_task_scheduler_registers
->control
);
1638 pts_control_value
&=
1639 ~(SCU_PTSxCR_GEN_BIT(ENABLE
) | SCU_PTSxCR_GEN_BIT(SUSPEND
));
1640 writel(pts_control_value
, &port
->port_task_scheduler_registers
->control
);
1643 static void scic_sds_port_post_dummy_remote_node(struct scic_sds_port
*sci_port
)
1645 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1646 u8 phys_index
= sci_port
->physical_port_index
;
1647 union scu_remote_node_context
*rnc
;
1648 u16 rni
= sci_port
->reserved_rni
;
1651 rnc
= &scic
->remote_node_context_table
[rni
];
1652 rnc
->ssp
.is_valid
= true;
1654 command
= SCU_CONTEXT_COMMAND_POST_RNC_32
|
1655 phys_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
| rni
;
1657 scic_sds_controller_post_request(scic
, command
);
1659 /* ensure hardware has seen the post rnc command and give it
1660 * ample time to act before sending the suspend
1662 readl(&scic
->smu_registers
->interrupt_status
); /* flush */
1665 command
= SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX
|
1666 phys_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
| rni
;
1668 scic_sds_controller_post_request(scic
, command
);
1671 static void scic_sds_port_stopped_state_enter(struct sci_base_state_machine
*sm
)
1673 struct scic_sds_port
*sci_port
= container_of(sm
, typeof(*sci_port
), sm
);
1675 if (sci_port
->sm
.previous_state_id
== SCI_PORT_STOPPING
) {
1677 * If we enter this state becasuse of a request to stop
1678 * the port then we want to disable the hardwares port
1679 * task scheduler. */
1680 scic_sds_port_disable_port_task_scheduler(sci_port
);
1684 static void scic_sds_port_stopped_state_exit(struct sci_base_state_machine
*sm
)
1686 struct scic_sds_port
*sci_port
= container_of(sm
, typeof(*sci_port
), sm
);
1688 /* Enable and suspend the port task scheduler */
1689 scic_sds_port_enable_port_task_scheduler(sci_port
);
1692 static void scic_sds_port_ready_state_enter(struct sci_base_state_machine
*sm
)
1694 struct scic_sds_port
*sci_port
= container_of(sm
, typeof(*sci_port
), sm
);
1695 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1696 struct isci_host
*ihost
= scic_to_ihost(scic
);
1697 struct isci_port
*iport
= sci_port_to_iport(sci_port
);
1700 prev_state
= sci_port
->sm
.previous_state_id
;
1701 if (prev_state
== SCI_PORT_RESETTING
)
1702 isci_port_hard_reset_complete(iport
, SCI_SUCCESS
);
1704 isci_port_not_ready(ihost
, iport
);
1706 /* Post and suspend the dummy remote node context for this port. */
1707 scic_sds_port_post_dummy_remote_node(sci_port
);
1709 /* Start the ready substate machine */
1710 port_state_machine_change(sci_port
,
1711 SCI_PORT_SUB_WAITING
);
1714 static void scic_sds_port_resetting_state_exit(struct sci_base_state_machine
*sm
)
1716 struct scic_sds_port
*sci_port
= container_of(sm
, typeof(*sci_port
), sm
);
1718 sci_del_timer(&sci_port
->timer
);
1721 static void scic_sds_port_stopping_state_exit(struct sci_base_state_machine
*sm
)
1723 struct scic_sds_port
*sci_port
= container_of(sm
, typeof(*sci_port
), sm
);
1725 sci_del_timer(&sci_port
->timer
);
1727 scic_sds_port_destroy_dummy_resources(sci_port
);
1730 static void scic_sds_port_failed_state_enter(struct sci_base_state_machine
*sm
)
1732 struct scic_sds_port
*sci_port
= container_of(sm
, typeof(*sci_port
), sm
);
1733 struct isci_port
*iport
= sci_port_to_iport(sci_port
);
1735 isci_port_hard_reset_complete(iport
, SCI_FAILURE_TIMEOUT
);
1738 /* --------------------------------------------------------------------------- */
1740 static const struct sci_base_state scic_sds_port_state_table
[] = {
1741 [SCI_PORT_STOPPED
] = {
1742 .enter_state
= scic_sds_port_stopped_state_enter
,
1743 .exit_state
= scic_sds_port_stopped_state_exit
1745 [SCI_PORT_STOPPING
] = {
1746 .exit_state
= scic_sds_port_stopping_state_exit
1748 [SCI_PORT_READY
] = {
1749 .enter_state
= scic_sds_port_ready_state_enter
,
1751 [SCI_PORT_SUB_WAITING
] = {
1752 .enter_state
= scic_sds_port_ready_substate_waiting_enter
,
1754 [SCI_PORT_SUB_OPERATIONAL
] = {
1755 .enter_state
= scic_sds_port_ready_substate_operational_enter
,
1756 .exit_state
= scic_sds_port_ready_substate_operational_exit
1758 [SCI_PORT_SUB_CONFIGURING
] = {
1759 .enter_state
= scic_sds_port_ready_substate_configuring_enter
,
1760 .exit_state
= scic_sds_port_ready_substate_configuring_exit
1762 [SCI_PORT_RESETTING
] = {
1763 .exit_state
= scic_sds_port_resetting_state_exit
1765 [SCI_PORT_FAILED
] = {
1766 .enter_state
= scic_sds_port_failed_state_enter
,
1770 void scic_sds_port_construct(struct scic_sds_port
*sci_port
, u8 index
,
1771 struct scic_sds_controller
*scic
)
1773 sci_init_sm(&sci_port
->sm
, scic_sds_port_state_table
, SCI_PORT_STOPPED
);
1775 sci_port
->logical_port_index
= SCIC_SDS_DUMMY_PORT
;
1776 sci_port
->physical_port_index
= index
;
1777 sci_port
->active_phy_mask
= 0;
1778 sci_port
->ready_exit
= false;
1780 sci_port
->owning_controller
= scic
;
1782 sci_port
->started_request_count
= 0;
1783 sci_port
->assigned_device_count
= 0;
1785 sci_port
->reserved_rni
= SCU_DUMMY_INDEX
;
1786 sci_port
->reserved_tag
= SCI_CONTROLLER_INVALID_IO_TAG
;
1788 sci_init_timer(&sci_port
->timer
, port_timeout
);
1790 sci_port
->port_task_scheduler_registers
= NULL
;
1792 for (index
= 0; index
< SCI_MAX_PHYS
; index
++)
1793 sci_port
->phy_table
[index
] = NULL
;
1796 void isci_port_init(struct isci_port
*iport
, struct isci_host
*ihost
, int index
)
1798 INIT_LIST_HEAD(&iport
->remote_dev_list
);
1799 INIT_LIST_HEAD(&iport
->domain_dev_list
);
1800 spin_lock_init(&iport
->state_lock
);
1801 init_completion(&iport
->start_complete
);
1802 iport
->isci_host
= ihost
;
1803 isci_port_change_state(iport
, isci_freed
);
1804 atomic_set(&iport
->event
, 0);
1808 * isci_port_get_state() - This function gets the status of the port object.
1809 * @isci_port: This parameter points to the isci_port object
1811 * status of the object as a isci_status enum.
1813 enum isci_status
isci_port_get_state(
1814 struct isci_port
*isci_port
)
1816 return isci_port
->status
;
1819 void scic_sds_port_broadcast_change_received(
1820 struct scic_sds_port
*sci_port
,
1821 struct isci_phy
*iphy
)
1823 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1824 struct isci_host
*ihost
= scic_to_ihost(scic
);
1826 /* notify the user. */
1827 isci_port_bc_change_received(ihost
, sci_port
, iphy
);
1830 int isci_port_perform_hard_reset(struct isci_host
*ihost
, struct isci_port
*iport
,
1831 struct isci_phy
*iphy
)
1833 unsigned long flags
;
1834 enum sci_status status
;
1835 int idx
, ret
= TMF_RESP_FUNC_COMPLETE
;
1837 dev_dbg(&ihost
->pdev
->dev
, "%s: iport = %p\n",
1840 init_completion(&iport
->hard_reset_complete
);
1842 spin_lock_irqsave(&ihost
->scic_lock
, flags
);
1844 #define ISCI_PORT_RESET_TIMEOUT SCIC_SDS_SIGNATURE_FIS_TIMEOUT
1845 status
= scic_port_hard_reset(&iport
->sci
, ISCI_PORT_RESET_TIMEOUT
);
1847 spin_unlock_irqrestore(&ihost
->scic_lock
, flags
);
1849 if (status
== SCI_SUCCESS
) {
1850 wait_for_completion(&iport
->hard_reset_complete
);
1852 dev_dbg(&ihost
->pdev
->dev
,
1853 "%s: iport = %p; hard reset completion\n",
1856 if (iport
->hard_reset_status
!= SCI_SUCCESS
)
1857 ret
= TMF_RESP_FUNC_FAILED
;
1859 ret
= TMF_RESP_FUNC_FAILED
;
1861 dev_err(&ihost
->pdev
->dev
,
1862 "%s: iport = %p; scic_port_hard_reset call"
1864 __func__
, iport
, status
);
1868 /* If the hard reset for the port has failed, consider this
1869 * the same as link failures on all phys in the port.
1871 if (ret
!= TMF_RESP_FUNC_COMPLETE
) {
1873 dev_err(&ihost
->pdev
->dev
,
1874 "%s: iport = %p; hard reset failed "
1875 "(0x%x) - driving explicit link fail for all phys\n",
1876 __func__
, iport
, iport
->hard_reset_status
);
1878 /* Down all phys in the port. */
1879 spin_lock_irqsave(&ihost
->scic_lock
, flags
);
1880 for (idx
= 0; idx
< SCI_MAX_PHYS
; ++idx
) {
1882 if (iport
->sci
.phy_table
[idx
] != NULL
) {
1885 iport
->sci
.phy_table
[idx
]);
1887 iport
->sci
.phy_table
[idx
]);
1890 spin_unlock_irqrestore(&ihost
->scic_lock
, flags
);
1896 * isci_port_deformed() - This function is called by libsas when a port becomes
1898 * @phy: This parameter specifies the libsas phy with the inactive port.
1901 void isci_port_deformed(struct asd_sas_phy
*phy
)
1903 pr_debug("%s: sas_phy = %p\n", __func__
, phy
);
1907 * isci_port_formed() - This function is called by libsas when a port becomes
1909 * @phy: This parameter specifies the libsas phy with the active port.
1912 void isci_port_formed(struct asd_sas_phy
*phy
)
1914 pr_debug("%s: sas_phy = %p, sas_port = %p\n", __func__
, phy
, phy
->port
);