isci: replace this_* and the_* variables with more meaningful names
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / scsi / isci / core / scic_sds_port.c
bloba8d7e51bdf7b9229b160f526da32f81855a29511
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 "scic_controller.h"
58 #include "scic_phy.h"
59 #include "scic_port.h"
60 #include "scic_sds_controller.h"
61 #include "scic_sds_phy.h"
62 #include "scic_sds_port.h"
63 #include "scic_sds_remote_device.h"
64 #include "scic_sds_remote_node_context.h"
65 #include "scic_sds_request.h"
66 #include "sci_environment.h"
67 #include "scu_registers.h"
69 #define SCIC_SDS_PORT_MIN_TIMER_COUNT (SCI_MAX_PORTS)
70 #define SCIC_SDS_PORT_MAX_TIMER_COUNT (SCI_MAX_PORTS)
72 #define SCIC_SDS_PORT_HARD_RESET_TIMEOUT (1000)
73 #define SCU_DUMMY_INDEX (0xFFFF)
76 /**
78 * @sci_port: This is the port object to which the phy is being assigned.
79 * @phy_index: This is the phy index that is being assigned to the port.
81 * This method will return a true value if the specified phy can be assigned to
82 * this port The following is a list of phys for each port that are allowed: -
83 * Port 0 - 3 2 1 0 - Port 1 - 1 - Port 2 - 3 2 - Port 3 - 3 This method
84 * doesn't preclude all configurations. It merely ensures that a phy is part
85 * of the allowable set of phy identifiers for that port. For example, one
86 * could assign phy 3 to port 0 and no other phys. Please refer to
87 * scic_sds_port_is_phy_mask_valid() for information regarding whether the
88 * phy_mask for a port can be supported. bool true if this is a valid phy
89 * assignment for the port false if this is not a valid phy assignment for the
90 * port
92 bool scic_sds_port_is_valid_phy_assignment(
93 struct scic_sds_port *sci_port,
94 u32 phy_index)
96 /* Initialize to invalid value. */
97 u32 existing_phy_index = SCI_MAX_PHYS;
98 u32 index;
100 if ((sci_port->physical_port_index == 1) && (phy_index != 1)) {
101 return false;
104 if (sci_port->physical_port_index == 3 && phy_index != 3) {
105 return false;
108 if (
109 (sci_port->physical_port_index == 2)
110 && ((phy_index == 0) || (phy_index == 1))
112 return false;
115 for (index = 0; index < SCI_MAX_PHYS; index++) {
116 if ((sci_port->phy_table[index] != NULL)
117 && (index != phy_index)) {
118 existing_phy_index = index;
123 * Ensure that all of the phys in the port are capable of
124 * operating at the same maximum link rate. */
125 if (
126 (existing_phy_index < SCI_MAX_PHYS)
127 && (sci_port->owning_controller->user_parameters.sds1.phys[
128 phy_index].max_speed_generation !=
129 sci_port->owning_controller->user_parameters.sds1.phys[
130 existing_phy_index].max_speed_generation)
132 return false;
134 return true;
138 * This method requests a list (mask) of the phys contained in the supplied SAS
139 * port.
140 * @sci_port: a handle corresponding to the SAS port for which to return the
141 * phy mask.
143 * Return a bit mask indicating which phys are a part of this port. Each bit
144 * corresponds to a phy identifier (e.g. bit 0 = phy id 0).
146 static u32 scic_sds_port_get_phys(struct scic_sds_port *sci_port)
148 u32 index;
149 u32 mask;
151 mask = 0;
153 for (index = 0; index < SCI_MAX_PHYS; index++) {
154 if (sci_port->phy_table[index] != NULL) {
155 mask |= (1 << index);
159 return mask;
164 * @sci_port: This is the port object for which to determine if the phy mask
165 * can be supported.
167 * This method will return a true value if the port's phy mask can be supported
168 * by the SCU. The following is a list of valid PHY mask configurations for
169 * each port: - Port 0 - [[3 2] 1] 0 - Port 1 - [1] - Port 2 - [[3] 2]
170 * - Port 3 - [3] This method returns a boolean indication specifying if the
171 * phy mask can be supported. true if this is a valid phy assignment for the
172 * port false if this is not a valid phy assignment for the port
174 static bool scic_sds_port_is_phy_mask_valid(
175 struct scic_sds_port *sci_port,
176 u32 phy_mask)
178 if (sci_port->physical_port_index == 0) {
179 if (((phy_mask & 0x0F) == 0x0F)
180 || ((phy_mask & 0x03) == 0x03)
181 || ((phy_mask & 0x01) == 0x01)
182 || (phy_mask == 0))
183 return true;
184 } else if (sci_port->physical_port_index == 1) {
185 if (((phy_mask & 0x02) == 0x02)
186 || (phy_mask == 0))
187 return true;
188 } else if (sci_port->physical_port_index == 2) {
189 if (((phy_mask & 0x0C) == 0x0C)
190 || ((phy_mask & 0x04) == 0x04)
191 || (phy_mask == 0))
192 return true;
193 } else if (sci_port->physical_port_index == 3) {
194 if (((phy_mask & 0x08) == 0x08)
195 || (phy_mask == 0))
196 return true;
199 return false;
204 * @sci_port: This parameter specifies the port from which to return a
205 * connected phy.
207 * This method retrieves a currently active (i.e. connected) phy contained in
208 * the port. Currently, the lowest order phy that is connected is returned.
209 * This method returns a pointer to a SCIS_SDS_PHY object. NULL This value is
210 * returned if there are no currently active (i.e. connected to a remote end
211 * point) phys contained in the port. All other values specify a struct scic_sds_phy
212 * object that is active in the port.
214 static struct scic_sds_phy *scic_sds_port_get_a_connected_phy(
215 struct scic_sds_port *sci_port
217 u32 index;
218 struct scic_sds_phy *phy;
220 for (index = 0; index < SCI_MAX_PHYS; index++) {
222 * Ensure that the phy is both part of the port and currently
223 * connected to the remote end-point. */
224 phy = sci_port->phy_table[index];
225 if (
226 (phy != NULL)
227 && scic_sds_port_active_phy(sci_port, phy)
229 return phy;
233 return NULL;
237 * scic_sds_port_set_phy() -
238 * @out]: port The port object to which the phy assignement is being made.
239 * @out]: phy The phy which is being assigned to the port.
241 * This method attempts to make the assignment of the phy to the port. If
242 * successful the phy is assigned to the ports phy table. bool true if the phy
243 * assignment can be made. false if the phy assignement can not be made. This
244 * is a functional test that only fails if the phy is currently assigned to a
245 * different port.
247 static enum sci_status scic_sds_port_set_phy(
248 struct scic_sds_port *port,
249 struct scic_sds_phy *phy)
252 * Check to see if we can add this phy to a port
253 * that means that the phy is not part of a port and that the port does
254 * not already have a phy assinged to the phy index. */
255 if (
256 (port->phy_table[phy->phy_index] == NULL)
257 && (scic_sds_phy_get_port(phy) == NULL)
258 && scic_sds_port_is_valid_phy_assignment(port, phy->phy_index)
261 * Phy is being added in the stopped state so we are in MPC mode
262 * make logical port index = physical port index */
263 port->logical_port_index = port->physical_port_index;
264 port->phy_table[phy->phy_index] = phy;
265 scic_sds_phy_set_port(phy, port);
267 return SCI_SUCCESS;
270 return SCI_FAILURE;
274 * scic_sds_port_clear_phy() -
275 * @out]: port The port from which the phy is being cleared.
276 * @out]: phy The phy being cleared from the port.
278 * This method will clear the phy assigned to this port. This method fails if
279 * this phy is not currently assinged to this port. bool true if the phy is
280 * removed from the port. false if this phy is not assined to this port.
282 static enum sci_status scic_sds_port_clear_phy(
283 struct scic_sds_port *port,
284 struct scic_sds_phy *phy)
286 /* Make sure that this phy is part of this port */
287 if (
288 (port->phy_table[phy->phy_index] == phy)
289 && (scic_sds_phy_get_port(phy) == port)
291 /* Yep it is assigned to this port so remove it */
292 scic_sds_phy_set_port(
293 phy,
294 &scic_sds_port_get_controller(port)->port_table[SCI_MAX_PORTS]
297 port->phy_table[phy->phy_index] = NULL;
299 return SCI_SUCCESS;
302 return SCI_FAILURE;
306 * scic_sds_port_add_phy() -
307 * @sci_port: This parameter specifies the port in which the phy will be added.
308 * @sci_phy: This parameter is the phy which is to be added to the port.
310 * This method will add a PHY to the selected port. This method returns an
311 * enum sci_status. SCI_SUCCESS the phy has been added to the port. Any other status
312 * is failre to add the phy to the port.
314 enum sci_status scic_sds_port_add_phy(
315 struct scic_sds_port *sci_port,
316 struct scic_sds_phy *sci_phy)
318 return sci_port->state_handlers->add_phy_handler(
319 sci_port, sci_phy);
324 * scic_sds_port_remove_phy() -
325 * @sci_port: This parameter specifies the port in which the phy will be added.
326 * @sci_phy: This parameter is the phy which is to be added to the port.
328 * This method will remove the PHY from the selected PORT. This method returns
329 * an enum sci_status. SCI_SUCCESS the phy has been removed from the port. Any other
330 * status is failre to add the phy to the port.
332 enum sci_status scic_sds_port_remove_phy(
333 struct scic_sds_port *sci_port,
334 struct scic_sds_phy *sci_phy)
336 return sci_port->state_handlers->remove_phy_handler(
337 sci_port, sci_phy);
341 * This method requests the SAS address for the supplied SAS port from the SCI
342 * implementation.
343 * @sci_port: a handle corresponding to the SAS port for which to return the
344 * SAS address.
345 * @sas_address: This parameter specifies a pointer to a SAS address structure
346 * into which the core will copy the SAS address for the port.
349 void scic_sds_port_get_sas_address(
350 struct scic_sds_port *sci_port,
351 struct sci_sas_address *sas_address)
353 u32 index;
355 sas_address->high = 0;
356 sas_address->low = 0;
358 for (index = 0; index < SCI_MAX_PHYS; index++) {
359 if (sci_port->phy_table[index] != NULL) {
360 scic_sds_phy_get_sas_address(sci_port->phy_table[index], sas_address);
366 * This method will indicate which protocols are supported by this port.
367 * @sci_port: a handle corresponding to the SAS port for which to return the
368 * supported protocols.
369 * @protocols: This parameter specifies a pointer to an IAF protocol field
370 * structure into which the core will copy the protocol values for the port.
371 * The values are returned as part of a bit mask in order to allow for
372 * multi-protocol support.
375 static void scic_sds_port_get_protocols(
376 struct scic_sds_port *sci_port,
377 struct sci_sas_identify_address_frame_protocols *protocols)
379 u8 index;
381 protocols->u.all = 0;
383 for (index = 0; index < SCI_MAX_PHYS; index++) {
384 if (sci_port->phy_table[index] != NULL) {
385 scic_sds_phy_get_protocols(sci_port->phy_table[index], protocols);
391 * This method requests the SAS address for the device directly attached to
392 * this SAS port.
393 * @sci_port: a handle corresponding to the SAS port for which to return the
394 * SAS address.
395 * @sas_address: This parameter specifies a pointer to a SAS address structure
396 * into which the core will copy the SAS address for the device directly
397 * attached to the port.
400 void scic_sds_port_get_attached_sas_address(
401 struct scic_sds_port *sci_port,
402 struct sci_sas_address *sas_address)
404 struct sci_sas_identify_address_frame_protocols protocols;
405 struct scic_sds_phy *phy;
408 * Ensure that the phy is both part of the port and currently
409 * connected to the remote end-point. */
410 phy = scic_sds_port_get_a_connected_phy(sci_port);
411 if (phy != NULL) {
412 scic_sds_phy_get_attached_phy_protocols(phy, &protocols);
414 if (!protocols.u.bits.stp_target) {
415 scic_sds_phy_get_attached_sas_address(phy, sas_address);
416 } else {
417 scic_sds_phy_get_sas_address(phy, sas_address);
418 sas_address->low += phy->phy_index;
420 } else {
421 sas_address->high = 0;
422 sas_address->low = 0;
427 * This method will indicate which protocols are supported by this remote
428 * device.
429 * @sci_port: a handle corresponding to the SAS port for which to return the
430 * supported protocols.
431 * @protocols: This parameter specifies a pointer to an IAF protocol field
432 * structure into which the core will copy the protocol values for the port.
433 * The values are returned as part of a bit mask in order to allow for
434 * multi-protocol support.
437 void scic_sds_port_get_attached_protocols(
438 struct scic_sds_port *sci_port,
439 struct sci_sas_identify_address_frame_protocols *protocols)
441 struct scic_sds_phy *phy;
444 * Ensure that the phy is both part of the port and currently
445 * connected to the remote end-point. */
446 phy = scic_sds_port_get_a_connected_phy(sci_port);
447 if (phy != NULL)
448 scic_sds_phy_get_attached_phy_protocols(phy, protocols);
449 else
450 protocols->u.all = 0;
454 * scic_sds_port_construct_dummy_rnc() - create dummy rnc for si workaround
456 * @sci_port: logical port on which we need to create the remote node context
457 * @rni: remote node index for this remote node context.
459 * This routine will construct a dummy remote node context data structure
460 * This structure will be posted to the hardware to work around a scheduler
461 * error in the hardware.
463 static void scic_sds_port_construct_dummy_rnc(struct scic_sds_port *sci_port, u16 rni)
465 union scu_remote_node_context *rnc;
467 rnc = &sci_port->owning_controller->remote_node_context_table[rni];
469 memset(rnc, 0, sizeof(union scu_remote_node_context));
471 rnc->ssp.remote_sas_address_hi = 0;
472 rnc->ssp.remote_sas_address_lo = 0;
474 rnc->ssp.remote_node_index = rni;
475 rnc->ssp.remote_node_port_width = 1;
476 rnc->ssp.logical_port_index = sci_port->physical_port_index;
478 rnc->ssp.nexus_loss_timer_enable = false;
479 rnc->ssp.check_bit = false;
480 rnc->ssp.is_valid = true;
481 rnc->ssp.is_remote_node_context = true;
482 rnc->ssp.function_number = 0;
483 rnc->ssp.arbitration_wait_time = 0;
487 * scic_sds_port_construct_dummy_task() - create dummy task for si workaround
488 * @sci_port The logical port on which we need to create the
489 * remote node context.
490 * context.
491 * @tci The remote node index for this remote node context.
493 * This routine will construct a dummy task context data structure. This
494 * structure will be posted to the hardwre to work around a scheduler error
495 * in the hardware.
498 static void scic_sds_port_construct_dummy_task(struct scic_sds_port *sci_port, u16 tci)
500 struct scu_task_context *task_context;
502 task_context = scic_sds_controller_get_task_context_buffer(sci_port->owning_controller, tci);
504 memset(task_context, 0, sizeof(struct scu_task_context));
506 task_context->abort = 0;
507 task_context->priority = 0;
508 task_context->initiator_request = 1;
509 task_context->connection_rate = 1;
510 task_context->protocol_engine_index = 0;
511 task_context->logical_port_index = sci_port->physical_port_index;
512 task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SSP;
513 task_context->task_index = scic_sds_io_tag_get_index(tci);
514 task_context->valid = SCU_TASK_CONTEXT_VALID;
515 task_context->context_type = SCU_TASK_CONTEXT_TYPE;
517 task_context->remote_node_index = sci_port->reserved_rni;
518 task_context->command_code = 0;
520 task_context->link_layer_control = 0;
521 task_context->do_not_dma_ssp_good_response = 1;
522 task_context->strict_ordering = 0;
523 task_context->control_frame = 0;
524 task_context->timeout_enable = 0;
525 task_context->block_guard_enable = 0;
527 task_context->address_modifier = 0;
529 task_context->task_phase = 0x01;
532 static void scic_sds_port_destroy_dummy_resources(struct scic_sds_port *sci_port)
534 struct scic_sds_controller *scic = sci_port->owning_controller;
536 if (sci_port->reserved_tci != SCU_DUMMY_INDEX)
537 scic_controller_free_io_tag(scic, sci_port->reserved_tci);
539 if (sci_port->reserved_rni != SCU_DUMMY_INDEX)
540 scic_sds_remote_node_table_release_remote_node_index(&scic->available_remote_nodes,
541 1, sci_port->reserved_rni);
543 sci_port->reserved_rni = SCU_DUMMY_INDEX;
544 sci_port->reserved_tci = SCU_DUMMY_INDEX;
548 * This method performs initialization of the supplied port. Initialization
549 * includes: - state machine initialization - member variable initialization
550 * - configuring the phy_mask
551 * @sci_port:
552 * @transport_layer_registers:
553 * @port_task_scheduler_registers:
554 * @port_configuration_regsiter:
556 * enum sci_status SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION This value is returned
557 * if the phy being added to the port
559 enum sci_status scic_sds_port_initialize(
560 struct scic_sds_port *sci_port,
561 void __iomem *port_task_scheduler_registers,
562 void __iomem *port_configuration_regsiter,
563 void __iomem *viit_registers)
565 sci_port->port_task_scheduler_registers = port_task_scheduler_registers;
566 sci_port->port_pe_configuration_register = port_configuration_regsiter;
567 sci_port->viit_registers = viit_registers;
569 return SCI_SUCCESS;
573 * scic_port_get_properties() - This method simply returns the properties
574 * regarding the port, such as: physical index, protocols, sas address, etc.
575 * @port: this parameter specifies the port for which to retrieve the physical
576 * index.
577 * @properties: This parameter specifies the properties structure into which to
578 * copy the requested information.
580 * Indicate if the user specified a valid port. SCI_SUCCESS This value is
581 * returned if the specified port was valid. SCI_FAILURE_INVALID_PORT This
582 * value is returned if the specified port is not valid. When this value is
583 * returned, no data is copied to the properties output parameter.
585 enum sci_status scic_port_get_properties(
586 struct scic_sds_port *port,
587 struct scic_port_properties *prop)
589 if ((port == NULL) ||
590 (port->logical_port_index == SCIC_SDS_DUMMY_PORT))
591 return SCI_FAILURE_INVALID_PORT;
593 prop->index = port->logical_port_index;
594 prop->phy_mask = scic_sds_port_get_phys(port);
595 scic_sds_port_get_sas_address(port, &prop->local.sas_address);
596 scic_sds_port_get_protocols(port, &prop->local.protocols);
597 scic_sds_port_get_attached_sas_address(port, &prop->remote.sas_address);
598 scic_sds_port_get_attached_protocols(port, &prop->remote.protocols);
600 return SCI_SUCCESS;
604 * scic_port_hard_reset() - perform port hard reset
605 * @port: a handle corresponding to the SAS port to be hard reset.
606 * @reset_timeout: This parameter specifies the number of milliseconds in which
607 * the port reset operation should complete.
609 * The SCI User callback in scic_user_callbacks_t will only be called once for
610 * each phy in the SAS Port at completion of the hard reset sequence. Return a
611 * status indicating whether the hard reset started successfully. SCI_SUCCESS
612 * This value is returned if the hard reset operation started successfully.
614 enum sci_status scic_port_hard_reset(
615 struct scic_sds_port *port,
616 u32 reset_timeout)
618 return port->state_handlers->reset_handler(
619 port, reset_timeout);
623 * This method assigns the direct attached device ID for this port.
625 * @param[in] sci_port The port for which the direct attached device id is to
626 * be assigned.
627 * @param[in] device_id The direct attached device ID to assign to the port.
628 * This will be the RNi for the device
630 void scic_sds_port_setup_transports(
631 struct scic_sds_port *sci_port,
632 u32 device_id)
634 u8 index;
636 for (index = 0; index < SCI_MAX_PHYS; index++) {
637 if (sci_port->active_phy_mask & (1 << index))
638 scic_sds_phy_setup_transport(sci_port->phy_table[index], device_id);
644 * @sci_port: This is the port on which the phy should be enabled.
645 * @sci_phy: This is the specific phy which to enable.
646 * @do_notify_user: This parameter specifies whether to inform the user (via
647 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
649 * This function will activate the phy in the port.
650 * Activation includes: - adding
651 * the phy to the port - enabling the Protocol Engine in the silicon. -
652 * notifying the user that the link is up. none
654 static void scic_sds_port_activate_phy(struct scic_sds_port *sci_port,
655 struct scic_sds_phy *sci_phy,
656 bool do_notify_user)
658 struct scic_sds_controller *scic = scic_sds_port_get_controller(sci_port);
659 struct sci_sas_identify_address_frame_protocols protocols;
660 struct isci_host *ihost = sci_object_get_association(scic);
662 scic_sds_phy_get_attached_phy_protocols(sci_phy, &protocols);
664 /* If this is sata port then the phy has already been resumed */
665 if (!protocols.u.bits.stp_target)
666 scic_sds_phy_resume(sci_phy);
668 sci_port->active_phy_mask |= 1 << sci_phy->phy_index;
670 scic_sds_controller_clear_invalid_phy(scic, sci_phy);
672 if (do_notify_user == true)
673 isci_port_link_up(ihost, sci_port, sci_phy);
676 void scic_sds_port_deactivate_phy(struct scic_sds_port *sci_port,
677 struct scic_sds_phy *sci_phy,
678 bool do_notify_user)
680 struct scic_sds_controller *scic = scic_sds_port_get_controller(sci_port);
681 struct isci_port *iport = sci_object_get_association(sci_port);
682 struct isci_host *ihost = sci_object_get_association(scic);
683 struct isci_phy *iphy = sci_object_get_association(sci_phy);
685 sci_port->active_phy_mask &= ~(1 << sci_phy->phy_index);
687 sci_phy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
689 /* Re-assign the phy back to the LP as if it were a narrow port */
690 writel(sci_phy->phy_index,
691 &sci_port->port_pe_configuration_register[sci_phy->phy_index]);
693 if (do_notify_user == true)
694 isci_port_link_down(ihost, iphy, iport);
699 * @sci_port: This is the port on which the phy should be disabled.
700 * @sci_phy: This is the specific phy which to disabled.
702 * This function will disable the phy and report that the phy is not valid for
703 * this port object. None
705 static void scic_sds_port_invalid_link_up(
706 struct scic_sds_port *sci_port,
707 struct scic_sds_phy *sci_phy)
709 struct scic_sds_controller *scic =
710 scic_sds_port_get_controller(sci_port);
713 * Check to see if we have alreay reported this link as bad and if
714 * not go ahead and tell the SCI_USER that we have discovered an
715 * invalid link.
717 if ((scic->invalid_phy_mask & (1 << sci_phy->phy_index)) == 0) {
718 scic_sds_controller_set_invalid_phy(scic, sci_phy);
719 isci_port_invalid_link_up(scic, sci_port, sci_phy);
724 * scic_sds_port_general_link_up_handler - phy can be assigned to port?
725 * @sci_port: scic_sds_port object for which has a phy that has gone link up.
726 * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
727 * @do_notify_user: This parameter specifies whether to inform the user (via
728 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
730 * Determine if this phy can be assigned to this
731 * port . If the phy is not a valid PHY for
732 * this port then the function will notify the user. A PHY can only be
733 * part of a port if it's attached SAS ADDRESS is the same as all other PHYs in
734 * the same port. none
736 static void scic_sds_port_general_link_up_handler(struct scic_sds_port *sci_port,
737 struct scic_sds_phy *sci_phy,
738 bool do_notify_user)
740 struct sci_sas_address port_sas_address;
741 struct sci_sas_address phy_sas_address;
743 scic_sds_port_get_attached_sas_address(sci_port, &port_sas_address);
744 scic_sds_phy_get_attached_sas_address(sci_phy, &phy_sas_address);
746 /* If the SAS address of the new phy matches the SAS address of
747 * other phys in the port OR this is the first phy in the port,
748 * then activate the phy and allow it to be used for operations
749 * in this port.
751 if ((phy_sas_address.high == port_sas_address.high &&
752 phy_sas_address.low == port_sas_address.low) ||
753 sci_port->active_phy_mask == 0) {
754 struct sci_base_state_machine *sm = &sci_port->state_machine;
756 scic_sds_port_activate_phy(sci_port, sci_phy, do_notify_user);
757 if (sm->current_state_id == SCI_BASE_PORT_STATE_RESETTING)
758 sci_base_state_machine_change_state(sm, SCI_BASE_PORT_STATE_READY);
759 } else
760 scic_sds_port_invalid_link_up(sci_port, sci_phy);
766 * This method returns false if the port only has a single phy object assigned.
767 * If there are no phys or more than one phy then the method will return
768 * true.
769 * @sci_port: The port for which the wide port condition is to be checked.
771 * bool true Is returned if this is a wide ported port. false Is returned if
772 * this is a narrow port.
774 static bool scic_sds_port_is_wide(struct scic_sds_port *sci_port)
776 u32 index;
777 u32 phy_count = 0;
779 for (index = 0; index < SCI_MAX_PHYS; index++) {
780 if (sci_port->phy_table[index] != NULL) {
781 phy_count++;
785 return phy_count != 1;
789 * This method is called by the PHY object when the link is detected. if the
790 * port wants the PHY to continue on to the link up state then the port
791 * layer must return true. If the port object returns false the phy object
792 * must halt its attempt to go link up.
793 * @sci_port: The port associated with the phy object.
794 * @sci_phy: The phy object that is trying to go link up.
796 * true if the phy object can continue to the link up condition. true Is
797 * returned if this phy can continue to the ready state. false Is returned if
798 * can not continue on to the ready state. This notification is in place for
799 * wide ports and direct attached phys. Since there are no wide ported SATA
800 * devices this could become an invalid port configuration.
802 bool scic_sds_port_link_detected(
803 struct scic_sds_port *sci_port,
804 struct scic_sds_phy *sci_phy)
806 struct sci_sas_identify_address_frame_protocols protocols;
808 scic_sds_phy_get_attached_phy_protocols(sci_phy, &protocols);
810 if (
811 (sci_port->logical_port_index != SCIC_SDS_DUMMY_PORT)
812 && (protocols.u.bits.stp_target)
813 && scic_sds_port_is_wide(sci_port)
815 scic_sds_port_invalid_link_up(sci_port, sci_phy);
817 return false;
820 return true;
824 * This method is the entry point for the phy to inform the port that it is now
825 * in a ready state
826 * @sci_port:
830 void scic_sds_port_link_up(
831 struct scic_sds_port *sci_port,
832 struct scic_sds_phy *sci_phy)
834 sci_phy->is_in_link_training = false;
836 sci_port->state_handlers->link_up_handler(sci_port, sci_phy);
840 * This method is the entry point for the phy to inform the port that it is no
841 * longer in a ready state
842 * @sci_port:
846 void scic_sds_port_link_down(
847 struct scic_sds_port *sci_port,
848 struct scic_sds_phy *sci_phy)
850 sci_port->state_handlers->link_down_handler(sci_port, sci_phy);
854 * This method is called to start an IO request on this port.
855 * @sci_port:
856 * @sci_dev:
857 * @sci_req:
859 * enum sci_status
861 enum sci_status scic_sds_port_start_io(
862 struct scic_sds_port *sci_port,
863 struct scic_sds_remote_device *sci_dev,
864 struct scic_sds_request *sci_req)
866 return sci_port->state_handlers->start_io_handler(
867 sci_port, sci_dev, sci_req);
871 * This method is called to complete an IO request to the port.
872 * @sci_port:
873 * @sci_dev:
874 * @sci_req:
876 * enum sci_status
878 enum sci_status scic_sds_port_complete_io(
879 struct scic_sds_port *sci_port,
880 struct scic_sds_remote_device *sci_dev,
881 struct scic_sds_request *sci_req)
883 return sci_port->state_handlers->complete_io_handler(
884 sci_port, sci_dev, sci_req);
888 * This method is provided to timeout requests for port operations. Mostly its
889 * for the port reset operation.
893 static void scic_sds_port_timeout_handler(void *port)
895 struct scic_sds_port *sci_port = port;
896 u32 current_state;
898 current_state = sci_base_state_machine_get_state(
899 &sci_port->state_machine);
901 if (current_state == SCI_BASE_PORT_STATE_RESETTING) {
903 * if the port is still in the resetting state then the
904 * timeout fired before the reset completed.
906 sci_base_state_machine_change_state(
907 &sci_port->state_machine,
908 SCI_BASE_PORT_STATE_FAILED);
909 } else if (current_state == SCI_BASE_PORT_STATE_STOPPED) {
911 * if the port is stopped then the start request failed
912 * In this case stay in the stopped state.
914 dev_err(sciport_to_dev(sci_port),
915 "%s: SCIC Port 0x%p failed to stop before tiemout.\n",
916 __func__,
917 sci_port);
918 } else if (current_state == SCI_BASE_PORT_STATE_STOPPING) {
920 * if the port is still stopping then the stop has not
921 * completed
923 isci_port_stop_complete(
924 scic_sds_port_get_controller(sci_port),
925 sci_port,
926 SCI_FAILURE_TIMEOUT);
927 } else {
929 * The port is in the ready state and we have a timer
930 * reporting a timeout this should not happen.
932 dev_err(sciport_to_dev(sci_port),
933 "%s: SCIC Port 0x%p is processing a timeout operation "
934 "in state %d.\n",
935 __func__,
936 sci_port,
937 current_state);
941 /* --------------------------------------------------------------------------- */
944 * This function updates the hardwares VIIT entry for this port.
948 static void scic_sds_port_update_viit_entry(struct scic_sds_port *sci_port)
950 struct sci_sas_address sas_address;
952 scic_sds_port_get_sas_address(sci_port, &sas_address);
954 writel(sas_address.high,
955 &sci_port->viit_registers->initiator_sas_address_hi);
956 writel(sas_address.low,
957 &sci_port->viit_registers->initiator_sas_address_lo);
959 /* This value get cleared just in case its not already cleared */
960 writel(0, &sci_port->viit_registers->reserved);
962 /* We are required to update the status register last */
963 writel(SCU_VIIT_ENTRY_ID_VIIT |
964 SCU_VIIT_IPPT_INITIATOR |
965 ((1 << sci_port->physical_port_index) << SCU_VIIT_ENTRY_LPVIE_SHIFT) |
966 SCU_VIIT_STATUS_ALL_VALID,
967 &sci_port->viit_registers->status);
971 * This method returns the maximum allowed speed for data transfers on this
972 * port. This maximum allowed speed evaluates to the maximum speed of the
973 * slowest phy in the port.
974 * @sci_port: This parameter specifies the port for which to retrieve the
975 * maximum allowed speed.
977 * This method returns the maximum negotiated speed of the slowest phy in the
978 * port.
980 enum sas_linkrate scic_sds_port_get_max_allowed_speed(
981 struct scic_sds_port *sci_port)
983 u16 index;
984 enum sas_linkrate max_allowed_speed = SAS_LINK_RATE_6_0_GBPS;
985 struct scic_sds_phy *phy = NULL;
988 * Loop through all of the phys in this port and find the phy with the
989 * lowest maximum link rate. */
990 for (index = 0; index < SCI_MAX_PHYS; index++) {
991 phy = sci_port->phy_table[index];
992 if (
993 (phy != NULL)
994 && (scic_sds_port_active_phy(sci_port, phy) == true)
995 && (phy->max_negotiated_speed < max_allowed_speed)
997 max_allowed_speed = phy->max_negotiated_speed;
1000 return max_allowed_speed;
1005 * This method passes the event to core user.
1006 * @sci_port: The port that a BCN happens.
1007 * @sci_phy: The phy that receives BCN.
1010 void scic_sds_port_broadcast_change_received(
1011 struct scic_sds_port *sci_port,
1012 struct scic_sds_phy *sci_phy)
1014 struct scic_sds_controller *scic = sci_port->owning_controller;
1015 struct isci_host *ihost = sci_object_get_association(scic);
1017 /* notify the user. */
1018 isci_port_bc_change_received(ihost, sci_port, sci_phy);
1023 * This API methhod enables the broadcast change notification from underneath
1024 * hardware.
1025 * @sci_port: The port that a BCN had been disabled from.
1028 void scic_port_enable_broadcast_change_notification(
1029 struct scic_sds_port *port)
1031 struct scic_sds_phy *phy;
1032 u32 register_value;
1033 u8 index;
1035 /* Loop through all of the phys to enable BCN. */
1036 for (index = 0; index < SCI_MAX_PHYS; index++) {
1037 phy = port->phy_table[index];
1038 if (phy != NULL) {
1039 register_value =
1040 readl(&phy->link_layer_registers->link_layer_control);
1042 /* clear the bit by writing 1. */
1043 writel(register_value,
1044 &phy->link_layer_registers->link_layer_control);
1050 * ****************************************************************************
1051 * * READY SUBSTATE HANDLERS
1052 * **************************************************************************** */
1055 * This method is the general ready state stop handler for the struct scic_sds_port
1056 * object. This function will transition the ready substate machine to its
1057 * final state. enum sci_status SCI_SUCCESS
1059 static enum sci_status scic_sds_port_ready_substate_stop_handler(
1060 struct scic_sds_port *port)
1062 sci_base_state_machine_change_state(
1063 &port->state_machine,
1064 SCI_BASE_PORT_STATE_STOPPING
1067 return SCI_SUCCESS;
1071 * This method is the general ready substate complete io handler for the
1072 * struct scic_sds_port object. This function decrments the outstanding request count
1073 * for this port object. enum sci_status SCI_SUCCESS
1075 static enum sci_status scic_sds_port_ready_substate_complete_io_handler(
1076 struct scic_sds_port *port,
1077 struct scic_sds_remote_device *device,
1078 struct scic_sds_request *io_request)
1080 scic_sds_port_decrement_request_count(port);
1082 return SCI_SUCCESS;
1085 static enum sci_status scic_sds_port_ready_substate_add_phy_handler(
1086 struct scic_sds_port *port,
1087 struct scic_sds_phy *phy)
1089 enum sci_status status;
1091 status = scic_sds_port_set_phy(port, phy);
1093 if (status == SCI_SUCCESS) {
1094 scic_sds_port_general_link_up_handler(port, phy, true);
1096 port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
1098 sci_base_state_machine_change_state(
1099 &port->ready_substate_machine,
1100 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1104 return status;
1108 static enum sci_status scic_sds_port_ready_substate_remove_phy_handler(
1109 struct scic_sds_port *port,
1110 struct scic_sds_phy *phy)
1112 enum sci_status status;
1114 status = scic_sds_port_clear_phy(port, phy);
1116 if (status == SCI_SUCCESS) {
1117 scic_sds_port_deactivate_phy(port, phy, true);
1119 port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
1121 sci_base_state_machine_change_state(
1122 &port->ready_substate_machine,
1123 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1127 return status;
1131 * ****************************************************************************
1132 * * READY SUBSTATE WAITING HANDLERS
1133 * **************************************************************************** */
1137 * @sci_port: This is the struct scic_sds_port object that which has a phy that has
1138 * gone link up.
1139 * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
1141 * This method is the ready waiting substate link up handler for the
1142 * struct scic_sds_port object. This methos will report the link up condition for
1143 * this port and will transition to the ready operational substate. none
1145 static void scic_sds_port_ready_waiting_substate_link_up_handler(
1146 struct scic_sds_port *sci_port,
1147 struct scic_sds_phy *sci_phy)
1150 * Since this is the first phy going link up for the port we can just enable
1151 * it and continue. */
1152 scic_sds_port_activate_phy(sci_port, sci_phy, true);
1154 sci_base_state_machine_change_state(
1155 &sci_port->ready_substate_machine,
1156 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1161 * This method is the ready waiting substate start io handler for the
1162 * struct scic_sds_port object. The port object can not accept new requests so the
1163 * request is failed. enum sci_status SCI_FAILURE_INVALID_STATE
1165 static enum sci_status scic_sds_port_ready_waiting_substate_start_io_handler(
1166 struct scic_sds_port *port,
1167 struct scic_sds_remote_device *device,
1168 struct scic_sds_request *io_request)
1170 return SCI_FAILURE_INVALID_STATE;
1174 * ****************************************************************************
1175 * * READY SUBSTATE OPERATIONAL HANDLERS
1176 * **************************************************************************** */
1179 * This method will casue the port to reset. enum sci_status SCI_SUCCESS
1181 static enum
1182 sci_status scic_sds_port_ready_operational_substate_reset_handler(
1183 struct scic_sds_port *port,
1184 u32 timeout)
1186 enum sci_status status = SCI_FAILURE_INVALID_PHY;
1187 u32 phy_index;
1188 struct scic_sds_phy *selected_phy = NULL;
1191 /* Select a phy on which we can send the hard reset request. */
1192 for (phy_index = 0;
1193 (phy_index < SCI_MAX_PHYS) && (selected_phy == NULL);
1194 phy_index++) {
1195 selected_phy = port->phy_table[phy_index];
1197 if ((selected_phy != NULL) &&
1198 !scic_sds_port_active_phy(port, selected_phy)) {
1200 * We found a phy but it is not ready select
1201 * different phy
1203 selected_phy = NULL;
1207 /* If we have a phy then go ahead and start the reset procedure */
1208 if (selected_phy != NULL) {
1209 status = scic_sds_phy_reset(selected_phy);
1211 if (status == SCI_SUCCESS) {
1212 isci_timer_start(port->timer_handle, timeout);
1213 port->not_ready_reason =
1214 SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED;
1216 sci_base_state_machine_change_state(
1217 &port->state_machine,
1218 SCI_BASE_PORT_STATE_RESETTING);
1222 return status;
1226 * scic_sds_port_ready_operational_substate_link_up_handler() -
1227 * @sci_port: This is the struct scic_sds_port object that which has a phy that has
1228 * gone link up.
1229 * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
1231 * This method is the ready operational substate link up handler for the
1232 * struct scic_sds_port object. This function notifies the SCI User that the phy has
1233 * gone link up. none
1235 static void scic_sds_port_ready_operational_substate_link_up_handler(
1236 struct scic_sds_port *sci_port,
1237 struct scic_sds_phy *sci_phy)
1239 scic_sds_port_general_link_up_handler(sci_port, sci_phy, true);
1243 * scic_sds_port_ready_operational_substate_link_down_handler() -
1244 * @sci_port: This is the struct scic_sds_port object that which has a phy that has
1245 * gone link down.
1246 * @sci_phy: This is the struct scic_sds_phy object that has gone link down.
1248 * This method is the ready operational substate link down handler for the
1249 * struct scic_sds_port object. This function notifies the SCI User that the phy has
1250 * gone link down and if this is the last phy in the port the port will change
1251 * state to the ready waiting substate. none
1253 static void scic_sds_port_ready_operational_substate_link_down_handler(
1254 struct scic_sds_port *sci_port,
1255 struct scic_sds_phy *sci_phy)
1257 scic_sds_port_deactivate_phy(sci_port, sci_phy, true);
1260 * If there are no active phys left in the port, then transition
1261 * the port to the WAITING state until such time as a phy goes
1262 * link up. */
1263 if (sci_port->active_phy_mask == 0)
1264 sci_base_state_machine_change_state(&sci_port->ready_substate_machine,
1265 SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
1269 * This method is the ready operational substate start io handler for the
1270 * struct scic_sds_port object. This function incremetns the outstanding request
1271 * count for this port object. enum sci_status SCI_SUCCESS
1273 static enum sci_status scic_sds_port_ready_operational_substate_start_io_handler(
1274 struct scic_sds_port *port,
1275 struct scic_sds_remote_device *device,
1276 struct scic_sds_request *io_request)
1278 scic_sds_port_increment_request_count(port);
1280 return SCI_SUCCESS;
1284 * ****************************************************************************
1285 * * READY SUBSTATE OPERATIONAL HANDLERS
1286 * **************************************************************************** */
1289 * This is the default method for a port add phy request. It will report a
1290 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1292 static enum sci_status scic_sds_port_ready_configuring_substate_add_phy_handler(
1293 struct scic_sds_port *port,
1294 struct scic_sds_phy *phy)
1296 enum sci_status status;
1298 status = scic_sds_port_set_phy(port, phy);
1300 if (status == SCI_SUCCESS) {
1301 scic_sds_port_general_link_up_handler(port, phy, true);
1304 * Re-enter the configuring state since this may be the last phy in
1305 * the port. */
1306 sci_base_state_machine_change_state(
1307 &port->ready_substate_machine,
1308 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1312 return status;
1316 * This is the default method for a port remove phy request. It will report a
1317 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1319 static enum sci_status scic_sds_port_ready_configuring_substate_remove_phy_handler(
1320 struct scic_sds_port *port,
1321 struct scic_sds_phy *phy)
1323 enum sci_status status;
1325 status = scic_sds_port_clear_phy(port, phy);
1327 if (status == SCI_SUCCESS) {
1328 scic_sds_port_deactivate_phy(port, phy, true);
1331 * Re-enter the configuring state since this may be the last phy in
1332 * the port. */
1333 sci_base_state_machine_change_state(
1334 &port->ready_substate_machine,
1335 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1339 return status;
1343 * scic_sds_port_ready_configuring_substate_complete_io_handler() -
1344 * @port: This is the port that is being requested to complete the io request.
1345 * @device: This is the device on which the io is completing.
1347 * This method will decrement the outstanding request count for this port. If
1348 * the request count goes to 0 then the port can be reprogrammed with its new
1349 * phy data.
1351 static enum sci_status
1352 scic_sds_port_ready_configuring_substate_complete_io_handler(
1353 struct scic_sds_port *port,
1354 struct scic_sds_remote_device *device,
1355 struct scic_sds_request *io_request)
1357 scic_sds_port_decrement_request_count(port);
1359 if (port->started_request_count == 0) {
1360 sci_base_state_machine_change_state(
1361 &port->ready_substate_machine,
1362 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1366 return SCI_SUCCESS;
1369 static enum sci_status default_port_handler(struct scic_sds_port *sci_port,
1370 const char *func)
1372 dev_warn(sciport_to_dev(sci_port),
1373 "%s: in wrong state: %d\n", func,
1374 sci_base_state_machine_get_state(&sci_port->state_machine));
1375 return SCI_FAILURE_INVALID_STATE;
1378 static enum sci_status
1379 scic_sds_port_default_start_handler(struct scic_sds_port *sci_port)
1381 return default_port_handler(sci_port, __func__);
1384 static enum sci_status
1385 scic_sds_port_default_stop_handler(struct scic_sds_port *sci_port)
1387 return default_port_handler(sci_port, __func__);
1390 static enum sci_status
1391 scic_sds_port_default_destruct_handler(struct scic_sds_port *sci_port)
1393 return default_port_handler(sci_port, __func__);
1396 static enum sci_status
1397 scic_sds_port_default_reset_handler(struct scic_sds_port *sci_port,
1398 u32 timeout)
1400 return default_port_handler(sci_port, __func__);
1403 static enum sci_status
1404 scic_sds_port_default_add_phy_handler(struct scic_sds_port *sci_port,
1405 struct scic_sds_phy *base_phy)
1407 return default_port_handler(sci_port, __func__);
1410 static enum sci_status
1411 scic_sds_port_default_remove_phy_handler(struct scic_sds_port *sci_port,
1412 struct scic_sds_phy *base_phy)
1414 return default_port_handler(sci_port, __func__);
1418 * This is the default method for a port unsolicited frame request. It will
1419 * report a warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE Is it even
1420 * possible to receive an unsolicited frame directed to a port object? It
1421 * seems possible if we implementing virtual functions but until then?
1423 static enum sci_status
1424 scic_sds_port_default_frame_handler(struct scic_sds_port *sci_port,
1425 u32 frame_index)
1427 struct scic_sds_controller *scic = scic_sds_port_get_controller(sci_port);
1429 default_port_handler(sci_port, __func__);
1430 scic_sds_controller_release_frame(scic, frame_index);
1432 return SCI_FAILURE_INVALID_STATE;
1435 static enum sci_status scic_sds_port_default_event_handler(struct scic_sds_port *sci_port,
1436 u32 event_code)
1438 return default_port_handler(sci_port, __func__);
1441 static void scic_sds_port_default_link_up_handler(struct scic_sds_port *sci_port,
1442 struct scic_sds_phy *sci_phy)
1444 default_port_handler(sci_port, __func__);
1447 static void scic_sds_port_default_link_down_handler(struct scic_sds_port *sci_port,
1448 struct scic_sds_phy *sci_phy)
1450 default_port_handler(sci_port, __func__);
1453 static enum sci_status scic_sds_port_default_start_io_handler(struct scic_sds_port *sci_port,
1454 struct scic_sds_remote_device *sci_dev,
1455 struct scic_sds_request *sci_req)
1457 return default_port_handler(sci_port, __func__);
1460 static enum sci_status scic_sds_port_default_complete_io_handler(struct scic_sds_port *sci_port,
1461 struct scic_sds_remote_device *sci_dev,
1462 struct scic_sds_request *sci_req)
1464 return default_port_handler(sci_port, __func__);
1469 static struct scic_sds_port_state_handler
1470 scic_sds_port_ready_substate_handler_table[SCIC_SDS_PORT_READY_MAX_SUBSTATES] = {
1472 /* SCIC_SDS_PORT_READY_SUBSTATE_WAITING */
1473 scic_sds_port_default_start_handler,
1474 scic_sds_port_ready_substate_stop_handler,
1475 scic_sds_port_default_destruct_handler,
1476 scic_sds_port_default_reset_handler,
1477 scic_sds_port_ready_substate_add_phy_handler,
1478 scic_sds_port_default_remove_phy_handler,
1479 scic_sds_port_default_frame_handler,
1480 scic_sds_port_default_event_handler,
1481 scic_sds_port_ready_waiting_substate_link_up_handler,
1482 scic_sds_port_default_link_down_handler,
1483 scic_sds_port_ready_waiting_substate_start_io_handler,
1484 scic_sds_port_ready_substate_complete_io_handler,
1488 /* SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL */
1489 scic_sds_port_default_start_handler,
1490 scic_sds_port_ready_substate_stop_handler,
1491 scic_sds_port_default_destruct_handler,
1492 scic_sds_port_ready_operational_substate_reset_handler,
1493 scic_sds_port_ready_substate_add_phy_handler,
1494 scic_sds_port_ready_substate_remove_phy_handler,
1495 scic_sds_port_default_frame_handler,
1496 scic_sds_port_default_event_handler,
1497 scic_sds_port_ready_operational_substate_link_up_handler,
1498 scic_sds_port_ready_operational_substate_link_down_handler,
1499 scic_sds_port_ready_operational_substate_start_io_handler,
1500 scic_sds_port_ready_substate_complete_io_handler,
1504 /* SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING */
1505 scic_sds_port_default_start_handler,
1506 scic_sds_port_ready_substate_stop_handler,
1507 scic_sds_port_default_destruct_handler,
1508 scic_sds_port_default_reset_handler,
1509 scic_sds_port_ready_configuring_substate_add_phy_handler,
1510 scic_sds_port_ready_configuring_substate_remove_phy_handler,
1511 scic_sds_port_default_frame_handler,
1512 scic_sds_port_default_event_handler,
1513 scic_sds_port_default_link_up_handler,
1514 scic_sds_port_default_link_down_handler,
1515 scic_sds_port_default_start_io_handler,
1516 scic_sds_port_ready_configuring_substate_complete_io_handler
1521 * scic_sds_port_set_ready_state_handlers() -
1523 * This macro sets the port ready substate handlers.
1525 #define scic_sds_port_set_ready_state_handlers(port, state_id) \
1526 scic_sds_port_set_state_handlers(\
1527 port, &scic_sds_port_ready_substate_handler_table[(state_id)] \
1531 * ******************************************************************************
1532 * * PORT STATE PRIVATE METHODS
1533 * ****************************************************************************** */
1537 * @sci_port: This is the struct scic_sds_port object to suspend.
1539 * This method will susped the port task scheduler for this port object. none
1541 static void
1542 scic_sds_port_suspend_port_task_scheduler(struct scic_sds_port *port)
1544 u32 pts_control_value;
1546 pts_control_value = readl(&port->port_task_scheduler_registers->control);
1547 pts_control_value |= SCU_PTSxCR_GEN_BIT(SUSPEND);
1548 writel(pts_control_value, &port->port_task_scheduler_registers->control);
1552 * scic_sds_port_post_dummy_request() - post dummy/workaround request
1553 * @sci_port: port to post task
1555 * Prevent the hardware scheduler from posting new requests to the front
1556 * of the scheduler queue causing a starvation problem for currently
1557 * ongoing requests.
1560 static void scic_sds_port_post_dummy_request(struct scic_sds_port *sci_port)
1562 u32 command;
1563 struct scu_task_context *task_context;
1564 struct scic_sds_controller *scic = sci_port->owning_controller;
1565 u16 tci = sci_port->reserved_tci;
1567 task_context = scic_sds_controller_get_task_context_buffer(scic, tci);
1569 task_context->abort = 0;
1571 command = SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
1572 sci_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
1573 tci;
1575 scic_sds_controller_post_request(scic, command);
1579 * This routine will abort the dummy request. This will alow the hardware to
1580 * power down parts of the silicon to save power.
1582 * @sci_port: The port on which the task must be aborted.
1585 static void scic_sds_port_abort_dummy_request(struct scic_sds_port *sci_port)
1587 struct scic_sds_controller *scic = sci_port->owning_controller;
1588 u16 tci = sci_port->reserved_tci;
1589 struct scu_task_context *tc;
1590 u32 command;
1592 tc = scic_sds_controller_get_task_context_buffer(scic, tci);
1594 tc->abort = 1;
1596 command = SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT |
1597 sci_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
1598 tci;
1600 scic_sds_controller_post_request(scic, command);
1605 * @sci_port: This is the struct scic_sds_port object to resume.
1607 * This method will resume the port task scheduler for this port object. none
1609 static void
1610 scic_sds_port_resume_port_task_scheduler(struct scic_sds_port *port)
1612 u32 pts_control_value;
1614 pts_control_value = readl(&port->port_task_scheduler_registers->control);
1615 pts_control_value &= ~SCU_PTSxCR_GEN_BIT(SUSPEND);
1616 writel(pts_control_value, &port->port_task_scheduler_registers->control);
1620 * ******************************************************************************
1621 * * PORT READY SUBSTATE METHODS
1622 * ****************************************************************************** */
1626 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
1628 * This method will perform the actions required by the struct scic_sds_port on
1629 * entering the SCIC_SDS_PORT_READY_SUBSTATE_WAITING. This function checks the
1630 * port for any ready phys. If there is at least one phy in a ready state then
1631 * the port transitions to the ready operational substate. none
1633 static void scic_sds_port_ready_substate_waiting_enter(
1634 struct sci_base_object *object)
1636 struct scic_sds_port *sci_port = (struct scic_sds_port *)object;
1638 scic_sds_port_set_ready_state_handlers(
1639 sci_port, SCIC_SDS_PORT_READY_SUBSTATE_WAITING
1642 scic_sds_port_suspend_port_task_scheduler(sci_port);
1644 sci_port->not_ready_reason = SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS;
1646 if (sci_port->active_phy_mask != 0) {
1647 /* At least one of the phys on the port is ready */
1648 sci_base_state_machine_change_state(
1649 &sci_port->ready_substate_machine,
1650 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1657 * @object: This is the struct sci_base_object which is cast to a
1658 * struct scic_sds_port object.
1660 * This function will perform the actions required by the struct scic_sds_port
1661 * on entering the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function sets
1662 * the state handlers for the port object, notifies the SCI User that the port
1663 * is ready, and resumes port operations. none
1665 static void scic_sds_port_ready_substate_operational_enter(
1666 struct sci_base_object *object)
1668 u32 index;
1669 struct scic_sds_port *sci_port = (struct scic_sds_port *)object;
1670 struct scic_sds_controller *scic =
1671 scic_sds_port_get_controller(sci_port);
1672 struct isci_host *ihost = sci_object_get_association(scic);
1673 struct isci_port *iport = sci_object_get_association(sci_port);
1675 scic_sds_port_set_ready_state_handlers(
1676 sci_port,
1677 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
1679 isci_port_ready(ihost, iport);
1681 for (index = 0; index < SCI_MAX_PHYS; index++) {
1682 if (sci_port->phy_table[index]) {
1683 writel(sci_port->physical_port_index,
1684 &sci_port->port_pe_configuration_register[
1685 sci_port->phy_table[index]->phy_index]);
1689 scic_sds_port_update_viit_entry(sci_port);
1691 scic_sds_port_resume_port_task_scheduler(sci_port);
1694 * Post the dummy task for the port so the hardware can schedule
1695 * io correctly
1697 scic_sds_port_post_dummy_request(sci_port);
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 * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
1706 * the port not ready and suspends the port task scheduler. none
1708 static void scic_sds_port_ready_substate_operational_exit(
1709 struct sci_base_object *object)
1711 struct scic_sds_port *sci_port = (struct scic_sds_port *)object;
1712 struct scic_sds_controller *scic =
1713 scic_sds_port_get_controller(sci_port);
1714 struct isci_host *ihost = sci_object_get_association(scic);
1715 struct isci_port *iport = sci_object_get_association(sci_port);
1718 * Kill the dummy task for this port if it has not yet posted
1719 * the hardware will treat this as a NOP and just return abort
1720 * complete.
1722 scic_sds_port_abort_dummy_request(sci_port);
1724 isci_port_not_ready(ihost, iport);
1728 * ******************************************************************************
1729 * * PORT READY CONFIGURING METHODS
1730 * ****************************************************************************** */
1733 * scic_sds_port_ready_substate_configuring_enter() -
1734 * @object: This is the struct sci_base_object which is cast to a
1735 * struct scic_sds_port object.
1737 * This method will perform the actions required by the struct scic_sds_port on
1738 * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
1739 * the port not ready and suspends the port task scheduler. none
1741 static void scic_sds_port_ready_substate_configuring_enter(
1742 struct sci_base_object *object)
1744 struct scic_sds_port *sci_port = (struct scic_sds_port *)object;
1745 struct scic_sds_controller *scic =
1746 scic_sds_port_get_controller(sci_port);
1747 struct isci_host *ihost = sci_object_get_association(scic);
1748 struct isci_port *iport = sci_object_get_association(sci_port);
1750 scic_sds_port_set_ready_state_handlers(
1751 sci_port,
1752 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
1754 if (sci_port->active_phy_mask == 0) {
1755 isci_port_not_ready(ihost, iport);
1757 sci_base_state_machine_change_state(
1758 &sci_port->ready_substate_machine,
1759 SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
1760 } else if (sci_port->started_request_count == 0)
1761 sci_base_state_machine_change_state(
1762 &sci_port->ready_substate_machine,
1763 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
1766 static void scic_sds_port_ready_substate_configuring_exit(
1767 struct sci_base_object *object)
1769 struct scic_sds_port *sci_port = (struct scic_sds_port *)object;
1771 scic_sds_port_suspend_port_task_scheduler(sci_port);
1774 /* --------------------------------------------------------------------------- */
1776 static const struct sci_base_state scic_sds_port_ready_substate_table[] = {
1777 [SCIC_SDS_PORT_READY_SUBSTATE_WAITING] = {
1778 .enter_state = scic_sds_port_ready_substate_waiting_enter,
1780 [SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL] = {
1781 .enter_state = scic_sds_port_ready_substate_operational_enter,
1782 .exit_state = scic_sds_port_ready_substate_operational_exit
1784 [SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING] = {
1785 .enter_state = scic_sds_port_ready_substate_configuring_enter,
1786 .exit_state = scic_sds_port_ready_substate_configuring_exit
1792 * @port: This is the struct scic_sds_port object on which the io request count will
1793 * be decremented.
1794 * @device: This is the struct scic_sds_remote_device object to which the io request
1795 * is being directed. This parameter is not required to complete this
1796 * operation.
1797 * @io_request: This is the request that is being completed on this port
1798 * object. This parameter is not required to complete this operation.
1800 * This is a general complete io request handler for the struct scic_sds_port object.
1801 * enum sci_status SCI_SUCCESS
1803 static enum sci_status scic_sds_port_general_complete_io_handler(
1804 struct scic_sds_port *port,
1805 struct scic_sds_remote_device *device,
1806 struct scic_sds_request *io_request)
1808 scic_sds_port_decrement_request_count(port);
1810 return SCI_SUCCESS;
1814 * scic_sds_port_stopped_state_start_handler() - stop a port from "started"
1816 * @port: This is the struct scic_sds_port object which is cast into a
1817 * struct scic_sds_port object.
1819 * This function takes the struct scic_sds_port from a stopped state and
1820 * attempts to start it. To start a port it must have no assiged devices and
1821 * it must have at least one phy assigned to it. If those conditions are
1822 * met then the port can transition to the ready state.
1823 * enum sci_status
1824 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
1825 * This struct scic_sds_port object could not be started because the port
1826 * configuration is not valid.
1827 * SCI_SUCCESS
1828 * the start request is successful and the struct scic_sds_port object
1829 * has transitioned to the SCI_BASE_PORT_STATE_READY.
1831 static enum sci_status
1832 scic_sds_port_stopped_state_start_handler(struct scic_sds_port *sci_port)
1834 struct scic_sds_controller *scic = sci_port->owning_controller;
1835 struct isci_host *ihost = sci_object_get_association(scic);
1836 enum sci_status status = SCI_SUCCESS;
1837 u32 phy_mask;
1839 if (sci_port->assigned_device_count > 0) {
1841 * @todo This is a start failure operation because
1842 * there are still devices assigned to this port.
1843 * There must be no devices assigned to a port on a
1844 * start operation.
1846 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
1849 sci_port->timer_handle =
1850 isci_timer_create(ihost,
1851 sci_port,
1852 scic_sds_port_timeout_handler);
1854 if (!sci_port->timer_handle)
1855 return SCI_FAILURE_INSUFFICIENT_RESOURCES;
1857 if (sci_port->reserved_rni == SCU_DUMMY_INDEX) {
1858 u16 rni = scic_sds_remote_node_table_allocate_remote_node(
1859 &scic->available_remote_nodes, 1);
1861 if (rni != SCU_DUMMY_INDEX)
1862 scic_sds_port_construct_dummy_rnc(sci_port, rni);
1863 else
1864 status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
1865 sci_port->reserved_rni = rni;
1868 if (sci_port->reserved_tci == SCU_DUMMY_INDEX) {
1869 /* Allocate a TCI and remove the sequence nibble */
1870 u16 tci = scic_controller_allocate_io_tag(scic);
1872 if (tci != SCU_DUMMY_INDEX)
1873 scic_sds_port_construct_dummy_task(sci_port, tci);
1874 else
1875 status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
1876 sci_port->reserved_tci = tci;
1879 if (status == SCI_SUCCESS) {
1880 phy_mask = scic_sds_port_get_phys(sci_port);
1883 * There are one or more phys assigned to this port. Make sure
1884 * the port's phy mask is in fact legal and supported by the
1885 * silicon.
1887 if (scic_sds_port_is_phy_mask_valid(sci_port, phy_mask) == true) {
1888 sci_base_state_machine_change_state(
1889 &sci_port->state_machine,
1890 SCI_BASE_PORT_STATE_READY);
1892 return SCI_SUCCESS;
1893 } else
1894 status = SCI_FAILURE;
1897 if (status != SCI_SUCCESS)
1898 scic_sds_port_destroy_dummy_resources(sci_port);
1900 return status;
1904 * This method takes the struct scic_sds_port that is in a stopped state and handles a
1905 * stop request. This function takes no action. enum sci_status SCI_SUCCESS the
1906 * stop request is successful as the struct scic_sds_port object is already stopped.
1908 static enum sci_status scic_sds_port_stopped_state_stop_handler(
1909 struct scic_sds_port *port)
1911 /* We are already stopped so there is nothing to do here */
1912 return SCI_SUCCESS;
1916 * This method takes the struct scic_sds_port that is in a stopped state and handles
1917 * the destruct request. The stopped state is the only state in which the
1918 * struct scic_sds_port can be destroyed. This function causes the port object to
1919 * transition to the SCI_BASE_PORT_STATE_FINAL. enum sci_status SCI_SUCCESS
1921 static enum sci_status scic_sds_port_stopped_state_destruct_handler(
1922 struct scic_sds_port *port)
1924 sci_base_state_machine_stop(&port->state_machine);
1926 return SCI_SUCCESS;
1930 * This method takes the struct scic_sds_port that is in a stopped state and handles
1931 * the add phy request. In MPC mode the only time a phy can be added to a port
1932 * is in the SCI_BASE_PORT_STATE_STOPPED. enum sci_status
1933 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION is returned when the phy can not
1934 * be added to the port. SCI_SUCCESS if the phy is added to the port.
1936 static enum sci_status scic_sds_port_stopped_state_add_phy_handler(
1937 struct scic_sds_port *port,
1938 struct scic_sds_phy *phy)
1940 struct sci_sas_address port_sas_address;
1942 /* Read the port assigned SAS Address if there is one */
1943 scic_sds_port_get_sas_address(port, &port_sas_address);
1945 if (port_sas_address.high != 0 && port_sas_address.low != 0) {
1946 struct sci_sas_address phy_sas_address;
1949 * Make sure that the PHY SAS Address matches the SAS Address
1950 * for this port. */
1951 scic_sds_phy_get_sas_address(phy, &phy_sas_address);
1953 if (
1954 (port_sas_address.high != phy_sas_address.high)
1955 || (port_sas_address.low != phy_sas_address.low)
1957 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
1961 return scic_sds_port_set_phy(port, phy);
1965 * This method takes the struct scic_sds_port that is in a stopped state and handles
1966 * the remove phy request. In MPC mode the only time a phy can be removed from
1967 * a port is in the SCI_BASE_PORT_STATE_STOPPED. enum sci_status
1968 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION is returned when the phy can not
1969 * be added to the port. SCI_SUCCESS if the phy is added to the port.
1971 static enum sci_status scic_sds_port_stopped_state_remove_phy_handler(
1972 struct scic_sds_port *port,
1973 struct scic_sds_phy *phy)
1975 return scic_sds_port_clear_phy(port, phy);
1979 * ****************************************************************************
1980 * * READY STATE HANDLERS
1981 * **************************************************************************** */
1984 * ****************************************************************************
1985 * * RESETTING STATE HANDLERS
1986 * **************************************************************************** */
1989 * ****************************************************************************
1990 * * STOPPING STATE HANDLERS
1991 * **************************************************************************** */
1994 * This method takes the struct scic_sds_port that is in a stopping state and handles
1995 * the complete io request. Should the request count reach 0 then the port
1996 * object will transition to the stopped state. enum sci_status SCI_SUCCESS
1998 static enum sci_status scic_sds_port_stopping_state_complete_io_handler(
1999 struct scic_sds_port *sci_port,
2000 struct scic_sds_remote_device *device,
2001 struct scic_sds_request *io_request)
2003 scic_sds_port_decrement_request_count(sci_port);
2005 if (sci_port->started_request_count == 0) {
2006 sci_base_state_machine_change_state(&sci_port->state_machine,
2007 SCI_BASE_PORT_STATE_STOPPED);
2010 return SCI_SUCCESS;
2014 * ****************************************************************************
2015 * * RESETTING STATE HANDLERS
2016 * **************************************************************************** */
2020 * @port: This is the port object which is being requested to stop.
2022 * This method will stop a failed port. This causes a transition to the
2023 * stopping state. enum sci_status SCI_SUCCESS
2025 static enum sci_status scic_sds_port_reset_state_stop_handler(
2026 struct scic_sds_port *port)
2028 sci_base_state_machine_change_state(
2029 &port->state_machine,
2030 SCI_BASE_PORT_STATE_STOPPING
2033 return SCI_SUCCESS;
2037 * This method will transition a failed port to its ready state. The port
2038 * failed because a hard reset request timed out but at some time later one or
2039 * more phys in the port became ready. enum sci_status SCI_SUCCESS
2041 static void scic_sds_port_reset_state_link_up_handler(
2042 struct scic_sds_port *port,
2043 struct scic_sds_phy *phy)
2046 * / @todo We should make sure that the phy that has gone link up is the same
2047 * / one on which we sent the reset. It is possible that the phy on
2048 * / which we sent the reset is not the one that has gone link up and we
2049 * / want to make sure that phy being reset comes back. Consider the
2050 * / case where a reset is sent but before the hardware processes the
2051 * / reset it get a link up on the port because of a hot plug event.
2052 * / because of the reset request this phy will go link down almost
2053 * / immediately. */
2056 * In the resetting state we don't notify the user regarding
2057 * link up and link down notifications. */
2058 scic_sds_port_general_link_up_handler(port, phy, false);
2062 * This method process link down notifications that occur during a port reset
2063 * operation. Link downs can occur during the reset operation. enum sci_status
2064 * SCI_SUCCESS
2066 static void scic_sds_port_reset_state_link_down_handler(
2067 struct scic_sds_port *port,
2068 struct scic_sds_phy *phy)
2071 * In the resetting state we don't notify the user regarding
2072 * link up and link down notifications. */
2073 scic_sds_port_deactivate_phy(port, phy, false);
2076 static struct scic_sds_port_state_handler
2077 scic_sds_port_state_handler_table[SCI_BASE_PORT_MAX_STATES] =
2079 /* SCI_BASE_PORT_STATE_STOPPED */
2081 scic_sds_port_stopped_state_start_handler,
2082 scic_sds_port_stopped_state_stop_handler,
2083 scic_sds_port_stopped_state_destruct_handler,
2084 scic_sds_port_default_reset_handler,
2085 scic_sds_port_stopped_state_add_phy_handler,
2086 scic_sds_port_stopped_state_remove_phy_handler,
2087 scic_sds_port_default_frame_handler,
2088 scic_sds_port_default_event_handler,
2089 scic_sds_port_default_link_up_handler,
2090 scic_sds_port_default_link_down_handler,
2091 scic_sds_port_default_start_io_handler,
2092 scic_sds_port_default_complete_io_handler
2094 /* SCI_BASE_PORT_STATE_STOPPING */
2096 scic_sds_port_default_start_handler,
2097 scic_sds_port_default_stop_handler,
2098 scic_sds_port_default_destruct_handler,
2099 scic_sds_port_default_reset_handler,
2100 scic_sds_port_default_add_phy_handler,
2101 scic_sds_port_default_remove_phy_handler,
2102 scic_sds_port_default_frame_handler,
2103 scic_sds_port_default_event_handler,
2104 scic_sds_port_default_link_up_handler,
2105 scic_sds_port_default_link_down_handler,
2106 scic_sds_port_default_start_io_handler,
2107 scic_sds_port_stopping_state_complete_io_handler
2109 /* SCI_BASE_PORT_STATE_READY */
2111 scic_sds_port_default_start_handler,
2112 scic_sds_port_default_stop_handler,
2113 scic_sds_port_default_destruct_handler,
2114 scic_sds_port_default_reset_handler,
2115 scic_sds_port_default_add_phy_handler,
2116 scic_sds_port_default_remove_phy_handler,
2117 scic_sds_port_default_frame_handler,
2118 scic_sds_port_default_event_handler,
2119 scic_sds_port_default_link_up_handler,
2120 scic_sds_port_default_link_down_handler,
2121 scic_sds_port_default_start_io_handler,
2122 scic_sds_port_general_complete_io_handler
2124 /* SCI_BASE_PORT_STATE_RESETTING */
2126 scic_sds_port_default_start_handler,
2127 scic_sds_port_reset_state_stop_handler,
2128 scic_sds_port_default_destruct_handler,
2129 scic_sds_port_default_reset_handler,
2130 scic_sds_port_default_add_phy_handler,
2131 scic_sds_port_default_remove_phy_handler,
2132 scic_sds_port_default_frame_handler,
2133 scic_sds_port_default_event_handler,
2134 scic_sds_port_reset_state_link_up_handler,
2135 scic_sds_port_reset_state_link_down_handler,
2136 scic_sds_port_default_start_io_handler,
2137 scic_sds_port_general_complete_io_handler
2139 /* SCI_BASE_PORT_STATE_FAILED */
2141 scic_sds_port_default_start_handler,
2142 scic_sds_port_default_stop_handler,
2143 scic_sds_port_default_destruct_handler,
2144 scic_sds_port_default_reset_handler,
2145 scic_sds_port_default_add_phy_handler,
2146 scic_sds_port_default_remove_phy_handler,
2147 scic_sds_port_default_frame_handler,
2148 scic_sds_port_default_event_handler,
2149 scic_sds_port_default_link_up_handler,
2150 scic_sds_port_default_link_down_handler,
2151 scic_sds_port_default_start_io_handler,
2152 scic_sds_port_general_complete_io_handler
2157 * ******************************************************************************
2158 * * PORT STATE PRIVATE METHODS
2159 * ****************************************************************************** */
2163 * @sci_port: This is the port object which to suspend.
2165 * This method will enable the SCU Port Task Scheduler for this port object but
2166 * will leave the port task scheduler in a suspended state. none
2168 static void
2169 scic_sds_port_enable_port_task_scheduler(struct scic_sds_port *port)
2171 u32 pts_control_value;
2173 pts_control_value = readl(&port->port_task_scheduler_registers->control);
2174 pts_control_value |= SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND);
2175 writel(pts_control_value, &port->port_task_scheduler_registers->control);
2180 * @sci_port: This is the port object which to resume.
2182 * This method will disable the SCU port task scheduler for this port object.
2183 * none
2185 static void
2186 scic_sds_port_disable_port_task_scheduler(struct scic_sds_port *port)
2188 u32 pts_control_value;
2190 pts_control_value = readl(&port->port_task_scheduler_registers->control);
2191 pts_control_value &=
2192 ~(SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND));
2193 writel(pts_control_value, &port->port_task_scheduler_registers->control);
2196 static void scic_sds_port_post_dummy_remote_node(struct scic_sds_port *sci_port)
2198 struct scic_sds_controller *scic = sci_port->owning_controller;
2199 u8 phys_index = sci_port->physical_port_index;
2200 union scu_remote_node_context *rnc;
2201 u16 rni = sci_port->reserved_rni;
2202 u32 command;
2204 rnc = &scic->remote_node_context_table[rni];
2205 rnc->ssp.is_valid = true;
2207 command = SCU_CONTEXT_COMMAND_POST_RNC_32 |
2208 phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
2210 scic_sds_controller_post_request(scic, command);
2212 /* ensure hardware has seen the post rnc command and give it
2213 * ample time to act before sending the suspend
2215 readl(&scic->smu_registers->interrupt_status); /* flush */
2216 udelay(10);
2218 command = SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX |
2219 phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
2221 scic_sds_controller_post_request(scic, command);
2224 static void scic_sds_port_invalidate_dummy_remote_node(struct scic_sds_port *sci_port)
2226 struct scic_sds_controller *scic = sci_port->owning_controller;
2227 u8 phys_index = sci_port->physical_port_index;
2228 union scu_remote_node_context *rnc;
2229 u16 rni = sci_port->reserved_rni;
2230 u32 command;
2232 rnc = &scic->remote_node_context_table[rni];
2234 rnc->ssp.is_valid = false;
2236 /* ensure the preceding tc abort request has reached the
2237 * controller and give it ample time to act before posting the rnc
2238 * invalidate
2240 readl(&scic->smu_registers->interrupt_status); /* flush */
2241 udelay(10);
2243 command = SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE |
2244 phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
2246 scic_sds_controller_post_request(scic, command);
2250 * ******************************************************************************
2251 * * PORT STATE METHODS
2252 * ****************************************************************************** */
2256 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2258 * This method will perform the actions required by the struct scic_sds_port on
2259 * entering the SCI_BASE_PORT_STATE_STOPPED. This function sets the stopped
2260 * state handlers for the struct scic_sds_port object and disables the port task
2261 * scheduler in the hardware. none
2263 static void scic_sds_port_stopped_state_enter(
2264 struct sci_base_object *object)
2266 struct scic_sds_port *sci_port;
2268 sci_port = (struct scic_sds_port *)object;
2270 scic_sds_port_set_base_state_handlers(
2271 sci_port, SCI_BASE_PORT_STATE_STOPPED
2274 if (
2275 SCI_BASE_PORT_STATE_STOPPING
2276 == sci_port->state_machine.previous_state_id
2279 * If we enter this state becasuse of a request to stop
2280 * the port then we want to disable the hardwares port
2281 * task scheduler. */
2282 scic_sds_port_disable_port_task_scheduler(sci_port);
2288 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2290 * This method will perform the actions required by the struct scic_sds_port on
2291 * exiting the SCI_BASE_STATE_STOPPED. This function enables the SCU hardware
2292 * port task scheduler. none
2294 static void scic_sds_port_stopped_state_exit(
2295 struct sci_base_object *object)
2297 struct scic_sds_port *sci_port;
2299 sci_port = (struct scic_sds_port *)object;
2301 /* Enable and suspend the port task scheduler */
2302 scic_sds_port_enable_port_task_scheduler(sci_port);
2306 * scic_sds_port_ready_state_enter -
2307 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2309 * This method will perform the actions required by the struct scic_sds_port on
2310 * entering the SCI_BASE_PORT_STATE_READY. This function sets the ready state
2311 * handlers for the struct scic_sds_port object, reports the port object as
2312 * not ready and starts the ready substate machine. none
2314 static void scic_sds_port_ready_state_enter(struct sci_base_object *object)
2316 struct scic_sds_controller *scic;
2317 struct scic_sds_port *sci_port;
2318 struct isci_port *iport;
2319 struct isci_host *ihost;
2320 u32 prev_state;
2322 sci_port = container_of(object, typeof(*sci_port), parent);
2323 scic = scic_sds_port_get_controller(sci_port);
2324 ihost = sci_object_get_association(scic);
2325 iport = sci_object_get_association(sci_port);
2327 /* Put the ready state handlers in place though they will not be there long */
2328 scic_sds_port_set_base_state_handlers(sci_port, SCI_BASE_PORT_STATE_READY);
2330 prev_state = sci_port->state_machine.previous_state_id;
2331 if (prev_state == SCI_BASE_PORT_STATE_RESETTING)
2332 isci_port_hard_reset_complete(iport, SCI_SUCCESS);
2333 else
2334 isci_port_not_ready(ihost, iport);
2336 /* Post and suspend the dummy remote node context for this port. */
2337 scic_sds_port_post_dummy_remote_node(sci_port);
2339 /* Start the ready substate machine */
2340 sci_base_state_machine_start(&sci_port->ready_substate_machine);
2343 static void scic_sds_port_ready_state_exit(struct sci_base_object *object)
2345 struct scic_sds_port *sci_port;
2347 sci_port = container_of(object, typeof(*sci_port), parent);
2348 sci_base_state_machine_stop(&sci_port->ready_substate_machine);
2349 scic_sds_port_invalidate_dummy_remote_node(sci_port);
2354 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2356 * This method will perform the actions required by the struct scic_sds_port on
2357 * entering the SCI_BASE_PORT_STATE_RESETTING. This function sets the resetting
2358 * state handlers for the struct scic_sds_port object. none
2360 static void scic_sds_port_resetting_state_enter(
2361 struct sci_base_object *object)
2363 struct scic_sds_port *sci_port;
2365 sci_port = (struct scic_sds_port *)object;
2367 scic_sds_port_set_base_state_handlers(
2368 sci_port, SCI_BASE_PORT_STATE_RESETTING
2374 * @object: This is the struct sci_base_object which is cast to a
2375 * struct scic_sds_port object.
2377 * This function will perform the actions required by the
2378 * struct scic_sds_port on
2379 * exiting the SCI_BASE_STATE_RESETTING. This function does nothing. none
2381 static inline void scic_sds_port_resetting_state_exit(
2382 struct sci_base_object *object)
2384 struct scic_sds_port *sci_port = (struct scic_sds_port *)object;
2386 isci_timer_stop(sci_port->timer_handle);
2391 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2393 * This method will perform the actions required by the struct scic_sds_port on
2394 * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
2395 * state handlers for the struct scic_sds_port object. none
2397 static void scic_sds_port_stopping_state_enter(
2398 struct sci_base_object *object)
2400 struct scic_sds_port *sci_port;
2402 sci_port = (struct scic_sds_port *)object;
2404 scic_sds_port_set_base_state_handlers(
2405 sci_port, SCI_BASE_PORT_STATE_STOPPING
2411 * @object: This is the struct sci_base_object which is cast to a
2412 * struct scic_sds_port object.
2414 * This function will perform the actions required by the
2415 * struct scic_sds_port on
2416 * exiting the SCI_BASE_STATE_STOPPING. This function does nothing. none
2418 static inline void
2419 scic_sds_port_stopping_state_exit(struct sci_base_object *object)
2421 struct scic_sds_port *sci_port = (struct scic_sds_port *)object;
2423 isci_timer_stop(sci_port->timer_handle);
2425 scic_sds_port_destroy_dummy_resources(sci_port);
2430 * @object: This is the struct sci_base_object which is cast to a
2431 * struct scic_sds_port object.
2433 * This function will perform the actions required by the
2434 * struct scic_sds_port on
2435 * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
2436 * state handlers for the struct scic_sds_port object. none
2438 static void scic_sds_port_failed_state_enter(struct sci_base_object *object)
2440 struct scic_sds_port *sci_port = (struct scic_sds_port *)object;
2441 struct isci_port *iport = sci_object_get_association(sci_port);
2443 scic_sds_port_set_base_state_handlers(sci_port,
2444 SCI_BASE_PORT_STATE_FAILED);
2446 isci_port_hard_reset_complete(iport, SCI_FAILURE_TIMEOUT);
2449 /* --------------------------------------------------------------------------- */
2451 static const struct sci_base_state scic_sds_port_state_table[] = {
2452 [SCI_BASE_PORT_STATE_STOPPED] = {
2453 .enter_state = scic_sds_port_stopped_state_enter,
2454 .exit_state = scic_sds_port_stopped_state_exit
2456 [SCI_BASE_PORT_STATE_STOPPING] = {
2457 .enter_state = scic_sds_port_stopping_state_enter,
2458 .exit_state = scic_sds_port_stopping_state_exit
2460 [SCI_BASE_PORT_STATE_READY] = {
2461 .enter_state = scic_sds_port_ready_state_enter,
2462 .exit_state = scic_sds_port_ready_state_exit
2464 [SCI_BASE_PORT_STATE_RESETTING] = {
2465 .enter_state = scic_sds_port_resetting_state_enter,
2466 .exit_state = scic_sds_port_resetting_state_exit
2468 [SCI_BASE_PORT_STATE_FAILED] = {
2469 .enter_state = scic_sds_port_failed_state_enter,
2473 void scic_sds_port_construct(struct scic_sds_port *sci_port, u8 port_index,
2474 struct scic_sds_controller *scic)
2476 u32 index;
2478 sci_port->parent.private = NULL;
2479 sci_base_state_machine_construct(&sci_port->state_machine,
2480 &sci_port->parent,
2481 scic_sds_port_state_table,
2482 SCI_BASE_PORT_STATE_STOPPED);
2484 sci_base_state_machine_start(&sci_port->state_machine);
2486 sci_base_state_machine_construct(&sci_port->ready_substate_machine,
2487 &sci_port->parent,
2488 scic_sds_port_ready_substate_table,
2489 SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
2491 sci_port->logical_port_index = SCIC_SDS_DUMMY_PORT;
2492 sci_port->physical_port_index = port_index;
2493 sci_port->active_phy_mask = 0;
2495 sci_port->owning_controller = scic;
2497 sci_port->started_request_count = 0;
2498 sci_port->assigned_device_count = 0;
2500 sci_port->reserved_rni = SCU_DUMMY_INDEX;
2501 sci_port->reserved_tci = SCU_DUMMY_INDEX;
2503 sci_port->timer_handle = NULL;
2505 sci_port->port_task_scheduler_registers = NULL;
2507 for (index = 0; index < SCI_MAX_PHYS; index++)
2508 sci_port->phy_table[index] = NULL;