2 * This file is provided under a dual BSD/GPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
33 * * Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * * Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in
37 * the documentation and/or other materials provided with the
39 * * Neither the name of Intel Corporation nor the names of its
40 * contributors may be used to endorse or promote products derived
41 * from this software without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
44 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
45 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
46 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
47 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
50 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
51 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
53 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 #define SCIC_SDS_PORT_HARD_RESET_TIMEOUT (1000)
62 #define SCU_DUMMY_INDEX (0xFFFF)
64 static void isci_port_change_state(struct isci_port *iport, enum isci_status status)
68 dev_dbg(&iport->isci_host->pdev->dev,
69 "%s: iport = %p, state = 0x%x\n",
70 __func__, iport, status);
72 /* XXX pointless lock */
73 spin_lock_irqsave(&iport->state_lock, flags);
74 iport->status = status;
75 spin_unlock_irqrestore(&iport->state_lock, flags);
79 * This function will indicate which protocols are supported by this port.
80 * @sci_port: a handle corresponding to the SAS port for which to return the
81 * supported protocols.
82 * @protocols: This parameter specifies a pointer to a data structure
83 * which the core will copy the protocol values for the port from the
84 * transmit_identification register.
87 scic_sds_port_get_protocols(struct scic_sds_port *sci_port,
88 struct scic_phy_proto *protocols)
94 for (index = 0; index < SCI_MAX_PHYS; index++) {
95 if (sci_port->phy_table[index] != NULL) {
96 scic_sds_phy_get_protocols(sci_port->phy_table[index],
103 * This method requests a list (mask) of the phys contained in the supplied SAS
105 * @sci_port: a handle corresponding to the SAS port for which to return the
108 * Return a bit mask indicating which phys are a part of this port. Each bit
109 * corresponds to a phy identifier (e.g. bit 0 = phy id 0).
111 static u32 scic_sds_port_get_phys(struct scic_sds_port *sci_port)
118 for (index = 0; index < SCI_MAX_PHYS; index++) {
119 if (sci_port->phy_table[index] != NULL) {
120 mask |= (1 << index);
128 * scic_port_get_properties() - This method simply returns the properties
129 * regarding the port, such as: physical index, protocols, sas address, etc.
130 * @port: this parameter specifies the port for which to retrieve the physical
132 * @properties: This parameter specifies the properties structure into which to
133 * copy the requested information.
135 * Indicate if the user specified a valid port. SCI_SUCCESS This value is
136 * returned if the specified port was valid. SCI_FAILURE_INVALID_PORT This
137 * value is returned if the specified port is not valid. When this value is
138 * returned, no data is copied to the properties output parameter.
140 static enum sci_status scic_port_get_properties(struct scic_sds_port *port,
141 struct scic_port_properties *prop)
143 if ((port == NULL) ||
144 (port->logical_port_index == SCIC_SDS_DUMMY_PORT))
145 return SCI_FAILURE_INVALID_PORT;
147 prop->index = port->logical_port_index;
148 prop->phy_mask = scic_sds_port_get_phys(port);
149 scic_sds_port_get_sas_address(port, &prop->local.sas_address);
150 scic_sds_port_get_protocols(port, &prop->local.protocols);
151 scic_sds_port_get_attached_sas_address(port, &prop->remote.sas_address);
156 static void isci_port_link_up(struct isci_host *isci_host,
157 struct scic_sds_port *port,
158 struct scic_sds_phy *phy)
161 struct scic_port_properties properties;
162 struct isci_phy *isci_phy = sci_phy_to_iphy(phy);
163 struct isci_port *isci_port = sci_port_to_iport(port);
164 unsigned long success = true;
166 BUG_ON(isci_phy->isci_port != NULL);
168 isci_phy->isci_port = isci_port;
170 dev_dbg(&isci_host->pdev->dev,
171 "%s: isci_port = %p\n",
172 __func__, isci_port);
174 spin_lock_irqsave(&isci_phy->sas_phy.frame_rcvd_lock, flags);
176 isci_port_change_state(isci_phy->isci_port, isci_starting);
178 scic_port_get_properties(port, &properties);
180 if (phy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) {
181 u64 attached_sas_address;
183 isci_phy->sas_phy.oob_mode = SATA_OOB_MODE;
184 isci_phy->sas_phy.frame_rcvd_size = sizeof(struct dev_to_host_fis);
187 * For direct-attached SATA devices, the SCI core will
188 * automagically assign a SAS address to the end device
189 * for the purpose of creating a port. This SAS address
190 * will not be the same as assigned to the PHY and needs
191 * to be obtained from struct scic_port_properties properties.
193 attached_sas_address = properties.remote.sas_address.high;
194 attached_sas_address <<= 32;
195 attached_sas_address |= properties.remote.sas_address.low;
196 swab64s(&attached_sas_address);
198 memcpy(&isci_phy->sas_phy.attached_sas_addr,
199 &attached_sas_address, sizeof(attached_sas_address));
200 } else if (phy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
201 isci_phy->sas_phy.oob_mode = SAS_OOB_MODE;
202 isci_phy->sas_phy.frame_rcvd_size = sizeof(struct sas_identify_frame);
204 /* Copy the attached SAS address from the IAF */
205 memcpy(isci_phy->sas_phy.attached_sas_addr,
206 isci_phy->frame_rcvd.iaf.sas_addr, SAS_ADDR_SIZE);
208 dev_err(&isci_host->pdev->dev, "%s: unkown target\n", __func__);
212 isci_phy->sas_phy.phy->negotiated_linkrate = sci_phy_linkrate(phy);
214 spin_unlock_irqrestore(&isci_phy->sas_phy.frame_rcvd_lock, flags);
216 /* Notify libsas that we have an address frame, if indeed
217 * we've found an SSP, SMP, or STP target */
219 isci_host->sas_ha.notify_port_event(&isci_phy->sas_phy,
225 * isci_port_link_down() - This function is called by the sci core when a link
227 * @isci_host: This parameter specifies the isci host object.
228 * @phy: This parameter specifies the isci phy with the active link.
229 * @port: This parameter specifies the isci port with the active link.
232 static void isci_port_link_down(struct isci_host *isci_host,
233 struct isci_phy *isci_phy,
234 struct isci_port *isci_port)
236 struct isci_remote_device *isci_device;
238 dev_dbg(&isci_host->pdev->dev,
239 "%s: isci_port = %p\n", __func__, isci_port);
243 /* check to see if this is the last phy on this port. */
244 if (isci_phy->sas_phy.port
245 && isci_phy->sas_phy.port->num_phys == 1) {
247 /* change the state for all devices on this port.
248 * The next task sent to this device will be returned
249 * as SAS_TASK_UNDELIVERED, and the scsi mid layer
250 * will remove the target
252 list_for_each_entry(isci_device,
253 &isci_port->remote_dev_list,
255 dev_dbg(&isci_host->pdev->dev,
256 "%s: isci_device = %p\n",
257 __func__, isci_device);
258 isci_remote_device_change_state(isci_device,
262 isci_port_change_state(isci_port, isci_stopping);
265 /* Notify libsas of the borken link, this will trigger calls to our
266 * isci_port_deformed and isci_dev_gone functions.
268 sas_phy_disconnected(&isci_phy->sas_phy);
269 isci_host->sas_ha.notify_phy_event(&isci_phy->sas_phy,
270 PHYE_LOSS_OF_SIGNAL);
272 isci_phy->isci_port = NULL;
274 dev_dbg(&isci_host->pdev->dev,
275 "%s: isci_port = %p - Done\n", __func__, isci_port);
280 * isci_port_ready() - This function is called by the sci core when a link
282 * @isci_host: This parameter specifies the isci host object.
283 * @port: This parameter specifies the sci port with the active link.
286 static void isci_port_ready(struct isci_host *isci_host, struct isci_port *isci_port)
288 dev_dbg(&isci_host->pdev->dev,
289 "%s: isci_port = %p\n", __func__, isci_port);
291 complete_all(&isci_port->start_complete);
292 isci_port_change_state(isci_port, isci_ready);
297 * isci_port_not_ready() - This function is called by the sci core when a link
298 * is not ready. All remote devices on this link will be removed if they are
299 * in the stopping state.
300 * @isci_host: This parameter specifies the isci host object.
301 * @port: This parameter specifies the sci port with the active link.
304 static void isci_port_not_ready(struct isci_host *isci_host, struct isci_port *isci_port)
306 dev_dbg(&isci_host->pdev->dev,
307 "%s: isci_port = %p\n", __func__, isci_port);
310 static void isci_port_stop_complete(struct scic_sds_controller *scic,
311 struct scic_sds_port *sci_port,
312 enum sci_status completion_status)
314 dev_dbg(&scic_to_ihost(scic)->pdev->dev, "Port stop complete\n");
318 * isci_port_hard_reset_complete() - This function is called by the sci core
319 * when the hard reset complete notification has been received.
320 * @port: This parameter specifies the sci port with the active link.
321 * @completion_status: This parameter specifies the core status for the reset
325 static void isci_port_hard_reset_complete(struct isci_port *isci_port,
326 enum sci_status completion_status)
328 dev_dbg(&isci_port->isci_host->pdev->dev,
329 "%s: isci_port = %p, completion_status=%x\n",
330 __func__, isci_port, completion_status);
332 /* Save the status of the hard reset from the port. */
333 isci_port->hard_reset_status = completion_status;
335 complete_all(&isci_port->hard_reset_complete);
338 /* This method will return a true value if the specified phy can be assigned to
339 * this port The following is a list of phys for each port that are allowed: -
340 * Port 0 - 3 2 1 0 - Port 1 - 1 - Port 2 - 3 2 - Port 3 - 3 This method
341 * doesn't preclude all configurations. It merely ensures that a phy is part
342 * of the allowable set of phy identifiers for that port. For example, one
343 * could assign phy 3 to port 0 and no other phys. Please refer to
344 * scic_sds_port_is_phy_mask_valid() for information regarding whether the
345 * phy_mask for a port can be supported. bool true if this is a valid phy
346 * assignment for the port false if this is not a valid phy assignment for the
349 bool scic_sds_port_is_valid_phy_assignment(struct scic_sds_port *sci_port,
352 /* Initialize to invalid value. */
353 u32 existing_phy_index = SCI_MAX_PHYS;
356 if ((sci_port->physical_port_index == 1) && (phy_index != 1)) {
360 if (sci_port->physical_port_index == 3 && phy_index != 3) {
365 (sci_port->physical_port_index == 2)
366 && ((phy_index == 0) || (phy_index == 1))
371 for (index = 0; index < SCI_MAX_PHYS; index++) {
372 if ((sci_port->phy_table[index] != NULL)
373 && (index != phy_index)) {
374 existing_phy_index = index;
379 * Ensure that all of the phys in the port are capable of
380 * operating at the same maximum link rate. */
382 (existing_phy_index < SCI_MAX_PHYS)
383 && (sci_port->owning_controller->user_parameters.sds1.phys[
384 phy_index].max_speed_generation !=
385 sci_port->owning_controller->user_parameters.sds1.phys[
386 existing_phy_index].max_speed_generation)
395 * @sci_port: This is the port object for which to determine if the phy mask
398 * This method will return a true value if the port's phy mask can be supported
399 * by the SCU. The following is a list of valid PHY mask configurations for
400 * each port: - Port 0 - [[3 2] 1] 0 - Port 1 - [1] - Port 2 - [[3] 2]
401 * - Port 3 - [3] This method returns a boolean indication specifying if the
402 * phy mask can be supported. true if this is a valid phy assignment for the
403 * port false if this is not a valid phy assignment for the port
405 static bool scic_sds_port_is_phy_mask_valid(
406 struct scic_sds_port *sci_port,
409 if (sci_port->physical_port_index == 0) {
410 if (((phy_mask & 0x0F) == 0x0F)
411 || ((phy_mask & 0x03) == 0x03)
412 || ((phy_mask & 0x01) == 0x01)
415 } else if (sci_port->physical_port_index == 1) {
416 if (((phy_mask & 0x02) == 0x02)
419 } else if (sci_port->physical_port_index == 2) {
420 if (((phy_mask & 0x0C) == 0x0C)
421 || ((phy_mask & 0x04) == 0x04)
424 } else if (sci_port->physical_port_index == 3) {
425 if (((phy_mask & 0x08) == 0x08)
435 * @sci_port: This parameter specifies the port from which to return a
438 * This method retrieves a currently active (i.e. connected) phy contained in
439 * the port. Currently, the lowest order phy that is connected is returned.
440 * This method returns a pointer to a SCIS_SDS_PHY object. NULL This value is
441 * returned if there are no currently active (i.e. connected to a remote end
442 * point) phys contained in the port. All other values specify a struct scic_sds_phy
443 * object that is active in the port.
445 static struct scic_sds_phy *scic_sds_port_get_a_connected_phy(
446 struct scic_sds_port *sci_port
449 struct scic_sds_phy *phy;
451 for (index = 0; index < SCI_MAX_PHYS; index++) {
453 * Ensure that the phy is both part of the port and currently
454 * connected to the remote end-point. */
455 phy = sci_port->phy_table[index];
458 && scic_sds_port_active_phy(sci_port, phy)
468 * scic_sds_port_set_phy() -
469 * @out]: port The port object to which the phy assignement is being made.
470 * @out]: phy The phy which is being assigned to the port.
472 * This method attempts to make the assignment of the phy to the port. If
473 * successful the phy is assigned to the ports phy table. bool true if the phy
474 * assignment can be made. false if the phy assignement can not be made. This
475 * is a functional test that only fails if the phy is currently assigned to a
478 static enum sci_status scic_sds_port_set_phy(
479 struct scic_sds_port *port,
480 struct scic_sds_phy *phy)
483 * Check to see if we can add this phy to a port
484 * that means that the phy is not part of a port and that the port does
485 * not already have a phy assinged to the phy index. */
487 (port->phy_table[phy->phy_index] == NULL)
488 && (phy_get_non_dummy_port(phy) == NULL)
489 && scic_sds_port_is_valid_phy_assignment(port, phy->phy_index)
492 * Phy is being added in the stopped state so we are in MPC mode
493 * make logical port index = physical port index */
494 port->logical_port_index = port->physical_port_index;
495 port->phy_table[phy->phy_index] = phy;
496 scic_sds_phy_set_port(phy, port);
505 * scic_sds_port_clear_phy() -
506 * @out]: port The port from which the phy is being cleared.
507 * @out]: phy The phy being cleared from the port.
509 * This method will clear the phy assigned to this port. This method fails if
510 * this phy is not currently assinged to this port. bool true if the phy is
511 * removed from the port. false if this phy is not assined to this port.
513 static enum sci_status scic_sds_port_clear_phy(
514 struct scic_sds_port *port,
515 struct scic_sds_phy *phy)
517 /* Make sure that this phy is part of this port */
518 if (port->phy_table[phy->phy_index] == phy &&
519 phy_get_non_dummy_port(phy) == port) {
520 struct scic_sds_controller *scic = port->owning_controller;
521 struct isci_host *ihost = scic_to_ihost(scic);
523 /* Yep it is assigned to this port so remove it */
524 scic_sds_phy_set_port(phy, &ihost->ports[SCI_MAX_PORTS].sci);
525 port->phy_table[phy->phy_index] = NULL;
533 * scic_sds_port_add_phy() -
534 * @sci_port: This parameter specifies the port in which the phy will be added.
535 * @sci_phy: This parameter is the phy which is to be added to the port.
537 * This method will add a PHY to the selected port. This method returns an
538 * enum sci_status. SCI_SUCCESS the phy has been added to the port. Any other status
539 * is failre to add the phy to the port.
541 enum sci_status scic_sds_port_add_phy(
542 struct scic_sds_port *sci_port,
543 struct scic_sds_phy *sci_phy)
545 return sci_port->state_handlers->add_phy_handler(
551 * scic_sds_port_remove_phy() -
552 * @sci_port: This parameter specifies the port in which the phy will be added.
553 * @sci_phy: This parameter is the phy which is to be added to the port.
555 * This method will remove the PHY from the selected PORT. This method returns
556 * an enum sci_status. SCI_SUCCESS the phy has been removed from the port. Any other
557 * status is failre to add the phy to the port.
559 enum sci_status scic_sds_port_remove_phy(
560 struct scic_sds_port *sci_port,
561 struct scic_sds_phy *sci_phy)
563 return sci_port->state_handlers->remove_phy_handler(
568 * This method requests the SAS address for the supplied SAS port from the SCI
570 * @sci_port: a handle corresponding to the SAS port for which to return the
572 * @sas_address: This parameter specifies a pointer to a SAS address structure
573 * into which the core will copy the SAS address for the port.
576 void scic_sds_port_get_sas_address(
577 struct scic_sds_port *sci_port,
578 struct sci_sas_address *sas_address)
582 sas_address->high = 0;
583 sas_address->low = 0;
585 for (index = 0; index < SCI_MAX_PHYS; index++) {
586 if (sci_port->phy_table[index] != NULL) {
587 scic_sds_phy_get_sas_address(sci_port->phy_table[index], sas_address);
593 * This function requests the SAS address for the device directly attached to
595 * @sci_port: a handle corresponding to the SAS port for which to return the
597 * @sas_address: This parameter specifies a pointer to a SAS address structure
598 * into which the core will copy the SAS address for the device directly
599 * attached to the port.
602 void scic_sds_port_get_attached_sas_address(
603 struct scic_sds_port *sci_port,
604 struct sci_sas_address *sas_address)
606 struct scic_sds_phy *sci_phy;
609 * Ensure that the phy is both part of the port and currently
610 * connected to the remote end-point.
612 sci_phy = scic_sds_port_get_a_connected_phy(sci_port);
614 if (sci_phy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA) {
615 scic_sds_phy_get_attached_sas_address(sci_phy,
618 scic_sds_phy_get_sas_address(sci_phy, sas_address);
619 sas_address->low += sci_phy->phy_index;
622 sas_address->high = 0;
623 sas_address->low = 0;
628 * scic_sds_port_construct_dummy_rnc() - create dummy rnc for si workaround
630 * @sci_port: logical port on which we need to create the remote node context
631 * @rni: remote node index for this remote node context.
633 * This routine will construct a dummy remote node context data structure
634 * This structure will be posted to the hardware to work around a scheduler
635 * error in the hardware.
637 static void scic_sds_port_construct_dummy_rnc(struct scic_sds_port *sci_port, u16 rni)
639 union scu_remote_node_context *rnc;
641 rnc = &sci_port->owning_controller->remote_node_context_table[rni];
643 memset(rnc, 0, sizeof(union scu_remote_node_context));
645 rnc->ssp.remote_sas_address_hi = 0;
646 rnc->ssp.remote_sas_address_lo = 0;
648 rnc->ssp.remote_node_index = rni;
649 rnc->ssp.remote_node_port_width = 1;
650 rnc->ssp.logical_port_index = sci_port->physical_port_index;
652 rnc->ssp.nexus_loss_timer_enable = false;
653 rnc->ssp.check_bit = false;
654 rnc->ssp.is_valid = true;
655 rnc->ssp.is_remote_node_context = true;
656 rnc->ssp.function_number = 0;
657 rnc->ssp.arbitration_wait_time = 0;
661 * scic_sds_port_construct_dummy_task() - create dummy task for si workaround
662 * @sci_port The logical port on which we need to create the
663 * remote node context.
665 * @tci The remote node index for this remote node context.
667 * This routine will construct a dummy task context data structure. This
668 * structure will be posted to the hardwre to work around a scheduler error
672 static void scic_sds_port_construct_dummy_task(struct scic_sds_port *sci_port, u16 tci)
674 struct scu_task_context *task_context;
676 task_context = scic_sds_controller_get_task_context_buffer(sci_port->owning_controller, tci);
678 memset(task_context, 0, sizeof(struct scu_task_context));
680 task_context->abort = 0;
681 task_context->priority = 0;
682 task_context->initiator_request = 1;
683 task_context->connection_rate = 1;
684 task_context->protocol_engine_index = 0;
685 task_context->logical_port_index = sci_port->physical_port_index;
686 task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SSP;
687 task_context->task_index = scic_sds_io_tag_get_index(tci);
688 task_context->valid = SCU_TASK_CONTEXT_VALID;
689 task_context->context_type = SCU_TASK_CONTEXT_TYPE;
691 task_context->remote_node_index = sci_port->reserved_rni;
692 task_context->command_code = 0;
694 task_context->link_layer_control = 0;
695 task_context->do_not_dma_ssp_good_response = 1;
696 task_context->strict_ordering = 0;
697 task_context->control_frame = 0;
698 task_context->timeout_enable = 0;
699 task_context->block_guard_enable = 0;
701 task_context->address_modifier = 0;
703 task_context->task_phase = 0x01;
706 static void scic_sds_port_destroy_dummy_resources(struct scic_sds_port *sci_port)
708 struct scic_sds_controller *scic = sci_port->owning_controller;
710 if (sci_port->reserved_tci != SCU_DUMMY_INDEX)
711 scic_controller_free_io_tag(scic, sci_port->reserved_tci);
713 if (sci_port->reserved_rni != SCU_DUMMY_INDEX)
714 scic_sds_remote_node_table_release_remote_node_index(&scic->available_remote_nodes,
715 1, sci_port->reserved_rni);
717 sci_port->reserved_rni = SCU_DUMMY_INDEX;
718 sci_port->reserved_tci = SCU_DUMMY_INDEX;
722 * This method performs initialization of the supplied port. Initialization
723 * includes: - state machine initialization - member variable initialization
724 * - configuring the phy_mask
726 * @transport_layer_registers:
727 * @port_task_scheduler_registers:
728 * @port_configuration_regsiter:
730 * enum sci_status SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION This value is returned
731 * if the phy being added to the port
733 enum sci_status scic_sds_port_initialize(
734 struct scic_sds_port *sci_port,
735 void __iomem *port_task_scheduler_registers,
736 void __iomem *port_configuration_regsiter,
737 void __iomem *viit_registers)
739 sci_port->port_task_scheduler_registers = port_task_scheduler_registers;
740 sci_port->port_pe_configuration_register = port_configuration_regsiter;
741 sci_port->viit_registers = viit_registers;
747 * scic_port_hard_reset() - perform port hard reset
748 * @port: a handle corresponding to the SAS port to be hard reset.
749 * @reset_timeout: This parameter specifies the number of milliseconds in which
750 * the port reset operation should complete.
752 * The SCI User callback in scic_user_callbacks_t will only be called once for
753 * each phy in the SAS Port at completion of the hard reset sequence. Return a
754 * status indicating whether the hard reset started successfully. SCI_SUCCESS
755 * This value is returned if the hard reset operation started successfully.
757 static enum sci_status scic_port_hard_reset(struct scic_sds_port *port,
760 return port->state_handlers->reset_handler(
761 port, reset_timeout);
765 * This method assigns the direct attached device ID for this port.
767 * @param[in] sci_port The port for which the direct attached device id is to
769 * @param[in] device_id The direct attached device ID to assign to the port.
770 * This will be the RNi for the device
772 void scic_sds_port_setup_transports(
773 struct scic_sds_port *sci_port,
778 for (index = 0; index < SCI_MAX_PHYS; index++) {
779 if (sci_port->active_phy_mask & (1 << index))
780 scic_sds_phy_setup_transport(sci_port->phy_table[index], device_id);
786 * @sci_port: This is the port on which the phy should be enabled.
787 * @sci_phy: This is the specific phy which to enable.
788 * @do_notify_user: This parameter specifies whether to inform the user (via
789 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
791 * This function will activate the phy in the port.
792 * Activation includes: - adding
793 * the phy to the port - enabling the Protocol Engine in the silicon. -
794 * notifying the user that the link is up. none
796 static void scic_sds_port_activate_phy(struct scic_sds_port *sci_port,
797 struct scic_sds_phy *sci_phy,
800 struct scic_sds_controller *scic = sci_port->owning_controller;
801 struct isci_host *ihost = scic_to_ihost(scic);
803 if (sci_phy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA)
804 scic_sds_phy_resume(sci_phy);
806 sci_port->active_phy_mask |= 1 << sci_phy->phy_index;
808 scic_sds_controller_clear_invalid_phy(scic, sci_phy);
810 if (do_notify_user == true)
811 isci_port_link_up(ihost, sci_port, sci_phy);
814 void scic_sds_port_deactivate_phy(struct scic_sds_port *sci_port,
815 struct scic_sds_phy *sci_phy,
818 struct scic_sds_controller *scic = scic_sds_port_get_controller(sci_port);
819 struct isci_port *iport = sci_port_to_iport(sci_port);
820 struct isci_host *ihost = scic_to_ihost(scic);
821 struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
823 sci_port->active_phy_mask &= ~(1 << sci_phy->phy_index);
825 sci_phy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
827 /* Re-assign the phy back to the LP as if it were a narrow port */
828 writel(sci_phy->phy_index,
829 &sci_port->port_pe_configuration_register[sci_phy->phy_index]);
831 if (do_notify_user == true)
832 isci_port_link_down(ihost, iphy, iport);
837 * @sci_port: This is the port on which the phy should be disabled.
838 * @sci_phy: This is the specific phy which to disabled.
840 * This function will disable the phy and report that the phy is not valid for
841 * this port object. None
843 static void scic_sds_port_invalid_link_up(struct scic_sds_port *sci_port,
844 struct scic_sds_phy *sci_phy)
846 struct scic_sds_controller *scic = sci_port->owning_controller;
849 * Check to see if we have alreay reported this link as bad and if
850 * not go ahead and tell the SCI_USER that we have discovered an
853 if ((scic->invalid_phy_mask & (1 << sci_phy->phy_index)) == 0) {
854 scic_sds_controller_set_invalid_phy(scic, sci_phy);
855 dev_warn(&scic_to_ihost(scic)->pdev->dev, "Invalid link up!\n");
860 * scic_sds_port_general_link_up_handler - phy can be assigned to port?
861 * @sci_port: scic_sds_port object for which has a phy that has gone link up.
862 * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
863 * @do_notify_user: This parameter specifies whether to inform the user (via
864 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
866 * Determine if this phy can be assigned to this
867 * port . If the phy is not a valid PHY for
868 * this port then the function will notify the user. A PHY can only be
869 * part of a port if it's attached SAS ADDRESS is the same as all other PHYs in
870 * the same port. none
872 static void scic_sds_port_general_link_up_handler(struct scic_sds_port *sci_port,
873 struct scic_sds_phy *sci_phy,
876 struct sci_sas_address port_sas_address;
877 struct sci_sas_address phy_sas_address;
879 scic_sds_port_get_attached_sas_address(sci_port, &port_sas_address);
880 scic_sds_phy_get_attached_sas_address(sci_phy, &phy_sas_address);
882 /* If the SAS address of the new phy matches the SAS address of
883 * other phys in the port OR this is the first phy in the port,
884 * then activate the phy and allow it to be used for operations
887 if ((phy_sas_address.high == port_sas_address.high &&
888 phy_sas_address.low == port_sas_address.low) ||
889 sci_port->active_phy_mask == 0) {
890 struct sci_base_state_machine *sm = &sci_port->state_machine;
892 scic_sds_port_activate_phy(sci_port, sci_phy, do_notify_user);
893 if (sm->current_state_id == SCI_BASE_PORT_STATE_RESETTING)
894 sci_base_state_machine_change_state(sm, SCI_BASE_PORT_STATE_READY);
896 scic_sds_port_invalid_link_up(sci_port, sci_phy);
902 * This method returns false if the port only has a single phy object assigned.
903 * If there are no phys or more than one phy then the method will return
905 * @sci_port: The port for which the wide port condition is to be checked.
907 * bool true Is returned if this is a wide ported port. false Is returned if
908 * this is a narrow port.
910 static bool scic_sds_port_is_wide(struct scic_sds_port *sci_port)
915 for (index = 0; index < SCI_MAX_PHYS; index++) {
916 if (sci_port->phy_table[index] != NULL) {
921 return phy_count != 1;
925 * This method is called by the PHY object when the link is detected. if the
926 * port wants the PHY to continue on to the link up state then the port
927 * layer must return true. If the port object returns false the phy object
928 * must halt its attempt to go link up.
929 * @sci_port: The port associated with the phy object.
930 * @sci_phy: The phy object that is trying to go link up.
932 * true if the phy object can continue to the link up condition. true Is
933 * returned if this phy can continue to the ready state. false Is returned if
934 * can not continue on to the ready state. This notification is in place for
935 * wide ports and direct attached phys. Since there are no wide ported SATA
936 * devices this could become an invalid port configuration.
938 bool scic_sds_port_link_detected(
939 struct scic_sds_port *sci_port,
940 struct scic_sds_phy *sci_phy)
942 if ((sci_port->logical_port_index != SCIC_SDS_DUMMY_PORT) &&
943 (sci_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) &&
944 scic_sds_port_is_wide(sci_port)) {
945 scic_sds_port_invalid_link_up(sci_port, sci_phy);
954 * This method is the entry point for the phy to inform the port that it is now
960 void scic_sds_port_link_up(
961 struct scic_sds_port *sci_port,
962 struct scic_sds_phy *sci_phy)
964 sci_phy->is_in_link_training = false;
966 sci_port->state_handlers->link_up_handler(sci_port, sci_phy);
970 * This method is the entry point for the phy to inform the port that it is no
971 * longer in a ready state
976 void scic_sds_port_link_down(
977 struct scic_sds_port *sci_port,
978 struct scic_sds_phy *sci_phy)
980 sci_port->state_handlers->link_down_handler(sci_port, sci_phy);
984 * This method is called to start an IO request on this port.
991 enum sci_status scic_sds_port_start_io(
992 struct scic_sds_port *sci_port,
993 struct scic_sds_remote_device *sci_dev,
994 struct scic_sds_request *sci_req)
996 return sci_port->state_handlers->start_io_handler(
997 sci_port, sci_dev, sci_req);
1001 * This method is called to complete an IO request to the port.
1008 enum sci_status scic_sds_port_complete_io(
1009 struct scic_sds_port *sci_port,
1010 struct scic_sds_remote_device *sci_dev,
1011 struct scic_sds_request *sci_req)
1013 return sci_port->state_handlers->complete_io_handler(
1014 sci_port, sci_dev, sci_req);
1018 * This method is provided to timeout requests for port operations. Mostly its
1019 * for the port reset operation.
1023 static void scic_sds_port_timeout_handler(void *port)
1025 struct scic_sds_port *sci_port = port;
1028 current_state = sci_base_state_machine_get_state(
1029 &sci_port->state_machine);
1031 if (current_state == SCI_BASE_PORT_STATE_RESETTING) {
1033 * if the port is still in the resetting state then the
1034 * timeout fired before the reset completed.
1036 sci_base_state_machine_change_state(
1037 &sci_port->state_machine,
1038 SCI_BASE_PORT_STATE_FAILED);
1039 } else if (current_state == SCI_BASE_PORT_STATE_STOPPED) {
1041 * if the port is stopped then the start request failed
1042 * In this case stay in the stopped state.
1044 dev_err(sciport_to_dev(sci_port),
1045 "%s: SCIC Port 0x%p failed to stop before tiemout.\n",
1048 } else if (current_state == SCI_BASE_PORT_STATE_STOPPING) {
1050 * if the port is still stopping then the stop has not
1053 isci_port_stop_complete(
1054 scic_sds_port_get_controller(sci_port),
1056 SCI_FAILURE_TIMEOUT);
1059 * The port is in the ready state and we have a timer
1060 * reporting a timeout this should not happen.
1062 dev_err(sciport_to_dev(sci_port),
1063 "%s: SCIC Port 0x%p is processing a timeout operation "
1071 /* --------------------------------------------------------------------------- */
1074 * This function updates the hardwares VIIT entry for this port.
1078 static void scic_sds_port_update_viit_entry(struct scic_sds_port *sci_port)
1080 struct sci_sas_address sas_address;
1082 scic_sds_port_get_sas_address(sci_port, &sas_address);
1084 writel(sas_address.high,
1085 &sci_port->viit_registers->initiator_sas_address_hi);
1086 writel(sas_address.low,
1087 &sci_port->viit_registers->initiator_sas_address_lo);
1089 /* This value get cleared just in case its not already cleared */
1090 writel(0, &sci_port->viit_registers->reserved);
1092 /* We are required to update the status register last */
1093 writel(SCU_VIIT_ENTRY_ID_VIIT |
1094 SCU_VIIT_IPPT_INITIATOR |
1095 ((1 << sci_port->physical_port_index) << SCU_VIIT_ENTRY_LPVIE_SHIFT) |
1096 SCU_VIIT_STATUS_ALL_VALID,
1097 &sci_port->viit_registers->status);
1101 * This method returns the maximum allowed speed for data transfers on this
1102 * port. This maximum allowed speed evaluates to the maximum speed of the
1103 * slowest phy in the port.
1104 * @sci_port: This parameter specifies the port for which to retrieve the
1105 * maximum allowed speed.
1107 * This method returns the maximum negotiated speed of the slowest phy in the
1110 enum sas_linkrate scic_sds_port_get_max_allowed_speed(
1111 struct scic_sds_port *sci_port)
1114 enum sas_linkrate max_allowed_speed = SAS_LINK_RATE_6_0_GBPS;
1115 struct scic_sds_phy *phy = NULL;
1118 * Loop through all of the phys in this port and find the phy with the
1119 * lowest maximum link rate. */
1120 for (index = 0; index < SCI_MAX_PHYS; index++) {
1121 phy = sci_port->phy_table[index];
1124 && (scic_sds_port_active_phy(sci_port, phy) == true)
1125 && (phy->max_negotiated_speed < max_allowed_speed)
1127 max_allowed_speed = phy->max_negotiated_speed;
1130 return max_allowed_speed;
1133 static void scic_port_enable_broadcast_change_notification(struct scic_sds_port *port)
1135 struct scic_sds_phy *phy;
1139 /* Loop through all of the phys to enable BCN. */
1140 for (index = 0; index < SCI_MAX_PHYS; index++) {
1141 phy = port->phy_table[index];
1144 readl(&phy->link_layer_registers->link_layer_control);
1146 /* clear the bit by writing 1. */
1147 writel(register_value,
1148 &phy->link_layer_registers->link_layer_control);
1154 * ****************************************************************************
1155 * * READY SUBSTATE HANDLERS
1156 * **************************************************************************** */
1159 * This method is the general ready state stop handler for the struct scic_sds_port
1160 * object. This function will transition the ready substate machine to its
1161 * final state. enum sci_status SCI_SUCCESS
1163 static enum sci_status scic_sds_port_ready_substate_stop_handler(
1164 struct scic_sds_port *port)
1166 sci_base_state_machine_change_state(
1167 &port->state_machine,
1168 SCI_BASE_PORT_STATE_STOPPING
1175 * This method is the general ready substate complete io handler for the
1176 * struct scic_sds_port object. This function decrments the outstanding request count
1177 * for this port object. enum sci_status SCI_SUCCESS
1179 static enum sci_status scic_sds_port_ready_substate_complete_io_handler(
1180 struct scic_sds_port *port,
1181 struct scic_sds_remote_device *device,
1182 struct scic_sds_request *io_request)
1184 scic_sds_port_decrement_request_count(port);
1189 static enum sci_status scic_sds_port_ready_substate_add_phy_handler(
1190 struct scic_sds_port *port,
1191 struct scic_sds_phy *phy)
1193 enum sci_status status;
1195 status = scic_sds_port_set_phy(port, phy);
1197 if (status == SCI_SUCCESS) {
1198 scic_sds_port_general_link_up_handler(port, phy, true);
1200 port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
1202 sci_base_state_machine_change_state(
1203 &port->ready_substate_machine,
1204 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1212 static enum sci_status scic_sds_port_ready_substate_remove_phy_handler(
1213 struct scic_sds_port *port,
1214 struct scic_sds_phy *phy)
1216 enum sci_status status;
1218 status = scic_sds_port_clear_phy(port, phy);
1220 if (status == SCI_SUCCESS) {
1221 scic_sds_port_deactivate_phy(port, phy, true);
1223 port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
1225 sci_base_state_machine_change_state(
1226 &port->ready_substate_machine,
1227 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1235 * ****************************************************************************
1236 * * READY SUBSTATE WAITING HANDLERS
1237 * **************************************************************************** */
1241 * @sci_port: This is the struct scic_sds_port object that which has a phy that has
1243 * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
1245 * This method is the ready waiting substate link up handler for the
1246 * struct scic_sds_port object. This methos will report the link up condition for
1247 * this port and will transition to the ready operational substate. none
1249 static void scic_sds_port_ready_waiting_substate_link_up_handler(
1250 struct scic_sds_port *sci_port,
1251 struct scic_sds_phy *sci_phy)
1254 * Since this is the first phy going link up for the port we can just enable
1255 * it and continue. */
1256 scic_sds_port_activate_phy(sci_port, sci_phy, true);
1258 sci_base_state_machine_change_state(
1259 &sci_port->ready_substate_machine,
1260 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1265 * This method is the ready waiting substate start io handler for the
1266 * struct scic_sds_port object. The port object can not accept new requests so the
1267 * request is failed. enum sci_status SCI_FAILURE_INVALID_STATE
1269 static enum sci_status scic_sds_port_ready_waiting_substate_start_io_handler(
1270 struct scic_sds_port *port,
1271 struct scic_sds_remote_device *device,
1272 struct scic_sds_request *io_request)
1274 return SCI_FAILURE_INVALID_STATE;
1278 * ****************************************************************************
1279 * * READY SUBSTATE OPERATIONAL HANDLERS
1280 * **************************************************************************** */
1283 * This method will casue the port to reset. enum sci_status SCI_SUCCESS
1286 sci_status scic_sds_port_ready_operational_substate_reset_handler(
1287 struct scic_sds_port *port,
1290 enum sci_status status = SCI_FAILURE_INVALID_PHY;
1292 struct scic_sds_phy *selected_phy = NULL;
1295 /* Select a phy on which we can send the hard reset request. */
1297 (phy_index < SCI_MAX_PHYS) && (selected_phy == NULL);
1299 selected_phy = port->phy_table[phy_index];
1301 if ((selected_phy != NULL) &&
1302 !scic_sds_port_active_phy(port, selected_phy)) {
1304 * We found a phy but it is not ready select
1307 selected_phy = NULL;
1311 /* If we have a phy then go ahead and start the reset procedure */
1312 if (selected_phy != NULL) {
1313 status = scic_sds_phy_reset(selected_phy);
1315 if (status == SCI_SUCCESS) {
1316 isci_timer_start(port->timer_handle, timeout);
1317 port->not_ready_reason =
1318 SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED;
1320 sci_base_state_machine_change_state(
1321 &port->state_machine,
1322 SCI_BASE_PORT_STATE_RESETTING);
1330 * scic_sds_port_ready_operational_substate_link_up_handler() -
1331 * @sci_port: This is the struct scic_sds_port object that which has a phy that has
1333 * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
1335 * This method is the ready operational substate link up handler for the
1336 * struct scic_sds_port object. This function notifies the SCI User that the phy has
1337 * gone link up. none
1339 static void scic_sds_port_ready_operational_substate_link_up_handler(
1340 struct scic_sds_port *sci_port,
1341 struct scic_sds_phy *sci_phy)
1343 scic_sds_port_general_link_up_handler(sci_port, sci_phy, true);
1347 * scic_sds_port_ready_operational_substate_link_down_handler() -
1348 * @sci_port: This is the struct scic_sds_port object that which has a phy that has
1350 * @sci_phy: This is the struct scic_sds_phy object that has gone link down.
1352 * This method is the ready operational substate link down handler for the
1353 * struct scic_sds_port object. This function notifies the SCI User that the phy has
1354 * gone link down and if this is the last phy in the port the port will change
1355 * state to the ready waiting substate. none
1357 static void scic_sds_port_ready_operational_substate_link_down_handler(
1358 struct scic_sds_port *sci_port,
1359 struct scic_sds_phy *sci_phy)
1361 scic_sds_port_deactivate_phy(sci_port, sci_phy, true);
1364 * If there are no active phys left in the port, then transition
1365 * the port to the WAITING state until such time as a phy goes
1367 if (sci_port->active_phy_mask == 0)
1368 sci_base_state_machine_change_state(&sci_port->ready_substate_machine,
1369 SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
1373 * This method is the ready operational substate start io handler for the
1374 * struct scic_sds_port object. This function incremetns the outstanding request
1375 * count for this port object. enum sci_status SCI_SUCCESS
1377 static enum sci_status scic_sds_port_ready_operational_substate_start_io_handler(
1378 struct scic_sds_port *port,
1379 struct scic_sds_remote_device *device,
1380 struct scic_sds_request *io_request)
1382 port->started_request_count++;
1387 * ****************************************************************************
1388 * * READY SUBSTATE OPERATIONAL HANDLERS
1389 * **************************************************************************** */
1392 * This is the default method for a port add phy request. It will report a
1393 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1395 static enum sci_status scic_sds_port_ready_configuring_substate_add_phy_handler(
1396 struct scic_sds_port *port,
1397 struct scic_sds_phy *phy)
1399 enum sci_status status;
1401 status = scic_sds_port_set_phy(port, phy);
1403 if (status == SCI_SUCCESS) {
1404 scic_sds_port_general_link_up_handler(port, phy, true);
1407 * Re-enter the configuring state since this may be the last phy in
1409 sci_base_state_machine_change_state(
1410 &port->ready_substate_machine,
1411 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1419 * This is the default method for a port remove phy request. It will report a
1420 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1422 static enum sci_status scic_sds_port_ready_configuring_substate_remove_phy_handler(
1423 struct scic_sds_port *port,
1424 struct scic_sds_phy *phy)
1426 enum sci_status status;
1428 status = scic_sds_port_clear_phy(port, phy);
1430 if (status == SCI_SUCCESS) {
1431 scic_sds_port_deactivate_phy(port, phy, true);
1434 * Re-enter the configuring state since this may be the last phy in
1436 sci_base_state_machine_change_state(
1437 &port->ready_substate_machine,
1438 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1446 * scic_sds_port_ready_configuring_substate_complete_io_handler() -
1447 * @port: This is the port that is being requested to complete the io request.
1448 * @device: This is the device on which the io is completing.
1450 * This method will decrement the outstanding request count for this port. If
1451 * the request count goes to 0 then the port can be reprogrammed with its new
1454 static enum sci_status
1455 scic_sds_port_ready_configuring_substate_complete_io_handler(
1456 struct scic_sds_port *port,
1457 struct scic_sds_remote_device *device,
1458 struct scic_sds_request *io_request)
1460 scic_sds_port_decrement_request_count(port);
1462 if (port->started_request_count == 0) {
1463 sci_base_state_machine_change_state(
1464 &port->ready_substate_machine,
1465 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1472 static enum sci_status default_port_handler(struct scic_sds_port *sci_port,
1475 dev_warn(sciport_to_dev(sci_port),
1476 "%s: in wrong state: %d\n", func,
1477 sci_base_state_machine_get_state(&sci_port->state_machine));
1478 return SCI_FAILURE_INVALID_STATE;
1481 static enum sci_status
1482 scic_sds_port_default_start_handler(struct scic_sds_port *sci_port)
1484 return default_port_handler(sci_port, __func__);
1487 static enum sci_status
1488 scic_sds_port_default_stop_handler(struct scic_sds_port *sci_port)
1490 return default_port_handler(sci_port, __func__);
1493 static enum sci_status
1494 scic_sds_port_default_destruct_handler(struct scic_sds_port *sci_port)
1496 return default_port_handler(sci_port, __func__);
1499 static enum sci_status
1500 scic_sds_port_default_reset_handler(struct scic_sds_port *sci_port,
1503 return default_port_handler(sci_port, __func__);
1506 static enum sci_status
1507 scic_sds_port_default_add_phy_handler(struct scic_sds_port *sci_port,
1508 struct scic_sds_phy *base_phy)
1510 return default_port_handler(sci_port, __func__);
1513 static enum sci_status
1514 scic_sds_port_default_remove_phy_handler(struct scic_sds_port *sci_port,
1515 struct scic_sds_phy *base_phy)
1517 return default_port_handler(sci_port, __func__);
1521 * This is the default method for a port unsolicited frame request. It will
1522 * report a warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE Is it even
1523 * possible to receive an unsolicited frame directed to a port object? It
1524 * seems possible if we implementing virtual functions but until then?
1526 static enum sci_status
1527 scic_sds_port_default_frame_handler(struct scic_sds_port *sci_port,
1530 struct scic_sds_controller *scic = scic_sds_port_get_controller(sci_port);
1532 default_port_handler(sci_port, __func__);
1533 scic_sds_controller_release_frame(scic, frame_index);
1535 return SCI_FAILURE_INVALID_STATE;
1538 static enum sci_status scic_sds_port_default_event_handler(struct scic_sds_port *sci_port,
1541 return default_port_handler(sci_port, __func__);
1544 static void scic_sds_port_default_link_up_handler(struct scic_sds_port *sci_port,
1545 struct scic_sds_phy *sci_phy)
1547 default_port_handler(sci_port, __func__);
1550 static void scic_sds_port_default_link_down_handler(struct scic_sds_port *sci_port,
1551 struct scic_sds_phy *sci_phy)
1553 default_port_handler(sci_port, __func__);
1556 static enum sci_status scic_sds_port_default_start_io_handler(struct scic_sds_port *sci_port,
1557 struct scic_sds_remote_device *sci_dev,
1558 struct scic_sds_request *sci_req)
1560 return default_port_handler(sci_port, __func__);
1563 static enum sci_status scic_sds_port_default_complete_io_handler(struct scic_sds_port *sci_port,
1564 struct scic_sds_remote_device *sci_dev,
1565 struct scic_sds_request *sci_req)
1567 return default_port_handler(sci_port, __func__);
1570 static struct scic_sds_port_state_handler scic_sds_port_ready_substate_handler_table[] = {
1571 [SCIC_SDS_PORT_READY_SUBSTATE_WAITING] = {
1572 .start_handler = scic_sds_port_default_start_handler,
1573 .stop_handler = scic_sds_port_ready_substate_stop_handler,
1574 .destruct_handler = scic_sds_port_default_destruct_handler,
1575 .reset_handler = scic_sds_port_default_reset_handler,
1576 .add_phy_handler = scic_sds_port_ready_substate_add_phy_handler,
1577 .remove_phy_handler = scic_sds_port_default_remove_phy_handler,
1578 .frame_handler = scic_sds_port_default_frame_handler,
1579 .event_handler = scic_sds_port_default_event_handler,
1580 .link_up_handler = scic_sds_port_ready_waiting_substate_link_up_handler,
1581 .link_down_handler = scic_sds_port_default_link_down_handler,
1582 .start_io_handler = scic_sds_port_ready_waiting_substate_start_io_handler,
1583 .complete_io_handler = scic_sds_port_ready_substate_complete_io_handler,
1585 [SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL] = {
1586 .start_handler = scic_sds_port_default_start_handler,
1587 .stop_handler = scic_sds_port_ready_substate_stop_handler,
1588 .destruct_handler = scic_sds_port_default_destruct_handler,
1589 .reset_handler = scic_sds_port_ready_operational_substate_reset_handler,
1590 .add_phy_handler = scic_sds_port_ready_substate_add_phy_handler,
1591 .remove_phy_handler = scic_sds_port_ready_substate_remove_phy_handler,
1592 .frame_handler = scic_sds_port_default_frame_handler,
1593 .event_handler = scic_sds_port_default_event_handler,
1594 .link_up_handler = scic_sds_port_ready_operational_substate_link_up_handler,
1595 .link_down_handler = scic_sds_port_ready_operational_substate_link_down_handler,
1596 .start_io_handler = scic_sds_port_ready_operational_substate_start_io_handler,
1597 .complete_io_handler = scic_sds_port_ready_substate_complete_io_handler,
1599 [SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING] = {
1600 .start_handler = scic_sds_port_default_start_handler,
1601 .stop_handler = scic_sds_port_ready_substate_stop_handler,
1602 .destruct_handler = scic_sds_port_default_destruct_handler,
1603 .reset_handler = scic_sds_port_default_reset_handler,
1604 .add_phy_handler = scic_sds_port_ready_configuring_substate_add_phy_handler,
1605 .remove_phy_handler = scic_sds_port_ready_configuring_substate_remove_phy_handler,
1606 .frame_handler = scic_sds_port_default_frame_handler,
1607 .event_handler = scic_sds_port_default_event_handler,
1608 .link_up_handler = scic_sds_port_default_link_up_handler,
1609 .link_down_handler = scic_sds_port_default_link_down_handler,
1610 .start_io_handler = scic_sds_port_default_start_io_handler,
1611 .complete_io_handler = scic_sds_port_ready_configuring_substate_complete_io_handler
1616 * scic_sds_port_set_ready_state_handlers() -
1618 * This macro sets the port ready substate handlers.
1620 #define scic_sds_port_set_ready_state_handlers(port, state_id) \
1621 scic_sds_port_set_state_handlers(\
1622 port, &scic_sds_port_ready_substate_handler_table[(state_id)] \
1626 * ******************************************************************************
1627 * * PORT STATE PRIVATE METHODS
1628 * ****************************************************************************** */
1632 * @sci_port: This is the struct scic_sds_port object to suspend.
1634 * This method will susped the port task scheduler for this port object. none
1637 scic_sds_port_suspend_port_task_scheduler(struct scic_sds_port *port)
1639 u32 pts_control_value;
1641 pts_control_value = readl(&port->port_task_scheduler_registers->control);
1642 pts_control_value |= SCU_PTSxCR_GEN_BIT(SUSPEND);
1643 writel(pts_control_value, &port->port_task_scheduler_registers->control);
1647 * scic_sds_port_post_dummy_request() - post dummy/workaround request
1648 * @sci_port: port to post task
1650 * Prevent the hardware scheduler from posting new requests to the front
1651 * of the scheduler queue causing a starvation problem for currently
1655 static void scic_sds_port_post_dummy_request(struct scic_sds_port *sci_port)
1658 struct scu_task_context *task_context;
1659 struct scic_sds_controller *scic = sci_port->owning_controller;
1660 u16 tci = sci_port->reserved_tci;
1662 task_context = scic_sds_controller_get_task_context_buffer(scic, tci);
1664 task_context->abort = 0;
1666 command = SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
1667 sci_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
1670 scic_sds_controller_post_request(scic, command);
1674 * This routine will abort the dummy request. This will alow the hardware to
1675 * power down parts of the silicon to save power.
1677 * @sci_port: The port on which the task must be aborted.
1680 static void scic_sds_port_abort_dummy_request(struct scic_sds_port *sci_port)
1682 struct scic_sds_controller *scic = sci_port->owning_controller;
1683 u16 tci = sci_port->reserved_tci;
1684 struct scu_task_context *tc;
1687 tc = scic_sds_controller_get_task_context_buffer(scic, tci);
1691 command = SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT |
1692 sci_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
1695 scic_sds_controller_post_request(scic, command);
1700 * @sci_port: This is the struct scic_sds_port object to resume.
1702 * This method will resume the port task scheduler for this port object. none
1705 scic_sds_port_resume_port_task_scheduler(struct scic_sds_port *port)
1707 u32 pts_control_value;
1709 pts_control_value = readl(&port->port_task_scheduler_registers->control);
1710 pts_control_value &= ~SCU_PTSxCR_GEN_BIT(SUSPEND);
1711 writel(pts_control_value, &port->port_task_scheduler_registers->control);
1715 * ******************************************************************************
1716 * * PORT READY SUBSTATE METHODS
1717 * ****************************************************************************** */
1721 * @object: This is the object which is cast to a struct scic_sds_port object.
1723 * This method will perform the actions required by the struct scic_sds_port on
1724 * entering the SCIC_SDS_PORT_READY_SUBSTATE_WAITING. This function checks the
1725 * port for any ready phys. If there is at least one phy in a ready state then
1726 * the port transitions to the ready operational substate. none
1728 static void scic_sds_port_ready_substate_waiting_enter(void *object)
1730 struct scic_sds_port *sci_port = object;
1732 scic_sds_port_set_ready_state_handlers(
1733 sci_port, SCIC_SDS_PORT_READY_SUBSTATE_WAITING
1736 scic_sds_port_suspend_port_task_scheduler(sci_port);
1738 sci_port->not_ready_reason = SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS;
1740 if (sci_port->active_phy_mask != 0) {
1741 /* At least one of the phys on the port is ready */
1742 sci_base_state_machine_change_state(
1743 &sci_port->ready_substate_machine,
1744 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1751 * @object: This is the object which is cast to a struct scic_sds_port object.
1753 * This function will perform the actions required by the struct scic_sds_port
1754 * on entering the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function sets
1755 * the state handlers for the port object, notifies the SCI User that the port
1756 * is ready, and resumes port operations. none
1758 static void scic_sds_port_ready_substate_operational_enter(void *object)
1761 struct scic_sds_port *sci_port = object;
1762 struct scic_sds_controller *scic = sci_port->owning_controller;
1763 struct isci_host *ihost = scic_to_ihost(scic);
1764 struct isci_port *iport = sci_port_to_iport(sci_port);
1766 scic_sds_port_set_ready_state_handlers(
1768 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
1770 isci_port_ready(ihost, iport);
1772 for (index = 0; index < SCI_MAX_PHYS; index++) {
1773 if (sci_port->phy_table[index]) {
1774 writel(sci_port->physical_port_index,
1775 &sci_port->port_pe_configuration_register[
1776 sci_port->phy_table[index]->phy_index]);
1780 scic_sds_port_update_viit_entry(sci_port);
1782 scic_sds_port_resume_port_task_scheduler(sci_port);
1785 * Post the dummy task for the port so the hardware can schedule
1788 scic_sds_port_post_dummy_request(sci_port);
1793 * @object: This is the object which is cast to a struct scic_sds_port object.
1795 * This method will perform the actions required by the struct scic_sds_port on
1796 * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
1797 * the port not ready and suspends the port task scheduler. none
1799 static void scic_sds_port_ready_substate_operational_exit(void *object)
1801 struct scic_sds_port *sci_port = object;
1802 struct scic_sds_controller *scic = sci_port->owning_controller;
1803 struct isci_host *ihost = scic_to_ihost(scic);
1804 struct isci_port *iport = sci_port_to_iport(sci_port);
1807 * Kill the dummy task for this port if it has not yet posted
1808 * the hardware will treat this as a NOP and just return abort
1811 scic_sds_port_abort_dummy_request(sci_port);
1813 isci_port_not_ready(ihost, iport);
1817 * ******************************************************************************
1818 * * PORT READY CONFIGURING METHODS
1819 * ****************************************************************************** */
1822 * scic_sds_port_ready_substate_configuring_enter() -
1823 * @object: This is the object which is cast to a struct scic_sds_port object.
1825 * This method will perform the actions required by the struct scic_sds_port on
1826 * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
1827 * the port not ready and suspends the port task scheduler. none
1829 static void scic_sds_port_ready_substate_configuring_enter(void *object)
1831 struct scic_sds_port *sci_port = object;
1832 struct scic_sds_controller *scic = sci_port->owning_controller;
1833 struct isci_host *ihost = scic_to_ihost(scic);
1834 struct isci_port *iport = sci_port_to_iport(sci_port);
1836 scic_sds_port_set_ready_state_handlers(
1838 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
1840 if (sci_port->active_phy_mask == 0) {
1841 isci_port_not_ready(ihost, iport);
1843 sci_base_state_machine_change_state(
1844 &sci_port->ready_substate_machine,
1845 SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
1846 } else if (sci_port->started_request_count == 0)
1847 sci_base_state_machine_change_state(
1848 &sci_port->ready_substate_machine,
1849 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
1852 static void scic_sds_port_ready_substate_configuring_exit(void *object)
1854 struct scic_sds_port *sci_port = object;
1856 scic_sds_port_suspend_port_task_scheduler(sci_port);
1859 /* --------------------------------------------------------------------------- */
1861 static const struct sci_base_state scic_sds_port_ready_substate_table[] = {
1862 [SCIC_SDS_PORT_READY_SUBSTATE_WAITING] = {
1863 .enter_state = scic_sds_port_ready_substate_waiting_enter,
1865 [SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL] = {
1866 .enter_state = scic_sds_port_ready_substate_operational_enter,
1867 .exit_state = scic_sds_port_ready_substate_operational_exit
1869 [SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING] = {
1870 .enter_state = scic_sds_port_ready_substate_configuring_enter,
1871 .exit_state = scic_sds_port_ready_substate_configuring_exit
1877 * @port: This is the struct scic_sds_port object on which the io request count will
1879 * @device: This is the struct scic_sds_remote_device object to which the io request
1880 * is being directed. This parameter is not required to complete this
1882 * @io_request: This is the request that is being completed on this port
1883 * object. This parameter is not required to complete this operation.
1885 * This is a general complete io request handler for the struct scic_sds_port object.
1886 * enum sci_status SCI_SUCCESS
1888 static enum sci_status scic_sds_port_general_complete_io_handler(
1889 struct scic_sds_port *port,
1890 struct scic_sds_remote_device *device,
1891 struct scic_sds_request *io_request)
1893 scic_sds_port_decrement_request_count(port);
1899 * scic_sds_port_stopped_state_start_handler() - stop a port from "started"
1901 * @port: This is the struct scic_sds_port object which is cast into a
1902 * struct scic_sds_port object.
1904 * This function takes the struct scic_sds_port from a stopped state and
1905 * attempts to start it. To start a port it must have no assiged devices and
1906 * it must have at least one phy assigned to it. If those conditions are
1907 * met then the port can transition to the ready state.
1909 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
1910 * This struct scic_sds_port object could not be started because the port
1911 * configuration is not valid.
1913 * the start request is successful and the struct scic_sds_port object
1914 * has transitioned to the SCI_BASE_PORT_STATE_READY.
1916 static enum sci_status
1917 scic_sds_port_stopped_state_start_handler(struct scic_sds_port *sci_port)
1919 struct scic_sds_controller *scic = sci_port->owning_controller;
1920 struct isci_host *ihost = scic_to_ihost(scic);
1921 enum sci_status status = SCI_SUCCESS;
1924 if (sci_port->assigned_device_count > 0) {
1926 * @todo This is a start failure operation because
1927 * there are still devices assigned to this port.
1928 * There must be no devices assigned to a port on a
1931 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
1934 sci_port->timer_handle =
1935 isci_timer_create(ihost,
1937 scic_sds_port_timeout_handler);
1939 if (!sci_port->timer_handle)
1940 return SCI_FAILURE_INSUFFICIENT_RESOURCES;
1942 if (sci_port->reserved_rni == SCU_DUMMY_INDEX) {
1943 u16 rni = scic_sds_remote_node_table_allocate_remote_node(
1944 &scic->available_remote_nodes, 1);
1946 if (rni != SCU_DUMMY_INDEX)
1947 scic_sds_port_construct_dummy_rnc(sci_port, rni);
1949 status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
1950 sci_port->reserved_rni = rni;
1953 if (sci_port->reserved_tci == SCU_DUMMY_INDEX) {
1954 /* Allocate a TCI and remove the sequence nibble */
1955 u16 tci = scic_controller_allocate_io_tag(scic);
1957 if (tci != SCU_DUMMY_INDEX)
1958 scic_sds_port_construct_dummy_task(sci_port, tci);
1960 status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
1961 sci_port->reserved_tci = tci;
1964 if (status == SCI_SUCCESS) {
1965 phy_mask = scic_sds_port_get_phys(sci_port);
1968 * There are one or more phys assigned to this port. Make sure
1969 * the port's phy mask is in fact legal and supported by the
1972 if (scic_sds_port_is_phy_mask_valid(sci_port, phy_mask) == true) {
1973 sci_base_state_machine_change_state(
1974 &sci_port->state_machine,
1975 SCI_BASE_PORT_STATE_READY);
1979 status = SCI_FAILURE;
1982 if (status != SCI_SUCCESS)
1983 scic_sds_port_destroy_dummy_resources(sci_port);
1989 * This method takes the struct scic_sds_port that is in a stopped state and handles a
1990 * stop request. This function takes no action. enum sci_status SCI_SUCCESS the
1991 * stop request is successful as the struct scic_sds_port object is already stopped.
1993 static enum sci_status scic_sds_port_stopped_state_stop_handler(
1994 struct scic_sds_port *port)
1996 /* We are already stopped so there is nothing to do here */
2001 * This method takes the struct scic_sds_port that is in a stopped state and handles
2002 * the destruct request. The stopped state is the only state in which the
2003 * struct scic_sds_port can be destroyed. This function causes the port object to
2004 * transition to the SCI_BASE_PORT_STATE_FINAL. enum sci_status SCI_SUCCESS
2006 static enum sci_status scic_sds_port_stopped_state_destruct_handler(
2007 struct scic_sds_port *port)
2009 sci_base_state_machine_stop(&port->state_machine);
2015 * This method takes the struct scic_sds_port that is in a stopped state and handles
2016 * the add phy request. In MPC mode the only time a phy can be added to a port
2017 * is in the SCI_BASE_PORT_STATE_STOPPED. enum sci_status
2018 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION is returned when the phy can not
2019 * be added to the port. SCI_SUCCESS if the phy is added to the port.
2021 static enum sci_status scic_sds_port_stopped_state_add_phy_handler(
2022 struct scic_sds_port *port,
2023 struct scic_sds_phy *phy)
2025 struct sci_sas_address port_sas_address;
2027 /* Read the port assigned SAS Address if there is one */
2028 scic_sds_port_get_sas_address(port, &port_sas_address);
2030 if (port_sas_address.high != 0 && port_sas_address.low != 0) {
2031 struct sci_sas_address phy_sas_address;
2034 * Make sure that the PHY SAS Address matches the SAS Address
2036 scic_sds_phy_get_sas_address(phy, &phy_sas_address);
2039 (port_sas_address.high != phy_sas_address.high)
2040 || (port_sas_address.low != phy_sas_address.low)
2042 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
2046 return scic_sds_port_set_phy(port, phy);
2050 * This method takes the struct scic_sds_port that is in a stopped state and handles
2051 * the remove phy request. In MPC mode the only time a phy can be removed from
2052 * a port is in the SCI_BASE_PORT_STATE_STOPPED. enum sci_status
2053 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION is returned when the phy can not
2054 * be added to the port. SCI_SUCCESS if the phy is added to the port.
2056 static enum sci_status scic_sds_port_stopped_state_remove_phy_handler(
2057 struct scic_sds_port *port,
2058 struct scic_sds_phy *phy)
2060 return scic_sds_port_clear_phy(port, phy);
2064 * ****************************************************************************
2065 * * READY STATE HANDLERS
2066 * **************************************************************************** */
2069 * ****************************************************************************
2070 * * RESETTING STATE HANDLERS
2071 * **************************************************************************** */
2074 * ****************************************************************************
2075 * * STOPPING STATE HANDLERS
2076 * **************************************************************************** */
2079 * This method takes the struct scic_sds_port that is in a stopping state and handles
2080 * the complete io request. Should the request count reach 0 then the port
2081 * object will transition to the stopped state. enum sci_status SCI_SUCCESS
2083 static enum sci_status scic_sds_port_stopping_state_complete_io_handler(
2084 struct scic_sds_port *sci_port,
2085 struct scic_sds_remote_device *device,
2086 struct scic_sds_request *io_request)
2088 scic_sds_port_decrement_request_count(sci_port);
2090 if (sci_port->started_request_count == 0) {
2091 sci_base_state_machine_change_state(&sci_port->state_machine,
2092 SCI_BASE_PORT_STATE_STOPPED);
2099 * ****************************************************************************
2100 * * RESETTING STATE HANDLERS
2101 * **************************************************************************** */
2105 * @port: This is the port object which is being requested to stop.
2107 * This method will stop a failed port. This causes a transition to the
2108 * stopping state. enum sci_status SCI_SUCCESS
2110 static enum sci_status scic_sds_port_reset_state_stop_handler(
2111 struct scic_sds_port *port)
2113 sci_base_state_machine_change_state(
2114 &port->state_machine,
2115 SCI_BASE_PORT_STATE_STOPPING
2122 * This method will transition a failed port to its ready state. The port
2123 * failed because a hard reset request timed out but at some time later one or
2124 * more phys in the port became ready. enum sci_status SCI_SUCCESS
2126 static void scic_sds_port_reset_state_link_up_handler(
2127 struct scic_sds_port *port,
2128 struct scic_sds_phy *phy)
2131 * / @todo We should make sure that the phy that has gone link up is the same
2132 * / one on which we sent the reset. It is possible that the phy on
2133 * / which we sent the reset is not the one that has gone link up and we
2134 * / want to make sure that phy being reset comes back. Consider the
2135 * / case where a reset is sent but before the hardware processes the
2136 * / reset it get a link up on the port because of a hot plug event.
2137 * / because of the reset request this phy will go link down almost
2141 * In the resetting state we don't notify the user regarding
2142 * link up and link down notifications. */
2143 scic_sds_port_general_link_up_handler(port, phy, false);
2147 * This method process link down notifications that occur during a port reset
2148 * operation. Link downs can occur during the reset operation. enum sci_status
2151 static void scic_sds_port_reset_state_link_down_handler(
2152 struct scic_sds_port *port,
2153 struct scic_sds_phy *phy)
2156 * In the resetting state we don't notify the user regarding
2157 * link up and link down notifications. */
2158 scic_sds_port_deactivate_phy(port, phy, false);
2161 static struct scic_sds_port_state_handler scic_sds_port_state_handler_table[] = {
2162 [SCI_BASE_PORT_STATE_STOPPED] = {
2163 .start_handler = scic_sds_port_stopped_state_start_handler,
2164 .stop_handler = scic_sds_port_stopped_state_stop_handler,
2165 .destruct_handler = scic_sds_port_stopped_state_destruct_handler,
2166 .reset_handler = scic_sds_port_default_reset_handler,
2167 .add_phy_handler = scic_sds_port_stopped_state_add_phy_handler,
2168 .remove_phy_handler = scic_sds_port_stopped_state_remove_phy_handler,
2169 .frame_handler = scic_sds_port_default_frame_handler,
2170 .event_handler = scic_sds_port_default_event_handler,
2171 .link_up_handler = scic_sds_port_default_link_up_handler,
2172 .link_down_handler = scic_sds_port_default_link_down_handler,
2173 .start_io_handler = scic_sds_port_default_start_io_handler,
2174 .complete_io_handler = scic_sds_port_default_complete_io_handler
2176 [SCI_BASE_PORT_STATE_STOPPING] = {
2177 .start_handler = scic_sds_port_default_start_handler,
2178 .stop_handler = scic_sds_port_default_stop_handler,
2179 .destruct_handler = scic_sds_port_default_destruct_handler,
2180 .reset_handler = scic_sds_port_default_reset_handler,
2181 .add_phy_handler = scic_sds_port_default_add_phy_handler,
2182 .remove_phy_handler = scic_sds_port_default_remove_phy_handler,
2183 .frame_handler = scic_sds_port_default_frame_handler,
2184 .event_handler = scic_sds_port_default_event_handler,
2185 .link_up_handler = scic_sds_port_default_link_up_handler,
2186 .link_down_handler = scic_sds_port_default_link_down_handler,
2187 .start_io_handler = scic_sds_port_default_start_io_handler,
2188 .complete_io_handler = scic_sds_port_stopping_state_complete_io_handler
2190 [SCI_BASE_PORT_STATE_READY] = {
2191 .start_handler = scic_sds_port_default_start_handler,
2192 .stop_handler = scic_sds_port_default_stop_handler,
2193 .destruct_handler = scic_sds_port_default_destruct_handler,
2194 .reset_handler = scic_sds_port_default_reset_handler,
2195 .add_phy_handler = scic_sds_port_default_add_phy_handler,
2196 .remove_phy_handler = scic_sds_port_default_remove_phy_handler,
2197 .frame_handler = scic_sds_port_default_frame_handler,
2198 .event_handler = scic_sds_port_default_event_handler,
2199 .link_up_handler = scic_sds_port_default_link_up_handler,
2200 .link_down_handler = scic_sds_port_default_link_down_handler,
2201 .start_io_handler = scic_sds_port_default_start_io_handler,
2202 .complete_io_handler = scic_sds_port_general_complete_io_handler
2204 [SCI_BASE_PORT_STATE_RESETTING] = {
2205 .start_handler = scic_sds_port_default_start_handler,
2206 .stop_handler = scic_sds_port_reset_state_stop_handler,
2207 .destruct_handler = scic_sds_port_default_destruct_handler,
2208 .reset_handler = scic_sds_port_default_reset_handler,
2209 .add_phy_handler = scic_sds_port_default_add_phy_handler,
2210 .remove_phy_handler = scic_sds_port_default_remove_phy_handler,
2211 .frame_handler = scic_sds_port_default_frame_handler,
2212 .event_handler = scic_sds_port_default_event_handler,
2213 .link_up_handler = scic_sds_port_reset_state_link_up_handler,
2214 .link_down_handler = scic_sds_port_reset_state_link_down_handler,
2215 .start_io_handler = scic_sds_port_default_start_io_handler,
2216 .complete_io_handler = scic_sds_port_general_complete_io_handler
2218 [SCI_BASE_PORT_STATE_FAILED] = {
2219 .start_handler = scic_sds_port_default_start_handler,
2220 .stop_handler = scic_sds_port_default_stop_handler,
2221 .destruct_handler = scic_sds_port_default_destruct_handler,
2222 .reset_handler = scic_sds_port_default_reset_handler,
2223 .add_phy_handler = scic_sds_port_default_add_phy_handler,
2224 .remove_phy_handler = scic_sds_port_default_remove_phy_handler,
2225 .frame_handler = scic_sds_port_default_frame_handler,
2226 .event_handler = scic_sds_port_default_event_handler,
2227 .link_up_handler = scic_sds_port_default_link_up_handler,
2228 .link_down_handler = scic_sds_port_default_link_down_handler,
2229 .start_io_handler = scic_sds_port_default_start_io_handler,
2230 .complete_io_handler = scic_sds_port_general_complete_io_handler
2235 * ******************************************************************************
2236 * * PORT STATE PRIVATE METHODS
2237 * ****************************************************************************** */
2241 * @sci_port: This is the port object which to suspend.
2243 * This method will enable the SCU Port Task Scheduler for this port object but
2244 * will leave the port task scheduler in a suspended state. none
2247 scic_sds_port_enable_port_task_scheduler(struct scic_sds_port *port)
2249 u32 pts_control_value;
2251 pts_control_value = readl(&port->port_task_scheduler_registers->control);
2252 pts_control_value |= SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND);
2253 writel(pts_control_value, &port->port_task_scheduler_registers->control);
2258 * @sci_port: This is the port object which to resume.
2260 * This method will disable the SCU port task scheduler for this port object.
2264 scic_sds_port_disable_port_task_scheduler(struct scic_sds_port *port)
2266 u32 pts_control_value;
2268 pts_control_value = readl(&port->port_task_scheduler_registers->control);
2269 pts_control_value &=
2270 ~(SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND));
2271 writel(pts_control_value, &port->port_task_scheduler_registers->control);
2274 static void scic_sds_port_post_dummy_remote_node(struct scic_sds_port *sci_port)
2276 struct scic_sds_controller *scic = sci_port->owning_controller;
2277 u8 phys_index = sci_port->physical_port_index;
2278 union scu_remote_node_context *rnc;
2279 u16 rni = sci_port->reserved_rni;
2282 rnc = &scic->remote_node_context_table[rni];
2283 rnc->ssp.is_valid = true;
2285 command = SCU_CONTEXT_COMMAND_POST_RNC_32 |
2286 phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
2288 scic_sds_controller_post_request(scic, command);
2290 /* ensure hardware has seen the post rnc command and give it
2291 * ample time to act before sending the suspend
2293 readl(&scic->smu_registers->interrupt_status); /* flush */
2296 command = SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX |
2297 phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
2299 scic_sds_controller_post_request(scic, command);
2302 static void scic_sds_port_invalidate_dummy_remote_node(struct scic_sds_port *sci_port)
2304 struct scic_sds_controller *scic = sci_port->owning_controller;
2305 u8 phys_index = sci_port->physical_port_index;
2306 union scu_remote_node_context *rnc;
2307 u16 rni = sci_port->reserved_rni;
2310 rnc = &scic->remote_node_context_table[rni];
2312 rnc->ssp.is_valid = false;
2314 /* ensure the preceding tc abort request has reached the
2315 * controller and give it ample time to act before posting the rnc
2318 readl(&scic->smu_registers->interrupt_status); /* flush */
2321 command = SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE |
2322 phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
2324 scic_sds_controller_post_request(scic, command);
2328 * ******************************************************************************
2329 * * PORT STATE METHODS
2330 * ****************************************************************************** */
2334 * @object: This is the object which is cast to a struct scic_sds_port object.
2336 * This method will perform the actions required by the struct scic_sds_port on
2337 * entering the SCI_BASE_PORT_STATE_STOPPED. This function sets the stopped
2338 * state handlers for the struct scic_sds_port object and disables the port task
2339 * scheduler in the hardware. none
2341 static void scic_sds_port_stopped_state_enter(void *object)
2343 struct scic_sds_port *sci_port = object;
2345 scic_sds_port_set_base_state_handlers(
2346 sci_port, SCI_BASE_PORT_STATE_STOPPED
2350 SCI_BASE_PORT_STATE_STOPPING
2351 == sci_port->state_machine.previous_state_id
2354 * If we enter this state becasuse of a request to stop
2355 * the port then we want to disable the hardwares port
2356 * task scheduler. */
2357 scic_sds_port_disable_port_task_scheduler(sci_port);
2363 * @object: This is the object which is cast to a struct scic_sds_port object.
2365 * This method will perform the actions required by the struct scic_sds_port on
2366 * exiting the SCI_BASE_STATE_STOPPED. This function enables the SCU hardware
2367 * port task scheduler. none
2369 static void scic_sds_port_stopped_state_exit(void *object)
2371 struct scic_sds_port *sci_port = object;
2373 /* Enable and suspend the port task scheduler */
2374 scic_sds_port_enable_port_task_scheduler(sci_port);
2378 * scic_sds_port_ready_state_enter -
2379 * @object: This is the object which is cast to a struct scic_sds_port object.
2381 * This method will perform the actions required by the struct scic_sds_port on
2382 * entering the SCI_BASE_PORT_STATE_READY. This function sets the ready state
2383 * handlers for the struct scic_sds_port object, reports the port object as
2384 * not ready and starts the ready substate machine. none
2386 static void scic_sds_port_ready_state_enter(void *object)
2388 struct scic_sds_port *sci_port = object;
2389 struct scic_sds_controller *scic = sci_port->owning_controller;
2390 struct isci_host *ihost = scic_to_ihost(scic);
2391 struct isci_port *iport = sci_port_to_iport(sci_port);
2394 /* Put the ready state handlers in place though they will not be there long */
2395 scic_sds_port_set_base_state_handlers(sci_port, SCI_BASE_PORT_STATE_READY);
2397 prev_state = sci_port->state_machine.previous_state_id;
2398 if (prev_state == SCI_BASE_PORT_STATE_RESETTING)
2399 isci_port_hard_reset_complete(iport, SCI_SUCCESS);
2401 isci_port_not_ready(ihost, iport);
2403 /* Post and suspend the dummy remote node context for this port. */
2404 scic_sds_port_post_dummy_remote_node(sci_port);
2406 /* Start the ready substate machine */
2407 sci_base_state_machine_start(&sci_port->ready_substate_machine);
2410 static void scic_sds_port_ready_state_exit(void *object)
2412 struct scic_sds_port *sci_port = object;
2414 sci_base_state_machine_stop(&sci_port->ready_substate_machine);
2415 scic_sds_port_invalidate_dummy_remote_node(sci_port);
2420 * @object: This is the object which is cast to a struct scic_sds_port object.
2422 * This method will perform the actions required by the struct scic_sds_port on
2423 * entering the SCI_BASE_PORT_STATE_RESETTING. This function sets the resetting
2424 * state handlers for the struct scic_sds_port object. none
2426 static void scic_sds_port_resetting_state_enter(void *object)
2428 struct scic_sds_port *sci_port = object;
2430 scic_sds_port_set_base_state_handlers(
2431 sci_port, SCI_BASE_PORT_STATE_RESETTING
2437 * @object: This is the object which is cast to a struct scic_sds_port object.
2439 * This function will perform the actions required by the
2440 * struct scic_sds_port on
2441 * exiting the SCI_BASE_STATE_RESETTING. This function does nothing. none
2443 static inline void scic_sds_port_resetting_state_exit(void *object)
2445 struct scic_sds_port *sci_port = object;
2447 isci_timer_stop(sci_port->timer_handle);
2452 * @object: This is the void object which is cast to a
2453 * struct scic_sds_port object.
2455 * This method will perform the actions required by the struct scic_sds_port on
2456 * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
2457 * state handlers for the struct scic_sds_port object. none
2459 static void scic_sds_port_stopping_state_enter(void *object)
2461 struct scic_sds_port *sci_port = object;
2463 scic_sds_port_set_base_state_handlers(
2464 sci_port, SCI_BASE_PORT_STATE_STOPPING
2470 * @object: This is the object which is cast to a struct scic_sds_port object.
2472 * This function will perform the actions required by the
2473 * struct scic_sds_port on
2474 * exiting the SCI_BASE_STATE_STOPPING. This function does nothing. none
2477 scic_sds_port_stopping_state_exit(void *object)
2479 struct scic_sds_port *sci_port = object;
2481 isci_timer_stop(sci_port->timer_handle);
2483 scic_sds_port_destroy_dummy_resources(sci_port);
2488 * @object: This is the object which is cast to a struct scic_sds_port object.
2490 * This function will perform the actions required by the
2491 * struct scic_sds_port on
2492 * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
2493 * state handlers for the struct scic_sds_port object. none
2495 static void scic_sds_port_failed_state_enter(void *object)
2497 struct scic_sds_port *sci_port = object;
2498 struct isci_port *iport = sci_port_to_iport(sci_port);
2500 scic_sds_port_set_base_state_handlers(sci_port,
2501 SCI_BASE_PORT_STATE_FAILED);
2503 isci_port_hard_reset_complete(iport, SCI_FAILURE_TIMEOUT);
2506 /* --------------------------------------------------------------------------- */
2508 static const struct sci_base_state scic_sds_port_state_table[] = {
2509 [SCI_BASE_PORT_STATE_STOPPED] = {
2510 .enter_state = scic_sds_port_stopped_state_enter,
2511 .exit_state = scic_sds_port_stopped_state_exit
2513 [SCI_BASE_PORT_STATE_STOPPING] = {
2514 .enter_state = scic_sds_port_stopping_state_enter,
2515 .exit_state = scic_sds_port_stopping_state_exit
2517 [SCI_BASE_PORT_STATE_READY] = {
2518 .enter_state = scic_sds_port_ready_state_enter,
2519 .exit_state = scic_sds_port_ready_state_exit
2521 [SCI_BASE_PORT_STATE_RESETTING] = {
2522 .enter_state = scic_sds_port_resetting_state_enter,
2523 .exit_state = scic_sds_port_resetting_state_exit
2525 [SCI_BASE_PORT_STATE_FAILED] = {
2526 .enter_state = scic_sds_port_failed_state_enter,
2530 void scic_sds_port_construct(struct scic_sds_port *sci_port, u8 index,
2531 struct scic_sds_controller *scic)
2533 sci_base_state_machine_construct(&sci_port->state_machine,
2535 scic_sds_port_state_table,
2536 SCI_BASE_PORT_STATE_STOPPED);
2538 sci_base_state_machine_start(&sci_port->state_machine);
2540 sci_base_state_machine_construct(&sci_port->ready_substate_machine,
2542 scic_sds_port_ready_substate_table,
2543 SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
2545 sci_port->logical_port_index = SCIC_SDS_DUMMY_PORT;
2546 sci_port->physical_port_index = index;
2547 sci_port->active_phy_mask = 0;
2549 sci_port->owning_controller = scic;
2551 sci_port->started_request_count = 0;
2552 sci_port->assigned_device_count = 0;
2554 sci_port->reserved_rni = SCU_DUMMY_INDEX;
2555 sci_port->reserved_tci = SCU_DUMMY_INDEX;
2557 sci_port->timer_handle = NULL;
2558 sci_port->port_task_scheduler_registers = NULL;
2560 for (index = 0; index < SCI_MAX_PHYS; index++)
2561 sci_port->phy_table[index] = NULL;
2564 void isci_port_init(struct isci_port *iport, struct isci_host *ihost, int index)
2566 INIT_LIST_HEAD(&iport->remote_dev_list);
2567 INIT_LIST_HEAD(&iport->domain_dev_list);
2568 spin_lock_init(&iport->state_lock);
2569 init_completion(&iport->start_complete);
2570 iport->isci_host = ihost;
2571 isci_port_change_state(iport, isci_freed);
2575 * isci_port_get_state() - This function gets the status of the port object.
2576 * @isci_port: This parameter points to the isci_port object
2578 * status of the object as a isci_status enum.
2580 enum isci_status isci_port_get_state(
2581 struct isci_port *isci_port)
2583 return isci_port->status;
2586 static void isci_port_bc_change_received(struct isci_host *ihost,
2587 struct scic_sds_port *sci_port,
2588 struct scic_sds_phy *sci_phy)
2590 struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
2592 dev_dbg(&ihost->pdev->dev, "%s: iphy = %p, sas_phy = %p\n",
2593 __func__, iphy, &iphy->sas_phy);
2595 ihost->sas_ha.notify_port_event(&iphy->sas_phy, PORTE_BROADCAST_RCVD);
2596 scic_port_enable_broadcast_change_notification(sci_port);
2599 void scic_sds_port_broadcast_change_received(
2600 struct scic_sds_port *sci_port,
2601 struct scic_sds_phy *sci_phy)
2603 struct scic_sds_controller *scic = sci_port->owning_controller;
2604 struct isci_host *ihost = scic_to_ihost(scic);
2606 /* notify the user. */
2607 isci_port_bc_change_received(ihost, sci_port, sci_phy);
2610 int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *iport,
2611 struct isci_phy *iphy)
2613 unsigned long flags;
2614 enum sci_status status;
2615 int ret = TMF_RESP_FUNC_COMPLETE;
2617 dev_dbg(&ihost->pdev->dev, "%s: iport = %p\n",
2620 init_completion(&iport->hard_reset_complete);
2622 spin_lock_irqsave(&ihost->scic_lock, flags);
2624 #define ISCI_PORT_RESET_TIMEOUT SCIC_SDS_SIGNATURE_FIS_TIMEOUT
2625 status = scic_port_hard_reset(&iport->sci, ISCI_PORT_RESET_TIMEOUT);
2627 spin_unlock_irqrestore(&ihost->scic_lock, flags);
2629 if (status == SCI_SUCCESS) {
2630 wait_for_completion(&iport->hard_reset_complete);
2632 dev_dbg(&ihost->pdev->dev,
2633 "%s: iport = %p; hard reset completion\n",
2636 if (iport->hard_reset_status != SCI_SUCCESS)
2637 ret = TMF_RESP_FUNC_FAILED;
2639 ret = TMF_RESP_FUNC_FAILED;
2641 dev_err(&ihost->pdev->dev,
2642 "%s: iport = %p; scic_port_hard_reset call"
2644 __func__, iport, status);
2648 /* If the hard reset for the port has failed, consider this
2649 * the same as link failures on all phys in the port.
2651 if (ret != TMF_RESP_FUNC_COMPLETE) {
2652 dev_err(&ihost->pdev->dev,
2653 "%s: iport = %p; hard reset failed "
2654 "(0x%x) - sending link down to libsas for phy %p\n",
2655 __func__, iport, iport->hard_reset_status, iphy);
2657 isci_port_link_down(ihost, iphy, iport);
2664 * isci_port_deformed() - This function is called by libsas when a port becomes
2666 * @phy: This parameter specifies the libsas phy with the inactive port.
2669 void isci_port_deformed(struct asd_sas_phy *phy)
2671 pr_debug("%s: sas_phy = %p\n", __func__, phy);
2675 * isci_port_formed() - This function is called by libsas when a port becomes
2677 * @phy: This parameter specifies the libsas phy with the active port.
2680 void isci_port_formed(struct asd_sas_phy *phy)
2682 pr_debug("%s: sas_phy = %p, sas_port = %p\n", __func__, phy, phy->port);