xpc_partition.c 25 KB

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