xpc_partition.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971
  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. }
  169. memset(xpc_vars, 0, sizeof(struct xpc_vars));
  170. /*
  171. * Place the XPC per partition specific variables on the cache line
  172. * following the XPC variables structure.
  173. */
  174. next_cl += XPC_VARS_ALIGNED_SIZE;
  175. memset((u64 *) next_cl, 0, sizeof(struct xpc_vars_part) *
  176. XP_MAX_PARTITIONS);
  177. xpc_vars_part = (struct xpc_vars_part *) next_cl;
  178. xpc_vars->vars_part_pa = __pa(next_cl);
  179. xpc_vars->version = XPC_V_VERSION;
  180. xpc_vars->act_nasid = cpuid_to_nasid(0);
  181. xpc_vars->act_phys_cpuid = cpu_physical_id(0);
  182. xpc_vars->amos_page = amos_page; /* save for next load of XPC */
  183. /*
  184. * Initialize the activation related AMO variables.
  185. */
  186. xpc_vars->act_amos = xpc_IPI_init(XP_MAX_PARTITIONS);
  187. for (i = 1; i < XP_NASID_MASK_WORDS; i++) {
  188. xpc_IPI_init(i + XP_MAX_PARTITIONS);
  189. }
  190. /* export AMO page's physical address to other partitions */
  191. xpc_vars->amos_page_pa = ia64_tpa((u64) xpc_vars->amos_page);
  192. /*
  193. * This signifies to the remote partition that our reserved
  194. * page is initialized.
  195. */
  196. (volatile u64) rp->vars_pa = __pa(xpc_vars);
  197. return rp;
  198. }
  199. /*
  200. * Change protections to allow IPI operations (and AMO operations on
  201. * Shub 1.1 systems).
  202. */
  203. void
  204. xpc_allow_IPI_ops(void)
  205. {
  206. int node;
  207. int nasid;
  208. // >>> Change SH_IPI_ACCESS code to use SAL call once it is available.
  209. if (is_shub2()) {
  210. xpc_sh2_IPI_access0 =
  211. (u64) HUB_L((u64 *) LOCAL_MMR_ADDR(SH2_IPI_ACCESS0));
  212. xpc_sh2_IPI_access1 =
  213. (u64) HUB_L((u64 *) LOCAL_MMR_ADDR(SH2_IPI_ACCESS1));
  214. xpc_sh2_IPI_access2 =
  215. (u64) HUB_L((u64 *) LOCAL_MMR_ADDR(SH2_IPI_ACCESS2));
  216. xpc_sh2_IPI_access3 =
  217. (u64) HUB_L((u64 *) LOCAL_MMR_ADDR(SH2_IPI_ACCESS3));
  218. for_each_online_node(node) {
  219. nasid = cnodeid_to_nasid(node);
  220. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS0),
  221. -1UL);
  222. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS1),
  223. -1UL);
  224. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS2),
  225. -1UL);
  226. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS3),
  227. -1UL);
  228. }
  229. } else {
  230. xpc_sh1_IPI_access =
  231. (u64) HUB_L((u64 *) LOCAL_MMR_ADDR(SH1_IPI_ACCESS));
  232. for_each_online_node(node) {
  233. nasid = cnodeid_to_nasid(node);
  234. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH1_IPI_ACCESS),
  235. -1UL);
  236. /*
  237. * Since the BIST collides with memory operations on
  238. * SHUB 1.1 sn_change_memprotect() cannot be used.
  239. */
  240. if (enable_shub_wars_1_1()) {
  241. /* open up everything */
  242. xpc_prot_vec[node] = (u64) HUB_L((u64 *)
  243. GLOBAL_MMR_ADDR(nasid,
  244. SH1_MD_DQLP_MMR_DIR_PRIVEC0));
  245. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid,
  246. SH1_MD_DQLP_MMR_DIR_PRIVEC0),
  247. -1UL);
  248. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid,
  249. SH1_MD_DQRP_MMR_DIR_PRIVEC0),
  250. -1UL);
  251. }
  252. }
  253. }
  254. }
  255. /*
  256. * Restrict protections to disallow IPI operations (and AMO operations on
  257. * Shub 1.1 systems).
  258. */
  259. void
  260. xpc_restrict_IPI_ops(void)
  261. {
  262. int node;
  263. int nasid;
  264. // >>> Change SH_IPI_ACCESS code to use SAL call once it is available.
  265. if (is_shub2()) {
  266. for_each_online_node(node) {
  267. nasid = cnodeid_to_nasid(node);
  268. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS0),
  269. xpc_sh2_IPI_access0);
  270. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS1),
  271. xpc_sh2_IPI_access1);
  272. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS2),
  273. xpc_sh2_IPI_access2);
  274. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS3),
  275. xpc_sh2_IPI_access3);
  276. }
  277. } else {
  278. for_each_online_node(node) {
  279. nasid = cnodeid_to_nasid(node);
  280. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH1_IPI_ACCESS),
  281. xpc_sh1_IPI_access);
  282. if (enable_shub_wars_1_1()) {
  283. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid,
  284. SH1_MD_DQLP_MMR_DIR_PRIVEC0),
  285. xpc_prot_vec[node]);
  286. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid,
  287. SH1_MD_DQRP_MMR_DIR_PRIVEC0),
  288. xpc_prot_vec[node]);
  289. }
  290. }
  291. }
  292. }
  293. /*
  294. * At periodic intervals, scan through all active partitions and ensure
  295. * their heartbeat is still active. If not, the partition is deactivated.
  296. */
  297. void
  298. xpc_check_remote_hb(void)
  299. {
  300. struct xpc_vars *remote_vars;
  301. struct xpc_partition *part;
  302. partid_t partid;
  303. bte_result_t bres;
  304. remote_vars = (struct xpc_vars *) xpc_remote_copy_buffer;
  305. for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) {
  306. if (partid == sn_partition_id) {
  307. continue;
  308. }
  309. part = &xpc_partitions[partid];
  310. if (part->act_state == XPC_P_INACTIVE ||
  311. part->act_state == XPC_P_DEACTIVATING) {
  312. continue;
  313. }
  314. /* pull the remote_hb cache line */
  315. bres = xp_bte_copy(part->remote_vars_pa,
  316. ia64_tpa((u64) remote_vars),
  317. XPC_VARS_ALIGNED_SIZE,
  318. (BTE_NOTIFY | BTE_WACQUIRE), NULL);
  319. if (bres != BTE_SUCCESS) {
  320. XPC_DEACTIVATE_PARTITION(part,
  321. xpc_map_bte_errors(bres));
  322. continue;
  323. }
  324. dev_dbg(xpc_part, "partid = %d, heartbeat = %ld, last_heartbeat"
  325. " = %ld, kdb_status = %ld, HB_mask = 0x%lx\n", partid,
  326. remote_vars->heartbeat, part->last_heartbeat,
  327. remote_vars->kdb_status,
  328. remote_vars->heartbeating_to_mask);
  329. if (((remote_vars->heartbeat == part->last_heartbeat) &&
  330. (remote_vars->kdb_status == 0)) ||
  331. !XPC_HB_ALLOWED(sn_partition_id, remote_vars)) {
  332. XPC_DEACTIVATE_PARTITION(part, xpcNoHeartbeat);
  333. continue;
  334. }
  335. part->last_heartbeat = remote_vars->heartbeat;
  336. }
  337. }
  338. /*
  339. * Get a copy of the remote partition's rsvd page.
  340. *
  341. * remote_rp points to a buffer that is cacheline aligned for BTE copies and
  342. * assumed to be of size XPC_RSVD_PAGE_ALIGNED_SIZE.
  343. */
  344. static enum xpc_retval
  345. xpc_get_remote_rp(int nasid, u64 *discovered_nasids,
  346. struct xpc_rsvd_page *remote_rp, u64 *remote_rsvd_page_pa)
  347. {
  348. int bres, i;
  349. /* get the reserved page's physical address */
  350. *remote_rsvd_page_pa = xpc_get_rsvd_page_pa(nasid, (u64) remote_rp,
  351. XPC_RSVD_PAGE_ALIGNED_SIZE);
  352. if (*remote_rsvd_page_pa == 0) {
  353. return xpcNoRsvdPageAddr;
  354. }
  355. /* pull over the reserved page structure */
  356. bres = xp_bte_copy(*remote_rsvd_page_pa, ia64_tpa((u64) remote_rp),
  357. XPC_RSVD_PAGE_ALIGNED_SIZE,
  358. (BTE_NOTIFY | BTE_WACQUIRE), NULL);
  359. if (bres != BTE_SUCCESS) {
  360. return xpc_map_bte_errors(bres);
  361. }
  362. if (discovered_nasids != NULL) {
  363. for (i = 0; i < XP_NASID_MASK_WORDS; i++) {
  364. discovered_nasids[i] |= remote_rp->part_nasids[i];
  365. }
  366. }
  367. /* check that the partid is for another partition */
  368. if (remote_rp->partid < 1 ||
  369. remote_rp->partid > (XP_MAX_PARTITIONS - 1)) {
  370. return xpcInvalidPartid;
  371. }
  372. if (remote_rp->partid == sn_partition_id) {
  373. return xpcLocalPartid;
  374. }
  375. if (XPC_VERSION_MAJOR(remote_rp->version) !=
  376. XPC_VERSION_MAJOR(XPC_RP_VERSION)) {
  377. return xpcBadVersion;
  378. }
  379. return xpcSuccess;
  380. }
  381. /*
  382. * Get a copy of the remote partition's XPC variables.
  383. *
  384. * remote_vars points to a buffer that is cacheline aligned for BTE copies and
  385. * assumed to be of size XPC_VARS_ALIGNED_SIZE.
  386. */
  387. static enum xpc_retval
  388. xpc_get_remote_vars(u64 remote_vars_pa, struct xpc_vars *remote_vars)
  389. {
  390. int bres;
  391. if (remote_vars_pa == 0) {
  392. return xpcVarsNotSet;
  393. }
  394. /* pull over the cross partition variables */
  395. bres = xp_bte_copy(remote_vars_pa, ia64_tpa((u64) remote_vars),
  396. XPC_VARS_ALIGNED_SIZE,
  397. (BTE_NOTIFY | BTE_WACQUIRE), NULL);
  398. if (bres != BTE_SUCCESS) {
  399. return xpc_map_bte_errors(bres);
  400. }
  401. if (XPC_VERSION_MAJOR(remote_vars->version) !=
  402. XPC_VERSION_MAJOR(XPC_V_VERSION)) {
  403. return xpcBadVersion;
  404. }
  405. return xpcSuccess;
  406. }
  407. /*
  408. * Prior code has determine the nasid which generated an IPI. Inspect
  409. * that nasid to determine if its partition needs to be activated or
  410. * deactivated.
  411. *
  412. * A partition is consider "awaiting activation" if our partition
  413. * flags indicate it is not active and it has a heartbeat. A
  414. * partition is considered "awaiting deactivation" if our partition
  415. * flags indicate it is active but it has no heartbeat or it is not
  416. * sending its heartbeat to us.
  417. *
  418. * To determine the heartbeat, the remote nasid must have a properly
  419. * initialized reserved page.
  420. */
  421. static void
  422. xpc_identify_act_IRQ_req(int nasid)
  423. {
  424. struct xpc_rsvd_page *remote_rp;
  425. struct xpc_vars *remote_vars;
  426. u64 remote_rsvd_page_pa;
  427. u64 remote_vars_pa;
  428. partid_t partid;
  429. struct xpc_partition *part;
  430. enum xpc_retval ret;
  431. /* pull over the reserved page structure */
  432. remote_rp = (struct xpc_rsvd_page *) xpc_remote_copy_buffer;
  433. ret = xpc_get_remote_rp(nasid, NULL, remote_rp, &remote_rsvd_page_pa);
  434. if (ret != xpcSuccess) {
  435. dev_warn(xpc_part, "unable to get reserved page from nasid %d, "
  436. "which sent interrupt, reason=%d\n", nasid, ret);
  437. return;
  438. }
  439. remote_vars_pa = remote_rp->vars_pa;
  440. partid = remote_rp->partid;
  441. part = &xpc_partitions[partid];
  442. /* pull over the cross partition variables */
  443. remote_vars = (struct xpc_vars *) xpc_remote_copy_buffer;
  444. ret = xpc_get_remote_vars(remote_vars_pa, remote_vars);
  445. if (ret != xpcSuccess) {
  446. dev_warn(xpc_part, "unable to get XPC variables from nasid %d, "
  447. "which sent interrupt, reason=%d\n", nasid, ret);
  448. XPC_DEACTIVATE_PARTITION(part, ret);
  449. return;
  450. }
  451. part->act_IRQ_rcvd++;
  452. dev_dbg(xpc_part, "partid for nasid %d is %d; IRQs = %d; HB = "
  453. "%ld:0x%lx\n", (int) nasid, (int) partid, part->act_IRQ_rcvd,
  454. remote_vars->heartbeat, remote_vars->heartbeating_to_mask);
  455. if (part->act_state == XPC_P_INACTIVE) {
  456. part->remote_rp_pa = remote_rsvd_page_pa;
  457. dev_dbg(xpc_part, " remote_rp_pa = 0x%016lx\n",
  458. part->remote_rp_pa);
  459. part->remote_vars_pa = remote_vars_pa;
  460. dev_dbg(xpc_part, " remote_vars_pa = 0x%016lx\n",
  461. part->remote_vars_pa);
  462. part->last_heartbeat = remote_vars->heartbeat;
  463. dev_dbg(xpc_part, " last_heartbeat = 0x%016lx\n",
  464. part->last_heartbeat);
  465. part->remote_vars_part_pa = remote_vars->vars_part_pa;
  466. dev_dbg(xpc_part, " remote_vars_part_pa = 0x%016lx\n",
  467. part->remote_vars_part_pa);
  468. part->remote_act_nasid = remote_vars->act_nasid;
  469. dev_dbg(xpc_part, " remote_act_nasid = 0x%x\n",
  470. part->remote_act_nasid);
  471. part->remote_act_phys_cpuid = remote_vars->act_phys_cpuid;
  472. dev_dbg(xpc_part, " remote_act_phys_cpuid = 0x%x\n",
  473. part->remote_act_phys_cpuid);
  474. part->remote_amos_page_pa = remote_vars->amos_page_pa;
  475. dev_dbg(xpc_part, " remote_amos_page_pa = 0x%lx\n",
  476. part->remote_amos_page_pa);
  477. xpc_activate_partition(part);
  478. } else if (part->remote_amos_page_pa != remote_vars->amos_page_pa ||
  479. !XPC_HB_ALLOWED(sn_partition_id, remote_vars)) {
  480. part->reactivate_nasid = nasid;
  481. XPC_DEACTIVATE_PARTITION(part, xpcReactivating);
  482. }
  483. }
  484. /*
  485. * Loop through the activation AMO variables and process any bits
  486. * which are set. Each bit indicates a nasid sending a partition
  487. * activation or deactivation request.
  488. *
  489. * Return #of IRQs detected.
  490. */
  491. int
  492. xpc_identify_act_IRQ_sender(void)
  493. {
  494. int word, bit;
  495. u64 nasid_mask;
  496. u64 nasid; /* remote nasid */
  497. int n_IRQs_detected = 0;
  498. AMO_t *act_amos;
  499. struct xpc_rsvd_page *rp = (struct xpc_rsvd_page *) xpc_rsvd_page;
  500. act_amos = xpc_vars->act_amos;
  501. /* scan through act AMO variable looking for non-zero entries */
  502. for (word = 0; word < XP_NASID_MASK_WORDS; word++) {
  503. nasid_mask = xpc_IPI_receive(&act_amos[word]);
  504. if (nasid_mask == 0) {
  505. /* no IRQs from nasids in this variable */
  506. continue;
  507. }
  508. dev_dbg(xpc_part, "AMO[%d] gave back 0x%lx\n", word,
  509. nasid_mask);
  510. /*
  511. * If this nasid has been added to the machine since
  512. * our partition was reset, this will retain the
  513. * remote nasid in our reserved pages machine mask.
  514. * This is used in the event of module reload.
  515. */
  516. rp->mach_nasids[word] |= nasid_mask;
  517. /* locate the nasid(s) which sent interrupts */
  518. for (bit = 0; bit < (8 * sizeof(u64)); bit++) {
  519. if (nasid_mask & (1UL << bit)) {
  520. n_IRQs_detected++;
  521. nasid = XPC_NASID_FROM_W_B(word, bit);
  522. dev_dbg(xpc_part, "interrupt from nasid %ld\n",
  523. nasid);
  524. xpc_identify_act_IRQ_req(nasid);
  525. }
  526. }
  527. }
  528. return n_IRQs_detected;
  529. }
  530. /*
  531. * Mark specified partition as active.
  532. */
  533. enum xpc_retval
  534. xpc_mark_partition_active(struct xpc_partition *part)
  535. {
  536. unsigned long irq_flags;
  537. enum xpc_retval ret;
  538. dev_dbg(xpc_part, "setting partition %d to ACTIVE\n", XPC_PARTID(part));
  539. spin_lock_irqsave(&part->act_lock, irq_flags);
  540. if (part->act_state == XPC_P_ACTIVATING) {
  541. part->act_state = XPC_P_ACTIVE;
  542. ret = xpcSuccess;
  543. } else {
  544. DBUG_ON(part->reason == xpcSuccess);
  545. ret = part->reason;
  546. }
  547. spin_unlock_irqrestore(&part->act_lock, irq_flags);
  548. return ret;
  549. }
  550. /*
  551. * Notify XPC that the partition is down.
  552. */
  553. void
  554. xpc_deactivate_partition(const int line, struct xpc_partition *part,
  555. enum xpc_retval reason)
  556. {
  557. unsigned long irq_flags;
  558. partid_t partid = XPC_PARTID(part);
  559. spin_lock_irqsave(&part->act_lock, irq_flags);
  560. if (part->act_state == XPC_P_INACTIVE) {
  561. XPC_SET_REASON(part, reason, line);
  562. spin_unlock_irqrestore(&part->act_lock, irq_flags);
  563. if (reason == xpcReactivating) {
  564. /* we interrupt ourselves to reactivate partition */
  565. xpc_IPI_send_reactivate(part);
  566. }
  567. return;
  568. }
  569. if (part->act_state == XPC_P_DEACTIVATING) {
  570. if ((part->reason == xpcUnloading && reason != xpcUnloading) ||
  571. reason == xpcReactivating) {
  572. XPC_SET_REASON(part, reason, line);
  573. }
  574. spin_unlock_irqrestore(&part->act_lock, irq_flags);
  575. return;
  576. }
  577. part->act_state = XPC_P_DEACTIVATING;
  578. XPC_SET_REASON(part, reason, line);
  579. spin_unlock_irqrestore(&part->act_lock, irq_flags);
  580. XPC_DISALLOW_HB(partid, xpc_vars);
  581. dev_dbg(xpc_part, "bringing partition %d down, reason = %d\n", partid,
  582. reason);
  583. xpc_partition_down(part, reason);
  584. }
  585. /*
  586. * Mark specified partition as active.
  587. */
  588. void
  589. xpc_mark_partition_inactive(struct xpc_partition *part)
  590. {
  591. unsigned long irq_flags;
  592. dev_dbg(xpc_part, "setting partition %d to INACTIVE\n",
  593. XPC_PARTID(part));
  594. spin_lock_irqsave(&part->act_lock, irq_flags);
  595. part->act_state = XPC_P_INACTIVE;
  596. spin_unlock_irqrestore(&part->act_lock, irq_flags);
  597. part->remote_rp_pa = 0;
  598. }
  599. /*
  600. * SAL has provided a partition and machine mask. The partition mask
  601. * contains a bit for each even nasid in our partition. The machine
  602. * mask contains a bit for each even nasid in the entire machine.
  603. *
  604. * Using those two bit arrays, we can determine which nasids are
  605. * known in the machine. Each should also have a reserved page
  606. * initialized if they are available for partitioning.
  607. */
  608. void
  609. xpc_discovery(void)
  610. {
  611. void *remote_rp_base;
  612. struct xpc_rsvd_page *remote_rp;
  613. struct xpc_vars *remote_vars;
  614. u64 remote_rsvd_page_pa;
  615. u64 remote_vars_pa;
  616. int region;
  617. int max_regions;
  618. int nasid;
  619. struct xpc_rsvd_page *rp;
  620. partid_t partid;
  621. struct xpc_partition *part;
  622. u64 *discovered_nasids;
  623. enum xpc_retval ret;
  624. remote_rp = xpc_kmalloc_cacheline_aligned(XPC_RSVD_PAGE_ALIGNED_SIZE,
  625. GFP_KERNEL, &remote_rp_base);
  626. if (remote_rp == NULL) {
  627. return;
  628. }
  629. remote_vars = (struct xpc_vars *) remote_rp;
  630. discovered_nasids = kmalloc(sizeof(u64) * XP_NASID_MASK_WORDS,
  631. GFP_KERNEL);
  632. if (discovered_nasids == NULL) {
  633. kfree(remote_rp_base);
  634. return;
  635. }
  636. memset(discovered_nasids, 0, sizeof(u64) * XP_NASID_MASK_WORDS);
  637. rp = (struct xpc_rsvd_page *) xpc_rsvd_page;
  638. /*
  639. * The term 'region' in this context refers to the minimum number of
  640. * nodes that can comprise an access protection grouping. The access
  641. * protection is in regards to memory, IOI and IPI.
  642. */
  643. //>>> move the next two #defines into either include/asm-ia64/sn/arch.h or
  644. //>>> include/asm-ia64/sn/addrs.h
  645. #define SH1_MAX_REGIONS 64
  646. #define SH2_MAX_REGIONS 256
  647. max_regions = is_shub2() ? SH2_MAX_REGIONS : SH1_MAX_REGIONS;
  648. for (region = 0; region < max_regions; region++) {
  649. if ((volatile int) xpc_exiting) {
  650. break;
  651. }
  652. dev_dbg(xpc_part, "searching region %d\n", region);
  653. for (nasid = (region * sn_region_size * 2);
  654. nasid < ((region + 1) * sn_region_size * 2);
  655. nasid += 2) {
  656. if ((volatile int) xpc_exiting) {
  657. break;
  658. }
  659. dev_dbg(xpc_part, "checking nasid %d\n", nasid);
  660. if (XPC_NASID_IN_ARRAY(nasid, rp->part_nasids)) {
  661. dev_dbg(xpc_part, "PROM indicates Nasid %d is "
  662. "part of the local partition; skipping "
  663. "region\n", nasid);
  664. break;
  665. }
  666. if (!(XPC_NASID_IN_ARRAY(nasid, rp->mach_nasids))) {
  667. dev_dbg(xpc_part, "PROM indicates Nasid %d was "
  668. "not on Numa-Link network at reset\n",
  669. nasid);
  670. continue;
  671. }
  672. if (XPC_NASID_IN_ARRAY(nasid, discovered_nasids)) {
  673. dev_dbg(xpc_part, "Nasid %d is part of a "
  674. "partition which was previously "
  675. "discovered\n", nasid);
  676. continue;
  677. }
  678. /* pull over the reserved page structure */
  679. ret = xpc_get_remote_rp(nasid, discovered_nasids,
  680. remote_rp, &remote_rsvd_page_pa);
  681. if (ret != xpcSuccess) {
  682. dev_dbg(xpc_part, "unable to get reserved page "
  683. "from nasid %d, reason=%d\n", nasid,
  684. ret);
  685. if (ret == xpcLocalPartid) {
  686. break;
  687. }
  688. continue;
  689. }
  690. remote_vars_pa = remote_rp->vars_pa;
  691. partid = remote_rp->partid;
  692. part = &xpc_partitions[partid];
  693. /* pull over the cross partition variables */
  694. ret = xpc_get_remote_vars(remote_vars_pa, remote_vars);
  695. if (ret != xpcSuccess) {
  696. dev_dbg(xpc_part, "unable to get XPC variables "
  697. "from nasid %d, reason=%d\n", nasid,
  698. ret);
  699. XPC_DEACTIVATE_PARTITION(part, ret);
  700. continue;
  701. }
  702. if (part->act_state != XPC_P_INACTIVE) {
  703. dev_dbg(xpc_part, "partition %d on nasid %d is "
  704. "already activating\n", partid, nasid);
  705. break;
  706. }
  707. /*
  708. * Register the remote partition's AMOs with SAL so it
  709. * can handle and cleanup errors within that address
  710. * range should the remote partition go down. We don't
  711. * unregister this range because it is difficult to
  712. * tell when outstanding writes to the remote partition
  713. * are finished and thus when it is thus safe to
  714. * unregister. This should not result in wasted space
  715. * in the SAL xp_addr_region table because we should
  716. * get the same page for remote_act_amos_pa after
  717. * module reloads and system reboots.
  718. */
  719. if (sn_register_xp_addr_region(
  720. remote_vars->amos_page_pa,
  721. PAGE_SIZE, 1) < 0) {
  722. dev_dbg(xpc_part, "partition %d failed to "
  723. "register xp_addr region 0x%016lx\n",
  724. partid, remote_vars->amos_page_pa);
  725. XPC_SET_REASON(part, xpcPhysAddrRegFailed,
  726. __LINE__);
  727. break;
  728. }
  729. /*
  730. * The remote nasid is valid and available.
  731. * Send an interrupt to that nasid to notify
  732. * it that we are ready to begin activation.
  733. */
  734. dev_dbg(xpc_part, "sending an interrupt to AMO 0x%lx, "
  735. "nasid %d, phys_cpuid 0x%x\n",
  736. remote_vars->amos_page_pa,
  737. remote_vars->act_nasid,
  738. remote_vars->act_phys_cpuid);
  739. xpc_IPI_send_activate(remote_vars);
  740. }
  741. }
  742. kfree(discovered_nasids);
  743. kfree(remote_rp_base);
  744. }
  745. /*
  746. * Given a partid, get the nasids owned by that partition from the
  747. * remote partitions reserved page.
  748. */
  749. enum xpc_retval
  750. xpc_initiate_partid_to_nasids(partid_t partid, void *nasid_mask)
  751. {
  752. struct xpc_partition *part;
  753. u64 part_nasid_pa;
  754. int bte_res;
  755. part = &xpc_partitions[partid];
  756. if (part->remote_rp_pa == 0) {
  757. return xpcPartitionDown;
  758. }
  759. part_nasid_pa = part->remote_rp_pa +
  760. (u64) &((struct xpc_rsvd_page *) 0)->part_nasids;
  761. bte_res = xp_bte_copy(part_nasid_pa, ia64_tpa((u64) nasid_mask),
  762. L1_CACHE_ALIGN(XP_NASID_MASK_BYTES),
  763. (BTE_NOTIFY | BTE_WACQUIRE), NULL);
  764. return xpc_map_bte_errors(bte_res);
  765. }