xpc_main.c 36 KB

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