xpc_main.c 37 KB

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