xpc_main.c 36 KB

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