xpc_main.c 36 KB

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