blob: 6c82f2050974af785138f400116af98b13e2c86e [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>
Jes Sorensen65ed0b32005-06-21 17:15:03 -070023#include <asm/uncached.h>
Dean Nelson89eb8eb2005-03-23 19:50:00 -070024#include <asm/sn/intr.h>
25#include <asm/sn/sn_sal.h>
26#include <asm/sn/nodepda.h>
27#include <asm/sn/addrs.h>
Dean Nelson45d9ca42008-04-22 14:46:56 -050028#include "xpc.h"
Dean Nelson89eb8eb2005-03-23 19:50:00 -070029
Dean Nelson89eb8eb2005-03-23 19:50:00 -070030/* XPC is exiting flag */
31int xpc_exiting;
32
Dean Nelson89eb8eb2005-03-23 19:50:00 -070033/* SH_IPI_ACCESS shub register value on startup */
34static u64 xpc_sh1_IPI_access;
35static u64 xpc_sh2_IPI_access0;
36static u64 xpc_sh2_IPI_access1;
37static u64 xpc_sh2_IPI_access2;
38static u64 xpc_sh2_IPI_access3;
39
Dean Nelson89eb8eb2005-03-23 19:50:00 -070040/* original protection values for each node */
Jack Steiner24ee0a62005-09-12 12:15:43 -050041u64 xpc_prot_vec[MAX_NUMNODES];
Dean Nelson89eb8eb2005-03-23 19:50:00 -070042
Dean Nelson4b38fcd2005-10-25 14:09:51 -050043/* this partition's reserved page pointers */
Dean Nelson89eb8eb2005-03-23 19:50:00 -070044struct xpc_rsvd_page *xpc_rsvd_page;
Dean Nelson4b38fcd2005-10-25 14:09:51 -050045static u64 *xpc_part_nasids;
46static u64 *xpc_mach_nasids;
Dean Nelson89eb8eb2005-03-23 19:50:00 -070047struct xpc_vars *xpc_vars;
48struct xpc_vars_part *xpc_vars_part;
49
Dean Nelson4b38fcd2005-10-25 14:09:51 -050050static int xp_nasid_mask_bytes; /* actual size in bytes of nasid mask */
51static int xp_nasid_mask_words; /* actual size in words of nasid mask */
52
Dean Nelsonbc63d382008-07-29 22:34:04 -070053struct xpc_partition *xpc_partitions;
Dean Nelson89eb8eb2005-03-23 19:50:00 -070054
Dean Nelson89eb8eb2005-03-23 19:50:00 -070055/*
Dean Nelson4b38fcd2005-10-25 14:09:51 -050056 * Generic buffer used to store a local copy of portions of a remote
57 * partition's reserved page (either its header and part_nasids mask,
58 * or its vars).
Dean Nelson89eb8eb2005-03-23 19:50:00 -070059 */
Dean Nelson7682a4c2006-08-08 15:03:29 -050060char *xpc_remote_copy_buffer;
61void *xpc_remote_copy_buffer_base;
Dean Nelson89eb8eb2005-03-23 19:50:00 -070062
Dean Nelson89eb8eb2005-03-23 19:50:00 -070063/*
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050064 * Guarantee that the kmalloc'd memory is cacheline aligned.
65 */
Dean Nelson7682a4c2006-08-08 15:03:29 -050066void *
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050067xpc_kmalloc_cacheline_aligned(size_t size, gfp_t flags, void **base)
68{
69 /* see if kmalloc will give us cachline aligned memory by default */
70 *base = kmalloc(size, flags);
Dean Nelson2c2b94f2008-04-22 14:50:17 -050071 if (*base == NULL)
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050072 return NULL;
Dean Nelson2c2b94f2008-04-22 14:50:17 -050073
74 if ((u64)*base == L1_CACHE_ALIGN((u64)*base))
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050075 return *base;
Dean Nelson2c2b94f2008-04-22 14:50:17 -050076
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050077 kfree(*base);
78
79 /* nope, we'll have to do it ourselves */
80 *base = kmalloc(size + L1_CACHE_BYTES, flags);
Dean Nelson2c2b94f2008-04-22 14:50:17 -050081 if (*base == NULL)
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050082 return NULL;
Dean Nelson2c2b94f2008-04-22 14:50:17 -050083
Dean Nelson4a3ad2d2008-04-22 14:48:01 -050084 return (void *)L1_CACHE_ALIGN((u64)*base);
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050085}
86
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050087/*
Dean Nelson89eb8eb2005-03-23 19:50:00 -070088 * Given a nasid, get the physical address of the partition's reserved page
89 * for that nasid. This function returns 0 on any error.
90 */
91static u64
Dean Nelson27929022005-10-25 14:11:53 -050092xpc_get_rsvd_page_pa(int nasid)
Dean Nelson89eb8eb2005-03-23 19:50:00 -070093{
Dean Nelson908787d2008-07-29 22:34:05 -070094 enum xp_retval ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -070095 s64 status;
96 u64 cookie = 0;
97 u64 rp_pa = nasid; /* seed with nasid */
98 u64 len = 0;
Dean Nelson27929022005-10-25 14:11:53 -050099 u64 buf = buf;
100 u64 buf_len = 0;
101 void *buf_base = NULL;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700102
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700103 while (1) {
104
105 status = sn_partition_reserved_page_pa(buf, &cookie, &rp_pa,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500106 &len);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700107
108 dev_dbg(xpc_part, "SAL returned with status=%li, cookie="
109 "0x%016lx, address=0x%016lx, len=0x%016lx\n",
110 status, cookie, rp_pa, len);
111
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500112 if (status != SALRET_MORE_PASSES)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700113 break;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700114
Dean Nelson908787d2008-07-29 22:34:05 -0700115 /* >>> L1_CACHE_ALIGN() is only a sn2-bte_copy requirement */
Dean Nelson27929022005-10-25 14:11:53 -0500116 if (L1_CACHE_ALIGN(len) > buf_len) {
Jesper Juhlcbf283c2006-04-20 10:11:09 -0700117 kfree(buf_base);
Dean Nelson27929022005-10-25 14:11:53 -0500118 buf_len = L1_CACHE_ALIGN(len);
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500119 buf = (u64)xpc_kmalloc_cacheline_aligned(buf_len,
120 GFP_KERNEL,
121 &buf_base);
Dean Nelson27929022005-10-25 14:11:53 -0500122 if (buf_base == NULL) {
123 dev_err(xpc_part, "unable to kmalloc "
124 "len=0x%016lx\n", buf_len);
125 status = SALRET_ERROR;
126 break;
127 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700128 }
129
Dean Nelson908787d2008-07-29 22:34:05 -0700130 ret = xp_remote_memcpy((void *)buf, (void *)rp_pa, buf_len);
131 if (ret != xpSuccess) {
132 dev_dbg(xpc_part, "xp_remote_memcpy failed %d\n", ret);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700133 status = SALRET_ERROR;
134 break;
135 }
136 }
137
Jesper Juhlcbf283c2006-04-20 10:11:09 -0700138 kfree(buf_base);
Dean Nelson27929022005-10-25 14:11:53 -0500139
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500140 if (status != SALRET_OK)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700141 rp_pa = 0;
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500142
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700143 dev_dbg(xpc_part, "reserved page at phys address 0x%016lx\n", rp_pa);
144 return rp_pa;
145}
146
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700147/*
148 * Fill the partition reserved page with the information needed by
149 * other partitions to discover we are alive and establish initial
150 * communications.
151 */
152struct xpc_rsvd_page *
153xpc_rsvd_page_init(void)
154{
155 struct xpc_rsvd_page *rp;
156 AMO_t *amos_page;
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500157 u64 rp_pa, nasid_array = 0;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700158 int i, ret;
159
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700160 /* get the local reserved page's address */
161
Dean Nelson27929022005-10-25 14:11:53 -0500162 preempt_disable();
163 rp_pa = xpc_get_rsvd_page_pa(cpuid_to_nasid(smp_processor_id()));
164 preempt_enable();
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700165 if (rp_pa == 0) {
166 dev_err(xpc_part, "SAL failed to locate the reserved page\n");
167 return NULL;
168 }
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500169 rp = (struct xpc_rsvd_page *)__va(rp_pa);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700170
171 if (rp->partid != sn_partition_id) {
172 dev_err(xpc_part, "the reserved page's partid of %d should be "
173 "%d\n", rp->partid, sn_partition_id);
174 return NULL;
175 }
176
177 rp->version = XPC_RP_VERSION;
178
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500179 /* establish the actual sizes of the nasid masks */
180 if (rp->SAL_version == 1) {
181 /* SAL_version 1 didn't set the nasids_size field */
182 rp->nasids_size = 128;
183 }
184 xp_nasid_mask_bytes = rp->nasids_size;
185 xp_nasid_mask_words = xp_nasid_mask_bytes / 8;
186
187 /* setup the pointers to the various items in the reserved page */
188 xpc_part_nasids = XPC_RP_PART_NASIDS(rp);
189 xpc_mach_nasids = XPC_RP_MACH_NASIDS(rp);
190 xpc_vars = XPC_RP_VARS(rp);
191 xpc_vars_part = XPC_RP_VARS_PART(rp);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700192
193 /*
194 * Before clearing xpc_vars, see if a page of AMOs had been previously
195 * allocated. If not we'll need to allocate one and set permissions
196 * so that cross-partition AMOs are allowed.
197 *
198 * The allocated AMO page needs MCA reporting to remain disabled after
199 * XPC has unloaded. To make this work, we keep a copy of the pointer
200 * to this page (i.e., amos_page) in the struct xpc_vars structure,
201 * which is pointed to by the reserved page, and re-use that saved copy
202 * on subsequent loads of XPC. This AMO page is never freed, and its
203 * memory protections are never restricted.
204 */
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500205 amos_page = xpc_vars->amos_page;
206 if (amos_page == NULL) {
Dean Nelsone4a064d2008-04-25 15:22:19 -0500207 amos_page = (AMO_t *)TO_AMO(uncached_alloc_page(0, 1));
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700208 if (amos_page == NULL) {
209 dev_err(xpc_part, "can't allocate page of AMOs\n");
210 return NULL;
211 }
212
213 /*
214 * Open up AMO-R/W to cpu. This is done for Shub 1.1 systems
215 * when xpc_allow_IPI_ops() is called via xpc_hb_init().
216 */
217 if (!enable_shub_wars_1_1()) {
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500218 ret = sn_change_memprotect(ia64_tpa((u64)amos_page),
219 PAGE_SIZE,
220 SN_MEMPROT_ACCESS_CLASS_1,
221 &nasid_array);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700222 if (ret != 0) {
223 dev_err(xpc_part, "can't change memory "
224 "protections\n");
Jes Sorensen65ed0b32005-06-21 17:15:03 -0700225 uncached_free_page(__IA64_UNCACHED_OFFSET |
Dean Nelsone4a064d2008-04-25 15:22:19 -0500226 TO_PHYS((u64)amos_page), 1);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700227 return NULL;
228 }
229 }
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500230 } else if (!IS_AMO_ADDRESS((u64)amos_page)) {
Dean Nelson3a7d5552005-04-04 13:14:00 -0700231 /*
232 * EFI's XPBOOT can also set amos_page in the reserved page,
233 * but it happens to leave it as an uncached physical address
234 * and we need it to be an uncached virtual, so we'll have to
235 * convert it.
236 */
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500237 if (!IS_AMO_PHYS_ADDRESS((u64)amos_page)) {
Dean Nelson3a7d5552005-04-04 13:14:00 -0700238 dev_err(xpc_part, "previously used amos_page address "
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500239 "is bad = 0x%p\n", (void *)amos_page);
Dean Nelson3a7d5552005-04-04 13:14:00 -0700240 return NULL;
241 }
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500242 amos_page = (AMO_t *)TO_AMO((u64)amos_page);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700243 }
244
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500245 /* clear xpc_vars */
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700246 memset(xpc_vars, 0, sizeof(struct xpc_vars));
247
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700248 xpc_vars->version = XPC_V_VERSION;
249 xpc_vars->act_nasid = cpuid_to_nasid(0);
250 xpc_vars->act_phys_cpuid = cpu_physical_id(0);
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500251 xpc_vars->vars_part_pa = __pa(xpc_vars_part);
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500252 xpc_vars->amos_page_pa = ia64_tpa((u64)amos_page);
253 xpc_vars->amos_page = amos_page; /* save for next load of XPC */
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700254
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500255 /* clear xpc_vars_part */
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500256 memset((u64 *)xpc_vars_part, 0, sizeof(struct xpc_vars_part) *
Dean Nelsonbc63d382008-07-29 22:34:04 -0700257 xp_max_npartitions);
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500258
Dean Nelsona607c382005-09-01 14:01:37 -0500259 /* initialize the activate IRQ related AMO variables */
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500260 for (i = 0; i < xp_nasid_mask_words; i++)
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500261 (void)xpc_IPI_init(XPC_ACTIVATE_IRQ_AMOS + i);
Dean Nelsona607c382005-09-01 14:01:37 -0500262
263 /* initialize the engaged remote partitions related AMO variables */
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500264 (void)xpc_IPI_init(XPC_ENGAGED_PARTITIONS_AMO);
265 (void)xpc_IPI_init(XPC_DISENGAGE_REQUEST_AMO);
Dean Nelsona607c382005-09-01 14:01:37 -0500266
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500267 /* timestamp of when reserved page was setup by XPC */
Dean Nelsona607c382005-09-01 14:01:37 -0500268 rp->stamp = CURRENT_TIME;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700269
270 /*
271 * This signifies to the remote partition that our reserved
272 * page is initialized.
273 */
Dave Jones821fe942005-06-25 14:54:29 -0700274 rp->vars_pa = __pa(xpc_vars);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700275
276 return rp;
277}
278
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700279/*
280 * Change protections to allow IPI operations (and AMO operations on
281 * Shub 1.1 systems).
282 */
283void
284xpc_allow_IPI_ops(void)
285{
286 int node;
287 int nasid;
288
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500289 /* >>> Change SH_IPI_ACCESS code to use SAL call once it is available */
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700290
291 if (is_shub2()) {
292 xpc_sh2_IPI_access0 =
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500293 (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS0));
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700294 xpc_sh2_IPI_access1 =
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500295 (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS1));
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700296 xpc_sh2_IPI_access2 =
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500297 (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS2));
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700298 xpc_sh2_IPI_access3 =
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500299 (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS3));
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700300
301 for_each_online_node(node) {
302 nasid = cnodeid_to_nasid(node);
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500303 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS0),
304 -1UL);
305 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS1),
306 -1UL);
307 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS2),
308 -1UL);
309 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS3),
310 -1UL);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700311 }
312
313 } else {
314 xpc_sh1_IPI_access =
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500315 (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH1_IPI_ACCESS));
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700316
317 for_each_online_node(node) {
318 nasid = cnodeid_to_nasid(node);
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500319 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH1_IPI_ACCESS),
320 -1UL);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700321
322 /*
323 * Since the BIST collides with memory operations on
324 * SHUB 1.1 sn_change_memprotect() cannot be used.
325 */
326 if (enable_shub_wars_1_1()) {
327 /* open up everything */
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500328 xpc_prot_vec[node] = (u64)HUB_L((u64 *)
329 GLOBAL_MMR_ADDR
330 (nasid,
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500331 SH1_MD_DQLP_MMR_DIR_PRIVEC0));
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500332 HUB_S((u64 *)
333 GLOBAL_MMR_ADDR(nasid,
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500334 SH1_MD_DQLP_MMR_DIR_PRIVEC0),
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500335 -1UL);
336 HUB_S((u64 *)
337 GLOBAL_MMR_ADDR(nasid,
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500338 SH1_MD_DQRP_MMR_DIR_PRIVEC0),
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500339 -1UL);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700340 }
341 }
342 }
343}
344
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700345/*
346 * Restrict protections to disallow IPI operations (and AMO operations on
347 * Shub 1.1 systems).
348 */
349void
350xpc_restrict_IPI_ops(void)
351{
352 int node;
353 int nasid;
354
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500355 /* >>> Change SH_IPI_ACCESS code to use SAL call once it is available */
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700356
357 if (is_shub2()) {
358
359 for_each_online_node(node) {
360 nasid = cnodeid_to_nasid(node);
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500361 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS0),
362 xpc_sh2_IPI_access0);
363 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS1),
364 xpc_sh2_IPI_access1);
365 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS2),
366 xpc_sh2_IPI_access2);
367 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS3),
368 xpc_sh2_IPI_access3);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700369 }
370
371 } else {
372
373 for_each_online_node(node) {
374 nasid = cnodeid_to_nasid(node);
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500375 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH1_IPI_ACCESS),
376 xpc_sh1_IPI_access);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700377
378 if (enable_shub_wars_1_1()) {
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500379 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid,
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500380 SH1_MD_DQLP_MMR_DIR_PRIVEC0),
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500381 xpc_prot_vec[node]);
382 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid,
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500383 SH1_MD_DQRP_MMR_DIR_PRIVEC0),
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500384 xpc_prot_vec[node]);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700385 }
386 }
387 }
388}
389
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700390/*
391 * At periodic intervals, scan through all active partitions and ensure
392 * their heartbeat is still active. If not, the partition is deactivated.
393 */
394void
395xpc_check_remote_hb(void)
396{
397 struct xpc_vars *remote_vars;
398 struct xpc_partition *part;
Dean Nelson64d032b2008-05-12 14:02:03 -0700399 short partid;
Dean Nelson908787d2008-07-29 22:34:05 -0700400 enum xp_retval ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700401
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500402 remote_vars = (struct xpc_vars *)xpc_remote_copy_buffer;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700403
Dean Nelsonbc63d382008-07-29 22:34:04 -0700404 for (partid = 0; partid < xp_max_npartitions; partid++) {
Dean Nelsona607c382005-09-01 14:01:37 -0500405
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500406 if (xpc_exiting)
Dean Nelsona607c382005-09-01 14:01:37 -0500407 break;
Dean Nelsona607c382005-09-01 14:01:37 -0500408
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500409 if (partid == sn_partition_id)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700410 continue;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700411
412 part = &xpc_partitions[partid];
413
414 if (part->act_state == XPC_P_INACTIVE ||
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500415 part->act_state == XPC_P_DEACTIVATING) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700416 continue;
417 }
418
419 /* pull the remote_hb cache line */
Dean Nelson908787d2008-07-29 22:34:05 -0700420 ret = xp_remote_memcpy(remote_vars,
421 (void *)part->remote_vars_pa,
422 XPC_RP_VARS_SIZE);
423 if (ret != xpSuccess) {
424 XPC_DEACTIVATE_PARTITION(part, ret);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700425 continue;
426 }
427
428 dev_dbg(xpc_part, "partid = %d, heartbeat = %ld, last_heartbeat"
Dean Nelson780d09e2005-11-09 14:41:57 -0600429 " = %ld, heartbeat_offline = %ld, HB_mask = 0x%lx\n",
430 partid, remote_vars->heartbeat, part->last_heartbeat,
431 remote_vars->heartbeat_offline,
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700432 remote_vars->heartbeating_to_mask);
433
434 if (((remote_vars->heartbeat == part->last_heartbeat) &&
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500435 (remote_vars->heartbeat_offline == 0)) ||
436 !xpc_hb_allowed(sn_partition_id, remote_vars)) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700437
Dean Nelson65c17b82008-05-12 14:02:02 -0700438 XPC_DEACTIVATE_PARTITION(part, xpNoHeartbeat);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700439 continue;
440 }
441
442 part->last_heartbeat = remote_vars->heartbeat;
443 }
444}
445
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700446/*
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500447 * Get a copy of a portion of the remote partition's rsvd page.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700448 *
449 * remote_rp points to a buffer that is cacheline aligned for BTE copies and
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500450 * is large enough to contain a copy of their reserved page header and
451 * part_nasids mask.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700452 */
Dean Nelson65c17b82008-05-12 14:02:02 -0700453static enum xp_retval
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700454xpc_get_remote_rp(int nasid, u64 *discovered_nasids,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500455 struct xpc_rsvd_page *remote_rp, u64 *remote_rp_pa)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700456{
Dean Nelson908787d2008-07-29 22:34:05 -0700457 int i;
458 enum xp_retval ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700459
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700460 /* get the reserved page's physical address */
461
Dean Nelson27929022005-10-25 14:11:53 -0500462 *remote_rp_pa = xpc_get_rsvd_page_pa(nasid);
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500463 if (*remote_rp_pa == 0)
Dean Nelson65c17b82008-05-12 14:02:02 -0700464 return xpNoRsvdPageAddr;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700465
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500466 /* pull over the reserved page header and part_nasids mask */
Dean Nelson908787d2008-07-29 22:34:05 -0700467 ret = xp_remote_memcpy(remote_rp, (void *)*remote_rp_pa,
468 XPC_RP_HEADER_SIZE + xp_nasid_mask_bytes);
469 if (ret != xpSuccess)
470 return ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700471
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700472 if (discovered_nasids != NULL) {
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500473 u64 *remote_part_nasids = XPC_RP_PART_NASIDS(remote_rp);
474
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500475 for (i = 0; i < xp_nasid_mask_words; i++)
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500476 discovered_nasids[i] |= remote_part_nasids[i];
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700477 }
478
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700479 /* check that the partid is for another partition */
480
Dean Nelsonbc63d382008-07-29 22:34:04 -0700481 if (remote_rp->partid < 0 || remote_rp->partid >= xp_max_npartitions)
Dean Nelson65c17b82008-05-12 14:02:02 -0700482 return xpInvalidPartid;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700483
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500484 if (remote_rp->partid == sn_partition_id)
Dean Nelson65c17b82008-05-12 14:02:02 -0700485 return xpLocalPartid;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700486
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700487 if (XPC_VERSION_MAJOR(remote_rp->version) !=
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500488 XPC_VERSION_MAJOR(XPC_RP_VERSION)) {
Dean Nelson65c17b82008-05-12 14:02:02 -0700489 return xpBadVersion;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700490 }
491
Dean Nelson65c17b82008-05-12 14:02:02 -0700492 return xpSuccess;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700493}
494
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700495/*
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500496 * Get a copy of the remote partition's XPC variables from the reserved page.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700497 *
498 * remote_vars points to a buffer that is cacheline aligned for BTE copies and
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500499 * assumed to be of size XPC_RP_VARS_SIZE.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700500 */
Dean Nelson65c17b82008-05-12 14:02:02 -0700501static enum xp_retval
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700502xpc_get_remote_vars(u64 remote_vars_pa, struct xpc_vars *remote_vars)
503{
Dean Nelson908787d2008-07-29 22:34:05 -0700504 enum xp_retval ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700505
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500506 if (remote_vars_pa == 0)
Dean Nelson65c17b82008-05-12 14:02:02 -0700507 return xpVarsNotSet;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700508
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700509 /* pull over the cross partition variables */
Dean Nelson908787d2008-07-29 22:34:05 -0700510 ret = xp_remote_memcpy(remote_vars, (void *)remote_vars_pa,
511 XPC_RP_VARS_SIZE);
512 if (ret != xpSuccess)
513 return ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700514
515 if (XPC_VERSION_MAJOR(remote_vars->version) !=
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500516 XPC_VERSION_MAJOR(XPC_V_VERSION)) {
Dean Nelson65c17b82008-05-12 14:02:02 -0700517 return xpBadVersion;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700518 }
519
Dean Nelson65c17b82008-05-12 14:02:02 -0700520 return xpSuccess;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700521}
522
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700523/*
Dean Nelsona607c382005-09-01 14:01:37 -0500524 * Update the remote partition's info.
525 */
526static void
527xpc_update_partition_info(struct xpc_partition *part, u8 remote_rp_version,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500528 struct timespec *remote_rp_stamp, u64 remote_rp_pa,
529 u64 remote_vars_pa, struct xpc_vars *remote_vars)
Dean Nelsona607c382005-09-01 14:01:37 -0500530{
531 part->remote_rp_version = remote_rp_version;
Tony Luckb9ae3bd2007-05-10 11:47:38 -0700532 dev_dbg(xpc_part, " remote_rp_version = 0x%016x\n",
Dean Nelsona607c382005-09-01 14:01:37 -0500533 part->remote_rp_version);
534
535 part->remote_rp_stamp = *remote_rp_stamp;
536 dev_dbg(xpc_part, " remote_rp_stamp (tv_sec = 0x%lx tv_nsec = 0x%lx\n",
537 part->remote_rp_stamp.tv_sec, part->remote_rp_stamp.tv_nsec);
538
539 part->remote_rp_pa = remote_rp_pa;
540 dev_dbg(xpc_part, " remote_rp_pa = 0x%016lx\n", part->remote_rp_pa);
541
542 part->remote_vars_pa = remote_vars_pa;
543 dev_dbg(xpc_part, " remote_vars_pa = 0x%016lx\n",
544 part->remote_vars_pa);
545
546 part->last_heartbeat = remote_vars->heartbeat;
547 dev_dbg(xpc_part, " last_heartbeat = 0x%016lx\n",
548 part->last_heartbeat);
549
550 part->remote_vars_part_pa = remote_vars->vars_part_pa;
551 dev_dbg(xpc_part, " remote_vars_part_pa = 0x%016lx\n",
552 part->remote_vars_part_pa);
553
554 part->remote_act_nasid = remote_vars->act_nasid;
555 dev_dbg(xpc_part, " remote_act_nasid = 0x%x\n",
556 part->remote_act_nasid);
557
558 part->remote_act_phys_cpuid = remote_vars->act_phys_cpuid;
559 dev_dbg(xpc_part, " remote_act_phys_cpuid = 0x%x\n",
560 part->remote_act_phys_cpuid);
561
562 part->remote_amos_page_pa = remote_vars->amos_page_pa;
563 dev_dbg(xpc_part, " remote_amos_page_pa = 0x%lx\n",
564 part->remote_amos_page_pa);
565
566 part->remote_vars_version = remote_vars->version;
567 dev_dbg(xpc_part, " remote_vars_version = 0x%x\n",
568 part->remote_vars_version);
569}
570
Dean Nelsona607c382005-09-01 14:01:37 -0500571/*
Dean Nelsone54af722005-10-25 14:07:43 -0500572 * Prior code has determined the nasid which generated an IPI. Inspect
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700573 * that nasid to determine if its partition needs to be activated or
574 * deactivated.
575 *
576 * A partition is consider "awaiting activation" if our partition
577 * flags indicate it is not active and it has a heartbeat. A
578 * partition is considered "awaiting deactivation" if our partition
579 * flags indicate it is active but it has no heartbeat or it is not
580 * sending its heartbeat to us.
581 *
582 * To determine the heartbeat, the remote nasid must have a properly
583 * initialized reserved page.
584 */
585static void
586xpc_identify_act_IRQ_req(int nasid)
587{
588 struct xpc_rsvd_page *remote_rp;
589 struct xpc_vars *remote_vars;
Dean Nelsona607c382005-09-01 14:01:37 -0500590 u64 remote_rp_pa;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700591 u64 remote_vars_pa;
Dean Nelsona607c382005-09-01 14:01:37 -0500592 int remote_rp_version;
593 int reactivate = 0;
594 int stamp_diff;
595 struct timespec remote_rp_stamp = { 0, 0 };
Dean Nelson64d032b2008-05-12 14:02:03 -0700596 short partid;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700597 struct xpc_partition *part;
Dean Nelson65c17b82008-05-12 14:02:02 -0700598 enum xp_retval ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700599
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700600 /* pull over the reserved page structure */
601
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500602 remote_rp = (struct xpc_rsvd_page *)xpc_remote_copy_buffer;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700603
Dean Nelsona607c382005-09-01 14:01:37 -0500604 ret = xpc_get_remote_rp(nasid, NULL, remote_rp, &remote_rp_pa);
Dean Nelson65c17b82008-05-12 14:02:02 -0700605 if (ret != xpSuccess) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700606 dev_warn(xpc_part, "unable to get reserved page from nasid %d, "
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500607 "which sent interrupt, reason=%d\n", nasid, ret);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700608 return;
609 }
610
611 remote_vars_pa = remote_rp->vars_pa;
Dean Nelsona607c382005-09-01 14:01:37 -0500612 remote_rp_version = remote_rp->version;
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500613 if (XPC_SUPPORTS_RP_STAMP(remote_rp_version))
Dean Nelsona607c382005-09-01 14:01:37 -0500614 remote_rp_stamp = remote_rp->stamp;
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500615
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700616 partid = remote_rp->partid;
617 part = &xpc_partitions[partid];
618
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700619 /* pull over the cross partition variables */
620
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500621 remote_vars = (struct xpc_vars *)xpc_remote_copy_buffer;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700622
623 ret = xpc_get_remote_vars(remote_vars_pa, remote_vars);
Dean Nelson65c17b82008-05-12 14:02:02 -0700624 if (ret != xpSuccess) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700625
626 dev_warn(xpc_part, "unable to get XPC variables from nasid %d, "
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500627 "which sent interrupt, reason=%d\n", nasid, ret);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700628
629 XPC_DEACTIVATE_PARTITION(part, ret);
630 return;
631 }
632
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700633 part->act_IRQ_rcvd++;
634
635 dev_dbg(xpc_part, "partid for nasid %d is %d; IRQs = %d; HB = "
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500636 "%ld:0x%lx\n", (int)nasid, (int)partid, part->act_IRQ_rcvd,
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700637 remote_vars->heartbeat, remote_vars->heartbeating_to_mask);
638
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500639 if (xpc_partition_disengaged(part) &&
640 part->act_state == XPC_P_INACTIVE) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700641
Dean Nelsona607c382005-09-01 14:01:37 -0500642 xpc_update_partition_info(part, remote_rp_version,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500643 &remote_rp_stamp, remote_rp_pa,
644 remote_vars_pa, remote_vars);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700645
Dean Nelsona607c382005-09-01 14:01:37 -0500646 if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version)) {
647 if (xpc_partition_disengage_requested(1UL << partid)) {
648 /*
649 * Other side is waiting on us to disengage,
650 * even though we already have.
651 */
652 return;
653 }
654 } else {
655 /* other side doesn't support disengage requests */
656 xpc_clear_partition_disengage_request(1UL << partid);
657 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700658
659 xpc_activate_partition(part);
Dean Nelsona607c382005-09-01 14:01:37 -0500660 return;
661 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700662
Dean Nelsona607c382005-09-01 14:01:37 -0500663 DBUG_ON(part->remote_rp_version == 0);
664 DBUG_ON(part->remote_vars_version == 0);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700665
Dean Nelsona607c382005-09-01 14:01:37 -0500666 if (!XPC_SUPPORTS_RP_STAMP(part->remote_rp_version)) {
667 DBUG_ON(XPC_SUPPORTS_DISENGAGE_REQUEST(part->
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500668 remote_vars_version));
Dean Nelsona607c382005-09-01 14:01:37 -0500669
670 if (!XPC_SUPPORTS_RP_STAMP(remote_rp_version)) {
671 DBUG_ON(XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500672 version));
Dean Nelsona607c382005-09-01 14:01:37 -0500673 /* see if the other side rebooted */
674 if (part->remote_amos_page_pa ==
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500675 remote_vars->amos_page_pa &&
676 xpc_hb_allowed(sn_partition_id, remote_vars)) {
Dean Nelsona607c382005-09-01 14:01:37 -0500677 /* doesn't look that way, so ignore the IPI */
678 return;
679 }
680 }
681
682 /*
683 * Other side rebooted and previous XPC didn't support the
684 * disengage request, so we don't need to do anything special.
685 */
686
687 xpc_update_partition_info(part, remote_rp_version,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500688 &remote_rp_stamp, remote_rp_pa,
689 remote_vars_pa, remote_vars);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700690 part->reactivate_nasid = nasid;
Dean Nelson65c17b82008-05-12 14:02:02 -0700691 XPC_DEACTIVATE_PARTITION(part, xpReactivating);
Dean Nelsona607c382005-09-01 14:01:37 -0500692 return;
693 }
694
695 DBUG_ON(!XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version));
696
697 if (!XPC_SUPPORTS_RP_STAMP(remote_rp_version)) {
698 DBUG_ON(!XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->version));
699
700 /*
701 * Other side rebooted and previous XPC did support the
702 * disengage request, but the new one doesn't.
703 */
704
705 xpc_clear_partition_engaged(1UL << partid);
706 xpc_clear_partition_disengage_request(1UL << partid);
707
708 xpc_update_partition_info(part, remote_rp_version,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500709 &remote_rp_stamp, remote_rp_pa,
710 remote_vars_pa, remote_vars);
Dean Nelsona607c382005-09-01 14:01:37 -0500711 reactivate = 1;
712
713 } else {
714 DBUG_ON(!XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->version));
715
716 stamp_diff = xpc_compare_stamps(&part->remote_rp_stamp,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500717 &remote_rp_stamp);
Dean Nelsona607c382005-09-01 14:01:37 -0500718 if (stamp_diff != 0) {
719 DBUG_ON(stamp_diff >= 0);
720
721 /*
722 * Other side rebooted and the previous XPC did support
723 * the disengage request, as does the new one.
724 */
725
726 DBUG_ON(xpc_partition_engaged(1UL << partid));
727 DBUG_ON(xpc_partition_disengage_requested(1UL <<
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500728 partid));
Dean Nelsona607c382005-09-01 14:01:37 -0500729
730 xpc_update_partition_info(part, remote_rp_version,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500731 &remote_rp_stamp,
732 remote_rp_pa, remote_vars_pa,
733 remote_vars);
Dean Nelsona607c382005-09-01 14:01:37 -0500734 reactivate = 1;
735 }
736 }
737
Dean Nelson246c7e32005-12-22 14:32:56 -0600738 if (part->disengage_request_timeout > 0 &&
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500739 !xpc_partition_disengaged(part)) {
Dean Nelsona607c382005-09-01 14:01:37 -0500740 /* still waiting on other side to disengage from us */
741 return;
742 }
743
744 if (reactivate) {
745 part->reactivate_nasid = nasid;
Dean Nelson65c17b82008-05-12 14:02:02 -0700746 XPC_DEACTIVATE_PARTITION(part, xpReactivating);
Dean Nelsona607c382005-09-01 14:01:37 -0500747
748 } else if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version) &&
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500749 xpc_partition_disengage_requested(1UL << partid)) {
Dean Nelson65c17b82008-05-12 14:02:02 -0700750 XPC_DEACTIVATE_PARTITION(part, xpOtherGoingDown);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700751 }
752}
753
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700754/*
755 * Loop through the activation AMO variables and process any bits
756 * which are set. Each bit indicates a nasid sending a partition
757 * activation or deactivation request.
758 *
759 * Return #of IRQs detected.
760 */
761int
762xpc_identify_act_IRQ_sender(void)
763{
764 int word, bit;
765 u64 nasid_mask;
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500766 u64 nasid; /* remote nasid */
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700767 int n_IRQs_detected = 0;
768 AMO_t *act_amos;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700769
Dean Nelsona607c382005-09-01 14:01:37 -0500770 act_amos = xpc_vars->amos_page + XPC_ACTIVATE_IRQ_AMOS;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700771
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700772 /* scan through act AMO variable looking for non-zero entries */
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500773 for (word = 0; word < xp_nasid_mask_words; word++) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700774
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500775 if (xpc_exiting)
Dean Nelsona607c382005-09-01 14:01:37 -0500776 break;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700777
778 nasid_mask = xpc_IPI_receive(&act_amos[word]);
779 if (nasid_mask == 0) {
780 /* no IRQs from nasids in this variable */
781 continue;
782 }
783
784 dev_dbg(xpc_part, "AMO[%d] gave back 0x%lx\n", word,
785 nasid_mask);
786
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700787 /*
788 * If this nasid has been added to the machine since
789 * our partition was reset, this will retain the
790 * remote nasid in our reserved pages machine mask.
791 * This is used in the event of module reload.
792 */
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500793 xpc_mach_nasids[word] |= nasid_mask;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700794
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700795 /* locate the nasid(s) which sent interrupts */
796
797 for (bit = 0; bit < (8 * sizeof(u64)); bit++) {
798 if (nasid_mask & (1UL << bit)) {
799 n_IRQs_detected++;
800 nasid = XPC_NASID_FROM_W_B(word, bit);
801 dev_dbg(xpc_part, "interrupt from nasid %ld\n",
802 nasid);
803 xpc_identify_act_IRQ_req(nasid);
804 }
805 }
806 }
807 return n_IRQs_detected;
808}
809
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700810/*
Dean Nelsona607c382005-09-01 14:01:37 -0500811 * See if the other side has responded to a partition disengage request
812 * from us.
813 */
814int
815xpc_partition_disengaged(struct xpc_partition *part)
816{
Dean Nelson64d032b2008-05-12 14:02:03 -0700817 short partid = XPC_PARTID(part);
Dean Nelsona607c382005-09-01 14:01:37 -0500818 int disengaged;
819
Dean Nelsona607c382005-09-01 14:01:37 -0500820 disengaged = (xpc_partition_engaged(1UL << partid) == 0);
821 if (part->disengage_request_timeout) {
822 if (!disengaged) {
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500823 if (time_before(jiffies,
824 part->disengage_request_timeout)) {
Dean Nelsona607c382005-09-01 14:01:37 -0500825 /* timelimit hasn't been reached yet */
826 return 0;
827 }
828
829 /*
830 * Other side hasn't responded to our disengage
831 * request in a timely fashion, so assume it's dead.
832 */
833
Dean Nelson1ecaded2006-01-06 09:48:21 -0600834 dev_info(xpc_part, "disengage from remote partition %d "
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500835 "timed out\n", partid);
Dean Nelson1ecaded2006-01-06 09:48:21 -0600836 xpc_disengage_request_timedout = 1;
Dean Nelsona607c382005-09-01 14:01:37 -0500837 xpc_clear_partition_engaged(1UL << partid);
838 disengaged = 1;
839 }
840 part->disengage_request_timeout = 0;
841
842 /* cancel the timer function, provided it's not us */
843 if (!in_interrupt()) {
844 del_singleshot_timer_sync(&part->
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500845 disengage_request_timer);
Dean Nelsona607c382005-09-01 14:01:37 -0500846 }
847
848 DBUG_ON(part->act_state != XPC_P_DEACTIVATING &&
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500849 part->act_state != XPC_P_INACTIVE);
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500850 if (part->act_state != XPC_P_INACTIVE)
Dean Nelsona607c382005-09-01 14:01:37 -0500851 xpc_wakeup_channel_mgr(part);
Dean Nelsona607c382005-09-01 14:01:37 -0500852
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500853 if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version))
Dean Nelsona607c382005-09-01 14:01:37 -0500854 xpc_cancel_partition_disengage_request(part);
Dean Nelsona607c382005-09-01 14:01:37 -0500855 }
856 return disengaged;
857}
858
Dean Nelsona607c382005-09-01 14:01:37 -0500859/*
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700860 * Mark specified partition as active.
861 */
Dean Nelson65c17b82008-05-12 14:02:02 -0700862enum xp_retval
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700863xpc_mark_partition_active(struct xpc_partition *part)
864{
865 unsigned long irq_flags;
Dean Nelson65c17b82008-05-12 14:02:02 -0700866 enum xp_retval ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700867
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700868 dev_dbg(xpc_part, "setting partition %d to ACTIVE\n", XPC_PARTID(part));
869
870 spin_lock_irqsave(&part->act_lock, irq_flags);
871 if (part->act_state == XPC_P_ACTIVATING) {
872 part->act_state = XPC_P_ACTIVE;
Dean Nelson65c17b82008-05-12 14:02:02 -0700873 ret = xpSuccess;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700874 } else {
Dean Nelson65c17b82008-05-12 14:02:02 -0700875 DBUG_ON(part->reason == xpSuccess);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700876 ret = part->reason;
877 }
878 spin_unlock_irqrestore(&part->act_lock, irq_flags);
879
880 return ret;
881}
882
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700883/*
884 * Notify XPC that the partition is down.
885 */
886void
887xpc_deactivate_partition(const int line, struct xpc_partition *part,
Dean Nelson65c17b82008-05-12 14:02:02 -0700888 enum xp_retval reason)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700889{
890 unsigned long irq_flags;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700891
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700892 spin_lock_irqsave(&part->act_lock, irq_flags);
893
894 if (part->act_state == XPC_P_INACTIVE) {
895 XPC_SET_REASON(part, reason, line);
896 spin_unlock_irqrestore(&part->act_lock, irq_flags);
Dean Nelson65c17b82008-05-12 14:02:02 -0700897 if (reason == xpReactivating) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700898 /* we interrupt ourselves to reactivate partition */
899 xpc_IPI_send_reactivate(part);
900 }
901 return;
902 }
903 if (part->act_state == XPC_P_DEACTIVATING) {
Dean Nelson65c17b82008-05-12 14:02:02 -0700904 if ((part->reason == xpUnloading && reason != xpUnloading) ||
905 reason == xpReactivating) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700906 XPC_SET_REASON(part, reason, line);
907 }
908 spin_unlock_irqrestore(&part->act_lock, irq_flags);
909 return;
910 }
911
912 part->act_state = XPC_P_DEACTIVATING;
913 XPC_SET_REASON(part, reason, line);
914
915 spin_unlock_irqrestore(&part->act_lock, irq_flags);
916
Dean Nelsona607c382005-09-01 14:01:37 -0500917 if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version)) {
918 xpc_request_partition_disengage(part);
919 xpc_IPI_send_disengage(part);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700920
Dean Nelsona607c382005-09-01 14:01:37 -0500921 /* set a timelimit on the disengage request */
922 part->disengage_request_timeout = jiffies +
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500923 (xpc_disengage_request_timelimit * HZ);
Dean Nelsona607c382005-09-01 14:01:37 -0500924 part->disengage_request_timer.expires =
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500925 part->disengage_request_timeout;
Dean Nelsona607c382005-09-01 14:01:37 -0500926 add_timer(&part->disengage_request_timer);
927 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700928
Dean Nelsone54af722005-10-25 14:07:43 -0500929 dev_dbg(xpc_part, "bringing partition %d down, reason = %d\n",
930 XPC_PARTID(part), reason);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700931
Dean Nelsona607c382005-09-01 14:01:37 -0500932 xpc_partition_going_down(part, reason);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700933}
934
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700935/*
Dean Nelsona607c382005-09-01 14:01:37 -0500936 * Mark specified partition as inactive.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700937 */
938void
939xpc_mark_partition_inactive(struct xpc_partition *part)
940{
941 unsigned long irq_flags;
942
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700943 dev_dbg(xpc_part, "setting partition %d to INACTIVE\n",
944 XPC_PARTID(part));
945
946 spin_lock_irqsave(&part->act_lock, irq_flags);
947 part->act_state = XPC_P_INACTIVE;
948 spin_unlock_irqrestore(&part->act_lock, irq_flags);
949 part->remote_rp_pa = 0;
950}
951
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700952/*
953 * SAL has provided a partition and machine mask. The partition mask
954 * contains a bit for each even nasid in our partition. The machine
955 * mask contains a bit for each even nasid in the entire machine.
956 *
957 * Using those two bit arrays, we can determine which nasids are
958 * known in the machine. Each should also have a reserved page
959 * initialized if they are available for partitioning.
960 */
961void
962xpc_discovery(void)
963{
964 void *remote_rp_base;
965 struct xpc_rsvd_page *remote_rp;
966 struct xpc_vars *remote_vars;
Dean Nelsona607c382005-09-01 14:01:37 -0500967 u64 remote_rp_pa;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700968 u64 remote_vars_pa;
969 int region;
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500970 int region_size;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700971 int max_regions;
972 int nasid;
973 struct xpc_rsvd_page *rp;
Dean Nelson64d032b2008-05-12 14:02:03 -0700974 short partid;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700975 struct xpc_partition *part;
976 u64 *discovered_nasids;
Dean Nelson65c17b82008-05-12 14:02:02 -0700977 enum xp_retval ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700978
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500979 remote_rp = xpc_kmalloc_cacheline_aligned(XPC_RP_HEADER_SIZE +
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500980 xp_nasid_mask_bytes,
981 GFP_KERNEL, &remote_rp_base);
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500982 if (remote_rp == NULL)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700983 return;
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500984
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500985 remote_vars = (struct xpc_vars *)remote_rp;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700986
Jes Sorensen7aa6ba42006-02-17 05:18:43 -0500987 discovered_nasids = kzalloc(sizeof(u64) * xp_nasid_mask_words,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500988 GFP_KERNEL);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700989 if (discovered_nasids == NULL) {
990 kfree(remote_rp_base);
991 return;
992 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700993
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500994 rp = (struct xpc_rsvd_page *)xpc_rsvd_page;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700995
996 /*
997 * The term 'region' in this context refers to the minimum number of
998 * nodes that can comprise an access protection grouping. The access
999 * protection is in regards to memory, IOI and IPI.
1000 */
Dean Nelson4b38fcd2005-10-25 14:09:51 -05001001 max_regions = 64;
1002 region_size = sn_region_size;
1003
1004 switch (region_size) {
1005 case 128:
1006 max_regions *= 2;
1007 case 64:
1008 max_regions *= 2;
1009 case 32:
1010 max_regions *= 2;
1011 region_size = 16;
1012 DBUG_ON(!is_shub2());
1013 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001014
1015 for (region = 0; region < max_regions; region++) {
1016
Dean Nelson2c2b94f2008-04-22 14:50:17 -05001017 if (xpc_exiting)
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001018 break;
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001019
1020 dev_dbg(xpc_part, "searching region %d\n", region);
1021
Dean Nelson4b38fcd2005-10-25 14:09:51 -05001022 for (nasid = (region * region_size * 2);
Dean Nelson4a3ad2d2008-04-22 14:48:01 -05001023 nasid < ((region + 1) * region_size * 2); nasid += 2) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001024
Dean Nelson2c2b94f2008-04-22 14:50:17 -05001025 if (xpc_exiting)
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001026 break;
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001027
1028 dev_dbg(xpc_part, "checking nasid %d\n", nasid);
1029
Dean Nelson4b38fcd2005-10-25 14:09:51 -05001030 if (XPC_NASID_IN_ARRAY(nasid, xpc_part_nasids)) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001031 dev_dbg(xpc_part, "PROM indicates Nasid %d is "
1032 "part of the local partition; skipping "
1033 "region\n", nasid);
1034 break;
1035 }
1036
Dean Nelson4b38fcd2005-10-25 14:09:51 -05001037 if (!(XPC_NASID_IN_ARRAY(nasid, xpc_mach_nasids))) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001038 dev_dbg(xpc_part, "PROM indicates Nasid %d was "
1039 "not on Numa-Link network at reset\n",
1040 nasid);
1041 continue;
1042 }
1043
1044 if (XPC_NASID_IN_ARRAY(nasid, discovered_nasids)) {
1045 dev_dbg(xpc_part, "Nasid %d is part of a "
1046 "partition which was previously "
1047 "discovered\n", nasid);
1048 continue;
1049 }
1050
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001051 /* pull over the reserved page structure */
1052
1053 ret = xpc_get_remote_rp(nasid, discovered_nasids,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -05001054 remote_rp, &remote_rp_pa);
Dean Nelson65c17b82008-05-12 14:02:02 -07001055 if (ret != xpSuccess) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001056 dev_dbg(xpc_part, "unable to get reserved page "
1057 "from nasid %d, reason=%d\n", nasid,
1058 ret);
1059
Dean Nelson65c17b82008-05-12 14:02:02 -07001060 if (ret == xpLocalPartid)
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001061 break;
Dean Nelson2c2b94f2008-04-22 14:50:17 -05001062
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001063 continue;
1064 }
1065
1066 remote_vars_pa = remote_rp->vars_pa;
1067
1068 partid = remote_rp->partid;
1069 part = &xpc_partitions[partid];
1070
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001071 /* pull over the cross partition variables */
1072
1073 ret = xpc_get_remote_vars(remote_vars_pa, remote_vars);
Dean Nelson65c17b82008-05-12 14:02:02 -07001074 if (ret != xpSuccess) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001075 dev_dbg(xpc_part, "unable to get XPC variables "
1076 "from nasid %d, reason=%d\n", nasid,
1077 ret);
1078
1079 XPC_DEACTIVATE_PARTITION(part, ret);
1080 continue;
1081 }
1082
1083 if (part->act_state != XPC_P_INACTIVE) {
1084 dev_dbg(xpc_part, "partition %d on nasid %d is "
1085 "already activating\n", partid, nasid);
1086 break;
1087 }
1088
1089 /*
1090 * Register the remote partition's AMOs with SAL so it
1091 * can handle and cleanup errors within that address
1092 * range should the remote partition go down. We don't
1093 * unregister this range because it is difficult to
1094 * tell when outstanding writes to the remote partition
1095 * are finished and thus when it is thus safe to
1096 * unregister. This should not result in wasted space
1097 * in the SAL xp_addr_region table because we should
1098 * get the same page for remote_act_amos_pa after
1099 * module reloads and system reboots.
1100 */
Dean Nelson4a3ad2d2008-04-22 14:48:01 -05001101 if (sn_register_xp_addr_region
1102 (remote_vars->amos_page_pa, PAGE_SIZE, 1) < 0) {
1103 dev_dbg(xpc_part,
1104 "partition %d failed to "
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001105 "register xp_addr region 0x%016lx\n",
1106 partid, remote_vars->amos_page_pa);
1107
Dean Nelson65c17b82008-05-12 14:02:02 -07001108 XPC_SET_REASON(part, xpPhysAddrRegFailed,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -05001109 __LINE__);
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001110 break;
1111 }
1112
1113 /*
1114 * The remote nasid is valid and available.
1115 * Send an interrupt to that nasid to notify
1116 * it that we are ready to begin activation.
1117 */
1118 dev_dbg(xpc_part, "sending an interrupt to AMO 0x%lx, "
1119 "nasid %d, phys_cpuid 0x%x\n",
1120 remote_vars->amos_page_pa,
1121 remote_vars->act_nasid,
1122 remote_vars->act_phys_cpuid);
1123
Dean Nelsona607c382005-09-01 14:01:37 -05001124 if (XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->
Dean Nelson4a3ad2d2008-04-22 14:48:01 -05001125 version)) {
Dean Nelsona607c382005-09-01 14:01:37 -05001126 part->remote_amos_page_pa =
Dean Nelson4a3ad2d2008-04-22 14:48:01 -05001127 remote_vars->amos_page_pa;
Dean Nelsona607c382005-09-01 14:01:37 -05001128 xpc_mark_partition_disengaged(part);
1129 xpc_cancel_partition_disengage_request(part);
1130 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001131 xpc_IPI_send_activate(remote_vars);
1132 }
1133 }
1134
1135 kfree(discovered_nasids);
1136 kfree(remote_rp_base);
1137}
1138
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001139/*
1140 * Given a partid, get the nasids owned by that partition from the
Dean Nelson3a7d5552005-04-04 13:14:00 -07001141 * remote partition's reserved page.
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001142 */
Dean Nelson65c17b82008-05-12 14:02:02 -07001143enum xp_retval
Dean Nelson64d032b2008-05-12 14:02:03 -07001144xpc_initiate_partid_to_nasids(short partid, void *nasid_mask)
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001145{
1146 struct xpc_partition *part;
1147 u64 part_nasid_pa;
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001148
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001149 part = &xpc_partitions[partid];
Dean Nelson2c2b94f2008-04-22 14:50:17 -05001150 if (part->remote_rp_pa == 0)
Dean Nelson65c17b82008-05-12 14:02:02 -07001151 return xpPartitionDown;
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001152
Dean Nelson4b38fcd2005-10-25 14:09:51 -05001153 memset(nasid_mask, 0, XP_NASID_MASK_BYTES);
1154
Dean Nelson4a3ad2d2008-04-22 14:48:01 -05001155 part_nasid_pa = (u64)XPC_RP_PART_NASIDS(part->remote_rp_pa);
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001156
Dean Nelson908787d2008-07-29 22:34:05 -07001157 return xp_remote_memcpy(nasid_mask, (void *)part_nasid_pa,
1158 xp_nasid_mask_bytes);
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001159}