xpc_main.c 36 KB

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