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.
60 #define SCIC_SDS_PORT_HARD_RESET_TIMEOUT (1000)
61 #define SCU_DUMMY_INDEX (0xFFFF)
63 static struct device *sciport_to_dev(struct isci_port *iport)
65 int i = iport->physical_port_index;
66 struct isci_port *table;
67 struct isci_host *ihost;
69 if (i == SCIC_SDS_DUMMY_PORT)
73 ihost = container_of(table, typeof(*ihost), ports[0]);
75 return &ihost->pdev->dev;
78 static void isci_port_change_state(struct isci_port *iport, enum isci_status status)
82 dev_dbg(&iport->isci_host->pdev->dev,
83 "%s: iport = %p, state = 0x%x\n",
84 __func__, iport, status);
86 /* XXX pointless lock */
87 spin_lock_irqsave(&iport->state_lock, flags);
88 iport->status = status;
89 spin_unlock_irqrestore(&iport->state_lock, flags);
92 static void sci_port_get_protocols(struct isci_port *iport, struct sci_phy_proto *proto)
97 for (index = 0; index < SCI_MAX_PHYS; index++) {
98 struct isci_phy *iphy = iport->phy_table[index];
102 sci_phy_get_protocols(iphy, proto);
106 static u32 sci_port_get_phys(struct isci_port *iport)
112 for (index = 0; index < SCI_MAX_PHYS; index++)
113 if (iport->phy_table[index])
114 mask |= (1 << index);
120 * sci_port_get_properties() - This method simply returns the properties
121 * regarding the port, such as: physical index, protocols, sas address, etc.
122 * @port: this parameter specifies the port for which to retrieve the physical
124 * @properties: This parameter specifies the properties structure into which to
125 * copy the requested information.
127 * Indicate if the user specified a valid port. SCI_SUCCESS This value is
128 * returned if the specified port was valid. SCI_FAILURE_INVALID_PORT This
129 * value is returned if the specified port is not valid. When this value is
130 * returned, no data is copied to the properties output parameter.
132 enum sci_status sci_port_get_properties(struct isci_port *iport,
133 struct sci_port_properties *prop)
135 if (!iport || iport->logical_port_index == SCIC_SDS_DUMMY_PORT)
136 return SCI_FAILURE_INVALID_PORT;
138 prop->index = iport->logical_port_index;
139 prop->phy_mask = sci_port_get_phys(iport);
140 sci_port_get_sas_address(iport, &prop->local.sas_address);
141 sci_port_get_protocols(iport, &prop->local.protocols);
142 sci_port_get_attached_sas_address(iport, &prop->remote.sas_address);
147 static void sci_port_bcn_enable(struct isci_port *iport)
149 struct isci_phy *iphy;
153 for (i = 0; i < ARRAY_SIZE(iport->phy_table); i++) {
154 iphy = iport->phy_table[i];
157 val = readl(&iphy->link_layer_registers->link_layer_control);
158 /* clear the bit by writing 1. */
159 writel(val, &iphy->link_layer_registers->link_layer_control);
163 static void isci_port_bc_change_received(struct isci_host *ihost,
164 struct isci_port *iport,
165 struct isci_phy *iphy)
167 dev_dbg(&ihost->pdev->dev,
168 "%s: isci_phy = %p, sas_phy = %p\n",
169 __func__, iphy, &iphy->sas_phy);
171 ihost->sas_ha.notify_port_event(&iphy->sas_phy, PORTE_BROADCAST_RCVD);
172 sci_port_bcn_enable(iport);
175 static void isci_port_link_up(struct isci_host *isci_host,
176 struct isci_port *iport,
177 struct isci_phy *iphy)
180 struct sci_port_properties properties;
181 unsigned long success = true;
183 dev_dbg(&isci_host->pdev->dev,
184 "%s: isci_port = %p\n",
187 spin_lock_irqsave(&iphy->sas_phy.frame_rcvd_lock, flags);
189 isci_port_change_state(iport, isci_starting);
191 sci_port_get_properties(iport, &properties);
193 if (iphy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) {
194 u64 attached_sas_address;
196 iphy->sas_phy.oob_mode = SATA_OOB_MODE;
197 iphy->sas_phy.frame_rcvd_size = sizeof(struct dev_to_host_fis);
200 * For direct-attached SATA devices, the SCI core will
201 * automagically assign a SAS address to the end device
202 * for the purpose of creating a port. This SAS address
203 * will not be the same as assigned to the PHY and needs
204 * to be obtained from struct sci_port_properties properties.
206 attached_sas_address = properties.remote.sas_address.high;
207 attached_sas_address <<= 32;
208 attached_sas_address |= properties.remote.sas_address.low;
209 swab64s(&attached_sas_address);
211 memcpy(&iphy->sas_phy.attached_sas_addr,
212 &attached_sas_address, sizeof(attached_sas_address));
213 } else if (iphy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
214 iphy->sas_phy.oob_mode = SAS_OOB_MODE;
215 iphy->sas_phy.frame_rcvd_size = sizeof(struct sas_identify_frame);
217 /* Copy the attached SAS address from the IAF */
218 memcpy(iphy->sas_phy.attached_sas_addr,
219 iphy->frame_rcvd.iaf.sas_addr, SAS_ADDR_SIZE);
221 dev_err(&isci_host->pdev->dev, "%s: unkown target\n", __func__);
225 iphy->sas_phy.phy->negotiated_linkrate = sci_phy_linkrate(iphy);
227 spin_unlock_irqrestore(&iphy->sas_phy.frame_rcvd_lock, flags);
229 /* Notify libsas that we have an address frame, if indeed
230 * we've found an SSP, SMP, or STP target */
232 isci_host->sas_ha.notify_port_event(&iphy->sas_phy,
238 * isci_port_link_down() - This function is called by the sci core when a link
240 * @isci_host: This parameter specifies the isci host object.
241 * @phy: This parameter specifies the isci phy with the active link.
242 * @port: This parameter specifies the isci port with the active link.
245 static void isci_port_link_down(struct isci_host *isci_host,
246 struct isci_phy *isci_phy,
247 struct isci_port *isci_port)
249 struct isci_remote_device *isci_device;
251 dev_dbg(&isci_host->pdev->dev,
252 "%s: isci_port = %p\n", __func__, isci_port);
256 /* check to see if this is the last phy on this port. */
257 if (isci_phy->sas_phy.port &&
258 isci_phy->sas_phy.port->num_phys == 1) {
259 /* change the state for all devices on this port. The
260 * next task sent to this device will be returned as
261 * SAS_TASK_UNDELIVERED, and the scsi mid layer will
264 list_for_each_entry(isci_device,
265 &isci_port->remote_dev_list,
267 dev_dbg(&isci_host->pdev->dev,
268 "%s: isci_device = %p\n",
269 __func__, isci_device);
270 set_bit(IDEV_GONE, &isci_device->flags);
272 isci_port_change_state(isci_port, isci_stopping);
276 /* Notify libsas of the borken link, this will trigger calls to our
277 * isci_port_deformed and isci_dev_gone functions.
279 sas_phy_disconnected(&isci_phy->sas_phy);
280 isci_host->sas_ha.notify_phy_event(&isci_phy->sas_phy,
281 PHYE_LOSS_OF_SIGNAL);
283 dev_dbg(&isci_host->pdev->dev,
284 "%s: isci_port = %p - Done\n", __func__, isci_port);
289 * isci_port_ready() - This function is called by the sci core when a link
291 * @isci_host: This parameter specifies the isci host object.
292 * @port: This parameter specifies the sci port with the active link.
295 static void isci_port_ready(struct isci_host *isci_host, struct isci_port *isci_port)
297 dev_dbg(&isci_host->pdev->dev,
298 "%s: isci_port = %p\n", __func__, isci_port);
300 isci_port_change_state(isci_port, isci_ready);
305 * isci_port_not_ready() - This function is called by the sci core when a link
306 * is not ready. All remote devices on this link will be removed if they are
307 * in the stopping state.
308 * @isci_host: This parameter specifies the isci host object.
309 * @port: This parameter specifies the sci port with the active link.
312 static void isci_port_not_ready(struct isci_host *isci_host, struct isci_port *isci_port)
314 dev_dbg(&isci_host->pdev->dev,
315 "%s: isci_port = %p\n", __func__, isci_port);
318 static void isci_port_stop_complete(struct isci_host *ihost,
319 struct isci_port *iport,
320 enum sci_status completion_status)
322 dev_dbg(&ihost->pdev->dev, "Port stop complete\n");
326 static bool is_port_ready_state(enum sci_port_states state)
330 case SCI_PORT_SUB_WAITING:
331 case SCI_PORT_SUB_OPERATIONAL:
332 case SCI_PORT_SUB_CONFIGURING:
339 /* flag dummy rnc hanling when exiting a ready state */
340 static void port_state_machine_change(struct isci_port *iport,
341 enum sci_port_states state)
343 struct sci_base_state_machine *sm = &iport->sm;
344 enum sci_port_states old_state = sm->current_state_id;
346 if (is_port_ready_state(old_state) && !is_port_ready_state(state))
347 iport->ready_exit = true;
349 sci_change_state(sm, state);
350 iport->ready_exit = false;
354 * isci_port_hard_reset_complete() - This function is called by the sci core
355 * when the hard reset complete notification has been received.
356 * @port: This parameter specifies the sci port with the active link.
357 * @completion_status: This parameter specifies the core status for the reset
361 static void isci_port_hard_reset_complete(struct isci_port *isci_port,
362 enum sci_status completion_status)
364 dev_dbg(&isci_port->isci_host->pdev->dev,
365 "%s: isci_port = %p, completion_status=%x\n",
366 __func__, isci_port, completion_status);
368 /* Save the status of the hard reset from the port. */
369 isci_port->hard_reset_status = completion_status;
371 if (completion_status != SCI_SUCCESS) {
373 /* The reset failed. The port state is now SCI_PORT_FAILED. */
374 if (isci_port->active_phy_mask == 0) {
376 /* Generate the link down now to the host, since it
377 * was intercepted by the hard reset state machine when
378 * it really happened.
380 isci_port_link_down(isci_port->isci_host,
381 &isci_port->isci_host->phys[
382 isci_port->last_active_phy],
385 /* Advance the port state so that link state changes will be
388 port_state_machine_change(isci_port, SCI_PORT_SUB_WAITING);
391 complete_all(&isci_port->hard_reset_complete);
394 /* This method will return a true value if the specified phy can be assigned to
395 * this port The following is a list of phys for each port that are allowed: -
396 * Port 0 - 3 2 1 0 - Port 1 - 1 - Port 2 - 3 2 - Port 3 - 3 This method
397 * doesn't preclude all configurations. It merely ensures that a phy is part
398 * of the allowable set of phy identifiers for that port. For example, one
399 * could assign phy 3 to port 0 and no other phys. Please refer to
400 * sci_port_is_phy_mask_valid() for information regarding whether the
401 * phy_mask for a port can be supported. bool true if this is a valid phy
402 * assignment for the port false if this is not a valid phy assignment for the
405 bool sci_port_is_valid_phy_assignment(struct isci_port *iport, u32 phy_index)
407 struct isci_host *ihost = iport->owning_controller;
408 struct sci_user_parameters *user = &ihost->user_parameters;
410 /* Initialize to invalid value. */
411 u32 existing_phy_index = SCI_MAX_PHYS;
414 if ((iport->physical_port_index == 1) && (phy_index != 1))
417 if (iport->physical_port_index == 3 && phy_index != 3)
420 if (iport->physical_port_index == 2 &&
421 (phy_index == 0 || phy_index == 1))
424 for (index = 0; index < SCI_MAX_PHYS; index++)
425 if (iport->phy_table[index] && index != phy_index)
426 existing_phy_index = index;
428 /* Ensure that all of the phys in the port are capable of
429 * operating at the same maximum link rate.
431 if (existing_phy_index < SCI_MAX_PHYS &&
432 user->phys[phy_index].max_speed_generation !=
433 user->phys[existing_phy_index].max_speed_generation)
441 * @sci_port: This is the port object for which to determine if the phy mask
444 * This method will return a true value if the port's phy mask can be supported
445 * by the SCU. The following is a list of valid PHY mask configurations for
446 * each port: - Port 0 - [[3 2] 1] 0 - Port 1 - [1] - Port 2 - [[3] 2]
447 * - Port 3 - [3] This method returns a boolean indication specifying if the
448 * phy mask can be supported. true if this is a valid phy assignment for the
449 * port false if this is not a valid phy assignment for the port
451 static bool sci_port_is_phy_mask_valid(
452 struct isci_port *iport,
455 if (iport->physical_port_index == 0) {
456 if (((phy_mask & 0x0F) == 0x0F)
457 || ((phy_mask & 0x03) == 0x03)
458 || ((phy_mask & 0x01) == 0x01)
461 } else if (iport->physical_port_index == 1) {
462 if (((phy_mask & 0x02) == 0x02)
465 } else if (iport->physical_port_index == 2) {
466 if (((phy_mask & 0x0C) == 0x0C)
467 || ((phy_mask & 0x04) == 0x04)
470 } else if (iport->physical_port_index == 3) {
471 if (((phy_mask & 0x08) == 0x08)
480 * This method retrieves a currently active (i.e. connected) phy contained in
481 * the port. Currently, the lowest order phy that is connected is returned.
482 * This method returns a pointer to a SCIS_SDS_PHY object. NULL This value is
483 * returned if there are no currently active (i.e. connected to a remote end
484 * point) phys contained in the port. All other values specify a struct sci_phy
485 * object that is active in the port.
487 static struct isci_phy *sci_port_get_a_connected_phy(struct isci_port *iport)
490 struct isci_phy *iphy;
492 for (index = 0; index < SCI_MAX_PHYS; index++) {
493 /* Ensure that the phy is both part of the port and currently
494 * connected to the remote end-point.
496 iphy = iport->phy_table[index];
497 if (iphy && sci_port_active_phy(iport, iphy))
504 static enum sci_status sci_port_set_phy(struct isci_port *iport, struct isci_phy *iphy)
506 /* Check to see if we can add this phy to a port
507 * that means that the phy is not part of a port and that the port does
508 * not already have a phy assinged to the phy index.
510 if (!iport->phy_table[iphy->phy_index] &&
511 !phy_get_non_dummy_port(iphy) &&
512 sci_port_is_valid_phy_assignment(iport, iphy->phy_index)) {
513 /* Phy is being added in the stopped state so we are in MPC mode
514 * make logical port index = physical port index
516 iport->logical_port_index = iport->physical_port_index;
517 iport->phy_table[iphy->phy_index] = iphy;
518 sci_phy_set_port(iphy, iport);
526 static enum sci_status sci_port_clear_phy(struct isci_port *iport, struct isci_phy *iphy)
528 /* Make sure that this phy is part of this port */
529 if (iport->phy_table[iphy->phy_index] == iphy &&
530 phy_get_non_dummy_port(iphy) == iport) {
531 struct isci_host *ihost = iport->owning_controller;
533 /* Yep it is assigned to this port so remove it */
534 sci_phy_set_port(iphy, &ihost->ports[SCI_MAX_PORTS]);
535 iport->phy_table[iphy->phy_index] = NULL;
542 void sci_port_get_sas_address(struct isci_port *iport, struct sci_sas_address *sas)
548 for (index = 0; index < SCI_MAX_PHYS; index++)
549 if (iport->phy_table[index])
550 sci_phy_get_sas_address(iport->phy_table[index], sas);
553 void sci_port_get_attached_sas_address(struct isci_port *iport, struct sci_sas_address *sas)
555 struct isci_phy *iphy;
558 * Ensure that the phy is both part of the port and currently
559 * connected to the remote end-point.
561 iphy = sci_port_get_a_connected_phy(iport);
563 if (iphy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA) {
564 sci_phy_get_attached_sas_address(iphy, sas);
566 sci_phy_get_sas_address(iphy, sas);
567 sas->low += iphy->phy_index;
576 * sci_port_construct_dummy_rnc() - create dummy rnc for si workaround
578 * @sci_port: logical port on which we need to create the remote node context
579 * @rni: remote node index for this remote node context.
581 * This routine will construct a dummy remote node context data structure
582 * This structure will be posted to the hardware to work around a scheduler
583 * error in the hardware.
585 static void sci_port_construct_dummy_rnc(struct isci_port *iport, u16 rni)
587 union scu_remote_node_context *rnc;
589 rnc = &iport->owning_controller->remote_node_context_table[rni];
591 memset(rnc, 0, sizeof(union scu_remote_node_context));
593 rnc->ssp.remote_sas_address_hi = 0;
594 rnc->ssp.remote_sas_address_lo = 0;
596 rnc->ssp.remote_node_index = rni;
597 rnc->ssp.remote_node_port_width = 1;
598 rnc->ssp.logical_port_index = iport->physical_port_index;
600 rnc->ssp.nexus_loss_timer_enable = false;
601 rnc->ssp.check_bit = false;
602 rnc->ssp.is_valid = true;
603 rnc->ssp.is_remote_node_context = true;
604 rnc->ssp.function_number = 0;
605 rnc->ssp.arbitration_wait_time = 0;
609 * construct a dummy task context data structure. This
610 * structure will be posted to the hardwre to work around a scheduler error
613 static void sci_port_construct_dummy_task(struct isci_port *iport, u16 tag)
615 struct isci_host *ihost = iport->owning_controller;
616 struct scu_task_context *task_context;
618 task_context = &ihost->task_context_table[ISCI_TAG_TCI(tag)];
619 memset(task_context, 0, sizeof(struct scu_task_context));
621 task_context->initiator_request = 1;
622 task_context->connection_rate = 1;
623 task_context->logical_port_index = iport->physical_port_index;
624 task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SSP;
625 task_context->task_index = ISCI_TAG_TCI(tag);
626 task_context->valid = SCU_TASK_CONTEXT_VALID;
627 task_context->context_type = SCU_TASK_CONTEXT_TYPE;
628 task_context->remote_node_index = iport->reserved_rni;
629 task_context->do_not_dma_ssp_good_response = 1;
630 task_context->task_phase = 0x01;
633 static void sci_port_destroy_dummy_resources(struct isci_port *iport)
635 struct isci_host *ihost = iport->owning_controller;
637 if (iport->reserved_tag != SCI_CONTROLLER_INVALID_IO_TAG)
638 isci_free_tag(ihost, iport->reserved_tag);
640 if (iport->reserved_rni != SCU_DUMMY_INDEX)
641 sci_remote_node_table_release_remote_node_index(&ihost->available_remote_nodes,
642 1, iport->reserved_rni);
644 iport->reserved_rni = SCU_DUMMY_INDEX;
645 iport->reserved_tag = SCI_CONTROLLER_INVALID_IO_TAG;
648 void sci_port_setup_transports(struct isci_port *iport, u32 device_id)
652 for (index = 0; index < SCI_MAX_PHYS; index++) {
653 if (iport->active_phy_mask & (1 << index))
654 sci_phy_setup_transport(iport->phy_table[index], device_id);
658 static void sci_port_resume_phy(struct isci_port *iport, struct isci_phy *iphy)
660 sci_phy_resume(iphy);
661 iport->enabled_phy_mask |= 1 << iphy->phy_index;
664 static void sci_port_activate_phy(struct isci_port *iport,
665 struct isci_phy *iphy,
668 struct isci_host *ihost = iport->owning_controller;
670 if (iphy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA && (flags & PF_RESUME))
671 sci_phy_resume(iphy);
673 iport->active_phy_mask |= 1 << iphy->phy_index;
675 sci_controller_clear_invalid_phy(ihost, iphy);
677 if (flags & PF_NOTIFY)
678 isci_port_link_up(ihost, iport, iphy);
681 void sci_port_deactivate_phy(struct isci_port *iport, struct isci_phy *iphy,
684 struct isci_host *ihost = iport->owning_controller;
686 iport->active_phy_mask &= ~(1 << iphy->phy_index);
687 iport->enabled_phy_mask &= ~(1 << iphy->phy_index);
688 if (!iport->active_phy_mask)
689 iport->last_active_phy = iphy->phy_index;
691 iphy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
693 /* Re-assign the phy back to the LP as if it were a narrow port for APC
694 * mode. For MPC mode, the phy will remain in the port.
696 if (iport->owning_controller->oem_parameters.controller.mode_type ==
697 SCIC_PORT_AUTOMATIC_CONFIGURATION_MODE)
698 writel(iphy->phy_index,
699 &iport->port_pe_configuration_register[iphy->phy_index]);
701 if (do_notify_user == true)
702 isci_port_link_down(ihost, iphy, iport);
705 static void sci_port_invalid_link_up(struct isci_port *iport, struct isci_phy *iphy)
707 struct isci_host *ihost = iport->owning_controller;
710 * Check to see if we have alreay reported this link as bad and if
711 * not go ahead and tell the SCI_USER that we have discovered an
714 if ((ihost->invalid_phy_mask & (1 << iphy->phy_index)) == 0) {
715 ihost->invalid_phy_mask |= 1 << iphy->phy_index;
716 dev_warn(&ihost->pdev->dev, "Invalid link up!\n");
721 * sci_port_general_link_up_handler - phy can be assigned to port?
722 * @sci_port: sci_port object for which has a phy that has gone link up.
723 * @sci_phy: This is the struct isci_phy object that has gone link up.
724 * @flags: PF_RESUME, PF_NOTIFY to sci_port_activate_phy
726 * Determine if this phy can be assigned to this port . If the phy is
727 * not a valid PHY for this port then the function will notify the user.
728 * A PHY can only be part of a port if it's attached SAS ADDRESS is the
729 * same as all other PHYs in the same port.
731 static void sci_port_general_link_up_handler(struct isci_port *iport,
732 struct isci_phy *iphy,
735 struct sci_sas_address port_sas_address;
736 struct sci_sas_address phy_sas_address;
738 sci_port_get_attached_sas_address(iport, &port_sas_address);
739 sci_phy_get_attached_sas_address(iphy, &phy_sas_address);
741 /* If the SAS address of the new phy matches the SAS address of
742 * other phys in the port OR this is the first phy in the port,
743 * then activate the phy and allow it to be used for operations
746 if ((phy_sas_address.high == port_sas_address.high &&
747 phy_sas_address.low == port_sas_address.low) ||
748 iport->active_phy_mask == 0) {
749 struct sci_base_state_machine *sm = &iport->sm;
751 sci_port_activate_phy(iport, iphy, flags);
752 if (sm->current_state_id == SCI_PORT_RESETTING)
753 port_state_machine_change(iport, SCI_PORT_READY);
755 sci_port_invalid_link_up(iport, iphy);
761 * This method returns false if the port only has a single phy object assigned.
762 * If there are no phys or more than one phy then the method will return
764 * @sci_port: The port for which the wide port condition is to be checked.
766 * bool true Is returned if this is a wide ported port. false Is returned if
767 * this is a narrow port.
769 static bool sci_port_is_wide(struct isci_port *iport)
774 for (index = 0; index < SCI_MAX_PHYS; index++) {
775 if (iport->phy_table[index] != NULL) {
780 return phy_count != 1;
784 * This method is called by the PHY object when the link is detected. if the
785 * port wants the PHY to continue on to the link up state then the port
786 * layer must return true. If the port object returns false the phy object
787 * must halt its attempt to go link up.
788 * @sci_port: The port associated with the phy object.
789 * @sci_phy: The phy object that is trying to go link up.
791 * true if the phy object can continue to the link up condition. true Is
792 * returned if this phy can continue to the ready state. false Is returned if
793 * can not continue on to the ready state. This notification is in place for
794 * wide ports and direct attached phys. Since there are no wide ported SATA
795 * devices this could become an invalid port configuration.
797 bool sci_port_link_detected(
798 struct isci_port *iport,
799 struct isci_phy *iphy)
801 if ((iport->logical_port_index != SCIC_SDS_DUMMY_PORT) &&
802 (iphy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA)) {
803 if (sci_port_is_wide(iport)) {
804 sci_port_invalid_link_up(iport, iphy);
807 struct isci_host *ihost = iport->owning_controller;
808 struct isci_port *dst_port = &(ihost->ports[iphy->phy_index]);
809 writel(iphy->phy_index,
810 &dst_port->port_pe_configuration_register[iphy->phy_index]);
817 static void port_timeout(unsigned long data)
819 struct sci_timer *tmr = (struct sci_timer *)data;
820 struct isci_port *iport = container_of(tmr, typeof(*iport), timer);
821 struct isci_host *ihost = iport->owning_controller;
825 spin_lock_irqsave(&ihost->scic_lock, flags);
830 current_state = iport->sm.current_state_id;
832 if (current_state == SCI_PORT_RESETTING) {
833 /* if the port is still in the resetting state then the timeout
834 * fired before the reset completed.
836 port_state_machine_change(iport, SCI_PORT_FAILED);
837 } else if (current_state == SCI_PORT_STOPPED) {
838 /* if the port is stopped then the start request failed In this
839 * case stay in the stopped state.
841 dev_err(sciport_to_dev(iport),
842 "%s: SCIC Port 0x%p failed to stop before tiemout.\n",
845 } else if (current_state == SCI_PORT_STOPPING) {
846 /* if the port is still stopping then the stop has not completed */
847 isci_port_stop_complete(iport->owning_controller,
849 SCI_FAILURE_TIMEOUT);
851 /* The port is in the ready state and we have a timer
852 * reporting a timeout this should not happen.
854 dev_err(sciport_to_dev(iport),
855 "%s: SCIC Port 0x%p is processing a timeout operation "
856 "in state %d.\n", __func__, iport, current_state);
860 spin_unlock_irqrestore(&ihost->scic_lock, flags);
863 /* --------------------------------------------------------------------------- */
866 * This function updates the hardwares VIIT entry for this port.
870 static void sci_port_update_viit_entry(struct isci_port *iport)
872 struct sci_sas_address sas_address;
874 sci_port_get_sas_address(iport, &sas_address);
876 writel(sas_address.high,
877 &iport->viit_registers->initiator_sas_address_hi);
878 writel(sas_address.low,
879 &iport->viit_registers->initiator_sas_address_lo);
881 /* This value get cleared just in case its not already cleared */
882 writel(0, &iport->viit_registers->reserved);
884 /* We are required to update the status register last */
885 writel(SCU_VIIT_ENTRY_ID_VIIT |
886 SCU_VIIT_IPPT_INITIATOR |
887 ((1 << iport->physical_port_index) << SCU_VIIT_ENTRY_LPVIE_SHIFT) |
888 SCU_VIIT_STATUS_ALL_VALID,
889 &iport->viit_registers->status);
892 enum sas_linkrate sci_port_get_max_allowed_speed(struct isci_port *iport)
895 struct isci_phy *iphy;
896 enum sas_linkrate max_allowed_speed = SAS_LINK_RATE_6_0_GBPS;
899 * Loop through all of the phys in this port and find the phy with the
900 * lowest maximum link rate. */
901 for (index = 0; index < SCI_MAX_PHYS; index++) {
902 iphy = iport->phy_table[index];
903 if (iphy && sci_port_active_phy(iport, iphy) &&
904 iphy->max_negotiated_speed < max_allowed_speed)
905 max_allowed_speed = iphy->max_negotiated_speed;
908 return max_allowed_speed;
911 static void sci_port_suspend_port_task_scheduler(struct isci_port *iport)
913 u32 pts_control_value;
915 pts_control_value = readl(&iport->port_task_scheduler_registers->control);
916 pts_control_value |= SCU_PTSxCR_GEN_BIT(SUSPEND);
917 writel(pts_control_value, &iport->port_task_scheduler_registers->control);
921 * sci_port_post_dummy_request() - post dummy/workaround request
922 * @sci_port: port to post task
924 * Prevent the hardware scheduler from posting new requests to the front
925 * of the scheduler queue causing a starvation problem for currently
929 static void sci_port_post_dummy_request(struct isci_port *iport)
931 struct isci_host *ihost = iport->owning_controller;
932 u16 tag = iport->reserved_tag;
933 struct scu_task_context *tc;
936 tc = &ihost->task_context_table[ISCI_TAG_TCI(tag)];
939 command = SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
940 iport->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
943 sci_controller_post_request(ihost, command);
947 * This routine will abort the dummy request. This will alow the hardware to
948 * power down parts of the silicon to save power.
950 * @sci_port: The port on which the task must be aborted.
953 static void sci_port_abort_dummy_request(struct isci_port *iport)
955 struct isci_host *ihost = iport->owning_controller;
956 u16 tag = iport->reserved_tag;
957 struct scu_task_context *tc;
960 tc = &ihost->task_context_table[ISCI_TAG_TCI(tag)];
963 command = SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT |
964 iport->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
967 sci_controller_post_request(ihost, command);
972 * @sci_port: This is the struct isci_port object to resume.
974 * This method will resume the port task scheduler for this port object. none
977 sci_port_resume_port_task_scheduler(struct isci_port *iport)
979 u32 pts_control_value;
981 pts_control_value = readl(&iport->port_task_scheduler_registers->control);
982 pts_control_value &= ~SCU_PTSxCR_GEN_BIT(SUSPEND);
983 writel(pts_control_value, &iport->port_task_scheduler_registers->control);
986 static void sci_port_ready_substate_waiting_enter(struct sci_base_state_machine *sm)
988 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
990 sci_port_suspend_port_task_scheduler(iport);
992 iport->not_ready_reason = SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS;
994 if (iport->active_phy_mask != 0) {
995 /* At least one of the phys on the port is ready */
996 port_state_machine_change(iport,
997 SCI_PORT_SUB_OPERATIONAL);
1001 static void scic_sds_port_ready_substate_waiting_exit(
1002 struct sci_base_state_machine *sm)
1004 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1005 sci_port_resume_port_task_scheduler(iport);
1008 static void sci_port_ready_substate_operational_enter(struct sci_base_state_machine *sm)
1011 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1012 struct isci_host *ihost = iport->owning_controller;
1014 isci_port_ready(ihost, iport);
1016 for (index = 0; index < SCI_MAX_PHYS; index++) {
1017 if (iport->phy_table[index]) {
1018 writel(iport->physical_port_index,
1019 &iport->port_pe_configuration_register[
1020 iport->phy_table[index]->phy_index]);
1021 if (((iport->active_phy_mask^iport->enabled_phy_mask) & (1 << index)) != 0)
1022 sci_port_resume_phy(iport, iport->phy_table[index]);
1026 sci_port_update_viit_entry(iport);
1029 * Post the dummy task for the port so the hardware can schedule
1032 sci_port_post_dummy_request(iport);
1035 static void sci_port_invalidate_dummy_remote_node(struct isci_port *iport)
1037 struct isci_host *ihost = iport->owning_controller;
1038 u8 phys_index = iport->physical_port_index;
1039 union scu_remote_node_context *rnc;
1040 u16 rni = iport->reserved_rni;
1043 rnc = &ihost->remote_node_context_table[rni];
1045 rnc->ssp.is_valid = false;
1047 /* ensure the preceding tc abort request has reached the
1048 * controller and give it ample time to act before posting the rnc
1051 readl(&ihost->smu_registers->interrupt_status); /* flush */
1054 command = SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE |
1055 phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
1057 sci_controller_post_request(ihost, command);
1062 * @object: This is the object which is cast to a struct isci_port object.
1064 * This method will perform the actions required by the struct isci_port on
1065 * exiting the SCI_PORT_SUB_OPERATIONAL. This function reports
1066 * the port not ready and suspends the port task scheduler. none
1068 static void sci_port_ready_substate_operational_exit(struct sci_base_state_machine *sm)
1070 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1071 struct isci_host *ihost = iport->owning_controller;
1074 * Kill the dummy task for this port if it has not yet posted
1075 * the hardware will treat this as a NOP and just return abort
1078 sci_port_abort_dummy_request(iport);
1080 isci_port_not_ready(ihost, iport);
1082 if (iport->ready_exit)
1083 sci_port_invalidate_dummy_remote_node(iport);
1086 static void sci_port_ready_substate_configuring_enter(struct sci_base_state_machine *sm)
1088 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1089 struct isci_host *ihost = iport->owning_controller;
1091 if (iport->active_phy_mask == 0) {
1092 isci_port_not_ready(ihost, iport);
1094 port_state_machine_change(iport, SCI_PORT_SUB_WAITING);
1096 port_state_machine_change(iport, SCI_PORT_SUB_OPERATIONAL);
1099 enum sci_status sci_port_start(struct isci_port *iport)
1101 struct isci_host *ihost = iport->owning_controller;
1102 enum sci_status status = SCI_SUCCESS;
1103 enum sci_port_states state;
1106 state = iport->sm.current_state_id;
1107 if (state != SCI_PORT_STOPPED) {
1108 dev_warn(sciport_to_dev(iport),
1109 "%s: in wrong state: %d\n", __func__, state);
1110 return SCI_FAILURE_INVALID_STATE;
1113 if (iport->assigned_device_count > 0) {
1114 /* TODO This is a start failure operation because
1115 * there are still devices assigned to this port.
1116 * There must be no devices assigned to a port on a
1119 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
1122 if (iport->reserved_rni == SCU_DUMMY_INDEX) {
1123 u16 rni = sci_remote_node_table_allocate_remote_node(
1124 &ihost->available_remote_nodes, 1);
1126 if (rni != SCU_DUMMY_INDEX)
1127 sci_port_construct_dummy_rnc(iport, rni);
1129 status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
1130 iport->reserved_rni = rni;
1133 if (iport->reserved_tag == SCI_CONTROLLER_INVALID_IO_TAG) {
1136 tag = isci_alloc_tag(ihost);
1137 if (tag == SCI_CONTROLLER_INVALID_IO_TAG)
1138 status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
1140 sci_port_construct_dummy_task(iport, tag);
1141 iport->reserved_tag = tag;
1144 if (status == SCI_SUCCESS) {
1145 phy_mask = sci_port_get_phys(iport);
1148 * There are one or more phys assigned to this port. Make sure
1149 * the port's phy mask is in fact legal and supported by the
1152 if (sci_port_is_phy_mask_valid(iport, phy_mask) == true) {
1153 port_state_machine_change(iport,
1158 status = SCI_FAILURE;
1161 if (status != SCI_SUCCESS)
1162 sci_port_destroy_dummy_resources(iport);
1167 enum sci_status sci_port_stop(struct isci_port *iport)
1169 enum sci_port_states state;
1171 state = iport->sm.current_state_id;
1173 case SCI_PORT_STOPPED:
1175 case SCI_PORT_SUB_WAITING:
1176 case SCI_PORT_SUB_OPERATIONAL:
1177 case SCI_PORT_SUB_CONFIGURING:
1178 case SCI_PORT_RESETTING:
1179 port_state_machine_change(iport,
1183 dev_warn(sciport_to_dev(iport),
1184 "%s: in wrong state: %d\n", __func__, state);
1185 return SCI_FAILURE_INVALID_STATE;
1189 static enum sci_status sci_port_hard_reset(struct isci_port *iport, u32 timeout)
1191 enum sci_status status = SCI_FAILURE_INVALID_PHY;
1192 struct isci_phy *iphy = NULL;
1193 enum sci_port_states state;
1196 state = iport->sm.current_state_id;
1197 if (state != SCI_PORT_SUB_OPERATIONAL) {
1198 dev_warn(sciport_to_dev(iport),
1199 "%s: in wrong state: %d\n", __func__, state);
1200 return SCI_FAILURE_INVALID_STATE;
1203 /* Select a phy on which we can send the hard reset request. */
1204 for (phy_index = 0; phy_index < SCI_MAX_PHYS && !iphy; phy_index++) {
1205 iphy = iport->phy_table[phy_index];
1206 if (iphy && !sci_port_active_phy(iport, iphy)) {
1208 * We found a phy but it is not ready select
1215 /* If we have a phy then go ahead and start the reset procedure */
1218 status = sci_phy_reset(iphy);
1220 if (status != SCI_SUCCESS)
1223 sci_mod_timer(&iport->timer, timeout);
1224 iport->not_ready_reason = SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED;
1226 port_state_machine_change(iport, SCI_PORT_RESETTING);
1231 * sci_port_add_phy() -
1232 * @sci_port: This parameter specifies the port in which the phy will be added.
1233 * @sci_phy: This parameter is the phy which is to be added to the port.
1235 * This method will add a PHY to the selected port. This method returns an
1236 * enum sci_status. SCI_SUCCESS the phy has been added to the port. Any other
1237 * status is a failure to add the phy to the port.
1239 enum sci_status sci_port_add_phy(struct isci_port *iport,
1240 struct isci_phy *iphy)
1242 enum sci_status status;
1243 enum sci_port_states state;
1245 state = iport->sm.current_state_id;
1247 case SCI_PORT_STOPPED: {
1248 struct sci_sas_address port_sas_address;
1250 /* Read the port assigned SAS Address if there is one */
1251 sci_port_get_sas_address(iport, &port_sas_address);
1253 if (port_sas_address.high != 0 && port_sas_address.low != 0) {
1254 struct sci_sas_address phy_sas_address;
1256 /* Make sure that the PHY SAS Address matches the SAS Address
1259 sci_phy_get_sas_address(iphy, &phy_sas_address);
1261 if (port_sas_address.high != phy_sas_address.high ||
1262 port_sas_address.low != phy_sas_address.low)
1263 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
1265 return sci_port_set_phy(iport, iphy);
1267 case SCI_PORT_SUB_WAITING:
1268 case SCI_PORT_SUB_OPERATIONAL:
1269 status = sci_port_set_phy(iport, iphy);
1271 if (status != SCI_SUCCESS)
1274 sci_port_general_link_up_handler(iport, iphy, PF_NOTIFY|PF_RESUME);
1275 iport->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
1276 port_state_machine_change(iport, SCI_PORT_SUB_CONFIGURING);
1279 case SCI_PORT_SUB_CONFIGURING:
1280 status = sci_port_set_phy(iport, iphy);
1282 if (status != SCI_SUCCESS)
1284 sci_port_general_link_up_handler(iport, iphy, PF_NOTIFY);
1286 /* Re-enter the configuring state since this may be the last phy in
1289 port_state_machine_change(iport,
1290 SCI_PORT_SUB_CONFIGURING);
1293 dev_warn(sciport_to_dev(iport),
1294 "%s: in wrong state: %d\n", __func__, state);
1295 return SCI_FAILURE_INVALID_STATE;
1300 * sci_port_remove_phy() -
1301 * @sci_port: This parameter specifies the port in which the phy will be added.
1302 * @sci_phy: This parameter is the phy which is to be added to the port.
1304 * This method will remove the PHY from the selected PORT. This method returns
1305 * an enum sci_status. SCI_SUCCESS the phy has been removed from the port. Any
1306 * other status is a failure to add the phy to the port.
1308 enum sci_status sci_port_remove_phy(struct isci_port *iport,
1309 struct isci_phy *iphy)
1311 enum sci_status status;
1312 enum sci_port_states state;
1314 state = iport->sm.current_state_id;
1317 case SCI_PORT_STOPPED:
1318 return sci_port_clear_phy(iport, iphy);
1319 case SCI_PORT_SUB_OPERATIONAL:
1320 status = sci_port_clear_phy(iport, iphy);
1321 if (status != SCI_SUCCESS)
1324 sci_port_deactivate_phy(iport, iphy, true);
1325 iport->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
1326 port_state_machine_change(iport,
1327 SCI_PORT_SUB_CONFIGURING);
1329 case SCI_PORT_SUB_CONFIGURING:
1330 status = sci_port_clear_phy(iport, iphy);
1332 if (status != SCI_SUCCESS)
1334 sci_port_deactivate_phy(iport, iphy, true);
1336 /* Re-enter the configuring state since this may be the last phy in
1339 port_state_machine_change(iport,
1340 SCI_PORT_SUB_CONFIGURING);
1343 dev_warn(sciport_to_dev(iport),
1344 "%s: in wrong state: %d\n", __func__, state);
1345 return SCI_FAILURE_INVALID_STATE;
1349 enum sci_status sci_port_link_up(struct isci_port *iport,
1350 struct isci_phy *iphy)
1352 enum sci_port_states state;
1354 state = iport->sm.current_state_id;
1356 case SCI_PORT_SUB_WAITING:
1357 /* Since this is the first phy going link up for the port we
1358 * can just enable it and continue
1360 sci_port_activate_phy(iport, iphy, PF_NOTIFY|PF_RESUME);
1362 port_state_machine_change(iport,
1363 SCI_PORT_SUB_OPERATIONAL);
1365 case SCI_PORT_SUB_OPERATIONAL:
1366 sci_port_general_link_up_handler(iport, iphy, PF_NOTIFY|PF_RESUME);
1368 case SCI_PORT_RESETTING:
1369 /* TODO We should make sure that the phy that has gone
1370 * link up is the same one on which we sent the reset. It is
1371 * possible that the phy on which we sent the reset is not the
1372 * one that has gone link up and we want to make sure that
1373 * phy being reset comes back. Consider the case where a
1374 * reset is sent but before the hardware processes the reset it
1375 * get a link up on the port because of a hot plug event.
1376 * because of the reset request this phy will go link down
1377 * almost immediately.
1380 /* In the resetting state we don't notify the user regarding
1381 * link up and link down notifications.
1383 sci_port_general_link_up_handler(iport, iphy, PF_RESUME);
1386 dev_warn(sciport_to_dev(iport),
1387 "%s: in wrong state: %d\n", __func__, state);
1388 return SCI_FAILURE_INVALID_STATE;
1392 enum sci_status sci_port_link_down(struct isci_port *iport,
1393 struct isci_phy *iphy)
1395 enum sci_port_states state;
1397 state = iport->sm.current_state_id;
1399 case SCI_PORT_SUB_OPERATIONAL:
1400 sci_port_deactivate_phy(iport, iphy, true);
1402 /* If there are no active phys left in the port, then
1403 * transition the port to the WAITING state until such time
1404 * as a phy goes link up
1406 if (iport->active_phy_mask == 0)
1407 port_state_machine_change(iport,
1408 SCI_PORT_SUB_WAITING);
1410 case SCI_PORT_RESETTING:
1411 /* In the resetting state we don't notify the user regarding
1412 * link up and link down notifications. */
1413 sci_port_deactivate_phy(iport, iphy, false);
1416 dev_warn(sciport_to_dev(iport),
1417 "%s: in wrong state: %d\n", __func__, state);
1418 return SCI_FAILURE_INVALID_STATE;
1422 enum sci_status sci_port_start_io(struct isci_port *iport,
1423 struct isci_remote_device *idev,
1424 struct isci_request *ireq)
1426 enum sci_port_states state;
1428 state = iport->sm.current_state_id;
1430 case SCI_PORT_SUB_WAITING:
1431 return SCI_FAILURE_INVALID_STATE;
1432 case SCI_PORT_SUB_OPERATIONAL:
1433 iport->started_request_count++;
1436 dev_warn(sciport_to_dev(iport),
1437 "%s: in wrong state: %d\n", __func__, state);
1438 return SCI_FAILURE_INVALID_STATE;
1442 enum sci_status sci_port_complete_io(struct isci_port *iport,
1443 struct isci_remote_device *idev,
1444 struct isci_request *ireq)
1446 enum sci_port_states state;
1448 state = iport->sm.current_state_id;
1450 case SCI_PORT_STOPPED:
1451 dev_warn(sciport_to_dev(iport),
1452 "%s: in wrong state: %d\n", __func__, state);
1453 return SCI_FAILURE_INVALID_STATE;
1454 case SCI_PORT_STOPPING:
1455 sci_port_decrement_request_count(iport);
1457 if (iport->started_request_count == 0)
1458 port_state_machine_change(iport,
1461 case SCI_PORT_READY:
1462 case SCI_PORT_RESETTING:
1463 case SCI_PORT_FAILED:
1464 case SCI_PORT_SUB_WAITING:
1465 case SCI_PORT_SUB_OPERATIONAL:
1466 sci_port_decrement_request_count(iport);
1468 case SCI_PORT_SUB_CONFIGURING:
1469 sci_port_decrement_request_count(iport);
1470 if (iport->started_request_count == 0) {
1471 port_state_machine_change(iport,
1472 SCI_PORT_SUB_OPERATIONAL);
1479 static void sci_port_enable_port_task_scheduler(struct isci_port *iport)
1481 u32 pts_control_value;
1483 /* enable the port task scheduler in a suspended state */
1484 pts_control_value = readl(&iport->port_task_scheduler_registers->control);
1485 pts_control_value |= SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND);
1486 writel(pts_control_value, &iport->port_task_scheduler_registers->control);
1489 static void sci_port_disable_port_task_scheduler(struct isci_port *iport)
1491 u32 pts_control_value;
1493 pts_control_value = readl(&iport->port_task_scheduler_registers->control);
1494 pts_control_value &=
1495 ~(SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND));
1496 writel(pts_control_value, &iport->port_task_scheduler_registers->control);
1499 static void sci_port_post_dummy_remote_node(struct isci_port *iport)
1501 struct isci_host *ihost = iport->owning_controller;
1502 u8 phys_index = iport->physical_port_index;
1503 union scu_remote_node_context *rnc;
1504 u16 rni = iport->reserved_rni;
1507 rnc = &ihost->remote_node_context_table[rni];
1508 rnc->ssp.is_valid = true;
1510 command = SCU_CONTEXT_COMMAND_POST_RNC_32 |
1511 phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
1513 sci_controller_post_request(ihost, command);
1515 /* ensure hardware has seen the post rnc command and give it
1516 * ample time to act before sending the suspend
1518 readl(&ihost->smu_registers->interrupt_status); /* flush */
1521 command = SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX |
1522 phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
1524 sci_controller_post_request(ihost, command);
1527 static void sci_port_stopped_state_enter(struct sci_base_state_machine *sm)
1529 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1531 if (iport->sm.previous_state_id == SCI_PORT_STOPPING) {
1533 * If we enter this state becasuse of a request to stop
1534 * the port then we want to disable the hardwares port
1535 * task scheduler. */
1536 sci_port_disable_port_task_scheduler(iport);
1540 static void sci_port_stopped_state_exit(struct sci_base_state_machine *sm)
1542 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1544 /* Enable and suspend the port task scheduler */
1545 sci_port_enable_port_task_scheduler(iport);
1548 static void sci_port_ready_state_enter(struct sci_base_state_machine *sm)
1550 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1551 struct isci_host *ihost = iport->owning_controller;
1554 prev_state = iport->sm.previous_state_id;
1555 if (prev_state == SCI_PORT_RESETTING)
1556 isci_port_hard_reset_complete(iport, SCI_SUCCESS);
1558 isci_port_not_ready(ihost, iport);
1560 /* Post and suspend the dummy remote node context for this port. */
1561 sci_port_post_dummy_remote_node(iport);
1563 /* Start the ready substate machine */
1564 port_state_machine_change(iport,
1565 SCI_PORT_SUB_WAITING);
1568 static void sci_port_resetting_state_exit(struct sci_base_state_machine *sm)
1570 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1572 sci_del_timer(&iport->timer);
1575 static void sci_port_stopping_state_exit(struct sci_base_state_machine *sm)
1577 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1579 sci_del_timer(&iport->timer);
1581 sci_port_destroy_dummy_resources(iport);
1584 static void sci_port_failed_state_enter(struct sci_base_state_machine *sm)
1586 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1588 isci_port_hard_reset_complete(iport, SCI_FAILURE_TIMEOUT);
1591 /* --------------------------------------------------------------------------- */
1593 static const struct sci_base_state sci_port_state_table[] = {
1594 [SCI_PORT_STOPPED] = {
1595 .enter_state = sci_port_stopped_state_enter,
1596 .exit_state = sci_port_stopped_state_exit
1598 [SCI_PORT_STOPPING] = {
1599 .exit_state = sci_port_stopping_state_exit
1601 [SCI_PORT_READY] = {
1602 .enter_state = sci_port_ready_state_enter,
1604 [SCI_PORT_SUB_WAITING] = {
1605 .enter_state = sci_port_ready_substate_waiting_enter,
1606 .exit_state = scic_sds_port_ready_substate_waiting_exit,
1608 [SCI_PORT_SUB_OPERATIONAL] = {
1609 .enter_state = sci_port_ready_substate_operational_enter,
1610 .exit_state = sci_port_ready_substate_operational_exit
1612 [SCI_PORT_SUB_CONFIGURING] = {
1613 .enter_state = sci_port_ready_substate_configuring_enter
1615 [SCI_PORT_RESETTING] = {
1616 .exit_state = sci_port_resetting_state_exit
1618 [SCI_PORT_FAILED] = {
1619 .enter_state = sci_port_failed_state_enter,
1623 void sci_port_construct(struct isci_port *iport, u8 index,
1624 struct isci_host *ihost)
1626 sci_init_sm(&iport->sm, sci_port_state_table, SCI_PORT_STOPPED);
1628 iport->logical_port_index = SCIC_SDS_DUMMY_PORT;
1629 iport->physical_port_index = index;
1630 iport->active_phy_mask = 0;
1631 iport->enabled_phy_mask = 0;
1632 iport->last_active_phy = 0;
1633 iport->ready_exit = false;
1635 iport->owning_controller = ihost;
1637 iport->started_request_count = 0;
1638 iport->assigned_device_count = 0;
1640 iport->reserved_rni = SCU_DUMMY_INDEX;
1641 iport->reserved_tag = SCI_CONTROLLER_INVALID_IO_TAG;
1643 sci_init_timer(&iport->timer, port_timeout);
1645 iport->port_task_scheduler_registers = NULL;
1647 for (index = 0; index < SCI_MAX_PHYS; index++)
1648 iport->phy_table[index] = NULL;
1651 void isci_port_init(struct isci_port *iport, struct isci_host *ihost, int index)
1653 INIT_LIST_HEAD(&iport->remote_dev_list);
1654 INIT_LIST_HEAD(&iport->domain_dev_list);
1655 spin_lock_init(&iport->state_lock);
1656 iport->isci_host = ihost;
1657 isci_port_change_state(iport, isci_freed);
1661 * isci_port_get_state() - This function gets the status of the port object.
1662 * @isci_port: This parameter points to the isci_port object
1664 * status of the object as a isci_status enum.
1666 enum isci_status isci_port_get_state(
1667 struct isci_port *isci_port)
1669 return isci_port->status;
1672 void sci_port_broadcast_change_received(struct isci_port *iport, struct isci_phy *iphy)
1674 struct isci_host *ihost = iport->owning_controller;
1676 /* notify the user. */
1677 isci_port_bc_change_received(ihost, iport, iphy);
1680 int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *iport,
1681 struct isci_phy *iphy)
1683 unsigned long flags;
1684 enum sci_status status;
1685 int ret = TMF_RESP_FUNC_COMPLETE;
1687 dev_dbg(&ihost->pdev->dev, "%s: iport = %p\n",
1690 init_completion(&iport->hard_reset_complete);
1692 spin_lock_irqsave(&ihost->scic_lock, flags);
1694 #define ISCI_PORT_RESET_TIMEOUT SCIC_SDS_SIGNATURE_FIS_TIMEOUT
1695 status = sci_port_hard_reset(iport, ISCI_PORT_RESET_TIMEOUT);
1697 spin_unlock_irqrestore(&ihost->scic_lock, flags);
1699 if (status == SCI_SUCCESS) {
1700 wait_for_completion(&iport->hard_reset_complete);
1702 dev_dbg(&ihost->pdev->dev,
1703 "%s: iport = %p; hard reset completion\n",
1706 if (iport->hard_reset_status != SCI_SUCCESS) {
1707 ret = TMF_RESP_FUNC_FAILED;
1709 dev_err(&ihost->pdev->dev,
1710 "%s: iport = %p; hard reset failed (0x%x)\n",
1711 __func__, iport, iport->hard_reset_status);
1714 ret = TMF_RESP_FUNC_FAILED;
1716 dev_err(&ihost->pdev->dev,
1717 "%s: iport = %p; sci_port_hard_reset call"
1719 __func__, iport, status);
1723 /* If the hard reset for the port has failed, consider this
1724 * the same as link failures on all phys in the port.
1726 if (ret != TMF_RESP_FUNC_COMPLETE) {
1728 dev_err(&ihost->pdev->dev,
1729 "%s: iport = %p; hard reset failed "
1730 "(0x%x) - driving explicit link fail for all phys\n",
1731 __func__, iport, iport->hard_reset_status);
1736 void isci_port_deformed(struct asd_sas_phy *phy)
1738 struct isci_host *ihost = phy->ha->lldd_ha;
1739 struct isci_port *iport = phy->port->lldd_port;
1740 unsigned long flags;
1743 /* we got a port notification on a port that was subsequently
1744 * torn down and libsas is just now catching up
1749 spin_lock_irqsave(&ihost->scic_lock, flags);
1750 for (i = 0; i < SCI_MAX_PHYS; i++) {
1751 if (iport->active_phy_mask & 1 << i)
1754 spin_unlock_irqrestore(&ihost->scic_lock, flags);
1756 if (i >= SCI_MAX_PHYS)
1757 dev_dbg(&ihost->pdev->dev, "%s: port: %ld\n",
1758 __func__, (long) (iport - &ihost->ports[0]));
1761 void isci_port_formed(struct asd_sas_phy *phy)
1763 struct isci_host *ihost = phy->ha->lldd_ha;
1764 struct isci_phy *iphy = to_iphy(phy);
1765 struct asd_sas_port *port = phy->port;
1766 struct isci_port *iport;
1767 unsigned long flags;
1770 /* initial ports are formed as the driver is still initializing,
1771 * wait for that process to complete
1773 wait_for_start(ihost);
1775 spin_lock_irqsave(&ihost->scic_lock, flags);
1776 for (i = 0; i < SCI_MAX_PORTS; i++) {
1777 iport = &ihost->ports[i];
1778 if (iport->active_phy_mask & 1 << iphy->phy_index)
1781 spin_unlock_irqrestore(&ihost->scic_lock, flags);
1783 if (i >= SCI_MAX_PORTS)
1786 port->lldd_port = iport;