2 * This file is provided under a dual BSD/GPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
33 * * Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * * Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in
37 * the documentation and/or other materials provided with the
39 * * Neither the name of Intel Corporation nor the names of its
40 * contributors may be used to endorse or promote products derived
41 * from this software without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
44 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
45 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
46 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
47 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
50 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
51 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
53 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 #define SCIC_SDS_PORT_HARD_RESET_TIMEOUT (1000)
62 #define SCU_DUMMY_INDEX (0xFFFF)
64 static struct scic_sds_port_state_handler scic_sds_port_state_handler_table[];
66 static void isci_port_change_state(struct isci_port *iport, enum isci_status status)
70 dev_dbg(&iport->isci_host->pdev->dev,
71 "%s: iport = %p, state = 0x%x\n",
72 __func__, iport, status);
74 /* XXX pointless lock */
75 spin_lock_irqsave(&iport->state_lock, flags);
76 iport->status = status;
77 spin_unlock_irqrestore(&iport->state_lock, flags);
81 * This function will indicate which protocols are supported by this port.
82 * @sci_port: a handle corresponding to the SAS port for which to return the
83 * supported protocols.
84 * @protocols: This parameter specifies a pointer to a data structure
85 * which the core will copy the protocol values for the port from the
86 * transmit_identification register.
89 scic_sds_port_get_protocols(struct scic_sds_port *sci_port,
90 struct scic_phy_proto *protocols)
96 for (index = 0; index < SCI_MAX_PHYS; index++) {
97 if (sci_port->phy_table[index] != NULL) {
98 scic_sds_phy_get_protocols(sci_port->phy_table[index],
105 * This method requests a list (mask) of the phys contained in the supplied SAS
107 * @sci_port: a handle corresponding to the SAS port for which to return the
110 * Return a bit mask indicating which phys are a part of this port. Each bit
111 * corresponds to a phy identifier (e.g. bit 0 = phy id 0).
113 static u32 scic_sds_port_get_phys(struct scic_sds_port *sci_port)
120 for (index = 0; index < SCI_MAX_PHYS; index++) {
121 if (sci_port->phy_table[index] != NULL) {
122 mask |= (1 << index);
130 * scic_port_get_properties() - This method simply returns the properties
131 * regarding the port, such as: physical index, protocols, sas address, etc.
132 * @port: this parameter specifies the port for which to retrieve the physical
134 * @properties: This parameter specifies the properties structure into which to
135 * copy the requested information.
137 * Indicate if the user specified a valid port. SCI_SUCCESS This value is
138 * returned if the specified port was valid. SCI_FAILURE_INVALID_PORT This
139 * value is returned if the specified port is not valid. When this value is
140 * returned, no data is copied to the properties output parameter.
142 static enum sci_status scic_port_get_properties(struct scic_sds_port *port,
143 struct scic_port_properties *prop)
145 if ((port == NULL) ||
146 (port->logical_port_index == SCIC_SDS_DUMMY_PORT))
147 return SCI_FAILURE_INVALID_PORT;
149 prop->index = port->logical_port_index;
150 prop->phy_mask = scic_sds_port_get_phys(port);
151 scic_sds_port_get_sas_address(port, &prop->local.sas_address);
152 scic_sds_port_get_protocols(port, &prop->local.protocols);
153 scic_sds_port_get_attached_sas_address(port, &prop->remote.sas_address);
158 static void isci_port_link_up(struct isci_host *isci_host,
159 struct scic_sds_port *port,
160 struct scic_sds_phy *phy)
163 struct scic_port_properties properties;
164 struct isci_phy *isci_phy = sci_phy_to_iphy(phy);
165 struct isci_port *isci_port = sci_port_to_iport(port);
166 unsigned long success = true;
168 BUG_ON(isci_phy->isci_port != NULL);
170 isci_phy->isci_port = isci_port;
172 dev_dbg(&isci_host->pdev->dev,
173 "%s: isci_port = %p\n",
174 __func__, isci_port);
176 spin_lock_irqsave(&isci_phy->sas_phy.frame_rcvd_lock, flags);
178 isci_port_change_state(isci_phy->isci_port, isci_starting);
180 scic_port_get_properties(port, &properties);
182 if (phy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) {
183 u64 attached_sas_address;
185 isci_phy->sas_phy.oob_mode = SATA_OOB_MODE;
186 isci_phy->sas_phy.frame_rcvd_size = sizeof(struct dev_to_host_fis);
189 * For direct-attached SATA devices, the SCI core will
190 * automagically assign a SAS address to the end device
191 * for the purpose of creating a port. This SAS address
192 * will not be the same as assigned to the PHY and needs
193 * to be obtained from struct scic_port_properties properties.
195 attached_sas_address = properties.remote.sas_address.high;
196 attached_sas_address <<= 32;
197 attached_sas_address |= properties.remote.sas_address.low;
198 swab64s(&attached_sas_address);
200 memcpy(&isci_phy->sas_phy.attached_sas_addr,
201 &attached_sas_address, sizeof(attached_sas_address));
202 } else if (phy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
203 isci_phy->sas_phy.oob_mode = SAS_OOB_MODE;
204 isci_phy->sas_phy.frame_rcvd_size = sizeof(struct sas_identify_frame);
206 /* Copy the attached SAS address from the IAF */
207 memcpy(isci_phy->sas_phy.attached_sas_addr,
208 isci_phy->frame_rcvd.iaf.sas_addr, SAS_ADDR_SIZE);
210 dev_err(&isci_host->pdev->dev, "%s: unkown target\n", __func__);
214 isci_phy->sas_phy.phy->negotiated_linkrate = sci_phy_linkrate(phy);
216 spin_unlock_irqrestore(&isci_phy->sas_phy.frame_rcvd_lock, flags);
218 /* Notify libsas that we have an address frame, if indeed
219 * we've found an SSP, SMP, or STP target */
221 isci_host->sas_ha.notify_port_event(&isci_phy->sas_phy,
227 * isci_port_link_down() - This function is called by the sci core when a link
229 * @isci_host: This parameter specifies the isci host object.
230 * @phy: This parameter specifies the isci phy with the active link.
231 * @port: This parameter specifies the isci port with the active link.
234 static void isci_port_link_down(struct isci_host *isci_host,
235 struct isci_phy *isci_phy,
236 struct isci_port *isci_port)
238 struct isci_remote_device *isci_device;
240 dev_dbg(&isci_host->pdev->dev,
241 "%s: isci_port = %p\n", __func__, isci_port);
245 /* check to see if this is the last phy on this port. */
246 if (isci_phy->sas_phy.port
247 && isci_phy->sas_phy.port->num_phys == 1) {
249 /* change the state for all devices on this port.
250 * The next task sent to this device will be returned
251 * as SAS_TASK_UNDELIVERED, and the scsi mid layer
252 * will remove the target
254 list_for_each_entry(isci_device,
255 &isci_port->remote_dev_list,
257 dev_dbg(&isci_host->pdev->dev,
258 "%s: isci_device = %p\n",
259 __func__, isci_device);
260 isci_remote_device_change_state(isci_device,
264 isci_port_change_state(isci_port, isci_stopping);
267 /* Notify libsas of the borken link, this will trigger calls to our
268 * isci_port_deformed and isci_dev_gone functions.
270 sas_phy_disconnected(&isci_phy->sas_phy);
271 isci_host->sas_ha.notify_phy_event(&isci_phy->sas_phy,
272 PHYE_LOSS_OF_SIGNAL);
274 isci_phy->isci_port = NULL;
276 dev_dbg(&isci_host->pdev->dev,
277 "%s: isci_port = %p - Done\n", __func__, isci_port);
282 * isci_port_ready() - This function is called by the sci core when a link
284 * @isci_host: This parameter specifies the isci host object.
285 * @port: This parameter specifies the sci port with the active link.
288 static void isci_port_ready(struct isci_host *isci_host, struct isci_port *isci_port)
290 dev_dbg(&isci_host->pdev->dev,
291 "%s: isci_port = %p\n", __func__, isci_port);
293 complete_all(&isci_port->start_complete);
294 isci_port_change_state(isci_port, isci_ready);
299 * isci_port_not_ready() - This function is called by the sci core when a link
300 * is not ready. All remote devices on this link will be removed if they are
301 * in the stopping state.
302 * @isci_host: This parameter specifies the isci host object.
303 * @port: This parameter specifies the sci port with the active link.
306 static void isci_port_not_ready(struct isci_host *isci_host, struct isci_port *isci_port)
308 dev_dbg(&isci_host->pdev->dev,
309 "%s: isci_port = %p\n", __func__, isci_port);
312 static void isci_port_stop_complete(struct scic_sds_controller *scic,
313 struct scic_sds_port *sci_port,
314 enum sci_status completion_status)
316 dev_dbg(&scic_to_ihost(scic)->pdev->dev, "Port stop complete\n");
320 * isci_port_hard_reset_complete() - This function is called by the sci core
321 * when the hard reset complete notification has been received.
322 * @port: This parameter specifies the sci port with the active link.
323 * @completion_status: This parameter specifies the core status for the reset
327 static void isci_port_hard_reset_complete(struct isci_port *isci_port,
328 enum sci_status completion_status)
330 dev_dbg(&isci_port->isci_host->pdev->dev,
331 "%s: isci_port = %p, completion_status=%x\n",
332 __func__, isci_port, completion_status);
334 /* Save the status of the hard reset from the port. */
335 isci_port->hard_reset_status = completion_status;
337 complete_all(&isci_port->hard_reset_complete);
340 /* This method will return a true value if the specified phy can be assigned to
341 * this port The following is a list of phys for each port that are allowed: -
342 * Port 0 - 3 2 1 0 - Port 1 - 1 - Port 2 - 3 2 - Port 3 - 3 This method
343 * doesn't preclude all configurations. It merely ensures that a phy is part
344 * of the allowable set of phy identifiers for that port. For example, one
345 * could assign phy 3 to port 0 and no other phys. Please refer to
346 * scic_sds_port_is_phy_mask_valid() for information regarding whether the
347 * phy_mask for a port can be supported. bool true if this is a valid phy
348 * assignment for the port false if this is not a valid phy assignment for the
351 bool scic_sds_port_is_valid_phy_assignment(struct scic_sds_port *sci_port,
354 /* Initialize to invalid value. */
355 u32 existing_phy_index = SCI_MAX_PHYS;
358 if ((sci_port->physical_port_index == 1) && (phy_index != 1)) {
362 if (sci_port->physical_port_index == 3 && phy_index != 3) {
367 (sci_port->physical_port_index == 2)
368 && ((phy_index == 0) || (phy_index == 1))
373 for (index = 0; index < SCI_MAX_PHYS; index++) {
374 if ((sci_port->phy_table[index] != NULL)
375 && (index != phy_index)) {
376 existing_phy_index = index;
381 * Ensure that all of the phys in the port are capable of
382 * operating at the same maximum link rate. */
384 (existing_phy_index < SCI_MAX_PHYS)
385 && (sci_port->owning_controller->user_parameters.sds1.phys[
386 phy_index].max_speed_generation !=
387 sci_port->owning_controller->user_parameters.sds1.phys[
388 existing_phy_index].max_speed_generation)
397 * @sci_port: This is the port object for which to determine if the phy mask
400 * This method will return a true value if the port's phy mask can be supported
401 * by the SCU. The following is a list of valid PHY mask configurations for
402 * each port: - Port 0 - [[3 2] 1] 0 - Port 1 - [1] - Port 2 - [[3] 2]
403 * - Port 3 - [3] This method returns a boolean indication specifying if the
404 * phy mask can be supported. true if this is a valid phy assignment for the
405 * port false if this is not a valid phy assignment for the port
407 static bool scic_sds_port_is_phy_mask_valid(
408 struct scic_sds_port *sci_port,
411 if (sci_port->physical_port_index == 0) {
412 if (((phy_mask & 0x0F) == 0x0F)
413 || ((phy_mask & 0x03) == 0x03)
414 || ((phy_mask & 0x01) == 0x01)
417 } else if (sci_port->physical_port_index == 1) {
418 if (((phy_mask & 0x02) == 0x02)
421 } else if (sci_port->physical_port_index == 2) {
422 if (((phy_mask & 0x0C) == 0x0C)
423 || ((phy_mask & 0x04) == 0x04)
426 } else if (sci_port->physical_port_index == 3) {
427 if (((phy_mask & 0x08) == 0x08)
437 * @sci_port: This parameter specifies the port from which to return a
440 * This method retrieves a currently active (i.e. connected) phy contained in
441 * the port. Currently, the lowest order phy that is connected is returned.
442 * This method returns a pointer to a SCIS_SDS_PHY object. NULL This value is
443 * returned if there are no currently active (i.e. connected to a remote end
444 * point) phys contained in the port. All other values specify a struct scic_sds_phy
445 * object that is active in the port.
447 static struct scic_sds_phy *scic_sds_port_get_a_connected_phy(
448 struct scic_sds_port *sci_port
451 struct scic_sds_phy *phy;
453 for (index = 0; index < SCI_MAX_PHYS; index++) {
455 * Ensure that the phy is both part of the port and currently
456 * connected to the remote end-point. */
457 phy = sci_port->phy_table[index];
460 && scic_sds_port_active_phy(sci_port, phy)
470 * scic_sds_port_set_phy() -
471 * @out]: port The port object to which the phy assignement is being made.
472 * @out]: phy The phy which is being assigned to the port.
474 * This method attempts to make the assignment of the phy to the port. If
475 * successful the phy is assigned to the ports phy table. bool true if the phy
476 * assignment can be made. false if the phy assignement can not be made. This
477 * is a functional test that only fails if the phy is currently assigned to a
480 static enum sci_status scic_sds_port_set_phy(
481 struct scic_sds_port *port,
482 struct scic_sds_phy *phy)
485 * Check to see if we can add this phy to a port
486 * that means that the phy is not part of a port and that the port does
487 * not already have a phy assinged to the phy index. */
489 (port->phy_table[phy->phy_index] == NULL)
490 && (phy_get_non_dummy_port(phy) == NULL)
491 && scic_sds_port_is_valid_phy_assignment(port, phy->phy_index)
494 * Phy is being added in the stopped state so we are in MPC mode
495 * make logical port index = physical port index */
496 port->logical_port_index = port->physical_port_index;
497 port->phy_table[phy->phy_index] = phy;
498 scic_sds_phy_set_port(phy, port);
507 * scic_sds_port_clear_phy() -
508 * @out]: port The port from which the phy is being cleared.
509 * @out]: phy The phy being cleared from the port.
511 * This method will clear the phy assigned to this port. This method fails if
512 * this phy is not currently assinged to this port. bool true if the phy is
513 * removed from the port. false if this phy is not assined to this port.
515 static enum sci_status scic_sds_port_clear_phy(
516 struct scic_sds_port *port,
517 struct scic_sds_phy *phy)
519 /* Make sure that this phy is part of this port */
520 if (port->phy_table[phy->phy_index] == phy &&
521 phy_get_non_dummy_port(phy) == port) {
522 struct scic_sds_controller *scic = port->owning_controller;
523 struct isci_host *ihost = scic_to_ihost(scic);
525 /* Yep it is assigned to this port so remove it */
526 scic_sds_phy_set_port(phy, &ihost->ports[SCI_MAX_PORTS].sci);
527 port->phy_table[phy->phy_index] = NULL;
535 * scic_sds_port_add_phy() -
536 * @sci_port: This parameter specifies the port in which the phy will be added.
537 * @sci_phy: This parameter is the phy which is to be added to the port.
539 * This method will add a PHY to the selected port. This method returns an
540 * enum sci_status. SCI_SUCCESS the phy has been added to the port. Any other status
541 * is failre to add the phy to the port.
543 enum sci_status scic_sds_port_add_phy(
544 struct scic_sds_port *sci_port,
545 struct scic_sds_phy *sci_phy)
547 return sci_port->state_handlers->add_phy_handler(
553 * scic_sds_port_remove_phy() -
554 * @sci_port: This parameter specifies the port in which the phy will be added.
555 * @sci_phy: This parameter is the phy which is to be added to the port.
557 * This method will remove the PHY from the selected PORT. This method returns
558 * an enum sci_status. SCI_SUCCESS the phy has been removed from the port. Any other
559 * status is failre to add the phy to the port.
561 enum sci_status scic_sds_port_remove_phy(
562 struct scic_sds_port *sci_port,
563 struct scic_sds_phy *sci_phy)
565 return sci_port->state_handlers->remove_phy_handler(
570 * This method requests the SAS address for the supplied SAS port from the SCI
572 * @sci_port: a handle corresponding to the SAS port for which to return the
574 * @sas_address: This parameter specifies a pointer to a SAS address structure
575 * into which the core will copy the SAS address for the port.
578 void scic_sds_port_get_sas_address(
579 struct scic_sds_port *sci_port,
580 struct sci_sas_address *sas_address)
584 sas_address->high = 0;
585 sas_address->low = 0;
587 for (index = 0; index < SCI_MAX_PHYS; index++) {
588 if (sci_port->phy_table[index] != NULL) {
589 scic_sds_phy_get_sas_address(sci_port->phy_table[index], sas_address);
595 * This function requests the SAS address for the device directly attached to
597 * @sci_port: a handle corresponding to the SAS port for which to return the
599 * @sas_address: This parameter specifies a pointer to a SAS address structure
600 * into which the core will copy the SAS address for the device directly
601 * attached to the port.
604 void scic_sds_port_get_attached_sas_address(
605 struct scic_sds_port *sci_port,
606 struct sci_sas_address *sas_address)
608 struct scic_sds_phy *sci_phy;
611 * Ensure that the phy is both part of the port and currently
612 * connected to the remote end-point.
614 sci_phy = scic_sds_port_get_a_connected_phy(sci_port);
616 if (sci_phy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA) {
617 scic_sds_phy_get_attached_sas_address(sci_phy,
620 scic_sds_phy_get_sas_address(sci_phy, sas_address);
621 sas_address->low += sci_phy->phy_index;
624 sas_address->high = 0;
625 sas_address->low = 0;
630 * scic_sds_port_construct_dummy_rnc() - create dummy rnc for si workaround
632 * @sci_port: logical port on which we need to create the remote node context
633 * @rni: remote node index for this remote node context.
635 * This routine will construct a dummy remote node context data structure
636 * This structure will be posted to the hardware to work around a scheduler
637 * error in the hardware.
639 static void scic_sds_port_construct_dummy_rnc(struct scic_sds_port *sci_port, u16 rni)
641 union scu_remote_node_context *rnc;
643 rnc = &sci_port->owning_controller->remote_node_context_table[rni];
645 memset(rnc, 0, sizeof(union scu_remote_node_context));
647 rnc->ssp.remote_sas_address_hi = 0;
648 rnc->ssp.remote_sas_address_lo = 0;
650 rnc->ssp.remote_node_index = rni;
651 rnc->ssp.remote_node_port_width = 1;
652 rnc->ssp.logical_port_index = sci_port->physical_port_index;
654 rnc->ssp.nexus_loss_timer_enable = false;
655 rnc->ssp.check_bit = false;
656 rnc->ssp.is_valid = true;
657 rnc->ssp.is_remote_node_context = true;
658 rnc->ssp.function_number = 0;
659 rnc->ssp.arbitration_wait_time = 0;
663 * scic_sds_port_construct_dummy_task() - create dummy task for si workaround
664 * @sci_port The logical port on which we need to create the
665 * remote node context.
667 * @tci The remote node index for this remote node context.
669 * This routine will construct a dummy task context data structure. This
670 * structure will be posted to the hardwre to work around a scheduler error
674 static void scic_sds_port_construct_dummy_task(struct scic_sds_port *sci_port, u16 tci)
676 struct scu_task_context *task_context;
678 task_context = scic_sds_controller_get_task_context_buffer(sci_port->owning_controller, tci);
680 memset(task_context, 0, sizeof(struct scu_task_context));
682 task_context->abort = 0;
683 task_context->priority = 0;
684 task_context->initiator_request = 1;
685 task_context->connection_rate = 1;
686 task_context->protocol_engine_index = 0;
687 task_context->logical_port_index = sci_port->physical_port_index;
688 task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SSP;
689 task_context->task_index = scic_sds_io_tag_get_index(tci);
690 task_context->valid = SCU_TASK_CONTEXT_VALID;
691 task_context->context_type = SCU_TASK_CONTEXT_TYPE;
693 task_context->remote_node_index = sci_port->reserved_rni;
694 task_context->command_code = 0;
696 task_context->link_layer_control = 0;
697 task_context->do_not_dma_ssp_good_response = 1;
698 task_context->strict_ordering = 0;
699 task_context->control_frame = 0;
700 task_context->timeout_enable = 0;
701 task_context->block_guard_enable = 0;
703 task_context->address_modifier = 0;
705 task_context->task_phase = 0x01;
708 static void scic_sds_port_destroy_dummy_resources(struct scic_sds_port *sci_port)
710 struct scic_sds_controller *scic = sci_port->owning_controller;
712 if (sci_port->reserved_tci != SCU_DUMMY_INDEX)
713 scic_controller_free_io_tag(scic, sci_port->reserved_tci);
715 if (sci_port->reserved_rni != SCU_DUMMY_INDEX)
716 scic_sds_remote_node_table_release_remote_node_index(&scic->available_remote_nodes,
717 1, sci_port->reserved_rni);
719 sci_port->reserved_rni = SCU_DUMMY_INDEX;
720 sci_port->reserved_tci = SCU_DUMMY_INDEX;
724 * This method performs initialization of the supplied port. Initialization
725 * includes: - state machine initialization - member variable initialization
726 * - configuring the phy_mask
728 * @transport_layer_registers:
729 * @port_task_scheduler_registers:
730 * @port_configuration_regsiter:
732 * enum sci_status SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION This value is returned
733 * if the phy being added to the port
735 enum sci_status scic_sds_port_initialize(
736 struct scic_sds_port *sci_port,
737 void __iomem *port_task_scheduler_registers,
738 void __iomem *port_configuration_regsiter,
739 void __iomem *viit_registers)
741 sci_port->port_task_scheduler_registers = port_task_scheduler_registers;
742 sci_port->port_pe_configuration_register = port_configuration_regsiter;
743 sci_port->viit_registers = viit_registers;
749 * scic_port_hard_reset() - perform port hard reset
750 * @port: a handle corresponding to the SAS port to be hard reset.
751 * @reset_timeout: This parameter specifies the number of milliseconds in which
752 * the port reset operation should complete.
754 * The SCI User callback in scic_user_callbacks_t will only be called once for
755 * each phy in the SAS Port at completion of the hard reset sequence. Return a
756 * status indicating whether the hard reset started successfully. SCI_SUCCESS
757 * This value is returned if the hard reset operation started successfully.
759 static enum sci_status scic_port_hard_reset(struct scic_sds_port *port,
762 return port->state_handlers->reset_handler(
763 port, reset_timeout);
767 * This method assigns the direct attached device ID for this port.
769 * @param[in] sci_port The port for which the direct attached device id is to
771 * @param[in] device_id The direct attached device ID to assign to the port.
772 * This will be the RNi for the device
774 void scic_sds_port_setup_transports(
775 struct scic_sds_port *sci_port,
780 for (index = 0; index < SCI_MAX_PHYS; index++) {
781 if (sci_port->active_phy_mask & (1 << index))
782 scic_sds_phy_setup_transport(sci_port->phy_table[index], device_id);
788 * @sci_port: This is the port on which the phy should be enabled.
789 * @sci_phy: This is the specific phy which to enable.
790 * @do_notify_user: This parameter specifies whether to inform the user (via
791 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
793 * This function will activate the phy in the port.
794 * Activation includes: - adding
795 * the phy to the port - enabling the Protocol Engine in the silicon. -
796 * notifying the user that the link is up. none
798 static void scic_sds_port_activate_phy(struct scic_sds_port *sci_port,
799 struct scic_sds_phy *sci_phy,
802 struct scic_sds_controller *scic = sci_port->owning_controller;
803 struct isci_host *ihost = scic_to_ihost(scic);
805 if (sci_phy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA)
806 scic_sds_phy_resume(sci_phy);
808 sci_port->active_phy_mask |= 1 << sci_phy->phy_index;
810 scic_sds_controller_clear_invalid_phy(scic, sci_phy);
812 if (do_notify_user == true)
813 isci_port_link_up(ihost, sci_port, sci_phy);
816 void scic_sds_port_deactivate_phy(struct scic_sds_port *sci_port,
817 struct scic_sds_phy *sci_phy,
820 struct scic_sds_controller *scic = scic_sds_port_get_controller(sci_port);
821 struct isci_port *iport = sci_port_to_iport(sci_port);
822 struct isci_host *ihost = scic_to_ihost(scic);
823 struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
825 sci_port->active_phy_mask &= ~(1 << sci_phy->phy_index);
827 sci_phy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
829 /* Re-assign the phy back to the LP as if it were a narrow port */
830 writel(sci_phy->phy_index,
831 &sci_port->port_pe_configuration_register[sci_phy->phy_index]);
833 if (do_notify_user == true)
834 isci_port_link_down(ihost, iphy, iport);
839 * @sci_port: This is the port on which the phy should be disabled.
840 * @sci_phy: This is the specific phy which to disabled.
842 * This function will disable the phy and report that the phy is not valid for
843 * this port object. None
845 static void scic_sds_port_invalid_link_up(struct scic_sds_port *sci_port,
846 struct scic_sds_phy *sci_phy)
848 struct scic_sds_controller *scic = sci_port->owning_controller;
851 * Check to see if we have alreay reported this link as bad and if
852 * not go ahead and tell the SCI_USER that we have discovered an
855 if ((scic->invalid_phy_mask & (1 << sci_phy->phy_index)) == 0) {
856 scic_sds_controller_set_invalid_phy(scic, sci_phy);
857 dev_warn(&scic_to_ihost(scic)->pdev->dev, "Invalid link up!\n");
861 static bool is_port_ready_state(enum scic_sds_port_states state)
864 case SCI_BASE_PORT_STATE_READY:
865 case SCIC_SDS_PORT_READY_SUBSTATE_WAITING:
866 case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL:
867 case SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING:
874 /* flag dummy rnc hanling when exiting a ready state */
875 static void port_state_machine_change(struct scic_sds_port *sci_port,
876 enum scic_sds_port_states state)
878 struct sci_base_state_machine *sm = &sci_port->state_machine;
879 enum scic_sds_port_states old_state = sm->current_state_id;
881 if (is_port_ready_state(old_state) && !is_port_ready_state(state))
882 sci_port->ready_exit = true;
884 sci_base_state_machine_change_state(sm, state);
885 sci_port->ready_exit = false;
888 static void port_state_machine_stop(struct scic_sds_port *sci_port)
890 sci_port->ready_exit = true;
891 sci_base_state_machine_stop(&sci_port->state_machine);
892 sci_port->ready_exit = false;
896 * scic_sds_port_general_link_up_handler - phy can be assigned to port?
897 * @sci_port: scic_sds_port object for which has a phy that has gone link up.
898 * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
899 * @do_notify_user: This parameter specifies whether to inform the user (via
900 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
902 * Determine if this phy can be assigned to this
903 * port . If the phy is not a valid PHY for
904 * this port then the function will notify the user. A PHY can only be
905 * part of a port if it's attached SAS ADDRESS is the same as all other PHYs in
906 * the same port. none
908 static void scic_sds_port_general_link_up_handler(struct scic_sds_port *sci_port,
909 struct scic_sds_phy *sci_phy,
912 struct sci_sas_address port_sas_address;
913 struct sci_sas_address phy_sas_address;
915 scic_sds_port_get_attached_sas_address(sci_port, &port_sas_address);
916 scic_sds_phy_get_attached_sas_address(sci_phy, &phy_sas_address);
918 /* If the SAS address of the new phy matches the SAS address of
919 * other phys in the port OR this is the first phy in the port,
920 * then activate the phy and allow it to be used for operations
923 if ((phy_sas_address.high == port_sas_address.high &&
924 phy_sas_address.low == port_sas_address.low) ||
925 sci_port->active_phy_mask == 0) {
926 struct sci_base_state_machine *sm = &sci_port->state_machine;
928 scic_sds_port_activate_phy(sci_port, sci_phy, do_notify_user);
929 if (sm->current_state_id == SCI_BASE_PORT_STATE_RESETTING)
930 port_state_machine_change(sci_port, SCI_BASE_PORT_STATE_READY);
932 scic_sds_port_invalid_link_up(sci_port, sci_phy);
938 * This method returns false if the port only has a single phy object assigned.
939 * If there are no phys or more than one phy then the method will return
941 * @sci_port: The port for which the wide port condition is to be checked.
943 * bool true Is returned if this is a wide ported port. false Is returned if
944 * this is a narrow port.
946 static bool scic_sds_port_is_wide(struct scic_sds_port *sci_port)
951 for (index = 0; index < SCI_MAX_PHYS; index++) {
952 if (sci_port->phy_table[index] != NULL) {
957 return phy_count != 1;
961 * This method is called by the PHY object when the link is detected. if the
962 * port wants the PHY to continue on to the link up state then the port
963 * layer must return true. If the port object returns false the phy object
964 * must halt its attempt to go link up.
965 * @sci_port: The port associated with the phy object.
966 * @sci_phy: The phy object that is trying to go link up.
968 * true if the phy object can continue to the link up condition. true Is
969 * returned if this phy can continue to the ready state. false Is returned if
970 * can not continue on to the ready state. This notification is in place for
971 * wide ports and direct attached phys. Since there are no wide ported SATA
972 * devices this could become an invalid port configuration.
974 bool scic_sds_port_link_detected(
975 struct scic_sds_port *sci_port,
976 struct scic_sds_phy *sci_phy)
978 if ((sci_port->logical_port_index != SCIC_SDS_DUMMY_PORT) &&
979 (sci_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) &&
980 scic_sds_port_is_wide(sci_port)) {
981 scic_sds_port_invalid_link_up(sci_port, sci_phy);
990 * This method is the entry point for the phy to inform the port that it is now
996 void scic_sds_port_link_up(
997 struct scic_sds_port *sci_port,
998 struct scic_sds_phy *sci_phy)
1000 sci_phy->is_in_link_training = false;
1002 sci_port->state_handlers->link_up_handler(sci_port, sci_phy);
1006 * This method is the entry point for the phy to inform the port that it is no
1007 * longer in a ready state
1012 void scic_sds_port_link_down(
1013 struct scic_sds_port *sci_port,
1014 struct scic_sds_phy *sci_phy)
1016 sci_port->state_handlers->link_down_handler(sci_port, sci_phy);
1020 * This method is called to start an IO request on this port.
1027 enum sci_status scic_sds_port_start_io(
1028 struct scic_sds_port *sci_port,
1029 struct scic_sds_remote_device *sci_dev,
1030 struct scic_sds_request *sci_req)
1032 return sci_port->state_handlers->start_io_handler(
1033 sci_port, sci_dev, sci_req);
1037 * This method is called to complete an IO request to the port.
1044 enum sci_status scic_sds_port_complete_io(
1045 struct scic_sds_port *sci_port,
1046 struct scic_sds_remote_device *sci_dev,
1047 struct scic_sds_request *sci_req)
1049 return sci_port->state_handlers->complete_io_handler(
1050 sci_port, sci_dev, sci_req);
1054 * This method is provided to timeout requests for port operations. Mostly its
1055 * for the port reset operation.
1059 static void scic_sds_port_timeout_handler(void *port)
1061 struct scic_sds_port *sci_port = port;
1064 current_state = sci_base_state_machine_get_state(&sci_port->state_machine);
1066 if (current_state == SCI_BASE_PORT_STATE_RESETTING) {
1067 /* if the port is still in the resetting state then the timeout
1068 * fired before the reset completed.
1070 port_state_machine_change(sci_port, SCI_BASE_PORT_STATE_FAILED);
1071 } else if (current_state == SCI_BASE_PORT_STATE_STOPPED) {
1072 /* if the port is stopped then the start request failed In this
1073 * case stay in the stopped state.
1075 dev_err(sciport_to_dev(sci_port),
1076 "%s: SCIC Port 0x%p failed to stop before tiemout.\n",
1079 } else if (current_state == SCI_BASE_PORT_STATE_STOPPING) {
1080 /* if the port is still stopping then the stop has not completed */
1081 isci_port_stop_complete(sci_port->owning_controller,
1083 SCI_FAILURE_TIMEOUT);
1085 /* The port is in the ready state and we have a timer
1086 * reporting a timeout this should not happen.
1088 dev_err(sciport_to_dev(sci_port),
1089 "%s: SCIC Port 0x%p is processing a timeout operation "
1090 "in state %d.\n", __func__, sci_port, current_state);
1094 /* --------------------------------------------------------------------------- */
1097 * This function updates the hardwares VIIT entry for this port.
1101 static void scic_sds_port_update_viit_entry(struct scic_sds_port *sci_port)
1103 struct sci_sas_address sas_address;
1105 scic_sds_port_get_sas_address(sci_port, &sas_address);
1107 writel(sas_address.high,
1108 &sci_port->viit_registers->initiator_sas_address_hi);
1109 writel(sas_address.low,
1110 &sci_port->viit_registers->initiator_sas_address_lo);
1112 /* This value get cleared just in case its not already cleared */
1113 writel(0, &sci_port->viit_registers->reserved);
1115 /* We are required to update the status register last */
1116 writel(SCU_VIIT_ENTRY_ID_VIIT |
1117 SCU_VIIT_IPPT_INITIATOR |
1118 ((1 << sci_port->physical_port_index) << SCU_VIIT_ENTRY_LPVIE_SHIFT) |
1119 SCU_VIIT_STATUS_ALL_VALID,
1120 &sci_port->viit_registers->status);
1124 * This method returns the maximum allowed speed for data transfers on this
1125 * port. This maximum allowed speed evaluates to the maximum speed of the
1126 * slowest phy in the port.
1127 * @sci_port: This parameter specifies the port for which to retrieve the
1128 * maximum allowed speed.
1130 * This method returns the maximum negotiated speed of the slowest phy in the
1133 enum sas_linkrate scic_sds_port_get_max_allowed_speed(
1134 struct scic_sds_port *sci_port)
1137 enum sas_linkrate max_allowed_speed = SAS_LINK_RATE_6_0_GBPS;
1138 struct scic_sds_phy *phy = NULL;
1141 * Loop through all of the phys in this port and find the phy with the
1142 * lowest maximum link rate. */
1143 for (index = 0; index < SCI_MAX_PHYS; index++) {
1144 phy = sci_port->phy_table[index];
1147 && (scic_sds_port_active_phy(sci_port, phy) == true)
1148 && (phy->max_negotiated_speed < max_allowed_speed)
1150 max_allowed_speed = phy->max_negotiated_speed;
1153 return max_allowed_speed;
1156 static void scic_port_enable_broadcast_change_notification(struct scic_sds_port *port)
1158 struct scic_sds_phy *phy;
1162 /* Loop through all of the phys to enable BCN. */
1163 for (index = 0; index < SCI_MAX_PHYS; index++) {
1164 phy = port->phy_table[index];
1167 readl(&phy->link_layer_registers->link_layer_control);
1169 /* clear the bit by writing 1. */
1170 writel(register_value,
1171 &phy->link_layer_registers->link_layer_control);
1177 * ****************************************************************************
1178 * * READY SUBSTATE HANDLERS
1179 * **************************************************************************** */
1182 * This method is the general ready state stop handler for the struct scic_sds_port
1183 * object. This function will transition the ready substate machine to its
1184 * final state. enum sci_status SCI_SUCCESS
1186 static enum sci_status scic_sds_port_ready_substate_stop_handler(struct scic_sds_port *sci_port)
1188 port_state_machine_change(sci_port, SCI_BASE_PORT_STATE_STOPPING);
1193 * This method is the general ready substate complete io handler for the
1194 * struct scic_sds_port object. This function decrments the outstanding request count
1195 * for this port object. enum sci_status SCI_SUCCESS
1197 static enum sci_status scic_sds_port_ready_substate_complete_io_handler(
1198 struct scic_sds_port *port,
1199 struct scic_sds_remote_device *device,
1200 struct scic_sds_request *io_request)
1202 scic_sds_port_decrement_request_count(port);
1207 static enum sci_status scic_sds_port_ready_substate_add_phy_handler(struct scic_sds_port *sci_port,
1208 struct scic_sds_phy *sci_phy)
1210 enum sci_status status;
1212 status = scic_sds_port_set_phy(sci_port, sci_phy);
1214 if (status != SCI_SUCCESS)
1217 scic_sds_port_general_link_up_handler(sci_port, sci_phy, true);
1218 sci_port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
1219 port_state_machine_change(sci_port, SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
1225 static enum sci_status scic_sds_port_ready_substate_remove_phy_handler(struct scic_sds_port *port,
1226 struct scic_sds_phy *phy)
1228 enum sci_status status;
1230 status = scic_sds_port_clear_phy(port, phy);
1232 if (status != SCI_SUCCESS)
1235 scic_sds_port_deactivate_phy(port, phy, true);
1237 port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
1239 port_state_machine_change(port,
1240 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
1245 * ****************************************************************************
1246 * * READY SUBSTATE WAITING HANDLERS
1247 * **************************************************************************** */
1251 * @sci_port: This is the struct scic_sds_port object that which has a phy that has
1253 * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
1255 * This method is the ready waiting substate link up handler for the
1256 * struct scic_sds_port object. This methos will report the link up condition for
1257 * this port and will transition to the ready operational substate. none
1259 static void scic_sds_port_ready_waiting_substate_link_up_handler(
1260 struct scic_sds_port *sci_port,
1261 struct scic_sds_phy *sci_phy)
1264 * Since this is the first phy going link up for the port we can just enable
1265 * it and continue. */
1266 scic_sds_port_activate_phy(sci_port, sci_phy, true);
1268 port_state_machine_change(sci_port,
1269 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
1273 * This method is the ready waiting substate start io handler for the
1274 * struct scic_sds_port object. The port object can not accept new requests so the
1275 * request is failed. enum sci_status SCI_FAILURE_INVALID_STATE
1277 static enum sci_status scic_sds_port_ready_waiting_substate_start_io_handler(
1278 struct scic_sds_port *port,
1279 struct scic_sds_remote_device *device,
1280 struct scic_sds_request *io_request)
1282 return SCI_FAILURE_INVALID_STATE;
1286 * ****************************************************************************
1287 * * READY SUBSTATE OPERATIONAL HANDLERS
1288 * **************************************************************************** */
1291 * This method will casue the port to reset. enum sci_status SCI_SUCCESS
1294 sci_status scic_sds_port_ready_operational_substate_reset_handler(
1295 struct scic_sds_port *port,
1298 enum sci_status status = SCI_FAILURE_INVALID_PHY;
1300 struct scic_sds_phy *selected_phy = NULL;
1303 /* Select a phy on which we can send the hard reset request. */
1305 (phy_index < SCI_MAX_PHYS) && (selected_phy == NULL);
1307 selected_phy = port->phy_table[phy_index];
1309 if ((selected_phy != NULL) &&
1310 !scic_sds_port_active_phy(port, selected_phy)) {
1312 * We found a phy but it is not ready select
1315 selected_phy = NULL;
1319 /* If we have a phy then go ahead and start the reset procedure */
1320 if (selected_phy != NULL) {
1321 status = scic_sds_phy_reset(selected_phy);
1323 if (status == SCI_SUCCESS) {
1324 isci_timer_start(port->timer_handle, timeout);
1325 port->not_ready_reason =
1326 SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED;
1328 port_state_machine_change(port,
1329 SCI_BASE_PORT_STATE_RESETTING);
1337 * scic_sds_port_ready_operational_substate_link_up_handler() -
1338 * @sci_port: This is the struct scic_sds_port object that which has a phy that has
1340 * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
1342 * This method is the ready operational substate link up handler for the
1343 * struct scic_sds_port object. This function notifies the SCI User that the phy has
1344 * gone link up. none
1346 static void scic_sds_port_ready_operational_substate_link_up_handler(
1347 struct scic_sds_port *sci_port,
1348 struct scic_sds_phy *sci_phy)
1350 scic_sds_port_general_link_up_handler(sci_port, sci_phy, true);
1354 * scic_sds_port_ready_operational_substate_link_down_handler() -
1355 * @sci_port: This is the struct scic_sds_port object that which has a phy that has
1357 * @sci_phy: This is the struct scic_sds_phy object that has gone link down.
1359 * This method is the ready operational substate link down handler for the
1360 * struct scic_sds_port object. This function notifies the SCI User that the phy has
1361 * gone link down and if this is the last phy in the port the port will change
1362 * state to the ready waiting substate. none
1364 static void scic_sds_port_ready_operational_substate_link_down_handler(
1365 struct scic_sds_port *sci_port,
1366 struct scic_sds_phy *sci_phy)
1368 scic_sds_port_deactivate_phy(sci_port, sci_phy, true);
1371 * If there are no active phys left in the port, then transition
1372 * the port to the WAITING state until such time as a phy goes
1374 if (sci_port->active_phy_mask == 0)
1375 port_state_machine_change(sci_port,
1376 SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
1380 * This method is the ready operational substate start io handler for the
1381 * struct scic_sds_port object. This function incremetns the outstanding request
1382 * count for this port object. enum sci_status SCI_SUCCESS
1384 static enum sci_status scic_sds_port_ready_operational_substate_start_io_handler(
1385 struct scic_sds_port *port,
1386 struct scic_sds_remote_device *device,
1387 struct scic_sds_request *io_request)
1389 port->started_request_count++;
1394 * ****************************************************************************
1395 * * READY SUBSTATE OPERATIONAL HANDLERS
1396 * **************************************************************************** */
1399 * This is the default method for a port add phy request. It will report a
1400 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1402 static enum sci_status scic_sds_port_ready_configuring_substate_add_phy_handler(
1403 struct scic_sds_port *port,
1404 struct scic_sds_phy *phy)
1406 enum sci_status status;
1408 status = scic_sds_port_set_phy(port, phy);
1410 if (status == SCI_SUCCESS) {
1411 scic_sds_port_general_link_up_handler(port, phy, true);
1414 * Re-enter the configuring state since this may be the last phy in
1416 port_state_machine_change(port,
1417 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
1424 * This is the default method for a port remove phy request. It will report a
1425 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1427 static enum sci_status scic_sds_port_ready_configuring_substate_remove_phy_handler(
1428 struct scic_sds_port *port,
1429 struct scic_sds_phy *phy)
1431 enum sci_status status;
1433 status = scic_sds_port_clear_phy(port, phy);
1435 if (status != SCI_SUCCESS)
1437 scic_sds_port_deactivate_phy(port, phy, true);
1439 /* Re-enter the configuring state since this may be the last phy in
1442 port_state_machine_change(port,
1443 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
1449 * scic_sds_port_ready_configuring_substate_complete_io_handler() -
1450 * @port: This is the port that is being requested to complete the io request.
1451 * @device: This is the device on which the io is completing.
1453 * This method will decrement the outstanding request count for this port. If
1454 * the request count goes to 0 then the port can be reprogrammed with its new
1457 static enum sci_status
1458 scic_sds_port_ready_configuring_substate_complete_io_handler(
1459 struct scic_sds_port *port,
1460 struct scic_sds_remote_device *device,
1461 struct scic_sds_request *io_request)
1463 scic_sds_port_decrement_request_count(port);
1465 if (port->started_request_count == 0) {
1466 port_state_machine_change(port,
1467 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
1473 static enum sci_status default_port_handler(struct scic_sds_port *sci_port,
1476 dev_warn(sciport_to_dev(sci_port),
1477 "%s: in wrong state: %d\n", func,
1478 sci_base_state_machine_get_state(&sci_port->state_machine));
1479 return SCI_FAILURE_INVALID_STATE;
1482 static enum sci_status
1483 scic_sds_port_default_start_handler(struct scic_sds_port *sci_port)
1485 return default_port_handler(sci_port, __func__);
1488 static enum sci_status
1489 scic_sds_port_default_stop_handler(struct scic_sds_port *sci_port)
1491 return default_port_handler(sci_port, __func__);
1494 static enum sci_status
1495 scic_sds_port_default_destruct_handler(struct scic_sds_port *sci_port)
1497 return default_port_handler(sci_port, __func__);
1500 static enum sci_status
1501 scic_sds_port_default_reset_handler(struct scic_sds_port *sci_port,
1504 return default_port_handler(sci_port, __func__);
1507 static enum sci_status
1508 scic_sds_port_default_add_phy_handler(struct scic_sds_port *sci_port,
1509 struct scic_sds_phy *base_phy)
1511 return default_port_handler(sci_port, __func__);
1514 static enum sci_status
1515 scic_sds_port_default_remove_phy_handler(struct scic_sds_port *sci_port,
1516 struct scic_sds_phy *base_phy)
1518 return default_port_handler(sci_port, __func__);
1522 * This is the default method for a port unsolicited frame request. It will
1523 * report a warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE Is it even
1524 * possible to receive an unsolicited frame directed to a port object? It
1525 * seems possible if we implementing virtual functions but until then?
1527 static enum sci_status
1528 scic_sds_port_default_frame_handler(struct scic_sds_port *sci_port,
1531 struct scic_sds_controller *scic = scic_sds_port_get_controller(sci_port);
1533 default_port_handler(sci_port, __func__);
1534 scic_sds_controller_release_frame(scic, frame_index);
1536 return SCI_FAILURE_INVALID_STATE;
1539 static enum sci_status scic_sds_port_default_event_handler(struct scic_sds_port *sci_port,
1542 return default_port_handler(sci_port, __func__);
1545 static void scic_sds_port_default_link_up_handler(struct scic_sds_port *sci_port,
1546 struct scic_sds_phy *sci_phy)
1548 default_port_handler(sci_port, __func__);
1551 static void scic_sds_port_default_link_down_handler(struct scic_sds_port *sci_port,
1552 struct scic_sds_phy *sci_phy)
1554 default_port_handler(sci_port, __func__);
1557 static enum sci_status scic_sds_port_default_start_io_handler(struct scic_sds_port *sci_port,
1558 struct scic_sds_remote_device *sci_dev,
1559 struct scic_sds_request *sci_req)
1561 return default_port_handler(sci_port, __func__);
1564 static enum sci_status scic_sds_port_default_complete_io_handler(struct scic_sds_port *sci_port,
1565 struct scic_sds_remote_device *sci_dev,
1566 struct scic_sds_request *sci_req)
1568 return default_port_handler(sci_port, __func__);
1572 * ******************************************************************************
1573 * * PORT STATE PRIVATE METHODS
1574 * ****************************************************************************** */
1578 * @sci_port: This is the struct scic_sds_port object to suspend.
1580 * This method will susped the port task scheduler for this port object. none
1583 scic_sds_port_suspend_port_task_scheduler(struct scic_sds_port *port)
1585 u32 pts_control_value;
1587 pts_control_value = readl(&port->port_task_scheduler_registers->control);
1588 pts_control_value |= SCU_PTSxCR_GEN_BIT(SUSPEND);
1589 writel(pts_control_value, &port->port_task_scheduler_registers->control);
1593 * scic_sds_port_post_dummy_request() - post dummy/workaround request
1594 * @sci_port: port to post task
1596 * Prevent the hardware scheduler from posting new requests to the front
1597 * of the scheduler queue causing a starvation problem for currently
1601 static void scic_sds_port_post_dummy_request(struct scic_sds_port *sci_port)
1604 struct scu_task_context *task_context;
1605 struct scic_sds_controller *scic = sci_port->owning_controller;
1606 u16 tci = sci_port->reserved_tci;
1608 task_context = scic_sds_controller_get_task_context_buffer(scic, tci);
1610 task_context->abort = 0;
1612 command = SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
1613 sci_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
1616 scic_sds_controller_post_request(scic, command);
1620 * This routine will abort the dummy request. This will alow the hardware to
1621 * power down parts of the silicon to save power.
1623 * @sci_port: The port on which the task must be aborted.
1626 static void scic_sds_port_abort_dummy_request(struct scic_sds_port *sci_port)
1628 struct scic_sds_controller *scic = sci_port->owning_controller;
1629 u16 tci = sci_port->reserved_tci;
1630 struct scu_task_context *tc;
1633 tc = scic_sds_controller_get_task_context_buffer(scic, tci);
1637 command = SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT |
1638 sci_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
1641 scic_sds_controller_post_request(scic, command);
1646 * @sci_port: This is the struct scic_sds_port object to resume.
1648 * This method will resume the port task scheduler for this port object. none
1651 scic_sds_port_resume_port_task_scheduler(struct scic_sds_port *port)
1653 u32 pts_control_value;
1655 pts_control_value = readl(&port->port_task_scheduler_registers->control);
1656 pts_control_value &= ~SCU_PTSxCR_GEN_BIT(SUSPEND);
1657 writel(pts_control_value, &port->port_task_scheduler_registers->control);
1661 * ******************************************************************************
1662 * * PORT READY SUBSTATE METHODS
1663 * ****************************************************************************** */
1667 * @object: This is the object which is cast to a struct scic_sds_port object.
1669 * This method will perform the actions required by the struct scic_sds_port on
1670 * entering the SCIC_SDS_PORT_READY_SUBSTATE_WAITING. This function checks the
1671 * port for any ready phys. If there is at least one phy in a ready state then
1672 * the port transitions to the ready operational substate. none
1674 static void scic_sds_port_ready_substate_waiting_enter(void *object)
1676 struct scic_sds_port *sci_port = object;
1678 scic_sds_port_set_base_state_handlers(
1679 sci_port, SCIC_SDS_PORT_READY_SUBSTATE_WAITING
1682 scic_sds_port_suspend_port_task_scheduler(sci_port);
1684 sci_port->not_ready_reason = SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS;
1686 if (sci_port->active_phy_mask != 0) {
1687 /* At least one of the phys on the port is ready */
1688 port_state_machine_change(sci_port,
1689 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
1695 * @object: This is the object which is cast to a struct scic_sds_port object.
1697 * This function will perform the actions required by the struct scic_sds_port
1698 * on entering the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function sets
1699 * the state handlers for the port object, notifies the SCI User that the port
1700 * is ready, and resumes port operations. none
1702 static void scic_sds_port_ready_substate_operational_enter(void *object)
1705 struct scic_sds_port *sci_port = object;
1706 struct scic_sds_controller *scic = sci_port->owning_controller;
1707 struct isci_host *ihost = scic_to_ihost(scic);
1708 struct isci_port *iport = sci_port_to_iport(sci_port);
1710 scic_sds_port_set_base_state_handlers(
1712 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
1714 isci_port_ready(ihost, iport);
1716 for (index = 0; index < SCI_MAX_PHYS; index++) {
1717 if (sci_port->phy_table[index]) {
1718 writel(sci_port->physical_port_index,
1719 &sci_port->port_pe_configuration_register[
1720 sci_port->phy_table[index]->phy_index]);
1724 scic_sds_port_update_viit_entry(sci_port);
1726 scic_sds_port_resume_port_task_scheduler(sci_port);
1729 * Post the dummy task for the port so the hardware can schedule
1732 scic_sds_port_post_dummy_request(sci_port);
1735 static void scic_sds_port_invalidate_dummy_remote_node(struct scic_sds_port *sci_port)
1737 struct scic_sds_controller *scic = sci_port->owning_controller;
1738 u8 phys_index = sci_port->physical_port_index;
1739 union scu_remote_node_context *rnc;
1740 u16 rni = sci_port->reserved_rni;
1743 rnc = &scic->remote_node_context_table[rni];
1745 rnc->ssp.is_valid = false;
1747 /* ensure the preceding tc abort request has reached the
1748 * controller and give it ample time to act before posting the rnc
1751 readl(&scic->smu_registers->interrupt_status); /* flush */
1754 command = SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE |
1755 phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
1757 scic_sds_controller_post_request(scic, command);
1762 * @object: This is the object which is cast to a struct scic_sds_port object.
1764 * This method will perform the actions required by the struct scic_sds_port on
1765 * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
1766 * the port not ready and suspends the port task scheduler. none
1768 static void scic_sds_port_ready_substate_operational_exit(void *object)
1770 struct scic_sds_port *sci_port = object;
1771 struct scic_sds_controller *scic = sci_port->owning_controller;
1772 struct isci_host *ihost = scic_to_ihost(scic);
1773 struct isci_port *iport = sci_port_to_iport(sci_port);
1776 * Kill the dummy task for this port if it has not yet posted
1777 * the hardware will treat this as a NOP and just return abort
1780 scic_sds_port_abort_dummy_request(sci_port);
1782 isci_port_not_ready(ihost, iport);
1784 if (sci_port->ready_exit)
1785 scic_sds_port_invalidate_dummy_remote_node(sci_port);
1789 * ******************************************************************************
1790 * * PORT READY CONFIGURING METHODS
1791 * ****************************************************************************** */
1794 * scic_sds_port_ready_substate_configuring_enter() -
1795 * @object: This is the object which is cast to a struct scic_sds_port object.
1797 * This method will perform the actions required by the struct scic_sds_port on
1798 * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
1799 * the port not ready and suspends the port task scheduler. none
1801 static void scic_sds_port_ready_substate_configuring_enter(void *object)
1803 struct scic_sds_port *sci_port = object;
1804 struct scic_sds_controller *scic = sci_port->owning_controller;
1805 struct isci_host *ihost = scic_to_ihost(scic);
1806 struct isci_port *iport = sci_port_to_iport(sci_port);
1808 scic_sds_port_set_base_state_handlers(
1810 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
1812 if (sci_port->active_phy_mask == 0) {
1813 isci_port_not_ready(ihost, iport);
1815 port_state_machine_change(sci_port,
1816 SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
1817 } else if (sci_port->started_request_count == 0)
1818 port_state_machine_change(sci_port,
1819 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
1822 static void scic_sds_port_ready_substate_configuring_exit(void *object)
1824 struct scic_sds_port *sci_port = object;
1826 scic_sds_port_suspend_port_task_scheduler(sci_port);
1827 if (sci_port->ready_exit)
1828 scic_sds_port_invalidate_dummy_remote_node(sci_port);
1831 /* --------------------------------------------------------------------------- */
1835 * @port: This is the struct scic_sds_port object on which the io request count will
1837 * @device: This is the struct scic_sds_remote_device object to which the io request
1838 * is being directed. This parameter is not required to complete this
1840 * @io_request: This is the request that is being completed on this port
1841 * object. This parameter is not required to complete this operation.
1843 * This is a general complete io request handler for the struct scic_sds_port object.
1844 * enum sci_status SCI_SUCCESS
1846 static enum sci_status scic_sds_port_general_complete_io_handler(
1847 struct scic_sds_port *port,
1848 struct scic_sds_remote_device *device,
1849 struct scic_sds_request *io_request)
1851 scic_sds_port_decrement_request_count(port);
1857 * scic_sds_port_stopped_state_start_handler() - stop a port from "started"
1859 * @port: This is the struct scic_sds_port object which is cast into a
1860 * struct scic_sds_port object.
1862 * This function takes the struct scic_sds_port from a stopped state and
1863 * attempts to start it. To start a port it must have no assiged devices and
1864 * it must have at least one phy assigned to it. If those conditions are
1865 * met then the port can transition to the ready state.
1867 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
1868 * This struct scic_sds_port object could not be started because the port
1869 * configuration is not valid.
1871 * the start request is successful and the struct scic_sds_port object
1872 * has transitioned to the SCI_BASE_PORT_STATE_READY.
1874 static enum sci_status
1875 scic_sds_port_stopped_state_start_handler(struct scic_sds_port *sci_port)
1877 struct scic_sds_controller *scic = sci_port->owning_controller;
1878 struct isci_host *ihost = scic_to_ihost(scic);
1879 enum sci_status status = SCI_SUCCESS;
1882 if (sci_port->assigned_device_count > 0) {
1884 * @todo This is a start failure operation because
1885 * there are still devices assigned to this port.
1886 * There must be no devices assigned to a port on a
1889 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
1892 sci_port->timer_handle =
1893 isci_timer_create(ihost,
1895 scic_sds_port_timeout_handler);
1897 if (!sci_port->timer_handle)
1898 return SCI_FAILURE_INSUFFICIENT_RESOURCES;
1900 if (sci_port->reserved_rni == SCU_DUMMY_INDEX) {
1901 u16 rni = scic_sds_remote_node_table_allocate_remote_node(
1902 &scic->available_remote_nodes, 1);
1904 if (rni != SCU_DUMMY_INDEX)
1905 scic_sds_port_construct_dummy_rnc(sci_port, rni);
1907 status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
1908 sci_port->reserved_rni = rni;
1911 if (sci_port->reserved_tci == SCU_DUMMY_INDEX) {
1912 /* Allocate a TCI and remove the sequence nibble */
1913 u16 tci = scic_controller_allocate_io_tag(scic);
1915 if (tci != SCU_DUMMY_INDEX)
1916 scic_sds_port_construct_dummy_task(sci_port, tci);
1918 status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
1919 sci_port->reserved_tci = tci;
1922 if (status == SCI_SUCCESS) {
1923 phy_mask = scic_sds_port_get_phys(sci_port);
1926 * There are one or more phys assigned to this port. Make sure
1927 * the port's phy mask is in fact legal and supported by the
1930 if (scic_sds_port_is_phy_mask_valid(sci_port, phy_mask) == true) {
1931 port_state_machine_change(sci_port,
1932 SCI_BASE_PORT_STATE_READY);
1936 status = SCI_FAILURE;
1939 if (status != SCI_SUCCESS)
1940 scic_sds_port_destroy_dummy_resources(sci_port);
1946 * This method takes the struct scic_sds_port that is in a stopped state and handles a
1947 * stop request. This function takes no action. enum sci_status SCI_SUCCESS the
1948 * stop request is successful as the struct scic_sds_port object is already stopped.
1950 static enum sci_status scic_sds_port_stopped_state_stop_handler(
1951 struct scic_sds_port *port)
1953 /* We are already stopped so there is nothing to do here */
1958 * This method takes the struct scic_sds_port that is in a stopped state and handles
1959 * the destruct request. The stopped state is the only state in which the
1960 * struct scic_sds_port can be destroyed. This function causes the port object to
1961 * transition to the SCI_BASE_PORT_STATE_FINAL. enum sci_status SCI_SUCCESS
1963 static enum sci_status scic_sds_port_stopped_state_destruct_handler(struct scic_sds_port *port)
1965 port_state_machine_stop(port);
1971 * This method takes the struct scic_sds_port that is in a stopped state and handles
1972 * the add phy request. In MPC mode the only time a phy can be added to a port
1973 * is in the SCI_BASE_PORT_STATE_STOPPED. enum sci_status
1974 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION is returned when the phy can not
1975 * be added to the port. SCI_SUCCESS if the phy is added to the port.
1977 static enum sci_status scic_sds_port_stopped_state_add_phy_handler(
1978 struct scic_sds_port *port,
1979 struct scic_sds_phy *phy)
1981 struct sci_sas_address port_sas_address;
1983 /* Read the port assigned SAS Address if there is one */
1984 scic_sds_port_get_sas_address(port, &port_sas_address);
1986 if (port_sas_address.high != 0 && port_sas_address.low != 0) {
1987 struct sci_sas_address phy_sas_address;
1990 * Make sure that the PHY SAS Address matches the SAS Address
1992 scic_sds_phy_get_sas_address(phy, &phy_sas_address);
1995 (port_sas_address.high != phy_sas_address.high)
1996 || (port_sas_address.low != phy_sas_address.low)
1998 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
2002 return scic_sds_port_set_phy(port, phy);
2006 * This method takes the struct scic_sds_port that is in a stopped state and handles
2007 * the remove phy request. In MPC mode the only time a phy can be removed from
2008 * a port is in the SCI_BASE_PORT_STATE_STOPPED. enum sci_status
2009 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION is returned when the phy can not
2010 * be added to the port. SCI_SUCCESS if the phy is added to the port.
2012 static enum sci_status scic_sds_port_stopped_state_remove_phy_handler(
2013 struct scic_sds_port *port,
2014 struct scic_sds_phy *phy)
2016 return scic_sds_port_clear_phy(port, phy);
2020 * ****************************************************************************
2021 * * READY STATE HANDLERS
2022 * **************************************************************************** */
2025 * ****************************************************************************
2026 * * RESETTING STATE HANDLERS
2027 * **************************************************************************** */
2030 * ****************************************************************************
2031 * * STOPPING STATE HANDLERS
2032 * **************************************************************************** */
2035 * This method takes the struct scic_sds_port that is in a stopping state and handles
2036 * the complete io request. Should the request count reach 0 then the port
2037 * object will transition to the stopped state. enum sci_status SCI_SUCCESS
2039 static enum sci_status scic_sds_port_stopping_state_complete_io_handler(
2040 struct scic_sds_port *sci_port,
2041 struct scic_sds_remote_device *device,
2042 struct scic_sds_request *io_request)
2044 scic_sds_port_decrement_request_count(sci_port);
2046 if (sci_port->started_request_count == 0)
2047 port_state_machine_change(sci_port,
2048 SCI_BASE_PORT_STATE_STOPPED);
2054 * ****************************************************************************
2055 * * RESETTING STATE HANDLERS
2056 * **************************************************************************** */
2060 * @port: This is the port object which is being requested to stop.
2062 * This method will stop a failed port. This causes a transition to the
2063 * stopping state. enum sci_status SCI_SUCCESS
2065 static enum sci_status scic_sds_port_reset_state_stop_handler(
2066 struct scic_sds_port *port)
2068 port_state_machine_change(port,
2069 SCI_BASE_PORT_STATE_STOPPING);
2075 * This method will transition a failed port to its ready state. The port
2076 * failed because a hard reset request timed out but at some time later one or
2077 * more phys in the port became ready. enum sci_status SCI_SUCCESS
2079 static void scic_sds_port_reset_state_link_up_handler(
2080 struct scic_sds_port *port,
2081 struct scic_sds_phy *phy)
2084 * / @todo We should make sure that the phy that has gone link up is the same
2085 * / one on which we sent the reset. It is possible that the phy on
2086 * / which we sent the reset is not the one that has gone link up and we
2087 * / want to make sure that phy being reset comes back. Consider the
2088 * / case where a reset is sent but before the hardware processes the
2089 * / reset it get a link up on the port because of a hot plug event.
2090 * / because of the reset request this phy will go link down almost
2094 * In the resetting state we don't notify the user regarding
2095 * link up and link down notifications. */
2096 scic_sds_port_general_link_up_handler(port, phy, false);
2100 * This method process link down notifications that occur during a port reset
2101 * operation. Link downs can occur during the reset operation. enum sci_status
2104 static void scic_sds_port_reset_state_link_down_handler(
2105 struct scic_sds_port *port,
2106 struct scic_sds_phy *phy)
2109 * In the resetting state we don't notify the user regarding
2110 * link up and link down notifications. */
2111 scic_sds_port_deactivate_phy(port, phy, false);
2114 static struct scic_sds_port_state_handler scic_sds_port_state_handler_table[] = {
2115 [SCI_BASE_PORT_STATE_STOPPED] = {
2116 .start_handler = scic_sds_port_stopped_state_start_handler,
2117 .stop_handler = scic_sds_port_stopped_state_stop_handler,
2118 .destruct_handler = scic_sds_port_stopped_state_destruct_handler,
2119 .reset_handler = scic_sds_port_default_reset_handler,
2120 .add_phy_handler = scic_sds_port_stopped_state_add_phy_handler,
2121 .remove_phy_handler = scic_sds_port_stopped_state_remove_phy_handler,
2122 .frame_handler = scic_sds_port_default_frame_handler,
2123 .event_handler = scic_sds_port_default_event_handler,
2124 .link_up_handler = scic_sds_port_default_link_up_handler,
2125 .link_down_handler = scic_sds_port_default_link_down_handler,
2126 .start_io_handler = scic_sds_port_default_start_io_handler,
2127 .complete_io_handler = scic_sds_port_default_complete_io_handler
2129 [SCI_BASE_PORT_STATE_STOPPING] = {
2130 .start_handler = scic_sds_port_default_start_handler,
2131 .stop_handler = scic_sds_port_default_stop_handler,
2132 .destruct_handler = scic_sds_port_default_destruct_handler,
2133 .reset_handler = scic_sds_port_default_reset_handler,
2134 .add_phy_handler = scic_sds_port_default_add_phy_handler,
2135 .remove_phy_handler = scic_sds_port_default_remove_phy_handler,
2136 .frame_handler = scic_sds_port_default_frame_handler,
2137 .event_handler = scic_sds_port_default_event_handler,
2138 .link_up_handler = scic_sds_port_default_link_up_handler,
2139 .link_down_handler = scic_sds_port_default_link_down_handler,
2140 .start_io_handler = scic_sds_port_default_start_io_handler,
2141 .complete_io_handler = scic_sds_port_stopping_state_complete_io_handler
2143 [SCI_BASE_PORT_STATE_READY] = {
2144 .start_handler = scic_sds_port_default_start_handler,
2145 .stop_handler = scic_sds_port_default_stop_handler,
2146 .destruct_handler = scic_sds_port_default_destruct_handler,
2147 .reset_handler = scic_sds_port_default_reset_handler,
2148 .add_phy_handler = scic_sds_port_default_add_phy_handler,
2149 .remove_phy_handler = scic_sds_port_default_remove_phy_handler,
2150 .frame_handler = scic_sds_port_default_frame_handler,
2151 .event_handler = scic_sds_port_default_event_handler,
2152 .link_up_handler = scic_sds_port_default_link_up_handler,
2153 .link_down_handler = scic_sds_port_default_link_down_handler,
2154 .start_io_handler = scic_sds_port_default_start_io_handler,
2155 .complete_io_handler = scic_sds_port_general_complete_io_handler
2157 [SCIC_SDS_PORT_READY_SUBSTATE_WAITING] = {
2158 .start_handler = scic_sds_port_default_start_handler,
2159 .stop_handler = scic_sds_port_ready_substate_stop_handler,
2160 .destruct_handler = scic_sds_port_default_destruct_handler,
2161 .reset_handler = scic_sds_port_default_reset_handler,
2162 .add_phy_handler = scic_sds_port_ready_substate_add_phy_handler,
2163 .remove_phy_handler = scic_sds_port_default_remove_phy_handler,
2164 .frame_handler = scic_sds_port_default_frame_handler,
2165 .event_handler = scic_sds_port_default_event_handler,
2166 .link_up_handler = scic_sds_port_ready_waiting_substate_link_up_handler,
2167 .link_down_handler = scic_sds_port_default_link_down_handler,
2168 .start_io_handler = scic_sds_port_ready_waiting_substate_start_io_handler,
2169 .complete_io_handler = scic_sds_port_ready_substate_complete_io_handler,
2171 [SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL] = {
2172 .start_handler = scic_sds_port_default_start_handler,
2173 .stop_handler = scic_sds_port_ready_substate_stop_handler,
2174 .destruct_handler = scic_sds_port_default_destruct_handler,
2175 .reset_handler = scic_sds_port_ready_operational_substate_reset_handler,
2176 .add_phy_handler = scic_sds_port_ready_substate_add_phy_handler,
2177 .remove_phy_handler = scic_sds_port_ready_substate_remove_phy_handler,
2178 .frame_handler = scic_sds_port_default_frame_handler,
2179 .event_handler = scic_sds_port_default_event_handler,
2180 .link_up_handler = scic_sds_port_ready_operational_substate_link_up_handler,
2181 .link_down_handler = scic_sds_port_ready_operational_substate_link_down_handler,
2182 .start_io_handler = scic_sds_port_ready_operational_substate_start_io_handler,
2183 .complete_io_handler = scic_sds_port_ready_substate_complete_io_handler,
2185 [SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING] = {
2186 .start_handler = scic_sds_port_default_start_handler,
2187 .stop_handler = scic_sds_port_ready_substate_stop_handler,
2188 .destruct_handler = scic_sds_port_default_destruct_handler,
2189 .reset_handler = scic_sds_port_default_reset_handler,
2190 .add_phy_handler = scic_sds_port_ready_configuring_substate_add_phy_handler,
2191 .remove_phy_handler = scic_sds_port_ready_configuring_substate_remove_phy_handler,
2192 .frame_handler = scic_sds_port_default_frame_handler,
2193 .event_handler = scic_sds_port_default_event_handler,
2194 .link_up_handler = scic_sds_port_default_link_up_handler,
2195 .link_down_handler = scic_sds_port_default_link_down_handler,
2196 .start_io_handler = scic_sds_port_default_start_io_handler,
2197 .complete_io_handler = scic_sds_port_ready_configuring_substate_complete_io_handler
2199 [SCI_BASE_PORT_STATE_RESETTING] = {
2200 .start_handler = scic_sds_port_default_start_handler,
2201 .stop_handler = scic_sds_port_reset_state_stop_handler,
2202 .destruct_handler = scic_sds_port_default_destruct_handler,
2203 .reset_handler = scic_sds_port_default_reset_handler,
2204 .add_phy_handler = scic_sds_port_default_add_phy_handler,
2205 .remove_phy_handler = scic_sds_port_default_remove_phy_handler,
2206 .frame_handler = scic_sds_port_default_frame_handler,
2207 .event_handler = scic_sds_port_default_event_handler,
2208 .link_up_handler = scic_sds_port_reset_state_link_up_handler,
2209 .link_down_handler = scic_sds_port_reset_state_link_down_handler,
2210 .start_io_handler = scic_sds_port_default_start_io_handler,
2211 .complete_io_handler = scic_sds_port_general_complete_io_handler
2213 [SCI_BASE_PORT_STATE_FAILED] = {
2214 .start_handler = scic_sds_port_default_start_handler,
2215 .stop_handler = scic_sds_port_default_stop_handler,
2216 .destruct_handler = scic_sds_port_default_destruct_handler,
2217 .reset_handler = scic_sds_port_default_reset_handler,
2218 .add_phy_handler = scic_sds_port_default_add_phy_handler,
2219 .remove_phy_handler = scic_sds_port_default_remove_phy_handler,
2220 .frame_handler = scic_sds_port_default_frame_handler,
2221 .event_handler = scic_sds_port_default_event_handler,
2222 .link_up_handler = scic_sds_port_default_link_up_handler,
2223 .link_down_handler = scic_sds_port_default_link_down_handler,
2224 .start_io_handler = scic_sds_port_default_start_io_handler,
2225 .complete_io_handler = scic_sds_port_general_complete_io_handler
2230 * ******************************************************************************
2231 * * PORT STATE PRIVATE METHODS
2232 * ****************************************************************************** */
2236 * @sci_port: This is the port object which to suspend.
2238 * This method will enable the SCU Port Task Scheduler for this port object but
2239 * will leave the port task scheduler in a suspended state. none
2242 scic_sds_port_enable_port_task_scheduler(struct scic_sds_port *port)
2244 u32 pts_control_value;
2246 pts_control_value = readl(&port->port_task_scheduler_registers->control);
2247 pts_control_value |= SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND);
2248 writel(pts_control_value, &port->port_task_scheduler_registers->control);
2253 * @sci_port: This is the port object which to resume.
2255 * This method will disable the SCU port task scheduler for this port object.
2259 scic_sds_port_disable_port_task_scheduler(struct scic_sds_port *port)
2261 u32 pts_control_value;
2263 pts_control_value = readl(&port->port_task_scheduler_registers->control);
2264 pts_control_value &=
2265 ~(SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND));
2266 writel(pts_control_value, &port->port_task_scheduler_registers->control);
2269 static void scic_sds_port_post_dummy_remote_node(struct scic_sds_port *sci_port)
2271 struct scic_sds_controller *scic = sci_port->owning_controller;
2272 u8 phys_index = sci_port->physical_port_index;
2273 union scu_remote_node_context *rnc;
2274 u16 rni = sci_port->reserved_rni;
2277 rnc = &scic->remote_node_context_table[rni];
2278 rnc->ssp.is_valid = true;
2280 command = SCU_CONTEXT_COMMAND_POST_RNC_32 |
2281 phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
2283 scic_sds_controller_post_request(scic, command);
2285 /* ensure hardware has seen the post rnc command and give it
2286 * ample time to act before sending the suspend
2288 readl(&scic->smu_registers->interrupt_status); /* flush */
2291 command = SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX |
2292 phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
2294 scic_sds_controller_post_request(scic, command);
2298 * ******************************************************************************
2299 * * PORT STATE METHODS
2300 * ****************************************************************************** */
2304 * @object: This is the object which is cast to a struct scic_sds_port object.
2306 * This method will perform the actions required by the struct scic_sds_port on
2307 * entering the SCI_BASE_PORT_STATE_STOPPED. This function sets the stopped
2308 * state handlers for the struct scic_sds_port object and disables the port task
2309 * scheduler in the hardware. none
2311 static void scic_sds_port_stopped_state_enter(void *object)
2313 struct scic_sds_port *sci_port = object;
2315 scic_sds_port_set_base_state_handlers(
2316 sci_port, SCI_BASE_PORT_STATE_STOPPED
2320 SCI_BASE_PORT_STATE_STOPPING
2321 == sci_port->state_machine.previous_state_id
2324 * If we enter this state becasuse of a request to stop
2325 * the port then we want to disable the hardwares port
2326 * task scheduler. */
2327 scic_sds_port_disable_port_task_scheduler(sci_port);
2333 * @object: This is the object which is cast to a struct scic_sds_port object.
2335 * This method will perform the actions required by the struct scic_sds_port on
2336 * exiting the SCI_BASE_STATE_STOPPED. This function enables the SCU hardware
2337 * port task scheduler. none
2339 static void scic_sds_port_stopped_state_exit(void *object)
2341 struct scic_sds_port *sci_port = object;
2343 /* Enable and suspend the port task scheduler */
2344 scic_sds_port_enable_port_task_scheduler(sci_port);
2348 * scic_sds_port_ready_state_enter -
2349 * @object: This is the object which is cast to a struct scic_sds_port object.
2351 * This method will perform the actions required by the struct scic_sds_port on
2352 * entering the SCI_BASE_PORT_STATE_READY. This function sets the ready state
2353 * handlers for the struct scic_sds_port object, reports the port object as
2354 * not ready and starts the ready substate machine. none
2356 static void scic_sds_port_ready_state_enter(void *object)
2358 struct scic_sds_port *sci_port = object;
2359 struct scic_sds_controller *scic = sci_port->owning_controller;
2360 struct isci_host *ihost = scic_to_ihost(scic);
2361 struct isci_port *iport = sci_port_to_iport(sci_port);
2364 /* Put the ready state handlers in place though they will not be there long */
2365 scic_sds_port_set_base_state_handlers(sci_port, SCI_BASE_PORT_STATE_READY);
2367 prev_state = sci_port->state_machine.previous_state_id;
2368 if (prev_state == SCI_BASE_PORT_STATE_RESETTING)
2369 isci_port_hard_reset_complete(iport, SCI_SUCCESS);
2371 isci_port_not_ready(ihost, iport);
2373 /* Post and suspend the dummy remote node context for this port. */
2374 scic_sds_port_post_dummy_remote_node(sci_port);
2376 /* Start the ready substate machine */
2377 port_state_machine_change(sci_port,
2378 SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
2383 * @object: This is the object which is cast to a struct scic_sds_port object.
2385 * This method will perform the actions required by the struct scic_sds_port on
2386 * entering the SCI_BASE_PORT_STATE_RESETTING. This function sets the resetting
2387 * state handlers for the struct scic_sds_port object. none
2389 static void scic_sds_port_resetting_state_enter(void *object)
2391 struct scic_sds_port *sci_port = object;
2393 scic_sds_port_set_base_state_handlers(
2394 sci_port, SCI_BASE_PORT_STATE_RESETTING
2400 * @object: This is the object which is cast to a struct scic_sds_port object.
2402 * This function will perform the actions required by the
2403 * struct scic_sds_port on
2404 * exiting the SCI_BASE_STATE_RESETTING. This function does nothing. none
2406 static inline void scic_sds_port_resetting_state_exit(void *object)
2408 struct scic_sds_port *sci_port = object;
2410 isci_timer_stop(sci_port->timer_handle);
2415 * @object: This is the void object which is cast to a
2416 * struct scic_sds_port object.
2418 * This method will perform the actions required by the struct scic_sds_port on
2419 * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
2420 * state handlers for the struct scic_sds_port object. none
2422 static void scic_sds_port_stopping_state_enter(void *object)
2424 struct scic_sds_port *sci_port = object;
2426 scic_sds_port_set_base_state_handlers(
2427 sci_port, SCI_BASE_PORT_STATE_STOPPING
2433 * @object: This is the object which is cast to a struct scic_sds_port object.
2435 * This function will perform the actions required by the
2436 * struct scic_sds_port on
2437 * exiting the SCI_BASE_STATE_STOPPING. This function does nothing. none
2440 scic_sds_port_stopping_state_exit(void *object)
2442 struct scic_sds_port *sci_port = object;
2444 isci_timer_stop(sci_port->timer_handle);
2446 scic_sds_port_destroy_dummy_resources(sci_port);
2451 * @object: This is the object which is cast to a struct scic_sds_port object.
2453 * This function will perform the actions required by the
2454 * struct scic_sds_port on
2455 * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
2456 * state handlers for the struct scic_sds_port object. none
2458 static void scic_sds_port_failed_state_enter(void *object)
2460 struct scic_sds_port *sci_port = object;
2461 struct isci_port *iport = sci_port_to_iport(sci_port);
2463 scic_sds_port_set_base_state_handlers(sci_port,
2464 SCI_BASE_PORT_STATE_FAILED);
2466 isci_port_hard_reset_complete(iport, SCI_FAILURE_TIMEOUT);
2469 /* --------------------------------------------------------------------------- */
2471 static const struct sci_base_state scic_sds_port_state_table[] = {
2472 [SCI_BASE_PORT_STATE_STOPPED] = {
2473 .enter_state = scic_sds_port_stopped_state_enter,
2474 .exit_state = scic_sds_port_stopped_state_exit
2476 [SCI_BASE_PORT_STATE_STOPPING] = {
2477 .enter_state = scic_sds_port_stopping_state_enter,
2478 .exit_state = scic_sds_port_stopping_state_exit
2480 [SCI_BASE_PORT_STATE_READY] = {
2481 .enter_state = scic_sds_port_ready_state_enter,
2483 [SCIC_SDS_PORT_READY_SUBSTATE_WAITING] = {
2484 .enter_state = scic_sds_port_ready_substate_waiting_enter,
2486 [SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL] = {
2487 .enter_state = scic_sds_port_ready_substate_operational_enter,
2488 .exit_state = scic_sds_port_ready_substate_operational_exit
2490 [SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING] = {
2491 .enter_state = scic_sds_port_ready_substate_configuring_enter,
2492 .exit_state = scic_sds_port_ready_substate_configuring_exit
2494 [SCI_BASE_PORT_STATE_RESETTING] = {
2495 .enter_state = scic_sds_port_resetting_state_enter,
2496 .exit_state = scic_sds_port_resetting_state_exit
2498 [SCI_BASE_PORT_STATE_FAILED] = {
2499 .enter_state = scic_sds_port_failed_state_enter,
2503 void scic_sds_port_construct(struct scic_sds_port *sci_port, u8 index,
2504 struct scic_sds_controller *scic)
2506 sci_base_state_machine_construct(&sci_port->state_machine,
2508 scic_sds_port_state_table,
2509 SCI_BASE_PORT_STATE_STOPPED);
2511 sci_base_state_machine_start(&sci_port->state_machine);
2513 sci_port->logical_port_index = SCIC_SDS_DUMMY_PORT;
2514 sci_port->physical_port_index = index;
2515 sci_port->active_phy_mask = 0;
2516 sci_port->ready_exit = false;
2518 sci_port->owning_controller = scic;
2520 sci_port->started_request_count = 0;
2521 sci_port->assigned_device_count = 0;
2523 sci_port->reserved_rni = SCU_DUMMY_INDEX;
2524 sci_port->reserved_tci = SCU_DUMMY_INDEX;
2526 sci_port->timer_handle = NULL;
2527 sci_port->port_task_scheduler_registers = NULL;
2529 for (index = 0; index < SCI_MAX_PHYS; index++)
2530 sci_port->phy_table[index] = NULL;
2533 void isci_port_init(struct isci_port *iport, struct isci_host *ihost, int index)
2535 INIT_LIST_HEAD(&iport->remote_dev_list);
2536 INIT_LIST_HEAD(&iport->domain_dev_list);
2537 spin_lock_init(&iport->state_lock);
2538 init_completion(&iport->start_complete);
2539 iport->isci_host = ihost;
2540 isci_port_change_state(iport, isci_freed);
2544 * isci_port_get_state() - This function gets the status of the port object.
2545 * @isci_port: This parameter points to the isci_port object
2547 * status of the object as a isci_status enum.
2549 enum isci_status isci_port_get_state(
2550 struct isci_port *isci_port)
2552 return isci_port->status;
2555 static void isci_port_bc_change_received(struct isci_host *ihost,
2556 struct scic_sds_port *sci_port,
2557 struct scic_sds_phy *sci_phy)
2559 struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
2561 dev_dbg(&ihost->pdev->dev, "%s: iphy = %p, sas_phy = %p\n",
2562 __func__, iphy, &iphy->sas_phy);
2564 ihost->sas_ha.notify_port_event(&iphy->sas_phy, PORTE_BROADCAST_RCVD);
2565 scic_port_enable_broadcast_change_notification(sci_port);
2568 void scic_sds_port_broadcast_change_received(
2569 struct scic_sds_port *sci_port,
2570 struct scic_sds_phy *sci_phy)
2572 struct scic_sds_controller *scic = sci_port->owning_controller;
2573 struct isci_host *ihost = scic_to_ihost(scic);
2575 /* notify the user. */
2576 isci_port_bc_change_received(ihost, sci_port, sci_phy);
2579 int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *iport,
2580 struct isci_phy *iphy)
2582 unsigned long flags;
2583 enum sci_status status;
2584 int ret = TMF_RESP_FUNC_COMPLETE;
2586 dev_dbg(&ihost->pdev->dev, "%s: iport = %p\n",
2589 init_completion(&iport->hard_reset_complete);
2591 spin_lock_irqsave(&ihost->scic_lock, flags);
2593 #define ISCI_PORT_RESET_TIMEOUT SCIC_SDS_SIGNATURE_FIS_TIMEOUT
2594 status = scic_port_hard_reset(&iport->sci, ISCI_PORT_RESET_TIMEOUT);
2596 spin_unlock_irqrestore(&ihost->scic_lock, flags);
2598 if (status == SCI_SUCCESS) {
2599 wait_for_completion(&iport->hard_reset_complete);
2601 dev_dbg(&ihost->pdev->dev,
2602 "%s: iport = %p; hard reset completion\n",
2605 if (iport->hard_reset_status != SCI_SUCCESS)
2606 ret = TMF_RESP_FUNC_FAILED;
2608 ret = TMF_RESP_FUNC_FAILED;
2610 dev_err(&ihost->pdev->dev,
2611 "%s: iport = %p; scic_port_hard_reset call"
2613 __func__, iport, status);
2617 /* If the hard reset for the port has failed, consider this
2618 * the same as link failures on all phys in the port.
2620 if (ret != TMF_RESP_FUNC_COMPLETE) {
2621 dev_err(&ihost->pdev->dev,
2622 "%s: iport = %p; hard reset failed "
2623 "(0x%x) - sending link down to libsas for phy %p\n",
2624 __func__, iport, iport->hard_reset_status, iphy);
2626 isci_port_link_down(ihost, iphy, iport);
2633 * isci_port_deformed() - This function is called by libsas when a port becomes
2635 * @phy: This parameter specifies the libsas phy with the inactive port.
2638 void isci_port_deformed(struct asd_sas_phy *phy)
2640 pr_debug("%s: sas_phy = %p\n", __func__, phy);
2644 * isci_port_formed() - This function is called by libsas when a port becomes
2646 * @phy: This parameter specifies the libsas phy with the active port.
2649 void isci_port_formed(struct asd_sas_phy *phy)
2651 pr_debug("%s: sas_phy = %p, sas_port = %p\n", __func__, phy, phy->port);