blob: 9f104450478f7394ac1b2811a814fbaa5aa61c18 [file] [log] [blame]
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001/*
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
4 * for more details.
5 *
Dean Nelson45d9ca42008-04-22 14:46:56 -05006 * Copyright (c) 2004-2008 Silicon Graphics, Inc. All Rights Reserved.
Dean Nelson89eb8eb2005-03-23 19:50:00 -07007 */
8
Dean Nelson89eb8eb2005-03-23 19:50:00 -07009/*
10 * Cross Partition Communication (XPC) partition support.
11 *
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.
15 *
16 */
17
Dean Nelson89eb8eb2005-03-23 19:50:00 -070018#include <linux/kernel.h>
19#include <linux/sysctl.h>
20#include <linux/cache.h>
21#include <linux/mmzone.h>
22#include <linux/nodemask.h>
Dean Nelson89eb8eb2005-03-23 19:50:00 -070023#include <asm/sn/intr.h>
24#include <asm/sn/sn_sal.h>
25#include <asm/sn/nodepda.h>
26#include <asm/sn/addrs.h>
Dean Nelson45d9ca42008-04-22 14:46:56 -050027#include "xpc.h"
Dean Nelson89eb8eb2005-03-23 19:50:00 -070028
Dean Nelson89eb8eb2005-03-23 19:50:00 -070029/* XPC is exiting flag */
30int xpc_exiting;
31
Dean Nelson4b38fcd2005-10-25 14:09:51 -050032/* this partition's reserved page pointers */
Dean Nelson89eb8eb2005-03-23 19:50:00 -070033struct xpc_rsvd_page *xpc_rsvd_page;
Dean Nelson4b38fcd2005-10-25 14:09:51 -050034static u64 *xpc_part_nasids;
Dean Nelson33ba3c72008-07-29 22:34:07 -070035u64 *xpc_mach_nasids;
Dean Nelson89eb8eb2005-03-23 19:50:00 -070036
Dean Nelsonee6665e2008-07-29 22:34:13 -070037static int xpc_sizeof_nasid_mask; /* actual size in bytes of nasid mask */
38int xpc_nasid_mask_words; /* actual size in words of nasid mask */
Dean Nelson4b38fcd2005-10-25 14:09:51 -050039
Dean Nelsonbc63d382008-07-29 22:34:04 -070040struct xpc_partition *xpc_partitions;
Dean Nelson89eb8eb2005-03-23 19:50:00 -070041
Dean Nelson89eb8eb2005-03-23 19:50:00 -070042/*
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050043 * Guarantee that the kmalloc'd memory is cacheline aligned.
44 */
Dean Nelson7682a4c2006-08-08 15:03:29 -050045void *
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050046xpc_kmalloc_cacheline_aligned(size_t size, gfp_t flags, void **base)
47{
48 /* see if kmalloc will give us cachline aligned memory by default */
49 *base = kmalloc(size, flags);
Dean Nelson2c2b94f2008-04-22 14:50:17 -050050 if (*base == NULL)
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050051 return NULL;
Dean Nelson2c2b94f2008-04-22 14:50:17 -050052
53 if ((u64)*base == L1_CACHE_ALIGN((u64)*base))
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050054 return *base;
Dean Nelson2c2b94f2008-04-22 14:50:17 -050055
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050056 kfree(*base);
57
58 /* nope, we'll have to do it ourselves */
59 *base = kmalloc(size + L1_CACHE_BYTES, flags);
Dean Nelson2c2b94f2008-04-22 14:50:17 -050060 if (*base == NULL)
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050061 return NULL;
Dean Nelson2c2b94f2008-04-22 14:50:17 -050062
Dean Nelson4a3ad2d2008-04-22 14:48:01 -050063 return (void *)L1_CACHE_ALIGN((u64)*base);
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050064}
65
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050066/*
Dean Nelson89eb8eb2005-03-23 19:50:00 -070067 * Given a nasid, get the physical address of the partition's reserved page
68 * for that nasid. This function returns 0 on any error.
69 */
70static u64
Dean Nelson27929022005-10-25 14:11:53 -050071xpc_get_rsvd_page_pa(int nasid)
Dean Nelson89eb8eb2005-03-23 19:50:00 -070072{
Dean Nelson908787d2008-07-29 22:34:05 -070073 enum xp_retval ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -070074 s64 status;
75 u64 cookie = 0;
76 u64 rp_pa = nasid; /* seed with nasid */
77 u64 len = 0;
Dean Nelson27929022005-10-25 14:11:53 -050078 u64 buf = buf;
79 u64 buf_len = 0;
80 void *buf_base = NULL;
Dean Nelson89eb8eb2005-03-23 19:50:00 -070081
Dean Nelson89eb8eb2005-03-23 19:50:00 -070082 while (1) {
83
84 status = sn_partition_reserved_page_pa(buf, &cookie, &rp_pa,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -050085 &len);
Dean Nelson89eb8eb2005-03-23 19:50:00 -070086
87 dev_dbg(xpc_part, "SAL returned with status=%li, cookie="
88 "0x%016lx, address=0x%016lx, len=0x%016lx\n",
89 status, cookie, rp_pa, len);
90
Dean Nelson2c2b94f2008-04-22 14:50:17 -050091 if (status != SALRET_MORE_PASSES)
Dean Nelson89eb8eb2005-03-23 19:50:00 -070092 break;
Dean Nelson89eb8eb2005-03-23 19:50:00 -070093
Dean Nelson908787d2008-07-29 22:34:05 -070094 /* >>> L1_CACHE_ALIGN() is only a sn2-bte_copy requirement */
Dean Nelson27929022005-10-25 14:11:53 -050095 if (L1_CACHE_ALIGN(len) > buf_len) {
Jesper Juhlcbf283c2006-04-20 10:11:09 -070096 kfree(buf_base);
Dean Nelson27929022005-10-25 14:11:53 -050097 buf_len = L1_CACHE_ALIGN(len);
Dean Nelson4a3ad2d2008-04-22 14:48:01 -050098 buf = (u64)xpc_kmalloc_cacheline_aligned(buf_len,
99 GFP_KERNEL,
100 &buf_base);
Dean Nelson27929022005-10-25 14:11:53 -0500101 if (buf_base == NULL) {
102 dev_err(xpc_part, "unable to kmalloc "
103 "len=0x%016lx\n", buf_len);
104 status = SALRET_ERROR;
105 break;
106 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700107 }
108
Dean Nelson908787d2008-07-29 22:34:05 -0700109 ret = xp_remote_memcpy((void *)buf, (void *)rp_pa, buf_len);
110 if (ret != xpSuccess) {
111 dev_dbg(xpc_part, "xp_remote_memcpy failed %d\n", ret);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700112 status = SALRET_ERROR;
113 break;
114 }
115 }
116
Jesper Juhlcbf283c2006-04-20 10:11:09 -0700117 kfree(buf_base);
Dean Nelson27929022005-10-25 14:11:53 -0500118
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500119 if (status != SALRET_OK)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700120 rp_pa = 0;
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500121
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700122 dev_dbg(xpc_part, "reserved page at phys address 0x%016lx\n", rp_pa);
123 return rp_pa;
124}
125
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700126/*
127 * Fill the partition reserved page with the information needed by
128 * other partitions to discover we are alive and establish initial
129 * communications.
130 */
131struct xpc_rsvd_page *
Dean Nelson94bd2702008-07-29 22:34:05 -0700132xpc_setup_rsvd_page(void)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700133{
134 struct xpc_rsvd_page *rp;
Dean Nelson94bd2702008-07-29 22:34:05 -0700135 u64 rp_pa;
Dean Nelsonaaa3cd62008-07-29 22:34:07 -0700136 unsigned long new_stamp;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700137
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700138 /* get the local reserved page's address */
139
Dean Nelson27929022005-10-25 14:11:53 -0500140 preempt_disable();
141 rp_pa = xpc_get_rsvd_page_pa(cpuid_to_nasid(smp_processor_id()));
142 preempt_enable();
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700143 if (rp_pa == 0) {
144 dev_err(xpc_part, "SAL failed to locate the reserved page\n");
145 return NULL;
146 }
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500147 rp = (struct xpc_rsvd_page *)__va(rp_pa);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700148
Dean Nelson94bd2702008-07-29 22:34:05 -0700149 if (rp->SAL_version < 3) {
150 /* SAL_versions < 3 had a SAL_partid defined as a u8 */
151 rp->SAL_partid &= 0xff;
152 }
153 BUG_ON(rp->SAL_partid != sn_partition_id);
154
155 if (rp->SAL_partid < 0 || rp->SAL_partid >= xp_max_npartitions) {
156 dev_err(xpc_part, "the reserved page's partid of %d is outside "
157 "supported range (< 0 || >= %d)\n", rp->SAL_partid,
158 xp_max_npartitions);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700159 return NULL;
160 }
161
162 rp->version = XPC_RP_VERSION;
Dean Nelson94bd2702008-07-29 22:34:05 -0700163 rp->max_npartitions = xp_max_npartitions;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700164
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500165 /* establish the actual sizes of the nasid masks */
166 if (rp->SAL_version == 1) {
167 /* SAL_version 1 didn't set the nasids_size field */
Dean Nelson94bd2702008-07-29 22:34:05 -0700168 rp->SAL_nasids_size = 128;
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500169 }
Dean Nelsonee6665e2008-07-29 22:34:13 -0700170 xpc_sizeof_nasid_mask = rp->SAL_nasids_size;
171 xpc_nasid_mask_words = DIV_ROUND_UP(xpc_sizeof_nasid_mask,
172 BYTES_PER_WORD);
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500173
174 /* setup the pointers to the various items in the reserved page */
175 xpc_part_nasids = XPC_RP_PART_NASIDS(rp);
176 xpc_mach_nasids = XPC_RP_MACH_NASIDS(rp);
Dean Nelson94bd2702008-07-29 22:34:05 -0700177
178 if (xpc_rsvd_page_init(rp) != xpSuccess)
179 return NULL;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700180
181 /*
Dean Nelson94bd2702008-07-29 22:34:05 -0700182 * Set timestamp of when reserved page was setup by XPC.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700183 * This signifies to the remote partition that our reserved
184 * page is initialized.
185 */
Dean Nelsonaaa3cd62008-07-29 22:34:07 -0700186 new_stamp = jiffies;
187 if (new_stamp == 0 || new_stamp == rp->stamp)
188 new_stamp++;
189 rp->stamp = new_stamp;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700190
191 return rp;
192}
193
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700194/*
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500195 * Get a copy of a portion of the remote partition's rsvd page.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700196 *
197 * remote_rp points to a buffer that is cacheline aligned for BTE copies and
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500198 * is large enough to contain a copy of their reserved page header and
199 * part_nasids mask.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700200 */
Dean Nelson33ba3c72008-07-29 22:34:07 -0700201enum xp_retval
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700202xpc_get_remote_rp(int nasid, u64 *discovered_nasids,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500203 struct xpc_rsvd_page *remote_rp, u64 *remote_rp_pa)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700204{
Dean Nelson908787d2008-07-29 22:34:05 -0700205 int i;
206 enum xp_retval ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700207
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700208 /* get the reserved page's physical address */
209
Dean Nelson27929022005-10-25 14:11:53 -0500210 *remote_rp_pa = xpc_get_rsvd_page_pa(nasid);
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500211 if (*remote_rp_pa == 0)
Dean Nelson65c17b82008-05-12 14:02:02 -0700212 return xpNoRsvdPageAddr;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700213
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500214 /* pull over the reserved page header and part_nasids mask */
Dean Nelson908787d2008-07-29 22:34:05 -0700215 ret = xp_remote_memcpy(remote_rp, (void *)*remote_rp_pa,
Dean Nelsonee6665e2008-07-29 22:34:13 -0700216 XPC_RP_HEADER_SIZE + xpc_sizeof_nasid_mask);
Dean Nelson908787d2008-07-29 22:34:05 -0700217 if (ret != xpSuccess)
218 return ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700219
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700220 if (discovered_nasids != NULL) {
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500221 u64 *remote_part_nasids = XPC_RP_PART_NASIDS(remote_rp);
222
Dean Nelsonee6665e2008-07-29 22:34:13 -0700223 for (i = 0; i < xpc_nasid_mask_words; i++)
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500224 discovered_nasids[i] |= remote_part_nasids[i];
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700225 }
226
Dean Nelsonaaa3cd62008-07-29 22:34:07 -0700227 /* see if the reserved page has been set up by XPC */
228 if (remote_rp->stamp == 0)
Dean Nelson94bd2702008-07-29 22:34:05 -0700229 return xpRsvdPageNotSet;
230
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700231 if (XPC_VERSION_MAJOR(remote_rp->version) !=
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500232 XPC_VERSION_MAJOR(XPC_RP_VERSION)) {
Dean Nelson65c17b82008-05-12 14:02:02 -0700233 return xpBadVersion;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700234 }
235
Dean Nelsona47d5da2008-07-29 22:34:09 -0700236 /* check that both remote and local partids are valid for each side */
Dean Nelsonaaa3cd62008-07-29 22:34:07 -0700237 if (remote_rp->SAL_partid < 0 ||
238 remote_rp->SAL_partid >= xp_max_npartitions ||
239 remote_rp->max_npartitions <= sn_partition_id) {
Dean Nelson94bd2702008-07-29 22:34:05 -0700240 return xpInvalidPartid;
Dean Nelsonaaa3cd62008-07-29 22:34:07 -0700241 }
242
243 if (remote_rp->SAL_partid == sn_partition_id)
244 return xpLocalPartid;
Dean Nelson94bd2702008-07-29 22:34:05 -0700245
Dean Nelson65c17b82008-05-12 14:02:02 -0700246 return xpSuccess;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700247}
248
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700249/*
Dean Nelsona47d5da2008-07-29 22:34:09 -0700250 * See if the other side has responded to a partition deactivate request
251 * from us. Though we requested the remote partition to deactivate with regard
252 * to us, we really only need to wait for the other side to disengage from us.
Dean Nelsona607c3892005-09-01 14:01:37 -0500253 */
254int
255xpc_partition_disengaged(struct xpc_partition *part)
256{
Dean Nelson64d032b2008-05-12 14:02:03 -0700257 short partid = XPC_PARTID(part);
Dean Nelsona607c3892005-09-01 14:01:37 -0500258 int disengaged;
259
Dean Nelsona47d5da2008-07-29 22:34:09 -0700260 disengaged = !xpc_partition_engaged(partid);
261 if (part->disengage_timeout) {
Dean Nelsona607c3892005-09-01 14:01:37 -0500262 if (!disengaged) {
Dean Nelsona47d5da2008-07-29 22:34:09 -0700263 if (time_is_after_jiffies(part->disengage_timeout)) {
Dean Nelsona607c3892005-09-01 14:01:37 -0500264 /* timelimit hasn't been reached yet */
265 return 0;
266 }
267
268 /*
Dean Nelsona47d5da2008-07-29 22:34:09 -0700269 * Other side hasn't responded to our deactivate
Dean Nelsona607c3892005-09-01 14:01:37 -0500270 * request in a timely fashion, so assume it's dead.
271 */
272
Dean Nelsona47d5da2008-07-29 22:34:09 -0700273 dev_info(xpc_part, "deactivate request to remote "
274 "partition %d timed out\n", partid);
275 xpc_disengage_timedout = 1;
276 xpc_assume_partition_disengaged(partid);
Dean Nelsona607c3892005-09-01 14:01:37 -0500277 disengaged = 1;
278 }
Dean Nelsona47d5da2008-07-29 22:34:09 -0700279 part->disengage_timeout = 0;
Dean Nelsona607c3892005-09-01 14:01:37 -0500280
281 /* cancel the timer function, provided it's not us */
Dean Nelsona47d5da2008-07-29 22:34:09 -0700282 if (!in_interrupt())
283 del_singleshot_timer_sync(&part->disengage_timer);
Dean Nelsona607c3892005-09-01 14:01:37 -0500284
285 DBUG_ON(part->act_state != XPC_P_DEACTIVATING &&
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500286 part->act_state != XPC_P_INACTIVE);
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500287 if (part->act_state != XPC_P_INACTIVE)
Dean Nelsona607c3892005-09-01 14:01:37 -0500288 xpc_wakeup_channel_mgr(part);
Dean Nelsona607c3892005-09-01 14:01:37 -0500289
Dean Nelsona47d5da2008-07-29 22:34:09 -0700290 xpc_cancel_partition_deactivation_request(part);
Dean Nelsona607c3892005-09-01 14:01:37 -0500291 }
292 return disengaged;
293}
294
Dean Nelsona607c3892005-09-01 14:01:37 -0500295/*
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700296 * Mark specified partition as active.
297 */
Dean Nelson65c17b82008-05-12 14:02:02 -0700298enum xp_retval
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700299xpc_mark_partition_active(struct xpc_partition *part)
300{
301 unsigned long irq_flags;
Dean Nelson65c17b82008-05-12 14:02:02 -0700302 enum xp_retval ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700303
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700304 dev_dbg(xpc_part, "setting partition %d to ACTIVE\n", XPC_PARTID(part));
305
306 spin_lock_irqsave(&part->act_lock, irq_flags);
307 if (part->act_state == XPC_P_ACTIVATING) {
308 part->act_state = XPC_P_ACTIVE;
Dean Nelson65c17b82008-05-12 14:02:02 -0700309 ret = xpSuccess;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700310 } else {
Dean Nelson65c17b82008-05-12 14:02:02 -0700311 DBUG_ON(part->reason == xpSuccess);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700312 ret = part->reason;
313 }
314 spin_unlock_irqrestore(&part->act_lock, irq_flags);
315
316 return ret;
317}
318
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700319/*
Dean Nelsona47d5da2008-07-29 22:34:09 -0700320 * Start the process of deactivating the specified partition.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700321 */
322void
323xpc_deactivate_partition(const int line, struct xpc_partition *part,
Dean Nelson65c17b82008-05-12 14:02:02 -0700324 enum xp_retval reason)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700325{
326 unsigned long irq_flags;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700327
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700328 spin_lock_irqsave(&part->act_lock, irq_flags);
329
330 if (part->act_state == XPC_P_INACTIVE) {
331 XPC_SET_REASON(part, reason, line);
332 spin_unlock_irqrestore(&part->act_lock, irq_flags);
Dean Nelson65c17b82008-05-12 14:02:02 -0700333 if (reason == xpReactivating) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700334 /* we interrupt ourselves to reactivate partition */
Dean Nelsona47d5da2008-07-29 22:34:09 -0700335 xpc_request_partition_reactivation(part);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700336 }
337 return;
338 }
339 if (part->act_state == XPC_P_DEACTIVATING) {
Dean Nelson65c17b82008-05-12 14:02:02 -0700340 if ((part->reason == xpUnloading && reason != xpUnloading) ||
341 reason == xpReactivating) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700342 XPC_SET_REASON(part, reason, line);
343 }
344 spin_unlock_irqrestore(&part->act_lock, irq_flags);
345 return;
346 }
347
348 part->act_state = XPC_P_DEACTIVATING;
349 XPC_SET_REASON(part, reason, line);
350
351 spin_unlock_irqrestore(&part->act_lock, irq_flags);
352
Dean Nelsona47d5da2008-07-29 22:34:09 -0700353 /* ask remote partition to deactivate with regard to us */
354 xpc_request_partition_deactivation(part);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700355
Dean Nelsona47d5da2008-07-29 22:34:09 -0700356 /* set a timelimit on the disengage phase of the deactivation request */
357 part->disengage_timeout = jiffies + (xpc_disengage_timelimit * HZ);
358 part->disengage_timer.expires = part->disengage_timeout;
359 add_timer(&part->disengage_timer);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700360
Dean Nelsone54af722005-10-25 14:07:43 -0500361 dev_dbg(xpc_part, "bringing partition %d down, reason = %d\n",
362 XPC_PARTID(part), reason);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700363
Dean Nelsona607c3892005-09-01 14:01:37 -0500364 xpc_partition_going_down(part, reason);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700365}
366
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700367/*
Dean Nelsona607c3892005-09-01 14:01:37 -0500368 * Mark specified partition as inactive.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700369 */
370void
371xpc_mark_partition_inactive(struct xpc_partition *part)
372{
373 unsigned long irq_flags;
374
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700375 dev_dbg(xpc_part, "setting partition %d to INACTIVE\n",
376 XPC_PARTID(part));
377
378 spin_lock_irqsave(&part->act_lock, irq_flags);
379 part->act_state = XPC_P_INACTIVE;
380 spin_unlock_irqrestore(&part->act_lock, irq_flags);
381 part->remote_rp_pa = 0;
382}
383
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700384/*
385 * SAL has provided a partition and machine mask. The partition mask
386 * contains a bit for each even nasid in our partition. The machine
387 * mask contains a bit for each even nasid in the entire machine.
388 *
389 * Using those two bit arrays, we can determine which nasids are
390 * known in the machine. Each should also have a reserved page
391 * initialized if they are available for partitioning.
392 */
393void
394xpc_discovery(void)
395{
396 void *remote_rp_base;
397 struct xpc_rsvd_page *remote_rp;
Dean Nelsona607c3892005-09-01 14:01:37 -0500398 u64 remote_rp_pa;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700399 int region;
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500400 int region_size;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700401 int max_regions;
402 int nasid;
403 struct xpc_rsvd_page *rp;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700404 u64 *discovered_nasids;
Dean Nelson65c17b82008-05-12 14:02:02 -0700405 enum xp_retval ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700406
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500407 remote_rp = xpc_kmalloc_cacheline_aligned(XPC_RP_HEADER_SIZE +
Dean Nelsonee6665e2008-07-29 22:34:13 -0700408 xpc_sizeof_nasid_mask,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500409 GFP_KERNEL, &remote_rp_base);
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500410 if (remote_rp == NULL)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700411 return;
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500412
Dean Nelsonee6665e2008-07-29 22:34:13 -0700413 discovered_nasids = kzalloc(sizeof(u64) * xpc_nasid_mask_words,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500414 GFP_KERNEL);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700415 if (discovered_nasids == NULL) {
416 kfree(remote_rp_base);
417 return;
418 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700419
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500420 rp = (struct xpc_rsvd_page *)xpc_rsvd_page;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700421
422 /*
423 * The term 'region' in this context refers to the minimum number of
424 * nodes that can comprise an access protection grouping. The access
425 * protection is in regards to memory, IOI and IPI.
426 */
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500427 max_regions = 64;
428 region_size = sn_region_size;
429
430 switch (region_size) {
431 case 128:
432 max_regions *= 2;
433 case 64:
434 max_regions *= 2;
435 case 32:
436 max_regions *= 2;
437 region_size = 16;
438 DBUG_ON(!is_shub2());
439 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700440
441 for (region = 0; region < max_regions; region++) {
442
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500443 if (xpc_exiting)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700444 break;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700445
446 dev_dbg(xpc_part, "searching region %d\n", region);
447
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500448 for (nasid = (region * region_size * 2);
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500449 nasid < ((region + 1) * region_size * 2); nasid += 2) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700450
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500451 if (xpc_exiting)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700452 break;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700453
454 dev_dbg(xpc_part, "checking nasid %d\n", nasid);
455
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500456 if (XPC_NASID_IN_ARRAY(nasid, xpc_part_nasids)) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700457 dev_dbg(xpc_part, "PROM indicates Nasid %d is "
458 "part of the local partition; skipping "
459 "region\n", nasid);
460 break;
461 }
462
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500463 if (!(XPC_NASID_IN_ARRAY(nasid, xpc_mach_nasids))) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700464 dev_dbg(xpc_part, "PROM indicates Nasid %d was "
465 "not on Numa-Link network at reset\n",
466 nasid);
467 continue;
468 }
469
470 if (XPC_NASID_IN_ARRAY(nasid, discovered_nasids)) {
471 dev_dbg(xpc_part, "Nasid %d is part of a "
472 "partition which was previously "
473 "discovered\n", nasid);
474 continue;
475 }
476
Dean Nelson33ba3c72008-07-29 22:34:07 -0700477 /* pull over the rsvd page header & part_nasids mask */
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700478
479 ret = xpc_get_remote_rp(nasid, discovered_nasids,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500480 remote_rp, &remote_rp_pa);
Dean Nelson65c17b82008-05-12 14:02:02 -0700481 if (ret != xpSuccess) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700482 dev_dbg(xpc_part, "unable to get reserved page "
483 "from nasid %d, reason=%d\n", nasid,
484 ret);
485
Dean Nelson65c17b82008-05-12 14:02:02 -0700486 if (ret == xpLocalPartid)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700487 break;
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500488
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700489 continue;
490 }
491
Dean Nelsona47d5da2008-07-29 22:34:09 -0700492 xpc_request_partition_activation(remote_rp,
493 remote_rp_pa, nasid);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700494 }
495 }
496
497 kfree(discovered_nasids);
498 kfree(remote_rp_base);
499}
500
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700501/*
502 * Given a partid, get the nasids owned by that partition from the
Dean Nelson3a7d5552005-04-04 13:14:00 -0700503 * remote partition's reserved page.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700504 */
Dean Nelson65c17b82008-05-12 14:02:02 -0700505enum xp_retval
Dean Nelson64d032b2008-05-12 14:02:03 -0700506xpc_initiate_partid_to_nasids(short partid, void *nasid_mask)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700507{
508 struct xpc_partition *part;
509 u64 part_nasid_pa;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700510
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700511 part = &xpc_partitions[partid];
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500512 if (part->remote_rp_pa == 0)
Dean Nelson65c17b82008-05-12 14:02:02 -0700513 return xpPartitionDown;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700514
Dean Nelsonee6665e2008-07-29 22:34:13 -0700515 memset(nasid_mask, 0, xpc_sizeof_nasid_mask);
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500516
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500517 part_nasid_pa = (u64)XPC_RP_PART_NASIDS(part->remote_rp_pa);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700518
Dean Nelson908787d2008-07-29 22:34:05 -0700519 return xp_remote_memcpy(nasid_mask, (void *)part_nasid_pa,
Dean Nelsonee6665e2008-07-29 22:34:13 -0700520 xpc_sizeof_nasid_mask);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700521}