blob: f150dbfcfcc7b627a98301cca4deac83e980a966 [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 Nelson261f3b42008-07-29 22:34:16 -070018#include <linux/device.h>
19#include <linux/hardirq.h>
Dean Nelson45d9ca42008-04-22 14:46:56 -050020#include "xpc.h"
Dean Nelson89eb8eb2005-03-23 19:50:00 -070021
Dean Nelson89eb8eb2005-03-23 19:50:00 -070022/* XPC is exiting flag */
23int xpc_exiting;
24
Dean Nelson4b38fcd2005-10-25 14:09:51 -050025/* this partition's reserved page pointers */
Dean Nelson89eb8eb2005-03-23 19:50:00 -070026struct xpc_rsvd_page *xpc_rsvd_page;
Dean Nelson04de7412008-07-29 22:34:14 -070027static unsigned long *xpc_part_nasids;
28unsigned long *xpc_mach_nasids;
Dean Nelson89eb8eb2005-03-23 19:50:00 -070029
Dean Nelson04de7412008-07-29 22:34:14 -070030static int xpc_nasid_mask_nbytes; /* #of bytes in nasid mask */
31int xpc_nasid_mask_nlongs; /* #of longs in nasid mask */
Dean Nelson4b38fcd2005-10-25 14:09:51 -050032
Dean Nelsonbc63d382008-07-29 22:34:04 -070033struct xpc_partition *xpc_partitions;
Dean Nelson89eb8eb2005-03-23 19:50:00 -070034
Dean Nelson89eb8eb2005-03-23 19:50:00 -070035/*
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050036 * Guarantee that the kmalloc'd memory is cacheline aligned.
37 */
Dean Nelson7682a4c2006-08-08 15:03:29 -050038void *
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050039xpc_kmalloc_cacheline_aligned(size_t size, gfp_t flags, void **base)
40{
41 /* see if kmalloc will give us cachline aligned memory by default */
42 *base = kmalloc(size, flags);
Dean Nelson2c2b94f2008-04-22 14:50:17 -050043 if (*base == NULL)
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050044 return NULL;
Dean Nelson2c2b94f2008-04-22 14:50:17 -050045
46 if ((u64)*base == L1_CACHE_ALIGN((u64)*base))
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050047 return *base;
Dean Nelson2c2b94f2008-04-22 14:50:17 -050048
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050049 kfree(*base);
50
51 /* nope, we'll have to do it ourselves */
52 *base = kmalloc(size + L1_CACHE_BYTES, flags);
Dean Nelson2c2b94f2008-04-22 14:50:17 -050053 if (*base == NULL)
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050054 return NULL;
Dean Nelson2c2b94f2008-04-22 14:50:17 -050055
Dean Nelson4a3ad2d2008-04-22 14:48:01 -050056 return (void *)L1_CACHE_ALIGN((u64)*base);
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050057}
58
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050059/*
Dean Nelson89eb8eb2005-03-23 19:50:00 -070060 * Given a nasid, get the physical address of the partition's reserved page
61 * for that nasid. This function returns 0 on any error.
62 */
Dean Nelsona812dcc2008-07-29 22:34:16 -070063static unsigned long
Dean Nelson27929022005-10-25 14:11:53 -050064xpc_get_rsvd_page_pa(int nasid)
Dean Nelson89eb8eb2005-03-23 19:50:00 -070065{
Dean Nelson908787d2008-07-29 22:34:05 -070066 enum xp_retval ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -070067 u64 cookie = 0;
Dean Nelsona812dcc2008-07-29 22:34:16 -070068 unsigned long rp_pa = nasid; /* seed with nasid */
Dean Nelson261f3b42008-07-29 22:34:16 -070069 size_t len = 0;
Dean Nelsona812dcc2008-07-29 22:34:16 -070070 size_t buf_len = 0;
71 void *buf = buf;
Dean Nelson27929022005-10-25 14:11:53 -050072 void *buf_base = NULL;
Dean Nelson89eb8eb2005-03-23 19:50:00 -070073
Dean Nelson89eb8eb2005-03-23 19:50:00 -070074 while (1) {
75
Dean Nelson261f3b42008-07-29 22:34:16 -070076 ret = xpc_get_partition_rsvd_page_pa(buf, &cookie, &rp_pa,
77 &len);
Dean Nelson89eb8eb2005-03-23 19:50:00 -070078
Dean Nelson261f3b42008-07-29 22:34:16 -070079 dev_dbg(xpc_part, "SAL returned with ret=%d, cookie=0x%016lx, "
80 "address=0x%016lx, len=0x%016lx\n", ret,
Dean Nelsona812dcc2008-07-29 22:34:16 -070081 (unsigned long)cookie, rp_pa, len);
Dean Nelson89eb8eb2005-03-23 19:50:00 -070082
Dean Nelson261f3b42008-07-29 22:34:16 -070083 if (ret != xpNeedMoreInfo)
Dean Nelson89eb8eb2005-03-23 19:50:00 -070084 break;
Dean Nelson89eb8eb2005-03-23 19:50:00 -070085
Dean Nelsonea57f802008-07-29 22:34:14 -070086 /* !!! L1_CACHE_ALIGN() is only a sn2-bte_copy requirement */
Dean Nelson27929022005-10-25 14:11:53 -050087 if (L1_CACHE_ALIGN(len) > buf_len) {
Jesper Juhlcbf283c2006-04-20 10:11:09 -070088 kfree(buf_base);
Dean Nelson27929022005-10-25 14:11:53 -050089 buf_len = L1_CACHE_ALIGN(len);
Dean Nelsona812dcc2008-07-29 22:34:16 -070090 buf = xpc_kmalloc_cacheline_aligned(buf_len, GFP_KERNEL,
91 &buf_base);
Dean Nelson27929022005-10-25 14:11:53 -050092 if (buf_base == NULL) {
93 dev_err(xpc_part, "unable to kmalloc "
Dean Nelsona812dcc2008-07-29 22:34:16 -070094 "len=0x%016lx\n", buf_len);
Dean Nelson261f3b42008-07-29 22:34:16 -070095 ret = xpNoMemory;
Dean Nelson27929022005-10-25 14:11:53 -050096 break;
97 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -070098 }
99
Dean Nelsona812dcc2008-07-29 22:34:16 -0700100 ret = xp_remote_memcpy(xp_pa(buf), rp_pa, buf_len);
Dean Nelson908787d2008-07-29 22:34:05 -0700101 if (ret != xpSuccess) {
102 dev_dbg(xpc_part, "xp_remote_memcpy failed %d\n", ret);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700103 break;
104 }
105 }
106
Jesper Juhlcbf283c2006-04-20 10:11:09 -0700107 kfree(buf_base);
Dean Nelson27929022005-10-25 14:11:53 -0500108
Dean Nelson261f3b42008-07-29 22:34:16 -0700109 if (ret != xpSuccess)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700110 rp_pa = 0;
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500111
Dean Nelsona812dcc2008-07-29 22:34:16 -0700112 dev_dbg(xpc_part, "reserved page at phys address 0x%016lx\n", rp_pa);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700113 return rp_pa;
114}
115
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700116/*
117 * Fill the partition reserved page with the information needed by
118 * other partitions to discover we are alive and establish initial
119 * communications.
120 */
121struct xpc_rsvd_page *
Dean Nelson94bd2702008-07-29 22:34:05 -0700122xpc_setup_rsvd_page(void)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700123{
124 struct xpc_rsvd_page *rp;
Dean Nelsona812dcc2008-07-29 22:34:16 -0700125 unsigned long rp_pa;
Dean Nelson81fe7882008-07-29 22:34:15 -0700126 unsigned long new_ts_jiffies;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700127
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700128 /* get the local reserved page's address */
129
Dean Nelson27929022005-10-25 14:11:53 -0500130 preempt_disable();
Dean Nelson261f3b42008-07-29 22:34:16 -0700131 rp_pa = xpc_get_rsvd_page_pa(xp_cpu_to_nasid(smp_processor_id()));
Dean Nelson27929022005-10-25 14:11:53 -0500132 preempt_enable();
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700133 if (rp_pa == 0) {
134 dev_err(xpc_part, "SAL failed to locate the reserved page\n");
135 return NULL;
136 }
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500137 rp = (struct xpc_rsvd_page *)__va(rp_pa);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700138
Dean Nelson94bd2702008-07-29 22:34:05 -0700139 if (rp->SAL_version < 3) {
140 /* SAL_versions < 3 had a SAL_partid defined as a u8 */
141 rp->SAL_partid &= 0xff;
142 }
Dean Nelson261f3b42008-07-29 22:34:16 -0700143 BUG_ON(rp->SAL_partid != xp_partition_id);
Dean Nelson94bd2702008-07-29 22:34:05 -0700144
145 if (rp->SAL_partid < 0 || rp->SAL_partid >= xp_max_npartitions) {
146 dev_err(xpc_part, "the reserved page's partid of %d is outside "
147 "supported range (< 0 || >= %d)\n", rp->SAL_partid,
148 xp_max_npartitions);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700149 return NULL;
150 }
151
152 rp->version = XPC_RP_VERSION;
Dean Nelson94bd2702008-07-29 22:34:05 -0700153 rp->max_npartitions = xp_max_npartitions;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700154
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500155 /* establish the actual sizes of the nasid masks */
156 if (rp->SAL_version == 1) {
157 /* SAL_version 1 didn't set the nasids_size field */
Dean Nelson94bd2702008-07-29 22:34:05 -0700158 rp->SAL_nasids_size = 128;
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500159 }
Dean Nelson04de7412008-07-29 22:34:14 -0700160 xpc_nasid_mask_nbytes = rp->SAL_nasids_size;
161 xpc_nasid_mask_nlongs = BITS_TO_LONGS(rp->SAL_nasids_size *
162 BITS_PER_BYTE);
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500163
164 /* setup the pointers to the various items in the reserved page */
165 xpc_part_nasids = XPC_RP_PART_NASIDS(rp);
166 xpc_mach_nasids = XPC_RP_MACH_NASIDS(rp);
Dean Nelson94bd2702008-07-29 22:34:05 -0700167
168 if (xpc_rsvd_page_init(rp) != xpSuccess)
169 return NULL;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700170
171 /*
Dean Nelson94bd2702008-07-29 22:34:05 -0700172 * Set timestamp of when reserved page was setup by XPC.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700173 * This signifies to the remote partition that our reserved
174 * page is initialized.
175 */
Dean Nelson81fe7882008-07-29 22:34:15 -0700176 new_ts_jiffies = jiffies;
177 if (new_ts_jiffies == 0 || new_ts_jiffies == rp->ts_jiffies)
178 new_ts_jiffies++;
179 rp->ts_jiffies = new_ts_jiffies;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700180
181 return rp;
182}
183
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700184/*
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500185 * Get a copy of a portion of the remote partition's rsvd page.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700186 *
187 * remote_rp points to a buffer that is cacheline aligned for BTE copies and
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500188 * is large enough to contain a copy of their reserved page header and
189 * part_nasids mask.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700190 */
Dean Nelson33ba3c72008-07-29 22:34:07 -0700191enum xp_retval
Dean Nelson04de7412008-07-29 22:34:14 -0700192xpc_get_remote_rp(int nasid, unsigned long *discovered_nasids,
Dean Nelsona812dcc2008-07-29 22:34:16 -0700193 struct xpc_rsvd_page *remote_rp, unsigned long *remote_rp_pa)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700194{
Dean Nelson04de7412008-07-29 22:34:14 -0700195 int l;
Dean Nelson908787d2008-07-29 22:34:05 -0700196 enum xp_retval ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700197
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700198 /* get the reserved page's physical address */
199
Dean Nelson27929022005-10-25 14:11:53 -0500200 *remote_rp_pa = xpc_get_rsvd_page_pa(nasid);
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500201 if (*remote_rp_pa == 0)
Dean Nelson65c17b82008-05-12 14:02:02 -0700202 return xpNoRsvdPageAddr;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700203
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500204 /* pull over the reserved page header and part_nasids mask */
Dean Nelsona812dcc2008-07-29 22:34:16 -0700205 ret = xp_remote_memcpy(xp_pa(remote_rp), *remote_rp_pa,
Dean Nelson04de7412008-07-29 22:34:14 -0700206 XPC_RP_HEADER_SIZE + xpc_nasid_mask_nbytes);
Dean Nelson908787d2008-07-29 22:34:05 -0700207 if (ret != xpSuccess)
208 return ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700209
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700210 if (discovered_nasids != NULL) {
Dean Nelson04de7412008-07-29 22:34:14 -0700211 unsigned long *remote_part_nasids =
212 XPC_RP_PART_NASIDS(remote_rp);
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500213
Dean Nelson04de7412008-07-29 22:34:14 -0700214 for (l = 0; l < xpc_nasid_mask_nlongs; l++)
215 discovered_nasids[l] |= remote_part_nasids[l];
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700216 }
217
Dean Nelson81fe7882008-07-29 22:34:15 -0700218 /* zero timestamp indicates the reserved page has not been setup */
219 if (remote_rp->ts_jiffies == 0)
Dean Nelson94bd2702008-07-29 22:34:05 -0700220 return xpRsvdPageNotSet;
221
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700222 if (XPC_VERSION_MAJOR(remote_rp->version) !=
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500223 XPC_VERSION_MAJOR(XPC_RP_VERSION)) {
Dean Nelson65c17b82008-05-12 14:02:02 -0700224 return xpBadVersion;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700225 }
226
Dean Nelsona47d5da2008-07-29 22:34:09 -0700227 /* check that both remote and local partids are valid for each side */
Dean Nelsonaaa3cd62008-07-29 22:34:07 -0700228 if (remote_rp->SAL_partid < 0 ||
229 remote_rp->SAL_partid >= xp_max_npartitions ||
Dean Nelson261f3b42008-07-29 22:34:16 -0700230 remote_rp->max_npartitions <= xp_partition_id) {
Dean Nelson94bd2702008-07-29 22:34:05 -0700231 return xpInvalidPartid;
Dean Nelsonaaa3cd62008-07-29 22:34:07 -0700232 }
233
Dean Nelson261f3b42008-07-29 22:34:16 -0700234 if (remote_rp->SAL_partid == xp_partition_id)
Dean Nelsonaaa3cd62008-07-29 22:34:07 -0700235 return xpLocalPartid;
Dean Nelson94bd2702008-07-29 22:34:05 -0700236
Dean Nelson65c17b82008-05-12 14:02:02 -0700237 return xpSuccess;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700238}
239
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700240/*
Dean Nelsona47d5da2008-07-29 22:34:09 -0700241 * See if the other side has responded to a partition deactivate request
242 * from us. Though we requested the remote partition to deactivate with regard
243 * to us, we really only need to wait for the other side to disengage from us.
Dean Nelsona607c3892005-09-01 14:01:37 -0500244 */
245int
246xpc_partition_disengaged(struct xpc_partition *part)
247{
Dean Nelson64d032b2008-05-12 14:02:03 -0700248 short partid = XPC_PARTID(part);
Dean Nelsona607c3892005-09-01 14:01:37 -0500249 int disengaged;
250
Dean Nelsona47d5da2008-07-29 22:34:09 -0700251 disengaged = !xpc_partition_engaged(partid);
252 if (part->disengage_timeout) {
Dean Nelsona607c3892005-09-01 14:01:37 -0500253 if (!disengaged) {
Dean Nelsona47d5da2008-07-29 22:34:09 -0700254 if (time_is_after_jiffies(part->disengage_timeout)) {
Dean Nelsona607c3892005-09-01 14:01:37 -0500255 /* timelimit hasn't been reached yet */
256 return 0;
257 }
258
259 /*
Dean Nelsona47d5da2008-07-29 22:34:09 -0700260 * Other side hasn't responded to our deactivate
Dean Nelsona607c3892005-09-01 14:01:37 -0500261 * request in a timely fashion, so assume it's dead.
262 */
263
Dean Nelsona47d5da2008-07-29 22:34:09 -0700264 dev_info(xpc_part, "deactivate request to remote "
265 "partition %d timed out\n", partid);
266 xpc_disengage_timedout = 1;
267 xpc_assume_partition_disengaged(partid);
Dean Nelsona607c3892005-09-01 14:01:37 -0500268 disengaged = 1;
269 }
Dean Nelsona47d5da2008-07-29 22:34:09 -0700270 part->disengage_timeout = 0;
Dean Nelsona607c3892005-09-01 14:01:37 -0500271
272 /* cancel the timer function, provided it's not us */
Dean Nelsona47d5da2008-07-29 22:34:09 -0700273 if (!in_interrupt())
274 del_singleshot_timer_sync(&part->disengage_timer);
Dean Nelsona607c3892005-09-01 14:01:37 -0500275
276 DBUG_ON(part->act_state != XPC_P_DEACTIVATING &&
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500277 part->act_state != XPC_P_INACTIVE);
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500278 if (part->act_state != XPC_P_INACTIVE)
Dean Nelsona607c3892005-09-01 14:01:37 -0500279 xpc_wakeup_channel_mgr(part);
Dean Nelsona607c3892005-09-01 14:01:37 -0500280
Dean Nelsona47d5da2008-07-29 22:34:09 -0700281 xpc_cancel_partition_deactivation_request(part);
Dean Nelsona607c3892005-09-01 14:01:37 -0500282 }
283 return disengaged;
284}
285
Dean Nelsona607c3892005-09-01 14:01:37 -0500286/*
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700287 * Mark specified partition as active.
288 */
Dean Nelson65c17b82008-05-12 14:02:02 -0700289enum xp_retval
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700290xpc_mark_partition_active(struct xpc_partition *part)
291{
292 unsigned long irq_flags;
Dean Nelson65c17b82008-05-12 14:02:02 -0700293 enum xp_retval ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700294
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700295 dev_dbg(xpc_part, "setting partition %d to ACTIVE\n", XPC_PARTID(part));
296
297 spin_lock_irqsave(&part->act_lock, irq_flags);
298 if (part->act_state == XPC_P_ACTIVATING) {
299 part->act_state = XPC_P_ACTIVE;
Dean Nelson65c17b82008-05-12 14:02:02 -0700300 ret = xpSuccess;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700301 } else {
Dean Nelson65c17b82008-05-12 14:02:02 -0700302 DBUG_ON(part->reason == xpSuccess);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700303 ret = part->reason;
304 }
305 spin_unlock_irqrestore(&part->act_lock, irq_flags);
306
307 return ret;
308}
309
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700310/*
Dean Nelsona47d5da2008-07-29 22:34:09 -0700311 * Start the process of deactivating the specified partition.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700312 */
313void
314xpc_deactivate_partition(const int line, struct xpc_partition *part,
Dean Nelson65c17b82008-05-12 14:02:02 -0700315 enum xp_retval reason)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700316{
317 unsigned long irq_flags;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700318
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700319 spin_lock_irqsave(&part->act_lock, irq_flags);
320
321 if (part->act_state == XPC_P_INACTIVE) {
322 XPC_SET_REASON(part, reason, line);
323 spin_unlock_irqrestore(&part->act_lock, irq_flags);
Dean Nelson65c17b82008-05-12 14:02:02 -0700324 if (reason == xpReactivating) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700325 /* we interrupt ourselves to reactivate partition */
Dean Nelsona47d5da2008-07-29 22:34:09 -0700326 xpc_request_partition_reactivation(part);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700327 }
328 return;
329 }
330 if (part->act_state == XPC_P_DEACTIVATING) {
Dean Nelson65c17b82008-05-12 14:02:02 -0700331 if ((part->reason == xpUnloading && reason != xpUnloading) ||
332 reason == xpReactivating) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700333 XPC_SET_REASON(part, reason, line);
334 }
335 spin_unlock_irqrestore(&part->act_lock, irq_flags);
336 return;
337 }
338
339 part->act_state = XPC_P_DEACTIVATING;
340 XPC_SET_REASON(part, reason, line);
341
342 spin_unlock_irqrestore(&part->act_lock, irq_flags);
343
Dean Nelsona47d5da2008-07-29 22:34:09 -0700344 /* ask remote partition to deactivate with regard to us */
345 xpc_request_partition_deactivation(part);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700346
Dean Nelsona47d5da2008-07-29 22:34:09 -0700347 /* set a timelimit on the disengage phase of the deactivation request */
348 part->disengage_timeout = jiffies + (xpc_disengage_timelimit * HZ);
349 part->disengage_timer.expires = part->disengage_timeout;
350 add_timer(&part->disengage_timer);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700351
Dean Nelsone54af722005-10-25 14:07:43 -0500352 dev_dbg(xpc_part, "bringing partition %d down, reason = %d\n",
353 XPC_PARTID(part), reason);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700354
Dean Nelsona607c3892005-09-01 14:01:37 -0500355 xpc_partition_going_down(part, reason);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700356}
357
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700358/*
Dean Nelsona607c3892005-09-01 14:01:37 -0500359 * Mark specified partition as inactive.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700360 */
361void
362xpc_mark_partition_inactive(struct xpc_partition *part)
363{
364 unsigned long irq_flags;
365
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700366 dev_dbg(xpc_part, "setting partition %d to INACTIVE\n",
367 XPC_PARTID(part));
368
369 spin_lock_irqsave(&part->act_lock, irq_flags);
370 part->act_state = XPC_P_INACTIVE;
371 spin_unlock_irqrestore(&part->act_lock, irq_flags);
372 part->remote_rp_pa = 0;
373}
374
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700375/*
376 * SAL has provided a partition and machine mask. The partition mask
377 * contains a bit for each even nasid in our partition. The machine
378 * mask contains a bit for each even nasid in the entire machine.
379 *
380 * Using those two bit arrays, we can determine which nasids are
381 * known in the machine. Each should also have a reserved page
382 * initialized if they are available for partitioning.
383 */
384void
385xpc_discovery(void)
386{
387 void *remote_rp_base;
388 struct xpc_rsvd_page *remote_rp;
Dean Nelsona812dcc2008-07-29 22:34:16 -0700389 unsigned long remote_rp_pa;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700390 int region;
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500391 int region_size;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700392 int max_regions;
393 int nasid;
394 struct xpc_rsvd_page *rp;
Dean Nelson04de7412008-07-29 22:34:14 -0700395 unsigned long *discovered_nasids;
Dean Nelson65c17b82008-05-12 14:02:02 -0700396 enum xp_retval ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700397
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500398 remote_rp = xpc_kmalloc_cacheline_aligned(XPC_RP_HEADER_SIZE +
Dean Nelson04de7412008-07-29 22:34:14 -0700399 xpc_nasid_mask_nbytes,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500400 GFP_KERNEL, &remote_rp_base);
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500401 if (remote_rp == NULL)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700402 return;
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500403
Dean Nelson04de7412008-07-29 22:34:14 -0700404 discovered_nasids = kzalloc(sizeof(long) * xpc_nasid_mask_nlongs,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500405 GFP_KERNEL);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700406 if (discovered_nasids == NULL) {
407 kfree(remote_rp_base);
408 return;
409 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700410
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500411 rp = (struct xpc_rsvd_page *)xpc_rsvd_page;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700412
413 /*
414 * The term 'region' in this context refers to the minimum number of
415 * nodes that can comprise an access protection grouping. The access
416 * protection is in regards to memory, IOI and IPI.
417 */
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500418 max_regions = 64;
Dean Nelson261f3b42008-07-29 22:34:16 -0700419 region_size = xp_region_size;
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500420
421 switch (region_size) {
422 case 128:
423 max_regions *= 2;
424 case 64:
425 max_regions *= 2;
426 case 32:
427 max_regions *= 2;
428 region_size = 16;
429 DBUG_ON(!is_shub2());
430 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700431
432 for (region = 0; region < max_regions; region++) {
433
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500434 if (xpc_exiting)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700435 break;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700436
437 dev_dbg(xpc_part, "searching region %d\n", region);
438
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500439 for (nasid = (region * region_size * 2);
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500440 nasid < ((region + 1) * region_size * 2); nasid += 2) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700441
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500442 if (xpc_exiting)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700443 break;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700444
445 dev_dbg(xpc_part, "checking nasid %d\n", nasid);
446
Dean Nelson04de7412008-07-29 22:34:14 -0700447 if (test_bit(nasid / 2, xpc_part_nasids)) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700448 dev_dbg(xpc_part, "PROM indicates Nasid %d is "
449 "part of the local partition; skipping "
450 "region\n", nasid);
451 break;
452 }
453
Dean Nelson04de7412008-07-29 22:34:14 -0700454 if (!(test_bit(nasid / 2, xpc_mach_nasids))) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700455 dev_dbg(xpc_part, "PROM indicates Nasid %d was "
456 "not on Numa-Link network at reset\n",
457 nasid);
458 continue;
459 }
460
Dean Nelson04de7412008-07-29 22:34:14 -0700461 if (test_bit(nasid / 2, discovered_nasids)) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700462 dev_dbg(xpc_part, "Nasid %d is part of a "
463 "partition which was previously "
464 "discovered\n", nasid);
465 continue;
466 }
467
Dean Nelson33ba3c72008-07-29 22:34:07 -0700468 /* pull over the rsvd page header & part_nasids mask */
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700469
470 ret = xpc_get_remote_rp(nasid, discovered_nasids,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500471 remote_rp, &remote_rp_pa);
Dean Nelson65c17b82008-05-12 14:02:02 -0700472 if (ret != xpSuccess) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700473 dev_dbg(xpc_part, "unable to get reserved page "
474 "from nasid %d, reason=%d\n", nasid,
475 ret);
476
Dean Nelson65c17b82008-05-12 14:02:02 -0700477 if (ret == xpLocalPartid)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700478 break;
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500479
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700480 continue;
481 }
482
Dean Nelsona47d5da2008-07-29 22:34:09 -0700483 xpc_request_partition_activation(remote_rp,
484 remote_rp_pa, nasid);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700485 }
486 }
487
488 kfree(discovered_nasids);
489 kfree(remote_rp_base);
490}
491
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700492/*
493 * Given a partid, get the nasids owned by that partition from the
Dean Nelson3a7d5552005-04-04 13:14:00 -0700494 * remote partition's reserved page.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700495 */
Dean Nelson65c17b82008-05-12 14:02:02 -0700496enum xp_retval
Dean Nelson64d032b2008-05-12 14:02:03 -0700497xpc_initiate_partid_to_nasids(short partid, void *nasid_mask)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700498{
499 struct xpc_partition *part;
Dean Nelsona812dcc2008-07-29 22:34:16 -0700500 unsigned long part_nasid_pa;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700501
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700502 part = &xpc_partitions[partid];
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500503 if (part->remote_rp_pa == 0)
Dean Nelson65c17b82008-05-12 14:02:02 -0700504 return xpPartitionDown;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700505
Dean Nelson04de7412008-07-29 22:34:14 -0700506 memset(nasid_mask, 0, xpc_nasid_mask_nbytes);
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500507
Dean Nelsona812dcc2008-07-29 22:34:16 -0700508 part_nasid_pa = (unsigned long)XPC_RP_PART_NASIDS(part->remote_rp_pa);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700509
Dean Nelsona812dcc2008-07-29 22:34:16 -0700510 return xp_remote_memcpy(xp_pa(nasid_mask), part_nasid_pa,
Dean Nelson04de7412008-07-29 22:34:14 -0700511 xpc_nasid_mask_nbytes);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700512}