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.
56 #include "scic_controller.h"
58 #include "scic_port.h"
59 #include "scic_sds_controller.h"
60 #include "scic_sds_phy.h"
61 #include "scic_sds_port.h"
62 #include "remote_device.h"
63 #include "remote_node_context.h"
64 #include "scic_sds_request.h"
65 #include "sci_environment.h"
66 #include "scu_registers.h"
69 #define SCIC_SDS_PORT_MIN_TIMER_COUNT (SCI_MAX_PORTS)
70 #define SCIC_SDS_PORT_MAX_TIMER_COUNT (SCI_MAX_PORTS)
72 #define SCIC_SDS_PORT_HARD_RESET_TIMEOUT (1000)
73 #define SCU_DUMMY_INDEX (0xFFFF)
78 * @sci_port: This is the port object to which the phy is being assigned.
79 * @phy_index: This is the phy index that is being assigned to the port.
81 * This method will return a true value if the specified phy can be assigned to
82 * this port The following is a list of phys for each port that are allowed: -
83 * Port 0 - 3 2 1 0 - Port 1 - 1 - Port 2 - 3 2 - Port 3 - 3 This method
84 * doesn't preclude all configurations. It merely ensures that a phy is part
85 * of the allowable set of phy identifiers for that port. For example, one
86 * could assign phy 3 to port 0 and no other phys. Please refer to
87 * scic_sds_port_is_phy_mask_valid() for information regarding whether the
88 * phy_mask for a port can be supported. bool true if this is a valid phy
89 * assignment for the port false if this is not a valid phy assignment for the
92 bool scic_sds_port_is_valid_phy_assignment(
93 struct scic_sds_port
*sci_port
,
96 /* Initialize to invalid value. */
97 u32 existing_phy_index
= SCI_MAX_PHYS
;
100 if ((sci_port
->physical_port_index
== 1) && (phy_index
!= 1)) {
104 if (sci_port
->physical_port_index
== 3 && phy_index
!= 3) {
109 (sci_port
->physical_port_index
== 2)
110 && ((phy_index
== 0) || (phy_index
== 1))
115 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
116 if ((sci_port
->phy_table
[index
] != NULL
)
117 && (index
!= phy_index
)) {
118 existing_phy_index
= index
;
123 * Ensure that all of the phys in the port are capable of
124 * operating at the same maximum link rate. */
126 (existing_phy_index
< SCI_MAX_PHYS
)
127 && (sci_port
->owning_controller
->user_parameters
.sds1
.phys
[
128 phy_index
].max_speed_generation
!=
129 sci_port
->owning_controller
->user_parameters
.sds1
.phys
[
130 existing_phy_index
].max_speed_generation
)
138 * This method requests a list (mask) of the phys contained in the supplied SAS
140 * @sci_port: a handle corresponding to the SAS port for which to return the
143 * Return a bit mask indicating which phys are a part of this port. Each bit
144 * corresponds to a phy identifier (e.g. bit 0 = phy id 0).
146 static u32
scic_sds_port_get_phys(struct scic_sds_port
*sci_port
)
153 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
154 if (sci_port
->phy_table
[index
] != NULL
) {
155 mask
|= (1 << index
);
164 * @sci_port: This is the port object for which to determine if the phy mask
167 * This method will return a true value if the port's phy mask can be supported
168 * by the SCU. The following is a list of valid PHY mask configurations for
169 * each port: - Port 0 - [[3 2] 1] 0 - Port 1 - [1] - Port 2 - [[3] 2]
170 * - Port 3 - [3] This method returns a boolean indication specifying if the
171 * phy mask can be supported. true if this is a valid phy assignment for the
172 * port false if this is not a valid phy assignment for the port
174 static bool scic_sds_port_is_phy_mask_valid(
175 struct scic_sds_port
*sci_port
,
178 if (sci_port
->physical_port_index
== 0) {
179 if (((phy_mask
& 0x0F) == 0x0F)
180 || ((phy_mask
& 0x03) == 0x03)
181 || ((phy_mask
& 0x01) == 0x01)
184 } else if (sci_port
->physical_port_index
== 1) {
185 if (((phy_mask
& 0x02) == 0x02)
188 } else if (sci_port
->physical_port_index
== 2) {
189 if (((phy_mask
& 0x0C) == 0x0C)
190 || ((phy_mask
& 0x04) == 0x04)
193 } else if (sci_port
->physical_port_index
== 3) {
194 if (((phy_mask
& 0x08) == 0x08)
204 * @sci_port: This parameter specifies the port from which to return a
207 * This method retrieves a currently active (i.e. connected) phy contained in
208 * the port. Currently, the lowest order phy that is connected is returned.
209 * This method returns a pointer to a SCIS_SDS_PHY object. NULL This value is
210 * returned if there are no currently active (i.e. connected to a remote end
211 * point) phys contained in the port. All other values specify a struct scic_sds_phy
212 * object that is active in the port.
214 static struct scic_sds_phy
*scic_sds_port_get_a_connected_phy(
215 struct scic_sds_port
*sci_port
218 struct scic_sds_phy
*phy
;
220 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
222 * Ensure that the phy is both part of the port and currently
223 * connected to the remote end-point. */
224 phy
= sci_port
->phy_table
[index
];
227 && scic_sds_port_active_phy(sci_port
, phy
)
237 * scic_sds_port_set_phy() -
238 * @out]: port The port object to which the phy assignement is being made.
239 * @out]: phy The phy which is being assigned to the port.
241 * This method attempts to make the assignment of the phy to the port. If
242 * successful the phy is assigned to the ports phy table. bool true if the phy
243 * assignment can be made. false if the phy assignement can not be made. This
244 * is a functional test that only fails if the phy is currently assigned to a
247 static enum sci_status
scic_sds_port_set_phy(
248 struct scic_sds_port
*port
,
249 struct scic_sds_phy
*phy
)
252 * Check to see if we can add this phy to a port
253 * that means that the phy is not part of a port and that the port does
254 * not already have a phy assinged to the phy index. */
256 (port
->phy_table
[phy
->phy_index
] == NULL
)
257 && (scic_sds_phy_get_port(phy
) == NULL
)
258 && scic_sds_port_is_valid_phy_assignment(port
, phy
->phy_index
)
261 * Phy is being added in the stopped state so we are in MPC mode
262 * make logical port index = physical port index */
263 port
->logical_port_index
= port
->physical_port_index
;
264 port
->phy_table
[phy
->phy_index
] = phy
;
265 scic_sds_phy_set_port(phy
, port
);
274 * scic_sds_port_clear_phy() -
275 * @out]: port The port from which the phy is being cleared.
276 * @out]: phy The phy being cleared from the port.
278 * This method will clear the phy assigned to this port. This method fails if
279 * this phy is not currently assinged to this port. bool true if the phy is
280 * removed from the port. false if this phy is not assined to this port.
282 static enum sci_status
scic_sds_port_clear_phy(
283 struct scic_sds_port
*port
,
284 struct scic_sds_phy
*phy
)
286 /* Make sure that this phy is part of this port */
287 if (port
->phy_table
[phy
->phy_index
] == phy
&&
288 scic_sds_phy_get_port(phy
) == port
) {
289 struct scic_sds_controller
*scic
= port
->owning_controller
;
290 struct isci_host
*ihost
= scic_to_ihost(scic
);
292 /* Yep it is assigned to this port so remove it */
293 scic_sds_phy_set_port(phy
, &ihost
->ports
[SCI_MAX_PORTS
].sci
);
294 port
->phy_table
[phy
->phy_index
] = NULL
;
302 * scic_sds_port_add_phy() -
303 * @sci_port: This parameter specifies the port in which the phy will be added.
304 * @sci_phy: This parameter is the phy which is to be added to the port.
306 * This method will add a PHY to the selected port. This method returns an
307 * enum sci_status. SCI_SUCCESS the phy has been added to the port. Any other status
308 * is failre to add the phy to the port.
310 enum sci_status
scic_sds_port_add_phy(
311 struct scic_sds_port
*sci_port
,
312 struct scic_sds_phy
*sci_phy
)
314 return sci_port
->state_handlers
->add_phy_handler(
320 * scic_sds_port_remove_phy() -
321 * @sci_port: This parameter specifies the port in which the phy will be added.
322 * @sci_phy: This parameter is the phy which is to be added to the port.
324 * This method will remove the PHY from the selected PORT. This method returns
325 * an enum sci_status. SCI_SUCCESS the phy has been removed from the port. Any other
326 * status is failre to add the phy to the port.
328 enum sci_status
scic_sds_port_remove_phy(
329 struct scic_sds_port
*sci_port
,
330 struct scic_sds_phy
*sci_phy
)
332 return sci_port
->state_handlers
->remove_phy_handler(
337 * This method requests the SAS address for the supplied SAS port from the SCI
339 * @sci_port: a handle corresponding to the SAS port for which to return the
341 * @sas_address: This parameter specifies a pointer to a SAS address structure
342 * into which the core will copy the SAS address for the port.
345 void scic_sds_port_get_sas_address(
346 struct scic_sds_port
*sci_port
,
347 struct sci_sas_address
*sas_address
)
351 sas_address
->high
= 0;
352 sas_address
->low
= 0;
354 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
355 if (sci_port
->phy_table
[index
] != NULL
) {
356 scic_sds_phy_get_sas_address(sci_port
->phy_table
[index
], sas_address
);
362 * This function will indicate which protocols are supported by this port.
363 * @sci_port: a handle corresponding to the SAS port for which to return the
364 * supported protocols.
365 * @protocols: This parameter specifies a pointer to a data structure
366 * which the core will copy the protocol values for the port from the
367 * transmit_identification register.
370 scic_sds_port_get_protocols(struct scic_sds_port
*sci_port
,
371 struct scic_phy_proto
*protocols
)
377 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
378 if (sci_port
->phy_table
[index
] != NULL
) {
379 scic_sds_phy_get_protocols(sci_port
->phy_table
[index
],
386 * This function requests the SAS address for the device directly attached to
388 * @sci_port: a handle corresponding to the SAS port for which to return the
390 * @sas_address: This parameter specifies a pointer to a SAS address structure
391 * into which the core will copy the SAS address for the device directly
392 * attached to the port.
395 void scic_sds_port_get_attached_sas_address(
396 struct scic_sds_port
*sci_port
,
397 struct sci_sas_address
*sas_address
)
399 struct scic_sds_phy
*sci_phy
;
402 * Ensure that the phy is both part of the port and currently
403 * connected to the remote end-point.
405 sci_phy
= scic_sds_port_get_a_connected_phy(sci_port
);
407 if (sci_phy
->protocol
!= SCIC_SDS_PHY_PROTOCOL_SATA
) {
408 scic_sds_phy_get_attached_sas_address(sci_phy
,
411 scic_sds_phy_get_sas_address(sci_phy
, sas_address
);
412 sas_address
->low
+= sci_phy
->phy_index
;
415 sas_address
->high
= 0;
416 sas_address
->low
= 0;
421 * scic_sds_port_construct_dummy_rnc() - create dummy rnc for si workaround
423 * @sci_port: logical port on which we need to create the remote node context
424 * @rni: remote node index for this remote node context.
426 * This routine will construct a dummy remote node context data structure
427 * This structure will be posted to the hardware to work around a scheduler
428 * error in the hardware.
430 static void scic_sds_port_construct_dummy_rnc(struct scic_sds_port
*sci_port
, u16 rni
)
432 union scu_remote_node_context
*rnc
;
434 rnc
= &sci_port
->owning_controller
->remote_node_context_table
[rni
];
436 memset(rnc
, 0, sizeof(union scu_remote_node_context
));
438 rnc
->ssp
.remote_sas_address_hi
= 0;
439 rnc
->ssp
.remote_sas_address_lo
= 0;
441 rnc
->ssp
.remote_node_index
= rni
;
442 rnc
->ssp
.remote_node_port_width
= 1;
443 rnc
->ssp
.logical_port_index
= sci_port
->physical_port_index
;
445 rnc
->ssp
.nexus_loss_timer_enable
= false;
446 rnc
->ssp
.check_bit
= false;
447 rnc
->ssp
.is_valid
= true;
448 rnc
->ssp
.is_remote_node_context
= true;
449 rnc
->ssp
.function_number
= 0;
450 rnc
->ssp
.arbitration_wait_time
= 0;
454 * scic_sds_port_construct_dummy_task() - create dummy task for si workaround
455 * @sci_port The logical port on which we need to create the
456 * remote node context.
458 * @tci The remote node index for this remote node context.
460 * This routine will construct a dummy task context data structure. This
461 * structure will be posted to the hardwre to work around a scheduler error
465 static void scic_sds_port_construct_dummy_task(struct scic_sds_port
*sci_port
, u16 tci
)
467 struct scu_task_context
*task_context
;
469 task_context
= scic_sds_controller_get_task_context_buffer(sci_port
->owning_controller
, tci
);
471 memset(task_context
, 0, sizeof(struct scu_task_context
));
473 task_context
->abort
= 0;
474 task_context
->priority
= 0;
475 task_context
->initiator_request
= 1;
476 task_context
->connection_rate
= 1;
477 task_context
->protocol_engine_index
= 0;
478 task_context
->logical_port_index
= sci_port
->physical_port_index
;
479 task_context
->protocol_type
= SCU_TASK_CONTEXT_PROTOCOL_SSP
;
480 task_context
->task_index
= scic_sds_io_tag_get_index(tci
);
481 task_context
->valid
= SCU_TASK_CONTEXT_VALID
;
482 task_context
->context_type
= SCU_TASK_CONTEXT_TYPE
;
484 task_context
->remote_node_index
= sci_port
->reserved_rni
;
485 task_context
->command_code
= 0;
487 task_context
->link_layer_control
= 0;
488 task_context
->do_not_dma_ssp_good_response
= 1;
489 task_context
->strict_ordering
= 0;
490 task_context
->control_frame
= 0;
491 task_context
->timeout_enable
= 0;
492 task_context
->block_guard_enable
= 0;
494 task_context
->address_modifier
= 0;
496 task_context
->task_phase
= 0x01;
499 static void scic_sds_port_destroy_dummy_resources(struct scic_sds_port
*sci_port
)
501 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
503 if (sci_port
->reserved_tci
!= SCU_DUMMY_INDEX
)
504 scic_controller_free_io_tag(scic
, sci_port
->reserved_tci
);
506 if (sci_port
->reserved_rni
!= SCU_DUMMY_INDEX
)
507 scic_sds_remote_node_table_release_remote_node_index(&scic
->available_remote_nodes
,
508 1, sci_port
->reserved_rni
);
510 sci_port
->reserved_rni
= SCU_DUMMY_INDEX
;
511 sci_port
->reserved_tci
= SCU_DUMMY_INDEX
;
515 * This method performs initialization of the supplied port. Initialization
516 * includes: - state machine initialization - member variable initialization
517 * - configuring the phy_mask
519 * @transport_layer_registers:
520 * @port_task_scheduler_registers:
521 * @port_configuration_regsiter:
523 * enum sci_status SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION This value is returned
524 * if the phy being added to the port
526 enum sci_status
scic_sds_port_initialize(
527 struct scic_sds_port
*sci_port
,
528 void __iomem
*port_task_scheduler_registers
,
529 void __iomem
*port_configuration_regsiter
,
530 void __iomem
*viit_registers
)
532 sci_port
->port_task_scheduler_registers
= port_task_scheduler_registers
;
533 sci_port
->port_pe_configuration_register
= port_configuration_regsiter
;
534 sci_port
->viit_registers
= viit_registers
;
540 * scic_port_get_properties() - This method simply returns the properties
541 * regarding the port, such as: physical index, protocols, sas address, etc.
542 * @port: this parameter specifies the port for which to retrieve the physical
544 * @properties: This parameter specifies the properties structure into which to
545 * copy the requested information.
547 * Indicate if the user specified a valid port. SCI_SUCCESS This value is
548 * returned if the specified port was valid. SCI_FAILURE_INVALID_PORT This
549 * value is returned if the specified port is not valid. When this value is
550 * returned, no data is copied to the properties output parameter.
552 enum sci_status
scic_port_get_properties(
553 struct scic_sds_port
*port
,
554 struct scic_port_properties
*prop
)
556 if ((port
== NULL
) ||
557 (port
->logical_port_index
== SCIC_SDS_DUMMY_PORT
))
558 return SCI_FAILURE_INVALID_PORT
;
560 prop
->index
= port
->logical_port_index
;
561 prop
->phy_mask
= scic_sds_port_get_phys(port
);
562 scic_sds_port_get_sas_address(port
, &prop
->local
.sas_address
);
563 scic_sds_port_get_protocols(port
, &prop
->local
.protocols
);
564 scic_sds_port_get_attached_sas_address(port
, &prop
->remote
.sas_address
);
570 * scic_port_hard_reset() - perform port hard reset
571 * @port: a handle corresponding to the SAS port to be hard reset.
572 * @reset_timeout: This parameter specifies the number of milliseconds in which
573 * the port reset operation should complete.
575 * The SCI User callback in scic_user_callbacks_t will only be called once for
576 * each phy in the SAS Port at completion of the hard reset sequence. Return a
577 * status indicating whether the hard reset started successfully. SCI_SUCCESS
578 * This value is returned if the hard reset operation started successfully.
580 enum sci_status
scic_port_hard_reset(
581 struct scic_sds_port
*port
,
584 return port
->state_handlers
->reset_handler(
585 port
, reset_timeout
);
589 * This method assigns the direct attached device ID for this port.
591 * @param[in] sci_port The port for which the direct attached device id is to
593 * @param[in] device_id The direct attached device ID to assign to the port.
594 * This will be the RNi for the device
596 void scic_sds_port_setup_transports(
597 struct scic_sds_port
*sci_port
,
602 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
603 if (sci_port
->active_phy_mask
& (1 << index
))
604 scic_sds_phy_setup_transport(sci_port
->phy_table
[index
], device_id
);
610 * @sci_port: This is the port on which the phy should be enabled.
611 * @sci_phy: This is the specific phy which to enable.
612 * @do_notify_user: This parameter specifies whether to inform the user (via
613 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
615 * This function will activate the phy in the port.
616 * Activation includes: - adding
617 * the phy to the port - enabling the Protocol Engine in the silicon. -
618 * notifying the user that the link is up. none
620 static void scic_sds_port_activate_phy(struct scic_sds_port
*sci_port
,
621 struct scic_sds_phy
*sci_phy
,
624 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
625 struct isci_host
*ihost
= scic_to_ihost(scic
);
627 if (sci_phy
->protocol
!= SCIC_SDS_PHY_PROTOCOL_SATA
)
628 scic_sds_phy_resume(sci_phy
);
630 sci_port
->active_phy_mask
|= 1 << sci_phy
->phy_index
;
632 scic_sds_controller_clear_invalid_phy(scic
, sci_phy
);
634 if (do_notify_user
== true)
635 isci_port_link_up(ihost
, sci_port
, sci_phy
);
638 void scic_sds_port_deactivate_phy(struct scic_sds_port
*sci_port
,
639 struct scic_sds_phy
*sci_phy
,
642 struct scic_sds_controller
*scic
= scic_sds_port_get_controller(sci_port
);
643 struct isci_port
*iport
= sci_port_to_iport(sci_port
);
644 struct isci_host
*ihost
= scic_to_ihost(scic
);
645 struct isci_phy
*iphy
= sci_phy_to_iphy(sci_phy
);
647 sci_port
->active_phy_mask
&= ~(1 << sci_phy
->phy_index
);
649 sci_phy
->max_negotiated_speed
= SAS_LINK_RATE_UNKNOWN
;
651 /* Re-assign the phy back to the LP as if it were a narrow port */
652 writel(sci_phy
->phy_index
,
653 &sci_port
->port_pe_configuration_register
[sci_phy
->phy_index
]);
655 if (do_notify_user
== true)
656 isci_port_link_down(ihost
, iphy
, iport
);
661 * @sci_port: This is the port on which the phy should be disabled.
662 * @sci_phy: This is the specific phy which to disabled.
664 * This function will disable the phy and report that the phy is not valid for
665 * this port object. None
667 static void scic_sds_port_invalid_link_up(struct scic_sds_port
*sci_port
,
668 struct scic_sds_phy
*sci_phy
)
670 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
673 * Check to see if we have alreay reported this link as bad and if
674 * not go ahead and tell the SCI_USER that we have discovered an
677 if ((scic
->invalid_phy_mask
& (1 << sci_phy
->phy_index
)) == 0) {
678 scic_sds_controller_set_invalid_phy(scic
, sci_phy
);
679 dev_warn(&scic_to_ihost(scic
)->pdev
->dev
, "Invalid link up!\n");
684 * scic_sds_port_general_link_up_handler - phy can be assigned to port?
685 * @sci_port: scic_sds_port object for which has a phy that has gone link up.
686 * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
687 * @do_notify_user: This parameter specifies whether to inform the user (via
688 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
690 * Determine if this phy can be assigned to this
691 * port . If the phy is not a valid PHY for
692 * this port then the function will notify the user. A PHY can only be
693 * part of a port if it's attached SAS ADDRESS is the same as all other PHYs in
694 * the same port. none
696 static void scic_sds_port_general_link_up_handler(struct scic_sds_port
*sci_port
,
697 struct scic_sds_phy
*sci_phy
,
700 struct sci_sas_address port_sas_address
;
701 struct sci_sas_address phy_sas_address
;
703 scic_sds_port_get_attached_sas_address(sci_port
, &port_sas_address
);
704 scic_sds_phy_get_attached_sas_address(sci_phy
, &phy_sas_address
);
706 /* If the SAS address of the new phy matches the SAS address of
707 * other phys in the port OR this is the first phy in the port,
708 * then activate the phy and allow it to be used for operations
711 if ((phy_sas_address
.high
== port_sas_address
.high
&&
712 phy_sas_address
.low
== port_sas_address
.low
) ||
713 sci_port
->active_phy_mask
== 0) {
714 struct sci_base_state_machine
*sm
= &sci_port
->state_machine
;
716 scic_sds_port_activate_phy(sci_port
, sci_phy
, do_notify_user
);
717 if (sm
->current_state_id
== SCI_BASE_PORT_STATE_RESETTING
)
718 sci_base_state_machine_change_state(sm
, SCI_BASE_PORT_STATE_READY
);
720 scic_sds_port_invalid_link_up(sci_port
, sci_phy
);
726 * This method returns false if the port only has a single phy object assigned.
727 * If there are no phys or more than one phy then the method will return
729 * @sci_port: The port for which the wide port condition is to be checked.
731 * bool true Is returned if this is a wide ported port. false Is returned if
732 * this is a narrow port.
734 static bool scic_sds_port_is_wide(struct scic_sds_port
*sci_port
)
739 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
740 if (sci_port
->phy_table
[index
] != NULL
) {
745 return phy_count
!= 1;
749 * This method is called by the PHY object when the link is detected. if the
750 * port wants the PHY to continue on to the link up state then the port
751 * layer must return true. If the port object returns false the phy object
752 * must halt its attempt to go link up.
753 * @sci_port: The port associated with the phy object.
754 * @sci_phy: The phy object that is trying to go link up.
756 * true if the phy object can continue to the link up condition. true Is
757 * returned if this phy can continue to the ready state. false Is returned if
758 * can not continue on to the ready state. This notification is in place for
759 * wide ports and direct attached phys. Since there are no wide ported SATA
760 * devices this could become an invalid port configuration.
762 bool scic_sds_port_link_detected(
763 struct scic_sds_port
*sci_port
,
764 struct scic_sds_phy
*sci_phy
)
766 if ((sci_port
->logical_port_index
!= SCIC_SDS_DUMMY_PORT
) &&
767 (sci_phy
->protocol
== SCIC_SDS_PHY_PROTOCOL_SATA
) &&
768 scic_sds_port_is_wide(sci_port
)) {
769 scic_sds_port_invalid_link_up(sci_port
, sci_phy
);
778 * This method is the entry point for the phy to inform the port that it is now
784 void scic_sds_port_link_up(
785 struct scic_sds_port
*sci_port
,
786 struct scic_sds_phy
*sci_phy
)
788 sci_phy
->is_in_link_training
= false;
790 sci_port
->state_handlers
->link_up_handler(sci_port
, sci_phy
);
794 * This method is the entry point for the phy to inform the port that it is no
795 * longer in a ready state
800 void scic_sds_port_link_down(
801 struct scic_sds_port
*sci_port
,
802 struct scic_sds_phy
*sci_phy
)
804 sci_port
->state_handlers
->link_down_handler(sci_port
, sci_phy
);
808 * This method is called to start an IO request on this port.
815 enum sci_status
scic_sds_port_start_io(
816 struct scic_sds_port
*sci_port
,
817 struct scic_sds_remote_device
*sci_dev
,
818 struct scic_sds_request
*sci_req
)
820 return sci_port
->state_handlers
->start_io_handler(
821 sci_port
, sci_dev
, sci_req
);
825 * This method is called to complete an IO request to the port.
832 enum sci_status
scic_sds_port_complete_io(
833 struct scic_sds_port
*sci_port
,
834 struct scic_sds_remote_device
*sci_dev
,
835 struct scic_sds_request
*sci_req
)
837 return sci_port
->state_handlers
->complete_io_handler(
838 sci_port
, sci_dev
, sci_req
);
842 * This method is provided to timeout requests for port operations. Mostly its
843 * for the port reset operation.
847 static void scic_sds_port_timeout_handler(void *port
)
849 struct scic_sds_port
*sci_port
= port
;
852 current_state
= sci_base_state_machine_get_state(
853 &sci_port
->state_machine
);
855 if (current_state
== SCI_BASE_PORT_STATE_RESETTING
) {
857 * if the port is still in the resetting state then the
858 * timeout fired before the reset completed.
860 sci_base_state_machine_change_state(
861 &sci_port
->state_machine
,
862 SCI_BASE_PORT_STATE_FAILED
);
863 } else if (current_state
== SCI_BASE_PORT_STATE_STOPPED
) {
865 * if the port is stopped then the start request failed
866 * In this case stay in the stopped state.
868 dev_err(sciport_to_dev(sci_port
),
869 "%s: SCIC Port 0x%p failed to stop before tiemout.\n",
872 } else if (current_state
== SCI_BASE_PORT_STATE_STOPPING
) {
874 * if the port is still stopping then the stop has not
877 isci_port_stop_complete(
878 scic_sds_port_get_controller(sci_port
),
880 SCI_FAILURE_TIMEOUT
);
883 * The port is in the ready state and we have a timer
884 * reporting a timeout this should not happen.
886 dev_err(sciport_to_dev(sci_port
),
887 "%s: SCIC Port 0x%p is processing a timeout operation "
895 /* --------------------------------------------------------------------------- */
898 * This function updates the hardwares VIIT entry for this port.
902 static void scic_sds_port_update_viit_entry(struct scic_sds_port
*sci_port
)
904 struct sci_sas_address sas_address
;
906 scic_sds_port_get_sas_address(sci_port
, &sas_address
);
908 writel(sas_address
.high
,
909 &sci_port
->viit_registers
->initiator_sas_address_hi
);
910 writel(sas_address
.low
,
911 &sci_port
->viit_registers
->initiator_sas_address_lo
);
913 /* This value get cleared just in case its not already cleared */
914 writel(0, &sci_port
->viit_registers
->reserved
);
916 /* We are required to update the status register last */
917 writel(SCU_VIIT_ENTRY_ID_VIIT
|
918 SCU_VIIT_IPPT_INITIATOR
|
919 ((1 << sci_port
->physical_port_index
) << SCU_VIIT_ENTRY_LPVIE_SHIFT
) |
920 SCU_VIIT_STATUS_ALL_VALID
,
921 &sci_port
->viit_registers
->status
);
925 * This method returns the maximum allowed speed for data transfers on this
926 * port. This maximum allowed speed evaluates to the maximum speed of the
927 * slowest phy in the port.
928 * @sci_port: This parameter specifies the port for which to retrieve the
929 * maximum allowed speed.
931 * This method returns the maximum negotiated speed of the slowest phy in the
934 enum sas_linkrate
scic_sds_port_get_max_allowed_speed(
935 struct scic_sds_port
*sci_port
)
938 enum sas_linkrate max_allowed_speed
= SAS_LINK_RATE_6_0_GBPS
;
939 struct scic_sds_phy
*phy
= NULL
;
942 * Loop through all of the phys in this port and find the phy with the
943 * lowest maximum link rate. */
944 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
945 phy
= sci_port
->phy_table
[index
];
948 && (scic_sds_port_active_phy(sci_port
, phy
) == true)
949 && (phy
->max_negotiated_speed
< max_allowed_speed
)
951 max_allowed_speed
= phy
->max_negotiated_speed
;
954 return max_allowed_speed
;
959 * This method passes the event to core user.
960 * @sci_port: The port that a BCN happens.
961 * @sci_phy: The phy that receives BCN.
964 void scic_sds_port_broadcast_change_received(
965 struct scic_sds_port
*sci_port
,
966 struct scic_sds_phy
*sci_phy
)
968 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
969 struct isci_host
*ihost
= scic_to_ihost(scic
);
971 /* notify the user. */
972 isci_port_bc_change_received(ihost
, sci_port
, sci_phy
);
977 * This API methhod enables the broadcast change notification from underneath
979 * @sci_port: The port that a BCN had been disabled from.
982 void scic_port_enable_broadcast_change_notification(
983 struct scic_sds_port
*port
)
985 struct scic_sds_phy
*phy
;
989 /* Loop through all of the phys to enable BCN. */
990 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
991 phy
= port
->phy_table
[index
];
994 readl(&phy
->link_layer_registers
->link_layer_control
);
996 /* clear the bit by writing 1. */
997 writel(register_value
,
998 &phy
->link_layer_registers
->link_layer_control
);
1004 * ****************************************************************************
1005 * * READY SUBSTATE HANDLERS
1006 * **************************************************************************** */
1009 * This method is the general ready state stop handler for the struct scic_sds_port
1010 * object. This function will transition the ready substate machine to its
1011 * final state. enum sci_status SCI_SUCCESS
1013 static enum sci_status
scic_sds_port_ready_substate_stop_handler(
1014 struct scic_sds_port
*port
)
1016 sci_base_state_machine_change_state(
1017 &port
->state_machine
,
1018 SCI_BASE_PORT_STATE_STOPPING
1025 * This method is the general ready substate complete io handler for the
1026 * struct scic_sds_port object. This function decrments the outstanding request count
1027 * for this port object. enum sci_status SCI_SUCCESS
1029 static enum sci_status
scic_sds_port_ready_substate_complete_io_handler(
1030 struct scic_sds_port
*port
,
1031 struct scic_sds_remote_device
*device
,
1032 struct scic_sds_request
*io_request
)
1034 scic_sds_port_decrement_request_count(port
);
1039 static enum sci_status
scic_sds_port_ready_substate_add_phy_handler(
1040 struct scic_sds_port
*port
,
1041 struct scic_sds_phy
*phy
)
1043 enum sci_status status
;
1045 status
= scic_sds_port_set_phy(port
, phy
);
1047 if (status
== SCI_SUCCESS
) {
1048 scic_sds_port_general_link_up_handler(port
, phy
, true);
1050 port
->not_ready_reason
= SCIC_PORT_NOT_READY_RECONFIGURING
;
1052 sci_base_state_machine_change_state(
1053 &port
->ready_substate_machine
,
1054 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1062 static enum sci_status
scic_sds_port_ready_substate_remove_phy_handler(
1063 struct scic_sds_port
*port
,
1064 struct scic_sds_phy
*phy
)
1066 enum sci_status status
;
1068 status
= scic_sds_port_clear_phy(port
, phy
);
1070 if (status
== SCI_SUCCESS
) {
1071 scic_sds_port_deactivate_phy(port
, phy
, true);
1073 port
->not_ready_reason
= SCIC_PORT_NOT_READY_RECONFIGURING
;
1075 sci_base_state_machine_change_state(
1076 &port
->ready_substate_machine
,
1077 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1085 * ****************************************************************************
1086 * * READY SUBSTATE WAITING HANDLERS
1087 * **************************************************************************** */
1091 * @sci_port: This is the struct scic_sds_port object that which has a phy that has
1093 * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
1095 * This method is the ready waiting substate link up handler for the
1096 * struct scic_sds_port object. This methos will report the link up condition for
1097 * this port and will transition to the ready operational substate. none
1099 static void scic_sds_port_ready_waiting_substate_link_up_handler(
1100 struct scic_sds_port
*sci_port
,
1101 struct scic_sds_phy
*sci_phy
)
1104 * Since this is the first phy going link up for the port we can just enable
1105 * it and continue. */
1106 scic_sds_port_activate_phy(sci_port
, sci_phy
, true);
1108 sci_base_state_machine_change_state(
1109 &sci_port
->ready_substate_machine
,
1110 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1115 * This method is the ready waiting substate start io handler for the
1116 * struct scic_sds_port object. The port object can not accept new requests so the
1117 * request is failed. enum sci_status SCI_FAILURE_INVALID_STATE
1119 static enum sci_status
scic_sds_port_ready_waiting_substate_start_io_handler(
1120 struct scic_sds_port
*port
,
1121 struct scic_sds_remote_device
*device
,
1122 struct scic_sds_request
*io_request
)
1124 return SCI_FAILURE_INVALID_STATE
;
1128 * ****************************************************************************
1129 * * READY SUBSTATE OPERATIONAL HANDLERS
1130 * **************************************************************************** */
1133 * This method will casue the port to reset. enum sci_status SCI_SUCCESS
1136 sci_status
scic_sds_port_ready_operational_substate_reset_handler(
1137 struct scic_sds_port
*port
,
1140 enum sci_status status
= SCI_FAILURE_INVALID_PHY
;
1142 struct scic_sds_phy
*selected_phy
= NULL
;
1145 /* Select a phy on which we can send the hard reset request. */
1147 (phy_index
< SCI_MAX_PHYS
) && (selected_phy
== NULL
);
1149 selected_phy
= port
->phy_table
[phy_index
];
1151 if ((selected_phy
!= NULL
) &&
1152 !scic_sds_port_active_phy(port
, selected_phy
)) {
1154 * We found a phy but it is not ready select
1157 selected_phy
= NULL
;
1161 /* If we have a phy then go ahead and start the reset procedure */
1162 if (selected_phy
!= NULL
) {
1163 status
= scic_sds_phy_reset(selected_phy
);
1165 if (status
== SCI_SUCCESS
) {
1166 isci_timer_start(port
->timer_handle
, timeout
);
1167 port
->not_ready_reason
=
1168 SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED
;
1170 sci_base_state_machine_change_state(
1171 &port
->state_machine
,
1172 SCI_BASE_PORT_STATE_RESETTING
);
1180 * scic_sds_port_ready_operational_substate_link_up_handler() -
1181 * @sci_port: This is the struct scic_sds_port object that which has a phy that has
1183 * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
1185 * This method is the ready operational substate link up handler for the
1186 * struct scic_sds_port object. This function notifies the SCI User that the phy has
1187 * gone link up. none
1189 static void scic_sds_port_ready_operational_substate_link_up_handler(
1190 struct scic_sds_port
*sci_port
,
1191 struct scic_sds_phy
*sci_phy
)
1193 scic_sds_port_general_link_up_handler(sci_port
, sci_phy
, true);
1197 * scic_sds_port_ready_operational_substate_link_down_handler() -
1198 * @sci_port: This is the struct scic_sds_port object that which has a phy that has
1200 * @sci_phy: This is the struct scic_sds_phy object that has gone link down.
1202 * This method is the ready operational substate link down handler for the
1203 * struct scic_sds_port object. This function notifies the SCI User that the phy has
1204 * gone link down and if this is the last phy in the port the port will change
1205 * state to the ready waiting substate. none
1207 static void scic_sds_port_ready_operational_substate_link_down_handler(
1208 struct scic_sds_port
*sci_port
,
1209 struct scic_sds_phy
*sci_phy
)
1211 scic_sds_port_deactivate_phy(sci_port
, sci_phy
, true);
1214 * If there are no active phys left in the port, then transition
1215 * the port to the WAITING state until such time as a phy goes
1217 if (sci_port
->active_phy_mask
== 0)
1218 sci_base_state_machine_change_state(&sci_port
->ready_substate_machine
,
1219 SCIC_SDS_PORT_READY_SUBSTATE_WAITING
);
1223 * This method is the ready operational substate start io handler for the
1224 * struct scic_sds_port object. This function incremetns the outstanding request
1225 * count for this port object. enum sci_status SCI_SUCCESS
1227 static enum sci_status
scic_sds_port_ready_operational_substate_start_io_handler(
1228 struct scic_sds_port
*port
,
1229 struct scic_sds_remote_device
*device
,
1230 struct scic_sds_request
*io_request
)
1232 port
->started_request_count
++;
1237 * ****************************************************************************
1238 * * READY SUBSTATE OPERATIONAL HANDLERS
1239 * **************************************************************************** */
1242 * This is the default method for a port add phy request. It will report a
1243 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1245 static enum sci_status
scic_sds_port_ready_configuring_substate_add_phy_handler(
1246 struct scic_sds_port
*port
,
1247 struct scic_sds_phy
*phy
)
1249 enum sci_status status
;
1251 status
= scic_sds_port_set_phy(port
, phy
);
1253 if (status
== SCI_SUCCESS
) {
1254 scic_sds_port_general_link_up_handler(port
, phy
, true);
1257 * Re-enter the configuring state since this may be the last phy in
1259 sci_base_state_machine_change_state(
1260 &port
->ready_substate_machine
,
1261 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1269 * This is the default method for a port remove phy request. It will report a
1270 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1272 static enum sci_status
scic_sds_port_ready_configuring_substate_remove_phy_handler(
1273 struct scic_sds_port
*port
,
1274 struct scic_sds_phy
*phy
)
1276 enum sci_status status
;
1278 status
= scic_sds_port_clear_phy(port
, phy
);
1280 if (status
== SCI_SUCCESS
) {
1281 scic_sds_port_deactivate_phy(port
, phy
, true);
1284 * Re-enter the configuring state since this may be the last phy in
1286 sci_base_state_machine_change_state(
1287 &port
->ready_substate_machine
,
1288 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1296 * scic_sds_port_ready_configuring_substate_complete_io_handler() -
1297 * @port: This is the port that is being requested to complete the io request.
1298 * @device: This is the device on which the io is completing.
1300 * This method will decrement the outstanding request count for this port. If
1301 * the request count goes to 0 then the port can be reprogrammed with its new
1304 static enum sci_status
1305 scic_sds_port_ready_configuring_substate_complete_io_handler(
1306 struct scic_sds_port
*port
,
1307 struct scic_sds_remote_device
*device
,
1308 struct scic_sds_request
*io_request
)
1310 scic_sds_port_decrement_request_count(port
);
1312 if (port
->started_request_count
== 0) {
1313 sci_base_state_machine_change_state(
1314 &port
->ready_substate_machine
,
1315 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1322 static enum sci_status
default_port_handler(struct scic_sds_port
*sci_port
,
1325 dev_warn(sciport_to_dev(sci_port
),
1326 "%s: in wrong state: %d\n", func
,
1327 sci_base_state_machine_get_state(&sci_port
->state_machine
));
1328 return SCI_FAILURE_INVALID_STATE
;
1331 static enum sci_status
1332 scic_sds_port_default_start_handler(struct scic_sds_port
*sci_port
)
1334 return default_port_handler(sci_port
, __func__
);
1337 static enum sci_status
1338 scic_sds_port_default_stop_handler(struct scic_sds_port
*sci_port
)
1340 return default_port_handler(sci_port
, __func__
);
1343 static enum sci_status
1344 scic_sds_port_default_destruct_handler(struct scic_sds_port
*sci_port
)
1346 return default_port_handler(sci_port
, __func__
);
1349 static enum sci_status
1350 scic_sds_port_default_reset_handler(struct scic_sds_port
*sci_port
,
1353 return default_port_handler(sci_port
, __func__
);
1356 static enum sci_status
1357 scic_sds_port_default_add_phy_handler(struct scic_sds_port
*sci_port
,
1358 struct scic_sds_phy
*base_phy
)
1360 return default_port_handler(sci_port
, __func__
);
1363 static enum sci_status
1364 scic_sds_port_default_remove_phy_handler(struct scic_sds_port
*sci_port
,
1365 struct scic_sds_phy
*base_phy
)
1367 return default_port_handler(sci_port
, __func__
);
1371 * This is the default method for a port unsolicited frame request. It will
1372 * report a warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE Is it even
1373 * possible to receive an unsolicited frame directed to a port object? It
1374 * seems possible if we implementing virtual functions but until then?
1376 static enum sci_status
1377 scic_sds_port_default_frame_handler(struct scic_sds_port
*sci_port
,
1380 struct scic_sds_controller
*scic
= scic_sds_port_get_controller(sci_port
);
1382 default_port_handler(sci_port
, __func__
);
1383 scic_sds_controller_release_frame(scic
, frame_index
);
1385 return SCI_FAILURE_INVALID_STATE
;
1388 static enum sci_status
scic_sds_port_default_event_handler(struct scic_sds_port
*sci_port
,
1391 return default_port_handler(sci_port
, __func__
);
1394 static void scic_sds_port_default_link_up_handler(struct scic_sds_port
*sci_port
,
1395 struct scic_sds_phy
*sci_phy
)
1397 default_port_handler(sci_port
, __func__
);
1400 static void scic_sds_port_default_link_down_handler(struct scic_sds_port
*sci_port
,
1401 struct scic_sds_phy
*sci_phy
)
1403 default_port_handler(sci_port
, __func__
);
1406 static enum sci_status
scic_sds_port_default_start_io_handler(struct scic_sds_port
*sci_port
,
1407 struct scic_sds_remote_device
*sci_dev
,
1408 struct scic_sds_request
*sci_req
)
1410 return default_port_handler(sci_port
, __func__
);
1413 static enum sci_status
scic_sds_port_default_complete_io_handler(struct scic_sds_port
*sci_port
,
1414 struct scic_sds_remote_device
*sci_dev
,
1415 struct scic_sds_request
*sci_req
)
1417 return default_port_handler(sci_port
, __func__
);
1422 static struct scic_sds_port_state_handler
1423 scic_sds_port_ready_substate_handler_table
[SCIC_SDS_PORT_READY_MAX_SUBSTATES
] = {
1425 /* SCIC_SDS_PORT_READY_SUBSTATE_WAITING */
1426 scic_sds_port_default_start_handler
,
1427 scic_sds_port_ready_substate_stop_handler
,
1428 scic_sds_port_default_destruct_handler
,
1429 scic_sds_port_default_reset_handler
,
1430 scic_sds_port_ready_substate_add_phy_handler
,
1431 scic_sds_port_default_remove_phy_handler
,
1432 scic_sds_port_default_frame_handler
,
1433 scic_sds_port_default_event_handler
,
1434 scic_sds_port_ready_waiting_substate_link_up_handler
,
1435 scic_sds_port_default_link_down_handler
,
1436 scic_sds_port_ready_waiting_substate_start_io_handler
,
1437 scic_sds_port_ready_substate_complete_io_handler
,
1441 /* SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL */
1442 scic_sds_port_default_start_handler
,
1443 scic_sds_port_ready_substate_stop_handler
,
1444 scic_sds_port_default_destruct_handler
,
1445 scic_sds_port_ready_operational_substate_reset_handler
,
1446 scic_sds_port_ready_substate_add_phy_handler
,
1447 scic_sds_port_ready_substate_remove_phy_handler
,
1448 scic_sds_port_default_frame_handler
,
1449 scic_sds_port_default_event_handler
,
1450 scic_sds_port_ready_operational_substate_link_up_handler
,
1451 scic_sds_port_ready_operational_substate_link_down_handler
,
1452 scic_sds_port_ready_operational_substate_start_io_handler
,
1453 scic_sds_port_ready_substate_complete_io_handler
,
1457 /* SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING */
1458 scic_sds_port_default_start_handler
,
1459 scic_sds_port_ready_substate_stop_handler
,
1460 scic_sds_port_default_destruct_handler
,
1461 scic_sds_port_default_reset_handler
,
1462 scic_sds_port_ready_configuring_substate_add_phy_handler
,
1463 scic_sds_port_ready_configuring_substate_remove_phy_handler
,
1464 scic_sds_port_default_frame_handler
,
1465 scic_sds_port_default_event_handler
,
1466 scic_sds_port_default_link_up_handler
,
1467 scic_sds_port_default_link_down_handler
,
1468 scic_sds_port_default_start_io_handler
,
1469 scic_sds_port_ready_configuring_substate_complete_io_handler
1474 * scic_sds_port_set_ready_state_handlers() -
1476 * This macro sets the port ready substate handlers.
1478 #define scic_sds_port_set_ready_state_handlers(port, state_id) \
1479 scic_sds_port_set_state_handlers(\
1480 port, &scic_sds_port_ready_substate_handler_table[(state_id)] \
1484 * ******************************************************************************
1485 * * PORT STATE PRIVATE METHODS
1486 * ****************************************************************************** */
1490 * @sci_port: This is the struct scic_sds_port object to suspend.
1492 * This method will susped the port task scheduler for this port object. none
1495 scic_sds_port_suspend_port_task_scheduler(struct scic_sds_port
*port
)
1497 u32 pts_control_value
;
1499 pts_control_value
= readl(&port
->port_task_scheduler_registers
->control
);
1500 pts_control_value
|= SCU_PTSxCR_GEN_BIT(SUSPEND
);
1501 writel(pts_control_value
, &port
->port_task_scheduler_registers
->control
);
1505 * scic_sds_port_post_dummy_request() - post dummy/workaround request
1506 * @sci_port: port to post task
1508 * Prevent the hardware scheduler from posting new requests to the front
1509 * of the scheduler queue causing a starvation problem for currently
1513 static void scic_sds_port_post_dummy_request(struct scic_sds_port
*sci_port
)
1516 struct scu_task_context
*task_context
;
1517 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1518 u16 tci
= sci_port
->reserved_tci
;
1520 task_context
= scic_sds_controller_get_task_context_buffer(scic
, tci
);
1522 task_context
->abort
= 0;
1524 command
= SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC
|
1525 sci_port
->physical_port_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
|
1528 scic_sds_controller_post_request(scic
, command
);
1532 * This routine will abort the dummy request. This will alow the hardware to
1533 * power down parts of the silicon to save power.
1535 * @sci_port: The port on which the task must be aborted.
1538 static void scic_sds_port_abort_dummy_request(struct scic_sds_port
*sci_port
)
1540 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1541 u16 tci
= sci_port
->reserved_tci
;
1542 struct scu_task_context
*tc
;
1545 tc
= scic_sds_controller_get_task_context_buffer(scic
, tci
);
1549 command
= SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT
|
1550 sci_port
->physical_port_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
|
1553 scic_sds_controller_post_request(scic
, command
);
1558 * @sci_port: This is the struct scic_sds_port object to resume.
1560 * This method will resume the port task scheduler for this port object. none
1563 scic_sds_port_resume_port_task_scheduler(struct scic_sds_port
*port
)
1565 u32 pts_control_value
;
1567 pts_control_value
= readl(&port
->port_task_scheduler_registers
->control
);
1568 pts_control_value
&= ~SCU_PTSxCR_GEN_BIT(SUSPEND
);
1569 writel(pts_control_value
, &port
->port_task_scheduler_registers
->control
);
1573 * ******************************************************************************
1574 * * PORT READY SUBSTATE METHODS
1575 * ****************************************************************************** */
1579 * @object: This is the object which is cast to a struct scic_sds_port object.
1581 * This method will perform the actions required by the struct scic_sds_port on
1582 * entering the SCIC_SDS_PORT_READY_SUBSTATE_WAITING. This function checks the
1583 * port for any ready phys. If there is at least one phy in a ready state then
1584 * the port transitions to the ready operational substate. none
1586 static void scic_sds_port_ready_substate_waiting_enter(void *object
)
1588 struct scic_sds_port
*sci_port
= object
;
1590 scic_sds_port_set_ready_state_handlers(
1591 sci_port
, SCIC_SDS_PORT_READY_SUBSTATE_WAITING
1594 scic_sds_port_suspend_port_task_scheduler(sci_port
);
1596 sci_port
->not_ready_reason
= SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS
;
1598 if (sci_port
->active_phy_mask
!= 0) {
1599 /* At least one of the phys on the port is ready */
1600 sci_base_state_machine_change_state(
1601 &sci_port
->ready_substate_machine
,
1602 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1609 * @object: This is the object which is cast to a struct scic_sds_port object.
1611 * This function will perform the actions required by the struct scic_sds_port
1612 * on entering the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function sets
1613 * the state handlers for the port object, notifies the SCI User that the port
1614 * is ready, and resumes port operations. none
1616 static void scic_sds_port_ready_substate_operational_enter(void *object
)
1619 struct scic_sds_port
*sci_port
= object
;
1620 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1621 struct isci_host
*ihost
= scic_to_ihost(scic
);
1622 struct isci_port
*iport
= sci_port_to_iport(sci_port
);
1624 scic_sds_port_set_ready_state_handlers(
1626 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
);
1628 isci_port_ready(ihost
, iport
);
1630 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
1631 if (sci_port
->phy_table
[index
]) {
1632 writel(sci_port
->physical_port_index
,
1633 &sci_port
->port_pe_configuration_register
[
1634 sci_port
->phy_table
[index
]->phy_index
]);
1638 scic_sds_port_update_viit_entry(sci_port
);
1640 scic_sds_port_resume_port_task_scheduler(sci_port
);
1643 * Post the dummy task for the port so the hardware can schedule
1646 scic_sds_port_post_dummy_request(sci_port
);
1651 * @object: This is the object which is cast to a struct scic_sds_port object.
1653 * This method will perform the actions required by the struct scic_sds_port on
1654 * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
1655 * the port not ready and suspends the port task scheduler. none
1657 static void scic_sds_port_ready_substate_operational_exit(void *object
)
1659 struct scic_sds_port
*sci_port
= object
;
1660 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1661 struct isci_host
*ihost
= scic_to_ihost(scic
);
1662 struct isci_port
*iport
= sci_port_to_iport(sci_port
);
1665 * Kill the dummy task for this port if it has not yet posted
1666 * the hardware will treat this as a NOP and just return abort
1669 scic_sds_port_abort_dummy_request(sci_port
);
1671 isci_port_not_ready(ihost
, iport
);
1675 * ******************************************************************************
1676 * * PORT READY CONFIGURING METHODS
1677 * ****************************************************************************** */
1680 * scic_sds_port_ready_substate_configuring_enter() -
1681 * @object: This is the object which is cast to a struct scic_sds_port object.
1683 * This method will perform the actions required by the struct scic_sds_port on
1684 * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
1685 * the port not ready and suspends the port task scheduler. none
1687 static void scic_sds_port_ready_substate_configuring_enter(void *object
)
1689 struct scic_sds_port
*sci_port
= object
;
1690 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1691 struct isci_host
*ihost
= scic_to_ihost(scic
);
1692 struct isci_port
*iport
= sci_port_to_iport(sci_port
);
1694 scic_sds_port_set_ready_state_handlers(
1696 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
);
1698 if (sci_port
->active_phy_mask
== 0) {
1699 isci_port_not_ready(ihost
, iport
);
1701 sci_base_state_machine_change_state(
1702 &sci_port
->ready_substate_machine
,
1703 SCIC_SDS_PORT_READY_SUBSTATE_WAITING
);
1704 } else if (sci_port
->started_request_count
== 0)
1705 sci_base_state_machine_change_state(
1706 &sci_port
->ready_substate_machine
,
1707 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
);
1710 static void scic_sds_port_ready_substate_configuring_exit(void *object
)
1712 struct scic_sds_port
*sci_port
= object
;
1714 scic_sds_port_suspend_port_task_scheduler(sci_port
);
1717 /* --------------------------------------------------------------------------- */
1719 static const struct sci_base_state scic_sds_port_ready_substate_table
[] = {
1720 [SCIC_SDS_PORT_READY_SUBSTATE_WAITING
] = {
1721 .enter_state
= scic_sds_port_ready_substate_waiting_enter
,
1723 [SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
] = {
1724 .enter_state
= scic_sds_port_ready_substate_operational_enter
,
1725 .exit_state
= scic_sds_port_ready_substate_operational_exit
1727 [SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
] = {
1728 .enter_state
= scic_sds_port_ready_substate_configuring_enter
,
1729 .exit_state
= scic_sds_port_ready_substate_configuring_exit
1735 * @port: This is the struct scic_sds_port object on which the io request count will
1737 * @device: This is the struct scic_sds_remote_device object to which the io request
1738 * is being directed. This parameter is not required to complete this
1740 * @io_request: This is the request that is being completed on this port
1741 * object. This parameter is not required to complete this operation.
1743 * This is a general complete io request handler for the struct scic_sds_port object.
1744 * enum sci_status SCI_SUCCESS
1746 static enum sci_status
scic_sds_port_general_complete_io_handler(
1747 struct scic_sds_port
*port
,
1748 struct scic_sds_remote_device
*device
,
1749 struct scic_sds_request
*io_request
)
1751 scic_sds_port_decrement_request_count(port
);
1757 * scic_sds_port_stopped_state_start_handler() - stop a port from "started"
1759 * @port: This is the struct scic_sds_port object which is cast into a
1760 * struct scic_sds_port object.
1762 * This function takes the struct scic_sds_port from a stopped state and
1763 * attempts to start it. To start a port it must have no assiged devices and
1764 * it must have at least one phy assigned to it. If those conditions are
1765 * met then the port can transition to the ready state.
1767 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
1768 * This struct scic_sds_port object could not be started because the port
1769 * configuration is not valid.
1771 * the start request is successful and the struct scic_sds_port object
1772 * has transitioned to the SCI_BASE_PORT_STATE_READY.
1774 static enum sci_status
1775 scic_sds_port_stopped_state_start_handler(struct scic_sds_port
*sci_port
)
1777 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1778 struct isci_host
*ihost
= scic_to_ihost(scic
);
1779 enum sci_status status
= SCI_SUCCESS
;
1782 if (sci_port
->assigned_device_count
> 0) {
1784 * @todo This is a start failure operation because
1785 * there are still devices assigned to this port.
1786 * There must be no devices assigned to a port on a
1789 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
;
1792 sci_port
->timer_handle
=
1793 isci_timer_create(ihost
,
1795 scic_sds_port_timeout_handler
);
1797 if (!sci_port
->timer_handle
)
1798 return SCI_FAILURE_INSUFFICIENT_RESOURCES
;
1800 if (sci_port
->reserved_rni
== SCU_DUMMY_INDEX
) {
1801 u16 rni
= scic_sds_remote_node_table_allocate_remote_node(
1802 &scic
->available_remote_nodes
, 1);
1804 if (rni
!= SCU_DUMMY_INDEX
)
1805 scic_sds_port_construct_dummy_rnc(sci_port
, rni
);
1807 status
= SCI_FAILURE_INSUFFICIENT_RESOURCES
;
1808 sci_port
->reserved_rni
= rni
;
1811 if (sci_port
->reserved_tci
== SCU_DUMMY_INDEX
) {
1812 /* Allocate a TCI and remove the sequence nibble */
1813 u16 tci
= scic_controller_allocate_io_tag(scic
);
1815 if (tci
!= SCU_DUMMY_INDEX
)
1816 scic_sds_port_construct_dummy_task(sci_port
, tci
);
1818 status
= SCI_FAILURE_INSUFFICIENT_RESOURCES
;
1819 sci_port
->reserved_tci
= tci
;
1822 if (status
== SCI_SUCCESS
) {
1823 phy_mask
= scic_sds_port_get_phys(sci_port
);
1826 * There are one or more phys assigned to this port. Make sure
1827 * the port's phy mask is in fact legal and supported by the
1830 if (scic_sds_port_is_phy_mask_valid(sci_port
, phy_mask
) == true) {
1831 sci_base_state_machine_change_state(
1832 &sci_port
->state_machine
,
1833 SCI_BASE_PORT_STATE_READY
);
1837 status
= SCI_FAILURE
;
1840 if (status
!= SCI_SUCCESS
)
1841 scic_sds_port_destroy_dummy_resources(sci_port
);
1847 * This method takes the struct scic_sds_port that is in a stopped state and handles a
1848 * stop request. This function takes no action. enum sci_status SCI_SUCCESS the
1849 * stop request is successful as the struct scic_sds_port object is already stopped.
1851 static enum sci_status
scic_sds_port_stopped_state_stop_handler(
1852 struct scic_sds_port
*port
)
1854 /* We are already stopped so there is nothing to do here */
1859 * This method takes the struct scic_sds_port that is in a stopped state and handles
1860 * the destruct request. The stopped state is the only state in which the
1861 * struct scic_sds_port can be destroyed. This function causes the port object to
1862 * transition to the SCI_BASE_PORT_STATE_FINAL. enum sci_status SCI_SUCCESS
1864 static enum sci_status
scic_sds_port_stopped_state_destruct_handler(
1865 struct scic_sds_port
*port
)
1867 sci_base_state_machine_stop(&port
->state_machine
);
1873 * This method takes the struct scic_sds_port that is in a stopped state and handles
1874 * the add phy request. In MPC mode the only time a phy can be added to a port
1875 * is in the SCI_BASE_PORT_STATE_STOPPED. enum sci_status
1876 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION is returned when the phy can not
1877 * be added to the port. SCI_SUCCESS if the phy is added to the port.
1879 static enum sci_status
scic_sds_port_stopped_state_add_phy_handler(
1880 struct scic_sds_port
*port
,
1881 struct scic_sds_phy
*phy
)
1883 struct sci_sas_address port_sas_address
;
1885 /* Read the port assigned SAS Address if there is one */
1886 scic_sds_port_get_sas_address(port
, &port_sas_address
);
1888 if (port_sas_address
.high
!= 0 && port_sas_address
.low
!= 0) {
1889 struct sci_sas_address phy_sas_address
;
1892 * Make sure that the PHY SAS Address matches the SAS Address
1894 scic_sds_phy_get_sas_address(phy
, &phy_sas_address
);
1897 (port_sas_address
.high
!= phy_sas_address
.high
)
1898 || (port_sas_address
.low
!= phy_sas_address
.low
)
1900 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
;
1904 return scic_sds_port_set_phy(port
, phy
);
1908 * This method takes the struct scic_sds_port that is in a stopped state and handles
1909 * the remove phy request. In MPC mode the only time a phy can be removed from
1910 * a port is in the SCI_BASE_PORT_STATE_STOPPED. enum sci_status
1911 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION is returned when the phy can not
1912 * be added to the port. SCI_SUCCESS if the phy is added to the port.
1914 static enum sci_status
scic_sds_port_stopped_state_remove_phy_handler(
1915 struct scic_sds_port
*port
,
1916 struct scic_sds_phy
*phy
)
1918 return scic_sds_port_clear_phy(port
, phy
);
1922 * ****************************************************************************
1923 * * READY STATE HANDLERS
1924 * **************************************************************************** */
1927 * ****************************************************************************
1928 * * RESETTING STATE HANDLERS
1929 * **************************************************************************** */
1932 * ****************************************************************************
1933 * * STOPPING STATE HANDLERS
1934 * **************************************************************************** */
1937 * This method takes the struct scic_sds_port that is in a stopping state and handles
1938 * the complete io request. Should the request count reach 0 then the port
1939 * object will transition to the stopped state. enum sci_status SCI_SUCCESS
1941 static enum sci_status
scic_sds_port_stopping_state_complete_io_handler(
1942 struct scic_sds_port
*sci_port
,
1943 struct scic_sds_remote_device
*device
,
1944 struct scic_sds_request
*io_request
)
1946 scic_sds_port_decrement_request_count(sci_port
);
1948 if (sci_port
->started_request_count
== 0) {
1949 sci_base_state_machine_change_state(&sci_port
->state_machine
,
1950 SCI_BASE_PORT_STATE_STOPPED
);
1957 * ****************************************************************************
1958 * * RESETTING STATE HANDLERS
1959 * **************************************************************************** */
1963 * @port: This is the port object which is being requested to stop.
1965 * This method will stop a failed port. This causes a transition to the
1966 * stopping state. enum sci_status SCI_SUCCESS
1968 static enum sci_status
scic_sds_port_reset_state_stop_handler(
1969 struct scic_sds_port
*port
)
1971 sci_base_state_machine_change_state(
1972 &port
->state_machine
,
1973 SCI_BASE_PORT_STATE_STOPPING
1980 * This method will transition a failed port to its ready state. The port
1981 * failed because a hard reset request timed out but at some time later one or
1982 * more phys in the port became ready. enum sci_status SCI_SUCCESS
1984 static void scic_sds_port_reset_state_link_up_handler(
1985 struct scic_sds_port
*port
,
1986 struct scic_sds_phy
*phy
)
1989 * / @todo We should make sure that the phy that has gone link up is the same
1990 * / one on which we sent the reset. It is possible that the phy on
1991 * / which we sent the reset is not the one that has gone link up and we
1992 * / want to make sure that phy being reset comes back. Consider the
1993 * / case where a reset is sent but before the hardware processes the
1994 * / reset it get a link up on the port because of a hot plug event.
1995 * / because of the reset request this phy will go link down almost
1999 * In the resetting state we don't notify the user regarding
2000 * link up and link down notifications. */
2001 scic_sds_port_general_link_up_handler(port
, phy
, false);
2005 * This method process link down notifications that occur during a port reset
2006 * operation. Link downs can occur during the reset operation. enum sci_status
2009 static void scic_sds_port_reset_state_link_down_handler(
2010 struct scic_sds_port
*port
,
2011 struct scic_sds_phy
*phy
)
2014 * In the resetting state we don't notify the user regarding
2015 * link up and link down notifications. */
2016 scic_sds_port_deactivate_phy(port
, phy
, false);
2019 static struct scic_sds_port_state_handler
2020 scic_sds_port_state_handler_table
[SCI_BASE_PORT_MAX_STATES
] =
2022 /* SCI_BASE_PORT_STATE_STOPPED */
2024 scic_sds_port_stopped_state_start_handler
,
2025 scic_sds_port_stopped_state_stop_handler
,
2026 scic_sds_port_stopped_state_destruct_handler
,
2027 scic_sds_port_default_reset_handler
,
2028 scic_sds_port_stopped_state_add_phy_handler
,
2029 scic_sds_port_stopped_state_remove_phy_handler
,
2030 scic_sds_port_default_frame_handler
,
2031 scic_sds_port_default_event_handler
,
2032 scic_sds_port_default_link_up_handler
,
2033 scic_sds_port_default_link_down_handler
,
2034 scic_sds_port_default_start_io_handler
,
2035 scic_sds_port_default_complete_io_handler
2037 /* SCI_BASE_PORT_STATE_STOPPING */
2039 scic_sds_port_default_start_handler
,
2040 scic_sds_port_default_stop_handler
,
2041 scic_sds_port_default_destruct_handler
,
2042 scic_sds_port_default_reset_handler
,
2043 scic_sds_port_default_add_phy_handler
,
2044 scic_sds_port_default_remove_phy_handler
,
2045 scic_sds_port_default_frame_handler
,
2046 scic_sds_port_default_event_handler
,
2047 scic_sds_port_default_link_up_handler
,
2048 scic_sds_port_default_link_down_handler
,
2049 scic_sds_port_default_start_io_handler
,
2050 scic_sds_port_stopping_state_complete_io_handler
2052 /* SCI_BASE_PORT_STATE_READY */
2054 scic_sds_port_default_start_handler
,
2055 scic_sds_port_default_stop_handler
,
2056 scic_sds_port_default_destruct_handler
,
2057 scic_sds_port_default_reset_handler
,
2058 scic_sds_port_default_add_phy_handler
,
2059 scic_sds_port_default_remove_phy_handler
,
2060 scic_sds_port_default_frame_handler
,
2061 scic_sds_port_default_event_handler
,
2062 scic_sds_port_default_link_up_handler
,
2063 scic_sds_port_default_link_down_handler
,
2064 scic_sds_port_default_start_io_handler
,
2065 scic_sds_port_general_complete_io_handler
2067 /* SCI_BASE_PORT_STATE_RESETTING */
2069 scic_sds_port_default_start_handler
,
2070 scic_sds_port_reset_state_stop_handler
,
2071 scic_sds_port_default_destruct_handler
,
2072 scic_sds_port_default_reset_handler
,
2073 scic_sds_port_default_add_phy_handler
,
2074 scic_sds_port_default_remove_phy_handler
,
2075 scic_sds_port_default_frame_handler
,
2076 scic_sds_port_default_event_handler
,
2077 scic_sds_port_reset_state_link_up_handler
,
2078 scic_sds_port_reset_state_link_down_handler
,
2079 scic_sds_port_default_start_io_handler
,
2080 scic_sds_port_general_complete_io_handler
2082 /* SCI_BASE_PORT_STATE_FAILED */
2084 scic_sds_port_default_start_handler
,
2085 scic_sds_port_default_stop_handler
,
2086 scic_sds_port_default_destruct_handler
,
2087 scic_sds_port_default_reset_handler
,
2088 scic_sds_port_default_add_phy_handler
,
2089 scic_sds_port_default_remove_phy_handler
,
2090 scic_sds_port_default_frame_handler
,
2091 scic_sds_port_default_event_handler
,
2092 scic_sds_port_default_link_up_handler
,
2093 scic_sds_port_default_link_down_handler
,
2094 scic_sds_port_default_start_io_handler
,
2095 scic_sds_port_general_complete_io_handler
2100 * ******************************************************************************
2101 * * PORT STATE PRIVATE METHODS
2102 * ****************************************************************************** */
2106 * @sci_port: This is the port object which to suspend.
2108 * This method will enable the SCU Port Task Scheduler for this port object but
2109 * will leave the port task scheduler in a suspended state. none
2112 scic_sds_port_enable_port_task_scheduler(struct scic_sds_port
*port
)
2114 u32 pts_control_value
;
2116 pts_control_value
= readl(&port
->port_task_scheduler_registers
->control
);
2117 pts_control_value
|= SCU_PTSxCR_GEN_BIT(ENABLE
) | SCU_PTSxCR_GEN_BIT(SUSPEND
);
2118 writel(pts_control_value
, &port
->port_task_scheduler_registers
->control
);
2123 * @sci_port: This is the port object which to resume.
2125 * This method will disable the SCU port task scheduler for this port object.
2129 scic_sds_port_disable_port_task_scheduler(struct scic_sds_port
*port
)
2131 u32 pts_control_value
;
2133 pts_control_value
= readl(&port
->port_task_scheduler_registers
->control
);
2134 pts_control_value
&=
2135 ~(SCU_PTSxCR_GEN_BIT(ENABLE
) | SCU_PTSxCR_GEN_BIT(SUSPEND
));
2136 writel(pts_control_value
, &port
->port_task_scheduler_registers
->control
);
2139 static void scic_sds_port_post_dummy_remote_node(struct scic_sds_port
*sci_port
)
2141 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
2142 u8 phys_index
= sci_port
->physical_port_index
;
2143 union scu_remote_node_context
*rnc
;
2144 u16 rni
= sci_port
->reserved_rni
;
2147 rnc
= &scic
->remote_node_context_table
[rni
];
2148 rnc
->ssp
.is_valid
= true;
2150 command
= SCU_CONTEXT_COMMAND_POST_RNC_32
|
2151 phys_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
| rni
;
2153 scic_sds_controller_post_request(scic
, command
);
2155 /* ensure hardware has seen the post rnc command and give it
2156 * ample time to act before sending the suspend
2158 readl(&scic
->smu_registers
->interrupt_status
); /* flush */
2161 command
= SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX
|
2162 phys_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
| rni
;
2164 scic_sds_controller_post_request(scic
, command
);
2167 static void scic_sds_port_invalidate_dummy_remote_node(struct scic_sds_port
*sci_port
)
2169 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
2170 u8 phys_index
= sci_port
->physical_port_index
;
2171 union scu_remote_node_context
*rnc
;
2172 u16 rni
= sci_port
->reserved_rni
;
2175 rnc
= &scic
->remote_node_context_table
[rni
];
2177 rnc
->ssp
.is_valid
= false;
2179 /* ensure the preceding tc abort request has reached the
2180 * controller and give it ample time to act before posting the rnc
2183 readl(&scic
->smu_registers
->interrupt_status
); /* flush */
2186 command
= SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE
|
2187 phys_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
| rni
;
2189 scic_sds_controller_post_request(scic
, command
);
2193 * ******************************************************************************
2194 * * PORT STATE METHODS
2195 * ****************************************************************************** */
2199 * @object: This is the object which is cast to a struct scic_sds_port object.
2201 * This method will perform the actions required by the struct scic_sds_port on
2202 * entering the SCI_BASE_PORT_STATE_STOPPED. This function sets the stopped
2203 * state handlers for the struct scic_sds_port object and disables the port task
2204 * scheduler in the hardware. none
2206 static void scic_sds_port_stopped_state_enter(void *object
)
2208 struct scic_sds_port
*sci_port
= object
;
2210 scic_sds_port_set_base_state_handlers(
2211 sci_port
, SCI_BASE_PORT_STATE_STOPPED
2215 SCI_BASE_PORT_STATE_STOPPING
2216 == sci_port
->state_machine
.previous_state_id
2219 * If we enter this state becasuse of a request to stop
2220 * the port then we want to disable the hardwares port
2221 * task scheduler. */
2222 scic_sds_port_disable_port_task_scheduler(sci_port
);
2228 * @object: This is the object which is cast to a struct scic_sds_port object.
2230 * This method will perform the actions required by the struct scic_sds_port on
2231 * exiting the SCI_BASE_STATE_STOPPED. This function enables the SCU hardware
2232 * port task scheduler. none
2234 static void scic_sds_port_stopped_state_exit(void *object
)
2236 struct scic_sds_port
*sci_port
= object
;
2238 /* Enable and suspend the port task scheduler */
2239 scic_sds_port_enable_port_task_scheduler(sci_port
);
2243 * scic_sds_port_ready_state_enter -
2244 * @object: This is the object which is cast to a struct scic_sds_port object.
2246 * This method will perform the actions required by the struct scic_sds_port on
2247 * entering the SCI_BASE_PORT_STATE_READY. This function sets the ready state
2248 * handlers for the struct scic_sds_port object, reports the port object as
2249 * not ready and starts the ready substate machine. none
2251 static void scic_sds_port_ready_state_enter(void *object
)
2253 struct scic_sds_port
*sci_port
= object
;
2254 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
2255 struct isci_host
*ihost
= scic_to_ihost(scic
);
2256 struct isci_port
*iport
= sci_port_to_iport(sci_port
);
2259 /* Put the ready state handlers in place though they will not be there long */
2260 scic_sds_port_set_base_state_handlers(sci_port
, SCI_BASE_PORT_STATE_READY
);
2262 prev_state
= sci_port
->state_machine
.previous_state_id
;
2263 if (prev_state
== SCI_BASE_PORT_STATE_RESETTING
)
2264 isci_port_hard_reset_complete(iport
, SCI_SUCCESS
);
2266 isci_port_not_ready(ihost
, iport
);
2268 /* Post and suspend the dummy remote node context for this port. */
2269 scic_sds_port_post_dummy_remote_node(sci_port
);
2271 /* Start the ready substate machine */
2272 sci_base_state_machine_start(&sci_port
->ready_substate_machine
);
2275 static void scic_sds_port_ready_state_exit(void *object
)
2277 struct scic_sds_port
*sci_port
= object
;
2279 sci_base_state_machine_stop(&sci_port
->ready_substate_machine
);
2280 scic_sds_port_invalidate_dummy_remote_node(sci_port
);
2285 * @object: This is the object which is cast to a struct scic_sds_port object.
2287 * This method will perform the actions required by the struct scic_sds_port on
2288 * entering the SCI_BASE_PORT_STATE_RESETTING. This function sets the resetting
2289 * state handlers for the struct scic_sds_port object. none
2291 static void scic_sds_port_resetting_state_enter(void *object
)
2293 struct scic_sds_port
*sci_port
= object
;
2295 scic_sds_port_set_base_state_handlers(
2296 sci_port
, SCI_BASE_PORT_STATE_RESETTING
2302 * @object: This is the object which is cast to a struct scic_sds_port object.
2304 * This function will perform the actions required by the
2305 * struct scic_sds_port on
2306 * exiting the SCI_BASE_STATE_RESETTING. This function does nothing. none
2308 static inline void scic_sds_port_resetting_state_exit(void *object
)
2310 struct scic_sds_port
*sci_port
= object
;
2312 isci_timer_stop(sci_port
->timer_handle
);
2317 * @object: This is the void object which is cast to a
2318 * struct scic_sds_port object.
2320 * This method will perform the actions required by the struct scic_sds_port on
2321 * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
2322 * state handlers for the struct scic_sds_port object. none
2324 static void scic_sds_port_stopping_state_enter(void *object
)
2326 struct scic_sds_port
*sci_port
= object
;
2328 scic_sds_port_set_base_state_handlers(
2329 sci_port
, SCI_BASE_PORT_STATE_STOPPING
2335 * @object: This is the object which is cast to a struct scic_sds_port object.
2337 * This function will perform the actions required by the
2338 * struct scic_sds_port on
2339 * exiting the SCI_BASE_STATE_STOPPING. This function does nothing. none
2342 scic_sds_port_stopping_state_exit(void *object
)
2344 struct scic_sds_port
*sci_port
= object
;
2346 isci_timer_stop(sci_port
->timer_handle
);
2348 scic_sds_port_destroy_dummy_resources(sci_port
);
2353 * @object: This is the object which is cast to a struct scic_sds_port object.
2355 * This function will perform the actions required by the
2356 * struct scic_sds_port on
2357 * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
2358 * state handlers for the struct scic_sds_port object. none
2360 static void scic_sds_port_failed_state_enter(void *object
)
2362 struct scic_sds_port
*sci_port
= object
;
2363 struct isci_port
*iport
= sci_port_to_iport(sci_port
);
2365 scic_sds_port_set_base_state_handlers(sci_port
,
2366 SCI_BASE_PORT_STATE_FAILED
);
2368 isci_port_hard_reset_complete(iport
, SCI_FAILURE_TIMEOUT
);
2371 /* --------------------------------------------------------------------------- */
2373 static const struct sci_base_state scic_sds_port_state_table
[] = {
2374 [SCI_BASE_PORT_STATE_STOPPED
] = {
2375 .enter_state
= scic_sds_port_stopped_state_enter
,
2376 .exit_state
= scic_sds_port_stopped_state_exit
2378 [SCI_BASE_PORT_STATE_STOPPING
] = {
2379 .enter_state
= scic_sds_port_stopping_state_enter
,
2380 .exit_state
= scic_sds_port_stopping_state_exit
2382 [SCI_BASE_PORT_STATE_READY
] = {
2383 .enter_state
= scic_sds_port_ready_state_enter
,
2384 .exit_state
= scic_sds_port_ready_state_exit
2386 [SCI_BASE_PORT_STATE_RESETTING
] = {
2387 .enter_state
= scic_sds_port_resetting_state_enter
,
2388 .exit_state
= scic_sds_port_resetting_state_exit
2390 [SCI_BASE_PORT_STATE_FAILED
] = {
2391 .enter_state
= scic_sds_port_failed_state_enter
,
2395 void scic_sds_port_construct(struct scic_sds_port
*sci_port
, u8 index
,
2396 struct scic_sds_controller
*scic
)
2398 sci_base_state_machine_construct(&sci_port
->state_machine
,
2400 scic_sds_port_state_table
,
2401 SCI_BASE_PORT_STATE_STOPPED
);
2403 sci_base_state_machine_start(&sci_port
->state_machine
);
2405 sci_base_state_machine_construct(&sci_port
->ready_substate_machine
,
2407 scic_sds_port_ready_substate_table
,
2408 SCIC_SDS_PORT_READY_SUBSTATE_WAITING
);
2410 sci_port
->logical_port_index
= SCIC_SDS_DUMMY_PORT
;
2411 sci_port
->physical_port_index
= index
;
2412 sci_port
->active_phy_mask
= 0;
2414 sci_port
->owning_controller
= scic
;
2416 sci_port
->started_request_count
= 0;
2417 sci_port
->assigned_device_count
= 0;
2419 sci_port
->reserved_rni
= SCU_DUMMY_INDEX
;
2420 sci_port
->reserved_tci
= SCU_DUMMY_INDEX
;
2422 sci_port
->timer_handle
= NULL
;
2423 sci_port
->port_task_scheduler_registers
= NULL
;
2425 for (index
= 0; index
< SCI_MAX_PHYS
; index
++)
2426 sci_port
->phy_table
[index
] = NULL
;