blob: 70d4a00c97231a22bc5948a6197cf46a9eaa956e [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 Nelson04de7412008-07-29 22:34:14 -070034static unsigned long *xpc_part_nasids;
35unsigned long *xpc_mach_nasids;
Dean Nelson89eb8eb2005-03-23 19:50:00 -070036
Dean Nelson04de7412008-07-29 22:34:14 -070037static int xpc_nasid_mask_nbytes; /* #of bytes in nasid mask */
38int xpc_nasid_mask_nlongs; /* #of longs in 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 Nelsonea57f802008-07-29 22:34:14 -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 Nelson81fe7882008-07-29 22:34:15 -0700136 unsigned long new_ts_jiffies;
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 Nelson04de7412008-07-29 22:34:14 -0700170 xpc_nasid_mask_nbytes = rp->SAL_nasids_size;
171 xpc_nasid_mask_nlongs = BITS_TO_LONGS(rp->SAL_nasids_size *
172 BITS_PER_BYTE);
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 Nelson81fe7882008-07-29 22:34:15 -0700186 new_ts_jiffies = jiffies;
187 if (new_ts_jiffies == 0 || new_ts_jiffies == rp->ts_jiffies)
188 new_ts_jiffies++;
189 rp->ts_jiffies = new_ts_jiffies;
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 Nelson04de7412008-07-29 22:34:14 -0700202xpc_get_remote_rp(int nasid, unsigned long *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 Nelson04de7412008-07-29 22:34:14 -0700205 int l;
Dean Nelson908787d2008-07-29 22:34:05 -0700206 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 Nelson04de7412008-07-29 22:34:14 -0700216 XPC_RP_HEADER_SIZE + xpc_nasid_mask_nbytes);
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 Nelson04de7412008-07-29 22:34:14 -0700221 unsigned long *remote_part_nasids =
222 XPC_RP_PART_NASIDS(remote_rp);
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500223
Dean Nelson04de7412008-07-29 22:34:14 -0700224 for (l = 0; l < xpc_nasid_mask_nlongs; l++)
225 discovered_nasids[l] |= remote_part_nasids[l];
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700226 }
227
Dean Nelson81fe7882008-07-29 22:34:15 -0700228 /* zero timestamp indicates the reserved page has not been setup */
229 if (remote_rp->ts_jiffies == 0)
Dean Nelson94bd2702008-07-29 22:34:05 -0700230 return xpRsvdPageNotSet;
231
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700232 if (XPC_VERSION_MAJOR(remote_rp->version) !=
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500233 XPC_VERSION_MAJOR(XPC_RP_VERSION)) {
Dean Nelson65c17b82008-05-12 14:02:02 -0700234 return xpBadVersion;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700235 }
236
Dean Nelsona47d5da2008-07-29 22:34:09 -0700237 /* check that both remote and local partids are valid for each side */
Dean Nelsonaaa3cd62008-07-29 22:34:07 -0700238 if (remote_rp->SAL_partid < 0 ||
239 remote_rp->SAL_partid >= xp_max_npartitions ||
240 remote_rp->max_npartitions <= sn_partition_id) {
Dean Nelson94bd2702008-07-29 22:34:05 -0700241 return xpInvalidPartid;
Dean Nelsonaaa3cd62008-07-29 22:34:07 -0700242 }
243
244 if (remote_rp->SAL_partid == sn_partition_id)
245 return xpLocalPartid;
Dean Nelson94bd2702008-07-29 22:34:05 -0700246
Dean Nelson65c17b82008-05-12 14:02:02 -0700247 return xpSuccess;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700248}
249
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700250/*
Dean Nelsona47d5da2008-07-29 22:34:09 -0700251 * See if the other side has responded to a partition deactivate request
252 * from us. Though we requested the remote partition to deactivate with regard
253 * to us, we really only need to wait for the other side to disengage from us.
Dean Nelsona607c382005-09-01 14:01:37 -0500254 */
255int
256xpc_partition_disengaged(struct xpc_partition *part)
257{
Dean Nelson64d032b2008-05-12 14:02:03 -0700258 short partid = XPC_PARTID(part);
Dean Nelsona607c382005-09-01 14:01:37 -0500259 int disengaged;
260
Dean Nelsona47d5da2008-07-29 22:34:09 -0700261 disengaged = !xpc_partition_engaged(partid);
262 if (part->disengage_timeout) {
Dean Nelsona607c382005-09-01 14:01:37 -0500263 if (!disengaged) {
Dean Nelsona47d5da2008-07-29 22:34:09 -0700264 if (time_is_after_jiffies(part->disengage_timeout)) {
Dean Nelsona607c382005-09-01 14:01:37 -0500265 /* timelimit hasn't been reached yet */
266 return 0;
267 }
268
269 /*
Dean Nelsona47d5da2008-07-29 22:34:09 -0700270 * Other side hasn't responded to our deactivate
Dean Nelsona607c382005-09-01 14:01:37 -0500271 * request in a timely fashion, so assume it's dead.
272 */
273
Dean Nelsona47d5da2008-07-29 22:34:09 -0700274 dev_info(xpc_part, "deactivate request to remote "
275 "partition %d timed out\n", partid);
276 xpc_disengage_timedout = 1;
277 xpc_assume_partition_disengaged(partid);
Dean Nelsona607c382005-09-01 14:01:37 -0500278 disengaged = 1;
279 }
Dean Nelsona47d5da2008-07-29 22:34:09 -0700280 part->disengage_timeout = 0;
Dean Nelsona607c382005-09-01 14:01:37 -0500281
282 /* cancel the timer function, provided it's not us */
Dean Nelsona47d5da2008-07-29 22:34:09 -0700283 if (!in_interrupt())
284 del_singleshot_timer_sync(&part->disengage_timer);
Dean Nelsona607c382005-09-01 14:01:37 -0500285
286 DBUG_ON(part->act_state != XPC_P_DEACTIVATING &&
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500287 part->act_state != XPC_P_INACTIVE);
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500288 if (part->act_state != XPC_P_INACTIVE)
Dean Nelsona607c382005-09-01 14:01:37 -0500289 xpc_wakeup_channel_mgr(part);
Dean Nelsona607c382005-09-01 14:01:37 -0500290
Dean Nelsona47d5da2008-07-29 22:34:09 -0700291 xpc_cancel_partition_deactivation_request(part);
Dean Nelsona607c382005-09-01 14:01:37 -0500292 }
293 return disengaged;
294}
295
Dean Nelsona607c382005-09-01 14:01:37 -0500296/*
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700297 * Mark specified partition as active.
298 */
Dean Nelson65c17b82008-05-12 14:02:02 -0700299enum xp_retval
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700300xpc_mark_partition_active(struct xpc_partition *part)
301{
302 unsigned long irq_flags;
Dean Nelson65c17b82008-05-12 14:02:02 -0700303 enum xp_retval ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700304
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700305 dev_dbg(xpc_part, "setting partition %d to ACTIVE\n", XPC_PARTID(part));
306
307 spin_lock_irqsave(&part->act_lock, irq_flags);
308 if (part->act_state == XPC_P_ACTIVATING) {
309 part->act_state = XPC_P_ACTIVE;
Dean Nelson65c17b82008-05-12 14:02:02 -0700310 ret = xpSuccess;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700311 } else {
Dean Nelson65c17b82008-05-12 14:02:02 -0700312 DBUG_ON(part->reason == xpSuccess);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700313 ret = part->reason;
314 }
315 spin_unlock_irqrestore(&part->act_lock, irq_flags);
316
317 return ret;
318}
319
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700320/*
Dean Nelsona47d5da2008-07-29 22:34:09 -0700321 * Start the process of deactivating the specified partition.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700322 */
323void
324xpc_deactivate_partition(const int line, struct xpc_partition *part,
Dean Nelson65c17b82008-05-12 14:02:02 -0700325 enum xp_retval reason)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700326{
327 unsigned long irq_flags;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700328
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700329 spin_lock_irqsave(&part->act_lock, irq_flags);
330
331 if (part->act_state == XPC_P_INACTIVE) {
332 XPC_SET_REASON(part, reason, line);
333 spin_unlock_irqrestore(&part->act_lock, irq_flags);
Dean Nelson65c17b82008-05-12 14:02:02 -0700334 if (reason == xpReactivating) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700335 /* we interrupt ourselves to reactivate partition */
Dean Nelsona47d5da2008-07-29 22:34:09 -0700336 xpc_request_partition_reactivation(part);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700337 }
338 return;
339 }
340 if (part->act_state == XPC_P_DEACTIVATING) {
Dean Nelson65c17b82008-05-12 14:02:02 -0700341 if ((part->reason == xpUnloading && reason != xpUnloading) ||
342 reason == xpReactivating) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700343 XPC_SET_REASON(part, reason, line);
344 }
345 spin_unlock_irqrestore(&part->act_lock, irq_flags);
346 return;
347 }
348
349 part->act_state = XPC_P_DEACTIVATING;
350 XPC_SET_REASON(part, reason, line);
351
352 spin_unlock_irqrestore(&part->act_lock, irq_flags);
353
Dean Nelsona47d5da2008-07-29 22:34:09 -0700354 /* ask remote partition to deactivate with regard to us */
355 xpc_request_partition_deactivation(part);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700356
Dean Nelsona47d5da2008-07-29 22:34:09 -0700357 /* set a timelimit on the disengage phase of the deactivation request */
358 part->disengage_timeout = jiffies + (xpc_disengage_timelimit * HZ);
359 part->disengage_timer.expires = part->disengage_timeout;
360 add_timer(&part->disengage_timer);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700361
Dean Nelsone54af722005-10-25 14:07:43 -0500362 dev_dbg(xpc_part, "bringing partition %d down, reason = %d\n",
363 XPC_PARTID(part), reason);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700364
Dean Nelsona607c382005-09-01 14:01:37 -0500365 xpc_partition_going_down(part, reason);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700366}
367
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700368/*
Dean Nelsona607c382005-09-01 14:01:37 -0500369 * Mark specified partition as inactive.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700370 */
371void
372xpc_mark_partition_inactive(struct xpc_partition *part)
373{
374 unsigned long irq_flags;
375
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700376 dev_dbg(xpc_part, "setting partition %d to INACTIVE\n",
377 XPC_PARTID(part));
378
379 spin_lock_irqsave(&part->act_lock, irq_flags);
380 part->act_state = XPC_P_INACTIVE;
381 spin_unlock_irqrestore(&part->act_lock, irq_flags);
382 part->remote_rp_pa = 0;
383}
384
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700385/*
386 * SAL has provided a partition and machine mask. The partition mask
387 * contains a bit for each even nasid in our partition. The machine
388 * mask contains a bit for each even nasid in the entire machine.
389 *
390 * Using those two bit arrays, we can determine which nasids are
391 * known in the machine. Each should also have a reserved page
392 * initialized if they are available for partitioning.
393 */
394void
395xpc_discovery(void)
396{
397 void *remote_rp_base;
398 struct xpc_rsvd_page *remote_rp;
Dean Nelsona607c382005-09-01 14:01:37 -0500399 u64 remote_rp_pa;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700400 int region;
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500401 int region_size;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700402 int max_regions;
403 int nasid;
404 struct xpc_rsvd_page *rp;
Dean Nelson04de7412008-07-29 22:34:14 -0700405 unsigned long *discovered_nasids;
Dean Nelson65c17b82008-05-12 14:02:02 -0700406 enum xp_retval ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700407
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500408 remote_rp = xpc_kmalloc_cacheline_aligned(XPC_RP_HEADER_SIZE +
Dean Nelson04de7412008-07-29 22:34:14 -0700409 xpc_nasid_mask_nbytes,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500410 GFP_KERNEL, &remote_rp_base);
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500411 if (remote_rp == NULL)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700412 return;
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500413
Dean Nelson04de7412008-07-29 22:34:14 -0700414 discovered_nasids = kzalloc(sizeof(long) * xpc_nasid_mask_nlongs,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500415 GFP_KERNEL);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700416 if (discovered_nasids == NULL) {
417 kfree(remote_rp_base);
418 return;
419 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700420
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500421 rp = (struct xpc_rsvd_page *)xpc_rsvd_page;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700422
423 /*
424 * The term 'region' in this context refers to the minimum number of
425 * nodes that can comprise an access protection grouping. The access
426 * protection is in regards to memory, IOI and IPI.
427 */
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500428 max_regions = 64;
429 region_size = sn_region_size;
430
431 switch (region_size) {
432 case 128:
433 max_regions *= 2;
434 case 64:
435 max_regions *= 2;
436 case 32:
437 max_regions *= 2;
438 region_size = 16;
439 DBUG_ON(!is_shub2());
440 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700441
442 for (region = 0; region < max_regions; region++) {
443
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500444 if (xpc_exiting)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700445 break;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700446
447 dev_dbg(xpc_part, "searching region %d\n", region);
448
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500449 for (nasid = (region * region_size * 2);
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500450 nasid < ((region + 1) * region_size * 2); nasid += 2) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700451
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500452 if (xpc_exiting)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700453 break;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700454
455 dev_dbg(xpc_part, "checking nasid %d\n", nasid);
456
Dean Nelson04de7412008-07-29 22:34:14 -0700457 if (test_bit(nasid / 2, xpc_part_nasids)) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700458 dev_dbg(xpc_part, "PROM indicates Nasid %d is "
459 "part of the local partition; skipping "
460 "region\n", nasid);
461 break;
462 }
463
Dean Nelson04de7412008-07-29 22:34:14 -0700464 if (!(test_bit(nasid / 2, xpc_mach_nasids))) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700465 dev_dbg(xpc_part, "PROM indicates Nasid %d was "
466 "not on Numa-Link network at reset\n",
467 nasid);
468 continue;
469 }
470
Dean Nelson04de7412008-07-29 22:34:14 -0700471 if (test_bit(nasid / 2, discovered_nasids)) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700472 dev_dbg(xpc_part, "Nasid %d is part of a "
473 "partition which was previously "
474 "discovered\n", nasid);
475 continue;
476 }
477
Dean Nelson33ba3c72008-07-29 22:34:07 -0700478 /* pull over the rsvd page header & part_nasids mask */
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700479
480 ret = xpc_get_remote_rp(nasid, discovered_nasids,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500481 remote_rp, &remote_rp_pa);
Dean Nelson65c17b82008-05-12 14:02:02 -0700482 if (ret != xpSuccess) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700483 dev_dbg(xpc_part, "unable to get reserved page "
484 "from nasid %d, reason=%d\n", nasid,
485 ret);
486
Dean Nelson65c17b82008-05-12 14:02:02 -0700487 if (ret == xpLocalPartid)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700488 break;
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500489
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700490 continue;
491 }
492
Dean Nelsona47d5da2008-07-29 22:34:09 -0700493 xpc_request_partition_activation(remote_rp,
494 remote_rp_pa, nasid);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700495 }
496 }
497
498 kfree(discovered_nasids);
499 kfree(remote_rp_base);
500}
501
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700502/*
503 * Given a partid, get the nasids owned by that partition from the
Dean Nelson3a7d5552005-04-04 13:14:00 -0700504 * remote partition's reserved page.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700505 */
Dean Nelson65c17b82008-05-12 14:02:02 -0700506enum xp_retval
Dean Nelson64d032b2008-05-12 14:02:03 -0700507xpc_initiate_partid_to_nasids(short partid, void *nasid_mask)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700508{
509 struct xpc_partition *part;
510 u64 part_nasid_pa;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700511
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700512 part = &xpc_partitions[partid];
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500513 if (part->remote_rp_pa == 0)
Dean Nelson65c17b82008-05-12 14:02:02 -0700514 return xpPartitionDown;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700515
Dean Nelson04de7412008-07-29 22:34:14 -0700516 memset(nasid_mask, 0, xpc_nasid_mask_nbytes);
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500517
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500518 part_nasid_pa = (u64)XPC_RP_PART_NASIDS(part->remote_rp_pa);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700519
Dean Nelson908787d2008-07-29 22:34:05 -0700520 return xp_remote_memcpy(nasid_mask, (void *)part_nasid_pa,
Dean Nelson04de7412008-07-29 22:34:14 -0700521 xpc_nasid_mask_nbytes);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700522}