2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (c) 2004-2008 Silicon Graphics, Inc. All Rights Reserved.
10 * Cross Partition Communication (XPC) partition support.
12 * This is the part of XPC that detects the presence/absence of
13 * other partitions. It provides a heartbeat and monitors the
14 * heartbeats of other partitions.
18 #include <linux/kernel.h>
19 #include <linux/sysctl.h>
20 #include <linux/cache.h>
21 #include <linux/mmzone.h>
22 #include <linux/nodemask.h>
23 #include <asm/uncached.h>
24 #include <asm/sn/intr.h>
25 #include <asm/sn/sn_sal.h>
26 #include <asm/sn/nodepda.h>
27 #include <asm/sn/addrs.h>
30 /* XPC is exiting flag */
33 /* SH_IPI_ACCESS shub register value on startup */
34 static u64 xpc_sh1_IPI_access;
35 static u64 xpc_sh2_IPI_access0;
36 static u64 xpc_sh2_IPI_access1;
37 static u64 xpc_sh2_IPI_access2;
38 static u64 xpc_sh2_IPI_access3;
40 /* original protection values for each node */
41 u64 xpc_prot_vec[MAX_NUMNODES];
43 /* this partition's reserved page pointers */
44 struct xpc_rsvd_page *xpc_rsvd_page;
45 static u64 *xpc_part_nasids;
46 static u64 *xpc_mach_nasids;
47 struct xpc_vars *xpc_vars;
48 struct xpc_vars_part *xpc_vars_part;
50 static int xp_nasid_mask_bytes; /* actual size in bytes of nasid mask */
51 static int xp_nasid_mask_words; /* actual size in words of nasid mask */
53 struct xpc_partition *xpc_partitions;
56 * Generic buffer used to store a local copy of portions of a remote
57 * partition's reserved page (either its header and part_nasids mask,
60 char *xpc_remote_copy_buffer;
61 void *xpc_remote_copy_buffer_base;
64 * Guarantee that the kmalloc'd memory is cacheline aligned.
67 xpc_kmalloc_cacheline_aligned(size_t size, gfp_t flags, void **base)
69 /* see if kmalloc will give us cachline aligned memory by default */
70 *base = kmalloc(size, flags);
74 if ((u64)*base == L1_CACHE_ALIGN((u64)*base))
79 /* nope, we'll have to do it ourselves */
80 *base = kmalloc(size + L1_CACHE_BYTES, flags);
84 return (void *)L1_CACHE_ALIGN((u64)*base);
88 * Given a nasid, get the physical address of the partition's reserved page
89 * for that nasid. This function returns 0 on any error.
92 xpc_get_rsvd_page_pa(int nasid)
97 u64 rp_pa = nasid; /* seed with nasid */
101 void *buf_base = NULL;
105 status = sn_partition_reserved_page_pa(buf, &cookie, &rp_pa,
108 dev_dbg(xpc_part, "SAL returned with status=%li, cookie="
109 "0x%016lx, address=0x%016lx, len=0x%016lx\n",
110 status, cookie, rp_pa, len);
112 if (status != SALRET_MORE_PASSES)
115 /* >>> L1_CACHE_ALIGN() is only a sn2-bte_copy requirement */
116 if (L1_CACHE_ALIGN(len) > buf_len) {
118 buf_len = L1_CACHE_ALIGN(len);
119 buf = (u64)xpc_kmalloc_cacheline_aligned(buf_len,
122 if (buf_base == NULL) {
123 dev_err(xpc_part, "unable to kmalloc "
124 "len=0x%016lx\n", buf_len);
125 status = SALRET_ERROR;
130 ret = xp_remote_memcpy((void *)buf, (void *)rp_pa, buf_len);
131 if (ret != xpSuccess) {
132 dev_dbg(xpc_part, "xp_remote_memcpy failed %d\n", ret);
133 status = SALRET_ERROR;
140 if (status != SALRET_OK)
143 dev_dbg(xpc_part, "reserved page at phys address 0x%016lx\n", rp_pa);
148 * Fill the partition reserved page with the information needed by
149 * other partitions to discover we are alive and establish initial
152 struct xpc_rsvd_page *
153 xpc_rsvd_page_init(void)
155 struct xpc_rsvd_page *rp;
157 u64 rp_pa, nasid_array = 0;
160 /* get the local reserved page's address */
163 rp_pa = xpc_get_rsvd_page_pa(cpuid_to_nasid(smp_processor_id()));
166 dev_err(xpc_part, "SAL failed to locate the reserved page\n");
169 rp = (struct xpc_rsvd_page *)__va(rp_pa);
171 if (rp->partid != sn_partition_id) {
172 dev_err(xpc_part, "the reserved page's partid of %d should be "
173 "%d\n", rp->partid, sn_partition_id);
177 rp->version = XPC_RP_VERSION;
179 /* establish the actual sizes of the nasid masks */
180 if (rp->SAL_version == 1) {
181 /* SAL_version 1 didn't set the nasids_size field */
182 rp->nasids_size = 128;
184 xp_nasid_mask_bytes = rp->nasids_size;
185 xp_nasid_mask_words = xp_nasid_mask_bytes / 8;
187 /* setup the pointers to the various items in the reserved page */
188 xpc_part_nasids = XPC_RP_PART_NASIDS(rp);
189 xpc_mach_nasids = XPC_RP_MACH_NASIDS(rp);
190 xpc_vars = XPC_RP_VARS(rp);
191 xpc_vars_part = XPC_RP_VARS_PART(rp);
194 * Before clearing xpc_vars, see if a page of AMOs had been previously
195 * allocated. If not we'll need to allocate one and set permissions
196 * so that cross-partition AMOs are allowed.
198 * The allocated AMO page needs MCA reporting to remain disabled after
199 * XPC has unloaded. To make this work, we keep a copy of the pointer
200 * to this page (i.e., amos_page) in the struct xpc_vars structure,
201 * which is pointed to by the reserved page, and re-use that saved copy
202 * on subsequent loads of XPC. This AMO page is never freed, and its
203 * memory protections are never restricted.
205 amos_page = xpc_vars->amos_page;
206 if (amos_page == NULL) {
207 amos_page = (AMO_t *)TO_AMO(uncached_alloc_page(0, 1));
208 if (amos_page == NULL) {
209 dev_err(xpc_part, "can't allocate page of AMOs\n");
214 * Open up AMO-R/W to cpu. This is done for Shub 1.1 systems
215 * when xpc_allow_IPI_ops() is called via xpc_hb_init().
217 if (!enable_shub_wars_1_1()) {
218 ret = sn_change_memprotect(ia64_tpa((u64)amos_page),
220 SN_MEMPROT_ACCESS_CLASS_1,
223 dev_err(xpc_part, "can't change memory "
225 uncached_free_page(__IA64_UNCACHED_OFFSET |
226 TO_PHYS((u64)amos_page), 1);
230 } else if (!IS_AMO_ADDRESS((u64)amos_page)) {
232 * EFI's XPBOOT can also set amos_page in the reserved page,
233 * but it happens to leave it as an uncached physical address
234 * and we need it to be an uncached virtual, so we'll have to
237 if (!IS_AMO_PHYS_ADDRESS((u64)amos_page)) {
238 dev_err(xpc_part, "previously used amos_page address "
239 "is bad = 0x%p\n", (void *)amos_page);
242 amos_page = (AMO_t *)TO_AMO((u64)amos_page);
246 memset(xpc_vars, 0, sizeof(struct xpc_vars));
248 xpc_vars->version = XPC_V_VERSION;
249 xpc_vars->act_nasid = cpuid_to_nasid(0);
250 xpc_vars->act_phys_cpuid = cpu_physical_id(0);
251 xpc_vars->vars_part_pa = __pa(xpc_vars_part);
252 xpc_vars->amos_page_pa = ia64_tpa((u64)amos_page);
253 xpc_vars->amos_page = amos_page; /* save for next load of XPC */
255 /* clear xpc_vars_part */
256 memset((u64 *)xpc_vars_part, 0, sizeof(struct xpc_vars_part) *
259 /* initialize the activate IRQ related AMO variables */
260 for (i = 0; i < xp_nasid_mask_words; i++)
261 (void)xpc_IPI_init(XPC_ACTIVATE_IRQ_AMOS + i);
263 /* initialize the engaged remote partitions related AMO variables */
264 (void)xpc_IPI_init(XPC_ENGAGED_PARTITIONS_AMO);
265 (void)xpc_IPI_init(XPC_DISENGAGE_REQUEST_AMO);
267 /* timestamp of when reserved page was setup by XPC */
268 rp->stamp = CURRENT_TIME;
271 * This signifies to the remote partition that our reserved
272 * page is initialized.
274 rp->vars_pa = __pa(xpc_vars);
280 * Change protections to allow IPI operations (and AMO operations on
284 xpc_allow_IPI_ops(void)
289 /* >>> Change SH_IPI_ACCESS code to use SAL call once it is available */
292 xpc_sh2_IPI_access0 =
293 (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS0));
294 xpc_sh2_IPI_access1 =
295 (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS1));
296 xpc_sh2_IPI_access2 =
297 (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS2));
298 xpc_sh2_IPI_access3 =
299 (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS3));
301 for_each_online_node(node) {
302 nasid = cnodeid_to_nasid(node);
303 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS0),
305 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS1),
307 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS2),
309 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS3),
315 (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH1_IPI_ACCESS));
317 for_each_online_node(node) {
318 nasid = cnodeid_to_nasid(node);
319 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH1_IPI_ACCESS),
323 * Since the BIST collides with memory operations on
324 * SHUB 1.1 sn_change_memprotect() cannot be used.
326 if (enable_shub_wars_1_1()) {
327 /* open up everything */
328 xpc_prot_vec[node] = (u64)HUB_L((u64 *)
331 SH1_MD_DQLP_MMR_DIR_PRIVEC0));
333 GLOBAL_MMR_ADDR(nasid,
334 SH1_MD_DQLP_MMR_DIR_PRIVEC0),
337 GLOBAL_MMR_ADDR(nasid,
338 SH1_MD_DQRP_MMR_DIR_PRIVEC0),
346 * Restrict protections to disallow IPI operations (and AMO operations on
350 xpc_restrict_IPI_ops(void)
355 /* >>> Change SH_IPI_ACCESS code to use SAL call once it is available */
359 for_each_online_node(node) {
360 nasid = cnodeid_to_nasid(node);
361 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS0),
362 xpc_sh2_IPI_access0);
363 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS1),
364 xpc_sh2_IPI_access1);
365 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS2),
366 xpc_sh2_IPI_access2);
367 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS3),
368 xpc_sh2_IPI_access3);
373 for_each_online_node(node) {
374 nasid = cnodeid_to_nasid(node);
375 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH1_IPI_ACCESS),
378 if (enable_shub_wars_1_1()) {
379 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid,
380 SH1_MD_DQLP_MMR_DIR_PRIVEC0),
382 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid,
383 SH1_MD_DQRP_MMR_DIR_PRIVEC0),
391 * At periodic intervals, scan through all active partitions and ensure
392 * their heartbeat is still active. If not, the partition is deactivated.
395 xpc_check_remote_hb(void)
397 struct xpc_vars *remote_vars;
398 struct xpc_partition *part;
402 remote_vars = (struct xpc_vars *)xpc_remote_copy_buffer;
404 for (partid = 0; partid < xp_max_npartitions; partid++) {
409 if (partid == sn_partition_id)
412 part = &xpc_partitions[partid];
414 if (part->act_state == XPC_P_INACTIVE ||
415 part->act_state == XPC_P_DEACTIVATING) {
419 /* pull the remote_hb cache line */
420 ret = xp_remote_memcpy(remote_vars,
421 (void *)part->remote_vars_pa,
423 if (ret != xpSuccess) {
424 XPC_DEACTIVATE_PARTITION(part, ret);
428 dev_dbg(xpc_part, "partid = %d, heartbeat = %ld, last_heartbeat"
429 " = %ld, heartbeat_offline = %ld, HB_mask = 0x%lx\n",
430 partid, remote_vars->heartbeat, part->last_heartbeat,
431 remote_vars->heartbeat_offline,
432 remote_vars->heartbeating_to_mask);
434 if (((remote_vars->heartbeat == part->last_heartbeat) &&
435 (remote_vars->heartbeat_offline == 0)) ||
436 !xpc_hb_allowed(sn_partition_id, remote_vars)) {
438 XPC_DEACTIVATE_PARTITION(part, xpNoHeartbeat);
442 part->last_heartbeat = remote_vars->heartbeat;
447 * Get a copy of a portion of the remote partition's rsvd page.
449 * remote_rp points to a buffer that is cacheline aligned for BTE copies and
450 * is large enough to contain a copy of their reserved page header and
453 static enum xp_retval
454 xpc_get_remote_rp(int nasid, u64 *discovered_nasids,
455 struct xpc_rsvd_page *remote_rp, u64 *remote_rp_pa)
460 /* get the reserved page's physical address */
462 *remote_rp_pa = xpc_get_rsvd_page_pa(nasid);
463 if (*remote_rp_pa == 0)
464 return xpNoRsvdPageAddr;
466 /* pull over the reserved page header and part_nasids mask */
467 ret = xp_remote_memcpy(remote_rp, (void *)*remote_rp_pa,
468 XPC_RP_HEADER_SIZE + xp_nasid_mask_bytes);
469 if (ret != xpSuccess)
472 if (discovered_nasids != NULL) {
473 u64 *remote_part_nasids = XPC_RP_PART_NASIDS(remote_rp);
475 for (i = 0; i < xp_nasid_mask_words; i++)
476 discovered_nasids[i] |= remote_part_nasids[i];
479 /* check that the partid is for another partition */
481 if (remote_rp->partid < 0 || remote_rp->partid >= xp_max_npartitions)
482 return xpInvalidPartid;
484 if (remote_rp->partid == sn_partition_id)
485 return xpLocalPartid;
487 if (XPC_VERSION_MAJOR(remote_rp->version) !=
488 XPC_VERSION_MAJOR(XPC_RP_VERSION)) {
496 * Get a copy of the remote partition's XPC variables from the reserved page.
498 * remote_vars points to a buffer that is cacheline aligned for BTE copies and
499 * assumed to be of size XPC_RP_VARS_SIZE.
501 static enum xp_retval
502 xpc_get_remote_vars(u64 remote_vars_pa, struct xpc_vars *remote_vars)
506 if (remote_vars_pa == 0)
509 /* pull over the cross partition variables */
510 ret = xp_remote_memcpy(remote_vars, (void *)remote_vars_pa,
512 if (ret != xpSuccess)
515 if (XPC_VERSION_MAJOR(remote_vars->version) !=
516 XPC_VERSION_MAJOR(XPC_V_VERSION)) {
524 * Update the remote partition's info.
527 xpc_update_partition_info(struct xpc_partition *part, u8 remote_rp_version,
528 struct timespec *remote_rp_stamp, u64 remote_rp_pa,
529 u64 remote_vars_pa, struct xpc_vars *remote_vars)
531 part->remote_rp_version = remote_rp_version;
532 dev_dbg(xpc_part, " remote_rp_version = 0x%016x\n",
533 part->remote_rp_version);
535 part->remote_rp_stamp = *remote_rp_stamp;
536 dev_dbg(xpc_part, " remote_rp_stamp (tv_sec = 0x%lx tv_nsec = 0x%lx\n",
537 part->remote_rp_stamp.tv_sec, part->remote_rp_stamp.tv_nsec);
539 part->remote_rp_pa = remote_rp_pa;
540 dev_dbg(xpc_part, " remote_rp_pa = 0x%016lx\n", part->remote_rp_pa);
542 part->remote_vars_pa = remote_vars_pa;
543 dev_dbg(xpc_part, " remote_vars_pa = 0x%016lx\n",
544 part->remote_vars_pa);
546 part->last_heartbeat = remote_vars->heartbeat;
547 dev_dbg(xpc_part, " last_heartbeat = 0x%016lx\n",
548 part->last_heartbeat);
550 part->remote_vars_part_pa = remote_vars->vars_part_pa;
551 dev_dbg(xpc_part, " remote_vars_part_pa = 0x%016lx\n",
552 part->remote_vars_part_pa);
554 part->remote_act_nasid = remote_vars->act_nasid;
555 dev_dbg(xpc_part, " remote_act_nasid = 0x%x\n",
556 part->remote_act_nasid);
558 part->remote_act_phys_cpuid = remote_vars->act_phys_cpuid;
559 dev_dbg(xpc_part, " remote_act_phys_cpuid = 0x%x\n",
560 part->remote_act_phys_cpuid);
562 part->remote_amos_page_pa = remote_vars->amos_page_pa;
563 dev_dbg(xpc_part, " remote_amos_page_pa = 0x%lx\n",
564 part->remote_amos_page_pa);
566 part->remote_vars_version = remote_vars->version;
567 dev_dbg(xpc_part, " remote_vars_version = 0x%x\n",
568 part->remote_vars_version);
572 * Prior code has determined the nasid which generated an IPI. Inspect
573 * that nasid to determine if its partition needs to be activated or
576 * A partition is consider "awaiting activation" if our partition
577 * flags indicate it is not active and it has a heartbeat. A
578 * partition is considered "awaiting deactivation" if our partition
579 * flags indicate it is active but it has no heartbeat or it is not
580 * sending its heartbeat to us.
582 * To determine the heartbeat, the remote nasid must have a properly
583 * initialized reserved page.
586 xpc_identify_act_IRQ_req(int nasid)
588 struct xpc_rsvd_page *remote_rp;
589 struct xpc_vars *remote_vars;
592 int remote_rp_version;
595 struct timespec remote_rp_stamp = { 0, 0 };
597 struct xpc_partition *part;
600 /* pull over the reserved page structure */
602 remote_rp = (struct xpc_rsvd_page *)xpc_remote_copy_buffer;
604 ret = xpc_get_remote_rp(nasid, NULL, remote_rp, &remote_rp_pa);
605 if (ret != xpSuccess) {
606 dev_warn(xpc_part, "unable to get reserved page from nasid %d, "
607 "which sent interrupt, reason=%d\n", nasid, ret);
611 remote_vars_pa = remote_rp->vars_pa;
612 remote_rp_version = remote_rp->version;
613 if (XPC_SUPPORTS_RP_STAMP(remote_rp_version))
614 remote_rp_stamp = remote_rp->stamp;
616 partid = remote_rp->partid;
617 part = &xpc_partitions[partid];
619 /* pull over the cross partition variables */
621 remote_vars = (struct xpc_vars *)xpc_remote_copy_buffer;
623 ret = xpc_get_remote_vars(remote_vars_pa, remote_vars);
624 if (ret != xpSuccess) {
626 dev_warn(xpc_part, "unable to get XPC variables from nasid %d, "
627 "which sent interrupt, reason=%d\n", nasid, ret);
629 XPC_DEACTIVATE_PARTITION(part, ret);
633 part->act_IRQ_rcvd++;
635 dev_dbg(xpc_part, "partid for nasid %d is %d; IRQs = %d; HB = "
636 "%ld:0x%lx\n", (int)nasid, (int)partid, part->act_IRQ_rcvd,
637 remote_vars->heartbeat, remote_vars->heartbeating_to_mask);
639 if (xpc_partition_disengaged(part) &&
640 part->act_state == XPC_P_INACTIVE) {
642 xpc_update_partition_info(part, remote_rp_version,
643 &remote_rp_stamp, remote_rp_pa,
644 remote_vars_pa, remote_vars);
646 if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version)) {
647 if (xpc_partition_disengage_requested(1UL << partid)) {
649 * Other side is waiting on us to disengage,
650 * even though we already have.
655 /* other side doesn't support disengage requests */
656 xpc_clear_partition_disengage_request(1UL << partid);
659 xpc_activate_partition(part);
663 DBUG_ON(part->remote_rp_version == 0);
664 DBUG_ON(part->remote_vars_version == 0);
666 if (!XPC_SUPPORTS_RP_STAMP(part->remote_rp_version)) {
667 DBUG_ON(XPC_SUPPORTS_DISENGAGE_REQUEST(part->
668 remote_vars_version));
670 if (!XPC_SUPPORTS_RP_STAMP(remote_rp_version)) {
671 DBUG_ON(XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->
673 /* see if the other side rebooted */
674 if (part->remote_amos_page_pa ==
675 remote_vars->amos_page_pa &&
676 xpc_hb_allowed(sn_partition_id, remote_vars)) {
677 /* doesn't look that way, so ignore the IPI */
683 * Other side rebooted and previous XPC didn't support the
684 * disengage request, so we don't need to do anything special.
687 xpc_update_partition_info(part, remote_rp_version,
688 &remote_rp_stamp, remote_rp_pa,
689 remote_vars_pa, remote_vars);
690 part->reactivate_nasid = nasid;
691 XPC_DEACTIVATE_PARTITION(part, xpReactivating);
695 DBUG_ON(!XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version));
697 if (!XPC_SUPPORTS_RP_STAMP(remote_rp_version)) {
698 DBUG_ON(!XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->version));
701 * Other side rebooted and previous XPC did support the
702 * disengage request, but the new one doesn't.
705 xpc_clear_partition_engaged(1UL << partid);
706 xpc_clear_partition_disengage_request(1UL << partid);
708 xpc_update_partition_info(part, remote_rp_version,
709 &remote_rp_stamp, remote_rp_pa,
710 remote_vars_pa, remote_vars);
714 DBUG_ON(!XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->version));
716 stamp_diff = xpc_compare_stamps(&part->remote_rp_stamp,
718 if (stamp_diff != 0) {
719 DBUG_ON(stamp_diff >= 0);
722 * Other side rebooted and the previous XPC did support
723 * the disengage request, as does the new one.
726 DBUG_ON(xpc_partition_engaged(1UL << partid));
727 DBUG_ON(xpc_partition_disengage_requested(1UL <<
730 xpc_update_partition_info(part, remote_rp_version,
732 remote_rp_pa, remote_vars_pa,
738 if (part->disengage_request_timeout > 0 &&
739 !xpc_partition_disengaged(part)) {
740 /* still waiting on other side to disengage from us */
745 part->reactivate_nasid = nasid;
746 XPC_DEACTIVATE_PARTITION(part, xpReactivating);
748 } else if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version) &&
749 xpc_partition_disengage_requested(1UL << partid)) {
750 XPC_DEACTIVATE_PARTITION(part, xpOtherGoingDown);
755 * Loop through the activation AMO variables and process any bits
756 * which are set. Each bit indicates a nasid sending a partition
757 * activation or deactivation request.
759 * Return #of IRQs detected.
762 xpc_identify_act_IRQ_sender(void)
766 u64 nasid; /* remote nasid */
767 int n_IRQs_detected = 0;
770 act_amos = xpc_vars->amos_page + XPC_ACTIVATE_IRQ_AMOS;
772 /* scan through act AMO variable looking for non-zero entries */
773 for (word = 0; word < xp_nasid_mask_words; word++) {
778 nasid_mask = xpc_IPI_receive(&act_amos[word]);
779 if (nasid_mask == 0) {
780 /* no IRQs from nasids in this variable */
784 dev_dbg(xpc_part, "AMO[%d] gave back 0x%lx\n", word,
788 * If this nasid has been added to the machine since
789 * our partition was reset, this will retain the
790 * remote nasid in our reserved pages machine mask.
791 * This is used in the event of module reload.
793 xpc_mach_nasids[word] |= nasid_mask;
795 /* locate the nasid(s) which sent interrupts */
797 for (bit = 0; bit < (8 * sizeof(u64)); bit++) {
798 if (nasid_mask & (1UL << bit)) {
800 nasid = XPC_NASID_FROM_W_B(word, bit);
801 dev_dbg(xpc_part, "interrupt from nasid %ld\n",
803 xpc_identify_act_IRQ_req(nasid);
807 return n_IRQs_detected;
811 * See if the other side has responded to a partition disengage request
815 xpc_partition_disengaged(struct xpc_partition *part)
817 short partid = XPC_PARTID(part);
820 disengaged = (xpc_partition_engaged(1UL << partid) == 0);
821 if (part->disengage_request_timeout) {
823 if (time_before(jiffies,
824 part->disengage_request_timeout)) {
825 /* timelimit hasn't been reached yet */
830 * Other side hasn't responded to our disengage
831 * request in a timely fashion, so assume it's dead.
834 dev_info(xpc_part, "disengage from remote partition %d "
835 "timed out\n", partid);
836 xpc_disengage_request_timedout = 1;
837 xpc_clear_partition_engaged(1UL << partid);
840 part->disengage_request_timeout = 0;
842 /* cancel the timer function, provided it's not us */
843 if (!in_interrupt()) {
844 del_singleshot_timer_sync(&part->
845 disengage_request_timer);
848 DBUG_ON(part->act_state != XPC_P_DEACTIVATING &&
849 part->act_state != XPC_P_INACTIVE);
850 if (part->act_state != XPC_P_INACTIVE)
851 xpc_wakeup_channel_mgr(part);
853 if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version))
854 xpc_cancel_partition_disengage_request(part);
860 * Mark specified partition as active.
863 xpc_mark_partition_active(struct xpc_partition *part)
865 unsigned long irq_flags;
868 dev_dbg(xpc_part, "setting partition %d to ACTIVE\n", XPC_PARTID(part));
870 spin_lock_irqsave(&part->act_lock, irq_flags);
871 if (part->act_state == XPC_P_ACTIVATING) {
872 part->act_state = XPC_P_ACTIVE;
875 DBUG_ON(part->reason == xpSuccess);
878 spin_unlock_irqrestore(&part->act_lock, irq_flags);
884 * Notify XPC that the partition is down.
887 xpc_deactivate_partition(const int line, struct xpc_partition *part,
888 enum xp_retval reason)
890 unsigned long irq_flags;
892 spin_lock_irqsave(&part->act_lock, irq_flags);
894 if (part->act_state == XPC_P_INACTIVE) {
895 XPC_SET_REASON(part, reason, line);
896 spin_unlock_irqrestore(&part->act_lock, irq_flags);
897 if (reason == xpReactivating) {
898 /* we interrupt ourselves to reactivate partition */
899 xpc_IPI_send_reactivate(part);
903 if (part->act_state == XPC_P_DEACTIVATING) {
904 if ((part->reason == xpUnloading && reason != xpUnloading) ||
905 reason == xpReactivating) {
906 XPC_SET_REASON(part, reason, line);
908 spin_unlock_irqrestore(&part->act_lock, irq_flags);
912 part->act_state = XPC_P_DEACTIVATING;
913 XPC_SET_REASON(part, reason, line);
915 spin_unlock_irqrestore(&part->act_lock, irq_flags);
917 if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version)) {
918 xpc_request_partition_disengage(part);
919 xpc_IPI_send_disengage(part);
921 /* set a timelimit on the disengage request */
922 part->disengage_request_timeout = jiffies +
923 (xpc_disengage_request_timelimit * HZ);
924 part->disengage_request_timer.expires =
925 part->disengage_request_timeout;
926 add_timer(&part->disengage_request_timer);
929 dev_dbg(xpc_part, "bringing partition %d down, reason = %d\n",
930 XPC_PARTID(part), reason);
932 xpc_partition_going_down(part, reason);
936 * Mark specified partition as inactive.
939 xpc_mark_partition_inactive(struct xpc_partition *part)
941 unsigned long irq_flags;
943 dev_dbg(xpc_part, "setting partition %d to INACTIVE\n",
946 spin_lock_irqsave(&part->act_lock, irq_flags);
947 part->act_state = XPC_P_INACTIVE;
948 spin_unlock_irqrestore(&part->act_lock, irq_flags);
949 part->remote_rp_pa = 0;
953 * SAL has provided a partition and machine mask. The partition mask
954 * contains a bit for each even nasid in our partition. The machine
955 * mask contains a bit for each even nasid in the entire machine.
957 * Using those two bit arrays, we can determine which nasids are
958 * known in the machine. Each should also have a reserved page
959 * initialized if they are available for partitioning.
964 void *remote_rp_base;
965 struct xpc_rsvd_page *remote_rp;
966 struct xpc_vars *remote_vars;
973 struct xpc_rsvd_page *rp;
975 struct xpc_partition *part;
976 u64 *discovered_nasids;
979 remote_rp = xpc_kmalloc_cacheline_aligned(XPC_RP_HEADER_SIZE +
981 GFP_KERNEL, &remote_rp_base);
982 if (remote_rp == NULL)
985 remote_vars = (struct xpc_vars *)remote_rp;
987 discovered_nasids = kzalloc(sizeof(u64) * xp_nasid_mask_words,
989 if (discovered_nasids == NULL) {
990 kfree(remote_rp_base);
994 rp = (struct xpc_rsvd_page *)xpc_rsvd_page;
997 * The term 'region' in this context refers to the minimum number of
998 * nodes that can comprise an access protection grouping. The access
999 * protection is in regards to memory, IOI and IPI.
1002 region_size = sn_region_size;
1004 switch (region_size) {
1012 DBUG_ON(!is_shub2());
1015 for (region = 0; region < max_regions; region++) {
1020 dev_dbg(xpc_part, "searching region %d\n", region);
1022 for (nasid = (region * region_size * 2);
1023 nasid < ((region + 1) * region_size * 2); nasid += 2) {
1028 dev_dbg(xpc_part, "checking nasid %d\n", nasid);
1030 if (XPC_NASID_IN_ARRAY(nasid, xpc_part_nasids)) {
1031 dev_dbg(xpc_part, "PROM indicates Nasid %d is "
1032 "part of the local partition; skipping "
1037 if (!(XPC_NASID_IN_ARRAY(nasid, xpc_mach_nasids))) {
1038 dev_dbg(xpc_part, "PROM indicates Nasid %d was "
1039 "not on Numa-Link network at reset\n",
1044 if (XPC_NASID_IN_ARRAY(nasid, discovered_nasids)) {
1045 dev_dbg(xpc_part, "Nasid %d is part of a "
1046 "partition which was previously "
1047 "discovered\n", nasid);
1051 /* pull over the reserved page structure */
1053 ret = xpc_get_remote_rp(nasid, discovered_nasids,
1054 remote_rp, &remote_rp_pa);
1055 if (ret != xpSuccess) {
1056 dev_dbg(xpc_part, "unable to get reserved page "
1057 "from nasid %d, reason=%d\n", nasid,
1060 if (ret == xpLocalPartid)
1066 remote_vars_pa = remote_rp->vars_pa;
1068 partid = remote_rp->partid;
1069 part = &xpc_partitions[partid];
1071 /* pull over the cross partition variables */
1073 ret = xpc_get_remote_vars(remote_vars_pa, remote_vars);
1074 if (ret != xpSuccess) {
1075 dev_dbg(xpc_part, "unable to get XPC variables "
1076 "from nasid %d, reason=%d\n", nasid,
1079 XPC_DEACTIVATE_PARTITION(part, ret);
1083 if (part->act_state != XPC_P_INACTIVE) {
1084 dev_dbg(xpc_part, "partition %d on nasid %d is "
1085 "already activating\n", partid, nasid);
1090 * Register the remote partition's AMOs with SAL so it
1091 * can handle and cleanup errors within that address
1092 * range should the remote partition go down. We don't
1093 * unregister this range because it is difficult to
1094 * tell when outstanding writes to the remote partition
1095 * are finished and thus when it is thus safe to
1096 * unregister. This should not result in wasted space
1097 * in the SAL xp_addr_region table because we should
1098 * get the same page for remote_act_amos_pa after
1099 * module reloads and system reboots.
1101 if (sn_register_xp_addr_region
1102 (remote_vars->amos_page_pa, PAGE_SIZE, 1) < 0) {
1104 "partition %d failed to "
1105 "register xp_addr region 0x%016lx\n",
1106 partid, remote_vars->amos_page_pa);
1108 XPC_SET_REASON(part, xpPhysAddrRegFailed,
1114 * The remote nasid is valid and available.
1115 * Send an interrupt to that nasid to notify
1116 * it that we are ready to begin activation.
1118 dev_dbg(xpc_part, "sending an interrupt to AMO 0x%lx, "
1119 "nasid %d, phys_cpuid 0x%x\n",
1120 remote_vars->amos_page_pa,
1121 remote_vars->act_nasid,
1122 remote_vars->act_phys_cpuid);
1124 if (XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->
1126 part->remote_amos_page_pa =
1127 remote_vars->amos_page_pa;
1128 xpc_mark_partition_disengaged(part);
1129 xpc_cancel_partition_disengage_request(part);
1131 xpc_IPI_send_activate(remote_vars);
1135 kfree(discovered_nasids);
1136 kfree(remote_rp_base);
1140 * Given a partid, get the nasids owned by that partition from the
1141 * remote partition's reserved page.
1144 xpc_initiate_partid_to_nasids(short partid, void *nasid_mask)
1146 struct xpc_partition *part;
1149 part = &xpc_partitions[partid];
1150 if (part->remote_rp_pa == 0)
1151 return xpPartitionDown;
1153 memset(nasid_mask, 0, XP_NASID_MASK_BYTES);
1155 part_nasid_pa = (u64)XPC_RP_PART_NASIDS(part->remote_rp_pa);
1157 return xp_remote_memcpy(nasid_mask, (void *)part_nasid_pa,
1158 xp_nasid_mask_bytes);