linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / arch / ia64 / sn / kernel / xpc_main.c
1 /*
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  *
6  * Copyright (c) 2004-2006 Silicon Graphics, Inc.  All Rights Reserved.
7  */
8
9
10 /*
11  * Cross Partition Communication (XPC) support - standard version.
12  *
13  *      XPC provides a message passing capability that crosses partition
14  *      boundaries. This module is made up of two parts:
15  *
16  *          partition   This part detects the presence/absence of other
17  *                      partitions. It provides a heartbeat and monitors
18  *                      the heartbeats of other partitions.
19  *
20  *          channel     This part manages the channels and sends/receives
21  *                      messages across them to/from other partitions.
22  *
23  *      There are a couple of additional functions residing in XP, which
24  *      provide an interface to XPC for its users.
25  *
26  *
27  *      Caveats:
28  *
29  *        . We currently have no way to determine which nasid an IPI came
30  *          from. Thus, xpc_IPI_send() does a remote AMO write followed by
31  *          an IPI. The AMO indicates where data is to be pulled from, so
32  *          after the IPI arrives, the remote partition checks the AMO word.
33  *          The IPI can actually arrive before the AMO however, so other code
34  *          must periodically check for this case. Also, remote AMO operations
35  *          do not reliably time out. Thus we do a remote PIO read solely to
36  *          know whether the remote partition is down and whether we should
37  *          stop sending IPIs to it. This remote PIO read operation is set up
38  *          in a special nofault region so SAL knows to ignore (and cleanup)
39  *          any errors due to the remote AMO write, PIO read, and/or PIO
40  *          write operations.
41  *
42  *          If/when new hardware solves this IPI problem, we should abandon
43  *          the current approach.
44  *
45  */
46
47
48 #include <linux/kernel.h>
49 #include <linux/module.h>
50 #include <linux/init.h>
51 #include <linux/sched.h>
52 #include <linux/syscalls.h>
53 #include <linux/cache.h>
54 #include <linux/interrupt.h>
55 #include <linux/slab.h>
56 #include <linux/delay.h>
57 #include <linux/reboot.h>
58 #include <linux/completion.h>
59 #include <asm/sn/intr.h>
60 #include <asm/sn/sn_sal.h>
61 #include <asm/kdebug.h>
62 #include <asm/uaccess.h>
63 #include <asm/sn/xpc.h>
64
65
66 /* define two XPC debug device structures to be used with dev_dbg() et al */
67
68 struct device_driver xpc_dbg_name = {
69         .name = "xpc"
70 };
71
72 struct device xpc_part_dbg_subname = {
73         .bus_id = {0},          /* set to "part" at xpc_init() time */
74         .driver = &xpc_dbg_name
75 };
76
77 struct device xpc_chan_dbg_subname = {
78         .bus_id = {0},          /* set to "chan" at xpc_init() time */
79         .driver = &xpc_dbg_name
80 };
81
82 struct device *xpc_part = &xpc_part_dbg_subname;
83 struct device *xpc_chan = &xpc_chan_dbg_subname;
84
85
86 static int xpc_kdebug_ignore;
87
88
89 /* systune related variables for /proc/sys directories */
90
91 static int xpc_hb_interval = XPC_HB_DEFAULT_INTERVAL;
92 static int xpc_hb_min_interval = 1;
93 static int xpc_hb_max_interval = 10;
94
95 static int xpc_hb_check_interval = XPC_HB_CHECK_DEFAULT_INTERVAL;
96 static int xpc_hb_check_min_interval = 10;
97 static int xpc_hb_check_max_interval = 120;
98
99 int xpc_disengage_request_timelimit = XPC_DISENGAGE_REQUEST_DEFAULT_TIMELIMIT;
100 static int xpc_disengage_request_min_timelimit = 0;
101 static int xpc_disengage_request_max_timelimit = 120;
102
103 static ctl_table xpc_sys_xpc_hb_dir[] = {
104         {
105                 1,
106                 "hb_interval",
107                 &xpc_hb_interval,
108                 sizeof(int),
109                 0644,
110                 NULL,
111                 &proc_dointvec_minmax,
112                 NULL,
113                 &sysctl_intvec,
114                 NULL,
115                 &xpc_hb_min_interval,
116                 &xpc_hb_max_interval
117         },
118         {
119                 2,
120                 "hb_check_interval",
121                 &xpc_hb_check_interval,
122                 sizeof(int),
123                 0644,
124                 NULL,
125                 &proc_dointvec_minmax,
126                 NULL,
127                 &sysctl_intvec,
128                 NULL,
129                 &xpc_hb_check_min_interval,
130                 &xpc_hb_check_max_interval
131         },
132         {0}
133 };
134 static ctl_table xpc_sys_xpc_dir[] = {
135         {
136                 1,
137                 "hb",
138                 NULL,
139                 0,
140                 0555,
141                 xpc_sys_xpc_hb_dir
142         },
143         {
144                 2,
145                 "disengage_request_timelimit",
146                 &xpc_disengage_request_timelimit,
147                 sizeof(int),
148                 0644,
149                 NULL,
150                 &proc_dointvec_minmax,
151                 NULL,
152                 &sysctl_intvec,
153                 NULL,
154                 &xpc_disengage_request_min_timelimit,
155                 &xpc_disengage_request_max_timelimit
156         },
157         {0}
158 };
159 static ctl_table xpc_sys_dir[] = {
160         {
161                 1,
162                 "xpc",
163                 NULL,
164                 0,
165                 0555,
166                 xpc_sys_xpc_dir
167         },
168         {0}
169 };
170 static struct ctl_table_header *xpc_sysctl;
171
172 /* non-zero if any remote partition disengage request was timed out */
173 int xpc_disengage_request_timedout;
174
175 /* #of IRQs received */
176 static atomic_t xpc_act_IRQ_rcvd;
177
178 /* IRQ handler notifies this wait queue on receipt of an IRQ */
179 static DECLARE_WAIT_QUEUE_HEAD(xpc_act_IRQ_wq);
180
181 static unsigned long xpc_hb_check_timeout;
182
183 /* notification that the xpc_hb_checker thread has exited */
184 static DECLARE_COMPLETION(xpc_hb_checker_exited);
185
186 /* notification that the xpc_discovery thread has exited */
187 static DECLARE_COMPLETION(xpc_discovery_exited);
188
189
190 static struct timer_list xpc_hb_timer;
191
192
193 static void xpc_kthread_waitmsgs(struct xpc_partition *, struct xpc_channel *);
194
195
196 static int xpc_system_reboot(struct notifier_block *, unsigned long, void *);
197 static struct notifier_block xpc_reboot_notifier = {
198         .notifier_call = xpc_system_reboot,
199 };
200
201 static int xpc_system_die(struct notifier_block *, unsigned long, void *);
202 static struct notifier_block xpc_die_notifier = {
203         .notifier_call = xpc_system_die,
204 };
205
206
207 /*
208  * Timer function to enforce the timelimit on the partition disengage request.
209  */
210 static void
211 xpc_timeout_partition_disengage_request(unsigned long data)
212 {
213         struct xpc_partition *part = (struct xpc_partition *) data;
214
215
216         DBUG_ON(jiffies < part->disengage_request_timeout);
217
218         (void) xpc_partition_disengaged(part);
219
220         DBUG_ON(part->disengage_request_timeout != 0);
221         DBUG_ON(xpc_partition_engaged(1UL << XPC_PARTID(part)) != 0);
222 }
223
224
225 /*
226  * Notify the heartbeat check thread that an IRQ has been received.
227  */
228 static irqreturn_t
229 xpc_act_IRQ_handler(int irq, void *dev_id, struct pt_regs *regs)
230 {
231         atomic_inc(&xpc_act_IRQ_rcvd);
232         wake_up_interruptible(&xpc_act_IRQ_wq);
233         return IRQ_HANDLED;
234 }
235
236
237 /*
238  * Timer to produce the heartbeat.  The timer structures function is
239  * already set when this is initially called.  A tunable is used to
240  * specify when the next timeout should occur.
241  */
242 static void
243 xpc_hb_beater(unsigned long dummy)
244 {
245         xpc_vars->heartbeat++;
246
247         if (jiffies >= xpc_hb_check_timeout) {
248                 wake_up_interruptible(&xpc_act_IRQ_wq);
249         }
250
251         xpc_hb_timer.expires = jiffies + (xpc_hb_interval * HZ);
252         add_timer(&xpc_hb_timer);
253 }
254
255
256 /*
257  * This thread is responsible for nearly all of the partition
258  * activation/deactivation.
259  */
260 static int
261 xpc_hb_checker(void *ignore)
262 {
263         int last_IRQ_count = 0;
264         int new_IRQ_count;
265         int force_IRQ=0;
266
267
268         /* this thread was marked active by xpc_hb_init() */
269
270         daemonize(XPC_HB_CHECK_THREAD_NAME);
271
272         set_cpus_allowed(current, cpumask_of_cpu(XPC_HB_CHECK_CPU));
273
274         xpc_hb_check_timeout = jiffies + (xpc_hb_check_interval * HZ);
275
276         while (!(volatile int) xpc_exiting) {
277
278                 dev_dbg(xpc_part, "woke up with %d ticks rem; %d IRQs have "
279                         "been received\n",
280                         (int) (xpc_hb_check_timeout - jiffies),
281                         atomic_read(&xpc_act_IRQ_rcvd) - last_IRQ_count);
282
283
284                 /* checking of remote heartbeats is skewed by IRQ handling */
285                 if (jiffies >= xpc_hb_check_timeout) {
286                         dev_dbg(xpc_part, "checking remote heartbeats\n");
287                         xpc_check_remote_hb();
288
289                         /*
290                          * We need to periodically recheck to ensure no
291                          * IPI/AMO pairs have been missed.  That check
292                          * must always reset xpc_hb_check_timeout.
293                          */
294                         force_IRQ = 1;
295                 }
296
297
298                 /* check for outstanding IRQs */
299                 new_IRQ_count = atomic_read(&xpc_act_IRQ_rcvd);
300                 if (last_IRQ_count < new_IRQ_count || force_IRQ != 0) {
301                         force_IRQ = 0;
302
303                         dev_dbg(xpc_part, "found an IRQ to process; will be "
304                                 "resetting xpc_hb_check_timeout\n");
305
306                         last_IRQ_count += xpc_identify_act_IRQ_sender();
307                         if (last_IRQ_count < new_IRQ_count) {
308                                 /* retry once to help avoid missing AMO */
309                                 (void) xpc_identify_act_IRQ_sender();
310                         }
311                         last_IRQ_count = new_IRQ_count;
312
313                         xpc_hb_check_timeout = jiffies +
314                                            (xpc_hb_check_interval * HZ);
315                 }
316
317                 /* wait for IRQ or timeout */
318                 (void) wait_event_interruptible(xpc_act_IRQ_wq,
319                             (last_IRQ_count < atomic_read(&xpc_act_IRQ_rcvd) ||
320                                         jiffies >= xpc_hb_check_timeout ||
321                                                 (volatile int) xpc_exiting));
322         }
323
324         dev_dbg(xpc_part, "heartbeat checker is exiting\n");
325
326
327         /* mark this thread as having exited */
328         complete(&xpc_hb_checker_exited);
329         return 0;
330 }
331
332
333 /*
334  * This thread will attempt to discover other partitions to activate
335  * based on info provided by SAL. This new thread is short lived and
336  * will exit once discovery is complete.
337  */
338 static int
339 xpc_initiate_discovery(void *ignore)
340 {
341         daemonize(XPC_DISCOVERY_THREAD_NAME);
342
343         xpc_discovery();
344
345         dev_dbg(xpc_part, "discovery thread is exiting\n");
346
347         /* mark this thread as having exited */
348         complete(&xpc_discovery_exited);
349         return 0;
350 }
351
352
353 /*
354  * Establish first contact with the remote partititon. This involves pulling
355  * the XPC per partition variables from the remote partition and waiting for
356  * the remote partition to pull ours.
357  */
358 static enum xpc_retval
359 xpc_make_first_contact(struct xpc_partition *part)
360 {
361         enum xpc_retval ret;
362
363
364         while ((ret = xpc_pull_remote_vars_part(part)) != xpcSuccess) {
365                 if (ret != xpcRetry) {
366                         XPC_DEACTIVATE_PARTITION(part, ret);
367                         return ret;
368                 }
369
370                 dev_dbg(xpc_chan, "waiting to make first contact with "
371                         "partition %d\n", XPC_PARTID(part));
372
373                 /* wait a 1/4 of a second or so */
374                 (void) msleep_interruptible(250);
375
376                 if (part->act_state == XPC_P_DEACTIVATING) {
377                         return part->reason;
378                 }
379         }
380
381         return xpc_mark_partition_active(part);
382 }
383
384
385 /*
386  * The first kthread assigned to a newly activated partition is the one
387  * created by XPC HB with which it calls xpc_partition_up(). XPC hangs on to
388  * that kthread until the partition is brought down, at which time that kthread
389  * returns back to XPC HB. (The return of that kthread will signify to XPC HB
390  * that XPC has dismantled all communication infrastructure for the associated
391  * partition.) This kthread becomes the channel manager for that partition.
392  *
393  * Each active partition has a channel manager, who, besides connecting and
394  * disconnecting channels, will ensure that each of the partition's connected
395  * channels has the required number of assigned kthreads to get the work done.
396  */
397 static void
398 xpc_channel_mgr(struct xpc_partition *part)
399 {
400         while (part->act_state != XPC_P_DEACTIVATING ||
401                         atomic_read(&part->nchannels_active) > 0 ||
402                                         !xpc_partition_disengaged(part)) {
403
404                 xpc_process_channel_activity(part);
405
406
407                 /*
408                  * Wait until we've been requested to activate kthreads or
409                  * all of the channel's message queues have been torn down or
410                  * a signal is pending.
411                  *
412                  * The channel_mgr_requests is set to 1 after being awakened,
413                  * This is done to prevent the channel mgr from making one pass
414                  * through the loop for each request, since he will
415                  * be servicing all the requests in one pass. The reason it's
416                  * set to 1 instead of 0 is so that other kthreads will know
417                  * that the channel mgr is running and won't bother trying to
418                  * wake him up.
419                  */
420                 atomic_dec(&part->channel_mgr_requests);
421                 (void) wait_event_interruptible(part->channel_mgr_wq,
422                                 (atomic_read(&part->channel_mgr_requests) > 0 ||
423                                 (volatile u64) part->local_IPI_amo != 0 ||
424                                 ((volatile u8) part->act_state ==
425                                                         XPC_P_DEACTIVATING &&
426                                 atomic_read(&part->nchannels_active) == 0 &&
427                                 xpc_partition_disengaged(part))));
428                 atomic_set(&part->channel_mgr_requests, 1);
429
430                 // >>> Does it need to wakeup periodically as well? In case we
431                 // >>> miscalculated the #of kthreads to wakeup or create?
432         }
433 }
434
435
436 /*
437  * When XPC HB determines that a partition has come up, it will create a new
438  * kthread and that kthread will call this function to attempt to set up the
439  * basic infrastructure used for Cross Partition Communication with the newly
440  * upped partition.
441  *
442  * The kthread that was created by XPC HB and which setup the XPC
443  * infrastructure will remain assigned to the partition until the partition
444  * goes down. At which time the kthread will teardown the XPC infrastructure
445  * and then exit.
446  *
447  * XPC HB will put the remote partition's XPC per partition specific variables
448  * physical address into xpc_partitions[partid].remote_vars_part_pa prior to
449  * calling xpc_partition_up().
450  */
451 static void
452 xpc_partition_up(struct xpc_partition *part)
453 {
454         DBUG_ON(part->channels != NULL);
455
456         dev_dbg(xpc_chan, "activating partition %d\n", XPC_PARTID(part));
457
458         if (xpc_setup_infrastructure(part) != xpcSuccess) {
459                 return;
460         }
461
462         /*
463          * The kthread that XPC HB called us with will become the
464          * channel manager for this partition. It will not return
465          * back to XPC HB until the partition's XPC infrastructure
466          * has been dismantled.
467          */
468
469         (void) xpc_part_ref(part);      /* this will always succeed */
470
471         if (xpc_make_first_contact(part) == xpcSuccess) {
472                 xpc_channel_mgr(part);
473         }
474
475         xpc_part_deref(part);
476
477         xpc_teardown_infrastructure(part);
478 }
479
480
481 static int
482 xpc_activating(void *__partid)
483 {
484         partid_t partid = (u64) __partid;
485         struct xpc_partition *part = &xpc_partitions[partid];
486         unsigned long irq_flags;
487         struct sched_param param = { sched_priority: MAX_RT_PRIO - 1 };
488         int ret;
489
490
491         DBUG_ON(partid <= 0 || partid >= XP_MAX_PARTITIONS);
492
493         spin_lock_irqsave(&part->act_lock, irq_flags);
494
495         if (part->act_state == XPC_P_DEACTIVATING) {
496                 part->act_state = XPC_P_INACTIVE;
497                 spin_unlock_irqrestore(&part->act_lock, irq_flags);
498                 part->remote_rp_pa = 0;
499                 return 0;
500         }
501
502         /* indicate the thread is activating */
503         DBUG_ON(part->act_state != XPC_P_ACTIVATION_REQ);
504         part->act_state = XPC_P_ACTIVATING;
505
506         XPC_SET_REASON(part, 0, 0);
507         spin_unlock_irqrestore(&part->act_lock, irq_flags);
508
509         dev_dbg(xpc_part, "bringing partition %d up\n", partid);
510
511         daemonize("xpc%02d", partid);
512
513         /*
514          * This thread needs to run at a realtime priority to prevent a
515          * significant performance degradation.
516          */
517         ret = sched_setscheduler(current, SCHED_FIFO, &param);
518         if (ret != 0) {
519                 dev_warn(xpc_part, "unable to set pid %d to a realtime "
520                         "priority, ret=%d\n", current->pid, ret);
521         }
522
523         /* allow this thread and its children to run on any CPU */
524         set_cpus_allowed(current, CPU_MASK_ALL);
525
526         /*
527          * Register the remote partition's AMOs with SAL so it can handle
528          * and cleanup errors within that address range should the remote
529          * partition go down. We don't unregister this range because it is
530          * difficult to tell when outstanding writes to the remote partition
531          * are finished and thus when it is safe to unregister. This should
532          * not result in wasted space in the SAL xp_addr_region table because
533          * we should get the same page for remote_amos_page_pa after module
534          * reloads and system reboots.
535          */
536         if (sn_register_xp_addr_region(part->remote_amos_page_pa,
537                                                         PAGE_SIZE, 1) < 0) {
538                 dev_warn(xpc_part, "xpc_partition_up(%d) failed to register "
539                         "xp_addr region\n", partid);
540
541                 spin_lock_irqsave(&part->act_lock, irq_flags);
542                 part->act_state = XPC_P_INACTIVE;
543                 XPC_SET_REASON(part, xpcPhysAddrRegFailed, __LINE__);
544                 spin_unlock_irqrestore(&part->act_lock, irq_flags);
545                 part->remote_rp_pa = 0;
546                 return 0;
547         }
548
549         xpc_allow_hb(partid, xpc_vars);
550         xpc_IPI_send_activated(part);
551
552
553         /*
554          * xpc_partition_up() holds this thread and marks this partition as
555          * XPC_P_ACTIVE by calling xpc_hb_mark_active().
556          */
557         (void) xpc_partition_up(part);
558
559         xpc_disallow_hb(partid, xpc_vars);
560         xpc_mark_partition_inactive(part);
561
562         if (part->reason == xpcReactivating) {
563                 /* interrupting ourselves results in activating partition */
564                 xpc_IPI_send_reactivate(part);
565         }
566
567         return 0;
568 }
569
570
571 void
572 xpc_activate_partition(struct xpc_partition *part)
573 {
574         partid_t partid = XPC_PARTID(part);
575         unsigned long irq_flags;
576         pid_t pid;
577
578
579         spin_lock_irqsave(&part->act_lock, irq_flags);
580
581         DBUG_ON(part->act_state != XPC_P_INACTIVE);
582
583         part->act_state = XPC_P_ACTIVATION_REQ;
584         XPC_SET_REASON(part, xpcCloneKThread, __LINE__);
585
586         spin_unlock_irqrestore(&part->act_lock, irq_flags);
587
588         pid = kernel_thread(xpc_activating, (void *) ((u64) partid), 0);
589
590         if (unlikely(pid <= 0)) {
591                 spin_lock_irqsave(&part->act_lock, irq_flags);
592                 part->act_state = XPC_P_INACTIVE;
593                 XPC_SET_REASON(part, xpcCloneKThreadFailed, __LINE__);
594                 spin_unlock_irqrestore(&part->act_lock, irq_flags);
595         }
596 }
597
598
599 /*
600  * Handle the receipt of a SGI_XPC_NOTIFY IRQ by seeing whether the specified
601  * partition actually sent it. Since SGI_XPC_NOTIFY IRQs may be shared by more
602  * than one partition, we use an AMO_t structure per partition to indicate
603  * whether a partition has sent an IPI or not.  >>> If it has, then wake up the
604  * associated kthread to handle it.
605  *
606  * All SGI_XPC_NOTIFY IRQs received by XPC are the result of IPIs sent by XPC
607  * running on other partitions.
608  *
609  * Noteworthy Arguments:
610  *
611  *      irq - Interrupt ReQuest number. NOT USED.
612  *
613  *      dev_id - partid of IPI's potential sender.
614  *
615  *      regs - processor's context before the processor entered
616  *             interrupt code. NOT USED.
617  */
618 irqreturn_t
619 xpc_notify_IRQ_handler(int irq, void *dev_id, struct pt_regs *regs)
620 {
621         partid_t partid = (partid_t) (u64) dev_id;
622         struct xpc_partition *part = &xpc_partitions[partid];
623
624
625         DBUG_ON(partid <= 0 || partid >= XP_MAX_PARTITIONS);
626
627         if (xpc_part_ref(part)) {
628                 xpc_check_for_channel_activity(part);
629
630                 xpc_part_deref(part);
631         }
632         return IRQ_HANDLED;
633 }
634
635
636 /*
637  * Check to see if xpc_notify_IRQ_handler() dropped any IPIs on the floor
638  * because the write to their associated IPI amo completed after the IRQ/IPI
639  * was received.
640  */
641 void
642 xpc_dropped_IPI_check(struct xpc_partition *part)
643 {
644         if (xpc_part_ref(part)) {
645                 xpc_check_for_channel_activity(part);
646
647                 part->dropped_IPI_timer.expires = jiffies +
648                                                         XPC_P_DROPPED_IPI_WAIT;
649                 add_timer(&part->dropped_IPI_timer);
650                 xpc_part_deref(part);
651         }
652 }
653
654
655 void
656 xpc_activate_kthreads(struct xpc_channel *ch, int needed)
657 {
658         int idle = atomic_read(&ch->kthreads_idle);
659         int assigned = atomic_read(&ch->kthreads_assigned);
660         int wakeup;
661
662
663         DBUG_ON(needed <= 0);
664
665         if (idle > 0) {
666                 wakeup = (needed > idle) ? idle : needed;
667                 needed -= wakeup;
668
669                 dev_dbg(xpc_chan, "wakeup %d idle kthreads, partid=%d, "
670                         "channel=%d\n", wakeup, ch->partid, ch->number);
671
672                 /* only wakeup the requested number of kthreads */
673                 wake_up_nr(&ch->idle_wq, wakeup);
674         }
675
676         if (needed <= 0) {
677                 return;
678         }
679
680         if (needed + assigned > ch->kthreads_assigned_limit) {
681                 needed = ch->kthreads_assigned_limit - assigned;
682                 // >>>should never be less than 0
683                 if (needed <= 0) {
684                         return;
685                 }
686         }
687
688         dev_dbg(xpc_chan, "create %d new kthreads, partid=%d, channel=%d\n",
689                 needed, ch->partid, ch->number);
690
691         xpc_create_kthreads(ch, needed);
692 }
693
694
695 /*
696  * This function is where XPC's kthreads wait for messages to deliver.
697  */
698 static void
699 xpc_kthread_waitmsgs(struct xpc_partition *part, struct xpc_channel *ch)
700 {
701         do {
702                 /* deliver messages to their intended recipients */
703
704                 while ((volatile s64) ch->w_local_GP.get <
705                                 (volatile s64) ch->w_remote_GP.put &&
706                                         !((volatile u32) ch->flags &
707                                                 XPC_C_DISCONNECTING)) {
708                         xpc_deliver_msg(ch);
709                 }
710
711                 if (atomic_inc_return(&ch->kthreads_idle) >
712                                                 ch->kthreads_idle_limit) {
713                         /* too many idle kthreads on this channel */
714                         atomic_dec(&ch->kthreads_idle);
715                         break;
716                 }
717
718                 dev_dbg(xpc_chan, "idle kthread calling "
719                         "wait_event_interruptible_exclusive()\n");
720
721                 (void) wait_event_interruptible_exclusive(ch->idle_wq,
722                                 ((volatile s64) ch->w_local_GP.get <
723                                         (volatile s64) ch->w_remote_GP.put ||
724                                 ((volatile u32) ch->flags &
725                                                 XPC_C_DISCONNECTING)));
726
727                 atomic_dec(&ch->kthreads_idle);
728
729         } while (!((volatile u32) ch->flags & XPC_C_DISCONNECTING));
730 }
731
732
733 static int
734 xpc_daemonize_kthread(void *args)
735 {
736         partid_t partid = XPC_UNPACK_ARG1(args);
737         u16 ch_number = XPC_UNPACK_ARG2(args);
738         struct xpc_partition *part = &xpc_partitions[partid];
739         struct xpc_channel *ch;
740         int n_needed;
741         unsigned long irq_flags;
742
743
744         daemonize("xpc%02dc%d", partid, ch_number);
745
746         dev_dbg(xpc_chan, "kthread starting, partid=%d, channel=%d\n",
747                 partid, ch_number);
748
749         ch = &part->channels[ch_number];
750
751         if (!(ch->flags & XPC_C_DISCONNECTING)) {
752
753                 /* let registerer know that connection has been established */
754
755                 spin_lock_irqsave(&ch->lock, irq_flags);
756                 if (!(ch->flags & XPC_C_CONNECTEDCALLOUT)) {
757                         ch->flags |= XPC_C_CONNECTEDCALLOUT;
758                         spin_unlock_irqrestore(&ch->lock, irq_flags);
759
760                         xpc_connected_callout(ch);
761
762                         spin_lock_irqsave(&ch->lock, irq_flags);
763                         ch->flags |= XPC_C_CONNECTEDCALLOUT_MADE;
764                         spin_unlock_irqrestore(&ch->lock, irq_flags);
765
766                         /*
767                          * It is possible that while the callout was being
768                          * made that the remote partition sent some messages.
769                          * If that is the case, we may need to activate
770                          * additional kthreads to help deliver them. We only
771                          * need one less than total #of messages to deliver.
772                          */
773                         n_needed = ch->w_remote_GP.put - ch->w_local_GP.get - 1;
774                         if (n_needed > 0 &&
775                                         !(ch->flags & XPC_C_DISCONNECTING)) {
776                                 xpc_activate_kthreads(ch, n_needed);
777                         }
778                 } else {
779                         spin_unlock_irqrestore(&ch->lock, irq_flags);
780                 }
781
782                 xpc_kthread_waitmsgs(part, ch);
783         }
784
785         if (atomic_dec_return(&ch->kthreads_assigned) == 0) {
786                 spin_lock_irqsave(&ch->lock, irq_flags);
787                 if ((ch->flags & XPC_C_CONNECTEDCALLOUT_MADE) &&
788                                 !(ch->flags & XPC_C_DISCONNECTINGCALLOUT)) {
789                         ch->flags |= XPC_C_DISCONNECTINGCALLOUT;
790                         spin_unlock_irqrestore(&ch->lock, irq_flags);
791
792                         xpc_disconnect_callout(ch, xpcDisconnecting);
793
794                         spin_lock_irqsave(&ch->lock, irq_flags);
795                         ch->flags |= XPC_C_DISCONNECTINGCALLOUT_MADE;
796                 }
797                 spin_unlock_irqrestore(&ch->lock, irq_flags);
798                 if (atomic_dec_return(&part->nchannels_engaged) == 0) {
799                         xpc_mark_partition_disengaged(part);
800                         xpc_IPI_send_disengage(part);
801                 }
802         }
803
804
805         xpc_msgqueue_deref(ch);
806
807         dev_dbg(xpc_chan, "kthread exiting, partid=%d, channel=%d\n",
808                 partid, ch_number);
809
810         xpc_part_deref(part);
811         return 0;
812 }
813
814
815 /*
816  * For each partition that XPC has established communications with, there is
817  * a minimum of one kernel thread assigned to perform any operation that
818  * may potentially sleep or block (basically the callouts to the asynchronous
819  * functions registered via xpc_connect()).
820  *
821  * Additional kthreads are created and destroyed by XPC as the workload
822  * demands.
823  *
824  * A kthread is assigned to one of the active channels that exists for a given
825  * partition.
826  */
827 void
828 xpc_create_kthreads(struct xpc_channel *ch, int needed)
829 {
830         unsigned long irq_flags;
831         pid_t pid;
832         u64 args = XPC_PACK_ARGS(ch->partid, ch->number);
833         struct xpc_partition *part = &xpc_partitions[ch->partid];
834
835
836         while (needed-- > 0) {
837
838                 /*
839                  * The following is done on behalf of the newly created
840                  * kthread. That kthread is responsible for doing the
841                  * counterpart to the following before it exits.
842                  */
843                 (void) xpc_part_ref(part);
844                 xpc_msgqueue_ref(ch);
845                 if (atomic_inc_return(&ch->kthreads_assigned) == 1 &&
846                     atomic_inc_return(&part->nchannels_engaged) == 1) {
847                         xpc_mark_partition_engaged(part);
848                 }
849
850                 pid = kernel_thread(xpc_daemonize_kthread, (void *) args, 0);
851                 if (pid < 0) {
852                         /* the fork failed */
853                         if (atomic_dec_return(&ch->kthreads_assigned) == 0 &&
854                             atomic_dec_return(&part->nchannels_engaged) == 0) {
855                                 xpc_mark_partition_disengaged(part);
856                                 xpc_IPI_send_disengage(part);
857                         }
858                         xpc_msgqueue_deref(ch);
859                         xpc_part_deref(part);
860
861                         if (atomic_read(&ch->kthreads_assigned) <
862                                                 ch->kthreads_idle_limit) {
863                                 /*
864                                  * Flag this as an error only if we have an
865                                  * insufficient #of kthreads for the channel
866                                  * to function.
867                                  *
868                                  * No xpc_msgqueue_ref() is needed here since
869                                  * the channel mgr is doing this.
870                                  */
871                                 spin_lock_irqsave(&ch->lock, irq_flags);
872                                 XPC_DISCONNECT_CHANNEL(ch, xpcLackOfResources,
873                                                                 &irq_flags);
874                                 spin_unlock_irqrestore(&ch->lock, irq_flags);
875                         }
876                         break;
877                 }
878
879                 ch->kthreads_created++; // >>> temporary debug only!!!
880         }
881 }
882
883
884 void
885 xpc_disconnect_wait(int ch_number)
886 {
887         unsigned long irq_flags;
888         partid_t partid;
889         struct xpc_partition *part;
890         struct xpc_channel *ch;
891         int wakeup_channel_mgr;
892
893
894         /* now wait for all callouts to the caller's function to cease */
895         for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) {
896                 part = &xpc_partitions[partid];
897
898                 if (!xpc_part_ref(part)) {
899                         continue;
900                 }
901
902                 ch = &part->channels[ch_number];
903
904                 if (!(ch->flags & XPC_C_WDISCONNECT)) {
905                         xpc_part_deref(part);
906                         continue;
907                 }
908
909                 wait_for_completion(&ch->wdisconnect_wait);
910
911                 spin_lock_irqsave(&ch->lock, irq_flags);
912                 DBUG_ON(!(ch->flags & XPC_C_DISCONNECTED));
913                 wakeup_channel_mgr = 0;
914
915                 if (ch->delayed_IPI_flags) {
916                         if (part->act_state != XPC_P_DEACTIVATING) {
917                                 spin_lock(&part->IPI_lock);
918                                 XPC_SET_IPI_FLAGS(part->local_IPI_amo,
919                                         ch->number, ch->delayed_IPI_flags);
920                                 spin_unlock(&part->IPI_lock);
921                                 wakeup_channel_mgr = 1;
922                         }
923                         ch->delayed_IPI_flags = 0;
924                 }
925
926                 ch->flags &= ~XPC_C_WDISCONNECT;
927                 spin_unlock_irqrestore(&ch->lock, irq_flags);
928
929                 if (wakeup_channel_mgr) {
930                         xpc_wakeup_channel_mgr(part);
931                 }
932
933                 xpc_part_deref(part);
934         }
935 }
936
937
938 static void
939 xpc_do_exit(enum xpc_retval reason)
940 {
941         partid_t partid;
942         int active_part_count, printed_waiting_msg = 0;
943         struct xpc_partition *part;
944         unsigned long printmsg_time, disengage_request_timeout = 0;
945
946
947         /* a 'rmmod XPC' and a 'reboot' cannot both end up here together */
948         DBUG_ON(xpc_exiting == 1);
949
950         /*
951          * Let the heartbeat checker thread and the discovery thread
952          * (if one is running) know that they should exit. Also wake up
953          * the heartbeat checker thread in case it's sleeping.
954          */
955         xpc_exiting = 1;
956         wake_up_interruptible(&xpc_act_IRQ_wq);
957
958         /* ignore all incoming interrupts */
959         free_irq(SGI_XPC_ACTIVATE, NULL);
960
961         /* wait for the discovery thread to exit */
962         wait_for_completion(&xpc_discovery_exited);
963
964         /* wait for the heartbeat checker thread to exit */
965         wait_for_completion(&xpc_hb_checker_exited);
966
967
968         /* sleep for a 1/3 of a second or so */
969         (void) msleep_interruptible(300);
970
971
972         /* wait for all partitions to become inactive */
973
974         printmsg_time = jiffies + (XPC_DISENGAGE_PRINTMSG_INTERVAL * HZ);
975         xpc_disengage_request_timedout = 0;
976
977         do {
978                 active_part_count = 0;
979
980                 for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) {
981                         part = &xpc_partitions[partid];
982
983                         if (xpc_partition_disengaged(part) &&
984                                         part->act_state == XPC_P_INACTIVE) {
985                                 continue;
986                         }
987
988                         active_part_count++;
989
990                         XPC_DEACTIVATE_PARTITION(part, reason);
991
992                         if (part->disengage_request_timeout >
993                                                 disengage_request_timeout) {
994                                 disengage_request_timeout =
995                                                 part->disengage_request_timeout;
996                         }
997                 }
998
999                 if (xpc_partition_engaged(-1UL)) {
1000                         if (time_after(jiffies, printmsg_time)) {
1001                                 dev_info(xpc_part, "waiting for remote "
1002                                         "partitions to disengage, timeout in "
1003                                         "%ld seconds\n",
1004                                         (disengage_request_timeout - jiffies)
1005                                                                         / HZ);
1006                                 printmsg_time = jiffies +
1007                                         (XPC_DISENGAGE_PRINTMSG_INTERVAL * HZ);
1008                                 printed_waiting_msg = 1;
1009                         }
1010
1011                 } else if (active_part_count > 0) {
1012                         if (printed_waiting_msg) {
1013                                 dev_info(xpc_part, "waiting for local partition"
1014                                         " to disengage\n");
1015                                 printed_waiting_msg = 0;
1016                         }
1017
1018                 } else {
1019                         if (!xpc_disengage_request_timedout) {
1020                                 dev_info(xpc_part, "all partitions have "
1021                                         "disengaged\n");
1022                         }
1023                         break;
1024                 }
1025
1026                 /* sleep for a 1/3 of a second or so */
1027                 (void) msleep_interruptible(300);
1028
1029         } while (1);
1030
1031         DBUG_ON(xpc_partition_engaged(-1UL));
1032
1033
1034         /* indicate to others that our reserved page is uninitialized */
1035         xpc_rsvd_page->vars_pa = 0;
1036
1037         /* now it's time to eliminate our heartbeat */
1038         del_timer_sync(&xpc_hb_timer);
1039         DBUG_ON(xpc_vars->heartbeating_to_mask != 0);
1040
1041         if (reason == xpcUnloading) {
1042                 /* take ourselves off of the reboot_notifier_list */
1043                 (void) unregister_reboot_notifier(&xpc_reboot_notifier);
1044
1045                 /* take ourselves off of the die_notifier list */
1046                 (void) unregister_die_notifier(&xpc_die_notifier);
1047         }
1048
1049         /* close down protections for IPI operations */
1050         xpc_restrict_IPI_ops();
1051
1052
1053         /* clear the interface to XPC's functions */
1054         xpc_clear_interface();
1055
1056         if (xpc_sysctl) {
1057                 unregister_sysctl_table(xpc_sysctl);
1058         }
1059
1060         kfree(xpc_remote_copy_buffer_base);
1061 }
1062
1063
1064 /*
1065  * This function is called when the system is being rebooted.
1066  */
1067 static int
1068 xpc_system_reboot(struct notifier_block *nb, unsigned long event, void *unused)
1069 {
1070         enum xpc_retval reason;
1071
1072
1073         switch (event) {
1074         case SYS_RESTART:
1075                 reason = xpcSystemReboot;
1076                 break;
1077         case SYS_HALT:
1078                 reason = xpcSystemHalt;
1079                 break;
1080         case SYS_POWER_OFF:
1081                 reason = xpcSystemPoweroff;
1082                 break;
1083         default:
1084                 reason = xpcSystemGoingDown;
1085         }
1086
1087         xpc_do_exit(reason);
1088         return NOTIFY_DONE;
1089 }
1090
1091
1092 /*
1093  * Notify other partitions to disengage from all references to our memory.
1094  */
1095 static void
1096 xpc_die_disengage(void)
1097 {
1098         struct xpc_partition *part;
1099         partid_t partid;
1100         unsigned long engaged;
1101         long time, printmsg_time, disengage_request_timeout;
1102
1103
1104         /* keep xpc_hb_checker thread from doing anything (just in case) */
1105         xpc_exiting = 1;
1106
1107         xpc_vars->heartbeating_to_mask = 0;  /* indicate we're deactivated */
1108
1109         for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) {
1110                 part = &xpc_partitions[partid];
1111
1112                 if (!XPC_SUPPORTS_DISENGAGE_REQUEST(part->
1113                                                         remote_vars_version)) {
1114
1115                         /* just in case it was left set by an earlier XPC */
1116                         xpc_clear_partition_engaged(1UL << partid);
1117                         continue;
1118                 }
1119
1120                 if (xpc_partition_engaged(1UL << partid) ||
1121                                         part->act_state != XPC_P_INACTIVE) {
1122                         xpc_request_partition_disengage(part);
1123                         xpc_mark_partition_disengaged(part);
1124                         xpc_IPI_send_disengage(part);
1125                 }
1126         }
1127
1128         time = rtc_time();
1129         printmsg_time = time +
1130                 (XPC_DISENGAGE_PRINTMSG_INTERVAL * sn_rtc_cycles_per_second);
1131         disengage_request_timeout = time +
1132                 (xpc_disengage_request_timelimit * sn_rtc_cycles_per_second);
1133
1134         /* wait for all other partitions to disengage from us */
1135
1136         while (1) {
1137                 engaged = xpc_partition_engaged(-1UL);
1138                 if (!engaged) {
1139                         dev_info(xpc_part, "all partitions have disengaged\n");
1140                         break;
1141                 }
1142
1143                 time = rtc_time();
1144                 if (time >= disengage_request_timeout) {
1145                         for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) {
1146                                 if (engaged & (1UL << partid)) {
1147                                         dev_info(xpc_part, "disengage from "
1148                                                 "remote partition %d timed "
1149                                                 "out\n", partid);
1150                                 }
1151                         }
1152                         break;
1153                 }
1154
1155                 if (time >= printmsg_time) {
1156                         dev_info(xpc_part, "waiting for remote partitions to "
1157                                 "disengage, timeout in %ld seconds\n",
1158                                 (disengage_request_timeout - time) /
1159                                                 sn_rtc_cycles_per_second);
1160                         printmsg_time = time +
1161                                         (XPC_DISENGAGE_PRINTMSG_INTERVAL *
1162                                                 sn_rtc_cycles_per_second);
1163                 }
1164         }
1165 }
1166
1167
1168 /*
1169  * This function is called when the system is being restarted or halted due
1170  * to some sort of system failure. If this is the case we need to notify the
1171  * other partitions to disengage from all references to our memory.
1172  * This function can also be called when our heartbeater could be offlined
1173  * for a time. In this case we need to notify other partitions to not worry
1174  * about the lack of a heartbeat.
1175  */
1176 static int
1177 xpc_system_die(struct notifier_block *nb, unsigned long event, void *unused)
1178 {
1179         switch (event) {
1180         case DIE_MACHINE_RESTART:
1181         case DIE_MACHINE_HALT:
1182                 xpc_die_disengage();
1183                 break;
1184
1185         case DIE_KDEBUG_ENTER:
1186                 /* Should lack of heartbeat be ignored by other partitions? */
1187                 if (!xpc_kdebug_ignore) {
1188                         break;
1189                 }
1190                 /* fall through */
1191         case DIE_MCA_MONARCH_ENTER:
1192         case DIE_INIT_MONARCH_ENTER:
1193                 xpc_vars->heartbeat++;
1194                 xpc_vars->heartbeat_offline = 1;
1195                 break;
1196
1197         case DIE_KDEBUG_LEAVE:
1198                 /* Is lack of heartbeat being ignored by other partitions? */
1199                 if (!xpc_kdebug_ignore) {
1200                         break;
1201                 }
1202                 /* fall through */
1203         case DIE_MCA_MONARCH_LEAVE:
1204         case DIE_INIT_MONARCH_LEAVE:
1205                 xpc_vars->heartbeat++;
1206                 xpc_vars->heartbeat_offline = 0;
1207                 break;
1208         }
1209
1210         return NOTIFY_DONE;
1211 }
1212
1213
1214 int __init
1215 xpc_init(void)
1216 {
1217         int ret;
1218         partid_t partid;
1219         struct xpc_partition *part;
1220         pid_t pid;
1221         size_t buf_size;
1222
1223
1224         if (!ia64_platform_is("sn2")) {
1225                 return -ENODEV;
1226         }
1227
1228
1229         buf_size = max(XPC_RP_VARS_SIZE,
1230                                 XPC_RP_HEADER_SIZE + XP_NASID_MASK_BYTES);
1231         xpc_remote_copy_buffer = xpc_kmalloc_cacheline_aligned(buf_size,
1232                                      GFP_KERNEL, &xpc_remote_copy_buffer_base);
1233         if (xpc_remote_copy_buffer == NULL)
1234                 return -ENOMEM;
1235
1236         snprintf(xpc_part->bus_id, BUS_ID_SIZE, "part");
1237         snprintf(xpc_chan->bus_id, BUS_ID_SIZE, "chan");
1238
1239         xpc_sysctl = register_sysctl_table(xpc_sys_dir, 1);
1240
1241         /*
1242          * The first few fields of each entry of xpc_partitions[] need to
1243          * be initialized now so that calls to xpc_connect() and
1244          * xpc_disconnect() can be made prior to the activation of any remote
1245          * partition. NOTE THAT NONE OF THE OTHER FIELDS BELONGING TO THESE
1246          * ENTRIES ARE MEANINGFUL UNTIL AFTER AN ENTRY'S CORRESPONDING
1247          * PARTITION HAS BEEN ACTIVATED.
1248          */
1249         for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) {
1250                 part = &xpc_partitions[partid];
1251
1252                 DBUG_ON((u64) part != L1_CACHE_ALIGN((u64) part));
1253
1254                 part->act_IRQ_rcvd = 0;
1255                 spin_lock_init(&part->act_lock);
1256                 part->act_state = XPC_P_INACTIVE;
1257                 XPC_SET_REASON(part, 0, 0);
1258
1259                 init_timer(&part->disengage_request_timer);
1260                 part->disengage_request_timer.function =
1261                                 xpc_timeout_partition_disengage_request;
1262                 part->disengage_request_timer.data = (unsigned long) part;
1263
1264                 part->setup_state = XPC_P_UNSET;
1265                 init_waitqueue_head(&part->teardown_wq);
1266                 atomic_set(&part->references, 0);
1267         }
1268
1269         /*
1270          * Open up protections for IPI operations (and AMO operations on
1271          * Shub 1.1 systems).
1272          */
1273         xpc_allow_IPI_ops();
1274
1275         /*
1276          * Interrupts being processed will increment this atomic variable and
1277          * awaken the heartbeat thread which will process the interrupts.
1278          */
1279         atomic_set(&xpc_act_IRQ_rcvd, 0);
1280
1281         /*
1282          * This is safe to do before the xpc_hb_checker thread has started
1283          * because the handler releases a wait queue.  If an interrupt is
1284          * received before the thread is waiting, it will not go to sleep,
1285          * but rather immediately process the interrupt.
1286          */
1287         ret = request_irq(SGI_XPC_ACTIVATE, xpc_act_IRQ_handler, 0,
1288                                                         "xpc hb", NULL);
1289         if (ret != 0) {
1290                 dev_err(xpc_part, "can't register ACTIVATE IRQ handler, "
1291                         "errno=%d\n", -ret);
1292
1293                 xpc_restrict_IPI_ops();
1294
1295                 if (xpc_sysctl) {
1296                         unregister_sysctl_table(xpc_sysctl);
1297                 }
1298
1299                 kfree(xpc_remote_copy_buffer_base);
1300                 return -EBUSY;
1301         }
1302
1303         /*
1304          * Fill the partition reserved page with the information needed by
1305          * other partitions to discover we are alive and establish initial
1306          * communications.
1307          */
1308         xpc_rsvd_page = xpc_rsvd_page_init();
1309         if (xpc_rsvd_page == NULL) {
1310                 dev_err(xpc_part, "could not setup our reserved page\n");
1311
1312                 free_irq(SGI_XPC_ACTIVATE, NULL);
1313                 xpc_restrict_IPI_ops();
1314
1315                 if (xpc_sysctl) {
1316                         unregister_sysctl_table(xpc_sysctl);
1317                 }
1318
1319                 kfree(xpc_remote_copy_buffer_base);
1320                 return -EBUSY;
1321         }
1322
1323
1324         /* add ourselves to the reboot_notifier_list */
1325         ret = register_reboot_notifier(&xpc_reboot_notifier);
1326         if (ret != 0) {
1327                 dev_warn(xpc_part, "can't register reboot notifier\n");
1328         }
1329
1330         /* add ourselves to the die_notifier list (i.e., ia64die_chain) */
1331         ret = register_die_notifier(&xpc_die_notifier);
1332         if (ret != 0) {
1333                 dev_warn(xpc_part, "can't register die notifier\n");
1334         }
1335
1336
1337         /*
1338          * Set the beating to other partitions into motion.  This is
1339          * the last requirement for other partitions' discovery to
1340          * initiate communications with us.
1341          */
1342         init_timer(&xpc_hb_timer);
1343         xpc_hb_timer.function = xpc_hb_beater;
1344         xpc_hb_beater(0);
1345
1346
1347         /*
1348          * The real work-horse behind xpc.  This processes incoming
1349          * interrupts and monitors remote heartbeats.
1350          */
1351         pid = kernel_thread(xpc_hb_checker, NULL, 0);
1352         if (pid < 0) {
1353                 dev_err(xpc_part, "failed while forking hb check thread\n");
1354
1355                 /* indicate to others that our reserved page is uninitialized */
1356                 xpc_rsvd_page->vars_pa = 0;
1357
1358                 /* take ourselves off of the reboot_notifier_list */
1359                 (void) unregister_reboot_notifier(&xpc_reboot_notifier);
1360
1361                 /* take ourselves off of the die_notifier list */
1362                 (void) unregister_die_notifier(&xpc_die_notifier);
1363
1364                 del_timer_sync(&xpc_hb_timer);
1365                 free_irq(SGI_XPC_ACTIVATE, NULL);
1366                 xpc_restrict_IPI_ops();
1367
1368                 if (xpc_sysctl) {
1369                         unregister_sysctl_table(xpc_sysctl);
1370                 }
1371
1372                 kfree(xpc_remote_copy_buffer_base);
1373                 return -EBUSY;
1374         }
1375
1376
1377         /*
1378          * Startup a thread that will attempt to discover other partitions to
1379          * activate based on info provided by SAL. This new thread is short
1380          * lived and will exit once discovery is complete.
1381          */
1382         pid = kernel_thread(xpc_initiate_discovery, NULL, 0);
1383         if (pid < 0) {
1384                 dev_err(xpc_part, "failed while forking discovery thread\n");
1385
1386                 /* mark this new thread as a non-starter */
1387                 complete(&xpc_discovery_exited);
1388
1389                 xpc_do_exit(xpcUnloading);
1390                 return -EBUSY;
1391         }
1392
1393
1394         /* set the interface to point at XPC's functions */
1395         xpc_set_interface(xpc_initiate_connect, xpc_initiate_disconnect,
1396                           xpc_initiate_allocate, xpc_initiate_send,
1397                           xpc_initiate_send_notify, xpc_initiate_received,
1398                           xpc_initiate_partid_to_nasids);
1399
1400         return 0;
1401 }
1402 module_init(xpc_init);
1403
1404
1405 void __exit
1406 xpc_exit(void)
1407 {
1408         xpc_do_exit(xpcUnloading);
1409 }
1410 module_exit(xpc_exit);
1411
1412
1413 MODULE_AUTHOR("Silicon Graphics, Inc.");
1414 MODULE_DESCRIPTION("Cross Partition Communication (XPC) support");
1415 MODULE_LICENSE("GPL");
1416
1417 module_param(xpc_hb_interval, int, 0);
1418 MODULE_PARM_DESC(xpc_hb_interval, "Number of seconds between "
1419                 "heartbeat increments.");
1420
1421 module_param(xpc_hb_check_interval, int, 0);
1422 MODULE_PARM_DESC(xpc_hb_check_interval, "Number of seconds between "
1423                 "heartbeat checks.");
1424
1425 module_param(xpc_disengage_request_timelimit, int, 0);
1426 MODULE_PARM_DESC(xpc_disengage_request_timelimit, "Number of seconds to wait "
1427                 "for disengage request to complete.");
1428
1429 module_param(xpc_kdebug_ignore, int, 0);
1430 MODULE_PARM_DESC(xpc_kdebug_ignore, "Should lack of heartbeat be ignored by "
1431                 "other partitions when dropping into kdebug.");
1432