56 #include <linux/bitops.h>
71 return strings[
state];
93 "%s: idev = %p\n", __func__, idev);
101 static enum sci_status sci_remote_device_terminate_req(
113 "%s: idev=%p; flags=%lx; req=%p; req target=%p\n",
121 static enum sci_status sci_remote_device_terminate_reqs_checkabort(
133 s = sci_remote_device_terminate_req(ihost, idev, chk, ireq);
140 static bool isci_compare_suspendcount(
149 return (localcount != idev->
rnc.suspend_count)
150 || sci_remote_node_context_is_being_destroyed(&idev->
rnc);
153 static bool isci_check_reqterm(
163 res = isci_compare_suspendcount(idev, localcount)
165 spin_unlock_irqrestore(&ihost->
scic_lock, flags);
170 static bool isci_check_devempty(
179 res = isci_compare_suspendcount(idev, localcount)
181 spin_unlock_irqrestore(&ihost->
scic_lock, flags);
193 u32 rnc_suspend_count;
197 if (isci_get_device(idev) ==
NULL) {
198 dev_dbg(&ihost->
pdev->dev,
"%s: failed isci_get_device(idev=%p)\n",
200 spin_unlock_irqrestore(&ihost->
scic_lock, flags);
207 ? 0 : idev->
rnc.suspend_count;
210 "%s: idev=%p, ireq=%p; started_request_count=%d, "
211 "rnc_suspend_count=%d, rnc.suspend_count=%d"
214 rnc_suspend_count, idev->
rnc.suspend_count);
216 #define MAX_SUSPEND_MSECS 10000
220 sci_remote_device_terminate_req(ihost, idev, 0, ireq);
221 spin_unlock_irqrestore(&ihost->
scic_lock, flags);
223 isci_check_reqterm(ihost, idev, ireq,
227 dev_warn(&ihost->
pdev->dev,
"%s host%d timeout single\n",
228 __func__, ihost->
id);
230 "%s: ******* Timeout waiting for "
231 "suspend; idev=%p, current state %s; "
232 "started_request_count=%d, flags=%lx\n\t"
233 "rnc_suspend_count=%d, rnc.suspend_count=%d "
234 "RNC: current state %s, current "
235 "suspend_type %x dest state %d;\n"
236 "ireq=%p, ireq->flags = %lx\n",
240 rnc_suspend_count, idev->
rnc.suspend_count,
242 idev->
rnc.suspend_type,
243 idev->
rnc.destination_state,
250 spin_unlock_irqrestore(&ihost->
scic_lock, flags);
254 spin_unlock_irqrestore(&ihost->
scic_lock, flags);
256 isci_check_devempty(ihost, idev,
261 __func__, ihost->
id);
263 "%s: ******* Timeout waiting for "
264 "suspend; idev=%p, current state %s; "
265 "started_request_count=%d, flags=%lx\n\t"
266 "rnc_suspend_count=%d, "
267 "RNC: current state %s, "
268 "rnc.suspend_count=%d, current "
269 "suspend_type %x dest state %d\n",
275 idev->
rnc.suspend_count,
276 idev->
rnc.suspend_type,
277 idev->
rnc.destination_state);
280 dev_dbg(&ihost->
pdev->dev,
"%s: idev=%p, wait done\n",
282 isci_put_device(idev);
296 static void isci_remote_device_not_ready(
struct isci_host *ihost,
301 "%s: isci_device = %p; reason = %d\n", __func__, idev, reason);
323 static void rnc_destruct_done(
void *_dev)
334 return sci_remote_device_terminate_reqs_checkabort(idev, 0);
344 case SCI_DEV_INITIAL:
348 dev_warn(scirdev_to_dev(idev),
"%s: in wrong state: %s\n",
351 case SCI_DEV_STOPPED:
353 case SCI_DEV_STARTING:
357 rnc_destruct_done, idev);
364 case SCI_STP_DEV_IDLE:
365 case SCI_STP_DEV_CMD:
366 case SCI_STP_DEV_NCQ:
367 case SCI_STP_DEV_NCQ_ERROR:
368 case SCI_STP_DEV_AWAIT_RESET:
369 case SCI_SMP_DEV_IDLE:
370 case SCI_SMP_DEV_CMD:
382 case SCI_DEV_STOPPING:
388 case SCI_DEV_RESETTING:
400 case SCI_DEV_INITIAL:
401 case SCI_DEV_STOPPED:
402 case SCI_DEV_STARTING:
403 case SCI_SMP_DEV_IDLE:
404 case SCI_SMP_DEV_CMD:
405 case SCI_DEV_STOPPING:
407 case SCI_DEV_RESETTING:
410 dev_warn(scirdev_to_dev(idev),
"%s: in wrong state: %s\n",
414 case SCI_STP_DEV_IDLE:
415 case SCI_STP_DEV_CMD:
416 case SCI_STP_DEV_NCQ:
417 case SCI_STP_DEV_NCQ_ERROR:
418 case SCI_STP_DEV_AWAIT_RESET:
429 if (state != SCI_DEV_RESETTING) {
430 dev_warn(scirdev_to_dev(idev),
"%s: in wrong state: %s\n",
448 case SCI_DEV_INITIAL:
449 case SCI_DEV_STOPPED:
450 case SCI_DEV_STARTING:
451 case SCI_STP_DEV_IDLE:
452 case SCI_SMP_DEV_IDLE:
455 dev_warn(scirdev_to_dev(idev),
"%s: in wrong state: %s\n",
461 case SCI_STP_DEV_NCQ_ERROR:
462 case SCI_STP_DEV_AWAIT_RESET:
463 case SCI_DEV_STOPPING:
465 case SCI_DEV_RESETTING: {
467 struct ssp_frame_hdr hdr;
477 word_cnt =
sizeof(
hdr) /
sizeof(
u32);
478 sci_swab32_cpy(&hdr, frame_header, word_cnt);
492 case SCI_STP_DEV_NCQ: {
521 case SCI_STP_DEV_CMD:
522 case SCI_SMP_DEV_CMD:
542 case SCI_STP_DEV_IDLE:
543 case SCI_STP_DEV_CMD:
544 case SCI_STP_DEV_NCQ:
545 case SCI_STP_DEV_NCQ_ERROR:
546 case SCI_STP_DEV_AWAIT_RESET:
547 case SCI_SMP_DEV_IDLE:
548 case SCI_SMP_DEV_CMD:
559 static void atapi_remote_device_resume_done(
void *_dev)
588 "%s: device: %p event code: %x: %s\n",
589 __func__, idev, event_code,
590 is_remote_device_ready(idev)
591 ?
"I_T_Nexus_Timeout event"
592 :
"I_T_Nexus_Timeout event in wrong state");
599 "%s: device: %p event code: %x: %s\n",
600 __func__, idev, event_code,
601 is_remote_device_ready(idev)
603 :
"unexpected event in wrong state");
615 if (state == SCI_STP_DEV_ATAPI_ERROR) {
620 atapi_remote_device_resume_done,
625 if (state == SCI_STP_DEV_IDLE) {
648 kref_get(&idev->
kref);
663 case SCI_DEV_INITIAL:
664 case SCI_DEV_STOPPED:
665 case SCI_DEV_STARTING:
666 case SCI_STP_DEV_NCQ_ERROR:
667 case SCI_DEV_STOPPING:
669 case SCI_DEV_RESETTING:
672 dev_warn(scirdev_to_dev(idev),
"%s: in wrong state: %s\n",
691 case SCI_STP_DEV_IDLE: {
716 new_state = SCI_STP_DEV_NCQ;
719 new_state = SCI_STP_DEV_CMD;
724 case SCI_STP_DEV_NCQ: {
741 case SCI_STP_DEV_AWAIT_RESET:
743 case SCI_SMP_DEV_IDLE:
759 case SCI_STP_DEV_CMD:
760 case SCI_SMP_DEV_CMD:
767 sci_remote_device_start_request(idev, ireq, status);
785 sci_remote_device_decrement_request_count(idev);
799 case SCI_DEV_INITIAL:
800 case SCI_DEV_STOPPED:
801 case SCI_DEV_STARTING:
802 case SCI_STP_DEV_IDLE:
803 case SCI_SMP_DEV_IDLE:
807 dev_warn(scirdev_to_dev(idev),
"%s: in wrong state: %s\n",
811 case SCI_STP_DEV_AWAIT_RESET:
812 case SCI_DEV_RESETTING:
813 status = common_complete_io(iport, idev, ireq);
815 case SCI_STP_DEV_CMD:
816 case SCI_STP_DEV_NCQ:
817 case SCI_STP_DEV_NCQ_ERROR:
818 case SCI_STP_DEV_ATAPI_ERROR:
819 status = common_complete_io(iport, idev, ireq);
833 case SCI_SMP_DEV_CMD:
834 status = common_complete_io(iport, idev, ireq);
839 case SCI_DEV_STOPPING:
840 status = common_complete_io(iport, idev, ireq);
853 "%s: Port:0x%p Device:0x%p Request:0x%p Status:0x%x "
854 "could not complete\n", __func__, iport,
857 isci_put_device(idev);
862 static void sci_remote_device_continue_request(
void *
dev)
881 case SCI_DEV_INITIAL:
882 case SCI_DEV_STOPPED:
883 case SCI_DEV_STARTING:
884 case SCI_SMP_DEV_IDLE:
885 case SCI_SMP_DEV_CMD:
886 case SCI_DEV_STOPPING:
888 case SCI_DEV_RESETTING:
891 dev_warn(scirdev_to_dev(idev),
"%s: in wrong state: %s\n",
894 case SCI_STP_DEV_IDLE:
895 case SCI_STP_DEV_CMD:
896 case SCI_STP_DEV_NCQ:
897 case SCI_STP_DEV_NCQ_ERROR:
898 case SCI_STP_DEV_AWAIT_RESET:
925 sci_remote_device_continue_request, idev);
928 sci_remote_device_start_request(idev, ireq, status);
948 sci_remote_device_start_request(idev, ireq, status);
961 idev->
rnc.remote_node_index;
970 static void remote_device_resume_done(
void *_dev)
974 if (is_remote_device_ready(idev))
981 static void sci_stp_remote_device_ready_idle_substate_resume_complete_handler(
void *_dev)
989 if (idev->
sm.previous_state_id != SCI_STP_DEV_NCQ)
990 isci_remote_device_ready(ihost, idev);
1020 if (state != SCI_DEV_STOPPED) {
1021 dev_warn(scirdev_to_dev(idev),
"%s: in wrong state: %s\n",
1028 idev->
rnc.remote_node_index);
1044 "%s: isci_device = %p\n", __func__, idev);
1052 sci_remote_device_destruct(idev);
1053 list_del_init(&idev->
node);
1054 isci_put_device(idev);
1066 prev_state = idev->
sm.previous_state_id;
1067 if (prev_state == SCI_DEV_STOPPING)
1068 isci_remote_device_deconstruct(ihost, idev);
1078 isci_remote_device_not_ready(ihost, idev,
1090 }
else if (dev_is_expander(dev)) {
1093 isci_remote_device_ready(ihost, idev);
1104 isci_remote_device_not_ready(ihost, idev,
1115 "%s: isci_device = %p\n", __func__, idev);
1126 "%s: isci_device = %p\n", __func__, idev);
1140 sci_stp_remote_device_ready_idle_substate_resume_complete_handler(idev);
1143 sci_stp_remote_device_ready_idle_substate_resume_complete_handler,
1155 isci_remote_device_not_ready(ihost, idev,
1165 isci_remote_device_not_ready(ihost, idev,
1174 isci_remote_device_ready(ihost, idev);
1184 isci_remote_device_not_ready(ihost, idev,
1195 static const struct sci_base_state sci_remote_device_state_table[] = {
1196 [SCI_DEV_INITIAL] = {
1197 .enter_state = sci_remote_device_initial_state_enter,
1199 [SCI_DEV_STOPPED] = {
1200 .enter_state = sci_remote_device_stopped_state_enter,
1202 [SCI_DEV_STARTING] = {
1203 .enter_state = sci_remote_device_starting_state_enter,
1206 .enter_state = sci_remote_device_ready_state_enter,
1207 .exit_state = sci_remote_device_ready_state_exit
1209 [SCI_STP_DEV_IDLE] = {
1210 .enter_state = sci_stp_remote_device_ready_idle_substate_enter,
1212 [SCI_STP_DEV_CMD] = {
1213 .enter_state = sci_stp_remote_device_ready_cmd_substate_enter,
1215 [SCI_STP_DEV_NCQ] = { },
1216 [SCI_STP_DEV_NCQ_ERROR] = {
1217 .enter_state = sci_stp_remote_device_ready_ncq_error_substate_enter,
1219 [SCI_STP_DEV_ATAPI_ERROR] = { },
1220 [SCI_STP_DEV_AWAIT_RESET] = { },
1221 [SCI_SMP_DEV_IDLE] = {
1222 .enter_state = sci_smp_remote_device_ready_idle_substate_enter,
1224 [SCI_SMP_DEV_CMD] = {
1225 .enter_state = sci_smp_remote_device_ready_cmd_substate_enter,
1226 .exit_state = sci_smp_remote_device_ready_cmd_substate_exit,
1228 [SCI_DEV_STOPPING] = { },
1229 [SCI_DEV_FAILED] = { },
1230 [SCI_DEV_RESETTING] = {
1231 .enter_state = sci_remote_device_resetting_state_enter,
1232 .exit_state = sci_remote_device_resetting_state_exit
1234 [SCI_DEV_FINAL] = { },
1247 static void sci_remote_device_construct(
struct isci_port *iport,
1253 sci_init_sm(&idev->
sm, sci_remote_device_state_table, SCI_DEV_INITIAL);
1279 sci_remote_device_construct(iport, idev);
1287 &idev->
rnc.remote_node_index);
1315 sci_remote_device_construct(iport, idev);
1319 &idev->
rnc.remote_node_index);
1348 dev_dbg(scirdev_to_dev(idev),
"%s: failed to resume: %d\n",
1353 static void isci_remote_device_resume_from_abort_complete(
void *cbparam)
1360 dev_dbg(scirdev_to_dev(idev),
"%s: passing-along resume: %p\n",
1361 __func__, abort_resume_cb);
1363 if (abort_resume_cb !=
NULL) {
1371 static bool isci_remote_device_test_resume_done(
1375 unsigned long flags;
1381 || sci_remote_node_context_is_being_destroyed(&idev->
rnc);
1382 spin_unlock_irqrestore(&ihost->
scic_lock, flags);
1391 dev_dbg(&ihost->
pdev->dev,
"%s: starting resume wait: %p\n",
1394 #define MAX_RESUME_MSECS 10000
1396 isci_remote_device_test_resume_done(ihost, idev),
1399 dev_warn(&ihost->
pdev->dev,
"%s: #### Timeout waiting for "
1400 "resume: %p\n", __func__, idev);
1404 dev_dbg(&ihost->
pdev->dev,
"%s: resume wait done: %p\n",
1412 unsigned long flags;
1424 destroyed = sci_remote_node_context_is_being_destroyed(&idev->
rnc);
1427 idev, isci_remote_device_resume_from_abort_complete,
1429 spin_unlock_irqrestore(&ihost->
scic_lock, flags);
1458 if (state != SCI_DEV_STOPPED) {
1459 dev_warn(scirdev_to_dev(idev),
"%s: in wrong state: %s\n",
1482 status = sci_remote_device_ea_construct(iport, idev);
1484 status = sci_remote_device_da_construct(iport, idev);
1487 dev_dbg(&ihost->
pdev->dev,
"%s: construct failed: %d\n",
1497 dev_warn(&ihost->
pdev->dev,
"remote device start failed: %d\n",
1523 if (i >= SCI_MAX_REMOTE_DEVICES) {
1527 if (
WARN_ONCE(!list_empty(&idev->
node),
"found non-idle remote device\n"))
1560 unsigned long flags;
1563 "%s: isci_device = %p\n", __func__, idev);
1571 spin_unlock_irqrestore(&ihost->
scic_lock, flags);
1577 wait_for_device_stop(ihost, idev);
1580 "%s: isci_device = %p, waiting done.\n", __func__, idev);
1593 struct isci_host *ihost = dev_to_ihost(dev);
1597 "%s: domain_device = %p, isci_device = %p, isci_port = %p\n",
1621 "%s: domain_device = %p\n", __func__, dev);
1626 isci_device = isci_remote_device_alloc(isci_host, isci_port);
1630 kref_init(&isci_device->
kref);
1631 INIT_LIST_HEAD(&isci_device->
node);
1639 status = isci_remote_device_construct(isci_port, isci_device);
1642 "%s: isci_device = %p\n",
1643 __func__, isci_device);
1649 isci_put_device(isci_device);
1653 wait_for_device_start(isci_host, isci_device);
1663 unsigned long flags;
1670 spin_unlock_irqrestore(&ihost->
scic_lock, flags);
1676 "%s: isci_remote_device_terminate_requests(%p) "
1678 __func__, idev, status);
1693 return sci_remote_device_terminate_reqs_checkabort(idev, 1);
1700 unsigned long flags;
1705 spin_unlock_irqrestore(&ihost->
scic_lock, flags);