blob: f673ba90eb0eb2ab68187e00b723431f15d90389 [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) support - standard version.
11 *
12 * XPC provides a message passing capability that crosses partition
13 * boundaries. This module is made up of two parts:
14 *
15 * partition This part detects the presence/absence of other
16 * partitions. It provides a heartbeat and monitors
17 * the heartbeats of other partitions.
18 *
19 * channel This part manages the channels and sends/receives
20 * messages across them to/from other partitions.
21 *
22 * There are a couple of additional functions residing in XP, which
23 * provide an interface to XPC for its users.
24 *
25 *
26 * Caveats:
27 *
28 * . We currently have no way to determine which nasid an IPI came
29 * from. Thus, xpc_IPI_send() does a remote AMO write followed by
30 * an IPI. The AMO indicates where data is to be pulled from, so
31 * after the IPI arrives, the remote partition checks the AMO word.
32 * The IPI can actually arrive before the AMO however, so other code
33 * must periodically check for this case. Also, remote AMO operations
34 * do not reliably time out. Thus we do a remote PIO read solely to
35 * know whether the remote partition is down and whether we should
36 * stop sending IPIs to it. This remote PIO read operation is set up
37 * in a special nofault region so SAL knows to ignore (and cleanup)
38 * any errors due to the remote AMO write, PIO read, and/or PIO
39 * write operations.
40 *
41 * If/when new hardware solves this IPI problem, we should abandon
42 * the current approach.
43 *
44 */
45
Dean Nelson89eb8eb2005-03-23 19:50:00 -070046#include <linux/kernel.h>
47#include <linux/module.h>
48#include <linux/init.h>
Dean Nelson89eb8eb2005-03-23 19:50:00 -070049#include <linux/cache.h>
50#include <linux/interrupt.h>
Nishanth Aravamudan69913922005-07-08 17:10:00 -070051#include <linux/delay.h>
Dean Nelsona607c382005-09-01 14:01:37 -050052#include <linux/reboot.h>
Jes Sorensenf9e505a2006-01-17 12:52:21 -050053#include <linux/completion.h>
Christoph Hellwig1eeb66a2007-05-08 00:27:03 -070054#include <linux/kdebug.h>
Dean Nelson2c2b94f2008-04-22 14:50:17 -050055#include <linux/kthread.h>
56#include <linux/uaccess.h>
Dean Nelson89eb8eb2005-03-23 19:50:00 -070057#include <asm/sn/intr.h>
58#include <asm/sn/sn_sal.h>
Dean Nelson45d9ca42008-04-22 14:46:56 -050059#include "xpc.h"
Dean Nelson89eb8eb2005-03-23 19:50:00 -070060
Dean Nelson89eb8eb2005-03-23 19:50:00 -070061/* define two XPC debug device structures to be used with dev_dbg() et al */
62
63struct device_driver xpc_dbg_name = {
64 .name = "xpc"
65};
66
67struct device xpc_part_dbg_subname = {
68 .bus_id = {0}, /* set to "part" at xpc_init() time */
69 .driver = &xpc_dbg_name
70};
71
72struct device xpc_chan_dbg_subname = {
73 .bus_id = {0}, /* set to "chan" at xpc_init() time */
74 .driver = &xpc_dbg_name
75};
76
77struct device *xpc_part = &xpc_part_dbg_subname;
78struct device *xpc_chan = &xpc_chan_dbg_subname;
79
Dean Nelson1f4674b2006-01-10 11:08:00 -060080static int xpc_kdebug_ignore;
81
Dean Nelson89eb8eb2005-03-23 19:50:00 -070082/* systune related variables for /proc/sys directories */
83
Dean Nelsona607c382005-09-01 14:01:37 -050084static int xpc_hb_interval = XPC_HB_DEFAULT_INTERVAL;
85static int xpc_hb_min_interval = 1;
86static int xpc_hb_max_interval = 10;
Dean Nelson89eb8eb2005-03-23 19:50:00 -070087
Dean Nelsona607c382005-09-01 14:01:37 -050088static int xpc_hb_check_interval = XPC_HB_CHECK_DEFAULT_INTERVAL;
89static int xpc_hb_check_min_interval = 10;
90static int xpc_hb_check_max_interval = 120;
Dean Nelson89eb8eb2005-03-23 19:50:00 -070091
Dean Nelsone54af722005-10-25 14:07:43 -050092int xpc_disengage_request_timelimit = XPC_DISENGAGE_REQUEST_DEFAULT_TIMELIMIT;
Dean Nelson2c2b94f2008-04-22 14:50:17 -050093static int xpc_disengage_request_min_timelimit; /* = 0 */
Dean Nelsone54af722005-10-25 14:07:43 -050094static int xpc_disengage_request_max_timelimit = 120;
Dean Nelson89eb8eb2005-03-23 19:50:00 -070095
96static ctl_table xpc_sys_xpc_hb_dir[] = {
97 {
Dean Nelson35190502008-04-22 14:48:55 -050098 .ctl_name = CTL_UNNUMBERED,
99 .procname = "hb_interval",
100 .data = &xpc_hb_interval,
101 .maxlen = sizeof(int),
102 .mode = 0644,
103 .proc_handler = &proc_dointvec_minmax,
104 .strategy = &sysctl_intvec,
105 .extra1 = &xpc_hb_min_interval,
106 .extra2 = &xpc_hb_max_interval},
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700107 {
Dean Nelson35190502008-04-22 14:48:55 -0500108 .ctl_name = CTL_UNNUMBERED,
109 .procname = "hb_check_interval",
110 .data = &xpc_hb_check_interval,
111 .maxlen = sizeof(int),
112 .mode = 0644,
113 .proc_handler = &proc_dointvec_minmax,
114 .strategy = &sysctl_intvec,
115 .extra1 = &xpc_hb_check_min_interval,
116 .extra2 = &xpc_hb_check_max_interval},
Eric W. Biederman68cbf072007-02-14 00:33:41 -0800117 {}
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700118};
119static ctl_table xpc_sys_xpc_dir[] = {
120 {
Dean Nelson35190502008-04-22 14:48:55 -0500121 .ctl_name = CTL_UNNUMBERED,
122 .procname = "hb",
123 .mode = 0555,
124 .child = xpc_sys_xpc_hb_dir},
Dean Nelsone54af722005-10-25 14:07:43 -0500125 {
Dean Nelson35190502008-04-22 14:48:55 -0500126 .ctl_name = CTL_UNNUMBERED,
127 .procname = "disengage_request_timelimit",
128 .data = &xpc_disengage_request_timelimit,
129 .maxlen = sizeof(int),
130 .mode = 0644,
131 .proc_handler = &proc_dointvec_minmax,
132 .strategy = &sysctl_intvec,
133 .extra1 = &xpc_disengage_request_min_timelimit,
134 .extra2 = &xpc_disengage_request_max_timelimit},
Eric W. Biederman68cbf072007-02-14 00:33:41 -0800135 {}
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700136};
137static ctl_table xpc_sys_dir[] = {
138 {
Dean Nelson35190502008-04-22 14:48:55 -0500139 .ctl_name = CTL_UNNUMBERED,
140 .procname = "xpc",
141 .mode = 0555,
142 .child = xpc_sys_xpc_dir},
Eric W. Biederman68cbf072007-02-14 00:33:41 -0800143 {}
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700144};
145static struct ctl_table_header *xpc_sysctl;
146
Dean Nelson1ecaded2006-01-06 09:48:21 -0600147/* non-zero if any remote partition disengage request was timed out */
148int xpc_disengage_request_timedout;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700149
150/* #of IRQs received */
151static atomic_t xpc_act_IRQ_rcvd;
152
153/* IRQ handler notifies this wait queue on receipt of an IRQ */
154static DECLARE_WAIT_QUEUE_HEAD(xpc_act_IRQ_wq);
155
156static unsigned long xpc_hb_check_timeout;
157
Dean Nelsone54af722005-10-25 14:07:43 -0500158/* notification that the xpc_hb_checker thread has exited */
Jes Sorensenf9e505a2006-01-17 12:52:21 -0500159static DECLARE_COMPLETION(xpc_hb_checker_exited);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700160
Dean Nelsone54af722005-10-25 14:07:43 -0500161/* notification that the xpc_discovery thread has exited */
Jes Sorensenf9e505a2006-01-17 12:52:21 -0500162static DECLARE_COMPLETION(xpc_discovery_exited);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700163
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700164static struct timer_list xpc_hb_timer;
165
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700166static void xpc_kthread_waitmsgs(struct xpc_partition *, struct xpc_channel *);
167
Dean Nelsona607c382005-09-01 14:01:37 -0500168static int xpc_system_reboot(struct notifier_block *, unsigned long, void *);
169static struct notifier_block xpc_reboot_notifier = {
170 .notifier_call = xpc_system_reboot,
171};
172
Dean Nelson780d09e2005-11-09 14:41:57 -0600173static int xpc_system_die(struct notifier_block *, unsigned long, void *);
174static struct notifier_block xpc_die_notifier = {
175 .notifier_call = xpc_system_die,
176};
177
Dean Nelsona607c382005-09-01 14:01:37 -0500178/*
179 * Timer function to enforce the timelimit on the partition disengage request.
180 */
181static void
182xpc_timeout_partition_disengage_request(unsigned long data)
183{
Dean Nelson35190502008-04-22 14:48:55 -0500184 struct xpc_partition *part = (struct xpc_partition *)data;
Dean Nelsona607c382005-09-01 14:01:37 -0500185
Robert P. J. Dayd167cb82008-03-29 10:05:30 -0400186 DBUG_ON(time_before(jiffies, part->disengage_request_timeout));
Dean Nelsona607c382005-09-01 14:01:37 -0500187
Dean Nelson35190502008-04-22 14:48:55 -0500188 (void)xpc_partition_disengaged(part);
Dean Nelsona607c382005-09-01 14:01:37 -0500189
190 DBUG_ON(part->disengage_request_timeout != 0);
191 DBUG_ON(xpc_partition_engaged(1UL << XPC_PARTID(part)) != 0);
192}
193
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700194/*
195 * Notify the heartbeat check thread that an IRQ has been received.
196 */
197static irqreturn_t
Al Viro5dcded12006-10-08 14:59:19 +0100198xpc_act_IRQ_handler(int irq, void *dev_id)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700199{
200 atomic_inc(&xpc_act_IRQ_rcvd);
201 wake_up_interruptible(&xpc_act_IRQ_wq);
202 return IRQ_HANDLED;
203}
204
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700205/*
206 * Timer to produce the heartbeat. The timer structures function is
207 * already set when this is initially called. A tunable is used to
208 * specify when the next timeout should occur.
209 */
210static void
211xpc_hb_beater(unsigned long dummy)
212{
213 xpc_vars->heartbeat++;
214
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500215 if (time_after_eq(jiffies, xpc_hb_check_timeout))
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700216 wake_up_interruptible(&xpc_act_IRQ_wq);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700217
218 xpc_hb_timer.expires = jiffies + (xpc_hb_interval * HZ);
219 add_timer(&xpc_hb_timer);
220}
221
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700222/*
223 * This thread is responsible for nearly all of the partition
224 * activation/deactivation.
225 */
226static int
227xpc_hb_checker(void *ignore)
228{
229 int last_IRQ_count = 0;
230 int new_IRQ_count;
Dean Nelson35190502008-04-22 14:48:55 -0500231 int force_IRQ = 0;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700232
233 /* this thread was marked active by xpc_hb_init() */
234
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700235 set_cpus_allowed(current, cpumask_of_cpu(XPC_HB_CHECK_CPU));
236
Dean Nelson4c013f52007-11-07 07:53:06 -0600237 /* set our heartbeating to other partitions into motion */
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700238 xpc_hb_check_timeout = jiffies + (xpc_hb_check_interval * HZ);
Dean Nelson4c013f52007-11-07 07:53:06 -0600239 xpc_hb_beater(0);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700240
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500241 while (!xpc_exiting) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700242
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700243 dev_dbg(xpc_part, "woke up with %d ticks rem; %d IRQs have "
244 "been received\n",
Dean Nelson35190502008-04-22 14:48:55 -0500245 (int)(xpc_hb_check_timeout - jiffies),
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700246 atomic_read(&xpc_act_IRQ_rcvd) - last_IRQ_count);
247
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700248 /* checking of remote heartbeats is skewed by IRQ handling */
Robert P. J. Dayd167cb82008-03-29 10:05:30 -0400249 if (time_after_eq(jiffies, xpc_hb_check_timeout)) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700250 dev_dbg(xpc_part, "checking remote heartbeats\n");
251 xpc_check_remote_hb();
252
253 /*
254 * We need to periodically recheck to ensure no
255 * IPI/AMO pairs have been missed. That check
256 * must always reset xpc_hb_check_timeout.
257 */
258 force_IRQ = 1;
259 }
260
Dean Nelsona607c382005-09-01 14:01:37 -0500261 /* check for outstanding IRQs */
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700262 new_IRQ_count = atomic_read(&xpc_act_IRQ_rcvd);
263 if (last_IRQ_count < new_IRQ_count || force_IRQ != 0) {
264 force_IRQ = 0;
265
266 dev_dbg(xpc_part, "found an IRQ to process; will be "
267 "resetting xpc_hb_check_timeout\n");
268
269 last_IRQ_count += xpc_identify_act_IRQ_sender();
270 if (last_IRQ_count < new_IRQ_count) {
271 /* retry once to help avoid missing AMO */
Dean Nelson35190502008-04-22 14:48:55 -0500272 (void)xpc_identify_act_IRQ_sender();
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700273 }
274 last_IRQ_count = new_IRQ_count;
275
276 xpc_hb_check_timeout = jiffies +
Dean Nelson35190502008-04-22 14:48:55 -0500277 (xpc_hb_check_interval * HZ);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700278 }
Dean Nelsona607c382005-09-01 14:01:37 -0500279
280 /* wait for IRQ or timeout */
Dean Nelson35190502008-04-22 14:48:55 -0500281 (void)wait_event_interruptible(xpc_act_IRQ_wq,
282 (last_IRQ_count <
283 atomic_read(&xpc_act_IRQ_rcvd)
284 || time_after_eq(jiffies,
285 xpc_hb_check_timeout) ||
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500286 xpc_exiting));
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700287 }
288
289 dev_dbg(xpc_part, "heartbeat checker is exiting\n");
290
Dean Nelsone54af722005-10-25 14:07:43 -0500291 /* mark this thread as having exited */
Jes Sorensenf9e505a2006-01-17 12:52:21 -0500292 complete(&xpc_hb_checker_exited);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700293 return 0;
294}
295
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700296/*
297 * This thread will attempt to discover other partitions to activate
298 * based on info provided by SAL. This new thread is short lived and
299 * will exit once discovery is complete.
300 */
301static int
302xpc_initiate_discovery(void *ignore)
303{
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700304 xpc_discovery();
305
306 dev_dbg(xpc_part, "discovery thread is exiting\n");
307
Dean Nelsone54af722005-10-25 14:07:43 -0500308 /* mark this thread as having exited */
Jes Sorensenf9e505a2006-01-17 12:52:21 -0500309 complete(&xpc_discovery_exited);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700310 return 0;
311}
312
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700313/*
314 * Establish first contact with the remote partititon. This involves pulling
315 * the XPC per partition variables from the remote partition and waiting for
316 * the remote partition to pull ours.
317 */
318static enum xpc_retval
319xpc_make_first_contact(struct xpc_partition *part)
320{
321 enum xpc_retval ret;
322
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700323 while ((ret = xpc_pull_remote_vars_part(part)) != xpcSuccess) {
324 if (ret != xpcRetry) {
325 XPC_DEACTIVATE_PARTITION(part, ret);
326 return ret;
327 }
328
329 dev_dbg(xpc_chan, "waiting to make first contact with "
330 "partition %d\n", XPC_PARTID(part));
331
332 /* wait a 1/4 of a second or so */
Dean Nelson35190502008-04-22 14:48:55 -0500333 (void)msleep_interruptible(250);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700334
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500335 if (part->act_state == XPC_P_DEACTIVATING)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700336 return part->reason;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700337 }
338
339 return xpc_mark_partition_active(part);
340}
341
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700342/*
343 * The first kthread assigned to a newly activated partition is the one
344 * created by XPC HB with which it calls xpc_partition_up(). XPC hangs on to
345 * that kthread until the partition is brought down, at which time that kthread
346 * returns back to XPC HB. (The return of that kthread will signify to XPC HB
347 * that XPC has dismantled all communication infrastructure for the associated
348 * partition.) This kthread becomes the channel manager for that partition.
349 *
350 * Each active partition has a channel manager, who, besides connecting and
351 * disconnecting channels, will ensure that each of the partition's connected
352 * channels has the required number of assigned kthreads to get the work done.
353 */
354static void
355xpc_channel_mgr(struct xpc_partition *part)
356{
357 while (part->act_state != XPC_P_DEACTIVATING ||
Dean Nelson35190502008-04-22 14:48:55 -0500358 atomic_read(&part->nchannels_active) > 0 ||
359 !xpc_partition_disengaged(part)) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700360
361 xpc_process_channel_activity(part);
362
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700363 /*
364 * Wait until we've been requested to activate kthreads or
365 * all of the channel's message queues have been torn down or
366 * a signal is pending.
367 *
368 * The channel_mgr_requests is set to 1 after being awakened,
369 * This is done to prevent the channel mgr from making one pass
370 * through the loop for each request, since he will
371 * be servicing all the requests in one pass. The reason it's
372 * set to 1 instead of 0 is so that other kthreads will know
373 * that the channel mgr is running and won't bother trying to
374 * wake him up.
375 */
376 atomic_dec(&part->channel_mgr_requests);
Dean Nelson35190502008-04-22 14:48:55 -0500377 (void)wait_event_interruptible(part->channel_mgr_wq,
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500378 (atomic_read(&part->channel_mgr_requests) > 0 ||
379 part->local_IPI_amo != 0 ||
380 (part->act_state == XPC_P_DEACTIVATING &&
381 atomic_read(&part->nchannels_active) == 0 &&
382 xpc_partition_disengaged(part))));
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700383 atomic_set(&part->channel_mgr_requests, 1);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700384 }
385}
386
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700387/*
388 * When XPC HB determines that a partition has come up, it will create a new
389 * kthread and that kthread will call this function to attempt to set up the
390 * basic infrastructure used for Cross Partition Communication with the newly
391 * upped partition.
392 *
393 * The kthread that was created by XPC HB and which setup the XPC
394 * infrastructure will remain assigned to the partition until the partition
395 * goes down. At which time the kthread will teardown the XPC infrastructure
396 * and then exit.
397 *
398 * XPC HB will put the remote partition's XPC per partition specific variables
399 * physical address into xpc_partitions[partid].remote_vars_part_pa prior to
400 * calling xpc_partition_up().
401 */
402static void
403xpc_partition_up(struct xpc_partition *part)
404{
405 DBUG_ON(part->channels != NULL);
406
407 dev_dbg(xpc_chan, "activating partition %d\n", XPC_PARTID(part));
408
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500409 if (xpc_setup_infrastructure(part) != xpcSuccess)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700410 return;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700411
412 /*
413 * The kthread that XPC HB called us with will become the
414 * channel manager for this partition. It will not return
415 * back to XPC HB until the partition's XPC infrastructure
416 * has been dismantled.
417 */
418
Dean Nelson35190502008-04-22 14:48:55 -0500419 (void)xpc_part_ref(part); /* this will always succeed */
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700420
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500421 if (xpc_make_first_contact(part) == xpcSuccess)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700422 xpc_channel_mgr(part);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700423
424 xpc_part_deref(part);
425
426 xpc_teardown_infrastructure(part);
427}
428
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700429static int
430xpc_activating(void *__partid)
431{
Dean Nelson35190502008-04-22 14:48:55 -0500432 partid_t partid = (u64)__partid;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700433 struct xpc_partition *part = &xpc_partitions[partid];
434 unsigned long irq_flags;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700435
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700436 DBUG_ON(partid <= 0 || partid >= XP_MAX_PARTITIONS);
437
438 spin_lock_irqsave(&part->act_lock, irq_flags);
439
440 if (part->act_state == XPC_P_DEACTIVATING) {
441 part->act_state = XPC_P_INACTIVE;
442 spin_unlock_irqrestore(&part->act_lock, irq_flags);
443 part->remote_rp_pa = 0;
444 return 0;
445 }
446
447 /* indicate the thread is activating */
448 DBUG_ON(part->act_state != XPC_P_ACTIVATION_REQ);
449 part->act_state = XPC_P_ACTIVATING;
450
451 XPC_SET_REASON(part, 0, 0);
452 spin_unlock_irqrestore(&part->act_lock, irq_flags);
453
454 dev_dbg(xpc_part, "bringing partition %d up\n", partid);
455
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700456 /*
457 * Register the remote partition's AMOs with SAL so it can handle
458 * and cleanup errors within that address range should the remote
459 * partition go down. We don't unregister this range because it is
460 * difficult to tell when outstanding writes to the remote partition
461 * are finished and thus when it is safe to unregister. This should
462 * not result in wasted space in the SAL xp_addr_region table because
463 * we should get the same page for remote_amos_page_pa after module
464 * reloads and system reboots.
465 */
466 if (sn_register_xp_addr_region(part->remote_amos_page_pa,
Dean Nelson35190502008-04-22 14:48:55 -0500467 PAGE_SIZE, 1) < 0) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700468 dev_warn(xpc_part, "xpc_partition_up(%d) failed to register "
Dean Nelson35190502008-04-22 14:48:55 -0500469 "xp_addr region\n", partid);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700470
471 spin_lock_irqsave(&part->act_lock, irq_flags);
472 part->act_state = XPC_P_INACTIVE;
473 XPC_SET_REASON(part, xpcPhysAddrRegFailed, __LINE__);
474 spin_unlock_irqrestore(&part->act_lock, irq_flags);
475 part->remote_rp_pa = 0;
476 return 0;
477 }
478
Dean Nelsona607c382005-09-01 14:01:37 -0500479 xpc_allow_hb(partid, xpc_vars);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700480 xpc_IPI_send_activated(part);
481
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700482 /*
483 * xpc_partition_up() holds this thread and marks this partition as
484 * XPC_P_ACTIVE by calling xpc_hb_mark_active().
485 */
Dean Nelson35190502008-04-22 14:48:55 -0500486 (void)xpc_partition_up(part);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700487
Dean Nelsona607c382005-09-01 14:01:37 -0500488 xpc_disallow_hb(partid, xpc_vars);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700489 xpc_mark_partition_inactive(part);
490
491 if (part->reason == xpcReactivating) {
492 /* interrupting ourselves results in activating partition */
493 xpc_IPI_send_reactivate(part);
494 }
495
496 return 0;
497}
498
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700499void
500xpc_activate_partition(struct xpc_partition *part)
501{
502 partid_t partid = XPC_PARTID(part);
503 unsigned long irq_flags;
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500504 struct task_struct *kthread;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700505
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700506 spin_lock_irqsave(&part->act_lock, irq_flags);
507
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700508 DBUG_ON(part->act_state != XPC_P_INACTIVE);
509
Robin Holt7c6c6632006-02-02 12:30:21 -0600510 part->act_state = XPC_P_ACTIVATION_REQ;
511 XPC_SET_REASON(part, xpcCloneKThread, __LINE__);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700512
513 spin_unlock_irqrestore(&part->act_lock, irq_flags);
Robin Holt7c6c6632006-02-02 12:30:21 -0600514
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500515 kthread = kthread_run(xpc_activating, (void *)((u64)partid), "xpc%02d",
516 partid);
517 if (IS_ERR(kthread)) {
Robin Holt7c6c6632006-02-02 12:30:21 -0600518 spin_lock_irqsave(&part->act_lock, irq_flags);
519 part->act_state = XPC_P_INACTIVE;
520 XPC_SET_REASON(part, xpcCloneKThreadFailed, __LINE__);
521 spin_unlock_irqrestore(&part->act_lock, irq_flags);
522 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700523}
524
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700525/*
526 * Handle the receipt of a SGI_XPC_NOTIFY IRQ by seeing whether the specified
527 * partition actually sent it. Since SGI_XPC_NOTIFY IRQs may be shared by more
528 * than one partition, we use an AMO_t structure per partition to indicate
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500529 * whether a partition has sent an IPI or not. If it has, then wake up the
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700530 * associated kthread to handle it.
531 *
532 * All SGI_XPC_NOTIFY IRQs received by XPC are the result of IPIs sent by XPC
533 * running on other partitions.
534 *
535 * Noteworthy Arguments:
536 *
537 * irq - Interrupt ReQuest number. NOT USED.
538 *
539 * dev_id - partid of IPI's potential sender.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700540 */
541irqreturn_t
Al Viro5dcded12006-10-08 14:59:19 +0100542xpc_notify_IRQ_handler(int irq, void *dev_id)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700543{
Dean Nelson35190502008-04-22 14:48:55 -0500544 partid_t partid = (partid_t) (u64)dev_id;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700545 struct xpc_partition *part = &xpc_partitions[partid];
546
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700547 DBUG_ON(partid <= 0 || partid >= XP_MAX_PARTITIONS);
548
549 if (xpc_part_ref(part)) {
550 xpc_check_for_channel_activity(part);
551
552 xpc_part_deref(part);
553 }
554 return IRQ_HANDLED;
555}
556
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700557/*
558 * Check to see if xpc_notify_IRQ_handler() dropped any IPIs on the floor
559 * because the write to their associated IPI amo completed after the IRQ/IPI
560 * was received.
561 */
562void
563xpc_dropped_IPI_check(struct xpc_partition *part)
564{
565 if (xpc_part_ref(part)) {
566 xpc_check_for_channel_activity(part);
567
568 part->dropped_IPI_timer.expires = jiffies +
Dean Nelson35190502008-04-22 14:48:55 -0500569 XPC_P_DROPPED_IPI_WAIT;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700570 add_timer(&part->dropped_IPI_timer);
571 xpc_part_deref(part);
572 }
573}
574
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700575void
576xpc_activate_kthreads(struct xpc_channel *ch, int needed)
577{
578 int idle = atomic_read(&ch->kthreads_idle);
579 int assigned = atomic_read(&ch->kthreads_assigned);
580 int wakeup;
581
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700582 DBUG_ON(needed <= 0);
583
584 if (idle > 0) {
585 wakeup = (needed > idle) ? idle : needed;
586 needed -= wakeup;
587
588 dev_dbg(xpc_chan, "wakeup %d idle kthreads, partid=%d, "
589 "channel=%d\n", wakeup, ch->partid, ch->number);
590
591 /* only wakeup the requested number of kthreads */
592 wake_up_nr(&ch->idle_wq, wakeup);
593 }
594
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500595 if (needed <= 0)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700596 return;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700597
598 if (needed + assigned > ch->kthreads_assigned_limit) {
599 needed = ch->kthreads_assigned_limit - assigned;
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500600 if (needed <= 0)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700601 return;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700602 }
603
604 dev_dbg(xpc_chan, "create %d new kthreads, partid=%d, channel=%d\n",
605 needed, ch->partid, ch->number);
606
Dean Nelsona460ef82006-11-22 08:25:00 -0600607 xpc_create_kthreads(ch, needed, 0);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700608}
609
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700610/*
611 * This function is where XPC's kthreads wait for messages to deliver.
612 */
613static void
614xpc_kthread_waitmsgs(struct xpc_partition *part, struct xpc_channel *ch)
615{
616 do {
617 /* deliver messages to their intended recipients */
618
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500619 while (ch->w_local_GP.get < ch->w_remote_GP.put &&
620 !(ch->flags & XPC_C_DISCONNECTING)) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700621 xpc_deliver_msg(ch);
622 }
623
624 if (atomic_inc_return(&ch->kthreads_idle) >
Dean Nelson35190502008-04-22 14:48:55 -0500625 ch->kthreads_idle_limit) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700626 /* too many idle kthreads on this channel */
627 atomic_dec(&ch->kthreads_idle);
628 break;
629 }
630
631 dev_dbg(xpc_chan, "idle kthread calling "
632 "wait_event_interruptible_exclusive()\n");
633
Dean Nelson35190502008-04-22 14:48:55 -0500634 (void)wait_event_interruptible_exclusive(ch->idle_wq,
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500635 (ch->w_local_GP.get < ch->w_remote_GP.put ||
636 (ch->flags & XPC_C_DISCONNECTING)));
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700637
638 atomic_dec(&ch->kthreads_idle);
639
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500640 } while (!(ch->flags & XPC_C_DISCONNECTING));
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700641}
642
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700643static int
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500644xpc_kthread_start(void *args)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700645{
646 partid_t partid = XPC_UNPACK_ARG1(args);
647 u16 ch_number = XPC_UNPACK_ARG2(args);
648 struct xpc_partition *part = &xpc_partitions[partid];
649 struct xpc_channel *ch;
650 int n_needed;
Dean Nelsone54af722005-10-25 14:07:43 -0500651 unsigned long irq_flags;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700652
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700653 dev_dbg(xpc_chan, "kthread starting, partid=%d, channel=%d\n",
654 partid, ch_number);
655
656 ch = &part->channels[ch_number];
657
658 if (!(ch->flags & XPC_C_DISCONNECTING)) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700659
660 /* let registerer know that connection has been established */
661
Dean Nelsone54af722005-10-25 14:07:43 -0500662 spin_lock_irqsave(&ch->lock, irq_flags);
Dean Nelson4c2cd962006-02-15 08:02:21 -0600663 if (!(ch->flags & XPC_C_CONNECTEDCALLOUT)) {
664 ch->flags |= XPC_C_CONNECTEDCALLOUT;
Dean Nelsone54af722005-10-25 14:07:43 -0500665 spin_unlock_irqrestore(&ch->lock, irq_flags);
666
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700667 xpc_connected_callout(ch);
668
Dean Nelson4c2cd962006-02-15 08:02:21 -0600669 spin_lock_irqsave(&ch->lock, irq_flags);
670 ch->flags |= XPC_C_CONNECTEDCALLOUT_MADE;
671 spin_unlock_irqrestore(&ch->lock, irq_flags);
672
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700673 /*
674 * It is possible that while the callout was being
675 * made that the remote partition sent some messages.
676 * If that is the case, we may need to activate
677 * additional kthreads to help deliver them. We only
678 * need one less than total #of messages to deliver.
679 */
680 n_needed = ch->w_remote_GP.put - ch->w_local_GP.get - 1;
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500681 if (n_needed > 0 && !(ch->flags & XPC_C_DISCONNECTING))
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700682 xpc_activate_kthreads(ch, n_needed);
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500683
Dean Nelsone54af722005-10-25 14:07:43 -0500684 } else {
685 spin_unlock_irqrestore(&ch->lock, irq_flags);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700686 }
687
688 xpc_kthread_waitmsgs(part, ch);
689 }
690
Dean Nelsona460ef82006-11-22 08:25:00 -0600691 /* let registerer know that connection is disconnecting */
Dean Nelsone54af722005-10-25 14:07:43 -0500692
Dean Nelsona460ef82006-11-22 08:25:00 -0600693 spin_lock_irqsave(&ch->lock, irq_flags);
694 if ((ch->flags & XPC_C_CONNECTEDCALLOUT_MADE) &&
Dean Nelson35190502008-04-22 14:48:55 -0500695 !(ch->flags & XPC_C_DISCONNECTINGCALLOUT)) {
Dean Nelsona460ef82006-11-22 08:25:00 -0600696 ch->flags |= XPC_C_DISCONNECTINGCALLOUT;
Dean Nelson4c2cd962006-02-15 08:02:21 -0600697 spin_unlock_irqrestore(&ch->lock, irq_flags);
Dean Nelsona460ef82006-11-22 08:25:00 -0600698
699 xpc_disconnect_callout(ch, xpcDisconnecting);
700
701 spin_lock_irqsave(&ch->lock, irq_flags);
702 ch->flags |= XPC_C_DISCONNECTINGCALLOUT_MADE;
703 }
704 spin_unlock_irqrestore(&ch->lock, irq_flags);
705
706 if (atomic_dec_return(&ch->kthreads_assigned) == 0) {
Dean Nelsona607c382005-09-01 14:01:37 -0500707 if (atomic_dec_return(&part->nchannels_engaged) == 0) {
708 xpc_mark_partition_disengaged(part);
709 xpc_IPI_send_disengage(part);
710 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700711 }
712
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700713 xpc_msgqueue_deref(ch);
714
715 dev_dbg(xpc_chan, "kthread exiting, partid=%d, channel=%d\n",
716 partid, ch_number);
717
718 xpc_part_deref(part);
719 return 0;
720}
721
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700722/*
723 * For each partition that XPC has established communications with, there is
724 * a minimum of one kernel thread assigned to perform any operation that
725 * may potentially sleep or block (basically the callouts to the asynchronous
726 * functions registered via xpc_connect()).
727 *
728 * Additional kthreads are created and destroyed by XPC as the workload
729 * demands.
730 *
731 * A kthread is assigned to one of the active channels that exists for a given
732 * partition.
733 */
734void
Dean Nelsona460ef82006-11-22 08:25:00 -0600735xpc_create_kthreads(struct xpc_channel *ch, int needed,
Dean Nelson35190502008-04-22 14:48:55 -0500736 int ignore_disconnecting)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700737{
738 unsigned long irq_flags;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700739 u64 args = XPC_PACK_ARGS(ch->partid, ch->number);
Dean Nelsona607c382005-09-01 14:01:37 -0500740 struct xpc_partition *part = &xpc_partitions[ch->partid];
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500741 struct task_struct *kthread;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700742
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700743 while (needed-- > 0) {
Dean Nelsone54af722005-10-25 14:07:43 -0500744
745 /*
746 * The following is done on behalf of the newly created
747 * kthread. That kthread is responsible for doing the
748 * counterpart to the following before it exits.
749 */
Dean Nelsona460ef82006-11-22 08:25:00 -0600750 if (ignore_disconnecting) {
751 if (!atomic_inc_not_zero(&ch->kthreads_assigned)) {
752 /* kthreads assigned had gone to zero */
753 BUG_ON(!(ch->flags &
Dean Nelson35190502008-04-22 14:48:55 -0500754 XPC_C_DISCONNECTINGCALLOUT_MADE));
Dean Nelsona460ef82006-11-22 08:25:00 -0600755 break;
756 }
757
758 } else if (ch->flags & XPC_C_DISCONNECTING) {
759 break;
760
761 } else if (atomic_inc_return(&ch->kthreads_assigned) == 1) {
762 if (atomic_inc_return(&part->nchannels_engaged) == 1)
763 xpc_mark_partition_engaged(part);
764 }
Dean Nelson35190502008-04-22 14:48:55 -0500765 (void)xpc_part_ref(part);
Dean Nelsone54af722005-10-25 14:07:43 -0500766 xpc_msgqueue_ref(ch);
Dean Nelsone54af722005-10-25 14:07:43 -0500767
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500768 kthread = kthread_run(xpc_kthread_start, (void *)args,
769 "xpc%02dc%d", ch->partid, ch->number);
770 if (IS_ERR(kthread)) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700771 /* the fork failed */
Dean Nelsona460ef82006-11-22 08:25:00 -0600772
773 /*
774 * NOTE: if (ignore_disconnecting &&
775 * !(ch->flags & XPC_C_DISCONNECTINGCALLOUT)) is true,
776 * then we'll deadlock if all other kthreads assigned
777 * to this channel are blocked in the channel's
778 * registerer, because the only thing that will unblock
779 * them is the xpcDisconnecting callout that this
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500780 * failed kthread_run() would have made.
Dean Nelsona460ef82006-11-22 08:25:00 -0600781 */
782
Dean Nelsone54af722005-10-25 14:07:43 -0500783 if (atomic_dec_return(&ch->kthreads_assigned) == 0 &&
784 atomic_dec_return(&part->nchannels_engaged) == 0) {
785 xpc_mark_partition_disengaged(part);
786 xpc_IPI_send_disengage(part);
787 }
788 xpc_msgqueue_deref(ch);
789 xpc_part_deref(part);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700790
791 if (atomic_read(&ch->kthreads_assigned) <
Dean Nelson35190502008-04-22 14:48:55 -0500792 ch->kthreads_idle_limit) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700793 /*
794 * Flag this as an error only if we have an
795 * insufficient #of kthreads for the channel
796 * to function.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700797 */
798 spin_lock_irqsave(&ch->lock, irq_flags);
799 XPC_DISCONNECT_CHANNEL(ch, xpcLackOfResources,
Dean Nelson35190502008-04-22 14:48:55 -0500800 &irq_flags);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700801 spin_unlock_irqrestore(&ch->lock, irq_flags);
802 }
803 break;
804 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700805 }
806}
807
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700808void
809xpc_disconnect_wait(int ch_number)
810{
Dean Nelsona607c382005-09-01 14:01:37 -0500811 unsigned long irq_flags;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700812 partid_t partid;
813 struct xpc_partition *part;
814 struct xpc_channel *ch;
Dean Nelsone54af722005-10-25 14:07:43 -0500815 int wakeup_channel_mgr;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700816
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700817 /* now wait for all callouts to the caller's function to cease */
818 for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) {
819 part = &xpc_partitions[partid];
820
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500821 if (!xpc_part_ref(part))
Dean Nelsone54af722005-10-25 14:07:43 -0500822 continue;
Dean Nelsone54af722005-10-25 14:07:43 -0500823
824 ch = &part->channels[ch_number];
825
826 if (!(ch->flags & XPC_C_WDISCONNECT)) {
827 xpc_part_deref(part);
828 continue;
829 }
830
Jes Sorensenf9e505a2006-01-17 12:52:21 -0500831 wait_for_completion(&ch->wdisconnect_wait);
Dean Nelsone54af722005-10-25 14:07:43 -0500832
833 spin_lock_irqsave(&ch->lock, irq_flags);
834 DBUG_ON(!(ch->flags & XPC_C_DISCONNECTED));
835 wakeup_channel_mgr = 0;
836
837 if (ch->delayed_IPI_flags) {
838 if (part->act_state != XPC_P_DEACTIVATING) {
839 spin_lock(&part->IPI_lock);
840 XPC_SET_IPI_FLAGS(part->local_IPI_amo,
Dean Nelson35190502008-04-22 14:48:55 -0500841 ch->number,
842 ch->delayed_IPI_flags);
Dean Nelsone54af722005-10-25 14:07:43 -0500843 spin_unlock(&part->IPI_lock);
844 wakeup_channel_mgr = 1;
845 }
846 ch->delayed_IPI_flags = 0;
847 }
848
849 ch->flags &= ~XPC_C_WDISCONNECT;
850 spin_unlock_irqrestore(&ch->lock, irq_flags);
851
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500852 if (wakeup_channel_mgr)
Dean Nelsone54af722005-10-25 14:07:43 -0500853 xpc_wakeup_channel_mgr(part);
Dean Nelsone54af722005-10-25 14:07:43 -0500854
855 xpc_part_deref(part);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700856 }
857}
858
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700859static void
Dean Nelsona607c382005-09-01 14:01:37 -0500860xpc_do_exit(enum xpc_retval reason)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700861{
862 partid_t partid;
Dean Nelson1ecaded2006-01-06 09:48:21 -0600863 int active_part_count, printed_waiting_msg = 0;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700864 struct xpc_partition *part;
Dean Nelson1ecaded2006-01-06 09:48:21 -0600865 unsigned long printmsg_time, disengage_request_timeout = 0;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700866
Dean Nelsona607c382005-09-01 14:01:37 -0500867 /* a 'rmmod XPC' and a 'reboot' cannot both end up here together */
868 DBUG_ON(xpc_exiting == 1);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700869
870 /*
Dean Nelsona607c382005-09-01 14:01:37 -0500871 * Let the heartbeat checker thread and the discovery thread
872 * (if one is running) know that they should exit. Also wake up
873 * the heartbeat checker thread in case it's sleeping.
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700874 */
875 xpc_exiting = 1;
876 wake_up_interruptible(&xpc_act_IRQ_wq);
877
Dean Nelsona607c382005-09-01 14:01:37 -0500878 /* ignore all incoming interrupts */
879 free_irq(SGI_XPC_ACTIVATE, NULL);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700880
Dean Nelsone54af722005-10-25 14:07:43 -0500881 /* wait for the discovery thread to exit */
Jes Sorensenf9e505a2006-01-17 12:52:21 -0500882 wait_for_completion(&xpc_discovery_exited);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700883
Dean Nelsone54af722005-10-25 14:07:43 -0500884 /* wait for the heartbeat checker thread to exit */
Jes Sorensenf9e505a2006-01-17 12:52:21 -0500885 wait_for_completion(&xpc_hb_checker_exited);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700886
Dean Nelsona607c382005-09-01 14:01:37 -0500887 /* sleep for a 1/3 of a second or so */
Dean Nelson35190502008-04-22 14:48:55 -0500888 (void)msleep_interruptible(300);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700889
890 /* wait for all partitions to become inactive */
891
Dean Nelson1ecaded2006-01-06 09:48:21 -0600892 printmsg_time = jiffies + (XPC_DISENGAGE_PRINTMSG_INTERVAL * HZ);
893 xpc_disengage_request_timedout = 0;
Dean Nelsona607c382005-09-01 14:01:37 -0500894
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700895 do {
896 active_part_count = 0;
897
898 for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) {
899 part = &xpc_partitions[partid];
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700900
Dean Nelsona607c382005-09-01 14:01:37 -0500901 if (xpc_partition_disengaged(part) &&
Dean Nelson35190502008-04-22 14:48:55 -0500902 part->act_state == XPC_P_INACTIVE) {
Dean Nelsona607c382005-09-01 14:01:37 -0500903 continue;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700904 }
Dean Nelsona607c382005-09-01 14:01:37 -0500905
906 active_part_count++;
907
908 XPC_DEACTIVATE_PARTITION(part, reason);
Dean Nelson1ecaded2006-01-06 09:48:21 -0600909
910 if (part->disengage_request_timeout >
Dean Nelson35190502008-04-22 14:48:55 -0500911 disengage_request_timeout) {
Dean Nelson1ecaded2006-01-06 09:48:21 -0600912 disengage_request_timeout =
Dean Nelson35190502008-04-22 14:48:55 -0500913 part->disengage_request_timeout;
Dean Nelson1ecaded2006-01-06 09:48:21 -0600914 }
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700915 }
916
Dean Nelson1ecaded2006-01-06 09:48:21 -0600917 if (xpc_partition_engaged(-1UL)) {
918 if (time_after(jiffies, printmsg_time)) {
919 dev_info(xpc_part, "waiting for remote "
Dean Nelson35190502008-04-22 14:48:55 -0500920 "partitions to disengage, timeout in "
921 "%ld seconds\n",
922 (disengage_request_timeout - jiffies)
923 / HZ);
Dean Nelson1ecaded2006-01-06 09:48:21 -0600924 printmsg_time = jiffies +
Dean Nelson35190502008-04-22 14:48:55 -0500925 (XPC_DISENGAGE_PRINTMSG_INTERVAL * HZ);
Dean Nelson1ecaded2006-01-06 09:48:21 -0600926 printed_waiting_msg = 1;
927 }
928
929 } else if (active_part_count > 0) {
930 if (printed_waiting_msg) {
931 dev_info(xpc_part, "waiting for local partition"
Dean Nelson35190502008-04-22 14:48:55 -0500932 " to disengage\n");
Dean Nelson1ecaded2006-01-06 09:48:21 -0600933 printed_waiting_msg = 0;
934 }
935
936 } else {
937 if (!xpc_disengage_request_timedout) {
938 dev_info(xpc_part, "all partitions have "
Dean Nelson35190502008-04-22 14:48:55 -0500939 "disengaged\n");
Dean Nelson1ecaded2006-01-06 09:48:21 -0600940 }
941 break;
Dean Nelsona607c382005-09-01 14:01:37 -0500942 }
943
944 /* sleep for a 1/3 of a second or so */
Dean Nelson35190502008-04-22 14:48:55 -0500945 (void)msleep_interruptible(300);
Dean Nelsona607c382005-09-01 14:01:37 -0500946
947 } while (1);
948
949 DBUG_ON(xpc_partition_engaged(-1UL));
950
Dean Nelsona607c382005-09-01 14:01:37 -0500951 /* indicate to others that our reserved page is uninitialized */
952 xpc_rsvd_page->vars_pa = 0;
953
954 /* now it's time to eliminate our heartbeat */
955 del_timer_sync(&xpc_hb_timer);
Dean Nelsone54af722005-10-25 14:07:43 -0500956 DBUG_ON(xpc_vars->heartbeating_to_mask != 0);
Dean Nelsona607c382005-09-01 14:01:37 -0500957
Dean Nelson0752c672006-01-10 11:07:19 -0600958 if (reason == xpcUnloading) {
959 /* take ourselves off of the reboot_notifier_list */
Dean Nelson35190502008-04-22 14:48:55 -0500960 (void)unregister_reboot_notifier(&xpc_reboot_notifier);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700961
Dean Nelson0752c672006-01-10 11:07:19 -0600962 /* take ourselves off of the die_notifier list */
Dean Nelson35190502008-04-22 14:48:55 -0500963 (void)unregister_die_notifier(&xpc_die_notifier);
Dean Nelson0752c672006-01-10 11:07:19 -0600964 }
Dean Nelson780d09e2005-11-09 14:41:57 -0600965
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700966 /* close down protections for IPI operations */
967 xpc_restrict_IPI_ops();
968
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700969 /* clear the interface to XPC's functions */
970 xpc_clear_interface();
971
Dean Nelson2c2b94f2008-04-22 14:50:17 -0500972 if (xpc_sysctl)
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700973 unregister_sysctl_table(xpc_sysctl);
Dean Nelson7682a4c2006-08-08 15:03:29 -0500974
975 kfree(xpc_remote_copy_buffer_base);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700976}
977
Dean Nelsona607c382005-09-01 14:01:37 -0500978/*
Dean Nelsond6ad0332006-01-10 11:08:55 -0600979 * This function is called when the system is being rebooted.
980 */
981static int
982xpc_system_reboot(struct notifier_block *nb, unsigned long event, void *unused)
983{
984 enum xpc_retval reason;
985
Dean Nelsond6ad0332006-01-10 11:08:55 -0600986 switch (event) {
987 case SYS_RESTART:
988 reason = xpcSystemReboot;
989 break;
990 case SYS_HALT:
991 reason = xpcSystemHalt;
992 break;
993 case SYS_POWER_OFF:
994 reason = xpcSystemPoweroff;
995 break;
996 default:
997 reason = xpcSystemGoingDown;
998 }
999
1000 xpc_do_exit(reason);
1001 return NOTIFY_DONE;
1002}
1003
Dean Nelsond6ad0332006-01-10 11:08:55 -06001004/*
1005 * Notify other partitions to disengage from all references to our memory.
Dean Nelson780d09e2005-11-09 14:41:57 -06001006 */
1007static void
1008xpc_die_disengage(void)
1009{
1010 struct xpc_partition *part;
1011 partid_t partid;
1012 unsigned long engaged;
Dean Nelson1ecaded2006-01-06 09:48:21 -06001013 long time, printmsg_time, disengage_request_timeout;
Dean Nelson780d09e2005-11-09 14:41:57 -06001014
Dean Nelson780d09e2005-11-09 14:41:57 -06001015 /* keep xpc_hb_checker thread from doing anything (just in case) */
1016 xpc_exiting = 1;
1017
Dean Nelson35190502008-04-22 14:48:55 -05001018 xpc_vars->heartbeating_to_mask = 0; /* indicate we're deactivated */
Dean Nelson780d09e2005-11-09 14:41:57 -06001019
1020 for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) {
1021 part = &xpc_partitions[partid];
1022
Dean Nelson2c2b94f2008-04-22 14:50:17 -05001023 if (!XPC_SUPPORTS_DISENGAGE_REQUEST(part->
1024 remote_vars_version)) {
Dean Nelson780d09e2005-11-09 14:41:57 -06001025
1026 /* just in case it was left set by an earlier XPC */
1027 xpc_clear_partition_engaged(1UL << partid);
1028 continue;
1029 }
1030
1031 if (xpc_partition_engaged(1UL << partid) ||
Dean Nelson35190502008-04-22 14:48:55 -05001032 part->act_state != XPC_P_INACTIVE) {
Dean Nelson780d09e2005-11-09 14:41:57 -06001033 xpc_request_partition_disengage(part);
1034 xpc_mark_partition_disengaged(part);
1035 xpc_IPI_send_disengage(part);
1036 }
1037 }
1038
Dean Nelson1ecaded2006-01-06 09:48:21 -06001039 time = rtc_time();
1040 printmsg_time = time +
Dean Nelson35190502008-04-22 14:48:55 -05001041 (XPC_DISENGAGE_PRINTMSG_INTERVAL * sn_rtc_cycles_per_second);
Dean Nelson1ecaded2006-01-06 09:48:21 -06001042 disengage_request_timeout = time +
Dean Nelson35190502008-04-22 14:48:55 -05001043 (xpc_disengage_request_timelimit * sn_rtc_cycles_per_second);
Dean Nelson780d09e2005-11-09 14:41:57 -06001044
1045 /* wait for all other partitions to disengage from us */
1046
Dean Nelson1ecaded2006-01-06 09:48:21 -06001047 while (1) {
1048 engaged = xpc_partition_engaged(-1UL);
1049 if (!engaged) {
1050 dev_info(xpc_part, "all partitions have disengaged\n");
1051 break;
1052 }
Dean Nelson780d09e2005-11-09 14:41:57 -06001053
Dean Nelson1ecaded2006-01-06 09:48:21 -06001054 time = rtc_time();
1055 if (time >= disengage_request_timeout) {
1056 for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) {
1057 if (engaged & (1UL << partid)) {
1058 dev_info(xpc_part, "disengage from "
Dean Nelson35190502008-04-22 14:48:55 -05001059 "remote partition %d timed "
1060 "out\n", partid);
Dean Nelson1ecaded2006-01-06 09:48:21 -06001061 }
1062 }
1063 break;
1064 }
1065
1066 if (time >= printmsg_time) {
Dean Nelson780d09e2005-11-09 14:41:57 -06001067 dev_info(xpc_part, "waiting for remote partitions to "
Dean Nelson35190502008-04-22 14:48:55 -05001068 "disengage, timeout in %ld seconds\n",
1069 (disengage_request_timeout - time) /
1070 sn_rtc_cycles_per_second);
Dean Nelson1ecaded2006-01-06 09:48:21 -06001071 printmsg_time = time +
Dean Nelson35190502008-04-22 14:48:55 -05001072 (XPC_DISENGAGE_PRINTMSG_INTERVAL *
1073 sn_rtc_cycles_per_second);
Dean Nelson780d09e2005-11-09 14:41:57 -06001074 }
1075 }
Dean Nelson780d09e2005-11-09 14:41:57 -06001076}
1077
Dean Nelson780d09e2005-11-09 14:41:57 -06001078/*
Dean Nelson1f4674b2006-01-10 11:08:00 -06001079 * This function is called when the system is being restarted or halted due
1080 * to some sort of system failure. If this is the case we need to notify the
1081 * other partitions to disengage from all references to our memory.
1082 * This function can also be called when our heartbeater could be offlined
1083 * for a time. In this case we need to notify other partitions to not worry
1084 * about the lack of a heartbeat.
Dean Nelson780d09e2005-11-09 14:41:57 -06001085 */
1086static int
1087xpc_system_die(struct notifier_block *nb, unsigned long event, void *unused)
1088{
1089 switch (event) {
1090 case DIE_MACHINE_RESTART:
1091 case DIE_MACHINE_HALT:
1092 xpc_die_disengage();
1093 break;
Dean Nelson1f4674b2006-01-10 11:08:00 -06001094
1095 case DIE_KDEBUG_ENTER:
1096 /* Should lack of heartbeat be ignored by other partitions? */
Dean Nelson2c2b94f2008-04-22 14:50:17 -05001097 if (!xpc_kdebug_ignore)
Dean Nelson1f4674b2006-01-10 11:08:00 -06001098 break;
Dean Nelson2c2b94f2008-04-22 14:50:17 -05001099
Dean Nelson1f4674b2006-01-10 11:08:00 -06001100 /* fall through */
Dean Nelson780d09e2005-11-09 14:41:57 -06001101 case DIE_MCA_MONARCH_ENTER:
1102 case DIE_INIT_MONARCH_ENTER:
1103 xpc_vars->heartbeat++;
1104 xpc_vars->heartbeat_offline = 1;
1105 break;
Dean Nelson1f4674b2006-01-10 11:08:00 -06001106
1107 case DIE_KDEBUG_LEAVE:
1108 /* Is lack of heartbeat being ignored by other partitions? */
Dean Nelson2c2b94f2008-04-22 14:50:17 -05001109 if (!xpc_kdebug_ignore)
Dean Nelson1f4674b2006-01-10 11:08:00 -06001110 break;
Dean Nelson2c2b94f2008-04-22 14:50:17 -05001111
Dean Nelson1f4674b2006-01-10 11:08:00 -06001112 /* fall through */
Dean Nelson780d09e2005-11-09 14:41:57 -06001113 case DIE_MCA_MONARCH_LEAVE:
1114 case DIE_INIT_MONARCH_LEAVE:
1115 xpc_vars->heartbeat++;
1116 xpc_vars->heartbeat_offline = 0;
1117 break;
1118 }
1119
1120 return NOTIFY_DONE;
1121}
1122
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001123int __init
1124xpc_init(void)
1125{
1126 int ret;
1127 partid_t partid;
1128 struct xpc_partition *part;
Dean Nelson2c2b94f2008-04-22 14:50:17 -05001129 struct task_struct *kthread;
Dean Nelson7682a4c2006-08-08 15:03:29 -05001130 size_t buf_size;
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001131
Dean Nelson2c2b94f2008-04-22 14:50:17 -05001132 if (!ia64_platform_is("sn2"))
Dean Nelson408865c2005-09-08 10:46:58 -05001133 return -ENODEV;
Dean Nelson408865c2005-09-08 10:46:58 -05001134
Dean Nelson7682a4c2006-08-08 15:03:29 -05001135 buf_size = max(XPC_RP_VARS_SIZE,
Dean Nelson35190502008-04-22 14:48:55 -05001136 XPC_RP_HEADER_SIZE + XP_NASID_MASK_BYTES);
Dean Nelson7682a4c2006-08-08 15:03:29 -05001137 xpc_remote_copy_buffer = xpc_kmalloc_cacheline_aligned(buf_size,
Dean Nelson35190502008-04-22 14:48:55 -05001138 GFP_KERNEL,
Dean Nelson2c2b94f2008-04-22 14:50:17 -05001139 &xpc_remote_copy_buffer_base);
Dean Nelson7682a4c2006-08-08 15:03:29 -05001140 if (xpc_remote_copy_buffer == NULL)
1141 return -ENOMEM;
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001142
1143 snprintf(xpc_part->bus_id, BUS_ID_SIZE, "part");
1144 snprintf(xpc_chan->bus_id, BUS_ID_SIZE, "chan");
1145
Eric W. Biederman0b4d4142007-02-14 00:34:09 -08001146 xpc_sysctl = register_sysctl_table(xpc_sys_dir);
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001147
1148 /*
1149 * The first few fields of each entry of xpc_partitions[] need to
1150 * be initialized now so that calls to xpc_connect() and
1151 * xpc_disconnect() can be made prior to the activation of any remote
1152 * partition. NOTE THAT NONE OF THE OTHER FIELDS BELONGING TO THESE
1153 * ENTRIES ARE MEANINGFUL UNTIL AFTER AN ENTRY'S CORRESPONDING
1154 * PARTITION HAS BEEN ACTIVATED.
1155 */
1156 for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) {
1157 part = &xpc_partitions[partid];
1158
Dean Nelson35190502008-04-22 14:48:55 -05001159 DBUG_ON((u64)part != L1_CACHE_ALIGN((u64)part));
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001160
1161 part->act_IRQ_rcvd = 0;
1162 spin_lock_init(&part->act_lock);
1163 part->act_state = XPC_P_INACTIVE;
1164 XPC_SET_REASON(part, 0, 0);
Dean Nelsona607c382005-09-01 14:01:37 -05001165
1166 init_timer(&part->disengage_request_timer);
1167 part->disengage_request_timer.function =
Dean Nelson35190502008-04-22 14:48:55 -05001168 xpc_timeout_partition_disengage_request;
1169 part->disengage_request_timer.data = (unsigned long)part;
Dean Nelsona607c382005-09-01 14:01:37 -05001170
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001171 part->setup_state = XPC_P_UNSET;
1172 init_waitqueue_head(&part->teardown_wq);
1173 atomic_set(&part->references, 0);
1174 }
1175
1176 /*
1177 * Open up protections for IPI operations (and AMO operations on
1178 * Shub 1.1 systems).
1179 */
1180 xpc_allow_IPI_ops();
1181
1182 /*
1183 * Interrupts being processed will increment this atomic variable and
1184 * awaken the heartbeat thread which will process the interrupts.
1185 */
1186 atomic_set(&xpc_act_IRQ_rcvd, 0);
1187
1188 /*
1189 * This is safe to do before the xpc_hb_checker thread has started
1190 * because the handler releases a wait queue. If an interrupt is
1191 * received before the thread is waiting, it will not go to sleep,
1192 * but rather immediately process the interrupt.
1193 */
1194 ret = request_irq(SGI_XPC_ACTIVATE, xpc_act_IRQ_handler, 0,
Dean Nelson35190502008-04-22 14:48:55 -05001195 "xpc hb", NULL);
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001196 if (ret != 0) {
1197 dev_err(xpc_part, "can't register ACTIVATE IRQ handler, "
1198 "errno=%d\n", -ret);
1199
1200 xpc_restrict_IPI_ops();
1201
Dean Nelson2c2b94f2008-04-22 14:50:17 -05001202 if (xpc_sysctl)
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001203 unregister_sysctl_table(xpc_sysctl);
Dean Nelson7682a4c2006-08-08 15:03:29 -05001204
1205 kfree(xpc_remote_copy_buffer_base);
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001206 return -EBUSY;
1207 }
1208
1209 /*
1210 * Fill the partition reserved page with the information needed by
1211 * other partitions to discover we are alive and establish initial
1212 * communications.
1213 */
1214 xpc_rsvd_page = xpc_rsvd_page_init();
1215 if (xpc_rsvd_page == NULL) {
1216 dev_err(xpc_part, "could not setup our reserved page\n");
1217
1218 free_irq(SGI_XPC_ACTIVATE, NULL);
1219 xpc_restrict_IPI_ops();
1220
Dean Nelson2c2b94f2008-04-22 14:50:17 -05001221 if (xpc_sysctl)
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001222 unregister_sysctl_table(xpc_sysctl);
Dean Nelson7682a4c2006-08-08 15:03:29 -05001223
1224 kfree(xpc_remote_copy_buffer_base);
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001225 return -EBUSY;
1226 }
1227
Dean Nelsona607c382005-09-01 14:01:37 -05001228 /* add ourselves to the reboot_notifier_list */
1229 ret = register_reboot_notifier(&xpc_reboot_notifier);
Dean Nelson2c2b94f2008-04-22 14:50:17 -05001230 if (ret != 0)
Dean Nelsona607c382005-09-01 14:01:37 -05001231 dev_warn(xpc_part, "can't register reboot notifier\n");
Dean Nelsona607c382005-09-01 14:01:37 -05001232
Christoph Hellwig1eeb66a2007-05-08 00:27:03 -07001233 /* add ourselves to the die_notifier list */
Dean Nelson780d09e2005-11-09 14:41:57 -06001234 ret = register_die_notifier(&xpc_die_notifier);
Dean Nelson2c2b94f2008-04-22 14:50:17 -05001235 if (ret != 0)
Dean Nelson780d09e2005-11-09 14:41:57 -06001236 dev_warn(xpc_part, "can't register die notifier\n");
Dean Nelson780d09e2005-11-09 14:41:57 -06001237
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001238 init_timer(&xpc_hb_timer);
1239 xpc_hb_timer.function = xpc_hb_beater;
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001240
1241 /*
1242 * The real work-horse behind xpc. This processes incoming
1243 * interrupts and monitors remote heartbeats.
1244 */
Dean Nelson2c2b94f2008-04-22 14:50:17 -05001245 kthread = kthread_run(xpc_hb_checker, NULL, XPC_HB_CHECK_THREAD_NAME);
1246 if (IS_ERR(kthread)) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001247 dev_err(xpc_part, "failed while forking hb check thread\n");
1248
1249 /* indicate to others that our reserved page is uninitialized */
1250 xpc_rsvd_page->vars_pa = 0;
1251
Dean Nelsona607c382005-09-01 14:01:37 -05001252 /* take ourselves off of the reboot_notifier_list */
Dean Nelson35190502008-04-22 14:48:55 -05001253 (void)unregister_reboot_notifier(&xpc_reboot_notifier);
Dean Nelsona607c382005-09-01 14:01:37 -05001254
Dean Nelson780d09e2005-11-09 14:41:57 -06001255 /* take ourselves off of the die_notifier list */
Dean Nelson35190502008-04-22 14:48:55 -05001256 (void)unregister_die_notifier(&xpc_die_notifier);
Dean Nelson780d09e2005-11-09 14:41:57 -06001257
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001258 del_timer_sync(&xpc_hb_timer);
1259 free_irq(SGI_XPC_ACTIVATE, NULL);
1260 xpc_restrict_IPI_ops();
1261
Dean Nelson2c2b94f2008-04-22 14:50:17 -05001262 if (xpc_sysctl)
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001263 unregister_sysctl_table(xpc_sysctl);
Dean Nelson7682a4c2006-08-08 15:03:29 -05001264
1265 kfree(xpc_remote_copy_buffer_base);
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001266 return -EBUSY;
1267 }
1268
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001269 /*
1270 * Startup a thread that will attempt to discover other partitions to
1271 * activate based on info provided by SAL. This new thread is short
1272 * lived and will exit once discovery is complete.
1273 */
Dean Nelson2c2b94f2008-04-22 14:50:17 -05001274 kthread = kthread_run(xpc_initiate_discovery, NULL,
1275 XPC_DISCOVERY_THREAD_NAME);
1276 if (IS_ERR(kthread)) {
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001277 dev_err(xpc_part, "failed while forking discovery thread\n");
1278
1279 /* mark this new thread as a non-starter */
Jes Sorensenf9e505a2006-01-17 12:52:21 -05001280 complete(&xpc_discovery_exited);
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001281
Dean Nelsona607c382005-09-01 14:01:37 -05001282 xpc_do_exit(xpcUnloading);
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001283 return -EBUSY;
1284 }
1285
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001286 /* set the interface to point at XPC's functions */
1287 xpc_set_interface(xpc_initiate_connect, xpc_initiate_disconnect,
1288 xpc_initiate_allocate, xpc_initiate_send,
1289 xpc_initiate_send_notify, xpc_initiate_received,
1290 xpc_initiate_partid_to_nasids);
1291
1292 return 0;
1293}
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001294
Dean Nelson35190502008-04-22 14:48:55 -05001295module_init(xpc_init);
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001296
1297void __exit
1298xpc_exit(void)
1299{
Dean Nelsona607c382005-09-01 14:01:37 -05001300 xpc_do_exit(xpcUnloading);
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001301}
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001302
Dean Nelson35190502008-04-22 14:48:55 -05001303module_exit(xpc_exit);
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001304
1305MODULE_AUTHOR("Silicon Graphics, Inc.");
1306MODULE_DESCRIPTION("Cross Partition Communication (XPC) support");
1307MODULE_LICENSE("GPL");
1308
1309module_param(xpc_hb_interval, int, 0);
1310MODULE_PARM_DESC(xpc_hb_interval, "Number of seconds between "
Dean Nelson35190502008-04-22 14:48:55 -05001311 "heartbeat increments.");
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001312
1313module_param(xpc_hb_check_interval, int, 0);
1314MODULE_PARM_DESC(xpc_hb_check_interval, "Number of seconds between "
Dean Nelson35190502008-04-22 14:48:55 -05001315 "heartbeat checks.");
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001316
Dean Nelsone54af722005-10-25 14:07:43 -05001317module_param(xpc_disengage_request_timelimit, int, 0);
1318MODULE_PARM_DESC(xpc_disengage_request_timelimit, "Number of seconds to wait "
Dean Nelson35190502008-04-22 14:48:55 -05001319 "for disengage request to complete.");
Dean Nelsone54af722005-10-25 14:07:43 -05001320
Dean Nelson1f4674b2006-01-10 11:08:00 -06001321module_param(xpc_kdebug_ignore, int, 0);
1322MODULE_PARM_DESC(xpc_kdebug_ignore, "Should lack of heartbeat be ignored by "
Dean Nelson35190502008-04-22 14:48:55 -05001323 "other partitions when dropping into kdebug.");