xpc_main.c 35 KB

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