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
;
629 * If this is not the dummy port make the assignment of
630 * the timer and start the state machine */
631 if (this_port
->physical_port_index
!= SCI_MAX_PORTS
) {
632 /* / @todo should we create the timer at create time? */
633 this_port
->timer_handle
= isci_event_timer_create(
634 scic_sds_port_get_controller(this_port
),
635 scic_sds_port_timeout_handler
,
641 * Force the dummy port into a condition where it rejects all requests
642 * as its in an invalid state for any operation.
643 * / @todo should we set a set of specical handlers for the dummy port? */
644 scic_sds_port_set_base_state_handlers(
645 this_port
, SCI_BASE_PORT_STATE_STOPPED
654 * @this_port: This is the struct scic_sds_port object for which has a phy that has
656 * @the_phy: This is the struct scic_sds_phy object that has gone link up.
657 * @do_notify_user: This parameter specifies whether to inform the user (via
658 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
660 * This method is the a general link up handler for the struct scic_sds_port object.
661 * This function will determine if this struct scic_sds_phy can be assigned to this
662 * struct scic_sds_port object. If the struct scic_sds_phy object can is not a valid PHY for
663 * this port then the function will notify the SCIC_USER. A PHY can only be
664 * part of a port if it's attached SAS ADDRESS is the same as all other PHYs in
665 * the same port. none
667 void scic_sds_port_general_link_up_handler(
668 struct scic_sds_port
*this_port
,
669 struct scic_sds_phy
*the_phy
,
672 struct sci_sas_address port_sas_address
;
673 struct sci_sas_address phy_sas_address
;
675 scic_sds_port_get_attached_sas_address(this_port
, &port_sas_address
);
676 scic_sds_phy_get_attached_sas_address(the_phy
, &phy_sas_address
);
679 * If the SAS address of the new phy matches the SAS address of
680 * other phys in the port OR this is the first phy in the port,
681 * then activate the phy and allow it to be used for operations
685 (phy_sas_address
.high
== port_sas_address
.high
)
686 && (phy_sas_address
.low
== port_sas_address
.low
)
688 || (this_port
->active_phy_mask
== 0)
690 scic_sds_port_activate_phy(this_port
, the_phy
, do_notify_user
);
692 if (this_port
->parent
.state_machine
.current_state_id
693 == SCI_BASE_PORT_STATE_RESETTING
) {
694 sci_base_state_machine_change_state(
695 &this_port
->parent
.state_machine
, SCI_BASE_PORT_STATE_READY
699 scic_sds_port_invalid_link_up(this_port
, the_phy
);
703 enum sci_status
scic_port_stop(struct scic_sds_port
*port
)
705 return port
->state_handlers
->parent
.stop_handler(&port
->parent
);
708 enum sci_status
scic_port_get_properties(
709 struct scic_sds_port
*port
,
710 struct scic_port_properties
*prop
)
712 if ((port
== NULL
) ||
713 (port
->logical_port_index
== SCIC_SDS_DUMMY_PORT
))
714 return SCI_FAILURE_INVALID_PORT
;
716 prop
->index
= port
->logical_port_index
;
717 prop
->phy_mask
= scic_sds_port_get_phys(port
);
718 scic_sds_port_get_sas_address(port
, &prop
->local
.sas_address
);
719 scic_sds_port_get_protocols(port
, &prop
->local
.protocols
);
720 scic_sds_port_get_attached_sas_address(port
, &prop
->remote
.sas_address
);
721 scic_sds_port_get_attached_protocols(port
, &prop
->remote
.protocols
);
727 enum sci_status
scic_port_hard_reset(
728 struct scic_sds_port
*port
,
731 return port
->state_handlers
->parent
.reset_handler(
732 &port
->parent
, reset_timeout
);
736 * This method assigns the direct attached device ID for this port.
738 * @param[in] this_port The port for which the direct attached device id is to
740 * @param[in] device_id The direct attached device ID to assign to the port.
741 * This will be the RNi for the device
743 void scic_sds_port_setup_transports(
744 struct scic_sds_port
*this_port
,
749 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
750 if (this_port
->active_phy_mask
& (1 << index
))
751 scic_sds_phy_setup_transport(this_port
->phy_table
[index
], device_id
);
757 * @this_port: This is the port on which the phy should be enabled.
758 * @the_phy: This is the specific phy which to enable.
759 * @do_notify_user: This parameter specifies whether to inform the user (via
760 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
762 * This method will activate the phy in the port. Activation includes: - adding
763 * the phy to the port - enabling the Protocol Engine in the silicon. -
764 * notifying the user that the link is up. none
766 void scic_sds_port_activate_phy(
767 struct scic_sds_port
*this_port
,
768 struct scic_sds_phy
*the_phy
,
771 struct scic_sds_controller
*controller
;
772 struct sci_sas_identify_address_frame_protocols protocols
;
774 controller
= scic_sds_port_get_controller(this_port
);
775 scic_sds_phy_get_attached_phy_protocols(the_phy
, &protocols
);
777 /* If this is sata port then the phy has already been resumed */
778 if (!protocols
.u
.bits
.stp_target
) {
779 scic_sds_phy_resume(the_phy
);
782 this_port
->active_phy_mask
|= 1 << the_phy
->phy_index
;
784 scic_sds_controller_clear_invalid_phy(controller
, the_phy
);
786 if (do_notify_user
== true)
787 isci_event_port_link_up(this_port
->owning_controller
,
794 * @this_port: This is the port on which the phy should be deactivated.
795 * @the_phy: This is the specific phy that is no longer active in the port.
796 * @do_notify_user: This parameter specifies whether to inform the user (via
797 * isci_event_port_link_down()) as to the fact that a new phy as become
800 * This method will deactivate the supplied phy in the port. none
802 void scic_sds_port_deactivate_phy(
803 struct scic_sds_port
*this_port
,
804 struct scic_sds_phy
*the_phy
,
807 this_port
->active_phy_mask
&= ~(1 << the_phy
->phy_index
);
809 the_phy
->max_negotiated_speed
= SCI_SAS_NO_LINK_RATE
;
811 /* Re-assign the phy back to the LP as if it were a narrow port */
812 SCU_PCSPExCR_WRITE(this_port
, the_phy
->phy_index
, the_phy
->phy_index
);
814 if (do_notify_user
== true)
815 isci_event_port_link_down(this_port
->owning_controller
,
822 * @this_port: This is the port on which the phy should be disabled.
823 * @the_phy: This is the specific phy which to disabled.
825 * This method will disable the phy and report that the phy is not valid for
826 * this port object. None
828 static void scic_sds_port_invalid_link_up(
829 struct scic_sds_port
*this_port
,
830 struct scic_sds_phy
*the_phy
)
832 struct scic_sds_controller
*controller
= scic_sds_port_get_controller(this_port
);
835 * Check to see if we have alreay reported this link as bad and if not go
836 * ahead and tell the SCI_USER that we have discovered an invalid link. */
837 if ((controller
->invalid_phy_mask
& (1 << the_phy
->phy_index
)) == 0) {
838 scic_sds_controller_set_invalid_phy(controller
, the_phy
);
840 isci_event_port_invalid_link_up(controller
, this_port
, the_phy
);
845 * This method returns false if the port only has a single phy object assigned.
846 * If there are no phys or more than one phy then the method will return
848 * @this_port: The port for which the wide port condition is to be checked.
850 * bool true Is returned if this is a wide ported port. false Is returned if
851 * this is a narrow port.
853 static bool scic_sds_port_is_wide(struct scic_sds_port
*this_port
)
858 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
859 if (this_port
->phy_table
[index
] != NULL
) {
864 return phy_count
!= 1;
868 * This method is called by the PHY object when the link is detected. if the
869 * port wants the PHY to continue on to the link up state then the port
870 * layer must return true. If the port object returns false the phy object
871 * must halt its attempt to go link up.
872 * @this_port: The port associated with the phy object.
873 * @the_phy: The phy object that is trying to go link up.
875 * true if the phy object can continue to the link up condition. true Is
876 * returned if this phy can continue to the ready state. false Is returned if
877 * can not continue on to the ready state. This notification is in place for
878 * wide ports and direct attached phys. Since there are no wide ported SATA
879 * devices this could become an invalid port configuration.
881 bool scic_sds_port_link_detected(
882 struct scic_sds_port
*this_port
,
883 struct scic_sds_phy
*the_phy
)
885 struct sci_sas_identify_address_frame_protocols protocols
;
887 scic_sds_phy_get_attached_phy_protocols(the_phy
, &protocols
);
890 (this_port
->logical_port_index
!= SCIC_SDS_DUMMY_PORT
)
891 && (protocols
.u
.bits
.stp_target
)
892 && scic_sds_port_is_wide(this_port
)
894 scic_sds_port_invalid_link_up(this_port
, the_phy
);
903 * This method is the entry point for the phy to inform the port that it is now
909 void scic_sds_port_link_up(
910 struct scic_sds_port
*this_port
,
911 struct scic_sds_phy
*the_phy
)
913 the_phy
->is_in_link_training
= false;
915 this_port
->state_handlers
->link_up_handler(this_port
, the_phy
);
919 * This method is the entry point for the phy to inform the port that it is no
920 * longer in a ready state
925 void scic_sds_port_link_down(
926 struct scic_sds_port
*this_port
,
927 struct scic_sds_phy
*the_phy
)
929 this_port
->state_handlers
->link_down_handler(this_port
, the_phy
);
933 * This method is called to start an IO request on this port.
940 enum sci_status
scic_sds_port_start_io(
941 struct scic_sds_port
*this_port
,
942 struct scic_sds_remote_device
*the_device
,
943 struct scic_sds_request
*the_io_request
)
945 return this_port
->state_handlers
->start_io_handler(
946 this_port
, the_device
, the_io_request
);
950 * This method is called to complete an IO request to the port.
957 enum sci_status
scic_sds_port_complete_io(
958 struct scic_sds_port
*this_port
,
959 struct scic_sds_remote_device
*the_device
,
960 struct scic_sds_request
*the_io_request
)
962 return this_port
->state_handlers
->complete_io_handler(
963 this_port
, the_device
, the_io_request
);
967 * This method is provided to timeout requests for port operations. Mostly its
968 * for the port reset operation.
972 static void scic_sds_port_timeout_handler(void *port
)
974 struct scic_sds_port
*this_port
= port
;
977 current_state
= sci_base_state_machine_get_state(
978 &this_port
->parent
.state_machine
);
980 if (current_state
== SCI_BASE_PORT_STATE_RESETTING
) {
982 * if the port is still in the resetting state then the timeout fired
983 * before the reset completed. */
984 sci_base_state_machine_change_state(
985 &this_port
->parent
.state_machine
,
986 SCI_BASE_PORT_STATE_FAILED
988 } else if (current_state
== SCI_BASE_PORT_STATE_STOPPED
) {
990 * if the port is stopped then the start request failed
991 * In this case stay in the stopped state. */
992 dev_err(sciport_to_dev(this_port
),
993 "%s: SCIC Port 0x%p failed to stop before tiemout.\n",
996 } else if (current_state
== SCI_BASE_PORT_STATE_STOPPING
) {
997 /* if the port is still stopping then the stop has not completed */
998 isci_event_port_stop_complete(
999 scic_sds_port_get_controller(this_port
),
1005 * The port is in the ready state and we have a timer reporting a timeout
1006 * this should not happen. */
1007 dev_err(sciport_to_dev(this_port
),
1008 "%s: SCIC Port 0x%p is processing a timeout operation "
1016 /* --------------------------------------------------------------------------- */
1019 * This function updates the hardwares VIIT entry for this port.
1023 void scic_sds_port_update_viit_entry(struct scic_sds_port
*this_port
)
1025 struct sci_sas_address sas_address
;
1027 scic_sds_port_get_sas_address(this_port
, &sas_address
);
1029 scu_port_viit_register_write(
1030 this_port
, initiator_sas_address_hi
, sas_address
.high
);
1032 scu_port_viit_register_write(
1033 this_port
, initiator_sas_address_lo
, sas_address
.low
);
1035 /* This value get cleared just in case its not already cleared */
1036 scu_port_viit_register_write(
1037 this_port
, reserved
, 0);
1039 /* We are required to update the status register last */
1040 scu_port_viit_register_write(
1041 this_port
, status
, (
1042 SCU_VIIT_ENTRY_ID_VIIT
1043 | SCU_VIIT_IPPT_INITIATOR
1044 | ((1 << this_port
->physical_port_index
) << SCU_VIIT_ENTRY_LPVIE_SHIFT
)
1045 | SCU_VIIT_STATUS_ALL_VALID
1051 * This method returns the maximum allowed speed for data transfers on this
1052 * port. This maximum allowed speed evaluates to the maximum speed of the
1053 * slowest phy in the port.
1054 * @this_port: This parameter specifies the port for which to retrieve the
1055 * maximum allowed speed.
1057 * This method returns the maximum negotiated speed of the slowest phy in the
1060 enum sci_sas_link_rate
scic_sds_port_get_max_allowed_speed(
1061 struct scic_sds_port
*this_port
)
1064 enum sci_sas_link_rate max_allowed_speed
= SCI_SAS_600_GB
;
1065 struct scic_sds_phy
*phy
= NULL
;
1068 * Loop through all of the phys in this port and find the phy with the
1069 * lowest maximum link rate. */
1070 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
1071 phy
= this_port
->phy_table
[index
];
1074 && (scic_sds_port_active_phy(this_port
, phy
) == true)
1075 && (phy
->max_negotiated_speed
< max_allowed_speed
)
1077 max_allowed_speed
= phy
->max_negotiated_speed
;
1080 return max_allowed_speed
;
1085 * This method passes the event to core user.
1086 * @this_port: The port that a BCN happens.
1087 * @this_phy: The phy that receives BCN.
1090 void scic_sds_port_broadcast_change_received(
1091 struct scic_sds_port
*this_port
,
1092 struct scic_sds_phy
*this_phy
)
1094 /* notify the user. */
1095 isci_event_port_bc_change_primitive_received(
1096 this_port
->owning_controller
, this_port
, this_phy
1102 * This API methhod enables the broadcast change notification from underneath
1104 * @this_port: The port that a BCN had been disabled from.
1107 void scic_port_enable_broadcast_change_notification(
1108 struct scic_sds_port
*port
)
1110 struct scic_sds_phy
*phy
;
1114 /* Loop through all of the phys to enable BCN. */
1115 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
1116 phy
= port
->phy_table
[index
];
1118 register_value
= SCU_SAS_LLCTL_READ(phy
);
1120 /* clear the bit by writing 1. */
1121 SCU_SAS_LLCTL_WRITE(phy
, register_value
);
1127 * ****************************************************************************
1128 * * READY SUBSTATE HANDLERS
1129 * **************************************************************************** */
1133 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1136 * This method is the general ready state stop handler for the struct scic_sds_port
1137 * object. This function will transition the ready substate machine to its
1138 * final state. enum sci_status SCI_SUCCESS
1140 static enum sci_status
scic_sds_port_ready_substate_stop_handler(
1141 struct sci_base_port
*port
)
1143 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
1145 sci_base_state_machine_change_state(
1146 &this_port
->parent
.state_machine
,
1147 SCI_BASE_PORT_STATE_STOPPING
1155 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1157 * @device: This is the struct sci_base_remote_device object which is not used in this
1159 * @io_request: This is the struct sci_base_request object which is not used in this
1162 * This method is the general ready substate complete io handler for the
1163 * struct scic_sds_port object. This function decrments the outstanding request count
1164 * for this port object. enum sci_status SCI_SUCCESS
1166 static enum sci_status
scic_sds_port_ready_substate_complete_io_handler(
1167 struct scic_sds_port
*port
,
1168 struct scic_sds_remote_device
*device
,
1169 struct scic_sds_request
*io_request
)
1171 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
1173 scic_sds_port_decrement_request_count(this_port
);
1178 static enum sci_status
scic_sds_port_ready_substate_add_phy_handler(
1179 struct sci_base_port
*port
,
1180 struct sci_base_phy
*phy
)
1182 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
1183 struct scic_sds_phy
*this_phy
= (struct scic_sds_phy
*)phy
;
1184 enum sci_status status
;
1186 status
= scic_sds_port_set_phy(this_port
, this_phy
);
1188 if (status
== SCI_SUCCESS
) {
1189 scic_sds_port_general_link_up_handler(this_port
, this_phy
, true);
1191 this_port
->not_ready_reason
= SCIC_PORT_NOT_READY_RECONFIGURING
;
1193 sci_base_state_machine_change_state(
1194 &this_port
->ready_substate_machine
,
1195 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1203 static enum sci_status
scic_sds_port_ready_substate_remove_phy_handler(
1204 struct sci_base_port
*port
,
1205 struct sci_base_phy
*phy
)
1207 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
1208 struct scic_sds_phy
*this_phy
= (struct scic_sds_phy
*)phy
;
1209 enum sci_status status
;
1211 status
= scic_sds_port_clear_phy(this_port
, this_phy
);
1213 if (status
== SCI_SUCCESS
) {
1214 scic_sds_port_deactivate_phy(this_port
, this_phy
, true);
1216 this_port
->not_ready_reason
= SCIC_PORT_NOT_READY_RECONFIGURING
;
1218 sci_base_state_machine_change_state(
1219 &this_port
->ready_substate_machine
,
1220 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1228 * ****************************************************************************
1229 * * READY SUBSTATE WAITING HANDLERS
1230 * **************************************************************************** */
1234 * @this_port: This is the struct scic_sds_port object that which has a phy that has
1236 * @the_phy: This is the struct scic_sds_phy object that has gone link up.
1238 * This method is the ready waiting substate link up handler for the
1239 * struct scic_sds_port object. This methos will report the link up condition for
1240 * this port and will transition to the ready operational substate. none
1242 static void scic_sds_port_ready_waiting_substate_link_up_handler(
1243 struct scic_sds_port
*this_port
,
1244 struct scic_sds_phy
*the_phy
)
1247 * Since this is the first phy going link up for the port we can just enable
1248 * it and continue. */
1249 scic_sds_port_activate_phy(this_port
, the_phy
, true);
1251 sci_base_state_machine_change_state(
1252 &this_port
->ready_substate_machine
,
1253 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1259 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1261 * @device: This is the struct sci_base_remote_device object which is not used in this
1263 * @io_request: This is the struct sci_base_request object which is not used in this
1266 * This method is the ready waiting substate start io handler for the
1267 * struct scic_sds_port object. The port object can not accept new requests so the
1268 * request is failed. enum sci_status SCI_FAILURE_INVALID_STATE
1270 static enum sci_status
scic_sds_port_ready_waiting_substate_start_io_handler(
1271 struct scic_sds_port
*port
,
1272 struct scic_sds_remote_device
*device
,
1273 struct scic_sds_request
*io_request
)
1275 return SCI_FAILURE_INVALID_STATE
;
1279 * ****************************************************************************
1280 * * READY SUBSTATE OPERATIONAL HANDLERS
1281 * **************************************************************************** */
1285 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1287 * @timeout: This is the timeout for the reset request to complete.
1289 * This method will casue the port to reset. enum sci_status SCI_SUCCESS
1291 static enum sci_status
scic_sds_port_ready_operational_substate_reset_handler(
1292 struct sci_base_port
*port
,
1295 enum sci_status status
= SCI_FAILURE_INVALID_PHY
;
1297 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
1298 struct scic_sds_phy
*selected_phy
= NULL
;
1301 /* Select a phy on which we can send the hard reset request. */
1304 (phy_index
< SCI_MAX_PHYS
)
1305 && (selected_phy
== NULL
);
1308 selected_phy
= this_port
->phy_table
[phy_index
];
1311 (selected_phy
!= NULL
)
1312 && !scic_sds_port_active_phy(this_port
, selected_phy
)
1314 /* We found a phy but it is not ready select different phy */
1315 selected_phy
= NULL
;
1319 /* If we have a phy then go ahead and start the reset procedure */
1320 if (selected_phy
!= NULL
) {
1321 status
= scic_sds_phy_reset(selected_phy
);
1323 if (status
== SCI_SUCCESS
) {
1324 isci_event_timer_start(
1325 scic_sds_port_get_controller(this_port
),
1326 this_port
->timer_handle
,
1330 this_port
->not_ready_reason
= SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED
;
1332 sci_base_state_machine_change_state(
1333 &this_port
->parent
.state_machine
,
1334 SCI_BASE_PORT_STATE_RESETTING
1343 * scic_sds_port_ready_operational_substate_link_up_handler() -
1344 * @this_port: This is the struct scic_sds_port object that which has a phy that has
1346 * @the_phy: This is the struct scic_sds_phy object that has gone link up.
1348 * This method is the ready operational substate link up handler for the
1349 * struct scic_sds_port object. This function notifies the SCI User that the phy has
1350 * gone link up. none
1352 static void scic_sds_port_ready_operational_substate_link_up_handler(
1353 struct scic_sds_port
*this_port
,
1354 struct scic_sds_phy
*the_phy
)
1356 scic_sds_port_general_link_up_handler(this_port
, the_phy
, true);
1360 * scic_sds_port_ready_operational_substate_link_down_handler() -
1361 * @this_port: This is the struct scic_sds_port object that which has a phy that has
1363 * @the_phy: This is the struct scic_sds_phy object that has gone link down.
1365 * This method is the ready operational substate link down handler for the
1366 * struct scic_sds_port object. This function notifies the SCI User that the phy has
1367 * gone link down and if this is the last phy in the port the port will change
1368 * state to the ready waiting substate. none
1370 static void scic_sds_port_ready_operational_substate_link_down_handler(
1371 struct scic_sds_port
*this_port
,
1372 struct scic_sds_phy
*the_phy
)
1374 scic_sds_port_deactivate_phy(this_port
, the_phy
, true);
1377 * If there are no active phys left in the port, then transition
1378 * the port to the WAITING state until such time as a phy goes
1380 if (this_port
->active_phy_mask
== 0) {
1381 sci_base_state_machine_change_state(
1382 scic_sds_port_get_ready_substate_machine(this_port
),
1383 SCIC_SDS_PORT_READY_SUBSTATE_WAITING
1390 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1392 * @device: This is the struct sci_base_remote_device object which is not used in this
1394 * @io_request: This is the struct sci_base_request object which is not used in this
1397 * This method is the ready operational substate start io handler for the
1398 * struct scic_sds_port object. This function incremetns the outstanding request
1399 * count for this port object. enum sci_status SCI_SUCCESS
1401 static enum sci_status
scic_sds_port_ready_operational_substate_start_io_handler(
1402 struct scic_sds_port
*port
,
1403 struct scic_sds_remote_device
*device
,
1404 struct scic_sds_request
*io_request
)
1406 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
1408 scic_sds_port_increment_request_count(this_port
);
1414 * ****************************************************************************
1415 * * READY SUBSTATE OPERATIONAL HANDLERS
1416 * **************************************************************************** */
1419 * scic_sds_port_ready_configuring_substate_add_phy_handler() -
1420 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1423 * This is the default method for a port add phy request. It will report a
1424 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1426 static enum sci_status
scic_sds_port_ready_configuring_substate_add_phy_handler(
1427 struct sci_base_port
*port
,
1428 struct sci_base_phy
*phy
)
1430 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
1431 struct scic_sds_phy
*this_phy
= (struct scic_sds_phy
*)phy
;
1432 enum sci_status status
;
1434 status
= scic_sds_port_set_phy(this_port
, this_phy
);
1436 if (status
== SCI_SUCCESS
) {
1437 scic_sds_port_general_link_up_handler(this_port
, this_phy
, true);
1440 * Re-enter the configuring state since this may be the last phy in
1442 sci_base_state_machine_change_state(
1443 &this_port
->ready_substate_machine
,
1444 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1452 * scic_sds_port_ready_configuring_substate_remove_phy_handler() -
1453 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1456 * This is the default method for a port remove phy request. It will report a
1457 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1459 static enum sci_status
scic_sds_port_ready_configuring_substate_remove_phy_handler(
1460 struct sci_base_port
*port
,
1461 struct sci_base_phy
*phy
)
1463 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
1464 struct scic_sds_phy
*this_phy
= (struct scic_sds_phy
*)phy
;
1465 enum sci_status status
;
1467 status
= scic_sds_port_clear_phy(this_port
, this_phy
);
1469 if (status
== SCI_SUCCESS
) {
1470 scic_sds_port_deactivate_phy(this_port
, this_phy
, true);
1473 * Re-enter the configuring state since this may be the last phy in
1475 sci_base_state_machine_change_state(
1476 &this_port
->ready_substate_machine
,
1477 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1485 * scic_sds_port_ready_configuring_substate_complete_io_handler() -
1486 * @port: This is the port that is being requested to complete the io request.
1487 * @device: This is the device on which the io is completing.
1489 * This method will decrement the outstanding request count for this port. If
1490 * the request count goes to 0 then the port can be reprogrammed with its new
1493 static enum sci_status
scic_sds_port_ready_configuring_substate_complete_io_handler(
1494 struct scic_sds_port
*port
,
1495 struct scic_sds_remote_device
*device
,
1496 struct scic_sds_request
*io_request
)
1498 scic_sds_port_decrement_request_count(port
);
1500 if (port
->started_request_count
== 0) {
1501 sci_base_state_machine_change_state(
1502 &port
->ready_substate_machine
,
1503 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1510 /* --------------------------------------------------------------------------- */
1512 struct scic_sds_port_state_handler
1513 scic_sds_port_ready_substate_handler_table
[SCIC_SDS_PORT_READY_MAX_SUBSTATES
] =
1515 /* SCIC_SDS_PORT_READY_SUBSTATE_WAITING */
1518 scic_sds_port_default_start_handler
,
1519 scic_sds_port_ready_substate_stop_handler
,
1520 scic_sds_port_default_destruct_handler
,
1521 scic_sds_port_default_reset_handler
,
1522 scic_sds_port_ready_substate_add_phy_handler
,
1523 scic_sds_port_default_remove_phy_handler
1525 scic_sds_port_default_frame_handler
,
1526 scic_sds_port_default_event_handler
,
1527 scic_sds_port_ready_waiting_substate_link_up_handler
,
1528 scic_sds_port_default_link_down_handler
,
1529 scic_sds_port_ready_waiting_substate_start_io_handler
,
1530 scic_sds_port_ready_substate_complete_io_handler
,
1532 /* SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL */
1535 scic_sds_port_default_start_handler
,
1536 scic_sds_port_ready_substate_stop_handler
,
1537 scic_sds_port_default_destruct_handler
,
1538 scic_sds_port_ready_operational_substate_reset_handler
,
1539 scic_sds_port_ready_substate_add_phy_handler
,
1540 scic_sds_port_ready_substate_remove_phy_handler
1542 scic_sds_port_default_frame_handler
,
1543 scic_sds_port_default_event_handler
,
1544 scic_sds_port_ready_operational_substate_link_up_handler
,
1545 scic_sds_port_ready_operational_substate_link_down_handler
,
1546 scic_sds_port_ready_operational_substate_start_io_handler
,
1547 scic_sds_port_ready_substate_complete_io_handler
1549 /* SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING */
1552 scic_sds_port_default_start_handler
,
1553 scic_sds_port_ready_substate_stop_handler
,
1554 scic_sds_port_default_destruct_handler
,
1555 scic_sds_port_default_reset_handler
,
1556 scic_sds_port_ready_configuring_substate_add_phy_handler
,
1557 scic_sds_port_ready_configuring_substate_remove_phy_handler
1559 scic_sds_port_default_frame_handler
,
1560 scic_sds_port_default_event_handler
,
1561 scic_sds_port_default_link_up_handler
,
1562 scic_sds_port_default_link_down_handler
,
1563 scic_sds_port_default_start_io_handler
,
1564 scic_sds_port_ready_configuring_substate_complete_io_handler
1570 * scic_sds_port_set_ready_state_handlers() -
1572 * This macro sets the port ready substate handlers.
1574 #define scic_sds_port_set_ready_state_handlers(port, state_id) \
1575 scic_sds_port_set_state_handlers(\
1576 port, &scic_sds_port_ready_substate_handler_table[(state_id)] \
1580 * ******************************************************************************
1581 * * PORT STATE PRIVATE METHODS
1582 * ****************************************************************************** */
1586 * @this_port: This is the struct scic_sds_port object to suspend.
1588 * This method will susped the port task scheduler for this port object. none
1590 static void scic_sds_port_suspend_port_task_scheduler(
1591 struct scic_sds_port
*this_port
)
1593 u32 pts_control_value
;
1595 pts_control_value
= scu_port_task_scheduler_read(this_port
, control
);
1597 pts_control_value
|= SCU_PTSxCR_GEN_BIT(SUSPEND
);
1599 scu_port_task_scheduler_write(this_port
, control
, pts_control_value
);
1603 * scic_sds_port_post_dummy_request() - post dummy/workaround request
1604 * @sci_port: port to post task
1606 * Prevent the hardware scheduler from posting new requests to the front
1607 * of the scheduler queue causing a starvation problem for currently
1611 void scic_sds_port_post_dummy_request(struct scic_sds_port
*sci_port
)
1614 struct scu_task_context
*task_context
;
1615 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1616 u16 tci
= sci_port
->reserved_tci
;
1618 task_context
= scic_sds_controller_get_task_context_buffer(scic
, tci
);
1620 task_context
->abort
= 0;
1622 command
= SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC
|
1623 sci_port
->physical_port_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
|
1626 scic_sds_controller_post_request(scic
, command
);
1630 * This routine will abort the dummy request. This will alow the hardware to
1631 * power down parts of the silicon to save power.
1633 * @sci_port: The port on which the task must be aborted.
1636 void scic_sds_port_abort_dummy_request(struct scic_sds_port
*sci_port
)
1638 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1639 u16 tci
= sci_port
->reserved_tci
;
1640 struct scu_task_context
*tc
;
1643 tc
= scic_sds_controller_get_task_context_buffer(scic
, tci
);
1647 command
= SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT
|
1648 sci_port
->physical_port_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
|
1651 scic_sds_controller_post_request(scic
, command
);
1656 * @this_port: This is the struct scic_sds_port object to resume.
1658 * This method will resume the port task scheduler for this port object. none
1660 static void scic_sds_port_resume_port_task_scheduler(
1661 struct scic_sds_port
*this_port
)
1663 u32 pts_control_value
;
1665 pts_control_value
= scu_port_task_scheduler_read(this_port
, control
);
1667 pts_control_value
&= ~SCU_PTSxCR_GEN_BIT(SUSPEND
);
1669 scu_port_task_scheduler_write(this_port
, control
, pts_control_value
);
1673 * ******************************************************************************
1674 * * PORT READY SUBSTATE METHODS
1675 * ****************************************************************************** */
1679 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
1681 * This method will perform the actions required by the struct scic_sds_port on
1682 * entering the SCIC_SDS_PORT_READY_SUBSTATE_WAITING. This function checks the
1683 * port for any ready phys. If there is at least one phy in a ready state then
1684 * the port transitions to the ready operational substate. none
1686 static void scic_sds_port_ready_substate_waiting_enter(
1687 struct sci_base_object
*object
)
1689 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)object
;
1691 scic_sds_port_set_ready_state_handlers(
1692 this_port
, SCIC_SDS_PORT_READY_SUBSTATE_WAITING
1695 scic_sds_port_suspend_port_task_scheduler(this_port
);
1697 /* Kill the dummy task for this port if it has not yet posted
1698 * the hardware will treat this as a NOP and just return abort
1701 scic_sds_port_abort_dummy_request(this_port
);
1703 this_port
->not_ready_reason
= SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS
;
1705 if (this_port
->active_phy_mask
!= 0) {
1706 /* At least one of the phys on the port is ready */
1707 sci_base_state_machine_change_state(
1708 &this_port
->ready_substate_machine
,
1709 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1716 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
1718 * This method will perform the actions required by the struct scic_sds_port on
1719 * entering the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function sets
1720 * the state handlers for the port object, notifies the SCI User that the port
1721 * is ready, and resumes port operations. none
1723 static void scic_sds_port_ready_substate_operational_enter(
1724 struct sci_base_object
*object
)
1727 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)object
;
1729 scic_sds_port_set_ready_state_handlers(
1730 this_port
, SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1733 isci_event_port_ready(
1734 scic_sds_port_get_controller(this_port
), this_port
1737 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
1738 if (this_port
->phy_table
[index
] != NULL
) {
1739 scic_sds_port_write_phy_assignment(
1740 this_port
, this_port
->phy_table
[index
]
1745 scic_sds_port_update_viit_entry(this_port
);
1747 scic_sds_port_resume_port_task_scheduler(this_port
);
1749 /* Post the dummy task for the port so the hardware can schedule
1752 scic_sds_port_post_dummy_request(this_port
);
1757 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
1759 * This method will perform the actions required by the struct scic_sds_port on
1760 * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
1761 * the port not ready and suspends the port task scheduler. none
1763 static void scic_sds_port_ready_substate_operational_exit(
1764 struct sci_base_object
*object
)
1766 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)object
;
1768 isci_event_port_not_ready(
1769 scic_sds_port_get_controller(this_port
),
1771 this_port
->not_ready_reason
1776 * ******************************************************************************
1777 * * PORT READY CONFIGURING METHODS
1778 * ****************************************************************************** */
1781 * scic_sds_port_ready_substate_configuring_enter() -
1782 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
1784 * This method will perform the actions required by the struct scic_sds_port on
1785 * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
1786 * the port not ready and suspends the port task scheduler. none
1788 static void scic_sds_port_ready_substate_configuring_enter(
1789 struct sci_base_object
*object
)
1791 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)object
;
1793 scic_sds_port_set_ready_state_handlers(
1794 this_port
, SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1797 if (this_port
->active_phy_mask
== 0) {
1798 isci_event_port_not_ready(
1799 scic_sds_port_get_controller(this_port
),
1801 SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS
1804 sci_base_state_machine_change_state(
1805 &this_port
->ready_substate_machine
,
1806 SCIC_SDS_PORT_READY_SUBSTATE_WAITING
1808 } else if (this_port
->started_request_count
== 0) {
1809 sci_base_state_machine_change_state(
1810 &this_port
->ready_substate_machine
,
1811 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1816 static void scic_sds_port_ready_substate_configuring_exit(
1817 struct sci_base_object
*object
)
1819 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)object
;
1821 scic_sds_port_suspend_port_task_scheduler(this_port
);
1824 /* --------------------------------------------------------------------------- */
1826 const struct sci_base_state scic_sds_port_ready_substate_table
[] = {
1827 [SCIC_SDS_PORT_READY_SUBSTATE_WAITING
] = {
1828 .enter_state
= scic_sds_port_ready_substate_waiting_enter
,
1830 [SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
] = {
1831 .enter_state
= scic_sds_port_ready_substate_operational_enter
,
1832 .exit_state
= scic_sds_port_ready_substate_operational_exit
1834 [SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
] = {
1835 .enter_state
= scic_sds_port_ready_substate_configuring_enter
,
1836 .exit_state
= scic_sds_port_ready_substate_configuring_exit
1841 * ***************************************************************************
1842 * * DEFAULT HANDLERS
1843 * *************************************************************************** */
1847 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1850 * This is the default method for port a start request. It will report a
1851 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1853 enum sci_status
scic_sds_port_default_start_handler(
1854 struct sci_base_port
*port
)
1856 struct scic_sds_port
*sci_port
= (struct scic_sds_port
*)port
;
1858 dev_warn(sciport_to_dev(sci_port
),
1859 "%s: SCIC Port 0x%p requested to start while in invalid "
1863 sci_base_state_machine_get_state(
1864 scic_sds_port_get_base_state_machine(
1865 (struct scic_sds_port
*)port
)));
1867 return SCI_FAILURE_INVALID_STATE
;
1872 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1875 * This is the default method for a port stop request. It will report a
1876 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1878 static enum sci_status
scic_sds_port_default_stop_handler(
1879 struct sci_base_port
*port
)
1881 struct scic_sds_port
*sci_port
= (struct scic_sds_port
*)port
;
1883 dev_warn(sciport_to_dev(sci_port
),
1884 "%s: SCIC Port 0x%p requested to stop while in invalid "
1888 sci_base_state_machine_get_state(
1889 scic_sds_port_get_base_state_machine(
1890 (struct scic_sds_port
*)port
)));
1892 return SCI_FAILURE_INVALID_STATE
;
1897 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1900 * This is the default method for a port destruct request. It will report a
1901 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1903 enum sci_status
scic_sds_port_default_destruct_handler(
1904 struct sci_base_port
*port
)
1906 struct scic_sds_port
*sci_port
= (struct scic_sds_port
*)port
;
1908 dev_warn(sciport_to_dev(sci_port
),
1909 "%s: SCIC Port 0x%p requested to destruct while in invalid "
1913 sci_base_state_machine_get_state(
1914 scic_sds_port_get_base_state_machine(
1915 (struct scic_sds_port
*)port
)));
1917 return SCI_FAILURE_INVALID_STATE
;
1922 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1924 * @timeout: This is the timeout for the reset request to complete.
1926 * This is the default method for a port reset request. It will report a
1927 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1929 enum sci_status
scic_sds_port_default_reset_handler(
1930 struct sci_base_port
*port
,
1933 struct scic_sds_port
*sci_port
= (struct scic_sds_port
*)port
;
1935 dev_warn(sciport_to_dev(sci_port
),
1936 "%s: SCIC Port 0x%p requested to reset while in invalid "
1940 sci_base_state_machine_get_state(
1941 scic_sds_port_get_base_state_machine(
1942 (struct scic_sds_port
*)port
)));
1944 return SCI_FAILURE_INVALID_STATE
;
1949 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1952 * This is the default method for a port add phy request. It will report a
1953 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1955 static enum sci_status
scic_sds_port_default_add_phy_handler(
1956 struct sci_base_port
*port
,
1957 struct sci_base_phy
*phy
)
1959 struct scic_sds_port
*sci_port
= (struct scic_sds_port
*)port
;
1961 dev_warn(sciport_to_dev(sci_port
),
1962 "%s: SCIC Port 0x%p requested to add phy 0x%p while in "
1963 "invalid state %d\n",
1967 sci_base_state_machine_get_state(
1968 scic_sds_port_get_base_state_machine(
1969 (struct scic_sds_port
*)port
)));
1971 return SCI_FAILURE_INVALID_STATE
;
1976 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1979 * This is the default method for a port remove phy request. It will report a
1980 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1982 enum sci_status
scic_sds_port_default_remove_phy_handler(
1983 struct sci_base_port
*port
,
1984 struct sci_base_phy
*phy
)
1986 struct scic_sds_port
*sci_port
= (struct scic_sds_port
*)port
;
1988 dev_warn(sciport_to_dev(sci_port
),
1989 "%s: SCIC Port 0x%p requested to remove phy 0x%p while in "
1990 "invalid state %d\n",
1994 sci_base_state_machine_get_state(
1995 scic_sds_port_get_base_state_machine(
1996 (struct scic_sds_port
*)port
)));
1998 return SCI_FAILURE_INVALID_STATE
;
2003 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2006 * This is the default method for a port unsolicited frame request. It will
2007 * report a warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE Is it even
2008 * possible to receive an unsolicited frame directed to a port object? It
2009 * seems possible if we implementing virtual functions but until then?
2011 enum sci_status
scic_sds_port_default_frame_handler(
2012 struct scic_sds_port
*port
,
2015 dev_warn(sciport_to_dev(port
),
2016 "%s: SCIC Port 0x%p requested to process frame %d while in "
2017 "invalid state %d\n",
2021 sci_base_state_machine_get_state(
2022 scic_sds_port_get_base_state_machine(port
)));
2024 scic_sds_controller_release_frame(
2025 scic_sds_port_get_controller(port
), frame_index
2028 return SCI_FAILURE_INVALID_STATE
;
2033 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2036 * This is the default method for a port event request. It will report a
2037 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
2039 enum sci_status
scic_sds_port_default_event_handler(
2040 struct scic_sds_port
*port
,
2043 dev_warn(sciport_to_dev(port
),
2044 "%s: SCIC Port 0x%p requested to process event 0x%x while "
2045 "in invalid state %d\n",
2049 sci_base_state_machine_get_state(
2050 scic_sds_port_get_base_state_machine(
2051 (struct scic_sds_port
*)port
)));
2053 return SCI_FAILURE_INVALID_STATE
;
2058 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2061 * This is the default method for a port link up notification. It will report
2062 * a warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
2064 void scic_sds_port_default_link_up_handler(
2065 struct scic_sds_port
*this_port
,
2066 struct scic_sds_phy
*phy
)
2068 dev_warn(sciport_to_dev(this_port
),
2069 "%s: SCIC Port 0x%p received link_up notification from phy "
2070 "0x%p while in invalid state %d\n",
2074 sci_base_state_machine_get_state(
2075 scic_sds_port_get_base_state_machine(this_port
)));
2080 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2083 * This is the default method for a port link down notification. It will
2084 * report a warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
2086 void scic_sds_port_default_link_down_handler(
2087 struct scic_sds_port
*this_port
,
2088 struct scic_sds_phy
*phy
)
2090 dev_warn(sciport_to_dev(this_port
),
2091 "%s: SCIC Port 0x%p received link down notification from "
2092 "phy 0x%p while in invalid state %d\n",
2096 sci_base_state_machine_get_state(
2097 scic_sds_port_get_base_state_machine(this_port
)));
2102 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2105 * This is the default method for a port start io request. It will report a
2106 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
2108 enum sci_status
scic_sds_port_default_start_io_handler(
2109 struct scic_sds_port
*this_port
,
2110 struct scic_sds_remote_device
*device
,
2111 struct scic_sds_request
*io_request
)
2113 dev_warn(sciport_to_dev(this_port
),
2114 "%s: SCIC Port 0x%p requested to start io request 0x%p "
2115 "while in invalid state %d\n",
2119 sci_base_state_machine_get_state(
2120 scic_sds_port_get_base_state_machine(this_port
)));
2122 return SCI_FAILURE_INVALID_STATE
;
2127 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2130 * This is the default method for a port complete io request. It will report a
2131 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
2133 static enum sci_status
scic_sds_port_default_complete_io_handler(
2134 struct scic_sds_port
*this_port
,
2135 struct scic_sds_remote_device
*device
,
2136 struct scic_sds_request
*io_request
)
2138 dev_warn(sciport_to_dev(this_port
),
2139 "%s: SCIC Port 0x%p requested to complete io request 0x%p "
2140 "while in invalid state %d\n",
2144 sci_base_state_machine_get_state(
2145 scic_sds_port_get_base_state_machine(this_port
)));
2147 return SCI_FAILURE_INVALID_STATE
;
2151 * ****************************************************************************
2152 * * GENERAL STATE HANDLERS
2153 * **************************************************************************** */
2157 * @port: This is the struct scic_sds_port object on which the io request count will
2159 * @device: This is the struct scic_sds_remote_device object to which the io request
2160 * is being directed. This parameter is not required to complete this
2162 * @io_request: This is the request that is being completed on this port
2163 * object. This parameter is not required to complete this operation.
2165 * This is a general complete io request handler for the struct scic_sds_port object.
2166 * enum sci_status SCI_SUCCESS
2168 static enum sci_status
scic_sds_port_general_complete_io_handler(
2169 struct scic_sds_port
*port
,
2170 struct scic_sds_remote_device
*device
,
2171 struct scic_sds_request
*io_request
)
2173 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
2175 scic_sds_port_decrement_request_count(this_port
);
2181 * ****************************************************************************
2182 * * STOPPED STATE HANDLERS
2183 * **************************************************************************** */
2186 * scic_sds_port_stopped_state_start_handler() - stop a port from "started"
2188 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2191 * This method takes the struct scic_sds_port from a stopped state and attempts to
2192 * start it. To start a port it must have no assiged devices and it must have
2193 * at least one phy assigned to it. If those conditions are met then the port
2194 * can transition to the ready state. enum sci_status
2195 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION This struct scic_sds_port object could
2196 * not be started because the port configuration is not valid. SCI_SUCCESS the
2197 * start request is successful and the struct scic_sds_port object has transitioned to
2198 * the SCI_BASE_PORT_STATE_READY.
2200 static enum sci_status
scic_sds_port_stopped_state_start_handler(struct sci_base_port
*base_port
)
2202 struct scic_sds_port
*sci_port
= container_of(base_port
, typeof(*sci_port
), parent
);
2203 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
2204 enum sci_status status
= SCI_SUCCESS
;
2207 if (sci_port
->assigned_device_count
> 0) {
2209 * / @todo This is a start failure operation because there are still
2210 * / devices assigned to this port. There must be no devices
2211 * / assigned to a port on a start operation. */
2212 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
;
2215 sci_port
->timer_handle
= isci_event_timer_create(scic
,
2216 scic_sds_port_timeout_handler
,
2219 if (!sci_port
->timer_handle
)
2220 return SCI_FAILURE_INSUFFICIENT_RESOURCES
;
2222 if (sci_port
->reserved_rni
== SCU_DUMMY_INDEX
) {
2223 u16 rni
= scic_sds_remote_node_table_allocate_remote_node(&scic
->available_remote_nodes
, 1);
2225 if (rni
!= SCU_DUMMY_INDEX
)
2226 scic_sds_port_construct_dummy_rnc(sci_port
, rni
);
2228 status
= SCI_FAILURE_INSUFFICIENT_RESOURCES
;
2229 sci_port
->reserved_rni
= rni
;
2232 if (sci_port
->reserved_tci
== SCU_DUMMY_INDEX
) {
2233 /* Allocate a TCI and remove the sequence nibble */
2234 u16 tci
= scic_controller_allocate_io_tag(scic
);
2236 if (tci
!= SCU_DUMMY_INDEX
)
2237 scic_sds_port_construct_dummy_task(sci_port
, tci
);
2239 status
= SCI_FAILURE_INSUFFICIENT_RESOURCES
;
2240 sci_port
->reserved_tci
= tci
;
2243 if (status
== SCI_SUCCESS
) {
2244 phy_mask
= scic_sds_port_get_phys(sci_port
);
2247 * There are one or more phys assigned to this port. Make sure
2248 * the port's phy mask is in fact legal and supported by the
2251 if (scic_sds_port_is_phy_mask_valid(sci_port
, phy_mask
) == true) {
2252 sci_base_state_machine_change_state(
2253 scic_sds_port_get_base_state_machine(sci_port
),
2254 SCI_BASE_PORT_STATE_READY
);
2258 status
= SCI_FAILURE
;
2261 if (status
!= SCI_SUCCESS
)
2262 scic_sds_port_destroy_dummy_resources(sci_port
);
2269 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2272 * This method takes the struct scic_sds_port that is in a stopped state and handles a
2273 * stop request. This function takes no action. enum sci_status SCI_SUCCESS the
2274 * stop request is successful as the struct scic_sds_port object is already stopped.
2276 static enum sci_status
scic_sds_port_stopped_state_stop_handler(
2277 struct sci_base_port
*port
)
2279 /* We are already stopped so there is nothing to do here */
2285 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2288 * This method takes the struct scic_sds_port that is in a stopped state and handles
2289 * the destruct request. The stopped state is the only state in which the
2290 * struct scic_sds_port can be destroyed. This function causes the port object to
2291 * transition to the SCI_BASE_PORT_STATE_FINAL. enum sci_status SCI_SUCCESS
2293 static enum sci_status
scic_sds_port_stopped_state_destruct_handler(
2294 struct sci_base_port
*port
)
2296 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
2298 sci_base_state_machine_stop(&this_port
->parent
.state_machine
);
2305 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2307 * @phy: This is the struct sci_base_phy object which is cast into a struct scic_sds_phy
2310 * This method takes the struct scic_sds_port that is in a stopped state and handles
2311 * the add phy request. In MPC mode the only time a phy can be added to a port
2312 * is in the SCI_BASE_PORT_STATE_STOPPED. enum sci_status
2313 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION is returned when the phy can not
2314 * be added to the port. SCI_SUCCESS if the phy is added to the port.
2316 static enum sci_status
scic_sds_port_stopped_state_add_phy_handler(
2317 struct sci_base_port
*port
,
2318 struct sci_base_phy
*phy
)
2320 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
2321 struct scic_sds_phy
*this_phy
= (struct scic_sds_phy
*)phy
;
2322 struct sci_sas_address port_sas_address
;
2324 /* Read the port assigned SAS Address if there is one */
2325 scic_sds_port_get_sas_address(this_port
, &port_sas_address
);
2327 if (port_sas_address
.high
!= 0 && port_sas_address
.low
!= 0) {
2328 struct sci_sas_address phy_sas_address
;
2331 * Make sure that the PHY SAS Address matches the SAS Address
2333 scic_sds_phy_get_sas_address(this_phy
, &phy_sas_address
);
2336 (port_sas_address
.high
!= phy_sas_address
.high
)
2337 || (port_sas_address
.low
!= phy_sas_address
.low
)
2339 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
;
2343 return scic_sds_port_set_phy(this_port
, this_phy
);
2349 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2351 * @phy: This is the struct sci_base_phy object which is cast into a struct scic_sds_phy
2354 * This method takes the struct scic_sds_port that is in a stopped state and handles
2355 * the remove phy request. In MPC mode the only time a phy can be removed from
2356 * a port is in the SCI_BASE_PORT_STATE_STOPPED. enum sci_status
2357 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION is returned when the phy can not
2358 * be added to the port. SCI_SUCCESS if the phy is added to the port.
2360 static enum sci_status
scic_sds_port_stopped_state_remove_phy_handler(
2361 struct sci_base_port
*port
,
2362 struct sci_base_phy
*phy
)
2364 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
2365 struct scic_sds_phy
*this_phy
= (struct scic_sds_phy
*)phy
;
2367 return scic_sds_port_clear_phy(this_port
, this_phy
);
2371 * ****************************************************************************
2372 * * READY STATE HANDLERS
2373 * **************************************************************************** */
2376 * ****************************************************************************
2377 * * RESETTING STATE HANDLERS
2378 * **************************************************************************** */
2381 * ****************************************************************************
2382 * * STOPPING STATE HANDLERS
2383 * **************************************************************************** */
2387 * @port: This is the struct scic_sds_port object on which the io request count will
2389 * @device: This is the struct scic_sds_remote_device object to which the io request
2390 * is being directed. This parameter is not required to complete this
2392 * @io_request: This is the request that is being completed on this port
2393 * object. This parameter is not required to complete this operation.
2395 * This method takes the struct scic_sds_port that is in a stopping state and handles
2396 * the complete io request. Should the request count reach 0 then the port
2397 * object will transition to the stopped state. enum sci_status SCI_SUCCESS
2399 static enum sci_status
scic_sds_port_stopping_state_complete_io_handler(
2400 struct scic_sds_port
*port
,
2401 struct scic_sds_remote_device
*device
,
2402 struct scic_sds_request
*io_request
)
2404 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
2406 scic_sds_port_decrement_request_count(this_port
);
2408 if (this_port
->started_request_count
== 0) {
2409 sci_base_state_machine_change_state(
2410 scic_sds_port_get_base_state_machine(this_port
),
2411 SCI_BASE_PORT_STATE_STOPPED
2419 * ****************************************************************************
2420 * * RESETTING STATE HANDLERS
2421 * **************************************************************************** */
2425 * @port: This is the port object which is being requested to stop.
2427 * This method will stop a failed port. This causes a transition to the
2428 * stopping state. enum sci_status SCI_SUCCESS
2430 static enum sci_status
scic_sds_port_reset_state_stop_handler(
2431 struct sci_base_port
*port
)
2433 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
2435 sci_base_state_machine_change_state(
2436 &this_port
->parent
.state_machine
,
2437 SCI_BASE_PORT_STATE_STOPPING
2445 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2448 * This method will transition a failed port to its ready state. The port
2449 * failed because a hard reset request timed out but at some time later one or
2450 * more phys in the port became ready. enum sci_status SCI_SUCCESS
2452 static void scic_sds_port_reset_state_link_up_handler(
2453 struct scic_sds_port
*this_port
,
2454 struct scic_sds_phy
*phy
)
2457 * / @todo We should make sure that the phy that has gone link up is the same
2458 * / one on which we sent the reset. It is possible that the phy on
2459 * / which we sent the reset is not the one that has gone link up and we
2460 * / want to make sure that phy being reset comes back. Consider the
2461 * / case where a reset is sent but before the hardware processes the
2462 * / reset it get a link up on the port because of a hot plug event.
2463 * / because of the reset request this phy will go link down almost
2467 * In the resetting state we don't notify the user regarding
2468 * link up and link down notifications. */
2469 scic_sds_port_general_link_up_handler(this_port
, phy
, false);
2474 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2477 * This method process link down notifications that occur during a port reset
2478 * operation. Link downs can occur during the reset operation. enum sci_status
2481 static void scic_sds_port_reset_state_link_down_handler(
2482 struct scic_sds_port
*this_port
,
2483 struct scic_sds_phy
*phy
)
2486 * In the resetting state we don't notify the user regarding
2487 * link up and link down notifications. */
2488 scic_sds_port_deactivate_phy(this_port
, phy
, false);
2491 /* --------------------------------------------------------------------------- */
2493 struct scic_sds_port_state_handler
2494 scic_sds_port_state_handler_table
[SCI_BASE_PORT_MAX_STATES
] =
2496 /* SCI_BASE_PORT_STATE_STOPPED */
2499 scic_sds_port_stopped_state_start_handler
,
2500 scic_sds_port_stopped_state_stop_handler
,
2501 scic_sds_port_stopped_state_destruct_handler
,
2502 scic_sds_port_default_reset_handler
,
2503 scic_sds_port_stopped_state_add_phy_handler
,
2504 scic_sds_port_stopped_state_remove_phy_handler
2506 scic_sds_port_default_frame_handler
,
2507 scic_sds_port_default_event_handler
,
2508 scic_sds_port_default_link_up_handler
,
2509 scic_sds_port_default_link_down_handler
,
2510 scic_sds_port_default_start_io_handler
,
2511 scic_sds_port_default_complete_io_handler
2513 /* SCI_BASE_PORT_STATE_STOPPING */
2516 scic_sds_port_default_start_handler
,
2517 scic_sds_port_default_stop_handler
,
2518 scic_sds_port_default_destruct_handler
,
2519 scic_sds_port_default_reset_handler
,
2520 scic_sds_port_default_add_phy_handler
,
2521 scic_sds_port_default_remove_phy_handler
2523 scic_sds_port_default_frame_handler
,
2524 scic_sds_port_default_event_handler
,
2525 scic_sds_port_default_link_up_handler
,
2526 scic_sds_port_default_link_down_handler
,
2527 scic_sds_port_default_start_io_handler
,
2528 scic_sds_port_stopping_state_complete_io_handler
2530 /* SCI_BASE_PORT_STATE_READY */
2533 scic_sds_port_default_start_handler
,
2534 scic_sds_port_default_stop_handler
,
2535 scic_sds_port_default_destruct_handler
,
2536 scic_sds_port_default_reset_handler
,
2537 scic_sds_port_default_add_phy_handler
,
2538 scic_sds_port_default_remove_phy_handler
2540 scic_sds_port_default_frame_handler
,
2541 scic_sds_port_default_event_handler
,
2542 scic_sds_port_default_link_up_handler
,
2543 scic_sds_port_default_link_down_handler
,
2544 scic_sds_port_default_start_io_handler
,
2545 scic_sds_port_general_complete_io_handler
2547 /* SCI_BASE_PORT_STATE_RESETTING */
2550 scic_sds_port_default_start_handler
,
2551 scic_sds_port_reset_state_stop_handler
,
2552 scic_sds_port_default_destruct_handler
,
2553 scic_sds_port_default_reset_handler
,
2554 scic_sds_port_default_add_phy_handler
,
2555 scic_sds_port_default_remove_phy_handler
2557 scic_sds_port_default_frame_handler
,
2558 scic_sds_port_default_event_handler
,
2559 scic_sds_port_reset_state_link_up_handler
,
2560 scic_sds_port_reset_state_link_down_handler
,
2561 scic_sds_port_default_start_io_handler
,
2562 scic_sds_port_general_complete_io_handler
2564 /* SCI_BASE_PORT_STATE_FAILED */
2567 scic_sds_port_default_start_handler
,
2568 scic_sds_port_default_stop_handler
,
2569 scic_sds_port_default_destruct_handler
,
2570 scic_sds_port_default_reset_handler
,
2571 scic_sds_port_default_add_phy_handler
,
2572 scic_sds_port_default_remove_phy_handler
2574 scic_sds_port_default_frame_handler
,
2575 scic_sds_port_default_event_handler
,
2576 scic_sds_port_default_link_up_handler
,
2577 scic_sds_port_default_link_down_handler
,
2578 scic_sds_port_default_start_io_handler
,
2579 scic_sds_port_general_complete_io_handler
2584 * ******************************************************************************
2585 * * PORT STATE PRIVATE METHODS
2586 * ****************************************************************************** */
2590 * @this_port: This is the port object which to suspend.
2592 * This method will enable the SCU Port Task Scheduler for this port object but
2593 * will leave the port task scheduler in a suspended state. none
2595 static void scic_sds_port_enable_port_task_scheduler(
2596 struct scic_sds_port
*this_port
)
2598 u32 pts_control_value
;
2600 pts_control_value
= scu_port_task_scheduler_read(this_port
, control
);
2602 pts_control_value
|= SCU_PTSxCR_GEN_BIT(ENABLE
) | SCU_PTSxCR_GEN_BIT(SUSPEND
);
2604 scu_port_task_scheduler_write(this_port
, control
, pts_control_value
);
2609 * @this_port: This is the port object which to resume.
2611 * This method will disable the SCU port task scheduler for this port object.
2614 static void scic_sds_port_disable_port_task_scheduler(
2615 struct scic_sds_port
*this_port
)
2617 u32 pts_control_value
;
2619 pts_control_value
= scu_port_task_scheduler_read(this_port
, control
);
2621 pts_control_value
&= ~(SCU_PTSxCR_GEN_BIT(ENABLE
)
2622 | SCU_PTSxCR_GEN_BIT(SUSPEND
));
2624 scu_port_task_scheduler_write(this_port
, control
, pts_control_value
);
2627 void scic_sds_port_post_dummy_remote_node(struct scic_sds_port
*sci_port
)
2629 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
2630 u8 phys_index
= sci_port
->physical_port_index
;
2631 union scu_remote_node_context
*rnc
;
2632 u16 rni
= sci_port
->reserved_rni
;
2635 rnc
= &scic
->remote_node_context_table
[rni
];
2636 rnc
->ssp
.is_valid
= true;
2638 command
= SCU_CONTEXT_COMMAND_POST_RNC_32
|
2639 phys_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
| rni
;
2641 scic_sds_controller_post_request(scic
, command
);
2643 /* ensure hardware has seen the post rnc command and give it
2644 * ample time to act before sending the suspend
2646 SMU_ISR_READ(scic
); /* flush */
2649 command
= SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX
|
2650 phys_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
| rni
;
2652 scic_sds_controller_post_request(scic
, command
);
2655 void scic_sds_port_invalidate_dummy_remote_node(struct scic_sds_port
*sci_port
)
2657 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
2658 u8 phys_index
= sci_port
->physical_port_index
;
2659 union scu_remote_node_context
*rnc
;
2660 u16 rni
= sci_port
->reserved_rni
;
2663 rnc
= &scic
->remote_node_context_table
[rni
];
2665 rnc
->ssp
.is_valid
= false;
2667 command
= SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE
|
2668 phys_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
| rni
;
2670 scic_sds_controller_post_request(scic
, command
);
2674 * ******************************************************************************
2675 * * PORT STATE METHODS
2676 * ****************************************************************************** */
2680 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2682 * This method will perform the actions required by the struct scic_sds_port on
2683 * entering the SCI_BASE_PORT_STATE_STOPPED. This function sets the stopped
2684 * state handlers for the struct scic_sds_port object and disables the port task
2685 * scheduler in the hardware. none
2687 static void scic_sds_port_stopped_state_enter(
2688 struct sci_base_object
*object
)
2690 struct scic_sds_port
*this_port
;
2692 this_port
= (struct scic_sds_port
*)object
;
2694 scic_sds_port_set_base_state_handlers(
2695 this_port
, SCI_BASE_PORT_STATE_STOPPED
2699 SCI_BASE_PORT_STATE_STOPPING
2700 == this_port
->parent
.state_machine
.previous_state_id
2703 * If we enter this state becasuse of a request to stop
2704 * the port then we want to disable the hardwares port
2705 * task scheduler. */
2706 scic_sds_port_disable_port_task_scheduler(this_port
);
2712 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2714 * This method will perform the actions required by the struct scic_sds_port on
2715 * exiting the SCI_BASE_STATE_STOPPED. This function enables the SCU hardware
2716 * port task scheduler. none
2718 static void scic_sds_port_stopped_state_exit(
2719 struct sci_base_object
*object
)
2721 struct scic_sds_port
*this_port
;
2723 this_port
= (struct scic_sds_port
*)object
;
2725 /* Enable and suspend the port task scheduler */
2726 scic_sds_port_enable_port_task_scheduler(this_port
);
2731 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2733 * This method will perform the actions required by the struct scic_sds_port on
2734 * entering the SCI_BASE_PORT_STATE_READY. This function sets the ready state
2735 * handlers for the struct scic_sds_port object, reports the port object as not ready
2736 * and starts the ready substate machine. none
2738 static void scic_sds_port_ready_state_enter(
2739 struct sci_base_object
*object
)
2741 struct scic_sds_port
*this_port
;
2743 this_port
= (struct scic_sds_port
*)object
;
2745 /* Put the ready state handlers in place though they will not be there long */
2746 scic_sds_port_set_base_state_handlers(
2747 this_port
, SCI_BASE_PORT_STATE_READY
2751 SCI_BASE_PORT_STATE_RESETTING
2752 == this_port
->parent
.state_machine
.previous_state_id
2754 isci_event_port_hard_reset_complete(
2755 scic_sds_port_get_controller(this_port
),
2760 /* Notify the caller that the port is not yet ready */
2761 isci_event_port_not_ready(
2762 scic_sds_port_get_controller(this_port
),
2764 SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS
2768 /* Post and suspend the dummy remote node context for this port. */
2769 scic_sds_port_post_dummy_remote_node(this_port
);
2771 /* Start the ready substate machine */
2772 sci_base_state_machine_start(
2773 scic_sds_port_get_ready_substate_machine(this_port
)
2779 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2781 * This method will perform the actions required by the struct scic_sds_port on
2782 * exiting the SCI_BASE_STATE_READY. This function does nothing. none
2784 static void scic_sds_port_ready_state_exit(
2785 struct sci_base_object
*object
)
2787 struct scic_sds_port
*this_port
;
2789 this_port
= (struct scic_sds_port
*)object
;
2791 sci_base_state_machine_stop(&this_port
->ready_substate_machine
);
2793 scic_sds_port_invalidate_dummy_remote_node(this_port
);
2798 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2800 * This method will perform the actions required by the struct scic_sds_port on
2801 * entering the SCI_BASE_PORT_STATE_RESETTING. This function sets the resetting
2802 * state handlers for the struct scic_sds_port object. none
2804 static void scic_sds_port_resetting_state_enter(
2805 struct sci_base_object
*object
)
2807 struct scic_sds_port
*this_port
;
2809 this_port
= (struct scic_sds_port
*)object
;
2811 scic_sds_port_set_base_state_handlers(
2812 this_port
, SCI_BASE_PORT_STATE_RESETTING
2818 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2820 * This method will perform the actions required by the struct scic_sds_port on
2821 * exiting the SCI_BASE_STATE_RESETTING. This function does nothing. none
2823 static void scic_sds_port_resetting_state_exit(
2824 struct sci_base_object
*object
)
2826 struct scic_sds_port
*this_port
;
2828 this_port
= (struct scic_sds_port
*)object
;
2830 isci_event_timer_stop(
2831 scic_sds_port_get_controller(this_port
),
2832 this_port
->timer_handle
2838 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2840 * This method will perform the actions required by the struct scic_sds_port on
2841 * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
2842 * state handlers for the struct scic_sds_port object. none
2844 static void scic_sds_port_stopping_state_enter(
2845 struct sci_base_object
*object
)
2847 struct scic_sds_port
*this_port
;
2849 this_port
= (struct scic_sds_port
*)object
;
2851 scic_sds_port_set_base_state_handlers(
2852 this_port
, SCI_BASE_PORT_STATE_STOPPING
2858 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2860 * This method will perform the actions required by the struct scic_sds_port on
2861 * exiting the SCI_BASE_STATE_STOPPING. This function does nothing. none
2863 static void scic_sds_port_stopping_state_exit(
2864 struct sci_base_object
*object
)
2866 struct scic_sds_port
*this_port
;
2868 this_port
= (struct scic_sds_port
*)object
;
2870 isci_event_timer_stop(
2871 scic_sds_port_get_controller(this_port
),
2872 this_port
->timer_handle
2875 scic_sds_port_destroy_dummy_resources(this_port
);
2880 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2882 * This method will perform the actions required by the struct scic_sds_port on
2883 * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
2884 * state handlers for the struct scic_sds_port object. none
2886 static void scic_sds_port_failed_state_enter(
2887 struct sci_base_object
*object
)
2889 struct scic_sds_port
*this_port
;
2891 this_port
= (struct scic_sds_port
*)object
;
2893 scic_sds_port_set_base_state_handlers(
2895 SCI_BASE_PORT_STATE_FAILED
2898 isci_event_port_hard_reset_complete(
2899 scic_sds_port_get_controller(this_port
),
2905 /* --------------------------------------------------------------------------- */
2907 const struct sci_base_state scic_sds_port_state_table
[] = {
2908 [SCI_BASE_PORT_STATE_STOPPED
] = {
2909 .enter_state
= scic_sds_port_stopped_state_enter
,
2910 .exit_state
= scic_sds_port_stopped_state_exit
2912 [SCI_BASE_PORT_STATE_STOPPING
] = {
2913 .enter_state
= scic_sds_port_stopping_state_enter
,
2914 .exit_state
= scic_sds_port_stopping_state_exit
2916 [SCI_BASE_PORT_STATE_READY
] = {
2917 .enter_state
= scic_sds_port_ready_state_enter
,
2918 .exit_state
= scic_sds_port_ready_state_exit
2920 [SCI_BASE_PORT_STATE_RESETTING
] = {
2921 .enter_state
= scic_sds_port_resetting_state_enter
,
2922 .exit_state
= scic_sds_port_resetting_state_exit
2924 [SCI_BASE_PORT_STATE_FAILED
] = {
2925 .enter_state
= scic_sds_port_failed_state_enter
,