xpc_main.c 37 KB

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