xpc_main.c 37 KB

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