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/bte.h>
25 #include <asm/sn/intr.h>
26 #include <asm/sn/sn_sal.h>
27 #include <asm/sn/nodepda.h>
28 #include <asm/sn/addrs.h>
31 /* XPC is exiting flag */
34 /* SH_IPI_ACCESS shub register value on startup */
35 static u64 xpc_sh1_IPI_access;
36 static u64 xpc_sh2_IPI_access0;
37 static u64 xpc_sh2_IPI_access1;
38 static u64 xpc_sh2_IPI_access2;
39 static u64 xpc_sh2_IPI_access3;
41 /* original protection values for each node */
42 u64 xpc_prot_vec[MAX_NUMNODES];
44 /* this partition's reserved page pointers */
45 struct xpc_rsvd_page *xpc_rsvd_page;
46 static u64 *xpc_part_nasids;
47 static u64 *xpc_mach_nasids;
48 struct xpc_vars *xpc_vars;
49 struct xpc_vars_part *xpc_vars_part;
51 static int xp_nasid_mask_bytes; /* actual size in bytes of nasid mask */
52 static int xp_nasid_mask_words; /* actual size in words of nasid mask */
54 struct xpc_partition *xpc_partitions;
57 * Generic buffer used to store a local copy of portions of a remote
58 * partition's reserved page (either its header and part_nasids mask,
61 char *xpc_remote_copy_buffer;
62 void *xpc_remote_copy_buffer_base;
65 * Guarantee that the kmalloc'd memory is cacheline aligned.
68 xpc_kmalloc_cacheline_aligned(size_t size, gfp_t flags, void **base)
70 /* see if kmalloc will give us cachline aligned memory by default */
71 *base = kmalloc(size, flags);
75 if ((u64)*base == L1_CACHE_ALIGN((u64)*base))
80 /* nope, we'll have to do it ourselves */
81 *base = kmalloc(size + L1_CACHE_BYTES, flags);
85 return (void *)L1_CACHE_ALIGN((u64)*base);
89 * Given a nasid, get the physical address of the partition's reserved page
90 * for that nasid. This function returns 0 on any error.
93 xpc_get_rsvd_page_pa(int nasid)
98 u64 rp_pa = nasid; /* seed with nasid */
102 void *buf_base = NULL;
106 status = sn_partition_reserved_page_pa(buf, &cookie, &rp_pa,
109 dev_dbg(xpc_part, "SAL returned with status=%li, cookie="
110 "0x%016lx, address=0x%016lx, len=0x%016lx\n",
111 status, cookie, rp_pa, len);
113 if (status != SALRET_MORE_PASSES)
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 bte_res = xp_bte_copy(rp_pa, buf, buf_len,
131 (BTE_NOTIFY | BTE_WACQUIRE), NULL);
132 if (bte_res != BTE_SUCCESS) {
133 dev_dbg(xpc_part, "xp_bte_copy failed %i\n", bte_res);
134 status = SALRET_ERROR;
141 if (status != SALRET_OK)
144 dev_dbg(xpc_part, "reserved page at phys address 0x%016lx\n", rp_pa);
149 * Fill the partition reserved page with the information needed by
150 * other partitions to discover we are alive and establish initial
153 struct xpc_rsvd_page *
154 xpc_rsvd_page_init(void)
156 struct xpc_rsvd_page *rp;
158 u64 rp_pa, nasid_array = 0;
161 /* get the local reserved page's address */
164 rp_pa = xpc_get_rsvd_page_pa(cpuid_to_nasid(smp_processor_id()));
167 dev_err(xpc_part, "SAL failed to locate the reserved page\n");
170 rp = (struct xpc_rsvd_page *)__va(rp_pa);
172 if (rp->partid != sn_partition_id) {
173 dev_err(xpc_part, "the reserved page's partid of %d should be "
174 "%d\n", rp->partid, sn_partition_id);
178 rp->version = XPC_RP_VERSION;
180 /* establish the actual sizes of the nasid masks */
181 if (rp->SAL_version == 1) {
182 /* SAL_version 1 didn't set the nasids_size field */
183 rp->nasids_size = 128;
185 xp_nasid_mask_bytes = rp->nasids_size;
186 xp_nasid_mask_words = xp_nasid_mask_bytes / 8;
188 /* setup the pointers to the various items in the reserved page */
189 xpc_part_nasids = XPC_RP_PART_NASIDS(rp);
190 xpc_mach_nasids = XPC_RP_MACH_NASIDS(rp);
191 xpc_vars = XPC_RP_VARS(rp);
192 xpc_vars_part = XPC_RP_VARS_PART(rp);
195 * Before clearing xpc_vars, see if a page of AMOs had been previously
196 * allocated. If not we'll need to allocate one and set permissions
197 * so that cross-partition AMOs are allowed.
199 * The allocated AMO page needs MCA reporting to remain disabled after
200 * XPC has unloaded. To make this work, we keep a copy of the pointer
201 * to this page (i.e., amos_page) in the struct xpc_vars structure,
202 * which is pointed to by the reserved page, and re-use that saved copy
203 * on subsequent loads of XPC. This AMO page is never freed, and its
204 * memory protections are never restricted.
206 amos_page = xpc_vars->amos_page;
207 if (amos_page == NULL) {
208 amos_page = (AMO_t *)TO_AMO(uncached_alloc_page(0, 1));
209 if (amos_page == NULL) {
210 dev_err(xpc_part, "can't allocate page of AMOs\n");
215 * Open up AMO-R/W to cpu. This is done for Shub 1.1 systems
216 * when xpc_allow_IPI_ops() is called via xpc_hb_init().
218 if (!enable_shub_wars_1_1()) {
219 ret = sn_change_memprotect(ia64_tpa((u64)amos_page),
221 SN_MEMPROT_ACCESS_CLASS_1,
224 dev_err(xpc_part, "can't change memory "
226 uncached_free_page(__IA64_UNCACHED_OFFSET |
227 TO_PHYS((u64)amos_page), 1);
231 } else if (!IS_AMO_ADDRESS((u64)amos_page)) {
233 * EFI's XPBOOT can also set amos_page in the reserved page,
234 * but it happens to leave it as an uncached physical address
235 * and we need it to be an uncached virtual, so we'll have to
238 if (!IS_AMO_PHYS_ADDRESS((u64)amos_page)) {
239 dev_err(xpc_part, "previously used amos_page address "
240 "is bad = 0x%p\n", (void *)amos_page);
243 amos_page = (AMO_t *)TO_AMO((u64)amos_page);
247 memset(xpc_vars, 0, sizeof(struct xpc_vars));
249 xpc_vars->version = XPC_V_VERSION;
250 xpc_vars->act_nasid = cpuid_to_nasid(0);
251 xpc_vars->act_phys_cpuid = cpu_physical_id(0);
252 xpc_vars->vars_part_pa = __pa(xpc_vars_part);
253 xpc_vars->amos_page_pa = ia64_tpa((u64)amos_page);
254 xpc_vars->amos_page = amos_page; /* save for next load of XPC */
256 /* clear xpc_vars_part */
257 memset((u64 *)xpc_vars_part, 0, sizeof(struct xpc_vars_part) *
260 /* initialize the activate IRQ related AMO variables */
261 for (i = 0; i < xp_nasid_mask_words; i++)
262 (void)xpc_IPI_init(XPC_ACTIVATE_IRQ_AMOS + i);
264 /* initialize the engaged remote partitions related AMO variables */
265 (void)xpc_IPI_init(XPC_ENGAGED_PARTITIONS_AMO);
266 (void)xpc_IPI_init(XPC_DISENGAGE_REQUEST_AMO);
268 /* timestamp of when reserved page was setup by XPC */
269 rp->stamp = CURRENT_TIME;
272 * This signifies to the remote partition that our reserved
273 * page is initialized.
275 rp->vars_pa = __pa(xpc_vars);
281 * Change protections to allow IPI operations (and AMO operations on
285 xpc_allow_IPI_ops(void)
290 /* >>> Change SH_IPI_ACCESS code to use SAL call once it is available */
293 xpc_sh2_IPI_access0 =
294 (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS0));
295 xpc_sh2_IPI_access1 =
296 (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS1));
297 xpc_sh2_IPI_access2 =
298 (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS2));
299 xpc_sh2_IPI_access3 =
300 (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS3));
302 for_each_online_node(node) {
303 nasid = cnodeid_to_nasid(node);
304 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS0),
306 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS1),
308 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS2),
310 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS3),
316 (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH1_IPI_ACCESS));
318 for_each_online_node(node) {
319 nasid = cnodeid_to_nasid(node);
320 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH1_IPI_ACCESS),
324 * Since the BIST collides with memory operations on
325 * SHUB 1.1 sn_change_memprotect() cannot be used.
327 if (enable_shub_wars_1_1()) {
328 /* open up everything */
329 xpc_prot_vec[node] = (u64)HUB_L((u64 *)
332 SH1_MD_DQLP_MMR_DIR_PRIVEC0));
334 GLOBAL_MMR_ADDR(nasid,
335 SH1_MD_DQLP_MMR_DIR_PRIVEC0),
338 GLOBAL_MMR_ADDR(nasid,
339 SH1_MD_DQRP_MMR_DIR_PRIVEC0),
347 * Restrict protections to disallow IPI operations (and AMO operations on
351 xpc_restrict_IPI_ops(void)
356 /* >>> Change SH_IPI_ACCESS code to use SAL call once it is available */
360 for_each_online_node(node) {
361 nasid = cnodeid_to_nasid(node);
362 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS0),
363 xpc_sh2_IPI_access0);
364 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS1),
365 xpc_sh2_IPI_access1);
366 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS2),
367 xpc_sh2_IPI_access2);
368 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS3),
369 xpc_sh2_IPI_access3);
374 for_each_online_node(node) {
375 nasid = cnodeid_to_nasid(node);
376 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH1_IPI_ACCESS),
379 if (enable_shub_wars_1_1()) {
380 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid,
381 SH1_MD_DQLP_MMR_DIR_PRIVEC0),
383 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid,
384 SH1_MD_DQRP_MMR_DIR_PRIVEC0),
392 * At periodic intervals, scan through all active partitions and ensure
393 * their heartbeat is still active. If not, the partition is deactivated.
396 xpc_check_remote_hb(void)
398 struct xpc_vars *remote_vars;
399 struct xpc_partition *part;
403 remote_vars = (struct xpc_vars *)xpc_remote_copy_buffer;
405 for (partid = 0; partid < xp_max_npartitions; partid++) {
410 if (partid == sn_partition_id)
413 part = &xpc_partitions[partid];
415 if (part->act_state == XPC_P_INACTIVE ||
416 part->act_state == XPC_P_DEACTIVATING) {
420 /* pull the remote_hb cache line */
421 bres = xp_bte_copy(part->remote_vars_pa,
424 (BTE_NOTIFY | BTE_WACQUIRE), NULL);
425 if (bres != BTE_SUCCESS) {
426 XPC_DEACTIVATE_PARTITION(part,
427 xpc_map_bte_errors(bres));
431 dev_dbg(xpc_part, "partid = %d, heartbeat = %ld, last_heartbeat"
432 " = %ld, heartbeat_offline = %ld, HB_mask = 0x%lx\n",
433 partid, remote_vars->heartbeat, part->last_heartbeat,
434 remote_vars->heartbeat_offline,
435 remote_vars->heartbeating_to_mask);
437 if (((remote_vars->heartbeat == part->last_heartbeat) &&
438 (remote_vars->heartbeat_offline == 0)) ||
439 !xpc_hb_allowed(sn_partition_id, remote_vars)) {
441 XPC_DEACTIVATE_PARTITION(part, xpNoHeartbeat);
445 part->last_heartbeat = remote_vars->heartbeat;
450 * Get a copy of a portion of the remote partition's rsvd page.
452 * remote_rp points to a buffer that is cacheline aligned for BTE copies and
453 * is large enough to contain a copy of their reserved page header and
456 static enum xp_retval
457 xpc_get_remote_rp(int nasid, u64 *discovered_nasids,
458 struct xpc_rsvd_page *remote_rp, u64 *remote_rp_pa)
462 /* get the reserved page's physical address */
464 *remote_rp_pa = xpc_get_rsvd_page_pa(nasid);
465 if (*remote_rp_pa == 0)
466 return xpNoRsvdPageAddr;
468 /* pull over the reserved page header and part_nasids mask */
469 bres = xp_bte_copy(*remote_rp_pa, (u64)remote_rp,
470 XPC_RP_HEADER_SIZE + xp_nasid_mask_bytes,
471 (BTE_NOTIFY | BTE_WACQUIRE), NULL);
472 if (bres != BTE_SUCCESS)
473 return xpc_map_bte_errors(bres);
475 if (discovered_nasids != NULL) {
476 u64 *remote_part_nasids = XPC_RP_PART_NASIDS(remote_rp);
478 for (i = 0; i < xp_nasid_mask_words; i++)
479 discovered_nasids[i] |= remote_part_nasids[i];
482 /* check that the partid is for another partition */
484 if (remote_rp->partid < 0 || remote_rp->partid >= xp_max_npartitions)
485 return xpInvalidPartid;
487 if (remote_rp->partid == sn_partition_id)
488 return xpLocalPartid;
490 if (XPC_VERSION_MAJOR(remote_rp->version) !=
491 XPC_VERSION_MAJOR(XPC_RP_VERSION)) {
499 * Get a copy of the remote partition's XPC variables from the reserved page.
501 * remote_vars points to a buffer that is cacheline aligned for BTE copies and
502 * assumed to be of size XPC_RP_VARS_SIZE.
504 static enum xp_retval
505 xpc_get_remote_vars(u64 remote_vars_pa, struct xpc_vars *remote_vars)
509 if (remote_vars_pa == 0)
512 /* pull over the cross partition variables */
513 bres = xp_bte_copy(remote_vars_pa, (u64)remote_vars, XPC_RP_VARS_SIZE,
514 (BTE_NOTIFY | BTE_WACQUIRE), NULL);
515 if (bres != BTE_SUCCESS)
516 return xpc_map_bte_errors(bres);
518 if (XPC_VERSION_MAJOR(remote_vars->version) !=
519 XPC_VERSION_MAJOR(XPC_V_VERSION)) {
527 * Update the remote partition's info.
530 xpc_update_partition_info(struct xpc_partition *part, u8 remote_rp_version,
531 struct timespec *remote_rp_stamp, u64 remote_rp_pa,
532 u64 remote_vars_pa, struct xpc_vars *remote_vars)
534 part->remote_rp_version = remote_rp_version;
535 dev_dbg(xpc_part, " remote_rp_version = 0x%016x\n",
536 part->remote_rp_version);
538 part->remote_rp_stamp = *remote_rp_stamp;
539 dev_dbg(xpc_part, " remote_rp_stamp (tv_sec = 0x%lx tv_nsec = 0x%lx\n",
540 part->remote_rp_stamp.tv_sec, part->remote_rp_stamp.tv_nsec);
542 part->remote_rp_pa = remote_rp_pa;
543 dev_dbg(xpc_part, " remote_rp_pa = 0x%016lx\n", part->remote_rp_pa);
545 part->remote_vars_pa = remote_vars_pa;
546 dev_dbg(xpc_part, " remote_vars_pa = 0x%016lx\n",
547 part->remote_vars_pa);
549 part->last_heartbeat = remote_vars->heartbeat;
550 dev_dbg(xpc_part, " last_heartbeat = 0x%016lx\n",
551 part->last_heartbeat);
553 part->remote_vars_part_pa = remote_vars->vars_part_pa;
554 dev_dbg(xpc_part, " remote_vars_part_pa = 0x%016lx\n",
555 part->remote_vars_part_pa);
557 part->remote_act_nasid = remote_vars->act_nasid;
558 dev_dbg(xpc_part, " remote_act_nasid = 0x%x\n",
559 part->remote_act_nasid);
561 part->remote_act_phys_cpuid = remote_vars->act_phys_cpuid;
562 dev_dbg(xpc_part, " remote_act_phys_cpuid = 0x%x\n",
563 part->remote_act_phys_cpuid);
565 part->remote_amos_page_pa = remote_vars->amos_page_pa;
566 dev_dbg(xpc_part, " remote_amos_page_pa = 0x%lx\n",
567 part->remote_amos_page_pa);
569 part->remote_vars_version = remote_vars->version;
570 dev_dbg(xpc_part, " remote_vars_version = 0x%x\n",
571 part->remote_vars_version);
575 * Prior code has determined the nasid which generated an IPI. Inspect
576 * that nasid to determine if its partition needs to be activated or
579 * A partition is consider "awaiting activation" if our partition
580 * flags indicate it is not active and it has a heartbeat. A
581 * partition is considered "awaiting deactivation" if our partition
582 * flags indicate it is active but it has no heartbeat or it is not
583 * sending its heartbeat to us.
585 * To determine the heartbeat, the remote nasid must have a properly
586 * initialized reserved page.
589 xpc_identify_act_IRQ_req(int nasid)
591 struct xpc_rsvd_page *remote_rp;
592 struct xpc_vars *remote_vars;
595 int remote_rp_version;
598 struct timespec remote_rp_stamp = { 0, 0 };
600 struct xpc_partition *part;
603 /* pull over the reserved page structure */
605 remote_rp = (struct xpc_rsvd_page *)xpc_remote_copy_buffer;
607 ret = xpc_get_remote_rp(nasid, NULL, remote_rp, &remote_rp_pa);
608 if (ret != xpSuccess) {
609 dev_warn(xpc_part, "unable to get reserved page from nasid %d, "
610 "which sent interrupt, reason=%d\n", nasid, ret);
614 remote_vars_pa = remote_rp->vars_pa;
615 remote_rp_version = remote_rp->version;
616 if (XPC_SUPPORTS_RP_STAMP(remote_rp_version))
617 remote_rp_stamp = remote_rp->stamp;
619 partid = remote_rp->partid;
620 part = &xpc_partitions[partid];
622 /* pull over the cross partition variables */
624 remote_vars = (struct xpc_vars *)xpc_remote_copy_buffer;
626 ret = xpc_get_remote_vars(remote_vars_pa, remote_vars);
627 if (ret != xpSuccess) {
629 dev_warn(xpc_part, "unable to get XPC variables from nasid %d, "
630 "which sent interrupt, reason=%d\n", nasid, ret);
632 XPC_DEACTIVATE_PARTITION(part, ret);
636 part->act_IRQ_rcvd++;
638 dev_dbg(xpc_part, "partid for nasid %d is %d; IRQs = %d; HB = "
639 "%ld:0x%lx\n", (int)nasid, (int)partid, part->act_IRQ_rcvd,
640 remote_vars->heartbeat, remote_vars->heartbeating_to_mask);
642 if (xpc_partition_disengaged(part) &&
643 part->act_state == XPC_P_INACTIVE) {
645 xpc_update_partition_info(part, remote_rp_version,
646 &remote_rp_stamp, remote_rp_pa,
647 remote_vars_pa, remote_vars);
649 if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version)) {
650 if (xpc_partition_disengage_requested(1UL << partid)) {
652 * Other side is waiting on us to disengage,
653 * even though we already have.
658 /* other side doesn't support disengage requests */
659 xpc_clear_partition_disengage_request(1UL << partid);
662 xpc_activate_partition(part);
666 DBUG_ON(part->remote_rp_version == 0);
667 DBUG_ON(part->remote_vars_version == 0);
669 if (!XPC_SUPPORTS_RP_STAMP(part->remote_rp_version)) {
670 DBUG_ON(XPC_SUPPORTS_DISENGAGE_REQUEST(part->
671 remote_vars_version));
673 if (!XPC_SUPPORTS_RP_STAMP(remote_rp_version)) {
674 DBUG_ON(XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->
676 /* see if the other side rebooted */
677 if (part->remote_amos_page_pa ==
678 remote_vars->amos_page_pa &&
679 xpc_hb_allowed(sn_partition_id, remote_vars)) {
680 /* doesn't look that way, so ignore the IPI */
686 * Other side rebooted and previous XPC didn't support the
687 * disengage request, so we don't need to do anything special.
690 xpc_update_partition_info(part, remote_rp_version,
691 &remote_rp_stamp, remote_rp_pa,
692 remote_vars_pa, remote_vars);
693 part->reactivate_nasid = nasid;
694 XPC_DEACTIVATE_PARTITION(part, xpReactivating);
698 DBUG_ON(!XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version));
700 if (!XPC_SUPPORTS_RP_STAMP(remote_rp_version)) {
701 DBUG_ON(!XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->version));
704 * Other side rebooted and previous XPC did support the
705 * disengage request, but the new one doesn't.
708 xpc_clear_partition_engaged(1UL << partid);
709 xpc_clear_partition_disengage_request(1UL << partid);
711 xpc_update_partition_info(part, remote_rp_version,
712 &remote_rp_stamp, remote_rp_pa,
713 remote_vars_pa, remote_vars);
717 DBUG_ON(!XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->version));
719 stamp_diff = xpc_compare_stamps(&part->remote_rp_stamp,
721 if (stamp_diff != 0) {
722 DBUG_ON(stamp_diff >= 0);
725 * Other side rebooted and the previous XPC did support
726 * the disengage request, as does the new one.
729 DBUG_ON(xpc_partition_engaged(1UL << partid));
730 DBUG_ON(xpc_partition_disengage_requested(1UL <<
733 xpc_update_partition_info(part, remote_rp_version,
735 remote_rp_pa, remote_vars_pa,
741 if (part->disengage_request_timeout > 0 &&
742 !xpc_partition_disengaged(part)) {
743 /* still waiting on other side to disengage from us */
748 part->reactivate_nasid = nasid;
749 XPC_DEACTIVATE_PARTITION(part, xpReactivating);
751 } else if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version) &&
752 xpc_partition_disengage_requested(1UL << partid)) {
753 XPC_DEACTIVATE_PARTITION(part, xpOtherGoingDown);
758 * Loop through the activation AMO variables and process any bits
759 * which are set. Each bit indicates a nasid sending a partition
760 * activation or deactivation request.
762 * Return #of IRQs detected.
765 xpc_identify_act_IRQ_sender(void)
769 u64 nasid; /* remote nasid */
770 int n_IRQs_detected = 0;
773 act_amos = xpc_vars->amos_page + XPC_ACTIVATE_IRQ_AMOS;
775 /* scan through act AMO variable looking for non-zero entries */
776 for (word = 0; word < xp_nasid_mask_words; word++) {
781 nasid_mask = xpc_IPI_receive(&act_amos[word]);
782 if (nasid_mask == 0) {
783 /* no IRQs from nasids in this variable */
787 dev_dbg(xpc_part, "AMO[%d] gave back 0x%lx\n", word,
791 * If this nasid has been added to the machine since
792 * our partition was reset, this will retain the
793 * remote nasid in our reserved pages machine mask.
794 * This is used in the event of module reload.
796 xpc_mach_nasids[word] |= nasid_mask;
798 /* locate the nasid(s) which sent interrupts */
800 for (bit = 0; bit < (8 * sizeof(u64)); bit++) {
801 if (nasid_mask & (1UL << bit)) {
803 nasid = XPC_NASID_FROM_W_B(word, bit);
804 dev_dbg(xpc_part, "interrupt from nasid %ld\n",
806 xpc_identify_act_IRQ_req(nasid);
810 return n_IRQs_detected;
814 * See if the other side has responded to a partition disengage request
818 xpc_partition_disengaged(struct xpc_partition *part)
820 short partid = XPC_PARTID(part);
823 disengaged = (xpc_partition_engaged(1UL << partid) == 0);
824 if (part->disengage_request_timeout) {
826 if (time_before(jiffies,
827 part->disengage_request_timeout)) {
828 /* timelimit hasn't been reached yet */
833 * Other side hasn't responded to our disengage
834 * request in a timely fashion, so assume it's dead.
837 dev_info(xpc_part, "disengage from remote partition %d "
838 "timed out\n", partid);
839 xpc_disengage_request_timedout = 1;
840 xpc_clear_partition_engaged(1UL << partid);
843 part->disengage_request_timeout = 0;
845 /* cancel the timer function, provided it's not us */
846 if (!in_interrupt()) {
847 del_singleshot_timer_sync(&part->
848 disengage_request_timer);
851 DBUG_ON(part->act_state != XPC_P_DEACTIVATING &&
852 part->act_state != XPC_P_INACTIVE);
853 if (part->act_state != XPC_P_INACTIVE)
854 xpc_wakeup_channel_mgr(part);
856 if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version))
857 xpc_cancel_partition_disengage_request(part);
863 * Mark specified partition as active.
866 xpc_mark_partition_active(struct xpc_partition *part)
868 unsigned long irq_flags;
871 dev_dbg(xpc_part, "setting partition %d to ACTIVE\n", XPC_PARTID(part));
873 spin_lock_irqsave(&part->act_lock, irq_flags);
874 if (part->act_state == XPC_P_ACTIVATING) {
875 part->act_state = XPC_P_ACTIVE;
878 DBUG_ON(part->reason == xpSuccess);
881 spin_unlock_irqrestore(&part->act_lock, irq_flags);
887 * Notify XPC that the partition is down.
890 xpc_deactivate_partition(const int line, struct xpc_partition *part,
891 enum xp_retval reason)
893 unsigned long irq_flags;
895 spin_lock_irqsave(&part->act_lock, irq_flags);
897 if (part->act_state == XPC_P_INACTIVE) {
898 XPC_SET_REASON(part, reason, line);
899 spin_unlock_irqrestore(&part->act_lock, irq_flags);
900 if (reason == xpReactivating) {
901 /* we interrupt ourselves to reactivate partition */
902 xpc_IPI_send_reactivate(part);
906 if (part->act_state == XPC_P_DEACTIVATING) {
907 if ((part->reason == xpUnloading && reason != xpUnloading) ||
908 reason == xpReactivating) {
909 XPC_SET_REASON(part, reason, line);
911 spin_unlock_irqrestore(&part->act_lock, irq_flags);
915 part->act_state = XPC_P_DEACTIVATING;
916 XPC_SET_REASON(part, reason, line);
918 spin_unlock_irqrestore(&part->act_lock, irq_flags);
920 if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version)) {
921 xpc_request_partition_disengage(part);
922 xpc_IPI_send_disengage(part);
924 /* set a timelimit on the disengage request */
925 part->disengage_request_timeout = jiffies +
926 (xpc_disengage_request_timelimit * HZ);
927 part->disengage_request_timer.expires =
928 part->disengage_request_timeout;
929 add_timer(&part->disengage_request_timer);
932 dev_dbg(xpc_part, "bringing partition %d down, reason = %d\n",
933 XPC_PARTID(part), reason);
935 xpc_partition_going_down(part, reason);
939 * Mark specified partition as inactive.
942 xpc_mark_partition_inactive(struct xpc_partition *part)
944 unsigned long irq_flags;
946 dev_dbg(xpc_part, "setting partition %d to INACTIVE\n",
949 spin_lock_irqsave(&part->act_lock, irq_flags);
950 part->act_state = XPC_P_INACTIVE;
951 spin_unlock_irqrestore(&part->act_lock, irq_flags);
952 part->remote_rp_pa = 0;
956 * SAL has provided a partition and machine mask. The partition mask
957 * contains a bit for each even nasid in our partition. The machine
958 * mask contains a bit for each even nasid in the entire machine.
960 * Using those two bit arrays, we can determine which nasids are
961 * known in the machine. Each should also have a reserved page
962 * initialized if they are available for partitioning.
967 void *remote_rp_base;
968 struct xpc_rsvd_page *remote_rp;
969 struct xpc_vars *remote_vars;
976 struct xpc_rsvd_page *rp;
978 struct xpc_partition *part;
979 u64 *discovered_nasids;
982 remote_rp = xpc_kmalloc_cacheline_aligned(XPC_RP_HEADER_SIZE +
984 GFP_KERNEL, &remote_rp_base);
985 if (remote_rp == NULL)
988 remote_vars = (struct xpc_vars *)remote_rp;
990 discovered_nasids = kzalloc(sizeof(u64) * xp_nasid_mask_words,
992 if (discovered_nasids == NULL) {
993 kfree(remote_rp_base);
997 rp = (struct xpc_rsvd_page *)xpc_rsvd_page;
1000 * The term 'region' in this context refers to the minimum number of
1001 * nodes that can comprise an access protection grouping. The access
1002 * protection is in regards to memory, IOI and IPI.
1005 region_size = sn_region_size;
1007 switch (region_size) {
1015 DBUG_ON(!is_shub2());
1018 for (region = 0; region < max_regions; region++) {
1023 dev_dbg(xpc_part, "searching region %d\n", region);
1025 for (nasid = (region * region_size * 2);
1026 nasid < ((region + 1) * region_size * 2); nasid += 2) {
1031 dev_dbg(xpc_part, "checking nasid %d\n", nasid);
1033 if (XPC_NASID_IN_ARRAY(nasid, xpc_part_nasids)) {
1034 dev_dbg(xpc_part, "PROM indicates Nasid %d is "
1035 "part of the local partition; skipping "
1040 if (!(XPC_NASID_IN_ARRAY(nasid, xpc_mach_nasids))) {
1041 dev_dbg(xpc_part, "PROM indicates Nasid %d was "
1042 "not on Numa-Link network at reset\n",
1047 if (XPC_NASID_IN_ARRAY(nasid, discovered_nasids)) {
1048 dev_dbg(xpc_part, "Nasid %d is part of a "
1049 "partition which was previously "
1050 "discovered\n", nasid);
1054 /* pull over the reserved page structure */
1056 ret = xpc_get_remote_rp(nasid, discovered_nasids,
1057 remote_rp, &remote_rp_pa);
1058 if (ret != xpSuccess) {
1059 dev_dbg(xpc_part, "unable to get reserved page "
1060 "from nasid %d, reason=%d\n", nasid,
1063 if (ret == xpLocalPartid)
1069 remote_vars_pa = remote_rp->vars_pa;
1071 partid = remote_rp->partid;
1072 part = &xpc_partitions[partid];
1074 /* pull over the cross partition variables */
1076 ret = xpc_get_remote_vars(remote_vars_pa, remote_vars);
1077 if (ret != xpSuccess) {
1078 dev_dbg(xpc_part, "unable to get XPC variables "
1079 "from nasid %d, reason=%d\n", nasid,
1082 XPC_DEACTIVATE_PARTITION(part, ret);
1086 if (part->act_state != XPC_P_INACTIVE) {
1087 dev_dbg(xpc_part, "partition %d on nasid %d is "
1088 "already activating\n", partid, nasid);
1093 * Register the remote partition's AMOs with SAL so it
1094 * can handle and cleanup errors within that address
1095 * range should the remote partition go down. We don't
1096 * unregister this range because it is difficult to
1097 * tell when outstanding writes to the remote partition
1098 * are finished and thus when it is thus safe to
1099 * unregister. This should not result in wasted space
1100 * in the SAL xp_addr_region table because we should
1101 * get the same page for remote_act_amos_pa after
1102 * module reloads and system reboots.
1104 if (sn_register_xp_addr_region
1105 (remote_vars->amos_page_pa, PAGE_SIZE, 1) < 0) {
1107 "partition %d failed to "
1108 "register xp_addr region 0x%016lx\n",
1109 partid, remote_vars->amos_page_pa);
1111 XPC_SET_REASON(part, xpPhysAddrRegFailed,
1117 * The remote nasid is valid and available.
1118 * Send an interrupt to that nasid to notify
1119 * it that we are ready to begin activation.
1121 dev_dbg(xpc_part, "sending an interrupt to AMO 0x%lx, "
1122 "nasid %d, phys_cpuid 0x%x\n",
1123 remote_vars->amos_page_pa,
1124 remote_vars->act_nasid,
1125 remote_vars->act_phys_cpuid);
1127 if (XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->
1129 part->remote_amos_page_pa =
1130 remote_vars->amos_page_pa;
1131 xpc_mark_partition_disengaged(part);
1132 xpc_cancel_partition_disengage_request(part);
1134 xpc_IPI_send_activate(remote_vars);
1138 kfree(discovered_nasids);
1139 kfree(remote_rp_base);
1143 * Given a partid, get the nasids owned by that partition from the
1144 * remote partition's reserved page.
1147 xpc_initiate_partid_to_nasids(short partid, void *nasid_mask)
1149 struct xpc_partition *part;
1153 part = &xpc_partitions[partid];
1154 if (part->remote_rp_pa == 0)
1155 return xpPartitionDown;
1157 memset(nasid_mask, 0, XP_NASID_MASK_BYTES);
1159 part_nasid_pa = (u64)XPC_RP_PART_NASIDS(part->remote_rp_pa);
1161 bte_res = xp_bte_copy(part_nasid_pa, (u64)nasid_mask,
1162 xp_nasid_mask_bytes, (BTE_NOTIFY | BTE_WACQUIRE),
1165 return xpc_map_bte_errors(bte_res);