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 struct scic_sds_port_state_handler scic_sds_port_state_handler_table
[];
66 static void isci_port_change_state(struct isci_port
*iport
, enum isci_status status
)
70 dev_dbg(&iport
->isci_host
->pdev
->dev
,
71 "%s: iport = %p, state = 0x%x\n",
72 __func__
, iport
, status
);
74 /* XXX pointless lock */
75 spin_lock_irqsave(&iport
->state_lock
, flags
);
76 iport
->status
= status
;
77 spin_unlock_irqrestore(&iport
->state_lock
, flags
);
81 * This function will indicate which protocols are supported by this port.
82 * @sci_port: a handle corresponding to the SAS port for which to return the
83 * supported protocols.
84 * @protocols: This parameter specifies a pointer to a data structure
85 * which the core will copy the protocol values for the port from the
86 * transmit_identification register.
89 scic_sds_port_get_protocols(struct scic_sds_port
*sci_port
,
90 struct scic_phy_proto
*protocols
)
96 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
97 if (sci_port
->phy_table
[index
] != NULL
) {
98 scic_sds_phy_get_protocols(sci_port
->phy_table
[index
],
105 * This method requests a list (mask) of the phys contained in the supplied SAS
107 * @sci_port: a handle corresponding to the SAS port for which to return the
110 * Return a bit mask indicating which phys are a part of this port. Each bit
111 * corresponds to a phy identifier (e.g. bit 0 = phy id 0).
113 static u32
scic_sds_port_get_phys(struct scic_sds_port
*sci_port
)
120 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
121 if (sci_port
->phy_table
[index
] != NULL
) {
122 mask
|= (1 << index
);
130 * scic_port_get_properties() - This method simply returns the properties
131 * regarding the port, such as: physical index, protocols, sas address, etc.
132 * @port: this parameter specifies the port for which to retrieve the physical
134 * @properties: This parameter specifies the properties structure into which to
135 * copy the requested information.
137 * Indicate if the user specified a valid port. SCI_SUCCESS This value is
138 * returned if the specified port was valid. SCI_FAILURE_INVALID_PORT This
139 * value is returned if the specified port is not valid. When this value is
140 * returned, no data is copied to the properties output parameter.
142 static enum sci_status
scic_port_get_properties(struct scic_sds_port
*port
,
143 struct scic_port_properties
*prop
)
145 if ((port
== NULL
) ||
146 (port
->logical_port_index
== SCIC_SDS_DUMMY_PORT
))
147 return SCI_FAILURE_INVALID_PORT
;
149 prop
->index
= port
->logical_port_index
;
150 prop
->phy_mask
= scic_sds_port_get_phys(port
);
151 scic_sds_port_get_sas_address(port
, &prop
->local
.sas_address
);
152 scic_sds_port_get_protocols(port
, &prop
->local
.protocols
);
153 scic_sds_port_get_attached_sas_address(port
, &prop
->remote
.sas_address
);
158 static void isci_port_link_up(struct isci_host
*isci_host
,
159 struct scic_sds_port
*port
,
160 struct scic_sds_phy
*phy
)
163 struct scic_port_properties properties
;
164 struct isci_phy
*isci_phy
= sci_phy_to_iphy(phy
);
165 struct isci_port
*isci_port
= sci_port_to_iport(port
);
166 unsigned long success
= true;
168 BUG_ON(isci_phy
->isci_port
!= NULL
);
170 isci_phy
->isci_port
= isci_port
;
172 dev_dbg(&isci_host
->pdev
->dev
,
173 "%s: isci_port = %p\n",
174 __func__
, isci_port
);
176 spin_lock_irqsave(&isci_phy
->sas_phy
.frame_rcvd_lock
, flags
);
178 isci_port_change_state(isci_phy
->isci_port
, isci_starting
);
180 scic_port_get_properties(port
, &properties
);
182 if (phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SATA
) {
183 u64 attached_sas_address
;
185 isci_phy
->sas_phy
.oob_mode
= SATA_OOB_MODE
;
186 isci_phy
->sas_phy
.frame_rcvd_size
= sizeof(struct dev_to_host_fis
);
189 * For direct-attached SATA devices, the SCI core will
190 * automagically assign a SAS address to the end device
191 * for the purpose of creating a port. This SAS address
192 * will not be the same as assigned to the PHY and needs
193 * to be obtained from struct scic_port_properties properties.
195 attached_sas_address
= properties
.remote
.sas_address
.high
;
196 attached_sas_address
<<= 32;
197 attached_sas_address
|= properties
.remote
.sas_address
.low
;
198 swab64s(&attached_sas_address
);
200 memcpy(&isci_phy
->sas_phy
.attached_sas_addr
,
201 &attached_sas_address
, sizeof(attached_sas_address
));
202 } else if (phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SAS
) {
203 isci_phy
->sas_phy
.oob_mode
= SAS_OOB_MODE
;
204 isci_phy
->sas_phy
.frame_rcvd_size
= sizeof(struct sas_identify_frame
);
206 /* Copy the attached SAS address from the IAF */
207 memcpy(isci_phy
->sas_phy
.attached_sas_addr
,
208 isci_phy
->frame_rcvd
.iaf
.sas_addr
, SAS_ADDR_SIZE
);
210 dev_err(&isci_host
->pdev
->dev
, "%s: unkown target\n", __func__
);
214 isci_phy
->sas_phy
.phy
->negotiated_linkrate
= sci_phy_linkrate(phy
);
216 spin_unlock_irqrestore(&isci_phy
->sas_phy
.frame_rcvd_lock
, flags
);
218 /* Notify libsas that we have an address frame, if indeed
219 * we've found an SSP, SMP, or STP target */
221 isci_host
->sas_ha
.notify_port_event(&isci_phy
->sas_phy
,
227 * isci_port_link_down() - This function is called by the sci core when a link
229 * @isci_host: This parameter specifies the isci host object.
230 * @phy: This parameter specifies the isci phy with the active link.
231 * @port: This parameter specifies the isci port with the active link.
234 static void isci_port_link_down(struct isci_host
*isci_host
,
235 struct isci_phy
*isci_phy
,
236 struct isci_port
*isci_port
)
238 struct isci_remote_device
*isci_device
;
240 dev_dbg(&isci_host
->pdev
->dev
,
241 "%s: isci_port = %p\n", __func__
, isci_port
);
245 /* check to see if this is the last phy on this port. */
246 if (isci_phy
->sas_phy
.port
247 && isci_phy
->sas_phy
.port
->num_phys
== 1) {
249 /* change the state for all devices on this port.
250 * The next task sent to this device will be returned
251 * as SAS_TASK_UNDELIVERED, and the scsi mid layer
252 * will remove the target
254 list_for_each_entry(isci_device
,
255 &isci_port
->remote_dev_list
,
257 dev_dbg(&isci_host
->pdev
->dev
,
258 "%s: isci_device = %p\n",
259 __func__
, isci_device
);
260 isci_remote_device_change_state(isci_device
,
264 isci_port_change_state(isci_port
, isci_stopping
);
267 /* Notify libsas of the borken link, this will trigger calls to our
268 * isci_port_deformed and isci_dev_gone functions.
270 sas_phy_disconnected(&isci_phy
->sas_phy
);
271 isci_host
->sas_ha
.notify_phy_event(&isci_phy
->sas_phy
,
272 PHYE_LOSS_OF_SIGNAL
);
274 isci_phy
->isci_port
= NULL
;
276 dev_dbg(&isci_host
->pdev
->dev
,
277 "%s: isci_port = %p - Done\n", __func__
, isci_port
);
282 * isci_port_ready() - This function is called by the sci core when a link
284 * @isci_host: This parameter specifies the isci host object.
285 * @port: This parameter specifies the sci port with the active link.
288 static void isci_port_ready(struct isci_host
*isci_host
, struct isci_port
*isci_port
)
290 dev_dbg(&isci_host
->pdev
->dev
,
291 "%s: isci_port = %p\n", __func__
, isci_port
);
293 complete_all(&isci_port
->start_complete
);
294 isci_port_change_state(isci_port
, isci_ready
);
299 * isci_port_not_ready() - This function is called by the sci core when a link
300 * is not ready. All remote devices on this link will be removed if they are
301 * in the stopping state.
302 * @isci_host: This parameter specifies the isci host object.
303 * @port: This parameter specifies the sci port with the active link.
306 static void isci_port_not_ready(struct isci_host
*isci_host
, struct isci_port
*isci_port
)
308 dev_dbg(&isci_host
->pdev
->dev
,
309 "%s: isci_port = %p\n", __func__
, isci_port
);
312 static void isci_port_stop_complete(struct scic_sds_controller
*scic
,
313 struct scic_sds_port
*sci_port
,
314 enum sci_status completion_status
)
316 dev_dbg(&scic_to_ihost(scic
)->pdev
->dev
, "Port stop complete\n");
320 * isci_port_hard_reset_complete() - This function is called by the sci core
321 * when the hard reset complete notification has been received.
322 * @port: This parameter specifies the sci port with the active link.
323 * @completion_status: This parameter specifies the core status for the reset
327 static void isci_port_hard_reset_complete(struct isci_port
*isci_port
,
328 enum sci_status completion_status
)
330 dev_dbg(&isci_port
->isci_host
->pdev
->dev
,
331 "%s: isci_port = %p, completion_status=%x\n",
332 __func__
, isci_port
, completion_status
);
334 /* Save the status of the hard reset from the port. */
335 isci_port
->hard_reset_status
= completion_status
;
337 complete_all(&isci_port
->hard_reset_complete
);
340 /* This method will return a true value if the specified phy can be assigned to
341 * this port The following is a list of phys for each port that are allowed: -
342 * Port 0 - 3 2 1 0 - Port 1 - 1 - Port 2 - 3 2 - Port 3 - 3 This method
343 * doesn't preclude all configurations. It merely ensures that a phy is part
344 * of the allowable set of phy identifiers for that port. For example, one
345 * could assign phy 3 to port 0 and no other phys. Please refer to
346 * scic_sds_port_is_phy_mask_valid() for information regarding whether the
347 * phy_mask for a port can be supported. bool true if this is a valid phy
348 * assignment for the port false if this is not a valid phy assignment for the
351 bool scic_sds_port_is_valid_phy_assignment(struct scic_sds_port
*sci_port
,
354 /* Initialize to invalid value. */
355 u32 existing_phy_index
= SCI_MAX_PHYS
;
358 if ((sci_port
->physical_port_index
== 1) && (phy_index
!= 1)) {
362 if (sci_port
->physical_port_index
== 3 && phy_index
!= 3) {
367 (sci_port
->physical_port_index
== 2)
368 && ((phy_index
== 0) || (phy_index
== 1))
373 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
374 if ((sci_port
->phy_table
[index
] != NULL
)
375 && (index
!= phy_index
)) {
376 existing_phy_index
= index
;
381 * Ensure that all of the phys in the port are capable of
382 * operating at the same maximum link rate. */
384 (existing_phy_index
< SCI_MAX_PHYS
)
385 && (sci_port
->owning_controller
->user_parameters
.sds1
.phys
[
386 phy_index
].max_speed_generation
!=
387 sci_port
->owning_controller
->user_parameters
.sds1
.phys
[
388 existing_phy_index
].max_speed_generation
)
397 * @sci_port: This is the port object for which to determine if the phy mask
400 * This method will return a true value if the port's phy mask can be supported
401 * by the SCU. The following is a list of valid PHY mask configurations for
402 * each port: - Port 0 - [[3 2] 1] 0 - Port 1 - [1] - Port 2 - [[3] 2]
403 * - Port 3 - [3] This method returns a boolean indication specifying if the
404 * phy mask can be supported. true if this is a valid phy assignment for the
405 * port false if this is not a valid phy assignment for the port
407 static bool scic_sds_port_is_phy_mask_valid(
408 struct scic_sds_port
*sci_port
,
411 if (sci_port
->physical_port_index
== 0) {
412 if (((phy_mask
& 0x0F) == 0x0F)
413 || ((phy_mask
& 0x03) == 0x03)
414 || ((phy_mask
& 0x01) == 0x01)
417 } else if (sci_port
->physical_port_index
== 1) {
418 if (((phy_mask
& 0x02) == 0x02)
421 } else if (sci_port
->physical_port_index
== 2) {
422 if (((phy_mask
& 0x0C) == 0x0C)
423 || ((phy_mask
& 0x04) == 0x04)
426 } else if (sci_port
->physical_port_index
== 3) {
427 if (((phy_mask
& 0x08) == 0x08)
437 * @sci_port: This parameter specifies the port from which to return a
440 * This method retrieves a currently active (i.e. connected) phy contained in
441 * the port. Currently, the lowest order phy that is connected is returned.
442 * This method returns a pointer to a SCIS_SDS_PHY object. NULL This value is
443 * returned if there are no currently active (i.e. connected to a remote end
444 * point) phys contained in the port. All other values specify a struct scic_sds_phy
445 * object that is active in the port.
447 static struct scic_sds_phy
*scic_sds_port_get_a_connected_phy(
448 struct scic_sds_port
*sci_port
451 struct scic_sds_phy
*phy
;
453 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
455 * Ensure that the phy is both part of the port and currently
456 * connected to the remote end-point. */
457 phy
= sci_port
->phy_table
[index
];
460 && scic_sds_port_active_phy(sci_port
, phy
)
470 * scic_sds_port_set_phy() -
471 * @out]: port The port object to which the phy assignement is being made.
472 * @out]: phy The phy which is being assigned to the port.
474 * This method attempts to make the assignment of the phy to the port. If
475 * successful the phy is assigned to the ports phy table. bool true if the phy
476 * assignment can be made. false if the phy assignement can not be made. This
477 * is a functional test that only fails if the phy is currently assigned to a
480 static enum sci_status
scic_sds_port_set_phy(
481 struct scic_sds_port
*port
,
482 struct scic_sds_phy
*phy
)
485 * Check to see if we can add this phy to a port
486 * that means that the phy is not part of a port and that the port does
487 * not already have a phy assinged to the phy index. */
489 (port
->phy_table
[phy
->phy_index
] == NULL
)
490 && (phy_get_non_dummy_port(phy
) == NULL
)
491 && scic_sds_port_is_valid_phy_assignment(port
, phy
->phy_index
)
494 * Phy is being added in the stopped state so we are in MPC mode
495 * make logical port index = physical port index */
496 port
->logical_port_index
= port
->physical_port_index
;
497 port
->phy_table
[phy
->phy_index
] = phy
;
498 scic_sds_phy_set_port(phy
, port
);
507 * scic_sds_port_clear_phy() -
508 * @out]: port The port from which the phy is being cleared.
509 * @out]: phy The phy being cleared from the port.
511 * This method will clear the phy assigned to this port. This method fails if
512 * this phy is not currently assinged to this port. bool true if the phy is
513 * removed from the port. false if this phy is not assined to this port.
515 static enum sci_status
scic_sds_port_clear_phy(
516 struct scic_sds_port
*port
,
517 struct scic_sds_phy
*phy
)
519 /* Make sure that this phy is part of this port */
520 if (port
->phy_table
[phy
->phy_index
] == phy
&&
521 phy_get_non_dummy_port(phy
) == port
) {
522 struct scic_sds_controller
*scic
= port
->owning_controller
;
523 struct isci_host
*ihost
= scic_to_ihost(scic
);
525 /* Yep it is assigned to this port so remove it */
526 scic_sds_phy_set_port(phy
, &ihost
->ports
[SCI_MAX_PORTS
].sci
);
527 port
->phy_table
[phy
->phy_index
] = NULL
;
536 * This method requests the SAS address for the supplied SAS port from the SCI
538 * @sci_port: a handle corresponding to the SAS port for which to return the
540 * @sas_address: This parameter specifies a pointer to a SAS address structure
541 * into which the core will copy the SAS address for the port.
544 void scic_sds_port_get_sas_address(
545 struct scic_sds_port
*sci_port
,
546 struct sci_sas_address
*sas_address
)
550 sas_address
->high
= 0;
551 sas_address
->low
= 0;
553 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
554 if (sci_port
->phy_table
[index
] != NULL
) {
555 scic_sds_phy_get_sas_address(sci_port
->phy_table
[index
], sas_address
);
561 * This function requests the SAS address for the device directly attached to
563 * @sci_port: a handle corresponding to the SAS port for which to return the
565 * @sas_address: This parameter specifies a pointer to a SAS address structure
566 * into which the core will copy the SAS address for the device directly
567 * attached to the port.
570 void scic_sds_port_get_attached_sas_address(
571 struct scic_sds_port
*sci_port
,
572 struct sci_sas_address
*sas_address
)
574 struct scic_sds_phy
*sci_phy
;
577 * Ensure that the phy is both part of the port and currently
578 * connected to the remote end-point.
580 sci_phy
= scic_sds_port_get_a_connected_phy(sci_port
);
582 if (sci_phy
->protocol
!= SCIC_SDS_PHY_PROTOCOL_SATA
) {
583 scic_sds_phy_get_attached_sas_address(sci_phy
,
586 scic_sds_phy_get_sas_address(sci_phy
, sas_address
);
587 sas_address
->low
+= sci_phy
->phy_index
;
590 sas_address
->high
= 0;
591 sas_address
->low
= 0;
596 * scic_sds_port_construct_dummy_rnc() - create dummy rnc for si workaround
598 * @sci_port: logical port on which we need to create the remote node context
599 * @rni: remote node index for this remote node context.
601 * This routine will construct a dummy remote node context data structure
602 * This structure will be posted to the hardware to work around a scheduler
603 * error in the hardware.
605 static void scic_sds_port_construct_dummy_rnc(struct scic_sds_port
*sci_port
, u16 rni
)
607 union scu_remote_node_context
*rnc
;
609 rnc
= &sci_port
->owning_controller
->remote_node_context_table
[rni
];
611 memset(rnc
, 0, sizeof(union scu_remote_node_context
));
613 rnc
->ssp
.remote_sas_address_hi
= 0;
614 rnc
->ssp
.remote_sas_address_lo
= 0;
616 rnc
->ssp
.remote_node_index
= rni
;
617 rnc
->ssp
.remote_node_port_width
= 1;
618 rnc
->ssp
.logical_port_index
= sci_port
->physical_port_index
;
620 rnc
->ssp
.nexus_loss_timer_enable
= false;
621 rnc
->ssp
.check_bit
= false;
622 rnc
->ssp
.is_valid
= true;
623 rnc
->ssp
.is_remote_node_context
= true;
624 rnc
->ssp
.function_number
= 0;
625 rnc
->ssp
.arbitration_wait_time
= 0;
629 * scic_sds_port_construct_dummy_task() - create dummy task for si workaround
630 * @sci_port The logical port on which we need to create the
631 * remote node context.
633 * @tci The remote node index for this remote node context.
635 * This routine will construct a dummy task context data structure. This
636 * structure will be posted to the hardwre to work around a scheduler error
640 static void scic_sds_port_construct_dummy_task(struct scic_sds_port
*sci_port
, u16 tci
)
642 struct scu_task_context
*task_context
;
644 task_context
= scic_sds_controller_get_task_context_buffer(sci_port
->owning_controller
, tci
);
646 memset(task_context
, 0, sizeof(struct scu_task_context
));
648 task_context
->abort
= 0;
649 task_context
->priority
= 0;
650 task_context
->initiator_request
= 1;
651 task_context
->connection_rate
= 1;
652 task_context
->protocol_engine_index
= 0;
653 task_context
->logical_port_index
= sci_port
->physical_port_index
;
654 task_context
->protocol_type
= SCU_TASK_CONTEXT_PROTOCOL_SSP
;
655 task_context
->task_index
= scic_sds_io_tag_get_index(tci
);
656 task_context
->valid
= SCU_TASK_CONTEXT_VALID
;
657 task_context
->context_type
= SCU_TASK_CONTEXT_TYPE
;
659 task_context
->remote_node_index
= sci_port
->reserved_rni
;
660 task_context
->command_code
= 0;
662 task_context
->link_layer_control
= 0;
663 task_context
->do_not_dma_ssp_good_response
= 1;
664 task_context
->strict_ordering
= 0;
665 task_context
->control_frame
= 0;
666 task_context
->timeout_enable
= 0;
667 task_context
->block_guard_enable
= 0;
669 task_context
->address_modifier
= 0;
671 task_context
->task_phase
= 0x01;
674 static void scic_sds_port_destroy_dummy_resources(struct scic_sds_port
*sci_port
)
676 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
678 if (sci_port
->reserved_tci
!= SCU_DUMMY_INDEX
)
679 scic_controller_free_io_tag(scic
, sci_port
->reserved_tci
);
681 if (sci_port
->reserved_rni
!= SCU_DUMMY_INDEX
)
682 scic_sds_remote_node_table_release_remote_node_index(&scic
->available_remote_nodes
,
683 1, sci_port
->reserved_rni
);
685 sci_port
->reserved_rni
= SCU_DUMMY_INDEX
;
686 sci_port
->reserved_tci
= SCU_DUMMY_INDEX
;
690 * This method performs initialization of the supplied port. Initialization
691 * includes: - state machine initialization - member variable initialization
692 * - configuring the phy_mask
694 * @transport_layer_registers:
695 * @port_task_scheduler_registers:
696 * @port_configuration_regsiter:
698 * enum sci_status SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION This value is returned
699 * if the phy being added to the port
701 enum sci_status
scic_sds_port_initialize(
702 struct scic_sds_port
*sci_port
,
703 void __iomem
*port_task_scheduler_registers
,
704 void __iomem
*port_configuration_regsiter
,
705 void __iomem
*viit_registers
)
707 sci_port
->port_task_scheduler_registers
= port_task_scheduler_registers
;
708 sci_port
->port_pe_configuration_register
= port_configuration_regsiter
;
709 sci_port
->viit_registers
= viit_registers
;
716 * This method assigns the direct attached device ID for this port.
718 * @param[in] sci_port The port for which the direct attached device id is to
720 * @param[in] device_id The direct attached device ID to assign to the port.
721 * This will be the RNi for the device
723 void scic_sds_port_setup_transports(
724 struct scic_sds_port
*sci_port
,
729 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
730 if (sci_port
->active_phy_mask
& (1 << index
))
731 scic_sds_phy_setup_transport(sci_port
->phy_table
[index
], device_id
);
737 * @sci_port: This is the port on which the phy should be enabled.
738 * @sci_phy: This is the specific phy which to enable.
739 * @do_notify_user: This parameter specifies whether to inform the user (via
740 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
742 * This function will activate the phy in the port.
743 * Activation includes: - adding
744 * the phy to the port - enabling the Protocol Engine in the silicon. -
745 * notifying the user that the link is up. none
747 static void scic_sds_port_activate_phy(struct scic_sds_port
*sci_port
,
748 struct scic_sds_phy
*sci_phy
,
751 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
752 struct isci_host
*ihost
= scic_to_ihost(scic
);
754 if (sci_phy
->protocol
!= SCIC_SDS_PHY_PROTOCOL_SATA
)
755 scic_sds_phy_resume(sci_phy
);
757 sci_port
->active_phy_mask
|= 1 << sci_phy
->phy_index
;
759 scic_sds_controller_clear_invalid_phy(scic
, sci_phy
);
761 if (do_notify_user
== true)
762 isci_port_link_up(ihost
, sci_port
, sci_phy
);
765 void scic_sds_port_deactivate_phy(struct scic_sds_port
*sci_port
,
766 struct scic_sds_phy
*sci_phy
,
769 struct scic_sds_controller
*scic
= scic_sds_port_get_controller(sci_port
);
770 struct isci_port
*iport
= sci_port_to_iport(sci_port
);
771 struct isci_host
*ihost
= scic_to_ihost(scic
);
772 struct isci_phy
*iphy
= sci_phy_to_iphy(sci_phy
);
774 sci_port
->active_phy_mask
&= ~(1 << sci_phy
->phy_index
);
776 sci_phy
->max_negotiated_speed
= SAS_LINK_RATE_UNKNOWN
;
778 /* Re-assign the phy back to the LP as if it were a narrow port */
779 writel(sci_phy
->phy_index
,
780 &sci_port
->port_pe_configuration_register
[sci_phy
->phy_index
]);
782 if (do_notify_user
== true)
783 isci_port_link_down(ihost
, iphy
, iport
);
788 * @sci_port: This is the port on which the phy should be disabled.
789 * @sci_phy: This is the specific phy which to disabled.
791 * This function will disable the phy and report that the phy is not valid for
792 * this port object. None
794 static void scic_sds_port_invalid_link_up(struct scic_sds_port
*sci_port
,
795 struct scic_sds_phy
*sci_phy
)
797 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
800 * Check to see if we have alreay reported this link as bad and if
801 * not go ahead and tell the SCI_USER that we have discovered an
804 if ((scic
->invalid_phy_mask
& (1 << sci_phy
->phy_index
)) == 0) {
805 scic_sds_controller_set_invalid_phy(scic
, sci_phy
);
806 dev_warn(&scic_to_ihost(scic
)->pdev
->dev
, "Invalid link up!\n");
810 static bool is_port_ready_state(enum scic_sds_port_states state
)
813 case SCI_BASE_PORT_STATE_READY
:
814 case SCIC_SDS_PORT_READY_SUBSTATE_WAITING
:
815 case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
:
816 case SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
:
823 /* flag dummy rnc hanling when exiting a ready state */
824 static void port_state_machine_change(struct scic_sds_port
*sci_port
,
825 enum scic_sds_port_states state
)
827 struct sci_base_state_machine
*sm
= &sci_port
->state_machine
;
828 enum scic_sds_port_states old_state
= sm
->current_state_id
;
830 if (is_port_ready_state(old_state
) && !is_port_ready_state(state
))
831 sci_port
->ready_exit
= true;
833 sci_base_state_machine_change_state(sm
, state
);
834 sci_port
->ready_exit
= false;
838 * scic_sds_port_general_link_up_handler - phy can be assigned to port?
839 * @sci_port: scic_sds_port object for which has a phy that has gone link up.
840 * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
841 * @do_notify_user: This parameter specifies whether to inform the user (via
842 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
844 * Determine if this phy can be assigned to this
845 * port . If the phy is not a valid PHY for
846 * this port then the function will notify the user. A PHY can only be
847 * part of a port if it's attached SAS ADDRESS is the same as all other PHYs in
848 * the same port. none
850 static void scic_sds_port_general_link_up_handler(struct scic_sds_port
*sci_port
,
851 struct scic_sds_phy
*sci_phy
,
854 struct sci_sas_address port_sas_address
;
855 struct sci_sas_address phy_sas_address
;
857 scic_sds_port_get_attached_sas_address(sci_port
, &port_sas_address
);
858 scic_sds_phy_get_attached_sas_address(sci_phy
, &phy_sas_address
);
860 /* If the SAS address of the new phy matches the SAS address of
861 * other phys in the port OR this is the first phy in the port,
862 * then activate the phy and allow it to be used for operations
865 if ((phy_sas_address
.high
== port_sas_address
.high
&&
866 phy_sas_address
.low
== port_sas_address
.low
) ||
867 sci_port
->active_phy_mask
== 0) {
868 struct sci_base_state_machine
*sm
= &sci_port
->state_machine
;
870 scic_sds_port_activate_phy(sci_port
, sci_phy
, do_notify_user
);
871 if (sm
->current_state_id
== SCI_BASE_PORT_STATE_RESETTING
)
872 port_state_machine_change(sci_port
, SCI_BASE_PORT_STATE_READY
);
874 scic_sds_port_invalid_link_up(sci_port
, sci_phy
);
880 * This method returns false if the port only has a single phy object assigned.
881 * If there are no phys or more than one phy then the method will return
883 * @sci_port: The port for which the wide port condition is to be checked.
885 * bool true Is returned if this is a wide ported port. false Is returned if
886 * this is a narrow port.
888 static bool scic_sds_port_is_wide(struct scic_sds_port
*sci_port
)
893 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
894 if (sci_port
->phy_table
[index
] != NULL
) {
899 return phy_count
!= 1;
903 * This method is called by the PHY object when the link is detected. if the
904 * port wants the PHY to continue on to the link up state then the port
905 * layer must return true. If the port object returns false the phy object
906 * must halt its attempt to go link up.
907 * @sci_port: The port associated with the phy object.
908 * @sci_phy: The phy object that is trying to go link up.
910 * true if the phy object can continue to the link up condition. true Is
911 * returned if this phy can continue to the ready state. false Is returned if
912 * can not continue on to the ready state. This notification is in place for
913 * wide ports and direct attached phys. Since there are no wide ported SATA
914 * devices this could become an invalid port configuration.
916 bool scic_sds_port_link_detected(
917 struct scic_sds_port
*sci_port
,
918 struct scic_sds_phy
*sci_phy
)
920 if ((sci_port
->logical_port_index
!= SCIC_SDS_DUMMY_PORT
) &&
921 (sci_phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SATA
) &&
922 scic_sds_port_is_wide(sci_port
)) {
923 scic_sds_port_invalid_link_up(sci_port
, sci_phy
);
932 * This method is the entry point for the phy to inform the port that it is now
938 void scic_sds_port_link_up(
939 struct scic_sds_port
*sci_port
,
940 struct scic_sds_phy
*sci_phy
)
942 sci_phy
->is_in_link_training
= false;
944 sci_port
->state_handlers
->link_up_handler(sci_port
, sci_phy
);
948 * This method is the entry point for the phy to inform the port that it is no
949 * longer in a ready state
954 void scic_sds_port_link_down(
955 struct scic_sds_port
*sci_port
,
956 struct scic_sds_phy
*sci_phy
)
958 sci_port
->state_handlers
->link_down_handler(sci_port
, sci_phy
);
962 * This method is called to start an IO request on this port.
969 enum sci_status
scic_sds_port_start_io(
970 struct scic_sds_port
*sci_port
,
971 struct scic_sds_remote_device
*sci_dev
,
972 struct scic_sds_request
*sci_req
)
974 return sci_port
->state_handlers
->start_io_handler(
975 sci_port
, sci_dev
, sci_req
);
979 * This method is called to complete an IO request to the port.
986 enum sci_status
scic_sds_port_complete_io(
987 struct scic_sds_port
*sci_port
,
988 struct scic_sds_remote_device
*sci_dev
,
989 struct scic_sds_request
*sci_req
)
991 return sci_port
->state_handlers
->complete_io_handler(
992 sci_port
, sci_dev
, sci_req
);
996 * This method is provided to timeout requests for port operations. Mostly its
997 * for the port reset operation.
1001 static void scic_sds_port_timeout_handler(void *port
)
1003 struct scic_sds_port
*sci_port
= port
;
1006 current_state
= sci_base_state_machine_get_state(&sci_port
->state_machine
);
1008 if (current_state
== SCI_BASE_PORT_STATE_RESETTING
) {
1009 /* if the port is still in the resetting state then the timeout
1010 * fired before the reset completed.
1012 port_state_machine_change(sci_port
, SCI_BASE_PORT_STATE_FAILED
);
1013 } else if (current_state
== SCI_BASE_PORT_STATE_STOPPED
) {
1014 /* if the port is stopped then the start request failed In this
1015 * case stay in the stopped state.
1017 dev_err(sciport_to_dev(sci_port
),
1018 "%s: SCIC Port 0x%p failed to stop before tiemout.\n",
1021 } else if (current_state
== SCI_BASE_PORT_STATE_STOPPING
) {
1022 /* if the port is still stopping then the stop has not completed */
1023 isci_port_stop_complete(sci_port
->owning_controller
,
1025 SCI_FAILURE_TIMEOUT
);
1027 /* The port is in the ready state and we have a timer
1028 * reporting a timeout this should not happen.
1030 dev_err(sciport_to_dev(sci_port
),
1031 "%s: SCIC Port 0x%p is processing a timeout operation "
1032 "in state %d.\n", __func__
, sci_port
, current_state
);
1036 /* --------------------------------------------------------------------------- */
1039 * This function updates the hardwares VIIT entry for this port.
1043 static void scic_sds_port_update_viit_entry(struct scic_sds_port
*sci_port
)
1045 struct sci_sas_address sas_address
;
1047 scic_sds_port_get_sas_address(sci_port
, &sas_address
);
1049 writel(sas_address
.high
,
1050 &sci_port
->viit_registers
->initiator_sas_address_hi
);
1051 writel(sas_address
.low
,
1052 &sci_port
->viit_registers
->initiator_sas_address_lo
);
1054 /* This value get cleared just in case its not already cleared */
1055 writel(0, &sci_port
->viit_registers
->reserved
);
1057 /* We are required to update the status register last */
1058 writel(SCU_VIIT_ENTRY_ID_VIIT
|
1059 SCU_VIIT_IPPT_INITIATOR
|
1060 ((1 << sci_port
->physical_port_index
) << SCU_VIIT_ENTRY_LPVIE_SHIFT
) |
1061 SCU_VIIT_STATUS_ALL_VALID
,
1062 &sci_port
->viit_registers
->status
);
1066 * This method returns the maximum allowed speed for data transfers on this
1067 * port. This maximum allowed speed evaluates to the maximum speed of the
1068 * slowest phy in the port.
1069 * @sci_port: This parameter specifies the port for which to retrieve the
1070 * maximum allowed speed.
1072 * This method returns the maximum negotiated speed of the slowest phy in the
1075 enum sas_linkrate
scic_sds_port_get_max_allowed_speed(
1076 struct scic_sds_port
*sci_port
)
1079 enum sas_linkrate max_allowed_speed
= SAS_LINK_RATE_6_0_GBPS
;
1080 struct scic_sds_phy
*phy
= NULL
;
1083 * Loop through all of the phys in this port and find the phy with the
1084 * lowest maximum link rate. */
1085 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
1086 phy
= sci_port
->phy_table
[index
];
1089 && (scic_sds_port_active_phy(sci_port
, phy
) == true)
1090 && (phy
->max_negotiated_speed
< max_allowed_speed
)
1092 max_allowed_speed
= phy
->max_negotiated_speed
;
1095 return max_allowed_speed
;
1098 static void scic_port_enable_broadcast_change_notification(struct scic_sds_port
*port
)
1100 struct scic_sds_phy
*phy
;
1104 /* Loop through all of the phys to enable BCN. */
1105 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
1106 phy
= port
->phy_table
[index
];
1109 readl(&phy
->link_layer_registers
->link_layer_control
);
1111 /* clear the bit by writing 1. */
1112 writel(register_value
,
1113 &phy
->link_layer_registers
->link_layer_control
);
1119 * ****************************************************************************
1120 * * READY SUBSTATE HANDLERS
1121 * **************************************************************************** */
1124 * This method is the general ready substate complete io handler for the
1125 * struct scic_sds_port object. This function decrments the outstanding request count
1126 * for this port object. enum sci_status SCI_SUCCESS
1128 static enum sci_status
scic_sds_port_ready_substate_complete_io_handler(
1129 struct scic_sds_port
*port
,
1130 struct scic_sds_remote_device
*device
,
1131 struct scic_sds_request
*io_request
)
1133 scic_sds_port_decrement_request_count(port
);
1140 * @sci_port: This is the struct scic_sds_port object that which has a phy that has
1142 * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
1144 * This method is the ready waiting substate link up handler for the
1145 * struct scic_sds_port object. This methos will report the link up condition for
1146 * this port and will transition to the ready operational substate. none
1148 static void scic_sds_port_ready_waiting_substate_link_up_handler(
1149 struct scic_sds_port
*sci_port
,
1150 struct scic_sds_phy
*sci_phy
)
1153 * Since this is the first phy going link up for the port we can just enable
1154 * it and continue. */
1155 scic_sds_port_activate_phy(sci_port
, sci_phy
, true);
1157 port_state_machine_change(sci_port
,
1158 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
);
1162 * This method is the ready waiting substate start io handler for the
1163 * struct scic_sds_port object. The port object can not accept new requests so the
1164 * request is failed. enum sci_status SCI_FAILURE_INVALID_STATE
1166 static enum sci_status
scic_sds_port_ready_waiting_substate_start_io_handler(
1167 struct scic_sds_port
*port
,
1168 struct scic_sds_remote_device
*device
,
1169 struct scic_sds_request
*io_request
)
1171 return SCI_FAILURE_INVALID_STATE
;
1175 * scic_sds_port_ready_operational_substate_link_up_handler() -
1176 * @sci_port: This is the struct scic_sds_port object that which has a phy that has
1178 * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
1180 * This method is the ready operational substate link up handler for the
1181 * struct scic_sds_port object. This function notifies the SCI User that the phy has
1182 * gone link up. none
1184 static void scic_sds_port_ready_operational_substate_link_up_handler(
1185 struct scic_sds_port
*sci_port
,
1186 struct scic_sds_phy
*sci_phy
)
1188 scic_sds_port_general_link_up_handler(sci_port
, sci_phy
, true);
1192 * scic_sds_port_ready_operational_substate_link_down_handler() -
1193 * @sci_port: This is the struct scic_sds_port object that which has a phy that has
1195 * @sci_phy: This is the struct scic_sds_phy object that has gone link down.
1197 * This method is the ready operational substate link down handler for the
1198 * struct scic_sds_port object. This function notifies the SCI User that the phy has
1199 * gone link down and if this is the last phy in the port the port will change
1200 * state to the ready waiting substate. none
1202 static void scic_sds_port_ready_operational_substate_link_down_handler(
1203 struct scic_sds_port
*sci_port
,
1204 struct scic_sds_phy
*sci_phy
)
1206 scic_sds_port_deactivate_phy(sci_port
, sci_phy
, true);
1209 * If there are no active phys left in the port, then transition
1210 * the port to the WAITING state until such time as a phy goes
1212 if (sci_port
->active_phy_mask
== 0)
1213 port_state_machine_change(sci_port
,
1214 SCIC_SDS_PORT_READY_SUBSTATE_WAITING
);
1218 * This method is the ready operational substate start io handler for the
1219 * struct scic_sds_port object. This function incremetns the outstanding request
1220 * count for this port object. enum sci_status SCI_SUCCESS
1222 static enum sci_status
scic_sds_port_ready_operational_substate_start_io_handler(
1223 struct scic_sds_port
*port
,
1224 struct scic_sds_remote_device
*device
,
1225 struct scic_sds_request
*io_request
)
1227 port
->started_request_count
++;
1232 * scic_sds_port_ready_configuring_substate_complete_io_handler() -
1233 * @port: This is the port that is being requested to complete the io request.
1234 * @device: This is the device on which the io is completing.
1236 * This method will decrement the outstanding request count for this port. If
1237 * the request count goes to 0 then the port can be reprogrammed with its new
1240 static enum sci_status
1241 scic_sds_port_ready_configuring_substate_complete_io_handler(
1242 struct scic_sds_port
*port
,
1243 struct scic_sds_remote_device
*device
,
1244 struct scic_sds_request
*io_request
)
1246 scic_sds_port_decrement_request_count(port
);
1248 if (port
->started_request_count
== 0) {
1249 port_state_machine_change(port
,
1250 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
);
1256 static enum sci_status
default_port_handler(struct scic_sds_port
*sci_port
,
1259 dev_warn(sciport_to_dev(sci_port
),
1260 "%s: in wrong state: %d\n", func
,
1261 sci_base_state_machine_get_state(&sci_port
->state_machine
));
1262 return SCI_FAILURE_INVALID_STATE
;
1266 * This is the default method for a port unsolicited frame request. It will
1267 * report a warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE Is it even
1268 * possible to receive an unsolicited frame directed to a port object? It
1269 * seems possible if we implementing virtual functions but until then?
1271 static enum sci_status
1272 scic_sds_port_default_frame_handler(struct scic_sds_port
*sci_port
,
1275 struct scic_sds_controller
*scic
= scic_sds_port_get_controller(sci_port
);
1277 default_port_handler(sci_port
, __func__
);
1278 scic_sds_controller_release_frame(scic
, frame_index
);
1280 return SCI_FAILURE_INVALID_STATE
;
1283 static enum sci_status
scic_sds_port_default_event_handler(struct scic_sds_port
*sci_port
,
1286 return default_port_handler(sci_port
, __func__
);
1289 static void scic_sds_port_default_link_up_handler(struct scic_sds_port
*sci_port
,
1290 struct scic_sds_phy
*sci_phy
)
1292 default_port_handler(sci_port
, __func__
);
1295 static void scic_sds_port_default_link_down_handler(struct scic_sds_port
*sci_port
,
1296 struct scic_sds_phy
*sci_phy
)
1298 default_port_handler(sci_port
, __func__
);
1301 static enum sci_status
scic_sds_port_default_start_io_handler(struct scic_sds_port
*sci_port
,
1302 struct scic_sds_remote_device
*sci_dev
,
1303 struct scic_sds_request
*sci_req
)
1305 return default_port_handler(sci_port
, __func__
);
1308 static enum sci_status
scic_sds_port_default_complete_io_handler(struct scic_sds_port
*sci_port
,
1309 struct scic_sds_remote_device
*sci_dev
,
1310 struct scic_sds_request
*sci_req
)
1312 return default_port_handler(sci_port
, __func__
);
1316 * ******************************************************************************
1317 * * PORT STATE PRIVATE METHODS
1318 * ****************************************************************************** */
1322 * @sci_port: This is the struct scic_sds_port object to suspend.
1324 * This method will susped the port task scheduler for this port object. none
1327 scic_sds_port_suspend_port_task_scheduler(struct scic_sds_port
*port
)
1329 u32 pts_control_value
;
1331 pts_control_value
= readl(&port
->port_task_scheduler_registers
->control
);
1332 pts_control_value
|= SCU_PTSxCR_GEN_BIT(SUSPEND
);
1333 writel(pts_control_value
, &port
->port_task_scheduler_registers
->control
);
1337 * scic_sds_port_post_dummy_request() - post dummy/workaround request
1338 * @sci_port: port to post task
1340 * Prevent the hardware scheduler from posting new requests to the front
1341 * of the scheduler queue causing a starvation problem for currently
1345 static void scic_sds_port_post_dummy_request(struct scic_sds_port
*sci_port
)
1348 struct scu_task_context
*task_context
;
1349 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1350 u16 tci
= sci_port
->reserved_tci
;
1352 task_context
= scic_sds_controller_get_task_context_buffer(scic
, tci
);
1354 task_context
->abort
= 0;
1356 command
= SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC
|
1357 sci_port
->physical_port_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
|
1360 scic_sds_controller_post_request(scic
, command
);
1364 * This routine will abort the dummy request. This will alow the hardware to
1365 * power down parts of the silicon to save power.
1367 * @sci_port: The port on which the task must be aborted.
1370 static void scic_sds_port_abort_dummy_request(struct scic_sds_port
*sci_port
)
1372 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1373 u16 tci
= sci_port
->reserved_tci
;
1374 struct scu_task_context
*tc
;
1377 tc
= scic_sds_controller_get_task_context_buffer(scic
, tci
);
1381 command
= SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT
|
1382 sci_port
->physical_port_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
|
1385 scic_sds_controller_post_request(scic
, command
);
1390 * @sci_port: This is the struct scic_sds_port object to resume.
1392 * This method will resume the port task scheduler for this port object. none
1395 scic_sds_port_resume_port_task_scheduler(struct scic_sds_port
*port
)
1397 u32 pts_control_value
;
1399 pts_control_value
= readl(&port
->port_task_scheduler_registers
->control
);
1400 pts_control_value
&= ~SCU_PTSxCR_GEN_BIT(SUSPEND
);
1401 writel(pts_control_value
, &port
->port_task_scheduler_registers
->control
);
1405 * ******************************************************************************
1406 * * PORT READY SUBSTATE METHODS
1407 * ****************************************************************************** */
1411 * @object: This is the object which is cast to a struct scic_sds_port object.
1413 * This method will perform the actions required by the struct scic_sds_port on
1414 * entering the SCIC_SDS_PORT_READY_SUBSTATE_WAITING. This function checks the
1415 * port for any ready phys. If there is at least one phy in a ready state then
1416 * the port transitions to the ready operational substate. none
1418 static void scic_sds_port_ready_substate_waiting_enter(void *object
)
1420 struct scic_sds_port
*sci_port
= object
;
1422 scic_sds_port_set_base_state_handlers(
1423 sci_port
, SCIC_SDS_PORT_READY_SUBSTATE_WAITING
1426 scic_sds_port_suspend_port_task_scheduler(sci_port
);
1428 sci_port
->not_ready_reason
= SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS
;
1430 if (sci_port
->active_phy_mask
!= 0) {
1431 /* At least one of the phys on the port is ready */
1432 port_state_machine_change(sci_port
,
1433 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
);
1439 * @object: This is the object which is cast to a struct scic_sds_port object.
1441 * This function will perform the actions required by the struct scic_sds_port
1442 * on entering the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function sets
1443 * the state handlers for the port object, notifies the SCI User that the port
1444 * is ready, and resumes port operations. none
1446 static void scic_sds_port_ready_substate_operational_enter(void *object
)
1449 struct scic_sds_port
*sci_port
= object
;
1450 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1451 struct isci_host
*ihost
= scic_to_ihost(scic
);
1452 struct isci_port
*iport
= sci_port_to_iport(sci_port
);
1454 scic_sds_port_set_base_state_handlers(
1456 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
);
1458 isci_port_ready(ihost
, iport
);
1460 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
1461 if (sci_port
->phy_table
[index
]) {
1462 writel(sci_port
->physical_port_index
,
1463 &sci_port
->port_pe_configuration_register
[
1464 sci_port
->phy_table
[index
]->phy_index
]);
1468 scic_sds_port_update_viit_entry(sci_port
);
1470 scic_sds_port_resume_port_task_scheduler(sci_port
);
1473 * Post the dummy task for the port so the hardware can schedule
1476 scic_sds_port_post_dummy_request(sci_port
);
1479 static void scic_sds_port_invalidate_dummy_remote_node(struct scic_sds_port
*sci_port
)
1481 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1482 u8 phys_index
= sci_port
->physical_port_index
;
1483 union scu_remote_node_context
*rnc
;
1484 u16 rni
= sci_port
->reserved_rni
;
1487 rnc
= &scic
->remote_node_context_table
[rni
];
1489 rnc
->ssp
.is_valid
= false;
1491 /* ensure the preceding tc abort request has reached the
1492 * controller and give it ample time to act before posting the rnc
1495 readl(&scic
->smu_registers
->interrupt_status
); /* flush */
1498 command
= SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE
|
1499 phys_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
| rni
;
1501 scic_sds_controller_post_request(scic
, command
);
1506 * @object: This is the object which is cast to a struct scic_sds_port object.
1508 * This method will perform the actions required by the struct scic_sds_port on
1509 * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
1510 * the port not ready and suspends the port task scheduler. none
1512 static void scic_sds_port_ready_substate_operational_exit(void *object
)
1514 struct scic_sds_port
*sci_port
= object
;
1515 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1516 struct isci_host
*ihost
= scic_to_ihost(scic
);
1517 struct isci_port
*iport
= sci_port_to_iport(sci_port
);
1520 * Kill the dummy task for this port if it has not yet posted
1521 * the hardware will treat this as a NOP and just return abort
1524 scic_sds_port_abort_dummy_request(sci_port
);
1526 isci_port_not_ready(ihost
, iport
);
1528 if (sci_port
->ready_exit
)
1529 scic_sds_port_invalidate_dummy_remote_node(sci_port
);
1533 * ******************************************************************************
1534 * * PORT READY CONFIGURING METHODS
1535 * ****************************************************************************** */
1538 * scic_sds_port_ready_substate_configuring_enter() -
1539 * @object: This is the object which is cast to a struct scic_sds_port object.
1541 * This method will perform the actions required by the struct scic_sds_port on
1542 * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
1543 * the port not ready and suspends the port task scheduler. none
1545 static void scic_sds_port_ready_substate_configuring_enter(void *object
)
1547 struct scic_sds_port
*sci_port
= object
;
1548 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1549 struct isci_host
*ihost
= scic_to_ihost(scic
);
1550 struct isci_port
*iport
= sci_port_to_iport(sci_port
);
1552 scic_sds_port_set_base_state_handlers(
1554 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
);
1556 if (sci_port
->active_phy_mask
== 0) {
1557 isci_port_not_ready(ihost
, iport
);
1559 port_state_machine_change(sci_port
,
1560 SCIC_SDS_PORT_READY_SUBSTATE_WAITING
);
1561 } else if (sci_port
->started_request_count
== 0)
1562 port_state_machine_change(sci_port
,
1563 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
);
1566 static void scic_sds_port_ready_substate_configuring_exit(void *object
)
1568 struct scic_sds_port
*sci_port
= object
;
1570 scic_sds_port_suspend_port_task_scheduler(sci_port
);
1571 if (sci_port
->ready_exit
)
1572 scic_sds_port_invalidate_dummy_remote_node(sci_port
);
1575 /* --------------------------------------------------------------------------- */
1579 * @port: This is the struct scic_sds_port object on which the io request count will
1581 * @device: This is the struct scic_sds_remote_device object to which the io request
1582 * is being directed. This parameter is not required to complete this
1584 * @io_request: This is the request that is being completed on this port
1585 * object. This parameter is not required to complete this operation.
1587 * This is a general complete io request handler for the struct scic_sds_port object.
1588 * enum sci_status SCI_SUCCESS
1590 static enum sci_status
scic_sds_port_general_complete_io_handler(
1591 struct scic_sds_port
*port
,
1592 struct scic_sds_remote_device
*device
,
1593 struct scic_sds_request
*io_request
)
1595 scic_sds_port_decrement_request_count(port
);
1601 * This method takes the struct scic_sds_port that is in a stopping state and handles
1602 * the complete io request. Should the request count reach 0 then the port
1603 * object will transition to the stopped state. enum sci_status SCI_SUCCESS
1605 static enum sci_status
scic_sds_port_stopping_state_complete_io_handler(
1606 struct scic_sds_port
*sci_port
,
1607 struct scic_sds_remote_device
*device
,
1608 struct scic_sds_request
*io_request
)
1610 scic_sds_port_decrement_request_count(sci_port
);
1612 if (sci_port
->started_request_count
== 0)
1613 port_state_machine_change(sci_port
,
1614 SCI_BASE_PORT_STATE_STOPPED
);
1620 * ****************************************************************************
1621 * * RESETTING STATE HANDLERS
1622 * **************************************************************************** */
1625 * This method will transition a failed port to its ready state. The port
1626 * failed because a hard reset request timed out but at some time later one or
1627 * more phys in the port became ready. enum sci_status SCI_SUCCESS
1629 static void scic_sds_port_reset_state_link_up_handler(
1630 struct scic_sds_port
*port
,
1631 struct scic_sds_phy
*phy
)
1634 * / @todo We should make sure that the phy that has gone link up is the same
1635 * / one on which we sent the reset. It is possible that the phy on
1636 * / which we sent the reset is not the one that has gone link up and we
1637 * / want to make sure that phy being reset comes back. Consider the
1638 * / case where a reset is sent but before the hardware processes the
1639 * / reset it get a link up on the port because of a hot plug event.
1640 * / because of the reset request this phy will go link down almost
1644 * In the resetting state we don't notify the user regarding
1645 * link up and link down notifications. */
1646 scic_sds_port_general_link_up_handler(port
, phy
, false);
1650 * This method process link down notifications that occur during a port reset
1651 * operation. Link downs can occur during the reset operation. enum sci_status
1654 static void scic_sds_port_reset_state_link_down_handler(
1655 struct scic_sds_port
*port
,
1656 struct scic_sds_phy
*phy
)
1659 * In the resetting state we don't notify the user regarding
1660 * link up and link down notifications. */
1661 scic_sds_port_deactivate_phy(port
, phy
, false);
1664 enum sci_status
scic_sds_port_start(struct scic_sds_port
*sci_port
)
1666 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1667 struct isci_host
*ihost
= scic_to_ihost(scic
);
1668 enum sci_status status
= SCI_SUCCESS
;
1669 enum scic_sds_port_states state
;
1672 state
= sci_port
->state_machine
.current_state_id
;
1673 if (state
!= SCI_BASE_PORT_STATE_STOPPED
) {
1674 dev_warn(sciport_to_dev(sci_port
),
1675 "%s: in wrong state: %d\n", __func__
, state
);
1676 return SCI_FAILURE_INVALID_STATE
;
1679 if (sci_port
->assigned_device_count
> 0) {
1680 /* TODO This is a start failure operation because
1681 * there are still devices assigned to this port.
1682 * There must be no devices assigned to a port on a
1685 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
;
1688 sci_port
->timer_handle
=
1689 isci_timer_create(ihost
,
1691 scic_sds_port_timeout_handler
);
1693 if (!sci_port
->timer_handle
)
1694 return SCI_FAILURE_INSUFFICIENT_RESOURCES
;
1696 if (sci_port
->reserved_rni
== SCU_DUMMY_INDEX
) {
1697 u16 rni
= scic_sds_remote_node_table_allocate_remote_node(
1698 &scic
->available_remote_nodes
, 1);
1700 if (rni
!= SCU_DUMMY_INDEX
)
1701 scic_sds_port_construct_dummy_rnc(sci_port
, rni
);
1703 status
= SCI_FAILURE_INSUFFICIENT_RESOURCES
;
1704 sci_port
->reserved_rni
= rni
;
1707 if (sci_port
->reserved_tci
== SCU_DUMMY_INDEX
) {
1708 /* Allocate a TCI and remove the sequence nibble */
1709 u16 tci
= scic_controller_allocate_io_tag(scic
);
1711 if (tci
!= SCU_DUMMY_INDEX
)
1712 scic_sds_port_construct_dummy_task(sci_port
, tci
);
1714 status
= SCI_FAILURE_INSUFFICIENT_RESOURCES
;
1715 sci_port
->reserved_tci
= tci
;
1718 if (status
== SCI_SUCCESS
) {
1719 phy_mask
= scic_sds_port_get_phys(sci_port
);
1722 * There are one or more phys assigned to this port. Make sure
1723 * the port's phy mask is in fact legal and supported by the
1726 if (scic_sds_port_is_phy_mask_valid(sci_port
, phy_mask
) == true) {
1727 port_state_machine_change(sci_port
,
1728 SCI_BASE_PORT_STATE_READY
);
1732 status
= SCI_FAILURE
;
1735 if (status
!= SCI_SUCCESS
)
1736 scic_sds_port_destroy_dummy_resources(sci_port
);
1741 enum sci_status
scic_sds_port_stop(struct scic_sds_port
*sci_port
)
1743 enum scic_sds_port_states state
;
1745 state
= sci_port
->state_machine
.current_state_id
;
1747 case SCI_BASE_PORT_STATE_STOPPED
:
1749 case SCIC_SDS_PORT_READY_SUBSTATE_WAITING
:
1750 case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
:
1751 case SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
:
1752 case SCI_BASE_PORT_STATE_RESETTING
:
1753 port_state_machine_change(sci_port
,
1754 SCI_BASE_PORT_STATE_STOPPING
);
1757 dev_warn(sciport_to_dev(sci_port
),
1758 "%s: in wrong state: %d\n", __func__
, state
);
1759 return SCI_FAILURE_INVALID_STATE
;
1763 static enum sci_status
scic_port_hard_reset(struct scic_sds_port
*sci_port
, u32 timeout
)
1765 enum sci_status status
= SCI_FAILURE_INVALID_PHY
;
1766 struct scic_sds_phy
*selected_phy
= NULL
;
1767 enum scic_sds_port_states state
;
1770 state
= sci_port
->state_machine
.current_state_id
;
1771 if (state
!= SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
) {
1772 dev_warn(sciport_to_dev(sci_port
),
1773 "%s: in wrong state: %d\n", __func__
, state
);
1774 return SCI_FAILURE_INVALID_STATE
;
1777 /* Select a phy on which we can send the hard reset request. */
1778 for (phy_index
= 0; phy_index
< SCI_MAX_PHYS
&& !selected_phy
; phy_index
++) {
1779 selected_phy
= sci_port
->phy_table
[phy_index
];
1781 !scic_sds_port_active_phy(sci_port
, selected_phy
)) {
1783 * We found a phy but it is not ready select
1786 selected_phy
= NULL
;
1790 /* If we have a phy then go ahead and start the reset procedure */
1793 status
= scic_sds_phy_reset(selected_phy
);
1795 if (status
!= SCI_SUCCESS
)
1798 isci_timer_start(sci_port
->timer_handle
, timeout
);
1799 sci_port
->not_ready_reason
= SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED
;
1801 port_state_machine_change(sci_port
,
1802 SCI_BASE_PORT_STATE_RESETTING
);
1807 * scic_sds_port_add_phy() -
1808 * @sci_port: This parameter specifies the port in which the phy will be added.
1809 * @sci_phy: This parameter is the phy which is to be added to the port.
1811 * This method will add a PHY to the selected port. This method returns an
1812 * enum sci_status. SCI_SUCCESS the phy has been added to the port. Any other
1813 * status is a failure to add the phy to the port.
1815 enum sci_status
scic_sds_port_add_phy(struct scic_sds_port
*sci_port
,
1816 struct scic_sds_phy
*sci_phy
)
1818 enum sci_status status
;
1819 enum scic_sds_port_states state
;
1821 state
= sci_port
->state_machine
.current_state_id
;
1823 case SCI_BASE_PORT_STATE_STOPPED
: {
1824 struct sci_sas_address port_sas_address
;
1826 /* Read the port assigned SAS Address if there is one */
1827 scic_sds_port_get_sas_address(sci_port
, &port_sas_address
);
1829 if (port_sas_address
.high
!= 0 && port_sas_address
.low
!= 0) {
1830 struct sci_sas_address phy_sas_address
;
1832 /* Make sure that the PHY SAS Address matches the SAS Address
1835 scic_sds_phy_get_sas_address(sci_phy
, &phy_sas_address
);
1837 if (port_sas_address
.high
!= phy_sas_address
.high
||
1838 port_sas_address
.low
!= phy_sas_address
.low
)
1839 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
;
1841 return scic_sds_port_set_phy(sci_port
, sci_phy
);
1843 case SCIC_SDS_PORT_READY_SUBSTATE_WAITING
:
1844 case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
:
1845 status
= scic_sds_port_set_phy(sci_port
, sci_phy
);
1847 if (status
!= SCI_SUCCESS
)
1850 scic_sds_port_general_link_up_handler(sci_port
, sci_phy
, true);
1851 sci_port
->not_ready_reason
= SCIC_PORT_NOT_READY_RECONFIGURING
;
1852 port_state_machine_change(sci_port
, SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
);
1855 case SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
:
1856 status
= scic_sds_port_set_phy(sci_port
, sci_phy
);
1858 if (status
!= SCI_SUCCESS
)
1860 scic_sds_port_general_link_up_handler(sci_port
, sci_phy
, true);
1862 /* Re-enter the configuring state since this may be the last phy in
1865 port_state_machine_change(sci_port
,
1866 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
);
1869 dev_warn(sciport_to_dev(sci_port
),
1870 "%s: in wrong state: %d\n", __func__
, state
);
1871 return SCI_FAILURE_INVALID_STATE
;
1876 * scic_sds_port_remove_phy() -
1877 * @sci_port: This parameter specifies the port in which the phy will be added.
1878 * @sci_phy: This parameter is the phy which is to be added to the port.
1880 * This method will remove the PHY from the selected PORT. This method returns
1881 * an enum sci_status. SCI_SUCCESS the phy has been removed from the port. Any
1882 * other status is a failure to add the phy to the port.
1884 enum sci_status
scic_sds_port_remove_phy(struct scic_sds_port
*sci_port
,
1885 struct scic_sds_phy
*sci_phy
)
1887 enum sci_status status
;
1888 enum scic_sds_port_states state
;
1890 state
= sci_port
->state_machine
.current_state_id
;
1893 case SCI_BASE_PORT_STATE_STOPPED
:
1894 return scic_sds_port_clear_phy(sci_port
, sci_phy
);
1895 case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
:
1896 status
= scic_sds_port_clear_phy(sci_port
, sci_phy
);
1897 if (status
!= SCI_SUCCESS
)
1900 scic_sds_port_deactivate_phy(sci_port
, sci_phy
, true);
1901 sci_port
->not_ready_reason
= SCIC_PORT_NOT_READY_RECONFIGURING
;
1902 port_state_machine_change(sci_port
,
1903 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
);
1905 case SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
:
1906 status
= scic_sds_port_clear_phy(sci_port
, sci_phy
);
1908 if (status
!= SCI_SUCCESS
)
1910 scic_sds_port_deactivate_phy(sci_port
, sci_phy
, true);
1912 /* Re-enter the configuring state since this may be the last phy in
1915 port_state_machine_change(sci_port
,
1916 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
);
1920 dev_warn(sciport_to_dev(sci_port
),
1921 "%s: in wrong state: %d\n", __func__
, state
);
1922 return SCI_FAILURE_INVALID_STATE
;
1926 static struct scic_sds_port_state_handler scic_sds_port_state_handler_table
[] = {
1927 [SCI_BASE_PORT_STATE_STOPPED
] = {
1928 .frame_handler
= scic_sds_port_default_frame_handler
,
1929 .event_handler
= scic_sds_port_default_event_handler
,
1930 .link_up_handler
= scic_sds_port_default_link_up_handler
,
1931 .link_down_handler
= scic_sds_port_default_link_down_handler
,
1932 .start_io_handler
= scic_sds_port_default_start_io_handler
,
1933 .complete_io_handler
= scic_sds_port_default_complete_io_handler
1935 [SCI_BASE_PORT_STATE_STOPPING
] = {
1936 .frame_handler
= scic_sds_port_default_frame_handler
,
1937 .event_handler
= scic_sds_port_default_event_handler
,
1938 .link_up_handler
= scic_sds_port_default_link_up_handler
,
1939 .link_down_handler
= scic_sds_port_default_link_down_handler
,
1940 .start_io_handler
= scic_sds_port_default_start_io_handler
,
1941 .complete_io_handler
= scic_sds_port_stopping_state_complete_io_handler
1943 [SCI_BASE_PORT_STATE_READY
] = {
1944 .frame_handler
= scic_sds_port_default_frame_handler
,
1945 .event_handler
= scic_sds_port_default_event_handler
,
1946 .link_up_handler
= scic_sds_port_default_link_up_handler
,
1947 .link_down_handler
= scic_sds_port_default_link_down_handler
,
1948 .start_io_handler
= scic_sds_port_default_start_io_handler
,
1949 .complete_io_handler
= scic_sds_port_general_complete_io_handler
1951 [SCIC_SDS_PORT_READY_SUBSTATE_WAITING
] = {
1952 .frame_handler
= scic_sds_port_default_frame_handler
,
1953 .event_handler
= scic_sds_port_default_event_handler
,
1954 .link_up_handler
= scic_sds_port_ready_waiting_substate_link_up_handler
,
1955 .link_down_handler
= scic_sds_port_default_link_down_handler
,
1956 .start_io_handler
= scic_sds_port_ready_waiting_substate_start_io_handler
,
1957 .complete_io_handler
= scic_sds_port_ready_substate_complete_io_handler
,
1959 [SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
] = {
1960 .frame_handler
= scic_sds_port_default_frame_handler
,
1961 .event_handler
= scic_sds_port_default_event_handler
,
1962 .link_up_handler
= scic_sds_port_ready_operational_substate_link_up_handler
,
1963 .link_down_handler
= scic_sds_port_ready_operational_substate_link_down_handler
,
1964 .start_io_handler
= scic_sds_port_ready_operational_substate_start_io_handler
,
1965 .complete_io_handler
= scic_sds_port_ready_substate_complete_io_handler
,
1967 [SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
] = {
1968 .frame_handler
= scic_sds_port_default_frame_handler
,
1969 .event_handler
= scic_sds_port_default_event_handler
,
1970 .link_up_handler
= scic_sds_port_default_link_up_handler
,
1971 .link_down_handler
= scic_sds_port_default_link_down_handler
,
1972 .start_io_handler
= scic_sds_port_default_start_io_handler
,
1973 .complete_io_handler
= scic_sds_port_ready_configuring_substate_complete_io_handler
1975 [SCI_BASE_PORT_STATE_RESETTING
] = {
1976 .frame_handler
= scic_sds_port_default_frame_handler
,
1977 .event_handler
= scic_sds_port_default_event_handler
,
1978 .link_up_handler
= scic_sds_port_reset_state_link_up_handler
,
1979 .link_down_handler
= scic_sds_port_reset_state_link_down_handler
,
1980 .start_io_handler
= scic_sds_port_default_start_io_handler
,
1981 .complete_io_handler
= scic_sds_port_general_complete_io_handler
1983 [SCI_BASE_PORT_STATE_FAILED
] = {
1984 .frame_handler
= scic_sds_port_default_frame_handler
,
1985 .event_handler
= scic_sds_port_default_event_handler
,
1986 .link_up_handler
= scic_sds_port_default_link_up_handler
,
1987 .link_down_handler
= scic_sds_port_default_link_down_handler
,
1988 .start_io_handler
= scic_sds_port_default_start_io_handler
,
1989 .complete_io_handler
= scic_sds_port_general_complete_io_handler
1994 * ******************************************************************************
1995 * * PORT STATE PRIVATE METHODS
1996 * ****************************************************************************** */
2000 * @sci_port: This is the port object which to suspend.
2002 * This method will enable the SCU Port Task Scheduler for this port object but
2003 * will leave the port task scheduler in a suspended state. none
2006 scic_sds_port_enable_port_task_scheduler(struct scic_sds_port
*port
)
2008 u32 pts_control_value
;
2010 pts_control_value
= readl(&port
->port_task_scheduler_registers
->control
);
2011 pts_control_value
|= SCU_PTSxCR_GEN_BIT(ENABLE
) | SCU_PTSxCR_GEN_BIT(SUSPEND
);
2012 writel(pts_control_value
, &port
->port_task_scheduler_registers
->control
);
2017 * @sci_port: This is the port object which to resume.
2019 * This method will disable the SCU port task scheduler for this port object.
2023 scic_sds_port_disable_port_task_scheduler(struct scic_sds_port
*port
)
2025 u32 pts_control_value
;
2027 pts_control_value
= readl(&port
->port_task_scheduler_registers
->control
);
2028 pts_control_value
&=
2029 ~(SCU_PTSxCR_GEN_BIT(ENABLE
) | SCU_PTSxCR_GEN_BIT(SUSPEND
));
2030 writel(pts_control_value
, &port
->port_task_scheduler_registers
->control
);
2033 static void scic_sds_port_post_dummy_remote_node(struct scic_sds_port
*sci_port
)
2035 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
2036 u8 phys_index
= sci_port
->physical_port_index
;
2037 union scu_remote_node_context
*rnc
;
2038 u16 rni
= sci_port
->reserved_rni
;
2041 rnc
= &scic
->remote_node_context_table
[rni
];
2042 rnc
->ssp
.is_valid
= true;
2044 command
= SCU_CONTEXT_COMMAND_POST_RNC_32
|
2045 phys_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
| rni
;
2047 scic_sds_controller_post_request(scic
, command
);
2049 /* ensure hardware has seen the post rnc command and give it
2050 * ample time to act before sending the suspend
2052 readl(&scic
->smu_registers
->interrupt_status
); /* flush */
2055 command
= SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX
|
2056 phys_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
| rni
;
2058 scic_sds_controller_post_request(scic
, command
);
2062 * ******************************************************************************
2063 * * PORT STATE METHODS
2064 * ****************************************************************************** */
2068 * @object: This is the object which is cast to a struct scic_sds_port object.
2070 * This method will perform the actions required by the struct scic_sds_port on
2071 * entering the SCI_BASE_PORT_STATE_STOPPED. This function sets the stopped
2072 * state handlers for the struct scic_sds_port object and disables the port task
2073 * scheduler in the hardware. none
2075 static void scic_sds_port_stopped_state_enter(void *object
)
2077 struct scic_sds_port
*sci_port
= object
;
2079 scic_sds_port_set_base_state_handlers(
2080 sci_port
, SCI_BASE_PORT_STATE_STOPPED
2084 SCI_BASE_PORT_STATE_STOPPING
2085 == sci_port
->state_machine
.previous_state_id
2088 * If we enter this state becasuse of a request to stop
2089 * the port then we want to disable the hardwares port
2090 * task scheduler. */
2091 scic_sds_port_disable_port_task_scheduler(sci_port
);
2097 * @object: This is the object which is cast to a struct scic_sds_port object.
2099 * This method will perform the actions required by the struct scic_sds_port on
2100 * exiting the SCI_BASE_STATE_STOPPED. This function enables the SCU hardware
2101 * port task scheduler. none
2103 static void scic_sds_port_stopped_state_exit(void *object
)
2105 struct scic_sds_port
*sci_port
= object
;
2107 /* Enable and suspend the port task scheduler */
2108 scic_sds_port_enable_port_task_scheduler(sci_port
);
2112 * scic_sds_port_ready_state_enter -
2113 * @object: This is the object which is cast to a struct scic_sds_port object.
2115 * This method will perform the actions required by the struct scic_sds_port on
2116 * entering the SCI_BASE_PORT_STATE_READY. This function sets the ready state
2117 * handlers for the struct scic_sds_port object, reports the port object as
2118 * not ready and starts the ready substate machine. none
2120 static void scic_sds_port_ready_state_enter(void *object
)
2122 struct scic_sds_port
*sci_port
= object
;
2123 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
2124 struct isci_host
*ihost
= scic_to_ihost(scic
);
2125 struct isci_port
*iport
= sci_port_to_iport(sci_port
);
2128 /* Put the ready state handlers in place though they will not be there long */
2129 scic_sds_port_set_base_state_handlers(sci_port
, SCI_BASE_PORT_STATE_READY
);
2131 prev_state
= sci_port
->state_machine
.previous_state_id
;
2132 if (prev_state
== SCI_BASE_PORT_STATE_RESETTING
)
2133 isci_port_hard_reset_complete(iport
, SCI_SUCCESS
);
2135 isci_port_not_ready(ihost
, iport
);
2137 /* Post and suspend the dummy remote node context for this port. */
2138 scic_sds_port_post_dummy_remote_node(sci_port
);
2140 /* Start the ready substate machine */
2141 port_state_machine_change(sci_port
,
2142 SCIC_SDS_PORT_READY_SUBSTATE_WAITING
);
2147 * @object: This is the object which is cast to a struct scic_sds_port object.
2149 * This method will perform the actions required by the struct scic_sds_port on
2150 * entering the SCI_BASE_PORT_STATE_RESETTING. This function sets the resetting
2151 * state handlers for the struct scic_sds_port object. none
2153 static void scic_sds_port_resetting_state_enter(void *object
)
2155 struct scic_sds_port
*sci_port
= object
;
2157 scic_sds_port_set_base_state_handlers(
2158 sci_port
, SCI_BASE_PORT_STATE_RESETTING
2164 * @object: This is the object which is cast to a struct scic_sds_port object.
2166 * This function will perform the actions required by the
2167 * struct scic_sds_port on
2168 * exiting the SCI_BASE_STATE_RESETTING. This function does nothing. none
2170 static inline void scic_sds_port_resetting_state_exit(void *object
)
2172 struct scic_sds_port
*sci_port
= object
;
2174 isci_timer_stop(sci_port
->timer_handle
);
2179 * @object: This is the void object which is cast to a
2180 * struct scic_sds_port object.
2182 * This method will perform the actions required by the struct scic_sds_port on
2183 * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
2184 * state handlers for the struct scic_sds_port object. none
2186 static void scic_sds_port_stopping_state_enter(void *object
)
2188 struct scic_sds_port
*sci_port
= object
;
2190 scic_sds_port_set_base_state_handlers(
2191 sci_port
, SCI_BASE_PORT_STATE_STOPPING
2197 * @object: This is the object which is cast to a struct scic_sds_port object.
2199 * This function will perform the actions required by the
2200 * struct scic_sds_port on
2201 * exiting the SCI_BASE_STATE_STOPPING. This function does nothing. none
2204 scic_sds_port_stopping_state_exit(void *object
)
2206 struct scic_sds_port
*sci_port
= object
;
2208 isci_timer_stop(sci_port
->timer_handle
);
2210 scic_sds_port_destroy_dummy_resources(sci_port
);
2215 * @object: This is the object which is cast to a struct scic_sds_port object.
2217 * This function will perform the actions required by the
2218 * struct scic_sds_port on
2219 * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
2220 * state handlers for the struct scic_sds_port object. none
2222 static void scic_sds_port_failed_state_enter(void *object
)
2224 struct scic_sds_port
*sci_port
= object
;
2225 struct isci_port
*iport
= sci_port_to_iport(sci_port
);
2227 scic_sds_port_set_base_state_handlers(sci_port
,
2228 SCI_BASE_PORT_STATE_FAILED
);
2230 isci_port_hard_reset_complete(iport
, SCI_FAILURE_TIMEOUT
);
2233 /* --------------------------------------------------------------------------- */
2235 static const struct sci_base_state scic_sds_port_state_table
[] = {
2236 [SCI_BASE_PORT_STATE_STOPPED
] = {
2237 .enter_state
= scic_sds_port_stopped_state_enter
,
2238 .exit_state
= scic_sds_port_stopped_state_exit
2240 [SCI_BASE_PORT_STATE_STOPPING
] = {
2241 .enter_state
= scic_sds_port_stopping_state_enter
,
2242 .exit_state
= scic_sds_port_stopping_state_exit
2244 [SCI_BASE_PORT_STATE_READY
] = {
2245 .enter_state
= scic_sds_port_ready_state_enter
,
2247 [SCIC_SDS_PORT_READY_SUBSTATE_WAITING
] = {
2248 .enter_state
= scic_sds_port_ready_substate_waiting_enter
,
2250 [SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
] = {
2251 .enter_state
= scic_sds_port_ready_substate_operational_enter
,
2252 .exit_state
= scic_sds_port_ready_substate_operational_exit
2254 [SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
] = {
2255 .enter_state
= scic_sds_port_ready_substate_configuring_enter
,
2256 .exit_state
= scic_sds_port_ready_substate_configuring_exit
2258 [SCI_BASE_PORT_STATE_RESETTING
] = {
2259 .enter_state
= scic_sds_port_resetting_state_enter
,
2260 .exit_state
= scic_sds_port_resetting_state_exit
2262 [SCI_BASE_PORT_STATE_FAILED
] = {
2263 .enter_state
= scic_sds_port_failed_state_enter
,
2267 void scic_sds_port_construct(struct scic_sds_port
*sci_port
, u8 index
,
2268 struct scic_sds_controller
*scic
)
2270 sci_base_state_machine_construct(&sci_port
->state_machine
,
2272 scic_sds_port_state_table
,
2273 SCI_BASE_PORT_STATE_STOPPED
);
2275 sci_base_state_machine_start(&sci_port
->state_machine
);
2277 sci_port
->logical_port_index
= SCIC_SDS_DUMMY_PORT
;
2278 sci_port
->physical_port_index
= index
;
2279 sci_port
->active_phy_mask
= 0;
2280 sci_port
->ready_exit
= false;
2282 sci_port
->owning_controller
= scic
;
2284 sci_port
->started_request_count
= 0;
2285 sci_port
->assigned_device_count
= 0;
2287 sci_port
->reserved_rni
= SCU_DUMMY_INDEX
;
2288 sci_port
->reserved_tci
= SCU_DUMMY_INDEX
;
2290 sci_port
->timer_handle
= NULL
;
2291 sci_port
->port_task_scheduler_registers
= NULL
;
2293 for (index
= 0; index
< SCI_MAX_PHYS
; index
++)
2294 sci_port
->phy_table
[index
] = NULL
;
2297 void isci_port_init(struct isci_port
*iport
, struct isci_host
*ihost
, int index
)
2299 INIT_LIST_HEAD(&iport
->remote_dev_list
);
2300 INIT_LIST_HEAD(&iport
->domain_dev_list
);
2301 spin_lock_init(&iport
->state_lock
);
2302 init_completion(&iport
->start_complete
);
2303 iport
->isci_host
= ihost
;
2304 isci_port_change_state(iport
, isci_freed
);
2308 * isci_port_get_state() - This function gets the status of the port object.
2309 * @isci_port: This parameter points to the isci_port object
2311 * status of the object as a isci_status enum.
2313 enum isci_status
isci_port_get_state(
2314 struct isci_port
*isci_port
)
2316 return isci_port
->status
;
2319 static void isci_port_bc_change_received(struct isci_host
*ihost
,
2320 struct scic_sds_port
*sci_port
,
2321 struct scic_sds_phy
*sci_phy
)
2323 struct isci_phy
*iphy
= sci_phy_to_iphy(sci_phy
);
2325 dev_dbg(&ihost
->pdev
->dev
, "%s: iphy = %p, sas_phy = %p\n",
2326 __func__
, iphy
, &iphy
->sas_phy
);
2328 ihost
->sas_ha
.notify_port_event(&iphy
->sas_phy
, PORTE_BROADCAST_RCVD
);
2329 scic_port_enable_broadcast_change_notification(sci_port
);
2332 void scic_sds_port_broadcast_change_received(
2333 struct scic_sds_port
*sci_port
,
2334 struct scic_sds_phy
*sci_phy
)
2336 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
2337 struct isci_host
*ihost
= scic_to_ihost(scic
);
2339 /* notify the user. */
2340 isci_port_bc_change_received(ihost
, sci_port
, sci_phy
);
2343 int isci_port_perform_hard_reset(struct isci_host
*ihost
, struct isci_port
*iport
,
2344 struct isci_phy
*iphy
)
2346 unsigned long flags
;
2347 enum sci_status status
;
2348 int ret
= TMF_RESP_FUNC_COMPLETE
;
2350 dev_dbg(&ihost
->pdev
->dev
, "%s: iport = %p\n",
2353 init_completion(&iport
->hard_reset_complete
);
2355 spin_lock_irqsave(&ihost
->scic_lock
, flags
);
2357 #define ISCI_PORT_RESET_TIMEOUT SCIC_SDS_SIGNATURE_FIS_TIMEOUT
2358 status
= scic_port_hard_reset(&iport
->sci
, ISCI_PORT_RESET_TIMEOUT
);
2360 spin_unlock_irqrestore(&ihost
->scic_lock
, flags
);
2362 if (status
== SCI_SUCCESS
) {
2363 wait_for_completion(&iport
->hard_reset_complete
);
2365 dev_dbg(&ihost
->pdev
->dev
,
2366 "%s: iport = %p; hard reset completion\n",
2369 if (iport
->hard_reset_status
!= SCI_SUCCESS
)
2370 ret
= TMF_RESP_FUNC_FAILED
;
2372 ret
= TMF_RESP_FUNC_FAILED
;
2374 dev_err(&ihost
->pdev
->dev
,
2375 "%s: iport = %p; scic_port_hard_reset call"
2377 __func__
, iport
, status
);
2381 /* If the hard reset for the port has failed, consider this
2382 * the same as link failures on all phys in the port.
2384 if (ret
!= TMF_RESP_FUNC_COMPLETE
) {
2385 dev_err(&ihost
->pdev
->dev
,
2386 "%s: iport = %p; hard reset failed "
2387 "(0x%x) - sending link down to libsas for phy %p\n",
2388 __func__
, iport
, iport
->hard_reset_status
, iphy
);
2390 isci_port_link_down(ihost
, iphy
, iport
);
2397 * isci_port_deformed() - This function is called by libsas when a port becomes
2399 * @phy: This parameter specifies the libsas phy with the inactive port.
2402 void isci_port_deformed(struct asd_sas_phy
*phy
)
2404 pr_debug("%s: sas_phy = %p\n", __func__
, phy
);
2408 * isci_port_formed() - This function is called by libsas when a port becomes
2410 * @phy: This parameter specifies the libsas phy with the active port.
2413 void isci_port_formed(struct asd_sas_phy
*phy
)
2415 pr_debug("%s: sas_phy = %p, sas_port = %p\n", __func__
, phy
, phy
->port
);