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 void isci_port_change_state(struct isci_port *iport, enum isci_status status)
67 dev_dbg(&iport->isci_host->pdev->dev,
68 "%s: iport = %p, state = 0x%x\n",
69 __func__, iport, status);
71 /* XXX pointless lock */
72 spin_lock_irqsave(&iport->state_lock, flags);
73 iport->status = status;
74 spin_unlock_irqrestore(&iport->state_lock, flags);
78 * This function will indicate which protocols are supported by this port.
79 * @sci_port: a handle corresponding to the SAS port for which to return the
80 * supported protocols.
81 * @protocols: This parameter specifies a pointer to a data structure
82 * which the core will copy the protocol values for the port from the
83 * transmit_identification register.
86 scic_sds_port_get_protocols(struct isci_port *iport,
87 struct scic_phy_proto *protocols)
93 for (index = 0; index < SCI_MAX_PHYS; index++) {
94 if (iport->phy_table[index] != NULL) {
95 scic_sds_phy_get_protocols(iport->phy_table[index],
102 * This method requests a list (mask) of the phys contained in the supplied SAS
104 * @sci_port: a handle corresponding to the SAS port for which to return the
107 * Return a bit mask indicating which phys are a part of this port. Each bit
108 * corresponds to a phy identifier (e.g. bit 0 = phy id 0).
110 static u32 scic_sds_port_get_phys(struct isci_port *iport)
117 for (index = 0; index < SCI_MAX_PHYS; index++) {
118 if (iport->phy_table[index] != NULL) {
119 mask |= (1 << index);
127 * scic_port_get_properties() - This method simply returns the properties
128 * regarding the port, such as: physical index, protocols, sas address, etc.
129 * @port: this parameter specifies the port for which to retrieve the physical
131 * @properties: This parameter specifies the properties structure into which to
132 * copy the requested information.
134 * Indicate if the user specified a valid port. SCI_SUCCESS This value is
135 * returned if the specified port was valid. SCI_FAILURE_INVALID_PORT This
136 * value is returned if the specified port is not valid. When this value is
137 * returned, no data is copied to the properties output parameter.
139 static enum sci_status scic_port_get_properties(struct isci_port *iport,
140 struct scic_port_properties *prop)
142 if (!iport || iport->logical_port_index == SCIC_SDS_DUMMY_PORT)
143 return SCI_FAILURE_INVALID_PORT;
145 prop->index = iport->logical_port_index;
146 prop->phy_mask = scic_sds_port_get_phys(iport);
147 scic_sds_port_get_sas_address(iport, &prop->local.sas_address);
148 scic_sds_port_get_protocols(iport, &prop->local.protocols);
149 scic_sds_port_get_attached_sas_address(iport, &prop->remote.sas_address);
154 static void scic_port_bcn_enable(struct isci_port *iport)
156 struct isci_phy *iphy;
160 for (i = 0; i < ARRAY_SIZE(iport->phy_table); i++) {
161 iphy = iport->phy_table[i];
164 val = readl(&iphy->link_layer_registers->link_layer_control);
165 /* clear the bit by writing 1. */
166 writel(val, &iphy->link_layer_registers->link_layer_control);
170 /* called under scic_lock to stabilize phy:port associations */
171 void isci_port_bcn_enable(struct isci_host *ihost, struct isci_port *iport)
175 clear_bit(IPORT_BCN_BLOCKED, &iport->flags);
176 wake_up(&ihost->eventq);
178 if (!test_and_clear_bit(IPORT_BCN_PENDING, &iport->flags))
181 for (i = 0; i < ARRAY_SIZE(iport->phy_table); i++) {
182 struct isci_phy *iphy = iport->phy_table[i];
187 ihost->sas_ha.notify_port_event(&iphy->sas_phy,
188 PORTE_BROADCAST_RCVD);
193 static void isci_port_bc_change_received(struct isci_host *ihost,
194 struct isci_port *iport,
195 struct isci_phy *iphy)
197 if (iport && test_bit(IPORT_BCN_BLOCKED, &iport->flags)) {
198 dev_dbg(&ihost->pdev->dev,
199 "%s: disabled BCN; isci_phy = %p, sas_phy = %p\n",
200 __func__, iphy, &iphy->sas_phy);
201 set_bit(IPORT_BCN_PENDING, &iport->flags);
202 atomic_inc(&iport->event);
203 wake_up(&ihost->eventq);
205 dev_dbg(&ihost->pdev->dev,
206 "%s: isci_phy = %p, sas_phy = %p\n",
207 __func__, iphy, &iphy->sas_phy);
209 ihost->sas_ha.notify_port_event(&iphy->sas_phy,
210 PORTE_BROADCAST_RCVD);
212 scic_port_bcn_enable(iport);
215 static void isci_port_link_up(struct isci_host *isci_host,
216 struct isci_port *iport,
217 struct isci_phy *iphy)
220 struct scic_port_properties properties;
221 unsigned long success = true;
223 BUG_ON(iphy->isci_port != NULL);
225 iphy->isci_port = iport;
227 dev_dbg(&isci_host->pdev->dev,
228 "%s: isci_port = %p\n",
231 spin_lock_irqsave(&iphy->sas_phy.frame_rcvd_lock, flags);
233 isci_port_change_state(iphy->isci_port, isci_starting);
235 scic_port_get_properties(iport, &properties);
237 if (iphy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) {
238 u64 attached_sas_address;
240 iphy->sas_phy.oob_mode = SATA_OOB_MODE;
241 iphy->sas_phy.frame_rcvd_size = sizeof(struct dev_to_host_fis);
244 * For direct-attached SATA devices, the SCI core will
245 * automagically assign a SAS address to the end device
246 * for the purpose of creating a port. This SAS address
247 * will not be the same as assigned to the PHY and needs
248 * to be obtained from struct scic_port_properties properties.
250 attached_sas_address = properties.remote.sas_address.high;
251 attached_sas_address <<= 32;
252 attached_sas_address |= properties.remote.sas_address.low;
253 swab64s(&attached_sas_address);
255 memcpy(&iphy->sas_phy.attached_sas_addr,
256 &attached_sas_address, sizeof(attached_sas_address));
257 } else if (iphy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
258 iphy->sas_phy.oob_mode = SAS_OOB_MODE;
259 iphy->sas_phy.frame_rcvd_size = sizeof(struct sas_identify_frame);
261 /* Copy the attached SAS address from the IAF */
262 memcpy(iphy->sas_phy.attached_sas_addr,
263 iphy->frame_rcvd.iaf.sas_addr, SAS_ADDR_SIZE);
265 dev_err(&isci_host->pdev->dev, "%s: unkown target\n", __func__);
269 iphy->sas_phy.phy->negotiated_linkrate = sci_phy_linkrate(iphy);
271 spin_unlock_irqrestore(&iphy->sas_phy.frame_rcvd_lock, flags);
273 /* Notify libsas that we have an address frame, if indeed
274 * we've found an SSP, SMP, or STP target */
276 isci_host->sas_ha.notify_port_event(&iphy->sas_phy,
282 * isci_port_link_down() - This function is called by the sci core when a link
284 * @isci_host: This parameter specifies the isci host object.
285 * @phy: This parameter specifies the isci phy with the active link.
286 * @port: This parameter specifies the isci port with the active link.
289 static void isci_port_link_down(struct isci_host *isci_host,
290 struct isci_phy *isci_phy,
291 struct isci_port *isci_port)
293 struct isci_remote_device *isci_device;
295 dev_dbg(&isci_host->pdev->dev,
296 "%s: isci_port = %p\n", __func__, isci_port);
300 /* check to see if this is the last phy on this port. */
301 if (isci_phy->sas_phy.port &&
302 isci_phy->sas_phy.port->num_phys == 1) {
303 atomic_inc(&isci_port->event);
304 isci_port_bcn_enable(isci_host, isci_port);
306 /* change the state for all devices on this port. The
307 * next task sent to this device will be returned as
308 * SAS_TASK_UNDELIVERED, and the scsi mid layer will
311 list_for_each_entry(isci_device,
312 &isci_port->remote_dev_list,
314 dev_dbg(&isci_host->pdev->dev,
315 "%s: isci_device = %p\n",
316 __func__, isci_device);
317 set_bit(IDEV_GONE, &isci_device->flags);
320 isci_port_change_state(isci_port, isci_stopping);
323 /* Notify libsas of the borken link, this will trigger calls to our
324 * isci_port_deformed and isci_dev_gone functions.
326 sas_phy_disconnected(&isci_phy->sas_phy);
327 isci_host->sas_ha.notify_phy_event(&isci_phy->sas_phy,
328 PHYE_LOSS_OF_SIGNAL);
330 isci_phy->isci_port = NULL;
332 dev_dbg(&isci_host->pdev->dev,
333 "%s: isci_port = %p - Done\n", __func__, isci_port);
338 * isci_port_ready() - This function is called by the sci core when a link
340 * @isci_host: This parameter specifies the isci host object.
341 * @port: This parameter specifies the sci port with the active link.
344 static void isci_port_ready(struct isci_host *isci_host, struct isci_port *isci_port)
346 dev_dbg(&isci_host->pdev->dev,
347 "%s: isci_port = %p\n", __func__, isci_port);
349 complete_all(&isci_port->start_complete);
350 isci_port_change_state(isci_port, isci_ready);
355 * isci_port_not_ready() - This function is called by the sci core when a link
356 * is not ready. All remote devices on this link will be removed if they are
357 * in the stopping state.
358 * @isci_host: This parameter specifies the isci host object.
359 * @port: This parameter specifies the sci port with the active link.
362 static void isci_port_not_ready(struct isci_host *isci_host, struct isci_port *isci_port)
364 dev_dbg(&isci_host->pdev->dev,
365 "%s: isci_port = %p\n", __func__, isci_port);
368 static void isci_port_stop_complete(struct isci_host *ihost,
369 struct isci_port *iport,
370 enum sci_status completion_status)
372 dev_dbg(&ihost->pdev->dev, "Port stop complete\n");
376 * isci_port_hard_reset_complete() - This function is called by the sci core
377 * when the hard reset complete notification has been received.
378 * @port: This parameter specifies the sci port with the active link.
379 * @completion_status: This parameter specifies the core status for the reset
383 static void isci_port_hard_reset_complete(struct isci_port *isci_port,
384 enum sci_status completion_status)
386 dev_dbg(&isci_port->isci_host->pdev->dev,
387 "%s: isci_port = %p, completion_status=%x\n",
388 __func__, isci_port, completion_status);
390 /* Save the status of the hard reset from the port. */
391 isci_port->hard_reset_status = completion_status;
393 complete_all(&isci_port->hard_reset_complete);
396 /* This method will return a true value if the specified phy can be assigned to
397 * this port The following is a list of phys for each port that are allowed: -
398 * Port 0 - 3 2 1 0 - Port 1 - 1 - Port 2 - 3 2 - Port 3 - 3 This method
399 * doesn't preclude all configurations. It merely ensures that a phy is part
400 * of the allowable set of phy identifiers for that port. For example, one
401 * could assign phy 3 to port 0 and no other phys. Please refer to
402 * scic_sds_port_is_phy_mask_valid() for information regarding whether the
403 * phy_mask for a port can be supported. bool true if this is a valid phy
404 * assignment for the port false if this is not a valid phy assignment for the
407 bool scic_sds_port_is_valid_phy_assignment(struct isci_port *iport,
410 /* Initialize to invalid value. */
411 u32 existing_phy_index = SCI_MAX_PHYS;
414 if ((iport->physical_port_index == 1) && (phy_index != 1)) {
418 if (iport->physical_port_index == 3 && phy_index != 3) {
423 (iport->physical_port_index == 2)
424 && ((phy_index == 0) || (phy_index == 1))
429 for (index = 0; index < SCI_MAX_PHYS; index++) {
430 if ((iport->phy_table[index] != NULL)
431 && (index != phy_index)) {
432 existing_phy_index = index;
437 * Ensure that all of the phys in the port are capable of
438 * operating at the same maximum link rate. */
440 (existing_phy_index < SCI_MAX_PHYS)
441 && (iport->owning_controller->user_parameters.sds1.phys[
442 phy_index].max_speed_generation !=
443 iport->owning_controller->user_parameters.sds1.phys[
444 existing_phy_index].max_speed_generation)
453 * @sci_port: This is the port object for which to determine if the phy mask
456 * This method will return a true value if the port's phy mask can be supported
457 * by the SCU. The following is a list of valid PHY mask configurations for
458 * each port: - Port 0 - [[3 2] 1] 0 - Port 1 - [1] - Port 2 - [[3] 2]
459 * - Port 3 - [3] This method returns a boolean indication specifying if the
460 * phy mask can be supported. true if this is a valid phy assignment for the
461 * port false if this is not a valid phy assignment for the port
463 static bool scic_sds_port_is_phy_mask_valid(
464 struct isci_port *iport,
467 if (iport->physical_port_index == 0) {
468 if (((phy_mask & 0x0F) == 0x0F)
469 || ((phy_mask & 0x03) == 0x03)
470 || ((phy_mask & 0x01) == 0x01)
473 } else if (iport->physical_port_index == 1) {
474 if (((phy_mask & 0x02) == 0x02)
477 } else if (iport->physical_port_index == 2) {
478 if (((phy_mask & 0x0C) == 0x0C)
479 || ((phy_mask & 0x04) == 0x04)
482 } else if (iport->physical_port_index == 3) {
483 if (((phy_mask & 0x08) == 0x08)
492 * This method retrieves a currently active (i.e. connected) phy contained in
493 * the port. Currently, the lowest order phy that is connected is returned.
494 * This method returns a pointer to a SCIS_SDS_PHY object. NULL This value is
495 * returned if there are no currently active (i.e. connected to a remote end
496 * point) phys contained in the port. All other values specify a struct scic_sds_phy
497 * object that is active in the port.
499 static struct isci_phy *scic_sds_port_get_a_connected_phy(struct isci_port *iport)
502 struct isci_phy *iphy;
504 for (index = 0; index < SCI_MAX_PHYS; index++) {
505 /* Ensure that the phy is both part of the port and currently
506 * connected to the remote end-point.
508 iphy = iport->phy_table[index];
509 if (iphy && scic_sds_port_active_phy(iport, iphy))
516 static enum sci_status scic_sds_port_set_phy(struct isci_port *iport, struct isci_phy *iphy)
518 /* Check to see if we can add this phy to a port
519 * that means that the phy is not part of a port and that the port does
520 * not already have a phy assinged to the phy index.
522 if (!iport->phy_table[iphy->phy_index] &&
523 !phy_get_non_dummy_port(iphy) &&
524 scic_sds_port_is_valid_phy_assignment(iport, iphy->phy_index)) {
525 /* Phy is being added in the stopped state so we are in MPC mode
526 * make logical port index = physical port index
528 iport->logical_port_index = iport->physical_port_index;
529 iport->phy_table[iphy->phy_index] = iphy;
530 scic_sds_phy_set_port(iphy, iport);
538 static enum sci_status scic_sds_port_clear_phy(struct isci_port *iport,
539 struct isci_phy *iphy)
541 /* Make sure that this phy is part of this port */
542 if (iport->phy_table[iphy->phy_index] == iphy &&
543 phy_get_non_dummy_port(iphy) == iport) {
544 struct isci_host *ihost = iport->owning_controller;
546 /* Yep it is assigned to this port so remove it */
547 scic_sds_phy_set_port(iphy, &ihost->ports[SCI_MAX_PORTS]);
548 iport->phy_table[iphy->phy_index] = NULL;
557 * This method requests the SAS address for the supplied SAS port from the SCI
559 * @sci_port: a handle corresponding to the SAS port for which to return the
561 * @sas_address: This parameter specifies a pointer to a SAS address structure
562 * into which the core will copy the SAS address for the port.
565 void scic_sds_port_get_sas_address(
566 struct isci_port *iport,
567 struct sci_sas_address *sas_address)
571 sas_address->high = 0;
572 sas_address->low = 0;
574 for (index = 0; index < SCI_MAX_PHYS; index++) {
575 if (iport->phy_table[index] != NULL) {
576 scic_sds_phy_get_sas_address(iport->phy_table[index], sas_address);
582 * This function requests the SAS address for the device directly attached to
584 * @sci_port: a handle corresponding to the SAS port for which to return the
586 * @sas_address: This parameter specifies a pointer to a SAS address structure
587 * into which the core will copy the SAS address for the device directly
588 * attached to the port.
591 void scic_sds_port_get_attached_sas_address(
592 struct isci_port *iport,
593 struct sci_sas_address *sas_address)
595 struct isci_phy *iphy;
598 * Ensure that the phy is both part of the port and currently
599 * connected to the remote end-point.
601 iphy = scic_sds_port_get_a_connected_phy(iport);
603 if (iphy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA) {
604 scic_sds_phy_get_attached_sas_address(iphy,
607 scic_sds_phy_get_sas_address(iphy, sas_address);
608 sas_address->low += iphy->phy_index;
611 sas_address->high = 0;
612 sas_address->low = 0;
617 * scic_sds_port_construct_dummy_rnc() - create dummy rnc for si workaround
619 * @sci_port: logical port on which we need to create the remote node context
620 * @rni: remote node index for this remote node context.
622 * This routine will construct a dummy remote node context data structure
623 * This structure will be posted to the hardware to work around a scheduler
624 * error in the hardware.
626 static void scic_sds_port_construct_dummy_rnc(struct isci_port *iport, u16 rni)
628 union scu_remote_node_context *rnc;
630 rnc = &iport->owning_controller->remote_node_context_table[rni];
632 memset(rnc, 0, sizeof(union scu_remote_node_context));
634 rnc->ssp.remote_sas_address_hi = 0;
635 rnc->ssp.remote_sas_address_lo = 0;
637 rnc->ssp.remote_node_index = rni;
638 rnc->ssp.remote_node_port_width = 1;
639 rnc->ssp.logical_port_index = iport->physical_port_index;
641 rnc->ssp.nexus_loss_timer_enable = false;
642 rnc->ssp.check_bit = false;
643 rnc->ssp.is_valid = true;
644 rnc->ssp.is_remote_node_context = true;
645 rnc->ssp.function_number = 0;
646 rnc->ssp.arbitration_wait_time = 0;
650 * construct a dummy task context data structure. This
651 * structure will be posted to the hardwre to work around a scheduler error
654 static void scic_sds_port_construct_dummy_task(struct isci_port *iport, u16 tag)
656 struct isci_host *ihost = iport->owning_controller;
657 struct scu_task_context *task_context;
659 task_context = &ihost->task_context_table[ISCI_TAG_TCI(tag)];
660 memset(task_context, 0, sizeof(struct scu_task_context));
662 task_context->initiator_request = 1;
663 task_context->connection_rate = 1;
664 task_context->logical_port_index = iport->physical_port_index;
665 task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SSP;
666 task_context->task_index = ISCI_TAG_TCI(tag);
667 task_context->valid = SCU_TASK_CONTEXT_VALID;
668 task_context->context_type = SCU_TASK_CONTEXT_TYPE;
669 task_context->remote_node_index = iport->reserved_rni;
670 task_context->do_not_dma_ssp_good_response = 1;
671 task_context->task_phase = 0x01;
674 static void scic_sds_port_destroy_dummy_resources(struct isci_port *iport)
676 struct isci_host *ihost = iport->owning_controller;
678 if (iport->reserved_tag != SCI_CONTROLLER_INVALID_IO_TAG)
679 isci_free_tag(ihost, iport->reserved_tag);
681 if (iport->reserved_rni != SCU_DUMMY_INDEX)
682 scic_sds_remote_node_table_release_remote_node_index(&ihost->available_remote_nodes,
683 1, iport->reserved_rni);
685 iport->reserved_rni = SCU_DUMMY_INDEX;
686 iport->reserved_tag = SCI_CONTROLLER_INVALID_IO_TAG;
690 * This method performs initialization of the supplied port. Initialization
691 * includes: - state machine initialization - member variable initialization
692 * - configuring the phy_mask
694 * @transport_layer_registers:
695 * @port_task_scheduler_registers:
696 * @port_configuration_regsiter:
698 * enum sci_status SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION This value is returned
699 * if the phy being added to the port
701 enum sci_status scic_sds_port_initialize(
702 struct isci_port *iport,
703 void __iomem *port_task_scheduler_registers,
704 void __iomem *port_configuration_regsiter,
705 void __iomem *viit_registers)
707 iport->port_task_scheduler_registers = port_task_scheduler_registers;
708 iport->port_pe_configuration_register = port_configuration_regsiter;
709 iport->viit_registers = viit_registers;
716 * This method assigns the direct attached device ID for this port.
718 * @param[in] iport The port for which the direct attached device id is to
720 * @param[in] device_id The direct attached device ID to assign to the port.
721 * This will be the RNi for the device
723 void scic_sds_port_setup_transports(
724 struct isci_port *iport,
729 for (index = 0; index < SCI_MAX_PHYS; index++) {
730 if (iport->active_phy_mask & (1 << index))
731 scic_sds_phy_setup_transport(iport->phy_table[index], device_id);
737 * @sci_port: This is the port on which the phy should be enabled.
738 * @sci_phy: This is the specific phy which to enable.
739 * @do_notify_user: This parameter specifies whether to inform the user (via
740 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
742 * This function will activate the phy in the port.
743 * Activation includes: - adding
744 * the phy to the port - enabling the Protocol Engine in the silicon. -
745 * notifying the user that the link is up. none
747 static void scic_sds_port_activate_phy(struct isci_port *iport,
748 struct isci_phy *iphy,
751 struct isci_host *ihost = iport->owning_controller;
753 if (iphy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA)
754 scic_sds_phy_resume(iphy);
756 iport->active_phy_mask |= 1 << iphy->phy_index;
758 scic_sds_controller_clear_invalid_phy(ihost, iphy);
760 if (do_notify_user == true)
761 isci_port_link_up(ihost, iport, iphy);
764 void scic_sds_port_deactivate_phy(struct isci_port *iport,
765 struct isci_phy *iphy,
768 struct isci_host *ihost = scic_sds_port_get_controller(iport);
770 iport->active_phy_mask &= ~(1 << iphy->phy_index);
772 iphy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
774 /* Re-assign the phy back to the LP as if it were a narrow port */
775 writel(iphy->phy_index,
776 &iport->port_pe_configuration_register[iphy->phy_index]);
778 if (do_notify_user == true)
779 isci_port_link_down(ihost, iphy, iport);
784 * @sci_port: This is the port on which the phy should be disabled.
785 * @sci_phy: This is the specific phy which to disabled.
787 * This function will disable the phy and report that the phy is not valid for
788 * this port object. None
790 static void scic_sds_port_invalid_link_up(struct isci_port *iport,
791 struct isci_phy *iphy)
793 struct isci_host *ihost = iport->owning_controller;
796 * Check to see if we have alreay reported this link as bad and if
797 * not go ahead and tell the SCI_USER that we have discovered an
800 if ((ihost->invalid_phy_mask & (1 << iphy->phy_index)) == 0) {
801 scic_sds_controller_set_invalid_phy(ihost, iphy);
802 dev_warn(&ihost->pdev->dev, "Invalid link up!\n");
806 static bool is_port_ready_state(enum scic_sds_port_states state)
810 case SCI_PORT_SUB_WAITING:
811 case SCI_PORT_SUB_OPERATIONAL:
812 case SCI_PORT_SUB_CONFIGURING:
819 /* flag dummy rnc hanling when exiting a ready state */
820 static void port_state_machine_change(struct isci_port *iport,
821 enum scic_sds_port_states state)
823 struct sci_base_state_machine *sm = &iport->sm;
824 enum scic_sds_port_states old_state = sm->current_state_id;
826 if (is_port_ready_state(old_state) && !is_port_ready_state(state))
827 iport->ready_exit = true;
829 sci_change_state(sm, state);
830 iport->ready_exit = false;
834 * scic_sds_port_general_link_up_handler - phy can be assigned to port?
835 * @sci_port: scic_sds_port object for which has a phy that has gone link up.
836 * @sci_phy: This is the struct isci_phy object that has gone link up.
837 * @do_notify_user: This parameter specifies whether to inform the user (via
838 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
840 * Determine if this phy can be assigned to this
841 * port . If the phy is not a valid PHY for
842 * this port then the function will notify the user. A PHY can only be
843 * part of a port if it's attached SAS ADDRESS is the same as all other PHYs in
844 * the same port. none
846 static void scic_sds_port_general_link_up_handler(struct isci_port *iport,
847 struct isci_phy *iphy,
850 struct sci_sas_address port_sas_address;
851 struct sci_sas_address phy_sas_address;
853 scic_sds_port_get_attached_sas_address(iport, &port_sas_address);
854 scic_sds_phy_get_attached_sas_address(iphy, &phy_sas_address);
856 /* If the SAS address of the new phy matches the SAS address of
857 * other phys in the port OR this is the first phy in the port,
858 * then activate the phy and allow it to be used for operations
861 if ((phy_sas_address.high == port_sas_address.high &&
862 phy_sas_address.low == port_sas_address.low) ||
863 iport->active_phy_mask == 0) {
864 struct sci_base_state_machine *sm = &iport->sm;
866 scic_sds_port_activate_phy(iport, iphy, do_notify_user);
867 if (sm->current_state_id == SCI_PORT_RESETTING)
868 port_state_machine_change(iport, SCI_PORT_READY);
870 scic_sds_port_invalid_link_up(iport, iphy);
876 * This method returns false if the port only has a single phy object assigned.
877 * If there are no phys or more than one phy then the method will return
879 * @sci_port: The port for which the wide port condition is to be checked.
881 * bool true Is returned if this is a wide ported port. false Is returned if
882 * this is a narrow port.
884 static bool scic_sds_port_is_wide(struct isci_port *iport)
889 for (index = 0; index < SCI_MAX_PHYS; index++) {
890 if (iport->phy_table[index] != NULL) {
895 return phy_count != 1;
899 * This method is called by the PHY object when the link is detected. if the
900 * port wants the PHY to continue on to the link up state then the port
901 * layer must return true. If the port object returns false the phy object
902 * must halt its attempt to go link up.
903 * @sci_port: The port associated with the phy object.
904 * @sci_phy: The phy object that is trying to go link up.
906 * true if the phy object can continue to the link up condition. true Is
907 * returned if this phy can continue to the ready state. false Is returned if
908 * can not continue on to the ready state. This notification is in place for
909 * wide ports and direct attached phys. Since there are no wide ported SATA
910 * devices this could become an invalid port configuration.
912 bool scic_sds_port_link_detected(
913 struct isci_port *iport,
914 struct isci_phy *iphy)
916 if ((iport->logical_port_index != SCIC_SDS_DUMMY_PORT) &&
917 (iphy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) &&
918 scic_sds_port_is_wide(iport)) {
919 scic_sds_port_invalid_link_up(iport, iphy);
927 static void port_timeout(unsigned long data)
929 struct sci_timer *tmr = (struct sci_timer *)data;
930 struct isci_port *iport = container_of(tmr, typeof(*iport), timer);
931 struct isci_host *ihost = iport->owning_controller;
935 spin_lock_irqsave(&ihost->scic_lock, flags);
940 current_state = iport->sm.current_state_id;
942 if (current_state == SCI_PORT_RESETTING) {
943 /* if the port is still in the resetting state then the timeout
944 * fired before the reset completed.
946 port_state_machine_change(iport, SCI_PORT_FAILED);
947 } else if (current_state == SCI_PORT_STOPPED) {
948 /* if the port is stopped then the start request failed In this
949 * case stay in the stopped state.
951 dev_err(sciport_to_dev(iport),
952 "%s: SCIC Port 0x%p failed to stop before tiemout.\n",
955 } else if (current_state == SCI_PORT_STOPPING) {
956 /* if the port is still stopping then the stop has not completed */
957 isci_port_stop_complete(iport->owning_controller,
959 SCI_FAILURE_TIMEOUT);
961 /* The port is in the ready state and we have a timer
962 * reporting a timeout this should not happen.
964 dev_err(sciport_to_dev(iport),
965 "%s: SCIC Port 0x%p is processing a timeout operation "
966 "in state %d.\n", __func__, iport, current_state);
970 spin_unlock_irqrestore(&ihost->scic_lock, flags);
973 /* --------------------------------------------------------------------------- */
976 * This function updates the hardwares VIIT entry for this port.
980 static void scic_sds_port_update_viit_entry(struct isci_port *iport)
982 struct sci_sas_address sas_address;
984 scic_sds_port_get_sas_address(iport, &sas_address);
986 writel(sas_address.high,
987 &iport->viit_registers->initiator_sas_address_hi);
988 writel(sas_address.low,
989 &iport->viit_registers->initiator_sas_address_lo);
991 /* This value get cleared just in case its not already cleared */
992 writel(0, &iport->viit_registers->reserved);
994 /* We are required to update the status register last */
995 writel(SCU_VIIT_ENTRY_ID_VIIT |
996 SCU_VIIT_IPPT_INITIATOR |
997 ((1 << iport->physical_port_index) << SCU_VIIT_ENTRY_LPVIE_SHIFT) |
998 SCU_VIIT_STATUS_ALL_VALID,
999 &iport->viit_registers->status);
1002 enum sas_linkrate scic_sds_port_get_max_allowed_speed(struct isci_port *iport)
1005 struct isci_phy *iphy;
1006 enum sas_linkrate max_allowed_speed = SAS_LINK_RATE_6_0_GBPS;
1009 * Loop through all of the phys in this port and find the phy with the
1010 * lowest maximum link rate. */
1011 for (index = 0; index < SCI_MAX_PHYS; index++) {
1012 iphy = iport->phy_table[index];
1013 if (iphy && scic_sds_port_active_phy(iport, iphy) &&
1014 iphy->max_negotiated_speed < max_allowed_speed)
1015 max_allowed_speed = iphy->max_negotiated_speed;
1018 return max_allowed_speed;
1021 static void scic_sds_port_suspend_port_task_scheduler(struct isci_port *iport)
1023 u32 pts_control_value;
1025 pts_control_value = readl(&iport->port_task_scheduler_registers->control);
1026 pts_control_value |= SCU_PTSxCR_GEN_BIT(SUSPEND);
1027 writel(pts_control_value, &iport->port_task_scheduler_registers->control);
1031 * scic_sds_port_post_dummy_request() - post dummy/workaround request
1032 * @sci_port: port to post task
1034 * Prevent the hardware scheduler from posting new requests to the front
1035 * of the scheduler queue causing a starvation problem for currently
1039 static void scic_sds_port_post_dummy_request(struct isci_port *iport)
1041 struct isci_host *ihost = iport->owning_controller;
1042 u16 tag = iport->reserved_tag;
1043 struct scu_task_context *tc;
1046 tc = &ihost->task_context_table[ISCI_TAG_TCI(tag)];
1049 command = SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
1050 iport->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
1053 scic_sds_controller_post_request(ihost, command);
1057 * This routine will abort the dummy request. This will alow the hardware to
1058 * power down parts of the silicon to save power.
1060 * @sci_port: The port on which the task must be aborted.
1063 static void scic_sds_port_abort_dummy_request(struct isci_port *iport)
1065 struct isci_host *ihost = iport->owning_controller;
1066 u16 tag = iport->reserved_tag;
1067 struct scu_task_context *tc;
1070 tc = &ihost->task_context_table[ISCI_TAG_TCI(tag)];
1073 command = SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT |
1074 iport->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
1077 scic_sds_controller_post_request(ihost, command);
1082 * @sci_port: This is the struct isci_port object to resume.
1084 * This method will resume the port task scheduler for this port object. none
1087 scic_sds_port_resume_port_task_scheduler(struct isci_port *iport)
1089 u32 pts_control_value;
1091 pts_control_value = readl(&iport->port_task_scheduler_registers->control);
1092 pts_control_value &= ~SCU_PTSxCR_GEN_BIT(SUSPEND);
1093 writel(pts_control_value, &iport->port_task_scheduler_registers->control);
1096 static void scic_sds_port_ready_substate_waiting_enter(struct sci_base_state_machine *sm)
1098 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1100 scic_sds_port_suspend_port_task_scheduler(iport);
1102 iport->not_ready_reason = SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS;
1104 if (iport->active_phy_mask != 0) {
1105 /* At least one of the phys on the port is ready */
1106 port_state_machine_change(iport,
1107 SCI_PORT_SUB_OPERATIONAL);
1111 static void scic_sds_port_ready_substate_operational_enter(struct sci_base_state_machine *sm)
1114 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1115 struct isci_host *ihost = iport->owning_controller;
1117 isci_port_ready(ihost, iport);
1119 for (index = 0; index < SCI_MAX_PHYS; index++) {
1120 if (iport->phy_table[index]) {
1121 writel(iport->physical_port_index,
1122 &iport->port_pe_configuration_register[
1123 iport->phy_table[index]->phy_index]);
1127 scic_sds_port_update_viit_entry(iport);
1129 scic_sds_port_resume_port_task_scheduler(iport);
1132 * Post the dummy task for the port so the hardware can schedule
1135 scic_sds_port_post_dummy_request(iport);
1138 static void scic_sds_port_invalidate_dummy_remote_node(struct isci_port *iport)
1140 struct isci_host *ihost = iport->owning_controller;
1141 u8 phys_index = iport->physical_port_index;
1142 union scu_remote_node_context *rnc;
1143 u16 rni = iport->reserved_rni;
1146 rnc = &ihost->remote_node_context_table[rni];
1148 rnc->ssp.is_valid = false;
1150 /* ensure the preceding tc abort request has reached the
1151 * controller and give it ample time to act before posting the rnc
1154 readl(&ihost->smu_registers->interrupt_status); /* flush */
1157 command = SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE |
1158 phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
1160 scic_sds_controller_post_request(ihost, command);
1165 * @object: This is the object which is cast to a struct isci_port object.
1167 * This method will perform the actions required by the struct isci_port on
1168 * exiting the SCI_PORT_SUB_OPERATIONAL. This function reports
1169 * the port not ready and suspends the port task scheduler. none
1171 static void scic_sds_port_ready_substate_operational_exit(struct sci_base_state_machine *sm)
1173 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1174 struct isci_host *ihost = iport->owning_controller;
1177 * Kill the dummy task for this port if it has not yet posted
1178 * the hardware will treat this as a NOP and just return abort
1181 scic_sds_port_abort_dummy_request(iport);
1183 isci_port_not_ready(ihost, iport);
1185 if (iport->ready_exit)
1186 scic_sds_port_invalidate_dummy_remote_node(iport);
1189 static void scic_sds_port_ready_substate_configuring_enter(struct sci_base_state_machine *sm)
1191 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1192 struct isci_host *ihost = iport->owning_controller;
1194 if (iport->active_phy_mask == 0) {
1195 isci_port_not_ready(ihost, iport);
1197 port_state_machine_change(iport,
1198 SCI_PORT_SUB_WAITING);
1199 } else if (iport->started_request_count == 0)
1200 port_state_machine_change(iport,
1201 SCI_PORT_SUB_OPERATIONAL);
1204 static void scic_sds_port_ready_substate_configuring_exit(struct sci_base_state_machine *sm)
1206 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1208 scic_sds_port_suspend_port_task_scheduler(iport);
1209 if (iport->ready_exit)
1210 scic_sds_port_invalidate_dummy_remote_node(iport);
1213 enum sci_status scic_sds_port_start(struct isci_port *iport)
1215 struct isci_host *ihost = iport->owning_controller;
1216 enum sci_status status = SCI_SUCCESS;
1217 enum scic_sds_port_states state;
1220 state = iport->sm.current_state_id;
1221 if (state != SCI_PORT_STOPPED) {
1222 dev_warn(sciport_to_dev(iport),
1223 "%s: in wrong state: %d\n", __func__, state);
1224 return SCI_FAILURE_INVALID_STATE;
1227 if (iport->assigned_device_count > 0) {
1228 /* TODO This is a start failure operation because
1229 * there are still devices assigned to this port.
1230 * There must be no devices assigned to a port on a
1233 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
1236 if (iport->reserved_rni == SCU_DUMMY_INDEX) {
1237 u16 rni = scic_sds_remote_node_table_allocate_remote_node(
1238 &ihost->available_remote_nodes, 1);
1240 if (rni != SCU_DUMMY_INDEX)
1241 scic_sds_port_construct_dummy_rnc(iport, rni);
1243 status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
1244 iport->reserved_rni = rni;
1247 if (iport->reserved_tag == SCI_CONTROLLER_INVALID_IO_TAG) {
1250 tag = isci_alloc_tag(ihost);
1251 if (tag == SCI_CONTROLLER_INVALID_IO_TAG)
1252 status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
1254 scic_sds_port_construct_dummy_task(iport, tag);
1255 iport->reserved_tag = tag;
1258 if (status == SCI_SUCCESS) {
1259 phy_mask = scic_sds_port_get_phys(iport);
1262 * There are one or more phys assigned to this port. Make sure
1263 * the port's phy mask is in fact legal and supported by the
1266 if (scic_sds_port_is_phy_mask_valid(iport, phy_mask) == true) {
1267 port_state_machine_change(iport,
1272 status = SCI_FAILURE;
1275 if (status != SCI_SUCCESS)
1276 scic_sds_port_destroy_dummy_resources(iport);
1281 enum sci_status scic_sds_port_stop(struct isci_port *iport)
1283 enum scic_sds_port_states state;
1285 state = iport->sm.current_state_id;
1287 case SCI_PORT_STOPPED:
1289 case SCI_PORT_SUB_WAITING:
1290 case SCI_PORT_SUB_OPERATIONAL:
1291 case SCI_PORT_SUB_CONFIGURING:
1292 case SCI_PORT_RESETTING:
1293 port_state_machine_change(iport,
1297 dev_warn(sciport_to_dev(iport),
1298 "%s: in wrong state: %d\n", __func__, state);
1299 return SCI_FAILURE_INVALID_STATE;
1303 static enum sci_status scic_port_hard_reset(struct isci_port *iport, u32 timeout)
1305 enum sci_status status = SCI_FAILURE_INVALID_PHY;
1306 struct isci_phy *iphy = NULL;
1307 enum scic_sds_port_states state;
1310 state = iport->sm.current_state_id;
1311 if (state != SCI_PORT_SUB_OPERATIONAL) {
1312 dev_warn(sciport_to_dev(iport),
1313 "%s: in wrong state: %d\n", __func__, state);
1314 return SCI_FAILURE_INVALID_STATE;
1317 /* Select a phy on which we can send the hard reset request. */
1318 for (phy_index = 0; phy_index < SCI_MAX_PHYS && !iphy; phy_index++) {
1319 iphy = iport->phy_table[phy_index];
1320 if (iphy && !scic_sds_port_active_phy(iport, iphy)) {
1322 * We found a phy but it is not ready select
1329 /* If we have a phy then go ahead and start the reset procedure */
1332 status = scic_sds_phy_reset(iphy);
1334 if (status != SCI_SUCCESS)
1337 sci_mod_timer(&iport->timer, timeout);
1338 iport->not_ready_reason = SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED;
1340 port_state_machine_change(iport, SCI_PORT_RESETTING);
1345 * scic_sds_port_add_phy() -
1346 * @sci_port: This parameter specifies the port in which the phy will be added.
1347 * @sci_phy: This parameter is the phy which is to be added to the port.
1349 * This method will add a PHY to the selected port. This method returns an
1350 * enum sci_status. SCI_SUCCESS the phy has been added to the port. Any other
1351 * status is a failure to add the phy to the port.
1353 enum sci_status scic_sds_port_add_phy(struct isci_port *iport,
1354 struct isci_phy *iphy)
1356 enum sci_status status;
1357 enum scic_sds_port_states state;
1359 state = iport->sm.current_state_id;
1361 case SCI_PORT_STOPPED: {
1362 struct sci_sas_address port_sas_address;
1364 /* Read the port assigned SAS Address if there is one */
1365 scic_sds_port_get_sas_address(iport, &port_sas_address);
1367 if (port_sas_address.high != 0 && port_sas_address.low != 0) {
1368 struct sci_sas_address phy_sas_address;
1370 /* Make sure that the PHY SAS Address matches the SAS Address
1373 scic_sds_phy_get_sas_address(iphy, &phy_sas_address);
1375 if (port_sas_address.high != phy_sas_address.high ||
1376 port_sas_address.low != phy_sas_address.low)
1377 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
1379 return scic_sds_port_set_phy(iport, iphy);
1381 case SCI_PORT_SUB_WAITING:
1382 case SCI_PORT_SUB_OPERATIONAL:
1383 status = scic_sds_port_set_phy(iport, iphy);
1385 if (status != SCI_SUCCESS)
1388 scic_sds_port_general_link_up_handler(iport, iphy, true);
1389 iport->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
1390 port_state_machine_change(iport, SCI_PORT_SUB_CONFIGURING);
1393 case SCI_PORT_SUB_CONFIGURING:
1394 status = scic_sds_port_set_phy(iport, iphy);
1396 if (status != SCI_SUCCESS)
1398 scic_sds_port_general_link_up_handler(iport, iphy, true);
1400 /* Re-enter the configuring state since this may be the last phy in
1403 port_state_machine_change(iport,
1404 SCI_PORT_SUB_CONFIGURING);
1407 dev_warn(sciport_to_dev(iport),
1408 "%s: in wrong state: %d\n", __func__, state);
1409 return SCI_FAILURE_INVALID_STATE;
1414 * scic_sds_port_remove_phy() -
1415 * @sci_port: This parameter specifies the port in which the phy will be added.
1416 * @sci_phy: This parameter is the phy which is to be added to the port.
1418 * This method will remove the PHY from the selected PORT. This method returns
1419 * an enum sci_status. SCI_SUCCESS the phy has been removed from the port. Any
1420 * other status is a failure to add the phy to the port.
1422 enum sci_status scic_sds_port_remove_phy(struct isci_port *iport,
1423 struct isci_phy *iphy)
1425 enum sci_status status;
1426 enum scic_sds_port_states state;
1428 state = iport->sm.current_state_id;
1431 case SCI_PORT_STOPPED:
1432 return scic_sds_port_clear_phy(iport, iphy);
1433 case SCI_PORT_SUB_OPERATIONAL:
1434 status = scic_sds_port_clear_phy(iport, iphy);
1435 if (status != SCI_SUCCESS)
1438 scic_sds_port_deactivate_phy(iport, iphy, true);
1439 iport->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
1440 port_state_machine_change(iport,
1441 SCI_PORT_SUB_CONFIGURING);
1443 case SCI_PORT_SUB_CONFIGURING:
1444 status = scic_sds_port_clear_phy(iport, iphy);
1446 if (status != SCI_SUCCESS)
1448 scic_sds_port_deactivate_phy(iport, iphy, true);
1450 /* Re-enter the configuring state since this may be the last phy in
1453 port_state_machine_change(iport,
1454 SCI_PORT_SUB_CONFIGURING);
1457 dev_warn(sciport_to_dev(iport),
1458 "%s: in wrong state: %d\n", __func__, state);
1459 return SCI_FAILURE_INVALID_STATE;
1463 enum sci_status scic_sds_port_link_up(struct isci_port *iport,
1464 struct isci_phy *iphy)
1466 enum scic_sds_port_states state;
1468 state = iport->sm.current_state_id;
1470 case SCI_PORT_SUB_WAITING:
1471 /* Since this is the first phy going link up for the port we
1472 * can just enable it and continue
1474 scic_sds_port_activate_phy(iport, iphy, true);
1476 port_state_machine_change(iport,
1477 SCI_PORT_SUB_OPERATIONAL);
1479 case SCI_PORT_SUB_OPERATIONAL:
1480 scic_sds_port_general_link_up_handler(iport, iphy, true);
1482 case SCI_PORT_RESETTING:
1483 /* TODO We should make sure that the phy that has gone
1484 * link up is the same one on which we sent the reset. It is
1485 * possible that the phy on which we sent the reset is not the
1486 * one that has gone link up and we want to make sure that
1487 * phy being reset comes back. Consider the case where a
1488 * reset is sent but before the hardware processes the reset it
1489 * get a link up on the port because of a hot plug event.
1490 * because of the reset request this phy will go link down
1491 * almost immediately.
1494 /* In the resetting state we don't notify the user regarding
1495 * link up and link down notifications.
1497 scic_sds_port_general_link_up_handler(iport, iphy, false);
1500 dev_warn(sciport_to_dev(iport),
1501 "%s: in wrong state: %d\n", __func__, state);
1502 return SCI_FAILURE_INVALID_STATE;
1506 enum sci_status scic_sds_port_link_down(struct isci_port *iport,
1507 struct isci_phy *iphy)
1509 enum scic_sds_port_states state;
1511 state = iport->sm.current_state_id;
1513 case SCI_PORT_SUB_OPERATIONAL:
1514 scic_sds_port_deactivate_phy(iport, iphy, true);
1516 /* If there are no active phys left in the port, then
1517 * transition the port to the WAITING state until such time
1518 * as a phy goes link up
1520 if (iport->active_phy_mask == 0)
1521 port_state_machine_change(iport,
1522 SCI_PORT_SUB_WAITING);
1524 case SCI_PORT_RESETTING:
1525 /* In the resetting state we don't notify the user regarding
1526 * link up and link down notifications. */
1527 scic_sds_port_deactivate_phy(iport, iphy, false);
1530 dev_warn(sciport_to_dev(iport),
1531 "%s: in wrong state: %d\n", __func__, state);
1532 return SCI_FAILURE_INVALID_STATE;
1536 enum sci_status scic_sds_port_start_io(struct isci_port *iport,
1537 struct isci_remote_device *idev,
1538 struct isci_request *ireq)
1540 enum scic_sds_port_states state;
1542 state = iport->sm.current_state_id;
1544 case SCI_PORT_SUB_WAITING:
1545 return SCI_FAILURE_INVALID_STATE;
1546 case SCI_PORT_SUB_OPERATIONAL:
1547 iport->started_request_count++;
1550 dev_warn(sciport_to_dev(iport),
1551 "%s: in wrong state: %d\n", __func__, state);
1552 return SCI_FAILURE_INVALID_STATE;
1556 enum sci_status scic_sds_port_complete_io(struct isci_port *iport,
1557 struct isci_remote_device *idev,
1558 struct isci_request *ireq)
1560 enum scic_sds_port_states state;
1562 state = iport->sm.current_state_id;
1564 case SCI_PORT_STOPPED:
1565 dev_warn(sciport_to_dev(iport),
1566 "%s: in wrong state: %d\n", __func__, state);
1567 return SCI_FAILURE_INVALID_STATE;
1568 case SCI_PORT_STOPPING:
1569 scic_sds_port_decrement_request_count(iport);
1571 if (iport->started_request_count == 0)
1572 port_state_machine_change(iport,
1575 case SCI_PORT_READY:
1576 case SCI_PORT_RESETTING:
1577 case SCI_PORT_FAILED:
1578 case SCI_PORT_SUB_WAITING:
1579 case SCI_PORT_SUB_OPERATIONAL:
1580 scic_sds_port_decrement_request_count(iport);
1582 case SCI_PORT_SUB_CONFIGURING:
1583 scic_sds_port_decrement_request_count(iport);
1584 if (iport->started_request_count == 0) {
1585 port_state_machine_change(iport,
1586 SCI_PORT_SUB_OPERATIONAL);
1595 * @sci_port: This is the port object which to suspend.
1597 * This method will enable the SCU Port Task Scheduler for this port object but
1598 * will leave the port task scheduler in a suspended state. none
1601 scic_sds_port_enable_port_task_scheduler(struct isci_port *iport)
1603 u32 pts_control_value;
1605 pts_control_value = readl(&iport->port_task_scheduler_registers->control);
1606 pts_control_value |= SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND);
1607 writel(pts_control_value, &iport->port_task_scheduler_registers->control);
1612 * @sci_port: This is the port object which to resume.
1614 * This method will disable the SCU port task scheduler for this port object.
1618 scic_sds_port_disable_port_task_scheduler(struct isci_port *iport)
1620 u32 pts_control_value;
1622 pts_control_value = readl(&iport->port_task_scheduler_registers->control);
1623 pts_control_value &=
1624 ~(SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND));
1625 writel(pts_control_value, &iport->port_task_scheduler_registers->control);
1628 static void scic_sds_port_post_dummy_remote_node(struct isci_port *iport)
1630 struct isci_host *ihost = iport->owning_controller;
1631 u8 phys_index = iport->physical_port_index;
1632 union scu_remote_node_context *rnc;
1633 u16 rni = iport->reserved_rni;
1636 rnc = &ihost->remote_node_context_table[rni];
1637 rnc->ssp.is_valid = true;
1639 command = SCU_CONTEXT_COMMAND_POST_RNC_32 |
1640 phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
1642 scic_sds_controller_post_request(ihost, command);
1644 /* ensure hardware has seen the post rnc command and give it
1645 * ample time to act before sending the suspend
1647 readl(&ihost->smu_registers->interrupt_status); /* flush */
1650 command = SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX |
1651 phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
1653 scic_sds_controller_post_request(ihost, command);
1656 static void scic_sds_port_stopped_state_enter(struct sci_base_state_machine *sm)
1658 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1660 if (iport->sm.previous_state_id == SCI_PORT_STOPPING) {
1662 * If we enter this state becasuse of a request to stop
1663 * the port then we want to disable the hardwares port
1664 * task scheduler. */
1665 scic_sds_port_disable_port_task_scheduler(iport);
1669 static void scic_sds_port_stopped_state_exit(struct sci_base_state_machine *sm)
1671 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1673 /* Enable and suspend the port task scheduler */
1674 scic_sds_port_enable_port_task_scheduler(iport);
1677 static void scic_sds_port_ready_state_enter(struct sci_base_state_machine *sm)
1679 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1680 struct isci_host *ihost = iport->owning_controller;
1683 prev_state = iport->sm.previous_state_id;
1684 if (prev_state == SCI_PORT_RESETTING)
1685 isci_port_hard_reset_complete(iport, SCI_SUCCESS);
1687 isci_port_not_ready(ihost, iport);
1689 /* Post and suspend the dummy remote node context for this port. */
1690 scic_sds_port_post_dummy_remote_node(iport);
1692 /* Start the ready substate machine */
1693 port_state_machine_change(iport,
1694 SCI_PORT_SUB_WAITING);
1697 static void scic_sds_port_resetting_state_exit(struct sci_base_state_machine *sm)
1699 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1701 sci_del_timer(&iport->timer);
1704 static void scic_sds_port_stopping_state_exit(struct sci_base_state_machine *sm)
1706 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1708 sci_del_timer(&iport->timer);
1710 scic_sds_port_destroy_dummy_resources(iport);
1713 static void scic_sds_port_failed_state_enter(struct sci_base_state_machine *sm)
1715 struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1717 isci_port_hard_reset_complete(iport, SCI_FAILURE_TIMEOUT);
1720 /* --------------------------------------------------------------------------- */
1722 static const struct sci_base_state scic_sds_port_state_table[] = {
1723 [SCI_PORT_STOPPED] = {
1724 .enter_state = scic_sds_port_stopped_state_enter,
1725 .exit_state = scic_sds_port_stopped_state_exit
1727 [SCI_PORT_STOPPING] = {
1728 .exit_state = scic_sds_port_stopping_state_exit
1730 [SCI_PORT_READY] = {
1731 .enter_state = scic_sds_port_ready_state_enter,
1733 [SCI_PORT_SUB_WAITING] = {
1734 .enter_state = scic_sds_port_ready_substate_waiting_enter,
1736 [SCI_PORT_SUB_OPERATIONAL] = {
1737 .enter_state = scic_sds_port_ready_substate_operational_enter,
1738 .exit_state = scic_sds_port_ready_substate_operational_exit
1740 [SCI_PORT_SUB_CONFIGURING] = {
1741 .enter_state = scic_sds_port_ready_substate_configuring_enter,
1742 .exit_state = scic_sds_port_ready_substate_configuring_exit
1744 [SCI_PORT_RESETTING] = {
1745 .exit_state = scic_sds_port_resetting_state_exit
1747 [SCI_PORT_FAILED] = {
1748 .enter_state = scic_sds_port_failed_state_enter,
1752 void scic_sds_port_construct(struct isci_port *iport, u8 index,
1753 struct isci_host *ihost)
1755 sci_init_sm(&iport->sm, scic_sds_port_state_table, SCI_PORT_STOPPED);
1757 iport->logical_port_index = SCIC_SDS_DUMMY_PORT;
1758 iport->physical_port_index = index;
1759 iport->active_phy_mask = 0;
1760 iport->ready_exit = false;
1762 iport->owning_controller = ihost;
1764 iport->started_request_count = 0;
1765 iport->assigned_device_count = 0;
1767 iport->reserved_rni = SCU_DUMMY_INDEX;
1768 iport->reserved_tag = SCI_CONTROLLER_INVALID_IO_TAG;
1770 sci_init_timer(&iport->timer, port_timeout);
1772 iport->port_task_scheduler_registers = NULL;
1774 for (index = 0; index < SCI_MAX_PHYS; index++)
1775 iport->phy_table[index] = NULL;
1778 void isci_port_init(struct isci_port *iport, struct isci_host *ihost, int index)
1780 INIT_LIST_HEAD(&iport->remote_dev_list);
1781 INIT_LIST_HEAD(&iport->domain_dev_list);
1782 spin_lock_init(&iport->state_lock);
1783 init_completion(&iport->start_complete);
1784 iport->isci_host = ihost;
1785 isci_port_change_state(iport, isci_freed);
1786 atomic_set(&iport->event, 0);
1790 * isci_port_get_state() - This function gets the status of the port object.
1791 * @isci_port: This parameter points to the isci_port object
1793 * status of the object as a isci_status enum.
1795 enum isci_status isci_port_get_state(
1796 struct isci_port *isci_port)
1798 return isci_port->status;
1801 void scic_sds_port_broadcast_change_received(
1802 struct isci_port *iport,
1803 struct isci_phy *iphy)
1805 struct isci_host *ihost = iport->owning_controller;
1807 /* notify the user. */
1808 isci_port_bc_change_received(ihost, iport, iphy);
1811 int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *iport,
1812 struct isci_phy *iphy)
1814 unsigned long flags;
1815 enum sci_status status;
1816 int idx, ret = TMF_RESP_FUNC_COMPLETE;
1818 dev_dbg(&ihost->pdev->dev, "%s: iport = %p\n",
1821 init_completion(&iport->hard_reset_complete);
1823 spin_lock_irqsave(&ihost->scic_lock, flags);
1825 #define ISCI_PORT_RESET_TIMEOUT SCIC_SDS_SIGNATURE_FIS_TIMEOUT
1826 status = scic_port_hard_reset(iport, ISCI_PORT_RESET_TIMEOUT);
1828 spin_unlock_irqrestore(&ihost->scic_lock, flags);
1830 if (status == SCI_SUCCESS) {
1831 wait_for_completion(&iport->hard_reset_complete);
1833 dev_dbg(&ihost->pdev->dev,
1834 "%s: iport = %p; hard reset completion\n",
1837 if (iport->hard_reset_status != SCI_SUCCESS)
1838 ret = TMF_RESP_FUNC_FAILED;
1840 ret = TMF_RESP_FUNC_FAILED;
1842 dev_err(&ihost->pdev->dev,
1843 "%s: iport = %p; scic_port_hard_reset call"
1845 __func__, iport, status);
1849 /* If the hard reset for the port has failed, consider this
1850 * the same as link failures on all phys in the port.
1852 if (ret != TMF_RESP_FUNC_COMPLETE) {
1854 dev_err(&ihost->pdev->dev,
1855 "%s: iport = %p; hard reset failed "
1856 "(0x%x) - driving explicit link fail for all phys\n",
1857 __func__, iport, iport->hard_reset_status);
1859 /* Down all phys in the port. */
1860 spin_lock_irqsave(&ihost->scic_lock, flags);
1861 for (idx = 0; idx < SCI_MAX_PHYS; ++idx) {
1862 struct isci_phy *iphy = iport->phy_table[idx];
1866 scic_sds_phy_stop(iphy);
1867 scic_sds_phy_start(iphy);
1869 spin_unlock_irqrestore(&ihost->scic_lock, flags);
1875 * isci_port_deformed() - This function is called by libsas when a port becomes
1877 * @phy: This parameter specifies the libsas phy with the inactive port.
1880 void isci_port_deformed(struct asd_sas_phy *phy)
1882 pr_debug("%s: sas_phy = %p\n", __func__, phy);
1886 * isci_port_formed() - This function is called by libsas when a port becomes
1888 * @phy: This parameter specifies the libsas phy with the active port.
1891 void isci_port_formed(struct asd_sas_phy *phy)
1893 pr_debug("%s: sas_phy = %p, sas_port = %p\n", __func__, phy, phy->port);