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)
65 static const char *port_state_name(enum sci_port_states state
)
67 static const char * const strings
[] = PORT_STATES
;
69 return strings
[state
];
73 static struct device
*sciport_to_dev(struct isci_port
*iport
)
75 int i
= iport
->physical_port_index
;
76 struct isci_port
*table
;
77 struct isci_host
*ihost
;
79 if (i
== SCIC_SDS_DUMMY_PORT
)
83 ihost
= container_of(table
, typeof(*ihost
), ports
[0]);
85 return &ihost
->pdev
->dev
;
88 static void sci_port_get_protocols(struct isci_port
*iport
, struct sci_phy_proto
*proto
)
93 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
94 struct isci_phy
*iphy
= iport
->phy_table
[index
];
98 sci_phy_get_protocols(iphy
, proto
);
102 static u32
sci_port_get_phys(struct isci_port
*iport
)
108 for (index
= 0; index
< SCI_MAX_PHYS
; index
++)
109 if (iport
->phy_table
[index
])
110 mask
|= (1 << index
);
116 * sci_port_get_properties() - This method simply returns the properties
117 * regarding the port, such as: physical index, protocols, sas address, etc.
118 * @iport: this parameter specifies the port for which to retrieve the physical
120 * @prop: This parameter specifies the properties structure into which to
121 * copy the requested information.
123 * Indicate if the user specified a valid port. SCI_SUCCESS This value is
124 * returned if the specified port was valid. SCI_FAILURE_INVALID_PORT This
125 * value is returned if the specified port is not valid. When this value is
126 * returned, no data is copied to the properties output parameter.
128 enum sci_status
sci_port_get_properties(struct isci_port
*iport
,
129 struct sci_port_properties
*prop
)
131 if (!iport
|| iport
->logical_port_index
== SCIC_SDS_DUMMY_PORT
)
132 return SCI_FAILURE_INVALID_PORT
;
134 prop
->index
= iport
->logical_port_index
;
135 prop
->phy_mask
= sci_port_get_phys(iport
);
136 sci_port_get_sas_address(iport
, &prop
->local
.sas_address
);
137 sci_port_get_protocols(iport
, &prop
->local
.protocols
);
138 sci_port_get_attached_sas_address(iport
, &prop
->remote
.sas_address
);
143 static void sci_port_bcn_enable(struct isci_port
*iport
)
145 struct isci_phy
*iphy
;
149 for (i
= 0; i
< ARRAY_SIZE(iport
->phy_table
); i
++) {
150 iphy
= iport
->phy_table
[i
];
153 val
= readl(&iphy
->link_layer_registers
->link_layer_control
);
154 /* clear the bit by writing 1. */
155 writel(val
, &iphy
->link_layer_registers
->link_layer_control
);
159 static void isci_port_bc_change_received(struct isci_host
*ihost
,
160 struct isci_port
*iport
,
161 struct isci_phy
*iphy
)
163 dev_dbg(&ihost
->pdev
->dev
,
164 "%s: isci_phy = %p, sas_phy = %p\n",
165 __func__
, iphy
, &iphy
->sas_phy
);
167 sas_notify_port_event(&iphy
->sas_phy
,
168 PORTE_BROADCAST_RCVD
, GFP_ATOMIC
);
169 sci_port_bcn_enable(iport
);
172 static void isci_port_link_up(struct isci_host
*isci_host
,
173 struct isci_port
*iport
,
174 struct isci_phy
*iphy
)
177 struct sci_port_properties properties
;
178 unsigned long success
= true;
180 dev_dbg(&isci_host
->pdev
->dev
,
181 "%s: isci_port = %p\n",
184 spin_lock_irqsave(&iphy
->sas_phy
.frame_rcvd_lock
, flags
);
186 sci_port_get_properties(iport
, &properties
);
188 if (iphy
->protocol
== SAS_PROTOCOL_SATA
) {
189 u64 attached_sas_address
;
191 iphy
->sas_phy
.oob_mode
= SATA_OOB_MODE
;
192 iphy
->sas_phy
.frame_rcvd_size
= sizeof(struct dev_to_host_fis
);
195 * For direct-attached SATA devices, the SCI core will
196 * automagically assign a SAS address to the end device
197 * for the purpose of creating a port. This SAS address
198 * will not be the same as assigned to the PHY and needs
199 * to be obtained from struct sci_port_properties properties.
201 attached_sas_address
= properties
.remote
.sas_address
.high
;
202 attached_sas_address
<<= 32;
203 attached_sas_address
|= properties
.remote
.sas_address
.low
;
204 swab64s(&attached_sas_address
);
206 memcpy(&iphy
->sas_phy
.attached_sas_addr
,
207 &attached_sas_address
, sizeof(attached_sas_address
));
208 } else if (iphy
->protocol
== SAS_PROTOCOL_SSP
) {
209 iphy
->sas_phy
.oob_mode
= SAS_OOB_MODE
;
210 iphy
->sas_phy
.frame_rcvd_size
= sizeof(struct sas_identify_frame
);
212 /* Copy the attached SAS address from the IAF */
213 memcpy(iphy
->sas_phy
.attached_sas_addr
,
214 iphy
->frame_rcvd
.iaf
.sas_addr
, SAS_ADDR_SIZE
);
216 dev_err(&isci_host
->pdev
->dev
, "%s: unknown target\n", __func__
);
220 iphy
->sas_phy
.phy
->negotiated_linkrate
= sci_phy_linkrate(iphy
);
222 spin_unlock_irqrestore(&iphy
->sas_phy
.frame_rcvd_lock
, flags
);
224 /* Notify libsas that we have an address frame, if indeed
225 * we've found an SSP, SMP, or STP target */
227 sas_notify_port_event(&iphy
->sas_phy
,
228 PORTE_BYTES_DMAED
, GFP_ATOMIC
);
233 * isci_port_link_down() - This function is called by the sci core when a link
235 * @isci_host: This parameter specifies the isci host object.
236 * @isci_phy: This parameter specifies the isci phy with the active link.
237 * @isci_port: This parameter specifies the isci port with the active link.
240 static void isci_port_link_down(struct isci_host
*isci_host
,
241 struct isci_phy
*isci_phy
,
242 struct isci_port
*isci_port
)
244 struct isci_remote_device
*isci_device
;
246 dev_dbg(&isci_host
->pdev
->dev
,
247 "%s: isci_port = %p\n", __func__
, isci_port
);
251 /* check to see if this is the last phy on this port. */
252 if (isci_phy
->sas_phy
.port
&&
253 isci_phy
->sas_phy
.port
->num_phys
== 1) {
254 /* change the state for all devices on this port. The
255 * next task sent to this device will be returned as
256 * SAS_TASK_UNDELIVERED, and the scsi mid layer will
259 list_for_each_entry(isci_device
,
260 &isci_port
->remote_dev_list
,
262 dev_dbg(&isci_host
->pdev
->dev
,
263 "%s: isci_device = %p\n",
264 __func__
, isci_device
);
265 set_bit(IDEV_GONE
, &isci_device
->flags
);
270 /* Notify libsas of the borken link, this will trigger calls to our
271 * isci_port_deformed and isci_dev_gone functions.
273 sas_phy_disconnected(&isci_phy
->sas_phy
);
274 sas_notify_phy_event(&isci_phy
->sas_phy
,
275 PHYE_LOSS_OF_SIGNAL
, GFP_ATOMIC
);
277 dev_dbg(&isci_host
->pdev
->dev
,
278 "%s: isci_port = %p - Done\n", __func__
, isci_port
);
281 static bool is_port_ready_state(enum sci_port_states state
)
285 case SCI_PORT_SUB_WAITING
:
286 case SCI_PORT_SUB_OPERATIONAL
:
287 case SCI_PORT_SUB_CONFIGURING
:
294 /* flag dummy rnc hanling when exiting a ready state */
295 static void port_state_machine_change(struct isci_port
*iport
,
296 enum sci_port_states state
)
298 struct sci_base_state_machine
*sm
= &iport
->sm
;
299 enum sci_port_states old_state
= sm
->current_state_id
;
301 if (is_port_ready_state(old_state
) && !is_port_ready_state(state
))
302 iport
->ready_exit
= true;
304 sci_change_state(sm
, state
);
305 iport
->ready_exit
= false;
309 * isci_port_hard_reset_complete() - This function is called by the sci core
310 * when the hard reset complete notification has been received.
311 * @isci_port: This parameter specifies the sci port with the active link.
312 * @completion_status: This parameter specifies the core status for the reset
316 static void isci_port_hard_reset_complete(struct isci_port
*isci_port
,
317 enum sci_status completion_status
)
319 struct isci_host
*ihost
= isci_port
->owning_controller
;
321 dev_dbg(&ihost
->pdev
->dev
,
322 "%s: isci_port = %p, completion_status=%x\n",
323 __func__
, isci_port
, completion_status
);
325 /* Save the status of the hard reset from the port. */
326 isci_port
->hard_reset_status
= completion_status
;
328 if (completion_status
!= SCI_SUCCESS
) {
330 /* The reset failed. The port state is now SCI_PORT_FAILED. */
331 if (isci_port
->active_phy_mask
== 0) {
332 int phy_idx
= isci_port
->last_active_phy
;
333 struct isci_phy
*iphy
= &ihost
->phys
[phy_idx
];
335 /* Generate the link down now to the host, since it
336 * was intercepted by the hard reset state machine when
337 * it really happened.
339 isci_port_link_down(ihost
, iphy
, isci_port
);
341 /* Advance the port state so that link state changes will be
344 port_state_machine_change(isci_port
, SCI_PORT_SUB_WAITING
);
347 clear_bit(IPORT_RESET_PENDING
, &isci_port
->state
);
348 wake_up(&ihost
->eventq
);
352 /* This method will return a true value if the specified phy can be assigned to
353 * this port The following is a list of phys for each port that are allowed: -
354 * Port 0 - 3 2 1 0 - Port 1 - 1 - Port 2 - 3 2 - Port 3 - 3 This method
355 * doesn't preclude all configurations. It merely ensures that a phy is part
356 * of the allowable set of phy identifiers for that port. For example, one
357 * could assign phy 3 to port 0 and no other phys. Please refer to
358 * sci_port_is_phy_mask_valid() for information regarding whether the
359 * phy_mask for a port can be supported. bool true if this is a valid phy
360 * assignment for the port false if this is not a valid phy assignment for the
363 bool sci_port_is_valid_phy_assignment(struct isci_port
*iport
, u32 phy_index
)
365 struct isci_host
*ihost
= iport
->owning_controller
;
366 struct sci_user_parameters
*user
= &ihost
->user_parameters
;
368 /* Initialize to invalid value. */
369 u32 existing_phy_index
= SCI_MAX_PHYS
;
372 if ((iport
->physical_port_index
== 1) && (phy_index
!= 1))
375 if (iport
->physical_port_index
== 3 && phy_index
!= 3)
378 if (iport
->physical_port_index
== 2 &&
379 (phy_index
== 0 || phy_index
== 1))
382 for (index
= 0; index
< SCI_MAX_PHYS
; index
++)
383 if (iport
->phy_table
[index
] && index
!= phy_index
)
384 existing_phy_index
= index
;
386 /* Ensure that all of the phys in the port are capable of
387 * operating at the same maximum link rate.
389 if (existing_phy_index
< SCI_MAX_PHYS
&&
390 user
->phys
[phy_index
].max_speed_generation
!=
391 user
->phys
[existing_phy_index
].max_speed_generation
)
398 * sci_port_is_phy_mask_valid()
399 * @iport: This is the port object for which to determine if the phy mask
401 * @phy_mask: Phy mask belonging to this port
403 * This method will return a true value if the port's phy mask can be supported
404 * by the SCU. The following is a list of valid PHY mask configurations for
405 * each port: - Port 0 - [[3 2] 1] 0 - Port 1 - [1] - Port 2 - [[3] 2]
406 * - Port 3 - [3] This method returns a boolean indication specifying if the
407 * phy mask can be supported. true if this is a valid phy assignment for the
408 * port false if this is not a valid phy assignment for the port
410 static bool sci_port_is_phy_mask_valid(
411 struct isci_port
*iport
,
414 if (iport
->physical_port_index
== 0) {
415 if (((phy_mask
& 0x0F) == 0x0F)
416 || ((phy_mask
& 0x03) == 0x03)
417 || ((phy_mask
& 0x01) == 0x01)
420 } else if (iport
->physical_port_index
== 1) {
421 if (((phy_mask
& 0x02) == 0x02)
424 } else if (iport
->physical_port_index
== 2) {
425 if (((phy_mask
& 0x0C) == 0x0C)
426 || ((phy_mask
& 0x04) == 0x04)
429 } else if (iport
->physical_port_index
== 3) {
430 if (((phy_mask
& 0x08) == 0x08)
439 * This method retrieves a currently active (i.e. connected) phy contained in
440 * the port. Currently, the lowest order phy that is connected is returned.
441 * This method returns a pointer to a SCIS_SDS_PHY object. NULL This value is
442 * returned if there are no currently active (i.e. connected to a remote end
443 * point) phys contained in the port. All other values specify a struct sci_phy
444 * object that is active in the port.
446 static struct isci_phy
*sci_port_get_a_connected_phy(struct isci_port
*iport
)
449 struct isci_phy
*iphy
;
451 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
452 /* Ensure that the phy is both part of the port and currently
453 * connected to the remote end-point.
455 iphy
= iport
->phy_table
[index
];
456 if (iphy
&& sci_port_active_phy(iport
, iphy
))
463 static enum sci_status
sci_port_set_phy(struct isci_port
*iport
, struct isci_phy
*iphy
)
465 /* Check to see if we can add this phy to a port
466 * that means that the phy is not part of a port and that the port does
467 * not already have a phy assinged to the phy index.
469 if (!iport
->phy_table
[iphy
->phy_index
] &&
470 !phy_get_non_dummy_port(iphy
) &&
471 sci_port_is_valid_phy_assignment(iport
, iphy
->phy_index
)) {
472 /* Phy is being added in the stopped state so we are in MPC mode
473 * make logical port index = physical port index
475 iport
->logical_port_index
= iport
->physical_port_index
;
476 iport
->phy_table
[iphy
->phy_index
] = iphy
;
477 sci_phy_set_port(iphy
, iport
);
485 static enum sci_status
sci_port_clear_phy(struct isci_port
*iport
, struct isci_phy
*iphy
)
487 /* Make sure that this phy is part of this port */
488 if (iport
->phy_table
[iphy
->phy_index
] == iphy
&&
489 phy_get_non_dummy_port(iphy
) == iport
) {
490 struct isci_host
*ihost
= iport
->owning_controller
;
492 /* Yep it is assigned to this port so remove it */
493 sci_phy_set_port(iphy
, &ihost
->ports
[SCI_MAX_PORTS
]);
494 iport
->phy_table
[iphy
->phy_index
] = NULL
;
501 void sci_port_get_sas_address(struct isci_port
*iport
, struct sci_sas_address
*sas
)
507 for (index
= 0; index
< SCI_MAX_PHYS
; index
++)
508 if (iport
->phy_table
[index
])
509 sci_phy_get_sas_address(iport
->phy_table
[index
], sas
);
512 void sci_port_get_attached_sas_address(struct isci_port
*iport
, struct sci_sas_address
*sas
)
514 struct isci_phy
*iphy
;
517 * Ensure that the phy is both part of the port and currently
518 * connected to the remote end-point.
520 iphy
= sci_port_get_a_connected_phy(iport
);
522 if (iphy
->protocol
!= SAS_PROTOCOL_SATA
) {
523 sci_phy_get_attached_sas_address(iphy
, sas
);
525 sci_phy_get_sas_address(iphy
, sas
);
526 sas
->low
+= iphy
->phy_index
;
535 * sci_port_construct_dummy_rnc() - create dummy rnc for si workaround
537 * @iport: logical port on which we need to create the remote node context
538 * @rni: remote node index for this remote node context.
540 * This routine will construct a dummy remote node context data structure
541 * This structure will be posted to the hardware to work around a scheduler
542 * error in the hardware.
544 static void sci_port_construct_dummy_rnc(struct isci_port
*iport
, u16 rni
)
546 union scu_remote_node_context
*rnc
;
548 rnc
= &iport
->owning_controller
->remote_node_context_table
[rni
];
550 memset(rnc
, 0, sizeof(union scu_remote_node_context
));
552 rnc
->ssp
.remote_sas_address_hi
= 0;
553 rnc
->ssp
.remote_sas_address_lo
= 0;
555 rnc
->ssp
.remote_node_index
= rni
;
556 rnc
->ssp
.remote_node_port_width
= 1;
557 rnc
->ssp
.logical_port_index
= iport
->physical_port_index
;
559 rnc
->ssp
.nexus_loss_timer_enable
= false;
560 rnc
->ssp
.check_bit
= false;
561 rnc
->ssp
.is_valid
= true;
562 rnc
->ssp
.is_remote_node_context
= true;
563 rnc
->ssp
.function_number
= 0;
564 rnc
->ssp
.arbitration_wait_time
= 0;
568 * construct a dummy task context data structure. This
569 * structure will be posted to the hardwre to work around a scheduler error
572 static void sci_port_construct_dummy_task(struct isci_port
*iport
, u16 tag
)
574 struct isci_host
*ihost
= iport
->owning_controller
;
575 struct scu_task_context
*task_context
;
577 task_context
= &ihost
->task_context_table
[ISCI_TAG_TCI(tag
)];
578 memset(task_context
, 0, sizeof(struct scu_task_context
));
580 task_context
->initiator_request
= 1;
581 task_context
->connection_rate
= 1;
582 task_context
->logical_port_index
= iport
->physical_port_index
;
583 task_context
->protocol_type
= SCU_TASK_CONTEXT_PROTOCOL_SSP
;
584 task_context
->task_index
= ISCI_TAG_TCI(tag
);
585 task_context
->valid
= SCU_TASK_CONTEXT_VALID
;
586 task_context
->context_type
= SCU_TASK_CONTEXT_TYPE
;
587 task_context
->remote_node_index
= iport
->reserved_rni
;
588 task_context
->do_not_dma_ssp_good_response
= 1;
589 task_context
->task_phase
= 0x01;
592 static void sci_port_destroy_dummy_resources(struct isci_port
*iport
)
594 struct isci_host
*ihost
= iport
->owning_controller
;
596 if (iport
->reserved_tag
!= SCI_CONTROLLER_INVALID_IO_TAG
)
597 isci_free_tag(ihost
, iport
->reserved_tag
);
599 if (iport
->reserved_rni
!= SCU_DUMMY_INDEX
)
600 sci_remote_node_table_release_remote_node_index(&ihost
->available_remote_nodes
,
601 1, iport
->reserved_rni
);
603 iport
->reserved_rni
= SCU_DUMMY_INDEX
;
604 iport
->reserved_tag
= SCI_CONTROLLER_INVALID_IO_TAG
;
607 void sci_port_setup_transports(struct isci_port
*iport
, u32 device_id
)
611 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
612 if (iport
->active_phy_mask
& (1 << index
))
613 sci_phy_setup_transport(iport
->phy_table
[index
], device_id
);
617 static void sci_port_resume_phy(struct isci_port
*iport
, struct isci_phy
*iphy
)
619 sci_phy_resume(iphy
);
620 iport
->enabled_phy_mask
|= 1 << iphy
->phy_index
;
623 static void sci_port_activate_phy(struct isci_port
*iport
,
624 struct isci_phy
*iphy
,
627 struct isci_host
*ihost
= iport
->owning_controller
;
629 if (iphy
->protocol
!= SAS_PROTOCOL_SATA
&& (flags
& PF_RESUME
))
630 sci_phy_resume(iphy
);
632 iport
->active_phy_mask
|= 1 << iphy
->phy_index
;
634 sci_controller_clear_invalid_phy(ihost
, iphy
);
636 if (flags
& PF_NOTIFY
)
637 isci_port_link_up(ihost
, iport
, iphy
);
640 void sci_port_deactivate_phy(struct isci_port
*iport
, struct isci_phy
*iphy
,
643 struct isci_host
*ihost
= iport
->owning_controller
;
645 iport
->active_phy_mask
&= ~(1 << iphy
->phy_index
);
646 iport
->enabled_phy_mask
&= ~(1 << iphy
->phy_index
);
647 if (!iport
->active_phy_mask
)
648 iport
->last_active_phy
= iphy
->phy_index
;
650 iphy
->max_negotiated_speed
= SAS_LINK_RATE_UNKNOWN
;
652 /* Re-assign the phy back to the LP as if it were a narrow port for APC
653 * mode. For MPC mode, the phy will remain in the port.
655 if (iport
->owning_controller
->oem_parameters
.controller
.mode_type
==
656 SCIC_PORT_AUTOMATIC_CONFIGURATION_MODE
)
657 writel(iphy
->phy_index
,
658 &iport
->port_pe_configuration_register
[iphy
->phy_index
]);
660 if (do_notify_user
== true)
661 isci_port_link_down(ihost
, iphy
, iport
);
664 static void sci_port_invalid_link_up(struct isci_port
*iport
, struct isci_phy
*iphy
)
666 struct isci_host
*ihost
= iport
->owning_controller
;
669 * Check to see if we have alreay reported this link as bad and if
670 * not go ahead and tell the SCI_USER that we have discovered an
673 if ((ihost
->invalid_phy_mask
& (1 << iphy
->phy_index
)) == 0) {
674 ihost
->invalid_phy_mask
|= 1 << iphy
->phy_index
;
675 dev_warn(&ihost
->pdev
->dev
, "Invalid link up!\n");
680 * sci_port_general_link_up_handler - phy can be assigned to port?
681 * @iport: sci_port object for which has a phy that has gone link up.
682 * @iphy: This is the struct isci_phy object that has gone link up.
683 * @flags: PF_RESUME, PF_NOTIFY to sci_port_activate_phy
685 * Determine if this phy can be assigned to this port . If the phy is
686 * not a valid PHY for this port then the function will notify the user.
687 * A PHY can only be part of a port if it's attached SAS ADDRESS is the
688 * same as all other PHYs in the same port.
690 static void sci_port_general_link_up_handler(struct isci_port
*iport
,
691 struct isci_phy
*iphy
,
694 struct sci_sas_address port_sas_address
;
695 struct sci_sas_address phy_sas_address
;
697 sci_port_get_attached_sas_address(iport
, &port_sas_address
);
698 sci_phy_get_attached_sas_address(iphy
, &phy_sas_address
);
700 /* If the SAS address of the new phy matches the SAS address of
701 * other phys in the port OR this is the first phy in the port,
702 * then activate the phy and allow it to be used for operations
705 if ((phy_sas_address
.high
== port_sas_address
.high
&&
706 phy_sas_address
.low
== port_sas_address
.low
) ||
707 iport
->active_phy_mask
== 0) {
708 struct sci_base_state_machine
*sm
= &iport
->sm
;
710 sci_port_activate_phy(iport
, iphy
, flags
);
711 if (sm
->current_state_id
== SCI_PORT_RESETTING
)
712 port_state_machine_change(iport
, SCI_PORT_READY
);
714 sci_port_invalid_link_up(iport
, iphy
);
721 * This method returns false if the port only has a single phy object assigned.
722 * If there are no phys or more than one phy then the method will return
724 * @iport: The port for which the wide port condition is to be checked.
726 * bool true Is returned if this is a wide ported port. false Is returned if
727 * this is a narrow port.
729 static bool sci_port_is_wide(struct isci_port
*iport
)
734 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
735 if (iport
->phy_table
[index
] != NULL
) {
740 return phy_count
!= 1;
744 * sci_port_link_detected()
745 * This method is called by the PHY object when the link is detected. if the
746 * port wants the PHY to continue on to the link up state then the port
747 * layer must return true. If the port object returns false the phy object
748 * must halt its attempt to go link up.
749 * @iport: The port associated with the phy object.
750 * @iphy: The phy object that is trying to go link up.
752 * true if the phy object can continue to the link up condition. true Is
753 * returned if this phy can continue to the ready state. false Is returned if
754 * can not continue on to the ready state. This notification is in place for
755 * wide ports and direct attached phys. Since there are no wide ported SATA
756 * devices this could become an invalid port configuration.
758 bool sci_port_link_detected(struct isci_port
*iport
, struct isci_phy
*iphy
)
760 if ((iport
->logical_port_index
!= SCIC_SDS_DUMMY_PORT
) &&
761 (iphy
->protocol
== SAS_PROTOCOL_SATA
)) {
762 if (sci_port_is_wide(iport
)) {
763 sci_port_invalid_link_up(iport
, iphy
);
766 struct isci_host
*ihost
= iport
->owning_controller
;
767 struct isci_port
*dst_port
= &(ihost
->ports
[iphy
->phy_index
]);
768 writel(iphy
->phy_index
,
769 &dst_port
->port_pe_configuration_register
[iphy
->phy_index
]);
776 static void port_timeout(struct timer_list
*t
)
778 struct sci_timer
*tmr
= from_timer(tmr
, t
, timer
);
779 struct isci_port
*iport
= container_of(tmr
, typeof(*iport
), timer
);
780 struct isci_host
*ihost
= iport
->owning_controller
;
784 spin_lock_irqsave(&ihost
->scic_lock
, flags
);
789 current_state
= iport
->sm
.current_state_id
;
791 if (current_state
== SCI_PORT_RESETTING
) {
792 /* if the port is still in the resetting state then the timeout
793 * fired before the reset completed.
795 port_state_machine_change(iport
, SCI_PORT_FAILED
);
796 } else if (current_state
== SCI_PORT_STOPPED
) {
797 /* if the port is stopped then the start request failed In this
798 * case stay in the stopped state.
800 dev_err(sciport_to_dev(iport
),
801 "%s: SCIC Port 0x%p failed to stop before timeout.\n",
804 } else if (current_state
== SCI_PORT_STOPPING
) {
805 dev_dbg(sciport_to_dev(iport
),
806 "%s: port%d: stop complete timeout\n",
807 __func__
, iport
->physical_port_index
);
809 /* The port is in the ready state and we have a timer
810 * reporting a timeout this should not happen.
812 dev_err(sciport_to_dev(iport
),
813 "%s: SCIC Port 0x%p is processing a timeout operation "
814 "in state %d.\n", __func__
, iport
, current_state
);
818 spin_unlock_irqrestore(&ihost
->scic_lock
, flags
);
821 /* --------------------------------------------------------------------------- */
824 * This function updates the hardwares VIIT entry for this port.
826 static void sci_port_update_viit_entry(struct isci_port
*iport
)
828 struct sci_sas_address sas_address
;
830 sci_port_get_sas_address(iport
, &sas_address
);
832 writel(sas_address
.high
,
833 &iport
->viit_registers
->initiator_sas_address_hi
);
834 writel(sas_address
.low
,
835 &iport
->viit_registers
->initiator_sas_address_lo
);
837 /* This value get cleared just in case its not already cleared */
838 writel(0, &iport
->viit_registers
->reserved
);
840 /* We are required to update the status register last */
841 writel(SCU_VIIT_ENTRY_ID_VIIT
|
842 SCU_VIIT_IPPT_INITIATOR
|
843 ((1 << iport
->physical_port_index
) << SCU_VIIT_ENTRY_LPVIE_SHIFT
) |
844 SCU_VIIT_STATUS_ALL_VALID
,
845 &iport
->viit_registers
->status
);
848 enum sas_linkrate
sci_port_get_max_allowed_speed(struct isci_port
*iport
)
851 struct isci_phy
*iphy
;
852 enum sas_linkrate max_allowed_speed
= SAS_LINK_RATE_6_0_GBPS
;
855 * Loop through all of the phys in this port and find the phy with the
856 * lowest maximum link rate. */
857 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
858 iphy
= iport
->phy_table
[index
];
859 if (iphy
&& sci_port_active_phy(iport
, iphy
) &&
860 iphy
->max_negotiated_speed
< max_allowed_speed
)
861 max_allowed_speed
= iphy
->max_negotiated_speed
;
864 return max_allowed_speed
;
867 static void sci_port_suspend_port_task_scheduler(struct isci_port
*iport
)
869 u32 pts_control_value
;
871 pts_control_value
= readl(&iport
->port_task_scheduler_registers
->control
);
872 pts_control_value
|= SCU_PTSxCR_GEN_BIT(SUSPEND
);
873 writel(pts_control_value
, &iport
->port_task_scheduler_registers
->control
);
877 * sci_port_post_dummy_request() - post dummy/workaround request
878 * @iport: port to post task
880 * Prevent the hardware scheduler from posting new requests to the front
881 * of the scheduler queue causing a starvation problem for currently
885 static void sci_port_post_dummy_request(struct isci_port
*iport
)
887 struct isci_host
*ihost
= iport
->owning_controller
;
888 u16 tag
= iport
->reserved_tag
;
889 struct scu_task_context
*tc
;
892 tc
= &ihost
->task_context_table
[ISCI_TAG_TCI(tag
)];
895 command
= SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC
|
896 iport
->physical_port_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
|
899 sci_controller_post_request(ihost
, command
);
903 * sci_port_abort_dummy_request()
904 * This routine will abort the dummy request. This will allow the hardware to
905 * power down parts of the silicon to save power.
907 * @iport: The port on which the task must be aborted.
910 static void sci_port_abort_dummy_request(struct isci_port
*iport
)
912 struct isci_host
*ihost
= iport
->owning_controller
;
913 u16 tag
= iport
->reserved_tag
;
914 struct scu_task_context
*tc
;
917 tc
= &ihost
->task_context_table
[ISCI_TAG_TCI(tag
)];
920 command
= SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT
|
921 iport
->physical_port_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
|
924 sci_controller_post_request(ihost
, command
);
928 * sci_port_resume_port_task_scheduler()
929 * @iport: This is the struct isci_port object to resume.
931 * This method will resume the port task scheduler for this port object. none
934 sci_port_resume_port_task_scheduler(struct isci_port
*iport
)
936 u32 pts_control_value
;
938 pts_control_value
= readl(&iport
->port_task_scheduler_registers
->control
);
939 pts_control_value
&= ~SCU_PTSxCR_GEN_BIT(SUSPEND
);
940 writel(pts_control_value
, &iport
->port_task_scheduler_registers
->control
);
943 static void sci_port_ready_substate_waiting_enter(struct sci_base_state_machine
*sm
)
945 struct isci_port
*iport
= container_of(sm
, typeof(*iport
), sm
);
947 sci_port_suspend_port_task_scheduler(iport
);
949 iport
->not_ready_reason
= SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS
;
951 if (iport
->active_phy_mask
!= 0) {
952 /* At least one of the phys on the port is ready */
953 port_state_machine_change(iport
,
954 SCI_PORT_SUB_OPERATIONAL
);
958 static void scic_sds_port_ready_substate_waiting_exit(
959 struct sci_base_state_machine
*sm
)
961 struct isci_port
*iport
= container_of(sm
, typeof(*iport
), sm
);
962 sci_port_resume_port_task_scheduler(iport
);
965 static void sci_port_ready_substate_operational_enter(struct sci_base_state_machine
*sm
)
968 struct isci_port
*iport
= container_of(sm
, typeof(*iport
), sm
);
969 struct isci_host
*ihost
= iport
->owning_controller
;
971 dev_dbg(&ihost
->pdev
->dev
, "%s: port%d ready\n",
972 __func__
, iport
->physical_port_index
);
974 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
975 if (iport
->phy_table
[index
]) {
976 writel(iport
->physical_port_index
,
977 &iport
->port_pe_configuration_register
[
978 iport
->phy_table
[index
]->phy_index
]);
979 if (((iport
->active_phy_mask
^iport
->enabled_phy_mask
) & (1 << index
)) != 0)
980 sci_port_resume_phy(iport
, iport
->phy_table
[index
]);
984 sci_port_update_viit_entry(iport
);
987 * Post the dummy task for the port so the hardware can schedule
990 sci_port_post_dummy_request(iport
);
993 static void sci_port_invalidate_dummy_remote_node(struct isci_port
*iport
)
995 struct isci_host
*ihost
= iport
->owning_controller
;
996 u8 phys_index
= iport
->physical_port_index
;
997 union scu_remote_node_context
*rnc
;
998 u16 rni
= iport
->reserved_rni
;
1001 rnc
= &ihost
->remote_node_context_table
[rni
];
1003 rnc
->ssp
.is_valid
= false;
1005 /* ensure the preceding tc abort request has reached the
1006 * controller and give it ample time to act before posting the rnc
1009 readl(&ihost
->smu_registers
->interrupt_status
); /* flush */
1012 command
= SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE
|
1013 phys_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
| rni
;
1015 sci_controller_post_request(ihost
, command
);
1019 * sci_port_ready_substate_operational_exit()
1020 * @sm: This is the object which is cast to a struct isci_port object.
1022 * This method will perform the actions required by the struct isci_port on
1023 * exiting the SCI_PORT_SUB_OPERATIONAL. This function reports
1024 * the port not ready and suspends the port task scheduler. none
1026 static void sci_port_ready_substate_operational_exit(struct sci_base_state_machine
*sm
)
1028 struct isci_port
*iport
= container_of(sm
, typeof(*iport
), sm
);
1029 struct isci_host
*ihost
= iport
->owning_controller
;
1032 * Kill the dummy task for this port if it has not yet posted
1033 * the hardware will treat this as a NOP and just return abort
1036 sci_port_abort_dummy_request(iport
);
1038 dev_dbg(&ihost
->pdev
->dev
, "%s: port%d !ready\n",
1039 __func__
, iport
->physical_port_index
);
1041 if (iport
->ready_exit
)
1042 sci_port_invalidate_dummy_remote_node(iport
);
1045 static void sci_port_ready_substate_configuring_enter(struct sci_base_state_machine
*sm
)
1047 struct isci_port
*iport
= container_of(sm
, typeof(*iport
), sm
);
1048 struct isci_host
*ihost
= iport
->owning_controller
;
1050 if (iport
->active_phy_mask
== 0) {
1051 dev_dbg(&ihost
->pdev
->dev
, "%s: port%d !ready\n",
1052 __func__
, iport
->physical_port_index
);
1054 port_state_machine_change(iport
, SCI_PORT_SUB_WAITING
);
1056 port_state_machine_change(iport
, SCI_PORT_SUB_OPERATIONAL
);
1059 enum sci_status
sci_port_start(struct isci_port
*iport
)
1061 struct isci_host
*ihost
= iport
->owning_controller
;
1062 enum sci_status status
= SCI_SUCCESS
;
1063 enum sci_port_states state
;
1066 state
= iport
->sm
.current_state_id
;
1067 if (state
!= SCI_PORT_STOPPED
) {
1068 dev_warn(sciport_to_dev(iport
), "%s: in wrong state: %s\n",
1069 __func__
, port_state_name(state
));
1070 return SCI_FAILURE_INVALID_STATE
;
1073 if (iport
->assigned_device_count
> 0) {
1074 /* TODO This is a start failure operation because
1075 * there are still devices assigned to this port.
1076 * There must be no devices assigned to a port on a
1079 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
;
1082 if (iport
->reserved_rni
== SCU_DUMMY_INDEX
) {
1083 u16 rni
= sci_remote_node_table_allocate_remote_node(
1084 &ihost
->available_remote_nodes
, 1);
1086 if (rni
!= SCU_DUMMY_INDEX
)
1087 sci_port_construct_dummy_rnc(iport
, rni
);
1089 status
= SCI_FAILURE_INSUFFICIENT_RESOURCES
;
1090 iport
->reserved_rni
= rni
;
1093 if (iport
->reserved_tag
== SCI_CONTROLLER_INVALID_IO_TAG
) {
1096 tag
= isci_alloc_tag(ihost
);
1097 if (tag
== SCI_CONTROLLER_INVALID_IO_TAG
)
1098 status
= SCI_FAILURE_INSUFFICIENT_RESOURCES
;
1100 sci_port_construct_dummy_task(iport
, tag
);
1101 iport
->reserved_tag
= tag
;
1104 if (status
== SCI_SUCCESS
) {
1105 phy_mask
= sci_port_get_phys(iport
);
1108 * There are one or more phys assigned to this port. Make sure
1109 * the port's phy mask is in fact legal and supported by the
1112 if (sci_port_is_phy_mask_valid(iport
, phy_mask
) == true) {
1113 port_state_machine_change(iport
,
1118 status
= SCI_FAILURE
;
1121 if (status
!= SCI_SUCCESS
)
1122 sci_port_destroy_dummy_resources(iport
);
1127 enum sci_status
sci_port_stop(struct isci_port
*iport
)
1129 enum sci_port_states state
;
1131 state
= iport
->sm
.current_state_id
;
1133 case SCI_PORT_STOPPED
:
1135 case SCI_PORT_SUB_WAITING
:
1136 case SCI_PORT_SUB_OPERATIONAL
:
1137 case SCI_PORT_SUB_CONFIGURING
:
1138 case SCI_PORT_RESETTING
:
1139 port_state_machine_change(iport
,
1143 dev_warn(sciport_to_dev(iport
), "%s: in wrong state: %s\n",
1144 __func__
, port_state_name(state
));
1145 return SCI_FAILURE_INVALID_STATE
;
1149 static enum sci_status
sci_port_hard_reset(struct isci_port
*iport
, u32 timeout
)
1151 enum sci_status status
= SCI_FAILURE_INVALID_PHY
;
1152 struct isci_phy
*iphy
= NULL
;
1153 enum sci_port_states state
;
1156 state
= iport
->sm
.current_state_id
;
1157 if (state
!= SCI_PORT_SUB_OPERATIONAL
) {
1158 dev_warn(sciport_to_dev(iport
), "%s: in wrong state: %s\n",
1159 __func__
, port_state_name(state
));
1160 return SCI_FAILURE_INVALID_STATE
;
1163 /* Select a phy on which we can send the hard reset request. */
1164 for (phy_index
= 0; phy_index
< SCI_MAX_PHYS
&& !iphy
; phy_index
++) {
1165 iphy
= iport
->phy_table
[phy_index
];
1166 if (iphy
&& !sci_port_active_phy(iport
, iphy
)) {
1168 * We found a phy but it is not ready select
1175 /* If we have a phy then go ahead and start the reset procedure */
1178 status
= sci_phy_reset(iphy
);
1180 if (status
!= SCI_SUCCESS
)
1183 sci_mod_timer(&iport
->timer
, timeout
);
1184 iport
->not_ready_reason
= SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED
;
1186 port_state_machine_change(iport
, SCI_PORT_RESETTING
);
1191 * sci_port_add_phy()
1192 * @iport: This parameter specifies the port in which the phy will be added.
1193 * @iphy: This parameter is the phy which is to be added to the port.
1195 * This method will add a PHY to the selected port. This method returns an
1196 * enum sci_status. SCI_SUCCESS the phy has been added to the port. Any other
1197 * status is a failure to add the phy to the port.
1199 enum sci_status
sci_port_add_phy(struct isci_port
*iport
,
1200 struct isci_phy
*iphy
)
1202 enum sci_status status
;
1203 enum sci_port_states state
;
1205 sci_port_bcn_enable(iport
);
1207 state
= iport
->sm
.current_state_id
;
1209 case SCI_PORT_STOPPED
: {
1210 struct sci_sas_address port_sas_address
;
1212 /* Read the port assigned SAS Address if there is one */
1213 sci_port_get_sas_address(iport
, &port_sas_address
);
1215 if (port_sas_address
.high
!= 0 && port_sas_address
.low
!= 0) {
1216 struct sci_sas_address phy_sas_address
;
1218 /* Make sure that the PHY SAS Address matches the SAS Address
1221 sci_phy_get_sas_address(iphy
, &phy_sas_address
);
1223 if (port_sas_address
.high
!= phy_sas_address
.high
||
1224 port_sas_address
.low
!= phy_sas_address
.low
)
1225 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
;
1227 return sci_port_set_phy(iport
, iphy
);
1229 case SCI_PORT_SUB_WAITING
:
1230 case SCI_PORT_SUB_OPERATIONAL
:
1231 status
= sci_port_set_phy(iport
, iphy
);
1233 if (status
!= SCI_SUCCESS
)
1236 sci_port_general_link_up_handler(iport
, iphy
, PF_NOTIFY
|PF_RESUME
);
1237 iport
->not_ready_reason
= SCIC_PORT_NOT_READY_RECONFIGURING
;
1238 port_state_machine_change(iport
, SCI_PORT_SUB_CONFIGURING
);
1241 case SCI_PORT_SUB_CONFIGURING
:
1242 status
= sci_port_set_phy(iport
, iphy
);
1244 if (status
!= SCI_SUCCESS
)
1246 sci_port_general_link_up_handler(iport
, iphy
, PF_NOTIFY
);
1248 /* Re-enter the configuring state since this may be the last phy in
1251 port_state_machine_change(iport
,
1252 SCI_PORT_SUB_CONFIGURING
);
1255 dev_warn(sciport_to_dev(iport
), "%s: in wrong state: %s\n",
1256 __func__
, port_state_name(state
));
1257 return SCI_FAILURE_INVALID_STATE
;
1262 * sci_port_remove_phy()
1263 * @iport: This parameter specifies the port in which the phy will be added.
1264 * @iphy: This parameter is the phy which is to be added to the port.
1266 * This method will remove the PHY from the selected PORT. This method returns
1267 * an enum sci_status. SCI_SUCCESS the phy has been removed from the port. Any
1268 * other status is a failure to add the phy to the port.
1270 enum sci_status
sci_port_remove_phy(struct isci_port
*iport
,
1271 struct isci_phy
*iphy
)
1273 enum sci_status status
;
1274 enum sci_port_states state
;
1276 state
= iport
->sm
.current_state_id
;
1279 case SCI_PORT_STOPPED
:
1280 return sci_port_clear_phy(iport
, iphy
);
1281 case SCI_PORT_SUB_OPERATIONAL
:
1282 status
= sci_port_clear_phy(iport
, iphy
);
1283 if (status
!= SCI_SUCCESS
)
1286 sci_port_deactivate_phy(iport
, iphy
, true);
1287 iport
->not_ready_reason
= SCIC_PORT_NOT_READY_RECONFIGURING
;
1288 port_state_machine_change(iport
,
1289 SCI_PORT_SUB_CONFIGURING
);
1291 case SCI_PORT_SUB_CONFIGURING
:
1292 status
= sci_port_clear_phy(iport
, iphy
);
1294 if (status
!= SCI_SUCCESS
)
1296 sci_port_deactivate_phy(iport
, iphy
, true);
1298 /* Re-enter the configuring state since this may be the last phy in
1301 port_state_machine_change(iport
,
1302 SCI_PORT_SUB_CONFIGURING
);
1305 dev_warn(sciport_to_dev(iport
), "%s: in wrong state: %s\n",
1306 __func__
, port_state_name(state
));
1307 return SCI_FAILURE_INVALID_STATE
;
1311 enum sci_status
sci_port_link_up(struct isci_port
*iport
,
1312 struct isci_phy
*iphy
)
1314 enum sci_port_states state
;
1316 state
= iport
->sm
.current_state_id
;
1318 case SCI_PORT_SUB_WAITING
:
1319 /* Since this is the first phy going link up for the port we
1320 * can just enable it and continue
1322 sci_port_activate_phy(iport
, iphy
, PF_NOTIFY
|PF_RESUME
);
1324 port_state_machine_change(iport
,
1325 SCI_PORT_SUB_OPERATIONAL
);
1327 case SCI_PORT_SUB_OPERATIONAL
:
1328 sci_port_general_link_up_handler(iport
, iphy
, PF_NOTIFY
|PF_RESUME
);
1330 case SCI_PORT_RESETTING
:
1331 /* TODO We should make sure that the phy that has gone
1332 * link up is the same one on which we sent the reset. It is
1333 * possible that the phy on which we sent the reset is not the
1334 * one that has gone link up and we want to make sure that
1335 * phy being reset comes back. Consider the case where a
1336 * reset is sent but before the hardware processes the reset it
1337 * get a link up on the port because of a hot plug event.
1338 * because of the reset request this phy will go link down
1339 * almost immediately.
1342 /* In the resetting state we don't notify the user regarding
1343 * link up and link down notifications.
1345 sci_port_general_link_up_handler(iport
, iphy
, PF_RESUME
);
1348 dev_warn(sciport_to_dev(iport
), "%s: in wrong state: %s\n",
1349 __func__
, port_state_name(state
));
1350 return SCI_FAILURE_INVALID_STATE
;
1354 enum sci_status
sci_port_link_down(struct isci_port
*iport
,
1355 struct isci_phy
*iphy
)
1357 enum sci_port_states state
;
1359 state
= iport
->sm
.current_state_id
;
1361 case SCI_PORT_SUB_OPERATIONAL
:
1362 sci_port_deactivate_phy(iport
, iphy
, true);
1364 /* If there are no active phys left in the port, then
1365 * transition the port to the WAITING state until such time
1366 * as a phy goes link up
1368 if (iport
->active_phy_mask
== 0)
1369 port_state_machine_change(iport
,
1370 SCI_PORT_SUB_WAITING
);
1372 case SCI_PORT_RESETTING
:
1373 /* In the resetting state we don't notify the user regarding
1374 * link up and link down notifications. */
1375 sci_port_deactivate_phy(iport
, iphy
, false);
1378 dev_warn(sciport_to_dev(iport
), "%s: in wrong state: %s\n",
1379 __func__
, port_state_name(state
));
1380 return SCI_FAILURE_INVALID_STATE
;
1384 enum sci_status
sci_port_start_io(struct isci_port
*iport
,
1385 struct isci_remote_device
*idev
,
1386 struct isci_request
*ireq
)
1388 enum sci_port_states state
;
1390 state
= iport
->sm
.current_state_id
;
1392 case SCI_PORT_SUB_WAITING
:
1393 return SCI_FAILURE_INVALID_STATE
;
1394 case SCI_PORT_SUB_OPERATIONAL
:
1395 iport
->started_request_count
++;
1398 dev_warn(sciport_to_dev(iport
), "%s: in wrong state: %s\n",
1399 __func__
, port_state_name(state
));
1400 return SCI_FAILURE_INVALID_STATE
;
1404 enum sci_status
sci_port_complete_io(struct isci_port
*iport
,
1405 struct isci_remote_device
*idev
,
1406 struct isci_request
*ireq
)
1408 enum sci_port_states state
;
1410 state
= iport
->sm
.current_state_id
;
1412 case SCI_PORT_STOPPED
:
1413 dev_warn(sciport_to_dev(iport
), "%s: in wrong state: %s\n",
1414 __func__
, port_state_name(state
));
1415 return SCI_FAILURE_INVALID_STATE
;
1416 case SCI_PORT_STOPPING
:
1417 sci_port_decrement_request_count(iport
);
1419 if (iport
->started_request_count
== 0)
1420 port_state_machine_change(iport
,
1423 case SCI_PORT_READY
:
1424 case SCI_PORT_RESETTING
:
1425 case SCI_PORT_FAILED
:
1426 case SCI_PORT_SUB_WAITING
:
1427 case SCI_PORT_SUB_OPERATIONAL
:
1428 sci_port_decrement_request_count(iport
);
1430 case SCI_PORT_SUB_CONFIGURING
:
1431 sci_port_decrement_request_count(iport
);
1432 if (iport
->started_request_count
== 0) {
1433 port_state_machine_change(iport
,
1434 SCI_PORT_SUB_OPERATIONAL
);
1441 static void sci_port_enable_port_task_scheduler(struct isci_port
*iport
)
1443 u32 pts_control_value
;
1445 /* enable the port task scheduler in a suspended state */
1446 pts_control_value
= readl(&iport
->port_task_scheduler_registers
->control
);
1447 pts_control_value
|= SCU_PTSxCR_GEN_BIT(ENABLE
) | SCU_PTSxCR_GEN_BIT(SUSPEND
);
1448 writel(pts_control_value
, &iport
->port_task_scheduler_registers
->control
);
1451 static void sci_port_disable_port_task_scheduler(struct isci_port
*iport
)
1453 u32 pts_control_value
;
1455 pts_control_value
= readl(&iport
->port_task_scheduler_registers
->control
);
1456 pts_control_value
&=
1457 ~(SCU_PTSxCR_GEN_BIT(ENABLE
) | SCU_PTSxCR_GEN_BIT(SUSPEND
));
1458 writel(pts_control_value
, &iport
->port_task_scheduler_registers
->control
);
1461 static void sci_port_post_dummy_remote_node(struct isci_port
*iport
)
1463 struct isci_host
*ihost
= iport
->owning_controller
;
1464 u8 phys_index
= iport
->physical_port_index
;
1465 union scu_remote_node_context
*rnc
;
1466 u16 rni
= iport
->reserved_rni
;
1469 rnc
= &ihost
->remote_node_context_table
[rni
];
1470 rnc
->ssp
.is_valid
= true;
1472 command
= SCU_CONTEXT_COMMAND_POST_RNC_32
|
1473 phys_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
| rni
;
1475 sci_controller_post_request(ihost
, command
);
1477 /* ensure hardware has seen the post rnc command and give it
1478 * ample time to act before sending the suspend
1480 readl(&ihost
->smu_registers
->interrupt_status
); /* flush */
1483 command
= SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX
|
1484 phys_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
| rni
;
1486 sci_controller_post_request(ihost
, command
);
1489 static void sci_port_stopped_state_enter(struct sci_base_state_machine
*sm
)
1491 struct isci_port
*iport
= container_of(sm
, typeof(*iport
), sm
);
1493 if (iport
->sm
.previous_state_id
== SCI_PORT_STOPPING
) {
1495 * If we enter this state becasuse of a request to stop
1496 * the port then we want to disable the hardwares port
1497 * task scheduler. */
1498 sci_port_disable_port_task_scheduler(iport
);
1502 static void sci_port_stopped_state_exit(struct sci_base_state_machine
*sm
)
1504 struct isci_port
*iport
= container_of(sm
, typeof(*iport
), sm
);
1506 /* Enable and suspend the port task scheduler */
1507 sci_port_enable_port_task_scheduler(iport
);
1510 static void sci_port_ready_state_enter(struct sci_base_state_machine
*sm
)
1512 struct isci_port
*iport
= container_of(sm
, typeof(*iport
), sm
);
1513 struct isci_host
*ihost
= iport
->owning_controller
;
1516 prev_state
= iport
->sm
.previous_state_id
;
1517 if (prev_state
== SCI_PORT_RESETTING
)
1518 isci_port_hard_reset_complete(iport
, SCI_SUCCESS
);
1520 dev_dbg(&ihost
->pdev
->dev
, "%s: port%d !ready\n",
1521 __func__
, iport
->physical_port_index
);
1523 /* Post and suspend the dummy remote node context for this port. */
1524 sci_port_post_dummy_remote_node(iport
);
1526 /* Start the ready substate machine */
1527 port_state_machine_change(iport
,
1528 SCI_PORT_SUB_WAITING
);
1531 static void sci_port_resetting_state_exit(struct sci_base_state_machine
*sm
)
1533 struct isci_port
*iport
= container_of(sm
, typeof(*iport
), sm
);
1535 sci_del_timer(&iport
->timer
);
1538 static void sci_port_stopping_state_exit(struct sci_base_state_machine
*sm
)
1540 struct isci_port
*iport
= container_of(sm
, typeof(*iport
), sm
);
1542 sci_del_timer(&iport
->timer
);
1544 sci_port_destroy_dummy_resources(iport
);
1547 static void sci_port_failed_state_enter(struct sci_base_state_machine
*sm
)
1549 struct isci_port
*iport
= container_of(sm
, typeof(*iport
), sm
);
1551 isci_port_hard_reset_complete(iport
, SCI_FAILURE_TIMEOUT
);
1554 void sci_port_set_hang_detection_timeout(struct isci_port
*iport
, u32 timeout
)
1557 u32 phy_mask
= iport
->active_phy_mask
;
1560 ++iport
->hang_detect_users
;
1561 else if (iport
->hang_detect_users
> 1)
1562 --iport
->hang_detect_users
;
1564 iport
->hang_detect_users
= 0;
1566 if (timeout
|| (iport
->hang_detect_users
== 0)) {
1567 for (phy_index
= 0; phy_index
< SCI_MAX_PHYS
; phy_index
++) {
1568 if ((phy_mask
>> phy_index
) & 1) {
1570 &iport
->phy_table
[phy_index
]
1571 ->link_layer_registers
1572 ->link_layer_hang_detection_timeout
);
1577 /* --------------------------------------------------------------------------- */
1579 static const struct sci_base_state sci_port_state_table
[] = {
1580 [SCI_PORT_STOPPED
] = {
1581 .enter_state
= sci_port_stopped_state_enter
,
1582 .exit_state
= sci_port_stopped_state_exit
1584 [SCI_PORT_STOPPING
] = {
1585 .exit_state
= sci_port_stopping_state_exit
1587 [SCI_PORT_READY
] = {
1588 .enter_state
= sci_port_ready_state_enter
,
1590 [SCI_PORT_SUB_WAITING
] = {
1591 .enter_state
= sci_port_ready_substate_waiting_enter
,
1592 .exit_state
= scic_sds_port_ready_substate_waiting_exit
,
1594 [SCI_PORT_SUB_OPERATIONAL
] = {
1595 .enter_state
= sci_port_ready_substate_operational_enter
,
1596 .exit_state
= sci_port_ready_substate_operational_exit
1598 [SCI_PORT_SUB_CONFIGURING
] = {
1599 .enter_state
= sci_port_ready_substate_configuring_enter
1601 [SCI_PORT_RESETTING
] = {
1602 .exit_state
= sci_port_resetting_state_exit
1604 [SCI_PORT_FAILED
] = {
1605 .enter_state
= sci_port_failed_state_enter
,
1609 void sci_port_construct(struct isci_port
*iport
, u8 index
,
1610 struct isci_host
*ihost
)
1612 sci_init_sm(&iport
->sm
, sci_port_state_table
, SCI_PORT_STOPPED
);
1614 iport
->logical_port_index
= SCIC_SDS_DUMMY_PORT
;
1615 iport
->physical_port_index
= index
;
1616 iport
->active_phy_mask
= 0;
1617 iport
->enabled_phy_mask
= 0;
1618 iport
->last_active_phy
= 0;
1619 iport
->ready_exit
= false;
1621 iport
->owning_controller
= ihost
;
1623 iport
->started_request_count
= 0;
1624 iport
->assigned_device_count
= 0;
1625 iport
->hang_detect_users
= 0;
1627 iport
->reserved_rni
= SCU_DUMMY_INDEX
;
1628 iport
->reserved_tag
= SCI_CONTROLLER_INVALID_IO_TAG
;
1630 sci_init_timer(&iport
->timer
, port_timeout
);
1632 iport
->port_task_scheduler_registers
= NULL
;
1634 for (index
= 0; index
< SCI_MAX_PHYS
; index
++)
1635 iport
->phy_table
[index
] = NULL
;
1638 void sci_port_broadcast_change_received(struct isci_port
*iport
, struct isci_phy
*iphy
)
1640 struct isci_host
*ihost
= iport
->owning_controller
;
1642 /* notify the user. */
1643 isci_port_bc_change_received(ihost
, iport
, iphy
);
1646 static void wait_port_reset(struct isci_host
*ihost
, struct isci_port
*iport
)
1648 wait_event(ihost
->eventq
, !test_bit(IPORT_RESET_PENDING
, &iport
->state
));
1651 int isci_port_perform_hard_reset(struct isci_host
*ihost
, struct isci_port
*iport
,
1652 struct isci_phy
*iphy
)
1654 unsigned long flags
;
1655 enum sci_status status
;
1656 int ret
= TMF_RESP_FUNC_COMPLETE
;
1658 dev_dbg(&ihost
->pdev
->dev
, "%s: iport = %p\n",
1661 spin_lock_irqsave(&ihost
->scic_lock
, flags
);
1662 set_bit(IPORT_RESET_PENDING
, &iport
->state
);
1664 #define ISCI_PORT_RESET_TIMEOUT SCIC_SDS_SIGNATURE_FIS_TIMEOUT
1665 status
= sci_port_hard_reset(iport
, ISCI_PORT_RESET_TIMEOUT
);
1667 spin_unlock_irqrestore(&ihost
->scic_lock
, flags
);
1669 if (status
== SCI_SUCCESS
) {
1670 wait_port_reset(ihost
, iport
);
1672 dev_dbg(&ihost
->pdev
->dev
,
1673 "%s: iport = %p; hard reset completion\n",
1676 if (iport
->hard_reset_status
!= SCI_SUCCESS
) {
1677 ret
= TMF_RESP_FUNC_FAILED
;
1679 dev_err(&ihost
->pdev
->dev
,
1680 "%s: iport = %p; hard reset failed (0x%x)\n",
1681 __func__
, iport
, iport
->hard_reset_status
);
1684 clear_bit(IPORT_RESET_PENDING
, &iport
->state
);
1685 wake_up(&ihost
->eventq
);
1686 ret
= TMF_RESP_FUNC_FAILED
;
1688 dev_err(&ihost
->pdev
->dev
,
1689 "%s: iport = %p; sci_port_hard_reset call"
1691 __func__
, iport
, status
);
1697 int isci_ata_check_ready(struct domain_device
*dev
)
1699 struct isci_port
*iport
= dev
->port
->lldd_port
;
1700 struct isci_host
*ihost
= dev_to_ihost(dev
);
1701 struct isci_remote_device
*idev
;
1702 unsigned long flags
;
1705 spin_lock_irqsave(&ihost
->scic_lock
, flags
);
1706 idev
= isci_lookup_device(dev
);
1707 spin_unlock_irqrestore(&ihost
->scic_lock
, flags
);
1712 if (test_bit(IPORT_RESET_PENDING
, &iport
->state
))
1715 rc
= !!iport
->active_phy_mask
;
1717 isci_put_device(idev
);
1722 void isci_port_deformed(struct asd_sas_phy
*phy
)
1724 struct isci_host
*ihost
= phy
->ha
->lldd_ha
;
1725 struct isci_port
*iport
= phy
->port
->lldd_port
;
1726 unsigned long flags
;
1729 /* we got a port notification on a port that was subsequently
1730 * torn down and libsas is just now catching up
1735 spin_lock_irqsave(&ihost
->scic_lock
, flags
);
1736 for (i
= 0; i
< SCI_MAX_PHYS
; i
++) {
1737 if (iport
->active_phy_mask
& 1 << i
)
1740 spin_unlock_irqrestore(&ihost
->scic_lock
, flags
);
1742 if (i
>= SCI_MAX_PHYS
)
1743 dev_dbg(&ihost
->pdev
->dev
, "%s: port: %ld\n",
1744 __func__
, (long) (iport
- &ihost
->ports
[0]));
1747 void isci_port_formed(struct asd_sas_phy
*phy
)
1749 struct isci_host
*ihost
= phy
->ha
->lldd_ha
;
1750 struct isci_phy
*iphy
= to_iphy(phy
);
1751 struct asd_sas_port
*port
= phy
->port
;
1752 struct isci_port
*iport
= NULL
;
1753 unsigned long flags
;
1756 /* initial ports are formed as the driver is still initializing,
1757 * wait for that process to complete
1759 wait_for_start(ihost
);
1761 spin_lock_irqsave(&ihost
->scic_lock
, flags
);
1762 for (i
= 0; i
< SCI_MAX_PORTS
; i
++) {
1763 iport
= &ihost
->ports
[i
];
1764 if (iport
->active_phy_mask
& 1 << iphy
->phy_index
)
1767 spin_unlock_irqrestore(&ihost
->scic_lock
, flags
);
1769 if (i
>= SCI_MAX_PORTS
)
1772 port
->lldd_port
= iport
;