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-2005 Silicon Graphics, Inc. All Rights Reserved.
11 * Cross Partition Communication (XPC) partition support.
13 * This is the part of XPC that detects the presence/absence of
14 * other partitions. It provides a heartbeat and monitors the
15 * heartbeats of other partitions.
20 #include <linux/kernel.h>
21 #include <linux/sysctl.h>
22 #include <linux/cache.h>
23 #include <linux/mmzone.h>
24 #include <linux/nodemask.h>
25 #include <asm/uncached.h>
26 #include <asm/sn/bte.h>
27 #include <asm/sn/intr.h>
28 #include <asm/sn/sn_sal.h>
29 #include <asm/sn/nodepda.h>
30 #include <asm/sn/addrs.h>
34 /* XPC is exiting flag */
38 /* SH_IPI_ACCESS shub register value on startup */
39 static u64 xpc_sh1_IPI_access
;
40 static u64 xpc_sh2_IPI_access0
;
41 static u64 xpc_sh2_IPI_access1
;
42 static u64 xpc_sh2_IPI_access2
;
43 static u64 xpc_sh2_IPI_access3
;
46 /* original protection values for each node */
47 u64 xpc_prot_vec
[MAX_COMPACT_NODES
];
50 /* this partition's reserved page */
51 struct xpc_rsvd_page
*xpc_rsvd_page
;
53 /* this partition's XPC variables (within the reserved page) */
54 struct xpc_vars
*xpc_vars
;
55 struct xpc_vars_part
*xpc_vars_part
;
59 * For performance reasons, each entry of xpc_partitions[] is cacheline
60 * aligned. And xpc_partitions[] is padded with an additional entry at the
61 * end so that the last legitimate entry doesn't share its cacheline with
64 struct xpc_partition xpc_partitions
[XP_MAX_PARTITIONS
+ 1];
68 * Generic buffer used to store a local copy of the remote partitions
69 * reserved page or XPC variables.
71 * xpc_discovery runs only once and is a seperate thread that is
72 * very likely going to be processing in parallel with receiving
75 char ____cacheline_aligned
76 xpc_remote_copy_buffer
[XPC_RSVD_PAGE_ALIGNED_SIZE
];
79 /* systune related variables */
80 int xpc_hb_interval
= XPC_HB_DEFAULT_INTERVAL
;
81 int xpc_hb_check_interval
= XPC_HB_CHECK_DEFAULT_TIMEOUT
;
85 * Given a nasid, get the physical address of the partition's reserved page
86 * for that nasid. This function returns 0 on any error.
89 xpc_get_rsvd_page_pa(int nasid
, u64 buf
, u64 buf_size
)
94 u64 rp_pa
= nasid
; /* seed with nasid */
100 status
= sn_partition_reserved_page_pa(buf
, &cookie
, &rp_pa
,
103 dev_dbg(xpc_part
, "SAL returned with status=%li, cookie="
104 "0x%016lx, address=0x%016lx, len=0x%016lx\n",
105 status
, cookie
, rp_pa
, len
);
107 if (status
!= SALRET_MORE_PASSES
) {
111 if (len
> buf_size
) {
112 dev_err(xpc_part
, "len (=0x%016lx) > buf_size\n", len
);
113 status
= SALRET_ERROR
;
117 bte_res
= xp_bte_copy(rp_pa
, ia64_tpa(buf
), buf_size
,
118 (BTE_NOTIFY
| BTE_WACQUIRE
), NULL
);
119 if (bte_res
!= BTE_SUCCESS
) {
120 dev_dbg(xpc_part
, "xp_bte_copy failed %i\n", bte_res
);
121 status
= SALRET_ERROR
;
126 if (status
!= SALRET_OK
) {
129 dev_dbg(xpc_part
, "reserved page at phys address 0x%016lx\n", rp_pa
);
135 * Fill the partition reserved page with the information needed by
136 * other partitions to discover we are alive and establish initial
139 struct xpc_rsvd_page
*
140 xpc_rsvd_page_init(void)
142 struct xpc_rsvd_page
*rp
;
144 u64 rp_pa
, next_cl
, nasid_array
= 0;
148 /* get the local reserved page's address */
150 rp_pa
= xpc_get_rsvd_page_pa(cnodeid_to_nasid(0),
151 (u64
) xpc_remote_copy_buffer
,
152 XPC_RSVD_PAGE_ALIGNED_SIZE
);
154 dev_err(xpc_part
, "SAL failed to locate the reserved page\n");
157 rp
= (struct xpc_rsvd_page
*) __va(rp_pa
);
159 if (rp
->partid
!= sn_partition_id
) {
160 dev_err(xpc_part
, "the reserved page's partid of %d should be "
161 "%d\n", rp
->partid
, sn_partition_id
);
165 rp
->version
= XPC_RP_VERSION
;
168 * Place the XPC variables on the cache line following the
169 * reserved page structure.
171 next_cl
= (u64
) rp
+ XPC_RSVD_PAGE_ALIGNED_SIZE
;
172 xpc_vars
= (struct xpc_vars
*) next_cl
;
175 * Before clearing xpc_vars, see if a page of AMOs had been previously
176 * allocated. If not we'll need to allocate one and set permissions
177 * so that cross-partition AMOs are allowed.
179 * The allocated AMO page needs MCA reporting to remain disabled after
180 * XPC has unloaded. To make this work, we keep a copy of the pointer
181 * to this page (i.e., amos_page) in the struct xpc_vars structure,
182 * which is pointed to by the reserved page, and re-use that saved copy
183 * on subsequent loads of XPC. This AMO page is never freed, and its
184 * memory protections are never restricted.
186 if ((amos_page
= xpc_vars
->amos_page
) == NULL
) {
187 amos_page
= (AMO_t
*) TO_AMO(uncached_alloc_page(0));
188 if (amos_page
== NULL
) {
189 dev_err(xpc_part
, "can't allocate page of AMOs\n");
194 * Open up AMO-R/W to cpu. This is done for Shub 1.1 systems
195 * when xpc_allow_IPI_ops() is called via xpc_hb_init().
197 if (!enable_shub_wars_1_1()) {
198 ret
= sn_change_memprotect(ia64_tpa((u64
) amos_page
),
199 PAGE_SIZE
, SN_MEMPROT_ACCESS_CLASS_1
,
202 dev_err(xpc_part
, "can't change memory "
204 uncached_free_page(__IA64_UNCACHED_OFFSET
|
205 TO_PHYS((u64
) amos_page
));
209 } else if (!IS_AMO_ADDRESS((u64
) amos_page
)) {
211 * EFI's XPBOOT can also set amos_page in the reserved page,
212 * but it happens to leave it as an uncached physical address
213 * and we need it to be an uncached virtual, so we'll have to
216 if (!IS_AMO_PHYS_ADDRESS((u64
) amos_page
)) {
217 dev_err(xpc_part
, "previously used amos_page address "
218 "is bad = 0x%p\n", (void *) amos_page
);
221 amos_page
= (AMO_t
*) TO_AMO((u64
) amos_page
);
224 memset(xpc_vars
, 0, sizeof(struct xpc_vars
));
227 * Place the XPC per partition specific variables on the cache line
228 * following the XPC variables structure.
230 next_cl
+= XPC_VARS_ALIGNED_SIZE
;
231 memset((u64
*) next_cl
, 0, sizeof(struct xpc_vars_part
) *
233 xpc_vars_part
= (struct xpc_vars_part
*) next_cl
;
234 xpc_vars
->vars_part_pa
= __pa(next_cl
);
236 xpc_vars
->version
= XPC_V_VERSION
;
237 xpc_vars
->act_nasid
= cpuid_to_nasid(0);
238 xpc_vars
->act_phys_cpuid
= cpu_physical_id(0);
239 xpc_vars
->amos_page
= amos_page
; /* save for next load of XPC */
243 * Initialize the activation related AMO variables.
245 xpc_vars
->act_amos
= xpc_IPI_init(XP_MAX_PARTITIONS
);
246 for (i
= 1; i
< XP_NASID_MASK_WORDS
; i
++) {
247 xpc_IPI_init(i
+ XP_MAX_PARTITIONS
);
249 /* export AMO page's physical address to other partitions */
250 xpc_vars
->amos_page_pa
= ia64_tpa((u64
) xpc_vars
->amos_page
);
253 * This signifies to the remote partition that our reserved
254 * page is initialized.
256 (volatile u64
) rp
->vars_pa
= __pa(xpc_vars
);
263 * Change protections to allow IPI operations (and AMO operations on
267 xpc_allow_IPI_ops(void)
273 // >>> Change SH_IPI_ACCESS code to use SAL call once it is available.
276 xpc_sh2_IPI_access0
=
277 (u64
) HUB_L((u64
*) LOCAL_MMR_ADDR(SH2_IPI_ACCESS0
));
278 xpc_sh2_IPI_access1
=
279 (u64
) HUB_L((u64
*) LOCAL_MMR_ADDR(SH2_IPI_ACCESS1
));
280 xpc_sh2_IPI_access2
=
281 (u64
) HUB_L((u64
*) LOCAL_MMR_ADDR(SH2_IPI_ACCESS2
));
282 xpc_sh2_IPI_access3
=
283 (u64
) HUB_L((u64
*) LOCAL_MMR_ADDR(SH2_IPI_ACCESS3
));
285 for_each_online_node(node
) {
286 nasid
= cnodeid_to_nasid(node
);
287 HUB_S((u64
*) GLOBAL_MMR_ADDR(nasid
, SH2_IPI_ACCESS0
),
289 HUB_S((u64
*) GLOBAL_MMR_ADDR(nasid
, SH2_IPI_ACCESS1
),
291 HUB_S((u64
*) GLOBAL_MMR_ADDR(nasid
, SH2_IPI_ACCESS2
),
293 HUB_S((u64
*) GLOBAL_MMR_ADDR(nasid
, SH2_IPI_ACCESS3
),
299 (u64
) HUB_L((u64
*) LOCAL_MMR_ADDR(SH1_IPI_ACCESS
));
301 for_each_online_node(node
) {
302 nasid
= cnodeid_to_nasid(node
);
303 HUB_S((u64
*) GLOBAL_MMR_ADDR(nasid
, SH1_IPI_ACCESS
),
307 * Since the BIST collides with memory operations on
308 * SHUB 1.1 sn_change_memprotect() cannot be used.
310 if (enable_shub_wars_1_1()) {
311 /* open up everything */
312 xpc_prot_vec
[node
] = (u64
) HUB_L((u64
*)
313 GLOBAL_MMR_ADDR(nasid
,
314 SH1_MD_DQLP_MMR_DIR_PRIVEC0
));
315 HUB_S((u64
*) GLOBAL_MMR_ADDR(nasid
,
316 SH1_MD_DQLP_MMR_DIR_PRIVEC0
),
318 HUB_S((u64
*) GLOBAL_MMR_ADDR(nasid
,
319 SH1_MD_DQRP_MMR_DIR_PRIVEC0
),
328 * Restrict protections to disallow IPI operations (and AMO operations on
332 xpc_restrict_IPI_ops(void)
338 // >>> Change SH_IPI_ACCESS code to use SAL call once it is available.
342 for_each_online_node(node
) {
343 nasid
= cnodeid_to_nasid(node
);
344 HUB_S((u64
*) GLOBAL_MMR_ADDR(nasid
, SH2_IPI_ACCESS0
),
345 xpc_sh2_IPI_access0
);
346 HUB_S((u64
*) GLOBAL_MMR_ADDR(nasid
, SH2_IPI_ACCESS1
),
347 xpc_sh2_IPI_access1
);
348 HUB_S((u64
*) GLOBAL_MMR_ADDR(nasid
, SH2_IPI_ACCESS2
),
349 xpc_sh2_IPI_access2
);
350 HUB_S((u64
*) GLOBAL_MMR_ADDR(nasid
, SH2_IPI_ACCESS3
),
351 xpc_sh2_IPI_access3
);
356 for_each_online_node(node
) {
357 nasid
= cnodeid_to_nasid(node
);
358 HUB_S((u64
*) GLOBAL_MMR_ADDR(nasid
, SH1_IPI_ACCESS
),
361 if (enable_shub_wars_1_1()) {
362 HUB_S((u64
*) GLOBAL_MMR_ADDR(nasid
,
363 SH1_MD_DQLP_MMR_DIR_PRIVEC0
),
365 HUB_S((u64
*) GLOBAL_MMR_ADDR(nasid
,
366 SH1_MD_DQRP_MMR_DIR_PRIVEC0
),
375 * At periodic intervals, scan through all active partitions and ensure
376 * their heartbeat is still active. If not, the partition is deactivated.
379 xpc_check_remote_hb(void)
381 struct xpc_vars
*remote_vars
;
382 struct xpc_partition
*part
;
387 remote_vars
= (struct xpc_vars
*) xpc_remote_copy_buffer
;
389 for (partid
= 1; partid
< XP_MAX_PARTITIONS
; partid
++) {
390 if (partid
== sn_partition_id
) {
394 part
= &xpc_partitions
[partid
];
396 if (part
->act_state
== XPC_P_INACTIVE
||
397 part
->act_state
== XPC_P_DEACTIVATING
) {
401 /* pull the remote_hb cache line */
402 bres
= xp_bte_copy(part
->remote_vars_pa
,
403 ia64_tpa((u64
) remote_vars
),
404 XPC_VARS_ALIGNED_SIZE
,
405 (BTE_NOTIFY
| BTE_WACQUIRE
), NULL
);
406 if (bres
!= BTE_SUCCESS
) {
407 XPC_DEACTIVATE_PARTITION(part
,
408 xpc_map_bte_errors(bres
));
412 dev_dbg(xpc_part
, "partid = %d, heartbeat = %ld, last_heartbeat"
413 " = %ld, kdb_status = %ld, HB_mask = 0x%lx\n", partid
,
414 remote_vars
->heartbeat
, part
->last_heartbeat
,
415 remote_vars
->kdb_status
,
416 remote_vars
->heartbeating_to_mask
);
418 if (((remote_vars
->heartbeat
== part
->last_heartbeat
) &&
419 (remote_vars
->kdb_status
== 0)) ||
420 !XPC_HB_ALLOWED(sn_partition_id
, remote_vars
)) {
422 XPC_DEACTIVATE_PARTITION(part
, xpcNoHeartbeat
);
426 part
->last_heartbeat
= remote_vars
->heartbeat
;
432 * Get a copy of the remote partition's rsvd page.
434 * remote_rp points to a buffer that is cacheline aligned for BTE copies and
435 * assumed to be of size XPC_RSVD_PAGE_ALIGNED_SIZE.
437 static enum xpc_retval
438 xpc_get_remote_rp(int nasid
, u64
*discovered_nasids
,
439 struct xpc_rsvd_page
*remote_rp
, u64
*remote_rsvd_page_pa
)
444 /* get the reserved page's physical address */
446 *remote_rsvd_page_pa
= xpc_get_rsvd_page_pa(nasid
, (u64
) remote_rp
,
447 XPC_RSVD_PAGE_ALIGNED_SIZE
);
448 if (*remote_rsvd_page_pa
== 0) {
449 return xpcNoRsvdPageAddr
;
453 /* pull over the reserved page structure */
455 bres
= xp_bte_copy(*remote_rsvd_page_pa
, ia64_tpa((u64
) remote_rp
),
456 XPC_RSVD_PAGE_ALIGNED_SIZE
,
457 (BTE_NOTIFY
| BTE_WACQUIRE
), NULL
);
458 if (bres
!= BTE_SUCCESS
) {
459 return xpc_map_bte_errors(bres
);
463 if (discovered_nasids
!= NULL
) {
464 for (i
= 0; i
< XP_NASID_MASK_WORDS
; i
++) {
465 discovered_nasids
[i
] |= remote_rp
->part_nasids
[i
];
470 /* check that the partid is for another partition */
472 if (remote_rp
->partid
< 1 ||
473 remote_rp
->partid
> (XP_MAX_PARTITIONS
- 1)) {
474 return xpcInvalidPartid
;
477 if (remote_rp
->partid
== sn_partition_id
) {
478 return xpcLocalPartid
;
482 if (XPC_VERSION_MAJOR(remote_rp
->version
) !=
483 XPC_VERSION_MAJOR(XPC_RP_VERSION
)) {
484 return xpcBadVersion
;
492 * Get a copy of the remote partition's XPC variables.
494 * remote_vars points to a buffer that is cacheline aligned for BTE copies and
495 * assumed to be of size XPC_VARS_ALIGNED_SIZE.
497 static enum xpc_retval
498 xpc_get_remote_vars(u64 remote_vars_pa
, struct xpc_vars
*remote_vars
)
503 if (remote_vars_pa
== 0) {
504 return xpcVarsNotSet
;
508 /* pull over the cross partition variables */
510 bres
= xp_bte_copy(remote_vars_pa
, ia64_tpa((u64
) remote_vars
),
511 XPC_VARS_ALIGNED_SIZE
,
512 (BTE_NOTIFY
| BTE_WACQUIRE
), NULL
);
513 if (bres
!= BTE_SUCCESS
) {
514 return xpc_map_bte_errors(bres
);
517 if (XPC_VERSION_MAJOR(remote_vars
->version
) !=
518 XPC_VERSION_MAJOR(XPC_V_VERSION
)) {
519 return xpcBadVersion
;
527 * Prior code has determine the nasid which generated an IPI. Inspect
528 * that nasid to determine if its partition needs to be activated or
531 * A partition is consider "awaiting activation" if our partition
532 * flags indicate it is not active and it has a heartbeat. A
533 * partition is considered "awaiting deactivation" if our partition
534 * flags indicate it is active but it has no heartbeat or it is not
535 * sending its heartbeat to us.
537 * To determine the heartbeat, the remote nasid must have a properly
538 * initialized reserved page.
541 xpc_identify_act_IRQ_req(int nasid
)
543 struct xpc_rsvd_page
*remote_rp
;
544 struct xpc_vars
*remote_vars
;
545 u64 remote_rsvd_page_pa
;
548 struct xpc_partition
*part
;
552 /* pull over the reserved page structure */
554 remote_rp
= (struct xpc_rsvd_page
*) xpc_remote_copy_buffer
;
556 ret
= xpc_get_remote_rp(nasid
, NULL
, remote_rp
, &remote_rsvd_page_pa
);
557 if (ret
!= xpcSuccess
) {
558 dev_warn(xpc_part
, "unable to get reserved page from nasid %d, "
559 "which sent interrupt, reason=%d\n", nasid
, ret
);
563 remote_vars_pa
= remote_rp
->vars_pa
;
564 partid
= remote_rp
->partid
;
565 part
= &xpc_partitions
[partid
];
568 /* pull over the cross partition variables */
570 remote_vars
= (struct xpc_vars
*) xpc_remote_copy_buffer
;
572 ret
= xpc_get_remote_vars(remote_vars_pa
, remote_vars
);
573 if (ret
!= xpcSuccess
) {
575 dev_warn(xpc_part
, "unable to get XPC variables from nasid %d, "
576 "which sent interrupt, reason=%d\n", nasid
, ret
);
578 XPC_DEACTIVATE_PARTITION(part
, ret
);
583 part
->act_IRQ_rcvd
++;
585 dev_dbg(xpc_part
, "partid for nasid %d is %d; IRQs = %d; HB = "
586 "%ld:0x%lx\n", (int) nasid
, (int) partid
, part
->act_IRQ_rcvd
,
587 remote_vars
->heartbeat
, remote_vars
->heartbeating_to_mask
);
590 if (part
->act_state
== XPC_P_INACTIVE
) {
592 part
->remote_rp_pa
= remote_rsvd_page_pa
;
593 dev_dbg(xpc_part
, " remote_rp_pa = 0x%016lx\n",
596 part
->remote_vars_pa
= remote_vars_pa
;
597 dev_dbg(xpc_part
, " remote_vars_pa = 0x%016lx\n",
598 part
->remote_vars_pa
);
600 part
->last_heartbeat
= remote_vars
->heartbeat
;
601 dev_dbg(xpc_part
, " last_heartbeat = 0x%016lx\n",
602 part
->last_heartbeat
);
604 part
->remote_vars_part_pa
= remote_vars
->vars_part_pa
;
605 dev_dbg(xpc_part
, " remote_vars_part_pa = 0x%016lx\n",
606 part
->remote_vars_part_pa
);
608 part
->remote_act_nasid
= remote_vars
->act_nasid
;
609 dev_dbg(xpc_part
, " remote_act_nasid = 0x%x\n",
610 part
->remote_act_nasid
);
612 part
->remote_act_phys_cpuid
= remote_vars
->act_phys_cpuid
;
613 dev_dbg(xpc_part
, " remote_act_phys_cpuid = 0x%x\n",
614 part
->remote_act_phys_cpuid
);
616 part
->remote_amos_page_pa
= remote_vars
->amos_page_pa
;
617 dev_dbg(xpc_part
, " remote_amos_page_pa = 0x%lx\n",
618 part
->remote_amos_page_pa
);
620 xpc_activate_partition(part
);
622 } else if (part
->remote_amos_page_pa
!= remote_vars
->amos_page_pa
||
623 !XPC_HB_ALLOWED(sn_partition_id
, remote_vars
)) {
625 part
->reactivate_nasid
= nasid
;
626 XPC_DEACTIVATE_PARTITION(part
, xpcReactivating
);
632 * Loop through the activation AMO variables and process any bits
633 * which are set. Each bit indicates a nasid sending a partition
634 * activation or deactivation request.
636 * Return #of IRQs detected.
639 xpc_identify_act_IRQ_sender(void)
643 u64 nasid
; /* remote nasid */
644 int n_IRQs_detected
= 0;
646 struct xpc_rsvd_page
*rp
= (struct xpc_rsvd_page
*) xpc_rsvd_page
;
649 act_amos
= xpc_vars
->act_amos
;
652 /* scan through act AMO variable looking for non-zero entries */
653 for (word
= 0; word
< XP_NASID_MASK_WORDS
; word
++) {
655 nasid_mask
= xpc_IPI_receive(&act_amos
[word
]);
656 if (nasid_mask
== 0) {
657 /* no IRQs from nasids in this variable */
661 dev_dbg(xpc_part
, "AMO[%d] gave back 0x%lx\n", word
,
666 * If this nasid has been added to the machine since
667 * our partition was reset, this will retain the
668 * remote nasid in our reserved pages machine mask.
669 * This is used in the event of module reload.
671 rp
->mach_nasids
[word
] |= nasid_mask
;
674 /* locate the nasid(s) which sent interrupts */
676 for (bit
= 0; bit
< (8 * sizeof(u64
)); bit
++) {
677 if (nasid_mask
& (1UL << bit
)) {
679 nasid
= XPC_NASID_FROM_W_B(word
, bit
);
680 dev_dbg(xpc_part
, "interrupt from nasid %ld\n",
682 xpc_identify_act_IRQ_req(nasid
);
686 return n_IRQs_detected
;
691 * Mark specified partition as active.
694 xpc_mark_partition_active(struct xpc_partition
*part
)
696 unsigned long irq_flags
;
700 dev_dbg(xpc_part
, "setting partition %d to ACTIVE\n", XPC_PARTID(part
));
702 spin_lock_irqsave(&part
->act_lock
, irq_flags
);
703 if (part
->act_state
== XPC_P_ACTIVATING
) {
704 part
->act_state
= XPC_P_ACTIVE
;
707 DBUG_ON(part
->reason
== xpcSuccess
);
710 spin_unlock_irqrestore(&part
->act_lock
, irq_flags
);
717 * Notify XPC that the partition is down.
720 xpc_deactivate_partition(const int line
, struct xpc_partition
*part
,
721 enum xpc_retval reason
)
723 unsigned long irq_flags
;
724 partid_t partid
= XPC_PARTID(part
);
727 spin_lock_irqsave(&part
->act_lock
, irq_flags
);
729 if (part
->act_state
== XPC_P_INACTIVE
) {
730 XPC_SET_REASON(part
, reason
, line
);
731 spin_unlock_irqrestore(&part
->act_lock
, irq_flags
);
732 if (reason
== xpcReactivating
) {
733 /* we interrupt ourselves to reactivate partition */
734 xpc_IPI_send_reactivate(part
);
738 if (part
->act_state
== XPC_P_DEACTIVATING
) {
739 if ((part
->reason
== xpcUnloading
&& reason
!= xpcUnloading
) ||
740 reason
== xpcReactivating
) {
741 XPC_SET_REASON(part
, reason
, line
);
743 spin_unlock_irqrestore(&part
->act_lock
, irq_flags
);
747 part
->act_state
= XPC_P_DEACTIVATING
;
748 XPC_SET_REASON(part
, reason
, line
);
750 spin_unlock_irqrestore(&part
->act_lock
, irq_flags
);
752 XPC_DISALLOW_HB(partid
, xpc_vars
);
754 dev_dbg(xpc_part
, "bringing partition %d down, reason = %d\n", partid
,
757 xpc_partition_down(part
, reason
);
762 * Mark specified partition as active.
765 xpc_mark_partition_inactive(struct xpc_partition
*part
)
767 unsigned long irq_flags
;
770 dev_dbg(xpc_part
, "setting partition %d to INACTIVE\n",
773 spin_lock_irqsave(&part
->act_lock
, irq_flags
);
774 part
->act_state
= XPC_P_INACTIVE
;
775 spin_unlock_irqrestore(&part
->act_lock
, irq_flags
);
776 part
->remote_rp_pa
= 0;
781 * SAL has provided a partition and machine mask. The partition mask
782 * contains a bit for each even nasid in our partition. The machine
783 * mask contains a bit for each even nasid in the entire machine.
785 * Using those two bit arrays, we can determine which nasids are
786 * known in the machine. Each should also have a reserved page
787 * initialized if they are available for partitioning.
792 void *remote_rp_base
;
793 struct xpc_rsvd_page
*remote_rp
;
794 struct xpc_vars
*remote_vars
;
795 u64 remote_rsvd_page_pa
;
800 struct xpc_rsvd_page
*rp
;
802 struct xpc_partition
*part
;
803 u64
*discovered_nasids
;
807 remote_rp
= xpc_kmalloc_cacheline_aligned(XPC_RSVD_PAGE_ALIGNED_SIZE
,
808 GFP_KERNEL
, &remote_rp_base
);
809 if (remote_rp
== NULL
) {
812 remote_vars
= (struct xpc_vars
*) remote_rp
;
815 discovered_nasids
= kmalloc(sizeof(u64
) * XP_NASID_MASK_WORDS
,
817 if (discovered_nasids
== NULL
) {
818 kfree(remote_rp_base
);
821 memset(discovered_nasids
, 0, sizeof(u64
) * XP_NASID_MASK_WORDS
);
823 rp
= (struct xpc_rsvd_page
*) xpc_rsvd_page
;
826 * The term 'region' in this context refers to the minimum number of
827 * nodes that can comprise an access protection grouping. The access
828 * protection is in regards to memory, IOI and IPI.
830 //>>> move the next two #defines into either include/asm-ia64/sn/arch.h or
831 //>>> include/asm-ia64/sn/addrs.h
832 #define SH1_MAX_REGIONS 64
833 #define SH2_MAX_REGIONS 256
834 max_regions
= is_shub2() ? SH2_MAX_REGIONS
: SH1_MAX_REGIONS
;
836 for (region
= 0; region
< max_regions
; region
++) {
838 if ((volatile int) xpc_exiting
) {
842 dev_dbg(xpc_part
, "searching region %d\n", region
);
844 for (nasid
= (region
* sn_region_size
* 2);
845 nasid
< ((region
+ 1) * sn_region_size
* 2);
848 if ((volatile int) xpc_exiting
) {
852 dev_dbg(xpc_part
, "checking nasid %d\n", nasid
);
855 if (XPC_NASID_IN_ARRAY(nasid
, rp
->part_nasids
)) {
856 dev_dbg(xpc_part
, "PROM indicates Nasid %d is "
857 "part of the local partition; skipping "
862 if (!(XPC_NASID_IN_ARRAY(nasid
, rp
->mach_nasids
))) {
863 dev_dbg(xpc_part
, "PROM indicates Nasid %d was "
864 "not on Numa-Link network at reset\n",
869 if (XPC_NASID_IN_ARRAY(nasid
, discovered_nasids
)) {
870 dev_dbg(xpc_part
, "Nasid %d is part of a "
871 "partition which was previously "
872 "discovered\n", nasid
);
877 /* pull over the reserved page structure */
879 ret
= xpc_get_remote_rp(nasid
, discovered_nasids
,
880 remote_rp
, &remote_rsvd_page_pa
);
881 if (ret
!= xpcSuccess
) {
882 dev_dbg(xpc_part
, "unable to get reserved page "
883 "from nasid %d, reason=%d\n", nasid
,
886 if (ret
== xpcLocalPartid
) {
892 remote_vars_pa
= remote_rp
->vars_pa
;
894 partid
= remote_rp
->partid
;
895 part
= &xpc_partitions
[partid
];
898 /* pull over the cross partition variables */
900 ret
= xpc_get_remote_vars(remote_vars_pa
, remote_vars
);
901 if (ret
!= xpcSuccess
) {
902 dev_dbg(xpc_part
, "unable to get XPC variables "
903 "from nasid %d, reason=%d\n", nasid
,
906 XPC_DEACTIVATE_PARTITION(part
, ret
);
910 if (part
->act_state
!= XPC_P_INACTIVE
) {
911 dev_dbg(xpc_part
, "partition %d on nasid %d is "
912 "already activating\n", partid
, nasid
);
917 * Register the remote partition's AMOs with SAL so it
918 * can handle and cleanup errors within that address
919 * range should the remote partition go down. We don't
920 * unregister this range because it is difficult to
921 * tell when outstanding writes to the remote partition
922 * are finished and thus when it is thus safe to
923 * unregister. This should not result in wasted space
924 * in the SAL xp_addr_region table because we should
925 * get the same page for remote_act_amos_pa after
926 * module reloads and system reboots.
928 if (sn_register_xp_addr_region(
929 remote_vars
->amos_page_pa
,
931 dev_dbg(xpc_part
, "partition %d failed to "
932 "register xp_addr region 0x%016lx\n",
933 partid
, remote_vars
->amos_page_pa
);
935 XPC_SET_REASON(part
, xpcPhysAddrRegFailed
,
941 * The remote nasid is valid and available.
942 * Send an interrupt to that nasid to notify
943 * it that we are ready to begin activation.
945 dev_dbg(xpc_part
, "sending an interrupt to AMO 0x%lx, "
946 "nasid %d, phys_cpuid 0x%x\n",
947 remote_vars
->amos_page_pa
,
948 remote_vars
->act_nasid
,
949 remote_vars
->act_phys_cpuid
);
951 xpc_IPI_send_activate(remote_vars
);
955 kfree(discovered_nasids
);
956 kfree(remote_rp_base
);
961 * Given a partid, get the nasids owned by that partition from the
962 * remote partition's reserved page.
965 xpc_initiate_partid_to_nasids(partid_t partid
, void *nasid_mask
)
967 struct xpc_partition
*part
;
972 part
= &xpc_partitions
[partid
];
973 if (part
->remote_rp_pa
== 0) {
974 return xpcPartitionDown
;
977 part_nasid_pa
= part
->remote_rp_pa
+
978 (u64
) &((struct xpc_rsvd_page
*) 0)->part_nasids
;
980 bte_res
= xp_bte_copy(part_nasid_pa
, ia64_tpa((u64
) nasid_mask
),
981 L1_CACHE_ALIGN(XP_NASID_MASK_BYTES
),
982 (BTE_NOTIFY
| BTE_WACQUIRE
), NULL
);
984 return xpc_map_bte_errors(bte_res
);