xpc_main.c 37 KB

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