PageRenderTime 54ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/misc/sgi-xp/xpc_sn2.c

http://github.com/mirrors/linux
C | 2462 lines | 1562 code | 425 blank | 475 comment | 222 complexity | f9e52eb63bb1695cc3995a59bfeebe9d MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.0
  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) 2008-2009 Silicon Graphics, Inc. All Rights Reserved.
  7. */
  8. /*
  9. * Cross Partition Communication (XPC) sn2-based functions.
  10. *
  11. * Architecture specific implementation of common functions.
  12. *
  13. */
  14. #include <linux/delay.h>
  15. #include <linux/slab.h>
  16. #include <asm/uncached.h>
  17. #include <asm/sn/mspec.h>
  18. #include <asm/sn/sn_sal.h>
  19. #include "xpc.h"
  20. /*
  21. * Define the number of u64s required to represent all the C-brick nasids
  22. * as a bitmap. The cross-partition kernel modules deal only with
  23. * C-brick nasids, thus the need for bitmaps which don't account for
  24. * odd-numbered (non C-brick) nasids.
  25. */
  26. #define XPC_MAX_PHYSNODES_SN2 (MAX_NUMALINK_NODES / 2)
  27. #define XP_NASID_MASK_BYTES_SN2 ((XPC_MAX_PHYSNODES_SN2 + 7) / 8)
  28. #define XP_NASID_MASK_WORDS_SN2 ((XPC_MAX_PHYSNODES_SN2 + 63) / 64)
  29. /*
  30. * Memory for XPC's amo variables is allocated by the MSPEC driver. These
  31. * pages are located in the lowest granule. The lowest granule uses 4k pages
  32. * for cached references and an alternate TLB handler to never provide a
  33. * cacheable mapping for the entire region. This will prevent speculative
  34. * reading of cached copies of our lines from being issued which will cause
  35. * a PI FSB Protocol error to be generated by the SHUB. For XPC, we need 64
  36. * amo variables (based on XP_MAX_NPARTITIONS_SN2) to identify the senders of
  37. * NOTIFY IRQs, 128 amo variables (based on XP_NASID_MASK_WORDS_SN2) to identify
  38. * the senders of ACTIVATE IRQs, 1 amo variable to identify which remote
  39. * partitions (i.e., XPCs) consider themselves currently engaged with the
  40. * local XPC and 1 amo variable to request partition deactivation.
  41. */
  42. #define XPC_NOTIFY_IRQ_AMOS_SN2 0
  43. #define XPC_ACTIVATE_IRQ_AMOS_SN2 (XPC_NOTIFY_IRQ_AMOS_SN2 + \
  44. XP_MAX_NPARTITIONS_SN2)
  45. #define XPC_ENGAGED_PARTITIONS_AMO_SN2 (XPC_ACTIVATE_IRQ_AMOS_SN2 + \
  46. XP_NASID_MASK_WORDS_SN2)
  47. #define XPC_DEACTIVATE_REQUEST_AMO_SN2 (XPC_ENGAGED_PARTITIONS_AMO_SN2 + 1)
  48. /*
  49. * Buffer used to store a local copy of portions of a remote partition's
  50. * reserved page (either its header and part_nasids mask, or its vars).
  51. */
  52. static void *xpc_remote_copy_buffer_base_sn2;
  53. static char *xpc_remote_copy_buffer_sn2;
  54. static struct xpc_vars_sn2 *xpc_vars_sn2;
  55. static struct xpc_vars_part_sn2 *xpc_vars_part_sn2;
  56. static int
  57. xpc_setup_partitions_sn2(void)
  58. {
  59. /* nothing needs to be done */
  60. return 0;
  61. }
  62. static void
  63. xpc_teardown_partitions_sn2(void)
  64. {
  65. /* nothing needs to be done */
  66. }
  67. /* SH_IPI_ACCESS shub register value on startup */
  68. static u64 xpc_sh1_IPI_access_sn2;
  69. static u64 xpc_sh2_IPI_access0_sn2;
  70. static u64 xpc_sh2_IPI_access1_sn2;
  71. static u64 xpc_sh2_IPI_access2_sn2;
  72. static u64 xpc_sh2_IPI_access3_sn2;
  73. /*
  74. * Change protections to allow IPI operations.
  75. */
  76. static void
  77. xpc_allow_IPI_ops_sn2(void)
  78. {
  79. int node;
  80. int nasid;
  81. /* !!! The following should get moved into SAL. */
  82. if (is_shub2()) {
  83. xpc_sh2_IPI_access0_sn2 =
  84. (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS0));
  85. xpc_sh2_IPI_access1_sn2 =
  86. (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS1));
  87. xpc_sh2_IPI_access2_sn2 =
  88. (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS2));
  89. xpc_sh2_IPI_access3_sn2 =
  90. (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS3));
  91. for_each_online_node(node) {
  92. nasid = cnodeid_to_nasid(node);
  93. HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS0),
  94. -1UL);
  95. HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS1),
  96. -1UL);
  97. HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS2),
  98. -1UL);
  99. HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS3),
  100. -1UL);
  101. }
  102. } else {
  103. xpc_sh1_IPI_access_sn2 =
  104. (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH1_IPI_ACCESS));
  105. for_each_online_node(node) {
  106. nasid = cnodeid_to_nasid(node);
  107. HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH1_IPI_ACCESS),
  108. -1UL);
  109. }
  110. }
  111. }
  112. /*
  113. * Restrict protections to disallow IPI operations.
  114. */
  115. static void
  116. xpc_disallow_IPI_ops_sn2(void)
  117. {
  118. int node;
  119. int nasid;
  120. /* !!! The following should get moved into SAL. */
  121. if (is_shub2()) {
  122. for_each_online_node(node) {
  123. nasid = cnodeid_to_nasid(node);
  124. HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS0),
  125. xpc_sh2_IPI_access0_sn2);
  126. HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS1),
  127. xpc_sh2_IPI_access1_sn2);
  128. HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS2),
  129. xpc_sh2_IPI_access2_sn2);
  130. HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS3),
  131. xpc_sh2_IPI_access3_sn2);
  132. }
  133. } else {
  134. for_each_online_node(node) {
  135. nasid = cnodeid_to_nasid(node);
  136. HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH1_IPI_ACCESS),
  137. xpc_sh1_IPI_access_sn2);
  138. }
  139. }
  140. }
  141. /*
  142. * The following set of functions are used for the sending and receiving of
  143. * IRQs (also known as IPIs). There are two flavors of IRQs, one that is
  144. * associated with partition activity (SGI_XPC_ACTIVATE) and the other that
  145. * is associated with channel activity (SGI_XPC_NOTIFY).
  146. */
  147. static u64
  148. xpc_receive_IRQ_amo_sn2(struct amo *amo)
  149. {
  150. return FETCHOP_LOAD_OP(TO_AMO((u64)&amo->variable), FETCHOP_CLEAR);
  151. }
  152. static enum xp_retval
  153. xpc_send_IRQ_sn2(struct amo *amo, u64 flag, int nasid, int phys_cpuid,
  154. int vector)
  155. {
  156. int ret = 0;
  157. unsigned long irq_flags;
  158. local_irq_save(irq_flags);
  159. FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_OR, flag);
  160. sn_send_IPI_phys(nasid, phys_cpuid, vector, 0);
  161. /*
  162. * We must always use the nofault function regardless of whether we
  163. * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
  164. * didn't, we'd never know that the other partition is down and would
  165. * keep sending IRQs and amos to it until the heartbeat times out.
  166. */
  167. ret = xp_nofault_PIOR((u64 *)GLOBAL_MMR_ADDR(NASID_GET(&amo->variable),
  168. xp_nofault_PIOR_target));
  169. local_irq_restore(irq_flags);
  170. return (ret == 0) ? xpSuccess : xpPioReadError;
  171. }
  172. static struct amo *
  173. xpc_init_IRQ_amo_sn2(int index)
  174. {
  175. struct amo *amo = xpc_vars_sn2->amos_page + index;
  176. (void)xpc_receive_IRQ_amo_sn2(amo); /* clear amo variable */
  177. return amo;
  178. }
  179. /*
  180. * Functions associated with SGI_XPC_ACTIVATE IRQ.
  181. */
  182. /*
  183. * Notify the heartbeat check thread that an activate IRQ has been received.
  184. */
  185. static irqreturn_t
  186. xpc_handle_activate_IRQ_sn2(int irq, void *dev_id)
  187. {
  188. unsigned long irq_flags;
  189. spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  190. xpc_activate_IRQ_rcvd++;
  191. spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  192. wake_up_interruptible(&xpc_activate_IRQ_wq);
  193. return IRQ_HANDLED;
  194. }
  195. /*
  196. * Flag the appropriate amo variable and send an IRQ to the specified node.
  197. */
  198. static void
  199. xpc_send_activate_IRQ_sn2(unsigned long amos_page_pa, int from_nasid,
  200. int to_nasid, int to_phys_cpuid)
  201. {
  202. struct amo *amos = (struct amo *)__va(amos_page_pa +
  203. (XPC_ACTIVATE_IRQ_AMOS_SN2 *
  204. sizeof(struct amo)));
  205. (void)xpc_send_IRQ_sn2(&amos[BIT_WORD(from_nasid / 2)],
  206. BIT_MASK(from_nasid / 2), to_nasid,
  207. to_phys_cpuid, SGI_XPC_ACTIVATE);
  208. }
  209. static void
  210. xpc_send_local_activate_IRQ_sn2(int from_nasid)
  211. {
  212. unsigned long irq_flags;
  213. struct amo *amos = (struct amo *)__va(xpc_vars_sn2->amos_page_pa +
  214. (XPC_ACTIVATE_IRQ_AMOS_SN2 *
  215. sizeof(struct amo)));
  216. /* fake the sending and receipt of an activate IRQ from remote nasid */
  217. FETCHOP_STORE_OP(TO_AMO((u64)&amos[BIT_WORD(from_nasid / 2)].variable),
  218. FETCHOP_OR, BIT_MASK(from_nasid / 2));
  219. spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  220. xpc_activate_IRQ_rcvd++;
  221. spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  222. wake_up_interruptible(&xpc_activate_IRQ_wq);
  223. }
  224. /*
  225. * Functions associated with SGI_XPC_NOTIFY IRQ.
  226. */
  227. /*
  228. * Check to see if any chctl flags were sent from the specified partition.
  229. */
  230. static void
  231. xpc_check_for_sent_chctl_flags_sn2(struct xpc_partition *part)
  232. {
  233. union xpc_channel_ctl_flags chctl;
  234. unsigned long irq_flags;
  235. chctl.all_flags = xpc_receive_IRQ_amo_sn2(part->sn.sn2.
  236. local_chctl_amo_va);
  237. if (chctl.all_flags == 0)
  238. return;
  239. spin_lock_irqsave(&part->chctl_lock, irq_flags);
  240. part->chctl.all_flags |= chctl.all_flags;
  241. spin_unlock_irqrestore(&part->chctl_lock, irq_flags);
  242. dev_dbg(xpc_chan, "received notify IRQ from partid=%d, chctl.all_flags="
  243. "0x%llx\n", XPC_PARTID(part), chctl.all_flags);
  244. xpc_wakeup_channel_mgr(part);
  245. }
  246. /*
  247. * Handle the receipt of a SGI_XPC_NOTIFY IRQ by seeing whether the specified
  248. * partition actually sent it. Since SGI_XPC_NOTIFY IRQs may be shared by more
  249. * than one partition, we use an amo structure per partition to indicate
  250. * whether a partition has sent an IRQ or not. If it has, then wake up the
  251. * associated kthread to handle it.
  252. *
  253. * All SGI_XPC_NOTIFY IRQs received by XPC are the result of IRQs sent by XPC
  254. * running on other partitions.
  255. *
  256. * Noteworthy Arguments:
  257. *
  258. * irq - Interrupt ReQuest number. NOT USED.
  259. *
  260. * dev_id - partid of IRQ's potential sender.
  261. */
  262. static irqreturn_t
  263. xpc_handle_notify_IRQ_sn2(int irq, void *dev_id)
  264. {
  265. short partid = (short)(u64)dev_id;
  266. struct xpc_partition *part = &xpc_partitions[partid];
  267. DBUG_ON(partid < 0 || partid >= XP_MAX_NPARTITIONS_SN2);
  268. if (xpc_part_ref(part)) {
  269. xpc_check_for_sent_chctl_flags_sn2(part);
  270. xpc_part_deref(part);
  271. }
  272. return IRQ_HANDLED;
  273. }
  274. /*
  275. * Check to see if xpc_handle_notify_IRQ_sn2() dropped any IRQs on the floor
  276. * because the write to their associated amo variable completed after the IRQ
  277. * was received.
  278. */
  279. static void
  280. xpc_check_for_dropped_notify_IRQ_sn2(struct xpc_partition *part)
  281. {
  282. struct xpc_partition_sn2 *part_sn2 = &part->sn.sn2;
  283. if (xpc_part_ref(part)) {
  284. xpc_check_for_sent_chctl_flags_sn2(part);
  285. part_sn2->dropped_notify_IRQ_timer.expires = jiffies +
  286. XPC_DROPPED_NOTIFY_IRQ_WAIT_INTERVAL;
  287. add_timer(&part_sn2->dropped_notify_IRQ_timer);
  288. xpc_part_deref(part);
  289. }
  290. }
  291. /*
  292. * Send a notify IRQ to the remote partition that is associated with the
  293. * specified channel.
  294. */
  295. static void
  296. xpc_send_notify_IRQ_sn2(struct xpc_channel *ch, u8 chctl_flag,
  297. char *chctl_flag_string, unsigned long *irq_flags)
  298. {
  299. struct xpc_partition *part = &xpc_partitions[ch->partid];
  300. struct xpc_partition_sn2 *part_sn2 = &part->sn.sn2;
  301. union xpc_channel_ctl_flags chctl = { 0 };
  302. enum xp_retval ret;
  303. if (likely(part->act_state != XPC_P_AS_DEACTIVATING)) {
  304. chctl.flags[ch->number] = chctl_flag;
  305. ret = xpc_send_IRQ_sn2(part_sn2->remote_chctl_amo_va,
  306. chctl.all_flags,
  307. part_sn2->notify_IRQ_nasid,
  308. part_sn2->notify_IRQ_phys_cpuid,
  309. SGI_XPC_NOTIFY);
  310. dev_dbg(xpc_chan, "%s sent to partid=%d, channel=%d, ret=%d\n",
  311. chctl_flag_string, ch->partid, ch->number, ret);
  312. if (unlikely(ret != xpSuccess)) {
  313. if (irq_flags != NULL)
  314. spin_unlock_irqrestore(&ch->lock, *irq_flags);
  315. XPC_DEACTIVATE_PARTITION(part, ret);
  316. if (irq_flags != NULL)
  317. spin_lock_irqsave(&ch->lock, *irq_flags);
  318. }
  319. }
  320. }
  321. #define XPC_SEND_NOTIFY_IRQ_SN2(_ch, _ipi_f, _irq_f) \
  322. xpc_send_notify_IRQ_sn2(_ch, _ipi_f, #_ipi_f, _irq_f)
  323. /*
  324. * Make it look like the remote partition, which is associated with the
  325. * specified channel, sent us a notify IRQ. This faked IRQ will be handled
  326. * by xpc_check_for_dropped_notify_IRQ_sn2().
  327. */
  328. static void
  329. xpc_send_local_notify_IRQ_sn2(struct xpc_channel *ch, u8 chctl_flag,
  330. char *chctl_flag_string)
  331. {
  332. struct xpc_partition *part = &xpc_partitions[ch->partid];
  333. union xpc_channel_ctl_flags chctl = { 0 };
  334. chctl.flags[ch->number] = chctl_flag;
  335. FETCHOP_STORE_OP(TO_AMO((u64)&part->sn.sn2.local_chctl_amo_va->
  336. variable), FETCHOP_OR, chctl.all_flags);
  337. dev_dbg(xpc_chan, "%s sent local from partid=%d, channel=%d\n",
  338. chctl_flag_string, ch->partid, ch->number);
  339. }
  340. #define XPC_SEND_LOCAL_NOTIFY_IRQ_SN2(_ch, _ipi_f) \
  341. xpc_send_local_notify_IRQ_sn2(_ch, _ipi_f, #_ipi_f)
  342. static void
  343. xpc_send_chctl_closerequest_sn2(struct xpc_channel *ch,
  344. unsigned long *irq_flags)
  345. {
  346. struct xpc_openclose_args *args = ch->sn.sn2.local_openclose_args;
  347. args->reason = ch->reason;
  348. XPC_SEND_NOTIFY_IRQ_SN2(ch, XPC_CHCTL_CLOSEREQUEST, irq_flags);
  349. }
  350. static void
  351. xpc_send_chctl_closereply_sn2(struct xpc_channel *ch, unsigned long *irq_flags)
  352. {
  353. XPC_SEND_NOTIFY_IRQ_SN2(ch, XPC_CHCTL_CLOSEREPLY, irq_flags);
  354. }
  355. static void
  356. xpc_send_chctl_openrequest_sn2(struct xpc_channel *ch, unsigned long *irq_flags)
  357. {
  358. struct xpc_openclose_args *args = ch->sn.sn2.local_openclose_args;
  359. args->entry_size = ch->entry_size;
  360. args->local_nentries = ch->local_nentries;
  361. XPC_SEND_NOTIFY_IRQ_SN2(ch, XPC_CHCTL_OPENREQUEST, irq_flags);
  362. }
  363. static void
  364. xpc_send_chctl_openreply_sn2(struct xpc_channel *ch, unsigned long *irq_flags)
  365. {
  366. struct xpc_openclose_args *args = ch->sn.sn2.local_openclose_args;
  367. args->remote_nentries = ch->remote_nentries;
  368. args->local_nentries = ch->local_nentries;
  369. args->local_msgqueue_pa = xp_pa(ch->sn.sn2.local_msgqueue);
  370. XPC_SEND_NOTIFY_IRQ_SN2(ch, XPC_CHCTL_OPENREPLY, irq_flags);
  371. }
  372. static void
  373. xpc_send_chctl_opencomplete_sn2(struct xpc_channel *ch,
  374. unsigned long *irq_flags)
  375. {
  376. XPC_SEND_NOTIFY_IRQ_SN2(ch, XPC_CHCTL_OPENCOMPLETE, irq_flags);
  377. }
  378. static void
  379. xpc_send_chctl_msgrequest_sn2(struct xpc_channel *ch)
  380. {
  381. XPC_SEND_NOTIFY_IRQ_SN2(ch, XPC_CHCTL_MSGREQUEST, NULL);
  382. }
  383. static void
  384. xpc_send_chctl_local_msgrequest_sn2(struct xpc_channel *ch)
  385. {
  386. XPC_SEND_LOCAL_NOTIFY_IRQ_SN2(ch, XPC_CHCTL_MSGREQUEST);
  387. }
  388. static enum xp_retval
  389. xpc_save_remote_msgqueue_pa_sn2(struct xpc_channel *ch,
  390. unsigned long msgqueue_pa)
  391. {
  392. ch->sn.sn2.remote_msgqueue_pa = msgqueue_pa;
  393. return xpSuccess;
  394. }
  395. /*
  396. * This next set of functions are used to keep track of when a partition is
  397. * potentially engaged in accessing memory belonging to another partition.
  398. */
  399. static void
  400. xpc_indicate_partition_engaged_sn2(struct xpc_partition *part)
  401. {
  402. unsigned long irq_flags;
  403. struct amo *amo = (struct amo *)__va(part->sn.sn2.remote_amos_page_pa +
  404. (XPC_ENGAGED_PARTITIONS_AMO_SN2 *
  405. sizeof(struct amo)));
  406. local_irq_save(irq_flags);
  407. /* set bit corresponding to our partid in remote partition's amo */
  408. FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_OR,
  409. BIT(sn_partition_id));
  410. /*
  411. * We must always use the nofault function regardless of whether we
  412. * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
  413. * didn't, we'd never know that the other partition is down and would
  414. * keep sending IRQs and amos to it until the heartbeat times out.
  415. */
  416. (void)xp_nofault_PIOR((u64 *)GLOBAL_MMR_ADDR(NASID_GET(&amo->
  417. variable),
  418. xp_nofault_PIOR_target));
  419. local_irq_restore(irq_flags);
  420. }
  421. static void
  422. xpc_indicate_partition_disengaged_sn2(struct xpc_partition *part)
  423. {
  424. struct xpc_partition_sn2 *part_sn2 = &part->sn.sn2;
  425. unsigned long irq_flags;
  426. struct amo *amo = (struct amo *)__va(part_sn2->remote_amos_page_pa +
  427. (XPC_ENGAGED_PARTITIONS_AMO_SN2 *
  428. sizeof(struct amo)));
  429. local_irq_save(irq_flags);
  430. /* clear bit corresponding to our partid in remote partition's amo */
  431. FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_AND,
  432. ~BIT(sn_partition_id));
  433. /*
  434. * We must always use the nofault function regardless of whether we
  435. * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
  436. * didn't, we'd never know that the other partition is down and would
  437. * keep sending IRQs and amos to it until the heartbeat times out.
  438. */
  439. (void)xp_nofault_PIOR((u64 *)GLOBAL_MMR_ADDR(NASID_GET(&amo->
  440. variable),
  441. xp_nofault_PIOR_target));
  442. local_irq_restore(irq_flags);
  443. /*
  444. * Send activate IRQ to get other side to see that we've cleared our
  445. * bit in their engaged partitions amo.
  446. */
  447. xpc_send_activate_IRQ_sn2(part_sn2->remote_amos_page_pa,
  448. cnodeid_to_nasid(0),
  449. part_sn2->activate_IRQ_nasid,
  450. part_sn2->activate_IRQ_phys_cpuid);
  451. }
  452. static void
  453. xpc_assume_partition_disengaged_sn2(short partid)
  454. {
  455. struct amo *amo = xpc_vars_sn2->amos_page +
  456. XPC_ENGAGED_PARTITIONS_AMO_SN2;
  457. /* clear bit(s) based on partid mask in our partition's amo */
  458. FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_AND,
  459. ~BIT(partid));
  460. }
  461. static int
  462. xpc_partition_engaged_sn2(short partid)
  463. {
  464. struct amo *amo = xpc_vars_sn2->amos_page +
  465. XPC_ENGAGED_PARTITIONS_AMO_SN2;
  466. /* our partition's amo variable ANDed with partid mask */
  467. return (FETCHOP_LOAD_OP(TO_AMO((u64)&amo->variable), FETCHOP_LOAD) &
  468. BIT(partid)) != 0;
  469. }
  470. static int
  471. xpc_any_partition_engaged_sn2(void)
  472. {
  473. struct amo *amo = xpc_vars_sn2->amos_page +
  474. XPC_ENGAGED_PARTITIONS_AMO_SN2;
  475. /* our partition's amo variable */
  476. return FETCHOP_LOAD_OP(TO_AMO((u64)&amo->variable), FETCHOP_LOAD) != 0;
  477. }
  478. /* original protection values for each node */
  479. static u64 xpc_prot_vec_sn2[MAX_NUMNODES];
  480. /*
  481. * Change protections to allow amo operations on non-Shub 1.1 systems.
  482. */
  483. static enum xp_retval
  484. xpc_allow_amo_ops_sn2(struct amo *amos_page)
  485. {
  486. enum xp_retval ret = xpSuccess;
  487. /*
  488. * On SHUB 1.1, we cannot call sn_change_memprotect() since the BIST
  489. * collides with memory operations. On those systems we call
  490. * xpc_allow_amo_ops_shub_wars_1_1_sn2() instead.
  491. */
  492. if (!enable_shub_wars_1_1())
  493. ret = xp_expand_memprotect(ia64_tpa((u64)amos_page), PAGE_SIZE);
  494. return ret;
  495. }
  496. /*
  497. * Change protections to allow amo operations on Shub 1.1 systems.
  498. */
  499. static void
  500. xpc_allow_amo_ops_shub_wars_1_1_sn2(void)
  501. {
  502. int node;
  503. int nasid;
  504. if (!enable_shub_wars_1_1())
  505. return;
  506. for_each_online_node(node) {
  507. nasid = cnodeid_to_nasid(node);
  508. /* save current protection values */
  509. xpc_prot_vec_sn2[node] =
  510. (u64)HUB_L((u64 *)GLOBAL_MMR_ADDR(nasid,
  511. SH1_MD_DQLP_MMR_DIR_PRIVEC0));
  512. /* open up everything */
  513. HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid,
  514. SH1_MD_DQLP_MMR_DIR_PRIVEC0),
  515. -1UL);
  516. HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid,
  517. SH1_MD_DQRP_MMR_DIR_PRIVEC0),
  518. -1UL);
  519. }
  520. }
  521. static enum xp_retval
  522. xpc_get_partition_rsvd_page_pa_sn2(void *buf, u64 *cookie, unsigned long *rp_pa,
  523. size_t *len)
  524. {
  525. s64 status;
  526. enum xp_retval ret;
  527. status = sn_partition_reserved_page_pa((u64)buf, cookie,
  528. (u64 *)rp_pa, (u64 *)len);
  529. if (status == SALRET_OK)
  530. ret = xpSuccess;
  531. else if (status == SALRET_MORE_PASSES)
  532. ret = xpNeedMoreInfo;
  533. else
  534. ret = xpSalError;
  535. return ret;
  536. }
  537. static int
  538. xpc_setup_rsvd_page_sn2(struct xpc_rsvd_page *rp)
  539. {
  540. struct amo *amos_page;
  541. int i;
  542. int ret;
  543. xpc_vars_sn2 = XPC_RP_VARS(rp);
  544. rp->sn.sn2.vars_pa = xp_pa(xpc_vars_sn2);
  545. /* vars_part array follows immediately after vars */
  546. xpc_vars_part_sn2 = (struct xpc_vars_part_sn2 *)((u8 *)XPC_RP_VARS(rp) +
  547. XPC_RP_VARS_SIZE);
  548. /*
  549. * Before clearing xpc_vars_sn2, see if a page of amos had been
  550. * previously allocated. If not we'll need to allocate one and set
  551. * permissions so that cross-partition amos are allowed.
  552. *
  553. * The allocated amo page needs MCA reporting to remain disabled after
  554. * XPC has unloaded. To make this work, we keep a copy of the pointer
  555. * to this page (i.e., amos_page) in the struct xpc_vars_sn2 structure,
  556. * which is pointed to by the reserved page, and re-use that saved copy
  557. * on subsequent loads of XPC. This amo page is never freed, and its
  558. * memory protections are never restricted.
  559. */
  560. amos_page = xpc_vars_sn2->amos_page;
  561. if (amos_page == NULL) {
  562. amos_page = (struct amo *)TO_AMO(uncached_alloc_page(0, 1));
  563. if (amos_page == NULL) {
  564. dev_err(xpc_part, "can't allocate page of amos\n");
  565. return -ENOMEM;
  566. }
  567. /*
  568. * Open up amo-R/W to cpu. This is done on Shub 1.1 systems
  569. * when xpc_allow_amo_ops_shub_wars_1_1_sn2() is called.
  570. */
  571. ret = xpc_allow_amo_ops_sn2(amos_page);
  572. if (ret != xpSuccess) {
  573. dev_err(xpc_part, "can't allow amo operations\n");
  574. uncached_free_page(__IA64_UNCACHED_OFFSET |
  575. TO_PHYS((u64)amos_page), 1);
  576. return -EPERM;
  577. }
  578. }
  579. /* clear xpc_vars_sn2 */
  580. memset(xpc_vars_sn2, 0, sizeof(struct xpc_vars_sn2));
  581. xpc_vars_sn2->version = XPC_V_VERSION;
  582. xpc_vars_sn2->activate_IRQ_nasid = cpuid_to_nasid(0);
  583. xpc_vars_sn2->activate_IRQ_phys_cpuid = cpu_physical_id(0);
  584. xpc_vars_sn2->vars_part_pa = xp_pa(xpc_vars_part_sn2);
  585. xpc_vars_sn2->amos_page_pa = ia64_tpa((u64)amos_page);
  586. xpc_vars_sn2->amos_page = amos_page; /* save for next load of XPC */
  587. /* clear xpc_vars_part_sn2 */
  588. memset((u64 *)xpc_vars_part_sn2, 0, sizeof(struct xpc_vars_part_sn2) *
  589. XP_MAX_NPARTITIONS_SN2);
  590. /* initialize the activate IRQ related amo variables */
  591. for (i = 0; i < xpc_nasid_mask_nlongs; i++)
  592. (void)xpc_init_IRQ_amo_sn2(XPC_ACTIVATE_IRQ_AMOS_SN2 + i);
  593. /* initialize the engaged remote partitions related amo variables */
  594. (void)xpc_init_IRQ_amo_sn2(XPC_ENGAGED_PARTITIONS_AMO_SN2);
  595. (void)xpc_init_IRQ_amo_sn2(XPC_DEACTIVATE_REQUEST_AMO_SN2);
  596. return 0;
  597. }
  598. static int
  599. xpc_hb_allowed_sn2(short partid, void *heartbeating_to_mask)
  600. {
  601. return test_bit(partid, heartbeating_to_mask);
  602. }
  603. static void
  604. xpc_allow_hb_sn2(short partid)
  605. {
  606. DBUG_ON(xpc_vars_sn2 == NULL);
  607. set_bit(partid, xpc_vars_sn2->heartbeating_to_mask);
  608. }
  609. static void
  610. xpc_disallow_hb_sn2(short partid)
  611. {
  612. DBUG_ON(xpc_vars_sn2 == NULL);
  613. clear_bit(partid, xpc_vars_sn2->heartbeating_to_mask);
  614. }
  615. static void
  616. xpc_disallow_all_hbs_sn2(void)
  617. {
  618. DBUG_ON(xpc_vars_sn2 == NULL);
  619. bitmap_zero(xpc_vars_sn2->heartbeating_to_mask, xp_max_npartitions);
  620. }
  621. static void
  622. xpc_increment_heartbeat_sn2(void)
  623. {
  624. xpc_vars_sn2->heartbeat++;
  625. }
  626. static void
  627. xpc_offline_heartbeat_sn2(void)
  628. {
  629. xpc_increment_heartbeat_sn2();
  630. xpc_vars_sn2->heartbeat_offline = 1;
  631. }
  632. static void
  633. xpc_online_heartbeat_sn2(void)
  634. {
  635. xpc_increment_heartbeat_sn2();
  636. xpc_vars_sn2->heartbeat_offline = 0;
  637. }
  638. static void
  639. xpc_heartbeat_init_sn2(void)
  640. {
  641. DBUG_ON(xpc_vars_sn2 == NULL);
  642. bitmap_zero(xpc_vars_sn2->heartbeating_to_mask, XP_MAX_NPARTITIONS_SN2);
  643. xpc_online_heartbeat_sn2();
  644. }
  645. static void
  646. xpc_heartbeat_exit_sn2(void)
  647. {
  648. xpc_offline_heartbeat_sn2();
  649. }
  650. static enum xp_retval
  651. xpc_get_remote_heartbeat_sn2(struct xpc_partition *part)
  652. {
  653. struct xpc_vars_sn2 *remote_vars;
  654. enum xp_retval ret;
  655. remote_vars = (struct xpc_vars_sn2 *)xpc_remote_copy_buffer_sn2;
  656. /* pull the remote vars structure that contains the heartbeat */
  657. ret = xp_remote_memcpy(xp_pa(remote_vars),
  658. part->sn.sn2.remote_vars_pa,
  659. XPC_RP_VARS_SIZE);
  660. if (ret != xpSuccess)
  661. return ret;
  662. dev_dbg(xpc_part, "partid=%d, heartbeat=%lld, last_heartbeat=%lld, "
  663. "heartbeat_offline=%lld, HB_mask[0]=0x%lx\n", XPC_PARTID(part),
  664. remote_vars->heartbeat, part->last_heartbeat,
  665. remote_vars->heartbeat_offline,
  666. remote_vars->heartbeating_to_mask[0]);
  667. if ((remote_vars->heartbeat == part->last_heartbeat &&
  668. !remote_vars->heartbeat_offline) ||
  669. !xpc_hb_allowed_sn2(sn_partition_id,
  670. remote_vars->heartbeating_to_mask)) {
  671. ret = xpNoHeartbeat;
  672. } else {
  673. part->last_heartbeat = remote_vars->heartbeat;
  674. }
  675. return ret;
  676. }
  677. /*
  678. * Get a copy of the remote partition's XPC variables from the reserved page.
  679. *
  680. * remote_vars points to a buffer that is cacheline aligned for BTE copies and
  681. * assumed to be of size XPC_RP_VARS_SIZE.
  682. */
  683. static enum xp_retval
  684. xpc_get_remote_vars_sn2(unsigned long remote_vars_pa,
  685. struct xpc_vars_sn2 *remote_vars)
  686. {
  687. enum xp_retval ret;
  688. if (remote_vars_pa == 0)
  689. return xpVarsNotSet;
  690. /* pull over the cross partition variables */
  691. ret = xp_remote_memcpy(xp_pa(remote_vars), remote_vars_pa,
  692. XPC_RP_VARS_SIZE);
  693. if (ret != xpSuccess)
  694. return ret;
  695. if (XPC_VERSION_MAJOR(remote_vars->version) !=
  696. XPC_VERSION_MAJOR(XPC_V_VERSION)) {
  697. return xpBadVersion;
  698. }
  699. return xpSuccess;
  700. }
  701. static void
  702. xpc_request_partition_activation_sn2(struct xpc_rsvd_page *remote_rp,
  703. unsigned long remote_rp_pa, int nasid)
  704. {
  705. xpc_send_local_activate_IRQ_sn2(nasid);
  706. }
  707. static void
  708. xpc_request_partition_reactivation_sn2(struct xpc_partition *part)
  709. {
  710. xpc_send_local_activate_IRQ_sn2(part->sn.sn2.activate_IRQ_nasid);
  711. }
  712. static void
  713. xpc_request_partition_deactivation_sn2(struct xpc_partition *part)
  714. {
  715. struct xpc_partition_sn2 *part_sn2 = &part->sn.sn2;
  716. unsigned long irq_flags;
  717. struct amo *amo = (struct amo *)__va(part_sn2->remote_amos_page_pa +
  718. (XPC_DEACTIVATE_REQUEST_AMO_SN2 *
  719. sizeof(struct amo)));
  720. local_irq_save(irq_flags);
  721. /* set bit corresponding to our partid in remote partition's amo */
  722. FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_OR,
  723. BIT(sn_partition_id));
  724. /*
  725. * We must always use the nofault function regardless of whether we
  726. * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
  727. * didn't, we'd never know that the other partition is down and would
  728. * keep sending IRQs and amos to it until the heartbeat times out.
  729. */
  730. (void)xp_nofault_PIOR((u64 *)GLOBAL_MMR_ADDR(NASID_GET(&amo->
  731. variable),
  732. xp_nofault_PIOR_target));
  733. local_irq_restore(irq_flags);
  734. /*
  735. * Send activate IRQ to get other side to see that we've set our
  736. * bit in their deactivate request amo.
  737. */
  738. xpc_send_activate_IRQ_sn2(part_sn2->remote_amos_page_pa,
  739. cnodeid_to_nasid(0),
  740. part_sn2->activate_IRQ_nasid,
  741. part_sn2->activate_IRQ_phys_cpuid);
  742. }
  743. static void
  744. xpc_cancel_partition_deactivation_request_sn2(struct xpc_partition *part)
  745. {
  746. unsigned long irq_flags;
  747. struct amo *amo = (struct amo *)__va(part->sn.sn2.remote_amos_page_pa +
  748. (XPC_DEACTIVATE_REQUEST_AMO_SN2 *
  749. sizeof(struct amo)));
  750. local_irq_save(irq_flags);
  751. /* clear bit corresponding to our partid in remote partition's amo */
  752. FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_AND,
  753. ~BIT(sn_partition_id));
  754. /*
  755. * We must always use the nofault function regardless of whether we
  756. * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
  757. * didn't, we'd never know that the other partition is down and would
  758. * keep sending IRQs and amos to it until the heartbeat times out.
  759. */
  760. (void)xp_nofault_PIOR((u64 *)GLOBAL_MMR_ADDR(NASID_GET(&amo->
  761. variable),
  762. xp_nofault_PIOR_target));
  763. local_irq_restore(irq_flags);
  764. }
  765. static int
  766. xpc_partition_deactivation_requested_sn2(short partid)
  767. {
  768. struct amo *amo = xpc_vars_sn2->amos_page +
  769. XPC_DEACTIVATE_REQUEST_AMO_SN2;
  770. /* our partition's amo variable ANDed with partid mask */
  771. return (FETCHOP_LOAD_OP(TO_AMO((u64)&amo->variable), FETCHOP_LOAD) &
  772. BIT(partid)) != 0;
  773. }
  774. /*
  775. * Update the remote partition's info.
  776. */
  777. static void
  778. xpc_update_partition_info_sn2(struct xpc_partition *part, u8 remote_rp_version,
  779. unsigned long *remote_rp_ts_jiffies,
  780. unsigned long remote_rp_pa,
  781. unsigned long remote_vars_pa,
  782. struct xpc_vars_sn2 *remote_vars)
  783. {
  784. struct xpc_partition_sn2 *part_sn2 = &part->sn.sn2;
  785. part->remote_rp_version = remote_rp_version;
  786. dev_dbg(xpc_part, " remote_rp_version = 0x%016x\n",
  787. part->remote_rp_version);
  788. part->remote_rp_ts_jiffies = *remote_rp_ts_jiffies;
  789. dev_dbg(xpc_part, " remote_rp_ts_jiffies = 0x%016lx\n",
  790. part->remote_rp_ts_jiffies);
  791. part->remote_rp_pa = remote_rp_pa;
  792. dev_dbg(xpc_part, " remote_rp_pa = 0x%016lx\n", part->remote_rp_pa);
  793. part_sn2->remote_vars_pa = remote_vars_pa;
  794. dev_dbg(xpc_part, " remote_vars_pa = 0x%016lx\n",
  795. part_sn2->remote_vars_pa);
  796. part->last_heartbeat = remote_vars->heartbeat - 1;
  797. dev_dbg(xpc_part, " last_heartbeat = 0x%016llx\n",
  798. part->last_heartbeat);
  799. part_sn2->remote_vars_part_pa = remote_vars->vars_part_pa;
  800. dev_dbg(xpc_part, " remote_vars_part_pa = 0x%016lx\n",
  801. part_sn2->remote_vars_part_pa);
  802. part_sn2->activate_IRQ_nasid = remote_vars->activate_IRQ_nasid;
  803. dev_dbg(xpc_part, " activate_IRQ_nasid = 0x%x\n",
  804. part_sn2->activate_IRQ_nasid);
  805. part_sn2->activate_IRQ_phys_cpuid =
  806. remote_vars->activate_IRQ_phys_cpuid;
  807. dev_dbg(xpc_part, " activate_IRQ_phys_cpuid = 0x%x\n",
  808. part_sn2->activate_IRQ_phys_cpuid);
  809. part_sn2->remote_amos_page_pa = remote_vars->amos_page_pa;
  810. dev_dbg(xpc_part, " remote_amos_page_pa = 0x%lx\n",
  811. part_sn2->remote_amos_page_pa);
  812. part_sn2->remote_vars_version = remote_vars->version;
  813. dev_dbg(xpc_part, " remote_vars_version = 0x%x\n",
  814. part_sn2->remote_vars_version);
  815. }
  816. /*
  817. * Prior code has determined the nasid which generated a activate IRQ.
  818. * Inspect that nasid to determine if its partition needs to be activated
  819. * or deactivated.
  820. *
  821. * A partition is considered "awaiting activation" if our partition
  822. * flags indicate it is not active and it has a heartbeat. A
  823. * partition is considered "awaiting deactivation" if our partition
  824. * flags indicate it is active but it has no heartbeat or it is not
  825. * sending its heartbeat to us.
  826. *
  827. * To determine the heartbeat, the remote nasid must have a properly
  828. * initialized reserved page.
  829. */
  830. static void
  831. xpc_identify_activate_IRQ_req_sn2(int nasid)
  832. {
  833. struct xpc_rsvd_page *remote_rp;
  834. struct xpc_vars_sn2 *remote_vars;
  835. unsigned long remote_rp_pa;
  836. unsigned long remote_vars_pa;
  837. int remote_rp_version;
  838. int reactivate = 0;
  839. unsigned long remote_rp_ts_jiffies = 0;
  840. short partid;
  841. struct xpc_partition *part;
  842. struct xpc_partition_sn2 *part_sn2;
  843. enum xp_retval ret;
  844. /* pull over the reserved page structure */
  845. remote_rp = (struct xpc_rsvd_page *)xpc_remote_copy_buffer_sn2;
  846. ret = xpc_get_remote_rp(nasid, NULL, remote_rp, &remote_rp_pa);
  847. if (ret != xpSuccess) {
  848. dev_warn(xpc_part, "unable to get reserved page from nasid %d, "
  849. "which sent interrupt, reason=%d\n", nasid, ret);
  850. return;
  851. }
  852. remote_vars_pa = remote_rp->sn.sn2.vars_pa;
  853. remote_rp_version = remote_rp->version;
  854. remote_rp_ts_jiffies = remote_rp->ts_jiffies;
  855. partid = remote_rp->SAL_partid;
  856. part = &xpc_partitions[partid];
  857. part_sn2 = &part->sn.sn2;
  858. /* pull over the cross partition variables */
  859. remote_vars = (struct xpc_vars_sn2 *)xpc_remote_copy_buffer_sn2;
  860. ret = xpc_get_remote_vars_sn2(remote_vars_pa, remote_vars);
  861. if (ret != xpSuccess) {
  862. dev_warn(xpc_part, "unable to get XPC variables from nasid %d, "
  863. "which sent interrupt, reason=%d\n", nasid, ret);
  864. XPC_DEACTIVATE_PARTITION(part, ret);
  865. return;
  866. }
  867. part->activate_IRQ_rcvd++;
  868. dev_dbg(xpc_part, "partid for nasid %d is %d; IRQs = %d; HB = "
  869. "%lld:0x%lx\n", (int)nasid, (int)partid,
  870. part->activate_IRQ_rcvd,
  871. remote_vars->heartbeat, remote_vars->heartbeating_to_mask[0]);
  872. if (xpc_partition_disengaged(part) &&
  873. part->act_state == XPC_P_AS_INACTIVE) {
  874. xpc_update_partition_info_sn2(part, remote_rp_version,
  875. &remote_rp_ts_jiffies,
  876. remote_rp_pa, remote_vars_pa,
  877. remote_vars);
  878. if (xpc_partition_deactivation_requested_sn2(partid)) {
  879. /*
  880. * Other side is waiting on us to deactivate even though
  881. * we already have.
  882. */
  883. return;
  884. }
  885. xpc_activate_partition(part);
  886. return;
  887. }
  888. DBUG_ON(part->remote_rp_version == 0);
  889. DBUG_ON(part_sn2->remote_vars_version == 0);
  890. if (remote_rp_ts_jiffies != part->remote_rp_ts_jiffies) {
  891. /* the other side rebooted */
  892. DBUG_ON(xpc_partition_engaged_sn2(partid));
  893. DBUG_ON(xpc_partition_deactivation_requested_sn2(partid));
  894. xpc_update_partition_info_sn2(part, remote_rp_version,
  895. &remote_rp_ts_jiffies,
  896. remote_rp_pa, remote_vars_pa,
  897. remote_vars);
  898. reactivate = 1;
  899. }
  900. if (part->disengage_timeout > 0 && !xpc_partition_disengaged(part)) {
  901. /* still waiting on other side to disengage from us */
  902. return;
  903. }
  904. if (reactivate)
  905. XPC_DEACTIVATE_PARTITION(part, xpReactivating);
  906. else if (xpc_partition_deactivation_requested_sn2(partid))
  907. XPC_DEACTIVATE_PARTITION(part, xpOtherGoingDown);
  908. }
  909. /*
  910. * Loop through the activation amo variables and process any bits
  911. * which are set. Each bit indicates a nasid sending a partition
  912. * activation or deactivation request.
  913. *
  914. * Return #of IRQs detected.
  915. */
  916. int
  917. xpc_identify_activate_IRQ_sender_sn2(void)
  918. {
  919. int l;
  920. int b;
  921. unsigned long nasid_mask_long;
  922. u64 nasid; /* remote nasid */
  923. int n_IRQs_detected = 0;
  924. struct amo *act_amos;
  925. act_amos = xpc_vars_sn2->amos_page + XPC_ACTIVATE_IRQ_AMOS_SN2;
  926. /* scan through activate amo variables looking for non-zero entries */
  927. for (l = 0; l < xpc_nasid_mask_nlongs; l++) {
  928. if (xpc_exiting)
  929. break;
  930. nasid_mask_long = xpc_receive_IRQ_amo_sn2(&act_amos[l]);
  931. b = find_first_bit(&nasid_mask_long, BITS_PER_LONG);
  932. if (b >= BITS_PER_LONG) {
  933. /* no IRQs from nasids in this amo variable */
  934. continue;
  935. }
  936. dev_dbg(xpc_part, "amo[%d] gave back 0x%lx\n", l,
  937. nasid_mask_long);
  938. /*
  939. * If this nasid has been added to the machine since
  940. * our partition was reset, this will retain the
  941. * remote nasid in our reserved pages machine mask.
  942. * This is used in the event of module reload.
  943. */
  944. xpc_mach_nasids[l] |= nasid_mask_long;
  945. /* locate the nasid(s) which sent interrupts */
  946. do {
  947. n_IRQs_detected++;
  948. nasid = (l * BITS_PER_LONG + b) * 2;
  949. dev_dbg(xpc_part, "interrupt from nasid %lld\n", nasid);
  950. xpc_identify_activate_IRQ_req_sn2(nasid);
  951. b = find_next_bit(&nasid_mask_long, BITS_PER_LONG,
  952. b + 1);
  953. } while (b < BITS_PER_LONG);
  954. }
  955. return n_IRQs_detected;
  956. }
  957. static void
  958. xpc_process_activate_IRQ_rcvd_sn2(void)
  959. {
  960. unsigned long irq_flags;
  961. int n_IRQs_expected;
  962. int n_IRQs_detected;
  963. spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  964. n_IRQs_expected = xpc_activate_IRQ_rcvd;
  965. xpc_activate_IRQ_rcvd = 0;
  966. spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  967. n_IRQs_detected = xpc_identify_activate_IRQ_sender_sn2();
  968. if (n_IRQs_detected < n_IRQs_expected) {
  969. /* retry once to help avoid missing amo */
  970. (void)xpc_identify_activate_IRQ_sender_sn2();
  971. }
  972. }
  973. /*
  974. * Setup the channel structures that are sn2 specific.
  975. */
  976. static enum xp_retval
  977. xpc_setup_ch_structures_sn2(struct xpc_partition *part)
  978. {
  979. struct xpc_partition_sn2 *part_sn2 = &part->sn.sn2;
  980. struct xpc_channel_sn2 *ch_sn2;
  981. enum xp_retval retval;
  982. int ret;
  983. int cpuid;
  984. int ch_number;
  985. struct timer_list *timer;
  986. short partid = XPC_PARTID(part);
  987. /* allocate all the required GET/PUT values */
  988. part_sn2->local_GPs =
  989. xpc_kzalloc_cacheline_aligned(XPC_GP_SIZE, GFP_KERNEL,
  990. &part_sn2->local_GPs_base);
  991. if (part_sn2->local_GPs == NULL) {
  992. dev_err(xpc_chan, "can't get memory for local get/put "
  993. "values\n");
  994. return xpNoMemory;
  995. }
  996. part_sn2->remote_GPs =
  997. xpc_kzalloc_cacheline_aligned(XPC_GP_SIZE, GFP_KERNEL,
  998. &part_sn2->remote_GPs_base);
  999. if (part_sn2->remote_GPs == NULL) {
  1000. dev_err(xpc_chan, "can't get memory for remote get/put "
  1001. "values\n");
  1002. retval = xpNoMemory;
  1003. goto out_1;
  1004. }
  1005. part_sn2->remote_GPs_pa = 0;
  1006. /* allocate all the required open and close args */
  1007. part_sn2->local_openclose_args =
  1008. xpc_kzalloc_cacheline_aligned(XPC_OPENCLOSE_ARGS_SIZE,
  1009. GFP_KERNEL, &part_sn2->
  1010. local_openclose_args_base);
  1011. if (part_sn2->local_openclose_args == NULL) {
  1012. dev_err(xpc_chan, "can't get memory for local connect args\n");
  1013. retval = xpNoMemory;
  1014. goto out_2;
  1015. }
  1016. part_sn2->remote_openclose_args_pa = 0;
  1017. part_sn2->local_chctl_amo_va = xpc_init_IRQ_amo_sn2(partid);
  1018. part_sn2->notify_IRQ_nasid = 0;
  1019. part_sn2->notify_IRQ_phys_cpuid = 0;
  1020. part_sn2->remote_chctl_amo_va = NULL;
  1021. sprintf(part_sn2->notify_IRQ_owner, "xpc%02d", partid);
  1022. ret = request_irq(SGI_XPC_NOTIFY, xpc_handle_notify_IRQ_sn2,
  1023. IRQF_SHARED, part_sn2->notify_IRQ_owner,
  1024. (void *)(u64)partid);
  1025. if (ret != 0) {
  1026. dev_err(xpc_chan, "can't register NOTIFY IRQ handler, "
  1027. "errno=%d\n", -ret);
  1028. retval = xpLackOfResources;
  1029. goto out_3;
  1030. }
  1031. /* Setup a timer to check for dropped notify IRQs */
  1032. timer = &part_sn2->dropped_notify_IRQ_timer;
  1033. init_timer(timer);
  1034. timer->function =
  1035. (void (*)(unsigned long))xpc_check_for_dropped_notify_IRQ_sn2;
  1036. timer->data = (unsigned long)part;
  1037. timer->expires = jiffies + XPC_DROPPED_NOTIFY_IRQ_WAIT_INTERVAL;
  1038. add_timer(timer);
  1039. for (ch_number = 0; ch_number < part->nchannels; ch_number++) {
  1040. ch_sn2 = &part->channels[ch_number].sn.sn2;
  1041. ch_sn2->local_GP = &part_sn2->local_GPs[ch_number];
  1042. ch_sn2->local_openclose_args =
  1043. &part_sn2->local_openclose_args[ch_number];
  1044. mutex_init(&ch_sn2->msg_to_pull_mutex);
  1045. }
  1046. /*
  1047. * Setup the per partition specific variables required by the
  1048. * remote partition to establish channel connections with us.
  1049. *
  1050. * The setting of the magic # indicates that these per partition
  1051. * specific variables are ready to be used.
  1052. */
  1053. xpc_vars_part_sn2[partid].GPs_pa = xp_pa(part_sn2->local_GPs);
  1054. xpc_vars_part_sn2[partid].openclose_args_pa =
  1055. xp_pa(part_sn2->local_openclose_args);
  1056. xpc_vars_part_sn2[partid].chctl_amo_pa =
  1057. xp_pa(part_sn2->local_chctl_amo_va);
  1058. cpuid = raw_smp_processor_id(); /* any CPU in this partition will do */
  1059. xpc_vars_part_sn2[partid].notify_IRQ_nasid = cpuid_to_nasid(cpuid);
  1060. xpc_vars_part_sn2[partid].notify_IRQ_phys_cpuid =
  1061. cpu_physical_id(cpuid);
  1062. xpc_vars_part_sn2[partid].nchannels = part->nchannels;
  1063. xpc_vars_part_sn2[partid].magic = XPC_VP_MAGIC1_SN2;
  1064. return xpSuccess;
  1065. /* setup of ch structures failed */
  1066. out_3:
  1067. kfree(part_sn2->local_openclose_args_base);
  1068. part_sn2->local_openclose_args = NULL;
  1069. out_2:
  1070. kfree(part_sn2->remote_GPs_base);
  1071. part_sn2->remote_GPs = NULL;
  1072. out_1:
  1073. kfree(part_sn2->local_GPs_base);
  1074. part_sn2->local_GPs = NULL;
  1075. return retval;
  1076. }
  1077. /*
  1078. * Teardown the channel structures that are sn2 specific.
  1079. */
  1080. static void
  1081. xpc_teardown_ch_structures_sn2(struct xpc_partition *part)
  1082. {
  1083. struct xpc_partition_sn2 *part_sn2 = &part->sn.sn2;
  1084. short partid = XPC_PARTID(part);
  1085. /*
  1086. * Indicate that the variables specific to the remote partition are no
  1087. * longer available for its use.
  1088. */
  1089. xpc_vars_part_sn2[partid].magic = 0;
  1090. /* in case we've still got outstanding timers registered... */
  1091. del_timer_sync(&part_sn2->dropped_notify_IRQ_timer);
  1092. free_irq(SGI_XPC_NOTIFY, (void *)(u64)partid);
  1093. kfree(part_sn2->local_openclose_args_base);
  1094. part_sn2->local_openclose_args = NULL;
  1095. kfree(part_sn2->remote_GPs_base);
  1096. part_sn2->remote_GPs = NULL;
  1097. kfree(part_sn2->local_GPs_base);
  1098. part_sn2->local_GPs = NULL;
  1099. part_sn2->local_chctl_amo_va = NULL;
  1100. }
  1101. /*
  1102. * Create a wrapper that hides the underlying mechanism for pulling a cacheline
  1103. * (or multiple cachelines) from a remote partition.
  1104. *
  1105. * src_pa must be a cacheline aligned physical address on the remote partition.
  1106. * dst must be a cacheline aligned virtual address on this partition.
  1107. * cnt must be cacheline sized
  1108. */
  1109. /* ??? Replace this function by call to xp_remote_memcpy() or bte_copy()? */
  1110. static enum xp_retval
  1111. xpc_pull_remote_cachelines_sn2(struct xpc_partition *part, void *dst,
  1112. const unsigned long src_pa, size_t cnt)
  1113. {
  1114. enum xp_retval ret;
  1115. DBUG_ON(src_pa != L1_CACHE_ALIGN(src_pa));
  1116. DBUG_ON((unsigned long)dst != L1_CACHE_ALIGN((unsigned long)dst));
  1117. DBUG_ON(cnt != L1_CACHE_ALIGN(cnt));
  1118. if (part->act_state == XPC_P_AS_DEACTIVATING)
  1119. return part->reason;
  1120. ret = xp_remote_memcpy(xp_pa(dst), src_pa, cnt);
  1121. if (ret != xpSuccess) {
  1122. dev_dbg(xpc_chan, "xp_remote_memcpy() from partition %d failed,"
  1123. " ret=%d\n", XPC_PARTID(part), ret);
  1124. }
  1125. return ret;
  1126. }
  1127. /*
  1128. * Pull the remote per partition specific variables from the specified
  1129. * partition.
  1130. */
  1131. static enum xp_retval
  1132. xpc_pull_remote_vars_part_sn2(struct xpc_partition *part)
  1133. {
  1134. struct xpc_partition_sn2 *part_sn2 = &part->sn.sn2;
  1135. u8 buffer[L1_CACHE_BYTES * 2];
  1136. struct xpc_vars_part_sn2 *pulled_entry_cacheline =
  1137. (struct xpc_vars_part_sn2 *)L1_CACHE_ALIGN((u64)buffer);
  1138. struct xpc_vars_part_sn2 *pulled_entry;
  1139. unsigned long remote_entry_cacheline_pa;
  1140. unsigned long remote_entry_pa;
  1141. short partid = XPC_PARTID(part);
  1142. enum xp_retval ret;
  1143. /* pull the cacheline that contains the variables we're interested in */
  1144. DBUG_ON(part_sn2->remote_vars_part_pa !=
  1145. L1_CACHE_ALIGN(part_sn2->remote_vars_part_pa));
  1146. DBUG_ON(sizeof(struct xpc_vars_part_sn2) != L1_CACHE_BYTES / 2);
  1147. remote_entry_pa = part_sn2->remote_vars_part_pa +
  1148. sn_partition_id * sizeof(struct xpc_vars_part_sn2);
  1149. remote_entry_cacheline_pa = (remote_entry_pa & ~(L1_CACHE_BYTES - 1));
  1150. pulled_entry = (struct xpc_vars_part_sn2 *)((u64)pulled_entry_cacheline
  1151. + (remote_entry_pa &
  1152. (L1_CACHE_BYTES - 1)));
  1153. ret = xpc_pull_remote_cachelines_sn2(part, pulled_entry_cacheline,
  1154. remote_entry_cacheline_pa,
  1155. L1_CACHE_BYTES);
  1156. if (ret != xpSuccess) {
  1157. dev_dbg(xpc_chan, "failed to pull XPC vars_part from "
  1158. "partition %d, ret=%d\n", partid, ret);
  1159. return ret;
  1160. }
  1161. /* see if they've been set up yet */
  1162. if (pulled_entry->magic != XPC_VP_MAGIC1_SN2 &&
  1163. pulled_entry->magic != XPC_VP_MAGIC2_SN2) {
  1164. if (pulled_entry->magic != 0) {
  1165. dev_dbg(xpc_chan, "partition %d's XPC vars_part for "
  1166. "partition %d has bad magic value (=0x%llx)\n",
  1167. partid, sn_partition_id, pulled_entry->magic);
  1168. return xpBadMagic;
  1169. }
  1170. /* they've not been initialized yet */
  1171. return xpRetry;
  1172. }
  1173. if (xpc_vars_part_sn2[partid].magic == XPC_VP_MAGIC1_SN2) {
  1174. /* validate the variables */
  1175. if (pulled_entry->GPs_pa == 0 ||
  1176. pulled_entry->openclose_args_pa == 0 ||
  1177. pulled_entry->chctl_amo_pa == 0) {
  1178. dev_err(xpc_chan, "partition %d's XPC vars_part for "
  1179. "partition %d are not valid\n", partid,
  1180. sn_partition_id);
  1181. return xpInvalidAddress;
  1182. }
  1183. /* the variables we imported look to be valid */
  1184. part_sn2->remote_GPs_pa = pulled_entry->GPs_pa;
  1185. part_sn2->remote_openclose_args_pa =
  1186. pulled_entry->openclose_args_pa;
  1187. part_sn2->remote_chctl_amo_va =
  1188. (struct amo *)__va(pulled_entry->chctl_amo_pa);
  1189. part_sn2->notify_IRQ_nasid = pulled_entry->notify_IRQ_nasid;
  1190. part_sn2->notify_IRQ_phys_cpuid =
  1191. pulled_entry->notify_IRQ_phys_cpuid;
  1192. if (part->nchannels > pulled_entry->nchannels)
  1193. part->nchannels = pulled_entry->nchannels;
  1194. /* let the other side know that we've pulled their variables */
  1195. xpc_vars_part_sn2[partid].magic = XPC_VP_MAGIC2_SN2;
  1196. }
  1197. if (pulled_entry->magic == XPC_VP_MAGIC1_SN2)
  1198. return xpRetry;
  1199. return xpSuccess;
  1200. }
  1201. /*
  1202. * Establish first contact with the remote partititon. This involves pulling
  1203. * the XPC per partition variables from the remote partition and waiting for
  1204. * the remote partition to pull ours.
  1205. */
  1206. static enum xp_retval
  1207. xpc_make_first_contact_sn2(struct xpc_partition *part)
  1208. {
  1209. struct xpc_partition_sn2 *part_sn2 = &part->sn.sn2;
  1210. enum xp_retval ret;
  1211. /*
  1212. * Register the remote partition's amos with SAL so it can handle
  1213. * and cleanup errors within that address range should the remote
  1214. * partition go down. We don't unregister this range because it is
  1215. * difficult to tell when outstanding writes to the remote partition
  1216. * are finished and thus when it is safe to unregister. This should
  1217. * not result in wasted space in the SAL xp_addr_region table because
  1218. * we should get the same page for remote_amos_page_pa after module
  1219. * reloads and system reboots.
  1220. */
  1221. if (sn_register_xp_addr_region(part_sn2->remote_amos_page_pa,
  1222. PAGE_SIZE, 1) < 0) {
  1223. dev_warn(xpc_part, "xpc_activating(%d) failed to register "
  1224. "xp_addr region\n", XPC_PARTID(part));
  1225. ret = xpPhysAddrRegFailed;
  1226. XPC_DEACTIVATE_PARTITION(part, ret);
  1227. return ret;
  1228. }
  1229. /*
  1230. * Send activate IRQ to get other side to activate if they've not
  1231. * already begun to do so.
  1232. */
  1233. xpc_send_activate_IRQ_sn2(part_sn2->remote_amos_page_pa,
  1234. cnodeid_to_nasid(0),
  1235. part_sn2->activate_IRQ_nasid,
  1236. part_sn2->activate_IRQ_phys_cpuid);
  1237. while ((ret = xpc_pull_remote_vars_part_sn2(part)) != xpSuccess) {
  1238. if (ret != xpRetry) {
  1239. XPC_DEACTIVATE_PARTITION(part, ret);
  1240. return ret;
  1241. }
  1242. dev_dbg(xpc_part, "waiting to make first contact with "
  1243. "partition %d\n", XPC_PARTID(part));
  1244. /* wait a 1/4 of a second or so */
  1245. (void)msleep_interruptible(250);
  1246. if (part->act_state == XPC_P_AS_DEACTIVATING)
  1247. return part->reason;
  1248. }
  1249. return xpSuccess;
  1250. }
  1251. /*
  1252. * Get the chctl flags and pull the openclose args and/or remote GPs as needed.
  1253. */
  1254. static u64
  1255. xpc_get_chctl_all_flags_sn2(struct xpc_partition *part)
  1256. {
  1257. struct xpc_partition_sn2 *part_sn2 = &part->sn.sn2;
  1258. unsigned long irq_flags;
  1259. union xpc_channel_ctl_flags chctl;
  1260. enum xp_retval ret;
  1261. /*
  1262. * See if there are any chctl flags to be handled.
  1263. */
  1264. spin_lock_irqsave(&part->chctl_lock, irq_flags);
  1265. chctl = part->chctl;
  1266. if (chctl.all_flags != 0)
  1267. part->chctl.all_flags = 0;
  1268. spin_unlock_irqrestore(&part->chctl_lock, irq_flags);
  1269. if (xpc_any_openclose_chctl_flags_set(&chctl)) {
  1270. ret = xpc_pull_remote_cachelines_sn2(part, part->
  1271. remote_openclose_args,
  1272. part_sn2->
  1273. remote_openclose_args_pa,
  1274. XPC_OPENCLOSE_ARGS_SIZE);
  1275. if (ret != xpSuccess) {
  1276. XPC_DEACTIVATE_PARTITION(part, ret);
  1277. dev_dbg(xpc_chan, "failed to pull openclose args from "
  1278. "partition %d, ret=%d\n", XPC_PARTID(part),
  1279. ret);
  1280. /* don't bother processing chctl flags anymore */
  1281. chctl.all_flags = 0;
  1282. }
  1283. }
  1284. if (xpc_any_msg_chctl_flags_set(&chctl)) {
  1285. ret = xpc_pull_remote_cachelines_sn2(part, part_sn2->remote_GPs,
  1286. part_sn2->remote_GPs_pa,
  1287. XPC_GP_SIZE);
  1288. if (ret != xpSuccess) {
  1289. XPC_DEACTIVATE_PARTITION(part, ret);
  1290. dev_dbg(xpc_chan, "failed to pull GPs from partition "
  1291. "%d, ret=%d\n", XPC_PARTID(part), ret);
  1292. /* don't bother processing chctl flags anymore */
  1293. chctl.all_flags = 0;
  1294. }
  1295. }
  1296. return chctl.all_flags;
  1297. }
  1298. /*
  1299. * Allocate the local message queue and the notify queue.
  1300. */
  1301. static enum xp_retval
  1302. xpc_allocate_local_msgqueue_sn2(struct xpc_channel *ch)
  1303. {
  1304. struct xpc_channel_sn2 *ch_sn2 = &ch->sn.sn2;
  1305. unsigned long irq_flags;
  1306. int nentries;
  1307. size_t nbytes;
  1308. for (nentries = ch->local_nentries; nentries > 0; nentries--) {
  1309. nbytes = nentries * ch->entry_size;
  1310. ch_sn2->local_msgqueue =
  1311. xpc_kzalloc_cacheline_aligned(nbytes, GFP_KERNEL,
  1312. &ch_sn2->local_msgqueue_base);
  1313. if (ch_sn2->local_msgqueue == NULL)
  1314. continue;
  1315. nbytes = nentries * sizeof(struct xpc_notify_sn2);
  1316. ch_sn2->notify_queue = kzalloc(nbytes, GFP_KERNEL);
  1317. if (ch_sn2->notify_queue == NULL) {
  1318. kfree(ch_sn2->local_msgqueue_base);
  1319. ch_sn2->local_msgqueue = NULL;
  1320. continue;
  1321. }
  1322. spin_lock_irqsave(&ch->lock, irq_flags);
  1323. if (nentries < ch->local_nentries) {
  1324. dev_dbg(xpc_chan, "nentries=%d local_nentries=%d, "
  1325. "partid=%d, channel=%d\n", nentries,
  1326. ch->local_nentries, ch->partid, ch->number);
  1327. ch->local_nentries = nentries;
  1328. }
  1329. spin_unlock_irqrestore(&ch->lock, irq_flags);
  1330. return xpSuccess;
  1331. }
  1332. dev_dbg(xpc_chan, "can't get memory for local message queue and notify "
  1333. "queue, partid=%d, channel=%d\n", ch->partid, ch->number);
  1334. return xpNoMemory;
  1335. }
  1336. /*
  1337. * Allocate the cached remote message queue.
  1338. */
  1339. static enum xp_retval
  1340. xpc_allocate_remote_msgqueue_sn2(struct xpc_channel *ch)
  1341. {
  1342. struct xpc_channel_sn2 *ch_sn2 = &ch->sn.sn2;
  1343. unsigned long irq_flags;
  1344. int nentries;
  1345. size_t nbytes;
  1346. DBUG_ON(ch->remote_nentries <= 0);
  1347. for (nentries = ch->remote_nentries; nentries > 0; nentries--) {
  1348. nbytes = nentries * ch->entry_size;
  1349. ch_sn2->remote_msgqueue =
  1350. xpc_kzalloc_cacheline_aligned(nbytes, GFP_KERNEL, &ch_sn2->
  1351. remote_msgqueue_base);
  1352. if (ch_sn2->remote_msgqueue == NULL)
  1353. continue;
  1354. spin_lock_irqsave(&ch->lock, irq_flags);
  1355. if (nentries < ch->remote_nentries) {
  1356. dev_dbg(xpc_chan, "nentries=%d remote_nentries=%d, "
  1357. "partid=%d, channel=%d\n", nentries,
  1358. ch->remote_nentries, ch->partid, ch->number);
  1359. ch->remote_nentries = nentries;
  1360. }
  1361. spin_unlock_irqrestore(&ch->lock, irq_flags);
  1362. return xpSuccess;
  1363. }
  1364. dev_dbg(xpc_chan, "can't get memory for cached remote message queue, "
  1365. "partid=%d, channel=%d\n", ch->partid, ch->number);
  1366. return xpNoMemory;
  1367. }
  1368. /*
  1369. * Allocate message queues and other stuff associated with a channel.
  1370. *
  1371. * Note: Assumes all of the channel sizes are filled in.
  1372. */
  1373. static enum xp_retval
  1374. xpc_setup_msg_structures_sn2(struct xpc_channel *ch)
  1375. {
  1376. struct xpc_channel_sn2 *ch_sn2 = &ch->sn.sn2;
  1377. enum xp_retval ret;
  1378. DBUG_ON(ch->flags & XPC_C_SETUP);
  1379. ret = xpc_allocate_local_msgqueue_sn2(ch);
  1380. if (ret == xpSuccess) {
  1381. ret = xpc_allocate_remote_msgqueue_sn2(ch);
  1382. if (ret != xpSuccess) {
  1383. kfree(ch_sn2->local_msgqueue_base);
  1384. ch_sn2->local_msgqueue = NULL;
  1385. kfree(ch_sn2->notify_queue);
  1386. ch_sn2->notify_queue = NULL;
  1387. }
  1388. }
  1389. return ret;
  1390. }
  1391. /*
  1392. * Free up message queues and other stuff that were allocated for the specified
  1393. * channel.
  1394. */
  1395. static void
  1396. xpc_teardown_msg_structures_sn2(struct xpc_channel *ch)
  1397. {
  1398. struct xpc_channel_sn2 *ch_sn2 = &ch->sn.sn2;
  1399. DBUG_ON(!spin_is_locked(&ch->lock));
  1400. ch_sn2->remote_msgqueue_pa = 0;
  1401. ch_sn2->local_GP->get = 0;
  1402. ch_sn2->local_GP->put = 0;
  1403. ch_sn2->remote_GP.get = 0;
  1404. ch_sn2->remote_GP.put = 0;
  1405. ch_sn2->w_local_GP.get = 0;
  1406. ch_sn2->w_local_GP.put = 0;
  1407. ch_sn2->w_remote_GP.get = 0;
  1408. ch_sn2->w_remote_GP.put = 0;
  1409. ch_sn2->next_msg_to_pull = 0;
  1410. if (ch->flags & XPC_C_SETUP) {
  1411. dev_dbg(xpc_chan, "ch->flags=0x%x, partid=%d, channel=%d\n",
  1412. ch->flags, ch->partid, ch->number);
  1413. kfree(ch_sn2->local_msgqueue_base);
  1414. ch_sn2->local_msgqueue = NULL;
  1415. kfree(ch_sn2->remote_msgqueue_base);
  1416. ch_sn2->remote_msgqueue = NULL;
  1417. kfree(ch_sn2->notify_queue);
  1418. ch_sn2->notify_queue = NULL;
  1419. }
  1420. }
  1421. /*
  1422. * Notify those who wanted to be notified upon delivery of their message.
  1423. */
  1424. static void
  1425. xpc_notify_senders_sn2(struct xpc_channel *ch, enum xp_retval reason, s64 put)
  1426. {
  1427. struct xpc_notify_sn2 *notify;
  1428. u8 notify_type;
  1429. s64 get = ch->sn.sn2.w_remote_GP.get - 1;
  1430. while (++get < put && atomic_read(&ch->n_to_notify) > 0) {
  1431. notify = &ch->sn.sn2.notify_queue[get % ch->local_nentries];
  1432. /*
  1433. * See if the notify entry indicates it was associated with
  1434. * a message who's sender wants to be notified. It is possible
  1435. * that it is, but someone else is doing or has done the
  1436. * notification.
  1437. */
  1438. notify_type = notify->type;
  1439. if (notify_type == 0 ||
  1440. cmpxchg(&notify->type, notify_type, 0) != notify_type) {
  1441. continue;
  1442. }
  1443. DBUG_ON(notify_type != XPC_N_CALL);
  1444. atomic_dec(&ch->n_to_notify);
  1445. if (notify->func != NULL) {
  1446. dev_dbg(xpc_chan, "notify->func() called, notify=0x%p "
  1447. "msg_number=%lld partid=%d channel=%d\n",
  1448. (void *)notify, get, ch->partid, ch->number);
  1449. notify->func(reason, ch->partid, ch->number,
  1450. notify->key);
  1451. dev_dbg(xpc_chan, "notify->func() returned, notify=0x%p"
  1452. " msg_number=%lld partid=%d channel=%d\n",
  1453. (void *)notify, get, ch->partid, ch->number);
  1454. }
  1455. }
  1456. }
  1457. static void
  1458. xpc_notify_senders_of_disconnect_sn2(struct xpc_channel *ch)
  1459. {
  1460. xpc_notify_senders_sn2(ch, ch->reason, ch->sn.sn2.w_local_GP.put);
  1461. }
  1462. /*
  1463. * Clear some of the msg flags in the local message queue.
  1464. */
  1465. static inline void
  1466. xpc_clear_local_msgqueue_flags_sn2(struct xpc_channel *ch)
  1467. {
  1468. struct xpc_channel_sn2 *ch_sn2 = &ch->sn.sn2;
  1469. struct xpc_msg_sn2 *msg;
  1470. s64 get;
  1471. get = ch_sn2->w_remote_GP.get;
  1472. do {
  1473. msg = (struct xpc_msg_sn2 *)((u64)ch_sn2->local_msgqueue +
  1474. (get % ch->local_nentries) *
  1475. ch->entry_size);
  1476. DBUG_ON(!(msg->flags & XPC_M_SN2_READY));
  1477. msg->flags = 0;
  1478. } while (++get < ch_sn2->remote_GP.get);
  1479. }
  1480. /*
  1481. * Clear some of the msg flags in the remote message queue.
  1482. */
  1483. static inline void
  1484. xpc_clear_remote_msgqueue_flags_sn2(struct xpc_channel *ch)
  1485. {
  1486. struct xpc_channel_sn2 *ch_sn2 = &ch->sn.sn2;
  1487. struct xpc_msg_sn2 *msg;
  1488. s64 put, remote_nentries = ch->remote_nentries;
  1489. /* flags are zeroed when the buffer is allocated */
  1490. if (ch_sn2->remote_GP.put < remote_nentries)
  1491. return;
  1492. put = max(ch_sn2->w_remote_GP.put, remote_nentries);
  1493. do {
  1494. msg = (struct xpc_msg_sn2 *)((u64)ch_sn2->remote_msgqueue +
  1495. (put % remote_nentries) *
  1496. ch->entry_size);
  1497. DBUG_ON(!(msg->flags & XPC_M_SN2_READY));
  1498. DBUG_ON(!(msg->flags & XPC_M_SN2_DONE));
  1499. DBUG_ON(msg->number != put - remote_nentries);
  1500. msg->flags = 0;
  1501. } while (++put < ch_sn2->remote_GP.put);
  1502. }
  1503. static int
  1504. xpc_n_of_deliverable_payloads_sn2(struct xpc_channel *ch)
  1505. {
  1506. return ch->sn.sn2.w_remote_GP.put - ch->sn.sn2.w_local_GP.get;
  1507. }
  1508. static void
  1509. xpc_process_msg_chctl_flags_sn2(struct xpc_partition *part, int ch_number)
  1510. {
  1511. struct xpc_channel *ch = &part->channels[ch_number];
  1512. struct xpc_channel_sn2 *ch_sn2 = &ch->sn.sn2;
  1513. int npayloads_sent;
  1514. ch_sn2->remote_GP = part->sn.sn2.remote_GPs[ch_number];
  1515. /* See what, if anything, has changed for each connected channel */
  1516. xpc_msgqueue_ref(ch);
  1517. if (ch_sn2->w_remote_GP.get == ch_sn2->remote_GP.get &&
  1518. ch_sn2->w_remote_GP.put == ch_sn2->remote_GP.put) {
  1519. /* nothing changed since GPs were last pulled */
  1520. xpc_msgqueue_deref(ch);
  1521. return;
  1522. }
  1523. if (!(ch->flags & XPC_C_CONNECTED)) {
  1524. xpc_msgqueue_deref(ch);
  1525. return;
  1526. }
  1527. /*
  1528. * First check to see if messages recently sent by us have been
  1529. * received by the other side. (The remote GET value will have
  1530. * changed since we last looked at it.)
  1531. */
  1532. if (ch_sn2->w_remote_GP.get != ch_sn2->remote_GP.get) {
  1533. /*
  1534. * We need to notify any senders that want to be notified
  1535. * that their sent messages have been received by their
  1536. * intended recipients. We need to do this before updating
  1537. * w_remote_GP.get so that we don't allocate the same message
  1538. * queue entries prematurely (see xpc_allocate_msg()).
  1539. */
  1540. if (atomic_read(&ch->n_to_notify) > 0) {
  1541. /*
  1542. * Notify senders that messages sent have been
  1543. * received and delivered by the other side.
  1544. */
  1545. xpc_notify_senders_sn2(ch, xpMsgDelivered,
  1546. ch_sn2->remote_GP.get);
  1547. }
  1548. /*
  1549. * Clear msg->flags in previously sent messages, so that
  1550. * they're ready for xpc_allocate_msg().
  1551. */
  1552. xpc_clear_local_msgqueue_flags_sn2(ch);
  1553. ch_sn2->w_remote_GP.get = ch_sn2->remote_GP.get;
  1554. dev_dbg(xpc_chan, "w_remote_GP.get changed to %lld, partid=%d, "
  1555. "channel=%d\n", ch_sn2->w_remote_GP.get, ch->partid,
  1556. ch->number);
  1557. /*
  1558. * If anyone was waiting for message queue entries to become
  1559. * available, wake them up.
  1560. */
  1561. if (atomic_read(&ch->n_on_msg_allocate_wq) > 0)
  1562. wake_up(&ch->msg_allocate_wq);
  1563. }
  1564. /*
  1565. * Now check for newly sent messages by the other side. (The remote
  1566. * PUT value will have changed since we last looked at it.)
  1567. */
  1568. if (ch_sn2->w_remote_GP.put != ch_sn2->remote_GP.put) {
  1569. /*
  1570. * Clear msg->flags in previously received messages, so that
  1571. * they're ready for xpc_get_deliverable_payload_sn2().
  1572. */
  1573. xpc_clear_remote_msgqueue_flags_sn2(ch);
  1574. smp_wmb(); /* ensure flags have been cleared before bte_copy */
  1575. ch_sn2->w_remote_GP.put = ch_sn2->remote_GP.put;
  1576. dev_dbg(xpc_chan, "w_remote_GP.put changed to %lld, partid=%d, "
  1577. "channel=%d\n", ch_sn2->w_remote_GP.put, ch->partid,
  1578. ch->number);
  1579. npayloads_sent = xpc_n_of_deliverable_payloads_sn2(ch);
  1580. if (npayloads_sent > 0) {
  1581. dev_dbg(xpc_chan, "msgs waiting to be copied and "
  1582. "delivered=%d, partid=%d, channel=%d\n",
  1583. npayloads_sent, ch->partid, ch->number);
  1584. if (ch->flags & XPC_C_CONNECTEDCALLOUT_MADE)
  1585. xpc_activate_kthreads(ch, npayloads_sent);
  1586. }
  1587. }
  1588. xpc_msgqueue_deref(ch);
  1589. }
  1590. static struct xpc_msg_sn2 *
  1591. xpc_pull_remote_msg_sn2(struct xpc_channel *ch, s64 get)
  1592. {
  1593. struct xpc_partition *part = &xpc_partitions[ch->partid];
  1594. struct xpc_channel_sn2 *ch_sn2 = &ch->sn.sn2;
  1595. unsigned long remote_msg_pa;
  1596. struct xpc_msg_sn2 *msg;
  1597. u32 msg_index;
  1598. u32 nmsgs;
  1599. u64 msg_offset;
  1600. enum xp_retval ret;
  1601. if (mutex_lock_interruptible(&ch_sn2->msg_to_pull_mutex) != 0) {
  1602. /* we were interrupted by a signal */
  1603. return NULL;
  1604. }
  1605. while (get >= ch_sn2->next_msg_to_pull) {
  1606. /* pull as many messages as are ready and able to be pulled */
  1607. msg_index = ch_sn2->next_msg_to_pull % ch->remote_nentries;
  1608. DBUG_ON(ch_sn2->next_msg_to_pull >= ch_sn2->w_remote_GP.put);
  1609. nmsgs = ch_sn2->w_remote_GP.put - ch_sn2->next_msg_to_pull;
  1610. if (msg_index + nmsgs > ch->remote_nentries) {
  1611. /* ignore the ones that wrap the msg queue for now */
  1612. nmsgs = ch->remote_nentries - msg_index;
  1613. }
  1614. msg_offset = msg_index * ch->entry_size;
  1615. msg = (struct xpc_msg_sn2 *)((u64)ch_sn2->remote_msgqueue +
  1616. msg_offset);
  1617. remote_msg_pa = ch_sn2->remote_msgqueue_pa + msg_offset;
  1618. ret = xpc_pull_remote_cachelines_sn2(part, msg, remote_msg_pa,
  1619. nmsgs * ch->entry_size);
  1620. if (ret != xpSuccess) {
  1621. dev_dbg(xpc_chan, "failed to pull %d msgs starting with"
  1622. " msg %lld from partition %d, channel=%d, "
  1623. "ret=%d\n", nmsgs, ch_sn2->next_msg_to_pull,
  1624. ch->partid, ch->number, ret);
  1625. XPC_DEACTIVATE_PARTITION(part, ret);
  1626. mutex_unlock(&ch_sn2->msg_to_pull_mutex);
  1627. return NULL;
  1628. }
  1629. ch_sn2->next_msg_to_pull += nmsgs;
  1630. }
  1631. mutex_unlock(&ch_sn2->msg_to_pull_mutex);
  1632. /* return the message we were looking for */
  1633. msg_offset = (get % ch->remote_nentries) * ch->entry_size;
  1634. msg = (struct xpc_msg_sn2 *)((u64)ch_sn2->remote_msgqueue + msg_offset);
  1635. return msg;
  1636. }
  1637. /*
  1638. * Get the next deliverable message's payload.
  1639. */
  1640. static void *
  1641. xpc_get_deliverable_payload_sn2(struct xpc_channel *ch)
  1642. {
  1643. struct xpc_channel_sn2 *ch_sn2 = &ch->sn.sn2;
  1644. struct xpc_msg_sn2 *msg;
  1645. void *payload = NULL;
  1646. s64 get;
  1647. do {
  1648. if (ch->flags & XPC_C_DISCONNECTING)
  1649. break;
  1650. get = ch_sn2->w_local_GP.get;
  1651. smp_rmb(); /* guarantee that .get loads before .put */
  1652. if (get == ch_sn2->w_remote_GP.put)
  1653. break;
  1654. /* There are messages waiting to be pulled and delivered.
  1655. * We need to try to secure one for ourselves. We'll do this
  1656. * by trying to increment w_local_GP.get and hope that no one
  1657. * else beats us to it. If they do, we'll we'll simply have
  1658. * to try again for the next one.
  1659. */
  1660. if (cmpxchg(&ch_sn2->w_local_GP.get, get, get + 1) == get) {
  1661. /* we got the entry referenced by get */
  1662. dev_dbg(xpc_chan, "w_local_GP.get changed to %lld, "
  1663. "partid=%d, channel=%d\n", get + 1,
  1664. ch->partid, ch->number);
  1665. /* pull the message from the remote partition */
  1666. msg = xpc_pull_remote_msg_sn2(ch, get);
  1667. if (msg != NULL) {
  1668. DBUG_ON(msg->number != get);
  1669. DBUG_ON(msg->flags & XPC_M_SN2_DONE);
  1670. DBUG_ON(!(msg->flags & XPC_M_SN2_READY));
  1671. payload = &msg->payload;
  1672. }
  1673. break;
  1674. }
  1675. } while (1);
  1676. return payload;
  1677. }
  1678. /*
  1679. * Now we actually send the messages that are ready to be sent by advancing
  1680. * the local message queue's Put value and then send a chctl msgrequest to the
  1681. * recipient partition.
  1682. */
  1683. static void
  1684. xpc_send_msgs_sn2(struct xpc_channel *ch, s64 initial_put)
  1685. {
  1686. struct xpc_channel_sn2 *ch_sn2 = &ch->sn.sn2;
  1687. struct xpc_msg_sn2 *msg;
  1688. s64 put = initial_put + 1;
  1689. int send_msgrequest = 0;
  1690. while (1) {
  1691. while (1) {
  1692. if (put == ch_sn2->w_local_GP.put)
  1693. break;
  1694. msg = (struct xpc_msg_sn2 *)((u64)ch_sn2->
  1695. local_msgqueue + (put %
  1696. ch->local_nentries) *
  1697. ch->entry_size);
  1698. if (!(msg->flags & XPC_M_SN2_READY))
  1699. break;
  1700. put++;
  1701. }
  1702. if (put == initial_put) {
  1703. /* nothing's changed */
  1704. break;
  1705. }
  1706. if (cmpxchg_rel(&ch_sn2->local_GP->put, initial_put, put) !=
  1707. initial_put) {
  1708. /* someone else beat us to it */
  1709. DBUG_ON(ch_sn2->local_GP->put < initial_put);
  1710. break;
  1711. }
  1712. /* we just set the new value of local_GP->put */
  1713. dev_dbg(xpc_chan, "local_GP->put changed to %lld, partid=%d, "
  1714. "channel=%d\n", put, ch->partid, ch->number);
  1715. send_msgrequest = 1;
  1716. /*
  1717. * We need to ensure that the message referenced by
  1718. * local_GP->put is not XPC_M_SN2_READY or that local_GP->put
  1719. * equals w_local_GP.put, so we'll go have a look.
  1720. */
  1721. initial_put = put;
  1722. }
  1723. if (send_msgrequest)
  1724. xpc_send_chctl_msgrequest_sn2(ch);
  1725. }
  1726. /*
  1727. * Allocate an entry for a message from the message queue associated with the
  1728. * specified channel.
  1729. */
  1730. static enum xp_retval
  1731. xpc_allocate_msg_sn2(struct xpc_channel *ch, u32 flags,
  1732. struct xpc_msg_sn2 **address_of_msg)
  1733. {
  1734. struct xpc_channel_sn2 *ch_sn2 = &ch->sn.sn2;
  1735. struct xpc_msg_sn2 *msg;
  1736. enum xp_retval ret;
  1737. s64 put;
  1738. /*
  1739. * Get the next available message entry from the local message queue.
  1740. * If none are available, we'll make sure that we grab the latest
  1741. * GP values.
  1742. */
  1743. ret = xpTimeout;
  1744. while (1) {
  1745. put = ch_sn2->w_local_GP.put;
  1746. smp_rmb(); /* guarantee that .put loads before .get */
  1747. if (put - ch_sn2->w_remote_GP.get < ch->local_nentries) {
  1748. /* There are available message entries. We need to try
  1749. * to secure one for ourselves. We'll do this by trying
  1750. * to increment w_local_GP.put as long as someone else
  1751. * doesn't beat us to it. If they do, we'll have to
  1752. * try again.
  1753. */
  1754. if (cmpxchg(&ch_sn2->w_local_GP.put, put, put + 1) ==
  1755. put) {
  1756. /* we got the entry referenced by put */
  1757. break;
  1758. }
  1759. continue; /* try again */
  1760. }
  1761. /*
  1762. * There aren't any available msg entries at this time.
  1763. *
  1764. * In waiting for a message entry to become available,
  1765. * we set a timeout in case the other side is not sending
  1766. * completion interrupts. This lets us fake a notify IRQ
  1767. * that will cause the notify IRQ handler to fetch the latest
  1768. * GP values as if an interrupt was sent by the other side.
  1769. */
  1770. if (ret == xpTimeout)
  1771. xpc_send_chctl_local_msgrequest_sn2(ch);
  1772. if (flags & XPC_NOWAIT)
  1773. return xpNoWait;
  1774. ret = xpc_allocate_msg_wait(ch);
  1775. if (ret != xpInterrupted && ret != xpTimeout)
  1776. return ret;
  1777. }
  1778. /* get the message's address and initialize it */
  1779. msg = (struct xpc_msg_sn2 *)((u64)ch_sn2->local_msgqueue +
  1780. (put % ch->local_nentries) *
  1781. ch->entry_size);
  1782. DBUG_ON(msg->flags != 0);
  1783. msg->number = put;
  1784. dev_dbg(xpc_chan, "w_local_GP.put changed to %lld; msg=0x%p, "
  1785. "msg_number=%lld, partid=%d, channel=%d\n", put + 1,
  1786. (void *)msg, msg->number, ch->partid, ch->number);
  1787. *address_of_msg = msg;
  1788. return xpSuccess;
  1789. }
  1790. /*
  1791. * Common code that does the actual sending of the message by advancing the
  1792. * local message queue's Put value and sends a chctl msgrequest to the
  1793. * partition the message is being sent to.
  1794. */
  1795. static enum xp_retval
  1796. xpc_send_payload_sn2(struct xpc_channel *ch, u32 flags, void *payload,
  1797. u16 payload_size, u8 notify_type, xpc_notify_func func,
  1798. void *key)
  1799. {
  1800. enum xp_retval ret = xpSuccess;
  1801. struct xpc_channel_sn2 *ch_sn2 = &ch->sn.sn2;
  1802. struct xpc_msg_sn2 *msg = msg;
  1803. struct xpc_notify_sn2 *notify = notify;
  1804. s64 msg_number;
  1805. s64 put;
  1806. DBUG_ON(notify_type == XPC_N_CALL && func == NULL);
  1807. if (XPC_MSG_SIZE(payload_size) > ch->entry_size)
  1808. return xpPayloadTooBig;
  1809. xpc_msgqueue_ref(ch);
  1810. if (ch->flags & XPC_C_DISCONNECTING) {
  1811. ret = ch->reason;
  1812. goto out_1;
  1813. }
  1814. if (!(ch->flags & XPC_C_CONNECTED)) {
  1815. ret = xpNotConnected;
  1816. goto out_1;
  1817. }
  1818. ret = xpc_allocate_msg_sn2(ch, flags, &msg);
  1819. if (ret != xpSuccess)
  1820. goto out_1;
  1821. msg_number = msg->number;
  1822. if (notify_type != 0) {
  1823. /*
  1824. * Tell the remote side to send an ACK interrupt when the
  1825. * message has been delivered.
  1826. */
  1827. msg->flags |= XPC_M_SN2_INTERRUPT;
  1828. atomic_inc(&ch->n_to_notify);
  1829. notify = &ch_sn2->notify_queue[msg_number % ch->local_nentries];
  1830. notify->func = func;
  1831. notify->key = key;
  1832. notify->type = notify_type;
  1833. /* ??? Is a mb() needed here? */
  1834. if (ch->flags & XPC_C_DISCONNECTING) {
  1835. /*
  1836. * An error occurred between our last error check and
  1837. * this one. We will try to clear the type field from
  1838. * the notify entry. If we succeed then
  1839. * xpc_disconnect_channel() didn't already process
  1840. * the notify entry.
  1841. */
  1842. if (cmpxchg(&notify->type, notify_type, 0) ==
  1843. notify_type) {
  1844. atomic_dec(&ch->n_to_notify);
  1845. ret = ch->reason;
  1846. }
  1847. goto out_1;
  1848. }
  1849. }
  1850. memcpy(&msg->payload, payload, payload_size);
  1851. msg->flags |= XPC_M_SN2_READY;
  1852. /*
  1853. * The preceding store of msg->flags must occur before the following
  1854. * load of local_GP->put.
  1855. */
  1856. smp_mb();
  1857. /* see if the message is next in line to be sent, if so send it */
  1858. put = ch_sn2->local_GP->put;
  1859. if (put == msg_number)
  1860. xpc_send_msgs_sn2(ch, put);
  1861. out_1:
  1862. xpc_msgqueue_deref(ch);
  1863. return ret;
  1864. }
  1865. /*
  1866. * Now we actually acknowledge the messages that have been delivered and ack'd
  1867. * by advancing the cached remote message queue's Get value and if requested
  1868. * send a chctl msgrequest to the message sender's partition.
  1869. *
  1870. * If a message has XPC_M_SN2_INTERRUPT set, send an interrupt to the partition
  1871. * that sent the message.
  1872. */
  1873. static void
  1874. xpc_acknowledge_msgs_sn2(struct xpc_channel *ch, s64 initial_get, u8 msg_flags)
  1875. {
  1876. struct xpc_channel_sn2 *ch_sn2 = &ch->sn.sn2;
  1877. struct xpc_msg_sn2 *msg;
  1878. s64 get = initial_get + 1;
  1879. int send_msgrequest = 0;
  1880. while (1) {
  1881. while (1) {
  1882. if (get == ch_sn2->w_local_GP.get)
  1883. break;
  1884. msg = (struct xpc_msg_sn2 *)((u64)ch_sn2->
  1885. remote_msgqueue + (get %
  1886. ch->remote_nentries) *
  1887. ch->entry_size);
  1888. if (!(msg->flags & XPC_M_SN2_DONE))
  1889. break;
  1890. msg_flags |= msg->flags;
  1891. get++;
  1892. }
  1893. if (get == initial_get) {
  1894. /* nothing's changed */
  1895. break;
  1896. }
  1897. if (cmpxchg_rel(&ch_sn2->local_GP->get, initial_get, get) !=
  1898. initial_get) {
  1899. /* someone else beat us to it */
  1900. DBUG_ON(ch_sn2->local_GP->get <= initial_get);
  1901. break;
  1902. }
  1903. /* we just set the new value of local_GP->get */
  1904. dev_dbg(xpc_chan, "local_GP->get changed to %lld, partid=%d, "
  1905. "channel=%d\n", get, ch->partid, ch->number);
  1906. send_msgrequest = (msg_flags & XPC_M_SN2_INTERRUPT);
  1907. /*
  1908. * We need to ensure that the message referenced by
  1909. * local_GP->get is not XPC_M_SN2_DONE or that local_GP->get
  1910. * equals w_local_GP.get, so we'll go have a look.
  1911. */
  1912. initial_get = get;
  1913. }
  1914. if (send_msgrequest)
  1915. xpc_send_chctl_msgrequest_sn2(ch);
  1916. }
  1917. static void
  1918. xpc_received_payload_sn2(struct xpc_channel *ch, void *payload)
  1919. {
  1920. struct xpc_msg_sn2 *msg;
  1921. s64 msg_number;
  1922. s64 get;
  1923. msg = container_of(payload, struct xpc_msg_sn2, payload);
  1924. msg_number = msg->number;
  1925. dev_dbg(xpc_chan, "msg=0x%p, msg_number=%lld, partid=%d, channel=%d\n",
  1926. (void *)msg, msg_number, ch->partid, ch->number);
  1927. DBUG_ON((((u64)msg - (u64)ch->sn.sn2.remote_msgqueue) / ch->entry_size) !=
  1928. msg_number % ch->remote_nentries);
  1929. DBUG_ON(!(msg->flags & XPC_M_SN2_READY));
  1930. DBUG_ON(msg->flags & XPC_M_SN2_DONE);
  1931. msg->flags |= XPC_M_SN2_DONE;
  1932. /*
  1933. * The preceding store of msg->flags must occur before the following
  1934. * load of local_GP->get.
  1935. */
  1936. smp_mb();
  1937. /*
  1938. * See if this message is next in line to be acknowledged as having
  1939. * been delivered.
  1940. */
  1941. get = ch->sn.sn2.local_GP->get;
  1942. if (get == msg_number)
  1943. xpc_acknowledge_msgs_sn2(ch, get, msg->flags);
  1944. }
  1945. static struct xpc_arch_operations xpc_arch_ops_sn2 = {
  1946. .setup_partitions = xpc_setup_partitions_sn2,
  1947. .teardown_partitions = xpc_teardown_partitions_sn2,
  1948. .process_activate_IRQ_rcvd = xpc_process_activate_IRQ_rcvd_sn2,
  1949. .get_partition_rsvd_page_pa = xpc_get_partition_rsvd_page_pa_sn2,
  1950. .setup_rsvd_page = xpc_setup_rsvd_page_sn2,
  1951. .allow_hb = xpc_allow_hb_sn2,
  1952. .disallow_hb = xpc_disallow_hb_sn2,
  1953. .disallow_all_hbs = xpc_disallow_all_hbs_sn2,
  1954. .increment_heartbeat = xpc_increment_heartbeat_sn2,
  1955. .offline_heartbeat = xpc_offline_heartbeat_sn2,
  1956. .online_heartbeat = xpc_online_heartbeat_sn2,
  1957. .heartbeat_init = xpc_heartbeat_init_sn2,
  1958. .heartbeat_exit = xpc_heartbeat_exit_sn2,
  1959. .get_remote_heartbeat = xpc_get_remote_heartbeat_sn2,
  1960. .request_partition_activation =
  1961. xpc_request_partition_activation_sn2,
  1962. .request_partition_reactivation =
  1963. xpc_request_partition_reactivation_sn2,
  1964. .request_partition_deactivation =
  1965. xpc_request_partition_deactivation_sn2,
  1966. .cancel_partition_deactivation_request =
  1967. xpc_cancel_partition_deactivation_request_sn2,
  1968. .setup_ch_structures = xpc_setup_ch_structures_sn2,
  1969. .teardown_ch_structures = xpc_teardown_ch_structures_sn2,
  1970. .make_first_contact = xpc_make_first_contact_sn2,
  1971. .get_chctl_all_flags = xpc_get_chctl_all_flags_sn2,
  1972. .send_chctl_closerequest = xpc_send_chctl_closerequest_sn2,
  1973. .send_chctl_closereply = xpc_send_chctl_closereply_sn2,
  1974. .send_chctl_openrequest = xpc_send_chctl_openrequest_sn2,
  1975. .send_chctl_openreply = xpc_send_chctl_openreply_sn2,
  1976. .send_chctl_opencomplete = xpc_send_chctl_opencomplete_sn2,
  1977. .process_msg_chctl_flags = xpc_process_msg_chctl_flags_sn2,
  1978. .save_remote_msgqueue_pa = xpc_save_remote_msgqueue_pa_sn2,
  1979. .setup_msg_structures = xpc_setup_msg_structures_sn2,
  1980. .teardown_msg_structures = xpc_teardown_msg_structures_sn2,
  1981. .indicate_partition_engaged = xpc_indicate_partition_engaged_sn2,
  1982. .indicate_partition_disengaged = xpc_indicate_partition_disengaged_sn2,
  1983. .partition_engaged = xpc_partition_engaged_sn2,
  1984. .any_partition_engaged = xpc_any_partition_engaged_sn2,
  1985. .assume_partition_disengaged = xpc_assume_partition_disengaged_sn2,
  1986. .n_of_deliverable_payloads = xpc_n_of_deliverable_payloads_sn2,
  1987. .send_payload = xpc_send_payload_sn2,
  1988. .get_deliverable_payload = xpc_get_deliverable_payload_sn2,
  1989. .received_payload = xpc_received_payload_sn2,
  1990. .notify_senders_of_disconnect = xpc_notify_senders_of_disconnect_sn2,
  1991. };
  1992. int
  1993. xpc_init_sn2(void)
  1994. {
  1995. int ret;
  1996. size_t buf_size;
  1997. xpc_arch_ops = xpc_arch_ops_sn2;
  1998. if (offsetof(struct xpc_msg_sn2, payload) > XPC_MSG_HDR_MAX_SIZE) {
  1999. dev_err(xpc_part, "header portion of struct xpc_msg_sn2 is "
  2000. "larger than %d\n", XPC_MSG_HDR_MAX_SIZE);
  2001. return -E2BIG;
  2002. }
  2003. buf_size = max(XPC_RP_VARS_SIZE,
  2004. XPC_RP_HEADER_SIZE + XP_NASID_MASK_BYTES_SN2);
  2005. xpc_remote_copy_buffer_sn2 = xpc_kmalloc_cacheline_aligned(buf_size,
  2006. GFP_KERNEL,
  2007. &xpc_remote_copy_buffer_base_sn2);
  2008. if (xpc_remote_copy_buffer_sn2 == NULL) {
  2009. dev_err(xpc_part, "can't get memory for remote copy buffer\n");
  2010. return -ENOMEM;
  2011. }
  2012. /* open up protections for IPI and [potentially] amo operations */
  2013. xpc_allow_IPI_ops_sn2();
  2014. xpc_allow_amo_ops_shub_wars_1_1_sn2();
  2015. /*
  2016. * This is safe to do before the xpc_hb_checker thread has started
  2017. * because the handler releases a wait queue. If an interrupt is
  2018. * received before the thread is waiting, it will not go to sleep,
  2019. * but rather immediately process the interrupt.
  2020. */
  2021. ret = request_irq(SGI_XPC_ACTIVATE, xpc_handle_activate_IRQ_sn2, 0,
  2022. "xpc hb", NULL);
  2023. if (ret != 0) {
  2024. dev_err(xpc_part, "can't register ACTIVATE IRQ handler, "
  2025. "errno=%d\n", -ret);
  2026. xpc_disallow_IPI_ops_sn2();
  2027. kfree(xpc_remote_copy_buffer_base_sn2);
  2028. }
  2029. return ret;
  2030. }
  2031. void
  2032. xpc_exit_sn2(void)
  2033. {
  2034. free_irq(SGI_XPC_ACTIVATE, NULL);
  2035. xpc_disallow_IPI_ops_sn2();
  2036. kfree(xpc_remote_copy_buffer_base_sn2);
  2037. }