isci: remove mmio wrappers
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / scsi / isci / core / scic_sds_port.c
blob8e3983ebc4dcd006b4d1225becf58ed36bbb5ceb
1 /*
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.
5 * GPL LICENSE SUMMARY
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.
24 * BSD LICENSE
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
31 * are met:
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
38 * distribution.
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"
59 #include "scic_phy.h"
60 #include "scic_port.h"
61 #include "scic_sds_controller.h"
62 #include "scic_sds_phy.h"
63 #include "scic_sds_port.h"
64 #include "scic_sds_remote_device.h"
65 #include "scic_sds_remote_node_context.h"
66 #include "scic_sds_request.h"
67 #include "sci_environment.h"
68 #include "scu_registers.h"
70 #define SCIC_SDS_PORT_MIN_TIMER_COUNT (SCI_MAX_PORTS)
71 #define SCIC_SDS_PORT_MAX_TIMER_COUNT (SCI_MAX_PORTS)
73 #define SCIC_SDS_PORT_HARD_RESET_TIMEOUT (1000)
74 #define SCU_DUMMY_INDEX (0xFFFF)
76 static void sci_base_port_construct(
77 struct sci_base_port *base_port,
78 const struct sci_base_state *state_table)
80 base_port->parent.private = NULL;
81 sci_base_state_machine_construct(
82 &base_port->state_machine,
83 &base_port->parent,
84 state_table,
85 SCI_BASE_PORT_STATE_STOPPED
88 sci_base_state_machine_start(
89 &base_port->state_machine
93 /**
95 * @this_port: This is the port object to which the phy is being assigned.
96 * @phy_index: This is the phy index that is being assigned to the port.
98 * This method will return a true value if the specified phy can be assigned to
99 * this port The following is a list of phys for each port that are allowed: -
100 * Port 0 - 3 2 1 0 - Port 1 - 1 - Port 2 - 3 2 - Port 3 - 3 This method
101 * doesn't preclude all configurations. It merely ensures that a phy is part
102 * of the allowable set of phy identifiers for that port. For example, one
103 * could assign phy 3 to port 0 and no other phys. Please refer to
104 * scic_sds_port_is_phy_mask_valid() for information regarding whether the
105 * phy_mask for a port can be supported. bool true if this is a valid phy
106 * assignment for the port false if this is not a valid phy assignment for the
107 * port
109 bool scic_sds_port_is_valid_phy_assignment(
110 struct scic_sds_port *this_port,
111 u32 phy_index)
113 /* Initialize to invalid value. */
114 u32 existing_phy_index = SCI_MAX_PHYS;
115 u32 index;
117 if ((this_port->physical_port_index == 1) && (phy_index != 1)) {
118 return false;
121 if (this_port->physical_port_index == 3 && phy_index != 3) {
122 return false;
125 if (
126 (this_port->physical_port_index == 2)
127 && ((phy_index == 0) || (phy_index == 1))
129 return false;
132 for (index = 0; index < SCI_MAX_PHYS; index++) {
133 if ((this_port->phy_table[index] != NULL)
134 && (index != phy_index)) {
135 existing_phy_index = index;
140 * Ensure that all of the phys in the port are capable of
141 * operating at the same maximum link rate. */
142 if (
143 (existing_phy_index < SCI_MAX_PHYS)
144 && (this_port->owning_controller->user_parameters.sds1.phys[
145 phy_index].max_speed_generation !=
146 this_port->owning_controller->user_parameters.sds1.phys[
147 existing_phy_index].max_speed_generation)
149 return false;
151 return true;
155 * This method requests a list (mask) of the phys contained in the supplied SAS
156 * port.
157 * @this_port: a handle corresponding to the SAS port for which to return the
158 * phy mask.
160 * Return a bit mask indicating which phys are a part of this port. Each bit
161 * corresponds to a phy identifier (e.g. bit 0 = phy id 0).
163 static u32 scic_sds_port_get_phys(struct scic_sds_port *this_port)
165 u32 index;
166 u32 mask;
168 mask = 0;
170 for (index = 0; index < SCI_MAX_PHYS; index++) {
171 if (this_port->phy_table[index] != NULL) {
172 mask |= (1 << index);
176 return mask;
181 * @this_port: This is the port object for which to determine if the phy mask
182 * can be supported.
184 * This method will return a true value if the port's phy mask can be supported
185 * by the SCU. The following is a list of valid PHY mask configurations for
186 * each port: - Port 0 - [[3 2] 1] 0 - Port 1 - [1] - Port 2 - [[3] 2]
187 * - Port 3 - [3] This method returns a boolean indication specifying if the
188 * phy mask can be supported. true if this is a valid phy assignment for the
189 * port false if this is not a valid phy assignment for the port
191 static bool scic_sds_port_is_phy_mask_valid(
192 struct scic_sds_port *this_port,
193 u32 phy_mask)
195 if (this_port->physical_port_index == 0) {
196 if (((phy_mask & 0x0F) == 0x0F)
197 || ((phy_mask & 0x03) == 0x03)
198 || ((phy_mask & 0x01) == 0x01)
199 || (phy_mask == 0))
200 return true;
201 } else if (this_port->physical_port_index == 1) {
202 if (((phy_mask & 0x02) == 0x02)
203 || (phy_mask == 0))
204 return true;
205 } else if (this_port->physical_port_index == 2) {
206 if (((phy_mask & 0x0C) == 0x0C)
207 || ((phy_mask & 0x04) == 0x04)
208 || (phy_mask == 0))
209 return true;
210 } else if (this_port->physical_port_index == 3) {
211 if (((phy_mask & 0x08) == 0x08)
212 || (phy_mask == 0))
213 return true;
216 return false;
221 * @this_port: This parameter specifies the port from which to return a
222 * connected phy.
224 * This method retrieves a currently active (i.e. connected) phy contained in
225 * the port. Currently, the lowest order phy that is connected is returned.
226 * This method returns a pointer to a SCIS_SDS_PHY object. NULL This value is
227 * returned if there are no currently active (i.e. connected to a remote end
228 * point) phys contained in the port. All other values specify a struct scic_sds_phy
229 * object that is active in the port.
231 static struct scic_sds_phy *scic_sds_port_get_a_connected_phy(
232 struct scic_sds_port *this_port
234 u32 index;
235 struct scic_sds_phy *phy;
237 for (index = 0; index < SCI_MAX_PHYS; index++) {
239 * Ensure that the phy is both part of the port and currently
240 * connected to the remote end-point. */
241 phy = this_port->phy_table[index];
242 if (
243 (phy != NULL)
244 && scic_sds_port_active_phy(this_port, phy)
246 return phy;
250 return NULL;
254 * scic_sds_port_set_phy() -
255 * @out]: port The port object to which the phy assignement is being made.
256 * @out]: phy The phy which is being assigned to the port.
258 * This method attempts to make the assignment of the phy to the port. If
259 * successful the phy is assigned to the ports phy table. bool true if the phy
260 * assignment can be made. false if the phy assignement can not be made. This
261 * is a functional test that only fails if the phy is currently assigned to a
262 * different port.
264 static enum sci_status scic_sds_port_set_phy(
265 struct scic_sds_port *port,
266 struct scic_sds_phy *phy)
269 * Check to see if we can add this phy to a port
270 * that means that the phy is not part of a port and that the port does
271 * not already have a phy assinged to the phy index. */
272 if (
273 (port->phy_table[phy->phy_index] == NULL)
274 && (scic_sds_phy_get_port(phy) == NULL)
275 && scic_sds_port_is_valid_phy_assignment(port, phy->phy_index)
278 * Phy is being added in the stopped state so we are in MPC mode
279 * make logical port index = physical port index */
280 port->logical_port_index = port->physical_port_index;
281 port->phy_table[phy->phy_index] = phy;
282 scic_sds_phy_set_port(phy, port);
284 return SCI_SUCCESS;
287 return SCI_FAILURE;
291 * scic_sds_port_clear_phy() -
292 * @out]: port The port from which the phy is being cleared.
293 * @out]: phy The phy being cleared from the port.
295 * This method will clear the phy assigned to this port. This method fails if
296 * this phy is not currently assinged to this port. bool true if the phy is
297 * removed from the port. false if this phy is not assined to this port.
299 static enum sci_status scic_sds_port_clear_phy(
300 struct scic_sds_port *port,
301 struct scic_sds_phy *phy)
303 /* Make sure that this phy is part of this port */
304 if (
305 (port->phy_table[phy->phy_index] == phy)
306 && (scic_sds_phy_get_port(phy) == port)
308 /* Yep it is assigned to this port so remove it */
309 scic_sds_phy_set_port(
310 phy,
311 &scic_sds_port_get_controller(port)->port_table[SCI_MAX_PORTS]
314 port->phy_table[phy->phy_index] = NULL;
316 return SCI_SUCCESS;
319 return SCI_FAILURE;
323 * scic_sds_port_add_phy() -
324 * @this_port: This parameter specifies the port in which the phy will be added.
325 * @the_phy: This parameter is the phy which is to be added to the port.
327 * This method will add a PHY to the selected port. This method returns an
328 * enum sci_status. SCI_SUCCESS the phy has been added to the port. Any other status
329 * is failre to add the phy to the port.
331 enum sci_status scic_sds_port_add_phy(
332 struct scic_sds_port *this_port,
333 struct scic_sds_phy *the_phy)
335 return this_port->state_handlers->parent.add_phy_handler(
336 &this_port->parent, &the_phy->parent);
341 * scic_sds_port_remove_phy() -
342 * @this_port: This parameter specifies the port in which the phy will be added.
343 * @the_phy: This parameter is the phy which is to be added to the port.
345 * This method will remove the PHY from the selected PORT. This method returns
346 * an enum sci_status. SCI_SUCCESS the phy has been removed from the port. Any other
347 * status is failre to add the phy to the port.
349 enum sci_status scic_sds_port_remove_phy(
350 struct scic_sds_port *this_port,
351 struct scic_sds_phy *the_phy)
353 return this_port->state_handlers->parent.remove_phy_handler(
354 &this_port->parent, &the_phy->parent);
358 * This method requests the SAS address for the supplied SAS port from the SCI
359 * implementation.
360 * @this_port: a handle corresponding to the SAS port for which to return the
361 * SAS address.
362 * @sas_address: This parameter specifies a pointer to a SAS address structure
363 * into which the core will copy the SAS address for the port.
366 void scic_sds_port_get_sas_address(
367 struct scic_sds_port *this_port,
368 struct sci_sas_address *sas_address)
370 u32 index;
372 sas_address->high = 0;
373 sas_address->low = 0;
375 for (index = 0; index < SCI_MAX_PHYS; index++) {
376 if (this_port->phy_table[index] != NULL) {
377 scic_sds_phy_get_sas_address(this_port->phy_table[index], sas_address);
383 * This method will indicate which protocols are supported by this port.
384 * @this_port: a handle corresponding to the SAS port for which to return the
385 * supported protocols.
386 * @protocols: This parameter specifies a pointer to an IAF protocol field
387 * structure into which the core will copy the protocol values for the port.
388 * The values are returned as part of a bit mask in order to allow for
389 * multi-protocol support.
392 static void scic_sds_port_get_protocols(
393 struct scic_sds_port *this_port,
394 struct sci_sas_identify_address_frame_protocols *protocols)
396 u8 index;
398 protocols->u.all = 0;
400 for (index = 0; index < SCI_MAX_PHYS; index++) {
401 if (this_port->phy_table[index] != NULL) {
402 scic_sds_phy_get_protocols(this_port->phy_table[index], protocols);
408 * This method requests the SAS address for the device directly attached to
409 * this SAS port.
410 * @this_port: a handle corresponding to the SAS port for which to return the
411 * SAS address.
412 * @sas_address: This parameter specifies a pointer to a SAS address structure
413 * into which the core will copy the SAS address for the device directly
414 * attached to the port.
417 void scic_sds_port_get_attached_sas_address(
418 struct scic_sds_port *this_port,
419 struct sci_sas_address *sas_address)
421 struct sci_sas_identify_address_frame_protocols protocols;
422 struct scic_sds_phy *phy;
425 * Ensure that the phy is both part of the port and currently
426 * connected to the remote end-point. */
427 phy = scic_sds_port_get_a_connected_phy(this_port);
428 if (phy != NULL) {
429 scic_sds_phy_get_attached_phy_protocols(phy, &protocols);
431 if (!protocols.u.bits.stp_target) {
432 scic_sds_phy_get_attached_sas_address(phy, sas_address);
433 } else {
434 scic_sds_phy_get_sas_address(phy, sas_address);
435 sas_address->low += phy->phy_index;
437 } else {
438 sas_address->high = 0;
439 sas_address->low = 0;
444 * This method will indicate which protocols are supported by this remote
445 * device.
446 * @this_port: a handle corresponding to the SAS port for which to return the
447 * supported protocols.
448 * @protocols: This parameter specifies a pointer to an IAF protocol field
449 * structure into which the core will copy the protocol values for the port.
450 * The values are returned as part of a bit mask in order to allow for
451 * multi-protocol support.
454 void scic_sds_port_get_attached_protocols(
455 struct scic_sds_port *this_port,
456 struct sci_sas_identify_address_frame_protocols *protocols)
458 struct scic_sds_phy *phy;
461 * Ensure that the phy is both part of the port and currently
462 * connected to the remote end-point. */
463 phy = scic_sds_port_get_a_connected_phy(this_port);
464 if (phy != NULL)
465 scic_sds_phy_get_attached_phy_protocols(phy, protocols);
466 else
467 protocols->u.all = 0;
471 * scic_sds_port_construct_dummy_rnc() - create dummy rnc for si workaround
473 * @sci_port: logical port on which we need to create the remote node context
474 * @rni: remote node index for this remote node context.
476 * This routine will construct a dummy remote node context data structure
477 * This structure will be posted to the hardware to work around a scheduler
478 * error in the hardware.
480 static void scic_sds_port_construct_dummy_rnc(struct scic_sds_port *sci_port, u16 rni)
482 union scu_remote_node_context *rnc;
484 rnc = &sci_port->owning_controller->remote_node_context_table[rni];
486 memset(rnc, 0, sizeof(union scu_remote_node_context));
488 rnc->ssp.remote_sas_address_hi = 0;
489 rnc->ssp.remote_sas_address_lo = 0;
491 rnc->ssp.remote_node_index = rni;
492 rnc->ssp.remote_node_port_width = 1;
493 rnc->ssp.logical_port_index = sci_port->physical_port_index;
495 rnc->ssp.nexus_loss_timer_enable = false;
496 rnc->ssp.check_bit = false;
497 rnc->ssp.is_valid = true;
498 rnc->ssp.is_remote_node_context = true;
499 rnc->ssp.function_number = 0;
500 rnc->ssp.arbitration_wait_time = 0;
504 * scic_sds_port_construct_dummy_task() - create dummy task for si workaround
505 * @sci_port The logical port on which we need to create the
506 * remote node context.
507 * context.
508 * @tci The remote node index for this remote node context.
510 * This routine will construct a dummy task context data structure. This
511 * structure will be posted to the hardwre to work around a scheduler error
512 * in the hardware.
515 static void scic_sds_port_construct_dummy_task(struct scic_sds_port *sci_port, u16 tci)
517 struct scu_task_context *task_context;
519 task_context = scic_sds_controller_get_task_context_buffer(sci_port->owning_controller, tci);
521 memset(task_context, 0, sizeof(struct scu_task_context));
523 task_context->abort = 0;
524 task_context->priority = 0;
525 task_context->initiator_request = 1;
526 task_context->connection_rate = 1;
527 task_context->protocol_engine_index = 0;
528 task_context->logical_port_index = sci_port->physical_port_index;
529 task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SSP;
530 task_context->task_index = scic_sds_io_tag_get_index(tci);
531 task_context->valid = SCU_TASK_CONTEXT_VALID;
532 task_context->context_type = SCU_TASK_CONTEXT_TYPE;
534 task_context->remote_node_index = sci_port->reserved_rni;
535 task_context->command_code = 0;
537 task_context->link_layer_control = 0;
538 task_context->do_not_dma_ssp_good_response = 1;
539 task_context->strict_ordering = 0;
540 task_context->control_frame = 0;
541 task_context->timeout_enable = 0;
542 task_context->block_guard_enable = 0;
544 task_context->address_modifier = 0;
546 task_context->task_phase = 0x01;
549 static void scic_sds_port_destroy_dummy_resources(struct scic_sds_port *sci_port)
551 struct scic_sds_controller *scic = sci_port->owning_controller;
553 if (sci_port->reserved_tci != SCU_DUMMY_INDEX)
554 scic_controller_free_io_tag(scic, sci_port->reserved_tci);
556 if (sci_port->reserved_rni != SCU_DUMMY_INDEX)
557 scic_sds_remote_node_table_release_remote_node_index(&scic->available_remote_nodes,
558 1, sci_port->reserved_rni);
560 sci_port->reserved_rni = SCU_DUMMY_INDEX;
561 sci_port->reserved_tci = SCU_DUMMY_INDEX;
565 * This method performs initialization of the supplied port. Initialization
566 * includes: - state machine initialization - member variable initialization
567 * - configuring the phy_mask
568 * @this_port:
569 * @transport_layer_registers:
570 * @port_task_scheduler_registers:
571 * @port_configuration_regsiter:
573 * enum sci_status SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION This value is returned
574 * if the phy being added to the port
576 enum sci_status scic_sds_port_initialize(
577 struct scic_sds_port *this_port,
578 void __iomem *port_task_scheduler_registers,
579 void __iomem *port_configuration_regsiter,
580 void __iomem *viit_registers)
582 this_port->port_task_scheduler_registers = port_task_scheduler_registers;
583 this_port->port_pe_configuration_register = port_configuration_regsiter;
584 this_port->viit_registers = viit_registers;
586 return SCI_SUCCESS;
590 * scic_port_get_properties() - This method simply returns the properties
591 * regarding the port, such as: physical index, protocols, sas address, etc.
592 * @port: this parameter specifies the port for which to retrieve the physical
593 * index.
594 * @properties: This parameter specifies the properties structure into which to
595 * copy the requested information.
597 * Indicate if the user specified a valid port. SCI_SUCCESS This value is
598 * returned if the specified port was valid. SCI_FAILURE_INVALID_PORT This
599 * value is returned if the specified port is not valid. When this value is
600 * returned, no data is copied to the properties output parameter.
602 enum sci_status scic_port_get_properties(
603 struct scic_sds_port *port,
604 struct scic_port_properties *prop)
606 if ((port == NULL) ||
607 (port->logical_port_index == SCIC_SDS_DUMMY_PORT))
608 return SCI_FAILURE_INVALID_PORT;
610 prop->index = port->logical_port_index;
611 prop->phy_mask = scic_sds_port_get_phys(port);
612 scic_sds_port_get_sas_address(port, &prop->local.sas_address);
613 scic_sds_port_get_protocols(port, &prop->local.protocols);
614 scic_sds_port_get_attached_sas_address(port, &prop->remote.sas_address);
615 scic_sds_port_get_attached_protocols(port, &prop->remote.protocols);
617 return SCI_SUCCESS;
621 * scic_port_hard_reset() - perform port hard reset
622 * @port: a handle corresponding to the SAS port to be hard reset.
623 * @reset_timeout: This parameter specifies the number of milliseconds in which
624 * the port reset operation should complete.
626 * The SCI User callback in scic_user_callbacks_t will only be called once for
627 * each phy in the SAS Port at completion of the hard reset sequence. Return a
628 * status indicating whether the hard reset started successfully. SCI_SUCCESS
629 * This value is returned if the hard reset operation started successfully.
631 enum sci_status scic_port_hard_reset(
632 struct scic_sds_port *port,
633 u32 reset_timeout)
635 return port->state_handlers->parent.reset_handler(
636 &port->parent, reset_timeout);
640 * This method assigns the direct attached device ID for this port.
642 * @param[in] this_port The port for which the direct attached device id is to
643 * be assigned.
644 * @param[in] device_id The direct attached device ID to assign to the port.
645 * This will be the RNi for the device
647 void scic_sds_port_setup_transports(
648 struct scic_sds_port *this_port,
649 u32 device_id)
651 u8 index;
653 for (index = 0; index < SCI_MAX_PHYS; index++) {
654 if (this_port->active_phy_mask & (1 << index))
655 scic_sds_phy_setup_transport(this_port->phy_table[index], device_id);
661 * @this_port: This is the port on which the phy should be enabled.
662 * @the_phy: This is the specific phy which to enable.
663 * @do_notify_user: This parameter specifies whether to inform the user (via
664 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
666 * This function will activate the phy in the port.
667 * Activation includes: - adding
668 * the phy to the port - enabling the Protocol Engine in the silicon. -
669 * notifying the user that the link is up. none
671 static void scic_sds_port_activate_phy(struct scic_sds_port *sci_port,
672 struct scic_sds_phy *sci_phy,
673 bool do_notify_user)
675 struct scic_sds_controller *scic = scic_sds_port_get_controller(sci_port);
676 struct sci_sas_identify_address_frame_protocols protocols;
677 struct isci_host *ihost = sci_object_get_association(scic);
679 scic_sds_phy_get_attached_phy_protocols(sci_phy, &protocols);
681 /* If this is sata port then the phy has already been resumed */
682 if (!protocols.u.bits.stp_target)
683 scic_sds_phy_resume(sci_phy);
685 sci_port->active_phy_mask |= 1 << sci_phy->phy_index;
687 scic_sds_controller_clear_invalid_phy(scic, sci_phy);
689 if (do_notify_user == true)
690 isci_port_link_up(ihost, sci_port, sci_phy);
693 void scic_sds_port_deactivate_phy(struct scic_sds_port *sci_port,
694 struct scic_sds_phy *sci_phy,
695 bool do_notify_user)
697 struct scic_sds_controller *scic = scic_sds_port_get_controller(sci_port);
698 struct isci_port *iport = sci_object_get_association(sci_port);
699 struct isci_host *ihost = sci_object_get_association(scic);
700 struct isci_phy *iphy = sci_object_get_association(sci_phy);
702 sci_port->active_phy_mask &= ~(1 << sci_phy->phy_index);
704 sci_phy->max_negotiated_speed = SCI_SAS_NO_LINK_RATE;
706 /* Re-assign the phy back to the LP as if it were a narrow port */
707 writel(sci_phy->phy_index,
708 &sci_port->port_pe_configuration_register[sci_phy->phy_index]);
710 if (do_notify_user == true)
711 isci_port_link_down(ihost, iphy, iport);
716 * @this_port: This is the port on which the phy should be disabled.
717 * @the_phy: This is the specific phy which to disabled.
719 * This function will disable the phy and report that the phy is not valid for
720 * this port object. None
722 static void scic_sds_port_invalid_link_up(
723 struct scic_sds_port *sci_port,
724 struct scic_sds_phy *sci_phy)
726 struct scic_sds_controller *scic =
727 scic_sds_port_get_controller(sci_port);
730 * Check to see if we have alreay reported this link as bad and if
731 * not go ahead and tell the SCI_USER that we have discovered an
732 * invalid link.
734 if ((scic->invalid_phy_mask & (1 << sci_phy->phy_index)) == 0) {
735 scic_sds_controller_set_invalid_phy(scic, sci_phy);
736 isci_port_invalid_link_up(scic, sci_port, sci_phy);
741 * scic_sds_port_general_link_up_handler - phy can be assigned to port?
742 * @sci_port: scic_sds_port object for which has a phy that has gone link up.
743 * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
744 * @do_notify_user: This parameter specifies whether to inform the user (via
745 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
747 * Determine if this phy can be assigned to this
748 * port . If the phy is not a valid PHY for
749 * this port then the function will notify the user. A PHY can only be
750 * part of a port if it's attached SAS ADDRESS is the same as all other PHYs in
751 * the same port. none
753 static void scic_sds_port_general_link_up_handler(struct scic_sds_port *sci_port,
754 struct scic_sds_phy *sci_phy,
755 bool do_notify_user)
757 struct sci_sas_address port_sas_address;
758 struct sci_sas_address phy_sas_address;
760 scic_sds_port_get_attached_sas_address(sci_port, &port_sas_address);
761 scic_sds_phy_get_attached_sas_address(sci_phy, &phy_sas_address);
763 /* If the SAS address of the new phy matches the SAS address of
764 * other phys in the port OR this is the first phy in the port,
765 * then activate the phy and allow it to be used for operations
766 * in this port.
768 if ((phy_sas_address.high == port_sas_address.high &&
769 phy_sas_address.low == port_sas_address.low) ||
770 sci_port->active_phy_mask == 0) {
771 struct sci_base_state_machine *sm = &sci_port->parent.state_machine;
773 scic_sds_port_activate_phy(sci_port, sci_phy, do_notify_user);
774 if (sm->current_state_id == SCI_BASE_PORT_STATE_RESETTING)
775 sci_base_state_machine_change_state(sm, SCI_BASE_PORT_STATE_READY);
776 } else
777 scic_sds_port_invalid_link_up(sci_port, sci_phy);
783 * This method returns false if the port only has a single phy object assigned.
784 * If there are no phys or more than one phy then the method will return
785 * true.
786 * @this_port: The port for which the wide port condition is to be checked.
788 * bool true Is returned if this is a wide ported port. false Is returned if
789 * this is a narrow port.
791 static bool scic_sds_port_is_wide(struct scic_sds_port *this_port)
793 u32 index;
794 u32 phy_count = 0;
796 for (index = 0; index < SCI_MAX_PHYS; index++) {
797 if (this_port->phy_table[index] != NULL) {
798 phy_count++;
802 return phy_count != 1;
806 * This method is called by the PHY object when the link is detected. if the
807 * port wants the PHY to continue on to the link up state then the port
808 * layer must return true. If the port object returns false the phy object
809 * must halt its attempt to go link up.
810 * @this_port: The port associated with the phy object.
811 * @the_phy: The phy object that is trying to go link up.
813 * true if the phy object can continue to the link up condition. true Is
814 * returned if this phy can continue to the ready state. false Is returned if
815 * can not continue on to the ready state. This notification is in place for
816 * wide ports and direct attached phys. Since there are no wide ported SATA
817 * devices this could become an invalid port configuration.
819 bool scic_sds_port_link_detected(
820 struct scic_sds_port *this_port,
821 struct scic_sds_phy *the_phy)
823 struct sci_sas_identify_address_frame_protocols protocols;
825 scic_sds_phy_get_attached_phy_protocols(the_phy, &protocols);
827 if (
828 (this_port->logical_port_index != SCIC_SDS_DUMMY_PORT)
829 && (protocols.u.bits.stp_target)
830 && scic_sds_port_is_wide(this_port)
832 scic_sds_port_invalid_link_up(this_port, the_phy);
834 return false;
837 return true;
841 * This method is the entry point for the phy to inform the port that it is now
842 * in a ready state
843 * @this_port:
847 void scic_sds_port_link_up(
848 struct scic_sds_port *this_port,
849 struct scic_sds_phy *the_phy)
851 the_phy->is_in_link_training = false;
853 this_port->state_handlers->link_up_handler(this_port, the_phy);
857 * This method is the entry point for the phy to inform the port that it is no
858 * longer in a ready state
859 * @this_port:
863 void scic_sds_port_link_down(
864 struct scic_sds_port *this_port,
865 struct scic_sds_phy *the_phy)
867 this_port->state_handlers->link_down_handler(this_port, the_phy);
871 * This method is called to start an IO request on this port.
872 * @this_port:
873 * @the_device:
874 * @the_io_request:
876 * enum sci_status
878 enum sci_status scic_sds_port_start_io(
879 struct scic_sds_port *this_port,
880 struct scic_sds_remote_device *the_device,
881 struct scic_sds_request *the_io_request)
883 return this_port->state_handlers->start_io_handler(
884 this_port, the_device, the_io_request);
888 * This method is called to complete an IO request to the port.
889 * @this_port:
890 * @the_device:
891 * @the_io_request:
893 * enum sci_status
895 enum sci_status scic_sds_port_complete_io(
896 struct scic_sds_port *this_port,
897 struct scic_sds_remote_device *the_device,
898 struct scic_sds_request *the_io_request)
900 return this_port->state_handlers->complete_io_handler(
901 this_port, the_device, the_io_request);
905 * This method is provided to timeout requests for port operations. Mostly its
906 * for the port reset operation.
910 static void scic_sds_port_timeout_handler(void *port)
912 struct scic_sds_port *sci_port = port;
913 u32 current_state;
915 current_state = sci_base_state_machine_get_state(
916 &sci_port->parent.state_machine);
918 if (current_state == SCI_BASE_PORT_STATE_RESETTING) {
920 * if the port is still in the resetting state then the
921 * timeout fired before the reset completed.
923 sci_base_state_machine_change_state(
924 &sci_port->parent.state_machine,
925 SCI_BASE_PORT_STATE_FAILED);
926 } else if (current_state == SCI_BASE_PORT_STATE_STOPPED) {
928 * if the port is stopped then the start request failed
929 * In this case stay in the stopped state.
931 dev_err(sciport_to_dev(sci_port),
932 "%s: SCIC Port 0x%p failed to stop before tiemout.\n",
933 __func__,
934 sci_port);
935 } else if (current_state == SCI_BASE_PORT_STATE_STOPPING) {
937 * if the port is still stopping then the stop has not
938 * completed
940 isci_port_stop_complete(
941 scic_sds_port_get_controller(sci_port),
942 sci_port,
943 SCI_FAILURE_TIMEOUT);
944 } else {
946 * The port is in the ready state and we have a timer
947 * reporting a timeout this should not happen.
949 dev_err(sciport_to_dev(sci_port),
950 "%s: SCIC Port 0x%p is processing a timeout operation "
951 "in state %d.\n",
952 __func__,
953 sci_port,
954 current_state);
958 /* --------------------------------------------------------------------------- */
961 * This function updates the hardwares VIIT entry for this port.
965 static void scic_sds_port_update_viit_entry(struct scic_sds_port *this_port)
967 struct sci_sas_address sas_address;
969 scic_sds_port_get_sas_address(this_port, &sas_address);
971 writel(sas_address.high,
972 &this_port->viit_registers->initiator_sas_address_hi);
973 writel(sas_address.low,
974 &this_port->viit_registers->initiator_sas_address_lo);
976 /* This value get cleared just in case its not already cleared */
977 writel(0, &this_port->viit_registers->reserved);
979 /* We are required to update the status register last */
980 writel(SCU_VIIT_ENTRY_ID_VIIT |
981 SCU_VIIT_IPPT_INITIATOR |
982 ((1 << this_port->physical_port_index) << SCU_VIIT_ENTRY_LPVIE_SHIFT) |
983 SCU_VIIT_STATUS_ALL_VALID,
984 &this_port->viit_registers->status);
988 * This method returns the maximum allowed speed for data transfers on this
989 * port. This maximum allowed speed evaluates to the maximum speed of the
990 * slowest phy in the port.
991 * @this_port: This parameter specifies the port for which to retrieve the
992 * maximum allowed speed.
994 * This method returns the maximum negotiated speed of the slowest phy in the
995 * port.
997 enum sci_sas_link_rate scic_sds_port_get_max_allowed_speed(
998 struct scic_sds_port *this_port)
1000 u16 index = 0;
1001 enum sci_sas_link_rate max_allowed_speed = SCI_SAS_600_GB;
1002 struct scic_sds_phy *phy = NULL;
1005 * Loop through all of the phys in this port and find the phy with the
1006 * lowest maximum link rate. */
1007 for (index = 0; index < SCI_MAX_PHYS; index++) {
1008 phy = this_port->phy_table[index];
1009 if (
1010 (phy != NULL)
1011 && (scic_sds_port_active_phy(this_port, phy) == true)
1012 && (phy->max_negotiated_speed < max_allowed_speed)
1014 max_allowed_speed = phy->max_negotiated_speed;
1017 return max_allowed_speed;
1022 * This method passes the event to core user.
1023 * @this_port: The port that a BCN happens.
1024 * @this_phy: The phy that receives BCN.
1027 void scic_sds_port_broadcast_change_received(
1028 struct scic_sds_port *sci_port,
1029 struct scic_sds_phy *sci_phy)
1031 struct scic_sds_controller *scic = sci_port->owning_controller;
1032 struct isci_host *ihost = sci_object_get_association(scic);
1034 /* notify the user. */
1035 isci_port_bc_change_received(ihost, sci_port, sci_phy);
1040 * This API methhod enables the broadcast change notification from underneath
1041 * hardware.
1042 * @this_port: The port that a BCN had been disabled from.
1045 void scic_port_enable_broadcast_change_notification(
1046 struct scic_sds_port *port)
1048 struct scic_sds_phy *phy;
1049 u32 register_value;
1050 u8 index;
1052 /* Loop through all of the phys to enable BCN. */
1053 for (index = 0; index < SCI_MAX_PHYS; index++) {
1054 phy = port->phy_table[index];
1055 if (phy != NULL) {
1056 register_value =
1057 readl(&phy->link_layer_registers->link_layer_control);
1059 /* clear the bit by writing 1. */
1060 writel(register_value,
1061 &phy->link_layer_registers->link_layer_control);
1067 * ****************************************************************************
1068 * * READY SUBSTATE HANDLERS
1069 * **************************************************************************** */
1073 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1074 * object.
1076 * This method is the general ready state stop handler for the struct scic_sds_port
1077 * object. This function will transition the ready substate machine to its
1078 * final state. enum sci_status SCI_SUCCESS
1080 static enum sci_status scic_sds_port_ready_substate_stop_handler(
1081 struct sci_base_port *port)
1083 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
1085 sci_base_state_machine_change_state(
1086 &this_port->parent.state_machine,
1087 SCI_BASE_PORT_STATE_STOPPING
1090 return SCI_SUCCESS;
1095 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1096 * object.
1097 * @device: This is the struct sci_base_remote_device object which is not used in this
1098 * function.
1099 * @io_request: This is the struct sci_base_request object which is not used in this
1100 * function.
1102 * This method is the general ready substate complete io handler for the
1103 * struct scic_sds_port object. This function decrments the outstanding request count
1104 * for this port object. enum sci_status SCI_SUCCESS
1106 static enum sci_status scic_sds_port_ready_substate_complete_io_handler(
1107 struct scic_sds_port *port,
1108 struct scic_sds_remote_device *device,
1109 struct scic_sds_request *io_request)
1111 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
1113 scic_sds_port_decrement_request_count(this_port);
1115 return SCI_SUCCESS;
1118 static enum sci_status scic_sds_port_ready_substate_add_phy_handler(
1119 struct sci_base_port *port,
1120 struct sci_base_phy *phy)
1122 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
1123 struct scic_sds_phy *this_phy = (struct scic_sds_phy *)phy;
1124 enum sci_status status;
1126 status = scic_sds_port_set_phy(this_port, this_phy);
1128 if (status == SCI_SUCCESS) {
1129 scic_sds_port_general_link_up_handler(this_port, this_phy, true);
1131 this_port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
1133 sci_base_state_machine_change_state(
1134 &this_port->ready_substate_machine,
1135 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1139 return status;
1143 static enum sci_status scic_sds_port_ready_substate_remove_phy_handler(
1144 struct sci_base_port *port,
1145 struct sci_base_phy *phy)
1147 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
1148 struct scic_sds_phy *this_phy = (struct scic_sds_phy *)phy;
1149 enum sci_status status;
1151 status = scic_sds_port_clear_phy(this_port, this_phy);
1153 if (status == SCI_SUCCESS) {
1154 scic_sds_port_deactivate_phy(this_port, this_phy, true);
1156 this_port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
1158 sci_base_state_machine_change_state(
1159 &this_port->ready_substate_machine,
1160 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1164 return status;
1168 * ****************************************************************************
1169 * * READY SUBSTATE WAITING HANDLERS
1170 * **************************************************************************** */
1174 * @this_port: This is the struct scic_sds_port object that which has a phy that has
1175 * gone link up.
1176 * @the_phy: This is the struct scic_sds_phy object that has gone link up.
1178 * This method is the ready waiting substate link up handler for the
1179 * struct scic_sds_port object. This methos will report the link up condition for
1180 * this port and will transition to the ready operational substate. none
1182 static void scic_sds_port_ready_waiting_substate_link_up_handler(
1183 struct scic_sds_port *this_port,
1184 struct scic_sds_phy *the_phy)
1187 * Since this is the first phy going link up for the port we can just enable
1188 * it and continue. */
1189 scic_sds_port_activate_phy(this_port, the_phy, true);
1191 sci_base_state_machine_change_state(
1192 &this_port->ready_substate_machine,
1193 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1199 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1200 * object.
1201 * @device: This is the struct sci_base_remote_device object which is not used in this
1202 * request.
1203 * @io_request: This is the struct sci_base_request object which is not used in this
1204 * function.
1206 * This method is the ready waiting substate start io handler for the
1207 * struct scic_sds_port object. The port object can not accept new requests so the
1208 * request is failed. enum sci_status SCI_FAILURE_INVALID_STATE
1210 static enum sci_status scic_sds_port_ready_waiting_substate_start_io_handler(
1211 struct scic_sds_port *port,
1212 struct scic_sds_remote_device *device,
1213 struct scic_sds_request *io_request)
1215 return SCI_FAILURE_INVALID_STATE;
1219 * ****************************************************************************
1220 * * READY SUBSTATE OPERATIONAL HANDLERS
1221 * **************************************************************************** */
1225 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1226 * object.
1227 * @timeout: This is the timeout for the reset request to complete.
1229 * This method will casue the port to reset. enum sci_status SCI_SUCCESS
1231 static enum
1232 sci_status scic_sds_port_ready_operational_substate_reset_handler(
1233 struct sci_base_port *port,
1234 u32 timeout)
1236 enum sci_status status = SCI_FAILURE_INVALID_PHY;
1237 u32 phy_index;
1238 struct scic_sds_port *sci_port = (struct scic_sds_port *)port;
1239 struct scic_sds_phy *selected_phy = NULL;
1242 /* Select a phy on which we can send the hard reset request. */
1243 for (phy_index = 0;
1244 (phy_index < SCI_MAX_PHYS) && (selected_phy == NULL);
1245 phy_index++) {
1246 selected_phy = sci_port->phy_table[phy_index];
1248 if ((selected_phy != NULL) &&
1249 !scic_sds_port_active_phy(sci_port, selected_phy)) {
1251 * We found a phy but it is not ready select
1252 * different phy
1254 selected_phy = NULL;
1258 /* If we have a phy then go ahead and start the reset procedure */
1259 if (selected_phy != NULL) {
1260 status = scic_sds_phy_reset(selected_phy);
1262 if (status == SCI_SUCCESS) {
1263 isci_timer_start(sci_port->timer_handle, timeout);
1264 sci_port->not_ready_reason =
1265 SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED;
1267 sci_base_state_machine_change_state(
1268 &sci_port->parent.state_machine,
1269 SCI_BASE_PORT_STATE_RESETTING);
1273 return status;
1277 * scic_sds_port_ready_operational_substate_link_up_handler() -
1278 * @this_port: This is the struct scic_sds_port object that which has a phy that has
1279 * gone link up.
1280 * @the_phy: This is the struct scic_sds_phy object that has gone link up.
1282 * This method is the ready operational substate link up handler for the
1283 * struct scic_sds_port object. This function notifies the SCI User that the phy has
1284 * gone link up. none
1286 static void scic_sds_port_ready_operational_substate_link_up_handler(
1287 struct scic_sds_port *this_port,
1288 struct scic_sds_phy *the_phy)
1290 scic_sds_port_general_link_up_handler(this_port, the_phy, true);
1294 * scic_sds_port_ready_operational_substate_link_down_handler() -
1295 * @sci_port: This is the struct scic_sds_port object that which has a phy that has
1296 * gone link down.
1297 * @sci_phy: This is the struct scic_sds_phy object that has gone link down.
1299 * This method is the ready operational substate link down handler for the
1300 * struct scic_sds_port object. This function notifies the SCI User that the phy has
1301 * gone link down and if this is the last phy in the port the port will change
1302 * state to the ready waiting substate. none
1304 static void scic_sds_port_ready_operational_substate_link_down_handler(
1305 struct scic_sds_port *sci_port,
1306 struct scic_sds_phy *sci_phy)
1308 scic_sds_port_deactivate_phy(sci_port, sci_phy, true);
1311 * If there are no active phys left in the port, then transition
1312 * the port to the WAITING state until such time as a phy goes
1313 * link up. */
1314 if (sci_port->active_phy_mask == 0)
1315 sci_base_state_machine_change_state(&sci_port->ready_substate_machine,
1316 SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
1321 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1322 * object.
1323 * @device: This is the struct sci_base_remote_device object which is not used in this
1324 * function.
1325 * @io_request: This is the struct sci_base_request object which is not used in this
1326 * function.
1328 * This method is the ready operational substate start io handler for the
1329 * struct scic_sds_port object. This function incremetns the outstanding request
1330 * count for this port object. enum sci_status SCI_SUCCESS
1332 static enum sci_status scic_sds_port_ready_operational_substate_start_io_handler(
1333 struct scic_sds_port *port,
1334 struct scic_sds_remote_device *device,
1335 struct scic_sds_request *io_request)
1337 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
1339 scic_sds_port_increment_request_count(this_port);
1341 return SCI_SUCCESS;
1345 * ****************************************************************************
1346 * * READY SUBSTATE OPERATIONAL HANDLERS
1347 * **************************************************************************** */
1350 * scic_sds_port_ready_configuring_substate_add_phy_handler() -
1351 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1352 * object.
1354 * This is the default method for a port add phy request. It will report a
1355 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1357 static enum sci_status scic_sds_port_ready_configuring_substate_add_phy_handler(
1358 struct sci_base_port *port,
1359 struct sci_base_phy *phy)
1361 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
1362 struct scic_sds_phy *this_phy = (struct scic_sds_phy *)phy;
1363 enum sci_status status;
1365 status = scic_sds_port_set_phy(this_port, this_phy);
1367 if (status == SCI_SUCCESS) {
1368 scic_sds_port_general_link_up_handler(this_port, this_phy, true);
1371 * Re-enter the configuring state since this may be the last phy in
1372 * the port. */
1373 sci_base_state_machine_change_state(
1374 &this_port->ready_substate_machine,
1375 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1379 return status;
1383 * scic_sds_port_ready_configuring_substate_remove_phy_handler() -
1384 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1385 * object.
1387 * This is the default method for a port remove phy request. It will report a
1388 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1390 static enum sci_status scic_sds_port_ready_configuring_substate_remove_phy_handler(
1391 struct sci_base_port *port,
1392 struct sci_base_phy *phy)
1394 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
1395 struct scic_sds_phy *this_phy = (struct scic_sds_phy *)phy;
1396 enum sci_status status;
1398 status = scic_sds_port_clear_phy(this_port, this_phy);
1400 if (status == SCI_SUCCESS) {
1401 scic_sds_port_deactivate_phy(this_port, this_phy, true);
1404 * Re-enter the configuring state since this may be the last phy in
1405 * the port. */
1406 sci_base_state_machine_change_state(
1407 &this_port->ready_substate_machine,
1408 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1412 return status;
1416 * scic_sds_port_ready_configuring_substate_complete_io_handler() -
1417 * @port: This is the port that is being requested to complete the io request.
1418 * @device: This is the device on which the io is completing.
1420 * This method will decrement the outstanding request count for this port. If
1421 * the request count goes to 0 then the port can be reprogrammed with its new
1422 * phy data.
1424 static enum sci_status scic_sds_port_ready_configuring_substate_complete_io_handler(
1425 struct scic_sds_port *port,
1426 struct scic_sds_remote_device *device,
1427 struct scic_sds_request *io_request)
1429 scic_sds_port_decrement_request_count(port);
1431 if (port->started_request_count == 0) {
1432 sci_base_state_machine_change_state(
1433 &port->ready_substate_machine,
1434 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1438 return SCI_SUCCESS;
1441 static enum sci_status default_port_handler(struct sci_base_port *base_port, const char *func)
1443 struct scic_sds_port *sci_port;
1445 sci_port = container_of(base_port, typeof(*sci_port), parent);
1446 dev_warn(sciport_to_dev(sci_port),
1447 "%s: in wrong state: %d\n", func,
1448 sci_base_state_machine_get_state(&base_port->state_machine));
1449 return SCI_FAILURE_INVALID_STATE;
1452 static enum sci_status scic_sds_port_default_start_handler(struct sci_base_port *base_port)
1454 return default_port_handler(base_port, __func__);
1457 static enum sci_status scic_sds_port_default_stop_handler(struct sci_base_port *base_port)
1459 return default_port_handler(base_port, __func__);
1462 static enum sci_status scic_sds_port_default_destruct_handler(struct sci_base_port *base_port)
1464 return default_port_handler(base_port, __func__);
1467 static enum sci_status scic_sds_port_default_reset_handler(struct sci_base_port *base_port,
1468 u32 timeout)
1470 return default_port_handler(base_port, __func__);
1473 static enum sci_status scic_sds_port_default_add_phy_handler(struct sci_base_port *base_port,
1474 struct sci_base_phy *base_phy)
1476 return default_port_handler(base_port, __func__);
1479 static enum sci_status scic_sds_port_default_remove_phy_handler(struct sci_base_port *base_port,
1480 struct sci_base_phy *base_phy)
1482 return default_port_handler(base_port, __func__);
1486 * scic_sds_port_default_frame_handler
1487 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1488 * object.
1490 * This is the default method for a port unsolicited frame request. It will
1491 * report a warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE Is it even
1492 * possible to receive an unsolicited frame directed to a port object? It
1493 * seems possible if we implementing virtual functions but until then?
1495 static enum sci_status scic_sds_port_default_frame_handler(struct scic_sds_port *sci_port,
1496 u32 frame_index)
1498 struct scic_sds_controller *scic = scic_sds_port_get_controller(sci_port);
1500 default_port_handler(&sci_port->parent, __func__);
1501 scic_sds_controller_release_frame(scic, frame_index);
1503 return SCI_FAILURE_INVALID_STATE;
1506 static enum sci_status scic_sds_port_default_event_handler(struct scic_sds_port *sci_port,
1507 u32 event_code)
1509 return default_port_handler(&sci_port->parent, __func__);
1512 static void scic_sds_port_default_link_up_handler(struct scic_sds_port *sci_port,
1513 struct scic_sds_phy *sci_phy)
1515 default_port_handler(&sci_port->parent, __func__);
1518 static void scic_sds_port_default_link_down_handler(struct scic_sds_port *sci_port,
1519 struct scic_sds_phy *sci_phy)
1521 default_port_handler(&sci_port->parent, __func__);
1524 static enum sci_status scic_sds_port_default_start_io_handler(struct scic_sds_port *sci_port,
1525 struct scic_sds_remote_device *sci_dev,
1526 struct scic_sds_request *sci_req)
1528 return default_port_handler(&sci_port->parent, __func__);
1531 static enum sci_status scic_sds_port_default_complete_io_handler(struct scic_sds_port *sci_port,
1532 struct scic_sds_remote_device *sci_dev,
1533 struct scic_sds_request *sci_req)
1535 return default_port_handler(&sci_port->parent, __func__);
1540 static struct scic_sds_port_state_handler
1541 scic_sds_port_ready_substate_handler_table[SCIC_SDS_PORT_READY_MAX_SUBSTATES] =
1543 /* SCIC_SDS_PORT_READY_SUBSTATE_WAITING */
1546 scic_sds_port_default_start_handler,
1547 scic_sds_port_ready_substate_stop_handler,
1548 scic_sds_port_default_destruct_handler,
1549 scic_sds_port_default_reset_handler,
1550 scic_sds_port_ready_substate_add_phy_handler,
1551 scic_sds_port_default_remove_phy_handler
1553 scic_sds_port_default_frame_handler,
1554 scic_sds_port_default_event_handler,
1555 scic_sds_port_ready_waiting_substate_link_up_handler,
1556 scic_sds_port_default_link_down_handler,
1557 scic_sds_port_ready_waiting_substate_start_io_handler,
1558 scic_sds_port_ready_substate_complete_io_handler,
1560 /* SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL */
1563 scic_sds_port_default_start_handler,
1564 scic_sds_port_ready_substate_stop_handler,
1565 scic_sds_port_default_destruct_handler,
1566 scic_sds_port_ready_operational_substate_reset_handler,
1567 scic_sds_port_ready_substate_add_phy_handler,
1568 scic_sds_port_ready_substate_remove_phy_handler
1570 scic_sds_port_default_frame_handler,
1571 scic_sds_port_default_event_handler,
1572 scic_sds_port_ready_operational_substate_link_up_handler,
1573 scic_sds_port_ready_operational_substate_link_down_handler,
1574 scic_sds_port_ready_operational_substate_start_io_handler,
1575 scic_sds_port_ready_substate_complete_io_handler
1577 /* SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING */
1580 scic_sds_port_default_start_handler,
1581 scic_sds_port_ready_substate_stop_handler,
1582 scic_sds_port_default_destruct_handler,
1583 scic_sds_port_default_reset_handler,
1584 scic_sds_port_ready_configuring_substate_add_phy_handler,
1585 scic_sds_port_ready_configuring_substate_remove_phy_handler
1587 scic_sds_port_default_frame_handler,
1588 scic_sds_port_default_event_handler,
1589 scic_sds_port_default_link_up_handler,
1590 scic_sds_port_default_link_down_handler,
1591 scic_sds_port_default_start_io_handler,
1592 scic_sds_port_ready_configuring_substate_complete_io_handler
1597 * scic_sds_port_set_ready_state_handlers() -
1599 * This macro sets the port ready substate handlers.
1601 #define scic_sds_port_set_ready_state_handlers(port, state_id) \
1602 scic_sds_port_set_state_handlers(\
1603 port, &scic_sds_port_ready_substate_handler_table[(state_id)] \
1607 * ******************************************************************************
1608 * * PORT STATE PRIVATE METHODS
1609 * ****************************************************************************** */
1613 * @this_port: This is the struct scic_sds_port object to suspend.
1615 * This method will susped the port task scheduler for this port object. none
1617 static void
1618 scic_sds_port_suspend_port_task_scheduler(struct scic_sds_port *port)
1620 u32 pts_control_value;
1622 pts_control_value = readl(&port->port_task_scheduler_registers->control);
1623 pts_control_value |= SCU_PTSxCR_GEN_BIT(SUSPEND);
1624 writel(pts_control_value, &port->port_task_scheduler_registers->control);
1628 * scic_sds_port_post_dummy_request() - post dummy/workaround request
1629 * @sci_port: port to post task
1631 * Prevent the hardware scheduler from posting new requests to the front
1632 * of the scheduler queue causing a starvation problem for currently
1633 * ongoing requests.
1636 static void scic_sds_port_post_dummy_request(struct scic_sds_port *sci_port)
1638 u32 command;
1639 struct scu_task_context *task_context;
1640 struct scic_sds_controller *scic = sci_port->owning_controller;
1641 u16 tci = sci_port->reserved_tci;
1643 task_context = scic_sds_controller_get_task_context_buffer(scic, tci);
1645 task_context->abort = 0;
1647 command = SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
1648 sci_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
1649 tci;
1651 scic_sds_controller_post_request(scic, command);
1655 * This routine will abort the dummy request. This will alow the hardware to
1656 * power down parts of the silicon to save power.
1658 * @sci_port: The port on which the task must be aborted.
1661 static void scic_sds_port_abort_dummy_request(struct scic_sds_port *sci_port)
1663 struct scic_sds_controller *scic = sci_port->owning_controller;
1664 u16 tci = sci_port->reserved_tci;
1665 struct scu_task_context *tc;
1666 u32 command;
1668 tc = scic_sds_controller_get_task_context_buffer(scic, tci);
1670 tc->abort = 1;
1672 command = SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT |
1673 sci_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
1674 tci;
1676 scic_sds_controller_post_request(scic, command);
1681 * @this_port: This is the struct scic_sds_port object to resume.
1683 * This method will resume the port task scheduler for this port object. none
1685 static void
1686 scic_sds_port_resume_port_task_scheduler(struct scic_sds_port *port)
1688 u32 pts_control_value;
1690 pts_control_value = readl(&port->port_task_scheduler_registers->control);
1691 pts_control_value &= ~SCU_PTSxCR_GEN_BIT(SUSPEND);
1692 writel(pts_control_value, &port->port_task_scheduler_registers->control);
1696 * ******************************************************************************
1697 * * PORT READY SUBSTATE METHODS
1698 * ****************************************************************************** */
1702 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
1704 * This method will perform the actions required by the struct scic_sds_port on
1705 * entering the SCIC_SDS_PORT_READY_SUBSTATE_WAITING. This function checks the
1706 * port for any ready phys. If there is at least one phy in a ready state then
1707 * the port transitions to the ready operational substate. none
1709 static void scic_sds_port_ready_substate_waiting_enter(
1710 struct sci_base_object *object)
1712 struct scic_sds_port *this_port = (struct scic_sds_port *)object;
1714 scic_sds_port_set_ready_state_handlers(
1715 this_port, SCIC_SDS_PORT_READY_SUBSTATE_WAITING
1718 scic_sds_port_suspend_port_task_scheduler(this_port);
1720 this_port->not_ready_reason = SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS;
1722 if (this_port->active_phy_mask != 0) {
1723 /* At least one of the phys on the port is ready */
1724 sci_base_state_machine_change_state(
1725 &this_port->ready_substate_machine,
1726 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1733 * @object: This is the struct sci_base_object which is cast to a
1734 * struct scic_sds_port object.
1736 * This function will perform the actions required by the struct scic_sds_port
1737 * on entering the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function sets
1738 * the state handlers for the port object, notifies the SCI User that the port
1739 * is ready, and resumes port operations. none
1741 static void scic_sds_port_ready_substate_operational_enter(
1742 struct sci_base_object *object)
1744 u32 index;
1745 struct scic_sds_port *sci_port = (struct scic_sds_port *)object;
1746 struct scic_sds_controller *scic =
1747 scic_sds_port_get_controller(sci_port);
1748 struct isci_host *ihost = sci_object_get_association(scic);
1749 struct isci_port *iport = sci_object_get_association(sci_port);
1751 scic_sds_port_set_ready_state_handlers(
1752 sci_port,
1753 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
1755 isci_port_ready(ihost, iport);
1757 for (index = 0; index < SCI_MAX_PHYS; index++) {
1758 if (sci_port->phy_table[index]) {
1759 writel(sci_port->physical_port_index,
1760 &sci_port->port_pe_configuration_register[
1761 sci_port->phy_table[index]->phy_index]);
1765 scic_sds_port_update_viit_entry(sci_port);
1767 scic_sds_port_resume_port_task_scheduler(sci_port);
1770 * Post the dummy task for the port so the hardware can schedule
1771 * io correctly
1773 scic_sds_port_post_dummy_request(sci_port);
1778 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
1780 * This method will perform the actions required by the struct scic_sds_port on
1781 * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
1782 * the port not ready and suspends the port task scheduler. none
1784 static void scic_sds_port_ready_substate_operational_exit(
1785 struct sci_base_object *object)
1787 struct scic_sds_port *sci_port = (struct scic_sds_port *)object;
1788 struct scic_sds_controller *scic =
1789 scic_sds_port_get_controller(sci_port);
1790 struct isci_host *ihost = sci_object_get_association(scic);
1791 struct isci_port *iport = sci_object_get_association(sci_port);
1794 * Kill the dummy task for this port if it has not yet posted
1795 * the hardware will treat this as a NOP and just return abort
1796 * complete.
1798 scic_sds_port_abort_dummy_request(sci_port);
1800 isci_port_not_ready(ihost, iport);
1804 * ******************************************************************************
1805 * * PORT READY CONFIGURING METHODS
1806 * ****************************************************************************** */
1809 * scic_sds_port_ready_substate_configuring_enter() -
1810 * @object: This is the struct sci_base_object which is cast to a
1811 * struct scic_sds_port object.
1813 * This method will perform the actions required by the struct scic_sds_port on
1814 * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
1815 * the port not ready and suspends the port task scheduler. none
1817 static void scic_sds_port_ready_substate_configuring_enter(
1818 struct sci_base_object *object)
1820 struct scic_sds_port *sci_port = (struct scic_sds_port *)object;
1821 struct scic_sds_controller *scic =
1822 scic_sds_port_get_controller(sci_port);
1823 struct isci_host *ihost = sci_object_get_association(scic);
1824 struct isci_port *iport = sci_object_get_association(sci_port);
1826 scic_sds_port_set_ready_state_handlers(
1827 sci_port,
1828 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
1830 if (sci_port->active_phy_mask == 0) {
1831 isci_port_not_ready(ihost, iport);
1833 sci_base_state_machine_change_state(
1834 &sci_port->ready_substate_machine,
1835 SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
1836 } else if (sci_port->started_request_count == 0)
1837 sci_base_state_machine_change_state(
1838 &sci_port->ready_substate_machine,
1839 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
1842 static void scic_sds_port_ready_substate_configuring_exit(
1843 struct sci_base_object *object)
1845 struct scic_sds_port *this_port = (struct scic_sds_port *)object;
1847 scic_sds_port_suspend_port_task_scheduler(this_port);
1850 /* --------------------------------------------------------------------------- */
1852 static const struct sci_base_state scic_sds_port_ready_substate_table[] = {
1853 [SCIC_SDS_PORT_READY_SUBSTATE_WAITING] = {
1854 .enter_state = scic_sds_port_ready_substate_waiting_enter,
1856 [SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL] = {
1857 .enter_state = scic_sds_port_ready_substate_operational_enter,
1858 .exit_state = scic_sds_port_ready_substate_operational_exit
1860 [SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING] = {
1861 .enter_state = scic_sds_port_ready_substate_configuring_enter,
1862 .exit_state = scic_sds_port_ready_substate_configuring_exit
1868 * @port: This is the struct scic_sds_port object on which the io request count will
1869 * be decremented.
1870 * @device: This is the struct scic_sds_remote_device object to which the io request
1871 * is being directed. This parameter is not required to complete this
1872 * operation.
1873 * @io_request: This is the request that is being completed on this port
1874 * object. This parameter is not required to complete this operation.
1876 * This is a general complete io request handler for the struct scic_sds_port object.
1877 * enum sci_status SCI_SUCCESS
1879 static enum sci_status scic_sds_port_general_complete_io_handler(
1880 struct scic_sds_port *port,
1881 struct scic_sds_remote_device *device,
1882 struct scic_sds_request *io_request)
1884 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
1886 scic_sds_port_decrement_request_count(this_port);
1888 return SCI_SUCCESS;
1892 * scic_sds_port_stopped_state_start_handler() - stop a port from "started"
1894 * @port: This is the struct sci_base_port object which is cast into a
1895 * struct scic_sds_port object.
1897 * This function takes the struct scic_sds_port from a stopped state and
1898 * attempts to start it. To start a port it must have no assiged devices and
1899 * it must have at least one phy assigned to it. If those conditions are
1900 * met then the port can transition to the ready state.
1901 * enum sci_status
1902 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
1903 * This struct scic_sds_port object could not be started because the port
1904 * configuration is not valid.
1905 * SCI_SUCCESS
1906 * the start request is successful and the struct scic_sds_port object
1907 * has transitioned to the SCI_BASE_PORT_STATE_READY.
1909 static enum sci_status
1910 scic_sds_port_stopped_state_start_handler(struct sci_base_port *base_port)
1912 struct scic_sds_port *sci_port =
1913 container_of(base_port, typeof(*sci_port), parent);
1914 struct scic_sds_controller *scic = sci_port->owning_controller;
1915 struct isci_host *ihost = sci_object_get_association(scic);
1916 enum sci_status status = SCI_SUCCESS;
1917 u32 phy_mask;
1919 if (sci_port->assigned_device_count > 0) {
1921 * @todo This is a start failure operation because
1922 * there are still devices assigned to this port.
1923 * There must be no devices assigned to a port on a
1924 * start operation.
1926 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
1929 sci_port->timer_handle =
1930 isci_timer_create(ihost,
1931 sci_port,
1932 scic_sds_port_timeout_handler);
1934 if (!sci_port->timer_handle)
1935 return SCI_FAILURE_INSUFFICIENT_RESOURCES;
1937 if (sci_port->reserved_rni == SCU_DUMMY_INDEX) {
1938 u16 rni = scic_sds_remote_node_table_allocate_remote_node(
1939 &scic->available_remote_nodes, 1);
1941 if (rni != SCU_DUMMY_INDEX)
1942 scic_sds_port_construct_dummy_rnc(sci_port, rni);
1943 else
1944 status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
1945 sci_port->reserved_rni = rni;
1948 if (sci_port->reserved_tci == SCU_DUMMY_INDEX) {
1949 /* Allocate a TCI and remove the sequence nibble */
1950 u16 tci = scic_controller_allocate_io_tag(scic);
1952 if (tci != SCU_DUMMY_INDEX)
1953 scic_sds_port_construct_dummy_task(sci_port, tci);
1954 else
1955 status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
1956 sci_port->reserved_tci = tci;
1959 if (status == SCI_SUCCESS) {
1960 phy_mask = scic_sds_port_get_phys(sci_port);
1963 * There are one or more phys assigned to this port. Make sure
1964 * the port's phy mask is in fact legal and supported by the
1965 * silicon.
1967 if (scic_sds_port_is_phy_mask_valid(sci_port, phy_mask) == true) {
1968 sci_base_state_machine_change_state(&base_port->state_machine,
1969 SCI_BASE_PORT_STATE_READY);
1971 return SCI_SUCCESS;
1972 } else
1973 status = SCI_FAILURE;
1976 if (status != SCI_SUCCESS)
1977 scic_sds_port_destroy_dummy_resources(sci_port);
1979 return status;
1984 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1985 * object.
1987 * This method takes the struct scic_sds_port that is in a stopped state and handles a
1988 * stop request. This function takes no action. enum sci_status SCI_SUCCESS the
1989 * stop request is successful as the struct scic_sds_port object is already stopped.
1991 static enum sci_status scic_sds_port_stopped_state_stop_handler(
1992 struct sci_base_port *port)
1994 /* We are already stopped so there is nothing to do here */
1995 return SCI_SUCCESS;
2000 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2001 * object.
2003 * This method takes the struct scic_sds_port that is in a stopped state and handles
2004 * the destruct request. The stopped state is the only state in which the
2005 * struct scic_sds_port can be destroyed. This function causes the port object to
2006 * transition to the SCI_BASE_PORT_STATE_FINAL. enum sci_status SCI_SUCCESS
2008 static enum sci_status scic_sds_port_stopped_state_destruct_handler(
2009 struct sci_base_port *port)
2011 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
2013 sci_base_state_machine_stop(&this_port->parent.state_machine);
2015 return SCI_SUCCESS;
2020 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2021 * object.
2022 * @phy: This is the struct sci_base_phy object which is cast into a struct scic_sds_phy
2023 * object.
2025 * This method takes the struct scic_sds_port that is in a stopped state and handles
2026 * the add phy request. In MPC mode the only time a phy can be added to a port
2027 * is in the SCI_BASE_PORT_STATE_STOPPED. enum sci_status
2028 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION is returned when the phy can not
2029 * be added to the port. SCI_SUCCESS if the phy is added to the port.
2031 static enum sci_status scic_sds_port_stopped_state_add_phy_handler(
2032 struct sci_base_port *port,
2033 struct sci_base_phy *phy)
2035 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
2036 struct scic_sds_phy *this_phy = (struct scic_sds_phy *)phy;
2037 struct sci_sas_address port_sas_address;
2039 /* Read the port assigned SAS Address if there is one */
2040 scic_sds_port_get_sas_address(this_port, &port_sas_address);
2042 if (port_sas_address.high != 0 && port_sas_address.low != 0) {
2043 struct sci_sas_address phy_sas_address;
2046 * Make sure that the PHY SAS Address matches the SAS Address
2047 * for this port. */
2048 scic_sds_phy_get_sas_address(this_phy, &phy_sas_address);
2050 if (
2051 (port_sas_address.high != phy_sas_address.high)
2052 || (port_sas_address.low != phy_sas_address.low)
2054 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
2058 return scic_sds_port_set_phy(this_port, this_phy);
2064 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2065 * object.
2066 * @phy: This is the struct sci_base_phy object which is cast into a struct scic_sds_phy
2067 * object.
2069 * This method takes the struct scic_sds_port that is in a stopped state and handles
2070 * the remove phy request. In MPC mode the only time a phy can be removed from
2071 * a port is in the SCI_BASE_PORT_STATE_STOPPED. enum sci_status
2072 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION is returned when the phy can not
2073 * be added to the port. SCI_SUCCESS if the phy is added to the port.
2075 static enum sci_status scic_sds_port_stopped_state_remove_phy_handler(
2076 struct sci_base_port *port,
2077 struct sci_base_phy *phy)
2079 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
2080 struct scic_sds_phy *this_phy = (struct scic_sds_phy *)phy;
2082 return scic_sds_port_clear_phy(this_port, this_phy);
2086 * ****************************************************************************
2087 * * READY STATE HANDLERS
2088 * **************************************************************************** */
2091 * ****************************************************************************
2092 * * RESETTING STATE HANDLERS
2093 * **************************************************************************** */
2096 * ****************************************************************************
2097 * * STOPPING STATE HANDLERS
2098 * **************************************************************************** */
2102 * @port: This is the struct scic_sds_port object on which the io request count will
2103 * be decremented.
2104 * @device: This is the struct scic_sds_remote_device object to which the io request
2105 * is being directed. This parameter is not required to complete this
2106 * operation.
2107 * @io_request: This is the request that is being completed on this port
2108 * object. This parameter is not required to complete this operation.
2110 * This method takes the struct scic_sds_port that is in a stopping state and handles
2111 * the complete io request. Should the request count reach 0 then the port
2112 * object will transition to the stopped state. enum sci_status SCI_SUCCESS
2114 static enum sci_status scic_sds_port_stopping_state_complete_io_handler(
2115 struct scic_sds_port *sci_port,
2116 struct scic_sds_remote_device *device,
2117 struct scic_sds_request *io_request)
2119 scic_sds_port_decrement_request_count(sci_port);
2121 if (sci_port->started_request_count == 0) {
2122 sci_base_state_machine_change_state(&sci_port->parent.state_machine,
2123 SCI_BASE_PORT_STATE_STOPPED);
2126 return SCI_SUCCESS;
2130 * ****************************************************************************
2131 * * RESETTING STATE HANDLERS
2132 * **************************************************************************** */
2136 * @port: This is the port object which is being requested to stop.
2138 * This method will stop a failed port. This causes a transition to the
2139 * stopping state. enum sci_status SCI_SUCCESS
2141 static enum sci_status scic_sds_port_reset_state_stop_handler(
2142 struct sci_base_port *port)
2144 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
2146 sci_base_state_machine_change_state(
2147 &this_port->parent.state_machine,
2148 SCI_BASE_PORT_STATE_STOPPING
2151 return SCI_SUCCESS;
2156 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2157 * object.
2159 * This method will transition a failed port to its ready state. The port
2160 * failed because a hard reset request timed out but at some time later one or
2161 * more phys in the port became ready. enum sci_status SCI_SUCCESS
2163 static void scic_sds_port_reset_state_link_up_handler(
2164 struct scic_sds_port *this_port,
2165 struct scic_sds_phy *phy)
2168 * / @todo We should make sure that the phy that has gone link up is the same
2169 * / one on which we sent the reset. It is possible that the phy on
2170 * / which we sent the reset is not the one that has gone link up and we
2171 * / want to make sure that phy being reset comes back. Consider the
2172 * / case where a reset is sent but before the hardware processes the
2173 * / reset it get a link up on the port because of a hot plug event.
2174 * / because of the reset request this phy will go link down almost
2175 * / immediately. */
2178 * In the resetting state we don't notify the user regarding
2179 * link up and link down notifications. */
2180 scic_sds_port_general_link_up_handler(this_port, phy, false);
2185 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2186 * object.
2188 * This method process link down notifications that occur during a port reset
2189 * operation. Link downs can occur during the reset operation. enum sci_status
2190 * SCI_SUCCESS
2192 static void scic_sds_port_reset_state_link_down_handler(
2193 struct scic_sds_port *this_port,
2194 struct scic_sds_phy *phy)
2197 * In the resetting state we don't notify the user regarding
2198 * link up and link down notifications. */
2199 scic_sds_port_deactivate_phy(this_port, phy, false);
2202 static struct scic_sds_port_state_handler
2203 scic_sds_port_state_handler_table[SCI_BASE_PORT_MAX_STATES] =
2205 /* SCI_BASE_PORT_STATE_STOPPED */
2208 scic_sds_port_stopped_state_start_handler,
2209 scic_sds_port_stopped_state_stop_handler,
2210 scic_sds_port_stopped_state_destruct_handler,
2211 scic_sds_port_default_reset_handler,
2212 scic_sds_port_stopped_state_add_phy_handler,
2213 scic_sds_port_stopped_state_remove_phy_handler
2215 scic_sds_port_default_frame_handler,
2216 scic_sds_port_default_event_handler,
2217 scic_sds_port_default_link_up_handler,
2218 scic_sds_port_default_link_down_handler,
2219 scic_sds_port_default_start_io_handler,
2220 scic_sds_port_default_complete_io_handler
2222 /* SCI_BASE_PORT_STATE_STOPPING */
2225 scic_sds_port_default_start_handler,
2226 scic_sds_port_default_stop_handler,
2227 scic_sds_port_default_destruct_handler,
2228 scic_sds_port_default_reset_handler,
2229 scic_sds_port_default_add_phy_handler,
2230 scic_sds_port_default_remove_phy_handler
2232 scic_sds_port_default_frame_handler,
2233 scic_sds_port_default_event_handler,
2234 scic_sds_port_default_link_up_handler,
2235 scic_sds_port_default_link_down_handler,
2236 scic_sds_port_default_start_io_handler,
2237 scic_sds_port_stopping_state_complete_io_handler
2239 /* SCI_BASE_PORT_STATE_READY */
2242 scic_sds_port_default_start_handler,
2243 scic_sds_port_default_stop_handler,
2244 scic_sds_port_default_destruct_handler,
2245 scic_sds_port_default_reset_handler,
2246 scic_sds_port_default_add_phy_handler,
2247 scic_sds_port_default_remove_phy_handler
2249 scic_sds_port_default_frame_handler,
2250 scic_sds_port_default_event_handler,
2251 scic_sds_port_default_link_up_handler,
2252 scic_sds_port_default_link_down_handler,
2253 scic_sds_port_default_start_io_handler,
2254 scic_sds_port_general_complete_io_handler
2256 /* SCI_BASE_PORT_STATE_RESETTING */
2259 scic_sds_port_default_start_handler,
2260 scic_sds_port_reset_state_stop_handler,
2261 scic_sds_port_default_destruct_handler,
2262 scic_sds_port_default_reset_handler,
2263 scic_sds_port_default_add_phy_handler,
2264 scic_sds_port_default_remove_phy_handler
2266 scic_sds_port_default_frame_handler,
2267 scic_sds_port_default_event_handler,
2268 scic_sds_port_reset_state_link_up_handler,
2269 scic_sds_port_reset_state_link_down_handler,
2270 scic_sds_port_default_start_io_handler,
2271 scic_sds_port_general_complete_io_handler
2273 /* SCI_BASE_PORT_STATE_FAILED */
2276 scic_sds_port_default_start_handler,
2277 scic_sds_port_default_stop_handler,
2278 scic_sds_port_default_destruct_handler,
2279 scic_sds_port_default_reset_handler,
2280 scic_sds_port_default_add_phy_handler,
2281 scic_sds_port_default_remove_phy_handler
2283 scic_sds_port_default_frame_handler,
2284 scic_sds_port_default_event_handler,
2285 scic_sds_port_default_link_up_handler,
2286 scic_sds_port_default_link_down_handler,
2287 scic_sds_port_default_start_io_handler,
2288 scic_sds_port_general_complete_io_handler
2293 * ******************************************************************************
2294 * * PORT STATE PRIVATE METHODS
2295 * ****************************************************************************** */
2299 * @this_port: This is the port object which to suspend.
2301 * This method will enable the SCU Port Task Scheduler for this port object but
2302 * will leave the port task scheduler in a suspended state. none
2304 static void
2305 scic_sds_port_enable_port_task_scheduler(struct scic_sds_port *port)
2307 u32 pts_control_value;
2309 pts_control_value = readl(&port->port_task_scheduler_registers->control);
2310 pts_control_value |= SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND);
2311 writel(pts_control_value, &port->port_task_scheduler_registers->control);
2316 * @this_port: This is the port object which to resume.
2318 * This method will disable the SCU port task scheduler for this port object.
2319 * none
2321 static void
2322 scic_sds_port_disable_port_task_scheduler(struct scic_sds_port *port)
2324 u32 pts_control_value;
2326 pts_control_value = readl(&port->port_task_scheduler_registers->control);
2327 pts_control_value &=
2328 ~(SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND));
2329 writel(pts_control_value, &port->port_task_scheduler_registers->control);
2332 static void scic_sds_port_post_dummy_remote_node(struct scic_sds_port *sci_port)
2334 struct scic_sds_controller *scic = sci_port->owning_controller;
2335 u8 phys_index = sci_port->physical_port_index;
2336 union scu_remote_node_context *rnc;
2337 u16 rni = sci_port->reserved_rni;
2338 u32 command;
2340 rnc = &scic->remote_node_context_table[rni];
2341 rnc->ssp.is_valid = true;
2343 command = SCU_CONTEXT_COMMAND_POST_RNC_32 |
2344 phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
2346 scic_sds_controller_post_request(scic, command);
2348 /* ensure hardware has seen the post rnc command and give it
2349 * ample time to act before sending the suspend
2351 readl(&scic->smu_registers->interrupt_status); /* flush */
2352 udelay(10);
2354 command = SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX |
2355 phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
2357 scic_sds_controller_post_request(scic, command);
2360 static void scic_sds_port_invalidate_dummy_remote_node(struct scic_sds_port *sci_port)
2362 struct scic_sds_controller *scic = sci_port->owning_controller;
2363 u8 phys_index = sci_port->physical_port_index;
2364 union scu_remote_node_context *rnc;
2365 u16 rni = sci_port->reserved_rni;
2366 u32 command;
2368 rnc = &scic->remote_node_context_table[rni];
2370 rnc->ssp.is_valid = false;
2372 /* ensure the preceding tc abort request has reached the
2373 * controller and give it ample time to act before posting the rnc
2374 * invalidate
2376 readl(&scic->smu_registers->interrupt_status); /* flush */
2377 udelay(10);
2379 command = SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE |
2380 phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
2382 scic_sds_controller_post_request(scic, command);
2386 * ******************************************************************************
2387 * * PORT STATE METHODS
2388 * ****************************************************************************** */
2392 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2394 * This method will perform the actions required by the struct scic_sds_port on
2395 * entering the SCI_BASE_PORT_STATE_STOPPED. This function sets the stopped
2396 * state handlers for the struct scic_sds_port object and disables the port task
2397 * scheduler in the hardware. none
2399 static void scic_sds_port_stopped_state_enter(
2400 struct sci_base_object *object)
2402 struct scic_sds_port *this_port;
2404 this_port = (struct scic_sds_port *)object;
2406 scic_sds_port_set_base_state_handlers(
2407 this_port, SCI_BASE_PORT_STATE_STOPPED
2410 if (
2411 SCI_BASE_PORT_STATE_STOPPING
2412 == this_port->parent.state_machine.previous_state_id
2415 * If we enter this state becasuse of a request to stop
2416 * the port then we want to disable the hardwares port
2417 * task scheduler. */
2418 scic_sds_port_disable_port_task_scheduler(this_port);
2424 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2426 * This method will perform the actions required by the struct scic_sds_port on
2427 * exiting the SCI_BASE_STATE_STOPPED. This function enables the SCU hardware
2428 * port task scheduler. none
2430 static void scic_sds_port_stopped_state_exit(
2431 struct sci_base_object *object)
2433 struct scic_sds_port *this_port;
2435 this_port = (struct scic_sds_port *)object;
2437 /* Enable and suspend the port task scheduler */
2438 scic_sds_port_enable_port_task_scheduler(this_port);
2442 * scic_sds_port_ready_state_enter -
2443 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2445 * This method will perform the actions required by the struct scic_sds_port on
2446 * entering the SCI_BASE_PORT_STATE_READY. This function sets the ready state
2447 * handlers for the struct scic_sds_port object, reports the port object as
2448 * not ready and starts the ready substate machine. none
2450 static void scic_sds_port_ready_state_enter(struct sci_base_object *object)
2452 struct scic_sds_controller *scic;
2453 struct scic_sds_port *sci_port;
2454 struct isci_port *iport;
2455 struct isci_host *ihost;
2456 u32 prev_state;
2458 sci_port = container_of(object, typeof(*sci_port), parent.parent);
2459 scic = scic_sds_port_get_controller(sci_port);
2460 ihost = sci_object_get_association(scic);
2461 iport = sci_object_get_association(sci_port);
2463 /* Put the ready state handlers in place though they will not be there long */
2464 scic_sds_port_set_base_state_handlers(sci_port, SCI_BASE_PORT_STATE_READY);
2466 prev_state = sci_port->parent.state_machine.previous_state_id;
2467 if (prev_state == SCI_BASE_PORT_STATE_RESETTING)
2468 isci_port_hard_reset_complete(iport, SCI_SUCCESS);
2469 else
2470 isci_port_not_ready(ihost, iport);
2472 /* Post and suspend the dummy remote node context for this port. */
2473 scic_sds_port_post_dummy_remote_node(sci_port);
2475 /* Start the ready substate machine */
2476 sci_base_state_machine_start(&sci_port->ready_substate_machine);
2479 static void scic_sds_port_ready_state_exit(struct sci_base_object *object)
2481 struct scic_sds_port *sci_port;
2483 sci_port = container_of(object, typeof(*sci_port), parent.parent);
2484 sci_base_state_machine_stop(&sci_port->ready_substate_machine);
2485 scic_sds_port_invalidate_dummy_remote_node(sci_port);
2490 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2492 * This method will perform the actions required by the struct scic_sds_port on
2493 * entering the SCI_BASE_PORT_STATE_RESETTING. This function sets the resetting
2494 * state handlers for the struct scic_sds_port object. none
2496 static void scic_sds_port_resetting_state_enter(
2497 struct sci_base_object *object)
2499 struct scic_sds_port *this_port;
2501 this_port = (struct scic_sds_port *)object;
2503 scic_sds_port_set_base_state_handlers(
2504 this_port, SCI_BASE_PORT_STATE_RESETTING
2510 * @object: This is the struct sci_base_object which is cast to a
2511 * struct scic_sds_port object.
2513 * This function will perform the actions required by the
2514 * struct scic_sds_port on
2515 * exiting the SCI_BASE_STATE_RESETTING. This function does nothing. none
2517 static inline void scic_sds_port_resetting_state_exit(
2518 struct sci_base_object *object)
2520 struct scic_sds_port *sci_port = (struct scic_sds_port *)object;
2522 isci_timer_stop(sci_port->timer_handle);
2527 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2529 * This method will perform the actions required by the struct scic_sds_port on
2530 * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
2531 * state handlers for the struct scic_sds_port object. none
2533 static void scic_sds_port_stopping_state_enter(
2534 struct sci_base_object *object)
2536 struct scic_sds_port *this_port;
2538 this_port = (struct scic_sds_port *)object;
2540 scic_sds_port_set_base_state_handlers(
2541 this_port, SCI_BASE_PORT_STATE_STOPPING
2547 * @object: This is the struct sci_base_object which is cast to a
2548 * struct scic_sds_port object.
2550 * This function will perform the actions required by the
2551 * struct scic_sds_port on
2552 * exiting the SCI_BASE_STATE_STOPPING. This function does nothing. none
2554 static inline void
2555 scic_sds_port_stopping_state_exit(struct sci_base_object *object)
2557 struct scic_sds_port *sci_port = (struct scic_sds_port *)object;
2559 isci_timer_stop(sci_port->timer_handle);
2561 scic_sds_port_destroy_dummy_resources(sci_port);
2566 * @object: This is the struct sci_base_object which is cast to a
2567 * struct scic_sds_port object.
2569 * This function will perform the actions required by the
2570 * struct scic_sds_port on
2571 * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
2572 * state handlers for the struct scic_sds_port object. none
2574 static void scic_sds_port_failed_state_enter(struct sci_base_object *object)
2576 struct scic_sds_port *sci_port = (struct scic_sds_port *)object;
2577 struct isci_port *iport = sci_object_get_association(sci_port);
2579 scic_sds_port_set_base_state_handlers(sci_port,
2580 SCI_BASE_PORT_STATE_FAILED);
2582 isci_port_hard_reset_complete(iport, SCI_FAILURE_TIMEOUT);
2585 /* --------------------------------------------------------------------------- */
2587 static const struct sci_base_state scic_sds_port_state_table[] = {
2588 [SCI_BASE_PORT_STATE_STOPPED] = {
2589 .enter_state = scic_sds_port_stopped_state_enter,
2590 .exit_state = scic_sds_port_stopped_state_exit
2592 [SCI_BASE_PORT_STATE_STOPPING] = {
2593 .enter_state = scic_sds_port_stopping_state_enter,
2594 .exit_state = scic_sds_port_stopping_state_exit
2596 [SCI_BASE_PORT_STATE_READY] = {
2597 .enter_state = scic_sds_port_ready_state_enter,
2598 .exit_state = scic_sds_port_ready_state_exit
2600 [SCI_BASE_PORT_STATE_RESETTING] = {
2601 .enter_state = scic_sds_port_resetting_state_enter,
2602 .exit_state = scic_sds_port_resetting_state_exit
2604 [SCI_BASE_PORT_STATE_FAILED] = {
2605 .enter_state = scic_sds_port_failed_state_enter,
2609 void scic_sds_port_construct(struct scic_sds_port *sci_port, u8 port_index,
2610 struct scic_sds_controller *scic)
2612 u32 index;
2614 sci_base_port_construct(&sci_port->parent, scic_sds_port_state_table);
2616 sci_base_state_machine_construct(&sci_port->ready_substate_machine,
2617 &sci_port->parent.parent,
2618 scic_sds_port_ready_substate_table,
2619 SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
2621 sci_port->logical_port_index = SCIC_SDS_DUMMY_PORT;
2622 sci_port->physical_port_index = port_index;
2623 sci_port->active_phy_mask = 0;
2625 sci_port->owning_controller = scic;
2627 sci_port->started_request_count = 0;
2628 sci_port->assigned_device_count = 0;
2630 sci_port->reserved_rni = SCU_DUMMY_INDEX;
2631 sci_port->reserved_tci = SCU_DUMMY_INDEX;
2633 sci_port->timer_handle = NULL;
2635 sci_port->port_task_scheduler_registers = NULL;
2637 for (index = 0; index < SCI_MAX_PHYS; index++)
2638 sci_port->phy_table[index] = NULL;