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 scic_sds_phy
*sci_phy
;
161 for (i
= 0; i
< ARRAY_SIZE(sci_port
->phy_table
); i
++) {
162 sci_phy
= sci_port
->phy_table
[i
];
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
);
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 scic_sds_phy
*sci_phy
= iport
->sci
.phy_table
[i
];
184 struct isci_phy
*iphy
= sci_phy_to_iphy(sci_phy
);
189 ihost
->sas_ha
.notify_port_event(&iphy
->sas_phy
,
190 PORTE_BROADCAST_RCVD
);
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
)
199 struct isci_phy
*iphy
= sci_phy_to_iphy(sci_phy
);
200 struct isci_port
*iport
= iphy
->isci_port
;
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
);
210 dev_dbg(&ihost
->pdev
->dev
,
211 "%s: isci_phy = %p, sas_phy = %p\n",
212 __func__
, iphy
, &iphy
->sas_phy
);
214 ihost
->sas_ha
.notify_port_event(&iphy
->sas_phy
,
215 PORTE_BROADCAST_RCVD
);
217 scic_port_bcn_enable(sci_port
);
220 static void isci_port_link_up(struct isci_host
*isci_host
,
221 struct scic_sds_port
*port
,
222 struct scic_sds_phy
*phy
)
225 struct scic_port_properties properties
;
226 struct isci_phy
*isci_phy
= sci_phy_to_iphy(phy
);
227 struct isci_port
*isci_port
= sci_port_to_iport(port
);
228 unsigned long success
= true;
230 BUG_ON(isci_phy
->isci_port
!= NULL
);
232 isci_phy
->isci_port
= isci_port
;
234 dev_dbg(&isci_host
->pdev
->dev
,
235 "%s: isci_port = %p\n",
236 __func__
, isci_port
);
238 spin_lock_irqsave(&isci_phy
->sas_phy
.frame_rcvd_lock
, flags
);
240 isci_port_change_state(isci_phy
->isci_port
, isci_starting
);
242 scic_port_get_properties(port
, &properties
);
244 if (phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SATA
) {
245 u64 attached_sas_address
;
247 isci_phy
->sas_phy
.oob_mode
= SATA_OOB_MODE
;
248 isci_phy
->sas_phy
.frame_rcvd_size
= sizeof(struct dev_to_host_fis
);
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.
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
);
262 memcpy(&isci_phy
->sas_phy
.attached_sas_addr
,
263 &attached_sas_address
, sizeof(attached_sas_address
));
264 } else if (phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SAS
) {
265 isci_phy
->sas_phy
.oob_mode
= SAS_OOB_MODE
;
266 isci_phy
->sas_phy
.frame_rcvd_size
= sizeof(struct sas_identify_frame
);
268 /* Copy the attached SAS address from the IAF */
269 memcpy(isci_phy
->sas_phy
.attached_sas_addr
,
270 isci_phy
->frame_rcvd
.iaf
.sas_addr
, SAS_ADDR_SIZE
);
272 dev_err(&isci_host
->pdev
->dev
, "%s: unkown target\n", __func__
);
276 isci_phy
->sas_phy
.phy
->negotiated_linkrate
= sci_phy_linkrate(phy
);
278 spin_unlock_irqrestore(&isci_phy
->sas_phy
.frame_rcvd_lock
, flags
);
280 /* Notify libsas that we have an address frame, if indeed
281 * we've found an SSP, SMP, or STP target */
283 isci_host
->sas_ha
.notify_port_event(&isci_phy
->sas_phy
,
289 * isci_port_link_down() - This function is called by the sci core when a link
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.
296 static void isci_port_link_down(struct isci_host
*isci_host
,
297 struct isci_phy
*isci_phy
,
298 struct isci_port
*isci_port
)
300 struct isci_remote_device
*isci_device
;
302 dev_dbg(&isci_host
->pdev
->dev
,
303 "%s: isci_port = %p\n", __func__
, isci_port
);
307 /* check to see if this is the last phy on this port. */
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
);
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
318 list_for_each_entry(isci_device
,
319 &isci_port
->remote_dev_list
,
321 dev_dbg(&isci_host
->pdev
->dev
,
322 "%s: isci_device = %p\n",
323 __func__
, isci_device
);
324 set_bit(IDEV_GONE
, &isci_device
->flags
);
327 isci_port_change_state(isci_port
, isci_stopping
);
330 /* Notify libsas of the borken link, this will trigger calls to our
331 * isci_port_deformed and isci_dev_gone functions.
333 sas_phy_disconnected(&isci_phy
->sas_phy
);
334 isci_host
->sas_ha
.notify_phy_event(&isci_phy
->sas_phy
,
335 PHYE_LOSS_OF_SIGNAL
);
337 isci_phy
->isci_port
= NULL
;
339 dev_dbg(&isci_host
->pdev
->dev
,
340 "%s: isci_port = %p - Done\n", __func__
, isci_port
);
345 * isci_port_ready() - This function is called by the sci core when a link
347 * @isci_host: This parameter specifies the isci host object.
348 * @port: This parameter specifies the sci port with the active link.
351 static void isci_port_ready(struct isci_host
*isci_host
, struct isci_port
*isci_port
)
353 dev_dbg(&isci_host
->pdev
->dev
,
354 "%s: isci_port = %p\n", __func__
, isci_port
);
356 complete_all(&isci_port
->start_complete
);
357 isci_port_change_state(isci_port
, isci_ready
);
362 * isci_port_not_ready() - This function is called by the sci core when a link
363 * is not ready. All remote devices on this link will be removed if they are
364 * in the stopping state.
365 * @isci_host: This parameter specifies the isci host object.
366 * @port: This parameter specifies the sci port with the active link.
369 static void isci_port_not_ready(struct isci_host
*isci_host
, struct isci_port
*isci_port
)
371 dev_dbg(&isci_host
->pdev
->dev
,
372 "%s: isci_port = %p\n", __func__
, isci_port
);
375 static void isci_port_stop_complete(struct scic_sds_controller
*scic
,
376 struct scic_sds_port
*sci_port
,
377 enum sci_status completion_status
)
379 dev_dbg(&scic_to_ihost(scic
)->pdev
->dev
, "Port stop complete\n");
383 * isci_port_hard_reset_complete() - This function is called by the sci core
384 * when the hard reset complete notification has been received.
385 * @port: This parameter specifies the sci port with the active link.
386 * @completion_status: This parameter specifies the core status for the reset
390 static void isci_port_hard_reset_complete(struct isci_port
*isci_port
,
391 enum sci_status completion_status
)
393 dev_dbg(&isci_port
->isci_host
->pdev
->dev
,
394 "%s: isci_port = %p, completion_status=%x\n",
395 __func__
, isci_port
, completion_status
);
397 /* Save the status of the hard reset from the port. */
398 isci_port
->hard_reset_status
= completion_status
;
400 complete_all(&isci_port
->hard_reset_complete
);
403 /* This method will return a true value if the specified phy can be assigned to
404 * this port The following is a list of phys for each port that are allowed: -
405 * Port 0 - 3 2 1 0 - Port 1 - 1 - Port 2 - 3 2 - Port 3 - 3 This method
406 * doesn't preclude all configurations. It merely ensures that a phy is part
407 * of the allowable set of phy identifiers for that port. For example, one
408 * could assign phy 3 to port 0 and no other phys. Please refer to
409 * scic_sds_port_is_phy_mask_valid() for information regarding whether the
410 * phy_mask for a port can be supported. bool true if this is a valid phy
411 * assignment for the port false if this is not a valid phy assignment for the
414 bool scic_sds_port_is_valid_phy_assignment(struct scic_sds_port
*sci_port
,
417 /* Initialize to invalid value. */
418 u32 existing_phy_index
= SCI_MAX_PHYS
;
421 if ((sci_port
->physical_port_index
== 1) && (phy_index
!= 1)) {
425 if (sci_port
->physical_port_index
== 3 && phy_index
!= 3) {
430 (sci_port
->physical_port_index
== 2)
431 && ((phy_index
== 0) || (phy_index
== 1))
436 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
437 if ((sci_port
->phy_table
[index
] != NULL
)
438 && (index
!= phy_index
)) {
439 existing_phy_index
= index
;
444 * Ensure that all of the phys in the port are capable of
445 * operating at the same maximum link rate. */
447 (existing_phy_index
< SCI_MAX_PHYS
)
448 && (sci_port
->owning_controller
->user_parameters
.sds1
.phys
[
449 phy_index
].max_speed_generation
!=
450 sci_port
->owning_controller
->user_parameters
.sds1
.phys
[
451 existing_phy_index
].max_speed_generation
)
460 * @sci_port: This is the port object for which to determine if the phy mask
463 * This method will return a true value if the port's phy mask can be supported
464 * by the SCU. The following is a list of valid PHY mask configurations for
465 * each port: - Port 0 - [[3 2] 1] 0 - Port 1 - [1] - Port 2 - [[3] 2]
466 * - Port 3 - [3] This method returns a boolean indication specifying if the
467 * phy mask can be supported. true if this is a valid phy assignment for the
468 * port false if this is not a valid phy assignment for the port
470 static bool scic_sds_port_is_phy_mask_valid(
471 struct scic_sds_port
*sci_port
,
474 if (sci_port
->physical_port_index
== 0) {
475 if (((phy_mask
& 0x0F) == 0x0F)
476 || ((phy_mask
& 0x03) == 0x03)
477 || ((phy_mask
& 0x01) == 0x01)
480 } else if (sci_port
->physical_port_index
== 1) {
481 if (((phy_mask
& 0x02) == 0x02)
484 } else if (sci_port
->physical_port_index
== 2) {
485 if (((phy_mask
& 0x0C) == 0x0C)
486 || ((phy_mask
& 0x04) == 0x04)
489 } else if (sci_port
->physical_port_index
== 3) {
490 if (((phy_mask
& 0x08) == 0x08)
500 * @sci_port: This parameter specifies the port from which to return a
503 * This method retrieves a currently active (i.e. connected) phy contained in
504 * the port. Currently, the lowest order phy that is connected is returned.
505 * This method returns a pointer to a SCIS_SDS_PHY object. NULL This value is
506 * returned if there are no currently active (i.e. connected to a remote end
507 * point) phys contained in the port. All other values specify a struct scic_sds_phy
508 * object that is active in the port.
510 static struct scic_sds_phy
*scic_sds_port_get_a_connected_phy(
511 struct scic_sds_port
*sci_port
514 struct scic_sds_phy
*phy
;
516 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
518 * Ensure that the phy is both part of the port and currently
519 * connected to the remote end-point. */
520 phy
= sci_port
->phy_table
[index
];
523 && scic_sds_port_active_phy(sci_port
, phy
)
533 * scic_sds_port_set_phy() -
534 * @out]: port The port object to which the phy assignement is being made.
535 * @out]: phy The phy which is being assigned to the port.
537 * This method attempts to make the assignment of the phy to the port. If
538 * successful the phy is assigned to the ports phy table. bool true if the phy
539 * assignment can be made. false if the phy assignement can not be made. This
540 * is a functional test that only fails if the phy is currently assigned to a
543 static enum sci_status
scic_sds_port_set_phy(
544 struct scic_sds_port
*port
,
545 struct scic_sds_phy
*phy
)
548 * Check to see if we can add this phy to a port
549 * that means that the phy is not part of a port and that the port does
550 * not already have a phy assinged to the phy index. */
552 (port
->phy_table
[phy
->phy_index
] == NULL
)
553 && (phy_get_non_dummy_port(phy
) == NULL
)
554 && scic_sds_port_is_valid_phy_assignment(port
, phy
->phy_index
)
557 * Phy is being added in the stopped state so we are in MPC mode
558 * make logical port index = physical port index */
559 port
->logical_port_index
= port
->physical_port_index
;
560 port
->phy_table
[phy
->phy_index
] = phy
;
561 scic_sds_phy_set_port(phy
, port
);
570 * scic_sds_port_clear_phy() -
571 * @out]: port The port from which the phy is being cleared.
572 * @out]: phy The phy being cleared from the port.
574 * This method will clear the phy assigned to this port. This method fails if
575 * this phy is not currently assinged to this port. bool true if the phy is
576 * removed from the port. false if this phy is not assined to this port.
578 static enum sci_status
scic_sds_port_clear_phy(
579 struct scic_sds_port
*port
,
580 struct scic_sds_phy
*phy
)
582 /* Make sure that this phy is part of this port */
583 if (port
->phy_table
[phy
->phy_index
] == phy
&&
584 phy_get_non_dummy_port(phy
) == port
) {
585 struct scic_sds_controller
*scic
= port
->owning_controller
;
586 struct isci_host
*ihost
= scic_to_ihost(scic
);
588 /* Yep it is assigned to this port so remove it */
589 scic_sds_phy_set_port(phy
, &ihost
->ports
[SCI_MAX_PORTS
].sci
);
590 port
->phy_table
[phy
->phy_index
] = NULL
;
599 * This method requests the SAS address for the supplied SAS port from the SCI
601 * @sci_port: a handle corresponding to the SAS port for which to return the
603 * @sas_address: This parameter specifies a pointer to a SAS address structure
604 * into which the core will copy the SAS address for the port.
607 void scic_sds_port_get_sas_address(
608 struct scic_sds_port
*sci_port
,
609 struct sci_sas_address
*sas_address
)
613 sas_address
->high
= 0;
614 sas_address
->low
= 0;
616 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
617 if (sci_port
->phy_table
[index
] != NULL
) {
618 scic_sds_phy_get_sas_address(sci_port
->phy_table
[index
], sas_address
);
624 * This function requests the SAS address for the device directly attached to
626 * @sci_port: a handle corresponding to the SAS port for which to return the
628 * @sas_address: This parameter specifies a pointer to a SAS address structure
629 * into which the core will copy the SAS address for the device directly
630 * attached to the port.
633 void scic_sds_port_get_attached_sas_address(
634 struct scic_sds_port
*sci_port
,
635 struct sci_sas_address
*sas_address
)
637 struct scic_sds_phy
*sci_phy
;
640 * Ensure that the phy is both part of the port and currently
641 * connected to the remote end-point.
643 sci_phy
= scic_sds_port_get_a_connected_phy(sci_port
);
645 if (sci_phy
->protocol
!= SCIC_SDS_PHY_PROTOCOL_SATA
) {
646 scic_sds_phy_get_attached_sas_address(sci_phy
,
649 scic_sds_phy_get_sas_address(sci_phy
, sas_address
);
650 sas_address
->low
+= sci_phy
->phy_index
;
653 sas_address
->high
= 0;
654 sas_address
->low
= 0;
659 * scic_sds_port_construct_dummy_rnc() - create dummy rnc for si workaround
661 * @sci_port: logical port on which we need to create the remote node context
662 * @rni: remote node index for this remote node context.
664 * This routine will construct a dummy remote node context data structure
665 * This structure will be posted to the hardware to work around a scheduler
666 * error in the hardware.
668 static void scic_sds_port_construct_dummy_rnc(struct scic_sds_port
*sci_port
, u16 rni
)
670 union scu_remote_node_context
*rnc
;
672 rnc
= &sci_port
->owning_controller
->remote_node_context_table
[rni
];
674 memset(rnc
, 0, sizeof(union scu_remote_node_context
));
676 rnc
->ssp
.remote_sas_address_hi
= 0;
677 rnc
->ssp
.remote_sas_address_lo
= 0;
679 rnc
->ssp
.remote_node_index
= rni
;
680 rnc
->ssp
.remote_node_port_width
= 1;
681 rnc
->ssp
.logical_port_index
= sci_port
->physical_port_index
;
683 rnc
->ssp
.nexus_loss_timer_enable
= false;
684 rnc
->ssp
.check_bit
= false;
685 rnc
->ssp
.is_valid
= true;
686 rnc
->ssp
.is_remote_node_context
= true;
687 rnc
->ssp
.function_number
= 0;
688 rnc
->ssp
.arbitration_wait_time
= 0;
692 * construct a dummy task context data structure. This
693 * structure will be posted to the hardwre to work around a scheduler error
696 static void scic_sds_port_construct_dummy_task(struct scic_sds_port
*sci_port
, u16 tag
)
698 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
699 struct scu_task_context
*task_context
;
701 task_context
= &scic
->task_context_table
[ISCI_TAG_TCI(tag
)];
702 memset(task_context
, 0, sizeof(struct scu_task_context
));
704 task_context
->initiator_request
= 1;
705 task_context
->connection_rate
= 1;
706 task_context
->logical_port_index
= sci_port
->physical_port_index
;
707 task_context
->protocol_type
= SCU_TASK_CONTEXT_PROTOCOL_SSP
;
708 task_context
->task_index
= ISCI_TAG_TCI(tag
);
709 task_context
->valid
= SCU_TASK_CONTEXT_VALID
;
710 task_context
->context_type
= SCU_TASK_CONTEXT_TYPE
;
711 task_context
->remote_node_index
= sci_port
->reserved_rni
;
712 task_context
->do_not_dma_ssp_good_response
= 1;
713 task_context
->task_phase
= 0x01;
716 static void scic_sds_port_destroy_dummy_resources(struct scic_sds_port
*sci_port
)
718 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
720 if (sci_port
->reserved_tag
!= SCI_CONTROLLER_INVALID_IO_TAG
)
721 isci_free_tag(scic_to_ihost(scic
), sci_port
->reserved_tag
);
723 if (sci_port
->reserved_rni
!= SCU_DUMMY_INDEX
)
724 scic_sds_remote_node_table_release_remote_node_index(&scic
->available_remote_nodes
,
725 1, sci_port
->reserved_rni
);
727 sci_port
->reserved_rni
= SCU_DUMMY_INDEX
;
728 sci_port
->reserved_tag
= SCI_CONTROLLER_INVALID_IO_TAG
;
732 * This method performs initialization of the supplied port. Initialization
733 * includes: - state machine initialization - member variable initialization
734 * - configuring the phy_mask
736 * @transport_layer_registers:
737 * @port_task_scheduler_registers:
738 * @port_configuration_regsiter:
740 * enum sci_status SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION This value is returned
741 * if the phy being added to the port
743 enum sci_status
scic_sds_port_initialize(
744 struct scic_sds_port
*sci_port
,
745 void __iomem
*port_task_scheduler_registers
,
746 void __iomem
*port_configuration_regsiter
,
747 void __iomem
*viit_registers
)
749 sci_port
->port_task_scheduler_registers
= port_task_scheduler_registers
;
750 sci_port
->port_pe_configuration_register
= port_configuration_regsiter
;
751 sci_port
->viit_registers
= viit_registers
;
758 * This method assigns the direct attached device ID for this port.
760 * @param[in] sci_port The port for which the direct attached device id is to
762 * @param[in] device_id The direct attached device ID to assign to the port.
763 * This will be the RNi for the device
765 void scic_sds_port_setup_transports(
766 struct scic_sds_port
*sci_port
,
771 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
772 if (sci_port
->active_phy_mask
& (1 << index
))
773 scic_sds_phy_setup_transport(sci_port
->phy_table
[index
], device_id
);
779 * @sci_port: This is the port on which the phy should be enabled.
780 * @sci_phy: This is the specific phy which to enable.
781 * @do_notify_user: This parameter specifies whether to inform the user (via
782 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
784 * This function will activate the phy in the port.
785 * Activation includes: - adding
786 * the phy to the port - enabling the Protocol Engine in the silicon. -
787 * notifying the user that the link is up. none
789 static void scic_sds_port_activate_phy(struct scic_sds_port
*sci_port
,
790 struct scic_sds_phy
*sci_phy
,
793 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
794 struct isci_host
*ihost
= scic_to_ihost(scic
);
796 if (sci_phy
->protocol
!= SCIC_SDS_PHY_PROTOCOL_SATA
)
797 scic_sds_phy_resume(sci_phy
);
799 sci_port
->active_phy_mask
|= 1 << sci_phy
->phy_index
;
801 scic_sds_controller_clear_invalid_phy(scic
, sci_phy
);
803 if (do_notify_user
== true)
804 isci_port_link_up(ihost
, sci_port
, sci_phy
);
807 void scic_sds_port_deactivate_phy(struct scic_sds_port
*sci_port
,
808 struct scic_sds_phy
*sci_phy
,
811 struct scic_sds_controller
*scic
= scic_sds_port_get_controller(sci_port
);
812 struct isci_port
*iport
= sci_port_to_iport(sci_port
);
813 struct isci_host
*ihost
= scic_to_ihost(scic
);
814 struct isci_phy
*iphy
= sci_phy_to_iphy(sci_phy
);
816 sci_port
->active_phy_mask
&= ~(1 << sci_phy
->phy_index
);
818 sci_phy
->max_negotiated_speed
= SAS_LINK_RATE_UNKNOWN
;
820 /* Re-assign the phy back to the LP as if it were a narrow port */
821 writel(sci_phy
->phy_index
,
822 &sci_port
->port_pe_configuration_register
[sci_phy
->phy_index
]);
824 if (do_notify_user
== true)
825 isci_port_link_down(ihost
, iphy
, iport
);
830 * @sci_port: This is the port on which the phy should be disabled.
831 * @sci_phy: This is the specific phy which to disabled.
833 * This function will disable the phy and report that the phy is not valid for
834 * this port object. None
836 static void scic_sds_port_invalid_link_up(struct scic_sds_port
*sci_port
,
837 struct scic_sds_phy
*sci_phy
)
839 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
842 * Check to see if we have alreay reported this link as bad and if
843 * not go ahead and tell the SCI_USER that we have discovered an
846 if ((scic
->invalid_phy_mask
& (1 << sci_phy
->phy_index
)) == 0) {
847 scic_sds_controller_set_invalid_phy(scic
, sci_phy
);
848 dev_warn(&scic_to_ihost(scic
)->pdev
->dev
, "Invalid link up!\n");
852 static bool is_port_ready_state(enum scic_sds_port_states state
)
856 case SCI_PORT_SUB_WAITING
:
857 case SCI_PORT_SUB_OPERATIONAL
:
858 case SCI_PORT_SUB_CONFIGURING
:
865 /* flag dummy rnc hanling when exiting a ready state */
866 static void port_state_machine_change(struct scic_sds_port
*sci_port
,
867 enum scic_sds_port_states state
)
869 struct sci_base_state_machine
*sm
= &sci_port
->sm
;
870 enum scic_sds_port_states old_state
= sm
->current_state_id
;
872 if (is_port_ready_state(old_state
) && !is_port_ready_state(state
))
873 sci_port
->ready_exit
= true;
875 sci_change_state(sm
, state
);
876 sci_port
->ready_exit
= false;
880 * scic_sds_port_general_link_up_handler - phy can be assigned to port?
881 * @sci_port: scic_sds_port object for which has a phy that has gone link up.
882 * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
883 * @do_notify_user: This parameter specifies whether to inform the user (via
884 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
886 * Determine if this phy can be assigned to this
887 * port . If the phy is not a valid PHY for
888 * this port then the function will notify the user. A PHY can only be
889 * part of a port if it's attached SAS ADDRESS is the same as all other PHYs in
890 * the same port. none
892 static void scic_sds_port_general_link_up_handler(struct scic_sds_port
*sci_port
,
893 struct scic_sds_phy
*sci_phy
,
896 struct sci_sas_address port_sas_address
;
897 struct sci_sas_address phy_sas_address
;
899 scic_sds_port_get_attached_sas_address(sci_port
, &port_sas_address
);
900 scic_sds_phy_get_attached_sas_address(sci_phy
, &phy_sas_address
);
902 /* If the SAS address of the new phy matches the SAS address of
903 * other phys in the port OR this is the first phy in the port,
904 * then activate the phy and allow it to be used for operations
907 if ((phy_sas_address
.high
== port_sas_address
.high
&&
908 phy_sas_address
.low
== port_sas_address
.low
) ||
909 sci_port
->active_phy_mask
== 0) {
910 struct sci_base_state_machine
*sm
= &sci_port
->sm
;
912 scic_sds_port_activate_phy(sci_port
, sci_phy
, do_notify_user
);
913 if (sm
->current_state_id
== SCI_PORT_RESETTING
)
914 port_state_machine_change(sci_port
, SCI_PORT_READY
);
916 scic_sds_port_invalid_link_up(sci_port
, sci_phy
);
922 * This method returns false if the port only has a single phy object assigned.
923 * If there are no phys or more than one phy then the method will return
925 * @sci_port: The port for which the wide port condition is to be checked.
927 * bool true Is returned if this is a wide ported port. false Is returned if
928 * this is a narrow port.
930 static bool scic_sds_port_is_wide(struct scic_sds_port
*sci_port
)
935 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
936 if (sci_port
->phy_table
[index
] != NULL
) {
941 return phy_count
!= 1;
945 * This method is called by the PHY object when the link is detected. if the
946 * port wants the PHY to continue on to the link up state then the port
947 * layer must return true. If the port object returns false the phy object
948 * must halt its attempt to go link up.
949 * @sci_port: The port associated with the phy object.
950 * @sci_phy: The phy object that is trying to go link up.
952 * true if the phy object can continue to the link up condition. true Is
953 * returned if this phy can continue to the ready state. false Is returned if
954 * can not continue on to the ready state. This notification is in place for
955 * wide ports and direct attached phys. Since there are no wide ported SATA
956 * devices this could become an invalid port configuration.
958 bool scic_sds_port_link_detected(
959 struct scic_sds_port
*sci_port
,
960 struct scic_sds_phy
*sci_phy
)
962 if ((sci_port
->logical_port_index
!= SCIC_SDS_DUMMY_PORT
) &&
963 (sci_phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SATA
) &&
964 scic_sds_port_is_wide(sci_port
)) {
965 scic_sds_port_invalid_link_up(sci_port
, sci_phy
);
973 static void port_timeout(unsigned long data
)
975 struct sci_timer
*tmr
= (struct sci_timer
*)data
;
976 struct scic_sds_port
*sci_port
= container_of(tmr
, typeof(*sci_port
), timer
);
977 struct isci_host
*ihost
= scic_to_ihost(sci_port
->owning_controller
);
981 spin_lock_irqsave(&ihost
->scic_lock
, flags
);
986 current_state
= sci_port
->sm
.current_state_id
;
988 if (current_state
== SCI_PORT_RESETTING
) {
989 /* if the port is still in the resetting state then the timeout
990 * fired before the reset completed.
992 port_state_machine_change(sci_port
, SCI_PORT_FAILED
);
993 } else if (current_state
== SCI_PORT_STOPPED
) {
994 /* if the port is stopped then the start request failed In this
995 * case stay in the stopped state.
997 dev_err(sciport_to_dev(sci_port
),
998 "%s: SCIC Port 0x%p failed to stop before tiemout.\n",
1001 } else if (current_state
== SCI_PORT_STOPPING
) {
1002 /* if the port is still stopping then the stop has not completed */
1003 isci_port_stop_complete(sci_port
->owning_controller
,
1005 SCI_FAILURE_TIMEOUT
);
1007 /* The port is in the ready state and we have a timer
1008 * reporting a timeout this should not happen.
1010 dev_err(sciport_to_dev(sci_port
),
1011 "%s: SCIC Port 0x%p is processing a timeout operation "
1012 "in state %d.\n", __func__
, sci_port
, current_state
);
1016 spin_unlock_irqrestore(&ihost
->scic_lock
, flags
);
1019 /* --------------------------------------------------------------------------- */
1022 * This function updates the hardwares VIIT entry for this port.
1026 static void scic_sds_port_update_viit_entry(struct scic_sds_port
*sci_port
)
1028 struct sci_sas_address sas_address
;
1030 scic_sds_port_get_sas_address(sci_port
, &sas_address
);
1032 writel(sas_address
.high
,
1033 &sci_port
->viit_registers
->initiator_sas_address_hi
);
1034 writel(sas_address
.low
,
1035 &sci_port
->viit_registers
->initiator_sas_address_lo
);
1037 /* This value get cleared just in case its not already cleared */
1038 writel(0, &sci_port
->viit_registers
->reserved
);
1040 /* We are required to update the status register last */
1041 writel(SCU_VIIT_ENTRY_ID_VIIT
|
1042 SCU_VIIT_IPPT_INITIATOR
|
1043 ((1 << sci_port
->physical_port_index
) << SCU_VIIT_ENTRY_LPVIE_SHIFT
) |
1044 SCU_VIIT_STATUS_ALL_VALID
,
1045 &sci_port
->viit_registers
->status
);
1049 * This method returns the maximum allowed speed for data transfers on this
1050 * port. This maximum allowed speed evaluates to the maximum speed of the
1051 * slowest phy in the port.
1052 * @sci_port: This parameter specifies the port for which to retrieve the
1053 * maximum allowed speed.
1055 * This method returns the maximum negotiated speed of the slowest phy in the
1058 enum sas_linkrate
scic_sds_port_get_max_allowed_speed(
1059 struct scic_sds_port
*sci_port
)
1062 enum sas_linkrate max_allowed_speed
= SAS_LINK_RATE_6_0_GBPS
;
1063 struct scic_sds_phy
*phy
= NULL
;
1066 * Loop through all of the phys in this port and find the phy with the
1067 * lowest maximum link rate. */
1068 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
1069 phy
= sci_port
->phy_table
[index
];
1072 && (scic_sds_port_active_phy(sci_port
, phy
) == true)
1073 && (phy
->max_negotiated_speed
< max_allowed_speed
)
1075 max_allowed_speed
= phy
->max_negotiated_speed
;
1078 return max_allowed_speed
;
1083 * @sci_port: This is the struct scic_sds_port object to suspend.
1085 * This method will susped the port task scheduler for this port object. none
1088 scic_sds_port_suspend_port_task_scheduler(struct scic_sds_port
*port
)
1090 u32 pts_control_value
;
1092 pts_control_value
= readl(&port
->port_task_scheduler_registers
->control
);
1093 pts_control_value
|= SCU_PTSxCR_GEN_BIT(SUSPEND
);
1094 writel(pts_control_value
, &port
->port_task_scheduler_registers
->control
);
1098 * scic_sds_port_post_dummy_request() - post dummy/workaround request
1099 * @sci_port: port to post task
1101 * Prevent the hardware scheduler from posting new requests to the front
1102 * of the scheduler queue causing a starvation problem for currently
1106 static void scic_sds_port_post_dummy_request(struct scic_sds_port
*sci_port
)
1108 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1109 u16 tag
= sci_port
->reserved_tag
;
1110 struct scu_task_context
*tc
;
1113 tc
= &scic
->task_context_table
[ISCI_TAG_TCI(tag
)];
1116 command
= SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC
|
1117 sci_port
->physical_port_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
|
1120 scic_sds_controller_post_request(scic
, command
);
1124 * This routine will abort the dummy request. This will alow the hardware to
1125 * power down parts of the silicon to save power.
1127 * @sci_port: The port on which the task must be aborted.
1130 static void scic_sds_port_abort_dummy_request(struct scic_sds_port
*sci_port
)
1132 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1133 u16 tag
= sci_port
->reserved_tag
;
1134 struct scu_task_context
*tc
;
1137 tc
= &scic
->task_context_table
[ISCI_TAG_TCI(tag
)];
1140 command
= SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT
|
1141 sci_port
->physical_port_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
|
1144 scic_sds_controller_post_request(scic
, command
);
1149 * @sci_port: This is the struct scic_sds_port object to resume.
1151 * This method will resume the port task scheduler for this port object. none
1154 scic_sds_port_resume_port_task_scheduler(struct scic_sds_port
*port
)
1156 u32 pts_control_value
;
1158 pts_control_value
= readl(&port
->port_task_scheduler_registers
->control
);
1159 pts_control_value
&= ~SCU_PTSxCR_GEN_BIT(SUSPEND
);
1160 writel(pts_control_value
, &port
->port_task_scheduler_registers
->control
);
1163 static void scic_sds_port_ready_substate_waiting_enter(struct sci_base_state_machine
*sm
)
1165 struct scic_sds_port
*sci_port
= container_of(sm
, typeof(*sci_port
), sm
);
1167 scic_sds_port_suspend_port_task_scheduler(sci_port
);
1169 sci_port
->not_ready_reason
= SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS
;
1171 if (sci_port
->active_phy_mask
!= 0) {
1172 /* At least one of the phys on the port is ready */
1173 port_state_machine_change(sci_port
,
1174 SCI_PORT_SUB_OPERATIONAL
);
1178 static void scic_sds_port_ready_substate_operational_enter(struct sci_base_state_machine
*sm
)
1181 struct scic_sds_port
*sci_port
= container_of(sm
, typeof(*sci_port
), sm
);
1182 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1183 struct isci_host
*ihost
= scic_to_ihost(scic
);
1184 struct isci_port
*iport
= sci_port_to_iport(sci_port
);
1186 isci_port_ready(ihost
, iport
);
1188 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
1189 if (sci_port
->phy_table
[index
]) {
1190 writel(sci_port
->physical_port_index
,
1191 &sci_port
->port_pe_configuration_register
[
1192 sci_port
->phy_table
[index
]->phy_index
]);
1196 scic_sds_port_update_viit_entry(sci_port
);
1198 scic_sds_port_resume_port_task_scheduler(sci_port
);
1201 * Post the dummy task for the port so the hardware can schedule
1204 scic_sds_port_post_dummy_request(sci_port
);
1207 static void scic_sds_port_invalidate_dummy_remote_node(struct scic_sds_port
*sci_port
)
1209 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1210 u8 phys_index
= sci_port
->physical_port_index
;
1211 union scu_remote_node_context
*rnc
;
1212 u16 rni
= sci_port
->reserved_rni
;
1215 rnc
= &scic
->remote_node_context_table
[rni
];
1217 rnc
->ssp
.is_valid
= false;
1219 /* ensure the preceding tc abort request has reached the
1220 * controller and give it ample time to act before posting the rnc
1223 readl(&scic
->smu_registers
->interrupt_status
); /* flush */
1226 command
= SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE
|
1227 phys_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
| rni
;
1229 scic_sds_controller_post_request(scic
, command
);
1234 * @object: This is the object which is cast to a struct scic_sds_port object.
1236 * This method will perform the actions required by the struct scic_sds_port on
1237 * exiting the SCI_PORT_SUB_OPERATIONAL. This function reports
1238 * the port not ready and suspends the port task scheduler. none
1240 static void scic_sds_port_ready_substate_operational_exit(struct sci_base_state_machine
*sm
)
1242 struct scic_sds_port
*sci_port
= container_of(sm
, typeof(*sci_port
), sm
);
1243 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1244 struct isci_host
*ihost
= scic_to_ihost(scic
);
1245 struct isci_port
*iport
= sci_port_to_iport(sci_port
);
1248 * Kill the dummy task for this port if it has not yet posted
1249 * the hardware will treat this as a NOP and just return abort
1252 scic_sds_port_abort_dummy_request(sci_port
);
1254 isci_port_not_ready(ihost
, iport
);
1256 if (sci_port
->ready_exit
)
1257 scic_sds_port_invalidate_dummy_remote_node(sci_port
);
1260 static void scic_sds_port_ready_substate_configuring_enter(struct sci_base_state_machine
*sm
)
1262 struct scic_sds_port
*sci_port
= container_of(sm
, typeof(*sci_port
), sm
);
1263 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1264 struct isci_host
*ihost
= scic_to_ihost(scic
);
1265 struct isci_port
*iport
= sci_port_to_iport(sci_port
);
1267 if (sci_port
->active_phy_mask
== 0) {
1268 isci_port_not_ready(ihost
, iport
);
1270 port_state_machine_change(sci_port
,
1271 SCI_PORT_SUB_WAITING
);
1272 } else if (sci_port
->started_request_count
== 0)
1273 port_state_machine_change(sci_port
,
1274 SCI_PORT_SUB_OPERATIONAL
);
1277 static void scic_sds_port_ready_substate_configuring_exit(struct sci_base_state_machine
*sm
)
1279 struct scic_sds_port
*sci_port
= container_of(sm
, typeof(*sci_port
), sm
);
1281 scic_sds_port_suspend_port_task_scheduler(sci_port
);
1282 if (sci_port
->ready_exit
)
1283 scic_sds_port_invalidate_dummy_remote_node(sci_port
);
1286 enum sci_status
scic_sds_port_start(struct scic_sds_port
*sci_port
)
1288 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1289 enum sci_status status
= SCI_SUCCESS
;
1290 enum scic_sds_port_states state
;
1293 state
= sci_port
->sm
.current_state_id
;
1294 if (state
!= SCI_PORT_STOPPED
) {
1295 dev_warn(sciport_to_dev(sci_port
),
1296 "%s: in wrong state: %d\n", __func__
, state
);
1297 return SCI_FAILURE_INVALID_STATE
;
1300 if (sci_port
->assigned_device_count
> 0) {
1301 /* TODO This is a start failure operation because
1302 * there are still devices assigned to this port.
1303 * There must be no devices assigned to a port on a
1306 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
;
1309 if (sci_port
->reserved_rni
== SCU_DUMMY_INDEX
) {
1310 u16 rni
= scic_sds_remote_node_table_allocate_remote_node(
1311 &scic
->available_remote_nodes
, 1);
1313 if (rni
!= SCU_DUMMY_INDEX
)
1314 scic_sds_port_construct_dummy_rnc(sci_port
, rni
);
1316 status
= SCI_FAILURE_INSUFFICIENT_RESOURCES
;
1317 sci_port
->reserved_rni
= rni
;
1320 if (sci_port
->reserved_tag
== SCI_CONTROLLER_INVALID_IO_TAG
) {
1321 struct isci_host
*ihost
= scic_to_ihost(scic
);
1324 tag
= isci_alloc_tag(ihost
);
1325 if (tag
== SCI_CONTROLLER_INVALID_IO_TAG
)
1326 status
= SCI_FAILURE_INSUFFICIENT_RESOURCES
;
1328 scic_sds_port_construct_dummy_task(sci_port
, tag
);
1329 sci_port
->reserved_tag
= tag
;
1332 if (status
== SCI_SUCCESS
) {
1333 phy_mask
= scic_sds_port_get_phys(sci_port
);
1336 * There are one or more phys assigned to this port. Make sure
1337 * the port's phy mask is in fact legal and supported by the
1340 if (scic_sds_port_is_phy_mask_valid(sci_port
, phy_mask
) == true) {
1341 port_state_machine_change(sci_port
,
1346 status
= SCI_FAILURE
;
1349 if (status
!= SCI_SUCCESS
)
1350 scic_sds_port_destroy_dummy_resources(sci_port
);
1355 enum sci_status
scic_sds_port_stop(struct scic_sds_port
*sci_port
)
1357 enum scic_sds_port_states state
;
1359 state
= sci_port
->sm
.current_state_id
;
1361 case SCI_PORT_STOPPED
:
1363 case SCI_PORT_SUB_WAITING
:
1364 case SCI_PORT_SUB_OPERATIONAL
:
1365 case SCI_PORT_SUB_CONFIGURING
:
1366 case SCI_PORT_RESETTING
:
1367 port_state_machine_change(sci_port
,
1371 dev_warn(sciport_to_dev(sci_port
),
1372 "%s: in wrong state: %d\n", __func__
, state
);
1373 return SCI_FAILURE_INVALID_STATE
;
1377 static enum sci_status
scic_port_hard_reset(struct scic_sds_port
*sci_port
, u32 timeout
)
1379 enum sci_status status
= SCI_FAILURE_INVALID_PHY
;
1380 struct scic_sds_phy
*selected_phy
= NULL
;
1381 enum scic_sds_port_states state
;
1384 state
= sci_port
->sm
.current_state_id
;
1385 if (state
!= SCI_PORT_SUB_OPERATIONAL
) {
1386 dev_warn(sciport_to_dev(sci_port
),
1387 "%s: in wrong state: %d\n", __func__
, state
);
1388 return SCI_FAILURE_INVALID_STATE
;
1391 /* Select a phy on which we can send the hard reset request. */
1392 for (phy_index
= 0; phy_index
< SCI_MAX_PHYS
&& !selected_phy
; phy_index
++) {
1393 selected_phy
= sci_port
->phy_table
[phy_index
];
1395 !scic_sds_port_active_phy(sci_port
, selected_phy
)) {
1397 * We found a phy but it is not ready select
1400 selected_phy
= NULL
;
1404 /* If we have a phy then go ahead and start the reset procedure */
1407 status
= scic_sds_phy_reset(selected_phy
);
1409 if (status
!= SCI_SUCCESS
)
1412 sci_mod_timer(&sci_port
->timer
, timeout
);
1413 sci_port
->not_ready_reason
= SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED
;
1415 port_state_machine_change(sci_port
,
1416 SCI_PORT_RESETTING
);
1421 * scic_sds_port_add_phy() -
1422 * @sci_port: This parameter specifies the port in which the phy will be added.
1423 * @sci_phy: This parameter is the phy which is to be added to the port.
1425 * This method will add a PHY to the selected port. This method returns an
1426 * enum sci_status. SCI_SUCCESS the phy has been added to the port. Any other
1427 * status is a failure to add the phy to the port.
1429 enum sci_status
scic_sds_port_add_phy(struct scic_sds_port
*sci_port
,
1430 struct scic_sds_phy
*sci_phy
)
1432 enum sci_status status
;
1433 enum scic_sds_port_states state
;
1435 state
= sci_port
->sm
.current_state_id
;
1437 case SCI_PORT_STOPPED
: {
1438 struct sci_sas_address port_sas_address
;
1440 /* Read the port assigned SAS Address if there is one */
1441 scic_sds_port_get_sas_address(sci_port
, &port_sas_address
);
1443 if (port_sas_address
.high
!= 0 && port_sas_address
.low
!= 0) {
1444 struct sci_sas_address phy_sas_address
;
1446 /* Make sure that the PHY SAS Address matches the SAS Address
1449 scic_sds_phy_get_sas_address(sci_phy
, &phy_sas_address
);
1451 if (port_sas_address
.high
!= phy_sas_address
.high
||
1452 port_sas_address
.low
!= phy_sas_address
.low
)
1453 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
;
1455 return scic_sds_port_set_phy(sci_port
, sci_phy
);
1457 case SCI_PORT_SUB_WAITING
:
1458 case SCI_PORT_SUB_OPERATIONAL
:
1459 status
= scic_sds_port_set_phy(sci_port
, sci_phy
);
1461 if (status
!= SCI_SUCCESS
)
1464 scic_sds_port_general_link_up_handler(sci_port
, sci_phy
, true);
1465 sci_port
->not_ready_reason
= SCIC_PORT_NOT_READY_RECONFIGURING
;
1466 port_state_machine_change(sci_port
, SCI_PORT_SUB_CONFIGURING
);
1469 case SCI_PORT_SUB_CONFIGURING
:
1470 status
= scic_sds_port_set_phy(sci_port
, sci_phy
);
1472 if (status
!= SCI_SUCCESS
)
1474 scic_sds_port_general_link_up_handler(sci_port
, sci_phy
, true);
1476 /* Re-enter the configuring state since this may be the last phy in
1479 port_state_machine_change(sci_port
,
1480 SCI_PORT_SUB_CONFIGURING
);
1483 dev_warn(sciport_to_dev(sci_port
),
1484 "%s: in wrong state: %d\n", __func__
, state
);
1485 return SCI_FAILURE_INVALID_STATE
;
1490 * scic_sds_port_remove_phy() -
1491 * @sci_port: This parameter specifies the port in which the phy will be added.
1492 * @sci_phy: This parameter is the phy which is to be added to the port.
1494 * This method will remove the PHY from the selected PORT. This method returns
1495 * an enum sci_status. SCI_SUCCESS the phy has been removed from the port. Any
1496 * other status is a failure to add the phy to the port.
1498 enum sci_status
scic_sds_port_remove_phy(struct scic_sds_port
*sci_port
,
1499 struct scic_sds_phy
*sci_phy
)
1501 enum sci_status status
;
1502 enum scic_sds_port_states state
;
1504 state
= sci_port
->sm
.current_state_id
;
1507 case SCI_PORT_STOPPED
:
1508 return scic_sds_port_clear_phy(sci_port
, sci_phy
);
1509 case SCI_PORT_SUB_OPERATIONAL
:
1510 status
= scic_sds_port_clear_phy(sci_port
, sci_phy
);
1511 if (status
!= SCI_SUCCESS
)
1514 scic_sds_port_deactivate_phy(sci_port
, sci_phy
, true);
1515 sci_port
->not_ready_reason
= SCIC_PORT_NOT_READY_RECONFIGURING
;
1516 port_state_machine_change(sci_port
,
1517 SCI_PORT_SUB_CONFIGURING
);
1519 case SCI_PORT_SUB_CONFIGURING
:
1520 status
= scic_sds_port_clear_phy(sci_port
, sci_phy
);
1522 if (status
!= SCI_SUCCESS
)
1524 scic_sds_port_deactivate_phy(sci_port
, sci_phy
, true);
1526 /* Re-enter the configuring state since this may be the last phy in
1529 port_state_machine_change(sci_port
,
1530 SCI_PORT_SUB_CONFIGURING
);
1533 dev_warn(sciport_to_dev(sci_port
),
1534 "%s: in wrong state: %d\n", __func__
, state
);
1535 return SCI_FAILURE_INVALID_STATE
;
1539 enum sci_status
scic_sds_port_link_up(struct scic_sds_port
*sci_port
,
1540 struct scic_sds_phy
*sci_phy
)
1542 enum scic_sds_port_states state
;
1544 state
= sci_port
->sm
.current_state_id
;
1546 case SCI_PORT_SUB_WAITING
:
1547 /* Since this is the first phy going link up for the port we
1548 * can just enable it and continue
1550 scic_sds_port_activate_phy(sci_port
, sci_phy
, true);
1552 port_state_machine_change(sci_port
,
1553 SCI_PORT_SUB_OPERATIONAL
);
1555 case SCI_PORT_SUB_OPERATIONAL
:
1556 scic_sds_port_general_link_up_handler(sci_port
, sci_phy
, true);
1558 case SCI_PORT_RESETTING
:
1559 /* TODO We should make sure that the phy that has gone
1560 * link up is the same one on which we sent the reset. It is
1561 * possible that the phy on which we sent the reset is not the
1562 * one that has gone link up and we want to make sure that
1563 * phy being reset comes back. Consider the case where a
1564 * reset is sent but before the hardware processes the reset it
1565 * get a link up on the port because of a hot plug event.
1566 * because of the reset request this phy will go link down
1567 * almost immediately.
1570 /* In the resetting state we don't notify the user regarding
1571 * link up and link down notifications.
1573 scic_sds_port_general_link_up_handler(sci_port
, sci_phy
, false);
1576 dev_warn(sciport_to_dev(sci_port
),
1577 "%s: in wrong state: %d\n", __func__
, state
);
1578 return SCI_FAILURE_INVALID_STATE
;
1582 enum sci_status
scic_sds_port_link_down(struct scic_sds_port
*sci_port
,
1583 struct scic_sds_phy
*sci_phy
)
1585 enum scic_sds_port_states state
;
1587 state
= sci_port
->sm
.current_state_id
;
1589 case SCI_PORT_SUB_OPERATIONAL
:
1590 scic_sds_port_deactivate_phy(sci_port
, sci_phy
, true);
1592 /* If there are no active phys left in the port, then
1593 * transition the port to the WAITING state until such time
1594 * as a phy goes link up
1596 if (sci_port
->active_phy_mask
== 0)
1597 port_state_machine_change(sci_port
,
1598 SCI_PORT_SUB_WAITING
);
1600 case SCI_PORT_RESETTING
:
1601 /* In the resetting state we don't notify the user regarding
1602 * link up and link down notifications. */
1603 scic_sds_port_deactivate_phy(sci_port
, sci_phy
, false);
1606 dev_warn(sciport_to_dev(sci_port
),
1607 "%s: in wrong state: %d\n", __func__
, state
);
1608 return SCI_FAILURE_INVALID_STATE
;
1612 enum sci_status
scic_sds_port_start_io(struct scic_sds_port
*sci_port
,
1613 struct scic_sds_remote_device
*sci_dev
,
1614 struct isci_request
*ireq
)
1616 enum scic_sds_port_states state
;
1618 state
= sci_port
->sm
.current_state_id
;
1620 case SCI_PORT_SUB_WAITING
:
1621 return SCI_FAILURE_INVALID_STATE
;
1622 case SCI_PORT_SUB_OPERATIONAL
:
1623 sci_port
->started_request_count
++;
1626 dev_warn(sciport_to_dev(sci_port
),
1627 "%s: in wrong state: %d\n", __func__
, state
);
1628 return SCI_FAILURE_INVALID_STATE
;
1632 enum sci_status
scic_sds_port_complete_io(struct scic_sds_port
*sci_port
,
1633 struct scic_sds_remote_device
*sci_dev
,
1634 struct isci_request
*ireq
)
1636 enum scic_sds_port_states state
;
1638 state
= sci_port
->sm
.current_state_id
;
1640 case SCI_PORT_STOPPED
:
1641 dev_warn(sciport_to_dev(sci_port
),
1642 "%s: in wrong state: %d\n", __func__
, state
);
1643 return SCI_FAILURE_INVALID_STATE
;
1644 case SCI_PORT_STOPPING
:
1645 scic_sds_port_decrement_request_count(sci_port
);
1647 if (sci_port
->started_request_count
== 0)
1648 port_state_machine_change(sci_port
,
1651 case SCI_PORT_READY
:
1652 case SCI_PORT_RESETTING
:
1653 case SCI_PORT_FAILED
:
1654 case SCI_PORT_SUB_WAITING
:
1655 case SCI_PORT_SUB_OPERATIONAL
:
1656 scic_sds_port_decrement_request_count(sci_port
);
1658 case SCI_PORT_SUB_CONFIGURING
:
1659 scic_sds_port_decrement_request_count(sci_port
);
1660 if (sci_port
->started_request_count
== 0) {
1661 port_state_machine_change(sci_port
,
1662 SCI_PORT_SUB_OPERATIONAL
);
1671 * @sci_port: This is the port object which to suspend.
1673 * This method will enable the SCU Port Task Scheduler for this port object but
1674 * will leave the port task scheduler in a suspended state. none
1677 scic_sds_port_enable_port_task_scheduler(struct scic_sds_port
*port
)
1679 u32 pts_control_value
;
1681 pts_control_value
= readl(&port
->port_task_scheduler_registers
->control
);
1682 pts_control_value
|= SCU_PTSxCR_GEN_BIT(ENABLE
) | SCU_PTSxCR_GEN_BIT(SUSPEND
);
1683 writel(pts_control_value
, &port
->port_task_scheduler_registers
->control
);
1688 * @sci_port: This is the port object which to resume.
1690 * This method will disable the SCU port task scheduler for this port object.
1694 scic_sds_port_disable_port_task_scheduler(struct scic_sds_port
*port
)
1696 u32 pts_control_value
;
1698 pts_control_value
= readl(&port
->port_task_scheduler_registers
->control
);
1699 pts_control_value
&=
1700 ~(SCU_PTSxCR_GEN_BIT(ENABLE
) | SCU_PTSxCR_GEN_BIT(SUSPEND
));
1701 writel(pts_control_value
, &port
->port_task_scheduler_registers
->control
);
1704 static void scic_sds_port_post_dummy_remote_node(struct scic_sds_port
*sci_port
)
1706 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1707 u8 phys_index
= sci_port
->physical_port_index
;
1708 union scu_remote_node_context
*rnc
;
1709 u16 rni
= sci_port
->reserved_rni
;
1712 rnc
= &scic
->remote_node_context_table
[rni
];
1713 rnc
->ssp
.is_valid
= true;
1715 command
= SCU_CONTEXT_COMMAND_POST_RNC_32
|
1716 phys_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
| rni
;
1718 scic_sds_controller_post_request(scic
, command
);
1720 /* ensure hardware has seen the post rnc command and give it
1721 * ample time to act before sending the suspend
1723 readl(&scic
->smu_registers
->interrupt_status
); /* flush */
1726 command
= SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX
|
1727 phys_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
| rni
;
1729 scic_sds_controller_post_request(scic
, command
);
1732 static void scic_sds_port_stopped_state_enter(struct sci_base_state_machine
*sm
)
1734 struct scic_sds_port
*sci_port
= container_of(sm
, typeof(*sci_port
), sm
);
1736 if (sci_port
->sm
.previous_state_id
== SCI_PORT_STOPPING
) {
1738 * If we enter this state becasuse of a request to stop
1739 * the port then we want to disable the hardwares port
1740 * task scheduler. */
1741 scic_sds_port_disable_port_task_scheduler(sci_port
);
1745 static void scic_sds_port_stopped_state_exit(struct sci_base_state_machine
*sm
)
1747 struct scic_sds_port
*sci_port
= container_of(sm
, typeof(*sci_port
), sm
);
1749 /* Enable and suspend the port task scheduler */
1750 scic_sds_port_enable_port_task_scheduler(sci_port
);
1753 static void scic_sds_port_ready_state_enter(struct sci_base_state_machine
*sm
)
1755 struct scic_sds_port
*sci_port
= container_of(sm
, typeof(*sci_port
), sm
);
1756 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1757 struct isci_host
*ihost
= scic_to_ihost(scic
);
1758 struct isci_port
*iport
= sci_port_to_iport(sci_port
);
1761 prev_state
= sci_port
->sm
.previous_state_id
;
1762 if (prev_state
== SCI_PORT_RESETTING
)
1763 isci_port_hard_reset_complete(iport
, SCI_SUCCESS
);
1765 isci_port_not_ready(ihost
, iport
);
1767 /* Post and suspend the dummy remote node context for this port. */
1768 scic_sds_port_post_dummy_remote_node(sci_port
);
1770 /* Start the ready substate machine */
1771 port_state_machine_change(sci_port
,
1772 SCI_PORT_SUB_WAITING
);
1775 static void scic_sds_port_resetting_state_exit(struct sci_base_state_machine
*sm
)
1777 struct scic_sds_port
*sci_port
= container_of(sm
, typeof(*sci_port
), sm
);
1779 sci_del_timer(&sci_port
->timer
);
1782 static void scic_sds_port_stopping_state_exit(struct sci_base_state_machine
*sm
)
1784 struct scic_sds_port
*sci_port
= container_of(sm
, typeof(*sci_port
), sm
);
1786 sci_del_timer(&sci_port
->timer
);
1788 scic_sds_port_destroy_dummy_resources(sci_port
);
1791 static void scic_sds_port_failed_state_enter(struct sci_base_state_machine
*sm
)
1793 struct scic_sds_port
*sci_port
= container_of(sm
, typeof(*sci_port
), sm
);
1794 struct isci_port
*iport
= sci_port_to_iport(sci_port
);
1796 isci_port_hard_reset_complete(iport
, SCI_FAILURE_TIMEOUT
);
1799 /* --------------------------------------------------------------------------- */
1801 static const struct sci_base_state scic_sds_port_state_table
[] = {
1802 [SCI_PORT_STOPPED
] = {
1803 .enter_state
= scic_sds_port_stopped_state_enter
,
1804 .exit_state
= scic_sds_port_stopped_state_exit
1806 [SCI_PORT_STOPPING
] = {
1807 .exit_state
= scic_sds_port_stopping_state_exit
1809 [SCI_PORT_READY
] = {
1810 .enter_state
= scic_sds_port_ready_state_enter
,
1812 [SCI_PORT_SUB_WAITING
] = {
1813 .enter_state
= scic_sds_port_ready_substate_waiting_enter
,
1815 [SCI_PORT_SUB_OPERATIONAL
] = {
1816 .enter_state
= scic_sds_port_ready_substate_operational_enter
,
1817 .exit_state
= scic_sds_port_ready_substate_operational_exit
1819 [SCI_PORT_SUB_CONFIGURING
] = {
1820 .enter_state
= scic_sds_port_ready_substate_configuring_enter
,
1821 .exit_state
= scic_sds_port_ready_substate_configuring_exit
1823 [SCI_PORT_RESETTING
] = {
1824 .exit_state
= scic_sds_port_resetting_state_exit
1826 [SCI_PORT_FAILED
] = {
1827 .enter_state
= scic_sds_port_failed_state_enter
,
1831 void scic_sds_port_construct(struct scic_sds_port
*sci_port
, u8 index
,
1832 struct scic_sds_controller
*scic
)
1834 sci_init_sm(&sci_port
->sm
, scic_sds_port_state_table
, SCI_PORT_STOPPED
);
1836 sci_port
->logical_port_index
= SCIC_SDS_DUMMY_PORT
;
1837 sci_port
->physical_port_index
= index
;
1838 sci_port
->active_phy_mask
= 0;
1839 sci_port
->ready_exit
= false;
1841 sci_port
->owning_controller
= scic
;
1843 sci_port
->started_request_count
= 0;
1844 sci_port
->assigned_device_count
= 0;
1846 sci_port
->reserved_rni
= SCU_DUMMY_INDEX
;
1847 sci_port
->reserved_tag
= SCI_CONTROLLER_INVALID_IO_TAG
;
1849 sci_init_timer(&sci_port
->timer
, port_timeout
);
1851 sci_port
->port_task_scheduler_registers
= NULL
;
1853 for (index
= 0; index
< SCI_MAX_PHYS
; index
++)
1854 sci_port
->phy_table
[index
] = NULL
;
1857 void isci_port_init(struct isci_port
*iport
, struct isci_host
*ihost
, int index
)
1859 INIT_LIST_HEAD(&iport
->remote_dev_list
);
1860 INIT_LIST_HEAD(&iport
->domain_dev_list
);
1861 spin_lock_init(&iport
->state_lock
);
1862 init_completion(&iport
->start_complete
);
1863 iport
->isci_host
= ihost
;
1864 isci_port_change_state(iport
, isci_freed
);
1865 atomic_set(&iport
->event
, 0);
1869 * isci_port_get_state() - This function gets the status of the port object.
1870 * @isci_port: This parameter points to the isci_port object
1872 * status of the object as a isci_status enum.
1874 enum isci_status
isci_port_get_state(
1875 struct isci_port
*isci_port
)
1877 return isci_port
->status
;
1880 void scic_sds_port_broadcast_change_received(
1881 struct scic_sds_port
*sci_port
,
1882 struct scic_sds_phy
*sci_phy
)
1884 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1885 struct isci_host
*ihost
= scic_to_ihost(scic
);
1887 /* notify the user. */
1888 isci_port_bc_change_received(ihost
, sci_port
, sci_phy
);
1891 int isci_port_perform_hard_reset(struct isci_host
*ihost
, struct isci_port
*iport
,
1892 struct isci_phy
*iphy
)
1894 unsigned long flags
;
1895 enum sci_status status
;
1896 int idx
, ret
= TMF_RESP_FUNC_COMPLETE
;
1898 dev_dbg(&ihost
->pdev
->dev
, "%s: iport = %p\n",
1901 init_completion(&iport
->hard_reset_complete
);
1903 spin_lock_irqsave(&ihost
->scic_lock
, flags
);
1905 #define ISCI_PORT_RESET_TIMEOUT SCIC_SDS_SIGNATURE_FIS_TIMEOUT
1906 status
= scic_port_hard_reset(&iport
->sci
, ISCI_PORT_RESET_TIMEOUT
);
1908 spin_unlock_irqrestore(&ihost
->scic_lock
, flags
);
1910 if (status
== SCI_SUCCESS
) {
1911 wait_for_completion(&iport
->hard_reset_complete
);
1913 dev_dbg(&ihost
->pdev
->dev
,
1914 "%s: iport = %p; hard reset completion\n",
1917 if (iport
->hard_reset_status
!= SCI_SUCCESS
)
1918 ret
= TMF_RESP_FUNC_FAILED
;
1920 ret
= TMF_RESP_FUNC_FAILED
;
1922 dev_err(&ihost
->pdev
->dev
,
1923 "%s: iport = %p; scic_port_hard_reset call"
1925 __func__
, iport
, status
);
1929 /* If the hard reset for the port has failed, consider this
1930 * the same as link failures on all phys in the port.
1932 if (ret
!= TMF_RESP_FUNC_COMPLETE
) {
1934 dev_err(&ihost
->pdev
->dev
,
1935 "%s: iport = %p; hard reset failed "
1936 "(0x%x) - driving explicit link fail for all phys\n",
1937 __func__
, iport
, iport
->hard_reset_status
);
1939 /* Down all phys in the port. */
1940 spin_lock_irqsave(&ihost
->scic_lock
, flags
);
1941 for (idx
= 0; idx
< SCI_MAX_PHYS
; ++idx
) {
1943 if (iport
->sci
.phy_table
[idx
] != NULL
) {
1946 iport
->sci
.phy_table
[idx
]);
1948 iport
->sci
.phy_table
[idx
]);
1951 spin_unlock_irqrestore(&ihost
->scic_lock
, flags
);
1957 * isci_port_deformed() - This function is called by libsas when a port becomes
1959 * @phy: This parameter specifies the libsas phy with the inactive port.
1962 void isci_port_deformed(struct asd_sas_phy
*phy
)
1964 pr_debug("%s: sas_phy = %p\n", __func__
, phy
);
1968 * isci_port_formed() - This function is called by libsas when a port becomes
1970 * @phy: This parameter specifies the libsas phy with the active port.
1973 void isci_port_formed(struct asd_sas_phy
*phy
)
1975 pr_debug("%s: sas_phy = %p, sas_port = %p\n", __func__
, phy
, phy
->port
);