xpc_partition.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210
  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 pointers */
  39. struct xpc_rsvd_page *xpc_rsvd_page;
  40. static u64 *xpc_part_nasids;
  41. static u64 *xpc_mach_nasids;
  42. struct xpc_vars *xpc_vars;
  43. struct xpc_vars_part *xpc_vars_part;
  44. static int xp_nasid_mask_bytes; /* actual size in bytes of nasid mask */
  45. static int xp_nasid_mask_words; /* actual size in words of nasid mask */
  46. /*
  47. * For performance reasons, each entry of xpc_partitions[] is cacheline
  48. * aligned. And xpc_partitions[] is padded with an additional entry at the
  49. * end so that the last legitimate entry doesn't share its cacheline with
  50. * another variable.
  51. */
  52. struct xpc_partition xpc_partitions[XP_MAX_PARTITIONS + 1];
  53. /*
  54. * Generic buffer used to store a local copy of portions of a remote
  55. * partition's reserved page (either its header and part_nasids mask,
  56. * or its vars).
  57. *
  58. * xpc_discovery runs only once and is a seperate thread that is
  59. * very likely going to be processing in parallel with receiving
  60. * interrupts.
  61. */
  62. char ____cacheline_aligned xpc_remote_copy_buffer[XPC_RP_HEADER_SIZE +
  63. XP_NASID_MASK_BYTES];
  64. /*
  65. * Given a nasid, get the physical address of the partition's reserved page
  66. * for that nasid. This function returns 0 on any error.
  67. */
  68. static u64
  69. xpc_get_rsvd_page_pa(int nasid, u64 buf, u64 buf_size)
  70. {
  71. bte_result_t bte_res;
  72. s64 status;
  73. u64 cookie = 0;
  74. u64 rp_pa = nasid; /* seed with nasid */
  75. u64 len = 0;
  76. while (1) {
  77. status = sn_partition_reserved_page_pa(buf, &cookie, &rp_pa,
  78. &len);
  79. dev_dbg(xpc_part, "SAL returned with status=%li, cookie="
  80. "0x%016lx, address=0x%016lx, len=0x%016lx\n",
  81. status, cookie, rp_pa, len);
  82. if (status != SALRET_MORE_PASSES) {
  83. break;
  84. }
  85. if (len > buf_size) {
  86. dev_err(xpc_part, "len (=0x%016lx) > buf_size\n", len);
  87. status = SALRET_ERROR;
  88. break;
  89. }
  90. bte_res = xp_bte_copy(rp_pa, ia64_tpa(buf), buf_size,
  91. (BTE_NOTIFY | BTE_WACQUIRE), NULL);
  92. if (bte_res != BTE_SUCCESS) {
  93. dev_dbg(xpc_part, "xp_bte_copy failed %i\n", bte_res);
  94. status = SALRET_ERROR;
  95. break;
  96. }
  97. }
  98. if (status != SALRET_OK) {
  99. rp_pa = 0;
  100. }
  101. dev_dbg(xpc_part, "reserved page at phys address 0x%016lx\n", rp_pa);
  102. return rp_pa;
  103. }
  104. /*
  105. * Fill the partition reserved page with the information needed by
  106. * other partitions to discover we are alive and establish initial
  107. * communications.
  108. */
  109. struct xpc_rsvd_page *
  110. xpc_rsvd_page_init(void)
  111. {
  112. struct xpc_rsvd_page *rp;
  113. AMO_t *amos_page;
  114. u64 rp_pa, nasid_array = 0;
  115. int i, ret;
  116. /* get the local reserved page's address */
  117. rp_pa = xpc_get_rsvd_page_pa(cnodeid_to_nasid(0),
  118. (u64) xpc_remote_copy_buffer,
  119. XPC_RP_HEADER_SIZE +
  120. L1_CACHE_BYTES);
  121. if (rp_pa == 0) {
  122. dev_err(xpc_part, "SAL failed to locate the reserved page\n");
  123. return NULL;
  124. }
  125. rp = (struct xpc_rsvd_page *) __va(rp_pa);
  126. if (rp->partid != sn_partition_id) {
  127. dev_err(xpc_part, "the reserved page's partid of %d should be "
  128. "%d\n", rp->partid, sn_partition_id);
  129. return NULL;
  130. }
  131. rp->version = XPC_RP_VERSION;
  132. /* establish the actual sizes of the nasid masks */
  133. if (rp->SAL_version == 1) {
  134. /* SAL_version 1 didn't set the nasids_size field */
  135. rp->nasids_size = 128;
  136. }
  137. xp_nasid_mask_bytes = rp->nasids_size;
  138. xp_nasid_mask_words = xp_nasid_mask_bytes / 8;
  139. /* setup the pointers to the various items in the reserved page */
  140. xpc_part_nasids = XPC_RP_PART_NASIDS(rp);
  141. xpc_mach_nasids = XPC_RP_MACH_NASIDS(rp);
  142. xpc_vars = XPC_RP_VARS(rp);
  143. xpc_vars_part = XPC_RP_VARS_PART(rp);
  144. /*
  145. * Before clearing xpc_vars, see if a page of AMOs had been previously
  146. * allocated. If not we'll need to allocate one and set permissions
  147. * so that cross-partition AMOs are allowed.
  148. *
  149. * The allocated AMO page needs MCA reporting to remain disabled after
  150. * XPC has unloaded. To make this work, we keep a copy of the pointer
  151. * to this page (i.e., amos_page) in the struct xpc_vars structure,
  152. * which is pointed to by the reserved page, and re-use that saved copy
  153. * on subsequent loads of XPC. This AMO page is never freed, and its
  154. * memory protections are never restricted.
  155. */
  156. if ((amos_page = xpc_vars->amos_page) == NULL) {
  157. amos_page = (AMO_t *) TO_AMO(uncached_alloc_page(0));
  158. if (amos_page == NULL) {
  159. dev_err(xpc_part, "can't allocate page of AMOs\n");
  160. return NULL;
  161. }
  162. /*
  163. * Open up AMO-R/W to cpu. This is done for Shub 1.1 systems
  164. * when xpc_allow_IPI_ops() is called via xpc_hb_init().
  165. */
  166. if (!enable_shub_wars_1_1()) {
  167. ret = sn_change_memprotect(ia64_tpa((u64) amos_page),
  168. PAGE_SIZE, SN_MEMPROT_ACCESS_CLASS_1,
  169. &nasid_array);
  170. if (ret != 0) {
  171. dev_err(xpc_part, "can't change memory "
  172. "protections\n");
  173. uncached_free_page(__IA64_UNCACHED_OFFSET |
  174. TO_PHYS((u64) amos_page));
  175. return NULL;
  176. }
  177. }
  178. } else if (!IS_AMO_ADDRESS((u64) amos_page)) {
  179. /*
  180. * EFI's XPBOOT can also set amos_page in the reserved page,
  181. * but it happens to leave it as an uncached physical address
  182. * and we need it to be an uncached virtual, so we'll have to
  183. * convert it.
  184. */
  185. if (!IS_AMO_PHYS_ADDRESS((u64) amos_page)) {
  186. dev_err(xpc_part, "previously used amos_page address "
  187. "is bad = 0x%p\n", (void *) amos_page);
  188. return NULL;
  189. }
  190. amos_page = (AMO_t *) TO_AMO((u64) amos_page);
  191. }
  192. /* clear xpc_vars */
  193. memset(xpc_vars, 0, sizeof(struct xpc_vars));
  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->vars_part_pa = __pa(xpc_vars_part);
  198. xpc_vars->amos_page_pa = ia64_tpa((u64) amos_page);
  199. xpc_vars->amos_page = amos_page; /* save for next load of XPC */
  200. /* clear xpc_vars_part */
  201. memset((u64 *) xpc_vars_part, 0, sizeof(struct xpc_vars_part) *
  202. XP_MAX_PARTITIONS);
  203. /* initialize the activate IRQ related AMO variables */
  204. for (i = 0; i < xp_nasid_mask_words; i++) {
  205. (void) xpc_IPI_init(XPC_ACTIVATE_IRQ_AMOS + i);
  206. }
  207. /* initialize the engaged remote partitions related AMO variables */
  208. (void) xpc_IPI_init(XPC_ENGAGED_PARTITIONS_AMO);
  209. (void) xpc_IPI_init(XPC_DISENGAGE_REQUEST_AMO);
  210. /* timestamp of when reserved page was setup by XPC */
  211. rp->stamp = CURRENT_TIME;
  212. /*
  213. * This signifies to the remote partition that our reserved
  214. * page is initialized.
  215. */
  216. rp->vars_pa = __pa(xpc_vars);
  217. return rp;
  218. }
  219. /*
  220. * Change protections to allow IPI operations (and AMO operations on
  221. * Shub 1.1 systems).
  222. */
  223. void
  224. xpc_allow_IPI_ops(void)
  225. {
  226. int node;
  227. int nasid;
  228. // >>> Change SH_IPI_ACCESS code to use SAL call once it is available.
  229. if (is_shub2()) {
  230. xpc_sh2_IPI_access0 =
  231. (u64) HUB_L((u64 *) LOCAL_MMR_ADDR(SH2_IPI_ACCESS0));
  232. xpc_sh2_IPI_access1 =
  233. (u64) HUB_L((u64 *) LOCAL_MMR_ADDR(SH2_IPI_ACCESS1));
  234. xpc_sh2_IPI_access2 =
  235. (u64) HUB_L((u64 *) LOCAL_MMR_ADDR(SH2_IPI_ACCESS2));
  236. xpc_sh2_IPI_access3 =
  237. (u64) HUB_L((u64 *) LOCAL_MMR_ADDR(SH2_IPI_ACCESS3));
  238. for_each_online_node(node) {
  239. nasid = cnodeid_to_nasid(node);
  240. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS0),
  241. -1UL);
  242. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS1),
  243. -1UL);
  244. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS2),
  245. -1UL);
  246. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS3),
  247. -1UL);
  248. }
  249. } else {
  250. xpc_sh1_IPI_access =
  251. (u64) HUB_L((u64 *) LOCAL_MMR_ADDR(SH1_IPI_ACCESS));
  252. for_each_online_node(node) {
  253. nasid = cnodeid_to_nasid(node);
  254. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH1_IPI_ACCESS),
  255. -1UL);
  256. /*
  257. * Since the BIST collides with memory operations on
  258. * SHUB 1.1 sn_change_memprotect() cannot be used.
  259. */
  260. if (enable_shub_wars_1_1()) {
  261. /* open up everything */
  262. xpc_prot_vec[node] = (u64) HUB_L((u64 *)
  263. GLOBAL_MMR_ADDR(nasid,
  264. SH1_MD_DQLP_MMR_DIR_PRIVEC0));
  265. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid,
  266. SH1_MD_DQLP_MMR_DIR_PRIVEC0),
  267. -1UL);
  268. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid,
  269. SH1_MD_DQRP_MMR_DIR_PRIVEC0),
  270. -1UL);
  271. }
  272. }
  273. }
  274. }
  275. /*
  276. * Restrict protections to disallow IPI operations (and AMO operations on
  277. * Shub 1.1 systems).
  278. */
  279. void
  280. xpc_restrict_IPI_ops(void)
  281. {
  282. int node;
  283. int nasid;
  284. // >>> Change SH_IPI_ACCESS code to use SAL call once it is available.
  285. if (is_shub2()) {
  286. for_each_online_node(node) {
  287. nasid = cnodeid_to_nasid(node);
  288. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS0),
  289. xpc_sh2_IPI_access0);
  290. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS1),
  291. xpc_sh2_IPI_access1);
  292. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS2),
  293. xpc_sh2_IPI_access2);
  294. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS3),
  295. xpc_sh2_IPI_access3);
  296. }
  297. } else {
  298. for_each_online_node(node) {
  299. nasid = cnodeid_to_nasid(node);
  300. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH1_IPI_ACCESS),
  301. xpc_sh1_IPI_access);
  302. if (enable_shub_wars_1_1()) {
  303. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid,
  304. SH1_MD_DQLP_MMR_DIR_PRIVEC0),
  305. xpc_prot_vec[node]);
  306. HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid,
  307. SH1_MD_DQRP_MMR_DIR_PRIVEC0),
  308. xpc_prot_vec[node]);
  309. }
  310. }
  311. }
  312. }
  313. /*
  314. * At periodic intervals, scan through all active partitions and ensure
  315. * their heartbeat is still active. If not, the partition is deactivated.
  316. */
  317. void
  318. xpc_check_remote_hb(void)
  319. {
  320. struct xpc_vars *remote_vars;
  321. struct xpc_partition *part;
  322. partid_t partid;
  323. bte_result_t bres;
  324. remote_vars = (struct xpc_vars *) xpc_remote_copy_buffer;
  325. for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) {
  326. if (xpc_exiting) {
  327. break;
  328. }
  329. if (partid == sn_partition_id) {
  330. continue;
  331. }
  332. part = &xpc_partitions[partid];
  333. if (part->act_state == XPC_P_INACTIVE ||
  334. part->act_state == XPC_P_DEACTIVATING) {
  335. continue;
  336. }
  337. /* pull the remote_hb cache line */
  338. bres = xp_bte_copy(part->remote_vars_pa,
  339. ia64_tpa((u64) remote_vars),
  340. XPC_RP_VARS_SIZE,
  341. (BTE_NOTIFY | BTE_WACQUIRE), NULL);
  342. if (bres != BTE_SUCCESS) {
  343. XPC_DEACTIVATE_PARTITION(part,
  344. xpc_map_bte_errors(bres));
  345. continue;
  346. }
  347. dev_dbg(xpc_part, "partid = %d, heartbeat = %ld, last_heartbeat"
  348. " = %ld, kdb_status = %ld, HB_mask = 0x%lx\n", partid,
  349. remote_vars->heartbeat, part->last_heartbeat,
  350. remote_vars->kdb_status,
  351. remote_vars->heartbeating_to_mask);
  352. if (((remote_vars->heartbeat == part->last_heartbeat) &&
  353. (remote_vars->kdb_status == 0)) ||
  354. !xpc_hb_allowed(sn_partition_id, remote_vars)) {
  355. XPC_DEACTIVATE_PARTITION(part, xpcNoHeartbeat);
  356. continue;
  357. }
  358. part->last_heartbeat = remote_vars->heartbeat;
  359. }
  360. }
  361. /*
  362. * Get a copy of a portion of the remote partition's rsvd page.
  363. *
  364. * remote_rp points to a buffer that is cacheline aligned for BTE copies and
  365. * is large enough to contain a copy of their reserved page header and
  366. * part_nasids mask.
  367. */
  368. static enum xpc_retval
  369. xpc_get_remote_rp(int nasid, u64 *discovered_nasids,
  370. struct xpc_rsvd_page *remote_rp, u64 *remote_rp_pa)
  371. {
  372. int bres, i;
  373. /* get the reserved page's physical address */
  374. *remote_rp_pa = xpc_get_rsvd_page_pa(nasid, (u64) remote_rp,
  375. XPC_RP_HEADER_SIZE +
  376. xp_nasid_mask_bytes);
  377. if (*remote_rp_pa == 0) {
  378. return xpcNoRsvdPageAddr;
  379. }
  380. /* pull over the reserved page header and part_nasids mask */
  381. bres = xp_bte_copy(*remote_rp_pa, ia64_tpa((u64) remote_rp),
  382. XPC_RP_HEADER_SIZE + xp_nasid_mask_bytes,
  383. (BTE_NOTIFY | BTE_WACQUIRE), NULL);
  384. if (bres != BTE_SUCCESS) {
  385. return xpc_map_bte_errors(bres);
  386. }
  387. if (discovered_nasids != NULL) {
  388. u64 *remote_part_nasids = XPC_RP_PART_NASIDS(remote_rp);
  389. for (i = 0; i < xp_nasid_mask_words; i++) {
  390. discovered_nasids[i] |= remote_part_nasids[i];
  391. }
  392. }
  393. /* check that the partid is for another partition */
  394. if (remote_rp->partid < 1 ||
  395. remote_rp->partid > (XP_MAX_PARTITIONS - 1)) {
  396. return xpcInvalidPartid;
  397. }
  398. if (remote_rp->partid == sn_partition_id) {
  399. return xpcLocalPartid;
  400. }
  401. if (XPC_VERSION_MAJOR(remote_rp->version) !=
  402. XPC_VERSION_MAJOR(XPC_RP_VERSION)) {
  403. return xpcBadVersion;
  404. }
  405. return xpcSuccess;
  406. }
  407. /*
  408. * Get a copy of the remote partition's XPC variables from the reserved page.
  409. *
  410. * remote_vars points to a buffer that is cacheline aligned for BTE copies and
  411. * assumed to be of size XPC_RP_VARS_SIZE.
  412. */
  413. static enum xpc_retval
  414. xpc_get_remote_vars(u64 remote_vars_pa, struct xpc_vars *remote_vars)
  415. {
  416. int bres;
  417. if (remote_vars_pa == 0) {
  418. return xpcVarsNotSet;
  419. }
  420. /* pull over the cross partition variables */
  421. bres = xp_bte_copy(remote_vars_pa, ia64_tpa((u64) remote_vars),
  422. XPC_RP_VARS_SIZE,
  423. (BTE_NOTIFY | BTE_WACQUIRE), NULL);
  424. if (bres != BTE_SUCCESS) {
  425. return xpc_map_bte_errors(bres);
  426. }
  427. if (XPC_VERSION_MAJOR(remote_vars->version) !=
  428. XPC_VERSION_MAJOR(XPC_V_VERSION)) {
  429. return xpcBadVersion;
  430. }
  431. return xpcSuccess;
  432. }
  433. /*
  434. * Update the remote partition's info.
  435. */
  436. static void
  437. xpc_update_partition_info(struct xpc_partition *part, u8 remote_rp_version,
  438. struct timespec *remote_rp_stamp, u64 remote_rp_pa,
  439. u64 remote_vars_pa, struct xpc_vars *remote_vars)
  440. {
  441. part->remote_rp_version = remote_rp_version;
  442. dev_dbg(xpc_part, " remote_rp_version = 0x%016lx\n",
  443. part->remote_rp_version);
  444. part->remote_rp_stamp = *remote_rp_stamp;
  445. dev_dbg(xpc_part, " remote_rp_stamp (tv_sec = 0x%lx tv_nsec = 0x%lx\n",
  446. part->remote_rp_stamp.tv_sec, part->remote_rp_stamp.tv_nsec);
  447. part->remote_rp_pa = remote_rp_pa;
  448. dev_dbg(xpc_part, " remote_rp_pa = 0x%016lx\n", part->remote_rp_pa);
  449. part->remote_vars_pa = remote_vars_pa;
  450. dev_dbg(xpc_part, " remote_vars_pa = 0x%016lx\n",
  451. part->remote_vars_pa);
  452. part->last_heartbeat = remote_vars->heartbeat;
  453. dev_dbg(xpc_part, " last_heartbeat = 0x%016lx\n",
  454. part->last_heartbeat);
  455. part->remote_vars_part_pa = remote_vars->vars_part_pa;
  456. dev_dbg(xpc_part, " remote_vars_part_pa = 0x%016lx\n",
  457. part->remote_vars_part_pa);
  458. part->remote_act_nasid = remote_vars->act_nasid;
  459. dev_dbg(xpc_part, " remote_act_nasid = 0x%x\n",
  460. part->remote_act_nasid);
  461. part->remote_act_phys_cpuid = remote_vars->act_phys_cpuid;
  462. dev_dbg(xpc_part, " remote_act_phys_cpuid = 0x%x\n",
  463. part->remote_act_phys_cpuid);
  464. part->remote_amos_page_pa = remote_vars->amos_page_pa;
  465. dev_dbg(xpc_part, " remote_amos_page_pa = 0x%lx\n",
  466. part->remote_amos_page_pa);
  467. part->remote_vars_version = remote_vars->version;
  468. dev_dbg(xpc_part, " remote_vars_version = 0x%x\n",
  469. part->remote_vars_version);
  470. }
  471. /*
  472. * Prior code has determined the nasid which generated an IPI. Inspect
  473. * that nasid to determine if its partition needs to be activated or
  474. * deactivated.
  475. *
  476. * A partition is consider "awaiting activation" if our partition
  477. * flags indicate it is not active and it has a heartbeat. A
  478. * partition is considered "awaiting deactivation" if our partition
  479. * flags indicate it is active but it has no heartbeat or it is not
  480. * sending its heartbeat to us.
  481. *
  482. * To determine the heartbeat, the remote nasid must have a properly
  483. * initialized reserved page.
  484. */
  485. static void
  486. xpc_identify_act_IRQ_req(int nasid)
  487. {
  488. struct xpc_rsvd_page *remote_rp;
  489. struct xpc_vars *remote_vars;
  490. u64 remote_rp_pa;
  491. u64 remote_vars_pa;
  492. int remote_rp_version;
  493. int reactivate = 0;
  494. int stamp_diff;
  495. struct timespec remote_rp_stamp = { 0, 0 };
  496. partid_t partid;
  497. struct xpc_partition *part;
  498. enum xpc_retval ret;
  499. /* pull over the reserved page structure */
  500. remote_rp = (struct xpc_rsvd_page *) xpc_remote_copy_buffer;
  501. ret = xpc_get_remote_rp(nasid, NULL, remote_rp, &remote_rp_pa);
  502. if (ret != xpcSuccess) {
  503. dev_warn(xpc_part, "unable to get reserved page from nasid %d, "
  504. "which sent interrupt, reason=%d\n", nasid, ret);
  505. return;
  506. }
  507. remote_vars_pa = remote_rp->vars_pa;
  508. remote_rp_version = remote_rp->version;
  509. if (XPC_SUPPORTS_RP_STAMP(remote_rp_version)) {
  510. remote_rp_stamp = remote_rp->stamp;
  511. }
  512. partid = remote_rp->partid;
  513. part = &xpc_partitions[partid];
  514. /* pull over the cross partition variables */
  515. remote_vars = (struct xpc_vars *) xpc_remote_copy_buffer;
  516. ret = xpc_get_remote_vars(remote_vars_pa, remote_vars);
  517. if (ret != xpcSuccess) {
  518. dev_warn(xpc_part, "unable to get XPC variables from nasid %d, "
  519. "which sent interrupt, reason=%d\n", nasid, ret);
  520. XPC_DEACTIVATE_PARTITION(part, ret);
  521. return;
  522. }
  523. part->act_IRQ_rcvd++;
  524. dev_dbg(xpc_part, "partid for nasid %d is %d; IRQs = %d; HB = "
  525. "%ld:0x%lx\n", (int) nasid, (int) partid, part->act_IRQ_rcvd,
  526. remote_vars->heartbeat, remote_vars->heartbeating_to_mask);
  527. if (xpc_partition_disengaged(part) &&
  528. part->act_state == XPC_P_INACTIVE) {
  529. xpc_update_partition_info(part, remote_rp_version,
  530. &remote_rp_stamp, remote_rp_pa,
  531. remote_vars_pa, remote_vars);
  532. if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version)) {
  533. if (xpc_partition_disengage_requested(1UL << partid)) {
  534. /*
  535. * Other side is waiting on us to disengage,
  536. * even though we already have.
  537. */
  538. return;
  539. }
  540. } else {
  541. /* other side doesn't support disengage requests */
  542. xpc_clear_partition_disengage_request(1UL << partid);
  543. }
  544. xpc_activate_partition(part);
  545. return;
  546. }
  547. DBUG_ON(part->remote_rp_version == 0);
  548. DBUG_ON(part->remote_vars_version == 0);
  549. if (!XPC_SUPPORTS_RP_STAMP(part->remote_rp_version)) {
  550. DBUG_ON(XPC_SUPPORTS_DISENGAGE_REQUEST(part->
  551. remote_vars_version));
  552. if (!XPC_SUPPORTS_RP_STAMP(remote_rp_version)) {
  553. DBUG_ON(XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->
  554. version));
  555. /* see if the other side rebooted */
  556. if (part->remote_amos_page_pa ==
  557. remote_vars->amos_page_pa &&
  558. xpc_hb_allowed(sn_partition_id,
  559. remote_vars)) {
  560. /* doesn't look that way, so ignore the IPI */
  561. return;
  562. }
  563. }
  564. /*
  565. * Other side rebooted and previous XPC didn't support the
  566. * disengage request, so we don't need to do anything special.
  567. */
  568. xpc_update_partition_info(part, remote_rp_version,
  569. &remote_rp_stamp, remote_rp_pa,
  570. remote_vars_pa, remote_vars);
  571. part->reactivate_nasid = nasid;
  572. XPC_DEACTIVATE_PARTITION(part, xpcReactivating);
  573. return;
  574. }
  575. DBUG_ON(!XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version));
  576. if (!XPC_SUPPORTS_RP_STAMP(remote_rp_version)) {
  577. DBUG_ON(!XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->version));
  578. /*
  579. * Other side rebooted and previous XPC did support the
  580. * disengage request, but the new one doesn't.
  581. */
  582. xpc_clear_partition_engaged(1UL << partid);
  583. xpc_clear_partition_disengage_request(1UL << partid);
  584. xpc_update_partition_info(part, remote_rp_version,
  585. &remote_rp_stamp, remote_rp_pa,
  586. remote_vars_pa, remote_vars);
  587. reactivate = 1;
  588. } else {
  589. DBUG_ON(!XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->version));
  590. stamp_diff = xpc_compare_stamps(&part->remote_rp_stamp,
  591. &remote_rp_stamp);
  592. if (stamp_diff != 0) {
  593. DBUG_ON(stamp_diff >= 0);
  594. /*
  595. * Other side rebooted and the previous XPC did support
  596. * the disengage request, as does the new one.
  597. */
  598. DBUG_ON(xpc_partition_engaged(1UL << partid));
  599. DBUG_ON(xpc_partition_disengage_requested(1UL <<
  600. partid));
  601. xpc_update_partition_info(part, remote_rp_version,
  602. &remote_rp_stamp, remote_rp_pa,
  603. remote_vars_pa, remote_vars);
  604. reactivate = 1;
  605. }
  606. }
  607. if (!xpc_partition_disengaged(part)) {
  608. /* still waiting on other side to disengage from us */
  609. return;
  610. }
  611. if (reactivate) {
  612. part->reactivate_nasid = nasid;
  613. XPC_DEACTIVATE_PARTITION(part, xpcReactivating);
  614. } else if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version) &&
  615. xpc_partition_disengage_requested(1UL << partid)) {
  616. XPC_DEACTIVATE_PARTITION(part, xpcOtherGoingDown);
  617. }
  618. }
  619. /*
  620. * Loop through the activation AMO variables and process any bits
  621. * which are set. Each bit indicates a nasid sending a partition
  622. * activation or deactivation request.
  623. *
  624. * Return #of IRQs detected.
  625. */
  626. int
  627. xpc_identify_act_IRQ_sender(void)
  628. {
  629. int word, bit;
  630. u64 nasid_mask;
  631. u64 nasid; /* remote nasid */
  632. int n_IRQs_detected = 0;
  633. AMO_t *act_amos;
  634. act_amos = xpc_vars->amos_page + XPC_ACTIVATE_IRQ_AMOS;
  635. /* scan through act AMO variable looking for non-zero entries */
  636. for (word = 0; word < xp_nasid_mask_words; word++) {
  637. if (xpc_exiting) {
  638. break;
  639. }
  640. nasid_mask = xpc_IPI_receive(&act_amos[word]);
  641. if (nasid_mask == 0) {
  642. /* no IRQs from nasids in this variable */
  643. continue;
  644. }
  645. dev_dbg(xpc_part, "AMO[%d] gave back 0x%lx\n", word,
  646. nasid_mask);
  647. /*
  648. * If this nasid has been added to the machine since
  649. * our partition was reset, this will retain the
  650. * remote nasid in our reserved pages machine mask.
  651. * This is used in the event of module reload.
  652. */
  653. xpc_mach_nasids[word] |= nasid_mask;
  654. /* locate the nasid(s) which sent interrupts */
  655. for (bit = 0; bit < (8 * sizeof(u64)); bit++) {
  656. if (nasid_mask & (1UL << bit)) {
  657. n_IRQs_detected++;
  658. nasid = XPC_NASID_FROM_W_B(word, bit);
  659. dev_dbg(xpc_part, "interrupt from nasid %ld\n",
  660. nasid);
  661. xpc_identify_act_IRQ_req(nasid);
  662. }
  663. }
  664. }
  665. return n_IRQs_detected;
  666. }
  667. /*
  668. * See if the other side has responded to a partition disengage request
  669. * from us.
  670. */
  671. int
  672. xpc_partition_disengaged(struct xpc_partition *part)
  673. {
  674. partid_t partid = XPC_PARTID(part);
  675. int disengaged;
  676. disengaged = (xpc_partition_engaged(1UL << partid) == 0);
  677. if (part->disengage_request_timeout) {
  678. if (!disengaged) {
  679. if (jiffies < part->disengage_request_timeout) {
  680. /* timelimit hasn't been reached yet */
  681. return 0;
  682. }
  683. /*
  684. * Other side hasn't responded to our disengage
  685. * request in a timely fashion, so assume it's dead.
  686. */
  687. xpc_clear_partition_engaged(1UL << partid);
  688. disengaged = 1;
  689. }
  690. part->disengage_request_timeout = 0;
  691. /* cancel the timer function, provided it's not us */
  692. if (!in_interrupt()) {
  693. del_singleshot_timer_sync(&part->
  694. disengage_request_timer);
  695. }
  696. DBUG_ON(part->act_state != XPC_P_DEACTIVATING &&
  697. part->act_state != XPC_P_INACTIVE);
  698. if (part->act_state != XPC_P_INACTIVE) {
  699. xpc_wakeup_channel_mgr(part);
  700. }
  701. if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version)) {
  702. xpc_cancel_partition_disengage_request(part);
  703. }
  704. }
  705. return disengaged;
  706. }
  707. /*
  708. * Mark specified partition as active.
  709. */
  710. enum xpc_retval
  711. xpc_mark_partition_active(struct xpc_partition *part)
  712. {
  713. unsigned long irq_flags;
  714. enum xpc_retval ret;
  715. dev_dbg(xpc_part, "setting partition %d to ACTIVE\n", XPC_PARTID(part));
  716. spin_lock_irqsave(&part->act_lock, irq_flags);
  717. if (part->act_state == XPC_P_ACTIVATING) {
  718. part->act_state = XPC_P_ACTIVE;
  719. ret = xpcSuccess;
  720. } else {
  721. DBUG_ON(part->reason == xpcSuccess);
  722. ret = part->reason;
  723. }
  724. spin_unlock_irqrestore(&part->act_lock, irq_flags);
  725. return ret;
  726. }
  727. /*
  728. * Notify XPC that the partition is down.
  729. */
  730. void
  731. xpc_deactivate_partition(const int line, struct xpc_partition *part,
  732. enum xpc_retval reason)
  733. {
  734. unsigned long irq_flags;
  735. spin_lock_irqsave(&part->act_lock, irq_flags);
  736. if (part->act_state == XPC_P_INACTIVE) {
  737. XPC_SET_REASON(part, reason, line);
  738. spin_unlock_irqrestore(&part->act_lock, irq_flags);
  739. if (reason == xpcReactivating) {
  740. /* we interrupt ourselves to reactivate partition */
  741. xpc_IPI_send_reactivate(part);
  742. }
  743. return;
  744. }
  745. if (part->act_state == XPC_P_DEACTIVATING) {
  746. if ((part->reason == xpcUnloading && reason != xpcUnloading) ||
  747. reason == xpcReactivating) {
  748. XPC_SET_REASON(part, reason, line);
  749. }
  750. spin_unlock_irqrestore(&part->act_lock, irq_flags);
  751. return;
  752. }
  753. part->act_state = XPC_P_DEACTIVATING;
  754. XPC_SET_REASON(part, reason, line);
  755. spin_unlock_irqrestore(&part->act_lock, irq_flags);
  756. if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version)) {
  757. xpc_request_partition_disengage(part);
  758. xpc_IPI_send_disengage(part);
  759. /* set a timelimit on the disengage request */
  760. part->disengage_request_timeout = jiffies +
  761. (xpc_disengage_request_timelimit * HZ);
  762. part->disengage_request_timer.expires =
  763. part->disengage_request_timeout;
  764. add_timer(&part->disengage_request_timer);
  765. }
  766. dev_dbg(xpc_part, "bringing partition %d down, reason = %d\n",
  767. XPC_PARTID(part), reason);
  768. xpc_partition_going_down(part, reason);
  769. }
  770. /*
  771. * Mark specified partition as inactive.
  772. */
  773. void
  774. xpc_mark_partition_inactive(struct xpc_partition *part)
  775. {
  776. unsigned long irq_flags;
  777. dev_dbg(xpc_part, "setting partition %d to INACTIVE\n",
  778. XPC_PARTID(part));
  779. spin_lock_irqsave(&part->act_lock, irq_flags);
  780. part->act_state = XPC_P_INACTIVE;
  781. spin_unlock_irqrestore(&part->act_lock, irq_flags);
  782. part->remote_rp_pa = 0;
  783. }
  784. /*
  785. * SAL has provided a partition and machine mask. The partition mask
  786. * contains a bit for each even nasid in our partition. The machine
  787. * mask contains a bit for each even nasid in the entire machine.
  788. *
  789. * Using those two bit arrays, we can determine which nasids are
  790. * known in the machine. Each should also have a reserved page
  791. * initialized if they are available for partitioning.
  792. */
  793. void
  794. xpc_discovery(void)
  795. {
  796. void *remote_rp_base;
  797. struct xpc_rsvd_page *remote_rp;
  798. struct xpc_vars *remote_vars;
  799. u64 remote_rp_pa;
  800. u64 remote_vars_pa;
  801. int region;
  802. int region_size;
  803. int max_regions;
  804. int nasid;
  805. struct xpc_rsvd_page *rp;
  806. partid_t partid;
  807. struct xpc_partition *part;
  808. u64 *discovered_nasids;
  809. enum xpc_retval ret;
  810. remote_rp = xpc_kmalloc_cacheline_aligned(XPC_RP_HEADER_SIZE +
  811. xp_nasid_mask_bytes,
  812. GFP_KERNEL, &remote_rp_base);
  813. if (remote_rp == NULL) {
  814. return;
  815. }
  816. remote_vars = (struct xpc_vars *) remote_rp;
  817. discovered_nasids = kmalloc(sizeof(u64) * xp_nasid_mask_words,
  818. GFP_KERNEL);
  819. if (discovered_nasids == NULL) {
  820. kfree(remote_rp_base);
  821. return;
  822. }
  823. memset(discovered_nasids, 0, sizeof(u64) * xp_nasid_mask_words);
  824. rp = (struct xpc_rsvd_page *) xpc_rsvd_page;
  825. /*
  826. * The term 'region' in this context refers to the minimum number of
  827. * nodes that can comprise an access protection grouping. The access
  828. * protection is in regards to memory, IOI and IPI.
  829. */
  830. max_regions = 64;
  831. region_size = sn_region_size;
  832. switch (region_size) {
  833. case 128:
  834. max_regions *= 2;
  835. case 64:
  836. max_regions *= 2;
  837. case 32:
  838. max_regions *= 2;
  839. region_size = 16;
  840. DBUG_ON(!is_shub2());
  841. }
  842. for (region = 0; region < max_regions; region++) {
  843. if ((volatile int) xpc_exiting) {
  844. break;
  845. }
  846. dev_dbg(xpc_part, "searching region %d\n", region);
  847. for (nasid = (region * region_size * 2);
  848. nasid < ((region + 1) * region_size * 2);
  849. nasid += 2) {
  850. if ((volatile int) xpc_exiting) {
  851. break;
  852. }
  853. dev_dbg(xpc_part, "checking nasid %d\n", nasid);
  854. if (XPC_NASID_IN_ARRAY(nasid, xpc_part_nasids)) {
  855. dev_dbg(xpc_part, "PROM indicates Nasid %d is "
  856. "part of the local partition; skipping "
  857. "region\n", nasid);
  858. break;
  859. }
  860. if (!(XPC_NASID_IN_ARRAY(nasid, xpc_mach_nasids))) {
  861. dev_dbg(xpc_part, "PROM indicates Nasid %d was "
  862. "not on Numa-Link network at reset\n",
  863. nasid);
  864. continue;
  865. }
  866. if (XPC_NASID_IN_ARRAY(nasid, discovered_nasids)) {
  867. dev_dbg(xpc_part, "Nasid %d is part of a "
  868. "partition which was previously "
  869. "discovered\n", nasid);
  870. continue;
  871. }
  872. /* pull over the reserved page structure */
  873. ret = xpc_get_remote_rp(nasid, discovered_nasids,
  874. remote_rp, &remote_rp_pa);
  875. if (ret != xpcSuccess) {
  876. dev_dbg(xpc_part, "unable to get reserved page "
  877. "from nasid %d, reason=%d\n", nasid,
  878. ret);
  879. if (ret == xpcLocalPartid) {
  880. break;
  881. }
  882. continue;
  883. }
  884. remote_vars_pa = remote_rp->vars_pa;
  885. partid = remote_rp->partid;
  886. part = &xpc_partitions[partid];
  887. /* pull over the cross partition variables */
  888. ret = xpc_get_remote_vars(remote_vars_pa, remote_vars);
  889. if (ret != xpcSuccess) {
  890. dev_dbg(xpc_part, "unable to get XPC variables "
  891. "from nasid %d, reason=%d\n", nasid,
  892. ret);
  893. XPC_DEACTIVATE_PARTITION(part, ret);
  894. continue;
  895. }
  896. if (part->act_state != XPC_P_INACTIVE) {
  897. dev_dbg(xpc_part, "partition %d on nasid %d is "
  898. "already activating\n", partid, nasid);
  899. break;
  900. }
  901. /*
  902. * Register the remote partition's AMOs with SAL so it
  903. * can handle and cleanup errors within that address
  904. * range should the remote partition go down. We don't
  905. * unregister this range because it is difficult to
  906. * tell when outstanding writes to the remote partition
  907. * are finished and thus when it is thus safe to
  908. * unregister. This should not result in wasted space
  909. * in the SAL xp_addr_region table because we should
  910. * get the same page for remote_act_amos_pa after
  911. * module reloads and system reboots.
  912. */
  913. if (sn_register_xp_addr_region(
  914. remote_vars->amos_page_pa,
  915. PAGE_SIZE, 1) < 0) {
  916. dev_dbg(xpc_part, "partition %d failed to "
  917. "register xp_addr region 0x%016lx\n",
  918. partid, remote_vars->amos_page_pa);
  919. XPC_SET_REASON(part, xpcPhysAddrRegFailed,
  920. __LINE__);
  921. break;
  922. }
  923. /*
  924. * The remote nasid is valid and available.
  925. * Send an interrupt to that nasid to notify
  926. * it that we are ready to begin activation.
  927. */
  928. dev_dbg(xpc_part, "sending an interrupt to AMO 0x%lx, "
  929. "nasid %d, phys_cpuid 0x%x\n",
  930. remote_vars->amos_page_pa,
  931. remote_vars->act_nasid,
  932. remote_vars->act_phys_cpuid);
  933. if (XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->
  934. version)) {
  935. part->remote_amos_page_pa =
  936. remote_vars->amos_page_pa;
  937. xpc_mark_partition_disengaged(part);
  938. xpc_cancel_partition_disengage_request(part);
  939. }
  940. xpc_IPI_send_activate(remote_vars);
  941. }
  942. }
  943. kfree(discovered_nasids);
  944. kfree(remote_rp_base);
  945. }
  946. /*
  947. * Given a partid, get the nasids owned by that partition from the
  948. * remote partition's reserved page.
  949. */
  950. enum xpc_retval
  951. xpc_initiate_partid_to_nasids(partid_t partid, void *nasid_mask)
  952. {
  953. struct xpc_partition *part;
  954. u64 part_nasid_pa;
  955. int bte_res;
  956. part = &xpc_partitions[partid];
  957. if (part->remote_rp_pa == 0) {
  958. return xpcPartitionDown;
  959. }
  960. memset(nasid_mask, 0, XP_NASID_MASK_BYTES);
  961. part_nasid_pa = (u64) XPC_RP_PART_NASIDS(part->remote_rp_pa);
  962. bte_res = xp_bte_copy(part_nasid_pa, ia64_tpa((u64) nasid_mask),
  963. xp_nasid_mask_bytes, (BTE_NOTIFY | BTE_WACQUIRE), NULL);
  964. return xpc_map_bte_errors(bte_res);
  965. }