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
6 * Copyright (c) 2004-2005 Silicon Graphics, Inc. All Rights Reserved.
11 * Cross Partition Communication (XPC) support - standard version.
13 * XPC provides a message passing capability that crosses partition
14 * boundaries. This module is made up of two parts:
16 * partition This part detects the presence/absence of other
17 * partitions. It provides a heartbeat and monitors
18 * the heartbeats of other partitions.
20 * channel This part manages the channels and sends/receives
21 * messages across them to/from other partitions.
23 * There are a couple of additional functions residing in XP, which
24 * provide an interface to XPC for its users.
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
42 * If/when new hardware solves this IPI problem, we should abandon
43 * the current approach.
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 <asm/sn/intr.h>
58 #include <asm/sn/sn_sal.h>
59 #include <asm/uaccess.h>
63 /* define two XPC debug device structures to be used with dev_dbg() et al */
65 struct device_driver xpc_dbg_name = {
69 struct device xpc_part_dbg_subname = {
70 .bus_id = {0}, /* set to "part" at xpc_init() time */
71 .driver = &xpc_dbg_name
74 struct device xpc_chan_dbg_subname = {
75 .bus_id = {0}, /* set to "chan" at xpc_init() time */
76 .driver = &xpc_dbg_name
79 struct device *xpc_part = &xpc_part_dbg_subname;
80 struct device *xpc_chan = &xpc_chan_dbg_subname;
83 /* systune related variables for /proc/sys directories */
85 static int xpc_hb_min = 1;
86 static int xpc_hb_max = 10;
88 static int xpc_hb_check_min = 10;
89 static int xpc_hb_check_max = 120;
91 static ctl_table xpc_sys_xpc_hb_dir[] = {
99 &proc_dointvec_minmax,
102 &xpc_hb_min, &xpc_hb_max
107 &xpc_hb_check_interval,
111 &proc_dointvec_minmax,
114 &xpc_hb_check_min, &xpc_hb_check_max
118 static ctl_table xpc_sys_xpc_dir[] = {
129 static ctl_table xpc_sys_dir[] = {
140 static struct ctl_table_header *xpc_sysctl;
143 /* #of IRQs received */
144 static atomic_t xpc_act_IRQ_rcvd;
146 /* IRQ handler notifies this wait queue on receipt of an IRQ */
147 static DECLARE_WAIT_QUEUE_HEAD(xpc_act_IRQ_wq);
149 static unsigned long xpc_hb_check_timeout;
151 /* xpc_hb_checker thread exited notification */
152 static DECLARE_MUTEX_LOCKED(xpc_hb_checker_exited);
154 /* xpc_discovery thread exited notification */
155 static DECLARE_MUTEX_LOCKED(xpc_discovery_exited);
158 static struct timer_list xpc_hb_timer;
161 static void xpc_kthread_waitmsgs(struct xpc_partition *, struct xpc_channel *);
165 * Notify the heartbeat check thread that an IRQ has been received.
168 xpc_act_IRQ_handler(int irq, void *dev_id, struct pt_regs *regs)
170 atomic_inc(&xpc_act_IRQ_rcvd);
171 wake_up_interruptible(&xpc_act_IRQ_wq);
177 * Timer to produce the heartbeat. The timer structures function is
178 * already set when this is initially called. A tunable is used to
179 * specify when the next timeout should occur.
182 xpc_hb_beater(unsigned long dummy)
184 xpc_vars->heartbeat++;
186 if (jiffies >= xpc_hb_check_timeout) {
187 wake_up_interruptible(&xpc_act_IRQ_wq);
190 xpc_hb_timer.expires = jiffies + (xpc_hb_interval * HZ);
191 add_timer(&xpc_hb_timer);
196 * This thread is responsible for nearly all of the partition
197 * activation/deactivation.
200 xpc_hb_checker(void *ignore)
202 int last_IRQ_count = 0;
207 /* this thread was marked active by xpc_hb_init() */
209 daemonize(XPC_HB_CHECK_THREAD_NAME);
211 set_cpus_allowed(current, cpumask_of_cpu(XPC_HB_CHECK_CPU));
213 xpc_hb_check_timeout = jiffies + (xpc_hb_check_interval * HZ);
215 while (!(volatile int) xpc_exiting) {
217 /* wait for IRQ or timeout */
218 (void) wait_event_interruptible(xpc_act_IRQ_wq,
219 (last_IRQ_count < atomic_read(&xpc_act_IRQ_rcvd) ||
220 jiffies >= xpc_hb_check_timeout ||
221 (volatile int) xpc_exiting));
223 dev_dbg(xpc_part, "woke up with %d ticks rem; %d IRQs have "
225 (int) (xpc_hb_check_timeout - jiffies),
226 atomic_read(&xpc_act_IRQ_rcvd) - last_IRQ_count);
229 /* checking of remote heartbeats is skewed by IRQ handling */
230 if (jiffies >= xpc_hb_check_timeout) {
231 dev_dbg(xpc_part, "checking remote heartbeats\n");
232 xpc_check_remote_hb();
235 * We need to periodically recheck to ensure no
236 * IPI/AMO pairs have been missed. That check
237 * must always reset xpc_hb_check_timeout.
243 new_IRQ_count = atomic_read(&xpc_act_IRQ_rcvd);
244 if (last_IRQ_count < new_IRQ_count || force_IRQ != 0) {
247 dev_dbg(xpc_part, "found an IRQ to process; will be "
248 "resetting xpc_hb_check_timeout\n");
250 last_IRQ_count += xpc_identify_act_IRQ_sender();
251 if (last_IRQ_count < new_IRQ_count) {
252 /* retry once to help avoid missing AMO */
253 (void) xpc_identify_act_IRQ_sender();
255 last_IRQ_count = new_IRQ_count;
257 xpc_hb_check_timeout = jiffies +
258 (xpc_hb_check_interval * HZ);
262 dev_dbg(xpc_part, "heartbeat checker is exiting\n");
265 /* mark this thread as inactive */
266 up(&xpc_hb_checker_exited);
272 * This thread will attempt to discover other partitions to activate
273 * based on info provided by SAL. This new thread is short lived and
274 * will exit once discovery is complete.
277 xpc_initiate_discovery(void *ignore)
279 daemonize(XPC_DISCOVERY_THREAD_NAME);
283 dev_dbg(xpc_part, "discovery thread is exiting\n");
285 /* mark this thread as inactive */
286 up(&xpc_discovery_exited);
292 * Establish first contact with the remote partititon. This involves pulling
293 * the XPC per partition variables from the remote partition and waiting for
294 * the remote partition to pull ours.
296 static enum xpc_retval
297 xpc_make_first_contact(struct xpc_partition *part)
302 while ((ret = xpc_pull_remote_vars_part(part)) != xpcSuccess) {
303 if (ret != xpcRetry) {
304 XPC_DEACTIVATE_PARTITION(part, ret);
308 dev_dbg(xpc_chan, "waiting to make first contact with "
309 "partition %d\n", XPC_PARTID(part));
311 /* wait a 1/4 of a second or so */
312 msleep_interruptible(250);
314 if (part->act_state == XPC_P_DEACTIVATING) {
319 return xpc_mark_partition_active(part);
324 * The first kthread assigned to a newly activated partition is the one
325 * created by XPC HB with which it calls xpc_partition_up(). XPC hangs on to
326 * that kthread until the partition is brought down, at which time that kthread
327 * returns back to XPC HB. (The return of that kthread will signify to XPC HB
328 * that XPC has dismantled all communication infrastructure for the associated
329 * partition.) This kthread becomes the channel manager for that partition.
331 * Each active partition has a channel manager, who, besides connecting and
332 * disconnecting channels, will ensure that each of the partition's connected
333 * channels has the required number of assigned kthreads to get the work done.
336 xpc_channel_mgr(struct xpc_partition *part)
338 while (part->act_state != XPC_P_DEACTIVATING ||
339 atomic_read(&part->nchannels_active) > 0) {
341 xpc_process_channel_activity(part);
345 * Wait until we've been requested to activate kthreads or
346 * all of the channel's message queues have been torn down or
347 * a signal is pending.
349 * The channel_mgr_requests is set to 1 after being awakened,
350 * This is done to prevent the channel mgr from making one pass
351 * through the loop for each request, since he will
352 * be servicing all the requests in one pass. The reason it's
353 * set to 1 instead of 0 is so that other kthreads will know
354 * that the channel mgr is running and won't bother trying to
357 atomic_dec(&part->channel_mgr_requests);
358 (void) wait_event_interruptible(part->channel_mgr_wq,
359 (atomic_read(&part->channel_mgr_requests) > 0 ||
360 (volatile u64) part->local_IPI_amo != 0 ||
361 ((volatile u8) part->act_state ==
362 XPC_P_DEACTIVATING &&
363 atomic_read(&part->nchannels_active) == 0)));
364 atomic_set(&part->channel_mgr_requests, 1);
366 // >>> Does it need to wakeup periodically as well? In case we
367 // >>> miscalculated the #of kthreads to wakeup or create?
373 * When XPC HB determines that a partition has come up, it will create a new
374 * kthread and that kthread will call this function to attempt to set up the
375 * basic infrastructure used for Cross Partition Communication with the newly
378 * The kthread that was created by XPC HB and which setup the XPC
379 * infrastructure will remain assigned to the partition until the partition
380 * goes down. At which time the kthread will teardown the XPC infrastructure
383 * XPC HB will put the remote partition's XPC per partition specific variables
384 * physical address into xpc_partitions[partid].remote_vars_part_pa prior to
385 * calling xpc_partition_up().
388 xpc_partition_up(struct xpc_partition *part)
390 DBUG_ON(part->channels != NULL);
392 dev_dbg(xpc_chan, "activating partition %d\n", XPC_PARTID(part));
394 if (xpc_setup_infrastructure(part) != xpcSuccess) {
399 * The kthread that XPC HB called us with will become the
400 * channel manager for this partition. It will not return
401 * back to XPC HB until the partition's XPC infrastructure
402 * has been dismantled.
405 (void) xpc_part_ref(part); /* this will always succeed */
407 if (xpc_make_first_contact(part) == xpcSuccess) {
408 xpc_channel_mgr(part);
411 xpc_part_deref(part);
413 xpc_teardown_infrastructure(part);
418 xpc_activating(void *__partid)
420 partid_t partid = (u64) __partid;
421 struct xpc_partition *part = &xpc_partitions[partid];
422 unsigned long irq_flags;
423 struct sched_param param = { sched_priority: MAX_RT_PRIO - 1 };
427 DBUG_ON(partid <= 0 || partid >= XP_MAX_PARTITIONS);
429 spin_lock_irqsave(&part->act_lock, irq_flags);
431 if (part->act_state == XPC_P_DEACTIVATING) {
432 part->act_state = XPC_P_INACTIVE;
433 spin_unlock_irqrestore(&part->act_lock, irq_flags);
434 part->remote_rp_pa = 0;
438 /* indicate the thread is activating */
439 DBUG_ON(part->act_state != XPC_P_ACTIVATION_REQ);
440 part->act_state = XPC_P_ACTIVATING;
442 XPC_SET_REASON(part, 0, 0);
443 spin_unlock_irqrestore(&part->act_lock, irq_flags);
445 dev_dbg(xpc_part, "bringing partition %d up\n", partid);
447 daemonize("xpc%02d", partid);
450 * This thread needs to run at a realtime priority to prevent a
451 * significant performance degradation.
453 ret = sched_setscheduler(current, SCHED_FIFO, ¶m);
455 dev_warn(xpc_part, "unable to set pid %d to a realtime "
456 "priority, ret=%d\n", current->pid, ret);
459 /* allow this thread and its children to run on any CPU */
460 set_cpus_allowed(current, CPU_MASK_ALL);
463 * Register the remote partition's AMOs with SAL so it can handle
464 * and cleanup errors within that address range should the remote
465 * partition go down. We don't unregister this range because it is
466 * difficult to tell when outstanding writes to the remote partition
467 * are finished and thus when it is safe to unregister. This should
468 * not result in wasted space in the SAL xp_addr_region table because
469 * we should get the same page for remote_amos_page_pa after module
470 * reloads and system reboots.
472 if (sn_register_xp_addr_region(part->remote_amos_page_pa,
474 dev_warn(xpc_part, "xpc_partition_up(%d) failed to register "
475 "xp_addr region\n", partid);
477 spin_lock_irqsave(&part->act_lock, irq_flags);
478 part->act_state = XPC_P_INACTIVE;
479 XPC_SET_REASON(part, xpcPhysAddrRegFailed, __LINE__);
480 spin_unlock_irqrestore(&part->act_lock, irq_flags);
481 part->remote_rp_pa = 0;
485 XPC_ALLOW_HB(partid, xpc_vars);
486 xpc_IPI_send_activated(part);
490 * xpc_partition_up() holds this thread and marks this partition as
491 * XPC_P_ACTIVE by calling xpc_hb_mark_active().
493 (void) xpc_partition_up(part);
495 xpc_mark_partition_inactive(part);
497 if (part->reason == xpcReactivating) {
498 /* interrupting ourselves results in activating partition */
499 xpc_IPI_send_reactivate(part);
507 xpc_activate_partition(struct xpc_partition *part)
509 partid_t partid = XPC_PARTID(part);
510 unsigned long irq_flags;
514 spin_lock_irqsave(&part->act_lock, irq_flags);
516 pid = kernel_thread(xpc_activating, (void *) ((u64) partid), 0);
518 DBUG_ON(part->act_state != XPC_P_INACTIVE);
521 part->act_state = XPC_P_ACTIVATION_REQ;
522 XPC_SET_REASON(part, xpcCloneKThread, __LINE__);
524 XPC_SET_REASON(part, xpcCloneKThreadFailed, __LINE__);
527 spin_unlock_irqrestore(&part->act_lock, irq_flags);
532 * Handle the receipt of a SGI_XPC_NOTIFY IRQ by seeing whether the specified
533 * partition actually sent it. Since SGI_XPC_NOTIFY IRQs may be shared by more
534 * than one partition, we use an AMO_t structure per partition to indicate
535 * whether a partition has sent an IPI or not. >>> If it has, then wake up the
536 * associated kthread to handle it.
538 * All SGI_XPC_NOTIFY IRQs received by XPC are the result of IPIs sent by XPC
539 * running on other partitions.
541 * Noteworthy Arguments:
543 * irq - Interrupt ReQuest number. NOT USED.
545 * dev_id - partid of IPI's potential sender.
547 * regs - processor's context before the processor entered
548 * interrupt code. NOT USED.
551 xpc_notify_IRQ_handler(int irq, void *dev_id, struct pt_regs *regs)
553 partid_t partid = (partid_t) (u64) dev_id;
554 struct xpc_partition *part = &xpc_partitions[partid];
557 DBUG_ON(partid <= 0 || partid >= XP_MAX_PARTITIONS);
559 if (xpc_part_ref(part)) {
560 xpc_check_for_channel_activity(part);
562 xpc_part_deref(part);
569 * Check to see if xpc_notify_IRQ_handler() dropped any IPIs on the floor
570 * because the write to their associated IPI amo completed after the IRQ/IPI
574 xpc_dropped_IPI_check(struct xpc_partition *part)
576 if (xpc_part_ref(part)) {
577 xpc_check_for_channel_activity(part);
579 part->dropped_IPI_timer.expires = jiffies +
580 XPC_P_DROPPED_IPI_WAIT;
581 add_timer(&part->dropped_IPI_timer);
582 xpc_part_deref(part);
588 xpc_activate_kthreads(struct xpc_channel *ch, int needed)
590 int idle = atomic_read(&ch->kthreads_idle);
591 int assigned = atomic_read(&ch->kthreads_assigned);
595 DBUG_ON(needed <= 0);
598 wakeup = (needed > idle) ? idle : needed;
601 dev_dbg(xpc_chan, "wakeup %d idle kthreads, partid=%d, "
602 "channel=%d\n", wakeup, ch->partid, ch->number);
604 /* only wakeup the requested number of kthreads */
605 wake_up_nr(&ch->idle_wq, wakeup);
612 if (needed + assigned > ch->kthreads_assigned_limit) {
613 needed = ch->kthreads_assigned_limit - assigned;
614 // >>>should never be less than 0
620 dev_dbg(xpc_chan, "create %d new kthreads, partid=%d, channel=%d\n",
621 needed, ch->partid, ch->number);
623 xpc_create_kthreads(ch, needed);
628 * This function is where XPC's kthreads wait for messages to deliver.
631 xpc_kthread_waitmsgs(struct xpc_partition *part, struct xpc_channel *ch)
634 /* deliver messages to their intended recipients */
636 while ((volatile s64) ch->w_local_GP.get <
637 (volatile s64) ch->w_remote_GP.put &&
638 !((volatile u32) ch->flags &
639 XPC_C_DISCONNECTING)) {
643 if (atomic_inc_return(&ch->kthreads_idle) >
644 ch->kthreads_idle_limit) {
645 /* too many idle kthreads on this channel */
646 atomic_dec(&ch->kthreads_idle);
650 dev_dbg(xpc_chan, "idle kthread calling "
651 "wait_event_interruptible_exclusive()\n");
653 (void) wait_event_interruptible_exclusive(ch->idle_wq,
654 ((volatile s64) ch->w_local_GP.get <
655 (volatile s64) ch->w_remote_GP.put ||
656 ((volatile u32) ch->flags &
657 XPC_C_DISCONNECTING)));
659 atomic_dec(&ch->kthreads_idle);
661 } while (!((volatile u32) ch->flags & XPC_C_DISCONNECTING));
666 xpc_daemonize_kthread(void *args)
668 partid_t partid = XPC_UNPACK_ARG1(args);
669 u16 ch_number = XPC_UNPACK_ARG2(args);
670 struct xpc_partition *part = &xpc_partitions[partid];
671 struct xpc_channel *ch;
675 daemonize("xpc%02dc%d", partid, ch_number);
677 dev_dbg(xpc_chan, "kthread starting, partid=%d, channel=%d\n",
680 ch = &part->channels[ch_number];
682 if (!(ch->flags & XPC_C_DISCONNECTING)) {
683 DBUG_ON(!(ch->flags & XPC_C_CONNECTED));
685 /* let registerer know that connection has been established */
687 if (atomic_read(&ch->kthreads_assigned) == 1) {
688 xpc_connected_callout(ch);
691 * It is possible that while the callout was being
692 * made that the remote partition sent some messages.
693 * If that is the case, we may need to activate
694 * additional kthreads to help deliver them. We only
695 * need one less than total #of messages to deliver.
697 n_needed = ch->w_remote_GP.put - ch->w_local_GP.get - 1;
699 !(ch->flags & XPC_C_DISCONNECTING)) {
700 xpc_activate_kthreads(ch, n_needed);
704 xpc_kthread_waitmsgs(part, ch);
707 if (atomic_dec_return(&ch->kthreads_assigned) == 0 &&
708 ((ch->flags & XPC_C_CONNECTCALLOUT) ||
709 (ch->reason != xpcUnregistering &&
710 ch->reason != xpcOtherUnregistering))) {
711 xpc_disconnected_callout(ch);
715 xpc_msgqueue_deref(ch);
717 dev_dbg(xpc_chan, "kthread exiting, partid=%d, channel=%d\n",
720 xpc_part_deref(part);
726 * For each partition that XPC has established communications with, there is
727 * a minimum of one kernel thread assigned to perform any operation that
728 * may potentially sleep or block (basically the callouts to the asynchronous
729 * functions registered via xpc_connect()).
731 * Additional kthreads are created and destroyed by XPC as the workload
734 * A kthread is assigned to one of the active channels that exists for a given
738 xpc_create_kthreads(struct xpc_channel *ch, int needed)
740 unsigned long irq_flags;
742 u64 args = XPC_PACK_ARGS(ch->partid, ch->number);
745 while (needed-- > 0) {
746 pid = kernel_thread(xpc_daemonize_kthread, (void *) args, 0);
748 /* the fork failed */
750 if (atomic_read(&ch->kthreads_assigned) <
751 ch->kthreads_idle_limit) {
753 * Flag this as an error only if we have an
754 * insufficient #of kthreads for the channel
757 * No xpc_msgqueue_ref() is needed here since
758 * the channel mgr is doing this.
760 spin_lock_irqsave(&ch->lock, irq_flags);
761 XPC_DISCONNECT_CHANNEL(ch, xpcLackOfResources,
763 spin_unlock_irqrestore(&ch->lock, irq_flags);
769 * The following is done on behalf of the newly created
770 * kthread. That kthread is responsible for doing the
771 * counterpart to the following before it exits.
773 (void) xpc_part_ref(&xpc_partitions[ch->partid]);
774 xpc_msgqueue_ref(ch);
775 atomic_inc(&ch->kthreads_assigned);
776 ch->kthreads_created++; // >>> temporary debug only!!!
782 xpc_disconnect_wait(int ch_number)
785 struct xpc_partition *part;
786 struct xpc_channel *ch;
789 /* now wait for all callouts to the caller's function to cease */
790 for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) {
791 part = &xpc_partitions[partid];
793 if (xpc_part_ref(part)) {
794 ch = &part->channels[ch_number];
796 // >>> how do we keep from falling into the window between our check and going
797 // >>> down and coming back up where sema is re-inited?
798 if (ch->flags & XPC_C_SETUP) {
799 (void) down(&ch->teardown_sema);
802 xpc_part_deref(part);
812 int active_part_count;
813 struct xpc_partition *part;
816 /* now it's time to eliminate our heartbeat */
817 del_timer_sync(&xpc_hb_timer);
818 xpc_vars->heartbeating_to_mask = 0;
820 /* indicate to others that our reserved page is uninitialized */
821 xpc_rsvd_page->vars_pa = 0;
824 * Ignore all incoming interrupts. Without interupts the heartbeat
825 * checker won't activate any new partitions that may come up.
827 free_irq(SGI_XPC_ACTIVATE, NULL);
830 * Cause the heartbeat checker and the discovery threads to exit.
831 * We don't want them attempting to activate new partitions as we
832 * try to deactivate the existing ones.
835 wake_up_interruptible(&xpc_act_IRQ_wq);
837 /* wait for the heartbeat checker thread to mark itself inactive */
838 down(&xpc_hb_checker_exited);
840 /* wait for the discovery thread to mark itself inactive */
841 down(&xpc_discovery_exited);
844 msleep_interruptible(300);
847 /* wait for all partitions to become inactive */
850 active_part_count = 0;
852 for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) {
853 part = &xpc_partitions[partid];
854 if (part->act_state != XPC_P_INACTIVE) {
857 XPC_DEACTIVATE_PARTITION(part, xpcUnloading);
861 if (active_part_count)
862 msleep_interruptible(300);
863 } while (active_part_count > 0);
866 /* close down protections for IPI operations */
867 xpc_restrict_IPI_ops();
870 /* clear the interface to XPC's functions */
871 xpc_clear_interface();
874 unregister_sysctl_table(xpc_sysctl);
884 struct xpc_partition *part;
888 if (!ia64_platform_is("sn2")) {
893 * xpc_remote_copy_buffer is used as a temporary buffer for bte_copy'ng
894 * both a partition's reserved page and its XPC variables. Its size was
895 * based on the size of a reserved page. So we need to ensure that the
896 * XPC variables will fit as well.
898 if (XPC_VARS_ALIGNED_SIZE > XPC_RSVD_PAGE_ALIGNED_SIZE) {
899 dev_err(xpc_part, "xpc_remote_copy_buffer is not big enough\n");
902 DBUG_ON((u64) xpc_remote_copy_buffer !=
903 L1_CACHE_ALIGN((u64) xpc_remote_copy_buffer));
905 snprintf(xpc_part->bus_id, BUS_ID_SIZE, "part");
906 snprintf(xpc_chan->bus_id, BUS_ID_SIZE, "chan");
908 xpc_sysctl = register_sysctl_table(xpc_sys_dir, 1);
911 * The first few fields of each entry of xpc_partitions[] need to
912 * be initialized now so that calls to xpc_connect() and
913 * xpc_disconnect() can be made prior to the activation of any remote
914 * partition. NOTE THAT NONE OF THE OTHER FIELDS BELONGING TO THESE
915 * ENTRIES ARE MEANINGFUL UNTIL AFTER AN ENTRY'S CORRESPONDING
916 * PARTITION HAS BEEN ACTIVATED.
918 for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) {
919 part = &xpc_partitions[partid];
921 DBUG_ON((u64) part != L1_CACHE_ALIGN((u64) part));
923 part->act_IRQ_rcvd = 0;
924 spin_lock_init(&part->act_lock);
925 part->act_state = XPC_P_INACTIVE;
926 XPC_SET_REASON(part, 0, 0);
927 part->setup_state = XPC_P_UNSET;
928 init_waitqueue_head(&part->teardown_wq);
929 atomic_set(&part->references, 0);
933 * Open up protections for IPI operations (and AMO operations on
939 * Interrupts being processed will increment this atomic variable and
940 * awaken the heartbeat thread which will process the interrupts.
942 atomic_set(&xpc_act_IRQ_rcvd, 0);
945 * This is safe to do before the xpc_hb_checker thread has started
946 * because the handler releases a wait queue. If an interrupt is
947 * received before the thread is waiting, it will not go to sleep,
948 * but rather immediately process the interrupt.
950 ret = request_irq(SGI_XPC_ACTIVATE, xpc_act_IRQ_handler, 0,
953 dev_err(xpc_part, "can't register ACTIVATE IRQ handler, "
956 xpc_restrict_IPI_ops();
959 unregister_sysctl_table(xpc_sysctl);
965 * Fill the partition reserved page with the information needed by
966 * other partitions to discover we are alive and establish initial
969 xpc_rsvd_page = xpc_rsvd_page_init();
970 if (xpc_rsvd_page == NULL) {
971 dev_err(xpc_part, "could not setup our reserved page\n");
973 free_irq(SGI_XPC_ACTIVATE, NULL);
974 xpc_restrict_IPI_ops();
977 unregister_sysctl_table(xpc_sysctl);
984 * Set the beating to other partitions into motion. This is
985 * the last requirement for other partitions' discovery to
986 * initiate communications with us.
988 init_timer(&xpc_hb_timer);
989 xpc_hb_timer.function = xpc_hb_beater;
994 * The real work-horse behind xpc. This processes incoming
995 * interrupts and monitors remote heartbeats.
997 pid = kernel_thread(xpc_hb_checker, NULL, 0);
999 dev_err(xpc_part, "failed while forking hb check thread\n");
1001 /* indicate to others that our reserved page is uninitialized */
1002 xpc_rsvd_page->vars_pa = 0;
1004 del_timer_sync(&xpc_hb_timer);
1005 free_irq(SGI_XPC_ACTIVATE, NULL);
1006 xpc_restrict_IPI_ops();
1009 unregister_sysctl_table(xpc_sysctl);
1016 * Startup a thread that will attempt to discover other partitions to
1017 * activate based on info provided by SAL. This new thread is short
1018 * lived and will exit once discovery is complete.
1020 pid = kernel_thread(xpc_initiate_discovery, NULL, 0);
1022 dev_err(xpc_part, "failed while forking discovery thread\n");
1024 /* mark this new thread as a non-starter */
1025 up(&xpc_discovery_exited);
1032 /* set the interface to point at XPC's functions */
1033 xpc_set_interface(xpc_initiate_connect, xpc_initiate_disconnect,
1034 xpc_initiate_allocate, xpc_initiate_send,
1035 xpc_initiate_send_notify, xpc_initiate_received,
1036 xpc_initiate_partid_to_nasids);
1040 module_init(xpc_init);
1048 module_exit(xpc_exit);
1051 MODULE_AUTHOR("Silicon Graphics, Inc.");
1052 MODULE_DESCRIPTION("Cross Partition Communication (XPC) support");
1053 MODULE_LICENSE("GPL");
1055 module_param(xpc_hb_interval, int, 0);
1056 MODULE_PARM_DESC(xpc_hb_interval, "Number of seconds between "
1057 "heartbeat increments.");
1059 module_param(xpc_hb_check_interval, int, 0);
1060 MODULE_PARM_DESC(xpc_hb_check_interval, "Number of seconds between "
1061 "heartbeat checks.");