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 "intel_sas.h"
57 #include "sci_base_port.h"
58 #include "scic_controller.h"
60 #include "scic_port.h"
61 #include "scic_sds_controller.h"
62 #include "scic_sds_phy.h"
63 #include "scic_sds_phy_registers.h"
64 #include "scic_sds_port.h"
65 #include "scic_sds_port_registers.h"
66 #include "scic_sds_remote_device.h"
67 #include "scic_sds_remote_node_context.h"
68 #include "scic_sds_request.h"
69 #include "sci_environment.h"
70 #include "scic_sds_controller_registers.h"
73 static void scic_sds_port_invalid_link_up(
74 struct scic_sds_port
*this_port
,
75 struct scic_sds_phy
*phy
);
76 static void scic_sds_port_timeout_handler(
78 #define SCIC_SDS_PORT_MIN_TIMER_COUNT (SCI_MAX_PORTS)
79 #define SCIC_SDS_PORT_MAX_TIMER_COUNT (SCI_MAX_PORTS)
81 #define SCIC_SDS_PORT_HARD_RESET_TIMEOUT (1000)
82 #define SCU_DUMMY_INDEX (0xFFFF)
84 void sci_base_port_construct(
85 struct sci_base_port
*base_port
,
86 const struct sci_base_state
*state_table
)
88 base_port
->parent
.private = NULL
;
89 sci_base_state_machine_construct(
90 &base_port
->state_machine
,
93 SCI_BASE_PORT_STATE_STOPPED
96 sci_base_state_machine_start(
97 &base_port
->state_machine
103 * @this_port: This is the port object to which the phy is being assigned.
104 * @phy_index: This is the phy index that is being assigned to the port.
106 * This method will return a true value if the specified phy can be assigned to
107 * this port The following is a list of phys for each port that are allowed: -
108 * Port 0 - 3 2 1 0 - Port 1 - 1 - Port 2 - 3 2 - Port 3 - 3 This method
109 * doesn't preclude all configurations. It merely ensures that a phy is part
110 * of the allowable set of phy identifiers for that port. For example, one
111 * could assign phy 3 to port 0 and no other phys. Please refer to
112 * scic_sds_port_is_phy_mask_valid() for information regarding whether the
113 * phy_mask for a port can be supported. bool true if this is a valid phy
114 * assignment for the port false if this is not a valid phy assignment for the
117 bool scic_sds_port_is_valid_phy_assignment(
118 struct scic_sds_port
*this_port
,
121 /* Initialize to invalid value. */
122 u32 existing_phy_index
= SCI_MAX_PHYS
;
125 if ((this_port
->physical_port_index
== 1) && (phy_index
!= 1)) {
129 if (this_port
->physical_port_index
== 3 && phy_index
!= 3) {
134 (this_port
->physical_port_index
== 2)
135 && ((phy_index
== 0) || (phy_index
== 1))
140 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
141 if ((this_port
->phy_table
[index
] != NULL
)
142 && (index
!= phy_index
)) {
143 existing_phy_index
= index
;
148 * Ensure that all of the phys in the port are capable of
149 * operating at the same maximum link rate. */
151 (existing_phy_index
< SCI_MAX_PHYS
)
152 && (this_port
->owning_controller
->user_parameters
.sds1
.phys
[
153 phy_index
].max_speed_generation
!=
154 this_port
->owning_controller
->user_parameters
.sds1
.phys
[
155 existing_phy_index
].max_speed_generation
)
163 * This method requests a list (mask) of the phys contained in the supplied SAS
165 * @this_port: a handle corresponding to the SAS port for which to return the
168 * Return a bit mask indicating which phys are a part of this port. Each bit
169 * corresponds to a phy identifier (e.g. bit 0 = phy id 0).
171 u32
scic_sds_port_get_phys(struct scic_sds_port
*this_port
)
178 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
179 if (this_port
->phy_table
[index
] != NULL
) {
180 mask
|= (1 << index
);
189 * @this_port: This is the port object for which to determine if the phy mask
192 * This method will return a true value if the port's phy mask can be supported
193 * by the SCU. The following is a list of valid PHY mask configurations for
194 * each port: - Port 0 - [[3 2] 1] 0 - Port 1 - [1] - Port 2 - [[3] 2]
195 * - Port 3 - [3] This method returns a boolean indication specifying if the
196 * phy mask can be supported. true if this is a valid phy assignment for the
197 * port false if this is not a valid phy assignment for the port
199 bool scic_sds_port_is_phy_mask_valid(
200 struct scic_sds_port
*this_port
,
203 if (this_port
->physical_port_index
== 0) {
204 if (((phy_mask
& 0x0F) == 0x0F)
205 || ((phy_mask
& 0x03) == 0x03)
206 || ((phy_mask
& 0x01) == 0x01)
209 } else if (this_port
->physical_port_index
== 1) {
210 if (((phy_mask
& 0x02) == 0x02)
213 } else if (this_port
->physical_port_index
== 2) {
214 if (((phy_mask
& 0x0C) == 0x0C)
215 || ((phy_mask
& 0x04) == 0x04)
218 } else if (this_port
->physical_port_index
== 3) {
219 if (((phy_mask
& 0x08) == 0x08)
229 * @this_port: This parameter specifies the port from which to return a
232 * This method retrieves a currently active (i.e. connected) phy contained in
233 * the port. Currently, the lowest order phy that is connected is returned.
234 * This method returns a pointer to a SCIS_SDS_PHY object. NULL This value is
235 * returned if there are no currently active (i.e. connected to a remote end
236 * point) phys contained in the port. All other values specify a struct scic_sds_phy
237 * object that is active in the port.
239 static struct scic_sds_phy
*scic_sds_port_get_a_connected_phy(
240 struct scic_sds_port
*this_port
243 struct scic_sds_phy
*phy
;
245 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
247 * Ensure that the phy is both part of the port and currently
248 * connected to the remote end-point. */
249 phy
= this_port
->phy_table
[index
];
252 && scic_sds_port_active_phy(this_port
, phy
)
262 * scic_sds_port_set_phy() -
263 * @out]: port The port object to which the phy assignement is being made.
264 * @out]: phy The phy which is being assigned to the port.
266 * This method attempts to make the assignment of the phy to the port. If
267 * successful the phy is assigned to the ports phy table. bool true if the phy
268 * assignment can be made. false if the phy assignement can not be made. This
269 * is a functional test that only fails if the phy is currently assigned to a
272 enum sci_status
scic_sds_port_set_phy(
273 struct scic_sds_port
*port
,
274 struct scic_sds_phy
*phy
)
277 * Check to see if we can add this phy to a port
278 * that means that the phy is not part of a port and that the port does
279 * not already have a phy assinged to the phy index. */
281 (port
->phy_table
[phy
->phy_index
] == NULL
)
282 && (scic_sds_phy_get_port(phy
) == NULL
)
283 && scic_sds_port_is_valid_phy_assignment(port
, phy
->phy_index
)
286 * Phy is being added in the stopped state so we are in MPC mode
287 * make logical port index = physical port index */
288 port
->logical_port_index
= port
->physical_port_index
;
289 port
->phy_table
[phy
->phy_index
] = phy
;
290 scic_sds_phy_set_port(phy
, port
);
299 * scic_sds_port_clear_phy() -
300 * @out]: port The port from which the phy is being cleared.
301 * @out]: phy The phy being cleared from the port.
303 * This method will clear the phy assigned to this port. This method fails if
304 * this phy is not currently assinged to this port. bool true if the phy is
305 * removed from the port. false if this phy is not assined to this port.
307 enum sci_status
scic_sds_port_clear_phy(
308 struct scic_sds_port
*port
,
309 struct scic_sds_phy
*phy
)
311 /* Make sure that this phy is part of this port */
313 (port
->phy_table
[phy
->phy_index
] == phy
)
314 && (scic_sds_phy_get_port(phy
) == port
)
316 /* Yep it is assigned to this port so remove it */
317 scic_sds_phy_set_port(
319 &scic_sds_port_get_controller(port
)->port_table
[SCI_MAX_PORTS
]
322 port
->phy_table
[phy
->phy_index
] = NULL
;
331 * scic_sds_port_add_phy() -
332 * @this_port: This parameter specifies the port in which the phy will be added.
333 * @the_phy: This parameter is the phy which is to be added to the port.
335 * This method will add a PHY to the selected port. This method returns an
336 * enum sci_status. SCI_SUCCESS the phy has been added to the port. Any other status
337 * is failre to add the phy to the port.
339 enum sci_status
scic_sds_port_add_phy(
340 struct scic_sds_port
*this_port
,
341 struct scic_sds_phy
*the_phy
)
343 return this_port
->state_handlers
->parent
.add_phy_handler(
344 &this_port
->parent
, &the_phy
->parent
);
349 * scic_sds_port_remove_phy() -
350 * @this_port: This parameter specifies the port in which the phy will be added.
351 * @the_phy: This parameter is the phy which is to be added to the port.
353 * This method will remove the PHY from the selected PORT. This method returns
354 * an enum sci_status. SCI_SUCCESS the phy has been removed from the port. Any other
355 * status is failre to add the phy to the port.
357 enum sci_status
scic_sds_port_remove_phy(
358 struct scic_sds_port
*this_port
,
359 struct scic_sds_phy
*the_phy
)
361 return this_port
->state_handlers
->parent
.remove_phy_handler(
362 &this_port
->parent
, &the_phy
->parent
);
366 * This method requests the SAS address for the supplied SAS port from the SCI
368 * @this_port: a handle corresponding to the SAS port for which to return the
370 * @sas_address: This parameter specifies a pointer to a SAS address structure
371 * into which the core will copy the SAS address for the port.
374 void scic_sds_port_get_sas_address(
375 struct scic_sds_port
*this_port
,
376 struct sci_sas_address
*sas_address
)
380 sas_address
->high
= 0;
381 sas_address
->low
= 0;
383 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
384 if (this_port
->phy_table
[index
] != NULL
) {
385 scic_sds_phy_get_sas_address(this_port
->phy_table
[index
], sas_address
);
391 * This method will indicate which protocols are supported by this port.
392 * @this_port: a handle corresponding to the SAS port for which to return the
393 * supported protocols.
394 * @protocols: This parameter specifies a pointer to an IAF protocol field
395 * structure into which the core will copy the protocol values for the port.
396 * The values are returned as part of a bit mask in order to allow for
397 * multi-protocol support.
400 static void scic_sds_port_get_protocols(
401 struct scic_sds_port
*this_port
,
402 struct sci_sas_identify_address_frame_protocols
*protocols
)
406 protocols
->u
.all
= 0;
408 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
409 if (this_port
->phy_table
[index
] != NULL
) {
410 scic_sds_phy_get_protocols(this_port
->phy_table
[index
], protocols
);
416 * This method requests the SAS address for the device directly attached to
418 * @this_port: a handle corresponding to the SAS port for which to return the
420 * @sas_address: This parameter specifies a pointer to a SAS address structure
421 * into which the core will copy the SAS address for the device directly
422 * attached to the port.
425 void scic_sds_port_get_attached_sas_address(
426 struct scic_sds_port
*this_port
,
427 struct sci_sas_address
*sas_address
)
429 struct sci_sas_identify_address_frame_protocols protocols
;
430 struct scic_sds_phy
*phy
;
433 * Ensure that the phy is both part of the port and currently
434 * connected to the remote end-point. */
435 phy
= scic_sds_port_get_a_connected_phy(this_port
);
437 scic_sds_phy_get_attached_phy_protocols(phy
, &protocols
);
439 if (!protocols
.u
.bits
.stp_target
) {
440 scic_sds_phy_get_attached_sas_address(phy
, sas_address
);
442 scic_sds_phy_get_sas_address(phy
, sas_address
);
443 sas_address
->low
+= phy
->phy_index
;
446 sas_address
->high
= 0;
447 sas_address
->low
= 0;
452 * This method will indicate which protocols are supported by this remote
454 * @this_port: a handle corresponding to the SAS port for which to return the
455 * supported protocols.
456 * @protocols: This parameter specifies a pointer to an IAF protocol field
457 * structure into which the core will copy the protocol values for the port.
458 * The values are returned as part of a bit mask in order to allow for
459 * multi-protocol support.
462 void scic_sds_port_get_attached_protocols(
463 struct scic_sds_port
*this_port
,
464 struct sci_sas_identify_address_frame_protocols
*protocols
)
466 struct scic_sds_phy
*phy
;
469 * Ensure that the phy is both part of the port and currently
470 * connected to the remote end-point. */
471 phy
= scic_sds_port_get_a_connected_phy(this_port
);
473 scic_sds_phy_get_attached_phy_protocols(phy
, protocols
);
475 protocols
->u
.all
= 0;
479 * scic_sds_port_construct_dummy_rnc() - create dummy rnc for si workaround
481 * @sci_port: logical port on which we need to create the remote node context
482 * @rni: remote node index for this remote node context.
484 * This routine will construct a dummy remote node context data structure
485 * This structure will be posted to the hardware to work around a scheduler
486 * error in the hardware.
488 void scic_sds_port_construct_dummy_rnc(struct scic_sds_port
*sci_port
, u16 rni
)
490 union scu_remote_node_context
*rnc
;
492 rnc
= &sci_port
->owning_controller
->remote_node_context_table
[rni
];
494 memset(rnc
, 0, sizeof(union scu_remote_node_context
));
496 rnc
->ssp
.remote_sas_address_hi
= 0;
497 rnc
->ssp
.remote_sas_address_lo
= 0;
499 rnc
->ssp
.remote_node_index
= rni
;
500 rnc
->ssp
.remote_node_port_width
= 1;
501 rnc
->ssp
.logical_port_index
= sci_port
->physical_port_index
;
503 rnc
->ssp
.nexus_loss_timer_enable
= false;
504 rnc
->ssp
.check_bit
= false;
505 rnc
->ssp
.is_valid
= true;
506 rnc
->ssp
.is_remote_node_context
= true;
507 rnc
->ssp
.function_number
= 0;
508 rnc
->ssp
.arbitration_wait_time
= 0;
512 * scic_sds_port_construct_dummy_task() - create dummy task for si workaround
513 * @sci_port The logical port on which we need to create the
514 * remote node context.
516 * @tci The remote node index for this remote node context.
518 * This routine will construct a dummy task context data structure. This
519 * structure will be posted to the hardwre to work around a scheduler error
523 void scic_sds_port_construct_dummy_task(struct scic_sds_port
*sci_port
, u16 tci
)
525 struct scu_task_context
*task_context
;
527 task_context
= scic_sds_controller_get_task_context_buffer(sci_port
->owning_controller
, tci
);
529 memset(task_context
, 0, sizeof(struct scu_task_context
));
531 task_context
->abort
= 0;
532 task_context
->priority
= 0;
533 task_context
->initiator_request
= 1;
534 task_context
->connection_rate
= 1;
535 task_context
->protocol_engine_index
= 0;
536 task_context
->logical_port_index
= sci_port
->physical_port_index
;
537 task_context
->protocol_type
= SCU_TASK_CONTEXT_PROTOCOL_SSP
;
538 task_context
->task_index
= scic_sds_io_tag_get_index(tci
);
539 task_context
->valid
= SCU_TASK_CONTEXT_VALID
;
540 task_context
->context_type
= SCU_TASK_CONTEXT_TYPE
;
542 task_context
->remote_node_index
= sci_port
->reserved_rni
;
543 task_context
->command_code
= 0;
545 task_context
->link_layer_control
= 0;
546 task_context
->do_not_dma_ssp_good_response
= 1;
547 task_context
->strict_ordering
= 0;
548 task_context
->control_frame
= 0;
549 task_context
->timeout_enable
= 0;
550 task_context
->block_guard_enable
= 0;
552 task_context
->address_modifier
= 0;
554 task_context
->task_phase
= 0x01;
557 void scic_sds_port_destroy_dummy_resources(struct scic_sds_port
*sci_port
)
559 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
561 if (sci_port
->reserved_tci
!= SCU_DUMMY_INDEX
)
562 scic_controller_free_io_tag(scic
, sci_port
->reserved_tci
);
564 if (sci_port
->reserved_rni
!= SCU_DUMMY_INDEX
)
565 scic_sds_remote_node_table_release_remote_node_index(&scic
->available_remote_nodes
,
566 1, sci_port
->reserved_rni
);
568 sci_port
->reserved_rni
= SCU_DUMMY_INDEX
;
569 sci_port
->reserved_tci
= SCU_DUMMY_INDEX
;
572 void scic_sds_port_construct(struct scic_sds_port
*sci_port
, u8 port_index
,
573 struct scic_sds_controller
*scic
)
577 sci_base_port_construct(&sci_port
->parent
, scic_sds_port_state_table
);
579 sci_base_state_machine_construct(
580 scic_sds_port_get_ready_substate_machine(sci_port
),
581 &sci_port
->parent
.parent
,
582 scic_sds_port_ready_substate_table
,
583 SCIC_SDS_PORT_READY_SUBSTATE_WAITING
586 sci_port
->logical_port_index
= SCIC_SDS_DUMMY_PORT
;
587 sci_port
->physical_port_index
= port_index
;
588 sci_port
->active_phy_mask
= 0;
590 sci_port
->owning_controller
= scic
;
592 sci_port
->started_request_count
= 0;
593 sci_port
->assigned_device_count
= 0;
595 sci_port
->reserved_rni
= SCU_DUMMY_INDEX
;
596 sci_port
->reserved_tci
= SCU_DUMMY_INDEX
;
598 sci_port
->timer_handle
= NULL
;
600 sci_port
->port_task_scheduler_registers
= NULL
;
602 for (index
= 0; index
< SCI_MAX_PHYS
; index
++)
603 sci_port
->phy_table
[index
] = NULL
;
607 * This method performs initialization of the supplied port. Initialization
608 * includes: - state machine initialization - member variable initialization
609 * - configuring the phy_mask
611 * @transport_layer_registers:
612 * @port_task_scheduler_registers:
613 * @port_configuration_regsiter:
615 * enum sci_status SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION This value is returned
616 * if the phy being added to the port
618 enum sci_status
scic_sds_port_initialize(
619 struct scic_sds_port
*this_port
,
620 void __iomem
*port_task_scheduler_registers
,
621 void __iomem
*port_configuration_regsiter
,
622 void __iomem
*viit_registers
)
624 this_port
->port_task_scheduler_registers
= port_task_scheduler_registers
;
625 this_port
->port_pe_configuration_register
= port_configuration_regsiter
;
626 this_port
->viit_registers
= viit_registers
;
633 * @this_port: This is the struct scic_sds_port object for which has a phy that has
635 * @the_phy: This is the struct scic_sds_phy object that has gone link up.
636 * @do_notify_user: This parameter specifies whether to inform the user (via
637 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
639 * This method is the a general link up handler for the struct scic_sds_port object.
640 * This function will determine if this struct scic_sds_phy can be assigned to this
641 * struct scic_sds_port object. If the struct scic_sds_phy object can is not a valid PHY for
642 * this port then the function will notify the SCIC_USER. A PHY can only be
643 * part of a port if it's attached SAS ADDRESS is the same as all other PHYs in
644 * the same port. none
646 void scic_sds_port_general_link_up_handler(
647 struct scic_sds_port
*this_port
,
648 struct scic_sds_phy
*the_phy
,
651 struct sci_sas_address port_sas_address
;
652 struct sci_sas_address phy_sas_address
;
654 scic_sds_port_get_attached_sas_address(this_port
, &port_sas_address
);
655 scic_sds_phy_get_attached_sas_address(the_phy
, &phy_sas_address
);
658 * If the SAS address of the new phy matches the SAS address of
659 * other phys in the port OR this is the first phy in the port,
660 * then activate the phy and allow it to be used for operations
664 (phy_sas_address
.high
== port_sas_address
.high
)
665 && (phy_sas_address
.low
== port_sas_address
.low
)
667 || (this_port
->active_phy_mask
== 0)
669 scic_sds_port_activate_phy(this_port
, the_phy
, do_notify_user
);
671 if (this_port
->parent
.state_machine
.current_state_id
672 == SCI_BASE_PORT_STATE_RESETTING
) {
673 sci_base_state_machine_change_state(
674 &this_port
->parent
.state_machine
, SCI_BASE_PORT_STATE_READY
678 scic_sds_port_invalid_link_up(this_port
, the_phy
);
682 enum sci_status
scic_port_stop(struct scic_sds_port
*port
)
684 return port
->state_handlers
->parent
.stop_handler(&port
->parent
);
687 enum sci_status
scic_port_get_properties(
688 struct scic_sds_port
*port
,
689 struct scic_port_properties
*prop
)
691 if ((port
== NULL
) ||
692 (port
->logical_port_index
== SCIC_SDS_DUMMY_PORT
))
693 return SCI_FAILURE_INVALID_PORT
;
695 prop
->index
= port
->logical_port_index
;
696 prop
->phy_mask
= scic_sds_port_get_phys(port
);
697 scic_sds_port_get_sas_address(port
, &prop
->local
.sas_address
);
698 scic_sds_port_get_protocols(port
, &prop
->local
.protocols
);
699 scic_sds_port_get_attached_sas_address(port
, &prop
->remote
.sas_address
);
700 scic_sds_port_get_attached_protocols(port
, &prop
->remote
.protocols
);
706 enum sci_status
scic_port_hard_reset(
707 struct scic_sds_port
*port
,
710 return port
->state_handlers
->parent
.reset_handler(
711 &port
->parent
, reset_timeout
);
715 * This method assigns the direct attached device ID for this port.
717 * @param[in] this_port The port for which the direct attached device id is to
719 * @param[in] device_id The direct attached device ID to assign to the port.
720 * This will be the RNi for the device
722 void scic_sds_port_setup_transports(
723 struct scic_sds_port
*this_port
,
728 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
729 if (this_port
->active_phy_mask
& (1 << index
))
730 scic_sds_phy_setup_transport(this_port
->phy_table
[index
], device_id
);
736 * @this_port: This is the port on which the phy should be enabled.
737 * @the_phy: This is the specific phy which to enable.
738 * @do_notify_user: This parameter specifies whether to inform the user (via
739 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
741 * This method will activate the phy in the port. Activation includes: - adding
742 * the phy to the port - enabling the Protocol Engine in the silicon. -
743 * notifying the user that the link is up. none
745 void scic_sds_port_activate_phy(
746 struct scic_sds_port
*this_port
,
747 struct scic_sds_phy
*the_phy
,
750 struct scic_sds_controller
*controller
;
751 struct sci_sas_identify_address_frame_protocols protocols
;
753 controller
= scic_sds_port_get_controller(this_port
);
754 scic_sds_phy_get_attached_phy_protocols(the_phy
, &protocols
);
756 /* If this is sata port then the phy has already been resumed */
757 if (!protocols
.u
.bits
.stp_target
) {
758 scic_sds_phy_resume(the_phy
);
761 this_port
->active_phy_mask
|= 1 << the_phy
->phy_index
;
763 scic_sds_controller_clear_invalid_phy(controller
, the_phy
);
765 if (do_notify_user
== true)
766 isci_event_port_link_up(this_port
->owning_controller
,
773 * @this_port: This is the port on which the phy should be deactivated.
774 * @the_phy: This is the specific phy that is no longer active in the port.
775 * @do_notify_user: This parameter specifies whether to inform the user (via
776 * isci_event_port_link_down()) as to the fact that a new phy as become
779 * This method will deactivate the supplied phy in the port. none
781 void scic_sds_port_deactivate_phy(
782 struct scic_sds_port
*this_port
,
783 struct scic_sds_phy
*the_phy
,
786 this_port
->active_phy_mask
&= ~(1 << the_phy
->phy_index
);
788 the_phy
->max_negotiated_speed
= SCI_SAS_NO_LINK_RATE
;
790 /* Re-assign the phy back to the LP as if it were a narrow port */
791 SCU_PCSPExCR_WRITE(this_port
, the_phy
->phy_index
, the_phy
->phy_index
);
793 if (do_notify_user
== true)
794 isci_event_port_link_down(this_port
->owning_controller
,
801 * @this_port: This is the port on which the phy should be disabled.
802 * @the_phy: This is the specific phy which to disabled.
804 * This method will disable the phy and report that the phy is not valid for
805 * this port object. None
807 static void scic_sds_port_invalid_link_up(
808 struct scic_sds_port
*this_port
,
809 struct scic_sds_phy
*the_phy
)
811 struct scic_sds_controller
*controller
= scic_sds_port_get_controller(this_port
);
814 * Check to see if we have alreay reported this link as bad and if not go
815 * ahead and tell the SCI_USER that we have discovered an invalid link. */
816 if ((controller
->invalid_phy_mask
& (1 << the_phy
->phy_index
)) == 0) {
817 scic_sds_controller_set_invalid_phy(controller
, the_phy
);
819 isci_event_port_invalid_link_up(controller
, this_port
, the_phy
);
824 * This method returns false if the port only has a single phy object assigned.
825 * If there are no phys or more than one phy then the method will return
827 * @this_port: The port for which the wide port condition is to be checked.
829 * bool true Is returned if this is a wide ported port. false Is returned if
830 * this is a narrow port.
832 static bool scic_sds_port_is_wide(struct scic_sds_port
*this_port
)
837 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
838 if (this_port
->phy_table
[index
] != NULL
) {
843 return phy_count
!= 1;
847 * This method is called by the PHY object when the link is detected. if the
848 * port wants the PHY to continue on to the link up state then the port
849 * layer must return true. If the port object returns false the phy object
850 * must halt its attempt to go link up.
851 * @this_port: The port associated with the phy object.
852 * @the_phy: The phy object that is trying to go link up.
854 * true if the phy object can continue to the link up condition. true Is
855 * returned if this phy can continue to the ready state. false Is returned if
856 * can not continue on to the ready state. This notification is in place for
857 * wide ports and direct attached phys. Since there are no wide ported SATA
858 * devices this could become an invalid port configuration.
860 bool scic_sds_port_link_detected(
861 struct scic_sds_port
*this_port
,
862 struct scic_sds_phy
*the_phy
)
864 struct sci_sas_identify_address_frame_protocols protocols
;
866 scic_sds_phy_get_attached_phy_protocols(the_phy
, &protocols
);
869 (this_port
->logical_port_index
!= SCIC_SDS_DUMMY_PORT
)
870 && (protocols
.u
.bits
.stp_target
)
871 && scic_sds_port_is_wide(this_port
)
873 scic_sds_port_invalid_link_up(this_port
, the_phy
);
882 * This method is the entry point for the phy to inform the port that it is now
888 void scic_sds_port_link_up(
889 struct scic_sds_port
*this_port
,
890 struct scic_sds_phy
*the_phy
)
892 the_phy
->is_in_link_training
= false;
894 this_port
->state_handlers
->link_up_handler(this_port
, the_phy
);
898 * This method is the entry point for the phy to inform the port that it is no
899 * longer in a ready state
904 void scic_sds_port_link_down(
905 struct scic_sds_port
*this_port
,
906 struct scic_sds_phy
*the_phy
)
908 this_port
->state_handlers
->link_down_handler(this_port
, the_phy
);
912 * This method is called to start an IO request on this port.
919 enum sci_status
scic_sds_port_start_io(
920 struct scic_sds_port
*this_port
,
921 struct scic_sds_remote_device
*the_device
,
922 struct scic_sds_request
*the_io_request
)
924 return this_port
->state_handlers
->start_io_handler(
925 this_port
, the_device
, the_io_request
);
929 * This method is called to complete an IO request to the port.
936 enum sci_status
scic_sds_port_complete_io(
937 struct scic_sds_port
*this_port
,
938 struct scic_sds_remote_device
*the_device
,
939 struct scic_sds_request
*the_io_request
)
941 return this_port
->state_handlers
->complete_io_handler(
942 this_port
, the_device
, the_io_request
);
946 * This method is provided to timeout requests for port operations. Mostly its
947 * for the port reset operation.
951 static void scic_sds_port_timeout_handler(void *port
)
953 struct scic_sds_port
*this_port
= port
;
956 current_state
= sci_base_state_machine_get_state(
957 &this_port
->parent
.state_machine
);
959 if (current_state
== SCI_BASE_PORT_STATE_RESETTING
) {
961 * if the port is still in the resetting state then the timeout fired
962 * before the reset completed. */
963 sci_base_state_machine_change_state(
964 &this_port
->parent
.state_machine
,
965 SCI_BASE_PORT_STATE_FAILED
967 } else if (current_state
== SCI_BASE_PORT_STATE_STOPPED
) {
969 * if the port is stopped then the start request failed
970 * In this case stay in the stopped state. */
971 dev_err(sciport_to_dev(this_port
),
972 "%s: SCIC Port 0x%p failed to stop before tiemout.\n",
975 } else if (current_state
== SCI_BASE_PORT_STATE_STOPPING
) {
976 /* if the port is still stopping then the stop has not completed */
977 isci_event_port_stop_complete(
978 scic_sds_port_get_controller(this_port
),
984 * The port is in the ready state and we have a timer reporting a timeout
985 * this should not happen. */
986 dev_err(sciport_to_dev(this_port
),
987 "%s: SCIC Port 0x%p is processing a timeout operation "
995 /* --------------------------------------------------------------------------- */
998 * This function updates the hardwares VIIT entry for this port.
1002 void scic_sds_port_update_viit_entry(struct scic_sds_port
*this_port
)
1004 struct sci_sas_address sas_address
;
1006 scic_sds_port_get_sas_address(this_port
, &sas_address
);
1008 scu_port_viit_register_write(
1009 this_port
, initiator_sas_address_hi
, sas_address
.high
);
1011 scu_port_viit_register_write(
1012 this_port
, initiator_sas_address_lo
, sas_address
.low
);
1014 /* This value get cleared just in case its not already cleared */
1015 scu_port_viit_register_write(
1016 this_port
, reserved
, 0);
1018 /* We are required to update the status register last */
1019 scu_port_viit_register_write(
1020 this_port
, status
, (
1021 SCU_VIIT_ENTRY_ID_VIIT
1022 | SCU_VIIT_IPPT_INITIATOR
1023 | ((1 << this_port
->physical_port_index
) << SCU_VIIT_ENTRY_LPVIE_SHIFT
)
1024 | SCU_VIIT_STATUS_ALL_VALID
1030 * This method returns the maximum allowed speed for data transfers on this
1031 * port. This maximum allowed speed evaluates to the maximum speed of the
1032 * slowest phy in the port.
1033 * @this_port: This parameter specifies the port for which to retrieve the
1034 * maximum allowed speed.
1036 * This method returns the maximum negotiated speed of the slowest phy in the
1039 enum sci_sas_link_rate
scic_sds_port_get_max_allowed_speed(
1040 struct scic_sds_port
*this_port
)
1043 enum sci_sas_link_rate max_allowed_speed
= SCI_SAS_600_GB
;
1044 struct scic_sds_phy
*phy
= NULL
;
1047 * Loop through all of the phys in this port and find the phy with the
1048 * lowest maximum link rate. */
1049 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
1050 phy
= this_port
->phy_table
[index
];
1053 && (scic_sds_port_active_phy(this_port
, phy
) == true)
1054 && (phy
->max_negotiated_speed
< max_allowed_speed
)
1056 max_allowed_speed
= phy
->max_negotiated_speed
;
1059 return max_allowed_speed
;
1064 * This method passes the event to core user.
1065 * @this_port: The port that a BCN happens.
1066 * @this_phy: The phy that receives BCN.
1069 void scic_sds_port_broadcast_change_received(
1070 struct scic_sds_port
*this_port
,
1071 struct scic_sds_phy
*this_phy
)
1073 /* notify the user. */
1074 isci_event_port_bc_change_primitive_received(
1075 this_port
->owning_controller
, this_port
, this_phy
1081 * This API methhod enables the broadcast change notification from underneath
1083 * @this_port: The port that a BCN had been disabled from.
1086 void scic_port_enable_broadcast_change_notification(
1087 struct scic_sds_port
*port
)
1089 struct scic_sds_phy
*phy
;
1093 /* Loop through all of the phys to enable BCN. */
1094 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
1095 phy
= port
->phy_table
[index
];
1097 register_value
= SCU_SAS_LLCTL_READ(phy
);
1099 /* clear the bit by writing 1. */
1100 SCU_SAS_LLCTL_WRITE(phy
, register_value
);
1106 * ****************************************************************************
1107 * * READY SUBSTATE HANDLERS
1108 * **************************************************************************** */
1112 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1115 * This method is the general ready state stop handler for the struct scic_sds_port
1116 * object. This function will transition the ready substate machine to its
1117 * final state. enum sci_status SCI_SUCCESS
1119 static enum sci_status
scic_sds_port_ready_substate_stop_handler(
1120 struct sci_base_port
*port
)
1122 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
1124 sci_base_state_machine_change_state(
1125 &this_port
->parent
.state_machine
,
1126 SCI_BASE_PORT_STATE_STOPPING
1134 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1136 * @device: This is the struct sci_base_remote_device object which is not used in this
1138 * @io_request: This is the struct sci_base_request object which is not used in this
1141 * This method is the general ready substate complete io handler for the
1142 * struct scic_sds_port object. This function decrments the outstanding request count
1143 * for this port object. enum sci_status SCI_SUCCESS
1145 static enum sci_status
scic_sds_port_ready_substate_complete_io_handler(
1146 struct scic_sds_port
*port
,
1147 struct scic_sds_remote_device
*device
,
1148 struct scic_sds_request
*io_request
)
1150 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
1152 scic_sds_port_decrement_request_count(this_port
);
1157 static enum sci_status
scic_sds_port_ready_substate_add_phy_handler(
1158 struct sci_base_port
*port
,
1159 struct sci_base_phy
*phy
)
1161 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
1162 struct scic_sds_phy
*this_phy
= (struct scic_sds_phy
*)phy
;
1163 enum sci_status status
;
1165 status
= scic_sds_port_set_phy(this_port
, this_phy
);
1167 if (status
== SCI_SUCCESS
) {
1168 scic_sds_port_general_link_up_handler(this_port
, this_phy
, true);
1170 this_port
->not_ready_reason
= SCIC_PORT_NOT_READY_RECONFIGURING
;
1172 sci_base_state_machine_change_state(
1173 &this_port
->ready_substate_machine
,
1174 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1182 static enum sci_status
scic_sds_port_ready_substate_remove_phy_handler(
1183 struct sci_base_port
*port
,
1184 struct sci_base_phy
*phy
)
1186 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
1187 struct scic_sds_phy
*this_phy
= (struct scic_sds_phy
*)phy
;
1188 enum sci_status status
;
1190 status
= scic_sds_port_clear_phy(this_port
, this_phy
);
1192 if (status
== SCI_SUCCESS
) {
1193 scic_sds_port_deactivate_phy(this_port
, this_phy
, true);
1195 this_port
->not_ready_reason
= SCIC_PORT_NOT_READY_RECONFIGURING
;
1197 sci_base_state_machine_change_state(
1198 &this_port
->ready_substate_machine
,
1199 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1207 * ****************************************************************************
1208 * * READY SUBSTATE WAITING HANDLERS
1209 * **************************************************************************** */
1213 * @this_port: This is the struct scic_sds_port object that which has a phy that has
1215 * @the_phy: This is the struct scic_sds_phy object that has gone link up.
1217 * This method is the ready waiting substate link up handler for the
1218 * struct scic_sds_port object. This methos will report the link up condition for
1219 * this port and will transition to the ready operational substate. none
1221 static void scic_sds_port_ready_waiting_substate_link_up_handler(
1222 struct scic_sds_port
*this_port
,
1223 struct scic_sds_phy
*the_phy
)
1226 * Since this is the first phy going link up for the port we can just enable
1227 * it and continue. */
1228 scic_sds_port_activate_phy(this_port
, the_phy
, true);
1230 sci_base_state_machine_change_state(
1231 &this_port
->ready_substate_machine
,
1232 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1238 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1240 * @device: This is the struct sci_base_remote_device object which is not used in this
1242 * @io_request: This is the struct sci_base_request object which is not used in this
1245 * This method is the ready waiting substate start io handler for the
1246 * struct scic_sds_port object. The port object can not accept new requests so the
1247 * request is failed. enum sci_status SCI_FAILURE_INVALID_STATE
1249 static enum sci_status
scic_sds_port_ready_waiting_substate_start_io_handler(
1250 struct scic_sds_port
*port
,
1251 struct scic_sds_remote_device
*device
,
1252 struct scic_sds_request
*io_request
)
1254 return SCI_FAILURE_INVALID_STATE
;
1258 * ****************************************************************************
1259 * * READY SUBSTATE OPERATIONAL HANDLERS
1260 * **************************************************************************** */
1264 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1266 * @timeout: This is the timeout for the reset request to complete.
1268 * This method will casue the port to reset. enum sci_status SCI_SUCCESS
1270 static enum sci_status
scic_sds_port_ready_operational_substate_reset_handler(
1271 struct sci_base_port
*port
,
1274 enum sci_status status
= SCI_FAILURE_INVALID_PHY
;
1276 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
1277 struct scic_sds_phy
*selected_phy
= NULL
;
1280 /* Select a phy on which we can send the hard reset request. */
1283 (phy_index
< SCI_MAX_PHYS
)
1284 && (selected_phy
== NULL
);
1287 selected_phy
= this_port
->phy_table
[phy_index
];
1290 (selected_phy
!= NULL
)
1291 && !scic_sds_port_active_phy(this_port
, selected_phy
)
1293 /* We found a phy but it is not ready select different phy */
1294 selected_phy
= NULL
;
1298 /* If we have a phy then go ahead and start the reset procedure */
1299 if (selected_phy
!= NULL
) {
1300 status
= scic_sds_phy_reset(selected_phy
);
1302 if (status
== SCI_SUCCESS
) {
1303 isci_event_timer_start(
1304 scic_sds_port_get_controller(this_port
),
1305 this_port
->timer_handle
,
1309 this_port
->not_ready_reason
= SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED
;
1311 sci_base_state_machine_change_state(
1312 &this_port
->parent
.state_machine
,
1313 SCI_BASE_PORT_STATE_RESETTING
1322 * scic_sds_port_ready_operational_substate_link_up_handler() -
1323 * @this_port: This is the struct scic_sds_port object that which has a phy that has
1325 * @the_phy: This is the struct scic_sds_phy object that has gone link up.
1327 * This method is the ready operational substate link up handler for the
1328 * struct scic_sds_port object. This function notifies the SCI User that the phy has
1329 * gone link up. none
1331 static void scic_sds_port_ready_operational_substate_link_up_handler(
1332 struct scic_sds_port
*this_port
,
1333 struct scic_sds_phy
*the_phy
)
1335 scic_sds_port_general_link_up_handler(this_port
, the_phy
, true);
1339 * scic_sds_port_ready_operational_substate_link_down_handler() -
1340 * @this_port: This is the struct scic_sds_port object that which has a phy that has
1342 * @the_phy: This is the struct scic_sds_phy object that has gone link down.
1344 * This method is the ready operational substate link down handler for the
1345 * struct scic_sds_port object. This function notifies the SCI User that the phy has
1346 * gone link down and if this is the last phy in the port the port will change
1347 * state to the ready waiting substate. none
1349 static void scic_sds_port_ready_operational_substate_link_down_handler(
1350 struct scic_sds_port
*this_port
,
1351 struct scic_sds_phy
*the_phy
)
1353 scic_sds_port_deactivate_phy(this_port
, the_phy
, true);
1356 * If there are no active phys left in the port, then transition
1357 * the port to the WAITING state until such time as a phy goes
1359 if (this_port
->active_phy_mask
== 0) {
1360 sci_base_state_machine_change_state(
1361 scic_sds_port_get_ready_substate_machine(this_port
),
1362 SCIC_SDS_PORT_READY_SUBSTATE_WAITING
1369 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1371 * @device: This is the struct sci_base_remote_device object which is not used in this
1373 * @io_request: This is the struct sci_base_request object which is not used in this
1376 * This method is the ready operational substate start io handler for the
1377 * struct scic_sds_port object. This function incremetns the outstanding request
1378 * count for this port object. enum sci_status SCI_SUCCESS
1380 static enum sci_status
scic_sds_port_ready_operational_substate_start_io_handler(
1381 struct scic_sds_port
*port
,
1382 struct scic_sds_remote_device
*device
,
1383 struct scic_sds_request
*io_request
)
1385 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
1387 scic_sds_port_increment_request_count(this_port
);
1393 * ****************************************************************************
1394 * * READY SUBSTATE OPERATIONAL HANDLERS
1395 * **************************************************************************** */
1398 * scic_sds_port_ready_configuring_substate_add_phy_handler() -
1399 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1402 * This is the default method for a port add phy request. It will report a
1403 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1405 static enum sci_status
scic_sds_port_ready_configuring_substate_add_phy_handler(
1406 struct sci_base_port
*port
,
1407 struct sci_base_phy
*phy
)
1409 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
1410 struct scic_sds_phy
*this_phy
= (struct scic_sds_phy
*)phy
;
1411 enum sci_status status
;
1413 status
= scic_sds_port_set_phy(this_port
, this_phy
);
1415 if (status
== SCI_SUCCESS
) {
1416 scic_sds_port_general_link_up_handler(this_port
, this_phy
, true);
1419 * Re-enter the configuring state since this may be the last phy in
1421 sci_base_state_machine_change_state(
1422 &this_port
->ready_substate_machine
,
1423 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1431 * scic_sds_port_ready_configuring_substate_remove_phy_handler() -
1432 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1435 * This is the default method for a port remove phy request. It will report a
1436 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1438 static enum sci_status
scic_sds_port_ready_configuring_substate_remove_phy_handler(
1439 struct sci_base_port
*port
,
1440 struct sci_base_phy
*phy
)
1442 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
1443 struct scic_sds_phy
*this_phy
= (struct scic_sds_phy
*)phy
;
1444 enum sci_status status
;
1446 status
= scic_sds_port_clear_phy(this_port
, this_phy
);
1448 if (status
== SCI_SUCCESS
) {
1449 scic_sds_port_deactivate_phy(this_port
, this_phy
, true);
1452 * Re-enter the configuring state since this may be the last phy in
1454 sci_base_state_machine_change_state(
1455 &this_port
->ready_substate_machine
,
1456 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1464 * scic_sds_port_ready_configuring_substate_complete_io_handler() -
1465 * @port: This is the port that is being requested to complete the io request.
1466 * @device: This is the device on which the io is completing.
1468 * This method will decrement the outstanding request count for this port. If
1469 * the request count goes to 0 then the port can be reprogrammed with its new
1472 static enum sci_status
scic_sds_port_ready_configuring_substate_complete_io_handler(
1473 struct scic_sds_port
*port
,
1474 struct scic_sds_remote_device
*device
,
1475 struct scic_sds_request
*io_request
)
1477 scic_sds_port_decrement_request_count(port
);
1479 if (port
->started_request_count
== 0) {
1480 sci_base_state_machine_change_state(
1481 &port
->ready_substate_machine
,
1482 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1489 /* --------------------------------------------------------------------------- */
1491 struct scic_sds_port_state_handler
1492 scic_sds_port_ready_substate_handler_table
[SCIC_SDS_PORT_READY_MAX_SUBSTATES
] =
1494 /* SCIC_SDS_PORT_READY_SUBSTATE_WAITING */
1497 scic_sds_port_default_start_handler
,
1498 scic_sds_port_ready_substate_stop_handler
,
1499 scic_sds_port_default_destruct_handler
,
1500 scic_sds_port_default_reset_handler
,
1501 scic_sds_port_ready_substate_add_phy_handler
,
1502 scic_sds_port_default_remove_phy_handler
1504 scic_sds_port_default_frame_handler
,
1505 scic_sds_port_default_event_handler
,
1506 scic_sds_port_ready_waiting_substate_link_up_handler
,
1507 scic_sds_port_default_link_down_handler
,
1508 scic_sds_port_ready_waiting_substate_start_io_handler
,
1509 scic_sds_port_ready_substate_complete_io_handler
,
1511 /* SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL */
1514 scic_sds_port_default_start_handler
,
1515 scic_sds_port_ready_substate_stop_handler
,
1516 scic_sds_port_default_destruct_handler
,
1517 scic_sds_port_ready_operational_substate_reset_handler
,
1518 scic_sds_port_ready_substate_add_phy_handler
,
1519 scic_sds_port_ready_substate_remove_phy_handler
1521 scic_sds_port_default_frame_handler
,
1522 scic_sds_port_default_event_handler
,
1523 scic_sds_port_ready_operational_substate_link_up_handler
,
1524 scic_sds_port_ready_operational_substate_link_down_handler
,
1525 scic_sds_port_ready_operational_substate_start_io_handler
,
1526 scic_sds_port_ready_substate_complete_io_handler
1528 /* SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING */
1531 scic_sds_port_default_start_handler
,
1532 scic_sds_port_ready_substate_stop_handler
,
1533 scic_sds_port_default_destruct_handler
,
1534 scic_sds_port_default_reset_handler
,
1535 scic_sds_port_ready_configuring_substate_add_phy_handler
,
1536 scic_sds_port_ready_configuring_substate_remove_phy_handler
1538 scic_sds_port_default_frame_handler
,
1539 scic_sds_port_default_event_handler
,
1540 scic_sds_port_default_link_up_handler
,
1541 scic_sds_port_default_link_down_handler
,
1542 scic_sds_port_default_start_io_handler
,
1543 scic_sds_port_ready_configuring_substate_complete_io_handler
1549 * scic_sds_port_set_ready_state_handlers() -
1551 * This macro sets the port ready substate handlers.
1553 #define scic_sds_port_set_ready_state_handlers(port, state_id) \
1554 scic_sds_port_set_state_handlers(\
1555 port, &scic_sds_port_ready_substate_handler_table[(state_id)] \
1559 * ******************************************************************************
1560 * * PORT STATE PRIVATE METHODS
1561 * ****************************************************************************** */
1565 * @this_port: This is the struct scic_sds_port object to suspend.
1567 * This method will susped the port task scheduler for this port object. none
1569 static void scic_sds_port_suspend_port_task_scheduler(
1570 struct scic_sds_port
*this_port
)
1572 u32 pts_control_value
;
1574 pts_control_value
= scu_port_task_scheduler_read(this_port
, control
);
1576 pts_control_value
|= SCU_PTSxCR_GEN_BIT(SUSPEND
);
1578 scu_port_task_scheduler_write(this_port
, control
, pts_control_value
);
1582 * scic_sds_port_post_dummy_request() - post dummy/workaround request
1583 * @sci_port: port to post task
1585 * Prevent the hardware scheduler from posting new requests to the front
1586 * of the scheduler queue causing a starvation problem for currently
1590 void scic_sds_port_post_dummy_request(struct scic_sds_port
*sci_port
)
1593 struct scu_task_context
*task_context
;
1594 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1595 u16 tci
= sci_port
->reserved_tci
;
1597 task_context
= scic_sds_controller_get_task_context_buffer(scic
, tci
);
1599 task_context
->abort
= 0;
1601 command
= SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC
|
1602 sci_port
->physical_port_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
|
1605 scic_sds_controller_post_request(scic
, command
);
1609 * This routine will abort the dummy request. This will alow the hardware to
1610 * power down parts of the silicon to save power.
1612 * @sci_port: The port on which the task must be aborted.
1615 void scic_sds_port_abort_dummy_request(struct scic_sds_port
*sci_port
)
1617 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1618 u16 tci
= sci_port
->reserved_tci
;
1619 struct scu_task_context
*tc
;
1622 tc
= scic_sds_controller_get_task_context_buffer(scic
, tci
);
1626 command
= SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT
|
1627 sci_port
->physical_port_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
|
1630 scic_sds_controller_post_request(scic
, command
);
1635 * @this_port: This is the struct scic_sds_port object to resume.
1637 * This method will resume the port task scheduler for this port object. none
1639 static void scic_sds_port_resume_port_task_scheduler(
1640 struct scic_sds_port
*this_port
)
1642 u32 pts_control_value
;
1644 pts_control_value
= scu_port_task_scheduler_read(this_port
, control
);
1646 pts_control_value
&= ~SCU_PTSxCR_GEN_BIT(SUSPEND
);
1648 scu_port_task_scheduler_write(this_port
, control
, pts_control_value
);
1652 * ******************************************************************************
1653 * * PORT READY SUBSTATE METHODS
1654 * ****************************************************************************** */
1658 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
1660 * This method will perform the actions required by the struct scic_sds_port on
1661 * entering the SCIC_SDS_PORT_READY_SUBSTATE_WAITING. This function checks the
1662 * port for any ready phys. If there is at least one phy in a ready state then
1663 * the port transitions to the ready operational substate. none
1665 static void scic_sds_port_ready_substate_waiting_enter(
1666 struct sci_base_object
*object
)
1668 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)object
;
1670 scic_sds_port_set_ready_state_handlers(
1671 this_port
, SCIC_SDS_PORT_READY_SUBSTATE_WAITING
1674 scic_sds_port_suspend_port_task_scheduler(this_port
);
1676 this_port
->not_ready_reason
= SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS
;
1678 if (this_port
->active_phy_mask
!= 0) {
1679 /* At least one of the phys on the port is ready */
1680 sci_base_state_machine_change_state(
1681 &this_port
->ready_substate_machine
,
1682 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1689 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
1691 * This method will perform the actions required by the struct scic_sds_port on
1692 * entering the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function sets
1693 * the state handlers for the port object, notifies the SCI User that the port
1694 * is ready, and resumes port operations. none
1696 static void scic_sds_port_ready_substate_operational_enter(
1697 struct sci_base_object
*object
)
1700 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)object
;
1702 scic_sds_port_set_ready_state_handlers(
1703 this_port
, SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1706 isci_event_port_ready(
1707 scic_sds_port_get_controller(this_port
), this_port
1710 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
1711 if (this_port
->phy_table
[index
] != NULL
) {
1712 scic_sds_port_write_phy_assignment(
1713 this_port
, this_port
->phy_table
[index
]
1718 scic_sds_port_update_viit_entry(this_port
);
1720 scic_sds_port_resume_port_task_scheduler(this_port
);
1722 /* Post the dummy task for the port so the hardware can schedule
1725 scic_sds_port_post_dummy_request(this_port
);
1730 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
1732 * This method will perform the actions required by the struct scic_sds_port on
1733 * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
1734 * the port not ready and suspends the port task scheduler. none
1736 static void scic_sds_port_ready_substate_operational_exit(
1737 struct sci_base_object
*object
)
1739 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)object
;
1742 * Kill the dummy task for this port if it has not yet posted
1743 * the hardware will treat this as a NOP and just return abort
1746 scic_sds_port_abort_dummy_request(this_port
);
1748 isci_event_port_not_ready(
1749 scic_sds_port_get_controller(this_port
),
1751 this_port
->not_ready_reason
1756 * ******************************************************************************
1757 * * PORT READY CONFIGURING METHODS
1758 * ****************************************************************************** */
1761 * scic_sds_port_ready_substate_configuring_enter() -
1762 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
1764 * This method will perform the actions required by the struct scic_sds_port on
1765 * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
1766 * the port not ready and suspends the port task scheduler. none
1768 static void scic_sds_port_ready_substate_configuring_enter(
1769 struct sci_base_object
*object
)
1771 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)object
;
1773 scic_sds_port_set_ready_state_handlers(
1774 this_port
, SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1777 if (this_port
->active_phy_mask
== 0) {
1778 isci_event_port_not_ready(
1779 scic_sds_port_get_controller(this_port
),
1781 SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS
1784 sci_base_state_machine_change_state(
1785 &this_port
->ready_substate_machine
,
1786 SCIC_SDS_PORT_READY_SUBSTATE_WAITING
1788 } else if (this_port
->started_request_count
== 0) {
1789 sci_base_state_machine_change_state(
1790 &this_port
->ready_substate_machine
,
1791 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1796 static void scic_sds_port_ready_substate_configuring_exit(
1797 struct sci_base_object
*object
)
1799 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)object
;
1801 scic_sds_port_suspend_port_task_scheduler(this_port
);
1804 /* --------------------------------------------------------------------------- */
1806 const struct sci_base_state scic_sds_port_ready_substate_table
[] = {
1807 [SCIC_SDS_PORT_READY_SUBSTATE_WAITING
] = {
1808 .enter_state
= scic_sds_port_ready_substate_waiting_enter
,
1810 [SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
] = {
1811 .enter_state
= scic_sds_port_ready_substate_operational_enter
,
1812 .exit_state
= scic_sds_port_ready_substate_operational_exit
1814 [SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
] = {
1815 .enter_state
= scic_sds_port_ready_substate_configuring_enter
,
1816 .exit_state
= scic_sds_port_ready_substate_configuring_exit
1821 * ***************************************************************************
1822 * * DEFAULT HANDLERS
1823 * *************************************************************************** */
1827 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1830 * This is the default method for port a start request. It will report a
1831 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1833 enum sci_status
scic_sds_port_default_start_handler(
1834 struct sci_base_port
*port
)
1836 struct scic_sds_port
*sci_port
= (struct scic_sds_port
*)port
;
1838 dev_warn(sciport_to_dev(sci_port
),
1839 "%s: SCIC Port 0x%p requested to start while in invalid "
1843 sci_base_state_machine_get_state(
1844 scic_sds_port_get_base_state_machine(
1845 (struct scic_sds_port
*)port
)));
1847 return SCI_FAILURE_INVALID_STATE
;
1852 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1855 * This is the default method for a port stop request. It will report a
1856 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1858 static enum sci_status
scic_sds_port_default_stop_handler(
1859 struct sci_base_port
*port
)
1861 struct scic_sds_port
*sci_port
= (struct scic_sds_port
*)port
;
1863 dev_warn(sciport_to_dev(sci_port
),
1864 "%s: SCIC Port 0x%p requested to stop while in invalid "
1868 sci_base_state_machine_get_state(
1869 scic_sds_port_get_base_state_machine(
1870 (struct scic_sds_port
*)port
)));
1872 return SCI_FAILURE_INVALID_STATE
;
1877 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1880 * This is the default method for a port destruct request. It will report a
1881 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1883 enum sci_status
scic_sds_port_default_destruct_handler(
1884 struct sci_base_port
*port
)
1886 struct scic_sds_port
*sci_port
= (struct scic_sds_port
*)port
;
1888 dev_warn(sciport_to_dev(sci_port
),
1889 "%s: SCIC Port 0x%p requested to destruct while in invalid "
1893 sci_base_state_machine_get_state(
1894 scic_sds_port_get_base_state_machine(
1895 (struct scic_sds_port
*)port
)));
1897 return SCI_FAILURE_INVALID_STATE
;
1902 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1904 * @timeout: This is the timeout for the reset request to complete.
1906 * This is the default method for a port reset request. It will report a
1907 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1909 enum sci_status
scic_sds_port_default_reset_handler(
1910 struct sci_base_port
*port
,
1913 struct scic_sds_port
*sci_port
= (struct scic_sds_port
*)port
;
1915 dev_warn(sciport_to_dev(sci_port
),
1916 "%s: SCIC Port 0x%p requested to reset while in invalid "
1920 sci_base_state_machine_get_state(
1921 scic_sds_port_get_base_state_machine(
1922 (struct scic_sds_port
*)port
)));
1924 return SCI_FAILURE_INVALID_STATE
;
1929 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1932 * This is the default method for a port add phy request. It will report a
1933 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1935 static enum sci_status
scic_sds_port_default_add_phy_handler(
1936 struct sci_base_port
*port
,
1937 struct sci_base_phy
*phy
)
1939 struct scic_sds_port
*sci_port
= (struct scic_sds_port
*)port
;
1941 dev_warn(sciport_to_dev(sci_port
),
1942 "%s: SCIC Port 0x%p requested to add phy 0x%p while in "
1943 "invalid state %d\n",
1947 sci_base_state_machine_get_state(
1948 scic_sds_port_get_base_state_machine(
1949 (struct scic_sds_port
*)port
)));
1951 return SCI_FAILURE_INVALID_STATE
;
1956 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1959 * This is the default method for a port remove phy request. It will report a
1960 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1962 enum sci_status
scic_sds_port_default_remove_phy_handler(
1963 struct sci_base_port
*port
,
1964 struct sci_base_phy
*phy
)
1966 struct scic_sds_port
*sci_port
= (struct scic_sds_port
*)port
;
1968 dev_warn(sciport_to_dev(sci_port
),
1969 "%s: SCIC Port 0x%p requested to remove phy 0x%p while in "
1970 "invalid state %d\n",
1974 sci_base_state_machine_get_state(
1975 scic_sds_port_get_base_state_machine(
1976 (struct scic_sds_port
*)port
)));
1978 return SCI_FAILURE_INVALID_STATE
;
1983 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1986 * This is the default method for a port unsolicited frame request. It will
1987 * report a warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE Is it even
1988 * possible to receive an unsolicited frame directed to a port object? It
1989 * seems possible if we implementing virtual functions but until then?
1991 enum sci_status
scic_sds_port_default_frame_handler(
1992 struct scic_sds_port
*port
,
1995 dev_warn(sciport_to_dev(port
),
1996 "%s: SCIC Port 0x%p requested to process frame %d while in "
1997 "invalid state %d\n",
2001 sci_base_state_machine_get_state(
2002 scic_sds_port_get_base_state_machine(port
)));
2004 scic_sds_controller_release_frame(
2005 scic_sds_port_get_controller(port
), frame_index
2008 return SCI_FAILURE_INVALID_STATE
;
2013 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2016 * This is the default method for a port event request. It will report a
2017 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
2019 enum sci_status
scic_sds_port_default_event_handler(
2020 struct scic_sds_port
*port
,
2023 dev_warn(sciport_to_dev(port
),
2024 "%s: SCIC Port 0x%p requested to process event 0x%x while "
2025 "in invalid state %d\n",
2029 sci_base_state_machine_get_state(
2030 scic_sds_port_get_base_state_machine(
2031 (struct scic_sds_port
*)port
)));
2033 return SCI_FAILURE_INVALID_STATE
;
2038 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2041 * This is the default method for a port link up notification. It will report
2042 * a warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
2044 void scic_sds_port_default_link_up_handler(
2045 struct scic_sds_port
*this_port
,
2046 struct scic_sds_phy
*phy
)
2048 dev_warn(sciport_to_dev(this_port
),
2049 "%s: SCIC Port 0x%p received link_up notification from phy "
2050 "0x%p while in invalid state %d\n",
2054 sci_base_state_machine_get_state(
2055 scic_sds_port_get_base_state_machine(this_port
)));
2060 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2063 * This is the default method for a port link down notification. It will
2064 * report a warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
2066 void scic_sds_port_default_link_down_handler(
2067 struct scic_sds_port
*this_port
,
2068 struct scic_sds_phy
*phy
)
2070 dev_warn(sciport_to_dev(this_port
),
2071 "%s: SCIC Port 0x%p received link down notification from "
2072 "phy 0x%p while in invalid state %d\n",
2076 sci_base_state_machine_get_state(
2077 scic_sds_port_get_base_state_machine(this_port
)));
2082 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2085 * This is the default method for a port start io request. It will report a
2086 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
2088 enum sci_status
scic_sds_port_default_start_io_handler(
2089 struct scic_sds_port
*this_port
,
2090 struct scic_sds_remote_device
*device
,
2091 struct scic_sds_request
*io_request
)
2093 dev_warn(sciport_to_dev(this_port
),
2094 "%s: SCIC Port 0x%p requested to start io request 0x%p "
2095 "while in invalid state %d\n",
2099 sci_base_state_machine_get_state(
2100 scic_sds_port_get_base_state_machine(this_port
)));
2102 return SCI_FAILURE_INVALID_STATE
;
2107 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2110 * This is the default method for a port complete io request. It will report a
2111 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
2113 static enum sci_status
scic_sds_port_default_complete_io_handler(
2114 struct scic_sds_port
*this_port
,
2115 struct scic_sds_remote_device
*device
,
2116 struct scic_sds_request
*io_request
)
2118 dev_warn(sciport_to_dev(this_port
),
2119 "%s: SCIC Port 0x%p requested to complete io request 0x%p "
2120 "while in invalid state %d\n",
2124 sci_base_state_machine_get_state(
2125 scic_sds_port_get_base_state_machine(this_port
)));
2127 return SCI_FAILURE_INVALID_STATE
;
2131 * ****************************************************************************
2132 * * GENERAL STATE HANDLERS
2133 * **************************************************************************** */
2137 * @port: This is the struct scic_sds_port object on which the io request count will
2139 * @device: This is the struct scic_sds_remote_device object to which the io request
2140 * is being directed. This parameter is not required to complete this
2142 * @io_request: This is the request that is being completed on this port
2143 * object. This parameter is not required to complete this operation.
2145 * This is a general complete io request handler for the struct scic_sds_port object.
2146 * enum sci_status SCI_SUCCESS
2148 static enum sci_status
scic_sds_port_general_complete_io_handler(
2149 struct scic_sds_port
*port
,
2150 struct scic_sds_remote_device
*device
,
2151 struct scic_sds_request
*io_request
)
2153 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
2155 scic_sds_port_decrement_request_count(this_port
);
2161 * ****************************************************************************
2162 * * STOPPED STATE HANDLERS
2163 * **************************************************************************** */
2166 * scic_sds_port_stopped_state_start_handler() - stop a port from "started"
2168 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2171 * This method takes the struct scic_sds_port from a stopped state and attempts to
2172 * start it. To start a port it must have no assiged devices and it must have
2173 * at least one phy assigned to it. If those conditions are met then the port
2174 * can transition to the ready state. enum sci_status
2175 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION This struct scic_sds_port object could
2176 * not be started because the port configuration is not valid. SCI_SUCCESS the
2177 * start request is successful and the struct scic_sds_port object has transitioned to
2178 * the SCI_BASE_PORT_STATE_READY.
2180 static enum sci_status
scic_sds_port_stopped_state_start_handler(struct sci_base_port
*base_port
)
2182 struct scic_sds_port
*sci_port
= container_of(base_port
, typeof(*sci_port
), parent
);
2183 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
2184 enum sci_status status
= SCI_SUCCESS
;
2187 if (sci_port
->assigned_device_count
> 0) {
2189 * / @todo This is a start failure operation because there are still
2190 * / devices assigned to this port. There must be no devices
2191 * / assigned to a port on a start operation. */
2192 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
;
2195 sci_port
->timer_handle
= isci_event_timer_create(scic
,
2196 scic_sds_port_timeout_handler
,
2199 if (!sci_port
->timer_handle
)
2200 return SCI_FAILURE_INSUFFICIENT_RESOURCES
;
2202 if (sci_port
->reserved_rni
== SCU_DUMMY_INDEX
) {
2203 u16 rni
= scic_sds_remote_node_table_allocate_remote_node(&scic
->available_remote_nodes
, 1);
2205 if (rni
!= SCU_DUMMY_INDEX
)
2206 scic_sds_port_construct_dummy_rnc(sci_port
, rni
);
2208 status
= SCI_FAILURE_INSUFFICIENT_RESOURCES
;
2209 sci_port
->reserved_rni
= rni
;
2212 if (sci_port
->reserved_tci
== SCU_DUMMY_INDEX
) {
2213 /* Allocate a TCI and remove the sequence nibble */
2214 u16 tci
= scic_controller_allocate_io_tag(scic
);
2216 if (tci
!= SCU_DUMMY_INDEX
)
2217 scic_sds_port_construct_dummy_task(sci_port
, tci
);
2219 status
= SCI_FAILURE_INSUFFICIENT_RESOURCES
;
2220 sci_port
->reserved_tci
= tci
;
2223 if (status
== SCI_SUCCESS
) {
2224 phy_mask
= scic_sds_port_get_phys(sci_port
);
2227 * There are one or more phys assigned to this port. Make sure
2228 * the port's phy mask is in fact legal and supported by the
2231 if (scic_sds_port_is_phy_mask_valid(sci_port
, phy_mask
) == true) {
2232 sci_base_state_machine_change_state(
2233 scic_sds_port_get_base_state_machine(sci_port
),
2234 SCI_BASE_PORT_STATE_READY
);
2238 status
= SCI_FAILURE
;
2241 if (status
!= SCI_SUCCESS
)
2242 scic_sds_port_destroy_dummy_resources(sci_port
);
2249 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2252 * This method takes the struct scic_sds_port that is in a stopped state and handles a
2253 * stop request. This function takes no action. enum sci_status SCI_SUCCESS the
2254 * stop request is successful as the struct scic_sds_port object is already stopped.
2256 static enum sci_status
scic_sds_port_stopped_state_stop_handler(
2257 struct sci_base_port
*port
)
2259 /* We are already stopped so there is nothing to do here */
2265 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2268 * This method takes the struct scic_sds_port that is in a stopped state and handles
2269 * the destruct request. The stopped state is the only state in which the
2270 * struct scic_sds_port can be destroyed. This function causes the port object to
2271 * transition to the SCI_BASE_PORT_STATE_FINAL. enum sci_status SCI_SUCCESS
2273 static enum sci_status
scic_sds_port_stopped_state_destruct_handler(
2274 struct sci_base_port
*port
)
2276 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
2278 sci_base_state_machine_stop(&this_port
->parent
.state_machine
);
2285 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2287 * @phy: This is the struct sci_base_phy object which is cast into a struct scic_sds_phy
2290 * This method takes the struct scic_sds_port that is in a stopped state and handles
2291 * the add phy request. In MPC mode the only time a phy can be added to a port
2292 * is in the SCI_BASE_PORT_STATE_STOPPED. enum sci_status
2293 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION is returned when the phy can not
2294 * be added to the port. SCI_SUCCESS if the phy is added to the port.
2296 static enum sci_status
scic_sds_port_stopped_state_add_phy_handler(
2297 struct sci_base_port
*port
,
2298 struct sci_base_phy
*phy
)
2300 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
2301 struct scic_sds_phy
*this_phy
= (struct scic_sds_phy
*)phy
;
2302 struct sci_sas_address port_sas_address
;
2304 /* Read the port assigned SAS Address if there is one */
2305 scic_sds_port_get_sas_address(this_port
, &port_sas_address
);
2307 if (port_sas_address
.high
!= 0 && port_sas_address
.low
!= 0) {
2308 struct sci_sas_address phy_sas_address
;
2311 * Make sure that the PHY SAS Address matches the SAS Address
2313 scic_sds_phy_get_sas_address(this_phy
, &phy_sas_address
);
2316 (port_sas_address
.high
!= phy_sas_address
.high
)
2317 || (port_sas_address
.low
!= phy_sas_address
.low
)
2319 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
;
2323 return scic_sds_port_set_phy(this_port
, this_phy
);
2329 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2331 * @phy: This is the struct sci_base_phy object which is cast into a struct scic_sds_phy
2334 * This method takes the struct scic_sds_port that is in a stopped state and handles
2335 * the remove phy request. In MPC mode the only time a phy can be removed from
2336 * a port is in the SCI_BASE_PORT_STATE_STOPPED. enum sci_status
2337 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION is returned when the phy can not
2338 * be added to the port. SCI_SUCCESS if the phy is added to the port.
2340 static enum sci_status
scic_sds_port_stopped_state_remove_phy_handler(
2341 struct sci_base_port
*port
,
2342 struct sci_base_phy
*phy
)
2344 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
2345 struct scic_sds_phy
*this_phy
= (struct scic_sds_phy
*)phy
;
2347 return scic_sds_port_clear_phy(this_port
, this_phy
);
2351 * ****************************************************************************
2352 * * READY STATE HANDLERS
2353 * **************************************************************************** */
2356 * ****************************************************************************
2357 * * RESETTING STATE HANDLERS
2358 * **************************************************************************** */
2361 * ****************************************************************************
2362 * * STOPPING STATE HANDLERS
2363 * **************************************************************************** */
2367 * @port: This is the struct scic_sds_port object on which the io request count will
2369 * @device: This is the struct scic_sds_remote_device object to which the io request
2370 * is being directed. This parameter is not required to complete this
2372 * @io_request: This is the request that is being completed on this port
2373 * object. This parameter is not required to complete this operation.
2375 * This method takes the struct scic_sds_port that is in a stopping state and handles
2376 * the complete io request. Should the request count reach 0 then the port
2377 * object will transition to the stopped state. enum sci_status SCI_SUCCESS
2379 static enum sci_status
scic_sds_port_stopping_state_complete_io_handler(
2380 struct scic_sds_port
*port
,
2381 struct scic_sds_remote_device
*device
,
2382 struct scic_sds_request
*io_request
)
2384 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
2386 scic_sds_port_decrement_request_count(this_port
);
2388 if (this_port
->started_request_count
== 0) {
2389 sci_base_state_machine_change_state(
2390 scic_sds_port_get_base_state_machine(this_port
),
2391 SCI_BASE_PORT_STATE_STOPPED
2399 * ****************************************************************************
2400 * * RESETTING STATE HANDLERS
2401 * **************************************************************************** */
2405 * @port: This is the port object which is being requested to stop.
2407 * This method will stop a failed port. This causes a transition to the
2408 * stopping state. enum sci_status SCI_SUCCESS
2410 static enum sci_status
scic_sds_port_reset_state_stop_handler(
2411 struct sci_base_port
*port
)
2413 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
2415 sci_base_state_machine_change_state(
2416 &this_port
->parent
.state_machine
,
2417 SCI_BASE_PORT_STATE_STOPPING
2425 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2428 * This method will transition a failed port to its ready state. The port
2429 * failed because a hard reset request timed out but at some time later one or
2430 * more phys in the port became ready. enum sci_status SCI_SUCCESS
2432 static void scic_sds_port_reset_state_link_up_handler(
2433 struct scic_sds_port
*this_port
,
2434 struct scic_sds_phy
*phy
)
2437 * / @todo We should make sure that the phy that has gone link up is the same
2438 * / one on which we sent the reset. It is possible that the phy on
2439 * / which we sent the reset is not the one that has gone link up and we
2440 * / want to make sure that phy being reset comes back. Consider the
2441 * / case where a reset is sent but before the hardware processes the
2442 * / reset it get a link up on the port because of a hot plug event.
2443 * / because of the reset request this phy will go link down almost
2447 * In the resetting state we don't notify the user regarding
2448 * link up and link down notifications. */
2449 scic_sds_port_general_link_up_handler(this_port
, phy
, false);
2454 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2457 * This method process link down notifications that occur during a port reset
2458 * operation. Link downs can occur during the reset operation. enum sci_status
2461 static void scic_sds_port_reset_state_link_down_handler(
2462 struct scic_sds_port
*this_port
,
2463 struct scic_sds_phy
*phy
)
2466 * In the resetting state we don't notify the user regarding
2467 * link up and link down notifications. */
2468 scic_sds_port_deactivate_phy(this_port
, phy
, false);
2471 /* --------------------------------------------------------------------------- */
2473 struct scic_sds_port_state_handler
2474 scic_sds_port_state_handler_table
[SCI_BASE_PORT_MAX_STATES
] =
2476 /* SCI_BASE_PORT_STATE_STOPPED */
2479 scic_sds_port_stopped_state_start_handler
,
2480 scic_sds_port_stopped_state_stop_handler
,
2481 scic_sds_port_stopped_state_destruct_handler
,
2482 scic_sds_port_default_reset_handler
,
2483 scic_sds_port_stopped_state_add_phy_handler
,
2484 scic_sds_port_stopped_state_remove_phy_handler
2486 scic_sds_port_default_frame_handler
,
2487 scic_sds_port_default_event_handler
,
2488 scic_sds_port_default_link_up_handler
,
2489 scic_sds_port_default_link_down_handler
,
2490 scic_sds_port_default_start_io_handler
,
2491 scic_sds_port_default_complete_io_handler
2493 /* SCI_BASE_PORT_STATE_STOPPING */
2496 scic_sds_port_default_start_handler
,
2497 scic_sds_port_default_stop_handler
,
2498 scic_sds_port_default_destruct_handler
,
2499 scic_sds_port_default_reset_handler
,
2500 scic_sds_port_default_add_phy_handler
,
2501 scic_sds_port_default_remove_phy_handler
2503 scic_sds_port_default_frame_handler
,
2504 scic_sds_port_default_event_handler
,
2505 scic_sds_port_default_link_up_handler
,
2506 scic_sds_port_default_link_down_handler
,
2507 scic_sds_port_default_start_io_handler
,
2508 scic_sds_port_stopping_state_complete_io_handler
2510 /* SCI_BASE_PORT_STATE_READY */
2513 scic_sds_port_default_start_handler
,
2514 scic_sds_port_default_stop_handler
,
2515 scic_sds_port_default_destruct_handler
,
2516 scic_sds_port_default_reset_handler
,
2517 scic_sds_port_default_add_phy_handler
,
2518 scic_sds_port_default_remove_phy_handler
2520 scic_sds_port_default_frame_handler
,
2521 scic_sds_port_default_event_handler
,
2522 scic_sds_port_default_link_up_handler
,
2523 scic_sds_port_default_link_down_handler
,
2524 scic_sds_port_default_start_io_handler
,
2525 scic_sds_port_general_complete_io_handler
2527 /* SCI_BASE_PORT_STATE_RESETTING */
2530 scic_sds_port_default_start_handler
,
2531 scic_sds_port_reset_state_stop_handler
,
2532 scic_sds_port_default_destruct_handler
,
2533 scic_sds_port_default_reset_handler
,
2534 scic_sds_port_default_add_phy_handler
,
2535 scic_sds_port_default_remove_phy_handler
2537 scic_sds_port_default_frame_handler
,
2538 scic_sds_port_default_event_handler
,
2539 scic_sds_port_reset_state_link_up_handler
,
2540 scic_sds_port_reset_state_link_down_handler
,
2541 scic_sds_port_default_start_io_handler
,
2542 scic_sds_port_general_complete_io_handler
2544 /* SCI_BASE_PORT_STATE_FAILED */
2547 scic_sds_port_default_start_handler
,
2548 scic_sds_port_default_stop_handler
,
2549 scic_sds_port_default_destruct_handler
,
2550 scic_sds_port_default_reset_handler
,
2551 scic_sds_port_default_add_phy_handler
,
2552 scic_sds_port_default_remove_phy_handler
2554 scic_sds_port_default_frame_handler
,
2555 scic_sds_port_default_event_handler
,
2556 scic_sds_port_default_link_up_handler
,
2557 scic_sds_port_default_link_down_handler
,
2558 scic_sds_port_default_start_io_handler
,
2559 scic_sds_port_general_complete_io_handler
2564 * ******************************************************************************
2565 * * PORT STATE PRIVATE METHODS
2566 * ****************************************************************************** */
2570 * @this_port: This is the port object which to suspend.
2572 * This method will enable the SCU Port Task Scheduler for this port object but
2573 * will leave the port task scheduler in a suspended state. none
2575 static void scic_sds_port_enable_port_task_scheduler(
2576 struct scic_sds_port
*this_port
)
2578 u32 pts_control_value
;
2580 pts_control_value
= scu_port_task_scheduler_read(this_port
, control
);
2582 pts_control_value
|= SCU_PTSxCR_GEN_BIT(ENABLE
) | SCU_PTSxCR_GEN_BIT(SUSPEND
);
2584 scu_port_task_scheduler_write(this_port
, control
, pts_control_value
);
2589 * @this_port: This is the port object which to resume.
2591 * This method will disable the SCU port task scheduler for this port object.
2594 static void scic_sds_port_disable_port_task_scheduler(
2595 struct scic_sds_port
*this_port
)
2597 u32 pts_control_value
;
2599 pts_control_value
= scu_port_task_scheduler_read(this_port
, control
);
2601 pts_control_value
&= ~(SCU_PTSxCR_GEN_BIT(ENABLE
)
2602 | SCU_PTSxCR_GEN_BIT(SUSPEND
));
2604 scu_port_task_scheduler_write(this_port
, control
, pts_control_value
);
2607 void scic_sds_port_post_dummy_remote_node(struct scic_sds_port
*sci_port
)
2609 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
2610 u8 phys_index
= sci_port
->physical_port_index
;
2611 union scu_remote_node_context
*rnc
;
2612 u16 rni
= sci_port
->reserved_rni
;
2615 rnc
= &scic
->remote_node_context_table
[rni
];
2616 rnc
->ssp
.is_valid
= true;
2618 command
= SCU_CONTEXT_COMMAND_POST_RNC_32
|
2619 phys_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
| rni
;
2621 scic_sds_controller_post_request(scic
, command
);
2623 /* ensure hardware has seen the post rnc command and give it
2624 * ample time to act before sending the suspend
2626 SMU_ISR_READ(scic
); /* flush */
2629 command
= SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX
|
2630 phys_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
| rni
;
2632 scic_sds_controller_post_request(scic
, command
);
2635 void scic_sds_port_invalidate_dummy_remote_node(struct scic_sds_port
*sci_port
)
2637 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
2638 u8 phys_index
= sci_port
->physical_port_index
;
2639 union scu_remote_node_context
*rnc
;
2640 u16 rni
= sci_port
->reserved_rni
;
2643 rnc
= &scic
->remote_node_context_table
[rni
];
2645 rnc
->ssp
.is_valid
= false;
2647 /* ensure the preceding tc abort request has reached the
2648 * controller and give it ample time to act before posting the rnc
2651 SMU_ISR_READ(scic
); /* flush */
2654 command
= SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE
|
2655 phys_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
| rni
;
2657 scic_sds_controller_post_request(scic
, command
);
2661 * ******************************************************************************
2662 * * PORT STATE METHODS
2663 * ****************************************************************************** */
2667 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2669 * This method will perform the actions required by the struct scic_sds_port on
2670 * entering the SCI_BASE_PORT_STATE_STOPPED. This function sets the stopped
2671 * state handlers for the struct scic_sds_port object and disables the port task
2672 * scheduler in the hardware. none
2674 static void scic_sds_port_stopped_state_enter(
2675 struct sci_base_object
*object
)
2677 struct scic_sds_port
*this_port
;
2679 this_port
= (struct scic_sds_port
*)object
;
2681 scic_sds_port_set_base_state_handlers(
2682 this_port
, SCI_BASE_PORT_STATE_STOPPED
2686 SCI_BASE_PORT_STATE_STOPPING
2687 == this_port
->parent
.state_machine
.previous_state_id
2690 * If we enter this state becasuse of a request to stop
2691 * the port then we want to disable the hardwares port
2692 * task scheduler. */
2693 scic_sds_port_disable_port_task_scheduler(this_port
);
2699 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2701 * This method will perform the actions required by the struct scic_sds_port on
2702 * exiting the SCI_BASE_STATE_STOPPED. This function enables the SCU hardware
2703 * port task scheduler. none
2705 static void scic_sds_port_stopped_state_exit(
2706 struct sci_base_object
*object
)
2708 struct scic_sds_port
*this_port
;
2710 this_port
= (struct scic_sds_port
*)object
;
2712 /* Enable and suspend the port task scheduler */
2713 scic_sds_port_enable_port_task_scheduler(this_port
);
2718 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2720 * This method will perform the actions required by the struct scic_sds_port on
2721 * entering the SCI_BASE_PORT_STATE_READY. This function sets the ready state
2722 * handlers for the struct scic_sds_port object, reports the port object as not ready
2723 * and starts the ready substate machine. none
2725 static void scic_sds_port_ready_state_enter(
2726 struct sci_base_object
*object
)
2728 struct scic_sds_port
*this_port
;
2730 this_port
= (struct scic_sds_port
*)object
;
2732 /* Put the ready state handlers in place though they will not be there long */
2733 scic_sds_port_set_base_state_handlers(
2734 this_port
, SCI_BASE_PORT_STATE_READY
2738 SCI_BASE_PORT_STATE_RESETTING
2739 == this_port
->parent
.state_machine
.previous_state_id
2741 isci_event_port_hard_reset_complete(
2742 scic_sds_port_get_controller(this_port
),
2747 /* Notify the caller that the port is not yet ready */
2748 isci_event_port_not_ready(
2749 scic_sds_port_get_controller(this_port
),
2751 SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS
2755 /* Post and suspend the dummy remote node context for this port. */
2756 scic_sds_port_post_dummy_remote_node(this_port
);
2758 /* Start the ready substate machine */
2759 sci_base_state_machine_start(
2760 scic_sds_port_get_ready_substate_machine(this_port
)
2766 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2768 * This method will perform the actions required by the struct scic_sds_port on
2769 * exiting the SCI_BASE_STATE_READY. This function does nothing. none
2771 static void scic_sds_port_ready_state_exit(
2772 struct sci_base_object
*object
)
2774 struct scic_sds_port
*this_port
;
2776 this_port
= (struct scic_sds_port
*)object
;
2778 sci_base_state_machine_stop(&this_port
->ready_substate_machine
);
2780 scic_sds_port_invalidate_dummy_remote_node(this_port
);
2785 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2787 * This method will perform the actions required by the struct scic_sds_port on
2788 * entering the SCI_BASE_PORT_STATE_RESETTING. This function sets the resetting
2789 * state handlers for the struct scic_sds_port object. none
2791 static void scic_sds_port_resetting_state_enter(
2792 struct sci_base_object
*object
)
2794 struct scic_sds_port
*this_port
;
2796 this_port
= (struct scic_sds_port
*)object
;
2798 scic_sds_port_set_base_state_handlers(
2799 this_port
, SCI_BASE_PORT_STATE_RESETTING
2805 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2807 * This method will perform the actions required by the struct scic_sds_port on
2808 * exiting the SCI_BASE_STATE_RESETTING. This function does nothing. none
2810 static void scic_sds_port_resetting_state_exit(
2811 struct sci_base_object
*object
)
2813 struct scic_sds_port
*this_port
;
2815 this_port
= (struct scic_sds_port
*)object
;
2817 isci_event_timer_stop(
2818 scic_sds_port_get_controller(this_port
),
2819 this_port
->timer_handle
2825 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2827 * This method will perform the actions required by the struct scic_sds_port on
2828 * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
2829 * state handlers for the struct scic_sds_port object. none
2831 static void scic_sds_port_stopping_state_enter(
2832 struct sci_base_object
*object
)
2834 struct scic_sds_port
*this_port
;
2836 this_port
= (struct scic_sds_port
*)object
;
2838 scic_sds_port_set_base_state_handlers(
2839 this_port
, SCI_BASE_PORT_STATE_STOPPING
2845 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2847 * This method will perform the actions required by the struct scic_sds_port on
2848 * exiting the SCI_BASE_STATE_STOPPING. This function does nothing. none
2850 static void scic_sds_port_stopping_state_exit(
2851 struct sci_base_object
*object
)
2853 struct scic_sds_port
*this_port
;
2855 this_port
= (struct scic_sds_port
*)object
;
2857 isci_event_timer_stop(
2858 scic_sds_port_get_controller(this_port
),
2859 this_port
->timer_handle
2862 scic_sds_port_destroy_dummy_resources(this_port
);
2867 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2869 * This method will perform the actions required by the struct scic_sds_port on
2870 * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
2871 * state handlers for the struct scic_sds_port object. none
2873 static void scic_sds_port_failed_state_enter(
2874 struct sci_base_object
*object
)
2876 struct scic_sds_port
*this_port
;
2878 this_port
= (struct scic_sds_port
*)object
;
2880 scic_sds_port_set_base_state_handlers(
2882 SCI_BASE_PORT_STATE_FAILED
2885 isci_event_port_hard_reset_complete(
2886 scic_sds_port_get_controller(this_port
),
2892 /* --------------------------------------------------------------------------- */
2894 const struct sci_base_state scic_sds_port_state_table
[] = {
2895 [SCI_BASE_PORT_STATE_STOPPED
] = {
2896 .enter_state
= scic_sds_port_stopped_state_enter
,
2897 .exit_state
= scic_sds_port_stopped_state_exit
2899 [SCI_BASE_PORT_STATE_STOPPING
] = {
2900 .enter_state
= scic_sds_port_stopping_state_enter
,
2901 .exit_state
= scic_sds_port_stopping_state_exit
2903 [SCI_BASE_PORT_STATE_READY
] = {
2904 .enter_state
= scic_sds_port_ready_state_enter
,
2905 .exit_state
= scic_sds_port_ready_state_exit
2907 [SCI_BASE_PORT_STATE_RESETTING
] = {
2908 .enter_state
= scic_sds_port_resetting_state_enter
,
2909 .exit_state
= scic_sds_port_resetting_state_exit
2911 [SCI_BASE_PORT_STATE_FAILED
] = {
2912 .enter_state
= scic_sds_port_failed_state_enter
,