blob: c769ab8f74ef7bd06ab869050a998ce625d2971d [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 Nelson94bd2702008-07-29 22:34:05 -070037/* >>> next two variables should be 'xpc_' if they remain here */
38static int xp_sizeof_nasid_mask; /* actual size in bytes of nasid mask */
39int xp_nasid_mask_words; /* actual size in words of nasid mask */
Dean Nelson4b38fcd2005-10-25 14:09:51 -050040
Dean Nelsonbc63d382008-07-29 22:34:04 -070041struct xpc_partition *xpc_partitions;
Dean Nelson89eb8eb2005-03-23 19:50:00 -070042
Dean Nelson89eb8eb2005-03-23 19:50:00 -070043/*
Dean Nelson4b38fcd2005-10-25 14:09:51 -050044 * Generic buffer used to store a local copy of portions of a remote
45 * partition's reserved page (either its header and part_nasids mask,
46 * or its vars).
Dean Nelson89eb8eb2005-03-23 19:50:00 -070047 */
Dean Nelson7682a4c2006-08-08 15:03:29 -050048char *xpc_remote_copy_buffer;
49void *xpc_remote_copy_buffer_base;
Dean Nelson89eb8eb2005-03-23 19:50:00 -070050
Dean Nelson89eb8eb2005-03-23 19:50:00 -070051/*
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050052 * Guarantee that the kmalloc'd memory is cacheline aligned.
53 */
Dean Nelson7682a4c2006-08-08 15:03:29 -050054void *
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050055xpc_kmalloc_cacheline_aligned(size_t size, gfp_t flags, void **base)
56{
57 /* see if kmalloc will give us cachline aligned memory by default */
58 *base = kmalloc(size, flags);
Dean Nelson2c2b94f2008-04-22 14:50:17 -050059 if (*base == NULL)
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050060 return NULL;
Dean Nelson2c2b94f2008-04-22 14:50:17 -050061
62 if ((u64)*base == L1_CACHE_ALIGN((u64)*base))
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050063 return *base;
Dean Nelson2c2b94f2008-04-22 14:50:17 -050064
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050065 kfree(*base);
66
67 /* nope, we'll have to do it ourselves */
68 *base = kmalloc(size + L1_CACHE_BYTES, flags);
Dean Nelson2c2b94f2008-04-22 14:50:17 -050069 if (*base == NULL)
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050070 return NULL;
Dean Nelson2c2b94f2008-04-22 14:50:17 -050071
Dean Nelson4a3ad2d2008-04-22 14:48:01 -050072 return (void *)L1_CACHE_ALIGN((u64)*base);
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050073}
74
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050075/*
Dean Nelson89eb8eb2005-03-23 19:50:00 -070076 * Given a nasid, get the physical address of the partition's reserved page
77 * for that nasid. This function returns 0 on any error.
78 */
79static u64
Dean Nelson27929022005-10-25 14:11:53 -050080xpc_get_rsvd_page_pa(int nasid)
Dean Nelson89eb8eb2005-03-23 19:50:00 -070081{
Dean Nelson908787d2008-07-29 22:34:05 -070082 enum xp_retval ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -070083 s64 status;
84 u64 cookie = 0;
85 u64 rp_pa = nasid; /* seed with nasid */
86 u64 len = 0;
Dean Nelson27929022005-10-25 14:11:53 -050087 u64 buf = buf;
88 u64 buf_len = 0;
89 void *buf_base = NULL;
Dean Nelson89eb8eb2005-03-23 19:50:00 -070090
Dean Nelson89eb8eb2005-03-23 19:50:00 -070091 while (1) {
92
93 status = sn_partition_reserved_page_pa(buf, &cookie, &rp_pa,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -050094 &len);
Dean Nelson89eb8eb2005-03-23 19:50:00 -070095
96 dev_dbg(xpc_part, "SAL returned with status=%li, cookie="
97 "0x%016lx, address=0x%016lx, len=0x%016lx\n",
98 status, cookie, rp_pa, len);
99
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500100 if (status != SALRET_MORE_PASSES)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700101 break;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700102
Dean Nelson908787d2008-07-29 22:34:05 -0700103 /* >>> L1_CACHE_ALIGN() is only a sn2-bte_copy requirement */
Dean Nelson27929022005-10-25 14:11:53 -0500104 if (L1_CACHE_ALIGN(len) > buf_len) {
Jesper Juhlcbf283c2006-04-20 10:11:09 -0700105 kfree(buf_base);
Dean Nelson27929022005-10-25 14:11:53 -0500106 buf_len = L1_CACHE_ALIGN(len);
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500107 buf = (u64)xpc_kmalloc_cacheline_aligned(buf_len,
108 GFP_KERNEL,
109 &buf_base);
Dean Nelson27929022005-10-25 14:11:53 -0500110 if (buf_base == NULL) {
111 dev_err(xpc_part, "unable to kmalloc "
112 "len=0x%016lx\n", buf_len);
113 status = SALRET_ERROR;
114 break;
115 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700116 }
117
Dean Nelson908787d2008-07-29 22:34:05 -0700118 ret = xp_remote_memcpy((void *)buf, (void *)rp_pa, buf_len);
119 if (ret != xpSuccess) {
120 dev_dbg(xpc_part, "xp_remote_memcpy failed %d\n", ret);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700121 status = SALRET_ERROR;
122 break;
123 }
124 }
125
Jesper Juhlcbf283c2006-04-20 10:11:09 -0700126 kfree(buf_base);
Dean Nelson27929022005-10-25 14:11:53 -0500127
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500128 if (status != SALRET_OK)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700129 rp_pa = 0;
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500130
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700131 dev_dbg(xpc_part, "reserved page at phys address 0x%016lx\n", rp_pa);
132 return rp_pa;
133}
134
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700135/*
136 * Fill the partition reserved page with the information needed by
137 * other partitions to discover we are alive and establish initial
138 * communications.
139 */
140struct xpc_rsvd_page *
Dean Nelson94bd2702008-07-29 22:34:05 -0700141xpc_setup_rsvd_page(void)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700142{
143 struct xpc_rsvd_page *rp;
Dean Nelson94bd2702008-07-29 22:34:05 -0700144 u64 rp_pa;
Dean Nelsonaaa3cd62008-07-29 22:34:07 -0700145 unsigned long new_stamp;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700146
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700147 /* get the local reserved page's address */
148
Dean Nelson27929022005-10-25 14:11:53 -0500149 preempt_disable();
150 rp_pa = xpc_get_rsvd_page_pa(cpuid_to_nasid(smp_processor_id()));
151 preempt_enable();
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700152 if (rp_pa == 0) {
153 dev_err(xpc_part, "SAL failed to locate the reserved page\n");
154 return NULL;
155 }
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500156 rp = (struct xpc_rsvd_page *)__va(rp_pa);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700157
Dean Nelson94bd2702008-07-29 22:34:05 -0700158 if (rp->SAL_version < 3) {
159 /* SAL_versions < 3 had a SAL_partid defined as a u8 */
160 rp->SAL_partid &= 0xff;
161 }
162 BUG_ON(rp->SAL_partid != sn_partition_id);
163
164 if (rp->SAL_partid < 0 || rp->SAL_partid >= xp_max_npartitions) {
165 dev_err(xpc_part, "the reserved page's partid of %d is outside "
166 "supported range (< 0 || >= %d)\n", rp->SAL_partid,
167 xp_max_npartitions);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700168 return NULL;
169 }
170
171 rp->version = XPC_RP_VERSION;
Dean Nelson94bd2702008-07-29 22:34:05 -0700172 rp->max_npartitions = xp_max_npartitions;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700173
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500174 /* establish the actual sizes of the nasid masks */
175 if (rp->SAL_version == 1) {
176 /* SAL_version 1 didn't set the nasids_size field */
Dean Nelson94bd2702008-07-29 22:34:05 -0700177 rp->SAL_nasids_size = 128;
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500178 }
Dean Nelson94bd2702008-07-29 22:34:05 -0700179 xp_sizeof_nasid_mask = rp->SAL_nasids_size;
180 xp_nasid_mask_words = DIV_ROUND_UP(xp_sizeof_nasid_mask,
181 BYTES_PER_WORD);
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500182
183 /* setup the pointers to the various items in the reserved page */
184 xpc_part_nasids = XPC_RP_PART_NASIDS(rp);
185 xpc_mach_nasids = XPC_RP_MACH_NASIDS(rp);
Dean Nelson94bd2702008-07-29 22:34:05 -0700186
187 if (xpc_rsvd_page_init(rp) != xpSuccess)
188 return NULL;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700189
190 /*
Dean Nelson94bd2702008-07-29 22:34:05 -0700191 * Set timestamp of when reserved page was setup by XPC.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700192 * This signifies to the remote partition that our reserved
193 * page is initialized.
194 */
Dean Nelsonaaa3cd62008-07-29 22:34:07 -0700195 new_stamp = jiffies;
196 if (new_stamp == 0 || new_stamp == rp->stamp)
197 new_stamp++;
198 rp->stamp = new_stamp;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700199
200 return rp;
201}
202
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700203/*
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500204 * Get a copy of a portion of the remote partition's rsvd page.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700205 *
206 * remote_rp points to a buffer that is cacheline aligned for BTE copies and
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500207 * is large enough to contain a copy of their reserved page header and
208 * part_nasids mask.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700209 */
Dean Nelson33ba3c72008-07-29 22:34:07 -0700210enum xp_retval
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700211xpc_get_remote_rp(int nasid, u64 *discovered_nasids,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500212 struct xpc_rsvd_page *remote_rp, u64 *remote_rp_pa)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700213{
Dean Nelson908787d2008-07-29 22:34:05 -0700214 int i;
215 enum xp_retval ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700216
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700217 /* get the reserved page's physical address */
218
Dean Nelson27929022005-10-25 14:11:53 -0500219 *remote_rp_pa = xpc_get_rsvd_page_pa(nasid);
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500220 if (*remote_rp_pa == 0)
Dean Nelson65c17b82008-05-12 14:02:02 -0700221 return xpNoRsvdPageAddr;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700222
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500223 /* pull over the reserved page header and part_nasids mask */
Dean Nelson908787d2008-07-29 22:34:05 -0700224 ret = xp_remote_memcpy(remote_rp, (void *)*remote_rp_pa,
Dean Nelson94bd2702008-07-29 22:34:05 -0700225 XPC_RP_HEADER_SIZE + xp_sizeof_nasid_mask);
Dean Nelson908787d2008-07-29 22:34:05 -0700226 if (ret != xpSuccess)
227 return ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700228
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700229 if (discovered_nasids != NULL) {
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500230 u64 *remote_part_nasids = XPC_RP_PART_NASIDS(remote_rp);
231
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500232 for (i = 0; i < xp_nasid_mask_words; i++)
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500233 discovered_nasids[i] |= remote_part_nasids[i];
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700234 }
235
Dean Nelsonaaa3cd62008-07-29 22:34:07 -0700236 /* see if the reserved page has been set up by XPC */
237 if (remote_rp->stamp == 0)
Dean Nelson94bd2702008-07-29 22:34:05 -0700238 return xpRsvdPageNotSet;
239
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700240 if (XPC_VERSION_MAJOR(remote_rp->version) !=
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500241 XPC_VERSION_MAJOR(XPC_RP_VERSION)) {
Dean Nelson65c17b82008-05-12 14:02:02 -0700242 return xpBadVersion;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700243 }
244
Dean Nelsona47d5da2008-07-29 22:34:09 -0700245 /* check that both remote and local partids are valid for each side */
Dean Nelsonaaa3cd62008-07-29 22:34:07 -0700246 if (remote_rp->SAL_partid < 0 ||
247 remote_rp->SAL_partid >= xp_max_npartitions ||
248 remote_rp->max_npartitions <= sn_partition_id) {
Dean Nelson94bd2702008-07-29 22:34:05 -0700249 return xpInvalidPartid;
Dean Nelsonaaa3cd62008-07-29 22:34:07 -0700250 }
251
252 if (remote_rp->SAL_partid == sn_partition_id)
253 return xpLocalPartid;
Dean Nelson94bd2702008-07-29 22:34:05 -0700254
Dean Nelson65c17b82008-05-12 14:02:02 -0700255 return xpSuccess;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700256}
257
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700258/*
Dean Nelsona47d5da2008-07-29 22:34:09 -0700259 * See if the other side has responded to a partition deactivate request
260 * from us. Though we requested the remote partition to deactivate with regard
261 * to us, we really only need to wait for the other side to disengage from us.
Dean Nelsona607c382005-09-01 14:01:37 -0500262 */
263int
264xpc_partition_disengaged(struct xpc_partition *part)
265{
Dean Nelson64d032b2008-05-12 14:02:03 -0700266 short partid = XPC_PARTID(part);
Dean Nelsona607c382005-09-01 14:01:37 -0500267 int disengaged;
268
Dean Nelsona47d5da2008-07-29 22:34:09 -0700269 disengaged = !xpc_partition_engaged(partid);
270 if (part->disengage_timeout) {
Dean Nelsona607c382005-09-01 14:01:37 -0500271 if (!disengaged) {
Dean Nelsona47d5da2008-07-29 22:34:09 -0700272 if (time_is_after_jiffies(part->disengage_timeout)) {
Dean Nelsona607c382005-09-01 14:01:37 -0500273 /* timelimit hasn't been reached yet */
274 return 0;
275 }
276
277 /*
Dean Nelsona47d5da2008-07-29 22:34:09 -0700278 * Other side hasn't responded to our deactivate
Dean Nelsona607c382005-09-01 14:01:37 -0500279 * request in a timely fashion, so assume it's dead.
280 */
281
Dean Nelsona47d5da2008-07-29 22:34:09 -0700282 dev_info(xpc_part, "deactivate request to remote "
283 "partition %d timed out\n", partid);
284 xpc_disengage_timedout = 1;
285 xpc_assume_partition_disengaged(partid);
Dean Nelsona607c382005-09-01 14:01:37 -0500286 disengaged = 1;
287 }
Dean Nelsona47d5da2008-07-29 22:34:09 -0700288 part->disengage_timeout = 0;
Dean Nelsona607c382005-09-01 14:01:37 -0500289
290 /* cancel the timer function, provided it's not us */
Dean Nelsona47d5da2008-07-29 22:34:09 -0700291 if (!in_interrupt())
292 del_singleshot_timer_sync(&part->disengage_timer);
Dean Nelsona607c382005-09-01 14:01:37 -0500293
294 DBUG_ON(part->act_state != XPC_P_DEACTIVATING &&
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500295 part->act_state != XPC_P_INACTIVE);
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500296 if (part->act_state != XPC_P_INACTIVE)
Dean Nelsona607c382005-09-01 14:01:37 -0500297 xpc_wakeup_channel_mgr(part);
Dean Nelsona607c382005-09-01 14:01:37 -0500298
Dean Nelsona47d5da2008-07-29 22:34:09 -0700299 xpc_cancel_partition_deactivation_request(part);
Dean Nelsona607c382005-09-01 14:01:37 -0500300 }
301 return disengaged;
302}
303
Dean Nelsona607c382005-09-01 14:01:37 -0500304/*
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700305 * Mark specified partition as active.
306 */
Dean Nelson65c17b82008-05-12 14:02:02 -0700307enum xp_retval
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700308xpc_mark_partition_active(struct xpc_partition *part)
309{
310 unsigned long irq_flags;
Dean Nelson65c17b82008-05-12 14:02:02 -0700311 enum xp_retval ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700312
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700313 dev_dbg(xpc_part, "setting partition %d to ACTIVE\n", XPC_PARTID(part));
314
315 spin_lock_irqsave(&part->act_lock, irq_flags);
316 if (part->act_state == XPC_P_ACTIVATING) {
317 part->act_state = XPC_P_ACTIVE;
Dean Nelson65c17b82008-05-12 14:02:02 -0700318 ret = xpSuccess;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700319 } else {
Dean Nelson65c17b82008-05-12 14:02:02 -0700320 DBUG_ON(part->reason == xpSuccess);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700321 ret = part->reason;
322 }
323 spin_unlock_irqrestore(&part->act_lock, irq_flags);
324
325 return ret;
326}
327
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700328/*
Dean Nelsona47d5da2008-07-29 22:34:09 -0700329 * Start the process of deactivating the specified partition.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700330 */
331void
332xpc_deactivate_partition(const int line, struct xpc_partition *part,
Dean Nelson65c17b82008-05-12 14:02:02 -0700333 enum xp_retval reason)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700334{
335 unsigned long irq_flags;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700336
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700337 spin_lock_irqsave(&part->act_lock, irq_flags);
338
339 if (part->act_state == XPC_P_INACTIVE) {
340 XPC_SET_REASON(part, reason, line);
341 spin_unlock_irqrestore(&part->act_lock, irq_flags);
Dean Nelson65c17b82008-05-12 14:02:02 -0700342 if (reason == xpReactivating) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700343 /* we interrupt ourselves to reactivate partition */
Dean Nelsona47d5da2008-07-29 22:34:09 -0700344 xpc_request_partition_reactivation(part);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700345 }
346 return;
347 }
348 if (part->act_state == XPC_P_DEACTIVATING) {
Dean Nelson65c17b82008-05-12 14:02:02 -0700349 if ((part->reason == xpUnloading && reason != xpUnloading) ||
350 reason == xpReactivating) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700351 XPC_SET_REASON(part, reason, line);
352 }
353 spin_unlock_irqrestore(&part->act_lock, irq_flags);
354 return;
355 }
356
357 part->act_state = XPC_P_DEACTIVATING;
358 XPC_SET_REASON(part, reason, line);
359
360 spin_unlock_irqrestore(&part->act_lock, irq_flags);
361
Dean Nelsona47d5da2008-07-29 22:34:09 -0700362 /* ask remote partition to deactivate with regard to us */
363 xpc_request_partition_deactivation(part);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700364
Dean Nelsona47d5da2008-07-29 22:34:09 -0700365 /* set a timelimit on the disengage phase of the deactivation request */
366 part->disengage_timeout = jiffies + (xpc_disengage_timelimit * HZ);
367 part->disengage_timer.expires = part->disengage_timeout;
368 add_timer(&part->disengage_timer);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700369
Dean Nelsone54af722005-10-25 14:07:43 -0500370 dev_dbg(xpc_part, "bringing partition %d down, reason = %d\n",
371 XPC_PARTID(part), reason);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700372
Dean Nelsona607c382005-09-01 14:01:37 -0500373 xpc_partition_going_down(part, reason);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700374}
375
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700376/*
Dean Nelsona607c382005-09-01 14:01:37 -0500377 * Mark specified partition as inactive.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700378 */
379void
380xpc_mark_partition_inactive(struct xpc_partition *part)
381{
382 unsigned long irq_flags;
383
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700384 dev_dbg(xpc_part, "setting partition %d to INACTIVE\n",
385 XPC_PARTID(part));
386
387 spin_lock_irqsave(&part->act_lock, irq_flags);
388 part->act_state = XPC_P_INACTIVE;
389 spin_unlock_irqrestore(&part->act_lock, irq_flags);
390 part->remote_rp_pa = 0;
391}
392
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700393/*
394 * SAL has provided a partition and machine mask. The partition mask
395 * contains a bit for each even nasid in our partition. The machine
396 * mask contains a bit for each even nasid in the entire machine.
397 *
398 * Using those two bit arrays, we can determine which nasids are
399 * known in the machine. Each should also have a reserved page
400 * initialized if they are available for partitioning.
401 */
402void
403xpc_discovery(void)
404{
405 void *remote_rp_base;
406 struct xpc_rsvd_page *remote_rp;
Dean Nelsona607c382005-09-01 14:01:37 -0500407 u64 remote_rp_pa;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700408 int region;
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500409 int region_size;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700410 int max_regions;
411 int nasid;
412 struct xpc_rsvd_page *rp;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700413 u64 *discovered_nasids;
Dean Nelson65c17b82008-05-12 14:02:02 -0700414 enum xp_retval ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700415
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500416 remote_rp = xpc_kmalloc_cacheline_aligned(XPC_RP_HEADER_SIZE +
Dean Nelson94bd2702008-07-29 22:34:05 -0700417 xp_sizeof_nasid_mask,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500418 GFP_KERNEL, &remote_rp_base);
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500419 if (remote_rp == NULL)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700420 return;
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500421
Jes Sorensen7aa6ba42006-02-17 05:18:43 -0500422 discovered_nasids = kzalloc(sizeof(u64) * xp_nasid_mask_words,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500423 GFP_KERNEL);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700424 if (discovered_nasids == NULL) {
425 kfree(remote_rp_base);
426 return;
427 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700428
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500429 rp = (struct xpc_rsvd_page *)xpc_rsvd_page;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700430
431 /*
432 * The term 'region' in this context refers to the minimum number of
433 * nodes that can comprise an access protection grouping. The access
434 * protection is in regards to memory, IOI and IPI.
435 */
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500436 max_regions = 64;
437 region_size = sn_region_size;
438
439 switch (region_size) {
440 case 128:
441 max_regions *= 2;
442 case 64:
443 max_regions *= 2;
444 case 32:
445 max_regions *= 2;
446 region_size = 16;
447 DBUG_ON(!is_shub2());
448 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700449
450 for (region = 0; region < max_regions; region++) {
451
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, "searching region %d\n", region);
456
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500457 for (nasid = (region * region_size * 2);
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500458 nasid < ((region + 1) * region_size * 2); nasid += 2) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700459
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500460 if (xpc_exiting)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700461 break;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700462
463 dev_dbg(xpc_part, "checking nasid %d\n", nasid);
464
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500465 if (XPC_NASID_IN_ARRAY(nasid, xpc_part_nasids)) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700466 dev_dbg(xpc_part, "PROM indicates Nasid %d is "
467 "part of the local partition; skipping "
468 "region\n", nasid);
469 break;
470 }
471
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500472 if (!(XPC_NASID_IN_ARRAY(nasid, xpc_mach_nasids))) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700473 dev_dbg(xpc_part, "PROM indicates Nasid %d was "
474 "not on Numa-Link network at reset\n",
475 nasid);
476 continue;
477 }
478
479 if (XPC_NASID_IN_ARRAY(nasid, discovered_nasids)) {
480 dev_dbg(xpc_part, "Nasid %d is part of a "
481 "partition which was previously "
482 "discovered\n", nasid);
483 continue;
484 }
485
Dean Nelson33ba3c72008-07-29 22:34:07 -0700486 /* pull over the rsvd page header & part_nasids mask */
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700487
488 ret = xpc_get_remote_rp(nasid, discovered_nasids,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500489 remote_rp, &remote_rp_pa);
Dean Nelson65c17b82008-05-12 14:02:02 -0700490 if (ret != xpSuccess) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700491 dev_dbg(xpc_part, "unable to get reserved page "
492 "from nasid %d, reason=%d\n", nasid,
493 ret);
494
Dean Nelson65c17b82008-05-12 14:02:02 -0700495 if (ret == xpLocalPartid)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700496 break;
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500497
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700498 continue;
499 }
500
Dean Nelsona47d5da2008-07-29 22:34:09 -0700501 xpc_request_partition_activation(remote_rp,
502 remote_rp_pa, nasid);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700503 }
504 }
505
506 kfree(discovered_nasids);
507 kfree(remote_rp_base);
508}
509
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700510/*
511 * Given a partid, get the nasids owned by that partition from the
Dean Nelson3a7d5552005-04-04 13:14:00 -0700512 * remote partition's reserved page.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700513 */
Dean Nelson65c17b82008-05-12 14:02:02 -0700514enum xp_retval
Dean Nelson64d032b2008-05-12 14:02:03 -0700515xpc_initiate_partid_to_nasids(short partid, void *nasid_mask)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700516{
517 struct xpc_partition *part;
518 u64 part_nasid_pa;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700519
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700520 part = &xpc_partitions[partid];
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500521 if (part->remote_rp_pa == 0)
Dean Nelson65c17b82008-05-12 14:02:02 -0700522 return xpPartitionDown;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700523
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500524 memset(nasid_mask, 0, XP_NASID_MASK_BYTES);
525
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500526 part_nasid_pa = (u64)XPC_RP_PART_NASIDS(part->remote_rp_pa);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700527
Dean Nelson908787d2008-07-29 22:34:05 -0700528 return xp_remote_memcpy(nasid_mask, (void *)part_nasid_pa,
Dean Nelson94bd2702008-07-29 22:34:05 -0700529 xp_sizeof_nasid_mask);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700530}