xpc_partition.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984
  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-2005 Silicon Graphics, Inc. All Rights Reserved.
  7. */
  8. /*
  9. * Cross Partition Communication (XPC) partition support.
  10. *
  11. * This is the part of XPC that detects the presence/absence of
  12. * other partitions. It provides a heartbeat and monitors the
  13. * heartbeats of other partitions.
  14. *
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/sysctl.h>
  18. #include <linux/cache.h>
  19. #include <linux/mmzone.h>
  20. #include <linux/nodemask.h>
  21. #include <asm/sn/bte.h>
  22. #include <asm/sn/intr.h>
  23. #include <asm/sn/sn_sal.h>
  24. #include <asm/sn/nodepda.h>
  25. #include <asm/sn/addrs.h>
  26. #include "xpc.h"
  27. /* XPC is exiting flag */
  28. int xpc_exiting;
  29. /* SH_IPI_ACCESS shub register value on startup */
  30. static u64 xpc_sh1_IPI_access;
  31. static u64 xpc_sh2_IPI_access0;
  32. static u64 xpc_sh2_IPI_access1;
  33. static u64 xpc_sh2_IPI_access2;
  34. static u64 xpc_sh2_IPI_access3;
  35. /* original protection values for each node */
  36. u64 xpc_prot_vec[MAX_COMPACT_NODES];
  37. /* this partition's reserved page */
  38. struct xpc_rsvd_page *xpc_rsvd_page;
  39. /* this partition's XPC variables (within the reserved page) */
  40. struct xpc_vars *xpc_vars;
  41. struct xpc_vars_part *xpc_vars_part;
  42. /*
  43. * For performance reasons, each entry of xpc_partitions[] is cacheline
  44. * aligned. And xpc_partitions[] is padded with an additional entry at the
  45. * end so that the last legitimate entry doesn't share its cacheline with
  46. * another variable.
  47. */
  48. struct xpc_partition xpc_partitions[XP_MAX_PARTITIONS + 1];
  49. /*
  50. * Generic buffer used to store a local copy of the remote partitions
  51. * reserved page or XPC variables.
  52. *
  53. * xpc_discovery runs only once and is a seperate thread that is
  54. * very likely going to be processing in parallel with receiving
  55. * interrupts.
  56. */
  57. char ____cacheline_aligned
  58. xpc_remote_copy_buffer[XPC_RSVD_PAGE_ALIGNED_SIZE];
  59. /* systune related variables */
  60. int xpc_hb_interval = XPC_HB_DEFAULT_INTERVAL;
  61. int xpc_hb_check_interval = XPC_HB_CHECK_DEFAULT_TIMEOUT;
  62. /*
  63. * Given a nasid, get the physical address of the partition's reserved page
  64. * for that nasid. This function returns 0 on any error.
  65. */
  66. static u64
  67. xpc_get_rsvd_page_pa(int nasid, u64 buf, u64 buf_size)
  68. {
  69. bte_result_t bte_res;
  70. s64 status;
  71. u64 cookie = 0;
  72. u64 rp_pa = nasid; /* seed with nasid */
  73. u64 len = 0;
  74. while (1) {
  75. status = sn_partition_reserved_page_pa(buf, &cookie, &rp_pa,
  76. &len);
  77. dev_dbg(xpc_part, "SAL returned with status=%li, cookie="
  78. "0x%016lx, address=0x%016lx, len=0x%016lx\n",
  79. status, cookie, rp_pa, len);
  80. if (status != SALRET_MORE_PASSES) {
  81. break;
  82. }
  83. if (len > buf_size) {
  84. dev_err(xpc_part, "len (=0x%016lx) > buf_size\n", len);
  85. status = SALRET_ERROR;
  86. break;
  87. }
  88. bte_res = xp_bte_copy(rp_pa, ia64_tpa(buf), buf_size,
  89. (BTE_NOTIFY | BTE_WACQUIRE), NULL);
  90. if (bte_res != BTE_SUCCESS) {
  91. dev_dbg(xpc_part, "xp_bte_copy failed %i\n", bte_res);
  92. status = SALRET_ERROR;
  93. break;
  94. }
  95. }
  96. if (status != SALRET_OK) {
  97. rp_pa = 0;
  98. }
  99. dev_dbg(xpc_part, "reserved page at phys address 0x%016lx\n", rp_pa);
  100. return rp_pa;
  101. }
  102. /*
  103. * Fill the partition reserved page with the information needed by
  104. * other partitions to discover we are alive and establish initial
  105. * communications.
  106. */
  107. struct xpc_rsvd_page *
  108. xpc_rsvd_page_init(void)
  109. {
  110. struct xpc_rsvd_page *rp;
  111. AMO_t *amos_page;
  112. u64 rp_pa, next_cl, nasid_array = 0;
  113. int i, ret;
  114. /* get the local reserved page's address */
  115. rp_pa = xpc_get_rsvd_page_pa(cnodeid_to_nasid(0),
  116. (u64) xpc_remote_copy_buffer,
  117. XPC_RSVD_PAGE_ALIGNED_SIZE);
  118. if (rp_pa == 0) {
  119. dev_err(xpc_part, "SAL failed to locate the reserved page\n");
  120. return NULL;
  121. }
  122. rp = (struct xpc_rsvd_page *) __va(rp_pa);
  123. if (rp->partid != sn_partition_id) {
  124. dev_err(xpc_part, "the reserved page's partid of %d should be "
  125. "%d\n", rp->partid, sn_partition_id);
  126. return NULL;
  127. }
  128. rp->version = XPC_RP_VERSION;
  129. /*
  130. * Place the XPC variables on the cache line following the
  131. * reserved page structure.
  132. */
  133. next_cl = (u64) rp + XPC_RSVD_PAGE_ALIGNED_SIZE;
  134. xpc_vars = (struct xpc_vars *) next_cl;
  135. /*
  136. * Before clearing xpc_vars, see if a page of AMOs had been previously
  137. * allocated. If not we'll need to allocate one and set permissions
  138. * so that cross-partition AMOs are allowed.
  139. *
  140. * The allocated AMO page needs MCA reporting to remain disabled after
  141. * XPC has unloaded. To make this work, we keep a copy of the pointer
  142. * to this page (i.e., amos_page) in the struct xpc_vars structure,
  143. * which is pointed to by the reserved page, and re-use that saved copy
  144. * on subsequent loads of XPC. This AMO page is never freed, and its
  145. * memory protections are never restricted.
  146. */
  147. if ((amos_page = xpc_vars->amos_page) == NULL) {
  148. amos_page = (AMO_t *) mspec_kalloc_page(0);
  149. if (amos_page == NULL) {
  150. dev_err(xpc_part, "can't allocate page of AMOs\n");
  151. return NULL;
  152. }
  153. /*
  154. * Open up AMO-R/W to cpu. This is done for Shub 1.1 systems
  155. * when xpc_allow_IPI_ops() is called via xpc_hb_init().
  156. */
  157. if (!enable_shub_wars_1_1()) {
  158. ret = sn_change_memprotect(ia64_tpa((u64) amos_page),
  159. PAGE_SIZE, SN_MEMPROT_ACCESS_CLASS_1,
  160. &nasid_array);
  161. if (ret != 0) {
  162. dev_err(xpc_part, "can't change memory "
  163. "protections\n");
  164. mspec_kfree_page((unsigned long) amos_page);
  165. return NULL;
  166. }
  167. }
  168. } else if (!IS_AMO_ADDRESS((u64) amos_page)) {
  169. /*
  170. * EFI's XPBOOT can also set amos_page in the reserved page,
  171. * but it happens to leave it as an uncached physical address
  172. * and we need it to be an uncached virtual, so we'll have to
  173. * convert it.
  174. */
  175. if (!IS_AMO_PHYS_ADDRESS((u64) amos_page)) {
  176. dev_err(xpc_part, "previously used amos_page address "
  177. "is bad = 0x%p\n", (void *) amos_page);
  178. return NULL;
  179. }
  180. amos_page = (AMO_t *) TO_AMO((u64) amos_page);
  181. }
  182. memset(xpc_vars, 0, sizeof(struct xpc_vars));
  183. /*
  184. * Place the XPC per partition specific variables on the cache line
  185. * following the XPC variables structure.
  186. */
  187. next_cl += XPC_VARS_ALIGNED_SIZE;
  188. memset((u64 *) next_cl, 0, sizeof(struct xpc_vars_part) *
  189. XP_MAX_PARTITIONS);
  190. xpc_vars_part = (struct xpc_vars_part *) next_cl;
  191. xpc_vars->vars_part_pa = __pa(next_cl);
  192. xpc_vars->version = XPC_V_VERSION;
  193. xpc_vars->act_nasid = cpuid_to_nasid(0);
  194. xpc_vars->act_phys_cpuid = cpu_physical_id(0);
  195. xpc_vars->amos_page = amos_page; /* save for next load of XPC */
  196. /*
  197. * Initialize the activation related AMO variables.
  198. */
  199. xpc_vars->act_amos = xpc_IPI_init(XP_MAX_PARTITIONS);
  200. for (i = 1; i < XP_NASID_MASK_WORDS; i++) {
  201. xpc_IPI_init(i + XP_MAX_PARTITIONS);
  202. }
  203. /* export AMO page's physical address to other partitions */
  204. xpc_vars->amos_page_pa = ia64_tpa((u64) xpc_vars->amos_page);
  205. /*
  206. * This signifies to the remote partition that our reserved
  207. * page is initialized.
  208. */
  209. (volatile u64) rp->vars_pa = __pa(xpc_vars);
  210. return rp;
  211. }
  212. /*
  213. * Change protections to allow IPI operations (and AMO operations on
  214. * Shub 1.1 systems).
  215. */
  216. void
  217. xpc_allow_IPI_ops(void)
  218. {
  219. int node;
  220. int nasid;
  221. // >>> Change SH_IPI_ACCESS code to use SAL call once it is available.
  222. if (is_shub2()) {
  223. xpc_sh2_IPI_access0 =
  224. (u64) HUB_L((u64 *) LOCAL_MMR_ADDR(SH2_IPI_ACCESS0));
  225. xpc_sh2_IPI_access1 =
  226. (u64) HUB_L((u64 *) LOCAL_MMR_ADDR(SH2_IPI_ACCESS1));
  227. xpc_sh2_IPI_access2 =
  228. (u64) HUB_L((u64 *) LOCAL_MMR_ADDR(SH2_IPI_ACCESS2));
  229. xpc_sh2_IPI_access3 =
  230. (u64) HUB_L((u64 *) LOCAL_MMR_ADDR(SH2_IPI_ACCESS3));
  231. for_each_online_node(node) {
  232. nasid = cnodeid_to_nasid(node);
  233. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS0),
  234. -1UL);
  235. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS1),
  236. -1UL);
  237. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS2),
  238. -1UL);
  239. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS3),
  240. -1UL);
  241. }
  242. } else {
  243. xpc_sh1_IPI_access =
  244. (u64) HUB_L((u64 *) LOCAL_MMR_ADDR(SH1_IPI_ACCESS));
  245. for_each_online_node(node) {
  246. nasid = cnodeid_to_nasid(node);
  247. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH1_IPI_ACCESS),
  248. -1UL);
  249. /*
  250. * Since the BIST collides with memory operations on
  251. * SHUB 1.1 sn_change_memprotect() cannot be used.
  252. */
  253. if (enable_shub_wars_1_1()) {
  254. /* open up everything */
  255. xpc_prot_vec[node] = (u64) HUB_L((u64 *)
  256. GLOBAL_MMR_ADDR(nasid,
  257. SH1_MD_DQLP_MMR_DIR_PRIVEC0));
  258. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid,
  259. SH1_MD_DQLP_MMR_DIR_PRIVEC0),
  260. -1UL);
  261. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid,
  262. SH1_MD_DQRP_MMR_DIR_PRIVEC0),
  263. -1UL);
  264. }
  265. }
  266. }
  267. }
  268. /*
  269. * Restrict protections to disallow IPI operations (and AMO operations on
  270. * Shub 1.1 systems).
  271. */
  272. void
  273. xpc_restrict_IPI_ops(void)
  274. {
  275. int node;
  276. int nasid;
  277. // >>> Change SH_IPI_ACCESS code to use SAL call once it is available.
  278. if (is_shub2()) {
  279. for_each_online_node(node) {
  280. nasid = cnodeid_to_nasid(node);
  281. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS0),
  282. xpc_sh2_IPI_access0);
  283. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS1),
  284. xpc_sh2_IPI_access1);
  285. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS2),
  286. xpc_sh2_IPI_access2);
  287. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS3),
  288. xpc_sh2_IPI_access3);
  289. }
  290. } else {
  291. for_each_online_node(node) {
  292. nasid = cnodeid_to_nasid(node);
  293. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH1_IPI_ACCESS),
  294. xpc_sh1_IPI_access);
  295. if (enable_shub_wars_1_1()) {
  296. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid,
  297. SH1_MD_DQLP_MMR_DIR_PRIVEC0),
  298. xpc_prot_vec[node]);
  299. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid,
  300. SH1_MD_DQRP_MMR_DIR_PRIVEC0),
  301. xpc_prot_vec[node]);
  302. }
  303. }
  304. }
  305. }
  306. /*
  307. * At periodic intervals, scan through all active partitions and ensure
  308. * their heartbeat is still active. If not, the partition is deactivated.
  309. */
  310. void
  311. xpc_check_remote_hb(void)
  312. {
  313. struct xpc_vars *remote_vars;
  314. struct xpc_partition *part;
  315. partid_t partid;
  316. bte_result_t bres;
  317. remote_vars = (struct xpc_vars *) xpc_remote_copy_buffer;
  318. for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) {
  319. if (partid == sn_partition_id) {
  320. continue;
  321. }
  322. part = &xpc_partitions[partid];
  323. if (part->act_state == XPC_P_INACTIVE ||
  324. part->act_state == XPC_P_DEACTIVATING) {
  325. continue;
  326. }
  327. /* pull the remote_hb cache line */
  328. bres = xp_bte_copy(part->remote_vars_pa,
  329. ia64_tpa((u64) remote_vars),
  330. XPC_VARS_ALIGNED_SIZE,
  331. (BTE_NOTIFY | BTE_WACQUIRE), NULL);
  332. if (bres != BTE_SUCCESS) {
  333. XPC_DEACTIVATE_PARTITION(part,
  334. xpc_map_bte_errors(bres));
  335. continue;
  336. }
  337. dev_dbg(xpc_part, "partid = %d, heartbeat = %ld, last_heartbeat"
  338. " = %ld, kdb_status = %ld, HB_mask = 0x%lx\n", partid,
  339. remote_vars->heartbeat, part->last_heartbeat,
  340. remote_vars->kdb_status,
  341. remote_vars->heartbeating_to_mask);
  342. if (((remote_vars->heartbeat == part->last_heartbeat) &&
  343. (remote_vars->kdb_status == 0)) ||
  344. !XPC_HB_ALLOWED(sn_partition_id, remote_vars)) {
  345. XPC_DEACTIVATE_PARTITION(part, xpcNoHeartbeat);
  346. continue;
  347. }
  348. part->last_heartbeat = remote_vars->heartbeat;
  349. }
  350. }
  351. /*
  352. * Get a copy of the remote partition's rsvd page.
  353. *
  354. * remote_rp points to a buffer that is cacheline aligned for BTE copies and
  355. * assumed to be of size XPC_RSVD_PAGE_ALIGNED_SIZE.
  356. */
  357. static enum xpc_retval
  358. xpc_get_remote_rp(int nasid, u64 *discovered_nasids,
  359. struct xpc_rsvd_page *remote_rp, u64 *remote_rsvd_page_pa)
  360. {
  361. int bres, i;
  362. /* get the reserved page's physical address */
  363. *remote_rsvd_page_pa = xpc_get_rsvd_page_pa(nasid, (u64) remote_rp,
  364. XPC_RSVD_PAGE_ALIGNED_SIZE);
  365. if (*remote_rsvd_page_pa == 0) {
  366. return xpcNoRsvdPageAddr;
  367. }
  368. /* pull over the reserved page structure */
  369. bres = xp_bte_copy(*remote_rsvd_page_pa, ia64_tpa((u64) remote_rp),
  370. XPC_RSVD_PAGE_ALIGNED_SIZE,
  371. (BTE_NOTIFY | BTE_WACQUIRE), NULL);
  372. if (bres != BTE_SUCCESS) {
  373. return xpc_map_bte_errors(bres);
  374. }
  375. if (discovered_nasids != NULL) {
  376. for (i = 0; i < XP_NASID_MASK_WORDS; i++) {
  377. discovered_nasids[i] |= remote_rp->part_nasids[i];
  378. }
  379. }
  380. /* check that the partid is for another partition */
  381. if (remote_rp->partid < 1 ||
  382. remote_rp->partid > (XP_MAX_PARTITIONS - 1)) {
  383. return xpcInvalidPartid;
  384. }
  385. if (remote_rp->partid == sn_partition_id) {
  386. return xpcLocalPartid;
  387. }
  388. if (XPC_VERSION_MAJOR(remote_rp->version) !=
  389. XPC_VERSION_MAJOR(XPC_RP_VERSION)) {
  390. return xpcBadVersion;
  391. }
  392. return xpcSuccess;
  393. }
  394. /*
  395. * Get a copy of the remote partition's XPC variables.
  396. *
  397. * remote_vars points to a buffer that is cacheline aligned for BTE copies and
  398. * assumed to be of size XPC_VARS_ALIGNED_SIZE.
  399. */
  400. static enum xpc_retval
  401. xpc_get_remote_vars(u64 remote_vars_pa, struct xpc_vars *remote_vars)
  402. {
  403. int bres;
  404. if (remote_vars_pa == 0) {
  405. return xpcVarsNotSet;
  406. }
  407. /* pull over the cross partition variables */
  408. bres = xp_bte_copy(remote_vars_pa, ia64_tpa((u64) remote_vars),
  409. XPC_VARS_ALIGNED_SIZE,
  410. (BTE_NOTIFY | BTE_WACQUIRE), NULL);
  411. if (bres != BTE_SUCCESS) {
  412. return xpc_map_bte_errors(bres);
  413. }
  414. if (XPC_VERSION_MAJOR(remote_vars->version) !=
  415. XPC_VERSION_MAJOR(XPC_V_VERSION)) {
  416. return xpcBadVersion;
  417. }
  418. return xpcSuccess;
  419. }
  420. /*
  421. * Prior code has determine the nasid which generated an IPI. Inspect
  422. * that nasid to determine if its partition needs to be activated or
  423. * deactivated.
  424. *
  425. * A partition is consider "awaiting activation" if our partition
  426. * flags indicate it is not active and it has a heartbeat. A
  427. * partition is considered "awaiting deactivation" if our partition
  428. * flags indicate it is active but it has no heartbeat or it is not
  429. * sending its heartbeat to us.
  430. *
  431. * To determine the heartbeat, the remote nasid must have a properly
  432. * initialized reserved page.
  433. */
  434. static void
  435. xpc_identify_act_IRQ_req(int nasid)
  436. {
  437. struct xpc_rsvd_page *remote_rp;
  438. struct xpc_vars *remote_vars;
  439. u64 remote_rsvd_page_pa;
  440. u64 remote_vars_pa;
  441. partid_t partid;
  442. struct xpc_partition *part;
  443. enum xpc_retval ret;
  444. /* pull over the reserved page structure */
  445. remote_rp = (struct xpc_rsvd_page *) xpc_remote_copy_buffer;
  446. ret = xpc_get_remote_rp(nasid, NULL, remote_rp, &remote_rsvd_page_pa);
  447. if (ret != xpcSuccess) {
  448. dev_warn(xpc_part, "unable to get reserved page from nasid %d, "
  449. "which sent interrupt, reason=%d\n", nasid, ret);
  450. return;
  451. }
  452. remote_vars_pa = remote_rp->vars_pa;
  453. partid = remote_rp->partid;
  454. part = &xpc_partitions[partid];
  455. /* pull over the cross partition variables */
  456. remote_vars = (struct xpc_vars *) xpc_remote_copy_buffer;
  457. ret = xpc_get_remote_vars(remote_vars_pa, remote_vars);
  458. if (ret != xpcSuccess) {
  459. dev_warn(xpc_part, "unable to get XPC variables from nasid %d, "
  460. "which sent interrupt, reason=%d\n", nasid, ret);
  461. XPC_DEACTIVATE_PARTITION(part, ret);
  462. return;
  463. }
  464. part->act_IRQ_rcvd++;
  465. dev_dbg(xpc_part, "partid for nasid %d is %d; IRQs = %d; HB = "
  466. "%ld:0x%lx\n", (int) nasid, (int) partid, part->act_IRQ_rcvd,
  467. remote_vars->heartbeat, remote_vars->heartbeating_to_mask);
  468. if (part->act_state == XPC_P_INACTIVE) {
  469. part->remote_rp_pa = remote_rsvd_page_pa;
  470. dev_dbg(xpc_part, " remote_rp_pa = 0x%016lx\n",
  471. part->remote_rp_pa);
  472. part->remote_vars_pa = remote_vars_pa;
  473. dev_dbg(xpc_part, " remote_vars_pa = 0x%016lx\n",
  474. part->remote_vars_pa);
  475. part->last_heartbeat = remote_vars->heartbeat;
  476. dev_dbg(xpc_part, " last_heartbeat = 0x%016lx\n",
  477. part->last_heartbeat);
  478. part->remote_vars_part_pa = remote_vars->vars_part_pa;
  479. dev_dbg(xpc_part, " remote_vars_part_pa = 0x%016lx\n",
  480. part->remote_vars_part_pa);
  481. part->remote_act_nasid = remote_vars->act_nasid;
  482. dev_dbg(xpc_part, " remote_act_nasid = 0x%x\n",
  483. part->remote_act_nasid);
  484. part->remote_act_phys_cpuid = remote_vars->act_phys_cpuid;
  485. dev_dbg(xpc_part, " remote_act_phys_cpuid = 0x%x\n",
  486. part->remote_act_phys_cpuid);
  487. part->remote_amos_page_pa = remote_vars->amos_page_pa;
  488. dev_dbg(xpc_part, " remote_amos_page_pa = 0x%lx\n",
  489. part->remote_amos_page_pa);
  490. xpc_activate_partition(part);
  491. } else if (part->remote_amos_page_pa != remote_vars->amos_page_pa ||
  492. !XPC_HB_ALLOWED(sn_partition_id, remote_vars)) {
  493. part->reactivate_nasid = nasid;
  494. XPC_DEACTIVATE_PARTITION(part, xpcReactivating);
  495. }
  496. }
  497. /*
  498. * Loop through the activation AMO variables and process any bits
  499. * which are set. Each bit indicates a nasid sending a partition
  500. * activation or deactivation request.
  501. *
  502. * Return #of IRQs detected.
  503. */
  504. int
  505. xpc_identify_act_IRQ_sender(void)
  506. {
  507. int word, bit;
  508. u64 nasid_mask;
  509. u64 nasid; /* remote nasid */
  510. int n_IRQs_detected = 0;
  511. AMO_t *act_amos;
  512. struct xpc_rsvd_page *rp = (struct xpc_rsvd_page *) xpc_rsvd_page;
  513. act_amos = xpc_vars->act_amos;
  514. /* scan through act AMO variable looking for non-zero entries */
  515. for (word = 0; word < XP_NASID_MASK_WORDS; word++) {
  516. nasid_mask = xpc_IPI_receive(&act_amos[word]);
  517. if (nasid_mask == 0) {
  518. /* no IRQs from nasids in this variable */
  519. continue;
  520. }
  521. dev_dbg(xpc_part, "AMO[%d] gave back 0x%lx\n", word,
  522. nasid_mask);
  523. /*
  524. * If this nasid has been added to the machine since
  525. * our partition was reset, this will retain the
  526. * remote nasid in our reserved pages machine mask.
  527. * This is used in the event of module reload.
  528. */
  529. rp->mach_nasids[word] |= nasid_mask;
  530. /* locate the nasid(s) which sent interrupts */
  531. for (bit = 0; bit < (8 * sizeof(u64)); bit++) {
  532. if (nasid_mask & (1UL << bit)) {
  533. n_IRQs_detected++;
  534. nasid = XPC_NASID_FROM_W_B(word, bit);
  535. dev_dbg(xpc_part, "interrupt from nasid %ld\n",
  536. nasid);
  537. xpc_identify_act_IRQ_req(nasid);
  538. }
  539. }
  540. }
  541. return n_IRQs_detected;
  542. }
  543. /*
  544. * Mark specified partition as active.
  545. */
  546. enum xpc_retval
  547. xpc_mark_partition_active(struct xpc_partition *part)
  548. {
  549. unsigned long irq_flags;
  550. enum xpc_retval ret;
  551. dev_dbg(xpc_part, "setting partition %d to ACTIVE\n", XPC_PARTID(part));
  552. spin_lock_irqsave(&part->act_lock, irq_flags);
  553. if (part->act_state == XPC_P_ACTIVATING) {
  554. part->act_state = XPC_P_ACTIVE;
  555. ret = xpcSuccess;
  556. } else {
  557. DBUG_ON(part->reason == xpcSuccess);
  558. ret = part->reason;
  559. }
  560. spin_unlock_irqrestore(&part->act_lock, irq_flags);
  561. return ret;
  562. }
  563. /*
  564. * Notify XPC that the partition is down.
  565. */
  566. void
  567. xpc_deactivate_partition(const int line, struct xpc_partition *part,
  568. enum xpc_retval reason)
  569. {
  570. unsigned long irq_flags;
  571. partid_t partid = XPC_PARTID(part);
  572. spin_lock_irqsave(&part->act_lock, irq_flags);
  573. if (part->act_state == XPC_P_INACTIVE) {
  574. XPC_SET_REASON(part, reason, line);
  575. spin_unlock_irqrestore(&part->act_lock, irq_flags);
  576. if (reason == xpcReactivating) {
  577. /* we interrupt ourselves to reactivate partition */
  578. xpc_IPI_send_reactivate(part);
  579. }
  580. return;
  581. }
  582. if (part->act_state == XPC_P_DEACTIVATING) {
  583. if ((part->reason == xpcUnloading && reason != xpcUnloading) ||
  584. reason == xpcReactivating) {
  585. XPC_SET_REASON(part, reason, line);
  586. }
  587. spin_unlock_irqrestore(&part->act_lock, irq_flags);
  588. return;
  589. }
  590. part->act_state = XPC_P_DEACTIVATING;
  591. XPC_SET_REASON(part, reason, line);
  592. spin_unlock_irqrestore(&part->act_lock, irq_flags);
  593. XPC_DISALLOW_HB(partid, xpc_vars);
  594. dev_dbg(xpc_part, "bringing partition %d down, reason = %d\n", partid,
  595. reason);
  596. xpc_partition_down(part, reason);
  597. }
  598. /*
  599. * Mark specified partition as active.
  600. */
  601. void
  602. xpc_mark_partition_inactive(struct xpc_partition *part)
  603. {
  604. unsigned long irq_flags;
  605. dev_dbg(xpc_part, "setting partition %d to INACTIVE\n",
  606. XPC_PARTID(part));
  607. spin_lock_irqsave(&part->act_lock, irq_flags);
  608. part->act_state = XPC_P_INACTIVE;
  609. spin_unlock_irqrestore(&part->act_lock, irq_flags);
  610. part->remote_rp_pa = 0;
  611. }
  612. /*
  613. * SAL has provided a partition and machine mask. The partition mask
  614. * contains a bit for each even nasid in our partition. The machine
  615. * mask contains a bit for each even nasid in the entire machine.
  616. *
  617. * Using those two bit arrays, we can determine which nasids are
  618. * known in the machine. Each should also have a reserved page
  619. * initialized if they are available for partitioning.
  620. */
  621. void
  622. xpc_discovery(void)
  623. {
  624. void *remote_rp_base;
  625. struct xpc_rsvd_page *remote_rp;
  626. struct xpc_vars *remote_vars;
  627. u64 remote_rsvd_page_pa;
  628. u64 remote_vars_pa;
  629. int region;
  630. int max_regions;
  631. int nasid;
  632. struct xpc_rsvd_page *rp;
  633. partid_t partid;
  634. struct xpc_partition *part;
  635. u64 *discovered_nasids;
  636. enum xpc_retval ret;
  637. remote_rp = xpc_kmalloc_cacheline_aligned(XPC_RSVD_PAGE_ALIGNED_SIZE,
  638. GFP_KERNEL, &remote_rp_base);
  639. if (remote_rp == NULL) {
  640. return;
  641. }
  642. remote_vars = (struct xpc_vars *) remote_rp;
  643. discovered_nasids = kmalloc(sizeof(u64) * XP_NASID_MASK_WORDS,
  644. GFP_KERNEL);
  645. if (discovered_nasids == NULL) {
  646. kfree(remote_rp_base);
  647. return;
  648. }
  649. memset(discovered_nasids, 0, sizeof(u64) * XP_NASID_MASK_WORDS);
  650. rp = (struct xpc_rsvd_page *) xpc_rsvd_page;
  651. /*
  652. * The term 'region' in this context refers to the minimum number of
  653. * nodes that can comprise an access protection grouping. The access
  654. * protection is in regards to memory, IOI and IPI.
  655. */
  656. //>>> move the next two #defines into either include/asm-ia64/sn/arch.h or
  657. //>>> include/asm-ia64/sn/addrs.h
  658. #define SH1_MAX_REGIONS 64
  659. #define SH2_MAX_REGIONS 256
  660. max_regions = is_shub2() ? SH2_MAX_REGIONS : SH1_MAX_REGIONS;
  661. for (region = 0; region < max_regions; region++) {
  662. if ((volatile int) xpc_exiting) {
  663. break;
  664. }
  665. dev_dbg(xpc_part, "searching region %d\n", region);
  666. for (nasid = (region * sn_region_size * 2);
  667. nasid < ((region + 1) * sn_region_size * 2);
  668. nasid += 2) {
  669. if ((volatile int) xpc_exiting) {
  670. break;
  671. }
  672. dev_dbg(xpc_part, "checking nasid %d\n", nasid);
  673. if (XPC_NASID_IN_ARRAY(nasid, rp->part_nasids)) {
  674. dev_dbg(xpc_part, "PROM indicates Nasid %d is "
  675. "part of the local partition; skipping "
  676. "region\n", nasid);
  677. break;
  678. }
  679. if (!(XPC_NASID_IN_ARRAY(nasid, rp->mach_nasids))) {
  680. dev_dbg(xpc_part, "PROM indicates Nasid %d was "
  681. "not on Numa-Link network at reset\n",
  682. nasid);
  683. continue;
  684. }
  685. if (XPC_NASID_IN_ARRAY(nasid, discovered_nasids)) {
  686. dev_dbg(xpc_part, "Nasid %d is part of a "
  687. "partition which was previously "
  688. "discovered\n", nasid);
  689. continue;
  690. }
  691. /* pull over the reserved page structure */
  692. ret = xpc_get_remote_rp(nasid, discovered_nasids,
  693. remote_rp, &remote_rsvd_page_pa);
  694. if (ret != xpcSuccess) {
  695. dev_dbg(xpc_part, "unable to get reserved page "
  696. "from nasid %d, reason=%d\n", nasid,
  697. ret);
  698. if (ret == xpcLocalPartid) {
  699. break;
  700. }
  701. continue;
  702. }
  703. remote_vars_pa = remote_rp->vars_pa;
  704. partid = remote_rp->partid;
  705. part = &xpc_partitions[partid];
  706. /* pull over the cross partition variables */
  707. ret = xpc_get_remote_vars(remote_vars_pa, remote_vars);
  708. if (ret != xpcSuccess) {
  709. dev_dbg(xpc_part, "unable to get XPC variables "
  710. "from nasid %d, reason=%d\n", nasid,
  711. ret);
  712. XPC_DEACTIVATE_PARTITION(part, ret);
  713. continue;
  714. }
  715. if (part->act_state != XPC_P_INACTIVE) {
  716. dev_dbg(xpc_part, "partition %d on nasid %d is "
  717. "already activating\n", partid, nasid);
  718. break;
  719. }
  720. /*
  721. * Register the remote partition's AMOs with SAL so it
  722. * can handle and cleanup errors within that address
  723. * range should the remote partition go down. We don't
  724. * unregister this range because it is difficult to
  725. * tell when outstanding writes to the remote partition
  726. * are finished and thus when it is thus safe to
  727. * unregister. This should not result in wasted space
  728. * in the SAL xp_addr_region table because we should
  729. * get the same page for remote_act_amos_pa after
  730. * module reloads and system reboots.
  731. */
  732. if (sn_register_xp_addr_region(
  733. remote_vars->amos_page_pa,
  734. PAGE_SIZE, 1) < 0) {
  735. dev_dbg(xpc_part, "partition %d failed to "
  736. "register xp_addr region 0x%016lx\n",
  737. partid, remote_vars->amos_page_pa);
  738. XPC_SET_REASON(part, xpcPhysAddrRegFailed,
  739. __LINE__);
  740. break;
  741. }
  742. /*
  743. * The remote nasid is valid and available.
  744. * Send an interrupt to that nasid to notify
  745. * it that we are ready to begin activation.
  746. */
  747. dev_dbg(xpc_part, "sending an interrupt to AMO 0x%lx, "
  748. "nasid %d, phys_cpuid 0x%x\n",
  749. remote_vars->amos_page_pa,
  750. remote_vars->act_nasid,
  751. remote_vars->act_phys_cpuid);
  752. xpc_IPI_send_activate(remote_vars);
  753. }
  754. }
  755. kfree(discovered_nasids);
  756. kfree(remote_rp_base);
  757. }
  758. /*
  759. * Given a partid, get the nasids owned by that partition from the
  760. * remote partition's reserved page.
  761. */
  762. enum xpc_retval
  763. xpc_initiate_partid_to_nasids(partid_t partid, void *nasid_mask)
  764. {
  765. struct xpc_partition *part;
  766. u64 part_nasid_pa;
  767. int bte_res;
  768. part = &xpc_partitions[partid];
  769. if (part->remote_rp_pa == 0) {
  770. return xpcPartitionDown;
  771. }
  772. part_nasid_pa = part->remote_rp_pa +
  773. (u64) &((struct xpc_rsvd_page *) 0)->part_nasids;
  774. bte_res = xp_bte_copy(part_nasid_pa, ia64_tpa((u64) nasid_mask),
  775. L1_CACHE_ALIGN(XP_NASID_MASK_BYTES),
  776. (BTE_NOTIFY | BTE_WACQUIRE), NULL);
  777. return xpc_map_bte_errors(bte_res);
  778. }