blob: 90ec5ca8c9ab134339202b5b0bb6ddfb4d1e90cc [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 Nelsonaaa3cd62008-07-29 22:34:07 -0700155 unsigned long new_stamp;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700156
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700157 /* get the local reserved page's address */
158
Dean Nelson27929022005-10-25 14:11:53 -0500159 preempt_disable();
160 rp_pa = xpc_get_rsvd_page_pa(cpuid_to_nasid(smp_processor_id()));
161 preempt_enable();
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700162 if (rp_pa == 0) {
163 dev_err(xpc_part, "SAL failed to locate the reserved page\n");
164 return NULL;
165 }
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500166 rp = (struct xpc_rsvd_page *)__va(rp_pa);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700167
Dean Nelson94bd2702008-07-29 22:34:05 -0700168 if (rp->SAL_version < 3) {
169 /* SAL_versions < 3 had a SAL_partid defined as a u8 */
170 rp->SAL_partid &= 0xff;
171 }
172 BUG_ON(rp->SAL_partid != sn_partition_id);
173
174 if (rp->SAL_partid < 0 || rp->SAL_partid >= xp_max_npartitions) {
175 dev_err(xpc_part, "the reserved page's partid of %d is outside "
176 "supported range (< 0 || >= %d)\n", rp->SAL_partid,
177 xp_max_npartitions);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700178 return NULL;
179 }
180
181 rp->version = XPC_RP_VERSION;
Dean Nelson94bd2702008-07-29 22:34:05 -0700182 rp->max_npartitions = xp_max_npartitions;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700183
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500184 /* establish the actual sizes of the nasid masks */
185 if (rp->SAL_version == 1) {
186 /* SAL_version 1 didn't set the nasids_size field */
Dean Nelson94bd2702008-07-29 22:34:05 -0700187 rp->SAL_nasids_size = 128;
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500188 }
Dean Nelson94bd2702008-07-29 22:34:05 -0700189 xp_sizeof_nasid_mask = rp->SAL_nasids_size;
190 xp_nasid_mask_words = DIV_ROUND_UP(xp_sizeof_nasid_mask,
191 BYTES_PER_WORD);
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500192
193 /* setup the pointers to the various items in the reserved page */
194 xpc_part_nasids = XPC_RP_PART_NASIDS(rp);
195 xpc_mach_nasids = XPC_RP_MACH_NASIDS(rp);
Dean Nelson94bd2702008-07-29 22:34:05 -0700196
197 if (xpc_rsvd_page_init(rp) != xpSuccess)
198 return NULL;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700199
200 /*
Dean Nelson94bd2702008-07-29 22:34:05 -0700201 * Set timestamp of when reserved page was setup by XPC.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700202 * This signifies to the remote partition that our reserved
203 * page is initialized.
204 */
Dean Nelsonaaa3cd62008-07-29 22:34:07 -0700205 new_stamp = jiffies;
206 if (new_stamp == 0 || new_stamp == rp->stamp)
207 new_stamp++;
208 rp->stamp = new_stamp;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700209
210 return rp;
211}
212
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700213/*
214 * Change protections to allow IPI operations (and AMO operations on
215 * Shub 1.1 systems).
216 */
217void
218xpc_allow_IPI_ops(void)
219{
220 int node;
221 int nasid;
222
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500223 /* >>> Change SH_IPI_ACCESS code to use SAL call once it is available */
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700224
225 if (is_shub2()) {
226 xpc_sh2_IPI_access0 =
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500227 (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS0));
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700228 xpc_sh2_IPI_access1 =
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500229 (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS1));
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700230 xpc_sh2_IPI_access2 =
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500231 (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS2));
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700232 xpc_sh2_IPI_access3 =
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500233 (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS3));
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700234
235 for_each_online_node(node) {
236 nasid = cnodeid_to_nasid(node);
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500237 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS0),
238 -1UL);
239 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS1),
240 -1UL);
241 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS2),
242 -1UL);
243 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS3),
244 -1UL);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700245 }
246
247 } else {
248 xpc_sh1_IPI_access =
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500249 (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH1_IPI_ACCESS));
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700250
251 for_each_online_node(node) {
252 nasid = cnodeid_to_nasid(node);
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500253 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH1_IPI_ACCESS),
254 -1UL);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700255
256 /*
257 * Since the BIST collides with memory operations on
258 * SHUB 1.1 sn_change_memprotect() cannot be used.
259 */
260 if (enable_shub_wars_1_1()) {
261 /* open up everything */
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500262 xpc_prot_vec[node] = (u64)HUB_L((u64 *)
263 GLOBAL_MMR_ADDR
264 (nasid,
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500265 SH1_MD_DQLP_MMR_DIR_PRIVEC0));
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500266 HUB_S((u64 *)
267 GLOBAL_MMR_ADDR(nasid,
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500268 SH1_MD_DQLP_MMR_DIR_PRIVEC0),
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500269 -1UL);
270 HUB_S((u64 *)
271 GLOBAL_MMR_ADDR(nasid,
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500272 SH1_MD_DQRP_MMR_DIR_PRIVEC0),
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500273 -1UL);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700274 }
275 }
276 }
277}
278
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700279/*
280 * Restrict protections to disallow IPI operations (and AMO operations on
281 * Shub 1.1 systems).
282 */
283void
284xpc_restrict_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
293 for_each_online_node(node) {
294 nasid = cnodeid_to_nasid(node);
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500295 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS0),
296 xpc_sh2_IPI_access0);
297 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS1),
298 xpc_sh2_IPI_access1);
299 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS2),
300 xpc_sh2_IPI_access2);
301 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS3),
302 xpc_sh2_IPI_access3);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700303 }
304
305 } else {
306
307 for_each_online_node(node) {
308 nasid = cnodeid_to_nasid(node);
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500309 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH1_IPI_ACCESS),
310 xpc_sh1_IPI_access);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700311
312 if (enable_shub_wars_1_1()) {
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500313 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid,
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500314 SH1_MD_DQLP_MMR_DIR_PRIVEC0),
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500315 xpc_prot_vec[node]);
316 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid,
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500317 SH1_MD_DQRP_MMR_DIR_PRIVEC0),
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500318 xpc_prot_vec[node]);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700319 }
320 }
321 }
322}
323
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700324/*
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500325 * Get a copy of a portion of the remote partition's rsvd page.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700326 *
327 * remote_rp points to a buffer that is cacheline aligned for BTE copies and
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500328 * is large enough to contain a copy of their reserved page header and
329 * part_nasids mask.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700330 */
Dean Nelson33ba3c72008-07-29 22:34:07 -0700331enum xp_retval
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700332xpc_get_remote_rp(int nasid, u64 *discovered_nasids,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500333 struct xpc_rsvd_page *remote_rp, u64 *remote_rp_pa)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700334{
Dean Nelson908787d2008-07-29 22:34:05 -0700335 int i;
336 enum xp_retval ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700337
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700338 /* get the reserved page's physical address */
339
Dean Nelson27929022005-10-25 14:11:53 -0500340 *remote_rp_pa = xpc_get_rsvd_page_pa(nasid);
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500341 if (*remote_rp_pa == 0)
Dean Nelson65c17b82008-05-12 14:02:02 -0700342 return xpNoRsvdPageAddr;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700343
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500344 /* pull over the reserved page header and part_nasids mask */
Dean Nelson908787d2008-07-29 22:34:05 -0700345 ret = xp_remote_memcpy(remote_rp, (void *)*remote_rp_pa,
Dean Nelson94bd2702008-07-29 22:34:05 -0700346 XPC_RP_HEADER_SIZE + xp_sizeof_nasid_mask);
Dean Nelson908787d2008-07-29 22:34:05 -0700347 if (ret != xpSuccess)
348 return ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700349
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700350 if (discovered_nasids != NULL) {
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500351 u64 *remote_part_nasids = XPC_RP_PART_NASIDS(remote_rp);
352
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500353 for (i = 0; i < xp_nasid_mask_words; i++)
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500354 discovered_nasids[i] |= remote_part_nasids[i];
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700355 }
356
Dean Nelsonaaa3cd62008-07-29 22:34:07 -0700357 /* see if the reserved page has been set up by XPC */
358 if (remote_rp->stamp == 0)
Dean Nelson94bd2702008-07-29 22:34:05 -0700359 return xpRsvdPageNotSet;
360
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700361 if (XPC_VERSION_MAJOR(remote_rp->version) !=
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500362 XPC_VERSION_MAJOR(XPC_RP_VERSION)) {
Dean Nelson65c17b82008-05-12 14:02:02 -0700363 return xpBadVersion;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700364 }
365
Dean Nelsonaaa3cd62008-07-29 22:34:07 -0700366 /* check that both local and remote partids are valid for each side */
367 if (remote_rp->SAL_partid < 0 ||
368 remote_rp->SAL_partid >= xp_max_npartitions ||
369 remote_rp->max_npartitions <= sn_partition_id) {
Dean Nelson94bd2702008-07-29 22:34:05 -0700370 return xpInvalidPartid;
Dean Nelsonaaa3cd62008-07-29 22:34:07 -0700371 }
372
373 if (remote_rp->SAL_partid == sn_partition_id)
374 return xpLocalPartid;
Dean Nelson94bd2702008-07-29 22:34:05 -0700375
Dean Nelson65c17b82008-05-12 14:02:02 -0700376 return xpSuccess;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700377}
378
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700379/*
Dean Nelsona607c382005-09-01 14:01:37 -0500380 * See if the other side has responded to a partition disengage request
381 * from us.
382 */
383int
384xpc_partition_disengaged(struct xpc_partition *part)
385{
Dean Nelson64d032b2008-05-12 14:02:03 -0700386 short partid = XPC_PARTID(part);
Dean Nelsona607c382005-09-01 14:01:37 -0500387 int disengaged;
388
Dean Nelsona607c382005-09-01 14:01:37 -0500389 disengaged = (xpc_partition_engaged(1UL << partid) == 0);
390 if (part->disengage_request_timeout) {
391 if (!disengaged) {
Dean Nelsonaaa3cd62008-07-29 22:34:07 -0700392 if (time_is_after_jiffies(part->
393 disengage_request_timeout)) {
Dean Nelsona607c382005-09-01 14:01:37 -0500394 /* timelimit hasn't been reached yet */
395 return 0;
396 }
397
398 /*
399 * Other side hasn't responded to our disengage
400 * request in a timely fashion, so assume it's dead.
401 */
402
Dean Nelson1ecaded2006-01-06 09:48:21 -0600403 dev_info(xpc_part, "disengage from remote partition %d "
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500404 "timed out\n", partid);
Dean Nelson1ecaded2006-01-06 09:48:21 -0600405 xpc_disengage_request_timedout = 1;
Dean Nelsona607c382005-09-01 14:01:37 -0500406 xpc_clear_partition_engaged(1UL << partid);
407 disengaged = 1;
408 }
409 part->disengage_request_timeout = 0;
410
411 /* cancel the timer function, provided it's not us */
412 if (!in_interrupt()) {
413 del_singleshot_timer_sync(&part->
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500414 disengage_request_timer);
Dean Nelsona607c382005-09-01 14:01:37 -0500415 }
416
417 DBUG_ON(part->act_state != XPC_P_DEACTIVATING &&
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500418 part->act_state != XPC_P_INACTIVE);
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500419 if (part->act_state != XPC_P_INACTIVE)
Dean Nelsona607c382005-09-01 14:01:37 -0500420 xpc_wakeup_channel_mgr(part);
Dean Nelsona607c382005-09-01 14:01:37 -0500421
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500422 if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version))
Dean Nelsona607c382005-09-01 14:01:37 -0500423 xpc_cancel_partition_disengage_request(part);
Dean Nelsona607c382005-09-01 14:01:37 -0500424 }
425 return disengaged;
426}
427
Dean Nelsona607c382005-09-01 14:01:37 -0500428/*
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700429 * Mark specified partition as active.
430 */
Dean Nelson65c17b82008-05-12 14:02:02 -0700431enum xp_retval
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700432xpc_mark_partition_active(struct xpc_partition *part)
433{
434 unsigned long irq_flags;
Dean Nelson65c17b82008-05-12 14:02:02 -0700435 enum xp_retval ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700436
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700437 dev_dbg(xpc_part, "setting partition %d to ACTIVE\n", XPC_PARTID(part));
438
439 spin_lock_irqsave(&part->act_lock, irq_flags);
440 if (part->act_state == XPC_P_ACTIVATING) {
441 part->act_state = XPC_P_ACTIVE;
Dean Nelson65c17b82008-05-12 14:02:02 -0700442 ret = xpSuccess;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700443 } else {
Dean Nelson65c17b82008-05-12 14:02:02 -0700444 DBUG_ON(part->reason == xpSuccess);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700445 ret = part->reason;
446 }
447 spin_unlock_irqrestore(&part->act_lock, irq_flags);
448
449 return ret;
450}
451
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700452/*
453 * Notify XPC that the partition is down.
454 */
455void
456xpc_deactivate_partition(const int line, struct xpc_partition *part,
Dean Nelson65c17b82008-05-12 14:02:02 -0700457 enum xp_retval reason)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700458{
459 unsigned long irq_flags;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700460
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700461 spin_lock_irqsave(&part->act_lock, irq_flags);
462
463 if (part->act_state == XPC_P_INACTIVE) {
464 XPC_SET_REASON(part, reason, line);
465 spin_unlock_irqrestore(&part->act_lock, irq_flags);
Dean Nelson65c17b82008-05-12 14:02:02 -0700466 if (reason == xpReactivating) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700467 /* we interrupt ourselves to reactivate partition */
Dean Nelson33ba3c72008-07-29 22:34:07 -0700468 xpc_IPI_send_local_reactivate(part->reactivate_nasid);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700469 }
470 return;
471 }
472 if (part->act_state == XPC_P_DEACTIVATING) {
Dean Nelson65c17b82008-05-12 14:02:02 -0700473 if ((part->reason == xpUnloading && reason != xpUnloading) ||
474 reason == xpReactivating) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700475 XPC_SET_REASON(part, reason, line);
476 }
477 spin_unlock_irqrestore(&part->act_lock, irq_flags);
478 return;
479 }
480
481 part->act_state = XPC_P_DEACTIVATING;
482 XPC_SET_REASON(part, reason, line);
483
484 spin_unlock_irqrestore(&part->act_lock, irq_flags);
485
Dean Nelsona607c382005-09-01 14:01:37 -0500486 if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version)) {
487 xpc_request_partition_disengage(part);
488 xpc_IPI_send_disengage(part);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700489
Dean Nelsona607c382005-09-01 14:01:37 -0500490 /* set a timelimit on the disengage request */
491 part->disengage_request_timeout = jiffies +
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500492 (xpc_disengage_request_timelimit * HZ);
Dean Nelsona607c382005-09-01 14:01:37 -0500493 part->disengage_request_timer.expires =
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500494 part->disengage_request_timeout;
Dean Nelsona607c382005-09-01 14:01:37 -0500495 add_timer(&part->disengage_request_timer);
496 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700497
Dean Nelsone54af722005-10-25 14:07:43 -0500498 dev_dbg(xpc_part, "bringing partition %d down, reason = %d\n",
499 XPC_PARTID(part), reason);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700500
Dean Nelsona607c382005-09-01 14:01:37 -0500501 xpc_partition_going_down(part, reason);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700502}
503
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700504/*
Dean Nelsona607c382005-09-01 14:01:37 -0500505 * Mark specified partition as inactive.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700506 */
507void
508xpc_mark_partition_inactive(struct xpc_partition *part)
509{
510 unsigned long irq_flags;
511
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700512 dev_dbg(xpc_part, "setting partition %d to INACTIVE\n",
513 XPC_PARTID(part));
514
515 spin_lock_irqsave(&part->act_lock, irq_flags);
516 part->act_state = XPC_P_INACTIVE;
517 spin_unlock_irqrestore(&part->act_lock, irq_flags);
518 part->remote_rp_pa = 0;
519}
520
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700521/*
522 * SAL has provided a partition and machine mask. The partition mask
523 * contains a bit for each even nasid in our partition. The machine
524 * mask contains a bit for each even nasid in the entire machine.
525 *
526 * Using those two bit arrays, we can determine which nasids are
527 * known in the machine. Each should also have a reserved page
528 * initialized if they are available for partitioning.
529 */
530void
531xpc_discovery(void)
532{
533 void *remote_rp_base;
534 struct xpc_rsvd_page *remote_rp;
Dean Nelsona607c382005-09-01 14:01:37 -0500535 u64 remote_rp_pa;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700536 int region;
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500537 int region_size;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700538 int max_regions;
539 int nasid;
540 struct xpc_rsvd_page *rp;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700541 u64 *discovered_nasids;
Dean Nelson65c17b82008-05-12 14:02:02 -0700542 enum xp_retval ret;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700543
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500544 remote_rp = xpc_kmalloc_cacheline_aligned(XPC_RP_HEADER_SIZE +
Dean Nelson94bd2702008-07-29 22:34:05 -0700545 xp_sizeof_nasid_mask,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500546 GFP_KERNEL, &remote_rp_base);
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500547 if (remote_rp == NULL)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700548 return;
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500549
Jes Sorensen7aa6ba42006-02-17 05:18:43 -0500550 discovered_nasids = kzalloc(sizeof(u64) * xp_nasid_mask_words,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500551 GFP_KERNEL);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700552 if (discovered_nasids == NULL) {
553 kfree(remote_rp_base);
554 return;
555 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700556
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500557 rp = (struct xpc_rsvd_page *)xpc_rsvd_page;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700558
559 /*
560 * The term 'region' in this context refers to the minimum number of
561 * nodes that can comprise an access protection grouping. The access
562 * protection is in regards to memory, IOI and IPI.
563 */
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500564 max_regions = 64;
565 region_size = sn_region_size;
566
567 switch (region_size) {
568 case 128:
569 max_regions *= 2;
570 case 64:
571 max_regions *= 2;
572 case 32:
573 max_regions *= 2;
574 region_size = 16;
575 DBUG_ON(!is_shub2());
576 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700577
578 for (region = 0; region < max_regions; region++) {
579
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500580 if (xpc_exiting)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700581 break;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700582
583 dev_dbg(xpc_part, "searching region %d\n", region);
584
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500585 for (nasid = (region * region_size * 2);
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500586 nasid < ((region + 1) * region_size * 2); nasid += 2) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700587
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500588 if (xpc_exiting)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700589 break;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700590
591 dev_dbg(xpc_part, "checking nasid %d\n", nasid);
592
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500593 if (XPC_NASID_IN_ARRAY(nasid, xpc_part_nasids)) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700594 dev_dbg(xpc_part, "PROM indicates Nasid %d is "
595 "part of the local partition; skipping "
596 "region\n", nasid);
597 break;
598 }
599
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500600 if (!(XPC_NASID_IN_ARRAY(nasid, xpc_mach_nasids))) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700601 dev_dbg(xpc_part, "PROM indicates Nasid %d was "
602 "not on Numa-Link network at reset\n",
603 nasid);
604 continue;
605 }
606
607 if (XPC_NASID_IN_ARRAY(nasid, discovered_nasids)) {
608 dev_dbg(xpc_part, "Nasid %d is part of a "
609 "partition which was previously "
610 "discovered\n", nasid);
611 continue;
612 }
613
Dean Nelson33ba3c72008-07-29 22:34:07 -0700614 /* pull over the rsvd page header & part_nasids mask */
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700615
616 ret = xpc_get_remote_rp(nasid, discovered_nasids,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500617 remote_rp, &remote_rp_pa);
Dean Nelson65c17b82008-05-12 14:02:02 -0700618 if (ret != xpSuccess) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700619 dev_dbg(xpc_part, "unable to get reserved page "
620 "from nasid %d, reason=%d\n", nasid,
621 ret);
622
Dean Nelson65c17b82008-05-12 14:02:02 -0700623 if (ret == xpLocalPartid)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700624 break;
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500625
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700626 continue;
627 }
628
Dean Nelson33ba3c72008-07-29 22:34:07 -0700629 xpc_initiate_partition_activation(remote_rp,
630 remote_rp_pa, nasid);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700631 }
632 }
633
634 kfree(discovered_nasids);
635 kfree(remote_rp_base);
636}
637
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700638/*
639 * Given a partid, get the nasids owned by that partition from the
Dean Nelson3a7d5552005-04-04 13:14:00 -0700640 * remote partition's reserved page.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700641 */
Dean Nelson65c17b82008-05-12 14:02:02 -0700642enum xp_retval
Dean Nelson64d032b2008-05-12 14:02:03 -0700643xpc_initiate_partid_to_nasids(short partid, void *nasid_mask)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700644{
645 struct xpc_partition *part;
646 u64 part_nasid_pa;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700647
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700648 part = &xpc_partitions[partid];
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500649 if (part->remote_rp_pa == 0)
Dean Nelson65c17b82008-05-12 14:02:02 -0700650 return xpPartitionDown;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700651
Dean Nelson4b38fcd2005-10-25 14:09:51 -0500652 memset(nasid_mask, 0, XP_NASID_MASK_BYTES);
653
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500654 part_nasid_pa = (u64)XPC_RP_PART_NASIDS(part->remote_rp_pa);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700655
Dean Nelson908787d2008-07-29 22:34:05 -0700656 return xp_remote_memcpy(nasid_mask, (void *)part_nasid_pa,
Dean Nelson94bd2702008-07-29 22:34:05 -0700657 xp_sizeof_nasid_mask);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700658}