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.
61 #define SCIC_SDS_PORT_HARD_RESET_TIMEOUT (1000)
62 #define SCU_DUMMY_INDEX (0xFFFF)
64 static void isci_port_change_state(struct isci_port
*iport
, enum isci_status status
)
68 dev_dbg(&iport
->isci_host
->pdev
->dev
,
69 "%s: iport = %p, state = 0x%x\n",
70 __func__
, iport
, status
);
72 /* XXX pointless lock */
73 spin_lock_irqsave(&iport
->state_lock
, flags
);
74 iport
->status
= status
;
75 spin_unlock_irqrestore(&iport
->state_lock
, flags
);
79 * This function will indicate which protocols are supported by this port.
80 * @sci_port: a handle corresponding to the SAS port for which to return the
81 * supported protocols.
82 * @protocols: This parameter specifies a pointer to a data structure
83 * which the core will copy the protocol values for the port from the
84 * transmit_identification register.
87 scic_sds_port_get_protocols(struct scic_sds_port
*sci_port
,
88 struct scic_phy_proto
*protocols
)
94 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
95 if (sci_port
->phy_table
[index
] != NULL
) {
96 scic_sds_phy_get_protocols(sci_port
->phy_table
[index
],
103 * This method requests a list (mask) of the phys contained in the supplied SAS
105 * @sci_port: a handle corresponding to the SAS port for which to return the
108 * Return a bit mask indicating which phys are a part of this port. Each bit
109 * corresponds to a phy identifier (e.g. bit 0 = phy id 0).
111 static u32
scic_sds_port_get_phys(struct scic_sds_port
*sci_port
)
118 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
119 if (sci_port
->phy_table
[index
] != NULL
) {
120 mask
|= (1 << index
);
128 * scic_port_get_properties() - This method simply returns the properties
129 * regarding the port, such as: physical index, protocols, sas address, etc.
130 * @port: this parameter specifies the port for which to retrieve the physical
132 * @properties: This parameter specifies the properties structure into which to
133 * copy the requested information.
135 * Indicate if the user specified a valid port. SCI_SUCCESS This value is
136 * returned if the specified port was valid. SCI_FAILURE_INVALID_PORT This
137 * value is returned if the specified port is not valid. When this value is
138 * returned, no data is copied to the properties output parameter.
140 static enum sci_status
scic_port_get_properties(struct scic_sds_port
*port
,
141 struct scic_port_properties
*prop
)
143 if ((port
== NULL
) ||
144 (port
->logical_port_index
== SCIC_SDS_DUMMY_PORT
))
145 return SCI_FAILURE_INVALID_PORT
;
147 prop
->index
= port
->logical_port_index
;
148 prop
->phy_mask
= scic_sds_port_get_phys(port
);
149 scic_sds_port_get_sas_address(port
, &prop
->local
.sas_address
);
150 scic_sds_port_get_protocols(port
, &prop
->local
.protocols
);
151 scic_sds_port_get_attached_sas_address(port
, &prop
->remote
.sas_address
);
156 static void isci_port_link_up(struct isci_host
*isci_host
,
157 struct scic_sds_port
*port
,
158 struct scic_sds_phy
*phy
)
161 struct scic_port_properties properties
;
162 struct isci_phy
*isci_phy
= sci_phy_to_iphy(phy
);
163 struct isci_port
*isci_port
= sci_port_to_iport(port
);
164 unsigned long success
= true;
166 BUG_ON(isci_phy
->isci_port
!= NULL
);
168 isci_phy
->isci_port
= isci_port
;
170 dev_dbg(&isci_host
->pdev
->dev
,
171 "%s: isci_port = %p\n",
172 __func__
, isci_port
);
174 spin_lock_irqsave(&isci_phy
->sas_phy
.frame_rcvd_lock
, flags
);
176 isci_port_change_state(isci_phy
->isci_port
, isci_starting
);
178 scic_port_get_properties(port
, &properties
);
180 if (phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SATA
) {
181 u64 attached_sas_address
;
183 isci_phy
->sas_phy
.oob_mode
= SATA_OOB_MODE
;
184 isci_phy
->sas_phy
.frame_rcvd_size
= sizeof(struct dev_to_host_fis
);
187 * For direct-attached SATA devices, the SCI core will
188 * automagically assign a SAS address to the end device
189 * for the purpose of creating a port. This SAS address
190 * will not be the same as assigned to the PHY and needs
191 * to be obtained from struct scic_port_properties properties.
193 attached_sas_address
= properties
.remote
.sas_address
.high
;
194 attached_sas_address
<<= 32;
195 attached_sas_address
|= properties
.remote
.sas_address
.low
;
196 swab64s(&attached_sas_address
);
198 memcpy(&isci_phy
->sas_phy
.attached_sas_addr
,
199 &attached_sas_address
, sizeof(attached_sas_address
));
200 } else if (phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SAS
) {
201 isci_phy
->sas_phy
.oob_mode
= SAS_OOB_MODE
;
202 isci_phy
->sas_phy
.frame_rcvd_size
= sizeof(struct sas_identify_frame
);
204 /* Copy the attached SAS address from the IAF */
205 memcpy(isci_phy
->sas_phy
.attached_sas_addr
,
206 isci_phy
->frame_rcvd
.iaf
.sas_addr
, SAS_ADDR_SIZE
);
208 dev_err(&isci_host
->pdev
->dev
, "%s: unkown target\n", __func__
);
212 isci_phy
->sas_phy
.phy
->negotiated_linkrate
= sci_phy_linkrate(phy
);
214 spin_unlock_irqrestore(&isci_phy
->sas_phy
.frame_rcvd_lock
, flags
);
216 /* Notify libsas that we have an address frame, if indeed
217 * we've found an SSP, SMP, or STP target */
219 isci_host
->sas_ha
.notify_port_event(&isci_phy
->sas_phy
,
225 * isci_port_link_down() - This function is called by the sci core when a link
227 * @isci_host: This parameter specifies the isci host object.
228 * @phy: This parameter specifies the isci phy with the active link.
229 * @port: This parameter specifies the isci port with the active link.
232 static void isci_port_link_down(struct isci_host
*isci_host
,
233 struct isci_phy
*isci_phy
,
234 struct isci_port
*isci_port
)
236 struct isci_remote_device
*isci_device
;
238 dev_dbg(&isci_host
->pdev
->dev
,
239 "%s: isci_port = %p\n", __func__
, isci_port
);
243 /* check to see if this is the last phy on this port. */
244 if (isci_phy
->sas_phy
.port
245 && isci_phy
->sas_phy
.port
->num_phys
== 1) {
247 /* change the state for all devices on this port.
248 * The next task sent to this device will be returned
249 * as SAS_TASK_UNDELIVERED, and the scsi mid layer
250 * will remove the target
252 list_for_each_entry(isci_device
,
253 &isci_port
->remote_dev_list
,
255 dev_dbg(&isci_host
->pdev
->dev
,
256 "%s: isci_device = %p\n",
257 __func__
, isci_device
);
258 isci_remote_device_change_state(isci_device
,
262 isci_port_change_state(isci_port
, isci_stopping
);
265 /* Notify libsas of the borken link, this will trigger calls to our
266 * isci_port_deformed and isci_dev_gone functions.
268 sas_phy_disconnected(&isci_phy
->sas_phy
);
269 isci_host
->sas_ha
.notify_phy_event(&isci_phy
->sas_phy
,
270 PHYE_LOSS_OF_SIGNAL
);
272 isci_phy
->isci_port
= NULL
;
274 dev_dbg(&isci_host
->pdev
->dev
,
275 "%s: isci_port = %p - Done\n", __func__
, isci_port
);
280 * isci_port_ready() - This function is called by the sci core when a link
282 * @isci_host: This parameter specifies the isci host object.
283 * @port: This parameter specifies the sci port with the active link.
286 static void isci_port_ready(struct isci_host
*isci_host
, struct isci_port
*isci_port
)
288 dev_dbg(&isci_host
->pdev
->dev
,
289 "%s: isci_port = %p\n", __func__
, isci_port
);
291 complete_all(&isci_port
->start_complete
);
292 isci_port_change_state(isci_port
, isci_ready
);
297 * isci_port_not_ready() - This function is called by the sci core when a link
298 * is not ready. All remote devices on this link will be removed if they are
299 * in the stopping state.
300 * @isci_host: This parameter specifies the isci host object.
301 * @port: This parameter specifies the sci port with the active link.
304 static void isci_port_not_ready(struct isci_host
*isci_host
, struct isci_port
*isci_port
)
306 dev_dbg(&isci_host
->pdev
->dev
,
307 "%s: isci_port = %p\n", __func__
, isci_port
);
310 static void isci_port_stop_complete(struct scic_sds_controller
*scic
,
311 struct scic_sds_port
*sci_port
,
312 enum sci_status completion_status
)
314 dev_dbg(&scic_to_ihost(scic
)->pdev
->dev
, "Port stop complete\n");
318 * isci_port_hard_reset_complete() - This function is called by the sci core
319 * when the hard reset complete notification has been received.
320 * @port: This parameter specifies the sci port with the active link.
321 * @completion_status: This parameter specifies the core status for the reset
325 static void isci_port_hard_reset_complete(struct isci_port
*isci_port
,
326 enum sci_status completion_status
)
328 dev_dbg(&isci_port
->isci_host
->pdev
->dev
,
329 "%s: isci_port = %p, completion_status=%x\n",
330 __func__
, isci_port
, completion_status
);
332 /* Save the status of the hard reset from the port. */
333 isci_port
->hard_reset_status
= completion_status
;
335 complete_all(&isci_port
->hard_reset_complete
);
338 /* This method will return a true value if the specified phy can be assigned to
339 * this port The following is a list of phys for each port that are allowed: -
340 * Port 0 - 3 2 1 0 - Port 1 - 1 - Port 2 - 3 2 - Port 3 - 3 This method
341 * doesn't preclude all configurations. It merely ensures that a phy is part
342 * of the allowable set of phy identifiers for that port. For example, one
343 * could assign phy 3 to port 0 and no other phys. Please refer to
344 * scic_sds_port_is_phy_mask_valid() for information regarding whether the
345 * phy_mask for a port can be supported. bool true if this is a valid phy
346 * assignment for the port false if this is not a valid phy assignment for the
349 bool scic_sds_port_is_valid_phy_assignment(struct scic_sds_port
*sci_port
,
352 /* Initialize to invalid value. */
353 u32 existing_phy_index
= SCI_MAX_PHYS
;
356 if ((sci_port
->physical_port_index
== 1) && (phy_index
!= 1)) {
360 if (sci_port
->physical_port_index
== 3 && phy_index
!= 3) {
365 (sci_port
->physical_port_index
== 2)
366 && ((phy_index
== 0) || (phy_index
== 1))
371 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
372 if ((sci_port
->phy_table
[index
] != NULL
)
373 && (index
!= phy_index
)) {
374 existing_phy_index
= index
;
379 * Ensure that all of the phys in the port are capable of
380 * operating at the same maximum link rate. */
382 (existing_phy_index
< SCI_MAX_PHYS
)
383 && (sci_port
->owning_controller
->user_parameters
.sds1
.phys
[
384 phy_index
].max_speed_generation
!=
385 sci_port
->owning_controller
->user_parameters
.sds1
.phys
[
386 existing_phy_index
].max_speed_generation
)
395 * @sci_port: This is the port object for which to determine if the phy mask
398 * This method will return a true value if the port's phy mask can be supported
399 * by the SCU. The following is a list of valid PHY mask configurations for
400 * each port: - Port 0 - [[3 2] 1] 0 - Port 1 - [1] - Port 2 - [[3] 2]
401 * - Port 3 - [3] This method returns a boolean indication specifying if the
402 * phy mask can be supported. true if this is a valid phy assignment for the
403 * port false if this is not a valid phy assignment for the port
405 static bool scic_sds_port_is_phy_mask_valid(
406 struct scic_sds_port
*sci_port
,
409 if (sci_port
->physical_port_index
== 0) {
410 if (((phy_mask
& 0x0F) == 0x0F)
411 || ((phy_mask
& 0x03) == 0x03)
412 || ((phy_mask
& 0x01) == 0x01)
415 } else if (sci_port
->physical_port_index
== 1) {
416 if (((phy_mask
& 0x02) == 0x02)
419 } else if (sci_port
->physical_port_index
== 2) {
420 if (((phy_mask
& 0x0C) == 0x0C)
421 || ((phy_mask
& 0x04) == 0x04)
424 } else if (sci_port
->physical_port_index
== 3) {
425 if (((phy_mask
& 0x08) == 0x08)
435 * @sci_port: This parameter specifies the port from which to return a
438 * This method retrieves a currently active (i.e. connected) phy contained in
439 * the port. Currently, the lowest order phy that is connected is returned.
440 * This method returns a pointer to a SCIS_SDS_PHY object. NULL This value is
441 * returned if there are no currently active (i.e. connected to a remote end
442 * point) phys contained in the port. All other values specify a struct scic_sds_phy
443 * object that is active in the port.
445 static struct scic_sds_phy
*scic_sds_port_get_a_connected_phy(
446 struct scic_sds_port
*sci_port
449 struct scic_sds_phy
*phy
;
451 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
453 * Ensure that the phy is both part of the port and currently
454 * connected to the remote end-point. */
455 phy
= sci_port
->phy_table
[index
];
458 && scic_sds_port_active_phy(sci_port
, phy
)
468 * scic_sds_port_set_phy() -
469 * @out]: port The port object to which the phy assignement is being made.
470 * @out]: phy The phy which is being assigned to the port.
472 * This method attempts to make the assignment of the phy to the port. If
473 * successful the phy is assigned to the ports phy table. bool true if the phy
474 * assignment can be made. false if the phy assignement can not be made. This
475 * is a functional test that only fails if the phy is currently assigned to a
478 static enum sci_status
scic_sds_port_set_phy(
479 struct scic_sds_port
*port
,
480 struct scic_sds_phy
*phy
)
483 * Check to see if we can add this phy to a port
484 * that means that the phy is not part of a port and that the port does
485 * not already have a phy assinged to the phy index. */
487 (port
->phy_table
[phy
->phy_index
] == NULL
)
488 && (phy_get_non_dummy_port(phy
) == NULL
)
489 && scic_sds_port_is_valid_phy_assignment(port
, phy
->phy_index
)
492 * Phy is being added in the stopped state so we are in MPC mode
493 * make logical port index = physical port index */
494 port
->logical_port_index
= port
->physical_port_index
;
495 port
->phy_table
[phy
->phy_index
] = phy
;
496 scic_sds_phy_set_port(phy
, port
);
505 * scic_sds_port_clear_phy() -
506 * @out]: port The port from which the phy is being cleared.
507 * @out]: phy The phy being cleared from the port.
509 * This method will clear the phy assigned to this port. This method fails if
510 * this phy is not currently assinged to this port. bool true if the phy is
511 * removed from the port. false if this phy is not assined to this port.
513 static enum sci_status
scic_sds_port_clear_phy(
514 struct scic_sds_port
*port
,
515 struct scic_sds_phy
*phy
)
517 /* Make sure that this phy is part of this port */
518 if (port
->phy_table
[phy
->phy_index
] == phy
&&
519 phy_get_non_dummy_port(phy
) == port
) {
520 struct scic_sds_controller
*scic
= port
->owning_controller
;
521 struct isci_host
*ihost
= scic_to_ihost(scic
);
523 /* Yep it is assigned to this port so remove it */
524 scic_sds_phy_set_port(phy
, &ihost
->ports
[SCI_MAX_PORTS
].sci
);
525 port
->phy_table
[phy
->phy_index
] = NULL
;
534 * This method requests the SAS address for the supplied SAS port from the SCI
536 * @sci_port: a handle corresponding to the SAS port for which to return the
538 * @sas_address: This parameter specifies a pointer to a SAS address structure
539 * into which the core will copy the SAS address for the port.
542 void scic_sds_port_get_sas_address(
543 struct scic_sds_port
*sci_port
,
544 struct sci_sas_address
*sas_address
)
548 sas_address
->high
= 0;
549 sas_address
->low
= 0;
551 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
552 if (sci_port
->phy_table
[index
] != NULL
) {
553 scic_sds_phy_get_sas_address(sci_port
->phy_table
[index
], sas_address
);
559 * This function requests the SAS address for the device directly attached to
561 * @sci_port: a handle corresponding to the SAS port for which to return the
563 * @sas_address: This parameter specifies a pointer to a SAS address structure
564 * into which the core will copy the SAS address for the device directly
565 * attached to the port.
568 void scic_sds_port_get_attached_sas_address(
569 struct scic_sds_port
*sci_port
,
570 struct sci_sas_address
*sas_address
)
572 struct scic_sds_phy
*sci_phy
;
575 * Ensure that the phy is both part of the port and currently
576 * connected to the remote end-point.
578 sci_phy
= scic_sds_port_get_a_connected_phy(sci_port
);
580 if (sci_phy
->protocol
!= SCIC_SDS_PHY_PROTOCOL_SATA
) {
581 scic_sds_phy_get_attached_sas_address(sci_phy
,
584 scic_sds_phy_get_sas_address(sci_phy
, sas_address
);
585 sas_address
->low
+= sci_phy
->phy_index
;
588 sas_address
->high
= 0;
589 sas_address
->low
= 0;
594 * scic_sds_port_construct_dummy_rnc() - create dummy rnc for si workaround
596 * @sci_port: logical port on which we need to create the remote node context
597 * @rni: remote node index for this remote node context.
599 * This routine will construct a dummy remote node context data structure
600 * This structure will be posted to the hardware to work around a scheduler
601 * error in the hardware.
603 static void scic_sds_port_construct_dummy_rnc(struct scic_sds_port
*sci_port
, u16 rni
)
605 union scu_remote_node_context
*rnc
;
607 rnc
= &sci_port
->owning_controller
->remote_node_context_table
[rni
];
609 memset(rnc
, 0, sizeof(union scu_remote_node_context
));
611 rnc
->ssp
.remote_sas_address_hi
= 0;
612 rnc
->ssp
.remote_sas_address_lo
= 0;
614 rnc
->ssp
.remote_node_index
= rni
;
615 rnc
->ssp
.remote_node_port_width
= 1;
616 rnc
->ssp
.logical_port_index
= sci_port
->physical_port_index
;
618 rnc
->ssp
.nexus_loss_timer_enable
= false;
619 rnc
->ssp
.check_bit
= false;
620 rnc
->ssp
.is_valid
= true;
621 rnc
->ssp
.is_remote_node_context
= true;
622 rnc
->ssp
.function_number
= 0;
623 rnc
->ssp
.arbitration_wait_time
= 0;
627 * scic_sds_port_construct_dummy_task() - create dummy task for si workaround
628 * @sci_port The logical port on which we need to create the
629 * remote node context.
631 * @tci The remote node index for this remote node context.
633 * This routine will construct a dummy task context data structure. This
634 * structure will be posted to the hardwre to work around a scheduler error
638 static void scic_sds_port_construct_dummy_task(struct scic_sds_port
*sci_port
, u16 tci
)
640 struct scu_task_context
*task_context
;
642 task_context
= scic_sds_controller_get_task_context_buffer(sci_port
->owning_controller
, tci
);
644 memset(task_context
, 0, sizeof(struct scu_task_context
));
646 task_context
->abort
= 0;
647 task_context
->priority
= 0;
648 task_context
->initiator_request
= 1;
649 task_context
->connection_rate
= 1;
650 task_context
->protocol_engine_index
= 0;
651 task_context
->logical_port_index
= sci_port
->physical_port_index
;
652 task_context
->protocol_type
= SCU_TASK_CONTEXT_PROTOCOL_SSP
;
653 task_context
->task_index
= scic_sds_io_tag_get_index(tci
);
654 task_context
->valid
= SCU_TASK_CONTEXT_VALID
;
655 task_context
->context_type
= SCU_TASK_CONTEXT_TYPE
;
657 task_context
->remote_node_index
= sci_port
->reserved_rni
;
658 task_context
->command_code
= 0;
660 task_context
->link_layer_control
= 0;
661 task_context
->do_not_dma_ssp_good_response
= 1;
662 task_context
->strict_ordering
= 0;
663 task_context
->control_frame
= 0;
664 task_context
->timeout_enable
= 0;
665 task_context
->block_guard_enable
= 0;
667 task_context
->address_modifier
= 0;
669 task_context
->task_phase
= 0x01;
672 static void scic_sds_port_destroy_dummy_resources(struct scic_sds_port
*sci_port
)
674 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
676 if (sci_port
->reserved_tci
!= SCU_DUMMY_INDEX
)
677 scic_controller_free_io_tag(scic
, sci_port
->reserved_tci
);
679 if (sci_port
->reserved_rni
!= SCU_DUMMY_INDEX
)
680 scic_sds_remote_node_table_release_remote_node_index(&scic
->available_remote_nodes
,
681 1, sci_port
->reserved_rni
);
683 sci_port
->reserved_rni
= SCU_DUMMY_INDEX
;
684 sci_port
->reserved_tci
= SCU_DUMMY_INDEX
;
688 * This method performs initialization of the supplied port. Initialization
689 * includes: - state machine initialization - member variable initialization
690 * - configuring the phy_mask
692 * @transport_layer_registers:
693 * @port_task_scheduler_registers:
694 * @port_configuration_regsiter:
696 * enum sci_status SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION This value is returned
697 * if the phy being added to the port
699 enum sci_status
scic_sds_port_initialize(
700 struct scic_sds_port
*sci_port
,
701 void __iomem
*port_task_scheduler_registers
,
702 void __iomem
*port_configuration_regsiter
,
703 void __iomem
*viit_registers
)
705 sci_port
->port_task_scheduler_registers
= port_task_scheduler_registers
;
706 sci_port
->port_pe_configuration_register
= port_configuration_regsiter
;
707 sci_port
->viit_registers
= viit_registers
;
714 * This method assigns the direct attached device ID for this port.
716 * @param[in] sci_port The port for which the direct attached device id is to
718 * @param[in] device_id The direct attached device ID to assign to the port.
719 * This will be the RNi for the device
721 void scic_sds_port_setup_transports(
722 struct scic_sds_port
*sci_port
,
727 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
728 if (sci_port
->active_phy_mask
& (1 << index
))
729 scic_sds_phy_setup_transport(sci_port
->phy_table
[index
], device_id
);
735 * @sci_port: This is the port on which the phy should be enabled.
736 * @sci_phy: This is the specific phy which to enable.
737 * @do_notify_user: This parameter specifies whether to inform the user (via
738 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
740 * This function will activate the phy in the port.
741 * Activation includes: - adding
742 * the phy to the port - enabling the Protocol Engine in the silicon. -
743 * notifying the user that the link is up. none
745 static void scic_sds_port_activate_phy(struct scic_sds_port
*sci_port
,
746 struct scic_sds_phy
*sci_phy
,
749 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
750 struct isci_host
*ihost
= scic_to_ihost(scic
);
752 if (sci_phy
->protocol
!= SCIC_SDS_PHY_PROTOCOL_SATA
)
753 scic_sds_phy_resume(sci_phy
);
755 sci_port
->active_phy_mask
|= 1 << sci_phy
->phy_index
;
757 scic_sds_controller_clear_invalid_phy(scic
, sci_phy
);
759 if (do_notify_user
== true)
760 isci_port_link_up(ihost
, sci_port
, sci_phy
);
763 void scic_sds_port_deactivate_phy(struct scic_sds_port
*sci_port
,
764 struct scic_sds_phy
*sci_phy
,
767 struct scic_sds_controller
*scic
= scic_sds_port_get_controller(sci_port
);
768 struct isci_port
*iport
= sci_port_to_iport(sci_port
);
769 struct isci_host
*ihost
= scic_to_ihost(scic
);
770 struct isci_phy
*iphy
= sci_phy_to_iphy(sci_phy
);
772 sci_port
->active_phy_mask
&= ~(1 << sci_phy
->phy_index
);
774 sci_phy
->max_negotiated_speed
= SAS_LINK_RATE_UNKNOWN
;
776 /* Re-assign the phy back to the LP as if it were a narrow port */
777 writel(sci_phy
->phy_index
,
778 &sci_port
->port_pe_configuration_register
[sci_phy
->phy_index
]);
780 if (do_notify_user
== true)
781 isci_port_link_down(ihost
, iphy
, iport
);
786 * @sci_port: This is the port on which the phy should be disabled.
787 * @sci_phy: This is the specific phy which to disabled.
789 * This function will disable the phy and report that the phy is not valid for
790 * this port object. None
792 static void scic_sds_port_invalid_link_up(struct scic_sds_port
*sci_port
,
793 struct scic_sds_phy
*sci_phy
)
795 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
798 * Check to see if we have alreay reported this link as bad and if
799 * not go ahead and tell the SCI_USER that we have discovered an
802 if ((scic
->invalid_phy_mask
& (1 << sci_phy
->phy_index
)) == 0) {
803 scic_sds_controller_set_invalid_phy(scic
, sci_phy
);
804 dev_warn(&scic_to_ihost(scic
)->pdev
->dev
, "Invalid link up!\n");
808 static bool is_port_ready_state(enum scic_sds_port_states state
)
811 case SCI_BASE_PORT_STATE_READY
:
812 case SCIC_SDS_PORT_READY_SUBSTATE_WAITING
:
813 case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
:
814 case SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
:
821 /* flag dummy rnc hanling when exiting a ready state */
822 static void port_state_machine_change(struct scic_sds_port
*sci_port
,
823 enum scic_sds_port_states state
)
825 struct sci_base_state_machine
*sm
= &sci_port
->state_machine
;
826 enum scic_sds_port_states old_state
= sm
->current_state_id
;
828 if (is_port_ready_state(old_state
) && !is_port_ready_state(state
))
829 sci_port
->ready_exit
= true;
831 sci_base_state_machine_change_state(sm
, state
);
832 sci_port
->ready_exit
= false;
836 * scic_sds_port_general_link_up_handler - phy can be assigned to port?
837 * @sci_port: scic_sds_port object for which has a phy that has gone link up.
838 * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
839 * @do_notify_user: This parameter specifies whether to inform the user (via
840 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
842 * Determine if this phy can be assigned to this
843 * port . If the phy is not a valid PHY for
844 * this port then the function will notify the user. A PHY can only be
845 * part of a port if it's attached SAS ADDRESS is the same as all other PHYs in
846 * the same port. none
848 static void scic_sds_port_general_link_up_handler(struct scic_sds_port
*sci_port
,
849 struct scic_sds_phy
*sci_phy
,
852 struct sci_sas_address port_sas_address
;
853 struct sci_sas_address phy_sas_address
;
855 scic_sds_port_get_attached_sas_address(sci_port
, &port_sas_address
);
856 scic_sds_phy_get_attached_sas_address(sci_phy
, &phy_sas_address
);
858 /* If the SAS address of the new phy matches the SAS address of
859 * other phys in the port OR this is the first phy in the port,
860 * then activate the phy and allow it to be used for operations
863 if ((phy_sas_address
.high
== port_sas_address
.high
&&
864 phy_sas_address
.low
== port_sas_address
.low
) ||
865 sci_port
->active_phy_mask
== 0) {
866 struct sci_base_state_machine
*sm
= &sci_port
->state_machine
;
868 scic_sds_port_activate_phy(sci_port
, sci_phy
, do_notify_user
);
869 if (sm
->current_state_id
== SCI_BASE_PORT_STATE_RESETTING
)
870 port_state_machine_change(sci_port
, SCI_BASE_PORT_STATE_READY
);
872 scic_sds_port_invalid_link_up(sci_port
, sci_phy
);
878 * This method returns false if the port only has a single phy object assigned.
879 * If there are no phys or more than one phy then the method will return
881 * @sci_port: The port for which the wide port condition is to be checked.
883 * bool true Is returned if this is a wide ported port. false Is returned if
884 * this is a narrow port.
886 static bool scic_sds_port_is_wide(struct scic_sds_port
*sci_port
)
891 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
892 if (sci_port
->phy_table
[index
] != NULL
) {
897 return phy_count
!= 1;
901 * This method is called by the PHY object when the link is detected. if the
902 * port wants the PHY to continue on to the link up state then the port
903 * layer must return true. If the port object returns false the phy object
904 * must halt its attempt to go link up.
905 * @sci_port: The port associated with the phy object.
906 * @sci_phy: The phy object that is trying to go link up.
908 * true if the phy object can continue to the link up condition. true Is
909 * returned if this phy can continue to the ready state. false Is returned if
910 * can not continue on to the ready state. This notification is in place for
911 * wide ports and direct attached phys. Since there are no wide ported SATA
912 * devices this could become an invalid port configuration.
914 bool scic_sds_port_link_detected(
915 struct scic_sds_port
*sci_port
,
916 struct scic_sds_phy
*sci_phy
)
918 if ((sci_port
->logical_port_index
!= SCIC_SDS_DUMMY_PORT
) &&
919 (sci_phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SATA
) &&
920 scic_sds_port_is_wide(sci_port
)) {
921 scic_sds_port_invalid_link_up(sci_port
, sci_phy
);
930 * This method is provided to timeout requests for port operations. Mostly its
931 * for the port reset operation.
935 static void scic_sds_port_timeout_handler(void *port
)
937 struct scic_sds_port
*sci_port
= port
;
940 current_state
= sci_base_state_machine_get_state(&sci_port
->state_machine
);
942 if (current_state
== SCI_BASE_PORT_STATE_RESETTING
) {
943 /* if the port is still in the resetting state then the timeout
944 * fired before the reset completed.
946 port_state_machine_change(sci_port
, SCI_BASE_PORT_STATE_FAILED
);
947 } else if (current_state
== SCI_BASE_PORT_STATE_STOPPED
) {
948 /* if the port is stopped then the start request failed In this
949 * case stay in the stopped state.
951 dev_err(sciport_to_dev(sci_port
),
952 "%s: SCIC Port 0x%p failed to stop before tiemout.\n",
955 } else if (current_state
== SCI_BASE_PORT_STATE_STOPPING
) {
956 /* if the port is still stopping then the stop has not completed */
957 isci_port_stop_complete(sci_port
->owning_controller
,
959 SCI_FAILURE_TIMEOUT
);
961 /* The port is in the ready state and we have a timer
962 * reporting a timeout this should not happen.
964 dev_err(sciport_to_dev(sci_port
),
965 "%s: SCIC Port 0x%p is processing a timeout operation "
966 "in state %d.\n", __func__
, sci_port
, current_state
);
970 /* --------------------------------------------------------------------------- */
973 * This function updates the hardwares VIIT entry for this port.
977 static void scic_sds_port_update_viit_entry(struct scic_sds_port
*sci_port
)
979 struct sci_sas_address sas_address
;
981 scic_sds_port_get_sas_address(sci_port
, &sas_address
);
983 writel(sas_address
.high
,
984 &sci_port
->viit_registers
->initiator_sas_address_hi
);
985 writel(sas_address
.low
,
986 &sci_port
->viit_registers
->initiator_sas_address_lo
);
988 /* This value get cleared just in case its not already cleared */
989 writel(0, &sci_port
->viit_registers
->reserved
);
991 /* We are required to update the status register last */
992 writel(SCU_VIIT_ENTRY_ID_VIIT
|
993 SCU_VIIT_IPPT_INITIATOR
|
994 ((1 << sci_port
->physical_port_index
) << SCU_VIIT_ENTRY_LPVIE_SHIFT
) |
995 SCU_VIIT_STATUS_ALL_VALID
,
996 &sci_port
->viit_registers
->status
);
1000 * This method returns the maximum allowed speed for data transfers on this
1001 * port. This maximum allowed speed evaluates to the maximum speed of the
1002 * slowest phy in the port.
1003 * @sci_port: This parameter specifies the port for which to retrieve the
1004 * maximum allowed speed.
1006 * This method returns the maximum negotiated speed of the slowest phy in the
1009 enum sas_linkrate
scic_sds_port_get_max_allowed_speed(
1010 struct scic_sds_port
*sci_port
)
1013 enum sas_linkrate max_allowed_speed
= SAS_LINK_RATE_6_0_GBPS
;
1014 struct scic_sds_phy
*phy
= NULL
;
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 phy
= sci_port
->phy_table
[index
];
1023 && (scic_sds_port_active_phy(sci_port
, phy
) == true)
1024 && (phy
->max_negotiated_speed
< max_allowed_speed
)
1026 max_allowed_speed
= phy
->max_negotiated_speed
;
1029 return max_allowed_speed
;
1032 static void scic_port_enable_broadcast_change_notification(struct scic_sds_port
*port
)
1034 struct scic_sds_phy
*phy
;
1038 /* Loop through all of the phys to enable BCN. */
1039 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
1040 phy
= port
->phy_table
[index
];
1043 readl(&phy
->link_layer_registers
->link_layer_control
);
1045 /* clear the bit by writing 1. */
1046 writel(register_value
,
1047 &phy
->link_layer_registers
->link_layer_control
);
1054 * @sci_port: This is the struct scic_sds_port object to suspend.
1056 * This method will susped the port task scheduler for this port object. none
1059 scic_sds_port_suspend_port_task_scheduler(struct scic_sds_port
*port
)
1061 u32 pts_control_value
;
1063 pts_control_value
= readl(&port
->port_task_scheduler_registers
->control
);
1064 pts_control_value
|= SCU_PTSxCR_GEN_BIT(SUSPEND
);
1065 writel(pts_control_value
, &port
->port_task_scheduler_registers
->control
);
1069 * scic_sds_port_post_dummy_request() - post dummy/workaround request
1070 * @sci_port: port to post task
1072 * Prevent the hardware scheduler from posting new requests to the front
1073 * of the scheduler queue causing a starvation problem for currently
1077 static void scic_sds_port_post_dummy_request(struct scic_sds_port
*sci_port
)
1080 struct scu_task_context
*task_context
;
1081 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1082 u16 tci
= sci_port
->reserved_tci
;
1084 task_context
= scic_sds_controller_get_task_context_buffer(scic
, tci
);
1086 task_context
->abort
= 0;
1088 command
= SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC
|
1089 sci_port
->physical_port_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
|
1092 scic_sds_controller_post_request(scic
, command
);
1096 * This routine will abort the dummy request. This will alow the hardware to
1097 * power down parts of the silicon to save power.
1099 * @sci_port: The port on which the task must be aborted.
1102 static void scic_sds_port_abort_dummy_request(struct scic_sds_port
*sci_port
)
1104 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1105 u16 tci
= sci_port
->reserved_tci
;
1106 struct scu_task_context
*tc
;
1109 tc
= scic_sds_controller_get_task_context_buffer(scic
, tci
);
1113 command
= SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT
|
1114 sci_port
->physical_port_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
|
1117 scic_sds_controller_post_request(scic
, command
);
1122 * @sci_port: This is the struct scic_sds_port object to resume.
1124 * This method will resume the port task scheduler for this port object. none
1127 scic_sds_port_resume_port_task_scheduler(struct scic_sds_port
*port
)
1129 u32 pts_control_value
;
1131 pts_control_value
= readl(&port
->port_task_scheduler_registers
->control
);
1132 pts_control_value
&= ~SCU_PTSxCR_GEN_BIT(SUSPEND
);
1133 writel(pts_control_value
, &port
->port_task_scheduler_registers
->control
);
1136 static void scic_sds_port_ready_substate_waiting_enter(void *object
)
1138 struct scic_sds_port
*sci_port
= object
;
1140 scic_sds_port_suspend_port_task_scheduler(sci_port
);
1142 sci_port
->not_ready_reason
= SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS
;
1144 if (sci_port
->active_phy_mask
!= 0) {
1145 /* At least one of the phys on the port is ready */
1146 port_state_machine_change(sci_port
,
1147 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
);
1151 static void scic_sds_port_ready_substate_operational_enter(void *object
)
1154 struct scic_sds_port
*sci_port
= object
;
1155 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1156 struct isci_host
*ihost
= scic_to_ihost(scic
);
1157 struct isci_port
*iport
= sci_port_to_iport(sci_port
);
1159 isci_port_ready(ihost
, iport
);
1161 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
1162 if (sci_port
->phy_table
[index
]) {
1163 writel(sci_port
->physical_port_index
,
1164 &sci_port
->port_pe_configuration_register
[
1165 sci_port
->phy_table
[index
]->phy_index
]);
1169 scic_sds_port_update_viit_entry(sci_port
);
1171 scic_sds_port_resume_port_task_scheduler(sci_port
);
1174 * Post the dummy task for the port so the hardware can schedule
1177 scic_sds_port_post_dummy_request(sci_port
);
1180 static void scic_sds_port_invalidate_dummy_remote_node(struct scic_sds_port
*sci_port
)
1182 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1183 u8 phys_index
= sci_port
->physical_port_index
;
1184 union scu_remote_node_context
*rnc
;
1185 u16 rni
= sci_port
->reserved_rni
;
1188 rnc
= &scic
->remote_node_context_table
[rni
];
1190 rnc
->ssp
.is_valid
= false;
1192 /* ensure the preceding tc abort request has reached the
1193 * controller and give it ample time to act before posting the rnc
1196 readl(&scic
->smu_registers
->interrupt_status
); /* flush */
1199 command
= SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE
|
1200 phys_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
| rni
;
1202 scic_sds_controller_post_request(scic
, command
);
1207 * @object: This is the object which is cast to a struct scic_sds_port object.
1209 * This method will perform the actions required by the struct scic_sds_port on
1210 * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
1211 * the port not ready and suspends the port task scheduler. none
1213 static void scic_sds_port_ready_substate_operational_exit(void *object
)
1215 struct scic_sds_port
*sci_port
= object
;
1216 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1217 struct isci_host
*ihost
= scic_to_ihost(scic
);
1218 struct isci_port
*iport
= sci_port_to_iport(sci_port
);
1221 * Kill the dummy task for this port if it has not yet posted
1222 * the hardware will treat this as a NOP and just return abort
1225 scic_sds_port_abort_dummy_request(sci_port
);
1227 isci_port_not_ready(ihost
, iport
);
1229 if (sci_port
->ready_exit
)
1230 scic_sds_port_invalidate_dummy_remote_node(sci_port
);
1233 static void scic_sds_port_ready_substate_configuring_enter(void *object
)
1235 struct scic_sds_port
*sci_port
= object
;
1236 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1237 struct isci_host
*ihost
= scic_to_ihost(scic
);
1238 struct isci_port
*iport
= sci_port_to_iport(sci_port
);
1240 if (sci_port
->active_phy_mask
== 0) {
1241 isci_port_not_ready(ihost
, iport
);
1243 port_state_machine_change(sci_port
,
1244 SCIC_SDS_PORT_READY_SUBSTATE_WAITING
);
1245 } else if (sci_port
->started_request_count
== 0)
1246 port_state_machine_change(sci_port
,
1247 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
);
1250 static void scic_sds_port_ready_substate_configuring_exit(void *object
)
1252 struct scic_sds_port
*sci_port
= object
;
1254 scic_sds_port_suspend_port_task_scheduler(sci_port
);
1255 if (sci_port
->ready_exit
)
1256 scic_sds_port_invalidate_dummy_remote_node(sci_port
);
1259 enum sci_status
scic_sds_port_start(struct scic_sds_port
*sci_port
)
1261 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1262 struct isci_host
*ihost
= scic_to_ihost(scic
);
1263 enum sci_status status
= SCI_SUCCESS
;
1264 enum scic_sds_port_states state
;
1267 state
= sci_port
->state_machine
.current_state_id
;
1268 if (state
!= SCI_BASE_PORT_STATE_STOPPED
) {
1269 dev_warn(sciport_to_dev(sci_port
),
1270 "%s: in wrong state: %d\n", __func__
, state
);
1271 return SCI_FAILURE_INVALID_STATE
;
1274 if (sci_port
->assigned_device_count
> 0) {
1275 /* TODO This is a start failure operation because
1276 * there are still devices assigned to this port.
1277 * There must be no devices assigned to a port on a
1280 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
;
1283 sci_port
->timer_handle
=
1284 isci_timer_create(ihost
,
1286 scic_sds_port_timeout_handler
);
1288 if (!sci_port
->timer_handle
)
1289 return SCI_FAILURE_INSUFFICIENT_RESOURCES
;
1291 if (sci_port
->reserved_rni
== SCU_DUMMY_INDEX
) {
1292 u16 rni
= scic_sds_remote_node_table_allocate_remote_node(
1293 &scic
->available_remote_nodes
, 1);
1295 if (rni
!= SCU_DUMMY_INDEX
)
1296 scic_sds_port_construct_dummy_rnc(sci_port
, rni
);
1298 status
= SCI_FAILURE_INSUFFICIENT_RESOURCES
;
1299 sci_port
->reserved_rni
= rni
;
1302 if (sci_port
->reserved_tci
== SCU_DUMMY_INDEX
) {
1303 /* Allocate a TCI and remove the sequence nibble */
1304 u16 tci
= scic_controller_allocate_io_tag(scic
);
1306 if (tci
!= SCU_DUMMY_INDEX
)
1307 scic_sds_port_construct_dummy_task(sci_port
, tci
);
1309 status
= SCI_FAILURE_INSUFFICIENT_RESOURCES
;
1310 sci_port
->reserved_tci
= tci
;
1313 if (status
== SCI_SUCCESS
) {
1314 phy_mask
= scic_sds_port_get_phys(sci_port
);
1317 * There are one or more phys assigned to this port. Make sure
1318 * the port's phy mask is in fact legal and supported by the
1321 if (scic_sds_port_is_phy_mask_valid(sci_port
, phy_mask
) == true) {
1322 port_state_machine_change(sci_port
,
1323 SCI_BASE_PORT_STATE_READY
);
1327 status
= SCI_FAILURE
;
1330 if (status
!= SCI_SUCCESS
)
1331 scic_sds_port_destroy_dummy_resources(sci_port
);
1336 enum sci_status
scic_sds_port_stop(struct scic_sds_port
*sci_port
)
1338 enum scic_sds_port_states state
;
1340 state
= sci_port
->state_machine
.current_state_id
;
1342 case SCI_BASE_PORT_STATE_STOPPED
:
1344 case SCIC_SDS_PORT_READY_SUBSTATE_WAITING
:
1345 case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
:
1346 case SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
:
1347 case SCI_BASE_PORT_STATE_RESETTING
:
1348 port_state_machine_change(sci_port
,
1349 SCI_BASE_PORT_STATE_STOPPING
);
1352 dev_warn(sciport_to_dev(sci_port
),
1353 "%s: in wrong state: %d\n", __func__
, state
);
1354 return SCI_FAILURE_INVALID_STATE
;
1358 static enum sci_status
scic_port_hard_reset(struct scic_sds_port
*sci_port
, u32 timeout
)
1360 enum sci_status status
= SCI_FAILURE_INVALID_PHY
;
1361 struct scic_sds_phy
*selected_phy
= NULL
;
1362 enum scic_sds_port_states state
;
1365 state
= sci_port
->state_machine
.current_state_id
;
1366 if (state
!= SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
) {
1367 dev_warn(sciport_to_dev(sci_port
),
1368 "%s: in wrong state: %d\n", __func__
, state
);
1369 return SCI_FAILURE_INVALID_STATE
;
1372 /* Select a phy on which we can send the hard reset request. */
1373 for (phy_index
= 0; phy_index
< SCI_MAX_PHYS
&& !selected_phy
; phy_index
++) {
1374 selected_phy
= sci_port
->phy_table
[phy_index
];
1376 !scic_sds_port_active_phy(sci_port
, selected_phy
)) {
1378 * We found a phy but it is not ready select
1381 selected_phy
= NULL
;
1385 /* If we have a phy then go ahead and start the reset procedure */
1388 status
= scic_sds_phy_reset(selected_phy
);
1390 if (status
!= SCI_SUCCESS
)
1393 isci_timer_start(sci_port
->timer_handle
, timeout
);
1394 sci_port
->not_ready_reason
= SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED
;
1396 port_state_machine_change(sci_port
,
1397 SCI_BASE_PORT_STATE_RESETTING
);
1402 * scic_sds_port_add_phy() -
1403 * @sci_port: This parameter specifies the port in which the phy will be added.
1404 * @sci_phy: This parameter is the phy which is to be added to the port.
1406 * This method will add a PHY to the selected port. This method returns an
1407 * enum sci_status. SCI_SUCCESS the phy has been added to the port. Any other
1408 * status is a failure to add the phy to the port.
1410 enum sci_status
scic_sds_port_add_phy(struct scic_sds_port
*sci_port
,
1411 struct scic_sds_phy
*sci_phy
)
1413 enum sci_status status
;
1414 enum scic_sds_port_states state
;
1416 state
= sci_port
->state_machine
.current_state_id
;
1418 case SCI_BASE_PORT_STATE_STOPPED
: {
1419 struct sci_sas_address port_sas_address
;
1421 /* Read the port assigned SAS Address if there is one */
1422 scic_sds_port_get_sas_address(sci_port
, &port_sas_address
);
1424 if (port_sas_address
.high
!= 0 && port_sas_address
.low
!= 0) {
1425 struct sci_sas_address phy_sas_address
;
1427 /* Make sure that the PHY SAS Address matches the SAS Address
1430 scic_sds_phy_get_sas_address(sci_phy
, &phy_sas_address
);
1432 if (port_sas_address
.high
!= phy_sas_address
.high
||
1433 port_sas_address
.low
!= phy_sas_address
.low
)
1434 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
;
1436 return scic_sds_port_set_phy(sci_port
, sci_phy
);
1438 case SCIC_SDS_PORT_READY_SUBSTATE_WAITING
:
1439 case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
:
1440 status
= scic_sds_port_set_phy(sci_port
, sci_phy
);
1442 if (status
!= SCI_SUCCESS
)
1445 scic_sds_port_general_link_up_handler(sci_port
, sci_phy
, true);
1446 sci_port
->not_ready_reason
= SCIC_PORT_NOT_READY_RECONFIGURING
;
1447 port_state_machine_change(sci_port
, SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
);
1450 case SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
:
1451 status
= scic_sds_port_set_phy(sci_port
, sci_phy
);
1453 if (status
!= SCI_SUCCESS
)
1455 scic_sds_port_general_link_up_handler(sci_port
, sci_phy
, true);
1457 /* Re-enter the configuring state since this may be the last phy in
1460 port_state_machine_change(sci_port
,
1461 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
);
1464 dev_warn(sciport_to_dev(sci_port
),
1465 "%s: in wrong state: %d\n", __func__
, state
);
1466 return SCI_FAILURE_INVALID_STATE
;
1471 * scic_sds_port_remove_phy() -
1472 * @sci_port: This parameter specifies the port in which the phy will be added.
1473 * @sci_phy: This parameter is the phy which is to be added to the port.
1475 * This method will remove the PHY from the selected PORT. This method returns
1476 * an enum sci_status. SCI_SUCCESS the phy has been removed from the port. Any
1477 * other status is a failure to add the phy to the port.
1479 enum sci_status
scic_sds_port_remove_phy(struct scic_sds_port
*sci_port
,
1480 struct scic_sds_phy
*sci_phy
)
1482 enum sci_status status
;
1483 enum scic_sds_port_states state
;
1485 state
= sci_port
->state_machine
.current_state_id
;
1488 case SCI_BASE_PORT_STATE_STOPPED
:
1489 return scic_sds_port_clear_phy(sci_port
, sci_phy
);
1490 case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
:
1491 status
= scic_sds_port_clear_phy(sci_port
, sci_phy
);
1492 if (status
!= SCI_SUCCESS
)
1495 scic_sds_port_deactivate_phy(sci_port
, sci_phy
, true);
1496 sci_port
->not_ready_reason
= SCIC_PORT_NOT_READY_RECONFIGURING
;
1497 port_state_machine_change(sci_port
,
1498 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
);
1500 case SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
:
1501 status
= scic_sds_port_clear_phy(sci_port
, sci_phy
);
1503 if (status
!= SCI_SUCCESS
)
1505 scic_sds_port_deactivate_phy(sci_port
, sci_phy
, true);
1507 /* Re-enter the configuring state since this may be the last phy in
1510 port_state_machine_change(sci_port
,
1511 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
);
1514 dev_warn(sciport_to_dev(sci_port
),
1515 "%s: in wrong state: %d\n", __func__
, state
);
1516 return SCI_FAILURE_INVALID_STATE
;
1520 enum sci_status
scic_sds_port_link_up(struct scic_sds_port
*sci_port
,
1521 struct scic_sds_phy
*sci_phy
)
1523 enum scic_sds_port_states state
;
1525 state
= sci_port
->state_machine
.current_state_id
;
1527 case SCIC_SDS_PORT_READY_SUBSTATE_WAITING
:
1528 /* Since this is the first phy going link up for the port we
1529 * can just enable it and continue
1531 scic_sds_port_activate_phy(sci_port
, sci_phy
, true);
1533 port_state_machine_change(sci_port
,
1534 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
);
1536 case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
:
1537 scic_sds_port_general_link_up_handler(sci_port
, sci_phy
, true);
1539 case SCI_BASE_PORT_STATE_RESETTING
:
1540 /* TODO We should make sure that the phy that has gone
1541 * link up is the same one on which we sent the reset. It is
1542 * possible that the phy on which we sent the reset is not the
1543 * one that has gone link up and we want to make sure that
1544 * phy being reset comes back. Consider the case where a
1545 * reset is sent but before the hardware processes the reset it
1546 * get a link up on the port because of a hot plug event.
1547 * because of the reset request this phy will go link down
1548 * almost immediately.
1551 /* In the resetting state we don't notify the user regarding
1552 * link up and link down notifications.
1554 scic_sds_port_general_link_up_handler(sci_port
, sci_phy
, false);
1557 dev_warn(sciport_to_dev(sci_port
),
1558 "%s: in wrong state: %d\n", __func__
, state
);
1559 return SCI_FAILURE_INVALID_STATE
;
1563 enum sci_status
scic_sds_port_link_down(struct scic_sds_port
*sci_port
,
1564 struct scic_sds_phy
*sci_phy
)
1566 enum scic_sds_port_states state
;
1568 state
= sci_port
->state_machine
.current_state_id
;
1570 case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
:
1571 scic_sds_port_deactivate_phy(sci_port
, sci_phy
, true);
1573 /* If there are no active phys left in the port, then
1574 * transition the port to the WAITING state until such time
1575 * as a phy goes link up
1577 if (sci_port
->active_phy_mask
== 0)
1578 port_state_machine_change(sci_port
,
1579 SCIC_SDS_PORT_READY_SUBSTATE_WAITING
);
1581 case SCI_BASE_PORT_STATE_RESETTING
:
1582 /* In the resetting state we don't notify the user regarding
1583 * link up and link down notifications. */
1584 scic_sds_port_deactivate_phy(sci_port
, sci_phy
, false);
1587 dev_warn(sciport_to_dev(sci_port
),
1588 "%s: in wrong state: %d\n", __func__
, state
);
1589 return SCI_FAILURE_INVALID_STATE
;
1593 enum sci_status
scic_sds_port_start_io(struct scic_sds_port
*sci_port
,
1594 struct scic_sds_remote_device
*sci_dev
,
1595 struct scic_sds_request
*sci_req
)
1597 enum scic_sds_port_states state
;
1599 state
= sci_port
->state_machine
.current_state_id
;
1601 case SCIC_SDS_PORT_READY_SUBSTATE_WAITING
:
1602 return SCI_FAILURE_INVALID_STATE
;
1603 case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
:
1604 sci_port
->started_request_count
++;
1607 dev_warn(sciport_to_dev(sci_port
),
1608 "%s: in wrong state: %d\n", __func__
, state
);
1609 return SCI_FAILURE_INVALID_STATE
;
1613 enum sci_status
scic_sds_port_complete_io(struct scic_sds_port
*sci_port
,
1614 struct scic_sds_remote_device
*sci_dev
,
1615 struct scic_sds_request
*sci_req
)
1617 enum scic_sds_port_states state
;
1619 state
= sci_port
->state_machine
.current_state_id
;
1621 case SCI_BASE_PORT_STATE_STOPPED
:
1622 dev_warn(sciport_to_dev(sci_port
),
1623 "%s: in wrong state: %d\n", __func__
, state
);
1624 return SCI_FAILURE_INVALID_STATE
;
1625 case SCI_BASE_PORT_STATE_STOPPING
:
1626 scic_sds_port_decrement_request_count(sci_port
);
1628 if (sci_port
->started_request_count
== 0)
1629 port_state_machine_change(sci_port
,
1630 SCI_BASE_PORT_STATE_STOPPED
);
1632 case SCI_BASE_PORT_STATE_READY
:
1633 case SCI_BASE_PORT_STATE_RESETTING
:
1634 case SCI_BASE_PORT_STATE_FAILED
:
1635 case SCIC_SDS_PORT_READY_SUBSTATE_WAITING
:
1636 case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
:
1637 scic_sds_port_decrement_request_count(sci_port
);
1639 case SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
:
1640 scic_sds_port_decrement_request_count(sci_port
);
1641 if (sci_port
->started_request_count
== 0) {
1642 port_state_machine_change(sci_port
,
1643 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
);
1652 * @sci_port: This is the port object which to suspend.
1654 * This method will enable the SCU Port Task Scheduler for this port object but
1655 * will leave the port task scheduler in a suspended state. none
1658 scic_sds_port_enable_port_task_scheduler(struct scic_sds_port
*port
)
1660 u32 pts_control_value
;
1662 pts_control_value
= readl(&port
->port_task_scheduler_registers
->control
);
1663 pts_control_value
|= SCU_PTSxCR_GEN_BIT(ENABLE
) | SCU_PTSxCR_GEN_BIT(SUSPEND
);
1664 writel(pts_control_value
, &port
->port_task_scheduler_registers
->control
);
1669 * @sci_port: This is the port object which to resume.
1671 * This method will disable the SCU port task scheduler for this port object.
1675 scic_sds_port_disable_port_task_scheduler(struct scic_sds_port
*port
)
1677 u32 pts_control_value
;
1679 pts_control_value
= readl(&port
->port_task_scheduler_registers
->control
);
1680 pts_control_value
&=
1681 ~(SCU_PTSxCR_GEN_BIT(ENABLE
) | SCU_PTSxCR_GEN_BIT(SUSPEND
));
1682 writel(pts_control_value
, &port
->port_task_scheduler_registers
->control
);
1685 static void scic_sds_port_post_dummy_remote_node(struct scic_sds_port
*sci_port
)
1687 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1688 u8 phys_index
= sci_port
->physical_port_index
;
1689 union scu_remote_node_context
*rnc
;
1690 u16 rni
= sci_port
->reserved_rni
;
1693 rnc
= &scic
->remote_node_context_table
[rni
];
1694 rnc
->ssp
.is_valid
= true;
1696 command
= SCU_CONTEXT_COMMAND_POST_RNC_32
|
1697 phys_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
| rni
;
1699 scic_sds_controller_post_request(scic
, command
);
1701 /* ensure hardware has seen the post rnc command and give it
1702 * ample time to act before sending the suspend
1704 readl(&scic
->smu_registers
->interrupt_status
); /* flush */
1707 command
= SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX
|
1708 phys_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
| rni
;
1710 scic_sds_controller_post_request(scic
, command
);
1713 static void scic_sds_port_stopped_state_enter(void *object
)
1715 struct scic_sds_port
*sci_port
= object
;
1717 if (sci_port
->state_machine
.previous_state_id
== SCI_BASE_PORT_STATE_STOPPING
) {
1719 * If we enter this state becasuse of a request to stop
1720 * the port then we want to disable the hardwares port
1721 * task scheduler. */
1722 scic_sds_port_disable_port_task_scheduler(sci_port
);
1726 static void scic_sds_port_stopped_state_exit(void *object
)
1728 struct scic_sds_port
*sci_port
= object
;
1730 /* Enable and suspend the port task scheduler */
1731 scic_sds_port_enable_port_task_scheduler(sci_port
);
1734 static void scic_sds_port_ready_state_enter(void *object
)
1736 struct scic_sds_port
*sci_port
= object
;
1737 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1738 struct isci_host
*ihost
= scic_to_ihost(scic
);
1739 struct isci_port
*iport
= sci_port_to_iport(sci_port
);
1742 prev_state
= sci_port
->state_machine
.previous_state_id
;
1743 if (prev_state
== SCI_BASE_PORT_STATE_RESETTING
)
1744 isci_port_hard_reset_complete(iport
, SCI_SUCCESS
);
1746 isci_port_not_ready(ihost
, iport
);
1748 /* Post and suspend the dummy remote node context for this port. */
1749 scic_sds_port_post_dummy_remote_node(sci_port
);
1751 /* Start the ready substate machine */
1752 port_state_machine_change(sci_port
,
1753 SCIC_SDS_PORT_READY_SUBSTATE_WAITING
);
1756 static void scic_sds_port_resetting_state_exit(void *object
)
1758 struct scic_sds_port
*sci_port
= object
;
1760 isci_timer_stop(sci_port
->timer_handle
);
1763 static void scic_sds_port_stopping_state_exit(void *object
)
1765 struct scic_sds_port
*sci_port
= object
;
1767 isci_timer_stop(sci_port
->timer_handle
);
1769 scic_sds_port_destroy_dummy_resources(sci_port
);
1772 static void scic_sds_port_failed_state_enter(void *object
)
1774 struct scic_sds_port
*sci_port
= object
;
1775 struct isci_port
*iport
= sci_port_to_iport(sci_port
);
1777 isci_port_hard_reset_complete(iport
, SCI_FAILURE_TIMEOUT
);
1780 /* --------------------------------------------------------------------------- */
1782 static const struct sci_base_state scic_sds_port_state_table
[] = {
1783 [SCI_BASE_PORT_STATE_STOPPED
] = {
1784 .enter_state
= scic_sds_port_stopped_state_enter
,
1785 .exit_state
= scic_sds_port_stopped_state_exit
1787 [SCI_BASE_PORT_STATE_STOPPING
] = {
1788 .exit_state
= scic_sds_port_stopping_state_exit
1790 [SCI_BASE_PORT_STATE_READY
] = {
1791 .enter_state
= scic_sds_port_ready_state_enter
,
1793 [SCIC_SDS_PORT_READY_SUBSTATE_WAITING
] = {
1794 .enter_state
= scic_sds_port_ready_substate_waiting_enter
,
1796 [SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
] = {
1797 .enter_state
= scic_sds_port_ready_substate_operational_enter
,
1798 .exit_state
= scic_sds_port_ready_substate_operational_exit
1800 [SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
] = {
1801 .enter_state
= scic_sds_port_ready_substate_configuring_enter
,
1802 .exit_state
= scic_sds_port_ready_substate_configuring_exit
1804 [SCI_BASE_PORT_STATE_RESETTING
] = {
1805 .exit_state
= scic_sds_port_resetting_state_exit
1807 [SCI_BASE_PORT_STATE_FAILED
] = {
1808 .enter_state
= scic_sds_port_failed_state_enter
,
1812 void scic_sds_port_construct(struct scic_sds_port
*sci_port
, u8 index
,
1813 struct scic_sds_controller
*scic
)
1815 sci_base_state_machine_construct(&sci_port
->state_machine
,
1817 scic_sds_port_state_table
,
1818 SCI_BASE_PORT_STATE_STOPPED
);
1820 sci_base_state_machine_start(&sci_port
->state_machine
);
1822 sci_port
->logical_port_index
= SCIC_SDS_DUMMY_PORT
;
1823 sci_port
->physical_port_index
= index
;
1824 sci_port
->active_phy_mask
= 0;
1825 sci_port
->ready_exit
= false;
1827 sci_port
->owning_controller
= scic
;
1829 sci_port
->started_request_count
= 0;
1830 sci_port
->assigned_device_count
= 0;
1832 sci_port
->reserved_rni
= SCU_DUMMY_INDEX
;
1833 sci_port
->reserved_tci
= SCU_DUMMY_INDEX
;
1835 sci_port
->timer_handle
= NULL
;
1836 sci_port
->port_task_scheduler_registers
= NULL
;
1838 for (index
= 0; index
< SCI_MAX_PHYS
; index
++)
1839 sci_port
->phy_table
[index
] = NULL
;
1842 void isci_port_init(struct isci_port
*iport
, struct isci_host
*ihost
, int index
)
1844 INIT_LIST_HEAD(&iport
->remote_dev_list
);
1845 INIT_LIST_HEAD(&iport
->domain_dev_list
);
1846 spin_lock_init(&iport
->state_lock
);
1847 init_completion(&iport
->start_complete
);
1848 iport
->isci_host
= ihost
;
1849 isci_port_change_state(iport
, isci_freed
);
1853 * isci_port_get_state() - This function gets the status of the port object.
1854 * @isci_port: This parameter points to the isci_port object
1856 * status of the object as a isci_status enum.
1858 enum isci_status
isci_port_get_state(
1859 struct isci_port
*isci_port
)
1861 return isci_port
->status
;
1864 static void isci_port_bc_change_received(struct isci_host
*ihost
,
1865 struct scic_sds_port
*sci_port
,
1866 struct scic_sds_phy
*sci_phy
)
1868 struct isci_phy
*iphy
= sci_phy_to_iphy(sci_phy
);
1870 dev_dbg(&ihost
->pdev
->dev
, "%s: iphy = %p, sas_phy = %p\n",
1871 __func__
, iphy
, &iphy
->sas_phy
);
1873 ihost
->sas_ha
.notify_port_event(&iphy
->sas_phy
, PORTE_BROADCAST_RCVD
);
1874 scic_port_enable_broadcast_change_notification(sci_port
);
1877 void scic_sds_port_broadcast_change_received(
1878 struct scic_sds_port
*sci_port
,
1879 struct scic_sds_phy
*sci_phy
)
1881 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1882 struct isci_host
*ihost
= scic_to_ihost(scic
);
1884 /* notify the user. */
1885 isci_port_bc_change_received(ihost
, sci_port
, sci_phy
);
1888 int isci_port_perform_hard_reset(struct isci_host
*ihost
, struct isci_port
*iport
,
1889 struct isci_phy
*iphy
)
1891 unsigned long flags
;
1892 enum sci_status status
;
1893 int ret
= TMF_RESP_FUNC_COMPLETE
;
1895 dev_dbg(&ihost
->pdev
->dev
, "%s: iport = %p\n",
1898 init_completion(&iport
->hard_reset_complete
);
1900 spin_lock_irqsave(&ihost
->scic_lock
, flags
);
1902 #define ISCI_PORT_RESET_TIMEOUT SCIC_SDS_SIGNATURE_FIS_TIMEOUT
1903 status
= scic_port_hard_reset(&iport
->sci
, ISCI_PORT_RESET_TIMEOUT
);
1905 spin_unlock_irqrestore(&ihost
->scic_lock
, flags
);
1907 if (status
== SCI_SUCCESS
) {
1908 wait_for_completion(&iport
->hard_reset_complete
);
1910 dev_dbg(&ihost
->pdev
->dev
,
1911 "%s: iport = %p; hard reset completion\n",
1914 if (iport
->hard_reset_status
!= SCI_SUCCESS
)
1915 ret
= TMF_RESP_FUNC_FAILED
;
1917 ret
= TMF_RESP_FUNC_FAILED
;
1919 dev_err(&ihost
->pdev
->dev
,
1920 "%s: iport = %p; scic_port_hard_reset call"
1922 __func__
, iport
, status
);
1926 /* If the hard reset for the port has failed, consider this
1927 * the same as link failures on all phys in the port.
1929 if (ret
!= TMF_RESP_FUNC_COMPLETE
) {
1930 dev_err(&ihost
->pdev
->dev
,
1931 "%s: iport = %p; hard reset failed "
1932 "(0x%x) - sending link down to libsas for phy %p\n",
1933 __func__
, iport
, iport
->hard_reset_status
, iphy
);
1935 isci_port_link_down(ihost
, iphy
, iport
);
1942 * isci_port_deformed() - This function is called by libsas when a port becomes
1944 * @phy: This parameter specifies the libsas phy with the inactive port.
1947 void isci_port_deformed(struct asd_sas_phy
*phy
)
1949 pr_debug("%s: sas_phy = %p\n", __func__
, phy
);
1953 * isci_port_formed() - This function is called by libsas when a port becomes
1955 * @phy: This parameter specifies the libsas phy with the active port.
1958 void isci_port_formed(struct asd_sas_phy
*phy
)
1960 pr_debug("%s: sas_phy = %p, sas_port = %p\n", __func__
, phy
, phy
->port
);