aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc/sgi-xp/xpc_partition.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/misc/sgi-xp/xpc_partition.c')
-rw-r--r--drivers/misc/sgi-xp/xpc_partition.c454
1 files changed, 6 insertions, 448 deletions
diff --git a/drivers/misc/sgi-xp/xpc_partition.c b/drivers/misc/sgi-xp/xpc_partition.c
index be5b7547dab4..4e14effdeddb 100644
--- a/drivers/misc/sgi-xp/xpc_partition.c
+++ b/drivers/misc/sgi-xp/xpc_partition.c
@@ -42,7 +42,7 @@ u64 xpc_prot_vec[MAX_NUMNODES];
42/* this partition's reserved page pointers */ 42/* this partition's reserved page pointers */
43struct xpc_rsvd_page *xpc_rsvd_page; 43struct xpc_rsvd_page *xpc_rsvd_page;
44static u64 *xpc_part_nasids; 44static u64 *xpc_part_nasids;
45static u64 *xpc_mach_nasids; 45u64 *xpc_mach_nasids;
46 46
47/* >>> next two variables should be 'xpc_' if they remain here */ 47/* >>> next two variables should be 'xpc_' if they remain here */
48static int xp_sizeof_nasid_mask; /* actual size in bytes of nasid mask */ 48static int xp_sizeof_nasid_mask; /* actual size in bytes of nasid mask */
@@ -318,69 +318,13 @@ xpc_restrict_IPI_ops(void)
318} 318}
319 319
320/* 320/*
321 * At periodic intervals, scan through all active partitions and ensure
322 * their heartbeat is still active. If not, the partition is deactivated.
323 */
324void
325xpc_check_remote_hb(void)
326{
327 struct xpc_vars *remote_vars;
328 struct xpc_partition *part;
329 short partid;
330 enum xp_retval ret;
331
332 remote_vars = (struct xpc_vars *)xpc_remote_copy_buffer;
333
334 for (partid = 0; partid < xp_max_npartitions; partid++) {
335
336 if (xpc_exiting)
337 break;
338
339 if (partid == sn_partition_id)
340 continue;
341
342 part = &xpc_partitions[partid];
343
344 if (part->act_state == XPC_P_INACTIVE ||
345 part->act_state == XPC_P_DEACTIVATING) {
346 continue;
347 }
348
349 /* pull the remote_hb cache line */
350 ret = xp_remote_memcpy(remote_vars,
351 (void *)part->remote_vars_pa,
352 XPC_RP_VARS_SIZE);
353 if (ret != xpSuccess) {
354 XPC_DEACTIVATE_PARTITION(part, ret);
355 continue;
356 }
357
358 dev_dbg(xpc_part, "partid = %d, heartbeat = %ld, last_heartbeat"
359 " = %ld, heartbeat_offline = %ld, HB_mask = 0x%lx\n",
360 partid, remote_vars->heartbeat, part->last_heartbeat,
361 remote_vars->heartbeat_offline,
362 remote_vars->heartbeating_to_mask);
363
364 if (((remote_vars->heartbeat == part->last_heartbeat) &&
365 (remote_vars->heartbeat_offline == 0)) ||
366 !xpc_hb_allowed(sn_partition_id, remote_vars)) {
367
368 XPC_DEACTIVATE_PARTITION(part, xpNoHeartbeat);
369 continue;
370 }
371
372 part->last_heartbeat = remote_vars->heartbeat;
373 }
374}
375
376/*
377 * Get a copy of a portion of the remote partition's rsvd page. 321 * Get a copy of a portion of the remote partition's rsvd page.
378 * 322 *
379 * remote_rp points to a buffer that is cacheline aligned for BTE copies and 323 * remote_rp points to a buffer that is cacheline aligned for BTE copies and
380 * is large enough to contain a copy of their reserved page header and 324 * is large enough to contain a copy of their reserved page header and
381 * part_nasids mask. 325 * part_nasids mask.
382 */ 326 */
383static enum xp_retval 327enum xp_retval
384xpc_get_remote_rp(int nasid, u64 *discovered_nasids, 328xpc_get_remote_rp(int nasid, u64 *discovered_nasids,
385 struct xpc_rsvd_page *remote_rp, u64 *remote_rp_pa) 329 struct xpc_rsvd_page *remote_rp, u64 *remote_rp_pa)
386{ 330{
@@ -432,322 +376,6 @@ xpc_get_remote_rp(int nasid, u64 *discovered_nasids,
432} 376}
433 377
434/* 378/*
435 * Get a copy of the remote partition's XPC variables from the reserved page.
436 *
437 * remote_vars points to a buffer that is cacheline aligned for BTE copies and
438 * assumed to be of size XPC_RP_VARS_SIZE.
439 */
440static enum xp_retval
441xpc_get_remote_vars(u64 remote_vars_pa, struct xpc_vars *remote_vars)
442{
443 enum xp_retval ret;
444
445 if (remote_vars_pa == 0)
446 return xpVarsNotSet;
447
448 /* pull over the cross partition variables */
449 ret = xp_remote_memcpy(remote_vars, (void *)remote_vars_pa,
450 XPC_RP_VARS_SIZE);
451 if (ret != xpSuccess)
452 return ret;
453
454 if (XPC_VERSION_MAJOR(remote_vars->version) !=
455 XPC_VERSION_MAJOR(XPC_V_VERSION)) {
456 return xpBadVersion;
457 }
458
459 return xpSuccess;
460}
461
462/*
463 * Update the remote partition's info.
464 */
465static void
466xpc_update_partition_info(struct xpc_partition *part, u8 remote_rp_version,
467 struct timespec *remote_rp_stamp, u64 remote_rp_pa,
468 u64 remote_vars_pa, struct xpc_vars *remote_vars)
469{
470 part->remote_rp_version = remote_rp_version;
471 dev_dbg(xpc_part, " remote_rp_version = 0x%016x\n",
472 part->remote_rp_version);
473
474 part->remote_rp_stamp = *remote_rp_stamp;
475 dev_dbg(xpc_part, " remote_rp_stamp (tv_sec = 0x%lx tv_nsec = 0x%lx\n",
476 part->remote_rp_stamp.tv_sec, part->remote_rp_stamp.tv_nsec);
477
478 part->remote_rp_pa = remote_rp_pa;
479 dev_dbg(xpc_part, " remote_rp_pa = 0x%016lx\n", part->remote_rp_pa);
480
481 part->remote_vars_pa = remote_vars_pa;
482 dev_dbg(xpc_part, " remote_vars_pa = 0x%016lx\n",
483 part->remote_vars_pa);
484
485 part->last_heartbeat = remote_vars->heartbeat;
486 dev_dbg(xpc_part, " last_heartbeat = 0x%016lx\n",
487 part->last_heartbeat);
488
489/* >>> remote_vars_part_pa and vars_part_pa are sn2 only!!! */
490 part->remote_vars_part_pa = remote_vars->vars_part_pa;
491 dev_dbg(xpc_part, " remote_vars_part_pa = 0x%016lx\n",
492 part->remote_vars_part_pa);
493
494 part->remote_act_nasid = remote_vars->act_nasid;
495 dev_dbg(xpc_part, " remote_act_nasid = 0x%x\n",
496 part->remote_act_nasid);
497
498 part->remote_act_phys_cpuid = remote_vars->act_phys_cpuid;
499 dev_dbg(xpc_part, " remote_act_phys_cpuid = 0x%x\n",
500 part->remote_act_phys_cpuid);
501
502 part->remote_amos_page_pa = remote_vars->amos_page_pa;
503 dev_dbg(xpc_part, " remote_amos_page_pa = 0x%lx\n",
504 part->remote_amos_page_pa);
505
506 part->remote_vars_version = remote_vars->version;
507 dev_dbg(xpc_part, " remote_vars_version = 0x%x\n",
508 part->remote_vars_version);
509}
510
511/*
512 * Prior code has determined the nasid which generated an IPI. Inspect
513 * that nasid to determine if its partition needs to be activated or
514 * deactivated.
515 *
516 * A partition is consider "awaiting activation" if our partition
517 * flags indicate it is not active and it has a heartbeat. A
518 * partition is considered "awaiting deactivation" if our partition
519 * flags indicate it is active but it has no heartbeat or it is not
520 * sending its heartbeat to us.
521 *
522 * To determine the heartbeat, the remote nasid must have a properly
523 * initialized reserved page.
524 */
525static void
526xpc_identify_act_IRQ_req(int nasid)
527{
528 struct xpc_rsvd_page *remote_rp;
529 struct xpc_vars *remote_vars;
530 u64 remote_rp_pa;
531 u64 remote_vars_pa;
532 int remote_rp_version;
533 int reactivate = 0;
534 int stamp_diff;
535 struct timespec remote_rp_stamp = { 0, 0 }; /*>>> ZERO_STAMP */
536 short partid;
537 struct xpc_partition *part;
538 enum xp_retval ret;
539
540 /* pull over the reserved page structure */
541
542 remote_rp = (struct xpc_rsvd_page *)xpc_remote_copy_buffer;
543
544 ret = xpc_get_remote_rp(nasid, NULL, remote_rp, &remote_rp_pa);
545 if (ret != xpSuccess) {
546 dev_warn(xpc_part, "unable to get reserved page from nasid %d, "
547 "which sent interrupt, reason=%d\n", nasid, ret);
548 return;
549 }
550
551 remote_vars_pa = remote_rp->sn.vars_pa;
552 remote_rp_version = remote_rp->version;
553 if (XPC_SUPPORTS_RP_STAMP(remote_rp_version))
554 remote_rp_stamp = remote_rp->stamp;
555
556 partid = remote_rp->SAL_partid;
557 part = &xpc_partitions[partid];
558
559 /* pull over the cross partition variables */
560
561 remote_vars = (struct xpc_vars *)xpc_remote_copy_buffer;
562
563 ret = xpc_get_remote_vars(remote_vars_pa, remote_vars);
564 if (ret != xpSuccess) {
565
566 dev_warn(xpc_part, "unable to get XPC variables from nasid %d, "
567 "which sent interrupt, reason=%d\n", nasid, ret);
568
569 XPC_DEACTIVATE_PARTITION(part, ret);
570 return;
571 }
572
573 part->act_IRQ_rcvd++;
574
575 dev_dbg(xpc_part, "partid for nasid %d is %d; IRQs = %d; HB = "
576 "%ld:0x%lx\n", (int)nasid, (int)partid, part->act_IRQ_rcvd,
577 remote_vars->heartbeat, remote_vars->heartbeating_to_mask);
578
579 if (xpc_partition_disengaged(part) &&
580 part->act_state == XPC_P_INACTIVE) {
581
582 xpc_update_partition_info(part, remote_rp_version,
583 &remote_rp_stamp, remote_rp_pa,
584 remote_vars_pa, remote_vars);
585
586 if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version)) {
587 if (xpc_partition_disengage_requested(1UL << partid)) {
588 /*
589 * Other side is waiting on us to disengage,
590 * even though we already have.
591 */
592 return;
593 }
594 } else {
595 /* other side doesn't support disengage requests */
596 xpc_clear_partition_disengage_request(1UL << partid);
597 }
598
599 xpc_activate_partition(part);
600 return;
601 }
602
603 DBUG_ON(part->remote_rp_version == 0);
604 DBUG_ON(part->remote_vars_version == 0);
605
606 if (!XPC_SUPPORTS_RP_STAMP(part->remote_rp_version)) {
607 DBUG_ON(XPC_SUPPORTS_DISENGAGE_REQUEST(part->
608 remote_vars_version));
609
610 if (!XPC_SUPPORTS_RP_STAMP(remote_rp_version)) {
611 DBUG_ON(XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->
612 version));
613 /* see if the other side rebooted */
614 if (part->remote_amos_page_pa ==
615 remote_vars->amos_page_pa &&
616 xpc_hb_allowed(sn_partition_id, remote_vars)) {
617 /* doesn't look that way, so ignore the IPI */
618 return;
619 }
620 }
621
622 /*
623 * Other side rebooted and previous XPC didn't support the
624 * disengage request, so we don't need to do anything special.
625 */
626
627 xpc_update_partition_info(part, remote_rp_version,
628 &remote_rp_stamp, remote_rp_pa,
629 remote_vars_pa, remote_vars);
630 part->reactivate_nasid = nasid;
631 XPC_DEACTIVATE_PARTITION(part, xpReactivating);
632 return;
633 }
634
635 DBUG_ON(!XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version));
636
637 if (!XPC_SUPPORTS_RP_STAMP(remote_rp_version)) {
638 DBUG_ON(!XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->version));
639
640 /*
641 * Other side rebooted and previous XPC did support the
642 * disengage request, but the new one doesn't.
643 */
644
645 xpc_clear_partition_engaged(1UL << partid);
646 xpc_clear_partition_disengage_request(1UL << partid);
647
648 xpc_update_partition_info(part, remote_rp_version,
649 &remote_rp_stamp, remote_rp_pa,
650 remote_vars_pa, remote_vars);
651 reactivate = 1;
652
653 } else {
654 DBUG_ON(!XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->version));
655
656 stamp_diff = xpc_compare_stamps(&part->remote_rp_stamp,
657 &remote_rp_stamp);
658 if (stamp_diff != 0) {
659 DBUG_ON(stamp_diff >= 0);
660
661 /*
662 * Other side rebooted and the previous XPC did support
663 * the disengage request, as does the new one.
664 */
665
666 DBUG_ON(xpc_partition_engaged(1UL << partid));
667 DBUG_ON(xpc_partition_disengage_requested(1UL <<
668 partid));
669
670 xpc_update_partition_info(part, remote_rp_version,
671 &remote_rp_stamp,
672 remote_rp_pa, remote_vars_pa,
673 remote_vars);
674 reactivate = 1;
675 }
676 }
677
678 if (part->disengage_request_timeout > 0 &&
679 !xpc_partition_disengaged(part)) {
680 /* still waiting on other side to disengage from us */
681 return;
682 }
683
684 if (reactivate) {
685 part->reactivate_nasid = nasid;
686 XPC_DEACTIVATE_PARTITION(part, xpReactivating);
687
688 } else if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version) &&
689 xpc_partition_disengage_requested(1UL << partid)) {
690 XPC_DEACTIVATE_PARTITION(part, xpOtherGoingDown);
691 }
692}
693
694/*
695 * Loop through the activation AMO variables and process any bits
696 * which are set. Each bit indicates a nasid sending a partition
697 * activation or deactivation request.
698 *
699 * Return #of IRQs detected.
700 */
701int
702xpc_identify_act_IRQ_sender(void)
703{
704 int word, bit;
705 u64 nasid_mask;
706 u64 nasid; /* remote nasid */
707 int n_IRQs_detected = 0;
708 AMO_t *act_amos;
709
710 act_amos = xpc_vars->amos_page + XPC_ACTIVATE_IRQ_AMOS;
711
712 /* scan through act AMO variable looking for non-zero entries */
713 for (word = 0; word < xp_nasid_mask_words; word++) {
714
715 if (xpc_exiting)
716 break;
717
718 nasid_mask = xpc_IPI_receive(&act_amos[word]);
719 if (nasid_mask == 0) {
720 /* no IRQs from nasids in this variable */
721 continue;
722 }
723
724 dev_dbg(xpc_part, "AMO[%d] gave back 0x%lx\n", word,
725 nasid_mask);
726
727 /*
728 * If this nasid has been added to the machine since
729 * our partition was reset, this will retain the
730 * remote nasid in our reserved pages machine mask.
731 * This is used in the event of module reload.
732 */
733 xpc_mach_nasids[word] |= nasid_mask;
734
735 /* locate the nasid(s) which sent interrupts */
736
737 for (bit = 0; bit < (8 * sizeof(u64)); bit++) {
738 if (nasid_mask & (1UL << bit)) {
739 n_IRQs_detected++;
740 nasid = XPC_NASID_FROM_W_B(word, bit);
741 dev_dbg(xpc_part, "interrupt from nasid %ld\n",
742 nasid);
743 xpc_identify_act_IRQ_req(nasid);
744 }
745 }
746 }
747 return n_IRQs_detected;
748}
749
750/*
751 * See if the other side has responded to a partition disengage request 379 * See if the other side has responded to a partition disengage request
752 * from us. 380 * from us.
753 */ 381 */
@@ -836,7 +464,7 @@ xpc_deactivate_partition(const int line, struct xpc_partition *part,
836 spin_unlock_irqrestore(&part->act_lock, irq_flags); 464 spin_unlock_irqrestore(&part->act_lock, irq_flags);
837 if (reason == xpReactivating) { 465 if (reason == xpReactivating) {
838 /* we interrupt ourselves to reactivate partition */ 466 /* we interrupt ourselves to reactivate partition */
839 xpc_IPI_send_reactivate(part); 467 xpc_IPI_send_local_reactivate(part->reactivate_nasid);
840 } 468 }
841 return; 469 return;
842 } 470 }
@@ -903,16 +531,12 @@ xpc_discovery(void)
903{ 531{
904 void *remote_rp_base; 532 void *remote_rp_base;
905 struct xpc_rsvd_page *remote_rp; 533 struct xpc_rsvd_page *remote_rp;
906 struct xpc_vars *remote_vars;
907 u64 remote_rp_pa; 534 u64 remote_rp_pa;
908 u64 remote_vars_pa;
909 int region; 535 int region;
910 int region_size; 536 int region_size;
911 int max_regions; 537 int max_regions;
912 int nasid; 538 int nasid;
913 struct xpc_rsvd_page *rp; 539 struct xpc_rsvd_page *rp;
914 short partid;
915 struct xpc_partition *part;
916 u64 *discovered_nasids; 540 u64 *discovered_nasids;
917 enum xp_retval ret; 541 enum xp_retval ret;
918 542
@@ -922,8 +546,6 @@ xpc_discovery(void)
922 if (remote_rp == NULL) 546 if (remote_rp == NULL)
923 return; 547 return;
924 548
925 remote_vars = (struct xpc_vars *)remote_rp;
926
927 discovered_nasids = kzalloc(sizeof(u64) * xp_nasid_mask_words, 549 discovered_nasids = kzalloc(sizeof(u64) * xp_nasid_mask_words,
928 GFP_KERNEL); 550 GFP_KERNEL);
929 if (discovered_nasids == NULL) { 551 if (discovered_nasids == NULL) {
@@ -988,7 +610,7 @@ xpc_discovery(void)
988 continue; 610 continue;
989 } 611 }
990 612
991 /* pull over the reserved page structure */ 613 /* pull over the rsvd page header & part_nasids mask */
992 614
993 ret = xpc_get_remote_rp(nasid, discovered_nasids, 615 ret = xpc_get_remote_rp(nasid, discovered_nasids,
994 remote_rp, &remote_rp_pa); 616 remote_rp, &remote_rp_pa);
@@ -1003,72 +625,8 @@ xpc_discovery(void)
1003 continue; 625 continue;
1004 } 626 }
1005 627
1006 remote_vars_pa = remote_rp->sn.vars_pa; 628 xpc_initiate_partition_activation(remote_rp,
1007 629 remote_rp_pa, nasid);
1008 partid = remote_rp->SAL_partid;
1009 part = &xpc_partitions[partid];
1010
1011 /* pull over the cross partition variables */
1012
1013 ret = xpc_get_remote_vars(remote_vars_pa, remote_vars);
1014 if (ret != xpSuccess) {
1015 dev_dbg(xpc_part, "unable to get XPC variables "
1016 "from nasid %d, reason=%d\n", nasid,
1017 ret);
1018
1019 XPC_DEACTIVATE_PARTITION(part, ret);
1020 continue;
1021 }
1022
1023 if (part->act_state != XPC_P_INACTIVE) {
1024 dev_dbg(xpc_part, "partition %d on nasid %d is "
1025 "already activating\n", partid, nasid);
1026 break;
1027 }
1028
1029 /*
1030 * Register the remote partition's AMOs with SAL so it
1031 * can handle and cleanup errors within that address
1032 * range should the remote partition go down. We don't
1033 * unregister this range because it is difficult to
1034 * tell when outstanding writes to the remote partition
1035 * are finished and thus when it is thus safe to
1036 * unregister. This should not result in wasted space
1037 * in the SAL xp_addr_region table because we should
1038 * get the same page for remote_act_amos_pa after
1039 * module reloads and system reboots.
1040 */
1041 if (sn_register_xp_addr_region
1042 (remote_vars->amos_page_pa, PAGE_SIZE, 1) < 0) {
1043 dev_dbg(xpc_part,
1044 "partition %d failed to "
1045 "register xp_addr region 0x%016lx\n",
1046 partid, remote_vars->amos_page_pa);
1047
1048 XPC_SET_REASON(part, xpPhysAddrRegFailed,
1049 __LINE__);
1050 break;
1051 }
1052
1053 /*
1054 * The remote nasid is valid and available.
1055 * Send an interrupt to that nasid to notify
1056 * it that we are ready to begin activation.
1057 */
1058 dev_dbg(xpc_part, "sending an interrupt to AMO 0x%lx, "
1059 "nasid %d, phys_cpuid 0x%x\n",
1060 remote_vars->amos_page_pa,
1061 remote_vars->act_nasid,
1062 remote_vars->act_phys_cpuid);
1063
1064 if (XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->
1065 version)) {
1066 part->remote_amos_page_pa =
1067 remote_vars->amos_page_pa;
1068 xpc_mark_partition_disengaged(part);
1069 xpc_cancel_partition_disengage_request(part);
1070 }
1071 xpc_IPI_send_activate(remote_vars);
1072 } 630 }
1073 } 631 }
1074 632