xpc_main.c 37 KB

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