xpc_main.c 37 KB

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