blob: 4e14effdeddb9016431f41ac29f225a4bce46895 [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 Nelson89eb8eb2005-03-23 19:50:00 -070032/* SH_IPI_ACCESS shub register value on startup */
33static u64 xpc_sh1_IPI_access;
34static u64 xpc_sh2_IPI_access0;
35static u64 xpc_sh2_IPI_access1;
36static u64 xpc_sh2_IPI_access2;
37static u64 xpc_sh2_IPI_access3;
38
Dean Nelson89eb8eb2005-03-23 19:50:00 -070039/* original protection values for each node */
Jack Steiner24ee0a62005-09-12 12:15:43 -050040u64 xpc_prot_vec[MAX_NUMNODES];
Dean Nelson89eb8eb2005-03-23 19:50:00 -070041
Dean Nelson4b38fcd2005-10-25 14:09:51 -050042/* this partition's reserved page pointers */
Dean Nelson89eb8eb2005-03-23 19:50:00 -070043struct xpc_rsvd_page *xpc_rsvd_page;
Dean Nelson4b38fcd2005-10-25 14:09:51 -050044static u64 *xpc_part_nasids;
Dean Nelson33ba3c72008-07-29 22:34:07 -070045u64 *xpc_mach_nasids;
Dean Nelson89eb8eb2005-03-23 19:50:00 -070046
Dean Nelson94bd2702008-07-29 22:34:05 -070047/* >>> next two variables should be 'xpc_' if they remain here */
48static int xp_sizeof_nasid_mask; /* actual size in bytes of nasid mask */
49int xp_nasid_mask_words; /* actual size in words of nasid mask */
Dean Nelson4b38fcd2005-10-25 14:09:51 -050050
Dean Nelsonbc63d382008-07-29 22:34:04 -070051struct xpc_partition *xpc_partitions;
Dean Nelson89eb8eb2005-03-23 19:50:00 -070052
Dean Nelson89eb8eb2005-03-23 19:50:00 -070053/*
Dean Nelson4b38fcd2005-10-25 14:09:51 -050054 * Generic buffer used to store a local copy of portions of a remote
55 * partition's reserved page (either its header and part_nasids mask,
56 * or its vars).
Dean Nelson89eb8eb2005-03-23 19:50:00 -070057 */
Dean Nelson7682a4c2006-08-08 15:03:29 -050058char *xpc_remote_copy_buffer;
59void *xpc_remote_copy_buffer_base;
Dean Nelson89eb8eb2005-03-23 19:50:00 -070060
Dean Nelson89eb8eb2005-03-23 19:50:00 -070061/*
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050062 * Guarantee that the kmalloc'd memory is cacheline aligned.
63 */
Dean Nelson7682a4c2006-08-08 15:03:29 -050064void *
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050065xpc_kmalloc_cacheline_aligned(size_t size, gfp_t flags, void **base)
66{
67 /* see if kmalloc will give us cachline aligned memory by default */
68 *base = kmalloc(size, 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
72 if ((u64)*base == L1_CACHE_ALIGN((u64)*base))
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050073 return *base;
Dean Nelson2c2b94f2008-04-22 14:50:17 -050074
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050075 kfree(*base);
76
77 /* nope, we'll have to do it ourselves */
78 *base = kmalloc(size + L1_CACHE_BYTES, flags);
Dean Nelson2c2b94f2008-04-22 14:50:17 -050079 if (*base == NULL)
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050080 return NULL;
Dean Nelson2c2b94f2008-04-22 14:50:17 -050081
Dean Nelson4a3ad2d2008-04-22 14:48:01 -050082 return (void *)L1_CACHE_ALIGN((u64)*base);
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050083}
84
Jes Sorensen7aa6ba42006-02-17 05:18:43 -050085/*
Dean Nelson89eb8eb2005-03-23 19:50:00 -070086 * Given a nasid, get the physical address of the partition's reserved page
87 * for that nasid. This function returns 0 on any error.
88 */
89static u64
Dean Nelson27929022005-10-25 14:11:53 -050090xpc_get_rsvd_page_pa(int nasid)
Dean Nelson89eb8eb2005-03-23 19:50:00 -070091{
Dean Nelson908787d2008-07-29 22:34:05 -070092 enum xp_retval ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -070093 s64 status;
94 u64 cookie = 0;
95 u64 rp_pa = nasid; /* seed with nasid */
96 u64 len = 0;
Dean Nelson27929022005-10-25 14:11:53 -050097 u64 buf = buf;
98 u64 buf_len = 0;
99 void *buf_base = NULL;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700100
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700101 while (1) {
102
103 status = sn_partition_reserved_page_pa(buf, &cookie, &rp_pa,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500104 &len);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700105
106 dev_dbg(xpc_part, "SAL returned with status=%li, cookie="
107 "0x%016lx, address=0x%016lx, len=0x%016lx\n",
108 status, cookie, rp_pa, len);
109
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500110 if (status != SALRET_MORE_PASSES)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700111 break;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700112
Dean Nelson908787d2008-07-29 22:34:05 -0700113 /* >>> L1_CACHE_ALIGN() is only a sn2-bte_copy requirement */
Dean Nelson27929022005-10-25 14:11:53 -0500114 if (L1_CACHE_ALIGN(len) > buf_len) {
Jesper Juhlcbf283c2006-04-20 10:11:09 -0700115 kfree(buf_base);
Dean Nelson27929022005-10-25 14:11:53 -0500116 buf_len = L1_CACHE_ALIGN(len);
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500117 buf = (u64)xpc_kmalloc_cacheline_aligned(buf_len,
118 GFP_KERNEL,
119 &buf_base);
Dean Nelson27929022005-10-25 14:11:53 -0500120 if (buf_base == NULL) {
121 dev_err(xpc_part, "unable to kmalloc "
122 "len=0x%016lx\n", buf_len);
123 status = SALRET_ERROR;
124 break;
125 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700126 }
127
Dean Nelson908787d2008-07-29 22:34:05 -0700128 ret = xp_remote_memcpy((void *)buf, (void *)rp_pa, buf_len);
129 if (ret != xpSuccess) {
130 dev_dbg(xpc_part, "xp_remote_memcpy failed %d\n", ret);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700131 status = SALRET_ERROR;
132 break;
133 }
134 }
135
Jesper Juhlcbf283c2006-04-20 10:11:09 -0700136 kfree(buf_base);
Dean Nelson27929022005-10-25 14:11:53 -0500137
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500138 if (status != SALRET_OK)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700139 rp_pa = 0;
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500140
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700141 dev_dbg(xpc_part, "reserved page at phys address 0x%016lx\n", rp_pa);
142 return rp_pa;
143}
144
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700145/*
146 * Fill the partition reserved page with the information needed by
147 * other partitions to discover we are alive and establish initial
148 * communications.
149 */
150struct xpc_rsvd_page *
Dean Nelson94bd2702008-07-29 22:34:05 -0700151xpc_setup_rsvd_page(void)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700152{
153 struct xpc_rsvd_page *rp;
Dean Nelson94bd2702008-07-29 22:34:05 -0700154 u64 rp_pa;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700155
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700156 /* get the local reserved page's address */
157
Dean Nelson27929022005-10-25 14:11:53 -0500158 preempt_disable();
159 rp_pa = xpc_get_rsvd_page_pa(cpuid_to_nasid(smp_processor_id()));
160 preempt_enable();
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700161 if (rp_pa == 0) {
162 dev_err(xpc_part, "SAL failed to locate the reserved page\n");
163 return NULL;
164 }
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500165 rp = (struct xpc_rsvd_page *)__va(rp_pa);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700166
Dean Nelson94bd2702008-07-29 22:34:05 -0700167 if (rp->SAL_version < 3) {
168 /* SAL_versions < 3 had a SAL_partid defined as a u8 */
169 rp->SAL_partid &= 0xff;
170 }
171 BUG_ON(rp->SAL_partid != sn_partition_id);
172
173 if (rp->SAL_partid < 0 || rp->SAL_partid >= xp_max_npartitions) {
174 dev_err(xpc_part, "the reserved page's partid of %d is outside "
175 "supported range (< 0 || >= %d)\n", rp->SAL_partid,
176 xp_max_npartitions);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700177 return NULL;
178 }
179
180 rp->version = XPC_RP_VERSION;
Dean Nelson94bd2702008-07-29 22:34:05 -0700181 rp->max_npartitions = xp_max_npartitions;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700182
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500183 /* establish the actual sizes of the nasid masks */
184 if (rp->SAL_version == 1) {
185 /* SAL_version 1 didn't set the nasids_size field */
Dean Nelson94bd2702008-07-29 22:34:05 -0700186 rp->SAL_nasids_size = 128;
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500187 }
Dean Nelson94bd2702008-07-29 22:34:05 -0700188 xp_sizeof_nasid_mask = rp->SAL_nasids_size;
189 xp_nasid_mask_words = DIV_ROUND_UP(xp_sizeof_nasid_mask,
190 BYTES_PER_WORD);
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500191
192 /* setup the pointers to the various items in the reserved page */
193 xpc_part_nasids = XPC_RP_PART_NASIDS(rp);
194 xpc_mach_nasids = XPC_RP_MACH_NASIDS(rp);
Dean Nelson94bd2702008-07-29 22:34:05 -0700195
196 if (xpc_rsvd_page_init(rp) != xpSuccess)
197 return NULL;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700198
199 /*
Dean Nelson94bd2702008-07-29 22:34:05 -0700200 * Set timestamp of when reserved page was setup by XPC.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700201 * This signifies to the remote partition that our reserved
202 * page is initialized.
203 */
Dean Nelson94bd2702008-07-29 22:34:05 -0700204 rp->stamp = CURRENT_TIME;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700205
206 return rp;
207}
208
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700209/*
210 * Change protections to allow IPI operations (and AMO operations on
211 * Shub 1.1 systems).
212 */
213void
214xpc_allow_IPI_ops(void)
215{
216 int node;
217 int nasid;
218
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500219 /* >>> Change SH_IPI_ACCESS code to use SAL call once it is available */
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700220
221 if (is_shub2()) {
222 xpc_sh2_IPI_access0 =
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500223 (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS0));
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700224 xpc_sh2_IPI_access1 =
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500225 (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS1));
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700226 xpc_sh2_IPI_access2 =
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500227 (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS2));
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700228 xpc_sh2_IPI_access3 =
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500229 (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS3));
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700230
231 for_each_online_node(node) {
232 nasid = cnodeid_to_nasid(node);
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500233 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS0),
234 -1UL);
235 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS1),
236 -1UL);
237 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS2),
238 -1UL);
239 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS3),
240 -1UL);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700241 }
242
243 } else {
244 xpc_sh1_IPI_access =
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500245 (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH1_IPI_ACCESS));
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700246
247 for_each_online_node(node) {
248 nasid = cnodeid_to_nasid(node);
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500249 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH1_IPI_ACCESS),
250 -1UL);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700251
252 /*
253 * Since the BIST collides with memory operations on
254 * SHUB 1.1 sn_change_memprotect() cannot be used.
255 */
256 if (enable_shub_wars_1_1()) {
257 /* open up everything */
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500258 xpc_prot_vec[node] = (u64)HUB_L((u64 *)
259 GLOBAL_MMR_ADDR
260 (nasid,
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500261 SH1_MD_DQLP_MMR_DIR_PRIVEC0));
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500262 HUB_S((u64 *)
263 GLOBAL_MMR_ADDR(nasid,
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500264 SH1_MD_DQLP_MMR_DIR_PRIVEC0),
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500265 -1UL);
266 HUB_S((u64 *)
267 GLOBAL_MMR_ADDR(nasid,
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500268 SH1_MD_DQRP_MMR_DIR_PRIVEC0),
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500269 -1UL);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700270 }
271 }
272 }
273}
274
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700275/*
276 * Restrict protections to disallow IPI operations (and AMO operations on
277 * Shub 1.1 systems).
278 */
279void
280xpc_restrict_IPI_ops(void)
281{
282 int node;
283 int nasid;
284
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500285 /* >>> Change SH_IPI_ACCESS code to use SAL call once it is available */
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700286
287 if (is_shub2()) {
288
289 for_each_online_node(node) {
290 nasid = cnodeid_to_nasid(node);
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500291 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS0),
292 xpc_sh2_IPI_access0);
293 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS1),
294 xpc_sh2_IPI_access1);
295 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS2),
296 xpc_sh2_IPI_access2);
297 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS3),
298 xpc_sh2_IPI_access3);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700299 }
300
301 } else {
302
303 for_each_online_node(node) {
304 nasid = cnodeid_to_nasid(node);
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500305 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH1_IPI_ACCESS),
306 xpc_sh1_IPI_access);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700307
308 if (enable_shub_wars_1_1()) {
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500309 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid,
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500310 SH1_MD_DQLP_MMR_DIR_PRIVEC0),
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500311 xpc_prot_vec[node]);
312 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid,
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500313 SH1_MD_DQRP_MMR_DIR_PRIVEC0),
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500314 xpc_prot_vec[node]);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700315 }
316 }
317 }
318}
319
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700320/*
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500321 * Get a copy of a portion of the remote partition's rsvd page.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700322 *
323 * remote_rp points to a buffer that is cacheline aligned for BTE copies and
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500324 * is large enough to contain a copy of their reserved page header and
325 * part_nasids mask.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700326 */
Dean Nelson33ba3c72008-07-29 22:34:07 -0700327enum xp_retval
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700328xpc_get_remote_rp(int nasid, u64 *discovered_nasids,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500329 struct xpc_rsvd_page *remote_rp, u64 *remote_rp_pa)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700330{
Dean Nelson908787d2008-07-29 22:34:05 -0700331 int i;
332 enum xp_retval ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700333
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700334 /* get the reserved page's physical address */
335
Dean Nelson27929022005-10-25 14:11:53 -0500336 *remote_rp_pa = xpc_get_rsvd_page_pa(nasid);
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500337 if (*remote_rp_pa == 0)
Dean Nelson65c17b82008-05-12 14:02:02 -0700338 return xpNoRsvdPageAddr;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700339
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500340 /* pull over the reserved page header and part_nasids mask */
Dean Nelson908787d2008-07-29 22:34:05 -0700341 ret = xp_remote_memcpy(remote_rp, (void *)*remote_rp_pa,
Dean Nelson94bd2702008-07-29 22:34:05 -0700342 XPC_RP_HEADER_SIZE + xp_sizeof_nasid_mask);
Dean Nelson908787d2008-07-29 22:34:05 -0700343 if (ret != xpSuccess)
344 return ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700345
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700346 if (discovered_nasids != NULL) {
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500347 u64 *remote_part_nasids = XPC_RP_PART_NASIDS(remote_rp);
348
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500349 for (i = 0; i < xp_nasid_mask_words; i++)
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500350 discovered_nasids[i] |= remote_part_nasids[i];
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700351 }
352
Dean Nelson94bd2702008-07-29 22:34:05 -0700353 /* check that the partid is valid and is for another partition */
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700354
Dean Nelson94bd2702008-07-29 22:34:05 -0700355 if (remote_rp->SAL_partid < 0 ||
356 remote_rp->SAL_partid >= xp_max_npartitions) {
Dean Nelson65c17b82008-05-12 14:02:02 -0700357 return xpInvalidPartid;
Dean Nelson94bd2702008-07-29 22:34:05 -0700358 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700359
Dean Nelson94bd2702008-07-29 22:34:05 -0700360 if (remote_rp->SAL_partid == sn_partition_id)
Dean Nelson65c17b82008-05-12 14:02:02 -0700361 return xpLocalPartid;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700362
Dean Nelson94bd2702008-07-29 22:34:05 -0700363 /* see if the rest of the reserved page has been set up by XPC */
364 if (timespec_equal(&remote_rp->stamp, &ZERO_STAMP))
365 return xpRsvdPageNotSet;
366
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700367 if (XPC_VERSION_MAJOR(remote_rp->version) !=
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500368 XPC_VERSION_MAJOR(XPC_RP_VERSION)) {
Dean Nelson65c17b82008-05-12 14:02:02 -0700369 return xpBadVersion;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700370 }
371
Dean Nelson94bd2702008-07-29 22:34:05 -0700372 if (remote_rp->max_npartitions <= sn_partition_id)
373 return xpInvalidPartid;
374
Dean Nelson65c17b82008-05-12 14:02:02 -0700375 return xpSuccess;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700376}
377
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700378/*
Dean Nelsona607c382005-09-01 14:01:37 -0500379 * See if the other side has responded to a partition disengage request
380 * from us.
381 */
382int
383xpc_partition_disengaged(struct xpc_partition *part)
384{
Dean Nelson64d032b2008-05-12 14:02:03 -0700385 short partid = XPC_PARTID(part);
Dean Nelsona607c382005-09-01 14:01:37 -0500386 int disengaged;
387
Dean Nelsona607c382005-09-01 14:01:37 -0500388 disengaged = (xpc_partition_engaged(1UL << partid) == 0);
389 if (part->disengage_request_timeout) {
390 if (!disengaged) {
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500391 if (time_before(jiffies,
392 part->disengage_request_timeout)) {
Dean Nelsona607c382005-09-01 14:01:37 -0500393 /* timelimit hasn't been reached yet */
394 return 0;
395 }
396
397 /*
398 * Other side hasn't responded to our disengage
399 * request in a timely fashion, so assume it's dead.
400 */
401
Dean Nelson1ecaded2006-01-06 09:48:21 -0600402 dev_info(xpc_part, "disengage from remote partition %d "
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500403 "timed out\n", partid);
Dean Nelson1ecaded2006-01-06 09:48:21 -0600404 xpc_disengage_request_timedout = 1;
Dean Nelsona607c382005-09-01 14:01:37 -0500405 xpc_clear_partition_engaged(1UL << partid);
406 disengaged = 1;
407 }
408 part->disengage_request_timeout = 0;
409
410 /* cancel the timer function, provided it's not us */
411 if (!in_interrupt()) {
412 del_singleshot_timer_sync(&part->
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500413 disengage_request_timer);
Dean Nelsona607c382005-09-01 14:01:37 -0500414 }
415
416 DBUG_ON(part->act_state != XPC_P_DEACTIVATING &&
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500417 part->act_state != XPC_P_INACTIVE);
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500418 if (part->act_state != XPC_P_INACTIVE)
Dean Nelsona607c382005-09-01 14:01:37 -0500419 xpc_wakeup_channel_mgr(part);
Dean Nelsona607c382005-09-01 14:01:37 -0500420
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500421 if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version))
Dean Nelsona607c382005-09-01 14:01:37 -0500422 xpc_cancel_partition_disengage_request(part);
Dean Nelsona607c382005-09-01 14:01:37 -0500423 }
424 return disengaged;
425}
426
Dean Nelsona607c382005-09-01 14:01:37 -0500427/*
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700428 * Mark specified partition as active.
429 */
Dean Nelson65c17b82008-05-12 14:02:02 -0700430enum xp_retval
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700431xpc_mark_partition_active(struct xpc_partition *part)
432{
433 unsigned long irq_flags;
Dean Nelson65c17b82008-05-12 14:02:02 -0700434 enum xp_retval ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700435
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700436 dev_dbg(xpc_part, "setting partition %d to ACTIVE\n", XPC_PARTID(part));
437
438 spin_lock_irqsave(&part->act_lock, irq_flags);
439 if (part->act_state == XPC_P_ACTIVATING) {
440 part->act_state = XPC_P_ACTIVE;
Dean Nelson65c17b82008-05-12 14:02:02 -0700441 ret = xpSuccess;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700442 } else {
Dean Nelson65c17b82008-05-12 14:02:02 -0700443 DBUG_ON(part->reason == xpSuccess);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700444 ret = part->reason;
445 }
446 spin_unlock_irqrestore(&part->act_lock, irq_flags);
447
448 return ret;
449}
450
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700451/*
452 * Notify XPC that the partition is down.
453 */
454void
455xpc_deactivate_partition(const int line, struct xpc_partition *part,
Dean Nelson65c17b82008-05-12 14:02:02 -0700456 enum xp_retval reason)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700457{
458 unsigned long irq_flags;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700459
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700460 spin_lock_irqsave(&part->act_lock, irq_flags);
461
462 if (part->act_state == XPC_P_INACTIVE) {
463 XPC_SET_REASON(part, reason, line);
464 spin_unlock_irqrestore(&part->act_lock, irq_flags);
Dean Nelson65c17b82008-05-12 14:02:02 -0700465 if (reason == xpReactivating) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700466 /* we interrupt ourselves to reactivate partition */
Dean Nelson33ba3c72008-07-29 22:34:07 -0700467 xpc_IPI_send_local_reactivate(part->reactivate_nasid);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700468 }
469 return;
470 }
471 if (part->act_state == XPC_P_DEACTIVATING) {
Dean Nelson65c17b82008-05-12 14:02:02 -0700472 if ((part->reason == xpUnloading && reason != xpUnloading) ||
473 reason == xpReactivating) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700474 XPC_SET_REASON(part, reason, line);
475 }
476 spin_unlock_irqrestore(&part->act_lock, irq_flags);
477 return;
478 }
479
480 part->act_state = XPC_P_DEACTIVATING;
481 XPC_SET_REASON(part, reason, line);
482
483 spin_unlock_irqrestore(&part->act_lock, irq_flags);
484
Dean Nelsona607c382005-09-01 14:01:37 -0500485 if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version)) {
486 xpc_request_partition_disengage(part);
487 xpc_IPI_send_disengage(part);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700488
Dean Nelsona607c382005-09-01 14:01:37 -0500489 /* set a timelimit on the disengage request */
490 part->disengage_request_timeout = jiffies +
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500491 (xpc_disengage_request_timelimit * HZ);
Dean Nelsona607c382005-09-01 14:01:37 -0500492 part->disengage_request_timer.expires =
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500493 part->disengage_request_timeout;
Dean Nelsona607c382005-09-01 14:01:37 -0500494 add_timer(&part->disengage_request_timer);
495 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700496
Dean Nelsone54af722005-10-25 14:07:43 -0500497 dev_dbg(xpc_part, "bringing partition %d down, reason = %d\n",
498 XPC_PARTID(part), reason);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700499
Dean Nelsona607c382005-09-01 14:01:37 -0500500 xpc_partition_going_down(part, reason);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700501}
502
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700503/*
Dean Nelsona607c382005-09-01 14:01:37 -0500504 * Mark specified partition as inactive.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700505 */
506void
507xpc_mark_partition_inactive(struct xpc_partition *part)
508{
509 unsigned long irq_flags;
510
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700511 dev_dbg(xpc_part, "setting partition %d to INACTIVE\n",
512 XPC_PARTID(part));
513
514 spin_lock_irqsave(&part->act_lock, irq_flags);
515 part->act_state = XPC_P_INACTIVE;
516 spin_unlock_irqrestore(&part->act_lock, irq_flags);
517 part->remote_rp_pa = 0;
518}
519
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700520/*
521 * SAL has provided a partition and machine mask. The partition mask
522 * contains a bit for each even nasid in our partition. The machine
523 * mask contains a bit for each even nasid in the entire machine.
524 *
525 * Using those two bit arrays, we can determine which nasids are
526 * known in the machine. Each should also have a reserved page
527 * initialized if they are available for partitioning.
528 */
529void
530xpc_discovery(void)
531{
532 void *remote_rp_base;
533 struct xpc_rsvd_page *remote_rp;
Dean Nelsona607c382005-09-01 14:01:37 -0500534 u64 remote_rp_pa;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700535 int region;
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500536 int region_size;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700537 int max_regions;
538 int nasid;
539 struct xpc_rsvd_page *rp;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700540 u64 *discovered_nasids;
Dean Nelson65c17b82008-05-12 14:02:02 -0700541 enum xp_retval ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700542
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500543 remote_rp = xpc_kmalloc_cacheline_aligned(XPC_RP_HEADER_SIZE +
Dean Nelson94bd2702008-07-29 22:34:05 -0700544 xp_sizeof_nasid_mask,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500545 GFP_KERNEL, &remote_rp_base);
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500546 if (remote_rp == NULL)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700547 return;
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500548
Jes Sorensen7aa6ba42006-02-17 05:18:43 -0500549 discovered_nasids = kzalloc(sizeof(u64) * xp_nasid_mask_words,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500550 GFP_KERNEL);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700551 if (discovered_nasids == NULL) {
552 kfree(remote_rp_base);
553 return;
554 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700555
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500556 rp = (struct xpc_rsvd_page *)xpc_rsvd_page;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700557
558 /*
559 * The term 'region' in this context refers to the minimum number of
560 * nodes that can comprise an access protection grouping. The access
561 * protection is in regards to memory, IOI and IPI.
562 */
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500563 max_regions = 64;
564 region_size = sn_region_size;
565
566 switch (region_size) {
567 case 128:
568 max_regions *= 2;
569 case 64:
570 max_regions *= 2;
571 case 32:
572 max_regions *= 2;
573 region_size = 16;
574 DBUG_ON(!is_shub2());
575 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700576
577 for (region = 0; region < max_regions; region++) {
578
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500579 if (xpc_exiting)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700580 break;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700581
582 dev_dbg(xpc_part, "searching region %d\n", region);
583
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500584 for (nasid = (region * region_size * 2);
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500585 nasid < ((region + 1) * region_size * 2); nasid += 2) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700586
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500587 if (xpc_exiting)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700588 break;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700589
590 dev_dbg(xpc_part, "checking nasid %d\n", nasid);
591
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500592 if (XPC_NASID_IN_ARRAY(nasid, xpc_part_nasids)) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700593 dev_dbg(xpc_part, "PROM indicates Nasid %d is "
594 "part of the local partition; skipping "
595 "region\n", nasid);
596 break;
597 }
598
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500599 if (!(XPC_NASID_IN_ARRAY(nasid, xpc_mach_nasids))) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700600 dev_dbg(xpc_part, "PROM indicates Nasid %d was "
601 "not on Numa-Link network at reset\n",
602 nasid);
603 continue;
604 }
605
606 if (XPC_NASID_IN_ARRAY(nasid, discovered_nasids)) {
607 dev_dbg(xpc_part, "Nasid %d is part of a "
608 "partition which was previously "
609 "discovered\n", nasid);
610 continue;
611 }
612
Dean Nelson33ba3c72008-07-29 22:34:07 -0700613 /* pull over the rsvd page header & part_nasids mask */
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700614
615 ret = xpc_get_remote_rp(nasid, discovered_nasids,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500616 remote_rp, &remote_rp_pa);
Dean Nelson65c17b82008-05-12 14:02:02 -0700617 if (ret != xpSuccess) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700618 dev_dbg(xpc_part, "unable to get reserved page "
619 "from nasid %d, reason=%d\n", nasid,
620 ret);
621
Dean Nelson65c17b82008-05-12 14:02:02 -0700622 if (ret == xpLocalPartid)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700623 break;
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500624
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700625 continue;
626 }
627
Dean Nelson33ba3c72008-07-29 22:34:07 -0700628 xpc_initiate_partition_activation(remote_rp,
629 remote_rp_pa, nasid);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700630 }
631 }
632
633 kfree(discovered_nasids);
634 kfree(remote_rp_base);
635}
636
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700637/*
638 * Given a partid, get the nasids owned by that partition from the
Dean Nelson3a7d5552005-04-04 13:14:00 -0700639 * remote partition's reserved page.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700640 */
Dean Nelson65c17b82008-05-12 14:02:02 -0700641enum xp_retval
Dean Nelson64d032b2008-05-12 14:02:03 -0700642xpc_initiate_partid_to_nasids(short partid, void *nasid_mask)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700643{
644 struct xpc_partition *part;
645 u64 part_nasid_pa;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700646
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700647 part = &xpc_partitions[partid];
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500648 if (part->remote_rp_pa == 0)
Dean Nelson65c17b82008-05-12 14:02:02 -0700649 return xpPartitionDown;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700650
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500651 memset(nasid_mask, 0, XP_NASID_MASK_BYTES);
652
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500653 part_nasid_pa = (u64)XPC_RP_PART_NASIDS(part->remote_rp_pa);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700654
Dean Nelson908787d2008-07-29 22:34:05 -0700655 return xp_remote_memcpy(nasid_mask, (void *)part_nasid_pa,
Dean Nelson94bd2702008-07-29 22:34:05 -0700656 xp_sizeof_nasid_mask);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700657}